diff --git a/Source/Core/Core/PowerPC/Gekko.h b/Source/Core/Core/PowerPC/Gekko.h index 6da4a91d7b..f2613df73c 100644 --- a/Source/Core/Core/PowerPC/Gekko.h +++ b/Source/Core/Core/PowerPC/Gekko.h @@ -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 diff --git a/Source/Core/Core/PowerPC/MMU.cpp b/Source/Core/Core/PowerPC/MMU.cpp index 399f90b2a1..960e67147f 100644 --- a/Source/Core/Core/PowerPC/MMU.cpp +++ b/Source/Core/Core/PowerPC/MMU.cpp @@ -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