Full refactor for modularization #2
@@ -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
|
||||
|
||||
@@ -37,8 +37,6 @@ InitFATDriver:
|
||||
.calc_active_part:
|
||||
mov bx, [partition_offset_ptr]
|
||||
mov ax, [bx + 0]
|
||||
mov bx, ax
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 - ($ - $$))
|
||||
|
||||
Reference in New Issue
Block a user