Now we have a working '-cpu max', the linux-user-only
'any' CPU is pretty much the same thing, so implement it
that way.
For the moment we don't add any of the extra feature bits
to the system-emulation "max", because we don't set the
ID register bits we would need to to advertise those
features as present.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/cpu.c | 50 +++++++++++++++++++++++----------------------
target/arm/cpu64.c | 59 ++++++++++++++++++++++++++----------------------------
2 files changed, 54 insertions(+), 55 deletions(-)
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index e46ddcc613..c8d3da2140 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -965,9 +965,17 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
ObjectClass *oc;
char *typename;
char **cpuname;
+ const char *cpunamestr;
cpuname = g_strsplit(cpu_model, ",", 1);
- typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpuname[0]);
+ cpunamestr = cpuname[0];
+#ifdef CONFIG_USER_ONLY
+ /* For backwards compatibility usermode emulation allows "-cpu any",
+ * which has the same semantics as "-cpu max".
+ */
+ cpunamestr = "max";
+#endif
+ typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpunamestr);
oc = object_class_by_name(typename);
g_strfreev(cpuname);
g_free(typename);
@@ -1711,29 +1719,23 @@ static void arm_max_initfn(Object *obj)
kvm_arm_set_cpu_features_from_host(cpu);
} else {
cortex_a15_initfn(obj);
- /* In future we might add feature bits here even if the
- * real-world A15 doesn't implement them.
- */
- }
-}
-#endif
-
#ifdef CONFIG_USER_ONLY
-static void arm_any_initfn(Object *obj)
-{
- ARMCPU *cpu = ARM_CPU(obj);
- set_feature(&cpu->env, ARM_FEATURE_V8);
- set_feature(&cpu->env, ARM_FEATURE_VFP4);
- set_feature(&cpu->env, ARM_FEATURE_NEON);
- set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
- set_feature(&cpu->env, ARM_FEATURE_V8_AES);
- set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
- set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
- set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
- set_feature(&cpu->env, ARM_FEATURE_CRC);
- set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
- set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
- cpu->midr = 0xffffffff;
+ /* We don't set these in system emulation mode for the moment,
+ * since we don't correctly set the ID registers to advertise them,
+ */
+ set_feature(&cpu->env, ARM_FEATURE_V8);
+ set_feature(&cpu->env, ARM_FEATURE_VFP4);
+ set_feature(&cpu->env, ARM_FEATURE_NEON);
+ set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
+ set_feature(&cpu->env, ARM_FEATURE_V8_AES);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
+ set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
+ set_feature(&cpu->env, ARM_FEATURE_CRC);
+ set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
+ set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
+#endif
+ }
}
#endif
@@ -1789,7 +1791,7 @@ static const ARMCPUInfo arm_cpus[] = {
{ .name = "max", .initfn = arm_max_initfn },
#endif
#ifdef CONFIG_USER_ONLY
- { .name = "any", .initfn = arm_any_initfn },
+ { .name = "any", .initfn = arm_max_initfn },
#endif
#endif
{ .name = NULL }
diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c
index 9042d3dfd1..3429875787 100644
--- a/target/arm/cpu64.c
+++ b/target/arm/cpu64.c
@@ -226,38 +226,38 @@ static void aarch64_max_initfn(Object *obj)
kvm_arm_set_cpu_features_from_host(cpu);
} else {
aarch64_a57_initfn(obj);
- /* In future we might add feature bits here even if the
- * real-world A57 doesn't implement them.
+#ifdef CONFIG_USER_ONLY
+ /* We don't set these in system emulation mode for the moment,
+ * since we don't correctly set the ID registers to advertise them,
+ * and in some cases they're only available in AArch64 and not AArch32,
+ * whereas the architecture requires them to be present in both if
+ * present in either.
*/
+ set_feature(&cpu->env, ARM_FEATURE_V8);
+ set_feature(&cpu->env, ARM_FEATURE_VFP4);
+ set_feature(&cpu->env, ARM_FEATURE_NEON);
+ set_feature(&cpu->env, ARM_FEATURE_AARCH64);
+ set_feature(&cpu->env, ARM_FEATURE_V8_AES);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SHA512);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SHA3);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SM3);
+ set_feature(&cpu->env, ARM_FEATURE_V8_SM4);
+ set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
+ set_feature(&cpu->env, ARM_FEATURE_CRC);
+ set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
+ set_feature(&cpu->env, ARM_FEATURE_V8_FP16);
+ set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
+ /* For usermode -cpu max we can use a larger and more efficient DCZ
+ * blocksize since we don't have to follow what the hardware does.
+ */
+ cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
+ cpu->dcz_blocksize = 7; /* 512 bytes */
+#endif
}
}
-#ifdef CONFIG_USER_ONLY
-static void aarch64_any_initfn(Object *obj)
-{
- ARMCPU *cpu = ARM_CPU(obj);
-
- set_feature(&cpu->env, ARM_FEATURE_V8);
- set_feature(&cpu->env, ARM_FEATURE_VFP4);
- set_feature(&cpu->env, ARM_FEATURE_NEON);
- set_feature(&cpu->env, ARM_FEATURE_AARCH64);
- set_feature(&cpu->env, ARM_FEATURE_V8_AES);
- set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
- set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
- set_feature(&cpu->env, ARM_FEATURE_V8_SHA512);
- set_feature(&cpu->env, ARM_FEATURE_V8_SHA3);
- set_feature(&cpu->env, ARM_FEATURE_V8_SM3);
- set_feature(&cpu->env, ARM_FEATURE_V8_SM4);
- set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
- set_feature(&cpu->env, ARM_FEATURE_CRC);
- set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
- set_feature(&cpu->env, ARM_FEATURE_V8_FP16);
- set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
- cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */
- cpu->dcz_blocksize = 7; /* 512 bytes */
-}
-#endif
-
typedef struct ARMCPUInfo {
const char *name;
void (*initfn)(Object *obj);
@@ -268,9 +268,6 @@ static const ARMCPUInfo aarch64_cpus[] = {
{ .name = "cortex-a57", .initfn = aarch64_a57_initfn },
{ .name = "cortex-a53", .initfn = aarch64_a53_initfn },
{ .name = "max", .initfn = aarch64_max_initfn },
-#ifdef CONFIG_USER_ONLY
- { .name = "any", .initfn = aarch64_any_initfn },
-#endif
{ .name = NULL }
};
--
2.16.2
On Tue, 6 Mar 2018 12:55:24 +0000
Peter Maydell <peter.maydell@linaro.org> wrote:
> Now we have a working '-cpu max', the linux-user-only
> 'any' CPU is pretty much the same thing, so implement it
> that way.
>
> For the moment we don't add any of the extra feature bits
> to the system-emulation "max", because we don't set the
> ID register bits we would need to to advertise those
> features as present.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> target/arm/cpu.c | 50 +++++++++++++++++++++++----------------------
> target/arm/cpu64.c | 59 ++++++++++++++++++++++++++----------------------------
> 2 files changed, 54 insertions(+), 55 deletions(-)
>
> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
> index e46ddcc613..c8d3da2140 100644
> --- a/target/arm/cpu.c
> +++ b/target/arm/cpu.c
> @@ -965,9 +965,17 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
> ObjectClass *oc;
> char *typename;
> char **cpuname;
> + const char *cpunamestr;
>
> cpuname = g_strsplit(cpu_model, ",", 1);
> - typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpuname[0]);
> + cpunamestr = cpuname[0];
> +#ifdef CONFIG_USER_ONLY
> + /* For backwards compatibility usermode emulation allows "-cpu any",
> + * which has the same semantics as "-cpu max".
> + */
> + cpunamestr = "max";
shouldn't it be
if (!strcmp(cpuname[0], "any")) {
cpunamestr = "max";
}
> +#endif
> + typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpunamestr);
> oc = object_class_by_name(typename);
> g_strfreev(cpuname);
> g_free(typename);
> @@ -1711,29 +1719,23 @@ static void arm_max_initfn(Object *obj)
> kvm_arm_set_cpu_features_from_host(cpu);
> } else {
> cortex_a15_initfn(obj);
> - /* In future we might add feature bits here even if the
> - * real-world A15 doesn't implement them.
> - */
> - }
> -}
> -#endif
> -
> #ifdef CONFIG_USER_ONLY
> -static void arm_any_initfn(Object *obj)
> -{
> - ARMCPU *cpu = ARM_CPU(obj);
> - set_feature(&cpu->env, ARM_FEATURE_V8);
> - set_feature(&cpu->env, ARM_FEATURE_VFP4);
> - set_feature(&cpu->env, ARM_FEATURE_NEON);
> - set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
> - set_feature(&cpu->env, ARM_FEATURE_V8_AES);
> - set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
> - set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
> - set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
> - set_feature(&cpu->env, ARM_FEATURE_CRC);
> - set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
> - set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
> - cpu->midr = 0xffffffff;
> + /* We don't set these in system emulation mode for the moment,
> + * since we don't correctly set the ID registers to advertise them,
> + */
> + set_feature(&cpu->env, ARM_FEATURE_V8);
> + set_feature(&cpu->env, ARM_FEATURE_VFP4);
> + set_feature(&cpu->env, ARM_FEATURE_NEON);
> + set_feature(&cpu->env, ARM_FEATURE_THUMB2EE);
> + set_feature(&cpu->env, ARM_FEATURE_V8_AES);
> + set_feature(&cpu->env, ARM_FEATURE_V8_SHA1);
> + set_feature(&cpu->env, ARM_FEATURE_V8_SHA256);
> + set_feature(&cpu->env, ARM_FEATURE_V8_PMULL);
> + set_feature(&cpu->env, ARM_FEATURE_CRC);
> + set_feature(&cpu->env, ARM_FEATURE_V8_RDM);
> + set_feature(&cpu->env, ARM_FEATURE_V8_FCMA);
> +#endif
> + }
> }
> #endif
>
> @@ -1789,7 +1791,7 @@ static const ARMCPUInfo arm_cpus[] = {
> { .name = "max", .initfn = arm_max_initfn },
> #endif
> #ifdef CONFIG_USER_ONLY
> - { .name = "any", .initfn = arm_any_initfn },
> + { .name = "any", .initfn = arm_max_initfn },
Note,
'any' will disappear from "-cpu help"
but that's probably fine, old users would still be able to use alias
and new ones won't even suspect about its existence and use 'max'.
[...]
On 6 March 2018 at 15:16, Igor Mammedov <imammedo@redhat.com> wrote:
> On Tue, 6 Mar 2018 12:55:24 +0000
> Peter Maydell <peter.maydell@linaro.org> wrote:
>
>> Now we have a working '-cpu max', the linux-user-only
>> 'any' CPU is pretty much the same thing, so implement it
>> that way.
>>
>> For the moment we don't add any of the extra feature bits
>> to the system-emulation "max", because we don't set the
>> ID register bits we would need to to advertise those
>> features as present.
>>
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>> target/arm/cpu.c | 50 +++++++++++++++++++++++----------------------
>> target/arm/cpu64.c | 59 ++++++++++++++++++++++++++----------------------------
>> 2 files changed, 54 insertions(+), 55 deletions(-)
>>
>> diff --git a/target/arm/cpu.c b/target/arm/cpu.c
>> index e46ddcc613..c8d3da2140 100644
>> --- a/target/arm/cpu.c
>> +++ b/target/arm/cpu.c
>> @@ -965,9 +965,17 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)
>> ObjectClass *oc;
>> char *typename;
>> char **cpuname;
>> + const char *cpunamestr;
>>
>> cpuname = g_strsplit(cpu_model, ",", 1);
>> - typename = g_strdup_printf(ARM_CPU_TYPE_NAME("%s"), cpuname[0]);
>> + cpunamestr = cpuname[0];
>> +#ifdef CONFIG_USER_ONLY
>> + /* For backwards compatibility usermode emulation allows "-cpu any",
>> + * which has the same semantics as "-cpu max".
>> + */
>> + cpunamestr = "max";
> shouldn't it be
> if (!strcmp(cpuname[0], "any")) {
> cpunamestr = "max";
> }
Yes. I shuffled the code around a bit and managed to lose the
comparison...
>> @@ -1789,7 +1791,7 @@ static const ARMCPUInfo arm_cpus[] = {
>> { .name = "max", .initfn = arm_max_initfn },
>> #endif
>> #ifdef CONFIG_USER_ONLY
>> - { .name = "any", .initfn = arm_any_initfn },
>> + { .name = "any", .initfn = arm_max_initfn },
> Note,
> 'any' will disappear from "-cpu help"
> but that's probably fine, old users would still be able to use alias
> and new ones won't even suspect about its existence and use 'max'.
Yeah, I guess that's OK.
thanks
-- PMM
© 2016 - 2025 Red Hat, Inc.