neaten kdp

This commit is contained in:
Elliot Nunn 2018-07-15 19:13:45 +08:00
parent 2bbb5c24c8
commit 681bd4e52f
10 changed files with 75 additions and 85 deletions

View File

@ -11,7 +11,7 @@ ExceptionAfterRetry
bcl BO_IF, bitFlag15, major_0x02980_0x100
lwz r6, KDP.PA_ContextBlock(r1)
lwz r6, KDP.CurCBPtr(r1)
_bset r7, r16, 27
@ -62,11 +62,11 @@ RunExceptionHandler
li r8, 0 ; r8/Enables = 0 (handler must not throw exception)
lwz r10, CB.ExceptionHandler(r6) ; r10/SRR0 = handler addr
lwz r4, CB.ExceptionHandlerR4(r6) ; r4 = arbitrary second argument
lwz r3, KDP.LA_ECB(r1) ; r3 = ContextBlock ptr
lwz r3, KDP.ECBPtrLogical(r1) ; r3 = ContextBlock ptr
bc BO_IF, bitFlagEmu, @sys
lwz r3, KDP.NCBCacheLA0(r1)
@sys
lwz r12, KDP.LA_EmulatorKernelTrapTable + KCallTbl.ReturnFromException(r1)
lwz r12, KDP.LA_EmuKCallTbl + KCallTbl.ReturnFromException(r1)
; r12/LR = address of KCallReturnFromException trap
bcl BO_IF, bitFlagLowSaves, PreferRegistersFromKDPSavingContextBlock ; ???
@ -199,7 +199,7 @@ LoadInterruptRegisters
stw r6, KDP.r6(r1)
mfsprg r6, 1
stw r6, KDP.r1(r1)
lwz r6, KDP.PA_ContextBlock(r1)
lwz r6, KDP.CurCBPtr(r1)
stw r7, CB.r7(r6)
stw r8, CB.r8(r6)
stw r9, CB.r9(r6)
@ -236,7 +236,7 @@ Exception
########################################################################
RunSystemContext
lwz r9, KDP.PA_ECB(r1) ; System ("Emulator") ContextBlock
lwz r9, KDP.ECBPtr(r1) ; System ("Emulator") ContextBlock
addi r8, r1, KDP.VecTblSystem ; System VecTbl
mtsprg 3, r8
@ -315,8 +315,8 @@ SwitchContext ; OldCB *r6, NewCB *r9
blel ResetDEC ; to r8
lwz r8, CB.Flags(r9) ; r8 is the new Flags variable
stw r9, KDP.PA_ContextBlock(r1)
xoris r7, r7, 1 << (15 - bitFlagEmu) ; flip Emulator flag
stw r9, KDP.CurCBPtr(r1)
xoris r7, r7, 1 << (15 - bitFlagEmu) ; flip Emulator flag
rlwimi r11, r8, 0, 20, 23 ; "enact" MSR[FE0/SE/BE/FE1]
mr r6, r9 ; change the magic ContextBlock register
rlwimi r7, r8, 0, 0x0000FFFF ; change bottom half of flags only

View File

@ -19,7 +19,7 @@ IntFPUnavail
mfmsr r11 ; need this to access float registers
_bset r11, r11, bitMsrFP
lwz r6, KDP.PA_ContextBlock(r1)
lwz r6, KDP.CurCBPtr(r1)
mtmsr r11
bl LoadFloats

View File

