summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/common_sizes.h4
-rw-r--r--src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp32
-rw-r--r--src/core/hle/kernel/k_address_space_info.cpp29
-rw-r--r--src/core/hle/kernel/k_memory_layout.h16
-rw-r--r--src/core/hle/kernel/kernel.cpp14
5 files changed, 50 insertions, 45 deletions
diff --git a/src/common/common_sizes.h b/src/common/common_sizes.h
index 5dc039c94..7e9fd968b 100644
--- a/src/common/common_sizes.h
+++ b/src/common/common_sizes.h
@@ -8,6 +8,8 @@
8 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10 10
11namespace Common {
12
11enum : u64 { 13enum : u64 {
12 Size_1_KB = 0x400ULL, 14 Size_1_KB = 0x400ULL,
13 Size_64_KB = 64ULL * Size_1_KB, 15 Size_64_KB = 64ULL * Size_1_KB,
@@ -37,3 +39,5 @@ enum : u64 {
37 Size_512_GB = 512ULL * Size_1_GB, 39 Size_512_GB = 512ULL * Size_1_GB,
38 Size_Invalid = std::numeric_limits<u64>::max(), 40 Size_Invalid = std::numeric_limits<u64>::max(),
39}; 41};
42
43} // namespace Common
diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
index a48d0c11e..919a6b943 100644
--- a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
+++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp
@@ -57,11 +57,11 @@ size_t KSystemControl::Init::GetIntendedMemorySize() {
57 switch (GetMemorySizeForInit()) { 57 switch (GetMemorySizeForInit()) {
58 case Smc::MemorySize_4GB: 58 case Smc::MemorySize_4GB:
59 default: // All invalid modes should go to 4GB. 59 default: // All invalid modes should go to 4GB.
60 return Size_4_GB; 60 return Common::Size_4_GB;
61 case Smc::MemorySize_6GB: 61 case Smc::MemorySize_6GB:
62 return Size_6_GB; 62 return Common::Size_6_GB;
63 case Smc::MemorySize_8GB: 63 case Smc::MemorySize_8GB:
64 return Size_8_GB; 64 return Common::Size_8_GB;
65 } 65 }
66} 66}
67 67
@@ -79,17 +79,17 @@ std::size_t KSystemControl::Init::GetApplicationPoolSize() {
79 switch (GetMemoryArrangeForInit()) { 79 switch (GetMemoryArrangeForInit()) {
80 case Smc::MemoryArrangement_4GB: 80 case Smc::MemoryArrangement_4GB:
81 default: 81 default:
82 return Size_3285_MB; 82 return Common::Size_3285_MB;
83 case Smc::MemoryArrangement_4GBForAppletDev: 83 case Smc::MemoryArrangement_4GBForAppletDev:
84 return Size_2048_MB; 84 return Common::Size_2048_MB;
85 case Smc::MemoryArrangement_4GBForSystemDev: 85 case Smc::MemoryArrangement_4GBForSystemDev:
86 return Size_3285_MB; 86 return Common::Size_3285_MB;
87 case Smc::MemoryArrangement_6GB: 87 case Smc::MemoryArrangement_6GB:
88 return Size_4916_MB; 88 return Common::Size_4916_MB;
89 case Smc::MemoryArrangement_6GBForAppletDev: 89 case Smc::MemoryArrangement_6GBForAppletDev:
90 return Size_3285_MB; 90 return Common::Size_3285_MB;
91 case Smc::MemoryArrangement_8GB: 91 case Smc::MemoryArrangement_8GB:
92 return Size_4916_MB; 92 return Common::Size_4916_MB;
93 } 93 }
94 }(); 94 }();
95 95
@@ -103,22 +103,22 @@ size_t KSystemControl::Init::GetAppletPoolSize() {
103 switch (GetMemoryArrangeForInit()) { 103 switch (GetMemoryArrangeForInit()) {
104 case Smc::MemoryArrangement_4GB: 104 case Smc::MemoryArrangement_4GB:
105 default: 105 default:
106 return Size_507_MB; 106 return Common::Size_507_MB;
107 case Smc::MemoryArrangement_4GBForAppletDev: 107 case Smc::MemoryArrangement_4GBForAppletDev:
108 return Size_1554_MB; 108 return Common::Size_1554_MB;
109 case Smc::MemoryArrangement_4GBForSystemDev: 109 case Smc::MemoryArrangement_4GBForSystemDev:
110 return Size_448_MB; 110 return Common::Size_448_MB;
111 case Smc::MemoryArrangement_6GB: 111 case Smc::MemoryArrangement_6GB:
112 return Size_562_MB; 112 return Common::Size_562_MB;
113 case Smc::MemoryArrangement_6GBForAppletDev: 113 case Smc::MemoryArrangement_6GBForAppletDev:
114 return Size_2193_MB; 114 return Common::Size_2193_MB;
115 case Smc::MemoryArrangement_8GB: 115 case Smc::MemoryArrangement_8GB:
116 return Size_2193_MB; 116 return Common::Size_2193_MB;
117 } 117 }
118 }(); 118 }();
119 119
120 // Return (possibly) adjusted size. 120 // Return (possibly) adjusted size.
121 constexpr size_t ExtraSystemMemoryForAtmosphere = Size_33_MB; 121 constexpr size_t ExtraSystemMemoryForAtmosphere = Common::Size_33_MB;
122 return base_pool_size - ExtraSystemMemoryForAtmosphere - KTraceBufferSize; 122 return base_pool_size - ExtraSystemMemoryForAtmosphere - KTraceBufferSize;
123} 123}
124 124
diff --git a/src/core/hle/kernel/k_address_space_info.cpp b/src/core/hle/kernel/k_address_space_info.cpp
index 89906954d..c7549f7a2 100644
--- a/src/core/hle/kernel/k_address_space_info.cpp
+++ b/src/core/hle/kernel/k_address_space_info.cpp
@@ -14,24 +14,25 @@ namespace {
14 14
15// clang-format off 15// clang-format off
16constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{ 16constexpr std::array<KAddressSpaceInfo, 13> AddressSpaceInfos{{
17 { .bit_width = 32, .address = Size_2_MB , .size = Size_1_GB - Size_2_MB , .type = KAddressSpaceInfo::Type::MapSmall, }, 17 { .bit_width = 32, .address = Common::Size_2_MB , .size = Common::Size_1_GB - Common::Size_2_MB , .type = KAddressSpaceInfo::Type::MapSmall, },
18 { .bit_width = 32, .address = Size_1_GB , .size = Size_4_GB - Size_1_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, 18 { .bit_width = 32, .address = Common::Size_1_GB , .size = Common::Size_4_GB - Common::Size_1_GB , .type = KAddressSpaceInfo::Type::MapLarge, },
19 { .bit_width = 32, .address = Size_Invalid, .size = Size_1_GB , .type = KAddressSpaceInfo::Type::Heap, }, 19 { .bit_width = 32, .address = Common::Size_Invalid, .size = Common::Size_1_GB , .type = KAddressSpaceInfo::Type::Alias, },
20 { .bit_width = 32, .address = Size_Invalid, .size = Size_1_GB , .type = KAddressSpaceInfo::Type::Alias, }, 20 { .bit_width = 32, .address = Common::Size_Invalid, .size = Common::Size_1_GB , .type = KAddressSpaceInfo::Type::Heap, },
21 { .bit_width = 36, .address = Size_128_MB , .size = Size_2_GB - Size_128_MB, .type = KAddressSpaceInfo::Type::MapSmall, }, 21 { .bit_width = 36, .address = Common::Size_128_MB , .size = Common::Size_2_GB - Common::Size_128_MB, .type = KAddressSpaceInfo::Type::MapSmall, },
22 { .bit_width = 36, .address = Size_2_GB , .size = Size_64_GB - Size_2_GB , .type = KAddressSpaceInfo::Type::MapLarge, }, 22 { .bit_width = 36, .address = Common::Size_2_GB , .size = Common::Size_64_GB - Common::Size_2_GB , .type = KAddressSpaceInfo::Type::MapLarge, },
23 { .bit_width = 36, .address = Size_Invalid, .size = Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, 23 { .bit_width = 36, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, },
24 { .bit_width = 36, .address = Size_Invalid, .size = Size_6_GB , .type = KAddressSpaceInfo::Type::Alias, }, 24 { .bit_width = 36, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Alias, },
25 { .bit_width = 39, .address = Size_128_MB , .size = Size_512_GB - Size_128_MB, .type = KAddressSpaceInfo::Type::Map39Bit, }, 25 { .bit_width = 39, .address = Common::Size_128_MB , .size = Common::Size_512_GB - Common::Size_128_MB, .type = KAddressSpaceInfo::Type::Map39Bit, },
26 { .bit_width = 39, .address = Size_Invalid, .size = Size_64_GB , .type = KAddressSpaceInfo::Type::MapSmall }, 26 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_64_GB , .type = KAddressSpaceInfo::Type::MapSmall },
27 { .bit_width = 39, .address = Size_Invalid, .size = Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, }, 27 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_6_GB , .type = KAddressSpaceInfo::Type::Heap, },
28 { .bit_width = 39, .address = Size_Invalid, .size = Size_64_GB , .type = KAddressSpaceInfo::Type::Alias, }, 28 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_64_GB , .type = KAddressSpaceInfo::Type::Alias, },
29 { .bit_width = 39, .address = Size_Invalid, .size = Size_2_GB , .type = KAddressSpaceInfo::Type::Stack, }, 29 { .bit_width = 39, .address = Common::Size_Invalid, .size = Common::Size_2_GB , .type = KAddressSpaceInfo::Type::Stack, },
30}}; 30}};
31// clang-format on 31// clang-format on
32 32
33constexpr bool IsAllowedIndexForAddress(std::size_t index) { 33constexpr bool IsAllowedIndexForAddress(std::size_t index) {
34 return index < AddressSpaceInfos.size() && AddressSpaceInfos[index].address != Size_Invalid; 34 return index < AddressSpaceInfos.size() &&
35 AddressSpaceInfos[index].address != Common::Size_Invalid;
35} 36}
36 37
37using IndexArray = 38using IndexArray =
diff --git a/src/core/hle/kernel/k_memory_layout.h b/src/core/hle/kernel/k_memory_layout.h
index b3e057326..590dc449a 100644
--- a/src/core/hle/kernel/k_memory_layout.h
+++ b/src/core/hle/kernel/k_memory_layout.h
@@ -14,20 +14,20 @@
14 14
15namespace Kernel { 15namespace Kernel {
16 16
17constexpr std::size_t L1BlockSize = Size_1_GB; 17constexpr std::size_t L1BlockSize = Common::Size_1_GB;
18constexpr std::size_t L2BlockSize = Size_2_MB; 18constexpr std::size_t L2BlockSize = Common::Size_2_MB;
19 19
20constexpr std::size_t GetMaximumOverheadSize(std::size_t size) { 20constexpr std::size_t GetMaximumOverheadSize(std::size_t size) {
21 return (Common::DivideUp(size, L1BlockSize) + Common::DivideUp(size, L2BlockSize)) * PageSize; 21 return (Common::DivideUp(size, L1BlockSize) + Common::DivideUp(size, L2BlockSize)) * PageSize;
22} 22}
23 23
24constexpr std::size_t MainMemorySize = Size_4_GB; 24constexpr std::size_t MainMemorySize = Common::Size_4_GB;
25constexpr std::size_t MainMemorySizeMax = Size_8_GB; 25constexpr std::size_t MainMemorySizeMax = Common::Size_8_GB;
26 26
27constexpr std::size_t ReservedEarlyDramSize = 0x60000; 27constexpr std::size_t ReservedEarlyDramSize = 0x60000;
28constexpr std::size_t DramPhysicalAddress = 0x80000000; 28constexpr std::size_t DramPhysicalAddress = 0x80000000;
29 29
30constexpr std::size_t KernelAslrAlignment = Size_2_MB; 30constexpr std::size_t KernelAslrAlignment = Common::Size_2_MB;
31constexpr std::size_t KernelVirtualAddressSpaceWidth = 1ULL << 39; 31constexpr std::size_t KernelVirtualAddressSpaceWidth = 1ULL << 39;
32constexpr std::size_t KernelPhysicalAddressSpaceWidth = 1ULL << 48; 32constexpr std::size_t KernelPhysicalAddressSpaceWidth = 1ULL << 48;
33 33
@@ -51,10 +51,10 @@ constexpr std::size_t KernelPhysicalAddressSpaceSize =
51constexpr std::size_t KernelPhysicalAddressCodeBase = DramPhysicalAddress + ReservedEarlyDramSize; 51constexpr std::size_t KernelPhysicalAddressCodeBase = DramPhysicalAddress + ReservedEarlyDramSize;
52 52
53constexpr std::size_t KernelPageTableHeapSize = GetMaximumOverheadSize(MainMemorySizeMax); 53constexpr std::size_t KernelPageTableHeapSize = GetMaximumOverheadSize(MainMemorySizeMax);
54constexpr std::size_t KernelInitialPageHeapSize = Size_128_KB; 54constexpr std::size_t KernelInitialPageHeapSize = Common::Size_128_KB;
55 55
56constexpr std::size_t KernelSlabHeapDataSize = Size_5_MB; 56constexpr std::size_t KernelSlabHeapDataSize = Common::Size_5_MB;
57constexpr std::size_t KernelSlabHeapGapsSize = Size_2_MB - Size_64_KB; 57constexpr std::size_t KernelSlabHeapGapsSize = Common::Size_2_MB - Common::Size_64_KB;
58constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSize; 58constexpr std::size_t KernelSlabHeapSize = KernelSlabHeapDataSize + KernelSlabHeapGapsSize;
59 59
60// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860. 60// NOTE: This is calculated from KThread slab counts, assuming KThread size <= 0x860.
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 9360710de..e994e8bed 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -289,8 +289,8 @@ struct KernelCore::Impl {
289 const VAddr code_end_virt_addr = KernelVirtualAddressCodeEnd; 289 const VAddr code_end_virt_addr = KernelVirtualAddressCodeEnd;
290 290
291 // Setup the containing kernel region. 291 // Setup the containing kernel region.
292 constexpr size_t KernelRegionSize = Size_1_GB; 292 constexpr size_t KernelRegionSize = Common::Size_1_GB;
293 constexpr size_t KernelRegionAlign = Size_1_GB; 293 constexpr size_t KernelRegionAlign = Common::Size_1_GB;
294 constexpr VAddr kernel_region_start = 294 constexpr VAddr kernel_region_start =
295 Common::AlignDown(code_start_virt_addr, KernelRegionAlign); 295 Common::AlignDown(code_start_virt_addr, KernelRegionAlign);
296 size_t kernel_region_size = KernelRegionSize; 296 size_t kernel_region_size = KernelRegionSize;
@@ -337,7 +337,7 @@ struct KernelCore::Impl {
337 337
338 // Decide on the actual size for the misc region. 338 // Decide on the actual size for the misc region.
339 constexpr size_t MiscRegionAlign = KernelAslrAlignment; 339 constexpr size_t MiscRegionAlign = KernelAslrAlignment;
340 constexpr size_t MiscRegionMinimumSize = Size_32_MB; 340 constexpr size_t MiscRegionMinimumSize = Common::Size_32_MB;
341 const size_t misc_region_size = Common::AlignUp( 341 const size_t misc_region_size = Common::AlignUp(
342 std::max(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign); 342 std::max(misc_region_needed_size, MiscRegionMinimumSize), MiscRegionAlign);
343 ASSERT(misc_region_size > 0); 343 ASSERT(misc_region_size > 0);
@@ -350,7 +350,7 @@ struct KernelCore::Impl {
350 misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc)); 350 misc_region_start, misc_region_size, KMemoryRegionType_KernelMisc));
351 351
352 // Setup the stack region. 352 // Setup the stack region.
353 constexpr size_t StackRegionSize = Size_14_MB; 353 constexpr size_t StackRegionSize = Common::Size_14_MB;
354 constexpr size_t StackRegionAlign = KernelAslrAlignment; 354 constexpr size_t StackRegionAlign = KernelAslrAlignment;
355 const VAddr stack_region_start = 355 const VAddr stack_region_start =
356 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion( 356 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion(
@@ -382,7 +382,7 @@ struct KernelCore::Impl {
382 slab_region_start, slab_region_size, KMemoryRegionType_KernelSlab)); 382 slab_region_start, slab_region_size, KMemoryRegionType_KernelSlab));
383 383
384 // Setup the temp region. 384 // Setup the temp region.
385 constexpr size_t TempRegionSize = Size_128_MB; 385 constexpr size_t TempRegionSize = Common::Size_128_MB;
386 constexpr size_t TempRegionAlign = KernelAslrAlignment; 386 constexpr size_t TempRegionAlign = KernelAslrAlignment;
387 const VAddr temp_region_start = 387 const VAddr temp_region_start =
388 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion( 388 memory_layout.GetVirtualMemoryRegionTree().GetRandomAlignedRegion(
@@ -438,7 +438,7 @@ struct KernelCore::Impl {
438 // Determine size available for kernel page table heaps, requiring > 8 MB. 438 // Determine size available for kernel page table heaps, requiring > 8 MB.
439 const PAddr resource_end_phys_addr = slab_start_phys_addr + resource_region_size; 439 const PAddr resource_end_phys_addr = slab_start_phys_addr + resource_region_size;
440 const size_t page_table_heap_size = resource_end_phys_addr - slab_end_phys_addr; 440 const size_t page_table_heap_size = resource_end_phys_addr - slab_end_phys_addr;
441 ASSERT(page_table_heap_size / Size_4_MB > 2); 441 ASSERT(page_table_heap_size / Common::Size_4_MB > 2);
442 442
443 // Insert a physical region for the kernel page table heap region 443 // Insert a physical region for the kernel page table heap region
444 ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert( 444 ASSERT(memory_layout.GetPhysicalMemoryRegionTree().Insert(
@@ -463,7 +463,7 @@ struct KernelCore::Impl {
463 ASSERT(linear_extents.GetEndAddress() != 0); 463 ASSERT(linear_extents.GetEndAddress() != 0);
464 464
465 // Setup the linear mapping region. 465 // Setup the linear mapping region.
466 constexpr size_t LinearRegionAlign = Size_1_GB; 466 constexpr size_t LinearRegionAlign = Common::Size_1_GB;
467 const PAddr aligned_linear_phys_start = 467 const PAddr aligned_linear_phys_start =
468 Common::AlignDown(linear_extents.GetAddress(), LinearRegionAlign); 468 Common::AlignDown(linear_extents.GetAddress(), LinearRegionAlign);
469 const size_t linear_region_size = 469 const size_t linear_region_size =