Hello,
I never understood what the difficulty of writing boot programs in C is. It really is not hard and not much different then any other operating system service. There is a common error made however; the
boot record is not a
boot loader. The boot record should be written in assembly however through some hacks it can be written with some ancient compilers that support 16 bit binary output.
The boot loader itself can be written in C with ease. You have a few options here depending on firmware and design,
1. With
EFI Firmware, you can boot directly into a C boot loader and skip the boot record and real mode stages altogether. This is by far the simplest method; the OSDev Wiki has a good article on EFI.
2. With
BIOS Firmware, you have a few options. You just need an assembly language stub to set up the C environment and jump to the actual C boot loader. You need to decide on design structure here; the C boot loader portion must be able to call the BIOS services directly and be able to fall back to real mode as needed in order to
chain load other boot records. For example, if the C boot loader runs in 32 bit protected mode, you must support either
v8086 mode or dropping down to real mode to call the BIOS [this is the method I use.] If the C boot loader is compiled as 16 bit real mode code instead, you can call it directly [not recommended though due to real mode limitations.]
Build a single boot image containing both your assembly stub program and the C boot loader and have the boot record load and execute the boot image. The stub program must set up the environment and copy over the C boot loader part of the boot image to where it should be ran in memory and calls its entry point. This method can be extended in multiple loading stages to support boot images of any size.
There are many different ways and possible designs you can come up with, but it really is not that hard. I can provide more information on my specific design if interested, but I encourage you to look farther into the requirements and try to find one that works best for your design goals and needs. I also encourage looking into other C boot loaders that are open source to get some more insight - but take note that there is no best design; it is whatever that is best for your needs and most compatible with your build environment.
Finally, I highly advise knowing how to use your tools correctly. If you ever come across a compiler or linker error that you cannot resolve, you are not yet ready for this task. Sorry, but its just how it is; those are basic errors.
The whole point of a bootloader is getting C code running
No. The point of a boot loader is, as its name implies, getting an operating system loaded properly into memory and transferring control. C boot loaders provide all the benefits of high level languages over assembly language : through good design one can achieve firmware independence and hardware independence and extensability; they can effectively be their own little operating system themselves. Many boot loaders also act as boot managers to allow chain loading other boot applications or operating systems.