1 /*------------------------------------------------------------- 2 3 system.h -- OS functions and initialization 4 5 Copyright (C) 2004 6 Michael Wiedenbauer (shagkur) 7 Dave Murphy (WinterMute) 8 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. 12 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: 16 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. 21 22 2. Altered source versions must be plainly marked as such, and 23 must not be misrepresented as being the original software. 24 25 3. This notice may not be removed or altered from any source 26 distribution. 27 28 -------------------------------------------------------------*/ 29 30 #ifndef __SYSTEM_H__ 31 #define __SYSTEM_H__ 32 33 /*! \file system.h 34 \brief OS functions and initialization 35 36 */ 37 38 #include <gctypes.h> 39 #include <gcutil.h> 40 #include <time.h> 41 #include <ogc/lwp_queue.h> 42 #include "gx_struct.h" 43 44 #define SYS_BASE_CACHED (0x80000000) 45 #define SYS_BASE_UNCACHED (0xC0000000) 46 47 #define SYS_WD_NULL 0xffffffff 48 49 /*! 50 * \addtogroup sys_resettypes OS reset types 51 * @{ 52 */ 53 54 #define SYS_RESTART 0 /*!< Reboot the gamecube, force, if necessary, to boot the IPL menu. Cold reset is issued */ 55 #define SYS_HOTRESET 1 /*!< Restart the application. Kind of softreset */ 56 #define SYS_SHUTDOWN 2 /*!< Shutdown the thread system, card management system etc. Leave current thread running and return to caller */ 57 58 #define SYS_RETURNTOMENU 3 /*!< Directly load the Wii Channels menu, without actually cold-resetting the system */ 59 #define SYS_POWEROFF 4 /*!< Powers off the Wii, automatically choosing Standby or Idle mode depending on the user's configuration */ 60 #define SYS_POWEROFF_STANDBY 5 /*!< Powers off the Wii to standby (red LED, WC24 off) mode. */ 61 #define SYS_POWEROFF_IDLE 6 /*!< Powers off the Wii to idle (yellow LED, WC24 on) mode. */ 62 63 /*! 64 *@} 65 */ 66 67 /*! 68 * \addtogroup sys_mprotchans OS memory protection channels 69 * @{ 70 */ 71 72 #define SYS_PROTECTCHAN0 0 /*!< OS memory protection channel 0 */ 73 #define SYS_PROTECTCHAN1 1 /*!< OS memory protection channel 1 */ 74 #define SYS_PROTECTCHAN2 2 /*!< OS memory protection channel 2 */ 75 #define SYS_PROTECTCHAN3 3 /*!< OS memory protection channel 2 */ 76 #define SYS_PROTECTCHANMAX 4 /*!< _Termination */ 77 78 /*! 79 *@} 80 */ 81 82 /*! 83 * \addtogroup sys_mprotmodes OS memory protection modes 84 * @{ 85 */ 86 87 #define SYS_PROTECTNONE 0x00000000 /*!< Read and write operations on protected region is granted */ 88 #define SYS_PROTECTREAD 0x00000001 /*!< Read from protected region is permitted */ 89 #define SYS_PROTECTWRITE 0x00000002 /*!< Write to protected region is permitted */ 90 #define SYS_PROTECTRDWR (SYS_PROTECTREAD|SYS_PROTECTWRITE) /*!< Read and write operations on protected region is permitted */ 91 92 /*! 93 *@} 94 */ 95 96 #define SYS_FONTSIZE_ANSI (288 + 131072) 97 #define SYS_FONTSIZE_SJIS (3840 + 1179648) 98 99 /*! 100 * \addtogroup sys_mcastmacros OS memory casting macros 101 * @{ 102 */ 103 104 #define MEM_VIRTUAL_TO_PHYSICAL(x) (((u32)(x)) & ~SYS_BASE_UNCACHED) /*!< Cast virtual address to physical address, e.g. 0x8xxxxxxx -> 0x0xxxxxxx */ 105 #define MEM_PHYSICAL_TO_K0(x) (void*)((u32)(x) + SYS_BASE_CACHED) /*!< Cast physical address to cached virtual address, e.g. 0x0xxxxxxx -> 0x8xxxxxxx */ 106 #define MEM_PHYSICAL_TO_K1(x) (void*)((u32)(x) + SYS_BASE_UNCACHED) /*!< Cast physical address to uncached virtual address, e.g. 0x0xxxxxxx -> 0xCxxxxxxx */ 107 #define MEM_K0_TO_PHYSICAL(x) (void*)((u32)(x) - SYS_BASE_CACHED) /*!< Cast physical address to cached virtual address, e.g. 0x0xxxxxxx -> 0x8xxxxxxx */ 108 #define MEM_K1_TO_PHYSICAL(x) (void*)((u32)(x) - SYS_BASE_UNCACHED) /*!< Cast physical address to uncached virtual address, e.g. 0x0xxxxxxx -> 0xCxxxxxxx */ 109 #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 */ 110 #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 */ 111 112 /*! 113 *@} 114 */ 115 116 #define SYS_GetArenaLo SYS_GetArena1Lo 117 #define SYS_SetArenaLo SYS_SetArena1Lo 118 #define SYS_GetArenaHi SYS_GetArena1Hi 119 #define SYS_SetArenaHi SYS_SetArena1Hi 120 #define SYS_GetArenaSize SYS_GetArena1Size 121 122 #ifdef __cplusplus 123 extern "C" { 124 #endif /* __cplusplus */ 125 126 /*! 127 * \typedef u32 syswd_t 128 * \brief handle typedef for the alarm context 129 */ 130 typedef u32 syswd_t; 131 132 /*! 133 * \typedef struct _syssram syssram 134 * \brief holds the stored configuration value from the system SRAM area 135 * \param checksum holds the block checksum. 136 * \param checksum_in holds the inverse block checksum 137 * \param ead0 unknown attribute 138 * \param ead1 unknown attribute 139 * \param counter_bias bias value for the realtime clock 140 * \param display_offsetH pixel offset for the VI 141 * \param ntd unknown attribute 142 * \param lang language of system 143 * \param flags device and operations flag 144 */ 145 typedef struct _syssram syssram; 146 147 struct _syssram { 148 u16 checksum; 149 u16 checksum_inv; 150 u32 ead0; 151 u32 ead1; 152 u32 counter_bias; 153 s8 display_offsetH; 154 u8 ntd; 155 u8 lang; 156 u8 flags; 157 } ATTRIBUTE_PACKED; 158 159 /*! 160 * \typedef struct _syssramex syssramex 161 * \brief holds the stored configuration value from the extended SRAM area 162 * \param flash_id[2][12] 96bit memorycard unlock flash ID 163 * \param wirelessKbd_id Device ID of last connected wireless keyboard 164 * \param wirelessPad_id[4] 16bit device ID of last connected pad. 165 * \param dvderr_code last non-recoverable error from DVD interface 166 * \param __padding0 padding 167 * \param flashID_chksum[2] 16bit checksum of unlock flash ID 168 * \param __padding1[4] padding 169 */ 170 typedef struct _syssramex syssramex; 171 172 struct _syssramex { 173 u8 flash_id[2][12]; 174 u32 wirelessKbd_id; 175 u16 wirelessPad_id[4]; 176 u8 dvderr_code; 177 u8 __padding0; 178 u16 flashID_chksum[2]; 179 u8 __padding1[4]; 180 } ATTRIBUTE_PACKED; 181 182 typedef void (*alarmcallback)(syswd_t alarm,void *cb_arg); 183 184 typedef struct _sys_fontheader sys_fontheader; 185 186 struct _sys_fontheader { 187 u16 font_type; 188 u16 first_char; 189 u16 last_char; 190 u16 inval_char; 191 u16 asc; 192 u16 desc; 193 u16 width; 194 u16 leading; 195 u16 cell_width; 196 u16 cell_height; 197 u32 sheet_size; 198 u16 sheet_format; 199 u16 sheet_column; 200 u16 sheet_row; 201 u16 sheet_width; 202 u16 sheet_height; 203 u16 width_table; 204 u32 sheet_image; 205 u32 sheet_fullsize; 206 u8 c0; 207 u8 c1; 208 u8 c2; 209 u8 c3; 210 } ATTRIBUTE_PACKED; 211 212 typedef void (*resetcallback)(void); 213 typedef void (*powercallback)(void); 214 typedef s32 (*resetfunction)(s32 final); 215 typedef struct _sys_resetinfo sys_resetinfo; 216 217 struct _sys_resetinfo { 218 lwp_node node; 219 resetfunction func; 220 u32 prio; 221 }; 222 223 /*! \fn void SYS_Init() 224 \deprecated Performs basic system initialization such as EXI init etc. This function is called from within the crt0 startup code. 225 226 \return none 227 */ 228 void SYS_Init(); 229 230 /*! 231 * \fn void* SYS_AllocateFramebuffer(GXRModeObj *rmode) 232 * \brief Allocate cacheline aligned memory for the external framebuffer based on the rendermode object. 233 * \param[in] rmode pointer to the video/render mode configuration 234 * 235 * \return pointer to the framebuffer's startaddress. <b><i>NOTE:</i></b> Address returned is aligned to a 32byte boundery! 236 */ 237 void* SYS_AllocateFramebuffer(GXRModeObj *rmode); 238 239 void SYS_ProtectRange(u32 chan,void *addr,u32 bytes,u32 cntrl); 240 void SYS_StartPMC(u32 mcr0val,u32 mcr1val); 241 void SYS_DumpPMC(); 242 void SYS_StopPMC(); 243 244 /*! \fn s32 SYS_CreateAlarm(syswd_t *thealarm) 245 \brief Create/initialize sysalarm structure 246 \param[in] thealarm pointer to the handle to store the created alarm context identifier 247 248 \return 0 on succuess, non-zero on error 249 */ 250 s32 SYS_CreateAlarm(syswd_t *thealarm); 251 252 /*! \fn s32 SYS_SetAlarm(syswd_t thealarm,const struct timespec *tp,alarmcallback cb) 253 \brief Set the alarm parameters for a one-shot alarm, add to the list of alarms and start. 254 \param[in] thealarm identifier to the alarm context to be initialize for a one-shot alarm 255 \param[in] tp pointer to timespec structure holding the time to fire the alarm 256 \param[in] cb pointer to callback which is called when the alarm fires. 257 258 \return 0 on succuess, non-zero on error 259 */ 260 s32 SYS_SetAlarm(syswd_t thealarm,const struct timespec *tp,alarmcallback cb,void *cbarg); 261 262 /*! \fn s32 SYS_SetPeriodicAlarm(syswd_t thealarm,const struct timespec *tp_start,const struct timespec *tp_period,alarmcallback cb) 263 \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. 264 \param[in] thealarm identifier to the alarm context to be initialized for a periodic alarm 265 \param[in] tp_start pointer to timespec structure holding the time to fire first time the alarm 266 \param[in] tp_period pointer to timespec structure holding the interval for all following alarm triggers. 267 \param[in] cb pointer to callback which is called when the alarm fires. 268 269 \return 0 on succuess, non-zero on error 270 */ 271 s32 SYS_SetPeriodicAlarm(syswd_t thealarm,const struct timespec *tp_start,const struct timespec *tp_period,alarmcallback cb,void *cbarg); 272 273 /*! \fn s32 SYS_RemoveAlarm(syswd_t thealarm) 274 \brief Remove the given alarm context from the list of contexts and destroy it 275 \param[in] thealarm identifier to the alarm context to be removed and destroyed 276 277 \return 0 on succuess, non-zero on error 278 */ 279 s32 SYS_RemoveAlarm(syswd_t thealarm); 280 281 /*! \fn s32 SYS_CancelAlarm(syswd_t thealarm) 282 \brief Cancel the alarm, but do not remove from the list of contexts. 283 \param[in] thealarm identifier to the alram context to be canceled 284 285 \return 0 on succuess, non-zero on error 286 */ 287 s32 SYS_CancelAlarm(syswd_t thealarm); 288 289 void SYS_SetWirelessID(u32 chan,u32 id); 290 u32 SYS_GetWirelessID(u32 chan); 291 u32 SYS_GetFontEncoding(); 292 u32 SYS_InitFont(sys_fontheader *font_data); 293 void SYS_GetFontTexture(s32 c,void **image,s32 *xpos,s32 *ypos,s32 *width); 294 void SYS_GetFontTexel(s32 c,void *image,s32 pos,s32 stride,s32 *width); 295 void SYS_ResetSystem(s32 reset,u32 reset_code,s32 force_menu); 296 void SYS_RegisterResetFunc(sys_resetinfo *info); 297 void SYS_UnregisterResetFunc(sys_resetinfo *info); 298 void SYS_SwitchFiber(u32 arg0,u32 arg1,u32 arg2,u32 arg3,u32 pc,u32 newsp); 299 300 void* SYS_GetArena1Lo(); 301 void SYS_SetArena1Lo(void *newLo); 302 void* SYS_GetArena1Hi(); 303 void SYS_SetArena1Hi(void *newHi); 304 u32 SYS_GetArena1Size(); 305 306 resetcallback SYS_SetResetCallback(resetcallback cb); 307 308 u32 SYS_ResetButtonDown(); 309 310 #if defined(HW_RVL) 311 u32 SYS_GetHollywoodRevision(); 312 void* SYS_GetArena2Lo(); 313 void SYS_SetArena2Lo(void *newLo); 314 void* SYS_GetArena2Hi(); 315 void SYS_SetArena2Hi(void *newHi); 316 u32 SYS_GetArena2Size(); 317 powercallback SYS_SetPowerCallback(powercallback cb); 318 #endif 319 320 /* \fn u64 SYS_Time() 321 \brief Returns the current time in ticks since 2000 (proper Dolphin/Wii time) 322 \return ticks since 2000 323 */ 324 u64 SYS_Time(); 325 326 void kprintf(const char *str, ...); 327 328 #ifdef __cplusplus 329 } 330 #endif /* __cplusplus */ 331 332 #endif 333