From: Frank K. <fbk...@zy...> - 2009-07-09 15:54:57
|
zak100 wrote: > Hi, > I am trying to call 'C" functions from my tiny kernel code. Can somebody plz > help me with this? > ; call c function > extern [_K_main] > ;--- test kernel.bin--- > > ; push cs > ; push cs > ; pop ds > ; pop es > mov ax, 7E0H > mov ds,ax > mov es,ax > mov si, msg > > mov ah, 0Eh > mov bx, 7 > top: > lodsb > cmp al, 0 > jz blackhole > int 10h > jmp short top > > blackhole: > > mov cx,1000 > Delay: Loop Delay > call _K_main; this is in main.c > hlt > jmp blackhole > > msg db 'Welcome to the Kernel!', 0 > > times 0x200-($-$$) db 0 > > > I am getting following error mesg: > D:\nasm prog>nasm -f bin -o boot.bin test_kernel2.asm > test_kernel2.asm:5: error: label or instruction expected at start of line Hi Zulfi, Removing the brackets will at least give you correct syntax (extern _K_main), but binary format still doesn't know about external references. What format is your proposed _K_main in? OMF probably, for 16-bit code(???). Try assembling with "nasm -f obj test_kernel2.asm" this will produce "test_kernel2.obj", by default. If your linker won't handle long file names, you can shorten it with the "-o" switch, but your linker is probably going to be happier with ".obj" than ".bin" (maybe not?). Then... your linker is probably going to want to produce an MZ executable by default. I don't think it's too hard to write a loader for MZ, but it might be easier to persuade your linker to produce a .com file. I believe ld (for 32-bit Linux - won't help you) can be coerced to produce a flat binary, explicitly specifying origins for the various sections (if you know how - I don't). If your linker will do that, you're in luck. Failing that... I dunno. Make sure your compiler isn't producing any "dosisms" in your C code, of course. The OS-development guys may have better advice on this. Best, Frank P.S. Thanks for asking here, rather than nasm-devel, Zulfi! :) |