imx233: fix auto slow divisor
[maemo-rb.git] / firmware / target / arm / imx233 / crt0.S
blobffc58d56fc33236a5b431c4d81c2ce91da3847da
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2011 by Amaury Pouly
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 .vectors,"ax",%progbits
25 .code 32
26     /* most handlers are in DRAM which is too far away for a relative jump */
27     ldr     pc, =start
28     ldr     pc, =undef_instr_handler
29     ldr     pc, =software_int_handler
30     ldr     pc, =prefetch_abort_handler
31     ldr     pc, =data_abort_handler
32     ldr     pc, =reserved_handler
33     ldr     pc, =irq_handler
34     ldr     pc, =fiq_handler
36 /* When starting, we will be running at 0x40000000 most probably
37  * but the code is expected to be loaded at 0x4xxxxxxx (uncached) and to be
38  * running at virtual address 0xyyyyyyyy (cached). So we first
39  * need to move everything to the right locationn then we setup the mmu and
40  * jump to the final virtual address. */
41 .text
42 .global start
43     /** The code below must be able to run at any address **/
44 start:
45     /* Copy running address */
46     sub     r7, pc, #8
47     /* Save r0 */
48     mov     r6, r0
50     /* enter supervisor mode, disable IRQ/FIQ */
51     msr     cpsr_c, #0xd3
52     /* Disable MMU, disable caching and buffering;
53      * use low exception range address (the core uses high range by default) */
54     mrc     p15, 0, r0, c1, c0, 0
55     ldr     r1, =0x3005
56     bic     r0, r1
57     mcr     p15, 0, r0, c1, c0, 0
59     /* To call the C code we need a stack, since the stack is in virtual memory
60      * use the stack's physical address */
61     ldr     sp, =stackend_phys
63     /* Enable MMU */
64     bl      memory_init
66     /* Copy the DRAM
67      * Assume the dram binary blob is located at the loading address (r5) */
68     mov    r2, r7
69     ldr    r3, =_dramcopystart
70     ldr    r4, =_dramcopyend
72     cmp     r4, r3
73     ldrhi   r5, [r2], #4
74     strhi   r5, [r3], #4
75     bhi     1b
77     mov     r2, #0
78     mcr     p15, 0, r2, c7, c5, 0   @ Invalidate ICache
79     
80     /* Jump to real location */
81     ldr     pc, =remap
82 remap:
83     /** The code below is be running at the right virtual address **/
84     /* Zero out IBSS */
85     ldr     r2, =_iedata
86     ldr     r3, =_iend
87     mov     r4, #0
89     cmp     r3, r2
90     strhi   r4, [r2], #4
91     bhi     1b
93     /* Copy the IRAM */
94     /* must be done before bss is zeroed */
95     ldr     r2, =_iramcopy
96     ldr     r3, =_iramstart
97     ldr     r4, =_iramend
99     cmp     r4, r3
100     ldrhi   r5, [r2], #4
101     strhi   r5, [r3], #4
102     bhi     1b
104 #ifdef HAVE_INIT_ATTR
105     /* copy init data to codec buffer */
106     /* must be done before bss is zeroed */
107     ldr    r2, =_initcopy
108     ldr    r3, =_initstart
109     ldr    r4, =_initend
111     cmp     r4, r3
112     ldrhi   r5, [r2], #4
113     strhi   r5, [r3], #4
114     bhi     1b
116     mov     r2, #0
117     mcr     p15, 0, r2, c7, c5, 0   @ Invalidate ICache
118 #endif
120     /* Initialise bss section to zero */
121     ldr     r2, =_edata
122     ldr     r3, =_end
123     mov     r4, #0
125     cmp     r3, r2
126     strhi   r4, [r2], #4
127     bhi     1b
129     /* Set up stack for IRQ mode */ 
130     msr     cpsr_c, #0xd2
131     ldr     sp, =irq_stack
133     /* Set up stack for FIQ mode */ 
134     msr     cpsr_c, #0xd1
135     ldr     sp, =fiq_stack
137     /* Let svc, abort and undefined modes use irq stack */
138     msr     cpsr_c, #0xd3
139     ldr     sp, =irq_stack
140     msr     cpsr_c, #0xd7
141     ldr     sp, =irq_stack
142     msr     cpsr_c, #0xdb
143     ldr     sp, =irq_stack
145     /* Switch to sys mode */
146     msr     cpsr_c, #0xdf
148     /* Set up some stack and munge it with 0xdeadbeef */
149     ldr     sp, =stackend
150     ldr     r2, =stackbegin
151     ldr     r3, =0xdeadbeef
153     cmp     sp, r2
154     strhi   r3, [r2], #4
155     bhi     1b
157     /* Jump to main */
158     mov     r0, r6
159     mov     r1, r7
160     bl      main
162     b       1b
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:
171 end: