3 %define STAGE2START 0x7e00
4 %define STAGE2SECTORS (STAGE2SIZE + 511) / 512
14 ; Initialize the stack
15 ; It grows down, overwriting this code
16 ; I have no idea what this does exactly (note by Lizzy: bp is base pointer, sp is stack pointer)
20 push dx ; Save boot drive (will be restored when making the int 0x13 ah=0x02 call)
26 mov ah, 0x0e ; TTY output
28 mov bl, 0x07 ; Color: Light grey on black background
33 ; Call print_al on all characters in si
34 ; si must be null terminated
36 mov cl, 0 ; Start with iteration 0 - equivalent of int i = 0
38 lodsb ; Load next characet of si into al
40 cmp al, 0 ; Null terminator?
41 je .print_str_exit ; If yes, we are done
69 ; Move cursor to 0, 0 on page 0
79 mov ah, 0x02 ; Read sectors
80 mov al, STAGE2SECTORS ; Stage 2 size in sectors
81 xor ch, ch ; Cylinder 0
82 mov cl, 2 ; Second sector, they start at 1
83 pop dx ; Restore boot drive
85 mov bx, STAGE2START ; Memory address to load stage 2 into
88 jc stage2_error ; Carry flag is set if there was an error
90 cmp al, STAGE2SECTORS ; Have we read as many sectors as we requested?
93 ; enable to unreal mode
94 ; https://wiki.osdev.org/Unreal_Mode
96 push ds ; save real mode
98 lgdt [gdtinfo] ; load gdt register
100 mov eax, cr0 ; switch to pmode by
101 or al, 1 ; set pmode bit
104 jmp $+2 ; tell 386/486 to not crash
106 mov bx, 0x08 ; select descriptor 1
107 mov ds, bx ; 8h = 1000b
109 and al, 0xFE ; back to realmode
110 mov cr0, eax ; by toggling bit again
112 pop ds ; get back old segment
115 jmp STAGE2START ; Hand over control to stage 2
117 hello db 'Welcome to loadnothing stage 1!', 13, 10, 0 ; \r\n\0
118 error db 'Error reading stage 2 from disk', 13, 10, 0 ; \r\n\0
121 dw gdt_end - gdt - 1 ; last byte in table
122 dd gdt ; start of table
124 gdt dd 0, 0 ; entry 0 is always unused
125 flatdesc db 0xff, 0xff, 0, 0, 0, 10010010b, 11001111b, 0
128 times (446 - ($ - $$)) db 0x00