diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_address_space_info.cpp | 79 |
1 files changed, 13 insertions, 66 deletions
diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp index 3e612a207..97972ebae 100644 --- a/src/core/hle/kernel/k_address_space_info.cpp +++ b/src/core/hle/kernel/k_address_space_info.cpp | |||
| @@ -23,86 +23,33 @@ constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{ | |||
| 23 | { .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Heap, }, | 23 | { .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Heap, }, |
| 24 | { .bit_width = 36, .address = 128_MiB , .size = 2_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::MapSmall, }, | 24 | { .bit_width = 36, .address = 128_MiB , .size = 2_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::MapSmall, }, |
| 25 | { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, }, | 25 | { .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, }, |
| 26 | { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, }, | 26 | { .bit_width = 36, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, |
| 27 | { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, }, | 27 | { .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, }, |
| 28 | { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, }, | 28 | { .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, }, |
| 29 | { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall }, | 29 | { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall }, |
| 30 | { .bit_width = 39, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, }, | 30 | { .bit_width = 39, .address = Size_Invalid, .size = 8_GiB , .type = KAddressSpaceInfo::Type::Heap, }, |
| 31 | { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, }, | 31 | { .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, }, |
| 32 | { .bit_width = 39, .address = Size_Invalid, .size = 2_GiB , .type = KAddressSpaceInfo::Type::Stack, }, | 32 | { .bit_width = 39, .address = Size_Invalid, .size = 2_GiB , .type = KAddressSpaceInfo::Type::Stack, }, |
| 33 | }}; | 33 | }}; |
| 34 | // clang-format on | 34 | // clang-format on |
| 35 | 35 | ||
| 36 | constexpr bool IsAllowedIndexForAddress(std::size_t index) { | 36 | const KAddressSpaceInfo& GetAddressSpaceInfo(size_t width, KAddressSpaceInfo::Type type) { |
| 37 | return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Size_Invalid; | 37 | for (auto& info : AddressSpaceInfos) { |
| 38 | } | 38 | if (info.bit_width == width && info.type == type) { |
| 39 | 39 | return info; | |
| 40 | using IndexArray = | 40 | } |
| 41 | std::array<std::size_t, static_cast<std::size_t>(KAddressSpaceInfo::Type::Count)>; | 41 | } |
| 42 | 42 | UNREACHABLE_MSG("Could not find AddressSpaceInfo"); | |
| 43 | constexpr IndexArray AddressSpaceIndices32Bit{ | ||
| 44 | 0, 1, 0, 2, 0, 3, | ||
| 45 | }; | ||
| 46 | |||
| 47 | constexpr IndexArray AddressSpaceIndices36Bit{ | ||
| 48 | 4, 5, 4, 6, 4, 7, | ||
| 49 | }; | ||
| 50 | |||
| 51 | constexpr IndexArray AddressSpaceIndices39Bit{ | ||
| 52 | 9, 8, 8, 10, 12, 11, | ||
| 53 | }; | ||
| 54 | |||
| 55 | constexpr bool IsAllowed32BitType(KAddressSpaceInfo::Type type) { | ||
| 56 | return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::Map39Bit && | ||
| 57 | type != KAddressSpaceInfo::Type::Stack; | ||
| 58 | } | ||
| 59 | |||
| 60 | constexpr bool IsAllowed36BitType(KAddressSpaceInfo::Type type) { | ||
| 61 | return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::Map39Bit && | ||
| 62 | type != KAddressSpaceInfo::Type::Stack; | ||
| 63 | } | ||
| 64 | |||
| 65 | constexpr bool IsAllowed39BitType(KAddressSpaceInfo::Type type) { | ||
| 66 | return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::MapLarge; | ||
| 67 | } | 43 | } |
| 68 | 44 | ||
| 69 | } // namespace | 45 | } // namespace |
| 70 | 46 | ||
| 71 | u64 KAddressSpaceInfo::GetAddressSpaceStart(std::size_t width, Type type) { | 47 | uintptr_t KAddressSpaceInfo::GetAddressSpaceStart(size_t width, KAddressSpaceInfo::Type type) { |
| 72 | const std::size_t index{static_cast<std::size_t>(type)}; | 48 | return GetAddressSpaceInfo(width, type).address; |
| 73 | switch (width) { | ||
| 74 | case 32: | ||
| 75 | ASSERT(IsAllowed32BitType(type)); | ||
| 76 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices32Bit[index])); | ||
| 77 | return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].address; | ||
| 78 | case 36: | ||
| 79 | ASSERT(IsAllowed36BitType(type)); | ||
| 80 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices36Bit[index])); | ||
| 81 | return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].address; | ||
| 82 | case 39: | ||
| 83 | ASSERT(IsAllowed39BitType(type)); | ||
| 84 | ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices39Bit[index])); | ||
| 85 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address; | ||
| 86 | } | ||
| 87 | ASSERT(false); | ||
| 88 | return 0; | ||
| 89 | } | 49 | } |
| 90 | 50 | ||
| 91 | std::size_t KAddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { | 51 | size_t KAddressSpaceInfo::GetAddressSpaceSize(size_t width, KAddressSpaceInfo::Type type) { |
| 92 | const std::size_t index{static_cast<std::size_t>(type)}; | 52 | return GetAddressSpaceInfo(width, type).size; |
| 93 | switch (width) { | ||
| 94 | case 32: | ||
| 95 | ASSERT(IsAllowed32BitType(type)); | ||
| 96 | return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].size; | ||
| 97 | case 36: | ||
| 98 | ASSERT(IsAllowed36BitType(type)); | ||
| 99 | return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].size; | ||
| 100 | case 39: | ||
| 101 | ASSERT(IsAllowed39BitType(type)); | ||
| 102 | return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; | ||
| 103 | } | ||
| 104 | ASSERT(false); | ||
| 105 | return 0; | ||
| 106 | } | 53 | } |
| 107 | 54 | ||
| 108 | } // namespace Kernel | 55 | } // namespace Kernel |