From 6d2734a074f44a24129db850339677d8d7b436aa Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 21:17:57 -0500 Subject: Kernel/Memory: Give each Process its own page table. The loader is in charge of setting the newly created process's page table as the main one during the loading process. --- src/core/memory.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index c8c56babd..859a14202 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -7,8 +7,10 @@ #include #include #include +#include #include #include "common/common_types.h" +#include "core/mmio.h" namespace Memory { @@ -21,6 +23,59 @@ const u32 PAGE_MASK = PAGE_SIZE - 1; const int PAGE_BITS = 12; const size_t PAGE_TABLE_NUM_ENTRIES = 1 << (32 - PAGE_BITS); +enum class PageType { + /// Page is unmapped and should cause an access error. + Unmapped, + /// Page is mapped to regular memory. This is the only type you can get pointers to. + Memory, + /// Page is mapped to regular memory, but also needs to check for rasterizer cache flushing and + /// invalidation + RasterizerCachedMemory, + /// Page is mapped to a I/O region. Writing and reading to this page is handled by functions. + Special, + /// Page is mapped to a I/O region, but also needs to check for rasterizer cache flushing and + /// invalidation + RasterizerCachedSpecial, +}; + +struct SpecialRegion { + VAddr base; + u32 size; + MMIORegionPointer handler; +}; + +/** + * A (reasonably) fast way of allowing switchable and remappable process address spaces. It loosely + * mimics the way a real CPU page table works, but instead is optimized for minimal decoding and + * fetching requirements when accessing. In the usual case of an access to regular memory, it only + * requires an indexed fetch and a check for NULL. + */ +struct PageTable { + /** + * 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`. + */ + std::array pointers; + + /** + * Contains MMIO handlers that back memory regions whose entries in the `attribute` array is of + * type `Special`. + */ + std::vector special_regions; + + /** + * Array 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; + + /** + * Indicates the number of externally cached resources touching a page that should be + * flushed before the memory is accessed + */ + std::array cached_res_count; +}; + /// Physical memory regions as seen from the ARM11 enum : PAddr { /// IO register area @@ -126,6 +181,9 @@ enum : VAddr { NEW_LINEAR_HEAP_VADDR_END = NEW_LINEAR_HEAP_VADDR + NEW_LINEAR_HEAP_SIZE, }; +/// Currently active page table +extern PageTable* current_page_table; + bool IsValidVirtualAddress(const VAddr addr); bool IsValidPhysicalAddress(const PAddr addr); @@ -209,4 +267,4 @@ void RasterizerFlushVirtualRegion(VAddr start, u32 size, FlushMode mode); * retrieve the current page table for that purpose. */ std::array* GetCurrentPageTablePointers(); -} +} // namespace Memory -- cgit v1.2.3 From 214150f00c77474927cbdfb1598dbdb2cb4fcf32 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 21 Jul 2017 22:22:59 -0500 Subject: Kernel/Memory: Changed GetPhysicalPointer so that it doesn't go through the current process' page table to obtain a pointer. --- src/core/memory.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 859a14202..b228a48c2 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -227,8 +227,6 @@ boost::optional PhysicalToVirtualAddress(PAddr addr); /** * Gets a pointer to the memory region beginning at the specified physical address. - * - * @note This is currently implemented using PhysicalToVirtualAddress(). */ u8* GetPhysicalPointer(PAddr address); -- cgit v1.2.3 From c02bbb7030efd072511bd0051a44d9e503016f74 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 24 Sep 2017 22:42:42 +0100 Subject: memory: Add GetCurrentPageTable/SetCurrentPageTable Don't expose Memory::current_page_table as a global. --- src/core/memory.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index b228a48c2..db5a704d0 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -182,7 +182,8 @@ enum : VAddr { }; /// Currently active page table -extern PageTable* current_page_table; +void SetCurrentPageTable(PageTable* page_table); +PageTable* GetCurrentPageTable(); bool IsValidVirtualAddress(const VAddr addr); bool IsValidPhysicalAddress(const PAddr addr); -- cgit v1.2.3 From 4e5eb2044acc304fc2068b53eb03e3a626832996 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 24 Sep 2017 22:43:28 +0100 Subject: memory: Remove GetCurrentPageTablePointers --- src/core/memory.h | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index db5a704d0..1865bfea0 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -260,10 +260,4 @@ enum class FlushMode { */ void RasterizerFlushVirtualRegion(VAddr start, u32 size, FlushMode mode); -/** - * Dynarmic has an optimization to memory accesses when the pointer to the page exists that - * can be used by setting up the current page table as a callback. This function is used to - * retrieve the current page table for that purpose. - */ -std::array* GetCurrentPageTablePointers(); } // namespace Memory -- cgit v1.2.3 From 35da7f57efd5153be37a05ffcbb57412da74265a Mon Sep 17 00:00:00 2001 From: Subv Date: Tue, 26 Sep 2017 17:27:44 -0500 Subject: Memory: Allow IsValidVirtualAddress to be called with a specific process parameter. There is still an overload of IsValidVirtualAddress that only takes the VAddr and will default to the current process. --- src/core/memory.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 1865bfea0..347c08c78 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -12,6 +12,10 @@ #include "common/common_types.h" #include "core/mmio.h" +namespace Kernel { +class Process; +} + namespace Memory { /** @@ -185,7 +189,10 @@ enum : VAddr { void SetCurrentPageTable(PageTable* page_table); PageTable* GetCurrentPageTable(); +/// Determines if the given VAddr is valid for the specified process. +bool IsValidVirtualAddress(const Kernel::Process& process, const VAddr vaddr); bool IsValidVirtualAddress(const VAddr addr); + bool IsValidPhysicalAddress(const PAddr addr); u8 Read8(VAddr addr); -- cgit v1.2.3 From 811c01e5fec3a1cc7a6faf5eaed11d1aaef31768 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 29 Sep 2017 19:38:54 -0500 Subject: Memory: Make ReadBlock take a Process parameter on which to operate --- src/core/memory.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 347c08c78..5d4eb56a9 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -205,6 +205,8 @@ void Write16(VAddr addr, u16 data); void Write32(VAddr addr, u32 data); void Write64(VAddr addr, u64 data); +void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_buffer, + size_t size); void ReadBlock(const VAddr src_addr, void* dest_buffer, size_t size); void WriteBlock(const VAddr dest_addr, const void* src_buffer, size_t size); void ZeroBlock(const VAddr dest_addr, const size_t size); -- cgit v1.2.3 From 1f2de7501b427f9f5ac1e5d244f8ec52eca9bc64 Mon Sep 17 00:00:00 2001 From: Subv Date: Fri, 29 Sep 2017 22:42:25 -0500 Subject: Memory: Make WriteBlock take a Process parameter on which to operate --- src/core/memory.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 5d4eb56a9..dd599f73e 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -208,6 +208,8 @@ void Write64(VAddr addr, u64 data); void ReadBlock(const Kernel::Process& process, const VAddr src_addr, void* dest_buffer, size_t size); void ReadBlock(const VAddr src_addr, void* dest_buffer, size_t size); +void WriteBlock(const Kernel::Process& process, const VAddr dest_addr, const void* src_buffer, + size_t size); void WriteBlock(const VAddr dest_addr, const void* src_buffer, size_t size); void ZeroBlock(const VAddr dest_addr, const size_t size); void CopyBlock(VAddr dest_addr, VAddr src_addr, size_t size); -- cgit v1.2.3