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:
Weiyi Wang 2019-07-13 22:25:51 -04:00 committed by GitHub
commit 508fa94e5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 22 deletions

View file

@ -141,7 +141,6 @@ System::ResultStatus System::Load(Frontend::EmuWindow& emu_window, const std::st
return ResultStatus::ErrorLoader;
}
}
memory->SetCurrentPageTable(&kernel->GetCurrentProcess()->vm_manager.page_table);
cheat_engine = std::make_unique<Cheats::CheatEngine>(*this);
status = ResultStatus::Success;
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) {
#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
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");
#endif
} 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);
memory->SetCPU(*cpu_core);
kernel->SetCPU(cpu_core);
if (Settings::values.enable_dsp_lle) {
dsp_core = std::make_unique<AudioCore::DspLle>(*memory,

View file

@ -255,7 +255,7 @@ private:
std::unique_ptr<Loader::AppLoader> app_loader;
/// ARM11 CPU core
std::unique_ptr<ARM_Interface> cpu_core;
std::shared_ptr<ARM_Interface> cpu_core;
/// DSP core
std::unique_ptr<AudioCore::DspInterface> dsp_core;

View file

@ -47,7 +47,20 @@ std::shared_ptr<Process> KernelSystem::GetCurrentProcess() const {
}
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() {

View file

@ -14,6 +14,7 @@
#include "common/common_types.h"
#include "core/hle/kernel/memory.h"
#include "core/hle/result.h"
#include "core/memory.h"
namespace ConfigMem {
class Handler;
@ -206,6 +207,10 @@ public:
std::shared_ptr<Process> GetCurrentProcess() const;
void SetCurrentProcess(std::shared_ptr<Process> process);
void SetCurrentMemoryPageTable(Memory::PageTable* page_table);
void SetCPU(std::shared_ptr<ARM_Interface> cpu);
ThreadManager& GetThreadManager();
const ThreadManager& GetThreadManager() const;
@ -233,6 +238,8 @@ public:
/// 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::shared_ptr<ARM_Interface> current_cpu;
Memory::MemorySystem& memory;
Core::Timing& timing;

View file

@ -112,8 +112,6 @@ void ThreadManager::SwitchContext(Thread* new_thread) {
if (previous_process.get() != current_thread->owner_process) {
kernel.SetCurrentProcess(SharedFrom(current_thread->owner_process));
kernel.memory.SetCurrentPageTable(
&current_thread->owner_process->vm_manager.page_table);
}
cpu->LoadContext(new_thread->context);

View file

@ -66,22 +66,14 @@ public:
RasterizerCacheMarker cache_marker;
std::vector<PageTable*> page_table_list;
ARM_Interface* cpu = nullptr;
AudioCore::DspInterface* dsp = nullptr;
};
MemorySystem::MemorySystem() : impl(std::make_unique<Impl>()) {}
MemorySystem::~MemorySystem() = default;
void MemorySystem::SetCPU(ARM_Interface& cpu) {
impl->cpu = &cpu;
}
void MemorySystem::SetCurrentPageTable(PageTable* page_table) {
impl->current_page_table = page_table;
if (impl->cpu != nullptr) {
impl->cpu->PageTableChanged();
}
}
PageTable* MemorySystem::GetCurrentPageTable() const {

View file

@ -220,9 +220,6 @@ public:
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.
*

View file

@ -28,7 +28,7 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
memory->MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
memory->MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
memory->SetCurrentPageTable(page_table);
kernel->SetCurrentMemoryPageTable(page_table);
}
TestEnvironment::~TestEnvironment() {