lsw: JPN fix
[savezelda.git] / loader / exception.c
1 // Copyright 2008-2009  Segher Boessenkool  <segher@kernel.crashing.org>
2 // This code is licensed to you under the terms of the GNU GPL, version 2;
3 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
4
5 #include "loader.h"
6
7 extern char exception_2200_start, exception_2200_end;
8
9 void exception_handler(int exception)
10 {
11         u32 *x;
12         u32 i;
13
14         printf("\nException %04x occurred!\n", exception);
15
16         x = (u32 *)0x80002000;
17
18         printf("\n R0..R7    R8..R15  R16..R23  R24..R31\n");
19         for (i = 0; i < 8; i++) {
20                 printf("%08x  %08x  %08x  %08x\n", x[0], x[8], x[16], x[24]);
21                 x++;
22         }
23         x += 24;
24
25         printf("\n CR/XER    LR/CTR  SRR0/SRR1 DAR/DSISR\n");
26         for (i = 0; i < 2; i++) {
27                 printf("%08x  %08x  %08x  %08x\n", x[0], x[2], x[4], x[6]);
28                 x++;
29         }
30
31         // Hang.
32         for (;;)
33                 ;
34 }
35
36 void exception_init(void)
37 {
38         u32 vector;
39         u32 len_2200;
40
41         for (vector = 0x100; vector < 0x2000; vector += 0x10) {
42                 u32 *insn = (u32 *)(0x80000000 + vector);
43
44                 insn[0] = 0xbc002000;                   // stmw 0,0x2000(0)
45                 insn[1] = 0x38600000 | (u32)vector;     // li 3,vector
46                 insn[2] = 0x48002202;                   // ba 0x2200
47                 insn[3] = 0;
48         }
49         sync_before_exec((void *)0x80000100, 0x1f00);
50
51         len_2200 = &exception_2200_end - &exception_2200_start;
52         memcpy((void *)0x80002200, &exception_2200_start, len_2200);
53         sync_before_exec((void *)0x80002200, len_2200);
54 }