core/memory: Introduce skeleton of Memory class
Currently, the main memory management code is one of the remaining places where we have global state. The next series of changes will aim to rectify this. This change simply introduces the main skeleton of the class that will contain all the necessary state.
This commit is contained in:
parent
6df6caaf5f
commit
4c2ed2706e
|
@ -39,6 +39,7 @@
|
||||||
#include "core/hle/service/service.h"
|
#include "core/hle/service/service.h"
|
||||||
#include "core/hle/service/sm/sm.h"
|
#include "core/hle/service/sm/sm.h"
|
||||||
#include "core/loader/loader.h"
|
#include "core/loader/loader.h"
|
||||||
|
#include "core/memory.h"
|
||||||
#include "core/memory/cheat_engine.h"
|
#include "core/memory/cheat_engine.h"
|
||||||
#include "core/perf_stats.h"
|
#include "core/perf_stats.h"
|
||||||
#include "core/reporter.h"
|
#include "core/reporter.h"
|
||||||
|
@ -112,8 +113,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
|
||||||
}
|
}
|
||||||
struct System::Impl {
|
struct System::Impl {
|
||||||
explicit Impl(System& system)
|
explicit Impl(System& system)
|
||||||
: kernel{system}, fs_controller{system}, cpu_core_manager{system}, reporter{system},
|
: kernel{system}, fs_controller{system}, memory{system},
|
||||||
applet_manager{system} {}
|
cpu_core_manager{system}, reporter{system}, applet_manager{system} {}
|
||||||
|
|
||||||
Cpu& CurrentCpuCore() {
|
Cpu& CurrentCpuCore() {
|
||||||
return cpu_core_manager.GetCurrentCore();
|
return cpu_core_manager.GetCurrentCore();
|
||||||
|
@ -341,7 +342,8 @@ struct System::Impl {
|
||||||
std::unique_ptr<VideoCore::RendererBase> renderer;
|
std::unique_ptr<VideoCore::RendererBase> renderer;
|
||||||
std::unique_ptr<Tegra::GPU> gpu_core;
|
std::unique_ptr<Tegra::GPU> gpu_core;
|
||||||
std::shared_ptr<Tegra::DebugContext> debug_context;
|
std::shared_ptr<Tegra::DebugContext> debug_context;
|
||||||
std::unique_ptr<Core::Hardware::InterruptManager> interrupt_manager;
|
std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
|
||||||
|
Memory::Memory memory;
|
||||||
CpuCoreManager cpu_core_manager;
|
CpuCoreManager cpu_core_manager;
|
||||||
bool is_powered_on = false;
|
bool is_powered_on = false;
|
||||||
bool exit_lock = false;
|
bool exit_lock = false;
|
||||||
|
@ -498,6 +500,14 @@ const ExclusiveMonitor& System::Monitor() const {
|
||||||
return impl->cpu_core_manager.GetExclusiveMonitor();
|
return impl->cpu_core_manager.GetExclusiveMonitor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Memory::Memory& System::Memory() {
|
||||||
|
return impl->memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Memory::Memory& System::Memory() const {
|
||||||
|
return impl->memory;
|
||||||
|
}
|
||||||
|
|
||||||
Tegra::GPU& System::GPU() {
|
Tegra::GPU& System::GPU() {
|
||||||
return *impl->gpu_core;
|
return *impl->gpu_core;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,10 @@ namespace Core::Hardware {
|
||||||
class InterruptManager;
|
class InterruptManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace Memory {
|
||||||
|
class Memory;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
|
|
||||||
class ARM_Interface;
|
class ARM_Interface;
|
||||||
|
@ -225,6 +229,12 @@ public:
|
||||||
/// Gets a constant reference to the exclusive monitor
|
/// Gets a constant reference to the exclusive monitor
|
||||||
const ExclusiveMonitor& Monitor() const;
|
const ExclusiveMonitor& Monitor() const;
|
||||||
|
|
||||||
|
/// Gets a mutable reference to the system memory instance.
|
||||||
|
Memory::Memory& Memory();
|
||||||
|
|
||||||
|
/// Gets a constant reference to the system memory instance.
|
||||||
|
const Memory::Memory& Memory() const;
|
||||||
|
|
||||||
/// Gets a mutable reference to the GPU interface
|
/// Gets a mutable reference to the GPU interface
|
||||||
Tegra::GPU& GPU();
|
Tegra::GPU& GPU();
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,18 @@ namespace Memory {
|
||||||
|
|
||||||
static Common::PageTable* current_page_table = nullptr;
|
static Common::PageTable* current_page_table = nullptr;
|
||||||
|
|
||||||
|
// Implementation class used to keep the specifics of the memory subsystem hidden
|
||||||
|
// from outside classes. This also allows modification to the internals of the memory
|
||||||
|
// subsystem without needing to rebuild all files that make use of the memory interface.
|
||||||
|
struct Memory::Impl {
|
||||||
|
explicit Impl(Core::System& system_) : system{system_} {}
|
||||||
|
|
||||||
|
Core::System& system;
|
||||||
|
};
|
||||||
|
|
||||||
|
Memory::Memory(Core::System& system) : impl{std::make_unique<Impl>(system)} {}
|
||||||
|
Memory::~Memory() = default;
|
||||||
|
|
||||||
void SetCurrentPageTable(Kernel::Process& process) {
|
void SetCurrentPageTable(Kernel::Process& process) {
|
||||||
current_page_table = &process.VMManager().page_table;
|
current_page_table = &process.VMManager().page_table;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
namespace Core {
|
||||||
|
class System;
|
||||||
|
}
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
class Process;
|
class Process;
|
||||||
}
|
}
|
||||||
|
@ -36,6 +40,23 @@ enum : VAddr {
|
||||||
KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE,
|
KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Central class that handles all memory operations and state.
|
||||||
|
class Memory {
|
||||||
|
public:
|
||||||
|
explicit Memory(Core::System& system);
|
||||||
|
~Memory();
|
||||||
|
|
||||||
|
Memory(const Memory&) = delete;
|
||||||
|
Memory& operator=(const Memory&) = delete;
|
||||||
|
|
||||||
|
Memory(Memory&&) = default;
|
||||||
|
Memory& operator=(Memory&&) = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Impl;
|
||||||
|
std::unique_ptr<Impl> impl;
|
||||||
|
};
|
||||||
|
|
||||||
/// Changes the currently active page table to that of
|
/// Changes the currently active page table to that of
|
||||||
/// the given process instance.
|
/// the given process instance.
|
||||||
void SetCurrentPageTable(Kernel::Process& process);
|
void SetCurrentPageTable(Kernel::Process& process);
|
||||||
|
|
Loading…
Reference in a new issue