From 170f6e0b3b37d0412c892f294916d09b59762a72 Mon Sep 17 00:00:00 2001 From: "Emilio G. Cota" Date: Fri, 23 Feb 2018 20:13:54 -0500 Subject: [PATCH] tb: consistently use uint32_t for tb->flags We are inconsistent with the type of tb->flags: usage varies loosely between int and uint64_t. Settle to uint32_t everywhere, which is superior to both: at least one target (aarch64) uses the most significant bit in the u32, and uint64_t is wasteful. Compile-tested for all targets. Backports commit 89fee74a0f066dfd73830a7b5fa137e87888c870 from qemu --- qemu/cpu-exec.c | 2 +- qemu/include/exec/exec-all.h | 5 +++-- qemu/target-arm/cpu.h | 2 +- qemu/target-i386/cpu.h | 2 +- qemu/target-i386/translate.c | 2 +- qemu/target-m68k/cpu.h | 2 +- qemu/target-mips/cpu.h | 2 +- qemu/target-sparc/cpu.h | 2 +- qemu/translate-all.c | 10 +++++----- 9 files changed, 15 insertions(+), 14 deletions(-) diff --git a/qemu/cpu-exec.c b/qemu/cpu-exec.c index fc147a14..4b255499 100644 --- a/qemu/cpu-exec.c +++ b/qemu/cpu-exec.c @@ -388,7 +388,7 @@ static TranslationBlock *tb_find_fast(CPUState *cpu) CPUArchState *env = (CPUArchState *)cpu->env_ptr; TranslationBlock *tb; target_ulong cs_base, pc; - int flags; + uint32_t flags; /* we record a subset of the CPU state. It will always be the same before a given translated block diff --git a/qemu/include/exec/exec-all.h b/qemu/include/exec/exec-all.h index 4cb5e23b..517797ea 100644 --- a/qemu/include/exec/exec-all.h +++ b/qemu/include/exec/exec-all.h @@ -74,7 +74,8 @@ void QEMU_NORETURN cpu_resume_from_signal(CPUState *cpu, void *puc); void QEMU_NORETURN cpu_io_recompile(CPUState *cpu, uintptr_t retaddr); TranslationBlock *tb_gen_code(CPUState *cpu, - target_ulong pc, target_ulong cs_base, int flags, + target_ulong pc, target_ulong cs_base, + uint32_t flags, int cflags); void cpu_exec_init(CPUState *env, void *opaque); @@ -235,7 +236,7 @@ static inline void tlb_flush_by_mmuidx(CPUState *cpu, ...) struct TranslationBlock { target_ulong pc; /* simulated PC corresponding to this block (EIP + CS base) */ target_ulong cs_base; /* CS base for this block */ - uint64_t flags; /* flags defining in which context the code was generated */ + uint32_t flags; /* flags defining in which context the code was generated */ uint16_t size; /* size of target code for this block (1 <= size <= TARGET_PAGE_SIZE) */ uint16_t icount; diff --git a/qemu/target-arm/cpu.h b/qemu/target-arm/cpu.h index 9e946f60..6d6f78aa 100644 --- a/qemu/target-arm/cpu.h +++ b/qemu/target-arm/cpu.h @@ -2129,7 +2129,7 @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) } static inline void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, - target_ulong *cs_base, int *flags) + target_ulong *cs_base, uint32_t *flags) { if (is_a64(env)) { *pc = env->pc; diff --git a/qemu/target-i386/cpu.h b/qemu/target-i386/cpu.h index 3f3e9e34..d85b5186 100644 --- a/qemu/target-i386/cpu.h +++ b/qemu/target-i386/cpu.h @@ -1266,7 +1266,7 @@ void tcg_x86_init(struct uc_struct *); #include "exec/exec-all.h" static inline void cpu_get_tb_cpu_state(CPUX86State *env, target_ulong *pc, - target_ulong *cs_base, int *flags) + target_ulong *cs_base, uint32_t *flags) { *cs_base = env->segs[R_CS].base; *pc = *cs_base + env->eip; diff --git a/qemu/target-i386/translate.c b/qemu/target-i386/translate.c index ee9aa622..bd3ab9ad 100644 --- a/qemu/target-i386/translate.c +++ b/qemu/target-i386/translate.c @@ -8948,7 +8948,7 @@ void gen_intermediate_code(CPUX86State *env, TranslationBlock *tb) TCGContext *tcg_ctx = env->uc->tcg_ctx; DisasContext dc1, *dc = &dc1; target_ulong pc_ptr; - uint64_t flags; + uint32_t flags; target_ulong pc_start; target_ulong cs_base; int num_insns = 0; diff --git a/qemu/target-m68k/cpu.h b/qemu/target-m68k/cpu.h index 7fec3e9c..2d7b3029 100644 --- a/qemu/target-m68k/cpu.h +++ b/qemu/target-m68k/cpu.h @@ -240,7 +240,7 @@ int m68k_cpu_handle_mmu_fault(CPUState *cpu, vaddr address, int rw, #include "exec/cpu-all.h" static inline void cpu_get_tb_cpu_state(CPUM68KState *env, target_ulong *pc, - target_ulong *cs_base, int *flags) + target_ulong *cs_base, uint32_t *flags) { *pc = env->pc; *cs_base = 0; diff --git a/qemu/target-mips/cpu.h b/qemu/target-mips/cpu.h index 06d5fce0..1af6faec 100644 --- a/qemu/target-mips/cpu.h +++ b/qemu/target-mips/cpu.h @@ -837,7 +837,7 @@ static inline void restore_pamask(CPUMIPSState *env) } static inline void cpu_get_tb_cpu_state(CPUMIPSState *env, target_ulong *pc, - target_ulong *cs_base, int *flags) + target_ulong *cs_base, uint32_t *flags) { *pc = env->active_tc.PC; *cs_base = 0; diff --git a/qemu/target-sparc/cpu.h b/qemu/target-sparc/cpu.h index 377cce4e..a7632955 100644 --- a/qemu/target-sparc/cpu.h +++ b/qemu/target-sparc/cpu.h @@ -697,7 +697,7 @@ trap_state* cpu_tsptr(CPUSPARCState* env); #define TB_FLAG_AM_ENABLED (1 << 5) static inline void cpu_get_tb_cpu_state(CPUSPARCState *env, target_ulong *pc, - target_ulong *cs_base, int *flags) + target_ulong *cs_base, uint32_t *flags) { *pc = env->pc; *cs_base = env->npc; diff --git a/qemu/translate-all.c b/qemu/translate-all.c index 7dde730e..06ec6a0b 100644 --- a/qemu/translate-all.c +++ b/qemu/translate-all.c @@ -1159,7 +1159,7 @@ static void build_page_bitmap(PageDesc *p) TranslationBlock *tb_gen_code(CPUState *cpu, target_ulong pc, target_ulong cs_base, - int flags, int cflags) // qq + uint32_t flags, int cflags) { CPUArchState *env = cpu->env_ptr; TCGContext *tcg_ctx = env->uc->tcg_ctx; @@ -1320,7 +1320,7 @@ void tb_invalidate_phys_page_range(struct uc_struct *uc, tb_page_addr_t start, t int current_tb_modified = 0; target_ulong current_pc = 0; target_ulong current_cs_base = 0; - int current_flags = 0; + uint32_t current_flags = 0; #endif /* TARGET_HAS_PRECISE_SMC */ p = page_find(uc, start >> TARGET_PAGE_BITS); @@ -1427,7 +1427,7 @@ static void tb_invalidate_phys_page(struct uc_struct *uc, tb_page_addr_t addr, int current_tb_modified = 0; target_ulong current_pc = 0; target_ulong current_cs_base = 0; - int current_flags = 0; + uint32_t current_flags = 0; #endif addr &= TARGET_PAGE_MASK; @@ -1686,7 +1686,7 @@ void tb_check_watchpoint(CPUState *cpu) CPUArchState *env = cpu->env_ptr; target_ulong pc, cs_base; tb_page_addr_t addr; - int flags; + uint32_t flags; cpu_get_tb_cpu_state(env, &pc, &cs_base, &flags); addr = get_page_addr_code(env, pc); @@ -1706,7 +1706,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr) TranslationBlock *tb; uint32_t n, cflags; target_ulong pc, cs_base; - uint64_t flags; + uint32_t flags; tb = tb_find_pc(env->uc, retaddr); if (!tb) {