Kernel 0.9.1 : Code reorganization & move to CSTR (CORE: PS Context switching)

This commit is contained in:
Rémy GIBERT 2017-09-19 17:34:01 +02:00
parent f624c10bd7
commit 24efef7d3b
10 changed files with 329 additions and 353 deletions

Binary file not shown.

Binary file not shown.

View File

@ -19,17 +19,20 @@ ZPKERNEL .EQ $0
*--------------------------------------
ZPMEMMGR .EQ $8
*--------------------------------------
pCode .EQ $10
pData .EQ $12
pLocal .EQ $14
pStack .EQ $16
pDrv .EQ $18
pPs .EQ $1A
pDev .EQ $1C
pEvent .EQ $1E
pDrv .EQ $10
pDev .EQ $12
pEvent .EQ $14
pPs .EQ $16
*--------------------------------------
* PS Context : 24 bytes
*--------------------------------------
pCode .EQ $18
pData .EQ $1A
pStack .EQ $1C
pLocal .EQ $1E
ZPBIN .EQ $20
*--------------------------------------
ZPDRV .EQ $30
ZPLIB .EQ $40 32 bytes for TCPIP
*--------------------------------------
@ -58,6 +61,8 @@ K.MLI.PATH .EQ $03B0 64+1 -> $03D0
* Main/Aux $400 -> $7FF : Console Screen
* Main/Aux $800 -> $BFF : System Screen
*--------------------------------------
PS.Table.PID .EQ $0C00 K.PS.MAX
PS.Table.hMem .EQ $0C00+K.PS.MAX
K.Buf256 .EQ $0E00 Main
*--------------------------------------
K.STACK .EQ $0F20 down to $0f00
@ -73,8 +78,6 @@ EvtMgr.Table .EQ $1180 K.EVT.MAX*S.EVT.SIZE=16*8=128b
*--------------------------------------
DevMgr.Table .EQ $1200 K.DEV.MAX*S.DEV.SIZE=32*16=512b
*--------------------------------------
TskMgr.Table .EQ $1400 K.PS.MAX*S.PS.SIZE=32*32=1k
*--------------------------------------
* MemMgr : $1800->$1FFF MAIN/AUX (2 kBytes)
*--------------------------------------
MemMgr.Table .EQ $1800 Slot 0 is Reserved
@ -460,8 +463,10 @@ S.PS.PC .EQ 14
S.PS.ARGC .EQ 16
S.PS.hARGS .EQ 17
S.PS.Context .EQ 24 24 Bytes
*
S.PS .EQ 32
S.PS .EQ 48
*--------------------------------------
* LIB Function Indexes
*--------------------------------------

View File

@ -100,7 +100,7 @@ OApple+1,OApple+2,OApple+3 to switch between screens : Kernel Log, text, DHGR.
## SBIN,Daemons/Commands:
| Name | Status | Comment | K.Ver |
| ---- | ------ | ------- | -----:|
| ---- | ------ | ------- | ------|
| INSDRV | Working | | 0.9 |
| GETTY | Working | | 0.9 |
| LOGIN | In Progress | no auth using /etc/passd yet | 0.9 |
@ -126,6 +126,7 @@ OApple+1,OApple+2,OApple+3 to switch between screens : Kernel Log, text, DHGR.
| | | -P : "prompt message" |
| TIME | Working | |
| SET | Working | |
| SLEEP | Working | |
| STARTPROC | Working | Used in A2osX.startup |
## Shell variables:

View File

