1 /******************************************************************************
\r
2 * @file system_ARMCA9.c
\r
3 * @brief CMSIS Device System Source File for ARM Cortex-A9 Device Series
\r
9 ******************************************************************************/
\r
11 * Copyright (c) 2009-2017 ARM Limited. All rights reserved.
\r
13 * SPDX-License-Identifier: Apache-2.0
\r
15 * Licensed under the Apache License, Version 2.0 (the License); you may
\r
16 * not use this file except in compliance with the License.
\r
17 * You may obtain a copy of the License at
\r
19 * www.apache.org/licenses/LICENSE-2.0
\r
21 * Unless required by applicable law or agreed to in writing, software
\r
22 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
\r
23 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
24 * See the License for the specific language governing permissions and
\r
25 * limitations under the License.
\r
30 /*----------------------------------------------------------------------------
\r
32 *----------------------------------------------------------------------------*/
\r
33 #define USR_MODE 0x10 // User mode
\r
34 #define FIQ_MODE 0x11 // Fast Interrupt Request mode
\r
35 #define IRQ_MODE 0x12 // Interrupt Request mode
\r
36 #define SVC_MODE 0x13 // Supervisor mode
\r
37 #define ABT_MODE 0x17 // Abort mode
\r
38 #define UND_MODE 0x1B // Undefined Instruction mode
\r
39 #define SYS_MODE 0x1F // System mode
\r
41 #define SVC_Handler FreeRTOS_SWI_Handler
\r
42 #define IRQ_Handler FreeRTOS_IRQ_Handler
\r
44 /*----------------------------------------------------------------------------
\r
45 Linker generated Symbols
\r
46 *----------------------------------------------------------------------------*/
\r
47 extern uint32_t Image$$FIQ_STACK$$ZI$$Limit;
\r
48 extern uint32_t Image$$IRQ_STACK$$ZI$$Limit;
\r
49 extern uint32_t Image$$SVC_STACK$$ZI$$Limit;
\r
50 extern uint32_t Image$$ABT_STACK$$ZI$$Limit;
\r
51 extern uint32_t Image$$UND_STACK$$ZI$$Limit;
\r
52 extern uint32_t Image$$ARM_LIB_STACK$$ZI$$Limit;
\r
54 /*----------------------------------------------------------------------------
\r
56 *----------------------------------------------------------------------------*/
\r
57 void Reset_Handler(void);
\r
59 /*----------------------------------------------------------------------------
\r
60 Exception / Interrupt Handler
\r
61 *----------------------------------------------------------------------------*/
\r
62 void Undef_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
63 void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
64 void PAbt_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
65 void DAbt_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
66 void IRQ_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
67 void FIQ_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
69 /*----------------------------------------------------------------------------
\r
70 Exception / Interrupt Vector Table
\r
71 *----------------------------------------------------------------------------*/
\r
72 void Vectors(void) __attribute__ ((section("RESET")));
\r
73 __ASM void Vectors(void) {
\r
74 IMPORT Reset_Handler
\r
75 IMPORT Undef_Handler
\r
81 LDR PC, =Reset_Handler
\r
82 LDR PC, =Undef_Handler
\r
83 LDR PC, =SVC_Handler
\r
84 LDR PC, =PAbt_Handler
\r
85 LDR PC, =DAbt_Handler
\r
87 LDR PC, =IRQ_Handler
\r
88 LDR PC, =FIQ_Handler
\r
91 /*----------------------------------------------------------------------------
\r
92 Reset Handler called on controller reset
\r
93 *----------------------------------------------------------------------------*/
\r
94 void Reset_Handler(void) {
\r
97 // Put any cores other than 0 to sleep
\r
98 if ((__get_MPIDR()&3U)!=0) __WFI();
\r
100 reg = __get_SCTLR(); // Read CP15 System Control register
\r
101 reg &= ~(0x1 << 12); // Clear I bit 12 to disable I Cache
\r
102 reg &= ~(0x1 << 2); // Clear C bit 2 to disable D Cache
\r
103 reg &= ~(0x1 << 0); // Clear M bit 0 to disable MMU
\r
104 reg &= ~(0x1 << 11); // Clear Z bit 11 to disable branch prediction
\r
105 reg &= ~(0x1 << 13); // Clear V bit 13 to disable hivecs
\r
106 __set_SCTLR(reg); // Write value back to CP15 System Control register
\r
109 reg = __get_ACTRL(); // Read CP15 Auxiliary Control Register
\r
110 reg |= (0x1 << 1); // Enable L2 prefetch hint (UNK/WI since r4p1)
\r
111 __set_ACTRL(reg); // Write CP15 Auxiliary Control Register
\r
113 __set_VBAR((uint32_t)((uint32_t*)&Vectors));
\r
115 // Setup Stack for each exceptional mode
\r
116 __set_mode(FIQ_MODE);
\r
117 __set_SP((uint32_t)&Image$$FIQ_STACK$$ZI$$Limit);
\r
118 __set_mode(IRQ_MODE);
\r
119 __set_SP((uint32_t)&Image$$IRQ_STACK$$ZI$$Limit);
\r
120 __set_mode(SVC_MODE);
\r
121 __set_SP((uint32_t)&Image$$SVC_STACK$$ZI$$Limit);
\r
122 __set_mode(ABT_MODE);
\r
123 __set_SP((uint32_t)&Image$$ABT_STACK$$ZI$$Limit);
\r
124 __set_mode(UND_MODE);
\r
125 __set_SP((uint32_t)&Image$$UND_STACK$$ZI$$Limit);
\r
126 __set_mode(SYS_MODE);
\r
127 __set_SP((uint32_t)&Image$$ARM_LIB_STACK$$ZI$$Limit);
\r
129 // Create Translation Table
\r
130 MMU_CreateTranslationTable();
\r
132 // Invalidate entire Unified TLB
\r
134 // Invalidate entire branch predictor array
\r
138 // Invalidate instruction cache and flush branch target cache
\r
143 // Invalidate data cache
\r
144 __L1C_CleanInvalidateCache(0);
\r
146 // Invalidate entire Unified TLB
\r
148 // Invalidate entire branch predictor array
\r
152 // Invalidate instruction cache and flush branch target cache
\r
157 // Enable MMU, but leave caches disabled (they will be enabled later)
\r
158 reg = __get_SCTLR(); // Read CP15 System Control register
\r
159 reg |= (0x1 << 29); // Set AFE bit 29 to enable simplified access permissions model
\r
160 reg &= ~(0x1 << 28); // Clear TRE bit 28 to disable TEX remap
\r
161 reg &= ~(0x1 << 12); // Clear I bit 12 to disable I Cache
\r
162 reg &= ~(0x1 << 2); // Clear C bit 2 to disable D Cache
\r
163 reg &= ~(0x1 << 1); // Clear A bit 1 to disable strict alignment fault checking
\r
164 reg |= (0x1 << 0); // Set M bit 0 to enable MMU
\r
165 __set_SCTLR(reg); // Write CP15 System Control register
\r
169 extern void __main(void);
\r
173 /*----------------------------------------------------------------------------
\r
174 Default Handler for Exceptions / Interrupts
\r
175 *----------------------------------------------------------------------------*/
\r
176 void Default_Handler(void) {
\r