]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - boot/x86/vbr-fat32.s
Rehaul the memory map
[nameless-os.git] / boot / x86 / vbr-fat32.s
index b4c71489e5bf9d421ded07e145550c13e37cb716..439157f3c4299b6f7bf116f3f519fcbb0d860deb 100644 (file)
@@ -2,14 +2,19 @@
 ; This is what's going to be on most USB sticks and HDDs, for now
 
 bits 16
-org 0x7c00
+org 0xfe00
 cpu 686
 
-STAGE3_ADDRESS equ 0x8000
+STAGE3_ADDRESS equ 0x1800
 STAGE3_SEGMENT equ STAGE3_ADDRESS >> 4
 STAGE3_OFFSET equ STAGE3_ADDRESS & 0xf
 
-%include "fat32-structs.s"
+%include "fat32/fat32-structs.s"
+
+%macro print 1
+       mov si, %1
+       call print_str
+%endmacro
 
 _start:
        jmp short real_start
@@ -20,7 +25,7 @@ times 0x57 db 0 ; skip past BPB
 real_start:
        sti
        ; no need to set up segments and stack again, because MBR did it for us
-       mov bp, 0x7c00
+       mov bp, 0xfe00
 
        ; we expect the boot drive to be in DL and our partition table entry in DS:SI
        mov [BOOT_DRIVE], dl
@@ -66,19 +71,21 @@ real_start:
        mov es, bx
        mov di, STAGE3_OFFSET
        call read_cluster_chain ; read stage 3
-       mov ds, bx
-       call STAGE3_SEGMENT:STAGE3_OFFSET ; call stage 3
+       mov dl, [BOOT_DRIVE]
+       call STAGE3_ADDRESS ; call stage 3
        jmp .halt ; halt in case we return, which should never happen
 
 .stage3_missing:
-       mov si, stage3_missing
-       call print
+       print stage3_missing
+       jmp .halt
+.error:
+       print read_error
 .halt:
        hlt
        jmp short $-1
 
 ; ds:si - string
-print:
+print_str:
        pusha
        mov ah, 0xe
        xor bh, bh
@@ -96,7 +103,7 @@ print:
        popa
        ret
 
-%include "fat32.s"
+%include "fat32/fat32.s"
 
 stage3_missing: db "LOADER.BIN is missing", 0
 STAGE3_NAME: db "LOADER  BIN"