blob: 67b2c6a695576701d72fee325be1da8f2d3f78ee [file] [log] [blame]
wdenkb98ac282004-02-24 00:16:43 +00001/*
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
Wolfgang Denk0191e472010-10-26 14:34:52 +020030#include <asm-offsets.h>
wdenkb98ac282004-02-24 00:16:43 +000031#include <config.h>
32#include <version.h>
33
wdenkb98ac282004-02-24 00:16:43 +000034/*
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
Heiko Schocher296c3ee2010-09-17 13:10:49 +020065.globl _TEXT_BASE
wdenkb98ac282004-02-24 00:16:43 +000066_TEXT_BASE:
Wolfgang Denk0708bc62010-10-07 21:51:12 +020067 .word CONFIG_SYS_TEXT_BASE
wdenkb98ac282004-02-24 00:16:43 +000068
wdenkb98ac282004-02-24 00:16:43 +000069/*
wdenkc35ba4e2004-03-14 22:25:36 +000070 * These are defined in the board-specific linker script.
wdenkb98ac282004-02-24 00:16:43 +000071 */
wdenkc35ba4e2004-03-14 22:25:36 +000072.globl _bss_start
73_bss_start:
74 .word __bss_start
75
76.globl _bss_end
77_bss_end:
78 .word _end
wdenkb98ac282004-02-24 00:16:43 +000079
80#ifdef CONFIG_USE_IRQ
81/* IRQ stack memory (calculated at run-time) */
82.globl IRQ_STACK_START
83IRQ_STACK_START:
84 .word 0x0badc0de
85
86/* IRQ stack memory (calculated at run-time) */
87.globl FIQ_STACK_START
88FIQ_STACK_START:
89 .word 0x0badc0de
90#endif
91
Heiko Schocher296c3ee2010-09-17 13:10:49 +020092/* IRQ stack memory (calculated at run-time) + 8 bytes */
93.globl IRQ_STACK_START_IN
94IRQ_STACK_START_IN:
95 .word 0x0badc0de
96
97.globl _datarel_start
98_datarel_start:
99 .word __datarel_start
100
101.globl _datarelrolocal_start
102_datarelrolocal_start:
103 .word __datarelrolocal_start
104
105.globl _datarellocal_start
106_datarellocal_start:
107 .word __datarellocal_start
108
109.globl _datarelro_start
110_datarelro_start:
111 .word __datarelro_start
112
113.globl _got_start
114_got_start:
115 .word __got_start
116
117.globl _got_end
118_got_end:
119 .word __got_end
120
121/*
122 * the actual reset code
123 */
124
125reset:
126 /*
127 * set the cpu to SVC32 mode
128 */
129 mrs r0,cpsr
130 bic r0,r0,#0x1f
131 orr r0,r0,#0xd3
132 msr cpsr,r0
133
134 /*
135 * we do sys-critical inits only at reboot,
136 * not when booting from ram!
137 */
138#ifndef CONFIG_SKIP_LOWLEVEL_INIT
139 bl cpu_init_crit
140 /*
141 * before relocating, we have to setup RAM timing
142 * because memory timing is board-dependend, you will
143 * find a lowlevel_init.S in your board directory.
144 */
145 bl lowlevel_init
146#endif
147
148/* Set stackpointer in internal RAM to call board_init_f */
149call_board_init_f:
150 ldr sp, =(CONFIG_SYS_INIT_SP_ADDR)
151 ldr r0,=0x00000000
152 bl board_init_f
153
154/*------------------------------------------------------------------------------*/
155
156/*
157 * void relocate_code (addr_sp, gd, addr_moni)
158 *
159 * This "function" does not return, instead it continues in RAM
160 * after relocating the monitor code.
161 *
162 */
163 .globl relocate_code
164relocate_code:
165 mov r4, r0 /* save addr_sp */
166 mov r5, r1 /* save addr of gd */
167 mov r6, r2 /* save addr of destination */
168 mov r7, r2 /* save addr of destination */
169
170 /* Set up the stack */
171stack_setup:
172 mov sp, r4
173
174 adr r0, _start
175 ldr r2, _TEXT_BASE
176 ldr r3, _bss_start
177 sub r2, r3, r2 /* r2 <- size of armboot */
178 add r2, r0, r2 /* r2 <- source end address */
179 cmp r0, r6
180 beq clear_bss
181
Heiko Schocher296c3ee2010-09-17 13:10:49 +0200182copy_loop:
183 ldmia r0!, {r9-r10} /* copy from source address [r0] */
184 stmia r6!, {r9-r10} /* copy to target address [r1] */
Albert Aribaud0668d162010-10-05 16:06:39 +0200185 cmp r0, r2 /* until source end address [r2] */
186 blo copy_loop
Heiko Schocher296c3ee2010-09-17 13:10:49 +0200187
188#ifndef CONFIG_PRELOADER
189 /* fix got entries */
190 ldr r1, _TEXT_BASE /* Text base */
191 mov r0, r7 /* reloc addr */
192 ldr r2, _got_start /* addr in Flash */
193 ldr r3, _got_end /* addr in Flash */
194 sub r3, r3, r1
195 add r3, r3, r0
196 sub r2, r2, r1
197 add r2, r2, r0
198
199fixloop:
200 ldr r4, [r2]
201 sub r4, r4, r1
202 add r4, r4, r0
203 str r4, [r2]
204 add r2, r2, #4
205 cmp r2, r3
Wolfgang Denk98dd07c2010-10-23 23:22:38 +0200206 blo fixloop
Heiko Schocher296c3ee2010-09-17 13:10:49 +0200207#endif
208/*
209 now copy to sram the interrupt vector
210*/
211 adr r0, real_vectors
212 add r2, r0, #1024
213 ldr r1, =0x0c000000
214 add r1, r1, #0x08
215vector_copy_loop:
216 ldmia r0!, {r3-r10}
217 stmia r1!, {r3-r10}
218 cmp r0, r2
Albert Aribaud0668d162010-10-05 16:06:39 +0200219 blo vector_copy_loop
Heiko Schocher296c3ee2010-09-17 13:10:49 +0200220
221clear_bss:
222#ifndef CONFIG_PRELOADER
223 ldr r0, _bss_start
224 ldr r1, _bss_end
225 ldr r3, _TEXT_BASE /* Text base */
226 mov r4, r7 /* reloc addr */
227 sub r0, r0, r3
228 add r0, r0, r4
229 sub r1, r1, r3
230 add r1, r1, r4
231 mov r2, #0x00000000 /* clear */
232
233clbss_l:str r2, [r0] /* clear loop... */
234 add r0, r0, #4
235 cmp r0, r1
236 bne clbss_l
237
238 bl coloured_LED_init
239 bl red_LED_on
240#endif
241
242/*
243 * We are done. Do not return, instead branch to second part of board
244 * initialization, now running from RAM.
245 */
246 ldr r0, _TEXT_BASE
247 ldr r2, _board_init_r
248 sub r2, r2, r0
249 add r2, r2, r7 /* position from board_init_r in RAM */
250 /* setup parameters for board_init_r */
251 mov r0, r5 /* gd_t */
252 mov r1, r7 /* dest_addr */
253 /* jump to it ... */
254 mov lr, r2
255 mov pc, lr
256
257_board_init_r: .word board_init_r
wdenkb98ac282004-02-24 00:16:43 +0000258
wdenkb98ac282004-02-24 00:16:43 +0000259/*
260 *************************************************************************
261 *
262 * CPU_init_critical registers
263 *
264 * setup important registers
265 * setup memory timing
266 *
267 *************************************************************************
268 */
269
270#define INTCON (0x01c00000+0x200000)
271#define INTMSK (0x01c00000+0x20000c)
272#define LOCKTIME (0x01c00000+0x18000c)
273#define PLLCON (0x01c00000+0x180000)
274#define CLKCON (0x01c00000+0x180004)
275#define WTCON (0x01c00000+0x130000)
276cpu_init_crit:
277 /* disable watch dog */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200278 ldr r0, =WTCON
wdenkb98ac282004-02-24 00:16:43 +0000279 ldr r1, =0x0
280 str r1, [r0]
281
282 /*
283 * mask all IRQs by clearing all bits in the INTMRs
284 */
285 ldr r1,=INTMSK
286 ldr r0, =0x03fffeff
287 str r0, [r1]
288
289 ldr r1, =INTCON
290 ldr r0, =0x05
291 str r0, [r1]
292
293 /* Set Clock Control Register */
294 ldr r1, =LOCKTIME
295 ldrb r0, =800
296 strb r0, [r1]
297
298 ldr r1, =PLLCON
299
300#if CONFIG_S3C44B0_CLOCK_SPEED==66
Wolfgang Denka1be4762008-05-20 16:00:29 +0200301 ldr r0, =0x34031 /* 66MHz (Quartz=11MHz) */
wdenkb98ac282004-02-24 00:16:43 +0000302#elif CONFIG_S3C44B0_CLOCK_SPEED==75
303 ldr r0, =0x610c1 /*B2: Xtal=20mhz Fclk=75MHz */
304#else
305# error CONFIG_S3C44B0_CLOCK_SPEED undefined
306#endif
307
308 str r0, [r1]
309
310 ldr r1,=CLKCON
311 ldr r0, =0x7ff8
312 str r0, [r1]
313
314 mov pc, lr
315
316
317/*************************************************/
318/* interrupt vectors */
319/*************************************************/
320real_vectors:
321 b reset
322 b undefined_instruction
323 b software_interrupt
324 b prefetch_abort
325 b data_abort
326 b not_used
327 b irq
328 b fiq
329
330/*************************************************/
331
332undefined_instruction:
333 mov r6, #3
334 b reset
335
336software_interrupt:
337 mov r6, #4
338 b reset
339
340prefetch_abort:
341 mov r6, #5
342 b reset
343
344data_abort:
345 mov r6, #6
346 b reset
347
348not_used:
349 /* we *should* never reach this */
350 mov r6, #7
351 b reset
352
353irq:
354 mov r6, #8
355 b reset
356
357fiq:
358 mov r6, #9
359 b reset