A2osX/SYS/KERNEL.S.PS.txt

464 lines
8.1 KiB
Plaintext
Raw Normal View History

2017-12-22 21:24:30 +00:00
NEW
PREFIX /A2OSX.BUILD
2017-12-22 21:24:30 +00:00
AUTO 4,1
2018-10-15 06:25:40 +00:00
*--------------------------------------
PS.Flags .BS 1
2018-10-26 14:46:11 +00:00
PS.ArgV .BS 2
*/--------------------------------------
2018-10-25 15:31:41 +00:00
* # ExecL
* ## C
* `int execl(const char* cmdline, short int flags);`
* ## ASM
* `>PUSHB flags`
* `>LDYA cmdline`
* `>SYSCALL execl`
* ## RETURN VALUE
* A = Child PSID
*\--------------------------------------
2018-10-26 14:46:11 +00:00
K.ExecL sty .1+1
sta .2+1
>PULLB PS.Flags
>LDYAI 256
jsr K.GetMem
bcs .99
2018-10-25 15:31:41 +00:00
2018-10-26 14:46:11 +00:00
stx .90+1
>STYA PS.ArgV
>PUSHYA
.1 ldy #$ff SELF MODIFIED
.2 lda #$ff SELF MODIFIED
2018-10-25 15:31:41 +00:00
2018-10-26 14:46:11 +00:00
jsr K.Args2ArgV
bcs .9
jsr PS.Exec
.9 php
2018-10-26 06:16:14 +00:00
pha
2018-10-26 14:46:11 +00:00
.90 lda #$ff SELF MODIFIED
jsr K.FreeMem
2018-10-26 06:16:14 +00:00
pla
2018-10-26 14:46:11 +00:00
plp
.99 rts
2018-10-25 15:31:41 +00:00
*/--------------------------------------
* # ExecV
2018-10-15 06:25:40 +00:00
* ## C
2018-10-16 15:48:03 +00:00
* `int exec(const char* argv[], short int flags);`
2018-10-15 06:25:40 +00:00
* ## ASM
* `>PUSHB flags`
* `>LDYA argv`
2018-10-15 15:39:21 +00:00
* `>SYSCALL execv`
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
2018-10-15 06:25:40 +00:00
* A = Child PSID
*\--------------------------------------
2018-10-26 14:46:11 +00:00
K.ExecV >STYA PS.ArgV
2018-10-15 06:25:40 +00:00
>PULLB PS.Flags
2018-10-25 15:31:41 +00:00
2018-10-26 14:46:11 +00:00
PS.Exec jsr PS.CreateChild Child S.PS at ZPPtr3
bcs .9
sta .8+1
2018-10-15 15:39:21 +00:00
2018-10-26 14:46:11 +00:00
>LDYA PS.ArgV
2018-10-15 15:39:21 +00:00
jsr PS.DupArgs
2018-10-16 15:48:03 +00:00
ldy #S.PS.hARGV
2018-10-15 15:39:21 +00:00
sta (ZPPtr3),y
pha
dey S.PS.ARGC
txa
sta (ZPPtr3),y
2018-10-15 15:39:21 +00:00
pla
>SYSCALL GetMemPtr
2018-10-26 14:46:11 +00:00
2018-07-05 05:42:16 +00:00
jsr PS.Load
bcc .8
pha save error code
lda .8+1
2018-10-24 15:36:45 +00:00
jsr CORE.PSFree
pla get back error code
sec
rts
.8 lda #$ff self modified
.9 rts
*--------------------------------------
2016-09-29 15:30:15 +00:00
* PS.CreateChild
2016-08-17 06:25:58 +00:00
* in :
* out :
* A = PSID
2017-01-12 17:43:45 +00:00
* we cannot use ZPPtrs1 & 2
2018-10-11 15:23:06 +00:00
* because of calling K.NewStr.YA & PS.Dup
2016-08-17 06:25:58 +00:00
*--------------------------------------
2018-10-23 15:36:57 +00:00
PS.CreateChild ldx CORE.PSCount
beq .3
ldx #0
2016-08-17 06:25:58 +00:00
2018-10-15 15:39:21 +00:00
.1 lda PS.Table.PID,x
2018-10-17 15:31:29 +00:00
beq .4 Found an empty slot
2018-10-23 15:36:57 +00:00
inx
2018-10-23 15:36:57 +00:00
cpx CORE.PSCount
2018-10-15 15:39:21 +00:00
bne .1
2016-08-17 06:25:58 +00:00
2018-10-23 15:36:57 +00:00
cpx #K.PS.MAX
bne .3
2018-10-21 20:54:07 +00:00
lda #E.OOH
2016-08-17 06:25:58 +00:00
sec
rts
.99 plx
rts
2018-10-23 15:36:57 +00:00
.3 inc CORE.PSCount
2018-10-15 15:39:21 +00:00
.4 inc CORE.LastPSID Get a PSID not already running
2016-08-17 06:25:58 +00:00
beq .4 not = 0
lda CORE.LastPSID
2018-10-17 15:31:29 +00:00
jsr CORE.GetPS Y=PS Index, X,A unmodified
bcc .4 running...loop
2016-08-17 06:25:58 +00:00
lda CORE.LastPSID
sta PS.Table.PID,x
2018-10-17 15:31:29 +00:00
phx save PS Index
2016-08-17 06:25:58 +00:00
>LDYAI S.PS
2018-06-21 15:12:10 +00:00
jsr K.GetMem0 Blank Everything in this S.PS
bcs .99
>STYA ZPPtr3
txa
plx
2018-10-17 15:31:29 +00:00
sta PS.Table.hPS,x
2018-06-21 15:12:10 +00:00
jsr PS.SetMemOwner Set Ownership
ldy #S.PS.PID
lda CORE.LastPSID
sta (ZPPtr3),y
2016-08-17 06:25:58 +00:00
lda #S.PS.F.DUPENV
2018-10-15 06:25:40 +00:00
bit PS.Flags need to create ENV & Prefix ?
beq .6 no...
sta (ZPPtr3) Mark this PS with DUPENV flag
2016-08-17 06:25:58 +00:00
ldy #S.PS.hPREFIX copy hPREFIX...
lda (pPs),y
2018-06-21 15:12:10 +00:00
jsr K.GetMemPtr
2018-06-22 14:59:24 +00:00
jsr K.NewStr
bcs .9
2016-08-17 06:25:58 +00:00
2017-10-27 14:56:46 +00:00
jsr PS.SetMemOwner Set Ownership
2016-08-17 06:25:58 +00:00
txa
ldy #S.PS.hPREFIX
2017-01-12 17:43:45 +00:00
sta (ZPPtr3),y
2016-08-17 06:25:58 +00:00
ldy #S.PS.hENV ...and hENV from parent PS
lda (pPs),y
2018-06-22 14:59:24 +00:00
jsr PS.DupEnv
bcs .9
2016-08-17 06:25:58 +00:00
ldy #S.PS.hENV
2017-01-12 17:43:45 +00:00
sta (ZPPtr3),y
2016-08-17 06:25:58 +00:00
bra .8
.6 ldy #S.PS.hPREFIX reuse same hPREFIX...
lda (pPs),y
2017-01-12 17:43:45 +00:00
sta (ZPPtr3),y
2016-08-17 06:25:58 +00:00
ldy #S.PS.hENV ...and hENV from parent PS
lda (pPs),y
2017-01-12 17:43:45 +00:00
sta (ZPPtr3),y
2016-08-17 06:25:58 +00:00
2018-10-15 15:39:21 +00:00
.8 ldy #S.PS.hStdIn
2016-08-17 06:25:58 +00:00
.81 lda (pPs),y
2017-01-12 17:43:45 +00:00
sta (ZPPtr3),y
2016-08-17 06:25:58 +00:00
iny
2017-01-12 17:43:45 +00:00
cpy #S.PS.hStdErr+1
2016-08-17 06:25:58 +00:00
bne .81
ldy #S.PS.PID
2016-08-17 06:25:58 +00:00
lda (pPs),y
ldy #S.PS.PPID
2017-01-12 17:43:45 +00:00
sta (ZPPtr3),y
lda #S.PS.F.HOLD
2017-10-27 14:56:46 +00:00
bit PS.Flags
beq .82
2016-08-17 06:25:58 +00:00
ora (pPs)
2018-10-15 06:25:40 +00:00
sta (pPs) HOLD parent PS
.82 lda #S.PS.F.INIT
2017-01-12 17:43:45 +00:00
ora (ZPPtr3)
sta (ZPPtr3) Make this PS Init....
2017-01-12 17:43:45 +00:00
ldy #S.PS.CPID
lda CORE.LastPSID
2017-01-12 17:43:45 +00:00
sta (pPs),y
clc Exit with A=PSID
.9 rts
2016-08-17 06:25:58 +00:00
*--------------------------------------
2018-07-05 05:42:16 +00:00
PS.Load jsr BIN.Load Y,A=filename full path
2016-08-17 06:25:58 +00:00
bcs .9
2017-01-12 17:43:45 +00:00
>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...
2016-08-17 06:25:58 +00:00
txa
ldy #S.PS.hCS
sta (ZPPtr3),y save CS hMem in S.PS
2018-09-19 15:25:42 +00:00
* jsr K.GetMemByID
* jsr PS.SetMemOwner Set Ownership
2018-09-19 15:25:42 +00:00
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
2017-01-12 17:43:45 +00:00
lda (ZPPtr4),y Load DS.SIZE HI
2016-08-17 06:25:58 +00:00
tax
dey
2017-01-12 17:43:45 +00:00
ora (ZPPtr4),y
2016-08-17 06:25:58 +00:00
beq .2 DS.SIZE=0...
lda (ZPPtr4),y
tay
txa Y,A = DS.SIZE
2018-08-11 10:57:57 +00:00
ldx #S.MEM.F.INIT0+S.MEM.F.DATA
jsr MEM.GetMem.YAX
2016-08-17 06:25:58 +00:00
bcs .9
phy
ldy #S.PS.ZP.DATA+1
sta (ZPPtr3),y save pData HI...
dey
pla
sta (ZPPtr3),y save pData LO...
2016-08-17 06:25:58 +00:00
txa
ldy #S.PS.hDS
sta (ZPPtr3),y save DS hMem in S.PS
2018-10-17 15:31:29 +00:00
jsr PS.SetMemOwner Set Ownership
2018-07-05 05:42:16 +00:00
.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
2018-08-11 10:57:57 +00:00
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
2018-07-05 05:42:16 +00:00
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
2016-08-17 06:25:58 +00:00
*--------------------------------------
2018-10-12 15:47:57 +00:00
* PS.DupArgs
2016-08-17 06:25:58 +00:00
* In:
2018-10-12 15:47:57 +00:00
* Y,A = Ptr To Args[]
2016-08-17 06:25:58 +00:00
* Out:
2018-10-12 15:47:57 +00:00
* A = hMem
2018-10-15 06:25:40 +00:00
* X = Count
2016-08-17 06:25:58 +00:00
*--------------------------------------
2018-10-12 15:47:57 +00:00
PS.DupArgs >STYA ZPPtr1
2018-10-15 06:25:40 +00:00
>STYA ZPPtr2
2018-10-15 15:39:21 +00:00
2018-10-15 06:25:40 +00:00
lda #1
sta .7+1
lda #0
sta .8+1 len = 1 for array ending 0
2018-10-15 15:39:21 +00:00
2018-10-15 06:25:40 +00:00
.1 lda (ZPPtr2)
2018-10-15 15:39:21 +00:00
beq .7
2018-10-12 15:47:57 +00:00
ldy #0
.2 iny
2018-10-15 06:25:40 +00:00
lda (ZPPtr2),y
2018-10-12 15:47:57 +00:00
bne .2
tya
sec
2018-10-15 06:25:40 +00:00
adc .7+1
sta .7+1
2018-10-12 15:47:57 +00:00
bcc .3
2018-10-15 06:25:40 +00:00
inc .8+1
2018-10-12 15:47:57 +00:00
.3 tya
sec
2018-10-15 06:25:40 +00:00
adc ZPPtr2
sta ZPPtr2
2018-10-12 15:47:57 +00:00
bcc .1
2018-10-15 06:25:40 +00:00
inc ZPPtr2+1
2018-10-12 15:47:57 +00:00
bra .1
2018-10-15 06:25:40 +00:00
.7 ldy #$ff SELF MODIFIED
.8 lda #$ff SELF MODIFIED
2018-10-15 15:39:21 +00:00
bra PS.DupStrV
2018-10-11 15:23:06 +00:00
*--------------------------------------
* PS.DupEnv
* In:
* A = ENV hMem To Duplicate
* Out:
* A = hMem to new ENV
2018-10-15 06:25:40 +00:00
* X = Count
2018-10-11 15:23:06 +00:00
*--------------------------------------
2018-06-21 15:12:10 +00:00
PS.DupEnv jsr K.GetMemPtr
2017-01-12 17:43:45 +00:00
>STYA ZPPtr1
>LDYAI K.ENV.SIZE
2018-10-12 15:47:57 +00:00
2018-10-15 15:39:21 +00:00
PS.DupStrV jsr K.GetMem
2016-08-17 06:25:58 +00:00
bcs .9
2017-01-12 17:43:45 +00:00
>STYA ZPPtr2
2018-10-15 06:25:40 +00:00
phx save hMem
2018-09-19 15:25:42 +00:00
jsr PS.SetMemOwner Set Ownership
2018-10-15 06:25:40 +00:00
ldx #0 Count
2016-08-17 06:25:58 +00:00
2018-10-15 06:25:40 +00:00
.1 lda (ZPPtr1)
sta (ZPPtr2)
beq .8 Ending \0
2016-08-17 06:25:58 +00:00
2018-10-15 06:25:40 +00:00
inx
ldy #0
2018-10-15 06:25:40 +00:00
.2 iny
lda (ZPPtr1),y
sta (ZPPtr2),y
bne .2
2018-10-15 06:25:40 +00:00
tya
sec
adc ZPPtr1
sta ZPPtr1
bcc .3
2017-01-12 17:43:45 +00:00
inc ZPPtr1+1
2018-10-15 06:25:40 +00:00
.3 tya
sec
adc ZPPtr2
sta ZPPtr2
bcc .1
2017-01-12 17:43:45 +00:00
inc ZPPtr2+1
2016-08-17 06:25:58 +00:00
bra .1
2018-10-15 06:25:40 +00:00
.8 pla hMem
2016-08-17 06:25:58 +00:00
clc
.9 rts
*--------------------------------------
2017-10-27 14:56:46 +00:00
PS.SetMemOwner lda CORE.LastPSID
ldy #S.MEM.OWNERPID
sta (ZPMEMMGR),y
rts
*/--------------------------------------
2018-06-21 15:12:10 +00:00
* # GetPSStatus
2018-06-14 15:31:36 +00:00
* **In:**
* A = PID
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* A = Status Byte
*\--------------------------------------
2018-06-21 15:12:10 +00:00
K.GetPSStatus jsr CORE.GetPSByID
bcs .9
>STYA ZPPtr1
lda (ZPPtr1)
.9 rts
*/--------------------------------------
2018-06-21 15:12:10 +00:00
* # GetPSStat
2018-06-14 15:31:36 +00:00
* **In:**
2018-10-15 15:39:21 +00:00
* Y,A = Ptr to K.PS.MAX*2+1 bytes buffer
2018-10-11 15:23:06 +00:00
* ## RETURN VALUE
* Buffer filled with PS stats
*\--------------------------------------
2018-06-21 15:12:10 +00:00
K.GetPSStat >STYA ZPPtr1
ldx #0
ldy #1
2018-10-17 15:31:29 +00:00
lda CORE.InKernelStats
sta (ZPPtr1),y
iny
.1 lda PS.Table.PID,x
beq .2
2018-10-17 15:31:29 +00:00
lda PS.Table.hPS,x
sta (ZPPtr1),y
iny
2018-10-15 15:39:21 +00:00
lda PS.Table.Stats,x
sta (ZPPtr1),y
iny
.2 inx
2018-10-15 15:39:21 +00:00
cpx #K.PS.MAX
bne .1
.9 tya
lsr
dec
sta (ZPPtr1)
rts
*--------------------------------------
2016-08-17 06:25:58 +00:00
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.PS
LOAD /A2OSX.SRC/SYS/KERNEL.S
2016-08-17 06:25:58 +00:00
ASM