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
28 ; calculate the 1st sector of the data area
32 ; load the root directory
37 call read_cluster_chain
44 cmp byte [es:di], 0 ; we have no more entries to look at
46 cmp byte [es:di], 0xe5 ; the entry was only previously used and as such not worth looking at
59 add di, 9 ; knowing that cmpsb incremented this by 11, we can also increment it by 9
60 ; right here so we can use 1 less offset below
61 ; stage 3 has been found and ES:DI points to its directory entry
62 mov ax, [es:di] ; load high half of the 1st cluster
64 mov ax, [es:di+(dir_entry.firstcluslo-dir_entry.firstclushi)] ; load low half of the 1st cluster
65 mov bx, STAGE3_SEGMENT
68 call read_cluster_chain ; read stage 3
70 call STAGE3_SEGMENT:STAGE3_OFFSET ; call stage 3
71 jmp .halt ; halt in case we return, which should never happen
74 mov si, stage3_missing
101 stage3_missing: db "LOADER.BIN is missing", 0
102 STAGE3_NAME: db "LOADER BIN"
104 times 510-($-$$) db 0