Search This Blog

Friday, December 11, 2009

Seting NFS Service on SUSE Server

Following are the steps to configure NFS on SUSE System



1) service nfsserver restart

2) echo "/home/user/nfs *(rw,sync,no_root_squash,no_all_squash,subtree_check)" >> /etc/exports

3) exportfs -a #; export the content of /etc/export file

4) exportfs #; Can check which files are exported and their permission

linux-hth0:/home/vijay # exportfs

/home/user

5) rpcinfo -p | grep nfs # this will list down the nfs server working status, we should be able to see some nfs working on the port number 2049

linux-hth0:/home/vijay # rpcinfo -p | grep nfs

100003 2 udp 2049 nfs

100003 3 udp 2049 nfs

100003 4 udp 2049 nfs

100003 2 tcp 2049 nfs

100003 3 tcp 2049 nfs

100003 4 tcp 2049 nfs

6)

linux-hth0:/home/vijay # netstat -tan | grep 2049

tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN

7) service nfsserver restart

linux-hth0:/home/vijay # service nfsserver start

Starting kernel based NFS server: idmapd mountd statd nfsd sm-notify done

From Client : Target System

1) Setup the IP if not set
ifconfig eth0 $MY_IP netmask $MY_MASK up

2) Set the Gate way

route add default gw $GW_IP

3) mount -t nfs $SERVER_IP:/home/user /mnt -o nolock,rsize=4096,wsize=4096

To Check if the which all system has mounted on your Server check

From Server

linux-hth0:/home/vijay/BSP_OUTPUT # showmount
Hosts on linux-hth0:
X.y.74.190
X.Y.74.222

On other linux distribution version like fedora we need to use nfs instead of nfsserver.

Monday, August 3, 2009

Never Say Codes are Static

Running Code from Stack/Heap

To make sure we understand this i will try to give as much as details as much possible.

Introduction

An Executable file is a collection of sections which stores information of the code, this may be

We can easily see the code runs from text Section which will be present in the Read only data format, We can summarize
this

1) Text Section – Read Only
2) Data Section – Read/Write
3) BSS Section – Read and Write – This is empty Section the ELF File only has information about the size of the Section, there is no data in this section so we see the section type as NOBITS
When the exe is executed the kernel allocates a process space to the executable with basic sections

1) Text
2) Stack
3) Heap
4) Data Section
5) Environment

We will concentrate to execute a code from stack.

The code starts execution from text section depending on the Loader which starts executing from a fixed address, For most
of the ELF Linked executable it starts with _start, which also calls some more initializers, we can understand them as
constructors. More about ELF Format can be read from www.skyfree.org/linux/references/ELF_Format.pdf

We will start with a very basic code
This C File Runs from the text section. We will try to edit this file to make some code run from stack.
Code Runnig from Heap/Stack:

#include
void Demo(void)
{
printf("He llo this is vijay \n");
re turn;
}
int main()
{
Demo();
re turn 0;
}
1 #include
2 #include
3 #include
4
5
6 void Demo(int (*_printf)(const char *, ...))
7 {
8 _printf("He llo this is Vijay \n");
9 re turn;
10 }
11
12 int main(int arg c, char *arg v[])
13 {
14 const char *buff;
15 int a=0;
16 int (*_printf)(const char *, ...) = printf;
17 int (* _main)(int, char **) = &main;
18 void (*_Demo)(int (*)(const char *, ...)) = &Demo;
19
20 unsig ned int func_le n = (unsig ned int )_main - (unsig ned int)_Demo;
21
22 buff = (const char *)malloc(func_len);
23
24 memcpy(( void *)buff, _Demo, func_len);
25
26
27 _Demo = (void (*) (int (*) (const char *, ...))) &buff[0];
28
29 _Demo(_printf);
30 return 0;


Algorithm:
1) Take the reference address of the Function to be copied in the stack.
2) Take the reference address of main
3) Get the size of function to be copied
4) Allocate this memory in the heap.
5) Copy the offcode of the instruction on the Heap/Stack
For Using Stack Instead of Heap, change the line number 14
< const char *buff;
> const chat buff[200]; Appropriate for the code to be copied
At line number 22, Comment it
6) This should be sufficient for the compiling the code, without any warning.

Verify:
Now, Running this with objdump we get, we will see the code has been copied in the heap memory.


$ objdump -dS SmC_code > test.asm
08048404 :
#include
void Demo(int (*_printf)(const char *, ...))
{
8048404: 55 push %ebp
8048405: 89 e5 mov %esp,%ebp
8048407: 83 ec 08 sub $0x8,%esp
_printf("Hello this is Vijay \n");
804840a: c7 04 24 50 85 04 08 movl $0x8048550,(%esp)
8048411: ff 55 08 call *0x8(%ebp)
return;
}
8048414: c9 leave
8048415: c3 ret
08048416
:
int main(int argc, char *argv[])
{
8048416: 8d 4c 24 04 lea 0x4(%esp),%ecx
804841a: 83 e4 f0 and $0xfffffff0,%esp
804841d: ff 71 fc pushl 0xfffffffc(%ecx)
8048420: 55 push %ebp
8048421: 89 e5 mov %esp,%ebp
8048423: 83 ec 18 sub $0x18,%esp
8048426: 89 4d f4 mov %ecx,0xfffffff4(%ebp)
8048429: 89 5d f8 mov %ebx,0xfffffff8(%ebp)
804842c: 89 75 fc mov %esi,0xfffffffc(%ebp)
const char *buff;
int a=0;
int (*_printf)(const char *, ...) = printf;
int (* _main)(int, char **) = &main;
void (*_Demo)(int (*)(const char *, ...)) = &Demo;
unsigned int func_len = (unsigned int )_main - (unsigned int)_Demo;
804842f: bb 16 84 04 08 mov $0x8048416,%ebx
8048434: 81 eb 04 84 04 08 sub $0x8048404,%ebx
buff = (const char *)malloc(func_len);
804843a: 89 1c 24 mov %ebx,(%esp)
804843d: e8 da fe ff ff call 804831c
8048442: 89 c6 mov %eax,%esi
memcpy(( void *)buff, _Demo, func_len);
8048444: 89 5c 24 08 mov %ebx,0x8(%esp)
8048448: c7 44 24 04 04 84 04 movl $0x8048404,0x4(%esp)
804844f: 08
8048450: 89 04 24 mov %eax,(%esp)
8048453: e8 a4 fe ff ff call 80482fc
/*
for (; a < func_len; a++)
{
buff[a] = ((char *) _Demo)[a];
}
*/
_Demo = (void (*) (int (*) (const char *, ...))) &buff[0];
_Demo(_printf);
8048458: c7 04 24 0c 83 04 08 movl $0x804830c,(%esp)
804845f: ff d6 call *%esi
return 0;
}
8048461: b8 00 00 00 00 mov $0x0,%eax
8048466: 8b 4d f4 mov 0xfffffff4(%ebp),%ecx
8048469: 8b 5d f8 mov 0xfffffff8(%ebp),%ebx
804846c: 8b 75 fc mov 0xfffffffc(%ebp),%esi
804846f: 89 ec mov %ebp,%esp
8048471: 5d pop %ebp
8048472: 8d 61 fc lea 0xfffffffc(%ecx),%esp
8048475: c3 ret
8048476: 90 nop
8048477: 90 nop
8048478: 90 nop
8048479: 90 nop
804847a: 90 nop
804847b: 90 nop
804847c: 90 nop
804847d: 90 nop
804847e: 90 nop
804847f: 90 nop

Running:
Now Finally Running the executable
[vijay@localhost tmp]$ vim slfmdfy_code.asm
[vijay@localhost tmp]$ ./slfmdfy_code
Hello this is Vijay

Conclusion:
We are able to run the code from Stack/Heap. This example will help for applications like
1) Speeding applications – We have lesser cache misses
2) Security – Exploits, Key Generators.
3) Implementing Encryption engine where we do not want to give the encryption code in the text section, this makes
it difficult to reverse engineer the assembly code.
4) Also, MPS(Multi Processor System), Different Arch CPU are present registers of the co-processor are io-mapped
with the main processor memory region, we can make the co-processor run from stack code.

References:
1) How to write Shared Libraries: Ulrich Drepper
2) Executable and Linkable Format (ELF)
3) Kernel Source Tree – 2.6.20.1
4) www.google.com

Can reach me at vijayendra dot suman at gmail.com / vijayendra dot s at samsung.com/ skype-Id – vijayendra.suman
This document is only for open source.

You can Find a copy here
https://docs.google.com/fileview?id=0B6FKJ7nzzC9eMDZmOTExYWEtNWE2NS00NDA3LTkyZGUtMTk0MTA3NzhlNTMx&hl=en

DC Motor Control



/*  DC Motor control
    Call For running the loop back DC motor
    Enhancement send the signal to serial terminal
    about rotation speed and motor max speed
    Edited by Vijayendra Suman for IICE Technologies   
*/


$TITLE (PI CONTROLLER, WITH DELTA(T)=10 mSEC, Km=0.5, Ti=50 MILLISECONDS)
$ALLPUBLIC

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;*This PI Algorith is implemented in a AT89C52 microcontroller and it can*
;*be used for controlling a DC motor in closed-loop configuration and is *
;*given by: U(k+1)= U(k)-0.4E(k) + 0.5E(k+1); where k) and (k+1) means *
;*the values of the variables in an instant of time k, and in an instant *
;*later respectively, this time is given by the sample time delta(T) *
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;***************BEGIN RAM AREA, BIT-TO-BIT ADDRESSABLE********************
EK EQU 20H ;ERROR IN A PREVIOUS INSTANTE OF TIME
EKM1 EQU 21H ;ERROR IN A CURRENT INSTANT OF TIME
UK EQU 22H ;CONTROL SIGNAL IN A PREVIOUS INSTANTE OF TIME
RESPRO3 EQU 26H ;RESULT OF MULTIPLY THE GAIN3 WITH EK
RESPRO5 EQU 28H ;RESULT OF MULTIPLY THE GAIN5 WITH EKM1
REFERENCIA EQU 2AH ;REFERENCE SIGNAL GIVEN TO THE MICROCONTROLLER
FLAG EQU 2BH ;REGISTER OF AUXILIARY FLAG
FLAG1 EQU 2CH ;REGISTER OF AUXILIARY FLAG1
EXHI EQU 2DH ;VARIABLE
;*****************BEGIN SCRATCH PAD RAM MEMORY****************************
ACC1 EQU 30H ;Variable used in all routines to perform the arithmetical operations(+,-,x,/)
ACC2 EQU 34H ;Variable used in all routines to perform the arithmetical operations(+,-,x,/)
CR0 EQU 38H ;LSB OF THE DIVIDEND, DIVISION ROUTINE(16 bit)
CR1 EQU 39H ;MSB OF THE DIVIDEND, DIVISION ROUTINE(16 bit)
CR2 EQU 3AH ;LSB OF DIVISOR DIVISION ROUTINE(16 bit).
CR3 EQU 3BH ;MSB OF THE DIVISOR, DIVISION ROUTINE(16 bit)
divalto EQU 3CH ;Variable that storage temporaly result of high-byte division routine(16 bits)
divbajo EQU 3DH ;Variable that storage temporaly result of low-byte division routine(16 bits)
NIBLE EQU 3EH ;AUXILIARY REGISTER TO DISPLAY DATA OF LCD MODULE
POS EQU 3FH ;POSITION REGISTER TO DISPLAY DATA OF LCD MODULE

