Kernel 0.9.1 : Code reorganization & move to CSTR (ARGS)

This commit is contained in:
Rémy GIBERT 2017-08-29 17:19:09 +02:00
parent d2f7de5190
commit b52ac88d2b
10 changed files with 444 additions and 469 deletions

Binary file not shown.

Binary file not shown.

379
SYS/KERNEL.S.CORE.txt Normal file
View File

@ -0,0 +1,379 @@
PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*--------------------------------------
SYS.BASL0 .EQ $800
*--------------------------------------
CORE.Run jsr CORE.TskMgrRun
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
>LDYAI TskMgr.Table Select PS0
>STYA pPs
lda #EvtMgr.Table
sta pEvent
.1 lda (pEvent)
beq .3
bmi .2 Ignore & Discard any timer event
jsr RUN.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 SYS.CPULOADI
lda SYS.CPULOADC,x
sta SYS.BASL0+38
dex
bpl .5
ldx #3
.5 stx SYS.CPULOADI
.6 bit OPENAPPLE
bpl CORE.Run
lda KBD
bpl CORE.Run
cmp #"1"
bcc CORE.Run
cmp #"5"
bcs CORE.Run
sta KBDSTROBE
and #$0F
cmp A2osX.ASCREEN Same as active screen...nothing to do
beq CORE.Run
tax
lda A2osX.SCRNDEVS-1,x
beq CORE.Run No device claimed this screen
jsr K.GetDevByID.A x unmodified.....
bcs CORE.Run ???
stx A2osX.ASCREEN
>STYA pDev
ldx #DEVMGR.CONTROL
jsr pDevJmp
jmp CORE.Run
*--------------------------------------
RUN.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"
*--------------------------------------
SYS.CPULOADI .BS 1
SYS.CPULOADC .AS "|/-\"
*--------------------------------------
CORE.TskMgrRun >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
bit #S.PS.F.HOLD Waiting for Another Task to Terminate?
beq .2
ldy #S.PS.CPID
lda (pPs),y
jsr K.GetPSByID.A
bcc .7 yes, running....
lda (pPs) get S.PS.F
and #$FF^S.PS.F.HOLD unmark as HOLD
sta (pPs)
.2 jsr PS.Select
lda (pPS)
bit #S.PS.F.INIT
bne .30
bit #S.PS.F.SLEEP Is this PS sleeping?
beq .3 no, call TSKMGR.RUN
jsr CORE.PSWakeUp
bra .4
.30 and #$FF^S.PS.F.INIT unmark as INIT
sta (pPS)
ldx #TSKMGR.INIT
.HS 2C BIT abs
.3 ldx #TSKMGR.RUN
.31 jsr pCodeJmp Call INIT/RUN function
.4 bcc .7 INIT/RUN said CS=QUIT?
pha save RC
ldy #S.PS.PPID Notify Parent Process for exit code...
lda (pPs),y
jsr K.GetPSByID.A will set ZPPtr1 if success
bcs .5 parent is dead.....skipping...
lda (ZPPtr1) Parent PS is HOLD?
bit #S.PS.F.HOLD
beq .5 no...
eor #S.PS.F.HOLD yes, release hold...
sta (ZPPtr1)
pla ...probably waiting for this PS to terminate....
ldy #S.PS.RC give it RC
sta (ZPPtr1),y
.HS B0 BCS
.5 pla
.6 ldx #TSKMGR.QUIT yes, quit this process
jsr pCodeJmp Call QUIT function
ldy #S.PS.PID
lda (pPs),y
jsr PS.Free.A
.7 lda pPs
clc
adc #S.PS
sta pPs
bcc .1
inc pPs+1
bcs .1 Always
.8 clc
rts
*--------------------------------------
CORE.PSWakeUp 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 setup by PS.Select
sta .1+1
iny
lda (pPs),y
adc pCode+1
sta .1+2
.1 jmp $FFFF
*--------------------------------------
* CORE.DispatchEvents
* IN:
* OUT:
* CS: Not Dispatched
* 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
beq .9
lda (pPs) get S.PS.F
bpl .4
* bit #S.PS.F.INUSE In use ?
* beq .4
bit #S.PS.F.INIT+S.PS.F.HOLD Init or Waiting for Another Task to Terminate?
bne .4
bit #S.PS.F.EVENT Accept Events ?
beq .4
jsr PS.Select
lda #EvtMgr.Table
sta pEvent Select first event in list
lda EVTMGR.COUNT
sta TSKMGR.EVENTCNT
.2 lda (pEvent) Empty event, select next
beq .3
lda (pCode)
cmp #H.BIN.HEADER.BIN65
bne *
ldx #TSKMGR.DOEVENT
jsr pCodeJmp Call DOEVENT function
bcs .3 not for this PS, try next event in list
jsr CORE.DestroyEvent this PS handled the EVT, destroy it...
lda EVTMGR.COUNT
beq .8 no more event, exit
.3 dec TSKMGR.EVENTCNT
beq .4 all EVT submitted to this PS, try other PS
lda pEvent try next EVT to this PS
clc
adc #S.EVT
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
.8 clc
rts
.9 sec
rts
*--------------------------------------
CORE.TskMgrQuit clc
rts
*--------------------------------------
TskMgr.Idx .BS 1
TSKMGR.EVENTCNT .BS 1
*--------------------------------------
* CORE.GetEvents :
* IN :
* OUT :
* CS = no event, A = ERROR
* CC * event in YA
* (pEvent)
*--------------------------------------
CORE.GetEvents lda #EvtMgr.Table
sta pEvent point to start of event list
stz EvtMgr.Count reset Size
lda K.IrkMgr.VBL do we have IRQ enabled for VBL ?
bpl .10 no, regular poll
lda K.IrkMgr.VBLINT
beq .3 no
dec K.IrkMgr.VBLINT
bra .11
.10 lda VBL get VLINE status
tax
eor EvtMgr.VBLState
bpl .3 no change,no tick
txa
sta EvtMgr.VBLState save new
bpl .3 Up2down transition,no tick
.11 inc A2osX.TIMER16
bne .1
inc A2osX.TIMER16+1
.1 dec EvtMgr.HZ.CNT
bne .3 not yet 100ms
ldx A2osX.HZ
stx EvtMgr.HZ.CNT
lda #S.EVT.F.T10TH
dec EvtMgr.10TH.CNT
bne .2
ldx #10
stx EvtMgr.10TH.CNT
ora #S.EVT.F.T1SEC
.2 sta (pEvent)
jsr CORE.GetEvents.Add
.3
sec
lda EvtMgr.Count if 0, exit with CS (from cmp), and A=0 "no event"
beq .9
.8 clc
.9 rts
*--------------------------------------
CORE.GetEvents.Add
inc EvtMgr.Count Add one event to Queue
lda pEvent
clc
adc #S.EVT
sta pEvent
rts if CS, EVT queue full!!! ($100)
*--------------------------------------
CORE.DestroyEvent
lda (pEvent)
beq .9
bit #S.EVT.F.hMEM1
beq .1
pha
ldy #S.EVT.DATALO
lda (pEvent),y
jsr K.FreeMem.A
pla
.1 bit #S.EVT.F.hMEM2
beq .2
ldy #S.EVT.DATAHI
lda (pEvent),y
jsr K.FreeMem.A
.2 lda #0
sta (pEvent)
dec EvtMgr.Count
.9 rts
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.CORE
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM

