3 * Purpose: Generic exception handling for ColdFire processors
7 #include "derivative.h"
8 #include "exceptions.h"
11 #define REGISTER_ABI __REGABI__
13 extern asm void interrupt 109 vPortYieldISR( void );
14 extern void interrupt 86 vFECISRHandler( void );
16 /***********************************************************************/
18 * Set NO_PRINTF to 0 in order the exceptions.c interrupt handler
19 * to output messages to the standard io.
25 #define VECTORDISPLAY(MESSAGE) asm { nop; };
26 #define VECTORDISPLAY2(MESSAGE,MESSAGE2) asm { nop; };
27 #define VECTORDISPLAY3(MESSAGE,MESSAGE2,MESSAGE3) asm { nop; };
30 #define VECTORDISPLAY(MESSAGE1) printf(MESSAGE1);
31 #define VECTORDISPLAY2(MESSAGE1,MESSAGE2) printf(MESSAGE1,MESSAGE2);
32 #define VECTORDISPLAY3(MESSAGE1,MESSAGE2,MESSAGE3) printf(MESSAGE1,MESSAGE2,MESSAGE3);
39 extern unsigned long far _SP_INIT[];
41 /***********************************************************************/
43 * Handling of the TRK ColdFire libs (printf support in Debugger Terminal)
45 * To enable this support:
46 * - Set CONSOLE_IO_SUPPORT 1 in this file; this will enable
47 * TrapHandler_printf for the trap #14 exception.
49 * - Make sure the file console_io_cf.c is in your project.
51 * - In the debugger make sure that in the Connection "Setup" dialog,
52 * "Debug Options" property page, the check box
53 * "Enable Terminal printf support" is set.
58 #define CONSOLE_IO_SUPPORT 0
60 #if CONSOLE_IO_SUPPORT
61 asm void TrapHandler_printf(void) {
67 /***********************************************************************/
69 * This is the handler for all exceptions which are not common to all
72 * Called by mcf_exception_handler
75 void derivative_interrupt(unsigned long vector)
77 if (vector < 64 || vector > 192) {
78 VECTORDISPLAY2("User Defined Vector #%d\n",vector);
82 /***********************************************************************
84 * This is the exception handler for all exceptions common to all
85 * chips ColdFire. Most exceptions do nothing, but some of the more
86 * important ones are handled to some extent.
88 * Called by asm_exception_handler
90 * The ColdFire family of processors has a simplified exception stack
91 * frame that looks like the following:
93 * 3322222222221111 111111
94 * 1098765432109876 5432109876543210
95 * 8 +----------------+----------------+
97 * 4 +----------------+----------------+
98 * |FS/Fmt/Vector/FS| SR |
99 * SP --> 0 +----------------+----------------+
101 * The stack self-aligns to a 4-byte boundary at an exception, with
102 * the FS/Fmt/Vector/FS field indicating the size of the adjustment
103 * (SP += 0,1,2,3 bytes).
104 * 31 28 27 26 25 18 17 16 15 0
105 * 4 +---------------------------------------+------------------------------------+
106 * | Format | FS[3..2] | Vector | FS[1..0] | SR |
107 * SP --> 0 +---------------------------------------+------------------------------------+
109 #define MCF5XXX_RD_SF_FORMAT(PTR) \
110 ((*((unsigned short *)(PTR)) >> 12) & 0x00FF)
112 #define MCF5XXX_RD_SF_VECTOR(PTR) \
113 ((*((unsigned short *)(PTR)) >> 2) & 0x00FF)
115 #define MCF5XXX_RD_SF_FS(PTR) \
116 ( ((*((unsigned short *)(PTR)) & 0x0C00) >> 8) | (*((unsigned short *)(PTR)) & 0x0003) )
118 #define MCF5XXX_SF_SR(PTR) *(((unsigned short *)(PTR))+1)
120 #define MCF5XXX_SF_PC(PTR) *((unsigned long *)(PTR)+1)
122 #define MCF5XXX_EXCEPTFMT "%s -- PC = %#08X\n"
125 void mcf_exception_handler(void *framepointer)
127 volatile unsigned long exceptionStackFrame = (*(unsigned long *)(framepointer));
128 volatile unsigned short stackFrameSR = MCF5XXX_SF_SR(framepointer);
129 volatile unsigned short stackFrameWord = (*(unsigned short *)(framepointer));
130 volatile unsigned long stackFrameFormat = (unsigned long)MCF5XXX_RD_SF_FORMAT(&stackFrameWord);
131 volatile unsigned long stackFrameFS = (unsigned long)MCF5XXX_RD_SF_FS(&stackFrameWord);
132 volatile unsigned long stackFrameVector = (unsigned long)MCF5XXX_RD_SF_VECTOR(&stackFrameWord);
133 volatile unsigned long stackFramePC = MCF5XXX_SF_PC(framepointer);
135 switch (stackFrameFormat)
143 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT,"Illegal stack type", stackFramePC);
147 switch (stackFrameVector)
150 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Access Error", stackFramePC);
151 switch (stackFrameFS)
154 VECTORDISPLAY("Error on instruction fetch\n");
157 VECTORDISPLAY("Error on operand write\n");
160 VECTORDISPLAY("Attempted write to write-protected space\n");
163 VECTORDISPLAY("Error on operand read\n");
166 VECTORDISPLAY("Reserved Fault Status Encoding\n");
171 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Address Error", stackFramePC);
172 switch (stackFrameFS)
175 VECTORDISPLAY("Error on instruction fetch\n");
178 VECTORDISPLAY("Error on operand write\n");
181 VECTORDISPLAY("Attempted write to write-protected space\n");
184 VECTORDISPLAY("Error on operand read\n");
187 VECTORDISPLAY("Reserved Fault Status Encoding\n");
192 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Illegal instruction", stackFramePC);
195 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Privilege violation", stackFramePC);
198 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Trace Exception", stackFramePC);
201 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Unimplemented A-Line Instruction", stackFramePC);
204 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Unimplemented F-Line Instruction", stackFramePC);
207 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Debug Interrupt", stackFramePC);
210 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Format Error", stackFramePC);
213 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Unitialized Interrupt", stackFramePC);
216 VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Spurious Interrupt", stackFramePC);
225 VECTORDISPLAY2("Autovector interrupt level %d\n", stackFrameVector - 24);
243 VECTORDISPLAY2("TRAP #%d\n", stackFrameVector - 32);
273 VECTORDISPLAY2("Reserved: #%d\n", stackFrameVector);
276 derivative_interrupt(stackFrameVector);
282 asm void asm_exception_handler(void)
286 movem.l d0-d2/a0-a1, (sp)
287 lea 24(sp),a0 /* A0 point to exception stack frame on the stack */
288 jsr mcf_exception_handler
289 movem.l (sp), d0-d2/a0-a1
295 asm void asm_exception_handler(void)
299 movem.l d0-d2/a0-a1, (sp)
300 pea 24(sp) /* push exception frame address */
301 jsr mcf_exception_handler
302 movem.l 4(sp), d0-d2/a0-a1
309 typedef void (* vectorTableEntryType)(void);
311 #if CONSOLE_IO_SUPPORT
312 vectorTableEntryType vector_printf @Vtrap14 = TrapHandler_printf;
316 * MCF51CN128 vector table
317 * CF V1 has 114 vector + SP_INIT in the vector table (115 entries)
320 __declspec(weak) vectorTableEntryType vector_0 @INITSP = (vectorTableEntryType)&_SP_INIT;
321 __declspec(weak) vectorTableEntryType vector_1 @INITPC = (vectorTableEntryType)&_startup;
322 __declspec(weak) vectorTableEntryType vector_2 @Vaccerr = asm_exception_handler;
323 __declspec(weak) vectorTableEntryType vector_3 @Vadderr = asm_exception_handler;
324 __declspec(weak) vectorTableEntryType vector_4 @Viinstr = asm_exception_handler;
325 __declspec(weak) vectorTableEntryType vector_5 @VReserved5 = asm_exception_handler;
326 __declspec(weak) vectorTableEntryType vector_6 @VReserved6 = asm_exception_handler;
327 __declspec(weak) vectorTableEntryType vector_7 @VReserved7 = asm_exception_handler;
328 __declspec(weak) vectorTableEntryType vector_8 @Vprviol = asm_exception_handler;
329 __declspec(weak) vectorTableEntryType vector_9 @Vtrace = asm_exception_handler;
330 __declspec(weak) vectorTableEntryType vector_10 @Vunilaop = asm_exception_handler;
331 __declspec(weak) vectorTableEntryType vector_11 @Vunilfop = asm_exception_handler;
332 __declspec(weak) vectorTableEntryType vector_12 @Vdbgi = asm_exception_handler;
333 __declspec(weak) vectorTableEntryType vector_13 @VReserved13 = asm_exception_handler;
334 __declspec(weak) vectorTableEntryType vector_14 @Vferror = asm_exception_handler;
335 __declspec(weak) vectorTableEntryType vector_15 @VReserved15 = asm_exception_handler;
336 __declspec(weak) vectorTableEntryType vector_16 @VReserved16 = asm_exception_handler;
337 __declspec(weak) vectorTableEntryType vector_17 @VReserved17 = asm_exception_handler;
338 __declspec(weak) vectorTableEntryType vector_18 @VReserved18 = asm_exception_handler;
339 __declspec(weak) vectorTableEntryType vector_19 @VReserved19 = asm_exception_handler;
340 __declspec(weak) vectorTableEntryType vector_20 @VReserved20 = asm_exception_handler;
341 __declspec(weak) vectorTableEntryType vector_21 @VReserved21 = asm_exception_handler;
342 __declspec(weak) vectorTableEntryType vector_22 @VReserved22 = asm_exception_handler;
343 __declspec(weak) vectorTableEntryType vector_23 @VReserved23 = asm_exception_handler;
344 __declspec(weak) vectorTableEntryType vector_24 @Vspuri = asm_exception_handler;
345 __declspec(weak) vectorTableEntryType vector_25 @VReserved25 = asm_exception_handler;
346 __declspec(weak) vectorTableEntryType vector_26 @VReserved26 = asm_exception_handler;
347 __declspec(weak) vectorTableEntryType vector_27 @VReserved27 = asm_exception_handler;
348 __declspec(weak) vectorTableEntryType vector_28 @VReserved28 = asm_exception_handler;
349 __declspec(weak) vectorTableEntryType vector_29 @VReserved29 = asm_exception_handler;
350 __declspec(weak) vectorTableEntryType vector_30 @VReserved30 = asm_exception_handler;
351 __declspec(weak) vectorTableEntryType vector_31 @VReserved31 = asm_exception_handler;
352 __declspec(weak) vectorTableEntryType vector_32 @Vtrap0 = asm_exception_handler;
353 __declspec(weak) vectorTableEntryType vector_33 @Vtrap1 = asm_exception_handler;
354 __declspec(weak) vectorTableEntryType vector_34 @Vtrap2 = asm_exception_handler;
355 __declspec(weak) vectorTableEntryType vector_35 @Vtrap3 = asm_exception_handler;
356 __declspec(weak) vectorTableEntryType vector_36 @Vtrap4 = asm_exception_handler;
357 __declspec(weak) vectorTableEntryType vector_37 @Vtrap5 = asm_exception_handler;
358 __declspec(weak) vectorTableEntryType vector_38 @Vtrap6 = asm_exception_handler;
359 __declspec(weak) vectorTableEntryType vector_39 @Vtrap7 = asm_exception_handler;
360 __declspec(weak) vectorTableEntryType vector_40 @Vtrap8 = asm_exception_handler;
361 __declspec(weak) vectorTableEntryType vector_41 @Vtrap9 = asm_exception_handler;
362 __declspec(weak) vectorTableEntryType vector_42 @Vtrap10 = asm_exception_handler;
363 __declspec(weak) vectorTableEntryType vector_43 @Vtrap11 = asm_exception_handler;
364 __declspec(weak) vectorTableEntryType vector_44 @Vtrap12 = asm_exception_handler;
365 __declspec(weak) vectorTableEntryType vector_45 @Vtrap13 = asm_exception_handler;
366 #if CONSOLE_IO_SUPPORT == 0
367 __declspec(weak) vectorTableEntryType vector_46 @Vtrap14 = asm_exception_handler;
369 __declspec(weak) vectorTableEntryType vector_47 @Vtrap15 = asm_exception_handler;
370 __declspec(weak) vectorTableEntryType vector_48 @VReserved48 = asm_exception_handler;
371 __declspec(weak) vectorTableEntryType vector_49 @VReserved49 = asm_exception_handler;
372 __declspec(weak) vectorTableEntryType vector_50 @VReserved50 = asm_exception_handler;
373 __declspec(weak) vectorTableEntryType vector_51 @VReserved51 = asm_exception_handler;
374 __declspec(weak) vectorTableEntryType vector_52 @VReserved52 = asm_exception_handler;
375 __declspec(weak) vectorTableEntryType vector_53 @VReserved53 = asm_exception_handler;
376 __declspec(weak) vectorTableEntryType vector_54 @VReserved54 = asm_exception_handler;
377 __declspec(weak) vectorTableEntryType vector_55 @VReserved55 = asm_exception_handler;
378 __declspec(weak) vectorTableEntryType vector_56 @VReserved56 = asm_exception_handler;
379 __declspec(weak) vectorTableEntryType vector_57 @VReserved57 = asm_exception_handler;
380 __declspec(weak) vectorTableEntryType vector_58 @VReserved58 = asm_exception_handler;
381 __declspec(weak) vectorTableEntryType vector_59 @VReserved59 = asm_exception_handler;
382 __declspec(weak) vectorTableEntryType vector_60 @VReserved60 = asm_exception_handler;
383 __declspec(weak) vectorTableEntryType vector_61 @Vunsinstr = asm_exception_handler;
384 __declspec(weak) vectorTableEntryType vector_62 @VReserved62 = asm_exception_handler;
385 __declspec(weak) vectorTableEntryType vector_63 @VReserved63 = asm_exception_handler;
386 __declspec(weak) vectorTableEntryType vector_64 @Virq = asm_exception_handler;
387 __declspec(weak) vectorTableEntryType vector_65 @Vlvd = asm_exception_handler;
388 __declspec(weak) vectorTableEntryType vector_66 @Vlol = asm_exception_handler;
389 __declspec(weak) vectorTableEntryType vector_67 @Vtpm1ch0 = asm_exception_handler;
390 __declspec(weak) vectorTableEntryType vector_68 @Vtpm1ch1 = asm_exception_handler;
391 __declspec(weak) vectorTableEntryType vector_69 @Vtpm1ch2 = asm_exception_handler;
392 __declspec(weak) vectorTableEntryType vector_70 @Vtpm1ovf = asm_exception_handler;
393 __declspec(weak) vectorTableEntryType vector_71 @Vmtim1 = asm_exception_handler;
394 __declspec(weak) vectorTableEntryType vector_72 @Vtpm2ch0 = asm_exception_handler;
395 __declspec(weak) vectorTableEntryType vector_73 @Vtpm2ch1 = asm_exception_handler;
396 __declspec(weak) vectorTableEntryType vector_74 @Vtpm2ch2 = asm_exception_handler;
397 __declspec(weak) vectorTableEntryType vector_75 @Vtpm2ovf = asm_exception_handler;
398 __declspec(weak) vectorTableEntryType vector_76 @Vspi1 = asm_exception_handler;
399 __declspec(weak) vectorTableEntryType vector_77 @Vspi2 = asm_exception_handler;
400 __declspec(weak) vectorTableEntryType vector_78 @Vmtim2 = asm_exception_handler;
401 __declspec(weak) vectorTableEntryType vector_79 @Vsci1err = asm_exception_handler;
402 __declspec(weak) vectorTableEntryType vector_80 @Vsci1rx = asm_exception_handler;
403 __declspec(weak) vectorTableEntryType vector_81 @Vsci1tx = asm_exception_handler;
404 __declspec(weak) vectorTableEntryType vector_82 @Vsci2err = asm_exception_handler;
405 __declspec(weak) vectorTableEntryType vector_83 @Vsci2rx = asm_exception_handler;
406 __declspec(weak) vectorTableEntryType vector_84 @Vsci2tx = asm_exception_handler;
407 __declspec(weak) vectorTableEntryType vector_85 @Vsci3or = asm_exception_handler;
408 __declspec(weak) vectorTableEntryType vector_86 @Vfectxf = vFECISRHandler;
409 __declspec(weak) vectorTableEntryType vector_87 @Vfecrxf = vFECISRHandler;
410 __declspec(weak) vectorTableEntryType vector_88 @Vfecother = vFECISRHandler;
411 __declspec(weak) vectorTableEntryType vector_89 @Vfechberr = vFECISRHandler;
412 __declspec(weak) vectorTableEntryType vector_90 @Vfecbabr = vFECISRHandler;
413 __declspec(weak) vectorTableEntryType vector_91 @Vfecbabt = vFECISRHandler;
414 __declspec(weak) vectorTableEntryType vector_92 @Vfecgra = vFECISRHandler;
415 __declspec(weak) vectorTableEntryType vector_93 @Vfectxb = vFECISRHandler;
416 __declspec(weak) vectorTableEntryType vector_94 @Vfecrxb = vFECISRHandler;
417 __declspec(weak) vectorTableEntryType vector_95 @Vfecmii = vFECISRHandler;
418 __declspec(weak) vectorTableEntryType vector_96 @Vfeceberr = vFECISRHandler;
419 __declspec(weak) vectorTableEntryType vector_97 @Vfeclc = vFECISRHandler;
420 __declspec(weak) vectorTableEntryType vector_98 @Vfecrl = vFECISRHandler;
421 __declspec(weak) vectorTableEntryType vector_99 @Vfecun = vFECISRHandler;
422 __declspec(weak) vectorTableEntryType vector_100 @Vsci3err = asm_exception_handler;
423 __declspec(weak) vectorTableEntryType vector_101 @Vsci3rx = asm_exception_handler;
424 __declspec(weak) vectorTableEntryType vector_102 @Vsci3tx = asm_exception_handler;
425 __declspec(weak) vectorTableEntryType vector_103 @VL7swi = asm_exception_handler;
426 __declspec(weak) vectorTableEntryType vector_104 @VL6swi = asm_exception_handler;
427 __declspec(weak) vectorTableEntryType vector_105 @VL5swi = asm_exception_handler;
428 __declspec(weak) vectorTableEntryType vector_106 @VL4swi = asm_exception_handler;
429 __declspec(weak) vectorTableEntryType vector_107 @VL3swi = asm_exception_handler;
430 __declspec(weak) vectorTableEntryType vector_108 @VL2swi = asm_exception_handler;
431 __declspec(weak) vectorTableEntryType vector_109 @VL1swi = vPortYieldISR;
432 __declspec(weak) vectorTableEntryType vector_110 @Viic1 = asm_exception_handler;
433 __declspec(weak) vectorTableEntryType vector_111 @Viic2 = asm_exception_handler;
434 __declspec(weak) vectorTableEntryType vector_112 @Vadc = asm_exception_handler;
435 __declspec(weak) vectorTableEntryType vector_113 @Vkeyboard = asm_exception_handler;
436 __declspec(weak) vectorTableEntryType vector_114 @Vrtc = asm_exception_handler;