-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTSOutline.X68
More file actions
307 lines (162 loc) · 7.56 KB
/
RTSOutline.X68
File metadata and controls
307 lines (162 loc) · 7.56 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
*-----------------------------------------------------------
* Title : RTS
* Written by : JNC
* Date : Dec 23
* Description: Outline runtime system
*-----------------------------------------------------------
;system call equates
sys equ 0 ; system call trap (trap 0)
syscr equ 1 ; create new task
sysdel equ 2 ; delete task
syswtmx equ 3 ; wait on mutex
syssgmx equ 4 ; signal mutex
sysinmx equ 5 ; initialise mutex
syswttm equ 6 ; wait on timer
usrcode equ $1000 ;address of user task 0
usrstk equ $8000 ;address of user stack
ntcblst equ 8 ;number of records in tcb list
tcb org 0 ;tcb record
tcbd0 ds.l 1 ; D register save
tcbd1 ds.l 1
tcbd2 ds.l 1
tcbd3 ds.l 1
tcbd4 ds.l 1
tcbd5 ds.l 1
tcbd6 ds.l 1
tcbd7 ds.l 1
tcba0 ds.l 1 ; A register save
tcba1 ds.l 1
tcba2 ds.l 1
tcba3 ds.l 1
tcba4 ds.l 1
tcba5 ds.l 1
tcba6 ds.l 1
tcba7 ds.l 1
tcbsr ds.l 1 ; SR (status reg) save
tcbpc ds.l 1 ; PC save
tcbnext ds.l 1 ; link to next record
tcbused ds.l 1 ; record in use flag
tcbwtim ds.l 1 ; timer wait expiry time
tcblen equ * ; length of tcb record
;******************************************************************************
rts ;RUNTIME SYSTEM
;******************************************************************************
;******************************************************************************
;INTERRUPT VECTORS
;******************************************************************************
org 0
dc.l usrstk ; initial SP
dc.l res ; reset
ds.b $5C
dc.l fltint ; interrupt 1 (timer)
ds.b $18
dc.l flsint ; trap 0 (system call)
;*******************************************************************************
res ;RESET
;*******************************************************************************
;*******************************************************************************
flih ;FIRST-LEVEL INTERRUPT HANDLER
;*******************************************************************************
fltint ;ENTRY FROM TIMER INTERRUPT
move.l d0,d0sav ;save D0
move.l #$0,d0 ;set id = 0
move.l d0,id
move.l d0sav,d0 ;restore D0
bra fl1
flsint ;ENTRY FROM TRAP (SOFTWARE INTERRUPT)
or #%0000011100000000,sr ;disable hardware interrupts
move.l d0,id ;store id
bra fl1
fl1 move.l a0,a0sav ;save working reg
move.l rdytcb,a0 ;A0 ^ 1st ready tcb (ie running tcb)
move.l d0,tcbd0(a0) ;store registers
move.l d1,tcbd1(a0)
move.l d2,tcbd2(a0)
move.l d3,tcbd3(a0)
move.l d4,tcbd4(a0)
move.l d5,tcbd5(a0)
move.l d6,tcbd6(a0)
move.l d7,tcbd7(a0)
move.l a0sav,d0
move.l d0,tcba0(a0)
move.l a1,tcba1(a0)
move.l a2,tcba2(a0)
move.l a3,tcba3(a0)
move.l a4,tcba4(a0)
move.l a5,tcba5(a0)
move.l a6,tcba6(a0)
move (sp),d0 ;pop and store SR
add.l #2,sp
move.l d0,tcbsr(a0)
move.l (sp),d0 ;pop and store PC
add.l #4,sp
move.l d0,tcbpc(a0)
move.l a7,tcba7(a0) ;store SP
;******************************************************************************
serv ;SERVICE ROUTINES
;******************************************************************************
;*******************************************************************************
sched ;SCHEDULER
;*******************************************************************************
;*******************************************************************************
disp ;DISPATCHER
;*******************************************************************************
move.l rdytcb,a0 ;A0 ^ new running tcb
move.l tcbd1(a0),d1 ;restore registers
move.l tcbd2(a0),d2
move.l tcbd3(a0),d3
move.l tcbd4(a0),d4
move.l tcbd5(a0),d5
move.l tcbd6(a0),d6
move.l tcbd7(a0),d7
move.l tcba1(a0),a1
move.l tcba2(a0),a2
move.l tcba3(a0),a3
move.l tcba4(a0),a4
move.l tcba5(a0),a5
move.l tcba6(a0),a6
move.l tcba7(a0),a7
sub.l #4,sp ;push PC
move.l tcbpc(a0),d0
move.l d0,(sp)
sub.l #2,sp
move.l tcbsr(a0),d0 ;push SR
move d0,(sp)
move.l tcbd0(a0),d0 ;restore remaining registers
move.l tcba0(a0),a0
rte ;return
;*******************************************************************************
;RTS variables
;*******************************************************************************
tcblst ds.b tcblen*ntcblst ;tcb list
rdytcb ds.l 1 ;^ ready tcb list
wttcb ds.l 1 ;^ waiting tcb
a0sav ds.l 1 ;A0 temporary save
d0sav ds.l 1 ;D0 temporary save
id ds.l 1 ;function id
time ds.l 1 ;system time
;*******************************************************************************
;USER APPLICATION TASKS
;*******************************************************************************
org usrcode
led equ $e00010 ;led
sw equ $e00014 ;switch
t0: ;TASK 0
move.l #syscr,d0 ;start task 1
move.l #t1,d1
move.l #$4000,d2
trap #sys
;repeat
t00: move.l #$01,d1 ; set led 0
move.b d1,led
bra t00
t1: ;TASK 1
;repeat
move.l #$02,d0 ; set led 1
move.b d0,led
bra t1
END res
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~4~