From a6835df63e935a90eddb9269ccb385116f214595 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Wed, 2 Oct 2024 12:37:21 -0400 Subject: [PATCH] =?UTF-8?q?fixing=20how=20the=20stack=20works=20stage1=20?= =?UTF-8?q?=F0=9F=98=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stage2/stage2.nasm | 47 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index 57cc708..7d0fd9e 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -72,44 +72,40 @@ main: mov ax, 0xBEEF push ax ; mark top of stack for debuging - push bp - mov bp, sp lea ax, [HelloPrompt_cstr] push ax call PrintString - leave + add sp, 0x2 ; enable A20 gate - push bp - mov bp, sp call EnableA20 + lea ax, [A20_Enabled_cstr] push ax call PrintString - leave + add sp, 0x2 ; get system memory map - push bp - mov bp, sp call GetMemoryMap + lea ax, [MemoryMap_OK_cstr] push ax call PrintString - leave + add sp, 0x2 ; enter unreal mode - push bp - mov bp, sp call EnterUnrealMode + lea ax, [UnrealMode_OK_cstr] push ax call PrintString - leave + add sp, 0x2 + + ; FAT Driver setup push bp mov bp, sp call InitFATDriver - leave ; ; Find first cluster of bootable file @@ -117,29 +113,26 @@ main: push bp mov bp, sp call SearchFATDIR - leave - PUSH_DWORD_EAX ; save return value of function + + PUSH_DWORD_EAX ; save return value of function as a 32-bit value on a 16-bit aligned stack + - push bp - mov bp, sp lea ax, [FileFound_OK_cstr] push ax call PrintString - leave + add sp, 0x2 POP_DWORD_EAX ; return value of SearchFATDIR push bp mov bp, sp PUSH_DWORD_EAX call PrintDWORD - leave + - push bp - mov bp, sp lea ax, [NewLine_cstr] push ax call PrintString - leave + add sp, 0x2 ; TODO @@ -544,11 +537,14 @@ read_disk_raw: ; Prints a C-Style string (null terminated) using BIOS vga teletype call ; void PrintString(char* buf) PrintString: + push bp + mov bp, sp + push si push di push bx - mov di, [bp - 2] ; first arg is char* + mov di, [bp + 2] ; first arg is char* .str_len: xor cx, cx ; ECX = 0 @@ -562,7 +558,7 @@ PrintString: dec cx ; CX contains the length of the string - nul byte at end .print: - mov si, [bp - 2] ; source string + mov si, [bp + 2] ; source string .print_L0: push bp mov bp, sp @@ -582,6 +578,9 @@ PrintString: pop bx pop di pop si + + mov sp, bp + pop bp ret ; Return from procedure ; Prints a single character