]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/arm1136/start.S
imported Freescale specific U-Boot additions for i.MX28,... release L2.6.31_10.08.01
[karo-tx-uboot.git] / cpu / arm1136 / start.S
1 /*
2  *  armboot - Startup Code for OMP2420/ARM1136 CPU-core
3  *
4  *  Copyright (c) 2004  Texas Instruments <r-woodruff2@ti.com>
5  *
6  *  Copyright (c) 2001  Marius Gröger <mag@sysgo.de>
7  *  Copyright (c) 2002  Alex Züpke <azu@sysgo.de>
8  *  Copyright (c) 2002  Gary Jennejohn <garyj@denx.de>
9  *  Copyright (c) 2003  Richard Woodruff <r-woodruff2@ti.com>
10  *  Copyright (c) 2003  Kshitij <kshitij@ti.com>
11  *
12  * See file CREDITS for list of people who contributed to this
13  * project.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License as
17  * published by the Free Software Foundation; either version 2 of
18  * the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28  * MA 02111-1307 USA
29  */
30
31 #include <config.h>
32 #include <version.h>
33
34 .section ".text.head", "ax"
35 .globl _start
36 _start:
37 .section ".text.vect", "ax"
38 .global _start_vect
39 _start_vect:
40 #ifdef CONFIG_PRELOADER
41         b       reset
42         ldr     pc, _hang
43         ldr     pc, _hang
44         ldr     pc, _hang
45         ldr     pc, _hang
46         ldr     pc, _hang
47         ldr     pc, _hang
48         ldr     pc, _hang
49
50 _hang:
51         .word   do_hang
52         .word   0x12345678
53         .word   0x12345678
54         .word   0x12345678
55         .word   0x12345678
56         .word   0x12345678
57         .word   0x12345678
58         .word   0x12345678      /* now 16*4=64 */
59 #else
60         ldr     pc, _undefined_instruction
61         ldr     pc, _software_interrupt
62         ldr     pc, _prefetch_abort
63         ldr     pc, _data_abort
64         ldr     pc, _not_used
65         ldr     pc, _irq
66         ldr     pc, _fiq
67
68 _undefined_instruction: .word undefined_instruction
69 _software_interrupt:    .word software_interrupt
70 _prefetch_abort:        .word prefetch_abort
71 _data_abort:            .word data_abort
72 _not_used:              .word not_used
73 _irq:                   .word irq
74 _fiq:                   .word fiq
75 _pad:                   .word 0x12345678 /* now 16*4=64 */
76 #endif  /* CONFIG_PRELOADER */
77 .global _end_vect
78 _end_vect:
79
80         .balignl 16,0xdeadbeef
81 /*
82  *************************************************************************
83  *
84  * Startup Code (reset vector)
85  *
86  * do important init only if we don't start from memory!
87  * setup Memory and board specific bits prior to relocation.
88  * relocate armboot to ram
89  * setup stack
90  *
91  *************************************************************************
92  */
93
94 /*
95  * the actual reset code
96  */
97
98 .section ".text.head", "ax"
99 .globl reset
100 reset:
101         /*
102          * set the cpu to SVC32 mode
103          */
104         mrs     r0,cpsr
105         bic     r0,r0,#0x1f
106         orr     r0,r0,#0xd3
107         msr     cpsr,r0
108
109 #ifdef CONFIG_OMAP2420H4
110        /* Copy vectors to mask ROM indirect addr */
111         adr     r0, _start              /* r0 <- current position of code   */
112         add     r0, r0, #4      /* skip reset vector                    */
113         mov     r2, #64                 /* r2 <- size to copy  */
114         add     r2, r0, r2              /* r2 <- source end address         */
115         mov     r1, #SRAM_OFFSET0         /* build vect addr */
116         mov     r3, #SRAM_OFFSET1
117         add     r1, r1, r3
118         mov     r3, #SRAM_OFFSET2
119         add     r1, r1, r3
120 next:
121         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
122         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
123         cmp     r0, r2                  /* until source end address [r2]    */
124         bne     next                    /* loop until equal */
125         bl      cpy_clk_code            /* put dpll adjust code behind vectors */
126 #endif
127         /* the mask ROM code should have PLL and others stable */
128 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
129         bl  cpu_init_crit
130 #endif
131         b       setup_env
132
133 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
134 /*
135  *************************************************************************
136  *
137  * CPU_init_critical registers
138  *
139  * setup important registers
140  * setup memory timing
141  *
142  *************************************************************************
143  */
144 cpu_init_crit:
145         /*
146          * flush v4 I/D caches
147          */
148         mov     r0, #0
149         mcr     p15, 0, r0, c7, c7, 0   /* flush v3/v4 cache */
150         mcr     p15, 0, r0, c8, c7, 0   /* flush v4 TLB */
151
152         /*
153          * disable MMU stuff and caches
154          */
155         mrc     p15, 0, r0, c1, c0, 0
156         bic     r0, r0, #0x00002300     @ clear bits 13, 9:8 (--V- --RS)
157         bic     r0, r0, #0x00000087     @ clear bits 7, 2:0 (B--- -CAM)
158         orr     r0, r0, #0x00000002     @ set bit 2 (A) Align
159         orr     r0, r0, #0x00001000     @ set bit 12 (I) I-Cache
160         mcr     p15, 0, r0, c1, c0, 0
161
162         /*
163          * Jump to board specific initialization... The Mask ROM will have already initialized
164          * basic memory.  Go here to bump up clock rate and handle wake up conditions.
165          */
166         mov     ip, lr          /* persevere link reg across call */
167         bl      lowlevel_init   /* go setup pll,mux,memory */
168         mov     lr, ip          /* restore link */
169         mov     pc, lr          /* back to my caller */
170 #endif /* CONFIG_SKIP_LOWLEVEL_INIT */
171
172 .section ".text.setup", "ax"
173
174 .globl _TEXT_BASE
175 _TEXT_BASE:
176         .word   TEXT_BASE
177
178 .globl _armboot_start
179 _armboot_start:
180         .word _start
181
182 /*
183  * These are defined in the board-specific linker script.
184  */
185 .globl _bss_start
186 _bss_start:
187         .word __bss_start
188
189 .globl _bss_end
190 _bss_end:
191         .word _end
192
193 #ifdef CONFIG_USE_IRQ
194 /* IRQ stack memory (calculated at run-time) */
195 .globl IRQ_STACK_START
196 IRQ_STACK_START:
197         .word   0x0badc0de
198
199 /* IRQ stack memory (calculated at run-time) */
200 .globl FIQ_STACK_START
201 FIQ_STACK_START:
202         .word 0x0badc0de
203 #endif
204
205 setup_env:
206
207 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
208 relocate:                               /* relocate U-Boot to RAM           */
209         adr     r0, _armboot_start
210         ldr     r1, =_armboot_start
211         cmp     r0, r1                  /* don't reloc during debug         */
212         beq     stack_setup
213         ldr     r2, _armboot_start
214         sub     r0, r1, r0
215         sub     r0, r2, r0
216         mov     r1, r2
217         ldr     r2, _armboot_start
218         ldr     r3, _bss_start
219         sub     r2, r3, r2              /* r2 <- size of armboot            */
220         add     r2, r0, r2              /* r2 <- source end address         */
221
222 copy_loop:
223         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
224         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
225         cmp     r0, r2                  /* until source end addreee [r2]    */
226         ble     copy_loop
227 #endif  /* CONFIG_SKIP_RELOCATE_UBOOT */
228
229         /* Set up the stack                                                 */
230 stack_setup:
231         ldr     r0, _TEXT_BASE          /* upper 128 KiB: relocated uboot   */
232 #ifdef CONFIG_PRELOADER
233         sub     sp, r0, #128            /* leave 32 words for abort-stack   */
234 #else
235         sub     r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area                       */
236         sub     r0, r0, #CONFIG_SYS_GBL_DATA_SIZE /* bdinfo                         */
237 #ifdef CONFIG_USE_IRQ
238         sub     r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
239 #endif
240         sub     sp, r0, #12             /* leave 3 words for abort-stack    */
241 #endif  /* CONFIG_PRELOADER */
242
243 clear_bss:
244         ldr     r0, _bss_start          /* find start of bss segment        */
245         ldr     r1, _bss_end            /* stop here                        */
246         mov     r2, #0x00000000         /* clear                            */
247
248 #ifndef CONFIG_PRELOADER
249 clbss_l:str     r2, [r0]                /* clear loop...                    */
250         add     r0, r0, #4
251         cmp     r0, r1
252         bne     clbss_l
253 #endif
254 #ifdef CONFIG_ARCH_MMU
255         bl board_mmu_init
256 #endif
257         ldr     pc, _start_armboot
258
259 #ifdef CONFIG_NAND_SPL
260 _start_armboot: .word nand_boot
261 #else
262 #ifdef CONFIG_ONENAND_IPL
263 _start_armboot: .word start_oneboot
264 #else
265 _start_armboot: .word start_armboot
266 #endif /* CONFIG_ONENAND_IPL */
267 #endif /* CONFIG_NAND_SPL */
268
269 #ifndef CONFIG_PRELOADER
270 /*
271  *************************************************************************
272  *
273  * Interrupt handling
274  *
275  *************************************************************************
276  */
277 @
278 @ IRQ stack frame.
279 @
280 #define S_FRAME_SIZE    72
281
282 #define S_OLD_R0        68
283 #define S_PSR           64
284 #define S_PC            60
285 #define S_LR            56
286 #define S_SP            52
287
288 #define S_IP            48
289 #define S_FP            44
290 #define S_R10           40
291 #define S_R9            36
292 #define S_R8            32
293 #define S_R7            28
294 #define S_R6            24
295 #define S_R5            20
296 #define S_R4            16
297 #define S_R3            12
298 #define S_R2            8
299 #define S_R1            4
300 #define S_R0            0
301
302 #define MODE_SVC 0x13
303 #define I_BIT    0x80
304
305 /*
306  * use bad_save_user_regs for abort/prefetch/undef/swi ...
307  * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
308  */
309
310         .macro  bad_save_user_regs
311         sub     sp, sp, #S_FRAME_SIZE           @ carve out a frame on current user stack
312         stmia   sp, {r0 - r12}                  @ Save user registers (now in svc mode) r0-r12
313
314         ldr     r2, _armboot_start
315         sub     r2, r2, #(CONFIG_SYS_MALLOC_LEN)
316         sub     r2, r2, #(CONFIG_SYS_GBL_DATA_SIZE+8)   @ set base 2 words into abort stack
317         ldmia   r2, {r2 - r3}                   @ get values for "aborted" pc and cpsr (into parm regs)
318         add     r0, sp, #S_FRAME_SIZE           @ grab pointer to old stack
319
320         add     r5, sp, #S_SP
321         mov     r1, lr
322         stmia   r5, {r0 - r3}                   @ save sp_SVC, lr_SVC, pc, cpsr
323         mov     r0, sp                          @ save current stack into r0 (param register)
324         .endm
325
326         .macro  irq_save_user_regs
327         sub     sp, sp, #S_FRAME_SIZE
328         stmia   sp, {r0 - r12}                  @ Calling r0-r12
329         add     r8, sp, #S_PC                   @ !!!! R8 NEEDS to be saved !!!! a reserved stack spot would be good.
330         stmdb   r8, {sp, lr}^                   @ Calling SP, LR
331         str     lr, [r8, #0]                    @ Save calling PC
332         mrs     r6, spsr
333         str     r6, [r8, #4]                    @ Save CPSR
334         str     r0, [r8, #8]                    @ Save OLD_R0
335         mov     r0, sp
336         .endm
337
338         .macro  irq_restore_user_regs
339         ldmia   sp, {r0 - lr}^                  @ Calling r0 - lr
340         mov     r0, r0
341         ldr     lr, [sp, #S_PC]                 @ Get PC
342         add     sp, sp, #S_FRAME_SIZE
343         subs    pc, lr, #4                      @ return & move spsr_svc into cpsr
344         .endm
345
346         .macro get_bad_stack
347         ldr     r13, _armboot_start             @ setup our mode stack (enter in banked mode)
348         sub     r13, r13, #(CONFIG_SYS_MALLOC_LEN)      @ move past malloc pool
349         sub     r13, r13, #(CONFIG_SYS_GBL_DATA_SIZE+8) @ move to reserved a couple spots for abort stack
350
351         str     lr, [r13]                       @ save caller lr in position 0 of saved stack
352         mrs     lr, spsr                        @ get the spsr
353         str     lr, [r13, #4]                   @ save spsr in position 1 of saved stack
354
355         mov     r13, #MODE_SVC                  @ prepare SVC-Mode
356         @ msr   spsr_c, r13
357         msr     spsr, r13                       @ switch modes, make sure moves will execute
358         mov     lr, pc                          @ capture return pc
359         movs    pc, lr                          @ jump to next instruction & switch modes.
360         .endm
361
362         .macro get_bad_stack_swi
363         sub     r13, r13, #4                    @ space on current stack for scratch reg.
364         str     r0, [r13]                       @ save R0's value.
365         ldr     r0, _armboot_start              @ get data regions start
366         sub     r0, r0, #(CONFIG_SYS_MALLOC_LEN)        @ move past malloc pool
367         sub     r0, r0, #(CONFIG_SYS_GBL_DATA_SIZE+8)   @ move past gbl and a couple spots for abort stack
368         str     lr, [r0]                        @ save caller lr in position 0 of saved stack
369         mrs     r0, spsr                        @ get the spsr
370         str     lr, [r0, #4]                    @ save spsr in position 1 of saved stack
371         ldr     r0, [r13]                       @ restore r0
372         add     r13, r13, #4                    @ pop stack entry
373         .endm
374
375         .macro get_irq_stack                    @ setup IRQ stack
376         ldr     sp, IRQ_STACK_START
377         .endm
378
379         .macro get_fiq_stack                    @ setup FIQ stack
380         ldr     sp, FIQ_STACK_START
381         .endm
382 #endif  /* CONFIG_PRELOADER */
383
384 /*
385  * exception handlers
386  */
387 #ifdef CONFIG_PRELOADER
388         .align  5
389 do_hang:
390         ldr     sp, _TEXT_BASE                  /* use 32 words about stack */
391         bl      hang                            /* hang and never return */
392 #else   /* !CONFIG_PRELOADER */
393         .align  5
394 undefined_instruction:
395         get_bad_stack
396         bad_save_user_regs
397         bl      do_undefined_instruction
398
399         .align  5
400 software_interrupt:
401         get_bad_stack_swi
402         bad_save_user_regs
403         bl      do_software_interrupt
404
405         .align  5
406 prefetch_abort:
407         get_bad_stack
408         bad_save_user_regs
409         bl      do_prefetch_abort
410
411         .align  5
412 data_abort:
413         get_bad_stack
414         bad_save_user_regs
415         bl      do_data_abort
416
417         .align  5
418 not_used:
419         get_bad_stack
420         bad_save_user_regs
421         bl      do_not_used
422
423 #ifdef CONFIG_USE_IRQ
424
425         .align  5
426 irq:
427         get_irq_stack
428         irq_save_user_regs
429         bl      do_irq
430         irq_restore_user_regs
431
432         .align  5
433 fiq:
434         get_fiq_stack
435         /* someone ought to write a more effiction fiq_save_user_regs */
436         irq_save_user_regs
437         bl      do_fiq
438         irq_restore_user_regs
439
440 #else
441
442         .align  5
443 irq:
444         get_bad_stack
445         bad_save_user_regs
446         bl      do_irq
447
448         .align  5
449 fiq:
450         get_bad_stack
451         bad_save_user_regs
452         bl      do_fiq
453
454 #endif
455         .align 5
456 .global arm1136_cache_flush
457 arm1136_cache_flush:
458                 mcr     p15, 0, r1, c7, c5, 0   @ invalidate I cache
459                 mov     pc, lr                  @ back to caller
460 #endif  /* CONFIG_PRELOADER */