bunch of changes mostly to do with cdecl16 conformity

moved top of stack marker to init
SetTextMode and Cursor done before hello msg
corrected CC/Stack usage to conform with cdecl16 for PrintString
corrected CC/Stack usage to conform with cdecl16 for PrintChar
corrected stack usage to conform with cdecl16 for SetTextMode
corrected stack usage to conform with cdecl16 for disable_cursor
This commit is contained in:
2024-10-03 13:49:44 -04:00
parent 054f4320ba
commit 929962eaca

View File

@@ -38,28 +38,30 @@ init:
mov ss, ax ; Set Stack Segment to 0 mov ss, ax ; Set Stack Segment to 0
mov sp, STACK_START ; Set Stack Pointer mov sp, STACK_START ; Set Stack Pointer
add sp, 0x4
mov ax, 0xDEAD
push word ax
mov ax, 0xBEEF
push word ax ; mark top of stack for debuging
mov bp, sp mov bp, sp
sti
jmp 0:main jmp 0:main
%include "config.inc" %include "config.inc"
%include "errors.inc" %include "errors.inc"
%include "memory.inc" %include "memory.inc"
%include "partition_table.inc" %include "partition_table.inc"
%include "fat32/bpb.inc" %include "fat32/bpb.inc"
%include "fat32/fat32_structures.inc" %include "fat32/fat32_structures.inc"
main: main:
sti
mov byte [fat32_ebpb + FAT32_ebpb_t.drive_number_8], dl mov byte [fat32_ebpb + FAT32_ebpb_t.drive_number_8], dl
mov word [partition_offset], si mov word [partition_offset], si
call SetTextMode
call disable_cursor
mov eax, dword [STAGE2_SIG] mov eax, dword [STAGE2_SIG]
cmp eax, 0xDEADBEEF cmp eax, 0xDEADBEEF
je main.signature_present je main.signature_present
@@ -67,16 +69,16 @@ main:
ERROR STAGE2_SIGNATURE_MISSING ERROR STAGE2_SIGNATURE_MISSING
.signature_present: .signature_present:
mov ax, 0xDEAD call SetTextMode
push ax call disable_cursor
mov ax, 0xBEEF
push ax ; mark top of stack for debuging
lea ax, [HelloPrompt_cstr] lea ax, [HelloPrompt_cstr]
push ax push ax
call PrintString call PrintString
add sp, 0x2 add sp, 0x2
ERROR STEVIA_DEBUG_HALT
; enable A20 gate ; enable A20 gate
call EnableA20 call EnableA20
@@ -544,9 +546,8 @@ PrintString:
push di push di
push bx push bx
mov di, [bp + 2] ; first arg is char* mov di, [bp + 4] ; first arg is char*
.str_len: .str_len:
xor cx, cx ; ECX = 0 xor cx, cx ; ECX = 0
not cx ; ECX = -1 == 0xFFFF not cx ; ECX = -1 == 0xFFFF
xor ax, ax ; search for al = 0x0 xor ax, ax ; search for al = 0x0
@@ -558,16 +559,12 @@ 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 + 4] ; source string
.print_L0: .print_L0:
push bp
mov bp, sp
movzx ax, byte [si] movzx ax, byte [si]
push ax push ax
call PrintCharacter call PrintCharacter
leave add sp, 0x2
inc si inc si
dec cx dec cx
@@ -586,11 +583,14 @@ PrintString:
; Prints a single character ; Prints a single character
; void PrintCharacter(char c); ; void PrintCharacter(char c);
PrintCharacter: PrintCharacter:
push bp
mov bp, sp
push si push si
push di push di
push bx push bx
.func_bios:
mov ax, [bp-2] ; c mov ax, [bp + 4] ; c
mov dx, 0x00ff mov dx, 0x00ff
and ax, dx and ax, dx
@@ -602,6 +602,9 @@ PrintCharacter:
pop bx pop bx
pop di pop di
pop si pop si
mov sp, bp
pop bp
ret ret
; prints the hex representation of of val_upper:val_lower (4 byte value) ; prints the hex representation of of val_upper:val_lower (4 byte value)
@@ -662,6 +665,15 @@ PrintDWORD:
; also clears screen ; also clears screen
; void SetTextMode(void) ; void SetTextMode(void)
SetTextMode: SetTextMode:
.prolog:
push bp
mov bp, sp
push si
push di
push bx
pushf
.func:
xor ah, ah ; Set Video mode BIOS function xor ah, ah ; Set Video mode BIOS function
mov al, 0x02 ; 16 color 80x25 Text mode mov al, 0x02 ; 16 color 80x25 Text mode
int 0x10 ; Call video interrupt int 0x10 ; Call video interrupt
@@ -670,6 +682,13 @@ SetTextMode:
xor al, al ; page 0 xor al, al ; page 0
int 0x10 ; call video interrupt int 0x10 ; call video interrupt
.endp: .endp:
popf
pop bx
pop di
pop si
mov sp, bp
pop bp
ret ret
; Address Range Descriptor Structure ; Address Range Descriptor Structure
@@ -826,22 +845,31 @@ GetMemoryMap:
; disables blinking text mode cursor ; disables blinking text mode cursor
disable_cursor: disable_cursor:
pushf .prolog:
push eax push bp
push edx mov bp, sp
mov dx, 0x3D4 push si
push di
push bx
pushf
.func:
mov dx, 0x3D4
mov al, 0xA ; low cursor shape register mov al, 0xA ; low cursor shape register
out dx, al out dx, al
inc dx inc dx
mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape
out dx, al out dx, al
.endp:
popf
pop bx
pop di
pop si
pop edx mov sp, bp
pop eax pop bp
popf ret
ret
; ;
;NT 0x15 Function 2400 - Disable A20 ;NT 0x15 Function 2400 - Disable A20