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.

Backports e9e51b7154404efc9af8735ab87c658a9c434cfd
This commit is contained in:
Eduardo Habkost 2021-03-04 16:38:15 -05:00 committed by Lioncash
parent 11ae599cb8
commit b9b711afe3
8 changed files with 23 additions and 8 deletions

View file

@ -640,11 +640,13 @@ void cpu_exec_init(CPUState *cpu, Error **errp, void *opaque)
// Unicorn: Required to clean-slate TLB state // Unicorn: Required to clean-slate TLB state
tlb_flush(cpu); tlb_flush(cpu);
#ifdef CONFIG_TCG
if (tcg_enabled(uc) && !cc->tcg_initialized) { if (tcg_enabled(uc) && !cc->tcg_initialized) {
cc->tcg_initialized = true; cc->tcg_initialized = true;
cc->tcg_initialize(uc); cc->tcg_ops.initialize(uc);
} }
tlb_init(cpu); tlb_init(cpu);
#endif /* CONFIG_TCG */
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY

View file

@ -74,6 +74,19 @@ typedef void (*CPUUnassignedAccess)(CPUState *cpu, hwaddr addr,
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)(struct uc_struct *uc);
} 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
@ -183,9 +196,9 @@ typedef struct CPUClass {
void (*cpu_exec_exit)(CPUState *cpu); void (*cpu_exec_exit)(CPUState *cpu);
bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request); bool (*cpu_exec_interrupt)(CPUState *cpu, int interrupt_request);
vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len); vaddr (*adjust_watchpoint_address)(CPUState *cpu, vaddr addr, int len);
void (*tcg_initialize)(struct uc_struct *uc);
/* Keep non-pointer data at the end to minimize holes. */ /* Keep non-pointer data at the end to minimize holes. */
TcgCpuOperations tcg_ops;
bool tcg_initialized; bool tcg_initialized;
} CPUClass; } CPUClass;

View file

@ -2108,7 +2108,7 @@ static void arm_cpu_class_init(struct uc_struct *uc, ObjectClass *oc, void *data
//cc->virtio_is_big_endian = arm_cpu_is_big_endian; //cc->virtio_is_big_endian = arm_cpu_is_big_endian;
#endif #endif
#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

@ -5893,7 +5893,7 @@ static void x86_cpu_common_class_init(struct uc_struct *uc, ObjectClass *oc, voi
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;
#ifdef CONFIG_TCG #ifdef CONFIG_TCG
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;
#endif #endif
} }

View file

@ -273,7 +273,7 @@ static void m68k_cpu_class_init(struct uc_struct *uc, ObjectClass *c, void *data
cc->do_transaction_failed = m68k_cpu_transaction_failed; cc->do_transaction_failed = m68k_cpu_transaction_failed;
cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug; cc->get_phys_page_debug = m68k_cpu_get_phys_page_debug;
#endif #endif
cc->tcg_initialize = m68k_tcg_init; cc->tcg_ops.initialize = m68k_tcg_init;
} }
#define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \ #define DEFINE_M68K_CPU_TYPE(cpu_model, initfn) \

View file

@ -181,7 +181,7 @@ static void mips_cpu_class_init(struct uc_struct *uc, ObjectClass *c, void *data
cc->get_phys_page_debug = mips_cpu_get_phys_page_debug; cc->get_phys_page_debug = mips_cpu_get_phys_page_debug;
#endif #endif
#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

@ -373,7 +373,7 @@ static void riscv_cpu_class_init(struct uc_struct *uc, ObjectClass *oc, void *da
cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug; cc->get_phys_page_debug = riscv_cpu_get_phys_page_debug;
#endif #endif
#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
/* For now, mark unmigratable: */ /* For now, mark unmigratable: */

View file

@ -856,7 +856,7 @@ static void sparc_cpu_class_init(struct uc_struct *uc, ObjectClass *oc, void *da
// Unicorn: commented out // Unicorn: commented out
//cc->vmsd = &vmstate_sparc_cpu; //cc->vmsd = &vmstate_sparc_cpu;
#endif #endif
cc->tcg_initialize = sparc_tcg_init; cc->tcg_ops.initialize = sparc_tcg_init;
} }
static void sparc_cpu_cpudef_class_init(struct uc_struct *uc, ObjectClass *oc, void *data) static void sparc_cpu_cpudef_class_init(struct uc_struct *uc, ObjectClass *oc, void *data)