From 145e9fbaa9cafae895f958f55936334ac0dcff12 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Sat, 5 Oct 2024 20:14:00 -0400 Subject: [PATCH] =?UTF-8?q?fixed=20read=5Fdisk=5Fraw=20in=20ReadFATCluster?= =?UTF-8?q?=20boot=5Fdrive=20and=20partition=5Foffset=20are=20global=20poi?= =?UTF-8?q?nters=20now=20removed=20an=20extra=20error=20from=20mbr=20disk?= =?UTF-8?q?=20read=20and=20some=20general=20formating=20and=20cleanup=20?= =?UTF-8?q?=F0=9F=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/BIOS/func/ext_read.inc | 2 +- include/fat32/fat32_sys.inc | 13 +++---------- src/mbr/mbr.nasm | 10 +++++----- src/stage2/stage2.nasm | 11 ++++++----- src/vbr/vbr.nasm | 13 ++++--------- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/include/BIOS/func/ext_read.inc b/include/BIOS/func/ext_read.inc index a107c94..42d1cdc 100644 --- a/include/BIOS/func/ext_read.inc +++ b/include/BIOS/func/ext_read.inc @@ -97,7 +97,7 @@ read_disk_raw: %ifdef __STEVIA_MBR ERROR MBR_ERROR_DISK_READ_ERR - %elifsef __STEVIA_VBR + %elifdef __STEVIA_VBR ERROR VBR_ERROR_DISK_READ_ERR %else ERROR STAGE2_MBR_DISK_READ_ERROR diff --git a/include/fat32/fat32_sys.inc b/include/fat32/fat32_sys.inc index 3de49ab..60f155a 100644 --- a/include/fat32/fat32_sys.inc +++ b/include/fat32/fat32_sys.inc @@ -36,9 +36,7 @@ InitFATDriver: .calc_active_part: mov bx, [partition_offset_ptr] - mov ax, [bx + 0] - mov bx, ax - mov ax, [bx + 0] + mov ax, [bx + 0] mov dx, partition_table 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 .get_first_root_dir: ; TODO - jmp InitFATDriver.endp .error: ERROR STAGE2_FAT32_INIT_ERROR @@ -74,7 +71,6 @@ InitFATDriver: __CDECL16_EXIT 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 ; ; SFN is a 8.3 file name, all uppercase, and padded with spaces @@ -284,15 +280,13 @@ ReadFATCluster: .func: mov bx, [boot_drive_ptr] 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 dword eax, [bp + 8] push dword eax call ClusterToLBA ; uint32_t ClusterToLBA(uint32_t cluster) add sp, 0x4 ; eax == LBA - + mov dword [bp - 6], eax movzx ax, [bp - 2] push ax @@ -300,8 +294,7 @@ ReadFATCluster: mov ax, 0x1 push ax - ; load correct fat - mov eax, dword [si + FAT32_NextClusterData_t.fat_sector] + mov eax, dword [bp + 6] push dword eax mov ax, fat_buffer diff --git a/src/mbr/mbr.nasm b/src/mbr/mbr.nasm index e4450a8..b1ad23d 100755 --- a/src/mbr/mbr.nasm +++ b/src/mbr/mbr.nasm @@ -138,15 +138,10 @@ main: ; uint16_t count, uint16_t drive_num) call read_disk_raw add sp, 0xC - - - jnc main.goto_vbr - ERROR MBR_ERROR_DISK_READ_ERR ; error in LBA read .goto_vbr: cmp word [VBR_ENTRY + 0x1FE], 0xAA55 je main.sig_ok ERROR MBR_ERROR_NO_VBR_SIG ; no signature present - .sig_ok: mov ax, partition_table_SIZE ; 72 bytes of data push ax @@ -166,8 +161,13 @@ main: ; BIOS Functions ; ; ############### + %include 'BIOS/func/ext_read.inc' +; ############### +; End Section +; ############### + %assign bytes_remaining (440 - ($ - $$)) %warning MBR has bytes_remaining bytes remaining for code (MAX: 440 bytes) times ((512 - 72) - ($ - $$)) nop ; Fill the rest of sector with nop diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index f014125..d6d11bd 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -23,16 +23,14 @@ [CPU KATMAI] jmp short init nop -; boot drive in dl -; active partition offset in si ; ############### ; ; Headers/Includes/Definitions ; ; ############### -%define __STEVIA_STAGE2 +%define __STEVIA_STAGE2 %include "cdecl16.inc" %include "entry.inc" @@ -43,6 +41,7 @@ nop ; ############### ; End Section ; ############### + ALIGN 4, db 0x90 init: cli ; We do not want to be interrupted @@ -62,7 +61,6 @@ init: jmp 0:main - ; ############### ; ; Extra/Shared Functions @@ -76,6 +74,10 @@ init: ; End Section ; ############### +; +; bp - 2 : uint8_t boot_drive +; bp - 4 : uint16_t part_offset +; main: lea ax, [bp - 2] mov [boot_drive_ptr], ax @@ -147,7 +149,6 @@ main: add sp, 0x2 ERROR STEVIA_DEBUG_HALT - hcf: hlt jmp short hcf diff --git a/src/vbr/vbr.nasm b/src/vbr/vbr.nasm index 2ffdd30..4c46864 100755 --- a/src/vbr/vbr.nasm +++ b/src/vbr/vbr.nasm @@ -37,7 +37,6 @@ times 54 db 0x00 ; ############### %define __STEVIA_VBR - %include "cdecl16.inc" %include "entry.inc" %include "config.inc" @@ -81,17 +80,14 @@ init: ALIGN 4, db 0x90 main: - mov byte [bp - 2], dl ; boot_drive + mov byte [bp - 2], dl ; boot_drive mov [bp - 4], si ; part_offset .check_FAT_size: ; we only support a very specific setup of FAT32 cmp dword [bsSectorHuge], 0 ; SectorsHuge will not be set if FAT12/16 ja main.load_stage2 - ERROR VBR_ERROR_WRONG_FAT_SIZE - -; read sectors 1-63 to stage2 entry point -.load_stage2: +.load_stage2: ; read sectors 1-63 to stage2 entry point mov ax, (fat32_bpb_SIZE + fat32_ebpb_SIZE) ; size in byte push ax 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 ; ############### -; -; Required BIOS functions -; +; Required BIOS function(s) ; ############### + %include 'BIOS/func/ext_read.inc' %assign bytes_remaining (420 - ($ - $$))