-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.S
66 lines (60 loc) · 985 Bytes
/
task.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
#include <avr/common.h>
.ifndef zero_reg
#ifdef __AVR_TINY__
zero_reg = 17
#else
zero_reg = 1
#endif
.endif
/* stable C ABI - see header */
.global task_terminate
/* unstable ABI */
.global task_block_
.global task_unblock_
.section .data
.byte lo8(cpu_queue)
.byte hi8(cpu_queue)
cpu_queue:
.byte 0
.byte 0
.section .text
task_block_:
push zero_reg ; potentially faster than ST with pre-decrement
in XL, _SFR_IO_ADDR(SPL)
in XH, _SFR_IO_ADDR(SPH)
st X, zero_reg
movw r24, X
ld XH, -Z
ld XL, -Z
st Z+, r24
st Z, r25
st X+, r24
st X, r25
task_terminate:
lds XL, cpu_queue
lds XH, cpu_queue+1
ld r24, X+
sts cpu_queue, r24
ld r24, X
sts cpu_queue+1, r24
out _SFR_IO_ADDR(SPL), XL
out _SFR_IO_ADDR(SPH), XH
ret
task_unblock_:
ld ZL, X+
ld ZH, X
sbiw Z, 0
breq 0f
ld r24, Z+
ld r25, Z
st X, r24
st -X, r25
st Z, zero_reg
st -Z, zero_reg
lds XH, cpu_queue-1
lds XL, cpu_queue-2
st X+, ZL
st X, ZH
sts cpu_queue-1, ZH
sts cpu_queue-2, ZL
0: ret