Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
__os.h File Reference

Go to the source code of this file.

Functions

u32 __OSIsDebuggerPresent (void)
 
void __OSPSInit (void)
 
void __OSInitAudioSystem (void)
 
void __OSStopAudioSystem (void)
 
void __OSCacheInit (void)
 
void __OSContextInit (void)
 
void __OSUnhandledException (__OSException exception, OSContext *context, u32 dsisr, u32 dar)
 
void __OSGetExecParams (OSExecParams *params)
 
void __OSSetExecParams (const OSExecParams *params, OSExecParams *addr)
 
void __OSBootDolSimple (u32 doloffset, u32 restartCode, void *regionStart, void *regionEnd, BOOL argsUseDefault, s32 argc, char **argv)
 
void __OSBootDol (u32 doloffset, u32 restartCode, const char **argv)
 
void __RAS_OSDisableInterrupts_begin (void)
 
void __RAS_OSDisableInterrupts_end (void)
 
__OSInterruptHandler __OSSetInterruptHandler (__OSInterrupt interrupt, __OSInterruptHandler handler)
 
__OSInterruptHandler __OSGetInterruptHandler (__OSInterrupt interrupt)
 
void __OSInterruptInit (void)
 
OSInterruptMask __OSMaskInterrupts (OSInterruptMask global)
 
OSInterruptMask __OSUnmaskInterrupts (OSInterruptMask global)
 
void __OSDispatchInterrupt (__OSException exception, OSContext *context)
 
void __OSModuleInit (void)
 
void __OSInitMemoryProtection (void)
 
void __OSUnlockAllMutex (OSThread *thread)
 
int __OSCheckDeadLock (OSThread *thread)
 
int __OSCheckMutexes (OSThread *thread)
 
void __OSDoHotReset (u32 resetCode)
 
void __OSShutdownDevices (BOOL doRecal)
 
int __OSCallResetFunctions (BOOL final)
 
void __OSResetSWInterruptHandler (s16 exception, OSContext *context)
 
void __OSSetResetButtonTimer (u8 min)
 
int __OSGetRTC (u32 *rtc)
 
int __OSSetRTC (u32 rtc)
 
void __OSInitSram (void)
 
OSSram__OSLockSram (void)
 
OSSramEx__OSLockSramEx (void)
 
int __OSUnlockSram (BOOL commit)
 
int __OSUnlockSramEx (BOOL commit)
 
int __OSSyncSram (void)
 
int __OSCheckSram (void)
 
int __OSReadROM (void *buffer, s32 length, s32 offset)
 
int __OSReadROMAsync (void *buffer, s32 length, s32 offset, void(*callback)())
 
u8 __OSGetBootMode (void)
 
void __OSSetBootMode (u8 ntd)
 
void __OSSystemCallVectorStart ()
 
void __OSSystemCallVectorEnd ()
 
void __OSInitSystemCall (void)
 
void __OSThreadInit (void)
 
s32 __OSGetEffectivePriority (OSThread *thread)
 
void __OSPromoteThread (OSThread *thread, s32 priority)
 
void __OSReschedule (void)
 
void __OSSetTime (OSTime time)
 
OSTime __OSGetSystemTime ()
 
void __OSSetTick (__REGISTER OSTick newTicks)
 
OSTime __OSTimeToSystemTime (OSTime time)
 
 __declspec (section ".init") asm void __init_hardware(void)
 
void __init_user (void)
 
void _ExitProcess (void)
 
DECL_WEAK void InitMetroTRK_BBA ()
 
OSTime __get_clock (void)
 
u32 __get_time (void)
 
int __to_gm_time (void)
 

Variables

char * __OSExceptionNames [17]
 
volatile int __OSCurrHeap
 
u64 __OSSpuriousInterrupts
 
char * __OSInterruptNames [33]
 
char * __OSPIErrors [8]
 
unsigned int size
 
const void * src
 

Function Documentation

◆ __declspec()

__declspec ( section ".init" )

Check the BI2 debug flag to determine how to call InitMetroTRK.

This can be done by either checking the value from the DVD (OSBI2.debugFlag), or by checking the global OS_BI2_DEBUG_FLAG.

If the DVD BI2 is available, it is prioritized over the global value.

At this point, we do one last check to decide whether we want to setup the TRK debugger.

