problems with linking objects -- must know some nasm\ASM\linker
Hello
I present 2 problem cases ,each case is followed with tested code thankyou for any help --paul-- .................................................................................................... ........................... CASE 1-- case 1 will compile but segfault when I insert into kernel using insmod paul@box:~$ nasm -f elf foo.asm -o a.o paul@box:~$ gcc -c foo.c -o b.o paul@box:~$ ld -r a.o b.o -o kernelmod.o paul@box:~$ sudo insmod -f kernelmod.o Password: Warning: kernel-module version mismatch kernelmod.o was compiled for kernel version 2.4.20 while this kernel is version 2.4.20-xfs Warning: loading kernelmod.o will taint the kernel: no license See [xxx] for information about tainted modules Warning: loading kernelmod.o will taint the kernel: forced load Segmentation fault gee, other than version mismatch I dont get why this code fails, it should play some cool tones on my pc speaker Code:
CASE 2-- these 2 modules will not compile, they follow the same 'call external asm routine' format except this should be compiled to ELF EXECUTABLE format ,ie it's NOT a loadable module paul@box:~$ nasm -f elf test.asm paul@box:~$ gcc -O3 test.c test.o -o TEST In file included from /usr/include/linux/sched.h:14, from /usr/include/linux/mm.h:4, from test.c:1: /usr/include/linux/timex.h:173: field `time' has incomplete type In file included from /usr/include/asm/smp.h:15, from /usr/include/linux/smp.h:14, from /usr/include/linux/sched.h:23, from /usr/include/linux/mm.h:4, from test.c:1: /usr/include/asm/fixmap.h:80: parse error before "pgprot_t" In file included from /usr/include/asm/smp.h:21, from /usr/include/linux/smp.h:14, from /usr/include/linux/sched.h:23, from /usr/include/linux/mm.h:4, from test.c:1: /usr/include/asm/apic.h:85: parse error before "unsigned" In file included from /usr/include/linux/sched.h:23, from /usr/include/linux/mm.h:4, from test.c:1: /usr/include/linux/smp.h:29: parse error before '(' token as you can see ,problems with headers. I need __get_free_pages() ,which is defined in linux/mm.h Are there really typos in these headers or is it the oder in which they are included??? I have found that sometimes order matters if header.h is dependant on variables declared in another header, the latter must precede the former [CODE --------------------- code case 2--------------------------------- ===== c module ============ #include <linux/mm.h> int * kep; void y() { // ring0 code to jmp to asm volatile ("mov $0x666,%di; in $0x61,%al" ); asm volatile ("or $3,%al;out %al,$0x61" ); asm volatile ("mov $0xb6,%al;out %al,$0x43"); asm volatile ("mov $0x14,%dx; mov $0x4F38,%ax"); asm volatile ("div %di; out %al,$0x42"); asm volatile ("mov %ah,%al; out %al,$0x42 "); } main() { kep = __get_free_pages(0x40, 3); JUMP(); } ================== asm module ==================== ; test source file for assembling to ELF ; build with: ; nasm -f elf elftest.asm ; gcc -o elftest elftest.c elftest.o ; (assuming your gcc is ELF) ; This file should test the following: BITS 32 GLOBAL JUMP EXTERN kep EXTERN y SECTION .text JUMP: mov dword esi,[kep] lea edi,[y] mov byte [esi],0xea mov dword [esi+1],edi jmp dword [kep] SECTION .data [/CODE] |
Well hmm.........for case code #1 -- I tried this.......
Code:
Chessmaster ~/tiny elf/tiny $ nasm -f elf sound.asm and when I tried it just exactly as you did........I got the same error.......except I have the 2.4.27 kernel...........BUT the compiled version was for 2.4.22........... your code looks good, but something in the kernel headers and the version of Glibc for which they were compiled against must be affecting the output....... |
All times are GMT -5. The time now is 07:59 PM. |