Initial checkin
[pandora-x-loader.git] / cpu / omap3 / start.S
1 /*
2  *  armboot - Startup Code for OMP2420/ARM1136 CPU-core
3  *
4  *  Copyright (c) 2004-2006  Texas Instruments
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 <gj@denx.de>
9  *  Copyright (c) 2003  Richard Woodruff <r-woodruff2@ti.com>
10  *  Copyright (c) 2003  Kshitij <kshitij@ti.com>
11  *  Copyright (c) 2004  Jian Zhang <jzhang@ti.com>
12  *
13  * See file CREDITS for list of people who contributed to this
14  * project.
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License as
18  * published by the Free Software Foundation; either version 2 of
19  * the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29  * MA 02111-1307 USA
30  */
31
32 #include <config.h>
33 #include <asm/arch/cpu.h>
34
35 .globl _start
36 _start: 
37         b       reset
38         ldr     pc, _hang
39         ldr     pc, _hang
40         ldr     pc, _hang
41         ldr     pc, _hang
42         ldr     pc, _hang
43         ldr     pc, _hang
44         ldr     pc, _hang
45
46 _hang:
47         .word do_hang
48         
49         .word 0x12345678
50         .word 0x12345678
51         .word 0x12345678
52         .word 0x12345678
53         .word 0x12345678
54         .word 0x12345678
55         .word 0x12345678 /* now 16*4=64 */
56
57 .global _end_vect
58 _end_vect:
59
60         .balignl 16,0xdeadbeef
61 /*
62  *************************************************************************
63  *
64  * Startup Code (reset vector)
65  *
66  * do important init only if we don't start from memory!
67  * setup Memory and board specific bits prior to relocation.
68  * relocate armboot to ram
69  * setup stack
70  *
71  *************************************************************************
72  */
73
74 _TEXT_BASE:
75         .word   TEXT_BASE
76
77 .globl _armboot_start
78 _armboot_start:
79         .word _start
80
81 /*
82  * These are defined in the board-specific linker script.
83  */
84 .globl _bss_start
85 _bss_start:
86         .word __bss_start
87
88 .globl _bss_end
89 _bss_end:
90         .word _end
91
92 /*
93  * the actual reset code
94  */
95
96 reset: 
97         /*
98          * set the cpu to SVC32 mode
99          */
100         mrs     r0,cpsr
101         bic     r0,r0,#0x1f
102         orr     r0,r0,#0xd3
103         msr     cpsr,r0
104
105         /* Copy vectors to mask ROM indirect addr */ 
106         adr     r0, _start              /* r0 <- current position of code   */
107         add     r0, r0, #4                              /* skip reset vector                    */
108         mov     r2, #64                 /* r2 <- size to copy  */
109         add     r2, r0, r2              /* r2 <- source end address         */
110         mov     r1, #SRAM_OFFSET0         /* build vect addr */
111         mov     r3, #SRAM_OFFSET1
112         add     r1, r1, r3
113         mov     r3, #SRAM_OFFSET2
114         add     r1, r1, r3
115 next:
116         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
117         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
118         cmp     r0, r2                  /* until source end address [r2]    */
119         bne     next                    /* loop until equal */
120
121         bl      cpy_clk_code            /* put dpll adjust code behind vectors */
122  
123         /* the mask ROM code should have PLL and others stable */
124         bl  cpu_init_crit
125
126 relocate:                               /* relocate U-Boot to RAM           */
127         adr     r0, _start              /* r0 <- current position of code   */
128         ldr     r1, _TEXT_BASE          /* test if we run from flash or RAM */
129         cmp r0, r1                      /* no need to relocate if XIP       */
130         beq stack_setup                 /* skip txt cpy if XIP(SRAM, SDRAM) */ 
131
132         ldr     r2, _armboot_start
133         ldr     r3, _bss_start
134         sub     r2, r3, r2              /* r2 <- size of armboot            */
135         add     r2, r0, r2              /* r2 <- source end address         */
136
137 copy_loop:
138         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
139         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
140         cmp     r0, r2                  /* until source end addreee [r2]    */
141         ble     copy_loop
142
143         /* Set up the stack                                                 */
144 stack_setup:
145         ldr     r0, _TEXT_BASE          /* upper 128 KiB: relocated uboot   */
146         sub     sp, r0, #128            /* leave 32 words for abort-stack   */
147         and     sp, sp, #~7             /* 8 byte alinged for (ldr/str)d    */
148
149         /* Clear BSS (if any).  Is below tx (watch load addr - need space)  */
150 clear_bss:
151         ldr     r0, _bss_start          /* find start of bss segment        */
152         ldr     r1, _bss_end            /* stop here                        */
153         mov     r2, #0x00000000         /* clear value                      */
154 clbss_l:
155         str     r2, [r0]                /* clear BSS location               */
156         cmp     r0, r1                  /* are we at the end yet            */
157         add     r0, r0, #4              /* increment clear index pointer    */
158         bne     clbss_l                 /* keep clearing till at end        */
159
160         ldr     pc, _start_armboot      /* jump to C code                   */
161
162 _start_armboot: .word start_armboot
163
164
165 /*
166  *************************************************************************
167  *
168  * CPU_init_critical registers
169  *
170  * setup important registers
171  * setup memory timing
172  *
173  *************************************************************************
174  */
175 cpu_init_crit:
176         /*
177          * Invalidate L1 I/D
178          */
179         mov     r0, #0                 /* set up for MCR */
180         mcr     p15, 0, r0, c8, c7, 0  /* invalidate TLBs */
181         mcr     p15, 0, r0, c7, c5, 1  /* invalidate icache */
182
183         /* Invalide L2 cache (gp device call point) 
184          * - warning, this may have issues on EMU/HS devices
185          * this call can corrupt r0-r5
186          */
187         mov r12, #0x1           @ set up to invalide L2 
188 smi:    .word 0xE1600070        @ Call SMI monitor
189
190         /*
191          * disable MMU stuff and caches
192          */
193         mrc     p15, 0, r0, c1, c0, 0
194         bic     r0, r0, #0x00002000     @ clear bits 13 (--V-)
195         bic     r0, r0, #0x00000007     @ clear bits 2:0 (-CAM)
196         orr     r0, r0, #0x00000002     @ set bit 1 (--A-) Align
197 #ifndef CONFIG_ICACHE_OFF
198         orr     r0, r0, #0x00001800     @ set bit 11,12 (---I Z---) BTB,I-Cache
199 #endif
200         mcr     p15, 0, r0, c1, c0, 0
201
202         /*
203          * Jump to board specific initialization... The Mask ROM will have already initialized
204          * basic memory.  Go here to bump up clock rate and handle wake up conditions.
205          */
206         adr     r0, _start              /* r0 <- current position of code   */
207         ldr     r1, _TEXT_BASE          /* test if we run from flash or RAM */
208         cmp     r0, r1                  /* pass on info about skipping some init portions */
209         moveq   r0,#0x1                 /* flag to skip prcm and sdrc setup */
210         movne   r0,#0x0
211
212         mov     ip, lr          /* persevere link reg across call */
213         bl      lowlevel_init   /* go setup pll,mux,memory */
214         mov     lr, ip          /* restore link */
215         mov     pc, lr          /* back to my caller */
216
217 /*
218  * exception handler
219  */
220         .align  5
221 do_hang:
222         ldr     sp, _TEXT_BASE          /* use 32 words abort stack */
223         bl      hang                    /* hang and never return */
224