target/mips: Start converting MIPS16e/micro/nanoMIPS to decodetree
v4 cover target/mips: Start converting MIPS16e/micro/nanoMIPS to decodetree
Missing review: patches 3, 4, 10, 13, 14
Since v3:
- Rebased; v3 patches 1-3 and 5 were merged
- Use translator_ld*_end() with mo_endian()
- Select decoders from the instruction size (Richard)
- New patch 4, computing the microMIPS size up front (Richard)
- Treat MIPS16e JAL/JALX as 32-bit
- Add micromips32_r6.decode; LSA no longer accepted on pre-R6 microMIPS CPUs
- Fix MIPS16e EXT-RI LI immediate field order
- Fix nanoMIPS LI[16] register map and unsigned immediate
- Fix nanoMIPS LI[48] immediate halfword order; split the NMS check into trans_LI_nnms(), reusing check_nms()
- New patch 10, sharing the MIPS16e/microMIPS GPR xlat map
Prepare the build system and the per-ISA dispatchers so MIPS16e, microMIPS and nanoMIPS opcodes can be decoded with the decodetree script, then convert the first opcodes: LSA and LI.
v3: https://lore.kernel.org/qemu-devel/[email protected]/
Philippe Mathieu-Daudé (14):
target/mips: Call translator_ld() in translate_insn() callees target/mips: Decode LSA shift amount using decodetree function target/mips: Introduce decode tree bindings for MIPS16e ASE target/mips: Determine microMIPS insn size before delay slot check target/mips: Introduce decodetree bindings for microMIPS ISA scripts/decodetree: Add support for 48-bit instructions target/mips: Introduce decode tree bindings for nanoMIPS ISA target/mips: Convert microMIPS LSA opcode to decodetree target/mips: Convert nanoMIPS LSA opcode to decodetree target/mips: Share MIPS16e/microMIPS 3-bit GPR xlat mapping target/mips: Add gen_li() helper
target/mips: Convert microMIPS LI opcode to decodetree target/mips: Convert MIPS16e LI opcodes to decodetree target/mips: Convert nanoMIPS LI opcodes to decodetree
target/mips/tcg/translate.h | 11 ++ target/mips/tcg/micromips16.decode | 18 +++ target/mips/tcg/micromips32.decode | 11 ++ target/mips/tcg/micromips32_r6.decode | 19 +++ target/mips/tcg/mips16e_16.decode | 17 +++ target/mips/tcg/mips16e_32.decode | 18 +++ target/mips/tcg/msa.decode | 3 +- target/mips/tcg/nanomips16.decode | 17 +++ target/mips/tcg/nanomips32.decode | 14 ++ target/mips/tcg/nanomips48.decode | 16 +++ target/mips/tcg/rel6.decode | 5 +- target/mips/tcg/comput_translate.c | 21 +++ target/mips/tcg/micromips_translate.c | 37 ++++++ target/mips/tcg/mips16e_translate.c | 21 +++ target/mips/tcg/msa_translate.c | 4 +- target/mips/tcg/nanomips_translate.c | 46 +++++++ target/mips/tcg/rel6_translate.c | 9 +- target/mips/tcg/translate.c | 24 ++-- target/mips/tcg/micromips_translate.c.inc | 152 +++++++++++----------- target/mips/tcg/mips16e_translate.c.inc | 56 ++++---- target/mips/tcg/nanomips_translate.c.inc | 56 ++++---- scripts/decodetree.py | 4 + target/mips/tcg/meson.build | 12 ++ 23 files changed, 447 insertions(+), 144 deletions(-) create mode 100644 target/mips/tcg/micromips16.decode create mode 100644 target/mips/tcg/micromips32.decode create mode 100644 target/mips/tcg/micromips32_r6.decode create mode 100644 target/mips/tcg/mips16e_16.decode create mode 100644 target/mips/tcg/mips16e_32.decode create mode 100644 target/mips/tcg/nanomips16.decode create mode 100644 target/mips/tcg/nanomips32.decode create mode 100644 target/mips/tcg/nanomips48.decode create mode 100644 target/mips/tcg/comput_translate.c create mode 100644 target/mips/tcg/micromips_translate.c create mode 100644 target/mips/tcg/mips16e_translate.c create mode 100644 target/mips/tcg/nanomips_translate.c
Signature · 1 line
2.55.0
PATCH v4 1/14 target/mips: Call translator_ld() in translate_insn() callees
From: Philippe Mathieu-Daudé <[email protected]>
Historically we were only calling decode_opc() from the MIPS translate_insn() handler. Then variable instruction length ISAs were added, we kept using the same pattern but call yet more translator_ld() in the callees when necessary.
This is cumbersome and bug prone, so better move all translator_ld() calls to the callees where it is more logical.
---
Since v3:
- Rebased on translator_ld*_end() API, passing mo_endian()
--- target/mips/tcg/translate.c | 11 +++-------- target/mips/tcg/micromips_translate.c.inc | 4 ++++ target/mips/tcg/mips16e_translate.c.inc | 9 ++++++--- target/mips/tcg/nanomips_translate.c.inc | 13 ++++++++++--- 4 files changed, 23 insertions(+), 14 deletions(-)
target/mips/tcg/translate.c +3 -8
@@ -15050,6 +15050,9 @@ static void decode_opc(CPUMIPSState *env, DisasContext *ctx)gen_set_label (l1); } + ctx->opcode =translator_ldl_end (env, &ctx->base, ctx->base.pc_next, +mo_endian (ctx)); +/* Transition to the auto-generated decoder. */ /* Vendor specific extensions */
@@ -15175,21 +15178,13 @@ static void mips_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) is_slot = ctx->hflags &MIPS_HFLAG_BMASK ;if (ctx->insn_flags &ISA_NANOMIPS32 ) { - ctx->opcode =translator_lduw_end (env, &ctx->base, ctx->base.pc_next, -mo_endian (ctx)); insn_bytes =decode_isa_nanomips (env, ctx); }else if (!(ctx->hflags &MIPS_HFLAG_M16 )) { - ctx->opcode =translator_ldl_end (env, &ctx->base, ctx->base.pc_next, -mo_endian (ctx)); insn_bytes =4 ;decode_opc (env, ctx); }else if (ctx->insn_flags &ASE_MICROMIPS ) { - ctx->opcode =translator_lduw_end (env, &ctx->base, ctx->base.pc_next, -mo_endian (ctx)); insn_bytes =decode_isa_micromips (env, ctx); }else if (ctx->insn_flags &ASE_MIPS16 ) { - ctx->opcode =translator_lduw_end (env, &ctx->base, ctx->base.pc_next, -mo_endian (ctx)); insn_bytes =decode_ase_mips16e (env, ctx); }else {gen_reserved_instruction (ctx);
target/mips/tcg/micromips_translate.c.inc +4 -0
@@ -2979,6 +2979,7 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx) static int decode_isa_micromips(CPUMIPSState *env, DisasContext *ctx) { + uint32_t opcode; uint32_t op; /* make sure instructions are on a halfword boundary */
@@ -2988,6 +2989,9 @@ static int decode_isa_micromips(CPUMIPSState *env, DisasContext *ctx) return 2; } + opcode = translator_lduw_end(env, &ctx->base, ctx->base.pc_next, + mo_endian(ctx)); + ctx->opcode = opcode; op = (ctx->opcode >> 10) & 0x3f; /* Enforce properly-sized instructions in a delay slot */ if (ctx->hflags & MIPS_HFLAG_BDS_STRICT) {
target/mips/tcg/mips16e_translate.c.inc +6 -3
@@ -453,12 +453,9 @@ static void decode_i64_mips16(DisasContext *ctx, static int decode_extended_mips16_opc(CPUMIPSState *env, DisasContext *ctx) { - int extend = translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, - mo_endian(ctx)); int op, rx, ry, funct, sa; int16_t imm, offset; - ctx->opcode = (ctx->opcode << 16) | extend; op = (ctx->opcode >> 11) & 0x1f; sa = (ctx->opcode >> 22) & 0x1f; funct = (ctx->opcode >> 8) & 0x7;
@@ -659,6 +656,8 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) int funct; int n_bytes; + ctx->opcode = translator_lduw_end(env, &ctx->base, ctx->base.pc_next, + mo_endian(ctx)); op = (ctx->opcode >> 11) & 0x1f; sa = (ctx->opcode >> 2) & 0x7; sa = sa == 0 ? 8 : sa;
@@ -1105,6 +1104,10 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) } break; case M16_OPC_EXTEND: + ctx->opcode <<= 16; + ctx->opcode |= translator_lduw_end(env, &ctx->base, + ctx->base.pc_next + 2, + mo_endian(ctx)); decode_extended_mips16_opc(env, ctx); n_bytes = 4; break;
target/mips/tcg/nanomips_translate.c.inc +10 -3
@@ -4463,10 +4463,11 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) { + uint64_t opcode; uint32_t op; - int rt = decode_gpr_gpr3(NANOMIPS_EXTRACT_RT3(ctx->opcode)); - int rs = decode_gpr_gpr3(NANOMIPS_EXTRACT_RS3(ctx->opcode)); - int rd = decode_gpr_gpr3(NANOMIPS_EXTRACT_RD3(ctx->opcode)); + int rt; + int rs; + int rd; int offset; int imm;
@@ -4478,6 +4479,12 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) return 2; } + opcode = translator_lduw_end(env, &ctx->base, ctx->base.pc_next, + mo_endian(ctx)); + ctx->opcode = opcode; + rt = decode_gpr_gpr3(NANOMIPS_EXTRACT_RT3(ctx->opcode)); + rs = decode_gpr_gpr3(NANOMIPS_EXTRACT_RS3(ctx->opcode)); + rd = decode_gpr_gpr3(NANOMIPS_EXTRACT_RD3(ctx->opcode)); op = extract32(ctx->opcode, 10, 6); switch (op) { case NM_P16_MV:
Signature · 1 line
2.55.0
PATCH v4 2/14 target/mips: Decode LSA shift amount using decodetree function
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Message-Id: <[email protected]>
---
Since v3:
- Rebased on top of CRC32 support
- plus_1() no longer declared inline
--- target/mips/tcg/msa.decode | 3 ++- target/mips/tcg/rel6.decode | 5 +++-- target/mips/tcg/msa_translate.c | 4 ++-- target/mips/tcg/rel6_translate.c | 9 +++++++-- 4 files changed, 14 insertions(+), 7 deletions(-)
target/mips/tcg/msa.decode +2 -1
@@ -21,6 +21,7 @@ &msa_elm_df df wd ws n &msa_elm wd ws +%lsa_sa 6:2 !function=plus_1 %elm_df 16:6 !function=elm_df %elm_n 16:6 !function=elm_n %bit_df 16:7 !function=bit_df
@@ -29,7 +30,7 @@ %3r_df_h 21:1 !function=plus_1 %3r_df_w 21:1 !function=plus_2 -@lsa ...... rs:5 rt:5 rd:5 ... sa:2 ...... &r +@lsa ...... rs:5 rt:5 rd:5 ... .. ...... &r sa=%lsa_sa @ldst ...... sa:s10 ws:5 wd:5 .... df:2 &msa_i @bz_v ...... ... .. wt:5 sa:s16 &msa_bz df=3 @bz ...... ... df:2 wt:5 sa:s16 &msa_bz
target/mips/tcg/rel6.decode +3 -2
@@ -15,11 +15,12 @@ # (Document Number: MD00087-2B-MIPS64BIS-AFP-6.06) &r rs rt rd sa - &special3_crc rs rt c sz -@lsa ...... rs:5 rt:5 rd:5 ... sa:2 ...... &r +%lsa_sa 6:2 !function=plus_1 + @crc32 ...... rs:5 rt:5 ..... c:3 sz:2 ...... &special3_crc +@lsa ...... rs:5 rt:5 rd:5 ... .. ...... &r sa=%lsa_sa LSA 000000 ..... ..... ..... 000 .. 000101 @lsa DLSA 000000 ..... ..... ..... 000 .. 010101 @lsa
target/mips/tcg/msa_translate.c +2 -2
@@ -780,7 +780,7 @@ TRANS_DF_iv(ST, trans_msa_ldst, gen_helper_msa_st);static bool trans_LSA (DisasContext *ctx,arg_r *a) { -return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa +1 ); +return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa); }static bool trans_DLSA (DisasContext *ctx,arg_r *a)
@@ -788,5 +788,5 @@ static bool trans_DLSA(DisasContext *ctx, arg_r *a)if (TARGET_LONG_BITS !=64 ) {return false; } -return gen_dlsa (ctx, a->rd, a->rt, a->rs, a->sa +1 ); +return gen_dlsa (ctx, a->rd, a->rt, a->rs, a->sa); }
target/mips/tcg/rel6_translate.c +7 -2
@@ -11,6 +11,11 @@#include "qemu/osdep.h" #include "translate.h" +static int plus_1 (DisasContext *ctx,int x) +{ +return x +1 ; +} +/* Include the auto-generated decoders. */ #include "decode-rel6.c.inc"
@@ -23,7 +28,7 @@ bool trans_REMOVED(DisasContext *ctx, arg_REMOVED *a)static bool trans_LSA (DisasContext *ctx,arg_r *a) { -return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa +1 ); +return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa); }static bool trans_DLSA (DisasContext *ctx,arg_r *a)
@@ -31,7 +36,7 @@ static bool trans_DLSA(DisasContext *ctx, arg_r *a)if (TARGET_LONG_BITS !=64 ) {return false; } -return gen_dlsa (ctx, a->rd, a->rt, a->rs, a->sa +1 ); +return gen_dlsa (ctx, a->rd, a->rt, a->rs, a->sa); }static bool trans_CRC32 (DisasContext *ctx,arg_special3_crc *a)
Signature · 1 line
2.55.0
PATCH v4 3/14 target/mips: Introduce decode tree bindings for MIPS16e ASE
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Introduce the MIPS16e decodetree configs for the 16-bit and 32-bit instructions.
EXTEND-prefixed and JAL/JALX instructions are 32-bit, all others are 16-bit. Call the matching decoder, loading the second halfword only for 32-bit instructions. Unmatched opcodes fall back to the legacy decoder.
---
Since v3:
- Only call the 32-bit decoder for EXTEND-prefixed opcodes, loading the second halfword only then (rth)
- Treat JAL/JALX as 32-bit instructions
--- target/mips/tcg/translate.h | 2 ++ target/mips/tcg/mips16e_16.decode | 9 +++++++++ target/mips/tcg/mips16e_32.decode | 9 +++++++++ target/mips/tcg/mips16e_translate.c | 14 ++++++++++++++ target/mips/tcg/mips16e_translate.c.inc | 17 ++++++++++++++++- target/mips/tcg/meson.build | 3 +++ 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 target/mips/tcg/mips16e_16.decode create mode 100644 target/mips/tcg/mips16e_32.decode create mode 100644 target/mips/tcg/mips16e_translate.c
target/mips/tcg/translate.h +2 -0
@@ -227,6 +227,8 @@ bool decode_64bit_enabled(DisasContext *ctx);/* decodetree generated */ bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn); +bool decode_ase_mips16e_16 (DisasContext *ctx,uint16_t insn); +bool decode_ase_mips16e_32 (DisasContext *ctx,uint32_t insn);bool decode_ase_msa (DisasContext *ctx,uint32_t insn);bool decode_ext_txx9 (DisasContext *ctx,uint32_t insn);bool decode_ext_loongson (DisasContext *ctx,uint32_t insn);
target/mips/tcg/mips16e_16.decode new file +9 -0
@@ -0,0 +1,9 @@ +# MIPS16e 16-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: MIPS Architecture for Programmers, Volume IV-a +# The MIPS16e Application Specific Extension +# (Document Number: MD00076)
target/mips/tcg/mips16e_32.decode new file +9 -0
@@ -0,0 +1,9 @@ +# MIPS16e 32-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: MIPS Architecture for Programmers, Volume IV-a +# The MIPS16e Application Specific Extension +# (Document Number: MD00076)
target/mips/tcg/mips16e_translate.c new file +14 -0
@@ -0,0 +1,14 @@ +/* +* MIPS emulation for QEMU - MIPS16e translation routines +* +* Copyright (c) 2021 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "translate.h" + +/* Include the auto-generated decoders. */ +#include "decode-mips16e_16.c.inc" +#include "decode-mips16e_32.c.inc"
target/mips/tcg/mips16e_translate.c.inc +16 -1
@@ -658,7 +658,22 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) ctx->opcode = translator_lduw_end(env, &ctx->base, ctx->base.pc_next, mo_endian(ctx)); - op = (ctx->opcode >> 11) & 0x1f; + + op = extract32(ctx->opcode, 11, 5); + /* EXTEND-prefixed and JAL/JALX instructions are 32-bit */ + if (op == M16_OPC_EXTEND || op == M16_OPC_JAL) { + uint32_t opcode; + + opcode = ctx->opcode << 16; + opcode |= translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, + mo_endian(ctx)); + if (decode_ase_mips16e_32(ctx, opcode)) { + return 4; + } + } else if (decode_ase_mips16e_16(ctx, ctx->opcode)) { + return 2; + } + sa = (ctx->opcode >> 2) & 0x7; sa = sa == 0 ? 8 : sa; rx = xlat((ctx->opcode >> 8) & 0x7);
target/mips/tcg/meson.build +3 -0
@@ -1,4 +1,6 @@ gen = [ + decodetree.process('mips16e_16.decode', extra_args: ['--decode=decode_ase_mips16e_16', '--insnwidth=16']), + decodetree.process('mips16e_32.decode', extra_args: ['--decode=decode_ase_mips16e_32']), decodetree.process('rel6.decode', extra_args: ['--decode=decode_isa_rel6']), decodetree.process('msa.decode', extra_args: '--decode=decode_ase_msa'), decodetree.process('tx79.decode', extra_args: '--static-decode=decode_tx79'),
@@ -16,6 +18,7 @@ mips_ss.add(files( 'fpu_helper.c', 'ldst_helper.c', 'lmmi_helper.c', + 'mips16e_translate.c', 'msa_helper.c', 'msa_translate.c', 'octeon_crypto.c',
Signature · 1 line
2.55.0
Re: [PATCH v4 03/14] target/mips: Introduce decode tree bindings for MIPS16e ASE
Quoted 10 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé<[email protected]>
Introduce the MIPS16e decodetree configs for the 16-bit and 32-bit instructions.
EXTEND-prefixed and JAL/JALX instructions are 32-bit, all others are 16-bit. Call the matching decoder, loading the second halfword only for 32-bit instructions. Unmatched opcodes fall back to the legacy decoder.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
Since v3:
- Only call the 32-bit decoder for EXTEND-prefixed opcodes, loading the second halfword only then (rth)
- Treat JAL/JALX as 32-bit instructions
---
r~
PATCH v4 4/14 target/mips: Determine microMIPS insn size before delay slot check
In reply to Philippe Mathieu-DaudéCompute whether the instruction is 16-bit or 32-bit unconditionally, then use the result for the delay slot size check. The default case is unreachable. No functional change.
The size will be used to select the 16-bit or 32-bit decodetree decoder in the next commit.
--- target/mips/tcg/micromips_translate.c.inc | 59 ++++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-)
target/mips/tcg/micromips_translate.c.inc +30 -29
@@ -2981,6 +2981,7 @@ static int decode_isa_micromips(CPUMIPSState *env, DisasContext *ctx) { uint32_t opcode; uint32_t op; + bool is_16bit; /* make sure instructions are on a halfword boundary */ if (ctx->base.pc_next & 0x1) {
@@ -2993,36 +2994,36 @@ static int decode_isa_micromips(CPUMIPSState *env, DisasContext *ctx) mo_endian(ctx)); ctx->opcode = opcode; op = (ctx->opcode >> 10) & 0x3f; + switch (op & 0x7) { /* MSB-3..MSB-5 */ + case 0: + /* POOL32A, POOL32B, POOL32I, POOL32C */ + case 4: + /* ADDI32, ADDIU32, ORI32, XORI32, SLTI32, SLTIU32, ANDI32, JALX32 */ + case 5: + /* LBU32, LHU32, POOL32F, JALS32, BEQ32, BNE32, J32, JAL32 */ + case 6: + /* SB32, SH32, ADDIUPC, SWC132, SDC132, SW32 */ + case 7: + /* LB32, LH32, LWC132, LDC132, LW32 */ + is_16bit = false; + break; + case 1: + /* POOL16A, POOL16B, POOL16C, LWGP16, POOL16F */ + case 2: + /* LBU16, LHU16, LWSP16, LW16, SB16, SH16, SWSP16, SW16 */ + case 3: + /* MOVE16, ANDI16, POOL16D, POOL16E, BEQZ16, BNEZ16, B16, LI16 */ + is_16bit = true; + break; + default: + g_assert_not_reached(); + } + /* Enforce properly-sized instructions in a delay slot */ - if (ctx->hflags & MIPS_HFLAG_BDS_STRICT) { - switch (op & 0x7) { /* MSB-3..MSB-5 */ - case 0: - /* POOL32A, POOL32B, POOL32I, POOL32C */ - case 4: - /* ADDI32, ADDIU32, ORI32, XORI32, SLTI32, SLTIU32, ANDI32, JALX32 */ - case 5: - /* LBU32, LHU32, POOL32F, JALS32, BEQ32, BNE32, J32, JAL32 */ - case 6: - /* SB32, SH32, ADDIUPC, SWC132, SDC132, SW32 */ - case 7: - /* LB32, LH32, LWC132, LDC132, LW32 */ - if (ctx->hflags & MIPS_HFLAG_BDS16) { - gen_reserved_instruction(ctx); - return 2; - } - break; - case 1: - /* POOL16A, POOL16B, POOL16C, LWGP16, POOL16F */ - case 2: - /* LBU16, LHU16, LWSP16, LW16, SB16, SH16, SWSP16, SW16 */ - case 3: - /* MOVE16, ANDI16, POOL16D, POOL16E, BEQZ16, BNEZ16, B16, LI16 */ - if (ctx->hflags & MIPS_HFLAG_BDS32) { - gen_reserved_instruction(ctx); - return 2; - } - break; - } + if ((ctx->hflags & MIPS_HFLAG_BDS_STRICT) + && (ctx->hflags & (is_16bit ? MIPS_HFLAG_BDS32 : MIPS_HFLAG_BDS16))) { + gen_reserved_instruction(ctx); + return 2; } switch (op) {
Signature · 1 line
2.55.0
Re: [PATCH v4 04/14] target/mips: Determine microMIPS insn size before delay slot check
Quoted 4 lines · Philippe Mathieu-Daudé
Compute whether the instruction is 16-bit or 32-bit unconditionally, then use the result for the delay slot size check. The default case is unreachable. No functional change.
Quoted 8 lines
The size will be used to select the 16-bit or 32-bit decodetree decoder in the next commit.
Suggested-by Richard Henderson<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/micromips_translate.c.inc | 59 ++++++++++++----------- 1 file changed, 30 insertions(+), 29 deletions(-)
r~
PATCH v4 5/14 target/mips: Introduce decodetree bindings for microMIPS ISA
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Add empty decodetree files for the microMIPS 16-bit and 32-bit instructions, and micromips32_r6.decode for the 32-bit encodings only valid on Release 6.
Select the 16-bit or 32-bit decoder from the instruction size, loading the second halfword only for 32-bit instructions. The R6 decoder is only called on R6 CPUs, like decode_isa_rel6() in decode_opc(), so its patterns need no check_insn(ISA_MIPS_R6). Unmatched opcodes fall back to the legacy decoder.
---
Since v3:
- Select the decoder from the instruction size, instead of calling it from the delay slot check (rth)
- Only load the second halfword for 32-bit instructions
- Add micromips32_r6.decode, only called on R6 CPUs
--- target/mips/tcg/translate.h | 3 +++ target/mips/tcg/micromips16.decode | 11 +++++++++++ target/mips/tcg/micromips32.decode | 11 +++++++++++ target/mips/tcg/micromips32_r6.decode | 11 +++++++++++ target/mips/tcg/micromips_translate.c | 15 +++++++++++++++ target/mips/tcg/micromips_translate.c.inc | 17 +++++++++++++++++ target/mips/tcg/meson.build | 4 ++++ 7 files changed, 72 insertions(+) create mode 100644 target/mips/tcg/micromips16.decode create mode 100644 target/mips/tcg/micromips32.decode create mode 100644 target/mips/tcg/micromips32_r6.decode create mode 100644 target/mips/tcg/micromips_translate.c
target/mips/tcg/translate.h +3 -0
@@ -226,6 +226,9 @@ bool decode_ase_mxu(DisasContext *ctx, uint32_t insn);bool decode_64bit_enabled (DisasContext *ctx);/* decodetree generated */ +bool decode_isa_micromips16 (DisasContext *ctx,uint16_t insn); +bool decode_isa_micromips32 (DisasContext *ctx,uint32_t insn); +bool decode_isa_micromips32_r6 (DisasContext *ctx,uint32_t insn);bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn);bool decode_ase_mips16e_16 (DisasContext *ctx,uint16_t insn);bool decode_ase_mips16e_32 (DisasContext *ctx,uint32_t insn);
target/mips/tcg/micromips16.decode new file +11 -0
@@ -0,0 +1,11 @@ +# microMIPS32 16-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: MIPS Architecture for Programmers, Volume II-B +# microMIPS32 Instruction Set +# (Document Number: MD00582) +# microMIPS64 Instruction Set +# (Document Number: MD00594)
target/mips/tcg/micromips32.decode new file +11 -0
@@ -0,0 +1,11 @@ +# microMIPS32 32-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: MIPS Architecture for Programmers, Volume II-B +# microMIPS32 Instruction Set +# (Document Number: MD00582) +# microMIPS64 Instruction Set +# (Document Number: MD00594)
target/mips/tcg/micromips32_r6.decode new file +11 -0
@@ -0,0 +1,11 @@ +# microMIPS32 Release 6 32-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: MIPS Architecture for Programmers, Volume II-B +# microMIPS32 Instruction Set +# (Document Number: MD00582) +# microMIPS64 Instruction Set +# (Document Number: MD00594)
target/mips/tcg/micromips_translate.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* MIPS emulation for QEMU - microMIPS translation routines +* +* Copyright (c) 2021 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "translate.h" + +/* Include the auto-generated decoders. */ +#include "decode-micromips16.c.inc" +#include "decode-micromips32.c.inc" +#include "decode-micromips32_r6.c.inc"
target/mips/tcg/micromips_translate.c.inc +17 -0
@@ -3026,6 +3026,23 @@ static int decode_isa_micromips(CPUMIPSState *env, DisasContext *ctx) return 2; } + if (is_16bit) { + if (decode_isa_micromips16(ctx, opcode)) { + return 2; + } + } else { + opcode <<= 16; + opcode |= translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, + mo_endian(ctx)); + if (cpu_supports_isa(env, ISA_MIPS_R6) + && decode_isa_micromips32_r6(ctx, opcode)) { + return 4; + } + if (decode_isa_micromips32(ctx, opcode)) { + return 4; + } + } + switch (op) { case POOL16A: {
target/mips/tcg/meson.build +4 -0
@@ -1,6 +1,9 @@ gen = [ decodetree.process('mips16e_16.decode', extra_args: ['--decode=decode_ase_mips16e_16', '--insnwidth=16']), decodetree.process('mips16e_32.decode', extra_args: ['--decode=decode_ase_mips16e_32']), + decodetree.process('micromips16.decode', extra_args: ['--decode=decode_isa_micromips16', '--insnwidth=16']), + decodetree.process('micromips32.decode', extra_args: ['--decode=decode_isa_micromips32']), + decodetree.process('micromips32_r6.decode', extra_args: ['--decode=decode_isa_micromips32_r6']), decodetree.process('rel6.decode', extra_args: ['--decode=decode_isa_rel6']), decodetree.process('msa.decode', extra_args: '--decode=decode_ase_msa'), decodetree.process('tx79.decode', extra_args: '--static-decode=decode_tx79'),
@@ -18,6 +21,7 @@ mips_ss.add(files( 'fpu_helper.c', 'ldst_helper.c', 'lmmi_helper.c', + 'micromips_translate.c', 'mips16e_translate.c', 'msa_helper.c', 'msa_translate.c',
Signature · 1 line
2.55.0
PATCH v4 6/14 scripts/decodetree: Add support for 48-bit instructions
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Some nanoMIPS instructions are 48-bit wide.
Accept --insnwidth=48, holding the instruction in a uint64_t.
---
Since v3:
- Reworded description
--- scripts/decodetree.py | 4 ++++ 1 file changed, 4 insertions(+)
scripts/decodetree.py +4 -0
@@ -1544,6 +1544,10 @@ def main(): insntype = 'uint64_t' insnmask = 0xffffffffffffffff bitop_width = 64 + elif insnwidth == 48: + insntype = 'uint64_t' + insnmask = 0xffffffffffff + bitop_width = 64 elif insnwidth != 32: error(0, 'cannot handle insns of width', insnwidth) elif o == '--test-for-error':
Signature · 1 line
2.55.0
PATCH v4 7/14 target/mips: Introduce decode tree bindings for nanoMIPS ISA
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Add empty decodetree files for the nanoMIPS 16-bit, 32-bit and 48-bit instructions.
The instruction size is known from the first halfword: 16-bit major opcodes have bit 12 set, and the P48I major opcode is the only 48-bit one. Call the matching decoder, reading only the halfwords needed. Unmatched opcodes fall back to the legacy decoder.
---
Since v3:
- Select the decoder from the instruction size, reading only the halfwords needed (rth)
--- target/mips/tcg/translate.h | 3 +++ target/mips/tcg/nanomips16.decode | 8 ++++++++ target/mips/tcg/nanomips32.decode | 8 ++++++++ target/mips/tcg/nanomips48.decode | 8 ++++++++ target/mips/tcg/nanomips_translate.c | 15 +++++++++++++++ target/mips/tcg/nanomips_translate.c.inc | 22 ++++++++++++++++++++++ target/mips/tcg/meson.build | 4 ++++ 7 files changed, 68 insertions(+) create mode 100644 target/mips/tcg/nanomips16.decode create mode 100644 target/mips/tcg/nanomips32.decode create mode 100644 target/mips/tcg/nanomips48.decode create mode 100644 target/mips/tcg/nanomips_translate.c
target/mips/tcg/translate.h +3 -0
@@ -229,6 +229,9 @@ bool decode_64bit_enabled(DisasContext *ctx);bool decode_isa_micromips16 (DisasContext *ctx,uint16_t insn);bool decode_isa_micromips32 (DisasContext *ctx,uint32_t insn);bool decode_isa_micromips32_r6 (DisasContext *ctx,uint32_t insn); +bool decode_isa_nanomips16 (DisasContext *ctx,uint16_t insn); +bool decode_isa_nanomips32 (DisasContext *ctx,uint32_t insn); +bool decode_isa_nanomips48 (DisasContext *ctx,uint64_t insn);bool decode_isa_rel6 (DisasContext *ctx,uint32_t insn);bool decode_ase_mips16e_16 (DisasContext *ctx,uint16_t insn);bool decode_ase_mips16e_32 (DisasContext *ctx,uint32_t insn);
target/mips/tcg/nanomips16.decode new file +8 -0
@@ -0,0 +1,8 @@ +# nanoMIPS32 16-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: nanoMIPS32 Instruction Set Technical Reference Manual +# (Document Number: MD01247)
target/mips/tcg/nanomips32.decode new file +8 -0
@@ -0,0 +1,8 @@ +# nanoMIPS32 32-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: nanoMIPS32 Instruction Set Technical Reference Manual +# (Document Number: MD01247)
target/mips/tcg/nanomips48.decode new file +8 -0
@@ -0,0 +1,8 @@ +# nanoMIPS32 48-bit instruction set extensions +# +# Copyright (C) 2021 Philippe Mathieu-Daudé +# +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Reference: nanoMIPS32 Instruction Set Technical Reference Manual +# (Document Number: MD01247)
target/mips/tcg/nanomips_translate.c new file +15 -0
@@ -0,0 +1,15 @@ +/* +* MIPS emulation for QEMU - nanoMIPS translation routines +* +* Copyright (c) 2021 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "translate.h" + +/* Include the auto-generated decoders. */ +#include "decode-nanomips16.c.inc" +#include "decode-nanomips32.c.inc" +#include "decode-nanomips48.c.inc"
target/mips/tcg/nanomips_translate.c.inc +22 -0
@@ -4482,6 +4482,28 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) opcode = translator_lduw_end(env, &ctx->base, ctx->base.pc_next, mo_endian(ctx)); ctx->opcode = opcode; + if (extract32(opcode, 12, 1)) { + /* Major opcodes with bit 2 set are 16-bit */ + if (decode_isa_nanomips16(ctx, opcode)) { + return 2; + } + } else { + opcode <<= 16; + opcode |= translator_lduw_end(env, &ctx->base, ctx->base.pc_next + 2, + mo_endian(ctx)); + if (extract32(opcode, 26, 6) == NM_P48I) { + opcode <<= 16; + opcode |= translator_lduw_end(env, &ctx->base, + ctx->base.pc_next + 4, + mo_endian(ctx)); + if (decode_isa_nanomips48(ctx, opcode)) { + return 6; + } + } else if (decode_isa_nanomips32(ctx, opcode)) { + return 4; + } + } + rt = decode_gpr_gpr3(NANOMIPS_EXTRACT_RT3(ctx->opcode)); rs = decode_gpr_gpr3(NANOMIPS_EXTRACT_RS3(ctx->opcode)); rd = decode_gpr_gpr3(NANOMIPS_EXTRACT_RD3(ctx->opcode));
target/mips/tcg/meson.build +4 -0
@@ -5,6 +5,9 @@ gen = [ decodetree.process('micromips32.decode', extra_args: ['--decode=decode_isa_micromips32']), decodetree.process('micromips32_r6.decode', extra_args: ['--decode=decode_isa_micromips32_r6']), decodetree.process('rel6.decode', extra_args: ['--decode=decode_isa_rel6']), + decodetree.process('nanomips16.decode', extra_args: ['--decode=decode_isa_nanomips16', '--insnwidth=16']), + decodetree.process('nanomips32.decode', extra_args: ['--decode=decode_isa_nanomips32']), + decodetree.process('nanomips48.decode', extra_args: ['--decode=decode_isa_nanomips48', '--insnwidth=48']), decodetree.process('msa.decode', extra_args: '--decode=decode_ase_msa'), decodetree.process('tx79.decode', extra_args: '--static-decode=decode_tx79'), decodetree.process('vr54xx.decode', extra_args: '--decode=decode_ext_vr54xx'),
@@ -25,6 +28,7 @@ mips_ss.add(files( 'mips16e_translate.c', 'msa_helper.c', 'msa_translate.c', + 'nanomips_translate.c', 'octeon_crypto.c', 'op_helper.c', 'rel6_translate.c',
Signature · 1 line
2.55.0
PATCH v4 8/14 target/mips: Convert microMIPS LSA opcode to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Call the generic gen_lsa(), using plus_1() to add 1 to the shift amount. LSA is a Release 6 instruction: add it to micromips32_r6.decode, which is only called on R6 CPUs.
The legacy decoder only matched bits [5:0]; the pattern also requires bits [8:6] to be zero, as specified. Other encodings now raise a Reserved Instruction exception.
Message-Id: <[email protected]>
---
Since v3:
- Move LSA to micromips32_r6.decode; v2 accepted it on pre-R6 microMIPS CPUs
- plus_1() no longer declared inline
--- target/mips/tcg/micromips32_r6.decode | 8 ++++++++ target/mips/tcg/micromips_translate.c | 10 ++++++++++ target/mips/tcg/micromips_translate.c.inc | 5 ----- 3 files changed, 18 insertions(+), 5 deletions(-)
target/mips/tcg/micromips32_r6.decode +8 -0
@@ -9,3 +9,11 @@ # (Document Number: MD00582) # microMIPS64 Instruction Set # (Document Number: MD00594) + +&r rs rt rd sa + +%lsa_sa 9:2 !function=plus_1 + +@lsa ...... rt:5 rs:5 rd:5 .. ... ...... &r sa=%lsa_sa + +LSA 000000 ..... ..... ..... .. 000 001111 @lsa
target/mips/tcg/micromips_translate.c +10 -0
@@ -9,7 +9,17 @@#include "qemu/osdep.h" #include "translate.h" +static int plus_1 (DisasContext *ctx,int x) +{ +return x +1 ; +} +/* Include the auto-generated decoders. */ #include "decode-micromips16.c.inc" #include "decode-micromips32.c.inc" #include "decode-micromips32_r6.c.inc" + +static bool trans_LSA (DisasContext *ctx,arg_r *a) +{ +return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa); +}
target/mips/tcg/micromips_translate.c.inc +0 -5
@@ -191,7 +191,6 @@ enum { /* The following can be distinguished by their lower 6 bits. */ BREAK32 = 0x07, INS = 0x0c, - LSA = 0x0f, ALIGN = 0x1f, EXT = 0x2c, POOL32AXF = 0x3c,
@@ -1799,10 +1798,6 @@ static void decode_micromips32_opc(CPUMIPSState *env, DisasContext *ctx) case INS: gen_bitops(ctx, OPC_INS, rt, rs, rr, rd); return; - case LSA: - check_insn(ctx, ISA_MIPS_R6); - gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2) + 1); - break; case ALIGN: check_insn(ctx, ISA_MIPS_R6); gen_align(ctx, 32, rd, rs, rt, extract32(ctx->opcode, 9, 2));
Signature · 1 line
2.55.0
PATCH v4 9/14 target/mips: Convert nanoMIPS LSA opcode to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Call the generic gen_lsa(). Unlike MIPS R6, the nanoMIPS shift amount is encoded as is, without +1 bias.
Message-Id: <[email protected]>
---
Since v3:
- Return gen_lsa() result, like the other LSA handlers
- Reworded description
--- target/mips/tcg/nanomips32.decode | 6 ++++++ target/mips/tcg/nanomips_translate.c | 5 +++++ target/mips/tcg/nanomips_translate.c.inc | 4 ---- 3 files changed, 11 insertions(+), 4 deletions(-)
target/mips/tcg/nanomips32.decode +6 -0
@@ -6,3 +6,9 @@ # # Reference: nanoMIPS32 Instruction Set Technical Reference Manual # (Document Number: MD01247) + +&r rs rt rd sa + +@lsa ...... rt:5 rs:5 rd:5 sa:2 --- ... ... &r + +LSA 001000 ..... ..... ..... .. ... 001 111 @lsa
target/mips/tcg/nanomips_translate.c +5 -0
@@ -13,3 +13,8 @@#include "decode-nanomips16.c.inc" #include "decode-nanomips32.c.inc" #include "decode-nanomips48.c.inc" + +static bool trans_LSA (DisasContext *ctx,arg_r *a) +{ +return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa); +}
target/mips/tcg/nanomips_translate.c.inc +0 -4
@@ -399,7 +399,6 @@ enum { /* POOL32A7 instruction pool */ enum { NM_P_LSX = 0x00, - NM_LSA = 0x01, NM_EXTW = 0x03, NM_POOL32AXF = 0x07, };
@@ -3625,9 +3624,6 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) case NM_P_LSX: gen_p_lsx(ctx, rd, rs, rt); break; - case NM_LSA: - gen_lsa(ctx, rd, rt, rs, extract32(ctx->opcode, 9, 2)); - break; case NM_EXTW: gen_ext(ctx, 32, rd, rs, rt, extract32(ctx->opcode, 6, 5)); break;
Signature · 1 line
2.55.0
PATCH v4 10/14 target/mips: Share MIPS16e/microMIPS 3-bit GPR xlat mapping
In reply to Philippe Mathieu-DaudéThe 3-bit register fields of MIPS16e and microMIPS 16-bit encodings map to the same 8 GPRs. The map is duplicated, and we want to re-use it for nanoMIPS. Rename as common gpr3_m16() helper, using the decodetree !function signature so both the legacy and the decodetree decoders can call it.
--- target/mips/tcg/translate.h | 1 + target/mips/tcg/translate.c | 11 ++++ target/mips/tcg/micromips_translate.c.inc | 61 ++++++++++------------- target/mips/tcg/mips16e_translate.c.inc | 19 +++---- 4 files changed, 45 insertions(+), 47 deletions(-)
target/mips/tcg/translate.h +1 -0
@@ -224,6 +224,7 @@ void mxu_translate_init(void);bool decode_ase_mxu (DisasContext *ctx,uint32_t insn);bool decode_64bit_enabled (DisasContext *ctx); +int gpr3_m16 (DisasContext *ctx,int x);/* decodetree generated */ bool decode_isa_micromips16 (DisasContext *ctx,uint16_t insn);
target/mips/tcg/translate.c +11 -0
@@ -1623,6 +1623,17 @@ bool decode_64bit_enabled(DisasContext *ctx)return ctx->hflags &MIPS_HFLAG_64 ; } +/* +* Map the 3-bit register field of MIPS16e and microMIPS +* 16-bit encodings to a GPR index. +*/ +int gpr3_m16 (DisasContext *ctx,int x) +{ +static const int map[8 ] = {16 ,17 ,2 ,3 ,4 ,5 ,6 ,7 }; + +return map[x]; +} +/* * This code generates a "reserved instruction" exception if cpu is not * 64-bit or 64-bit instructions are not enabled.
target/mips/tcg/micromips_translate.c.inc +27 -34
169 lines not on this page · raw message
target/mips/tcg/mips16e_translate.c.inc +6 -13
@@ -120,13 +120,6 @@ enum { RR_RY_CNVT_SEW = 0x6, }; -static int xlat(int r) -{ - static const int map[] = { 16, 17, 2, 3, 4, 5, 6, 7 }; - - return map[r]; -} - static void decr_and_store(DisasContext *ctx, unsigned regidx, TCGv t0) { TCGv t1 = tcg_temp_new();
@@ -459,8 +452,8 @@ static int decode_extended_mips16_opc(CPUMIPSState *env, DisasContext *ctx) op = (ctx->opcode >> 11) & 0x1f; sa = (ctx->opcode >> 22) & 0x1f; funct = (ctx->opcode >> 8) & 0x7; - rx = xlat((ctx->opcode >> 8) & 0x7); - ry = xlat((ctx->opcode >> 5) & 0x7); + rx = gpr3_m16(ctx, (ctx->opcode >> 8) & 0x7); + ry = gpr3_m16(ctx, (ctx->opcode >> 5) & 0x7); offset = imm = (int16_t) (((ctx->opcode >> 16) & 0x1f) << 11 | ((ctx->opcode >> 21) & 0x3f) << 5 | (ctx->opcode & 0x1f));
@@ -676,9 +669,9 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) sa = (ctx->opcode >> 2) & 0x7; sa = sa == 0 ? 8 : sa; - rx = xlat((ctx->opcode >> 8) & 0x7); + rx = gpr3_m16(ctx, (ctx->opcode >> 8) & 0x7); cnvt_op = (ctx->opcode >> 5) & 0x7; - ry = xlat((ctx->opcode >> 5) & 0x7); + ry = gpr3_m16(ctx, (ctx->opcode >> 5) & 0x7); op1 = offset = ctx->opcode & 0x1f; n_bytes = 2;
@@ -831,7 +824,7 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) break; case I8_MOV32R: { - int rz = xlat(ctx->opcode & 0x7); + int rz = gpr3_m16(ctx, ctx->opcode & 0x7); reg32 = (((ctx->opcode >> 3) & 0x3) << 3) | ((ctx->opcode >> 5) & 0x7);
@@ -910,7 +903,7 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) break; case M16_OPC_RRR: { - int rz = xlat((ctx->opcode >> 2) & 0x7); + int rz = gpr3_m16(ctx, (ctx->opcode >> 2) & 0x7); int mips32_op; switch (ctx->opcode & 0x3) {
Signature · 1 line
2.55.0
Re: [PATCH v4 10/14] target/mips: Share MIPS16e/microMIPS 3-bit GPR xlat mapping
Quoted 6 lines · Philippe Mathieu-Daudé
The 3-bit register fields of MIPS16e and microMIPS 16-bit encodings map to the same 8 GPRs. The map is duplicated, and we want to re-use it for nanoMIPS. Rename as common
gpr3_m16()helper, using the decodetree !function signature so both the legacy and the decodetree decoders can call it.
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- target/mips/tcg/translate.h | 1 + target/mips/tcg/translate.c | 11 ++++ target/mips/tcg/micromips_translate.c.inc | 61 ++++++++++------------- target/mips/tcg/mips16e_translate.c.inc | 19 +++---- 4 files changed, 45 insertions(+), 47 deletions(-)
r~
PATCH v4 11/14 target/mips: Add gen_li() helper
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Add gen_li() to load an immediate into a GPR, ignoring writes to $zero. It will be shared by the microMIPS, MIPS16e and nanoMIPS LI decodetree conversions.
--- target/mips/tcg/translate.h | 1 + target/mips/tcg/comput_translate.c | 21 +++++++++++++++++++++ target/mips/tcg/meson.build | 1 + 3 files changed, 23 insertions(+) create mode 100644 target/mips/tcg/comput_translate.c
target/mips/tcg/translate.h +1 -0
@@ -169,6 +169,7 @@ void gen_store_fpr32(DisasContext *ctx, TCGv_i32 t, int reg);void gen_store_fpr64 (DisasContext *ctx,TCGv_i64 t,int reg);int get_fp_bit (int cc); +void gen_li (DisasContext *ctx,int rd,int imm);void gen_lx (DisasContext *ctx,int rd,int base,int index,MemOp mop);void gen_ldxs (DisasContext *ctx,int base,int index,int rd);void gen_align (DisasContext *ctx,int wordsz,int rd,int rs,int rt,int bp);
target/mips/tcg/comput_translate.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* MIPS emulation for QEMU - computational translation routines +* +* Copyright (c) 2021 Philippe Mathieu-Daudé <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "translate.h" + +/* logical instructions */ + +void gen_li (DisasContext *ctx,int rd,int imm) +{ +if (rd ==0 ) { +/* Treat as NOP. */ +return ; + } +tcg_gen_movi_tl (cpu_gpr[rd], imm); +}
target/mips/tcg/meson.build +1 -0
@@ -19,6 +19,7 @@ gen = [ mips_ss.add(gen) mips_ss.add(files( + 'comput_translate.c', 'dsp_helper.c', 'exception.c', 'fpu_helper.c',
Signature · 1 line
2.55.0
PATCH v4 12/14 target/mips: Convert microMIPS LI opcode to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Decode the destination with xlat(), and the immediate with li16_imm7() (0x7f encodes -1), then call gen_li().
---
Since v3:
- Rename simm7() as li16_imm7(), drop the single-use format
- Helpers no longer declared inline
--- target/mips/tcg/micromips16.decode | 7 +++++++ target/mips/tcg/micromips_translate.c | 12 ++++++++++++ target/mips/tcg/micromips_translate.c.inc | 10 ---------- 3 files changed, 19 insertions(+), 10 deletions(-)
target/mips/tcg/micromips16.decode +7 -0
@@ -9,3 +9,10 @@ # (Document Number: MD00582) # microMIPS64 Instruction Set # (Document Number: MD00594) + +&rd_imm rd imm + +%rd3 7:3 !function=gpr3_m16 +%li16_imm7 0:7 !function=li16_imm7 + +LI 111011 ... ....... &rd_imm rd=%rd3 imm=%li16_imm7 # LI16
target/mips/tcg/micromips_translate.c +12 -0
@@ -14,6 +14,11 @@ static int plus_1(DisasContext *ctx, int x)return x +1 ; } +static int li16_imm7 (DisasContext *ctx,int x) +{ +return x ==0x7f ?-1 : x; +} +/* Include the auto-generated decoders. */ #include "decode-micromips16.c.inc" #include "decode-micromips32.c.inc"
@@ -23,3 +28,10 @@ static bool trans_LSA(DisasContext *ctx, arg_r *a) {return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa); } + +static bool trans_LI (DisasContext *ctx,arg_rd_imm *a) +{ +gen_li (ctx, a->rd, a->imm); + +return true; +}
target/mips/tcg/micromips_translate.c.inc +0 -10
@@ -113,7 +113,6 @@ enum { BLTZALC = 0x38, BLTUC = 0x38, SW16 = 0x3a, - LI16 = 0x3b, JALX32 = 0x3c, JAL32 = 0x3d, BLEZC = 0x3d,
@@ -3223,15 +3222,6 @@ static int decode_isa_micromips(CPUMIPSState *env, DisasContext *ctx) (ctx->insn_flags & ISA_MIPS_R6) ? 0 : 4); break; - case LI16: - { - int reg = gpr3_m16(ctx, uMIPS_RD(ctx->opcode)); - int imm = ZIMM(ctx->opcode, 0, 7); - - imm = (imm == 0x7f ? -1 : imm); - tcg_gen_movi_tl(cpu_gpr[reg], imm); - } - break; case RES_29: case RES_31: case RES_39:
Signature · 1 line
2.55.0
PATCH v4 13/14 target/mips: Convert MIPS16e LI opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Convert both the 16-bit RI and the extended EXT-RI forms. Decode the destination with xlat(); both immediates are zero-extended (8-bit and 16-bit).
The legacy decoder ignored EXT-RI bits [7:5]; the pattern requires them to be zero, as specified. Other encodings now raise a Reserved Instruction exception.
---
Since v3:
- Fix EXT-RI immediate field order (%ext_uimm16)
- Rename @ri format as @ext_ri
--- target/mips/tcg/mips16e_16.decode | 8 ++++++++ target/mips/tcg/mips16e_32.decode | 9 +++++++++ target/mips/tcg/mips16e_translate.c | 7 +++++++ target/mips/tcg/mips16e_translate.c.inc | 11 ----------- 4 files changed, 24 insertions(+), 11 deletions(-)
target/mips/tcg/mips16e_16.decode +8 -0
@@ -7,3 +7,11 @@ # Reference: MIPS Architecture for Programmers, Volume IV-a # The MIPS16e Application Specific Extension # (Document Number: MD00076) + +&rd_imm rd imm + +%rx3 8:3 !function=gpr3_m16 + +@ri ..... ... imm:8 &rd_imm rd=%rx3 + +LI 01101 ... ........ @ri
target/mips/tcg/mips16e_32.decode +9 -0
@@ -7,3 +7,12 @@ # Reference: MIPS Architecture for Programmers, Volume IV-a # The MIPS16e Application Specific Extension # (Document Number: MD00076) + +&rd_imm rd imm !extern + +%ext_uimm16 16:5 21:6 0:5 +%rx3 8:3 !function=gpr3_m16 + +@ext_ri ..... ...... ..... ..... ... ... ..... &rd_imm rd=%rx3 imm=%ext_uimm16 + +LI 11110 ...... ..... 01101 ... 000 ..... @ext_ri
target/mips/tcg/mips16e_translate.c +7 -0
@@ -12,3 +12,10 @@/* Include the auto-generated decoders. */ #include "decode-mips16e_16.c.inc" #include "decode-mips16e_32.c.inc" + +static bool trans_LI (DisasContext *ctx,arg_rd_imm *a) +{ +gen_li (ctx, a->rd, a->imm); + +return true; +}
target/mips/tcg/mips16e_translate.c.inc +0 -11
@@ -24,7 +24,6 @@ enum { M16_OPC_SLTI = 0x0a, M16_OPC_SLTIU = 0x0b, M16_OPC_I8 = 0x0c, - M16_OPC_LI = 0x0d, M16_OPC_CMPI = 0x0e, M16_OPC_SD = 0x0f, M16_OPC_LB = 0x10,
@@ -575,9 +574,6 @@ static int decode_extended_mips16_opc(CPUMIPSState *env, DisasContext *ctx) break; } break; - case M16_OPC_LI: - tcg_gen_movi_tl(cpu_gpr[rx], (uint16_t) imm); - break; case M16_OPC_CMPI: tcg_gen_xori_tl(cpu_gpr[24], cpu_gpr[rx], (uint16_t) imm); break;
@@ -841,13 +837,6 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) } } break; - case M16_OPC_LI: - { - int16_t imm = (uint8_t) ctx->opcode; - - gen_arith_imm(ctx, OPC_ADDIU, rx, 0, imm); - } - break; case M16_OPC_CMPI: { int16_t imm = (uint8_t) ctx->opcode;
Signature · 1 line
2.55.0
Re: [PATCH v4 13/14] target/mips: Convert MIPS16e LI opcodes to decodetree
Quoted 16 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé<[email protected]>
Convert both the 16-bit RI and the extended EXT-RI forms. Decode the destination with
xlat(); both immediates are zero-extended (8-bit and 16-bit).The legacy decoder ignored EXT-RI bits [7:5]; the pattern requires them to be zero, as specified. Other encodings now raise a Reserved Instruction exception.
Signed-off-by Philippe Mathieu-Daudé<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
Since v3:
- Fix EXT-RI immediate field order (%ext_uimm16)
- Rename @ri format as @ext_ri
Quoted 6 lines
--- target/mips/tcg/mips16e_16.decode | 8 ++++++++ target/mips/tcg/mips16e_32.decode | 9 +++++++++ target/mips/tcg/mips16e_translate.c | 7 +++++++ target/mips/tcg/mips16e_translate.c.inc | 11 ----------- 4 files changed, 24 insertions(+), 11 deletions(-)
r~
PATCH v4 14/14 target/mips: Convert nanoMIPS LI opcodes to decodetree
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Convert LI[16] and LI[48]. LI[16] decodes its 3-bit register with gpr3() and its immediate with s_eu() (0x7f encodes -1). LI[48] takes a 32-bit immediate and is not available in NMS cores; handle it in trans_LI_nnms(), which checks NMS before calling trans_LI(). Expose check_nms() for that purpose.
---
Since v3:
- Fix LI[16] register decoding, using the gpr3() mapping
- Fix LI[16] immediate, extracted unsigned
- Fix LI[48] immediate halfword order
- Replace the not_in_nms argument by trans_LI_nnms()
- Reuse check_nms() from translate.c
--- target/mips/tcg/translate.h | 1 + target/mips/tcg/nanomips16.decode | 9 ++++++++ target/mips/tcg/nanomips48.decode | 8 ++++++++ target/mips/tcg/nanomips_translate.c | 26 ++++++++++++++++++++++++ target/mips/tcg/translate.c | 2 +- target/mips/tcg/nanomips_translate.c.inc | 17 ---------------- 6 files changed, 45 insertions(+), 18 deletions(-)
target/mips/tcg/translate.h +1 -0
@@ -152,6 +152,7 @@ void check_cp1_enabled(DisasContext *ctx);void check_cp1_64bitmode (DisasContext *ctx);void check_cp1_registers (DisasContext *ctx,int regs);void check_cop1x (DisasContext *ctx); +void check_nms (DisasContext *ctx);void gen_base_offset_addr (DisasContext *ctx,TCGv addr,int base,int offset);void gen_base_index_addr (DisasContext *ctx,TCGv addr,int base,int index);
target/mips/tcg/nanomips16.decode +9 -0
@@ -6,3 +6,12 @@ # # Reference: nanoMIPS32 Instruction Set Technical Reference Manual # (Document Number: MD01247) + +&rd_imm rd imm + +%rt3 7:3 !function=gpr3 +%s_eu 0:7 !function=s_eu + +@rt3_s ...... ... ....... &rd_imm rd=%rt3 imm=%s_eu + +LI 110100 ... ....... @rt3_s # LI[16]
target/mips/tcg/nanomips48.decode +8 -0
@@ -6,3 +6,11 @@ # # Reference: nanoMIPS32 Instruction Set Technical Reference Manual # (Document Number: MD01247) + +&rd_imm rd imm !extern + +%imm 0:s16 16:16 + +@rd_imm ...... rd:5 ..... ................ ................ &rd_imm imm=%imm + +LI_nnms 011000 ..... 00000 ................ ................ @rd_imm
target/mips/tcg/nanomips_translate.c +26 -0
@@ -9,6 +9,18 @@#include "qemu/osdep.h" #include "translate.h" +static int gpr3 (DisasContext *ctx,int x) +{ +static const int map[8 ] = {16 ,17 ,18 ,19 ,4 ,5 ,6 ,7 }; + +return map[x]; +} + +static int s_eu (DisasContext *ctx,int x) +{ +return x ==0x7f ?-1 : x; +} +/* Include the auto-generated decoders. */ #include "decode-nanomips16.c.inc" #include "decode-nanomips32.c.inc"
@@ -18,3 +30,17 @@ static bool trans_LSA(DisasContext *ctx, arg_r *a) {return gen_lsa (ctx, a->rd, a->rt, a->rs, a->sa); } + +static bool trans_LI (DisasContext *ctx,arg_rd_imm *a) +{ +gen_li (ctx, a->rd, a->imm); + +return true; +} + +static bool trans_LI_nnms (DisasContext *ctx,arg_rd_imm *a) +{ +check_nms (ctx); + +return trans_LI (ctx, a); +}
target/mips/tcg/translate.c +1 -1
@@ -1712,7 +1712,7 @@ static inline void check_cp0_mt(DisasContext *ctx)* This code generates a "reserved instruction" exception if the * Config5 NMS bit is set. */ -static inline void check_nms (DisasContext *ctx) +void check_nms (DisasContext *ctx) {if (unlikely (ctx->CP0_Config5 & (1 <<CP0C5_NMS ))) {gen_reserved_instruction (ctx);
target/mips/tcg/nanomips_translate.c.inc +0 -17
@@ -57,7 +57,6 @@ enum { NM_POOL32S = 0x30, NM_P_BRI = 0x32, - NM_LI16 = 0x34, NM_SWGP16 = 0x35, NM_P16_BR = 0x36,
@@ -86,7 +85,6 @@ enum { /* P48I instruction pool */ enum { - NM_LI48 = 0x00, NM_ADDIU48 = 0x01, NM_ADDIUGP48 = 0x02, NM_ADDIUPC48 = 0x03,
@@ -3665,12 +3663,6 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) mo_endian(ctx)); target_long addr_off = extract32(ctx->opcode, 0, 16) | insn << 16; switch (extract32(ctx->opcode, 16, 5)) { - case NM_LI48: - check_nms(ctx); - if (rt != 0) { - tcg_gen_movi_tl(cpu_gpr[rt], addr_off); - } - break; case NM_ADDIU48: check_nms(ctx); if (rt != 0) {
@@ -4628,15 +4620,6 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) break; } break; - case NM_LI16: - { - imm = extract32(ctx->opcode, 0, 7); - imm = (imm == 0x7f ? -1 : imm); - if (rt != 0) { - tcg_gen_movi_tl(cpu_gpr[rt], imm); - } - } - break; case NM_ANDI16: { uint32_t u = extract32(ctx->opcode, 0, 4);
Signature · 1 line
2.55.0
Re: [PATCH v4 14/14] target/mips: Convert nanoMIPS LI opcodes to decodetree
Quoted 17 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé<[email protected]>
Convert LI[16] and LI[48]. LI[16] decodes its 3-bit register with
gpr3()and its immediate withs_eu()(0x7fencodes -1). LI[48] takes a 32-bit immediate and is not available in NMS cores; handle it intrans_LI_nnms(), which checks NMS before callingtrans_LI(). Exposecheck_nms()for that purpose.Signed-off-by Philippe Mathieu-Daudé<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>---
Since v3:
- Fix LI[16] register decoding, using thegpr3()mapping
- Fix LI[16] immediate, extracted unsigned
- Fix LI[48] immediate halfword order
- Replace thenot_in_nmsargument bytrans_LI_nnms()
- Reusecheck_nms()fromtranslate.c
Quoted 8 lines
--- target/mips/tcg/translate.h | 1 + target/mips/tcg/nanomips16.decode | 9 ++++++++ target/mips/tcg/nanomips48.decode | 8 ++++++++ target/mips/tcg/nanomips_translate.c | 26 ++++++++++++++++++++++++ target/mips/tcg/translate.c | 2 +- target/mips/tcg/nanomips_translate.c.inc | 17 ---------------- 6 files changed, 45 insertions(+), 18 deletions(-)
r~