diff options
| author | 2017-07-21 22:22:59 -0500 | |
|---|---|---|
| committer | 2017-09-15 14:26:13 -0500 | |
| commit | 214150f00c77474927cbdfb1598dbdb2cb4fcf32 (patch) | |
| tree | 4e86b987f4503953ab3b6389e176bd63f7cdd672 /src/core/memory.cpp | |
| parent | Kernel/Memory: Switch the current page table when a new process is scheduled. (diff) | |
| download | yuzu-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/core/memory.cpp')
| -rw-r--r-- | src/core/memory.cpp | 65 |
1 files changed, 62 insertions, 3 deletions
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 | ||
| 17 | namespace Memory { | 19 | namespace Memory { |
| 18 | 20 | ||
| 21 | static std::array<u8, Memory::VRAM_SIZE> vram; | ||
| 22 | static std::array<u8, Memory::N3DS_EXTRA_RAM_SIZE> n3ds_extra_ram; | ||
| 23 | |||
| 19 | PageTable* current_page_table = nullptr; | 24 | PageTable* current_page_table = nullptr; |
| 20 | 25 | ||
| 21 | std::array<u8*, PAGE_TABLE_NUM_ENTRIES>* GetCurrentPageTablePointers() { | 26 | std::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 | ||
| 238 | u8* GetPhysicalPointer(PAddr address) { | 243 | u8* 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 | ||
| 244 | void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { | 303 | void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { |