Work on the scheduler and interrupt handling code

This commit is contained in:
Elliot Nunn 2018-03-23 17:23:06 +08:00
parent f1df639613
commit 123c1e4bee
19 changed files with 866 additions and 674 deletions

View File

@ -88,7 +88,7 @@ MSR ds.l 1 ; 0a4 ; (SPAC) copied from kdp by CreateTask
org 0xc4
MQ ds.l 1 ; 0c4 ; 601 only
EDPOffsetSWIRelated ds.l 1 ; 0c8
PriorityShifty ds.l 1 ; 0cc ; if low nybble is empty, InitRDYQs sets this to 2
PriorityShifty ds.l 1 ; 0cc ; if low nybble is empty, SchInit sets this to 2
SWIEventGroupID ds.l 1 ; 0d0 ; what?
XER ds.l 1 ; 0d4
VectorSaveArea ds.l 1 ; 0d8 ; AltiVec hack: vector registers don't fit in CB!

View File

@ -328,7 +328,7 @@ VMDispatchCountTblPtr ds.l 1 ; 128, kdp+ee8
ds.l 1
ds.l 1
MPDispatchCountTblPtr ds.l 1 ; 134, kdp+ef4 ; ???????
AddrSpcSetCtr ds.l 1 ; 138, kdp+ef8 ; incremented by SetSpaceSRsAndBATs
AddrSpcSetCtr ds.l 1 ; 138, kdp+ef8 ; incremented by SchSwitchSpace
IDCtr ds.l 1 ; 13c, kdp+efc
org 0x160
@ -399,9 +399,7 @@ ProcessorFlags ds.l 1 ; 048, kdp+f68 ; flags to specify processor features
org 0x05e
SetToZero ds.w 1 ; 05e, kdp+f7e ; by same code that sets below
CpuClockRateHzCopy ds.l 1 ; 060, kdp+f80 ; copies by Init.s
BusClockRateHzCopy ds.l 1 ; 064, kdp+f84 ; copies by Init.s
DecClockRateHzCopy ds.l 1 ; 068, kdp+f88 ; copies by Init.s
ClockRates ds.b 16*4 ; 060:0a0, kdp:f80:fc0 ; 16b blks of cpu/bus/dec/?? speeds (Hz)
endr

View File

@ -139,13 +139,13 @@ kFlag17 equ 17
kFlag18 equ 18
kFlag19 equ 19
kFlag20 equ 20
kFlag21 equ 21
kFlagPMF equ 21 ; set by MPMarkPMFTask, means perf monitor
kFlag22 equ 22
kFlag23 equ 23
kFlag24 equ 24
kFlag25 equ 25 ; set for idle1, idle2
kFlag26 equ 26 ; set for blue
kFlag27 equ 27 ; set on SWI
kFlag68kInterrupt equ 27 ; set on SWI (meaning 68k, or 68k interrupt?)
kFlag28 equ 28 ; set for blue
kFlag29 equ 29
kFlag30 equ 30
@ -164,11 +164,7 @@ VectorSaveArea ds.l 1 ; 08c
ds.l 1 ; 094
ds.l 1 ; 098
NotificationPtr ds.l 1 ; 09c
SemaphoreLLL ds.l 4 ; 0a0:0b0
Zero ds.l 1 ; 0b0
One ds.l 1 ; 0b4
ds.l 1 ; 0b8
ds.l 1 ; 0bc
Semaphore ds.b 32 ; 0a0:0c0 ; Zero and One were fields
Zero1 ds.l 1 ; 0c0
Zero2 ds.l 1 ; 0c4
CreateTime1 ds.d 1 ; 0c8
@ -178,7 +174,7 @@ CreateTime2 ds.d 1 ; 0d0
Zero3 ds.l 1 ; 0e0
Zero4 ds.l 1 ; 0e4
Zero5 ds.l 1 ; 0e8
ds.l 1 ; 0ec
SomeLabelField ds.l 1 ; 0ec
YellowVecTblPtr ds.l 1 ; 0f0
ExceptionHandlerID ds.l 1 ; 0f4 ; a queue
ErrToReturnIfIDie ds.l 1 ; 0f8
@ -275,7 +271,7 @@ Size equ *
ReadyQueue record 0,INCR
LLL ds.l 4 ; 00:10 ; nothing fancy, freeform contains priority flag
Counter ds.l 1 ; 10 ; InitRDYQs sets, TaskReadyAsNext bumps, major_0x13e4c decs
Counter ds.l 1 ; 10 ; SchInit sets, SchRdyTaskLater bumps, major_0x13e4c decs
TotalWeight ds.l 1 ; 14 ; divide available time by these
Timecake ds.d 1 ; 18 ; period of ~1ms, 8ms, 64ms, 512ms
@ -386,12 +382,46 @@ kSignature equ 'CPU '
ID ds.l 1 ; 00
Signature ds.l 1 ; 04
LLL ds.l 4 ; 08:18 ; member of CGRP
Eff ds.l 1 ; 18 ; contains 0x0000000f ; cannot delete if this field & 9
Flags ds.l 1 ; 18 ; contains 0x0000000f ; cannot delete if this field & 9
IdleTaskPtr ds.l 1 ; 1c
EWABase ds.b 800 ; negative-indexed parts of EWA
EWA ds.b 128 ; positive-indexed parts of EWA
kFlag0 equ 0
kFlag1 equ 1
kFlag2 equ 2
kFlag3 equ 3
kFlag4 equ 4
kFlag5 equ 5
kFlag6 equ 6
kFlag7 equ 7
kFlag8 equ 8
kFlag9 equ 9
kFlag10 equ 10
kFlag11 equ 11
kFlag12 equ 12
kFlag13 equ 13
kFlag14 equ 14
kFlag15 equ 15
kFlag16 equ 16
kFlag17 equ 17
kFlag18 equ 18
kFlag19 equ 19
kFlag20 equ 20
kFlag21 equ 21
kFlag22 equ 22
kFlag23 equ 23
kFlag24 equ 24
kFlag25 equ 25
kFlag26 equ 26
kFlag27 equ 27
kFlagScheduled equ 28
kFlag29 equ 29
kFlag30 equ 30
kFlag31 equ 31
Size equ *
endr
@ -555,7 +585,7 @@ LogicalBase ds.l 1 ; 24
LogicalEnd ds.l 1 ; 28 ; the last valid address in the area
Length ds.l 1 ; 2c ; in actual bytes!
LogicalSeparation ds.l 1 ; 30 ; min logical distance to any other area
ds.l 1 ; 34
Counter ds.l 1 ; 34
BytesMapped ds.l 1 ; 38 ; total size of pages actually mapped to me
FaultCtrArrayPtr ds.l 1 ; 3c ; in paged areas, tracks how many times pages are added to HTAB
PageMapArrayPtr ds.l 1 ; 40 ; in paged areas, stores PTE template for each page

View File

@ -396,7 +396,7 @@ SIGPCallR10 ds.l 1 ; -21c, cpu+124
SchEvalFlag ds.b 1 ; -118, cpu+228
TaskPriority ds.b 1 ; -117, cpu+229
CPUIndex ds.w 1 ; -116, cpu+22a
ds.l 1 ; -114, cpu+22c
WeMightClear ds.l 1 ; -114, cpu+22c ; still boots if not cleared
ds.l 1 ; -110, cpu+230
ds.l 1 ; -10c, cpu+234
ds.l 1 ; -108, cpu+238
@ -408,7 +408,7 @@ CPUIndex ds.w 1 ; -116, cpu+22a
ds.l 1 ; -0f0, cpu+250
ds.l 1 ; -0ec, cpu+254
ds.l 1 ; -0e8, cpu+258
ds.l 1 ; -0e4, cpu+25c
SpecialAreaPtr ds.l 1 ; -0e4, cpu+25c
ds.l 1 ; -0e0, cpu+260
ds.l 1 ; -0dc, cpu+264
ds.l 1 ; -0d8, cpu+268
@ -504,6 +504,39 @@ r31 ds.l 1 ; 07c, cpu+3bc
; Fun fact: offsets past here contain the main kernel globals
; ("Kernel Data Page"), but only on CPU-0.
kFlag0 equ 0
kFlag1 equ 1
kFlag2 equ 2
kFlag3 equ 3
kFlag4 equ 4
kFlag5 equ 5
kFlag6 equ 6
kFlag7 equ 7
kFlag8 equ 8
kFlag9 equ 9
kFlagBlue equ 10 ; could mean "currently in interrupt mode"
kFlag11 equ 11
kFlag12 equ 12
kFlag13 equ 13
kFlag14 equ 14
kFlag15 equ 15
kFlag16 equ 16
kFlag17 equ 17
kFlag18 equ 18
kFlag19 equ 19
kFlag20 equ 20
kFlag21 equ 21
kFlag22 equ 22
kFlag23 equ 23
kFlag24 equ 24
kFlag25 equ 25
kFlag26 equ 26
kFlag27 equ 27
kFlag28 equ 28
kFlag29 equ 29
kFlag30 equ 30
kFlag31 equ 31
endr

View File

@ -33,7 +33,7 @@
; major_0x12b94
; InitTMRQs
; StartTimeslicing
; InitRDYQs
; SchInit
; major_0x14bcc
; panic
; major_0x18040
@ -360,7 +360,7 @@ printd_0x120
; createarea
; ExtendPool
; major_0x12b94
; InitRDYQs
; SchInit
; major_0x14bcc
; panic
; print_xpt_info