@ -143,20 +143,20 @@ CopyInfoRecords
########################################################################
InitKernelGlobals
stw rCI, KDP.PA_ConfigInfo(r1)
stw rCI, KDP.ConfigInfoPtr(r1)
addi r12, r14, 1
stw r12, KDP.SysInfo.HashTableSize(r11)
addi rED, r1, 0x1000
stw rED, KDP.PA_EmulatorData(r1)
stw rED, KDP.EDPPtr(r1)
stw r13, KDP.KernelMemoryBase(r1)
add r12, r13, r15
stw r12, KDP.KernelMemoryEnd(r1)
lwz r12, NKConfigurationInfo.PA_RelocatedLowMemInit(rCI)
stw r12, KDP.PA_RelocatedLowMemInit(r1)
stw r12, KDP.LowMemPtr(r1)
lwz r12, NKConfigurationInfo.SharedMemoryAddr(rCI)
stw r12, KDP.SharedMemoryAddr(r1)
@ -164,24 +164,24 @@ InitKernelGlobals
lwz r12, NKConfigurationInfo.LA_EmulatorCode(rCI)
lwz r11, NKConfigurationInfo.KernelTrapTableOffset(rCI)
add r12, r12, r11
stw r12, KDP.LA_EmulatorKernelTrapTable(r1)
stw r12, KDP.LA_EmuKCallTbl(r1)
bl * + 4
mflr r12
addi r12, r12, 4 - *
stw r12, KDP.PA_NanoKernelCode(r1)
stw r12, KDP.NKCodePtr(r1)
_kaddr r12, r12, FDP
stw r12, KDP.PA_FDP(r1)
stw r12, KDP.RetryCodePtr(r1)
lwz r12, NKConfigurationInfo.LA_EmulatorData(rCI)
lwz r11, NKConfigurationInfo.ECBOffset(rCI)
add r12, r12, r11
stw r12, KDP.LA_ECB(r1)
stw r12, KDP.ECBPtrLogical(r1)
add r12, rED, r11
stw r12, KDP.PA_ECB(r1)
stw r12, KDP.PA_ContextBlock(r1)
stw r12, KDP.ECBPtr(r1)
stw r12, KDP.CurCBPtr(r1)
lwz r12, NKConfigurationInfo.TestIntMaskInit(rCI)
stw r12, KDP.TestIntMaskInit(r1)
@ -192,7 +192,7 @@ InitKernelGlobals
lwz r12, NKConfigurationInfo.IplValueOffset(rCI)
add r12, rED, r12
stw r12, KDP.PA_EmulatorIplValue(r1)
stw r12, KDP.EmuIntLevelPtr(r1)
lwz r12, NKConfigurationInfo.SharedMemoryAddr(rCI)
addi r12, r12, 0x7c
@ -203,9 +203,9 @@ InitKernelGlobals
addi r13, r1, KDP.PageMap
lwz r12, NKConfigurationInfo.PageMapInitSize(rCI)
stw r13, KDP.PA_PageMapStart(r1)
stw r13, KDP.PageMapStartPtr(r1)
add r13, r13, r12
stw r13, KDP.PA_PageMapEnd(r1)
stw r13, KDP.PageMapEndPtr(r1)
########################################################################
@ -265,7 +265,7 @@ InitProcessorInfo
mfpvr r12
stw r12, KDP.ProcInfo.ProcessorVersionReg(r1)
srwi r12, r12, 16
lwz r11, KDP.PA_NanoKernelCode(r1)
lwz r11, KDP.NKCodePtr(r1)
addi r10, r1, KDP.ProcInfo.Ovr
li r9, NKProcessorInfo.OvrEnd - NKProcessorInfo.Ovr
_kaddr r11, r11, ProcessorInfoTable
@ -358,7 +358,7 @@ InitEmulator
stw r12, 12(r11)
lwz r12, NKConfigurationInfo.LA_EmulatorCode(rCI) ; Prepare the System ContextBlock
lwz r12, NKConfigurationInfo.LA_EmulatorCode(rCI) ; Prepare the System ContextBlock:
lwz r11, NKConfigurationInfo.EmulatorEntryOffset(rCI)
add r12, r11, r12
lwz r11, NKConfigurationInfo.ECBOffset(rCI) ; address of declared Emu entry point
@ -371,11 +371,11 @@ InitEmulator
lwz r12, NKConfigurationInfo.LA_DispatchTable(rCI) ; address of 512kb Emu dispatch table
stw r12, CB.ExceptionOriginR4(r11)
lwz r12, KDP.LA_EmulatorKernelTrapTable(r1) ; address of KCallReturnFromException trap
lwz r12, KDP.LA_EmuKCallTbl(r1) ; address of KCallReturnFromException trap
stw r12, CB.ExceptionHandlerRetAddr(r11)
lwz r10, KDP.PA_RelocatedLowMemInit(r1) ; Zero out bottom 8k of Low Memory
lwz r10, KDP.LowMemPtr(r1) ; Zero out bottom 8k of Low Memory
li r9, 0x2000
@zeroloop
subic. r9, r9, 4
@ -384,7 +384,7 @@ InitEmulator
lwz r11, NKConfigurationInfo.MacLowMemInitOffset(rCI) ; Read address/value pairs from ConfigInfo
lwz r10, KDP.PA_RelocatedLowMemInit(r1) ; and apply them to Low Memory
lwz r10, KDP.LowMemPtr(r1) ; and apply them to Low Memory
lwzux r9, r11, rCI
@setloop
mr. r9, r9
@ -406,7 +406,7 @@ InitEmulator
stw r7, KDP.Flags(r1)
lwz r10, KDP.LA_EmulatorKernelTrapTable(r1) ; Start at KCallReturnFromException trap
lwz r10, KDP.LA_EmuKCallTbl(r1) ; Start at KCallReturnFromException trap
mfmsr r14 ; Calculate the user space MSR

View File

@ -30,7 +30,7 @@ IntExternal0
lwz r2, KDP.DebugIntPtr(r1) ; Query the shared mem (debug?) for int num
mfcr r0
lha r2, 0(r2)
lwz r3, KDP.PA_EmulatorIplValue(r1)
lwz r3, KDP.EmuIntLevelPtr(r1)
rlwinm. r2, r2, 0, 0x80000007
ori r2, r2, 0x8000
sth r2, 0(r3)
@ -97,11 +97,11 @@ IntExternal1
lwz r4, KDP.r4(r1)
lwz r5, KDP.r5(r1)
lwz r3, KDP.PA_NanoKernelCode(r1) ; Loop that number up in the table
lwz r3, KDP.NKCodePtr(r1) ; Loop that number up in the table
rlwimi r3, r0, 0, 0x0000003F
lbz r2, IntLookupTable-NKTop(r3)
mfcr r0
lwz r3, KDP.PA_EmulatorIplValue(r1)
lwz r3, KDP.EmuIntLevelPtr(r1)
clrlwi. r2, r2, 29
sth r2, 0(r3)
mfsprg r2, 2
@ -179,7 +179,7 @@ IntExternal2
; else -> 0
@gotnum
lwz r3, KDP.PA_EmulatorIplValue(r1)
lwz r3, KDP.EmuIntLevelPtr(r1)
sth r2, 0(r3)
mfsprg r2, 2
lwz r3, KDP.r3(r1)
@ -282,7 +282,7 @@ IntDSI
EmulateDataAccess
rlwinm. r18, r27, 18, 25, 29 ; r16 = 4 * rA (r0 wired to 0)
lwz r25, KDP.PA_FDP(r1)
lwz r25, KDP.RetryCodePtr(r1)
li r21, 0
beq @r0
lwzx r18, r1, r18
@ -346,7 +346,7 @@ IntAlignment
mfdar r18
extrwi. r21, r27, 2, 15 ; evaluate hi two bits of XO (or 0 for d-form?)
lwz r25, KDP.PA_FDP(r1)
lwz r25, KDP.RetryCodePtr(r1)
rlwinm r17, r27, 16, 0x03FF0000
lwz r16, KDP.Flags(r1)
rlwimi r25, r27, 24, 23, 29 ; add constant fields from dsisr (*4) to FDP

View File

@ -33,7 +33,7 @@ MaxVMCallCount equ 26
KCallVMDispatch ; OUTSIDE REFERER
stw r7, KDP.Flags(r1)
lwz r7, KDP.PA_NanoKernelCode(r1)
lwz r7, KDP.NKCodePtr(r1)
cmplwi r3, MaxVMCallCount
insrwi r7, r3, 7, 24
lhz r8, VMDispatchTable - NKTop(r7)
@ -114,7 +114,7 @@ VMReturn ; OUTSIDE REFERER
lwz r15, KDP.r15(r1)
lwz r16, KDP.r16(r1)
lwz r7, KDP.Flags(r1)
lwz r6, KDP.PA_ContextBlock(r1)
lwz r6, KDP.CurCBPtr(r1)
b IntReturn

View File

@ -213,7 +213,7 @@ PopulateHTAB ; LogicalAddress r28 // Success cr0.eq
cmpwi cr7, r28, 0
clrrwi r28, r31, 12
cmpw r28, r1
lwz r30, KDP.PA_ContextBlock(r1)
lwz r30, KDP.CurCBPtr(r1)
beq cr7, @rethink_pte_search
addi r31, r30, 768-1

View File

