moved stack to end of bss & reduced size for now.

removed redzone label
reordered sp/bp setup and bss zeroing in init:
fixed kmemcpy call stack usage
This commit is contained in:
2024-10-15 12:56:12 -04:00
parent b4621a7fb8
commit aa8c7b67ab

View File

@@ -47,8 +47,6 @@
%endmacro %endmacro
section .text section .text
org 0x0500
begin_text: begin_text:
jmp short (init - $$) jmp short (init - $$)
nop nop
@@ -59,39 +57,36 @@ nop
; dx = ptr FAT32_bpb_t fat32_bpb ; dx = ptr FAT32_bpb_t fat32_bpb
ALIGN 4, db 0x90 ALIGN 4, db 0x90
init: init:
__BOCHS_MAGIC_DEBUG
cli ; We do not want to be interrupted cli ; We do not want to be interrupted
; mov ax, __STAGE2_SEGMENT ; set all our segments to the configured segment, excep es
mov ds, ax ; *
mov fs, ax ; *
mov gs, ax ; *
mov ss, ax
; Zero BSS section ; Zero BSS section
;
mov cx, (end_bss - begin_bss) ; count = bss length mov cx, (end_bss - begin_bss) ; count = bss length
mov ax, begin_bss mov ax, begin_bss
shr ax, 4 shr ax, 4
mov es, ax ; es = begining of bss section mov es, ax ; es = begining of bss section, remember to restore ES later
xor ax, ax
mov di, ax ; dst = 0
xor ax, ax ; val = 0
mov di, ax ; dst = 0 (start of segment)
cld cld
rep stosb ; zero bss section rep stosb
; done zeroing BSS
mov ax, __STAGE2_SEGMENT ; set all our segments to the configured segment mov ax, __STAGE2_SEGMENT
mov ds, ax ; * mov es, ax
mov es, ax ; * ; done zeroing bss section
mov fs, ax ; *
mov gs, ax ; *
mov ss, ax ; Set Stack Segment to data segment mov sp, stack_top
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 mov bp, sp
sub sp, 0x20 ; 32 bytes for local varibles sub sp, 0x20
push bp ; setup a somewhat normal stack frame, minus a ret ptr
sti sti
jmp word __STAGE2_SEGMENT:main jmp word __STAGE2_SEGMENT:main
@@ -154,14 +149,15 @@ main:
mov ax, PartTable_t_size mov ax, PartTable_t_size
push ax push ax
mov ax, [bp - 6] ; ptr partition_table mov ax, [bp - 6] ; ptr partition_table
push ax
mov ax, partition_table mov ax, partition_table
push ax push ax
call kmemcpy ; copy partition table data call kmemcpy ; copy partition table data
add sp, 0x6 add sp, 0x6
mov ax, (FAT32_bpb_t_size + FAT32_ebpb_t_size) ; size in byte mov ax, (FAT32_bpb_t_size + FAT32_ebpb_t_size) ; size in byte
push ax push ax
mov ax, [bp - 8] ; start of bpb - 0x3 for the jump short main at the start mov ax, [bp - 8]
push ax push ax
mov ax, fat32_bpb ; defined in memory.inc, destination mov ax, fat32_bpb ; defined in memory.inc, destination
push ax push ax
@@ -196,7 +192,6 @@ main:
print_string FileFound_OK_cstr print_string FileFound_OK_cstr
push dword eax push dword eax
call PrintDWORD ; void PrintDWORD(uint32_t dword) call PrintDWORD ; void PrintDWORD(uint32_t dword)
add sp, 0x4
print_string NewLine_cstr print_string NewLine_cstr
hcf: hcf:
ERROR STEVIA_DEBUG_OK ERROR STEVIA_DEBUG_OK
@@ -297,7 +292,7 @@ PrintDWORD:
push ax push ax
call PrintCharacter call PrintCharacter
add sp, 0x2 add sp, 0x2
pop cx pop cx
jcxz PrintDWORD.endp jcxz PrintDWORD.endp
@@ -491,17 +486,8 @@ times ((512 - 4) - ($ -$$) ) db 0x90 ; nop
STAGE2_SIG: dd 0xDEADBEEF ; Signature to mark the end of the stage2 STAGE2_SIG: dd 0xDEADBEEF ; Signature to mark the end of the stage2
section .bss follows=.sign section .bss follows=.sign
align 512, resb 1
begin_bss: begin_bss:
stack_bottom:
resb 4096
stack_top:
stage2_main_redzone:
resb 32
;
; structures ; structures
;
align 16, resb 1 align 16, resb 1
partition_table resb PartTable_t_size partition_table resb PartTable_t_size
@@ -550,4 +536,8 @@ align 16, resb 1
BIOSMemoryMap: BIOSMemoryMap:
resb 2048 resb 2048
align 512, resb 1
stack_bottom:
resb 1024
stack_top:
end_bss: end_bss: