summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2020-04-02 22:00:41 -0400
committerGravatar bunnei2020-04-17 00:59:29 -0400
commitdc25c86556c36dd23224d88234afc9ecbf780719 (patch)
tree5dbe45bcc17ecad8675e7a4cb03dd34361f01e03 /src
parentdynarmic: Enable strict alignment checks. (diff)
downloadyuzu-dc25c86556c36dd23224d88234afc9ecbf780719.tar.gz
yuzu-dc25c86556c36dd23224d88234afc9ecbf780719.tar.xz
yuzu-dc25c86556c36dd23224d88234afc9ecbf780719.zip
core: device_manager: Add a simple class to manage device RAM.
Diffstat (limited to 'src')
-rw-r--r--src/core/CMakeLists.txt2
-rw-r--r--src/core/core.cpp12
-rw-r--r--src/core/core.h7
-rw-r--r--src/core/device_memory.cpp50
-rw-r--r--src/core/device_memory.h48
5 files changed, 118 insertions, 1 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 1ea243283..26e1636ee 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -35,6 +35,8 @@ add_library(core STATIC
35 crypto/ctr_encryption_layer.h 35 crypto/ctr_encryption_layer.h
36 crypto/xts_encryption_layer.cpp 36 crypto/xts_encryption_layer.cpp
37 crypto/xts_encryption_layer.h 37 crypto/xts_encryption_layer.h
38 device_memory.cpp
39 device_memory.h
38 file_sys/bis_factory.cpp 40 file_sys/bis_factory.cpp
39 file_sys/bis_factory.h 41 file_sys/bis_factory.h
40 file_sys/card_image.cpp 42 file_sys/card_image.cpp
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 87b147f63..4bc71c7a7 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -14,6 +14,7 @@
14#include "core/core_manager.h" 14#include "core/core_manager.h"
15#include "core/core_timing.h" 15#include "core/core_timing.h"
16#include "core/cpu_manager.h" 16#include "core/cpu_manager.h"
17#include "core/device_memory.h"
17#include "core/file_sys/bis_factory.h" 18#include "core/file_sys/bis_factory.h"
18#include "core/file_sys/card_image.h" 19#include "core/file_sys/card_image.h"
19#include "core/file_sys/mode.h" 20#include "core/file_sys/mode.h"
@@ -113,7 +114,7 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
113} 114}
114struct System::Impl { 115struct System::Impl {
115 explicit Impl(System& system) 116 explicit Impl(System& system)
116 : kernel{system}, fs_controller{system}, memory{system}, 117 : kernel{system}, device_memory{system}, fs_controller{system}, memory{system},
117 cpu_manager{system}, reporter{system}, applet_manager{system} {} 118 cpu_manager{system}, reporter{system}, applet_manager{system} {}
118 119
119 CoreManager& CurrentCoreManager() { 120 CoreManager& CurrentCoreManager() {
@@ -337,6 +338,7 @@ struct System::Impl {
337 338
338 Timing::CoreTiming core_timing; 339 Timing::CoreTiming core_timing;
339 Kernel::KernelCore kernel; 340 Kernel::KernelCore kernel;
341 DeviceMemory device_memory;
340 /// RealVfsFilesystem instance 342 /// RealVfsFilesystem instance
341 FileSys::VirtualFilesystem virtual_filesystem; 343 FileSys::VirtualFilesystem virtual_filesystem;
342 /// ContentProviderUnion instance 344 /// ContentProviderUnion instance
@@ -472,6 +474,14 @@ Kernel::Process* System::CurrentProcess() {
472 return impl->kernel.CurrentProcess(); 474 return impl->kernel.CurrentProcess();
473} 475}
474 476
477DeviceMemory& System::GetDeviceMemory() {
478 return impl->device_memory;
479}
480
481const DeviceMemory& System::GetDeviceMemory() const {
482 return impl->device_memory;
483}
484
475const Kernel::Process* System::CurrentProcess() const { 485const Kernel::Process* System::CurrentProcess() const {
476 return impl->kernel.CurrentProcess(); 486 return impl->kernel.CurrentProcess();
477} 487}
diff --git a/src/core/core.h b/src/core/core.h
index c2bdef07e..6cd93000a 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -91,6 +91,7 @@ namespace Core {
91 91
92class ARM_Interface; 92class ARM_Interface;
93class CoreManager; 93class CoreManager;
94class DeviceMemory;
94class ExclusiveMonitor; 95class ExclusiveMonitor;
95class FrameLimiter; 96class FrameLimiter;
96class PerfStats; 97class PerfStats;
@@ -256,6 +257,12 @@ public:
256 /// Gets the global scheduler 257 /// Gets the global scheduler
257 const Kernel::GlobalScheduler& GlobalScheduler() const; 258 const Kernel::GlobalScheduler& GlobalScheduler() const;
258 259
260 /// Gets the manager for the guest device memory
261 DeviceMemory& GetDeviceMemory();
262
263 /// Gets the manager for the guest device memory
264 const DeviceMemory& GetDeviceMemory() const;
265
259 /// Provides a pointer to the current process 266 /// Provides a pointer to the current process
260 Kernel::Process* CurrentProcess(); 267 Kernel::Process* CurrentProcess();
261 268
diff --git a/src/core/device_memory.cpp b/src/core/device_memory.cpp
new file mode 100644
index 000000000..1e4187546
--- /dev/null
+++ b/src/core/device_memory.cpp
@@ -0,0 +1,50 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#ifdef _WIN32
6#include <windows.h>
7#endif
8
9#include "common/assert.h"
10#include "core/core.h"
11#include "core/device_memory.h"
12#include "core/memory.h"
13
14namespace Core {
15
16constexpr u64 DramSize{4ULL * 1024 * 1024 * 1024};
17
18DeviceMemory::DeviceMemory(System& system) : system{system} {
19#ifdef _WIN32
20 base = static_cast<u8*>(
21 VirtualAlloc(nullptr, // System selects address
22 DramSize, // Size of allocation
23 MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, // Allocate reserved pages
24 PAGE_READWRITE)); // Protection = no access
25#else
26 physical_memory.resize(DramSize);
27 base = physical_memory.data();
28#endif
29}
30
31DeviceMemory::~DeviceMemory() {
32#ifdef _WIN32
33 ASSERT(VirtualFree(base, DramSize, MEM_RELEASE));
34#endif
35}
36
37PAddr DeviceMemory::GetPhysicalAddr(VAddr addr) {
38 u8* pointer{system.Memory().GetPointer(addr)};
39 ASSERT(pointer);
40 const uintptr_t offset{static_cast<uintptr_t>(pointer - GetPointer(DramMemoryMap::Base))};
41 return DramMemoryMap::Base + offset;
42}
43
44u8* DeviceMemory::GetPointer(PAddr addr) {
45 ASSERT(addr >= DramMemoryMap::Base);
46 ASSERT(addr < DramMemoryMap::Base + DramSize);
47 return base + (addr - DramMemoryMap::Base);
48}
49
50} // namespace Core
diff --git a/src/core/device_memory.h b/src/core/device_memory.h
new file mode 100644
index 000000000..a60a7238a
--- /dev/null
+++ b/src/core/device_memory.h
@@ -0,0 +1,48 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/assert.h"
8#include "common/common_funcs.h"
9#include "core/hle/kernel/physical_memory.h"
10
11namespace Core {
12
13class System;
14
15namespace DramMemoryMap {
16constexpr u64 Base = 0x80000000ULL;
17constexpr u64 Size = 0x100000000ULL;
18constexpr u64 End = Base + Size;
19constexpr u64 KernelReserveBase = Base + 0x60000;
20constexpr u64 SlabHeapBase = KernelReserveBase + 0x85000;
21constexpr u64 SlapHeapSize = 0xa21000;
22constexpr u64 SlabHeapEnd = SlabHeapBase + SlapHeapSize;
23}; // namespace DramMemoryMap
24
25class DeviceMemory : NonCopyable {
26public:
27 DeviceMemory(Core::System& system);
28 ~DeviceMemory();
29
30 template <typename T>
31 PAddr GetPhysicalAddr(T* ptr) {
32 const auto ptr_addr{reinterpret_cast<uintptr_t>(ptr)};
33 const auto base_addr{reinterpret_cast<uintptr_t>(base)};
34 ASSERT(ptr_addr >= base_addr);
35 return ptr_addr - base_addr + DramMemoryMap::Base;
36 }
37
38 PAddr GetPhysicalAddr(VAddr addr);
39
40 u8* GetPointer(PAddr addr);
41
42private:
43 u8* base{};
44 Kernel::PhysicalMemory physical_memory;
45 Core::System& system;
46};
47
48} // namespace Core