source: rtems/c/src/lib/libcpu/powerpc/new-exceptions/bspsupport/vectors.h @ 2d2de4eb

4.104.115
Last change on this file since 2d2de4eb was 2d2de4eb, checked in by Thomas Doerfler <Thomas.Doerfler@…>, on 10/23/09 at 07:32:46

Update for exception support changes.

  • Property mode set to 100644
File size: 14.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ppc_exc
5 * @ingroup ppc_exc_frame
6 *
7 * @brief PowerPC Exceptions API.
8 */
9
10/*                                                               
11 * Copyright (C) 1999 Eric Valette (valette@crf.canon.fr)       
12 *                    Canon Centre Recherche France.             
13 *
14 * Copyright (C) 2007 Till Straumann <strauman@slac.stanford.edu>
15 *                                                               
16 * Copyright (C) 2009 embedded brains GmbH.                     
17 *                                                               
18 * Enhanced by Jay Kulpinski <jskulpin@eng01.gdds.com>           
19 * to support 603, 603e, 604, 604e exceptions                   
20 *                                                               
21 * Moved to "libcpu/powerpc/new-exceptions" and consolidated     
22 * by Thomas Doerfler <Thomas.Doerfler@embedded-brains.de>       
23 * to be common for all PPCs with new exceptions.               
24 *                                                               
25 * Derived from file "libcpu/powerpc/new-exceptions/raw_exception.h".
26 * Derived from file "libcpu/powerpc/new-exceptions/bspsupport/ppc_exc_bspsupp.h".
27 *                                                                   
28 * The license and distribution terms for this file may be           
29 * found in found in the file LICENSE in this distribution or at     
30 * http://www.rtems.com/license/LICENSE.                             
31 *                                                                   
32 * $Id$       
33 */
34
35/* DO NOT INTRODUCE #ifdef <cpu_flavor> in this file */
36
37#ifndef LIBCPU_VECTORS_H
38#define LIBCPU_VECTORS_H
39
40#include <libcpu/powerpc-utility.h>
41
42/**
43 * @defgroup ppc_exc PowerPC Exceptions
44 *
45 * @brief XXX
46 *
47 * @{
48 */
49
50#define ASM_RESET_VECTOR                     0x01
51#define ASM_MACH_VECTOR                      0x02
52#define ASM_PROT_VECTOR                      0x03
53#define ASM_ISI_VECTOR                       0x04
54#define ASM_EXT_VECTOR                       0x05
55#define ASM_ALIGN_VECTOR                     0x06
56#define ASM_PROG_VECTOR                      0x07
57#define ASM_FLOAT_VECTOR                     0x08
58#define ASM_DEC_VECTOR                       0x09
59#define ASM_SYS_VECTOR                       0x0C
60#define ASM_TRACE_VECTOR                     0x0D
61
62#define ASM_BOOKE_CRIT_VECTOR                0x01
63/* We could use the std. decrementer vector # on bookE, too,
64 * but the bookE decrementer has slightly different semantics
65 * so we use a different vector (which happens to be
66 * the PIT vector on the 405 which is like the booke decrementer)
67 */
68#define ASM_BOOKE_DEC_VECTOR                 0x10
69#define ASM_BOOKE_ITLBMISS_VECTOR            0x11
70#define ASM_BOOKE_DTLBMISS_VECTOR            0x12
71#define ASM_BOOKE_FIT_VECTOR                 0x13
72#define ASM_BOOKE_WDOG_VECTOR                0x14
73
74#define ASM_PPC405_APU_UNAVAIL_VECTOR        ASM_60X_VEC_ASSIST_VECTOR
75
76#define ASM_8XX_FLOATASSIST_VECTOR           0x0E
77#define ASM_8XX_SOFTEMUL_VECTOR              0x10
78#define ASM_8XX_ITLBMISS_VECTOR              0x11
79#define ASM_8XX_DTLBMISS_VECTOR              0x12
80#define ASM_8XX_ITLBERROR_VECTOR             0x13
81#define ASM_8XX_DTLBERROR_VECTOR             0x14
82#define ASM_8XX_DBREAK_VECTOR                0x1C
83#define ASM_8XX_IBREAK_VECTOR                0x1D
84#define ASM_8XX_PERIFBREAK_VECTOR            0x1E
85#define ASM_8XX_DEVPORT_VECTOR               0x1F
86
87#define ASM_5XX_FLOATASSIST_VECTOR           0x0E
88#define ASM_5XX_SOFTEMUL_VECTOR              0x10
89#define ASM_5XX_IPROT_VECTOR                 0x13
90#define ASM_5XX_DPROT_VECTOR                 0x14
91#define ASM_5XX_DBREAK_VECTOR                0x1C
92#define ASM_5XX_IBREAK_VECTOR                0x1D
93#define ASM_5XX_MEBREAK_VECTOR               0x1E
94#define ASM_5XX_NMEBREAK_VECTOR              0x1F
95
96#define ASM_60X_VEC_VECTOR                   0x0A
97#define ASM_60X_PERFMON_VECTOR               0x0F
98#define ASM_60X_IMISS_VECTOR                 0x10
99#define ASM_60X_DLMISS_VECTOR                0x11
100#define ASM_60X_DSMISS_VECTOR                0x12
101#define ASM_60X_ADDR_VECTOR                  0x13
102#define ASM_60X_SYSMGMT_VECTOR               0x14
103#define ASM_60X_VEC_ASSIST_VECTOR            0x16
104#define ASM_60X_ITM_VECTOR                   0x17
105
106/* e200 */
107#define ASM_E200_SPE_UNAVAILABLE_VECTOR      0x15
108#define ASM_E200_SPE_DATA_VECTOR             0x16
109#define ASM_E200_SPE_ROUND_VECTOR            0x17
110
111/* e300 */
112#define ASM_E300_CRIT_VECTOR                 0x0A
113#define ASM_E300_PERFMON_VECTOR              0x0F
114#define ASM_E300_IMISS_VECTOR                ASM_60X_IMISS_VECTOR  /* Special case: Shadowed GPRs */
115#define ASM_E300_DLMISS_VECTOR               ASM_60X_DLMISS_VECTOR /* Special case: Shadowed GPRs */
116#define ASM_E300_DSMISS_VECTOR               ASM_60X_DSMISS_VECTOR /* Special case: Shadowed GPRs */
117#define ASM_E300_ADDR_VECTOR                 0x13
118#define ASM_E300_SYSMGMT_VECTOR              0x14
119
120/*
121 * If you change that number make sure to adjust the wrapper code in ppc_exc.S
122 * and that ppc_exc_handler_table will be correctly initialized.
123 */
124#define LAST_VALID_EXC                       0x1F
125
126/* DO NOT USE -- this symbol is DEPRECATED
127 * (only used by libbsp/shared/vectors/vectors.S
128 * which should not be used by new BSPs).
129 */
130#define ASM_60X_VEC_VECTOR_OFFSET            0xf20
131
132#define ASM_PPC405_FIT_VECTOR_OFFSET         0x1010
133#define ASM_PPC405_WDOG_VECTOR_OFFSET        0x1020
134#define ASM_PPC405_TRACE_VECTOR_OFFSET       0x2000
135
136/** @} */
137
138/**
139 * @defgroup ppc_exc_frame PowerPC Exception Frame
140 *
141 * @brief XXX
142 *
143 * @{
144 */
145
146/*
147 * The callee (high level exception code written in C)
148 * will store the Link Registers (return address) at entry r1 + 4 !!!.
149 * So let room for it!!!.
150 */
151#define LINK_REGISTER_CALLEE_UPDATE_ROOM 4
152#define SRR0_FRAME_OFFSET 8
153#define SRR1_FRAME_OFFSET 12
154#define EXCEPTION_NUMBER_OFFSET 16
155#define GPR0_OFFSET 20
156#define GPR1_OFFSET 24
157#define GPR2_OFFSET 28
158#define GPR3_OFFSET 32
159#define GPR4_OFFSET 36
160#define GPR5_OFFSET 40
161#define GPR6_OFFSET 44
162#define GPR7_OFFSET 48
163#define GPR8_OFFSET 52
164#define GPR9_OFFSET 56
165#define GPR10_OFFSET 60
166#define GPR11_OFFSET 64
167#define GPR12_OFFSET 68
168#define GPR13_OFFSET 72
169#define GPR14_OFFSET 76
170#define GPR15_OFFSET 80
171#define GPR16_OFFSET 84
172#define GPR17_OFFSET 88
173#define GPR18_OFFSET 92
174#define GPR19_OFFSET 96
175#define GPR20_OFFSET 100
176#define GPR21_OFFSET 104
177#define GPR22_OFFSET 108
178#define GPR23_OFFSET 112
179#define GPR24_OFFSET 116
180#define GPR25_OFFSET 120
181#define GPR26_OFFSET 124
182#define GPR27_OFFSET 128
183#define GPR28_OFFSET 132
184#define GPR29_OFFSET 136
185#define GPR30_OFFSET 140
186#define GPR31_OFFSET 144
187#define EXC_CR_OFFSET 148
188#define EXC_CTR_OFFSET 152
189#define EXC_XER_OFFSET 156
190#define EXC_LR_OFFSET 160
191
192/* Exception stack frame -> BSP_Exception_frame */
193#define FRAME_LINK_SPACE 8
194
195/*
196 * maintain the EABI requested 8 bytes aligment
197 * As SVR4 ABI requires 16, make it 16 (as some
198 * exception may need more registers to be processed...)
199 */
200#define EXCEPTION_FRAME_END 176
201
202/** @} */
203
204#ifndef ASM
205
206/**
207 * @ingroup ppc_exc_frame
208 *
209 * @{
210 */
211
212typedef struct {
213  unsigned EXC_SRR0;
214  unsigned EXC_SRR1;
215  unsigned _EXC_number;
216  unsigned GPR0;
217  unsigned GPR1;
218  unsigned GPR2;
219  unsigned GPR3;
220  unsigned GPR4;
221  unsigned GPR5;
222  unsigned GPR6;
223  unsigned GPR7;
224  unsigned GPR8;
225  unsigned GPR9;
226  unsigned GPR10;
227  unsigned GPR11;
228  unsigned GPR12;
229  unsigned GPR13;
230  unsigned GPR14;
231  unsigned GPR15;
232  unsigned GPR16;
233  unsigned GPR17;
234  unsigned GPR18;
235  unsigned GPR19;
236  unsigned GPR20;
237  unsigned GPR21;
238  unsigned GPR22;
239  unsigned GPR23;
240  unsigned GPR24;
241  unsigned GPR25;
242  unsigned GPR26;
243  unsigned GPR27;
244  unsigned GPR28;
245  unsigned GPR29;
246  unsigned GPR30;
247  unsigned GPR31;
248  unsigned EXC_CR;
249  unsigned EXC_CTR;
250  unsigned EXC_XER;
251  unsigned EXC_LR;
252  unsigned EXC_MSR;
253  unsigned EXC_DAR;
254} BSP_Exception_frame;
255
256/** @} */
257
258/**
259 * @ingroup ppc_exc
260 *
261 * @{
262 */
263
264/**
265 * @brief Global exception handler type.
266 */
267typedef void (*exception_handler_t)(BSP_Exception_frame*);
268
269/**
270 * @brief Global exception handler.
271 */
272extern exception_handler_t globalExceptHdl;
273
274/**
275 * @brief Default global exception handler.
276 */
277void C_exception_handler(BSP_Exception_frame* excPtr);
278
279void BSP_printStackTrace(BSP_Exception_frame *excPtr);
280
281/**
282 * @brief Exception categories.
283 *
284 * Exceptions of different categories use different SRR registers to save the
285 * machine state and do different things in the prologue and epilogue.
286 *
287 * For now, the CPU descriptions assume this fits into 8 bits.
288 */
289typedef enum {
290  PPC_EXC_INVALID = 0,
291  PPC_EXC_ASYNC = 1,
292  PPC_EXC_CLASSIC = 2,
293  PPC_EXC_CLASSIC_ASYNC = PPC_EXC_CLASSIC | PPC_EXC_ASYNC,
294  PPC_EXC_405_CRITICAL = 4,
295  PPC_EXC_405_CRITICAL_ASYNC = PPC_EXC_405_CRITICAL | PPC_EXC_ASYNC,
296  PPC_EXC_BOOKE_CRITICAL = 6,
297  PPC_EXC_BOOKE_CRITICAL_ASYNC = PPC_EXC_BOOKE_CRITICAL | PPC_EXC_ASYNC,
298  PPC_EXC_E500_MACHCHK  = 8,
299  PPC_EXC_E500_MACHCHK_ASYNC = PPC_EXC_E500_MACHCHK | PPC_EXC_ASYNC,
300  PPC_EXC_NAKED = 10
301} ppc_exc_category;
302
303/**
304 * @brief Categorie set type.
305 */
306typedef uint8_t ppc_exc_categories [LAST_VALID_EXC + 1];
307
308static inline bool ppc_exc_is_valid_category(ppc_exc_category category)
309{
310  return (unsigned) category <= (unsigned) PPC_EXC_NAKED;
311}
312
313/**
314 * @brief Indicates if exception entry table resides in a writable memory.
315 *
316 * This variable is initialized to 'TRUE' by default;
317 * BSPs which have their vectors in ROM should set it
318 * to FALSE prior to initializing raw exceptions.
319 *
320 * I suspect the only candidate is the simulator.
321 * After all, the value of this variable is used to
322 * determine where to install the prologue code and
323 * installing to ROM on anyting that's real ROM
324 * will fail anyways.
325 *
326 * This should probably go away... (T.S. 2007/11/30)
327 */
328extern bool bsp_exceptions_in_RAM;
329
330/**
331 * @brief Vector base address for CPUs (for example e200 and e500) with IVPR
332 * and IVOR registers.
333 */
334extern uint32_t ppc_exc_vector_base;
335
336/**
337 * @brief Returns the entry address of the vector @a vector.
338 */
339void *ppc_exc_vector_address(unsigned vector);
340
341/**
342 * @brief Returns the category set for a CPU of type @a cpu, or @c NULL if
343 * there is no category set available for this CPU.
344 */
345const ppc_exc_categories *ppc_exc_categories_for_cpu(ppc_cpu_id_t cpu);
346
347/**
348 * @brief Returns the category set for the current CPU, or @c NULL if there is
349 * no category set available for this CPU.
350 */
351static inline const ppc_exc_categories *ppc_exc_current_categories(void)
352{
353  return ppc_exc_categories_for_cpu(ppc_cpu_current());
354}
355
356/**
357 * @brief Returns the category for the vector @a vector using the category set
358 * @a categories.
359 */
360ppc_exc_category ppc_exc_category_for_vector(
361  const ppc_exc_categories *categories,
362  unsigned vector
363);
364
365/**
366 * @brief Makes a minimal prologue for the vector @a vector with the category
367 * @a category.
368 *
369 * The minimal prologue will be copied to @a prologue.  Not more than @a
370 * prologue_size bytes will be copied.  Returns the actual minimal prologue
371 * size in bytes in @a prologue_size.
372 *
373 * @retval RTEMS_SUCCESSFUL Minimal prologue successfully made.
374 * @retval RTEMS_INVALID_ID Invalid vector number.
375 * @retval RTEMS_INVALID_NUMBER Invalid category.
376 * @retval RTEMS_INVALID_SIZE Prologue size to small.
377 */
378rtems_status_code ppc_exc_make_prologue(
379  unsigned vector,
380  ppc_exc_category category,
381  uint32_t *prologue,
382  size_t *prologue_size
383);
384
385/**
386 * @brief Initializes the exception handling.
387 *
388 * @retval RTEMS_SUCCESSFUL Successful initialization.
389 * @retval RTEMS_NOT_IMPLEMENTED No category set available for the current CPU.
390 * @retval RTEMS_NOT_CONFIGURED Register r13 does not point to the small data
391 * area anchor required by SVR4/EABI.
392 * @retval RTEMS_INTERNAL_ERROR Minimal prologue creation failed.
393 */
394rtems_status_code ppc_exc_initialize(
395  uint32_t interrupt_disable_mask,
396  uintptr_t interrupt_stack_begin,
397  uintptr_t interrupt_stack_size
398);
399
400/**
401 * @brief High-level exception handler type.
402 *
403 * Exception handlers should return zero if the exception was handled and
404 * normal execution may resume.
405 *
406 * They should return minus one to reject the exception resulting in the
407 * globalExcHdl() being called.
408 *
409 * Other return values are reserved.
410 */
411typedef int (*ppc_exc_handler_t)(BSP_Exception_frame *f, unsigned vector);
412
413/**
414 * @brief Bits for MSR update.
415 *
416 * Bits in MSR that are enabled during execution of exception handlers / ISRs
417 * (on classic PPC these are DR/IR/RI [default], on bookE-style CPUs they should
418 * be set to 0 during initialization)
419 *
420 * By default, the setting of these bits that is in effect when exception
421 * handling is initialized is used.
422 */
423extern uint32_t ppc_exc_msr_bits;
424
425/**
426 * @brief Cache write back check flag.
427 *
428 * (See README under CAVEATS). During initialization
429 * a check is performed to assert that write-back
430 * caching is enabled for memory accesses. If a BSP
431 * runs entirely without any caching then it should
432 * set this variable to zero prior to initializing
433 * exceptions in order to skip the test.
434 * NOTE: The code does NOT support mapping memory
435 *       with cache-attributes other than write-back
436 *       (unless the entire cache is physically disabled)
437 */
438extern uint32_t ppc_exc_cache_wb_check;
439
440/**
441 * @brief Set high-level exception handler.
442 *
443 * Hook C exception handlers.
444 *  - handlers for asynchronous exceptions run on the ISR stack
445 *    with thread-dispatching disabled.
446 *  - handlers for synchronous exceptions run on the task stack
447 *    with thread-dispatching enabled.
448 *
449 * If a particular slot is NULL then the traditional 'globalExcHdl' is used.
450 *
451 * ppc_exc_set_handler() registers a handler (returning 0 on success,
452 * -1 if the vector argument is too big).
453 *
454 * It is legal to set a NULL handler. This leads to the globalExcHdl
455 * being called if an exception for 'vector' occurs.
456 */
457rtems_status_code ppc_exc_set_handler(unsigned vector, ppc_exc_handler_t hdl);
458
459/**
460 * @brief Returns the currently active high-level exception handler.
461 */
462ppc_exc_handler_t ppc_exc_get_handler(unsigned vector);
463
464/**
465 * @brief Function for DAR access.
466 *
467 * CPU support may store the address of a function here
468 * that can be used by the default exception handler to
469 * obtain fault-address info which is helpful. Unfortunately,
470 * the SPR holding this information is not uniform
471 * across PPC families so we need assistance from
472 * CPU support
473 */
474extern uint32_t (*ppc_exc_get_DAR)(void);
475
476void
477ppc_exc_wrapup(BSP_Exception_frame *f);
478
479/** @} */
480
481/*
482 * Compatibility with pc386
483 */
484typedef BSP_Exception_frame CPU_Exception_frame;
485typedef exception_handler_t cpuExcHandlerType;
486
487#endif /* ASM */
488
489#endif /* LIBCPU_VECTORS_H */
Note: See TracBrowser for help on using the repository browser.