OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [ColdFire_MCF51CN128_CodeWarrior/] [Sources/] [exceptions.old0.c] - Blame information for rev 621

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 jeremybenn
/*
2
 * File:    exceptions.c
3
 * Purpose: Generic exception handling for ColdFire processors
4
 *
5
 */
6
 
7
#include "derivative.h"
8
#include "exceptions.h"
9
#include "startcf.h"
10
 
11
#define REGISTER_ABI __REGABI__
12
 
13
extern asm void interrupt 109 vPortYieldISR( void );
14
extern void interrupt 86 vFECISRHandler( void );
15
 
16
/***********************************************************************/
17
/*
18
 *  Set NO_PRINTF to 0 in order the exceptions.c interrupt handler
19
 *  to output messages to the standard io.
20
 *
21
 */
22
#define NO_PRINTF    1
23
 
24
#if NO_PRINTF
25
#define VECTORDISPLAY(MESSAGE)                    asm { nop; };
26
#define VECTORDISPLAY2(MESSAGE,MESSAGE2)          asm { nop; };
27
#define VECTORDISPLAY3(MESSAGE,MESSAGE2,MESSAGE3) asm { nop; };
28
#else
29
#include <stdio.h>
30
#define VECTORDISPLAY(MESSAGE1)                    printf(MESSAGE1);
31
#define VECTORDISPLAY2(MESSAGE1,MESSAGE2)          printf(MESSAGE1,MESSAGE2);
32
#define VECTORDISPLAY3(MESSAGE1,MESSAGE2,MESSAGE3) printf(MESSAGE1,MESSAGE2,MESSAGE3);
33
#endif
34
 
