]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo_bsp/ps7_cortexa9_0/libsrc/standalone_v5_4/src/xil_exception.c
xTaskGenericNotify() now sets xYieldPending to pdTRUE even when the 'higher priority...
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo_bsp / ps7_cortexa9_0 / libsrc / standalone_v5_4 / src / xil_exception.c
1 /******************************************************************************
2 *
3 * Copyright (C) 2009 - 2015 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 A9 exception
38 * Handler.
39 *
40 * <pre>
41 * MODIFICATION HISTORY:
42 *
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
57 * </pre>
58 *
59 *****************************************************************************/
60
61 /***************************** Include Files ********************************/
62
63 #include "xil_types.h"
64 #include "xil_assert.h"
65 #include "xil_exception.h"
66 #include "xpseudo_asm.h"
67 #include "xdebug.h"
68 /************************** Constant Definitions ****************************/
69
70 /**************************** Type Definitions ******************************/
71
72 typedef struct {
73         Xil_ExceptionHandler Handler;
74         void *Data;
75 } XExc_VectorTableEntry;
76
77 /***************** Macros (Inline Functions) Definitions ********************/
78
79 /************************** Function Prototypes *****************************/
80 static void Xil_ExceptionNullHandler(void *Data);
81 /************************** Variable Definitions *****************************/
82 /*
83  * Exception vector table to store handlers for each exception vector.
84  */
85 XExc_VectorTableEntry XExc_VectorTable[XIL_EXCEPTION_ID_LAST + 1] =
86 {
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},
94 };
95
96 u32 UndefinedExceptionAddr;   /* Address of instruction causing Undefined
97                                                          exception */
98 u32 DataAbortAddr;       /* Address of instruction causing data abort */
99 u32 PrefetchAbortAddr;   /* Address of instruction causing prefetch abort */
100
101 /*****************************************************************************/
102
103 /****************************************************************************/
104 /**
105 *
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.
110 *
111 * @param        Data is unused by this function.
112 *
113 * @return       None.
114 *
115 * @note         None.
116 *
117 *****************************************************************************/
118 static void Xil_ExceptionNullHandler(void *Data)
119 {
120         (void *)Data;
121 DieLoop: goto DieLoop;
122 }
123
124 /****************************************************************************/
125 /**
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).
133 *
134 * @param        None.
135 *
136 * @return       None.
137 *
138 * @note         None.
139 *
140 *****************************************************************************/
141 void Xil_ExceptionInit(void)
142 {
143         return;
144 }
145
146 /*****************************************************************************/
147 /**
148 *
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.
153 *
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.
160 *
161 * @return       None.
162 *
163 * @note         None.
164 *
165 ****************************************************************************/
166 void Xil_ExceptionRegisterHandler(u32 Exception_id,
167                                     Xil_ExceptionHandler Handler,
168                                     void *Data)
169 {
170         XExc_VectorTable[Exception_id].Handler = Handler;
171         XExc_VectorTable[Exception_id].Data = Data;
172 }
173
174 /*****************************************************************************/
175 /**
176 *
177 * Removes the Handler for a specific exception Id. The stub Handler is then
178 * registered for this exception Id.
179 *
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.
183
184 * @return       None.
185 *
186 * @note         None.
187 *
188 ****************************************************************************/
189 void Xil_ExceptionRemoveHandler(u32 Exception_id)
190 {
191         Xil_ExceptionRegisterHandler(Exception_id,
192                                        Xil_ExceptionNullHandler,
193                                        NULL);
194 }
195
196
197 /*****************************************************************************/
198 /**
199 *
200 * Default Data abort handler which prints data fault status register through
201 * which information about data fault can be acquired
202 *
203 * @param        None
204 *
205 * @return       None.
206 *
207 * @note         None.
208 *
209 ****************************************************************************/
210
211 void Xil_DataAbortHandler(void *CallBackRef){
212         u32 FaultStatus;
213         #ifdef __GNUC__
214                 FaultStatus = mfcp(XREG_CP15_DATA_FAULT_STATUS);
215         #elif defined (__ICCARM__)
216                 mfcp(XREG_CP15_DATA_FAULT_STATUS,FaultStatus);
217         #else
218                 { volatile register u32 Reg __asm(XREG_CP15_DATA_FAULT_STATUS);
219           FaultStatus = Reg; }
220         #endif
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);
223         while(1) {
224                 ;
225         }
226 }
227
228 /*****************************************************************************/
229 /**
230 *
231 * Default Prefetch abort handler which prints prefetch fault status register through
232 * which information about instruction prefetch fault can be acquired
233 *
234 * @param        None
235 *
236 * @return       None.
237 *
238 * @note         None.
239 *
240 ****************************************************************************/
241 void Xil_PrefetchAbortHandler(void *CallBackRef){
242         u32 FaultStatus;
243         #ifdef __GNUC__
244                 FaultStatus = mfcp(XREG_CP15_INST_FAULT_STATUS);
245         #elif defined (__ICCARM__)
246                 mfcp(XREG_CP15_INST_FAULT_STATUS,FaultStatus);
247         #else
248                 { volatile register u32 Reg __asm(XREG_CP15_INST_FAULT_STATUS);
249           FaultStatus = Reg; }
250         #endif
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);
253         while(1) {
254                 ;
255         }
256 }
257
258 /*****************************************************************************/
259 /**
260 *
261 * Default undefined exception handler which prints address of the undefined
262 * instruction if debug prints are enabled
263 *
264 * @param        None
265 *
266 * @return       None.
267 *
268 * @note         None.
269 *
270 ****************************************************************************/
271 void Xil_UndefinedExceptionHandler(void *CallBackRef){
272
273         xdbg_printf(XDBG_DEBUG_GENERAL, "Address of the undefined instruction %x\n",UndefinedExceptionAddr);
274         while(1) {
275                 ;
276         }
277 }