How can I boot my small console from a disk/cd/usb, with the following configuration:
The procedure that I want to use is that when my system starts, it boots from the disk/cd/usb, and starts my OS. For now imagine that the OS is going to be a hello world program. I actually want to see how the real world OS implement themselves.
The Boot Menu is the Windows' menu that lets you select the device you want to boot from: HDD, USB, CD-ROM etc. If the Boot Menu isn't available, you can force your computer to boot from an external and removable media (such as a USB flash drive, CD or DVD) by configuring your BIOS/UEFI settings.
On many computers, as the computer is booting, you may need to enter the boot menu (e.g., may see Press F9 for boot menu). If this option is available, press the key to enter the boot menu and then select the option to boot from the CD-ROM or DVD drive.
A bootloader must be 512 bytes. No less no more. And it must end with the standard PC boot signature: 0xAA55.
Also note a PC boots in 16 bits mode. You need to load your kernel or secondstage bootloader from that code into memory, and then jump to that code (and maybe switch the CPU to 32 bits protected mode).
For instance (nasm):
BITS 16
; Your assembly code here (510 bytes max)...
jmp $
; Fills the remaining space with 0
times 510 - ( $ - $$ ) db 0
; Boot signature
dw 0xAA55
Thas the job of a boot loader. The bootloader should be present in the first 512 bytes of a HardDisk. This location is called MBR(Master boot record)
When bios loads it checks if the media contains the MBR. it verifies the MBR signature 0xAA55 which should be present as the last 2 bytes of MBR.
Then the Bios loads the BootLoader into RAM at address 0x7C00
Then the boot loader is the one who actually loads the kernal into memory, by reading the filesystem.
usually you cannot fit in all the code in 512 bytes, so there will be a secondory boot loader.
secondary bootloader will be loaded by your primary bootloader.
secondary boot loader loads IDT and GDT (Interupt vector table and Global descriptor table). Enables A20 gate to move into protected mode.
secondary boot loader loads the 32 bit kernel from disk into memory, then jumps to the kernel code
For more information you can download Linux kernel v0.01 (First version). Look how it is done. to my surprise the code to read the File system + the code to move into protected mode is fit into 512 bytes of code.
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