Kernel 0.9.1 : KERNEL, Preemtive mode, task switching (bugfix)

This commit is contained in:
Rémy GIBERT 2018-04-13 16:18:48 +01:00
parent 644992f281
commit 3973ebbbed
10 changed files with 113 additions and 86 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -29,7 +29,7 @@ CS.START cld
.DA 0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #64 SS
.DA #8 ZP
.DA 0
*--------------------------------------

View File

@ -21,7 +21,7 @@ CS.START cld
.DA 0
.DA CS.END-CS.START CS
.DA DS.END-DS.START DS
.DA #16 SS
.DA #64 SS
.DA #2 ZP
.DA 0
*--------------------------------------
@ -64,7 +64,34 @@ CS.RUN >LDYA pData
lda (ZPPtr),y
>PUSHA Parent PID
lda (ZPPtr) Get flags
ldy #S.PS.UID
lda (ZPPtr),y
>PUSHA
jsr CS.RUN.DecodeFlags
>PUSHEA.G PS.FLAGS
ldy #S.PS.STATS
lda (ZPPtr),y
>PUSHA CPU%
ldy #S.PS.PID
lda (ZPPtr),y
>PUSHA
>LDYA L.MSG1
>SYSCALL PrintF.YA
.7 >DEC.G PS.COUNT
bne .1
.8
* lda #0 tell Kernel that all done ok, but
sec we do not want to stay in memory
rts
*--------------------------------------
CS.RUN.DecodeFlags
lda (ZPPtr) Get flags
ldy #PS.FLAGS+7
ldx #7
@ -79,27 +106,8 @@ CS.RUN >LDYA pData
pla
dey
dex
bpl .2
>PUSHEA.G PS.FLAGS
ldy #S.PS.STATS
lda (ZPPtr),y
>PUSHA CPU%
ldy #S.PS.PID
lda (ZPPtr),y
>PUSHA PID
>LDYA L.MSG1
>SYSCALL PrintF.YA
.7 >DEC.G PS.COUNT
bne .1
.8
* lda #0 tell Kernel that all done ok, but
sec we do not want to stay in memory
rts
bpl .2
rts
*--------------------------------------
CS.DOEVENT sec
rts
@ -108,9 +116,9 @@ CS.QUIT clc
rts
*--------------------------------------
CS.END
MSG0 .AZ "ID CPU\% Flags PID Command Line\r\n"
MSG1 .AZ "%03d %03d\% %s %03d %s\r\n"
MSG.FLAGS .AS "IRHSED--"
MSG0 .AZ "ID CPU\% Flags UID PID Command Line\r\n"
MSG1 .AZ "%03d %03d\% %s %03d %03d %s\r\n"
MSG.FLAGS .AS "IRHSED-P"
*--------------------------------------
.DUMMY
.OR 0

View File

@ -316,7 +316,8 @@ WRITE .DO SSCIRQ=1
* IRQ Handler
* on exit, CC if handled
*--------------------------------------
.DO SSCIRQ=1
.DO SSCIRQ=1
IRQ ldx DEVSLOTn08F
lda SSC.STATUS-$8F,x
@ -328,6 +329,8 @@ IRQ ldx DEVSLOTn08F
*------------ IRQ In
pha
.1 lda INBUF.HEAD
tay save actual head for later
@ -341,9 +344,10 @@ IRQ ldx DEVSLOTn08F
lda SSC.DATA-$8F,x read data to clear IRQ
sta INBUF,y
.2 lda SSC.STATUS-$8F,x
bit #SSC.STATUS.RDRF incoming char?
bne .1
.2 pla
* lda SSC.STATUS-$8F,x
* bit #SSC.STATUS.RDRF incoming char?
* bne .1
*------------ IRQ Out
@ -363,33 +367,42 @@ IRQ ldx DEVSLOTn08F
sta OUTBUF.TAIL
lda SSC.STATUS-$8F,x
bit #SSC.STATUS.TDRE
bne .4
* lda SSC.STATUS-$8F,x
* bit #SSC.STATUS.TDRE
* bne .4
.8 clc
rts
.9 sec
rts
.FIN
*--------------------------------------
DRV.CS.END
DEVSLOTn08F .BS 1
.DO SSCIRQ=1
INBUF.TAIL .BS 1
INBUF.HEAD .BS 1
OUTBUF.TAIL .BS 1
OUTBUF.HEAD .BS 1
INBUF .BS BUF.SIZE
OUTBUF .BS BUF.SIZE
.FIN
*--------------------------------------
STAT .DO SSCIRQ=1
.DA #S.DSTAT.S.WRITE+S.DSTAT.S.READ+S.DEV.S.IRQ
.ELSE
.DA #S.DSTAT.S.WRITE+S.DSTAT.S.READ
.FIN
.DA #0,#0,#0
>PSTR "Serial Card/Port"
.DA #S.DSTAT.T.CHAR

