-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathassembly.h
69 lines (59 loc) · 1.28 KB
/
assembly.h
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
/*
* Raspberry PI Remote Serial Protocol.
* Copyright 2012 Jamie Iles, jamie@jamieiles.com.
* Licensed under GPLv2.
*/
#ifndef __ASSEMBLY_H__
#define __ASSEMBLY_H__
#define CPSR_MODE_SVC 0x13
#define CPSR_MODE_MON 0x16
#define IRQ_DISABLE 0x80
#define FIQ_DISABLE 0x40
.macro push_arm_regs mode
sub sp, sp, #68
stmia sp, {r0-r12} /* Push the main registers. */
ldr r0, [sp, #72]
str r0, [sp, #60]
ldr r0, [sp, #76] /* Switch to old mode, grab sp + lr. */
mov r3, r0
orr r0, r0, #(IRQ_DISABLE | FIQ_DISABLE)
msr cpsr_c, r0
mov r1, sp
mov r2, lr
cps \mode
str r1, [sp, #52]
str r2, [sp, #56]
str r3, [sp, #64]
mov r0, sp
.endm
.macro pop_arm_regs mode
ldr r1, [sp, #52]
ldr r2, [sp, #56]
ldr r0, [sp, #64] /* Switch to old mode, grab sp + lr. */
orr r0, r0, #(IRQ_DISABLE | FIQ_DISABLE)
msr cpsr_c, r0
mov sp, r1 /* Restore sp. */
mov lr, r2 /* Restore lr. */
cps \mode
ldr r0, [sp, #60]
str r0, [sp, #72] /* Fixup return PC. */
ldmia sp, {r0-r12}
add sp, #68
.endm
.macro ex_handler lr_fixup, handler, mode
sub lr, lr, \lr_fixup
srsdb sp!, \mode
cps \mode
cpsid if
push {lr}
push_arm_regs \mode
bl \handler
pop_arm_regs \mode
pop {lr}
cpsie if
rfeia sp!
.endm
#define VECTOR(_type) \
.globl _vec_##_type; \
_vec_##_type:
#endif /* __ASSEMBLY_H__ */