Skip to content

Commit

Permalink
i386: Replace uint32_t* with FeatureWord on feature getter/setter
Browse files Browse the repository at this point in the history
Instead of passing a pointer to the feature property getter and
setter functions, pass a FeatureWord enum so they can perform
other actions related to the feature flag.

This will be used to add a new "user_features" field to keep
track of features that were explicitly set by the user.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20170327144815.8043-2-ehabkost@redhat.com>
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Tested-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
  • Loading branch information
ehabkost committed Mar 28, 2017
1 parent df90463 commit a7b0ffa
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions target/i386/cpu.c
Expand Up @@ -3692,22 +3692,25 @@ static void x86_cpu_unrealizefn(DeviceState *dev, Error **errp)
}

typedef struct BitProperty {
uint32_t *ptr;
FeatureWord w;
uint32_t mask;
} BitProperty;

static void x86_cpu_get_bit_prop(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
X86CPU *cpu = X86_CPU(obj);
BitProperty *fp = opaque;
bool value = (*fp->ptr & fp->mask) == fp->mask;
uint32_t f = cpu->env.features[fp->w];
bool value = (f & fp->mask) == fp->mask;
visit_type_bool(v, name, &value, errp);
}

static void x86_cpu_set_bit_prop(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
DeviceState *dev = DEVICE(obj);
X86CPU *cpu = X86_CPU(obj);
BitProperty *fp = opaque;
Error *local_err = NULL;
bool value;
Expand All @@ -3724,9 +3727,9 @@ static void x86_cpu_set_bit_prop(Object *obj, Visitor *v, const char *name,
}

if (value) {
*fp->ptr |= fp->mask;
cpu->env.features[fp->w] |= fp->mask;
} else {
*fp->ptr &= ~fp->mask;
cpu->env.features[fp->w] &= ~fp->mask;
}
}

Expand All @@ -3745,7 +3748,7 @@ static void x86_cpu_release_bit_prop(Object *obj, const char *name,
*/
static void x86_cpu_register_bit_prop(X86CPU *cpu,
const char *prop_name,
uint32_t *field,
FeatureWord w,
int bitnr)
{
BitProperty *fp;
Expand All @@ -3755,11 +3758,11 @@ static void x86_cpu_register_bit_prop(X86CPU *cpu,
op = object_property_find(OBJECT(cpu), prop_name, NULL);
if (op) {
fp = op->opaque;
assert(fp->ptr == field);
assert(fp->w == w);
fp->mask |= mask;
} else {
fp = g_new0(BitProperty, 1);
fp->ptr = field;
fp->w = w;
fp->mask = mask;
object_property_add(OBJECT(cpu), prop_name, "bool",
x86_cpu_get_bit_prop,
Expand Down Expand Up @@ -3787,7 +3790,7 @@ static void x86_cpu_register_feature_bit_props(X86CPU *cpu,
/* aliases don't use "|" delimiters anymore, they are registered
* manually using object_property_add_alias() */
assert(!strchr(name, '|'));
x86_cpu_register_bit_prop(cpu, name, &cpu->env.features[w], bitnr);
x86_cpu_register_bit_prop(cpu, name, w, bitnr);
}

static GuestPanicInformation *x86_cpu_get_crash_info(CPUState *cs)
Expand Down

0 comments on commit a7b0ffa

Please sign in to comment.