target-i386: Helpers for CPUID version
cover target-i386: Helpers for CPUID version
Hello x86 gurus,
This series came out of my qom-cpu work. The reasoning is that in a QOM world we will need this logic twice, once as before and once for
-cpu family=x,model=y,stepping=z,model_id=foo.
Note: The family=x value is not bounds-checked in cpu_x86_find_by_name()!
I'd appreciate if someone could double-check the masks I added. I calculated them based on "Intel® Processor Identification and the CPUID Instruction. Application Note 485. January 2011".
Thanks,
Andreas
Andreas Färber (4):
target-i386: Introduce x86_cpuid_version_set_family()
target-i386: Introduce x86_cpuid_version_set_model()
target-i386: Introduce x86_cpuid_version_set_stepping()
target-i386: Introduce x86_cpuid_set_model_id()
target-i386/cpuid.c | 64 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 20 deletions(-)
Signature · 1 line
1.7.7
PATCH 1/4 target-i386: Introduce x86_cpuid_version_set_family()
Move the logic for setting the family and extended family into a helper function.
To make the helper self-contained and in preparation of future unordered/multiple uses, mask out any previous family values first.
--- target-i386/cpuid.c | 15 +++++++++++---- 1 files changed, 11 insertions(+), 4 deletions(-)
target-i386/cpuid.c +11 -4
@@ -597,6 +597,16 @@ static int check_features_against_host(x86_def_t *guest_def)return rv; } +static void x86_cpuid_version_set_family (CPUX86State *env,int family) +{ + env->cpuid_version &= ~0xff00f00 ; +if (family >0x0f ) { + env->cpuid_version |=0xf00 | ((family -0x0f ) <<20 ); + }else { + env->cpuid_version |= family <<8 ; + } +} +static int cpu_x86_find_by_name (x86_def_t *x86_cpu_def,const char *cpu_model) {unsigned int i;
@@ -883,10 +893,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model) } env->cpuid_vendor_override = def->vendor_override; env->cpuid_level = def->level; -if (def->family >0x0f ) - env->cpuid_version =0xf00 | ((def->family -0x0f ) <<20 ); -else - env->cpuid_version = def->family <<8 ; +x86_cpuid_version_set_family (env, def->family); env->cpuid_version |= ((def->model &0xf ) <<4 ) | ((def->model >>4 ) <<16 ); env->cpuid_version |= def->stepping; env->cpuid_features = def->features;
Signature · 1 line
1.7.7
PATCH 2/4 target-i386: Introduce x86_cpuid_version_set_model()
In reply to Andreas FärberMove the logic for setting the model and extended model fields into a helper function.
To make the function self-contained and to prepare for future unordered/multiple uses, mask out any previous model values first.
--- target-i386/cpuid.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
target-i386/cpuid.c +7 -1
@@ -607,6 +607,12 @@ static void x86_cpuid_version_set_family(CPUX86State *env, int family) } } +static void x86_cpuid_version_set_model (CPUX86State *env,int model) +{ + env->cpuid_version &= ~0xf00f0 ; + env->cpuid_version |= ((model &0xf ) <<4 ) | ((model >>4 ) <<16 ); +} +static int cpu_x86_find_by_name (x86_def_t *x86_cpu_def,const char *cpu_model) {unsigned int i;
@@ -894,7 +900,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model) env->cpuid_vendor_override = def->vendor_override; env->cpuid_level = def->level;x86_cpuid_version_set_family (env, def->family); - env->cpuid_version |= ((def->model &0xf ) <<4 ) | ((def->model >>4 ) <<16 ); +x86_cpuid_version_set_model (env, def->model); env->cpuid_version |= def->stepping; env->cpuid_features = def->features; env->cpuid_ext_features = def->ext_features;
Signature · 1 line
1.7.7
PATCH 3/4 target-i386: Introduce x86_cpuid_version_set_stepping()
In reply to Andreas FärberMove the logic for setting the stepping field into a helper function.
To make the function self-contained and to prepare for future unordered/multiple uses, mask out any previous stepping values first.
--- target-i386/cpuid.c | 8 +++++++- 1 files changed, 7 insertions(+), 1 deletions(-)
target-i386/cpuid.c +7 -1
@@ -613,6 +613,12 @@ static void x86_cpuid_version_set_model(CPUX86State *env, int model) env->cpuid_version |= ((model &0xf ) <<4 ) | ((model >>4 ) <<16 ); } +static void x86_cpuid_version_set_stepping (CPUX86State *env,int stepping) +{ + env->cpuid_version &= ~0xf ; + env->cpuid_version |= stepping &0xf ; +} +static int cpu_x86_find_by_name (x86_def_t *x86_cpu_def,const char *cpu_model) {unsigned int i;
@@ -901,7 +907,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model) env->cpuid_level = def->level;x86_cpuid_version_set_family (env, def->family);x86_cpuid_version_set_model (env, def->model); - env->cpuid_version |= def->stepping; +x86_cpuid_version_set_stepping (env, def->stepping); env->cpuid_features = def->features; env->cpuid_ext_features = def->ext_features; env->cpuid_ext2_features = def->ext2_features;
Signature · 1 line
1.7.7
PATCH 4/4 target-i386: Introduce x86_cpuid_set_model_id()
In reply to Andreas FärberMove the logic to transform the 48-char model ID into the 12-word model value into a helper.
--- target-i386/cpuid.c | 33 +++++++++++++++++++-------------- 1 files changed, 19 insertions(+), 14 deletions(-)
target-i386/cpuid.c +19 -14
@@ -619,6 +619,24 @@ static void x86_cpuid_version_set_stepping(CPUX86State *env, int stepping) env->cpuid_version |= stepping &0xf ; } +static void x86_cpuid_set_model_id (CPUX86State *env,const char *model_id) +{ +int c, len, i; + +if (model_id ==NULL ) { + model_id ="" ; + } + len =strlen (model_id); +for (i =0 ; i <48 ; i++) { +if (i >= len) { + c ='\0' ; + }else { + c = (uint8_t )model_id[i]; + } + env->cpuid_model[i >>2 ] |= c << (8 * (i &3 )); + } +} +static int cpu_x86_find_by_name (x86_def_t *x86_cpu_def,const char *cpu_model) {unsigned int i;
@@ -929,20 +947,7 @@ int cpu_x86_register (CPUX86State *env, const char *cpu_model) env->cpuid_ext3_features &=TCG_EXT3_FEATURES ; env->cpuid_svm_features &=TCG_SVM_FEATURES ; } - { -const char *model_id = def->model_id; -int c, len, i; -if (!model_id) - model_id ="" ; - len =strlen (model_id); -for (i =0 ; i <48 ; i++) { -if (i >= len) - c ='\0' ; -else - c = (uint8_t )model_id[i]; - env->cpuid_model[i >>2 ] |= c << (8 * (i &3 )); - } - } +x86_cpuid_set_model_id (env, def->model_id);return 0 ; }
Signature · 1 line
1.7.7
Anthony Liguori
AppliedQuoted 11 lines · Andreas Färber
Hello x86 gurus,
This series came out of my qom-cpu work. The reasoning is that in a QOM world we will need this logic twice, once as before and once for
-cpu family=x,model=y,stepping=z,model_id=foo.Note: The family=x value is not bounds-checked in
cpu_x86_find_by_name()!I'd appreciate if someone could double-check the masks I added. I calculated them based on "Intel® Processor Identification and the CPUID Instruction. Application Note 485. January 2011".
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 15 lines
Thanks,
AndreasCc Andre Przywara<[email protected]>Andreas Färber (4):
target-i386: Introducex86_cpuid_version_set_family()
target-i386: Introducex86_cpuid_version_set_model()
target-i386: Introducex86_cpuid_version_set_stepping()
target-i386: Introducex86_cpuid_set_model_id()target-i386/cpuid.c | 64 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 20 deletions(-)