2019-12-09 12:57:37 +01:00
|
|
|
/*
|
2020-01-24 11:10:40 +01:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-12-09 12:57:37 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#include <stratosphere.hpp>
|
2020-04-17 07:57:01 +02:00
|
|
|
#include "hos_version_api_private.hpp"
|
2019-12-09 12:57:37 +01:00
|
|
|
|
|
|
|
namespace ams::hos {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
hos::Version g_hos_version;
|
|
|
|
bool g_has_cached;
|
2020-06-15 07:50:08 +02:00
|
|
|
os::SdkMutex g_mutex;
|
2019-12-09 12:57:37 +01:00
|
|
|
|
|
|
|
void CacheValues() {
|
|
|
|
if (__atomic_load_n(&g_has_cached, __ATOMIC_SEQ_CST)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::scoped_lock lk(g_mutex);
|
|
|
|
|
|
|
|
if (g_has_cached) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-07 07:29:07 +02:00
|
|
|
/* Hos version is a direct copy of target firmware, just renamed. */
|
|
|
|
g_hos_version = static_cast<hos::Version>(exosphere::GetApiInfo().GetTargetFirmware());
|
2020-06-15 07:50:08 +02:00
|
|
|
|
|
|
|
/* Ensure that this is a hos version we can sanely *try* to run. */
|
|
|
|
/* To be friendly, we will only require that we recognize the major and minor versions. */
|
2020-06-15 07:59:12 +02:00
|
|
|
/* We can consider only recognizing major in the future, but micro seems safe to ignore as */
|
2020-06-15 07:50:08 +02:00
|
|
|
/* there are no breaking IPC changes in minor updates. */
|
|
|
|
{
|
2020-06-15 07:53:39 +02:00
|
|
|
constexpr u32 MaxMajor = (static_cast<u32>(hos::Version_Max) >> 24) & 0xFF;
|
|
|
|
constexpr u32 MaxMinor = (static_cast<u32>(hos::Version_Max) >> 16) & 0xFF;
|
2020-06-15 07:50:08 +02:00
|
|
|
|
|
|
|
const u32 major = (static_cast<u32>(g_hos_version) >> 24) & 0xFF;
|
|
|
|
const u32 minor = (static_cast<u32>(g_hos_version) >> 16) & 0xFF;
|
|
|
|
|
|
|
|
const bool is_safely_tryable_version = (g_hos_version <= hos::Version_Max) || (major == MaxMajor && minor <= MaxMinor);
|
|
|
|
AMS_ABORT_UNLESS(is_safely_tryable_version);
|
|
|
|
}
|
2019-12-09 12:57:37 +01:00
|
|
|
|
|
|
|
__atomic_store_n(&g_has_cached, true, __ATOMIC_SEQ_CST);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
::ams::hos::Version GetVersion() {
|
|
|
|
CacheValues();
|
|
|
|
return g_hos_version;
|
|
|
|
}
|
|
|
|
|
2020-05-12 00:04:51 +02:00
|
|
|
|
|
|
|
void SetVersionForLibnxInternalDebug(hos::Version debug_version) {
|
|
|
|
std::scoped_lock lk(g_mutex);
|
|
|
|
g_hos_version = debug_version;
|
|
|
|
__atomic_store_n(&g_has_cached, true, __ATOMIC_SEQ_CST);
|
|
|
|
SetVersionForLibnxInternal();
|
|
|
|
}
|
|
|
|
|
2020-04-17 07:57:01 +02:00
|
|
|
void SetVersionForLibnxInternal() {
|
2020-05-07 07:29:07 +02:00
|
|
|
const u32 hos_version_val = static_cast<u32>(hos::GetVersion());
|
|
|
|
const u32 major = (hos_version_val >> 24) & 0xFF;
|
|
|
|
const u32 minor = (hos_version_val >> 16) & 0xFF;
|
|
|
|
const u32 micro = (hos_version_val >> 8) & 0xFF;
|
2019-12-09 12:57:37 +01:00
|
|
|
hosversionSet(MAKEHOSVERSION(major, minor, micro));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|