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
; Xrefs:
; non_skeleton_reset_trap
; ReturnToAnyTask
; RescheduleAndReturn
; SchReturn
; SchEval
; major_0x14548
; > sprg0 = for r1 and r6
@ -1327,20 +1321,20 @@ major_0x142dc_0x1bc
; > r12 = lr restore
; > r13 = cr restore
ReturnFromInterrupt ; OUTSIDE REFERER
SchExitInterrupt ; OUTSIDE REFERER
lwz r8, 0x0edc(r1)
mfsprg r1, 0
mtlr r12
mtspr srr0, r10
mtspr srr1, r11
rlwinm. r8, r8, 0, 27, 27
beq- ReturnFromInterrupt_0x2c
beq- SchExitInterrupt_0x2c
mfxer r8
rlwinm r8, r8, 0, 23, 21
rlwimi r8, r7, 19, 23, 23
mtxer r8
ReturnFromInterrupt_0x2c
SchExitInterrupt_0x2c
mtcr r13
lwz r10, 0x0154(r6)
lwz r11, 0x015c(r6)
@ -1361,7 +1355,7 @@ ReturnFromInterrupt_0x2c
; major_0x14548
; Xrefs:
; RescheduleAndReturn
; SchEval
major_0x14548 ; OUTSIDE REFERER
lwz r16, 0x0064(r31)
@ -1418,7 +1412,7 @@ major_0x14548_0x58
beq- major_0x14548_0xd4
cmpwi r16, 0x00
mr r8, r31
beql+ TaskReadyAsPrev
beql+ SchRdyTaskNow
major_0x14548_0xd4
mfsprg r19, 0
@ -1449,7 +1443,7 @@ major_0x14548_0xd4
cmpw r18, r9
beq- major_0x14548_0x148
mr r8, r18
bl SetSpaceSRsAndBATs
bl SchSwitchSpace
major_0x14548_0x148
mfsprg r19, 0
@ -1616,14 +1610,14 @@ major_0x14548_0x380
; r11 = new srr1
; r12 = lr restore
; r13 = cr restore
b ReturnFromInterrupt
b SchExitInterrupt
; major_0x148ec
; Xrefs:
; RescheduleAndReturn
; SchEval
; major_0x14548
major_0x148ec ; OUTSIDE REFERER
@ -1694,7 +1688,7 @@ major_0x148ec_0xc8
mtxer r20
li r16, 0x01
stb r16, -0x0309(r21)
b AdjustDecForTMRQGivenCurTime
b SetTimesliceFromCurTime
@ -1709,7 +1703,7 @@ major_0x148ec_0xc8
; SetEvent
; MPCall_8
; major_0x130f0
; RescheduleAndReturn
; SchEval
; major_0x14bcc
; CommonPIHPath
@ -1814,14 +1808,15 @@ clear_cr0_lt ; OUTSIDE REFERER
; major_0x14a98
; SchFiddlePriorityShifty
; Xrefs:
; IntDecrementer
; RescheduleAndReturn
; SchEval
major_0x14a98 ; OUTSIDE REFERER
rlwinm r8, r7, 10, 0, 0
SchFiddlePriorityShifty ; OUTSIDE REFERER
rlwinm r8, r7, EWA.kFlagBlue, 0, 0
lwz r18, KDP.PA_ECB(r1)
nand. r8, r8, r8
lwz r17, ContextBlock.PriorityShifty(r18)
@ -1829,24 +1824,26 @@ major_0x14a98 ; OUTSIDE REFERER
cmpwi r17, 0
rlwinm r9, r17, 0, 22, 22
blt- major_0x14a98_0x54
blt- @pshifty_high_bit_set
cmpwi r9, 0x200
lwz r16, ContextBlock.r25(r18)
beq- major_0x14a98_0x48
beq- @pshifty_bit_22_set
clrlwi r8, r16, 29
clrlwi r9, r17, 28
cmpwi r8, 6
bgt- major_0x14a98_0x48
bgt- @pshifty_bit_22_set
cmpw r8, r9
bltlr-
cmpw r8, r8
major_0x14a98_0x48
@pshifty_bit_22_set
ori r17, r17, 0x100
stw r17, ContextBlock.PriorityShifty(r18)
blr
major_0x14a98_0x54
@pshifty_high_bit_set
clrlwi r17, r17, 1
stw r17, ContextBlock.PriorityShifty(r18)
blr
@ -1864,71 +1861,109 @@ major_0x14a98_0x54
; ARG Task *r8
FlagSchEvaluationIfTaskRequires ; OUTSIDE REFERER
lwz r16, Task.Flags(r8)
mfsprg r15, 0
rlwinm. r16, r16, 0, Task.kFlag25, Task.kFlag26
bne- major_0x14af8_0xa0
rlwinm. r16, r16, 0, Task.kFlag25, Task.kFlag26
bne- FlagSchEval
addi r16, r15, EWA.CPUBase
lbz r17, 0x0019(r8)
lbz r17, Task.Priority(r8)
lwz r19, CPU.LLL + LLL.Freeform(r16)
; Uniprocessor systems:
; Flag a reevaluation on this, the only CPU
lwz r14, CoherenceGroup.ScheduledCpuCount(r19)
cmpwi r14, 2
blt- major_0x14af8_0xa0
blt- FlagSchEval
; Multiprocessor systems:
; Find the best CPU to flag a
;multiprocessor
lwz r14, CoherenceGroup.CpuCount(r19)
mr r18, r16
b @loopentry
@34
lwz r16, 0x0008(r19)
; r19 = motherboard coherence group
; r14 = loop counter
; r16 = current CPU pointer
@38
addi r16, r16, -0x08
@loop_hit_the_coherence_group
lwz r16, CoherenceGroup.CPUList + LLL.Next(r19)
@loop
subi r16, r16, CPU.LLL
@loopentry
addi r14, r14, -0x01
lbz r20, 0x0229(r16)
lwz r21, 0x0018(r16)
subi r14, r14, 1
lbz r20, CPU.EWA + EWA.TaskPriority(r16)
lwz r21, CPU.Flags(r16)
cmpw cr1, r17, r20
rlwinm. r21, r21, 0, 28, 28
bge- cr1, @60
beq- @60
rlwinm. r21, r21, 0, CPU.kFlagScheduled, CPU.kFlagScheduled
bge- cr1, @cpu_not_best_for_task
beq- @cpu_not_best_for_task
mr r17, r20
mr r18, r16
@cpu_not_best_for_task
@60
lwz r16, 0x0010(r16)
cmpwi cr1, r14, 0x00
lwz r16, CPU.LLL + LLL.Next(r16) ; next element
cmpwi cr1, r14, 0
cmpw r16, r19
ble- cr1, @78
beq+ @34
b @38
@78
lbz r16, 0x0019(r8)
ble- cr1, @exit_loop
beq+ @loop_hit_the_coherence_group ; skip the owner of the linked list
b @loop
@exit_loop
; r17 = least-important priority being executed on any CPU
; r18 = pointer to that CPU
; No suitable CPU found (all running important-er tasks)
lbz r16, Task.Priority(r8)
cmpw r17, r16
blelr-
; Was this CPU the most suitable?
lhz r17, EWA.CPUIndex(r15)
lhz r18, CPU.EWA + EWA.CPUIndex(r18)
cmpw r18, r17
bne- DoInterprocessorAlert
bne- AlertSchEvalOnOtherCPU
; otherwise fall through to FlagSchEvalOnThisCPU
NINETYFOUR
li r16, 0x01
; RETURN PATHS
; To force a scheduler evaluation to run on *this* CPU when returning from
; *this* interrupt, just raise a flag.
FlagSchEvalOnThisCPU
li r16, 1
stb r16, EWA.SchEvalFlag(r15)
blr
major_0x14af8_0xa0
; Public function! Can go to FlagSchEvalOnThisCPU or AlertSchEvalOnOtherCPU
FlagSchEval
mfsprg r15, 0
lhz r18, Task.CPUIndex(r8)
lhz r17, EWA.CPUIndex(r15)
cmpw r17, r18
beq+ NINETYFOUR
beq+ FlagSchEvalOnThisCPU
DoInterprocessorAlert
; To force a scheduler evaluation to run on *another* CPU, we interrupt it
AlertSchEvalOnOtherCPU
lwz r9, KDP.NanoKernelInfo + NKNanoKernelInfo.AlertCount(r1)
addi r9, r9, 1
stw r9, KDP.NanoKernelInfo + NKNanoKernelInfo.AlertCount(r1)
@ -1938,7 +1973,7 @@ DoInterprocessorAlert
stw r18, EWA.SIGPCallR4(r15)
li r8, 2
b SIGP
b SIGP ; returns to link register
@ -2051,7 +2086,7 @@ NewCpuEntryPoint
lwz r8, Task.AddressSpacePtr(r31)
li r9, 0
bl SetSpaceSRsAndBATs
bl SchSwitchSpace
_log 'Adding idle task 0x'
mr r8, r31
@ -2059,11 +2094,11 @@ NewCpuEntryPoint
_log 'to the ready queue^n'
mr r8, r31
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
lwz r16, CPU.Eff(r3)
lwz r16, CPU.Flags(r3)
ori r16, r16, 8
stw r16, CPU.Eff(r3)
stw r16, CPU.Flags(r3)
lwz r17, Task.QueueMember + LLL.Freeform(r3)
lwz r16, 0x0024(r17)
@ -2082,11 +2117,14 @@ NewCpuEntryPoint
mr r30, r31
b major_0x142dc_0xd8
b major_0x142dc_0x58
IdleCode
SchIdleTask
li r31, 0
lisori r20, 'idle'
lisori r21, 'task'
@ -2164,7 +2202,7 @@ IdleCode
StopProcessor
SchIdleTaskStopper
mfmsr r30
andi. r29, r30, 0x7fff
mtmsr r29
@ -2185,7 +2223,7 @@ StopProcessor
lwz r8, 0x001c(r31)
li r9, 0x00
stw r9, 0x001c(r31)
bl TaskUnready
bl SchTaskUnrdy
addi r16, r1, -0xa44
addi r17, r8, 0x08
stw r16, 0x0000(r17)
@ -2201,7 +2239,7 @@ StopProcessor
twi 31, r31, 8
_log 'Stop didn''t work - going to sleep.^n'
StopProcessor_0x10c
SchIdleTaskStopper_0x10c
lis r5, 0x7fff
ori r5, r5, 0xffff
mtdec r5
@ -2209,4 +2247,4 @@ StopProcessor_0x10c
li r3, 6
li r4, 0
twi 31, r31, 5
b StopProcessor_0x10c
b SchIdleTaskStopper_0x10c

View File

@ -374,7 +374,7 @@ RestoreKernelState_0x144
mfsprg r15, 0
lwz r8, -0x001c(r15)
li r9, 0x00
bl SetSpaceSRsAndBATs
bl SchSwitchSpace
isync
mfsprg r15, 0

View File

@ -155,7 +155,7 @@ MPDeleteQueue
; Put RDYQ
subi r8, r16, Task.QueueMember
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl FlagSchEvaluationIfTaskRequires
@ -392,7 +392,7 @@ EnqueueMessage
li r17, Task.kLatencyProtectPriority
stb r17, Task.Priority(r8)
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
bl FlagSchEvaluationIfTaskRequires
@ -491,7 +491,7 @@ MPWaitOnQueue
; Remove from ready queue
mr r8, r19
bl TaskUnready
bl SchTaskUnrdy
; Add to this queue
lwz r19, EWA.PA_CurTask(r30)
@ -711,7 +711,7 @@ MPWaitOnSemaphore
;committed to blocking the calling task
; Remove from ready queue
bl TaskUnready
bl SchTaskUnrdy
; Add to this queue
addi r16, r31, Semaphore.BlockedTasks
@ -861,7 +861,7 @@ SignalSemaphore_0x30
addi r8, r16, -0x08
li r17, 0x01
stb r17, 0x0019(r8)
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
bl FlagSchEvaluationIfTaskRequires
mtlr r27
@ -924,7 +924,7 @@ MPCall_21_0x68
lwz r16, 0x0008(r31)
RemoveFromList r16, scratch1=r17, scratch2=r18
addi r8, r16, -0x08
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl FlagSchEvaluationIfTaskRequires
b MPCall_21_0x34
@ -1089,7 +1089,7 @@ MPCall_27_0x78
MPCall_27_0xb4
mr r8, r30
bl TaskUnready
bl SchTaskUnrdy
lis r16, 0x7fff
addi r18, r30, 0x08
ori r16, r16, 0xffff
@ -1236,7 +1236,7 @@ MPCall_28_0x94
stw r18, 0x00fc(r17)
li r17, 0x01
stb r17, 0x0019(r8)
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
bl FlagSchEvaluationIfTaskRequires
@ -1289,7 +1289,7 @@ MPCall_26_0x68
lwz r16, 0x0008(r31)
RemoveFromList r16, scratch1=r17, scratch2=r18
addi r8, r16, -0x08
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl FlagSchEvaluationIfTaskRequires
b MPCall_26_0x34
@ -1442,7 +1442,7 @@ MPDeleteEvent_0x68
lwz r16, 0x0008(r31)
RemoveFromList r16, scratch1=r17, scratch2=r18
addi r8, r16, -0x08
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl FlagSchEvaluationIfTaskRequires
b MPDeleteEvent_0x34
@ -1543,7 +1543,7 @@ SetEvent
li r17, Task.kLatencyProtectPriority
stb r17, Task.Priority(r8)
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
bl FlagSchEvaluationIfTaskRequires
@ -1608,7 +1608,7 @@ SetEvent
lwz r16, Task.Flags(r26)
lbz r19, Task.State(r26)
ori r16, r16, (1 << (31 - Task.kFlag27))
ori r16, r16, (1 << (31 - Task.kFlag68kInterrupt))
stw r16, Task.Flags(r26)
; But what *is* MCR?
@ -1636,7 +1636,7 @@ SetEvent
li r16, Task.kCriticalPriority
stb r16, Task.Priority(r26)
mr r8, r26
bl TaskReadyAsNext
bl SchRdyTaskLater
mr r8, r26
bl CalculateTimeslice
@task_already_running
@ -1749,7 +1749,7 @@ MPWaitForEvent_field_10_was_zero
; MOVE TASK OUT OF QUEUE AND INTO EVENT GROUP
mr r8, r19
bl TaskUnready
bl SchTaskUnrdy
lwz r19, EWA.PA_CurTask(r30)
addi r16, r31, EventGroup.LLL
@ -2610,7 +2610,7 @@ major_0x0dce8_0x60
li r16, 0x01
stb r16, 0x0019(r19)
lwz r8, PSA.PA_BlueTask(r1)
bl TaskReadyAsPrev
bl SchRdyTaskNow
major_0x0dce8_0x70
lwz r8, PSA.PA_BlueTask(r1)

