Compare commits

...

4 Commits

Author SHA1 Message Date
11656c2827 more error codes and checks in vbr 2025-09-18 14:07:45 -04:00
f87f88a0dc fix qemu launch 2025-09-18 14:06:52 -04:00
7baa53178a update gitignore 2025-09-18 14:06:32 -04:00
8002d1cb54 more fat fs type checks 2025-09-18 11:50:27 -04:00
5 changed files with 58 additions and 36 deletions

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ stevia-log
compose-dev.yaml compose-dev.yaml
eth_null-tx.log eth_null-tx.log
eth_null-txdump.txt eth_null-txdump.txt
*.log

View File

@@ -38,9 +38,6 @@ QEMU_ARGS := \
-device e1000,netdev=n0,mac=52:54:00:12:34:56 \ -device e1000,netdev=n0,mac=52:54:00:12:34:56 \
-netdev user,id=n0 \ -netdev user,id=n0 \
-device piix3-usb-uhci \ -device piix3-usb-uhci \
-device usb-ohci,id=ohci0 \
-device usb-ehci,id=ehci0 \
-device pcspk \
-parallel null \ -parallel null \
-serial null -serial none -serial none -serial none \ -serial null -serial none -serial none -serial none \
-chardev file,id=dbg,path=bochs-e9.log,append=on \ -chardev file,id=dbg,path=bochs-e9.log,append=on \

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,19 +59,19 @@
%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'
%define STEVIA_DEBUG_HALT 'Z' %define STEVIA_DEBUG_HALT 'Z'
%endif %endif
%define __INC_ERROR_CODES %define __INC_ERROR_CODES

View File

@@ -65,11 +65,11 @@ struc FAT32_bpb_t
.u16_RootEntryCount16 resw 1 ; Root dir entry count field, 0 on fat32 .u16_RootEntryCount16 resw 1 ; Root dir entry count field, 0 on fat32
.u16_TotalSectors16 resw 1 ; total number of sectors size, 0 on fat32 .u16_TotalSectors16 resw 1 ; total number of sectors size, 0 on fat32
.u8_MediaDesc resb 1 .u8_MediaDesc resb 1
.u16_FatSize16 resw 1 ; FAT size 16, 0 on fat32 .u16_FATSize16 resw 1 ; FAT size 16, 0 on fat32
.u16_SectorsPerTrack resw 1 .u16_SectorsPerTrack resw 1
.u16_HeadCount resw 1 .u16_HeadCount resw 1
.u32_HiddenSectors resd 1 .u32_HiddenSectors resd 1
.u32_TotalSectors resd 1 .u32_TotalSectors32 resd 1
endstruc endstruc
; EBPB Information (FAT32) ; EBPB Information (FAT32)
@@ -89,7 +89,7 @@ endstruc
; 8 System identifier string. Always "FAT32 ". The spec says never to trust the contents of this string for any use. ; 8 System identifier string. Always "FAT32 ". The spec says never to trust the contents of this string for any use.
struc FAT32_ebpb_t struc FAT32_ebpb_t
.u32_FATSz resd 1 ; size of *each* fat in sectors, total = FATSz * (# of FATs) .u32_FATSize32 resd 1 ; size of *each* fat in sectors, total = FATSz * (# of FATs)
.u16_ExtFlags resw 1 .u16_ExtFlags resw 1
.u16_FSVersion resw 1 .u16_FSVersion resw 1
.u32_RootDirCluster resd 1 .u32_RootDirCluster resd 1

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)
@@ -257,18 +267,33 @@ ReadVbrData:
mov bx, [bp + 6] mov bx, [bp + 6]
cmp word [bx + 0x1FE], 0xAA55 ; check for bytes at end cmp word [bx + 0x1FE], 0xAA55 ; check for bytes at end
jne ReadVbrData.error_nosign jne ReadVbrData.error_nosign
.check_FAT_size: .check_FAT_sanity:
test word [bx + FAT32_bpb_t.u16_TotalSectors16], 0 ; TotSectors16 will not be set if FAT32 ; we only quickly validate that this is *probably* a FAT32 volume
jnz ReadVbrData.error_badfatfs
add bx, 11 ; point bx at start of bpb (skip jmp code and ident)
cmp word [bx + FAT32_bpb_t.u16_TotalSectors16], 0 ; TotalSectors16 should be 0 (use TotalSectors32 in bpb)
jne ReadVbrData.error_totsectors
cmp word [bx + FAT32_bpb_t.u16_FATSize16], 0 ; FatSize16 will be 0 if FAT32 (use FATSize32 in ebpb)
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