wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * armboot - Startup Code for OMP2420/ARM1136 CPU-core |
| 3 | * |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004 Texas Instruments <r-woodruff2@ti.com> |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 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> |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 9 | * Copyright (c) 2003 Richard Woodruff <r-woodruff2@ti.com> |
| 10 | * Copyright (c) 2003 Kshitij <kshitij@ti.com> |
| 11 | * |
| 12 | * See file CREDITS for list of people who contributed to this |
| 13 | * project. |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License as |
| 17 | * published by the Free Software Foundation; either version 2 of |
| 18 | * the License, or (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 28 | * MA 02111-1307 USA |
| 29 | */ |
| 30 | |
| 31 | #include <config.h> |
| 32 | #include <version.h> |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 33 | .globl _start |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 34 | _start: b reset |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 35 | #ifdef CONFIG_PRELOADER |
Kyungmin Park | 751b9b5 | 2008-01-17 16:43:25 +0900 | [diff] [blame] | 36 | ldr pc, _hang |
| 37 | ldr pc, _hang |
| 38 | ldr pc, _hang |
| 39 | ldr pc, _hang |
| 40 | ldr pc, _hang |
| 41 | ldr pc, _hang |
| 42 | ldr pc, _hang |
| 43 | |
| 44 | _hang: |
| 45 | .word do_hang |
| 46 | .word 0x12345678 |
| 47 | .word 0x12345678 |
| 48 | .word 0x12345678 |
| 49 | .word 0x12345678 |
| 50 | .word 0x12345678 |
| 51 | .word 0x12345678 |
| 52 | .word 0x12345678 /* now 16*4=64 */ |
| 53 | #else |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 54 | ldr pc, _undefined_instruction |
| 55 | ldr pc, _software_interrupt |
| 56 | ldr pc, _prefetch_abort |
| 57 | ldr pc, _data_abort |
| 58 | ldr pc, _not_used |
| 59 | ldr pc, _irq |
| 60 | ldr pc, _fiq |
| 61 | |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 62 | _undefined_instruction: .word undefined_instruction |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 63 | _software_interrupt: .word software_interrupt |
| 64 | _prefetch_abort: .word prefetch_abort |
| 65 | _data_abort: .word data_abort |
| 66 | _not_used: .word not_used |
| 67 | _irq: .word irq |
| 68 | _fiq: .word fiq |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 69 | _pad: .word 0x12345678 /* now 16*4=64 */ |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 70 | #endif /* CONFIG_PRELOADER */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 71 | .global _end_vect |
| 72 | _end_vect: |
| 73 | |
| 74 | .balignl 16,0xdeadbeef |
| 75 | /* |
| 76 | ************************************************************************* |
| 77 | * |
| 78 | * Startup Code (reset vector) |
| 79 | * |
| 80 | * do important init only if we don't start from memory! |
| 81 | * setup Memory and board specific bits prior to relocation. |
| 82 | * relocate armboot to ram |
| 83 | * setup stack |
| 84 | * |
| 85 | ************************************************************************* |
| 86 | */ |
| 87 | |
| 88 | _TEXT_BASE: |
| 89 | .word TEXT_BASE |
| 90 | |
| 91 | .globl _armboot_start |
| 92 | _armboot_start: |
| 93 | .word _start |
| 94 | |
| 95 | /* |
| 96 | * These are defined in the board-specific linker script. |
| 97 | */ |
| 98 | .globl _bss_start |
| 99 | _bss_start: |
| 100 | .word __bss_start |
| 101 | |
| 102 | .globl _bss_end |
| 103 | _bss_end: |
| 104 | .word _end |
| 105 | |
| 106 | #ifdef CONFIG_USE_IRQ |
| 107 | /* IRQ stack memory (calculated at run-time) */ |
| 108 | .globl IRQ_STACK_START |
| 109 | IRQ_STACK_START: |
| 110 | .word 0x0badc0de |
| 111 | |
| 112 | /* IRQ stack memory (calculated at run-time) */ |
| 113 | .globl FIQ_STACK_START |
| 114 | FIQ_STACK_START: |
| 115 | .word 0x0badc0de |
| 116 | #endif |
| 117 | |
| 118 | /* |
| 119 | * the actual reset code |
| 120 | */ |
| 121 | |
| 122 | reset: |
| 123 | /* |
| 124 | * set the cpu to SVC32 mode |
| 125 | */ |
| 126 | mrs r0,cpsr |
| 127 | bic r0,r0,#0x1f |
| 128 | orr r0,r0,#0xd3 |
| 129 | msr cpsr,r0 |
| 130 | |
| 131 | #ifdef CONFIG_OMAP2420H4 |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 132 | /* Copy vectors to mask ROM indirect addr */ |
| 133 | adr r0, _start /* r0 <- current position of code */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 134 | add r0, r0, #4 /* skip reset vector */ |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 135 | mov r2, #64 /* r2 <- size to copy */ |
| 136 | add r2, r0, r2 /* r2 <- source end address */ |
| 137 | mov r1, #SRAM_OFFSET0 /* build vect addr */ |
| 138 | mov r3, #SRAM_OFFSET1 |
| 139 | add r1, r1, r3 |
| 140 | mov r3, #SRAM_OFFSET2 |
| 141 | add r1, r1, r3 |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 142 | next: |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 143 | ldmia r0!, {r3-r10} /* copy from source address [r0] */ |
| 144 | stmia r1!, {r3-r10} /* copy to target address [r1] */ |
| 145 | cmp r0, r2 /* until source end address [r2] */ |
| 146 | bne next /* loop until equal */ |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 147 | bl cpy_clk_code /* put dpll adjust code behind vectors */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 148 | #endif |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 149 | /* the mask ROM code should have PLL and others stable */ |
wdenk | 8aa1a2d | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 150 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 151 | bl cpu_init_crit |
wdenk | 8aa1a2d | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 152 | #endif |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 153 | |
wdenk | 8aa1a2d | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 154 | #ifndef CONFIG_SKIP_RELOCATE_UBOOT |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 155 | relocate: /* relocate U-Boot to RAM */ |
| 156 | adr r0, _start /* r0 <- current position of code */ |
| 157 | ldr r1, _TEXT_BASE /* test if we run from flash or RAM */ |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 158 | cmp r0, r1 /* don't reloc during debug */ |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 159 | #ifndef CONFIG_PRELOADER |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 160 | beq stack_setup |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 161 | #endif /* CONFIG_PRELOADER */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 162 | |
| 163 | ldr r2, _armboot_start |
| 164 | ldr r3, _bss_start |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 165 | sub r2, r3, r2 /* r2 <- size of armboot */ |
| 166 | add r2, r0, r2 /* r2 <- source end address */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 167 | |
| 168 | copy_loop: |
| 169 | ldmia r0!, {r3-r10} /* copy from source address [r0] */ |
| 170 | stmia r1!, {r3-r10} /* copy to target address [r1] */ |
| 171 | cmp r0, r2 /* until source end addreee [r2] */ |
| 172 | ble copy_loop |
wdenk | 8aa1a2d | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 173 | #endif /* CONFIG_SKIP_RELOCATE_UBOOT */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 174 | |
| 175 | /* Set up the stack */ |
| 176 | stack_setup: |
| 177 | ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */ |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 178 | #ifdef CONFIG_PRELOADER |
Kyungmin Park | 751b9b5 | 2008-01-17 16:43:25 +0900 | [diff] [blame] | 179 | sub sp, r0, #128 /* leave 32 words for abort-stack */ |
| 180 | #else |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 181 | sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */ |
| 182 | sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 183 | #ifdef CONFIG_USE_IRQ |
| 184 | sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ) |
| 185 | #endif |
| 186 | sub sp, r0, #12 /* leave 3 words for abort-stack */ |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 187 | #endif /* CONFIG_PRELOADER */ |
Vitaly Kuzmichev | 1a27f7d | 2010-06-15 22:18:11 +0400 | [diff] [blame] | 188 | bic sp, sp, #7 /* 8-byte alignment for ABI compliance */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 189 | |
| 190 | clear_bss: |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 191 | ldr r0, _bss_start /* find start of bss segment */ |
| 192 | ldr r1, _bss_end /* stop here */ |
| 193 | mov r2, #0x00000000 /* clear */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 194 | |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 195 | #ifndef CONFIG_PRELOADER |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 196 | clbss_l:str r2, [r0] /* clear loop... */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 197 | add r0, r0, #4 |
| 198 | cmp r0, r1 |
| 199 | bne clbss_l |
Kyungmin Park | 751b9b5 | 2008-01-17 16:43:25 +0900 | [diff] [blame] | 200 | #endif |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 201 | |
| 202 | ldr pc, _start_armboot |
| 203 | |
Magnus Lilja | 40c642b | 2009-06-13 20:50:01 +0200 | [diff] [blame] | 204 | #ifdef CONFIG_NAND_SPL |
| 205 | _start_armboot: .word nand_boot |
| 206 | #else |
Kyungmin Park | 751b9b5 | 2008-01-17 16:43:25 +0900 | [diff] [blame] | 207 | #ifdef CONFIG_ONENAND_IPL |
| 208 | _start_armboot: .word start_oneboot |
| 209 | #else |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 210 | _start_armboot: .word start_armboot |
Magnus Lilja | 40c642b | 2009-06-13 20:50:01 +0200 | [diff] [blame] | 211 | #endif /* CONFIG_ONENAND_IPL */ |
| 212 | #endif /* CONFIG_NAND_SPL */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | ************************************************************************* |
| 216 | * |
| 217 | * CPU_init_critical registers |
| 218 | * |
| 219 | * setup important registers |
| 220 | * setup memory timing |
| 221 | * |
| 222 | ************************************************************************* |
| 223 | */ |
Magnus Lilja | 40c642b | 2009-06-13 20:50:01 +0200 | [diff] [blame] | 224 | #ifndef CONFIG_SKIP_LOWLEVEL_INIT |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 225 | cpu_init_crit: |
| 226 | /* |
| 227 | * flush v4 I/D caches |
| 228 | */ |
| 229 | mov r0, #0 |
George G. Davis | 409a07c | 2010-05-11 10:15:36 -0400 | [diff] [blame] | 230 | mcr p15, 0, r0, c7, c7, 0 /* Invalidate I+D+BTB caches */ |
| 231 | mcr p15, 0, r0, c8, c7, 0 /* Invalidate Unified TLB */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * disable MMU stuff and caches |
| 235 | */ |
| 236 | mrc p15, 0, r0, c1, c0, 0 |
| 237 | bic r0, r0, #0x00002300 @ clear bits 13, 9:8 (--V- --RS) |
| 238 | bic r0, r0, #0x00000087 @ clear bits 7, 2:0 (B--- -CAM) |
| 239 | orr r0, r0, #0x00000002 @ set bit 2 (A) Align |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 240 | orr r0, r0, #0x00001000 @ set bit 12 (I) I-Cache |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 241 | mcr p15, 0, r0, c1, c0, 0 |
| 242 | |
| 243 | /* |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 244 | * Jump to board specific initialization... The Mask ROM will have already initialized |
| 245 | * basic memory. Go here to bump up clock rate and handle wake up conditions. |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 246 | */ |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 247 | mov ip, lr /* persevere link reg across call */ |
Wolfgang Denk | 87cb686 | 2005-10-06 17:08:18 +0200 | [diff] [blame] | 248 | bl lowlevel_init /* go setup pll,mux,memory */ |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 249 | mov lr, ip /* restore link */ |
| 250 | mov pc, lr /* back to my caller */ |
Magnus Lilja | 40c642b | 2009-06-13 20:50:01 +0200 | [diff] [blame] | 251 | #endif /* CONFIG_SKIP_LOWLEVEL_INIT */ |
Kyungmin Park | 751b9b5 | 2008-01-17 16:43:25 +0900 | [diff] [blame] | 252 | |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 253 | #ifndef CONFIG_PRELOADER |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 254 | /* |
| 255 | ************************************************************************* |
| 256 | * |
| 257 | * Interrupt handling |
| 258 | * |
| 259 | ************************************************************************* |
| 260 | */ |
| 261 | @ |
| 262 | @ IRQ stack frame. |
| 263 | @ |
| 264 | #define S_FRAME_SIZE 72 |
| 265 | |
| 266 | #define S_OLD_R0 68 |
| 267 | #define S_PSR 64 |
| 268 | #define S_PC 60 |
| 269 | #define S_LR 56 |
| 270 | #define S_SP 52 |
| 271 | |
| 272 | #define S_IP 48 |
| 273 | #define S_FP 44 |
| 274 | #define S_R10 40 |
| 275 | #define S_R9 36 |
| 276 | #define S_R8 32 |
| 277 | #define S_R7 28 |
| 278 | #define S_R6 24 |
| 279 | #define S_R5 20 |
| 280 | #define S_R4 16 |
| 281 | #define S_R3 12 |
| 282 | #define S_R2 8 |
| 283 | #define S_R1 4 |
| 284 | #define S_R0 0 |
| 285 | |
| 286 | #define MODE_SVC 0x13 |
| 287 | #define I_BIT 0x80 |
| 288 | |
| 289 | /* |
| 290 | * use bad_save_user_regs for abort/prefetch/undef/swi ... |
| 291 | * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling |
| 292 | */ |
| 293 | |
| 294 | .macro bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 295 | sub sp, sp, #S_FRAME_SIZE @ carve out a frame on current user stack |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 296 | stmia sp, {r0 - r12} @ Save user registers (now in svc mode) r0-r12 |
| 297 | |
| 298 | ldr r2, _armboot_start |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 299 | sub r2, r2, #(CONFIG_SYS_MALLOC_LEN) |
| 300 | sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ set base 2 words into abort stack |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 301 | ldmia r2, {r2 - r3} @ get values for "aborted" pc and cpsr (into parm regs) |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 302 | add r0, sp, #S_FRAME_SIZE @ grab pointer to old stack |
| 303 | |
| 304 | add r5, sp, #S_SP |
| 305 | mov r1, lr |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 306 | stmia r5, {r0 - r3} @ save sp_SVC, lr_SVC, pc, cpsr |
| 307 | mov r0, sp @ save current stack into r0 (param register) |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 308 | .endm |
| 309 | |
| 310 | .macro irq_save_user_regs |
| 311 | sub sp, sp, #S_FRAME_SIZE |
| 312 | stmia sp, {r0 - r12} @ Calling r0-r12 |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 313 | add r8, sp, #S_PC @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good. |
| 314 | stmdb r8, {sp, lr}^ @ Calling SP, LR |
| 315 | str lr, [r8, #0] @ Save calling PC |
| 316 | mrs r6, spsr |
| 317 | str r6, [r8, #4] @ Save CPSR |
| 318 | str r0, [r8, #8] @ Save OLD_R0 |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 319 | mov r0, sp |
| 320 | .endm |
| 321 | |
| 322 | .macro irq_restore_user_regs |
| 323 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 324 | mov r0, r0 |
| 325 | ldr lr, [sp, #S_PC] @ Get PC |
| 326 | add sp, sp, #S_FRAME_SIZE |
| 327 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 328 | .endm |
| 329 | |
| 330 | .macro get_bad_stack |
| 331 | ldr r13, _armboot_start @ setup our mode stack (enter in banked mode) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 332 | sub r13, r13, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool |
| 333 | sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 334 | |
| 335 | str lr, [r13] @ save caller lr in position 0 of saved stack |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 336 | mrs lr, spsr @ get the spsr |
| 337 | str lr, [r13, #4] @ save spsr in position 1 of saved stack |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 338 | |
| 339 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 340 | @ msr spsr_c, r13 |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 341 | msr spsr, r13 @ switch modes, make sure moves will execute |
| 342 | mov lr, pc @ capture return pc |
| 343 | movs pc, lr @ jump to next instruction & switch modes. |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 344 | .endm |
| 345 | |
| 346 | .macro get_bad_stack_swi |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 347 | sub r13, r13, #4 @ space on current stack for scratch reg. |
| 348 | str r0, [r13] @ save R0's value. |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 349 | ldr r0, _armboot_start @ get data regions start |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 350 | sub r0, r0, #(CONFIG_SYS_MALLOC_LEN) @ move past malloc pool |
| 351 | sub r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ move past gbl and a couple spots for abort stack |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 352 | str lr, [r0] @ save caller lr in position 0 of saved stack |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 353 | mrs r0, spsr @ get the spsr |
| 354 | str lr, [r0, #4] @ save spsr in position 1 of saved stack |
| 355 | ldr r0, [r13] @ restore r0 |
| 356 | add r13, r13, #4 @ pop stack entry |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 357 | .endm |
| 358 | |
| 359 | .macro get_irq_stack @ setup IRQ stack |
| 360 | ldr sp, IRQ_STACK_START |
| 361 | .endm |
| 362 | |
| 363 | .macro get_fiq_stack @ setup FIQ stack |
| 364 | ldr sp, FIQ_STACK_START |
| 365 | .endm |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 366 | #endif /* CONFIG_PRELOADER */ |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 367 | |
| 368 | /* |
| 369 | * exception handlers |
| 370 | */ |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 371 | #ifdef CONFIG_PRELOADER |
Kyungmin Park | 751b9b5 | 2008-01-17 16:43:25 +0900 | [diff] [blame] | 372 | .align 5 |
| 373 | do_hang: |
| 374 | ldr sp, _TEXT_BASE /* use 32 words about stack */ |
| 375 | bl hang /* hang and never return */ |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 376 | #else /* !CONFIG_PRELOADER */ |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 377 | .align 5 |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 378 | undefined_instruction: |
| 379 | get_bad_stack |
| 380 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 381 | bl do_undefined_instruction |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 382 | |
| 383 | .align 5 |
| 384 | software_interrupt: |
| 385 | get_bad_stack_swi |
| 386 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 387 | bl do_software_interrupt |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 388 | |
| 389 | .align 5 |
| 390 | prefetch_abort: |
| 391 | get_bad_stack |
| 392 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 393 | bl do_prefetch_abort |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 394 | |
| 395 | .align 5 |
| 396 | data_abort: |
| 397 | get_bad_stack |
| 398 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 399 | bl do_data_abort |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 400 | |
| 401 | .align 5 |
| 402 | not_used: |
| 403 | get_bad_stack |
| 404 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 405 | bl do_not_used |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 406 | |
| 407 | #ifdef CONFIG_USE_IRQ |
| 408 | |
| 409 | .align 5 |
| 410 | irq: |
| 411 | get_irq_stack |
| 412 | irq_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 413 | bl do_irq |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 414 | irq_restore_user_regs |
| 415 | |
| 416 | .align 5 |
| 417 | fiq: |
| 418 | get_fiq_stack |
| 419 | /* someone ought to write a more effiction fiq_save_user_regs */ |
| 420 | irq_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 421 | bl do_fiq |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 422 | irq_restore_user_regs |
| 423 | |
| 424 | #else |
| 425 | |
| 426 | .align 5 |
| 427 | irq: |
| 428 | get_bad_stack |
| 429 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 430 | bl do_irq |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 431 | |
| 432 | .align 5 |
| 433 | fiq: |
| 434 | get_bad_stack |
| 435 | bad_save_user_regs |
wdenk | 082acfd | 2005-01-10 00:01:04 +0000 | [diff] [blame] | 436 | bl do_fiq |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 437 | |
| 438 | #endif |
| 439 | .align 5 |
| 440 | .global arm1136_cache_flush |
| 441 | arm1136_cache_flush: |
Heiko Schocher | 7e4a9e6 | 2010-09-17 13:10:32 +0200 | [diff] [blame^] | 442 | #if !defined(CONFIG_SYS_NO_ICACHE) |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 443 | mcr p15, 0, r1, c7, c5, 0 @ invalidate I cache |
Heiko Schocher | 7e4a9e6 | 2010-09-17 13:10:32 +0200 | [diff] [blame^] | 444 | #endif |
| 445 | #if !defined(CONFIG_SYS_NO_DCACHE) |
| 446 | mcr p15, 0, r1, c7, c14, 0 @ invalidate D cache |
| 447 | #endif |
wdenk | 8ed9604 | 2005-01-09 23:16:25 +0000 | [diff] [blame] | 448 | mov pc, lr @ back to caller |
Magnus Lilja | df81238 | 2009-06-13 20:50:00 +0200 | [diff] [blame] | 449 | #endif /* CONFIG_PRELOADER */ |