1 /*---------------------------------------------------------------------------*
2   Project:  OS Error APIs
3   File:     OSError.h
4 
5   Copyright 1998-2011 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  *---------------------------------------------------------------------------*/
14 
15 #ifndef __OSERROR_H__
16 #define __OSERROR_H__
17 
18 #include <cafe/os.h>
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /*---------------------------------------------------------------------------*
25     Error Handler API
26  *---------------------------------------------------------------------------*/
27 
28 typedef u16    OSError;
29 
30 /*
31  * Note: for most errors, OSErrorHandler takes third and fourth arguments
32  * /dsisr/ and /dar/, which are of type /u32/ like below:
33  *
34  * void (*OSErrorHandler)( OSError error, OSContext* context,
35  *                         u32 dsisr, u32 dar );
36  *
37  */
38 
39 #define OS_ERROR_SYSTEM_RESET         0
40 #define OS_ERROR_MACHINE_CHECK        1
41 #define OS_ERROR_DSI                  2
42 #define OS_ERROR_ISI                  3
43 #define OS_ERROR_EXTERNAL_INTERRUPT   4
44 #define OS_ERROR_ALIGNMENT            5
45 #define OS_ERROR_PROGRAM              6
46 #define OS_ERROR_FLOATING_POINT       7     // floating-point unavailable
47 #define OS_ERROR_DECREMENTER          8
48 #define OS_ERROR_SYSTEM_CALL          9
49 #define OS_ERROR_TRACE                10
50 #define OS_ERROR_PERFORMACE_MONITOR   11
51 #define OS_ERROR_BREAKPOINT           12
52 #define OS_ERROR_SYSTEM_INTERRUPT     13
53 #define OS_ERROR_THERMAL_INTERRUPT    14
54 #define OS_ERROR_PROTECTION           15
55 #define OS_ERROR_FPE                  16    // floating-point exception
56 
57 #define OS_ERROR_MAX                  (OS_ERROR_FPE+1)
58 
59 u32  OSGetLastError( void );
60 
61 void* OSGetSymbolName (u32 addr, u8* symbolName, u32 nameBufSize);
62 
63 
64 // valid crash control modes
65 #define CRASH_CONTROL_MODE_NONE       0
66 #define CRASH_CONTROL_MODE_UNHANDLED  1
67 #define CRASH_CONTROL_MODE_RESTART    2
68 #define CRASH_CONTROL_MODE_REBOOT     3
69 #define CRASH_CONTROL_MODE_KILL       4
70 
71 typedef struct
72 {
73   u32 mode;
74 
75   void* message;
76   u32   data0;
77   u32   data1;
78   u32   data2;
79 
80 } OSCrashControl;
81 
82 
83 // valid crash error codes
84 #define OS_CRASH_ERROR_DSI                  OS_ERROR_DSI
85 #define OS_CRASH_ERROR_ISI                  OS_ERROR_ISI
86 #define OS_CRASH_ERROR_PROGRAM              OS_ERROR_PROGRAM
87 #define OS_CRASH_ERROR_KILL                 OS_ERROR_MAX
88 
89 typedef struct
90 {
91   u32 error;
92   UPID upid;
93   u64 titleid;
94 } OSCrashInfo;
95 
96 void __OSGetAppCrashControl(OSCrashControl *cntl);
97 void __OSSetAppCrashControl(OSCrashControl *cntl);
98 void __OSClearAppCrash(void);
99 void OSGetCrashInfo(OSCrashInfo *cinfo);
100 BOOL OSRestartCrashedApp(void *apArgs, u32 aArgsBytes);
101 BOOL OSRebootCrash(void);
102 
103 void __OSSetTestSetting(const char *name, u32 value);
104 u32 __OSGetTestSetting(const char *name);
105 
106 typedef void (*OSPanicCBFunc)(void *arg);
107 void OSSetPanicCallback(OSPanicCBFunc func, void *arg);
108 
109 #define OS_CRASH_DUMP_TYPE_MINI   0
110 #define OS_CRASH_DUMP_TYPE_FULL   1
111 #define OS_MAX_CRASH_DUMP_TYPE    2   // illegal value
112 
113 u32 OSGetCrashDumpType(void);
114 void OSSetCrashDumpType(u32 type);
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif  // __OSERROR_H__
121