diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/k_memory_region_type.h | 105 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 23 |
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() == | |||
| 190 | constexpr inline auto KMemoryRegionType_DramKernelSecureAppletMemory = | 190 | constexpr 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); |
| 193 | constexpr inline const auto KMemoryRegionType_DramKernelSecureUnknown = | ||
| 194 | KMemoryRegionType_DramKernelBase.DeriveSparse(1, 3, 1).SetAttribute( | ||
| 195 | KMemoryRegionAttr_LinearMapped); | ||
| 193 | static_assert(KMemoryRegionType_DramKernelSecureAppletMemory.GetValue() == | 196 | static_assert(KMemoryRegionType_DramKernelSecureAppletMemory.GetValue() == |
| 194 | (0x18E | KMemoryRegionAttr_CarveoutProtected | KMemoryRegionAttr_NoUserMap | | 197 | (0x18E | KMemoryRegionAttr_CarveoutProtected | KMemoryRegionAttr_NoUserMap | |
| 195 | KMemoryRegionAttr_LinearMapped)); | 198 | KMemoryRegionAttr_LinearMapped)); |
| 199 | static_assert(KMemoryRegionType_DramKernelSecureUnknown.GetValue() == | ||
| 200 | (0x28E | KMemoryRegionAttr_CarveoutProtected | KMemoryRegionAttr_NoUserMap | | ||
| 201 | KMemoryRegionAttr_LinearMapped)); | ||
| 196 | 202 | ||
| 197 | constexpr inline auto KMemoryRegionType_DramReservedEarly = | 203 | constexpr 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 = | |||
| 217 | static_assert(KMemoryRegionType_DramPoolPartition.GetValue() == | 223 | static_assert(KMemoryRegionType_DramPoolPartition.GetValue() == |
| 218 | (0x26 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); | 224 | (0x26 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); |
| 219 | 225 | ||
| 220 | constexpr inline auto KMemoryRegionType_DramPoolManagement = | 226 | // UNUSED: .Derive(4, 1); |
| 221 | KMemoryRegionType_DramPoolPartition.DeriveTransition(0, 2).DeriveTransition().SetAttribute( | 227 | // UNUSED: .Derive(4, 2); |
| 228 | constexpr inline const auto KMemoryRegionType_DramPoolManagement = | ||
| 229 | KMemoryRegionType_DramPoolPartition.Derive(4, 0).SetAttribute( | ||
| 222 | KMemoryRegionAttr_CarveoutProtected); | 230 | KMemoryRegionAttr_CarveoutProtected); |
| 223 | constexpr inline auto KMemoryRegionType_DramUserPool = | 231 | constexpr inline const auto KMemoryRegionType_DramUserPool = |
| 224 | KMemoryRegionType_DramPoolPartition.DeriveTransition(1, 2).DeriveTransition(); | 232 | KMemoryRegionType_DramPoolPartition.Derive(4, 3); |
| 225 | static_assert(KMemoryRegionType_DramPoolManagement.GetValue() == | 233 | static_assert(KMemoryRegionType_DramPoolManagement.GetValue() == |
| 226 | (0x166 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap | | 234 | (0xE6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap | |
| 227 | KMemoryRegionAttr_CarveoutProtected)); | 235 | KMemoryRegionAttr_CarveoutProtected)); |
| 228 | static_assert(KMemoryRegionType_DramUserPool.GetValue() == | 236 | static_assert(KMemoryRegionType_DramUserPool.GetValue() == |
| 229 | (0x1A6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); | 237 | (0x266 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); |
| 230 | 238 | ||
| 231 | constexpr inline auto KMemoryRegionType_DramApplicationPool = | 239 | constexpr 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 = | |||
| 237 | constexpr inline auto KMemoryRegionType_DramSystemPool = | 245 | constexpr inline auto KMemoryRegionType_DramSystemPool = |
| 238 | KMemoryRegionType_DramUserPool.Derive(4, 3).SetAttribute(KMemoryRegionAttr_CarveoutProtected); | 246 | KMemoryRegionType_DramUserPool.Derive(4, 3).SetAttribute(KMemoryRegionAttr_CarveoutProtected); |
| 239 | static_assert(KMemoryRegionType_DramApplicationPool.GetValue() == | 247 | static_assert(KMemoryRegionType_DramApplicationPool.GetValue() == |
| 240 | (0x7A6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); | 248 | (0xE66 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); |
| 241 | static_assert(KMemoryRegionType_DramAppletPool.GetValue() == | 249 | static_assert(KMemoryRegionType_DramAppletPool.GetValue() == |
| 242 | (0xBA6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); | 250 | (0x1666 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); |
| 243 | static_assert(KMemoryRegionType_DramSystemNonSecurePool.GetValue() == | 251 | static_assert(KMemoryRegionType_DramSystemNonSecurePool.GetValue() == |
| 244 | (0xDA6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); | 252 | (0x1A66 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap)); |
| 245 | static_assert(KMemoryRegionType_DramSystemPool.GetValue() == | 253 | static_assert(KMemoryRegionType_DramSystemPool.GetValue() == |
| 246 | (0x13A6 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap | | 254 | (0x2666 | KMemoryRegionAttr_LinearMapped | KMemoryRegionAttr_NoUserMap | |
| 247 | KMemoryRegionAttr_CarveoutProtected)); | 255 | KMemoryRegionAttr_CarveoutProtected)); |
| 248 | 256 | ||
| 249 | constexpr inline auto KMemoryRegionType_VirtualDramHeapBase = | 257 | constexpr inline auto KMemoryRegionType_VirtualDramHeapBase = |
| 250 | KMemoryRegionType_Dram.DeriveSparse(1, 3, 0); | 258 | KMemoryRegionType_Dram.DeriveSparse(1, 4, 0); |
| 251 | constexpr inline auto KMemoryRegionType_VirtualDramKernelPtHeap = | 259 | constexpr inline auto KMemoryRegionType_VirtualDramKernelPtHeap = |
| 252 | KMemoryRegionType_Dram.DeriveSparse(1, 3, 1); | 260 | KMemoryRegionType_Dram.DeriveSparse(1, 4, 1); |
| 253 | constexpr inline auto KMemoryRegionType_VirtualDramKernelTraceBuffer = | 261 | constexpr inline auto KMemoryRegionType_VirtualDramKernelTraceBuffer = |
| 254 | KMemoryRegionType_Dram.DeriveSparse(1, 3, 2); | 262 | KMemoryRegionType_Dram.DeriveSparse(1, 4, 2); |
| 255 | static_assert(KMemoryRegionType_VirtualDramHeapBase.GetValue() == 0x1A); | 263 | static_assert(KMemoryRegionType_VirtualDramHeapBase.GetValue() == 0x1A); |
| 256 | static_assert(KMemoryRegionType_VirtualDramKernelPtHeap.GetValue() == 0x2A); | 264 | static_assert(KMemoryRegionType_VirtualDramKernelPtHeap.GetValue() == 0x2A); |
| 257 | static_assert(KMemoryRegionType_VirtualDramKernelTraceBuffer.GetValue() == 0x4A); | 265 | static_assert(KMemoryRegionType_VirtualDramKernelTraceBuffer.GetValue() == 0x4A); |
| 258 | 266 | ||
| 259 | // UNUSED: .DeriveSparse(2, 2, 0); | 267 | // UNUSED: .Derive(4, 2); |
| 260 | constexpr inline auto KMemoryRegionType_VirtualDramUnknownDebug = | 268 | constexpr inline const auto KMemoryRegionType_VirtualDramUnknownDebug = |
| 261 | KMemoryRegionType_Dram.DeriveSparse(2, 2, 1); | 269 | KMemoryRegionType_Dram.Advance(2).Derive(4, 0); |
| 262 | static_assert(KMemoryRegionType_VirtualDramUnknownDebug.GetValue() == (0x52)); | 270 | constexpr inline const auto KMemoryRegionType_VirtualDramKernelSecureAppletMemory = |
| 263 | 271 | KMemoryRegionType_Dram.Advance(2).Derive(4, 1); | |
| 264 | constexpr inline auto KMemoryRegionType_VirtualDramKernelSecureAppletMemory = | 272 | constexpr inline const auto KMemoryRegionType_VirtualDramKernelSecureUnknown = |
| 265 | KMemoryRegionType_Dram.DeriveSparse(3, 1, 0); | 273 | KMemoryRegionType_Dram.Advance(2).Derive(4, 3); |
| 266 | static_assert(KMemoryRegionType_VirtualDramKernelSecureAppletMemory.GetValue() == (0x62)); | 274 | static_assert(KMemoryRegionType_VirtualDramUnknownDebug.GetValue() == (0x32)); |
| 267 | 275 | static_assert(KMemoryRegionType_VirtualDramKernelSecureAppletMemory.GetValue() == (0x52)); | |
| 268 | constexpr inline auto KMemoryRegionType_VirtualDramKernelInitPt = | 276 | static_assert(KMemoryRegionType_VirtualDramKernelSecureUnknown.GetValue() == (0x92)); |
| 269 | KMemoryRegionType_VirtualDramHeapBase.Derive(3, 0); | 277 | |
| 270 | constexpr inline auto KMemoryRegionType_VirtualDramPoolManagement = | 278 | // UNUSED: .Derive(4, 3); |
| 271 | KMemoryRegionType_VirtualDramHeapBase.Derive(3, 1); | 279 | constexpr inline const auto KMemoryRegionType_VirtualDramKernelInitPt = |
| 272 | constexpr inline auto KMemoryRegionType_VirtualDramUserPool = | 280 | KMemoryRegionType_VirtualDramHeapBase.Derive(4, 0); |
| 273 | KMemoryRegionType_VirtualDramHeapBase.Derive(3, 2); | 281 | constexpr inline const auto KMemoryRegionType_VirtualDramPoolManagement = |
| 274 | static_assert(KMemoryRegionType_VirtualDramKernelInitPt.GetValue() == 0x19A); | 282 | KMemoryRegionType_VirtualDramHeapBase.Derive(4, 1); |
| 275 | static_assert(KMemoryRegionType_VirtualDramPoolManagement.GetValue() == 0x29A); | 283 | constexpr inline const auto KMemoryRegionType_VirtualDramUserPool = |
| 276 | static_assert(KMemoryRegionType_VirtualDramUserPool.GetValue() == 0x31A); | 284 | KMemoryRegionType_VirtualDramHeapBase.Derive(4, 2); |
| 285 | static_assert(KMemoryRegionType_VirtualDramKernelInitPt.GetValue() == 0x31A); | ||
| 286 | static_assert(KMemoryRegionType_VirtualDramPoolManagement.GetValue() == 0x51A); | ||
| 287 | static_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); |
| 282 | constexpr inline auto KMemoryRegionType_VirtualDramAppletPool = | 293 | constexpr inline const auto KMemoryRegionType_VirtualDramApplicationPool = |
| 283 | KMemoryRegionType_VirtualDramUserPool.Derive(6, 2); | 294 | KMemoryRegionType_VirtualDramUserPool.Derive(4, 0); |
| 284 | constexpr inline auto KMemoryRegionType_VirtualDramApplicationPool = | 295 | constexpr inline const auto KMemoryRegionType_VirtualDramAppletPool = |
| 285 | KMemoryRegionType_VirtualDramUserPool.Derive(6, 3); | 296 | KMemoryRegionType_VirtualDramUserPool.Derive(4, 1); |
| 286 | constexpr inline auto KMemoryRegionType_VirtualDramSystemNonSecurePool = | 297 | constexpr inline const auto KMemoryRegionType_VirtualDramSystemNonSecurePool = |
| 287 | KMemoryRegionType_VirtualDramUserPool.Derive(6, 4); | 298 | KMemoryRegionType_VirtualDramUserPool.Derive(4, 2); |
| 288 | constexpr inline auto KMemoryRegionType_VirtualDramSystemPool = | 299 | constexpr inline const auto KMemoryRegionType_VirtualDramSystemPool = |
| 289 | KMemoryRegionType_VirtualDramUserPool.Derive(6, 5); | 300 | KMemoryRegionType_VirtualDramUserPool.Derive(4, 3); |
| 290 | static_assert(KMemoryRegionType_VirtualDramAppletPool.GetValue() == 0x1B1A); | 301 | static_assert(KMemoryRegionType_VirtualDramApplicationPool.GetValue() == 0x361A); |
| 291 | static_assert(KMemoryRegionType_VirtualDramApplicationPool.GetValue() == 0x271A); | 302 | static_assert(KMemoryRegionType_VirtualDramAppletPool.GetValue() == 0x561A); |
| 292 | static_assert(KMemoryRegionType_VirtualDramSystemNonSecurePool.GetValue() == 0x2B1A); | 303 | static_assert(KMemoryRegionType_VirtualDramSystemNonSecurePool.GetValue() == 0x661A); |
| 293 | static_assert(KMemoryRegionType_VirtualDramSystemPool.GetValue() == 0x331A); | 304 | static_assert(KMemoryRegionType_VirtualDramSystemPool.GetValue() == 0x961A); |
| 294 | 305 | ||
| 295 | constexpr inline auto KMemoryRegionType_ArchDeviceBase = | 306 | constexpr 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 = | |||
| 354 | static_assert(KMemoryRegionType_KernelTemp.GetValue() == 0x31); | 365 | static_assert(KMemoryRegionType_KernelTemp.GetValue() == 0x31); |
| 355 | 366 | ||
| 356 | constexpr KMemoryRegionType GetTypeForVirtualLinearMapping(u32 type_id) { | 367 | constexpr 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 |