diff --git a/boot/common/const.inc b/boot/common/const.inc index 917987c..5a1f88e 100644 --- a/boot/common/const.inc +++ b/boot/common/const.inc @@ -16,6 +16,7 @@ STACK_TOP = 0x7000 ; ---------- Magic ------------ STPDBOOT_MAGIC = 0x53545044 +STPDFS_MAGIC = 0x44505453 ; ---------- Video ------------ VIDEO_WIDTH = 1024 diff --git a/boot/common/fat12.inc b/boot/common/fat12.inc index c42dab8..39ec1d8 100644 --- a/boot/common/fat12.inc +++ b/boot/common/fat12.inc @@ -1,5 +1,22 @@ ;; File: fat12.inc +struc fat_bpb +{ + .jump db 3 dup(?) + .oem_name db 8 dup(?) + .bytes_per_sects dw ? + .sects_per_clust db ? + .reserved_sects dw ? + .FAT_count db ? + .root_dir_entries dw ? + .total_sects dw ? + .media_type db ? + .sects_per_FAT dw ? + .sects_per_track dw ? + .heads_per_cyl dw ? +} +defn fat_bpb + ;; Struct: fat_entry struc fat_entry { diff --git a/boot/loader/disk.inc b/boot/loader/disk.inc index f86195c..19339f2 100644 --- a/boot/loader/disk.inc +++ b/boot/loader/disk.inc @@ -1,4 +1,11 @@ + ;; File: disk.inc + ;; Function: disk_read_sectors + ;; + ;; In: + ;; AX - LBA starting sector + ;; CX - Sector count + ;; ES:BX - buffer disk_read_sectors: ; test byte [bDriveLBA], TRUE ; je .lba_read diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index b874371..9fec956 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -64,8 +64,45 @@ _start: ; +---------+---------+---------....--+----....---+ ; 0 512 1024 XXXX XXXX ; - + + ; read stupidfs super block + mov ax, DISK_BUFFER/0x10 + mov es, ax + mov ax, 1 + mov cx, 1 + xor bx, bx + call disk_read_sectors + + cmp dword [DISK_BUFFER], STPDFS_MAGIC + jne .fat_fallback + + ; fallback to fat12 ; for now fat12 is asumed +.fat_fallback: + ; get bpb + mov ax, DISK_BUFFER/0x10 + mov es, ax + xor bx, bx + mov ax, 0 + mov cx, 1 + call disk_read_sectors + + mov word ax, [DISK_BUFFER + fat_bpb.sects_per_track] + mov word [sectors_per_track], ax + mov word ax, [DISK_BUFFER + fat_bpb.heads_per_cyl] + mov word [heads_per_cylinder], ax + mov word ax, [DISK_BUFFER + fat_bpb.bytes_per_sects] + mov word [bytes_per_sector], ax + mov word ax, [DISK_BUFFER + fat_bpb.sects_per_FAT] + mov word [sectors_per_FAT], ax + mov byte al, [DISK_BUFFER + fat_bpb.FAT_count] + mov byte [FAT_count], al + mov word ax, [DISK_BUFFER + fat_bpb.reserved_sects] + mov word [reserved_sectors], ax + mov word ax, [DISK_BUFFER + fat_bpb.root_dir_entries] + mov word [root_dir_entries], ax + mov byte al, [DISK_BUFFER + fat_bpb.sects_per_clust] + mov byte [sectors_per_cluster], al call fat_load_root