2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* Scheduler includes. */
\r
55 #include "FreeRTOS.h"
\r
58 /* Hardware includes. */
\r
59 #include <microblaze_exceptions_i.h>
\r
60 #include <microblaze_exceptions_g.h>
\r
62 /* The Xilinx library defined exception entry point stacks a number of
\r
63 registers. These definitions are offsets from the stack pointer to the various
\r
64 stacked register values. */
\r
65 #define portexR3_STACK_OFFSET 4
\r
66 #define portexR4_STACK_OFFSET 5
\r
67 #define portexR5_STACK_OFFSET 6
\r
68 #define portexR6_STACK_OFFSET 7
\r
69 #define portexR7_STACK_OFFSET 8
\r
70 #define portexR8_STACK_OFFSET 9
\r
71 #define portexR9_STACK_OFFSET 10
\r
72 #define portexR10_STACK_OFFSET 11
\r
73 #define portexR11_STACK_OFFSET 12
\r
74 #define portexR12_STACK_OFFSET 13
\r
75 #define portexR15_STACK_OFFSET 16
\r
76 #define portexR18_STACK_OFFSET 19
\r
77 #define portexMSR_STACK_OFFSET 20
\r
78 #define portexR19_STACK_OFFSET -1
\r
80 /* This is defined to equal the size, in bytes, of the stack frame generated by
\r
81 the Xilinx standard library exception entry point. It is required to determine
\r
82 the stack pointer value prior to the exception being entered. */
\r
83 #define portexASM_HANDLER_STACK_FRAME_SIZE 84UL
\r
85 /* The number of bytes a MicroBlaze instruction consumes. */
\r
86 #define portexINSTRUCTION_SIZE 4
\r
88 /* Exclude this entire file if the MicroBlaze is not configured to handle
\r
89 exceptions, or the application defined configuration constant
\r
90 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
91 #if ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 )
\r
93 /* This variable is set in the exception entry code, before
\r
94 vPortExceptionHandler is called. */
\r
95 unsigned long *pulStackPointerOnFunctionEntry = NULL;
\r
97 /* This is the structure that is filled with the MicroBlaze context as it
\r
98 existed immediately prior to the exception occurrence. A pointer to this
\r
99 structure is passed into the vApplicationExceptionRegisterDump() callback
\r
100 function, if one is defined. */
\r
101 static xPortRegisterDump xRegisterDump;
\r
103 /* This is the FreeRTOS exception handler that is installed for all exception
\r
104 types. It is called from vPortExceptionHanlderEntry() - which is itself defined
\r
106 void vPortExceptionHandler( void *pvExceptionID );
\r
107 extern void vPortExceptionHandlerEntry( void *pvExceptionID );
\r
109 /*-----------------------------------------------------------*/
\r
111 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
112 application can optionally define to receive a populated xPortRegisterDump
\r
113 structure. If the application chooses not to define a version of
\r
114 vApplicationExceptionRegisterDump() then this weekly defined default
\r
115 implementation will be called instead. */
\r
116 extern void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump ) __attribute__((weak));
\r
117 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump )
\r
119 ( void ) xRegisterDump;
\r
126 /*-----------------------------------------------------------*/
\r
128 void vPortExceptionHandler( void *pvExceptionID )
\r
130 extern void *pxCurrentTCB;
\r
132 /* Fill an xPortRegisterDump structure with the MicroBlaze context as it
\r
133 was immediately before the exception occurrence. */
\r
135 /* First fill in the name and handle of the task that was in the Running
\r
136 state when the exception occurred. */
\r
137 xRegisterDump.xCurrentTaskHandle = pxCurrentTCB;
\r
138 xRegisterDump.pcCurrentTaskName = pcTaskGetTaskName( NULL );
\r
140 configASSERT( pulStackPointerOnFunctionEntry );
\r
142 /* Obtain the values of registers that were stacked prior to this function
\r
143 being called, and may have changed since they were stacked. */
144 xRegisterDump.ulR3 = pulStackPointerOnFunctionEntry[ portexR3_STACK_OFFSET ];
\r
145 xRegisterDump.ulR4 = pulStackPointerOnFunctionEntry[ portexR4_STACK_OFFSET ];
\r
146 xRegisterDump.ulR5 = pulStackPointerOnFunctionEntry[ portexR5_STACK_OFFSET ];
\r
147 xRegisterDump.ulR6 = pulStackPointerOnFunctionEntry[ portexR6_STACK_OFFSET ];
\r
148 xRegisterDump.ulR7 = pulStackPointerOnFunctionEntry[ portexR7_STACK_OFFSET ];
\r
149 xRegisterDump.ulR8 = pulStackPointerOnFunctionEntry[ portexR8_STACK_OFFSET ];
\r
150 xRegisterDump.ulR9 = pulStackPointerOnFunctionEntry[ portexR9_STACK_OFFSET ];
\r
151 xRegisterDump.ulR10 = pulStackPointerOnFunctionEntry[ portexR10_STACK_OFFSET ];
\r
152 xRegisterDump.ulR11 = pulStackPointerOnFunctionEntry[ portexR11_STACK_OFFSET ];
\r
153 xRegisterDump.ulR12 = pulStackPointerOnFunctionEntry[ portexR12_STACK_OFFSET ];
\r
154 xRegisterDump.ulR15_return_address_from_subroutine = pulStackPointerOnFunctionEntry[ portexR15_STACK_OFFSET ];
\r
155 xRegisterDump.ulR18 = pulStackPointerOnFunctionEntry[ portexR18_STACK_OFFSET ];
\r
156 xRegisterDump.ulR19 = pulStackPointerOnFunctionEntry[ portexR19_STACK_OFFSET ];
\r
157 xRegisterDump.ulMSR = pulStackPointerOnFunctionEntry[ portexMSR_STACK_OFFSET ];
\r
159 /* Obtain the value of all other registers. */
\r
160 xRegisterDump.ulR2_small_data_area = mfgpr( R2 );
\r
161 xRegisterDump.ulR13_read_write_small_data_area = mfgpr( R13 );
\r
162 xRegisterDump.ulR14_return_address_from_interrupt = mfgpr( R14 );
\r
163 xRegisterDump.ulR16_return_address_from_trap = mfgpr( R16 );
\r
164 xRegisterDump.ulR17_return_address_from_exceptions = mfgpr( R17 );
\r
165 xRegisterDump.ulR20 = mfgpr( R20 );
\r
166 xRegisterDump.ulR21 = mfgpr( R21 );
\r
167 xRegisterDump.ulR22 = mfgpr( R22 );
\r
168 xRegisterDump.ulR23 = mfgpr( R23 );
\r
169 xRegisterDump.ulR24 = mfgpr( R24 );
\r
170 xRegisterDump.ulR25 = mfgpr( R25 );
\r
171 xRegisterDump.ulR26 = mfgpr( R26 );
\r
172 xRegisterDump.ulR27 = mfgpr( R27 );
\r
173 xRegisterDump.ulR28 = mfgpr( R28 );
\r
174 xRegisterDump.ulR29 = mfgpr( R29 );
\r
175 xRegisterDump.ulR30 = mfgpr( R30 );
\r
176 xRegisterDump.ulR31 = mfgpr( R31 );
\r
177 xRegisterDump.ulR1_SP = ( ( unsigned long ) pulStackPointerOnFunctionEntry ) + portexASM_HANDLER_STACK_FRAME_SIZE;
\r
178 xRegisterDump.ulEAR = mfear();
\r
179 xRegisterDump.ulESR = mfesr();
\r
180 xRegisterDump.ulEDR = mfedr();
\r
182 /* Move the saved program counter back to the instruction that was executed
\r
183 when the exception occurred. This is only valid for certain types of
\r
185 xRegisterDump.ulPC = xRegisterDump.ulR17_return_address_from_exceptions - portexINSTRUCTION_SIZE;
\r
187 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
189 xRegisterDump.ulFSR = mffsr();
\r
193 xRegisterDump.ulFSR = 0UL;
\r
197 /* Also fill in a string that describes what type of exception this is.
\r
198 The string uses the same ID names as defined in the MicroBlaze standard
\r
199 library exception header files. */
\r
200 switch( ( unsigned long ) pvExceptionID )
\r
203 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_FSL";
\r
206 case XEXC_ID_UNALIGNED_ACCESS :
\r
207 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_UNALIGNED_ACCESS";
\r
210 case XEXC_ID_ILLEGAL_OPCODE :
\r
211 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_ILLEGAL_OPCODE";
\r
214 case XEXC_ID_M_AXI_I_EXCEPTION :
\r
215 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_M_AXI_I_EXCEPTION or XEXC_ID_IPLB_EXCEPTION";
\r
218 case XEXC_ID_M_AXI_D_EXCEPTION :
\r
219 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_M_AXI_D_EXCEPTION or XEXC_ID_DPLB_EXCEPTION";
\r
222 case XEXC_ID_DIV_BY_ZERO :
\r
223 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_DIV_BY_ZERO";
\r
226 case XEXC_ID_STACK_VIOLATION :
\r
227 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_STACK_VIOLATION or XEXC_ID_MMU";
\r
230 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
233 /*_RB_ More decoding required here and in other exceptions. */
\r
234 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_FPU see ulFSR value";
\r
237 #endif /* XPAR_MICROBLAZE_0_USE_FPU */
\r
240 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
241 application can optionally define to receive the populated xPortRegisterDump
\r
242 structure. If the application chooses not to define a version of
\r
243 vApplicationExceptionRegisterDump() then the weekly defined default
\r
244 implementation within this file will be called instead. */
\r
245 vApplicationExceptionRegisterDump( &xRegisterDump );
\r
247 /* Must not attempt to leave this function! */
\r
253 /*-----------------------------------------------------------*/
\r
255 void vPortExceptionsInstallHandlers( void )
\r
257 static unsigned long ulHandlersAlreadyInstalled = pdFALSE;
\r
259 if( ulHandlersAlreadyInstalled == pdFALSE )
\r
261 ulHandlersAlreadyInstalled = pdTRUE;
\r
263 #if XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS == 1
\r
264 microblaze_register_exception_handler( XEXC_ID_UNALIGNED_ACCESS, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_UNALIGNED_ACCESS );
\r
265 #endif /* XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS*/
\r
267 #if XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION == 1
\r
268 microblaze_register_exception_handler( XEXC_ID_ILLEGAL_OPCODE, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_ILLEGAL_OPCODE );
\r
269 #endif /* XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION*/
\r
271 #if XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION == 1
\r
272 microblaze_register_exception_handler( XEXC_ID_M_AXI_I_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_I_EXCEPTION );
\r
273 #endif /* XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION*/
\r
275 #if XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION == 1
\r
276 microblaze_register_exception_handler( XEXC_ID_M_AXI_D_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_D_EXCEPTION );
\r
277 #endif /* XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION*/
\r
279 #if XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION == 1
\r
280 microblaze_register_exception_handler( XEXC_ID_IPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_IPLB_EXCEPTION );
\r
281 #endif /* XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION*/
\r
283 #if XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION == 1
\r
284 microblaze_register_exception_handler( XEXC_ID_DPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DPLB_EXCEPTION );
\r
285 #endif /* XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION*/
\r
287 #if XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION == 1
\r
288 microblaze_register_exception_handler( XEXC_ID_DIV_BY_ZERO, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DIV_BY_ZERO );
\r
289 #endif /* XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION*/
\r
291 #if XPAR_MICROBLAZE_0_FPU_EXCEPTION == 1
\r
292 microblaze_register_exception_handler( XEXC_ID_FPU, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FPU );
\r
293 #endif /* XPAR_MICROBLAZE_0_FPU_EXCEPTION*/
\r
295 #if XPAR_MICROBLAZE_0_FSL_EXCEPTION == 1
\r
296 microblaze_register_exception_handler( XEXC_ID_FSL, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FSL );
\r
297 #endif /* XPAR_MICROBLAZE_0_FSL_EXCEPTION*/
\r
301 /* Exclude the entire file if the MicroBlaze is not configured to handle
\r
302 exceptions, or the application defined configuration item
\r
303 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
304 #endif /* ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) */
\r