1 /******************************************************************************
3 * (c) Copyright 2009-13 Xilinx, Inc. All rights reserved.
5 * This file contains confidential and proprietary information of Xilinx, Inc.
6 * and is protected under U.S. and international copyright and other
7 * intellectual property laws.
10 * This disclaimer is not a license and does not grant any rights to the
11 * materials distributed herewith. Except as otherwise provided in a valid
12 * license issued to you by Xilinx, and to the maximum extent permitted by
13 * applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL
14 * FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,
15 * IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
16 * MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;
17 * and (2) Xilinx shall not be liable (whether in contract or tort, including
18 * negligence, or under any other theory of liability) for any loss or damage
19 * of any kind or nature related to, arising under or in connection with these
20 * materials, including for any direct, or any indirect, special, incidental,
21 * or consequential loss or damage (including loss of data, profits, goodwill,
22 * or any type of loss or damage suffered as a result of any action brought by
23 * a third party) even if such damage or loss was reasonably foreseeable or
24 * Xilinx had been advised of the possibility of the same.
26 * CRITICAL APPLICATIONS
27 * Xilinx products are not designed or intended to be fail-safe, or for use in
28 * any application requiring fail-safe performance, such as life-support or
29 * safety devices or systems, Class III medical devices, nuclear facilities,
30 * applications related to the deployment of airbags, or any other applications
31 * that could lead to death, personal injury, or severe property or
32 * environmental damage (individually and collectively, "Critical
33 * Applications"). Customer assumes the sole risk and liability of any use of
34 * Xilinx products in Critical Applications, subject only to applicable laws
35 * and regulations governing limitations on product liability.
37 * THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE
40 ******************************************************************************/
41 /*****************************************************************************/
44 * @file xil_exception.h
46 * This header file contains ARM Cortex A9 specific exception related APIs.
47 * For exception related functions that can be used across all Xilinx supported
48 * processors, please use xil_exception.h.
51 * MODIFICATION HISTORY:
53 * Ver Who Date Changes
54 * ----- -------- -------- -----------------------------------------------
55 * 1.00a ecm/sdm 11/04/09 First release
58 ******************************************************************************/
60 #ifndef XIL_EXCEPTION_H /* prevent circular inclusions */
61 #define XIL_EXCEPTION_H /* by using protection macros */
63 /***************************** Include Files ********************************/
65 #include "xil_types.h"
66 #include "xpseudo_asm.h"
72 /************************** Constant Definitions ****************************/
74 #define XIL_EXCEPTION_FIQ XREG_CPSR_FIQ_ENABLE
75 #define XIL_EXCEPTION_IRQ XREG_CPSR_IRQ_ENABLE
76 #define XIL_EXCEPTION_ALL (XREG_CPSR_FIQ_ENABLE | XREG_CPSR_IRQ_ENABLE)
78 #define XIL_EXCEPTION_ID_FIRST 0
79 #define XIL_EXCEPTION_ID_RESET 0
80 #define XIL_EXCEPTION_ID_UNDEFINED_INT 1
81 #define XIL_EXCEPTION_ID_SWI_INT 2
82 #define XIL_EXCEPTION_ID_PREFETCH_ABORT_INT 3
83 #define XIL_EXCEPTION_ID_DATA_ABORT_INT 4
84 #define XIL_EXCEPTION_ID_IRQ_INT 5
85 #define XIL_EXCEPTION_ID_FIQ_INT 6
86 #define XIL_EXCEPTION_ID_LAST 6
89 * XIL_EXCEPTION_ID_INT is defined for all Xilinx processors.
91 #define XIL_EXCEPTION_ID_INT XIL_EXCEPTION_ID_IRQ_INT
93 /**************************** Type Definitions ******************************/
96 * This typedef is the exception handler function.
98 typedef void (*Xil_ExceptionHandler)(void *data);
99 typedef void (*Xil_InterruptHandler)(void *data);
101 /***************** Macros (Inline Functions) Definitions ********************/
103 /****************************************************************************/
107 * @param Mask for exceptions to be enabled.
111 * @note If bit is 0, exception is enabled.
112 * C-Style signature: void Xil_ExceptionEnableMask(Mask);
114 ******************************************************************************/
116 #define Xil_ExceptionEnableMask(Mask) \
117 mtcpsr(mfcpsr() & ~ (Mask & XIL_EXCEPTION_ALL))
119 #define Xil_ExceptionEnableMask(Mask) \
120 { register unsigned int Reg __asm("cpsr"); \
121 mtcpsr(Reg & ~ (Mask & XIL_EXCEPTION_ALL)) }
124 /****************************************************************************/
126 * Enable the IRQ exception.
132 ******************************************************************************/
133 #define Xil_ExceptionEnable() \
134 Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ)
136 /****************************************************************************/
138 * Disable Exceptions.
140 * @param Mask for exceptions to be enabled.
144 * @note If bit is 1, exception is disabled.
145 * C-Style signature: Xil_ExceptionDisableMask(Mask);
147 ******************************************************************************/
149 #define Xil_ExceptionDisableMask(Mask) \
150 mtcpsr(mfcpsr() | (Mask & XIL_EXCEPTION_ALL))
152 #define Xil_ExceptionDisableMask(Mask) \
153 { register unsigned int Reg __asm("cpsr"); \
154 mtcpsr(Reg | (Mask & XIL_EXCEPTION_ALL)) }
157 /****************************************************************************/
159 * Disable the IRQ exception.
165 ******************************************************************************/
166 #define Xil_ExceptionDisable() \
167 Xil_ExceptionDisableMask(XIL_EXCEPTION_IRQ)
169 /****************************************************************************/
171 * Enable nested interrupts by clearing the I and F bits it CPSR
175 * @note This macro is supposed to be used from interrupt handlers. In the
176 * interrupt handler the interrupts are disabled by default (I and F
177 * are 1). To allow nesting of interrupts, this macro should be
178 * used. It clears the I and F bits by changing the ARM mode to
179 * system mode. Once these bits are cleared and provided the
180 * preemption of interrupt conditions are met in the GIC, nesting of
181 * interrupts will start happening.
182 * Caution: This macro must be used with caution. Before calling this
183 * macro, the user must ensure that the source of the current IRQ
184 * is appropriately cleared. Otherwise, as soon as we clear the I and
185 * F bits, there can be an infinite loop of interrupts with an
186 * eventual crash (all the stack space getting consumed).
187 ******************************************************************************/
188 #define Xil_EnableNestedInterrupts() \
189 __asm__ __volatile__ ("mrs lr, spsr"); \
190 __asm__ __volatile__ ("stmfd sp!, {lr}"); \
191 __asm__ __volatile__ ("msr cpsr_c, #0x1F"); \
192 __asm__ __volatile__ ("stmfd sp!, {lr}");
194 /****************************************************************************/
196 * Disable the nested interrupts by setting the I and F bits.
200 * @note This macro is meant to be called in the interrupt service routines.
201 * This macro cannot be used independently. It can only be used when
202 * nesting of interrupts have been enabled by using the macro
203 * Xil_EnableNestedInterrupts(). In a typical flow, the user first
204 * calls the Xil_EnableNestedInterrupts in the ISR at the appropriate
205 * point. The user then must call this macro before exiting the interrupt
206 * service routine. This macro puts the ARM back in IRQ/FIQ mode and
207 * hence sets back the I and F bits.
208 ******************************************************************************/
209 #define Xil_DisableNestedInterrupts() \
210 __asm__ __volatile__ ("ldmfd sp!, {lr}"); \
211 __asm__ __volatile__ ("msr cpsr_c, #0x92"); \
212 __asm__ __volatile__ ("ldmfd sp!, {lr}"); \
213 __asm__ __volatile__ ("msr spsr_cxsf, lr");
215 /************************** Variable Definitions ****************************/
217 /************************** Function Prototypes *****************************/
219 extern void Xil_ExceptionRegisterHandler(u32 id,
220 Xil_ExceptionHandler handler,
223 extern void Xil_ExceptionRemoveHandler(u32 id);
225 extern void Xil_ExceptionInit(void);
229 #endif /* __cplusplus */
231 #endif /* XIL_EXCEPTION_H */