I am making a small operating system and written a working kernel in c for it. But how will I create a bootloader to call the kernel and compile and link the kernel and bootloader. I am using gcc and yasm. I can also use nasm if required.
-
hello to SO! please follow rules of asking available here: [How-to-ask](https://stackoverflow.com/help/how-to-ask) – Maciej S. Mar 01 '19 at 01:22
-
I thing i have followed those rules! – Dr. MK Singh Mar 01 '19 at 15:01
-
1If you convert your kernel to a binary output file and rename it stage2.bin (and have your _C_ code start at memory location 0x7e00 then you can use the answer in this [Stackoveflow question](https://stackoverflow.com/q/54894585/3857942) . That is assuming you are on x86 and have legacy BIOS support. You don't give us enough details about what platform you are targeting?x86? ARM etc – Michael Petch Mar 01 '19 at 20:26
1 Answers
Basically there are 2 steps (highly simplified) during boot (specifically related to ARM based Embedded Linux boards):
When the power is supplied, the processor wakes up and its ROM code is executed. This code is hardcoded into the chip provided by the manufacturer. This ROM code after doing basic harware preparation and sanity checks calls the bootloader. You need to look into the docs as to where (which address) this initial code looks for the bootloader. If it find the bootloader, it relinquishes its control and the control passes over to the bootloader.
Again the bootloader looks for few pre-specified memory locations for the kernel binary (compiled image). It (bootloader) then relinquishes its control and passes control to the kernel (with few arguments and also sometimes the memory location of device tree).
AFAIK, the kernel and bootloader are not "compiled/linked" together usually. It is a process of one stage completely relinquishing itself and passing control to another (as explained in above 2 steps).

- 1,056
- 1
- 11
- 16