kern: update KSystemControl::InitializePhase1, dynamically scale 39-bit address space regions

This commit is contained in:
Michael Scire 2023-02-21 08:53:17 -07:00 committed by SciresM
parent 6e2dd791b2
commit db510f96c3
5 changed files with 83 additions and 100 deletions

View file

@ -100,23 +100,15 @@ namespace ams::kern {
}
/* System Initialization. */
void KSystemControlBase::InitializePhase1(bool skip_target_system) {
/* Initialize the rng, if we somehow haven't already. */
if (AMS_UNLIKELY(!s_initialized_random_generator)) {
const u64 seed = KHardwareTimer::GetTick();
s_random_generator.Initialize(reinterpret_cast<const u32*>(std::addressof(seed)), sizeof(seed) / sizeof(u32));
s_initialized_random_generator = true;
}
/* Configure KTargetSystem, if we haven't already by an implementation SystemControl. */
if (!skip_target_system) {
void KSystemControlBase::InitializePhase1() {
/* Configure KTargetSystem. */
{
/* Set IsDebugMode. */
{
KTargetSystem::SetIsDebugMode(true);
/* If debug mode, we want to initialize uart logging. */
KTargetSystem::EnableDebugLogging(true);
KDebugLog::Initialize();
}
/* Set Kernel Configuration. */
@ -135,6 +127,20 @@ namespace ams::kern {
}
}
/* Initialize random and resource limit. */
KSystemControlBase::InitializePhase1Base(KHardwareTimer::GetTick());
}
void KSystemControlBase::InitializePhase1Base(u64 seed) {
/* Initialize the rng, if we somehow haven't already. */
if (AMS_UNLIKELY(!s_initialized_random_generator)) {
s_random_generator.Initialize(reinterpret_cast<const u32*>(std::addressof(seed)), sizeof(seed) / sizeof(u32));
s_initialized_random_generator = true;
}
/* Initialize debug logging. */
KDebugLog::Initialize();
/* System ResourceLimit initialization. */
{
/* Construct the resource limit object. */
@ -144,6 +150,19 @@ namespace ams::kern {
/* Set the initial limits. */
const auto [total_memory_size, kernel_memory_size] = KMemoryLayout::GetTotalAndKernelMemorySizes();
/* Update 39-bit address space infos. */
{
/* Heap should be equal to the total memory size, minimum 8 GB, maximum 32 GB. */
/* Alias should be equal to 8 * heap size, maximum 128 GB. */
const size_t heap_size = std::max(std::min(util::AlignUp(total_memory_size, 1_GB), 32_GB), 8_GB);
const size_t alias_size = std::min(heap_size * 8, 128_GB);
/* Set the address space sizes. */
KAddressSpaceInfo::SetAddressSpaceSize(39, KAddressSpaceInfo::Type_Heap, heap_size);
KAddressSpaceInfo::SetAddressSpaceSize(39, KAddressSpaceInfo::Type_Alias, alias_size);
}
const auto &slab_counts = init::GetSlabResourceCounts();
MESOSPHERE_R_ABORT_UNLESS(sys_res_limit.SetLimitValue(ams::svc::LimitableResource_PhysicalMemoryMax, total_memory_size));
MESOSPHERE_R_ABORT_UNLESS(sys_res_limit.SetLimitValue(ams::svc::LimitableResource_ThreadCountMax, slab_counts.num_KThread));