Merge pull request #4799 from bamsbamx/pr-separate-cpu-mem
kernel: handle all page table changes internally when switching processes
This commit is contained in:
commit
508fa94e5d
|
@ -141,7 +141,6 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
|
||||||
return ResultStatus::ErrorLoader;
|
return ResultStatus::ErrorLoader;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
memory->SetCurrentPageTable(&kernel->GetCurrentProcess()->vm_manager.page_table);
|
|
||||||
cheat_engine = std::make_unique<Cheats::CheatEngine>(*this);
|
cheat_engine = std::make_unique<Cheats::CheatEngine>(*this);
|
||||||
status = ResultStatus::Success;
|
status = ResultStatus::Success;
|
||||||
m_emu_window = &emu_window;
|
m_emu_window = &emu_window;
|
||||||
|
@ -179,17 +178,16 @@ System::ResultStatus System::Init(Frontend::EmuWindow& emu_window, u32 system_mo
|
||||||
|
|
||||||
if (Settings::values.use_cpu_jit) {
|
if (Settings::values.use_cpu_jit) {
|
||||||
#ifdef ARCHITECTURE_x86_64
|
#ifdef ARCHITECTURE_x86_64
|
||||||
cpu_core = std::make_unique<ARM_Dynarmic>(this, *memory, USER32MODE);
|
cpu_core = std::make_shared<ARM_Dynarmic>(this, *memory, USER32MODE);
|
||||||
#else
|
#else
|
||||||
cpu_core = std::make_unique<ARM_DynCom>(this, *memory, USER32MODE);
|
cpu_core = std::make_shared<ARM_DynCom>(this, *memory, USER32MODE);
|
||||||
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
|
LOG_WARNING(Core, "CPU JIT requested, but Dynarmic not available");
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
cpu_core = std::make_unique<ARM_DynCom>(this, *memory, USER32MODE);
|
cpu_core = std::make_shared<ARM_DynCom>(this, *memory, USER32MODE);
|
||||||
}
|
}
|
||||||
|
|
||||||
kernel->GetThreadManager().SetCPU(*cpu_core);
|
kernel->SetCPU(cpu_core);
|
||||||
memory->SetCPU(*cpu_core);
|
|
||||||
|
|
||||||
if (Settings::values.enable_dsp_lle) {
|
if (Settings::values.enable_dsp_lle) {
|
||||||
dsp_core = std::make_unique<AudioCore::DspLle>(*memory,
|
dsp_core = std::make_unique<AudioCore::DspLle>(*memory,
|
||||||
|
|
|
@ -255,7 +255,7 @@ private:
|
||||||
std::unique_ptr<Loader::AppLoader> app_loader;
|
std::unique_ptr<Loader::AppLoader> app_loader;
|
||||||
|
|
||||||
/// ARM11 CPU core
|
/// ARM11 CPU core
|
||||||
std::unique_ptr<ARM_Interface> cpu_core;
|
std::shared_ptr<ARM_Interface> cpu_core;
|
||||||
|
|
||||||
/// DSP core
|
/// DSP core
|
||||||
std::unique_ptr<AudioCore::DspInterface> dsp_core;
|
std::unique_ptr<AudioCore::DspInterface> dsp_core;
|
||||||
|
|
|
@ -47,7 +47,20 @@ std::shared_ptr<Process> KernelSystem::GetCurrentProcess() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelSystem::SetCurrentProcess(std::shared_ptr<Process> process) {
|
void KernelSystem::SetCurrentProcess(std::shared_ptr<Process> process) {
|
||||||
current_process = std::move(process);
|
current_process = process;
|
||||||
|
SetCurrentMemoryPageTable(&process->vm_manager.page_table);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KernelSystem::SetCurrentMemoryPageTable(Memory::PageTable* page_table) {
|
||||||
|
memory.SetCurrentPageTable(page_table);
|
||||||
|
if (current_cpu != nullptr) {
|
||||||
|
current_cpu->PageTableChanged(); // notify the CPU the page table in memory has changed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void KernelSystem::SetCPU(std::shared_ptr<ARM_Interface> cpu) {
|
||||||
|
current_cpu = cpu;
|
||||||
|
thread_manager->SetCPU(*cpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
ThreadManager& KernelSystem::GetThreadManager() {
|
ThreadManager& KernelSystem::GetThreadManager() {
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/kernel/memory.h"
|
#include "core/hle/kernel/memory.h"
|
||||||
#include "core/hle/result.h"
|
#include "core/hle/result.h"
|
||||||
|
#include "core/memory.h"
|
||||||
|
|
||||||
namespace ConfigMem {
|
namespace ConfigMem {
|
||||||
class Handler;
|
class Handler;
|
||||||
|
@ -206,6 +207,10 @@ public:
|
||||||
std::shared_ptr<Process> GetCurrentProcess() const;
|
std::shared_ptr<Process> GetCurrentProcess() const;
|
||||||
void SetCurrentProcess(std::shared_ptr<Process> process);
|
void SetCurrentProcess(std::shared_ptr<Process> process);
|
||||||
|
|
||||||
|
void SetCurrentMemoryPageTable(Memory::PageTable* page_table);
|
||||||
|
|
||||||
|
void SetCPU(std::shared_ptr<ARM_Interface> cpu);
|
||||||
|
|
||||||
ThreadManager& GetThreadManager();
|
ThreadManager& GetThreadManager();
|
||||||
const ThreadManager& GetThreadManager() const;
|
const ThreadManager& GetThreadManager() const;
|
||||||
|
|
||||||
|
@ -233,6 +238,8 @@ public:
|
||||||
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort
|
/// Map of named ports managed by the kernel, which can be retrieved using the ConnectToPort
|
||||||
std::unordered_map<std::string, std::shared_ptr<ClientPort>> named_ports;
|
std::unordered_map<std::string, std::shared_ptr<ClientPort>> named_ports;
|
||||||
|
|
||||||
|
std::shared_ptr<ARM_Interface> current_cpu;
|
||||||
|
|
||||||
Memory::MemorySystem& memory;
|
Memory::MemorySystem& memory;
|
||||||
|
|
||||||
Core::Timing& timing;
|
Core::Timing& timing;
|
||||||
|
|
|
@ -112,8 +112,6 @@ void ThreadManager::SwitchContext(Thread* new_thread) {
|
||||||
|
|
||||||
if (previous_process.get() != current_thread->owner_process) {
|
if (previous_process.get() != current_thread->owner_process) {
|
||||||
kernel.SetCurrentProcess(SharedFrom(current_thread->owner_process));
|
kernel.SetCurrentProcess(SharedFrom(current_thread->owner_process));
|
||||||
kernel.memory.SetCurrentPageTable(
|
|
||||||
¤t_thread->owner_process->vm_manager.page_table);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cpu->LoadContext(new_thread->context);
|
cpu->LoadContext(new_thread->context);
|
||||||
|
|
|
@ -66,22 +66,14 @@ public:
|
||||||
RasterizerCacheMarker cache_marker;
|
RasterizerCacheMarker cache_marker;
|
||||||
std::vector<PageTable*> page_table_list;
|
std::vector<PageTable*> page_table_list;
|
||||||
|
|
||||||
ARM_Interface* cpu = nullptr;
|
|
||||||
AudioCore::DspInterface* dsp = nullptr;
|
AudioCore::DspInterface* dsp = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
MemorySystem::MemorySystem() : impl(std::make_unique<Impl>()) {}
|
MemorySystem::MemorySystem() : impl(std::make_unique<Impl>()) {}
|
||||||
MemorySystem::~MemorySystem() = default;
|
MemorySystem::~MemorySystem() = default;
|
||||||
|
|
||||||
void MemorySystem::SetCPU(ARM_Interface& cpu) {
|
|
||||||
impl->cpu = &cpu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemorySystem::SetCurrentPageTable(PageTable* page_table) {
|
void MemorySystem::SetCurrentPageTable(PageTable* page_table) {
|
||||||
impl->current_page_table = page_table;
|
impl->current_page_table = page_table;
|
||||||
if (impl->cpu != nullptr) {
|
|
||||||
impl->cpu->PageTableChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PageTable* MemorySystem::GetCurrentPageTable() const {
|
PageTable* MemorySystem::GetCurrentPageTable() const {
|
||||||
|
|
|
@ -220,9 +220,6 @@ public:
|
||||||
MemorySystem();
|
MemorySystem();
|
||||||
~MemorySystem();
|
~MemorySystem();
|
||||||
|
|
||||||
/// Sets CPU to notify page table change
|
|
||||||
void SetCPU(ARM_Interface& cpu);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maps an allocated buffer onto a region of the emulated process address space.
|
* Maps an allocated buffer onto a region of the emulated process address space.
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,7 +28,7 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
||||||
memory->MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
|
memory->MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
|
||||||
memory->MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
|
memory->MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
|
||||||
|
|
||||||
memory->SetCurrentPageTable(page_table);
|
kernel->SetCurrentMemoryPageTable(page_table);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestEnvironment::~TestEnvironment() {
|
TestEnvironment::~TestEnvironment() {
|
||||||
|
|
Reference in New Issue