1 ; x86 bootloader for nameless-os, FAT32 VBR portion
2 ; This is what's going to be on most USB sticks and HDDs, for now
8 STAGE3_ADDRESS equ 0x8000
9 STAGE3_SEGMENT equ STAGE3_ADDRESS >> 4
10 STAGE3_OFFSET equ STAGE3_ADDRESS & 0xf
12 %include "fat32-structs.s"
18 times 0x57 db 0 ; skip past BPB
22 ; no need to set up segments and stack again, because MBR did it for us
25 ; we expect the boot drive to be in DL and our partition table entry in DS:SI
27 mov [part_table_entry], si
29 ; calculate the 1st sector of the data area
33 ; load the root directory
38 call read_cluster_chain
43 cmp byte [es:di], 0 ; we have no more entries to look at
45 cmp byte [es:di], 0xe5 ; the entry was only previously used and as such not worth looking at
56 sub di, 0xb ; "repe cmpsb" incremented this
57 ; stage 3 has been found and ES:DI points to its directory entry
58 mov ax, [es:di+dir_entry.firstclushi] ; load high half of the 1st cluster
60 mov ax, [es:di+dir_entry.firstcluslo] ; load low half of the 1st cluster
61 mov bx, STAGE3_SEGMENT
64 call read_cluster_chain ; read stage 3
66 call STAGE3_SEGMENT:STAGE3_OFFSET ; call stage 3
67 jmp .halt ; halt in case we return, which should never happen
70 mov si, stage3_missing
98 stage3_missing: db "LOADER.BIN is missing", 0
99 STAGE3_NAME: db "LOADER BIN"
101 times 510-($-$$) db 0