x86: Rewrite config_default as config_ternary for FPU

config_default was intended to either evaluated to the passed configuration
value, or the a default value if the config didn't exist. For integer values
this does not actually work, and the default value always gets returned.
This commit reimplements the desired functionality as config_ternary, which
takes 3 arguments, a config to switch on and a desired true and false expansion
This commit is contained in:
Adrian Danis 2016-11-25 14:44:08 +11:00
parent fbe5c8457e
commit e7d0a88664
3 changed files with 9 additions and 9 deletions

View file

@ -36,13 +36,13 @@ void switchFpuOwner(user_fpu_state_t *new_owner, word_t cpu);
static inline uint32_t xsave_features_high(void)
{
uint64_t features = config_default(CONFIG_XSAVE_FEATURE_SET, 1);
uint64_t features = config_ternary(CONFIG_XSAVE, CONFIG_XSAVE_FEATURE_SET, 1);
return (uint32_t)(features >> 32);
}
static inline uint32_t xsave_features_low(void)
{
uint64_t features = config_default(CONFIG_XSAVE_FEATURE_SET, 1);
uint64_t features = config_ternary(CONFIG_XSAVE, CONFIG_XSAVE_FEATURE_SET, 1);
return (uint32_t)(features & 0xffffffff);
}

View file

@ -65,12 +65,12 @@
#define _is_set__(comma) _is_set___(comma 1, 0)
#define _is_set___(_, v, ...) v
/* Evalulate the value of a configuration setting, return a default
* if it isn't defined */
#define config_default(macro, default) _config_default(macro, default)
#define _config_default(value, default) _config_default_(_macrotest_##value, value, default)
#define _config_default_(comma, value, default) _config_default__(comma value, default)
#define _config_default__(_, v, ...) v
/* Check the existance of a configuration setting, returning one value if it
* exists and a different one if it does not */
#define config_ternary(macro, true, false) _config_ternary(macro, true, false)
#define _config_ternary(value, true, false) _config_ternary_(_macrotest_##value, true, false)
#define _config_ternary_(comma, true, false) _config_ternary__(comma true, false)
#define _config_ternary__(_, v, ...) v
/** MODIFIES:
FNSPEC

View file

@ -119,7 +119,7 @@ Arch_initFpu(void)
if (config_set(CONFIG_XSAVE)) {
uint64_t xsave_features;
uint32_t xsave_instruction;
uint64_t desired_features = config_default(CONFIG_XSAVE_FEATURE_SET, 1);
uint64_t desired_features = config_ternary(CONFIG_XSAVE, CONFIG_XSAVE_FEATURE_SET, 1);
/* check for XSAVE support */
if (!(x86_cpuid_ecx(1, 0) & BIT(26))) {
printf("XSAVE not supported\n");