1 /******************************************************************************
3 * Copyright (C) 2015 - 2016 Xilinx, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
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
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.
31 ******************************************************************************/
32 /****************************************************************************/
35 * @file xil_exception.c
37 * This file contains low-level driver functions for the Cortex A53,A9,R5 exception
41 * MODIFICATION HISTORY:
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
53 *****************************************************************************/
55 /***************************** Include Files ********************************/
57 #include "xil_types.h"
58 #include "xil_assert.h"
59 #include "xil_exception.h"
60 #include "xpseudo_asm.h"
62 /************************** Constant Definitions ****************************/
64 /**************************** Type Definitions ******************************/
67 Xil_ExceptionHandler Handler;
69 } XExc_VectorTableEntry;
71 /***************** Macros (Inline Functions) Definitions ********************/
73 /************************** Function Prototypes *****************************/
74 static void Xil_ExceptionNullHandler(void *Data);
75 /************************** Variable Definitions *****************************/
77 * Exception vector table to store handlers for each exception vector.
79 #if defined (__aarch64__)
80 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
82 {Xil_ExceptionNullHandler, NULL},
83 {Xil_SyncAbortHandler, NULL},
84 {Xil_ExceptionNullHandler, NULL},
85 {Xil_ExceptionNullHandler, NULL},
86 {Xil_SErrorAbortHandler, NULL},
90 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
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},
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
108 /*****************************************************************************/
110 /****************************************************************************/
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.
118 * @param Data is unused by this function.
124 *****************************************************************************/
125 static void Xil_ExceptionNullHandler(void *Data)
128 DieLoop: goto DieLoop;
131 /****************************************************************************/
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).
147 *****************************************************************************/
148 void Xil_ExceptionInit(void)
153 /*****************************************************************************/
155 * @brief Register a handler for a specific exception. This handler is being
156 * called when the processor encounters the specified exception.
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.
169 ****************************************************************************/
170 void Xil_ExceptionRegisterHandler(u32 Exception_id,
171 Xil_ExceptionHandler Handler,
174 XExc_VectorTable[Exception_id].Handler = Handler;
175 XExc_VectorTable[Exception_id].Data = Data;
178 /*****************************************************************************/
181 * @brief Removes the Handler for a specific exception Id. The stub Handler
182 * is then registered for this exception Id.
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.
192 ****************************************************************************/
193 void Xil_ExceptionRemoveHandler(u32 Exception_id)
195 Xil_ExceptionRegisterHandler(Exception_id,
196 Xil_ExceptionNullHandler,
200 #if defined (__aarch64__)
201 /*****************************************************************************/
204 * Default Synchronous abort handler which prints a debug message on console if
205 * Debug flag is enabled
213 ****************************************************************************/
215 void Xil_SyncAbortHandler(void *CallBackRef){
217 xdbg_printf(XDBG_DEBUG_ERROR, "Synchronous abort \n");
223 /*****************************************************************************/
226 * Default SError abort handler which prints a debug message on console if
227 * Debug flag is enabled
235 ****************************************************************************/
236 void Xil_SErrorAbortHandler(void *CallBackRef){
238 xdbg_printf(XDBG_DEBUG_ERROR, "Synchronous abort \n");
244 /*****************************************************************************/
247 * Default Data abort handler which prints data fault status register through
248 * which information about data fault can be acquired
256 ****************************************************************************/
258 void Xil_DataAbortHandler(void *CallBackRef){
263 xdbg_printf(XDBG_DEBUG_ERROR, "Data abort \n");
265 FaultStatus = mfcp(XREG_CP15_DATA_FAULT_STATUS);
266 #elif defined (__ICCARM__)
267 mfcp(XREG_CP15_DATA_FAULT_STATUS,FaultStatus);
269 { volatile register u32 Reg __asm(XREG_CP15_DATA_FAULT_STATUS);
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);
280 /*****************************************************************************/
283 * Default Prefetch abort handler which prints prefetch fault status register through
284 * which information about instruction prefetch fault can be acquired
292 ****************************************************************************/
293 void Xil_PrefetchAbortHandler(void *CallBackRef){
298 xdbg_printf(XDBG_DEBUG_ERROR, "Prefetch abort \n");
300 FaultStatus = mfcp(XREG_CP15_INST_FAULT_STATUS);
301 #elif defined (__ICCARM__)
302 mfcp(XREG_CP15_INST_FAULT_STATUS,FaultStatus);
304 { volatile register u32 Reg __asm(XREG_CP15_INST_FAULT_STATUS);
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);
314 /*****************************************************************************/
317 * Default undefined exception handler which prints address of the undefined
318 * instruction if debug prints are enabled
326 ****************************************************************************/
327 void Xil_UndefinedExceptionHandler(void *CallBackRef){
329 xdbg_printf(XDBG_DEBUG_GENERAL, "Address of the undefined instruction %lx\n",UndefinedExceptionAddr);