1 /*---------------------------------------------------------------------------*
2   Project:  OS
3   File:     OSException.h
4 
5   Copyright 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 __OSEXCEPTION_H__
16 #define __OSEXCEPTION_H__
17 
18 #define OS_EXCEPTION_SYSTEM_RESET         0
19 #define OS_EXCEPTION_MACHINE_CHECK        1
20 #define OS_EXCEPTION_DSI                  2
21 #define OS_EXCEPTION_ISI                  3
22 #define OS_EXCEPTION_EXTERNAL_INTERRUPT   4
23 #define OS_EXCEPTION_ALIGNMENT            5
24 #define OS_EXCEPTION_PROGRAM              6
25 #define OS_EXCEPTION_FLOATING_POINT       7
26 #define OS_EXCEPTION_DECREMENTER          8
27 #define OS_EXCEPTION_SYSTEM_CALL          9
28 #define OS_EXCEPTION_TRACE                10
29 #define OS_EXCEPTION_PERFORMANCE_MONITOR  11
30 #define OS_EXCEPTION_BREAKPOINT           12
31 #define OS_EXCEPTION_SYSTEM_INTERRUPT     13
32 #define OS_EXCEPTION_ICI                  14
33 #define OS_EXCEPTION_MAX                  (OS_EXCEPTION_ICI + 1)
34 
35 #ifndef _ASSEMBLER
36 #include <types.h>
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 #define OS_EXCEPTION_MODE_SYSTEM               0
43 #define OS_EXCEPTION_MODE_THREAD               1
44 #define OS_EXCEPTION_MODE_GLOBAL               2
45 #define OS_EXCEPTION_MODE_THREAD_ALL_CORES     3
46 #define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES     4
47 
48 FORWARD_DECLARE_STRUCT_TYPE(OSContext)
49 
50 typedef u8 OSExceptionMode;
51 typedef u8 OSExceptionType;
52 typedef BOOL (*OSExceptionCallback)(OSContext* interruptedContext);
53 OSExceptionCallback OSSetExceptionCallback(OSExceptionType     exceptionType,
54                                            OSExceptionCallback callback);
55 OSExceptionCallback OSSetExceptionCallbackEx(OSExceptionMode     exceptionMode,
56 		                                     OSExceptionType     exceptionType,
57                                              OSExceptionCallback newCallback);
58 
59 /* DABR and IABR registers are set per-process */
60 void OSSetDABR(BOOL allCores, void* address, BOOL matchReads, BOOL matchWrites);
61 void OSSetIABR(BOOL allCores, void* address);
62 
63 /*---------------------------------------------------------------------------*
64 	FPSCR bits
65  *---------------------------------------------------------------------------*/
66 #ifndef FPSCR_FX
67 #define FPSCR_FX            0x80000000  // Exception summary
68 #define FPSCR_FEX           0x40000000  // Enabled exception summary
69 #define FPSCR_VX            0x20000000  // Invalid operation
70 #define FPSCR_OX            0x10000000  // Overflow exception
71 #define FPSCR_UX            0x08000000  // Underflow exception
72 #define FPSCR_ZX            0x04000000  // Zero divide exception
73 #define FPSCR_XX            0x02000000  // Inexact exception
74 #define FPSCR_VXSNAN        0x01000000  // SNaN
75 #define FPSCR_VXISI         0x00800000  // Infinity - Infinity
76 #define FPSCR_VXIDI         0x00400000  // Infinity / Infinity
77 #define FPSCR_VXZDZ         0x00200000  // 0 / 0
78 #define FPSCR_VXIMZ         0x00100000  // Infinity * 0
79 #define FPSCR_VXVC          0x00080000  // Invalid compare
80 #define FPSCR_FR            0x00040000  // Fraction rounded
81 #define FPSCR_FI            0x00020000  // Fraction inexact
82 #define FPSCR_VXSOFT        0x00000400  // Software request
83 #define FPSCR_VXSQRT        0x00000200  // Invalid square root
84 #define FPSCR_VXCVI         0x00000100  // Invalid integer convert
85 #define FPSCR_VE            0x00000080  // Invalid operation exception enable
86 #define FPSCR_OE            0x00000040  // Overflow exception enable
87 #define FPSCR_UE            0x00000020  // Underflow exception enable
88 #define FPSCR_ZE            0x00000010  // Zero divide exception enable
89 #define FPSCR_XE            0x00000008  // Inexact exception enable
90 #define FPSCR_NI            0x00000004  // Non-IEEE mode
91 #endif  // FPSCR_FX
92 
93 #define FPSCR_ALL_ENABLE    (FPSCR_VE | FPSCR_OE | FPSCR_UE | FPSCR_ZE | FPSCR_XE)
94 
95 #define FPSCR_ALL_STATUS    (FPSCR_FX | FPSCR_FEX | FPSCR_VX | FPSCR_OX | FPSCR_UX | FPSCR_ZX | FPSCR_XX | \
96                              FPSCR_VXSNAN | FPSCR_VXISI | FPSCR_VXIDI | FPSCR_VXZDZ | FPSCR_VXIMZ | FPSCR_VXVC | \
97                              FPSCR_FI | FPSCR_VXSOFT | FPSCR_VXSQRT | FPSCR_VXCVI)
98 
99 FORWARD_DECLARE_STRUCT_TYPE(OSThread)
100 BOOL OSEnableThreadFPUException(OSThread *thread, u32 fpu_ex_mask);
101 u32 OSEnableAllThreadFPUException(u32 fpu_ex_mask);
102 BOOL OSDisableThreadFPUException(OSThread *thread);
103 u32 OSDisableAllThreadFPUException(void);
104 void OSDisableContextFPUException(OSContext *context);
105 
106 #ifdef __cplusplus
107 }
108 #endif
109 
110 #endif  // _ASSEMBLER
111 #endif  // __OSEXCEPTION_H__
112 
113