saves the drive ID it was booted from into variable BOOT_DRIVE,
sets the stack to 0x9000
and sets ES & DS to 0 so that memory operations act from 0x0000 as the base address.
calls load_stage2 to load stage2 of the bootloader...
moves BOOT_DRIVE into AX so stage2 can read AX to get the drive ID,
then jumps to stage2 code and starts executing it.
sets BX to the memory address of where to load stage2,
puts the number of sectors to read on the stack for error checks later.
sets up registers to call BIOS 0x13 to load stage2 into memory,
then calls BIOS.
checks the carry flag to see if the BIOS called failed,
if so, prints an error message and halts.
compares the number on the stack with AL, if they are not equal,
then there was an error, prints an error message and halts.
returns if no checks failed.
print_string: uses BIOS calls to print a string.
saves the drive ID AX into variable BOOT_DRIVE
calls load_kernel to load... kernel...
writes kernel start address into memory at 0x07FA as 4Bytes
writes the sector count of the kernel to memory at 0x07F8 as 2Bytes
disables interrupts,
calls scan_hardware,
loads the GDT,
and sets the protected mode bit in CR0.
its now in 32bit mode.
far jumps to mode32b_start.
| size | reserved | sector-to-read | offset | segment | LBA |
|---|---|---|---|---|---|
| 1B | 1B | 2B | 2B | 2B | 8B |
calls scan_ram
sets DX to the start of e820's entry buffer,
and clears e820's entry count.
calls BIOS to get system memory map entry.
checks if EAX equals "SMAP" aka 0x534D4150, if not equal, return,
checks if carry set, if so, return,
if EBX zero, then return.
incerment e820's entry count by 1,
add 24 to DX as not to overwrite the previous e820 entry.
jumps back to read the next entry.
i dont remember how it works
clears all registers with a 32 bit value to reset the CPU cache.
sets stack to 0x90000.
cld is vary much so required.
calls the kernel code.
halts if the kernel ever returns.
print_string: uses BIOS calls to print a string.
used to allow the linker to connect the bootloader and kernel