View File

@ -175,13 +175,13 @@ FinishInitBuiltin
; Copy some choice values out of KDP's copy of NKProcessorInfo
lwz r9, KDP.ProcessorInfo + NKProcessorInfo.DecClockRateHz(r1)
stw r9, KDP.ProcessorInfo + NKProcessorInfo.DecClockRateHzCopy(r1)
stw r9, KDP.ProcessorInfo + NKProcessorInfo.ClockRates + 8(r1)
lwz r9, KDP.ProcessorInfo + NKProcessorInfo.BusClockRateHz(r1)
stw r9, KDP.ProcessorInfo + NKProcessorInfo.BusClockRateHzCopy(r1)
stw r9, KDP.ProcessorInfo + NKProcessorInfo.ClockRates + 4(r1)
lwz r9, KDP.ProcessorInfo + NKProcessorInfo.CpuClockRateHz(r1)
stw r9, KDP.ProcessorInfo + NKProcessorInfo.CpuClockRateHzCopy(r1)
stw r9, KDP.ProcessorInfo + NKProcessorInfo.ClockRates + 0(r1)
li r9, 0
sth r9, KDP.ProcessorInfo + NKProcessorInfo.SetToZero(r1)
@ -873,7 +873,7 @@ SetProcessorFlags
; Actually populate something useful (still have one unused long)
lisori r8, 15
stw r8, CPU.Eff(r31)
stw r8, CPU.Flags(r31)
; Matches code in KCCreateCpuStruct very closely
@ -1094,7 +1094,7 @@ SetProcessorFlags
; One ready for each task priority (critical, etc)
bl InitRDYQs
bl SchInit
@ -1102,7 +1102,7 @@ SetProcessorFlags
lwz r8, EWA.PA_CurAddressSpace(r1)
li r9, 0
bl SetSpaceSRsAndBATs
bl SchSwitchSpace
@ -1192,14 +1192,14 @@ SetProcessorFlags
; CLOB r16, r17, r18
mr r8, r31
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
; Do some things I do not understand
bl major_0x14af8_0xa0
bl FlagSchEval
bl StartTimeslicing
@ -1255,7 +1255,7 @@ av set PSA.AVFeatureBit
; Point task ECB at the idle loop within the nanokernel code
lwz r8, KDP.PA_NanoKernelCode(r1)
llabel r26, IdleCode
llabel r26, SchIdleTask
add r8, r8, r26
stw r8, Task.ContextBlock + ContextBlock.CodePtr(r31)
@ -1283,7 +1283,7 @@ av set PSA.AVFeatureBit
; CLOB r16, r17, r18
mr r8, r31
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
@ -1865,7 +1865,7 @@ ReconcileMemory
mfsprg r8, 0
mtxer r9
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b kcPrioritizeInterrupts

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,7 @@ MaxMPCallCount equ 134
kcMPDispatch ; reached by `sc`, or `twi *, *, 8`
bl Save_r14_r31
bl SchSaveStartingAtR14
lwz r8, EWA.r6(r8) ; clobbers our EWA pointer :(
lwz r14, KDP.PA_NanoKernelCode(r1) ; but r14...
@ -670,7 +670,7 @@ ReleaseAndReturnMPCall ; OUTSIDE REFERER
; BlockMPCall
; KCGetCpuCount
; MPCall_6
; KCYieldWithHint
; MPYieldWithHint
; KCCpuPlugin
; NKPrintHex
; NKPrintDecimal
@ -699,15 +699,15 @@ TrulyCommonMPCallReturnPath ; OUTSIDE REFERER
bc BO_IF_NOT, 10, @block
;return immediately
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b IntReturn
@block
b RescheduleAndReturn
b SchEval
; MPCall_0
; Called after MPLibrary creates a new structure
DeclareMPCall 0, MPCall_0
@ -716,8 +716,10 @@ MPCall_0 ; OUTSIDE REFERER
mr r30, r7
mr r29, r6
bne+ ReturnMPCallOOM
; Fail if this page is outside of the PAR
rlwinm. r4, r3, 20, 12, 31
lwz r9, 0x06a8(r1)
lwz r9, KDP.PrimaryAddrRangePages(r1)
beq+ ReturnMPCallOOM
cmplw r4, r9
bge+ ReturnMPCallOOM
@ -909,17 +911,14 @@ MPRegisterCpuPlugin
; KCGetCpuCount
; Called by MPProcessors and MPProcessorsScheduled
; > r3 = 0:all, 1:scheduled
; ARG bool r3 scheduled_only
; RET int r3
; < r3 = cpu_count
DeclareMPCall 3, MPProcessors
DeclareMPCall 3, KCGetCpuCount
KCGetCpuCount ; OUTSIDE REFERER
MPProcessors
mfsprg r15, 0
lwz r14, EWA.CPUBase + CPU.LLL + LLL.Freeform(r15)
@ -936,9 +935,9 @@ KCGetCpuCount ; OUTSIDE REFERER
; ARG AddressSpaceID r3
; RET AddressSpaceID r3, ??? r4, ProcessStructID r5
DeclareMPCall 4, KCCreateProcess
DeclareMPCall 4, MPCreateProcess
KCCreateProcess ; OUTSIDE REFERER
MPCreateProcess
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
@ -991,9 +990,9 @@ KCCreateProcess ; OUTSIDE REFERER
DeclareMPCall 5, MPCall_5
DeclareMPCall 5, MPTerminateProcess
MPCall_5 ; OUTSIDE REFERER
MPTerminateProcess
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
@ -1069,12 +1068,12 @@ MPCall_6_0xb4
mr r8, r31
bl TaskUnready
bl SchTaskUnrdy
li r16, Task.kNominalPriority
stb r16, Task.Priority(r31)
bl TaskReadyAsPrev
bl SchRdyTaskNow
mr r8, r31
bl FlagSchEvaluationIfTaskRequires
@ -1083,44 +1082,51 @@ MPCall_6_0xb4
; KCYieldWithHint
; Implements MPYield (null argument)
; Caller gets its priority set to nominal
DeclareMPCall 13, KCYieldWithHint
; ARG TaskID r3 (null for MPYield)
; RET OSStatus r3
KCYieldWithHint ; OUTSIDE REFERER
DeclareMPCall 13, MPYieldWithHint
MPYieldWithHint
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
mfsprg r16, 0
rlwinm. r8, r7, 0, 10, 10
lwz r17, KDP.PA_ECB(r1)
lwz r31, -0x0008(r16)
beq- KCYieldWithHint_0x68
clrlwi. r8, r3, 0x1f
lwz r31, EWA.PA_CurTask(r16)
beq- @i_am_important ; not 68k mode?
clrlwi. r8, r3, 31
lwz r8, ContextBlock.PriorityShifty(r17)
rlwinm r8, r8, 0, 24, 21
oris r8, r8, 0x8000
stw r8, ContextBlock.PriorityShifty(r17)
beq- KCYieldWithHint_0x68
lbz r16, 0x0019(r31)
cmpwi r16, 0x02
bge- KCYieldWithHint_0x7c
mr r8, r31
bl TaskUnready
li r16, 0x02
stb r16, 0x0019(r31)
bl TaskReadyAsNext
b KCYieldWithHint_0x7c
beq- @i_am_important ; MPYield call
KCYieldWithHint_0x68
; If this task is
lbz r16, Task.Priority(r31)
cmpwi r16, Task.kNominalPriority
bge- @return
mr r8, r31
bl TaskUnready
li r16, 0x02
stb r16, 0x0019(r31)
bl TaskReadyAsPrev
bl SchTaskUnrdy
li r16, Task.kNominalPriority
stb r16, Task.Priority(r31)
bl SchRdyTaskLater
b @return
KCYieldWithHint_0x7c
@i_am_important
mr r8, r31
bl SchTaskUnrdy
li r16, Task.kNominalPriority
stb r16, Task.Priority(r31)
bl SchRdyTaskNow
@return
mr r8, r31
bl FlagSchEvaluationIfTaskRequires
_AssertAndRelease PSA.SchLock + Lock.Count, scratch=r16
@ -1128,32 +1134,35 @@ KCYieldWithHint_0x7c
DeclareMPCall 33, MPCall_33
; ARG AbsoluteTime r3/r4
; RET OSStatus r3
MPCall_33 ; OUTSIDE REFERER
rlwinm. r8, r7, 0, 10, 10 ; Contains CpuFlags
DeclareMPCall 33, MPDelayUntil
MPDelayUntil
rlwinm. r8, r7, 0, EWA.kFlagBlue, EWA.kFlagBlue
bne+ ReturnMPCallBlueBlocking
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
b MPCall_55_0x60
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
b _MPDelayUntilCommon
; This version is allowed while the blue task is running
; MPCall_55
; ARG AbsoluteTime r3/r4
; RET OSStatus r3
; Xrefs:
; kcMPDispatch
; MPCall_33
DeclareMPCall 55, MPDelayUntilSys
DeclareMPCall 55, MPCall_55
MPDelayUntilSys
MPCall_55 ; OUTSIDE REFERER
rlwinm. r8, r7, 0, 10, 10
rlwinm. r8, r7, 0, EWA.kFlagBlue, EWA.kFlagBlue
lwz r16, KDP.NanoKernelInfo + NKNanoKernelInfo.ExternalIntCount(r1)
beq- MPCall_55_0x60
beq- _MPDelayUntilCommon
; Why the hell are we counting interrupts?
lwz r17, PSA.OtherSystemContextPtr(r1)
lwz r18, KDP.PA_ECB(r1)
cmpw r16, r17
@ -1165,18 +1174,19 @@ MPCall_55 ; OUTSIDE REFERER
oris r8, r8, 0x8000
stw r8, ContextBlock.PriorityShifty(r18)
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
_Lock PSA.SchLock, scratch1=r16, scratch2=r17
lwz r16, PSA.BlueSpinningOn(r1)
cmpwi r16, -1
li r16, 0
bne- MPCall_55_0x60
bne- _MPDelayUntilCommon
stw r16, PSA.BlueSpinningOn(r1)
b ReleaseAndReturnZeroFromMPCall
MPCall_55_0x60 ; OUTSIDE REFERER
_MPDelayUntilCommon
mfsprg r16, 0
li r17, 1
@ -1196,7 +1206,7 @@ MPCall_55_0x60 ; OUTSIDE REFERER
bl EnqueueTimer
mr r8, r31
bl TaskUnready
bl SchTaskUnrdy
addi r16, r1, PSA.DelayQueue
addi r17, r31, Timer.QueueLLL
@ -1559,7 +1569,7 @@ KCCreateCpuStruct_0x68
lisori r8, 11
lisori r8, 6
stw r8, CPU.Eff(r31)
stw r8, CPU.Flags(r31)
@ -1622,7 +1632,7 @@ MPDeleteProcessor
mr r31, r8
bne+ ReleaseAndReturnMPCallInvalidIDErr
lwz r16, CPU.Eff(r31)
lwz r16, CPU.Flags(r31)
lisori r17, 9
and. r17, r17, r16
bne+ ReleaseAndReturnMPCallOOM
@ -1666,7 +1676,7 @@ KCStartCPU ; OUTSIDE REFERER
bne+ ReleaseAndReturnMPCallInvalidIDErr
mr r30, r8
lwz r16, CPU.Eff(r30)
lwz r16, CPU.Flags(r30)
rlwinm. r8, r16, 0, 28, 28
bne+ ReleaseAndReturnZeroFromMPCall
@ -1727,7 +1737,7 @@ KCStartCPU ; OUTSIDE REFERER
lwz r8, KDP.PA_NanoKernelCode(r1)
llabel r26, IdleCode
llabel r26, SchIdleTask
add r8, r8, r26
stw r8, Task.ContextBlock + ContextBlock.CodePtr(r31)
@ -1822,16 +1832,16 @@ KCStopScheduling ; OUTSIDE REFERER
oris r17, r17, 0x80
stw r17, 0x0064(r31)
mr r8, r31
bl TaskUnready
bl SchTaskUnrdy
li r17, 0x00
stb r17, 0x0019(r31)
mr r8, r31
bl TaskReadyAsNext
bl SchRdyTaskLater
bl CalculateTimeslice
mr r8, r31
bl major_0x14af8_0xa0
bl FlagSchEval
lwz r8, 0x064c(r1)
llabel r9, StopProcessor
llabel r9, SchIdleTaskStopper
add r8, r8, r9
stw r8, 0x01fc(r31)
@ -1853,7 +1863,7 @@ MPCpuPlugin
; Arguments in registers
li r8, 0
; Hopefully returns via kcReturnFromInterrupt? Geez...
; Hopefully returns via kcSchExitInterrupt? Geez...
bl SIGP
mr r3, r8
@ -2045,13 +2055,13 @@ KCMarkPMFTask ; OUTSIDE REFERER
; Insert bit 31 of r4 into bit 21 of these flags
lwz r17, Task.Flags(r31)
rlwimi r17, r4, 10, 21, 21
rlwimi r17, r4, 10, Task.kFlagPMF, Task.kFlagPMF
stw r17, Task.Flags(r31)
; Don't know what this does!
mr r8, r31
bl major_0x14af8_0xa0
bl FlagSchEval
b ReleaseAndReturnZeroFromMPCall
@ -2129,18 +2139,28 @@ NKLocateInfoRecord
DeclareMPCall 108, MPCall_108
; ARG int r3 stop
; long r4 CpuClockRateHz
; long r5 BusClockRateHz
; long r6 DecClockRateHz
; RET OSStatus r3
MPCall_108 ; OUTSIDE REFERER
cmplwi r3, 0x02
DeclareMPCall 108, NKSetPrInfoClockRates
NKSetPrInfoClockRates
cmplwi r3, 2
bge+ ReturnParamErrFromMPCall
mulli r17, r3, 0x10
addi r18, r1, 0xf80
mulli r17, r3, 16
addi r18, r1, KDP.ProcessorInfo + NKProcessorInfo.ClockRates
add r18, r17, r18
lwz r16, 0x0134(r6)
stw r4, 0x0000(r18)
stw r5, 0x0004(r18)
stw r16, 0x0008(r18)
lwz r16, ContextBlock.r6(r6)
stw r4, 0(r18)
stw r5, 4(r18)
stw r16, 8(r18)
_log 'Clock rates for step '
mr r8, r3
bl Printd
@ -2154,6 +2174,7 @@ MPCall_108 ; OUTSIDE REFERER
mr r8, r16
bl Printd
_log 'Hz^n'
b ReturnZeroFromMPCall

View File

@ -189,7 +189,17 @@ HalfLoadedReg set (&reg)
MACRO
_bclr &dest, &src, &bit
rlwinm&dot &dest, &src, 0, (&bit)+1, (&bit)-1
_bclr_rbit set &bit+1
if _bclr_rbit > 31
_bclr_rbit set 0
endif
_bclr_lbit set &bit-1
if _bclr_lbit < 0
_bclr_lbit set 31
endif
rlwinm&dot &dest, &src, 0, _bclr_rbit, _bclr_lbit
ENDM

View File

@ -59,7 +59,7 @@ PagingFunc1 ; OUTSIDE REFERER
lwz r8, -0x001c(r30)
bl FindAreaAbove
mr r31, r8
stw r8, -0x00e4(r30)
stw r8, EWA.SpecialAreaPtr(r30)
stw r27, -0x00e8(r30)
lwz r16, 0x0024(r31)
lwz r17, 0x0020(r31)

View File

@ -89,11 +89,12 @@ CommonPIHPath_0xc ; OUTSIDE REFERER
lwz r29, KDP.ClearIntMaskInit(r1)
bne- @noperf
bne- cr1, CommonPIHPath_0x78
bne- cr1, @CommonPIHPath_0x78
@noperf
rlwinm. r8, r7, 0, 10, 10
beq- CommonPIHPath_0x14c
beq- @actual_meat
sth r28, 0x0000(r23)
or r13, r13, r31
bgt- cr7, @negative
@ -101,10 +102,10 @@ CommonPIHPath_0xc ; OUTSIDE REFERER
@negative
_AssertAndRelease PSA.PIHLock, scratch=r8
bl Restore_r20_r31
bl SchRestoreStartingAtR20
b IntReturn
CommonPIHPath_0x78
@CommonPIHPath_0x78
_AssertAndRelease PSA.PIHLock, scratch=r8
bl Save_r14_r19
@ -122,7 +123,7 @@ CommonPIHPath_0x78
bl CauseNotification
_AssertAndRelease PSA.SchLock, scratch=r8
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b IntReturn
@no_handler_notification
@ -136,7 +137,13 @@ CommonPIHPath_0x78
b CommonPIHPath_0xc
CommonPIHPath_0x14c
@actual_meat
_AssertAndRelease PSA.PIHLock, scratch=r8
bl Save_r14_r19
@ -145,55 +152,56 @@ CommonPIHPath_0x14c
lwz r30, PSA.MCR(r1)
or r31, r31, r30
stw r31, PSA.MCR(r1)
sth r28, -0x043c(r1)
sth r28, PSA.Int(r1)
lwz r31, PSA.PA_BlueTask(r1)
mfsprg r30, 0
lwz r28, 0x0064(r31)
lbz r29, 0x0018(r31)
ori r28, r28, 0x10
stw r28, 0x0064(r31)
cmpwi r29, 0x00
lhz r16, 0x001a(r31)
beq- CommonPIHPath_0x1dc
lwz r28, Task.Flags(r31)
lbz r29, Task.State(r31)
_bset r28, r28, Task.kFlag68kInterrupt
stw r28, Task.Flags(r31)
cmpwi r29, 0
lhz r16, Task.CPUIndex(r31)
beq- @task_not_running
lhz r17, EWA.CPUIndex(r30)
cmpw cr1, r16, r17
rlwinm. r8, r28, 0, 26, 26
beq- cr1, CommonPIHPath_0x1d0
bne- CommonPIHPath_0x230
rlwinm. r8, r28, 0, Task.kFlag26, Task.kFlag26
beq- cr1, @running_on_this_cpu
bne- @flag_and_run
CommonPIHPath_0x1d0
@running_on_this_cpu
mr r8, r31
bl TaskUnready
b CommonPIHPath_0x218
bl SchTaskUnrdy
b @now_reschedule_task
CommonPIHPath_0x1dc
addi r16, r31, 0x08
@task_not_running
addi r16, r31, Task.QueueMember
RemoveFromList r16, scratch1=r17, scratch2=r18
lbz r17, 0x0037(r31)
cmpwi r17, 0x01
bne- CommonPIHPath_0x210
addi r8, r31, 0x20
lbz r17, Task.Timer + Timer.Byte3(r31)
cmpwi r17, 1
bne- @task_timer_not_in_use
addi r8, r31, Task.Timer
bl DequeueTimer
CommonPIHPath_0x210
lwz r16, 0x0e80(r1)
@task_timer_not_in_use
lwz r16, KDP.NanoKernelInfo + NKNanoKernelInfo.ExternalIntCount(r1)
stw r16, PSA.OtherSystemContextPtr(r1)
CommonPIHPath_0x218
li r16, 0x00
stb r16, 0x0019(r31)
@now_reschedule_task
li r16, Task.kCriticalPriority
stb r16, Task.Priority(r31)
mr r8, r31
bl TaskReadyAsNext
bl SchRdyTaskLater
mr r8, r31
bl CalculateTimeslice
CommonPIHPath_0x230
@flag_and_run
mr r8, r31
bl FlagSchEvaluationIfTaskRequires
_AssertAndRelease PSA.SchLock, scratch=r16
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b IntReturn
@ -297,7 +305,7 @@ PDM_PIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
bl Save_r20_r31
bl SchSaveStartingAtR20
addi r9, r1, PSA.BlueVecBase
andis. r8, r11, 0x8000 >> 14 ; SRR1 mystery bit
@ -375,7 +383,7 @@ PBX_PIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -439,7 +447,7 @@ GazellePIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -527,7 +535,7 @@ TNT_PIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -603,7 +611,7 @@ GossamerPIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -696,7 +704,7 @@ NewWorldPowerBookPIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -773,7 +781,7 @@ CordycepsPIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -837,7 +845,7 @@ NewWorldPIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750
@ -1025,7 +1033,7 @@ UnknownPIH
_Lock PSA.PIHLock, scratch1=r8, scratch2=r9
; r6 = ewa
bl Save_r20_r31
bl SchSaveStartingAtR20
; r8 = sprg0 (not used by me)
addi r9, r1, -0x750

View File

@ -22,7 +22,7 @@ Local_Panic set *
; Each one has a "time cake" that gets divided among its tasks.
; For critical it is ~1ms, successively multiplying by 8.
InitRDYQs
SchInit
li r16, 0
stw r16, KDP.NanoKernelInfo + NKNanoKernelInfo.TaskCount(r1)
@ -61,7 +61,7 @@ InitRDYQs
; Zero some shit
li r8, 0
stw r8, ReadyQueue.Counter(r9) ; incremented by TaskReadyAsPrev/Next
stw r8, ReadyQueue.Counter(r9) ; incremented by SchRdyTaskNow/Next
stw r8, ReadyQueue.TotalWeight(r9)
; 1ms for critical, successively 8x for other queues
@ -97,6 +97,10 @@ InitRDYQs
addi r9, r9, 32 ;ReadyQueue.Size
blt+ @loop
; DO SOMETHING ELSE:
; If the low nybble is empty, set ContextBlock.PriorityShifty to 2.
lwz r16, KDP.PA_ECB(r1)
lwz r17, ContextBlock.PriorityShifty(r16)
@ -120,13 +124,13 @@ InitRDYQs
; ...to (ECB *)r6
; (and also copy SPRG0 to r8)
Save_r14_r31
SchSaveStartingAtR14
li r8, ContextBlock.r16 & -32
dcbtst r8, r6
stw r14, ContextBlock.r14(r6)
stw r15, ContextBlock.r15(r6)
Save_r16_r31
SchSaveStartingAtR16
li r8, ContextBlock.r20 & -32
stw r16, ContextBlock.r16(r6)
dcbtst r8, r6
@ -134,7 +138,7 @@ Save_r16_r31
stw r18, ContextBlock.r18(r6)
stw r19, ContextBlock.r19(r6)
Save_r20_r31
SchSaveStartingAtR20
li r8, ContextBlock.r24 & -32
stw r20, ContextBlock.r20(r6)
dcbtst r8, r6
@ -142,7 +146,7 @@ Save_r20_r31
stw r22, ContextBlock.r22(r6)
stw r23, ContextBlock.r23(r6)
Save_r24_r31
SchSaveStartingAtR24
li r8, ContextBlock.r28 & -32
stw r24, ContextBlock.r24(r6)
dcbtst r8, r6
@ -169,13 +173,13 @@ Save_r24_r31
; ...from (ECB *)r6
Restore_r14_r31
SchRestoreStartingAtR14
li r31, ContextBlock.r16 & -32
dcbt r31, r6
lwz r14, ContextBlock.r14(r6)
lwz r15, ContextBlock.r15(r6)
Restore_r16_r31
SchRestoreStartingAtR16
li r31, ContextBlock.r20 & -32
lwz r16, ContextBlock.r16(r6)
dcbt r31, r6
@ -183,7 +187,7 @@ Restore_r16_r31
lwz r18, ContextBlock.r18(r6)
lwz r19, ContextBlock.r19(r6)
Restore_r20_r31
SchRestoreStartingAtR20
li r31, ContextBlock.r24 & -32
lwz r20, ContextBlock.r20(r6)
dcbt r31, r6
@ -191,7 +195,7 @@ Restore_r20_r31
lwz r22, ContextBlock.r22(r6)
lwz r23, ContextBlock.r23(r6)
Restore_r24_r31
SchRestoreStartingAtR24
li r31, ContextBlock.r28 & -32
lwz r24, ContextBlock.r24(r6)
dcbt r31, r6
@ -699,7 +703,7 @@ Save_v0_v31_0x1b8
; ARG Task *r8
; CLOB r16, r17, r18
TaskUnready
SchTaskUnrdy
lwz r17, Task.QueueMember + LLL.Next( r8)
lbz r18, Task.State( r8)
@ -762,14 +766,12 @@ TaskUnready
; ARG Task *r8
; CLOB r16, r17, r18
TaskReadyAsNext
SchRdyTaskLater
crclr cr1_eq
b TaskReadyCommonPath
TaskReadyAsPrev
b _SchRdyTaskCommon
SchRdyTaskNow ; not much point in doing this unless you then flag a scheduler evaluation
crset cr1_eq
TaskReadyCommonPath
_SchRdyTaskCommon
lwz r16, Task.QueueMember + LLL.Next(r8)
lis r17, 0x8000 ; ...0000
@ -842,7 +844,7 @@ TaskReadyCommonPath
; ARG AddressSpace *r8, AddressSpace *r9 (can be zero?)
SetSpaceSRsAndBATs
SchSwitchSpace
; This is the only function that hits this counter
lwz r17, KDP.NanoKernelInfo + NKNanoKernelInfo.AddrSpcSetCtr(r1)
@ -1130,49 +1132,40 @@ SetAddrSpcRegisters_0x314:
######## ######## ######## ## ### ## ## ## ##
## ## ## ## ## ## ## ### ## ## ##
## ## ## ## ## ## ## #### ## ####
######## ###### ## ## ## ## ## ## ## ##
## ## ## ## ## ######### ## #### ##
## ## ## ## ## ## ## ## ### ##
## ## ######## ## ## ## ## ## ## ##
; Always and only jumped to by IntReturn
SchReturn
ReturnToAnyTask ; OUTSIDE REFERER
lbz r8, EWA.SchEvalFlag(r1)
rlwinm. r9, r7, 0, 16, 16
lwz r1, EWA.PA_KDP(r1)
cmpwi cr1, r8, 0x00
cmpwi cr1, r8, 0
bne- ReturnFromInterrupt
beq+ cr1, ReturnFromInterrupt
bne- SchExitInterrupt
beq+ cr1, SchExitInterrupt
bl Save_r14_r31
bl SchSaveStartingAtR14
_Lock PSA.SchLock, scratch1=r27, scratch2=r28
; Either fallen through from SchReturn, or jumped to by
; TrulyCommonMPCallReturnPath when it wants to block the caller
######## ######## ######## ## ####### ######## ## ## ######## ########
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ##
######## ###### ## ## ## ## ## ######### ###### ########
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ## ##
## ## ######## ## ## ####### ## ## ## ######## ## ##
RescheduleAndReturn ; OUTSIDE REFERER
SchEval
mfsprg r14, 0
li r8, 0x00
li r8, 0
stb r8, EWA.SchEvalFlag(r14)
lwz r31, -0x0008(r14)
lwz r1, -0x0004(r14)
lwz r31, EWA.PA_CurTask(r14)
lwz r1, EWA.PA_KDP(r14)
lwz r9, KDP.NanoKernelInfo + NKNanoKernelInfo.SchEvalCount(r1)
addi r9, r9, 1
stw r9, KDP.NanoKernelInfo + NKNanoKernelInfo.SchEvalCount(r1)
bl major_0x14a98
bl SchFiddlePriorityShifty
lbz r27, 0x0019(r31)
blt- major_0x142dc_0x58
li r26, 0x01
@ -1183,12 +1176,13 @@ major_0x142dc_0x38
cmpw r27, r26
mr r8, r31
beq- major_0x142dc_0x58
bl TaskUnready
bl SchTaskUnrdy
stb r26, 0x0019(r31)
mr r8, r31
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
major_0x142dc_0x58 ; OUTSIDE REFERER
lwz r27, -0x0970(r1)
@ -1290,7 +1284,7 @@ major_0x142dc_0x1bc
_AssertAndRelease PSA.SchLock, scratch=r27
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
@ -1302,7 +1296,7 @@ major_0x142dc_0x1bc
## ## ## ##
## ## ## ####
; ReturnFromInterrupt
; SchExitInterrupt
; All MPCalls get here?
; r0,7,8,9,10,11,12,13 restored from r6 area
@ -1314,8 +1308,8 @@ major_0x142dc_0x1bc