more error codes and checks in vbr

This commit is contained in:
2025-09-18 14:07:45 -04:00
parent f87f88a0dc
commit 11656c2827
2 changed files with 49 additions and 32 deletions

View File

@@ -15,8 +15,7 @@
%ifndef __INC_ERROR_CODES %ifndef __INC_ERROR_CODES
; Errors ; MBR Error codes
; 12 Errors, 5 in use
%define MBR_ERROR_DISK_T_ERR 'a' %define MBR_ERROR_DISK_T_ERR 'a'
%define MBR_ERROR_NO_INT32E 'b' %define MBR_ERROR_NO_INT32E 'b'
%define MBR_ERROR_NO_NO_BOOT_PART 'c' %define MBR_ERROR_NO_NO_BOOT_PART 'c'
@@ -30,7 +29,7 @@
%define MBR_ERROR_RESERVED_k 'k' %define MBR_ERROR_RESERVED_k 'k'
%define MBR_ERROR_INT13h_EREAD_ERR 'l' %define MBR_ERROR_INT13h_EREAD_ERR 'l'
; 12 Error ; VBR Error codes
%define VBR_ERROR_WRONG_FAT_SIZE 'm' %define VBR_ERROR_WRONG_FAT_SIZE 'm'
%define VBR_ERROR_NO_SIGNATURE 'n' %define VBR_ERROR_NO_SIGNATURE 'n'
%define VBR_ERROR_DISK_READ_ERR 'o' %define VBR_ERROR_DISK_READ_ERR 'o'
@@ -44,7 +43,7 @@
%define VBR_ERROR_RESERVED_w 'w' %define VBR_ERROR_RESERVED_w 'w'
%define VBR_ERROR_RESERVED_x 'x' %define VBR_ERROR_RESERVED_x 'x'
; 22 errors, 8 in use ; Stage2 Error codes
%define STAGE2_A20_FAILED 'A' %define STAGE2_A20_FAILED 'A'
%define STAGE2_SIGNATURE_MISSING 'B' %define STAGE2_SIGNATURE_MISSING 'B'
%define STAGE2_MM_E820_NO_SUPPORT 'C' %define STAGE2_MM_E820_NO_SUPPORT 'C'
@@ -60,15 +59,15 @@
%define STAGE2_FAT32_E_UNSUPPORTED 'M' %define STAGE2_FAT32_E_UNSUPPORTED 'M'
%define STAGE2_FAT32_E_UNIMPLEMENTED 'N' %define STAGE2_FAT32_E_UNIMPLEMENTED 'N'
%define STAGE2_ERROR_BAD_MBR 'O' %define STAGE2_ERROR_BAD_MBR 'O'
%define STAGE2_ERROR_BAD_VBR 'P' %define STAGE2_VBR_E_ACTIVE 'P'
%define STAGE2_ERROR_RESERVED_Q 'Q' %define STAGE2_VBR_E_SIGN 'Q'
%define STAGE2_ERROR_RESERVED_R 'R' %define STAGE2_VBR_E_TOT 'R'
%define STAGE2_ERROR_RESERVED_S 'S' %define STAGE2_VBR_E_FATSZ 'S'
%define STAGE2_ERROR_RESERVED_T 'T' %define STAGE2_VBR_E_DIRENT 'T'
%define STAGE2_ERROR_RESERVED_U 'U' %define STAGE2_VBR_E_PARTTYPE 'U'
%define STAGE2_ERROR_RESERVED_V 'V' %define STAGE2_RESERVED_E_V 'V'
; for development only, specific errors should be above. ; Debug error codes
%define STEVIA_DEBUG_OK 'W' %define STEVIA_DEBUG_OK 'W'
%define STEVIA_DEBUG_ERR 'X' %define STEVIA_DEBUG_ERR 'X'
%define STEVIA_DEBUG_UNIMPLEMENTED 'Y' %define STEVIA_DEBUG_UNIMPLEMENTED 'Y'

View File

