From 57625177289624051e107578ccfce749a083f51a Mon Sep 17 00:00:00 2001 From: bunnei Date: Thu, 18 Feb 2021 18:38:23 -0800 Subject: hle: kernel: KSystemControl: Update to reflect board-specific behavior. --- src/core/CMakeLists.txt | 3 +- .../kernel/board/nintendo/nx/k_system_control.cpp | 46 ++++++++++++++++++++++ .../kernel/board/nintendo/nx/k_system_control.h | 22 +++++++++++ src/core/hle/kernel/k_system_control.cpp | 42 -------------------- src/core/hle/kernel/k_system_control.h | 18 +++++---- 5 files changed, 81 insertions(+), 50 deletions(-) create mode 100644 src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp create mode 100644 src/core/hle/kernel/board/nintendo/nx/k_system_control.h delete mode 100644 src/core/hle/kernel/k_system_control.cpp (limited to 'src') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 299f1ed13..6cf7ff81f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -141,6 +141,8 @@ add_library(core STATIC hardware_interrupt_manager.h hle/ipc.h hle/ipc_helpers.h + hle/kernel/board/nintendo/nx/k_system_control.cpp + hle/kernel/board/nintendo/nx/k_system_control.h hle/kernel/client_port.cpp hle/kernel/client_port.h hle/kernel/client_session.cpp @@ -198,7 +200,6 @@ add_library(core STATIC hle/kernel/k_spin_lock.h hle/kernel/k_synchronization_object.cpp hle/kernel/k_synchronization_object.h - hle/kernel/k_system_control.cpp hle/kernel/k_system_control.h hle/kernel/k_thread.cpp hle/kernel/k_thread.h diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp new file mode 100644 index 000000000..0f41c4110 --- /dev/null +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.cpp @@ -0,0 +1,46 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "core/hle/kernel/k_system_control.h" + +namespace Kernel::Board::Nintendo::Nx { + +bool KSystemControl::Init::ShouldIncreaseThreadResourceLimit() { + return true; +} + +namespace { +template +u64 GenerateUniformRange(u64 min, u64 max, F f) { + // Handle the case where the difference is too large to represent. + if (max == std::numeric_limits::max() && min == std::numeric_limits::min()) { + return f(); + } + + // Iterate until we get a value in range. + const u64 range_size = ((max + 1) - min); + const u64 effective_max = (std::numeric_limits::max() / range_size) * range_size; + while (true) { + if (const u64 rnd = f(); rnd < effective_max) { + return min + (rnd % range_size); + } + } +} + +} // Anonymous namespace + +u64 KSystemControl::GenerateRandomU64() { + static std::random_device device; + static std::mt19937 gen(device()); + static std::uniform_int_distribution distribution(1, std::numeric_limits::max()); + return distribution(gen); +} + +u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) { + return GenerateUniformRange(min, max, GenerateRandomU64); +} + +} // namespace Kernel::Board::Nintendo::Nx diff --git a/src/core/hle/kernel/board/nintendo/nx/k_system_control.h b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h new file mode 100644 index 000000000..3fde61971 --- /dev/null +++ b/src/core/hle/kernel/board/nintendo/nx/k_system_control.h @@ -0,0 +1,22 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_types.h" + +namespace Kernel::Board::Nintendo::Nx { + +class KSystemControl { +public: + class Init { + public: + static bool ShouldIncreaseThreadResourceLimit(); + }; + + static u64 GenerateRandomRange(u64 min, u64 max); + static u64 GenerateRandomU64(); +}; + +} // namespace Kernel::Board::Nintendo::Nx diff --git a/src/core/hle/kernel/k_system_control.cpp b/src/core/hle/kernel/k_system_control.cpp deleted file mode 100644 index aa1682f69..000000000 --- a/src/core/hle/kernel/k_system_control.cpp +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2021 yuzu Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "core/hle/kernel/k_system_control.h" - -namespace Kernel { - -namespace { -template -u64 GenerateUniformRange(u64 min, u64 max, F f) { - // Handle the case where the difference is too large to represent. - if (max == std::numeric_limits::max() && min == std::numeric_limits::min()) { - return f(); - } - - // Iterate until we get a value in range. - const u64 range_size = ((max + 1) - min); - const u64 effective_max = (std::numeric_limits::max() / range_size) * range_size; - while (true) { - if (const u64 rnd = f(); rnd < effective_max) { - return min + (rnd % range_size); - } - } -} - -} // Anonymous namespace - -u64 KSystemControl::GenerateRandomU64() { - static std::random_device device; - static std::mt19937 gen(device()); - static std::uniform_int_distribution distribution(1, std::numeric_limits::max()); - return distribution(gen); -} - -u64 KSystemControl::GenerateRandomRange(u64 min, u64 max) { - return GenerateUniformRange(min, max, GenerateRandomU64); -} - -} // namespace Kernel diff --git a/src/core/hle/kernel/k_system_control.h b/src/core/hle/kernel/k_system_control.h index 1d5b64ffa..d755082c2 100644 --- a/src/core/hle/kernel/k_system_control.h +++ b/src/core/hle/kernel/k_system_control.h @@ -6,14 +6,18 @@ #include "common/common_types.h" -namespace Kernel { +#define BOARD_NINTENDO_NX + +#ifdef BOARD_NINTENDO_NX -class KSystemControl { -public: - KSystemControl() = default; +#include "core/hle/kernel/board/nintendo/nx/k_system_control.h" - static u64 GenerateRandomRange(u64 min, u64 max); - static u64 GenerateRandomU64(); -}; +namespace Kernel { + +using Kernel::Board::Nintendo::Nx::KSystemControl; } // namespace Kernel + +#else +#error "Unknown board for KSystemControl" +#endif -- cgit v1.2.3