Mercurial > hg > Members > kono > nitros9-code
annotate level2/modules/kernel/krn.asm @ 1624:bb75784a1ec5
Minor source change by Rodney H.
author | boisy |
---|---|
date | Wed, 30 Jun 2004 01:07:36 +0000 |
parents | 5f18094d961d |
children | 5ecf6e023a64 |
rev | line source |
---|---|
1145 | 1 ******************************************************************** |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
2 * krn - NitrOS-9 Level 2 Kernel |
1145 | 3 * |
4 * $Id$ | |
5 * | |
1378 | 6 * Edt/Rev YYYY/MM/DD Modified by |
7 * Comment | |
1145 | 8 * ------------------------------------------------------------------ |
1378 | 9 * 19r6 2002/08/21 Boisy G. Pitre |
10 * Assembles to the os9p1 module that works on my NitrOS-9 system. | |
11 * | |
12 * 19r7 2002/09/26 Boisy G. Pitre | |
13 * Added check for CRC feature bit in init module | |
14 * | |
15 * 19r8 2003/09/22 Boisy G. Pitre | |
16 * Back-ported to OS-9 Level Two. | |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
17 * |
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
18 * 19r8 2004/05/22 Boisy G. Pitre |
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
19 * Renamed to 'krn' |
1145 | 20 |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
21 nam krn |
1378 | 22 ttl NitrOS-9 Level 2 Kernel |
1145 | 23 |
24 IFP1 | |
25 use defsfile | |
26 ENDC | |
27 | |
28 * defines for customizations | |
1251
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
29 Revision set 8 module revision |
1145 | 30 Edition set 19 module Edition |
1378 | 31 Where equ $F000 absolute address of where Kernel starts in memory |
1145 | 32 |
1387 | 33 mod eom,MName,Systm,ReEnt+Revision,entry,0 |
1145 | 34 |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
35 MName fcs /krn/ |
1145 | 36 fcb Edition |
37 | |
1378 | 38 * FILL - all unused bytes are now here |
1399 | 39 fcc /www.katvixen.com/ |
1146 | 40 IFNE H6309 |
1145 | 41 fcc /0123456789ABCDEF/ |
42 fcc /0123456789ABCDEF/ | |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
43 fcc /0123456/ |
1146 | 44 ELSE |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
45 fcc /012345678/ |
1146 | 46 ENDC |
1145 | 47 |
1378 | 48 * Might as well have this here as just past the end of Kernel... |
1145 | 49 DisTable fdb L0CD2+Where D.Clock absolute address at the start |
50 fdb XSWI3+Where D.XSWI3 | |
51 fdb XSWI2+Where D.XSWI2 | |
52 fdb D.Crash D.XFIRQ crash on an FIRQ | |
53 fdb XIRQ+Where D.XIRQ | |
54 fdb XSWI+Where D.XSWI | |
55 fdb D.Crash D.XNMI crash on an NMI | |
56 fdb $0055 D.ErrRst ??? Not used as far as I can tell | |
1378 | 57 fdb Sys.Vec+Where Initial Kernel system call vector |
1145 | 58 DisSize equ *-DisTable |
59 * DO NOT ADD ANYTHING BETWEEN THESE 2 TABLES: see code using 'SubSiz', below | |
60 LowSub equ $0160 start of low memory subroutines | |
61 SubStrt equ * | |
62 * D.Flip0 - switch to system task 0 | |
63 R.Flip0 equ * | |
64 IFNE H6309 | |
65 aim #$FE,<D.TINIT map type 0 | |
66 lde <D.TINIT 'nother 2 bytes saved if GRFDRV does a 'tfr cc,e' | |
67 ste >DAT.Task and we can use A here, instead of E | |
68 ELSE | |
69 pshs a | |
70 lda <D.TINIT | |
71 anda #$FE | |
72 sta <D.TINIT | |
73 sta >DAT.Task | |
74 puls a | |
75 ENDC | |
1258 | 76 clr <D.SSTskN |
1145 | 77 tfr x,s |
78 tfr a,cc | |
79 rts | |
80 SubSiz equ *-SubStrt | |
81 * Don't add any code here: See L0065, below. | |
82 * Interrupt service routine | |
1239 | 83 Vectors jmp [<-(D.SWI3-D.XSWI3),x] (-$10) (Jmp to 2ndary vector) |
1145 | 84 |
85 * Let's start by initializing system page | |
1387 | 86 entry equ * |
1445 | 87 IFEQ Level-1 |
88 IFNE H6309 | |
89 ldq #(D.FMBM*256)+($400-D.FMBM) | |
90 leay <entry+2,pc | |
91 tfm y,d+ | |
92 tfr d,x | |
93 ELSE | |
94 ldx #D.FMBM | |
95 ldy #$400-D.FMBM | |
96 clra | |
97 clrb | |
98 loop1 std ,x++ | |
99 leay -2,y | |
100 bne loop1 | |
101 ENDC | |
102 ELSE | |
1145 | 103 IFNE H6309 |
104 ldq #$01001f00 Start address to clear & # bytes to clear | |
1387 | 105 leay <entry+2,pc Point to a 0 |
1145 | 106 tfm y,d+ |
1239 | 107 std <D.CCStk Set pointer to top of global memory to $2000 |
108 lda #$01 set task user table to $0100 | |
1145 | 109 ELSE |
110 ldx #$100 | |
1239 | 111 ldy #$2000-$100 |
1145 | 112 clra |
113 clrb | |
114 L001C std ,x++ | |
115 leay -2,y | |
116 bne L001C | |
1239 | 117 stx <D.CCStk Set pointer to top of global memory to $2000 |
118 inca D = $0100 | |
1145 | 119 ENDC |
1445 | 120 ENDC |
121 | |
1145 | 122 * Setup system direct page variables |
1445 | 123 IFEQ Level-1 |
124 * For Level 1 this is how the memory map looks after | |
125 * the kernel has initialized: | |
126 * | |
127 * $0000----> ================================== | |
128 * | | | |
129 * | | | |
130 * $0020-$0111 | System Globals (D.FMBM-D.XNMI) | | |
131 * | | | |
132 * | | | |
133 * $0200---->|==================================| | |
134 * | Free Memory Bitmap | | |
135 * $0200-$021F | (1 bit = 256 byte page) | | |
136 * |----------------------------------| | |
137 * | System Dispatch Table | | |
138 * $0222-$0291 | (Room for 56 addresses) | | |
139 * |----------------------------------| | |
140 * $0292-$02FF | User Dispatch Table | | |
141 * | (Room for 56 addresses) | | |
142 * $0300---->|==================================| | |
143 * | | | |
144 * | | | |
145 * $0300-$03FF | Module Directory Entries | | |
146 * | (Room for 64 entries) | | |
147 * | | | |
148 * $0400---->|==================================| | |
149 * | | | |
150 * $0400-$04FF | System Stack | | |
151 * | | | |
152 * $0500---->|==================================| | |
153 | |
154 ldd #$200 | |
155 std <D.FMBM $200 = start of free memory bitmap | |
156 addb #$20 | |
157 std D.FMBM+2 $220 = end of free memory bitmap | |
158 addb #$02 | |
159 std <D.SysDis $222 = addr of sys dispatch table | |
160 addb #$70 | |
161 std <D.UsrDis $292 = addr of sys dispatch table | |
162 clrb | |
163 inca D = $300 | |
164 std <D.ModDir $300 = module dir start | |
165 stx <D.ModDir+2 $400 = module dir start | |
166 leas >$0100,x S = $500 (system stack) | |
167 ELSE | |
1145 | 168 std <D.Tasks |
169 addb #$20 set Task image table to $0120 | |
170 std <D.TskIPt | |
171 clrb set memory block map to $0200 | |
172 inca | |
173 std <D.BlkMap | |
174 addb #$40 set second block map to $0240 | |
175 std <D.BlkMap+2 | |
176 clrb set system service dispatch table to $0300 | |
177 inca | |
178 std <D.SysDis | |
179 inca set user dispatch table to $0400 | |
180 std <D.UsrDis | |
181 inca set process descriptor block to $0500 | |
182 std <D.PrcDBT | |
183 inca set system process descriptor to $0600 | |
184 std <D.SysPrc | |
185 std <D.Proc set user process descriptor to $0600 | |
186 adda #$02 set stack pointer to $0800 | |
187 tfr d,s | |
188 inca set system stack to $0900 | |
189 std <D.SysStk | |
190 std <D.SysMem set system memory map ptr $0900 | |
191 inca set module directory start to $0a00 | |
192 std <D.ModDir | |
193 std <D.ModEnd set module directory end to $0a00 | |
194 adda #$06 set secondary module directory start to $1000 | |
195 std <D.ModDir+2 | |
196 std <D.ModDAT set module directory DAT pointer to $1000 | |
1239 | 197 std <D.CCMem set pointer to beginning of global memory to $1000 |
1445 | 198 ENDC |
1145 | 199 * In following line, CRC=ON if it is STA <D.CRC, CRC=OFF if it is a STB <D.CRC |
200 stb <D.CRC set CRC checking flag to off | |
201 | |
202 * Initialize interrupt vector tables | |
1203 | 203 leay <DisTable,pcr point to table of absolute vector addresses |
1145 | 204 ldx #D.Clock where to put it in memory |
205 IFNE H6309 | |
206 ldf #DisSize size of the table - E=0 from TFM, above | |
207 tfm y+,x+ move it over | |
208 ELSE | |
209 ldb #DisSize | |
210 LoopCopy lda ,y+ | |
211 sta ,x+ | |
212 decb | |
213 bne LoopCopy | |
214 ENDC | |
215 | |
216 * initialize D.Flip0 routine in low memory | |
217 * Y=ptr to R.Flip0 already | |
218 * leay >R.Flip0,pc | |
219 ldu #LowSub somewhere in block 0 that's never modified | |
220 stu <D.Flip0 switch to system task 0 | |
221 IFNE H6309 | |
222 ldf #SubSiz size of it | |
223 tfm y+,u+ copy it over | |
224 ELSE | |
225 ldb #SubSiz | |
226 Loop2 lda ,y+ | |
227 sta ,u+ | |
228 decb | |
229 bne Loop2 | |
230 ENDC | |
231 | |
1239 | 232 * leau <Vectors,pc point to vector |
1145 | 233 tfr y,u move the pointer to a faster register |
1239 | 234 L0065 stu ,x++ Set all IRQ vectors to go to Vectors for now |
1145 | 235 cmpx #D.NMI |
236 bls L0065 | |
237 | |
238 * Initialize user interupt vectors | |
239 ldx <D.XSWI2 Get SWI2 (os9 command) service routine pointer | |
240 stx <D.UsrSvc Save it as user service routine pointer | |
241 ldx <D.XIRQ Get IRQ service routine pointer | |
242 stx <D.UsrIRQ Save it as user IRQ routine pointer | |
1239 | 243 |
244 leax >SysCall,pc Setup System service routine entry vector | |
1145 | 245 stx <D.SysSvc |
246 stx <D.XSWI2 | |
1239 | 247 |
248 leax >S.SysIRQ,pc Setup system IRQ service vector | |
1145 | 249 stx <D.SysIRQ |
250 stx <D.XIRQ | |
1239 | 251 |
252 leax >S.SvcIRQ,pc Setup in system IRQ service vector | |
1145 | 253 stx <D.SvcIRQ |
1239 | 254 leax >S.Poll,pc Setup interrupt polling vector |
1145 | 255 stx <D.Poll ORCC #$01;RTS |
1239 | 256 leax >S.AltIRQ,pc Setup alternate IRQ vector: pts to an RTS |
1145 | 257 stx <D.AltIRQ |
258 | |
1378 | 259 lda #'K --- in Kernel |
1145 | 260 jsr <D.BtBug --- |
261 | |
1239 | 262 leax >S.Flip1,pc Setup change to task 1 vector |
1145 | 263 stx <D.Flip1 |
1239 | 264 |
1145 | 265 * Setup System calls |
1239 | 266 leay >SysCalls,pc |
267 lbsr SysSvc | |
268 | |
1145 | 269 * Initialize system process descriptor |
270 ldu <D.PrcDBT get process table pointer | |
271 ldx <D.SysPrc get system process pointer | |
1239 | 272 |
1145 | 273 * These overlap because it is quicker than trying to strip hi byte from X |
274 stx ,u save it as first process in table | |
275 stx 1,u save it as the second as well | |
276 IFNE H6309 | |
277 oim #$01,P$ID,x Set process ID to 1 (inited to 0) | |
278 oim #SysState,P$State,x Set to system state (inited to 0) | |
279 ELSE | |
280 ldd #$01*256+SysState | |
281 sta P$ID,x | |
282 stb P$State,x | |
283 ENDC | |
284 clra System task is task #0 | |
285 sta <D.SysTsk | |
286 sta P$Task,x | |
287 coma Setup its priority & age ($FF) | |
288 sta P$Prior,x | |
289 sta P$Age,x | |
290 leax <P$DATImg,x point to DAT image | |
291 stx <D.SysDAT save it as a pointer in DP | |
292 * actually, since block 0 is tfm'd to be zero, we can skip the next 2 lines | |
293 IFNE H6309 | |
294 clrd | |
295 ELSE | |
296 clra | |
297 clrb | |
298 ENDC | |
299 std ,x++ initialize 1st block to 0 (for this DP) | |
1239 | 300 |
301 * Dat.BlCt-ROMCount-RAMCount | |
1145 | 302 lda #$06 initialize the rest of the blocks to be free |
303 ldu #DAT.Free | |
304 L00EF stu ,x++ | |
305 deca | |
306 bne L00EF | |
1239 | 307 |
1145 | 308 ldu #$003F Block $3F is in use, at the top of system DAT image |
1146 | 309 stu ,x |
1239 | 310 |
1145 | 311 ldx <D.Tasks Point to task user table |
312 inc ,x mark first 2 in use (system & GrfDrv) | |
313 inc 1,x | |
1239 | 314 |
1145 | 315 * Setup system memory map |
316 ldx <D.SysMem Get system memory map pointer | |
317 ldb <D.CCStk Get MSB of top of CC memory | |
318 L0104 inc ,x+ Mark it as used | |
319 decb Done? | |
320 bne L0104 No, go back till done | |
321 | |
322 * Calculate memory size | |
323 ldx <D.BlkMap get ptr to 8k block map | |
324 inc <$3F,x mark block $3F as used (kernel) | |
325 IFNE H6309 | |
326 ldq #$00080100 e=Marker, D=Block # to check | |
327 L0111 asld get next block # | |
328 stb >$FFA5 Map block into block 6 of my task | |
329 ste >-$6000,x save marker to that block | |
330 cmpe ,x did it ghost to block 0? | |
331 bne L0111 No, keep going till ghost is found | |
332 stb <D.MemSz Save # 8k mem blocks that exist | |
333 addr x,d add number of blocks to block map start | |
334 ELSE | |
335 ldd #$0008 | |
1239 | 336 L0111 aslb |
337 rola | |
1145 | 338 stb >$FFA5 |
339 pshs a | |
340 lda #$01 | |
341 sta >-$6000,x | |
342 cmpa ,x | |
343 puls a | |
1239 | 344 bne L0111 |
345 stb <D.MemSz | |
1145 | 346 pshs x |
347 addd ,s++ | |
348 ENDC | |
1240 | 349 std <D.BlkMap+2 save block map end pointer |
350 | |
1145 | 351 * [D] at this point will contain 1 of the following: |
1251
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
352 * $0210 - 128k |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
353 * $0220 - 256k |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
354 * $0240 - 512k |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
355 * $0280 - 1024k |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
356 * $0300 - 2048k |
1145 | 357 bitb #%00110000 block above 128K-256K? |
358 beq L0170 yes, no need to mark block map | |
359 tstb 2 meg? | |
360 beq L0170 yes, skip this | |
361 * Mark blocks from 128k-256K to block $3F as NOT RAM | |
362 abx add maximum block number to block map start | |
363 leax -1,x Skip good blocks that are RAM | |
364 lda #NotRAM Not RAM flag | |
365 subb #$3F Calculate # blocks to mark as not RAM | |
366 L0127 sta ,x+ Mark them all | |
367 decb | |
368 bne L0127 | |
369 | |
370 L0170 ldx #Bt.Start start address of the boot track in memory | |
371 lda #$12 size of the boot track: B=$00 from L0127 loop, above | |
372 lbsr I.VBlock go verify it | |
373 | |
374 bsr L01D2 go mark system map | |
1239 | 375 |
1145 | 376 * See if init module is in memory already |
377 L01B0 leax <init,pc point to 'Init' module name | |
378 bsr link try & link it | |
379 bcc L01BF no error, go on | |
380 L01B8 os9 F$Boot error linking init, try & load boot file | |
381 bcc L01B0 got it, try init again | |
382 bra L01CE error, re-booting do D.Crash | |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
383 * Save pointer to init module and execute krnp2 |
1145 | 384 L01BF stu <D.Init Save init module pointer |
385 lda Feature1,u Get feature byte #1 from init module | |
386 bita #CRCOn CRC feature on? | |
387 beq ShowI if not, continue | |
388 inc <D.CRC else inc. CRC flag | |
389 ShowI lda #'i found init module | |
390 jsr <D.BtBug | |
391 | |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
392 L01C1 leax <krnp2,pc Point to it's name |
1145 | 393 bsr link Try to link it |
394 bcc L01D0 It worked, execute it | |
395 os9 F$Boot It doesn't exist try re-booting | |
396 bcc L01C1 No error's, let's try to link it again | |
397 L01CE jmp <D.Crash obviously can't do it, crash machine | |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
398 L01D0 jmp ,y execute krnp2 |
1239 | 399 |
1145 | 400 * Mark kernel in system memory map as used memory (256 byte blocks) |
401 L01D2 ldx <D.SysMem Get system mem ptr | |
402 ldd #NotRAM*256+$ED $ED00 is the start of the boot | |
403 abx point to Bt.Start - start of boot track | |
404 comb we have $FF-$ED pages to mark as used | |
405 sta b,x Mark I/O as not RAM | |
406 L01DF lda #RAMinUse get in use flag | |
407 L01E1 sta ,x+ save it | |
408 decb done? | |
409 bne L01E1 no, keep going | |
410 ldx <D.BlkMap get pointer to start of block map | |
411 sta <$3f,x mark kernel block as RAMinUse, instead of ModInBlk | |
1239 | 412 S.AltIRQ rts return |
1145 | 413 |
414 * Link module pointed to by X | |
415 link lda #Systm Attempt to link system module | |
416 os9 F$Link | |
417 rts | |
418 | |
419 init fcs 'Init' | |
1587
5f18094d961d
kernel modules renamed to krn, updated makefiles, clock2_tc3 now clock2_cloud9...
boisy
parents:
1445
diff
changeset
|
420 krnp2 fcs 'krnp2' |
1145 | 421 |
422 * Service vector call pointers | |
1239 | 423 SysCalls fcb F$Link |
1145 | 424 fdb FLink-*-2 |
425 fcb F$PrsNam | |
426 fdb FPrsNam-*-2 | |
427 fcb F$CmpNam | |
428 fdb FCmpNam-*-2 | |
429 fcb F$CmpNam+SysState | |
430 fdb FSCmpNam-*-2 | |
431 fcb F$CRC | |
432 fdb FCRC-*-2 | |
433 fcb F$SRqMem+SysState | |
434 fdb FSRqMem-*-2 | |
435 fcb F$SRtMem+SysState | |
436 fdb FSRtMem-*-2 | |
437 fcb F$AProc+SysState | |
438 fdb FAProc-*-2 | |
439 fcb F$NProc+SysState | |
440 fdb FNProc-*-2 | |
441 fcb F$VModul+SysState | |
442 fdb FVModul-*-2 | |
443 fcb F$SSvc+SysState | |
444 fdb FSSvc-*-2 | |
445 fcb F$SLink+SysState | |
446 fdb FSLink-*-2 | |
447 fcb F$Boot+SysState | |
448 fdb FBoot-*-2 | |
449 fcb F$BtMem+SysState | |
450 fdb FSRqMem-*-2 | |
451 IFNE H6309 | |
1146 | 452 fcb F$CpyMem |
1145 | 453 fdb FCpyMem-*-2 |
454 ENDC | |
455 fcb F$Move+SysState | |
456 fdb FMove-*-2 | |
1387 | 457 fcb F$AllRAM |
458 fdb FAllRAM-*-2 | |
1145 | 459 fcb F$AllImg+SysState |
460 fdb FAllImg-*-2 | |
461 fcb F$SetImg+SysState | |
462 fdb FFreeLB-*-2 | |
463 fcb F$FreeLB+SysState | |
464 fdb FSFreeLB-*-2 | |
465 fcb F$FreeHB+SysState | |
466 fdb FFreeHB-*-2 | |
467 fcb F$AllTsk+SysState | |
468 fdb FAllTsk-*-2 | |
469 fcb F$DelTsk+SysState | |
470 fdb FDelTsk-*-2 | |
471 fcb F$SetTsk+SysState | |
472 fdb FSetTsk-*-2 | |
473 fcb F$ResTsk+SysState | |
474 fdb FResTsk-*-2 | |
475 fcb F$RelTsk+SysState | |
476 fdb FRelTsk-*-2 | |
477 fcb F$DATLog+SysState | |
478 fdb FDATLog-*-2 | |
479 fcb F$LDAXY+SysState | |
480 fdb FLDAXY-*-2 | |
481 fcb F$LDDDXY+SysState | |
482 fdb FLDDDXY-*-2 | |
483 fcb F$LDABX+SysState | |
484 fdb FLDABX-*-2 | |
485 fcb F$STABX+SysState | |
486 fdb FSTABX-*-2 | |
487 fcb F$ELink+SysState | |
488 fdb FELink-*-2 | |
489 fcb F$FModul+SysState | |
490 fdb FFModul-*-2 | |
1387 | 491 fcb F$AlHRAM+SysState |
492 fdb FAlHRAM-*-2 | |
1145 | 493 fcb F$VBlock+SysState |
494 fdb FVBlock-*-2 | |
1146 | 495 IFNE H6309 |
1145 | 496 fcb F$DelRAM |
497 fdb FDelRAM-*-2 | |
1146 | 498 ENDC |
1145 | 499 fcb $80 |
500 | |
501 * SWI3 vector entry | |
502 XSWI3 lda #P$SWI3 point to SWI3 vector | |
503 fcb $8C skip 2 bytes | |
504 | |
505 * SWI vector entry | |
506 XSWI lda #P$SWI point to SWI vector | |
507 ldx <D.Proc get process pointer | |
508 ldu a,x user defined SWI[x]? | |
509 beq L028E no, go get option byte | |
510 GoUser lbra L0E5E Yes, go call users's routine | |
511 | |
512 * SWI2 vector entry | |
513 XSWI2 ldx <D.Proc get current process descriptor | |
514 ldu P$SWI2,x any SWI vector? | |
515 bne GoUser yes, go execute it | |
516 | |
517 * Process software interupts from a user state | |
518 * Entry: X=Process descriptor pointer of process that made system call | |
519 * U=Register stack pointer | |
520 L028E ldu <D.SysSvc set system call processor to system side | |
521 stu <D.XSWI2 | |
522 ldu <D.SysIRQ do the same thing for IRQ's | |
523 stu <D.XIRQ | |
524 IFNE H6309 | |
525 oim #SysState,P$State,x mark process as in system state | |
526 ELSE | |
527 lda P$State,x | |
528 ora #SysState | |
529 sta P$State,x | |
530 ENDC | |
531 * copy register stack to process descriptor | |
532 sts P$SP,x save stack pointer | |
533 leas (P$Stack-R$Size),x point S to register stack destination | |
534 | |
1243
0819245a7e87
Fixed terrible bug in user state system call dispatch routine thanks to
boisy
parents:
1241
diff
changeset
|
535 IFNE H6309 |
1145 | 536 leau R$Size-1,s point to last byte of destination register stack |
537 leay -1,y point to caller's register stack in $FEE1 | |
538 ldw #R$Size size of the register stack | |
539 tfm y-,u- | |
1243
0819245a7e87
Fixed terrible bug in user state system call dispatch routine thanks to
boisy
parents:
1241
diff
changeset
|
540 leau ,s needed because the TFM is u-, not -u (post, not pre) |
1145 | 541 ELSE |
1251
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
542 * Note! R$Size MUST BE an EVEN number of bytes for this to work! |
1243
0819245a7e87
Fixed terrible bug in user state system call dispatch routine thanks to
boisy
parents:
1241
diff
changeset
|
543 leau R$Size,s point to last byte of destination register stack |
1251
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
544 lda #R$Size/2 |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
545 Loop3 ldx ,--y |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
546 stx ,--u |
411c88ed62f6
Fixed bug in os9p1, now boots in Level Two! Also inc'ed rev (and in os9p2)
boisy
parents:
1250
diff
changeset
|
547 deca |
1145 | 548 bne Loop3 |
549 ENDC | |
550 andcc #^IntMasks | |
551 * B=function code already from calling process: DON'T USE IT! | |
552 ldx R$PC,u get where PC was from process | |
553 leax 1,x move PC past option | |
554 stx R$PC,u save updated PC to process | |
555 * execute function call | |
556 ldy <D.UsrDis get user dispatch table pointer | |
557 lbsr L033B go execute option | |
558 IFNE H6309 | |
559 aim #^IntMasks,R$CC,u Clear interrupt flags in caller's CC | |
560 ELSE | |
1243
0819245a7e87
Fixed terrible bug in user state system call dispatch routine thanks to
boisy
parents:
1241
diff
changeset
|
561 lda R$CC,u |
0819245a7e87
Fixed terrible bug in user state system call dispatch routine thanks to
boisy
parents:
1241
diff
changeset
|
562 anda #^IntMasks |
0819245a7e87
Fixed terrible bug in user state system call dispatch routine thanks to
boisy
parents:
1241
diff
changeset
|
563 sta R$CC,u |
1145 | 564 ENDC |
565 ldx <D.Proc get current process ptr | |
566 IFNE H6309 | |
567 aim #^(SysState+TimOut),P$State,x Clear system & timeout flags | |
568 ELSE | |
569 lda P$State,x | |
570 anda #^(SysState+TimOut) | |
571 sta P$State,x | |
572 ENDC | |
573 | |
574 * Check for image change now, which lets stuff like F$MapBlk and F$ClrBlk | |
575 * do the short-circuit thing, too. Adds about 20 cycles to each system call. | |
576 lbsr TstImg it doesn't hurt to call this twice | |
577 lda P$State,x get current state of the process | |
578 ora <P$Signal,x is there a pending signal? | |
579 sta <D.Quick save quick return flag | |
580 beq AllClr if nothing's have changed, do full checks | |
581 | |
582 DoFull bsr L02DA move the stack frame back to user state | |
583 lbra L0D80 go back to the process | |
584 | |
585 * add ldu P$SP,x, etc... | |
1240 | 586 AllClr equ * |
1145 | 587 IFNE H6309 |
1240 | 588 inc <D.QCnt |
1145 | 589 aim #$1F,<D.QCnt |
1239 | 590 beq DoFull every 32 system calls, do the full check |
1145 | 591 ldw #R$Size --- size of the register stack |
592 ldy #Where+SWIStack --- to stack at top of memory | |
593 orcc #IntMasks | |
594 tfm u+,y+ --- move the stack to the top of memory | |
595 ELSE | |
596 lda <D.QCnt | |
1240 | 597 inca |
1145 | 598 anda #$1F |
599 sta <D.QCnt | |
600 beq DoFull | |
601 ldb #R$Size | |
602 ldy #Where+SWIStack | |
603 orcc #IntMasks | |
604 Loop4 lda ,u+ | |
605 sta ,y+ | |
606 decb | |
607 bne Loop4 | |
608 ENDC | |
609 lbra BackTo1 otherwise simply return to the user | |
610 | |
611 * Copy register stack from user to system | |
612 * Entry: U=Ptr to Register stack in process dsc | |
613 L02CB pshs cc,x,y,u preserve registers | |
614 ldb P$Task,x get task # | |
615 ldx P$SP,x get stack pointer | |
616 lbsr L0BF3 calculate block offset (only affects A&X) | |
617 leax -$6000,x adjust pointer to where memory map will be | |
618 bra L02E9 go copy it | |
619 | |
620 * Copy register stack from system to user | |
621 * Entry: U=Ptr to Register stack in process dsc | |
622 L02DA pshs cc,x,y,u preserve registers | |
623 ldb P$Task,x get task # of destination | |
624 ldx P$SP,x get stack pointer | |
625 lbsr L0BF3 calculate block offset (only affects A&X) | |
626 leax -$6000,x adjust pointer to where memory map will be | |
627 exg x,y swap pointers & copy | |
628 * Copy a register stack | |
629 * Entry: X=Source | |
630 * Y=Destination | |
631 * A=Offset into DAT image of stack | |
632 * B=Task # | |
633 L02E9 leau a,u point to block # of where stack is | |
634 lda 1,u get first block | |
635 ldb 3,u get a second just in case of overlap | |
636 orcc #IntMasks shutdown interupts while we do this | |
637 std >$FFA5 map blocks in | |
638 IFNE H6309 | |
639 ldw #R$Size get size of register stack | |
640 tfm x+,y+ copy it | |
641 ELSE | |
642 ldb #R$Size | |
643 Loop5 lda ,x+ | |
644 sta ,y+ | |
645 decb | |
646 bne Loop5 | |
647 ENDC | |
648 ldx <D.SysDAT remap the blocks we took out | |
649 lda $0B,x | |
650 ldb $0D,x | |
651 std >$FFA5 | |
652 puls cc,x,y,u,pc restore & return | |
653 | |
654 * Process software interupts from system state | |
655 * Entry: U=Register stack pointer | |
1239 | 656 SysCall leau ,s get pointer to register stack |
1145 | 657 lda <D.SSTskN Get system task # (0=SYSTEM, 1=GRFDRV) |
658 clr <D.SSTskN Force to System Process | |
659 pshs a Save the system task number | |
660 lda ,u Restore callers CC register (R$CC=$00) | |
661 tfr a,cc make it current | |
662 ldx R$PC,u Get my caller's PC register | |
663 leax 1,x move PC to next position | |
664 stx R$PC,u Save my caller's updated PC register | |
665 ldy <D.SysDis get system dispatch table pointer | |
666 bsr L033B execute system call | |
667 puls a restore system state task number | |
668 lbra L0E2B return to process | |
669 | |
670 * Entry: X = system call vector to jump to | |
671 Sys.Vec jmp ,x execute service call | |
672 | |
673 * Execute system call | |
674 * Entry: B=Function call # | |
675 * Y=Function dispatch table pointer (D.SysDis or D.UsrDis) | |
1247 | 676 L033B |
677 lslb is it a I/O call? (Also multiplys by 2 for offset) | |
1145 | 678 bcc L0345 no, go get normal vector |
679 * Execute I/O system calls | |
680 ldx IOEntry,y get IOMan vector | |
681 * Execute the system call | |
682 L034F pshs u preserve register stack pointer | |
683 jsr [D.SysVec] perform a vectored system call | |
684 puls u restore pointer | |
685 L0355 tfr cc,a move CC to A for stack update | |
686 bcc L035B go update it if no error from call | |
687 stb R$B,u save error code to caller's B | |
1247 | 688 L035B ldb R$CC,u get callers CC, R$CC=$00 |
1145 | 689 IFNE H6309 |
690 andd #$2FD0 [A]=H,N,Z,V,C [B]=E,F,I | |
691 orr b,a merge them together | |
692 ELSE | |
693 anda #$2F [A]=H,N,Z,V,C | |
694 andb #$D0 [B]=E,F,I | |
695 pshs b | |
696 ora ,s+ | |
697 ENDC | |
1247 | 698 sta R$CC,u return it to caller, R$CC=$00 |
1145 | 699 rts |
700 | |
701 * Execute regular system calls | |
1247 | 702 L0345 |
703 clra clear MSB of offset | |
1145 | 704 ldx d,y get vector to call |
705 bne L034F it's initialized, go execute it | |
706 comb set carry for error | |
707 ldb #E$UnkSvc get error code | |
708 bra L0355 return with it | |
709 | |
710 use freboot.asm | |
711 | |
712 use fssvc.asm | |
713 | |
714 use flink.asm | |
715 | |
716 use fvmodul.asm | |
717 | |
718 use ffmodul.asm | |
719 | |
720 use fprsnam.asm | |
721 | |
722 use fcmpnam.asm | |
723 | |
724 use fsrqmem.asm | |
725 | |
726 use fallram.asm | |
727 | |
1146 | 728 |
729 IFNE H6309 | |
1145 | 730 use fdelram.asm |
1146 | 731 ENDC |
1145 | 732 |
733 use fallimg.asm | |
734 | |
735 use ffreehb.asm | |
736 | |
737 use fdatlog.asm | |
738 | |
739 use fld.asm | |
740 | |
1146 | 741 IFNE H6309 |
1145 | 742 use fcpymem.asm |
1146 | 743 ENDC |
1145 | 744 |
745 use fmove.asm | |
746 | |
747 use fldabx.asm | |
748 | |
749 use falltsk.asm | |
750 | |
751 use faproc.asm | |
752 | |
753 * System IRQ service routine | |
754 XIRQ ldx <D.Proc get current process pointer | |
755 sts P$SP,x save the stack pointer | |
756 lds <D.SysStk get system stack pointer | |
757 ldd <D.SysSvc set system service routine to current | |
758 std <D.XSWI2 | |
759 ldd <D.SysIRQ set system IRQ routine to current | |
760 std <D.XIRQ | |
761 jsr [>D.SvcIRQ] execute irq service | |
762 bcc L0D5B | |
763 | |
764 ldx <D.Proc get current process pointer | |
765 ldb P$Task,x | |
766 ldx P$SP,x get it's stack pointer | |
767 | |
768 pshs u,d,cc save some registers | |
769 leau ,s point to a 'caller register stack' | |
770 lbsr L0C40 do a LDB 0,X in task B | |
771 puls u,d,cc and now A ( R$A,U ) = the CC we want | |
772 | |
773 ora #IntMasks disable it's IRQ's | |
774 lbsr L0C28 save it back | |
775 L0D5B orcc #IntMasks shut down IRQ's | |
776 ldx <D.Proc get current process pointer | |
777 tst <D.QIRQ was it a clock IRQ? | |
778 lbne L0DF7 if not, do a quick return | |
779 | |
780 lda P$State,x Get it's state | |
781 bita #TimOut Is it timed out? | |
782 bne L0D7C yes, wake it up | |
783 * Update active process queue | |
784 ldu #(D.AProcQ-P$Queue) point to active process queue | |
785 ldb #Suspend get suspend flag | |
786 L0D6A ldu P$Queue,u get a active process pointer | |
787 beq L0D78 | |
788 bitb P$State,u is it suspended? | |
789 bne L0D6A yes, go to next one in chain | |
790 ldb P$Prior,x get current process priority | |
791 cmpb P$Prior,u do we bump this one? | |
792 blo L0D7C | |
793 | |
794 L0D78 ldu P$SP,x | |
795 bra L0DB9 | |
796 | |
797 L0D7C anda #^TimOut | |
798 sta P$State,x | |
799 | |
800 L0D80 equ * | |
801 L0D83 bsr L0D11 activate next process | |
802 | |
803 use fnproc.asm | |
804 | |
805 * The following routines must appear no earlier than $E00 when assembled, as | |
806 * they have to always be in the vector RAM page ($FE00-$FEFF) | |
807 | |
808 * Default routine for D.SysIRQ | |
1239 | 809 S.SysIRQ lda <D.SSTskN Get current task's GIME task # (0 or 1) |
1145 | 810 beq FastIRQ Use super-fast version for system state |
811 clr <D.SSTskN Clear out memory copy (task 0) | |
812 jsr [>D.SvcIRQ] (Normally routine in Clock calling D.Poll) | |
813 inc <D.SSTskN Save task # for system state | |
814 lda #1 Task 1 | |
815 ora <D.TINIT Merge task bit's into Shadow version | |
816 sta <D.TINIT Update shadow | |
817 sta >DAT.Task Save to GIME as well & return | |
818 bra DoneIRQ Check for error and exit | |
819 | |
820 FastIRQ jsr [>D.SvcIRQ] (Normally routine in Clock calling D.Poll) | |
821 DoneIRQ bcc L0E28 No error on IRQ, exit | |
822 IFNE H6309 | |
823 oim #IntMasks,0,s Setup RTI to shut interrupts off again | |
824 ELSE | |
825 lda ,s | |
826 ora #IntMasks | |
827 sta ,s | |
828 ENDC | |
829 L0E28 rti | |
830 | |
831 * return from a system call | |
832 L0E29 clra Force System task # to 0 (non-GRDRV) | |
833 L0E2B ldx <D.SysPrc Get system process dsc. ptr | |
834 lbsr TstImg check image, and F$SetTsk (PRESERVES A) | |
835 orcc #IntMasks Shut interrupts off | |
836 sta <D.SSTskN Save task # for system state | |
837 beq Fst2 If task 0, skip subroutine | |
838 ora <D.TINIT Merge task bit's into Shadow version | |
839 sta <D.TINIT Update shadow | |
840 sta >DAT.Task Save to GIME as well & return | |
841 Fst2 leas ,u Stack ptr=U & return | |
842 rti | |
843 | |
844 * Switch to new process, X=Process descriptor pointer, U=Stack pointer | |
845 L0E4C equ * | |
846 IFNE H6309 | |
847 oim #$01,<D.TINIT switch GIME shadow to user state | |
848 lda <D.TINIT | |
849 ELSE | |
850 lda <D.TINIT | |
851 ora #$01 | |
852 sta <D.TINIT | |
853 ENDC | |
854 sta >DAT.Task save it to GIME | |
855 leas ,y point to new stack | |
856 tstb is the stack at SWISTACK? | |
857 bne MyRTI no, we're doing a system-state rti | |
858 | |
859 IFNE H6309 | |
860 ldf #R$Size E=0 from call to L0E8D before | |
861 ldu #Where+SWIStack point to the stack | |
862 tfm u+,y+ move the stack from top of memory to user memory | |
863 ELSE | |
864 ldb #R$Size | |
1239 | 865 ldu #Where+SWIStack point to the stack |
1145 | 866 RtiLoop lda ,u+ |
867 sta ,y+ | |
868 decb | |
869 bne RtiLoop | |
870 ENDC | |
871 MyRTI rti return from IRQ | |
872 | |
1249 | 873 |
1145 | 874 * Execute routine in task 1 pointed to by U |
875 * comes from user requested SWI vectors | |
876 L0E5E equ * | |
877 IFNE H6309 | |
878 oim #$01,<D.TINIT switch GIME shadow to user state | |
879 ldb <D.TINIT | |
880 ELSE | |
881 ldb <D.TINIT | |
882 orb #$01 | |
883 stb <D.TINIT | |
884 ENDC | |
885 stb >DAT.Task | |
886 jmp ,u | |
887 | |
888 * Flip to task 1 (used by GRF/WINDInt to switch to GRFDRV) (pointed to | |
889 * by <D.Flip1). All regs are already preserved on stack for the RTI | |
1239 | 890 S.Flip1 ldb #2 get Task image entry numberx2 for Grfdrv (task 1) |
1145 | 891 bsr L0E8D copy over the DAT image |
892 IFNE H6309 | |
893 oim #$01,<D.TINIT | |
894 lda <D.TINIT get copy of GIME Task side | |
895 ELSE | |
896 lda <D.TINIT | |
897 ora #$01 | |
898 sta <D.TINIT | |
899 ENDC | |
900 sta >DAT.Task save it to GIME register | |
901 inc <D.SSTskN increment system state task number | |
902 rti return | |
903 | |
904 * Setup MMU in task 1, B=Task # to swap to, shifted left 1 bit | |
905 L0E8D cmpb <D.Task1N are we going back to the same task | |
906 beq L0EA3 without the DAT image changing? | |
907 stb <D.Task1N nope, save current task in map type 1 | |
908 ldx #$FFA8 get MMU start register for process's | |
909 ldu <D.TskIPt get task image pointer table | |
910 ldu b,u get address of DAT image | |
911 L0E93 leau 1,u point to actual MMU block | |
912 IFNE H6309 | |
913 lde #4 get # banks/2 for task | |
914 ELSE | |
915 lda #4 | |
916 pshs a | |
917 ENDC | |
918 L0E9B lda ,u++ get a bank | |
919 ldb ,u++ and next one | |
920 std ,x++ Save it to MMU | |
921 IFNE H6309 | |
922 dece done? | |
923 ELSE | |
924 dec ,s | |
925 ENDC | |
926 bne L0E9B no, keep going | |
927 IFEQ H6309 | |
928 leas 1,s | |
929 ENDC | |
930 L0EA3 rts return | |
931 | |
932 * Execute SWI3 vector | |
933 * Execute FIRQ vector | |
934 FIRQVCT ldx #D.FIRQ get DP offset of vector | |
935 bra L0EB8 go execute it | |
936 | |
937 * Execute IRQ vector | |
938 IRQVCT orcc #IntMasks disasble IRQ's | |
939 ldx #D.IRQ get DP offset of vector | |
940 * Execute interrupt vector, B=DP Vector offset | |
941 L0EB8 clra (faster than CLR >$xxxx) | |
942 sta >DAT.Task Force to Task 0 (system state) | |
943 IFNE H6309 | |
944 tfr 0,dp setup DP | |
945 ELSE | |
946 tfr a,dp | |
947 ENDC | |
948 MapGrf equ * | |
949 IFNE H6309 | |
950 aim #$fe,<D.TINIT switch GIME shadow to system state | |
951 lda <D.TINIT set GIME again just in case timer is used | |
952 ELSE | |
953 lda <D.TINIT | |
954 anda #$FE | |
955 sta <D.TINIT | |
956 ENDC | |
957 MapT0 sta >DAT.Task | |
958 jmp [,x] execute it | |
959 | |
960 SWI3VCT orcc #IntMasks disable IRQ's | |
961 ldx #D.SWI3 get DP offset of vector | |
962 bra SWICall go execute it | |
963 | |
964 * Execute SWI2 vector | |
965 SWI2VCT orcc #IntMasks disasble IRQ's | |
966 ldx #D.SWI2 get DP offset of vector | |
967 | |
968 * saves 1 cycle on system-system calls | |
969 * saves about 200 cycles (calls to I.LDABX and L029E) on grfdrv-system, | |
970 * or user-system calls. | |
971 SWICall ldb [R$PC,s] --- get callcode of the system call | |
972 clr >DAT.Task go to map type 1 | |
973 IFNE H6309 | |
974 tfr 0,dp set DP to zero | |
975 ELSE | |
976 clra | |
977 tfr a,dp | |
978 ENDC | |
979 | |
980 * These lines add a total of 81 addition cycles to each SWI(2,3) call, | |
981 * and 36 bytes+12 for R$Size in the constant page at $FExx | |
982 * It takes no more time for a SWI(2,3) from system state than previously, | |
983 * ... and adds 14 cycles to each SWI(2,3) call from grfdrv... not a problem. | |
984 * For processes that re-vector SWI, SWI3, it adds 81 cycles. BUT SWI(3) | |
985 * CANNOT be vectored to L0EBF cause the user SWI service routine has been | |
986 * changed | |
987 lda <D.TINIT get map type flag | |
988 bita #$01 check it without changing it | |
989 | |
990 * Change to LBEQ R.SysSvc to avoid JMP [,X] | |
991 * and add R.SysSvc STA >DAT.Task ??? | |
992 beq MapT0 in map 0: restore hardware and do system service | |
993 tst <D.SSTskN get system state 0,1 | |
994 bne MapGrf if in grfdrv, go to map 0 and do system service | |
995 | |
996 * the preceding few lines are necessary, as all SWI's still pass thru | |
997 * here before being vectored to the system service routine... which | |
998 * doesn't copy the stack from user state. | |
999 sta >DAT.Task go to map type X again to get user's stack | |
1000 * a byte less, a cycle more than ldy #$FEED-R$Size, or ldy #$F000+SWIStack | |
1001 leay <SWIStack,pc where to put the register stack: to $FEDF | |
1002 tfr s,u get a copy of where the stack is | |
1003 IFNE H6309 | |
1004 ldw #R$Size get the size of the stack | |
1005 tfm u+,y+ move the stack to the top of memory | |
1006 ELSE | |
1007 pshs b | |
1008 ldb #R$Size | |
1009 Looper lda ,u+ | |
1010 sta ,y+ | |
1011 decb | |
1012 bne Looper | |
1013 puls b | |
1014 ENDC | |
1015 bra L0EB8 and go from map type 1 to map type 0 | |
1016 | |
1017 * Execute SWI vector | |
1018 SWIVCT ldx #D.SWI get DP offset of vector | |
1019 bra SWICall go execute it | |
1020 | |
1021 * Execute NMI vector | |
1022 NMIVCT ldx #D.NMI get DP offset of vector | |
1023 bra L0EB8 go execute it | |
1024 | |
1025 emod | |
1026 eom equ * | |
1027 | |
1028 *SWIStack fcc /REGISTER STACK/ R$Size data bytes | |
1239 | 1029 SWIStack fcb $88,$03,$00 |
1146 | 1030 IFNE H6309 |
1239 | 1031 fcb $45,$72 |
1146 | 1032 ENDC |
1239 | 1033 fcb $00,$cd,$00,$12,$00,$00,$00,$e5,$7f |
1145 | 1034 |
1035 fcb $55 D.ErrRst | |
1036 | |
1037 * Now bra instead of lbra since 2 cycles/interrupt faster | |
1038 bra SWI3VCT SWI3 vector | |
1039 nop | |
1040 bra SWI2VCT SWI2 vector | |
1041 nop | |
1042 bra FIRQVCT FIRQ vector | |
1043 nop | |
1044 bra IRQVCT IRQ vector | |
1045 nop | |
1046 bra SWIVCT SWI vector | |
1047 nop | |
1048 bra NMIVCT NMI vector | |
1049 nop | |
1050 | |
1051 end | |
1052 |