hle: kernel: Add initial KMemoryRegionType module.

This commit is contained in:
bunnei 2021-02-13 01:07:23 -08:00
parent 778e0f8ec1
commit 541b4353e4
3 changed files with 41 additions and 18 deletions

View File

@ -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

View File

@ -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<KMemoryRegion>,
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<uintptr_t>::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<u32>(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<u32>(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<uintptr_t>::max(), attributes_,
type_id_) {}
const u64 address{};
const u64 last_address{};
u64 pair_address{};

View File

@ -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<KMemoryRegionType>::type {
CarveoutProtected = 0x04000000,
DidKernelMap = 0x08000000,
ShouldKernelMap = 0x10000000,
UserReadOnly = 0x20000000,
NoUserMap = 0x40000000,
LinearMapped = 0x80000000,
};
} // namespace Kernel