1 /******************************************************************************
3 * Copyright (C) 2009 - 2015 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 A9 exception
41 * MODIFICATION HISTORY:
43 * Ver Who Date Changes
44 * ----- -------- -------- -----------------------------------------------
45 * 1.00a ecm/sdm 11/04/09 First release
46 * 3.05a sdm 02/02/12 Updated to resiter a null handler only if a handler
47 * is not already registered
48 * 4.2 pkp 06/19/14 Added default exception handlers for data abort and
49 * prefetch abort using handlers called
50 * DataAbortHandler and PrefetchAbortHandler respectively
51 * Both handlers are registers in vector table entries
52 * using XExc_VectorTable
53 * 5.1 pkp 05/13/15 Added debugging message to print address of instruction
54 * causing data abort and prefetch abort
55 * 5.4 pkp 12/03/15 Added handler for undefined exception to print the
56 * address of instruction causing exception
59 *****************************************************************************/
61 /***************************** Include Files ********************************/
63 #include "xil_types.h"
64 #include "xil_assert.h"
65 #include "xil_exception.h"
66 #include "xpseudo_asm.h"
68 /************************** Constant Definitions ****************************/
70 /**************************** Type Definitions ******************************/
73 Xil_ExceptionHandler Handler;
75 } XExc_VectorTableEntry;
77 /***************** Macros (Inline Functions) Definitions ********************/
79 /************************** Function Prototypes *****************************/
80 static void Xil_ExceptionNullHandler(void *Data);
81 /************************** Variable Definitions *****************************/
83 * Exception vector table to store handlers for each exception vector.
85 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
87 {Xil_ExceptionNullHandler, NULL},
88 {Xil_UndefinedExceptionHandler, NULL},
89 {Xil_ExceptionNullHandler, NULL},
90 {Xil_PrefetchAbortHandler, NULL},
91 {Xil_DataAbortHandler, NULL},
92 {Xil_ExceptionNullHandler, NULL},
93 {Xil_ExceptionNullHandler, NULL},
96 u32 UndefinedExceptionAddr; /* Address of instruction causing Undefined
98 u32 DataAbortAddr; /* Address of instruction causing data abort */
99 u32 PrefetchAbortAddr; /* Address of instruction causing prefetch abort */
101 /*****************************************************************************/
103 /****************************************************************************/
106 * This function is a stub Handler that is the default Handler that gets called
107 * if the application has not setup a Handler for a specific exception. The
108 * function interface has to match the interface specified for a Handler even
109 * though none of the arguments are used.
111 * @param Data is unused by this function.
117 *****************************************************************************/
118 static void Xil_ExceptionNullHandler(void *Data)
121 DieLoop: goto DieLoop;
124 /****************************************************************************/
126 * The function is a common API used to initialize exception handlers across all
127 * processors supported. For ARM CortexA9, the exception handlers are being
128 * initialized statically and hence this function does not do anything.
129 * However, it is still present to avoid any compilation issues in case an
130 * application uses this API and also to take care of backward compatibility
131 * issues (in earlier versions of BSPs, this API was being used to initialize
132 * exception handlers).
140 *****************************************************************************/
141 void Xil_ExceptionInit(void)
146 /*****************************************************************************/
149 * Makes the connection between the Id of the exception source and the
150 * associated Handler that is to run when the exception is recognized. The
151 * argument provided in this call as the Data is used as the argument
152 * for the Handler when it is called.
154 * @param exception_id contains the ID of the exception source and should
155 * be in the range of 0 to XIL_EXCEPTION_ID_LAST.
156 See xil_exception_l.h for further information.
157 * @param Handler to the Handler for that exception.
158 * @param Data is a reference to Data that will be passed to the
159 * Handler when it gets called.
165 ****************************************************************************/
166 void Xil_ExceptionRegisterHandler(u32 Exception_id,
167 Xil_ExceptionHandler Handler,
170 XExc_VectorTable[Exception_id].Handler = Handler;
171 XExc_VectorTable[Exception_id].Data = Data;
174 /*****************************************************************************/
177 * Removes the Handler for a specific exception Id. The stub Handler is then
178 * registered for this exception Id.
180 * @param exception_id contains the ID of the exception source and should
181 * be in the range of 0 to XIL_EXCEPTION_ID_LAST.
182 * See xil_exception_l.h for further information.
188 ****************************************************************************/
189 void Xil_ExceptionRemoveHandler(u32 Exception_id)
191 Xil_ExceptionRegisterHandler(Exception_id,
192 Xil_ExceptionNullHandler,
197 /*****************************************************************************/
200 * Default Data abort handler which prints data fault status register through
201 * which information about data fault can be acquired
209 ****************************************************************************/
211 void Xil_DataAbortHandler(void *CallBackRef){
214 FaultStatus = mfcp(XREG_CP15_DATA_FAULT_STATUS);
215 #elif defined (__ICCARM__)
216 mfcp(XREG_CP15_DATA_FAULT_STATUS,FaultStatus);
218 { volatile register u32 Reg __asm(XREG_CP15_DATA_FAULT_STATUS);
221 xdbg_printf(XDBG_DEBUG_GENERAL, "Data abort with Data Fault Status Register %x\n",FaultStatus);
222 xdbg_printf(XDBG_DEBUG_GENERAL, "Address of Instrcution causing Data abort %x\n",DataAbortAddr);
228 /*****************************************************************************/
231 * Default Prefetch abort handler which prints prefetch fault status register through
232 * which information about instruction prefetch fault can be acquired
240 ****************************************************************************/
241 void Xil_PrefetchAbortHandler(void *CallBackRef){
244 FaultStatus = mfcp(XREG_CP15_INST_FAULT_STATUS);
245 #elif defined (__ICCARM__)
246 mfcp(XREG_CP15_INST_FAULT_STATUS,FaultStatus);
248 { volatile register u32 Reg __asm(XREG_CP15_INST_FAULT_STATUS);
251 xdbg_printf(XDBG_DEBUG_GENERAL, "Prefetch abort with Instruction Fault Status Register %x\n",FaultStatus);
252 xdbg_printf(XDBG_DEBUG_GENERAL, "Address of Instrcution causing Prefetch abort %x\n",PrefetchAbortAddr);
258 /*****************************************************************************/
261 * Default undefined exception handler which prints address of the undefined
262 * instruction if debug prints are enabled
270 ****************************************************************************/
271 void Xil_UndefinedExceptionHandler(void *CallBackRef){
273 xdbg_printf(XDBG_DEBUG_GENERAL, "Address of the undefined instruction %x\n",UndefinedExceptionAddr);