From 7fd598636e819d4e86874b20081945936a05c5f1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 24 Sep 2018 10:29:56 -0400 Subject: 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. --- src/core/memory.h | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 2a27c0251..739e5be94 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -4,10 +4,10 @@ #pragma once -#include #include #include #include +#include #include #include "common/common_types.h" #include "core/memory_hook.h" @@ -23,10 +23,8 @@ namespace Memory { * be mapped. */ constexpr std::size_t PAGE_BITS = 12; -constexpr u64 PAGE_SIZE = 1 << PAGE_BITS; +constexpr u64 PAGE_SIZE = 1ULL << PAGE_BITS; constexpr u64 PAGE_MASK = PAGE_SIZE - 1; -constexpr std::size_t ADDRESS_SPACE_BITS = 36; -constexpr std::size_t PAGE_TABLE_NUM_ENTRIES = 1ULL << (ADDRESS_SPACE_BITS - PAGE_BITS); enum class PageType : u8 { /// Page is unmapped and should cause an access error. @@ -62,23 +60,35 @@ struct SpecialRegion { * mimics the way a real CPU page table works. */ struct PageTable { + explicit PageTable(); + explicit PageTable(std::size_t address_space_width_in_bits); + ~PageTable(); + + /** + * Resizes the page table to be able to accomodate enough pages within + * a given address space. + * + * @param address_space_width_in_bits The address size width in bits. + */ + void Resize(std::size_t address_space_width_in_bits); + /** - * Array of memory pointers backing each page. An entry can only be non-null if the - * corresponding entry in the `attributes` array is of type `Memory`. + * Vector of memory pointers backing each page. An entry can only be non-null if the + * corresponding entry in the `attributes` vector is of type `Memory`. */ - std::array pointers; + std::vector pointers; /** - * Contains MMIO handlers that back memory regions whose entries in the `attribute` array is of - * type `Special`. + * Contains MMIO handlers that back memory regions whose entries in the `attribute` vector is + * of type `Special`. */ boost::icl::interval_map> special_regions; /** - * Array of fine grained page attributes. If it is set to any value other than `Memory`, then + * Vector of fine grained page attributes. If it is set to any value other than `Memory`, then * the corresponding entry in `pointers` MUST be set to null. */ - std::array attributes; + std::vector attributes; }; /// Virtual user-space memory regions -- cgit v1.2.3 From 83377113bfe7791483a1b67e06dd0f51620c04ec Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 24 Sep 2018 20:01:45 -0400 Subject: memory: Dehardcode the use of fixed memory range constants The locations of these can actually vary depending on the address space layout, so we shouldn't be using these when determining where to map memory or be using them as offsets for calculations. This keeps all the memory ranges flexible and malleable based off of the virtual memory manager instance state. --- src/core/memory.h | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 739e5be94..1acf5ce8c 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -93,11 +93,6 @@ struct PageTable { /// Virtual user-space memory regions enum : VAddr { - /// Where the application text, data and bss reside. - PROCESS_IMAGE_VADDR = 0x08000000, - PROCESS_IMAGE_MAX_SIZE = 0x08000000, - PROCESS_IMAGE_VADDR_END = PROCESS_IMAGE_VADDR + PROCESS_IMAGE_MAX_SIZE, - /// Read-only page containing kernel and system configuration values. CONFIG_MEMORY_VADDR = 0x1FF80000, CONFIG_MEMORY_SIZE = 0x00001000, @@ -108,36 +103,12 @@ enum : VAddr { SHARED_PAGE_SIZE = 0x00001000, SHARED_PAGE_VADDR_END = SHARED_PAGE_VADDR + SHARED_PAGE_SIZE, - /// Area where TLS (Thread-Local Storage) buffers are allocated. - TLS_AREA_VADDR = 0x40000000, + /// TLS (Thread-Local Storage) related. TLS_ENTRY_SIZE = 0x200, - TLS_AREA_SIZE = 0x10000000, - TLS_AREA_VADDR_END = TLS_AREA_VADDR + TLS_AREA_SIZE, /// Application stack - STACK_AREA_VADDR = TLS_AREA_VADDR_END, - STACK_AREA_SIZE = 0x10000000, - STACK_AREA_VADDR_END = STACK_AREA_VADDR + STACK_AREA_SIZE, DEFAULT_STACK_SIZE = 0x100000, - /// Application heap - /// Size is confirmed to be a static value on fw 3.0.0 - HEAP_VADDR = 0x108000000, - HEAP_SIZE = 0x180000000, - HEAP_VADDR_END = HEAP_VADDR + HEAP_SIZE, - - /// New map region - /// Size is confirmed to be a static value on fw 3.0.0 - NEW_MAP_REGION_VADDR = HEAP_VADDR_END, - NEW_MAP_REGION_SIZE = 0x80000000, - NEW_MAP_REGION_VADDR_END = NEW_MAP_REGION_VADDR + NEW_MAP_REGION_SIZE, - - /// Map region - /// Size is confirmed to be a static value on fw 3.0.0 - MAP_REGION_VADDR = NEW_MAP_REGION_VADDR_END, - MAP_REGION_SIZE = 0x1000000000, - MAP_REGION_VADDR_END = MAP_REGION_VADDR + MAP_REGION_SIZE, - /// Kernel Virtual Address Range KERNEL_REGION_VADDR = 0xFFFFFF8000000000, KERNEL_REGION_SIZE = 0x7FFFE00000, -- cgit v1.2.3