From 1be7b55bb484a0f6611baafa3bb5969dd8ae0266 Mon Sep 17 00:00:00 2001 From: "Emilio G. Cota" Date: Wed, 14 Mar 2018 09:49:41 -0400 Subject: [PATCH] tcg: introduce **tcg_ctxs to keep track of all TCGContext's Groundwork for supporting multiple TCG contexts. Note that having n_tcg_ctxs is unnecessary. However, it is convenient to have it, since it will simplify iterating over the array: we'll have just a for loop instead of having to iterate over a NULL-terminated array (which would require n+1 elems) or having to check with ifdef's for usermode/softmmu. Backports commit df2cce2968069526553d82331ce9817eaca6b03a from qemu --- include/uc_priv.h | 11 ++++++++--- qemu/accel/tcg/translate-all.c | 3 +-- qemu/tcg/tcg.c | 6 +++++- qemu/tcg/tcg.h | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/uc_priv.h b/include/uc_priv.h index 069eb3ca..9dd79d4b 100644 --- a/include/uc_priv.h +++ b/include/uc_priv.h @@ -217,10 +217,15 @@ struct uc_struct { intptr_t qemu_host_page_mask; /* code generation context */ - void *tcg_ctx; // for "TCGContext tcg_ctx" in translate-all.c - void *tcg_init_ctx; // for "TCGContext init_tcg_contex" in translate-all.c + // translate-all.c + void *tcg_ctx; // actually "TCGContext *tcg_ctx" + void *tcg_init_ctx; // actually "TCGContext *init_tcg_contex" TBContext tb_ctx; - bool parallel_cpus; // for "bool parallel_cpus" in translate-all.c + bool parallel_cpus; + + // tcg.c + void *tcg_ctxs; // actually "TCGContext **tcg_ctxs" + unsigned int n_tcg_ctxs; /* memory.c */ unsigned memory_region_transaction_depth; diff --git a/qemu/accel/tcg/translate-all.c b/qemu/accel/tcg/translate-all.c index b4b2f209..389bb6e0 100644 --- a/qemu/accel/tcg/translate-all.c +++ b/qemu/accel/tcg/translate-all.c @@ -169,7 +169,7 @@ static void cpu_gen_init(struct uc_struct *uc) { uc->tcg_init_ctx = g_malloc0(sizeof(TCGContext));; - tcg_context_init(uc->tcg_init_ctx); + tcg_context_init(uc, uc->tcg_init_ctx); } static void tb_clean_internal(struct uc_struct *uc, int i, void** lp) @@ -880,7 +880,6 @@ void tcg_exec_init(struct uc_struct *uc, unsigned long tb_size) TCGContext *tcg_ctx; cpu_gen_init(uc); - uc->tcg_ctx = uc->tcg_init_ctx; tcg_ctx = uc->tcg_ctx; tcg_ctx->uc = uc; page_init(uc); diff --git a/qemu/tcg/tcg.c b/qemu/tcg/tcg.c index 58779c56..34f0faae 100644 --- a/qemu/tcg/tcg.c +++ b/qemu/tcg/tcg.c @@ -325,7 +325,7 @@ static const TCGHelperInfo all_helpers[] = { static void process_op_defs(TCGContext *s); -void tcg_context_init(TCGContext *s) +void tcg_context_init(struct uc_struct *uc, TCGContext *s) { int op, total_args, n, i; TCGOpDef *def; @@ -387,6 +387,10 @@ void tcg_context_init(TCGContext *s) for (; i < ARRAY_SIZE(tcg_target_reg_alloc_order); ++i) { s->indirect_reg_alloc_order[i] = tcg_target_reg_alloc_order[i]; } + + uc->tcg_ctx = s; + uc->tcg_ctxs = &uc->tcg_ctx; + uc->n_tcg_ctxs = 1; } /* diff --git a/qemu/tcg/tcg.h b/qemu/tcg/tcg.h index 5dd61685..19c4f3ec 100644 --- a/qemu/tcg/tcg.h +++ b/qemu/tcg/tcg.h @@ -639,7 +639,7 @@ void *tcg_malloc_internal(TCGContext *s, int size); void tcg_pool_reset(TCGContext *s); TranslationBlock *tcg_tb_alloc(TCGContext *s); -void tcg_context_init(TCGContext *s); +void tcg_context_init(struct uc_struct *uc, TCGContext *s); void tcg_context_free(void *s); // free memory allocated for @s void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s);