1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
32 33 34 35
36
37 package ti.sysbios.family.arm.exc;
38
39 import xdc.rov.ViewInfo;
40
41 import xdc.runtime.Error;
42
43 import ti.sysbios.BIOS;
44
45 /*!
46 * ======== Exception ========
47 * Exception Module
48 *
49 * The Exception module is a basic ARM exception handler.
50 * When an exception occurs, the execution state is saved into
51 * a buffer with a structure of type {@link #ExcContext ExcContext}.
52 *
53 * By default, a formatted dump of this structure is also sent to
54 * the console using System_printf(). This behavior can be suppressed
55 * by setting the {@link #enableDecode} config parameter to 'false'.
56 *
57 * An ROV view of the exception context is provided when
58 * attached to the target board with CCS.
59 *
60 * @a(Notes)
61 * No attempt is made to return from an exception as these are
62 * generally fatal in nature.
63 *
64 * When used, the Exception module will override the default
65 * exception handlers provided by the current Hwi module.
66 */
67
68 @ModuleStartup
69 module Exception
70 {
71 /*! Exception hook function type definition. */
72 typedef Void (*ExceptionHookFuncPtr)(ExcContext *);
73
74
75 enum Type {
76 Type_Supervisor = 0x13, /*! Supervisor (SWI). */
77 Type_PreAbort = 0x17, /*! Abort exception. */
78 Type_DataAbort = 0x18, /*! Abort exception. */
79 Type_UndefInst = 0x1b /*! Undefined instruction exception. */
80 };
81
82 /*!
83 * Exception Context - Register contents at the time of an exception.
84 */
85 struct ExcContext {
86
87 BIOS.ThreadType threadType;
88
89 Ptr threadHandle;
90
91 Ptr threadStack;
92
93
94 SizeT threadStackSize;
95
96 Type type;
97
98
99 Ptr r0;
100 Ptr r1;
101 Ptr r2;
102 Ptr r3;
103 Ptr r4;
104 Ptr r5;
105 Ptr r6;
106 Ptr r7;
107 Ptr r8;
108 Ptr r9;
109 Ptr r10;
110 Ptr r11;
111 Ptr r12;
112 Ptr sp;
113 Ptr lr;
114 Ptr pc;
115 Ptr psr;
116 }
117
118 @Facet
119 metaonly config ViewInfo.Instance rovViewInfo =
120 ViewInfo.create({
121 viewMap: [
122 ['Basic',
123 {
124 type: ViewInfo.TREE,
125 viewInitFxn: 'viewInitBasic',
126 structName: 'ExcContext'
127 }
128 ]
129 ]
130 });
131
132 /*! Error raised when a SWI exception occurs */
133 config Error.Id E_swi = {
134 msg: "E_swi: pc = 0x%08x, lr = 0x%08x."
135 };
136
137 /*! Error raised when an prefetch abort exception occurs */
138 config Error.Id E_prefetchAbort = {
139 msg: "E_prefetchAbort: pc = 0x%08x, lr = 0x%08x."
140 };
141
142 /*! Error raised when an data abort exception occurs */
143 config Error.Id E_dataAbort = {
144 msg: "E_dataAbort: pc = 0x%08x, lr = 0x%08x."
145 };
146
147 /*! Error raised when an undefined instruction exception occurs */
148 config Error.Id E_undefinedInstruction = {
149 msg: "E_undefinedInstruction: pc = 0x%08x, lr = 0x%08x."
150 };
151
152 /*!
153 * Enable full exception decoding, default is true.
154 *
155 * When enabled, the exception handler will fully
156 * decode an exception and dump the registers to the
157 * system console.
158 *
159 * When set to false, only an Error is printed on the console.
160 *
161 * In either case, the full exception context is always
162 * saved and visible with ROV.
163 */
164 config Bool enableDecode = true;
165
166 /*! @_nodoc
167 * Exception stack pointer. Default = null.
168 * (Indicates that stack is to be created using
169 * staticPlace()
170 */
171 config Ptr excStack = null;
172
173 /*!
174 * Exception stack size in MAUs.
175 * Default is 128 bytes.
176 */
177 metaonly config SizeT excStackSize = 128;
178
179 /*!
180 * Memory section used for Exception stack.
181 * Default is null, which results in the stack
182 * being placed in .bss.
183 */
184 metaonly config String excStackSection = null;
185
186 /*!
187 * User Exception Context Buffer Address
188 *
189 * By default, when an exception occurs, an {@link #ExcContext}
190 * structure is allocated on the exception stack and filled in
191 * by the exception handler.
192 *
193 * If {@link #excContextBuffer} is initialized by the user, the
194 * {@link #ExcContext} structure will be placed at that address instead.
195 *
196 * The buffer must be large enough to contain an {@link #ExcContext}
197 * structure.
198 */
199 metaonly config Ptr excContextBuffer;
200
201 /*!
202 * User Exception Stack Buffer Address
203 *
204 * When an exception occurs, a pointer to the base address
205 * of the stack being used by the thread causing the exception is stored
206 * in the ExcContext buffer.
207 *
208 * If {@link #excStackBuffer} is initialized by the user, the
209 * entire contents of that stack will also be
210 * copied to the address specified.
211 *
212 * The buffer must be large enough to contain the largest task stack or ISR
213 * stack defined in the application.
214 */
215 metaonly config Ptr excStackBuffer;
216
217 /*!
218 * User Exception hook function.
219 *
220 * Called just after exception context has been initialized.
221 */
222 config ExceptionHookFuncPtr excHookFunc = null;
223
224 internal:
225
226
227 Void init();
228
229 /*!
230 * ======== excHandlerAsm ========
231 * asm code common exception handler
232 */
233 Void excHandlerAsm();
234
235 /*!
236 * ======== excHandlerDataAsm ========
237 * asm code Data Abort exception handler
238 */
239 Void excHandlerDataAsm();
240
241 /*!
242 * ======== excHandler ========
243 * C function exception Handler
244 */
245 Void excHandler(UInt *excStack, UInt lr);
246
247 /*!
248 * ======== excDumpContext ========
249 */
250 Void excDumpContext(UInt pc);
251
252 struct Module_State {
253 Bool excActive;
254 ExcContext *excContext;
255 Ptr excStackBuffer;
256 Char excStack[];
257 SizeT excStackSize;
258 };
259 }
260 261 262 263
264