From 8c618c3fc3145da02c187c0f3662e891d5ca3363 Mon Sep 17 00:00:00 2001 From: Weiyi Wang Date: Tue, 20 Nov 2018 23:50:00 -0500 Subject: [PATCH] Memory: move PageTable functions into class --- src/core/arm/dynarmic/arm_dynarmic.cpp | 4 ++-- src/core/core.cpp | 2 +- src/core/hle/kernel/kernel.cpp | 2 +- src/core/hle/kernel/thread.cpp | 9 +++++---- src/core/hle/kernel/thread.h | 4 +++- src/core/memory.cpp | 4 ++-- src/core/memory.h | 8 ++++---- src/tests/core/arm/arm_test_common.cpp | 2 +- 8 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 19b6753a4c..9ba4d03682 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -172,7 +172,7 @@ ARM_Dynarmic::~ARM_Dynarmic() = default; MICROPROFILE_DEFINE(ARM_Jit, "ARM JIT", "ARM JIT", MP_RGB(255, 64, 64)); void ARM_Dynarmic::Run() { - ASSERT(Memory::GetCurrentPageTable() == current_page_table); + ASSERT(system.Memory().GetCurrentPageTable() == current_page_table); MICROPROFILE_SCOPE(ARM_Jit); jit->Run(); @@ -279,7 +279,7 @@ void ARM_Dynarmic::InvalidateCacheRange(u32 start_address, std::size_t length) { } void ARM_Dynarmic::PageTableChanged() { - current_page_table = Memory::GetCurrentPageTable(); + current_page_table = system.Memory().GetCurrentPageTable(); auto iter = jits.find(current_page_table); if (iter != jits.end()) { diff --git a/src/core/core.cpp b/src/core/core.cpp index 2d150a9cc3..032cf2a909 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -143,7 +143,7 @@ System::ResultStatus System::Load(EmuWindow& emu_window, const std::string& file return ResultStatus::ErrorLoader; } } - Memory::SetCurrentPageTable(&kernel->GetCurrentProcess()->vm_manager.page_table); + memory->SetCurrentPageTable(&kernel->GetCurrentProcess()->vm_manager.page_table); cheat_engine = std::make_unique(*this); status = ResultStatus::Success; m_emu_window = &emu_window; diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 5633d9bbce..f60611dcc1 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp @@ -20,7 +20,7 @@ KernelSystem::KernelSystem(Memory::MemorySystem& memory, u32 system_mode) : memo MemoryInit(system_mode); resource_limits = std::make_unique(*this); - thread_manager = std::make_unique(); + thread_manager = std::make_unique(*this); timer_manager = std::make_unique(); } diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 7f1749a5fc..d686947aa5 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -104,7 +104,7 @@ void ThreadManager::SwitchContext(Thread* new_thread) { // Cancel any outstanding wakeup events for this thread timing.UnscheduleEvent(ThreadWakeupEventType, new_thread->thread_id); - auto previous_process = Core::System::GetInstance().Kernel().GetCurrentProcess(); + auto previous_process = kernel.GetCurrentProcess(); current_thread = new_thread; @@ -112,8 +112,9 @@ void ThreadManager::SwitchContext(Thread* new_thread) { new_thread->status = ThreadStatus::Running; if (previous_process != current_thread->owner_process) { - Core::System::GetInstance().Kernel().SetCurrentProcess(current_thread->owner_process); - SetCurrentPageTable(¤t_thread->owner_process->vm_manager.page_table); + kernel.SetCurrentProcess(current_thread->owner_process); + kernel.memory.SetCurrentPageTable( + ¤t_thread->owner_process->vm_manager.page_table); } Core::CPU().LoadContext(new_thread->context); @@ -460,7 +461,7 @@ VAddr Thread::GetCommandBufferAddress() const { return GetTLSAddress() + CommandHeaderOffset; } -ThreadManager::ThreadManager() { +ThreadManager::ThreadManager(Kernel::KernelSystem& kernel) : kernel(kernel) { ThreadWakeupEventType = Core::System::GetInstance().CoreTiming().RegisterEvent( "ThreadWakeupCallback", [this](u64 thread_id, s64 cycle_late) { ThreadWakeupCallback(thread_id, cycle_late); }); diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index acb75a3749..e0af473e09 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -57,7 +57,7 @@ enum class ThreadWakeupReason { class ThreadManager { public: - ThreadManager(); + explicit ThreadManager(Kernel::KernelSystem& kernel); ~ThreadManager(); /** @@ -121,6 +121,8 @@ private: */ void ThreadWakeupCallback(u64 thread_id, s64 cycles_late); + Kernel::KernelSystem& kernel; + u32 next_thread_id = 1; SharedPtr current_thread; Common::ThreadQueueList ready_queue; diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 3326fc718b..f2bc11f6e4 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -27,14 +27,14 @@ std::array fcram; static PageTable* current_page_table = nullptr; -void SetCurrentPageTable(PageTable* page_table) { +void MemorySystem::SetCurrentPageTable(PageTable* page_table) { current_page_table = page_table; if (Core::System::GetInstance().IsPoweredOn()) { Core::CPU().PageTableChanged(); } } -PageTable* GetCurrentPageTable() { +PageTable* MemorySystem::GetCurrentPageTable() { return current_page_table; } diff --git a/src/core/memory.h b/src/core/memory.h index 3cb94dddca..fe4333d250 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -180,10 +180,6 @@ enum : VAddr { extern std::array fcram; -/// Currently active page table -void SetCurrentPageTable(PageTable* page_table); -PageTable* GetCurrentPageTable(); - /// Determines if the given VAddr is valid for the specified process. bool IsValidVirtualAddress(const Kernel::Process& process, VAddr vaddr); @@ -253,6 +249,10 @@ void RasterizerFlushVirtualRegion(VAddr start, u32 size, FlushMode mode); class MemorySystem { public: + /// Currently active page table + void SetCurrentPageTable(PageTable* page_table); + PageTable* GetCurrentPageTable(); + /// Gets offset in FCRAM from a pointer inside FCRAM range u32 GetFCRAMOffset(u8* pointer); }; diff --git a/src/tests/core/arm/arm_test_common.cpp b/src/tests/core/arm/arm_test_common.cpp index 61b4e1addf..bdd158dd02 100644 --- a/src/tests/core/arm/arm_test_common.cpp +++ b/src/tests/core/arm/arm_test_common.cpp @@ -33,7 +33,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); + memory.SetCurrentPageTable(page_table); } TestEnvironment::~TestEnvironment() {