Fix include problem
[kugel-rb.git] / firmware / target / arm / crt0.S
blob001d651a61afaa38a9aa34924648a7bdc5c0b525
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)
62 #define CACHE_NONE  0
63 #define CACHE_ALL   0x0C
64 #define UNCACHED_ADDR(a) (a + 0x10000000)
66     /* Setup MMU : has to be done before accessing IRAM ! */
68     bl      ttb_init
70     mov     r0, #0                          @ physical address
71     mov     r1, #0                          @ virtual address
72     mov     r2, #0x1000                     @ size (all memory)
73     mov     r3, #CACHE_NONE
74     bl      map_section
76     mov     r0, #0                          @ physical address
77     ldr     r1, =IRAM_ORIG                  @ virtual address
78     mov     r2, #1                          @ size : 1MB
79     mov     r3, #CACHE_ALL
80     bl      map_section
82     mov     r0, #0                          @ physical address
83     ldr     r1, =UNCACHED_ADDR(IRAM_ORIG)   @ virtual address
84     mov     r2, #1                          @ size : 1MB
85     mov     r3, #CACHE_NONE
86     bl      map_section
88     mov     r0, #0x30000000                 @ physical address
89     mov     r1, #DRAM_ORIG                  @ virtual address
90     mov     r2, #MEMORYSIZE                 @ size
91     mov     r3, #CACHE_ALL
92     bl      map_section
94     mov     r0, #0x30000000                 @ physical address
95     mov     r1, #UNCACHED_ADDR(DRAM_ORIG)   @ virtual address
96     mov     r2, #MEMORYSIZE                 @ size
97     mov     r3, #CACHE_NONE
98     bl      map_section
100     /* map 1st mbyte of DRAM at 0x0 to have exception vectors available */
102     mov     r0, #0x30000000                 @ physical address
103     mov     r1, #0                          @ virtual address
104     mov     r2, #1                          @ size
105     mov     r3, #CACHE_ALL
106     bl      map_section
108     bl      enable_mmu
110     /* Zero out IBSS */
111     ldr     r2, =_iedata
112     ldr     r3, =_iend
113     mov     r4, #0
115     cmp     r3, r2
116     strhi   r4, [r2], #4
117     bhi     1b
119     /* Copy the IRAM */
120     /* must be done before bss is zeroed */
121     ldr     r2, =_iramcopy
122     ldr     r3, =_iramstart
123     ldr     r4, =_iramend
125     cmp     r4, r3
126     ldrhi   r5, [r2], #4
127     strhi   r5, [r3], #4
128     bhi     1b
130 #endif
132 #ifdef HAVE_INIT_ATTR
133     /* copy init data to codec buffer */
134     /* must be done before bss is zeroed */
135     ldr    r2, =_initcopy
136     ldr    r3, =_initstart
137     ldr    r4, =_initend
139     cmp     r4, r3
140     ldrhi   r5, [r2], #4
141     strhi   r5, [r3], #4
142     bhi     1b
144     mov     r2, #0
145     mcr     p15, 0, r2, c7, c5, 0   @ Invalidate ICache
146 #endif
148     /* Initialise bss section to zero */
149     ldr     r2, =_edata
150     ldr     r3, =_end
151     mov     r4, #0
153     cmp     r3, r2
154     strhi   r4, [r2], #4
155     bhi     1b
157     /* Set up some stack and munge it with 0xdeadbeef */
158     ldr     sp, =stackend
159     ldr     r2, =stackbegin
160     ldr     r3, =0xdeadbeef
162     cmp     sp, r2
163     strhi   r3, [r2], #4
164     bhi     1b
165     
166     /* Set up stack for IRQ mode */ 
167     msr     cpsr_c, #0xd2
168     ldr     sp, =irq_stack
170     /* Set up stack for FIQ mode */ 
171     msr     cpsr_c, #0xd1
172     ldr     sp, =fiq_stack
174     /* Let abort and undefined modes use IRQ stack */
175     msr     cpsr_c, #0xd7
176     ldr     sp, =irq_stack
177     msr     cpsr_c, #0xdb
178     ldr     sp, =irq_stack
180     /* Switch back to supervisor mode */
181     msr     cpsr_c, #0xd3
182     bl      main
185 /* All illegal exceptions call into UIE with exception address as first
186  * parameter. This is calculated differently depending on which exception
187  * we're in. Second parameter is exception number, used for a string lookup
188  * in UIE. */
189 undef_instr_handler:
190     sub    r0, lr, #4
191     mov    r1, #0
192     b      UIE
194 /* We run supervisor mode most of the time, and should never see a software
195  * exception being thrown. Perhaps make it illegal and call UIE? */
196 software_int_handler:
197 reserved_handler:
198     movs   pc, lr
200 prefetch_abort_handler:
201     sub    r0, lr, #4
202     mov    r1, #1
203     b      UIE
205 data_abort_handler:
206     sub    r0, lr, #8 
207     mov    r1, #2
208     b      UIE
210 /* 256 words of IRQ stack */
211     .space 256*4
212 irq_stack:
214 /* 256 words of FIQ stack */
215     .space 256*4
216 fiq_stack:
218 end: