cd stage2 && cargo build
nothing.img: magic.bin stage1/boot.bin stage2/target/x86_64-loadnothing/debug/stage2
- dd if=/dev/zero of=nothing.img bs=32M count=1
+ dd if=/dev/zero of=nothing.img bs=16M count=1
parted -s nothing.img mklabel msdos
- parted -s -a optimal nothing.img mkpart primary fat32 16M 100%
+ parted -s -a optimal nothing.img mkpart primary fat32 256s 100%
doas losetup /dev/loop1 nothing.img
doas mkfs.fat /dev/loop1p1
doas losetup -d /dev/loop1
[bits 16]
[org 0x7c00]
+%define STAGE2START 0x7e00
+%define STAGE2SIZE 0xFF
+
; Initialize registers
xor ax, ax
mov ds, ax
ret
+stage2_error:
+ mov ch, 33 ; Our string is 33 characters long
+ mov si, error
+ call print_bytes_si
+
+ jmp $ ; Infinite loop
+
; Main
boot:
; Clear the screen
mov si, hello
call print_bytes_si
- jmp $ ; Infinite loop
+ 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
+ xor dl, dl ; Drive 0
+ mov bx, STAGE2START ; Memory address to load stage 2 into
+ int 0x13
+
+ jc stage2_error ; Carry flag is set if there was an error
+
+ cmp al, STAGE2SIZE ; Have we read as many sectors as we requested?
+ jne stage2_error
+
+ jmp STAGE2START ; Hand over control to stage 2
-hello db 'Welcome to loadnothing stage 1!', 13, 10 ; \r\n
+hello db 'Welcome to loadnothing stage 1!', 13, 10 ; \r\n
+error db 'Error reading stage 2 from disk', 13, 10 ; \r\n
times (446 - ($ - $$)) db 0x00