a442bc59e0a07c12a665136c4778870140ecb5a6
[bertos.git] / bertos / cpu / cortex-m3 / hw / crt_cm3.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  * \brief Cortex-M3 architecture's entry point
34  *
35  * \author Andrea Righi <arighi@develer.com>
36  */
37
38 .syntax unified
39 .thumb
40 .section .init, "ax", %progbits
41
42 .weak __init
43 .set __init, __init0
44
45 .weak __init1
46 .set __init1, __dummy_init
47
48 .weak __init2
49 .set __init2, __dummy_init
50
51 .balign 2
52 .thumb_func
53 __dummy_init:
54         bx lr
55
56 /*
57  * Reset handler.
58  */
59 .balign 2
60 .thumb_func
61 __init0:
62         /* Disable IRQs */
63         cpsid i
64
65         /* Call the early hardware initialization routine */
66         bl __init1
67
68         /* Copy the data segment initializers from flash to SRAM */
69         ldr r0, =__text_end
70         ldr r1, =__data_start
71         ldr r2, =__data_end
72 data_loop:
73         cmp r1, r2
74         ittt lo
75         ldrlo r3, [r0], #4
76         strlo r3, [r1], #4
77         blo data_loop
78
79         /* Zero fill the bss segment */
80         ldr r1, =__bss_start
81         ldr r2, =__bss_end
82         mov r0, #0
83 bss_loop:
84         cmp r1, r2
85         itt lo
86         strlo r0, [r1], #4
87         blo bss_loop
88
89         /* Call the hardware initialization routine */
90         bl __init2
91
92         /* Call the application's entry point */
93         bl main
94 end:
95         wfi
96         b end