qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Palmer Dabbelt <palmer@sifive.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, qemu-riscv@nongnu.org,
	Bastian Koppelmann <kbastian@mail.uni-paderborn.de>,
	Peer Adelt <peer.adelt@hni.uni-paderborn.de>,
	Palmer Dabbelt <palmer@sifive.com>
Subject: [Qemu-devel] [PULL 01/34] target/riscv: Activate decodetree and implemnt LUI & AUIPC
Date: Fri,  1 Mar 2019 13:49:12 -0800	[thread overview]
Message-ID: <20190301214945.4353-2-palmer@sifive.com> (raw)
In-Reply-To: <20190301214945.4353-1-palmer@sifive.com>

From: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>

for now only LUI & AUIPC are decoded and translated. If decodetree fails, we
fall back to the old decoder.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Signed-off-by: Bastian Koppelmann <kbastian@mail.uni-paderborn.de>
Signed-off-by: Peer Adelt <peer.adelt@hni.uni-paderborn.de>
Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
---
 target/riscv/Makefile.objs              | 10 +++++++
 target/riscv/insn32.decode              | 30 +++++++++++++++++++++
 target/riscv/insn_trans/trans_rvi.inc.c | 35 +++++++++++++++++++++++++
 target/riscv/translate.c                | 31 ++++++++++++----------
 4 files changed, 92 insertions(+), 14 deletions(-)
 create mode 100644 target/riscv/insn32.decode
 create mode 100644 target/riscv/insn_trans/trans_rvi.inc.c

diff --git a/target/riscv/Makefile.objs b/target/riscv/Makefile.objs
index 4072abe3e45c..bf0a268033a0 100644
--- a/target/riscv/Makefile.objs
+++ b/target/riscv/Makefile.objs
@@ -1 +1,11 @@
 obj-y += translate.o op_helper.o cpu_helper.o cpu.o csr.o fpu_helper.o gdbstub.o pmp.o
+
+DECODETREE = $(SRC_PATH)/scripts/decodetree.py
+
+target/riscv/decode_insn32.inc.c: \
+  $(SRC_PATH)/target/riscv/insn32.decode $(DECODETREE)
+	$(call quiet-command, \
+	  $(PYTHON) $(DECODETREE) -o $@ --decode decode_insn32 $<, \
+	  "GEN", $(TARGET_DIR)$@)
+
+target/riscv/translate.o: target/riscv/decode_insn32.inc.c
diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode
new file mode 100644
index 000000000000..44d4e922b6fa
--- /dev/null
+++ b/target/riscv/insn32.decode
@@ -0,0 +1,30 @@
+#
+# RISC-V translation routines for the RVXI Base Integer Instruction Set.
+#
+# Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
+#                    Bastian Koppelmann, kbastian@mail.uni-paderborn.de
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms and conditions of the GNU General Public License,
+# version 2 or later, as published by the Free Software Foundation.
+#
+# This program is distributed in the hope it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Fields:
+%rd        7:5
+
+# immediates:
+%imm_u    12:s20                 !function=ex_shift_12
+
+# Formats 32:
+@u       ....................      ..... .......         imm=%imm_u          %rd
+
+# *** RV32I Base Instruction Set ***
+lui      ....................       ..... 0110111 @u
+auipc    ....................       ..... 0010111 @u
diff --git a/target/riscv/insn_trans/trans_rvi.inc.c b/target/riscv/insn_trans/trans_rvi.inc.c
new file mode 100644
index 000000000000..9885a8d27551
--- /dev/null
+++ b/target/riscv/insn_trans/trans_rvi.inc.c
@@ -0,0 +1,35 @@
+/*
+ * RISC-V translation routines for the RVXI Base Integer Instruction Set.
+ *
+ * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
+ * Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
+ *                    Bastian Koppelmann, kbastian@mail.uni-paderborn.de
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2 or later, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+static bool trans_lui(DisasContext *ctx, arg_lui *a)
+{
+    if (a->rd != 0) {
+        tcg_gen_movi_tl(cpu_gpr[a->rd], a->imm);
+    }
+    return true;
+}
+
+static bool trans_auipc(DisasContext *ctx, arg_auipc *a)
+{
+    if (a->rd != 0) {
+        tcg_gen_movi_tl(cpu_gpr[a->rd], a->imm + ctx->base.pc_next);
+    }
+    return true;
+}
diff --git a/target/riscv/translate.c b/target/riscv/translate.c
index b7176cbf98e1..a273ac827448 100644
--- a/target/riscv/translate.c
+++ b/target/riscv/translate.c
@@ -1874,6 +1874,19 @@ static void decode_RV32_64C(DisasContext *ctx)
     }
 }
 
+#define EX_SH(amount) \
+    static int ex_shift_##amount(int imm) \
+    {                                         \
+        return imm << amount;                 \
+    }
+EX_SH(12)
+
+bool decode_insn32(DisasContext *ctx, uint32_t insn);
+/* Include the auto-generated decoder for 32 bit insn */
+#include "decode_insn32.inc.c"
+/* Include insn module translation function */
+#include "insn_trans/trans_rvi.inc.c"
+
 static void decode_RV32_64G(DisasContext *ctx)
 {
     int rs1;
@@ -1894,19 +1907,6 @@ static void decode_RV32_64G(DisasContext *ctx)
     imm = GET_IMM(ctx->opcode);
 
     switch (op) {
-    case OPC_RISC_LUI:
-        if (rd == 0) {
-            break; /* NOP */
-        }
-        tcg_gen_movi_tl(cpu_gpr[rd], sextract64(ctx->opcode, 12, 20) << 12);
-        break;
-    case OPC_RISC_AUIPC:
-        if (rd == 0) {
-            break; /* NOP */
-        }
-        tcg_gen_movi_tl(cpu_gpr[rd], (sextract64(ctx->opcode, 12, 20) << 12) +
-               ctx->base.pc_next);
-        break;
     case OPC_RISC_JAL:
         imm = GET_JAL_IMM(ctx->opcode);
         gen_jal(ctx, rd, imm);
@@ -2011,7 +2011,10 @@ static void decode_opc(DisasContext *ctx)
         }
     } else {
         ctx->pc_succ_insn = ctx->base.pc_next + 4;
-        decode_RV32_64G(ctx);
+        if (!decode_insn32(ctx, ctx->opcode)) {
+            /* fallback to old decoder */
+            decode_RV32_64G(ctx);
+        }
     }
 }
 
