Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TCI Support #2050

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ option(UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_INSTALL "Enable unicorn installation" ${PROJECT_IS_TOP_LEVEL})
set(UNICORN_ARCH "x86;arm;aarch64;riscv;mips;sparc;m68k;ppc;s390x;tricore" CACHE STRING "Enabled unicorn architectures")
option(UNICORN_TRACER "Trace unicorn execution" OFF)
option(UNICORN_INTERPRETER "Use interpreter mode" OFF)

foreach(ARCH_LOOP ${UNICORN_ARCH})
string(TOUPPER "${ARCH_LOOP}" ARCH_LOOP)
Expand Down Expand Up @@ -276,6 +277,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 ")
Expand Down Expand Up @@ -361,10 +366,17 @@ else()
set(TARGET_LIST "${TARGET_LIST} ")

# GEN config-host.mak & target directories
set(UNICORN_EXECUTION_MODE "")
if(UNICORN_INTERPRETER)
set(UNICORN_EXECUTION_MODE "--enable-interpreter")
else()
set(UNICORN_EXECUTION_MODE "--disable-interpreter")
endif()
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/configure
--cc=${CMAKE_C_COMPILER}
${EXTRA_CFLAGS}
${TARGET_LIST}
${UNICORN_EXECUTION_MODE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/qemu/scripts/create_config
Expand Down Expand Up @@ -506,6 +518,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}
Expand Down
6 changes: 6 additions & 0 deletions qemu/accel/tcg/translate-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -1019,12 +1019,18 @@ void free_code_gen_buffer(struct uc_struct *uc)
static inline void *alloc_code_gen_buffer(struct uc_struct *uc)
{
TCGContext *tcg_ctx = uc->tcg_ctx;
#if CONFIG_TCG_INTERPRETER
int prot = PROT_WRITE | PROT_READ;
#else
int prot = PROT_WRITE | PROT_READ | PROT_EXEC;
#endif
int flags = MAP_PRIVATE | MAP_ANONYMOUS;
size_t size = tcg_ctx->code_gen_buffer_size;
void *buf;
#if !CONFIG_TCG_INTERPRETER
#ifdef USE_MAP_JIT
flags |= MAP_JIT;
#endif
#endif
buf = mmap(NULL, size, prot, flags, -1, 0);
if (buf == MAP_FAILED) {
Expand Down
17 changes: 16 additions & 1 deletion qemu/configure
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ supported_cpu="no"
supported_os="no"
bogus_os="no"
malloc_trim=""
interpreter="yes"

# parse CC options first
for opt do
Expand Down Expand Up @@ -308,6 +309,10 @@ for opt do
eval "cross_cc_${cc_arch}=\$optarg"
cross_cc_vars="$cross_cc_vars cross_cc_${cc_arch}"
;;
--enable-interpreter) interpreter="yes"
;;
--disable-interpreter) interpreter="no"
;;
esac
done
# OS specific
Expand Down Expand Up @@ -689,6 +694,10 @@ for opt do
;;
--disable-debug-info)
;;
--enable-interpreter)
;;
--disable-interpreter)
;;
--cross-cc-*)
;;
--cpu=*)
Expand Down Expand Up @@ -922,6 +931,7 @@ disabled with --disable-FEATURE, default is enabled if available:
jemalloc jemalloc support
avx2 AVX2 optimization support
avx512f AVX512F optimization support
interpreter Interpreter mode

NOTE: The object files are built at the place where configure is launched
EOF
Expand Down Expand Up @@ -2136,7 +2146,7 @@ fi
##########################################
# check for Apple Silicon JIT function

if [ "$darwin" = "yes" ] ; then
if [ "$darwin" = "yes" ] && [ "$interpreter" = "no" ] ; then
cat > $TMPC << EOF
#include <pthread.h>
int main() { pthread_jit_write_protect_np(0); return 0;}
Expand Down Expand Up @@ -2314,6 +2324,7 @@ echo "tcmalloc support $tcmalloc"
echo "jemalloc support $jemalloc"
echo "avx2 optimization $avx2_opt"
echo "avx512f optimization $avx512f_opt"
echo "interpreter $interpreter"

if test "$supported_cpu" = "no"; then
echo
Expand Down Expand Up @@ -2558,6 +2569,10 @@ if test "$have_sprr" = "yes" ; then
echo "HAVE_SPRR=y" >> $config_host_mak
fi

if test "$interpreter" = "yes" ; then
echo "CONFIG_TCG_INTERPRETER=y" >> $config_host_mak
fi

# Hold two types of flag:
# CONFIG_THREAD_SETNAME_BYTHREAD - we've got a way of setting the name on
# a thread we have a handle to
Expand Down
1 change: 1 addition & 0 deletions qemu/include/tcg/tcg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions qemu/tcg/tcg.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

#include <uc_priv.h>

#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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down
Loading
Loading