Delete 16 *_cpu_class_by_name() functions
cover Delete 16 *_cpu_class_by_name() functions
This series adds a new CPUClass::class_name_format field, which allows us to delete 16 of the 21 *_cpu_class_by_name() functions that exist today.
Eduardo Habkost (7):
cpu: Change return type of cpu_class_by_name() to CPUClass
riscv: Don't split CPU model string
arm: Don't split CPU model string
arm: Remove special case for "any" CPU model
cpu: Let architectures set CPU class name format
cpu: Set class name format for some architectures
cpu: Set fixed class name on some architectures
include/qom/cpu.h | 14 +++++++++++++- target/s390x/internal.h | 1 - exec.c | 8 +++----- qom/cpu.c | 20 +++++++++++++++++--- target/arm/cpu.c | 30 +----------------------------- target/hppa/cpu.c | 8 ++------ target/i386/cpu.c | 11 +---------- target/lm32/cpu.c | 17 +---------------- target/m68k/cpu.c | 17 +---------------- target/microblaze/cpu.c | 8 ++------ target/mips/cpu.c | 13 +------------ target/moxie/cpu.c | 17 +---------------- target/nios2/cpu.c | 8 ++------ target/openrisc/cpu.c | 17 +---------------- target/riscv/cpu.c | 20 +------------------- target/s390x/cpu.c | 2 +- target/s390x/cpu_models.c | 20 +++++--------------- target/tilegx/cpu.c | 8 ++------ target/tricore/cpu.c | 17 +---------------- target/unicore32/cpu.c | 17 +---------------- target/xtensa/cpu.c | 17 +---------------- 21 files changed, 58 insertions(+), 232 deletions(-)
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
PATCH 1/7 cpu: Change return type of cpu_class_by_name() to CPUClass
The function always returns a CPU class. Change the return type to reflect that.
I'm not changing the return type of CPUClass::class_by_name() yet, because many of its implementations will be eliminated by the next commits.
---
Cc: Cornelia Huck <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: [email protected]
Cc: Markus Armbruster <[email protected]>
--- include/qom/cpu.h | 2 +- exec.c | 8 +++----- qom/cpu.c | 4 ++-- target/s390x/cpu_models.c | 10 +++++----- 4 files changed, 11 insertions(+), 13 deletions(-)
include/qom/cpu.h +1 -1
@@ -676,7 +676,7 @@ void cpu_reset(CPUState *cpu);* * Returns: A #CPUClass or %NULL if not matching class is found. */ -ObjectClass *cpu_class_by_name (const char *typename,const char *cpu_model); +CPUClass *cpu_class_by_name (const char *typename,const char *cpu_model);/** * cpu_create:
exec.c +3 -5
@@ -984,7 +984,6 @@ void cpu_exec_realizefn(CPUState *cpu, Error **errp)const char *parse_cpu_option (const char *cpu_option) { -ObjectClass *oc;CPUClass *cc;gchar **model_pieces;const char *cpu_type;
@@ -995,15 +994,14 @@ const char *parse_cpu_option(const char *cpu_option)exit (1 ); } - oc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]); -if (oc ==NULL ) { + cc =cpu_class_by_name (CPU_RESOLVING_TYPE , model_pieces[0 ]); +if (cc ==NULL ) {error_report ("unable to find CPU model '%s'" , model_pieces[0 ]);g_strfreev (model_pieces);exit (EXIT_FAILURE ); } - cpu_type =object_class_get_name (oc); - cc =CPU_CLASS (oc); + cpu_type =object_class_get_name (OBJECT_CLASS (cc)); cc->parse_features (cpu_type, model_pieces[1 ], &error_fatal);g_strfreev (model_pieces);return cpu_type;
qom/cpu.c +2 -2
@@ -283,12 +283,12 @@ static bool cpu_common_has_work(CPUState *cs)return false; } -ObjectClass *cpu_class_by_name (const char *typename,const char *cpu_model) +CPUClass *cpu_class_by_name (const char *typename,const char *cpu_model) {CPUClass *cc =CPU_CLASS (object_class_by_name (typename));assert (cpu_model && cc->class_by_name); -return cc->class_by_name (cpu_model); +return CPU_CLASS (cc->class_by_name (cpu_model)); } static void cpu_common_parse_features(const char *typename, char *features,
target/s390x/cpu_models.c +5 -5
@@ -482,7 +482,7 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info,const QDict *qdict =NULL ;const QDictEntry *e;Visitor *visitor; -ObjectClass *oc; +CPUClass *cc;S390CPU *cpu;Object *obj;
@@ -494,16 +494,16 @@ static void cpu_model_from_info(S390CPUModel *model, const CpuModelInfo *info, } } - oc =cpu_class_by_name (TYPE_S390_CPU , info->name); -if (!oc) { + cc =cpu_class_by_name (TYPE_S390_CPU , info->name); +if (!cc) {error_setg (errp,"The CPU definition \'%s\' is unknown." , info->name);return ; } -if (S390_CPU_CLASS (oc)->kvm_required && !kvm_enabled ()) { +if (S390_CPU_CLASS (cc)->kvm_required && !kvm_enabled ()) {error_setg (errp,"The CPU definition '%s' requires KVM" , info->name);return ; } - obj =object_new (object_class_get_name (oc)); + obj =object_new (object_class_get_name (OBJECT_CLASS (cc))); cpu =S390_CPU (obj);if (!cpu->model) {
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
PATCH 2/7 riscv: Don't split CPU model string
In reply to Eduardo HabkostCPUClass::class_by_name is called after the CPU model name and options were already split, there's no need to split the string again.
---
Cc: Palmer Dabbelt <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Sagar Karandikar <[email protected]>
Cc: Bastian Koppelmann <[email protected]>
Cc: [email protected]
--- target/riscv/cpu.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
target/riscv/cpu.c +1 -4
@@ -179,12 +179,9 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) {ObjectClass *oc;char *typename; -char **cpuname; - cpuname =g_strsplit (cpu_model,"," ,1 ); - typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpuname[0 ]); + typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename); -g_strfreev (cpuname);g_free (typename);if (!oc || !object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) ||object_class_is_abstract (oc)) {
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Re: [Qemu-devel] [PATCH 2/7] riscv: Don't split CPU model string
Quoted 6 lines · Eduardo Habkost
CPUClass::class_by_nameis called after the CPU model name and options were already split, there's no need to split the string again.Signed-off-by Eduardo Habkost <[email protected]>
Alistair
Quoted 32 lines
---
Cc: Palmer Dabbelt <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Sagar Karandikar <[email protected]>
Cc: Bastian Koppelmann <[email protected]>
Cc: [email protected]--- target/riscv/cpu.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)target/riscv/cpu.c +1
-5@@ -179,12 +179,9 @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) {ObjectClass *oc;char *typename; -char **cpuname; - cpuname =g_strsplit (cpu_model,"," ,1 ); - typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpuname[0 ]); + typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename); -g_strfreev (cpuname);g_free (typename);if (!oc || !object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) ||object_class_is_abstract (oc)) { --2.18.0.rc1.1.g3f1ff2140
PATCH 3/7 arm: Don't split CPU model string
In reply to Eduardo HabkostCPUClass::class_by_name is called after the CPU model name and options were already split, there's no need to split the string again.
---
Cc: Greg Bellows <[email protected]>
Cc: Peter Maydell <[email protected]>
Cc: [email protected]
--- target/arm/cpu.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
target/arm/cpu.c +3 -8
@@ -1212,22 +1212,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 ); - cpunamestr = cpuname[0 ];#ifdef CONFIG_USER_ONLY /* For backwards compatibility usermode emulation allows "-cpu any", * which has the same semantics as "-cpu max". */ -if (!strcmp (cpunamestr,"any" )) { - cpunamestr ="max" ; +if (!strcmp (cpu_model,"any" )) { + cpu_model ="max" ; }#endif - typename =g_strdup_printf (ARM_CPU_TYPE_NAME ("%s" ), cpunamestr); + typename =g_strdup_printf (ARM_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename); -g_strfreev (cpuname);g_free (typename);if (!oc || !object_class_dynamic_cast (oc,TYPE_ARM_CPU ) ||object_class_is_abstract (oc)) {
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
PATCH 4/7 arm: Remove special case for "any" CPU model
In reply to Eduardo HabkostWe already have an entry for "any" at arm_cpus[], which makes a "any-arm-cpu" QOM type be registered. This means the regular QOM type name lookup code already works and there's no need for a special case.
---
Cc: Peter Maydell <[email protected]>
Cc: [email protected]
--- target/arm/cpu.c | 8 -------- 1 file changed, 8 deletions(-)
target/arm/cpu.c +0 -8
@@ -1213,14 +1213,6 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model)ObjectClass *oc;char *typename; -#ifdef CONFIG_USER_ONLY -/* For backwards compatibility usermode emulation allows "-cpu any", -* which has the same semantics as "-cpu max". -*/ -if (!strcmp (cpu_model,"any" )) { - cpu_model ="max" ; - } -#endif typename =g_strdup_printf (ARM_CPU_TYPE_NAME ("%s" ), cpu_model); oc =object_class_by_name (typename);g_free (typename);
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
PATCH 5/7 cpu: Let architectures set CPU class name format
In reply to Eduardo HabkostInstead of requiring every architecture to implement a class_by_name function, let them set a format string at CPUClass::class_name_format.
This will let us get rid of at least 16 class_by_name functions in the next commits.
--- include/qom/cpu.h | 12 ++++++++++++ qom/cpu.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)
include/qom/cpu.h +12 -0
@@ -163,7 +163,19 @@ typedef struct CPUClass {DeviceClass parent_class;/*< public >*/ +/* The following fields configure CPU model name -> QOM type translation: */ + +/* +* arch-specific CPU model -> QOM type translation function. +* Optional if @class_name_format is set. +*/ ObjectClass *(*class_by_name)(const char *cpu_model); +/* +* Format string for g_strdup_printf(), used to generate the CPU +* class name. +*/ +const char *class_name_format; +void (*parse_features)(const char *typename,char *str,Error **errp);void (*reset)(CPUState *cpu);
qom/cpu.c +16 -2
@@ -286,9 +286,23 @@ static bool cpu_common_has_work(CPUState *cs)CPUClass *cpu_class_by_name (const char *typename,const char *cpu_model) {CPUClass *cc =CPU_CLASS (object_class_by_name (typename)); +ObjectClass *oc; +char *class_name; -assert (cpu_model && cc->class_by_name); -return CPU_CLASS (cc->class_by_name (cpu_model)); +assert (cpu_model); +if (cc->class_by_name) { +return CPU_CLASS (cc->class_by_name (cpu_model)); + } + +assert (cc->class_name_format); + class_name =g_strdup_printf (cc->class_name_format, cpu_model); + oc =object_class_by_name (class_name); +g_free (class_name); +if (!oc || !object_class_dynamic_cast (oc, typename) || +object_class_is_abstract (oc)) { +return NULL ; + } +return CPU_CLASS (oc); } static void cpu_common_parse_features(const char *typename, char *features,
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Re: [Qemu-devel] [PATCH 5/7] cpu: Let architectures set CPU class name format
Quoted 21 lines · Eduardo Habkost
Instead of requiring every architecture to implement a
class_by_namefunction, let them set a format string atCPUClass::class_name_format.This will let us get rid of at least 16
class_by_namefunctions in the next commits.Signed-off-by Eduardo Habkost <[email protected]>--- include/qom/cpu.h | 12 ++++++++++++ qom/cpu.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/qom/cpu.h +0
-0@@ -163,7 +163,19 @@ typedef struct CPUClass {DeviceClass parent_class;/*< public >*/
include/qom/cpu.h typedef struct CPUClass { · line 175
Quoted 10 lines
include/qom/cpu.h +9
-0+/* The following fields configure CPU model name -> QOM type translation: */ + +/* +* arch-specific CPU model -> QOM type translation function. +* Optional if @class_name_format is set. +*/ ObjectClass *(*class_by_name)(const char *cpu_model); +/* +* Format string for g_strdup_printf(), used to generate the CPU +* class name.
Please document acceptable conversion specifiers.
Quoted 16 lines
include/qom/cpu.h +3
-0+*/ +const char *class_name_format; +void (*parse_features)(const char *typename,char *str,Error **errp);void (*reset)(CPUState *cpu);qom/cpu.c +2
-0@@ -286,9 +286,23 @@ static bool cpu_common_has_work(CPUState *cs)CPUClass *cpu_class_by_name (const char *typename,const char *cpu_model) {CPUClass *cc =CPU_CLASS (object_class_by_name (typename)); +ObjectClass *oc; +char *class_name;
qom/cpu.c static bool cpu_common_has_work(CPUState *cs) · line 298
Quoted 10 lines
qom/cpu.c +7
-2-assert (cpu_model && cc->class_by_name); -return CPU_CLASS (cc->class_by_name (cpu_model)); +assert (cpu_model); +if (cc->class_by_name) { +return CPU_CLASS (cc->class_by_name (cpu_model)); + } + +assert (cc->class_name_format); + class_name =g_strdup_printf (cc->class_name_format, cpu_model);
Defeats -Wformat. Triggers -Wformat-nonliteral, which we don't use, I presume. Observation, not objection.
cc->class_name_format must contain exactly one conversion specifier, which must take a char *.
Quoted 10 lines
qom/cpu.c +7
-0+ oc =object_class_by_name (class_name); +g_free (class_name); +if (!oc || !object_class_dynamic_cast (oc, typename) || +object_class_is_abstract (oc)) { +return NULL ; + } +return CPU_CLASS (oc); } static void cpu_common_parse_features(const char *typename, char *features,
Re: [Qemu-devel] [PATCH 5/7] cpu: Let architectures set CPU class name format
Quoted 66 lines · Markus Armbruster
Quoted 21 lines · Eduardo Habkost
Instead of requiring every architecture to implement a
class_by_namefunction, let them set a format string atCPUClass::class_name_format.This will let us get rid of at least 16
class_by_namefunctions in the next commits.Signed-off-by Eduardo Habkost <[email protected]>--- include/qom/cpu.h | 12 ++++++++++++ qom/cpu.c | 18 ++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-)include/qom/cpu.h +0
-0@@ -163,7 +163,19 @@ typedef struct CPUClass {DeviceClass parent_class;/*< public >*/ include/qom/cpu.h typedef struct CPUClass { · line 175
Quoted 10 lines
include/qom/cpu.h +9
-0+/* The following fields configure CPU model name -> QOM type translation: */ + +/* +* arch-specific CPU model -> QOM type translation function. +* Optional if @class_name_format is set. +*/ ObjectClass *(*class_by_name)(const char *cpu_model); +/* +* Format string for g_strdup_printf(), used to generate the CPU +* class name. Please document acceptable conversion specifiers.
Quoted 16 lines
include/qom/cpu.h +3
-0+*/ +const char *class_name_format; +void (*parse_features)(const char *typename,char *str,Error **errp);void (*reset)(CPUState *cpu);qom/cpu.c +2
-0@@ -286,9 +286,23 @@ static bool cpu_common_has_work(CPUState *cs)CPUClass *cpu_class_by_name (const char *typename,const char *cpu_model) {CPUClass *cc =CPU_CLASS (object_class_by_name (typename)); +ObjectClass *oc; +char *class_name;qom/cpu.c static bool cpu_common_has_work(CPUState *cs) · line 298
Quoted 10 lines
qom/cpu.c +7
-2-assert (cpu_model && cc->class_by_name); -return CPU_CLASS (cc->class_by_name (cpu_model)); +assert (cpu_model); +if (cc->class_by_name) { +return CPU_CLASS (cc->class_by_name (cpu_model)); + } + +assert (cc->class_name_format); + class_name =g_strdup_printf (cc->class_name_format, cpu_model);Defeats -Wformat. Triggers -Wformat-nonliteral, which we don't use, I presume. Observation, not objection.
Quoted 2 lines
cc->class_name_formatmust contain exactly one conversion specifier, which must take a char *.
s/exactly one/at most one/
PATCH 7 defines formats without a conversion specifier.
Quoted 10 lines
Quoted 10 lines
qom/cpu.c +7
-0+ oc =object_class_by_name (class_name); +g_free (class_name); +if (!oc || !object_class_dynamic_cast (oc, typename) || +object_class_is_abstract (oc)) { +return NULL ; + } +return CPU_CLASS (oc); } static void cpu_common_parse_features(const char *typename, char *features,
PATCH 6/7 cpu: Set class name format for some architectures
In reply to Eduardo HabkostSet CPUClass::class_name_format for 12 architectures that simply generate a class name using g_strdup_printf(): arm, i386, lm32, m68k, mips, moxie, openrisc, riscv, s390x, tricore, unicore32, xtensa.
---
Cc: Peter Maydell <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: Laurent Vivier <[email protected]>
Cc: Aurelien Jarno <[email protected]>
Cc: Aleksandar Markovic <[email protected]>
Cc: Aleksandar Rikalo <[email protected]>
Cc: Anthony Green <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Sagar Karandikar <[email protected]>
Cc: Bastian Koppelmann <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
--- target/s390x/internal.h | 1 - target/arm/cpu.c | 17 +---------------- target/i386/cpu.c | 11 +---------- target/lm32/cpu.c | 17 +---------------- target/m68k/cpu.c | 17 +---------------- target/mips/cpu.c | 13 +------------ target/moxie/cpu.c | 17 +---------------- target/openrisc/cpu.c | 17 +---------------- target/riscv/cpu.c | 17 +---------------- target/s390x/cpu.c | 2 +- target/s390x/cpu_models.c | 10 ---------- target/tricore/cpu.c | 17 +---------------- target/unicore32/cpu.c | 17 +---------------- target/xtensa/cpu.c | 17 +---------------- 14 files changed, 12 insertions(+), 178 deletions(-)
target/s390x/internal.h +0 -1
@@ -256,7 +256,6 @@ static inline void s390_cpu_unhalt(S390CPU *cpu)void s390_cpu_model_register_props (Object *obj);void s390_cpu_model_class_register_props (ObjectClass *oc);void s390_realize_cpu_model (CPUState *cs,Error **errp); -ObjectClass *s390_cpu_class_by_name (const char *name);/* excp_helper.c */
target/arm/cpu.c +1 -16
@@ -1208,21 +1208,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) acc->parent_realize (dev, errp); } -static ObjectClass *arm_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (ARM_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_ARM_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -/* CPU models. These are not needed for the AArch64 linux-user build. */ #if !defined(CONFIG_USER_ONLY ) || !defined(TARGET_AARCH64 )
@@ -2142,7 +2127,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) acc->parent_reset = cc->reset; cc->reset = arm_cpu_reset; - cc->class_by_name = arm_cpu_class_by_name; + cc->class_name_format =ARM_CPU_TYPE_NAME ("%s" ); cc->has_work = arm_cpu_has_work; cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; cc->dump_state = arm_cpu_dump_state;
target/i386/cpu.c +1 -10
@@ -1391,15 +1391,6 @@ static char *x86_cpu_type_name(const char *model_name)return g_strdup_printf (X86_CPU_TYPE_NAME ("%s" ), model_name); } -static ObjectClass *x86_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename =x86_cpu_type_name (cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -return oc; -} -static char *x86_cpu_class_get_model_name (X86CPUClass *cc) {const char *class_name =object_class_get_name (OBJECT_CLASS (cc));
@@ -5851,7 +5842,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->reset = x86_cpu_reset; cc->reset_dump_flags =CPU_DUMP_FPU |CPU_DUMP_CCOP ; - cc->class_by_name = x86_cpu_class_by_name; + cc->class_name_format =X86_CPU_TYPE_NAME ("%s" ); cc->parse_features = x86_cpu_parse_featurestr; cc->has_work = x86_cpu_has_work;#ifdef CONFIG_TCG
target/lm32/cpu.c +1 -16
@@ -201,21 +201,6 @@ static void lm32_full_cpu_initfn(Object *obj) | LM32_FEATURE_CYCLE_COUNT; } -static ObjectClass *lm32_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (LM32_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_LM32_CPU ) || -object_class_is_abstract (oc))) { - oc =NULL ; - } -return oc; -} -static void lm32_cpu_class_init (ObjectClass *oc,void *data) {LM32CPUClass *lcc =LM32_CPU_CLASS (oc);
@@ -227,7 +212,7 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) lcc->parent_reset = cc->reset; cc->reset = lm32_cpu_reset; - cc->class_by_name = lm32_cpu_class_by_name; + cc->class_name_format =LM32_CPU_TYPE_NAME ("%s" ); cc->has_work = lm32_cpu_has_work; cc->do_interrupt = lm32_cpu_do_interrupt; cc->cpu_exec_interrupt = lm32_cpu_exec_interrupt;
target/m68k/cpu.c +1 -16
@@ -81,21 +81,6 @@ static void m68k_cpu_disas_set_info(CPUState *s, disassemble_info *info)/* CPU models */ -static ObjectClass *m68k_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (M68K_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (object_class_dynamic_cast (oc,TYPE_M68K_CPU ) ==NULL || -object_class_is_abstract (oc))) { -return NULL ; - } -return oc; -} -static void m5206_cpu_initfn (Object *obj) {M68kCPU *cpu =M68K_CPU (obj);
@@ -261,7 +246,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = m68k_cpu_reset; - cc->class_by_name = m68k_cpu_class_by_name; + cc->class_name_format =M68K_CPU_TYPE_NAME ("%s" ); cc->has_work = m68k_cpu_has_work; cc->do_interrupt = m68k_cpu_do_interrupt; cc->cpu_exec_interrupt = m68k_cpu_exec_interrupt;
target/mips/cpu.c +1 -12
@@ -166,17 +166,6 @@ static char *mips_cpu_type_name(const char *cpu_model)return g_strdup_printf (MIPS_CPU_TYPE_NAME ("%s" ), cpu_model); } -static ObjectClass *mips_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =mips_cpu_type_name (cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -return oc; -} -static void mips_cpu_class_init (ObjectClass *c,void *data) {MIPSCPUClass *mcc =MIPS_CPU_CLASS (c);
@@ -188,7 +177,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = mips_cpu_reset; - cc->class_by_name = mips_cpu_class_by_name; + cc->class_name_format =MIPS_CPU_TYPE_NAME ("%s" ); cc->has_work = mips_cpu_has_work; cc->do_interrupt = mips_cpu_do_interrupt; cc->cpu_exec_interrupt = mips_cpu_exec_interrupt;
target/moxie/cpu.c +1 -16
@@ -80,21 +80,6 @@ static void moxie_cpu_initfn(Object *obj) cs->env_ptr = &cpu->env; } -static ObjectClass *moxie_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (MOXIE_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_MOXIE_CPU ) || -object_class_is_abstract (oc))) { -return NULL ; - } -return oc; -} -static void moxie_cpu_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -106,7 +91,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) mcc->parent_reset = cc->reset; cc->reset = moxie_cpu_reset; - cc->class_by_name = moxie_cpu_class_by_name; + cc->class_name_format =MOXIE_CPU_TYPE_NAME ("%s" ); cc->has_work = moxie_cpu_has_work; cc->do_interrupt = moxie_cpu_do_interrupt;
target/openrisc/cpu.c +1 -16
@@ -99,21 +99,6 @@ static void openrisc_cpu_initfn(Object *obj)/* CPU models */ -static ObjectClass *openrisc_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (OPENRISC_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_OPENRISC_CPU ) || -object_class_is_abstract (oc))) { -return NULL ; - } -return oc; -} -static void or1200_initfn (Object *obj) {OpenRISCCPU *cpu =OPENRISC_CPU (obj);
@@ -140,7 +125,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) occ->parent_reset = cc->reset; cc->reset = openrisc_cpu_reset; - cc->class_by_name = openrisc_cpu_class_by_name; + cc->class_name_format =OPENRISC_CPU_TYPE_NAME ("%s" ); cc->has_work = openrisc_cpu_has_work; cc->do_interrupt = openrisc_cpu_do_interrupt; cc->cpu_exec_interrupt = openrisc_cpu_exec_interrupt;
target/riscv/cpu.c +1 -16
@@ -175,21 +175,6 @@ static void rv64imacu_nommu_cpu_init(Object *obj)#endif -static ObjectClass *riscv_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -static void riscv_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function cpu_fprintf,int flags) {
@@ -335,7 +320,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = riscv_cpu_reset; - cc->class_by_name = riscv_cpu_class_by_name; + cc->class_name_format =RISCV_CPU_TYPE_NAME ("%s" ); cc->has_work = riscv_cpu_has_work; cc->do_interrupt = riscv_cpu_do_interrupt; cc->cpu_exec_interrupt = riscv_cpu_exec_interrupt;
target/s390x/cpu.c +1 -1
@@ -461,7 +461,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) scc->cpu_reset = s390_cpu_reset; scc->initial_cpu_reset = s390_cpu_initial_reset; cc->reset = s390_cpu_full_reset; - cc->class_by_name = s390_cpu_class_by_name, + cc->class_name_format =S390_CPU_TYPE_NAME ("%s" ); cc->has_work = s390_cpu_has_work;#ifdef CONFIG_TCG cc->do_interrupt = s390_cpu_do_interrupt;
target/s390x/cpu_models.c +0 -10
@@ -1278,16 +1278,6 @@ static char *s390_base_cpu_type_name(const char *model_name)return g_strdup_printf (S390_CPU_TYPE_NAME ("%s-base" ), model_name); } -ObjectClass *s390_cpu_class_by_name (const char *name) -{ -char *typename =s390_cpu_type_name (name); -ObjectClass *oc; - - oc =object_class_by_name (typename); -g_free (typename); -return oc; -} -static const TypeInfo qemu_s390_cpu_type_info = { .name =S390_CPU_TYPE_NAME ("qemu" ), .parent =TYPE_S390_CPU ,
target/tricore/cpu.c +1 -16
@@ -111,21 +111,6 @@ static void tricore_cpu_initfn(Object *obj) cs->env_ptr = env; } -static ObjectClass *tricore_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (TRICORE_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_TRICORE_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -static void tc1796_initfn (Object *obj) {TriCoreCPU *cpu =TRICORE_CPU (obj);
@@ -158,7 +143,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = tricore_cpu_reset; - cc->class_by_name = tricore_cpu_class_by_name; + cc->class_name_format =TRICORE_CPU_TYPE_NAME ("%s" ); cc->has_work = tricore_cpu_has_work; cc->dump_state = tricore_cpu_dump_state;
target/unicore32/cpu.c +1 -16
@@ -40,21 +40,6 @@ static inline void set_feature(CPUUniCore32State *env, int feature)/* CPU models */ -static ObjectClass *uc32_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (UNICORE32_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_UNICORE32_CPU ) || -object_class_is_abstract (oc))) { - oc =NULL ; - } -return oc; -} -static void unicore_ii_cpu_initfn (Object *obj) {UniCore32CPU *cpu =UNICORE32_CPU (obj);
@@ -132,7 +117,7 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)device_class_set_parent_realize (dc, uc32_cpu_realizefn, &ucc->parent_realize); - cc->class_by_name = uc32_cpu_class_by_name; + cc->class_name_format =UNICORE32_CPU_TYPE_NAME ("%s" ); cc->has_work = uc32_cpu_has_work; cc->do_interrupt = uc32_cpu_do_interrupt; cc->cpu_exec_interrupt = uc32_cpu_exec_interrupt;
target/xtensa/cpu.c +1 -16
@@ -90,21 +90,6 @@ static void xtensa_cpu_reset(CPUState *s)#endif } -static ObjectClass *xtensa_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (XTENSA_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc ==NULL || !object_class_dynamic_cast (oc,TYPE_XTENSA_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -static void xtensa_cpu_disas_set_info (CPUState *cs,disassemble_info *info) {XtensaCPU *cpu =XTENSA_CPU (cs);
@@ -172,7 +157,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) xcc->parent_reset = cc->reset; cc->reset = xtensa_cpu_reset; - cc->class_by_name = xtensa_cpu_class_by_name; + cc->class_name_format =XTENSA_CPU_TYPE_NAME ("%s" ); cc->has_work = xtensa_cpu_has_work; cc->do_interrupt = xtensa_cpu_do_interrupt; cc->cpu_exec_interrupt = xtensa_cpu_exec_interrupt;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Re: [Qemu-devel] [PATCH 6/7] cpu: Set class name format for some architectures
Quoted 22 lines · Eduardo Habkost
Set
CPUClass::class_name_formatfor 12 architectures that simply generate a class name usingg_strdup_printf(): arm, i386, lm32, m68k, mips, moxie, openrisc, riscv, s390x, tricore, unicore32, xtensa.Signed-off-by Eduardo Habkost <[email protected]>---
Cc: Peter Maydell <[email protected]>
Cc: Paolo Bonzini <[email protected]>
Cc: Richard Henderson <[email protected]>
Cc: Eduardo Habkost <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: Laurent Vivier <[email protected]>
Cc: Aurelien Jarno <[email protected]>
Cc: Aleksandar Markovic <[email protected]>
Cc: Aleksandar Rikalo <[email protected]>
Cc: Anthony Green <[email protected]>
Cc: Stafford Horne <[email protected]>
Cc: Palmer Dabbelt <[email protected]>
Cc: Alistair Francis <[email protected]>
Cc: Sagar Karandikar <[email protected]>
Quoted 8 lines
Cc: Bastian Koppelmann <[email protected]>
Cc: Cornelia Huck <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Guan Xuetao <[email protected]>
Cc: Max Filippov <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
For RISC-V:
Alistair
Quoted 442 lines
--- target/s390x/internal.h | 1 - target/arm/cpu.c | 17 +---------------- target/i386/cpu.c | 11 +---------- target/lm32/cpu.c | 17 +---------------- target/m68k/cpu.c | 17 +---------------- target/mips/cpu.c | 13 +------------ target/moxie/cpu.c | 17 +---------------- target/openrisc/cpu.c | 17 +---------------- target/riscv/cpu.c | 17 +---------------- target/s390x/cpu.c | 2 +- target/s390x/cpu_models.c | 10 ---------- target/tricore/cpu.c | 17 +---------------- target/unicore32/cpu.c | 17 +---------------- target/xtensa/cpu.c | 17 +---------------- 14 files changed, 12 insertions(+), 178 deletions(-)target/s390x/internal.h +0
-1@@ -256,7 +256,6 @@ static inline void s390_cpu_unhalt(S390CPU *cpu)void s390_cpu_model_register_props (Object *obj);void s390_cpu_model_class_register_props (ObjectClass *oc);void s390_realize_cpu_model (CPUState *cs,Error **errp); -ObjectClass *s390_cpu_class_by_name (const char *name);/* excp_helper.c */ target/arm/cpu.c +1
-16@@ -1208,21 +1208,6 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) acc->parent_realize (dev, errp); } -static ObjectClass *arm_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (ARM_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_ARM_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -/* CPU models. These are not needed for the AArch64 linux-user build. */ #if !defined(CONFIG_USER_ONLY ) || !defined(TARGET_AARCH64 )@@ -2142,7 +2127,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) acc->parent_reset = cc->reset; cc->reset = arm_cpu_reset; - cc->class_by_name = arm_cpu_class_by_name; + cc->class_name_format =ARM_CPU_TYPE_NAME ("%s" ); cc->has_work = arm_cpu_has_work; cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; cc->dump_state = arm_cpu_dump_state;target/i386/cpu.c +1
-10@@ -1391,15 +1391,6 @@ static char *x86_cpu_type_name(const char *model_name)return g_strdup_printf (X86_CPU_TYPE_NAME ("%s" ), model_name); } -static ObjectClass *x86_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename =x86_cpu_type_name (cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -return oc; -} -static char *x86_cpu_class_get_model_name (X86CPUClass *cc) {const char *class_name =object_class_get_name (OBJECT_CLASS (cc));@@ -5851,7 +5842,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data) cc->reset = x86_cpu_reset; cc->reset_dump_flags =CPU_DUMP_FPU |CPU_DUMP_CCOP ; - cc->class_by_name = x86_cpu_class_by_name; + cc->class_name_format =X86_CPU_TYPE_NAME ("%s" ); cc->parse_features = x86_cpu_parse_featurestr; cc->has_work = x86_cpu_has_work;#ifdef CONFIG_TCG target/lm32/cpu.c +1
-16@@ -201,21 +201,6 @@ static void lm32_full_cpu_initfn(Object *obj) | LM32_FEATURE_CYCLE_COUNT; } -static ObjectClass *lm32_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (LM32_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_LM32_CPU ) || -object_class_is_abstract (oc))) { - oc =NULL ; - } -return oc; -} -static void lm32_cpu_class_init (ObjectClass *oc,void *data) {LM32CPUClass *lcc =LM32_CPU_CLASS (oc);@@ -227,7 +212,7 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data) lcc->parent_reset = cc->reset; cc->reset = lm32_cpu_reset; - cc->class_by_name = lm32_cpu_class_by_name; + cc->class_name_format =LM32_CPU_TYPE_NAME ("%s" ); cc->has_work = lm32_cpu_has_work; cc->do_interrupt = lm32_cpu_do_interrupt; cc->cpu_exec_interrupt = lm32_cpu_exec_interrupt;target/m68k/cpu.c +1
-16@@ -81,21 +81,6 @@ static void m68k_cpu_disas_set_info(CPUState *s, disassemble_info *info)/* CPU models */ -static ObjectClass *m68k_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (M68K_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (object_class_dynamic_cast (oc,TYPE_M68K_CPU ) ==NULL || -object_class_is_abstract (oc))) { -return NULL ; - } -return oc; -} -static void m5206_cpu_initfn (Object *obj) {M68kCPU *cpu =M68K_CPU (obj);@@ -261,7 +246,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = m68k_cpu_reset; - cc->class_by_name = m68k_cpu_class_by_name; + cc->class_name_format =M68K_CPU_TYPE_NAME ("%s" ); cc->has_work = m68k_cpu_has_work; cc->do_interrupt = m68k_cpu_do_interrupt; cc->cpu_exec_interrupt = m68k_cpu_exec_interrupt;target/mips/cpu.c +1
-12@@ -166,17 +166,6 @@ static char *mips_cpu_type_name(const char *cpu_model)return g_strdup_printf (MIPS_CPU_TYPE_NAME ("%s" ), cpu_model); } -static ObjectClass *mips_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =mips_cpu_type_name (cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -return oc; -} -static void mips_cpu_class_init (ObjectClass *c,void *data) {MIPSCPUClass *mcc =MIPS_CPU_CLASS (c);@@ -188,7 +177,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = mips_cpu_reset; - cc->class_by_name = mips_cpu_class_by_name; + cc->class_name_format =MIPS_CPU_TYPE_NAME ("%s" ); cc->has_work = mips_cpu_has_work; cc->do_interrupt = mips_cpu_do_interrupt; cc->cpu_exec_interrupt = mips_cpu_exec_interrupt;target/moxie/cpu.c +1
-16@@ -80,21 +80,6 @@ static void moxie_cpu_initfn(Object *obj) cs->env_ptr = &cpu->env; } -static ObjectClass *moxie_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (MOXIE_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_MOXIE_CPU ) || -object_class_is_abstract (oc))) { -return NULL ; - } -return oc; -} -static void moxie_cpu_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);@@ -106,7 +91,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data) mcc->parent_reset = cc->reset; cc->reset = moxie_cpu_reset; - cc->class_by_name = moxie_cpu_class_by_name; + cc->class_name_format =MOXIE_CPU_TYPE_NAME ("%s" ); cc->has_work = moxie_cpu_has_work; cc->do_interrupt = moxie_cpu_do_interrupt;target/openrisc/cpu.c +1
-16@@ -99,21 +99,6 @@ static void openrisc_cpu_initfn(Object *obj)/* CPU models */ -static ObjectClass *openrisc_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (OPENRISC_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_OPENRISC_CPU ) || -object_class_is_abstract (oc))) { -return NULL ; - } -return oc; -} -static void or1200_initfn (Object *obj) {OpenRISCCPU *cpu =OPENRISC_CPU (obj);@@ -140,7 +125,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data) occ->parent_reset = cc->reset; cc->reset = openrisc_cpu_reset; - cc->class_by_name = openrisc_cpu_class_by_name; + cc->class_name_format =OPENRISC_CPU_TYPE_NAME ("%s" ); cc->has_work = openrisc_cpu_has_work; cc->do_interrupt = openrisc_cpu_do_interrupt; cc->cpu_exec_interrupt = openrisc_cpu_exec_interrupt;target/riscv/cpu.c +1
-16@@ -175,21 +175,6 @@ static void rv64imacu_nommu_cpu_init(Object *obj)#endif -static ObjectClass *riscv_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (RISCV_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_RISCV_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -static void riscv_cpu_dump_state (CPUState *cs,FILE *f,fprintf_function cpu_fprintf,int flags) {@@ -335,7 +320,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = riscv_cpu_reset; - cc->class_by_name = riscv_cpu_class_by_name; + cc->class_name_format =RISCV_CPU_TYPE_NAME ("%s" ); cc->has_work = riscv_cpu_has_work; cc->do_interrupt = riscv_cpu_do_interrupt; cc->cpu_exec_interrupt = riscv_cpu_exec_interrupt;target/s390x/cpu.c +1
-1@@ -461,7 +461,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data) scc->cpu_reset = s390_cpu_reset; scc->initial_cpu_reset = s390_cpu_initial_reset; cc->reset = s390_cpu_full_reset; - cc->class_by_name = s390_cpu_class_by_name, + cc->class_name_format =S390_CPU_TYPE_NAME ("%s" ); cc->has_work = s390_cpu_has_work;#ifdef CONFIG_TCG cc->do_interrupt = s390_cpu_do_interrupt;target/s390x/cpu_models.c +0
-10@@ -1278,16 +1278,6 @@ static char *s390_base_cpu_type_name(const char *model_name)return g_strdup_printf (S390_CPU_TYPE_NAME ("%s-base" ), model_name); } -ObjectClass *s390_cpu_class_by_name (const char *name) -{ -char *typename =s390_cpu_type_name (name); -ObjectClass *oc; - - oc =object_class_by_name (typename); -g_free (typename); -return oc; -} -static const TypeInfo qemu_s390_cpu_type_info = { .name =S390_CPU_TYPE_NAME ("qemu" ), .parent =TYPE_S390_CPU ,target/tricore/cpu.c +1
-16@@ -111,21 +111,6 @@ static void tricore_cpu_initfn(Object *obj) cs->env_ptr = env; } -static ObjectClass *tricore_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (TRICORE_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (!oc || !object_class_dynamic_cast (oc,TYPE_TRICORE_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -static void tc1796_initfn (Object *obj) {TriCoreCPU *cpu =TRICORE_CPU (obj);@@ -158,7 +143,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) mcc->parent_reset = cc->reset; cc->reset = tricore_cpu_reset; - cc->class_by_name = tricore_cpu_class_by_name; + cc->class_name_format =TRICORE_CPU_TYPE_NAME ("%s" ); cc->has_work = tricore_cpu_has_work; cc->dump_state = tricore_cpu_dump_state;target/unicore32/cpu.c +1
-16@@ -40,21 +40,6 @@ static inline void set_feature(CPUUniCore32State *env, int feature)/* CPU models */ -static ObjectClass *uc32_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (UNICORE32_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc !=NULL && (!object_class_dynamic_cast (oc,TYPE_UNICORE32_CPU ) || -object_class_is_abstract (oc))) { - oc =NULL ; - } -return oc; -} -static void unicore_ii_cpu_initfn (Object *obj) {UniCore32CPU *cpu =UNICORE32_CPU (obj);@@ -132,7 +117,7 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)device_class_set_parent_realize (dc, uc32_cpu_realizefn, &ucc->parent_realize); - cc->class_by_name = uc32_cpu_class_by_name; + cc->class_name_format =UNICORE32_CPU_TYPE_NAME ("%s" ); cc->has_work = uc32_cpu_has_work; cc->do_interrupt = uc32_cpu_do_interrupt; cc->cpu_exec_interrupt = uc32_cpu_exec_interrupt;target/xtensa/cpu.c +1
-17@@ -90,21 +90,6 @@ static void xtensa_cpu_reset(CPUState *s)#endif } -static ObjectClass *xtensa_cpu_class_by_name (const char *cpu_model) -{ -ObjectClass *oc; -char *typename; - - typename =g_strdup_printf (XTENSA_CPU_TYPE_NAME ("%s" ), cpu_model); - oc =object_class_by_name (typename); -g_free (typename); -if (oc ==NULL || !object_class_dynamic_cast (oc,TYPE_XTENSA_CPU ) || -object_class_is_abstract (oc)) { -return NULL ; - } -return oc; -} -static void xtensa_cpu_disas_set_info (CPUState *cs,disassemble_info *info) {XtensaCPU *cpu =XTENSA_CPU (cs);@@ -172,7 +157,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data) xcc->parent_reset = cc->reset; cc->reset = xtensa_cpu_reset; - cc->class_by_name = xtensa_cpu_class_by_name; + cc->class_name_format =XTENSA_CPU_TYPE_NAME ("%s" ); cc->has_work = xtensa_cpu_has_work; cc->do_interrupt = xtensa_cpu_do_interrupt; cc->cpu_exec_interrupt = xtensa_cpu_exec_interrupt; --2.18.0.rc1.1.g3f1ff2140
PATCH 7/7 cpu: Set fixed class name on some architectures
In reply to Eduardo Habkosthppa, microblaze, nios2, and tilegx have a fixed class name being returned by CPUClass::class_by_name. We can implement the same behavior by setting CPUClass::class_name_format.
---
Cc: Richard Henderson <[email protected]>
Cc: "Edgar E. Iglesias" <[email protected]>
Cc: Chris Wulff <[email protected]>
Cc: Marek Vasut <[email protected]>
--- target/hppa/cpu.c | 8 ++------ target/microblaze/cpu.c | 8 ++------ target/nios2/cpu.c | 8 ++------ target/tilegx/cpu.c | 8 ++------ 4 files changed, 8 insertions(+), 24 deletions(-)
target/hppa/cpu.c +2 -6
@@ -144,11 +144,6 @@ static void hppa_cpu_initfn(Object *obj)cpu_hppa_put_psw (env,PSW_W ); } -static ObjectClass *hppa_cpu_class_by_name (const char *cpu_model) -{ -return object_class_by_name (TYPE_HPPA_CPU ); -} -static void hppa_cpu_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -158,7 +153,8 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)device_class_set_parent_realize (dc, hppa_cpu_realizefn, &acc->parent_realize); - cc->class_by_name = hppa_cpu_class_by_name; +/* All CPU model names are translated to the same QOM class */ + cc->class_name_format =TYPE_HPPA_CPU ; cc->has_work = hppa_cpu_has_work; cc->do_interrupt = hppa_cpu_do_interrupt; cc->cpu_exec_interrupt = hppa_cpu_exec_interrupt;
target/microblaze/cpu.c +2 -6
@@ -280,11 +280,6 @@ static Property mb_properties[] = { DEFINE_PROP_END_OF_LIST(), }; -static ObjectClass *mb_cpu_class_by_name (const char *cpu_model) -{ -return object_class_by_name (TYPE_MICROBLAZE_CPU ); -} -static void mb_cpu_class_init (ObjectClass *oc,void *data) {DeviceClass *dc =DEVICE_CLASS (oc);
@@ -296,7 +291,8 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data) mcc->parent_reset = cc->reset; cc->reset = mb_cpu_reset; - cc->class_by_name = mb_cpu_class_by_name; +/* All CPU model names are translated to the same QOM class */ + cc->class_name_format =TYPE_MICROBLAZE_CPU ; cc->has_work = mb_cpu_has_work; cc->do_interrupt = mb_cpu_do_interrupt; cc->cpu_exec_interrupt = mb_cpu_exec_interrupt;
target/nios2/cpu.c +2 -6
@@ -77,11 +77,6 @@ static void nios2_cpu_initfn(Object *obj)#endif } -static ObjectClass *nios2_cpu_class_by_name (const char *cpu_model) -{ -return object_class_by_name (TYPE_NIOS2_CPU ); -} -static void nios2_cpu_realizefn (DeviceState *dev,Error **errp) {CPUState *cs =CPU (dev);
@@ -193,7 +188,8 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data) ncc->parent_reset = cc->reset; cc->reset = nios2_cpu_reset; - cc->class_by_name = nios2_cpu_class_by_name; +/* All CPU model names are translated to the same QOM class */ + cc->class_name_format =TYPE_NIOS2_CPU ; cc->has_work = nios2_cpu_has_work; cc->do_interrupt = nios2_cpu_do_interrupt; cc->cpu_exec_interrupt = nios2_cpu_exec_interrupt;
target/tilegx/cpu.c +2 -6
@@ -51,11 +51,6 @@ static void tilegx_cpu_dump_state(CPUState *cs, FILE *f, env->pc, env->spregs[TILEGX_SPR_CMPEXCH]); } -static ObjectClass *tilegx_cpu_class_by_name (const char *cpu_model) -{ -return object_class_by_name (TYPE_TILEGX_CPU ); -} -static void tilegx_cpu_set_pc (CPUState *cs,vaddr value) {TileGXCPU *cpu =TILEGX_CPU (cs);
@@ -146,7 +141,8 @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data) tcc->parent_reset = cc->reset; cc->reset = tilegx_cpu_reset; - cc->class_by_name = tilegx_cpu_class_by_name; +/* All CPU model names are translated to the same QOM class */ + cc->class_name_format =TYPE_TILEGX_CPU ; cc->has_work = tilegx_cpu_has_work; cc->do_interrupt = tilegx_cpu_do_interrupt; cc->cpu_exec_interrupt = tilegx_cpu_exec_interrupt;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Quoted 3 lines · Eduardo Habkost
This series adds a new
CPUClass::class_name_formatfield, which allows us to delete 16 of the 21*_cpu_class_by_name()functions that exist today.
Which five remain, and why?
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Eduardo Habkost
This series adds a new
CPUClass::class_name_formatfield, which allows us to delete 16 of the 21*_cpu_class_by_name()functions that exist today.Which five remain, and why?
alpha_cpu_class_by_name:
* Translates aliases based on alpha_cpu_aliases;
* Falls back to "ev67" unconditionally
(there's a "TODO: remove match everything nonsense" comment).
cris_cpu_class_by_name:
* Translates "any" alias to "crisv32" if CONFIG_USER_ONLY.
ppc_cpu_class_by_name:
* Supports lookup by PVR if CPU model is a 8 digit hex number;
* Converts CPU model to lowercase.
superh_cpu_class_by_name:
* Translates "any" alias to TYPE_SH7750R_CPU.
sparc_cpu_class_by_name:
* Replaces whitespaces with '-' on CPU model name.
Signature · 1 line
Eduardo
Quoted 21 lines · Eduardo Habkost
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Eduardo Habkost
This series adds a new
CPUClass::class_name_formatfield, which allows us to delete 16 of the 21*_cpu_class_by_name()functions that exist today.Which five remain, and why?
alpha_cpu_class_by_name:
* Translates aliases based onalpha_cpu_aliases;
* Falls back to "ev67" unconditionally
(there's a "TODO: remove match everything nonsense" comment).
cris_cpu_class_by_name:
* Translates "any" alias to "crisv32" ifCONFIG_USER_ONLY.
ppc_cpu_class_by_name:
* Supports lookup by PVR if CPU model is a 8 digit hex number;
* Converts CPU model to lowercase.
Quoted 5 lines
superh_cpu_class_by_name:
* Translates "any" alias toTYPE_SH7750R_CPU.
sparc_cpu_class_by_name:
* Replaces whitespaces with '-' on CPU model name.
I'm of course asking because I wonder whether we can dumb down this CPU naming business to something simpler and more regular.
Let's review what we have.
For all <TARGET> in target/*:
* arm i386 lm32 m68k mips moxie openrisc riscv s390x s390x tricore unicore32 xtensa
CPU type name format is <TARGET>_CPU_TYPE_NAME("%s"), which boils down to:
- arm lm32 m68k moxie riscv s390x tricore unicore32 xtensa
"%s-<TARGET>-cpu"
- openrisc
"%s-or1k-cpu"
- i386
"%s-x86_64-cpu" #ifdef TARGET_X86_64
"%s-i386-cpu" #else- mips
"%s-mips64-cpu" #ifdef TARGET_MIPS64
"%s-mips-cpu" #elseThe %s gets replaced by the user's cpu model.
* hppa microblaze nios2 tilegx
CPU type name format is <TARGET>-cpu. The user's cpu model seems silently ignored.
* alpha cris ppc sh4 sparc
No format, using ->class_by_name()
- alpha
CPU type name format is "%s-alpha-cpu".
alpha_cpu_class_by_name() recognizes the full name, the full name without "-alpha-cpu" suffix, and a bunch of aliases.
- cris
CPU type name format is "%s-cris-cpu".
cris_cpu_class_by_name() recognizes the name without the "-cris-cpu" suffix, plus "any" as alias for "crisv32-cris-cpu" #ifdef CONFIG_USER_ONLY (this is the default CPU type for machine "axis-dev88"; the other machine "none" has no default).
- ppc
CPU type name format is
"%s-powerpc64-cpu" #ifdef TARGET_PPC64
"%s-powerpc-cpu" #else
ppc_cpu_class_by_name() recognizes the name without the suffix, plus the CPU type's PVR (8 digit hex number), plus a bunch of (case insensitive) aliases.
- sh4
CPU type name format is "%s-superh-cpu".
superh_cpu_class_by_name() recognizes the name without the suffix, plus "any" as alias for "sh7750r-superh-cpu" (this is the default CPU type for machine "shix"; machines "r2d" defaults to "sh7751r", and "none" has no default).
- sparc
CPU type name format is
"%s-sparc64-cpu" #ifdef TARGET_SPARC64
"%s-sparc-cpu" #else
sparc_cpu_class_by_name() recognizes the name without the suffix, mapping any spaces in the user's cpu model to '-'.
Observations:
* The CPU type name format is generally "%s-T-cpu", where T is either <TARGET> or <TARGET>64.
Exceptions:
- openrisc, sh4 uses or1k, superh instead. Looks pointless to me.
- i386 uses x86_64 instead of i38664. Makes sense.
- hppa, microblaze, nios2 and tilegx use CPU type name format "T-cpu", ignoring the user's cpu model. These exceptions looks pointless to me.
* The user's CPU model is generally the "%s" part of the format.
Exceptions:
- alpha additionaly recognizes full type names. If that's useful for alpha (I'm not sure it is), why isn't it useful for all other targets?
- cris and sh4 additionaly recognize an "any" alias, cris only #ifdef CONFIG_USER_ONLY.
Until PATCH 4, arm also recognizes an "any" alias #ifdef CONFIG_USER_ONLY. PATCH 4 drops that, because it's redundant with the "any" CPU, which is a copy instead of an alias. Sure we want to do have different targets do "any" in different ways?
See aliases below.
- ppc additionaly recognizes PVR aliases and additional (case insensitive) aliases. Feels overengineered to me. See aliases below.
- sparc additionally recognizes aliases with ' ' instead of '-'. Feels pointless to me. See aliases below.
* What about deprecating pointless exceptions?
* Aliases
We have several targets roll their own CPU name aliases code. Assuming aliases are here to stay (i.e. we're not deprecating all of them): what about letting each CPU type specify a set of aliases, so we can recognize them in generic code?
Quoted 23 lines · Markus Armbruster
Quoted 21 lines · Eduardo Habkost
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Eduardo Habkost
This series adds a new
CPUClass::class_name_formatfield, which allows us to delete 16 of the 21*_cpu_class_by_name()functions that exist today.Which five remain, and why?
alpha_cpu_class_by_name:
* Translates aliases based onalpha_cpu_aliases;
* Falls back to "ev67" unconditionally
(there's a "TODO: remove match everything nonsense" comment).
cris_cpu_class_by_name:
* Translates "any" alias to "crisv32" ifCONFIG_USER_ONLY.
ppc_cpu_class_by_name:
* Supports lookup by PVR if CPU model is a 8 digit hex number;
* Converts CPU model to lowercase.
Quoted 8 lines
Quoted 5 lines
superh_cpu_class_by_name:
* Translates "any" alias toTYPE_SH7750R_CPU.
sparc_cpu_class_by_name:
* Replaces whitespaces with '-' on CPU model name.I'm of course asking because I wonder whether we can dumb down this CPU naming business to something simpler and more regular.
We can, but that's not on my list of priorities. Any volunteers?
Quoted 1 line
[...]
Quoted 6 lines
* Aliases
We have several targets roll their own CPU name aliases code. Assuming aliases are here to stay (i.e. we're not deprecating all of them): what about letting each CPU type specify a set of aliases, so we can recognize them in generic code?
Yes. I considered adding alias support to generic code, but decided to do this one step at a time.
Signature · 1 line
Eduardo
Quoted 27 lines · Eduardo Habkost
Quoted 26 lines · Markus Armbruster
Quoted 24 lines · Eduardo Habkost
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Eduardo Habkost
This series adds a new
CPUClass::class_name_formatfield, which allows us to delete 16 of the 21*_cpu_class_by_name()functions that exist today.Which five remain, and why?
alpha_cpu_class_by_name:
* Translates aliases based onalpha_cpu_aliases;
* Falls back to "ev67" unconditionally
(there's a "TODO: remove match everything nonsense" comment).
cris_cpu_class_by_name:
* Translates "any" alias to "crisv32" ifCONFIG_USER_ONLY.
ppc_cpu_class_by_name:
* Supports lookup by PVR if CPU model is a 8 digit hex number;
* Converts CPU model to lowercase.
superh_cpu_class_by_name:
* Translates "any" alias toTYPE_SH7750R_CPU.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
sparc_cpu_class_by_name:
* Replaces whitespaces with '-' on CPU model name.I'm of course asking because I wonder whether we can dumb down this CPU naming business to something simpler and more regular.
We can, but that's not on my list of priorities. Any volunteers?
Fair enough. Except for...
Quoted 33 lines
Quoted 1 line
[...]
Quoted 31 lines
Observations:
* The CPU type name format is generally "%s-T-cpu", where T is either <TARGET> or <TARGET>64.
Exceptions:
- openrisc, sh4 uses or1k, superh instead. Looks pointless to me.
- i386 uses
x86_64instead of i38664. Makes sense.- hppa, microblaze, nios2 and tilegx use CPU type name format "T-cpu", ignoring the user's cpu model. These exceptions looks pointless to me.
* The user's CPU model is generally the "%s" part of the format.
Exceptions:
- alpha additionaly recognizes full type names. If that's useful for alpha (I'm not sure it is), why isn't it useful for all other targets?
- cris and sh4 additionaly recognize an "any" alias, cris only #ifdef
CONFIG_USER_ONLY.Until PATCH 4, arm also recognizes an "any" alias #ifdef
CONFIG_USER_ONLY. PATCH 4 drops that, because it's redundant with the "any" CPU, which is a copy instead of an alias. Sure we want to do have different targets do "any" in different ways?
Quoted 8 lines
Quoted 8 lines
See aliases below.
- ppc additionaly recognizes PVR aliases and additional (case insensitive) aliases. Feels overengineered to me. See aliases below.
- sparc additionally recognizes aliases with ' ' instead of '-'. Feels pointless to me. See aliases below.
... this, perhaps:
Quoted 1 line
Quoted 1 line
* What about deprecating pointless exceptions?
Deprecating unwanted stuff now is likely to make a later cleanup so much easier.
Quoted 9 lines
Quoted 6 lines
* Aliases
We have several targets roll their own CPU name aliases code. Assuming aliases are here to stay (i.e. we're not deprecating all of them): what about letting each CPU type specify a set of aliases, so we can recognize them in generic code?
Yes. I considered adding alias support to generic code, but decided to do this one step at a time.
Okay. Consider adding suitable TODO comments.
Quoted 144 lines · On Wed, 08 May 2019 10:34:44 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 21 lines · Eduardo Habkost
Quoted 7 lines · Markus Armbruster
Quoted 3 lines · Eduardo Habkost
This series adds a new
CPUClass::class_name_formatfield, which allows us to delete 16 of the 21*_cpu_class_by_name()functions that exist today.Which five remain, and why?
alpha_cpu_class_by_name:
* Translates aliases based onalpha_cpu_aliases;
* Falls back to "ev67" unconditionally
(there's a "TODO: remove match everything nonsense" comment).
cris_cpu_class_by_name:
* Translates "any" alias to "crisv32" ifCONFIG_USER_ONLY.
ppc_cpu_class_by_name:
* Supports lookup by PVR if CPU model is a 8 digit hex number;
* Converts CPU model to lowercase.Quoted 5 lines
superh_cpu_class_by_name:
* Translates "any" alias toTYPE_SH7750R_CPU.
sparc_cpu_class_by_name:
* Replaces whitespaces with '-' on CPU model name.I'm of course asking because I wonder whether we can dumb down this CPU naming business to something simpler and more regular.
Let's review what we have.
For all <TARGET> in target/*:
* arm i386 lm32 m68k mips moxie openrisc riscv s390x s390x tricore unicore32 xtensa
CPU type name format is <TARGET>_CPU_TYPE_NAME("%s"), which boils down to:
- arm lm32 m68k moxie riscv s390x tricore unicore32 xtensa
"%s-<TARGET>-cpu"- openrisc
"%s-or1k-cpu"- i386
"%s-x86_64-cpu" #ifdef TARGET_X86_64 "%s-i386-cpu" #else- mips
"%s-mips64-cpu" #ifdef TARGET_MIPS64 "%s-mips-cpu" #elseThe %s gets replaced by the user's cpu model.
* hppa microblaze nios2 tilegx
CPU type name format is <TARGET>-cpu. The user's cpu model seems silently ignored.
* alpha cris ppc sh4 sparc
No format, using ->class_by_name()
- alpha
CPU type name format is "%s-alpha-cpu".
alpha_cpu_class_by_name()recognizes the full name, the full name without "-alpha-cpu" suffix, and a bunch of aliases.- cris
CPU type name format is "%s-cris-cpu".
cris_cpu_class_by_name()recognizes the name without the "-cris-cpu" suffix, plus "any" as alias for "crisv32-cris-cpu" #ifdefCONFIG_USER_ONLY(this is the default CPU type for machine "axis-dev88"; the other machine "none" has no default).- ppc
CPU type name format is
"%s-powerpc64-cpu" #ifdefTARGET_PPC64
"%s-powerpc-cpu" #else
ppc_cpu_class_by_name()recognizes the name without the suffix, plus the CPU type's PVR (8 digit hex number), plus a bunch of (case insensitive) aliases.- sh4
CPU type name format is "%s-superh-cpu".
superh_cpu_class_by_name()recognizes the name without the suffix, plus "any" as alias for "sh7750r-superh-cpu" (this is the default CPU type for machine "shix"; machines "r2d" defaults to "sh7751r", and "none" has no default).- sparc
CPU type name format is
"%s-sparc64-cpu" #ifdefTARGET_SPARC64
"%s-sparc-cpu" #else
sparc_cpu_class_by_name()recognizes the name without the suffix, mapping any spaces in the user's cpu model to '-'.Observations:
* The CPU type name format is generally "%s-T-cpu", where T is either <TARGET> or <TARGET>64.
Exceptions:
- openrisc, sh4 uses or1k, superh instead. Looks pointless to me.
- i386 uses
x86_64instead of i38664. Makes sense.- hppa, microblaze, nios2 and tilegx use CPU type name format "T-cpu", ignoring the user's cpu model. These exceptions looks pointless to me.
* The user's CPU model is generally the "%s" part of the format.
Exceptions:
- alpha additionaly recognizes full type names. If that's useful for alpha (I'm not sure it is), why isn't it useful for all other targets?
- cris and sh4 additionaly recognize an "any" alias, cris only #ifdef
CONFIG_USER_ONLY.Until PATCH 4, arm also recognizes an "any" alias #ifdef
CONFIG_USER_ONLY. PATCH 4 drops that, because it's redundant with the "any" CPU, which is a copy instead of an alias. Sure we want to do have different targets do "any" in different ways?See aliases below.
Quoted 8 lines
- ppc additionaly recognizes PVR aliases and additional (case insensitive) aliases. Feels overengineered to me. See aliases below.
- sparc additionally recognizes aliases with ' ' instead of '-'. Feels pointless to me. See aliases below.
* What about deprecating pointless exceptions?
Last time I was refactoring all this CPU name thingy, there wasn't way to deprecate anything so I had to keep it. But I'd support deprecation in there now.
The same applies to aliases, sometimes its code even too complicated (ppc). I'd ditch it if possible.
(added in loop PPC folks for opinions)
Quoted 8 lines
* Aliases
We have several targets roll their own CPU name aliases code. Assuming aliases are here to stay (i.e. we're not deprecating all of them): what about letting each CPU type specify a set of aliases, so we can recognize them in generic code?