Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
os.h
Go to the documentation of this file.
1#ifndef OS_H_
2#define OS_H_
3
4#include "__va_arg.h"
5#include "macros.h"
6#include "dolphin/dvd.h"
7
10#include "dolphin/os/OSArena.h"
12#include "dolphin/os/OSCache.h"
14#include "dolphin/os/OSError.h"
15#include "dolphin/os/OSExec.h"
16#include "dolphin/os/OSFont.h"
18#include "dolphin/os/OSLink.h"
19#include "dolphin/os/OSMemory.h"
21#include "dolphin/os/OSMutex.h"
22#include "dolphin/os/OSReboot.h"
23#include "dolphin/os/OSReset.h"
25#include "dolphin/os/OSRtc.h"
26#include "dolphin/os/OSSync.h"
27#include "dolphin/os/OSThread.h"
28#include "dolphin/os/OSTime.h"
29
30void OSReportInit(void);
32void OSVAttention(const char* fmt, va_list args);
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38// Upper words of the masks, since UIMM is only 16 bits
39#define OS_CACHED_REGION_PREFIX 0x8000
40#define OS_UNCACHED_REGION_PREFIX 0xC000
41#define OS_PHYSICAL_MASK 0x3FFF
42
43#define OS_BASE_CACHED (OS_CACHED_REGION_PREFIX << 16)
44#define OS_BASE_UNCACHED (OS_UNCACHED_REGION_PREFIX << 16)
45
46#define OS_CONSOLE_MASK 0xf0000000
47#define OS_CONSOLE_RETAIL 0x00000000
48#define OS_CONSOLE_DEVELOPMENT 0x10000000
49#define OS_CONSOLE_TDEV 0x20000000
50
51#define OS_CONSOLE_RETAIL4 0x00000004
52#define OS_CONSOLE_RETAIL3 0x00000003
53#define OS_CONSOLE_RETAIL2 0x00000002
54#define OS_CONSOLE_RETAIL1 0x00000001
55#define OS_CONSOLE_TDEVHW4 0x20000007
56#define OS_CONSOLE_TDEVHW3 0x20000006
57#define OS_CONSOLE_TDEVHW2 0x20000005
58#define OS_CONSOLE_TDEVHW1 0x20000004
59#define OS_CONSOLE_DEVHW4 0x10000007
60#define OS_CONSOLE_DEVHW3 0x10000006
61#define OS_CONSOLE_DEVHW2 0x10000005
62#define OS_CONSOLE_DEVHW1 0x10000004
63#define OS_CONSOLE_MINNOW 0x10000003
64#define OS_CONSOLE_ARTHUR 0x10000002
65#define OS_CONSOLE_PC_EMULATOR 0x10000001
66#define OS_CONSOLE_EMULATOR 0x10000000
67
68volatile u16 __OSDeviceCode AT_ADDRESS(0x800030E6);
69
70volatile u32 OS_PI_INTR_CAUSE AT_ADDRESS(0xCC003000);
71volatile u32 OS_PI_INTR_MASK AT_ADDRESS(0xCC003004);
72
73volatile u16 OS_MI_INTR_MASK AT_ADDRESS(0xCC00401C);
74
75volatile u16 OS_DSP_DMA_ADDR_HI AT_ADDRESS(0xCC005030);
76volatile u16 OS_DSP_DMA_ADDR_LO AT_ADDRESS(0xCC005032);
77volatile u16 OS_DSP_INTR_MASK AT_ADDRESS(0xCC00500A);
78
79volatile u16 OS_ARAM_DMA_ADDR_HI AT_ADDRESS(0xCC005020);
80volatile u16 OS_ARAM_DMA_ADDR_LO AT_ADDRESS(0xCC005022);
81
83
85
86void OSAttention(const char* msg, ...);
87void OSPanic(const char* file, s32 line, const char* fmt, ...);
88void OSReport(char* fmt, ...);
89void OSReport_Error(const char* fmt, ...);
90void OSReport_FatalError(const char* fmt, ...);
91void OSReport_System(const char* fmt, ...);
92void OSReport_Warning(const char* fmt, ...);
93void OSReportDisable(void);
94void OSReportEnable(void);
95void OSReportForceEnableOff(void);
96void OSReportForceEnableOn(void);
97void OSVReport(const char* format, va_list list);
98
99#ifdef DEBUG
100#define OS_REPORT(...) OSReport(__VA_ARGS__)
101#define OS_PANIC(msg) OSPanic(__FILE__, __LINE__, msg)
102#define ASSERTMSG(exp, msg) (void)((exp) || (OSPanic(__FILE__, __LINE__, (msg)), 0))
103#else
104#define OS_REPORT(...)
105#define OS_WARNING(...)
106#define OS_REPORT_ERROR(...)
107#define OS_PANIC(...)
108#define ASSERTMSG(exp, msg) ((void)0)
109#endif
110
115extern u8 __OSReport_enable;
116
117extern BOOL __OSIsGcam;
118
119void OSReportInit__Fv(void); // needed for inline asm
120
121u8* OSGetStackPointer(void);
122void __OSFPRInit(void);
124void OSInit(void);
125static void OSExceptionInit(void);
126void __OSDBIntegrator(void);
127void __OSDBJump(void);
128
132static void OSExceptionVector(void);
137void __OSPSInit(void);
138u32 __OSGetDIConfig(void);
139void OSRegisterVersion(const char* version);
140
141inline s16 __OSf32tos16(register f32 inF) {
142 register s16 out;
143 u32 tmp;
144 register u32* tmpPtr = &tmp;
145 // clang-format off
146 asm {
147 psq_st inF, 0(tmpPtr), 0x1, 5
148 lha out, 0(tmpPtr)
149 }
150 // clang-format on
151
152 return out;
153}
154
155inline void OSf32tos16(f32* f, s16* out) {
156 *out = __OSf32tos16(*f);
157}
158
159inline u8 __OSf32tou8(register f32 inF) {
160 register u8 out;
161 u32 tmp;
162 register u32* tmpPtr = &tmp;
163 // clang-format off
164 asm {
165 psq_st inF, 0(tmpPtr), 0x1, 2
166 lbz out, 0(tmpPtr)
167 }
168 // clang-format on
169
170 return out;
171}
172
173inline void OSf32tou8(f32* f, u8* out) {
174 *out = __OSf32tou8(*f);
175}
176
177static inline void OSInitFastCast(void) {
178 // clang-format off
179 asm {
180 li r3, 4
181 oris r3, r3, 4
182 mtspr 0x392, r3
183 li r3, 5
184 oris r3, r3, 5
185 mtspr 0x393, r3
186 li r3, 6
187 oris r3, r3, 6
188 mtspr 0x394, r3
189 li r3, 7
190 oris r3, r3, 7
191 mtspr 0x395, r3
192 }
193 // clang-format on
194}
195
196typedef struct OSBootInfo {
198 /* 0x20 */ u32 boot_code;
199 /* 0x24 */ u32 version;
200 /* 0x28 */ u32 memory_size;
201 /* 0x2C */ u32 console_type;
202 /* 0x30 */ void* arena_lo;
203 /* 0x34 */ void* arena_hi;
204 /* 0x38 */ void* fst_location;
205 /* 0x3C */ u32 fst_max_length;
207
208typedef struct BI2Debug {
209 /* 0x00 */ s32 debugMonSize;
210 /* 0x04 */ s32 simMemSize;
211 /* 0x08 */ u32 argOffset;
212 /* 0x0C */ u32 debugFlag;
213 /* 0x10 */ int trackLocation;
214 /* 0x14 */ int trackSize;
215 /* 0x18 */ u32 countryCode;
216 /* 0x1C */ u8 unk[8];
217 /* 0x24 */ u32 padSpec;
219
222 u32 nintendo_boot_code; /* Nintendo Standard Boot Code. */
223 u32 field_0x24; /* Version (set by apploader) */
224 u32 memory_size; /* Memory Size (Physical) 24MB */
225 u32 field_0x2c; /* Production Board Model */
226 u32 arena_low; /* Arena Low */
227 u32 arena_high; /* Arena High */
228 u32 field_0x38; /* Start of FST (varies in all games) */
229 u32 field_0x3c; /* Maximum FST Size (varies in all games) */
231 u8 field_0x60[36]; /* Hook is PPC assembler used by Debugger. */
233 OSContext* field_0xd8; /* Current OSContext instance. */
234 OSThread* field_0xdc; /* OSThread pointer, previously created thread. */
235 OSThread* field_0xe0; /* OSThread pointer, most recently created thread. */
236 OSThread* field_0xe4; /* Current thread pointer. */
237 u32 field_0xe8; /* Dev Debugger Monitor Address (If present) */
238 u32 field_0xec; /* Simulated Memory Size */
239 u32 field_0xf0; /* Pointer to data read from partition's bi2.bin, set by apploader */
240 u32 field_0xf4; /* Console Bus Speed */
241 u32 field_0xf8; /* Console CPU Speed */
243 u8 field_0x1800[6144]; /* Unused Exception Vector */
245 u32 field_0x3040[34]; /* __OSInterrupt table. */
246 u32 field_0x30c8; /* Pointer to the first loaded REL file. */
247 u32 field_0x30cc; /* Pointer to the last loaded REL file. */
248 u32 field_0x30d0; /* Pointer to a REL module name table, or 0. */
250 u64 field_0x30d8; /* System time */
252 u32 field_0x30e4; /* __OSPADButton */
254 OSExecParams* field_0x30f0; /* DOL Execute Parameters */
256 u32 field_0x3100; /* Physical MEM1 size */
257 u32 field_0x3104; /* Simulated MEM1 size */
259 u32 field_0x3110; /* Heap pointer (end of usable memory by the game) */
261 u32 field_0x3118; /* Physical MEM2 size */
262 u32 field_0x311c; /* Simulated MEM2 size */
264 u32 field_0x3130; /* IOS Heap Range (start) */
265 u32 field_0x3134; /* IOS Heap Range (end) */
266 u32 field_0x3138; /* Hollywood Version */
268 u32 field_0x3140; /* IOS version */
269 u32 field_0x3144; /* IOS Build Date */
271 u32 field_0x3158; /* GDDR Vendor Code */
272 u32 field_0x315c; /* During the boot process, */
273 u32 field_0x3160; /* Init semaphore (1-2 main() waits for this to clear) */
274 u32 field_0x3164; /* GC (MIOS) mode flag? */
276 u32 field_0x3180; /* Game ID */
277 u8 field_0x3184; /* Application type. 0x80 for disc games, 0x81 for channels. */
279 u8 field_0x3186; /* Application type 2 */
281 u32 field_0x3188; /* Minimum IOS version */
282 u32 field_0x318c; /* Title Booted from NAND (Launch Code) */
283 u32 field_0x3190; /* Title Booted from NAND (Return Code) */
284 u32 field_0x3194; /* While reading a disc, the system menu reads the first partition table (0x20
285 bytes from 0x00040020) and stores a pointer to the data partition entry.
286 When launching the disc game, it copies the partition type to 0x3194. The
287 partition type for data partitions is 0, so typically this location always
288 has 0. */
289 u32 field_0x3198; /* While reading a disc, the system menu reads the first partition table (0x20
290 bytes from 0x00040020) and stores a pointer to the data partition entry.
291 When launching the disc game, it copies the partition offset to 0x3198. */
292 u32 field_0x319c; /* Set by the apploader to 0x80 for single-layer discs and 0x81 for dual-layer
293 discs (determined by whether 0x7ed40000 is the value at offset 0x30 in the
294 partition's bi2.bin; it seems that that value is 0 for single-layer discs).
295 Early titles' apploaders do not set it at all, leaving the value as 0. This
296 controls the /dev/di#0x8D_DVDLowUnencryptedRead out-of-bounds Error #001
297 read for titles that do make such a read: they try to read at 0x7ed40000
298 for dual-layer discs and 0x460a0000 for single-layer discs. */
300};
301
302#define OS_ASSERT(...)
303
304#define OSPhysicalToCached(paddr) ((void*)((u32)(paddr) + OS_BASE_CACHED))
305#define OSPhysicalToUncached(paddr) ((void*)((u32)(paddr) + OS_BASE_UNCACHED))
306#define OSCachedToPhysical(caddr) ((u32)((u8*)(caddr)-OS_BASE_CACHED))
307#define OSUncachedToPhysical(ucaddr) ((u32)((u8*)(ucaddr)-OS_BASE_UNCACHED))
308#define OSCachedToUncached(caddr) ((void*)((u8*)(caddr) + (OS_BASE_UNCACHED - OS_BASE_CACHED)))
309#define OSUncachedToCached(ucaddr) ((void*)((u8*)(ucaddr) - (OS_BASE_UNCACHED - OS_BASE_CACHED)))
310
311extern OSTime __OSStartTime;
312extern BOOL __OSInIPL;
313
314#ifdef __cplusplus
315};
316#endif
317
318#endif
static OSContext context
Definition JUTException.cpp:233
u8 __OSException
Definition OSError.h:53
s64 OSTime
Definition OSTime.h:10
T cLib_calcTimer(T *value)
Definition c_lib.h:74
static char * tmp[5]
Definition d_a_npc_ashB.cpp:231
void OSReportForceEnableOff(void)
Definition m_Do_printf.cpp:63
BOOL OSIsThreadSuspended(OSThread *thread)
void OSf32tos16(f32 *f, s16 *out)
Definition os.h:155
void __OSDBJump(void)
Definition OS.c:510
void OSReport_System(const char *fmt,...)
Definition m_Do_printf.cpp:211
void OSReportDisable(void)
Definition m_Do_printf.cpp:48
void OSReportInit(void)
Definition m_Do_printf.cpp:89
void OSVReport(const char *format, va_list list)
Definition m_Do_printf.cpp:150
void OSReportInit__Fv(void)
void OSReport_FatalError(const char *fmt,...)
Definition m_Do_printf.cpp:163
void OSReportForceEnableOn(void)
Definition m_Do_printf.cpp:58
void __OSPSInit(void)
Definition OS.c:651
void OSPanic(const char *file, s32 line, const char *fmt,...)
Definition m_Do_printf.cpp:224
u8 __OSReport_System_disable
Definition m_Do_printf.cpp:18
void OSRegisterVersion(const char *version)
Definition OS.c:691
void(* OSExceptionHandler)(__OSException, OSContext *)
Definition os.h:129
volatile u16 __OSDeviceCode AT_ADDRESS(0x800030E6)
static void OSExceptionInit(void)
OSTime __OSStartTime
Definition OS.c:43
void __DBVECTOR()
void __OSDBIntegrator(void)
Definition OS.c:491
void __OSEVSetNumber()
void OSReport_Error(const char *fmt,...)
Definition m_Do_printf.cpp:179
u8 __OSf32tou8(register f32 inF)
Definition os.h:159
void OSReport(char *fmt,...)
static void OSExceptionVector(void)
OSExceptionHandler __OSGetExceptionHandler(__OSException exception)
Definition OS.c:528
void OSReportEnable(void)
Definition m_Do_printf.cpp:53
u8 __OSReport_Warning_disable
Definition m_Do_printf.cpp:16
OSExceptionHandler __OSSetExceptionHandler(__OSException exception, OSExceptionHandler handler)
Definition OS.c:521
u8 __OSReport_disable
Definition m_Do_printf.cpp:12
void __OSFPRInit(void)
Definition OS.c:68
static void OSDefaultExceptionHandler(__OSException exception, OSContext *context)
void OSVAttention(const char *fmt, va_list args)
Definition m_Do_printf.cpp:35
u32 OSGetConsoleType(void)
Definition OS.c:155
s16 __OSf32tos16(register f32 inF)
Definition os.h:141
void OSSwitchFiberEx(u32, u32, u32, u32, u32, u32)
Definition m_Do_printf.cpp:24
void OSAttention(const char *msg,...)
Definition m_Do_printf.cpp:40
BOOL __OSInIPL
Definition OS.c:46
BOOL __OSIsGcam
Definition OS.c:65
void __OSEVEnd()
static void InquiryCallback(s32 param_0, DVDCommandBlock *param_1)
void OSReport_Warning(const char *fmt,...)
Definition m_Do_printf.cpp:195
u8 __OSReport_enable
Definition m_Do_printf.cpp:21
u8 * OSGetStackPointer(void)
Definition OSContext.c:344
u32 __OSGetDIConfig(void)
Definition OS.c:686
void OSf32tou8(f32 *f, u8 *out)
Definition os.h:173
static void OSInitFastCast(void)
Definition os.h:177
u8 __OSReport_Error_disable
Definition m_Do_printf.cpp:14
void OSInit(void)
Definition OS.c:231
Definition os.h:208
s32 simMemSize
Definition os.h:210
u32 debugFlag
Definition os.h:212
u32 countryCode
Definition os.h:215
int trackSize
Definition os.h:214
u8 unk[8]
Definition os.h:216
u32 padSpec
Definition os.h:217
u32 argOffset
Definition os.h:211
int trackLocation
Definition os.h:213
s32 debugMonSize
Definition os.h:209
Definition dvd.h:60
Definition dvd.h:45
Definition os.h:220
u32 field_0x3c
Definition os.h:229
u32 field_0x3040[34]
Definition os.h:245
u32 arena_low
Definition os.h:226
u8 padding_0x3185
Definition os.h:278
u32 field_0x318c
Definition os.h:282
u32 field_0x3110
Definition os.h:259
u8 padding_0x30e0[4]
Definition os.h:251
OSThread * field_0xe0
Definition os.h:235
u8 field_0x60[36]
Definition os.h:231
OSThread * field_0xdc
Definition os.h:234
u32 field_0x3180
Definition os.h:276
u32 field_0x3100
Definition os.h:256
u32 field_0x3198
Definition os.h:289
u32 field_0x30cc
Definition os.h:247
u32 field_0x3134
Definition os.h:265
u8 padding_0x3114[4]
Definition os.h:260
u32 field_0x2c
Definition os.h:225
u32 field_0x30e4
Definition os.h:252
u8 padding_0x3000[64]
Definition os.h:244
u8 padding_0x3148[16]
Definition os.h:270
OSExecParams * field_0x30f0
Definition os.h:254
u32 field_0x3190
Definition os.h:283
u32 field_0x30d0
Definition os.h:248
u8 padding_0x84[84]
Definition os.h:232
u8 padding_0x30ec[8]
Definition os.h:253
u8 padding_0xfc[5892]
Definition os.h:242
u8 field_0x3186
Definition os.h:279
u8 padding_0x40[32]
Definition os.h:230
u32 field_0xe8
Definition os.h:237
u8 field_0x1800[6144]
Definition os.h:243
u8 field_0x31a0[3424]
Definition os.h:299
u32 field_0xf4
Definition os.h:240
u8 padding_0x3108[8]
Definition os.h:258
u32 field_0x315c
Definition os.h:272
u32 field_0x38
Definition os.h:228
OSThread * field_0xe4
Definition os.h:236
u8 padding_0x30d8[4]
Definition os.h:249
u32 field_0x24
Definition os.h:223
u32 field_0x3138
Definition os.h:266
u32 field_0x3140
Definition os.h:268
u32 field_0x3118
Definition os.h:261
u32 field_0xec
Definition os.h:238
u8 padding_0x3120[16]
Definition os.h:263
u32 nintendo_boot_code
Definition os.h:222
u32 field_0xf0
Definition os.h:239
u32 field_0xf8
Definition os.h:241
u64 field_0x30d8
Definition os.h:250
u8 padding_0x3168[24]
Definition os.h:275
u32 field_0x3130
Definition os.h:264
u32 field_0x3194
Definition os.h:284
u32 field_0x3160
Definition os.h:273
u8 padding_0x3187
Definition os.h:280
u32 field_0x30c8
Definition os.h:246
DVDDiskID disk
Definition os.h:221
u32 field_0x3188
Definition os.h:281
OSContext * field_0xd8
Definition os.h:233
u8 field_0x3184
Definition os.h:277
u32 arena_high
Definition os.h:227
u8 padding_0x313c[4]
Definition os.h:267
u32 field_0x3158
Definition os.h:271
u8 padding_0x30f4[12]
Definition os.h:255
u32 field_0x3164
Definition os.h:274
u32 field_0x311c
Definition os.h:262
u32 field_0x3104
Definition os.h:257
u32 memory_size
Definition os.h:224
u32 field_0x319c
Definition os.h:292
u32 field_0x3144
Definition os.h:269
Definition os.h:196
u32 version
Definition os.h:199
void * arena_lo
Definition os.h:202
u32 fst_max_length
Definition os.h:205
u32 boot_code
Definition os.h:198
u32 memory_size
Definition os.h:200
u32 console_type
Definition os.h:201
void * arena_hi
Definition os.h:203
void * fst_location
Definition os.h:204
DVDDiskID disk_info
Definition os.h:197
Definition OSContext.h:137
Definition OSExec.h:10
Definition OSThread.h:56
Definition fdlibm.h:73
int BOOL
Definition types.h:27
unsigned long u32
Definition types.h:10
float f32
Definition types.h:22
signed short s16
Definition types.h:5
unsigned short u16
Definition types.h:9
unsigned long long u64
Definition types.h:11
signed long s32
Definition types.h:6
unsigned char u8
Definition types.h:8