wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for SA1100 CPU |
| 3 | * |
| 4 | * Copyright (C) 1998 Dan Malek <dmalek@jlc.net> |
| 5 | * Copyright (C) 1999 Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se> |
| 6 | * Copyright (C) 2000 Wolfgang Denk <wd@denx.de> |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 7 | * Copyright (c) 2001 Alex Züpke <azu@sysgo.de> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 8 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 9 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 12 | #include <asm-offsets.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 13 | #include <config.h> |
| 14 | #include <version.h> |
| 15 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 16 | /* |
| 17 | ************************************************************************* |
| 18 | * |
| 19 | * Jump vector table as in table 3.1 in [1] |
| 20 | * |
| 21 | ************************************************************************* |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | .globl _start |
| 26 | _start: b reset |
| 27 | ldr pc, _undefined_instruction |
| 28 | ldr pc, _software_interrupt |
| 29 | ldr pc, _prefetch_abort |
| 30 | ldr pc, _data_abort |
| 31 | ldr pc, _not_used |
| 32 | ldr pc, _irq |
| 33 | ldr pc, _fiq |
| 34 | |
| 35 | _undefined_instruction: .word undefined_instruction |
| 36 | _software_interrupt: .word software_interrupt |
| 37 | _prefetch_abort: .word prefetch_abort |
| 38 | _data_abort: .word data_abort |
| 39 | _not_used: .word not_used |
| 40 | _irq: .word irq |
| 41 | _fiq: .word fiq |
| 42 | |
| 43 | .balignl 16,0xdeadbeef |
| 44 | |
| 45 | |
| 46 | /* |
| 47 | ************************************************************************* |
| 48 | * |
| 49 | * Startup Code (reset vector) |
| 50 | * |
| 51 | * do important init only if we don't start from memory! |
| 52 | * relocate armboot to ram |
| 53 | * setup stack |
| 54 | * jump to second stage |
| 55 | * |
| 56 | ************************************************************************* |
| 57 | */ |
| 58 | |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 59 | .globl _TEXT_BASE |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 60 | _TEXT_BASE: |
Benoît Thébaudeau | a402da3 | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 61 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE) |
| 62 | .word CONFIG_SPL_TEXT_BASE |
| 63 | #else |
Wolfgang Denk | 0708bc6 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 64 | .word CONFIG_SYS_TEXT_BASE |
Benoît Thébaudeau | a402da3 | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 65 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 66 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 67 | /* |
wdenk | 927034e | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 68 | * These are defined in the board-specific linker script. |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 69 | * Subtracting _start from them lets the linker put their |
| 70 | * relative position in the executable instead of leaving |
| 71 | * them null. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 72 | */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 73 | .globl _bss_start_ofs |
| 74 | _bss_start_ofs: |
| 75 | .word __bss_start - _start |
wdenk | 927034e | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 76 | |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 77 | .globl _bss_end_ofs |
| 78 | _bss_end_ofs: |
Simon Glass | ed70c8f | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 79 | .word __bss_end - _start |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 80 | |
Po-Yu Chuang | 1864b00 | 2011-03-01 23:02:04 +0000 | [diff] [blame] | 81 | .globl _end_ofs |
| 82 | _end_ofs: |
| 83 | .word _end - _start |
| 84 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 85 | #ifdef CONFIG_USE_IRQ |
| 86 | /* IRQ stack memory (calculated at run-time) */ |
| 87 | .globl IRQ_STACK_START |
| 88 | IRQ_STACK_START: |
| 89 | .word 0x0badc0de |
| 90 | |
| 91 | /* IRQ stack memory (calculated at run-time) */ |
| 92 | .globl FIQ_STACK_START |
| 93 | FIQ_STACK_START: |
| 94 | .word 0x0badc0de |
| 95 | #endif |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 96 | |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 97 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 98 | .globl IRQ_STACK_START_IN |
| 99 | IRQ_STACK_START_IN: |
| 100 | .word 0x0badc0de |
| 101 | |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 102 | /* |
| 103 | * the actual reset code |
| 104 | */ |
| 105 | |
| 106 | reset: |
| 107 | /* |
| 108 | * set the cpu to SVC32 mode |
| 109 | */ |
| 110 | mrs r0,cpsr |
| 111 | bic r0,r0,#0x1f |
| 112 | orr r0,r0,#0xd3 |
| 113 | msr cpsr,r0 |
| 114 | |
| 115 | /* |
| 116 | * we do sys-critical inits only at reboot, |
| 117 | * not when booting from ram! |
| 118 | */ |
| 119 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 120 | bl cpu_init_crit |
| 121 | #endif |
| 122 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 123 | bl _main |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 124 | |
| 125 | /*------------------------------------------------------------------------------*/ |
| 126 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 127 | .globl c_runtime_cpu_setup |
| 128 | c_runtime_cpu_setup: |
| 129 | |
| 130 | mov pc, lr |
| 131 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 132 | /* |
| 133 | ************************************************************************* |
| 134 | * |
| 135 | * CPU_init_critical registers |
| 136 | * |
| 137 | * setup important registers |
| 138 | * setup memory timing |
| 139 | * |
| 140 | ************************************************************************* |
| 141 | */ |
| 142 | |
| 143 | |
Mike Williams | bf895ad | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 144 | /* Interrupt-Controller base address */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 145 | IC_BASE: .word 0x90050000 |
| 146 | #define ICMR 0x04 |
| 147 | |
| 148 | |
| 149 | /* Reset-Controller */ |
| 150 | RST_BASE: .word 0x90030000 |
| 151 | #define RSRR 0x00 |
| 152 | #define RCSR 0x04 |
| 153 | |
| 154 | |
| 155 | /* PWR */ |
| 156 | PWR_BASE: .word 0x90020000 |
| 157 | #define PSPR 0x08 |
| 158 | #define PPCR 0x14 |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 159 | cpuspeed: .word CONFIG_SYS_CPUSPEED |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 160 | |
| 161 | |
| 162 | cpu_init_crit: |
| 163 | /* |
| 164 | * mask all IRQs |
| 165 | */ |
| 166 | ldr r0, IC_BASE |
| 167 | mov r1, #0x00 |
| 168 | str r1, [r0, #ICMR] |
| 169 | |
| 170 | /* set clock speed */ |
| 171 | ldr r0, PWR_BASE |
| 172 | ldr r1, cpuspeed |
| 173 | str r1, [r0, #PPCR] |
| 174 | |
| 175 | /* |
| 176 | * before relocating, we have to setup RAM timing |
| 177 | * because memory timing is board-dependend, you will |
wdenk | 336b2bc | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 178 | * find a lowlevel_init.S in your board directory. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 179 | */ |
| 180 | mov ip, lr |
wdenk | 336b2bc | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 181 | bl lowlevel_init |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 182 | mov lr, ip |
| 183 | |
| 184 | /* |
| 185 | * disable MMU stuff and enable I-cache |
| 186 | */ |
| 187 | mrc p15,0,r0,c1,c0 |
| 188 | bic r0, r0, #0x00002000 @ clear bit 13 (X) |
| 189 | bic r0, r0, #0x0000000f @ clear bits 3-0 (WCAM) |
| 190 | orr r0, r0, #0x00001000 @ set bit 12 (I) Icache |
| 191 | orr r0, r0, #0x00000002 @ set bit 2 (A) Align |
| 192 | mcr p15,0,r0,c1,c0 |
| 193 | |
| 194 | /* |
| 195 | * flush v4 I/D caches |
| 196 | */ |
| 197 | mov r0, #0 |
| 198 | mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */ |
| 199 | mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */ |
| 200 | |
| 201 | mov pc, lr |
| 202 | |
| 203 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 204 | /* |
| 205 | ************************************************************************* |
| 206 | * |
| 207 | * Interrupt handling |
| 208 | * |
| 209 | ************************************************************************* |
| 210 | */ |
| 211 | |
| 212 | @ |
| 213 | @ IRQ stack frame. |
| 214 | @ |
| 215 | #define S_FRAME_SIZE 72 |
| 216 | |
| 217 | #define S_OLD_R0 68 |
| 218 | #define S_PSR 64 |
| 219 | #define S_PC 60 |
| 220 | #define S_LR 56 |
| 221 | #define S_SP 52 |
| 222 | |
| 223 | #define S_IP 48 |
| 224 | #define S_FP 44 |
| 225 | #define S_R10 40 |
| 226 | #define S_R9 36 |
| 227 | #define S_R8 32 |
| 228 | #define S_R7 28 |
| 229 | #define S_R6 24 |
| 230 | #define S_R5 20 |
| 231 | #define S_R4 16 |
| 232 | #define S_R3 12 |
| 233 | #define S_R2 8 |
| 234 | #define S_R1 4 |
| 235 | #define S_R0 0 |
| 236 | |
| 237 | #define MODE_SVC 0x13 |
| 238 | #define I_BIT 0x80 |
| 239 | |
| 240 | /* |
| 241 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 242 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 243 | */ |
| 244 | |
| 245 | .macro bad_save_user_regs |
| 246 | sub sp, sp, #S_FRAME_SIZE |
| 247 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 248 | add r8, sp, #S_PC |
| 249 | |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 250 | ldr r2, IRQ_STACK_START_IN |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 251 | ldmia r2, {r2 - r4} @ get pc, cpsr, old_r0 |
| 252 | add r0, sp, #S_FRAME_SIZE @ restore sp_SVC |
| 253 | |
| 254 | add r5, sp, #S_SP |
| 255 | mov r1, lr |
| 256 | stmia r5, {r0 - r4} @ save sp_SVC, lr_SVC, pc, cpsr, old_r |
| 257 | mov r0, sp |
| 258 | .endm |
| 259 | |
| 260 | .macro irq_save_user_regs |
| 261 | sub sp, sp, #S_FRAME_SIZE |
| 262 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 263 | add r8, sp, #S_PC |
| 264 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 265 | str lr, [r8, #0] @ Save calling PC |
| 266 | mrs r6, spsr |
| 267 | str r6, [r8, #4] @ Save CPSR |
| 268 | str r0, [r8, #8] @ Save OLD_R0 |
| 269 | mov r0, sp |
| 270 | .endm |
| 271 | |
| 272 | .macro irq_restore_user_regs |
| 273 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 274 | mov r0, r0 |
| 275 | ldr lr, [sp, #S_PC] @ Get PC |
| 276 | add sp, sp, #S_FRAME_SIZE |
| 277 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 278 | .endm |
| 279 | |
| 280 | .macro get_bad_stack |
Heiko Schocher | 344c303 | 2010-09-17 13:10:48 +0200 | [diff] [blame] | 281 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 282 | |
| 283 | str lr, [r13] @ save caller lr / spsr |
| 284 | mrs lr, spsr |
| 285 | str lr, [r13, #4] |
| 286 | |
| 287 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 288 | msr spsr_c, r13 |
| 289 | mov lr, pc |
| 290 | movs pc, lr |
| 291 | .endm |
| 292 | |
| 293 | .macro get_irq_stack @ setup IRQ stack |
| 294 | ldr sp, IRQ_STACK_START |
| 295 | .endm |
| 296 | |
| 297 | .macro get_fiq_stack @ setup FIQ stack |
| 298 | ldr sp, FIQ_STACK_START |
| 299 | .endm |
| 300 | |
| 301 | /* |
| 302 | * exception handlers |
| 303 | */ |
| 304 | .align 5 |
| 305 | undefined_instruction: |
| 306 | get_bad_stack |
| 307 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 308 | bl do_undefined_instruction |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 309 | |
| 310 | .align 5 |
| 311 | software_interrupt: |
| 312 | get_bad_stack |
| 313 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 314 | bl do_software_interrupt |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 315 | |
| 316 | .align 5 |
| 317 | prefetch_abort: |
| 318 | get_bad_stack |
| 319 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 320 | bl do_prefetch_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 321 | |
| 322 | .align 5 |
| 323 | data_abort: |
| 324 | get_bad_stack |
| 325 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 326 | bl do_data_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 327 | |
| 328 | .align 5 |
| 329 | not_used: |
| 330 | get_bad_stack |
| 331 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 332 | bl do_not_used |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 333 | |
| 334 | #ifdef CONFIG_USE_IRQ |
| 335 | |
| 336 | .align 5 |
| 337 | irq: |
| 338 | get_irq_stack |
| 339 | irq_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 340 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 341 | irq_restore_user_regs |
| 342 | |
| 343 | .align 5 |
| 344 | fiq: |
| 345 | get_fiq_stack |
| 346 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 347 | irq_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 348 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 349 | irq_restore_user_regs |
| 350 | |
| 351 | #else |
| 352 | |
| 353 | .align 5 |
| 354 | irq: |
| 355 | get_bad_stack |
| 356 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 357 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 358 | |
| 359 | .align 5 |
| 360 | fiq: |
| 361 | get_bad_stack |
| 362 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 363 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 364 | |
| 365 | #endif |
| 366 | |
| 367 | .align 5 |
| 368 | .globl reset_cpu |
| 369 | reset_cpu: |
| 370 | ldr r0, RST_BASE |
| 371 | mov r1, #0x0 @ set bit 3-0 ... |
| 372 | str r1, [r0, #RCSR] @ ... to clear in RCSR |
| 373 | mov r1, #0x1 |
| 374 | str r1, [r0, #RSRR] @ and perform reset |
| 375 | b reset_cpu @ silly, but repeat endlessly |