Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
The first part of your bootloader will be 16-bit code. It's possible to create 16-bit code with C (I have seen people doing it in Borland C 2.0) but there are a limited number of compilers and I don't know a free one (free as in free speech, not free beer).
With free compilers like GCC you can make 32-bit code. I wrote the 16-bit parts in assembly, after switch to a protected mode 32-bit codesegment you can use code written in C.
There are some complications: In the bootloader you need to call the BIOS for loading disksectors. You have to choose between writing the routines for loading files in memory in 16-bit realmode (when the memory is full you can switch to protected mode to move the read files to a higher part in memory) or in 32-bit protectedmode (for sector reading you temporary switch back to realmode). If you choose 32-bit you can write everything in C, but you have to write some assembly routines switching to realmode and reading sectors.
Candy wrote:There is BCC, Bruce's C Compiler. That is a 16-bit compiler but it is a bit awkward to use as it doesn't do C89, let alone any variant after that.
I know, K&R with some ANSI tacked on... using the -ansi argument might make it less-awkward.
EDIT: http://tack.sourceforge.net/ seems to have 8086 support, this was the C compiler used by Minix once upon a time, BSD licenced now.
"The ACK contains compilers for ANSI C, K&R C, Pascal, Modula-2, Occam 1, and a primitive Basic."
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
Actually, using GAS's '.code16gcc' directive, GCC can be used to write C code for a 16 bit code segment.
GAS will add the necessary address/operand override prefixes to the 32 bit instructions generated by GCC.
Just make sure you stay within your data segment limits.
For a real life example of 16 bit c code, examine the linux boot code. (arch\x86\boot)