Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for OMAP3530/ARM Cortex CPU-core |
| 3 | * |
| 4 | * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> |
| 5 | * |
| 6 | * Copyright (c) 2001 Marius Gröger <mag@sysgo.de> |
| 7 | * Copyright (c) 2002 Alex Züpke <azu@sysgo.de> |
Detlev Zundel | f1b3f2b | 2009-05-13 10:54:10 +0200 | [diff] [blame] | 8 | * Copyright (c) 2002 Gary Jennejohn <garyj@denx.de> |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 9 | * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> |
| 10 | * Copyright (c) 2003 Kshitij <kshitij@ti.com> |
| 11 | * Copyright (c) 2006-2008 Syed Mohammed Khasim <x0khasim@ti.com> |
| 12 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 13 | * SPDX-License-Identifier: GPL-2.0+ |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 16 | #include <asm-offsets.h> |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 17 | #include <config.h> |
| 18 | #include <version.h> |
Aneesh V | 688ee13 | 2011-11-21 23:34:00 +0000 | [diff] [blame] | 19 | #include <asm/system.h> |
Aneesh V | fd8798b | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 20 | #include <linux/linkage.h> |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 21 | |
| 22 | .globl _start |
| 23 | _start: b reset |
| 24 | ldr pc, _undefined_instruction |
| 25 | ldr pc, _software_interrupt |
| 26 | ldr pc, _prefetch_abort |
| 27 | ldr pc, _data_abort |
| 28 | ldr pc, _not_used |
| 29 | ldr pc, _irq |
| 30 | ldr pc, _fiq |
Aneesh V | ef0f76e | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 31 | #ifdef CONFIG_SPL_BUILD |
| 32 | _undefined_instruction: .word _undefined_instruction |
| 33 | _software_interrupt: .word _software_interrupt |
| 34 | _prefetch_abort: .word _prefetch_abort |
| 35 | _data_abort: .word _data_abort |
| 36 | _not_used: .word _not_used |
| 37 | _irq: .word _irq |
| 38 | _fiq: .word _fiq |
| 39 | _pad: .word 0x12345678 /* now 16*4=64 */ |
| 40 | #else |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 41 | .globl _undefined_instruction |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 42 | _undefined_instruction: .word undefined_instruction |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 43 | .globl _software_interrupt |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 44 | _software_interrupt: .word software_interrupt |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 45 | .globl _prefetch_abort |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 46 | _prefetch_abort: .word prefetch_abort |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 47 | .globl _data_abort |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 48 | _data_abort: .word data_abort |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 49 | .globl _not_used |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 50 | _not_used: .word not_used |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 51 | .globl _irq |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 52 | _irq: .word irq |
Marek Vasut | eb54c6b | 2013-12-14 05:55:26 +0100 | [diff] [blame^] | 53 | .globl _fiq |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 54 | _fiq: .word fiq |
| 55 | _pad: .word 0x12345678 /* now 16*4=64 */ |
Aneesh V | ef0f76e | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 56 | #endif /* CONFIG_SPL_BUILD */ |
| 57 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 58 | .global _end_vect |
| 59 | _end_vect: |
| 60 | |
| 61 | .balignl 16,0xdeadbeef |
| 62 | /************************************************************************* |
| 63 | * |
| 64 | * Startup Code (reset vector) |
| 65 | * |
| 66 | * do important init only if we don't start from memory! |
| 67 | * setup Memory and board specific bits prior to relocation. |
| 68 | * relocate armboot to ram |
| 69 | * setup stack |
| 70 | * |
| 71 | *************************************************************************/ |
| 72 | |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 73 | .globl _TEXT_BASE |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 74 | _TEXT_BASE: |
Benoît Thébaudeau | a402da3 | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 75 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE) |
| 76 | .word CONFIG_SPL_TEXT_BASE |
| 77 | #else |
Wolfgang Denk | 0708bc6 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 78 | .word CONFIG_SYS_TEXT_BASE |
Benoît Thébaudeau | a402da3 | 2013-04-11 09:35:42 +0000 | [diff] [blame] | 79 | #endif |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 80 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 81 | /* |
| 82 | * These are defined in the board-specific linker script. |
| 83 | */ |
Heiko Schocher | 661a29e | 2010-10-11 14:08:15 +0200 | [diff] [blame] | 84 | .globl _bss_start_ofs |
| 85 | _bss_start_ofs: |
| 86 | .word __bss_start - _start |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 87 | |
Heiko Schocher | 661a29e | 2010-10-11 14:08:15 +0200 | [diff] [blame] | 88 | .globl _bss_end_ofs |
| 89 | _bss_end_ofs: |
Simon Glass | ed70c8f | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 90 | .word __bss_end - _start |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 91 | |
Po-Yu Chuang | 1864b00 | 2011-03-01 23:02:04 +0000 | [diff] [blame] | 92 | .globl _end_ofs |
| 93 | _end_ofs: |
| 94 | .word _end - _start |
| 95 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 96 | #ifdef CONFIG_USE_IRQ |
| 97 | /* IRQ stack memory (calculated at run-time) */ |
| 98 | .globl IRQ_STACK_START |
| 99 | IRQ_STACK_START: |
| 100 | .word 0x0badc0de |
| 101 | |
| 102 | /* IRQ stack memory (calculated at run-time) */ |
| 103 | .globl FIQ_STACK_START |
| 104 | FIQ_STACK_START: |
| 105 | .word 0x0badc0de |
| 106 | #endif |
| 107 | |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 108 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 109 | .globl IRQ_STACK_START_IN |
| 110 | IRQ_STACK_START_IN: |
| 111 | .word 0x0badc0de |
| 112 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 113 | /* |
| 114 | * the actual reset code |
| 115 | */ |
| 116 | |
| 117 | reset: |
Aneesh V | 13a74c1 | 2011-07-21 09:10:27 -0400 | [diff] [blame] | 118 | bl save_boot_params |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 119 | /* |
Andre Przywara | 7acb96b | 2013-04-02 05:43:36 +0000 | [diff] [blame] | 120 | * disable interrupts (FIQ and IRQ), also set the cpu to SVC32 mode, |
| 121 | * except if in HYP mode already |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 122 | */ |
| 123 | mrs r0, cpsr |
Andre Przywara | 7acb96b | 2013-04-02 05:43:36 +0000 | [diff] [blame] | 124 | and r1, r0, #0x1f @ mask mode bits |
| 125 | teq r1, #0x1a @ test for HYP mode |
| 126 | bicne r0, r0, #0x1f @ clear all mode bits |
| 127 | orrne r0, r0, #0x13 @ set SVC mode |
| 128 | orr r0, r0, #0xc0 @ disable FIQ and IRQ |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 129 | msr cpsr,r0 |
| 130 | |
Aneesh V | 688ee13 | 2011-11-21 23:34:00 +0000 | [diff] [blame] | 131 | /* |
| 132 | * Setup vector: |
| 133 | * (OMAP4 spl TEXT_BASE is not 32 byte aligned. |
| 134 | * Continue to use ROM code vector only in OMAP4 spl) |
| 135 | */ |
| 136 | #if !(defined(CONFIG_OMAP44XX) && defined(CONFIG_SPL_BUILD)) |
| 137 | /* Set V=0 in CP15 SCTRL register - for VBAR to point to vector */ |
| 138 | mrc p15, 0, r0, c1, c0, 0 @ Read CP15 SCTRL Register |
| 139 | bic r0, #CR_V @ V = 0 |
| 140 | mcr p15, 0, r0, c1, c0, 0 @ Write CP15 SCTRL Register |
| 141 | |
| 142 | /* Set vector address in CP15 VBAR register */ |
| 143 | ldr r0, =_start |
| 144 | mcr p15, 0, r0, c12, c0, 0 @Set VBAR |
| 145 | #endif |
| 146 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 147 | /* the mask ROM code should have PLL and others stable */ |
| 148 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
Simon Glass | 277e308 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 149 | bl cpu_init_cp15 |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 150 | bl cpu_init_crit |
| 151 | #endif |
| 152 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 153 | bl _main |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 154 | |
| 155 | /*------------------------------------------------------------------------------*/ |
| 156 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 157 | ENTRY(c_runtime_cpu_setup) |
Aneesh V | 3e3bc1e | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 158 | /* |
| 159 | * If I-cache is enabled invalidate it |
| 160 | */ |
| 161 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 162 | mcr p15, 0, r0, c7, c5, 0 @ invalidate icache |
| 163 | mcr p15, 0, r0, c7, c10, 4 @ DSB |
| 164 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
| 165 | #endif |
Tetsuyuki Kobayashi | 61c70db | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 166 | /* |
| 167 | * Move vector table |
| 168 | */ |
Tetsuyuki Kobayashi | 61c70db | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 169 | /* Set vector address in CP15 VBAR register */ |
| 170 | ldr r0, =_start |
Tetsuyuki Kobayashi | 61c70db | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 171 | mcr p15, 0, r0, c12, c0, 0 @Set VBAR |
Tetsuyuki Kobayashi | 61c70db | 2012-06-25 02:40:57 +0000 | [diff] [blame] | 172 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 173 | bx lr |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 174 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 175 | ENDPROC(c_runtime_cpu_setup) |
Heiko Schocher | 661a29e | 2010-10-11 14:08:15 +0200 | [diff] [blame] | 176 | |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 177 | /************************************************************************* |
| 178 | * |
Tetsuyuki Kobayashi | 153ba38 | 2012-07-06 21:14:20 +0000 | [diff] [blame] | 179 | * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3) |
| 180 | * __attribute__((weak)); |
| 181 | * |
| 182 | * Stack pointer is not yet initialized at this moment |
| 183 | * Don't save anything to stack even if compiled with -O0 |
| 184 | * |
| 185 | *************************************************************************/ |
| 186 | ENTRY(save_boot_params) |
| 187 | bx lr @ back to my caller |
| 188 | ENDPROC(save_boot_params) |
| 189 | .weak save_boot_params |
| 190 | |
| 191 | /************************************************************************* |
| 192 | * |
Simon Glass | 277e308 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 193 | * cpu_init_cp15 |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 194 | * |
Simon Glass | 277e308 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 195 | * Setup CP15 registers (cache, MMU, TLBs). The I-cache is turned on unless |
| 196 | * CONFIG_SYS_ICACHE_OFF is defined. |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 197 | * |
| 198 | *************************************************************************/ |
Aneesh V | fd8798b | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 199 | ENTRY(cpu_init_cp15) |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 200 | /* |
| 201 | * Invalidate L1 I/D |
| 202 | */ |
| 203 | mov r0, #0 @ set up for MCR |
| 204 | mcr p15, 0, r0, c8, c7, 0 @ invalidate TLBs |
| 205 | mcr p15, 0, r0, c7, c5, 0 @ invalidate icache |
Aneesh V | 3e3bc1e | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 206 | mcr p15, 0, r0, c7, c5, 6 @ invalidate BP array |
| 207 | mcr p15, 0, r0, c7, c10, 4 @ DSB |
| 208 | mcr p15, 0, r0, c7, c5, 4 @ ISB |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 209 | |
| 210 | /* |
| 211 | * disable MMU stuff and caches |
| 212 | */ |
| 213 | mrc p15, 0, r0, c1, c0, 0 |
| 214 | bic r0, r0, #0x00002000 @ clear bits 13 (--V-) |
| 215 | bic r0, r0, #0x00000007 @ clear bits 2:0 (-CAM) |
| 216 | orr r0, r0, #0x00000002 @ set bit 1 (--A-) Align |
Aneesh V | 3e3bc1e | 2011-06-16 23:30:49 +0000 | [diff] [blame] | 217 | orr r0, r0, #0x00000800 @ set bit 11 (Z---) BTB |
| 218 | #ifdef CONFIG_SYS_ICACHE_OFF |
| 219 | bic r0, r0, #0x00001000 @ clear bit 12 (I) I-cache |
| 220 | #else |
| 221 | orr r0, r0, #0x00001000 @ set bit 12 (I) I-cache |
| 222 | #endif |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 223 | mcr p15, 0, r0, c1, c0, 0 |
Stephen Warren | e9d59c9 | 2013-02-26 12:28:27 +0000 | [diff] [blame] | 224 | |
Stephen Warren | c63c350 | 2013-03-04 13:29:40 +0000 | [diff] [blame] | 225 | #ifdef CONFIG_ARM_ERRATA_716044 |
| 226 | mrc p15, 0, r0, c1, c0, 0 @ read system control register |
| 227 | orr r0, r0, #1 << 11 @ set bit #11 |
| 228 | mcr p15, 0, r0, c1, c0, 0 @ write system control register |
| 229 | #endif |
| 230 | |
Stephen Warren | e9d59c9 | 2013-02-26 12:28:27 +0000 | [diff] [blame] | 231 | #ifdef CONFIG_ARM_ERRATA_742230 |
| 232 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 233 | orr r0, r0, #1 << 4 @ set bit #4 |
| 234 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 235 | #endif |
| 236 | |
| 237 | #ifdef CONFIG_ARM_ERRATA_743622 |
| 238 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 239 | orr r0, r0, #1 << 6 @ set bit #6 |
| 240 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 241 | #endif |
| 242 | |
| 243 | #ifdef CONFIG_ARM_ERRATA_751472 |
| 244 | mrc p15, 0, r0, c15, c0, 1 @ read diagnostic register |
| 245 | orr r0, r0, #1 << 11 @ set bit #11 |
| 246 | mcr p15, 0, r0, c15, c0, 1 @ write diagnostic register |
| 247 | #endif |
| 248 | |
Simon Glass | 277e308 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 249 | mov pc, lr @ back to my caller |
Aneesh V | fd8798b | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 250 | ENDPROC(cpu_init_cp15) |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 251 | |
Simon Glass | 277e308 | 2011-11-05 03:56:51 +0000 | [diff] [blame] | 252 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
| 253 | /************************************************************************* |
| 254 | * |
| 255 | * CPU_init_critical registers |
| 256 | * |
| 257 | * setup important registers |
| 258 | * setup memory timing |
| 259 | * |
| 260 | *************************************************************************/ |
Aneesh V | fd8798b | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 261 | ENTRY(cpu_init_crit) |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 262 | /* |
| 263 | * Jump to board specific initialization... |
| 264 | * The Mask ROM will have already initialized |
| 265 | * basic memory. Go here to bump up clock rate and handle |
| 266 | * wake up conditions. |
| 267 | */ |
Benoît Thébaudeau | 0a16790 | 2012-08-10 12:05:16 +0000 | [diff] [blame] | 268 | b lowlevel_init @ go setup pll,mux,memory |
Aneesh V | fd8798b | 2012-03-08 07:20:18 +0000 | [diff] [blame] | 269 | ENDPROC(cpu_init_crit) |
Rob Herring | a693287 | 2011-06-28 05:39:38 +0000 | [diff] [blame] | 270 | #endif |
Aneesh V | ef0f76e | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 271 | |
| 272 | #ifndef CONFIG_SPL_BUILD |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 273 | /* |
| 274 | ************************************************************************* |
| 275 | * |
| 276 | * Interrupt handling |
| 277 | * |
| 278 | ************************************************************************* |
| 279 | */ |
| 280 | @ |
| 281 | @ IRQ stack frame. |
| 282 | @ |
| 283 | #define S_FRAME_SIZE 72 |
| 284 | |
| 285 | #define S_OLD_R0 68 |
| 286 | #define S_PSR 64 |
| 287 | #define S_PC 60 |
| 288 | #define S_LR 56 |
| 289 | #define S_SP 52 |
| 290 | |
| 291 | #define S_IP 48 |
| 292 | #define S_FP 44 |
| 293 | #define S_R10 40 |
| 294 | #define S_R9 36 |
| 295 | #define S_R8 32 |
| 296 | #define S_R7 28 |
| 297 | #define S_R6 24 |
| 298 | #define S_R5 20 |
| 299 | #define S_R4 16 |
| 300 | #define S_R3 12 |
| 301 | #define S_R2 8 |
| 302 | #define S_R1 4 |
| 303 | #define S_R0 0 |
| 304 | |
| 305 | #define MODE_SVC 0x13 |
| 306 | #define I_BIT 0x80 |
| 307 | |
| 308 | /* |
| 309 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 310 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 311 | */ |
| 312 | |
| 313 | .macro bad_save_user_regs |
| 314 | sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current |
| 315 | @ user stack |
| 316 | stmia sp, {r0 - r12} @ Save user registers (now in |
| 317 | @ svc mode) r0-r12 |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 318 | ldr r2, IRQ_STACK_START_IN @ set base 2 words into abort |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 319 | @ stack |
| 320 | ldmia r2, {r2 - r3} @ get values for "aborted" pc |
| 321 | @ and cpsr (into parm regs) |
| 322 | add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack |
| 323 | |
| 324 | add r5, sp, #S_SP |
| 325 | mov r1, lr |
| 326 | stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr |
| 327 | mov r0, sp @ save current stack into r0 |
| 328 | @ (param register) |
| 329 | .endm |
| 330 | |
| 331 | .macro irq_save_user_regs |
| 332 | sub sp, sp, #S_FRAME_SIZE |
| 333 | stmia sp, {r0 - r12} @ Calling r0-r12 |
| 334 | add r8, sp, #S_PC @ !! R8 NEEDS to be saved !! |
| 335 | @ a reserved stack spot would |
| 336 | @ be good. |
| 337 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 338 | str lr, [r8, #0] @ Save calling PC |
| 339 | mrs r6, spsr |
| 340 | str r6, [r8, #4] @ Save CPSR |
| 341 | str r0, [r8, #8] @ Save OLD_R0 |
| 342 | mov r0, sp |
| 343 | .endm |
| 344 | |
| 345 | .macro irq_restore_user_regs |
| 346 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 347 | mov r0, r0 |
| 348 | ldr lr, [sp, #S_PC] @ Get PC |
| 349 | add sp, sp, #S_FRAME_SIZE |
| 350 | subs pc, lr, #4 @ return & move spsr_svc into |
| 351 | @ cpsr |
| 352 | .endm |
| 353 | |
| 354 | .macro get_bad_stack |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 355 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack (enter |
| 356 | @ in banked mode) |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 357 | |
| 358 | str lr, [r13] @ save caller lr in position 0 |
| 359 | @ of saved stack |
| 360 | mrs lr, spsr @ get the spsr |
| 361 | str lr, [r13, #4] @ save spsr in position 1 of |
| 362 | @ saved stack |
| 363 | |
| 364 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 365 | @ msr spsr_c, r13 |
| 366 | msr spsr, r13 @ switch modes, make sure |
| 367 | @ moves will execute |
| 368 | mov lr, pc @ capture return pc |
| 369 | movs pc, lr @ jump to next instruction & |
| 370 | @ switch modes. |
| 371 | .endm |
| 372 | |
| 373 | .macro get_bad_stack_swi |
| 374 | sub r13, r13, #4 @ space on current stack for |
| 375 | @ scratch reg. |
| 376 | str r0, [r13] @ save R0's value. |
Heiko Schocher | 56d0a4d | 2010-09-17 13:10:41 +0200 | [diff] [blame] | 377 | ldr r0, IRQ_STACK_START_IN @ get data regions start |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 378 | @ spots for abort stack |
| 379 | str lr, [r0] @ save caller lr in position 0 |
| 380 | @ of saved stack |
Tetsuyuki Kobayashi | b023a95 | 2013-04-05 00:12:51 +0000 | [diff] [blame] | 381 | mrs lr, spsr @ get the spsr |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 382 | str lr, [r0, #4] @ save spsr in position 1 of |
| 383 | @ saved stack |
Tetsuyuki Kobayashi | b023a95 | 2013-04-05 00:12:51 +0000 | [diff] [blame] | 384 | ldr lr, [r0] @ restore lr |
Dirk Behme | 7d75a10 | 2008-12-14 09:47:13 +0100 | [diff] [blame] | 385 | ldr r0, [r13] @ restore r0 |
| 386 | add r13, r13, #4 @ pop stack entry |
| 387 | .endm |
| 388 | |
| 389 | .macro get_irq_stack @ setup IRQ stack |
| 390 | ldr sp, IRQ_STACK_START |
| 391 | .endm |
| 392 | |
| 393 | .macro get_fiq_stack @ setup FIQ stack |
| 394 | ldr sp, FIQ_STACK_START |
| 395 | .endm |
| 396 | |
| 397 | /* |
| 398 | * exception handlers |
| 399 | */ |
| 400 | .align 5 |
| 401 | undefined_instruction: |
| 402 | get_bad_stack |
| 403 | bad_save_user_regs |
| 404 | bl do_undefined_instruction |
| 405 | |
| 406 | .align 5 |
| 407 | software_interrupt: |
| 408 | get_bad_stack_swi |
| 409 | bad_save_user_regs |
| 410 | bl do_software_interrupt |
| 411 | |
| 412 | .align 5 |
| 413 | prefetch_abort: |
| 414 | get_bad_stack |
| 415 | bad_save_user_regs |
| 416 | bl do_prefetch_abort |
| 417 | |
| 418 | .align 5 |
| 419 | data_abort: |
| 420 | get_bad_stack |
| 421 | bad_save_user_regs |
| 422 | bl do_data_abort |
| 423 | |
| 424 | .align 5 |
| 425 | not_used: |
| 426 | get_bad_stack |
| 427 | bad_save_user_regs |
| 428 | bl do_not_used |
| 429 | |
| 430 | #ifdef CONFIG_USE_IRQ |
| 431 | |
| 432 | .align 5 |
| 433 | irq: |
| 434 | get_irq_stack |
| 435 | irq_save_user_regs |
| 436 | bl do_irq |
| 437 | irq_restore_user_regs |
| 438 | |
| 439 | .align 5 |
| 440 | fiq: |
| 441 | get_fiq_stack |
| 442 | /* someone ought to write a more effective fiq_save_user_regs */ |
| 443 | irq_save_user_regs |
| 444 | bl do_fiq |
| 445 | irq_restore_user_regs |
| 446 | |
| 447 | #else |
| 448 | |
| 449 | .align 5 |
| 450 | irq: |
| 451 | get_bad_stack |
| 452 | bad_save_user_regs |
| 453 | bl do_irq |
| 454 | |
| 455 | .align 5 |
| 456 | fiq: |
| 457 | get_bad_stack |
| 458 | bad_save_user_regs |
| 459 | bl do_fiq |
| 460 | |
Aneesh V | ef0f76e | 2011-07-21 09:10:18 -0400 | [diff] [blame] | 461 | #endif /* CONFIG_USE_IRQ */ |
| 462 | #endif /* CONFIG_SPL_BUILD */ |