-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.S
133 lines (123 loc) · 3.97 KB
/
init.S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* This file is part of geckonator.
* Copyright 2017 Emil Renner Berthing <[email protected]>
*
* geckonator is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* geckonator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with geckonator. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __STACK_SIZE
#define __STACK_SIZE 1024
#endif
.syntax unified
.fpu softvfp
.global __Vectors
.global __halt
.extern main
.weak Default_Handler
.set Default_Handler, __halt
.section .stack
__StackLimit:
.space __STACK_SIZE
.size __StackLimit, . - __StackLimit
.macro interrupt name
.weak \name
.set \name, __halt
.long \name
.endm
.section .vectors, "a", %progbits
.type __Vectors, %object
__Vectors:
/* the first vector in Cortex is the stack pointer */
.long __StackTop /* top of stack */
.long Reset_Handler /* reset handler */
interrupt NMI_Handler /* nmi handler */
interrupt HardFault_Handler /* hard fault handler */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
interrupt SVC_Handler /* svcall handler */
.long Default_Handler /* reserved */
.long Default_Handler /* reserved */
interrupt PendSV_Handler /* pendsv handler */
interrupt SysTick_Handler /* systick handler */
/* external interrupts */
interrupt DMA_IRQHandler /* 0 - DMA */
interrupt GPIO_EVEN_IRQHandler /* 1 - GPIO_EVEN */
interrupt TIMER0_IRQHandler /* 2 - TIMER0 */
interrupt ACMP0_IRQHandler /* 3 - ACMP0 */
interrupt ADC0_IRQHandler /* 4 - ADC0 */
interrupt I2C0_IRQHandler /* 5 - I2C0 */
interrupt GPIO_ODD_IRQHandler /* 6 - GPIO_ODD */
interrupt TIMER1_IRQHandler /* 7 - TIMER1 */
interrupt USART1_RX_IRQHandler /* 8 - USART1_RX */
interrupt USART1_TX_IRQHandler /* 9 - USART1_TX */
interrupt LEUART0_IRQHandler /* 10 - LEUART0 */
interrupt PCNT0_IRQHandler /* 11 - PCNT0 */
interrupt RTC_IRQHandler /* 12 - RTC */
interrupt CMU_IRQHandler /* 13 - CMU */
interrupt VCMP_IRQHandler /* 14 - VCMP */
interrupt MSC_IRQHandler /* 15 - MSC */
interrupt AES_IRQHandler /* 16 - AES */
interrupt USART0_RX_IRQHandler /* 17 - USART0_RX */
interrupt USART0_TX_IRQHandler /* 18 - USART0_TX */
interrupt USB_IRQHandler /* 19 - USB */
interrupt TIMER2_IRQHandler /* 20 - TIMER2 */
.size __Vectors, . - __Vectors
.section .text.Reset_Handler, "ax", %progbits
.thumb_func
.weak Reset_Handler
.type Reset_Handler, %function
.func Reset_Handler
Reset_Handler:
/* copy data with *r5++ = *r4++ while r5 < r6 */
ldr r4, =__etext
ldr r5, =__data_start__
ldr r6, =__data_end__
b 2f
/* .ltorg is possible here */
1: ldmia r4!, {r7}
stmia r5!, {r7}
2: cmp r5, r6
blt 1b
/* clear bss with *r5++ = r4 (== 0) while r5 < r6 */
movs r4, #0
/* assume .bss follows .data
ldr r5, =__bss_start__
*/
ldr r6, =__bss_end__
/*
* if .bss is empty we clear the first word of
* whatever follows. that should be the bottom
* of stack or start of heap which is fine
b 4f
*/
3: stmia r5!, {r4}
4: cmp r5, r6
blt 3b
bl main
b __halt
.size Reset_Handler, . - Reset_Handler
.endfunc
.section .text.__halt, "ax", %progbits
.thumb_func
.type __halt, %function
.func __halt
__halt:
cpsid i
0: b 0b
.size __halt, . - __halt
.endfunc