View File

@ -1,105 +0,0 @@
PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*--------------------------------------
* EVT.GetEvents :
* IN :
* OUT :
* CS = no event, A = ERROR
* CC * event in YA
* (pEvent)
*--------------------------------------
EVT.GetEvents lda #EvtMgr.Table
sta pEvent point to start of event list
stz EvtMgr.Count reset Size
lda K.IrkMgr.VBL do we have IRQ enabled for VBL ?
bpl .10 no, regular poll
lda K.IrkMgr.VBLINT
beq .3 no
dec K.IrkMgr.VBLINT
bra .11
.10 lda VBL get VLINE status
tax
eor EvtMgr.VBLState
bpl .3 no change,no tick
txa
sta EvtMgr.VBLState save new
bpl .3 Up2down transition,no tick
.11 inc A2osX.TIMER16
bne .1
inc A2osX.TIMER16+1
.1 dec EvtMgr.HZ.CNT
bne .3 not yet 100ms
ldx A2osX.HZ
stx EvtMgr.HZ.CNT
lda #S.EVT.F.T10TH
dec EvtMgr.10TH.CNT
bne .2
ldx #10
stx EvtMgr.10TH.CNT
ora #S.EVT.F.T1SEC
.2 sta (pEvent)
jsr EVT.GetEvents.Add
.3
sec
lda EvtMgr.Count if 0, exit with CS (from cmp), and A=0 "no event"
beq .9
.8 clc
.9 rts
*--------------------------------------
EVT.GetEvents.Add
inc EvtMgr.Count Add one event to Queue
lda pEvent
clc
adc #S.EVT
sta pEvent
rts if CS, EVT queue full!!! ($100)
*--------------------------------------
EVT.DestroyEvent
lda (pEvent)
beq .9
bit #S.EVT.F.hMEM1
beq .1
pha
ldy #S.EVT.DATALO
lda (pEvent),y
jsr K.FreeMem.A
pla
.1 bit #S.EVT.F.hMEM2
beq .2
ldy #S.EVT.DATAHI
lda (pEvent),y
jsr K.FreeMem.A
.2 lda #0
sta (pEvent)
dec EvtMgr.Count
.9 rts
*--------------------------------------
EvtMgr.Idx .BS 1
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.EVT
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM

View File

@ -44,7 +44,7 @@ AUTO 6
.BS $BD20-*
*--------------------------------------
GO.Reset jsr GO.A2osX
jmp K.KernelRun
jmp CORE.Run
*--------------------------------------
* *** MUST BE REINTRANT ***
*--------------------------------------

View File

@ -163,7 +163,7 @@ Kernel.Init3 sta SETALTZP
bit RRAMWRAMBNK2
bit RRAMWRAMBNK2
jmp K.KernelRun
jmp CORE.Run
.9 >PUSHA
>LDYAI MSG.StartupErr

View File

@ -235,7 +235,7 @@ PS.CreateChild >LDYAI TskMgr.Table+S.PS
.9 rts
*--------------------------------------
PS.Init >LDYA K.CreateProcess.CmdLine
jsr PS.CmdLine2Args.YA
jsr PS.CmdLine2Args
bcs .9
phy save PTR to Args[0]...
@ -313,7 +313,10 @@ PS.Free.A jsr K.GetPSByID.A PS in ZPPtr1
ldy #S.PS.hPREFIX
jsr PS.Free.A.PsY
.1 ldy #S.PS.hDS
.1 ldy #S.PS.hSS
jsr PS.Free.A.PsY
ldy #S.PS.hDS
jsr PS.Free.A.PsY
ldy #S.PS.hCS
@ -334,13 +337,20 @@ PS.Select ldy #S.PS.hCS
jsr K.GetMemPtr.A
>STYA pCode
ldy #S.PS.hDS
iny
* ldy #S.PS.hDS
lda (pPs),y
beq .8
beq .1
jsr K.GetMemPtr.A
>STYA pData
.1 iny
* ldy #S.PS.hSS
lda (pPs),y
jsr K.GetMemPtr.A
>STYA pStack
.8 clc
rts
*--------------------------------------
@ -372,75 +382,63 @@ PS.DupEnv.A jsr K.GetMemPtr.A
.8 txa
clc
.9 rts
*/--------------------------------------
* # CmdLine2Args.YA
* Convert a CSTR (e.g. : command Line) to Args[]
* ## In:
* Y,A = PTR to String
* ## Out:
* CC : success
* Y,A = PTR to StrArray
* X = hMem
* CS : error
* A = SYS error code
*\--------------------------------------
PS.CmdLine2Args.YA
>STYA ZPPtr1
lda (ZPPtr1) Get mem size STRLEN+1
inc
*--------------------------------------
PS.CmdLine2Args >STYA ZPPtr1
ldy #0
.1 lda (ZPPtr1),y compute strlen in Y,X
beq .2
cmp #'"' skip "" in computation....
beq .1
iny
bne .1 max 255
.2 tya +2 for ending 0 for last string, and endig 0 for array
clc
adc #2
tay
lda #0
bcc .3
inc
jsr K.GetMem.YA
.3 jsr K.GetMem.YA
bcs .9
phx save hMem
phy save PTR.LO
pha save PTR.HI
>STYA ZPPtr2
lda (ZPPtr1)
tax count in src string
stz PS.CmdLine2Args.bInQuote
ldy #0
ldx #0 Arg Count
.4 lda (ZPPtr1),y
beq .8
ldy #0 reset index in dst token
cmp #'"' found a quote ?
bne .5
lda PS.CmdLine2Args.bInQuote
eor #$ff
sta PS.CmdLine2Args.bInQuote
bra .71
.3 inc ZPPtr1 get...
.5 cmp #' '
bne .70
bit PS.CmdLine2Args.bInQuote
bmi .70
inx Found one arg !!!
lda #0
.70 sta (ZPPtr2) yes, set this token len
.71 inc ZPPtr2
bne .72
inc ZPPtr2+1
.72 iny
bne .4
inc ZPPtr1+1
.4 lda (ZPPtr1) ...next char
cmp #' ' found a space ?
bne .6
tya in a token ?
beq .7 no, skip & go to next char
sta (ZPPtr2) yes, set this token len
sec
adc ZPPtr2 advance to next token
sta ZPPtr2
bcc .5
inc ZPPtr2+1
.5 ldy #0 reset index in dst token
bra .7
.6 iny add char to token
sta (ZPPtr2),y
.7 dex end of src string?
bne .3 no...next char...
tya yes, are we in a token ?
beq .8
sta (ZPPtr2) yes, set last token len
sec
adc ZPPtr2 advance to next token
sta ZPPtr2
bcc .8
inc ZPPtr2+1
.8 lda #0
sta (ZPPtr2) set Array Ending 0
@ -450,6 +448,8 @@ PS.CmdLine2Args.YA
plx get back hMem
clc
.9 rts
PS.CmdLine2Args.bInQuote
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.PS

