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 0x1800
9 STAGE3_SEGMENT equ STAGE3_ADDRESS >> 4
10 STAGE3_OFFSET equ STAGE3_ADDRESS & 0xf
12 %include "fat32/fat32-structs.s"
23 times 0x57 db 0 ; skip past BPB
27 ; no need to set up segments and stack again, because MBR did it for us
30 ; we expect the boot drive to be in DL and our partition table entry in DS:SI
33 ; calculate the 1st sector of the data area
37 ; load the root directory
42 call read_cluster_chain
49 cmp byte [es:di], 0 ; we have no more entries to look at
51 cmp byte [es:di], 0xe5 ; the entry was only previously used and as such not worth looking at
64 add di, 9 ; knowing that cmpsb incremented this by 11, we can also increment it by 9
65 ; right here so we can use 1 less offset below
66 ; stage 3 has been found and ES:DI points to its directory entry
67 mov ax, [es:di] ; load high half of the 1st cluster
69 mov ax, [es:di+(dir_entry.firstcluslo-dir_entry.firstclushi)] ; load low half of the 1st cluster
70 mov bx, STAGE3_SEGMENT
73 call read_cluster_chain ; read stage 3
75 call STAGE3_ADDRESS ; call stage 3
76 jmp .halt ; halt in case we return, which should never happen
106 %include "fat32/fat32.s"
108 stage3_missing: db "LOADER.BIN is missing", 0
109 STAGE3_NAME: db "LOADER BIN"
111 times 510-($-$$) db 0