accel/tcg: Add DisasContextBase argument to translator_ld*

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
[rth: Split out of a larger patch.]
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
Ilya Leoshkevich 2021-08-09 12:32:59 -10:00 committed by Richard Henderson
parent 4c9af1ea14
commit 4e116893c6
20 changed files with 58 additions and 50 deletions

View File

@ -157,7 +157,8 @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest);
#define GEN_TRANSLATOR_LD(fullname, type, load_fn, swap_fn) \ #define GEN_TRANSLATOR_LD(fullname, type, load_fn, swap_fn) \
static inline type \ static inline type \
fullname ## _swap(CPUArchState *env, abi_ptr pc, bool do_swap) \ fullname ## _swap(CPUArchState *env, DisasContextBase *dcbase, \
abi_ptr pc, bool do_swap) \
{ \ { \
type ret = load_fn(env, pc); \ type ret = load_fn(env, pc); \
if (do_swap) { \ if (do_swap) { \
@ -166,10 +167,10 @@ bool translator_use_goto_tb(DisasContextBase *db, target_ulong dest);
plugin_insn_append(&ret, sizeof(ret)); \ plugin_insn_append(&ret, sizeof(ret)); \
return ret; \ return ret; \
} \ } \
\ static inline type fullname(CPUArchState *env, \
static inline type fullname(CPUArchState *env, abi_ptr pc) \ DisasContextBase *dcbase, abi_ptr pc) \
{ \ { \
return fullname ## _swap(env, pc, false); \ return fullname ## _swap(env, dcbase, pc, false); \
} }
GEN_TRANSLATOR_LD(translator_ldub, uint8_t, cpu_ldub_code, /* no swap */) GEN_TRANSLATOR_LD(translator_ldub, uint8_t, cpu_ldub_code, /* no swap */)

View File

@ -2971,7 +2971,7 @@ static void alpha_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
{ {
DisasContext *ctx = container_of(dcbase, DisasContext, base); DisasContext *ctx = container_of(dcbase, DisasContext, base);
CPUAlphaState *env = cpu->env_ptr; CPUAlphaState *env = cpu->env_ptr;
uint32_t insn = translator_ldl(env, ctx->base.pc_next); uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next);
ctx->base.pc_next += 4; ctx->base.pc_next += 4;
ctx->base.is_jmp = translate_one(ctx, insn); ctx->base.is_jmp = translate_one(ctx, insn);

View File

@ -24,15 +24,15 @@
#include "qemu/bswap.h" #include "qemu/bswap.h"
/* Load an instruction and return it in the standard little-endian order */ /* Load an instruction and return it in the standard little-endian order */
static inline uint32_t arm_ldl_code(CPUARMState *env, target_ulong addr, static inline uint32_t arm_ldl_code(CPUARMState *env, DisasContextBase *s,
bool sctlr_b) target_ulong addr, bool sctlr_b)
{ {
return translator_ldl_swap(env, addr, bswap_code(sctlr_b)); return translator_ldl_swap(env, s, addr, bswap_code(sctlr_b));
} }
/* Ditto, for a halfword (Thumb) instruction */ /* Ditto, for a halfword (Thumb) instruction */
static inline uint16_t arm_lduw_code(CPUARMState *env, target_ulong addr, static inline uint16_t arm_lduw_code(CPUARMState *env, DisasContextBase* s,
bool sctlr_b) target_ulong addr, bool sctlr_b)
{ {
#ifndef CONFIG_USER_ONLY #ifndef CONFIG_USER_ONLY
/* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped /* In big-endian (BE32) mode, adjacent Thumb instructions have been swapped
@ -41,7 +41,7 @@ static inline uint16_t arm_lduw_code(CPUARMState *env, target_ulong addr,
addr ^= 2; addr ^= 2;
} }
#endif #endif
return translator_lduw_swap(env, addr, bswap_code(sctlr_b)); return translator_lduw_swap(env, s, addr, bswap_code(sctlr_b));
} }
#endif #endif

View File

@ -14772,7 +14772,7 @@ static void aarch64_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
} }
s->pc_curr = s->base.pc_next; s->pc_curr = s->base.pc_next;
insn = arm_ldl_code(env, s->base.pc_next, s->sctlr_b); insn = arm_ldl_code(env, &s->base, s->base.pc_next, s->sctlr_b);
s->insn = insn; s->insn = insn;
s->base.pc_next += 4; s->base.pc_next += 4;

View File

@ -9312,7 +9312,7 @@ static bool insn_crosses_page(CPUARMState *env, DisasContext *s)
* boundary, so we cross the page if the first 16 bits indicate * boundary, so we cross the page if the first 16 bits indicate
* that this is a 32 bit insn. * that this is a 32 bit insn.
*/ */
uint16_t insn = arm_lduw_code(env, s->base.pc_next, s->sctlr_b); uint16_t insn = arm_lduw_code(env, &s->base, s->base.pc_next, s->sctlr_b);
return !thumb_insn_is_16bit(s, s->base.pc_next, insn); return !thumb_insn_is_16bit(s, s->base.pc_next, insn);
} }
@ -9551,7 +9551,7 @@ static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
} }
dc->pc_curr = dc->base.pc_next; dc->pc_curr = dc->base.pc_next;
insn = arm_ldl_code(env, dc->base.pc_next, dc->sctlr_b); insn = arm_ldl_code(env, &dc->base, dc->base.pc_next, dc->sctlr_b);
dc->insn = insn; dc->insn = insn;
dc->base.pc_next += 4; dc->base.pc_next += 4;
disas_arm_insn(dc, insn); disas_arm_insn(dc, insn);
@ -9621,11 +9621,12 @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
} }
dc->pc_curr = dc->base.pc_next; dc->pc_curr = dc->base.pc_next;
insn = arm_lduw_code(env, dc->base.pc_next, dc->sctlr_b); insn = arm_lduw_code(env, &dc->base, dc->base.pc_next, dc->sctlr_b);
is_16bit = thumb_insn_is_16bit(dc, dc->base.pc_next, insn); is_16bit = thumb_insn_is_16bit(dc, dc->base.pc_next, insn);
dc->base.pc_next += 2; dc->base.pc_next += 2;
if (!is_16bit) { if (!is_16bit) {
uint32_t insn2 = arm_lduw_code(env, dc->base.pc_next, dc->sctlr_b); uint32_t insn2 = arm_lduw_code(env, &dc->base, dc->base.pc_next,
dc->sctlr_b);
insn = insn << 16 | insn2; insn = insn << 16 | insn2;
dc->base.pc_next += 2; dc->base.pc_next += 2;

View File

@ -112,7 +112,8 @@ static int read_packet_words(CPUHexagonState *env, DisasContext *ctx,
memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t)); memset(words, 0, PACKET_WORDS_MAX * sizeof(uint32_t));
for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) { for (nwords = 0; !found_end && nwords < PACKET_WORDS_MAX; nwords++) {
words[nwords] = words[nwords] =
translator_ldl(env, ctx->base.pc_next + nwords * sizeof(uint32_t)); translator_ldl(env, &ctx->base,
ctx->base.pc_next + nwords * sizeof(uint32_t));
found_end = is_packet_end(words[nwords]); found_end = is_packet_end(words[nwords]);
} }
if (!found_end) { if (!found_end) {

View File

@ -4177,7 +4177,7 @@ static void hppa_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
{ {
/* Always fetch the insn, even if nullified, so that we check /* Always fetch the insn, even if nullified, so that we check
the page permissions for execute. */ the page permissions for execute. */
uint32_t insn = translator_ldl(env, ctx->base.pc_next); uint32_t insn = translator_ldl(env, &ctx->base, ctx->base.pc_next);
/* Set up the IA queue for the next insn. /* Set up the IA queue for the next insn.
This will be overwritten by a branch. */ This will be overwritten by a branch. */

View File

@ -2028,28 +2028,28 @@ static uint64_t advance_pc(CPUX86State *env, DisasContext *s, int num_bytes)
static inline uint8_t x86_ldub_code(CPUX86State *env, DisasContext *s) static inline uint8_t x86_ldub_code(CPUX86State *env, DisasContext *s)
{ {
return translator_ldub(env, advance_pc(env, s, 1)); return translator_ldub(env, &s->base, advance_pc(env, s, 1));
} }
static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s) static inline int16_t x86_ldsw_code(CPUX86State *env, DisasContext *s)
{ {
return translator_ldsw(env, advance_pc(env, s, 2)); return translator_ldsw(env, &s->base, advance_pc(env, s, 2));
} }
static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s) static inline uint16_t x86_lduw_code(CPUX86State *env, DisasContext *s)
{ {
return translator_lduw(env, advance_pc(env, s, 2)); return translator_lduw(env, &s->base, advance_pc(env, s, 2));
} }
static inline uint32_t x86_ldl_code(CPUX86State *env, DisasContext *s) static inline uint32_t x86_ldl_code(CPUX86State *env, DisasContext *s)
{ {
return translator_ldl(env, advance_pc(env, s, 4)); return translator_ldl(env, &s->base, advance_pc(env, s, 4));
} }
#ifdef TARGET_X86_64 #ifdef TARGET_X86_64
static inline uint64_t x86_ldq_code(CPUX86State *env, DisasContext *s) static inline uint64_t x86_ldq_code(CPUX86State *env, DisasContext *s)
{ {
return translator_ldq(env, advance_pc(env, s, 8)); return translator_ldq(env, &s->base, advance_pc(env, s, 8));
} }
#endif #endif

View File

@ -415,7 +415,7 @@ static TCGv gen_ldst(DisasContext *s, int opsize, TCGv addr, TCGv val,
static inline uint16_t read_im16(CPUM68KState *env, DisasContext *s) static inline uint16_t read_im16(CPUM68KState *env, DisasContext *s)
{ {
uint16_t im; uint16_t im;
im = translator_lduw(env, s->pc); im = translator_lduw(env, &s->base, s->pc);
s->pc += 2; s->pc += 2;
return im; return im;
} }

View File

@ -1627,7 +1627,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx)
uint32_t op, minor, minor2, mips32_op; uint32_t op, minor, minor2, mips32_op;
uint32_t cond, fmt, cc; uint32_t cond, fmt, cc;
insn = translator_lduw(env, ctx->base.pc_next + 2); insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2);
ctx->opcode = (ctx->opcode << 16) | insn; ctx->opcode = (ctx->opcode << 16) | insn;
rt = (ctx->opcode >> 21) & 0x1f; rt = (ctx->opcode >> 21) & 0x1f;

View File

@ -455,7 +455,7 @@ static void decode_i64_mips16(DisasContext *ctx,
static int decode_extended_mips16_opc(CPUMIPSState *env, DisasContext *ctx) static int decode_extended_mips16_opc(CPUMIPSState *env, DisasContext *ctx)
{ {
int extend = translator_lduw(env, ctx->base.pc_next + 2); int extend = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2);
int op, rx, ry, funct, sa; int op, rx, ry, funct, sa;
int16_t imm, offset; int16_t imm, offset;
@ -688,7 +688,7 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx)
/* No delay slot, so just process as a normal instruction */ /* No delay slot, so just process as a normal instruction */
break; break;
case M16_OPC_JAL: case M16_OPC_JAL:
offset = translator_lduw(env, ctx->base.pc_next + 2); offset = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2);
offset = (((ctx->opcode & 0x1f) << 21) offset = (((ctx->opcode & 0x1f) << 21)
| ((ctx->opcode >> 5) & 0x1f) << 16 | ((ctx->opcode >> 5) & 0x1f) << 16
| offset) << 2; | offset) << 2;

View File

@ -3656,7 +3656,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
int offset; int offset;
int imm; int imm;
insn = translator_lduw(env, ctx->base.pc_next + 2); insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 2);
ctx->opcode = (ctx->opcode << 16) | insn; ctx->opcode = (ctx->opcode << 16) | insn;
rt = extract32(ctx->opcode, 21, 5); rt = extract32(ctx->opcode, 21, 5);
@ -3775,7 +3775,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
break; break;
case NM_P48I: case NM_P48I:
{ {
insn = translator_lduw(env, ctx->base.pc_next + 4); insn = translator_lduw(env, &ctx->base, ctx->base.pc_next + 4);
target_long addr_off = extract32(ctx->opcode, 0, 16) | insn << 16; target_long addr_off = extract32(ctx->opcode, 0, 16) | insn << 16;
switch (extract32(ctx->opcode, 16, 5)) { switch (extract32(ctx->opcode, 16, 5)) {
case NM_LI48: case NM_LI48:

View File

@ -16041,17 +16041,17 @@ static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
is_slot = ctx->hflags & MIPS_HFLAG_BMASK; is_slot = ctx->hflags & MIPS_HFLAG_BMASK;
if (ctx->insn_flags & ISA_NANOMIPS32) { if (ctx->insn_flags & ISA_NANOMIPS32) {
ctx->opcode = translator_lduw(env, ctx->base.pc_next); ctx->opcode = translator_lduw(env, &ctx->base, ctx->base.pc_next);
insn_bytes = decode_isa_nanomips(env, ctx); insn_bytes = decode_isa_nanomips(env, ctx);
} else if (!(ctx->hflags & MIPS_HFLAG_M16)) { } else if (!(ctx->hflags & MIPS_HFLAG_M16)) {
ctx->opcode = translator_ldl(env, ctx->base.pc_next); ctx->opcode = translator_ldl(env, &ctx->base, ctx->base.pc_next);
insn_bytes = 4; insn_bytes = 4;
decode_opc(env, ctx); decode_opc(env, ctx);
} else if (ctx->insn_flags & ASE_MICROMIPS) { } else if (ctx->insn_flags & ASE_MICROMIPS) {
ctx->opcode = translator_lduw(env, ctx->base.pc_next); ctx->opcode = translator_lduw(env, &ctx->base, ctx->base.pc_next);
insn_bytes = decode_isa_micromips(env, ctx); insn_bytes = decode_isa_micromips(env, ctx);
} else if (ctx->insn_flags & ASE_MIPS16) { } else if (ctx->insn_flags & ASE_MIPS16) {
ctx->opcode = translator_lduw(env, ctx->base.pc_next); ctx->opcode = translator_lduw(env, &ctx->base, ctx->base.pc_next);
insn_bytes = decode_ase_mips16e(env, ctx); insn_bytes = decode_ase_mips16e(env, ctx);
} else { } else {
gen_reserved_instruction(ctx); gen_reserved_instruction(ctx);

View File

@ -1613,7 +1613,7 @@ static void openrisc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
{ {
DisasContext *dc = container_of(dcbase, DisasContext, base); DisasContext *dc = container_of(dcbase, DisasContext, base);
OpenRISCCPU *cpu = OPENRISC_CPU(cs); OpenRISCCPU *cpu = OPENRISC_CPU(cs);
uint32_t insn = translator_ldl(&cpu->env, dc->base.pc_next); uint32_t insn = translator_ldl(&cpu->env, &dc->base, dc->base.pc_next);
if (!decode(dc, insn)) { if (!decode(dc, insn)) {
gen_illegal_exception(dc); gen_illegal_exception(dc);

View File

@ -8585,7 +8585,7 @@ static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
ctx->base.pc_next, ctx->mem_idx, (int)msr_ir); ctx->base.pc_next, ctx->mem_idx, (int)msr_ir);
ctx->cia = pc = ctx->base.pc_next; ctx->cia = pc = ctx->base.pc_next;
insn = translator_ldl_swap(env, pc, need_byteswap(ctx)); insn = translator_ldl_swap(env, dcbase, pc, need_byteswap(ctx));
ctx->base.pc_next = pc += 4; ctx->base.pc_next = pc += 4;
if (!is_prefix_insn(ctx, insn)) { if (!is_prefix_insn(ctx, insn)) {
@ -8600,7 +8600,8 @@ static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_INSN); gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_INSN);
ok = true; ok = true;
} else { } else {
uint32_t insn2 = translator_ldl_swap(env, pc, need_byteswap(ctx)); uint32_t insn2 = translator_ldl_swap(env, dcbase, pc,
need_byteswap(ctx));
ctx->base.pc_next = pc += 4; ctx->base.pc_next = pc += 4;
ok = decode_insn64(ctx, deposit64(insn2, 32, 32, insn)); ok = decode_insn64(ctx, deposit64(insn2, 32, 32, insn));
} }

View File

@ -500,7 +500,8 @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode)
} else { } else {
uint32_t opcode32 = opcode; uint32_t opcode32 = opcode;
opcode32 = deposit32(opcode32, 16, 16, opcode32 = deposit32(opcode32, 16, 16,
translator_lduw(env, ctx->base.pc_next + 2)); translator_lduw(env, &ctx->base,
ctx->base.pc_next + 2));
ctx->pc_succ_insn = ctx->base.pc_next + 4; ctx->pc_succ_insn = ctx->base.pc_next + 4;
if (!decode_insn32(ctx, opcode32)) { if (!decode_insn32(ctx, opcode32)) {
gen_exception_illegal(ctx); gen_exception_illegal(ctx);
@ -561,7 +562,7 @@ static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu)
{ {
DisasContext *ctx = container_of(dcbase, DisasContext, base); DisasContext *ctx = container_of(dcbase, DisasContext, base);
CPURISCVState *env = cpu->env_ptr; CPURISCVState *env = cpu->env_ptr;
uint16_t opcode16 = translator_lduw(env, ctx->base.pc_next); uint16_t opcode16 = translator_lduw(env, &ctx->base, ctx->base.pc_next);
decode_opc(env, ctx, opcode16); decode_opc(env, ctx, opcode16);
ctx->base.pc_next = ctx->pc_succ_insn; ctx->base.pc_next = ctx->pc_succ_insn;

View File

@ -388,14 +388,16 @@ static void update_cc_op(DisasContext *s)
} }
} }
static inline uint64_t ld_code2(CPUS390XState *env, uint64_t pc) static inline uint64_t ld_code2(CPUS390XState *env, DisasContext *s,
uint64_t pc)
{ {
return (uint64_t)cpu_lduw_code(env, pc); return (uint64_t)translator_lduw(env, &s->base, pc);
} }
static inline uint64_t ld_code4(CPUS390XState *env, uint64_t pc) static inline uint64_t ld_code4(CPUS390XState *env, DisasContext *s,
uint64_t pc)
{ {
return (uint64_t)(uint32_t)cpu_ldl_code(env, pc); return (uint64_t)(uint32_t)translator_ldl(env, &s->base, pc);
} }
static int get_mem_index(DisasContext *s) static int get_mem_index(DisasContext *s)
@ -6273,7 +6275,7 @@ static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s)
ilen = s->ex_value & 0xf; ilen = s->ex_value & 0xf;
op = insn >> 56; op = insn >> 56;
} else { } else {
insn = ld_code2(env, pc); insn = ld_code2(env, s, pc);
op = (insn >> 8) & 0xff; op = (insn >> 8) & 0xff;
ilen = get_ilen(op); ilen = get_ilen(op);
switch (ilen) { switch (ilen) {
@ -6281,10 +6283,10 @@ static const DisasInsn *extract_insn(CPUS390XState *env, DisasContext *s)
insn = insn << 48; insn = insn << 48;
break; break;
case 4: case 4:
insn = ld_code4(env, pc) << 32; insn = ld_code4(env, s, pc) << 32;
break; break;
case 6: case 6:
insn = (insn << 48) | (ld_code4(env, pc + 2) << 16); insn = (insn << 48) | (ld_code4(env, s, pc + 2) << 16);
break; break;
default: default:
g_assert_not_reached(); g_assert_not_reached();

View File

@ -1907,7 +1907,7 @@ static void decode_gusa(DisasContext *ctx, CPUSH4State *env)
/* Read all of the insns for the region. */ /* Read all of the insns for the region. */
for (i = 0; i < max_insns; ++i) { for (i = 0; i < max_insns; ++i) {
insns[i] = translator_lduw(env, pc + i * 2); insns[i] = translator_lduw(env, &ctx->base, pc + i * 2);
} }
ld_adr = ld_dst = ld_mop = -1; ld_adr = ld_dst = ld_mop = -1;
@ -2307,7 +2307,7 @@ static void sh4_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
} }
#endif #endif
ctx->opcode = translator_lduw(env, ctx->base.pc_next); ctx->opcode = translator_lduw(env, &ctx->base, ctx->base.pc_next);
decode_opc(ctx); decode_opc(ctx);
ctx->base.pc_next += 2; ctx->base.pc_next += 2;
} }

View File

@ -5855,7 +5855,7 @@ static void sparc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs)
CPUSPARCState *env = cs->env_ptr; CPUSPARCState *env = cs->env_ptr;
unsigned int insn; unsigned int insn;
insn = translator_ldl(env, dc->pc); insn = translator_ldl(env, &dc->base, dc->pc);
dc->base.pc_next += 4; dc->base.pc_next += 4;
disas_sparc_insn(dc, insn); disas_sparc_insn(dc, insn);

