summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s3c2440/crt0.S
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s3c2440/crt0.S')
-rw-r--r--firmware/target/arm/s3c2440/crt0.S355
1 files changed, 355 insertions, 0 deletions
diff --git a/firmware/target/arm/s3c2440/crt0.S b/firmware/target/arm/s3c2440/crt0.S
new file mode 100644
index 0000000000..2c94fc4510
--- /dev/null
+++ b/firmware/target/arm/s3c2440/crt0.S
@@ -0,0 +1,355 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include "cpu.h"
21
22 .section .init.text,"ax",%progbits
23
24 .global start
25start:
26
27/* Arm bootloader and startup code based on startup.s from the iPodLinux loader
28 *
29 * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
30 * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
31 *
32 */
33 msr cpsr, #0xd3 /* enter supervisor mode, disable IRQ */
34
35#if !defined(BOOTLOADER)
36 /* Copy exception handler code to address 0 */
37 ldr r2, =_vectorsstart
38 ldr r3, =_vectorsend
39 ldr r4, =_vectorscopy
401:
41 cmp r3, r2
42 ldrhi r5, [r4], #4
43 strhi r5, [r2], #4
44 bhi 1b
45#endif
46
47#if !defined(BOOTLOADER) && !defined(STUB)
48 /* Zero out IBSS */
49 ldr r2, =_iedata
50 ldr r3, =_iend
51 mov r4, #0
521:
53 cmp r3, r2
54 strhi r4, [r2], #4
55 bhi 1b
56
57 /* Copy the IRAM */
58 ldr r2, =_iramcopy
59 ldr r3, =_iramstart
60 ldr r4, =_iramend
611:
62 cmp r4, r3
63 ldrhi r5, [r2], #4
64 strhi r5, [r3], #4
65 bhi 1b
66#endif /* !BOOTLOADER, !STUB */
67
68 /* Initialise bss section to zero */
69 ldr r2, =_edata
70 ldr r3, =_end
71 mov r4, #0
721:
73 cmp r3, r2
74 strhi r4, [r2], #4
75 bhi 1b
76
77 /* Set up some stack and munge it with 0xdeadbeef */
78 ldr sp, =stackend
79 mov r3, sp
80 ldr r2, =stackbegin
81 ldr r4, =0xdeadbeef
821:
83 cmp r3, r2
84 strhi r4, [r2], #4
85 bhi 1b
86
87#ifdef BOOTLOADER
88/* Code for ARM bootloader targets other than iPod go here */
89
90 /* Proper initialization pulled from 0x5070 */
91
92 /* BWSCON
93 * Reserved 0
94 * Bank 0:
95 * Bus width 01 (16 bit)
96 * Bank 1:
97 * Buswidth 00 (8 bit)
98 * Disable wait 0
99 * Not using UB/LB 0
100 * Bank 2:
101 * Buswidth 10 (32 bit)
102 * Disable wait 0
103 * Not using UB/LB 0
104 * Bank 3:
105 * Buswidth 10 (32 bit)
106 * Disable wait 0
107 * Use UB/LB 1
108 * Bank 4:
109 * Buswidth 10 (32 bit)
110 * Disable wait 0
111 * Use UB/LB 1
112 * Bank 5:
113 * Buswidth 00 (8 bit)
114 * Disable wait 0
115 * Not using UB/LB 0
116 * Bank 6:
117 * Buswidth 10 (32 bit)
118 * Disable wait 0
119 * Not using UB/LB 0
120 * Bank 7:
121 * Buswidth 00 (8 bit)
122 * Disable wait 0
123 * Not using UB/LB 0
124 */
125 ldr r2,=0x01055102
126 mov r1, #0x48000000
127 str r2, [r1]
128
129 /* BANKCON0
130 * Pagemode: normal (1 data) 00
131 * Pagemode access cycle: 2 clocks 00
132 * Address hold: 2 clocks 10
133 * Chip selection hold time: 1 clock 10
134 * Access cycle: 8 clocks 101
135 * Chip select setup time: 1 clock 01
136 * Address setup time: 0 clock 00
137 */
138 ldr r2,=0x00000D60
139 str r2, [r1, #4]
140
141
142 /* BANKCON1
143 * Pagemode: normal (1 data) 00
144 * Pagemode access cycle: 2 clocks 00
145 * Address hold: 0 clocks 00
146 * Chip selection hold time: 0 clock 00
147 * Access cycle: 1 clocks 000
148 * Chip select setup time: 0 clocks 00
149 * Address setup time: 0 clocks 00
150 */
151 ldr r2,=0x00000000
152 str r2, [r1, #8]
153
154 /* BANKCON2
155 * Pagemode: normal (1 data) 00
156 * Pagemode access cycle: 2 clocks 00
157 * Address hold: 2 clocks 10
158 * Chip selection hold time: 2 clocks 10
159 * Access cycle: 14 clocks 111
160 * Chip select setup time: 4 clocks 11
161 * Address setup time: 0 clocks 00
162 */
163 ldr r2,=0x00001FA0
164 str r2, [r1, #0xC]
165
166 /* BANKCON3 */
167 ldr r2,=0x00001D80
168 str r2, [r1, #0x10]
169 /* BANKCON4 */
170 str r2, [r1, #0x14]
171
172 /* BANKCON5 */
173 ldr r2,=0x00000000
174 str r2, [r1, #0x18]
175
176 /* BANKCON6/7
177 * SCAN: 9 bit 01
178 * Trcd: 3 clocks 01
179 * Tcah: 0 clock 00
180 * Tcoh: 0 clock 00
181 * Tacc: 1 clock 000
182 * Tcos: 0 clock 00
183 * Tacs: 0 clock 00
184 * MT: Sync DRAM 11
185 */
186 ldr r2,=0x00018005
187 str r2, [r1, #0x1C]
188 /* BANKCON7 */
189 str r2, [r1, #0x20]
190
191 /* REFRESH */
192 ldr r2,=0x00980501
193 str r2, [r1, #0x24]
194
195 /* BANKSIZE
196 * BK76MAP: 32M/32M 000
197 * Reserved: 0 0 (was 1)
198 * SCLK_EN: always 1 (was 0)
199 * SCKE_EN: disable 0
200 * Reserved: 0 0
201 * BURST_EN: enabled 1
202 */
203 ldr r2,=0x00000090
204 str r2, [r1, #0x28]
205
206 /* MRSRB6 */
207 ldr r2,=0x00000030
208 str r2, [r1, #0x2C]
209 /* MRSRB7 */
210 str r2, [r1, #0x30]
211
212#if 0
213 /* This next part I am not sure of the purpose */
214
215 /* GPACON */
216 mov r2,#0x01FFFCFF
217 str r2,=0x56000000
218
219 /* GPADAT */
220 mov r2,#0x01FFFEFF
221 str r2,=0x56000004
222
223 /* MRSRB6 */
224 mov r2,#0x00000000
225 str r2,=0x4800002C
226
227 /* GPADAT */
228 ldr r2,=0x01FFFFFF
229 mov r1, #0x56000000
230 str r2, [r1, #4]
231
232 /* MRSRB6 */
233 mov r2,#0x00000030
234 str r2,=0x4800002C
235
236 /* GPACON */
237 mov r2,#0x01FFFFFF
238 str r2,=0x56000000
239
240 /* End of the unknown */
241#endif
242
243 /* get the high part of our execute address */
244 ldr r2, =0xffffff00
245 and r4, pc, r2
246
247 /* Copy bootloader to safe area - 0x31000000 */
248 mov r5, #0x30000000
249 add r5, r5, #0x1000000
250 ldr r6, = _dataend
251 sub r0, r6, r5 /* length of loader */
252 add r0, r4, r0 /* r0 points to start of loader */
2531:
254 cmp r5, r6
255 ldrcc r2, [r4], #4
256 strcc r2, [r5], #4
257 bcc 1b
258
259 ldr pc, =start_loc /* jump to the relocated start_loc: */
260
261start_loc:
262 bl main
263
264#else /* BOOTLOADER */
265
266 /* Set up stack for IRQ mode */
267 msr cpsr_c, #0xd2
268 ldr sp, =irq_stack
269 /* Set up stack for FIQ mode */
270 msr cpsr_c, #0xd1
271 ldr sp, =fiq_stack
272
273 /* Let abort and undefined modes use IRQ stack */
274 msr cpsr_c, #0xd7
275 ldr sp, =irq_stack
276 msr cpsr_c, #0xdb
277 ldr sp, =irq_stack
278 /* Switch to supervisor mode */
279 msr cpsr_c, #0xd3
280 ldr sp, =stackend
281 bl main
282 /* main() should never return */
283
284/* Exception handlers. Will be copied to address 0 after memory remapping */
285 .section .vectors,"aw"
286 ldr pc, [pc, #24]
287 ldr pc, [pc, #24]
288 ldr pc, [pc, #24]
289 ldr pc, [pc, #24]
290 ldr pc, [pc, #24]
291 ldr pc, [pc, #24]
292 ldr pc, [pc, #24]
293 ldr pc, [pc, #24]
294
295 /* Exception vectors */
296 .global vectors
297vectors:
298 .word start
299 .word undef_instr_handler
300 .word software_int_handler
301 .word prefetch_abort_handler
302 .word data_abort_handler
303 .word reserved_handler
304 .word irq_handler
305 .word fiq_handler
306
307 .text
308
309#ifndef STUB
310 .global irq
311 .global fiq
312 .global UIE
313#endif
314
315/* All illegal exceptions call into UIE with exception address as first
316 parameter. This is calculated differently depending on which exception
317 we're in. Second parameter is exception number, used for a string lookup
318 in UIE.
319 */
320undef_instr_handler:
321 mov r0, lr
322 mov r1, #0
323 b UIE
324
325/* We run supervisor mode most of the time, and should never see a software
326 exception being thrown. Perhaps make it illegal and call UIE?
327 */
328software_int_handler:
329reserved_handler:
330 movs pc, lr
331
332prefetch_abort_handler:
333 sub r0, lr, #4
334 mov r1, #1
335 b UIE
336
337data_abort_handler:
338 sub r0, lr, #8
339 mov r1, #2
340 b UIE
341
342#ifdef STUB
343UIE:
344 b UIE
345#endif
346
347/* 256 words of IRQ stack */
348 .space 256*4
349irq_stack:
350
351/* 256 words of FIQ stack */
352 .space 256*4
353fiq_stack:
354
355#endif /* BOOTLOADER */