arm/crt0.S: comment why the reset vector doesn't use absolute addressing
[kugel-rb.git] / firmware / target / arm / crt0.S
blob3765df9ffc2d72b18a5e07bd650d173bbaa3c6b4
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 */
30     /*
31      * reset vector *MUST* use relative-addressing only
32      * the MMU might not be enabled yet, and the PC might point to
33      * a memory region not present in the linked binary
34      */
36     b   newstart
37     b   undef_instr_handler
38     b   software_int_handler
39     b   prefetch_abort_handler
40     b   data_abort_handler
41     b   reserved_handler
42     b   irq_handler
43     b   fiq_handler
45 _vectorsend:
47     .text
49 newstart:
50     msr     cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
52 #if CONFIG_CPU == AS3525 || CONFIG_CPU == AS3525v2
53     bl      memory_init
54 #endif
56 #ifdef USE_IRAM
57     /* Zero out IBSS */
58     ldr     r2, =_iedata
59     ldr     r3, =_iend
60     mov     r4, #0
62     cmp     r3, r2
63     strhi   r4, [r2], #4
64     bhi     1b
66     /* Copy the IRAM */
67     /* must be done before bss is zeroed */
68     ldr     r2, =_iramcopy
69     ldr     r3, =_iramstart
70     ldr     r4, =_iramend
72     cmp     r4, r3
73     ldrhi   r5, [r2], #4
74     strhi   r5, [r3], #4
75     bhi     1b
76 #endif
78 #ifdef HAVE_INIT_ATTR
79     /* copy init data to codec buffer */
80     /* must be done before bss is zeroed */
81     ldr    r2, =_initcopy
82     ldr    r3, =_initstart
83     ldr    r4, =_initend
85     cmp     r4, r3
86     ldrhi   r5, [r2], #4
87     strhi   r5, [r3], #4
88     bhi     1b
90     mov     r2, #0
91     mcr     p15, 0, r2, c7, c5, 0   @ Invalidate ICache
92 #endif
94     /* Initialise bss section to zero */
95     ldr     r2, =_edata
96     ldr     r3, =_end
97     mov     r4, #0
99     cmp     r3, r2
100     strhi   r4, [r2], #4
101     bhi     1b
103     /* Set up some stack and munge it with 0xdeadbeef */
104     ldr     sp, =stackend
105     ldr     r2, =stackbegin
106     ldr     r3, =0xdeadbeef
108     cmp     sp, r2
109     strhi   r3, [r2], #4
110     bhi     1b
111     
112     /* Set up stack for IRQ mode */ 
113     msr     cpsr_c, #0xd2
114     ldr     sp, =irq_stack
116     /* Set up stack for FIQ mode */ 
117     msr     cpsr_c, #0xd1
118     ldr     sp, =fiq_stack
120     /* Let abort and undefined modes use IRQ stack */
121     msr     cpsr_c, #0xd7
122     ldr     sp, =irq_stack
123     msr     cpsr_c, #0xdb
124     ldr     sp, =irq_stack
126     /* Switch back to supervisor mode */
127     msr     cpsr_c, #0xd3
128     ldr     ip, =main       @ make sure we are using the virtual address
129     bx      ip
131 /* All illegal exceptions call into UIE with exception address as first
132  * parameter. This is calculated differently depending on which exception
133  * we're in. Second parameter is exception number, used for a string lookup
134  * in UIE. */
135 undef_instr_handler:
136     sub    r0, lr, #4   @ r0 points to the faulty ARM instruction
137 #ifdef USE_THUMB
138     mrs    r1, spsr
139     tst    r1, #(1<<5)  @ T bit set ?
140     subne  r0, lr, #2   @ if yes, r0 points to the faulty THUMB instruction
141 #endif /* USE_THUMB */
142     mov    r1, #0
143     b      UIE
145 /* We run supervisor mode most of the time, and should never see a software
146  * exception being thrown. Perhaps make it illegal and call UIE? */
147 software_int_handler:
148 reserved_handler:
149     movs   pc, lr
151 prefetch_abort_handler:
152     sub    r0, lr, #4
153     mov    r1, #1
154     b      UIE
156 data_abort_handler:
157     sub    r0, lr, #8 
158     mov    r1, #2
159     b      UIE
161 /* 256 words of IRQ stack */
162     .space 256*4
163 irq_stack:
165 /* 256 words of FIQ stack */
166     .space 256*4
167 fiq_stack:
169 end: