1 bits 16 ; boot sectors run in real mode
2 org 7C00h ; BIOS loads us at 0x7c00
4 KERNEL_OFFSET equ 1000h ; where we will load our kernel
6 mov [BOOT_DRIVE], dl ; BIOS puts the number of our boot drive in dl, so we will want to remember this
8 mov bp, 9000h ; initialize stack at a spot sufficiently distanced from this code
13 xor ax, ax ; clear accumulator
14 int 13h ; BIOS disk services, with a cleared accumulator this will reset the disk controller
15 jc reset_error ; halt if controller reset fails
17 mov ah, 2 ; instruct BIOS's interrupt 13h to read sectors
18 mov al, 10 ; load 10 sectors, might be excessive (for now) but it's still good to do so
19 xor ch, ch ; read from 1st cylinder
20 mov cl, 2 ; start reading from 2nd sector, right after the boot sector
21 xor dh, dh ; read from 1st head
22 xor bx, bx ; clear B register
23 mov es, bx ; clear extended segment
24 mov bx, KERNEL_OFFSET ; put the sectors in our desired offset
25 ; dl holds the number of the drive to read from, but BIOS already filled this in
27 jc read_error ; halt if read fails
28 cmp al, 10 ; make sure we actually read 10 sectors
29 jl read_error ; halt if we didn't
30 jmp switch_to_pm ; if all is good, begin the switch to 32-bit protected mode
48 %include "protected.s"
50 BOOT_DRIVE db 0 ; reserve a spot in RAM for our boot drive variable
53 dw 0AA55h ; MBR signature