aboutsummaryrefslogtreecommitdiff
path: root/later/schedule.S
blob: 1811c7cfdae042eac71384b4bcfd20dcdabbfc78 (plain)
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
.section .text
.globl preserveregs
preserveregs:
	str r4,  [r0, #0x10]
	str r5,  [r0, #0x14]
	str r6,  [r0, #0x18]
	str r7,  [r0, #0x1c]
	str r8,  [r0, #0x20]
	str r9,  [r0, #0x24]
	str r10, [r0, #0x28]
	str r11, [r0, #0x2c]
	bx lr

.globl restoreregs
restoreregs:
	ldr r4,  [r0, #0x10]
	ldr r5,  [r0, #0x14]
	ldr r6,  [r0, #0x18]
	ldr r7,  [r0, #0x1c]
	ldr r8,  [r0, #0x20]
	ldr r9,  [r0, #0x24]
	ldr r10, [r0, #0x28]
	ldr r11, [r0, #0x2c]
	bx lr

.globl exetask
exetask:
	push {r0, r4, r5, r6, r7, r8, r9, r10, r11, lr}
	// Restore registers from context switch
	ldr r4,  [r0, #0x10]
	ldr r5,  [r0, #0x14]
	ldr r6,  [r0, #0x18]
	ldr r7,  [r0, #0x1c]
	ldr r8,  [r0, #0x20]
	ldr r9,  [r0, #0x24]
	ldr r10, [r0, #0x28]
	ldr r11, [r0, #0x2c]

	// Preserve system stack
	ldr r1,  =msp
	str sp, [r1]
	// Setup task's stack
	ldr sp, [r0, #0x34]
	// Switch to task
	ldr lr, [r0, #0x3c]
	blx lr
	// Restore system stack
	ldr r1, =msp
	ldr sp, [r1]
	pop {r0, r4, r5, r6, r7, r8, r9, r10, r11, pc}

.section .data
msp:
	.space 4
.section .data.stacks
.globl stacks
stacks:
	.space 0x100000