diff options
Diffstat (limited to 'rdoff/test')
-rw-r--r-- | rdoff/test/Makefile | 2 | ||||
-rw-r--r-- | rdoff/test/makelib | 14 | ||||
-rw-r--r-- | rdoff/test/rdftest1.asm | 54 | ||||
-rw-r--r-- | rdoff/test/rdftest2.asm | 33 | ||||
-rw-r--r-- | rdoff/test/rdtlib.asm | 48 | ||||
-rw-r--r-- | rdoff/test/rdtmain.asm | 47 | ||||
-rw-r--r-- | rdoff/test/testlib.asm | 18 |
7 files changed, 216 insertions, 0 deletions
diff --git a/rdoff/test/Makefile b/rdoff/test/Makefile new file mode 100644 index 0000000..8e9f42e --- /dev/null +++ b/rdoff/test/Makefile @@ -0,0 +1,2 @@ +clean: + rm -f *.rdf *.rdx diff --git a/rdoff/test/makelib b/rdoff/test/makelib new file mode 100644 index 0000000..baa4676 --- /dev/null +++ b/rdoff/test/makelib @@ -0,0 +1,14 @@ + +LIBNAME=$1; +shift; + +if [ "$LIBNAME" = "" ]; then + echo 'Usage: makelib <library name> <module> [...]' +fi + +rdflib c $LIBNAME + +for FILE in $*; do + rdflib a $LIBNAME $FILE $FILE +done + diff --git a/rdoff/test/rdftest1.asm b/rdoff/test/rdftest1.asm new file mode 100644 index 0000000..76f1e43 --- /dev/null +++ b/rdoff/test/rdftest1.asm @@ -0,0 +1,54 @@ + ;; program to test RDOFF production and linkage + + ;; items to test include: + ;; [1] relocation within the same segment in each module + ;; [2] relocation to different segments in same module + ;; [3] relocation to same segment in different module + ;; [4] relocation to different segment in different module + ;; [5] relative relocation to same module + ;; [6] relative relocation to different module + ;; [7] correct generation of BSS addresses + +[SECTION .text] +[BITS 32] + +_main: + mov ax,localdata ; [2] (16 bit) => 66 b8 0000 + mov eax,localdata2 ; [2] (32 bit) => b8 0000000a + +[EXTERN _fardata] + + mov eax,[_fardata] ; [4] => a1 00000000 (+20) + mov cx,next ; [1] => 66 b9 0012 +next: + call localproc ; [5] => e8 00000019 + +[EXTERN _farproc] + mov eax,_farproc ; [3] => b8 00000000 (+40+0) + call _farproc ; [6] => e8 -$ (-0+40+0) (=1f) + + mov eax,localbss ; [7] => b8 00000000 + +[GLOBAL _term] +_term: xor ax,ax ; => 66 31 c0 + int 21h ; => cd 21 + jmp _term ; => e9 -0a (=fffffff6) + +localproc: + ret ; => c3 + +[GLOBAL _test1proc] +_test1proc: + call localproc ; [5] => e8 -$ (-0+0+?) (=-6=fffffffa) + ret ; => c3 + +[SECTION .data] +[GLOBAL localdata2] +localdata: db 'localdata',0 +localdata2: db 'localdata2',0 +farref: dd _fardata ; [3] => 0 (+20) +localref: dd _main ; [2] => 0 (+0) + +[SECTION .bss] +localbss: resw 4 ; reserve 8 bytes BSS +
\ No newline at end of file diff --git a/rdoff/test/rdftest2.asm b/rdoff/test/rdftest2.asm new file mode 100644 index 0000000..25b8c18 --- /dev/null +++ b/rdoff/test/rdftest2.asm @@ -0,0 +1,33 @@ + ;; rdftest2.asm - test linkage and generation of RDOFF files + +[SECTION .text] +[BITS 32] + +[GLOBAL _farproc] +[EXTERN _test1proc] +[EXTERN localdata2] +[EXTERN _term] +_farproc: + + mov bx,localdata2 ; [4] 0 => 66 bb 000a(+0) + mov eax,_term ; [3] 5 => b8 00000000(+26+0) + call _test1proc ; [6] A => e8 fffffff2(-40+0+31)(=ffffffe3) + + mov eax,_farproc ; [1] => b8 00000000(+40) + add eax,[_fardata] ; [2] => 03 05 00000000(+20) + + mov ebx,mybssdata ; [7] => bb 00000000(+08) + call myproc ; [5] => e8 00000001 + ret + +myproc: + add eax,ebx + ret + +[SECTION .data] +[GLOBAL _fardata] +_fardata: dw _term ; [4] +_localref: dd _farproc ; [2] + +[SECTION .bss] +mybssdata: resw 1 diff --git a/rdoff/test/rdtlib.asm b/rdoff/test/rdtlib.asm new file mode 100644 index 0000000..6c2b8ec --- /dev/null +++ b/rdoff/test/rdtlib.asm @@ -0,0 +1,48 @@ + ;; library functions for rdtmain - test of rdx linking and execution + + ;; library function = _strcmp, defined as in C + +[SECTION .text] +[BITS 32] + +[GLOBAL _strcmp] +_strcmp: + push ebp + mov ebp,esp + + ;; ebp+8 = first paramater, ebp+12 = second + + mov esi,[ebp+8] + mov edi,[ebp+12] + +.loop: + mov cl,byte [esi] + mov dl,byte [edi] + cmp cl,dl + jb .below + ja .above + or cl,cl + jz .match + inc esi + inc edi + jmp .loop + +.below: + mov eax,-1 + pop ebp + ret + +.above: + mov eax,1 + pop ebp + ret + +.match: + xor eax,eax + pop ebp + ret + +[SECTION .data] +[GLOBAL _message] + +_message: db 'hello',0
\ No newline at end of file diff --git a/rdoff/test/rdtmain.asm b/rdoff/test/rdtmain.asm new file mode 100644 index 0000000..626a2e2 --- /dev/null +++ b/rdoff/test/rdtmain.asm @@ -0,0 +1,47 @@ + ;; rdtmain - main part of test program for RDX execution. + ;; returns true (0) if its parameter equals the phrase "hello" + ;; "hello" is stored in the library part, to complicate the + ;; linkage. + + ;; assemble and link with the following commands: + ;; nasm -f rdf rdtmain.asm + ;; nasm -f rdf rdtlib.asm + ;; ldrdf rdtmain.rdf rdtlib.rdf -o rdxtest.rdx + + ;; run with 'rdx rdxtest.rdx [parameters]' on a Linux (or possibly + ;; other 32 bit OS) systems (x86 architectures only!) + ;; try using '&& echo Yes' afterwards to find out when it returns 0. + +[EXTERN _strcmp] ; strcmp is an imported function +[EXTERN _message] ; imported data +[SECTION .text] +[BITS 32] + + ;; main(int argc,char **argv) +[GLOBAL _main] +_main: + push ebp + mov ebp,esp + + ;; ebp+8 = argc, ebp+12 = argv + + cmp dword [ebp+8],2 + jb error ; cause error if < 1 parameters + + mov eax, [ebp+12] ; eax = argv + + mov ebx, [eax+4] ; ebx = argv[1] + mov ecx, _message ; ecx = "hello" + + push ecx + push ebx + call _strcmp ; compare strings + add esp,8 ; caller clears stack + + pop ebp + ret ; return return value of _strcmp + +error: + mov eax,2 ; return 2 on error + pop ebp + ret diff --git a/rdoff/test/testlib.asm b/rdoff/test/testlib.asm new file mode 100644 index 0000000..6ee3d89 --- /dev/null +++ b/rdoff/test/testlib.asm @@ -0,0 +1,18 @@ +; program to test retrieval of and linkage to modules in libraries by +; ldrdf + +[SECTION .text] +[GLOBAL _main] +[EXTERN _strcmp] + +_main: + push dword string1 + push dword string2 + call _strcmp + add esp,8 ; doh! clear up stack ;-) + ret + +[SECTION .data] + +string1: db 'abc',0 ; try changing these strings and see +string2: db 'abd',0 ; what happens! |