1 | /* |
---|
2 | ************************************************************************** |
---|
3 | * |
---|
4 | * Component = |
---|
5 | * |
---|
6 | * Synopsis = rdbg/m68k/excep_f.c |
---|
7 | * |
---|
8 | * $Id$ |
---|
9 | * |
---|
10 | ************************************************************************** |
---|
11 | */ |
---|
12 | |
---|
13 | #include <rtems.h> |
---|
14 | #include <rtems/error.h> |
---|
15 | #include <assert.h> |
---|
16 | #include <errno.h> |
---|
17 | #include <rdbg/rdbg.h> |
---|
18 | #include <rdbg/servrpc.h> |
---|
19 | |
---|
20 | int |
---|
21 | ExcepToSig (Exception_context * ctx) |
---|
22 | { |
---|
23 | int excep = getExcNum (ctx); |
---|
24 | |
---|
25 | switch (excep) { |
---|
26 | case 2: |
---|
27 | return 10; |
---|
28 | break; /* bus error */ |
---|
29 | case 3: |
---|
30 | return 10; |
---|
31 | break; /* address error */ |
---|
32 | case 4: |
---|
33 | return 4; |
---|
34 | break; /* illegal instruction */ |
---|
35 | case 5: |
---|
36 | return 8; |
---|
37 | break; /* zero divide */ |
---|
38 | case 6: |
---|
39 | return 8; |
---|
40 | break; /* chk instruction */ |
---|
41 | case 7: |
---|
42 | return 8; |
---|
43 | break; /* trapv instruction */ |
---|
44 | case 8: |
---|
45 | return 11; |
---|
46 | break; /* privilege violation */ |
---|
47 | case 9: |
---|
48 | return 5; |
---|
49 | break; /* trace trap */ |
---|
50 | case 10: |
---|
51 | return 4; |
---|
52 | break; /* line 1010 emulator */ |
---|
53 | case 11: |
---|
54 | return 4; |
---|
55 | break; /* line 1111 emulator */ |
---|
56 | |
---|
57 | /* |
---|
58 | * Coprocessor protocol violation. Using a standard MMU or FPU |
---|
59 | * this cannot be triggered by software. Call it a SIGBUS. |
---|
60 | */ |
---|
61 | case 13: |
---|
62 | return 10; |
---|
63 | break; |
---|
64 | |
---|
65 | case 31: |
---|
66 | return 2; |
---|
67 | break; /* interrupt */ |
---|
68 | case 33: |
---|
69 | return 5; |
---|
70 | break; /* monitor breakpoint */ |
---|
71 | case 34: |
---|
72 | return 2; |
---|
73 | break; /* lets use this for SCC1 interrupt */ |
---|
74 | case 35: |
---|
75 | return 5; |
---|
76 | break; /* rdbg breakpoint */ |
---|
77 | case 36: |
---|
78 | return 2; |
---|
79 | break; /* enter RDBG */ |
---|
80 | /* |
---|
81 | * This is a trap #8 instruction. Apparently it is someone's software |
---|
82 | * convention for some sort of SIGFPE condition. Whose? How many |
---|
83 | * people are being screwed by having this code the way it is? |
---|
84 | * Is there a clean solution? |
---|
85 | */ |
---|
86 | case 40: |
---|
87 | return 8; |
---|
88 | break; /* floating point err */ |
---|
89 | |
---|
90 | case 47: |
---|
91 | return 5; |
---|
92 | break; /* rdbg breakpoint */ |
---|
93 | |
---|
94 | case 48: |
---|
95 | return 8; |
---|
96 | break; /* floating point err */ |
---|
97 | case 49: |
---|
98 | return 8; |
---|
99 | break; /* floating point err */ |
---|
100 | case 50: |
---|
101 | return 8; |
---|
102 | break; /* zero divide */ |
---|
103 | case 51: |
---|
104 | return 8; |
---|
105 | break; /* underflow */ |
---|
106 | case 52: |
---|
107 | return 8; |
---|
108 | break; /* operand error */ |
---|
109 | case 53: |
---|
110 | return 8; |
---|
111 | break; /* overflow */ |
---|
112 | case 54: |
---|
113 | return 8; |
---|
114 | break; /* NAN */ |
---|
115 | default: |
---|
116 | return 7; /* "software generated" */ |
---|
117 | } |
---|
118 | return SIGKILL; |
---|
119 | } |
---|
120 | |
---|
121 | /*----- Breakpoint Exception management -----*/ |
---|
122 | |
---|
123 | /* |
---|
124 | * Handler for Breakpoint Exceptions : |
---|
125 | * software breakpoints. |
---|
126 | */ |
---|
127 | |
---|
128 | void |
---|
129 | BreakPointExcHdl (CPU_Exception_frame * ctx) |
---|
130 | { |
---|
131 | rtems_status_code status; |
---|
132 | rtems_id continueSemId; |
---|
133 | |
---|
134 | connect_rdbg_exception (); /* monitor stub changes trace vector */ |
---|
135 | if ((justSaveContext) && (ctx->vecnum == 47)) { /* break */ |
---|
136 | PushSavedExceptCtx (_Thread_Executing->Object.id, ctx); |
---|
137 | justSaveContext = 0; |
---|
138 | } else { |
---|
139 | if (ctx->vecnum != 9) { /* trace */ |
---|
140 | NbSerializedCtx++; |
---|
141 | rtems_semaphore_obtain (serializeSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
142 | NbSerializedCtx--; |
---|
143 | } |
---|
144 | |
---|
145 | currentTargetThread = _Thread_Executing->Object.id; |
---|
146 | |
---|
147 | #ifdef DDEBUG |
---|
148 | printk ("----------------------------------------------------------\n"); |
---|
149 | printk ("Exception %d caught at PC %x by thread %d\n", |
---|
150 | ctx->vecnum, ctx->pc, _Thread_Executing->Object.id); |
---|
151 | printk ("----------------------------------------------------------\n"); |
---|
152 | printk ("Processor execution context at time of the fault was :\n"); |
---|
153 | printk ("----------------------------------------------------------\n"); |
---|
154 | printk ("\t A0 = %x\n", ctx->a0); |
---|
155 | printk ("\t A1 = %x\n", ctx->a1); |
---|
156 | printk ("\t A2 = %x\n", ctx->a2); |
---|
157 | printk ("\t A3 = %x\n", ctx->a3); |
---|
158 | printk ("\t A4 = %x\n", ctx->a4); |
---|
159 | printk ("\t A5 = %x\n", ctx->a5); |
---|
160 | printk ("\t A6 = %x\n", ctx->a6); |
---|
161 | printk ("\t A7 = %x\n", ctx->a7); |
---|
162 | printk ("\t D0 = %x\n", ctx->d0); |
---|
163 | printk ("\t D1 = %x\n", ctx->d1); |
---|
164 | printk ("\t D2 = %x\n", ctx->d2); |
---|
165 | printk ("\t D3 = %x\n", ctx->d3); |
---|
166 | printk ("\t D4 = %x\n", ctx->d4); |
---|
167 | printk ("\t D5 = %x\n", ctx->d5); |
---|
168 | printk ("\t D6 = %x\n", ctx->d6); |
---|
169 | printk ("\t D7 = %x\n", ctx->d7); |
---|
170 | printk ("\t SR = %x\n", ctx->sr); |
---|
171 | #endif |
---|
172 | |
---|
173 | status = rtems_semaphore_create (rtems_build_name ('D', 'B', 'G', 'c'), |
---|
174 | 0, |
---|
175 | RTEMS_FIFO | |
---|
176 | RTEMS_COUNTING_SEMAPHORE | |
---|
177 | RTEMS_NO_INHERIT_PRIORITY | |
---|
178 | RTEMS_NO_PRIORITY_CEILING | |
---|
179 | RTEMS_LOCAL, 0, &continueSemId); |
---|
180 | if (status != RTEMS_SUCCESSFUL) |
---|
181 | rtems_panic ("Can't create continue semaphore: `%s'\n", |
---|
182 | rtems_status_text (status)); |
---|
183 | |
---|
184 | PushExceptCtx (_Thread_Executing->Object.id, continueSemId, ctx); |
---|
185 | |
---|
186 | switch (ctx->vecnum) { |
---|
187 | case 9: /* trace */ |
---|
188 | DPRINTF ((" TRACE EXCEPTION !!!\n")); |
---|
189 | ctx->sr &= ~(1 << 15); |
---|
190 | ExitForSingleStep--; |
---|
191 | rtems_semaphore_release (wakeupEventSemId); |
---|
192 | break; |
---|
193 | |
---|
194 | case 47: /* trap #15 */ |
---|
195 | DPRINTF ((" BREAKPOINT EXCEPTION !!!\n")); |
---|
196 | rtems_semaphore_release (wakeupEventSemId); |
---|
197 | break; |
---|
198 | |
---|
199 | case 36: /* trap #4 */ |
---|
200 | DPRINTF ((" ENTER RDBG !!!\n")); |
---|
201 | rtems_semaphore_release (wakeupEventSemId); |
---|
202 | break; |
---|
203 | |
---|
204 | default: |
---|
205 | DPRINTF ((" OTHER EXCEPTION !!!\n")); |
---|
206 | rtems_semaphore_release (wakeupEventSemId); |
---|
207 | break; |
---|
208 | } |
---|
209 | |
---|
210 | rtems_semaphore_obtain (continueSemId, RTEMS_WAIT, RTEMS_NO_TIMEOUT); |
---|
211 | |
---|
212 | PopExceptCtx (_Thread_Executing->Object.id); |
---|
213 | rtems_semaphore_delete (continueSemId); |
---|
214 | } |
---|
215 | |
---|
216 | connect_rdbg_exception (); /* monitor stub changes trace vector */ |
---|
217 | } |
---|