This might be OS specific I am not sure (I am working on Linux). When the BIOS brings the boot loader in the memory and the CPU starts executing it, how does it locate the OS? Is it stored in a special disk partition/well-known sector etc? If it is stored on the file system, then the boot loader needs to interact with the file system code which is stored in the OS. How is this chicken-egg problem resolved?
A bootloader falls into several parts. First of all, the BIOS fetches some code which match a very special format, called the MBR (Master Boot Record). Remember your old computer: you have to tell the BIOS in which order it will browse some device in search of that MBR. Once it has found an MBR (the MBR is 512 bytes long, ending with a magic number – 0x55aa
), it copies this piece of code at a given offset in physical memory (0x7c00
on x86), and set the Instruction Pointer to this address. Most of the time, an MBR contains a partition table and will load some extra code from the device that will help in loading the actual system: this is referred as chain loading or multi-stage loading.
Let’s elaborate that last point. Remember that the system is running at that point in real-mode, hence you can access only 1MB of physical memory, but on the other hand you can access to your HDD in a quite easy fashion through the BIOS Interrupt Call. Nowadays, operating systems ask for much more memory than 1MB, and they will want to switch the processor in protected-mode in order to have access to a full address-space (4GB, at least on a32bit system). But once the system is in protected-mode, BIOS Interrupt Call is no more available and input/output with the HDD must go through complex-setup communication such as DMA, and that setup usually doesn’t take place into the bootloader. A boot loader will switch back and forth from real-mode to protected-mode. It fetches a sector from the HDD into the 1MB address-space, and then it switches to protected-mode to copy this sector to some place into the 4GB address-space, and finally it switches back to real-mode to fetch another sector from the HDD. Once all the sectors has been fetched and copied to physical memory, the bootloader jump to the OS.
To sum-up:
multiboot
specification is used to locate an OS. Check the link below for more info on multiboot
.You may want to take a look at these resources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With