If the OS boot info specifies an arena hi, we grab the BI2 debug flag using the global OS_BI2_DEBUG_FLAG.

(This must be some heuristic, but I don't understand it)

The BI2 debug flag/level decides how to set up TRK.

Most importantly, it decides how InitMetroTRKCommTable is called, by specifying a type of hardware.

ID 1: NDEV hardware ID 2: BBA hardware Anything else: "Unknown" to TRK, defaults to GDEV hardware

BI2 debug level maps to TRK comm hardware ID as follows:

  • BI2 Level 2 -> ID 0 (GDEV)
  • BI2 Level 3 -> ID 1 (NDEV)
  • BI2 Level 4 -> ID 2 (BBA)

I think at one point this used to call InitMetroTRK as they set r5 here; however, in this version it goes unused.

What currently happens is __set_debug_bba sets Debug_BBA, which will result in a call to InitMetroTRK_BBA after the OS is initialized.

Maybe this is a leftover from how things worked before InitMetroTRK_BBA was written?

Call InitMetroTRK The MetroTRK hardware ID is specified in r5

After setting up the hardware and the debugger, we next setup the program arguments. This label checks whether any arguments exist.

BI2 contains an offset from itself to the argument data, which is formatted as follows:

typedef struct BI2Args { int argc; union { char* argument; u32 offset; } argv[]; } BI2Args;

This loop unpacks the arguments by converting them from offsets to pointers, in-place.

The offsets are relative to the start of the BI2, so we just add the offset to the BI2 pointer and write it back.

Both the MEM1 arena hi and the MEM1 limit are adjusted to preserve the BI2 args.

They are set to eight bytes into the BI2 arguments, rounded down to the nearest 32 bytes.

Either there was no BI2 available, or it did not contain any arguments

Here, the OS and its debug monitor are initialized, and then we check if we should call __check_pad3.

__check_pad3 is called before future initialization if the disk drive device code is 0x0001, or if the OS' inquiry fails (emulation or some debug hardware?)

The apploader reads the button state of the fourth GCN controller and writes it to GC_PAD_3_BTN (zero-indexed), which is used in __check_pad3. WiiBrew states that this is for GameCube NR disc support, so that could explain the unusual DVD device code address.

If the BI2 debug level from earlier was set to four, we need to initialize the debugger for BBA hardware.

  1. Initialize C++ runtime
  2. Call main(argc, argv)
  3. Teardown C++ runtime

◆ __get_clock()

OSTime __get_clock ( void )

◆ __get_time()

u32 __get_time ( void )

◆ __init_user()

void __init_user ( void )

◆ __OSBootDol()

void __OSBootDol ( u32 doloffset,
u32 restartCode,
const char ** argv )

◆ __OSBootDolSimple()

void __OSBootDolSimple ( u32 doloffset,
u32 restartCode,
void * regionStart,
void * regionEnd,
BOOL argsUseDefault,
s32 argc,
char ** argv )

◆ __OSCacheInit()

void __OSCacheInit ( void )

◆ __OSCallResetFunctions()

int __OSCallResetFunctions ( BOOL final)

◆ __OSCheckDeadLock()

int __OSCheckDeadLock ( OSThread * thread)

◆ __OSCheckMutexes()

int __OSCheckMutexes ( OSThread * thread)

◆ __OSCheckSram()

int __OSCheckSram ( void )

◆ __OSContextInit()

void __OSContextInit ( void )

◆ __OSDispatchInterrupt()

void __OSDispatchInterrupt ( __OSException exception,
OSContext * context )

◆ __OSDoHotReset()

void __OSDoHotReset ( u32 resetCode)

◆ __OSGetBootMode()

u8 __OSGetBootMode ( void )

◆ __OSGetEffectivePriority()

s32 __OSGetEffectivePriority ( OSThread * thread)

◆ __OSGetExecParams()

void __OSGetExecParams ( OSExecParams * params)

◆ __OSGetInterruptHandler()

__OSInterruptHandler __OSGetInterruptHandler ( __OSInterrupt interrupt)

◆ __OSGetRTC()

int __OSGetRTC ( u32 * rtc)

◆ __OSGetSystemTime()

OSTime __OSGetSystemTime ( )

◆ __OSInitAudioSystem()

void __OSInitAudioSystem ( void )

◆ __OSInitMemoryProtection()

void __OSInitMemoryProtection ( void )

◆ __OSInitSram()

void __OSInitSram ( void )

◆ __OSInitSystemCall()

void __OSInitSystemCall ( void )

◆ __OSInterruptInit()

void __OSInterruptInit ( void )

◆ __OSIsDebuggerPresent()

u32 __OSIsDebuggerPresent ( void )

◆ __OSLockSram()

OSSram * __OSLockSram ( void )

◆ __OSLockSramEx()

OSSramEx * __OSLockSramEx ( void )

◆ __OSMaskInterrupts()

OSInterruptMask __OSMaskInterrupts ( OSInterruptMask global)

◆ __OSModuleInit()

void __OSModuleInit ( void )

◆ __OSPromoteThread()

void __OSPromoteThread ( OSThread * thread,
s32 priority )

◆ __OSPSInit()

void __OSPSInit ( void )

◆ __OSReadROM()

int __OSReadROM ( void * buffer,
s32 length,
s32 offset )

◆ __OSReadROMAsync()

int __OSReadROMAsync ( void * buffer,
s32 length,
s32 offset,
void(* callback )() )

◆ __OSReschedule()

void __OSReschedule ( void )

◆ __OSResetSWInterruptHandler()

void __OSResetSWInterruptHandler ( s16 exception,
OSContext * context )

◆ __OSSetBootMode()

void __OSSetBootMode ( u8 ntd)

◆ __OSSetExecParams()

void __OSSetExecParams ( const OSExecParams * params,
OSExecParams * addr )

◆ __OSSetInterruptHandler()

__OSInterruptHandler __OSSetInterruptHandler ( __OSInterrupt interrupt,
__OSInterruptHandler handler )

◆ __OSSetResetButtonTimer()

void __OSSetResetButtonTimer ( u8 min)

◆ __OSSetRTC()

int __OSSetRTC ( u32 rtc)

◆ __OSSetTick()

void __OSSetTick ( __REGISTER OSTick newTicks)

◆ __OSSetTime()

void __OSSetTime ( OSTime time)

◆ __OSShutdownDevices()

void __OSShutdownDevices ( BOOL doRecal)

◆ __OSStopAudioSystem()

void __OSStopAudioSystem ( void )

◆ __OSSyncSram()

int __OSSyncSram ( void )

◆ __OSSystemCallVectorEnd()

void __OSSystemCallVectorEnd ( )
extern

◆ __OSSystemCallVectorStart()

void __OSSystemCallVectorStart ( )
extern

◆ __OSThreadInit()

void __OSThreadInit ( void )

◆ __OSTimeToSystemTime()

OSTime __OSTimeToSystemTime ( OSTime time)

◆ __OSUnhandledException()

void __OSUnhandledException ( __OSException exception,
OSContext * context,
u32 dsisr,
u32 dar )

◆ __OSUnlockAllMutex()

void __OSUnlockAllMutex ( OSThread * thread)

◆ __OSUnlockSram()

int __OSUnlockSram ( BOOL commit)

◆ __OSUnlockSramEx()

int __OSUnlockSramEx ( BOOL commit)

◆ __OSUnmaskInterrupts()

OSInterruptMask __OSUnmaskInterrupts ( OSInterruptMask global)

◆ __RAS_OSDisableInterrupts_begin()

void __RAS_OSDisableInterrupts_begin ( void )
extern

◆ __RAS_OSDisableInterrupts_end()

void __RAS_OSDisableInterrupts_end ( void )
extern

◆ __to_gm_time()

int __to_gm_time ( void )

◆ _ExitProcess()

void _ExitProcess ( void )

◆ InitMetroTRK_BBA()

DECL_WEAK void InitMetroTRK_BBA ( )

Variable Documentation

◆ __OSCurrHeap

volatile int __OSCurrHeap
extern

◆ __OSExceptionNames

char* __OSExceptionNames[17]
extern

◆ __OSInterruptNames

char* __OSInterruptNames[33]
extern

◆ __OSPIErrors

char* __OSPIErrors[8]
extern

◆ __OSSpuriousInterrupts

u64 __OSSpuriousInterrupts
extern

◆ size

u32 size

◆ src

const void* src