summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Lioncash2019-11-26 12:33:20 -0500
committerGravatar Lioncash2019-11-26 21:53:34 -0500
commit4c2ed2706e3579ec1304907dad0d45673768e1fc (patch)
tree89f72c13ad6ab374a4e2d2d475b1e03320de7066 /src/core
parentMerge pull request #3143 from ReinUsesLisp/indexing-bug (diff)
downloadyuzu-4c2ed2706e3579ec1304907dad0d45673768e1fc.tar.gz
yuzu-4c2ed2706e3579ec1304907dad0d45673768e1fc.tar.xz
yuzu-4c2ed2706e3579ec1304907dad0d45673768e1fc.zip
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.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.cpp16
-rw-r--r--src/core/core.h10
-rw-r--r--src/core/memory.cpp12
-rw-r--r--src/core/memory.h21
4 files changed, 56 insertions, 3 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index eba17218a..c45fb960c 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -39,6 +39,7 @@
39#include "core/hle/service/service.h" 39#include "core/hle/service/service.h"
40#include "core/hle/service/sm/sm.h" 40#include "core/hle/service/sm/sm.h"
41#include "core/loader/loader.h" 41#include "core/loader/loader.h"
42#include "core/memory.h"
42#include "core/memory/cheat_engine.h" 43#include "core/memory/cheat_engine.h"
43#include "core/perf_stats.h" 44#include "core/perf_stats.h"
44#include "core/reporter.h" 45#include "core/reporter.h"
@@ -112,8 +113,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
112} 113}
113struct System::Impl { 114struct System::Impl {
114 explicit Impl(System& system) 115 explicit Impl(System& system)
115 : kernel{system}, fs_controller{system}, cpu_core_manager{system}, reporter{system}, 116 : kernel{system}, fs_controller{system}, memory{system},
116 applet_manager{system} {} 117 cpu_core_manager{system}, reporter{system}, applet_manager{system} {}
117 118
118 Cpu& CurrentCpuCore() { 119 Cpu& CurrentCpuCore() {
119 return cpu_core_manager.GetCurrentCore(); 120 return cpu_core_manager.GetCurrentCore();
@@ -341,7 +342,8 @@ struct System::Impl {
341 std::unique_ptr<VideoCore::RendererBase> renderer; 342 std::unique_ptr<VideoCore::RendererBase> renderer;
342 std::unique_ptr<Tegra::GPU> gpu_core; 343 std::unique_ptr<Tegra::GPU> gpu_core;
343 std::shared_ptr<Tegra::DebugContext> debug_context; 344 std::shared_ptr<Tegra::DebugContext> debug_context;
344 std::unique_ptr<Core::Hardware::InterruptManager> interrupt_manager; 345 std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
346 Memory::Memory memory;
345 CpuCoreManager cpu_core_manager; 347 CpuCoreManager cpu_core_manager;
346 bool is_powered_on = false; 348 bool is_powered_on = false;
347 bool exit_lock = false; 349 bool exit_lock = false;
@@ -498,6 +500,14 @@ const ExclusiveMonitor& System::Monitor() const {
498 return impl->cpu_core_manager.GetExclusiveMonitor(); 500 return impl->cpu_core_manager.GetExclusiveMonitor();
499} 501}
500 502
503Memory::Memory& System::Memory() {
504 return impl->memory;
505}
506
507const Memory::Memory& System::Memory() const {
508 return impl->memory;
509}
510
501Tegra::GPU& System::GPU() { 511Tegra::GPU& System::GPU() {
502 return *impl->gpu_core; 512 return *impl->gpu_core;
503} 513}
diff --git a/src/core/core.h b/src/core/core.h
index f9b1a2866..91184e433 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -86,6 +86,10 @@ namespace Core::Hardware {
86class InterruptManager; 86class InterruptManager;
87} 87}
88 88
89namespace Memory {
90class Memory;
91}
92
89namespace Core { 93namespace Core {
90 94
91class ARM_Interface; 95class ARM_Interface;
@@ -225,6 +229,12 @@ public:
225 /// Gets a constant reference to the exclusive monitor 229 /// Gets a constant reference to the exclusive monitor
226 const ExclusiveMonitor& Monitor() const; 230 const ExclusiveMonitor& Monitor() const;
227 231
232 /// Gets a mutable reference to the system memory instance.
233 Memory::Memory& Memory();
234
235 /// Gets a constant reference to the system memory instance.
236 const Memory::Memory& Memory() const;
237
228 /// Gets a mutable reference to the GPU interface 238 /// Gets a mutable reference to the GPU interface
229 Tegra::GPU& GPU(); 239 Tegra::GPU& GPU();
230 240
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index fa49f3dd0..2098f13f7 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -24,6 +24,18 @@ namespace Memory {
24 24
25static Common::PageTable* current_page_table = nullptr; 25static Common::PageTable* current_page_table = nullptr;
26 26
27// Implementation class used to keep the specifics of the memory subsystem hidden
28// from outside classes. This also allows modification to the internals of the memory
29// subsystem without needing to rebuild all files that make use of the memory interface.
30struct Memory::Impl {
31 explicit Impl(Core::System& system_) : system{system_} {}
32
33 Core::System& system;
34};
35
36Memory::Memory(Core::System& system) : impl{std::make_unique<Impl>(system)} {}
37Memory::~Memory() = default;
38
27void SetCurrentPageTable(Kernel::Process& process) { 39void SetCurrentPageTable(Kernel::Process& process) {
28 current_page_table = &process.VMManager().page_table; 40 current_page_table = &process.VMManager().page_table;
29 41
diff --git a/src/core/memory.h b/src/core/memory.h
index 09008e1dd..c690df3c3 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -8,6 +8,10 @@
8#include <string> 8#include <string>
9#include "common/common_types.h" 9#include "common/common_types.h"
10 10
11namespace Core {
12class System;
13}
14
11namespace Kernel { 15namespace Kernel {
12class Process; 16class Process;
13} 17}
@@ -36,6 +40,23 @@ enum : VAddr {
36 KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE, 40 KERNEL_REGION_END = KERNEL_REGION_VADDR + KERNEL_REGION_SIZE,
37}; 41};
38 42
43/// Central class that handles all memory operations and state.
44class Memory {
45public:
46 explicit Memory(Core::System& system);
47 ~Memory();
48
49 Memory(const Memory&) = delete;
50 Memory& operator=(const Memory&) = delete;
51
52 Memory(Memory&&) = default;
53 Memory& operator=(Memory&&) = default;
54
55private:
56 struct Impl;
57 std::unique_ptr<Impl> impl;
58};
59
39/// Changes the currently active page table to that of 60/// Changes the currently active page table to that of
40/// the given process instance. 61/// the given process instance.
41void SetCurrentPageTable(Kernel::Process& process); 62void SetCurrentPageTable(Kernel::Process& process);