fixed read_disk_raw in ReadFATCluster

boot_drive and partition_offset are global pointers now
removed an extra error from mbr disk read
and some general formating and cleanup 😅
This commit is contained in:
2024-10-05 20:14:00 -04:00
parent 8f95c8f267
commit 145e9fbaa9
5 changed files with 19 additions and 30 deletions

View File

@@ -97,7 +97,7 @@ read_disk_raw:
%ifdef __STEVIA_MBR %ifdef __STEVIA_MBR
ERROR MBR_ERROR_DISK_READ_ERR ERROR MBR_ERROR_DISK_READ_ERR
%elifsef __STEVIA_VBR %elifdef __STEVIA_VBR
ERROR VBR_ERROR_DISK_READ_ERR ERROR VBR_ERROR_DISK_READ_ERR
%else %else
ERROR STAGE2_MBR_DISK_READ_ERROR ERROR STAGE2_MBR_DISK_READ_ERROR

View File

@@ -37,8 +37,6 @@ InitFATDriver:
.calc_active_part: .calc_active_part:
mov bx, [partition_offset_ptr] mov bx, [partition_offset_ptr]
mov ax, [bx + 0] mov ax, [bx + 0]
mov bx, ax
mov ax, [bx + 0]
mov dx, partition_table mov dx, partition_table
add dx, ax ; dx points to the partition that was booted from add dx, ax ; dx points to the partition that was booted from
@@ -66,7 +64,6 @@ InitFATDriver:
mov dword [fat32_state + FAT32_State_t.first_data_sector_32], eax mov dword [fat32_state + FAT32_State_t.first_data_sector_32], eax
.get_first_root_dir: .get_first_root_dir:
; TODO ; TODO
jmp InitFATDriver.endp jmp InitFATDriver.endp
.error: .error:
ERROR STAGE2_FAT32_INIT_ERROR ERROR STAGE2_FAT32_INIT_ERROR
@@ -74,7 +71,6 @@ InitFATDriver:
__CDECL16_EXIT __CDECL16_EXIT
ret ret
; TODO: needs validation
; this involves using the low memory buffer for the bios call and moving the file sector by sector to high memory ; this involves using the low memory buffer for the bios call and moving the file sector by sector to high memory
; ;
; SFN is a 8.3 file name, all uppercase, and padded with spaces ; SFN is a 8.3 file name, all uppercase, and padded with spaces
@@ -284,15 +280,13 @@ ReadFATCluster:
.func: .func:
mov bx, [boot_drive_ptr] mov bx, [boot_drive_ptr]
mov ax, [bx + 0] mov ax, [bx + 0]
mov bx, ax
movzx ax, byte [bx + 0] ; 67h override would probably work but this is the 16bit way to do it
mov byte [bp - 2], al ; save boot drive as a local for easy access mov byte [bp - 2], al ; save boot drive as a local for easy access
mov dword eax, [bp + 8] mov dword eax, [bp + 8]
push dword eax push dword eax
call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster) call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster)
add sp, 0x4 ; eax == LBA add sp, 0x4 ; eax == LBA
mov dword [bp - 6], eax
movzx ax, [bp - 2] movzx ax, [bp - 2]
push ax push ax
@@ -300,8 +294,7 @@ ReadFATCluster:
mov ax, 0x1 mov ax, 0x1
push ax push ax
; load correct fat mov eax, dword [bp + 6]
mov eax, dword [si + FAT32_NextClusterData_t.fat_sector]
push dword eax push dword eax
mov ax, fat_buffer mov ax, fat_buffer

View File

@@ -138,15 +138,10 @@ main:
; uint16_t count, uint16_t drive_num) ; uint16_t count, uint16_t drive_num)
call read_disk_raw call read_disk_raw
add sp, 0xC add sp, 0xC
jnc main.goto_vbr
ERROR MBR_ERROR_DISK_READ_ERR ; error in LBA read
.goto_vbr: .goto_vbr:
cmp word [VBR_ENTRY + 0x1FE], 0xAA55 cmp word [VBR_ENTRY + 0x1FE], 0xAA55
je main.sig_ok je main.sig_ok
ERROR MBR_ERROR_NO_VBR_SIG ; no signature present ERROR MBR_ERROR_NO_VBR_SIG ; no signature present
.sig_ok: .sig_ok:
mov ax, partition_table_SIZE ; 72 bytes of data mov ax, partition_table_SIZE ; 72 bytes of data
push ax push ax
@@ -166,8 +161,13 @@ main:
; BIOS Functions ; BIOS Functions
; ;
; ############### ; ###############
%include 'BIOS/func/ext_read.inc' %include 'BIOS/func/ext_read.inc'
; ###############
; End Section
; ###############
%assign bytes_remaining (440 - ($ - $$)) %assign bytes_remaining (440 - ($ - $$))
%warning MBR has bytes_remaining bytes remaining for code (MAX: 440 bytes) %warning MBR has bytes_remaining bytes remaining for code (MAX: 440 bytes)
times ((512 - 72) - ($ - $$)) nop ; Fill the rest of sector with nop times ((512 - 72) - ($ - $$)) nop ; Fill the rest of sector with nop

