fixing how the stack works stage1 😳

This commit is contained in:
2024-10-02 12:37:21 -04:00
parent 18bb9a5691
commit a6835df63e

View File

@@ -72,44 +72,40 @@ main:
mov ax, 0xBEEF mov ax, 0xBEEF
push ax ; mark top of stack for debuging push ax ; mark top of stack for debuging
push bp
mov bp, sp
lea ax, [HelloPrompt_cstr] lea ax, [HelloPrompt_cstr]
push ax push ax
call PrintString call PrintString
leave add sp, 0x2
; enable A20 gate ; enable A20 gate
push bp
mov bp, sp
call EnableA20 call EnableA20
lea ax, [A20_Enabled_cstr] lea ax, [A20_Enabled_cstr]
push ax push ax
call PrintString call PrintString
leave add sp, 0x2
; get system memory map ; get system memory map
push bp
mov bp, sp
call GetMemoryMap call GetMemoryMap
lea ax, [MemoryMap_OK_cstr] lea ax, [MemoryMap_OK_cstr]
push ax push ax
call PrintString call PrintString
leave add sp, 0x2
; enter unreal mode ; enter unreal mode
push bp
mov bp, sp
call EnterUnrealMode call EnterUnrealMode
lea ax, [UnrealMode_OK_cstr] lea ax, [UnrealMode_OK_cstr]
push ax push ax
call PrintString call PrintString
leave add sp, 0x2
; FAT Driver setup
push bp push bp
mov bp, sp mov bp, sp
call InitFATDriver call InitFATDriver
leave
; ;
; Find first cluster of bootable file ; Find first cluster of bootable file
@@ -117,29 +113,26 @@ main:
push bp push bp
mov bp, sp mov bp, sp
call SearchFATDIR 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] lea ax, [FileFound_OK_cstr]
push ax push ax
call PrintString call PrintString
leave add sp, 0x2
POP_DWORD_EAX ; return value of SearchFATDIR POP_DWORD_EAX ; return value of SearchFATDIR
push bp push bp
mov bp, sp mov bp, sp
PUSH_DWORD_EAX PUSH_DWORD_EAX
call PrintDWORD call PrintDWORD
leave
push bp
mov bp, sp
lea ax, [NewLine_cstr] lea ax, [NewLine_cstr]
push ax push ax
call PrintString call PrintString
leave add sp, 0x2
; TODO ; TODO
@@ -544,11 +537,14 @@ read_disk_raw:
; Prints a C-Style string (null terminated) using BIOS vga teletype call ; Prints a C-Style string (null terminated) using BIOS vga teletype call
; void PrintString(char* buf) ; void PrintString(char* buf)
PrintString: PrintString:
push bp
mov bp, sp
push si push si
push di push di
push bx push bx
mov di, [bp - 2] ; first arg is char* mov di, [bp + 2] ; first arg is char*
.str_len: .str_len:
xor cx, cx ; ECX = 0 xor cx, cx ; ECX = 0
@@ -562,7 +558,7 @@ PrintString:
dec cx ; CX contains the length of the string - nul byte at end dec cx ; CX contains the length of the string - nul byte at end
.print: .print:
mov si, [bp - 2] ; source string mov si, [bp + 2] ; source string
.print_L0: .print_L0:
push bp push bp
mov bp, sp mov bp, sp
@@ -582,6 +578,9 @@ PrintString:
pop bx pop bx
pop di pop di
pop si pop si
mov sp, bp
pop bp
ret ; Return from procedure ret ; Return from procedure
; Prints a single character ; Prints a single character