]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/s3c44b0/start.S
33a0a814ffe73c2a57c10ae33f25d0ec41df68d0
[karo-tx-uboot.git] / arch / arm / cpu / s3c44b0 / start.S
1 /*
2  * Startup Code for S3C44B0 CPU-core
3  *
4  * (C) Copyright 2004
5  * DAVE Srl
6  *
7  * http://www.dave-tech.it
8  * http://www.wawnet.biz
9  * mailto:info@wawnet.biz
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
34 /*
35  * Jump vector table
36  */
37
38
39 .globl _start
40 _start: b       reset
41         add     pc, pc, #0x0c000000
42         add     pc, pc, #0x0c000000
43         add     pc, pc, #0x0c000000
44         add     pc, pc, #0x0c000000
45         add     pc, pc, #0x0c000000
46         add     pc, pc, #0x0c000000
47         add     pc, pc, #0x0c000000
48
49         .balignl 16,0xdeadbeef
50
51
52 /*
53  *************************************************************************
54  *
55  * Startup Code (reset vector)
56  *
57  * do important init only if we don't start from memory!
58  * relocate u-boot to ram
59  * setup stack
60  * jump to second stage
61  *
62  *************************************************************************
63  */
64
65 .globl _TEXT_BASE
66 _TEXT_BASE:
67 #if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_TEXT_BASE)
68         .word   CONFIG_SPL_TEXT_BASE
69 #else
70         .word   CONFIG_SYS_TEXT_BASE
71 #endif
72
73 /*
74  * These are defined in the board-specific linker script.
75  * Subtracting _start from them lets the linker put their
76  * relative position in the executable instead of leaving
77  * them null.
78  */
79 .globl _bss_start_ofs
80 _bss_start_ofs:
81         .word __bss_start - _start
82
83 .globl _bss_end_ofs
84 _bss_end_ofs:
85         .word __bss_end - _start
86
87 .globl _end_ofs
88 _end_ofs:
89         .word _end - _start
90
91 #ifdef CONFIG_USE_IRQ
92 /* IRQ stack memory (calculated at run-time) */
93 .globl IRQ_STACK_START
94 IRQ_STACK_START:
95         .word   0x0badc0de
96
97 /* IRQ stack memory (calculated at run-time) */
98 .globl FIQ_STACK_START
99 FIQ_STACK_START:
100         .word 0x0badc0de
101 #endif
102
103 /* IRQ stack memory (calculated at run-time) + 8 bytes */
104 .globl IRQ_STACK_START_IN
105 IRQ_STACK_START_IN:
106         .word   0x0badc0de
107
108 /*
109  * the actual reset code
110  */
111
112 reset:
113         /*
114          * set the cpu to SVC32 mode
115          */
116         mrs     r0,cpsr
117         bic     r0,r0,#0x1f
118         orr     r0,r0,#0xd3
119         msr     cpsr,r0
120
121         /*
122          * we do sys-critical inits only at reboot,
123          * not when booting from ram!
124          */
125 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
126         bl      cpu_init_crit
127         /*
128          * before relocating, we have to setup RAM timing
129          * because memory timing is board-dependend, you will
130          * find a lowlevel_init.S in your board directory.
131          */
132         bl      lowlevel_init
133 #endif
134
135         bl      _main
136
137 /*------------------------------------------------------------------------------*/
138
139 #ifndef CONFIG_SPL_BUILD
140 /*
141  * void relocate_code(addr_moni)
142  *
143  * This function relocates the monitor code.
144  */
145         .globl  relocate_code
146 relocate_code:
147         mov     r6, r0  /* save addr of destination */
148
149         adr     r0, _start
150         subs    r9, r6, r0              /* r9 <- relocation offset */
151         beq     relocate_done           /* skip relocation */
152         mov     r1, r6                  /* r1 <- scratch for copy_loop */
153         ldr     r3, _image_copy_end_ofs
154         add     r2, r0, r3              /* r2 <- source end address         */
155
156 copy_loop:
157         ldmia   r0!, {r10-r11}          /* copy from source address [r0]    */
158         stmia   r1!, {r10-r11}          /* copy to   target address [r1]    */
159         cmp     r0, r2                  /* until source end address [r2]    */
160         blo     copy_loop
161
162         /*
163          * fix .rel.dyn relocations
164          */
165         ldr     r0, _TEXT_BASE          /* r0 <- Text base */
166         ldr     r10, _dynsym_start_ofs  /* r10 <- sym table ofs */
167         add     r10, r10, r0            /* r10 <- sym table in FLASH */
168         ldr     r2, _rel_dyn_start_ofs  /* r2 <- rel dyn start ofs */
169         add     r2, r2, r0              /* r2 <- rel dyn start in FLASH */
170         ldr     r3, _rel_dyn_end_ofs    /* r3 <- rel dyn end ofs */
171         add     r3, r3, r0              /* r3 <- rel dyn end in FLASH */
172 fixloop:
173         ldr     r0, [r2]                /* r0 <- location to fix up, IN FLASH! */
174         add     r0, r0, r9              /* r0 <- location to fix up in RAM */
175         ldr     r1, [r2, #4]
176         and     r7, r1, #0xff
177         cmp     r7, #23                 /* relative fixup? */
178         beq     fixrel
179         cmp     r7, #2                  /* absolute fixup? */
180         beq     fixabs
181         /* ignore unknown type of fixup */
182         b       fixnext
183 fixabs:
184         /* absolute fix: set location to (offset) symbol value */
185         mov     r1, r1, LSR #4          /* r1 <- symbol index in .dynsym */
186         add     r1, r10, r1             /* r1 <- address of symbol in table */
187         ldr     r1, [r1, #4]            /* r1 <- symbol value */
188         add     r1, r1, r9              /* r1 <- relocated sym addr */
189         b       fixnext
190 fixrel:
191         /* relative fix: increase location by offset */
192         ldr     r1, [r0]
193         add     r1, r1, r9
194 fixnext:
195         str     r1, [r0]
196         add     r2, r2, #8              /* each rel.dyn entry is 8 bytes */
197         cmp     r2, r3
198         blo     fixloop
199
200 relocate_done:
201
202         bx      lr
203
204 _image_copy_end_ofs:
205         .word __image_copy_end - _start
206 _rel_dyn_start_ofs:
207         .word __rel_dyn_start - _start
208 _rel_dyn_end_ofs:
209         .word __rel_dyn_end - _start
210 _dynsym_start_ofs:
211         .word __dynsym_start - _start
212
213 #endif
214
215         .globl  c_runtime_cpu_setup
216 c_runtime_cpu_setup:
217
218         bx      lr
219
220 /*
221  *************************************************************************
222  *
223  * CPU_init_critical registers
224  *
225  * setup important registers
226  * setup memory timing
227  *
228  *************************************************************************
229  */
230
231 #define INTCON (0x01c00000+0x200000)
232 #define INTMSK (0x01c00000+0x20000c)
233 #define LOCKTIME (0x01c00000+0x18000c)
234 #define PLLCON (0x01c00000+0x180000)
235 #define CLKCON (0x01c00000+0x180004)
236 #define WTCON (0x01c00000+0x130000)
237 cpu_init_crit:
238         /* disable watch dog */
239         ldr     r0, =WTCON
240         ldr     r1, =0x0
241         str     r1, [r0]
242
243         /*
244          * mask all IRQs by clearing all bits in the INTMRs
245          */
246         ldr     r1,=INTMSK
247         ldr     r0, =0x03fffeff
248         str     r0, [r1]
249
250         ldr     r1, =INTCON
251         ldr     r0, =0x05
252         str     r0, [r1]
253
254         /* Set Clock Control Register */
255         ldr     r1, =LOCKTIME
256         ldrb    r0, =800
257         strb    r0, [r1]
258
259         ldr     r1, =PLLCON
260
261 #if CONFIG_S3C44B0_CLOCK_SPEED==66
262         ldr     r0, =0x34031    /* 66MHz (Quartz=11MHz) */
263 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
264         ldr     r0, =0x610c1 /*B2: Xtal=20mhz Fclk=75MHz  */
265 #else
266 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
267 #endif
268
269         str     r0, [r1]
270
271         ldr     r1,=CLKCON
272         ldr     r0, =0x7ff8
273         str     r0, [r1]
274
275         mov     pc, lr
276
277
278 /*************************************************/
279 /*      interrupt vectors       */
280 /*************************************************/
281 real_vectors:
282         b       reset
283         b       undefined_instruction
284         b       software_interrupt
285         b       prefetch_abort
286         b       data_abort
287         b       not_used
288         b       irq
289         b       fiq
290
291 /*************************************************/
292
293 undefined_instruction:
294         mov     r6, #3
295         b       reset
296
297 software_interrupt:
298         mov     r6, #4
299         b       reset
300
301 prefetch_abort:
302         mov     r6, #5
303         b       reset
304
305 data_abort:
306         mov     r6, #6
307         b       reset
308
309 not_used:
310         /* we *should* never reach this */
311         mov     r6, #7
312         b       reset
313
314 irq:
315         mov     r6, #8
316         b       reset
317
318 fiq:
319         mov     r6, #9
320         b       reset