From 460165a8d1c2608bab3dc083403e24c0b86af0d4 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Sat, 13 Sep 2025 15:07:36 -0400 Subject: [PATCH] re-naming --- include/util/arena_alloc.nasm | 43 ++++++++++++++++------------------- src/stage2/stage2.nasm | 8 +++---- 2 files changed, 23 insertions(+), 28 deletions(-) diff --git a/include/util/arena_alloc.nasm b/include/util/arena_alloc.nasm index 19e7788..55db9f1 100644 --- a/include/util/arena_alloc.nasm +++ b/include/util/arena_alloc.nasm @@ -11,9 +11,9 @@ endstruc ; void arena_init(ArenaState *a) ; -arena_init: +ArenaInit: __CDECL16_PROC_ENTRY -.func: +.proc: mov ax, word [bp + 4] ; ptr to state structure mov di, ax @@ -25,15 +25,11 @@ arena_init: ; zero out heap area on init ; void* kmemset_byte(void* dst, uint8_t val, uint16_t len); ; TODO: use word or qword spacing at least to speed this up - mov ax, __ARENA_HEAP_SIZE - push ax ; len - xor ax, ax - push ax ; val = 0 - mov ax, __ARENA_HEAP_START - push ax ; dst + push __ARENA_HEAP_SIZE ; len + push 0x0 ; val = 0 + push __ARENA_HEAP_START ; dst call kmemset add sp, 0x6 - .endp: __CDECL16_PROC_EXIT ret @@ -43,7 +39,7 @@ arena_init: ; align x up to the nearest specified alignment (a), a should be a power of 2 ; (x + (a-1)) & ~(a-1) ; return value in ax -arena_align_up: +ArenaAlignUp: __CDECL16_PROC_ENTRY .func: ; if a == 0 return x @@ -51,7 +47,7 @@ arena_align_up: mov bx, [bp + 6] ; a test bx, bx - jz .endp + jz .endf ; enforce power-of-two for alignment, return x ; for example... @@ -69,7 +65,7 @@ arena_align_up: mov cx, bx dec cx test bx, cx - jnz .endp + jnz .endf dec bx ; a - 1 @@ -80,7 +76,7 @@ arena_align_up: and cx, bx ; and with the inverse mov ax, cx ; move to ax and return -.endp: +.endf: __CDECL16_PROC_EXIT ret @@ -88,9 +84,9 @@ arena_align_up: ; bp-2 - current used arena (i.e 'highmark') ; bp-4 - aligned_ptr ; bp-6 - new_end -arena_alloc: +ArenaAlloc: __CDECL16_PROC_ENTRY 0x10 -.func: +.proc: ; remove bytes from pool and increment mark to the new cursor location ; return a pointer to the begining of allocated segment mov bx, early_heap_state @@ -102,11 +98,10 @@ arena_alloc: push bx ; save heap_state pointer - mov ax, word [bp + 6] ; requested next allocation alignment - push ax - mov ax, word [bp - 2] ; current arena 'highmark' - push ax - call arena_align_up + + push word [bp + 6] ; requested next allocation alignment + push word [bp - 2] ; current arena 'highmark' + call ArenaAlignUp add sp, 0x4 mov word [bp - 4], ax ; save return value @@ -118,7 +113,7 @@ arena_alloc: mov dx, word [bx + ArenaStateStruc_t.end] cmp ax, dx - ja arena_alloc.error ; if our heap end is < the requested throw an error, heap is full + ja .error ; if our heap end is < the requested throw an error, heap is full ; else update the mark to the new value & return the aligned pointer ; mark_delta = new_end - curr_used @@ -140,7 +135,7 @@ arena_alloc: arena_mark: __CDECL16_PROC_ENTRY -.func: +.proc: ; return the current location of the 'cursor' in the allocator ERROR STEVIA_DEBUG_UNIMPLEMENTED .endp: @@ -149,7 +144,7 @@ arena_mark: arena_reset_to: __CDECL16_PROC_ENTRY -.func: +.proc: ; rewind the arena to a previously marked point ERROR STEVIA_DEBUG_UNIMPLEMENTED .endp: @@ -158,7 +153,7 @@ arena_reset_to: arena_reset: __CDECL16_PROC_ENTRY -.func: +.proc: ; reset the entire heap to a fresh state ERROR STEVIA_DEBUG_UNIMPLEMENTED .endp: diff --git a/src/stage2/stage2.nasm b/src/stage2/stage2.nasm index 9fba85b..99577bd 100755 --- a/src/stage2/stage2.nasm +++ b/src/stage2/stage2.nasm @@ -126,14 +126,14 @@ main: ; setup the early heap __CDECL16_CALL_ARGS early_heap_state - __CDECL16_CALL arena_init, 1 + __CDECL16_CALL ArenaInit, 1 __CDECL16_CALL_ARGS pszHelloPrompt __CDECL16_CALL PrintString, 1 ; setup and store our vbr/mbr (e)bpb __CDECL16_CALL_ARGS 0x200, 0x10 - __CDECL16_CALL arena_alloc, 2 + __CDECL16_CALL ArenaAlloc, 2 mov word [mbr_ptr], ax push ax ; dst @@ -142,13 +142,13 @@ main: __CDECL16_CALL ReadMbrData, 2 ; fill mbr buffer __CDECL16_CALL_ARGS 0x200, 0x10 - __CDECL16_CALL arena_alloc, 2 + __CDECL16_CALL ArenaAlloc, 2 mov word [vbr_ptr], ax push ax ; dst movzx ax, byte [u8_BootDrive] push ax ; boot_drive - __CDECL16_CALL ReadVbrData, 2 ; fill vbr buffer + __CDECL16_CALL ReadVbrData, 2 ; fill vbr buffer ; enable A20 gate call EnableA20