View File

@ -367,13 +367,14 @@ S.PS.F.HOLD .EQ %00100000
S.PS.F.SLEEP .EQ %00010000
S.PS.F.EVENT .EQ %00001000
S.PS.F.DUPENV .EQ %00000100
S.PS.F.PREEMPTED .EQ %00000001
S.PS.PPID .EQ 1
S.PS.PID .EQ 2
S.PS.CPID .EQ 3
S.PS.hCS .EQ 4
S.PS.hDS .EQ 5
S.PS.hSS .EQ 6
S.PS.ZP.SIZE .EQ 7
S.PS.UID .EQ 7
S.PS.hENV .EQ 8
S.PS.hPREFIX .EQ 9
S.PS.hStdIn .EQ 10
@ -383,14 +384,14 @@ S.PS.RC .EQ 13
S.PS.ARGC .EQ 14
S.PS.hARGS .EQ 15
S.PS.A .EQ 16
S.PS.X .EQ 17
S.PS.Y .EQ 18
S.PS.P .EQ 19
S.PS.PC .EQ 20 WORD
S.PS.S .EQ 22
S.PS.STATS .EQ 16
S.PS.STATS .EQ 23
S.PS.A .EQ 17
S.PS.X .EQ 18
S.PS.Y .EQ 19
S.PS.P .EQ 20
S.PS.PC .EQ 21 WORD
S.PS.ZP.SIZE .EQ 23
S.PS.ZP .EQ 24

View File

