[org 0x7c00]
%define STAGE2START 0x7e00
-%define STAGE2SIZE 0x7f
+%define STAGE2SECTORS (STAGE2SIZE + 511) / 512
; Initialize registers
xor ax, ax
; Move cursor to 0, 0 on page 0
mov ah, 0x02
- mov bh, 0 ; Page
- mov dh, 0 ; Row
- mov dl, 0 ; Column
+ mov bh, 0 ; Page
+ mov dh, 0 ; Row
+ mov dl, 0 ; Column
int 0x10
- mov ch, 33 ; Our string is 33 characters long
+ mov ch, 33 ; Our string is 33 characters long
mov si, hello
call print_bytes_si
- mov ah, 0x02 ; Read sectors
- mov al, STAGE2SIZE ; Stage 2 size (16 MiB) in sectors
- xor ch, ch ; Cylinder 0
- mov cl, 2 ; Second sector, they start at 1
- xor dh, dh ; Head 0
- mov dl, 0x80 ; Hard Drive 1
- mov bx, STAGE2START ; Memory address to load stage 2 into
+ mov ah, 0x02 ; Read sectors
+ mov al, STAGE2SECTORS ; Stage 2 size in sectors
+ xor ch, ch ; Cylinder 0
+ mov cl, 2 ; Second sector, they start at 1
+ xor dh, dh ; Head 0
+ mov dl, 0x80 ; Hard Drive 1
+ mov bx, STAGE2START ; Memory address to load stage 2 into
int 0x13
- jc stage2_error ; Carry flag is set if there was an error
+ jc stage2_error ; Carry flag is set if there was an error
- cmp al, STAGE2SIZE ; Have we read as many sectors as we requested?
+ cmp al, STAGE2SECTORS ; Have we read as many sectors as we requested?
jne stage2_error
- jmp STAGE2START ; Hand over control to stage 2
+ jmp STAGE2START ; Hand over control to stage 2
hello db 'Welcome to loadnothing stage 1!', 13, 10 ; \r\n
error db 'Error reading stage 2 from disk', 13, 10 ; \r\n