2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-04-05 20:39:08 +02:00
|
|
|
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
2021-06-23 23:18:27 +02:00
|
|
|
#include "common/literals.h"
|
2021-02-13 00:47:05 +01:00
|
|
|
#include "core/hle/kernel/k_address_space_info.h"
|
2020-04-05 20:39:08 +02:00
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
namespace Kernel {
|
2020-04-05 20:39:08 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2021-06-23 23:18:27 +02:00
|
|
|
using namespace Common::Literals;
|
|
|
|
|
|
|
|
constexpr u64 Size_Invalid = UINT64_MAX;
|
|
|
|
|
2020-04-05 20:39:08 +02:00
|
|
|
// clang-format off
|
2021-02-13 00:47:05 +01:00
|
|
|
constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{
|
2021-06-23 23:18:27 +02:00
|
|
|
{ .bit_width = 32, .address = 2_MiB , .size = 1_GiB - 2_MiB , .type = KAddressSpaceInfo::Type::MapSmall, },
|
|
|
|
{ .bit_width = 32, .address = 1_GiB , .size = 4_GiB - 1_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
|
|
|
|
{ .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Alias, },
|
|
|
|
{ .bit_width = 32, .address = Size_Invalid, .size = 1_GiB , .type = KAddressSpaceInfo::Type::Heap, },
|
|
|
|
{ .bit_width = 36, .address = 128_MiB , .size = 2_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::MapSmall, },
|
|
|
|
{ .bit_width = 36, .address = 2_GiB , .size = 64_GiB - 2_GiB , .type = KAddressSpaceInfo::Type::MapLarge, },
|
|
|
|
{ .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, },
|
|
|
|
{ .bit_width = 36, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Alias, },
|
|
|
|
{ .bit_width = 39, .address = 128_MiB , .size = 512_GiB - 128_MiB, .type = KAddressSpaceInfo::Type::Map39Bit, },
|
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::MapSmall },
|
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 6_GiB , .type = KAddressSpaceInfo::Type::Heap, },
|
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 64_GiB , .type = KAddressSpaceInfo::Type::Alias, },
|
|
|
|
{ .bit_width = 39, .address = Size_Invalid, .size = 2_GiB , .type = KAddressSpaceInfo::Type::Stack, },
|
2020-04-05 20:39:08 +02:00
|
|
|
}};
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
constexpr bool IsAllowedIndexForAddress(std::size_t index) {
|
2021-06-23 23:18:27 +02:00
|
|
|
return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Size_Invalid;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
using IndexArray =
|
|
|
|
std::array<std::size_t, static_cast<std::size_t>(KAddressSpaceInfo::Type::Count)>;
|
2020-07-13 16:35:22 +02:00
|
|
|
|
|
|
|
constexpr IndexArray AddressSpaceIndices32Bit{
|
|
|
|
0, 1, 0, 2, 0, 3,
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr IndexArray AddressSpaceIndices36Bit{
|
|
|
|
4, 5, 4, 6, 4, 7,
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr IndexArray AddressSpaceIndices39Bit{
|
|
|
|
9, 8, 8, 10, 12, 11,
|
|
|
|
};
|
2020-04-05 20:39:08 +02:00
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
constexpr bool IsAllowed32BitType(KAddressSpaceInfo::Type type) {
|
|
|
|
return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::Map39Bit &&
|
|
|
|
type != KAddressSpaceInfo::Type::Stack;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
constexpr bool IsAllowed36BitType(KAddressSpaceInfo::Type type) {
|
|
|
|
return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::Map39Bit &&
|
|
|
|
type != KAddressSpaceInfo::Type::Stack;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
constexpr bool IsAllowed39BitType(KAddressSpaceInfo::Type type) {
|
|
|
|
return type < KAddressSpaceInfo::Type::Count && type != KAddressSpaceInfo::Type::MapLarge;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
u64 KAddressSpaceInfo::GetAddressSpaceStart(std::size_t width, Type type) {
|
2020-04-05 20:39:08 +02:00
|
|
|
const std::size_t index{static_cast<std::size_t>(type)};
|
|
|
|
switch (width) {
|
|
|
|
case 32:
|
|
|
|
ASSERT(IsAllowed32BitType(type));
|
|
|
|
ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices32Bit[index]));
|
2020-07-13 16:33:36 +02:00
|
|
|
return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].address;
|
2020-04-05 20:39:08 +02:00
|
|
|
case 36:
|
|
|
|
ASSERT(IsAllowed36BitType(type));
|
|
|
|
ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices36Bit[index]));
|
2020-07-13 16:33:36 +02:00
|
|
|
return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].address;
|
2020-04-05 20:39:08 +02:00
|
|
|
case 39:
|
|
|
|
ASSERT(IsAllowed39BitType(type));
|
|
|
|
ASSERT(IsAllowedIndexForAddress(AddressSpaceIndices39Bit[index]));
|
2020-07-13 16:33:36 +02:00
|
|
|
return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
2021-01-05 08:18:16 +01:00
|
|
|
return 0;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
std::size_t KAddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) {
|
2020-04-05 20:39:08 +02:00
|
|
|
const std::size_t index{static_cast<std::size_t>(type)};
|
|
|
|
switch (width) {
|
|
|
|
case 32:
|
|
|
|
ASSERT(IsAllowed32BitType(type));
|
2020-07-13 16:33:36 +02:00
|
|
|
return AddressSpaceInfos[AddressSpaceIndices32Bit[index]].size;
|
2020-04-05 20:39:08 +02:00
|
|
|
case 36:
|
|
|
|
ASSERT(IsAllowed36BitType(type));
|
2020-07-13 16:33:36 +02:00
|
|
|
return AddressSpaceInfos[AddressSpaceIndices36Bit[index]].size;
|
2020-04-05 20:39:08 +02:00
|
|
|
case 39:
|
|
|
|
ASSERT(IsAllowed39BitType(type));
|
2020-07-13 16:33:36 +02:00
|
|
|
return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
UNREACHABLE();
|
2021-01-05 08:18:16 +01:00
|
|
|
return 0;
|
2020-04-05 20:39:08 +02:00
|
|
|
}
|
|
|
|
|
2021-02-13 00:47:05 +01:00
|
|
|
} // namespace Kernel
|