From f07bd0e337164239a2d0a6bb0e420d3cd440e2c6 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 11 Aug 2020 17:09:22 -0700 Subject: [PATCH] kern: correct flushing of init arguments --- .../mesosphere/init/kern_init_arguments_select.hpp | 1 - .../libmesosphere/source/kern_k_memory_layout.cpp | 3 --- .../kernel/source/arch/arm64/init/kern_init_core.cpp | 11 ++++++----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/libraries/libmesosphere/include/mesosphere/init/kern_init_arguments_select.hpp b/libraries/libmesosphere/include/mesosphere/init/kern_init_arguments_select.hpp index 09360267f..46190b021 100644 --- a/libraries/libmesosphere/include/mesosphere/init/kern_init_arguments_select.hpp +++ b/libraries/libmesosphere/include/mesosphere/init/kern_init_arguments_select.hpp @@ -26,6 +26,5 @@ namespace ams::kern::init { KPhysicalAddress GetInitArgumentsAddress(s32 core_id); void SetInitArguments(s32 core_id, KPhysicalAddress address, uintptr_t arg); - void StoreInitArguments(); } diff --git a/libraries/libmesosphere/source/kern_k_memory_layout.cpp b/libraries/libmesosphere/source/kern_k_memory_layout.cpp index dd67370af..ec9a28cbb 100644 --- a/libraries/libmesosphere/source/kern_k_memory_layout.cpp +++ b/libraries/libmesosphere/source/kern_k_memory_layout.cpp @@ -259,9 +259,6 @@ namespace ams::kern { /* Setup the InitArguments. */ SetInitArguments(static_cast(i), core_local_region_start_phys[i], GetInteger(core_l1_ttbr1_phys[i])); } - - /* Ensure the InitArguments are flushed to cache. */ - StoreInitArguments(); } void SetupPoolPartitionMemoryRegions() { diff --git a/mesosphere/kernel/source/arch/arm64/init/kern_init_core.cpp b/mesosphere/kernel/source/arch/arm64/init/kern_init_core.cpp index 1a20ff3c5..8628f5cae 100644 --- a/mesosphere/kernel/source/arch/arm64/init/kern_init_core.cpp +++ b/mesosphere/kernel/source/arch/arm64/init/kern_init_core.cpp @@ -349,6 +349,7 @@ namespace ams::kern::init { } void SetInitArguments(s32 core_id, KPhysicalAddress address, uintptr_t arg) { + /* Set the arguments. */ KInitArguments *init_args = reinterpret_cast(GetInteger(address)); init_args->ttbr0 = cpu::GetTtbr0El1(); init_args->ttbr1 = arg; @@ -361,14 +362,14 @@ namespace ams::kern::init { init_args->entrypoint = reinterpret_cast(::ams::kern::HorizonKernelMain); init_args->argument = static_cast(core_id); init_args->setup_function = reinterpret_cast(::ams::kern::init::StartOtherCore); + + /* Ensure the arguments are written to memory. */ + StoreDataCache(init_args, sizeof(*init_args)); + + /* Save the pointer to the arguments to use as argument upon core wakeup. */ g_init_arguments_phys_addr[core_id] = address; } - - void StoreInitArguments() { - StoreDataCache(g_init_arguments_phys_addr, sizeof(g_init_arguments_phys_addr)); - } - void InitializeDebugRegisters() { /* Determine how many watchpoints and breakpoints we have */ cpu::DebugFeatureRegisterAccessor aa64dfr0;