1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#include "libu64/runtime.h"
#include "libc64/malloc.h"
#include "libc64/os_malloc.h"
typedef void (*arg3_800FC868)(void*);
typedef void (*arg3_800FC8D8)(void*, u32);
typedef void (*arg3_800FC948)(void*, u32, u32, u32, u32, u32, u32, u32, u32);
typedef void (*arg3_800FCA18)(void*, u32);
typedef struct CtorEntry {
s32 nextOffset;
void (*func)(void);
} CtorEntry;
void* sGlobalCtorEntries = NULL;
#if DEBUG_FEATURES
char sNew[] = "new";
#else
char sNew[] = "";
#endif
void* Runtime_New(u32 size) {
DECLARE_INTERRUPT_MASK
void* ptr;
DISABLE_INTERRUPTS();
if (size == 0) {
size = 1;
}
#if DEBUG_FEATURES
ptr = __osMallocDebug(&gSystemArena, size, sNew, 0);
#else
ptr = __osMalloc(&gSystemArena, size);
#endif
RESTORE_INTERRUPTS();
return ptr;
}
void Runtime_Delete(void* ptr) {
DECLARE_INTERRUPT_MASK
DISABLE_INTERRUPTS();
if (ptr != NULL) {
__osFree(&gSystemArena, ptr);
}
RESTORE_INTERRUPTS();
}
void func_800FC868(void* blk, u32 nBlk, u32 blkSize, arg3_800FC868 arg3) {
DECLARE_INTERRUPT_MASK
u32 pos;
DISABLE_INTERRUPTS();
for (pos = ((u32)blk & ~0); pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
arg3((void*)pos);
}
RESTORE_INTERRUPTS();
}
void func_800FC8D8(void* blk, u32 nBlk, s32 blkSize, arg3_800FC8D8 arg3) {
DECLARE_INTERRUPT_MASK
u32 pos;
DISABLE_INTERRUPTS();
for (pos = ((u32)blk & ~0); pos < (u32)blk + (nBlk * blkSize); pos = (u32)pos + (blkSize & ~0)) {
arg3((void*)pos, 2);
}
RESTORE_INTERRUPTS();
}
void* func_800FC948(void* blk, u32 nBlk, u32 blkSize, arg3_800FC948 arg3) {
DECLARE_INTERRUPT_MASK
u32 pos;
DISABLE_INTERRUPTS();
if (blk == NULL) {
blk = Runtime_New(nBlk * blkSize);
}
if (blk != NULL && arg3 != NULL) {
pos = (u32)blk;
while (pos < (u32)blk + (nBlk * blkSize)) {
arg3((void*)pos, 0, 0, 0, 0, 0, 0, 0, 0);
pos = (u32)pos + (blkSize & ~0);
}
}
RESTORE_INTERRUPTS();
return blk;
}
void func_800FCA18(void* blk, u32 nBlk, u32 blkSize, arg3_800FCA18 arg3, s32 arg4) {
DECLARE_INTERRUPT_MASK
u32 pos;
u32 end;
DISABLE_INTERRUPTS();
if (blk != NULL) {
if (arg3 != NULL) {
end = (u32)blk;
pos = (u32)end + (nBlk * blkSize);
while (pos > end) {
pos -= (s32)(blkSize & ~0);
arg3((void*)pos, 2);
}
}
if (arg4 != 0) {
Runtime_Delete(blk);
}
}
RESTORE_INTERRUPTS();
}
void Runtime_ExecuteGlobalCtors(void) {
CtorEntry* ctorEntry = (CtorEntry*)&sGlobalCtorEntries;
u32 nextOffset = ctorEntry->nextOffset;
CtorEntry* prevEntry = NULL;
while (nextOffset != 0) {
ctorEntry = (CtorEntry*)((s32)ctorEntry + nextOffset);
if (ctorEntry->func != NULL) {
ctorEntry->func();
}
nextOffset = ctorEntry->nextOffset;
ctorEntry->nextOffset = (s32)prevEntry;
prevEntry = ctorEntry;
}
sGlobalCtorEntries = prevEntry;
}
void Runtime_Init(void* start, u32 size) {
#if PLATFORM_N64
__osMallocInit(&gSystemArena, start, size);
#else
SystemArena_Init(start, size);
#endif
Runtime_ExecuteGlobalCtors();
}
|