@ -5,13 +5,13 @@
; These registers will be used throughout
rCI set r26
lwz rCI, KDP.PA_ConfigInfo(r1)
lwz rCI, KDP.ConfigInfoPtr(r1)
rNK set r25
lwz rNK, KDP.PA_NanoKernelCode(r1)
lwz rNK, KDP.NKCodePtr(r1)
rPgMap set r18
lwz rPgMap, KDP.PA_PageMapStart(r1)
lwz rPgMap, KDP.PageMapStartPtr(r1)
rXER set r17
mfxer rXER
@ -148,25 +148,18 @@ InitKCalls
########################################################################
; Put HTABORG and PTEGMask in KDP, and zero out the last PTEG
InitHTAB
mfspr r8, sdr1
; get settable HTABMASK bits
rlwinm r22, r8, 16, 7, 15
rlwinm r22, r8, 16, 7, 15 ; Get settable HTABMASK bits
rlwinm r8, r8, 0, 0, 15 ; and HTABORG
; and HTABORG
rlwinm r8, r8, 0, 0, 15
ori r22, r22, (-64) & 0xffff; "PTEGMask" from upper half of HTABMASK
; get a PTEGMask from upper half of HTABMASK
ori r22, r22, (-64) & 0xffff
; Save in KDP (OldWorld must do this another way)
stw r8, KDP.HTABORG(r1)
stw r8, KDP.HTABORG(r1) ; Save
stw r22, KDP.PTEGMask(r1)
; zero out the last PTEG in the HTAB
li r23, 0
li r23, 0 ; Zero out the last PTEG in the HTAB
addi r22, r22, 64
@next_segment
subic. r22, r22, 4
@ -174,8 +167,7 @@ InitHTAB
bgt @next_segment
@skip_zeroing_pteg
; Flush the TLB after touching the HTAB
bl FlushTLB
bl FlushTLB ; Flush the TLB after touching the HTAB
########################################################################
@ -228,7 +220,7 @@ CopyPageMap
rlwimi r23, r1, 0, 0xFFFFF000
stw r23, PME.PBaseAndFlags(r8)
lwz r19, KDP.PA_EmulatorData(r1)
lwz r19, KDP.EDPPtr(r1)
lwz r8, NKConfigurationInfo.PageMapEDPOffset(rCI)
add r8, rPgMap, r8
lwz r23, PME.PBaseAndFlags(r8)
@ -423,15 +415,15 @@ CreatePARInPageMap
; Make sure some important areas of RAM are in the HTAB
lwz r27, KDP.PA_ConfigInfo(r1)
lwz r27, KDP.ConfigInfoPtr(r1)
lwz r27, NKConfigurationInfo.LA_InterruptCtl(r27)
bl PopulateHTAB
lwz r27, KDP.PA_ConfigInfo(r1)
lwz r27, KDP.ConfigInfoPtr(r1)
lwz r27, NKConfigurationInfo.LA_KernelData(r27)
bl PopulateHTAB
lwz r27, KDP.PA_ConfigInfo(r1)
lwz r27, KDP.ConfigInfoPtr(r1)
lwz r27, NKConfigurationInfo.LA_EmulatorData(r27)
bl PopulateHTAB

View File

@ -113,12 +113,12 @@ KCallRunAlternateContext
addi r8, r1, KDP.VecTblAlternate ; the only use of this vector table?
mtsprg 3, r8
lwz r8, KDP.LA_EmulatorKernelTrapTable(r1)
lwz r8, KDP.LA_EmuKCallTbl(r1)
mtcrf 0x3f, r7
clrlwi r7, r7, 8
stw r8, CB.ExceptionHandlerRetAddr(r9)
stw r9, KDP.PA_ContextBlock(r1)
stw r9, KDP.CurCBPtr(r1)
b SwitchContext ; OldCB *r6, NewCB *r9
@ -329,7 +329,7 @@ IntProgram
stw r6, KDP.r6(r1)
mfsprg r6, 1
stw r6, KDP.r1(r1)
lwz r6, KDP.PA_ContextBlock(r1)
lwz r6, KDP.CurCBPtr(r1)
stw r7, CB.r7(r6)
stw r8, CB.r8(r6)
stw r9, CB.r9(r6)
@ -339,7 +339,7 @@ IntProgram
stw r13, CB.r13(r6)
; Compare SRR0 with address of Emulator's KCall trap table
lwz r8, KDP.LA_EmulatorKernelTrapTable(r1)
lwz r8, KDP.LA_EmuKCallTbl(r1)
mfsrr0 r10
mfcr r13
xor. r8, r10, r8

View File

