summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2017-07-21 22:22:59 -0500
committerGravatar Subv2017-09-15 14:26:13 -0500
commit214150f00c77474927cbdfb1598dbdb2cb4fcf32 (patch)
tree4e86b987f4503953ab3b6389e176bd63f7cdd672 /src
parentKernel/Memory: Switch the current page table when a new process is scheduled. (diff)
downloadyuzu-214150f00c77474927cbdfb1598dbdb2cb4fcf32.tar.gz
yuzu-214150f00c77474927cbdfb1598dbdb2cb4fcf32.tar.xz
yuzu-214150f00c77474927cbdfb1598dbdb2cb4fcf32.zip
Kernel/Memory: Changed GetPhysicalPointer so that it doesn't go through the current process' page table to obtain a pointer.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/memory.cpp30
-rw-r--r--src/core/hle/kernel/memory.h2
-rw-r--r--src/core/memory.cpp65
-rw-r--r--src/core/memory.h2
4 files changed, 69 insertions, 30 deletions
diff --git a/src/core/hle/kernel/memory.cpp b/src/core/hle/kernel/memory.cpp
index 496d07cb5..7f27e9655 100644
--- a/src/core/hle/kernel/memory.cpp
+++ b/src/core/hle/kernel/memory.cpp
@@ -8,7 +8,6 @@
8#include <memory> 8#include <memory>
9#include <utility> 9#include <utility>
10#include <vector> 10#include <vector>
11#include "audio_core/audio_core.h"
12#include "common/assert.h" 11#include "common/assert.h"
13#include "common/common_types.h" 12#include "common/common_types.h"
14#include "common/logging/log.h" 13#include "common/logging/log.h"
@@ -24,7 +23,7 @@
24 23
25namespace Kernel { 24namespace Kernel {
26 25
27static MemoryRegionInfo memory_regions[3]; 26MemoryRegionInfo memory_regions[3];
28 27
29/// Size of the APPLICATION, SYSTEM and BASE memory regions (respectively) for each system 28/// Size of the APPLICATION, SYSTEM and BASE memory regions (respectively) for each system
30/// memory configuration type. 29/// memory configuration type.
@@ -96,9 +95,6 @@ MemoryRegionInfo* GetMemoryRegion(MemoryRegion region) {
96 } 95 }
97} 96}
98 97
99std::array<u8, Memory::VRAM_SIZE> vram;
100std::array<u8, Memory::N3DS_EXTRA_RAM_SIZE> n3ds_extra_ram;
101
102void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping) { 98void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping) {
103 using namespace Memory; 99 using namespace Memory;
104 100
@@ -143,30 +139,14 @@ void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mappin
143 return; 139 return;
144 } 140 }
145 141
146 // TODO(yuriks): Use GetPhysicalPointer when that becomes independent of the virtual 142 u8* target_pointer = Memory::GetPhysicalPointer(area->paddr_base + offset_into_region);
147 // mappings.
148 u8* target_pointer = nullptr;
149 switch (area->paddr_base) {
150 case VRAM_PADDR:
151 target_pointer = vram.data();
152 break;
153 case DSP_RAM_PADDR:
154 target_pointer = AudioCore::GetDspMemory().data();
155 break;
156 case N3DS_EXTRA_RAM_PADDR:
157 target_pointer = n3ds_extra_ram.data();
158 break;
159 default:
160 UNREACHABLE();
161 }
162 143
163 // TODO(yuriks): This flag seems to have some other effect, but it's unknown what 144 // TODO(yuriks): This flag seems to have some other effect, but it's unknown what
164 MemoryState memory_state = mapping.unk_flag ? MemoryState::Static : MemoryState::IO; 145 MemoryState memory_state = mapping.unk_flag ? MemoryState::Static : MemoryState::IO;
165 146
166 auto vma = address_space 147 auto vma =
167 .MapBackingMemory(mapping.address, target_pointer + offset_into_region, 148 address_space.MapBackingMemory(mapping.address, target_pointer, mapping.size, memory_state)
168 mapping.size, memory_state) 149 .Unwrap();
169 .Unwrap();
170 address_space.Reprotect(vma, 150 address_space.Reprotect(vma,
171 mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite); 151 mapping.read_only ? VMAPermission::Read : VMAPermission::ReadWrite);
172} 152}
diff --git a/src/core/hle/kernel/memory.h b/src/core/hle/kernel/memory.h
index 08c1a9989..da6bb3563 100644
--- a/src/core/hle/kernel/memory.h
+++ b/src/core/hle/kernel/memory.h
@@ -26,4 +26,6 @@ MemoryRegionInfo* GetMemoryRegion(MemoryRegion region);
26 26
27void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping); 27void HandleSpecialMapping(VMManager& address_space, const AddressMapping& mapping);
28void MapSharedPages(VMManager& address_space); 28void MapSharedPages(VMManager& address_space);
29
30extern MemoryRegionInfo memory_regions[3];
29} // namespace Kernel 31} // namespace Kernel
diff --git a/src/core/memory.cpp b/src/core/memory.cpp
index ea46b6ead..4dcbf2274 100644
--- a/src/core/memory.cpp
+++ b/src/core/memory.cpp
@@ -4,10 +4,12 @@
4 4
5#include <array> 5#include <array>
6#include <cstring> 6#include <cstring>
7#include "audio_core/audio_core.h"
7#include "common/assert.h" 8#include "common/assert.h"
8#include "common/common_types.h" 9#include "common/common_types.h"
9#include "common/logging/log.h" 10#include "common/logging/log.h"
10#include "common/swap.h" 11#include "common/swap.h"
12#include "core/hle/kernel/memory.h"
11#include "core/hle/kernel/process.h" 13#include "core/hle/kernel/process.h"
12#include "core/memory.h" 14#include "core/memory.h"
13#include "core/memory_setup.h" 15#include "core/memory_setup.h"
@@ -16,6 +18,9 @@
16 18
17namespace Memory { 19namespace Memory {
18 20
21static std::array<u8, Memory::VRAM_SIZE> vram;
22static std::array<u8, Memory::N3DS_EXTRA_RAM_SIZE> n3ds_extra_ram;
23
19PageTable* current_page_table = nullptr; 24PageTable* current_page_table = nullptr;
20 25
21std::array<u8*, PAGE_TABLE_NUM_ENTRIES>* GetCurrentPageTablePointers() { 26std::array<u8*, PAGE_TABLE_NUM_ENTRIES>* GetCurrentPageTablePointers() {
@@ -236,9 +241,63 @@ std::string ReadCString(VAddr vaddr, std::size_t max_length) {
236} 241}
237 242
238u8* GetPhysicalPointer(PAddr address) { 243u8* GetPhysicalPointer(PAddr address) {
239 // TODO(Subv): This call should not go through the application's memory mapping. 244 struct MemoryArea {
240 boost::optional<VAddr> vaddr = PhysicalToVirtualAddress(address); 245 PAddr paddr_base;
241 return vaddr ? GetPointer(*vaddr) : nullptr; 246 u32 size;
247 };
248
249 static constexpr MemoryArea memory_areas[] = {
250 {VRAM_PADDR, VRAM_SIZE},
251 {IO_AREA_PADDR, IO_AREA_SIZE},
252 {DSP_RAM_PADDR, DSP_RAM_SIZE},
253 {FCRAM_PADDR, FCRAM_N3DS_SIZE},
254 {N3DS_EXTRA_RAM_PADDR, N3DS_EXTRA_RAM_SIZE},
255 };
256
257 const auto area =
258 std::find_if(std::begin(memory_areas), std::end(memory_areas), [&](const auto& area) {
259 return address >= area.paddr_base && address < area.paddr_base + area.size;
260 });
261
262 if (area == std::end(memory_areas)) {
263 LOG_ERROR(HW_Memory, "unknown GetPhysicalPointer @ 0x%08X", address);
264 return nullptr;
265 }
266
267 if (area->paddr_base == IO_AREA_PADDR) {
268 LOG_ERROR(HW_Memory, "MMIO mappings are not supported yet. phys_addr=0x%08X", address);
269 return nullptr;
270 }
271
272 u32 offset_into_region = address - area->paddr_base;
273
274 u8* target_pointer = nullptr;
275 switch (area->paddr_base) {
276 case VRAM_PADDR:
277 target_pointer = vram.data() + offset_into_region;
278 break;
279 case DSP_RAM_PADDR:
280 target_pointer = AudioCore::GetDspMemory().data() + offset_into_region;
281 break;
282 case FCRAM_PADDR:
283 for (const auto& region : Kernel::memory_regions) {
284 if (offset_into_region >= region.base &&
285 offset_into_region < region.base + region.size) {
286 target_pointer =
287 region.linear_heap_memory->data() + offset_into_region - region.base;
288 break;
289 }
290 }
291 ASSERT_MSG(target_pointer != nullptr, "Invalid FCRAM address");
292 break;
293 case N3DS_EXTRA_RAM_PADDR:
294 target_pointer = n3ds_extra_ram.data() + offset_into_region;
295 break;
296 default:
297 UNREACHABLE();
298 }
299
300 return target_pointer;
242} 301}
243 302
244void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { 303void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) {
diff --git a/src/core/memory.h b/src/core/memory.h
index 859a14202..b228a48c2 100644
--- a/src/core/memory.h
+++ b/src/core/memory.h
@@ -227,8 +227,6 @@ boost::optional<VAddr> PhysicalToVirtualAddress(PAddr addr);
227 227
228/** 228/**
229 * Gets a pointer to the memory region beginning at the specified physical address. 229 * Gets a pointer to the memory region beginning at the specified physical address.
230 *
231 * @note This is currently implemented using PhysicalToVirtualAddress().
232 */ 230 */
233u8* GetPhysicalPointer(PAddr address); 231u8* GetPhysicalPointer(PAddr address);
234 232