From nobody Tue Feb 10 22:18:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529497285685905.1209128962963; Wed, 20 Jun 2018 05:21:25 -0700 (PDT) Received: from localhost ([::1]:49067 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVc72-0005ax-Qg for importer@patchew.org; Wed, 20 Jun 2018 08:21:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fVbut-0003i9-Dh for qemu-devel@nongnu.org; Wed, 20 Jun 2018 08:08:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fVbur-0004ED-Rj for qemu-devel@nongnu.org; Wed, 20 Jun 2018 08:08:51 -0400 Received: from 9pmail.ess.barracuda.com ([64.235.150.224]:34471) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fVbur-0004A7-Kn for qemu-devel@nongnu.org; Wed, 20 Jun 2018 08:08:49 -0400 Received: from mipsdag02.mipstec.com (mail2.mips.com [12.201.5.32]) by mx2.ess.sfj.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA256 bits=128 verify=NO); Wed, 20 Jun 2018 12:08:41 +0000 Received: from ubuntu1404.mipstec.com (192.168.40.13) by mipsdag02.mipstec.com (10.20.40.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1415.2; Wed, 20 Jun 2018 05:08:09 -0700 From: Yongbok Kim To: Date: Wed, 20 Jun 2018 13:05:53 +0100 Message-ID: <20180620120620.12806-9-yongbok.kim@mips.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20180620120620.12806-1-yongbok.kim@mips.com> References: <20180620120620.12806-1-yongbok.kim@mips.com> MIME-Version: 1.0 X-Originating-IP: [192.168.40.13] X-ClientProxiedBy: mipsdag02.mipstec.com (10.20.40.47) To mipsdag02.mipstec.com (10.20.40.47) X-BESS-ID: 1529496484-298553-23331-42495-4 X-BESS-VER: 2018.7-r1806151722 X-BESS-Apparent-Source-IP: 12.201.5.32 X-BESS-Envelope-From: Yongbok.Kim@mips.com X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.194221 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS59374 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND X-BESS-Orig-Rcpt: qemu-devel@nongnu.org,aurelien@aurel32.net X-BESS-BRTS-Status: 1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 64.235.150.224 Subject: [Qemu-devel] [PATCH 08/35] target/mips: Add nanoMIPS 32bit instructions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandar.Markovic@mips.com, Paul.Burton@mips.com, Stefan.Markovic@mips.com, Matthew.Fortune@mips.com, James.Hogan@mips.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add nanoMIPS 32bit instructions Signed-off-by: Yongbok Kim --- target/mips/translate.c | 285 ++++++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 284 insertions(+), 1 deletion(-) diff --git a/target/mips/translate.c b/target/mips/translate.c index 4ce80bf..c9b46dd 100644 --- a/target/mips/translate.c +++ b/target/mips/translate.c @@ -16313,6 +16313,289 @@ static void gen_pool16c_nanomips_insn(DisasContex= t *ctx) } } =20 +static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) +{ + uint16_t insn; + int rt, rs; + uint32_t op; + + insn =3D cpu_lduw_code(env, ctx->base.pc_next + 2); + ctx->opcode =3D (ctx->opcode << 16) | insn; + + rt =3D (ctx->opcode >> 21) & 0x1f; + rs =3D (ctx->opcode >> 16) & 0x1f; + + op =3D (ctx->opcode >> 26) & 0x3f; + switch (op) { + case NM_P_ADDIU: + if (rt =3D=3D 0) { + /* P.RI */ + switch ((ctx->opcode >> 19) & 0x03) { + case NM_SIGRIE: + default: + generate_exception_end(ctx, EXCP_RI); + break; + case NM_P_SYSCALL: + if (((ctx->opcode >> 18) & 0x01) =3D=3D NM_SYSCALL) { + generate_exception_end(ctx, EXCP_SYSCALL); + } else { + generate_exception_end(ctx, EXCP_RI); + } + break; + case NM_BREAK: + generate_exception_end(ctx, EXCP_BREAK); + break; + case NM_SDBBP: + if (is_uhi(extract32(ctx->opcode, 0, 19))) { + gen_helper_do_semihosting(cpu_env); + } else { + if (ctx->hflags & MIPS_HFLAG_SBRI) { + generate_exception_end(ctx, EXCP_RI); + } else { + generate_exception_end(ctx, EXCP_DBp); + } + } + break; + } + } else { + uint16_t imm; + imm =3D (uint16_t) extract32(ctx->opcode, 0, 16); + if (rs !=3D 0) { + tcg_gen_addi_tl(cpu_gpr[rt], cpu_gpr[rs], imm); + tcg_gen_ext32s_tl(cpu_gpr[rt], cpu_gpr[rt]); + } else { + tcg_gen_movi_tl(cpu_gpr[rt], imm); + } + } + break; + case NM_ADDIUPC: + if (rt !=3D 0) { + int32_t offset =3D sextract32(ctx->opcode, 0, 1) << 21 + | extract32(ctx->opcode, 1, 20) << 1; + target_long addr =3D addr_add(ctx, ctx->base.pc_next + 4, offs= et); + tcg_gen_movi_tl(cpu_gpr[rt], addr); + tcg_gen_ext32s_tl(cpu_gpr[rt], cpu_gpr[rt]); + } + break; + case NM_POOL32A: + break; + case NM_P_GP_W: + switch (ctx->opcode & 0x03) { + case NM_ADDIUGP_W: + if (rt !=3D 0) { + uint32_t offset =3D extract32(ctx->opcode, 0, 21); + if (offset =3D=3D 0) { + gen_load_gpr(cpu_gpr[rt], 28); + } else { + TCGv t0; + t0 =3D tcg_temp_new(); + tcg_gen_movi_tl(t0, offset); + gen_op_addr_add(ctx, cpu_gpr[rt], cpu_gpr[28], t0); + tcg_temp_free(t0); + } + } + break; + case NM_LWGP: + gen_ld(ctx, OPC_LW, rt, 28, extract32(ctx->opcode, 2, 19) << 2= ); + break; + case NM_SWGP: + gen_st(ctx, OPC_SW, rt, 28, extract32(ctx->opcode, 2, 19) << 2= ); + break; + default: + generate_exception_end(ctx, EXCP_RI); + break; + } + break; + case NM_P48I: + return 6; + case NM_P_U12: + switch ((ctx->opcode >> 12) & 0x0f) { + case NM_ORI: + gen_logic_imm(ctx, OPC_ORI, rt, rs, extract32(ctx->opcode, 0, = 12)); + break; + case NM_XORI: + gen_logic_imm(ctx, OPC_XORI, rt, rs, extract32(ctx->opcode, 0,= 12)); + break; + case NM_ANDI: + gen_logic_imm(ctx, OPC_ANDI, rt, rs, extract32(ctx->opcode, 0,= 12)); + break; + case NM_P_SR: + switch ((ctx->opcode >> 20) & 1) { + case NM_PP_SR: + switch (ctx->opcode & 3) { + case NM_SAVE: + gen_save(ctx, rt, extract32(ctx->opcode, 16, 4), + (ctx->opcode >> 2) & 1, + extract32(ctx->opcode, 3, 9) << 3); + break; + case NM_RESTORE: + case NM_RESTORE_JRC: + gen_restore(ctx, rt, extract32(ctx->opcode, 16, 4), + (ctx->opcode >> 2) & 1, + extract32(ctx->opcode, 3, 9) << 3); + if ((ctx->opcode & 3) =3D=3D NM_RESTORE_JRC) { + gen_compute_branch(ctx, OPC_JR, 2, 31, 0, 0, 0); + } + break; + } + break; + case NM_P_SR_F: + generate_exception_end(ctx, EXCP_RI); + break; + } + break; + case NM_SLTI: + gen_slt_imm(ctx, OPC_SLTI, rt, rs, extract32(ctx->opcode, 0, 1= 2)); + break; + case NM_SLTIU: + gen_slt_imm(ctx, OPC_SLTIU, rt, rs, extract32(ctx->opcode, 0, = 12)); + break; + case NM_SEQI: + { + TCGv t0 =3D tcg_temp_new(); + TCGv t1 =3D tcg_temp_new(); + TCGv t2 =3D tcg_temp_local_new(); + TCGLabel *l1 =3D gen_new_label(); + + gen_load_gpr(t0, rs); + tcg_gen_movi_tl(t1, extract32(ctx->opcode, 0, 12)); + tcg_gen_movi_tl(t2, 0); + tcg_gen_brcond_tl(TCG_COND_NE, t0, t1, l1); + tcg_gen_movi_tl(t2, 1); + gen_set_label(l1); + gen_store_gpr(t2, rt); + + tcg_temp_free(t0); + tcg_temp_free(t1); + tcg_temp_free(t2); + } + break; + case NM_ADDIUNEG: + { + int16_t imm; + imm =3D (int16_t) extract32(ctx->opcode, 0, 12); + gen_arith_imm(ctx, OPC_ADDIU, rt, rs, -imm); + } + break; + case NM_P_SHIFT: + { + int shift =3D extract32(ctx->opcode, 0, 5); + switch ((ctx->opcode >> 5) & 0x0f) { + case NM_P_SLL: + if (rt =3D=3D 0 && shift =3D=3D 0) { + /* NOP */ + } else if (rt =3D=3D 0 && shift =3D=3D 3) { + /* EHB treat as NOP */ + } else if (rt =3D=3D 0 && shift =3D=3D 5) { + /* PAUSE */ + if (ctx->hflags & MIPS_HFLAG_BMASK) { + generate_exception_end(ctx, EXCP_RI); + } + } else if (rt =3D=3D 0 && shift =3D=3D 6) { + /* SYNC */ + check_insn(ctx, ISA_MIPS2); + /* Treat as NOP. */ + } else { + /* SLL */ + gen_shift_imm(ctx, OPC_SLL, rt, rs, + extract32(ctx->opcode, 0, 5)); + } + break; + case NM_SRL: + gen_shift_imm(ctx, OPC_SRL, rt, rs, + extract32(ctx->opcode, 0, 5)); + break; + case NM_SRA: + gen_shift_imm(ctx, OPC_SRA, rt, rs, + extract32(ctx->opcode, 0, 5)); + break; + case NM_ROTR: + gen_shift_imm(ctx, OPC_ROTR, rt, rs, + extract32(ctx->opcode, 0, 5)); + break; + } + } + break; + case NM_P_ROTX: + break; + case NM_P_INS: + switch (((ctx->opcode >> 10) & 2) | ((ctx->opcode >> 5) & 1)) { + case NM_INS: + gen_bitops(ctx, OPC_INS, rt, rs, extract32(ctx->opcode, 0,= 5), + extract32(ctx->opcode, 6, 5)); + break; + default: + generate_exception_end(ctx, EXCP_RI); + break; + } + break; + case NM_P_EXT: + switch (((ctx->opcode >> 10) & 2) | ((ctx->opcode >> 5) & 1)) { + case NM_EXT: + gen_bitops(ctx, OPC_EXT, rt, rs, extract32(ctx->opcode, 0,= 5), + extract32(ctx->opcode, 6, 5)); + break; + default: + generate_exception_end(ctx, EXCP_RI); + break; + } + break; + default: + generate_exception_end(ctx, EXCP_RI); + break; + } + break; + case NM_POOL32F: + break; + case NM_POOL32S: + break; + case NM_P_LUI: + switch ((ctx->opcode >> 1) & 1) { + case NM_LUI: + if (rt !=3D 0) { + tcg_gen_movi_tl(cpu_gpr[rt], + sextract32(ctx->opcode, 0, 1) << 31 | + extract32(ctx->opcode, 2, 10) << 21 | + extract32(ctx->opcode, 12, 9) << 12); + } + break; + case NM_ALUIPC: + if (rt !=3D 0) { + int offset =3D sextract32(ctx->opcode, 0, 1) << 31 | + extract32(ctx->opcode, 2, 10) << 21 | + extract32(ctx->opcode, 12, 9) << 12; + target_long addr; + addr =3D ~0xFFF & addr_add(ctx, ctx->base.pc_next + 4, off= set); + tcg_gen_movi_tl(cpu_gpr[rt], addr); + } + break; + } + break; + case NM_P_GP_BH: + break; + case NM_P_LS_U12: + break; + case NM_P_LS_S9: + break; + case NM_MOVE_BALC: + break; + case NM_P_BAL: + break; + case NM_P_J: + break; + case NM_P_BR1: + break; + case NM_P_BR2: + break; + case NM_P_BRI: + break; + default: + generate_exception_end(ctx, EXCP_RI); + break; + } + return 4; +} + static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx) { uint32_t op; @@ -16687,7 +16970,7 @@ static int decode_nanomips_opc(CPUMIPSState *env, D= isasContext *ctx) } break; default: - break; + return decode_nanomips_32_48_opc(env, ctx); } =20 return 2; --=20 1.9.1