mirror of
https://github.com/PabloMK7/citra
synced 2024-11-15 05:08:23 +00:00
Memory: move memory setup into MemorySystem
This commit is contained in:
parent
e7a3c296c3
commit
643b7d4dcb
11 changed files with 46 additions and 56 deletions
|
@ -418,7 +418,6 @@ add_library(core STATIC
|
|||
loader/smdh.h
|
||||
memory.cpp
|
||||
memory.h
|
||||
memory_setup.h
|
||||
mmio.h
|
||||
movie.cpp
|
||||
movie.h
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "core/hle/service/sm/sm.h"
|
||||
#include "core/hw/hw.h"
|
||||
#include "core/loader/loader.h"
|
||||
#include "core/memory_setup.h"
|
||||
#include "core/movie.h"
|
||||
#ifdef ENABLE_SCRIPTING
|
||||
#include "core/rpc/rpc_server.h"
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "core/hle/kernel/vm_manager.h"
|
||||
#include "core/hle/result.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/memory_setup.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -402,7 +402,7 @@ ResultCode Process::Unmap(VAddr target, VAddr source, u32 size, VMAPermission pe
|
|||
}
|
||||
|
||||
Kernel::Process::Process(KernelSystem& kernel)
|
||||
: Object(kernel), handle_table(kernel), kernel(kernel) {}
|
||||
: Object(kernel), handle_table(kernel), kernel(kernel), vm_manager(kernel.memory) {}
|
||||
Kernel::Process::~Process() {}
|
||||
|
||||
SharedPtr<Process> KernelSystem::GetProcessById(u32 process_id) const {
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include "core/hle/kernel/errors.h"
|
||||
#include "core/hle/kernel/vm_manager.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/memory_setup.h"
|
||||
#include "core/mmio.h"
|
||||
|
||||
namespace Kernel {
|
||||
|
@ -37,7 +36,7 @@ bool VirtualMemoryArea::CanBeMergedWith(const VirtualMemoryArea& next) const {
|
|||
return true;
|
||||
}
|
||||
|
||||
VMManager::VMManager() {
|
||||
VMManager::VMManager(Memory::MemorySystem& memory) : memory(memory) {
|
||||
Reset();
|
||||
}
|
||||
|
||||
|
@ -351,13 +350,13 @@ VMManager::VMAIter VMManager::MergeAdjacent(VMAIter iter) {
|
|||
void VMManager::UpdatePageTableForVMA(const VirtualMemoryArea& vma) {
|
||||
switch (vma.type) {
|
||||
case VMAType::Free:
|
||||
Memory::UnmapRegion(page_table, vma.base, vma.size);
|
||||
memory.UnmapRegion(page_table, vma.base, vma.size);
|
||||
break;
|
||||
case VMAType::BackingMemory:
|
||||
Memory::MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory);
|
||||
memory.MapMemoryRegion(page_table, vma.base, vma.size, vma.backing_memory);
|
||||
break;
|
||||
case VMAType::MMIO:
|
||||
Memory::MapIoRegion(page_table, vma.base, vma.size, vma.mmio_handler);
|
||||
memory.MapIoRegion(page_table, vma.base, vma.size, vma.mmio_handler);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public:
|
|||
std::map<VAddr, VirtualMemoryArea> vma_map;
|
||||
using VMAHandle = decltype(vma_map)::const_iterator;
|
||||
|
||||
VMManager();
|
||||
explicit VMManager(Memory::MemorySystem& memory);
|
||||
~VMManager();
|
||||
|
||||
/// Clears the address space map, re-initializing with a single free area.
|
||||
|
@ -227,5 +227,7 @@ private:
|
|||
|
||||
/// Updates the pages corresponding to this VMA so they match the VMA's attributes.
|
||||
void UpdatePageTableForVMA(const VirtualMemoryArea& vma);
|
||||
|
||||
Memory::MemorySystem& memory;
|
||||
};
|
||||
} // namespace Kernel
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "core/hle/kernel/process.h"
|
||||
#include "core/hle/lock.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/memory_setup.h"
|
||||
#include "video_core/renderer_base.h"
|
||||
#include "video_core/video_core.h"
|
||||
|
||||
|
@ -87,7 +86,7 @@ PageTable* MemorySystem::GetCurrentPageTable() const {
|
|||
return impl->current_page_table;
|
||||
}
|
||||
|
||||
static void MapPages(PageTable& page_table, u32 base, u32 size, u8* memory, PageType type) {
|
||||
void MemorySystem::MapPages(PageTable& page_table, u32 base, u32 size, u8* memory, PageType type) {
|
||||
LOG_DEBUG(HW_Memory, "Mapping {} onto {:08X}-{:08X}", (void*)memory, base * PAGE_SIZE,
|
||||
(base + size) * PAGE_SIZE);
|
||||
|
||||
|
@ -107,13 +106,14 @@ static void MapPages(PageTable& page_table, u32 base, u32 size, u8* memory, Page
|
|||
}
|
||||
}
|
||||
|
||||
void MapMemoryRegion(PageTable& page_table, VAddr base, u32 size, u8* target) {
|
||||
void MemorySystem::MapMemoryRegion(PageTable& page_table, VAddr base, u32 size, u8* target) {
|
||||
ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:08X}", size);
|
||||
ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:08X}", base);
|
||||
MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, target, PageType::Memory);
|
||||
}
|
||||
|
||||
void MapIoRegion(PageTable& page_table, VAddr base, u32 size, MMIORegionPointer mmio_handler) {
|
||||
void MemorySystem::MapIoRegion(PageTable& page_table, VAddr base, u32 size,
|
||||
MMIORegionPointer mmio_handler) {
|
||||
ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:08X}", size);
|
||||
ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:08X}", base);
|
||||
MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Special);
|
||||
|
@ -121,7 +121,7 @@ void MapIoRegion(PageTable& page_table, VAddr base, u32 size, MMIORegionPointer
|
|||
page_table.special_regions.emplace_back(SpecialRegion{base, size, mmio_handler});
|
||||
}
|
||||
|
||||
void UnmapRegion(PageTable& page_table, VAddr base, u32 size) {
|
||||
void MemorySystem::UnmapRegion(PageTable& page_table, VAddr base, u32 size) {
|
||||
ASSERT_MSG((size & PAGE_MASK) == 0, "non-page aligned size: {:08X}", size);
|
||||
ASSERT_MSG((base & PAGE_MASK) == 0, "non-page aligned base: {:08X}", base);
|
||||
MapPages(page_table, base / PAGE_SIZE, size / PAGE_SIZE, nullptr, PageType::Unmapped);
|
||||
|
|
|
@ -214,6 +214,27 @@ public:
|
|||
MemorySystem();
|
||||
~MemorySystem();
|
||||
|
||||
/**
|
||||
* Maps an allocated buffer onto a region of the emulated process address space.
|
||||
*
|
||||
* @param page_table The page table of the emulated process.
|
||||
* @param base The address to start mapping at. Must be page-aligned.
|
||||
* @param size The amount of bytes to map. Must be page-aligned.
|
||||
* @param target Buffer with the memory backing the mapping. Must be of length at least `size`.
|
||||
*/
|
||||
void MapMemoryRegion(PageTable& page_table, VAddr base, u32 size, u8* target);
|
||||
|
||||
/**
|
||||
* Maps a region of the emulated process address space as a IO region.
|
||||
* @param page_table The page table of the emulated process.
|
||||
* @param base The address to start mapping at. Must be page-aligned.
|
||||
* @param size The amount of bytes to map. Must be page-aligned.
|
||||
* @param mmio_handler The handler that backs the mapping.
|
||||
*/
|
||||
void MapIoRegion(PageTable& page_table, VAddr base, u32 size, MMIORegionPointer mmio_handler);
|
||||
|
||||
void UnmapRegion(PageTable& page_table, VAddr base, u32 size);
|
||||
|
||||
/// Currently active page table
|
||||
void SetCurrentPageTable(PageTable* page_table);
|
||||
PageTable* GetCurrentPageTable() const;
|
||||
|
@ -275,6 +296,8 @@ private:
|
|||
*/
|
||||
u8* GetPointerForRasterizerCache(VAddr addr);
|
||||
|
||||
void MapPages(PageTable& page_table, u32 base, u32 size, u8* memory, PageType type);
|
||||
|
||||
class Impl;
|
||||
|
||||
std::unique_ptr<Impl> impl;
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright 2015 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_types.h"
|
||||
#include "core/mmio.h"
|
||||
|
||||
namespace Memory {
|
||||
|
||||
/**
|
||||
* Maps an allocated buffer onto a region of the emulated process address space.
|
||||
*
|
||||
* @param page_table The page table of the emulated process.
|
||||
* @param base The address to start mapping at. Must be page-aligned.
|
||||
* @param size The amount of bytes to map. Must be page-aligned.
|
||||
* @param target Buffer with the memory backing the mapping. Must be of length at least `size`.
|
||||
*/
|
||||
void MapMemoryRegion(PageTable& page_table, VAddr base, u32 size, u8* target);
|
||||
|
||||
/**
|
||||
* Maps a region of the emulated process address space as a IO region.
|
||||
* @param page_table The page table of the emulated process.
|
||||
* @param base The address to start mapping at. Must be page-aligned.
|
||||
* @param size The amount of bytes to map. Must be page-aligned.
|
||||
* @param mmio_handler The handler that backs the mapping.
|
||||
*/
|
||||
void MapIoRegion(PageTable& page_table, VAddr base, u32 size, MMIORegionPointer mmio_handler);
|
||||
|
||||
void UnmapRegion(PageTable& page_table, VAddr base, u32 size);
|
||||
} // namespace Memory
|
|
@ -6,7 +6,6 @@
|
|||
#include "core/core_timing.h"
|
||||
#include "core/hle/kernel/process.h"
|
||||
#include "core/memory.h"
|
||||
#include "core/memory_setup.h"
|
||||
#include "tests/core/arm/arm_test_common.h"
|
||||
|
||||
namespace ArmTests {
|
||||
|
@ -31,15 +30,16 @@ TestEnvironment::TestEnvironment(bool mutable_memory_)
|
|||
page_table->pointers.fill(nullptr);
|
||||
page_table->attributes.fill(Memory::PageType::Unmapped);
|
||||
|
||||
Memory::MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
|
||||
Memory::MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
|
||||
memory.MapIoRegion(*page_table, 0x00000000, 0x80000000, test_memory);
|
||||
memory.MapIoRegion(*page_table, 0x80000000, 0x80000000, test_memory);
|
||||
|
||||
memory.SetCurrentPageTable(page_table);
|
||||
}
|
||||
|
||||
TestEnvironment::~TestEnvironment() {
|
||||
Memory::UnmapRegion(*page_table, 0x80000000, 0x80000000);
|
||||
Memory::UnmapRegion(*page_table, 0x00000000, 0x80000000);
|
||||
Memory::MemorySystem& memory = *Core::System::GetInstance().memory;
|
||||
memory.UnmapRegion(*page_table, 0x80000000, 0x80000000);
|
||||
memory.UnmapRegion(*page_table, 0x00000000, 0x80000000);
|
||||
}
|
||||
|
||||
void TestEnvironment::SetMemory64(VAddr vaddr, u64 value) {
|
||||
|
|
|
@ -11,9 +11,10 @@
|
|||
|
||||
TEST_CASE("Memory Basics", "[kernel][memory]") {
|
||||
auto block = std::make_shared<std::vector<u8>>(Memory::PAGE_SIZE);
|
||||
Memory::MemorySystem memory;
|
||||
SECTION("mapping memory") {
|
||||
// Because of the PageTable, Kernel::VMManager is too big to be created on the stack.
|
||||
auto manager = std::make_unique<Kernel::VMManager>();
|
||||
auto manager = std::make_unique<Kernel::VMManager>(memory);
|
||||
auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block->data(), block->size(),
|
||||
Kernel::MemoryState::Private);
|
||||
REQUIRE(result.Code() == RESULT_SUCCESS);
|
||||
|
@ -28,7 +29,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") {
|
|||
|
||||
SECTION("unmapping memory") {
|
||||
// Because of the PageTable, Kernel::VMManager is too big to be created on the stack.
|
||||
auto manager = std::make_unique<Kernel::VMManager>();
|
||||
auto manager = std::make_unique<Kernel::VMManager>(memory);
|
||||
auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block->data(), block->size(),
|
||||
Kernel::MemoryState::Private);
|
||||
REQUIRE(result.Code() == RESULT_SUCCESS);
|
||||
|
@ -44,7 +45,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") {
|
|||
|
||||
SECTION("changing memory permissions") {
|
||||
// Because of the PageTable, Kernel::VMManager is too big to be created on the stack.
|
||||
auto manager = std::make_unique<Kernel::VMManager>();
|
||||
auto manager = std::make_unique<Kernel::VMManager>(memory);
|
||||
auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block->data(), block->size(),
|
||||
Kernel::MemoryState::Private);
|
||||
REQUIRE(result.Code() == RESULT_SUCCESS);
|
||||
|
@ -63,7 +64,7 @@ TEST_CASE("Memory Basics", "[kernel][memory]") {
|
|||
|
||||
SECTION("changing memory state") {
|
||||
// Because of the PageTable, Kernel::VMManager is too big to be created on the stack.
|
||||
auto manager = std::make_unique<Kernel::VMManager>();
|
||||
auto manager = std::make_unique<Kernel::VMManager>(memory);
|
||||
auto result = manager->MapBackingMemory(Memory::HEAP_VADDR, block->data(), block->size(),
|
||||
Kernel::MemoryState::Private);
|
||||
REQUIRE(result.Code() == RESULT_SUCCESS);
|
||||
|
|
Loading…
Reference in a new issue