summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDerek Hensley <hensley.derek58@gmail.com>2022-03-29 12:42:44 -0700
committerGitHub <noreply@github.com>2022-03-29 20:42:44 +0100
commitec9909c65cc909be4f1fb4dec08a003dbae520ee (patch)
tree28c2a467c19c153134fc36e499d29abd26e2e887
parentafec1c56a62d2d451e4ab00a1e5da5a14cf6a9c0 (diff)
Boot_800862E0 OK (#769)
* boot_800862E0 OK * Ran format.sh * attempt at fixing bss reordering * boot_800862E0 OK (for real this time) * Run formatter * Changes u32 pointers to uintptr_t and sizes to size_t * Run formatter * Fix bss reordering * Delete baserom.mm.us.rev1.z64:Zone.Identifier * Cleanup and some notes * Try my best to document * remove comments * Remove D_80097508 from variables.h Co-authored-by: kyleburnette <kyle@kyleburnette.com> Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
-rw-r--r--include/functions.h12
-rw-r--r--include/variables.h1
-rw-r--r--spec1
-rw-r--r--src/boot_O2/boot_800862E0.c116
-rw-r--r--tools/disasm/functions.txt12
-rw-r--r--tools/disasm/variables.txt4
-rw-r--r--tools/sizes/boot_functions.csv12
7 files changed, 126 insertions, 32 deletions
diff --git a/include/functions.h b/include/functions.h
index c4bd9eef7..26de0794d 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -153,14 +153,10 @@ void MtxConv_L2F(MtxF* m1, MatrixInternal* m2);
void __assert(const char* file, u32 lineNum);
// void func_800862B4(void);
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 SystemArena_Init(u32 base, u32 size);
-s32 PadSetup_Init(OSMesgQueue* mq, u8* outMask, OSContStatus* status);
+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);
// void func_80086760(void);
// void func_80086794(void);
// void func_800867B4(void);
diff --git a/include/variables.h b/include/variables.h
index c5047526c..4d2e0e42c 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -43,7 +43,6 @@ extern StackEntry* sStackInfoListEnd;
// extern UNK_TYPE1 sGfxPrintUnkTLUT;
// extern UNK_TYPE1 sGfxPrintUnkData;
// extern UNK_TYPE1 sGfxPrintFontData;
-// extern UNK_TYPE4 D_80097500;
// extern UNK_TYPE4 D_80097524;
// extern u32 sRandInt;
extern OSViMode osViModeNtscHpf1;
diff --git a/spec b/spec
index 45da21f4f..73bb622b4 100644
--- a/spec
+++ b/spec
@@ -38,7 +38,6 @@ 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/asm/boot/fp.text.o"
diff --git a/src/boot_O2/boot_800862E0.c b/src/boot_O2/boot_800862E0.c
index 1055dfe1b..5774af9da 100644
--- a/src/boot_O2/boot_800862E0.c
+++ b/src/boot_O2/boot_800862E0.c
@@ -1,18 +1,116 @@
#include "global.h"
-#include "os_malloc.h"
+#include "system_malloc.h"
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/SystemArena_MallocMin1.s")
+typedef void (*BlockFunc)(void*);
+typedef void (*BlockFunc1)(void*, u32);
+typedef void (*BlockFunc8)(void*, u32, u32, u32, u32, u32, u32, u32, u32);
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/SystemArena_FreeNull.s")
+typedef struct InitFunc {
+ uintptr_t nextOffset;
+ void (*func)(void);
+} InitFunc;
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_8008633C.s")
+void* sInitFuncs = NULL;
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_800863AC.s")
+char sNew[] = { 0x00, 0x00, 0x00, 0x00 };
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_8008641C.s")
+char 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,
+};
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_800864EC.s")
+void* SystemArena_MallocMin1(size_t size) {
+ if (size == 0) {
+ size = 1;
+ }
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/func_80086588.s")
+ return __osMalloc(&gSystemArena, size);
+}
-#pragma GLOBAL_ASM("asm/non_matchings/boot/boot_800862E0/SystemArena_Init.s")
+void SystemArena_FreeNullCheck(void* ptr) {
+ if (ptr != NULL) {
+ __osFree(&gSystemArena, ptr);
+ }
+}
+
+void SystemArena_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)) {
+ blockFunc(pos);
+ }
+}
+
+void SystemArena_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)) {
+ blockFunc(pos, 2);
+ }
+}
+
+void* SystemArena_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) {
+ if (blk == NULL) {
+ blk = SystemArena_MallocMin1(nBlk * blkSize);
+ }
+
+ if (blk != NULL && blockFunc != NULL) {
+ uintptr_t pos = blk;
+
+ for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) {
+ blockFunc(pos, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+ }
+
+ return blk;
+}
+
+void SystemArena_RunBlockFunc1Reverse(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc, s32 shouldFree) {
+ uintptr_t pos;
+ uintptr_t start;
+ size_t maskedBlkSize;
+
+ if (blk == NULL) {
+ return;
+ }
+
+ if (blockFunc != NULL) {
+ start = blk;
+ maskedBlkSize = (blkSize & ~0);
+ pos = (uintptr_t)start + (nBlk * blkSize);
+
+ while (pos > start) {
+ pos -= maskedBlkSize;
+ blockFunc(pos, 2);
+ }
+ }
+
+ if (shouldFree) {
+ SystemArena_FreeNullCheck(blk);
+ }
+}
+
+void SystemArena_RunInits(void) {
+ InitFunc* initFunc = (InitFunc*)&sInitFuncs;
+ u32 nextOffset = initFunc->nextOffset;
+ InitFunc* prev = NULL;
+
+ while (nextOffset != 0) {
+ initFunc = (InitFunc*)((uintptr_t)initFunc + nextOffset);
+
+ if (initFunc->func != NULL) {
+ (*initFunc->func)();
+ }
+
+ nextOffset = initFunc->nextOffset;
+ initFunc->nextOffset = (uintptr_t)prev;
+ prev = initFunc;
+ }
+
+ sInitFuncs = prev;
+}
+
+void SystemArena_Init(void* start, size_t size) {
+ SystemArena_InitArena(start, size);
+ SystemArena_RunInits();
+}
diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt
index fd71e02ad..2ca5d4dd1 100644
--- a/tools/disasm/functions.txt
+++ b/tools/disasm/functions.txt
@@ -158,12 +158,12 @@
0x80086280:("__assert",),
0x800862B4:("func_800862B4",),
0x800862E0:("SystemArena_MallocMin1",),
- 0x80086310:("SystemArena_FreeNull",),
- 0x8008633C:("func_8008633C",),
- 0x800863AC:("func_800863AC",),
- 0x8008641C:("func_8008641C",),
- 0x800864EC:("func_800864EC",),
- 0x80086588:("func_80086588",),
+ 0x80086310:("SystemArena_FreeNullCheck",),
+ 0x8008633C:("SystemArena_RunBlockFunc",),
+ 0x800863AC:("SystemArena_RunBlockFunc1",),
+ 0x8008641C:("SystemArena_RunBlockFunc8",),
+ 0x800864EC:("SystemArena_RunBlockFunc1Reverse",),
+ 0x80086588:("SystemArena_RunInits",),
0x800865F8:("SystemArena_Init",),
0x80086620:("PadSetup_Init",),
0x80086760:("func_80086760",),
diff --git a/tools/disasm/variables.txt b/tools/disasm/variables.txt
index 2e66c57e1..e7adc27f4 100644
--- a/tools/disasm/variables.txt
+++ b/tools/disasm/variables.txt
@@ -35,7 +35,9 @@
0x80096CD0:("sGfxPrintUnkTLUT","u16","[16]",0x20),
0x80096CF0:("sGfxPrintUnkData","u8","[8]",0x8),
0x80096CF8:("sGfxPrintFontData","u8","[0x800]",0x800),
- 0x80097500:("D_80097500","UNK_TYPE4","",0x4),
+ 0x80097500:("sInitFuncs","void*","",0x4),
+ 0x80097504:("sNew","char","[4]",0x4),
+ 0x80097508:("D_80097508","[24]","",0x18),
0x80097520:("qNaN0x3FFFFF","f32","",0x4),
0x80097524:("qNaN0x10000","f32","",0x4),
0x80097528:("sNaN0x3FFFFF","f32","",0x4),
diff --git a/tools/sizes/boot_functions.csv b/tools/sizes/boot_functions.csv
index f652c0d43..6c5c92e16 100644
--- a/tools/sizes/boot_functions.csv
+++ b/tools/sizes/boot_functions.csv
@@ -155,12 +155,12 @@ 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_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/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/padsetup/PadSetup_Init.s,PadSetup_Init,0x80086620,0x50
asm/non_matchings/boot/boot_80086760/func_80086760.s,func_80086760,0x80086760,0xD