]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A53_64-bit_UltraScale_MPSoC/RTOSDemo_A53_bsp/psu_cortexa53_0/libsrc/standalone_v6_1/src/xil_exception.c
Update Zynq MPSoC hardware definition and BSP files to be those shipped with the...
[freertos] / FreeRTOS / Demo / CORTEX_A53_64-bit_UltraScale_MPSoC / RTOSDemo_A53_bsp / psu_cortexa53_0 / libsrc / standalone_v6_1 / 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 * </pre>
50 *
51 *****************************************************************************/
52
53 /***************************** Include Files ********************************/
54
55 #include "xil_types.h"
56 #include "xil_assert.h"
57 #include "xil_exception.h"
58 #include "xpseudo_asm.h"
59 #include "xdebug.h"
60 /************************** Constant Definitions ****************************/
61
62 /**************************** Type Definitions ******************************/
63
64 typedef struct {
65         Xil_ExceptionHandler Handler;
66         void *Data;
67 } XExc_VectorTableEntry;
68
69 /***************** Macros (Inline Functions) Definitions ********************/
70
71 /************************** Function Prototypes *****************************/
72 static void Xil_ExceptionNullHandler(void *Data);
73 /************************** Variable Definitions *****************************/
74 /*
75  * Exception vector table to store handlers for each exception vector.
76  */
77 #if defined (__aarch64__)
78 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
79 {
80         {Xil_ExceptionNullHandler, NULL},
81         {Xil_SyncAbortHandler, NULL},
82         {Xil_ExceptionNullHandler, NULL},
83         {Xil_ExceptionNullHandler, NULL},
84         {Xil_SErrorAbortHandler, NULL},
85
86 };
87 #else
88 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
89 {
90         {Xil_ExceptionNullHandler, NULL},
91         {Xil_UndefinedExceptionHandler, NULL},
92         {Xil_ExceptionNullHandler, NULL},
93         {Xil_PrefetchAbortHandler, NULL},
94         {Xil_DataAbortHandler, NULL},
95         {Xil_ExceptionNullHandler, NULL},
96         {Xil_ExceptionNullHandler, NULL},
97 };
98 #endif
99 #if !defined (__aarch64__)
100 u32 DataAbortAddr;       /* Address of instruction causing data abort */
101 u32 PrefetchAbortAddr;   /* Address of instruction causing prefetch abort */
102 u32 UndefinedExceptionAddr;   /* Address of instruction causing Undefined
103                                                              exception */
104 #endif
105
106 /*****************************************************************************/
107
108 /****************************************************************************/
109 /**
110 *
111 * This function is a stub Handler that is the default Handler that gets called
112 * if the application has not setup a Handler for a specific  exception. The
113 * function interface has to match the interface specified for a Handler even
114 * though none of the arguments are used.
115 *
116 * @param        Data is unused by this function.
117 *
118 * @return       None.
119 *
120 * @note         None.
121 *
122 *****************************************************************************/
123 static void Xil_ExceptionNullHandler(void *Data)
124 {
125         (void *)Data;
126 DieLoop: goto DieLoop;
127 }
128
129 /****************************************************************************/
130 /**
131 * The function is a common API used to initialize exception handlers across all
132 * processors supported. For ARM CortexA53,R5,A9, the exception handlers are being
133 * initialized statically and hence this function does not do anything.
134 * However, it is still present to avoid any compilation issues in case an
135 * application uses this API and also to take care of backward compatibility
136 * issues (in earlier versions of BSPs, this API was being used to initialize
137 * exception handlers).
138 *
139 * @param        None.
140 *
141 * @return       None.
142 *
143 * @note         None.
144 *
145 *****************************************************************************/
146 void Xil_ExceptionInit(void)
147 {
148         return;
149 }
150
151 /*****************************************************************************/
152 /**
153 *
154 * Makes the connection between the Id of the exception source and the
155 * associated Handler that is to run when the exception is recognized. The
156 * argument provided in this call as the Data is used as the argument
157 * for the Handler when it is called.
158 *
159 * @param        exception_id contains the ID of the exception source and should
160 *               be in the range of 0 to XIL_EXCEPTION_ID_LAST.
161                 See xil_exception_l.h for further information.
162 * @param        Handler to the Handler for that exception.
163 * @param        Data is a reference to Data that will be passed to the
164 *               Handler when it gets called.
165 *
166 * @return       None.
167 *
168 * @note         None.
169 *
170 ****************************************************************************/
171 void Xil_ExceptionRegisterHandler(u32 Exception_id,
172                                     Xil_ExceptionHandler Handler,
173                                     void *Data)
174 {
175         XExc_VectorTable[Exception_id].Handler = Handler;
176         XExc_VectorTable[Exception_id].Data = Data;
177 }
178
179 /*****************************************************************************/
180 /**
181 *
182 * Removes the Handler for a specific exception Id. The stub Handler is then
183 * registered for this exception Id.
184 *
185 * @param        exception_id contains the ID of the exception source and should
186 *               be in the range of 0 to XIL_EXCEPTION_ID_LAST.
187 *               See xil_exception_l.h for further information.
188
189 * @return       None.
190 *
191 * @note         None.
192 *
193 ****************************************************************************/
194 void Xil_ExceptionRemoveHandler(u32 Exception_id)
195 {
196         Xil_ExceptionRegisterHandler(Exception_id,
197                                        Xil_ExceptionNullHandler,
198                                        NULL);
199 }
200
201 #if defined (__aarch64__)
202 /*****************************************************************************/
203 /**
204 *
205 * Default Synchronous abort handler which prints a debug message on console if
206 * Debug flag is enabled
207 *
208 * @param        None
209 *
210 * @return       None.
211 *
212 * @note         None.
213 *
214 ****************************************************************************/
215
216 void Xil_SyncAbortHandler(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         xdbg_printf(XDBG_DEBUG_ERROR, "Synchronous abort \n");
238         while(1) {
239                 ;
240         }
241 }
242 #else
243 /*****************************************************************************/
244 /**
245 *
246 * Default Data abort handler which prints data fault status register through
247 * which information about data fault can be acquired
248 *
249 * @param        None
250 *
251 * @return       None.
252 *
253 * @note         None.
254 *
255 ****************************************************************************/
256
257 void Xil_DataAbortHandler(void *CallBackRef){
258 #ifdef DEBUG
259         u32 FaultStatus;
260
261         xdbg_printf(XDBG_DEBUG_ERROR, "Data abort \n");
262         #ifdef __GNUC__
263         FaultStatus = mfcp(XREG_CP15_DATA_FAULT_STATUS);
264             #elif defined (__ICCARM__)
265                 mfcp(XREG_CP15_DATA_FAULT_STATUS,FaultStatus);
266             #else
267                 { volatile register u32 Reg __asm(XREG_CP15_DATA_FAULT_STATUS);
268                 FaultStatus = Reg; }
269             #endif
270         xdbg_printf(XDBG_DEBUG_GENERAL, "Data abort with Data Fault Status Register  %x\n",FaultStatus);
271         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of Instrcution causing Data abort %x\n",DataAbortAddr);
272 #endif
273         while(1) {
274                 ;
275         }
276 }
277
278 /*****************************************************************************/
279 /**
280 *
281 * Default Prefetch abort handler which prints prefetch fault status register through
282 * which information about instruction prefetch fault can be acquired
283 *
284 * @param        None
285 *
286 * @return       None.
287 *
288 * @note         None.
289 *
290 ****************************************************************************/
291 void Xil_PrefetchAbortHandler(void *CallBackRef){
292 #ifdef DEBUG
293         u32 FaultStatus;
294
295     xdbg_printf(XDBG_DEBUG_ERROR, "Prefetch abort \n");
296         #ifdef __GNUC__
297         FaultStatus = mfcp(XREG_CP15_INST_FAULT_STATUS);
298             #elif defined (__ICCARM__)
299                         mfcp(XREG_CP15_INST_FAULT_STATUS,FaultStatus);
300             #else
301                         { volatile register u32 Reg __asm(XREG_CP15_INST_FAULT_STATUS);
302                         FaultStatus = Reg; }
303                 #endif
304         xdbg_printf(XDBG_DEBUG_GENERAL, "Prefetch abort with Instruction Fault Status Register  %x\n",FaultStatus);
305         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of Instrcution causing Prefetch abort %x\n",PrefetchAbortAddr);
306 #endif
307         while(1) {
308                 ;
309         }
310 }
311 /*****************************************************************************/
312 /**
313 *
314 * Default undefined exception handler which prints address of the undefined
315 * instruction if debug prints are enabled
316 *
317 * @param        None
318 *
319 * @return       None.
320 *
321 * @note         None.
322 *
323 ****************************************************************************/
324 void Xil_UndefinedExceptionHandler(void *CallBackRef){
325
326         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of the undefined instruction %x\n",UndefinedExceptionAddr);
327         while(1) {
328                 ;
329         }
330 }
331 #endif