mirror of
https://github.com/A2osX/A2osX.git
synced 2024-11-26 13:49:18 +00:00
599 lines
10 KiB
Plaintext
599 lines
10 KiB
Plaintext
NEW
|
||
PREFIX
|
||
AUTO 4,1
|
||
*--------------------------------------
|
||
PS.Flags .BS 1
|
||
PS.ArgV .BS 2
|
||
*/--------------------------------------
|
||
* # ExecL
|
||
* ## C
|
||
* `int execl(const char* cmdline, short int flags);`
|
||
* ## ASM
|
||
* `>PUSHB flags`
|
||
* `>LDYA cmdline`
|
||
* `>SYSCALL execl`
|
||
* ## RETURN VALUE
|
||
* A = Child PSID
|
||
*\--------------------------------------
|
||
K.ExecL sty .1+1
|
||
sta .2+1
|
||
>PULLB PS.Flags
|
||
|
||
>LDYAI 256
|
||
jsr K.GetMem
|
||
bcs .99
|
||
|
||
stx .90+1
|
||
>STYA PS.ArgV
|
||
>PUSHYA
|
||
.1 ldy #$ff SELF MODIFIED
|
||
.2 lda #$ff SELF MODIFIED
|
||
|
||
jsr K.Args2ArgV
|
||
|
||
bcs .9
|
||
|
||
jsr PS.Exec
|
||
|
||
.9 php
|
||
pha
|
||
.90 lda #$ff SELF MODIFIED
|
||
jsr K.FreeMem
|
||
pla
|
||
plp
|
||
|
||
.99 rts
|
||
*/--------------------------------------
|
||
* # ExecV
|
||
* ## C
|
||
* `int exec(const char* argv[], short int flags);`
|
||
* ## ASM
|
||
* `>PUSHB flags`
|
||
* `>LDYA argv`
|
||
* `>SYSCALL execv`
|
||
* ## RETURN VALUE
|
||
* A = Child PSID
|
||
*\--------------------------------------
|
||
K.ExecV >STYA PS.ArgV
|
||
>PULLB PS.Flags
|
||
|
||
PS.Exec jsr PS.CreateChild A=PID,Child S.PS at ZPPtr3,PS.Load.hMem
|
||
bcs .9
|
||
sta .8+1
|
||
|
||
stz K.IOBuf
|
||
jsr PS.Load
|
||
bcs .90
|
||
|
||
jsr PS.AddArgV
|
||
bcc .8
|
||
|
||
.90 pha save error code
|
||
|
||
.91 lda .8+1
|
||
jsr CORE.PSFree
|
||
pla get back error code
|
||
sec
|
||
rts
|
||
|
||
.8 lda #$ff SELF MODIFIED
|
||
|
||
.9 rts
|
||
*--------------------------------------
|
||
* PS.CreateChild
|
||
* in :
|
||
* out :
|
||
* A = PSID
|
||
* we cannot use ZPPtrs1 & 2
|
||
* because of calling K.NewStr & PS.DupEnv
|
||
*--------------------------------------
|
||
PS.CreateChild ldx CORE.PSCount
|
||
beq .3
|
||
|
||
ldx #0
|
||
|
||
.1 lda PS.Table.PID,x
|
||
beq .4 Found an empty slot
|
||
|
||
inx
|
||
cpx CORE.PSCount
|
||
bne .1
|
||
|
||
cpx #K.PS.MAX
|
||
bne .3
|
||
|
||
lda #E.OOH
|
||
sec
|
||
rts
|
||
|
||
.99 plx
|
||
rts
|
||
|
||
.3 inc CORE.PSCount
|
||
|
||
.4 inc CORE.LastPSID Get a PSID not already running
|
||
beq .4 not = 0
|
||
lda CORE.LastPSID
|
||
jsr CORE.GetPS Y=PS Index, X,A unmodified
|
||
bcc .4 running...loop
|
||
|
||
lda CORE.LastPSID
|
||
sta PS.Table.PID,x
|
||
phx save PS Index
|
||
|
||
>LDYAI S.PS
|
||
jsr K.GetMem0 Blank Everything in this S.PS
|
||
bcs .99
|
||
|
||
>STYA ZPPtr3
|
||
stx PS.Load.hMem
|
||
txa
|
||
plx
|
||
sta PS.Table.hPS,x
|
||
|
||
jsr PS.SetMemOwner Set Ownership
|
||
|
||
ldy #S.PS.PID
|
||
lda CORE.LastPSID
|
||
sta (ZPPtr3),y
|
||
|
||
ldy #S.PS.hPREFIX copy hPREFIX...
|
||
lda (pPs),y
|
||
jsr K.GetMemPtr
|
||
jsr K.NewStr
|
||
bcs .9
|
||
|
||
jsr PS.SetMemOwner Set Ownership
|
||
|
||
txa
|
||
ldy #S.PS.hPREFIX
|
||
sta (ZPPtr3),y
|
||
|
||
lda #S.PS.F.DUPENV
|
||
bit PS.Flags need to create ENV ?
|
||
beq .6 no...
|
||
|
||
sta (ZPPtr3) Mark this PS with DUPENV flag
|
||
|
||
ldy #S.PS.hENV dup hENV from parent PS
|
||
lda (pPs),y
|
||
jsr PS.DupEnv
|
||
bcs .9
|
||
|
||
ldy #S.PS.hENV
|
||
bra .8
|
||
|
||
.6 ldy #S.PS.hENV reuse hENV from parent PS
|
||
lda (pPs),y
|
||
|
||
.8 sta (ZPPtr3),y
|
||
|
||
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 PS.Flags
|
||
beq .82
|
||
|
||
ora (pPs)
|
||
sta (pPs) HOLD parent PS
|
||
|
||
.82 lda #S.PS.F.INIT
|
||
ora (ZPPtr3)
|
||
sta (ZPPtr3) Make this PS Init....
|
||
|
||
ldy #S.PS.CPID
|
||
lda CORE.LastPSID
|
||
sta (pPs),y
|
||
|
||
clc Exit with A=PSID
|
||
.9 rts
|
||
*--------------------------------------
|
||
PS.Load >PUSHWI K.S.STAT
|
||
>LDYA PS.ArgV
|
||
>SYSCALL stat BANK 1
|
||
bcs .99
|
||
|
||
lda K.S.STAT+S.STAT.P.TYPE
|
||
cmp #S.FI.T.BIN
|
||
beq PS.LoadBIN
|
||
cmp #S.FI.T.TXT
|
||
bne .98
|
||
|
||
* beq .10
|
||
* cmp #S.FI.T.SYS
|
||
* bra *
|
||
|
||
.10 jsr PS.LoadGetHeader
|
||
bcs .99
|
||
|
||
>LDYAI PS.Load.ROOT
|
||
jsr K.GetEnv ZPPtr3 Trashed
|
||
bcs .97
|
||
|
||
>STYA .21+1
|
||
|
||
ldx #$ff
|
||
|
||
.2 inx
|
||
.21 lda $ffff,x SELF MODIFIED
|
||
sta K.IOBuf,x
|
||
bne .2
|
||
|
||
ldy #0
|
||
|
||
.3 lda K.IOBuf+128,y
|
||
cmp PS.Load.HEADER,y
|
||
bne .98
|
||
iny
|
||
cpy #3
|
||
bne .3
|
||
|
||
.4 iny
|
||
inx
|
||
lda K.IOBuf+128-1,y
|
||
sta K.IOBuf-1,x
|
||
beq .5
|
||
eor #C.CR
|
||
bne .4
|
||
|
||
sta K.IOBuf-1,x
|
||
|
||
.5 >PUSHWI K.S.STAT
|
||
>LDYAI K.IOBuf
|
||
>SYSCALL stat BANK 1
|
||
bcs .99
|
||
|
||
lda PS.Load.hMem Restore ZPPtr3 trashed by GetEnv
|
||
jsr K.GetMemPtr
|
||
>STYA ZPPtr3
|
||
|
||
>LDYAI K.IOBuf
|
||
|
||
bra PS.LoadBIN.YA
|
||
|
||
.97 lda #E.BADPATH
|
||
.HS 2C
|
||
.98 lda #E.IBIN
|
||
sec
|
||
.99 rts
|
||
|
||
PS.LoadBIN >LDYA PS.ArgV
|
||
|
||
PS.LoadBIN.YA jsr BIN.Load
|
||
bcs .9
|
||
>STYA ZPPtr4 save PTR to Code Segment
|
||
|
||
phy
|
||
ldy #S.PS.ZP.CODE+1
|
||
sta (ZPPtr3),y save pCode HI...
|
||
dey
|
||
pla
|
||
sta (ZPPtr3),y save pCode LO...
|
||
|
||
txa
|
||
ldy #S.PS.hCS
|
||
sta (ZPPtr3),y save CS hMem in S.PS
|
||
|
||
* jsr K.GetMemByID
|
||
* jsr PS.SetMemOwner Set Ownership
|
||
|
||
ldy #H.BIN.F Get Bin S.PS.F
|
||
lda (ZPPtr4),y
|
||
beq .1
|
||
|
||
ldy #S.PS.F update PS S.PS.F
|
||
ora (ZPPtr3),y
|
||
sta (ZPPtr3),y
|
||
|
||
.1 ldy #H.BIN.DS.SIZE+1
|
||
lda (ZPPtr4),y Load DS.SIZE HI
|
||
tax
|
||
dey
|
||
ora (ZPPtr4),y
|
||
|
||
beq .2 DS.SIZE=0...
|
||
|
||
lda (ZPPtr4),y
|
||
tay
|
||
txa Y,A = DS.SIZE
|
||
ldx #S.MEM.F.INIT0+S.MEM.F.DATA
|
||
jsr MEM.GetMem.YAX
|
||
bcs .9
|
||
|
||
phy
|
||
ldy #S.PS.ZP.DATA+1
|
||
sta (ZPPtr3),y save pData HI...
|
||
dey
|
||
pla
|
||
sta (ZPPtr3),y save pData LO...
|
||
|
||
txa
|
||
ldy #S.PS.hDS
|
||
sta (ZPPtr3),y save DS hMem in S.PS
|
||
|
||
jsr PS.SetMemOwner Set Ownership
|
||
|
||
.2 ldy #H.BIN.SS.SIZE
|
||
lda (ZPPtr4),y Load SS.SIZE
|
||
|
||
ldy #S.PS.ZP.STACK
|
||
sta (ZPPtr3),y save pStack LO...
|
||
|
||
tay
|
||
|
||
bne .3 SS.SIZE.LO=0, set as default $100
|
||
lda #1 SS.SIZE.HI
|
||
.HS 2C bit abs
|
||
.3 lda #0
|
||
|
||
ldx #S.MEM.F.ALIGN+S.MEM.F.STACK
|
||
jsr MEM.GetMem.YAX
|
||
bcs .9
|
||
|
||
ldy #S.PS.ZP.STACK+1
|
||
sta (ZPPtr3),y save pStack HI...(LO alredy set to Stack TOP)
|
||
|
||
txa
|
||
ldy #S.PS.hSS
|
||
sta (ZPPtr3),y save SS hMem in S.PS
|
||
|
||
jsr PS.SetMemOwner Set Ownership
|
||
|
||
ldy #H.BIN.ZP.SIZE
|
||
lda (ZPPtr4),y
|
||
clc
|
||
adc #8 Add room for 4 saved PTR
|
||
ldy #S.PS.ZP.SIZE
|
||
sta (ZPPtr3),y
|
||
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
PS.LoadGetHeader
|
||
>PUSHWI 0 Aux type
|
||
>PUSHBI S.FI.T.TXT
|
||
>PUSHBI O.RDONLY
|
||
>LDYA PS.ArgV
|
||
>SYSCALL fopen
|
||
bcs PS.LoadGetHeader.RTS
|
||
sta .1+1
|
||
|
||
>PUSHWI 128
|
||
>PUSHWI K.IOBuf+128
|
||
.1 lda #$ff SELF MODIFIED
|
||
>SYSCALL fread
|
||
|
||
php
|
||
pha
|
||
lda .1+1
|
||
>SYSCALL fclose
|
||
pla
|
||
plp
|
||
PS.LoadGetHeader.RTS
|
||
rts
|
||
*--------------------------------------
|
||
PS.Load.ROOT .AZ "ROOT"
|
||
PS.Load.HEADER .AZ "#!/"
|
||
PS.Load.ArgSize .BS 2
|
||
PS.Load.hMem .BS 1
|
||
*--------------------------------------
|
||
* hBIN + PS.ArgV -> #S.PS.hARGV
|
||
*--------------------------------------
|
||
PS.AddArgV stz PS.Load.ArgSize
|
||
stz PS.Load.ArgSize+1
|
||
|
||
lda K.IOBuf
|
||
beq .10
|
||
|
||
>LDYAI K.IOBuf
|
||
jsr K.strlen
|
||
iny +1 for \0
|
||
>STYA PS.Load.ArgSize
|
||
ldx #0 ARGC-1
|
||
.HS 2C
|
||
|
||
.10 ldx #$ff ARGC-1
|
||
>LDYA PS.ArgV
|
||
>STYA ZPPtr1
|
||
|
||
.1 lda (ZPPtr1)
|
||
beq .4
|
||
|
||
inx
|
||
|
||
ldy #0
|
||
|
||
.2 iny
|
||
lda (ZPPtr1),y
|
||
bne .2
|
||
|
||
tya
|
||
sec
|
||
adc PS.Load.ArgSize
|
||
sta PS.Load.ArgSize
|
||
bcc .3
|
||
|
||
inc PS.Load.ArgSize+1
|
||
|
||
.3 jsr PS.AddYp1ToPtr1
|
||
bra .1
|
||
|
||
.4 txa
|
||
ldy #S.PS.ARGC
|
||
sta (ZPPtr3),y
|
||
|
||
>LDYA PS.Load.ArgSize Add 1 for ending 0
|
||
iny
|
||
bne .5
|
||
inc
|
||
|
||
.5 jsr K.GetMem
|
||
bcs PS.LoadGetHeader.RTS
|
||
|
||
>STYA ZPPtr2 Target Buffer
|
||
txa
|
||
ldy #S.PS.hARGV
|
||
sta (ZPPtr3),y
|
||
|
||
lda K.IOBuf
|
||
beq .6
|
||
|
||
>LDYAI K.IOBuf
|
||
>STYA ZPPtr1
|
||
jsr PS.AddPtr1ToStrV
|
||
|
||
.6 >LDYA PS.ArgV
|
||
>STYA ZPPtr1
|
||
|
||
.7 lda (ZPPtr1)
|
||
sta (ZPPtr2)
|
||
beq .8 Ending \0
|
||
|
||
jsr PS.AddPtr1ToStrV
|
||
bra .7
|
||
|
||
.8 clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
* PS.DupEnv
|
||
* In:
|
||
* A = ENV hMem To Duplicate
|
||
* Out:
|
||
* A = hMem to new ENV
|
||
* X = Count
|
||
*--------------------------------------
|
||
PS.DupEnv jsr K.GetMemPtr
|
||
>STYA ZPPtr1
|
||
|
||
>LDYAI K.ENV.SIZE
|
||
|
||
jsr K.GetMem
|
||
bcs .9
|
||
|
||
>STYA ZPPtr2 Target Buffer
|
||
phx save hMem
|
||
|
||
jsr PS.SetMemOwner Set Ownership
|
||
|
||
.1 lda (ZPPtr1)
|
||
sta (ZPPtr2)
|
||
beq .8 Ending \0
|
||
|
||
jsr PS.AddPtr1ToStrV
|
||
bra .1
|
||
|
||
.8 pla hMem
|
||
|
||
clc
|
||
.9 rts
|
||
*--------------------------------------
|
||
PS.AddPtr1ToStrV
|
||
ldy #$ff
|
||
|
||
.2 iny
|
||
lda (ZPPtr1),y
|
||
sta (ZPPtr2),y
|
||
bne .2
|
||
|
||
jsr PS.AddYp1ToPtr1
|
||
|
||
tya
|
||
sec
|
||
adc ZPPtr2
|
||
sta ZPPtr2
|
||
bcc .8
|
||
inc ZPPtr2+1
|
||
|
||
.8 rts
|
||
*--------------------------------------
|
||
PS.AddYp1ToPtr1 tya
|
||
sec
|
||
adc ZPPtr1
|
||
sta ZPPtr1
|
||
bcc .8
|
||
|
||
inc ZPPtr1+1
|
||
|
||
.8 rts
|
||
*--------------------------------------
|
||
PS.SetMemOwner lda CORE.LastPSID
|
||
ldy #S.MEM.OWNERPID
|
||
sta (ZPMEMMGR),y
|
||
rts
|
||
*/--------------------------------------
|
||
* # ExecL
|
||
* ## C
|
||
* `int kill(short int pid, short int sig);`
|
||
* ## ASM
|
||
* `>PUSHB sig`
|
||
* `lda pid`
|
||
* `>SYSCALL kill`
|
||
* ## RETURN VALUE
|
||
* A = Child PSID
|
||
*\--------------------------------------
|
||
K.Kill cmp #0
|
||
beq .99 CS
|
||
|
||
jsr CORE.GetPSByID
|
||
bcs .99
|
||
>STYA ZPPtr1
|
||
|
||
>PULLA
|
||
cmp #2
|
||
bcs .9
|
||
asl
|
||
tax
|
||
jmp (.1,x)
|
||
|
||
.1 .DA K.Kill.0
|
||
.DA K.Kill.1
|
||
|
||
.9 lda #E.SYN
|
||
* sec
|
||
rts
|
||
|
||
.99 >RET 1
|
||
*--------------------------------------
|
||
K.Kill.0 clc
|
||
rts
|
||
|
||
*--------------------------------------
|
||
K.Kill.1 lda (ZPPtr1)
|
||
|
||
and #$33
|
||
ora #S.PS.F.QUIT
|
||
sta (ZPPtr1)
|
||
|
||
clc
|
||
rts
|
||
|
||
*/--------------------------------------
|
||
* # GetPSStatus
|
||
* **In:**
|
||
* A = PID
|
||
* ## RETURN VALUE
|
||
* A = Status Byte
|
||
*\--------------------------------------
|
||
K.GetPSStatus jsr CORE.GetPSByID
|
||
bcs .9
|
||
>STYA ZPPtr1
|
||
lda (ZPPtr1)
|
||
.9 rts
|
||
*--------------------------------------
|
||
MAN
|
||
SAVE USR/SRC/SYS/KERNEL.S.PS
|
||
LOAD USR/SRC/SYS/KERNEL.S
|
||
ASM
|