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