Move c/h files implementing/defining standard library stuff into a new libc directory...
[kugel-rb.git] / firmware / target / arm / pnx0101 / crt0-pnx0101.S
blobc8c4232a3a6a4bbad60508ed6ee599b8aace72a3
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id: crt0.S 11850 2006-12-29 02:49:12Z markun $
9  *
10  * Copyright (C) 2002 by Linus Nielsen Feltzing
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 #define ASM  /* do not include structure definitions from pnx0101.h */
23 #include "config.h"
24 #include "cpu.h"
26     .section .init.text,"ax",%progbits
28     .global    start
29 start:
31 /* Arm bootloader and startup code based on startup.s from the iPodLinux loader
32  *
33  * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
34  * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
35  *
36  */
38     msr    cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ */
40 #ifndef BOOTLOADER
41 #ifndef DEBUG
42     ldr    r0, =0x80105000
43     mov    r1, #1
44     str    r1, [r0, #4]
45     mov    r1, #0
46     str    r1, [r0, #4]
47 1:  ldr    r1, [r0]
48     cmp    r1, #0
49     bne    1b
50     mov    r1, #0x74
51     str    r1, [r0, #8]
52     mov    r1, #2
53     str    r1, [r0, #0x18]
54     mov    r1, #2
55     str    r1, [r0, #0x20]
56     mov    r1, #82
57     str    r1, [r0, #0x28]
58     mov    r1, #100
59     str    r1, [r0, #0x2c]
60     mov    r1, #0x120
61     str    r1, [r0, #0x30]
62     mov    r1, #6
63     str    r1, [r0, #4]
64     ldr    r0, =1f
65     mov    r15, r0
67 #endif /* !DEBUG */
69 #ifndef DEBUG
70     /* Copy exception handler code to address 0 */
71     ldr    r2, =_vectorsstart
72     ldr    r3, =_vectorsend
73     ldr    r4, =_vectorscopy
75     cmp    r3, r2
76     ldrhi  r5, [r4], #4
77     strhi  r5, [r2], #4
78     bhi    1b
79 #else
80     ldr    r1, =vectors
81     ldr    r0, =irq_handler
82     str    r0, [r1, #24]
83     ldr    r0, =fiq_handler
84     str    r0, [r1, #28]
85 #endif
86     
87 #ifndef STUB
88     /* Zero out IBSS */
89     ldr    r2, =_iedata
90     ldr    r3, =_iend
91     mov    r4, #0
93     cmp    r3, r2
94     strhi  r4, [r2], #4
95     bhi    1b
97     /* Copy the IRAM */
98     ldr    r2, =_iramcopy
99     ldr    r3, =_iramstart
100     ldr    r4, =_iramend
102     cmp    r4, r3
103     ldrhi  r5, [r2], #4
104     strhi  r5, [r3], #4
105     bhi    1b
106 #endif /* !STUB */
107 #endif /* !BOOTLOADER */
109     /* Initialise bss section to zero */
110     ldr    r2, =_edata
111     ldr    r3, =_end
112     mov    r4, #0
114     cmp    r3, r2
115     strhi  r4, [r2], #4
116     bhi    1b
117     
118     /* Set up some stack and munge it with 0xdeadbeef */
119     ldr    sp, =stackend
120     mov    r3, sp
121     ldr    r2, =stackbegin
122     ldr    r4, =0xdeadbeef
124     cmp    r3, r2
125     strhi  r4, [r2], #4
126     bhi    1b
128     /* Set up stack for IRQ mode */ 
129     msr    cpsr_c, #0xd2
130     ldr    sp, =irq_stack
131     /* Set up stack for FIQ mode */ 
132     msr    cpsr_c, #0xd1
133     ldr    sp, =fiq_stack
135     /* Let abort and undefined modes use IRQ stack */
136     msr    cpsr_c, #0xd7
137     ldr    sp, =irq_stack
138     msr    cpsr_c, #0xdb
139     ldr    sp, =irq_stack
140     /* Switch to supervisor mode */
141     msr    cpsr_c, #0xd3
142     ldr    sp, =stackend
143     bl     main
144     /* main() should never return */
145    
146 /* Exception handlers. Will be copied to address 0 after memory remapping */
147     .section .vectors,"aw"
148     ldr    pc, [pc, #24]
149     ldr    pc, [pc, #24]
150     ldr    pc, [pc, #24]
151     ldr    pc, [pc, #24]
152     ldr    pc, [pc, #24]
153     ldr    pc, [pc, #24]
154     ldr    pc, [pc, #24]
155     ldr    pc, [pc, #24]
157     /* Exception vectors */
158     .global vectors
159 vectors:
160     .word  start 
161     .word  undef_instr_handler
162     .word  software_int_handler
163     .word  prefetch_abort_handler
164     .word  data_abort_handler
165     .word  reserved_handler
166     .word  irq_handler
167     .word  fiq_handler
169     .text
171 /* All illegal exceptions call into UIE with exception address as first
172    parameter. This is calculated differently depending on which exception
173    we're in. Second parameter is exception number, used for a string lookup
174    in UIE.
175  */
176 undef_instr_handler:
177     sub    r0, lr, #4
178     mov    r1, #0
179     b      UIE
181 /* We run supervisor mode most of the time, and should never see a software
182    exception being thrown. Perhaps make it illegal and call UIE?
183  */
184 software_int_handler:
185 reserved_handler:
186     movs   pc, lr
188 prefetch_abort_handler:
189     sub    r0, lr, #4
190     mov    r1, #1
191     b      UIE
193 fiq_handler:
194     @ Branch straight to FIQ handler in pcm_playback.c. This also handles the
195     @ the correct return sequence.
196     stmfd sp!, {r0-r7, r12, lr}
197     bl    fiq
198     ldmfd sp!, {r0-r7, r12, lr}
199     subs pc, lr, #4
201 data_abort_handler:
202     sub    r0, lr, #8 
203     mov    r1, #2
204     b      UIE
206 irq_handler:
207 #ifndef STUB
208     stmfd  sp!, {r0-r11, r12, lr}
209     bl     irq
210     ldmfd  sp!, {r0-r11, r12, lr}
211 #endif
212     subs   pc, lr, #4
214 #ifdef STUB
215 UIE:
216     b UIE
217 #endif
219 /* 256 words of IRQ stack */
220     .space 256*4
221 irq_stack:
223 /* 256 words of FIQ stack */
224     .space 256*4
225 fiq_stack: