source: mainline/kernel/arch/mips32/src/exception.c@ 0c61955

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0c61955 was 0c61955, checked in by Jakub Jermar <jakub@…>, 15 years ago

Print all registers in istate_decode().

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 * Copyright (c) 2003-2004 Jakub Jermar
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 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup mips32
30 * @{
31 */
32/** @file
33 */
34
35#include <arch/exception.h>
36#include <arch/interrupt.h>
37#include <arch/mm/tlb.h>
38#include <panic.h>
39#include <arch/cp0.h>
40#include <typedefs.h>
41#include <arch.h>
42#include <debug.h>
43#include <proc/thread.h>
44#include <print.h>
45#include <interrupt.h>
46#include <func.h>
47#include <ddi/irq.h>
48#include <arch/debugger.h>
49#include <symtab.h>
50
51static const char *exctable[] = {
52 "Interrupt",
53 "TLB Modified",
54 "TLB Invalid",
55 "TLB Invalid Store",
56 "Address Error - load/instr. fetch",
57 "Address Error - store",
58 "Bus Error - fetch instruction",
59 "Bus Error - data reference",
60 "Syscall",
61 "BreakPoint",
62 "Reserved Instruction",
63 "Coprocessor Unusable",
64 "Arithmetic Overflow",
65 "Trap",
66 "Virtual Coherency - instruction",
67 "Floating Point",
68 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
69 "WatchHi/WatchLo", /* 23 */
70 NULL, NULL, NULL, NULL, NULL, NULL, NULL,
71 "Virtual Coherency - data",
72};
73
74void istate_decode(istate_t *istate)
75{
76 printf("epc=%p\tsta=%p\tlo =%p\thi =%p\n",
77 istate->epc, istate->status, istate->lo, istate->hi);
78 printf("a0 =%p\ta1 =%p\ta2 =%p\ta3 =%p\n",
79 istate->a0, istate->a1, istate->a2, istate->a3);
80 printf("t0 =%p\tt1 =%p\tt2 =%p\tt3 =%p\n",
81 istate->t0, istate->t1, istate->t2, istate->t3);
82 printf("t4 =%p\tt5 =%p\tt6 =%p\tt7 =%p\n",
83 istate->t4, istate->t5, istate->t6, istate->t7);
84 printf("t8 =%p\tt9 =%p\tv0 =%p\tv1 =%p\n",
85 istate->t8, istate->t9, istate->v0, istate->v1);
86 printf("s0 =%p\ts1 =%p\ts2 =%p\ts3 =%p\n",
87 istate->s0, istate->s1, istate->s2, istate->s3);
88 printf("s4 =%p\ts5 =%p\ts6 =%p\ts7 =%p\n",
89 istate->s4, istate->s5, istate->s6, istate->s7);
90 printf("s8 =%p\tat =%p\tkt0=%p\tkt1=%p\n",
91 istate->s8, istate->at, istate->kt0, istate->kt1);
92 printf("sp =%p\tra =%p\tgp =%p\n",
93 istate->sp, istate->ra, istate->gp);
94}
95
96static void unhandled_exception(unsigned int n, istate_t *istate)
97{
98 fault_if_from_uspace(istate, "Unhandled exception %s.", exctable[n]);
99 panic_badtrap(istate, n, "Unhandled exception %s.", exctable[n]);
100}
101
102static void reserved_instr_exception(unsigned int n, istate_t *istate)
103{
104 if (*((uint32_t *) istate->epc) == 0x7c03e83b) {
105 ASSERT(THREAD);
106 istate->epc += 4;
107 istate->v1 = istate->kt1;
108 } else
109 unhandled_exception(n, istate);
110}
111
112static void breakpoint_exception(unsigned int n, istate_t *istate)
113{
114#ifdef CONFIG_DEBUG
115 debugger_bpoint(istate);
116#else
117 /* it is necessary to not re-execute BREAK instruction after
118 returning from Exception handler
119 (see page 138 in R4000 Manual for more information) */
120 istate->epc += 4;
121#endif
122}
123
124static void tlbmod_exception(unsigned int n, istate_t *istate)
125{
126 tlb_modified(istate);
127}
128
129static void tlbinv_exception(unsigned int n, istate_t *istate)
130{
131 tlb_invalid(istate);
132}
133
134#ifdef CONFIG_FPU_LAZY
135static void cpuns_exception(unsigned int n, istate_t *istate)
136{
137 if (cp0_cause_coperr(cp0_cause_read()) == fpu_cop_id)
138 scheduler_fpu_lazy_request();
139 else {
140 fault_if_from_uspace(istate,
141 "Unhandled Coprocessor Unusable Exception.");
142 panic_badtrap(istate, n,
143 "Unhandled Coprocessor Unusable Exception.");
144 }
145}
146#endif
147
148static void interrupt_exception(unsigned int n, istate_t *istate)
149{
150 /* Decode interrupt number and process the interrupt */
151 uint32_t cause = (cp0_cause_read() >> 8) & 0xff;
152
153 unsigned int i;
154 for (i = 0; i < 8; i++) {
155 if (cause & (1 << i)) {
156 irq_t *irq = irq_dispatch_and_lock(i);
157 if (irq) {
158 /*
159 * The IRQ handler was found.
160 */
161 irq->handler(irq);
162 irq_spinlock_unlock(&irq->lock, false);
163 } else {
164 /*
165 * Spurious interrupt.
166 */
167#ifdef CONFIG_DEBUG
168 printf("cpu%u: spurious interrupt (inum=%u)\n",
169 CPU->id, i);
170#endif
171 }
172 }
173 }
174}
175
176/** Handle syscall userspace call */
177static void syscall_exception(unsigned int n, istate_t *istate)
178{
179 fault_if_from_uspace(istate, "Syscall is handled through shortcut.");
180}
181
182void exception_init(void)
183{
184 unsigned int i;
185
186 /* Clear exception table */
187 for (i = 0; i < IVT_ITEMS; i++)
188 exc_register(i, "undef", false,
189 (iroutine_t) unhandled_exception);
190
191 exc_register(EXC_Bp, "bkpoint", true,
192 (iroutine_t) breakpoint_exception);
193 exc_register(EXC_RI, "resinstr", true,
194 (iroutine_t) reserved_instr_exception);
195 exc_register(EXC_Mod, "tlb_mod", true,
196 (iroutine_t) tlbmod_exception);
197 exc_register(EXC_TLBL, "tlbinvl", true,
198 (iroutine_t) tlbinv_exception);
199 exc_register(EXC_TLBS, "tlbinvl", true,
200 (iroutine_t) tlbinv_exception);
201 exc_register(EXC_Int, "interrupt", true,
202 (iroutine_t) interrupt_exception);
203
204#ifdef CONFIG_FPU_LAZY
205 exc_register(EXC_CpU, "cpunus", true,
206 (iroutine_t) cpuns_exception);
207#endif
208
209 exc_register(EXC_Sys, "syscall", true,
210 (iroutine_t) syscall_exception);
211}
212
213/** @}
214 */
Note: See TracBrowser for help on using the repository browser.