ARM7TDMI: add sections for exception handlers.
[bertos.git] / bertos / cpu / arm / hw / crt_arm7tdmi.S
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2010 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  *
33  * \author Francesco Sacchi <batt@develer.com>
34  *
35  * \brief ARM7TDMI CRT.
36  */
37
38 #define ARM_MODE_USR   0x10
39 #define ARM_MODE_FIQ   0x11
40 #define ARM_MODE_IRQ   0x12
41 #define ARM_MODE_SVC   0x13
42 #define ARM_MODE_ABORT 0x17
43 #define ARM_MODE_UNDEF 0x1B
44 #define ARM_MODE_SYS   0x1F
45
46 #define IRQ_BIT        0x80
47 #define FIQ_BIT        0x40
48
49
50 /*
51  * Hardware initialization.
52  */
53         .section .init, "ax", %progbits
54 __init0:
55         /*
56          * Set stack pointers
57          */
58         ldr     r0, =__stack_fiq_end
59         msr     CPSR_c, #ARM_MODE_FIQ | IRQ_BIT | FIQ_BIT
60         mov     r13, r0
61         ldr     r0, =__stack_irq_end
62         msr     CPSR_c, #ARM_MODE_IRQ | IRQ_BIT | FIQ_BIT
63         mov     r13, r0
64         ldr     r0, =__stack_abt_end
65         msr     CPSR_c, #ARM_MODE_ABORT | IRQ_BIT | FIQ_BIT
66         mov     r13, r0
67         ldr     r0, =__stack_und_end
68         msr     CPSR_c, #ARM_MODE_UNDEF | IRQ_BIT | FIQ_BIT
69         mov     r13, r0
70         ldr     r0, =__stack_svc_end
71         msr     CPSR_c, #ARM_MODE_SVC | IRQ_BIT | FIQ_BIT
72         mov     r13, r0
73
74         /*
75          * Early hw initialization #1.
76          * Called before clearing .bss and
77          * loading .data segments.
78          */
79         bl      __init1
80
81         /*
82          * Clear .bss
83          */
84         ldr     r1, =__bss_start
85         ldr     r2, =__bss_end
86         ldr     r3, =0
87
88 bss_loop:
89         cmp     r1, r2
90         strne   r3, [r1], #+4
91         bne     bss_loop
92
93         /*
94          * Relocate .data section (Copy from ROM to RAM).
95          */
96         ldr     r1, =__etext
97         ldr     r2, =__data_start
98         ldr     r3, =__data_end
99
100 data_loop:
101         cmp     r2, r3
102         ldrlo   r0, [r1], #4
103         strlo   r0, [r2], #4
104         blo     data_loop
105
106         /*
107          * Early hw initialization #2.
108          * Called after setting up .bss and .data segments
109          * but before calling main().
110          */
111         bl      __init2
112
113         /*
114          * Jump to main
115          */
116         bl      main
117
118 end:
119         b       end
120
121 __dummy_init:
122         mov     pc, lr
123
124         /*
125          * Redefine your own __init() in order to supply
126          * a completely custom initialization routine.
127          */
128         .weak   __init
129         .set    __init, __init0
130
131         /*
132          * Redefine your own __init1() in order to supply
133          * an hardware initialization routine.
134          * Remember that __init1() is called *before*
135          * clearing .bss and loading .data sections.
136          */
137         .weak   __init1
138         .set    __init1, __dummy_init
139
140         /*
141          * Redefine your own __init2() in order to supply
142          * an hardware initialization routine.
143          * Remember that __init2() is called *after*
144          * clearing .bss and loading .data sections, just
145          * before calling main().
146          */
147         .weak   __init2
148         .set    __init2, __dummy_init
149
150         /*
151          * Redefine your own __undef() in order to supply
152          * a custom handler for undefined instruction exception.
153          */
154         .weak   __undef
155         .set    __undef, __xcpt_dummy_undef
156
157         /*
158          * Redefine your own __swi() in order to supply
159          * a custom handler for software interrupt exception.
160          */
161         .weak   __swi
162         .set    __swi, __xcpt_dummy_swi
163
164         /*
165          * Redefine your own __prefetch_abort() in order to supply
166          * a custom handler for prefetch abort exception.
167          */
168         .weak   __prefetch_abort
169         .set    __prefetch_abort, __xcpt_dummy_pref
170
171         /*
172          * Redefine your own __data_abort() in order to supply
173          * a custom handler for data abort exception.
174          */
175         .weak   __data_abort
176         .set    __data_abort, __xcpt_dummy_dab
177
178         .ltorg
179
180         .section .exceptions, "ax", %progbits
181
182 __xcpt_dummy_undef:
183         b       __xcpt_dummy_undef
184
185 __xcpt_dummy_swi:
186         b       __xcpt_dummy_swi
187
188 __xcpt_dummy_pref:
189         b       __xcpt_dummy_pref
190
191 __xcpt_dummy_dab:
192         b       __xcpt_dummy_dab