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
124 /*-----------------------------------------------------------*/
\r
126 void vPortExceptionHandler( void *pvExceptionID )
\r
128 extern void *pxCurrentTCB;
\r
130 /* Fill an xPortRegisterDump structure with the MicroBlaze context as it
\r
131 was immediately before the exception occurrence. */
\r
133 /* First fill in the name and handle of the task that was in the Running
\r
134 state when the exception occurred. */
\r
135 xRegisterDump.xCurrentTaskHandle = pxCurrentTCB;
\r
136 xRegisterDump.pcCurrentTaskName = pcTaskGetTaskName( NULL );
\r
138 configASSERT( pulStackPointerOnFunctionEntry );
\r
140 /* Obtain the values of registers that were stacked prior to this function
\r
141 being called, and may have changed since they were stacked. */
142 xRegisterDump.ulR3 = pulStackPointerOnFunctionEntry[ portexR3_STACK_OFFSET ];
\r
143 xRegisterDump.ulR4 = pulStackPointerOnFunctionEntry[ portexR4_STACK_OFFSET ];
\r
144 xRegisterDump.ulR5 = pulStackPointerOnFunctionEntry[ portexR5_STACK_OFFSET ];
\r
145 xRegisterDump.ulR6 = pulStackPointerOnFunctionEntry[ portexR6_STACK_OFFSET ];
\r
146 xRegisterDump.ulR7 = pulStackPointerOnFunctionEntry[ portexR7_STACK_OFFSET ];
\r
147 xRegisterDump.ulR8 = pulStackPointerOnFunctionEntry[ portexR8_STACK_OFFSET ];
\r
148 xRegisterDump.ulR9 = pulStackPointerOnFunctionEntry[ portexR9_STACK_OFFSET ];
\r
149 xRegisterDump.ulR10 = pulStackPointerOnFunctionEntry[ portexR10_STACK_OFFSET ];
\r
150 xRegisterDump.ulR11 = pulStackPointerOnFunctionEntry[ portexR11_STACK_OFFSET ];
\r
151 xRegisterDump.ulR12 = pulStackPointerOnFunctionEntry[ portexR12_STACK_OFFSET ];
\r
152 xRegisterDump.ulR15_return_address_from_subroutine = pulStackPointerOnFunctionEntry[ portexR15_STACK_OFFSET ];
\r
153 xRegisterDump.ulR18 = pulStackPointerOnFunctionEntry[ portexR18_STACK_OFFSET ];
\r
154 xRegisterDump.ulR19 = pulStackPointerOnFunctionEntry[ portexR19_STACK_OFFSET ];
\r
155 xRegisterDump.ulMSR = pulStackPointerOnFunctionEntry[ portexMSR_STACK_OFFSET ];
\r
157 /* Obtain the value of all other registers. */
\r
158 xRegisterDump.ulR2_small_data_area = mfgpr( R2 );
\r
159 xRegisterDump.ulR13_read_write_small_data_area = mfgpr( R13 );
\r
160 xRegisterDump.ulR14_return_address_from_interrupt = mfgpr( R14 );
\r
161 xRegisterDump.ulR16_return_address_from_trap = mfgpr( R16 );
\r
162 xRegisterDump.ulR17_return_address_from_exceptions = mfgpr( R17 );
\r
163 xRegisterDump.ulR20 = mfgpr( R20 );
\r
164 xRegisterDump.ulR21 = mfgpr( R21 );
\r
165 xRegisterDump.ulR22 = mfgpr( R22 );
\r
166 xRegisterDump.ulR23 = mfgpr( R23 );
\r
167 xRegisterDump.ulR24 = mfgpr( R24 );
\r
168 xRegisterDump.ulR25 = mfgpr( R25 );
\r
169 xRegisterDump.ulR26 = mfgpr( R26 );
\r
170 xRegisterDump.ulR27 = mfgpr( R27 );
\r
171 xRegisterDump.ulR28 = mfgpr( R28 );
\r
172 xRegisterDump.ulR29 = mfgpr( R29 );
\r
173 xRegisterDump.ulR30 = mfgpr( R30 );
\r
174 xRegisterDump.ulR31 = mfgpr( R31 );
\r
175 xRegisterDump.ulR1_SP = ( ( unsigned long ) pulStackPointerOnFunctionEntry ) + portexASM_HANDLER_STACK_FRAME_SIZE;
\r
176 xRegisterDump.ulEAR = mfear();
\r
177 xRegisterDump.ulESR = mfesr();
\r
178 xRegisterDump.ulEDR = mfedr();
\r
180 /* Move the saved program counter back to the instruction that was executed
\r
181 when the exception occurred. This is only valid for certain types of
\r
183 xRegisterDump.ulPC = xRegisterDump.ulR17_return_address_from_exceptions - portexINSTRUCTION_SIZE;
\r
185 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
187 xRegisterDump.ulFSR = mffsr();
\r
191 xRegisterDump.ulFSR = 0UL;
\r
195 /* Also fill in a string that describes what type of exception this is.
\r
196 The string uses the same ID names as defined in the MicroBlaze standard
\r
197 library exception header files. */
\r
198 switch( ( unsigned long ) pvExceptionID )
\r
201 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_FSL";
\r
204 case XEXC_ID_UNALIGNED_ACCESS :
\r
205 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_UNALIGNED_ACCESS";
\r
208 case XEXC_ID_ILLEGAL_OPCODE :
\r
209 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_ILLEGAL_OPCODE";
\r
212 case XEXC_ID_M_AXI_I_EXCEPTION :
\r
213 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_M_AXI_I_EXCEPTION or XEXC_ID_IPLB_EXCEPTION";
\r
216 case XEXC_ID_M_AXI_D_EXCEPTION :
\r
217 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_M_AXI_D_EXCEPTION or XEXC_ID_DPLB_EXCEPTION";
\r
220 case XEXC_ID_DIV_BY_ZERO :
\r
221 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_DIV_BY_ZERO";
\r
224 case XEXC_ID_STACK_VIOLATION :
\r
225 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_STACK_VIOLATION or XEXC_ID_MMU";
\r
228 #if XPAR_MICROBLAZE_0_USE_FPU == 1
\r
231 /*_RB_ More decoding required here and in other exceptions. */
\r
232 xRegisterDump.pcExceptionCause = ( signed char * const ) "XEXC_ID_FPU see ulFSR value";
\r
235 #endif /* XPAR_MICROBLAZE_0_USE_FPU */
\r
238 /* vApplicationExceptionRegisterDump() is a callback function that the
\r
239 application can optionally define to receive the populated xPortRegisterDump
\r
240 structure. If the application chooses not to define a version of
\r
241 vApplicationExceptionRegisterDump() then the weekly defined default
\r
242 implementation within this file will be called instead. */
\r
243 vApplicationExceptionRegisterDump( &xRegisterDump );
\r
245 /* Must not attempt to leave this function! */
\r
251 /*-----------------------------------------------------------*/
\r
253 void vPortExceptionsInstallHandlers( void )
\r
255 static unsigned long ulHandlersAlreadyInstalled = pdFALSE;
\r
257 if( ulHandlersAlreadyInstalled == pdFALSE )
\r
259 ulHandlersAlreadyInstalled = pdTRUE;
\r
261 #if XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS == 1
\r
262 microblaze_register_exception_handler( XEXC_ID_UNALIGNED_ACCESS, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_UNALIGNED_ACCESS );
\r
263 #endif /* XPAR_MICROBLAZE_0_UNALIGNED_EXCEPTIONS*/
\r
265 #if XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION == 1
\r
266 microblaze_register_exception_handler( XEXC_ID_ILLEGAL_OPCODE, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_ILLEGAL_OPCODE );
\r
267 #endif /* XPAR_MICROBLAZE_0_ILL_OPCODE_EXCEPTION*/
\r
269 #if XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION == 1
\r
270 microblaze_register_exception_handler( XEXC_ID_M_AXI_I_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_I_EXCEPTION );
\r
271 #endif /* XPAR_MICROBLAZE_0_M_AXI_I_BUS_EXCEPTION*/
\r
273 #if XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION == 1
\r
274 microblaze_register_exception_handler( XEXC_ID_M_AXI_D_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_M_AXI_D_EXCEPTION );
\r
275 #endif /* XPAR_MICROBLAZE_0_M_AXI_D_BUS_EXCEPTION*/
\r
277 #if XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION == 1
\r
278 microblaze_register_exception_handler( XEXC_ID_IPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_IPLB_EXCEPTION );
\r
279 #endif /* XPAR_MICROBLAZE_0_IPLB_BUS_EXCEPTION*/
\r
281 #if XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION == 1
\r
282 microblaze_register_exception_handler( XEXC_ID_DPLB_EXCEPTION, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DPLB_EXCEPTION );
\r
283 #endif /* XPAR_MICROBLAZE_0_DPLB_BUS_EXCEPTION*/
\r
285 #if XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION == 1
\r
286 microblaze_register_exception_handler( XEXC_ID_DIV_BY_ZERO, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_DIV_BY_ZERO );
\r
287 #endif /* XPAR_MICROBLAZE_0_DIV_ZERO_EXCEPTION*/
\r
289 #if XPAR_MICROBLAZE_0_FPU_EXCEPTION == 1
\r
290 microblaze_register_exception_handler( XEXC_ID_FPU, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FPU );
\r
291 #endif /* XPAR_MICROBLAZE_0_FPU_EXCEPTION*/
\r
293 #if XPAR_MICROBLAZE_0_FSL_EXCEPTION == 1
\r
294 microblaze_register_exception_handler( XEXC_ID_FSL, vPortExceptionHandlerEntry, ( void * ) XEXC_ID_FSL );
\r
295 #endif /* XPAR_MICROBLAZE_0_FSL_EXCEPTION*/
\r
299 /* Exclude the entire file if the MicroBlaze is not configured to handle
\r
300 exceptions, or the application defined configuration item
\r
301 configINSTALL_EXCEPTION_HANDLERS is not set to 1. */
\r
302 #endif /* ( MICROBLAZE_EXCEPTIONS_ENABLED == 1 ) && ( configINSTALL_EXCEPTION_HANDLERS == 1 ) */
\r