]> git.lizzy.rs Git - loadnothing.git/commitdiff
Broken stage 2 loader
authorHimbeerserverDE <himbeerserverde@gmail.com>
Sun, 11 Sep 2022 21:17:44 +0000 (23:17 +0200)
committerHimbeerserverDE <himbeerserverde@gmail.com>
Sun, 11 Sep 2022 21:17:44 +0000 (23:17 +0200)
Makefile
stage1/boot.asm

index 9856b63fcfe611e0a0635fa366a5c4040aeb0ece..d6a4fe5e923143524b49ad836d731b02b057ca7b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,9 +11,9 @@ stage2/target/x86_64-loadnothing/debug/stage2: stage2/src/main.rs
        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
index 096a4016a6e4ee2602d697783b812c9b2e5e84aa..98484699d17bbd79398de8b6644ca31c4b99f1aa 100644 (file)
@@ -1,6 +1,9 @@
 [bits 16]
 [org 0x7c00]
 
+%define STAGE2START 0x7e00
+%define STAGE2SIZE 0xFF
+
 ; Initialize registers
 xor ax, ax
 mov ds, ax
@@ -33,6 +36,13 @@ print_bytes_si_loop:
 
        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
@@ -56,8 +66,23 @@ boot:
        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