2 FreeRTOS V9.0.0rc1 - 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 /* Kernel includes. */
\r
71 #include "FreeRTOS.h"
\r
73 /* Machine includes */
\r
75 #include <machine/intrinsics.h>
\r
76 #include <machine/cint.h>
\r
77 /*---------------------------------------------------------------------------*/
\r
80 * This reference is required by the Save/Restore Context Macros.
\r
82 extern volatile uint32_t *pxCurrentTCB;
\r
83 /*-----------------------------------------------------------*/
\r
86 * This file contains base definitions for all of the possible traps in the system.
\r
87 * It is suggested to provide implementations for all of the traps but for
\r
88 * the time being they simply trigger a DEBUG instruction so that it is easy
\r
89 * to see what caused a particular trap.
\r
91 * Trap Class 6, the SYSCALL, is used exclusively by the operating system.
\r
94 /* The Trap Classes. */
\r
95 #define portMMU_TRAP 0
\r
96 #define portIPT_TRAP 1
\r
97 #define portIE_TRAP 2
\r
98 #define portCM_TRAP 3
\r
99 #define portSBP_TRAP 4
\r
100 #define portASSERT_TRAP 5
\r
101 #define portNMI_TRAP 7
\r
103 /* MMU Trap Identifications. */
\r
104 #define portTIN_MMU_VIRTUAL_ADDRESS_FILL 0
\r
105 #define portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION 1
\r
107 /* Internal Protection Trap Identifications. */
\r
108 #define portTIN_IPT_PRIVILIGED_INSTRUCTION 1
\r
109 #define portTIN_IPT_MEMORY_PROTECTION_READ 2
\r
110 #define portTIN_IPT_MEMORY_PROTECTION_WRITE 3
\r
111 #define portTIN_IPT_MEMORY_PROTECTION_EXECUTION 4
\r
112 #define portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS 5
\r
113 #define portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS 6
\r
114 #define portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION 7
\r
116 /* Instruction Error Trap Identifications. */
\r
117 #define portTIN_IE_ILLEGAL_OPCODE 1
\r
118 #define portTIN_IE_UNIMPLEMENTED_OPCODE 2
\r
119 #define portTIN_IE_INVALID_OPERAND 3
\r
120 #define portTIN_IE_DATA_ADDRESS_ALIGNMENT 4
\r
121 #define portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS 5
\r
123 /* Context Management Trap Identifications. */
\r
124 #define portTIN_CM_FREE_CONTEXT_LIST_DEPLETION 1
\r
125 #define portTIN_CM_CALL_DEPTH_OVERFLOW 2
\r
126 #define portTIN_CM_CALL_DEPTH_UNDEFLOW 3
\r
127 #define portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW 4
\r
128 #define portTIN_CM_CALL_STACK_UNDERFLOW 5
\r
129 #define portTIN_CM_CONTEXT_TYPE 6
\r
130 #define portTIN_CM_NESTING_ERROR 7
\r
132 /* System Bus and Peripherals Trap Identifications. */
\r
133 #define portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR 1
\r
134 #define portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR 2
\r
135 #define portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR 3
\r
136 #define portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR 4
\r
137 #define portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR 5
\r
138 #define portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR 6
\r
140 /* Assertion Trap Identifications. */
\r
141 #define portTIN_ASSERT_ARITHMETIC_OVERFLOW 1
\r
142 #define portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW 2
\r
144 /* Non-maskable Interrupt Trap Identifications. */
\r
145 #define portTIN_NMI_NON_MASKABLE_INTERRUPT 0
\r
146 /*---------------------------------------------------------------------------*/
\r
148 void vMMUTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
149 void vInternalProtectionTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
150 void vInstructionErrorTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
151 void vContextManagementTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
152 void vSystemBusAndPeripheralsTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
153 void vAssertionTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
154 void vNonMaskableInterruptTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
155 /*---------------------------------------------------------------------------*/
\r
157 void vTrapInstallHandlers( void )
\r
159 if( 0 == _install_trap_handler ( portMMU_TRAP, vMMUTrap ) )
\r
164 if( 0 == _install_trap_handler ( portIPT_TRAP, vInternalProtectionTrap ) )
\r
169 if( 0 == _install_trap_handler ( portIE_TRAP, vInstructionErrorTrap ) )
\r
174 if( 0 == _install_trap_handler ( portCM_TRAP, vContextManagementTrap ) )
\r
179 if( 0 == _install_trap_handler ( portSBP_TRAP, vSystemBusAndPeripheralsTrap ) )
\r
184 if( 0 == _install_trap_handler ( portASSERT_TRAP, vAssertionTrap ) )
\r
189 if( 0 == _install_trap_handler ( portNMI_TRAP, vNonMaskableInterruptTrap ) )
\r
194 /*-----------------------------------------------------------*/
\r
196 void vMMUTrap( int iTrapIdentification )
\r
198 switch( iTrapIdentification )
\r
200 case portTIN_MMU_VIRTUAL_ADDRESS_FILL:
\r
201 case portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION:
\r
207 /*---------------------------------------------------------------------------*/
\r
209 void vInternalProtectionTrap( int iTrapIdentification )
\r
211 /* Deliberate fall through to default. */
\r
212 switch( iTrapIdentification )
\r
214 case portTIN_IPT_PRIVILIGED_INSTRUCTION:
\r
215 /* Instruction is not allowed at current execution level, eg DISABLE at User-0. */
\r
217 case portTIN_IPT_MEMORY_PROTECTION_READ:
\r
218 /* Load word using invalid address. */
\r
220 case portTIN_IPT_MEMORY_PROTECTION_WRITE:
\r
221 /* Store Word using invalid address. */
\r
223 case portTIN_IPT_MEMORY_PROTECTION_EXECUTION:
\r
224 /* PC jumped to an address outside of the valid range. */
\r
226 case portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS:
\r
227 /* Access to a peripheral denied at current execution level. */
\r
229 case portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS:
\r
230 /* NULL Pointer. */
\r
232 case portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION:
\r
233 /* Tried to modify a global address pointer register. */
\r
237 pxCurrentTCB[ 0 ] = _mfcr( $PCXI );
\r
242 /*---------------------------------------------------------------------------*/
\r
244 void vInstructionErrorTrap( int iTrapIdentification )
\r
246 /* Deliberate fall through to default. */
\r
247 switch( iTrapIdentification )
\r
249 case portTIN_IE_ILLEGAL_OPCODE:
\r
250 case portTIN_IE_UNIMPLEMENTED_OPCODE:
\r
251 case portTIN_IE_INVALID_OPERAND:
\r
252 case portTIN_IE_DATA_ADDRESS_ALIGNMENT:
\r
253 case portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS:
\r
259 /*---------------------------------------------------------------------------*/
\r
261 void vContextManagementTrap( int iTrapIdentification )
\r
263 /* Deliberate fall through to default. */
\r
264 switch( iTrapIdentification )
\r
266 case portTIN_CM_FREE_CONTEXT_LIST_DEPLETION:
\r
267 case portTIN_CM_CALL_DEPTH_OVERFLOW:
\r
268 case portTIN_CM_CALL_DEPTH_UNDEFLOW:
\r
269 case portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW:
\r
270 case portTIN_CM_CALL_STACK_UNDERFLOW:
\r
271 case portTIN_CM_CONTEXT_TYPE:
\r
272 case portTIN_CM_NESTING_ERROR:
\r
278 /*---------------------------------------------------------------------------*/
\r
280 void vSystemBusAndPeripheralsTrap( int iTrapIdentification )
\r
282 /* Deliberate fall through to default. */
\r
283 switch( iTrapIdentification )
\r
285 case portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR:
\r
286 case portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR:
\r
287 case portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR:
\r
288 case portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR:
\r
289 case portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR:
\r
290 case portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR:
\r
296 /*---------------------------------------------------------------------------*/
\r
298 void vAssertionTrap( int iTrapIdentification )
\r
300 /* Deliberate fall through to default. */
\r
301 switch( iTrapIdentification )
\r
303 case portTIN_ASSERT_ARITHMETIC_OVERFLOW:
\r
304 case portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW:
\r
310 /*---------------------------------------------------------------------------*/
\r
312 void vNonMaskableInterruptTrap( int iTrapIdentification )
\r
314 /* Deliberate fall through to default. */
\r
315 switch( iTrapIdentification )
\r
317 case portTIN_NMI_NON_MASKABLE_INTERRUPT:
\r
323 /*---------------------------------------------------------------------------*/
\r