]> git.sur5r.net Git - u-boot/blob - cpu/sa1100/start.S
52f2c5d36e3ba40d1de957a31fe83954e6398057
[u-boot] / cpu / sa1100 / start.S
1 /*
2  *  armboot - Startup Code for SA1100 CPU
3  *
4  *  Copyright (C) 1998  Dan Malek <dmalek@jlc.net>
5  *  Copyright (C) 1999  Magnus Damm <kieraypc01.p.y.kie.era.ericsson.se>
6  *  Copyright (C) 2000  Wolfgang Denk <wd@denx.de>
7  *  Copyright (c) 2001  Alex Züpke <azu@sysgo.de>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28
29 #include <config.h>
30 #include <version.h>
31
32
33 /*
34  *************************************************************************
35  *
36  * Jump vector table as in table 3.1 in [1]
37  *
38  *************************************************************************
39  */
40
41
42 .globl _start
43 _start: b       reset
44         ldr     pc, _undefined_instruction
45         ldr     pc, _software_interrupt
46         ldr     pc, _prefetch_abort
47         ldr     pc, _data_abort
48         ldr     pc, _not_used
49         ldr     pc, _irq
50         ldr     pc, _fiq
51
52 _undefined_instruction: .word undefined_instruction
53 _software_interrupt:    .word software_interrupt
54 _prefetch_abort:        .word prefetch_abort
55 _data_abort:            .word data_abort
56 _not_used:              .word not_used
57 _irq:                   .word irq
58 _fiq:                   .word fiq
59
60         .balignl 16,0xdeadbeef
61
62
63 /*
64  *************************************************************************
65  *
66  * Startup Code (reset vector)
67  *
68  * do important init only if we don't start from memory!
69  * relocate armboot to ram
70  * setup stack
71  * jump to second stage
72  *
73  *************************************************************************
74  */
75
76 _TEXT_BASE:
77         .word   TEXT_BASE
78
79 .globl _armboot_start
80 _armboot_start:
81         .word _start
82
83 /*
84  * These are defined in the board-specific linker script.
85  */
86 .globl _bss_start
87 _bss_start:
88         .word __bss_start
89
90 .globl _bss_end
91 _bss_end:
92         .word _end
93
94 #ifdef CONFIG_USE_IRQ
95 /* IRQ stack memory (calculated at run-time) */
96 .globl IRQ_STACK_START
97 IRQ_STACK_START:
98         .word   0x0badc0de
99
100 /* IRQ stack memory (calculated at run-time) */
101 .globl FIQ_STACK_START
102 FIQ_STACK_START:
103         .word 0x0badc0de
104 #endif
105
106
107 /*
108  * the actual reset code
109  */
110
111 reset:
112         /*
113          * set the cpu to SVC32 mode
114          */
115         mrs     r0,cpsr
116         bic     r0,r0,#0x1f
117         orr     r0,r0,#0x13
118         msr     cpsr,r0
119
120         /*
121          * we do sys-critical inits only at reboot,
122          * not when booting from ram!
123          */
124 #ifdef CONFIG_INIT_CRITICAL
125         bl      cpu_init_crit
126 #endif
127
128 relocate:                               /* relocate U-Boot to RAM           */
129         adr     r0, _start              /* r0 <- current position of code   */
130         ldr     r1, _TEXT_BASE          /* test if we run from flash or RAM */
131         cmp     r0, r1                  /* don't reloc during debug         */
132         beq     stack_setup
133
134         ldr     r2, _armboot_start
135         ldr     r3, _bss_start
136         sub     r2, r3, r2              /* r2 <- size of armboot            */
137         add     r2, r0, r2              /* r2 <- source end address         */
138
139 copy_loop:
140         ldmia   r0!, {r3-r10}           /* copy from source address [r0]    */
141         stmia   r1!, {r3-r10}           /* copy to   target address [r1]    */
142         cmp     r0, r2                  /* until source end addreee [r2]    */
143         ble     copy_loop
144
145         /* Set up the stack                                                 */
146 stack_setup:
147         ldr     r0, _TEXT_BASE          /* upper 128 KiB: relocated uboot   */
148         sub     r0, r0, #CFG_MALLOC_LEN /* malloc area                      */
149         sub     r0, r0, #CFG_GBL_DATA_SIZE /* bdinfo                        */
150 #ifdef CONFIG_USE_IRQ
151         sub     r0, r0, #(CONFIG_STACKSIZE_IRQ+CONFIG_STACKSIZE_FIQ)
152 #endif
153         sub     sp, r0, #12             /* leave 3 words for abort-stack    */
154
155 clear_bss:
156         ldr     r0, _bss_start          /* find start of bss segment        */
157         ldr     r1, _bss_end            /* stop here                        */
158         mov     r2, #0x00000000         /* clear                            */
159
160 clbss_l:str     r2, [r0]                /* clear loop...                    */
161         add     r0, r0, #4
162         cmp     r0, r1
163         bne     clbss_l
164
165         ldr     pc, _start_armboot
166
167 _start_armboot: .word start_armboot
168
169
170 /*
171  *************************************************************************
172  *
173  * CPU_init_critical registers
174  *
175  * setup important registers
176  * setup memory timing
177  *
178  *************************************************************************
179  */
180
181
182 /* Interupt-Controller base address */
183 IC_BASE:        .word   0x90050000
184 #define ICMR    0x04
185
186
187 /* Reset-Controller */
188 RST_BASE:               .word   0x90030000
189 #define RSRR    0x00
190 #define RCSR    0x04
191
192
193 /* PWR */
194 PWR_BASE:               .word   0x90020000
195 #define PSPR    0x08
196 #define PPCR    0x14
197 cpuspeed:               .word   CFG_CPUSPEED
198
199
200 cpu_init_crit:
201         /*
202          * mask all IRQs
203          */
204         ldr     r0, IC_BASE
205         mov     r1, #0x00
206         str     r1, [r0, #ICMR]
207
208         /* set clock speed */
209         ldr     r0, PWR_BASE
210         ldr     r1, cpuspeed
211         str     r1, [r0, #PPCR]
212
213         /*
214          * before relocating, we have to setup RAM timing
215          * because memory timing is board-dependend, you will
216          * find a memsetup.S in your board directory.
217          */
218         mov     ip,     lr
219         bl      memsetup
220         mov     lr,     ip
221
222         /*
223          * disable MMU stuff and enable I-cache
224          */
225         mrc     p15,0,r0,c1,c0
226         bic     r0, r0, #0x00002000     @ clear bit 13 (X)
227         bic     r0, r0, #0x0000000f     @ clear bits 3-0 (WCAM)
228         orr     r0, r0, #0x00001000     @ set bit 12 (I) Icache
229         orr     r0, r0, #0x00000002     @ set bit 2 (A) Align
230         mcr     p15,0,r0,c1,c0
231
232         /*
233          * flush v4 I/D caches
234          */
235         mov     r0, #0
236         mcr     p15, 0, r0, c7, c7, 0   /* flush v3/v4 cache */
237         mcr     p15, 0, r0, c8, c7, 0   /* flush v4 TLB */
238
239         mov     pc, lr
240
241
242 /*
243  *************************************************************************
244  *
245  * Interrupt handling
246  *
247  *************************************************************************
248  */
249
250 @
251 @ IRQ stack frame.
252 @
253 #define S_FRAME_SIZE    72
254
255 #define S_OLD_R0        68
256 #define S_PSR           64
257 #define S_PC            60
258 #define S_LR            56
259 #define S_SP            52
260
261 #define S_IP            48
262 #define S_FP            44
263 #define S_R10           40
264 #define S_R9            36
265 #define S_R8            32
266 #define S_R7            28
267 #define S_R6            24
268 #define S_R5            20
269 #define S_R4            16
270 #define S_R3            12
271 #define S_R2            8
272 #define S_R1            4
273 #define S_R0            0
274
275 #define MODE_SVC 0x13
276 #define I_BIT    0x80
277
278 /*
279  * use bad_save_user_regs for abort/prefetch/undef/swi ...
280  * use irq_save_user_regs / irq_restore_user_regs for IRQ/FIQ handling
281  */
282
283         .macro  bad_save_user_regs
284         sub     sp, sp, #S_FRAME_SIZE
285         stmia   sp, {r0 - r12}                  @ Calling r0-r12
286         add     r8, sp, #S_PC
287
288         ldr     r2, _armboot_start
289         sub     r2, r2, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
290         sub     r2, r2, #(CFG_GBL_DATA_SIZE+8)  @ set base 2 words into abort stack
291         ldmia   r2, {r2 - r4}                   @ get pc, cpsr, old_r0
292         add     r0, sp, #S_FRAME_SIZE           @ restore sp_SVC
293
294         add     r5, sp, #S_SP
295         mov     r1, lr
296         stmia   r5, {r0 - r4}                   @ save sp_SVC, lr_SVC, pc, cpsr, old_r
297         mov     r0, sp
298         .endm
299
300         .macro  irq_save_user_regs
301         sub     sp, sp, #S_FRAME_SIZE
302         stmia   sp, {r0 - r12}                  @ Calling r0-r12
303         add     r8, sp, #S_PC
304         stmdb   r8, {sp, lr}^                   @ Calling SP, LR
305         str     lr, [r8, #0]                    @ Save calling PC
306         mrs     r6, spsr
307         str     r6, [r8, #4]                    @ Save CPSR
308         str     r0, [r8, #8]                    @ Save OLD_R0
309         mov     r0, sp
310         .endm
311
312         .macro  irq_restore_user_regs
313         ldmia   sp, {r0 - lr}^                  @ Calling r0 - lr
314         mov     r0, r0
315         ldr     lr, [sp, #S_PC]                 @ Get PC
316         add     sp, sp, #S_FRAME_SIZE
317         subs    pc, lr, #4                      @ return & move spsr_svc into cpsr
318         .endm
319
320         .macro get_bad_stack
321         ldr     r13, _armboot_start             @ setup our mode stack
322         sub     r13, r13, #(CONFIG_STACKSIZE+CFG_MALLOC_LEN)
323         sub     r13, r13, #(CFG_GBL_DATA_SIZE+8) @ reserved a couple spots in abort stack
324
325         str     lr, [r13]                       @ save caller lr / spsr
326         mrs     lr, spsr
327         str     lr, [r13, #4]
328
329         mov     r13, #MODE_SVC                  @ prepare SVC-Mode
330         msr     spsr_c, r13
331         mov     lr, pc
332         movs    pc, lr
333         .endm
334
335         .macro get_irq_stack                    @ setup IRQ stack
336         ldr     sp, IRQ_STACK_START
337         .endm
338
339         .macro get_fiq_stack                    @ setup FIQ stack
340         ldr     sp, FIQ_STACK_START
341         .endm
342
343 /*
344  * exception handlers
345  */
346         .align  5
347 undefined_instruction:
348         get_bad_stack
349         bad_save_user_regs
350         bl      do_undefined_instruction
351
352         .align  5
353 software_interrupt:
354         get_bad_stack
355         bad_save_user_regs
356         bl      do_software_interrupt
357
358         .align  5
359 prefetch_abort:
360         get_bad_stack
361         bad_save_user_regs
362         bl      do_prefetch_abort
363
364         .align  5
365 data_abort:
366         get_bad_stack
367         bad_save_user_regs
368         bl      do_data_abort
369
370         .align  5
371 not_used:
372         get_bad_stack
373         bad_save_user_regs
374         bl      do_not_used
375
376 #ifdef CONFIG_USE_IRQ
377
378         .align  5
379 irq:
380         get_irq_stack
381         irq_save_user_regs
382         bl      do_irq
383         irq_restore_user_regs
384
385         .align  5
386 fiq:
387         get_fiq_stack
388         /* someone ought to write a more effiction fiq_save_user_regs */
389         irq_save_user_regs
390         bl      do_fiq
391         irq_restore_user_regs
392
393 #else
394
395         .align  5
396 irq:
397         get_bad_stack
398         bad_save_user_regs
399         bl      do_irq
400
401         .align  5
402 fiq:
403         get_bad_stack
404         bad_save_user_regs
405         bl      do_fiq
406
407 #endif
408
409         .align  5
410 .globl reset_cpu
411 reset_cpu:
412         ldr     r0, RST_BASE
413         mov     r1, #0x0                        @ set bit 3-0 ...
414         str     r1, [r0, #RCSR]                 @ ... to clear in RCSR
415         mov     r1, #0x1
416         str     r1, [r0, #RSRR]                 @ and perform reset
417         b       reset_cpu                       @ silly, but repeat endlessly