wdenk | dc7c9a1 | 2003-03-26 06:55:25 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * armboot - Startup Code for ARM720 CPU-core |
| 3 | * |
| 4 | * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> |
| 5 | * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "version.h" |
| 30 | |
| 31 | |
| 32 | /* |
| 33 | ************************************************************************* |
| 34 | * |
| 35 | * Jump vector table as in table 3.1 in [1] |
| 36 | * |
| 37 | ************************************************************************* |
| 38 | */ |
| 39 | |
| 40 | |
| 41 | .globl _start |
| 42 | _start: b reset |
| 43 | ldr pc, _undefined_instruction |
| 44 | ldr pc, _software_interrupt |
| 45 | ldr pc, _prefetch_abort |
| 46 | ldr pc, _data_abort |
| 47 | ldr pc, _not_used |
| 48 | ldr pc, _irq |
| 49 | ldr pc, _fiq |
| 50 | |
| 51 | _undefined_instruction: .word undefined_instruction |
| 52 | _software_interrupt: .word software_interrupt |
| 53 | _prefetch_abort: .word prefetch_abort |
| 54 | _data_abort: .word data_abort |
| 55 | _not_used: .word not_used |
| 56 | _irq: .word irq |
| 57 | _fiq: .word fiq |
| 58 | |
| 59 | .balignl 16,0xdeadbeef |
| 60 | |
| 61 | |
| 62 | /* |
| 63 | ************************************************************************* |
| 64 | * |
| 65 | * Startup Code (reset vector) |
| 66 | * |
| 67 | * do important init only if we don't start from memory! |
| 68 | * relocate armboot to ram |
| 69 | * setup stack |
| 70 | * jump to second stage |
| 71 | * |
| 72 | ************************************************************************* |
| 73 | */ |
| 74 | |
| 75 | /* |
| 76 | * CFG_MEM_END is in the board dependent config-file (configs/config_BOARD.h) |
| 77 | */ |
| 78 | _TEXT_BASE: |
| 79 | .word TEXT_BASE |
| 80 | |
| 81 | .globl _armboot_start |
| 82 | _armboot_start: |
| 83 | .word _start |
| 84 | |
| 85 | /* |
| 86 | * Note: _armboot_end_data and _armboot_end are defined |
| 87 | * by the (board-dependent) linker script. |
| 88 | * _armboot_end_data is the first usable FLASH address after armboot |
| 89 | */ |
| 90 | .globl _armboot_end_data |
| 91 | _armboot_end_data: |
| 92 | .word armboot_end_data |
| 93 | /* |
| 94 | * Note: armboot_end is defined by the (board-dependent) linker script |
| 95 | */ |
| 96 | .globl _armboot_end |
| 97 | _armboot_end: |
| 98 | .word armboot_end |
| 99 | |
| 100 | /* |
| 101 | * _armboot_real_end is the first usable RAM address behind armboot |
| 102 | * and the various stacks |
| 103 | */ |
| 104 | .globl _armboot_real_end |
| 105 | _armboot_real_end: |
| 106 | .word 0x0badc0de |
| 107 | |
| 108 | #ifdef CONFIG_USE_IRQ |
| 109 | /* IRQ stack memory (calculated at run-time) */ |
| 110 | .globl IRQ_STACK_START |
| 111 | IRQ_STACK_START: |
| 112 | .word 0x0badc0de |
| 113 | |
| 114 | /* IRQ stack memory (calculated at run-time) */ |
| 115 | .globl FIQ_STACK_START |
| 116 | FIQ_STACK_START: |
| 117 | .word 0x0badc0de |
| 118 | #endif |
| 119 | |
| 120 | |
| 121 | /* |
| 122 | * the actual reset code |
| 123 | */ |
| 124 | |
| 125 | reset: |
| 126 | /* |
| 127 | * set the cpu to SVC32 mode |
| 128 | */ |
| 129 | mrs r0,cpsr |
| 130 | bic r0,r0,#0x1f |
| 131 | orr r0,r0,#0x13 |
| 132 | msr cpsr,r0 |
| 133 | |
| 134 | /* |
| 135 | * relocate exeception table |
| 136 | */ |
| 137 | ldr r0, =_start |
| 138 | ldr r1, =0x0 |
| 139 | mov r2, #16 |
| 140 | copyex: |
| 141 | subs r2, r2, #1 |
| 142 | ldr r3, [r0], #4 |
| 143 | str r3, [r1], #4 |
| 144 | bne copyex |
| 145 | |
| 146 | /* |
| 147 | * we do sys-critical inits only at reboot, |
| 148 | * not when booting from ram! |
| 149 | */ |
| 150 | #ifdef CONFIG_INIT_CRITICAL |
| 151 | bl cpu_init_crit |
| 152 | #endif |
| 153 | |
| 154 | /* set up the stack */ |
| 155 | ldr r0, _armboot_end |
| 156 | add r0, r0, #CONFIG_STACKSIZE |
| 157 | sub sp, r0, #12 /* leave 3 words for abort-stack */ |
| 158 | ldr pc,_start_armboot |
| 159 | |
| 160 | _start_armboot: .word start_armboot |
| 161 | |
| 162 | /* |
| 163 | ************************************************************************* |
| 164 | * |
| 165 | * CPU_init_critical registers |
| 166 | * |
| 167 | ************************************************************************* |
| 168 | */ |
| 169 | |
| 170 | cpu_init_crit: |
| 171 | # actually do nothing for now! |
| 172 | mov pc, lr |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | /* |
| 178 | ************************************************************************* |
| 179 | * |
| 180 | * Interrupt handling |
| 181 | * |
| 182 | ************************************************************************* |
| 183 | */ |
| 184 | |
| 185 | @ |
| 186 | @ IRQ stack frame. |
| 187 | @ |
| 188 | #define S_FRAME_SIZE 72 |
| 189 | |
| 190 | #define S_OLD_R0 68 |
| 191 | #define S_PSR 64 |
| 192 | #define S_PC 60 |
| 193 | #define S_LR 56 |
| 194 | #define S_SP 52 |
| 195 | |
| 196 | #define S_IP 48 |
| 197 | #define S_FP 44 |
| 198 | #define S_R10 40 |
| 199 | #define S_R9 36 |
| 200 | #define S_R8 32 |
| 201 | #define S_R7 28 |
| 202 | #define S_R6 24 |
| 203 | #define S_R5 20 |
| 204 | #define S_R4 16 |
| 205 | #define S_R3 12 |
| 206 | #define S_R2 8 |
| 207 | #define S_R1 4 |
| 208 | #define S_R0 0 |
| 209 | |
| 210 | #define MODE_SVC 0x13 |
| 211 | #define I_BIT 0x80 |
| 212 | |
| 213 | /* |
| 214 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 215 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 216 | */ |
| 217 | |
| 218 | .macro bad_save_user_regs |
| 219 | sub sp, sp, #S_FRAME_SIZE |
| 220 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 221 | add r8, sp, #S_PC |
| 222 | |
| 223 | ldr r2, _armboot_end |
| 224 | add r2, r2, #CONFIG_STACKSIZE |
| 225 | sub r2, r2, #8 |
| 226 | ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0 |
| 227 | add r0, sp, #S_FRAME_SIZE @ restore sp_SVC |
| 228 | |
| 229 | add r5, sp, #S_SP |
| 230 | mov r1, lr |
| 231 | stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r |
| 232 | mov r0, sp |
| 233 | .endm |
| 234 | |
| 235 | .macro irq_save_user_regs |
| 236 | sub sp, sp, #S_FRAME_SIZE |
| 237 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 238 | add r8, sp, #S_PC |
| 239 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 240 | str lr, [r8, #0] @ Save calling PC |
| 241 | mrs r6, spsr |
| 242 | str r6, [r8, #4] @ Save CPSR |
| 243 | str r0, [r8, #8] @ Save OLD_R0 |
| 244 | mov r0, sp |
| 245 | .endm |
| 246 | |
| 247 | .macro irq_restore_user_regs |
| 248 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 249 | mov r0, r0 |
| 250 | ldr lr, [sp, #S_PC] @ Get PC |
| 251 | add sp, sp, #S_FRAME_SIZE |
| 252 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 253 | .endm |
| 254 | |
| 255 | .macro get_bad_stack |
| 256 | ldr r13, _armboot_end @ setup our mode stack |
| 257 | add r13, r13, #CONFIG_STACKSIZE @ resides at top of normal stack |
| 258 | sub r13, r13, #8 |
| 259 | |
| 260 | str lr, [r13] @ save caller lr / spsr |
| 261 | mrs lr, spsr |
| 262 | str lr, [r13, #4] |
| 263 | |
| 264 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 265 | msr spsr_c, r13 |
| 266 | mov lr, pc |
| 267 | movs pc, lr |
| 268 | .endm |
| 269 | |
| 270 | .macro get_irq_stack @ setup IRQ stack |
| 271 | ldr sp, IRQ_STACK_START |
| 272 | .endm |
| 273 | |
| 274 | .macro get_fiq_stack @ setup FIQ stack |
| 275 | ldr sp, FIQ_STACK_START |
| 276 | .endm |
| 277 | |
| 278 | /* |
| 279 | * exception handlers |
| 280 | */ |
| 281 | .align 5 |
| 282 | undefined_instruction: |
| 283 | get_bad_stack |
| 284 | bad_save_user_regs |
| 285 | bl do_undefined_instruction |
| 286 | |
| 287 | .align 5 |
| 288 | software_interrupt: |
| 289 | get_bad_stack |
| 290 | bad_save_user_regs |
| 291 | bl do_software_interrupt |
| 292 | |
| 293 | .align 5 |
| 294 | prefetch_abort: |
| 295 | get_bad_stack |
| 296 | bad_save_user_regs |
| 297 | bl do_prefetch_abort |
| 298 | |
| 299 | .align 5 |
| 300 | data_abort: |
| 301 | get_bad_stack |
| 302 | bad_save_user_regs |
| 303 | bl do_data_abort |
| 304 | |
| 305 | .align 5 |
| 306 | not_used: |
| 307 | get_bad_stack |
| 308 | bad_save_user_regs |
| 309 | bl do_not_used |
| 310 | |
| 311 | #ifdef CONFIG_USE_IRQ |
| 312 | |
| 313 | .align 5 |
| 314 | irq: |
| 315 | get_irq_stack |
| 316 | irq_save_user_regs |
| 317 | bl do_irq |
| 318 | irq_restore_user_regs |
| 319 | |
| 320 | .align 5 |
| 321 | fiq: |
| 322 | get_fiq_stack |
| 323 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 324 | irq_save_user_regs |
| 325 | bl do_fiq |
| 326 | irq_restore_user_regs |
| 327 | |
| 328 | #else |
| 329 | |
| 330 | .align 5 |
| 331 | irq: |
| 332 | get_bad_stack |
| 333 | bad_save_user_regs |
| 334 | bl do_irq |
| 335 | |
| 336 | .align 5 |
| 337 | fiq: |
| 338 | get_bad_stack |
| 339 | bad_save_user_regs |
| 340 | bl do_fiq |
| 341 | |
| 342 | #endif |
| 343 | |
| 344 | .align 5 |
| 345 | .globl reset_cpu |
| 346 | reset_cpu: |
| 347 | mov pc, r0 |