diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/core.cpp | 1 | ||||
| -rw-r--r-- | src/core/memory.cpp | 30 | ||||
| -rw-r--r-- | src/core/memory.h | 16 |
3 files changed, 46 insertions, 1 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index d459d6c34..66500a0d4 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -311,6 +311,7 @@ struct System::Impl { | |||
| 311 | gpu_core.reset(); | 311 | gpu_core.reset(); |
| 312 | perf_stats.reset(); | 312 | perf_stats.reset(); |
| 313 | kernel.Shutdown(); | 313 | kernel.Shutdown(); |
| 314 | memory.Reset(); | ||
| 314 | applet_manager.ClearAll(); | 315 | applet_manager.ClearAll(); |
| 315 | 316 | ||
| 316 | LOG_DEBUG(Core, "Shutdown OK"); | 317 | LOG_DEBUG(Core, "Shutdown OK"); |
diff --git a/src/core/memory.cpp b/src/core/memory.cpp index b9dd3e275..ee4599063 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp | |||
| @@ -82,6 +82,22 @@ struct Memory::Impl { | |||
| 82 | return nullptr; | 82 | return nullptr; |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | u8* GetKernelBuffer(VAddr start_vaddr, size_t size) { | ||
| 86 | // TODO(bunnei): This is just a workaround until we have kernel memory layout mapped & | ||
| 87 | // managed. Until then, we use this to allocate and access kernel memory regions. | ||
| 88 | |||
| 89 | auto search = kernel_memory_regions.find(start_vaddr); | ||
| 90 | if (search != kernel_memory_regions.end()) { | ||
| 91 | return search->second.get(); | ||
| 92 | } | ||
| 93 | |||
| 94 | std::unique_ptr<u8[]> new_memory_region{new u8[size]}; | ||
| 95 | u8* raw_ptr = new_memory_region.get(); | ||
| 96 | kernel_memory_regions[start_vaddr] = std::move(new_memory_region); | ||
| 97 | |||
| 98 | return raw_ptr; | ||
| 99 | } | ||
| 100 | |||
| 85 | u8 Read8(const VAddr addr) { | 101 | u8 Read8(const VAddr addr) { |
| 86 | return Read<u8>(addr); | 102 | return Read<u8>(addr); |
| 87 | } | 103 | } |
| @@ -711,12 +727,20 @@ struct Memory::Impl { | |||
| 711 | } | 727 | } |
| 712 | 728 | ||
| 713 | Common::PageTable* current_page_table = nullptr; | 729 | Common::PageTable* current_page_table = nullptr; |
| 730 | std::unordered_map<VAddr, std::unique_ptr<u8[]>> kernel_memory_regions; | ||
| 714 | Core::System& system; | 731 | Core::System& system; |
| 715 | }; | 732 | }; |
| 716 | 733 | ||
| 717 | Memory::Memory(Core::System& system) : impl{std::make_unique<Impl>(system)} {} | 734 | Memory::Memory(Core::System& system_) : system{system_} { |
| 735 | Reset(); | ||
| 736 | } | ||
| 737 | |||
| 718 | Memory::~Memory() = default; | 738 | Memory::~Memory() = default; |
| 719 | 739 | ||
| 740 | void Memory::Reset() { | ||
| 741 | impl = std::make_unique<Impl>(system); | ||
| 742 | } | ||
| 743 | |||
| 720 | void Memory::SetCurrentPageTable(Kernel::Process& process, u32 core_id) { | 744 | void Memory::SetCurrentPageTable(Kernel::Process& process, u32 core_id) { |
| 721 | impl->SetCurrentPageTable(process, core_id); | 745 | impl->SetCurrentPageTable(process, core_id); |
| 722 | } | 746 | } |
| @@ -741,6 +765,10 @@ u8* Memory::GetPointer(VAddr vaddr) { | |||
| 741 | return impl->GetPointer(vaddr); | 765 | return impl->GetPointer(vaddr); |
| 742 | } | 766 | } |
| 743 | 767 | ||
| 768 | u8* Memory::GetKernelBuffer(VAddr start_vaddr, size_t size) { | ||
| 769 | return impl->GetKernelBuffer(start_vaddr, size); | ||
| 770 | } | ||
| 771 | |||
| 744 | const u8* Memory::GetPointer(VAddr vaddr) const { | 772 | const u8* Memory::GetPointer(VAddr vaddr) const { |
| 745 | return impl->GetPointer(vaddr); | 773 | return impl->GetPointer(vaddr); |
| 746 | } | 774 | } |
diff --git a/src/core/memory.h b/src/core/memory.h index 6d34fcfe2..9a706a9ac 100644 --- a/src/core/memory.h +++ b/src/core/memory.h | |||
| @@ -59,6 +59,11 @@ public: | |||
| 59 | Memory& operator=(Memory&&) = default; | 59 | Memory& operator=(Memory&&) = default; |
| 60 | 60 | ||
| 61 | /** | 61 | /** |
| 62 | * Resets the state of the Memory system. | ||
| 63 | */ | ||
| 64 | void Reset(); | ||
| 65 | |||
| 66 | /** | ||
| 62 | * Changes the currently active page table to that of the given process instance. | 67 | * Changes the currently active page table to that of the given process instance. |
| 63 | * | 68 | * |
| 64 | * @param process The process to use the page table of. | 69 | * @param process The process to use the page table of. |
| @@ -116,6 +121,15 @@ public: | |||
| 116 | */ | 121 | */ |
| 117 | u8* GetPointer(VAddr vaddr); | 122 | u8* GetPointer(VAddr vaddr); |
| 118 | 123 | ||
| 124 | /** | ||
| 125 | * Gets a pointer to the start of a kernel heap allocated memory region. Will allocate one if it | ||
| 126 | * does not already exist. | ||
| 127 | * | ||
| 128 | * @param start_vaddr Start virtual address for the memory region. | ||
| 129 | * @param size Size of the memory region. | ||
| 130 | */ | ||
| 131 | u8* GetKernelBuffer(VAddr start_vaddr, size_t size); | ||
| 132 | |||
| 119 | template <typename T> | 133 | template <typename T> |
| 120 | T* GetPointer(VAddr vaddr) { | 134 | T* GetPointer(VAddr vaddr) { |
| 121 | return reinterpret_cast<T*>(GetPointer(vaddr)); | 135 | return reinterpret_cast<T*>(GetPointer(vaddr)); |
| @@ -524,6 +538,8 @@ public: | |||
| 524 | void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached); | 538 | void RasterizerMarkRegionCached(VAddr vaddr, u64 size, bool cached); |
| 525 | 539 | ||
| 526 | private: | 540 | private: |
| 541 | Core::System& system; | ||
| 542 | |||
| 527 | struct Impl; | 543 | struct Impl; |
| 528 | std::unique_ptr<Impl> impl; | 544 | std::unique_ptr<Impl> impl; |
| 529 | }; | 545 | }; |