`system_malloc` OK (#261)

* move system_malloc to boot_O2

* Rename StartHeap into SystemArena

* match

* fake system_malloc data

* fix return types

* Rename Alloc to Malloc

* Update tools/disasm/files.txt

Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com>

* fix spec

Co-authored-by: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com>
This commit is contained in:
Anghelo Carvajal 2021-08-18 08:48:08 -04:00 committed by GitHub
parent 9eb438860c
commit 49922b4856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 88 additions and 60 deletions

View File

@ -167,14 +167,14 @@ void GfxPrint_PrintChar(GfxPrint* this, u8 c);
// void MtxConv_L2F(void);
void __assert(const char* file, u32 lineNum);
// void func_800862B4(void);
void* StartHeap_AllocMin1(u32 size);
void StartHeap_FreeNull(void* pvParm1);
void* SystemArena_MallocMin1(u32 size);
void SystemArena_FreeNull(void* pvParm1);
void func_8008633C(u32 param_1, s32 param_2, s32 param_3, UNK_PTR param_4);
void func_800863AC(u32 param_1, s32 param_2, s32 param_3, UNK_PTR param_4);
// void func_8008641C(void);
// void func_800864EC(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5);
// void func_80086588(void);
void StartHeap_Init(u32 base, u32 size);
void SystemArena_Init(u32 base, u32 size);
s32 func_80086620(OSMesgQueue* param_1, PadMgr* param_2, OSContStatus* param_3);
// void func_80086760(void);
// void func_80086794(void);
@ -209,16 +209,16 @@ s32 func_80086D40(f64 param_1);
f64 func_80086D6C(f64 param_1);
s32 func_80086D8C(f32 param_1);
s32 func_80086DAC(f64 param_1);
void* StartHeap_Alloc(u32 size);
void* StartHeap_AllocR(u32 size);
void* StartHeap_Realloc(void* oldPtr, u32 newSize);
void StartHeap_Free(void* ptr);
void* StartHeap_Calloc(s32 param_1, s32 param_2);
void StartHeap_AnalyzeArena(u32* maxFreeBlock, u32* bytesFree, u32* bytesAllocated);
// s32 StartHeap_CheckArena(void);
void StartHeap_InitArena(u32 base, u32 size);
// void StartHeap_Cleanup(void);
// u32 StartHeap_IsInitialized(void);
void* SystemArena_Malloc(u32 size);
void* SystemArena_MallocR(u32 size);
void* SystemArena_Realloc(void* oldPtr, u32 newSize);
void SystemArena_Free(void* ptr);
void* SystemArena_Calloc(u32 elements, u32 size);
void SystemArena_AnalyzeArena(u32* maxFreeBlock, u32* bytesFree, u32* bytesAllocated);
u32 SystemArena_CheckArena(void);
void SystemArena_InitArena(void* start, u32 size);
void SystemArena_Cleanup(void);
u8 SystemArena_IsInitialized(void);
s32 Rand_Next(void);
void Rand_Seed(u32 seed);
f32 Rand_ZeroOne(void);

View File

@ -322,7 +322,7 @@ extern StackEntry sFaultThreadInfo;
extern FaultThreadStruct gFaultStruct;
extern FaultDrawer sFaultDrawerStruct;
// extern UNK_TYPE4 D_8009CD10;
extern Arena startHeap;
extern Arena gSystemArena;
extern u32 sRandFloat;
// extern UNK_TYPE4 sArenaLockMsg;
extern OSTask tmp_task;

3
spec
View File

@ -43,13 +43,12 @@ beginseg
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/data/boot/boot_800862E0.data.o"
include "build/src/boot_O2/padsetup.o"
include "build/src/boot_O2/boot_80086760.o"
include "build/data/boot/boot_80086760.bss.o"
include "build/asm/boot/fp.text.o"
include "build/src/boot_O2/system_malloc.o"
include "build/data/boot/system_malloc.data.o"
include "build/data/boot/system_malloc.bss.o"
include "build/src/boot_O2/rand.o"
include "build/data/boot/rand.data.o"
include "build/data/boot/rand.bss.o"

View File

@ -1,8 +1,8 @@
#include "global.h"
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/StartHeap_AllocMin1.s")
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/SystemArena_MallocMin1.s")
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/StartHeap_FreeNull.s")
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/SystemArena_FreeNull.s")
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_8008633C.s")
@ -14,4 +14,4 @@
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_80086588.s")
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/StartHeap_Init.s")
#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/SystemArena_Init.s")

View File

@ -111,7 +111,7 @@ void* Load2_AllocateAndLoad(u32 vRomStart, u32 vRomEnd, u32 vRamStart, u32 vRamE
u32 size;
size = vRamEnd - vRamStart;
allocatedVRamAddr = StartHeap_AllocR(size);
allocatedVRamAddr = SystemArena_MallocR(size);
if (allocatedVRamAddr != NULL) {
Load2_LoadOverlay(vRomStart, vRomEnd, vRamStart, vRamEnd, (u32)allocatedVRamAddr);
}

View File

@ -1,21 +1,50 @@
#include "global.h"
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_Alloc.s")
Arena gSystemArena;
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_AllocR.s")
void* SystemArena_Malloc(u32 size) {
return __osMalloc(&gSystemArena, size);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_Realloc.s")
void* SystemArena_MallocR(u32 size) {
return __osMallocR(&gSystemArena, size);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_Free.s")
void* SystemArena_Realloc(void* oldPtr, u32 newSize) {
return __osRealloc(&gSystemArena, oldPtr, newSize);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_Calloc.s")
void SystemArena_Free(void* ptr) {
__osFree(&gSystemArena, ptr);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_AnalyzeArena.s")
void* SystemArena_Calloc(u32 elements, u32 size) {
void* ptr;
u32 totalSize = elements * size;
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_CheckArena.s")
ptr = __osMalloc(&gSystemArena, totalSize);
if (ptr != NULL) {
bzero(ptr, totalSize);
}
return ptr;
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_InitArena.s")
void SystemArena_AnalyzeArena(u32* maxFreeBlock, u32* bytesFree, u32* bytesAllocated) {
__osAnalyzeArena(&gSystemArena, maxFreeBlock, bytesFree, bytesAllocated);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_Cleanup.s")
u32 SystemArena_CheckArena(void) {
return __osCheckArena(&gSystemArena);
}
#pragma GLOBAL_ASM("asm/non_matchings/boot/system_malloc/StartHeap_IsInitialized.s")
void SystemArena_InitArena(void* start, u32 size) {
__osMallocInit(&gSystemArena, start, size);
}
void SystemArena_Cleanup(void) {
__osMallocCleanup(&gSystemArena);
}
u8 SystemArena_IsInitialized(void) {
return __osMallocIsInitalized(&gSystemArena);
}

View File

@ -170,7 +170,7 @@ void Game_ResizeHeap(GameState* gamestate, u32 size) {
alloc = &gamestate->alloc;
THA_Dt(&gamestate->heap);
Gamealloc_Free(alloc, heapStart);
StartHeap_AnalyzeArena(&systemMaxFree, &bytesFree, &bytesAllocated);
SystemArena_AnalyzeArena(&systemMaxFree, &bytesFree, &bytesAllocated);
size = ((systemMaxFree - (sizeof(ArenaNode))) < size) ? (0) : (size);
if (!size) {
size = systemMaxFree - (sizeof(ArenaNode));

View File

@ -92,7 +92,7 @@ void EffDust_Init(Actor* thisx, GlobalContext* globalCtx) {
this->scalingFactor = 20.0f;
break;
default:
StartHeap_Free(this);
SystemArena_Free(this);
break;
}
this->life = 10;

View File

@ -256,7 +256,7 @@
0x80096C30 : "loadfragment2",
0x80096C40 : "stackcheck",
0x80096C50 : "gfxprint",
0x80097500 : "system_malloc",
0x80097500 : "boot_800862E0",
0x80097530 : "rand",
0x80097540 : "vimodeHpf",
0x800975E0 : "sins",

View File

@ -157,14 +157,14 @@
0x80086258:("MtxConv_L2F",),
0x80086280:("__assert",),
0x800862B4:("func_800862B4",),
0x800862E0:("StartHeap_AllocMin1",),
0x80086310:("StartHeap_FreeNull",),
0x800862E0:("SystemArena_MallocMin1",),
0x80086310:("SystemArena_FreeNull",),
0x8008633C:("func_8008633C",),
0x800863AC:("func_800863AC",),
0x8008641C:("func_8008641C",),
0x800864EC:("func_800864EC",),
0x80086588:("func_80086588",),
0x800865F8:("StartHeap_Init",),
0x800865F8:("SystemArena_Init",),
0x80086620:("func_80086620",),
0x80086760:("func_80086760",),
0x80086794:("func_80086794",),
@ -199,16 +199,16 @@
0x80086D6C:("func_80086D6C",),
0x80086D8C:("func_80086D8C",),
0x80086DAC:("func_80086DAC",),
0x80086DD0:("StartHeap_Alloc",),
0x80086DF8:("StartHeap_AllocR",),
0x80086E20:("StartHeap_Realloc",),
0x80086E50:("StartHeap_Free",),
0x80086E78:("StartHeap_Calloc",),
0x80086ECC:("StartHeap_AnalyzeArena",),
0x80086F04:("StartHeap_CheckArena",),
0x80086F28:("StartHeap_InitArena",),
0x80086F58:("StartHeap_Cleanup",),
0x80086F7C:("StartHeap_IsInitialized",),
0x80086DD0:("SystemArena_Malloc",),
0x80086DF8:("SystemArena_MallocR",),
0x80086E20:("SystemArena_Realloc",),
0x80086E50:("SystemArena_Free",),
0x80086E78:("SystemArena_Calloc",),
0x80086ECC:("SystemArena_AnalyzeArena",),
0x80086F04:("SystemArena_CheckArena",),
0x80086F28:("SystemArena_InitArena",),
0x80086F58:("SystemArena_Cleanup",),
0x80086F7C:("SystemArena_IsInitialized",),
0x80086FA0:("Rand_Next",),
0x80086FD0:("Rand_Seed",),
0x80086FDC:("Rand_ZeroOne",),

View File

@ -321,7 +321,7 @@
0x8009C480:("gFaultStruct","FaultThreadStruct","",0x848),
0x8009CCD0:("sFaultDrawerStruct","FaultDrawer","",0x3c),
0x8009CD10:("D_8009CD10","UNK_TYPE4","",0x4),
0x8009CD20:("startHeap","Arena","",0x24),
0x8009CD20:("gSystemArena","Arena","",0x24),
0x8009CD50:("sRandFloat","f32","",0x4),
0x8009CD60:("sArenaLockMsg","OSMesg","[1]",0x4),
0x8009CD70:("tmp_task","OSTask","",0x40),

View File

@ -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/StartHeap_AllocMin1.s,StartHeap_AllocMin1,0x800862E0,0xC
asm/non_matchings/boot/boot_800862E0/StartHeap_FreeNull.s,StartHeap_FreeNull,0x80086310,0xB
asm/non_matchings/boot/boot_800862E0/SystemArena_MallocMin1.s,SystemArena_MallocMin1,0x800862E0,0xC
asm/non_matchings/boot/boot_800862E0/SystemArena_FreeNull.s,SystemArena_FreeNull,0x80086310,0xB
asm/non_matchings/boot/boot_800862E0/func_8008633C.s,func_8008633C,0x8008633C,0x1C
asm/non_matchings/boot/boot_800862E0/func_800863AC.s,func_800863AC,0x800863AC,0x1C
asm/non_matchings/boot/boot_800862E0/func_8008641C.s,func_8008641C,0x8008641C,0x34
asm/non_matchings/boot/boot_800862E0/func_800864EC.s,func_800864EC,0x800864EC,0x27
asm/non_matchings/boot/boot_800862E0/func_80086588.s,func_80086588,0x80086588,0x1C
asm/non_matchings/boot/boot_800862E0/StartHeap_Init.s,StartHeap_Init,0x800865F8,0xA
asm/non_matchings/boot/boot_800862E0/SystemArena_Init.s,SystemArena_Init,0x800865F8,0xA
asm/non_matchings/boot/padsetup/func_80086620.s,func_80086620,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
@ -196,16 +196,16 @@ asm/non_matchings/boot/fp/func_80086D50.s,func_80086D50,0x80086D50,0x7
asm/non_matchings/boot/fp/func_80086D6C.s,func_80086D6C,0x80086D6C,0x8
asm/non_matchings/boot/fp/func_80086D8C.s,func_80086D8C,0x80086D8C,0x8
asm/non_matchings/boot/fp/func_80086DAC.s,func_80086DAC,0x80086DAC,0x9
asm/non_matchings/boot/system_malloc/StartHeap_Alloc.s,StartHeap_Alloc,0x80086DD0,0xA
asm/non_matchings/boot/system_malloc/StartHeap_AllocR.s,StartHeap_AllocR,0x80086DF8,0xA
asm/non_matchings/boot/system_malloc/StartHeap_Realloc.s,StartHeap_Realloc,0x80086E20,0xC
asm/non_matchings/boot/system_malloc/StartHeap_Free.s,StartHeap_Free,0x80086E50,0xA
asm/non_matchings/boot/system_malloc/StartHeap_Calloc.s,StartHeap_Calloc,0x80086E78,0x15
asm/non_matchings/boot/system_malloc/StartHeap_AnalyzeArena.s,StartHeap_AnalyzeArena,0x80086ECC,0xE
asm/non_matchings/boot/system_malloc/StartHeap_CheckArena.s,StartHeap_CheckArena,0x80086F04,0x9
asm/non_matchings/boot/system_malloc/StartHeap_InitArena.s,StartHeap_InitArena,0x80086F28,0xC
asm/non_matchings/boot/system_malloc/StartHeap_Cleanup.s,StartHeap_Cleanup,0x80086F58,0x9
asm/non_matchings/boot/system_malloc/StartHeap_IsInitialized.s,StartHeap_IsInitialized,0x80086F7C,0x9
asm/non_matchings/boot/system_malloc/SystemArena_Malloc.s,SystemArena_Malloc,0x80086DD0,0xA
asm/non_matchings/boot/system_malloc/SystemArena_MallocR.s,SystemArena_MallocR,0x80086DF8,0xA
asm/non_matchings/boot/system_malloc/SystemArena_Realloc.s,SystemArena_Realloc,0x80086E20,0xC
asm/non_matchings/boot/system_malloc/SystemArena_Free.s,SystemArena_Free,0x80086E50,0xA
asm/non_matchings/boot/system_malloc/SystemArena_Calloc.s,SystemArena_Calloc,0x80086E78,0x15
asm/non_matchings/boot/system_malloc/SystemArena_AnalyzeArena.s,SystemArena_AnalyzeArena,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_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
asm/non_matchings/boot/rand/Rand_Seed.s,Rand_Seed,0x80086FD0,0x3
asm/non_matchings/boot/rand/Rand_ZeroOne.s,Rand_ZeroOne,0x80086FDC,0x15

1 asm/non_matchings/boot/boot_main/bootproc.s bootproc 0x80080060 0x3C
154 asm/non_matchings/boot/mtxuty-cvt/MtxConv_L2F.s MtxConv_L2F 0x80086258 0xA
155 asm/non_matchings/boot/assert/__assert.s __assert 0x80086280 0xD
156 asm/non_matchings/boot/assert/func_800862B4.s func_800862B4 0x800862B4 0xB
157 asm/non_matchings/boot/boot_800862E0/StartHeap_AllocMin1.s asm/non_matchings/boot/boot_800862E0/SystemArena_MallocMin1.s StartHeap_AllocMin1 SystemArena_MallocMin1 0x800862E0 0xC
158 asm/non_matchings/boot/boot_800862E0/StartHeap_FreeNull.s asm/non_matchings/boot/boot_800862E0/SystemArena_FreeNull.s StartHeap_FreeNull SystemArena_FreeNull 0x80086310 0xB
159 asm/non_matchings/boot/boot_800862E0/func_8008633C.s func_8008633C 0x8008633C 0x1C
160 asm/non_matchings/boot/boot_800862E0/func_800863AC.s func_800863AC 0x800863AC 0x1C
161 asm/non_matchings/boot/boot_800862E0/func_8008641C.s func_8008641C 0x8008641C 0x34
162 asm/non_matchings/boot/boot_800862E0/func_800864EC.s func_800864EC 0x800864EC 0x27
163 asm/non_matchings/boot/boot_800862E0/func_80086588.s func_80086588 0x80086588 0x1C
164 asm/non_matchings/boot/boot_800862E0/StartHeap_Init.s asm/non_matchings/boot/boot_800862E0/SystemArena_Init.s StartHeap_Init SystemArena_Init 0x800865F8 0xA
165 asm/non_matchings/boot/padsetup/func_80086620.s func_80086620 0x80086620 0x50
166 asm/non_matchings/boot/boot_80086760/func_80086760.s func_80086760 0x80086760 0xD
167 asm/non_matchings/boot/boot_80086760/func_80086794.s func_80086794 0x80086794 0x8
196 asm/non_matchings/boot/fp/func_80086D6C.s func_80086D6C 0x80086D6C 0x8
197 asm/non_matchings/boot/fp/func_80086D8C.s func_80086D8C 0x80086D8C 0x8
198 asm/non_matchings/boot/fp/func_80086DAC.s func_80086DAC 0x80086DAC 0x9
199 asm/non_matchings/boot/system_malloc/StartHeap_Alloc.s asm/non_matchings/boot/system_malloc/SystemArena_Malloc.s StartHeap_Alloc SystemArena_Malloc 0x80086DD0 0xA
200 asm/non_matchings/boot/system_malloc/StartHeap_AllocR.s asm/non_matchings/boot/system_malloc/SystemArena_MallocR.s StartHeap_AllocR SystemArena_MallocR 0x80086DF8 0xA
201 asm/non_matchings/boot/system_malloc/StartHeap_Realloc.s asm/non_matchings/boot/system_malloc/SystemArena_Realloc.s StartHeap_Realloc SystemArena_Realloc 0x80086E20 0xC
202 asm/non_matchings/boot/system_malloc/StartHeap_Free.s asm/non_matchings/boot/system_malloc/SystemArena_Free.s StartHeap_Free SystemArena_Free 0x80086E50 0xA
203 asm/non_matchings/boot/system_malloc/StartHeap_Calloc.s asm/non_matchings/boot/system_malloc/SystemArena_Calloc.s StartHeap_Calloc SystemArena_Calloc 0x80086E78 0x15
204 asm/non_matchings/boot/system_malloc/StartHeap_AnalyzeArena.s asm/non_matchings/boot/system_malloc/SystemArena_AnalyzeArena.s StartHeap_AnalyzeArena SystemArena_AnalyzeArena 0x80086ECC 0xE
205 asm/non_matchings/boot/system_malloc/StartHeap_CheckArena.s asm/non_matchings/boot/system_malloc/SystemArena_CheckArena.s StartHeap_CheckArena SystemArena_CheckArena 0x80086F04 0x9
206 asm/non_matchings/boot/system_malloc/StartHeap_InitArena.s asm/non_matchings/boot/system_malloc/SystemArena_InitArena.s StartHeap_InitArena SystemArena_InitArena 0x80086F28 0xC
207 asm/non_matchings/boot/system_malloc/StartHeap_Cleanup.s asm/non_matchings/boot/system_malloc/SystemArena_Cleanup.s StartHeap_Cleanup SystemArena_Cleanup 0x80086F58 0x9
208 asm/non_matchings/boot/system_malloc/StartHeap_IsInitialized.s asm/non_matchings/boot/system_malloc/SystemArena_IsInitialized.s StartHeap_IsInitialized SystemArena_IsInitialized 0x80086F7C 0x9
209 asm/non_matchings/boot/rand/Rand_Next.s Rand_Next 0x80086FA0 0xC
210 asm/non_matchings/boot/rand/Rand_Seed.s Rand_Seed 0x80086FD0 0x3
211 asm/non_matchings/boot/rand/Rand_ZeroOne.s Rand_ZeroOne 0x80086FDC 0x15