Add some missign register defines. Reformat.
[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 #define CONTROL_UNPRIVILEGED    1
39 #define CONTROL_PSP             2
40
41 .syntax unified
42 .thumb
43 .section .init, "ax", %progbits
44
45 .weak __init
46 .set __init, __init0
47
48 .weak __init1
49 .set __init1, __dummy_init
50
51 .weak __init2
52 .set __init2, __dummy_init
53
54 .balign 2
55 .thumb_func
56 __dummy_init:
57         bx lr
58
59 /*
60  * Reset handler.
61  */
62 .balign 2
63 .thumb_func
64 __init0:
65         /* Disable IRQs */
66         cpsid i
67         /*
68          * Initialize process stack pointer.
69          */
70         ldr     r0, =__psp_end
71         msr     psp, r0
72
73         /* Call the early hardware initialization routine */
74         bl __init1
75
76         /* Copy the data segment initializers from flash to SRAM */
77         ldr r0, =__text_end
78         ldr r1, =__data_start
79         ldr r2, =__data_end
80 data_loop:
81         cmp r1, r2
82         ittt lo
83         ldrlo r3, [r0], #4
84         strlo r3, [r1], #4
85         blo data_loop
86
87         /* Zero fill the bss segment */
88         ldr r1, =__bss_start
89         ldr r2, =__bss_end
90         mov r0, #0
91 bss_loop:
92         cmp r1, r2
93         itt lo
94         strlo r0, [r1], #4
95         blo bss_loop
96
97         /* Switch to the process stack */
98         movs r0, CONTROL_PSP
99         msr control, r0
100         isb
101
102         /* Call the hardware initialization routine */
103         bl __init2
104
105         /* Call the application's entry point */
106         cpsie i
107         mov r0, #0
108         mov r1, #0
109         bl main
110 end:
111         wfi
112         b end