From 738f91a57da7c129d1ee85b7abbf6858f8669ee3 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 27 Jan 2018 15:16:39 +0000 Subject: memory: Replace all memory hooking with Special regions --- src/core/memory.h | 72 ++++++++++++++++--------------------------------------- 1 file changed, 21 insertions(+), 51 deletions(-) (limited to 'src/core/memory.h') diff --git a/src/core/memory.h b/src/core/memory.h index 7e554f394..b2158ca46 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -8,10 +8,12 @@ #include #include #include +#include #include +#include #include #include "common/common_types.h" -#include "core/mmio.h" +#include "core/memory_hook.h" namespace Kernel { class Process; @@ -28,32 +30,35 @@ const u64 PAGE_SIZE = 1 << PAGE_BITS; const u64 PAGE_MASK = PAGE_SIZE - 1; const size_t PAGE_TABLE_NUM_ENTRIES = 1ULL << (36 - PAGE_BITS); -enum class PageType { +enum class PageType : u8 { /// 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. + /// Page is mapped to a memory hook, which intercepts read and write requests. 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; - u64 size; - MMIORegionPointer handler; + enum class Type { + DebugHook, + IODevice, + } type; + + MemoryHookPointer handler; + + bool operator<(const SpecialRegion& other) const { + return std::tie(type, handler) < std::tie(other.type, other.handler); + } + + bool operator==(const SpecialRegion& other) const { + return std::tie(type, handler) == std::tie(other.type, other.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. + * mimics the way a real CPU page table works. */ struct PageTable { /** @@ -66,19 +71,13 @@ struct PageTable { * Contains MMIO handlers that back memory regions whose entries in the `attribute` array is of * type `Special`. */ - std::vector special_regions; + boost::icl::interval_map> 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 @@ -243,33 +242,4 @@ boost::optional PhysicalToVirtualAddress(PAddr addr); */ u8* GetPhysicalPointer(PAddr address); -/** - * Adds the supplied value to the rasterizer resource cache counter of each - * page touching the region. - */ -void RasterizerMarkRegionCached(PAddr start, u64 size, int count_delta); - -/** - * Flushes any externally cached rasterizer resources touching the given region. - */ -void RasterizerFlushRegion(PAddr start, u64 size); - -/** - * Flushes and invalidates any externally cached rasterizer resources touching the given region. - */ -void RasterizerFlushAndInvalidateRegion(PAddr start, u64 size); - -enum class FlushMode { - /// Write back modified surfaces to RAM - Flush, - /// Write back modified surfaces to RAM, and also remove them from the cache - FlushAndInvalidate, -}; - -/** - * Flushes and invalidates any externally cached rasterizer resources touching the given virtual - * address region. - */ -void RasterizerFlushVirtualRegion(VAddr start, u64 size, FlushMode mode); - } // namespace Memory -- cgit v1.2.3