From 541b4353e4a85a1f10c53d643ea48b8e31363a62 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 13 Feb 2021 01:07:23 -0800 Subject: hle: kernel: Add initial KMemoryRegionType module. --- src/core/CMakeLists.txt | 1 + src/core/hle/kernel/k_memory_region.h | 36 +++++++++++++++--------------- src/core/hle/kernel/k_memory_region_type.h | 22 ++++++++++++++++++ 3 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 src/core/hle/kernel/k_memory_region_type.h (limited to 'src/core') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index d9eea00ca..299f1ed13 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -173,6 +173,7 @@ add_library(core STATIC hle/kernel/k_memory_manager.cpp hle/kernel/k_memory_manager.h hle/kernel/k_memory_region.h + hle/kernel/k_memory_region_type.h hle/kernel/k_page_bitmap.h hle/kernel/k_page_heap.cpp hle/kernel/k_page_heap.h diff --git a/src/core/hle/kernel/k_memory_region.h b/src/core/hle/kernel/k_memory_region.h index de236df6a..afa89011c 100644 --- a/src/core/hle/kernel/k_memory_region.h +++ b/src/core/hle/kernel/k_memory_region.h @@ -7,15 +7,26 @@ #include "common/assert.h" #include "common/common_types.h" #include "common/intrusive_red_black_tree.h" +#include "core/hle/kernel/k_memory_region_type.h" namespace Kernel { class KMemoryRegion final : public Common::IntrusiveRedBlackTreeBaseNode, NonCopyable { - friend class KMemoryLayout; friend class KMemoryRegionTree; public: + constexpr KMemoryRegion() = default; + constexpr KMemoryRegion(u64 address_, u64 last_address_) + : address{address_}, last_address{last_address_} {} + constexpr KMemoryRegion(u64 address_, u64 last_address_, u64 pair_address_, u32 attributes_, + u32 type_id_) + : address(address_), last_address(last_address_), pair_address(pair_address_), + attributes(attributes_), type_id(type_id_) {} + constexpr KMemoryRegion(u64 address_, u64 last_address_, u32 attributes_, u32 type_id_) + : KMemoryRegion(address_, last_address_, std::numeric_limits::max(), attributes_, + type_id_) {} + static constexpr int Compare(const KMemoryRegion& lhs, const KMemoryRegion& rhs) { if (lhs.GetAddress() < rhs.GetAddress()) { return -1; @@ -68,9 +79,9 @@ public: return (this->GetType() | type) == this->GetType(); } - // constexpr bool HasTypeAttribute(KMemoryRegionAttr attr) const { - // return (this->GetType() | attr) == this->GetType(); - //} + constexpr bool HasTypeAttribute(KMemoryRegionAttr attr) const { + return (this->GetType() | static_cast(attr)) == this->GetType(); + } constexpr bool CanDerive(u32 type) const { return (this->GetType() | type) == type; @@ -80,22 +91,11 @@ public: pair_address = a; } - // constexpr void SetTypeAttribute(KMemoryRegionAttr attr) { - // type_id |= attr; - //} + constexpr void SetTypeAttribute(KMemoryRegionAttr attr) { + type_id |= static_cast(attr); + } private: - constexpr KMemoryRegion() = default; - constexpr KMemoryRegion(u64 address_, u64 last_address_) - : address{address_}, last_address{last_address_} {} - constexpr KMemoryRegion(u64 address_, u64 last_address_, u64 pair_address_, u32 attributes_, - u32 type_id_) - : address(address_), last_address(last_address_), pair_address(pair_address_), - attributes(attributes_), type_id(type_id_) {} - constexpr KMemoryRegion(u64 address_, u64 last_address_, u32 attributes_, u32 type_id_) - : KMemoryRegion(address_, last_address_, std::numeric_limits::max(), attributes_, - type_id_) {} - const u64 address{}; const u64 last_address{}; u64 pair_address{}; diff --git a/src/core/hle/kernel/k_memory_region_type.h b/src/core/hle/kernel/k_memory_region_type.h new file mode 100644 index 000000000..6fb5abde9 --- /dev/null +++ b/src/core/hle/kernel/k_memory_region_type.h @@ -0,0 +1,22 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Kernel { + +enum class KMemoryRegionType : u32 {}; + +enum class KMemoryRegionAttr : typename std::underlying_type::type { + CarveoutProtected = 0x04000000, + DidKernelMap = 0x08000000, + ShouldKernelMap = 0x10000000, + UserReadOnly = 0x20000000, + NoUserMap = 0x40000000, + LinearMapped = 0x80000000, +}; + +} // namespace Kernel -- cgit v1.2.3