refactor to allow multiple hooks for one type

This commit is contained in:
Ryan Hileman
2016-01-16 00:44:02 -08:00
parent 6f0a01293d
commit 93052f6566
20 changed files with 542 additions and 751 deletions

View File

@ -11331,6 +11331,7 @@ static int decode_mips16_opc (CPUMIPSState *env, DisasContext *ctx, bool *insn_n
int op, cnvt_op, op1, offset;
int funct;
int n_bytes;
struct hook *hook;
op = (ctx->opcode >> 11) & 0x1f;
sa = (ctx->opcode >> 2) & 0x7;
@ -11343,12 +11344,11 @@ static int decode_mips16_opc (CPUMIPSState *env, DisasContext *ctx, bool *insn_n
n_bytes = 2;
// Unicorn: trace this instruction on request
if (env->uc->hook_insn) {
struct hook_struct *trace = hook_find(env->uc, UC_HOOK_CODE, ctx->pc);
if (trace) {
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, trace->callback, env->uc, ctx->pc, trace->user_data);
*insn_need_patch = true;
}
HOOK_FOREACH(env->uc, hook, UC_HOOK_CODE) {
if (! HOOK_BOUND_CHECK(hook, ctx->pc))
continue;
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, hook->callback, env->uc, ctx->pc, hook->user_data);
*insn_need_patch = true;
// the callback might want to stop emulation immediately
check_exit_request(tcg_ctx);
}
@ -13932,6 +13932,7 @@ static int decode_micromips_opc (CPUMIPSState *env, DisasContext *ctx, bool *ins
TCGContext *tcg_ctx = env->uc->tcg_ctx;
TCGv **cpu_gpr = (TCGv **)tcg_ctx->cpu_gpr;
uint32_t op;
struct hook *hook;
/* make sure instructions are on a halfword boundary */
if (ctx->pc & 0x1) {
@ -13942,12 +13943,11 @@ static int decode_micromips_opc (CPUMIPSState *env, DisasContext *ctx, bool *ins
}
// Unicorn: trace this instruction on request
if (env->uc->hook_insn) {
struct hook_struct *trace = hook_find(env->uc, UC_HOOK_CODE, ctx->pc);
if (trace) {
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, trace->callback, env->uc, ctx->pc, trace->user_data);
*insn_need_patch = true;
}
HOOK_FOREACH(env->uc, hook, UC_HOOK_CODE) {
if (! HOOK_BOUND_CHECK(hook, ctx->pc))
continue;
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, hook->callback, env->uc, ctx->pc, hook->user_data);
*insn_need_patch = true;
// the callback might want to stop emulation immediately
check_exit_request(tcg_ctx);
}
@ -18504,13 +18504,13 @@ static void gen_msa(CPUMIPSState *env, DisasContext *ctx)
// Unicorn: trace this instruction on request
static void hook_insn(CPUMIPSState *env, DisasContext *ctx, bool *insn_need_patch, int *insn_patch_offset, int offset_value)
{
if (env->uc->hook_insn) {
TCGContext *tcg_ctx = ctx->uc->tcg_ctx;
struct hook_struct *trace = hook_find(env->uc, UC_HOOK_CODE, ctx->pc);
if (trace) {
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, trace->callback, env->uc, ctx->pc, trace->user_data);
*insn_need_patch = true;
}
TCGContext *tcg_ctx = ctx->uc->tcg_ctx;
struct hook *hook;
HOOK_FOREACH(env->uc, hook, UC_HOOK_CODE) {
if (! HOOK_BOUND_CHECK(hook, ctx->pc))
continue;
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, hook->callback, env->uc, ctx->pc, hook->user_data);
*insn_need_patch = true;
// the callback might want to stop emulation immediately
check_exit_request(tcg_ctx);
*insn_patch_offset = offset_value;
@ -19178,6 +19178,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
TCGContext *tcg_ctx = env->uc->tcg_ctx;
TCGArg *save_opparam_ptr = NULL;
bool block_full = false;
struct hook *hook;
if (search_pc)
qemu_log("search pc %d\n", search_pc);
@ -19223,12 +19224,13 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
// Unicorn: trace this block on request
// Only hook this block if it is not broken from previous translation due to
// full translation cache
if (env->uc->hook_block && !env->uc->block_full) {
struct hook_struct *trace = hook_find(env->uc, UC_HOOK_BLOCK, pc_start);
if (trace) {
if (! env->uc->block_full) {
HOOK_FOREACH(env->uc, hook, UC_HOOK_BLOCK) {
if (! HOOK_BOUND_CHECK(hook, pc_start))
continue;
// save block address to see if we need to patch block size later
env->uc->block_addr = pc_start;
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, trace->callback, env->uc, pc_start, trace->user_data);
gen_uc_tracecode(tcg_ctx, 0xf8f8f8f8, hook->callback, env->uc, pc_start, hook->user_data);
}
}
@ -19275,7 +19277,7 @@ gen_intermediate_code_internal(MIPSCPU *cpu, TranslationBlock *tb,
int insn_patch_offset = 1;
// Unicorn: save param buffer
if (env->uc->hook_insn)
if (HOOK_EXISTS(env->uc, UC_HOOK_CODE))
save_opparam_ptr = tcg_ctx->gen_opparam_ptr;
is_slot = ctx.hflags & MIPS_HFLAG_BMASK;