root / prex-0.9.0 / bsp / hal / ppc / arch / trap.c @ 03e9c04a
History | View | Annotate | Download (4.43 KB)
1 |
/*-
|
---|---|
2 |
* Copyright (c) 2009, Kohsuke Ohtani
|
3 |
* All rights reserved.
|
4 |
*
|
5 |
* Redistribution and use in source and binary forms, with or without
|
6 |
* modification, are permitted provided that the following conditions
|
7 |
* are met:
|
8 |
* 1. Redistributions of source code must retain the above copyright
|
9 |
* notice, this list of conditions and the following disclaimer.
|
10 |
* 2. Redistributions in binary form must reproduce the above copyright
|
11 |
* notice, this list of conditions and the following disclaimer in the
|
12 |
* documentation and/or other materials provided with the distribution.
|
13 |
* 3. Neither the name of the author nor the names of any co-contributors
|
14 |
* may be used to endorse or promote products derived from this software
|
15 |
* without specific prior written permission.
|
16 |
*
|
17 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
18 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
19 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
20 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
21 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
22 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
23 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
24 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
26 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
27 |
* SUCH DAMAGE.
|
28 |
*/
|
29 |
|
30 |
/*
|
31 |
* trap.c - called from the trap handler when a processor trap occurs.
|
32 |
*/
|
33 |
|
34 |
#include <kernel.h> |
35 |
#include <task.h> |
36 |
#include <hal.h> |
37 |
#include <exception.h> |
38 |
#include <cpu.h> |
39 |
#include <trap.h> |
40 |
#include <cpufunc.h> |
41 |
#include <context.h> |
42 |
#include <locore.h> |
43 |
|
44 |
#include <sys/signal.h> |
45 |
|
46 |
#ifdef DEBUG
|
47 |
/*
|
48 |
* Trap name.
|
49 |
*/
|
50 |
static const char *const trap_name[] = { |
51 |
"", /* 0 */ |
52 |
"System reset", /* 1 */ |
53 |
"Machine check", /* 2 */ |
54 |
"DSI", /* 3 */ |
55 |
"ISI", /* 4 */ |
56 |
"External interrupt", /* 5 */ |
57 |
"Alignment", /* 6 */ |
58 |
"Program", /* 7 */ |
59 |
"Floating point unavailable", /* 8 */ |
60 |
"Decrementer", /* 9 */ |
61 |
"Reserved", /* a */ |
62 |
"Reserved", /* b */ |
63 |
"System call", /* c */ |
64 |
"Trace", /* d */ |
65 |
"Floating point assist", /* e */ |
66 |
}; |
67 |
#define MAXTRAP (sizeof(trap_name) / sizeof(void *) - 1) |
68 |
#endif /* DEBUG */ |
69 |
|
70 |
/*
|
71 |
* Exception mapping table.
|
72 |
* PPC exception is translated to the architecture
|
73 |
* independent exception code.
|
74 |
*/
|
75 |
static const int exception_map[] = { |
76 |
SIGILL, |
77 |
SIGILL, |
78 |
SIGSEGV, /* machine check */
|
79 |
SIGSEGV, /* address error (store) */
|
80 |
SIGBUS, /* instruction bus error */
|
81 |
SIGINT, /* external interrupt */
|
82 |
SIGBUS, /* alingment */
|
83 |
SIGTRAP, /* breakpoint trap */
|
84 |
SIGFPE, /* fpu unavail */
|
85 |
SIGALRM, /* decrementer */
|
86 |
SIGILL, /* reserved */
|
87 |
SIGILL, /* reserved */
|
88 |
SIGCHLD, /* syscall */
|
89 |
SIGTRAP, /* debug trap */
|
90 |
SIGFPE, /* fp assist */
|
91 |
}; |
92 |
|
93 |
/*
|
94 |
* Trap handler
|
95 |
* Invoke the exception handler if it is needed.
|
96 |
*/
|
97 |
void
|
98 |
trap_handler(struct cpu_regs *regs)
|
99 |
{ |
100 |
uint32_t trap_no = regs->trap_no; |
101 |
|
102 |
#ifdef DEBUG
|
103 |
printf("============================\n");
|
104 |
printf("Trap %x: %s\n", trap_no, trap_name[trap_no]);
|
105 |
printf("============================\n");
|
106 |
|
107 |
trap_dump(regs); |
108 |
for (;;) ;
|
109 |
#endif
|
110 |
if ((regs->srr1 & MSR_PR) != MSR_PR)
|
111 |
panic("Kernel exception");
|
112 |
|
113 |
exception_mark(exception_map[trap_no]); |
114 |
exception_deliver(); |
115 |
} |
116 |
|
117 |
#ifdef DEBUG
|
118 |
void
|
119 |
trap_dump(struct cpu_regs *r)
|
120 |
{ |
121 |
|
122 |
printf("Trap frame %x\n", r);
|
123 |
printf(" r0 %08x r1 %08x r2 %08x r3 %08x r4 %08x r5 %08x\n",
|
124 |
r->gr[0], r->gr[1], r->gr[2], r->gr[3], r->gr[4], r->gr[5]); |
125 |
printf(" r6 %08x r7 %08x r8 %08x r9 %08x r10 %08x r11 %08x\n",
|
126 |
r->gr[6], r->gr[7], r->gr[8], r->gr[9], r->gr[10], r->gr[11]); |
127 |
printf(" r12 %08x r13 %08x r14 %08x r15 %08x r16 %08x r17 %08x\n",
|
128 |
r->gr[12], r->gr[13], r->gr[14], r->gr[15], r->gr[16], r->gr[17]); |
129 |
printf(" r18 %08x r19 %08x r20 %08x r21 %08x r22 %08x r23 %08x\n",
|
130 |
r->gr[18], r->gr[19], r->gr[20], r->gr[21], r->gr[22], r->gr[23]); |
131 |
printf(" r24 %08x r25 %08x r26 %08x r27 %08x r28 %08x r29 %08x\n",
|
132 |
r->gr[24], r->gr[25], r->gr[26], r->gr[27], r->gr[28], r->gr[29]); |
133 |
printf(" r30 %08x r31 %08x lr %08x cr %08x xer %08x ctr %08x\n",
|
134 |
r->gr[30], r->gr[31], r->lr, r->cr, r->xer, r->ctr); |
135 |
printf(" srr0 %08x srr1 %08x\n", r->srr0, r->srr1);
|
136 |
|
137 |
printf(" >> interrupt is %s\n",
|
138 |
(r->srr1 & MSR_EE) ? "enabled" : "disabled"); |
139 |
|
140 |
printf(" >> task=%s\n", curtask->name);
|
141 |
} |
142 |
#endif /* !DEBUG */ |