2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
74 /* Hardware includes. */
\r
75 #include <microblaze_exceptions_i.h>
\r
76 #include <microblaze_exceptions_g.h>
\r
78 /* The Xilinx library defined exception entry point stacks a number of
\r
79 registers. These definitions are offsets from the stack pointer to the various
\r
80 stacked register values. */
\r
81 #define portexR3_STACK_OFFSET 4
\r
82 #define portexR4_STACK_OFFSET 5
\r
83 #define portexR5_STACK_OFFSET 6
\r
84 #define portexR6_STACK_OFFSET 7
\r
85 #define portexR7_STACK_OFFSET 8
\r
86 #define portexR8_STACK_OFFSET 9
\r
87 #define portexR9_STACK_OFFSET 10
\r
88 #define portexR10_STACK_OFFSET 11
\r
89 #define portexR11_STACK_OFFSET 12
\r
90 #define portexR12_STACK_OFFSET 13
\r
91 #define portexR15_STACK_OFFSET 16
\r
92 #define portexR18_STACK_OFFSET 19
\r
93 #define portexMSR_STACK_OFFSET 20
\r
94 #define portexR19_STACK_OFFSET -1
\r
96 /* This is defined to equal the size, in bytes, of the stack frame generated by
\r
97 the Xilinx standard library exception entry point. It is required to determine
\r
98 the stack pointer value prior to the exception being entered. */
\r
99 #define portexASM_HANDLER_STACK_FRAME_SIZE 84UL
\r
101 /* The number of bytes a MicroBlaze instruction consumes. */
\r
102 #define portexINSTRUCTION_SIZE 4
\r
104 /* Exclude this entire file if the MicroBlaze is not configured to handle
\r
105 exceptions, or the application defined configuration constant
\r
106 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
107 #if ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 )
\r
109 /* This variable is set in the exception entry code, before
\r
110 vPortExceptionHandler is called. */
\r
111 uint32_t *pulStackPointerOnFunctionEntry = NULL;
\r
113 /* This is the structure that is filled with the MicroBlaze context as it
\r
114 existed immediately prior to the exception occurrence. A pointer to this
\r
115 structure is passed into the vApplicationExceptionRegisterDump() callback
\r
116 function, if one is defined. */
\r
117 static xPortRegisterDump xRegisterDump;
\r
119 /* This is the FreeRTOS exception handler that is installed for all exception
\r
120 types. It is called from vPortExceptionHanlderEntry() - which is itself defined
\r
122 void vPortExceptionHandler( void *pvExceptionID );
\r
123 extern void vPortExceptionHandlerEntry( void *pvExceptionID );
\r
125 /*-----------------------------------------------------------*/
\r
127 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
128 application can optionally define to receive a populated xPortRegisterDump
\r
129 structure. If the application chooses not to define a version of
\r
130 vApplicationExceptionRegisterDump() then this weekly defined default
\r
131 implementation will be called instead. */
\r
132 extern void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ) __attribute__((weak));
\r
133 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump )
\r
135 ( void ) xRegisterDump;
\r
142 /*-----------------------------------------------------------*/
\r
144 void vPortExceptionHandler( void *pvExceptionID )
\r
146 extern void *pxCurrentTCB;
\r
148 /* Fill an xPortRegisterDump structure with the MicroBlaze context as it
\r
149 was immediately before the exception occurrence. */
\r
151 /* First fill in the name and handle of the task that was in the Running
\r
152 state when the exception occurred. */
\r
153 xRegisterDump.xCurrentTaskHandle = pxCurrentTCB;
\r
154 xRegisterDump.pcCurrentTaskName = pcTaskGetName( NULL );
\r
156 configASSERT( pulStackPointerOnFunctionEntry );
\r
158 /* Obtain the values of registers that were stacked prior to this function
\r
159 being called, and may have changed since they were stacked. */
\r
160 xRegisterDump.ulR3 = pulStackPointerOnFunctionEntry[ portexR3_STACK_OFFSET ];
\r
161 xRegisterDump.ulR4 = pulStackPointerOnFunctionEntry[ portexR4_STACK_OFFSET ];
\r
162 xRegisterDump.ulR5 = pulStackPointerOnFunctionEntry[ portexR5_STACK_OFFSET ];
\r
163 xRegisterDump.ulR6 = pulStackPointerOnFunctionEntry[ portexR6_STACK_OFFSET ];
\r
164 xRegisterDump.ulR7 = pulStackPointerOnFunctionEntry[ portexR7_STACK_OFFSET ];
\r
165 xRegisterDump.ulR8 = pulStackPointerOnFunctionEntry[ portexR8_STACK_OFFSET ];
\r
166 xRegisterDump.ulR9 = pulStackPointerOnFunctionEntry[ portexR9_STACK_OFFSET ];
\r
167 xRegisterDump.ulR10 = pulStackPointerOnFunctionEntry[ portexR10_STACK_OFFSET ];
\r
168 xRegisterDump.ulR11 = pulStackPointerOnFunctionEntry[ portexR11_STACK_OFFSET ];
\r
169 xRegisterDump.ulR12 = pulStackPointerOnFunctionEntry[ portexR12_STACK_OFFSET ];
\r
170 xRegisterDump.ulR15_return_address_from_subroutine = pulStackPointerOnFunctionEntry[ portexR15_STACK_OFFSET ];
\r
171 xRegisterDump.ulR18 = pulStackPointerOnFunctionEntry[ portexR18_STACK_OFFSET ];
\r
172 xRegisterDump.ulR19 = pulStackPointerOnFunctionEntry[ portexR19_STACK_OFFSET ];
\r
173 xRegisterDump.ulMSR = pulStackPointerOnFunctionEntry[ portexMSR_STACK_OFFSET ];
\r
175 /* Obtain the value of all other registers. */
\r
176 xRegisterDump.ulR2_small_data_area = mfgpr( R2 );
\r
177 xRegisterDump.ulR13_read_write_small_data_area = mfgpr( R13 );
\r
178 xRegisterDump.ulR14_return_address_from_interrupt = mfgpr( R14 );
\r
179 xRegisterDump.ulR16_return_address_from_trap = mfgpr( R16 );
\r
180 xRegisterDump.ulR17_return_address_from_exceptions = mfgpr( R17 );
\r
181 xRegisterDump.ulR20 = mfgpr( R20 );
\r
182 xRegisterDump.ulR21 = mfgpr( R21 );
\r
183 xRegisterDump.ulR22 = mfgpr( R22 );
\r
184 xRegisterDump.ulR23 = mfgpr( R23 );
\r
185 xRegisterDump.ulR24 = mfgpr( R24 );
\r
186 xRegisterDump.ulR25 = mfgpr( R25 );
\r
187 xRegisterDump.ulR26 = mfgpr( R26 );
\r
188 xRegisterDump.ulR27 = mfgpr( R27 );
\r
189 xRegisterDump.ulR28 = mfgpr( R28 );
\r
190 xRegisterDump.ulR29 = mfgpr( R29 );
\r
191 xRegisterDump.ulR30 = mfgpr( R30 );
\r
192 xRegisterDump.ulR31 = mfgpr( R31 );
\r
193 xRegisterDump.ulR1_SP = ( ( uint32_t ) pulStackPointerOnFunctionEntry ) + portexASM_HANDLER_STACK_FRAME_SIZE;
\r
194 xRegisterDump.ulEAR = mfear();
\r
195 xRegisterDump.ulESR = mfesr();
\r
196 xRegisterDump.ulEDR = mfedr();
\r
198 /* Move the saved program counter back to the instruction that was executed
\r
199 when the exception occurred. This is only valid for certain types of
\r
201 xRegisterDump.ulPC = xRegisterDump.ulR17_return_address_from_exceptions - portexINSTRUCTION_SIZE;
\r
203 #if( XPAR_MICROBLAZE_USE_FPU != 0 )
\r
205 xRegisterDump.ulFSR = mffsr();
\r
209 xRegisterDump.ulFSR = 0UL;
\r
213 /* Also fill in a string that describes what type of exception this is.
\r
214 The string uses the same ID names as defined in the MicroBlaze standard
\r
215 library exception header files. */
\r
216 switch( ( uint32_t ) pvExceptionID )
\r
219 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_FSL";
\r
222 case XEXC_ID_UNALIGNED_ACCESS :
\r
223 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_UNALIGNED_ACCESS";
\r
226 case XEXC_ID_ILLEGAL_OPCODE :
\r
227 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_ILLEGAL_OPCODE";
\r
230 case XEXC_ID_M_AXI_I_EXCEPTION :
\r
231 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_M_AXI_I_EXCEPTION or XEXC_ID_IPLB_EXCEPTION";
\r
234 case XEXC_ID_M_AXI_D_EXCEPTION :
\r
235 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_M_AXI_D_EXCEPTION or XEXC_ID_DPLB_EXCEPTION";
\r
238 case XEXC_ID_DIV_BY_ZERO :
\r
239 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_DIV_BY_ZERO";
\r
242 case XEXC_ID_STACK_VIOLATION :
\r
243 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_STACK_VIOLATION or XEXC_ID_MMU";
\r
246 #if( XPAR_MICROBLAZE_USE_FPU != 0 )
\r
249 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_FPU see ulFSR value";
\r
252 #endif /* XPAR_MICROBLAZE_USE_FPU */
\r
255 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
256 application can optionally define to receive the populated xPortRegisterDump
\r
257 structure. If the application chooses not to define a version of
\r
258 vApplicationExceptionRegisterDump() then the weekly defined default
\r
259 implementation within this file will be called instead. */
\r
260 vApplicationExceptionRegisterDump( &xRegisterDump );
\r
262 /* Must not attempt to leave this function! */
\r
268 /*-----------------------------------------------------------*/
\r
270 void vPortExceptionsInstallHandlers( void )
\r
272 static uint32_t ulHandlersAlreadyInstalled = pdFALSE;
\r
274 if( ulHandlersAlreadyInstalled == pdFALSE )
\r
276 ulHandlersAlreadyInstalled = pdTRUE;
\r
278 #if XPAR_MICROBLAZE_UNALIGNED_EXCEPTIONS == 1
\r
279 microblaze_register_exception_handler( XEXC_ID_UNALIGNED_ACCESS, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_UNALIGNED_ACCESS );
\r
280 #endif /* XPAR_MICROBLAZE_UNALIGNED_EXCEPTIONS*/
\r
282 #if XPAR_MICROBLAZE_ILL_OPCODE_EXCEPTION == 1
\r
283 microblaze_register_exception_handler( XEXC_ID_ILLEGAL_OPCODE, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_ILLEGAL_OPCODE );
\r
284 #endif /* XPAR_MICROBLAZE_ILL_OPCODE_EXCEPTION */
\r
286 #if XPAR_MICROBLAZE_M_AXI_I_BUS_EXCEPTION == 1
\r
287 microblaze_register_exception_handler( XEXC_ID_M_AXI_I_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_I_EXCEPTION );
\r
288 #endif /* XPAR_MICROBLAZE_M_AXI_I_BUS_EXCEPTION */
\r
290 #if XPAR_MICROBLAZE_M_AXI_D_BUS_EXCEPTION == 1
\r
291 microblaze_register_exception_handler( XEXC_ID_M_AXI_D_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_D_EXCEPTION );
\r
292 #endif /* XPAR_MICROBLAZE_M_AXI_D_BUS_EXCEPTION */
\r
294 #if XPAR_MICROBLAZE_IPLB_BUS_EXCEPTION == 1
\r
295 microblaze_register_exception_handler( XEXC_ID_IPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_IPLB_EXCEPTION );
\r
296 #endif /* XPAR_MICROBLAZE_IPLB_BUS_EXCEPTION */
\r
298 #if XPAR_MICROBLAZE_DPLB_BUS_EXCEPTION == 1
\r
299 microblaze_register_exception_handler( XEXC_ID_DPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DPLB_EXCEPTION );
\r
300 #endif /* XPAR_MICROBLAZE_DPLB_BUS_EXCEPTION */
\r
302 #if XPAR_MICROBLAZE_DIV_ZERO_EXCEPTION == 1
\r
303 microblaze_register_exception_handler( XEXC_ID_DIV_BY_ZERO, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DIV_BY_ZERO );
\r
304 #endif /* XPAR_MICROBLAZE_DIV_ZERO_EXCEPTION */
\r
306 #if XPAR_MICROBLAZE_FPU_EXCEPTION == 1
\r
307 microblaze_register_exception_handler( XEXC_ID_FPU, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FPU );
\r
308 #endif /* XPAR_MICROBLAZE_FPU_EXCEPTION */
\r
310 #if XPAR_MICROBLAZE_FSL_EXCEPTION == 1
\r
311 microblaze_register_exception_handler( XEXC_ID_FSL, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FSL );
\r
312 #endif /* XPAR_MICROBLAZE_FSL_EXCEPTION */
\r
314 microblaze_enable_exceptions();
\r
318 /* Exclude the entire file if the MicroBlaze is not configured to handle
\r
319 exceptions, or the application defined configuration item
\r
320 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
321 #endif /* ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) */
\r