WIP: irq handler
[ppcskel.git] / exception.c
1 /*
2         BootMii - a Free Software replacement for the Nintendo/BroadOn bootloader.
3         Requires mini.
4
5 Copyright (C) 2008              Segher Boessenkool <segher@kernel.crashing.org>
6
7 # This code is licensed to you under the terms of the GNU GPL, version 2;
8 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
9 */
10
11 #include "bootmii_ppc.h"
12
13 #include "string.h"
14 #include "irq.h"
15 #include "hollywood.h"
16
17 extern char exception_2200_start, exception_2200_end;
18
19 void exception_handler(int exception)
20 {
21         u32 cookie = irq_kill();
22         // check if the exception was actually an external interrupt
23         if (exception == 0x500) {
24                 irq_handler();
25         }
26
27         // check if exception happened due to the decrementer
28         else if (exception == 0x900) {
29                 printf("\nDecrementer exception occured - who cares?\n");
30         }
31
32         else {
33                 u32 *x;
34                 u32 i;
35
36                 printf("\nException %04X occurred!\n", exception);
37
38                 x = (u32 *)0x80002000;
39
40                 printf("\n R0..R7    R8..R15  R16..R23  R24..R31\n");
41                 for (i = 0; i < 8; i++) {
42                         printf("%08x  %08x  %08x  %08x\n", x[0], x[8], x[16], x[24]);
43                         x++;
44                 }
45                 x = (u32 *)0x80002080;
46
47                 printf("\n CR/XER    LR/CTR  SRR0/SRR1 DAR/DSISR\n");
48                 for (i = 0; i < 2; i++) {
49                         printf("%08x  %08x  %08x  %08x\n", x[0], x[2], x[4], x[6]);
50                         x++;
51                 }
52
53                 // Hang.
54                 for (;;)
55                         ;
56         }
57
58         irq_restore(cookie);
59         _CPU_ISR_Enable(); //wtf
60 }
61
62 void exception_init(void)
63 {
64         u32 vector;
65         u32 len_2200;
66
67         for (vector = 0x100; vector < 0x2000; vector += 0x10) {
68                 u32 *insn = (u32 *)(0x80000000 + vector);
69
70                 insn[0] = 0xbc002000;                   // stmw 0,0x2000(0)
71                 insn[1] = 0x38600000 | (u32)vector;     // li 3,vector
72                 insn[2] = 0x48002202;                   // ba 0x2200
73                 insn[3] = 0;
74         }
75         sync_before_exec((void *)0x80000100, 0x1f00);
76
77         len_2200 = &exception_2200_end - &exception_2200_start;
78         memcpy((void *)0x80002200, &exception_2200_start, len_2200);
79         sync_before_exec((void *)0x80002200, len_2200);
80 }
81