-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_switch.s
62 lines (50 loc) · 1.22 KB
/
context_switch.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
.global irq_entry
irq_entry:
/* Save user state */
msr CPSR_c, #0xDF /* System mode */
push {r7} /* Just like in syscall wrapper */
/* Load PIC status */
ldr r7, PIC
ldr r7, [r7]
PIC: .word 0x10140000
/* Most significant bit index */
clz r7, r7
sub r7, r7, #31
push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,fp,ip,lr}
mov r0, sp
msr CPSR_c, #0xD2 /* IRQ mode */
mrs ip, SPSR
sub lr, lr, #0x4 /* lr is address of next instruction */
stmfd r0!, {ip,lr}
msr CPSR_c, #0xD3 /* Supervisor mode */
/* Load kernel state */
pop {r4,r5,r6,r7,r8,r9,r10,fp,ip,lr}
mov sp, ip
bx lr
.global svc_entry
svc_entry:
/* Save user state*/
msr CPSR_c, #0xDF /* System mode */
push {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,fp,ip,lr}
mov r0, sp
msr CPSR_c, #0xD3 /* Supervisor mode */
mrs ip, SPSR
stmfd r0!, {ip,lr}
/* Load kernel state */
pop {r4,r5,r6,r7,r8,r9,r10,fp,ip,lr}
mov sp, ip
bx lr
.type activate, %function
.global activate
activate:
/* Save kernel state */
mov ip, sp
push {r4,r5,r6,r7,r8,r9,r10,fp,ip,lr}
ldmfd r0!, {ip,lr} /* Get SPSR and lr */
msr SPSR, ip
msr CPSR_c, #0xDF /* System mode */
mov sp, r0
pop {r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,fp,ip,lr}
pop {r7}
msr CPSR_c, #0xD3 /* Supervisor mode */
movs pc, lr