View File

@@ -23,16 +23,14 @@
[CPU KATMAI] [CPU KATMAI]
jmp short init jmp short init
nop nop
; boot drive in dl
; active partition offset in si
; ############### ; ###############
; ;
; Headers/Includes/Definitions ; Headers/Includes/Definitions
; ;
; ############### ; ###############
%define __STEVIA_STAGE2
%define __STEVIA_STAGE2
%include "cdecl16.inc" %include "cdecl16.inc"
%include "entry.inc" %include "entry.inc"
@@ -43,6 +41,7 @@ nop
; ############### ; ###############
; End Section ; End Section
; ############### ; ###############
ALIGN 4, db 0x90 ALIGN 4, db 0x90
init: init:
cli ; We do not want to be interrupted cli ; We do not want to be interrupted
@@ -62,7 +61,6 @@ init:
jmp 0:main jmp 0:main
; ############### ; ###############
; ;
; Extra/Shared Functions ; Extra/Shared Functions
@@ -76,6 +74,10 @@ init:
; End Section ; End Section
; ############### ; ###############
;
; bp - 2 : uint8_t boot_drive
; bp - 4 : uint16_t part_offset
;
main: main:
lea ax, [bp - 2] lea ax, [bp - 2]
mov [boot_drive_ptr], ax mov [boot_drive_ptr], ax
@@ -147,7 +149,6 @@ main:
add sp, 0x2 add sp, 0x2
ERROR STEVIA_DEBUG_HALT ERROR STEVIA_DEBUG_HALT
hcf: hcf:
hlt hlt
jmp short hcf jmp short hcf

View File

@@ -37,7 +37,6 @@ times 54 db 0x00
; ############### ; ###############
%define __STEVIA_VBR %define __STEVIA_VBR
%include "cdecl16.inc" %include "cdecl16.inc"
%include "entry.inc" %include "entry.inc"
%include "config.inc" %include "config.inc"
@@ -81,17 +80,14 @@ init:
ALIGN 4, db 0x90 ALIGN 4, db 0x90
main: main:
mov byte [bp - 2], dl ; boot_drive mov byte [bp - 2], dl ; boot_drive
mov [bp - 4], si ; part_offset mov [bp - 4], si ; part_offset
.check_FAT_size: ; we only support a very specific setup of FAT32 .check_FAT_size: ; we only support a very specific setup of FAT32
cmp dword [bsSectorHuge], 0 ; SectorsHuge will not be set if FAT12/16 cmp dword [bsSectorHuge], 0 ; SectorsHuge will not be set if FAT12/16
ja main.load_stage2 ja main.load_stage2
ERROR VBR_ERROR_WRONG_FAT_SIZE ERROR VBR_ERROR_WRONG_FAT_SIZE
.load_stage2: ; read sectors 1-63 to stage2 entry point
; read sectors 1-63 to stage2 entry point
.load_stage2:
mov ax, (fat32_bpb_SIZE + fat32_ebpb_SIZE) ; size in byte mov ax, (fat32_bpb_SIZE + fat32_ebpb_SIZE) ; size in byte
push ax push ax
mov ax, (phy_bpb_start - 0x3) ; start of bpb - 0x3 for the jump short main at the start mov ax, (phy_bpb_start - 0x3) ; start of bpb - 0x3 for the jump short main at the start
@@ -140,10 +136,9 @@ main:
jmp 0:0x7E00 jmp 0:0x7E00
; ############### ; ###############
; ; Required BIOS function(s)
; Required BIOS functions
;
; ############### ; ###############
%include 'BIOS/func/ext_read.inc' %include 'BIOS/func/ext_read.inc'
%assign bytes_remaining (420 - ($ - $$)) %assign bytes_remaining (420 - ($ - $$))