wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for ARM920 CPU-core |
| 3 | * |
Albert ARIBAUD | 60fbc8d | 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 | f1b3f2b | 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 | d79de1d | 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 | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 11 | #include <asm-offsets.h> |
Wolfgang Denk | 140f044 | 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 | d1cacc7 | 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 | 782cf16 | 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 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 58 | #ifdef CONFIG_USE_IRQ |
| 59 | /* IRQ stack memory (calculated at run-time) */ |
| 60 | .globl IRQ_STACK_START |
| 61 | IRQ_STACK_START: |
| 62 | .word 0x0badc0de |
| 63 | |
| 64 | /* IRQ stack memory (calculated at run-time) */ |
| 65 | .globl FIQ_STACK_START |
| 66 | FIQ_STACK_START: |
| 67 | .word 0x0badc0de |
| 68 | #endif |
| 69 | |
Heiko Schocher | 271a240 | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 70 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 71 | .globl IRQ_STACK_START_IN |
| 72 | IRQ_STACK_START_IN: |
| 73 | .word 0x0badc0de |
| 74 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 75 | /* |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 76 | * the actual start code |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 77 | */ |
| 78 | |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 79 | start_code: |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 80 | /* |
| 81 | * set the cpu to SVC32 mode |
| 82 | */ |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 83 | mrs r0, cpsr |
| 84 | bic r0, r0, #0x1f |
| 85 | orr r0, r0, #0xd3 |
| 86 | msr cpsr, r0 |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 87 | |
Jean-Christophe PLAGNIOL-VILLARD | 06f3496 | 2008-11-30 19:36:50 +0100 | [diff] [blame] | 88 | #if defined(CONFIG_AT91RM9200DK) || defined(CONFIG_AT91RM9200EK) |
Peter Pearse | de5b02c | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 89 | /* |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 90 | * relocate exception table |
Peter Pearse | de5b02c | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 91 | */ |
| 92 | ldr r0, =_start |
| 93 | ldr r1, =0x0 |
| 94 | mov r2, #16 |
| 95 | copyex: |
| 96 | subs r2, r2, #1 |
| 97 | ldr r3, [r0], #4 |
| 98 | str r3, [r1], #4 |
| 99 | bne copyex |
| 100 | #endif |
| 101 | |
kevin.morfitt@fearnside-systems.co.uk | e0d8131 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 102 | #ifdef CONFIG_S3C24X0 |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 103 | /* turn off the watchdog */ |
| 104 | |
| 105 | # if defined(CONFIG_S3C2400) |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 106 | # define pWTCON 0x15300000 |
Mike Williams | bf895ad | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 107 | # define INTMSK 0x14400008 /* Interrupt-Controller base addresses */ |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 108 | # define CLKDIVN 0x14800014 /* clock divisor register */ |
| 109 | #else |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 110 | # define pWTCON 0x53000000 |
Mike Williams | bf895ad | 2011-07-22 04:01:30 +0000 | [diff] [blame] | 111 | # define INTMSK 0x4A000008 /* Interrupt-Controller base addresses */ |
Peter Pearse | 782cf16 | 2007-09-05 16:04:41 +0100 | [diff] [blame] | 112 | # define INTSUBMSK 0x4A00001C |
| 113 | # define CLKDIVN 0x4C000014 /* clock divisor register */ |
| 114 | # endif |
| 115 | |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 116 | ldr r0, =pWTCON |
| 117 | mov r1, #0x0 |
| 118 | str r1, [r0] |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 119 | |
| 120 | /* |
| 121 | * mask all IRQs by setting all bits in the INTMR - default |
| 122 | */ |
| 123 | mov r1, #0xffffffff |
| 124 | ldr r0, =INTMSK |
| 125 | str r1, [r0] |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 126 | # if defined(CONFIG_S3C2410) |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 127 | ldr r1, =0x3ff |
| 128 | ldr r0, =INTSUBMSK |
| 129 | str r1, [r0] |
wdenk | 7ac1610 | 2004-08-01 22:48:16 +0000 | [diff] [blame] | 130 | # endif |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 131 | |
| 132 | /* FCLK:HCLK:PCLK = 1:2:4 */ |
| 133 | /* default FCLK is 120 MHz ! */ |
| 134 | ldr r0, =CLKDIVN |
| 135 | mov r1, #3 |
| 136 | str r1, [r0] |
kevin.morfitt@fearnside-systems.co.uk | e0d8131 | 2009-11-17 18:30:34 +0900 | [diff] [blame] | 137 | #endif /* CONFIG_S3C24X0 */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * we do sys-critical inits only at reboot, |
| 141 | * not when booting from ram! |
| 142 | */ |
wdenk | 3d3d99f | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 143 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 144 | bl cpu_init_crit |
| 145 | #endif |
| 146 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 147 | bl _main |
Heiko Schocher | 271a240 | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 148 | |
| 149 | /*------------------------------------------------------------------------------*/ |
| 150 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 151 | .globl c_runtime_cpu_setup |
| 152 | c_runtime_cpu_setup: |
| 153 | |
| 154 | mov pc, lr |
| 155 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 156 | /* |
| 157 | ************************************************************************* |
| 158 | * |
| 159 | * CPU_init_critical registers |
| 160 | * |
| 161 | * setup important registers |
| 162 | * setup memory timing |
| 163 | * |
| 164 | ************************************************************************* |
| 165 | */ |
| 166 | |
| 167 | |
Wolfgang Denk | f2e11a7 | 2006-04-03 15:46:10 +0200 | [diff] [blame] | 168 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 169 | cpu_init_crit: |
| 170 | /* |
| 171 | * flush v4 I/D caches |
| 172 | */ |
| 173 | mov r0, #0 |
| 174 | mcr p15, 0, r0, c7, c7, 0 /* flush v3/v4 cache */ |
| 175 | mcr p15, 0, r0, c8, c7, 0 /* flush v4 TLB */ |
| 176 | |
| 177 | /* |
| 178 | * disable MMU stuff and caches |
| 179 | */ |
| 180 | mrc p15, 0, r0, c1, c0, 0 |
| 181 | bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) |
| 182 | bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) |
| 183 | orr r0, r0, #0x00000002 @ set bit 2 (A) Align |
| 184 | orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache |
| 185 | mcr p15, 0, r0, c1, c0, 0 |
| 186 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 187 | /* |
| 188 | * before relocating, we have to setup RAM timing |
| 189 | * because memory timing is board-dependend, you will |
wdenk | 336b2bc | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 190 | * find a lowlevel_init.S in your board directory. |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 191 | */ |
| 192 | mov ip, lr |
Peter Pearse | de5b02c | 2007-08-14 10:10:52 +0100 | [diff] [blame] | 193 | |
wdenk | 336b2bc | 2005-04-02 23:52:25 +0000 | [diff] [blame] | 194 | bl lowlevel_init |
Ulf Samuelsson | 07f9b4e | 2009-03-27 23:26:43 +0100 | [diff] [blame] | 195 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 196 | mov lr, ip |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 197 | mov pc, lr |
Wolfgang Denk | f2e11a7 | 2006-04-03 15:46:10 +0200 | [diff] [blame] | 198 | #endif /* CONFIG_SKIP_LOWLEVEL_INIT */ |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 199 | |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 200 | /* |
| 201 | ************************************************************************* |
| 202 | * |
| 203 | * Interrupt handling |
| 204 | * |
| 205 | ************************************************************************* |
| 206 | */ |
| 207 | |
| 208 | @ |
| 209 | @ IRQ stack frame. |
| 210 | @ |
| 211 | #define S_FRAME_SIZE 72 |
| 212 | |
| 213 | #define S_OLD_R0 68 |
| 214 | #define S_PSR 64 |
| 215 | #define S_PC 60 |
| 216 | #define S_LR 56 |
| 217 | #define S_SP 52 |
| 218 | |
| 219 | #define S_IP 48 |
| 220 | #define S_FP 44 |
| 221 | #define S_R10 40 |
| 222 | #define S_R9 36 |
| 223 | #define S_R8 32 |
| 224 | #define S_R7 28 |
| 225 | #define S_R6 24 |
| 226 | #define S_R5 20 |
| 227 | #define S_R4 16 |
| 228 | #define S_R3 12 |
| 229 | #define S_R2 8 |
| 230 | #define S_R1 4 |
| 231 | #define S_R0 0 |
| 232 | |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 233 | #define MODE_SVC 0x13 |
| 234 | #define I_BIT 0x80 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 235 | |
| 236 | /* |
| 237 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 238 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 239 | */ |
| 240 | |
| 241 | .macro bad_save_user_regs |
| 242 | sub sp, sp, #S_FRAME_SIZE |
| 243 | stmia sp, {r0 - r12} @ Calling r0-r12 |
Heiko Schocher | 271a240 | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 244 | ldr r2, IRQ_STACK_START_IN |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 245 | ldmia r2, {r2 - r3} @ get pc, cpsr |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 246 | add r0, sp, #S_FRAME_SIZE @ restore sp_SVC |
| 247 | |
| 248 | add r5, sp, #S_SP |
| 249 | mov r1, lr |
wdenk | f4688a2 | 2003-05-28 08:06:31 +0000 | [diff] [blame] | 250 | stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 251 | mov r0, sp |
| 252 | .endm |
| 253 | |
| 254 | .macro irq_save_user_regs |
| 255 | sub sp, sp, #S_FRAME_SIZE |
| 256 | stmia sp, {r0 - r12} @ Calling r0-r12 |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 257 | add r7, sp, #S_PC |
| 258 | stmdb r7, {sp, lr}^ @ Calling SP, LR |
| 259 | str lr, [r7, #0] @ Save calling PC |
| 260 | mrs r6, spsr |
| 261 | str r6, [r7, #4] @ Save CPSR |
| 262 | str r0, [r7, #8] @ Save OLD_R0 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 263 | mov r0, sp |
| 264 | .endm |
| 265 | |
| 266 | .macro irq_restore_user_regs |
| 267 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 268 | mov r0, r0 |
| 269 | ldr lr, [sp, #S_PC] @ Get PC |
| 270 | add sp, sp, #S_FRAME_SIZE |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 271 | /* return & move spsr_svc into cpsr */ |
| 272 | subs pc, lr, #4 |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 273 | .endm |
| 274 | |
| 275 | .macro get_bad_stack |
Heiko Schocher | 271a240 | 2010-09-17 13:10:43 +0200 | [diff] [blame] | 276 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 277 | |
| 278 | str lr, [r13] @ save caller lr / spsr |
| 279 | mrs lr, spsr |
kevin.morfitt@fearnside-systems.co.uk | d1cacc7 | 2009-10-10 13:30:22 +0900 | [diff] [blame] | 280 | str lr, [r13, #4] |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 281 | |
| 282 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 283 | @ msr spsr_c, r13 |
| 284 | msr spsr, r13 |
| 285 | mov lr, pc |
| 286 | movs pc, lr |
| 287 | .endm |
| 288 | |
| 289 | .macro get_irq_stack @ setup IRQ stack |
| 290 | ldr sp, IRQ_STACK_START |
| 291 | .endm |
| 292 | |
| 293 | .macro get_fiq_stack @ setup FIQ stack |
| 294 | ldr sp, FIQ_STACK_START |
| 295 | .endm |
| 296 | |
| 297 | /* |
| 298 | * exception handlers |
| 299 | */ |
| 300 | .align 5 |
| 301 | undefined_instruction: |
| 302 | get_bad_stack |
| 303 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 304 | bl do_undefined_instruction |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 305 | |
| 306 | .align 5 |
| 307 | software_interrupt: |
| 308 | get_bad_stack |
| 309 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 310 | bl do_software_interrupt |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 311 | |
| 312 | .align 5 |
| 313 | prefetch_abort: |
| 314 | get_bad_stack |
| 315 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 316 | bl do_prefetch_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 317 | |
| 318 | .align 5 |
| 319 | data_abort: |
| 320 | get_bad_stack |
| 321 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 322 | bl do_data_abort |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 323 | |
| 324 | .align 5 |
| 325 | not_used: |
| 326 | get_bad_stack |
| 327 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 328 | bl do_not_used |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 329 | |
| 330 | #ifdef CONFIG_USE_IRQ |
| 331 | |
| 332 | .align 5 |
| 333 | irq: |
| 334 | get_irq_stack |
| 335 | irq_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 336 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 337 | irq_restore_user_regs |
| 338 | |
| 339 | .align 5 |
| 340 | fiq: |
| 341 | get_fiq_stack |
| 342 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 343 | irq_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 344 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 345 | irq_restore_user_regs |
| 346 | |
| 347 | #else |
| 348 | |
| 349 | .align 5 |
| 350 | irq: |
| 351 | get_bad_stack |
| 352 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 353 | bl do_irq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 354 | |
| 355 | .align 5 |
| 356 | fiq: |
| 357 | get_bad_stack |
| 358 | bad_save_user_regs |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 359 | bl do_fiq |
wdenk | fe8c280 | 2002-11-03 00:38:21 +0000 | [diff] [blame] | 360 | |
| 361 | #endif |