1 /*---------------------------------------------------------------------------*
2   Project:  Revolution OS Interrupt API
3   File:     OSInterrupt.h
4   Programmers: Shiki Okasaka
5                Hashida Takayuki
6                HIRATSU Daisuke
7                Kazuki Hirose
8 
9   Copyright 1998-2006 Nintendo.  All rights reserved.
10 
11   These coded instructions, statements, and computer programs contain
12   proprietary information of Nintendo of America Inc. and/or Nintendo
13   Company Ltd., and are protected by Federal copyright law.  They may
14   not be disclosed to third parties or copied or duplicated in any form,
15   in whole or in part, without the prior written consent of Nintendo.
16 
17 
18     5     11/09/01 12:54 Shiki
19     Added __OSLastInterrupt and other declarations.
20 
21     4     01/02/14 21:07 Shiki
22     Added __OS_INTERRUPT_PI_HSP.
23 
24     3     5/13/00 7:38p Shiki
25     Added __OSSpuriousInterrupts().
26 
27     2     4/20/00 5:43p Shiki
28     Minor revision.
29 
30     12    11/10/99 4:36p Shiki
31     Revised CP and PE interrupt handling method.
32 
33     11    10/04/99 10:19a Hashida
34     Changed VI to be handled using PI_VI
35 
36     10    9/08/99 4:26p Shiki
37     Removed CP_IDLE and CP_BREAKPOINT definitions.
38 
39     9     9/03/99 5:56p Shiki
40     Changed __OS_INTERRUPT_SI_TC to __OS_INTERRUPT_PI_SI.
41 
42     8     8/27/99 4:32p Shiki
43     Revised __OS_INTERRUPT definitions.
44 
45     7     8/26/99 5:11p Shiki
46     Added __OS_INTERRUPT_MEM_ADDRESS.
47 
48     6     8/19/99 3:48p Shiki
49     Added __OSDispatchInterrupt().
50 
51     5     8/17/99 3:31p Shiki
52     Revised OS_INTERRUPTMASK_* definitions.
53 
54     4     8/16/99 11:04p Shiki
55     Added __OSSetInterruptMask() and __OSGetInterruptMask().
56 
57     3     8/16/99 10:06p Shiki
58     Added OS_INTERRUPTMASK_* definitions.
59 
60     2     8/13/99 5:22p Shiki
61     Revised __OS_INTERRUPT definitions.
62 
63     1     8/02/99 2:17p Shiki
64     Initial check-in.
65   $NoKeywords: $
66  *---------------------------------------------------------------------------*/
67 
68 #ifndef __OSINTERRUPT_H__
69 #define __OSINTERRUPT_H__
70 
71 #include <revolution/types.h>
72 #include <revolution/os/OSContext.h>
73 
74 #ifdef __cplusplus
75 extern "C" {
76 #endif
77 
78 typedef s16  __OSInterrupt;
79 typedef void (*__OSInterruptHandler)(
80     __OSInterrupt   interrupt,
81     OSContext*      context
82 );
83 
84 typedef u32  OSInterruptMask;
85 
86 #define __OS_INTERRUPT_MEM_0                0
87 #define __OS_INTERRUPT_MEM_1                1
88 #define __OS_INTERRUPT_MEM_2                2
89 #define __OS_INTERRUPT_MEM_3                3
90 #define __OS_INTERRUPT_MEM_ADDRESS          4
91 #define __OS_INTERRUPT_DSP_AI               5
92 #define __OS_INTERRUPT_DSP_ARAM             6
93 #define __OS_INTERRUPT_DSP_DSP              7
94 #define __OS_INTERRUPT_AI_AI                8
95 #define __OS_INTERRUPT_EXI_0_EXI            9
96 #define __OS_INTERRUPT_EXI_0_TC             10
97 #define __OS_INTERRUPT_EXI_0_EXT            11
98 #define __OS_INTERRUPT_EXI_1_EXI            12
99 #define __OS_INTERRUPT_EXI_1_TC             13
100 #define __OS_INTERRUPT_EXI_1_EXT            14
101 #define __OS_INTERRUPT_EXI_2_EXI            15
102 #define __OS_INTERRUPT_EXI_2_TC             16
103 #define __OS_INTERRUPT_PI_CP                17
104 #define __OS_INTERRUPT_PI_PE_TOKEN          18
105 #define __OS_INTERRUPT_PI_PE_FINISH         19
106 #define __OS_INTERRUPT_PI_SI                20
107 #define __OS_INTERRUPT_PI_DI                21
108 #define __OS_INTERRUPT_PI_RSW               22
109 #define __OS_INTERRUPT_PI_ERROR             23
110 #define __OS_INTERRUPT_PI_VI                24
111 #define __OS_INTERRUPT_PI_DEBUG             25
112 #define __OS_INTERRUPT_PI_HSP               26
113 #define __OS_INTERRUPT_PI_ACR               27   // for Revolution
114 #define __OS_INTERRUPT_MAX                  32
115 
116 
117 #define OS_INTERRUPTMASK(interrupt)         (0x80000000u >> (interrupt))        // for cntlzw
118 
119 #define OS_INTERRUPTMASK_MEM_0              OS_INTERRUPTMASK(__OS_INTERRUPT_MEM_0)
120 #define OS_INTERRUPTMASK_MEM_1              OS_INTERRUPTMASK(__OS_INTERRUPT_MEM_1)
121 #define OS_INTERRUPTMASK_MEM_2              OS_INTERRUPTMASK(__OS_INTERRUPT_MEM_2)
122 #define OS_INTERRUPTMASK_MEM_3              OS_INTERRUPTMASK(__OS_INTERRUPT_MEM_3)
123 #define OS_INTERRUPTMASK_MEM_ADDRESS        OS_INTERRUPTMASK(__OS_INTERRUPT_MEM_ADDRESS)
124 #define OS_INTERRUPTMASK_MEM                (OS_INTERRUPTMASK_MEM_0             | \
125                                                 OS_INTERRUPTMASK_MEM_1          | \
126                                                 OS_INTERRUPTMASK_MEM_2          | \
127                                                 OS_INTERRUPTMASK_MEM_3          | \
128                                                 OS_INTERRUPTMASK_MEM_ADDRESS)
129 #define OS_INTERRUPTMASK_DSP_AI             OS_INTERRUPTMASK(__OS_INTERRUPT_DSP_AI)
130 #define OS_INTERRUPTMASK_DSP_ARAM           OS_INTERRUPTMASK(__OS_INTERRUPT_DSP_ARAM)
131 #define OS_INTERRUPTMASK_DSP_DSP            OS_INTERRUPTMASK(__OS_INTERRUPT_DSP_DSP)
132 #define OS_INTERRUPTMASK_DSP                (OS_INTERRUPTMASK_DSP_AI            | \
133                                                 OS_INTERRUPTMASK_DSP_ARAM       | \
134                                                 OS_INTERRUPTMASK_DSP_DSP)
135 #define OS_INTERRUPTMASK_AI_AI              OS_INTERRUPTMASK(__OS_INTERRUPT_AI_AI)
136 #define OS_INTERRUPTMASK_AI                 (OS_INTERRUPTMASK_AI_AI)
137 #define OS_INTERRUPTMASK_EXI_0_EXI          OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_0_EXI)
138 #define OS_INTERRUPTMASK_EXI_0_TC           OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_0_TC)
139 #define OS_INTERRUPTMASK_EXI_0_EXT          OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_0_EXT)
140 #define OS_INTERRUPTMASK_EXI_0              (OS_INTERRUPTMASK_EXI_0_EXI         | \
141                                                 OS_INTERRUPTMASK_EXI_0_TC       | \
142                                                 OS_INTERRUPTMASK_EXI_0_EXT)
143 #define OS_INTERRUPTMASK_EXI_1_EXI          OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_1_EXI)
144 #define OS_INTERRUPTMASK_EXI_1_TC           OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_1_TC)
145 #define OS_INTERRUPTMASK_EXI_1_EXT          OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_1_EXT)
146 #define OS_INTERRUPTMASK_EXI_1              (OS_INTERRUPTMASK_EXI_1_EXI         | \
147                                                 OS_INTERRUPTMASK_EXI_1_TC       | \
148                                                 OS_INTERRUPTMASK_EXI_1_EXT)
149 #define OS_INTERRUPTMASK_EXI_2_EXI          OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_2_EXI)
150 #define OS_INTERRUPTMASK_EXI_2_TC           OS_INTERRUPTMASK(__OS_INTERRUPT_EXI_2_TC)
151 #define OS_INTERRUPTMASK_EXI_2              (OS_INTERRUPTMASK_EXI_2_EXI         | \
152                                                 OS_INTERRUPTMASK_EXI_2_TC)
153 #define OS_INTERRUPTMASK_EXI                (OS_INTERRUPTMASK_EXI_0_EXI         | \
154                                                 OS_INTERRUPTMASK_EXI_0_TC       | \
155                                                 OS_INTERRUPTMASK_EXI_0_EXT      | \
156                                                 OS_INTERRUPTMASK_EXI_1_EXI      | \
157                                                 OS_INTERRUPTMASK_EXI_1_TC       | \
158                                                 OS_INTERRUPTMASK_EXI_1_EXT      | \
159                                                 OS_INTERRUPTMASK_EXI_2_EXI      | \
160                                                 OS_INTERRUPTMASK_EXI_2_TC)
161 #define OS_INTERRUPTMASK_PI_PE_TOKEN        OS_INTERRUPTMASK(__OS_INTERRUPT_PI_PE_TOKEN)
162 #define OS_INTERRUPTMASK_PI_PE_FINISH       OS_INTERRUPTMASK(__OS_INTERRUPT_PI_PE_FINISH)
163 #define OS_INTERRUPTMASK_PI_PE              (OS_INTERRUPTMASK_PI_PE_TOKEN       | \
164                                                 OS_INTERRUPTMASK_PI_PE_FINISH)
165 #define OS_INTERRUPTMASK_PI_CP              OS_INTERRUPTMASK(__OS_INTERRUPT_PI_CP)
166 #define OS_INTERRUPTMASK_PI_SI              OS_INTERRUPTMASK(__OS_INTERRUPT_PI_SI)
167 #define OS_INTERRUPTMASK_PI_DI              OS_INTERRUPTMASK(__OS_INTERRUPT_PI_DI)
168 #define OS_INTERRUPTMASK_PI_RSW             OS_INTERRUPTMASK(__OS_INTERRUPT_PI_RSW)
169 #define OS_INTERRUPTMASK_PI_ERROR           OS_INTERRUPTMASK(__OS_INTERRUPT_PI_ERROR)
170 #define OS_INTERRUPTMASK_PI_VI              OS_INTERRUPTMASK(__OS_INTERRUPT_PI_VI)
171 #define OS_INTERRUPTMASK_PI_DEBUG           OS_INTERRUPTMASK(__OS_INTERRUPT_PI_DEBUG)
172 #define OS_INTERRUPTMASK_PI_HSP             OS_INTERRUPTMASK(__OS_INTERRUPT_PI_HSP)
173 #define OS_INTERRUPTMASK_PI_ACR             OS_INTERRUPTMASK(__OS_INTERRUPT_PI_ACR)
174 #define OS_INTERRUPTMASK_PI                 (OS_INTERRUPTMASK_PI_CP             | \
175                                                 OS_INTERRUPTMASK_PI_SI          | \
176                                                 OS_INTERRUPTMASK_PI_DI          | \
177                                                 OS_INTERRUPTMASK_PI_RSW         | \
178                                                 OS_INTERRUPTMASK_PI_ERROR       | \
179                                                 OS_INTERRUPTMASK_PI_VI          | \
180                                                 OS_INTERRUPTMASK_PI_PE_TOKEN    | \
181                                                 OS_INTERRUPTMASK_PI_PE_FINISH   | \
182                                                 OS_INTERRUPTMASK_PI_DEBUG       | \
183                                                 OS_INTERRUPTMASK_PI_HSP         | \
184                                                 OS_INTERRUPTMASK_PI_ACR           )
185 
186 __OSInterruptHandler __OSSetInterruptHandler(
187     __OSInterrupt         interrupt,
188     __OSInterruptHandler  handler
189 );
190 
191 __OSInterruptHandler __OSGetInterruptHandler(
192     __OSInterrupt         interrupt
193 );
194 
195 void __OSDispatchInterrupt(
196     __OSException         exception,
197     OSContext*            context);
198 
199 OSInterruptMask OSGetInterruptMask  ( void );
200 OSInterruptMask OSSetInterruptMask  ( OSInterruptMask mask );
201 OSInterruptMask __OSMaskInterrupts  ( OSInterruptMask mask );
202 OSInterruptMask __OSUnmaskInterrupts( OSInterruptMask mask );
203 
204 #ifdef  _DEBUG
205 extern u64 __OSSpuriousInterrupts;  // # of spurious interrupts Gekko has taken
206 #endif  // _DEBUG
207 
208 // The record of the last interrupt Gekko has taken except __OS_INTERRUPT_MEM_*.
209 extern volatile __OSInterrupt __OSLastInterrupt;        // One of __OS_INTERRUPT_*
210 extern volatile u32           __OSLastInterruptSrr0;    // SRR0 value at the interrupt
211 extern volatile OSTime        __OSLastInterruptTime;    // OSGetTime() value at the interrupt
212 
213 
214 /*-----------------------------------------------------------------------------*/
215 // ACR interrupt emulation for non-RVL target (tentative)
216 #ifndef HOLLYWOOD_REV
217 #define EMU_PI_ACRINT
218 #endif
219 
220 /*-----------------------------------------------------------------------------*/
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif  // __OSINTERRUPT_H__
227