1 /*-------------------------------------------------------------
3 system.h -- OS functions and initialization
6 Michael Wiedenbauer (shagkur)
7 Dave Murphy (WinterMute)
9 This software is provided 'as-is', without any express or implied
10 warranty. In no event will the authors be held liable for any
11 damages arising from the use of this software.
13 Permission is granted to anyone to use this software for any
14 purpose, including commercial applications, and to alter it and
15 redistribute it freely, subject to the following restrictions:
17 1. The origin of this software must not be misrepresented; you
18 must not claim that you wrote the original software. If you use
19 this software in a product, an acknowledgment in the product
20 documentation would be appreciated but is not required.
22 2. Altered source versions must be plainly marked as such, and
23 must not be misrepresented as being the original software.
25 3. This notice may not be removed or altered from any source
29 -------------------------------------------------------------*/
37 \brief OS functions and initialization
44 #include <ogc/lwp_queue.h>
45 #include "gx_struct.h"
47 #define SYS_BASE_CACHED (0x80000000)
48 #define SYS_BASE_UNCACHED (0xC0000000)
50 #define SYS_WD_NULL 0xffffffff
53 * \addtogroup sys_resettypes OS reset types
57 #define SYS_RESTART 0 /*!< Reboot the gamecube, force, if necessary, to boot the IPL menu. Cold reset is issued */
58 #define SYS_HOTRESET 1 /*!< Restart the application. Kind of softreset */
59 #define SYS_SHUTDOWN 2 /*!< Shutdown the thread system, card management system etc. Leave current thread running and return to caller */
61 #define SYS_RETURNTOMENU 3 /*!< Directly load the Wii Channels menu, without actually cold-resetting the system */
62 #define SYS_POWEROFF 4 /*!< Powers off the Wii, automatically choosing Standby or Idle mode depending on the user's configuration */
63 #define SYS_POWEROFF_STANDBY 5 /*!< Powers off the Wii to standby (red LED, WC24 off) mode. */
64 #define SYS_POWEROFF_IDLE 6 /*!< Powers off the Wii to idle (yellow LED, WC24 on) mode. */
72 * \addtogroup sys_mprotchans OS memory protection channels
76 #define SYS_PROTECTCHAN0 0 /*!< OS memory protection channel 0 */
77 #define SYS_PROTECTCHAN1 1 /*!< OS memory protection channel 1 */
78 #define SYS_PROTECTCHAN2 2 /*!< OS memory protection channel 2 */
79 #define SYS_PROTECTCHAN3 3 /*!< OS memory protection channel 2 */
80 #define SYS_PROTECTCHANMAX 4 /*!< _Termination */
88 * \addtogroup sys_mprotmodes OS memory protection modes
92 #define SYS_PROTECTNONE 0x00000000 /*!< Read and write operations on protected region is granted */
93 #define SYS_PROTECTREAD 0x00000001 /*!< Read from protected region is permitted */
94 #define SYS_PROTECTWRITE 0x00000002 /*!< Write to protected region is permitted */
95 #define SYS_PROTECTRDWR (SYS_PROTECTREAD|SYS_PROTECTWRITE) /*!< Read and write operations on protected region is permitted */
101 #define SYS_FONTSIZE_ANSI (288 + 131072)
102 #define SYS_FONTSIZE_SJIS (3840 + 1179648)
107 * \addtogroup sys_mcastmacros OS memory casting macros
111 #define MEM_VIRTUAL_TO_PHYSICAL(x) (((u32)(x)) & ~SYS_BASE_UNCACHED) /*!< Cast virtual address to physical address, e.g. 0x8xxxxxxx -> 0x0xxxxxxx */
112 #define MEM_PHYSICAL_TO_K0(x) (void*)((u32)(x) + SYS_BASE_CACHED) /*!< Cast physical address to cached virtual address, e.g. 0x0xxxxxxx -> 0x8xxxxxxx */
113 #define MEM_PHYSICAL_TO_K1(x) (void*)((u32)(x) + SYS_BASE_UNCACHED) /*!< Cast physical address to uncached virtual address, e.g. 0x0xxxxxxx -> 0xCxxxxxxx */
114 #define MEM_K0_TO_PHYSICAL(x) (void*)((u32)(x) - SYS_BASE_CACHED) /*!< Cast physical address to cached virtual address, e.g. 0x0xxxxxxx -> 0x8xxxxxxx */
115 #define MEM_K1_TO_PHYSICAL(x) (void*)((u32)(x) - SYS_BASE_UNCACHED) /*!< Cast physical address to uncached virtual address, e.g. 0x0xxxxxxx -> 0xCxxxxxxx */
116 #define MEM_K0_TO_K1(x) (void*)((u32)(x) + (SYS_BASE_UNCACHED - SYS_BASE_CACHED)) /*!< Cast cached virtual address to uncached virtual address, e.g. 0x8xxxxxxx -> 0xCxxxxxxx */
117 #define MEM_K1_TO_K0(x) (void*)((u32)(x) - (SYS_BASE_UNCACHED - SYS_BASE_CACHED)) /*!< Cast uncached virtual address to cached virtual address, e.g. 0xCxxxxxxx -> 0x8xxxxxxx */
123 #define SYS_GetArenaLo SYS_GetArena1Lo
124 #define SYS_SetArenaLo SYS_SetArena1Lo
125 #define SYS_GetArenaHi SYS_GetArena1Hi
126 #define SYS_SetArenaHi SYS_SetArena1Hi
127 #define SYS_GetArenaSize SYS_GetArena1Size
131 #endif /* __cplusplus */
135 * \typedef u32 syswd_t
136 * \brief handle typedef for the alarm context
142 * \typedef struct _syssram syssram
143 * \brief holds the stored configuration value from the system SRAM area
144 * \param checksum holds the block checksum.
145 * \param checksum_in holds the inverse block checksum
146 * \param ead0 unknown attribute
147 * \param ead1 unknown attribute
148 * \param counter_bias bias value for the realtime clock
149 * \param display_offsetH pixel offset for the VI
150 * \param ntd unknown attribute
151 * \param lang language of system
152 * \param flags device and operations flag
154 typedef struct _syssram syssram
;
170 * \typedef struct _syssramex syssramex
171 * \brief holds the stored configuration value from the extended SRAM area
172 * \param flash_id[2][12] 96bit memorycard unlock flash ID
173 * \param wirelessKbd_id Device ID of last connected wireless keyboard
174 * \param wirelessPad_id[4] 16bit device ID of last connected pad.
175 * \param dvderr_code last non-recoverable error from DVD interface
176 * \param __padding0 padding
177 * \param flashID_chksum[2] 16bit checksum of unlock flash ID
178 * \param __padding1[4] padding
180 typedef struct _syssramex syssramex
;
185 u16 wirelessPad_id
[4];
188 u16 flashID_chksum
[2];
192 typedef void (*alarmcallback
)(syswd_t alarm
,void *cb_arg
);
194 typedef struct _sys_fontheader sys_fontheader
;
196 struct _sys_fontheader
{
222 typedef void (*resetcallback
)(void);
223 typedef void (*powercallback
)(void);
224 typedef s32 (*resetfunction
)(s32 final
);
225 typedef struct _sys_resetinfo sys_resetinfo
;
227 struct _sys_resetinfo
{
233 /*! \fn void SYS_Init()
234 \deprecated Performs basic system initialization such as EXI init etc. This function is called from within the crt0 startup code.
242 * \fn void* SYS_AllocateFramebuffer(GXRModeObj *rmode)
243 * \brief Allocate cacheline aligned memory for the external framebuffer based on the rendermode object.
244 * \param[in] rmode pointer to the video/render mode configuration
246 * \return pointer to the framebuffer's startaddress. <b><i>NOTE:</i></b> Address returned is aligned to a 32byte boundery!
248 void* SYS_AllocateFramebuffer(GXRModeObj
*rmode
);
251 void SYS_ProtectRange(u32 chan
,void *addr
,u32 bytes
,u32 cntrl
);
252 void SYS_StartPMC(u32 mcr0val
,u32 mcr1val
);
257 /*! \fn s32 SYS_CreateAlarm(syswd_t *thealarm)
258 \brief Create/initialize sysalarm structure
259 \param[in] thealarm pointer to the handle to store the created alarm context identifier
261 \return 0 on succuess, non-zero on error
263 s32
SYS_CreateAlarm(syswd_t
*thealarm
);
266 /*! \fn s32 SYS_SetAlarm(syswd_t thealarm,const struct timespec *tp,alarmcallback cb)
267 \brief Set the alarm parameters for a one-shot alarm, add to the list of alarms and start.
268 \param[in] thealarm identifier to the alarm context to be initialize for a one-shot alarm
269 \param[in] tp pointer to timespec structure holding the time to fire the alarm
270 \param[in] cb pointer to callback which is called when the alarm fires.
272 \return 0 on succuess, non-zero on error
274 s32
SYS_SetAlarm(syswd_t thealarm
,const struct timespec
*tp
,alarmcallback cb
,void *cbarg
);
277 /*! \fn s32 SYS_SetPeriodicAlarm(syswd_t thealarm,const struct timespec *tp_start,const struct timespec *tp_period,alarmcallback cb)
278 \brief Set the alarm parameters for a periodioc alarm, add to the list of alarms and start. The alarm and interval persists as long as SYS_CancelAlarm() isn't called.
279 \param[in] thealarm identifier to the alarm context to be initialized for a periodic alarm
280 \param[in] tp_start pointer to timespec structure holding the time to fire first time the alarm
281 \param[in] tp_period pointer to timespec structure holding the interval for all following alarm triggers.
282 \param[in] cb pointer to callback which is called when the alarm fires.
284 \return 0 on succuess, non-zero on error
286 s32
SYS_SetPeriodicAlarm(syswd_t thealarm
,const struct timespec
*tp_start
,const struct timespec
*tp_period
,alarmcallback cb
,void *cbarg
);
289 /*! \fn s32 SYS_RemoveAlarm(syswd_t thealarm)
290 \brief Remove the given alarm context from the list of contexts and destroy it
291 \param[in] thealarm identifier to the alarm context to be removed and destroyed
293 \return 0 on succuess, non-zero on error
295 s32
SYS_RemoveAlarm(syswd_t thealarm
);
298 /*! \fn s32 SYS_CancelAlarm(syswd_t thealarm)
299 \brief Cancel the alarm, but do not remove from the list of contexts.
300 \param[in] thealarm identifier to the alram context to be canceled
302 \return 0 on succuess, non-zero on error
304 s32
SYS_CancelAlarm(syswd_t thealarm
);
307 void SYS_SetWirelessID(u32 chan
,u32 id
);
308 u32
SYS_GetWirelessID(u32 chan
);
309 u32
SYS_GetFontEncoding();
310 u32
SYS_InitFont(sys_fontheader
*font_data
);
311 void SYS_GetFontTexture(s32 c
,void **image
,s32
*xpos
,s32
*ypos
,s32
*width
);
312 void SYS_GetFontTexel(s32 c
,void *image
,s32 pos
,s32 stride
,s32
*width
);
313 void SYS_ResetSystem(s32 reset
,u32 reset_code
,s32 force_menu
);
314 void SYS_RegisterResetFunc(sys_resetinfo
*info
);
315 void SYS_UnregisterResetFunc(sys_resetinfo
*info
);
316 u32
SYS_GetArenaSize();
317 void SYS_SwitchFiber(u32 arg0
,u32 arg1
,u32 arg2
,u32 arg3
,u32 pc
,u32 newsp
);
319 void* SYS_GetArena1Lo();
320 void SYS_SetArena1Lo(void *newLo
);
321 void* SYS_GetArena1Hi();
322 void SYS_SetArena1Hi(void *newHi
);
323 u32
SYS_GetArena1Size();
325 resetcallback
SYS_SetResetCallback(resetcallback cb
);
327 u32
SYS_ResetButtonDown();
330 u32
SYS_GetHollywoodRevision();
331 void* SYS_GetArena2Lo();
332 void SYS_SetArena2Lo(void *newLo
);
333 void* SYS_GetArena2Hi();
334 void SYS_SetArena2Hi(void *newHi
);
335 u32
SYS_GetArena2Size();
336 powercallback
SYS_SetPowerCallback(powercallback cb
);
339 void kprintf(const char *str
, ...);
343 #endif /* __cplusplus */