mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-07-03 14:38:17 +00:00
translator: merge max_insns into DisasContextBase
While at it, use int for both num_insns and max_insns to make sure we have same-type comparisons. Backports commit b542683d77b4f56cef0221b267c341616d87bce9 from qemu
This commit is contained in:
parent
28cfe5dab0
commit
d26bf1d446
|
@ -33,7 +33,6 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
|
||||||
CPUState *cpu, TranslationBlock *tb)
|
CPUState *cpu, TranslationBlock *tb)
|
||||||
{
|
{
|
||||||
TCGContext *tcg_ctx = cpu->uc->tcg_ctx;
|
TCGContext *tcg_ctx = cpu->uc->tcg_ctx;
|
||||||
int max_insns;
|
|
||||||
|
|
||||||
/* Initialize DisasContext */
|
/* Initialize DisasContext */
|
||||||
db->tb = tb;
|
db->tb = tb;
|
||||||
|
@ -47,19 +46,19 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
|
||||||
db->uc->block_full = false;
|
db->uc->block_full = false;
|
||||||
|
|
||||||
/* Instruction counting */
|
/* Instruction counting */
|
||||||
max_insns = db->tb->cflags & CF_COUNT_MASK;
|
db->max_insns = db->tb->cflags & CF_COUNT_MASK;
|
||||||
if (max_insns == 0) {
|
if (db->max_insns == 0) {
|
||||||
max_insns = CF_COUNT_MASK;
|
db->max_insns = CF_COUNT_MASK;
|
||||||
}
|
}
|
||||||
if (max_insns > TCG_MAX_INSNS) {
|
if (db->max_insns > TCG_MAX_INSNS) {
|
||||||
max_insns = TCG_MAX_INSNS;
|
db->max_insns = TCG_MAX_INSNS;
|
||||||
}
|
}
|
||||||
// Unicorn: commented out
|
// Unicorn: commented out
|
||||||
if (db->singlestep_enabled /*|| singlestep*/) {
|
if (db->singlestep_enabled /*|| singlestep*/) {
|
||||||
max_insns = 1;
|
db->max_insns = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
max_insns = ops->init_disas_context(db, cpu, max_insns);
|
ops->init_disas_context(db, cpu);
|
||||||
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
|
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */
|
||||||
|
|
||||||
/* Reset the temp count so that we can identify leaks */
|
/* Reset the temp count so that we can identify leaks */
|
||||||
|
@ -121,7 +120,8 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
|
||||||
update db->pc_next and db->is_jmp to indicate what should be
|
update db->pc_next and db->is_jmp to indicate what should be
|
||||||
done next -- either exiting this loop or locate the start of
|
done next -- either exiting this loop or locate the start of
|
||||||
the next instruction. */
|
the next instruction. */
|
||||||
if (db->num_insns == max_insns && (db->tb->cflags & CF_LAST_IO)) {
|
if (db->num_insns == db->max_insns
|
||||||
|
&& (db->tb->cflags & CF_LAST_IO)) {
|
||||||
/* Accept I/O on the last instruction. */
|
/* Accept I/O on the last instruction. */
|
||||||
//gen_io_start();
|
//gen_io_start();
|
||||||
ops->translate_insn(db, cpu);
|
ops->translate_insn(db, cpu);
|
||||||
|
@ -137,7 +137,7 @@ void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
|
||||||
|
|
||||||
/* Stop translation if the output buffer is full,
|
/* Stop translation if the output buffer is full,
|
||||||
or we have executed all of the allowed instructions. */
|
or we have executed all of the allowed instructions. */
|
||||||
if (tcg_op_buf_full(tcg_ctx) || db->num_insns >= max_insns) {
|
if (tcg_op_buf_full(tcg_ctx) || db->num_insns >= db->max_insns) {
|
||||||
db->is_jmp = DISAS_TOO_MANY;
|
db->is_jmp = DISAS_TOO_MANY;
|
||||||
db->uc->block_full = true;
|
db->uc->block_full = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -58,6 +58,7 @@ typedef enum DisasJumpType {
|
||||||
* disassembly).
|
* disassembly).
|
||||||
* @is_jmp: What instruction to disassemble next.
|
* @is_jmp: What instruction to disassemble next.
|
||||||
* @num_insns: Number of translated instructions (including current).
|
* @num_insns: Number of translated instructions (including current).
|
||||||
|
* @max_insns: Maximum number of instructions to be translated in this TB.
|
||||||
* @singlestep_enabled: "Hardware" single stepping enabled.
|
* @singlestep_enabled: "Hardware" single stepping enabled.
|
||||||
*
|
*
|
||||||
* Architecture-agnostic disassembly context.
|
* Architecture-agnostic disassembly context.
|
||||||
|
@ -67,7 +68,8 @@ typedef struct DisasContextBase {
|
||||||
target_ulong pc_first;
|
target_ulong pc_first;
|
||||||
target_ulong pc_next;
|
target_ulong pc_next;
|
||||||
DisasJumpType is_jmp;
|
DisasJumpType is_jmp;
|
||||||
unsigned int num_insns;
|
int num_insns;
|
||||||
|
int max_insns;
|
||||||
bool singlestep_enabled;
|
bool singlestep_enabled;
|
||||||
|
|
||||||
// Unicorn member variables
|
// Unicorn member variables
|
||||||
|
@ -79,7 +81,6 @@ typedef struct DisasContextBase {
|
||||||
* @init_disas_context:
|
* @init_disas_context:
|
||||||
* Initialize the target-specific portions of DisasContext struct.
|
* Initialize the target-specific portions of DisasContext struct.
|
||||||
* The generic DisasContextBase has already been initialized.
|
* The generic DisasContextBase has already been initialized.
|
||||||
* Return max_insns, modified as necessary by db->tb->flags.
|
|
||||||
*
|
*
|
||||||
* @tb_start:
|
* @tb_start:
|
||||||
* Emit any code required before the start of the main loop,
|
* Emit any code required before the start of the main loop,
|
||||||
|
@ -109,8 +110,7 @@ typedef struct DisasContextBase {
|
||||||
* Print instruction disassembly to log.
|
* Print instruction disassembly to log.
|
||||||
*/
|
*/
|
||||||
typedef struct TranslatorOps {
|
typedef struct TranslatorOps {
|
||||||
int (*init_disas_context)(DisasContextBase *db, CPUState *cpu,
|
void (*init_disas_context)(DisasContextBase *db, CPUState *cpu);
|
||||||
int max_insns);
|
|
||||||
void (*tb_start)(DisasContextBase *db, CPUState *cpu);
|
void (*tb_start)(DisasContextBase *db, CPUState *cpu);
|
||||||
void (*insn_start)(DisasContextBase *db, CPUState *cpu);
|
void (*insn_start)(DisasContextBase *db, CPUState *cpu);
|
||||||
bool (*breakpoint_check)(DisasContextBase *db, CPUState *cpu,
|
bool (*breakpoint_check)(DisasContextBase *db, CPUState *cpu,
|
||||||
|
|
|
@ -13397,8 +13397,8 @@ static void disas_a64_insn(CPUARMState *env, DisasContext *s)
|
||||||
free_tmp_a64(s);
|
free_tmp_a64(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int aarch64_tr_init_disas_context(DisasContextBase *dcbase,
|
static void aarch64_tr_init_disas_context(DisasContextBase *dcbase,
|
||||||
CPUState *cpu, int max_insns)
|
CPUState *cpu)
|
||||||
{
|
{
|
||||||
DisasContext *dc = container_of(dcbase, DisasContext, base);
|
DisasContext *dc = container_of(dcbase, DisasContext, base);
|
||||||
CPUARMState *env = cpu->env_ptr;
|
CPUARMState *env = cpu->env_ptr;
|
||||||
|
@ -13464,11 +13464,9 @@ static int aarch64_tr_init_disas_context(DisasContextBase *dcbase,
|
||||||
if (dc->ss_active) {
|
if (dc->ss_active) {
|
||||||
bound = 1;
|
bound = 1;
|
||||||
}
|
}
|
||||||
max_insns = MIN(max_insns, bound);
|
dc->base.max_insns = MIN(dc->base.max_insns, bound);
|
||||||
|
|
||||||
init_tmp_a64_array(dc);
|
init_tmp_a64_array(dc);
|
||||||
|
|
||||||
return max_insns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu)
|
static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu)
|
||||||
|
|
|
@ -12440,8 +12440,7 @@ static bool insn_crosses_page(CPUARMState *env, DisasContext *s)
|
||||||
return !thumb_insn_is_16bit(s, insn);
|
return !thumb_insn_is_16bit(s, insn);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int arm_tr_init_disas_context(DisasContextBase *dcbase,
|
static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs)
|
||||||
CPUState *cs, int max_insns)
|
|
||||||
{
|
{
|
||||||
TCGContext *tcg_ctx = cs->uc->tcg_ctx;
|
TCGContext *tcg_ctx = cs->uc->tcg_ctx;
|
||||||
DisasContext *dc = container_of(dcbase, DisasContext, base);
|
DisasContext *dc = container_of(dcbase, DisasContext, base);
|
||||||
|
@ -12504,14 +12503,14 @@ static int arm_tr_init_disas_context(DisasContextBase *dcbase,
|
||||||
|
|
||||||
/* If architectural single step active, limit to 1. */
|
/* If architectural single step active, limit to 1. */
|
||||||
if (is_singlestepping(dc)) {
|
if (is_singlestepping(dc)) {
|
||||||
max_insns = 1;
|
dc->base.max_insns = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ARM is a fixed-length ISA. Bound the number of insns to execute
|
/* ARM is a fixed-length ISA. Bound the number of insns to execute
|
||||||
to those left on the page. */
|
to those left on the page. */
|
||||||
if (!dc->thumb) {
|
if (!dc->thumb) {
|
||||||
int bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
|
int bound = -(dc->base.pc_first | TARGET_PAGE_MASK) / 4;
|
||||||
max_insns = MIN(max_insns, bound);
|
dc->base.max_insns = MIN(dc->base.max_insns, bound);
|
||||||
}
|
}
|
||||||
|
|
||||||
tcg_ctx->cpu_F0s = tcg_temp_new_i32(tcg_ctx);
|
tcg_ctx->cpu_F0s = tcg_temp_new_i32(tcg_ctx);
|
||||||
|
@ -12522,8 +12521,6 @@ static int arm_tr_init_disas_context(DisasContextBase *dcbase,
|
||||||
tcg_ctx->cpu_V1 = tcg_ctx->cpu_F1d;
|
tcg_ctx->cpu_V1 = tcg_ctx->cpu_F1d;
|
||||||
/* FIXME: tcg_ctx->cpu_M0 can probably be the same as tcg_ctx->cpu_V0. */
|
/* FIXME: tcg_ctx->cpu_M0 can probably be the same as tcg_ctx->cpu_V0. */
|
||||||
tcg_ctx->cpu_M0 = tcg_temp_new_i64(tcg_ctx);
|
tcg_ctx->cpu_M0 = tcg_temp_new_i64(tcg_ctx);
|
||||||
|
|
||||||
return max_insns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arm_tr_tb_start(DisasContextBase *dcbase, CPUState *cpu)
|
static void arm_tr_tb_start(DisasContextBase *dcbase, CPUState *cpu)
|
||||||
|
|
|
@ -9141,8 +9141,7 @@ void tcg_x86_init(struct uc_struct *uc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu,
|
static void i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu)
|
||||||
int max_insns)
|
|
||||||
{
|
{
|
||||||
DisasContext *dc = container_of(dcbase, DisasContext, base);
|
DisasContext *dc = container_of(dcbase, DisasContext, base);
|
||||||
CPUX86State *env = cpu->env_ptr;
|
CPUX86State *env = cpu->env_ptr;
|
||||||
|
@ -9217,8 +9216,6 @@ static int i386_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cpu,
|
||||||
|
|
||||||
// done with initializing TCG variables
|
// done with initializing TCG variables
|
||||||
env->uc->init_tcg = true;
|
env->uc->init_tcg = true;
|
||||||
|
|
||||||
return max_insns;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void i386_tr_tb_start(DisasContextBase *db, CPUState *cpu)
|
static void i386_tr_tb_start(DisasContextBase *db, CPUState *cpu)
|
||||||
|
|
Loading…
Reference in a new issue