Mercurial > hg > Members > kono > nitros9-code
comparison level1/modules/kernel/krnp2.asm @ 1453:5dbf908c1483
Kernel and KernelP2 moved to krnl/
author | boisy |
---|---|
date | Thu, 11 Dec 2003 23:47:53 +0000 |
parents | |
children | 5f18094d961d |
comparison
equal
deleted
inserted
replaced
1452:32b27b6792b6 | 1453:5dbf908c1483 |
---|---|
1 ******************************************************************** | |
2 * KernelP2 - NitrOS-9 Level 1 Kernel Part 2 | |
3 * | |
4 * $Id$ | |
5 * | |
6 * Edt/Rev YYYY/MM/DD Modified by | |
7 * Comment | |
8 * ------------------------------------------------------------------ | |
9 | |
10 nam KernelP2 | |
11 ttl NitrOS-9 Level 1 Kernel Part 2 | |
12 | |
13 ifp1 | |
14 use defsfile | |
15 endc | |
16 | |
17 tylg set Systm+Objct | |
18 atrv set ReEnt+rev | |
19 rev set $00 | |
20 edition set 10 | |
21 | |
22 mod eom,name,tylg,atrv,start,size | |
23 | |
24 size equ . | |
25 | |
26 name fcs /KernelP2/ | |
27 fcb edition | |
28 | |
29 SvcTbl fcb $7F | |
30 fdb IOCall-*-2 | |
31 | |
32 fcb F$Unlink | |
33 fdb FUnlink-*-2 | |
34 | |
35 fcb F$Wait | |
36 fdb FWait-*-2 | |
37 | |
38 fcb F$Exit | |
39 fdb FExit-*-2 | |
40 | |
41 fcb F$Mem | |
42 fdb FMem-*-2 | |
43 | |
44 fcb F$Send | |
45 fdb FSend-*-2 | |
46 | |
47 fcb F$Sleep | |
48 fdb FSleep-*-2 | |
49 | |
50 fcb F$Icpt | |
51 fdb FIcpt-*-2 | |
52 | |
53 fcb F$ID | |
54 fdb FID-*-2 | |
55 | |
56 fcb F$SPrior | |
57 fdb FSPrior-*-2 | |
58 | |
59 fcb F$SSwi | |
60 fdb FSSwi-*-2 | |
61 | |
62 fcb F$STime | |
63 fdb FSTime-*-2 | |
64 | |
65 fcb F$Find64+$80 | |
66 fdb FFind64-*-2 | |
67 | |
68 fcb F$All64+$80 | |
69 fdb FAll64-*-2 | |
70 | |
71 fcb F$Ret64+$80 | |
72 fdb FRet64-*-2 | |
73 | |
74 fcb $80 | |
75 | |
76 start equ * | |
77 * install system calls | |
78 leay SvcTbl,pcr | |
79 os9 F$SSvc | |
80 ldx <D.PrcDBT | |
81 os9 F$All64 | |
82 bcs L0081 | |
83 stx <D.PrcDBT | |
84 sty <D.Proc | |
85 tfr s,d | |
86 deca | |
87 ldb #$01 | |
88 std P$ADDR,y | |
89 lda #SysState | |
90 sta P$State,y | |
91 ldu <D.Init | |
92 bsr ChdDir | |
93 bcc L006A | |
94 lbsr JmpBoot | |
95 bsr ChdDir | |
96 L006A bsr OpenCons | |
97 bcc L0073 | |
98 lbsr JmpBoot | |
99 bsr OpenCons | |
100 L0073 ldd InitStr,u | |
101 leax d,u | |
102 lda #$01 | |
103 clrb | |
104 ldy #$0000 | |
105 os9 F$Chain | |
106 L0081 jmp [<$FFFE] | |
107 | |
108 * | |
109 * U = address of init module | |
110 ChdDir clrb | |
111 ldd <SysStr,u get system device | |
112 beq ChdDir10 branch if none | |
113 leax d,u | |
114 lda #READ.+EXEC. | |
115 os9 I$ChgDir else change directory to it | |
116 ChdDir10 rts | |
117 | |
118 * open console device | |
119 * U = address of init module | |
120 OpenCons clrb | |
121 ldd <StdStr,u | |
122 leax d,u | |
123 lda #UPDAT. | |
124 os9 I$Open | |
125 bcs OpenCn10 | |
126 ldx <D.Proc get process descriptor | |
127 sta P$Path+0,x save path to console to stdin... | |
128 os9 I$Dup | |
129 sta P$Path+1,x ...stdout | |
130 os9 I$Dup | |
131 sta P$Path+2,x ...and stderr | |
132 OpenCn10 rts | |
133 | |
134 FUnlink ldd R$U,u D = ptr to module to unlink | |
135 beq L00F9 | |
136 ldx <D.ModDir X = ptr to 1st module dir entry | |
137 L00B8 cmpd MD$MPtr,x module match? | |
138 beq L00C5 branch if so | |
139 leax MD$ESize,x go to next entry | |
140 cmpx <D.ModDir+2 is this end? | |
141 bcs L00B8 if not, go check next entry for match | |
142 bra L00F9 else exit | |
143 L00C5 lda MD$Link,x get link count | |
144 beq L00CE branch if zero | |
145 deca else decrement by one | |
146 sta MD$Link,x and save count | |
147 bne L00F9 branch if post-dec wasn't zero | |
148 * If here, deallocate module | |
149 L00CE ldy MD$MPtr,x get module pointer | |
150 cmpy <D.BTLO compare against boot lo mem | |
151 bcc L00F9 | |
152 ldb M$Type,y get type of module | |
153 cmpb #FlMgr is it a file manager? | |
154 bcs L00E5 branch if not | |
155 os9 F$IODel determine if I/O module is in use | |
156 bcc L00E5 branch if not | |
157 inc MD$Link,x else cancel out prior dec | |
158 bra L00FA and exit call | |
159 L00E5 clra | |
160 clrb | |
161 std MD$MPtr,x clear out moddir entry's module address | |
162 std M$ID,y and destroy module's first 2 bytes | |
163 ldd M$Size,y get size of module in D | |
164 lbsr L0236 | |
165 exg d,y | |
166 exg a,b | |
167 ldx <D.FMBM get free mem bitmap ptr | |
168 os9 F$DelBit delete the corresponding bits | |
169 L00F9 clra | |
170 L00FA rts | |
171 | |
172 FWait ldy <D.Proc | |
173 ldx <D.PrcDBT | |
174 lda P$CID,y | |
175 bne L0108 | |
176 comb | |
177 ldb #E$NoChld | |
178 rts | |
179 L0108 os9 F$Find64 | |
180 lda P$State,y | |
181 bita #Dead dead? | |
182 bne L0124 branch if so | |
183 lda P$SID,y siblings? | |
184 bne L0108 branch if so | |
185 clr R$A,u | |
186 ldx <D.Proc | |
187 orcc #FIRQMask+IRQMask | |
188 ldd <D.WProcQ | |
189 std P$Queue,x | |
190 stx <D.WProcQ | |
191 lbra L034D | |
192 L0124 ldx <D.Proc | |
193 L0126 lda P$ID,y | |
194 ldb <P$Signal,y | |
195 std R$A,u | |
196 pshs u,y,x,a | |
197 leay P$PID,x | |
198 ldx <D.PrcDBT | |
199 bra L0138 | |
200 L0135 os9 F$Find64 | |
201 L0138 lda P$SID,y | |
202 cmpa ,s | |
203 bne L0135 | |
204 ldu $03,s | |
205 ldb $02,u | |
206 stb $02,y | |
207 os9 F$Ret64 | |
208 puls pc,u,y,x,a | |
209 | |
210 FExit ldx <D.Proc | |
211 ldb R$B,u | |
212 stb P$Signal,x | |
213 ldb #NumPaths | |
214 leay P$PATH,x | |
215 L0155 lda ,y+ | |
216 beq L0160 | |
217 pshs b | |
218 os9 I$Close | |
219 puls b | |
220 L0160 decb | |
221 bne L0155 | |
222 lda P$ADDR,x | |
223 tfr d,u | |
224 lda P$PagCnt,x | |
225 os9 F$SRtMem | |
226 ldu P$PModul,x | |
227 os9 F$UnLink | |
228 ldu <D.Proc | |
229 leay P$PID,u | |
230 ldx <D.PrcDBT | |
231 bra L018C | |
232 L017A clr $02,y | |
233 os9 F$Find64 | |
234 lda P$State,y | |
235 bita #Dead dead? | |
236 beq L018A branch if not | |
237 lda ,y | |
238 os9 F$Ret64 | |
239 L018A clr P$PID,y | |
240 L018C lda P$SID,y | |
241 bne L017A | |
242 ldx #$0041 | |
243 lda P$PID,u | |
244 bne L01A4 | |
245 ldx <D.PrcDBT | |
246 lda P$ID,u | |
247 os9 F$Ret64 | |
248 bra L01C2 | |
249 L01A0 cmpa ,x | |
250 beq L01B2 | |
251 L01A4 leay ,x Y = proc desc ptr | |
252 ldx P$Queue,x | |
253 bne L01A0 | |
254 lda P$State,u | |
255 ora #Dead | |
256 sta P$State,u | |
257 bra L01C2 | |
258 L01B2 ldd P$Queue,x | |
259 std P$Queue,y | |
260 os9 F$AProc | |
261 leay ,u | |
262 ldu P$SP,x | |
263 ldu $01,u | |
264 lbsr L0126 | |
265 L01C2 clra | |
266 clrb | |
267 std <D.Proc | |
268 rts | |
269 | |
270 FMem ldx <D.Proc | |
271 ldd R$A,u | |
272 beq L0227 | |
273 bsr L0236 | |
274 subb P$PagCnt,x | |
275 beq L0227 | |
276 bcs L0207 | |
277 tfr d,y | |
278 ldx P$ADDR,x | |
279 pshs u,y,x | |
280 ldb ,s | |
281 beq L01E1 | |
282 addb $01,s | |
283 L01E1 ldx <D.FMBM | |
284 ldu <D.FMBM+2 | |
285 os9 F$SchBit | |
286 bcs L0231 | |
287 stb $02,s | |
288 ldb ,s | |
289 beq L01F6 | |
290 addb $01,s | |
291 cmpb $02,s | |
292 bne L0231 | |
293 L01F6 ldb $02,s | |
294 os9 F$AllBit | |
295 ldd $02,s | |
296 suba $01,s | |
297 addb $01,s | |
298 puls u,y,x | |
299 ldx <D.Proc | |
300 bra L0225 | |
301 | |
302 L0207 negb | |
303 tfr d,y | |
304 negb | |
305 addb $08,x | |
306 addb $07,x | |
307 cmpb $04,x | |
308 bhi L0217 | |
309 comb | |
310 ldb #E$DelSP | |
311 rts | |
312 | |
313 L0217 ldx <D.FMBM | |
314 os9 F$DelBit | |
315 tfr y,d | |
316 negb | |
317 ldx <D.Proc | |
318 addb P$PagCnt,x | |
319 lda P$ADDR,x | |
320 L0225 std P$ADDR,x | |
321 L0227 lda P$PagCnt,x | |
322 clrb | |
323 std $01,u | |
324 adda P$ADDR,x | |
325 std $06,u | |
326 rts | |
327 L0231 comb | |
328 ldb #E$MemFul | |
329 puls pc,u,y,x | |
330 | |
331 L0236 addd #$00FF | |
332 clrb | |
333 exg a,b | |
334 rts | |
335 | |
336 FSend lda R$A,u | |
337 bne L024F | |
338 inca | |
339 L0242 ldx <D.Proc | |
340 cmpa P$ID,x | |
341 beq L024A | |
342 bsr L024F | |
343 L024A inca | |
344 bne L0242 | |
345 clrb | |
346 rts | |
347 | |
348 L024F ldx <D.PrcDBT | |
349 os9 F$Find64 | |
350 bcc L025E | |
351 ldb #E$IPrcID | |
352 rts | |
353 | |
354 L0259 comb | |
355 ldb #E$IPrcID | |
356 puls pc,y,a | |
357 | |
358 L025E pshs y,a | |
359 ldb P$SID,u | |
360 bne L0275 | |
361 ldx <D.Proc | |
362 ldd P$User,x | |
363 beq L026F | |
364 cmpd P$User,y | |
365 bne L0259 | |
366 L026F lda P$State,y | |
367 ora #Condem | |
368 sta P$State,y | |
369 L0275 orcc #FIRQMask+IRQMask | |
370 lda <P$Signal,y | |
371 beq L0284 | |
372 deca | |
373 beq L0284 | |
374 comb | |
375 ldb #E$USigP | |
376 puls pc,y,a | |
377 | |
378 L0284 ldb P$SID,u | |
379 stb <P$Signal,y | |
380 ldx #$0043 | |
381 bra L02B4 | |
382 L028E cmpx $01,s | |
383 bne L02B4 | |
384 lda P$State,x | |
385 bita #$40 | |
386 beq L02C7 | |
387 ldu P$SP,x | |
388 ldd R$X,u | |
389 beq L02C7 | |
390 ldu P$Queue,x | |
391 beq L02C7 | |
392 pshs b,a | |
393 lda P$State,u | |
394 bita #$40 | |
395 puls b,a | |
396 beq L02C7 | |
397 ldu P$SP,u | |
398 addd P$SP,u | |
399 std P$SP,u | |
400 bra L02C7 | |
401 L02B4 leay ,x | |
402 ldx P$Queue,y | |
403 bne L028E | |
404 ldx #$0041 | |
405 L02BD leay ,x | |
406 ldx P$Queue,y | |
407 beq L02D7 | |
408 cmpx $01,s | |
409 bne L02BD | |
410 L02C7 ldd P$Queue,x | |
411 std P$Queue,y | |
412 lda <P$Signal,x | |
413 deca | |
414 bne L02D4 | |
415 sta <P$Signal,x | |
416 L02D4 os9 F$AProc | |
417 L02D7 clrb | |
418 puls pc,y,a | |
419 | |
420 * F$Sleep | |
421 FSleep ldx <D.Proc get pdesc | |
422 orcc #FIRQMask+IRQMask mask ints | |
423 lda P$Signal,x get proc signal | |
424 beq L02EE branch if none | |
425 deca dec signal | |
426 bne L02E9 branch if not S$Wake | |
427 sta P$Signal,x clear signal | |
428 L02E9 os9 F$AProc insert into activeq | |
429 bra L034D | |
430 L02EE ldd R$X,u get timeout | |
431 beq L033A branch if forever | |
432 subd #$0001 subtract 1 | |
433 std R$X,u save back to caller | |
434 beq L02E9 branch if give up tslice | |
435 pshs u,x | |
436 ldx #$0043 | |
437 L02FE leay ,x | |
438 ldx P$Queue,x | |
439 beq L0316 | |
440 pshs b,a | |
441 lda P$State,x | |
442 bita #TimSleep | |
443 puls b,a | |
444 beq L0316 | |
445 ldu P$SP,x | |
446 subd $04,u | |
447 bcc L02FE | |
448 addd $04,u | |
449 L0316 puls u,x | |
450 std R$X,u | |
451 ldd P$Queue,y | |
452 stx P$Queue,y | |
453 std P$Queue,x | |
454 lda P$State,x | |
455 ora #TimSleep | |
456 sta P$State,x | |
457 ldx P$Queue,x | |
458 beq L034D | |
459 lda P$State,x | |
460 bita #TimSleep | |
461 beq L034D | |
462 ldx P$SP,x | |
463 ldd P$SP,x | |
464 subd R$X,u | |
465 std P$SP,x | |
466 bra L034D | |
467 L033A lda P$State,x | |
468 anda #^TimSleep | |
469 sta P$State,x | |
470 ldd #$0043 | |
471 L0343 tfr d,y | |
472 ldd P$Queue,y | |
473 bne L0343 | |
474 stx P$Queue,y | |
475 std P$Queue,x | |
476 L034D leay <L0361,pcr | |
477 pshs y | |
478 ldy <D.Proc | |
479 ldd P$SP,y | |
480 ldx R$X,u | |
481 pshs u,y,x,dp,b,a,cc | |
482 sts P$SP,y | |
483 os9 F$NProc | |
484 L0361 std P$SP,y | |
485 stx R$X,u | |
486 clrb | |
487 rts | |
488 | |
489 * F$Icpt | |
490 FIcpt ldx <D.Proc get pdesc | |
491 ldd R$X,u get addr of icpt rtn | |
492 std <P$SigVec,x store in pdesc | |
493 ldd R$U,u get data ptr | |
494 std <P$SigDat,x store in pdesc | |
495 clrb | |
496 rts | |
497 | |
498 * F$SPrior | |
499 FSPrior lda R$A,u get ID | |
500 ldx <D.PrcDBT find pdesc | |
501 os9 F$Find64 | |
502 bcs FSPrEx branch if can't find | |
503 ldx <D.Proc get pdesc | |
504 ldd P$User,x get user ID | |
505 cmpd P$User,y same as dest pdesc | |
506 bne FSPrEx branch if not, must be owner | |
507 lda R$B,u else get prior | |
508 sta P$Prior,y and store it in dest pdesc | |
509 rts | |
510 FSPrEx comb | |
511 ldb #E$IPrcID | |
512 rts | |
513 | |
514 * F$ID | |
515 FID ldx <D.Proc get proc desc | |
516 lda P$ID,x get id | |
517 sta R$A,u put in A | |
518 ldd P$User,x get user ID | |
519 std R$Y,u store in Y | |
520 clrb | |
521 rts | |
522 | |
523 * F$SSwi | |
524 FSSwi ldx <D.Proc | |
525 leay P$SWI,x | |
526 ldb R$A,u | |
527 decb | |
528 cmpb #$03 | |
529 bcc FSSwiEx | |
530 lslb | |
531 ldx R$X,u | |
532 stx b,y | |
533 rts | |
534 FSSwiEx comb | |
535 ldb #E$ISWI | |
536 rts | |
537 | |
538 ClkName fcs /Clock/ | |
539 | |
540 * F$STime | |
541 FSTime ldx R$X,u | |
542 ldd ,x | |
543 std <D.Year | |
544 ldd 2,x | |
545 std <D.Day | |
546 ldd 4,x | |
547 std <D.Min | |
548 lda #Systm+Objct | |
549 leax <ClkName,pcr | |
550 os9 F$Link | |
551 bcs L03D2 | |
552 jmp ,y | |
553 clrb | |
554 L03D2 rts | |
555 | |
556 * F$Find64 | |
557 FFind64 lda R$A,u | |
558 ldx R$X,u | |
559 bsr L03DF | |
560 bcs L03DE | |
561 sty R$Y,u | |
562 L03DE rts | |
563 | |
564 L03DF pshs b,a | |
565 tsta | |
566 beq L03F3 | |
567 clrb | |
568 lsra | |
569 rorb | |
570 lsra | |
571 rorb | |
572 lda a,x | |
573 tfr d,y | |
574 beq L03F3 | |
575 tst ,y | |
576 bne L03F4 | |
577 L03F3 coma | |
578 L03F4 puls pc,b,a | |
579 | |
580 * F$All64 | |
581 FAll64 ldx R$X,u | |
582 bne L0402 | |
583 bsr L040C | |
584 bcs L040B | |
585 stx ,x | |
586 stx R$X,u | |
587 L0402 bsr L0422 | |
588 bcs L040B | |
589 sta R$A,u | |
590 sty R$Y,u | |
591 L040B rts | |
592 | |
593 L040C pshs u | |
594 ldd #$0100 | |
595 os9 F$SRqMem | |
596 leax ,u | |
597 puls u | |
598 bcs L0421 | |
599 clra | |
600 clrb | |
601 L041C sta d,x | |
602 incb | |
603 bne L041C | |
604 L0421 rts | |
605 | |
606 L0422 pshs u,x | |
607 clra | |
608 L0425 pshs a | |
609 clrb | |
610 lda a,x | |
611 beq L0437 | |
612 tfr d,y | |
613 clra | |
614 L042F tst d,y | |
615 beq L0439 | |
616 addb #$40 | |
617 bcc L042F | |
618 L0437 orcc #Carry | |
619 L0439 leay d,y | |
620 puls a | |
621 bcc L0464 | |
622 inca | |
623 cmpa #$40 | |
624 bcs L0425 | |
625 clra | |
626 L0445 tst a,x | |
627 beq L0453 | |
628 inca | |
629 cmpa #$40 | |
630 bcs L0445 | |
631 ldb #E$PthFul | |
632 coma | |
633 bra L0471 | |
634 L0453 pshs x,a | |
635 bsr L040C | |
636 bcs L0473 | |
637 leay ,x | |
638 tfr x,d | |
639 tfr a,b | |
640 puls x,a | |
641 stb a,x | |
642 clrb | |
643 L0464 lslb | |
644 rola | |
645 lslb | |
646 rola | |
647 ldb #$3F | |
648 L046A clr b,y | |
649 decb | |
650 bne L046A | |
651 sta ,y | |
652 L0471 puls pc,u,x | |
653 L0473 leas 3,s | |
654 puls pc,u,x | |
655 | |
656 * F$Ret64 | |
657 FRet64 lda R$A,u | |
658 ldx R$X,u | |
659 pshs u,y,x,b,a | |
660 clrb | |
661 lsra | |
662 rorb | |
663 lsra | |
664 rorb | |
665 pshs a | |
666 lda a,x | |
667 beq L04A0 | |
668 tfr d,y | |
669 clr ,y | |
670 clrb | |
671 tfr d,u | |
672 clra | |
673 Ret64Lp tst d,u | |
674 bne Ret64Ex | |
675 addb #64 | |
676 bne Ret64Lp | |
677 inca | |
678 os9 F$SRtMem | |
679 lda ,s | |
680 clr a,x | |
681 L04A0 | |
682 Ret64Ex clr ,s+ | |
683 puls pc,u,y,x,b,a | |
684 | |
685 IOMgr fcs /IOMAN/ | |
686 | |
687 IOCall pshs u,y,x,b,a | |
688 ldu <D.Init get ptr to init | |
689 bsr LinkIOM link to IOMan | |
690 bcc JmpIOM jump into him if ok | |
691 bsr JmpBoot try boot | |
692 bcs IOCallRt problem booting... return w/ error | |
693 bsr LinkIOM ok, NOW link to IOMan | |
694 bcs IOCallRt still a problem... | |
695 JmpIOM jsr ,y | |
696 puls u,y,x,b,a | |
697 ldx -2,y | |
698 jmp ,x | |
699 IOCAllRt puls pc,u,y,x,b,a | |
700 | |
701 LinkIOM leax IOMgr,pcr | |
702 lda #Systm+Objct | |
703 os9 F$Link | |
704 rts | |
705 | |
706 * | |
707 * U = address of init module | |
708 JmpBoot pshs u | |
709 comb | |
710 tst <D.Boot already booted? | |
711 bne JmpBtEr yep, return to caller... | |
712 inc <D.Boot else set boot flag | |
713 ldd <BootStr,u get pointer to boot str | |
714 beq JmpBtEr if none, return to caller | |
715 leax d,u X = ptr to boot mod name | |
716 lda #Systm+Objct | |
717 os9 F$Link link | |
718 bcs JmpBtEr return if error | |
719 jsr ,y ...else jsr into boot module | |
720 * D = size of bootfile | |
721 * X = address of bootfile | |
722 bcs JmpBtEr return if error | |
723 stx <D.MLIM | |
724 stx <D.BTLO | |
725 leau d,x | |
726 stu <D.BTHI | |
727 * search through bootfile and validate modules | |
728 ValBoot ldd ,x | |
729 cmpd #M$ID12 | |
730 bne ValBoot1 | |
731 os9 F$VModul | |
732 bcs ValBoot1 | |
733 ldd M$Size,x | |
734 leax d,x move X to next module | |
735 bra ValBoot2 | |
736 ValBoot1 leax 1,x advance one byte | |
737 ValBoot2 cmpx <D.BTHI | |
738 bcs ValBoot | |
739 JmpBtEr puls pc,u | |
740 | |
741 emod | |
742 eom equ * |