/*---------------------------------------------------------------------------* Project: Cafe OS File: os.h Copyright (C) Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. *---------------------------------------------------------------------------*/ #ifndef __OS_H__ #define __OS_H__ #ifndef _ASSEMBLER #include #include #include #include #ifdef __ghs__ #include #endif #ifdef __cplusplus extern "C" { #endif /*---------------------------------------------------------------------------* Round APIs *---------------------------------------------------------------------------*/ // Most subsystems require 32 byte alignment #define OSRoundUp32B(x) (((u32)(x) + 32 - 1) & ~(32 - 1)) #define OSRoundDown32B(x) (((u32)(x)) & ~(32 - 1)) /*---------------------------------------------------------------------------* Basic OS API *---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------* Name: OSGetConsoleType Description: Checks the console type. Arguments: None. Returns: Returns one of the OS_CONSOLE_* values *---------------------------------------------------------------------------*/ u32 OSGetConsoleType( void ); /*---------------------------------------------------------------------------* Name: OSGetSecurityLevel Description: Get the security level. Arguments: None. Returns: OS_SECURITY_LEVEL_PROD or OS_SECURITY_LEVEL_DEV *---------------------------------------------------------------------------*/ #define OS_SECURITY_LEVEL_PROD 0 #define OS_SECURITY_LEVEL_DEV 1 u32 OSGetSecurityLevel( void ); /*---------------------------------------------------------------------------* Name: OSIsDebuggerPresent Description: Indicate if debugger is initialized and connected (open and running). Arguments: None. Returns: TRUE if debugger is connected FALSE if debugger is not connected *---------------------------------------------------------------------------*/ BOOL OSIsDebuggerPresent( void ); /*---------------------------------------------------------------------------* Name: OSIsDebuggerInitialized Description: Indicate if debugger is initialized but not necessarily connected (open and running). When the debugger is initialized you can call OS debug functions like OSDebug() or OSDebugStr(). Calling a OS debug function when OSIsDebuggerInitialized() is true, and OSIsDebuggerPresent() is false, will cause the process to stop and wait for the debugger to connect. Calling any OS debug function when OSIsDebuggerInitialized is false will cause a fatal unhandled exception. Arguments: None. Returns: TRUE if debugger is initialized FALSE if debugger is not initialized *---------------------------------------------------------------------------*/ BOOL OSIsDebuggerInitialized( void ); /* foreground switching */ void OSSavesDone_ReadyToRelease(void); void OSReleaseForeground( void ); BOOL OSGetForegroundBucket( void ** appRetArea, u32 * apRetSizeBytes); BOOL OSGetForegroundBucketFreeArea( void ** appRetArea, u32 * apRetSizeBytes); BOOL OSRequestFastExit(u32 aFlags, BOOL bRunExit); BOOL OSSendAppSwitchRequest(UPID aProcId, void *apArgs, u32 aArgsBytes); BOOL OSGetCallArgs(UPID *apRetCaller, u8 *apBuffer, u32 aBufferBytes); BOOL OSSetScreenCapturePermission(BOOL enabled); BOOL OSGetScreenCapturePermission(void); BOOL OSSetScreenCapturePermissionEx(BOOL tvEnabled, BOOL drcEnabled); BOOL OSGetScreenCapturePermissionEx(BOOL* tvEnabled, BOOL* drcEnabled); BOOL OSEnableHomeButtonMenu(BOOL enable); BOOL OSIsColdBoot(void); BOOL OSIsSelfRefreshBoot(void); BOOL OSIsNormalBoot(void); BOOL OSIsECOBoot(void); BOOL OSIsStandbyBoot(void); BOOL OSIsOffBoot(); BOOL OSIsCompatBoot(void); u32 OSGetBootPMFlags(void); u32 OSGetLastPMState(void); u32 OSGetCurrentPMState(void); BOOL OSIsProdMode(void); BOOL OSIsECOMode(void); BOOL OSIsHomeButtonMenuEnabled(void); void OSEnableForegroundExit(void); #define APP_IN_FOREGROUND (OSGetForegroundBucket(NULL, NULL)) /* system policy notifications */ typedef enum _osPolicyRequest { OSPOLICY_Exit=1, OSPOLICY_NotifyNetIoStart=2, OSPOLICY_NotifyNetIoEnd=3, OSPOLICY_NotifyHomeButtonDenied=4, } OSPolicyRequest; BOOL OSSendPolicyRequest(OSPolicyRequest aPolicy, UPID aTargetProcId); void OSRegisterVersion( const char* id ); void OSGetArgcArgv(int *apRetArgc, char const ***apRetArgv); /*---------------------------------------------------------------------------* Real-time Clock API *---------------------------------------------------------------------------*/ #include /*----------------------------------------------------------------------* Debug API *----------------------------------------------------------------------*/ #define OSHalt(msg) OSPanic(__FILE__, __LINE__, msg) #ifdef _DEBUG #ifndef ASSERT #define ASSERT(exp) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, "Failed assertion " #exp), 0)) #endif #ifndef ASSERTMSG #if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__ghs__) #define ASSERTMSG(exp, ...) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, __VA_ARGS__), 0)) #else #define ASSERTMSG(exp, msg) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, (msg)), 0)) #endif #endif #ifndef ASSERTMSG1 #define ASSERTMSG1(exp, msg, param1) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, (msg), \ (param1)), 0)) #endif #ifndef ASSERTMSG2 #define ASSERTMSG2(exp, msg, param1, param2) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, (msg), \ (param1), (param2)), 0)) #endif #ifndef ASSERTMSG3 #define ASSERTMSG3(exp, msg, param1, param2, param3) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, (msg), \ (param1), (param2), (param3)), 0)) #endif #ifndef ASSERTMSG4 #define ASSERTMSG4(exp, msg, param1, param2, param3, param4) \ (void) ((exp) || \ (OSPanic(__FILE__, __LINE__, (msg), \ (param1), (param2), (param3), (param4)), 0)) #endif #else // _DEBUG #ifndef ASSERT #define ASSERT(exp) ((void) 0) #endif #ifndef ASSERTMSG #if defined(__STDC_VERSION__) && (199901L <= __STDC_VERSION__) || defined(__ghs__) #define ASSERTMSG(exp, ...) ((void) 0) #else #define ASSERTMSG(exp, msg) ((void) 0) #endif #endif #ifndef ASSERTMSG1 #define ASSERTMSG1(exp, msg, param1) ((void) 0) #endif #ifndef ASSERTMSG2 #define ASSERTMSG2(exp, msg, param1, param2) ((void) 0) #endif #ifndef ASSERTMSG3 #define ASSERTMSG3(exp, msg, param1, param2, param3) ((void) 0) #endif #ifndef ASSERTMSG4 #define ASSERTMSG4(exp, msg, param1, param2, param3, param4) ((void) 0) #endif #endif // _DEBUG #ifndef OS_STATIC_ASSERT #define OS_STATIC_ASSERT(e, message) \ typedef int os_static_assert__failed__##message[!(e) ? -1 : 1] #endif void OSPanic ( const char* file, int line, const char* msg, ... ); void OSReport ( const char* msg, ... ); void OSVReport( const char* msg, va_list list ); void OSConsoleWrite( const char *buf, unsigned long len ); void OSFatal ( const char* msg ); void OSReportSetNewline(const char *newline); void OSSupressConsoleOutput(BOOL umSuppress, BOOL appSuppress, BOOL kmSuppress); void OSDisableUserHeartbeat(void); /* * caferun -v : set verbose level (0=off 7 == MAX) determines whether these * versions of OSReport emit anything or are skipped. */ void OSReportWarn( const char* msg, ...); void OSReportInfo( const char* msg, ...); void OSReportVerbose( const char* msg, ...); #if INCLUDE_COSREPORT #include "private/COSReport.h" extern void OSConsoleWriteForModule(COSREPORT_MODULE mod, COSREPORT_LEVEL level, const char *buffer, unsigned long count); #endif #ifdef __ghs__ /* made this macros to avoid problems if inlining is off * note: do { ... } while (0) * executes body of loop exactly once, and avoids problems * if expanded in an if statement like: * if (x != 0) OSDebugStr("failed"); */ #define OSDebugStr(message) do { \ __SETREG(3, (unsigned int) message); \ asm("tw 31,r31,r31"); \ } while (0) #define OSDebug() OSDebugStr(0) #define OSDebugMessageBytes(message, count) do { \ __SETREG(3, (unsigned int) message); \ __SETREG(4, count); \ asm("tw 31,r30,r30"); \ } while (0) #define OSDebugMessage(message) OSDebugMessageBytes(message, 0) #define OSDebugStrIfConnected(message) do { if (OSIsDebuggerPresent()) OSDebugStr(message); } while (0) #else extern void OSDebug(void); extern void OSDebugStr(const char *message); extern void OSDebugMessage(const char *message); extern void OSDebugMessageBytes(const char *message, unsigned int count); extern void OSDebugStrIfConnected(const char *message); #endif /*---------------------------------------------------------------------------* Get infomation APIs *---------------------------------------------------------------------------*/ const char* OSGetAppGamename(void); const u8 OSGetAppType(void); #define OS_APP_TYPE_WC24 0x20 #define OS_APP_TYPE_IPL 0x40 #define OS_APP_TYPE_DVD 0x80 #define OS_APP_TYPE_NAND 0x81 #ifdef __cplusplus } #endif /*---------------------------------------------------------------------------* Advanced OS APIs *---------------------------------------------------------------------------*/ #include // Processor Core routines and defines #include // Synchronization routines and defines #include // Alarm routines and defines #include // Atomic operation #include // Cache routines and defines #include // Context structures and defines #include // Threads for device drivers and user callback functions #include // Error handler routines and defines #include // Fast float/int conversion #include // Message routines and defines #include // Mutex routines and defines #include // Fast Mutex routines which are not thread cancel points #include // Semaphore routines and defines #include #include #include // Thread routines and defines #include // Reset APIs #include #include #include #include #include #include #include // Memory mapping APIs #include // Platform information #include #define WEAK_SYMBOL #endif // _ASSEMBLER #endif // __OS_H__