2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /* Scheduler includes. */
\r
67 #include "FreeRTOS.h"
\r
70 /* Hardware includes. */
\r
71 #include <microblaze_exceptions_i.h>
\r
72 #include <microblaze_exceptions_g.h>
\r
74 /* The Xilinx library defined exception entry point stacks a number of
\r
75 registers. These definitions are offsets from the stack pointer to the various
\r
76 stacked register values. */
\r
77 #define portexR3_STACK_OFFSET 4
\r
78 #define portexR4_STACK_OFFSET 5
\r
79 #define portexR5_STACK_OFFSET 6
\r
80 #define portexR6_STACK_OFFSET 7
\r
81 #define portexR7_STACK_OFFSET 8
\r
82 #define portexR8_STACK_OFFSET 9
\r
83 #define portexR9_STACK_OFFSET 10
\r
84 #define portexR10_STACK_OFFSET 11
\r
85 #define portexR11_STACK_OFFSET 12
\r
86 #define portexR12_STACK_OFFSET 13
\r
87 #define portexR15_STACK_OFFSET 16
\r
88 #define portexR18_STACK_OFFSET 19
\r
89 #define portexMSR_STACK_OFFSET 20
\r
90 #define portexR19_STACK_OFFSET -1
\r
92 /* This is defined to equal the size, in bytes, of the stack frame generated by
\r
93 the Xilinx standard library exception entry point. It is required to determine
\r
94 the stack pointer value prior to the exception being entered. */
\r
95 #define portexASM_HANDLER_STACK_FRAME_SIZE 84UL
\r
97 /* The number of bytes a MicroBlaze instruction consumes. */
\r
98 #define portexINSTRUCTION_SIZE 4
\r
100 /* Exclude this entire file if the MicroBlaze is not configured to handle
\r
101 exceptions, or the application defined configuration constant
\r
102 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
103 #if ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 )
\r
105 /* This variable is set in the exception entry code, before
\r
106 vPortExceptionHandler is called. */
\r
107 uint32_t *pulStackPointerOnFunctionEntry = NULL;
\r
109 /* This is the structure that is filled with the MicroBlaze context as it
\r
110 existed immediately prior to the exception occurrence. A pointer to this
\r
111 structure is passed into the vApplicationExceptionRegisterDump() callback
\r
112 function, if one is defined. */
\r
113 static xPortRegisterDump xRegisterDump;
\r
115 /* This is the FreeRTOS exception handler that is installed for all exception
\r
116 types. It is called from vPortExceptionHanlderEntry() - which is itself defined
\r
118 void vPortExceptionHandler( void *pvExceptionID );
\r
119 extern void vPortExceptionHandlerEntry( void *pvExceptionID );
\r
121 /*-----------------------------------------------------------*/
\r
123 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
124 application can optionally define to receive a populated xPortRegisterDump
\r
125 structure. If the application chooses not to define a version of
\r
126 vApplicationExceptionRegisterDump() then this weekly defined default
\r
127 implementation will be called instead. */
\r
128 extern void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ) __attribute__((weak));
\r
129 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump )
\r
131 ( void ) xRegisterDump;
\r
138 /*-----------------------------------------------------------*/
\r
140 void vPortExceptionHandler( void *pvExceptionID )
\r
142 extern void *pxCurrentTCB;
\r
144 /* Fill an xPortRegisterDump structure with the MicroBlaze context as it
\r
145 was immediately before the exception occurrence. */
\r
147 /* First fill in the name and handle of the task that was in the Running
\r
148 state when the exception occurred. */
\r
149 xRegisterDump.xCurrentTaskHandle = pxCurrentTCB;
\r
150 xRegisterDump.pcCurrentTaskName = pcTaskGetTaskName( NULL );
\r
152 configASSERT( pulStackPointerOnFunctionEntry );
\r
154 /* Obtain the values of registers that were stacked prior to this function
\r
155 being called, and may have changed since they were stacked. */
\r
156 xRegisterDump.ulR3 = pulStackPointerOnFunctionEntry[ portexR3_STACK_OFFSET ];
\r
157 xRegisterDump.ulR4 = pulStackPointerOnFunctionEntry[ portexR4_STACK_OFFSET ];
\r
158 xRegisterDump.ulR5 = pulStackPointerOnFunctionEntry[ portexR5_STACK_OFFSET ];
\r
159 xRegisterDump.ulR6 = pulStackPointerOnFunctionEntry[ portexR6_STACK_OFFSET ];
\r
160 xRegisterDump.ulR7 = pulStackPointerOnFunctionEntry[ portexR7_STACK_OFFSET ];
\r
161 xRegisterDump.ulR8 = pulStackPointerOnFunctionEntry[ portexR8_STACK_OFFSET ];
\r
162 xRegisterDump.ulR9 = pulStackPointerOnFunctionEntry[ portexR9_STACK_OFFSET ];
\r
163 xRegisterDump.ulR10 = pulStackPointerOnFunctionEntry[ portexR10_STACK_OFFSET ];
\r
164 xRegisterDump.ulR11 = pulStackPointerOnFunctionEntry[ portexR11_STACK_OFFSET ];
\r
165 xRegisterDump.ulR12 = pulStackPointerOnFunctionEntry[ portexR12_STACK_OFFSET ];
\r
166 xRegisterDump.ulR15_return_address_from_subroutine = pulStackPointerOnFunctionEntry[ portexR15_STACK_OFFSET ];
\r
167 xRegisterDump.ulR18 = pulStackPointerOnFunctionEntry[ portexR18_STACK_OFFSET ];
\r
168 xRegisterDump.ulR19 = pulStackPointerOnFunctionEntry[ portexR19_STACK_OFFSET ];
\r
169 xRegisterDump.ulMSR = pulStackPointerOnFunctionEntry[ portexMSR_STACK_OFFSET ];
\r
171 /* Obtain the value of all other registers. */
\r
172 xRegisterDump.ulR2_small_data_area = mfgpr( R2 );
\r
173 xRegisterDump.ulR13_read_write_small_data_area = mfgpr( R13 );
\r
174 xRegisterDump.ulR14_return_address_from_interrupt = mfgpr( R14 );
\r
175 xRegisterDump.ulR16_return_address_from_trap = mfgpr( R16 );
\r
176 xRegisterDump.ulR17_return_address_from_exceptions = mfgpr( R17 );
\r
177 xRegisterDump.ulR20 = mfgpr( R20 );
\r
178 xRegisterDump.ulR21 = mfgpr( R21 );
\r
179 xRegisterDump.ulR22 = mfgpr( R22 );
\r
180 xRegisterDump.ulR23 = mfgpr( R23 );
\r
181 xRegisterDump.ulR24 = mfgpr( R24 );
\r
182 xRegisterDump.ulR25 = mfgpr( R25 );
\r
183 xRegisterDump.ulR26 = mfgpr( R26 );
\r
184 xRegisterDump.ulR27 = mfgpr( R27 );
\r
185 xRegisterDump.ulR28 = mfgpr( R28 );
\r
186 xRegisterDump.ulR29 = mfgpr( R29 );
\r
187 xRegisterDump.ulR30 = mfgpr( R30 );
\r
188 xRegisterDump.ulR31 = mfgpr( R31 );
\r
189 xRegisterDump.ulR1_SP = ( ( uint32_t ) pulStackPointerOnFunctionEntry ) + portexASM_HANDLER_STACK_FRAME_SIZE;
\r
190 xRegisterDump.ulEAR = mfear();
\r
191 xRegisterDump.ulESR = mfesr();
\r
192 xRegisterDump.ulEDR = mfedr();
\r
194 /* Move the saved program counter back to the instruction that was executed
\r
195 when the exception occurred. This is only valid for certain types of
\r
197 xRegisterDump.ulPC = xRegisterDump.ulR17_return_address_from_exceptions - portexINSTRUCTION_SIZE;
\r
199 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
201 xRegisterDump.ulFSR = mffsr();
\r
205 xRegisterDump.ulFSR = 0UL;
\r
209 /* Also fill in a string that describes what type of exception this is.
\r
210 The string uses the same ID names as defined in the MicroBlaze standard
\r
211 library exception header files. */
\r
212 switch( ( uint32_t ) pvExceptionID )
\r
215 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_FSL";
\r
218 case XEXC_ID_UNALIGNED_ACCESS :
\r
219 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_UNALIGNED_ACCESS";
\r
222 case XEXC_ID_ILLEGAL_OPCODE :
\r
223 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_ILLEGAL_OPCODE";
\r
226 case XEXC_ID_M_AXI_I_EXCEPTION :
\r
227 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_M_AXI_I_EXCEPTION or XEXC_ID_IPLB_EXCEPTION";
\r
230 case XEXC_ID_M_AXI_D_EXCEPTION :
\r
231 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_M_AXI_D_EXCEPTION or XEXC_ID_DPLB_EXCEPTION";
\r
234 case XEXC_ID_DIV_BY_ZERO :
\r
235 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_DIV_BY_ZERO";
\r
238 case XEXC_ID_STACK_VIOLATION :
\r
239 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_STACK_VIOLATION or XEXC_ID_MMU";
\r
242 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
245 xRegisterDump.pcExceptionCause = ( int8_t * const ) "XEXC_ID_FPU see ulFSR value";
\r
248 #endif /* XPAR_MICROBLAZE_0_USE_FPU */
\r
251 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
252 application can optionally define to receive the populated xPortRegisterDump
\r
253 structure. If the application chooses not to define a version of
\r
254 vApplicationExceptionRegisterDump() then the weekly defined default
\r
255 implementation within this file will be called instead. */
\r
256 vApplicationExceptionRegisterDump( &xRegisterDump );
\r
258 /* Must not attempt to leave this function! */
\r
264 /*-----------------------------------------------------------*/
\r
266 void vPortExceptionsInstallHandlers( void )
\r
268 static uint32_t ulHandlersAlreadyInstalled = pdFALSE;
\r
270 if( ulHandlersAlreadyInstalled == pdFALSE )
\r
272 ulHandlersAlreadyInstalled = pdTRUE;
\r
274 #if XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS == 1
\r
275 microblaze_register_exception_handler( XEXC_ID_UNALIGNED_ACCESS, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_UNALIGNED_ACCESS );
\r
276 #endif /* XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS*/
\r
278 #if XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION == 1
\r
279 microblaze_register_exception_handler( XEXC_ID_ILLEGAL_OPCODE, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_ILLEGAL_OPCODE );
\r
280 #endif /* XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION*/
\r
282 #if XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION == 1
\r
283 microblaze_register_exception_handler( XEXC_ID_M_AXI_I_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_I_EXCEPTION );
\r
284 #endif /* XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION*/
\r
286 #if XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION == 1
\r
287 microblaze_register_exception_handler( XEXC_ID_M_AXI_D_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_D_EXCEPTION );
\r
288 #endif /* XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION*/
\r
290 #if XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION == 1
\r
291 microblaze_register_exception_handler( XEXC_ID_IPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_IPLB_EXCEPTION );
\r
292 #endif /* XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION*/
\r
294 #if XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION == 1
\r
295 microblaze_register_exception_handler( XEXC_ID_DPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DPLB_EXCEPTION );
\r
296 #endif /* XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION*/
\r
298 #if XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION == 1
\r
299 microblaze_register_exception_handler( XEXC_ID_DIV_BY_ZERO, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DIV_BY_ZERO );
\r
300 #endif /* XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION*/
\r
302 #if XPAR_MICROBLAZE_0_FPU_EXCEPTION == 1
\r
303 microblaze_register_exception_handler( XEXC_ID_FPU, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FPU );
\r
304 #endif /* XPAR_MICROBLAZE_0_FPU_EXCEPTION*/
\r
306 #if XPAR_MICROBLAZE_0_FSL_EXCEPTION == 1
\r
307 microblaze_register_exception_handler( XEXC_ID_FSL, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FSL );
\r
308 #endif /* XPAR_MICROBLAZE_0_FSL_EXCEPTION*/
\r
312 /* Exclude the entire file if the MicroBlaze is not configured to handle
\r
313 exceptions, or the application defined configuration item
\r
314 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
315 #endif /* ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) */
\r