summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/k_memory_region_type.h105
-rw-r--r--src/core/hle/kernel/kernel.cpp23
2 files changed, 80 insertions, 48 deletions
diff --git a/src/core/hle/kernel/k_memory_region_type.h b/src/core/hle/kernel/k_memory_region_type.h
index e5630c1ac..bcbf450f0 100644
--- a/src/core/hle/kernel/k_memory_region_type.h
+++ b/src/core/hle/kernel/k_memory_region_type.h
@@ -190,9 +190,15 @@ static_assert(KMemoryRegionType_DramKernelInitPt.GetValue() ==
190constexpr inline auto KMemoryRegionType_DramKernelSecureAppletMemory = 190constexpr inline auto KMemoryRegionType_DramKernelSecureAppletMemory =
191 KMemoryRegionType_DramKernelBase.DeriveSparse(1, 3, 0).SetAttribute( 191 KMemoryRegionType_DramKernelBase.DeriveSparse(1, 3, 0).SetAttribute(
192 KMemoryRegionAttr_LinearMapped); 192 KMemoryRegionAttr_LinearMapped);
193constexpr inline const auto KMemoryRegionType_DramKernelSecureUnknown =
194 KMemoryRegionType_DramKernelBase.DeriveSparse(1, 3, 1).SetAttribute(
195 KMemoryRegionAttr_LinearMapped);
193static_assert(KMemoryRegionType_DramKernelSecureAppletMemory.GetValue() == 196static_assert(KMemoryRegionType_DramKernelSecureAppletMemory.GetValue() ==
194 (0x18E | KMemoryRegionAttr_CarveoutProtected | KMemoryRegionAttr_NoUserMap | 197 (0x18E | KMemoryRegionAttr_CarveoutProtected | KMemoryRegionAttr_NoUserMap |
195 KMemoryRegionAttr_LinearMapped)); 198 KMemoryRegionAttr_LinearMapped));
199static_assert(KMemoryRegionType_DramKernelSecureUnknown.GetValue() ==
200 (0x28E | KMemoryRegionAttr_CarveoutProtected | KMemoryRegionAttr_NoUserMap |
201 KMemoryRegionAttr_LinearMapped));
196 202
197constexpr inline auto KMemoryRegionType_DramReservedEarly = 203constexpr inline auto KMemoryRegionType_DramReservedEarly =
198 KMemoryRegionType_DramReservedBase.DeriveAttribute(KMemoryRegionAttr_NoUserMap); 204 KMemoryRegionType_DramReservedBase.DeriveAttribute(KMemoryRegionAttr_NoUserMap);
@@ -217,16 +223,18 @@ constexpr inline auto KMemoryRegionType_DramPoolPartition =
217static_assert(KMemoryRegionType_DramPoolPartition.GetValue() == 223static_assert(KMemoryRegionType_DramPoolPartition.GetValue() ==
218 (0x26 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); 224 (0x26 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap));
219 225
220constexpr inline auto KMemoryRegionType_DramPoolManagement = 226// UNUSED: .Derive(4, 1);
221 KMemoryRegionType_DramPoolPartition.DeriveTransition(0, 2).DeriveTransition().SetAttribute( 227// UNUSED: .Derive(4, 2);
228constexpr inline const auto KMemoryRegionType_DramPoolManagement =
229 KMemoryRegionType_DramPoolPartition.Derive(4, 0).SetAttribute(
222 KMemoryRegionAttr_CarveoutProtected); 230 KMemoryRegionAttr_CarveoutProtected);
223constexpr inline auto KMemoryRegionType_DramUserPool = 231constexpr inline const auto KMemoryRegionType_DramUserPool =
224 KMemoryRegionType_DramPoolPartition.DeriveTransition(1, 2).DeriveTransition(); 232 KMemoryRegionType_DramPoolPartition.Derive(4, 3);
225static_assert(KMemoryRegionType_DramPoolManagement.GetValue() == 233static_assert(KMemoryRegionType_DramPoolManagement.GetValue() ==
226 (0x166 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap | 234 (0xE6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap |
227 KMemoryRegionAttr_CarveoutProtected)); 235 KMemoryRegionAttr_CarveoutProtected));
228static_assert(KMemoryRegionType_DramUserPool.GetValue() == 236static_assert(KMemoryRegionType_DramUserPool.GetValue() ==
229 (0x1A6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); 237 (0x266 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap));
230 238
231constexpr inline auto KMemoryRegionType_DramApplicationPool = 239constexpr inline auto KMemoryRegionType_DramApplicationPool =
232 KMemoryRegionType_DramUserPool.Derive(4, 0); 240 KMemoryRegionType_DramUserPool.Derive(4, 0);
@@ -237,60 +245,63 @@ constexpr inline auto KMemoryRegionType_DramSystemNonSecurePool =
237constexpr inline auto KMemoryRegionType_DramSystemPool = 245constexpr inline auto KMemoryRegionType_DramSystemPool =
238 KMemoryRegionType_DramUserPool.Derive(4, 3).SetAttribute(KMemoryRegionAttr_CarveoutProtected); 246 KMemoryRegionType_DramUserPool.Derive(4, 3).SetAttribute(KMemoryRegionAttr_CarveoutProtected);
239static_assert(KMemoryRegionType_DramApplicationPool.GetValue() == 247static_assert(KMemoryRegionType_DramApplicationPool.GetValue() ==
240 (0x7A6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); 248 (0xE66 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap));
241static_assert(KMemoryRegionType_DramAppletPool.GetValue() == 249static_assert(KMemoryRegionType_DramAppletPool.GetValue() ==
242 (0xBA6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); 250 (0x1666 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap));
243static_assert(KMemoryRegionType_DramSystemNonSecurePool.GetValue() == 251static_assert(KMemoryRegionType_DramSystemNonSecurePool.GetValue() ==
244 (0xDA6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); 252 (0x1A66 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap));
245static_assert(KMemoryRegionType_DramSystemPool.GetValue() == 253static_assert(KMemoryRegionType_DramSystemPool.GetValue() ==
246 (0x13A6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap | 254 (0x2666 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap |
247 KMemoryRegionAttr_CarveoutProtected)); 255 KMemoryRegionAttr_CarveoutProtected));
248 256
249constexpr inline auto KMemoryRegionType_VirtualDramHeapBase = 257constexpr inline auto KMemoryRegionType_VirtualDramHeapBase =
250 KMemoryRegionType_Dram.DeriveSparse(1, 3, 0); 258 KMemoryRegionType_Dram.DeriveSparse(1, 4, 0);
251constexpr inline auto KMemoryRegionType_VirtualDramKernelPtHeap = 259constexpr inline auto KMemoryRegionType_VirtualDramKernelPtHeap =
252 KMemoryRegionType_Dram.DeriveSparse(1, 3, 1); 260 KMemoryRegionType_Dram.DeriveSparse(1, 4, 1);
253constexpr inline auto KMemoryRegionType_VirtualDramKernelTraceBuffer = 261constexpr inline auto KMemoryRegionType_VirtualDramKernelTraceBuffer =
254 KMemoryRegionType_Dram.DeriveSparse(1, 3, 2); 262 KMemoryRegionType_Dram.DeriveSparse(1, 4, 2);
255static_assert(KMemoryRegionType_VirtualDramHeapBase.GetValue() == 0x1A); 263static_assert(KMemoryRegionType_VirtualDramHeapBase.GetValue() == 0x1A);
256static_assert(KMemoryRegionType_VirtualDramKernelPtHeap.GetValue() == 0x2A); 264static_assert(KMemoryRegionType_VirtualDramKernelPtHeap.GetValue() == 0x2A);
257static_assert(KMemoryRegionType_VirtualDramKernelTraceBuffer.GetValue() == 0x4A); 265static_assert(KMemoryRegionType_VirtualDramKernelTraceBuffer.GetValue() == 0x4A);
258 266
259// UNUSED: .DeriveSparse(2, 2, 0); 267// UNUSED: .Derive(4, 2);
260constexpr inline auto KMemoryRegionType_VirtualDramUnknownDebug = 268constexpr inline const auto KMemoryRegionType_VirtualDramUnknownDebug =
261 KMemoryRegionType_Dram.DeriveSparse(2, 2, 1); 269 KMemoryRegionType_Dram.Advance(2).Derive(4, 0);
262static_assert(KMemoryRegionType_VirtualDramUnknownDebug.GetValue() == (0x52)); 270constexpr inline const auto KMemoryRegionType_VirtualDramKernelSecureAppletMemory =
263 271 KMemoryRegionType_Dram.Advance(2).Derive(4, 1);
264constexpr inline auto KMemoryRegionType_VirtualDramKernelSecureAppletMemory = 272constexpr inline const auto KMemoryRegionType_VirtualDramKernelSecureUnknown =
265 KMemoryRegionType_Dram.DeriveSparse(3, 1, 0); 273 KMemoryRegionType_Dram.Advance(2).Derive(4, 3);
266static_assert(KMemoryRegionType_VirtualDramKernelSecureAppletMemory.GetValue() == (0x62)); 274static_assert(KMemoryRegionType_VirtualDramUnknownDebug.GetValue() == (0x32));
267 275static_assert(KMemoryRegionType_VirtualDramKernelSecureAppletMemory.GetValue() == (0x52));
268constexpr inline auto KMemoryRegionType_VirtualDramKernelInitPt = 276static_assert(KMemoryRegionType_VirtualDramKernelSecureUnknown.GetValue() == (0x92));
269 KMemoryRegionType_VirtualDramHeapBase.Derive(3, 0); 277
270constexpr inline auto KMemoryRegionType_VirtualDramPoolManagement = 278// UNUSED: .Derive(4, 3);
271 KMemoryRegionType_VirtualDramHeapBase.Derive(3, 1); 279constexpr inline const auto KMemoryRegionType_VirtualDramKernelInitPt =
272constexpr inline auto KMemoryRegionType_VirtualDramUserPool = 280 KMemoryRegionType_VirtualDramHeapBase.Derive(4, 0);
273 KMemoryRegionType_VirtualDramHeapBase.Derive(3, 2); 281constexpr inline const auto KMemoryRegionType_VirtualDramPoolManagement =
274static_assert(KMemoryRegionType_VirtualDramKernelInitPt.GetValue() == 0x19A); 282 KMemoryRegionType_VirtualDramHeapBase.Derive(4, 1);
275static_assert(KMemoryRegionType_VirtualDramPoolManagement.GetValue() == 0x29A); 283constexpr inline const auto KMemoryRegionType_VirtualDramUserPool =
276static_assert(KMemoryRegionType_VirtualDramUserPool.GetValue() == 0x31A); 284 KMemoryRegionType_VirtualDramHeapBase.Derive(4, 2);
285static_assert(KMemoryRegionType_VirtualDramKernelInitPt.GetValue() == 0x31A);
286static_assert(KMemoryRegionType_VirtualDramPoolManagement.GetValue() == 0x51A);
287static_assert(KMemoryRegionType_VirtualDramUserPool.GetValue() == 0x61A);
277 288
278// NOTE: For unknown reason, the pools are derived out-of-order here. 289// NOTE: For unknown reason, the pools are derived out-of-order here.
279// It's worth eventually trying to understand why Nintendo made this choice. 290// It's worth eventually trying to understand why Nintendo made this choice.
280// UNUSED: .Derive(6, 0); 291// UNUSED: .Derive(6, 0);
281// UNUSED: .Derive(6, 1); 292// UNUSED: .Derive(6, 1);
282constexpr inline auto KMemoryRegionType_VirtualDramAppletPool = 293constexpr inline const auto KMemoryRegionType_VirtualDramApplicationPool =
283 KMemoryRegionType_VirtualDramUserPool.Derive(6, 2); 294 KMemoryRegionType_VirtualDramUserPool.Derive(4, 0);
284constexpr inline auto KMemoryRegionType_VirtualDramApplicationPool = 295constexpr inline const auto KMemoryRegionType_VirtualDramAppletPool =
285 KMemoryRegionType_VirtualDramUserPool.Derive(6, 3); 296 KMemoryRegionType_VirtualDramUserPool.Derive(4, 1);
286constexpr inline auto KMemoryRegionType_VirtualDramSystemNonSecurePool = 297constexpr inline const auto KMemoryRegionType_VirtualDramSystemNonSecurePool =
287 KMemoryRegionType_VirtualDramUserPool.Derive(6, 4); 298 KMemoryRegionType_VirtualDramUserPool.Derive(4, 2);
288constexpr inline auto KMemoryRegionType_VirtualDramSystemPool = 299constexpr inline const auto KMemoryRegionType_VirtualDramSystemPool =
289 KMemoryRegionType_VirtualDramUserPool.Derive(6, 5); 300 KMemoryRegionType_VirtualDramUserPool.Derive(4, 3);
290static_assert(KMemoryRegionType_VirtualDramAppletPool.GetValue() == 0x1B1A); 301static_assert(KMemoryRegionType_VirtualDramApplicationPool.GetValue() == 0x361A);
291static_assert(KMemoryRegionType_VirtualDramApplicationPool.GetValue() == 0x271A); 302static_assert(KMemoryRegionType_VirtualDramAppletPool.GetValue() == 0x561A);
292static_assert(KMemoryRegionType_VirtualDramSystemNonSecurePool.GetValue() == 0x2B1A); 303static_assert(KMemoryRegionType_VirtualDramSystemNonSecurePool.GetValue() == 0x661A);
293static_assert(KMemoryRegionType_VirtualDramSystemPool.GetValue() == 0x331A); 304static_assert(KMemoryRegionType_VirtualDramSystemPool.GetValue() == 0x961A);
294 305
295constexpr inline auto KMemoryRegionType_ArchDeviceBase = 306constexpr inline auto KMemoryRegionType_ArchDeviceBase =
296 KMemoryRegionType_Kernel.DeriveTransition(0, 1).SetSparseOnly(); 307 KMemoryRegionType_Kernel.DeriveTransition(0, 1).SetSparseOnly();
@@ -354,12 +365,14 @@ constexpr inline auto KMemoryRegionType_KernelTemp =
354static_assert(KMemoryRegionType_KernelTemp.GetValue() == 0x31); 365static_assert(KMemoryRegionType_KernelTemp.GetValue() == 0x31);
355 366
356constexpr KMemoryRegionType GetTypeForVirtualLinearMapping(u32 type_id) { 367constexpr KMemoryRegionType GetTypeForVirtualLinearMapping(u32 type_id) {
357 if (KMemoryRegionType_KernelTraceBuffer.IsAncestorOf(type_id)) { 368 if (KMemoryRegionType_DramKernelPtHeap.IsAncestorOf(type_id)) {
358 return KMemoryRegionType_VirtualDramKernelTraceBuffer;
359 } else if (KMemoryRegionType_DramKernelPtHeap.IsAncestorOf(type_id)) {
360 return KMemoryRegionType_VirtualDramKernelPtHeap; 369 return KMemoryRegionType_VirtualDramKernelPtHeap;
361 } else if (KMemoryRegionType_DramKernelSecureAppletMemory.IsAncestorOf(type_id)) { 370 } else if (KMemoryRegionType_DramKernelSecureAppletMemory.IsAncestorOf(type_id)) {
362 return KMemoryRegionType_VirtualDramKernelSecureAppletMemory; 371 return KMemoryRegionType_VirtualDramKernelSecureAppletMemory;
372 } else if (KMemoryRegionType_DramKernelSecureUnknown.IsAncestorOf(type_id)) {
373 return KMemoryRegionType_VirtualDramKernelSecureUnknown;
374 } else if (KMemoryRegionType_KernelTraceBuffer.IsAncestorOf(type_id)) {
375 return KMemoryRegionType_VirtualDramKernelTraceBuffer;
363 } else if ((type_id | KMemoryRegionAttr_ShouldKernelMap) == type_id) { 376 } else if ((type_id | KMemoryRegionAttr_ShouldKernelMap) == type_id) {
364 return KMemoryRegionType_VirtualDramUnknownDebug; 377 return KMemoryRegionType_VirtualDramUnknownDebug;
365 } else { 378 } else {
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index cb025c3d6..6f19860a1 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -623,14 +623,33 @@ struct KernelCore::Impl {
623 ASSERT(memory_layout->GetPhysicalMemoryRegionTree().Insert( 623 ASSERT(memory_layout->GetPhysicalMemoryRegionTree().Insert(
624 GetInteger(slab_start_phys_addr), slab_region_size, KMemoryRegionType_DramKernelSlab)); 624 GetInteger(slab_start_phys_addr), slab_region_size, KMemoryRegionType_DramKernelSlab));
625 625
626 // Insert a physical region for the secure applet memory.
627 const auto secure_applet_end_phys_addr =
628 slab_end_phys_addr + KSystemControl::SecureAppletMemorySize;
629 if constexpr (KSystemControl::SecureAppletMemorySize > 0) {
630 ASSERT(memory_layout->GetPhysicalMemoryRegionTree().Insert(
631 GetInteger(slab_end_phys_addr), KSystemControl::SecureAppletMemorySize,
632 KMemoryRegionType_DramKernelSecureAppletMemory));
633 }
634
635 // Insert a physical region for the unknown debug2 region.
636 constexpr size_t SecureUnknownRegionSize = 0;
637 const size_t secure_unknown_size = SecureUnknownRegionSize;
638 const auto secure_unknown_end_phys_addr = secure_applet_end_phys_addr + secure_unknown_size;
639 if (secure_unknown_size > 0) {
640 ASSERT(memory_layout->GetPhysicalMemoryRegionTree().Insert(
641 GetInteger(secure_applet_end_phys_addr), secure_unknown_size,
642 KMemoryRegionType_DramKernelSecureUnknown));
643 }
644
626 // Determine size available for kernel page table heaps, requiring > 8 MB. 645 // Determine size available for kernel page table heaps, requiring > 8 MB.
627 const KPhysicalAddress resource_end_phys_addr = slab_start_phys_addr + resource_region_size; 646 const KPhysicalAddress resource_end_phys_addr = slab_start_phys_addr + resource_region_size;
628 const size_t page_table_heap_size = resource_end_phys_addr - slab_end_phys_addr; 647 const size_t page_table_heap_size = resource_end_phys_addr - secure_unknown_end_phys_addr;
629 ASSERT(page_table_heap_size / 4_MiB > 2); 648 ASSERT(page_table_heap_size / 4_MiB > 2);
630 649
631 // Insert a physical region for the kernel page table heap region 650 // Insert a physical region for the kernel page table heap region
632 ASSERT(memory_layout->GetPhysicalMemoryRegionTree().Insert( 651 ASSERT(memory_layout->GetPhysicalMemoryRegionTree().Insert(
633 GetInteger(slab_end_phys_addr), page_table_heap_size, 652 GetInteger(secure_unknown_end_phys_addr), page_table_heap_size,
634 KMemoryRegionType_DramKernelPtHeap)); 653 KMemoryRegionType_DramKernelPtHeap));
635 654
636 // All DRAM regions that we haven't tagged by this point will be mapped under the linear 655 // All DRAM regions that we haven't tagged by this point will be mapped under the linear