View File

@ -1,104 +0,0 @@
PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*--------------------------------------
SYS.BASL0 .EQ $800
*--------------------------------------
K.KernelRun jsr TSK.TskMgrRun
stx A2osX.RANDOM16
jsr EVT.GetEvents
txa
eor KBD
sta A2osX.RANDOM16+1
bcs .4 CS=no event
jsr TSK.DispatchEvents
bcc .4 CC=All Events Dispatched
>LDYAI TskMgr.Table Select PS0
>STYA pPs
lda #EvtMgr.Table
sta pEvent
.1 lda (pEvent)
beq .3
bmi .2 Ignore & Discard any timer event
jsr RUN.DumpEvent
.2 jsr EVT.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 SYS.CPULOADI
lda SYS.CPULOADC,x
sta SYS.BASL0+38
dex
bpl .5
ldx #3
.5 stx SYS.CPULOADI
.6 bit OPENAPPLE
bpl K.KernelRun
lda KBD
bpl K.KernelRun
cmp #"1"
bcc K.KernelRun
cmp #"5"
bcs K.KernelRun
sta KBDSTROBE
and #$0F
cmp A2osX.ASCREEN Same as active screen...nothing to do
beq K.KernelRun
tax
lda A2osX.SCRNDEVS-1,x
beq K.KernelRun No device claimed this screen
jsr K.GetDevByID.A x unmodified.....
bcs K.KernelRun ???
stx A2osX.ASCREEN
>STYA pDev
ldx #DEVMGR.CONTROL
jsr pDevJmp
jmp K.KernelRun
*--------------------------------------
RUN.DumpEvent ldy #S.EVT-1
.1 >PUSHB (pEvent),y
dey
bpl .1
>LDYAI MSG.DumpEvent
jmp K.PrintF.YA
*--------------------------------------
MSG.DumpEvent >CSTR "!Evt:F=%b,Dev=$%h,LO=$%h,HI=$%h,W1=$%H,W2=$%H\n"
SYS.CPULOADI .BS 1
SYS.CPULOADC .AS "|/-\"
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.RUN
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM

View File

