1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin OS Reset API
3   File:     OSReset.h
4 
5   Copyright 2001-2003 Nintendo.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Log: OSReset.h,v $
14   Revision 1.6  08/10/2006 13:48:37  urata
15   Added OS_SHUTDOWN_PRIO_VI.
16 
17   Revision 1.5  07/24/2006 06:14:34  hirose
18   Cleanup.
19 
20   Revision 1.4  07/24/2006 00:23:34  hirose
21   Changes due to new reset/shutdown architecture.
22 
23   Revision 1.3  06/16/2006 12:45:42  ooizumi
24   Commented out definition of OSExec.
25 
26   Revision 1.2  2006/02/04 11:56:47  hashida
27   (none)
28 
29   Revision 1.1.1.1  2005/12/29 06:53:28  hiratsu
30   Initial import.
31 
32   Revision 1.1.1.1  2005/05/12 02:41:07  yasuh-to
33   transitioned from the Dolphin source tree
34 
35 
36     20    04/01/30 16:42 Hashida
37     Added OSExec.
38 
39 
40     19    11/28/03 19:04 Shiki
41     Removed OSGetRestartCode().
42 
43     18    11/13/03 16:57 Shiki
44     Fixed OSIsRestart() macro for new OSGetResetCode().
45 
46     17    11/13/03 14:20:00 Shiki
47     Added support for OSGetRestartCode().
48 
49     16    10/24/03 9:33 Shiki
50     Defined OS_RESETCODE_NETCONFIG.
51 
52     15    7/10/03 14:38 Shiki
53     Defined OS_RESET_PRIO_ALARM.
54 
55     14     03/04/16 22:32:00 Hashida
56     Added OSSetBootDol.
57 
58     13    3/12/03 11:28 Shiki
59     Defined OS_RESET_PRIO_SO and OS_RESET_PRIO_IP.
60 
61     12    2/13/03 14:24 Shiki
62     Defined OS_RESET_TIMEOUT.
63 
64     11    02/11/19 14:55 Hirose
65     Added OS_RESET_PRIO_GX.
66 
67     10    02/10/28 20:28 Hashida
68     Added OSIsRestart().
69 
70     9     02/04/11 17:59 Hashida
71     Added OSGetSavedRegion
72 
73     8     9/15/01 3:31a Hashida
74     Added OS_RESET_SHUTDOWN
75 
76     7     9/07/01 5:30a Hashida
77     Added OSSet/GetSaveRegion.
78 
79     6     7/18/01 10:55p Hashida
80     Changed definitions.
81 
82     5     7/11/01 10:19p Hashida
83     Added code definition for restarting.
84 
85     4     5/17/01 8:20p Shiki
86     Modified priority from s32 to u32.
87 
88     3     5/17/01 7:58p Shiki
89     Revised.
90 
91     2     01/04/23 16:31:00 Shiki
92     Added menu param to OSResetSystem().
93 
94     1     01/04/09 13:52 Shiki
95     Initial check-in.
96   $NoKeywords: $
97  *---------------------------------------------------------------------------*/
98 
99 #ifndef __OSRESET_H__
100 #define __OSRESET_H__
101 
102 #include <revolution/types.h>
103 
104 #ifdef __cplusplus
105 extern "C" {
106 #endif
107 
108 #define OS_RESETCODE_RESTART    0x80000000      // not by cold/hot reset
109 #define OS_RESETCODE_SYSTEM     0x40000000      // reserved by system
110 
111 #define OS_RESETCODE_EXEC       0xC0000000
112 #define OS_RESETCODE_NETCONFIG  0xC0010000
113 
114 #define OS_RESET_TIMEOUT        OSMillisecondsToTicks(1000)
115 
116 #define OS_RESET_RESTART        0
117 #define OS_RESET_HOTRESET       1
118 #define OS_RESET_SHUTDOWN       2
119 
120 #define OS_SHUTDOWN_PRIO_SO         110     // SO API
121 #define OS_SHUTDOWN_PRIO_IP         111     // IP API
122 #define OS_SHUTDOWN_PRIO_MIDI       126     // MIDI API
123 #define OS_SHUTDOWN_PRIO_CARD       127     // CARD API
124 #define OS_SHUTDOWN_PRIO_PAD        127     // PAD API
125 #define OS_SHUTDOWN_PRIO_STEERING   127     // SI Steering
126 #define OS_SHUTDOWN_PRIO_GX         127     // GX API
127 #define OS_SHUTDOWN_PRIO_MEMPROT    127     // OS Memory Protection
128 #define OS_SHUTDOWN_PRIO_ALARM      4294967295  // OSAlarm
129 #define OS_SHUTDOWN_PRIO_VI         127     // VI API
130 
131 // Event types for __OSShutdownDevices()
132 #define OS_SD_FATALERR          0
133 #define OS_SD_REBOOT            1
134 #define OS_SD_SHUTDOWN          2
135 #define OS_SD_IDLE              3
136 #define OS_SD_RESTART           4
137 #define OS_SD_RETURNTOMENU      5
138 #define OS_SD_EXEC              6
139 
140 
141 typedef BOOL (* OSShutdownFunction )( BOOL final, u32 event );
142 typedef struct OSShutdownFunctionInfo OSShutdownFunctionInfo;
143 
144 struct OSShutdownFunctionInfo
145 {
146     // public
147     OSShutdownFunction      func;
148     u32                     priority;
149 
150     // private
151     OSShutdownFunctionInfo* next;
152     OSShutdownFunctionInfo* prev;
153 };
154 
155 void OSRegisterShutdownFunction     ( OSShutdownFunctionInfo* info );
156 void OSUnregisterShutdownFunction   ( OSShutdownFunctionInfo* info );
157 
158 
159 void OSRebootSystem         ( void );
160 void OSShutdownSystem       ( void );
161 void OSRestart              ( u32 resetCode );
162 void OSReturnToMenu         ( void );
163 
164 
165 u32  OSGetResetCode         ( void );
166 void OSGetSaveRegion        ( void** start, void** end );
167 void OSGetSavedRegion       ( void** start, void** end );
168 void OSSetSaveRegion        ( void* start, void* end );
169 
170 
171 // Obsolete (implemented as stubs)
172 void OSResetSystem          ( int reset, u32 resetCode, BOOL forceMenu );
173 u32  OSSetBootDol           ( u32 dolOffset );
174 
175 // Obsolete
176 #if 0
177 typedef BOOL (* OSResetFunction )(BOOL final);
178 typedef struct OSResetFunctionInfo OSResetFunctionInfo;
179 
180 struct OSResetFunctionInfo
181 {
182     // public
183     OSResetFunction      func;
184     u32                  priority;
185 
186     // private
187     OSResetFunctionInfo* next;
188     OSResetFunctionInfo* prev;
189 };
190 
191 void OSRegisterResetFunction  ( OSResetFunctionInfo* info );
192 void OSUnregisterResetFunction( OSResetFunctionInfo* info );
193 #endif
194 
195 // Hidden temporary
196 // void OSExecv                  ( const char* dolfile, char* const argv[] );
197 // void OSExecl                  ( const char* dolfile,
198 //                                const char* arg0, .../*, (char*)NULL */ );
199 
200 /*---------------------------------------------------------------------------*
201   Name:         OSIsRestart
202 
203   Description:  Check to see if it's restarted
204 
205   Arguments:    None
206 
207   Returns:      True if restarted, False if cold-started
208  *---------------------------------------------------------------------------*/
209 #define OSIsRestart()   \
210             ((OSGetResetCode() & OS_RESETCODE_RESTART) ? TRUE : FALSE)
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif  // __OSRESET_H__
217