exec: [tcg] Track which vCPU is performing translation and execution

Information is tracked inside the TCGContext structure, and later used
by tracing events with the 'tcg' and 'vcpu' properties.

The 'cpu' field is used to check tracing of translation-time
events ("*_trans"). The 'tcg_env' field is used to pass it to
execution-time events ("*_exec").

Backports commit 7c2550432abe62f53e6df878ceba6ceaf71f0e7e from qemu
This commit is contained in:
Lluís Vilanova 2018-02-24 19:17:36 -05:00 committed by Lioncash
parent 0f6513ef62
commit 2297527755
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
7 changed files with 13 additions and 0 deletions

View file

@ -73,6 +73,7 @@ void arm_translate_init(struct uc_struct *uc)
TCGContext *tcg_ctx = uc->tcg_ctx;
tcg_ctx->cpu_env = tcg_global_reg_new_ptr(uc->tcg_ctx, TCG_AREG0, "env");
tcg_ctx->tcg_env = tcg_ctx->cpu_env;
for (i = 0; i < 16; i++) {
tcg_ctx->cpu_R[i] = tcg_global_mem_new_i32(uc->tcg_ctx, tcg_ctx->cpu_env,

View file

@ -8909,6 +8909,8 @@ void tcg_x86_init(struct uc_struct *uc)
TCGContext *tcg_ctx = uc->tcg_ctx;
tcg_ctx->cpu_env = tcg_global_reg_new_ptr(uc->tcg_ctx, TCG_AREG0, "env");
tcg_ctx->tcg_env = tcg_ctx->cpu_env;
tcg_ctx->cpu_cc_op = tcg_global_mem_new_i32(uc->tcg_ctx, tcg_ctx->cpu_env,
offsetof(CPUX86State, cc_op), "cc_op");

View file

@ -52,6 +52,7 @@ void m68k_tcg_init(struct uc_struct *uc)
int i;
tcg_ctx->cpu_env = tcg_global_reg_new_ptr(tcg_ctx, TCG_AREG0, "env");
tcg_ctx->tcg_env = tcg_ctx->cpu_env;
#define DEFO32(name, offset) tcg_ctx->QREG_##name = tcg_global_mem_new_i32(tcg_ctx, tcg_ctx->cpu_env, offsetof(CPUM68KState, offset), #name);
#define DEFO64(name, offset) tcg_ctx->QREG_##name = tcg_global_mem_new_i64(tcg_ctx, tcg_ctx->cpu_env, offsetof(CPUM68KState, offset), #name);

View file

@ -20144,6 +20144,7 @@ void mips_tcg_init(struct uc_struct *uc)
int i;
tcg_ctx->cpu_env = tcg_global_reg_new_ptr(uc->tcg_ctx, TCG_AREG0, "env");
tcg_ctx->tcg_env = tcg_ctx->cpu_env;
for (i = 0; i < 32; i++) {
tcg_ctx->cpu_gpr[i] = tcg_global_mem_new(tcg_ctx, tcg_ctx->cpu_env,

View file

@ -5537,6 +5537,8 @@ void gen_intermediate_code_init(CPUSPARCState *env)
return;
}
tcg_ctx->cpu_env = tcg_global_reg_new_ptr(tcg_ctx, TCG_AREG0, "env");
tcg_ctx->tcg_env = tcg_ctx->cpu_env;
tcg_ctx->cpu_regwptr = tcg_global_mem_new_ptr(tcg_ctx, tcg_ctx->cpu_env,
offsetof(CPUSPARCState, regwptr),
"regwptr");

View file

@ -727,6 +727,10 @@ struct TCGContext {
TBContext tb_ctx;
/* Track which vCPU triggers events */
CPUState *cpu; /* *_trans */
TCGv_env tcg_env; /* *_exec */
/* The TCGBackendData structure is private to tcg-target.inc.c. */
struct TCGBackendData *be;

View file

@ -1292,7 +1292,9 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
tcg_func_start(tcg_ctx);
tcg_ctx->cpu = ENV_GET_CPU(env);
gen_intermediate_code(env, tb);
tcg_ctx->cpu = NULL;
// Unicorn: when tracing block, patch block size operand for callback
if (env->uc->size_arg != -1 && HOOK_EXISTS_BOUNDED(env->uc, UC_HOOK_BLOCK, tb->pc)) {