View File

@ -882,7 +882,8 @@ static int arg_copy_compare(const void *a, const void *b)
static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)
{ {
xtensa_isa isa = dc->config->isa; xtensa_isa isa = dc->config->isa;
unsigned char b[MAX_INSN_LENGTH] = {translator_ldub(env, dc->pc)}; unsigned char b[MAX_INSN_LENGTH] = {translator_ldub(env, &dc->base,
dc->pc)};
unsigned len = xtensa_op0_insn_len(dc, b[0]); unsigned len = xtensa_op0_insn_len(dc, b[0]);
xtensa_format fmt; xtensa_format fmt;
int slot, slots; int slot, slots;
@ -907,7 +908,7 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)
dc->base.pc_next = dc->pc + len; dc->base.pc_next = dc->pc + len;
for (i = 1; i < len; ++i) { for (i = 1; i < len; ++i) {
b[i] = translator_ldub(env, dc->pc + i); b[i] = translator_ldub(env, &dc->base, dc->pc + i);
} }
xtensa_insnbuf_from_chars(isa, dc->insnbuf, b, len); xtensa_insnbuf_from_chars(isa, dc->insnbuf, b, len);
fmt = xtensa_format_decode(isa, dc->insnbuf); fmt = xtensa_format_decode(isa, dc->insnbuf);