Really fix bootloaders now.
[kugel-rb.git] / firmware / target / arm / crt0.S
blobcb8242c72e4162b906284b089f2a3a48a7bc011b
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2008 by Marcoen Hirschberg
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
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18  * KIND, either express or implied.
19  *
20  ****************************************************************************/
21 #include "config.h"
22 #include "cpu.h"
24     .section .init.text,"ax",%progbits
26     .global    start
27 start:
28     /* Exception vectors */
29     ldr     pc, [pc, #28]
30     ldr     pc, [pc, #28]
31     ldr     pc, [pc, #28]
32     ldr     pc, [pc, #28]
33     ldr     pc, [pc, #28]
34     ldr     pc, [pc, #28]
35     ldr     pc, [pc, #28]
36     ldr     pc, [pc, #28]
38 #if CONFIG_CPU==S5L8700
39     .word 0x43554644 /* DFUC */
40 #else
41     .word 0xdeadbeef /* to keep the same PC offsets */
42 #endif
44 .word newstart
45 .word undef_instr_handler
46 .word software_int_handler
47 .word prefetch_abort_handler
48 .word data_abort_handler
49 .word reserved_handler
50 .word irq_handler
51 .word fiq_handler
53 _vectorsend:
55     .text
57 newstart:
58     msr     cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
60 #if (CONFIG_CPU==AS3525 || CONFIG_CPU==AS3525v2) && !defined(BOOTLOADER)
61     /* Setup MMU : has to be done before accessing IRAM ! */
62     bl      memory_init
64     /* Zero out IBSS */
65     ldr     r2, =_iedata
66     ldr     r3, =_iend
67     mov     r4, #0
69     cmp     r3, r2
70     strhi   r4, [r2], #4
71     bhi     1b
73     /* Copy the IRAM */
74     /* must be done before bss is zeroed */
75     ldr     r2, =_iramcopy
76     ldr     r3, =_iramstart
77     ldr     r4, =_iramend
79     cmp     r4, r3
80     ldrhi   r5, [r2], #4
81     strhi   r5, [r3], #4
82     bhi     1b
84 #endif
86 #ifdef HAVE_INIT_ATTR
87     /* copy init data to codec buffer */
88     /* must be done before bss is zeroed */
89     ldr    r2, =_initcopy
90     ldr    r3, =_initstart
91     ldr    r4, =_initend
93     cmp     r4, r3
94     ldrhi   r5, [r2], #4
95     strhi   r5, [r3], #4
96     bhi     1b
98     mov     r2, #0
99     mcr     p15, 0, r2, c7, c5, 0   @ Invalidate ICache
100 #endif
102     /* Initialise bss section to zero */
103     ldr     r2, =_edata
104     ldr     r3, =_end
105     mov     r4, #0
107     cmp     r3, r2
108     strhi   r4, [r2], #4
109     bhi     1b
111     /* Set up some stack and munge it with 0xdeadbeef */
112     ldr     sp, =stackend
113     ldr     r2, =stackbegin
114     ldr     r3, =0xdeadbeef
116     cmp     sp, r2
117     strhi   r3, [r2], #4
118     bhi     1b
119     
120     /* Set up stack for IRQ mode */ 
121     msr     cpsr_c, #0xd2
122     ldr     sp, =irq_stack
124     /* Set up stack for FIQ mode */ 
125     msr     cpsr_c, #0xd1
126     ldr     sp, =fiq_stack
128     /* Let abort and undefined modes use IRQ stack */
129     msr     cpsr_c, #0xd7
130     ldr     sp, =irq_stack
131     msr     cpsr_c, #0xdb
132     ldr     sp, =irq_stack
134     /* Switch back to supervisor mode */
135     msr     cpsr_c, #0xd3
136     bl      main
139 /* All illegal exceptions call into UIE with exception address as first
140  * parameter. This is calculated differently depending on which exception
141  * we're in. Second parameter is exception number, used for a string lookup
142  * in UIE. */
143 undef_instr_handler:
144     sub    r0, lr, #4
145     mov    r1, #0
146     b      UIE
148 /* We run supervisor mode most of the time, and should never see a software
149  * exception being thrown. Perhaps make it illegal and call UIE? */
150 software_int_handler:
151 reserved_handler:
152     movs   pc, lr
154 prefetch_abort_handler:
155     sub    r0, lr, #4
156     mov    r1, #1
157     b      UIE
159 data_abort_handler:
160     sub    r0, lr, #8 
161     mov    r1, #2
162     b      UIE
164 /* 256 words of IRQ stack */
165     .space 256*4
166 irq_stack:
168 /* 256 words of FIQ stack */
169     .space 256*4
170 fiq_stack:
172 end: