cpu: Introduce TCGCpuOperations struct

The TCG-specific CPU methods will be moved to a separate struct,
to make it easier to move accel-specific code outside generic CPU
code in the future.  Start by moving tcg_initialize().

The new CPUClass.tcg_opts field may eventually become a pointer,
but keep it an embedded struct for now, to make code conversion
easier.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
[claudio: move TCGCpuOperations inside include/hw/core/cpu.h]
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20210204163931.7358-2-cfontana@suse.de>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Eduardo Habkost 2021-02-04 17:39:09 +01:00 committed by Richard Henderson
parent 2f74f45e32
commit e9e51b7154
25 changed files with 48 additions and 30 deletions

6
cpu.c
View File

@ -159,14 +159,18 @@ void cpu_exec_initfn(CPUState *cpu)
void cpu_exec_realizefn(CPUState *cpu, Error **errp) void cpu_exec_realizefn(CPUState *cpu, Error **errp)
{ {
CPUClass *cc = CPU_GET_CLASS(cpu); CPUClass *cc = CPU_GET_CLASS(cpu);
#ifdef CONFIG_TCG
static bool tcg_target_initialized; static bool tcg_target_initialized;
#endif /* CONFIG_TCG */
cpu_list_add(cpu); cpu_list_add(cpu);
#ifdef CONFIG_TCG
if (tcg_enabled() && !tcg_target_initialized) { if (tcg_enabled() && !tcg_target_initialized) {
tcg_target_initialized = true; tcg_target_initialized = true;
cc->tcg_initialize(); cc->tcg_ops.initialize();
} }
#endif /* CONFIG_TCG */
tlb_init(cpu); tlb_init(cpu);
qemu_plugin_vcpu_init_hook(cpu); qemu_plugin_vcpu_init_hook(cpu);

View File

@ -76,6 +76,19 @@ typedef struct CPUWatchpoint CPUWatchpoint;
struct TranslationBlock; struct TranslationBlock;
/**
* struct TcgCpuOperations: TCG operations specific to a CPU class
*/
typedef struct TcgCpuOperations {
/**
* @initialize: Initalize TCG state
*
* Called when the first CPU is realized.
*/
void (*initialize)(void);
} TcgCpuOperations;
/** /**
* CPUClass: * CPUClass:
* @class_by_name: Callback to map -cpu command line model name to an * @class_by_name: Callback to map -cpu command line model name to an
@ -222,12 +235,13 @@ struct CPUClass {
void (*disas_set_info)(CPUState *cpu, disassemble_info *info); void (*disas_set_info)(CPUState *cpu, disassemble_info *info);
vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
void (*tcg_initialize)(void);
const char *deprecation_note; const char *deprecation_note;
/* Keep non-pointer data at the end to minimize holes. */ /* Keep non-pointer data at the end to minimize holes. */
int gdb_num_core_regs; int gdb_num_core_regs;
bool gdb_stop_before_watchpoint; bool gdb_stop_before_watchpoint;
TcgCpuOperations tcg_ops;
}; };
/* /*

View File

@ -231,7 +231,7 @@ static void alpha_cpu_class_init(ObjectClass *oc, void *data)
dc->vmsd = &vmstate_alpha_cpu; dc->vmsd = &vmstate_alpha_cpu;
#endif #endif
cc->disas_set_info = alpha_cpu_disas_set_info; cc->disas_set_info = alpha_cpu_disas_set_info;
cc->tcg_initialize = alpha_translate_init; cc->tcg_ops.initialize = alpha_translate_init;
cc->gdb_num_core_regs = 67; cc->gdb_num_core_regs = 67;
} }

View File

@ -2276,7 +2276,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data)
cc->gdb_stop_before_watchpoint = true; cc->gdb_stop_before_watchpoint = true;
cc->disas_set_info = arm_disas_set_info; cc->disas_set_info = arm_disas_set_info;
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
cc->tcg_initialize = arm_translate_init; cc->tcg_ops.initialize = arm_translate_init;
cc->tlb_fill = arm_cpu_tlb_fill; cc->tlb_fill = arm_cpu_tlb_fill;
cc->debug_excp_handler = arm_debug_excp_handler; cc->debug_excp_handler = arm_debug_excp_handler;
cc->debug_check_watchpoint = arm_debug_check_watchpoint; cc->debug_check_watchpoint = arm_debug_check_watchpoint;

View File

@ -207,7 +207,7 @@ static void avr_cpu_class_init(ObjectClass *oc, void *data)
cc->tlb_fill = avr_cpu_tlb_fill; cc->tlb_fill = avr_cpu_tlb_fill;
cc->vmsd = &vms_avr_cpu; cc->vmsd = &vms_avr_cpu;
cc->disas_set_info = avr_cpu_disas_set_info; cc->disas_set_info = avr_cpu_disas_set_info;
cc->tcg_initialize = avr_cpu_tcg_init; cc->tcg_ops.initialize = avr_cpu_tcg_init;
cc->synchronize_from_tb = avr_cpu_synchronize_from_tb; cc->synchronize_from_tb = avr_cpu_synchronize_from_tb;
cc->gdb_read_register = avr_cpu_gdb_read_register; cc->gdb_read_register = avr_cpu_gdb_read_register;
cc->gdb_write_register = avr_cpu_gdb_write_register; cc->gdb_write_register = avr_cpu_gdb_write_register;

View File

@ -201,7 +201,7 @@ static void crisv8_cpu_class_init(ObjectClass *oc, void *data)
ccc->vr = 8; ccc->vr = 8;
cc->do_interrupt = crisv10_cpu_do_interrupt; cc->do_interrupt = crisv10_cpu_do_interrupt;
cc->gdb_read_register = crisv10_cpu_gdb_read_register; cc->gdb_read_register = crisv10_cpu_gdb_read_register;
cc->tcg_initialize = cris_initialize_crisv10_tcg; cc->tcg_ops.initialize = cris_initialize_crisv10_tcg;
} }
static void crisv9_cpu_class_init(ObjectClass *oc, void *data) static void crisv9_cpu_class_init(ObjectClass *oc, void *data)
@ -212,7 +212,7 @@ static void crisv9_cpu_class_init(ObjectClass *oc, void *data)
ccc->vr = 9; ccc->vr = 9;
cc->do_interrupt = crisv10_cpu_do_interrupt; cc->do_interrupt = crisv10_cpu_do_interrupt;
cc->gdb_read_register = crisv10_cpu_gdb_read_register; cc->gdb_read_register = crisv10_cpu_gdb_read_register;
cc->tcg_initialize = cris_initialize_crisv10_tcg; cc->tcg_ops.initialize = cris_initialize_crisv10_tcg;
} }
static void crisv10_cpu_class_init(ObjectClass *oc, void *data) static void crisv10_cpu_class_init(ObjectClass *oc, void *data)
@ -223,7 +223,7 @@ static void crisv10_cpu_class_init(ObjectClass *oc, void *data)
ccc->vr = 10; ccc->vr = 10;
cc->do_interrupt = crisv10_cpu_do_interrupt; cc->do_interrupt = crisv10_cpu_do_interrupt;
cc->gdb_read_register = crisv10_cpu_gdb_read_register; cc->gdb_read_register = crisv10_cpu_gdb_read_register;
cc->tcg_initialize = cris_initialize_crisv10_tcg; cc->tcg_ops.initialize = cris_initialize_crisv10_tcg;
} }
static void crisv11_cpu_class_init(ObjectClass *oc, void *data) static void crisv11_cpu_class_init(ObjectClass *oc, void *data)
@ -234,7 +234,7 @@ static void crisv11_cpu_class_init(ObjectClass *oc, void *data)
ccc->vr = 11; ccc->vr = 11;
cc->do_interrupt = crisv10_cpu_do_interrupt; cc->do_interrupt = crisv10_cpu_do_interrupt;
cc->gdb_read_register = crisv10_cpu_gdb_read_register; cc->gdb_read_register = crisv10_cpu_gdb_read_register;
cc->tcg_initialize = cris_initialize_crisv10_tcg; cc->tcg_ops.initialize = cris_initialize_crisv10_tcg;
} }
static void crisv17_cpu_class_init(ObjectClass *oc, void *data) static void crisv17_cpu_class_init(ObjectClass *oc, void *data)
@ -245,7 +245,7 @@ static void crisv17_cpu_class_init(ObjectClass *oc, void *data)
ccc->vr = 17; ccc->vr = 17;
cc->do_interrupt = crisv10_cpu_do_interrupt; cc->do_interrupt = crisv10_cpu_do_interrupt;
cc->gdb_read_register = crisv10_cpu_gdb_read_register; cc->gdb_read_register = crisv10_cpu_gdb_read_register;
cc->tcg_initialize = cris_initialize_crisv10_tcg; cc->tcg_ops.initialize = cris_initialize_crisv10_tcg;
} }
static void crisv32_cpu_class_init(ObjectClass *oc, void *data) static void crisv32_cpu_class_init(ObjectClass *oc, void *data)
@ -284,7 +284,7 @@ static void cris_cpu_class_init(ObjectClass *oc, void *data)
cc->gdb_stop_before_watchpoint = true; cc->gdb_stop_before_watchpoint = true;
cc->disas_set_info = cris_disas_set_info; cc->disas_set_info = cris_disas_set_info;
cc->tcg_initialize = cris_initialize_tcg; cc->tcg_ops.initialize = cris_initialize_tcg;
} }
#define DEFINE_CRIS_CPU_TYPE(cpu_model, initfn) \ #define DEFINE_CRIS_CPU_TYPE(cpu_model, initfn) \

View File

@ -154,7 +154,7 @@ static void hppa_cpu_class_init(ObjectClass *oc, void *data)
#endif #endif
cc->do_unaligned_access = hppa_cpu_do_unaligned_access; cc->do_unaligned_access = hppa_cpu_do_unaligned_access;
cc->disas_set_info = hppa_cpu_disas_set_info; cc->disas_set_info = hppa_cpu_disas_set_info;
cc->tcg_initialize = hppa_translate_init; cc->tcg_ops.initialize = hppa_translate_init;
cc->gdb_num_core_regs = 128; cc->gdb_num_core_regs = 128;
} }

View File

@ -64,7 +64,7 @@ void tcg_cpu_common_class_init(CPUClass *cc)
cc->synchronize_from_tb = x86_cpu_synchronize_from_tb; cc->synchronize_from_tb = x86_cpu_synchronize_from_tb;
cc->cpu_exec_enter = x86_cpu_exec_enter; cc->cpu_exec_enter = x86_cpu_exec_enter;
cc->cpu_exec_exit = x86_cpu_exec_exit; cc->cpu_exec_exit = x86_cpu_exec_exit;
cc->tcg_initialize = tcg_x86_init; cc->tcg_ops.initialize = tcg_x86_init;
cc->tlb_fill = x86_cpu_tlb_fill; cc->tlb_fill = x86_cpu_tlb_fill;
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
cc->debug_excp_handler = breakpoint_handler; cc->debug_excp_handler = breakpoint_handler;

View File

@ -237,7 +237,7 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data)
cc->gdb_stop_before_watchpoint = true; cc->gdb_stop_before_watchpoint = true;
cc->debug_excp_handler = lm32_debug_excp_handler; cc->debug_excp_handler = lm32_debug_excp_handler;
cc->disas_set_info = lm32_cpu_disas_set_info; cc->disas_set_info = lm32_cpu_disas_set_info;
cc->tcg_initialize = lm32_translate_init; cc->tcg_ops.initialize = lm32_translate_init;
} }
#define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \ #define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \

View File

@ -478,7 +478,7 @@ static void m68k_cpu_class_init(ObjectClass *c, void *data)
dc->vmsd = &vmstate_m68k_cpu; dc->vmsd = &vmstate_m68k_cpu;
#endif #endif
cc->disas_set_info = m68k_cpu_disas_set_info; cc->disas_set_info = m68k_cpu_disas_set_info;
cc->tcg_initialize = m68k_tcg_init; cc->tcg_ops.initialize = m68k_tcg_init;
cc->gdb_num_core_regs = 18; cc->gdb_num_core_regs = 18;
} }

View File

@ -382,7 +382,7 @@ static void mb_cpu_class_init(ObjectClass *oc, void *data)
cc->gdb_num_core_regs = 32 + 27; cc->gdb_num_core_regs = 32 + 27;
cc->disas_set_info = mb_disas_set_info; cc->disas_set_info = mb_disas_set_info;
cc->tcg_initialize = mb_tcg_init; cc->tcg_ops.initialize = mb_tcg_init;
} }
static const TypeInfo mb_cpu_type_info = { static const TypeInfo mb_cpu_type_info = {

View File

@ -689,7 +689,7 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
#endif #endif
cc->disas_set_info = mips_cpu_disas_set_info; cc->disas_set_info = mips_cpu_disas_set_info;
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
cc->tcg_initialize = mips_tcg_init; cc->tcg_ops.initialize = mips_tcg_init;
cc->tlb_fill = mips_cpu_tlb_fill; cc->tlb_fill = mips_cpu_tlb_fill;
#endif #endif

View File

@ -116,7 +116,7 @@ static void moxie_cpu_class_init(ObjectClass *oc, void *data)
cc->vmsd = &vmstate_moxie_cpu; cc->vmsd = &vmstate_moxie_cpu;
#endif #endif
cc->disas_set_info = moxie_cpu_disas_set_info; cc->disas_set_info = moxie_cpu_disas_set_info;
cc->tcg_initialize = moxie_translate_init; cc->tcg_ops.initialize = moxie_translate_init;
} }
static void moxielite_initfn(Object *obj) static void moxielite_initfn(Object *obj)

View File

@ -234,7 +234,7 @@ static void nios2_cpu_class_init(ObjectClass *oc, void *data)
cc->gdb_read_register = nios2_cpu_gdb_read_register; cc->gdb_read_register = nios2_cpu_gdb_read_register;
cc->gdb_write_register = nios2_cpu_gdb_write_register; cc->gdb_write_register = nios2_cpu_gdb_write_register;
cc->gdb_num_core_regs = 49; cc->gdb_num_core_regs = 49;
cc->tcg_initialize = nios2_tcg_init; cc->tcg_ops.initialize = nios2_tcg_init;
} }
static const TypeInfo nios2_cpu_type_info = { static const TypeInfo nios2_cpu_type_info = {

View File

@ -198,7 +198,7 @@ static void openrisc_cpu_class_init(ObjectClass *oc, void *data)
dc->vmsd = &vmstate_openrisc_cpu; dc->vmsd = &vmstate_openrisc_cpu;
#endif #endif
cc->gdb_num_core_regs = 32 + 3; cc->gdb_num_core_regs = 32 + 3;
cc->tcg_initialize = openrisc_translate_init; cc->tcg_ops.initialize = openrisc_translate_init;
cc->disas_set_info = openrisc_disas_set_info; cc->disas_set_info = openrisc_disas_set_info;
} }

View File

@ -10878,7 +10878,7 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data)
cc->virtio_is_big_endian = ppc_cpu_is_big_endian; cc->virtio_is_big_endian = ppc_cpu_is_big_endian;
#endif #endif
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
cc->tcg_initialize = ppc_translate_init; cc->tcg_ops.initialize = ppc_translate_init;
cc->tlb_fill = ppc_cpu_tlb_fill; cc->tlb_fill = ppc_cpu_tlb_fill;
#endif #endif
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY

View File

@ -618,7 +618,7 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
cc->gdb_arch_name = riscv_gdb_arch_name; cc->gdb_arch_name = riscv_gdb_arch_name;
cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
cc->tcg_initialize = riscv_translate_init; cc->tcg_ops.initialize = riscv_translate_init;
cc->tlb_fill = riscv_cpu_tlb_fill; cc->tlb_fill = riscv_cpu_tlb_fill;
#endif #endif
device_class_set_props(dc, riscv_cpu_properties); device_class_set_props(dc, riscv_cpu_properties);

View File

@ -195,7 +195,7 @@ static void rx_cpu_class_init(ObjectClass *klass, void *data)
cc->gdb_write_register = rx_cpu_gdb_write_register; cc->gdb_write_register = rx_cpu_gdb_write_register;
cc->get_phys_page_debug = rx_cpu_get_phys_page_debug; cc->get_phys_page_debug = rx_cpu_get_phys_page_debug;
cc->disas_set_info = rx_cpu_disas_set_info; cc->disas_set_info = rx_cpu_disas_set_info;
cc->tcg_initialize = rx_translate_init; cc->tcg_ops.initialize = rx_translate_init;
cc->tlb_fill = rx_cpu_tlb_fill; cc->tlb_fill = rx_cpu_tlb_fill;
cc->gdb_num_core_regs = 26; cc->gdb_num_core_regs = 26;

View File

@ -515,7 +515,7 @@ static void s390_cpu_class_init(ObjectClass *oc, void *data)
#endif #endif
cc->disas_set_info = s390_cpu_disas_set_info; cc->disas_set_info = s390_cpu_disas_set_info;
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
cc->tcg_initialize = s390x_translate_init; cc->tcg_ops.initialize = s390x_translate_init;
cc->tlb_fill = s390_cpu_tlb_fill; cc->tlb_fill = s390_cpu_tlb_fill;
#endif #endif

View File

@ -232,7 +232,7 @@ static void superh_cpu_class_init(ObjectClass *oc, void *data)
cc->get_phys_page_debug = superh_cpu_get_phys_page_debug; cc->get_phys_page_debug = superh_cpu_get_phys_page_debug;
#endif #endif
cc->disas_set_info = superh_cpu_disas_set_info; cc->disas_set_info = superh_cpu_disas_set_info;
cc->tcg_initialize = sh4_translate_init; cc->tcg_ops.initialize = sh4_translate_init;
cc->gdb_num_core_regs = 59; cc->gdb_num_core_regs = 59;

View File

@ -881,7 +881,7 @@ static void sparc_cpu_class_init(ObjectClass *oc, void *data)
cc->vmsd = &vmstate_sparc_cpu; cc->vmsd = &vmstate_sparc_cpu;
#endif #endif
cc->disas_set_info = cpu_sparc_disas_set_info; cc->disas_set_info = cpu_sparc_disas_set_info;
cc->tcg_initialize = sparc_tcg_init; cc->tcg_ops.initialize = sparc_tcg_init;
#if defined(TARGET_SPARC64) && !defined(TARGET_ABI32) #if defined(TARGET_SPARC64) && !defined(TARGET_ABI32)
cc->gdb_num_core_regs = 86; cc->gdb_num_core_regs = 86;

View File

@ -153,7 +153,7 @@ static void tilegx_cpu_class_init(ObjectClass *oc, void *data)
cc->set_pc = tilegx_cpu_set_pc; cc->set_pc = tilegx_cpu_set_pc;
cc->tlb_fill = tilegx_cpu_tlb_fill; cc->tlb_fill = tilegx_cpu_tlb_fill;
cc->gdb_num_core_regs = 0; cc->gdb_num_core_regs = 0;
cc->tcg_initialize = tilegx_tcg_init; cc->tcg_ops.initialize = tilegx_tcg_init;
} }
static const TypeInfo tilegx_cpu_type_info = { static const TypeInfo tilegx_cpu_type_info = {

View File

@ -164,7 +164,7 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data)
cc->set_pc = tricore_cpu_set_pc; cc->set_pc = tricore_cpu_set_pc;
cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb; cc->synchronize_from_tb = tricore_cpu_synchronize_from_tb;
cc->get_phys_page_debug = tricore_cpu_get_phys_page_debug; cc->get_phys_page_debug = tricore_cpu_get_phys_page_debug;
cc->tcg_initialize = tricore_tcg_init; cc->tcg_ops.initialize = tricore_tcg_init;
cc->tlb_fill = tricore_cpu_tlb_fill; cc->tlb_fill = tricore_cpu_tlb_fill;
} }

View File

@ -137,7 +137,7 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)
cc->set_pc = uc32_cpu_set_pc; cc->set_pc = uc32_cpu_set_pc;
cc->tlb_fill = uc32_cpu_tlb_fill; cc->tlb_fill = uc32_cpu_tlb_fill;
cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug; cc->get_phys_page_debug = uc32_cpu_get_phys_page_debug;
cc->tcg_initialize = uc32_translate_init; cc->tcg_ops.initialize = uc32_translate_init;
dc->vmsd = &vmstate_uc32_cpu; dc->vmsd = &vmstate_uc32_cpu;
} }

View File

@ -209,7 +209,7 @@ static void xtensa_cpu_class_init(ObjectClass *oc, void *data)
#endif #endif
cc->debug_excp_handler = xtensa_breakpoint_handler; cc->debug_excp_handler = xtensa_breakpoint_handler;
cc->disas_set_info = xtensa_cpu_disas_set_info; cc->disas_set_info = xtensa_cpu_disas_set_info;
cc->tcg_initialize = xtensa_translate_init; cc->tcg_ops.initialize = xtensa_translate_init;
dc->vmsd = &vmstate_xtensa_cpu; dc->vmsd = &vmstate_xtensa_cpu;
} }