2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* Kernel includes. */
\r
66 #include "FreeRTOS.h"
\r
68 /* Machine includes */
\r
70 #include <machine/intrinsics.h>
\r
71 #include <machine/cint.h>
\r
72 /*---------------------------------------------------------------------------*/
\r
75 * This reference is required by the Save/Restore Context Macros.
\r
77 extern volatile unsigned long *pxCurrentTCB;
\r
78 /*-----------------------------------------------------------*/
\r
81 * This file contains base definitions for all of the possible traps in the system.
\r
82 * It is suggested to provide implementations for all of the traps but for
\r
83 * the time being they simply trigger a DEBUG instruction so that it is easy
\r
84 * to see what caused a particular trap.
\r
86 * Trap Class 6, the SYSCALL, is used exclusively by the operating system.
\r
89 /* The Trap Classes. */
\r
90 #define portMMU_TRAP 0
\r
91 #define portIPT_TRAP 1
\r
92 #define portIE_TRAP 2
\r
93 #define portCM_TRAP 3
\r
94 #define portSBP_TRAP 4
\r
95 #define portASSERT_TRAP 5
\r
96 #define portNMI_TRAP 7
\r
98 /* MMU Trap Identifications. */
\r
99 #define portTIN_MMU_VIRTUAL_ADDRESS_FILL 0
\r
100 #define portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION 1
\r
102 /* Internal Protection Trap Identifications. */
\r
103 #define portTIN_IPT_PRIVILIGED_INSTRUCTION 1
\r
104 #define portTIN_IPT_MEMORY_PROTECTION_READ 2
\r
105 #define portTIN_IPT_MEMORY_PROTECTION_WRITE 3
\r
106 #define portTIN_IPT_MEMORY_PROTECTION_EXECUTION 4
\r
107 #define portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS 5
\r
108 #define portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS 6
\r
109 #define portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION 7
\r
111 /* Instruction Error Trap Identifications. */
\r
112 #define portTIN_IE_ILLEGAL_OPCODE 1
\r
113 #define portTIN_IE_UNIMPLEMENTED_OPCODE 2
\r
114 #define portTIN_IE_INVALID_OPERAND 3
\r
115 #define portTIN_IE_DATA_ADDRESS_ALIGNMENT 4
\r
116 #define portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS 5
\r
118 /* Context Management Trap Identifications. */
\r
119 #define portTIN_CM_FREE_CONTEXT_LIST_DEPLETION 1
\r
120 #define portTIN_CM_CALL_DEPTH_OVERFLOW 2
\r
121 #define portTIN_CM_CALL_DEPTH_UNDEFLOW 3
\r
122 #define portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW 4
\r
123 #define portTIN_CM_CALL_STACK_UNDERFLOW 5
\r
124 #define portTIN_CM_CONTEXT_TYPE 6
\r
125 #define portTIN_CM_NESTING_ERROR 7
\r
127 /* System Bus and Peripherals Trap Identifications. */
\r
128 #define portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR 1
\r
129 #define portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR 2
\r
130 #define portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR 3
\r
131 #define portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR 4
\r
132 #define portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR 5
\r
133 #define portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR 6
\r
135 /* Assertion Trap Identifications. */
\r
136 #define portTIN_ASSERT_ARITHMETIC_OVERFLOW 1
\r
137 #define portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW 2
\r
139 /* Non-maskable Interrupt Trap Identifications. */
\r
140 #define portTIN_NMI_NON_MASKABLE_INTERRUPT 0
\r
141 /*---------------------------------------------------------------------------*/
\r
143 void vMMUTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
144 void vInternalProtectionTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
145 void vInstructionErrorTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
146 void vContextManagementTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
147 void vSystemBusAndPeripheralsTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
148 void vAssertionTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
149 void vNonMaskableInterruptTrap( int iTrapIdentification ) __attribute__( ( longcall, weak ) );
\r
150 /*---------------------------------------------------------------------------*/
\r
152 void vTrapInstallHandlers( void )
\r
154 if( 0 == _install_trap_handler ( portMMU_TRAP, vMMUTrap ) )
\r
159 if( 0 == _install_trap_handler ( portIPT_TRAP, vInternalProtectionTrap ) )
\r
164 if( 0 == _install_trap_handler ( portIE_TRAP, vInstructionErrorTrap ) )
\r
169 if( 0 == _install_trap_handler ( portCM_TRAP, vContextManagementTrap ) )
\r
174 if( 0 == _install_trap_handler ( portSBP_TRAP, vSystemBusAndPeripheralsTrap ) )
\r
179 if( 0 == _install_trap_handler ( portASSERT_TRAP, vAssertionTrap ) )
\r
184 if( 0 == _install_trap_handler ( portNMI_TRAP, vNonMaskableInterruptTrap ) )
\r
189 /*-----------------------------------------------------------*/
\r
191 void vMMUTrap( int iTrapIdentification )
\r
193 switch( iTrapIdentification )
\r
195 case portTIN_MMU_VIRTUAL_ADDRESS_FILL:
\r
196 case portTIN_MMU_VIRTUAL_ADDRESS_PROTECTION:
\r
202 /*---------------------------------------------------------------------------*/
\r
204 void vInternalProtectionTrap( int iTrapIdentification )
\r
206 /* Deliberate fall through to default. */
\r
207 switch( iTrapIdentification )
\r
209 case portTIN_IPT_PRIVILIGED_INSTRUCTION:
\r
210 /* Instruction is not allowed at current execution level, eg DISABLE at User-0. */
\r
212 case portTIN_IPT_MEMORY_PROTECTION_READ:
\r
213 /* Load word using invalid address. */
\r
215 case portTIN_IPT_MEMORY_PROTECTION_WRITE:
\r
216 /* Store Word using invalid address. */
\r
218 case portTIN_IPT_MEMORY_PROTECTION_EXECUTION:
\r
219 /* PC jumped to an address outside of the valid range. */
\r
221 case portTIN_IPT_MEMORY_PROTECTION_PERIPHERAL_ACCESS:
\r
222 /* Access to a peripheral denied at current execution level. */
\r
224 case portTIN_IPT_MEMORY_PROTECTION_NULL_ADDRESS:
\r
225 /* NULL Pointer. */
\r
227 case portTIN_IPT_MEMORY_PROTECTION_GLOBAL_REGISTER_WRITE_PROTECTION:
\r
228 /* Tried to modify a global address pointer register. */
\r
232 pxCurrentTCB[ 0 ] = _mfcr( $PCXI );
\r
237 /*---------------------------------------------------------------------------*/
\r
239 void vInstructionErrorTrap( int iTrapIdentification )
\r
241 /* Deliberate fall through to default. */
\r
242 switch( iTrapIdentification )
\r
244 case portTIN_IE_ILLEGAL_OPCODE:
\r
245 case portTIN_IE_UNIMPLEMENTED_OPCODE:
\r
246 case portTIN_IE_INVALID_OPERAND:
\r
247 case portTIN_IE_DATA_ADDRESS_ALIGNMENT:
\r
248 case portTIN_IE_INVALID_LOCAL_MEMORY_ADDRESS:
\r
254 /*---------------------------------------------------------------------------*/
\r
256 void vContextManagementTrap( int iTrapIdentification )
\r
258 /* Deliberate fall through to default. */
\r
259 switch( iTrapIdentification )
\r
261 case portTIN_CM_FREE_CONTEXT_LIST_DEPLETION:
\r
262 case portTIN_CM_CALL_DEPTH_OVERFLOW:
\r
263 case portTIN_CM_CALL_DEPTH_UNDEFLOW:
\r
264 case portTIN_CM_FREE_CONTEXT_LIST_UNDERFLOW:
\r
265 case portTIN_CM_CALL_STACK_UNDERFLOW:
\r
266 case portTIN_CM_CONTEXT_TYPE:
\r
267 case portTIN_CM_NESTING_ERROR:
\r
273 /*---------------------------------------------------------------------------*/
\r
275 void vSystemBusAndPeripheralsTrap( int iTrapIdentification )
\r
277 /* Deliberate fall through to default. */
\r
278 switch( iTrapIdentification )
\r
280 case portTIN_SBP_PROGRAM_FETCH_SYNCHRONOUS_ERROR:
\r
281 case portTIN_SBP_DATA_ACCESS_SYNCHRONOUS_ERROR:
\r
282 case portTIN_SBP_DATA_ACCESS_ASYNCHRONOUS_ERROR:
\r
283 case portTIN_SBP_COPROCESSOR_TRAP_ASYNCHRONOUS_ERROR:
\r
284 case portTIN_SBP_PROGRAM_MEMORY_INTEGRITY_ERROR:
\r
285 case portTIN_SBP_DATA_MEMORY_INTEGRITY_ERROR:
\r
291 /*---------------------------------------------------------------------------*/
\r
293 void vAssertionTrap( int iTrapIdentification )
\r
295 /* Deliberate fall through to default. */
\r
296 switch( iTrapIdentification )
\r
298 case portTIN_ASSERT_ARITHMETIC_OVERFLOW:
\r
299 case portTIN_ASSERT_STICKY_ARITHMETIC_OVERFLOW:
\r
305 /*---------------------------------------------------------------------------*/
\r
307 void vNonMaskableInterruptTrap( int iTrapIdentification )
\r
309 /* Deliberate fall through to default. */
\r
310 switch( iTrapIdentification )
\r
312 case portTIN_NMI_NON_MASKABLE_INTERRUPT:
\r
318 /*---------------------------------------------------------------------------*/
\r