Message ID | 1334704279-11708-12-git-send-email-afaerber@suse.de |
---|---|
State | New |
Headers | show |
On Wed, Apr 18, 2012 at 01:11:15AM +0200, Andreas Färber wrote: > Signed-off-by: Andreas Färber <afaerber@suse.de> > --- > target-i386/cpu.c | 17 ++++++++++++++++- > 1 files changed, 16 insertions(+), 1 deletions(-) > > diff --git a/target-i386/cpu.c b/target-i386/cpu.c > index 0c98fcc..cc4f566 100644 > --- a/target-i386/cpu.c > +++ b/target-i386/cpu.c > @@ -711,6 +711,21 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, > env->cpuid_version |= value & 0xf; > } > > +static char *x86_cpuid_get_model_id(Object *obj, Error **errp) > +{ > + X86CPU *cpu = X86_CPU(obj); > + CPUX86State *env = &cpu->env; > + char *value; > + int i; > + > + value = g_malloc(48 + 1); > + for (i = 0; i < 48; i++) { > + value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3)); setter code is a bit difficult to parse but I think we need value[i] &= 0xff here > + } > + value[48] = '\0'; > + return value; > +} > + > static void x86_cpuid_set_model_id(Object *obj, const char *model_id, > Error **errp) > { > @@ -1586,7 +1601,7 @@ static void x86_cpu_initfn(Object *obj) > x86_cpuid_version_get_stepping, > x86_cpuid_version_set_stepping, NULL, NULL, NULL); > object_property_add_str(obj, "model-id", > - NULL, > + x86_cpuid_get_model_id, > x86_cpuid_set_model_id, NULL); > > env->cpuid_apic_id = env->cpu_index; > -- > 1.7.7 > >
On 04/19/2012 06:41 PM, Michael Roth wrote: >> + char *value; >> + int i; >> + >> + value = g_malloc(48 + 1); >> + for (i = 0; i < 48; i++) { >> + value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3)); > > setter code is a bit difficult to parse but I think we need value[i] &= 0xff > here value[i] is a char. Unless you're planning on compiling for a non-POSIX system where char is more than 8 bits, value[i] &= 0xff is a no-op.
On Thu, Apr 19, 2012 at 06:47:57PM -0600, Eric Blake wrote: > On 04/19/2012 06:41 PM, Michael Roth wrote: > > >> + char *value; > >> + int i; > >> + > >> + value = g_malloc(48 + 1); > >> + for (i = 0; i < 48; i++) { > >> + value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3)); > > > > setter code is a bit difficult to parse but I think we need value[i] &= 0xff > > here > > value[i] is a char. Unless you're planning on compiling for a non-POSIX > system where char is more than 8 bits, value[i] &= 0xff is a no-op. Heh, indeed it is. Please disregard :) > > -- > Eric Blake eblake@redhat.com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >
diff --git a/target-i386/cpu.c b/target-i386/cpu.c index 0c98fcc..cc4f566 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -711,6 +711,21 @@ static void x86_cpuid_version_set_stepping(Object *obj, Visitor *v, env->cpuid_version |= value & 0xf; } +static char *x86_cpuid_get_model_id(Object *obj, Error **errp) +{ + X86CPU *cpu = X86_CPU(obj); + CPUX86State *env = &cpu->env; + char *value; + int i; + + value = g_malloc(48 + 1); + for (i = 0; i < 48; i++) { + value[i] = env->cpuid_model[i >> 2] >> (8 * (i & 3)); + } + value[48] = '\0'; + return value; +} + static void x86_cpuid_set_model_id(Object *obj, const char *model_id, Error **errp) { @@ -1586,7 +1601,7 @@ static void x86_cpu_initfn(Object *obj) x86_cpuid_version_get_stepping, x86_cpuid_version_set_stepping, NULL, NULL, NULL); object_property_add_str(obj, "model-id", - NULL, + x86_cpuid_get_model_id, x86_cpuid_set_model_id, NULL); env->cpuid_apic_id = env->cpu_index;
Signed-off-by: Andreas Färber <afaerber@suse.de> --- target-i386/cpu.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-)