imx233/fuze+: gives bootloader argument to main
[kugel-rb.git] / firmware / target / arm / imx233 / crt0.S
blobb8b63e5f26497b943c6b5729a0e94a84b810ed82
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 .text
37 .global start
38 start:
39     /* Save r0 */
40     mov     r6, r0
41     msr     cpsr_c, #0xd3 /* enter supervisor mode, disable IRQ/FIQ */
42     /* Zero out IBSS */
43     ldr     r2, =_iedata
44     ldr     r3, =_iend
45     mov     r4, #0
47     cmp     r3, r2
48     strhi   r4, [r2], #4
49     bhi     1b
51     /* Copy the IRAM */
52     /* must be done before bss is zeroed */
53     ldr     r2, =_iramcopy
54     ldr     r3, =_iramstart
55     ldr     r4, =_iramend
57     cmp     r4, r3
58     ldrhi   r5, [r2], #4
59     strhi   r5, [r3], #4
60     bhi     1b
62     /* Initialise bss section to zero */
63     ldr     r2, =_edata
64     ldr     r3, =_end
65     mov     r4, #0
67     cmp     r3, r2
68     strhi   r4, [r2], #4
69     bhi     1b
72     /* Set up some stack and munge it with 0xdeadbeef */
73     ldr     sp, =stackend
74     ldr     r2, =stackbegin
75     ldr     r3, =0xdeadbeef
77     cmp     sp, r2
78     strhi   r3, [r2], #4
79     bhi     1b
80     
81     /* Set up stack for IRQ mode */ 
82     msr     cpsr_c, #0xd2
83     ldr     sp, =irq_stack
85     /* Set up stack for FIQ mode */ 
86     msr     cpsr_c, #0xd1
87     ldr     sp, =fiq_stack
89     /* Let abort and undefined modes use IRQ stack */
90     msr     cpsr_c, #0xd7
91     ldr     sp, =irq_stack
92     msr     cpsr_c, #0xdb
93     ldr     sp, =irq_stack
95     /* Switch back to supervisor mode */
96     msr     cpsr_c, #0xd3
98     /* Disable MMU, disable caching and buffering;
99      * use low exception range address (the core uses high range by default) */
100     mrc     p15, 0, r0, c1, c0, 0
101     ldr     r1, =0x3005
102     bic     r0, r1
103     mcr     p15, 0, r0, c1, c0, 0
105     /* Jump to main */
106     mov     r0, r6
107     bl      main
109     b       1b
111 /* All illegal exceptions call into UIE with exception address as first
112  * parameter. This is calculated differently depending on which exception
113  * we're in. Second parameter is exception number, used for a string lookup
114  * in UIE. */
115 undef_instr_handler:
116     sub    r0, lr, #4   @ r0 points to the faulty ARM instruction
117 #ifdef USE_THUMB
118     mrs    r1, spsr
119     tst    r1, #(1<<5)  @ T bit set ?
120     subne  r0, lr, #2   @ if yes, r0 points to the faulty THUMB instruction
121 #endif /* USE_THUMB */
122     mov    r1, #0
123     b      UIE
125 /* We run supervisor mode most of the time, and should never see a software
126  * exception being thrown. Perhaps make it illegal and call UIE? */
127 software_int_handler:
128 reserved_handler:
129     movs   pc, lr
131 prefetch_abort_handler:
132     sub    r0, lr, #4
133     mov    r1, #1
134     b      UIE
136 data_abort_handler:
137     sub    r0, lr, #8 
138     mov    r1, #2
139     b      UIE
141 /* 256 words of IRQ stack */
142     .space 256*4
143 irq_stack:
145 /* 256 words of FIQ stack */
146     .space 256*4
147 fiq_stack:
149 end: