kern: pass kernel base from KernelLdr to Kernel

This commit is contained in:
Michael Scire 2024-03-28 00:24:45 -07:00
parent b12e89d0a9
commit c331216f99
5 changed files with 8 additions and 6 deletions

View File

@ -32,6 +32,7 @@ namespace ams::kern {
struct InitialProcessBinaryLayout { struct InitialProcessBinaryLayout {
uintptr_t address; uintptr_t address;
uintptr_t _08; uintptr_t _08;
uintptr_t kern_address;
}; };
struct InitialProcessBinaryLayoutWithSize { struct InitialProcessBinaryLayoutWithSize {

View File

@ -53,7 +53,7 @@ namespace ams::kern {
static size_t GetRealMemorySize(); static size_t GetRealMemorySize();
static size_t GetIntendedMemorySize(); static size_t GetIntendedMemorySize();
static KPhysicalAddress GetKernelPhysicalBaseAddress(KPhysicalAddress base_address); static KPhysicalAddress GetKernelPhysicalBaseAddress(KPhysicalAddress base_address);
static void GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out); static void GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out, KPhysicalAddress kern_base_address);
static bool ShouldIncreaseThreadResourceLimit(); static bool ShouldIncreaseThreadResourceLimit();
static void TurnOnCpu(u64 core_id, const ams::kern::init::KInitArguments *args); static void TurnOnCpu(u64 core_id, const ams::kern::init::KInitArguments *args);
static size_t GetApplicationPoolSize(); static size_t GetApplicationPoolSize();

View File

@ -46,10 +46,11 @@ namespace ams::kern {
} }
} }
void KSystemControlBase::Init::GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out) { void KSystemControlBase::Init::GetInitialProcessBinaryLayout(InitialProcessBinaryLayout *out, KPhysicalAddress kern_base_address) {
*out = { *out = {
.address = GetInteger(KSystemControl::Init::GetKernelPhysicalBaseAddress(ams::kern::MainMemoryAddress)) + KSystemControl::Init::GetIntendedMemorySize() - InitialProcessBinarySizeMax, .address = GetInteger(KSystemControl::Init::GetKernelPhysicalBaseAddress(ams::kern::MainMemoryAddress)) + KSystemControl::Init::GetIntendedMemorySize() - InitialProcessBinarySizeMax,
._08 = 0, ._08 = 0,
.kern_address = GetInteger(kern_base_address),
}; };
} }

View File

@ -345,7 +345,7 @@ namespace ams::kern::init {
MESOSPHERE_INIT_ABORT_UNLESS(slab_region_size <= resource_region_size); MESOSPHERE_INIT_ABORT_UNLESS(slab_region_size <= resource_region_size);
/* Setup the slab region. */ /* Setup the slab region. */
const KPhysicalAddress code_start_phys_addr = init_pt.GetPhysicalAddressOfRandomizedRange(code_start_virt_addr, code_region_size); const KPhysicalAddress code_start_phys_addr = g_phase2_initial_process_binary_meta.layout.kern_address;
const KPhysicalAddress code_end_phys_addr = code_start_phys_addr + code_region_size; const KPhysicalAddress code_end_phys_addr = code_start_phys_addr + code_region_size;
const KPhysicalAddress slab_start_phys_addr = code_end_phys_addr; const KPhysicalAddress slab_start_phys_addr = code_end_phys_addr;
const KPhysicalAddress slab_end_phys_addr = slab_start_phys_addr + slab_region_size; const KPhysicalAddress slab_end_phys_addr = slab_start_phys_addr + slab_region_size;

View File

@ -195,7 +195,7 @@ namespace ams::kern::init::loader {
/* Setup the INI1 header in memory for the kernel. */ /* Setup the INI1 header in memory for the kernel. */
{ {
/* Get the kernel layout. */ /* Get the kernel layout. */
KSystemControl::Init::GetInitialProcessBinaryLayout(std::addressof(g_initial_process_binary_meta.layout)); KSystemControl::Init::GetInitialProcessBinaryLayout(std::addressof(g_initial_process_binary_meta.layout), base_address);
/* If there's no desired base address, use the ini in place. */ /* If there's no desired base address, use the ini in place. */
if (g_initial_process_binary_meta.layout.address == 0) { if (g_initial_process_binary_meta.layout.address == 0) {