Skip to content

Commit

Permalink
feat(boot): read BPB
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Jul 29, 2024
1 parent 85d09cb commit 899e456
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
1 change: 1 addition & 0 deletions boot/common/const.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ STACK_TOP = 0x7000

; ---------- Magic ------------
STPDBOOT_MAGIC = 0x53545044
STPDFS_MAGIC = 0x44505453

; ---------- Video ------------
VIDEO_WIDTH = 1024
Expand Down
17 changes: 17 additions & 0 deletions boot/common/fat12.inc
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down
7 changes: 7 additions & 0 deletions boot/loader/disk.inc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
39 changes: 38 additions & 1 deletion boot/loader/loader.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 899e456

Please sign in to comment.