From fc475a97565ade34d57f80970c6b5cebcc2892a7 Mon Sep 17 00:00:00 2001 From: Derek Hensley Date: Sun, 28 May 2023 20:04:07 -0700 Subject: [PATCH] Docs Cleanup (#1153) * sysheap * Gorons * Update goron comment * functions.h * Update src/boot_O2/system_heap.c Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> * add header * Fix header guards * Update data * Add malloc and free to header --------- Co-authored-by: engineer124 <47598039+engineer124@users.noreply.github.com> --- assets/xml/objects/object_oF1d_map.xml | 18 ++++---- include/functions.h | 4 -- include/system_heap.h | 11 +++++ include/system_malloc.h | 6 +-- spec | 2 +- .../{boot_800862E0.c => system_heap.c} | 41 +++++++++++-------- src/boot_O2/system_malloc.c | 2 +- src/code/main.c | 3 +- tools/disasm/files.txt | 4 +- tools/disasm/functions.txt | 18 ++++---- tools/sizes/boot_functions.csv | 18 ++++---- 11 files changed, 71 insertions(+), 56 deletions(-) create mode 100644 include/system_heap.h rename src/boot_O2/{boot_800862E0.c => system_heap.c} (66%) diff --git a/assets/xml/objects/object_oF1d_map.xml b/assets/xml/objects/object_oF1d_map.xml index 0f331cbcec..a241eac131 100644 --- a/assets/xml/objects/object_oF1d_map.xml +++ b/assets/xml/objects/object_oF1d_map.xml @@ -47,16 +47,16 @@ - - + + - - - - - - - + + + + + + + diff --git a/include/functions.h b/include/functions.h index bcc79f9e5e..0f99fb24b1 100644 --- a/include/functions.h +++ b/include/functions.h @@ -128,10 +128,6 @@ void MtxConv_L2F(MtxF* mtx, Mtx* mf); void __assert(const char* file, u32 lineNum); // void func_800862B4(void); -void* SystemArena_MallocMin1(u32 size); -void SystemArena_FreeNullCheck(void* ptr); -void SystemArena_RunInits(void); -void SystemArena_Init(void* start, size_t size); s32 func_80086620(OSMesgQueue* param_1, PadMgr* param_2, OSContStatus* param_3); f32 func_80086760(f32 x); // void func_80086794(void); diff --git a/include/system_heap.h b/include/system_heap.h new file mode 100644 index 0000000000..e0864cca6c --- /dev/null +++ b/include/system_heap.h @@ -0,0 +1,11 @@ +#ifndef SYSTEM_HEAP_H +#define SYSTEM_HEAP_H + +#include "libc/stddef.h" +#include "PR/ultratypes.h" + +void* SystemHeap_Malloc(size_t size); +void SystemHeap_Free(void* ptr); +void SystemHeap_Init(void* start, size_t size); + +#endif diff --git a/include/system_malloc.h b/include/system_malloc.h index e92eaf89fd..cf91899ef0 100644 --- a/include/system_malloc.h +++ b/include/system_malloc.h @@ -1,5 +1,5 @@ -#ifndef SYSTEM_MALLOC -#define SYSTEM_MALLOC +#ifndef SYSTEM_MALLOC_H +#define SYSTEM_MALLOC_H #include "PR/ultratypes.h" #include "os_malloc.h" @@ -11,7 +11,7 @@ void SystemArena_Free(void* ptr); void* SystemArena_Calloc(u32 elements, size_t size); void SystemArena_GetSizes(size_t* maxFreeBlock, size_t* bytesFree, size_t* bytesAllocated); u32 SystemArena_CheckArena(void); -void SystemArena_InitArena(void* start, size_t size); +void SystemArena_Init(void* start, size_t size); void SystemArena_Cleanup(void); u8 SystemArena_IsInitialized(void); diff --git a/spec b/spec index 4d327dc207..9bfbc750c4 100644 --- a/spec +++ b/spec @@ -36,7 +36,7 @@ beginseg include "build/data/boot/gfxprint.data.o" include "build/src/boot_O2/mtxuty-cvt.o" include "build/src/boot_O2/assert.o" - include "build/src/boot_O2/boot_800862E0.o" + include "build/src/boot_O2/system_heap.o" include "build/src/boot_O2/padsetup.o" include "build/src/boot_O2/boot_80086760.o" include "build/asm/boot/fp.text.o" diff --git a/src/boot_O2/boot_800862E0.c b/src/boot_O2/system_heap.c similarity index 66% rename from src/boot_O2/boot_800862E0.c rename to src/boot_O2/system_heap.c index 5774af9dac..66e53dc124 100644 --- a/src/boot_O2/boot_800862E0.c +++ b/src/boot_O2/system_heap.c @@ -1,3 +1,10 @@ +/** + * @file system_heap.c + * + * @note: + * Only SystemHeap_Init() is used, and is essentially just a wrapper for SystemArena_Init(). + * + */ #include "global.h" #include "system_malloc.h" @@ -6,20 +13,20 @@ typedef void (*BlockFunc1)(void*, u32); typedef void (*BlockFunc8)(void*, u32, u32, u32, u32, u32, u32, u32, u32); typedef struct InitFunc { - uintptr_t nextOffset; - void (*func)(void); -} InitFunc; + /* 0x0 */ uintptr_t nextOffset; + /* 0x4 */ void (*func)(void); +} InitFunc; // size = 0x8 void* sInitFuncs = NULL; -char sNew[] = { 0x00, 0x00, 0x00, 0x00 }; +char sNew[] = ""; -char D_80097508[] = { +UNK_TYPE1 D_80097508[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x80, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, }; -void* SystemArena_MallocMin1(size_t size) { +void* SystemHeap_Malloc(size_t size) { if (size == 0) { size = 1; } @@ -27,13 +34,13 @@ void* SystemArena_MallocMin1(size_t size) { return __osMalloc(&gSystemArena, size); } -void SystemArena_FreeNullCheck(void* ptr) { +void SystemHeap_Free(void* ptr) { if (ptr != NULL) { __osFree(&gSystemArena, ptr); } } -void SystemArena_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc blockFunc) { +void SystemHeap_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc blockFunc) { uintptr_t pos = blk; for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) { @@ -41,7 +48,7 @@ void SystemArena_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc } } -void SystemArena_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc) { +void SystemHeap_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc) { uintptr_t pos = blk; for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) { @@ -49,9 +56,9 @@ void SystemArena_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc } } -void* SystemArena_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) { +void* SystemHeap_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) { if (blk == NULL) { - blk = SystemArena_MallocMin1(nBlk * blkSize); + blk = SystemHeap_Malloc(nBlk * blkSize); } if (blk != NULL && blockFunc != NULL) { @@ -65,7 +72,7 @@ void* SystemArena_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFun return blk; } -void SystemArena_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc, s32 shouldFree) { +void SystemHeap_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc, s32 shouldFree) { uintptr_t pos; uintptr_t start; size_t maskedBlkSize; @@ -86,11 +93,11 @@ void SystemArena_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, Bl } if (shouldFree) { - SystemArena_FreeNullCheck(blk); + SystemHeap_Free(blk); } } -void SystemArena_RunInits(void) { +void SystemHeap_RunInits(void) { InitFunc* initFunc = (InitFunc*)&sInitFuncs; u32 nextOffset = initFunc->nextOffset; InitFunc* prev = NULL; @@ -110,7 +117,7 @@ void SystemArena_RunInits(void) { sInitFuncs = prev; } -void SystemArena_Init(void* start, size_t size) { - SystemArena_InitArena(start, size); - SystemArena_RunInits(); +void SystemHeap_Init(void* start, size_t size) { + SystemArena_Init(start, size); + SystemHeap_RunInits(); } diff --git a/src/boot_O2/system_malloc.c b/src/boot_O2/system_malloc.c index 56608166cb..cea017b38b 100644 --- a/src/boot_O2/system_malloc.c +++ b/src/boot_O2/system_malloc.c @@ -38,7 +38,7 @@ u32 SystemArena_CheckArena(void) { return __osCheckArena(&gSystemArena); } -void SystemArena_InitArena(void* start, size_t size) { +void SystemArena_Init(void* start, size_t size) { __osMallocInit(&gSystemArena, start, size); } diff --git a/src/code/main.c b/src/code/main.c index 6eadd591a7..1862404899 100644 --- a/src/code/main.c +++ b/src/code/main.c @@ -8,6 +8,7 @@ #include "buffers.h" #include "stack.h" #include "stackcheck.h" +#include "system_heap.h" extern OSMesgQueue sSiIntMsgQ; extern OSMesg sSiIntMsgBuf[1]; @@ -44,7 +45,7 @@ void Main(void* arg) { sysHeap = gSystemHeap; fb = 0x80780000; startHeapSize = fb - sysHeap; - SystemArena_Init(sysHeap, startHeapSize); + SystemHeap_Init(sysHeap, startHeapSize); Regs_Init(); diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index 88fab2cab8..df205189fd 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -57,7 +57,7 @@ 0x80085570 : "gfxprint", 0x80086110 : "mtxuty-cvt", 0x80086280 : "assert", - 0x800862E0 : "", + 0x800862E0 : "system_heap", 0x80086620 : "padsetup", 0x80086760 : "boot_80086760", 0x80086C70 : "fp", @@ -256,7 +256,7 @@ 0x80096C30 : "loadfragment2", 0x80096C40 : "stackcheck", 0x80096C50 : "gfxprint", - 0x80097500 : "boot_800862E0", + 0x80097500 : "system_heap", 0x80097520 : "fp", 0x80097530 : "rand", 0x80097540 : "osViModeNtscHpf1", diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index 127fb34bf4..0422c71e2b 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -157,14 +157,14 @@ 0x80086258:("MtxConv_L2F",), 0x80086280:("__assert",), 0x800862B4:("func_800862B4",), - 0x800862E0:("SystemArena_MallocMin1",), - 0x80086310:("SystemArena_FreeNullCheck",), - 0x8008633C:("SystemArena_RunBlockFunc",), - 0x800863AC:("SystemArena_RunBlockFunc1",), - 0x8008641C:("SystemArena_RunBlockFunc8",), - 0x800864EC:("SystemArena_RunBlockFunc1Reverse",), - 0x80086588:("SystemArena_RunInits",), - 0x800865F8:("SystemArena_Init",), + 0x800862E0:("SystemHeap_Malloc",), + 0x80086310:("SystemHeap_Free",), + 0x8008633C:("SystemHeap_RunBlockFunc",), + 0x800863AC:("SystemHeap_RunBlockFunc1",), + 0x8008641C:("SystemHeap_RunBlockFunc8",), + 0x800864EC:("SystemHeap_RunBlockFunc1Reverse",), + 0x80086588:("SystemHeap_RunInits",), + 0x800865F8:("SystemHeap_Init",), 0x80086620:("PadSetup_Init",), 0x80086760:("func_80086760",), 0x80086794:("func_80086794",), @@ -206,7 +206,7 @@ 0x80086E78:("SystemArena_Calloc",), 0x80086ECC:("SystemArena_GetSizes",), 0x80086F04:("SystemArena_CheckArena",), - 0x80086F28:("SystemArena_InitArena",), + 0x80086F28:("SystemArena_Init",), 0x80086F58:("SystemArena_Cleanup",), 0x80086F7C:("SystemArena_IsInitialized",), 0x80086FA0:("Rand_Next",), diff --git a/tools/sizes/boot_functions.csv b/tools/sizes/boot_functions.csv index bbcf6d5dea..744376bcc9 100644 --- a/tools/sizes/boot_functions.csv +++ b/tools/sizes/boot_functions.csv @@ -154,14 +154,14 @@ asm/non_matchings/boot/mtxuty-cvt/MtxConv_F2L.s,MtxConv_F2L,0x80086110,0x52 asm/non_matchings/boot/mtxuty-cvt/MtxConv_L2F.s,MtxConv_L2F,0x80086258,0xA asm/non_matchings/boot/assert/__assert.s,__assert,0x80086280,0xD asm/non_matchings/boot/assert/func_800862B4.s,func_800862B4,0x800862B4,0xB -asm/non_matchings/boot/boot_800862E0/SystemArena_MallocMin1.s,SystemArena_MallocMin1,0x800862E0,0xC -asm/non_matchings/boot/boot_800862E0/SystemArena_FreeNullCheck.s,SystemArena_FreeNullCheck,0x80086310,0xB -asm/non_matchings/boot/boot_800862E0/SystemArena_RunBlockFunc.s,SystemArena_RunBlockFunc,0x8008633C,0x1C -asm/non_matchings/boot/boot_800862E0/SystemArena_RunBlockFunc1.s,SystemArena_RunBlockFunc1,0x800863AC,0x1C -asm/non_matchings/boot/boot_800862E0/SystemArena_RunBlockFunc8.s,SystemArena_RunBlockFunc8,0x8008641C,0x34 -asm/non_matchings/boot/boot_800862E0/SystemArena_RunBlockFunc1Reverse.s,SystemArena_RunBlockFunc1Reverse,0x800864EC,0x27 -asm/non_matchings/boot/boot_800862E0/SystemArena_RunInits.s,SystemArena_RunInits,0x80086588,0x1C -asm/non_matchings/boot/boot_800862E0/SystemArena_Init.s,SystemArena_Init,0x800865F8,0xA +asm/non_matchings/boot/boot_800862E0/SystemHeap_Malloc.s,SystemHeap_Malloc,0x800862E0,0xC +asm/non_matchings/boot/boot_800862E0/SystemArena_Free.s,SystemArena_Free,0x80086310,0xB +asm/non_matchings/boot/boot_800862E0/SystemHeap_RunBlockFunc.s,SystemHeap_RunBlockFunc,0x8008633C,0x1C +asm/non_matchings/boot/boot_800862E0/SystemHeap_RunBlockFunc1.s,SystemHeap_RunBlockFunc1,0x800863AC,0x1C +asm/non_matchings/boot/boot_800862E0/SystemHeap_RunBlockFunc8.s,SystemHeap_RunBlockFunc8,0x8008641C,0x34 +asm/non_matchings/boot/boot_800862E0/SystemHeap_RunBlockFunc1Reverse.s,SystemHeap_RunBlockFunc1Reverse,0x800864EC,0x27 +asm/non_matchings/boot/boot_800862E0/SystemHeap_RunInits.s,SystemHeap_RunInits,0x80086588,0x1C +asm/non_matchings/boot/boot_800862E0/SystemHeap_Init.s,SystemHeap_Init,0x800865F8,0xA asm/non_matchings/boot/padsetup/PadSetup_Init.s,PadSetup_Init,0x80086620,0x50 asm/non_matchings/boot/boot_80086760/func_80086760.s,func_80086760,0x80086760,0xD asm/non_matchings/boot/boot_80086760/func_80086794.s,func_80086794,0x80086794,0x8 @@ -203,7 +203,7 @@ asm/non_matchings/boot/system_malloc/SystemArena_Free.s,SystemArena_Free,0x80086 asm/non_matchings/boot/system_malloc/SystemArena_Calloc.s,SystemArena_Calloc,0x80086E78,0x15 asm/non_matchings/boot/system_malloc/SystemArena_GetSizes.s,SystemArena_GetSizes,0x80086ECC,0xE asm/non_matchings/boot/system_malloc/SystemArena_CheckArena.s,SystemArena_CheckArena,0x80086F04,0x9 -asm/non_matchings/boot/system_malloc/SystemArena_InitArena.s,SystemArena_InitArena,0x80086F28,0xC +asm/non_matchings/boot/system_malloc/SystemArena_Init.s,SystemArena_Init,0x80086F28,0xC asm/non_matchings/boot/system_malloc/SystemArena_Cleanup.s,SystemArena_Cleanup,0x80086F58,0x9 asm/non_matchings/boot/system_malloc/SystemArena_IsInitialized.s,SystemArena_IsInitialized,0x80086F7C,0x9 asm/non_matchings/boot/rand/Rand_Next.s,Rand_Next,0x80086FA0,0xC