1 | ; Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs
|
2 |
|
3 | Mode_USR EQU 0x10
|
4 | Mode_FIQ EQU 0x11
|
5 | Mode_IRQ EQU 0x12
|
6 | Mode_SVC EQU 0x13
|
7 | Mode_ABT EQU 0x17
|
8 | Mode_UND EQU 0x1B
|
9 | Mode_SYS EQU 0x1F
|
10 |
|
11 | I_Bit EQU 0x80 ; when I bit is set, IRQ is disabled
|
12 | F_Bit EQU 0x40 ; when F bit is set, FIQ is disabled
|
13 |
|
14 |
|
15 |
|
16 | ;// <h> Stack Configuration (Stack Sizes in Bytes)
|
17 | ;// <o0> Undefined Mode <0x0-0xFFFFFFFF:8>
|
18 | ;// <o1> Supervisor Mode <0x0-0xFFFFFFFF:8>
|
19 | ;// <o2> Abort Mode <0x0-0xFFFFFFFF:8>
|
20 | ;// <o3> Fast Interrupt Mode <0x0-0xFFFFFFFF:8>
|
21 | ;// <o4> Interrupt Mode <0x0-0xFFFFFFFF:8>
|
22 | ;// <o5> User/System Mode <0x0-0xFFFFFFFF:8>
|
23 | ;// </h>
|
24 |
|
25 | UND_Stack_Size EQU 0x00000000
|
26 | SVC_Stack_Size EQU 0x00000008
|
27 | ABT_Stack_Size EQU 0x00000000
|
28 | FIQ_Stack_Size EQU 0x00000000
|
29 | IRQ_Stack_Size EQU 0x00000080
|
30 | USR_Stack_Size EQU 0x00000400
|
31 |
|
32 | ISR_Stack_Size EQU (UND_Stack_Size + SVC_Stack_Size + ABT_Stack_Size + \
|
33 | FIQ_Stack_Size + IRQ_Stack_Size)
|
34 |
|
35 | AREA STACK, NOINIT, READWRITE, ALIGN=3
|
36 |
|
37 | Stack_Mem SPACE USR_Stack_Size
|
38 | __initial_sp SPACE ISR_Stack_Size
|
39 |
|
40 | Stack_Top
|
41 |
|
42 | ;// <h> Heap Configuration
|
43 | ;// <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF>
|
44 | ;// </h>
|
45 |
|
46 | Heap_Size EQU 0x00000000
|
47 |
|
48 | AREA HEAP, NOINIT, READWRITE, ALIGN=3
|
49 | __heap_base
|
50 | Heap_Mem SPACE Heap_Size
|
51 | __heap_limit
|
52 |
|
53 |
|
54 | ; VPBDIV definitions
|
55 | VPBDIV EQU 0xE01FC100 ; VPBDIV Address
|
56 |
|
57 | ;// <e> VPBDIV Setup
|
58 | ;// <i> Peripheral Bus Clock Rate
|
59 | ;// <o1.0..1> VPBDIV: VPB Clock
|
60 | ;// <0=> VPB Clock = CPU Clock / 4
|
61 | ;// <1=> VPB Clock = CPU Clock
|
62 | ;// <2=> VPB Clock = CPU Clock / 2
|
63 | ;// <o1.4..5> XCLKDIV: XCLK Pin
|
64 | ;// <0=> XCLK Pin = CPU Clock / 4
|
65 | ;// <1=> XCLK Pin = CPU Clock
|
66 | ;// <2=> XCLK Pin = CPU Clock / 2
|
67 | ;// </e>
|
68 | VPBDIV_SETUP EQU 1
|
69 | VPBDIV_Val EQU 0x00000001
|
70 |
|
71 |
|
72 | ; Phase Locked Loop (PLL) definitions
|
73 | PLL_BASE EQU 0xE01FC080 ; PLL Base Address
|
74 | PLLCON_OFS EQU 0x00 ; PLL Control Offset
|
75 | PLLCFG_OFS EQU 0x04 ; PLL Configuration Offset
|
76 | PLLSTAT_OFS EQU 0x08 ; PLL Status Offset
|
77 | PLLFEED_OFS EQU 0x0C ; PLL Feed Offset
|
78 | PLLCON_PLLE EQU (1<<0) ; PLL Enable
|
79 | PLLCON_PLLC EQU (1<<1) ; PLL Connect
|
80 | PLLCFG_MSEL EQU (0x1F<<0) ; PLL Multiplier
|
81 | PLLCFG_PSEL EQU (0x03<<5) ; PLL Divider
|
82 | PLLSTAT_PLOCK EQU (1<<10) ; PLL Lock Status
|
83 |
|
84 | ;// <e> PLL Setup
|
85 | ;// <o1.0..4> MSEL: PLL Multiplier Selection
|
86 | ;// <1-32><#-1>
|
87 | ;// <i> M Value
|
88 | ;// <o1.5..6> PSEL: PLL Divider Selection
|
89 | ;// <0=> 1 <1=> 2 <2=> 4 <3=> 8
|
90 | ;// <i> P Value
|
91 | ;// </e>
|
92 | PLL_SETUP EQU 1
|
93 | PLLCFG_Val EQU 0x00000024
|
94 |
|
95 |
|
96 | ; Memory Accelerator Module (MAM) definitions
|
97 | MAM_BASE EQU 0xE01FC000 ; MAM Base Address
|
98 | MAMCR_OFS EQU 0x00 ; MAM Control Offset
|
99 | MAMTIM_OFS EQU 0x04 ; MAM Timing Offset
|
100 |
|
101 | ;// <e> MAM Setup
|
102 | ;// <o1.0..1> MAM Control
|
103 | ;// <0=> Disabled
|
104 | ;// <1=> Partially Enabled
|
105 | ;// <2=> Fully Enabled
|
106 | ;// <i> Mode
|
107 | ;// <o2.0..2> MAM Timing
|
108 | ;// <0=> Reserved <1=> 1 <2=> 2 <3=> 3
|
109 | ;// <4=> 4 <5=> 5 <6=> 6 <7=> 7
|
110 | ;// <i> Fetch Cycles
|
111 | ;// </e>
|
112 | MAM_SETUP EQU 1
|
113 | MAMCR_Val EQU 0x00000002
|
114 | MAMTIM_Val EQU 0x00000004
|
115 |
|
116 |
|
117 | ; External Memory Controller (EMC) definitions
|
118 | EMC_BASE EQU 0xFFE00000 ; EMC Base Address
|
119 | BCFG0_OFS EQU 0x00 ; BCFG0 Offset
|
120 | BCFG1_OFS EQU 0x04 ; BCFG1 Offset
|
121 | BCFG2_OFS EQU 0x08 ; BCFG2 Offset
|
122 | BCFG3_OFS EQU 0x0C ; BCFG3 Offset
|
123 |
|
124 | ;// <e> External Memory Controller (EMC)
|
125 | EMC_SETUP EQU 0
|
126 |
|
127 | ;// <e> Bank Configuration 0 (BCFG0)
|
128 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
129 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
130 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
131 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
132 | ;// <o1.26> WP: Write Protect
|
133 | ;// <o1.27> BM: Burst ROM
|
134 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
135 | ;// <2=> 32-bit <3=> Reserved
|
136 | ;// </e>
|
137 | BCFG0_SETUP EQU 0
|
138 | BCFG0_Val EQU 0x0000FBEF
|
139 |
|
140 | ;// <e> Bank Configuration 1 (BCFG1)
|
141 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
142 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
143 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
144 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
145 | ;// <o1.26> WP: Write Protect
|
146 | ;// <o1.27> BM: Burst ROM
|
147 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
148 | ;// <2=> 32-bit <3=> Reserved
|
149 | ;// </e>
|
150 | BCFG1_SETUP EQU 0
|
151 | BCFG1_Val EQU 0x0000FBEF
|
152 |
|
153 | ;// <e> Bank Configuration 2 (BCFG2)
|
154 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
155 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
156 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
157 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
158 | ;// <o1.26> WP: Write Protect
|
159 | ;// <o1.27> BM: Burst ROM
|
160 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
161 | ;// <2=> 32-bit <3=> Reserved
|
162 | ;// </e>
|
163 | BCFG2_SETUP EQU 0
|
164 | BCFG2_Val EQU 0x0000FBEF
|
165 |
|
166 | ;// <e> Bank Configuration 3 (BCFG3)
|
167 | ;// <o1.0..3> IDCY: Idle Cycles <0-15>
|
168 | ;// <o1.5..9> WST1: Wait States 1 <0-31>
|
169 | ;// <o1.11..15> WST2: Wait States 2 <0-31>
|
170 | ;// <o1.10> RBLE: Read Byte Lane Enable
|
171 | ;// <o1.26> WP: Write Protect
|
172 | ;// <o1.27> BM: Burst ROM
|
173 | ;// <o1.28..29> MW: Memory Width <0=> 8-bit <1=> 16-bit
|
174 | ;// <2=> 32-bit <3=> Reserved
|
175 | ;// </e>
|
176 | BCFG3_SETUP EQU 0
|
177 | BCFG3_Val EQU 0x0000FBEF
|
178 |
|
179 | ;// </e> End of EMC
|
180 |
|
181 |
|
182 | ; External Memory Pins definitions
|
183 | PINSEL2 EQU 0xE002C014 ; PINSEL2 Address
|
184 | PINSEL2_Val EQU 0x0E6149E4 ; CS0..3, OE, WE, BLS0..3,
|
185 | ; D0..31, A2..23, JTAG Pins
|
186 |
|
187 |
|
188 | PRESERVE8
|
189 |
|
190 |
|
191 | ; Area Definition and Entry Point
|
192 | ; Startup Code must be linked first at Address at which it expects to run.
|
193 |
|
194 | AREA RESET, CODE, READONLY
|
195 | ARM
|
196 |
|
197 | ; Exception Vectors
|
198 | ; Mapped to Address 0.
|
199 | ; Absolute addressing mode must be used.
|
200 | ; Dummy Handlers are implemented as infinite loops which can be modified.
|
201 |
|
202 |
|
203 | Vectors LDR PC, Reset_Addr
|
204 | LDR PC, Undef_Addr
|
205 | LDR PC, SWI_Addr
|
206 | LDR PC, PAbt_Addr
|
207 | LDR PC, DAbt_Addr
|
208 | NOP ; Reserved Vector
|
209 | LDR PC, IRQ_Addr
|
210 | LDR PC, [PC, #-0x0FF0] ; Vector from VicVectAddr
|
211 | LDR PC, FIQ_Addr
|
212 |
|
213 | Reset_Addr DCD Reset_Handler
|
214 | Undef_Addr DCD Undef_Handler
|
215 | SWI_Addr DCD SWI_Handler
|
216 | PAbt_Addr DCD PAbt_Handler
|
217 | DAbt_Addr DCD DAbt_Handler
|
218 | DCD 0 ; Reserved Address
|
219 | IRQ_Addr DCD IRQ_Handler
|
220 | FIQ_Addr DCD FIQ_Handler
|
221 |
|
222 | ;/ Modifikation: Code an Adresse 0x40 springt zum Reset_Handler
|
223 | ;/ Adresse 0x40 wird bei leerem Boot-Block als erster ausfuehrbarer
|
224 | ;/ Befehl im internen Flash erreicht
|
225 | B Reset_Handler
|
226 | Undef_Handler B Undef_Handler
|
227 | SWI_Handler B SWI_Handler
|
228 | PAbt_Handler B PAbt_Handler
|
229 | DAbt_Handler B DAbt_Handler
|
230 | IRQ_Handler B IRQ_Handler
|
231 | FIQ_Handler B FIQ_Handler
|
232 |
|
233 |
|
234 | ; Reset Handler
|
235 |
|
236 | EXPORT Reset_Handler
|
237 | Reset_Handler
|
238 |
|
239 | IF :DEF:DEBUG
|
240 | LDR R0, =0x800
|
241 | Reset_Catch
|
242 | SUBS R0, R0, #1
|
243 | BNE Reset_Catch
|
244 | ENDIF
|
245 |
|
246 |
|
247 | ; Setup External Memory Pins
|
248 | IF :DEF:EXTERNAL_MODE
|
249 | LDR R0, =PINSEL2
|
250 | LDR R1, =PINSEL2_Val
|
251 | STR R1, [R0]
|
252 | ENDIF
|
253 |
|
254 |
|
255 | ; Setup External Memory Controller
|
256 | IF EMC_SETUP <> 0
|
257 | LDR R0, =EMC_BASE
|
258 |
|
259 | IF BCFG0_SETUP <> 0
|
260 | LDR R1, =BCFG0_Val
|
261 | STR R1, [R0, #BCFG0_OFS]
|
262 | ENDIF
|
263 |
|
264 | IF BCFG1_SETUP <> 0
|
265 | LDR R1, =BCFG1_Val
|
266 | STR R1, [R0, #BCFG1_OFS]
|
267 | ENDIF
|
268 |
|
269 | IF BCFG2_SETUP <> 0
|
270 | LDR R1, =BCFG2_Val
|
271 | STR R1, [R0, #BCFG2_OFS]
|
272 | ENDIF
|
273 |
|
274 | IF BCFG3_SETUP <> 0
|
275 | LDR R1, =BCFG3_Val
|
276 | STR R1, [R0, #BCFG3_OFS]
|
277 | ENDIF
|
278 |
|
279 | ENDIF ; EMC_SETUP
|
280 |
|
281 |
|
282 | ; Setup VPBDIV
|
283 | IF VPBDIV_SETUP <> 0
|
284 | LDR R0, =VPBDIV
|
285 | LDR R1, =VPBDIV_Val
|
286 | STR R1, [R0]
|
287 | ENDIF
|
288 |
|
289 |
|
290 | ; Setup PLL
|
291 | IF PLL_SETUP <> 0
|
292 | LDR R0, =PLL_BASE
|
293 | MOV R1, #0xAA
|
294 | MOV R2, #0x55
|
295 |
|
296 | ; Configure and Enable PLL
|
297 | MOV R3, #PLLCFG_Val
|
298 | STR R3, [R0, #PLLCFG_OFS]
|
299 | MOV R3, #PLLCON_PLLE
|
300 | STR R3, [R0, #PLLCON_OFS]
|
301 | STR R1, [R0, #PLLFEED_OFS]
|
302 | STR R2, [R0, #PLLFEED_OFS]
|
303 |
|
304 | ; Wait until PLL Locked
|
305 | PLL_Loop LDR R3, [R0, #PLLSTAT_OFS]
|
306 | ANDS R3, R3, #PLLSTAT_PLOCK
|
307 | BEQ PLL_Loop
|
308 |
|
309 | ; Switch to PLL Clock
|
310 | MOV R3, #(PLLCON_PLLE:OR:PLLCON_PLLC)
|
311 | STR R3, [R0, #PLLCON_OFS]
|
312 | STR R1, [R0, #PLLFEED_OFS]
|
313 | STR R2, [R0, #PLLFEED_OFS]
|
314 | ENDIF ; PLL_SETUP
|
315 |
|
316 |
|
317 | ; Setup MAM
|
318 | IF MAM_SETUP <> 0
|
319 | LDR R0, =MAM_BASE
|
320 | MOV R1, #MAMTIM_Val
|
321 | STR R1, [R0, #MAMTIM_OFS]
|
322 | MOV R1, #MAMCR_Val
|
323 | STR R1, [R0, #MAMCR_OFS]
|
324 | ENDIF ; MAM_SETUP
|
325 |
|
326 |
|
327 | ; Memory Mapping (when Interrupt Vectors are in RAM)
|
328 | MEMMAP EQU 0xE01FC040 ; Memory Mapping Control
|
329 | IF :DEF:REMAP
|
330 | LDR R0, =MEMMAP
|
331 | IF :DEF:EXTMEM_MODE
|
332 | MOV R1, #3
|
333 | ELIF :DEF:RAM_MODE
|
334 | MOV R1, #2
|
335 | ELSE
|
336 | MOV R1, #1
|
337 | ENDIF
|
338 | STR R1, [R0]
|
339 | ENDIF
|
340 |
|
341 |
|
342 | ; Initialise Interrupt System
|
343 | ; ...
|
344 |
|
345 |
|
346 | ; Setup Stack for each mode
|
347 |
|
348 | LDR R0, =Stack_Top
|
349 |
|
350 | ; Enter Undefined Instruction Mode and set its Stack Pointer
|
351 | MSR CPSR_c, #Mode_UND:OR:I_Bit:OR:F_Bit
|
352 | MOV SP, R0
|
353 | SUB R0, R0, #UND_Stack_Size
|
354 |
|
355 | ; Enter Abort Mode and set its Stack Pointer
|
356 | MSR CPSR_c, #Mode_ABT:OR:I_Bit:OR:F_Bit
|
357 | MOV SP, R0
|
358 | SUB R0, R0, #ABT_Stack_Size
|
359 |
|
360 | ; Enter FIQ Mode and set its Stack Pointer
|
361 | MSR CPSR_c, #Mode_FIQ:OR:I_Bit:OR:F_Bit
|
362 | MOV SP, R0
|
363 | SUB R0, R0, #FIQ_Stack_Size
|
364 |
|
365 | ; Enter IRQ Mode and set its Stack Pointer
|
366 | MSR CPSR_c, #Mode_IRQ:OR:I_Bit:OR:F_Bit
|
367 | MOV SP, R0
|
368 | SUB R0, R0, #IRQ_Stack_Size
|
369 |
|
370 | ; Enter Supervisor Mode and set its Stack Pointer
|
371 | MSR CPSR_c, #Mode_SVC:OR:I_Bit:OR:F_Bit
|
372 | MOV SP, R0
|
373 | SUB R0, R0, #SVC_Stack_Size
|
374 |
|
375 | ; Enter User Mode and set its Stack Pointer
|
376 | MSR CPSR_c, #Mode_USR
|
377 | IF :DEF:__MICROLIB
|
378 |
|
379 | EXPORT __initial_sp
|
380 |
|
381 | ELSE
|
382 |
|
383 | MOV SP, R0
|
384 | SUB SL, SP, #USR_Stack_Size
|
385 |
|
386 | ENDIF
|
387 |
|
388 |
|
389 | ; Enter the C code
|
390 |
|
391 | IMPORT __main
|
392 | LDR R0, =__main
|
393 | BX R0
|
394 |
|
395 |
|
396 | IF :DEF:__MICROLIB
|
397 |
|
398 | EXPORT __heap_base
|
399 | EXPORT __heap_limit
|
400 |
|
401 | ELSE
|
402 | ; User Initial Stack & Heap
|
403 | AREA |.text|, CODE, READONLY
|
404 |
|
405 | IMPORT __use_two_region_memory
|
406 | EXPORT __user_initial_stackheap
|
407 | __user_initial_stackheap
|
408 |
|
409 | LDR R0, = Heap_Mem
|
410 | LDR R1, =(Stack_Mem + USR_Stack_Size)
|
411 | LDR R2, = (Heap_Mem + Heap_Size)
|
412 | LDR R3, = Stack_Mem
|
413 | BX LR
|
414 | ENDIF
|
415 |
|
416 |
|
417 | END
|