> hi joe
> thanks a lot for your clear and very helpful explanation. i followed your
> recommendations but there's still a bug (or a misunderstanding). ok let's
> see:
> i write a tiny c 'program' that includes stdio.h and contains a simple
> printf statement
printf() is not going to work. Two reasons:
(1) By using "gcc -c" you are telling the compiler to just compile
your code, and not to try to link it with the C library to
create an executable. Since printf() is a function in the C runtime
library, your object file contains an undefined reference to it.
(2) Even if you could link your object with the C library (which
would make it far too large to fit in the boot sector of a
disk), it won't work, because printf() works by making use
of OS facilities for doing console I/O, and you have no
OS available at boot time.
When the boot loader is running, the only functionality you
have is that built into the hardware itself, and the BIOS. That
means that *no* standard C library calls will work; if you want
I/O you have to either use the low-level BIOS routines or
read and write the hardware I/O ports and handle the interrupts
yourself. IMO, writing a bootloader in C is not a very good
idea, because you have very little control over what the
compiler is going to do with your code, and since you need
everything to fit in 512 bytes you do need fine control
over the generated code.
For an example of a working x86 bootloader and a tiny 16-bit
OS to go with it (written in NASM and Forth), have a look at
http://home.earthlink.net/~jknapka/jkf.html
HTH,
-- Joe
Quote:> i compile it using gcc -c boot.c --> results in boot.o
> i create a binary using objcopy -O binary boot.o boot (objdump only
> seems to DISPLAY info)
> i dump it on disk using dd if=./boot of=/dev/fd0 bs=512 count=1
> so? what did i miss?
> it would be nice if you could give me another hint
> bye, marcel
-- Joe Knapka
"It was just a maddened crocodile hidden in a flower bed. It could
have happened to anyone." -- Pratchett
// Linux MM Documentation in progress:
// http://home.earthlink.net/~jknapka/linux-mm/vmoutline.html
* Evolution is an "unproven theory" in the same sense that gravity is. *