Skip to content

Commit c17fd94

Browse files
committed
Media Engine: consolidate IsMeSensitiveHwPage to MemMapFunctions.cpp
Move the ME hardware page check function from three separate static copies (ARM64 backend, x64 backend, IRPassSimplify) into a single implementation in MemMapFunctions.cpp with declaration in MemMap.h. All three consumers (NeedsGenericMeHwAccess in both JIT backends and ApplyMeMemoryValidation in the IR pass) now use Memory::IsMeSensitiveHwPage().
1 parent 51a1db6 commit c17fd94

5 files changed

Lines changed: 30 additions & 41 deletions

File tree

Core/MIPS/ARM64/Arm64IRCompLoadStore.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,6 @@ namespace MIPSComp {
3838
using namespace Arm64Gen;
3939
using namespace Arm64IRJitConstants;
4040

41-
// Returns true if the given address falls within an ME-sensitive hardware register page.
42-
// These are pages where ME code reads/writes MMIO registers that need to go through
43-
// ReadFromHardware/WriteToHardware rather than direct memory access.
44-
//
45-
// Physical ranges (after masking with 0x1FFFFFFF):
46-
// 0x1C000000 - System Controller (power, clock, reset control)
47-
// 0x1C100000 - ME interrupt / soft-interrupt registers (0xBC100044, 0xBC100048, etc.)
48-
// 0x1C200000 - ME/SC communication registers
49-
// 0x1C300000 - Additional system control
50-
// 0x1CC00000 - VME (Video ME) registers (CSC, etc.)
51-
// 0x1D000000 - DMACplus registers
52-
static bool IsMeSensitiveHwPage(u32 address) {
53-
u32 phys = address & 0x1FFFFFFF;
54-
return (phys >= 0x1C000000 && phys < 0x1C001000) ||
55-
(phys >= 0x1C100000 && phys < 0x1C101000) ||
56-
(phys >= 0x1C200000 && phys < 0x1C201000) ||
57-
(phys >= 0x1C300000 && phys < 0x1C301000) ||
58-
(phys >= 0x1CC00000 && phys < 0x1CC01000) ||
59-
(phys >= 0x1D000000 && phys < 0x1D001000);
60-
}
61-
6241
static u32 ComputeConstantAddress(const IRInst &inst, Arm64IRRegCache &regs) {
6342
uint64_t base = 0;
6443
if (inst.src1 != MIPS_REG_ZERO) {
@@ -83,7 +62,7 @@ static bool NeedsGenericMeHwAccess(const IRInst &inst, Arm64IRRegCache &regs, co
8362
return false;
8463
}
8564
u32 addr = ComputeConstantAddress(inst, regs);
86-
bool sensitive = IsMeSensitiveHwPage(addr);
65+
bool sensitive = Memory::IsMeSensitiveHwPage(addr);
8766
if (sensitive) {
8867
DEBUG_LOG(Log::JIT, "ME HW access detected: addr=%08x src1=%d constant=%08x -> GENERIC", addr, inst.src1, inst.constant);
8968
}

Core/MIPS/IR/IRPassSimplify.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Common/Data/Convert/SmallDataConvert.h"
77
#include "Common/Log.h"
88
#include "Core/Config.h"
9+
#include "Core/MemMap.h"
910
#include "Core/MIPS/MIPSVFPUUtils.h"
1011
#include "Core/MIPS/IR/IRAnalysis.h"
1112
#include "Core/MIPS/IR/IRInterpreter.h"
@@ -1808,12 +1809,6 @@ static IRMemoryOpInfo IROpMemoryAccessSize(IROp op) {
18081809
}
18091810
}
18101811

1811-
// Matches IsMeSensitiveHwPage() in Arm64IRCompLoadStore.cpp.
1812-
static bool IsMeHwPageForValidation(u32 address) {
1813-
u32 phys = address & 0x1FFFFFFF;
1814-
return (phys >= 0x1C000000 && phys < 0x1D100000);
1815-
}
1816-
18171812
bool ApplyMeMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions &opts) {
18181813
CONDITIONAL_DISABLE;
18191814
if (g_Config.bFastMemory)
@@ -1833,7 +1828,7 @@ bool ApplyMeMemoryValidation(const IRWriter &in, IRWriter &out, const IROptions
18331828
} else {
18341829
// src1 == ZERO, address is fully constant.
18351830
u32 addr = inst.constant;
1836-
if (IsMeHwPageForValidation(addr)) {
1831+
if (Memory::IsMeSensitiveHwPage(addr)) {
18371832
// The backend handles ME HW registers.
18381833
skipValidation = true;
18391834
}

Core/MIPS/x86/X64IRCompLoadStore.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ namespace MIPSComp {
3737
using namespace Gen;
3838
using namespace X64IRJitConstants;
3939

40-
// See Arm64IRCompLoadStore.cpp for detailed documentation of these ranges.
41-
static bool IsMeSensitiveHwPage(u32 address) {
42-
u32 phys = address & 0x1FFFFFFF;
43-
return (phys >= 0x1C000000 && phys < 0x1C001000) ||
44-
(phys >= 0x1C100000 && phys < 0x1C101000) ||
45-
(phys >= 0x1C200000 && phys < 0x1C201000) ||
46-
(phys >= 0x1C300000 && phys < 0x1C301000) ||
47-
(phys >= 0x1CC00000 && phys < 0x1CC01000) ||
48-
(phys >= 0x1D000000 && phys < 0x1D001000);
49-
}
50-
5140
static u32 ComputeConstantAddress(const IRInst &inst, X64IRRegCache &regs) {
5241
uint64_t base = 0;
5342
if (inst.src1 != MIPS_REG_ZERO) {
@@ -68,7 +57,7 @@ static bool NeedsGenericMeHwAccess(const IRInst &inst, X64IRRegCache &regs, cons
6857
return false;
6958
if (inst.src1 != MIPS_REG_ZERO && !regs.IsGPRImm(inst.src1))
7059
return false;
71-
return IsMeSensitiveHwPage(ComputeConstantAddress(inst, regs));
60+
return Memory::IsMeSensitiveHwPage(ComputeConstantAddress(inst, regs));
7261
}
7362

7463
Gen::OpArg X64JitBackend::PrepareSrc1Address(IRInst inst) {

Core/MemMap.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ inline bool IsValid4AlignedAddress(const u32 address) {
336336
}
337337
}
338338

339+
// Returns true if address is in an ME-sensitive hardware register page
340+
// (system controller, ME interrupts, VME, DMACplus, etc.).
341+
// Implementation in MemMapFunctions.cpp.
342+
bool IsMeSensitiveHwPage(u32 address);
343+
339344
inline u32 MaxSizeAtAddress(const u32 address){
340345
if ((address & 0x3E000000) == 0x08000000) {
341346
return 0x08000000 + g_MemorySize - (address & 0x3FFFFFFF);

Core/MemMapFunctions.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ static inline bool IsMeHwRegister(u32 address) {
171171
return (phys >= 0x1C000000 && phys < 0x1D100000);
172172
}
173173

174+
// Finer-grained check for specific ME hardware register pages.
175+
// Used by IR backends and validation passes to detect MMIO accesses
176+
// that must go through ReadFromHardware/WriteToHardware.
177+
//
178+
// Physical ranges (after masking with 0x1FFFFFFF):
179+
// 0x1C000000 - System Controller (power, clock, reset control)
180+
// 0x1C100000 - ME interrupt / soft-interrupt registers (0xBC100044, 0xBC100048, etc.)
181+
// 0x1C200000 - ME/SC communication registers
182+
// 0x1C300000 - Additional system control
183+
// 0x1CC00000 - VME (Video ME) registers (CSC, etc.)
184+
// 0x1D000000 - DMACplus registers
185+
bool IsMeSensitiveHwPage(u32 address) {
186+
u32 phys = address & 0x1FFFFFFF;
187+
return (phys >= 0x1C000000 && phys < 0x1C001000) ||
188+
(phys >= 0x1C100000 && phys < 0x1C101000) ||
189+
(phys >= 0x1C200000 && phys < 0x1C201000) ||
190+
(phys >= 0x1C300000 && phys < 0x1C301000) ||
191+
(phys >= 0x1CC00000 && phys < 0x1CC01000) ||
192+
(phys >= 0x1D000000 && phys < 0x1D001000);
193+
}
194+
174195
// The page at 0xBC100000 (physical 0x1C100000) is mapped in the arena.
175196
// The JIT does raw LDR/STR there, and the interpreter goes through these
176197
// helpers. Per-CPU mutex masking is NOT applied because the emulator is

0 commit comments

Comments
 (0)