1 | /* $Id$ */ |
---|
2 | |
---|
3 | /* Copyright : |
---|
4 | * (C) Author: Till Straumann <strauman@slac.stanford.edu>, 2002/5 |
---|
5 | * (C) S. Kate Feng <feng1@bnl.gov> 4/2004 modified it for MVME5500 |
---|
6 | */ |
---|
7 | |
---|
8 | #include <bsp.h> |
---|
9 | #include <bsp/vectors.h> |
---|
10 | #include <libcpu/raw_exception.h> |
---|
11 | #include <libcpu/spr.h> |
---|
12 | #include <bsp/pci.h> |
---|
13 | #include <rtems/bspIo.h> |
---|
14 | |
---|
15 | #include <bsp/bspException.h> |
---|
16 | |
---|
17 | #define SRR1_TEA_EXC (1<<(31-13)) |
---|
18 | #define SRR1_MCP_EXC (1<<(31-12)) |
---|
19 | |
---|
20 | void |
---|
21 | BSP_printStackTrace(); |
---|
22 | |
---|
23 | |
---|
24 | void |
---|
25 | rtemsReboot(void); |
---|
26 | |
---|
27 | static volatile BSP_ExceptionExtension BSP_exceptionExtension = 0; |
---|
28 | |
---|
29 | BSP_ExceptionExtension |
---|
30 | BSP_exceptionHandlerInstall(BSP_ExceptionExtension e) |
---|
31 | { |
---|
32 | volatile BSP_ExceptionExtension test; |
---|
33 | if ( RTEMS_SUCCESSFUL != rtems_task_variable_get(RTEMS_SELF, (void*)&BSP_exceptionExtension, (void**)&test) ) { |
---|
34 | /* not yet added */ |
---|
35 | rtems_task_variable_add(RTEMS_SELF, (void*)&BSP_exceptionExtension, 0); |
---|
36 | } |
---|
37 | test = BSP_exceptionExtension; |
---|
38 | BSP_exceptionExtension = e; |
---|
39 | return test; |
---|
40 | } |
---|
41 | |
---|
42 | void |
---|
43 | BSP_exceptionHandler(BSP_Exception_frame* excPtr) |
---|
44 | { |
---|
45 | rtems_unsigned32 note; |
---|
46 | BSP_ExceptionExtension ext=0; |
---|
47 | rtems_id id=0; |
---|
48 | int recoverable = 0; |
---|
49 | char *fmt="Uhuuuh, Exception %d in unknown task???\n"; |
---|
50 | int quiet=0; |
---|
51 | |
---|
52 | if (!quiet) printk("In BSP_exceptionHandler()\n"); |
---|
53 | /* If we are in interrupt context, we are in trouble - skip the user |
---|
54 | * hook and panic |
---|
55 | */ |
---|
56 | if (rtems_interrupt_is_in_progress()) { |
---|
57 | fmt="Aieeh, Exception %d in interrupt handler\n"; |
---|
58 | } else if ( !_Thread_Executing) { |
---|
59 | fmt="Aieeh, Exception %d in initialization code\n"; |
---|
60 | } else { |
---|
61 | /* retrieve the notepad which possibly holds an extention pointer */ |
---|
62 | if (RTEMS_SUCCESSFUL==rtems_task_ident(RTEMS_SELF,RTEMS_LOCAL,&id) && |
---|
63 | #if 0 |
---|
64 | /* Must not use a notepad due to unknown initial value (notepad memory is allocated from the |
---|
65 | * workspace)! |
---|
66 | */ |
---|
67 | RTEMS_SUCCESSFUL==rtems_task_get_note(id, BSP_EXCEPTION_NOTEPAD, ¬e) |
---|
68 | #else |
---|
69 | RTEMS_SUCCESSFUL==rtems_task_variable_get(id, (void*)&BSP_exceptionExtension, (void**)¬e) |
---|
70 | #endif |
---|
71 | ) { |
---|
72 | ext = (BSP_ExceptionExtension)note; |
---|
73 | if (ext) |
---|
74 | quiet=ext->quiet; |
---|
75 | if (!quiet) { |
---|
76 | printk("Task (Id 0x%08x) got ",id); |
---|
77 | } |
---|
78 | fmt="exception %d\n"; |
---|
79 | } |
---|
80 | } |
---|
81 | |
---|
82 | if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr,ext,0)) { |
---|
83 | /* they did all the work and want us to do nothing! */ |
---|
84 | printk("they did all the work and want us to do nothing!\n"); |
---|
85 | return; |
---|
86 | } |
---|
87 | |
---|
88 | if (!quiet) { |
---|
89 | /* message about exception */ |
---|
90 | printk(fmt, excPtr->_EXC_number); |
---|
91 | /* register dump */ |
---|
92 | printk("\t Next PC or Address of fault = %x, ", excPtr->EXC_SRR0); |
---|
93 | printk("Mvme5500 Saved MSR = %x\n", excPtr->EXC_SRR1); |
---|
94 | printk("\t R0 = %08x", excPtr->GPR0); |
---|
95 | printk(" R1 = %08x", excPtr->GPR1); |
---|
96 | printk(" R2 = %08x", excPtr->GPR2); |
---|
97 | printk(" R3 = %08x\n", excPtr->GPR3); |
---|
98 | printk("\t R4 = %08x", excPtr->GPR4); |
---|
99 | printk(" R5 = %08x", excPtr->GPR5); |
---|
100 | printk(" R6 = %08x", excPtr->GPR6); |
---|
101 | printk(" R7 = %08x\n", excPtr->GPR7); |
---|
102 | printk("\t R8 = %08x", excPtr->GPR8); |
---|
103 | printk(" R9 = %08x", excPtr->GPR9); |
---|
104 | printk(" R10 = %08x", excPtr->GPR10); |
---|
105 | printk(" R11 = %08x\n", excPtr->GPR11); |
---|
106 | printk("\t R12 = %08x", excPtr->GPR12); |
---|
107 | printk(" R13 = %08x", excPtr->GPR13); |
---|
108 | printk(" R14 = %08x", excPtr->GPR14); |
---|
109 | printk(" R15 = %08x\n", excPtr->GPR15); |
---|
110 | printk("\t R16 = %08x", excPtr->GPR16); |
---|
111 | printk(" R17 = %08x", excPtr->GPR17); |
---|
112 | printk(" R18 = %08x", excPtr->GPR18); |
---|
113 | printk(" R19 = %08x\n", excPtr->GPR19); |
---|
114 | printk("\t R20 = %08x", excPtr->GPR20); |
---|
115 | printk(" R21 = %08x", excPtr->GPR21); |
---|
116 | printk(" R22 = %08x", excPtr->GPR22); |
---|
117 | printk(" R23 = %08x\n", excPtr->GPR23); |
---|
118 | printk("\t R24 = %08x", excPtr->GPR24); |
---|
119 | printk(" R25 = %08x", excPtr->GPR25); |
---|
120 | printk(" R26 = %08x", excPtr->GPR26); |
---|
121 | printk(" R27 = %08x\n", excPtr->GPR27); |
---|
122 | printk("\t R28 = %08x", excPtr->GPR28); |
---|
123 | printk(" R29 = %08x", excPtr->GPR29); |
---|
124 | printk(" R30 = %08x", excPtr->GPR30); |
---|
125 | printk(" R31 = %08x\n", excPtr->GPR31); |
---|
126 | printk("\t CR = %08x\n", excPtr->EXC_CR); |
---|
127 | printk("\t CTR = %08x\n", excPtr->EXC_CTR); |
---|
128 | printk("\t XER = %08x\n", excPtr->EXC_XER); |
---|
129 | printk("\t LR = %08x\n", excPtr->EXC_LR); |
---|
130 | printk("\t DAR = %08x\n", excPtr->EXC_DAR); |
---|
131 | |
---|
132 | BSP_printStackTrace(excPtr); |
---|
133 | } |
---|
134 | |
---|
135 | if (ASM_MACH_VECTOR == excPtr->_EXC_number) { |
---|
136 | /* ollah , we got a machine check - this could either |
---|
137 | * be a TEA, MCP or internal; let's see and provide more info |
---|
138 | */ |
---|
139 | if (!quiet) |
---|
140 | printk("Machine check; reason:"); |
---|
141 | if ( ! (excPtr->EXC_SRR1 & (SRR1_TEA_EXC | SRR1_MCP_EXC)) ) { |
---|
142 | if (!quiet) |
---|
143 | printk("SRR1\n"); |
---|
144 | } else { |
---|
145 | if (excPtr->EXC_SRR1 & (SRR1_TEA_EXC)) { |
---|
146 | if (!quiet) |
---|
147 | printk(" TEA"); |
---|
148 | } |
---|
149 | if (excPtr->EXC_SRR1 & (SRR1_MCP_EXC)) { |
---|
150 | unsigned char c1,c2; |
---|
151 | unsigned int l; |
---|
152 | unsigned long gerr; |
---|
153 | |
---|
154 | if (!quiet) printk(" MCP\n"); |
---|
155 | |
---|
156 | /* it's MCP; gather info from the host bridge */ |
---|
157 | gerr=_BSP_clear_hostbridge_errors(0,0); |
---|
158 | if (gerr&0x80000000) printk("GT64260 Parity error\n"); |
---|
159 | if (gerr&0x40000000) printk("GT64260 SysErr\n"); |
---|
160 | if ((!quiet) && (!gerr)) printk("GT64260 host bridge seems OK\n"); |
---|
161 | } |
---|
162 | } |
---|
163 | } else if (ASM_DEC_VECTOR == excPtr->_EXC_number) { |
---|
164 | recoverable = 1; |
---|
165 | } else if (ASM_SYS_VECTOR == excPtr->_EXC_number) { |
---|
166 | #ifdef TEST_RAW_EXCEPTION_CODE |
---|
167 | recoverable = 1; |
---|
168 | #else |
---|
169 | recoverable = 0; |
---|
170 | #endif |
---|
171 | } |
---|
172 | |
---|
173 | /* call them for a second time giving a chance to intercept |
---|
174 | * the task_suspend |
---|
175 | */ |
---|
176 | if (ext && ext->lowlevelHook && ext->lowlevelHook(excPtr, ext, 1)) |
---|
177 | return; |
---|
178 | |
---|
179 | if (!recoverable) { |
---|
180 | if (id) { |
---|
181 | /* if there's a highlevel hook, install it */ |
---|
182 | if (ext && ext->highlevelHook) { |
---|
183 | excPtr->EXC_SRR0 = (rtems_unsigned32)ext->highlevelHook; |
---|
184 | excPtr->GPR3 = (rtems_unsigned32)ext; |
---|
185 | return; |
---|
186 | } |
---|
187 | if (excPtr->EXC_SRR1 & MSR_FP) { |
---|
188 | /* thread dispatching is _not_ disabled at this point; hence |
---|
189 | * we must make sure we have the FPU enabled... |
---|
190 | */ |
---|
191 | _write_MSR( _read_MSR() | MSR_FP ); |
---|
192 | __asm__ __volatile__("isync"); |
---|
193 | } |
---|
194 | printk("unrecoverable exception!!! task %08x suspended\n",id); |
---|
195 | rtems_task_suspend(id); |
---|
196 | } else { |
---|
197 | printk("PANIC, rebooting...\n"); |
---|
198 | rtemsReboot(); |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|