* [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version
@ 2012-02-17 16:46 Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 1/4] target-i386: Introduce x86_cpuid_version_set_family() Andreas Färber
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: Andreas Färber @ 2012-02-17 16:46 UTC (permalink / raw)
To: qemu-devel; +Cc: andre.przywara, 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".
Thanks,
Andreas
Cc: Andre Przywara <andre.przywara@amd.com>
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(-)
--
1.7.7
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 1/4] target-i386: Introduce x86_cpuid_version_set_family()
2012-02-17 16:46 [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Andreas Färber
@ 2012-02-17 16:46 ` Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 2/4] target-i386: Introduce x86_cpuid_version_set_model() Andreas Färber
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andreas Färber @ 2012-02-17 16:46 UTC (permalink / raw)
To: qemu-devel; +Cc: andre.przywara, Andreas Färber
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.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
target-i386/cpuid.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index b9bfeaf..598a27c 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -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;
--
1.7.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 2/4] target-i386: Introduce x86_cpuid_version_set_model()
2012-02-17 16:46 [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 1/4] target-i386: Introduce x86_cpuid_version_set_family() Andreas Färber
@ 2012-02-17 16:46 ` Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 3/4] target-i386: Introduce x86_cpuid_version_set_stepping() Andreas Färber
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Andreas Färber @ 2012-02-17 16:46 UTC (permalink / raw)
To: qemu-devel; +Cc: andre.przywara, Andreas Färber
Move 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.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
target-i386/cpuid.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 598a27c..e76a31b 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -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;
--
1.7.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 3/4] target-i386: Introduce x86_cpuid_version_set_stepping()
2012-02-17 16:46 [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 1/4] target-i386: Introduce x86_cpuid_version_set_family() Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 2/4] target-i386: Introduce x86_cpuid_version_set_model() Andreas Färber
@ 2012-02-17 16:46 ` Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 4/4] target-i386: Introduce x86_cpuid_set_model_id() Andreas Färber
2012-02-24 15:31 ` [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Anthony Liguori
4 siblings, 0 replies; 6+ messages in thread
From: Andreas Färber @ 2012-02-17 16:46 UTC (permalink / raw)
To: qemu-devel; +Cc: andre.przywara, Andreas Färber
Move 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.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
target-i386/cpuid.c | 8 +++++++-
1 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index e76a31b..7a99fcd 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -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;
--
1.7.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH 4/4] target-i386: Introduce x86_cpuid_set_model_id()
2012-02-17 16:46 [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Andreas Färber
` (2 preceding siblings ...)
2012-02-17 16:46 ` [Qemu-devel] [PATCH 3/4] target-i386: Introduce x86_cpuid_version_set_stepping() Andreas Färber
@ 2012-02-17 16:46 ` Andreas Färber
2012-02-24 15:31 ` [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Anthony Liguori
4 siblings, 0 replies; 6+ messages in thread
From: Andreas Färber @ 2012-02-17 16:46 UTC (permalink / raw)
To: qemu-devel; +Cc: andre.przywara, Andreas Färber
Move the logic to transform the 48-char model ID into the 12-word model
value into a helper.
Signed-off-by: Andreas Färber <afaerber@suse.de>
---
target-i386/cpuid.c | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/target-i386/cpuid.c b/target-i386/cpuid.c
index 7a99fcd..aa70214 100644
--- a/target-i386/cpuid.c
+++ b/target-i386/cpuid.c
@@ -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;
}
--
1.7.7
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version
2012-02-17 16:46 [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Andreas Färber
` (3 preceding siblings ...)
2012-02-17 16:46 ` [Qemu-devel] [PATCH 4/4] target-i386: Introduce x86_cpuid_set_model_id() Andreas Färber
@ 2012-02-24 15:31 ` Anthony Liguori
4 siblings, 0 replies; 6+ messages in thread
From: Anthony Liguori @ 2012-02-24 15:31 UTC (permalink / raw)
To: Andreas Färber; +Cc: andre.przywara, qemu-devel
On 02/17/2012 10:46 AM, Andreas Färber wrote:
> 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
>
> Thanks,
> Andreas
>
> Cc: Andre Przywara<andre.przywara@amd.com>
>
> 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(-)
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-02-24 15:31 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-17 16:46 [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 1/4] target-i386: Introduce x86_cpuid_version_set_family() Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 2/4] target-i386: Introduce x86_cpuid_version_set_model() Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 3/4] target-i386: Introduce x86_cpuid_version_set_stepping() Andreas Färber
2012-02-17 16:46 ` [Qemu-devel] [PATCH 4/4] target-i386: Introduce x86_cpuid_set_model_id() Andreas Färber
2012-02-24 15:31 ` [Qemu-devel] [PATCH 0/4] target-i386: Helpers for CPUID version Anthony Liguori
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).