blob: 940d45d7328cd570f37747a81828be190dccef5b [file] [log] [blame]
wdenk2d5b5612003-10-14 19:43:55 +00001/* 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
wdenk42d1f032003-10-15 23:53:47 +000034#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 */
wdenk2d5b5612003-10-14 19:43:55 +000046#define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L)
47
48
49/*
50 * Macro definitions
51 */
wdenk42d1f032003-10-15 23:53:47 +000052 /* 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
wdenk2d5b5612003-10-14 19:43:55 +000058
wdenk42d1f032003-10-15 23:53:47 +000059 /* 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
wdenk2d5b5612003-10-14 19:43:55 +000065
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 Schocher2af0a092010-09-17 13:10:47 +020096.globl _TEXT_BASE
wdenk2d5b5612003-10-14 19:43:55 +000097_TEXT_BASE:
98 .word TEXT_BASE
99
Heiko Schocher2af0a092010-09-17 13:10:47 +0200100#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
wdenk2d5b5612003-10-14 19:43:55 +0000101.globl _armboot_start
102_armboot_start:
103 .word _start
Heiko Schocher2af0a092010-09-17 13:10:47 +0200104#endif
wdenk2d5b5612003-10-14 19:43:55 +0000105
106/*
wdenkf6e20fc2004-02-08 19:38:38 +0000107 * These are defined in the board-specific linker script.
wdenk2d5b5612003-10-14 19:43:55 +0000108 */
109.globl _bss_start
110_bss_start:
wdenkf6e20fc2004-02-08 19:38:38 +0000111 .word __bss_start
wdenk2d5b5612003-10-14 19:43:55 +0000112
113.globl _bss_end
114_bss_end:
wdenkf6e20fc2004-02-08 19:38:38 +0000115 .word _end
wdenk2d5b5612003-10-14 19:43:55 +0000116
117#ifdef CONFIG_USE_IRQ
118/* IRQ stack memory (calculated at run-time) */
119.globl IRQ_STACK_START
120IRQ_STACK_START:
121 .word 0x0badc0de
122
123/* IRQ stack memory (calculated at run-time) */
124.globl FIQ_STACK_START
125FIQ_STACK_START:
126 .word 0x0badc0de
127#endif
128
Heiko Schocher2af0a092010-09-17 13:10:47 +0200129#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
130/* IRQ stack memory (calculated at run-time) + 8 bytes */
131.globl IRQ_STACK_START_IN
132IRQ_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
163reset:
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
227111: 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 */
296call_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
311relocate_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 */
318stack_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
330copy_loop:
331 ldmia r0!, {r9-r10} /* copy from source address [r0] */
332 stmia r6!, {r9-r10} /* copy to target address [r1] */
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200333 cmp r0, r2 /* until source end address [r2] */
334 blo copy_loop
Heiko Schocher2af0a092010-09-17 13:10:47 +0200335
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
347fixloop:
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
358clear_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
370clbss_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) */
wdenk2d5b5612003-10-14 19:43:55 +0000397/****************************************************************************/
398/* */
399/* the actual reset code */
400/* */
401/****************************************************************************/
402
403reset:
404 /* disable mmu, set big-endian */
405 mov r0, #0xf8
406 mcr p15, 0, r0, c1, c0, 0
wdenk42d1f032003-10-15 23:53:47 +0000407 CPWAIT r0
wdenk2d5b5612003-10-14 19:43:55 +0000408
409 /* invalidate I & D caches & BTB */
410 mcr p15, 0, r0, c7, c7, 0
411 CPWAIT r0
412
413 /* invalidate I & Data TLB */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200414 mcr p15, 0, r0, c8, c7, 0
wdenk42d1f032003-10-15 23:53:47 +0000415 CPWAIT r0
wdenk2d5b5612003-10-14 19:43:55 +0000416
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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200428 ldr r1, =CONFIG_SYS_EXP_CS0
wdenk2d5b5612003-10-14 19:43:55 +0000429 ldr r2, =IXP425_EXP_CS0
430 str r1, [r2]
431
wdenk42d1f032003-10-15 23:53:47 +0000432 /* make sure flash is visible at 0 */
wdenka1191902005-01-09 17:12:27 +0000433#if 0
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200434 ldr r2, =IXP425_EXP_CFG0
wdenk2d5b5612003-10-14 19:43:55 +0000435 ldr r1, [r2]
436 orr r1, r1, #0x80000000
437 str r1, [r2]
wdenka1191902005-01-09 17:12:27 +0000438#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200439 mov r1, #CONFIG_SYS_SDR_CONFIG
wdenk2d5b5612003-10-14 19:43:55 +0000440 ldr r2, =IXP425_SDR_CONFIG
441 str r1, [r2]
442
443 /* disable refresh cycles */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200444 mov r1, #0
wdenk2d5b5612003-10-14 19:43:55 +0000445 ldr r3, =IXP425_SDR_REFRESH
446 str r1, [r3]
447
448 /* send nop command */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200449 mov r1, #3
wdenk2d5b5612003-10-14 19:43:55 +0000450 ldr r4, =IXP425_SDR_IR
451 str r1, [r4]
wdenk42d1f032003-10-15 23:53:47 +0000452 DELAY_FOR 0x4000, r0
wdenk2d5b5612003-10-14 19:43:55 +0000453
454 /* set SDRAM internal refresh val */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200455 ldr r1, =CONFIG_SYS_SDRAM_REFRESH_CNT
wdenk2d5b5612003-10-14 19:43:55 +0000456 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
467111: 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-VILLARD6d0f6bc2008-10-16 15:01:15 +0200473 mov r1, #CONFIG_SYS_SDR_MODE_CONFIG
wdenk2d5b5612003-10-14 19:43:55 +0000474 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 */
wdenk42d1f032003-10-15 23:53:47 +0000483 mov r0, #0
484 mov r4, r0
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200485 add r2, r0, #CONFIG_SYS_MONITOR_LEN
wdenk2d5b5612003-10-14 19:43:55 +0000486 mov r1, #0x10000000
wdenk42d1f032003-10-15 23:53:47 +0000487 mov r5, r1
wdenk2d5b5612003-10-14 19:43:55 +0000488
489 30:
wdenk42d1f032003-10-15 23:53:47 +0000490 ldr r3, [r0], #4
491 str r3, [r1], #4
492 cmp r0, r2
493 bne 30b
wdenk2d5b5612003-10-14 19:43:55 +0000494
495 /* invalidate I & D caches & BTB */
496 mcr p15, 0, r0, c7, c7, 0
497 CPWAIT r0
498
499 /* invalidate I & Data TLB */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200500 mcr p15, 0, r0, c8, c7, 0
wdenk42d1f032003-10-15 23:53:47 +0000501 CPWAIT r0
wdenk2d5b5612003-10-14 19:43:55 +0000502
503 /* drain write and fill buffers */
504 mcr p15, 0, r0, c7, c10, 4
505 CPWAIT r0
506
wdenk42d1f032003-10-15 23:53:47 +0000507 /* move flash to 0x50000000 */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200508 ldr r2, =IXP425_EXP_CFG0
wdenk2d5b5612003-10-14 19:43:55 +0000509 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 Denk53677ef2008-05-20 16:00:29 +0200521 mcr p15, 0, r0, c8, c7, 0
wdenk42d1f032003-10-15 23:53:47 +0000522 CPWAIT r0
wdenk2d5b5612003-10-14 19:43:55 +0000523
wdenk42d1f032003-10-15 23:53:47 +0000524 /* 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
wdenk2d5b5612003-10-14 19:43:55 +0000529
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
wdenk8aa1a2d2005-04-04 12:44:11 +0000535#ifndef CONFIG_SKIP_RELOCATE_UBOOT
wdenk2d5b5612003-10-14 19:43:55 +0000536relocate: /* 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
wdenkf6e20fc2004-02-08 19:38:38 +0000543 ldr r3, _bss_start
wdenk2d5b5612003-10-14 19:43:55 +0000544 sub r2, r3, r2 /* r2 <- size of armboot */
545 add r2, r0, r2 /* r2 <- source end address */
546
547copy_loop:
548 ldmia r0!, {r3-r10} /* copy from source address [r0] */
549 stmia r1!, {r3-r10} /* copy to target address [r1] */
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200550 cmp r0, r2 /* until source end address [r2] */
551 blo copy_loop
wdenk8aa1a2d2005-04-04 12:44:11 +0000552#endif /* CONFIG_SKIP_RELOCATE_UBOOT */
wdenk2d5b5612003-10-14 19:43:55 +0000553
554 /* Set up the stack */
wdenk2d5b5612003-10-14 19:43:55 +0000555stack_setup:
wdenkf6e20fc2004-02-08 19:38:38 +0000556 ldr r0, _TEXT_BASE /* upper 128 KiB: relocated uboot */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200557 sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
558 sub r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo */
wdenkf6e20fc2004-02-08 19:38:38 +0000559#ifdef CONFIG_USE_IRQ
560 sub r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
561#endif
wdenk2d5b5612003-10-14 19:43:55 +0000562 sub sp, r0, #12 /* leave 3 words for abort-stack */
Vitaly Kuzmichev1a27f7d2010-06-15 22:18:11 +0400563 bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
wdenk2d5b5612003-10-14 19:43:55 +0000564
565clear_bss:
wdenk2d5b5612003-10-14 19:43:55 +0000566 ldr r0, _bss_start /* find start of bss segment */
wdenk2d5b5612003-10-14 19:43:55 +0000567 ldr r1, _bss_end /* stop here */
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200568 mov r2, #0x00000000 /* clear */
wdenk2d5b5612003-10-14 19:43:55 +0000569
570clbss_l:str r2, [r0] /* clear loop... */
571 add r0, r0, #4
572 cmp r0, r1
Albert Aribaudda90d4c2010-10-05 16:06:39 +0200573 blo clbss_l
wdenk2d5b5612003-10-14 19:43:55 +0000574
wdenk2d5b5612003-10-14 19:43:55 +0000575 ldr pc, _start_armboot
576
577_start_armboot: .word start_armboot
Heiko Schocher2af0a092010-09-17 13:10:47 +0200578#endif /* #if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC) */
wdenk2d5b5612003-10-14 19:43:55 +0000579
580
wdenk2d5b5612003-10-14 19:43:55 +0000581/****************************************************************************/
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 Schocher2af0a092010-09-17 13:10:47 +0200620#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
wdenkf6e20fc2004-02-08 19:38:38 +0000621 ldr r2, _armboot_start
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200622 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 Schocher2af0a092010-09-17 13:10:47 +0200624#else
625 ldr r2, IRQ_STACK_START_IN
626#endif
wdenk2d5b5612003-10-14 19:43:55 +0000627 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 Schocher2af0a092010-09-17 13:10:47 +0200661#if defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
wdenkf6e20fc2004-02-08 19:38:38 +0000662 ldr r13, _armboot_start @ setup our mode stack
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200663 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 Schocher2af0a092010-09-17 13:10:47 +0200665#else
666 ldr r13, IRQ_STACK_START_IN @ setup our mode stack
667#endif
wdenk2d5b5612003-10-14 19:43:55 +0000668
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
695undefined_instruction:
696 get_bad_stack
697 bad_save_user_regs
698 bl do_undefined_instruction
699
700 .align 5
701software_interrupt:
702 get_bad_stack
703 bad_save_user_regs
704 bl do_software_interrupt
705
706 .align 5
707prefetch_abort:
708 get_bad_stack
709 bad_save_user_regs
710 bl do_prefetch_abort
711
712 .align 5
713data_abort:
714 get_bad_stack
715 bad_save_user_regs
716 bl do_data_abort
717
718 .align 5
719not_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
727irq:
728 get_irq_stack
729 irq_save_user_regs
730 bl do_irq
731 irq_restore_user_regs
732
733 .align 5
734fiq:
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
743irq:
744 get_bad_stack
745 bad_save_user_regs
746 bl do_irq
747
748 .align 5
749fiq:
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
765reset_cpu:
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200766 ldr r1, =0x482e
wdenk2d5b5612003-10-14 19:43:55 +0000767 ldr r2, =IXP425_OSWK
768 str r1, [r2]
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200769 ldr r1, =0x0fff
wdenk2d5b5612003-10-14 19:43:55 +0000770 ldr r2, =IXP425_OSWT
771 str r1, [r2]
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200772 ldr r1, =0x5
wdenk2d5b5612003-10-14 19:43:55 +0000773 ldr r2, =IXP425_OSWE
774 str r1, [r2]
775 b reset_endless
776
777
778reset_endless:
779
780 b reset_endless
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200781
782#ifdef CONFIG_USE_IRQ
783
784.LC0: .word loops_per_jiffy
785
786/*
787 * 0 <= r0 <= 2000
788 */
Ingo van Lil3eb90ba2009-11-24 14:09:21 +0100789.globl __udelay
790__udelay:
Wolfgang Denkba94a1b2006-05-30 15:56:48 +0200791 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
801delay_loop:
802 subs r0, r0, #1
803 bne delay_loop
804 mov pc, lr
805
806#endif /* CONFIG_USE_IRQ */