MMU: Make use of UReg_SDR1 in SDRUpdated()

Lets us simplify SDRUpdated() a little bit.

This also fixes the layout of UReg_SDR1. Turns out this struct has been
incorrect (from a little-endian perspective) the entire time and went
unnoticed, since the union was never used.
This commit is contained in:
Lioncash 2021-08-31 10:20:54 -04:00
parent 1c776d8c1a
commit 75840f62ff
2 changed files with 13 additions and 8 deletions

View File

@ -611,11 +611,14 @@ union UReg_HID4
// SDR1 - Page Table format
union UReg_SDR1
{
BitField<0, 16, u32> htaborg;
BitField<16, 7, u32> reserved;
BitField<23, 9, u32> htabmask;
BitField<0, 9, u32> htabmask;
BitField<9, 7, u32> reserved;
BitField<16, 16, u32> htaborg;
u32 Hex = 0;
UReg_SDR1() = default;
explicit UReg_SDR1(u32 hex_) : Hex{hex_} {}
};
// MMCR0 - Monitor Mode Control Register 0 format

View File

@ -1199,7 +1199,9 @@ static void GenerateISIException(u32 effective_address)
void SDRUpdated()
{
u32 htabmask = SDR1_HTABMASK(PowerPC::ppcState.spr[SPR_SDR]);
const auto sdr = UReg_SDR1{ppcState.spr[SPR_SDR]};
const u32 htabmask = sdr.htabmask;
if (!Common::IsValidLowMask(htabmask))
WARN_LOG_FMT(POWERPC, "Invalid HTABMASK: 0b{:032b}", htabmask);
@ -1207,12 +1209,12 @@ void SDRUpdated()
// must be equal to the number of trailing ones in the mask (i.e. HTABORG must be
// properly aligned), this is actually not a hard requirement. Real hardware will just OR
// the base address anyway. Ignoring SDR changes would lead to incorrect emulation.
u32 htaborg = SDR1_HTABORG(PowerPC::ppcState.spr[SPR_SDR]);
if (htaborg & htabmask)
const u32 htaborg = sdr.htaborg;
if ((htaborg & htabmask) != 0)
WARN_LOG_FMT(POWERPC, "Invalid HTABORG: htaborg=0x{:08x} htabmask=0x{:08x}", htaborg, htabmask);
PowerPC::ppcState.pagetable_base = htaborg << 16;
PowerPC::ppcState.pagetable_hashmask = ((htabmask << 10) | 0x3ff);
ppcState.pagetable_base = htaborg << 16;
ppcState.pagetable_hashmask = ((htabmask << 10) | 0x3ff);
}
enum class TLBLookupResult