1 | /* PowerPC exception handling middleware; consult README for more |
---|
2 | * information. |
---|
3 | * |
---|
4 | * Author: Till Straumann <strauman@slac.stanford.edu>, 2007 |
---|
5 | * |
---|
6 | * The license and distribution terms for this file may be |
---|
7 | * found in found in the file LICENSE in this distribution or at |
---|
8 | * http://www.rtems.com/license/LICENSE. |
---|
9 | * |
---|
10 | * $Id$ |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef PPC_EXC_SHARED_H |
---|
14 | #define PPC_EXC_SHARED_H |
---|
15 | |
---|
16 | #include <stdint.h> |
---|
17 | |
---|
18 | #include "vectors.h" |
---|
19 | |
---|
20 | #ifdef __cplusplus |
---|
21 | extern "C" { |
---|
22 | #endif |
---|
23 | |
---|
24 | /********* C-Exception Handlers *********************/ |
---|
25 | |
---|
26 | /* API to be used by middleware, */ |
---|
27 | /* BSP and application code (if necessary) */ |
---|
28 | |
---|
29 | /****************************************************/ |
---|
30 | |
---|
31 | /* |
---|
32 | * Exception handlers should return 0 if the exception |
---|
33 | * was handled and normal execution may resume. |
---|
34 | * |
---|
35 | * They should return (-1) to 'rethrow' the exception |
---|
36 | * resulting in the globalExcHdl() being called. |
---|
37 | * |
---|
38 | * Other return values are reserved. |
---|
39 | */ |
---|
40 | typedef int (*ppc_exc_handler_t)(BSP_Exception_frame *f, unsigned int vector); |
---|
41 | |
---|
42 | /* |
---|
43 | * Bits in MSR that are enabled during execution of exception handlers / ISRs |
---|
44 | * (on classic PPC these are DR/IR/RI [default], on bookE-style CPUs they should |
---|
45 | * be set to 0 during initialization) |
---|
46 | * |
---|
47 | * By default, the setting of these bits that is in effect when exception |
---|
48 | * handling is initialized is used. |
---|
49 | */ |
---|
50 | extern uint32_t ppc_exc_msr_bits; |
---|
51 | |
---|
52 | /* (See README under CAVEATS). During initialization |
---|
53 | * a check is performed to assert that write-back |
---|
54 | * caching is enabled for memory accesses. If a BSP |
---|
55 | * runs entirely without any caching then it should |
---|
56 | * set this variable to zero prior to initializing |
---|
57 | * exceptions in order to skip the test. |
---|
58 | * NOTE: The code does NOT support mapping memory |
---|
59 | * with cache-attributes other than write-back |
---|
60 | * (unless the entire cache is physically disabled) |
---|
61 | */ |
---|
62 | extern uint32_t ppc_exc_cache_wb_check; |
---|
63 | |
---|
64 | /* |
---|
65 | * Hook C exception handlers. |
---|
66 | * - handlers for asynchronous exceptions run on the ISR stack |
---|
67 | * with thread-dispatching disabled. |
---|
68 | * - handlers for synchronous exceptions run on the task stack |
---|
69 | * with thread-dispatching enabled. |
---|
70 | * |
---|
71 | * If a particular slot is NULL then the traditional 'globalExcHdl' is used. |
---|
72 | * |
---|
73 | * ppc_exc_set_handler() registers a handler (returning 0 on success, |
---|
74 | * -1 if the vector argument is too big). |
---|
75 | * |
---|
76 | * It is legal to set a NULL handler. This leads to the globalExcHdl |
---|
77 | * being called if an exception for 'vector' occurs. |
---|
78 | */ |
---|
79 | int |
---|
80 | ppc_exc_set_handler(unsigned vector, ppc_exc_handler_t hdl); |
---|
81 | |
---|
82 | /* ppc_exc_get_handler() retrieves the currently active handler. |
---|
83 | */ |
---|
84 | ppc_exc_handler_t |
---|
85 | ppc_exc_get_handler(unsigned vector); |
---|
86 | |
---|
87 | /********* Low-level Exception Handlers *************/ |
---|
88 | |
---|
89 | /* This part of the API is used by middleware code */ |
---|
90 | |
---|
91 | /****************************************************/ |
---|
92 | |
---|
93 | typedef uint32_t ppc_exc_min_prolog_t[4]; |
---|
94 | |
---|
95 | /* Templates are ppc_raw_except_func BUT they must be exactly 16 bytes */ |
---|
96 | typedef rtems_raw_except_func ppc_exc_min_prolog_template_t; |
---|
97 | |
---|
98 | /* |
---|
99 | * Expand a prolog template into 'buf' using vector 'vec' |
---|
100 | */ |
---|
101 | void |
---|
102 | ppc_exc_min_prolog_expand(ppc_exc_min_prolog_t buf, ppc_exc_min_prolog_template_t templ, uint16_t vec); |
---|
103 | |
---|
104 | extern unsigned ppc_exc_min_prolog_size[]; |
---|
105 | /* Symbols are defined by the linker; declare as an array so |
---|
106 | * that gcc doesn't attempt to emit a relocation looking for |
---|
107 | * it in the SDA section |
---|
108 | */ |
---|
109 | extern unsigned ppc_exc_tgpr_clr_prolog_size[]; |
---|
110 | |
---|
111 | /* Templates for ppc_exc_min_prolog_expand() which fills-in the vector information */ |
---|
112 | extern void ppc_exc_min_prolog_async_tmpl_std(void); |
---|
113 | extern void ppc_exc_min_prolog_sync_tmpl_std(void); |
---|
114 | extern void ppc_exc_min_prolog_async_tmpl_p405_crit(void); |
---|
115 | extern void ppc_exc_min_prolog_sync_tmpl_p405_crit(void); |
---|
116 | extern void ppc_exc_min_prolog_async_tmpl_bookE_crit(void); |
---|
117 | extern void ppc_exc_min_prolog_sync_tmpl_bookE_crit(void); |
---|
118 | extern void ppc_exc_min_prolog_sync_tmpl_e500_mchk(void); |
---|
119 | extern void ppc_exc_min_prolog_async_tmpl_e500_mchk(void); |
---|
120 | |
---|
121 | /* Special prologue for handling register shadowing on 603-style CPUs */ |
---|
122 | extern void ppc_exc_tgpr_clr_prolog(void); |
---|
123 | /* Classic prologue which determines the vector dynamically from |
---|
124 | * the offset address. This must only be used for classic, synchronous |
---|
125 | * exceptions with a vector offset aligned on a 256-byte boundary. |
---|
126 | */ |
---|
127 | extern void ppc_exc_min_prolog_auto(void); |
---|
128 | |
---|
129 | extern void ppc_exc_min_prolog_auto_packed(void); |
---|
130 | |
---|
131 | |
---|
132 | /* CPU support may store the address of a function here |
---|
133 | * that can be used by the default exception handler to |
---|
134 | * obtain fault-address info which is helpful. Unfortunately, |
---|
135 | * the SPR holding this information is not uniform |
---|
136 | * across PPC families so we need assistance from |
---|
137 | * CPU support |
---|
138 | */ |
---|
139 | extern uint32_t (*ppc_exc_get_DAR)(void); |
---|
140 | |
---|
141 | #ifdef __cplusplus |
---|
142 | }; |
---|
143 | #endif |
---|
144 | |
---|
145 | #endif |
---|