From ab8dfe40a05564f35603c44d0a31b07f49988e96 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 2 Jan 2020 18:11:05 -0800 Subject: [PATCH] ams: use bitpack for api version --- .../include/stratosphere/ams/ams_types.hpp | 38 +++++++++++++------ .../source/ams/ams_exosphere_api.cpp | 8 +--- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/libstratosphere/include/stratosphere/ams/ams_types.hpp b/libstratosphere/include/stratosphere/ams/ams_types.hpp index 27f575a8..02667187 100644 --- a/libstratosphere/include/stratosphere/ams/ams_types.hpp +++ b/libstratosphere/include/stratosphere/ams/ams_types.hpp @@ -38,27 +38,41 @@ namespace ams::exosphere { }; #undef AMS_DEFINE_TARGET_FIRMWARE_ENUM - constexpr inline u32 GetVersion(u32 major, u32 minor, u32 micro) { + constexpr ALWAYS_INLINE u32 GetVersion(u32 major, u32 minor, u32 micro) { return (major << 16) | (minor << 8) | (micro); } struct ApiInfo { - u32 major_version; - u32 minor_version; - u32 micro_version; - TargetFirmware target_firmware; - u32 master_key_revision; + using MasterKeyRevision = util::BitPack64::Field<0, 8, u32>; + using TargetFirmwareVersion = util::BitPack64::Field; + using MicroVersion = util::BitPack64::Field; + using MinorVersion = util::BitPack64::Field; + using MajorVersion = util::BitPack64::Field; - constexpr u32 GetVersion() const { - return ::ams::exosphere::GetVersion(this->major_version, this->minor_version, this->micro_version); + util::BitPack64 value; + + constexpr ALWAYS_INLINE u32 GetVersion() const { + return ::ams::exosphere::GetVersion(this->GetMajorVersion(), this->GetMinorVersion(), this->GetMicroVersion()); } - constexpr TargetFirmware GetTargetFirmware() const { - return this->target_firmware; + constexpr ALWAYS_INLINE u32 GetMajorVersion() const { + return this->value.Get(); } - constexpr u32 GetMasterKeyRevision() const { - return this->master_key_revision; + constexpr ALWAYS_INLINE u32 GetMinorVersion() const { + return this->value.Get(); + } + + constexpr ALWAYS_INLINE u32 GetMicroVersion() const { + return this->value.Get(); + } + + constexpr ALWAYS_INLINE TargetFirmware GetTargetFirmware() const { + return this->value.Get(); + } + + constexpr ALWAYS_INLINE u32 GetMasterKeyRevision() const { + return this->value.Get(); } }; diff --git a/libstratosphere/source/ams/ams_exosphere_api.cpp b/libstratosphere/source/ams/ams_exosphere_api.cpp index f1233ec3..5c19ad90 100644 --- a/libstratosphere/source/ams/ams_exosphere_api.cpp +++ b/libstratosphere/source/ams/ams_exosphere_api.cpp @@ -26,13 +26,7 @@ namespace ams::exosphere { R_ASSERT(ResultNotPresent()); } - return ApiInfo{ - .major_version = static_cast((exosphere_cfg >> 0x20) & 0xFF), - .minor_version = static_cast((exosphere_cfg >> 0x18) & 0xFF), - .micro_version = static_cast((exosphere_cfg >> 0x10) & 0xFF), - .target_firmware = static_cast((exosphere_cfg >> 0x08) & 0xFF), - .master_key_revision = static_cast((exosphere_cfg >> 0x00) & 0xFF), - }; + return ApiInfo{ util::BitPack64(exosphere_cfg) }; } void ForceRebootToRcm() {