Compare commits

..

3 Commits

Author SHA1 Message Date
4a27e09872 use partition entry size constant 2025-09-17 16:24:45 -04:00
59bc1afb7c stick mmap info in SteviaInfo 2025-09-17 16:24:27 -04:00
8b0b73d8a4 start partition table at entry 1 2025-09-17 16:22:47 -04:00
4 changed files with 29 additions and 90 deletions

View File

@@ -33,35 +33,27 @@ struc AddressRangeDescStruct_t
.ExtType resd 1 .ExtType resd 1
endstruc endstruc
; !!! this procedure changes ES !!!
ALIGN 4, db 0x90 ALIGN 4, db 0x90
GetMemoryMap: GetMemoryMap:
__CDECL16_PROC_ENTRY __CDECL16_PROC_ENTRY
push es ; save segment register push es ; save segment register
.func: .func:
mov dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries], 0 mov word [SteviaInfo + SteviaInfoStruct_t.u16_E820MMapEntryCount], 0
xor ebx, ebx ; Continuation value, 0 for the first call xor ebx, ebx ; Continuation value, 0 for the first call
mov di, BIOSMemoryMap ; destination is es:di, es should == ds
mov dx, BIOSMemoryMap
shr dx, 4
mov es, dx
xor di, di ; (BIOSMemoryMap >> 4):0 makes di an index into BIOSMemoryMap
mov ecx, AddressRangeDescStruct_t_size ; hard request ACPI 3.0 table versions (24 bytes) mov ecx, AddressRangeDescStruct_t_size ; hard request ACPI 3.0 table versions (24 bytes)
.loop_L1: .loop_L1:
mov eax, 0x0000E820 ; select 0xE820 function mov eax, 0x0000E820 ; select 0xE820 function
mov edx, 0x534D4150 ; 'SMAP' magic mov edx, 0x534D4150 ; 'SMAP' magic
clc ; clear carry clc ; clear carry
int 0x15 int 0x15 ; data will be stored at es:di by e820 call
jc GetMemoryMap.error jc GetMemoryMap.error
cmp eax, 0x534D4150 cmp eax, 0x534D4150
jne GetMemoryMap.no_smap_returned jne GetMemoryMap.no_smap_returned
.no_error: .no_error:
mov eax, dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries] inc word [SteviaInfo + SteviaInfoStruct_t.u16_E820MMapEntryCount]
add eax, 1
mov dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries], eax
cmp ecx, 20 ; TODO: maybe this could be handled better than just panicing cmp ecx, 20 ; TODO: maybe this could be handled better than just panicing
jb GetMemoryMap.nonstandard_e820 ; non-standard entry found jb GetMemoryMap.nonstandard_e820 ; non-standard entry found
@@ -89,7 +81,7 @@ GetMemoryMap:
PrintMemoryMap: PrintMemoryMap:
__CDECL16_PROC_ENTRY __CDECL16_PROC_ENTRY
.func: .func:
mov eax, dword [SteviaInfo + SteviaInfoStruct_t.MemoryMapEntries] mov eax, dword [SteviaInfo + SteviaInfoStruct_t.u16_E820MMapEntryCount]
cmp eax, 0 cmp eax, 0
je PrintMemoryMap.endp ; if entries == 0, exit je PrintMemoryMap.endp ; if entries == 0, exit

View File

@@ -15,6 +15,9 @@
%ifndef __INC_PART_TABLE %ifndef __INC_PART_TABLE
%define DISK_SIGNATURE_OFFSET 0x1B8
%define DISK_PARTITION_TABLE_OFFSET 0x1BE
; Partition table entry format ; Partition table entry format
; Off. Size. Description ; Off. Size. Description
;0x00 1 Drive attributes (bit 7 set = active or bootable) ;0x00 1 Drive attributes (bit 7 set = active or bootable)
@@ -34,8 +37,6 @@ struc PartEntry_t
endstruc endstruc
struc PartTable_t struc PartTable_t
.signature resb 4
.reserved resb 2
.partition1 resb PartEntry_t_size .partition1 resb PartEntry_t_size
.partition2 resb PartEntry_t_size .partition2 resb PartEntry_t_size
.partition3 resb PartEntry_t_size .partition3 resb PartEntry_t_size

