From: Frank K. <fbk...@zy...> - 2009-07-09 15:52:33
|
H. Peter Anvin wrote: > 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] > > That should be > > extern _K_main > > No brackets... Now why haven't I seen my reply to Zulfi... in which I point out that "-f bin" isn't going to like it without the brackets, either? Maybe "nasm-users" doesn't like me... Anyway... I tried the following experiment... Since I don't "do" C (much), I made up a "fake" kmain, which simply prints the letter "K" on the screen and returns. Assembled with "-f obj". Added a "..start:" label to "test_kernel2", and assembled that with "-f obj". Since I've got Alink working under Linux, I tried to link 'em with "alink -oCOM test_kernel2.obj kmain.obj". Alink warns that it's discarding data at offset... well, all of 'em... and produces a zero-length .com file. That's not going to help. So tried "-oEXE". Got an .exe! Since I don't have an MZ loader at hand, nor "exe2bin" (which might work), I simply removed the header with a text editor. The offsets happened to work out - I doubt if this will always be true! I think we're going to need a proper MZ loader to handle relocations, eventually. But for now... I combined "boot.bin" with this result using "cat", and wrote the resulting "image.bin" to floppy. Wrote that to floppy with "dd". Booted, and after "Welcome to the kernel", saw 'K' printed... repeatedly. Progress! This isn't exactly what you want to do, but leads me to believe that, with the proper tools, it may not be as difficult as I imagined. (famous last words...) Best, Frank |