mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-26 13:49:18 +00:00
377 lines
6.8 KiB
Plaintext
377 lines
6.8 KiB
Plaintext
PR#3
|
||
PREFIX /A2OSX.BUILD
|
||
LOMEM $A00
|
||
INC 1
|
||
AUTO 6
|
||
*/--------------------------------------
|
||
* # ExecProcessNewEnvYA
|
||
* # ExecProcessYA (Blocking Parent PID)
|
||
* # CreateProcessNewEnvYA
|
||
* # CreateProcessYA (Non Blocking)
|
||
* ## In:
|
||
* Y,A = PTR To Cmd Line
|
||
* ## Out:
|
||
* A = Child PSID
|
||
*\--------------------------------------
|
||
K.ExecProcessNewEnvYA
|
||
ldx #S.PS.F.ENV+S.PS.F.HOLD
|
||
.HS 2C bit abs
|
||
K.ExecProcessYA ldx #S.PS.F.HOLD
|
||
.HS 2C bit abs
|
||
K.CreateProcessNewEnvYA
|
||
ldx #S.PS.F.ENV
|
||
.HS 2C bit abs
|
||
K.CreateProcessYA
|
||
ldx #0
|
||
stx K.CreateProcess.Flags
|
||
>STYA K.CreateProcess.CmdLine
|
||
|
||
jsr PS.CreateChild
|
||
bcs .9
|
||
|
||
sta .8+1
|
||
|
||
jsr PS.Init
|
||
bcc .8
|
||
|
||
pha save error code
|
||
lda .8+1
|
||
jsr PS.FreeA
|
||
pla get back error code
|
||
sec
|
||
rts
|
||
|
||
.8 lda #$ff self modified
|
||
.9 rts
|
||
*--------------------------------------
|
||
K.CreateProcess.Flags .BS 1
|
||
K.CreateProcess.CmdLine .BS 2
|
||
*/--------------------------------------
|
||
* # GetPSByIDA
|
||
* ## In :
|
||
* A = PID
|
||
* ## Out :
|
||
* Y,A = PTR to TSKSLOT
|
||
*\--------------------------------------
|
||
K.GetPSByIDA pha
|
||
>LDYAI TskMgr.Table
|
||
>STYA ZPPtr1
|
||
|
||
pla
|
||
beq .8
|
||
sta .20+1
|
||
ldx #0
|
||
|
||
.1 inx
|
||
lda ZPPtr1
|
||
clc
|
||
adc #S.PS
|
||
sta ZPPtr1
|
||
bcc .2
|
||
inc ZPPtr1+1
|
||
|
||
.2 lda (ZPPtr1)
|
||
bpl .3
|
||
|
||
ldy #S.PS.PID
|
||
lda (ZPPtr1),y
|
||
.20 cmp #$ff Self Modified
|
||
beq .8
|
||
|
||
.3 cpx TskMgr.Count
|
||
bne .1
|
||
|
||
.9 lda #TSKMGR.ERRNSP
|
||
sec
|
||
rts
|
||
|
||
.8 >LDYA ZPPtr1
|
||
clc
|
||
rts
|
||
*/--------------------------------------
|
||
* # Sleep
|
||
* Make current process suspend until next RUN
|
||
* ## In :
|
||
* (none)
|
||
* ## Out :
|
||
* (none)
|
||
*\--------------------------------------
|
||
K.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
|
||
*--------------------------------------
|
||
* PS.CreateChild
|
||
* in :
|
||
* out :
|
||
* A = PSID
|
||
* we cannot use ZPPtrs1 & 2
|
||
* because of calling K.NewPStrYA & S.DupEnvA
|
||
*--------------------------------------
|
||
PS.CreateChild >LDYAI TskMgr.Table+S.PS
|
||
>STYA ZPPtr3
|
||
|
||
ldx #0
|
||
|
||
.1 inx
|
||
cpx TskMgr.Count
|
||
beq .2
|
||
|
||
lda (ZPPtr3) Found an empty slot
|
||
bpl .3
|
||
lda ZPPtr3
|
||
clc
|
||
adc #S.PS
|
||
sta ZPPtr3
|
||
bcc .1
|
||
inc ZPPtr3+1
|
||
|
||
bra .1
|
||
|
||
.2 cpx #K.PS.MAX
|
||
bne .3
|
||
|
||
lda #TSKMGR.ERROOH
|
||
sec
|
||
rts
|
||
|
||
.3 inc TskMgr.Count
|
||
|
||
.4 inc TSKMGR.LASTID Get a PSID not alredy running
|
||
beq .4 not = 0
|
||
lda TSKMGR.LASTID
|
||
jsr K.GetPSByIDA
|
||
bcc .4
|
||
|
||
ldy #S.PS.PID
|
||
lda TSKMGR.LASTID
|
||
sta (ZPPtr3),y
|
||
|
||
lda #0
|
||
ldy #S.PS.hCS
|
||
|
||
.5 sta (ZPPtr3),y Blank Everything in this S.PS
|
||
iny
|
||
cpy #S.PS
|
||
bne .5
|
||
|
||
lda #S.PS.F.ENV
|
||
bit K.CreateProcess.Flags need to create ENV & Prefix ?
|
||
beq .6 no...
|
||
|
||
sta (ZPPtr3) Mark this PS with ENV flag
|
||
|
||
ldy #S.PS.hPREFIX copy hPREFIX...
|
||
lda (pPs),y
|
||
jsr K.GetMemPtrA
|
||
jsr K.NewPStrYA
|
||
bcs .9
|
||
|
||
txa
|
||
ldy #S.PS.hPREFIX
|
||
sta (ZPPtr3),y
|
||
|
||
ldy #S.PS.hENV ...and hENV from parent PS
|
||
lda (pPs),y
|
||
jsr PS.DupEnvA
|
||
bcs .9
|
||
|
||
ldy #S.PS.hENV
|
||
sta (ZPPtr3),y
|
||
bra .8
|
||
|
||
.6 ldy #S.PS.hPREFIX reuse same hPREFIX...
|
||
lda (pPs),y
|
||
sta (ZPPtr3),y
|
||
|
||
ldy #S.PS.hENV ...and hENV from parent PS
|
||
lda (pPs),y
|
||
sta (ZPPtr3),y
|
||
|
||
.8 ldy #S.PS.hStdIn
|
||
|
||
.81 lda (pPs),y
|
||
sta (ZPPtr3),y
|
||
iny
|
||
cpy #S.PS.hStdErr+1
|
||
bne .81
|
||
|
||
ldy #S.PS.PID
|
||
lda (pPs),y
|
||
|
||
ldy #S.PS.PPID
|
||
sta (ZPPtr3),y
|
||
|
||
lda #S.PS.F.HOLD
|
||
bit K.CreateProcess.Flags
|
||
beq .82
|
||
|
||
ora (pPs)
|
||
sta (pPs) HOLD parent PS if ExecProcess
|
||
|
||
.82 lda #S.PS.F.INUSE+S.PS.F.INIT
|
||
ora (ZPPtr3)
|
||
sta (ZPPtr3) Make this PS Init....
|
||
|
||
ldy #S.PS.CPID
|
||
lda TSKMGR.LASTID
|
||
sta (pPs),y
|
||
|
||
clc Exit with A=PSID
|
||
.9 rts
|
||
*--------------------------------------
|
||
PS.Init >LDYA K.CreateProcess.CmdLine
|
||
jsr K.PStr2StrArrayYA
|
||
bcs .9
|
||
|
||
phy save PTR to StrArray...
|
||
pha
|
||
|
||
txa
|
||
ldy #S.PS.hCMDLINE
|
||
sta (ZPPtr3),y
|
||
|
||
pla Restore PTR...
|
||
ply
|
||
>SYSCALL LoadExeYA Y,A=filename full path
|
||
bcs .9
|
||
|
||
>STYA ZPPtr4 save PTR to Code Segment
|
||
txa
|
||
ldy #S.PS.hCS
|
||
sta (ZPPtr3),y save CS hMem in TSKSLOT
|
||
|
||
ldy #H.BIN.EXE.DS.SIZE+1
|
||
lda (ZPPtr4),y Load DS.SIZE HI
|
||
tax
|
||
dey
|
||
ora (ZPPtr4),y
|
||
|
||
beq .2 DS.SIZE=0...
|
||
|
||
lda (ZPPtr4),y
|
||
>PUSHAX Push DS.SIZE
|
||
>PUSHBI S.MEM.F.INIT0 Clear DS
|
||
jsr K.GetMem
|
||
bcs .9
|
||
|
||
txa
|
||
ldy #S.PS.hDS
|
||
sta (ZPPtr3),y save DS hMem in TSKSLOT
|
||
|
||
.2
|
||
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
* PS.FreeA
|
||
* In : A = PID to free
|
||
*--------------------------------------
|
||
PS.FreeA jsr K.GetPSByIDA PS in ZPPtr1
|
||
|
||
ldy #S.PS.hCMDLINE
|
||
jsr PS.FreeA.PsY
|
||
|
||
lda (ZPPtr1) get S.PS.F
|
||
and #S.PS.F.ENV do we have to discard duplicated env & prefix ?
|
||
beq .1
|
||
|
||
ldy #S.PS.hENV
|
||
jsr PS.FreeA.PsY
|
||
|
||
ldy #S.PS.hPREFIX
|
||
jsr PS.FreeA.PsY
|
||
|
||
.1 ldy #S.PS.hDS
|
||
jsr PS.FreeA.PsY
|
||
|
||
ldy #S.PS.hCS
|
||
jsr PS.FreeA.PsY
|
||
|
||
lda #0
|
||
sta (ZPPtr1) Mark TSKSLOT as free
|
||
clc
|
||
PS.FreeA.RTS rts
|
||
*--------------------------------------
|
||
PS.FreeA.PsY lda (ZPPtr1),y
|
||
beq PS.FreeA.RTS
|
||
jmp K.FreeMemA
|
||
*--------------------------------------
|
||
* PS.SelectA
|
||
* In : A=PSID
|
||
*--------------------------------------
|
||
PS.Select0 lda #0
|
||
PS.SelectA jsr K.GetPSByIDA
|
||
bcs *
|
||
>STYA pPs
|
||
|
||
PS.Select ldy #S.PS.hCS
|
||
lda (pPs),y
|
||
beq .1 PS=0 (kernel) has no CS/DS
|
||
|
||
jsr K.GetMemPtrA
|
||
>STYA pCode
|
||
|
||
ldy #S.PS.hDS
|
||
lda (pPs),y
|
||
beq .1
|
||
|
||
jsr K.GetMemPtrA
|
||
>STYA pData
|
||
|
||
.1 ldy #S.PS.hStdOut
|
||
lda (pPs),y
|
||
beq .8
|
||
|
||
jsr K.GetDevByIDA
|
||
>STYA pDev
|
||
|
||
.8 clc
|
||
rts
|
||
*--------------------------------------
|
||
* PS.DupEnvA
|
||
* In:
|
||
* A = ENV hMem To Duplicate
|
||
* Out:
|
||
* A = hMem to new ENV
|
||
*--------------------------------------
|
||
PS.DupEnvA jsr K.GetMemPtrA
|
||
>STYA ZPPtr1
|
||
>PUSHWI K.ENV.SIZE
|
||
>PUSHBI 0
|
||
jsr K.GetMem
|
||
bcs .9
|
||
>STYA ZPPtr2
|
||
|
||
ldy #0
|
||
|
||
.1 lda (ZPPtr1),y
|
||
sta (ZPPtr2),y
|
||
beq .8
|
||
|
||
iny
|
||
bne .1
|
||
inc ZPPtr1+1
|
||
inc ZPPtr2+1
|
||
bra .1
|
||
|
||
.8 txa
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE /A2OSX.SRC/SYS/KERNEL.S.PS
|
||
LOAD /A2OSX.SRC/SYS/KERNEL.S
|
||
ASM
|