summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/kernel.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2020-04-08 21:06:37 -0400
committerGravatar bunnei2020-04-17 00:59:32 -0400
commit8f75524e5534bb0893cce35631d98e08362be611 (patch)
treeff4efc38835e3f5af7f45c9eb7b8f8860df4b50a /src/core/hle/kernel/kernel.cpp
parentcore: system: Rename GetDeviceManager -> DeviceManager. (diff)
downloadyuzu-8f75524e5534bb0893cce35631d98e08362be611.tar.gz
yuzu-8f75524e5534bb0893cce35631d98e08362be611.tar.xz
yuzu-8f75524e5534bb0893cce35631d98e08362be611.zip
kernel: Initialize memory layout for new VMM.
Diffstat (limited to 'src/core/hle/kernel/kernel.cpp')
-rw-r--r--src/core/hle/kernel/kernel.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index 014d647cf..db5796d15 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -18,15 +18,20 @@
18#include "core/core.h" 18#include "core/core.h"
19#include "core/core_timing.h" 19#include "core/core_timing.h"
20#include "core/core_timing_util.h" 20#include "core/core_timing_util.h"
21#include "core/device_memory.h"
21#include "core/hardware_properties.h" 22#include "core/hardware_properties.h"
22#include "core/hle/kernel/client_port.h" 23#include "core/hle/kernel/client_port.h"
23#include "core/hle/kernel/errors.h" 24#include "core/hle/kernel/errors.h"
24#include "core/hle/kernel/handle_table.h" 25#include "core/hle/kernel/handle_table.h"
25#include "core/hle/kernel/kernel.h" 26#include "core/hle/kernel/kernel.h"
27#include "core/hle/kernel/memory/memory_layout.h"
28#include "core/hle/kernel/memory/memory_manager.h"
29#include "core/hle/kernel/memory/slab_heap.h"
26#include "core/hle/kernel/physical_core.h" 30#include "core/hle/kernel/physical_core.h"
27#include "core/hle/kernel/process.h" 31#include "core/hle/kernel/process.h"
28#include "core/hle/kernel/resource_limit.h" 32#include "core/hle/kernel/resource_limit.h"
29#include "core/hle/kernel/scheduler.h" 33#include "core/hle/kernel/scheduler.h"
34#include "core/hle/kernel/shared_memory.h"
30#include "core/hle/kernel/synchronization.h" 35#include "core/hle/kernel/synchronization.h"
31#include "core/hle/kernel/thread.h" 36#include "core/hle/kernel/thread.h"
32#include "core/hle/kernel/time_manager.h" 37#include "core/hle/kernel/time_manager.h"
@@ -110,6 +115,7 @@ struct KernelCore::Impl {
110 115
111 InitializePhysicalCores(); 116 InitializePhysicalCores();
112 InitializeSystemResourceLimit(kernel); 117 InitializeSystemResourceLimit(kernel);
118 InitializeMemoryLayout();
113 InitializeThreads(); 119 InitializeThreads();
114 InitializePreemption(); 120 InitializePreemption();
115 } 121 }
@@ -237,6 +243,57 @@ struct KernelCore::Impl {
237 return result; 243 return result;
238 } 244 }
239 245
246 void InitializeMemoryLayout() {
247 // Initialize memory layout
248 constexpr Memory::MemoryLayout layout{Memory::MemoryLayout::GetDefaultLayout()};
249 constexpr std::size_t hid_size{0x40000};
250 constexpr std::size_t font_size{0x1100000};
251 constexpr std::size_t irs_size{0x8000};
252 constexpr std::size_t time_size{0x1000};
253 constexpr PAddr hid_addr{layout.System().StartAddress()};
254 constexpr PAddr font_pa{layout.System().StartAddress() + hid_size};
255 constexpr PAddr irs_addr{layout.System().StartAddress() + hid_size + font_size};
256 constexpr PAddr time_addr{layout.System().StartAddress() + hid_size + font_size + irs_size};
257
258 // Initialize memory manager
259 memory_manager = std::make_unique<Memory::MemoryManager>();
260 memory_manager->InitializeManager(Memory::MemoryManager::Pool::Application,
261 layout.Application().StartAddress(),
262 layout.Application().EndAddress());
263 memory_manager->InitializeManager(Memory::MemoryManager::Pool::Applet,
264 layout.Applet().StartAddress(),
265 layout.Applet().EndAddress());
266 memory_manager->InitializeManager(Memory::MemoryManager::Pool::System,
267 layout.System().StartAddress(),
268 layout.System().EndAddress());
269
270 hid_shared_mem = Kernel::SharedMemory::Create(
271 system.Kernel(), system.DeviceMemory(), nullptr,
272 {hid_addr, hid_size / Memory::PageSize}, Memory::MemoryPermission::None,
273 Memory::MemoryPermission::Read, hid_addr, hid_size, "HID:SharedMemory");
274 font_shared_mem = Kernel::SharedMemory::Create(
275 system.Kernel(), system.DeviceMemory(), nullptr,
276 {font_pa, font_size / Memory::PageSize}, Memory::MemoryPermission::None,
277 Memory::MemoryPermission::Read, font_pa, font_size, "Font:SharedMemory");
278 irs_shared_mem = Kernel::SharedMemory::Create(
279 system.Kernel(), system.DeviceMemory(), nullptr,
280 {irs_addr, irs_size / Memory::PageSize}, Memory::MemoryPermission::None,
281 Memory::MemoryPermission::Read, irs_addr, irs_size, "IRS:SharedMemory");
282 time_shared_mem = Kernel::SharedMemory::Create(
283 system.Kernel(), system.DeviceMemory(), nullptr,
284 {time_addr, time_size / Memory::PageSize}, Memory::MemoryPermission::None,
285 Memory::MemoryPermission::Read, time_addr, time_size, "Time:SharedMemory");
286
287 // Allocate slab heaps
288 user_slab_heap_pages = std::make_unique<Memory::SlabHeap<Memory::Page>>();
289
290 // Initialize slab heaps
291 constexpr u64 user_slab_heap_size{0x3de000};
292 user_slab_heap_pages->Initialize(
293 system.DeviceMemory().GetPointer(Core::DramMemoryMap::SlabHeapBase),
294 user_slab_heap_size);
295 }
296
240 std::atomic<u32> next_object_id{0}; 297 std::atomic<u32> next_object_id{0};
241 std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin}; 298 std::atomic<u64> next_kernel_process_id{Process::InitialKIPIDMin};
242 std::atomic<u64> next_user_process_id{Process::ProcessIDMin}; 299 std::atomic<u64> next_user_process_id{Process::ProcessIDMin};
@@ -271,6 +328,16 @@ struct KernelCore::Impl {
271 std::bitset<Core::Hardware::NUM_CPU_CORES> registered_core_threads; 328 std::bitset<Core::Hardware::NUM_CPU_CORES> registered_core_threads;
272 std::mutex register_thread_mutex; 329 std::mutex register_thread_mutex;
273 330
331 // Kernel memory management
332 std::unique_ptr<Memory::MemoryManager> memory_manager;
333 std::unique_ptr<Memory::SlabHeap<Memory::Page>> user_slab_heap_pages;
334
335 // Shared memory for services
336 std::shared_ptr<Kernel::SharedMemory> hid_shared_mem;
337 std::shared_ptr<Kernel::SharedMemory> font_shared_mem;
338 std::shared_ptr<Kernel::SharedMemory> irs_shared_mem;
339 std::shared_ptr<Kernel::SharedMemory> time_shared_mem;
340
274 // System context 341 // System context
275 Core::System& system; 342 Core::System& system;
276}; 343};
@@ -437,4 +504,52 @@ Core::EmuThreadHandle KernelCore::GetCurrentEmuThreadID() const {
437 return impl->GetCurrentEmuThreadID(); 504 return impl->GetCurrentEmuThreadID();
438} 505}
439 506
507Memory::MemoryManager& KernelCore::MemoryManager() {
508 return *impl->memory_manager;
509}
510
511const Memory::MemoryManager& KernelCore::MemoryManager() const {
512 return *impl->memory_manager;
513}
514
515Memory::SlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() {
516 return *impl->user_slab_heap_pages;
517}
518
519const Memory::SlabHeap<Memory::Page>& KernelCore::GetUserSlabHeapPages() const {
520 return *impl->user_slab_heap_pages;
521}
522
523Kernel::SharedMemory& KernelCore::GetHidSharedMem() {
524 return *impl->hid_shared_mem;
525}
526
527const Kernel::SharedMemory& KernelCore::GetHidSharedMem() const {
528 return *impl->hid_shared_mem;
529}
530
531Kernel::SharedMemory& KernelCore::GetFontSharedMem() {
532 return *impl->font_shared_mem;
533}
534
535const Kernel::SharedMemory& KernelCore::GetFontSharedMem() const {
536 return *impl->font_shared_mem;
537}
538
539Kernel::SharedMemory& KernelCore::GetIrsSharedMem() {
540 return *impl->irs_shared_mem;
541}
542
543const Kernel::SharedMemory& KernelCore::GetIrsSharedMem() const {
544 return *impl->irs_shared_mem;
545}
546
547Kernel::SharedMemory& KernelCore::GetTimeSharedMem() {
548 return *impl->time_shared_mem;
549}
550
551const Kernel::SharedMemory& KernelCore::GetTimeSharedMem() const {
552 return *impl->time_shared_mem;
553}
554
440} // namespace Kernel 555} // namespace Kernel