-- 
2.18.1

  reply	other threads:[~2019-03-01 21:50 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01 21:49 [Qemu-devel] [PULL] target/riscv: Convert to decodetree Palmer Dabbelt
2019-03-01 21:49 ` Palmer Dabbelt [this message]
2019-03-01 21:49 ` [Qemu-devel] [PULL 02/34] target/riscv: Convert RVXI branch insns " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 03/34] target/riscv: Convert RV32I load/store " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 04/34] target/riscv: Convert RV64I " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 05/34] target/riscv: Convert RVXI arithmetic " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 06/34] target/riscv: Convert RVXI fence " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 07/34] target/riscv: Convert RVXI csr " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 08/34] target/riscv: Convert RVXM " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 09/34] target/riscv: Convert RV32A " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 10/34] target/riscv: Convert RV64A " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 11/34] target/riscv: Convert RV32F " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 12/34] target/riscv: Convert RV64F " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 13/34] target/riscv: Convert RV32D " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 14/34] target/riscv: Convert RV64D " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 15/34] target/riscv: Convert RV priv " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 16/34] target/riscv: Convert quadrant 0 of RVXC " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 17/34] target/riscv: Convert quadrant 1 " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 18/34] target/riscv: Convert quadrant 2 " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 19/34] target/riscv: Remove gen_jalr() Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 20/34] target/riscv: Remove manual decoding from gen_branch() Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 21/34] target/riscv: Remove manual decoding from gen_load() Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 22/34] target/riscv: Remove manual decoding from gen_store() Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 23/34] target/riscv: Move gen_arith_imm() decoding into trans_* functions Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 24/34] target/riscv: make ADD/SUB/OR/XOR/AND insn use arg lists Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 25/34] target/riscv: Remove shift and slt insn manual decoding Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 26/34] target/riscv: Remove manual decoding of RV32/64M insn Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 27/34] target/riscv: Rename trans_arith to gen_arith Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 28/34] target/riscv: Remove gen_system() Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 29/34] target/riscv: Remove decode_RV32_64G() Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 30/34] target/riscv: Convert @cs_2 insns to share translation functions Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 31/34] target/riscv: Convert @cl_d, @cl_w, @cs_d, @cs_w insns Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 32/34] target/riscv: Splice fsw_sd and flw_ld for riscv32 vs riscv64 Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 33/34] target/riscv: Splice remaining compressed insn pairs " Palmer Dabbelt
2019-03-01 21:49 ` [Qemu-devel] [PULL 34/34] target/riscv: Remaining rvc insn reuse 32 bit translators Palmer Dabbelt
2019-03-04 11:02 ` [Qemu-devel] [PULL] target/riscv: Convert to decodetree Peter Maydell
2019-03-04 12:52   ` Bastian Koppelmann
2019-03-04 15:25     ` Bastian Koppelmann
2019-03-04 19:30     ` Richard Henderson
2019-03-04 21:46       ` Palmer Dabbelt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190301214945.4353-2-palmer@sifive.com \
    --to=palmer@sifive.com \
    --cc=kbastian@mail.uni-paderborn.de \
    --cc=peer.adelt@hni.uni-paderborn.de \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).