35
#ifdef __cplusplus
36
extern "C" {
37
#endif
38
 
39
extern unsigned long far _SP_INIT[];
40
 
41
/***********************************************************************/
42
/*
43
 * Handling of the TRK ColdFire libs (printf support in Debugger Terminal)
44
 *
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.
48
 *
49
 * - Make sure the file console_io_cf.c is in your project.
50
 *
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.
54
 *
55
 *
56
 *
57
 */
58
#define CONSOLE_IO_SUPPORT  0 
59
 
60
#if CONSOLE_IO_SUPPORT
61
asm void TrapHandler_printf(void) {
62
   HALT
63
   RTE
64
}
65
#endif                                                   
66
 
67
/***********************************************************************/
68
/*
69
 * This is the handler for all exceptions which are not common to all
70
 * ColdFire Chips.
71
 *
72
 * Called by mcf_exception_handler
73
 *
74
 */
75
void derivative_interrupt(unsigned long vector)
76
{
77
   if (vector < 64 || vector > 192) {
78
      VECTORDISPLAY2("User Defined Vector #%d\n",vector);
79
   }
80
}
81
 
82
/***********************************************************************
83
 *
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.
87
 *
88
 * Called by asm_exception_handler
89
 *
90
 * The ColdFire family of processors has a simplified exception stack
91
 * frame that looks like the following:
92
 *
93
 *              3322222222221111 111111
94
 *              1098765432109876 5432109876543210
95
 *           8 +----------------+----------------+
96
 *             |         Program Counter         |
97
 *           4 +----------------+----------------+
98
 *             |FS/Fmt/Vector/FS|      SR        |
99
 *   SP -->  0 +----------------+----------------+
100
 *
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 +---------------------------------------+------------------------------------+
108
 */
109
#define MCF5XXX_RD_SF_FORMAT(PTR)   \
110
   ((*((unsigned short *)(PTR)) >> 12) & 0x00FF)
111
 
112
#define MCF5XXX_RD_SF_VECTOR(PTR)   \
113
   ((*((unsigned short *)(PTR)) >>  2) & 0x00FF)
114
 
115
#define MCF5XXX_RD_SF_FS(PTR)    \
116
   ( ((*((unsigned short *)(PTR)) & 0x0C00) >> 8) | (*((unsigned short *)(PTR)) & 0x0003) )
117
 
118
#define MCF5XXX_SF_SR(PTR)    *(((unsigned short *)(PTR))+1)
119
 
120
#define MCF5XXX_SF_PC(PTR)    *((unsigned long *)(PTR)+1)
121
 
122
#define MCF5XXX_EXCEPTFMT     "%s -- PC = %#08X\n"
123
 
124
 
125
void mcf_exception_handler(void *framepointer)
126
{
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);
134
 
135
   switch (stackFrameFormat)
136
   {
137
      case 4:
138
      case 5:
139
      case 6:
140
      case 7:
141
         break;
142
      default:
143
         VECTORDISPLAY3(MCF5XXX_EXCEPTFMT,"Illegal stack type", stackFramePC);
144
         break;
145
   }
146
 
147
   switch (stackFrameVector)
148
   {
149
   case 2:
150
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Access Error", stackFramePC);
151
      switch (stackFrameFS)
152
      {
153
         case 4:
154
            VECTORDISPLAY("Error on instruction fetch\n");
155
            break;
156
         case 8:
157
            VECTORDISPLAY("Error on operand write\n");
158
            break;
159
         case 9:
160
            VECTORDISPLAY("Attempted write to write-protected space\n");
161
            break;
162
         case 12:
163
            VECTORDISPLAY("Error on operand read\n");
164
            break;
165
         default:
166
            VECTORDISPLAY("Reserved Fault Status Encoding\n");
167
            break;
168
      }
169
      break;
170
   case 3:
171
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Address Error", stackFramePC);
172
      switch (stackFrameFS)
173
      {
174
         case 4:
175
            VECTORDISPLAY("Error on instruction fetch\n");
176
            break;
177
         case 8:
178
            VECTORDISPLAY("Error on operand write\n");
179
            break;
180
         case 9:
181
            VECTORDISPLAY("Attempted write to write-protected space\n");
182
            break;
183
         case 12:
184
            VECTORDISPLAY("Error on operand read\n");
185
            break;
186
         default:
187
            VECTORDISPLAY("Reserved Fault Status Encoding\n");
188
            break;
189
      }
190
      break;
191
   case 4:
192
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Illegal instruction", stackFramePC);
193
      break;
194
   case 8:
195
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Privilege violation", stackFramePC);
196
      break;
197
   case 9:
198
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Trace Exception", stackFramePC);
199
      break;
200
   case 10:
201
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Unimplemented A-Line Instruction",     stackFramePC);
202
      break;
203
   case 11:
204
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Unimplemented F-Line Instruction",     stackFramePC);
205
      break;
206
   case 12:
207
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Debug Interrupt", stackFramePC);
208
      break;
209
   case 14:
210
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Format Error", stackFramePC);
211
      break;
212
   case 15:
213
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Unitialized Interrupt", stackFramePC);
214
      break;
215
   case 24:
216
      VECTORDISPLAY3(MCF5XXX_EXCEPTFMT, "Spurious Interrupt", stackFramePC);
217
      break;
218
   case 25:
219
   case 26:
220
   case 27:
221
   case 28:
222
   case 29:
223
   case 30:
224
   case 31:
225
      VECTORDISPLAY2("Autovector interrupt level %d\n", stackFrameVector - 24);
226
      break;
227
   case 32:
228
   case 33:
229
   case 34:
230
   case 35:
231
   case 36:
232
   case 37:
233
   case 38:
234
   case 39:
235
   case 40:
236
   case 41:
237
   case 42:
238
   case 43:
239
   case 44:
240
   case 45:
241
   case 46:
242
   case 47:
243
      VECTORDISPLAY2("TRAP #%d\n", stackFrameVector - 32);
244
      break;
245
   case 5:
246
   case 6:
247
   case 7:
248
   case 13:
249
   case 16:
250
   case 17:
251
   case 18:
252
   case 19:
253
   case 20:
254
   case 21:
255
   case 22:
256
   case 23:
257
   case 48:
258
   case 49:
259
   case 50:
260
   case 51:
261
   case 52:
262
   case 53:
263
   case 54:
264
   case 55:
265
   case 56:
266
   case 57:
267
   case 58:
268
   case 59:
269
   case 60:
270
   case 61:
271
   case 62:
272
   case 63:
273
      VECTORDISPLAY2("Reserved: #%d\n", stackFrameVector);
274
      break;
275
   default:
276
      derivative_interrupt(stackFrameVector);
277
   break;
278
   }
279
}
280
 
281
#if REGISTER_ABI
282
asm void asm_exception_handler(void)
283
{
284
   link     a6,#0 
285
   lea     -20(sp), sp
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
290
   lea     20(sp), sp
291
   unlk a6
292
   rte
293
}
294
#else
295
asm void asm_exception_handler(void)
296
{
297
   link     a6,#0 
298
   lea     -20(sp), sp
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
303
   lea     24(sp), sp
304
   unlk a6
305
   rte
306
}
307
#endif
308
 
309
typedef void (* vectorTableEntryType)(void);
310
 
311
#if CONSOLE_IO_SUPPORT
312
vectorTableEntryType vector_printf @Vtrap14     = TrapHandler_printf;
313
#endif
314
 
315
/*
316
 *  MCF51CN128 vector table
317
 *  CF V1 has 114 vector + SP_INIT in the vector table (115 entries)
318
 */
319
 
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;
368
#endif
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;
437
 
438
 
439
 
440
#ifdef __cplusplus
441
}
442
#endif
443
 
444
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.