summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/boot_functions.h2
-rw-r--r--include/boot_variables.h2
-rw-r--r--include/system_heap.h11
-rw-r--r--linker_scripts/jp/symbol_addrs_boot.txt21
-rw-r--r--src/boot/O2/system_heap.c128
-rw-r--r--yamls/jp/boot.yaml5
6 files changed, 157 insertions, 12 deletions
diff --git a/include/boot_functions.h b/include/boot_functions.h
index 26177fa..0716d54 100644
--- a/include/boot_functions.h
+++ b/include/boot_functions.h
@@ -16,6 +16,8 @@
// void func_8002BF08_jp();
// void func_8002BF78_jp();
+// void func_8002BFA0_jp();
+
// void func_8003B960_jp();
// void func_8003B9B0_jp();
// void func_8003B9E0_jp();
diff --git a/include/boot_variables.h b/include/boot_variables.h
index 5d04b00..7cf0075 100644
--- a/include/boot_variables.h
+++ b/include/boot_variables.h
@@ -20,7 +20,7 @@ extern OSPiHandle* gCartHandle; // TODO: Determine where this goes
// extern UNK_TYPE D_8003BC90_jp;
// extern UNK_TYPE D_8003BC94_jp;
-// extern UNK_TYPE D_8003C560_jp;
+// extern UNK_TYPE __qrand_idum;
diff --git a/include/system_heap.h b/include/system_heap.h
new file mode 100644
index 0000000..a0138b0
--- /dev/null
+++ b/include/system_heap.h
@@ -0,0 +1,11 @@
+#ifndef SYSTEM_HEAP_H
+#define SYSTEM_HEAP_H
+
+#include "ultra64.h"
+#include "libc/stddef.h"
+
+void* SystemHeap_Malloc(size_t size);
+void SystemHeap_Free(void* ptr);
+void SystemHeap_Init(void* heap, size_t size);
+
+#endif
diff --git a/linker_scripts/jp/symbol_addrs_boot.txt b/linker_scripts/jp/symbol_addrs_boot.txt
index dca47b7..005925d 100644
--- a/linker_scripts/jp/symbol_addrs_boot.txt
+++ b/linker_scripts/jp/symbol_addrs_boot.txt
@@ -159,14 +159,14 @@ DoRelocation = 0x8002B9C0; // type:func
_dbg_hungup = 0x8002BC00; // type:func
Reset = 0x8002BC34; // type:func
-func_8002BC60_jp = 0x8002BC60; // type:func
-func_8002BC90_jp = 0x8002BC90; // type:func
-func_8002BCBC_jp = 0x8002BCBC; // type:func
-func_8002BD2C_jp = 0x8002BD2C; // type:func
-func_8002BD9C_jp = 0x8002BD9C; // type:func
-func_8002BE6C_jp = 0x8002BE6C; // type:func
-func_8002BF08_jp = 0x8002BF08; // type:func
-func_8002BF78_jp = 0x8002BF78; // type:func
+SystemHeap_Malloc = 0x8002BC60; // type:func
+SystemHeap_Free = 0x8002BC90; // type:func
+SystemHeap_RunBlockFunc = 0x8002BCBC; // type:func
+SystemHeap_RunBlockFunc1 = 0x8002BD2C; // type:func
+SystemHeap_RunBlockFunc8 = 0x8002BD9C; // type:func
+SystemHeap_RunBlockFunc1Reverse = 0x8002BE6C; // type:func
+SystemHeap_RunInits = 0x8002BF08; // type:func
+SystemHeap_Init = 0x8002BF78; // type:func
GetCurrentMilliseconds = 0x8002BFA0; // type:func
@@ -286,7 +286,10 @@ gfxprint_rainbow_tlut = 0x8003BD30; // type:u8 size:0x20
gfxprint_rainbow_txtr = 0x8003BD50; // type:u8 size:0x8
gfxprint_font = 0x8003BD58; // type:u8 size:0x800
-D_8003C560_jp = 0x8003C560; //
+sInitFuncs = 0x8003C560; //
+sNew = 0x8003C564; //
+D_8003C568_jp = 0x8003C568; //
+
qNaN0x3FFFFF = 0x8003C580; // type:f32 size:0x4
qNaN0x10000 = 0x8003C584; // type:f32 size:0x4
diff --git a/src/boot/O2/system_heap.c b/src/boot/O2/system_heap.c
new file mode 100644
index 0000000..19a0d6a
--- /dev/null
+++ b/src/boot/O2/system_heap.c
@@ -0,0 +1,128 @@
+/**
+ * @file system_heap.c
+ *
+ * Original file name unknown, as well as all function names.
+ *
+ * @note:
+ * Only SystemHeap_Init() is used, and is essentially just a wrapper for SystemArena_Init().
+ *
+ */
+
+#include "system_heap.h"
+#include "libc/stdint.h"
+#include "libc64/osmalloc.h"
+#include "libc64/malloc.h"
+#include "unk.h"
+
+typedef void (*BlockFunc)(void*);
+typedef void (*BlockFunc1)(void*, u32);
+typedef void (*BlockFunc8)(void*, u32, u32, u32, u32, u32, u32, u32, u32);
+
+typedef struct InitFunc {
+ /* 0x0 */ uintptr_t nextOffset;
+ /* 0x4 */ void (*func)(void);
+} InitFunc; // size = 0x8
+
+void* sInitFuncs = NULL;
+
+char sNew[] = "";
+
+UNK_TYPE1 D_8003C568_jp[] = {
+ 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* SystemHeap_Malloc(size_t size) {
+ if (size == 0) {
+ size = 1;
+ }
+ return __osMalloc(&malloc_arena, size);
+}
+
+void SystemHeap_Free(void* ptr) {
+ if (ptr != NULL) {
+ __osFree(&malloc_arena, ptr);
+ }
+}
+
+void SystemHeap_RunBlockFunc(void* blk, size_t nBlk, size_t blkSize, BlockFunc blockFunc) {
+ uintptr_t pos = (uintptr_t)blk;
+
+ for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) {
+ blockFunc((void*)pos);
+ }
+}
+
+void SystemHeap_RunBlockFunc1(void* blk, size_t nBlk, size_t blkSize, BlockFunc1 blockFunc) {
+ uintptr_t pos = (uintptr_t)blk;
+
+ for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) {
+ blockFunc((void*)pos, 2);
+ }
+}
+
+void* SystemHeap_RunBlockFunc8(void* blk, size_t nBlk, size_t blkSize, BlockFunc8 blockFunc) {
+ if (blk == NULL) {
+ blk = SystemHeap_Malloc(nBlk * blkSize);
+ }
+
+ if ((blk != NULL) && (blockFunc != NULL)) {
+ uintptr_t pos = (uintptr_t)blk;
+
+ for (; pos < (uintptr_t)blk + (nBlk * blkSize); pos += (blkSize & ~0)) {
+ blockFunc((void*)pos, 0, 0, 0, 0, 0, 0, 0, 0);
+ }
+ }
+
+ return blk;
+}
+
+void SystemHeap_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 = (uintptr_t)blk;
+ maskedBlkSize = (blkSize & ~0);
+ pos = (uintptr_t)start + (nBlk * blkSize);
+
+ while (pos > start) {
+ pos -= maskedBlkSize;
+ blockFunc((void*)pos, 2);
+ }
+ }
+
+ if (shouldFree) {
+ SystemHeap_Free(blk);
+ }
+}
+
+void SystemHeap_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 SystemHeap_Init(void* heap, size_t size) {
+ MallocInit(heap, size);
+ SystemHeap_RunInits();
+}
diff --git a/yamls/jp/boot.yaml b/yamls/jp/boot.yaml
index 65f220e..94da612 100644
--- a/yamls/jp/boot.yaml
+++ b/yamls/jp/boot.yaml
@@ -27,10 +27,11 @@
- [0x007000, asm, boot/libu64/debug]
- - [0x007060, asm, boot/007060]
+ - [0x007060, c, boot/O2/system_heap]
- [0x0073A0, c, boot/O2/getcurrentms]
- [0x0073F0, c, boot/O2/padsetup]
+
# libc64
- [0x007530, asm, boot/libc64/math64]
- [0x007A40, hasm, boot/libc64/fp]
@@ -221,7 +222,7 @@
- [0x0170B0, data, boot/libu64/gfxprint_data]
- - [0x017960, data, boot/007060]
+ - [0x017960, .data, boot/O2/system_heap]
# libc64
- [0x017980, data, boot/libc64/fp]