-
Notifications
You must be signed in to change notification settings - Fork 2
/
syscall.asm
executable file
·112 lines (92 loc) · 3.6 KB
/
syscall.asm
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "config.inc"
NAME SYSCALL
EXTRN CODE (_SWITCH_)
PUBLIC WAIT, WAKEUP
SYSCALL SEGMENT CODE
RSEG SYSCALL
;********************************************************
;* *
;* WAIT *
;* *
;********************************************************
WAIT:
;save environment
PUSH PSW
PUSH ACC
SETB RS1 ;switch to register group-3
SETB RS0
PUSH 18H
;judge is the operator is current task
MOV A,TASK_NUM_LOC ;get value of TASK_NUM_LOC
CJNE A,#0FFH,_SLFG1_ ;#0FFH means current task
;is current task
MOV A,CUR_SP_LOC ;get value of CUR_SP_LOC
ADD A,#08H ;caculate WAIT TIME location
SJMP _SLFG3_
;not current task, need judge if the task number is legal
_SLFG1_:
CLR C
PUSH ACC
SUBB A,#08H ;all task number should be smaller then #08H
POP ACC
JNC _SLFG4_ ;test C, C==1 means TASK NUM larger then seven, it's illegal
ADD A,#38H ;caculate WAIT TIME location
SJMP _SLFG3_
_SLFG4_:
MOV RETURN_LOC,#01H ;set RETURN_LOC value to #01H, means encountered error
SJMP _SLFG2_
;set value of wait state
_SLFG3_:
MOV RETURN_LOC,#00H ;set RETURN_LOC value to #00H, means successed
MOV R0,A
MOV A,WAIT_TIME_LOC ;get value of WAIT_TIME_LOC
MOV @R0,A ;save WAIT TIME to WAIT TIME location
;if is current task, we need SWITCH, else just return
MOV A,CUR_SP_LOC ;get value of CUR_SP_LOC
ADD A,#08H ;caculate WAIT TIME location
CJNE A,18H,_SLFG2_ ;current task WAIT TIME location(A) == TASK_NUM_LOC's task WAIT TIME location(R0) means is curren task
POP 18H
POP ACC
POP PSW
LJMP _SWITCH_ ;will use RETI in _SWITCH_ to return to next task
;restore environment
_SLFG2_:
POP 18H
POP ACC
POP PSW
RET
;********************************************************
;* *
;* WAKEUP *
;* *
;********************************************************
WAKEUP:
;save environment
PUSH PSW
PUSH ACC
SETB RS1 ;switch to register group-3
SETB RS0
PUSH 18H
;get and judge if the task number is legal
MOV A,TASK_NUM_LOC ;get value of TASK_NUM_LOC
MOV R0,A
CLR C
SUBB A,#08H ;all task number should be smaller then #08H
JC _SLFG5_ ;test C, C==1 means TASK NUM larger then seven, it's illegal
;illegal task number
MOV RETURN_LOC,#01H ;set RETURN_LOC value to #01H, means encountered error
SJMP _SLFG6_
;set value of wait state, then if is current task, we need SWITCH, else just return
_SLFG5_:
MOV RETURN_LOC,#00H ;set RETURN_LOC value to #00H, means successed
MOV A,R0 ;caculate WAIT TIME location
ADD A,#38H
MOV R0,A
MOV @R0,#00H ;save WAIT TIME to WAIT TIME location, #00H means running
;restore environment
_SLFG6_:
POP 18H
POP ACC
POP PSW
RET
END