]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/ixp/start.S
Merge branch 'for-wd-master' of git://git.denx.de/u-boot-pxa
[karo-tx-uboot.git] / arch / arm / cpu / ixp / start.S
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 <asm-offsets.h>
31 #include <config.h>
32 #include <version.h>
33 #include <asm/arch/ixp425.h>
34
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 */
47 #define MMU_Control_Init (MMU_Control_P|MMU_Control_D|MMU_Control_L)
48
49
50 /*
51  * Macro definitions
52  */
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
59
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
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
97 .globl _TEXT_BASE
98 _TEXT_BASE:
99         .word   CONFIG_SYS_TEXT_BASE
100
101 /*
102  * These are defined in the board-specific linker script.
103  */
104 .globl _bss_start
105 _bss_start:
106         .word __bss_start
107
108 .globl _bss_end
109 _bss_end:
110         .word _end
111
112 #ifdef CONFIG_USE_IRQ
113 /* IRQ stack memory (calculated at run-time) */
114 .globl IRQ_STACK_START
115 IRQ_STACK_START:
116         .word   0x0badc0de
117
118 /* IRQ stack memory (calculated at run-time) */
119 .globl FIQ_STACK_START
120 FIQ_STACK_START:
121         .word 0x0badc0de
122 #endif
123
124 /* IRQ stack memory (calculated at run-time) + 8 bytes */
125 .globl IRQ_STACK_START_IN
126 IRQ_STACK_START_IN:
127         .word   0x0badc0de
128
129 .globl _datarel_start
130 _datarel_start:
131         .word __datarel_start
132
133 .globl _datarelrolocal_start
134 _datarelrolocal_start:
135         .word __datarelrolocal_start
136
137 .globl _datarellocal_start
138 _datarellocal_start:
139         .word __datarellocal_start
140
141 .globl _datarelro_start
142 _datarelro_start:
143         .word __datarelro_start
144
145 .globl _got_start
146 _got_start:
147         .word __got_start
148
149 .globl _got_end
150 _got_end:
151         .word __got_end
152
153 /*
154  * the actual reset code
155  */
156
157 reset:
158         /* disable mmu, set big-endian */
159         mov     r0, #0xf8
160         mcr     p15, 0, r0, c1, c0, 0
161         CPWAIT  r0
162
163         /* invalidate I & D caches & BTB */
164         mcr     p15, 0, r0, c7, c7, 0
165         CPWAIT  r0
166
167         /* invalidate I & Data TLB */
168         mcr     p15, 0, r0, c8, c7, 0
169         CPWAIT r0
170
171         /* drain write and fill buffers */
172         mcr     p15, 0, r0, c7, c10, 4
173         CPWAIT  r0
174
175         /* disable write buffer coalescing */
176         mrc     p15, 0, r0, c1, c0, 1
177         orr     r0, r0, #1
178         mcr     p15, 0, r0, c1, c0, 1
179         CPWAIT  r0
180
181         /* set EXP CS0 to the optimum timing */
182         ldr     r1, =CONFIG_SYS_EXP_CS0
183         ldr     r2, =IXP425_EXP_CS0
184         str     r1, [r2]
185
186         /* make sure flash is visible at 0 */
187 #if 0
188         ldr     r2, =IXP425_EXP_CFG0
189         ldr     r1, [r2]
190         orr     r1, r1, #0x80000000
191         str     r1, [r2]
192 #endif
193         mov     r1, #CONFIG_SYS_SDR_CONFIG
194         ldr     r2, =IXP425_SDR_CONFIG
195         str     r1, [r2]
196
197         /* disable refresh cycles */
198         mov     r1, #0
199         ldr     r3, =IXP425_SDR_REFRESH
200         str     r1, [r3]
201
202         /* send nop command */
203         mov     r1, #3
204         ldr     r4, =IXP425_SDR_IR
205         str     r1, [r4]
206         DELAY_FOR 0x4000, r0
207
208         /* set SDRAM internal refresh val */
209         ldr     r1, =CONFIG_SYS_SDRAM_REFRESH_CNT
210         str     r1, [r3]
211         DELAY_FOR 0x4000, r0
212
213         /* send precharge-all command to close all open banks */
214         mov     r1, #2
215         str     r1, [r4]
216         DELAY_FOR 0x4000, r0
217
218         /* provide 8 auto-refresh cycles */
219         mov     r1, #4
220         mov     r5, #8
221 111:    str     r1, [r4]
222         DELAY_FOR 0x100, r0
223         subs    r5, r5, #1
224         bne     111b
225
226         /* set mode register in sdram */
227         mov     r1, #CONFIG_SYS_SDR_MODE_CONFIG
228         str     r1, [r4]
229         DELAY_FOR 0x4000, r0
230
231         /* send normal operation command */
232         mov     r1, #6
233         str     r1, [r4]
234         DELAY_FOR 0x4000, r0
235
236         /* copy */
237         mov     r0, #0
238         mov     r4, r0
239         add     r2, r0, #CONFIG_SYS_MONITOR_LEN
240         mov     r1, #0x10000000
241         mov     r5, r1
242
243     30:
244         ldr     r3, [r0], #4
245         str     r3, [r1], #4
246         cmp     r0, r2
247         bne     30b
248
249         /* invalidate I & D caches & BTB */
250         mcr     p15, 0, r0, c7, c7, 0
251         CPWAIT  r0
252
253         /* invalidate I & Data TLB */
254         mcr     p15, 0, r0, c8, c7, 0
255         CPWAIT r0
256
257         /* drain write and fill buffers */
258         mcr     p15, 0, r0, c7, c10, 4
259         CPWAIT  r0
260
261         /* move flash to 0x50000000 */
262         ldr     r2, =IXP425_EXP_CFG0
263         ldr     r1, [r2]
264         bic     r1, r1, #0x80000000
265         str     r1, [r2]
266
267         nop
268         nop
269         nop
270         nop
271         nop
272         nop
273
274         /* invalidate I & Data TLB */
275         mcr     p15, 0, r0, c8, c7, 0
276         CPWAIT r0
277
278         /* enable I cache */
279         mrc     p15, 0, r0, c1, c0, 0
280         orr     r0, r0, #MMU_Control_I
281         mcr     p15, 0, r0, c1, c0, 0
282         CPWAIT  r0
283
284         mrs     r0,cpsr                 /* set the cpu to SVC32 mode        */
285         bic     r0,r0,#0x1f             /* (superviser mode, M=10011)       */
286         orr     r0,r0,#0x13
287         msr     cpsr,r0
288
289 /* Set stackpointer in internal RAM to call board_init_f */
290 call_board_init_f:
291         ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
292         ldr     r0,=0x00000000
293         bl      board_init_f
294
295 /*------------------------------------------------------------------------------*/
296
297 /*
298  * void relocate_code (addr_sp, gd, addr_moni)
299  *
300  * This "function" does not return, instead it continues in RAM
301  * after relocating the monitor code.
302  *
303  */
304         .globl  relocate_code
305 relocate_code:
306         mov     r4, r0  /* save addr_sp */
307         mov     r5, r1  /* save addr of gd */
308         mov     r6, r2  /* save addr of destination */
309         mov     r7, r2  /* save addr of destination */
310
311         /* Set up the stack                                                 */
312 stack_setup:
313         mov     sp, r4
314
315         adr     r0, _start
316         ldr     r2, _TEXT_BASE
317         ldr     r3, _bss_start
318         sub     r2, r3, r2              /* r2 <- size of armboot            */
319         add     r2, r0, r2              /* r2 <- source end address         */
320         cmp     r0, r6
321         beq     clear_bss
322
323 copy_loop:
324         ldmia   r0!, {r9-r10}           /* copy from source address [r0]    */
325         stmia   r6!, {r9-r10}           /* copy to   target address [r1]    */
326         cmp     r0, r2                  /* until source end address [r2]    */
327         blo     copy_loop
328
329 #ifndef CONFIG_PRELOADER
330         /* fix got entries */
331         ldr     r1, _TEXT_BASE          /* Text base */
332         mov     r0, r7                  /* reloc addr */
333         ldr     r2, _got_start          /* addr in Flash */
334         ldr     r3, _got_end            /* addr in Flash */
335         sub     r3, r3, r1
336         add     r3, r3, r0
337         sub     r2, r2, r1
338         add     r2, r2, r0
339
340 fixloop:
341         ldr     r4, [r2]
342         sub     r4, r4, r1
343         add     r4, r4, r0
344         str     r4, [r2]
345         add     r2, r2, #4
346         cmp     r2, r3
347         blo     fixloop
348 #endif
349
350 clear_bss:
351 #ifndef CONFIG_PRELOADER
352         ldr     r0, _bss_start
353         ldr     r1, _bss_end
354         ldr     r3, _TEXT_BASE          /* Text base */
355         mov     r4, r7                  /* reloc addr */
356         sub     r0, r0, r3
357         add     r0, r0, r4
358         sub     r1, r1, r3
359         add     r1, r1, r4
360         mov     r2, #0x00000000         /* clear                            */
361
362 clbss_l:str     r2, [r0]                /* clear loop...                    */
363         add     r0, r0, #4
364         cmp     r0, r1
365         bne     clbss_l
366
367         bl coloured_LED_init
368         bl red_LED_on
369 #endif
370
371 /*
372  * We are done. Do not return, instead branch to second part of board
373  * initialization, now running from RAM.
374  */
375         ldr     r0, _TEXT_BASE
376         ldr     r2, _board_init_r
377         sub     r2, r2, r0
378         add     r2, r2, r7      /* position from board_init_r in RAM */
379         /* setup parameters for board_init_r */
380         mov     r0, r5          /* gd_t */
381         mov     r1, r7          /* dest_addr */
382         /* jump to it ... */
383         mov     lr, r2
384         mov     pc, lr
385
386 _board_init_r: .word board_init_r
387
388
389 /****************************************************************************/
390 /*                                                                          */
391 /* Interrupt handling                                                       */
392 /*                                                                          */
393 /****************************************************************************/
394
395 /* IRQ stack frame                                                          */
396
397 #define S_FRAME_SIZE    72
398
399 #define S_OLD_R0        68
400 #define S_PSR           64
401 #define S_PC            60
402 #define S_LR            56
403 #define S_SP            52
404
405 #define S_IP            48
406 #define S_FP            44
407 #define S_R10           40
408 #define S_R9            36
409 #define S_R8            32
410 #define S_R7            28
411 #define S_R6            24
412 #define S_R5            20
413 #define S_R4            16
414 #define S_R3            12
415 #define S_R2            8
416 #define S_R1            4
417 #define S_R0            0
418
419 #define MODE_SVC 0x13
420
421         /* use bad_save_user_regs for abort/prefetch/undef/swi ...          */
422
423         .macro  bad_save_user_regs
424         sub     sp, sp, #S_FRAME_SIZE
425         stmia   sp, {r0 - r12}                  /* Calling r0-r12           */
426         add     r8, sp, #S_PC
427
428         ldr     r2, IRQ_STACK_START_IN
429         ldmia   r2, {r2 - r4}                   /* get pc, cpsr, old_r0     */
430         add     r0, sp, #S_FRAME_SIZE           /* restore sp_SVC           */
431
432         add     r5, sp, #S_SP
433         mov     r1, lr
434         stmia   r5, {r0 - r4}                   /* save sp_SVC, lr_SVC, pc, cpsr, old_r */
435         mov     r0, sp
436         .endm
437
438
439         /* use irq_save_user_regs / irq_restore_user_regs for                */
440         /* IRQ/FIQ handling                                                  */
441
442         .macro  irq_save_user_regs
443         sub     sp, sp, #S_FRAME_SIZE
444         stmia   sp, {r0 - r12}                  /* Calling r0-r12            */
445         add     r8, sp, #S_PC
446         stmdb   r8, {sp, lr}^                   /* Calling SP, LR            */
447         str     lr, [r8, #0]                    /* Save calling PC           */
448         mrs     r6, spsr
449         str     r6, [r8, #4]                    /* Save CPSR                 */
450         str     r0, [r8, #8]                    /* Save OLD_R0               */
451         mov     r0, sp
452         .endm
453
454         .macro  irq_restore_user_regs
455         ldmia   sp, {r0 - lr}^                  @ Calling r0 - lr
456         mov     r0, r0
457         ldr     lr, [sp, #S_PC]                 @ Get PC
458         add     sp, sp, #S_FRAME_SIZE
459         subs    pc, lr, #4                      @ return & move spsr_svc into cpsr
460         .endm
461
462         .macro get_bad_stack
463         ldr     r13, IRQ_STACK_START_IN         @ setup our mode stack
464
465         str     lr, [r13]                       @ save caller lr / spsr
466         mrs     lr, spsr
467         str     lr, [r13, #4]
468
469         mov     r13, #MODE_SVC                  @ prepare SVC-Mode
470         msr     spsr_c, r13
471         mov     lr, pc
472         movs    pc, lr
473         .endm
474
475         .macro get_irq_stack                    @ setup IRQ stack
476         ldr     sp, IRQ_STACK_START
477         .endm
478
479         .macro get_fiq_stack                    @ setup FIQ stack
480         ldr     sp, FIQ_STACK_START
481         .endm
482
483
484 /****************************************************************************/
485 /*                                                                          */
486 /* exception handlers                                                       */
487 /*                                                                          */
488 /****************************************************************************/
489
490         .align  5
491 undefined_instruction:
492         get_bad_stack
493         bad_save_user_regs
494         bl      do_undefined_instruction
495
496         .align  5
497 software_interrupt:
498         get_bad_stack
499         bad_save_user_regs
500         bl      do_software_interrupt
501
502         .align  5
503 prefetch_abort:
504         get_bad_stack
505         bad_save_user_regs
506         bl      do_prefetch_abort
507
508         .align  5
509 data_abort:
510         get_bad_stack
511         bad_save_user_regs
512         bl      do_data_abort
513
514         .align  5
515 not_used:
516         get_bad_stack
517         bad_save_user_regs
518         bl      do_not_used
519
520 #ifdef CONFIG_USE_IRQ
521
522         .align  5
523 irq:
524         get_irq_stack
525         irq_save_user_regs
526         bl      do_irq
527         irq_restore_user_regs
528
529         .align  5
530 fiq:
531         get_fiq_stack
532         irq_save_user_regs              /* someone ought to write a more    */
533         bl      do_fiq                  /* effiction fiq_save_user_regs     */
534         irq_restore_user_regs
535
536 #else
537
538         .align  5
539 irq:
540         get_bad_stack
541         bad_save_user_regs
542         bl      do_irq
543
544         .align  5
545 fiq:
546         get_bad_stack
547         bad_save_user_regs
548         bl      do_fiq
549
550 #endif
551
552 /****************************************************************************/
553 /*                                                                          */
554 /* Reset function: Use Watchdog to reset                                    */
555 /*                                                                          */
556 /****************************************************************************/
557
558         .align  5
559 .globl reset_cpu
560
561 reset_cpu:
562         ldr     r1, =0x482e
563         ldr     r2, =IXP425_OSWK
564         str     r1, [r2]
565         ldr     r1, =0x0fff
566         ldr     r2, =IXP425_OSWT
567         str     r1, [r2]
568         ldr     r1, =0x5
569         ldr     r2, =IXP425_OSWE
570         str     r1, [r2]
571         b       reset_endless
572
573
574 reset_endless:
575
576         b       reset_endless
577
578 #ifdef CONFIG_USE_IRQ
579
580 .LC0:           .word   loops_per_jiffy
581
582 /*
583  * 0 <= r0 <= 2000
584  */
585 .globl __udelay
586 __udelay:
587         mov     r2,     #0x6800
588         orr     r2, r2, #0x00db
589         mul     r0, r2, r0
590         ldr     r2, .LC0
591         ldr     r2, [r2]                @ max = 0x0fffffff
592         mov     r0, r0, lsr #11         @ max = 0x00003fff
593         mov     r2, r2, lsr #11         @ max = 0x0003ffff
594         mul     r0, r2, r0              @ max = 2^32-1
595         movs    r0, r0, lsr #6
596
597 delay_loop:
598         subs    r0, r0, #1
599         bne     delay_loop
600         mov     pc, lr
601
602 #endif /* CONFIG_USE_IRQ */