From ad2d37c63ba70c403ab1265725631685ab6587dc Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Sun, 13 Oct 2024 20:53:13 -0400 Subject: [PATCH] use bochs magic breakpoints in the error printer makes it easier to get a good state to do some investigating before reseting. --- include/util/bochs_magic.inc | 3 ++- include/util/error_func.nasm | 5 +++++ src/stage2/stage2.nasm | 42 ++++++++++++++++++++---------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/include/util/bochs_magic.inc b/include/util/bochs_magic.inc index fa236fc..bc59c80 100644 --- a/include/util/bochs_magic.inc +++ b/include/util/bochs_magic.inc @@ -20,7 +20,8 @@ %ifndef __INC_BOCHS_DEBUG_MAGIC -; +; for things like the error printer, opperate differently when we are targeting a dev (bochs) build +%define __STEVIA_DEV_DEBUG ; port_e9_hack: enabled=1 needs to be set in bochsrc.txt/bxrc ; %ifnmacro __BOCHS_PRINTC diff --git a/include/util/error_func.nasm b/include/util/error_func.nasm index 5682266..271cf97 100644 --- a/include/util/error_func.nasm +++ b/include/util/error_func.nasm @@ -22,7 +22,12 @@ %macro ERROR 1 mov al, %1 ; al = 1 byte error code mapped to ascii values + %ifdef __STEVIA_DEV_DEBUG + __BOCHS_MAGIC_DEBUG + %endif jmp error + + %endmacro ; pass error as ascii character in al, errors a-zA-Z or 0-9 diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index fb4e88a..994530d 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -86,11 +86,13 @@ init: mov ss, ax ; Set Stack Segment to data segment mov sp, stack_top ; Set Stack Pointer + mov ax, init + push ax ; simulate a return value to the begining of the stage2 loader + + push bp mov bp, sp sub sp, 0x20 ; 32 bytes for local varibles - sti - jmp word __STAGE2_SEGMENT:main ; ############### @@ -106,11 +108,6 @@ init: ; FAT32 Driver ; ############### -boot_drive_ptr: - dw 0x0000 -partition_offset_ptr: - dw 0x0000 - %include 'fat32/FAT32_SYS.inc' ; ############### @@ -191,7 +188,6 @@ main: call InitFATDriver print_string InitFATSYS_OK_cstr - ERROR STEVIA_DEBUG_HALT ; ; Find first cluster of bootable file ; @@ -201,11 +197,9 @@ main: push dword eax call PrintDWORD ; void PrintDWORD(uint32_t dword) add sp, 0x4 - print_string NewLine_cstr - + print_string NewLine_cstr hcf: - hlt - jmp short (hcf - $$) + ERROR STEVIA_DEBUG_OK ; ############################## ; @@ -505,6 +499,10 @@ stack_top: stage2_main_redzone: resb 32 +; +; structures +; + align 16, resb 1 partition_table resb PartTable_t_size @@ -518,19 +516,25 @@ fat32_nc_data resb 16 align 16, resb 1 lba_packet resb LBAPkt_t_size -align 16, resb 1 -SteviaInfo: - resd 4 align 16, resb 1 fat32_state: resb FAT32_State_t_size align 16, resb 1 -mbr_sector_data: - resb 512 -vbr_sector_data: - resb 512 +SteviaInfo: + resd 4 +; +; locals +; +boot_drive_ptr: + resw 1 +partition_offset_ptr: + resw 1 + +; +; large continuous allocations +; align 16, resb 1 disk_buffer: resb 512