@ -190,36 +190,34 @@ CurrentMemLayout ds MemLayout ; 5e8:5f0
KCallTbl ds KCallTbl ; 5f0:630
PA_ConfigInfo ds.l 1 ; 630
PA_EmulatorData ds.l 1 ; 634
ConfigInfoPtr ds.l 1 ; 630
EDPPtr ds.l 1 ; 634
KernelMemoryBase ds.l 1 ; 638
KernelMemoryEnd ds.l 1 ; 63c ; Top of HTAB (and entire kernel reserved area). Set by Init.s
PA_RelocatedLowMemInit ds.l 1 ; 640 ; From ConfigInfo. Ptr to Mac LowMem vars, which Init.s sets up
SharedMemoryAddr ds.l 1 ; 644 ; From ConfigInfo. Not sure what latest use is.
LA_EmulatorKernelTrapTable ds.l 1 ; 648 ; Calculated from ConfigInfo.
PA_NanoKernelCode ds.l 1 ; 64c ; Calculated by NanoKernel itself.
PA_FDP ds.l 1 ; 650 ; See notes in NanoKernel. Very interesting.
LA_ECB ds.l 1 ; 654 ; Logical ptr into EDP.
PA_ECB ds.l 1 ; 658 ; gets called "system context"
PA_ContextBlock ds.l 1 ; 65c ; moved to EWA (per-CPU) in NKv2
KernelMemoryEnd ds.l 1 ; 63c
LowMemPtr ds.l 1 ; 640 ; physical address of PAR Low Memory
SharedMemoryAddr ds.l 1 ; 644 ; debug?
EmuKCallTblPtrLogical ds.l 1 ; 648
NKCodePtr ds.l 1 ; 64c
RetryCodePtr ds.l 1 ; 650
ECBPtrLogical ds.l 1 ; 654 ; Emulator/System ContextBlock
ECBPtr ds.l 1 ; 658
CurCBPtr ds.l 1 ; 65c ; moved to EWA (per-CPU) in NKv2
Flags ds.l 1 ; 660 ; moved to EWA (per-CPU) in NKv2
Enables ds.l 1 ; 664 ; moved to EWA (per-CPU) in NKv2
OtherContextDEC ds.l 1 ; 668 ; ticks the *inactive* context has left out of 1s
PA_PageMapEnd ds.l 1 ; 66c ; Set at the same time as PA_PageMapStart below...
TestIntMaskInit ds.l 1 ; 670 ; These are all copied from ConfigInfo...
PostIntMaskInit ds.l 1 ; 674
ClearIntMaskInit ds.l 1 ; 678
PA_EmulatorIplValue ds.l 1 ; 67c ; Physical ptr into EDP
DebugIntPtr ds.l 1 ; 680 ; Within (debug?) shared memory
PA_PageMapStart ds.l 1 ; 684 ; Physical ptr to PageMap (= KDP+0x920)
PageAttributeInit ds.l 1 ; 688 ; defaults for page table entries (see ConfigInfo)
HtabTempPage ds.l 1 ; 68c
HtabTempEntryPtr ds.l 1 ; 690
OtherContextDEC ds.l 1 ; 668 ; ticks that the *inactive* context has left out of 1s
PageMapEndPtr ds.l 1 ; 66c ; et at the same time as PageMapStartPtr below
TestIntMaskInit ds.l 1 ; 670
PostIntMaskInit ds.l 1 ; 674 ; CR flags to set when posting an interrupt to the Emulator
ClearIntMaskInit ds.l 1 ; 678 ; CR flags to clear (as mask) when clearing an interrupt
EmuIntLevelPtr ds.l 1 ; 67c ; physical ptr to an Emulator global
DebugIntPtr ds.l 1 ; 680 ; within (debug?) shared memory
PageMapStartPtr ds.l 1 ; 684
PageAttributeInit ds.l 1 ; 688 ; defaults for PLE/PTE?
HtabTempPage ds.l 1 ; 68c ; a page that lives temporarily in the HTAB (per its PME)
HtabTempEntryPtr ds.l 1 ; 690 ; ptr to that PME
NewestPageInHtab ds.l 1 ; 694
ApproxCurrentPTEG ds.l 1 ; 698
OverflowingPTEG ds.l 1 ; 69c
PTEGMask ds.l 1 ; 6a0
HTABORG ds.l 1 ; 6a4
VMLogicalPages ds.l 1 ; 6a8 ; set at init and changed by VMInit

View File

@ -2146,7 +2146,7 @@ ProbePerfMonitor ; OUTSIDE REFERER
; Temporarily disable program interrupts (leave old handler in r20)
lwz r21, KDP.PA_NanoKernelCode(r1)
lwz r21, KDP.NKCodePtr(r1)
lwz r20, KDP.VecTblSystem.ProgramIntVector(r1)
llabel r18, IgnoreSoftwareInt
add r21, r18, r21