Mercurial > hg > Members > kono > nitros9-code
changeset 1339:bd102e2f30a4
Removed os9p1/os9p2 from here now that they are made from the KERNEL subdir
author | boisy |
---|---|
date | Sat, 13 Sep 2003 16:10:39 +0000 |
parents | b3caa1b456ed |
children | 63bfe1e5c5f4 |
files | level2/modules/os9p1.asm level2/modules/os9p2.asm |
diffstat | 2 files changed, 0 insertions(+), 4499 deletions(-) [+] |
line wrap: on
line diff
--- a/level2/modules/os9p1.asm Sat Sep 13 16:10:19 2003 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2375 +0,0 @@ -******************************************************************** -* OS9p1 - OS-9 Level Two V3 P1 module -* -* $Id$ -* -* Ed. Comments Who YY/MM/DD -* ------------------------------------------------------------------ -* ?? Cleaned up some formatting KDM 87/05/15 -* ?? Added comments and added new defines KDM 87/03/31 -* 18 Added time of creation to process descriptor BRI 88/11/18 -* 18r1 Added F$AllTsk call error exit to F$Chain BRI 88/12/05 -* 18r2 Changed time tag to use F$Time - No ticks BRI 88/12/08 -* 18r3 Removed bogus assumptions regarding init BGP 98/10/05 -* module in order to shrink code size, added -* check for CRC bit in compabibility byte of -* init module. -* 18r9 Made minor optimizations as per Curtis Boyle's BGP 98/10/10 -* optimization document -* 18r10 Removed FastBoot flag, CRC check is done via BGP 02/09/26 -* D.CRC now - - nam OS9p1 - ttl OS9 Level Two V3 P1 module - - ifp1 - use defsfile - endc - -rev set 10 -edition set 18 - - mod eom,name,Systm,ReEnt+rev,entry,msiz ++ - - org $0000 -msiz equ . - -name fcs "OS9p1" - fcb edition - -*------------------------------------------------* -* OS9p1 begins here: -*------------------------------------------------* -entry ldx #$100 clear rest of first 8k Block: ++ - ldy #8192-$100 ++ - clra - clrb -L001C std ,x++ - leay -2,y - bne L001C - - inca - std D.Tasks =$0100 task flags (32) - addb #$20 (DAT.TkCt) ++ - std D.TskIPt =$0120 temporary images ++ - - inca - aslb - std D.BlkMap+2 =$0240 end of block map - clrb - std D.BlkMap =$0200 mem block map (64) - - inca ++ - std D.SysDis =$0300 sys dispatch table - inca - std D.UsrDis =$0400 usr dispatch table - inca - std D.PrcDBT =$0500 proc desc pointers - inca - std D.SysPrc =$0600 original sys proc - std D.Proc =$0600 original proc - adda #P$Size/256 desc - tfr d,s SP=$0800 sys SP within sys desc - inca - std D.SysStk =$0900 main sys stack ptr - std D.SysMem =$0900 sys memmap - inca - std D.ModDir =$0A00 module dir - std D.ModEnd =$0A00 (grows upward) - adda #$06 - std D.ModDir+2 =$1000 module DAT images - std D.ModDAT =$1000 (grows downward) - std D.CCMem =$1000 CC3IO static memory ++ -* In following line, CRC=ON if it is STA <D.CRC, CRC=OFF if it is a STB <D.CRC - stb <D.CRC set CRC checking flag to off - - asla d=$2000 GrfDrv stack area ++ - - std D.CCStk ++ - -*------------------------------------------------* - leax Vectors,pcr put jmp[,x] vectors: - tfr x,d - ldx #D.SWI3 - -* used by top 256 to jmp to sys. - -L0065 std ,x++ - cmpx #D.NMI - bls L0065 - - leax >eo,pcr move secondary vectors - pshs x from end of rom: - leay >D.VECTRS,pcr - ldx #D.Clock (Tick-NMI) -L0079 ldd ,y++ get vector - addd ,s add offset - std ,x++ store - cmpx #D.XNMI done? - bls L0079 ..no - leas 2,s drop offset - - ldx D.XSWI2 set calls to sys - stx D.UsrSvc - ldx D.XIRQ set IRQ to sys - stx D.UsrIRQ - - leax SysCall,pcr set syscall handler - stx D.SysSvc - stx D.XSWI2 - - leax S.SysIRQ,pcr set sysirq handler - stx D.SysIRQ - stx D.XIRQ - - leax >S.SvcIRQ,pcr IRQ svc handler - stx D.SvcIRQ - leax >S.POLL,pcr default poll 'til IOMan - stx D.Poll - leax S.AltIRQ,pcr default keyboard till CC3io ++ - stx D.AltIRQ ++ - leax S.Flip0,pcr Grfdrv return vector ++ - stx D.Flip0 ++ - leax S.Flip1,pcr GrfDrv exec vector ++ - stx D.Flip1 ++ - - leay SysCalls,pcr enter os9p1 svc calls: - lbsr InstSSvc - -*------------------------------------------------* - ldu D.PrcDBT set up first proc desc: - ldx D.SysPrc - stx 0,u proc table entries - stx 1,u zero and one - - lda #1 sys proc id=01 - sta P$ID,x - lda #SysState set sys state - sta P$State,x - lda #SysTask sys task # ++ - sta D.SysTsk - sta P$Task,x -* optimization below saves one byte - ldd #$FFFF top priority/age - std P$Prior,x store it -* lda #$FF -* sta P$Prior,x -* sta P$Age,x - - leax P$DATImg,x point sysdat -> sys proc - stx D.SysDAT - clra - clrb - std ,x++ first block always sys - -* DAT.BlCt-ROMCount-RAMCount: - ldy #6 next 6 are unused ++ - ldd #DAT.Free -L00EF std ,x++ - leay -1,y - bne L00EF - - ldd #IOBlock last one is Kernel ++ - std ,x++ - - ldx D.Tasks first task# is sys's - inc 0,x - inc 1,x Task 1 is GrfDrv ++ - -*------------------------------------------------* -* set 1st 8K sys mem used - ldx D.SysMem - ldb D.CCStk (=$20) ++ -L0104 inc ,x+ - decb - bne L0104 - -*------------------------------------------------* -* determine size of CoCo's memory (128K/512K) - clr D.MemSz default is 128k ++ - ldd #$0313 blocks $03 and $13 ++ - std DAT.Regs+5 map at logical $A000 ++ - ldx #$A000 point to first block ++ - ldd #$DC78 get inverted sync bytes ++ - std ,x store at start of first block ++ - cmpd 8192,x in second block too? ++ - beq L0122 yes, just 128k ++ - inc D.MemSz else set 512k flag ++ - -L0122 ldy #$2000 point to second block in map ++ - ldx D.BlkMap X=$0200 - -* Check Memory Blocks Loop: - -L0128 pshs x save current map pointer - ldd ,s D=map ptr - subd D.BlkMap D=block number - cmpb #IOBlock is it sys? - bne L0136 ..no, test for 512k ++ - ldb #RAMinUse load marker ++ - bra L015B go set in map ++ - -L0136 lda D.MemSz 512k memory? ++ - bne L013E yes, continue ++ - cmpb #$0F end of 128k mem? ++ - bhs L0159 yes, set notram ++ - -L013E stb >DAT.Regs+1 set block at $2000 for test ++ - ldu ,y get two bytes - ldx #$00FF store test bytes - stx ,y - cmpx ,y same on read - bne L0159 ..end if no mem here - - ldx #$FF00 make sure again - stx ,y - cmpx ,y - bne L0159 ..bad mem - stu ,y restore original bytes - bra L015D do next - -* End of Memory: - -L0159 ldb #NotRAM set non-mem flag - -L015B stb [,s] store at ,X in table ++ - -L015D puls x get current map pointer - leax 1,x next block - cmpx D.BlkMap+2 end of map? - blo L0128 ..no, keep trying - -*------------------------------------------------* -* Search For ROM Modules: - - ldx D.BlkMap X=map strt (X=$0200) - inc ,x mark as RAMinUse - ldx D.BlkMap+2 start at end of map (X=$0240) - - leax -1,x back up 1 (X=$023F) - -*------------------------------------------------* - tfr x,d else D=block number (D=$023F) - subd D.BlkMap make into block number (D=$003F) - - pshs d save block number - leay ,s Y = var pointer for routine below - - ldx #$0D00 offset in block ++ - -*------------------------------------------------* -* Check Block for Modules Loop: - -L017F pshs x,y - lbsr L0AF0 set up Y for X offset - ldb 1,y B=block# from image - stb >DAT.Regs map into sys zero - lda ,x get byte from block - clr >DAT.Regs back to sys - puls x,y - cmpa #M$ID1 module? - bne L01A7 - - lbsr L0463 do verify - bcc L019D - cmpb #E$KwnMod 'Known Module'? - bne L01A7 ..no, continue -L019D ldd #M$Size else get mod size - lbsr lddxy - leax d,x skip over it - bra L01A9 - -* Not Known Module: - -L01A7 leax 1,x byte ptr+1 - -L01A9 cmpx #$1E00 don't overrun vector page! ++ - blo L017F ok to continue ++ - bsr L01D2 setup system mem map ++ - -*------------------------------------------------* -* OS9p1 init finished: - -L01B0 os9 F$Boot boot! - bcs Crash crash if problem - leax InitMod,pcr 'Init' - bsr LinkSys link to it - bcs Crash crash if error -L01BF stu D.Init save Init ptr - lda Feature1,u get feature byte #1 - bita #CRCOn CRC checking on? - beq L01C1 branch if not... - inc <D.CRC else inc. CRC flag -L01C1 leax OS9p2Nm,pcr 'OS9p2' - bsr LinkSys link to it - bcs Crash crash if not found... -L01D0 jmp ,y ...else do OS9p2... -Crash jmp D.Crash report boot failed - -* Setup system memory map. - -L01D2 ldx D.SysMem point to map ++ - leax $ED00/256,x kernel offset in map ++ - lda #NotRam mark IOPage ++ - sta 18,x as Not RAM ++ - ldb #$12 18 pages in kernel ++ - -L01DF lda #RAMinUse mark kernel ++ - -L01E1 sta ,x+ RAM as in use ++ - decb all done ++ - bne L01E1 no, continue - ldx D.BlkMap+2 end of map++ - sta -1,x mark block #3F ++ - rts exit ++ - -* Link to Module (X = ptr to mod name): -LinkSys lda #Systm system module - os9 F$Link try to find it - rts - -*------------------------------------------------* -* System Service Calls -*------------------------------------------------* -SysCalls fcb F$Link - fdb FLink-*-2 - fcb F$PrsNam - fdb FPrsNam-*-2 - fcb F$CmpNam - fdb FCmpNam-*-2 - fcb F$CmpNam+$80 (sys) - fdb SCmpNam-*-2 - fcb F$CRC - fdb FCRC-*-2 - fcb F$SRqMem+$80 - fdb FSRqMem-*-2 - fcb F$SRtMem+$80 - fdb FSRtMem-*-2 - fcb F$AProc+$80 - fdb FAProc-*-2 - fcb F$NProc+$80 - fdb FNProc-*-2 - fcb F$VModul+$80 - fdb FVModul-*-2 - fcb F$SSvc - fdb FSSvc-*-2 - fcb F$SLink+$80 - fdb FSLink-*-2 - fcb F$Boot+$80 - fdb FBoot-*-2 - fcb F$BtMem+$80 - fdb FBtMem-*-2 - fcb F$Move+$80 - fdb FMove-*-2 - fcb F$AllRam - fdb FAllRam-*-2 - fcb F$AllImg+$80 - fdb FAllImg-*-2 - fcb F$SetImg+$80 - fdb FSetImg-*-2 - fcb F$FreeLB+$80 - fdb FFreeLB-*-2 - fcb F$FreeHB+$80 - fdb FFreeHB-*-2 - fcb F$AllTsk+$80 - fdb FAllTsk-*-2 - fcb F$DelTsk+$80 - fdb FDelTsk-*-2 - fcb F$SetTsk+$80 - fdb FSetTsk-*-2 - fcb F$ResTsk+$80 - fdb FResTsk-*-2 - fcb F$RelTsk+$80 - fdb FRelTsk-*-2 - fcb F$DATLog+$80 - fdb FDATLog-*-2 - fcb F$LDAXY+$80 - fdb FLDAXY-*-2 - fcb F$LDDDXY+$80 - fdb FLDDDXY-*-2 - fcb F$LDABX+$80 - fdb FLDABX-*-2 - fcb F$STABX+$80 - fdb FSTABX-*-2 - fcb F$ELink+$80 - fdb FELink-*-2 - fcb F$FModul+$80 - fdb FFModul-*-2 - fcb F$AlHRam+$80 new call ++ - fdb FAlHRam-*-2 for CoCo3 ++ - fcb $80 End of Table - -*------------------------------------------------* -InitMod fcs "Init" -OS9p2Nm fcs "OS9p2" -BootMod fcs "Boot" - -*------------------------------------------------* -Vectors jmp [-16,x] goto irq routine - -*------------------------------------------------* -* User State SWI Vectors: -*------------------------------------------------* - -XSWI3 ldx D.Proc proc desc - ldu P$SWI3,x diff swi3 vector? - beq L028E ..no, do normal - -L027B lbra L0E5E else do usr call. - -XSWI2 ldx D.Proc X=proc desc - ldu P$SWI2,x swi2 svc ptr - beq L028E ..zero, do normal - bra L027B else do usr map - -XSWI ldx D.Proc proc desc - ldu P$SWI,x swi ptr - bne L027B ..do user, else: - -*------------------------------------------------* -* System SWI calls: (X=pd, U=svc) - -L028E ldd D.SysSvc set system state: - std D.XSWI2 - ldd D.SysIRQ - std D.XIRQ - lda P$State,x - ora #SysState - sta P$State,x - - sts P$SP,x and save user stack - leas P$Stack-R$Size,x get local sys stack - andcc #^IntMasks okay interrupts - leau ,s U=sys reg stack - bsr L02CB copy user stack here - - ldb P$Task,x B=task# - ldx R$PC,u X=PC ptr - lbsr FLDBBX get call byte from user map ++ - leax 1,x increment PC - stx R$PC,u past call - - ldy D.UsrDis Y=user dispatch table - lbsr L033B do the call - ldb R$CC,u okay interrupts - andb #^IntMasks on return - stb R$CC,u to user map - - ldx D.Proc - bsr L02DA copy back new user stack - lda P$State,x drop sys state - anda #^SysState - lbra L0D7C and return to user. - -*------------------------------------------------* -* Get Caller's Regs: - -L02CB pshs cc,x,y,u ++ - ldb P$Task,x A=user tsk# ++ - ldx P$SP,x X=from user stack - lbsr L0BF5 get offset in 8k space ++ - leax $A000,x +$A000 =logical address ++ - bra L02E9 get regs & rts. - -* Return Regs to Caller: - -L02DA pshs cc,x,y,u save state ++ - ldb P$Task,x B=user tsk# - ldx P$SP,x X=to user stack - lbsr L0BF5 get offset in 8k space ++ - leax $A000,x +$A000 =logical address ++ - exg x,u U=user, X=sys - -* move caller stack --> - -L02E9 pshs u save U ++ - lbsr L0C09 get DAT image pointer in U ++ - leau a,u point to block # in image ++ - leau 1,u point to LSB ++ -* lda ,u++ first block # in A ++ --BGP -* ldb ,u second block # in B ++ --BGP - lda ,u first block # in A ++ ++BGP - ldb 2,u second block # in B ++ ++BGP - ldu #DAT.Regs+5 $A000 logical ++ - orcc #IntMasks mask interrupts ++ - std ,u set DAT ++ - puls u recover U ++ - ldy #R$SIZE register stack size ++ - -L0303 ldd ,x++ move them ++ - std ,u++ ++ - leay -2,y done yet? ++ - bne L0303 no, continue ++ - ldx D.SysDAT system DAT image ++ - lda 11,x get real ++ - ldb 13,x system blocks ++ - std DAT.Regs+5 and restore system map ++ - puls cc,x,y,u,pc clean up and rts ++ - -*------------------------------------------------* -* Sys State OS Call: -*------------------------------------------------* -SysCall leau ,s U=reg stack - lda D.SSTskN get task image ++ - clr D.SSTskN set to system ++ - pshs a save old task # ++ - lda R$CC,u - tfr a,cc set CC=user CC - ldx R$PC,u get call - ldb ,s is task sys? ++ - beq L032F yes ++ - lbsr FLDBBX get call from user space ++ - leax 1,x point past it ++ - bra L0331 set as PC ++ - -L032F ldb ,x+ and increment PC - -L0331 stx R$PC,u past it - ldy D.SysDis Y=system dispatch table - bsr L033B do the call - lbra L0E2B end - -*------------------------------------------------* -* Do Svc Call(B), Y=table: - -L033B aslb index - bcc L0345 ..okay if not I/O - -* count I$ calls for current process (D.Proc) - pshs b save index into table - ldb #P$ICalls set up I$ counter - bsr IncCount go do it... (X is altered) - puls b recover index - - rorb else reset B - ldx $00FE,y else X=IOMan vector - bra L034F and do it. - -* count User Ticks, System Ticks, F$ calls, or I$ calls -* for current process (D.Proc) BRI -IncCount ldx <D.Proc get pointer to current proc desc - beq IncExit no current proc, go return - abx add offset to appropriate counter - inc 3,x 4 byte counter LSB - bne IncExit no overflow, go return - inc 2,x 4 byte counter lower middle byte - bne IncExit no overflow, go return - inc 1,x 4 byte counter upper middle byte - bne IncExit no overflow, go return - inc ,x 4 byte counter MSB (ignore overflow) -IncExit rts - -* (not I/O call) - -L0345 pshs b save index into table - ldb #P$FCalls set up F$ counter - bsr IncCount go do it... (X is altered) - puls b recover index - - clra A=00 - ldx d,y X=vector from table - bne L034F ..ok if one - comb else - ldb #E$UnkSvc 'Unknown Service Call' - bra L0355 bad end: return err - -*------------------------------------------------* -* Do Call Vector (X) - -L034F pshs u save reg ptr - jsr ,x do the call - puls u retrieve reg ptr - -L0355 tfr cc,a A=svc call CC - bcc L035B ..skip if no err - stb R$B,u else return err in reg.B -L035B ldb R$CC,u drop lsb nibble - andb #(Entire!IntMasks) - stb R$CC,u - anda #^(Entire!IntMasks) put in call's CC lsnibble - ora R$CC,u - sta R$CC,u - rts end service call. - - -*------------------------------------------------* -* F$SSvc -*------------------------------------------------* -FSSvc ldy R$Y,u Y=table address - bra InstSSvc do check first... - -* SSvc Loop: - -L036D clra A=00 - aslb B=table index (set C if >=$80) - tfr d,u U=index - ldd ,y++ D=new call vector offset - leax d,y X=actual vector - ldd D.SysDis D=sys dispatch table - stx d,u store new call vector - bcs InstSSvc ..skip if sys only - ldd D.UsrDis else put in user - stx d,u dispatch table also. - -* End of Table Check: - -InstSSvc ldb ,y+ get next call - cmpb #$80 is it end-of-table? - bne L036D ..no - rts yes, end. - - -*------------------------------------------------* -* F$SLink -*------------------------------------------------* -* Link modules into map. -* A=type,X=name,Y=DAT image ptr -FSLink ldy R$Y,u get DAT image ptr - bra SLink - - -*------------------------------------------------* -* F$ELink -*------------------------------------------------* -FELink pshs u - ldb R$B,u type - ldx R$X,u name of module - bra L03AF go link it - - -*------------------------------------------------* -* F$Link -*------------------------------------------------* -FLink ldx D.Proc proc desc - leay P$DATImg,x Y=DAT image ptr - -*------------------------------------------------* -SLink pshs u save reg ptr - ldx R$X,u X=module name - lda R$A,u A=module type - lbsr L068D search moddir - - bcs L041E ..err - - leay ,u Y=moddir entry - ldu ,s get back reg ptr - stx R$X,u return X - std R$D,u return type/lang - leax ,y X=moddir entry - -L03AF bitb #ReEnt is it shareable? - bne L03BB ..yes - ldd MD$Link,x any links? - beq L03BB ..no:ok, else - ldb #E$ModBsy 'Module Busy' err - bra L041E bad end. - -L03BB ldd MD$MPtr,x D=module ptr - pshs a,b,x save ptr,entry - ldy MD$MPDAT,x Y=DAT img for module - ldd MD$MBSiz,x D=mem block size - addd #$1FFF round up A ++ - tfr a,b to 8K block ++ - lsrb B/32 - lsrb - lsrb - lsrb - lsrb ++ - adda #2 (A+2)/32 ++ - lsra - lsra - lsra - lsra - lsra ++ - pshs a save blocks needed - leau ,y U=moddir entry - bsr L0422 find it in callers map? - bcc L03EB ..yes - - lda ,s blocks needed - lbsr L0A33 room to map in? - bcc L03E8 ..okay - leas 5,s else drop junk - bra L041E bad end. - -L03E8 lbsr L0A8C set DAT image -L03EB leax P$Links,x link cnt tble - sta ,s save block # - asla index - leau a,x U=link ptr - ldx ,u increment link cnt: - leax 1,x - beq L03FC - stx ,u -L03FC ldu 3,s U=moddir entry - ldx MD$Link,u increment link cnt: - leax 1,x - beq L0406 - stx MD$Link,u -L0406 puls b,x,y,u - lbsr L0AB0 dattolog - stx R$U,u return module addrss - ldx MD$MPtr,y mod ptr - ldy MD$MPDAT,y DAT image ptr - ldd #M$Exec get exec offset - lbsr LDDXY - addd R$U,u plus mod addrss - std R$Y,u = exec address - clrb okay - rts end. - -L041E orcc #Carry set error - puls u,pc - -*------------------------------------------------* -* See if moddir image in proc map already: -*------------------------------------------------* - -* B=block img #, U=moddir ptr - -L0422 ldx D.Proc proc desc - leay P$DATImg,x Y=DAT image ptr - clra A=00 - pshs a,b,x,y save #,proc,img - subb #DAT.BlCt - negb - aslb index - leay b,y - -* Image Compare Loop: - -L0430 ldx ,s X=block cnt - pshs y,u -L0434 ldd ,y++ does proc img - cmpd ,u++ match mod image? - bne L0449 ..no - leax -1,x yes, cnt-1 - bne L0434 ..done? - - puls a,b,u D=start ptr - subd 4,s -block cnt = offset - lsrb B/2 index - stb ,s save block # - clrb okay - puls a,b,x,y,pc rts. - -L0449 puls y,u Y=start ptr - leay -2,y back up one img - cmpy 4,s too far? - bcc L0430 ..no, try again - puls a,b,x,y,pc error end. - - -*------------------------------------------------* -* F$VModul -*------------------------------------------------* -FVModul pshs u - ldx R$X,u X=mod offset - ldy R$D,u Y=DAT img ptr - bsr L0463 do the verify - ldx ,s - stu R$U,x return moddir ptr - puls u,pc - -L0463 pshs x,y - lbsr L0586 check module crc - bcs L0493 ..err - - ldd #M$Type - lbsr LDDXY get type/rev bytes - andb #$0F save rev - pshs a,b - - ldd #M$Name get name offset - lbsr LDDXY - leax d,x X points to mod name - puls a - lbsr L068D - puls a - bcs L0497 - - pshs a - andb #$0F - subb ,s+ - bcs L0497 - ldb #E$KwnMod 'Known Module' - bra L0493 - -L0491 ldb #E$DirFul 'Module Dir Full' -L0493 orcc #Carry - puls x,y,pc - -*------------------------------------------------* -L0497 ldx ,s X=module addrss - lbsr L0524 - bcs L0491 - sty MD$MPDAT,u insert DAT image ptr - stx MD$MPtr,u and module ptr - clra - clrb - std MD$Link,u link count=00 - ldd #M$Size - lbsr LDDXY get module size - pshs x mod addrss - addd ,s++ plus size - std MD$MBSiz,u - ldy [MD$MPDAT,u] Y=mod images - ldx D.ModDir X=mod dir strt - pshs u save entry - bra L04BE - -L04BC leax MD$ESize,x next moddir entry -L04BE cmpx D.ModEnd last one? - bcc L04CD ..yes, end - cmpx ,s same entry? - beq L04BC ..yes, try again - cmpy [,x] same image ptr? - bne L04BC ..no, try again - bsr L04F2 - -*------------------------------------------------* -* Mark BlockMaps as Modules: - -L04CD puls u U=dir entry - ldx D.BlkMap X=mem block map - ldd MD$MBSiz,u D=mod block size - addd #$1FFF round up size ++ - lsra A/32 = number of blocks - lsra (8K) - lsra - lsra - lsra ++ - ldy MD$MPDAT,u Y=mod dat image - -L04DE pshs a,x save block size, blkmap - ldd ,y++ D=image block# - leax d,x X=blkmap ptr - ldb ,x get block marker - orb #ModBlock set module in block - stb ,x marker - puls a,x .. - deca count-1 - bne L04DE ..mark all blocks - - clrb okay - puls x,y,pc end. - -*------------------------------------------------* -* Clear entries: - -L04F2 pshs a,b,x,y,u - ldx ,x - pshs x - clra D=0000 - clrb -L04FA ldy ,x last entry? - beq L0503 ..yes - std ,x++ no, clear - bra L04FA and loop - -L0503 puls x - ldy 2,s - ldu MD$MPDAT,u U=mod images - puls a,b - -L050C cmpx ,y same image? - bne L051B ..no, try next - stu MD$MPDAT,y yes, set new image - cmpd MD$MBSiz,y new size bigger? - bcc L0519 ..yes, use it - ldd MD$MBSiz,y else use old size -L0519 std MD$MBSiz,y set modblock size -L051B leay MD$ESize,y next entry - cmpy D.ModEnd last? - bne L050C ..no - puls x,y,u,pc end. - -*------------------------------------------------* -L0524 pshs x,y,u save mod adrs,img, - ldd #M$Size get module size - lbsr LDDXY - addd ,s end = begin+size - addd #$1FFF round to block ++ - lsra A/32 - lsra - lsra - lsra - lsra ++, - tfr a,b A,B=number of blocks - pshs b save num - incb - aslb - negb - sex sign extend into D - bsr L054E make new dir entry - bcc L054C ..okay rts - - os9 F$GCMDir else get task# - ldu #$0000 set flag - stu 5,s - bsr L054E make new dir entry -L054C puls b,x,y,u,pc rts. - -*------------------------------------------------* -* Allocate module dir image: - -L054E ldx D.ModDAT X+D = mod DAT img pointer - leax d,x - cmpx D.ModEnd would it be below last dir? - bcs L0583 ..yes, err - - ldu 7,s get back old U - bne L056E .. - pshs x save new moddat ptr - ldy D.ModEnd Y=end of dir - leay MD$ESize,y plus new entry - cmpy ,s++ collide with moddat? - bhi L0583 ..yes, err - - sty D.ModEnd store new dir end - leay -MD$ESize,y Y=new dir entry ptr - sty 7,s return it to caller -L056E stx D.ModDAT store new moddat ptr - ldy 5,s - ldb 2,s B=block count - stx 5,s return dir datimg ptr - -L0577 ldu ,y++ copy images - stu ,x++ to new mod dat entry - decb - bne L0577 - - clr ,x zero flag - clr 1,x - rts end. - -L0583 orcc #Carry set err flag - rts end. - - -*------------------------------------------------* -* Calculate CRC of Module: -*------------------------------------------------* - -L0586 pshs x,y - clra D=offset of zero - clrb - lbsr LDDXY get 2 bytes - cmpd #M$ID12 is it module? - beq L0597 ..yes - ldb #E$BMID 'Bad Module Header' - bra L05F3 ..err end. - -* Check Module Header: - -L0597 leas -1,s make var - leax 2,x X=past sync bytes - lbsr L0AF0 set Y for X offset - ldb #$07 seven bytes - lda #$4A header crc -L05A2 sta ,s save crc - lbsr LDAXY get next byte - eora ,s do crc - decb more? - bne L05A2 ..loop - - leas 1,s drop var - inca $FF+1 = 00 - beq L05B5 ..okay header - ldb #E$BMHP 'Bad Module Header' - bra L05F3 err end. - -*------------------------------------------------* -* Do CRC across module: -* -* Added code to check init module for CRC check flag -L05B5 lda <D.CRC get D.CRC flag ++BGP - bne L05CX if set, check CRC ++BGP -NOCRC clrb else clrb (A already zero) ++BGP - bra L05F5 branch to end of routine ++BGP -L05CX puls x,y - ldd #$0002 - lbsr LDDXY - pshs a,b,x,y - ldd #$FFFF set temp CRC register - pshs a,b - pshs b - lbsr L0AF0 set up Y for X offset - leau ,s -L05CB tstb - bne L05D8 - pshs x - ldx #$0001 - os9 F$Sleep - puls x -L05D8 lbsr LDAXY get a byte - bsr CRCCalc pass it through the CRC calculator - ldd 3,s - subd #$0001 - std 3,s - bne L05CB - puls b,x,y - cmpb #$80 - bne L05F1 - cmpx #$0FE3 - beq L05F5 -L05F1 ldb #E$BMCRC 'Bad Module CRC' -L05F3 orcc #Carry -L05F5 puls x,y,pc - -*------------------------------------------------* -* CRC Calculator: -*------------------------------------------------* - -* A = byte to be passed through accumulator -CRCCalc eora ,u - pshs a - ldd 1,u - std ,u - clra - ldb ,s - aslb - rola - eora 1,u - std 1,u - clrb - lda ,s - lsra - rorb - lsra - rorb - eora 1,u - eorb 2,u - std 1,u - lda ,s - asla - eora ,s - sta ,s - asla - asla - eora ,s - sta ,s - asla - asla - asla - asla - eora ,s+ - bpl L0635 - ldd #$8021 - eora ,u - sta ,u - eorb 2,u - stb 2,u -L0635 rts - -*------------------------------------------------* -* F$CRC -*------------------------------------------------* -FCRC ldd R$Y,u get byte count - beq L0677 ..zero - ldx R$X,u begin ptr - pshs a,b,x - leas -3,s - ldx D.Proc - lda P$Task,x - ldb D.SysTsk - ldx R$U,u - ldy #$0003 - leau ,s - pshs a,b,x,y - lbsr L0B2C - ldx D.Proc - leay P$DATImg,x - ldx 11,s - lbsr L0AF0 -L065D lbsr LDAXY - bsr CRCCalc pass byte through CRC calculator - ldd 9,s - subd #$0001 - std 9,s - bne L065D - puls a,b,x,y - exg a,b - exg x,u - lbsr L0B2C - leas 7,s -L0677 clrb - rts - -*------------------------------------------------* -* F$FModul -*------------------------------------------------* -* Find the Module named (X) with type (A) in Y -FFModul pshs u - lda R$A,u A=type request - ldx R$X,u X=name - ldy R$Y,u Y=DAT image ptr - bsr L068D find it - puls y - std R$D,y return type/attr - stx R$X,y updated name ptr - stu R$U,y module offset - rts - -L068D ldu #$0000 address flag - pshs a,b,u - bsr L0712 get first char - cmpa #PDELIM start with pathlist delimiter? - beq L070B ..bad name error - lbsr L0741 - bcs L070E - ldu D.ModEnd U=mod end ++ - bra L0700 - -*------------------------------------------------* -* Main Loop: - -L06A1 pshs a,b,x,y - pshs x,y - ldy MD$MPDAT,u Y=mod images - beq L06F6 - ldx MD$MPtr,u X=mod ptr - pshs x,y - ldd #M$Name get mod name - lbsr LDDXY offset - leax d,x X=name address - pshs x,y save add,images - leax 8,s - ldb 13,s - leay ,s - lbsr L07DE - leas 4,s - puls x,y - leas 4,s - bcs L06FE - ldd #M$Type get mod type/lang - lbsr LDDXY - sta ,s - stb 7,s - lda 6,s - beq L06ED - anda #$F0 - beq L06E1 - eora ,s - anda #$F0 - bne L06FE -L06E1 lda 6,s - anda #$0F - beq L06ED - eora ,s - anda #$0F - bne L06FE -L06ED puls a,b,x,y - abx - clrb - ldb 1,s - leas 4,s - rts - -*------------------------------------------------* -L06F6 leas 4,s - ldd 8,s - bne L06FE - stu 8,s -L06FE puls a,b,x,y - -* Moved back one ++ - -L0700 leau -MD$ESize,u next dir entry ++ - cmpu D.ModDir last one? ++ - bcc L06A1 ..no, loop ++ - -*------------------------------------------------* - ldb #E$MNF 'Module Not Found' - bra L070E - -L070B comb - ldb #E$BNam 'Bad Name' error -L070E stb 1,s return err code - puls a,b,u,pc - -*------------------------------------------------* -* Get Module Name: - -L0712 pshs y save image strt -L0714 lbsr L0AF0 point X to name in img(Y) - lbsr L0AC8 get char - leax 1,x ptr+1 - cmpa #C$SPAC was char space? - beq L0714 ..yes, skip - - leax -1,x ptr-1 - pshs a save char - tfr y,d D=image ptr - subd 1,s -images start - asrb block#=image/2 - lbsr L0AB0 ?? - puls a,y,pc rts. - - -*------------------------------------------------* -* F$PrsNam -*------------------------------------------------* -FPrsNam ldx D.Proc proc desc - leay P$DATImg,x Y=DAT image ptr - ldx R$X,u X=name string - bsr L0741 get it and length - std R$D,u return length in D - bcs L073E ..err - stx R$X,u and X at name begin - abx plus len -L073E stx R$Y,u return Y=end of name ptr - rts end. - -* Parse Name: - -L0741 pshs y save image ptr - lbsr L0AF0 find map block - pshs x,y save X offset within block and Y block pointer - lbsr LDAXY get A=byte(X) - cmpa #PDELIM is it a pathlist delimiter? - bne L0756 ..no, go keep X offset and block Y - leas 4,s - pshs x,y - lbsr LDAXY get next char -L0756 bsr L07A1 go check if valid first character... - bcs L076A not valid, go get next name start offset in X... - clrb initialize character counter -L075B incb incb add one character - tsta last character in name string? - bmi L0766 yes, go return valid... - lbsr LDAXY go get next character... - bsr L078A go check if valid character... - bcc L075B valid, go check if last character... -L0766 andcc #^Carry - bra L077C - -*------------------------------------------------* -L076A cmpa #C$COMA comma? - bne L0775 no, check for next character -L076E leas 4,s - pshs x,y - lbsr LDAXY -L0775 cmpa #C$SPAC is it a space? - beq L076E ..yes, go get next character - comb error, set Carry - ldb #E$BNam 'Bad Name' error -L077C puls x,y recover offset and pointer - pshs cc,a,b save Carry, character and count or error code - tfr y,d copy DAT image block pointer - subd 3,s subtract original DAT image pointer - asrb convert 2 byte/block count to block number - lbsr L0AB0 go get true map offset in X... - puls cc,a,b,y,pc recover registers and return... - -L078A pshs a save character - anda #$7F drop msbit - cmpa #PDIR period? - beq ValidChr yes, go return valid character... - cmpa #'0 is it control? - bcs InvalChr ..yes - cmpa #'9 is it number? - bls ValidChr ..yes - cmpa #'_ is it '_'? - bne L07A5 ..no -ValidChr clra clear carry - puls a,pc recover original character and return - -*---------------------------------------------- -L07A1 pshs a - anda #$7F drop msbit -L07A5 cmpa #'A less than "A"? - bcs InvalChr yes, go return invalid character... - cmpa #'Z less than or equal to "Z"? - bls ValidChr yes, go return valid character - cmpa #'a less than "a"? - bcs InvalChr yes, go return invalid character - cmpa #'z less than or equal to "z"? - bls ValidChr yes, go return valid character -InvalChr coma - puls a,pc - - -*------------------------------------------------* -* F$CmpNam -*------------------------------------------------* -FCmpNam ldx D.Proc proc desc - leay P$DATImg,x Y=caller DAT image ptr - ldx R$X,u X=first name - pshs x,y save name,img - bra L07CF do it - - -*------------------------------------------------* -* F$CmpNam (sys) -*------------------------------------------------* -SCmpNam ldx D.Proc proc desc - leay P$DATImg,x Y=images - ldx R$X,u X=first name - pshs x,y save name,imgs - ldy D.SysDAT Y=system DAT image ptr - -L07CF ldx R$Y,u X=second name - pshs x,y save name2,sysimg - ldd R$D,u D=match length - leax 4,s [X]=name1 - leay ,s [Y]=name2 - bsr L07DE compare them - leas 8,s drop vars - rts end. - -* Compare two strings: - -L07DE pshs a,b,x,y,u length,name1,name2,regs - ldu 2,s U=name1 ptr - pulu x,y get name,images - lbsr L0AF0 set X for img(Y) - pshu x,y save name1 offsets - ldu 4,s - pulu x,y - lbsr L0AF0 - bra L07F6 - -L07F2 ldu 4,s - pulu x,y -L07F6 lbsr LDAXY get name2 char - pshu x,y - pshs a save char - ldu 3,s - pulu x,y - lbsr LDAXY get name1 char - pshu x,y - eora ,s compare chars - tst ,s+ check result - bmi L0816 ..msb diff - decb len-1 - beq L0813 last? - anda #$DF - beq L07F2 do next char - -L0813 comb err - puls a,b,x,y,u,pc end. - -L0816 decb len-1 - bne L0813 ..err if >0 - anda #$5F - bne L0813 - clrb okay - puls a,b,x,y,u,pc end. - - -*------------------------------------------------* -* F$SRqMem / F$BtMem -*------------------------------------------------* -FSRqMem -FBtMem ldd R$D,u get # bytes wanted - addd #$00FF round up - clrb to page - std R$D,u return it - ldy D.SysMem Y=system mem map - leas -2,s - stb ,s -L082F ldx D.SysDAT X=system DAT image - aslb index block - ldd b,x D=DAT marker - cmpd #DAT.Free is it free? - beq L0847 ..yes - ldx D.BlkMap else look - lda d,x at block map byte - cmpa #RAMinUse is it in use? - bne L0848 ..yes - leay 32,y leave map ++ - bra L084F - -* Free Ram: - -L0847 clra - -* Ram Not in Use: - -L0848 ldb #32 count=32 pages ++ -L084A sta ,y+ mark the ram - decb - bne L084A - -L084F inc ,s - ldb ,s - cmpb #DAT.BlCt all blocks done? - bcs L082F -L0857 ldb R$A,u page count -L0859 cmpy D.SysMem back to map start? - bhi L0863 ..not yet - comb - ldb #E$NoRam was MemFul ++ - bra L0894 - -L0863 lda ,-y free page? - bne L0857 ..no,try again - decb else got page+1 - bne L0859 - sty ,s - lda 1,s - lsra - lsra - lsra - lsra - lsra ++ - ldb 1,s - andb #$1F ++ - addb R$A,u - addb #$1F ++ - lsrb - lsrb - lsrb - lsrb - lsrb ++ - ldx D.SysPrc - lbsr L09BE allocate ram images - bcs L0894 - ldb R$A,u -L088A inc ,y+ - decb - bne L088A - lda 1,s - std R$U,u return ptr to mem - clrb -L0894 leas 2,s - rts - - -*------------------------------------------------* -* F$SRtMem -*------------------------------------------------* -FSRtMem ldd R$D,u - beq L08F2 - addd #$00FF - ldb R$U+1,u - beq L08A6 - comb - ldb #E$BPAddr 'Boundary Error' - rts - -L08A6 ldb R$U,u - beq L08F2 - ldx D.SysMem - abx -L08AD ldb ,x - andb #^RAMinUse - stb ,x+ - deca - bne L08AD - ldx D.SysDAT - ldy #DAT.BlCt 16 blocks/space -L08BC ldd ,x - cmpd #DAT.Free free block? - beq L08EC ..yes - ldu D.BlkMap - lda d,u - cmpa #$01 - bne L08EC - tfr x,d - subd D.SysDAT - aslb - aslb - aslb - aslb ++ - ldu D.SysMem - leau d,u - ldb #32 16 blocks in sys space ++ -L08DA lda ,u+ - bne L08EC - decb - bne L08DA - ldd ,x - ldu D.BlkMap - clr d,u - ldd #DAT.Free - std ,x -L08EC leax 2,x - leay -1,y - bne L08BC -L08F2 clrb - rts - - -*------------------------------------------------* -* F$Boot -*------------------------------------------------* -FBoot comb - lda D.Boot booted already? - bne L0966 ..yes,rts. - inc D.Boot flag it -* ldx D.Init X=init module -* beq L0908 ..use default if no Init -* ldd BootStr,x offset to Boot name -* beq L0908 ..none -* leax d,x X=Init BootStrap name -* bra L090C use it - -L0908 leax BootMod,pcr default 'Boot' name -L090C lbsr LinkSys link to module - bcs L0966 ..err rts - jsr ,y do the boot - bcs L0966 ..err - std D.BtSz Bootfile size ++ - stx D.BtPtr Boot start address ++ - leau d,x - tfr x,d - anda #$E0 ++ - clrb - pshs a,b,u - lsra - lsra - lsra - lsra ++ - ldy D.SysDAT - leay a,y -*------------------------------------------------* -* Find & Verify Boot Modules: - -L092D ldd ,x get header - cmpd #M$ID12 (87CD) is it a module? - bne L0954 ..no - tfr x,d - subd ,s - tfr d,x - tfr y,d - os9 F$VModul - pshs b - ldd 1,s - leax d,x - puls b - bcc L094E - cmpb #E$KwnMod 'Known Module'? - bne L0954 ..no -L094E ldd 2,x - leax d,x - bra L0956 - -L0954 leax 1,x -L0956 cmpx 2,s end of boot mem? - bcs L092D ..no, try more - leas 4,s - ldx D.SysDAT ++ - ldb 13,x ++ - incb ++ - ldx D.BlkMap ++ - lbra L01DF ++ - -L0966 rts - - -*------------------------------------------------* -* F$AllRam -*------------------------------------------------* -FAllRam ldb R$B,u get # ram blocks desired - bsr L0970 - bcs L096F - std R$D,u -L096F rts - -*------------------------------------------------* -L0970 pshs a,b,x,y - ldx D.BlkMap X=block map start - -* Start at new block begin: - -L0974 leay ,x Y=start - ldb 1,s B=count -L0978 cmpx D.BlkMap+2 at end of block map? - bcc L0995 ..yes,end. - lda ,x+ is block free? - bne L0974 ..no, try new start - decb yes, count-1 - bne L0978 keep trying - -L0983 tfr y,d D=begin block ptr ++ - subd D.BlkMap D=begin block number - sta R$A-1,s return number on ,S - lda R$B-1,s A=count - stb R$B-1,s - -* mark off blocks - -L098D inc ,y+ mark as ram in use - deca - bne L098D - clrb - puls a,b,x,y,pc okay end. - -L0995 comb - ldb #E$NoRam 'Sys Ram Full' - stb 1,s return err - puls a,b,x,y,pc bad end. - -*------------------------------------------------* -* F$AlHRam -*------------------------------------------------* - -FALHRAM ldb R$B,u get block count ++ - bsr L09A5 find blocks ++ - bcs L09A4 error ++ - std R$D,u return count in D ++ - -L09A4 rts ++ - -L09A5 pshs a,b,x,y match up stack ++ - ldx D.BlkMap+2 point to end of map ++ - -L09A9 ldb R$B-1,s get block count ++ - -L09AB cmpx D.BlkMap at bottom of map? ++ - bls L0995 yes, error ++ - lda ,-x block free? ++ - bne L09A9 no ++ - decb found them all? ++ - bne L09AB no, continue ++ - tfr x,y match up registers ++ - bra L0983 allocate blocks ++ - -*------------------------------------------------* -* F$AllImg -*------------------------------------------------* -FAllImg ldd R$D,u A=begin blk#, B=# of blocks - ldx R$X,u X=proc desc -L09BE pshs a,b,x,y,u - asla - leay P$DATImg,x Y=DAT image ptr - leay a,y Y=image ptr - clra - tfr d,x - ldu D.BlkMap - pshs a,b,x,y,u -L09CD ldd ,y++ D=image - cmpd #DAT.Free unused? - beq L09E2 ..yes - lda d,u else what is it? - cmpa #RAMinUse ram? - puls a,b - bne L09F7 ..no - - subd #$0001 - pshs a,b -L09E2 leax -1,x - bne L09CD - ldx ,s++ - beq L0A00 -L09EA lda ,u+ - bne L09F2 - leax -1,x - beq L0A00 -L09F2 cmpu D.BlkMap+2 - bcs L09EA - -L09F7 ldb #E$MemFul 'Proc Memory Full' (207) - leas 6,s - stb R$B-1,s - comb - puls a,b,x,y,u,pc - -*------------------------------------------------* -L0A00 puls x,y,u -L0A02 ldd ,y++ - cmpd #DAT.Free - bne L0A16 -L0A0A lda ,u+ - bne L0A0A - inc ,-u - tfr u,d - subd D.BlkMap - std -2,y - -L0A16 leax -1,x - bne L0A02 - ldx 2,s - lda P$State,x get proc state & - ora #ImgChg flag image change - sta P$State,x . - clrb - puls a,b,x,y,u,pc - - -*------------------------------------------------* -* F$FreeHB -*------------------------------------------------* -FFreeHB ldb R$B,u B=block count - ldy R$Y,u - bsr L0A31 - bcs L0A30 - sta R$A,u -L0A30 rts - -L0A31 tfr b,a -L0A33 suba #$09 - nega - pshs x,b,a - ldd #$FFFF - pshs b,a - bra L0A58 - -FFreeLB ldb R$B,u - ldy R$Y,u - bsr L0A4B - bcs L0A4A - sta R$A,u -L0A4A rts - -L0A4B lda #$FF - pshs x,b,a - lda #$01 - subb #$09 - negb - pshs b,a - bra L0A58 - -L0A58 clra - ldb $02,s - addb ,s - stb $02,s - cmpb $01,s - bne L0A75 - ldb #$CF - cmpy <D.SysDAT - bne L0A6C - ldb #$ED -L0A6C stb $03,s - comb - bra L0A82 - -L0A71 tfr a,b - addb $02,s -L0A75 lslb - ldx b,y - cmpx #DAT.Free - bne L0A58 - inca - cmpa $03,s - bne L0A71 -L0A82 leas $02,s - puls pc,x,b,a - -FSetImg ldd R$A,u - ldx R$X,u - ldu R$U,u -L0A8C pshs u,y,x,b,a - leay P$DATImg,x - lsla - leay a,y -L0A94 ldx ,u++ - stx ,y++ - decb - bne L0A94 - ldx $02,s get proc desc ptr - lda P$State,x - ora #ImgChg - sta P$State,x - clrb - puls pc,u,y,x,b,a - -FDATLog ldb R$B,u - ldx R$X,u - bsr L0AB0 - stx R$X,u - clrb - rts - -*L0AB0 pshs x,b,a --BGP -L0AB0 pshs x,b ++BGP - lslb - lslb - lslb - lslb - lslb -* addb $02,s --BGP -* stb $02,s --BGP - addb 1,s ++BGP - stb 1,s ++BGP -* puls pc,x,b,a --BGP - puls pc,x,b ++BGP - -FLDAXY ldx R$X,u - ldy R$Y,u - bsr L0AC8 - sta R$A,u - clrb - rts - -L0AC8 pshs cc - lda $01,y - orcc #IntMasks - sta >DAT.Regs - lda ,x - clr >DAT.Regs - puls pc,cc - -LDAXY bsr L0AC8 - leax $01,x - bra L0AF0 - -L0AEA leax >-$2000,x - leay $02,y -L0AF0 cmpx #$2000 - bcc L0AEA - rts - -FLDDDXY ldd R$D,u - leau R$X,u - pulu y,x - bsr LDDXY - std -$07,u - clrb - rts -LDDXY pshs y,x - leax d,x - bsr L0AF0 - bsr LDAXY - pshs a - bsr L0AC8 - tfr a,b - puls pc,y,x,a - -FLDABX ldb R$B,u - ldx R$X,u - lbsr L0C12 - sta R$A,u - rts - -FSTABX ldd R$D,u - ldx R$X,u - lbra L0C28 - -FMove ldd R$D,u - ldx R$X,u - ldy R$Y,u - ldu R$U,u -L0B2C pshs u,y,x,b,a - leay ,y - lbeq L0BF2 - pshs y,b,a - tfr a,b - lbsr L0C0F - leay a,u - pshs y,x - ldb $09,s - ldx $0E,s - lbsr L0C0F - leay a,u - pshs y,x - ldd #$2000 - subd ,s - pshs b,a - ldd #$2000 - subd $06,s - pshs b,a - ldx $08,s - leax >-$6000,x - ldu $04,s - leau >-$4000,u -L0B6A pshs cc - ldd [<$07,s] - pshs b - ldd [<$0C,s] - pshs b - ldd <$11,s - cmpd $03,s - bls L0B82 - ldd $03,s -L0B82 cmpd $05,s - bls L0B89 - ldd $05,s -L0B89 cmpd #$0040 - bls L0B84 - ldd #$0040 -L0B84 std $0F,s - puls y - orcc #IntMasks - sty >$FFA5 - andb #$07 - beq L0B99 -L0B92 lda ,x+ - sta ,u+ - decb - bne L0B92 -L0B99 ldb $0E,s - lsrb - lsrb - lsrb - beq L0BBC - pshs b - exg x,u -L0BA4 pulu y,b,a - std ,x - sty $02,x - pulu y,b,a - std $04,x - sty $06,x - leax $08,x - dec ,s - bne L0BA4 - leas $01,s - exg x,u -L0BBC ldy <D.SysDAT - lda $0B,y - ldb $0D,y - std >$FFA5 - puls cc - ldd $0E,s - subd $0C,s - beq L0BEF - std $0E,s - ldd ,s - subd $0C,s - bne L0BD7 - ldd #$2000 - leax >-$2000,x - inc $0B,s - inc $0B,s -L0BD7 std ,s - ldd $02,s - subd $0C,s - bne L0BEA - ldd #$2000 - leau >-$2000,u - inc $07,s - inc $07,s -L0BEA std $02,s - lbra L0B6A -L0BEF leas <$10,s -L0BF2 clrb - puls pc,u,y,x,b,a - -L0BF5 pshs b - tfr x,d - anda #$1F - exg d,x - anda #$E0 - lsra - lsra - lsra - lsra -L0C07 puls pc,b -L0C0F bsr L0BF5 -*L0C09 pshs b --BGP -L0C09 - ldu <D.TskIPt - lslb - ldu b,u - rorb ++BGP -* puls pc,b --BGP - rts ++BGP - -L0C12 andcc #^Carry - pshs u,x,b,cc - bsr L0C0F - ldd a,u - orcc #IntMasks - stb >DAT.Regs - lda ,x - clr >DAT.Regs - puls pc,u,x,b,cc - -L0C28 andcc #^Carry - pshs u,x,b,a,cc - bsr L0C0F - ldd a,u - lda $01,s - orcc #IntMasks - stb >DAT.Regs - sta ,x - clr >DAT.Regs - puls pc,u,x,b,a,cc - -FLDBBX andcc #^Carry - pshs u,x,a,cc - bsr L0C0F - ldd a,u - orcc #IntMasks - stb >DAT.Regs - ldb ,x - clr >DAT.Regs - puls pc,u,x,a,cc - -FAllTsk ldx R$X,u -L0C58 ldb P$Task,x - bne L0C64 - cmpx <$004A - beq L0C64 - bsr L0CA6 - bcs L0C65 - stb P$Task,x - bsr L0C79 -L0C64 clrb -L0C65 rts - -FDelTsk ldx R$X,u get proc desc ptr -L0C68 ldb P$Task,x - beq L0C65 - clr P$Task,x - bra L0CC3 -L0C70 lda P$State,x - bita #ImgChg - bne L0C79 - rts - -FSetTsk ldx R$X,u -L0C79 lda P$State,x - anda #^ImgChg - sta P$State,x - andcc #^Carry - pshs u,y,x,b,a,cc - ldb P$Task,x - leax P$DATImg,x - ldu <D.TskIPt - lslb - stx b,u - cmpb #$02 - bgt L0C9F - ldu #DAT.Regs - leax 1,x - ldb #$08 -L0C98 lda ,x++ - sta ,u+ - decb - bne L0C98 -L0C9F puls pc,u,y,x,b,a,cc - -FResTsk bsr L0CA6 - stb R$B,u - rts - -L0CA6 pshs x - ldb #$02 - ldx <D.Tasks -L0CAC lda b,x - beq L0CBA - incb - cmpb #$20 - bne L0CAC - comb - ldb #$EF - bra L0CBF - -L0CBA inc b,x - clra -L0CBF puls pc,x - -FRelTsk ldb R$B,u -L0CC3 pshs x,b - tstb - beq L0CD0 - ldx <D.Tasks - clr b,x -L0CD0 puls pc,x,b - -* Control goes here when a tick interrupt comes in -Clock ldb #P$STicks assume system state - ldx <D.Proc get curr process - lda P$State,x get process state - bmi L0CDC branch if SysState - ldb #P$UTicks otherwise user state -L0CDC lbsr IncCount count ticks - ldx <D.SProcQ point to sleep queue - beq L0CFD branch if no process sleeping -* Process sleep queue here! -* Sleep queue is sorted by process closest to wake first, all the way -* to processes that are sleeping forever. - lda P$State,x get process' state - bita #TimSleep sleeping forever? - beq L0CFD yep, finished - ldu P$SP,x else get process' stack pointer - ldd R$X,u and get process' sleep tick counter - subd #$0001 subtract 1 from tick counter - std R$X,u save back to process' X - bne L0CFD branch if not ready to wake -L0CE7 ldu P$Queue,x else time to wake up! so... - bsr L0D11 activate this process - leax ,u point to next process - beq L0CFB - lda P$State,x - bita #TimSleep - beq L0CFB - ldu P$SP,x - ldd R$X,u - beq L0CE7 -L0CFB stx <D.SProcQ store new process pointer -L0CFD dec <D.Slice decrement slice - bne L0D0D branch if not at end of timeslice - inc <D.Slice - ldx <D.Proc get current process - beq L0D0D branch if none - lda P$State,x ...else get state - ora #TimOut and indicate it's out of time - sta P$State,x then restore it -L0D0D clrb - rts - -* X = address of process descriptor to put in active queue -FAProc ldx R$X,u -L0D11 clrb - pshs u,y,x,b,cc - lda P$Prior,x get priority of process - sta P$Age,x reset age to priority - orcc #IntMasks mask interrupts - ldu #$0045 - bra L0D29 -L0D1F inc $0B,u - bne L0D25 - dec $0B,u -L0D25 cmpa $0B,u - bhi L0D2B -L0D29 leay ,u -L0D2B ldu $0D,u - bne L0D1F - ldd $0D,y - stx $0D,y - std $0D,x - puls pc,u,y,x,b,cc - -* System IRQ service routine - -XIRQ ldx <D.Proc - sts P$SP,x - lds <D.SysStk - ldd <D.SysSvc - std <D.XSWI2 - ldd <D.SysIRQ - std <D.XIRQ - jsr [>D.SvcIRQ] - bcc L0D5B - ldx <D.Proc - ldb P$Task,x - ldx P$SP,x - lbsr L0C12 - ora #IntMasks - lbsr L0C28 -L0D5B orcc #IntMasks - ldx <D.Proc - lda P$State,x - bita #TimOut - bne L0D7C -L0D78 ldu $04,x - bra L0DB9 -L0D7C anda #$DF - sta $0C,x - lbsr L0C68 -L0D83 bsr L0D11 - -FNProc ldx <D.SysPrc - stx <D.Proc - lds <D.SysStk - andcc #^(IntMasks) - bra L0D93 - -L0D91 cwai #^(IntMasks) -L0D93 orcc #IntMasks - lda #Suspend - ldx #$0045 -L0D9A leay ,x - ldx $0D,y - beq L0D91 - bita P$State,x - bne L0D9A - ldd P$Queue,x - std $0D,y - stx <D.Proc - lbsr L0C58 - bcs L0D83 - lda <D.TSlice - sta <D.Slice - ldu P$SP,x - lda P$State,x - bmi L0E29 -L0DB9 bita #Condem - bne L0DFD - lbsr L0C70 - ldb P$Signal,x - beq L0DF2 - decb - beq L0DEF - leas -$0C,s - leau ,s - lbsr L02CB - lda P$Signal,x - sta $02,u - ldd P$SigVec,x - beq L0DFD - std $0A,u - ldd P$SigDat,x - std $08,u - ldd P$SP,x - subd #$000C - std P$SP,x - lbsr L02DA - leas $0C,s - ldu P$SP,x - clrb -L0DEF stb P$Signal,x -L0DF2 ldd <D.UsrSvc - std <D.XSWI2 - ldd <D.UsrIRQ - std <D.XIRQ - bra L0E4C -L0DFD lda P$State,x - ora #SysState - sta P$State,x - leas $0200,x - andcc #^(IntMasks) - ldb P$Signal,x - clr P$Signal,x - os9 F$Exit - -* Interrupts come through here when in system state -S.SysIRQ lda <D.SSTskN get system task number - clr <D.SSTskN clear system task number in globs - pshs a save on stack - jsr [>D.SvcIRQ] - puls a - bsr L0E39 - bcc XFIRQ - ldb R$CC,s - orb #IntMasks - stb R$CC,s -XFIRQ rti - -L0E29 clr ,-s -L0E2B ldx <D.SysPrc - lbsr L0C70 - orcc #IntMasks - puls a - bsr L0E39 - leas ,u - rti - -* A = task number -L0E39 sta <D.SSTskN - beq S.AltIRQ - ora <D.TINIT - sta <D.TINIT - sta DAT.Task -S.AltIRQ rts - -S.SvcIRQ jmp [>D.Poll] -S.POLL orcc #Carry - rts - -L0E4C ldb $06,x - orcc #IntMasks - bsr L0E8D - lda <D.TINIT - ora #$01 - sta <D.TINIT - sta DAT.Task - leas ,u - rti - -L0E5E ldb <D.TINIT - orb #$01 - stb <D.TINIT - stb DAT.Task - jmp ,u - -S.Flip0 pshs b,a - lda <D.TINIT - anda #$FE - sta <D.TINIT - sta DAT.Task - clr <D.SSTskN - puls b,a - tfr x,s - tfr a,cc - rts - -S.Flip1 ldb #$01 get task image entry number - bsr L0E8D copy over the DAT image - lda <D.TINIT get copy of GIME Task side - ora #$01 switch it to task one - sta <D.TINIT save it to image - sta DAT.Task save it to GIME register - inc <D.SSTskN increment system tstae task number - rti return - -L0E8D pshs u,x,b,a - ldx #$FFA8 get MMU start register for process - ldu <D.TskIPt get task image pointer table - lslb account for 2 bytes per entry - ldu b,u get address of MMU entry - leau $01,u - ldb #$08 -L0E9B lda ,u++ - sta ,x+ - decb - bne L0E9B - puls pc,u,x,b,a - -* SWI3.V - Control comes here upon a SWI3 interrupt -SWI3.V orcc #IntMasks mask interrupts - ldb #D.SWI3 get direct page global vector - bra IRQCntrl - -* SWI2.V - Control comes here upon a SWI2 interrupt -SWI2.V orcc #IntMasks mask interrupts - ldb #D.SWI2 get direct page global vector - bra IRQCntrl - -* FIRQ.V - Control comes here upon a FIRQ interrupt -FIRQ.V tst ,s - bmi L0EB0 - leas -$01,s - pshs y,x,dp,b,a - lda $08,s - stu $07,s - ora #$80 - pshs a -L0EB0 ldb #D.FIRQ - bra IRQCntrl - -* IRQ.V - Control comes here upon a IRQ interrupt -IRQ.V orcc #IntMasks mask interrupts - ldb #D.IRQ get direct page global vector -* B = address of vector from direct page -IRQCntrl clra clear A - tfr a,dp make DP point to 0 - sta DAT.Task redundancy??? - lda <D.TINIT get task register shadow - anda #$FE clear bit to use $FFA0-$FFA7 - sta <D.TINIT save in shadow - sta DAT.Task save in hardware (do it!) - clra clear A - tfr d,x D = addr of direct page vector - jmp [,x] transfer control to addr in passed vector - -* SWI.V - Control comes here upon a SWI interrupt -SWI.V ldb #D.SWI get direct page global vector - bra IRQCntrl - -* NMI.V - Control comes here upon a NMI interrupt -NMI.V ldb #D.NMI get direct page global vector - bra IRQCntrl - -* Filler to get $ED9 -Filler fill $39,$EDC-* - - emod -eom equ * - -* Direct Page vectors -D.VECTRS fdb $F100+Clock goes in D.Clock - fdb $F100+XSWI3 goes in D.XSWI3 - fdb $F100+XSWI2 goes in D.XSWI2 - fdb $F100+XFIRQ goes in D.XFIRQ - fdb $F100+XIRQ goes in D.XIRQ - fdb $F100+XSWI goes in D.XSWI - fdb $F100 goes in D.NMI - fcb $55 -* 6809 vectors -* This table starts at $FEEE. Each address is pointed to by the 6809 -* vectors at $FFF0 (defined in the CoCo 3 ROM). - lbra SWI3.V SWI3 - lbra SWI2.V SWI2 - lbra FIRQ.V FIRQ - lbra IRQ.V IRQ - lbra SWI.V SWI - lbra NMI.V NMI - -eo equ * - end
--- a/level2/modules/os9p2.asm Sat Sep 13 16:10:19 2003 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2124 +0,0 @@ -******************************************************************** -* OS9p2 - OS-9 Level Two V3 P2 module -* -* $Id$ -* -* Ed. Comments Who YY/MM/DD -* ------------------------------------------------------------------ -* 18d Removed bogus assumptions regarding init BGP 98/10/05 -* module in order to shrink code size, added -* check for CRC bit in compabibility byte of -* init module. -* 18e Made minor optimizations as per Curtis Boyle's BGP 98/10/10 -* optimization document - - nam OS9p2 - ttl OS-9 Level Two V3 P2 module - - ifp1 - use defsfile - endc - -msiz equ 256 - -F$IOMan equ $7F - -rev set $05 -edition set 18 - - mod endmod,name,Systm,Reent+rev,entry,msiz - -name fcs "OS9p2" - fcb edition - -*------------------------------------------------* -* OS9p2 Inits Here: -*------------------------------------------------* - -entry leay SysCalls,pcr insert OS9p2 sys calls - os9 F$SSvc - ldu <D.Init - ldd Maxmem,u D=top of free mem - lsra D/16 (16 blocks/map) - rorb - lsra - rorb - lsra - rorb - lsra - rorb - lsra - rorb - addd <D.BlkMap D+block map start - tfr d,x X=D - ldb #NotRAM get flag - bra L0036 - -L0030 lda ,x+ get block marker - bne L0036 ..skip if used - stb -1,x else set as none -L0036 cmpx <D.BlkMap+2 end of map? - bcs L0030 ..no,loop - -L003A ldu <D.Init U=init module - ldd SysStr,u point to '/D0' offset - beq L004F ..none - leax d,u X=name ptr - lda #READ.+EXEC. - os9 I$ChgDir 'CHD /D0',CHX /D0 -* bcc L004F ..okay -* os9 F$Boot else boot -* bcc L003A ..okay - -L004F ldu <D.Init init data - ldd StdStr,u point to '/TERM' - beq L0077 - leax d,u - lda #READ.+WRITE. - os9 I$Open try to open /Term -* bcc L0066 ..okay -* os9 F$Boot else boot and -* bcc L004F ..try again - bcs Crash crash! - -L0066 ldx <D.Proc X=proc desc - sta P$Path,x std in - os9 I$Dup - sta P$Path+1,x std out - os9 I$Dup - sta P$Path+2,x std err - -L0077 leax OS9p3Nam,pcr try to find OS9p3 - lbsr SysLink - bcs L0083 - jsr ,y do it's init if it exists - -L0083 ldu <D.Init - ldd InitStr,u point to 'Sysgo' - leax d,u - lda #Objct mod type - clrb mem ok - ldy #$0000 no parms - os9 F$Fork start up sysgo - os9 F$NProc and do it. - -OS9p3Nam fcs "OS9p3" - -* NEW CODE FOR BAD BOOT: - -Crash jmp <D.Crash reset vector - -*------------------------------------------------* -* Service Calls: -*------------------------------------------------* - -SysCalls fcb F$Unlink - fdb FUnlink-*-2 - fcb F$Fork - fdb FFork-*-2 - fcb F$Wait - fdb FWait-*-2 - fcb F$Chain - fdb FChain-*-2 - fcb F$Exit - fdb FExit-*-2 - fcb F$Mem - fdb FMem-*-2 - fcb F$Send - fdb FSend-*-2 - fcb F$Icpt - fdb FIcpt-*-2 - fcb F$Sleep - fdb FSleep-*-2 - fcb F$SPrior - fdb FSPrior-*-2 - fcb F$ID - fdb FID-*-2 - fcb F$SSWI - fdb FSSWI-*-2 - fcb F$STime - fdb FSTime-*-2 - fcb F$SchBit - fdb FSchBit-*-2 - fcb F$SchBit+$80 (sys) - fdb SSchBit-*-2 - fcb F$AllBit - fdb FAllBit-*-2 - fcb F$AllBit+$80 (sys) - fdb SAllBit-*-2 - fcb F$DelBit - fdb FDelBit-*-2 - fcb F$DelBit+$80 - fdb SDelBit-*-2 - fcb F$GPrDsc - fdb FGPrDsc-*-2 - fcb F$GBlkMp - fdb FGBlkMp-*-2 - fcb F$GModDr - fdb FGModDr-*-2 - fcb F$CpyMem - fdb FCpyMem-*-2 - fcb F$SUser - fdb FSUser-*-2 - fcb F$Unload - fdb FUnload-*-2 - fcb F$Find64+$80 - fdb FFind64-*-2 - fcb F$All64+$80 - fdb FAll64-*-2 - fcb F$Ret64+$80 - fdb FRet64-*-2 - fcb F$GProcP+$80 - fdb FGProcP-*-2 - fcb F$DelImg+$80 - fdb FDelImg-*-2 - fcb F$AllPrc+$80 - fdb FAllPrc-*-2 - fcb F$DelPrc+$80 - fdb FDelPrc-*-2 - fcb F$MapBlk - fdb FMapBlk-*-2 - fcb F$ClrBlk - fdb FClrBlk-*-2 - fcb F$DelRam - fdb FDelRam-*-2 - fcb F$GCMDir+$80 - fdb FGCMdir-*-2 - fcb F$IOMan - fdb IOCall-*-2 - fcb $80 End of Calls - -* Link to a Systm module -SysLink lda #Systm - os9 F$Link - rts - -*------------------------------------------------* -* The first I$Call will come here: - -IOMgrNam fcs "IOMan" - -IOCall pshs a,b,x,y,u - leax IOMgrNam,pcr - bsr SysLink try to find IOMan -* The following assumes os9p2 may be in the boot track and -* requires a call to F$Boot to get to IOMan. This is -* not the case for the CoCo 3. -* bcc L0121 ..okay -* os9 F$Boot else boot -* bcs L012B ..return err -* bsr SysLink try again - bcs L012B -L0121 jsr ,y initialize IOMan - puls a,b,x,y,u - ldx $00FE,y then do the call - jmp ,x - -*------------------------------------------------* -* Error, No IOMan: - -L012B stb 1,s return err code - puls a,b,x,y,u,pc - -*------------------------------------------------* -* F$Unlink -*------------------------------------------------* -FUnlink pshs a,b,u - ldd R$U,u D=module address - ldx R$U,u X=module address - lsra img block # = A/16 - lsra - lsra - lsra - lsra - sta ,s save usr map img num - beq L0183 ..ignore if zero - - ldu <D.Proc proc desc - leay P$DATImg,u map images - asla index by block# - ldd a,y D= DAT image number - ldu <D.BlkMap look it up - ldb d,u in the block map - bitb #ModBlock module in block? - beq L0183 ..no, okay - leau P$DATImg,y else see if done - bra L0161 with this block... - -L015D dec ,s at mod block? - beq L0183 ..yes, ignore. -L0161 ldb ,s usr block # - aslb index - ldd b,u D=real number - beq L015D skip if zero - - lda ,s else get usr blk # - asla *16 is module start - asla - asla - asla - asla - clrb B=00 - nega A=-A - leax d,x X=block begin - ldb ,s usr blk # - aslb index - ldd b,y D=img block - ldu <D.ModDir U=mod dir - bra L0185 ..check mods in block - -*------------------------------------------------* -* Check Block for Mods: - -L017C leau MD$ESize,u next entry - cmpu <D.ModEnd end of dir? - bcs L0185 ..no, try more -L0183 bra L01D0 ..yes,end. - -L0185 cmpx MD$MPtr,u is it dir entry? - bne L017C ..no, loop - cmpd [MD$MPDAT,u] image block same? - bne L017C ..no, loop - ldx MD$Link,u link count=0? - beq L0198 ..yes - leax -1,x else link-1 - stx MD$Link,u - bne L01B5 ..skip if not zero - -L0198 ldx 2,s X=reg stack - ldx R$U,x X=mod ptr - ldd #M$Type D=offset to type byte - os9 F$LDDDXY get module type/lang - cmpa #FlMgr is it mgr,driver, or desc? - bcs L01B3 ..no - os9 F$IODel yes, delete it properly - bcc L01B3 ..ok - ldx MD$Link,u else inc link count - leax 1,x - stx MD$Link,u - bra L01D1 ..bad end. - -L01B3 bsr L01D5 delete moddir entry -L01B5 ldb ,s block dat - aslb index - leay b,y Y=image ptr - ldx P$Links-P$DATImg,y link count - leax -1,x -1 - stx P$Links-P$DATImg,y - bne L01D0 ..skip if not zero - - ldd MD$MBSiz,u block size - bsr L0226 change to #blocks - ldx #DAT.Free free flag -L01CB stx ,y++ mark images free - deca - bne L01CB - -L01D0 clrb okay -L01D1 leas 2,s drop - puls u,pc end unlink. - -*------------------------------------------------* -* Clear ModDir Entry: - -L01D5 ldx <D.BlkMap X=ram map - ldd [MD$MPDAT,u] D=DAT img blk - lda d,x A=map marker - bmi L0225 ..bra if not ram - ldx <D.ModDir point to module dir - -L01DF ldd [MD$MPDAT,x] get block # - cmpd [MD$MPDAT,u] same as this? - bne L01EA ..no - - ldd MD$Link,x link cnt zero? - bne L0225 ..no -L01EA leax MD$ESize,x skip to next entry - cmpx <D.ModEnd last? - bcs L01DF ..no, keep looking - - ldx <D.BlkMap block map ptr - ldd MD$MBSiz,u module block size - bsr L0226 convert to #blocks - pshs y save y - ldy MD$MPDAT,u module image ptr -L01FB pshs a,x save #blocks, ptr - ldd ,y get block number - clr ,y+ clear the image - clr ,y+ - leax d,x point to blkmap entry - ldb ,x - andb #^(RAMinUse+ModBlock) free block - stb ,x - puls a,x - deca last block done? - bne L01FB ..no, loop - - puls y - ldx <D.ModDir module dir ptr - ldd MD$MPDAT,u image ptr - -L0216 cmpd ,x was module here? - bne L021F ..no - clr MD$MPDAT,x clear entry - clr MD$MPDAT+1,x -L021F leax MD$ESize,x next dir entry - cmpx <D.ModEnd last? - bcs L0216 ..no, keep looking - -L0225 rts end clear moddir entry. - -*------------------------------------------------* -* Convert BlockSize to #Blocks: - -L0226 addd #$1FFF round up - lsra - lsra - lsra - lsra - lsra - rts - -*------------------------------------------------* -* F$Fork -*------------------------------------------------* -FFork pshs u - lbsr L02EA get proc desc - bcc L0238 ..ok, fork - puls u,pc else err. - -*------------------------------------------------* -L0238 pshs u save child proc desc ptr - ldx <D.Proc get parent's - ldd P$User,x copy user index - std P$User,u - lda P$Prior,x priority & age - sta P$Prior,u - - pshs x,u save proc. desc. addresses - - leax P$NIO,x copy Net IO ptrs <NEW> - leau P$NIO,u <NEW> - ldb #NefIOSiz Net table size <NEW> - -L0250 lda ,x+ - sta ,u+ - decb - bne L0250 - - puls x,u recover proc. desc. addresses - leax P$DIO,x copy default data/exec dirs: - leau P$DIO,u - ldb #DefIOSiz -L0261 lda ,x+ - sta ,u+ - decb - bne L0261 - - ldy #3 - -* dup 1st 3 paths: - -L026C lda ,x+ - beq L0276 skip if not open - os9 I$Dup - bcc L0276 - clra - -* as std in/out/err: - -L0276 sta ,u+ - leay -1,y count-1 - bne L026C - - ldx ,s X=child proc desc - ldu 2,s U=caller regs - lbsr L04B1 link/load mod, set proc desc - bcs L02CF ..err - pshs a,b save size - os9 F$AllTsk get task# for child - bcs L02CF - -L028C lda P$PagCnt,x D=mem amt - clrb - subd ,s D-mod size - tfr d,u U=dest - ldb P$Task,x B=child task# for parm copy - ldx <D.Proc parent's proc desc - lda P$Task,x and task - leax ,y X=parameter ptr - puls y Y=count - os9 F$Move X(A)-->U(B) *Y copy over data - - ldx ,s copy over child's stack - lda <D.SysTsk - ldu P$SP,x - leax P$Stack-R$Size,x - ldy #R$Size - os9 F$Move X(A)-->U(B) *Y - - puls x,u - os9 F$DelTsk release child task# - ldy <D.Proc Y=parents proc desc - lda P$ID,x X=childs proc desc - sta R$A,u return it - ldb P$CID,y B=sibling - sta P$CID,y let parent have child - lda P$ID,y parents ID - std P$PID,x set child's parent/sibling - lda P$State,x - anda #^SysState take child out of sys - sta P$State,x state and - os9 F$AProc activate it - rts end. - -*------------------------------------------------* -* Error - couldn't link/load pgm: - -L02CF puls x bad proc desc - pshs b save error - lbsr L05A5 close paths & unlink mem - lda P$ID,x get bad id - lbsr L0386 delete proc desc & task# - comb set err - puls b,u,pc bad end. - -*------------------------------------------------* -* F$AllPrc -*------------------------------------------------* -FAllPrc pshs u save reg ptr - bsr L02EA allocate process desc - bcs L02E8 ..err - ldx ,s get reg ptr - stu R$U,x return proc desc ptr -L02E8 puls u,pc end. - -*------------------------------------------------* -* Allocate a Proc Desc: - -L02EA ldx <D.PrcDBT X=proc table -L02EC lda ,x+ search 'til empty - bne L02EC is found - - leax -1,x back up to it - tfr x,d D=addrss - subd <D.PrcDBT D=index - tsta >256? - beq L02FE ..no, ok - comb else - ldb #E$PrcFul 'Process Table Full' - bra L032F - -L02FE pshs b save index - ldd #P$Size get 512 bytes - os9 F$SRqMem for proc desc - puls a A=index - bcs L032F ..err - sta P$ID,u set proc ID - tfr u,d D=proc desc addrss - sta ,x set proc desc msb in table - - clra D=0000 - leax P$PID,u start after ID - ldy #$80 256 byte count -L0317 std ,x++ clear proc desc - leay -1,y - bne L0317 - - ldy <D.Proc get current proc desc address - ldx <D.SysPrc get system proc desc address - stx <D.Proc make system current proc - leax P$DatBeg,u new proc desc creation date/time tag - os9 F$Time ignore any error... - sty <D.Proc restore current proc desc address - - lda #SysState set system state - sta P$State,u - ldb #DAT.BlCt mark all blocks as unused - ldx #DAT.Free - leay P$DATImg,u in the proc images -L0329 stx ,y++ - decb - bne L0329 - clrb okay -L032F rts - -*------------------------------------------------* -* F$DelPrc -*------------------------------------------------* -FDelPrc lda R$A,u get proc id - bra L0386 delete it - -*------------------------------------------------* -* F$Wait -*------------------------------------------------* -FWait ldx <D.Proc proc desc - lda P$CID,x any children? - beq L0368 ..no, quick return - -L033A lbsr L0B2E find child proc desc - lda P$State,y - bita #Dead has it died? - bne L036C ..yes - lda P$SID,y else does it have sibling? - bne L033A ..yes, check it - - sta R$A,u return child's id - - sta R$B,U - - pshs cc save CC - orcc #IntMasks stop interrupts - - lda P$SIGNAL,X - beq N035D - deca - bne N035A - sta P$SIGNAL,X -N035A lbra L071B - -N035D ldd <D.WProcQ insert caller - std P$Queue,x into waiting proc - stx <D.WProcQ queue - puls cc restore CC - lbra L0780 and go wait. - -L0368 comb - ldb #E$NoChld 'No Child Error' - rts - -*------------------------------------------------* -L036C lda P$ID,y get child id - ldb P$Signal,y and its death signal - std R$A,u return to caller - leau ,y child proc desc - leay P$CID-P$SID,x - bra L037C go bury child - -*------------------------------------------------* -L0379 lbsr L0B2E find proc desc -L037C lda P$SID,y is sibling the link? - cmpa P$ID,u - bne L0379 ..no, try next - ldb P$SID,u link in other - stb P$SID,y siblings - -* Delete Proc Desc & Task#: - -L0386 pshs a,b,x,u - - cmpa WGlobal+G.AlPID is alarm call for this task? - bne NEWLABEL no .... - clr WGlobal+G.AlPID clear task # - clr WGlobal+G.AlSig clear signal - -NEWLABEL ldb ,s <NEW LABEL> - ldx <D.PrcDBT X=proc desc table - abx index task - lda ,x get pointer - beq L03AC ..quick ok if none - clrb else clear ptr - stb ,x - tfr d,x X=proc desc - os9 F$DelTsk release task flag - leau ,x U=proc desc - ldd #P$Size return 512 byte - os9 F$SRtMem proc desc mem -L03AC puls a,b,x,u,pc end. - -*------------------------------------------------* -* F$Chain -*------------------------------------------------* -FChain pshs u save U - lbsr L02EA allocate proc desc - bcc L03B7 ..go chain - puls u,pc - -*------------------------------------------------* -* Copy Proc Desc Data: - -L03B7 ldx <D.Proc save proc - pshs x,u - leax P$SP,x copy from P$SP--> - leau P$SP,u - ldy #$007E 252 byte count - -L03C3 ldd ,x++ copy bytes - std ,u++ - leay -1,y - bne L03C3 - - ldu 2,S get new proc desc address - leau P$DATImg,u point to DAT image - ldx ,S get old proc desc - lda P$Task,x get old task # - asla task # x2 is index - ldx <D.TskIPt point to DAT image table - stu A,X put image address into table - - ldx <D.Proc proc desc - clra D=0000 - clrb - stb P$Task,x set no task# - std P$SWI,x sys swi's - std P$SWI2,x - std P$SWI3,x - sta P$Signal,x no signal/vecs - std P$SigVec,x - ldu P$PModul,x unlink primary module - os9 F$Unlink - ldb P$PagCnt,x mem page count - addb #$1F round up - lsrb B/16 (pages-->blocks) - lsrb - lsrb - lsrb - lsrb - lda #DAT.BlCt max count=16 - pshs b -num used - suba ,s+ =number to release: - leay P$DATImg,x Y=images - aslb index - leay b,y first block - ldu #DAT.Free not used flag -L040C stu ,y++ clear proc images - deca - bne L040C - - ldu 2,s set new proc desc - stu <D.Proc - ldu P$SP,s - lbsr L04B1 link/load module - - bcs L04A1 ..err - - pshs a,b save size - os9 F$AllTsk get task# for new proc (if possible) - bcc L0425 - -*------------------------------------------------* -* Chain Error: - - leas 2,s dump parm size - -L04A1 - puls x,u - stx <D.Proc reset proc - pshs cc,b save error status/info - lda P$ID,u get temp proc id - lbsr L0386 and delete proc desc - puls cc,b recover error status/info - os9 F$Exit and exit gracefully - -L0425 ldu <D.Proc U=new proc - lda P$Task,u A=source tsk# - ldb P$Task,x B=dest tsk# - leau P$Stack-R$Size,x ($01F4) - leax ,y source ptr - ldu R$X,u dest ptr - pshs u source ptr > - cmpx ,s++ dest ptr? - puls y size - bhi L0471 ..yes - beq L0474 same place - leay ,y size=zero? - beq L0474 ..yes - - pshs a,b,x - tfr y,d size - leax d,x source end ptr - pshs u save dest - cmpx ,s++ source within dest? - puls a,b,x - bls L0471 ..no - - pshs a,b,x,y,u - tfr y,d size - leax d,x source end ptr - leau d,u dest end ptr - -* Copy Parms: - -L0457 ldb ,s source task# - leax -1,x back up fm end - os9 F$LDABX get byte - exg x,u src <--> dest - ldb 1,s task# - leax -1,x back up dest ptr - os9 F$STABX store byte - exg x,u - leay -1,y cnt-1 - bne L0457 - - puls a,b,x,y,u - bra L0474 - -*------------------------------------------------* -L0471 os9 F$Move X(A)-->U(B) *Y -L0474 lda <D.SysTsk from sys map - ldx ,s get proc desc - ldu P$SP,x and stack pointer - leax P$Stack-R$Size,x point to proc stack - ldy #R$Size stack count - os9 F$Move X(A)-->U(B) *Y copy from proc desc - puls x,u stack to user reg stack - lda P$ID,u get id - lbsr L0386 delete temp proc desc & free task# - os9 F$DelTsk delete task# - orcc #IntMasks halt interrupts - ldd <D.SysPrc set system as proc - std <D.Proc - lda P$State,x drop system state - anda #^SysState - sta P$State,x - os9 F$AProc insert in active queue - os9 F$NProc and start next process. -* NOTE: F$NProc will NOT return control to caller. -* This routine ends here, no error possible. - -*------------------------------------------------* -* Init New Proc Desc: -* Link or Load Primary Module: - -L04B1 pshs a,b,x,y,u - ldd <D.Proc proc desc - pshs a,b save it - stx <D.Proc temp proc - lda R$A,u type - ldx R$X,u name - ldy ,s new proc desc - leay P$DATImg,y Y=new images - os9 F$SLink link in primary mod - bcc L04D7 ..ok - - ldd ,s else restore old proc - std <D.Proc - ldu 4,s get new proc desc - os9 F$Load use sys f$load - bcc L04D7 ..ok - leas 4,s else drop junk - puls x,y,u,pc return err. - -*------------------------------------------------* -L04D7 stu 2,s save mod address - pshs a,y save mod type,entry - ldu $0B,s U=usr regs (old P$SP) - stx R$X,u update name ptr - ldx 7,s set new process desc - stx <D.Proc - ldd 5,s set primary module addrss - std P$PModul,x - puls a module type - cmpa #Prgrm+Objct is it program module? - beq L04FB ..yes - cmpa #Systm+Objct is it system module? - beq L04FB ..yes - - ldb #E$NEMod 'Non-Executable Module' -L04F4 leas 2,s drop return - stb 3,s return err code - comb set err - bra L053E restore proc desc & rts. - -*------------------------------------------------* -* Allocate data memory and set child regs: - -L04FB ldd #M$Mem offset to mem size - leay P$DATImg,x image - ldx P$PModul,x mod address - os9 F$LDDDXY get mem size - cmpa R$B,u greater than user request? - bcc L050E ..yes - lda R$B,u no, use request - clrb to page boundary -L050E os9 F$Mem get U=data memory - bcs L04F4 ..err - - ldx 6,s parent proc desc - leay P$Stack-R$Size,x - pshs a,b save mem size - subd R$Y,u -parm size - std R$X,y is new parm pointer - subd #R$Size memsize-reg stack - std P$SP,x is new stack pointer - - ldd R$Y,u get parm size - std R$D,y D is parm size - std 6,s return to caller - puls a,b,x mem and entry - std R$Y,y Y is end of data mem - ldd R$U,u parm ptr - std 6,s return - lda #Entire CC register is full rti - sta R$CC,y set cc reg - clra - sta R$DP,y DP is 00 - clrb - std R$U,y U is data address - stx R$PC,y PC is module exec address - -L053E puls a,b restore proc desc - std <D.Proc - puls a,b,x,y,u,pc return. - -*------------------------------------------------* -* F$Exit -*------------------------------------------------* -FExit ldx <D.Proc proc desc - bsr L05A5 close paths & return memory - ldb R$B,u get exit signal - stb P$Signal,x and save in proc desc - leay P$CID-P$SID,x parent id - bra L0563 go find kids... - -*------------------------------------------------* -L0551 clr P$SID,y clear sibling pointer - lbsr L0B2E find its proc desc - clr P$PID,y clear its parent ptr (us) - lda P$State,y get child's state - bita #Dead is it dead? - beq L0563 ..no - lda P$ID,y else get its id - lbsr L0386 and destroy its proc desc -L0563 lda P$SID,y did it have a sibling? - bne L0551 ..yes,loop - - leay ,x kid's proc desc - ldx #D.WProcQ-P$Queue - lds <D.SysStk use system stack - pshs cc save CC - orcc #IntMasks halt interrupts while queuing - lda P$PID,y get our parent id - bne L0584 ..and wake him up - - puls cc restore CC - lda P$ID,y our id - lbsr L0386 give up our proc desc - bra L05A2 and start next active process. - -*------------------------------------------------* -* Search For Waiting Parent: - -L0580 cmpa P$ID,x is proc desc our parent's? - beq L0592 ..yes! - -L0584 leau ,x U is base desc - ldx P$Queue,x X is next waiter - bne L0580 see if parent - puls cc restore CC - lda #SysState+Dead set us to system state - sta P$State,y and mark us as dead - bra L05A2 so F$Wait will find us; next proc. - -* Found Parent (X): - -L0592 ldd P$Queue,x take parent out of wait queue - std P$Queue,u - puls cc restore CC - ldu P$SP,x get parents reg stack - ldu R$U,u - lbsr L036C get child's death signal to parent - os9 F$AProc move parent to active queue -L05A2 os9 F$NProc start next proc in active queue. - -*------------------------------------------------* -* Close Proc I/O Paths & Unlink Mem: - -L05A5 pshs u save - ldb #NumPaths B=up to 16 paths - leay P$Path,x point to proc desc paths -L05AC lda ,y+ get path desc# - beq L05B9 ..skip if not used - clr -1,y else clr it - pshs b save cnt - os9 I$Close close path - puls b -L05B9 decb count-1 - bne L05AC ..loop - - clra begin block=00 - ldb P$PagCnt,x any memory used? - beq L05CB ..no - addb #$1F round up mem - lsrb mem/16 = blocks used - lsrb - lsrb - lsrb - lsrb - os9 F$DelImg return mem -L05CB ldd <D.Proc save current proc - pshs a,b - stx <D.Proc set bad proc - ldu P$PModul,x pgrm ptr - os9 F$Unlink unlink aborted pgrm - puls a,b,u - std <D.Proc reset parent proc - os9 F$DelTsk release X's task# - rts . - -*------------------------------------------------* -* F$Mem -*------------------------------------------------* -FMem ldx <D.Proc proc - ldd R$D,u get mem request - beq L0638 ..return current size request - addd #$00FF else round up size - bcc L05EE ..okay if <64K - ldb #E$MemFul 'Memory Full' - bra L0629 ..err end - -L05EE cmpa P$PagCnt,x same as current? - beq L0638 ..yes - pshs a save amt - bcc L0602 ..go for more mem - - deca go for less mem - ldb #$F4 enuf room for SP? - cmpd P$SP,x - bcc L0602 ..yes - ldb #E$DelSP 'Suicide Attempt' - bra L0627 - -L0602 lda P$PagCnt,x get current size - adda #$1F round up - lsra A/16 = block cnt - lsra - lsra - lsra - lsra - ldb ,s B=pages wanted - addb #$1F round up - bcc L0615 ..ok - ldb #E$MemFul 'Memory Full' - bra L0627 - -L0615 lsrb B/16 = blocks wanted - lsrb - lsrb - lsrb - lsrb - pshs a save #blocks now - subb ,s+ B=# difference - beq L0634 ..same - bcs L062C ..less - os9 F$AllImg else get mem - bcc L0634 ..err - -* Error ends: - -L0627 leas 1,s -L0629 orcc #Carry - rts - -*------------------------------------------------* -* Need Less Mem: - -L062C pshs b save amt less - adda ,s+ + amt now - negb - os9 F$DelImg return mem blocks -L0634 puls a get new amt - sta P$PagCnt,x set in proc desc - -* Return Mem Size to user: - -L0638 lda P$PagCnt,x D=byte count - clrb - std R$D,u return size - std R$Y,u and upper bound - rts - -*------------------------------------------------* -* F$Send -*------------------------------------------------* -FSend ldx <D.Proc proc desc - lda R$A,u A=dest proc - bne L0652 ..send if <> 00 - inca else send to all ('cept zero) -L0647 cmpa ,x our proc? - beq L064D ..skip if is - bsr L0652 else send signal -L064D inca ID+1 - bne L0647 done 255? - clrb yep - rts end. - -*------------------------------------------------* -* Send signal to Proc A: - -L0652 lbsr L0B2E find proc desc - pshs cc,a,y,u - bcs L066A ..not found - tst R$B,u is signal = zero? (Kill) - bne L066D ..no - ldd P$User,x are we superuser? - beq L066D ..yes - cmpd P$User,y else same user? - beq L066D ..yes - ldb #E$IPrcID 'Illegal Proc ID' - inc ,s set carry bit -L066A lbra L06F4 - -L066D orcc #IntMasks stop interrupts - ldb R$B,u B=signal - bne L067B skip if not Kill - - ldb #E$PrcAbt 'Keyboard Abort' (#2) - lda P$State,y - ora #Condem condemn process - sta P$State,y - -* Wake Up Dest Process: - -L067B lda P$State,y - anda #^Suspend (F7) drop suspend - sta P$State,y state - lda P$Signal,y have signal now? - beq L068F ..no - deca else was it wake? - beq L068F ..yes - inc ,s set carry - ldb #E$USigP 'Signal Error' - bra L06F4 - -L068F stb P$Signal,y save signal - ldx #D.SProcQ-P$Queue search sleep queue - clra ticks left=0000 - clrb - -L0697 leay ,x Y is base desc - ldx P$Queue,x X is next qproc - beq L06D3 ..last - ldu P$SP,x else get process - addd R$X,u add ticks - cmpx 2,s same as dest proc desc? - bne L0697 ..no, loop - - pshs a,b save tick count - lda P$State,x is process time sleeping? - bita #TimSleep - beq L06CF ..no it's not - - ldd ,s get tick count - beq L06CF ..bra if none - ldd R$X,u get time left - pshs a,b save it - ldd 2,s get ticks left - std R$X,u make it new time left - puls a,b tick count - ldu P$Queue,x qproc after this one? - beq L06CF ..no - std ,s - lda P$State,u time sleeping? - bita #TimSleep - beq L06CF ..no its not - - ldu P$SP,u next proc SP - ldd ,s update tick count - addd R$X,u - std R$X,u - -L06CF leas 2,s drop - bra L06E0 give signal... - -*------------------------------------------------* -L06D3 ldx #D.WProcQ-P$Queue search wait queue -L06D6 leay ,x base proc desc - ldx P$Queue,x get next in queue - beq L06F4 ..end if none - cmpx 2,s signal dest proc? - bne L06D6 ..no - -L06E0 ldd P$Queue,x take proc out of queue - std P$Queue,y - lda P$Signal,x has signal - deca other than S$Wake? - bne L06F1 ..yes - sta P$Signal,x no, clear for wakeup - lda ,s restore CC - tfr a,cc -L06F1 os9 F$AProc insert proc in active queue -L06F4 puls cc,a,y,u,pc return. - -*------------------------------------------------* -* F$Icpt -*------------------------------------------------* -FIcpt ldx <D.Proc proc desc - ldd R$X,u set signal vector - std P$SigVec,x - ldd R$U,u and data area - std P$SigDat,x - clrb ok - rts end. - -*------------------------------------------------* -* F$Sleep -*------------------------------------------------* -FSleep pshs cc save int masks - ldx <D.Proc proc desc - orcc #IntMasks stop interrupts here - lda P$Signal,x have unprocessed signal? - beq L0722 ..no - deca yes, was it Wake? - bne L0715 ..no - sta P$Signal,x yes, ignore it - -L0715 lda P$STATE,X - anda #^SUSPEND DROP SUSPEND - sta P$STATE,X - -L071B puls cc restore CC - os9 F$AProc activate immediately - bra L0780 - -* Do the Sleep: - -L0722 ldd R$X,u sleep forever? - beq L076D ..yes - subd #$0001 else -1 already - std R$X,u save tick cnt - - beq L071B ..awake if was just 1 - pshs x,y save - ldx #D.SProcQ-P$Queue - -L0732 std R$X,u return tick count - stx 2,s temp var - ldx P$Queue,x X=next queue proc - beq L074F ..end of line - lda P$State,x is it still - bita #TimSleep asleep? - beq L074F ..no - ldy P$SP,x yes, get its - ldd R$X,u X register and - subd R$X,y compare to ours - bcc L0732 ..try next if we're more - - nega else negate count - negb - sbca #$00 - std R$X,y and update proc sleep ticks -L074F puls x,y queue proc ptrs - lda P$State,x set proc as - ora #TimSleep tick sleeping - sta P$State,x - ldd P$Queue,y insert us in queue - stx P$Queue,y - std P$Queue,x - ldx R$X,u get ticks requested - bsr L0780 go wait for wakeup - - stx R$X,u return ticks left - ldx <D.Proc - lda P$State,x drop sleep flag - anda #^TimSleep - sta P$State,x - puls cc,pc return to caller. - -*------------------------------------------------* -L076D ldx #D.SProcQ-P$Queue start at first asleep - -L0770 leay ,x Y is base proc - ldx P$Queue,x X is next qproc - bne L0770 ..not last yet - ldx <D.Proc else get our proc - clra D=0000 - clrb - stx P$Queue,y put us at end of queue - std P$Queue,x and mark none after us now - puls cc restore CC - -*------------------------------------------------* -* Wait for Signal/Wakeup: - -L0780 pshs x,y,u,pc make vars - leax <L079C,pcr point to wakeup code - stx 6,s put as rts pcr - ldx <D.Proc - ldb P$Task,x are we sys proc? - cmpb <D.SysTsk - beq L0792 ..yes - os9 F$DelTsk else release task# -L0792 ldd P$SP,x save stack pointer - pshs cc,a,b,dp - sts P$SP,x and temp SP - os9 F$NProc go do next proc. - -*------------------------------------------------* -* Proc Wakes up here: - -L079C pshs x save tick count - ldx <D.Proc - std P$SP,x restore real SP - clrb ok - puls x,pc return from sleep. - -*------------------------------------------------* -* F$SPrior -*------------------------------------------------* -FSprior lda R$A,u get id - lbsr L0B2E find proc desc - bcs L07C0 ..err - ldx <D.Proc get our user index - ldd P$User,x - beq L07B7 ..zero is ok - cmpd P$User,y same as id? - bne L07BD ..no, err -L07B7 lda R$B,u get desired priority - sta P$Prior,y set it in id - clrb ok - rts end. - -L07BD comb - ldb #E$IPrcID 'Illegal Process ID' -L07C0 rts - -*------------------------------------------------* -* F$ID -*------------------------------------------------* -FID ldx <D.Proc proc desc - lda P$ID,x get id - sta R$A,u return it - ldd P$User,x and user - std R$Y,u index to caller - clrb ok - rts end. - -*------------------------------------------------* -* F$SSWI -*------------------------------------------------* -FSSWI ldx <D.Proc proc desc - leay P$SWI,x point to SWI vectors - ldb R$A,u B=swi to set - decb B-1 - cmpb #$03 0-2? - bcc L07DF ..no, err - aslb else index - ldx R$X,u get new vector - stx b,y and set it - rts end. - -L07DF comb - ldb #E$ISWI 'Illegal SWI code' - rts - -*------------------------------------------------* -* F$STime -*------------------------------------------------* -ClockNam fcs "Clock" - -FSTime ldx R$X,u X=time packet - tfr dp,a A=DP - ldb #D.Time B=sys time addrss - tfr d,u U=sys time location - ldy <D.Proc - lda P$Task,y A=from tsk# - ldb <D.SysTsk B=to (sys) tsk# - ldy #$0006 copy over time data - os9 F$Move X(A)-->U(B) *Y - ldx <D.Proc save user proc - pshs x - ldx <D.SysPrc make sys for link - stx <D.Proc - leax ClockNam,pcr link to Clock - lbsr SysLink - puls x - stx <D.Proc restore user proc - bcs L0816 ..err end - jmp ,y else go do Clock init. - -L0816 rts - -*------------------------------------------------* -* F$AllBit -*------------------------------------------------* -FAllBit ldd R$D,u number of first bit - ldx R$X,u map address - bsr L086E get X=addrss, A=mask - ldy <D.Proc proc desc - ldb P$Task,y use usr map - bra L082C - -SAllBit ldd R$D,u number of first bit - ldx R$X,u map address - bsr L086E get X=addrss, A=mask - ldb <D.SysTsk use sys map - -L082C ldy R$Y,u Y=number of bits - beq L086C ..none - sta ,-s save mask - bmi L0847 skip if no bit0 - os9 F$LDABX get map byte -L0838 ora ,s set bit - leay -1,y count-1 - beq L0867 ..quik end if last - lsr ,s next bit - bcc L0838 ..loop if not bit7 - - os9 F$STABX else store map byte - leax 1,x map addrss+1 - -L0847 lda #$FF now quik set byte at a time - bra L0852 - -*------------------------------------------------* -* Byte at a Time: - -L084B os9 F$STABX store map byte - leax 1,x map addrss+1 - leay -8,y bit count-8/byte - -L0852 cmpy #$0008 under 8 bits to go? - bhi L084B ..no, continue byte at a time - beq L0867 ..exactly one byte left - -* Last byte: - -L085A lsra move mask into pos - leay -1,y for last byte - bne L085A .. - - coma fix mask - sta ,s save it - os9 F$LDABX get last map byte - ora ,s set last bits -L0867 os9 F$STABX update last map byte - leas 1,s drop mask -L086C clrb okay - rts return. - -*------------------------------------------------* -L086E pshs b,y save regs & low order 0-7 - lsra - rorb D/8 - lsra - rorb - lsra - rorb - leax d,x X=byte address - puls b B=low order - leay <L0883,pcr table of A shifted - andb #$07 B=bit count - lda b,y get mask for A - puls y,pc return. - -*------------------------------------------------* -* Mask Table: - -L0883 fcb $80 - fcb $40 - fcb $20 - fcb $10 - fcb $08 - fcb $04 - fcb $02 - fcb $01 - -*------------------------------------------------* -* F$DelBit -*------------------------------------------------* -FDelBit ldd R$A,u - ldx R$X,u - bsr L086E - ldy <D.Proc - ldb P$Task,y - bra L08A0 - -SDelBit ldd R$A,u - ldx R$X,u - bsr L086E - ldb <D.SysTsk - -L08A0 ldy R$Y,u - beq L08E0 - coma - sta ,-s - bpl L08BC - os9 F$LDABX -L08AD anda ,s - leay -1,y - beq L08DB - asr ,s - bcs L08AD - os9 F$STABX - leax 1,x -L08BC clra - bra L08C6 - -*------------------------------------------------* -L08BF os9 F$STABX - leax 1,x - leay -8,y -L08C6 cmpy #8 - bhi L08BF - beq L08DB - coma -L08CF lsra - leay -1,y - bne L08CF - sta ,s - os9 F$LDABX - anda ,s -L08DB os9 F$STABX - leas 1,s -L08E0 clrb - rts - -*------------------------------------------------* -* F$SchBit -*------------------------------------------------* -FSchBit ldd R$D,u search start bit # - ldx R$X,u map address - bsr L086E set byte mask - ldy <D.Proc use user map - ldb P$Task,y - bra L08F8 do it - -SSchBit ldd R$D,u search start bit # - ldx R$X,u map address - lbsr L086E set byte mask - ldb <D.SysTsk use sys map - -L08F8 pshs cc,a,b,x,y,u - clra D=0000 - clrb - std 3,s - ldy R$D,u - sty 7,s - bra L0911 - -*------------------------------------------------* -L0906 sty 7,s -L0909 lsr 1,s - bcc L091C - ror 1,s - leax 1,x -L0911 cmpx R$U,u end of map? - bcc L093A ..yes - ldb 2,s - os9 F$LDABX - sta ,s -L091C leay 1,y - lda ,s - anda 1,s - bne L0906 - - tfr y,d - subd 7,s - cmpd R$Y,u - bcc L0943 - cmpd 3,s - bls L0909 - std 3,s - ldd 7,s - std 5,s - bra L0909 - -L093A ldd 3,s - std R$Y,u - comb - ldd 5,s - bra L0945 - -L0943 ldd 7,s -L0945 std R$D,u - leas 9,s - rts - -*------------------------------------------------* -* F$GPrDsc -*------------------------------------------------* -FGprDsc ldx <D.Proc proc desc - ldb P$Task,x B=dest task# - lda R$A,u A=desired ID - os9 F$GProcP get B=ptr to proc desc - bcs L0962 - lda <D.SysTsk A=from tsk# - leax ,y X=proc desc - ldy #P$Size 512 bytes - ldu R$X,u U=dest buffer - os9 F$Move X(A)-->U(B) *Y -L0962 rts end. - -*------------------------------------------------* -* F$GBlkMp -*------------------------------------------------* -FGblkMp ldd #$2000 RETURN 8K BLOCK SIZE - std R$D,u - ldd <D.BlkMap+2 return blk map size - subd <D.BlkMap - std R$Y,u - tfr d,y Y=count - lda <D.SysTsk A=from sys - ldx <D.Proc - ldb P$Task,x B=to user - ldx <D.BlkMap X=block map - ldu R$X,u U=dest buffer - os9 F$Move X(A)-->U(B) *Y - rts - -*------------------------------------------------* -* F$GModDr -*------------------------------------------------* -FGModDr ldd <D.ModDir+2 D=end of moddir - subd <D.ModDir -begin - tfr d,y Y=size - ldd <D.ModEnd D=top of dir stack - subd <D.ModDir D=size - ldx R$X,u X=dest buffer - leax d,x plus size - stx R$Y,u return size to user - ldx <D.ModDir and moddir - stx R$U,u address - - lda <D.SysTsk A=sys task - ldx <D.Proc B=usr task - ldb P$Task,x - ldx <D.ModDir X=moddir - ldu R$X,u U=dest buffer - os9 F$Move X(A)-->U(B) *Y - rts end. - -*------------------------------------------------* -* F$SUser -*------------------------------------------------* -FSUser ldx <D.Proc proc desc - ldd R$Y,u D=user num - std P$User,x set it - clrb ok - rts end. - -*------------------------------------------------* -* F$CpyMem -*------------------------------------------------* -FCpyMem ldd R$Y,u byte count - beq L0A01 ..skip if none - addd R$U,u plus dest buff - bcs L0A01 - leas -$10,s - leay ,s - pshs a,b,y save buff end,img ptr - ldx <D.Proc - ldb P$Task,X - pshs b save caller task# - leay P$DATImg,x - ldx R$D,u X=caller DAT img ptr - ldb #8 - pshs b,u - ldu P$Task,s U=tempdat ptr - -L09C7 clra D=0000 - clrb - os9 F$LDDDXY move user DAT image - std ,u++ to sys tempDAT img - leax 2,x - dec ,s - bne L09C7 ..loop - - puls b,u - ldx R$X,u X=offset - ldu R$U,u U=dest buffer - ldy 3,s Y=tmpDAT - - puls b - bra L09E7 - -N09D6 leax $E000,x - leay 2,y - -*------------------------------------------------* -* Copy Loop: - -L09E7 cmpx #$2000 - bcc N09D6 - -L09EC os9 F$LDAXY get byte - leax 1,x - exg x,u - - os9 F$STABX store byte - leax 1,x plus one - cmpx ,s - exg x,u - bcs L09E7 - leas $14,s - -L0A01 clrb ok - rts end. - -*------------------------------------------------* -* F$UnLoad -*------------------------------------------------* -FUnload pshs u - lda R$A,u A=type - ldx <D.Proc proc desc - leay P$DATImg,x images ptr - ldx R$X,u X=name - os9 F$FModul find the module - puls y reg stack - bcs L0A4F ..err - - stx R$X,y update name ptr - ldx MD$Link,u get module link cnt - beq L0A21 ..zero - leax -1,x else decrement it - stx MD$Link,u - bne L0A4E ..skip if still in use - -L0A21 cmpa #FlMgr system module? - bcs L0A4B ..no - - clra - ldx [MD$MPDAT,u] get module block - ldy <D.SysDAT check against sys map -L0A2B adda #$02 next offset - cmpa #DAT.ImSz last? - bcc L0A4B ..yes - cmpx a,y else found right img? - bne L0A2B ..no, loop - - asla A/8 block# -->address - asla - asla - asla - clrb - addd MD$MPtr,u point to module - tfr d,x - os9 F$IODel delete I/O module - bcc L0A4B ..ok - - ldx MD$Link,u else if error, - leax 1,x - stx MD$Link,u increment link cnt - bra L0A4F - -L0A4B lbsr L01D5 clear moddir entry -L0A4E clrb ok -L0A4F rts end. - -*------------------------------------------------* -* F$Find64 -*------------------------------------------------* -FFind64 lda R$A,u get pd block number - ldx R$X,u get block address - bsr L0A5C find it - bcs L0A5B ..err - sty R$Y,u return address -L0A5B rts end. - -* Find Path/Process Descriptor: - -L0A5C pshs a,b save number, make space - tsta number=zero? - beq L0A70 ..yes,bad - clrb else... - lsra number/4 - rorb (point to block ptr) - lsra - rorb - lda a,x use index to get - tfr d,y block address - beq L0A70 ..none - tst ,y is block in use? - bne L0A71 ..yes, okay! -L0A70 coma set error -L0A71 puls a,b,pc return. - -*------------------------------------------------* -* F$All64 -*------------------------------------------------* -FAll64 ldx R$X,u get base page - bne L0A7F ..okay if have one - bsr L0A89 else allocate page - bcs L0A88 ..err - stx ,x insert first page flag - stx R$X,u return base page -L0A7F bsr L0A9F get one 64-byte block - bcs L0A88 ..err - sta R$A,u return block number - sty R$Y,u return block address -L0A88 rts end. - -*------------------------------------------------* -* Allocate Base Block: - -L0A89 pshs u save U - ldd #$0100 get 256-byte page - os9 F$SRqMem - leax ,u X=page address - puls u - bcs L0A9E ..err - clra A=00 - clrb 256 byte count -L0A99 sta d,x clear block - incb - bne L0A99 -L0A9E rts - -*------------------------------------------------* -* Find & Set Block In Use: - -L0A9F pshs x,u - clra -L0AA2 pshs a - clrb - lda a,x - beq L0AB4 - tfr d,y - clra -L0AAC tst d,y - beq L0AB6 - addb #64 - bcc L0AAC -L0AB4 orcc #Carry -L0AB6 leay d,y - puls a - bcc L0AE1 - inca try all pages - cmpa #64 until 64th page - bcs L0AA2 - - clra -L0AC2 tst a,x - beq L0AD0 - inca - cmpa #64 - bcs L0AC2 - - comb - ldb #E$PthFul 'Path Table Full' - bra L0AEE - -*------------------------------------------------* -L0AD0 pshs a,x - bsr L0A89 - bcs L0AF0 - leay ,x - tfr x,d - tfr a,b - puls a,x - stb a,x - clrb - -* D=Block Address: - -L0AE1 aslb - rola - aslb - rola - - ldb #$3F - -* Clear Block: - -L0AE7 clr b,y - decb - bne L0AE7 - sta ,y -L0AEE puls x,u,pc okay rts. - -L0AF0 leas 3,s drop vars - puls x,u,pc return. - -*------------------------------------------------* -* F$Ret64 -*------------------------------------------------* -FRet64 lda R$A,u - ldx R$X,u - pshs a,b,x,y,u - clrb - tsta - beq L0B22 - lsra - rorb - lsra - rorb - pshs a - lda a,x - beq L0B20 - tfr d,y - clr ,y - clrb - tfr d,u - clra -L0B10 tst d,u - bne L0B20 - addb #64 - bne L0B10 - inca - os9 F$SRtMem - lda ,s - clr a,x -L0B20 clr ,s+ -L0B22 puls a,b,x,y,u,pc - -*------------------------------------------------* -* F$GProcP -*------------------------------------------------* -FGProcP lda R$A,u get id - bsr L0B2E find proc esc - bcs L0B2D ..err - sty R$Y,u return pointer -L0B2D rts end. - -*------------------------------------------------* -* Find Process Descriptor A, address --> Y: - -L0B2E pshs a,b,x save id, etc - ldb ,s B=id - beq L0B40 ..can't be zero - ldx <D.PrcDBT proc desc table - abx index - lda ,x get pointer - beq L0B40 ..err if none by that id - clrb else make address - tfr d,y return in Y - puls a,b,x,pc end. - -L0B40 puls a,b,x - comb - ldb #E$IPrcId - rts - -*------------------------------------------------* -* F$DelImg -*------------------------------------------------* -FDelImg ldx R$X,u X=proc desc - ldd R$D,u A=start, B=count - leau P$DATImg,x U=image table - asla index first - leau a,u point to it - clra - tfr d,y Y=count - pshs x save desc - -L0B55 ldd 0,u D=block number - addd <D.BlkMap plus map begin - tfr d,x X=map address - lda ,x get marker - anda #^RAMinUse release mem - sta ,x - ldd #DAT.Free flag image - std ,u++ as free - leay -1,y count-1 - bne L0B55 ..loop - - puls x proc desc - lda P$State,x - ora #ImgChg flag image change - sta P$State,x - clrb okay - rts end. - -*------------------------------------------------* -* F$MapBlk -*------------------------------------------------* -FMapBlk lda R$B,u get number of blocks - - beq L0BAA <NEW> - - cmpa #DAT.BlCt over 16? (8 ON COCO) - bhi L0BAA ..err WAS BCC - - leas -$10,s - ldx R$X,u beginning block# desired - leay ,s point to local vars - ldb #1 ++BGP -L0B82 stx ,y++ put images -* leax 1,x desired on - abx ++BGP - deca the local stack - bne L0B82 - - ldb R$B,u number of blocks - ldx <D.Proc point to process's - leay P$DATImg,x image map - os9 F$FreeHB find contiguous blocks free - bcs L0BA6 ..err - pshs a,b save begin free#,amt - asla first free*16 = mem address - asla - asla - asla - asla - clrb - std R$U,u return addrss of first block - puls a,b drop - leau ,s point to images wanted - os9 F$SetImg map them into callers space -L0BA6 leas $10,S - rts return. - -L0BAA comb set err - ldb #E$IBA 'Illegal Block Address' - rts return. - -*------------------------------------------------* -* F$ClrBlk -*------------------------------------------------* -FClrBlk ldb R$B,u B=block count - beq L0BE9 ..zero - ldd R$U,u D=first block addrss - tstb - bne L0BAA ..must be even page - bita #$1F - bne L0BAA ..and on 4k boundary - ldx <D.Proc get proc desc - lda P$SP,x and it's SP - anda #$E0 - suba R$U,u -mem - bcs L0BCE ..err if sp mem - lsra address -> block# - lsra - lsra - lsra - lsra - cmpa R$B,u end of mem? - bcs L0BAA ..error -L0BCE lda P$State,x mark image change - ora #ImgChg - sta P$State,x - lda R$U,u get mem ptr - lsra index as image ptr - lsra - lsra - lsra - leay P$DATImg,x proc images - leay a,y point to block image - ldb R$B,u get block count - ldx #DAT.Free free flag -L0BE4 stx ,y++ clear image(s) - decb - bne L0BE4 -L0BE9 clrb okay - rts end. - -*------------------------------------------------* -* F$DelRam -*------------------------------------------------* -FDelRam ldb R$B,u get block count - beq L0C11 ..zero - ldd <D.BlkMap+2 end of block map - subd <D.BlkMap D=max block# - subd R$X,u cmp to desired block# - bls L0C11 ..bad number - - tsta close to end of map? - bne L0C00 ..no - cmpb R$B,u block cnt easy? - bcc L0C00 ..no - stb R$B,u save block cnt lsb -L0C00 ldx <D.BlkMap point to block map - ldd R$X,u get start block# - leax d,x index into map - ldb R$B,u get count -L0C08 lda ,x get block flag - anda #^RAMinUse release for use - sta ,x+ - decb count-1 - bne L0C08 ..'til done. - -L0C11 clrb okay - rts end. - -*------------------------------------------------* -* F$GCMDir -*------------------------------------------------* -FGCMDir ldx <D.ModDir module dir ptr - bra L0C1D ..do garbage collect - -L0C17 ldu ,x get DAT entry - beq L0C23 ..empty - leax MD$ESize,x else point to next - -L0C1D cmpx <D.ModEnd end of dir? - bne L0C17 ..no, loop - bra L0C4B yes, do it - -L0C23 tfr x,y Y=entry - bra L0C2B ..do it - -L0C27 ldu ,y get DAT entry - bne L0C34 ..in use -L0C2B leay MD$ESize,y point to next entry - cmpy <D.ModEnd last? - bne L0C27 ..no - bra L0C49 do it. - -* Move Entries Up: - -L0C34 ldu ,y++ 2 - stu ,x++ - ldu ,y++ 4 - stu ,x++ - ldu ,y++ 6 - stu ,x++ - ldu ,y++ 8 bytes - stu ,x++ - cmpy <D.ModEnd end of dir? - bne L0C27 ..no - -L0C49 stx <D.ModEnd set new dir end -L0C4B ldx <D.ModDir+2 end of dir - bra L0C53 - -L0C4F ldu ,x get entry - beq L0C5B ..not used -L0C53 leax -2,x back up in entry - cmpx <D.ModDAT end? - bne L0C4F ..no - bra L0C93 else end if all done. - -L0C5B ldu -2,x - bne L0C53 - tfr x,y - bra L0C67 - -L0C63 ldu ,y get entry - bne L0C70 -L0C67 leay -2,y -L0C69 cmpy <D.ModDAT - bcc L0C63 - bra L0C81 - -L0C70 leay 2,y go back - ldu ,y do last entry - stu ,x -L0C76 ldu ,--y - stu ,--x - beq L0C87 - cmpy <D.ModDAT end? - bne L0C76 ..no -L0C81 - stx <D.ModDAT set new end - bsr L0C95 change images - bra L0C93 end. - -L0C87 leay 2,y - leax 2,x - bsr L0C95 - leay -4,y - leax -2,x - bra L0C69 -L0C93 clrb okay - rts end. - -*------------------------------------------------* -* Update Module Dir Image Ptrs: - -L0C95 pshs u - ldu <D.ModDir module dir start - bra L0CA4 - -L0C9B cmpy MD$MPDAT,u same DAT ptrs? - bne L0CA2 ..no, skip - stx MD$MPDAT,u else update ptr -L0CA2 leau MD$ESize,u next entry -L0CA4 cmpu <D.ModEnd last entry? - bne L0C9B ..no - puls u,pc yes, return. - - emod -endmod equ * - end -