mirror of
https://github.com/A2osX/A2osX.git
synced 2024-09-10 22:54:59 +00:00
556 lines
10 KiB
Plaintext
556 lines
10 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.SRC
|
||
NEW
|
||
INC 1
|
||
AUTO 6
|
||
.LIST OFF
|
||
*--------------------------------------
|
||
* S.TskMgrRun
|
||
*--------------------------------------
|
||
S.TskMgrRun >LDYAI TskMgr.Table+S.PS.SIZE
|
||
>STYA pPs
|
||
|
||
lda TSKMGR.SIZE
|
||
sta TSKMGR.COUNT
|
||
|
||
.1 dec TSKMGR.COUNT skip PS 0
|
||
beq .8
|
||
|
||
lda (pPs) get S.PS.F
|
||
bit #S.PS.F.INUSE In use ?
|
||
beq .5
|
||
|
||
bit #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
|
||
|
||
lda (pPS)
|
||
bit #S.PS.F.SLEEP Is this PS sleeping?
|
||
beq .3 no, call TSKMGR.RUN
|
||
|
||
and #$FF^S.PS.F.SLEEP unmark as SLEEP
|
||
sta (pPS)
|
||
|
||
ldy #S.PS.PC
|
||
lda (pPs),y
|
||
sec Advance PC by one as it was saved by a JSR
|
||
adc pCode
|
||
sta .21+1
|
||
iny
|
||
lda (pPs),y
|
||
adc pCode+1
|
||
sta .21+2
|
||
|
||
.21 jsr $FFFF
|
||
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 *
|
||
|
||
.5 lda pPs
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta pPs
|
||
bcc .1
|
||
inc pPs+1
|
||
bne .1
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
* S.DispatchEvent
|
||
* IN:
|
||
* OUT:
|
||
* CS: Not Dispatched
|
||
* CC: Event Cleared
|
||
*--------------------------------------
|
||
S.DispatchEvents
|
||
>LDYAI TskMgr.Table+S.PS.SIZE
|
||
>STYA pPs
|
||
|
||
lda TSKMGR.SIZE
|
||
sta TSKMGR.COUNT
|
||
|
||
.1 dec TSKMGR.COUNT skip PS 0
|
||
beq .9
|
||
|
||
lda (pPs) get S.PS.F
|
||
bit #S.PS.F.INUSE In use ?
|
||
beq .4
|
||
|
||
bit #S.PS.F.HOLD Waiting for Another Task to Terminate?
|
||
bne .4
|
||
|
||
bit #S.PS.F.EVENT Accept Events ?
|
||
beq .4
|
||
|
||
jsr S.SelectProcess
|
||
|
||
stz pEvent
|
||
|
||
lda EVTMGR.SIZE
|
||
sta TSKMGR.EVENTCNT
|
||
|
||
.2 lda (pEvent)
|
||
beq .3
|
||
|
||
lda (pCode)
|
||
cmp #H.BIN.HEADER.BIN65
|
||
bne *
|
||
|
||
ldx #TSKMGR.DOEVENT
|
||
jsr pCodeJmp Call DOEVENT function
|
||
bcs .3
|
||
jsr S.DestroyEvent
|
||
lda EVTMGR.COUNT
|
||
beq .8
|
||
|
||
.3 dec TSKMGR.EVENTCNT
|
||
beq .4
|
||
lda pEvent
|
||
clc
|
||
adc #S.EVT
|
||
sta pEvent
|
||
bra .2
|
||
|
||
.4 lda pPs
|
||
clc
|
||
adc #S.PS.SIZE
|
||
sta pPs
|
||
bcc .1
|
||
inc pPs+1
|
||
bne .1 always
|
||
|
||
.8 clc
|
||
rts
|
||
|
||
.9 sec
|
||
rts
|
||
*--------------------------------------
|
||
S.TskMgrQuit clc
|
||
rts
|
||
*--------------------------------------
|
||
* PUBLIC
|
||
*--------------------------------------
|
||
* S.ExecProcessNewEnvYA
|
||
* S.ExecProcessYA (Blocking Parent PID)
|
||
* S.CreateProcessNewEnvYA
|
||
* S.CreateProcessYA (Non Blocking)
|
||
* in :
|
||
* A = hMem To Cmd Line
|
||
* Y = hMem To Args
|
||
* out :
|
||
* A = Child PSID
|
||
*--------------------------------------
|
||
S.ExecProcessNewEnvYA
|
||
ldx #S.PS.F.ENV
|
||
.HS 2C bit abs
|
||
S.ExecProcessYA ldx #0
|
||
S.ExecProcess jsr S.CreateProcess
|
||
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.CreateProcessNewEnvYA
|
||
ldx #S.PS.F.ENV
|
||
.HS 2C bit abs
|
||
S.CreateProcessYA
|
||
ldx #0
|
||
S.CreateProcess stx S.CreateChildProcess.Flags
|
||
sta S.CreateProcessA.Cmd
|
||
sty S.CreateProcessA.Args
|
||
|
||
jsr S.CreateChildProcess
|
||
bcs .99
|
||
|
||
sta S.CreateProcessA.CPSID
|
||
jsr S.SelectProcessA
|
||
|
||
jsr S.InitProcess
|
||
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.Args .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
|
||
*--------------------------------------
|
||
S.Sleep pla get PC LO
|
||
sec
|
||
sbc pCode
|
||
ldy #S.PS.PC
|
||
sta (pPs),y
|
||
|
||
pla get PC HI
|
||
sbc pCode+1
|
||
iny
|
||
sta (pPs),y
|
||
lda (pPs)
|
||
ora #S.PS.F.SLEEP
|
||
sta (pPs)
|
||
clc No error,
|
||
rts back to Kernel
|
||
*--------------------------------------
|
||
* PRIVATE
|
||
*--------------------------------------
|
||
* S.CreateChildProcess
|
||
* in :
|
||
* out :
|
||
* A = PSID
|
||
* we cannot use ZPQuickPtrs
|
||
* because of calling S.NewPStrYA & 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
|
||
ora S.CreateChildProcess.Flags
|
||
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
|
||
|
||
lda S.CreateChildProcess.Flags
|
||
and #S.PS.F.ENV need to create ENV & Prefix ?
|
||
beq .6
|
||
|
||
ldy #S.PS.hPREFIX copy hPREFIX...
|
||
lda (pPs),y
|
||
jsr S.GetMemPtrA
|
||
jsr S.NewPStrYA
|
||
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
|
||
bra .8
|
||
|
||
.6 ldy #S.PS.hPREFIX reuse same hPREFIX...
|
||
lda (pPs),y
|
||
sta (R.AX),y
|
||
|
||
ldy #S.PS.hENV ...and hENV from parent PS
|
||
lda (pPs),y
|
||
sta (R.AX),y
|
||
|
||
.8 ldy #S.PS.hINDEV
|
||
.81 lda (pPs),y
|
||
sta (R.AX),y
|
||
iny
|
||
cpy #S.PS.hERRDEV+1
|
||
bne .81
|
||
|
||
ldy #S.PS.ID
|
||
lda (pPs),y
|
||
|
||
ldy #S.PS.PID
|
||
sta (R.AX),y
|
||
|
||
lda TSKMGR.LASTID
|
||
clc Exit with A=PSID
|
||
rts
|
||
|
||
.99 sec
|
||
rts
|
||
*--------------------------------------
|
||
S.CreateChildProcess.Flags
|
||
.BS 1
|
||
*--------------------------------------
|
||
* S.InitProcess
|
||
* In :
|
||
* A = hMem To Full Cmd Line
|
||
*--------------------------------------
|
||
S.InitProcess lda S.CreateProcessA.Args
|
||
beq .1
|
||
jsr S.ExpandPStrA
|
||
.1 ldy #S.PS.hARGS
|
||
sta (pPs),y set ARGS hMem (0 if none)
|
||
|
||
lda S.CreateProcessA.Cmd
|
||
jsr S.ExpandPStrA
|
||
|
||
ldy #S.PS.hCMD
|
||
sta (pPs),y
|
||
|
||
jsr S.LoadBinA A = BinPath hMem
|
||
bcs .99
|
||
|
||
>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 .2 DS.SIZE=0...
|
||
|
||
lda (pCode),y
|
||
>PUSHAX Push DS.SIZE
|
||
>PUSHBI S.MEM.F.INIT0 Clear DS
|
||
jsr S.GetMem
|
||
bcs .99
|
||
|
||
>STYA pData
|
||
txa
|
||
ldy #S.PS.hDS
|
||
sta (pPs),y save DS hMem in TSKSLOT
|
||
|
||
.2 lda (pCode)
|
||
cmp #H.BIN.HEADER.BIN65
|
||
bne *
|
||
|
||
ldx #TSKMGR.INIT
|
||
jsr pCodeJmp Call INIT function
|
||
bcc .99
|
||
pha save error code
|
||
ldx #TSKMGR.QUIT
|
||
jsr pCodeJmp Call QUIT function
|
||
pla get back error code
|
||
sec
|
||
.99 rts
|
||
*--------------------------------------
|
||
* S.SelectProcessA
|
||
* In : A=PSID
|
||
*--------------------------------------
|
||
S.SelectProcessA
|
||
tay
|
||
bne S.SelectProcessN
|
||
S.SelectProcess0
|
||
>LDYAI TskMgr.Table Make PS #0 as current process
|
||
>STYA pPs
|
||
bra S.SelectProcessDev
|
||
S.SelectProcessN
|
||
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 S.SelectProcessDev
|
||
|
||
jsr S.GetMemPtrA
|
||
>STYA pData
|
||
|
||
S.SelectProcessDev
|
||
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 *
|
||
>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
|
||
|
||
lda (ZPQuickPtr1) get S.PS.F
|
||
and #S.PS.F.ENV do we have to discard duplicated env & prefix ?
|
||
beq .4
|
||
|
||
.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
|
||
*--------------------------------------
|
||
TSKMGR.SIZE .BS 1
|
||
TSKMGR.COUNT .BS 1
|
||
TSKMGR.EVENTCNT .BS 1
|
||
TSKMGR.LASTID .BS 1
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE SYS/KERNEL.S.TSK
|
||
LOAD SYS/KERNEL.S
|
||
ASM
|