@ -1,193 +0,0 @@
PR#3
PREFIX /A2OSX.BUILD
LOMEM $A00
INC 1
AUTO 6
*--------------------------------------
* TSK.TskMgrRun
*--------------------------------------
TSK.TskMgrRun >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
bit #S.PS.F.HOLD Waiting for Another Task to Terminate?
beq .2
ldy #S.PS.CPID
lda (pPs),y
jsr K.GetPSByID.A
bcc .7 yes, running....
lda (pPs) get S.PS.F
and #$FF^S.PS.F.HOLD unmark as HOLD
sta (pPs)
.2 jsr PS.Select
lda (pPS)
bit #S.PS.F.INIT
bne .30
bit #S.PS.F.SLEEP Is this PS sleeping?
beq .3 no, call TSKMGR.RUN
jsr TSK.PSWakeUp
bra .4
.30 and #$FF^S.PS.F.INIT unmark as INIT
sta (pPS)
ldx #TSKMGR.INIT
.HS 2C BIT abs
.3 ldx #TSKMGR.RUN
.31 jsr pCodeJmp Call INIT/RUN function
.4 bcc .7 INIT/RUN said CS=QUIT?
pha save RC
ldy #S.PS.PPID Notify Parent Process for exit code...
lda (pPs),y
jsr K.GetPSByID.A will set ZPPtr1 if success
bcs .5 parent is dead.....skipping...
lda (ZPPtr1) Parent PS is HOLD?
bit #S.PS.F.HOLD
beq .5 no...
eor #S.PS.F.HOLD yes, release hold...
sta (ZPPtr1)
pla ...probably waiting for this PS to terminate....
ldy #S.PS.RC give it RC
sta (ZPPtr1),y
.HS B0 BCS
.5 pla
.6 ldx #TSKMGR.QUIT yes, quit this process
jsr pCodeJmp Call QUIT function
ldy #S.PS.PID
lda (pPs),y
jsr PS.Free.A
.7 lda pPs
clc
adc #S.PS
sta pPs
bcc .1
inc pPs+1
bcs .1 Always
.8 clc
rts
*--------------------------------------
TSK.PSWakeUp 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 setup by PS.Select
sta .1+1
iny
lda (pPs),y
adc pCode+1
sta .1+2
.1 jmp $FFFF
*--------------------------------------
* TSK.DispatchEvents
* IN:
* OUT:
* CS: Not Dispatched
* CC: Event Cleared
*--------------------------------------
TSK.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
beq .9
lda (pPs) get S.PS.F
bpl .4
* bit #S.PS.F.INUSE In use ?
* beq .4
bit #S.PS.F.INIT+S.PS.F.HOLD Init or Waiting for Another Task to Terminate?
bne .4
bit #S.PS.F.EVENT Accept Events ?
beq .4
jsr PS.Select
lda #EvtMgr.Table
sta pEvent Select first event in list
lda EVTMGR.COUNT
sta TSKMGR.EVENTCNT
.2 lda (pEvent) Empty event, select next
beq .3
lda (pCode)
cmp #H.BIN.HEADER.BIN65
bne *
ldx #TSKMGR.DOEVENT
jsr pCodeJmp Call DOEVENT function
bcs .3 not for this PS, try next event in list
jsr EVT.DestroyEvent this PS handled the EVT, destroy it...
lda EVTMGR.COUNT
beq .8 no more event, exit
.3 dec TSKMGR.EVENTCNT
beq .4 all EVT submitted to this PS, try other PS
lda pEvent try next EVT to this PS
clc
adc #S.EVT
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
.8 clc
rts
.9 sec
rts
*--------------------------------------
TSK.TskMgrQuit clc
rts
*--------------------------------------
TskMgr.Idx .BS 1
TSKMGR.EVENTCNT .BS 1
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.TSK
LOAD /A2OSX.SRC/SYS/KERNEL.S
ASM

View File

@ -43,12 +43,10 @@ A2osX.D2 .PH $D000
.INB /A2OSX.SRC/SYS/KERNEL.S.PS
.INB /A2OSX.SRC/SYS/KERNEL.S.ARG
.INB /A2OSX.SRC/SYS/KERNEL.S.ENV
.INB /A2OSX.SRC/SYS/KERNEL.S.EVT
.INB /A2OSX.SRC/SYS/KERNEL.S.TSK
.INB /A2OSX.SRC/SYS/KERNEL.S.RUN
.EP
A2osX.E0 .PH $E000
.INB /A2OSX.SRC/SYS/KERNEL.S.JMP
.INB /A2OSX.SRC/SYS/KERNEL.S.CORE
.INB /A2OSX.SRC/SYS/KERNEL.S.DAT
.INB /A2OSX.SRC/SYS/KERNEL.S.IRQ
.INB /A2OSX.SRC/SYS/KERNEL.S.MEM