wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for ARM920 CPU-core |
| 3 | * |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 4 | * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> |
| 5 | * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> |
Detlev Zundel | 792a09e | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 6 | * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 7 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Wolfgang Denk | 25ddd1f | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 11 | #include <asm-offsets.h> |
Wolfgang Denk | 9689ddc | 2009-07-27 10:06:39 +0200 | [diff] [blame] | 12 | #include <common.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 13 | #include <config.h> |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 14 | |
| 15 | /* |
| 16 | ************************************************************************* |
| 17 | * |
| 18 | * Jump vector table as in table 3.1 in [1] |
| 19 | * |
| 20 | ************************************************************************* |
| 21 | */ |
| 22 | |
| 23 | |
| 24 | .globl _start |
kevin.morfitt@fearnside-systems.co.uk | d67cce2 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 25 | _start: b start_code |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 26 | ldr pc, _undefined_instruction |
| 27 | ldr pc, _software_interrupt |
| 28 | ldr pc, _prefetch_abort |
| 29 | ldr pc, _data_abort |
| 30 | ldr pc, _not_used |
| 31 | ldr pc, _irq |
| 32 | ldr pc, _fiq |
| 33 | |
| 34 | _undefined_instruction: .word undefined_instruction |
| 35 | _software_interrupt: .word software_interrupt |
| 36 | _prefetch_abort: .word prefetch_abort |
| 37 | _data_abort: .word data_abort |
| 38 | _not_used: .word not_used |
| 39 | _irq: .word irq |
| 40 | _fiq: .word fiq |
| 41 | |
| 42 | .balignl 16,0xdeadbeef |
| 43 | |
| 44 | |
| 45 | /* |
| 46 | ************************************************************************* |
| 47 | * |
Peter Pearse | 80767a6 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 48 | * Startup Code (called from the ARM reset exception vector) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 49 | * |
| 50 | * do important init only if we don't start from memory! |
| 51 | * relocate armboot to ram |
| 52 | * setup stack |
| 53 | * jump to second stage |
| 54 | * |
| 55 | ************************************************************************* |
| 56 | */ |
| 57 | |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 58 | .globl _TEXT_BASE |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 59 | _TEXT_BASE: |
Benoît Thébaudeau | 508611b | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 60 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE) |
| 61 | .word CONFIG_SPL_TEXT_BASE |
| 62 | #else |
Wolfgang Denk | 14d0a02 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 63 | .word CONFIG_SYS_TEXT_BASE |
Benoît Thébaudeau | 508611b | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 64 | #endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 65 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 66 | /* |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 67 | * These are defined in the board-specific linker script. |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 68 | * Subtracting _start from them lets the linker put their |
| 69 | * relative position in the executable instead of leaving |
| 70 | * them null. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 71 | */ |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 72 | .globl _bss_start_ofs |
| 73 | _bss_start_ofs: |
| 74 | .word __bss_start - _start |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 75 | |
Albert Aribaud | 3336ca6 | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 76 | .globl _bss_end_ofs |
| 77 | _bss_end_ofs: |
Simon Glass | 3929fb0 | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 78 | .word __bss_end - _start |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 79 | |
Po-Yu Chuang | f326cbb | 2011-03-01 23:02:04 +0000 | [diff] [blame] | 80 | .globl _end_ofs |
| 81 | _end_ofs: |
| 82 | .word _end - _start |
| 83 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 84 | #ifdef CONFIG_USE_IRQ |
| 85 | /* IRQ stack memory (calculated at run-time) */ |
| 86 | .globl IRQ_STACK_START |
| 87 | IRQ_STACK_START: |
| 88 | .word 0x0badc0de |
| 89 | |
| 90 | /* IRQ stack memory (calculated at run-time) */ |
| 91 | .globl FIQ_STACK_START |
| 92 | FIQ_STACK_START: |
| 93 | .word 0x0badc0de |
| 94 | #endif |
| 95 | |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 96 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 97 | .globl IRQ_STACK_START_IN |
| 98 | IRQ_STACK_START_IN: |
| 99 | .word 0x0badc0de |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 100 | |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 101 | /* |
| 102 | * the actual start code |
| 103 | */ |
| 104 | |
| 105 | start_code: |
| 106 | /* |
| 107 | * set the cpu to SVC32 mode |
| 108 | */ |
| 109 | mrs r0, cpsr |
| 110 | bic r0, r0, #0x1f |
| 111 | orr r0, r0, #0xd3 |
| 112 | msr cpsr, r0 |
| 113 | |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 114 | #if defined(CONFIG_AT91RM9200DK) || defined(CONFIG_AT91RM9200EK) |
| 115 | /* |
| 116 | * relocate exception table |
| 117 | */ |
| 118 | ldr r0, =_start |
| 119 | ldr r1, =0x0 |
| 120 | mov r2, #16 |
| 121 | copyex: |
| 122 | subs r2, r2, #1 |
| 123 | ldr r3, [r0], #4 |
| 124 | str r3, [r1], #4 |
| 125 | bne copyex |
| 126 | #endif |
| 127 | |
| 128 | #ifdef CONFIG_S3C24X0 |
| 129 | /* turn off the watchdog */ |
| 130 | |
| 131 | # if defined(CONFIG_S3C2400) |
| 132 | # define pWTCON 0x15300000 |
Mike Williams | 1626308 | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 133 | # define INTMSK 0x14400008 /* Interrupt-Controller base addresses */ |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 134 | # define CLKDIVN 0x14800014 /* clock divisor register */ |
| 135 | #else |
| 136 | # define pWTCON 0x53000000 |
Mike Williams | 1626308 | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 137 | # define INTMSK 0x4A000008 /* Interrupt-Controller base addresses */ |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 138 | # define INTSUBMSK 0x4A00001C |
| 139 | # define CLKDIVN 0x4C000014 /* clock divisor register */ |
| 140 | # endif |
| 141 | |
| 142 | ldr r0, =pWTCON |
| 143 | mov r1, #0x0 |
| 144 | str r1, [r0] |
| 145 | |
| 146 | /* |
| 147 | * mask all IRQs by setting all bits in the INTMR - default |
| 148 | */ |
| 149 | mov r1, #0xffffffff |
| 150 | ldr r0, =INTMSK |
| 151 | str r1, [r0] |
| 152 | # if defined(CONFIG_S3C2410) |
| 153 | ldr r1, =0x3ff |
| 154 | ldr r0, =INTSUBMSK |
| 155 | str r1, [r0] |
| 156 | # endif |
| 157 | |
| 158 | /* FCLK:HCLK:PCLK = 1:2:4 */ |
| 159 | /* default FCLK is 120 MHz ! */ |
| 160 | ldr r0, =CLKDIVN |
| 161 | mov r1, #3 |
| 162 | str r1, [r0] |
| 163 | #endif /* CONFIG_S3C24X0 */ |
| 164 | |
| 165 | /* |
| 166 | * we do sys-critical inits only at reboot, |
| 167 | * not when booting from ram! |
| 168 | */ |
| 169 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 170 | bl cpu_init_crit |
| 171 | #endif |
| 172 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 173 | bl _main |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 174 | |
| 175 | /*------------------------------------------------------------------------------*/ |
| 176 | |
Albert ARIBAUD | e05e5de | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 177 | .globl c_runtime_cpu_setup |
| 178 | c_runtime_cpu_setup: |
| 179 | |
| 180 | mov pc, lr |
| 181 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 182 | /* |
| 183 | ************************************************************************* |
| 184 | * |
| 185 | * CPU_init_critical registers |
| 186 | * |
| 187 | * setup important registers |
| 188 | * setup memory timing |
| 189 | * |
| 190 | ************************************************************************* |
| 191 | */ |
| 192 | |
| 193 | |
Wolfgang Denk | db28ddb | 2006-04-03 15:46:10 +0200 | [diff] [blame] | 194 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 195 | cpu_init_crit: |
| 196 | /* |
| 197 | * flush v4 I/D caches |
| 198 | */ |
| 199 | mov r0, #0 |
| 200 | mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */ |
| 201 | mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */ |
| 202 | |
| 203 | /* |
| 204 | * disable MMU stuff and caches |
| 205 | */ |
| 206 | mrc p15, 0, r0, c1, c0, 0 |
| 207 | bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) |
| 208 | bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) |
| 209 | orr r0, r0, #0x00000002 @ set bit 2 (A) Align |
| 210 | orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache |
| 211 | mcr p15, 0, r0, c1, c0, 0 |
| 212 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 213 | /* |
| 214 | * before relocating, we have to setup RAM timing |
| 215 | * because memory timing is board-dependend, you will |
wdenk | 400558b | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 216 | * find a lowlevel_init.S in your board directory. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 217 | */ |
| 218 | mov ip, lr |
Peter Pearse | d4fc601 | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 219 | |
wdenk | 400558b | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 220 | bl lowlevel_init |
Ulf Samuelsson | cb82a53 | 2009-03-27 23:26:43 +0100 | [diff] [blame] | 221 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 222 | mov lr, ip |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 223 | mov pc, lr |
Wolfgang Denk | db28ddb | 2006-04-03 15:46:10 +0200 | [diff] [blame] | 224 | #endif /* CONFIG_SKIP_LOWLEVEL_INIT */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 225 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 226 | /* |
| 227 | ************************************************************************* |
| 228 | * |
| 229 | * Interrupt handling |
| 230 | * |
| 231 | ************************************************************************* |
| 232 | */ |
| 233 | |
| 234 | @ |
| 235 | @ IRQ stack frame. |
| 236 | @ |
| 237 | #define S_FRAME_SIZE 72 |
| 238 | |
| 239 | #define S_OLD_R0 68 |
| 240 | #define S_PSR 64 |
| 241 | #define S_PC 60 |
| 242 | #define S_LR 56 |
| 243 | #define S_SP 52 |
| 244 | |
| 245 | #define S_IP 48 |
| 246 | #define S_FP 44 |
| 247 | #define S_R10 40 |
| 248 | #define S_R9 36 |
| 249 | #define S_R8 32 |
| 250 | #define S_R7 28 |
| 251 | #define S_R6 24 |
| 252 | #define S_R5 20 |
| 253 | #define S_R4 16 |
| 254 | #define S_R3 12 |
| 255 | #define S_R2 8 |
| 256 | #define S_R1 4 |
| 257 | #define S_R0 0 |
| 258 | |
kevin.morfitt@fearnside-systems.co.uk | d67cce2 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 259 | #define MODE_SVC 0x13 |
| 260 | #define I_BIT 0x80 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 264 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 265 | */ |
| 266 | |
| 267 | .macro bad_save_user_regs |
| 268 | sub sp, sp, #S_FRAME_SIZE |
| 269 | stmia sp, {r0 - r12} @ Calling r0-r12 |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 270 | ldr r2, IRQ_STACK_START_IN |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 271 | ldmia r2, {r2 - r3} @ get pc, cpsr |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 272 | add r0, sp, #S_FRAME_SIZE @ restore sp_SVC |
| 273 | |
| 274 | add r5, sp, #S_SP |
| 275 | mov r1, lr |
wdenk | f07771c | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 276 | stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 277 | mov r0, sp |
| 278 | .endm |
| 279 | |
| 280 | .macro irq_save_user_regs |
| 281 | sub sp, sp, #S_FRAME_SIZE |
| 282 | stmia sp, {r0 - r12} @ Calling r0-r12 |
kevin.morfitt@fearnside-systems.co.uk | d67cce2 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 283 | add r7, sp, #S_PC |
| 284 | stmdb r7, {sp, lr}^ @ Calling SP, LR |
| 285 | str lr, [r7, #0] @ Save calling PC |
| 286 | mrs r6, spsr |
| 287 | str r6, [r7, #4] @ Save CPSR |
| 288 | str r0, [r7, #8] @ Save OLD_R0 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 289 | mov r0, sp |
| 290 | .endm |
| 291 | |
| 292 | .macro irq_restore_user_regs |
| 293 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 294 | mov r0, r0 |
| 295 | ldr lr, [sp, #S_PC] @ Get PC |
| 296 | add sp, sp, #S_FRAME_SIZE |
kevin.morfitt@fearnside-systems.co.uk | d67cce2 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 297 | /* return & move spsr_svc into cpsr */ |
| 298 | subs pc, lr, #4 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 299 | .endm |
| 300 | |
| 301 | .macro get_bad_stack |
Heiko Schocher | cc7cdcb | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 302 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 303 | |
| 304 | str lr, [r13] @ save caller lr / spsr |
| 305 | mrs lr, spsr |
kevin.morfitt@fearnside-systems.co.uk | d67cce2 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 306 | str lr, [r13, #4] |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 307 | |
| 308 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 309 | @ msr spsr_c, r13 |
| 310 | msr spsr, r13 |
| 311 | mov lr, pc |
| 312 | movs pc, lr |
| 313 | .endm |
| 314 | |
| 315 | .macro get_irq_stack @ setup IRQ stack |
| 316 | ldr sp, IRQ_STACK_START |
| 317 | .endm |
| 318 | |
| 319 | .macro get_fiq_stack @ setup FIQ stack |
| 320 | ldr sp, FIQ_STACK_START |
| 321 | .endm |
| 322 | |
| 323 | /* |
| 324 | * exception handlers |
| 325 | */ |
| 326 | .align 5 |
| 327 | undefined_instruction: |
| 328 | get_bad_stack |
| 329 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 330 | bl do_undefined_instruction |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 331 | |
| 332 | .align 5 |
| 333 | software_interrupt: |
| 334 | get_bad_stack |
| 335 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 336 | bl do_software_interrupt |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 337 | |
| 338 | .align 5 |
| 339 | prefetch_abort: |
| 340 | get_bad_stack |
| 341 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 342 | bl do_prefetch_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 343 | |
| 344 | .align 5 |
| 345 | data_abort: |
| 346 | get_bad_stack |
| 347 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 348 | bl do_data_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 349 | |
| 350 | .align 5 |
| 351 | not_used: |
| 352 | get_bad_stack |
| 353 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 354 | bl do_not_used |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 355 | |
| 356 | #ifdef CONFIG_USE_IRQ |
| 357 | |
| 358 | .align 5 |
| 359 | irq: |
| 360 | get_irq_stack |
| 361 | irq_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 362 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 363 | irq_restore_user_regs |
| 364 | |
| 365 | .align 5 |
| 366 | fiq: |
| 367 | get_fiq_stack |
| 368 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 369 | irq_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 370 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 371 | irq_restore_user_regs |
| 372 | |
| 373 | #else |
| 374 | |
| 375 | .align 5 |
| 376 | irq: |
| 377 | get_bad_stack |
| 378 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 379 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 380 | |
| 381 | .align 5 |
| 382 | fiq: |
| 383 | get_bad_stack |
| 384 | bad_save_user_regs |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 385 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 386 | |
| 387 | #endif |