1 /*---------------------------------------------------------------------------*
2   Project:  Dolphin OS Exception table
3   File:     OSException.h
4 
5   Copyright 1998, 1999 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: OSException.h,v $
14   Revision 1.2  2006/02/04 11:56:47  hashida
15   (none)
16 
17   Revision 1.1.1.1  2005/12/29 06:53:28  hiratsu
18   Initial import.
19 
20   Revision 1.1.1.1  2005/05/12 02:41:07  yasuh-to
21   Ported from dolphin source tree.
22 
23 
24     2     2001/03/16 17:41 Shiki
25     Moved GQR1 to GQR7 to general register context.
26 
27     9     1999/08/02 2:36p Shiki
28     Added __OSGetExceptionHandler().
29 
30     8     1999/07/26 4:01p Shiki
31     Removed #include <dolphin/base/PPCArch.h>.
32 
33     7     1999/07/21 2:29p Shiki
34     Removed OS_EXCEPTION_CALLBACK_EXIT macro since it is not necessary any
35     more.
36 
37     6     1999/07/20 10:13p Shiki
38     Cleanup.
39 
40     5     1999/07/08 8:08p Tian
41     All exceptions save and restore LR now.
42 
43     4     1999/05/11 4:43p Shiki
44     Refreshed include tree.
45 
46     2     1999/05/03 5:26p Tianli01
47     PPC->EPPC
48 
49     1     1999/04/30 12:49p Tianli01
50 
51     8     1999/04/21 8:11p Shiki
52     Moved to _DEBUG (avoid DEBUG).
53 
54     7     1999/04/21 8:10p Shiki
55     Detabbed.
56 
57     6     1999/04/13 5:50p Tianli01
58     Added PPCArch.h, added MSR[RI] management to exception handling.
59 
60     5     1999/04/12 7:46p Tianli01
61     Added OSExceptionNames for debugging
62 
63     4     1999/04/02 5:30p Tianli01
64     Fixed minor bug in OS_EXCEPTION_CALLBACK_EXIT.  It now assumes that R4
65     is the context pointer and does not clobber it.
66 
67     3     1999/04/01 7:54p Tianli01
68     Added OS_EXCEPTION_CALLBACK_EXIT for easy returns from exceptions that
69     invoked callbacks.
70 
71     2     1999/03/31 6:08p Tianli01
72     Changed OSException to __OSException.  Added basic context saving
73     helper macros.
74 
75     1     1999/03/26 2:08p Tianli01
76     Broken up from previous OS.h.
77   $NoKeywords: $
78  *---------------------------------------------------------------------------*/
79 
80 #ifndef __OSEXCEPTION_H__
81 #define __OSEXCEPTION_H__
82 
83 #include <revolution/types.h>
84 #include <revolution/os/OSContext.h>
85 
86 #ifdef __cplusplus
87 extern "C" {
88 #endif
89 
90 /*---------------------------------------------------------------------------*
91     Exception Handler API
92  *---------------------------------------------------------------------------*/
93 
94 typedef u8   __OSException;
95 typedef void (*__OSExceptionHandler)(
96     __OSException           exception,
97     OSContext*              context
98 );
99 
100 #define __OS_EXCEPTION_SYSTEM_RESET         0
101 #define __OS_EXCEPTION_MACHINE_CHECK        1
102 #define __OS_EXCEPTION_DSI                  2
103 #define __OS_EXCEPTION_ISI                  3
104 #define __OS_EXCEPTION_EXTERNAL_INTERRUPT   4
105 #define __OS_EXCEPTION_ALIGNMENT            5
106 #define __OS_EXCEPTION_PROGRAM              6
107 #define __OS_EXCEPTION_FLOATING_POINT       7
108 #define __OS_EXCEPTION_DECREMENTER          8
109 #define __OS_EXCEPTION_SYSTEM_CALL          9
110 #define __OS_EXCEPTION_TRACE                10
111 #define __OS_EXCEPTION_PERFORMACE_MONITOR   11
112 #define __OS_EXCEPTION_BREAKPOINT           12
113 #define __OS_EXCEPTION_SYSTEM_INTERRUPT     13
114 #define __OS_EXCEPTION_THERMAL_INTERRUPT    14
115 #define __OS_EXCEPTION_MAX                  \
116         (__OS_EXCEPTION_THERMAL_INTERRUPT+1)
117 
118 // Updates OS exception table, NOT first-level exception vector.
119 __OSExceptionHandler    __OSSetExceptionHandler(
120     __OSException           exception,
121     __OSExceptionHandler    handler
122 );
123 
124 __OSExceptionHandler    __OSGetExceptionHandler(
125     __OSException           exception
126 );
127 
128 // Context saving helpers
129 // For now, use stmw.  Theoretically on 750 it has the same latency
130 // as pipelined stores.
131 #ifdef GEKKO
132 #define OS_EXCEPTION_SAVE_GPRS(context)                 \
133     stw     r0, OS_CONTEXT_R0(context)              ;   \
134     stw     r1, OS_CONTEXT_R1(context)              ;   \
135     stw     r2, OS_CONTEXT_R2(context)              ;   \
136     stmw    r6, OS_CONTEXT_R6(context)              ;   \
137     /* Save GQR1 to GQR7. GQR0 must always be zero */   \
138     mfspr   r0, GQR1                                ;   \
139     stw     r0, OS_CONTEXT_GQR1(context)            ;   \
140     mfspr   r0, GQR2                                ;   \
141     stw     r0, OS_CONTEXT_GQR2(context)            ;   \
142     mfspr   r0, GQR3                                ;   \
143     stw     r0, OS_CONTEXT_GQR3(context)            ;   \
144     mfspr   r0, GQR4                                ;   \
145     stw     r0, OS_CONTEXT_GQR4(context)            ;   \
146     mfspr   r0, GQR5                                ;   \
147     stw     r0, OS_CONTEXT_GQR5(context)            ;   \
148     mfspr   r0, GQR6                                ;   \
149     stw     r0, OS_CONTEXT_GQR6(context)            ;   \
150     mfspr   r0, GQR7                                ;   \
151     stw     r0, OS_CONTEXT_GQR7(context)            ;
152 #else   // !GEKKO
153 #define OS_EXCEPTION_SAVE_GPRS(context)                 \
154     stw     r0, OS_CONTEXT_R0(context)              ;   \
155     stw     r1, OS_CONTEXT_R1(context)              ;   \
156     stw     r2, OS_CONTEXT_R2(context)              ;   \
157     stmw    r6, OS_CONTEXT_R6(context)              ;
158 #endif  // GEKKO
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif  // __OSEXCEPTION_H__
165