1 |
5 |
sergeykhbr |
#http://www.ic.unicamp.br/~celio/mc404-2014/docs/gnu-arm-directives.pdf
|
2 |
|
|
# R11 = FP (frame pointer)
|
3 |
|
|
# R13 = SP
|
4 |
|
|
# R14 = LR (Link Register). Register R14 receives the return address when a Branch with Link (BL or BLX) instruction is executed.
|
5 |
|
|
# R15 = PC
|
6 |
|
|
#==================================================================
|
7 |
|
|
# Entry point for the Reset handler
|
8 |
|
|
#==================================================================
|
9 |
|
|
# .section INTERRUPT_VECTOR, "x"
|
10 |
|
|
.text
|
11 |
|
|
_Reset:
|
12 |
|
|
|
13 |
|
|
#==================================================================
|
14 |
|
|
# Exception Vector Table
|
15 |
|
|
#==================================================================
|
16 |
|
|
|
17 |
|
|
Vectors:
|
18 |
|
|
LDR PC, Reset_Addr
|
19 |
|
|
LDR PC, Undefined_Addr @ Undefined Instruction
|
20 |
|
|
LDR PC, SVC_Addr @ Software interrupt
|
21 |
|
|
LDR PC, Prefetch_Addr @ Abort (prefetch)
|
22 |
|
|
LDR PC, Abort_Addr @ Abort (data)
|
23 |
|
|
B . @ Reserved vector
|
24 |
|
|
LDR PC, IRQ_Addr @ IRQ
|
25 |
|
|
LDR PC, FIQ_Addr @ FIQ
|
26 |
|
|
|
27 |
|
|
|
28 |
|
|
.balign 4
|
29 |
|
|
Reset_Addr: .word Reset_Handler
|
30 |
|
|
Undefined_Addr: .word Undefined_Handler
|
31 |
|
|
SVC_Addr: .word SVC_Handler
|
32 |
|
|
Prefetch_Addr: .word Prefetch_Handler
|
33 |
|
|
Abort_Addr: .word Abort_Handler
|
34 |
|
|
IRQ_Addr: .word 0x00000000
|
35 |
|
|
FIQ_Addr: .word 0x00000000
|
36 |
|
|
|
37 |
|
|
# 512 KB RAM
|
38 |
|
|
.equ STACK_BASE, 0x10080000
|
39 |
|
|
|
40 |
|
|
#==================================================================
|
41 |
|
|
# Exception Handlers
|
42 |
|
|
#==================================================================
|
43 |
|
|
|
44 |
|
|
Undefined_Handler:
|
45 |
|
|
B Undefined_Handler
|
46 |
|
|
SVC_Handler:
|
47 |
|
|
B SVC_Handler
|
48 |
|
|
Prefetch_Handler:
|
49 |
|
|
B Prefetch_Handler
|
50 |
|
|
Abort_Handler:
|
51 |
|
|
B Abort_Handler
|
52 |
|
|
|
53 |
|
|
FIQ_Handler:
|
54 |
|
|
B FIQ_Handler
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
#==================================================================
|
58 |
|
|
# Reset Handler
|
59 |
|
|
#==================================================================
|
60 |
|
|
|
61 |
|
|
# .global Reset_Handler
|
62 |
|
|
# .type Reset_Handler, "function"
|
63 |
|
|
Reset_Handler:
|
64 |
|
|
#==================================================================
|
65 |
|
|
# Disable MPU and caches
|
66 |
|
|
#==================================================================
|
67 |
|
|
|
68 |
|
|
# Disable MPU and cache in case it was left enabled from an earlier run
|
69 |
|
|
# This does not need to be done from a cold reset
|
70 |
|
|
|
71 |
|
|
MRC p15, 0, r0, c1, c0, 0 @ Read System Control Register
|
72 |
|
|
BIC r0, r0, #0x05 @ Disable MPU (M bit) and data cache (C bit)
|
73 |
|
|
BIC r0, r0, #0x1000 @ Disable instruction cache (I bit)
|
74 |
|
|
DSB @ Ensure all previous loads/stores have completed
|
75 |
|
|
MCR p15, 0, r0, c1, c0, 0 @ Write System Control Register
|
76 |
|
|
ISB @ Ensure subsequent insts execute wrt new MPU settings
|
77 |
|
|
|
78 |
|
|
#==================================================================
|
79 |
|
|
# Disable Branch prediction
|
80 |
|
|
#==================================================================
|
81 |
|
|
|
82 |
|
|
# In the Cortex-R5, the Z-bit of the SCTLR does not control the program flow prediction.
|
83 |
|
|
# Some control bits in the ACTLR control the program flow and prefetch features instead.
|
84 |
|
|
# These are enabled by default, but are shown here for completeness.
|
85 |
|
|
|
86 |
|
|
MRC p15, 0, r0, c1, c0, 1 @ Read ACTLR
|
87 |
|
|
ORR r0, r0, #(0x1 << 17) @ Enable RSDIS bit 17 to disable the return stack
|
88 |
|
|
ORR r0, r0, #(0x1 << 16) @ Clear BP bit 15 and set BP bit 16:
|
89 |
|
|
BIC r0, r0, #(0x1 << 15) @ Branch always not taken and history table updates disabled
|
90 |
|
|
MCR p15, 0, r0, c1, c0, 1 @ Write ACTLR
|
91 |
|
|
|
92 |
|
|
# Bits M[4:0] in CPSR register
|
93 |
|
|
.equ Mode_User, 0x10
|
94 |
|
|
.equ Mode_FIQ, 0x11
|
95 |
|
|
.equ Mode_IRQ, 0x12
|
96 |
|
|
.equ Mode_SVC, 0x13 @ supervisor (after reset)
|
97 |
|
|
.equ Mode_ABORT, 0x17
|
98 |
|
|
.equ Mode_UNDEF, 0x1B
|
99 |
|
|
.equ Mode_SYSTEM, 0x1F
|
100 |
|
|
# The I and F bits are the interrupt disable bits
|
101 |
|
|
.equ F_Bit, 0x40 @ FIQ disable
|
102 |
|
|
.equ I_Bit, 0x80 @ IRQ disable
|
103 |
|
|
|
104 |
|
|
LDR r10,=0x0
|
105 |
|
|
LDR r11,=0x0
|
106 |
|
|
LDR r12,=0x0
|
107 |
|
|
LDR r13,=0x0
|
108 |
|
|
LDR r14,=0x0 @ lp
|
109 |
|
|
|
110 |
|
|
LDR r0, =(STACK_BASE-16)
|
111 |
|
|
# @note:
|
112 |
|
|
# MSR CPSR_c, xxxx ; sets the control bits
|
113 |
|
|
# MSR CPSR_f, xxxx ; sets the flag bits
|
114 |
|
|
# MSR CPSR_cxsf, xxxx ; sets everything
|
115 |
|
|
# MRS R0, CPSR ; Copy CPSR into R0
|
116 |
|
|
|
117 |
|
|
# Init FIQ stack pointer
|
118 |
|
|
MSR CPSR_c, #(Mode_FIQ | I_Bit | F_Bit) @ Interrupts disabled
|
119 |
|
|
MOV SP, R0
|
120 |
|
|
MOV FP, R0
|
121 |
|
|
#SUB R0, R0, #Len_FIQ_Stack
|
122 |
|
|
# Init IRQ stack pointer
|
123 |
|
|
MSR CPSR_c, #(Mode_IRQ | I_Bit | F_Bit) @ Interrupts disabled
|
124 |
|
|
MOV SP, R0
|
125 |
|
|
#SUB R0, R0, #Len_IRQ_Stack
|
126 |
|
|
# Init IRQ stack pointer (default = Superviser mode)
|
127 |
|
|
MSR CPSR_c, #(Mode_SVC | I_Bit | F_Bit) @ Interrupts disabled
|
128 |
|
|
MOV SP, R0
|
129 |
|
|
MOV FP, R0
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
#==================================================================
|
133 |
|
|
# Cache invalidation
|
134 |
|
|
#==================================================================
|
135 |
|
|
DSB @ Complete all outstanding explicit memory operations
|
136 |
|
|
MOV r0, #0
|
137 |
|
|
MCR p15, 0, r0, c7, c5, 0 @ Invalidate entire instruction cache
|
138 |
|
|
MCR p15, 0, r0, c15, c5, 0 @ Invalidate entire data cache
|
139 |
|
|
|
140 |
|
|
B 0x10000000
|
141 |
|
|
.size Reset_Handler, . - Reset_Handler
|
142 |
|
|
|