View File

@ -131,34 +131,25 @@ CreateTask
; Create a semaphore struct inside the task
; (NOT a semaphore queue)
addi r16, r28, Task.SemaphoreLLL
_lstart r17, 'SEMA'
stw r16, LLL.Next(r16)
addi r16, r28, Task.Semaphore
_lstart r17, Semaphore.kSignature
stw r16, Semaphore.BlockedTasks + LLL.Next(r16)
_lfinish
stw r16, LLL.Prev(r16)
stw r17, LLL.Signature(r16)
; Might be part of the SEMA?
stw r16, Semaphore.BlockedTasks + LLL.Prev(r16)
stw r17, Semaphore.BlockedTasks + LLL.Signature(r16)
li r16, 1
stw r16, Task.One(r28)
stw r16, Task.Semaphore + Semaphore.MaxValue(r28)
li r16, 0
stw r16, Task.Zero(r28)
stw r16, Task.Semaphore + Semaphore.Value(r28)
; Allocate an ID for the SEMA
addi r8, r28, Task.SemaphoreLLL
addi r8, r28, Task.Semaphore
li r9, Semaphore.kIDClass
bl MakeID
cmpwi r8, 0
beq- @fail_semq_no_id
stw r8, Task.SemaphoreLLL + LLL.Freeform(r28)
stw r8, Task.Semaphore + Semaphore.BlockedTasks + LLL.Freeform(r28)
@ -356,7 +347,7 @@ MPCall_8 ; OUTSIDE REFERER
addi r16, r31, 0x08
RemoveFromList r16, scratch1=r17, scratch2=r18
mr r8, r31
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
bl FlagSchEvaluationIfTaskRequires
@ -403,7 +394,7 @@ MPCall_9 ; OUTSIDE REFERER
li r17, 0x01
stb r17, 0x0019(r31)
mr r8, r31
bl major_0x14af8_0xa0
bl FlagSchEval
_AssertAndRelease PSA.SchLock, scratch=r16
subi r10, r10, 4
b MPCall_6_0x78
@ -428,7 +419,7 @@ MPCall_9_0xe0
ori r16, r16, 0x02
stw r16, 0x0064(r31)
mr r8, r31
bl TaskUnready
bl SchTaskUnrdy
MPCall_9_0xf0
lwz r17, 0x009c(r31)
@ -597,7 +588,7 @@ MPCall_14 ; OUTSIDE REFERER
stw r18, 0x0014(r16)
beq- MPCall_14_0x70
mr r8, r31
bl major_0x14af8_0xa0
bl FlagSchEval
MPCall_14_0x70
stw r4, 0x001c(r31)
@ -697,7 +688,7 @@ KCThrowException_0x70
stw r4, 0x00f8(r31)
stw r16, 0x0064(r31)
mr r8, r31
bl TaskUnready
bl SchTaskUnrdy
addi r16, r1, -0xa34
addi r17, r31, 0x08
stw r16, 0x0000(r17)
@ -712,7 +703,7 @@ KCThrowException_0xb8
li r17, 0x01
stb r17, 0x0019(r31)
mr r8, r31
bl major_0x14af8_0xa0
bl FlagSchEval
_AssertAndRelease PSA.SchLock, scratch=r16
subi r10, r10, 4
b MPCall_6_0x78
@ -790,7 +781,7 @@ MPCall_58_0xb4
addi r16, r31, 0x08
RemoveFromList r16, scratch1=r17, scratch2=r18
mr r8, r31
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl FlagSchEvaluationIfTaskRequires
MPCall_58_0xe0
@ -800,9 +791,9 @@ MPCall_58_0xe0
FuncExportedFromTasks ; OUTSIDE REFERER
addi r16, r1, -0xa34
addi r17, r31, 0x08
stw r16, 0x0000(r17)
addi r16, r1, PSA.DbugQueue
addi r17, r31, Task.QueueMember
stw r16, LLL.Freeform(r17)
InsertAsPrev r17, r16, scratch=r18
li r8, 0x1c
bl PoolAlloc
@ -886,6 +877,8 @@ LoadSomeData ; OUTSIDE REFERER
; Used to extract task state. This will be tricky.
DeclareMPCall 59, MPCall_59
MPCall_59 ; OUTSIDE REFERER
@ -1505,8 +1498,8 @@ MPCall_114 ; OUTSIDE REFERER
rlwinm. r8, r16, 0, 26, 26
mr r8, r31
bne- MPCall_114_0x90
bl TaskUnready
bl TaskReadyAsPrev
bl SchTaskUnrdy
bl SchRdyTaskNow
MPCall_114_0x90
bl FlagSchEvaluationIfTaskRequires

View File

@ -68,7 +68,7 @@
; major_0x129cc
; Local_Panic
; Local_Panic
; RescheduleAndReturn
; SchEval
; major_0x14548
; Local_Panic
; CommonPIHPath

View File

@ -239,7 +239,7 @@ TimerDispatch_0x180:
TimerDispatch_0x188
lwz r19, EWA.TimerDispatchLR(r18)
mtlr r19
b AdjustDecForTMRQGivenCurTimeAndTripTime
b SetTimesliceFromCurTimeAndTripTime
@ -255,8 +255,8 @@ StartTimeslicing ; OUTSIDE REFERER
stb r8, EWA.GlobalTimeIsValid(r19)
li r8, 0
stw r8, -0x02e8(r19)
stw r8, -0x02e4(r19)
stw r8, EWA.GlobalTime(r19)
stw r8, EWA.GlobalTime + 4(r19)
mflr r19
_log 'Starting timeslicing^n'
@ -267,7 +267,7 @@ StartTimeslicing ; OUTSIDE REFERER
; CLOB r8/r9, r16-r21
AdjustDecForTMRQ
SetTimeslice
mflr r19
bl GetTime
@ -279,7 +279,7 @@ AdjustDecForTMRQ
; ARG TimeBase r8/r9 curTime
; CLOB r16-r21
AdjustDecForTMRQGivenCurTime
SetTimesliceFromCurTime
; This should get the most distant time???
lwz r18, PSA.TimerQueue + LLL.Next(r1)
@ -292,7 +292,7 @@ AdjustDecForTMRQGivenCurTime
; ARG TimeBase r8/r9 curTime, TimeBase r16/r17 TripTime
; CLOB r18-r21
AdjustDecForTMRQGivenCurTimeAndTripTime
SetTimesliceFromCurTimeAndTripTime
mfxer r20
mfsprg r19, 0
@ -372,7 +372,7 @@ TimerFire1 ; OUTSIDE REFERER
RemoveFromList r16, scratch1=r17, scratch2=r19
li r17, 0x01
stb r17, 0x0019(r8)
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
bl FlagSchEvaluationIfTaskRequires
b TimerDispatch_0x144
@ -442,7 +442,7 @@ TimerFire2_0x98
lwz r8, 0x0018(r30)
addi r16, r8, 0x08
RemoveFromList r16, scratch1=r17, scratch2=r18
bl TaskReadyAsPrev
bl SchRdyTaskNow
@ -539,7 +539,7 @@ TimerFire4_0x10 ; OUTSIDE REFERER
mfsprg r28, 0
lwz r29, -0x0008(r28)
mr r8, r29
bl TaskUnready
bl SchTaskUnrdy
lbz r17, 0x0019(r29)
cmpwi r17, 0x02
bge- TimerFire4_0x64
@ -549,7 +549,7 @@ TimerFire4_0x10 ; OUTSIDE REFERER
bl clear_cr0_lt
bge- TimerFire4_0x50
mr r8, r29
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl CalculateTimeslice
b TimerFire5_0x8
@ -557,7 +557,7 @@ TimerFire4_0x50
li r18, 0x02
stb r18, 0x0019(r29)
mr r8, r29
bl TaskReadyAsPrev
bl SchRdyTaskNow
b TimerFire5_0x8
TimerFire4_0x64
@ -572,7 +572,7 @@ TimerFire4_0x64
; TimerFire4
TimerFire5 ; OUTSIDE REFERER
bl TaskReadyAsPrev
bl SchRdyTaskNow
bl major_0x149d4
TimerFire5_0x8 ; OUTSIDE REFERER
@ -844,7 +844,7 @@ EnqueueTimer ; OUTSIDE REFERER
stw r8, LLL.Next(r20) ; next of considered = me
stw r19, LLL.Freeform(r8) ; my freeform = my original freeform
b AdjustDecForTMRQ
b SetTimeslice
@insert_further_ahead
lwz r20, PSA.TimerQueue + TimerQueueStruct.LLL + LLL.Prev(r1)
@ -898,7 +898,7 @@ DequeueTimer
cmpw r18, r8
stb r16, Timer.Byte3(r8)
beq+ AdjustDecForTMRQ
beq+ SetTimeslice
blr
@ -912,7 +912,7 @@ DequeueTimer
; MPCall_27
; MPCall_52
; MPCall_31
; InitRDYQs
; SchInit
; Get the number of timebase ticks in a specified period
@ -958,8 +958,8 @@ TimebaseTicksPerPeriod
; MPCall_32
; CreateTask
; InitTMRQs
; AdjustDecForTMRQ
; RescheduleAndReturn
; SetTimeslice
; SchEval
; major_0x14548
; RET long r8 tbu, long r9 tbl

View File

@ -2253,12 +2253,8 @@ ProbePerfMonitor_0x188
; FDP_1214
FDPEmulateInstruction
; Xrefs:
; IntProgram
FDP_1214 ; OUTSIDE REFERER
mfsprg r1, 0
lwz r8, 0x0104(r6)
stw r8, 0x0000(r1)

View File

@ -462,7 +462,7 @@ VMInit_0x29c
mfsprg r9, 0
lwz r6, EWA.PA_ContextBlock(r9)
bl Save_r14_r31 ; need some registers
bl SchSaveStartingAtR14 ; need some registers
lwz r8, EWA.PA_CurAddressSpace(r9)
li r9, 0
@ -495,7 +495,7 @@ VMInit_0x29c
bl printw
_log '^n'
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b VMReturn0
@ -562,7 +562,7 @@ VMGetPhysicalPage ; OUTSIDE REFERER
lwz r6, -0x0014(r9)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
slwi r29, r4, 12
@ -574,7 +574,7 @@ VMGetPhysicalPage ; OUTSIDE REFERER
VMGetPhysicalPage_0x28
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r9, KDP.PrimaryAddrRangePages(r1)
VMGetPhysicalPage_0x30
@ -595,7 +595,7 @@ getPTEntryGivenPage ; OUTSIDE REFERER
lwz r6, -0x0014(r9)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
slwi r29, r4, 12
@ -617,7 +617,7 @@ getPTEntryGivenPage_0x3c
getPTEntryGivenPage_0x48
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r9, KDP.PrimaryAddrRangePages(r1)
getPTEntryGivenPage_0x50
@ -698,12 +698,12 @@ major_0x08d88_0x8c
major_0x08d88_0xa8 ; OUTSIDE REFERER
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b VMReturnMinus1
major_0x08d88_0xb0 ; OUTSIDE REFERER
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b VMReturn
@ -730,7 +730,7 @@ VMIsResident ; OUTSIDE REFERER
lwz r6, -0x0014(r9)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
slwi r29, r4, 12
@ -742,7 +742,7 @@ VMIsResident ; OUTSIDE REFERER
VMIsResident_0x28
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r9, KDP.PrimaryAddrRangePages(r1)
VMIsResident_0x30
@ -875,13 +875,13 @@ VMMakePageCacheable_0x40
lwz r6, -0x0014(r6)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
bl major_0x08f14
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r5, 0x000c(r15)
andi. r6, r5, 0xe01
cmpwi r6, 0xa01
@ -950,13 +950,13 @@ VMMakePageWriteThrough_0x3c
lwz r6, -0x0014(r6)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
bl major_0x08f14
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r5, 0x000c(r15)
andi. r6, r5, 0xe01
cmpwi r6, 0xa01
@ -1119,13 +1119,13 @@ VMMakePageNonCacheable_0x78
lwz r6, -0x0014(r6)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
bl major_0x08f14
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r5, 0x0004(r15)
srwi r6, r5, 12
cmpw r6, r4
@ -1172,7 +1172,7 @@ VMMarkBacking ; OUTSIDE REFERER
lwz r6, -0x0014(r9)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
slwi r29, r4, 12
@ -1196,7 +1196,7 @@ VMMarkBacking_0x30
VMMarkBacking_0x50
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r9, KDP.PrimaryAddrRangePages(r1)
VMMarkBacking_0x58
@ -1277,7 +1277,7 @@ VMMarkResident ; OUTSIDE REFERER
lwz r6, -0x0014(r9)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
slwi r29, r4, 12
@ -1299,7 +1299,7 @@ VMMarkResident ; OUTSIDE REFERER
VMMarkResident_0x50
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r9, KDP.PrimaryAddrRangePages(r1)
VMMarkResident_0x58
@ -1348,7 +1348,7 @@ setPTEntryGivenPage ; OUTSIDE REFERER
lwz r6, -0x0014(r9)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
mr r26, r4
@ -1375,7 +1375,7 @@ setPTEntryGivenPage_0x34
setPTEntryGivenPage_0x5c
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
lwz r9, KDP.PrimaryAddrRangePages(r1)
setPTEntryGivenPage_0x64
@ -1562,7 +1562,7 @@ VMAllocateMemory_0x1a4
lwz r6, -0x0014(r6)
; r6 = ewa
bl Save_r14_r31
bl SchSaveStartingAtR14
; r8 = sprg0 (not used by me)
mr r30, r14
@ -1631,7 +1631,7 @@ VMAllocateMemory_0x1a4
VMAllocateMemory_0x2e0
; r6 = ewa
bl Restore_r14_r31
bl SchRestoreStartingAtR14
b VMReturn1
VMAllocateMemory_0x2e8