Fix executable booting not functioning, move dirty page initialization to emu thread initialization to fix MMU bug, general code cleanliness improvements

This commit is contained in:
Jared M. White 2024-07-07 20:39:50 -05:00
parent d062310de0
commit a277d66c50
3 changed files with 10 additions and 19 deletions

View File

@ -383,7 +383,6 @@ static void CpuThread(Core::System& system, const std::optional<std::string>& sa
if (exception_handler)
{
EMM::InstallExceptionHandler();
system.GetMemory().InitDirtyPages();
}
#ifdef USE_MEMORYWATCHER
s_memory_watcher = std::make_unique<MemoryWatcher>();
@ -689,6 +688,9 @@ static void EmuThread(Core::System& system, std::unique_ptr<BootParameters> boot
cpuThreadFunc(system, savestate_path, delete_savestate);
}
if (cpuThreadFunc == CpuThread)
system.GetMemory().InitDirtyPages();
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "Stopping GDB ..."));
GDBStub::Deinit();
INFO_LOG_FMT(CONSOLE, "{}", StopMessage(true, "GDB stopped."));

View File

@ -90,7 +90,8 @@ void MemoryManager::WriteProtectPhysicalMemoryRegions()
reinterpret_cast<u64>(*region.out_pointer));
}
const size_t page_size = Common::PageSize();
for (size_t i = reinterpret_cast<intptr_t>(*region.out_pointer); i < region.size; i += page_size)
const intptr_t out_pointer = reinterpret_cast<intptr_t>(*region.out_pointer);
for (size_t i = out_pointer; i < region.size; i += page_size)
{
m_dirty_pages[i] = false;
}
@ -154,7 +155,8 @@ void MemoryManager::Init()
m_physical_regions[1] = PhysicalMemoryRegion{
&m_l1_cache, 0xE0000000, GetL1CacheSize(), PhysicalMemoryRegion::ALWAYS, 0, false, false};
m_physical_regions[2] = PhysicalMemoryRegion{
&m_fake_vmem, 0x7E000000, GetFakeVMemSize(), PhysicalMemoryRegion::FAKE_VMEM, 0, false, false};
&m_fake_vmem, 0x7E000000, GetFakeVMemSize(), PhysicalMemoryRegion::FAKE_VMEM, 0,
false, false};
m_physical_regions[3] = PhysicalMemoryRegion{
&m_exram, 0x10000000, GetExRamSize(), PhysicalMemoryRegion::WII_ONLY, 0, false, true};
@ -408,23 +410,11 @@ void MemoryManager::DoState(PointerWrap& p, bool delta)
p.DoArray(m_ram + i, page_size);
}
}
for (size_t i = 0; i < current_l1_cache_size; i += page_size)
{
if (IsPageDirty(reinterpret_cast<uintptr_t>(&m_l1_cache[i])))
{
p.DoArray(m_l1_cache + i, page_size);
}
}
p.DoArray(m_l1_cache, current_l1_cache_size);
p.DoMarker("Memory RAM");
if (current_have_fake_vmem)
{
for (size_t i = 0; i < current_fake_vmem_size; i += page_size)
{
if (IsPageDirty(reinterpret_cast<uintptr_t>(&m_fake_vmem[i])))
{
p.DoArray(m_fake_vmem + i, page_size);
}
}
p.DoArray(m_fake_vmem, current_fake_vmem_size);
}
p.DoMarker("Memory FakeVMEM");
if (current_have_exram)
@ -456,13 +446,13 @@ void MemoryManager::DoState(PointerWrap& p, bool delta)
void MemoryManager::Shutdown()
{
ShutdownFastmemArena();
m_dirty_pages.clear();
m_is_initialized = false;
for (const PhysicalMemoryRegion& region : m_physical_regions)
{
if (!region.active)
continue;
m_arena.ReleaseView(*region.out_pointer, region.size);
*region.out_pointer = nullptr;
}

View File

@ -137,7 +137,6 @@ public:
bool IsPageDirty(uintptr_t address);
void SetPageDirtyBit(uintptr_t address, size_t size, bool dirty);
void ResetDirtyPages();
bool VirtualProtectMemory(u8* data, size_t size, u64 flag);
bool HandleFault(uintptr_t fault_address);
std::map<u64, u8>& GetDirtyPages() { return m_dirty_pages; }