M:Robe 500i: More LCD initialization, and beginnings of support for QVGA as well...
[kugel-rb.git] / firmware / target / arm / tms320dm320 / crt0.S
bloba5a965b9c2a51c4968782f31fcf0587058086785
1 /***************************************************************************
2  *             __________               __   ___.
3  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
4  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
5  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
6  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
7  *                     \/            \/     \/    \/            \/
8  * $Id$
9  *
10  * Copyright (C) 2002 by Linus Nielsen Feltzing
11  *
12  * Arm bootloader and startup code based on startup.s from the iPodLinux loader
13  *
14  * Copyright (c) 2003, Daniel Palffy (dpalffy (at) rainstorm.org)
15  * Copyright (c) 2005, Bernard Leach <leachbj@bouncycastle.org>
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * as published by the Free Software Foundation; either version 2
20  * of the License, or (at your option) any later version.
21  *
22  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
23  * KIND, either express or implied.
24  *
25  ****************************************************************************/
26 #include "config.h"
27 #include "cpu.h"
29     .section .init.text,"ax",%progbits
31     .global    start
32 start:
33     msr    cpsr, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
35 #ifndef CREATIVE_ZVx
36     /* Copy exception handler code to address 0 */
37     ldr    r2, =_vectorsstart
38     ldr    r3, =_vectorsend
39     ldr    r4, =_vectorscopy
41     cmp    r3, r2
42     ldrhi  r5, [r4], #4
43     strhi  r5, [r2], #4
44     bhi    1b
45 #endif
47     /* Disable data and instruction cache, high vectors (at 0xffff0000 instead of 0x00000000) */
48     mrc    p15, 0, r0, c1, c0, 0
49     /* clear bits 13, 9:8 (--VI --RS) */
50     bic    r0, r0, #0x00003300
51     /* clear bits 7, 2:0 (B--- -C-M) */
52     bic    r0, r0, #0x00000085
53     /* make sure bit 2 (A) Align is set */
54     orr    r0, r0, #0x00000002
55     mcr    p15, 0, r0, c1, c0, 0
57 #if !defined(BOOTLOADER) && !defined(STUB)
58     /* Zero out IBSS */
59     ldr    r2, =_iedata
60     ldr    r3, =_iend
61     mov    r4, #0
63     cmp    r3, r2
64     strhi  r4, [r2], #4
65     bhi    1b
67 #ifndef CREATIVE_ZVx
68     /* Copy the IRAM */
69     ldr    r2, =_iramcopy
70     ldr    r3, =_iramstart
71     ldr    r4, =_iramend
73     cmp    r4, r3
74     ldrhi  r5, [r2], #4
75     strhi  r5, [r3], #4
76     bhi    1b
77 #endif
78 #endif /* !BOOTLOADER,!STUB */
81     /* Initialise bss section to zero */
82     ldr     r2, =_edata
83     ldr     r3, =_end
84     mov     r4, #0
85 bsszero:
86     cmp     r3, r2
87     strhi   r4, [r2], #4
88     bhi     bsszero
90     /* Set up some stack and munge it with 0xdeadbeef */
91     ldr     sp, =stackend
92     mov     r3, sp
93     ldr     r2, =stackbegin
94     ldr     r4, =0xdeadbeef
95 stackmunge:
96     cmp     r3, r2
97     strhi   r4, [r2], #4
98     bhi     stackmunge
100     /* Set up stack for IRQ mode */
101     msr    cpsr_c, #0xd2 /* IRQ disabled, FIQ enabled */
102     ldr    sp, =irq_stack
103     /* Set up stack for FIQ mode */
104     msr    cpsr_c, #0xd1 /* IRQ/FIQ disabled */
105     ldr    sp, =fiq_stack
107     /* Let abort and undefined modes use IRQ stack */
108     msr    cpsr_c, #0xd7 /* IRQ/FIQ disabled */
109     ldr    sp, =irq_stack
110     msr    cpsr_c, #0xdb /* IRQ/FIQ disabled */
111     ldr    sp, =irq_stack
113     /* Switch to supervisor mode (no IRQ) */
114     msr    cpsr_c, #0xd3
115     ldr    sp, =stackend
116     
117 #if defined(BOOTLOADER) && !defined(CREATIVE_ZVx)
118     /* get the high part of our execute address */
119     ldr    r2, =0xffffff00
120     and    r4, pc, r2
122     /* Copy bootloader to safe area - 0x01900000 */
123     mov    r5, #0x01900000
124     ldr    r6, = _dataend
125     sub    r0, r6, r5       /* length of loader */
126     add    r0, r4, r0     /* r0 points to start of loader */
128     cmp    r5, r6
129     ldrcc  r2, [r4], #4
130     strcc  r2, [r5], #4
131     bcc    1b
133     ldr    pc, =start_loc    /* jump to the relocated start_loc:  */
135 #endif
137 start_loc:
138      bl main
139     /* main() should never return */
141 /* Exception handlers. Will be copied to address 0 after memory remapping */
142     .section .vectors,"aw"
143         b       start
144         b       undef_instr_handler
145     b   software_int_handler
146     b   prefetch_abort_handler
147     b   data_abort_handler
148     b   reserved_handler
149     b   irq_handler
150     b   fiq_handler
152     .text
154 /* All illegal exceptions call into UIE with exception address as first
155    parameter. This is calculated differently depending on which exception
156    we're in. Second parameter is exception number, used for a string lookup
157    in UIE.
158  */
159 undef_instr_handler:
160     mov    r0, lr
161     mov    r1, #0
162     b      UIE
164 /* We run supervisor mode most of the time, and should never see a software
165    exception being thrown. Perhaps make it illegal and call UIE?
166  */
167 software_int_handler:
168 reserved_handler:
169     movs   pc, lr
171 prefetch_abort_handler:
172     sub    r0, lr, #4
173     mov    r1, #1
174     b      UIE
176 data_abort_handler:
177     sub    r0, lr, #8 
178     mov    r1, #2
179     b      UIE
181 #ifdef STUB
182 UIE:
183     b UIE
184 #endif
186 /* Align stacks to cache line boundary */
187     .balign 16
189 /* 256 words of IRQ stack */
190     .space 256*4
191 irq_stack:
193 /* 256 words of FIQ stack */
194     .space 256*4
195 fiq_stack: