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 |
| 68 | _start: b reset |
| 69 | ldr pc, _undefined_instruction |
| 70 | ldr pc, _software_interrupt |
| 71 | ldr pc, _prefetch_abort |
| 72 | ldr pc, _data_abort |
| 73 | ldr pc, _not_used |
| 74 | ldr pc, _irq |
| 75 | ldr pc, _fiq |
| 76 | |
| 77 | _undefined_instruction: .word undefined_instruction |
| 78 | _software_interrupt: .word software_interrupt |
| 79 | _prefetch_abort: .word prefetch_abort |
| 80 | _data_abort: .word data_abort |
| 81 | _not_used: .word not_used |
| 82 | _irq: .word irq |
| 83 | _fiq: .word fiq |
| 84 | |
| 85 | .balignl 16,0xdeadbeef |
| 86 | |
| 87 | |
| 88 | /* |
| 89 | * Startup Code (reset vector) |
| 90 | * |
| 91 | * do important init only if we don't start from memory! |
| 92 | * - relocate armboot to ram |
| 93 | * - setup stack |
| 94 | * - jump to second stage |
| 95 | */ |
| 96 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 97 | .globl _TEXT_BASE |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 98 | _TEXT_BASE: |
Wolfgang Denk | 0708bc6 | 2010-10-07 21:51:12 +0200 | [diff] [blame] | 99 | .word CONFIG_SYS_TEXT_BASE |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 100 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 101 | /* |
wdenk | 927034e | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 102 | * These are defined in the board-specific linker script. |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 103 | * Subtracting _start from them lets the linker put their |
| 104 | * relative position in the executable instead of leaving |
| 105 | * them null. |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 106 | */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 107 | .globl _bss_start_ofs |
| 108 | _bss_start_ofs: |
| 109 | .word __bss_start - _start |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 110 | |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 111 | .globl _bss_end_ofs |
| 112 | _bss_end_ofs: |
Po-Yu Chuang | cedbf4b | 2011-03-01 22:59:59 +0000 | [diff] [blame] | 113 | .word __bss_end__ - _start |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 114 | |
Po-Yu Chuang | 1864b00 | 2011-03-01 23:02:04 +0000 | [diff] [blame^] | 115 | .globl _end_ofs |
| 116 | _end_ofs: |
| 117 | .word _end - _start |
| 118 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 119 | #ifdef CONFIG_USE_IRQ |
| 120 | /* IRQ stack memory (calculated at run-time) */ |
| 121 | .globl IRQ_STACK_START |
| 122 | IRQ_STACK_START: |
| 123 | .word 0x0badc0de |
| 124 | |
| 125 | /* IRQ stack memory (calculated at run-time) */ |
| 126 | .globl FIQ_STACK_START |
| 127 | FIQ_STACK_START: |
| 128 | .word 0x0badc0de |
| 129 | #endif |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 130 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 131 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 132 | .globl IRQ_STACK_START_IN |
| 133 | IRQ_STACK_START_IN: |
| 134 | .word 0x0badc0de |
| 135 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 136 | /* |
| 137 | * the actual reset code |
| 138 | */ |
| 139 | |
| 140 | reset: |
| 141 | /* disable mmu, set big-endian */ |
| 142 | mov r0, #0xf8 |
| 143 | mcr p15, 0, r0, c1, c0, 0 |
| 144 | CPWAIT r0 |
| 145 | |
| 146 | /* invalidate I & D caches & BTB */ |
| 147 | mcr p15, 0, r0, c7, c7, 0 |
| 148 | CPWAIT r0 |
| 149 | |
| 150 | /* invalidate I & Data TLB */ |
| 151 | mcr p15, 0, r0, c8, c7, 0 |
| 152 | CPWAIT r0 |
| 153 | |
| 154 | /* drain write and fill buffers */ |
| 155 | mcr p15, 0, r0, c7, c10, 4 |
| 156 | CPWAIT r0 |
| 157 | |
| 158 | /* disable write buffer coalescing */ |
| 159 | mrc p15, 0, r0, c1, c0, 1 |
| 160 | orr r0, r0, #1 |
| 161 | mcr p15, 0, r0, c1, c0, 1 |
| 162 | CPWAIT r0 |
| 163 | |
| 164 | /* set EXP CS0 to the optimum timing */ |
| 165 | ldr r1, =CONFIG_SYS_EXP_CS0 |
| 166 | ldr r2, =IXP425_EXP_CS0 |
| 167 | str r1, [r2] |
| 168 | |
| 169 | /* make sure flash is visible at 0 */ |
| 170 | #if 0 |
| 171 | ldr r2, =IXP425_EXP_CFG0 |
| 172 | ldr r1, [r2] |
| 173 | orr r1, r1, #0x80000000 |
| 174 | str r1, [r2] |
| 175 | #endif |
| 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 | |
| 219 | /* copy */ |
| 220 | mov r0, #0 |
| 221 | mov r4, r0 |
| 222 | add r2, r0, #CONFIG_SYS_MONITOR_LEN |
| 223 | mov r1, #0x10000000 |
| 224 | mov r5, r1 |
| 225 | |
| 226 | 30: |
| 227 | ldr r3, [r0], #4 |
| 228 | str r3, [r1], #4 |
| 229 | cmp r0, r2 |
| 230 | bne 30b |
| 231 | |
| 232 | /* invalidate I & D caches & BTB */ |
| 233 | mcr p15, 0, r0, c7, c7, 0 |
| 234 | CPWAIT r0 |
| 235 | |
| 236 | /* invalidate I & Data TLB */ |
| 237 | mcr p15, 0, r0, c8, c7, 0 |
| 238 | CPWAIT r0 |
| 239 | |
| 240 | /* drain write and fill buffers */ |
| 241 | mcr p15, 0, r0, c7, c10, 4 |
| 242 | CPWAIT r0 |
| 243 | |
| 244 | /* move flash to 0x50000000 */ |
| 245 | ldr r2, =IXP425_EXP_CFG0 |
| 246 | ldr r1, [r2] |
| 247 | bic r1, r1, #0x80000000 |
| 248 | str r1, [r2] |
| 249 | |
| 250 | nop |
| 251 | nop |
| 252 | nop |
| 253 | nop |
| 254 | nop |
| 255 | nop |
| 256 | |
| 257 | /* invalidate I & Data TLB */ |
| 258 | mcr p15, 0, r0, c8, c7, 0 |
| 259 | CPWAIT r0 |
| 260 | |
| 261 | /* enable I cache */ |
| 262 | mrc p15, 0, r0, c1, c0, 0 |
| 263 | orr r0, r0, #MMU_Control_I |
| 264 | mcr p15, 0, r0, c1, c0, 0 |
| 265 | CPWAIT r0 |
| 266 | |
| 267 | mrs r0,cpsr /* set the cpu to SVC32 mode */ |
| 268 | bic r0,r0,#0x1f /* (superviser mode, M=10011) */ |
| 269 | orr r0,r0,#0x13 |
| 270 | msr cpsr,r0 |
| 271 | |
| 272 | /* Set stackpointer in internal RAM to call board_init_f */ |
| 273 | call_board_init_f: |
| 274 | ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) |
Heiko Schocher | 17f288a | 2010-11-12 07:53:55 +0100 | [diff] [blame] | 275 | bic sp, sp, #7 /* 8-byte alignment for ABI compliance */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 276 | ldr r0,=0x00000000 |
| 277 | bl board_init_f |
| 278 | |
| 279 | /*------------------------------------------------------------------------------*/ |
| 280 | |
| 281 | /* |
| 282 | * void relocate_code (addr_sp, gd, addr_moni) |
| 283 | * |
| 284 | * This "function" does not return, instead it continues in RAM |
| 285 | * after relocating the monitor code. |
| 286 | * |
| 287 | */ |
| 288 | .globl relocate_code |
| 289 | relocate_code: |
| 290 | mov r4, r0 /* save addr_sp */ |
| 291 | mov r5, r1 /* save addr of gd */ |
| 292 | mov r6, r2 /* save addr of destination */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 293 | |
| 294 | /* Set up the stack */ |
| 295 | stack_setup: |
| 296 | mov sp, r4 |
| 297 | |
| 298 | adr r0, _start |
Andreas Bießmann | 007b38f | 2010-12-01 00:58:34 +0100 | [diff] [blame] | 299 | cmp r0, r6 |
| 300 | beq clear_bss /* skip relocation */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 301 | mov r1, r6 /* r1 <- scratch for copy_loop */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 302 | ldr r3, _bss_start_ofs |
| 303 | add r2, r0, r3 /* r2 <- source end address */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 304 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 305 | copy_loop: |
| 306 | ldmia r0!, {r9-r10} /* copy from source address [r0] */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 307 | stmia r1!, {r9-r10} /* copy to target address [r1] */ |
Albert Aribaud | 0668d16 | 2010-10-05 16:06:39 +0200 | [diff] [blame] | 308 | cmp r0, r2 /* until source end address [r2] */ |
| 309 | blo copy_loop |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 310 | |
| 311 | #ifndef CONFIG_PRELOADER |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 312 | /* |
| 313 | * fix .rel.dyn relocations |
| 314 | */ |
| 315 | ldr r0, _TEXT_BASE /* r0 <- Text base */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 316 | sub r9, r6, r0 /* r9 <- relocation offset */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 317 | ldr r10, _dynsym_start_ofs /* r10 <- sym table ofs */ |
| 318 | add r10, r10, r0 /* r10 <- sym table in FLASH */ |
| 319 | ldr r2, _rel_dyn_start_ofs /* r2 <- rel dyn start ofs */ |
| 320 | add r2, r2, r0 /* r2 <- rel dyn start in FLASH */ |
| 321 | ldr r3, _rel_dyn_end_ofs /* r3 <- rel dyn end ofs */ |
| 322 | add r3, r3, r0 /* r3 <- rel dyn end in FLASH */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 323 | fixloop: |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 324 | ldr r0, [r2] /* r0 <- location to fix up, IN FLASH! */ |
| 325 | add r0, r0, r9 /* r0 <- location to fix up in RAM */ |
| 326 | ldr r1, [r2, #4] |
Andreas Bießmann | 318cea1 | 2010-12-01 00:58:35 +0100 | [diff] [blame] | 327 | and r7, r1, #0xff |
| 328 | cmp r7, #23 /* relative fixup? */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 329 | beq fixrel |
Andreas Bießmann | 318cea1 | 2010-12-01 00:58:35 +0100 | [diff] [blame] | 330 | cmp r7, #2 /* absolute fixup? */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 331 | beq fixabs |
| 332 | /* ignore unknown type of fixup */ |
| 333 | b fixnext |
| 334 | fixabs: |
| 335 | /* absolute fix: set location to (offset) symbol value */ |
| 336 | mov r1, r1, LSR #4 /* r1 <- symbol index in .dynsym */ |
| 337 | add r1, r10, r1 /* r1 <- address of symbol in table */ |
| 338 | ldr r1, [r1, #4] /* r1 <- symbol value */ |
Wolfgang Denk | 899cdd1 | 2010-12-09 11:26:24 +0100 | [diff] [blame] | 339 | add r1, r1, r9 /* r1 <- relocated sym addr */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 340 | b fixnext |
| 341 | fixrel: |
| 342 | /* relative fix: increase location by offset */ |
| 343 | ldr r1, [r0] |
| 344 | add r1, r1, r9 |
| 345 | fixnext: |
| 346 | str r1, [r0] |
| 347 | add r2, r2, #8 /* each rel.dyn entry is 8 bytes */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 348 | cmp r2, r3 |
Wolfgang Denk | 98dd07c | 2010-10-23 23:22:38 +0200 | [diff] [blame] | 349 | blo fixloop |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 350 | #endif |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 351 | |
| 352 | clear_bss: |
| 353 | #ifndef CONFIG_PRELOADER |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 354 | ldr r0, _bss_start_ofs |
| 355 | ldr r1, _bss_end_ofs |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 356 | mov r4, r6 /* reloc addr */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 357 | add r0, r0, r4 |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 358 | add r1, r1, r4 |
| 359 | mov r2, #0x00000000 /* clear */ |
| 360 | |
| 361 | clbss_l:str r2, [r0] /* clear loop... */ |
| 362 | add r0, r0, #4 |
| 363 | cmp r0, r1 |
| 364 | bne clbss_l |
| 365 | |
| 366 | bl coloured_LED_init |
| 367 | bl red_LED_on |
| 368 | #endif |
| 369 | |
| 370 | /* |
| 371 | * We are done. Do not return, instead branch to second part of board |
| 372 | * initialization, now running from RAM. |
| 373 | */ |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 374 | ldr r0, _board_init_r_ofs |
| 375 | adr r1, _start |
| 376 | add lr, r0, r1 |
| 377 | add lr, lr, r9 |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 378 | /* setup parameters for board_init_r */ |
| 379 | mov r0, r5 /* gd_t */ |
Andreas Bießmann | 8cfbda9 | 2010-12-01 00:58:33 +0100 | [diff] [blame] | 380 | mov r1, r6 /* dest_addr */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 381 | /* jump to it ... */ |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 382 | mov pc, lr |
| 383 | |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 384 | _board_init_r_ofs: |
| 385 | .word board_init_r - _start |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 386 | |
Albert Aribaud | 126897e | 2010-11-25 22:45:02 +0100 | [diff] [blame] | 387 | _rel_dyn_start_ofs: |
| 388 | .word __rel_dyn_start - _start |
| 389 | _rel_dyn_end_ofs: |
| 390 | .word __rel_dyn_end - _start |
| 391 | _dynsym_start_ofs: |
| 392 | .word __dynsym_start - _start |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 393 | |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 394 | /****************************************************************************/ |
| 395 | /* */ |
| 396 | /* Interrupt handling */ |
| 397 | /* */ |
| 398 | /****************************************************************************/ |
| 399 | |
| 400 | /* IRQ stack frame */ |
| 401 | |
| 402 | #define S_FRAME_SIZE 72 |
| 403 | |
| 404 | #define S_OLD_R0 68 |
| 405 | #define S_PSR 64 |
| 406 | #define S_PC 60 |
| 407 | #define S_LR 56 |
| 408 | #define S_SP 52 |
| 409 | |
| 410 | #define S_IP 48 |
| 411 | #define S_FP 44 |
| 412 | #define S_R10 40 |
| 413 | #define S_R9 36 |
| 414 | #define S_R8 32 |
| 415 | #define S_R7 28 |
| 416 | #define S_R6 24 |
| 417 | #define S_R5 20 |
| 418 | #define S_R4 16 |
| 419 | #define S_R3 12 |
| 420 | #define S_R2 8 |
| 421 | #define S_R1 4 |
| 422 | #define S_R0 0 |
| 423 | |
| 424 | #define MODE_SVC 0x13 |
| 425 | |
| 426 | /* use bad_save_user_regs for abort/prefetch/undef/swi ... */ |
| 427 | |
| 428 | .macro bad_save_user_regs |
| 429 | sub sp, sp, #S_FRAME_SIZE |
| 430 | stmia sp, {r0 - r12} /* Calling r0-r12 */ |
| 431 | add r8, sp, #S_PC |
| 432 | |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 433 | ldr r2, IRQ_STACK_START_IN |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 434 | ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */ |
| 435 | add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */ |
| 436 | |
| 437 | add r5, sp, #S_SP |
| 438 | mov r1, lr |
| 439 | stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */ |
| 440 | mov r0, sp |
| 441 | .endm |
| 442 | |
| 443 | |
| 444 | /* use irq_save_user_regs / irq_restore_user_regs for */ |
| 445 | /* IRQ/FIQ handling */ |
| 446 | |
| 447 | .macro irq_save_user_regs |
| 448 | sub sp, sp, #S_FRAME_SIZE |
| 449 | stmia sp, {r0 - r12} /* Calling r0-r12 */ |
| 450 | add r8, sp, #S_PC |
| 451 | stmdb r8, {sp, lr}^ /* Calling SP, LR */ |
| 452 | str lr, [r8, #0] /* Save calling PC */ |
| 453 | mrs r6, spsr |
| 454 | str r6, [r8, #4] /* Save CPSR */ |
| 455 | str r0, [r8, #8] /* Save OLD_R0 */ |
| 456 | mov r0, sp |
| 457 | .endm |
| 458 | |
| 459 | .macro irq_restore_user_regs |
| 460 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 461 | mov r0, r0 |
| 462 | ldr lr, [sp, #S_PC] @ Get PC |
| 463 | add sp, sp, #S_FRAME_SIZE |
| 464 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 465 | .endm |
| 466 | |
| 467 | .macro get_bad_stack |
Heiko Schocher | b2b37f0 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 468 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 469 | |
| 470 | str lr, [r13] @ save caller lr / spsr |
| 471 | mrs lr, spsr |
| 472 | str lr, [r13, #4] |
| 473 | |
| 474 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 475 | msr spsr_c, r13 |
| 476 | mov lr, pc |
| 477 | movs pc, lr |
| 478 | .endm |
| 479 | |
| 480 | .macro get_irq_stack @ setup IRQ stack |
| 481 | ldr sp, IRQ_STACK_START |
| 482 | .endm |
| 483 | |
| 484 | .macro get_fiq_stack @ setup FIQ stack |
| 485 | ldr sp, FIQ_STACK_START |
| 486 | .endm |
| 487 | |
| 488 | |
| 489 | /****************************************************************************/ |
| 490 | /* */ |
| 491 | /* exception handlers */ |
| 492 | /* */ |
| 493 | /****************************************************************************/ |
| 494 | |
| 495 | .align 5 |
| 496 | undefined_instruction: |
| 497 | get_bad_stack |
| 498 | bad_save_user_regs |
| 499 | bl do_undefined_instruction |
| 500 | |
| 501 | .align 5 |
| 502 | software_interrupt: |
| 503 | get_bad_stack |
| 504 | bad_save_user_regs |
| 505 | bl do_software_interrupt |
| 506 | |
| 507 | .align 5 |
| 508 | prefetch_abort: |
| 509 | get_bad_stack |
| 510 | bad_save_user_regs |
| 511 | bl do_prefetch_abort |
| 512 | |
| 513 | .align 5 |
| 514 | data_abort: |
| 515 | get_bad_stack |
| 516 | bad_save_user_regs |
| 517 | bl do_data_abort |
| 518 | |
| 519 | .align 5 |
| 520 | not_used: |
| 521 | get_bad_stack |
| 522 | bad_save_user_regs |
| 523 | bl do_not_used |
| 524 | |
| 525 | #ifdef CONFIG_USE_IRQ |
| 526 | |
| 527 | .align 5 |
| 528 | irq: |
| 529 | get_irq_stack |
| 530 | irq_save_user_regs |
| 531 | bl do_irq |
| 532 | irq_restore_user_regs |
| 533 | |
| 534 | .align 5 |
| 535 | fiq: |
| 536 | get_fiq_stack |
| 537 | irq_save_user_regs /* someone ought to write a more */ |
| 538 | bl do_fiq /* effiction fiq_save_user_regs */ |
| 539 | irq_restore_user_regs |
| 540 | |
| 541 | #else |
| 542 | |
| 543 | .align 5 |
| 544 | irq: |
| 545 | get_bad_stack |
| 546 | bad_save_user_regs |
| 547 | bl do_irq |
| 548 | |
| 549 | .align 5 |
| 550 | fiq: |
| 551 | get_bad_stack |
| 552 | bad_save_user_regs |
| 553 | bl do_fiq |
| 554 | |
| 555 | #endif |
| 556 | |
| 557 | /****************************************************************************/ |
| 558 | /* */ |
| 559 | /* Reset function: Use Watchdog to reset */ |
| 560 | /* */ |
| 561 | /****************************************************************************/ |
| 562 | |
| 563 | .align 5 |
| 564 | .globl reset_cpu |
| 565 | |
| 566 | reset_cpu: |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 567 | ldr r1, =0x482e |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 568 | ldr r2, =IXP425_OSWK |
| 569 | str r1, [r2] |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 570 | ldr r1, =0x0fff |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 571 | ldr r2, =IXP425_OSWT |
| 572 | str r1, [r2] |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 573 | ldr r1, =0x5 |
wdenk | bd1575f | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 574 | ldr r2, =IXP425_OSWE |
| 575 | str r1, [r2] |
| 576 | b reset_endless |
| 577 | |
| 578 | |
| 579 | reset_endless: |
| 580 | |
| 581 | b reset_endless |
Wolfgang Denk | 4646d2a | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 582 | |
| 583 | #ifdef CONFIG_USE_IRQ |
| 584 | |
| 585 | .LC0: .word loops_per_jiffy |
| 586 | |
| 587 | /* |
| 588 | * 0 <= r0 <= 2000 |
| 589 | */ |
Ingo van Lil | f0f778a | 2009-11-24 14:09:21 +0100 | [diff] [blame] | 590 | .globl __udelay |
| 591 | __udelay: |
Wolfgang Denk | 4646d2a | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 592 | mov r2, #0x6800 |
| 593 | orr r2, r2, #0x00db |
| 594 | mul r0, r2, r0 |
| 595 | ldr r2, .LC0 |
| 596 | ldr r2, [r2] @ max = 0x0fffffff |
| 597 | mov r0, r0, lsr #11 @ max = 0x00003fff |
| 598 | mov r2, r2, lsr #11 @ max = 0x0003ffff |
| 599 | mul r0, r2, r0 @ max = 2^32-1 |
| 600 | movs r0, r0, lsr #6 |
| 601 | |
| 602 | delay_loop: |
| 603 | subs r0, r0, #1 |
| 604 | bne delay_loop |
| 605 | mov pc, lr |
| 606 | |
| 607 | #endif /* CONFIG_USE_IRQ */ |