DEFSEG PICTRL, ABSOLUTE
SEG PICTRL
LJMP INICIO
ORG 023H
JMP RUIN
ORG 100H
;--------- TO INITIATE DAC MAX508---------------------------------------
INICIO: CLR P0.3 ;INHIBIT BACK TO HOME (CHR)
MOV P2, #00H ;PUT LSB IN DATA BUS OF DAC
CLR P0.5 ;CLEAR CSLSB COMMAND
CLR P0.6 ;CLEAR WR COMMAND
NOP ;NOT OPERATION
SETB P0.6 ;DESABLE WR COMMAND
SETB P0.5 ;DESABLE CSLSB COMMAND
MOV P2, #00H ;PUT MSB IN DATA BUS OF DAC
CLR P0.4 ;ENABLE CSMSB COMMAND
CLR P0.6 ;CLEAR WR COMMAND
nop ;NOT OPERATION
SETB P0.6 ;CLEAR WR COMMAND
SETB P0.4 ;DESABLE CSMSB COMMAND
CLR P0.7 ;ENABLE LDAC COMMAND
NOP ;NOT OPERATION
SETB P0.7 ;DESABLE LDAC COMMAND
;-------INICIALIZA DAC-------------------------------------
;---------CONFIGURATION OF LCD MODULE----------------------
MOV P1, #00H ;LOAD 00H IN DATA BUS OF LCD MODULE
CLR P3.6 ;INHIBIT LCD MODULE
CLR P3.7 ;INDICATE THAT CURRENT WORD IN BUS-LCD IS A CONTROL DATA
MOV A, #38H ;CONFIGURE LCD
CALL INS ;ROUTINE THAT PUT DATA IN LCD-BUS;
MOV A, #0EH ;MOVE WORD TO CONFIGURE LCD
CALL INS
MOV A, #01H ;CLEAR SCREEN OF LCD MODULE
CALL INS
SETB P3.7 ;INDICATE THAT CURRENT WORD IN BUS-LCD IS A CONTROL DATA
;----------------------------------------------------------
;&&&&&&&&&&&&&&&&&& CONTROL LAW &&&&&&&&&&&&&&&&&&&&&&&&&&&
;-CONFIGURATION OF REGISTERS-------------------------------
NIDO1: CALL SERIAL
NIDO2: MOV TMOD, #15H ;CONFIGURATION TIMER0 AS 16-BIT COUNTER AND TIMER1 AS 16-BIT TIMER
MOV T2CON, #00H ;CONFIGURATION TIMER2 AS AUTOLOAD 16-BIT COUNTER
;-- LOAD INITIAL CONDITIONS OF PI CONTROLLER---------------
MOV P2, #00H
MOV EK, #00H
MOV UK, #00H
MOV UK+1, #00H
MOV UK+2, #00H
MOV UK+3, #00H
;-----------------MEAN PROGRAM----------------------------
CONTROLE3:MOV TH1, #0DAH ;INITIATE TIMER1 REGISTERS
MOV TL1, #0F8H
SETB TR1 ;SET TIMER1
CALL SENSORE3 ;CALL VELOCITY SENSOR ("VS") ROUTINE
MOV A, REFERENCIA ;LOAD REFERENCE VALUE (MINUEND OF SUBSTRACCION ROUTINE)
MOV B, TL0 ;LOAD ACTUAL VALUE OF COUNTER0 (SUSTRAEND)
ACALL ERRORE3 ;CALL SUBTRACTION ROUTINE TO CALCULATE THE ERROR SIGNAL
ACALL CEROE3 ;ROUTINE TO CHECK IF MOTOR HAS REACHED THE REFERENCE SIGNAL
JBC FLAG.7,BRICE3 ;IF ERROR E=0
JBC FLAG.0,JLC2E3 ;ASK ERROR IS NEGATIVE?, IF YES JUMP TO CONTROL2
CALL CONTROL1E3 ;IF ERROR IS POSITIVE CALL CONTROL1
JMP CONTROLE3
JLC2E3: ACALL CONTROL2E3 ;IF ERROR IS NEGATIVE CALL CONTROL2
BRICE3: JMP CONTROLE3
;---------------------END MEAN PROGRAM---------------------------------------
;---------------------ROUTINE TO CALCULATE THE ERROR SIGNAL------------------
;MINUEND MUST BE PREVIOUSLY LOAD IN ACCUMALATOR AND SUBSTRAEND IN B REGISTER-
ERRORE3: SUBB A,B ;PERFORMANCE SUBSTRACTION OF ACC AND B REGISTER
JC JE1E3 ;IF CARRY IS ON, MAKES COMPLEMENT
MOV EKM1, A ;IF CARRY IS OFF, STORAGE ERROR
RET
JE1E3: SETB FLAG.0 ;SET FLAG OF NEGATIVE SIGN
CLR C ;CLEAR CARRY FLAG
CPL A ;GET COMPLEMENT
INC A ;GET ABSOLUTE VALUE OF RESULT
MOV EKM1, A ;STORAGE ERROR
RET
;-&&&&&&&&&&&&&&&&--- ROUTINE TO CHECK ERROR = 0 &&&&&&&&&&&&&&&&&&&&&&&&
CEROE3: MOV A, #00H
CJNE A, EKM1,JUPIE3
SETB FLAG.7 ;IF MOTOR HAS REACHED THE REFERENCE(E=0), SET FLAG.7
CLR TR1 ;STOP TIMER1
MOV TH1, #00H ;CLEAR TIMER1 HIGH-REGISTER
MOV TL1, #00H ;CLEAR TIMER1 LOW-REGISTER
CALL MOSTRAR ;CALL ROUTINE TO EXHIBIT DATA, (MOD X CHR P/PRUEBA, 11/04/05)
CALL SERIAL ;CALL ROUTINE SERIAL
RET
JUPIE3: CLR FLAG.7 ;CLEAR FLAG.7
RET
;--------------------- ROUTINE OF "VS" TO CALCULATE ANGULAR VELOCITY----------
;THIS ROUTINE COMPUTES THE ANGULAR DISPLACEMENT THAT THE MOTOR REACHS DURING 2 MILLISECS
;TIMER0 MUST BE CONFIGURED AS 16BIT COUNTER (TMOD=01H), AND TIMER2 AS 16BIT CAPTURE TIMER(T2CON=00H)
;WITH AUTOLOAD (TH2TL2=F897H; TIMERO IS ENABLE WITH TR0 AND TIMER2 WITH T2CON.2
;THE TIMERS FLAGS ARE TF0 AND T2CON.7
SENSORE3: MOV TL2, #97H ;INITIAL VALUE OF LOW-REGISTER T2 (TIMER2 MUST COMPUTE 2MILLISECS)
MOV TH2, #0F8H ;INITIAL VALUE OF HIGH-REGISTER T2
MOV TL0, #00H ;LOAD INITIAL VALUE OF TL0 REGISTER
MOV TH0, #00H ;LOAD INITIAL VALUE OF TH0 REGISTER
SETB TR0 ;SET TIMER0
SETB T2CON.2 ;SET TIMER2
J01E3: JBC T2CON.7,J02E3 ;ASK IF TF2, TIMER2 FLAG IS ON
JMP J01E3 ;IF IS OFF, MAKES LOOP
J02E3: CLR TR0 ;SI TF2=1, DESHABILITA TIMER 0
CLR T2CON.2 ;DESABLE TIMER2
RET
;*************************************************************************
;-ROUTINE OF THE PI CONTROLLER GIVEN BY U(k+1)=U(k) - 0.4E(k) + 0.5E(K+1)*
;--------IN THIS ROUTINE THE E(k+1), E(k) AND U(k) VARIABLES ARE USED----*
**************************************************************************
CONTROL1E3:CLR FLAG.0
;MULTIPLICATION OF E(K) WITH 4, THE MULTIPLICAND IS LOADED IN ACC1 AND MULTIPLIER IN ACC2
MOV ACC1+2, #00H
MOV ACC1+3, EK
MOV ACC2+2, #00H
MOV ACC2+3, #04H
ACALL MUL16
MOV RESPRO3, R5
MOV RESPRO3+1, R4
;MULTIPLICATION OF E(K+1) WITH 5, THE MULTIPLICAND IS LOADED IN ACC1 AND MULTIPLIER IN ACC2
MOV ACC1+2, #00H
MOV ACC1+3, EKM1
MOV ACC2+2, #00H
MOV ACC2+3, #05H
ACALL MUL16
;ADDITION OF U(k) AND 5*E(k+1)
MOV ACC1+2, UK
MOV ACC1+3, UK+1
MOV ACC2+2, R5
MOV ACC2+3, R4
ACALL SUMA
;SUBSTRACTION OF PREVIOUS ADDITION RESULT AND 4*E(k)
MOV ACC2+2, R5 ;GET MSB MINUEND
MOV ACC2+3, R4 ;GET LSB MINUEND
MOV ACC1+2, RESPRO3 ;GET MSB SUSTRAEND
MOV ACC1+3, RESPRO3+1 ;GET LSB SUSTRAEND
ACALL RESTA ;CALL 16-BIT SUBSTRACTION ROUTINE
MOV UK, R5
MOV UK+1, R4
;DIVISION OF PREVIOUS RESULT BY 0AH (NUMBER TEN IN DECIMAL BASE)
MOV CR3, #00h ;MOVE SECOND NIBBLE DIVISOR
MOV CR2, #0Ah ;MOVE FIRST NIBBLE DIVISOR
MOV CR1, R5 ;MOVE FOURTH NIBBLE DIVIDEND
MOV CR0, R4 ;MOVE FOURTH NIBBLE DIVIDEND
acall limpiar ;CLEAR REGISTERS
acall div16 ;CALL 16-BIT DIVISION ROUTINE
;MULTIPLICATION OF PREVIOUS RESULT WITH 02BH (HEXADECIMAL BASE)
MOV ACC1+2, R5
MOV ACC1+3, R4
MOV ACC2+2, #00H
MOV ACC2+3, #2BH
ACALL MUL16 ;CALL 16-BIT MULTIPLICATION ROUTINE
ACALL DATADAC ;CALL ROUTINE FOR DIGITAL-ANALOG CONVERSION
**********************************************************************
;-BEGIN ROUTINE OF PI CONTROLLER U(k+1)= U(k) + 0.4E(k) - 0.5E(k+1) *
**********************************************************************
CONTROL2E3:CLR FLAG.0
;MULTIPLICATION OF E(K+1) WITH 5, THE MULTIPLICAND IS LOADED IN ACC1 AND MULTIPLIER IN ACC2
MOV ACC1+2, #00H
MOV ACC1+3, EKM1
MOV ACC2+2, #00H
MOV ACC2+3, #05H
ACALL MUL16 ;CALL 16-BIT MULTIPLICATION ROUTINE
MOV RESPRO5, R5
MOV RESPRO5+1, R4
MULTIPLICATION OF E(K) WITH 4, THE MULTIPLICAND IS LOADED IN ACC1 AND MULTIPLIER IN ACC2
MOV ACC1+2, #00H
MOV ACC1+3, EK
MOV ACC2+2, #00H
MOV ACC2+3, #04H
ACALL MUL16 ;CALL 16-BIT MULTIPLICATION ROUTINE
;ADDITION OF U(k) WITH 4*E(K)
MOV ACC1+2, UK
MOV ACC1+3, UK+1
MOV ACC2+2, R5
MOV ACC2+3, R4
ACALL SUMA
;SUBTRACTION OF PREVIOUS RESULT WITH 5*E(k+1)
MOV ACC2+2, R5 ;GET MSB MINUEND
MOV ACC2+3, R4 ;GET LSB MINUEND
MOV ACC1+2, RESPRO5 ;GET MSB SUSTRAEND
MOV ACC1+3, RESPRO5+1 ;GET LSB SUSTRAEND
ACALL RESTA ;CALL 16-BIT SUBSTRACTION ROUTINE
MOV UK, R5
MOV UK+1, R4
;DIVISION OF PREVIOUS RESULT BY 0AH (NUMBER TEN DECIMAL)
MOV CR3, #00h ;GET HIGH BYTE DIVISOR
MOV CR2, #0Ah ;GET LOW BYTE DIVISOR
MOV CR1, R5 ;GET HIGH BYTE DIVIDEND
MOV CR0, R4 ;GET LOW BYTE DIVIDEND
acall limpiar ;CLEAR REGISTERS
acall div16 ;CALL 16-BIT DIVISION ROUTINE
;MULTIPLICATION OF PREVIOUS RESULT BY 02BH (HEXADECIMAL BASE)
MOV ACC1+2, R5
MOV ACC1+3, R4
MOV ACC2+2, #00H
MOV ACC2+3, #2BH
ACALL MUL16 ;CALL 16-BIT MULTIPLICATION ROUTINE
***************************************************************************************
;THIS ROUTINE PUT THE PI ALGORITHM U(K+1) RESULT IN PORT0 FOR DIGITAL-ANALOG CONVERSION
***************************************************************************************
DATADAC: MOV P2, R4 ;PUT LSB IN DATA BUS OF DAC
CLR P0.5 ;CLEAR CSLSB COMMAND OF DAC
CLR P0.6 ;CLEAR WR COMMAND OF DAC
NOP
SETB P0.6 ;DESABLE WR COMMAND OF DAC
SETB P0.5 ;DESABLE CSLSB COMMAND OF DAC
MOV P2, R5 ;PUT MSB IN DATA BUS OF DAC
CLR P0.4 ;SET CSMSB COMMAND OF DAC
CLR P0.6 ;CLEAR WR COMMAND OF DAC
NOP
SETB P0.6 ;CLEAR WR COMMAND OF DAC
SETB P0.4 ;DESABLE CSMSB COMMAND OF DAC
CLR P0.7 ;SET LDAC COMMAND OF DAC
NOP
SETB P0.7 ;DESABLE LDAC COMMAND
;ROTATE CURRENT ERROR IN PREVIOUS ERROR REGISTER FOR NEXT LOOP, E(k+1) IS ROTATED TO E(k)
MOV EK, EKM1
JTM2E3: JBC TF1, JTM1E3 ;ASK IF TF1 IS ON, WHICH MEANS AN OVERFLOW OF TIMER1
JMP JTM2E3 ;IF TF1 IS OFF, TO CONTINUE DOING LOOP
JTM1E3: CLR TR1 ;IF TF1 IS ON, DESABLE TIMER1
RET
;---------------------END ROUTINE OF PI CONTROLLER U(K+1)=U(k) + 0.4E(k) - 0.5E(K+1)-----
;********************************************************************
; THIS ROUTINE PERFORMANCE THE MULTIPLICATION OF TWO 16 BITS NUMBERS*
;********************************************************************
MUL16: MOV A,ACC2+3 ;GET LSB MULTIPLIER
MOV B,ACC1+3 ;GET LSB MULTIPLICAND
MUL AB
MOV R4,A ;SAVE MULTIPLICATION RESULT IN R4
MOV R5,B ;Save byte 5, discard byte 6
MOV A,ACC2+2 ;Get multiplier NSB
MOV B,ACC1+3 ;Get multiplicand LSB
mul AB
add A,R5 ;Add previous byte 5 result
MOV R5,A ;Save byte 5
clr A ;clear Accumulator.
MOV A,B ;Get byte 4
addc A,#00H ;Carry propogate from byte 5
MOV R6,A ;Save byte 4
MOV A,ACC2+3 ;Get multiplier LSB
MOV B,ACC1+2 ;Get multiplicand NSB
mul AB
add A,R5 ;Add previous byte 5 result and discard
MOV R5,A ;save byte 5 -End tens-
MOV A,B ;Get byte 4
addc A,R6 ;Add previous byte 4 result and carry from byte 5
MOV R6,A ;Save byte 4 -save hundreds-
MOV A,ACC2+2 ;Get multiplier NSB
MOV B,ACC1+2 ;Get multiplicand NSB
mul AB ;Multiplication of Acc. with B register
add A,R6 ;Add previous byte 4 result
MOV R6,A ;Save byte 4 -save hundreds-
MOV A,B ;Get byte 3
addc A,#00H ;Carry propogate from byte 3
MOV R7,A ;Save byte 2
ret
;**********************************************************************
;*****THIS ROUTINE PERFORMANCE THE ADDITION OF TWO 16 BITS NUMBERS ****
;**IF THERE IS OVERFLOW, A FLAG IS SET IN R3; R3-R7 REGISTER ARE USED**
;**********************************************************************
SUMA: MOV A,ACC2+3 ;Get LSB ADDER2
MOV B,ACC1+3 ;Get LSB ADDER1
clr c ;CLEAR CARRY FLAG
add A,B ;Add lsb1,lsb2
MOV R4,A ;Save byte4
MOV A,ACC2+2 ;Get adder2 NSB
MOV B,ACC1+2 ;Get adder1 NSB
addc A,B
MOV R5,A ;Save byte 5
jnc fin
MOV R3,#01H ;Set carry in R3
CLR C
fin: ret
;***********************************************************************
;THIS ROUTINE PERFORMANCE THE SUBTRACTION OF TWO 16 BITS NUMBERS AND IF*
;***************RESULT IS NEGATIVE, A FLAG IS SET IN R3*****************
;***********************************************************************
RESTA: MOV A,ACC2+3 ;Get LSB minuend2
MOV B,ACC1+3 ;Get LSB sustraend1
clr c
subb A,B ;Subb lsb1,lsb2
MOV R4,A ;Save byte4
MOV A,ACC2+2 ;Get minuend1 NSB
MOV B,ACC1+2 ;Get sustraend2 NSB
subb A,B ;Subb NSB1,NSB2
MOV R5,A ;Save byte5
jnc end1
MOV R3,#01H
end1: ret
;**********************************************************************
;***THIS ROUTINE PERFORMANCE THE DIVISION OF TWO 16 BITS NUMBERS*******
;***CR0-CR3 ARE USED AND DIVISION RESULT IS STORAGE IN R4-R5 REGISTERS*
;**********************************************************************
div16: inc B ;Increment B counter (B register is used as counter)
MOV A,CR2 ;Get low byte of divisor to ratate with carry
RLC A ;Rotate low byte divisor left through the carry
MOV CR2,A ;Save previous result
MOV A,CR3 ;get high byte divisor to rotate with carry
RLC A ;Rotate high byte divisor right through the carry
MOV CR3,A ;Save previous result
jnc div16 ;Continues loops until carry is on (C=1)
;********************** start shift to left****************************
div21: MOV A,CR3 ;Get high byte divisor to rotate righ through the carry
RRC A ;rotate high byte divisor right through the carry
MOV CR3,A ;Save result
MOV A,CR2 ;Get low byte divisor to rotate righ through the carry
RRC A ;rotate low byte divisor right through the carry
MOV CR2,A ;Save result
clr c ;clear carry flag
MOV divalto,CR1 ;Save high byte dividend
MOV divbajo,CR0 ;Save low byte dividend
MOV A,CR0 ;Get low byte dividend
SUBB A,CR2 ;subtraction of low byte dividend with low byte divisor
MOV CR0,A ;Save result
MOV A,CR1 ;Get high byte dividend
SUBB A,CR3 ;subtraction of high byte dividend with high byte divisor
MOV CR1,A ;Save result
JNC div31 ;Jump if carry=0, if not (carry is on) then
MOV CR1,divalto ;Get copy of high byte dividend and discard subtraction result
MOV CR0,divbajo ;Get copy of low byte dividend and discard subtraction result
div31: CPL c ;Complement to carry
MOV A,R4 ;Get temporal low byte resul division
RLC A ;Rotate accumulator left through the carry
MOV R4,A ;Save result
MOV A,R5 ;Get temporal high byte result division
RLC A ;Rotate accumulator left through the carry
MOV R5,A ;Save result
DJNZ B,div21 ;continues loop until counter B=0
RET ;Return to main program
;************************************************************************
;****RUTINA QUE RESETEA TODOS LOS REGISTROS DEL BANCO CERO Y AL REGISTRO *
;***************B PARA INICIAR UNA OPERACION ALGEBRAICA*******************
LIMPIAR: MOV R3,#00H ;CLEAR R3 REGISTER
MOV R4,#00H ;CLEAR R4 REGISTER
MOV R5,#00H ;CLEAR R5 REGISTER
MOV R6,#00H ;CLEAR R6 REGISTER
MOV R7,#00H ;CLEAR R7 REGISTER
MOV B,#00H ;CLEAR B REGISTER
RET
;---------------------DELAY TIME ROUTINE-------------------------------
;RETAR: MOV R5, #024H ;Retardo deshabilitado 11/Abril/05 x CHR
;BACK5: MOV R4, #0FFH ;Solo para fines de prueba.
;BACK4: MOV R3, #0FFH
;BACK3: DJNZ R3, BACK3
; DJNZ R4, BACK4
; DJNZ R5, BACK5
; RET
;&&&&&&&&&&&&&&&&&& CONTROL &&&&&&&&&&&&&&&&&&&&&&&&&&&&
;--------DISPLAY DATA OF VELOCITY SENSOR (VS)---------------------
MOSTRAR: MOV POS, #87H
CALL CURSOR
MOV NIBLE, #00H
MOV NIBLE+1, TL0
CALL SALIDA
CLR FLAG.0
RET
;******* SUB-ROUTINE TO MOVE THE CURSOR POSITION IN LCD MODULE-----
CURSOR: CLR P3.7 ;CHANGE TO COMMAND MODE
MOV A, POS ;GET POSITION CURSOR
CALL INS
SETB P3.7 ;CHANGE TO DATA MODE
RET
;******* SUB-ROUTINE TO GIVE FORMAT TO THE DATA**********************
SALIDA: MOV R7, NIBLE
J22: MOV A, R7
SWAP A
CALL FORMAR ;GIVE FORMAT TO HIGH NIBBLE BYTE
INC POS
CALL CURSOR
MOV A, R7
CALL FORMAR ;GIVE FORMAT TO LOW NIBBLE BYTE
INC POS
JB FLAG.0, J11 ;RETURN
MOV R7, NIBLE+1
SETB FLAG.0 ;FLAG INDICATE THAT THE FOUR DATA HAVE BEEN ARRANGED
JMP J22
J11: RET
;****** RUOTINE THAT GIVES ASCII FORMAT TO DATA ******************************
FORMAR: ANL A, #0FH
MOV R0, A ;SAVE ACCUMULATOR
MOV A , #09H
SUBB A, R0
JC LETRA ;IF CARRY IS ON THE DATA IS A LETTER
MOV A, R0
ADD A,#30H
CALL INS
RET
LETRA: CLR C
MOV A, R0
ADD A,#37H
CALL INS
RET
;****** DISPLAY DATA IN LCD MODULE***********************************
INS: MOV P1, A
SETB P3.6
CALL DELAY
CLR P3.6
RET
DELAY: MOV R5,#010H
BACK1: MOV R6,#0CFH
BACK2: DJNZ R6, BACK2
DJNZ R5, BACK1
RET
;-----------------SERIAL COMMUNICATION ROUTINE ------------------------
SERIAL: MOV IE, #90H ;INTERRUPTION CONFIGURATION OF SERIAL PORT
MOV IP, #10H ;ASSIGN HIGH PRIORITY TO THE SERIAL PORT INTERRUPTION
CALL CONFI ;CONFIGURATION OF SERIAL PORT AS TRANSMISOR-RECEPTOR IN MODE1
MOV A, TL0
MOV SBUF,A
JH: JBC FLAG.2, J2 ;ASK IF DATA HAS BEEN TRANSFERED
JMP JH ;IF NOT CONTINUES LOOP
J2: JBC FLAG.1, J1 ;ASK IF DATA HAS BEEN RECEIVED
JMP J2
J1: MOV A, SBUF ;MOVE DATA OF SERIAL BUFFER TO ACC.
MOV REFERENCIA,A
MOV TMOD, #15H ;TIMER0 IS CONFIGURED AS 16-BIT COUNTER AND TIMER1 AS 16-BIT TIMER
MOV T2CON, #00H ;TIMER2 IS CONFIGURED AS AUTO-RELOAD 16-BIT TIMER
MOV IE, #00H ;CONFIGURATION OF SERIAL PORT INTERRUPTION
MOV IP, #00H ;ASIGNA LA PRIORIDAD MAS ALTA A LA INTERRUP
RET
RUIN: JBC RI, JA
JBC TI, JB
RETI
JA: SETB FLAG.1 ;FLAG TO INDICATE THAT A DATA HAS BEEN RECEIVED
RETI
JB: SETB FLAG.2 ;FLAG TO INDICATE THAT DATA HAS BEEN TRANSFERED
RETI
;------------ TIMER 1 IS CONFIGURED AS BAUD RATE GENERATOR---------------------
CONFI: MOV TMOD,#20H ;TIMER1 IS CONFIGURED AS TIMER
MOV TCON,#40H ;ENABLE TIMER 1
MOV TH1, #0FDH ;MOVE DATA FOR AUTOLOAD
;------------------------SERIAL PORT CONFIGURATION-----------------------------
MOV SCON,#070H ;SERIAL PORT CONFIGURATION IN MODE 1
MOV PCON,#00H ;CLEAR SMOD(MULTIPLICADOR DE BAUDIOS) MOVE ZERO
RET
END ;END OF MAIN PROGRAM
;NOTE:
;THIS PROGRAM RECEIVES THE REFERENCE SIGNAL IN PULSES PER SECONDS FROM PC, PERFORMANCE
;THE PI ALGORITHM AND WHEN THE REFERENCE IS REACHED, DISPLAYS THE DATA OF THE VELOCITY
;SENSOR ("VS") IN THE LCD MODULE AND AFTER SEND THIS DATA TO THE PC.
;AND WAITS FOR A NEW REFERENCE

Friday, June 26, 2009

configure for remote logg

-------------------------------------------------------------------------------------------------
Instruction procedure to configure logg messages on remote system.
-------------------------------------------------------------------------------------------------

The whole procedure describes the procedure for remote logging on *nix
like system.

The *nix like system consists directory /etc which consists of all the
system information eg:-
a): System initialization at varios run levels.
b): All networking files which are read at boot time.
c): All the password files for all users
d): All files consisting logg information.

