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