wdenk | 2d5b561 | 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 | |
| 30 | #include <config.h> |
| 31 | #include <version.h> |
| 32 | #include <asm/arch/ixp425.h> |
| 33 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 34 | #define MMU_Control_M 0x001 /* Enable MMU */ |
| 35 | #define MMU_Control_A 0x002 /* Enable address alignment faults */ |
| 36 | #define MMU_Control_C 0x004 /* Enable cache */ |
| 37 | #define MMU_Control_W 0x008 /* Enable write-buffer */ |
| 38 | #define MMU_Control_P 0x010 /* Compatability: 32 bit code */ |
| 39 | #define MMU_Control_D 0x020 /* Compatability: 32 bit data */ |
| 40 | #define MMU_Control_L 0x040 /* Compatability: */ |
| 41 | #define MMU_Control_B 0x080 /* Enable Big-Endian */ |
| 42 | #define MMU_Control_S 0x100 /* Enable system protection */ |
| 43 | #define MMU_Control_R 0x200 /* Enable ROM protection */ |
| 44 | #define MMU_Control_I 0x1000 /* Enable Instruction cache */ |
| 45 | #define MMU_Control_X 0x2000 /* Set interrupt vectors at 0xFFFF0000 */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 46 | #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L) |
| 47 | |
| 48 | |
| 49 | /* |
| 50 | * Macro definitions |
| 51 | */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 52 | /* Delay a bit */ |
| 53 | .macro DELAY_FOR cycles, reg0 |
| 54 | ldr \reg0, =\cycles |
| 55 | subs \reg0, \reg0, #1 |
| 56 | subne pc, pc, #0xc |
| 57 | .endm |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 58 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 59 | /* wait for coprocessor write complete */ |
| 60 | .macro CPWAIT reg |
| 61 | mrc p15,0,\reg,c2,c0,0 |
| 62 | mov \reg,\reg |
| 63 | sub pc,pc,#4 |
| 64 | .endm |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 65 | |
| 66 | .globl _start |
| 67 | _start: b reset |
| 68 | ldr pc, _undefined_instruction |
| 69 | ldr pc, _software_interrupt |
| 70 | ldr pc, _prefetch_abort |
| 71 | ldr pc, _data_abort |
| 72 | ldr pc, _not_used |
| 73 | ldr pc, _irq |
| 74 | ldr pc, _fiq |
| 75 | |
| 76 | _undefined_instruction: .word undefined_instruction |
| 77 | _software_interrupt: .word software_interrupt |
| 78 | _prefetch_abort: .word prefetch_abort |
| 79 | _data_abort: .word data_abort |
| 80 | _not_used: .word not_used |
| 81 | _irq: .word irq |
| 82 | _fiq: .word fiq |
| 83 | |
| 84 | .balignl 16,0xdeadbeef |
| 85 | |
| 86 | |
| 87 | /* |
| 88 | * Startup Code (reset vector) |
| 89 | * |
| 90 | * do important init only if we don't start from memory! |
| 91 | * - relocate armboot to ram |
| 92 | * - setup stack |
| 93 | * - jump to second stage |
| 94 | */ |
| 95 | |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 96 | .globl _TEXT_BASE |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 97 | _TEXT_BASE: |
| 98 | .word TEXT_BASE |
| 99 | |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 100 | #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 101 | .globl _armboot_start |
| 102 | _armboot_start: |
| 103 | .word _start |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 104 | #endif |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 105 | |
| 106 | /* |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 107 | * These are defined in the board-specific linker script. |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 108 | */ |
| 109 | .globl _bss_start |
| 110 | _bss_start: |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 111 | .word __bss_start |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 112 | |
| 113 | .globl _bss_end |
| 114 | _bss_end: |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 115 | .word _end |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 116 | |
| 117 | #ifdef CONFIG_USE_IRQ |
| 118 | /* IRQ stack memory (calculated at run-time) */ |
| 119 | .globl IRQ_STACK_START |
| 120 | IRQ_STACK_START: |
| 121 | .word 0x0badc0de |
| 122 | |
| 123 | /* IRQ stack memory (calculated at run-time) */ |
| 124 | .globl FIQ_STACK_START |
| 125 | FIQ_STACK_START: |
| 126 | .word 0x0badc0de |
| 127 | #endif |
| 128 | |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 129 | #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) |
| 130 | /* IRQ stack memory (calculated at run-time) + 8 bytes */ |
| 131 | .globl IRQ_STACK_START_IN |
| 132 | IRQ_STACK_START_IN: |
| 133 | .word 0x0badc0de |
| 134 | |
| 135 | .globl _datarel_start |
| 136 | _datarel_start: |
| 137 | .word __datarel_start |
| 138 | |
| 139 | .globl _datarelrolocal_start |
| 140 | _datarelrolocal_start: |
| 141 | .word __datarelrolocal_start |
| 142 | |
| 143 | .globl _datarellocal_start |
| 144 | _datarellocal_start: |
| 145 | .word __datarellocal_start |
| 146 | |
| 147 | .globl _datarelro_start |
| 148 | _datarelro_start: |
| 149 | .word __datarelro_start |
| 150 | |
| 151 | .globl _got_start |
| 152 | _got_start: |
| 153 | .word __got_start |
| 154 | |
| 155 | .globl _got_end |
| 156 | _got_end: |
| 157 | .word __got_end |
| 158 | |
| 159 | /* |
| 160 | * the actual reset code |
| 161 | */ |
| 162 | |
| 163 | reset: |
| 164 | /* disable mmu, set big-endian */ |
| 165 | mov r0, #0xf8 |
| 166 | mcr p15, 0, r0, c1, c0, 0 |
| 167 | CPWAIT r0 |
| 168 | |
| 169 | /* invalidate I & D caches & BTB */ |
| 170 | mcr p15, 0, r0, c7, c7, 0 |
| 171 | CPWAIT r0 |
| 172 | |
| 173 | /* invalidate I & Data TLB */ |
| 174 | mcr p15, 0, r0, c8, c7, 0 |
| 175 | CPWAIT r0 |
| 176 | |
| 177 | /* drain write and fill buffers */ |
| 178 | mcr p15, 0, r0, c7, c10, 4 |
| 179 | CPWAIT r0 |
| 180 | |
| 181 | /* disable write buffer coalescing */ |
| 182 | mrc p15, 0, r0, c1, c0, 1 |
| 183 | orr r0, r0, #1 |
| 184 | mcr p15, 0, r0, c1, c0, 1 |
| 185 | CPWAIT r0 |
| 186 | |
| 187 | /* set EXP CS0 to the optimum timing */ |
| 188 | ldr r1, =CONFIG_SYS_EXP_CS0 |
| 189 | ldr r2, =IXP425_EXP_CS0 |
| 190 | str r1, [r2] |
| 191 | |
| 192 | /* make sure flash is visible at 0 */ |
| 193 | #if 0 |
| 194 | ldr r2, =IXP425_EXP_CFG0 |
| 195 | ldr r1, [r2] |
| 196 | orr r1, r1, #0x80000000 |
| 197 | str r1, [r2] |
| 198 | #endif |
| 199 | mov r1, #CONFIG_SYS_SDR_CONFIG |
| 200 | ldr r2, =IXP425_SDR_CONFIG |
| 201 | str r1, [r2] |
| 202 | |
| 203 | /* disable refresh cycles */ |
| 204 | mov r1, #0 |
| 205 | ldr r3, =IXP425_SDR_REFRESH |
| 206 | str r1, [r3] |
| 207 | |
| 208 | /* send nop command */ |
| 209 | mov r1, #3 |
| 210 | ldr r4, =IXP425_SDR_IR |
| 211 | str r1, [r4] |
| 212 | DELAY_FOR 0x4000, r0 |
| 213 | |
| 214 | /* set SDRAM internal refresh val */ |
| 215 | ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT |
| 216 | str r1, [r3] |
| 217 | DELAY_FOR 0x4000, r0 |
| 218 | |
| 219 | /* send precharge-all command to close all open banks */ |
| 220 | mov r1, #2 |
| 221 | str r1, [r4] |
| 222 | DELAY_FOR 0x4000, r0 |
| 223 | |
| 224 | /* provide 8 auto-refresh cycles */ |
| 225 | mov r1, #4 |
| 226 | mov r5, #8 |
| 227 | 111: str r1, [r4] |
| 228 | DELAY_FOR 0x100, r0 |
| 229 | subs r5, r5, #1 |
| 230 | bne 111b |
| 231 | |
| 232 | /* set mode register in sdram */ |
| 233 | mov r1, #CONFIG_SYS_SDR_MODE_CONFIG |
| 234 | str r1, [r4] |
| 235 | DELAY_FOR 0x4000, r0 |
| 236 | |
| 237 | /* send normal operation command */ |
| 238 | mov r1, #6 |
| 239 | str r1, [r4] |
| 240 | DELAY_FOR 0x4000, r0 |
| 241 | |
| 242 | /* copy */ |
| 243 | mov r0, #0 |
| 244 | mov r4, r0 |
| 245 | add r2, r0, #CONFIG_SYS_MONITOR_LEN |
| 246 | mov r1, #0x10000000 |
| 247 | mov r5, r1 |
| 248 | |
| 249 | 30: |
| 250 | ldr r3, [r0], #4 |
| 251 | str r3, [r1], #4 |
| 252 | cmp r0, r2 |
| 253 | bne 30b |
| 254 | |
| 255 | /* invalidate I & D caches & BTB */ |
| 256 | mcr p15, 0, r0, c7, c7, 0 |
| 257 | CPWAIT r0 |
| 258 | |
| 259 | /* invalidate I & Data TLB */ |
| 260 | mcr p15, 0, r0, c8, c7, 0 |
| 261 | CPWAIT r0 |
| 262 | |
| 263 | /* drain write and fill buffers */ |
| 264 | mcr p15, 0, r0, c7, c10, 4 |
| 265 | CPWAIT r0 |
| 266 | |
| 267 | /* move flash to 0x50000000 */ |
| 268 | ldr r2, =IXP425_EXP_CFG0 |
| 269 | ldr r1, [r2] |
| 270 | bic r1, r1, #0x80000000 |
| 271 | str r1, [r2] |
| 272 | |
| 273 | nop |
| 274 | nop |
| 275 | nop |
| 276 | nop |
| 277 | nop |
| 278 | nop |
| 279 | |
| 280 | /* invalidate I & Data TLB */ |
| 281 | mcr p15, 0, r0, c8, c7, 0 |
| 282 | CPWAIT r0 |
| 283 | |
| 284 | /* enable I cache */ |
| 285 | mrc p15, 0, r0, c1, c0, 0 |
| 286 | orr r0, r0, #MMU_Control_I |
| 287 | mcr p15, 0, r0, c1, c0, 0 |
| 288 | CPWAIT r0 |
| 289 | |
| 290 | mrs r0,cpsr /* set the cpu to SVC32 mode */ |
| 291 | bic r0,r0,#0x1f /* (superviser mode, M=10011) */ |
| 292 | orr r0,r0,#0x13 |
| 293 | msr cpsr,r0 |
| 294 | |
| 295 | /* Set stackpointer in internal RAM to call board_init_f */ |
| 296 | call_board_init_f: |
| 297 | ldr sp, =(CONFIG_SYS_INIT_SP_ADDR) |
| 298 | ldr r0,=0x00000000 |
| 299 | bl board_init_f |
| 300 | |
| 301 | /*------------------------------------------------------------------------------*/ |
| 302 | |
| 303 | /* |
| 304 | * void relocate_code (addr_sp, gd, addr_moni) |
| 305 | * |
| 306 | * This "function" does not return, instead it continues in RAM |
| 307 | * after relocating the monitor code. |
| 308 | * |
| 309 | */ |
| 310 | .globl relocate_code |
| 311 | relocate_code: |
| 312 | mov r4, r0 /* save addr_sp */ |
| 313 | mov r5, r1 /* save addr of gd */ |
| 314 | mov r6, r2 /* save addr of destination */ |
| 315 | mov r7, r2 /* save addr of destination */ |
| 316 | |
| 317 | /* Set up the stack */ |
| 318 | stack_setup: |
| 319 | mov sp, r4 |
| 320 | |
| 321 | adr r0, _start |
| 322 | ldr r2, _TEXT_BASE |
| 323 | ldr r3, _bss_start |
| 324 | sub r2, r3, r2 /* r2 <- size of armboot */ |
| 325 | add r2, r0, r2 /* r2 <- source end address */ |
| 326 | cmp r0, r6 |
| 327 | beq clear_bss |
| 328 | |
| 329 | #ifndef CONFIG_SKIP_RELOCATE_UBOOT |
| 330 | copy_loop: |
| 331 | ldmia r0!, {r9-r10} /* copy from source address [r0] */ |
| 332 | stmia r6!, {r9-r10} /* copy to target address [r1] */ |
Albert Aribaud | da90d4c | 2010-10-05 16:06:39 +0200 | [diff] [blame] | 333 | cmp r0, r2 /* until source end address [r2] */ |
| 334 | blo copy_loop |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 335 | |
| 336 | #ifndef CONFIG_PRELOADER |
| 337 | /* fix got entries */ |
| 338 | ldr r1, _TEXT_BASE /* Text base */ |
| 339 | mov r0, r7 /* reloc addr */ |
| 340 | ldr r2, _got_start /* addr in Flash */ |
| 341 | ldr r3, _got_end /* addr in Flash */ |
| 342 | sub r3, r3, r1 |
| 343 | add r3, r3, r0 |
| 344 | sub r2, r2, r1 |
| 345 | add r2, r2, r0 |
| 346 | |
| 347 | fixloop: |
| 348 | ldr r4, [r2] |
| 349 | sub r4, r4, r1 |
| 350 | add r4, r4, r0 |
| 351 | str r4, [r2] |
| 352 | add r2, r2, #4 |
| 353 | cmp r2, r3 |
| 354 | bne fixloop |
| 355 | #endif |
| 356 | #endif /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */ |
| 357 | |
| 358 | clear_bss: |
| 359 | #ifndef CONFIG_PRELOADER |
| 360 | ldr r0, _bss_start |
| 361 | ldr r1, _bss_end |
| 362 | ldr r3, _TEXT_BASE /* Text base */ |
| 363 | mov r4, r7 /* reloc addr */ |
| 364 | sub r0, r0, r3 |
| 365 | add r0, r0, r4 |
| 366 | sub r1, r1, r3 |
| 367 | add r1, r1, r4 |
| 368 | mov r2, #0x00000000 /* clear */ |
| 369 | |
| 370 | clbss_l:str r2, [r0] /* clear loop... */ |
| 371 | add r0, r0, #4 |
| 372 | cmp r0, r1 |
| 373 | bne clbss_l |
| 374 | |
| 375 | bl coloured_LED_init |
| 376 | bl red_LED_on |
| 377 | #endif |
| 378 | |
| 379 | /* |
| 380 | * We are done. Do not return, instead branch to second part of board |
| 381 | * initialization, now running from RAM. |
| 382 | */ |
| 383 | ldr r0, _TEXT_BASE |
| 384 | ldr r2, _board_init_r |
| 385 | sub r2, r2, r0 |
| 386 | add r2, r2, r7 /* position from board_init_r in RAM */ |
| 387 | /* setup parameters for board_init_r */ |
| 388 | mov r0, r5 /* gd_t */ |
| 389 | mov r1, r7 /* dest_addr */ |
| 390 | /* jump to it ... */ |
| 391 | mov lr, r2 |
| 392 | mov pc, lr |
| 393 | |
| 394 | _board_init_r: .word board_init_r |
| 395 | |
| 396 | #else /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 397 | /****************************************************************************/ |
| 398 | /* */ |
| 399 | /* the actual reset code */ |
| 400 | /* */ |
| 401 | /****************************************************************************/ |
| 402 | |
| 403 | reset: |
| 404 | /* disable mmu, set big-endian */ |
| 405 | mov r0, #0xf8 |
| 406 | mcr p15, 0, r0, c1, c0, 0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 407 | CPWAIT r0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 408 | |
| 409 | /* invalidate I & D caches & BTB */ |
| 410 | mcr p15, 0, r0, c7, c7, 0 |
| 411 | CPWAIT r0 |
| 412 | |
| 413 | /* invalidate I & Data TLB */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 414 | mcr p15, 0, r0, c8, c7, 0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 415 | CPWAIT r0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 416 | |
| 417 | /* drain write and fill buffers */ |
| 418 | mcr p15, 0, r0, c7, c10, 4 |
| 419 | CPWAIT r0 |
| 420 | |
| 421 | /* disable write buffer coalescing */ |
| 422 | mrc p15, 0, r0, c1, c0, 1 |
| 423 | orr r0, r0, #1 |
| 424 | mcr p15, 0, r0, c1, c0, 1 |
| 425 | CPWAIT r0 |
| 426 | |
| 427 | /* set EXP CS0 to the optimum timing */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 428 | ldr r1, =CONFIG_SYS_EXP_CS0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 429 | ldr r2, =IXP425_EXP_CS0 |
| 430 | str r1, [r2] |
| 431 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 432 | /* make sure flash is visible at 0 */ |
wdenk | a119190 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 433 | #if 0 |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 434 | ldr r2, =IXP425_EXP_CFG0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 435 | ldr r1, [r2] |
| 436 | orr r1, r1, #0x80000000 |
| 437 | str r1, [r2] |
wdenk | a119190 | 2005-01-09 17:12:27 +0000 | [diff] [blame] | 438 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 439 | mov r1, #CONFIG_SYS_SDR_CONFIG |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 440 | ldr r2, =IXP425_SDR_CONFIG |
| 441 | str r1, [r2] |
| 442 | |
| 443 | /* disable refresh cycles */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 444 | mov r1, #0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 445 | ldr r3, =IXP425_SDR_REFRESH |
| 446 | str r1, [r3] |
| 447 | |
| 448 | /* send nop command */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 449 | mov r1, #3 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 450 | ldr r4, =IXP425_SDR_IR |
| 451 | str r1, [r4] |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 452 | DELAY_FOR 0x4000, r0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 453 | |
| 454 | /* set SDRAM internal refresh val */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 455 | ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 456 | str r1, [r3] |
| 457 | DELAY_FOR 0x4000, r0 |
| 458 | |
| 459 | /* send precharge-all command to close all open banks */ |
| 460 | mov r1, #2 |
| 461 | str r1, [r4] |
| 462 | DELAY_FOR 0x4000, r0 |
| 463 | |
| 464 | /* provide 8 auto-refresh cycles */ |
| 465 | mov r1, #4 |
| 466 | mov r5, #8 |
| 467 | 111: str r1, [r4] |
| 468 | DELAY_FOR 0x100, r0 |
| 469 | subs r5, r5, #1 |
| 470 | bne 111b |
| 471 | |
| 472 | /* set mode register in sdram */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 473 | mov r1, #CONFIG_SYS_SDR_MODE_CONFIG |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 474 | str r1, [r4] |
| 475 | DELAY_FOR 0x4000, r0 |
| 476 | |
| 477 | /* send normal operation command */ |
| 478 | mov r1, #6 |
| 479 | str r1, [r4] |
| 480 | DELAY_FOR 0x4000, r0 |
| 481 | |
| 482 | /* copy */ |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 483 | mov r0, #0 |
| 484 | mov r4, r0 |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 485 | add r2, r0, #CONFIG_SYS_MONITOR_LEN |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 486 | mov r1, #0x10000000 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 487 | mov r5, r1 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 488 | |
| 489 | 30: |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 490 | ldr r3, [r0], #4 |
| 491 | str r3, [r1], #4 |
| 492 | cmp r0, r2 |
| 493 | bne 30b |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 494 | |
| 495 | /* invalidate I & D caches & BTB */ |
| 496 | mcr p15, 0, r0, c7, c7, 0 |
| 497 | CPWAIT r0 |
| 498 | |
| 499 | /* invalidate I & Data TLB */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 500 | mcr p15, 0, r0, c8, c7, 0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 501 | CPWAIT r0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 502 | |
| 503 | /* drain write and fill buffers */ |
| 504 | mcr p15, 0, r0, c7, c10, 4 |
| 505 | CPWAIT r0 |
| 506 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 507 | /* move flash to 0x50000000 */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 508 | ldr r2, =IXP425_EXP_CFG0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 509 | ldr r1, [r2] |
| 510 | bic r1, r1, #0x80000000 |
| 511 | str r1, [r2] |
| 512 | |
| 513 | nop |
| 514 | nop |
| 515 | nop |
| 516 | nop |
| 517 | nop |
| 518 | nop |
| 519 | |
| 520 | /* invalidate I & Data TLB */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 521 | mcr p15, 0, r0, c8, c7, 0 |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 522 | CPWAIT r0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 523 | |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 524 | /* enable I cache */ |
| 525 | mrc p15, 0, r0, c1, c0, 0 |
| 526 | orr r0, r0, #MMU_Control_I |
| 527 | mcr p15, 0, r0, c1, c0, 0 |
| 528 | CPWAIT r0 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 529 | |
| 530 | mrs r0,cpsr /* set the cpu to SVC32 mode */ |
| 531 | bic r0,r0,#0x1f /* (superviser mode, M=10011) */ |
| 532 | orr r0,r0,#0x13 |
| 533 | msr cpsr,r0 |
| 534 | |
wdenk | 8aa1a2d | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 535 | #ifndef CONFIG_SKIP_RELOCATE_UBOOT |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 536 | relocate: /* relocate U-Boot to RAM */ |
| 537 | adr r0, _start /* r0 <- current position of code */ |
| 538 | ldr r1, _TEXT_BASE /* test if we run from flash or RAM */ |
| 539 | cmp r0, r1 /* don't reloc during debug */ |
| 540 | beq stack_setup |
| 541 | |
| 542 | ldr r2, _armboot_start |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 543 | ldr r3, _bss_start |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 544 | sub r2, r3, r2 /* r2 <- size of armboot */ |
| 545 | add r2, r0, r2 /* r2 <- source end address */ |
| 546 | |
| 547 | copy_loop: |
| 548 | ldmia r0!, {r3-r10} /* copy from source address [r0] */ |
| 549 | stmia r1!, {r3-r10} /* copy to target address [r1] */ |
Albert Aribaud | da90d4c | 2010-10-05 16:06:39 +0200 | [diff] [blame] | 550 | cmp r0, r2 /* until source end address [r2] */ |
| 551 | blo copy_loop |
wdenk | 8aa1a2d | 2005-04-04 12:44:11 +0000 | [diff] [blame] | 552 | #endif /* CONFIG_SKIP_RELOCATE_UBOOT */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 553 | |
| 554 | /* Set up the stack */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 555 | stack_setup: |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 556 | ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 557 | sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */ |
| 558 | sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */ |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 559 | #ifdef CONFIG_USE_IRQ |
| 560 | sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ) |
| 561 | #endif |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 562 | sub sp, r0, #12 /* leave 3 words for abort-stack */ |
Vitaly Kuzmichev | 1a27f7d | 2010-06-15 22:18:11 +0400 | [diff] [blame] | 563 | bic sp, sp, #7 /* 8-byte alignment for ABI compliance */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 564 | |
| 565 | clear_bss: |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 566 | ldr r0, _bss_start /* find start of bss segment */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 567 | ldr r1, _bss_end /* stop here */ |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 568 | mov r2, #0x00000000 /* clear */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 569 | |
| 570 | clbss_l:str r2, [r0] /* clear loop... */ |
| 571 | add r0, r0, #4 |
| 572 | cmp r0, r1 |
Albert Aribaud | da90d4c | 2010-10-05 16:06:39 +0200 | [diff] [blame] | 573 | blo clbss_l |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 574 | |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 575 | ldr pc, _start_armboot |
| 576 | |
| 577 | _start_armboot: .word start_armboot |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 578 | #endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */ |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 579 | |
| 580 | |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 581 | /****************************************************************************/ |
| 582 | /* */ |
| 583 | /* Interrupt handling */ |
| 584 | /* */ |
| 585 | /****************************************************************************/ |
| 586 | |
| 587 | /* IRQ stack frame */ |
| 588 | |
| 589 | #define S_FRAME_SIZE 72 |
| 590 | |
| 591 | #define S_OLD_R0 68 |
| 592 | #define S_PSR 64 |
| 593 | #define S_PC 60 |
| 594 | #define S_LR 56 |
| 595 | #define S_SP 52 |
| 596 | |
| 597 | #define S_IP 48 |
| 598 | #define S_FP 44 |
| 599 | #define S_R10 40 |
| 600 | #define S_R9 36 |
| 601 | #define S_R8 32 |
| 602 | #define S_R7 28 |
| 603 | #define S_R6 24 |
| 604 | #define S_R5 20 |
| 605 | #define S_R4 16 |
| 606 | #define S_R3 12 |
| 607 | #define S_R2 8 |
| 608 | #define S_R1 4 |
| 609 | #define S_R0 0 |
| 610 | |
| 611 | #define MODE_SVC 0x13 |
| 612 | |
| 613 | /* use bad_save_user_regs for abort/prefetch/undef/swi ... */ |
| 614 | |
| 615 | .macro bad_save_user_regs |
| 616 | sub sp, sp, #S_FRAME_SIZE |
| 617 | stmia sp, {r0 - r12} /* Calling r0-r12 */ |
| 618 | add r8, sp, #S_PC |
| 619 | |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 620 | #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 621 | ldr r2, _armboot_start |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 622 | sub r2, r2, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN) |
| 623 | sub r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ set base 2 words into abort stack |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 624 | #else |
| 625 | ldr r2, IRQ_STACK_START_IN |
| 626 | #endif |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 627 | ldmia r2, {r2 - r4} /* get pc, cpsr, old_r0 */ |
| 628 | add r0, sp, #S_FRAME_SIZE /* restore sp_SVC */ |
| 629 | |
| 630 | add r5, sp, #S_SP |
| 631 | mov r1, lr |
| 632 | stmia r5, {r0 - r4} /* save sp_SVC, lr_SVC, pc, cpsr, old_r */ |
| 633 | mov r0, sp |
| 634 | .endm |
| 635 | |
| 636 | |
| 637 | /* use irq_save_user_regs / irq_restore_user_regs for */ |
| 638 | /* IRQ/FIQ handling */ |
| 639 | |
| 640 | .macro irq_save_user_regs |
| 641 | sub sp, sp, #S_FRAME_SIZE |
| 642 | stmia sp, {r0 - r12} /* Calling r0-r12 */ |
| 643 | add r8, sp, #S_PC |
| 644 | stmdb r8, {sp, lr}^ /* Calling SP, LR */ |
| 645 | str lr, [r8, #0] /* Save calling PC */ |
| 646 | mrs r6, spsr |
| 647 | str r6, [r8, #4] /* Save CPSR */ |
| 648 | str r0, [r8, #8] /* Save OLD_R0 */ |
| 649 | mov r0, sp |
| 650 | .endm |
| 651 | |
| 652 | .macro irq_restore_user_regs |
| 653 | ldmia sp, {r0 - lr}^ @ Calling r0 - lr |
| 654 | mov r0, r0 |
| 655 | ldr lr, [sp, #S_PC] @ Get PC |
| 656 | add sp, sp, #S_FRAME_SIZE |
| 657 | subs pc, lr, #4 @ return & move spsr_svc into cpsr |
| 658 | .endm |
| 659 | |
| 660 | .macro get_bad_stack |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 661 | #if defined(CONFIG_SYS_ARM_WITHOUT_RELOC) |
wdenk | f6e20fc | 2004-02-08 19:38:38 +0000 | [diff] [blame] | 662 | ldr r13, _armboot_start @ setup our mode stack |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 663 | sub r13, r13, #(CONFIG_STACKSIZE+CONFIG_SYS_MALLOC_LEN) |
| 664 | sub r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack |
Heiko Schocher | 2af0a09 | 2010-09-17 13:10:47 +0200 | [diff] [blame] | 665 | #else |
| 666 | ldr r13, IRQ_STACK_START_IN @ setup our mode stack |
| 667 | #endif |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 668 | |
| 669 | str lr, [r13] @ save caller lr / spsr |
| 670 | mrs lr, spsr |
| 671 | str lr, [r13, #4] |
| 672 | |
| 673 | mov r13, #MODE_SVC @ prepare SVC-Mode |
| 674 | msr spsr_c, r13 |
| 675 | mov lr, pc |
| 676 | movs pc, lr |
| 677 | .endm |
| 678 | |
| 679 | .macro get_irq_stack @ setup IRQ stack |
| 680 | ldr sp, IRQ_STACK_START |
| 681 | .endm |
| 682 | |
| 683 | .macro get_fiq_stack @ setup FIQ stack |
| 684 | ldr sp, FIQ_STACK_START |
| 685 | .endm |
| 686 | |
| 687 | |
| 688 | /****************************************************************************/ |
| 689 | /* */ |
| 690 | /* exception handlers */ |
| 691 | /* */ |
| 692 | /****************************************************************************/ |
| 693 | |
| 694 | .align 5 |
| 695 | undefined_instruction: |
| 696 | get_bad_stack |
| 697 | bad_save_user_regs |
| 698 | bl do_undefined_instruction |
| 699 | |
| 700 | .align 5 |
| 701 | software_interrupt: |
| 702 | get_bad_stack |
| 703 | bad_save_user_regs |
| 704 | bl do_software_interrupt |
| 705 | |
| 706 | .align 5 |
| 707 | prefetch_abort: |
| 708 | get_bad_stack |
| 709 | bad_save_user_regs |
| 710 | bl do_prefetch_abort |
| 711 | |
| 712 | .align 5 |
| 713 | data_abort: |
| 714 | get_bad_stack |
| 715 | bad_save_user_regs |
| 716 | bl do_data_abort |
| 717 | |
| 718 | .align 5 |
| 719 | not_used: |
| 720 | get_bad_stack |
| 721 | bad_save_user_regs |
| 722 | bl do_not_used |
| 723 | |
| 724 | #ifdef CONFIG_USE_IRQ |
| 725 | |
| 726 | .align 5 |
| 727 | irq: |
| 728 | get_irq_stack |
| 729 | irq_save_user_regs |
| 730 | bl do_irq |
| 731 | irq_restore_user_regs |
| 732 | |
| 733 | .align 5 |
| 734 | fiq: |
| 735 | get_fiq_stack |
| 736 | irq_save_user_regs /* someone ought to write a more */ |
| 737 | bl do_fiq /* effiction fiq_save_user_regs */ |
| 738 | irq_restore_user_regs |
| 739 | |
| 740 | #else |
| 741 | |
| 742 | .align 5 |
| 743 | irq: |
| 744 | get_bad_stack |
| 745 | bad_save_user_regs |
| 746 | bl do_irq |
| 747 | |
| 748 | .align 5 |
| 749 | fiq: |
| 750 | get_bad_stack |
| 751 | bad_save_user_regs |
| 752 | bl do_fiq |
| 753 | |
| 754 | #endif |
| 755 | |
| 756 | /****************************************************************************/ |
| 757 | /* */ |
| 758 | /* Reset function: Use Watchdog to reset */ |
| 759 | /* */ |
| 760 | /****************************************************************************/ |
| 761 | |
| 762 | .align 5 |
| 763 | .globl reset_cpu |
| 764 | |
| 765 | reset_cpu: |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 766 | ldr r1, =0x482e |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 767 | ldr r2, =IXP425_OSWK |
| 768 | str r1, [r2] |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 769 | ldr r1, =0x0fff |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 770 | ldr r2, =IXP425_OSWT |
| 771 | str r1, [r2] |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 772 | ldr r1, =0x5 |
wdenk | 2d5b561 | 2003-10-14 19:43:55 +0000 | [diff] [blame] | 773 | ldr r2, =IXP425_OSWE |
| 774 | str r1, [r2] |
| 775 | b reset_endless |
| 776 | |
| 777 | |
| 778 | reset_endless: |
| 779 | |
| 780 | b reset_endless |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 781 | |
| 782 | #ifdef CONFIG_USE_IRQ |
| 783 | |
| 784 | .LC0: .word loops_per_jiffy |
| 785 | |
| 786 | /* |
| 787 | * 0 <= r0 <= 2000 |
| 788 | */ |
Ingo van Lil | 3eb90ba | 2009-11-24 14:09:21 +0100 | [diff] [blame] | 789 | .globl __udelay |
| 790 | __udelay: |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 791 | mov r2, #0x6800 |
| 792 | orr r2, r2, #0x00db |
| 793 | mul r0, r2, r0 |
| 794 | ldr r2, .LC0 |
| 795 | ldr r2, [r2] @ max = 0x0fffffff |
| 796 | mov r0, r0, lsr #11 @ max = 0x00003fff |
| 797 | mov r2, r2, lsr #11 @ max = 0x0003ffff |
| 798 | mul r0, r2, r0 @ max = 2^32-1 |
| 799 | movs r0, r0, lsr #6 |
| 800 | |
| 801 | delay_loop: |
| 802 | subs r0, r0, #1 |
| 803 | bne delay_loop |
| 804 | mov pc, lr |
| 805 | |
| 806 | #endif /* CONFIG_USE_IRQ */ |