memory: Dehardcode the use of a 36-bit address space

Given games can also request a 32-bit or 39-bit address space, we
shouldn't be hardcoding the address space range as 36-bit.
This commit is contained in:
Lioncash 2018-09-24 10:29:56 -04:00
parent 75603b005b
commit 7fd598636e
6 changed files with 63 additions and 24 deletions

View file

@ -66,18 +66,21 @@ VMManager::~VMManager() {
void VMManager::Reset(FileSys::ProgramAddressSpaceType type) {
Clear();
InitializeMemoryRegionRanges(type);
page_table.Resize(address_space_width);
// Initialize the map with a single free region covering the entire managed space.
VirtualMemoryArea initial_vma;
initial_vma.size = MAX_ADDRESS;
initial_vma.size = address_space_end;
vma_map.emplace(initial_vma.base, initial_vma);
UpdatePageTableForVMA(initial_vma);
}
VMManager::VMAHandle VMManager::FindVMA(VAddr target) const {
if (target >= MAX_ADDRESS) {
if (target >= address_space_end) {
return vma_map.end();
} else {
return std::prev(vma_map.upper_bound(target));
@ -291,7 +294,7 @@ ResultVal<VMManager::VMAIter> VMManager::CarveVMARange(VAddr target, u64 size) {
const VAddr target_end = target + size;
ASSERT(target_end >= target);
ASSERT(target_end <= MAX_ADDRESS);
ASSERT(target_end <= address_space_end);
ASSERT(size > 0);
VMAIter begin_vma = StripIterConstness(FindVMA(target));
@ -455,9 +458,10 @@ void VMManager::ClearVMAMap() {
}
void VMManager::ClearPageTable() {
page_table.pointers.fill(nullptr);
std::fill(page_table.pointers.begin(), page_table.pointers.end(), nullptr);
page_table.special_regions.clear();
page_table.attributes.fill(Memory::PageType::Unmapped);
std::fill(page_table.attributes.begin(), page_table.attributes.end(),
Memory::PageType::Unmapped);
}
u64 VMManager::GetTotalMemoryUsage() const {
@ -480,6 +484,10 @@ u64 VMManager::GetAddressSpaceSize() const {
return MAX_ADDRESS;
}
u64 VMManager::GetAddressSpaceWidth() const {
return address_space_width;
}
VAddr VMManager::GetCodeRegionBaseAddress() const {
return code_region_base;
}

View file

@ -205,6 +205,9 @@ public:
/// Gets the total address space address size, used by svcGetInfo
u64 GetAddressSpaceSize() const;
/// Gets the address space width in bits.
u64 GetAddressSpaceWidth() const;
/// Gets the base address of the code region.
VAddr GetCodeRegionBaseAddress() const;