forked from ddidiy/WirelessHart-Field-Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Init-IAR.S
212 lines (176 loc) · 6.14 KB
/
Init-IAR.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
;#####################################################################
;# Authors : Lasse Langwadt Christensen, Grig Barbulescu
;# Created : 06/03/01
;# Date : 02/27/07
;#####################################################################
;# Description:
;# - Interrupt vectors and C-init
;#####################################################################
F_Bit EQU 0x40
I_Bit EQU 0x80
Mode_Uvc EQU 0x10 ; // user mode - has same registers as system mode
Mode_Fvc EQU 0x11 ; // FIQ mode
Mode_Ivc EQU 0x12 ; // IRQ mode
Mode_Svc EQU 0x13 ; // supervisor mode
Mode_Avc EQU 0x17 ; // Abort mode
Mode_und EQU 0x1B ; // undefined instr mode
Mode_sys EQU 0x1F ; // system mode
;//__SUP_stack_size EQU 256*4
;//__USR_stack_size EQU 512*4
;//__IRQ_stack_size EQU 256*4
;//__FIQ_stack_size EQU 256*4
;//__UND_stack_size EQU 64*4
;//__ABT_stack_size EQU 64*4
__USR_stack_size EQU 1024
__IRQ_stack_size EQU 1024 ; // 512
__FIQ_stack_size EQU 64
__UND_stack_size EQU 64
__ABT_stack_size EQU 64
__SUP_stack_size EQU 64
EXPORT _start_vector_
IMPORT main
#if (__VER__ >= 5020000)
IMPORT __iar_data_init2
EXPORT __iar_data_init
#else
IMPORT __iar_data_init
#endif
IMPORT __rom_data_init
IMPORT Region$$Table$$Base
IMPORT Region$$Table$$Limit
IMPORT Region_ROM_Table_ROM_Base
IMPORT Region_ROM_Table_ROM_Limit
IMPORT RP_Vector_Thumb_0
IMPORT RP_Vector_Thumb_1
IMPORT RP_Vector_Thumb_2
IMPORT RP_Vector_Thumb_3
#ifndef NO_USE_INTERRUPTS
IMPORT IrqHandler
IMPORT FiqHandler
#endif
#ifndef NO_USE_EXCEPTIONS
;imported from ItcDriver.c
IMPORT mExceptionHandlerPrefetchAbort
IMPORT mExceptionHandlerDataAbort
IMPORT mExceptionHandlerUndefined
IMPORT mExceptionHandlerSupervisor
#endif
SECTION .vect: CODE
;//--Entry point-------------------------------------------------
CODE32
_start_vector_
B __start_ ; // reset
#ifdef NO_USE_EXCEPTIONS
B __reserved_ ; // reserved
B __reserved_ ; // reserved
B __reserved_ ; // reserved
B __reserved_ ; // reserved
#else
B __UndefInstructionHndlr_ ; // undefined instruction
B __SupervisorHndlr_ ; // supervisor
B __PrefetchAbtHndlr_ ; // prefetch abort
B __DataAbtHndlr_ ; // data abort
#endif
B __reserved_ ; // reserved
#ifdef NO_USE_INTERRUPTS
B __reserved_ ; // reserved
B __reserved_ ; // reserved
#else
B IrqHandler ; // IRQ
B FiqHandler ; // FIQ
#endif
SECTION .text: CODE
#if (__VER__ >= 5020000)
__iar_data_init:
B __iar_data_init2
#endif
__start_
LDR r1,=system_stack
MOV r0, #Mode_Svc | F_Bit | I_Bit ;// supervisor mode, disable all interrupts
MSR cpsr_c,r0
ADD r1,r1,#__SUP_stack_size
MOV sp,r1
MOV r0, #Mode_Ivc | F_Bit | I_Bit ;// IRQ mode, disable all interrupts
MSR cpsr_c,r0
ADD r1,r1,#__IRQ_stack_size
MOV sp,r1
MOV r0, #Mode_Fvc | F_Bit | I_Bit ;// FIQ mode, disable all interrupts
MSR cpsr_c,r0
ADD r1,r1,#__FIQ_stack_size
MOV sp,r1
MOV r0, #Mode_und | F_Bit | I_Bit ;// UND mode, disable all interrupts
MSR cpsr_c,r0
ADD r1,r1,#__UND_stack_size
MOV sp,r1
MOV r0, #Mode_Avc | F_Bit | I_Bit ;// ABT mode, disable all interrupts
MSR cpsr_c,r0
ADD r1,r1,#__ABT_stack_size
MOV sp,r1
MOV r0, #Mode_sys | F_Bit | I_Bit ;// system mode, disable all interrupts
MSR cpsr_c,r0
ADD r1,r1,#__USR_stack_size
MOV sp,r1
; MOV r0, #Mode_Uvc | F_Bit | I_Bit ;// user mode, disable all interrupts
; MSR cpsr_c,r0
BL __iar_data_init
; // See if we need to initialize the ROM variables
LDR r0, =Region_ROM_Table_ROM_Base
LDR r3, =Region_ROM_Table_ROM_Limit
CMP r0, r3
; // If Region_ROM_Table_ROM_Base and Region_ROM_Table_ROM_Limit are equal, then the ROM image is loaded in RAM (simulation)
; // No need to init the ROM variables.
BEQ __call_main
BL __rom_data_init
__call_main
;// the main function was renamed to Main in order to avoid inclusion of C library code for supplementary initializations
B main ; // jump to "Main()"
__reserved_
MOVS pc,lr
#ifndef NO_USE_EXCEPTIONS
__UndefInstructionHndlr_
STMFD r13!, {r0-r12,r14}
LDR r0, =mExceptionHandlerUndefined
LDR r0,[r0,#0]
CMP r0,#0
MOVNE r14,pc
BXNE r0
LDMFD r13!, {r0-r12,r14}
MOVS PC, R14
__SupervisorHndlr_
STMFD r13!, {r0-r12,r14}
LDR r0, =mExceptionHandlerSupervisor
LDR r0,[r0,#0]
CMP r0,#0
MOVNE r14,pc
BXNE r0
LDMFD r13!, {r0-r12,r14}
MOVS PC, R14
__PrefetchAbtHndlr_
STMFD r13!,{r0-r12,r14}
LDR r0, =mExceptionHandlerPrefetchAbort
LDR r0,[r0,#0]
CMP r0,#0
MOVNE r14,pc
BXNE r0
LDMFD r13!,{r0-r12,r14}
SUBS PC, r14, #4
__DataAbtHndlr_
STMFD r13!,{r0-r12,r14}
LDR r0, =mExceptionHandlerDataAbort
LDR r0,[r0,#0]
CMP r0,#0
MOVNE r14,pc
BXNE r0
LDMFD r13!,{r0-r12,r14}
SUBS PC, r14, #4
#endif
SECTION .stack:DATA(2) ;// stack in internal RAM
system_stack
DS8 __USR_stack_size+__IRQ_stack_size+__FIQ_stack_size+__UND_stack_size+__ABT_stack_size+__SUP_stack_size
;// force the ROM patching referencing
REQUIRE RP_Vector_Thumb_0
REQUIRE RP_Vector_Thumb_1
REQUIRE RP_Vector_Thumb_2
REQUIRE RP_Vector_Thumb_3
END
;//---------------------------------------------------------------