/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/fps2bios/kernel/eeload/eeirq.c
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/fps2bios/kernel/eeload/eeirq.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (10 years, 10 months ago) by william
File MIME type: text/plain
File size: 6624 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 // EE core interrupt and exception handlers
2 // most functions here can only use $at, $k0, and $k1
3 // [made by] [RO]man, zerofrog
4
5 #include "eekernel.h"
6 #include "eeirq.h"
7
8
9 #define LOAD_KERNELSTACK \
10 "lui $sp, %hi(g_kernelstackend)\n" \
11 "addiu $sp, %lo(g_kernelstackend)\n"
12
13 __asm__(".org 0x0000");
14
15 __asm__(".set noreorder");
16 void CpuException0() {
17 __asm__ (
18 "lui $26, %hi(SavedT9)\n"
19 "sd $25, %lo(SavedT9)($26)\n"
20
21 "mfc0 $25, $13\n"
22 "andi $25, 0x7C\n"
23 "lui $26, %hi(VCRTable)\n"
24 "addu $26, $25\n"
25 "lw $26, %lo(VCRTable)($26)\n"
26
27 "lui $25, %hi(SavedT9)\n"
28 "jr $26\n"
29 "ld $25, %lo(SavedT9)($25)\n"
30 );
31 }
32
33 __asm__(".org 0x0180");
34
35 __asm__(".set noreorder");
36 void CpuException() {
37 __asm__ (
38 "lui $26, %hi(SavedT9)\n"
39 "sd $25, %lo(SavedT9)($26)\n"
40
41 "mfc0 $25, $13\n"
42 "andi $25, 0x7C\n"
43 "lui $26, %hi(VCRTable)\n"
44 "addu $26, $25\n"
45 "lw $26, %lo(VCRTable)($26)\n"
46
47 "lui $25, %hi(SavedT9)\n"
48 "jr $26\n"
49 "ld $25, %lo(SavedT9)($25)\n"
50 );
51 }
52
53 __asm__(".org 0x0200");
54
55 __asm__(".set noreorder");
56 __asm__(".set noat");
57 void CpuException2() {
58 __asm__ (
59 "lui $26, %hi(SavedSP)\n"
60 "sq $sp, %lo(SavedSP)($26)\n"
61 "lui $26, %hi(SavedRA)\n"
62 "sq $31, %lo(SavedRA)($26)\n"
63 "lui $26, %hi(SavedAT)\n"
64 "sq $1, %lo(SavedAT)($26)\n"
65
66 "mfc0 $1, $13\n"
67 "mfc0 $26, $14\n"
68 "and $1, $26\n"
69 "srl $1, 8\n"
70 "andi $1, 0xFF\n"
71
72 "plzcw $26, $1\n"
73 "andi $26, 0xFF\n"
74 "ori $1, $0, 0x1E\n"
75 "subu $1, $26\n"
76 "sll $1, 2\n"
77 "lui $26, %hi(VIntTable)\n"
78 "addu $26, $25\n"
79 "lw $26, %lo(VIntTable)($26)\n"
80 "jr $26\n"
81 "nop\n"
82 );
83 }
84
85 extern char call_used_regs[];
86 extern char fixed_regs[];
87
88 __asm__(".org 0x0280");
89 __asm__(".set noreorder");
90
91 void SyscException()
92 {
93 const register int code __asm__("$3"); // $v1
94
95 if (code < 0) {
96 __asm__(
97 "addiu $sp, -0x10\n"
98 "sw $31, 0($sp)\n"
99 "mfc0 $26, $14\n"
100 "addiu $26, 4\n"
101 "sw $26, 4($sp)\n"
102 "mtc0 $26, $14\n"
103 "sync\n");
104
105 table_SYSCALL[-code]();
106
107 __asm__(
108 "lw $26, 4($sp)\n"
109 "lw $31, 0($sp)\n"
110 "addiu $sp, 0x10\n"
111 "mtc0 $26, $14\n"
112 "sync\n"
113 "eret\n"
114 "nop\n");
115 }
116
117 if (code == 0x7c) {
118 _Deci2Call();
119 return;
120 }
121
122 __asm__(
123 "lui $26, %hi(SavedSP)\n"
124 "sq $sp, %lo(SavedSP)($26)\n"
125 "lui $26, %hi(SavedRA)\n"
126 "sq $31, %lo(SavedRA)($26)\n"
127 "lui $26, %hi(SavedAT)\n"
128 "sq $1, %lo(SavedAT)($26)\n"
129
130 "mfc0 $1, $12\n"
131 "addiu $26, $0, 0xFFE4\n"
132 "and $1, $26\n"
133 "mtc0 $1, $12\n"
134 "sync\n"
135
136 "move $26, $sp\n"
137 LOAD_KERNELSTACK
138 "addiu $sp, -0x10\n"
139 "sw $31, 0($sp)\n"
140 "sw $26, 4($sp)\n"
141 "mfc0 $26, $14\n"
142 "addiu $26, 4\n"
143 "sw $26, 8($sp)\n"
144 "mtc0 $26, $14\n"
145 "sync\n");
146
147 table_SYSCALL[code]();
148
149 __asm__(
150 "lw $26, 8($sp)\n"
151 "lw $31, 0($sp)\n"
152 "lw $sp, 4($sp)\n"
153 "mtc0 $26, $14\n"
154 "sync\n"
155
156 "mfc0 $26, $12\n"
157 "ori $26, 0x13\n"
158 "mtc0 $26, $12\n"
159 "sync\n"
160 "eret\n"
161 "nop\n");
162 }
163
164 void _Deci2Call() {
165 __puts("_Deci2Call called\n");
166 }
167
168 void __ThreadHandler();
169
170 void INTCException() {
171 u32 code;
172 u32 temp;
173
174 code = INTC_STAT & INTC_MASK;
175 if (code & 0xC0) {
176 int VpuStat;
177
178 __asm__("cfc2 %0, $29\n" : "=r"(VpuStat) : );
179 if (VpuStat & 0x202) {
180 __asm__(
181 ".set noat\n"
182 "lui $26, %hi(SavedAT)\n"
183 "lq $1, %lo(SavedAT)($26)\n"
184 ".set at\n");
185 __exception();
186 }
187 }
188 __asm__ (
189 "mfc0 $26, $14\n"
190 "li $27, 0xFFFFFFE4\n"
191 "and $26, $27\n"
192 "mtc0 $26, $14\n"
193 "sync\n"
194
195 LOAD_KERNELSTACK
196 "addiu $sp, -0x10\n"
197 "mfc0 $26, $14\n"
198 "sw $26, 0($sp)\n"
199 );
200 saveContext2();
201
202 __asm__ (
203 "plzcw %0, %1"
204 : "=r"(temp) : "r"(code)
205 );
206 temp = 0x1e - (temp & 0xff);
207 INTC_STAT = 1 << temp;
208 threadStatus = 0;
209
210 INTCTable[temp](temp);
211
212 restoreContext2();
213
214 __asm__ (
215 ".set noat\n"
216 "lw $26, 0($sp)\n"
217 "mtc0 $26, $14\n"
218 "lui $26, %hi(SavedSP)\n"
219 "lq $sp, %lo(SavedSP)($26)\n"
220 "lui $26, %hi(SavedRA)\n"
221 "lq $31, %lo(SavedRA)($26)\n"
222 "lui $26, %hi(SavedAT)\n"
223 "lq $1, %lo(SavedAT)($26)\n"
224 ".set at\n"
225 );
226
227 if (!threadStatus) {
228 __asm__ (
229 "mfc0 $26, $12\n"
230 "ori $26, 0x13\n"
231 "mtc0 $26, $12\n"
232 "sync\n"
233 "eret\n"
234 );
235 }
236 __asm__(LOAD_KERNELSTACK);
237 threadStatus = 0;
238
239 __ThreadHandler();
240 }
241
242 ////////////////////////////////////////////////////////////////////
243 //800004C0
244 ////////////////////////////////////////////////////////////////////
245 void DMACException() {
246 unsigned int code;
247 unsigned int temp;
248
249 code = (DMAC_STAT >> 16) | 0x8000;
250 code&= DMAC_STAT & 0xFFFF;
251 if (code & 0x80) {
252 //__printf("%s: code & 0x80\n", __FUNCTION__);
253 __asm__(
254 ".set noat\n"
255 "lui $26, %hi(SavedAT)\n"
256 "lq $1, %lo(SavedAT)($26)\n"
257 ".set at\n");
258 __exception1();
259 }
260 __asm__ (
261 "mfc0 $26, $14\n"
262 "li $27, 0xFFFFFFE4\n"
263 "and $26, $27\n"
264 "mtc0 $26, $14\n"
265 "sync\n"
266
267 LOAD_KERNELSTACK
268 "addiu $sp, -0x10\n"
269 "mfc0 $26, $14\n"
270 "sw $26, 0($sp)\n"
271 );
272 saveContext2();
273
274 __asm__ (
275 "plzcw %0, %1"
276 : "=r"(temp) : "r"(code)
277 );
278 temp = 0x1e - (temp & 0xff);
279 DMAC_STAT = 1 << temp;
280 threadStatus = 0;
281
282 DMACTable[temp](temp);
283
284 restoreContext2();
285
286 __asm__ (
287 ".set noat\n"
288 "lw $26, 0($sp)\n"
289 "mtc0 $26, $14\n"
290 "lui $26, %hi(SavedSP)\n"
291 "lq $sp, %lo(SavedSP)($26)\n"
292 "lui $26, %hi(SavedRA)\n"
293 "lq $31, %lo(SavedRA)($26)\n"
294 "lui $26, %hi(SavedAT)\n"
295 "lq $1, %lo(SavedAT)($26)\n"
296 ".set at\n"
297 );
298
299 if (!threadStatus) {
300 __asm__ (
301 "mfc0 $26, $12\n"
302 "ori $26, 0x13\n"
303 "mtc0 $26, $12\n"
304 "sync\n"
305 "eret\n"
306 );
307 }
308 __asm__(LOAD_KERNELSTACK);
309 threadStatus = 0;
310
311 __ThreadHandler();
312 }
313
314 ////////////////////////////////////////////////////////////////////
315 //80000600
316 ////////////////////////////////////////////////////////////////////
317 void TIMERException()
318 {
319
320 }
321
322 ////////////////////////////////////////////////////////////////////
323 //80000700
324 ////////////////////////////////////////////////////////////////////
325 void setINTCHandler(int n, void (*phandler)(int))
326 {
327 INTCTable[n] = phandler;
328 }
329
330 ////////////////////////////////////////////////////////////////////
331 //80000780
332 ////////////////////////////////////////////////////////////////////
333 void setDMACHandler(int n, void (*phandler)(int))
334 {
335 DMACTable[n] = phandler;
336 }

  ViewVC Help
Powered by ViewVC 1.1.22