wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 1 | /* vi: set ts=8 sw=8 noet: */ |
| 2 | /* |
| 3 | * u-boot - Startup Code for XScale IXP |
| 4 | * |
| 5 | * Copyright (C) 2003 Kyle Harris <kharris@nexus-tech.net> |
| 6 | * |
| 7 | * Based on startup code example contained in the |
| 8 | * Intel IXP4xx Programmer's Guide and past u-boot Start.S |
| 9 | * samples. |
| 10 | * |
| 11 | * See file CREDITS for list of people who contributed to this |
| 12 | * project. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | |
Wolfgang Denk | 0191e47 | 2010-10-26 14:34:52 +0200 | [diff] [blame] | 30 | #include <asm-offsets.h> |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 31 | #include <config.h> |
| 32 | #include <version.h> |
| 33 | #include <asm/arch/ixp425.h> |
| 34 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 35 | #define MMU_Control_M 0x001 /* Enable MMU */ |
| 36 | #define MMU_Control_A 0x002 /* Enable address alignment faults */ |
| 37 | #define MMU_Control_C 0x004 /* Enable cache */ |
| 38 | #define MMU_Control_W 0x008 /* Enable write-buffer */ |
| 39 | #define MMU_Control_P 0x010 /* Compatability: 32 bit code */ |
| 40 | #define MMU_Control_D 0x020 /* Compatability: 32 bit data */ |
| 41 | #define MMU_Control_L 0x040 /* Compatability: */ |
| 42 | #define MMU_Control_B 0x080 /* Enable Big-Endian */ |
| 43 | #define MMU_Control_S 0x100 /* Enable system protection */ |
| 44 | #define MMU_Control_R 0x200 /* Enable ROM protection */ |
| 45 | #define MMU_Control_I 0x1000 /* Enable Instruction cache */ |
| 46 | #define MMU_Control_X 0x2000 /* Set interrupt vectors at 0xFFFF0000 */ |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 47 | #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L) |
| 48 | |
| 49 | |
| 50 | /* |
| 51 | * Macro definitions |
| 52 | */ |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 53 | /* Delay a bit */ |
| 54 | .macro DELAY_FOR cycles, reg0 |
| 55 | ldr \reg0, =\cycles |
| 56 | subs \reg0, \reg0, #1 |
| 57 | subne pc, pc, #0xc |
| 58 | .endm |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 59 | |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 60 | /* wait for coprocessor write complete */ |
| 61 | .macro CPWAIT reg |
| 62 | mrc p15,0,\reg,c2,c0,0 |
| 63 | mov \reg,\reg |
| 64 | sub pc,pc,#4 |
| 65 | .endm |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 66 | |
| 67 | .globl _start |
Michael Schwingen | 7ddf55e | 2011-05-23 00:00:00 +0200 | [diff] [blame] | 68 | _start: |
| 69 | ldr pc, _reset |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 70 | ldr pc, _undefined_instruction |
| 71 | ldr pc, _software_interrupt |
| 72 | ldr pc, _prefetch_abort |
| 73 | ldr pc, _data_abort |
| 74 | ldr pc, _not_used |
| 75 | ldr pc, _irq |
| 76 | ldr pc, _fiq |
| 77 | |
Michael Schwingen | 7ddf55e | 2011-05-23 00:00:00 +0200 | [diff] [blame] | 78 | _reset: .word reset |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 79 | _undefined_instruction: .word undefined_instruction |
| 80 | _software_interrupt: .word software_interrupt |
| 81 | _prefetch_abort: .word prefetch_abort |
| 82 | _data_abort: .word data_abort |
| 83 | _not_used: .word not_used |
| 84 | _irq: .word irq |
| 85 | _fiq: .word fiq |
| 86 | |
| 87 | .balignl 16,0xdeadbeef |
| 88 | |
| 89 | |
| 90 | /* |
| 91 | * Startup Code (reset vector) |
| 92 | * |
| 93 | * do important init only if we don't start from memory! |
| 94 | * - relocate armboot to ram |
| 95 | * - setup stack |
| 96 | * - jump to second stage |
| 97 | */ |
| 98 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 99 | .globl _TEXT_BASE |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 100 | _TEXT_BASE: |
Benoît Thébaudeau | a402da3 | 2013-04-11 09:35:42 +0000 | [diff] [blame^] | 101 | #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE) |
| 102 | .word CONFIG_SPL_TEXT_BASE |
| 103 | #else |
Wolfgang Denk | 0708bc6 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 104 | .word CONFIG_SYS_TEXT_BASE |
Benoît Thébaudeau | a402da3 | 2013-04-11 09:35:42 +0000 | [diff] [blame^] | 105 | #endif |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 106 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 107 | /* |
wdenk | 927034e | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 108 | * These are defined in the board-specific linker script. |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 109 | * Subtracting _start from them lets the linker put their |
| 110 | * relative position in the executable instead of leaving |
| 111 | * them null. |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 112 | */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 113 | .globl _bss_start_ofs |
| 114 | _bss_start_ofs: |
| 115 | .word __bss_start - _start |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 116 | |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 117 | .globl _bss_end_ofs |
| 118 | _bss_end_ofs: |
Simon Glass | ed70c8f | 2013-03-14 06:54:53 +0000 | [diff] [blame] | 119 | .word __bss_end - _start |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 120 | |
Po-Yu Chuang | 1864b00 | 2011-03-01 23:02:04 +0000 | [diff] [blame] | 121 | .globl _end_ofs |
| 122 | _end_ofs: |
| 123 | .word _end - _start |
| 124 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 125 | #ifdef CONFIG_USE_IRQ |
| 126 | /* IRQ stack memory (calculated at run-time) */ |
| 127 | .globl IRQ_STACK_START |
| 128 | IRQ_STACK_START: |
| 129 | .word 0x0badc0de |
| 130 | |
| 131 | /* IRQ stack memory (calculated at run-time) */ |
| 132 | .globl FIQ_STACK_START |
| 133 | FIQ_STACK_START: |
| 134 | .word 0x0badc0de |
| 135 | #endif |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 136 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 137 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 138 | .globl IRQ_STACK_START_IN |
| 139 | IRQ_STACK_START_IN: |
| 140 | .word 0x0badc0de |
| 141 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 142 | /* |
| 143 | * the actual reset code |
| 144 | */ |
| 145 | |
| 146 | reset: |
| 147 | /* disable mmu, set big-endian */ |
| 148 | mov r0, #0xf8 |
| 149 | mcr p15, 0, r0, c1, c0, 0 |
| 150 | CPWAIT r0 |
| 151 | |
| 152 | /* invalidate I & D caches & BTB */ |
| 153 | mcr p15, 0, r0, c7, c7, 0 |
| 154 | CPWAIT r0 |
| 155 | |
| 156 | /* invalidate I & Data TLB */ |
| 157 | mcr p15, 0, r0, c8, c7, 0 |
| 158 | CPWAIT r0 |
| 159 | |
| 160 | /* drain write and fill buffers */ |
| 161 | mcr p15, 0, r0, c7, c10, 4 |
| 162 | CPWAIT r0 |
| 163 | |
| 164 | /* disable write buffer coalescing */ |
| 165 | mrc p15, 0, r0, c1, c0, 1 |
| 166 | orr r0, r0, #1 |
| 167 | mcr p15, 0, r0, c1, c0, 1 |
| 168 | CPWAIT r0 |
| 169 | |
| 170 | /* set EXP CS0 to the optimum timing */ |
| 171 | ldr r1, =CONFIG_SYS_EXP_CS0 |
| 172 | ldr r2, =IXP425_EXP_CS0 |
| 173 | str r1, [r2] |
| 174 | |
| 175 | /* make sure flash is visible at 0 */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 176 | mov r1, #CONFIG_SYS_SDR_CONFIG |
| 177 | ldr r2, =IXP425_SDR_CONFIG |
| 178 | str r1, [r2] |
| 179 | |
| 180 | /* disable refresh cycles */ |
| 181 | mov r1, #0 |
| 182 | ldr r3, =IXP425_SDR_REFRESH |
| 183 | str r1, [r3] |
| 184 | |
| 185 | /* send nop command */ |
| 186 | mov r1, #3 |
| 187 | ldr r4, =IXP425_SDR_IR |
| 188 | str r1, [r4] |
| 189 | DELAY_FOR 0x4000, r0 |
| 190 | |
| 191 | /* set SDRAM internal refresh val */ |
| 192 | ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT |
| 193 | str r1, [r3] |
| 194 | DELAY_FOR 0x4000, r0 |
| 195 | |
| 196 | /* send precharge-all command to close all open banks */ |
| 197 | mov r1, #2 |
| 198 | str r1, [r4] |
| 199 | DELAY_FOR 0x4000, r0 |
| 200 | |
| 201 | /* provide 8 auto-refresh cycles */ |
| 202 | mov r1, #4 |
| 203 | mov r5, #8 |
| 204 | 111: str r1, [r4] |
| 205 | DELAY_FOR 0x100, r0 |
| 206 | subs r5, r5, #1 |
| 207 | bne 111b |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 208 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 209 | /* set mode register in sdram */ |
| 210 | mov r1, #CONFIG_SYS_SDR_MODE_CONFIG |
| 211 | str r1, [r4] |
| 212 | DELAY_FOR 0x4000, r0 |
| 213 | |
| 214 | /* send normal operation command */ |
| 215 | mov r1, #6 |
| 216 | str r1, [r4] |
| 217 | DELAY_FOR 0x4000, r0 |
| 218 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 219 | /* invalidate I & D caches & BTB */ |
| 220 | mcr p15, 0, r0, c7, c7, 0 |
| 221 | CPWAIT r0 |
| 222 | |
| 223 | /* invalidate I & Data TLB */ |
| 224 | mcr p15, 0, r0, c8, c7, 0 |
| 225 | CPWAIT r0 |
| 226 | |
| 227 | /* drain write and fill buffers */ |
| 228 | mcr p15, 0, r0, c7, c10, 4 |
| 229 | CPWAIT r0 |
| 230 | |
Michael Schwingen | 7ddf55e | 2011-05-23 00:00:00 +0200 | [diff] [blame] | 231 | /* remove flash mirror at 0x00000000 */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 232 | ldr r2, =IXP425_EXP_CFG0 |
| 233 | ldr r1, [r2] |
| 234 | bic r1, r1, #0x80000000 |
| 235 | str r1, [r2] |
| 236 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 237 | /* invalidate I & Data TLB */ |
| 238 | mcr p15, 0, r0, c8, c7, 0 |
| 239 | CPWAIT r0 |
| 240 | |
| 241 | /* enable I cache */ |
| 242 | mrc p15, 0, r0, c1, c0, 0 |
| 243 | orr r0, r0, #MMU_Control_I |
| 244 | mcr p15, 0, r0, c1, c0, 0 |
| 245 | CPWAIT r0 |
| 246 | |
| 247 | mrs r0,cpsr /* set the cpu to SVC32 mode */ |
| 248 | bic r0,r0,#0x1f /* (superviser mode, M=10011) */ |
| 249 | orr r0,r0,#0x13 |
| 250 | msr cpsr,r0 |
| 251 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 252 | bl _main |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 253 | |
| 254 | /*------------------------------------------------------------------------------*/ |
| 255 | |
| 256 | /* |
| 257 | * void relocate_code (addr_sp, gd, addr_moni) |
| 258 | * |
| 259 | * This "function" does not return, instead it continues in RAM |
| 260 | * after relocating the monitor code. |
| 261 | * |
| 262 | */ |
| 263 | .globl relocate_code |
| 264 | relocate_code: |
| 265 | mov r4, r0 /* save addr_sp */ |
| 266 | mov r5, r1 /* save addr of gd */ |
| 267 | mov r6, r2 /* save addr of destination */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 268 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 269 | adr r0, _start |
Andreas Bießmann | 007b38f | 2010-12-01 00:58:34 +0100 | [diff] [blame] | 270 | cmp r0, r6 |
Zhong Hongbo | 8c2ef80 | 2012-09-01 20:49:52 +0000 | [diff] [blame] | 271 | moveq r9, #0 /* no relocation. relocation offset(r9) = 0 */ |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 272 | beq relocate_done /* skip relocation */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 273 | mov r1, r6 /* r1 <- scratch for copy_loop */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 274 | ldr r3, _bss_start_ofs |
| 275 | add r2, r0, r3 /* r2 <- source end address */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 276 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 277 | copy_loop: |
| 278 | ldmia r0!, {r9-r10} /* copy from source address [r0] */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 279 | stmia r1!, {r9-r10} /* copy to target address [r1] */ |
Albert Aribaud | 0668d16 | 2010-10-05 16:06:39 +0200 | [diff] [blame] | 280 | cmp r0, r2 /* until source end address [r2] */ |
| 281 | blo copy_loop |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 282 | |
Aneesh V | 552a319 | 2011-07-13 05:11:07 +0000 | [diff] [blame] | 283 | #ifndef CONFIG_SPL_BUILD |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 284 | /* |
| 285 | * fix .rel.dyn relocations |
| 286 | */ |
| 287 | ldr r0, _TEXT_BASE /* r0 <- Text base */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 288 | sub r9, r6, r0 /* r9 <- relocation offset */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 289 | ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */ |
| 290 | add r10, r10, r0 /* r10 <- sym table in FLASH */ |
| 291 | ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */ |
| 292 | add r2, r2, r0 /* r2 <- rel dyn start in FLASH */ |
| 293 | ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */ |
| 294 | add r3, r3, r0 /* r3 <- rel dyn end in FLASH */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 295 | fixloop: |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 296 | ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */ |
| 297 | add r0, r0, r9 /* r0 <- location to fix up in RAM */ |
| 298 | ldr r1, [r2, #4] |
Andreas Bießmann | 318cea1 | 2010-12-01 00:58:35 +0100 | [diff] [blame] | 299 | and r7, r1, #0xff |
| 300 | cmp r7, #23 /* relative fixup? */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 301 | beq fixrel |
Andreas Bießmann | 318cea1 | 2010-12-01 00:58:35 +0100 | [diff] [blame] | 302 | cmp r7, #2 /* absolute fixup? */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 303 | beq fixabs |
| 304 | /* ignore unknown type of fixup */ |
| 305 | b fixnext |
| 306 | fixabs: |
| 307 | /* absolute fix: set location to (offset) symbol value */ |
| 308 | mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */ |
| 309 | add r1, r10, r1 /* r1 <- address of symbol in table */ |
| 310 | ldr r1, [r1, #4] /* r1 <- symbol value */ |
Wolfgang Denk | 899cdd1 | 2010-12-09 11:26:24 +0100 | [diff] [blame] | 311 | add r1, r1, r9 /* r1 <- relocated sym addr */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 312 | b fixnext |
| 313 | fixrel: |
| 314 | /* relative fix: increase location by offset */ |
| 315 | ldr r1, [r0] |
| 316 | add r1, r1, r9 |
| 317 | fixnext: |
| 318 | str r1, [r0] |
| 319 | add r2, r2, #8 /* each rel.dyn entry is 8 bytes */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 320 | cmp r2, r3 |
Wolfgang Denk | 98dd07c | 2010-10-23 23:22:38 +0200 | [diff] [blame] | 321 | blo fixloop |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 322 | #endif |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 323 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 324 | relocate_done: |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 325 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 326 | bx lr |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 327 | |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 328 | _rel_dyn_start_ofs: |
| 329 | .word __rel_dyn_start - _start |
| 330 | _rel_dyn_end_ofs: |
| 331 | .word __rel_dyn_end - _start |
| 332 | _dynsym_start_ofs: |
| 333 | .word __dynsym_start - _start |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 334 | |
Albert ARIBAUD | facdae5 | 2013-01-08 10:18:02 +0000 | [diff] [blame] | 335 | .globl c_runtime_cpu_setup |
| 336 | c_runtime_cpu_setup: |
| 337 | |
| 338 | bx lr |
| 339 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 340 | /****************************************************************************/ |
| 341 | /* */ |
| 342 | /* Interrupt handling */ |
| 343 | /* */ |
| 344 | /****************************************************************************/ |
| 345 | |
| 346 | /* IRQ stack frame */ |
| 347 | |
| 348 | #define S_FRAME_SIZE 72 |
| 349 | |
| 350 | #define S_OLD_R0 68 |
| 351 | #define S_PSR 64 |
| 352 | #define S_PC 60 |
| 353 | #define S_LR 56 |
| 354 | #define S_SP 52 |
| 355 | |
| 356 | #define S_IP 48 |
| 357 | #define S_FP 44 |
| 358 | #define S_R10 40 |
| 359 | #define S_R9 36 |
| 360 | #define S_R8 32 |
| 361 | #define S_R7 28 |
| 362 | #define S_R6 24 |
| 363 | #define S_R5 20 |
| 364 | #define S_R4 16 |
| 365 | #define S_R3 12 |
| 366 | #define S_R2 8 |
| 367 | #define S_R1 4 |
| 368 | #define S_R0 0 |
| 369 | |
| 370 | #define MODE_SVC 0x13 |
| 371 | |
| 372 | /* use bad_save_user_regs for abort/prefetch/undef/swi ... */ |
| 373 | |
| 374 | .macro bad_save_user_regs |
| 375 | sub sp, sp, #S_FRAME_SIZE |
| 376 | stmia sp, {r0 - r12} /* Calling r0-r12 */ |
| 377 | add r8, sp, #S_PC |
| 378 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 379 | ldr r2, IRQ_STACK_START_IN |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 380 | ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */ |
| 381 | add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */ |
| 382 | |
| 383 | add r5, sp, #S_SP |
| 384 | mov r1, lr |
| 385 | stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */ |
| 386 | mov r0, sp |
| 387 | .endm |
| 388 | |
| 389 | |
| 390 | /* use irq_save_user_regs / irq_restore_user_regs for */ |
| 391 | /* IRQ/FIQ handling */ |
| 392 | |
| 393 | .macro irq_save_user_regs |
| 394 | sub sp, sp, #S_FRAME_SIZE |
| 395 | stmia sp, {r0 - r12} /* Calling r0-r12 */ |
| 396 | add r8, sp, #S_PC |
| 397 | stmdb r8, {sp, lr}^ /* Calling SP, LR */ |
| 398 | str lr, [r8, #0] /* Save calling PC */ |
| 399 | mrs r6, spsr |
| 400 | str r6, [r8, #4] /* Save CPSR */ |
| 401 | str r0, [r8, #8] /* Save OLD_R0 */ |
| 402 | mov r0, sp |
| 403 | .endm |
| 404 | |
| 405 | .macro irq_restore_user_regs |
| 406 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 407 | mov r0, r0 |
| 408 | ldr lr, [sp, #S_PC] @ Get PC |
| 409 | add sp, sp, #S_FRAME_SIZE |
| 410 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 411 | .endm |
| 412 | |
| 413 | .macro get_bad_stack |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 414 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 415 | |
| 416 | str lr, [r13] @ save caller lr / spsr |
| 417 | mrs lr, spsr |
| 418 | str lr, [r13, #4] |
| 419 | |
| 420 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 421 | msr spsr_c, r13 |
| 422 | mov lr, pc |
| 423 | movs pc, lr |
| 424 | .endm |
| 425 | |
| 426 | .macro get_irq_stack @ setup IRQ stack |
| 427 | ldr sp, IRQ_STACK_START |
| 428 | .endm |
| 429 | |
| 430 | .macro get_fiq_stack @ setup FIQ stack |
| 431 | ldr sp, FIQ_STACK_START |
| 432 | .endm |
| 433 | |
| 434 | |
| 435 | /****************************************************************************/ |
| 436 | /* */ |
| 437 | /* exception handlers */ |
| 438 | /* */ |
| 439 | /****************************************************************************/ |
| 440 | |
| 441 | .align 5 |
| 442 | undefined_instruction: |
| 443 | get_bad_stack |
| 444 | bad_save_user_regs |
| 445 | bl do_undefined_instruction |
| 446 | |
| 447 | .align 5 |
| 448 | software_interrupt: |
| 449 | get_bad_stack |
| 450 | bad_save_user_regs |
| 451 | bl do_software_interrupt |
| 452 | |
| 453 | .align 5 |
| 454 | prefetch_abort: |
| 455 | get_bad_stack |
| 456 | bad_save_user_regs |
| 457 | bl do_prefetch_abort |
| 458 | |
| 459 | .align 5 |
| 460 | data_abort: |
| 461 | get_bad_stack |
| 462 | bad_save_user_regs |
| 463 | bl do_data_abort |
| 464 | |
| 465 | .align 5 |
| 466 | not_used: |
| 467 | get_bad_stack |
| 468 | bad_save_user_regs |
| 469 | bl do_not_used |
| 470 | |
| 471 | #ifdef CONFIG_USE_IRQ |
| 472 | |
| 473 | .align 5 |
| 474 | irq: |
| 475 | get_irq_stack |
| 476 | irq_save_user_regs |
| 477 | bl do_irq |
| 478 | irq_restore_user_regs |
| 479 | |
| 480 | .align 5 |
| 481 | fiq: |
| 482 | get_fiq_stack |
| 483 | irq_save_user_regs /* someone ought to write a more */ |
| 484 | bl do_fiq /* effiction fiq_save_user_regs */ |
| 485 | irq_restore_user_regs |
| 486 | |
| 487 | #else |
| 488 | |
| 489 | .align 5 |
| 490 | irq: |
| 491 | get_bad_stack |
| 492 | bad_save_user_regs |
| 493 | bl do_irq |
| 494 | |
| 495 | .align 5 |
| 496 | fiq: |
| 497 | get_bad_stack |
| 498 | bad_save_user_regs |
| 499 | bl do_fiq |
| 500 | |
| 501 | #endif |
| 502 | |
| 503 | /****************************************************************************/ |
| 504 | /* */ |
| 505 | /* Reset function: Use Watchdog to reset */ |
| 506 | /* */ |
| 507 | /****************************************************************************/ |
| 508 | |
| 509 | .align 5 |
| 510 | .globl reset_cpu |
| 511 | |
| 512 | reset_cpu: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 513 | ldr r1, =0x482e |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 514 | ldr r2, =IXP425_OSWK |
| 515 | str r1, [r2] |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 516 | ldr r1, =0x0fff |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 517 | ldr r2, =IXP425_OSWT |
| 518 | str r1, [r2] |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 519 | ldr r1, =0x5 |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 520 | ldr r2, =IXP425_OSWE |
| 521 | str r1, [r2] |
| 522 | b reset_endless |
| 523 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 524 | reset_endless: |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 525 | b reset_endless |