mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-22 00:32:44 +00:00
587 lines
11 KiB
Plaintext
587 lines
11 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
.OP 65C02
|
||
*--------------------------------------
|
||
* S.TskMgrInit
|
||
*--------------------------------------
|
||
S.TskMgrInit stz TSKMGR.LASTID
|
||
lda #1
|
||
sta TSKMGR.SIZE One Slot Busy (Kernel PS=0)
|
||
|
||
>LDYAI TskMgr.Table Make PS #0 as current process
|
||
>STYA pPs
|
||
|
||
ldx #K.PS.MAX
|
||
|
||
.1 lda #0
|
||
ldy #S.PS.SIZE-1
|
||
|
||
.2 sta (pPs),y
|
||
dey
|
||
bpl .2
|
||
|
||
lda pPs
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta pPs
|
||
bcc .3
|
||
|
||
inc pPs+1
|
||
.3 dex
|
||
bne .1
|
||
|
||
>LDYAI TskMgr.Table Make PS #0 as current process
|
||
>STYA pPs
|
||
|
||
jsr S.CreateEnv
|
||
bcs *
|
||
|
||
ldy #S.PS.hENV
|
||
sta TskMgr.Table,y
|
||
|
||
>LDYAI TmpBuffer256
|
||
jsr S.MLIGetPrefixYA
|
||
bcs *
|
||
|
||
>LDYAI TmpBuffer256
|
||
jsr S.NewPStrYA
|
||
bcs *
|
||
|
||
ldy #S.PS.hPREFIX
|
||
sta TskMgr.Table,y
|
||
>PUSHWI TmpBuffer256 push ENV value
|
||
>PUSHWI ENV.A2osX push ENV name
|
||
ldy #S.PS.hENV
|
||
lda TskMgr.Table,y
|
||
>PUSHA
|
||
jsr S.SetEnvVarP
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
* S.TskMgrRun
|
||
*--------------------------------------
|
||
S.TskMgrRun >LDYAI TskMgr.Table+S.PS.SIZE
|
||
>STYA pPs
|
||
|
||
lda #1 Skip PS #0
|
||
sta TSKMGR.COUNT
|
||
|
||
.1 lda (pPs) get S.PS.F
|
||
and #S.PS.F.INUSE In use ?
|
||
beq .5
|
||
|
||
lda (pPs) get S.PS.F
|
||
and #S.PS.F.HOLD Waiting for Another Task to Terminate?
|
||
beq .2
|
||
|
||
ldy #S.PS.CID
|
||
lda (pPs),y
|
||
jsr S.GetPSByIDA
|
||
bcc .5 yes, running....
|
||
|
||
lda (pPs) get S.PS.F
|
||
and #$FF^S.PS.F.HOLD unmark as HOLD
|
||
sta (pPs)
|
||
|
||
.2 jsr S.SelectProcess
|
||
|
||
ldy #S.PS.PC+1 Is this PS sleeping?
|
||
lda (pPs),y
|
||
tax
|
||
dey
|
||
ora (pPs),y
|
||
beq .3 no, call TSKMGR.RUN
|
||
|
||
lda (pPs),y
|
||
clc
|
||
adc pCode
|
||
sta S.TskMgrRunJmp+1
|
||
txa
|
||
adc pCode+1
|
||
sta S.TskMgrRunJmp+2
|
||
|
||
lda #0 Don't forget to reset S.PC
|
||
ldy #S.PS.PC
|
||
sta (pPs),y
|
||
iny
|
||
sta (pPs),y
|
||
|
||
jsr S.TskMgrRunJmp
|
||
bra .4
|
||
|
||
.3 ldx #TSKMGR.RUN
|
||
jsr pCodeJmp Call RUN function
|
||
.4 bcc .5 RUN said CS=QUIT?
|
||
|
||
ldx #TSKMGR.QUIT yes, quit this process
|
||
jsr pCodeJmp Call QUIT function
|
||
|
||
ldy #S.PS.ID
|
||
lda (pPs),y
|
||
jsr S.FreeProcessA
|
||
bcs .99
|
||
|
||
.5 lda pPs
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta pPs
|
||
bcc .6
|
||
inc pPs+1
|
||
|
||
.6 lda TSKMGR.COUNT
|
||
inc TSKMGR.COUNT
|
||
cmp TSKMGR.SIZE
|
||
bne .1
|
||
clc
|
||
rts
|
||
|
||
.99 bra *
|
||
*--------------------------------------
|
||
S.TskMgrRunJmp jmp $FFFF
|
||
*--------------------------------------
|
||
* S.DispatchEvent
|
||
* IN:
|
||
* OUT:
|
||
* CS: Not Dispatched
|
||
* CC: Event Cleared
|
||
*--------------------------------------
|
||
S.DispatchEvent >LDYAI TskMgr.Table+S.PS.SIZE
|
||
>STYA pPs
|
||
|
||
lda #1
|
||
sta TSKMGR.COUNT
|
||
|
||
.1 lda (pPs) get S.PS.F
|
||
and #S.PS.F.INUSE In use ?
|
||
beq .3
|
||
|
||
lda (pPs) get S.PS.F
|
||
and #S.PS.F.HOLD Waiting for Another Task to Terminate?
|
||
bne .3
|
||
|
||
lda (pPs) get S.PS.F
|
||
and #S.PS.F.EVENT Accept Events ?
|
||
beq .3
|
||
|
||
jsr S.SelectProcess
|
||
|
||
ldx #TSKMGR.DOEVENT
|
||
jsr pCodeJmp Call DOEVENT function
|
||
bcc .8
|
||
|
||
.3 lda pPs
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta pPs
|
||
bcc .4
|
||
inc pPs+1
|
||
|
||
.4 lda TSKMGR.COUNT
|
||
inc TSKMGR.COUNT
|
||
cmp TSKMGR.SIZE
|
||
bne .1
|
||
sec
|
||
rts
|
||
|
||
.8 jsr S.DestroyEvent
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
* S.TskMgrQuit
|
||
*--------------------------------------
|
||
S.TskMgrQuit clc
|
||
rts
|
||
*--------------------------------------
|
||
* PUBLIC
|
||
*--------------------------------------
|
||
* S.ExecProcessA (Blocking Parent PID)
|
||
* in :
|
||
* A = hMem To Cmd Line
|
||
* out :
|
||
* A = Child PSID
|
||
*--------------------------------------
|
||
S.ExecProcessA jsr S.CreateProcessA
|
||
bcs .9 terminated, do not set PID as HOLD
|
||
|
||
ldy #S.PS.CID
|
||
sta (pPs),y
|
||
|
||
pha Save Child PID
|
||
lda (pPs)
|
||
ora #S.PS.F.HOLD
|
||
sta (pPs)
|
||
pla Get Back PID
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
* S.CreateProcessA (Non Blocking)
|
||
* in :
|
||
* A = hMem To Full Cmd Line
|
||
* out :
|
||
* A = Child PSID
|
||
*--------------------------------------
|
||
S.CreateProcessA
|
||
sta S.CreateProcessA.Cmd
|
||
>LDYAI MSG.NEWPS
|
||
jsr S.SysScrPPSTRYA
|
||
|
||
jsr S.CreateChildProcess
|
||
bcs .99
|
||
|
||
sta S.CreateProcessA.CPSID
|
||
|
||
jsr S.SelectProcessA
|
||
|
||
lda S.CreateProcessA.Cmd
|
||
jsr S.InitProcessA
|
||
bcs .98 Init Failed or exit?
|
||
|
||
ldy #S.PS.PID switch back to Parent Process
|
||
lda (pPs),y
|
||
|
||
jsr S.SelectProcessA
|
||
|
||
lda S.CreateProcessA.CPSID
|
||
clc
|
||
rts
|
||
|
||
.98 pha save error code
|
||
|
||
ldy #S.PS.PID switch back to Parent Process
|
||
lda (pPs),y
|
||
jsr S.SelectProcessA
|
||
|
||
lda S.CreateProcessA.CPSID
|
||
jsr S.FreeProcessA
|
||
|
||
pla get back error code
|
||
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
S.CreateProcessA.Cmd .BS 1
|
||
S.CreateProcessA.CPSID .BS 1
|
||
*--------------------------------------
|
||
* S.GetPSByIDA
|
||
* In :
|
||
* A = PID
|
||
* Out :
|
||
* Y,A = PTR to TSKSLOT
|
||
*--------------------------------------
|
||
S.GetPSByIDA sta S.GetPSByIDA.PS
|
||
|
||
>LDYAI TskMgr.Table
|
||
>STYA ZPQuickPtr1
|
||
|
||
lda S.GetPSByIDA.PS
|
||
beq .8
|
||
|
||
ldx #0
|
||
|
||
.1 inx
|
||
lda ZPQuickPtr1
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta ZPQuickPtr1
|
||
bcc .2
|
||
inc ZPQuickPtr1+1
|
||
|
||
.2 lda (ZPQuickPtr1)
|
||
bpl .3
|
||
|
||
ldy #S.PS.ID
|
||
lda (ZPQuickPtr1),y
|
||
cmp S.GetPSByIDA.PS
|
||
beq .8
|
||
|
||
.3 cpx TSKMGR.SIZE
|
||
bne .1
|
||
|
||
.9 lda #TSKMGR.ERRNSP
|
||
sec
|
||
rts
|
||
|
||
.8 >LDYA ZPQuickPtr1
|
||
clc
|
||
rts
|
||
*--------------------------------------
|
||
S.GetPSByIDA.PS .BS 1
|
||
*--------------------------------------
|
||
* PRIVATE
|
||
*--------------------------------------
|
||
* S.CreateChildProcess
|
||
* in :
|
||
* out :
|
||
* A = PSID
|
||
* we cannot use ZPQuickPtrs
|
||
* because of calling S.PStrCpyA & S.DupEnvA
|
||
*--------------------------------------
|
||
S.CreateChildProcess
|
||
>LDYAI TskMgr.Table+S.PS.SIZE
|
||
>STYA R.AX
|
||
|
||
ldx #0
|
||
|
||
.1 inx
|
||
cpx TSKMGR.SIZE
|
||
beq .2
|
||
|
||
lda (R.AX) Found an empty slot
|
||
bpl .3
|
||
lda R.AL
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta R.AL
|
||
bcc .1
|
||
inc R.AH
|
||
|
||
bra .1
|
||
|
||
.2 cpx #K.PS.MAX
|
||
bne .30
|
||
|
||
lda #TSKMGR.ERROOH
|
||
sec
|
||
rts
|
||
|
||
.30 inc TSKMGR.SIZE
|
||
|
||
.3 lda #S.PS.F.INUSE
|
||
sta (R.AX)
|
||
|
||
.4 inc TSKMGR.LASTID Get a PSID not alredy running
|
||
beq .4 not = 0
|
||
lda TSKMGR.LASTID
|
||
jsr S.GetPSByIDA
|
||
bcc .4
|
||
|
||
ldy #S.PS.ID
|
||
lda TSKMGR.LASTID
|
||
sta (R.AX),y
|
||
|
||
lda #0
|
||
ldy #S.PS.hCS
|
||
.5 sta (R.AX),y Blank Everything in this S.PS
|
||
iny
|
||
cpy #S.PS.SIZE
|
||
bne .5
|
||
|
||
ldy #S.PS.hPREFIX copy hPREFIX...
|
||
lda (pPs),y
|
||
jsr S.PStrCpyA
|
||
bcs .99
|
||
|
||
ldy #S.PS.hPREFIX
|
||
sta (R.AX),y
|
||
|
||
ldy #S.PS.hENV ...and hENV from parent PS
|
||
lda (pPs),y
|
||
jsr S.DupEnvA
|
||
bcs .99
|
||
|
||
ldy #S.PS.hENV
|
||
sta (R.AX),y
|
||
|
||
ldy #S.PS.hINDEV
|
||
lda (pPs),y
|
||
sta (R.AX),y
|
||
ldy #S.PS.hOUTDEV
|
||
lda (pPs),y
|
||
sta (R.AX),y
|
||
ldy #S.PS.hERRDEV
|
||
lda (pPs),y
|
||
sta (R.AX),y
|
||
|
||
ldy #S.PS.ID
|
||
lda (pPs),y
|
||
|
||
ldy #S.PS.PID
|
||
sta (R.AX),y
|
||
|
||
ldy #S.PS.ID
|
||
lda (R.AX),y
|
||
clc Exit with A=PSID
|
||
rts
|
||
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
* S.InitProcessA
|
||
* In :
|
||
* A = hMem To Full Cmd Line
|
||
*--------------------------------------
|
||
S.InitProcessA >PUSHA Push Cmd Line
|
||
>PUSHBI $20 Push SEP=' '
|
||
>PUSHBI 0 Push 0 for getting CMD And ARGS
|
||
jsr S.PStrGetTkn
|
||
bcc .10
|
||
rts OOM error
|
||
|
||
.10 ldy #S.PS.hCMD
|
||
sta (pPs),y
|
||
>PUSHA push CMD for S.FileSearch
|
||
txa
|
||
ldy #S.PS.hARGS
|
||
sta (pPs),y set ARGS hMem (0 if none)
|
||
|
||
>PUSHWI ENV.PATH push ENVNAME=PATH
|
||
ldy #S.PS.hENV
|
||
lda (pPs),y
|
||
>PUSHA
|
||
jsr S.GetEnvVarP get value for ENV=PATH
|
||
bcs .99
|
||
|
||
sta S.InitProcessA.PATH save VALUE hMem for discard
|
||
>PUSHA A=PStr to ENV Value
|
||
jsr S.FileSearch find File in %PATH%
|
||
bcs .98
|
||
|
||
sta S.InitProcessA.FULLPATH save FULLPATH hMem for discard
|
||
pha
|
||
jsr S.SysScrPPSTRA
|
||
pla
|
||
|
||
jsr S.LoadBinA A = BinPath hMem
|
||
|
||
bcs .97
|
||
|
||
>STYA pCode save PTR to Code Segment
|
||
txa
|
||
ldy #S.PS.hCS
|
||
sta (pPs),y save CS hMem in TSKSLOT
|
||
|
||
ldy #H.BIN.BIN.DS.SIZE+1
|
||
lda (pCode),y Load DS.SIZE HI
|
||
tax
|
||
dey
|
||
ora (pCode),y
|
||
|
||
beq .1 DS.SIZE=0...
|
||
|
||
lda (pCode),y
|
||
>PUSHAX Push DS.SIZE
|
||
>PUSHBI S.MEM.F.INIT0 Clear DS
|
||
jsr S.GetMem
|
||
bcs .97
|
||
|
||
>STYA pData
|
||
txa
|
||
ldy #S.PS.hDS
|
||
sta (pPs),y save DS hMem in TSKSLOT
|
||
|
||
.1 ldx #TSKMGR.INIT
|
||
jsr pCodeJmp Call INIT function
|
||
bcs .97
|
||
jsr .97
|
||
clc
|
||
rts
|
||
|
||
.97 pha save ERR
|
||
lda S.InitProcessA.FULLPATH
|
||
jsr S.FreeMemA
|
||
pla
|
||
|
||
.98 pha save ERR
|
||
lda S.InitProcessA.PATH
|
||
jsr S.FreeMemA
|
||
pla
|
||
|
||
.99 sec
|
||
rts
|
||
S.InitProcessA.PATH .BS 1
|
||
S.InitProcessA.FULLPATH .BS 1
|
||
*--------------------------------------
|
||
* S.SelectProcessA
|
||
* In : A=PSID
|
||
*--------------------------------------
|
||
S.SelectProcessA
|
||
jsr S.GetPSByIDA
|
||
bcs *
|
||
>STYA pPS
|
||
|
||
S.SelectProcess ldy #S.PS.hCS
|
||
lda (pPs),y
|
||
jsr S.GetMemPtrA
|
||
>STYA pCode
|
||
|
||
ldy #S.PS.hDS
|
||
lda (pPs),y
|
||
beq .1
|
||
|
||
jsr S.GetMemPtrA
|
||
>STYA pData
|
||
|
||
.1 ldy #S.PS.hOUTDEV
|
||
lda (pPs),y
|
||
beq .8
|
||
|
||
jsr S.GetDevByIDA
|
||
>STYA pDev
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
* S.FreeProcessA
|
||
* In : A = PID to free
|
||
*--------------------------------------
|
||
S.FreeProcessA jsr S.GetPSByIDA
|
||
bcs .9
|
||
>STYA ZPQuickPtr1
|
||
ldy #S.PS.hARGS
|
||
lda (ZPQuickPtr1),y
|
||
beq .1
|
||
|
||
jsr S.FreeMemA
|
||
|
||
.1 ldy #S.PS.hCMD
|
||
lda (ZPQuickPtr1),y
|
||
beq .2
|
||
|
||
jsr S.FreeMemA
|
||
|
||
.2 ldy #S.PS.hENV
|
||
lda (ZPQuickPtr1),y
|
||
beq .3
|
||
|
||
jsr S.FreeMemA
|
||
|
||
.3 ldy #S.PS.hPREFIX
|
||
lda (ZPQuickPtr1),y
|
||
beq .4
|
||
|
||
jsr S.FreeMemA
|
||
|
||
.4 ldy #S.PS.hDS
|
||
lda (ZPQuickPtr1),y
|
||
beq .5
|
||
|
||
jsr S.FreeMemA
|
||
|
||
.5 ldy #S.PS.hCS
|
||
lda (ZPQuickPtr1),y
|
||
beq .8
|
||
|
||
jsr S.FreeMemA
|
||
|
||
.8 lda #0
|
||
sta (ZPQuickPtr1) Mark TSKSLOT as free
|
||
clc
|
||
rts
|
||
.9 bra *
|
||
*--------------------------------------
|
||
TSKMGR.SIZE .BS 1
|
||
TSKMGR.COUNT .BS 1
|
||
TSKMGR.LASTID .BS 1
|
||
*--------------------------------------
|
||
MSG.NEWPS >PSTRING "\nTskMgr:"
|
||
MAN
|
||
SAVE SYS/KERNEL.S.TSK
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|