Here we will be seeing what all option to be changed to upgrade a system
for remote logging.

*nix systems reads the logg info from /dev/log
port number is typically set to /udp/514.

---------NEED-----------

First of all we need to understand what are logg files.
These files get all the system, network, user, etc information during
normal system boot operation or any user operation or when system has
to send inforamtion about itself to the administrator.

--------CHANGES----------

These logg information gets configured by a file

/etc/syslog.conf

This file consists of which type of logg file will go in which file
eg:-
*.* /var/log/messages
It simply tells that all the information will be send to var/log/messages
file.

To configure our system for remote logging. We can add a line in this file(*)

*.info; mail.none @remote

Where remote is the name of remote system on which remote loggs are to
be read.

NOTE* It should be written with root privelage.

The second file which is needed to be changed is /etc/hosts
It consists the IP address from where the system is going to listen.

Adding the following line configures the the system for remote logging.
IP domain name system name
10.112.62.72 hclit200089hyutgh.hclit.com remote

IP address is the address at which logging info would go.
domain name is domain name given to the system
system name is the name gievn to the system which would
be same as given in syslog.conf file.

----------------------Starting the logging on remote sytem -----------------------------

pname -HUP syslogd
Will restart the sylogd hence following the new configuration.

-----------------------------------------------------------------------------------------------------

-------------------Starting a loghost on another machine--------------------------------

In order to create a loghost, pick one machine and secure it as much as possible.
Basically, don’t run anything on this machine besides syslogd. Turn off inetd,
sendmail, everything, but make sure you have basic networking up. Possibly don’t
even run ssh on this machine. That way, the only way to view the log files on the
loghost would be to physically log into the console.

Make sure the time is always correct on the loghost.
In order to allow the loghost to receive syslog messages from other
machines, you may need to enable it to receive remote logging. (Find out first by
reading the syslogd man pages). Do this by adding the –r command line upon
syslogd startup.

Edit /etc/rc$(RUNLEVEL).d/syslog(*), and find the line:

/usr/sbin/syslogd

and change it to:

/usr/sbin/syslogd -r

Again, make sure the loghost is as secure as possible: the only thing it
should be running is syslogd.
NOTE*:- The runlevel is to be checked from the /etc/inittab file what is the default
log level accordingly set the same in RUNLEVEL

(-----NOTE *-----) : Check for all security levels if possible remove all security option
on it so that logging can be done.

Vijayendra Suman
Dated : 7 May 2007