From 0d9f826a6952a0f3db5ae768ef762d80a1831e1b Mon Sep 17 00:00:00 2001 From: Zhang Date: Thu, 24 Oct 2024 18:22:22 +0800 Subject: [PATCH] [qemu]It compiles! --- CMakeLists.txt | 8 ++++++++ qemu/include/tcg/tcg.h | 1 + qemu/tcg/tcg.c | 6 ++++++ qemu/tcg/tci/tcg-target.inc.c | 8 ++++---- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d613ff7d94..7f61c522d9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -259,6 +259,10 @@ else() endwhile(TRUE) endif() + if(UNICORN_INTERPRETER) + set(UNICORN_TARGET_ARCH "tci") + endif() + set(EXTRA_CFLAGS "--extra-cflags=") if(UNICORN_HAS_X86) set(EXTRA_CFLAGS "${EXTRA_CFLAGS}-DUNICORN_HAS_X86 ") @@ -496,6 +500,10 @@ set(UNICORN_ARCH_COMMON qemu/softmmu/unicorn_vtlb.c ) +if(UNICORN_INTERPRETER) + list(APPEND UNICORN_ARCH_COMMON qemu/tcg/tci.c) +endif() + if(UNICORN_HAS_X86) add_library(x86_64-softmmu STATIC ${UNICORN_ARCH_COMMON} diff --git a/qemu/include/tcg/tcg.h b/qemu/include/tcg/tcg.h index 9908acaa57..1c548e0d66 100644 --- a/qemu/include/tcg/tcg.h +++ b/qemu/include/tcg/tcg.h @@ -695,6 +695,7 @@ struct TCGContext { struct jit_code_entry *one_entry; /* qemu/tcg/tcg-common.c */ TCGOpDef *tcg_op_defs; + size_t tcg_op_defs_max; // Unicorn engine variables struct uc_struct *uc; diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c index a91f2de6f1..326556e4bf 100644 --- a/qemu/tcg/tcg.c +++ b/qemu/tcg/tcg.c @@ -62,6 +62,10 @@ #include +#if CONFIG_TCG_INTERPRETER +#include "tcg/tcg.h" +#endif + /* Forward declarations for functions declared in tcg-target.inc.c and used here. */ static void tcg_target_init(TCGContext *s); @@ -659,6 +663,7 @@ static const TCGOpDef tcg_op_defs_org[] = { #include "tcg/tcg-opc.h" #undef DEF }; +static const size_t tcg_op_defs_max_org = ARRAY_SIZE(tcg_op_defs_org); static void process_op_defs(TCGContext *s); static TCGTemp *tcg_global_reg_new_internal(TCGContext *s, TCGType type, @@ -727,6 +732,7 @@ void tcg_context_init(TCGContext *s) // copy original tcg_op_defs_org for private usage s->tcg_op_defs = g_malloc0(sizeof(tcg_op_defs_org)); memcpy(s->tcg_op_defs, tcg_op_defs_org, sizeof(tcg_op_defs_org)); + s->tcg_op_defs_max = tcg_op_defs_max_org; /* Count total number of arguments and allocate the corresponding space */ diff --git a/qemu/tcg/tci/tcg-target.inc.c b/qemu/tcg/tci/tcg-target.inc.c index 992d50cb1e..ab3114532f 100644 --- a/qemu/tcg/tci/tcg-target.inc.c +++ b/qemu/tcg/tci/tcg-target.inc.c @@ -871,14 +871,14 @@ static void tcg_target_init(TCGContext *s) #endif /* The current code uses uint8_t for tcg operations. */ - tcg_debug_assert(tcg_op_defs_max <= UINT8_MAX); + tcg_debug_assert(s->tcg_op_defs_max <= UINT8_MAX); /* Registers available for 32 bit operations. */ - tcg_target_available_regs[TCG_TYPE_I32] = BIT(TCG_TARGET_NB_REGS) - 1; + s->tcg_target_available_regs[TCG_TYPE_I32] = BIT(TCG_TARGET_NB_REGS) - 1; /* Registers available for 64 bit operations. */ - tcg_target_available_regs[TCG_TYPE_I64] = BIT(TCG_TARGET_NB_REGS) - 1; + s->tcg_target_available_regs[TCG_TYPE_I64] = BIT(TCG_TARGET_NB_REGS) - 1; /* TODO: Which registers should be set here? */ - tcg_target_call_clobber_regs = BIT(TCG_TARGET_NB_REGS) - 1; + s->tcg_target_call_clobber_regs = BIT(TCG_TARGET_NB_REGS) - 1; s->reserved_regs = 0; tcg_regset_set_reg(s->reserved_regs, TCG_REG_CALL_STACK);