@@ -230,17 +230,27 @@ ReadVbrData:
mov ax, word [bx + SteviaInfoStruct_t.p16_MbrPtr] mov ax, word [bx + SteviaInfoStruct_t.p16_MbrPtr]
add ax, DISK_PARTITION_TABLE_OFFSET add ax, DISK_PARTITION_TABLE_OFFSET
mov bx, ax ; offset to part table mov bx, ax ; offset to part table
mov cx, 4 ; only checking 4 entries mov cx, 4 ; only checking 4 entries
mov si, PartEntry_t.attributes
.find_active_L0: .find_active_L0:
mov al, byte [bx + si] mov al, [bx + PartEntry_t.attributes]
test al, 0x80 ; 0x80 == 1000_0000b cmp al, 0x80 ; 0x80 == 1000_0000b
je ReadVbrData.active_found je ReadVbrData.check_fstype
add bx, PartEntry_t_size ; next part entry's attributes add bx, PartEntry_t_size ; next part entry's attributes
loop ReadVbrData.find_active_L0 loop ReadVbrData.find_active_L0
jmp ReadVbrData.error_noactive jmp ReadVbrData.error_noactive
.active_found: .check_fstype:
; check for part_type = 0x0C (DOS 7.1+/W95 FAT32 w/ LBA) or 0x1C (Hidden 0x0C)
__BOCHS_MAGIC_DEBUG
mov al, [bx + PartEntry_t.part_type]
cmp al, 0x0C
je ReadVbrData.active_ok
; *or*
cmp al, 0x1C
je ReadVbrData.active_ok
jmp ReadVbrData.error_badparttype ; error if part_type != 0x1C or 0x0C
.active_ok:
movzx ax, byte [bp + 4] movzx ax, byte [bp + 4]
push ax ; drive_num (2) push ax ; drive_num (2)
push 0x01 ; count (2) push 0x01 ; count (2)
@@ -259,23 +269,31 @@ ReadVbrData:
jne ReadVbrData.error_nosign jne ReadVbrData.error_nosign
.check_FAT_sanity: .check_FAT_sanity:
; we only quickly validate that this is *probably* a FAT32 volume ; we only quickly validate that this is *probably* a FAT32 volume
test word [bx + FAT32_bpb_t.u16_TotalSectors16], 0 ; TotalSectors16 should be 0 (use TotalSectors32 in bpb)
jnz ReadVbrData.error_badfatfs
test word [bx + FAT32_bpb_t.u16_FATSize16], 0 ; FatSize16 will be 0 if FAT32 (use FATSize32 in ebpb) add bx, 11 ; point bx at start of bpb (skip jmp code and ident)
jnz ReadVbrData.error_badfatfs cmp word [bx + FAT32_bpb_t.u16_TotalSectors16], 0 ; TotalSectors16 should be 0 (use TotalSectors32 in bpb)
jne ReadVbrData.error_totsectors
test word [bx + FAT32_bpb_t.u16_RootEntryCount16], 0 ; root dir info is in data clusters on fat32 cmp word [bx + FAT32_bpb_t.u16_FATSize16], 0 ; FatSize16 will be 0 if FAT32 (use FATSize32 in ebpb)
jnz ReadVbrData.error_badfatfs jne ReadVbrData.error_fatsz
cmp word [bx + FAT32_bpb_t.u16_RootEntryCount16], 0 ; root dir info is in data clusters on fat32
jne ReadVbrData.error_rootdir
.endp: .endp:
__CDECL16_PROC_EXIT __CDECL16_PROC_EXIT
ret ret
.error_noactive: .error_noactive:
ERROR STAGE2_ERROR_BAD_VBR ERROR STAGE2_VBR_E_ACTIVE
.error_nosign: .error_nosign:
ERROR STAGE2_ERROR_BAD_VBR ERROR STAGE2_VBR_E_SIGN
.error_badfatfs: .error_totsectors:
ERROR STAGE2_ERROR_BAD_VBR ERROR STAGE2_VBR_E_TOT
.error_fatsz:
ERROR STAGE2_VBR_E_FATSZ
.error_rootdir:
ERROR STAGE2_VBR_E_DIRENT
.error_badparttype:
ERROR STAGE2_VBR_E_PARTTYPE
; set ds and es segments back to the base of the loader ; set ds and es segments back to the base of the loader
%ifnmacro __TINY_DS_ES %ifnmacro __TINY_DS_ES