diff options
| author | 2021-04-02 17:06:21 -0700 | |
|---|---|---|
| committer | 2021-05-05 16:40:50 -0700 | |
| commit | 340167676828bf4595bc267c927f156a11b288aa (patch) | |
| tree | a8af50757dcea3878ae928d491f4108d392e29aa /src/core/memory.cpp | |
| parent | common: common_funcs: Add Size helper function. (diff) | |
| download | yuzu-340167676828bf4595bc267c927f156a11b288aa.tar.gz yuzu-340167676828bf4595bc267c927f156a11b288aa.tar.xz yuzu-340167676828bf4595bc267c927f156a11b288aa.zip | |
core: memory: Add a work-around to allocate and access kernel memory regions by vaddr.
Diffstat (limited to 'src/core/memory.cpp')
| -rw-r--r-- | src/core/memory.cpp | 30 |
1 files changed, 29 insertions, 1 deletions
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 | } |