target/mips: Add emulation of misc nanoMIPS instructions (p_lsx)

Add emulation of nanoMIPS instructions situated in pool p_lsx, and
emulation of LSA instruction as well.

Backports commit eac5266459fb83e70fbf33f95c7c846f89df5c6a from qemu
This commit is contained in:
Yongbok Kim 2018-08-27 05:05:44 -04:00 committed by Lioncash
parent db0ca1924e
commit e9442a5ca9
No known key found for this signature in database
GPG Key ID: 4E3C3CC1031BA9C7

View File

@ -17202,17 +17202,17 @@ static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx)
save_cpu_state(ctx, 1);
gen_helper_ei(tcg_ctx, t0, tcg_ctx->cpu_env);
gen_store_gpr(ctx, t0, rt);
gen_store_gpr(tcg_ctx, t0, rt);
/* Stop translation as we may have switched the execution mode */
ctx->base.is_jmp = DISAS_STOP;
tcg_temp_free(tcg_ctx, t0);
}
break;
case NM_RDPGPR:
gen_load_srsgpr(rs, rt);
gen_load_srsgpr(ctx, rs, rt);
break;
case NM_WRPGPR:
gen_store_srsgpr(rs, rt);
gen_store_srsgpr(ctx, rs, rt);
break;
case NM_WAIT:
gen_cp0(env, ctx, OPC_WAIT, 0, 0);
@ -17235,6 +17235,125 @@ static void gen_pool32axf_nanomips_insn(CPUMIPSState *env, DisasContext *ctx)
}
}
static void gen_p_lsx(DisasContext *ctx, int rd, int rs, int rt)
{
TCGContext *tcg_ctx = ctx->uc->tcg_ctx;
TCGv t0, t1;
t0 = tcg_temp_new(tcg_ctx);
t1 = tcg_temp_new(tcg_ctx);
gen_load_gpr(ctx, t0, rs);
gen_load_gpr(ctx, t1, rt);
if ((extract32(ctx->opcode, 6, 1)) == 1) {
/* PP.LSXS instructions require shifting */
switch (extract32(ctx->opcode, 7, 4)) {
case NM_LHXS:
case NM_SHXS:
case NM_LHUXS:
tcg_gen_shli_tl(tcg_ctx, t0, t0, 1);
break;
case NM_LWXS:
case NM_SWXS:
case NM_LWC1XS:
case NM_SWC1XS:
tcg_gen_shli_tl(tcg_ctx, t0, t0, 2);
break;
case NM_LDC1XS:
case NM_SDC1XS:
tcg_gen_shli_tl(tcg_ctx, t0, t0, 3);
break;
}
}
gen_op_addr_add(ctx, t0, t0, t1);
switch (extract32(ctx->opcode, 7, 4)) {
case NM_LBX:
tcg_gen_qemu_ld_tl(ctx->uc, t0, t0, ctx->mem_idx,
MO_SB);
gen_store_gpr(tcg_ctx, t0, rd);
break;
case NM_LHX:
/*case NM_LHXS:*/
tcg_gen_qemu_ld_tl(ctx->uc, t0, t0, ctx->mem_idx,
MO_TESW);
gen_store_gpr(tcg_ctx, t0, rd);
break;
case NM_LWX:
/*case NM_LWXS:*/
tcg_gen_qemu_ld_tl(ctx->uc, t0, t0, ctx->mem_idx,
MO_TESL);
gen_store_gpr(tcg_ctx, t0, rd);
break;
case NM_LBUX:
tcg_gen_qemu_ld_tl(ctx->uc, t0, t0, ctx->mem_idx,
MO_UB);
gen_store_gpr(tcg_ctx, t0, rd);
break;
case NM_LHUX:
/*case NM_LHUXS:*/
tcg_gen_qemu_ld_tl(ctx->uc, t0, t0, ctx->mem_idx,
MO_TEUW);
gen_store_gpr(tcg_ctx, t0, rd);
break;
case NM_SBX:
gen_load_gpr(ctx, t1, rd);
tcg_gen_qemu_st_tl(ctx->uc, t1, t0, ctx->mem_idx,
MO_8);
break;
case NM_SHX:
/*case NM_SHXS:*/
gen_load_gpr(ctx, t1, rd);
tcg_gen_qemu_st_tl(ctx->uc, t1, t0, ctx->mem_idx,
MO_TEUW);
break;
case NM_SWX:
/*case NM_SWXS:*/
gen_load_gpr(ctx, t1, rd);
tcg_gen_qemu_st_tl(ctx->uc, t1, t0, ctx->mem_idx,
MO_TEUL);
break;
case NM_LWC1X:
/*case NM_LWC1XS:*/
case NM_LDC1X:
/*case NM_LDC1XS:*/
case NM_SWC1X:
/*case NM_SWC1XS:*/
case NM_SDC1X:
/*case NM_SDC1XS:*/
if (ctx->CP0_Config1 & (1 << CP0C1_FP)) {
check_cp1_enabled(ctx);
switch (extract32(ctx->opcode, 7, 4)) {
case NM_LWC1X:
/*case NM_LWC1XS:*/
gen_flt_ldst(ctx, OPC_LWC1, rd, t0);
break;
case NM_LDC1X:
/*case NM_LDC1XS:*/
gen_flt_ldst(ctx, OPC_LDC1, rd, t0);
break;
case NM_SWC1X:
/*case NM_SWC1XS:*/
gen_flt_ldst(ctx, OPC_SWC1, rd, t0);
break;
case NM_SDC1X:
/*case NM_SDC1XS:*/
gen_flt_ldst(ctx, OPC_SDC1, rd, t0);
break;
}
} else {
generate_exception_err(ctx, EXCP_CpU, 1);
}
break;
default:
generate_exception_end(ctx, EXCP_RI);
break;
}
tcg_temp_free(tcg_ctx, t0);
tcg_temp_free(tcg_ctx, t1);
}
static void gen_pool32f_nanomips_insn(DisasContext *ctx)
{
int rt, rs, rd;
@ -17539,7 +17658,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
TCGContext *tcg_ctx = ctx->uc->tcg_ctx;
uint16_t insn;
uint32_t op;
int rt, rs;
int rt, rs, rd;
int offset;
int imm;
@ -17548,6 +17667,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
rt = extract32(ctx->opcode, 21, 5);
rs = extract32(ctx->opcode, 16, 5);
rd = extract32(ctx->opcode, 11, 5);
op = extract32(ctx->opcode, 26, 6);
switch (op) {
@ -17608,6 +17728,16 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx)
break;
case NM_POOL32A7:
switch (extract32(ctx->opcode, 3, 3)) {
case NM_P_LSX:
gen_p_lsx(ctx, rd, rs, rt);
break;
case NM_LSA:
/* In nanoMIPS, the shift field directly encodes the shift
* amount, meaning that the supported shift values are in
* the range 0 to 3 (instead of 1 to 4 in MIPSR6). */
gen_lsa(ctx, OPC_LSA, rd, rs, rt,
extract32(ctx->opcode, 9, 2) - 1);
break;
case NM_POOL32AXF:
gen_pool32axf_nanomips_insn(env, ctx);
break;