1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-10 06:01:52 +00:00

meso: use BitPack

This commit is contained in:
Michael Scire 2020-01-02 03:30:10 -08:00
parent 0d8bde6079
commit 43c0e39c34
3 changed files with 23 additions and 16 deletions

View file

@ -33,10 +33,10 @@ namespace ams::kern {
return static_cast<size_t>(config_value & 0x3FFF) << 20;
}
ALWAYS_INLINE u64 GetKernelConfigurationForInit() {
ALWAYS_INLINE util::BitPack32 GetKernelConfigurationForInit() {
u64 value = 0;
smc::init::GetConfig(&value, 1, smc::ConfigItem::KernelConfiguration);
return value;
return util::BitPack32{static_cast<u32>(value)};
}
ALWAYS_INLINE u64 GenerateRandomU64ForInit() {
@ -45,18 +45,14 @@ namespace ams::kern {
return value;
}
ALWAYS_INLINE smc::MemoryMode GetMemoryModeForInit() {
return static_cast<smc::MemoryMode>((GetKernelConfigurationForInit() >> 10) & 0x3);
}
ALWAYS_INLINE size_t GetIntendedMemorySizeForInit() {
switch (GetMemoryModeForInit()) {
case smc::MemoryMode_4GB:
switch (GetKernelConfigurationForInit().Get<smc::KernelConfiguration::MemorySize>()) {
case smc::MemorySize_4GB:
default: /* All invalid modes should go to 4GB. */
return FourGigabytes;
case smc::MemoryMode_6GB:
case smc::MemorySize_6GB:
return SixGigabytes;
case smc::MemoryMode_8GB:
case smc::MemorySize_8GB:
return EightGigabytes;
}
}
@ -75,7 +71,7 @@ namespace ams::kern {
}
bool KSystemControl::Init::ShouldIncreaseThreadResourceLimit() {
return (GetKernelConfigurationForInit() >> 3) & 1;
return GetKernelConfigurationForInit().Get<smc::KernelConfiguration::IncreaseThreadResourceLimit>();
}
/* Randomness for Initialization. */

View file

@ -19,10 +19,10 @@
namespace ams::kern::smc {
/* Types. */
enum MemoryMode {
MemoryMode_4GB = 0,
MemoryMode_6GB = 1,
MemoryMode_8GB = 2,
enum MemorySize {
MemorySize_4GB = 0,
MemorySize_6GB = 1,
MemorySize_8GB = 2,
};
enum class ConfigItem : u32 {
@ -63,6 +63,17 @@ namespace ams::kern::smc {
NotPermitted = 6,
};
struct KernelConfiguration {
using DebugFillMemory = util::BitPack32::Field<0, 1, bool>;
using EnableUserExceptionHandlers = util::BitPack32::Field<DebugFillMemory::Next, 1, bool>;
using EnableUserPmuAccess = util::BitPack32::Field<EnableUserExceptionHandlers::Next, 1, bool>;
using IncreaseThreadResourceLimit = util::BitPack32::Field<EnableUserPmuAccess::Next, 1, bool>;
using Reserved4 = util::BitPack32::Field<IncreaseThreadResourceLimit::Next, 4, u32>;
using UseSecureMonitorPanicCall = util::BitPack32::Field<Reserved4::Next, 1, bool>;
using Reserved9 = util::BitPack32::Field<UseSecureMonitorPanicCall::Next, 7, u32>;
using MemorySize = util::BitPack32::Field<Reserved9::Next, 2, smc::MemorySize>;
};
/* TODO: Rest of Secure Monitor API. */
void NORETURN Panic(u32 color);

View file

@ -50,7 +50,7 @@ namespace ams::util {
using BitPackType = BitPack<IntegralStorageType>;
static_assert(Mask<Index, Count> != 0);
static_assert(std::is_integral<T>::value);
static_assert(std::is_integral<T>::value || std::is_enum<T>::value);
static_assert(!std::is_same<T, bool>::value || Count == 1);
};
private: