]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/s3c44b0/start.S
Merge branch 'master' of /home/wd/git/u-boot/custodians
[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         .word   CONFIG_SYS_TEXT_BASE
68
69 /*
70  * These are defined in the board-specific linker script.
71  * Subtracting _start from them lets the linker put their
72  * relative position in the executable instead of leaving
73  * them null.
74  */
75 .globl _bss_start_ofs
76 _bss_start_ofs:
77         .word __bss_start - _start
78
79 .globl _bss_end_ofs
80 _bss_end_ofs:
81         .word _end - _start
82
83 #ifdef CONFIG_USE_IRQ
84 /* IRQ stack memory (calculated at run-time) */
85 .globl IRQ_STACK_START
86 IRQ_STACK_START:
87         .word   0x0badc0de
88
89 /* IRQ stack memory (calculated at run-time) */
90 .globl FIQ_STACK_START
91 FIQ_STACK_START:
92         .word 0x0badc0de
93 #endif
94
95 /* IRQ stack memory (calculated at run-time) + 8 bytes */
96 .globl IRQ_STACK_START_IN
97 IRQ_STACK_START_IN:
98         .word   0x0badc0de
99
100 /*
101  * the actual reset code
102  */
103
104 reset:
105         /*
106          * set the cpu to SVC32 mode
107          */
108         mrs     r0,cpsr
109         bic     r0,r0,#0x1f
110         orr     r0,r0,#0xd3
111         msr     cpsr,r0
112
113         /*
114          * we do sys-critical inits only at reboot,
115          * not when booting from ram!
116          */
117 #ifndef CONFIG_SKIP_LOWLEVEL_INIT
118         bl      cpu_init_crit
119         /*
120          * before relocating, we have to setup RAM timing
121          * because memory timing is board-dependend, you will
122          * find a lowlevel_init.S in your board directory.
123          */
124         bl      lowlevel_init
125 #endif
126
127 /* Set stackpointer in internal RAM to call board_init_f */
128 call_board_init_f:
129         ldr     sp, =(CONFIG_SYS_INIT_SP_ADDR)
130         ldr     r0,=0x00000000
131         bl      board_init_f
132
133 /*------------------------------------------------------------------------------*/
134
135 /*
136  * void relocate_code (addr_sp, gd, addr_moni)
137  *
138  * This "function" does not return, instead it continues in RAM
139  * after relocating the monitor code.
140  *
141  */
142         .globl  relocate_code
143 relocate_code:
144         mov     r4, r0  /* save addr_sp */
145         mov     r5, r1  /* save addr of gd */
146         mov     r6, r2  /* save addr of destination */
147         mov     r7, r2  /* save addr of destination */
148
149         /* Set up the stack                                                 */
150 stack_setup:
151         mov     sp, r4
152
153         adr     r0, _start
154         ldr     r2, _TEXT_BASE
155         ldr     r3, _bss_start_ofs
156         add     r2, r0, r3              /* r2 <- source end address         */
157         cmp     r0, r6
158         beq     clear_bss
159
160 copy_loop:
161         ldmia   r0!, {r9-r10}           /* copy from source address [r0]    */
162         stmia   r6!, {r9-r10}           /* copy to   target address [r1]    */
163         cmp     r0, r2                  /* until source end address [r2]    */
164         blo     copy_loop
165
166 #ifndef CONFIG_PRELOADER
167         /*
168          * fix .rel.dyn relocations
169          */
170         ldr     r0, _TEXT_BASE          /* r0 <- Text base */
171         sub     r9, r7, r0              /* r9 <- relocation offset */
172         ldr     r10, _dynsym_start_ofs  /* r10 <- sym table ofs */
173         add     r10, r10, r0            /* r10 <- sym table in FLASH */
174         ldr     r2, _rel_dyn_start_ofs  /* r2 <- rel dyn start ofs */
175         add     r2, r2, r0              /* r2 <- rel dyn start in FLASH */
176         ldr     r3, _rel_dyn_end_ofs    /* r3 <- rel dyn end ofs */
177         add     r3, r3, r0              /* r3 <- rel dyn end in FLASH */
178 fixloop:
179         ldr     r0, [r2]                /* r0 <- location to fix up, IN FLASH! */
180         add     r0, r0, r9              /* r0 <- location to fix up in RAM */
181         ldr     r1, [r2, #4]
182         and     r8, r1, #0xff
183         cmp     r8, #23                 /* relative fixup? */
184         beq     fixrel
185         cmp     r8, #2                  /* absolute fixup? */
186         beq     fixabs
187         /* ignore unknown type of fixup */
188         b       fixnext
189 fixabs:
190         /* absolute fix: set location to (offset) symbol value */
191         mov     r1, r1, LSR #4          /* r1 <- symbol index in .dynsym */
192         add     r1, r10, r1             /* r1 <- address of symbol in table */
193         ldr     r1, [r1, #4]            /* r1 <- symbol value */
194         add     r1, r9                  /* r1 <- relocated sym addr */
195         b       fixnext
196 fixrel:
197         /* relative fix: increase location by offset */
198         ldr     r1, [r0]
199         add     r1, r1, r9
200 fixnext:
201         str     r1, [r0]
202         add     r2, r2, #8              /* each rel.dyn entry is 8 bytes */
203         cmp     r2, r3
204         blo     fixloop
205 #endif
206
207 clear_bss:
208 #ifndef CONFIG_PRELOADER
209         ldr     r0, _bss_start_ofs
210         ldr     r1, _bss_end_ofs
211         ldr     r3, _TEXT_BASE          /* Text base */
212         mov     r4, r7                  /* reloc addr */
213         add     r0, r0, r4
214         add     r1, r1, r4
215         mov     r2, #0x00000000         /* clear                            */
216
217 clbss_l:str     r2, [r0]                /* clear loop...                    */
218         add     r0, r0, #4
219         cmp     r0, r1
220         bne     clbss_l
221
222         bl coloured_LED_init
223         bl red_LED_on
224 #endif
225
226 /*
227  * We are done. Do not return, instead branch to second part of board
228  * initialization, now running from RAM.
229  */
230         ldr     r0, _board_init_r_ofs
231         adr     r1, _start
232         add     lr, r0, r1
233         add     lr, lr, r9
234         /* setup parameters for board_init_r */
235         mov     r0, r5          /* gd_t */
236         mov     r1, r7          /* dest_addr */
237         /* jump to it ... */
238         mov     pc, lr
239
240 _board_init_r_ofs:
241         .word board_init_r - _start
242
243 _rel_dyn_start_ofs:
244         .word __rel_dyn_start - _start
245 _rel_dyn_end_ofs:
246         .word __rel_dyn_end - _start
247 _dynsym_start_ofs:
248         .word __dynsym_start - _start
249
250 /*
251  *************************************************************************
252  *
253  * CPU_init_critical registers
254  *
255  * setup important registers
256  * setup memory timing
257  *
258  *************************************************************************
259  */
260
261 #define INTCON (0x01c00000+0x200000)
262 #define INTMSK (0x01c00000+0x20000c)
263 #define LOCKTIME (0x01c00000+0x18000c)
264 #define PLLCON (0x01c00000+0x180000)
265 #define CLKCON (0x01c00000+0x180004)
266 #define WTCON (0x01c00000+0x130000)
267 cpu_init_crit:
268         /* disable watch dog */
269         ldr     r0, =WTCON
270         ldr     r1, =0x0
271         str     r1, [r0]
272
273         /*
274          * mask all IRQs by clearing all bits in the INTMRs
275          */
276         ldr     r1,=INTMSK
277         ldr     r0, =0x03fffeff
278         str     r0, [r1]
279
280         ldr     r1, =INTCON
281         ldr     r0, =0x05
282         str     r0, [r1]
283
284         /* Set Clock Control Register */
285         ldr     r1, =LOCKTIME
286         ldrb    r0, =800
287         strb    r0, [r1]
288
289         ldr     r1, =PLLCON
290
291 #if CONFIG_S3C44B0_CLOCK_SPEED==66
292         ldr     r0, =0x34031    /* 66MHz (Quartz=11MHz) */
293 #elif CONFIG_S3C44B0_CLOCK_SPEED==75
294         ldr     r0, =0x610c1 /*B2: Xtal=20mhz Fclk=75MHz  */
295 #else
296 # error CONFIG_S3C44B0_CLOCK_SPEED undefined
297 #endif
298
299         str     r0, [r1]
300
301         ldr     r1,=CLKCON
302         ldr     r0, =0x7ff8
303         str     r0, [r1]
304
305         mov     pc, lr
306
307
308 /*************************************************/
309 /*      interrupt vectors       */
310 /*************************************************/
311 real_vectors:
312         b       reset
313         b       undefined_instruction
314         b       software_interrupt
315         b       prefetch_abort
316         b       data_abort
317         b       not_used
318         b       irq
319         b       fiq
320
321 /*************************************************/
322
323 undefined_instruction:
324         mov     r6, #3
325         b       reset
326
327 software_interrupt:
328         mov     r6, #4
329         b       reset
330
331 prefetch_abort:
332         mov     r6, #5
333         b       reset
334
335 data_abort:
336         mov     r6, #6
337         b       reset
338
339 not_used:
340         /* we *should* never reach this */
341         mov     r6, #7
342         b       reset
343
344 irq:
345         mov     r6, #8
346         b       reset
347
348 fiq:
349         mov     r6, #9
350         b       reset