summaryrefslogtreecommitdiff
path: root/src/core/device_memory.cpp
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/core/device_memory.cpp
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/core/device_memory.cpp')
-rw-r--r--src/core/device_memory.cpp50
1 files changed, 50 insertions, 0 deletions
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