@ -67,8 +67,7 @@ CS.INIT ldy #S.PS.ARGC
txa
ldy #hBinName
sta (pData),y
>STA.G hBinName
lda (pPs)
ora #S.PS.F.EVENT Now accept events
@ -239,7 +238,6 @@ Wait.TimeOut sec
.9 rts
*--------------------------------------
CS.END
PRINT.DEBUG.CHAR .AS "0123456789ABCDEF"
MSG.USAGE >CSTR "Usage : GETTY <DEV> <PROGRAM>\r\n"
MSG.TELNET.OPT
* .DA #IAC,#WILL,#TELOPT.BINARY
@ -254,7 +252,7 @@ MSG.TELNET.OPT
.DA #IAC,#SB,#TELOPT.TTYPE,#SB.SEND,#IAC,#SE
.DA #0
MSG.GREETINGS >CSTR "\r\nA2osX-GeTTY\r\n"
TERM >PSTR "TERM"
TERM >CSTR "TERM"
* \e[12h
*--------------------------------------
.DUMMY

View File

@ -6,117 +6,18 @@ AUTO 6
*--------------------------------------
SYS.BASL0 .EQ $800
*--------------------------------------
CORE.Run jsr CORE.PSRun
stx A2osX.RANDOM16
jsr CORE.GetEvents
txa
eor KBD
sta A2osX.RANDOM16+1
bcs .4 CS=no event
jsr CORE.DispatchEvents
bcc .4 CC=All Events Dispatched
jsr CORE.PSSelect0
lda #EvtMgr.Table
sta pEvent
CORE.Run lda CORE.PSCount
sta CORE.Counter
beq CORE.Events
.1 lda (pEvent)
beq .3
.1 ldx CORE.Counter
bmi .2 Ignore & Discard any timer event
lda PS.Table.PID-1,x
beq .7
jsr CORE.DumpEvent
.2 jsr CORE.DestroyEvent
.3 lda pEvent
clc
adc #S.EVT
sta pEvent
lda EVTMGR.COUNT
bne .1
.4 lda A2osX.ASCREEN
cmp #2 is SYS active?
bne .6
ldx CORE.CPULOADI
lda CORE.CPULOADC,x
sta SYS.BASL0+38
dex
bpl .5
ldx #3
.5 stx CORE.CPULOADI
.6 bit OPENAPPLE
bpl CORE.Run
lda KBD
bpl CORE.Run
cmp #"1"
bcc CORE.Run
cmp #"5"
bcs CORE.Run
jsr CORE.ScreenSelect
bra CORE.Run
*--------------------------------------
CORE.DumpEvent ldy #S.EVT-1
.1 >PUSHB (pEvent),y
dey
bpl .1
>LDYAI .2
jmp K.PrintF.YA
.2 >CSTR "!Evt:F=%b,Dev=$%h,LO=$%h,HI=$%h,W1=$%H,W2=$%H\n"
*--------------------------------------
CORE.ScreenSelect
sta KBDSTROBE
and #$0F
cmp A2osX.ASCREEN Same as active screen...nothing to do
beq .8
tax
lda A2osX.SCRNDEVS-1,x
beq .8 No device claimed this screen
jsr K.GetDevByID.A x unmodified.....
bcs .8 ???
stx A2osX.ASCREEN
>STYA pDev
ldx #DEVMGR.CONTROL
jmp pDevJmp
.8 rts
*--------------------------------------
CORE.PSRun >LDYAI TskMgr.Table+S.PS skip PS 0
>STYA pPs
lda TskMgr.Count
sta TskMgr.Idx
.1 dec TskMgr.Idx skip PS 0
beq .8
lda (pPs) get S.PS.F
* bit #S.PS.F.INUSE In use ?
* beq .7
bpl .7
lda PS.Table.hMem-1,x
jsr K.GetMemPtr.A
>STYA pPS
bit #S.PS.F.HOLD Waiting for Another Task to Terminate?
beq .2
@ -156,9 +57,9 @@ CORE.PSRun >LDYAI TskMgr.Table+S.PS skip PS 0
pha save RC
ldy #S.PS.PPID Notify Parent Process for exit code...
lda (pPs),y
jsr CORE.GetPSByID.A will set ZPPtr1 if success
jsr CORE.GetPSByID.A
bcs .5 parent is dead.....skipping...
>STYA ZPPtr1
lda (ZPPtr1) Parent PS is HOLD?
bit #S.PS.F.HOLD
beq .5 no...
@ -180,123 +81,70 @@ CORE.PSRun >LDYAI TskMgr.Table+S.PS skip PS 0
lda (pPs),y
jsr CORE.PSFree.A
.7 lda pPs
clc
adc #S.PS
sta pPs
bcc .1
inc pPs+1
bcs .1 Always
.8 clc
rts
.7 dec CORE.Counter
bne .1
*--------------------------------------
CORE.GetPSByID.A
pha
>LDYAI TskMgr.Table
>STYA ZPPtr1
CORE.Events stx A2osX.RANDOM16
pla
beq .8
sta .20+1
ldx #0
jsr CORE.GetEvents
.1 inx
lda ZPPtr1
clc
adc #S.PS
sta ZPPtr1
bcc .2
inc ZPPtr1+1
txa
eor KBD
sta A2osX.RANDOM16+1
bcs .4 CS=no event
.2 lda (ZPPtr1)
bpl .3
jsr CORE.DispatchEvents
bcc .4 CC=All Events Dispatched
jsr CORE.PSSelect0
lda #EvtMgr.Table
sta pEvent
ldy #S.PS.PID
lda (ZPPtr1),y
.20 cmp #$ff Self Modified
beq .8
.1 lda (pEvent)
beq .3
.3 cpx TskMgr.Count
bmi .2 Ignore & Discard any timer event
jsr CORE.DumpEvent
.2 jsr CORE.DestroyEvent
.3 lda pEvent
clc
adc #S.EVT
sta pEvent
lda EVTMGR.COUNT
bne .1
.9 lda #TSKMGR.ERRNSP
sec
rts
.8 >LDYA ZPPtr1
clc
rts
*--------------------------------------
CORE.PSSelect0 >LDYAI TskMgr.Table Select PS0
>STYA pPs
>LDYA K.STACK
>STYA pStack
rts
*--------------------------------------
CORE.PSSelect ldy #S.PS.hCS
lda (pPs),y
.4 lda A2osX.ASCREEN
cmp #2 is SYS active?
bne .6
jsr K.GetMemPtr.A
>STYA pCode
ldy #S.PS.hDS
lda (pPs),y
beq .1
jsr K.GetMemPtr.A
>STYA pData
ldx CORE.CPULoadI
lda CORE.CPULoadC,x
sta SYS.BASL0+38
dex
bpl .5
.1 ldy #S.PS.hSS
lda (pPs),y
jsr K.GetMemPtr.A
sta pStack+1
ldy #S.PS.SP
lda (pPs),y
sta pStack
ldx #3
clc
rts
*--------------------------------------
CORE.PSLeave rts
*--------------------------------------
* PS.Free.A
* In : A = PID to free
*--------------------------------------
CORE.PSFree.A jsr CORE.GetPSByID.A PS in ZPPtr1
.5 stx CORE.CPULoadI
ldy #S.PS.hARGS
jsr .2
lda (ZPPtr1) get S.PS.F
and #S.PS.F.ENV do we have to discard duplicated env & prefix ?
beq .1
.6 bit OPENAPPLE
bpl .8
ldy #S.PS.hENV
jsr .2
lda KBD
ldy #S.PS.hPREFIX
jsr .2
bpl .8
.1 ldy #S.PS.hSS
jsr .2
cmp #"1"
bcc .8
cmp #"5"
bcs .8
ldy #S.PS.hDS
jsr .2
ldy #S.PS.hCS
jsr .2
lda #0
sta (ZPPtr1) Mark TSKSLOT as free
clc
.9 rts
.2 lda (ZPPtr1),y
beq .9
jmp K.FreeMem.A
jsr CORE.ScreenSelect
.8 jmp CORE.Run
*--------------------------------------
* CORE.GetEvents :
* IN :
@ -369,21 +217,20 @@ CORE.GetEvents lda #EvtMgr.Table
* CC: Event Cleared
*--------------------------------------
CORE.DispatchEvents
>LDYAI TskMgr.Table+S.PS
>STYA pPs
lda TskMgr.Count Number of actual processes...
sta TskMgr.Idx ...to give event list
.1 dec TskMgr.Idx skip PS 0
lda CORE.PSCount
sta CORE.Counter
beq .9
lda (pPs) get S.PS.F
bpl .4
.1 ldx CORE.Counter
* bit #S.PS.F.INUSE In use ?
* beq .4
lda PS.Table.PID-1,x
beq .4
lda PS.Table.hMem-1,x
jsr K.GetMemPtr.A
>STYA pPS
lda (pPs) get S.PS.F
bit #S.PS.F.INIT+S.PS.F.HOLD Init or Waiting for Another Task to Terminate?
bne .4
@ -422,21 +269,105 @@ CORE.DispatchEvents
sta pEvent
bra .2
.4 lda pPs go to next PS in PS list
clc
adc #S.PS
sta pPs
bcc .1
inc pPs+1
bne .1 always
.4 dec CORE.Counter
bne .1
.9 dec
rts
.8 clc
rts
.9 sec
rts
*--------------------------------------
CORE.TskMgrQuit clc
CORE.DumpEvent ldy #S.EVT-1
.1 >PUSHB (pEvent),y
dey
bpl .1
>LDYAI .2
jmp K.PrintF.YA
.2 >CSTR "!Evt:F=%b,Dev=$%h,LO=$%h,HI=$%h,W1=$%H,W2=$%H\n"
*--------------------------------------
CORE.ScreenSelect
sta KBDSTROBE
and #$0F
cmp A2osX.ASCREEN Same as active screen...nothing to do
beq .8
tax
lda A2osX.SCRNDEVS-1,x
beq .8 No device claimed this screen
jsr K.GetDevByID.A x unmodified.....
bcs .8 ???
stx A2osX.ASCREEN
>STYA pDev
ldx #DEVMGR.CONTROL
jmp pDevJmp
.8 rts
*--------------------------------------
CORE.GetPSByID.A
ldx CORE.PSCount
beq .9
.1 cmp PS.Table.PID-1,x
beq .2
dex
bne .1
.9 lda #TSKMGR.ERRNSP
sec
rts
.2 lda PS.TABLE.hMem-1,x
jmp K.GetMemPtr.A
*--------------------------------------
* PS.Free.A
* In : A = PID to free
*--------------------------------------
CORE.PSFree.A jsr CORE.GetPSByID.A PS in ZPPtr1
>STYA ZPPtr1
stx .1+1 Save Offset in PS.Table
ldy #S.PS.hSS
jsr .8
ldy #S.PS.hDS
jsr .8
ldy #S.PS.hCS
jsr .8
ldy #S.PS.hARGS
jsr .8
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 .8
ldy #S.PS.hPREFIX
jsr .8
.1 ldx #$ff Self Modified
stz PS.Table.PID-1,x
lda PS.TABLE.hMem-1,x
.7 jmp K.FreeMem.A
.8 lda (ZPPtr1),y
bne .9
.9 rts
*--------------------------------------
CORE.Quit clc
rts
*--------------------------------------
CORE.DestroyEvent
@ -463,6 +394,38 @@ CORE.DestroyEvent
sta (pEvent)
dec EvtMgr.Count
.9 rts
*--------------------------------------
CORE.PSSelect0 >LDYAI CORE.S.PS0 Select PS0
>STYA pPs
>LDYA K.STACK
>STYA pStack
rts
*--------------------------------------
CORE.PSSelect ldy #S.PS.hCS
lda (pPs),y
jsr K.GetMemPtr.A
>STYA pCode
ldy #S.PS.hDS
lda (pPs),y
beq .1
jsr K.GetMemPtr.A
>STYA pData
.1 ldy #S.PS.hSS
lda (pPs),y
jsr K.GetMemPtr.A
sta pStack+1
ldy #S.PS.SP
lda (pPs),y
sta pStack
clc
rts
*/--------------------------------------
* # Sleep
* Make current process suspend until next RUN
@ -481,41 +444,48 @@ K.Sleep pla get PC LO
sbc pCode+1
iny
sta (pPs),y
lda pStack Save DATA Stack Pointer
ldy #S.PS.SP
sta (pPs),y
lda (pPs)
ora #S.PS.F.SLEEP
sta (pPs)
CORE.PSLeave ldy #S.PS.Context+23
ldx #23
.1 lda pPs,x
sta (pPs),y
dey
dex
bpl .1
clc No error,
rts back to Kernel
*--------------------------------------
CORE.PSWakeUp and #$FF^S.PS.F.SLEEP unmark as SLEEP
CORE.PSWakeUp lda (pPs)
and #$FF^S.PS.F.SLEEP unmark as SLEEP
sta (pPS)
ldy #S.PS.SP
lda (pPs),y
sta pStack
ldy #S.PS.PC
lda (pPs),y
sec Advance PC by one as it was saved by a JSR
adc pCode setup by PS.Select
sta .1+1
sta .8+1
iny
lda (pPs),y
adc pCode+1
sta .1+2
sta .8+2
ldy #S.PS.Context+23
ldx #23
.1 jmp $FFFF
.1 lda (pPs),y
sta pPs,x
dey
dex
bpl .1
.8 jmp $FFFF
*--------------------------------------
CORE.CPULOADI .BS 1
CORE.CPULOADC .AS -"/-\|"
*--------------------------------------
TskMgr.Idx .BS 1
TSKMGR.EVENTCNT .BS 1
*--------------------------------------
DevMgr.Stat .DA DevMgr.NUL.Code
@ -528,8 +498,12 @@ EvtMgr.10TH.CNT .BS 1
EvtMgr.HZ.CNT .BS 1
EvtMgr.Count .BS 1
*--------------------------------------
TskMgr.Count .DA #1 One Slot Busy (Kernel PS=0)
TskMgr.LastID .DA #0
CORE.CPULoadI .BS 1
CORE.CPULoadC .AS -"/-\|"
CORE.Counter .BS 1
CORE.PSCount .DA #0
CORE.LastPSID .DA #0
CORE.S.PS0 .BS S.PS
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.CORE

View File

@ -391,26 +391,29 @@ ENV.SysVarsJmp .DA ENV.SysVarsArgs
*--------------------------------------
ENV.SysVarsArgs lda #1
jsr K.GetArg.A
bcs ENV.SysVarsExit2
bcs .8
>STYA ZPPtr3
.1 lda (ZPPtr3)
beq ENV.SysVarsExit2
beq .8
jsr ENV.AppendPtr3ToBuf
.2 jsr ENV.NextEnvPtr3
lda (ZPPtr3)
beq ENV.SysVarsExit2
beq .8
inx
beq ENV.SysVarsExit2 make sure not overlapping buf 256
beq .8 make sure not overlapping buf 256
lda #' '
sta K.Buf256,x
stx K.ExpandStr.BufLen
jsr ENV.AppendPtr3ToBuf
bra .2
.8 clc
rts
*--------------------------------------
ENV.AppendPtr3ToBuf
ldx K.ExpandStr.BufLen
@ -426,9 +429,8 @@ ENV.AppendPtr3ToBuf
stx K.ExpandStr.BufLen
rts
*--------------------------------------
ENV.SysVarsArgC jsr K.GetArgC Trash Ptr1
bra ENV.SysVarsA
ENV.SysVarsArgC ldy #S.PS.ARGC
.HS 2C
ENV.SysVarsRC ldy #S.PS.RC
.HS 2C
ENV.SysVarsPPID ldy #S.PS.PPID
@ -438,37 +440,52 @@ ENV.SysVarsPID ldy #S.PS.PID
ENV.SysVarsCPID ldy #S.PS.CPID
lda (pPS),y
ENV.SysVarsA sta HEXBUF
stz HEXBUF+1
stz HEXBUF+2
stz HEXBUF+3
jsr HEX2DEC
stz .2+1
stz .3+1
ldy #6 Start at 0000000xxx
ldx #8
sed
.1 iny
lda ASCBUF,y
cmp #'0'
bne .2
.1 asl
pha
.2 lda #$ff Self Modified
adc .2+1
sta .2+1
cpy #9 Print always last char
.3 lda #$ff Self Modified
adc .3+1
sta .3+1
pla
dex
bne .1
.2 ldx K.Buf256
cld
.3 inx
beq ENV.SysVarsExit2
ldx K.ExpandStr.BufLen
lda .3+1
beq .4
sta K.Buf256,x
iny
cpy #10
beq ENV.SysVarsExit
inx
lda ASCBUF,y
bra .3
.4 lda .2+1
lsr
lsr
lsr
lsr
beq .5
ora #$30
sta K.Buf256,x
inx
.5 lda .2+1
and #$0f
ora #$30
sta K.Buf256,x
inx
ENV.SysVarsExit stx K.Buf256
ENV.SysVarsExit2
stx K.ExpandStr.BufLen
clc
rts
*--------------------------------------

View File

@ -406,7 +406,7 @@ PS0Init ldx #S.DEV*2 NUL,SYS
lda #2
sta DevMgr.Count
>LDYAI TskMgr.Table Select Process 0 (Kernel)
>LDYAI CORE.S.PS0 Select Process 0 (Kernel)
>STYA pPs
ldy #S.PS-1
@ -744,28 +744,9 @@ FltMgrInit >LDYAI MSG.FLT
*--------------------------------------
TskMgrInit >LDYAI MSG.TSK
>SYSCALL PrintF.YA
>LDYAI TskMgr.Table+S.PS Clear whole process table except PS0
>STYA .2+1
ldx #K.PS.MAX-1
.1 lda #0
ldy #S.PS-1
.2 sta $ffff,y Self Modified
dey
bpl .2
lda .2+1
clc
adc #S.PS
sta .2+1
bcc .3
inc .2+2
.3 dex
bne .1
jsr CORE.PSSelect0
>LDYAI K.ENV.SIZE get a buffer for ENV
>SYSCALL GetMem0.YA make sure blank!!
bcs .9

View File

@ -351,8 +351,7 @@ K.FreeMem.A phy
bit RRAMWRAMBNK2
bit RRAMWRAMBNK2
>LDYAI TskMgr.Table Select PS0 for proper I/O devices
>STYA pPs
jsr CORE.PSSelect0 Select PS0 for proper I/O devices
jsr DevMgr.SYS.Control

View File

@ -57,26 +57,16 @@ K.CreateProcess.CmdLine .BS 2
* out :
* A = PSID
* we cannot use ZPPtrs1 & 2
* because of calling K.NewStrY.A & S.DupEnv.A
* because of calling K.NewStr.YA & S.DupEnv.A
*--------------------------------------
PS.CreateChild >LDYAI TskMgr.Table+S.PS
>STYA ZPPtr3
PS.CreateChild ldx #0
ldx #0
.1 inx
cpx TskMgr.Count
.1 cpx CORE.PSCount
beq .2
lda (ZPPtr3) Found an empty slot
bpl .3
lda ZPPtr3
clc
adc #S.PS
sta ZPPtr3
bcc .1
inc ZPPtr3+1
lda PS.Table.PID,x
beq .3 Found an empty slot
inx
bra .1
.2 cpx #K.PS.MAX
@ -86,31 +76,39 @@ PS.CreateChild >LDYAI TskMgr.Table+S.PS
sec
rts
.3 inc TskMgr.Count
.3 inc CORE.PSCount
.4 inc TSKMGR.LASTID Get a PSID not alredy running
phx save PS inex
.4 inc CORE.LastPSID Get a PSID not alredy running
beq .4 not = 0
lda TSKMGR.LASTID
lda CORE.LastPSID
jsr CORE.GetPSByID.A
bcc .4
plx
lda CORE.LastPSID
sta PS.Table.PID,x
phx
>LDYAI S.PS
jsr K.GetMem0.YA Blank Everything in this S.PS
bcs .99
>STYA ZPPtr3
txa
plx
sta PS.Table.hMem,x
ldy #S.PS.PID
lda TSKMGR.LASTID
lda CORE.LastPSID
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
sta (ZPPtr3) Mark this PS with ENV flag
ldy #S.PS.hPREFIX copy hPREFIX...
lda (pPs),y
@ -165,10 +163,13 @@ PS.CreateChild >LDYAI TskMgr.Table+S.PS
sta (ZPPtr3) Make this PS Init....
ldy #S.PS.CPID
lda TSKMGR.LASTID
lda CORE.LastPSID
sta (pPs),y
clc Exit with A=PSID
rts
.99 plx
.9 rts
*--------------------------------------
PS.CmdLine2Args >STYA ZPPtr1