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