|
| 1 | +;/****************************************************************************** |
| 2 | +; * @file startup_RZ_A1H.S |
| 3 | +; * @brief CMSIS Device System Source File for ARM Cortex-A9 Device Series |
| 4 | +; * |
| 5 | +; * @note |
| 6 | +; * |
| 7 | +; ******************************************************************************/ |
| 8 | +;/* |
| 9 | +; * Copyright (c) 2009-2017 ARM Limited. All rights reserved. |
| 10 | +; * |
| 11 | +; * SPDX-License-Identifier: Apache-2.0 |
| 12 | +; * |
| 13 | +; * Licensed under the Apache License, Version 2.0 (the License); you may |
| 14 | +; * not use this file except in compliance with the License. |
| 15 | +; * You may obtain a copy of the License at |
| 16 | +; * |
| 17 | +; * www.apache.org/licenses/LICENSE-2.0 |
| 18 | +; * |
| 19 | +; * Unless required by applicable law or agreed to in writing, software |
| 20 | +; * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 21 | +; * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 22 | +; * See the License for the specific language governing permissions and |
| 23 | +; * limitations under the License. |
| 24 | +; */ |
| 25 | + |
| 26 | +__UND_STACK_SIZE EQU 0x00000100 |
| 27 | +__SVC_STACK_SIZE EQU 0x00008000 |
| 28 | +__ABT_STACK_SIZE EQU 0x00000100 |
| 29 | +__FIQ_STACK_SIZE EQU 0x00000100 |
| 30 | +__IRQ_STACK_SIZE EQU 0x0000F000 |
| 31 | + |
| 32 | +USR_MODE EQU 0x10 ; User mode |
| 33 | +FIQ_MODE EQU 0x11 ; Fast Interrupt Request mode |
| 34 | +IRQ_MODE EQU 0x12 ; Interrupt Request mode |
| 35 | +SVC_MODE EQU 0x13 ; Supervisor mode |
| 36 | +ABT_MODE EQU 0x17 ; Abort mode |
| 37 | +UND_MODE EQU 0x1B ; Undefined Instruction mode |
| 38 | +SYS_MODE EQU 0x1F ; System mode |
| 39 | + |
| 40 | + |
| 41 | + PRESERVE8 |
| 42 | + ARM |
| 43 | + |
| 44 | + AREA RESET, CODE, READONLY |
| 45 | + |
| 46 | +Vectors PROC |
| 47 | + EXPORT Vectors |
| 48 | + IMPORT Undef_Handler |
| 49 | + IMPORT SVC_Handler |
| 50 | + IMPORT PAbt_Handler |
| 51 | + IMPORT DAbt_Handler |
| 52 | + IMPORT IRQ_Handler |
| 53 | + IMPORT FIQ_Handler |
| 54 | + |
| 55 | + LDR PC, =Reset_Handler |
| 56 | + LDR PC, =Undef_Handler |
| 57 | + LDR PC, =SVC_Handler |
| 58 | + LDR PC, =PAbt_Handler |
| 59 | + LDR PC, =DAbt_Handler |
| 60 | + NOP |
| 61 | + LDR PC, =IRQ_Handler |
| 62 | + LDR PC, =FIQ_Handler |
| 63 | + |
| 64 | + ENDP |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + AREA |.text|, CODE, READONLY |
| 69 | + |
| 70 | +Reset_Handler PROC |
| 71 | + EXPORT Reset_Handler |
| 72 | + IMPORT SystemInit |
| 73 | + IMPORT __main |
| 74 | + |
| 75 | + |
| 76 | + ; Mask interrupts |
| 77 | + CPSID if |
| 78 | + |
| 79 | + ; Put any cores other than 0 to sleep |
| 80 | + MRC p15, 0, R0, c0, c0, 5 ; Read MPIDR |
| 81 | + ANDS R0, R0, #3 |
| 82 | +goToSleep |
| 83 | + WFINE |
| 84 | + BNE goToSleep |
| 85 | + |
| 86 | + ; Reset SCTLR Settings |
| 87 | + MRC p15, 0, R0, c1, c0, 0 ; Read CP15 System Control register |
| 88 | + BIC R0, R0, #(0x1 << 12) ; Clear I bit 12 to disable I Cache |
| 89 | + BIC R0, R0, #(0x1 << 2) ; Clear C bit 2 to disable D Cache |
| 90 | + BIC R0, R0, #0x1 ; Clear M bit 0 to disable MMU |
| 91 | + BIC R0, R0, #(0x1 << 11) ; Clear Z bit 11 to disable branch prediction |
| 92 | + BIC R0, R0, #(0x1 << 13) ; Clear V bit 13 to disable hivecs |
| 93 | + MCR p15, 0, R0, c1, c0, 0 ; Write value back to CP15 System Control register |
| 94 | + ISB |
| 95 | + |
| 96 | + ; Configure ACTLR |
| 97 | + MRC p15, 0, r0, c1, c0, 1 ; Read CP15 Auxiliary Control Register |
| 98 | + ORR r0, r0, #(1 << 1) ; Enable L2 prefetch hint (UNK/WI since r4p1) |
| 99 | + MCR p15, 0, r0, c1, c0, 1 ; Write CP15 Auxiliary Control Register |
| 100 | + |
| 101 | + ; Set Vector Base Address Register (VBAR) to point to this application's vector table |
| 102 | + LDR R0, =Vectors |
| 103 | + MCR p15, 0, R0, c12, c0, 0 |
| 104 | + |
| 105 | + ; Setup Stack for each exceptional mode |
| 106 | + IMPORT |Image$$ARM_LIB_STACK$$ZI$$Limit| |
| 107 | + LDR R0, =|Image$$ARM_LIB_STACK$$ZI$$Limit| |
| 108 | + |
| 109 | + ;Enter Undefined Instruction Mode and set its Stack Pointer |
| 110 | + CPS #UND_MODE |
| 111 | + MOV SP, R0 |
| 112 | + SUB R0, R0, #__UND_STACK_SIZE |
| 113 | + |
| 114 | + ; Enter Abort Mode and set its Stack Pointer |
| 115 | + CPS #ABT_MODE |
| 116 | + MOV SP, R0 |
| 117 | + SUB R0, R0, #__ABT_STACK_SIZE |
| 118 | + |
| 119 | + ; Enter FIQ Mode and set its Stack Pointer |
| 120 | + CPS #FIQ_MODE |
| 121 | + MOV SP, R0 |
| 122 | + SUB R0, R0, #__FIQ_STACK_SIZE |
| 123 | + |
| 124 | + ; Enter IRQ Mode and set its Stack Pointer |
| 125 | + CPS #IRQ_MODE |
| 126 | + MOV SP, R0 |
| 127 | + SUB R0, R0, #__IRQ_STACK_SIZE |
| 128 | + |
| 129 | + ; Enter Supervisor Mode and set its Stack Pointer |
| 130 | + CPS #SVC_MODE |
| 131 | + MOV SP, R0 |
| 132 | + SUB R0, R0, #__SVC_STACK_SIZE |
| 133 | + |
| 134 | + ; Enter System Mode to complete initialization and enter kernel |
| 135 | + CPS #SYS_MODE |
| 136 | + MOV SP, R0 |
| 137 | + |
| 138 | + ; Call SystemInit |
| 139 | + IMPORT SystemInit |
| 140 | + BL SystemInit |
| 141 | + |
| 142 | + ; Unmask interrupts |
| 143 | + CPSIE if |
| 144 | + |
| 145 | + ; Call __main |
| 146 | + IMPORT __main |
| 147 | + BL __main |
| 148 | + |
| 149 | + ENDP |
| 150 | + |
| 151 | + END |
0 commit comments