]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5_bsp/psu_cortexr5_0/libsrc/standalone_v6_6/src/xil_exception.c
Update Zynq, MPSoc Cortex-A53 and MPSoc Cortex-R5 demo projects to build with the...
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5_bsp / psu_cortexr5_0 / libsrc / standalone_v6_6 / src / xil_exception.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2015 - 2016 Xilinx, Inc.  All rights reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * Use of the Software is limited solely to applications:
16 * (a) running on a Xilinx device, or
17 * (b) that interact with a Xilinx device through a bus or interconnect.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * XILINX  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 *
27 * Except as contained in this notice, the name of the Xilinx shall not be used
28 * in advertising or otherwise to promote the sale, use or other dealings in
29 * this Software without prior written authorization from Xilinx.
30 *
31 ******************************************************************************/
32 /****************************************************************************/
33 /**
34 *
35 * @file xil_exception.c
36 *
37 * This file contains low-level driver functions for the Cortex A53,A9,R5 exception
38 * Handler.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
43 * Ver   Who      Date     Changes
44 * ----- -------- -------- -----------------------------------------------
45 * 5.2   pkp      28/05/15 First release
46 * 6.0   mus      27/07/16 Consolidated exceptions for a53,a9 and r5
47 *                         processors and added Xil_UndefinedExceptionHandler
48 *                         for a53 32 bit and r5 as well.
49 * 6.4   mus      08/06/17 Updated debug prints to replace %x with the %lx, to
50 *                         fix the warnings.
51 * </pre>
52 *
53 *****************************************************************************/
54
55 /***************************** Include Files ********************************/
56
57 #include "xil_types.h"
58 #include "xil_assert.h"
59 #include "xil_exception.h"
60 #include "xpseudo_asm.h"
61 #include "xdebug.h"
62 /************************** Constant Definitions ****************************/
63
64 /**************************** Type Definitions ******************************/
65
66 typedef struct {
67         Xil_ExceptionHandler Handler;
68         void *Data;
69 } XExc_VectorTableEntry;
70
71 /***************** Macros (Inline Functions) Definitions ********************/
72
73 /************************** Function Prototypes *****************************/
74 static void Xil_ExceptionNullHandler(void *Data);
75 /************************** Variable Definitions *****************************/
76 /*
77  * Exception vector table to store handlers for each exception vector.
78  */
79 #if defined (__aarch64__)
80 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
81 {
82         {Xil_ExceptionNullHandler, NULL},
83         {Xil_SyncAbortHandler, NULL},
84         {Xil_ExceptionNullHandler, NULL},
85         {Xil_ExceptionNullHandler, NULL},
86         {Xil_SErrorAbortHandler, NULL},
87
88 };
89 #else
90 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
91 {
92         {Xil_ExceptionNullHandler, NULL},
93         {Xil_UndefinedExceptionHandler, NULL},
94         {Xil_ExceptionNullHandler, NULL},
95         {Xil_PrefetchAbortHandler, NULL},
96         {Xil_DataAbortHandler, NULL},
97         {Xil_ExceptionNullHandler, NULL},
98         {Xil_ExceptionNullHandler, NULL},
99 };
100 #endif
101 #if !defined (__aarch64__)
102 u32 DataAbortAddr;       /* Address of instruction causing data abort */
103 u32 PrefetchAbortAddr;   /* Address of instruction causing prefetch abort */
104 u32 UndefinedExceptionAddr;   /* Address of instruction causing Undefined
105                                                              exception */
106 #endif
107
108 /*****************************************************************************/
109
110 /****************************************************************************/
111 /**
112 *
113 * This function is a stub Handler that is the default Handler that gets called
114 * if the application has not setup a Handler for a specific  exception. The
115 * function interface has to match the interface specified for a Handler even
116 * though none of the arguments are used.
117 *
118 * @param        Data is unused by this function.
119 *
120 * @return       None.
121 *
122 * @note         None.
123 *
124 *****************************************************************************/
125 static void Xil_ExceptionNullHandler(void *Data)
126 {
127         (void) Data;
128 DieLoop: goto DieLoop;
129 }
130
131 /****************************************************************************/
132 /**
133 * @brief        The function is a common API used to initialize exception handlers
134 *                       across all supported arm processors. For ARM Cortex-A53, Cortex-R5,
135 *                       and Cortex-A9, the exception handlers are being initialized
136 *                       statically and this function does not do anything.
137 *                       However, it is still present to take care of backward compatibility
138 *                       issues (in earlier versions of BSPs, this API was being used to
139 *                       initialize exception handlers).
140 *
141 * @param        None.
142 *
143 * @return       None.
144 *
145 * @note         None.
146 *
147 *****************************************************************************/
148 void Xil_ExceptionInit(void)
149 {
150         return;
151 }
152
153 /*****************************************************************************/
154 /**
155 * @brief        Register a handler for a specific exception. This handler is being
156 *                       called when the processor encounters the specified exception.
157 *
158 * @param        exception_id contains the ID of the exception source and should
159 *                       be in the range of 0 to XIL_EXCEPTION_ID_LAST.
160 *                       See xil_exception.h for further information.
161 * @param        Handler to the Handler for that exception.
162 * @param        Data is a reference to Data that will be passed to the
163 *                       Handler when it gets called.
164 *
165 * @return       None.
166 *
167 * @note         None.
168 *
169 ****************************************************************************/
170 void Xil_ExceptionRegisterHandler(u32 Exception_id,
171                                     Xil_ExceptionHandler Handler,
172                                     void *Data)
173 {
174         XExc_VectorTable[Exception_id].Handler = Handler;
175         XExc_VectorTable[Exception_id].Data = Data;
176 }
177
178 /*****************************************************************************/
179 /**
180 *
181 * @brief        Removes the Handler for a specific exception Id. The stub Handler
182 *                       is then registered for this exception Id.
183 *
184 * @param        exception_id contains the ID of the exception source and should
185 *                       be in the range of 0 to XIL_EXCEPTION_ID_LAST.
186 *                       See xil_exception.h for further information.
187 *
188 * @return       None.
189 *
190 * @note         None.
191 *
192 ****************************************************************************/
193 void Xil_ExceptionRemoveHandler(u32 Exception_id)
194 {
195         Xil_ExceptionRegisterHandler(Exception_id,
196                                        Xil_ExceptionNullHandler,
197                                        NULL);
198 }
199
200 #if defined (__aarch64__)
201 /*****************************************************************************/
202 /**
203 *
204 * Default Synchronous abort handler which prints a debug message on console if
205 * Debug flag is enabled
206 *
207 * @param        None
208 *
209 * @return       None.
210 *
211 * @note         None.
212 *
213 ****************************************************************************/
214
215 void Xil_SyncAbortHandler(void *CallBackRef){
216         (void) CallBackRef;
217         xdbg_printf(XDBG_DEBUG_ERROR, "Synchronous abort \n");
218         while(1) {
219                 ;
220         }
221 }
222
223 /*****************************************************************************/
224 /**
225 *
226 * Default SError abort handler which prints a debug message on console if
227 * Debug flag is enabled
228 *
229 * @param        None
230 *
231 * @return       None.
232 *
233 * @note         None.
234 *
235 ****************************************************************************/
236 void Xil_SErrorAbortHandler(void *CallBackRef){
237         (void) CallBackRef;
238         xdbg_printf(XDBG_DEBUG_ERROR, "Synchronous abort \n");
239         while(1) {
240                 ;
241         }
242 }
243 #else
244 /*****************************************************************************/
245 /*
246 *
247 * Default Data abort handler which prints data fault status register through
248 * which information about data fault can be acquired
249 *
250 * @param        None
251 *
252 * @return       None.
253 *
254 * @note         None.
255 *
256 ****************************************************************************/
257
258 void Xil_DataAbortHandler(void *CallBackRef){
259         (void) CallBackRef;
260 #ifdef DEBUG
261         u32 FaultStatus;
262
263         xdbg_printf(XDBG_DEBUG_ERROR, "Data abort \n");
264         #ifdef __GNUC__
265         FaultStatus = mfcp(XREG_CP15_DATA_FAULT_STATUS);
266             #elif defined (__ICCARM__)
267                 mfcp(XREG_CP15_DATA_FAULT_STATUS,FaultStatus);
268             #else
269                 { volatile register u32 Reg __asm(XREG_CP15_DATA_FAULT_STATUS);
270                 FaultStatus = Reg; }
271             #endif
272         xdbg_printf(XDBG_DEBUG_GENERAL, "Data abort with Data Fault Status Register  %lx\n",FaultStatus);
273         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of Instruction causing Data abort %lx\n",DataAbortAddr);
274 #endif
275         while(1) {
276                 ;
277         }
278 }
279
280 /*****************************************************************************/
281 /*
282 *
283 * Default Prefetch abort handler which prints prefetch fault status register through
284 * which information about instruction prefetch fault can be acquired
285 *
286 * @param        None
287 *
288 * @return       None.
289 *
290 * @note         None.
291 *
292 ****************************************************************************/
293 void Xil_PrefetchAbortHandler(void *CallBackRef){
294         (void) CallBackRef;
295 #ifdef DEBUG
296         u32 FaultStatus;
297
298     xdbg_printf(XDBG_DEBUG_ERROR, "Prefetch abort \n");
299         #ifdef __GNUC__
300         FaultStatus = mfcp(XREG_CP15_INST_FAULT_STATUS);
301             #elif defined (__ICCARM__)
302                         mfcp(XREG_CP15_INST_FAULT_STATUS,FaultStatus);
303             #else
304                         { volatile register u32 Reg __asm(XREG_CP15_INST_FAULT_STATUS);
305                         FaultStatus = Reg; }
306                 #endif
307         xdbg_printf(XDBG_DEBUG_GENERAL, "Prefetch abort with Instruction Fault Status Register  %lx\n",FaultStatus);
308         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of Instruction causing Prefetch abort %lx\n",PrefetchAbortAddr);
309 #endif
310         while(1) {
311                 ;
312         }
313 }
314 /*****************************************************************************/
315 /*
316 *
317 * Default undefined exception handler which prints address of the undefined
318 * instruction if debug prints are enabled
319 *
320 * @param        None
321 *
322 * @return       None.
323 *
324 * @note         None.
325 *
326 ****************************************************************************/
327 void Xil_UndefinedExceptionHandler(void *CallBackRef){
328         (void) CallBackRef;
329         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of the undefined instruction %lx\n",UndefinedExceptionAddr);
330         while(1) {
331                 ;
332         }
333 }
334 #endif