]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm1176/start.S
arm: Remove deprecated and now unused NAND SPL
[karo-tx-uboot.git] / arch / arm / cpu / arm1176 / start.S
1 /*
2  *  armboot - Startup Code for ARM1176 CPU-core
3  *
4  * Copyright (c) 2007   Samsung Electronics
5  *
6  * Copyright (C) 2008
7  * Guennadi Liakhovetki, DENX Software Engineering, <lg@denx.de>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  *
27  * 2007-09-21 - Restructured codes by jsgood (jsgood.yang@samsung.com)
28  * 2007-09-21 - Added MoviNAND and OneNAND boot codes by
29  * jsgood (jsgood.yang@samsung.com)
30  * Base codes by scsuh (sc.suh)
31  */
32
33 #include <asm-offsets.h>
34 #include <config.h>
35 #include <version.h>
36 #ifdef CONFIG_ENABLE_MMU
37 #include <asm/proc/domain.h>
38 #endif
39
40 #if !defined(CONFIG_ENABLE_MMU) && !defined(CONFIG_SYS_PHY_UBOOT_BASE)
41 #define CONFIG_SYS_PHY_UBOOT_BASE       CONFIG_SYS_UBOOT_BASE
42 #endif
43
44 /*
45  *************************************************************************
46  *
47  * Jump vector table as in table 3.1 in [1]
48  *
49  *************************************************************************
50  */
51
52 .globl _start
53 _start: b       reset
54 #ifndef CONFIG_SPL_BUILD
55         ldr     pc, _undefined_instruction
56         ldr     pc, _software_interrupt
57         ldr     pc, _prefetch_abort
58         ldr     pc, _data_abort
59         ldr     pc, _not_used
60         ldr     pc, _irq
61         ldr     pc, _fiq
62
63 _undefined_instruction:
64         .word undefined_instruction
65 _software_interrupt:
66         .word software_interrupt
67 _prefetch_abort:
68         .word prefetch_abort
69 _data_abort:
70         .word data_abort
71 _not_used:
72         .word not_used
73 _irq:
74         .word irq
75 _fiq:
76         .word fiq
77 _pad:
78         .word 0x12345678 /* now 16*4=64 */
79 #else
80         . = _start + 64
81 #endif
82
83 .global _end_vect
84 _end_vect:
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  * setup Memory and board specific bits prior to relocation.
93  * relocate armboot to ram
94  * setup stack
95  *
96  *************************************************************************
97  */
98
99 .globl _TEXT_BASE
100 _TEXT_BASE:
101 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
102         .word   CONFIG_SPL_TEXT_BASE
103 #else
104         .word   CONFIG_SYS_TEXT_BASE
105 #endif
106
107 /*
108  * Below variable is very important because we use MMU in U-Boot.
109  * Without it, we cannot run code correctly before MMU is ON.
110  * by scsuh.
111  */
112 _TEXT_PHY_BASE:
113         .word   CONFIG_SYS_PHY_UBOOT_BASE
114
115 /*
116  * These are defined in the board-specific linker script.
117  * Subtracting _start from them lets the linker put their
118  * relative position in the executable instead of leaving
119  * them null.
120  */
121
122 .globl _bss_start_ofs
123 _bss_start_ofs:
124         .word __bss_start - _start
125
126 .globl _image_copy_end_ofs
127 _image_copy_end_ofs:
128         .word __image_copy_end - _start
129
130 .globl _bss_end_ofs
131 _bss_end_ofs:
132         .word __bss_end - _start
133
134 .globl _end_ofs
135 _end_ofs:
136         .word _end - _start
137
138 /* IRQ stack memory (calculated at run-time) + 8 bytes */
139 .globl IRQ_STACK_START_IN
140 IRQ_STACK_START_IN:
141         .word   0x0badc0de
142
143 /*
144  * the actual reset code
145  */
146
147 reset:
148         /*
149          * set the cpu to SVC32 mode
150          */
151         mrs     r0, cpsr
152         bic     r0, r0, #0x3f
153         orr     r0, r0, #0xd3
154         msr     cpsr, r0
155
156 /*
157  *************************************************************************
158  *
159  * CPU_init_critical registers
160  *
161  * setup important registers
162  * setup memory timing
163  *
164  *************************************************************************
165  */
166         /*
167          * we do sys-critical inits only at reboot,
168          * not when booting from ram!
169          */
170 cpu_init_crit:
171         /*
172          * When booting from NAND - it has definitely been a reset, so, no need
173          * to flush caches and disable the MMU
174          */
175 #ifndef CONFIG_SPL_BUILD
176         /*
177          * flush v4 I/D caches
178          */
179         mov     r0, #0
180         mcr     p15, 0, r0, c7, c7, 0   /* flush v3/v4 cache */
181         mcr     p15, 0, r0, c8, c7, 0   /* flush v4 TLB */
182
183         /*
184          * disable MMU stuff and caches
185          */
186         mrc     p15, 0, r0, c1, c0, 0
187         bic     r0, r0, #0x00002300     @ clear bits 13, 9:8 (--V- --RS)
188         bic     r0, r0, #0x00000087     @ clear bits 7, 2:0 (B--- -CAM)
189         orr     r0, r0, #0x00000002     @ set bit 2 (A) Align
190         orr     r0, r0, #0x00001000     @ set bit 12 (I) I-Cache
191
192         /* Prepare to disable the MMU */
193         adr     r2, mmu_disable_phys
194         sub     r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - CONFIG_SYS_TEXT_BASE)
195         b       mmu_disable
196
197         .align 5
198         /* Run in a single cache-line */
199 mmu_disable:
200         mcr     p15, 0, r0, c1, c0, 0
201         nop
202         nop
203         mov     pc, r2
204 mmu_disable_phys:
205
206 #ifdef CONFIG_DISABLE_TCM
207         /*
208          * Disable the TCMs
209          */
210         mrc     p15, 0, r0, c0, c0, 2   /* Return TCM details */
211         cmp     r0, #0
212         beq     skip_tcmdisable
213         mov     r1, #0
214         mov     r2, #1
215         tst     r0, r2
216         mcrne   p15, 0, r1, c9, c1, 1   /* Disable Instruction TCM if present*/
217         tst     r0, r2, LSL #16
218         mcrne   p15, 0, r1, c9, c1, 0   /* Disable Data TCM if present*/
219 skip_tcmdisable:
220 #endif
221 #endif
222
223 #ifdef CONFIG_PERIPORT_REMAP
224         /* Peri port setup */
225         ldr     r0, =CONFIG_PERIPORT_BASE
226         orr     r0, r0, #CONFIG_PERIPORT_SIZE
227         mcr     p15,0,r0,c15,c2,4
228 #endif
229
230         /*
231          * Go setup Memory and board specific bits prior to relocation.
232          */
233         bl      lowlevel_init           /* go setup pll,mux,memory */
234
235         bl      _main
236
237 /*------------------------------------------------------------------------------*/
238
239 /*
240  * void relocate_code(addr_moni)
241  *
242  * This function relocates the monitor code.
243  */
244         .globl  relocate_code
245 relocate_code:
246         mov     r6, r0  /* save addr of destination */
247
248         adr     r0, _start
249         subs    r9, r6, r0              /* r9 <- relocation offset */
250         beq     relocate_done           /* skip relocation */
251         mov     r1, r6                  /* r1 <- scratch for copy_loop */
252         ldr     r3, _image_copy_end_ofs
253         add     r2, r0, r3              /* r2 <- source end address         */
254
255 copy_loop:
256         ldmia   r0!, {r10-r11}          /* copy from source address [r0]    */
257         stmia   r1!, {r10-r11}          /* copy to   target address [r1]    */
258         cmp     r0, r2                  /* until source end address [r2]    */
259         blo     copy_loop
260
261 #ifndef CONFIG_SPL_BUILD
262         /*
263          * fix .rel.dyn relocations
264          */
265         ldr     r0, _TEXT_BASE          /* r0 <- Text base */
266         ldr     r10, _dynsym_start_ofs  /* r10 <- sym table ofs */
267         add     r10, r10, r0            /* r10 <- sym table in FLASH */
268         ldr     r2, _rel_dyn_start_ofs  /* r2 <- rel dyn start ofs */
269         add     r2, r2, r0              /* r2 <- rel dyn start in FLASH */
270         ldr     r3, _rel_dyn_end_ofs    /* r3 <- rel dyn end ofs */
271         add     r3, r3, r0              /* r3 <- rel dyn end in FLASH */
272 fixloop:
273         ldr     r0, [r2]                /* r0 <- location to fix up, IN FLASH! */
274         add     r0, r0, r9              /* r0 <- location to fix up in RAM */
275         ldr     r1, [r2, #4]
276         and     r7, r1, #0xff
277         cmp     r7, #23                 /* relative fixup? */
278         beq     fixrel
279         cmp     r7, #2                  /* absolute fixup? */
280         beq     fixabs
281         /* ignore unknown type of fixup */
282         b       fixnext
283 fixabs:
284         /* absolute fix: set location to (offset) symbol value */
285         mov     r1, r1, LSR #4          /* r1 <- symbol index in .dynsym */
286         add     r1, r10, r1             /* r1 <- address of symbol in table */
287         ldr     r1, [r1, #4]            /* r1 <- symbol value */
288         add     r1, r1, r9              /* r1 <- relocated sym addr */
289         b       fixnext
290 fixrel:
291         /* relative fix: increase location by offset */
292         ldr     r1, [r0]
293         add     r1, r1, r9
294 fixnext:
295         str     r1, [r0]
296         add     r2, r2, #8              /* each rel.dyn entry is 8 bytes */
297         cmp     r2, r3
298         blo     fixloop
299 #endif
300
301 #ifdef CONFIG_ENABLE_MMU
302 enable_mmu:
303         /* enable domain access */
304         ldr     r5, =0x0000ffff
305         mcr     p15, 0, r5, c3, c0, 0   /* load domain access register */
306
307         /* Set the TTB register */
308         ldr     r0, _mmu_table_base
309         ldr     r1, =CONFIG_SYS_PHY_UBOOT_BASE
310         ldr     r2, =0xfff00000
311         bic     r0, r0, r2
312         orr     r1, r0, r1
313         mcr     p15, 0, r1, c2, c0, 0
314
315         /* Enable the MMU */
316         mrc     p15, 0, r0, c1, c0, 0
317         orr     r0, r0, #1              /* Set CR_M to enable MMU */
318
319         /* Prepare to enable the MMU */
320         adr     r1, skip_hw_init
321         and     r1, r1, #0x3fc
322         ldr     r2, _TEXT_BASE
323         ldr     r3, =0xfff00000
324         and     r2, r2, r3
325         orr     r2, r2, r1
326         b       mmu_enable
327
328         .align 5
329         /* Run in a single cache-line */
330 mmu_enable:
331
332         mcr     p15, 0, r0, c1, c0, 0
333         nop
334         nop
335         mov     pc, r2
336 skip_hw_init:
337 #endif
338
339 relocate_done:
340
341         bx      lr
342
343 _rel_dyn_start_ofs:
344         .word __rel_dyn_start - _start
345 _rel_dyn_end_ofs:
346         .word __rel_dyn_end - _start
347 _dynsym_start_ofs:
348         .word __dynsym_start - _start
349
350 #ifdef CONFIG_ENABLE_MMU
351 _mmu_table_base:
352         .word mmu_table
353 #endif
354
355         .globl  c_runtime_cpu_setup
356 c_runtime_cpu_setup:
357
358         mov     pc, lr
359
360 #ifndef CONFIG_SPL_BUILD
361 /*
362  * we assume that cache operation is done before. (eg. cleanup_before_linux())
363  * actually, we don't need to do anything about cache if not use d-cache in
364  * U-Boot. So, in this function we clean only MMU. by scsuh
365  *
366  * void theLastJump(void *kernel, int arch_num, uint boot_params);
367  */
368 #ifdef CONFIG_ENABLE_MMU
369         .globl theLastJump
370 theLastJump:
371         mov     r9, r0
372         ldr     r3, =0xfff00000
373         ldr     r4, _TEXT_PHY_BASE
374         adr     r5, phy_last_jump
375         bic     r5, r5, r3
376         orr     r5, r5, r4
377         mov     pc, r5
378 phy_last_jump:
379         /*
380          * disable MMU stuff
381          */
382         mrc     p15, 0, r0, c1, c0, 0
383         bic     r0, r0, #0x00002300     /* clear bits 13, 9:8 (--V- --RS) */
384         bic     r0, r0, #0x00000087     /* clear bits 7, 2:0 (B--- -CAM) */
385         orr     r0, r0, #0x00000002     /* set bit 2 (A) Align */
386         orr     r0, r0, #0x00001000     /* set bit 12 (I) I-Cache */
387         mcr     p15, 0, r0, c1, c0, 0
388
389         mcr     p15, 0, r0, c8, c7, 0   /* flush v4 TLB */
390
391         mov     r0, #0
392         mov     pc, r9
393 #endif
394
395
396 /*
397  *************************************************************************
398  *
399  * Interrupt handling
400  *
401  *************************************************************************
402  */
403 @
404 @ IRQ stack frame.
405 @
406 #define S_FRAME_SIZE    72
407
408 #define S_OLD_R0        68
409 #define S_PSR           64
410 #define S_PC            60
411 #define S_LR            56
412 #define S_SP            52
413
414 #define S_IP            48
415 #define S_FP            44
416 #define S_R10           40
417 #define S_R9            36
418 #define S_R8            32
419 #define S_R7            28
420 #define S_R6            24
421 #define S_R5            20
422 #define S_R4            16
423 #define S_R3            12
424 #define S_R2            8
425 #define S_R1            4
426 #define S_R0            0
427
428 #define MODE_SVC 0x13
429 #define I_BIT    0x80
430
431 /*
432  * use bad_save_user_regs for abort/prefetch/undef/swi ...
433  */
434
435         .macro  bad_save_user_regs
436         /* carve out a frame on current user stack */
437         sub     sp, sp, #S_FRAME_SIZE
438         /* Save user registers (now in svc mode) r0-r12 */
439         stmia   sp, {r0 - r12}
440
441         ldr     r2, IRQ_STACK_START_IN
442         /* get values for "aborted" pc and cpsr (into parm regs) */
443         ldmia   r2, {r2 - r3}
444         /* grab pointer to old stack */
445         add     r0, sp, #S_FRAME_SIZE
446
447         add     r5, sp, #S_SP
448         mov     r1, lr
449         /* save sp_SVC, lr_SVC, pc, cpsr */
450         stmia   r5, {r0 - r3}
451         /* save current stack into r0 (param register) */
452         mov     r0, sp
453         .endm
454
455         .macro get_bad_stack
456         ldr     r13, IRQ_STACK_START_IN         @ setup our mode stack
457
458         /* save caller lr in position 0 of saved stack */
459         str     lr, [r13]
460         /* get the spsr */
461         mrs     lr, spsr
462         /* save spsr in position 1 of saved stack */
463         str     lr, [r13, #4]
464
465         /* prepare SVC-Mode */
466         mov     r13, #MODE_SVC
467         @ msr   spsr_c, r13
468         /* switch modes, make sure moves will execute */
469         msr     spsr, r13
470         /* capture return pc */
471         mov     lr, pc
472         /* jump to next instruction & switch modes. */
473         movs    pc, lr
474         .endm
475
476         .macro get_bad_stack_swi
477         /* space on current stack for scratch reg. */
478         sub     r13, r13, #4
479         /* save R0's value. */
480         str     r0, [r13]
481         ldr     r13, IRQ_STACK_START_IN         @ setup our mode stack
482         /* save caller lr in position 0 of saved stack */
483         str     lr, [r0]
484         /* get the spsr */
485         mrs     r0, spsr
486         /* save spsr in position 1 of saved stack */
487         str     lr, [r0, #4]
488         /* restore r0 */
489         ldr     r0, [r13]
490         /* pop stack entry */
491         add     r13, r13, #4
492         .endm
493
494 /*
495  * exception handlers
496  */
497         .align  5
498 undefined_instruction:
499         get_bad_stack
500         bad_save_user_regs
501         bl      do_undefined_instruction
502
503         .align  5
504 software_interrupt:
505         get_bad_stack_swi
506         bad_save_user_regs
507         bl      do_software_interrupt
508
509         .align  5
510 prefetch_abort:
511         get_bad_stack
512         bad_save_user_regs
513         bl      do_prefetch_abort
514
515         .align  5
516 data_abort:
517         get_bad_stack
518         bad_save_user_regs
519         bl      do_data_abort
520
521         .align  5
522 not_used:
523         get_bad_stack
524         bad_save_user_regs
525         bl      do_not_used
526
527         .align  5
528 irq:
529         get_bad_stack
530         bad_save_user_regs
531         bl      do_irq
532
533         .align  5
534 fiq:
535         get_bad_stack
536         bad_save_user_regs
537         bl      do_fiq
538 #endif /* CONFIG_SPL_BUILD */