View File

@@ -109,7 +109,7 @@ main:
mov al, byte [bx + PartEntry_t.attributes] mov al, byte [bx + PartEntry_t.attributes]
test al, 0x80 ; 0x80 == 1000_0000b test al, 0x80 ; 0x80 == 1000_0000b
jnz main.active_found jnz main.active_found
add bx, 0x10 ; add 16 bytes to offset add bx, PartEntry_t_size ; add 16 bytes to offset
loop main.find_active_L0 loop main.find_active_L0
ERROR MBR_ERROR_NO_NO_BOOT_PART ERROR MBR_ERROR_NO_NO_BOOT_PART

View File

@@ -102,8 +102,10 @@ init:
; structures ; structures
struc SteviaInfoStruct_t struc SteviaInfoStruct_t
.MemoryMapPtr resd 1 .p16_E820MemoryMapPtr resw 1
.MemoryMapEntries resd 1 .u16_E820MMapEntryCount resw 1
.p16_MbrPtr resw 1
.p16_VbrPtr resw 1
endstruc endstruc
struc EarlyBootStruct_t struc EarlyBootStruct_t
@@ -130,20 +132,20 @@ main:
__CDECL16_CALL_ARGS pszHelloPrompt __CDECL16_CALL_ARGS pszHelloPrompt
__CDECL16_CALL PrintString, 1 __CDECL16_CALL PrintString, 1
; setup and store our vbr/mbr (e)bpb ; setup and store our vbr/mbr (e)bpb
__CDECL16_CALL_ARGS 0x200, 0x10 __CDECL16_CALL_ARGS 0x200, 0x10
__CDECL16_CALL ArenaAlloc, 2 __CDECL16_CALL ArenaAlloc, 2
mov word [mbr_ptr], ax mov word [SteviaInfo + SteviaInfoStruct_t.p16_MbrPtr], ax
push ax ; dst push ax ; dst
movzx ax, byte [u8_BootDrive] movzx ax, byte [u8_BootDrive]
push ax ; boot_drive push ax ; boot_drive
__CDECL16_CALL ReadMbrData, 2 ; fill mbr buffer __CDECL16_CALL ReadMbrData, 2 ; fill mbr buffer
__CDECL16_CALL_ARGS 0x200, 0x10 __CDECL16_CALL_ARGS 0x200, 0x10
__CDECL16_CALL ArenaAlloc, 2 __CDECL16_CALL ArenaAlloc, 2
mov word [vbr_ptr], ax mov word [SteviaInfo + SteviaInfoStruct_t.p16_VbrPtr], ax
push ax ; dst push ax ; dst
movzx ax, byte [u8_BootDrive] movzx ax, byte [u8_BootDrive]
@@ -218,10 +220,6 @@ ReadMbrData:
cmp word [bx + 0x1FE], 0xAA55 ; check for bytes at end cmp word [bx + 0x1FE], 0xAA55 ; check for bytes at end
jne ReadMbrData.error jne ReadMbrData.error
; TODO: this needs error checking, zero checking, check the sig a bunch of stuff... ; TODO: this needs error checking, zero checking, check the sig a bunch of stuff...
.update_globals:
mov ax, [bp + 6]
add ax, 0x1B8 ; offset to start of PartTable
mov [part_table_ptr], ax
.endp: .endp:
__CDECL16_PROC_EXIT __CDECL16_PROC_EXIT
ret ret
@@ -233,19 +231,21 @@ ReadMbrData:
ReadVbrData: ReadVbrData:
__CDECL16_PROC_ENTRY __CDECL16_PROC_ENTRY
.proc: .proc:
mov bx, word [part_table_ptr] ; calculate offset; base pointer @ partition table mov bx, SteviaInfo
mov ax, word [bx + SteviaInfoStruct_t.p16_MbrPtr]
add ax, DISK_PARTITION_TABLE_OFFSET
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 mov si, PartEntry_t.attributes
.find_active_L0: .find_active_L0:
mov al, byte [bx + si] mov al, byte [bx + si]
test al, 0x80 ; 0x80 == 1000_0000b test al, 0x80 ; 0x80 == 1000_0000b
je ReadVbrData.active_found je ReadVbrData.active_found
add si, 0x10 ; add 16 bytes to offset (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 jmp ReadVbrData.error
.active_found: .active_found:
add bx, si ; update base to active part
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)
@@ -265,10 +265,6 @@ ReadVbrData:
.check_FAT_size: .check_FAT_size:
test word [bx + FAT32_bpb_t.unused2_ZERO_word], 0 ; TotSectors16 will not be set if FAT32 test word [bx + FAT32_bpb_t.unused2_ZERO_word], 0 ; TotSectors16 will not be set if FAT32
jnz ReadVbrData.error jnz ReadVbrData.error
.update_globals:
mov word [fat32_bpb_ptr], bx
add bx, FAT32_bpb_t_size ; offset to ebpb
mov word [fat32_ebpb_ptr], bx
.endp: .endp:
__CDECL16_PROC_EXIT __CDECL16_PROC_EXIT
ret ret
@@ -510,72 +506,22 @@ align 16, resb 1
section .bss follows=.sign section .bss follows=.sign
begin_bss: begin_bss:
align 4, resb 1
mbr_ptr:
resw 1
align 4, resb 1
vbr_ptr:
resw 1
align 4, resb 1
part_table_ptr:
resw 1
align 4, resb 1
fat32_bpb_ptr:
resw 1
align 4, resb 1
fat32_ebpb_ptr:
resw 1
; structures ; structures
align 16, resb 1 align 16, resb 1
partition_table: SteviaInfo:
resb PartTable_t_size resd SteviaInfoStruct_t_size
align 16, resb 1 align 16, resb 1
fat32_bpb: early_heap_state:
resb FAT32_bpb_t_size resb ArenaStateStruc_t_size
fat32_ebpb:
resb FAT32_ebpb_t_size
align 16, resb 1
fat32_nc_data:
resb 16
align 16, resb 1 align 16, resb 1
lba_packet: lba_packet:
resb LBAPkt_t_size resb LBAPkt_t_size
align 16, resb 1
fat32_state:
resb FAT32_State_t_size
align 16, resb 1
SteviaInfo:
resd 4
align 16, resb 1
early_heap_state:
resb ArenaStateStruc_t_size
;
; post-bss init globals
;
; ;
; large continuous allocations ; large continuous allocations
; ;
align 16, resb 1
disk_buffer:
resb 512
fat_buffer:
resb 512
dir_buffer:
resb 512
fat_fsinfo:
resb 512
; TODO: this will hold 42 entries from the map function ; TODO: this will hold 42 entries from the map function
; the e820 function needs to check that it doesn't overflow ; the e820 function needs to check that it doesn't overflow
@@ -593,7 +539,7 @@ end_bss:
; Pad to the cap (emits nothing in the file; only increases .bss virtual size). ; Pad to the cap (emits nothing in the file; only increases .bss virtual size).
; If BSS_SIZE > BSS_MAX_BYTES, this becomes negative and NASM errors out. ; If BSS_SIZE > BSS_MAX_BYTES, this becomes negative and NASM errors out.
%define BSS_MAX_BYTES 0x3000 %define BSS_MAX_BYTES 0x2000
resb (BSS_MAX_BYTES - (end_bss - begin_bss)) resb (BSS_MAX_BYTES - (end_bss - begin_bss))
; Optional: keep a label for later math: ; Optional: keep a label for later math: