feat(boot): read BPB
This commit is contained in:
parent
85d09cbbf6
commit
899e456249
|
@ -16,6 +16,7 @@ STACK_TOP = 0x7000
|
||||||
|
|
||||||
; ---------- Magic ------------
|
; ---------- Magic ------------
|
||||||
STPDBOOT_MAGIC = 0x53545044
|
STPDBOOT_MAGIC = 0x53545044
|
||||||
|
STPDFS_MAGIC = 0x44505453
|
||||||
|
|
||||||
; ---------- Video ------------
|
; ---------- Video ------------
|
||||||
VIDEO_WIDTH = 1024
|
VIDEO_WIDTH = 1024
|
||||||
|
|
|
@ -1,5 +1,22 @@
|
||||||
;; File: fat12.inc
|
;; 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
|
;; Struct: fat_entry
|
||||||
struc fat_entry
|
struc fat_entry
|
||||||
{
|
{
|
||||||
|
|
|
@ -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:
|
disk_read_sectors:
|
||||||
; test byte [bDriveLBA], TRUE
|
; test byte [bDriveLBA], TRUE
|
||||||
; je .lba_read
|
; je .lba_read
|
||||||
|
|
|
@ -64,8 +64,45 @@ _start:
|
||||||
; +---------+---------+---------....--+----....---+
|
; +---------+---------+---------....--+----....---+
|
||||||
; 0 512 1024 XXXX XXXX
|
; 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
|
; 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
|
call fat_load_root
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue