1 | /* $Id$ */ |
---|
2 | |
---|
3 | /* |
---|
4 | * Authorship |
---|
5 | * ---------- |
---|
6 | * This software was created by |
---|
7 | * Till Straumann <strauman@slac.stanford.edu>, 5/2002, |
---|
8 | * Stanford Linear Accelerator Center, Stanford University. |
---|
9 | * |
---|
10 | * Acknowledgement of sponsorship |
---|
11 | * ------------------------------ |
---|
12 | * This software was produced by |
---|
13 | * the Stanford Linear Accelerator Center, Stanford University, |
---|
14 | * under Contract DE-AC03-76SFO0515 with the Department of Energy. |
---|
15 | * |
---|
16 | * Government disclaimer of liability |
---|
17 | * ---------------------------------- |
---|
18 | * Neither the United States nor the United States Department of Energy, |
---|
19 | * nor any of their employees, makes any warranty, express or implied, or |
---|
20 | * assumes any legal liability or responsibility for the accuracy, |
---|
21 | * completeness, or usefulness of any data, apparatus, product, or process |
---|
22 | * disclosed, or represents that its use would not infringe privately owned |
---|
23 | * rights. |
---|
24 | * |
---|
25 | * Stanford disclaimer of liability |
---|
26 | * -------------------------------- |
---|
27 | * Stanford University makes no representations or warranties, express or |
---|
28 | * implied, nor assumes any liability for the use of this software. |
---|
29 | * |
---|
30 | * Stanford disclaimer of copyright |
---|
31 | * -------------------------------- |
---|
32 | * Stanford University, owner of the copyright, hereby disclaims its |
---|
33 | * copyright and all other rights in this software. Hence, anyone may |
---|
34 | * freely use it for any purpose without restriction. |
---|
35 | * |
---|
36 | * Maintenance of notices |
---|
37 | * ---------------------- |
---|
38 | * In the interest of clarity regarding the origin and status of this |
---|
39 | * SLAC software, this and all the preceding Stanford University notices |
---|
40 | * are to remain affixed to any copy or derivative of this software made |
---|
41 | * or distributed by the recipient and are to be affixed to any copy of |
---|
42 | * software made or distributed by the recipient that contains a copy or |
---|
43 | * derivative of this software. |
---|
44 | * |
---|
45 | * ------------------ SLAC Software Notices, Set 4 OTT.002a, 2004 FEB 03 |
---|
46 | */ |
---|
47 | /* Copyright : |
---|
48 | * (C) S. Kate Feng <feng1@bnl.gov> 4/2004 modified it for MVME5500 |
---|
49 | */ |
---|
50 | |
---|
51 | #include <bsp.h> |
---|
52 | #include <bsp/vectors.h> |
---|
53 | #include <libcpu/raw_exception.h> |
---|
54 | #include <libcpu/spr.h> |
---|
55 | #include <bsp/pci.h> |
---|
56 | #include <rtems/bspIo.h> |
---|
57 | |
---|
58 | #include <bsp/bspException.h> |
---|
59 | |
---|
60 | #define SRR1_TEA_EXC (1<<(31-13)) |
---|
61 | #define SRR1_MCP_EXC (1<<(31-12)) |
---|
62 | |
---|
63 | void |
---|
64 | BSP_printStackTrace(); |
---|
65 | |
---|
66 | |
---|
67 | void |
---|
68 | rtemsReboot(void); |
---|
69 | |
---|
70 | static volatile BSP_ExceptionExtension BSP_exceptionExtension = 0; |
---|
71 | |
---|
72 | BSP_ExceptionExtension |
---|
73 | BSP_exceptionHandlerInstall(BSP_ExceptionExtension e) |
---|
74 | { |
---|
75 | volatile BSP_ExceptionExtension test; |
---|
76 | if ( RTEMS_SUCCESSFUL != rtems_task_variable_get(RTEMS_SELF, (void*)&BSP_exceptionExtension, (void**)&test) ) { |
---|
77 | /* not yet added */ |
---|
78 | rtems_task_variable_add(RTEMS_SELF, (void*)&BSP_exceptionExtension, 0); |
---|
79 | } |
---|
80 | test = BSP_exceptionExtension; |
---|
81 | BSP_exceptionExtension = e; |
---|
82 | return test; |
---|
83 | } |
---|
84 | |
---|
85 | void |
---|
86 | BSP_exceptionHandler(BSP_Exception_frame* excPtr) |
---|
87 | { |
---|
88 | uint32_t note; |
---|
89 | BSP_ExceptionExtension ext=0; |
---|
90 | rtems_id id=0; |
---|
91 | int recoverable = 0; |
---|
92 | char *fmt="Uhuuuh, Exception %d in unknown task???\n"; |
---|
93 | int quiet=0; |
---|
94 | |
---|
95 | if (!quiet) printk("In BSP_exceptionHandler()\n"); |
---|
96 | /* If we are in interrupt context, we are in trouble - skip the user |
---|
97 | * hook and panic |
---|
98 | */ |
---|
99 | if (rtems_interrupt_is_in_progress()) { |
---|
100 | fmt="Aieeh, Exception %d in interrupt handler\n"; |
---|
101 | } else if ( !_Thread_Executing) { |
---|
102 | fmt="Aieeh, Exception %d in initialization code\n"; |
---|
103 | } else { |
---|
104 | /* retrieve the notepad which possibly holds an extention pointer */ |
---|
105 | if (RTEMS_SUCCESSFUL==rtems_task_ident(RTEMS_SELF,RTEMS_LOCAL,&id) && |
---|
106 | #if 0 |
---|
107 | /* Must not use a notepad due to unknown initial value (notepad memory is allocated from the |
---|
108 | * workspace)! |
---|
109 | */ |
---|
110 | RTEMS_SUCCESSFUL==rtems_task_get_note(id, BSP_EXCEPTION_NOTEPAD, ¬e) |
---|
111 | #else |
---|
112 | RTEMS_SUCCESSFUL==rtems_task_variable_get(id, (void*)&BSP_exceptionExtension, (void**)¬e) |
---|
113 | #endif |
---|
114 | ) { |
---|
115 | ext = (BSP_ExceptionExtension)note; |
---|
116 | if (ext) |
---|
117 | quiet=ext->quiet; |
---|
118 | if (!quiet) { |
---|
119 | printk("Task (Id 0x%08x) got ",id); |
---|
120 | } |
---|
121 | fmt="exception %d\n"; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr,ext,0)) { |
---|
126 | /* they did all the work and want us to do nothing! */ |
---|
127 | printk("they did all the work and want us to do nothing!\n"); |
---|
128 | return; |
---|
129 | } |
---|
130 | |
---|
131 | if (!quiet) { |
---|
132 | /* message about exception */ |
---|
133 | printk(fmt, excPtr->_EXC_number); |
---|
134 | /* register dump */ |
---|
135 | printk("\t Next PC or Address of fault = %x, ", excPtr->EXC_SRR0); |
---|
136 | printk("Mvme5500 Saved MSR = %x\n", excPtr->EXC_SRR1); |
---|
137 | printk("\t R0 = %08x", excPtr->GPR0); |
---|
138 | printk(" R1 = %08x", excPtr->GPR1); |
---|
139 | printk(" R2 = %08x", excPtr->GPR2); |
---|
140 | printk(" R3 = %08x\n", excPtr->GPR3); |
---|
141 | printk("\t R4 = %08x", excPtr->GPR4); |
---|
142 | printk(" R5 = %08x", excPtr->GPR5); |
---|
143 | printk(" R6 = %08x", excPtr->GPR6); |
---|
144 | printk(" R7 = %08x\n", excPtr->GPR7); |
---|
145 | printk("\t R8 = %08x", excPtr->GPR8); |
---|
146 | printk(" R9 = %08x", excPtr->GPR9); |
---|
147 | printk(" R10 = %08x", excPtr->GPR10); |
---|
148 | printk(" R11 = %08x\n", excPtr->GPR11); |
---|
149 | printk("\t R12 = %08x", excPtr->GPR12); |
---|
150 | printk(" R13 = %08x", excPtr->GPR13); |
---|
151 | printk(" R14 = %08x", excPtr->GPR14); |
---|
152 | printk(" R15 = %08x\n", excPtr->GPR15); |
---|
153 | printk("\t R16 = %08x", excPtr->GPR16); |
---|
154 | printk(" R17 = %08x", excPtr->GPR17); |
---|
155 | printk(" R18 = %08x", excPtr->GPR18); |
---|
156 | printk(" R19 = %08x\n", excPtr->GPR19); |
---|
157 | printk("\t R20 = %08x", excPtr->GPR20); |
---|
158 | printk(" R21 = %08x", excPtr->GPR21); |
---|
159 | printk(" R22 = %08x", excPtr->GPR22); |
---|
160 | printk(" R23 = %08x\n", excPtr->GPR23); |
---|
161 | printk("\t R24 = %08x", excPtr->GPR24); |
---|
162 | printk(" R25 = %08x", excPtr->GPR25); |
---|
163 | printk(" R26 = %08x", excPtr->GPR26); |
---|
164 | printk(" R27 = %08x\n", excPtr->GPR27); |
---|
165 | printk("\t R28 = %08x", excPtr->GPR28); |
---|
166 | printk(" R29 = %08x", excPtr->GPR29); |
---|
167 | printk(" R30 = %08x", excPtr->GPR30); |
---|
168 | printk(" R31 = %08x\n", excPtr->GPR31); |
---|
169 | printk("\t CR = %08x\n", excPtr->EXC_CR); |
---|
170 | printk("\t CTR = %08x\n", excPtr->EXC_CTR); |
---|
171 | printk("\t XER = %08x\n", excPtr->EXC_XER); |
---|
172 | printk("\t LR = %08x\n", excPtr->EXC_LR); |
---|
173 | printk("\t DAR = %08x\n", excPtr->EXC_DAR); |
---|
174 | |
---|
175 | BSP_printStackTrace(excPtr); |
---|
176 | } |
---|
177 | |
---|
178 | if (ASM_MACH_VECTOR == excPtr->_EXC_number) { |
---|
179 | /* ollah , we got a machine check - this could either |
---|
180 | * be a TEA, MCP or internal; let's see and provide more info |
---|
181 | */ |
---|
182 | if (!quiet) |
---|
183 | printk("Machine check; reason:"); |
---|
184 | if ( ! (excPtr->EXC_SRR1 & (SRR1_TEA_EXC | SRR1_MCP_EXC)) ) { |
---|
185 | if (!quiet) |
---|
186 | printk("SRR1\n"); |
---|
187 | } else { |
---|
188 | if (excPtr->EXC_SRR1 & (SRR1_TEA_EXC)) { |
---|
189 | if (!quiet) |
---|
190 | printk(" TEA"); |
---|
191 | } |
---|
192 | if (excPtr->EXC_SRR1 & (SRR1_MCP_EXC)) { |
---|
193 | unsigned long gerr; |
---|
194 | |
---|
195 | if (!quiet) printk(" MCP\n"); |
---|
196 | |
---|
197 | /* it's MCP; gather info from the host bridge */ |
---|
198 | gerr=_BSP_clear_hostbridge_errors(0,0); |
---|
199 | if (gerr&0x80000000) printk("GT64260 Parity error\n"); |
---|
200 | if (gerr&0x40000000) printk("GT64260 SysErr\n"); |
---|
201 | if ((!quiet) && (!gerr)) printk("GT64260 host bridge seems OK\n"); |
---|
202 | } |
---|
203 | } |
---|
204 | } else if (ASM_DEC_VECTOR == excPtr->_EXC_number) { |
---|
205 | recoverable = 1; |
---|
206 | } else if (ASM_SYS_VECTOR == excPtr->_EXC_number) { |
---|
207 | #ifdef TEST_RAW_EXCEPTION_CODE |
---|
208 | recoverable = 1; |
---|
209 | #else |
---|
210 | recoverable = 0; |
---|
211 | #endif |
---|
212 | } |
---|
213 | |
---|
214 | /* call them for a second time giving a chance to intercept |
---|
215 | * the task_suspend |
---|
216 | */ |
---|
217 | if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr, ext, 1)) |
---|
218 | return; |
---|
219 | |
---|
220 | if (!recoverable) { |
---|
221 | if (id) { |
---|
222 | /* if there's a highlevel hook, install it */ |
---|
223 | if (ext && ext->highlevelHook) { |
---|
224 | excPtr->EXC_SRR0 = (uint32_t)ext->highlevelHook; |
---|
225 | excPtr->GPR3 = (uint32_t)ext; |
---|
226 | return; |
---|
227 | } |
---|
228 | if (excPtr->EXC_SRR1 & MSR_FP) { |
---|
229 | /* thread dispatching is _not_ disabled at this point; hence |
---|
230 | * we must make sure we have the FPU enabled... |
---|
231 | */ |
---|
232 | _write_MSR( _read_MSR() | MSR_FP ); |
---|
233 | __asm__ __volatile__("isync"); |
---|
234 | } |
---|
235 | printk("unrecoverable exception!!! task %08x suspended\n",id); |
---|
236 | rtems_task_suspend(id); |
---|
237 | } else { |
---|
238 | printk("PANIC, rebooting...\n"); |
---|
239 | rtemsReboot(); |
---|
240 | } |
---|
241 | } |
---|
242 | } |
---|