-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstart.s
96 lines (85 loc) · 1.99 KB
/
start.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
.globl _start
_start:
mov sp, #0x7000 @ Set SVC stack pointer
bl _cstart
hang: b reboot
/*
* Enable/disable interrupts.
*
* CPSR = current program status register
* upper bits are differen carry flags.
* lower 8:
* 7 6 5 4 3 2 1 0
* +-+-+-+---------+
* |I|F|T| Mode |
* +-+-+-+---------+
*
* I : disables IRQ when = 1.
* F : disables FIQ when = 1.
* T : = 0 indicates ARM execution, = 1 is thumb execution.
* Mode = current mode.
*/
.globl system_enable_interrupts
system_enable_interrupts:
mrs r0,cpsr // mrs: move coprocessor register to CPU register
bic r0,r0,#0x80 // bic: bit clear
msr cpsr_c,r0 // msr: CPU register to coprocessor register
bx lr
.globl system_disable_interrupts
system_disable_interrupts:
mrs r0,cpsr
orr r0,r0,#0x80
msr cpsr_c,r0
bx lr
/*
* Interrupt vectors.
*/
.globl _vectors
.globl _vectors_end
_vectors:
ldr pc, _reset_asm
ldr pc, _undefined_instruction_asm
ldr pc, _software_interrupt_asm
ldr pc, _prefetch_abort_asm
ldr pc, _data_abort_asm
ldr pc, _reset_asm
ldr pc, _interrupt_asm
fast_interrupt_asm:
ldr pc, _fast_asm
_reset_asm: .word impossible_asm
_undefined_instruction_asm: .word impossible_asm
_software_interrupt_asm: .word impossible_asm
_prefetch_abort_asm: .word impossible_asm
_data_abort_asm: .word impossible_asm
_interrupt_asm: .word interrupt_asm
_fast_asm: .word impossible_asm
_vectors_end:
interrupt_asm:
mov sp, #0x8000
sub lr, lr, #4
push {r0-r12, lr}
mov r0, lr
bl interrupt_vector
pop {r0-r12, lr}
// jump back
subs pc, lr, #0
impossible_asm:
mov sp, #0x7000 @ Set SVC stack pointer
sub lr, lr, #4
bl impossible_vector @ C function
b reboot
/*
* Helpers to get cpsr/spsr
*/
.globl set_cpsr
set_cpsr:
msr cpsr, r0
bx lr
.globl get_cpsr
get_cpsr:
mrs r0, cpsr
bx lr
.globl get_spsr
get_spsr:
mrs r0, spsr
bx lr