@ -29,7 +29,7 @@ CORE.Run lda CORE.PSCount
and #$FF^S.PS.F.HOLD unmark as HOLD
sta (pPs)
.2 jsr CORE.PSEnter Restore at least ZP & Ptrs
.2 jsr CORE.PSSelect Restore at least ZP & Ptrs
lda (pPs) get S.PS.F again
bit #S.PS.F.SLEEP Is this PS sleeping?
@ -39,7 +39,7 @@ CORE.Run lda CORE.PSCount
sta (pPS)
jsr CORE.Resume Restore PC....and JMP to
dec IRQ.InKernel
bcc .7
bcs .5
@ -54,7 +54,7 @@ CORE.Run lda CORE.PSCount
.HS 2C BIT abs
.4 ldx #TSKMGR.RUN
jsr pCodeJmp Call INIT/RUN function
jsr CORE.pCodeJmp Call INIT/RUN function
dec IRQ.InKernel
bcc .7 INIT/RUN/RESUME said CS=QUIT?
@ -77,7 +77,7 @@ CORE.Run lda CORE.PSCount
sta (ZPPtr1),y
.6 ldx #TSKMGR.QUIT Quit this process
jsr pCodeJmp Call QUIT function
jsr CORE.pCodeJmp Call QUIT function
dec IRQ.InKernel
ldy #S.PS.PID
lda (pPs),y
@ -238,7 +238,7 @@ CORE.Dispatch lda CORE.PSCount
bit #S.PS.F.EVENT Accept Events ?
beq .5
jsr CORE.PSEnter
jsr CORE.PSSelect
lda #Evt.Table
sta pEvent Select first event in list
@ -250,7 +250,7 @@ CORE.Dispatch lda CORE.PSCount
beq .3
ldx #TSKMGR.DOEVENT
jsr pCodeJmp Call DOEVENT function
jsr CORE.pCodeJmp Call DOEVENT function
dec IRQ.InKernel
bcs .3 not for this PS, try next event in list
@ -277,17 +277,6 @@ CORE.Dispatch lda CORE.PSCount
.8 clc
rts
*--------------------------------------
pCodeJmp lda pCode+1
pha
lda pCode
pha
php
sei
inc IRQ.InKernel
rti
jmp (pCode)
*--------------------------------------
CORE.Quit clc
rts
@ -429,7 +418,7 @@ CORE.PSSelect0 >LDYAI CORE.S.PS0 Select PS0
>STYA pStack
rts
*--------------------------------------
CORE.PSEnter ldy #S.PS.ZP+ZPBIN.SIZE-1
CORE.PSSelect ldy #S.PS.ZP+ZPBIN.SIZE-1
ldx #ZPBIN.SIZE-1
.1 lda (pPs),y
@ -451,13 +440,22 @@ CORE.PSLeave ldy #S.PS.ZP+ZPBIN.SIZE-1
rts
*--------------------------------------
CORE.Switch php
sec
.HS 2C BIT ABS
*--------------------------------------
CORE.Sleep php
dec IRQ.InKernel
clc
phy
ldy #S.PS.A
sta (pPs),y
lda #S.PS.F.SLEEP
adc #0 C=S.PS.F.PREEMPTED
ora (pPs)
sta (pPs)
txa
iny #S.PS.X
sta (pPs),y
@ -481,15 +479,14 @@ CORE.Sleep php
iny #S.PS.PC+1
sta (pPs),y
iny #S.PS.S
tsx
inx
inx
inx
txa
sta (pPs),y
tay Save !Byte count for later
beq .8
.1 pla
@ -497,25 +494,23 @@ CORE.Sleep php
inx
bne .1
.8 lda (pPs)
ora #S.PS.F.SLEEP
sta (pPs)
.8 tya push CPU Stack BC to restorre on top of Soft Stack
>PUSHA
clc exit to kernel with CC
rts
*--------------------------------------
CORE.Resume ldy #S.PS.S
lda (pPs),y
beq .2
CORE.Resume >PULLA Get !BC
tax
beq .2
.1 >PULLA
pha
inx
bne .1
.2 dey #S.PS.PC+1
.2 ldy #S.PS.PC+1
lda (pPs),y
pha
@ -539,9 +534,11 @@ CORE.Resume ldy #S.PS.S
lda (pPs),y
ply
sei
inc IRQ.InKernel
rti
*--------------------------------------
CORE.pCodeJmp inc IRQ.InKernel
jmp (pCode)
*--------------------------------------
TSKMGR.EVENTCNT .BS 1
*--------------------------------------
@ -564,7 +561,7 @@ CORE.Tick10t .BS 1
CORE.Counter .BS 1
CORE.PSCount .DA #0
CORE.LastPSID .DA #0
CORE.S.PS0 .BS S.PS.hARGS+1
CORE.S.PS0 .BS S.PS.STATS+1
*--------------------------------------
MAN
SAVE /A2OSX.SRC/SYS/KERNEL.S.CORE

View File

@ -141,6 +141,9 @@ Kernel.Init3 sta SETALTZP
dex
bpl .1
lda #$ff Make sure we are in Kernel Mode during setup
sta IRQ.InKernel
jsr MemMgrInit
jsr PS0Init
bcs *
@ -583,8 +586,6 @@ IrqMgrInit >LDYAI MSG.IRQ
lda K.MLI.PARAMS+1
sta IRQ.INTNUM
lda #$ff
sta IRQ.InKernel
plp
jsr IrqMgrInit.TClock

View File

@ -72,21 +72,23 @@ K.IrqHAuxLC.3 pla
php
php make room for 2 additional bytes
php keep track of C
tsx
sec
lda $104,x get RTI PC LO
lda $105,x get RTI PC LO
sbc #1 back one byte, to make it a "RTS" return adddress
sta $104,x
sta $105,x
bcs .1
dec $105,x adjust RTI PC HI
dec $106,x adjust RTI PC HI
.1 lda #CORE.Sleep make a RTI like "jsr CORE.Sleep"
sta $102,x
lda /CORE.Sleep with RTS=PC IRQ-1
.1 lda $104,x get IRQ pushed P
sta $102,x down 2 bytes
lda #CORE.Switch make a RTI like "jsr CORE.Sleep"
sta $103,x
lda /CORE.Switch with RTS=PC IRQ-1
sta $104,x
plp
@ -136,7 +138,12 @@ K.IrqH.Switch inc IRQ.Tick
lda #$A0+'S
eor SYS.BASL0+37
sta SYS.BASL0+37
sta SYS.BASL0+37
ldy #S.PS.STATS
lda (pPs),y
inc
sta (pPs),y
.8 clc exit with V flag set
rts