]> git.sur5r.net Git - u-boot/blob - arch/arm/cpu/arm1176/start.S
Drop support for CONFIG_SYS_ARM_WITHOUT_RELOC
[u-boot] / 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_NAND_SPL
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         .word   CONFIG_SYS_TEXT_BASE
102
103 /*
104  * Below variable is very important because we use MMU in U-Boot.
105  * Without it, we cannot run code correctly before MMU is ON.
106  * by scsuh.
107  */
108 _TEXT_PHY_BASE:
109         .word   CONFIG_SYS_PHY_UBOOT_BASE
110
111 /*
112  * These are defined in the board-specific linker script.
113  * Subtracting _start from them lets the linker put their
114  * relative position in the executable instead of leaving
115  * them null.
116  */
117
118 .globl _bss_start_ofs
119 _bss_start_ofs:
120         .word __bss_start - _start
121
122 .globl _bss_end_ofs
123 _bss_end_ofs:
124         .word _end - _start
125
126 .globl _datarel_start_ofs
127 _datarel_start_ofs:
128         .word __datarel_start - _start
129
130 .globl _datarelrolocal_start_ofs
131 _datarelrolocal_start_ofs:
132         .word __datarelrolocal_start - _start
133
134 .globl _datarellocal_start_ofs
135 _datarellocal_start_ofs:
136         .word __datarellocal_start - _start
137
138 .globl _datarelro_start_ofs
139 _datarelro_start_ofs:
140         .word __datarelro_start - _start
141
142 .globl _rel_dyn_start_ofs
143 _rel_dyn_start_ofs:
144         .word __rel_dyn_start - _start
145
146 .globl _rel_dyn_end_ofs
147 _rel_dyn_end_ofs:
148         .word __rel_dyn_end - _start
149
150 .globl _dynsym_start_ofs
151 _dynsym_start_ofs:
152         .word __dynsym_start - _start
153
154 /* IRQ stack memory (calculated at run-time) + 8 bytes */
155 .globl IRQ_STACK_START_IN
156 IRQ_STACK_START_IN:
157         .word   0x0badc0de
158
159 /*
160  * the actual reset code
161  */
162
163 reset:
164         /*
165          * set the cpu to SVC32 mode
166          */
167         mrs     r0, cpsr
168         bic     r0, r0, #0x3f
169         orr     r0, r0, #0xd3
170         msr     cpsr, r0
171
172 /*
173  *************************************************************************
174  *
175  * CPU_init_critical registers
176  *
177  * setup important registers
178  * setup memory timing
179  *
180  *************************************************************************
181  */
182         /*
183          * we do sys-critical inits only at reboot,
184          * not when booting from ram!
185          */
186 cpu_init_crit:
187         /*
188          * When booting from NAND - it has definitely been a reset, so, no need
189          * to flush caches and disable the MMU
190          */
191 #ifndef CONFIG_NAND_SPL
192         /*
193          * flush v4 I/D caches
194          */
195         mov     r0, #0
196         mcr     p15, 0, r0, c7, c7, 0   /* flush v3/v4 cache */
197         mcr     p15, 0, r0, c8, c7, 0   /* flush v4 TLB */
198
199         /*
200          * disable MMU stuff and caches
201          */
202         mrc     p15, 0, r0, c1, c0, 0
203         bic     r0, r0, #0x00002300     @ clear bits 13, 9:8 (--V- --RS)
204         bic     r0, r0, #0x00000087     @ clear bits 7, 2:0 (B--- -CAM)
205         orr     r0, r0, #0x00000002     @ set bit 2 (A) Align
206         orr     r0, r0, #0x00001000     @ set bit 12 (I) I-Cache
207
208         /* Prepare to disable the MMU */
209         adr     r2, mmu_disable_phys
210         sub     r2, r2, #(CONFIG_SYS_PHY_UBOOT_BASE - CONFIG_SYS_TEXT_BASE)
211         b       mmu_disable
212
213         .align 5
214         /* Run in a single cache-line */
215 mmu_disable:
216         mcr     p15, 0, r0, c1, c0, 0
217         nop
218         nop
219         mov     pc, r2
220 mmu_disable_phys:
221
222 #ifdef CONFIG_DISABLE_TCM
223         /*
224          * Disable the TCMs
225          */
226         mrc     p15, 0, r0, c0, c0, 2   /* Return TCM details */
227         cmp     r0, #0
228         beq     skip_tcmdisable
229         mov     r1, #0
230         mov     r2, #1
231         tst     r0, r2
232         mcrne   p15, 0, r1, c9, c1, 1   /* Disable Instruction TCM if present*/
233         tst     r0, r2, LSL #16
234         mcrne   p15, 0, r1, c9, c1, 0   /* Disable Data TCM if present*/
235 skip_tcmdisable:
236 #endif
237 #endif
238
239 #ifdef CONFIG_PERIPORT_REMAP
240         /* Peri port setup */
241         ldr     r0, =CONFIG_PERIPORT_BASE
242         orr     r0, r0, #CONFIG_PERIPORT_SIZE
243         mcr     p15,0,r0,c15,c2,4
244 #endif
245
246         /*
247          * Go setup Memory and board specific bits prior to relocation.
248          */
249         bl      lowlevel_init           /* go setup pll,mux,memory */
250
251 /* Set stackpointer in internal RAM to call board_init_f */
252 call_board_init_f:
253         ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
254         ldr     r0,=0x00000000
255         bl      board_init_f
256
257 /*------------------------------------------------------------------------------*/
258
259 /*
260  * void relocate_code (addr_sp, gd, addr_moni)
261  *
262  * This "function" does not return, instead it continues in RAM
263  * after relocating the monitor code.
264  *
265  */
266         .globl  relocate_code
267 relocate_code:
268         mov     r4, r0  /* save addr_sp */
269         mov     r5, r1  /* save addr of gd */
270         mov     r6, r2  /* save addr of destination */
271         mov     r7, r2  /* save addr of destination */
272
273         /* Set up the stack                                                 */
274 stack_setup:
275         mov     sp, r4
276
277         adr     r0, _start
278         ldr     r2, _TEXT_BASE
279         ldr     r3, _bss_start_ofs
280         add     r2, r0, r3              /* r2 <- source end address         */
281         cmp     r0, r6
282         beq     clear_bss
283
284 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
285 copy_loop:
286         ldmia   r0!, {r9-r10}           /* copy from source address [r0]    */
287         stmia   r6!, {r9-r10}           /* copy to   target address [r1]    */
288         cmp     r0, r2                  /* until source end address [r2]    */
289         blo     copy_loop
290
291 #ifndef CONFIG_PRELOADER
292         /*
293          * fix .rel.dyn relocations
294          */
295         ldr     r0, _TEXT_BASE          /* r0 <- Text base */
296         sub     r9, r7, r0              /* r9 <- relocation offset */
297         ldr     r10, _dynsym_start_ofs  /* r10 <- sym table ofs */
298         add     r10, r10, r0            /* r10 <- sym table in FLASH */
299         ldr     r2, _rel_dyn_start_ofs  /* r2 <- rel dyn start ofs */
300         add     r2, r2, r0              /* r2 <- rel dyn start in FLASH */
301         ldr     r3, _rel_dyn_end_ofs    /* r3 <- rel dyn end ofs */
302         add     r3, r3, r0              /* r3 <- rel dyn end in FLASH */
303 fixloop:
304         ldr     r0, [r2]        /* r0 <- location to fix up, IN FLASH! */
305         add     r0, r0, r9      /* r0 <- location to fix up in RAM */
306         ldr     r1, [r2, #4]
307         and     r8, r1, #0xff
308         cmp     r8, #23         /* relative fixup? */
309         beq     fixrel
310         cmp     r8, #2          /* absolute fixup? */
311         beq     fixabs
312         /* ignore unknown type of fixup */
313         b       fixnext
314 fixabs:
315         /* absolute fix: set location to (offset) symbol value */
316         mov     r1, r1, LSR #4          /* r1 <- symbol index in .dynsym */
317         add     r1, r10, r1             /* r1 <- address of symbol in table */
318         ldr     r1, [r1, #4]            /* r1 <- symbol value */
319         add     r1, r1, r9              /* r1 <- relocated sym addr */
320         b       fixnext
321 fixrel:
322         /* relative fix: increase location by offset */
323         ldr     r1, [r0]
324         add     r1, r1, r9
325 fixnext:
326         str     r1, [r0]
327         add     r2, r2, #8      /* each rel.dyn entry is 8 bytes */
328         cmp     r2, r3
329         blo     fixloop
330 #endif
331 #endif  /* #ifndef CONFIG_SKIP_RELOCATE_UBOOT */
332
333 #ifdef CONFIG_ENABLE_MMU
334 enable_mmu:
335         /* enable domain access */
336         ldr     r5, =0x0000ffff
337         mcr     p15, 0, r5, c3, c0, 0   /* load domain access register */
338
339         /* Set the TTB register */
340         ldr     r0, _mmu_table_base
341         ldr     r1, =CONFIG_SYS_PHY_UBOOT_BASE
342         ldr     r2, =0xfff00000
343         bic     r0, r0, r2
344         orr     r1, r0, r1
345         mcr     p15, 0, r1, c2, c0, 0
346
347         /* Enable the MMU */
348         mrc     p15, 0, r0, c1, c0, 0
349         orr     r0, r0, #1              /* Set CR_M to enable MMU */
350
351         /* Prepare to enable the MMU */
352         adr     r1, skip_hw_init
353         and     r1, r1, #0x3fc
354         ldr     r2, _TEXT_BASE
355         ldr     r3, =0xfff00000
356         and     r2, r2, r3
357         orr     r2, r2, r1
358         b       mmu_enable
359
360         .align 5
361         /* Run in a single cache-line */
362 mmu_enable:
363
364         mcr     p15, 0, r0, c1, c0, 0
365         nop
366         nop
367         mov     pc, r2
368 skip_hw_init:
369 #endif
370
371 clear_bss:
372 #ifndef CONFIG_PRELOADER
373         ldr     r0, _bss_start_ofs
374         ldr     r1, _bss_end_ofs
375         ldr     r3, _TEXT_BASE          /* Text base */
376         mov     r4, r7                  /* reloc addr */
377         add     r0, r0, r4
378         add     r1, r1, r4
379         mov     r2, #0x00000000         /* clear                            */
380
381 clbss_l:str     r2, [r0]                /* clear loop...                    */
382         add     r0, r0, #4
383         cmp     r0, r1
384         bne     clbss_l
385
386         bl coloured_LED_init
387         bl red_LED_on
388 #endif
389
390 /*
391  * We are done. Do not return, instead branch to second part of board
392  * initialization, now running from RAM.
393  */
394 #ifdef CONFIG_NAND_SPL
395         ldr     pc, _nand_boot
396
397 _nand_boot: .word nand_boot
398 #else
399         ldr     r0, _board_init_r_ofs
400         adr     r1, _start
401         add     lr, r0, r1
402 #ifndef CONFIG_SKIP_RELOCATE_UBOOT
403         add     lr, lr, r9
404 #endif
405         /* setup parameters for board_init_r */
406         mov     r0, r5          /* gd_t */
407         mov     r1, r7          /* dest_addr */
408         /* jump to it ... */
409         mov     pc, lr
410
411 _board_init_r_ofs:
412         .word board_init_r - _start
413 #endif
414
415 #ifdef CONFIG_ENABLE_MMU
416 _mmu_table_base:
417         .word mmu_table
418 #endif
419
420 #ifndef CONFIG_NAND_SPL
421 /*
422  * we assume that cache operation is done before. (eg. cleanup_before_linux())
423  * actually, we don't need to do anything about cache if not use d-cache in
424  * U-Boot. So, in this function we clean only MMU. by scsuh
425  *
426  * void theLastJump(void *kernel, int arch_num, uint boot_params);
427  */
428 #ifdef CONFIG_ENABLE_MMU
429         .globl theLastJump
430 theLastJump:
431         mov     r9, r0
432         ldr     r3, =0xfff00000
433         ldr     r4, _TEXT_PHY_BASE
434         adr     r5, phy_last_jump
435         bic     r5, r5, r3
436         orr     r5, r5, r4
437         mov     pc, r5
438 phy_last_jump:
439         /*
440          * disable MMU stuff
441          */
442         mrc     p15, 0, r0, c1, c0, 0
443         bic     r0, r0, #0x00002300     /* clear bits 13, 9:8 (--V- --RS) */
444         bic     r0, r0, #0x00000087     /* clear bits 7, 2:0 (B--- -CAM) */
445         orr     r0, r0, #0x00000002     /* set bit 2 (A) Align */
446         orr     r0, r0, #0x00001000     /* set bit 12 (I) I-Cache */
447         mcr     p15, 0, r0, c1, c0, 0
448
449         mcr     p15, 0, r0, c8, c7, 0   /* flush v4 TLB */
450
451         mov     r0, #0
452         mov     pc, r9
453 #endif
454
455
456 /*
457  *************************************************************************
458  *
459  * Interrupt handling
460  *
461  *************************************************************************
462  */
463 @
464 @ IRQ stack frame.
465 @
466 #define S_FRAME_SIZE    72
467
468 #define S_OLD_R0        68
469 #define S_PSR           64
470 #define S_PC            60
471 #define S_LR            56
472 #define S_SP            52
473
474 #define S_IP            48
475 #define S_FP            44
476 #define S_R10           40
477 #define S_R9            36
478 #define S_R8            32
479 #define S_R7            28
480 #define S_R6            24
481 #define S_R5            20
482 #define S_R4            16
483 #define S_R3            12
484 #define S_R2            8
485 #define S_R1            4
486 #define S_R0            0
487
488 #define MODE_SVC 0x13
489 #define I_BIT    0x80
490
491 /*
492  * use bad_save_user_regs for abort/prefetch/undef/swi ...
493  */
494
495         .macro  bad_save_user_regs
496         /* carve out a frame on current user stack */
497         sub     sp, sp, #S_FRAME_SIZE
498         /* Save user registers (now in svc mode) r0-r12 */
499         stmia   sp, {r0 - r12}
500
501         ldr     r2, IRQ_STACK_START_IN
502         /* get values for "aborted" pc and cpsr (into parm regs) */
503         ldmia   r2, {r2 - r3}
504         /* grab pointer to old stack */
505         add     r0, sp, #S_FRAME_SIZE
506
507         add     r5, sp, #S_SP
508         mov     r1, lr
509         /* save sp_SVC, lr_SVC, pc, cpsr */
510         stmia   r5, {r0 - r3}
511         /* save current stack into r0 (param register) */
512         mov     r0, sp
513         .endm
514
515         .macro get_bad_stack
516         ldr     r13, IRQ_STACK_START_IN         @ setup our mode stack
517
518         /* save caller lr in position 0 of saved stack */
519         str     lr, [r13]
520         /* get the spsr */
521         mrs     lr, spsr
522         /* save spsr in position 1 of saved stack */
523         str     lr, [r13, #4]
524
525         /* prepare SVC-Mode */
526         mov     r13, #MODE_SVC
527         @ msr   spsr_c, r13
528         /* switch modes, make sure moves will execute */
529         msr     spsr, r13
530         /* capture return pc */
531         mov     lr, pc
532         /* jump to next instruction & switch modes. */
533         movs    pc, lr
534         .endm
535
536         .macro get_bad_stack_swi
537         /* space on current stack for scratch reg. */
538         sub     r13, r13, #4
539         /* save R0's value. */
540         str     r0, [r13]
541         ldr     r13, IRQ_STACK_START_IN         @ setup our mode stack
542         /* save caller lr in position 0 of saved stack */
543         str     lr, [r0]
544         /* get the spsr */
545         mrs     r0, spsr
546         /* save spsr in position 1 of saved stack */
547         str     lr, [r0, #4]
548         /* restore r0 */
549         ldr     r0, [r13]
550         /* pop stack entry */
551         add     r13, r13, #4
552         .endm
553
554 /*
555  * exception handlers
556  */
557         .align  5
558 undefined_instruction:
559         get_bad_stack
560         bad_save_user_regs
561         bl      do_undefined_instruction
562
563         .align  5
564 software_interrupt:
565         get_bad_stack_swi
566         bad_save_user_regs
567         bl      do_software_interrupt
568
569         .align  5
570 prefetch_abort:
571         get_bad_stack
572         bad_save_user_regs
573         bl      do_prefetch_abort
574
575         .align  5
576 data_abort:
577         get_bad_stack
578         bad_save_user_regs
579         bl      do_data_abort
580
581         .align  5
582 not_used:
583         get_bad_stack
584         bad_save_user_regs
585         bl      do_not_used
586
587         .align  5
588 irq:
589         get_bad_stack
590         bad_save_user_regs
591         bl      do_irq
592
593         .align  5
594 fiq:
595         get_bad_stack
596         bad_save_user_regs
597         bl      do_fiq
598 #endif /* CONFIG_NAND_SPL */