added (empty) handling for decrementer exception
[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
16 extern char exception_2200_start, exception_2200_end;
17
18 void exception_handler(int exception)
19 {
20         // check if the exception was actually an interrupt
21         if (exception == 0x500) {
22                 u32 cookie;
23
24                 _CPU_ISR_Disable(cookie);
25                 printf("\nInterrupt occured ;-) Which one? -> ");
26                 u32 enabled = read32(BW_PI_IRQMASK);
27                 u32 flags = read32(BW_PI_IRQFLAG);
28                 flags = flags & enabled;
29                 if (flags & (1<<1)) { // RESET
30                         write32(BW_PI_IRQFLAG, 1<<1);
31                         printf("RESET :)\n");
32                 }
33                 if (flags & (1<<14)) { // Hollywood-PIC IRQ
34                         write32(BW_PI_IRQFLAG, 1<<14);
35                         write32(HW_PPCIRQFLAG, ~0); // dirty
36                         printf("Hollywood-PIC :)\n");
37                 }
38                 _CPU_ISR_Restore(cookie);
39
40                 return;
41         }
42
43         // check if exception happened due to the decrementer
44         if (exception == 0x900) {
45                 printf("\nDecrementer exception occured - who cares?\n");
46                 return;
47         }
48
49         u32 *x;
50         u32 i;
51
52         printf("\nException %04x occurred!\n", exception);
53
54         x = (u32 *)0x80002000;
55
56         printf("\n R0..R7    R8..R15  R16..R23  R24..R31\n");
57         for (i = 0; i < 8; i++) {
58                 printf("%08x  %08x  %08x  %08x\n", x[0], x[8], x[16], x[24]);
59                 x++;
60         }
61         x = (u32 *)0x80002080;
62
63         printf("\n CR/XER    LR/CTR  SRR0/SRR1 DAR/DSISR\n");
64         for (i = 0; i < 2; i++) {
65                 printf("%08x  %08x  %08x  %08x\n", x[0], x[2], x[4], x[6]);
66                 x++;
67         }
68
69         // Hang.
70         for (;;)
71                 ;
72 }
73
74 void exception_init(void)
75 {
76         u32 vector;
77         u32 len_2200;
78
79         for (vector = 0x100; vector < 0x2000; vector += 0x10) {
80                 u32 *insn = (u32 *)(0x80000000 + vector);
81
82                 insn[0] = 0xbc002000;                   // stmw 0,0x2000(0)
83                 insn[1] = 0x38600000 | (u32)vector;     // li 3,vector
84                 insn[2] = 0x48002202;                   // ba 0x2200
85                 insn[3] = 0;
86         }
87         sync_before_exec((void *)0x80000100, 0x1f00);
88
89         len_2200 = &exception_2200_end - &exception_2200_start;
90         memcpy((void *)0x80002200, &exception_2200_start, len_2200);
91         sync_before_exec((void *)0x80002200, len_2200);
92 }
93