mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-07-23 11:28:30 +00:00
target/riscv: Convert quadrant 0 of RVXC insns to decodetree
This commit is contained in:
parent
67164f2b29
commit
8d294a7897
|
@ -5411,6 +5411,7 @@ riscv_symbols = (
|
||||||
'cpu_riscv_set_fflags',
|
'cpu_riscv_set_fflags',
|
||||||
'csr_read_helper',
|
'csr_read_helper',
|
||||||
'csr_write_helper',
|
'csr_write_helper',
|
||||||
|
'decode_insn16',
|
||||||
'decode_insn32',
|
'decode_insn32',
|
||||||
'do_raise_exception_err',
|
'do_raise_exception_err',
|
||||||
'gen_helper_tlb_flush',
|
'gen_helper_tlb_flush',
|
||||||
|
|
|
@ -3332,6 +3332,7 @@
|
||||||
#define cpu_riscv_set_fflags cpu_riscv_set_fflags_riscv32
|
#define cpu_riscv_set_fflags cpu_riscv_set_fflags_riscv32
|
||||||
#define csr_read_helper csr_read_helper_riscv32
|
#define csr_read_helper csr_read_helper_riscv32
|
||||||
#define csr_write_helper csr_write_helper_riscv32
|
#define csr_write_helper csr_write_helper_riscv32
|
||||||
|
#define decode_insn16 decode_insn16_riscv32
|
||||||
#define decode_insn32 decode_insn32_riscv32
|
#define decode_insn32 decode_insn32_riscv32
|
||||||
#define do_raise_exception_err do_raise_exception_err_riscv32
|
#define do_raise_exception_err do_raise_exception_err_riscv32
|
||||||
#define gen_helper_tlb_flush gen_helper_tlb_flush_riscv32
|
#define gen_helper_tlb_flush gen_helper_tlb_flush_riscv32
|
||||||
|
|
|
@ -3332,6 +3332,7 @@
|
||||||
#define cpu_riscv_set_fflags cpu_riscv_set_fflags_riscv64
|
#define cpu_riscv_set_fflags cpu_riscv_set_fflags_riscv64
|
||||||
#define csr_read_helper csr_read_helper_riscv64
|
#define csr_read_helper csr_read_helper_riscv64
|
||||||
#define csr_write_helper csr_write_helper_riscv64
|
#define csr_write_helper csr_write_helper_riscv64
|
||||||
|
#define decode_insn16 decode_insn16_riscv64
|
||||||
#define decode_insn32 decode_insn32_riscv64
|
#define decode_insn32 decode_insn32_riscv64
|
||||||
#define do_raise_exception_err do_raise_exception_err_riscv64
|
#define do_raise_exception_err do_raise_exception_err_riscv64
|
||||||
#define gen_helper_tlb_flush gen_helper_tlb_flush_riscv64
|
#define gen_helper_tlb_flush gen_helper_tlb_flush_riscv64
|
||||||
|
|
|
@ -11,4 +11,12 @@ target/riscv/decode_insn32.inc.c: $(decode32-y) $(DECODETREE)
|
||||||
$(PYTHON) $(DECODETREE) -o $@ --decode decode_insn32 $(decode32-y), \
|
$(PYTHON) $(DECODETREE) -o $@ --decode decode_insn32 $(decode32-y), \
|
||||||
"GEN", $(TARGET_DIR)$@)
|
"GEN", $(TARGET_DIR)$@)
|
||||||
|
|
||||||
target/riscv/translate.o: target/riscv/decode_insn32.inc.c
|
target/riscv/decode_insn16.inc.c: \
|
||||||
|
$(SRC_PATH)/target/riscv/insn16.decode $(DECODETREE)
|
||||||
|
$(call quiet-command, \
|
||||||
|
$(PYTHON) $(DECODETREE) -o $@ --decode decode_insn16 --insnwidth 16 $<, \
|
||||||
|
"GEN", $(TARGET_DIR)$@)
|
||||||
|
|
||||||
|
target/riscv/translate.o: target/riscv/decode_insn32.inc.c \
|
||||||
|
target/riscv/decode_insn16.inc.c
|
||||||
|
|
||||||
|
|
55
qemu/target/riscv/insn16.decode
Normal file
55
qemu/target/riscv/insn16.decode
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
%rs1_3 7:3 !function=ex_rvc_register
|
||||||
|
%rs2_3 2:3 !function=ex_rvc_register
|
||||||
|
|
||||||
|
# Immediates:
|
||||||
|
%nzuimm_ciw 7:4 11:2 5:1 6:1 !function=ex_shift_2
|
||||||
|
%uimm_cl_d 5:2 10:3 !function=ex_shift_3
|
||||||
|
%uimm_cl_w 5:1 10:3 6:1 !function=ex_shift_2
|
||||||
|
|
||||||
|
|
||||||
|
# Argument sets:
|
||||||
|
&cl rs1 rd
|
||||||
|
&cl_dw uimm rs1 rd
|
||||||
|
&ciw nzuimm rd
|
||||||
|
&cs rs1 rs2
|
||||||
|
&cs_dw uimm rs1 rs2
|
||||||
|
|
||||||
|
|
||||||
|
# Formats 16:
|
||||||
|
@ciw ... ........ ... .. &ciw nzuimm=%nzuimm_ciw rd=%rs2_3
|
||||||
|
@cl_d ... ... ... .. ... .. &cl_dw uimm=%uimm_cl_d rs1=%rs1_3 rd=%rs2_3
|
||||||
|
@cl_w ... ... ... .. ... .. &cl_dw uimm=%uimm_cl_w rs1=%rs1_3 rd=%rs2_3
|
||||||
|
@cl ... ... ... .. ... .. &cl rs1=%rs1_3 rd=%rs2_3
|
||||||
|
@cs ... ... ... .. ... .. &cs rs1=%rs1_3 rs2=%rs2_3
|
||||||
|
@cs_d ... ... ... .. ... .. &cs_dw uimm=%uimm_cl_d rs1=%rs1_3 rs2=%rs2_3
|
||||||
|
@cs_w ... ... ... .. ... .. &cs_dw uimm=%uimm_cl_w rs1=%rs1_3 rs2=%rs2_3
|
||||||
|
|
||||||
|
|
||||||
|
# *** RV64C Standard Extension (Quadrant 0) ***
|
||||||
|
c_addi4spn 000 ........ ... 00 @ciw
|
||||||
|
c_fld 001 ... ... .. ... 00 @cl_d
|
||||||
|
c_lw 010 ... ... .. ... 00 @cl_w
|
||||||
|
c_flw_ld 011 --- ... -- ... 00 @cl #Note: Must parse uimm manually
|
||||||
|
c_fsd 101 ... ... .. ... 00 @cs_d
|
||||||
|
c_sw 110 ... ... .. ... 00 @cs_w
|
||||||
|
c_fsw_sd 111 --- ... -- ... 00 @cs #Note: Must parse uimm manually
|
75
qemu/target/riscv/insn_trans/trans_rvc.inc.c
Normal file
75
qemu/target/riscv/insn_trans/trans_rvc.inc.c
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* RISC-V translation routines for the RVC Compressed 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_c_addi4spn(DisasContext *ctx, arg_c_addi4spn *a)
|
||||||
|
{
|
||||||
|
if (a->nzuimm == 0) {
|
||||||
|
/* Reserved in ISA */
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
arg_addi arg = { .rd = a->rd, .rs1 = 2, .imm = a->nzuimm };
|
||||||
|
return trans_addi(ctx, &arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool trans_c_fld(DisasContext *ctx, arg_c_fld *a)
|
||||||
|
{
|
||||||
|
arg_fld arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm };
|
||||||
|
return trans_fld(ctx, &arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool trans_c_lw(DisasContext *ctx, arg_c_lw *a)
|
||||||
|
{
|
||||||
|
arg_lw arg = { .rd = a->rd, .rs1 = a->rs1, .imm = a->uimm };
|
||||||
|
return trans_lw(ctx, &arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool trans_c_flw_ld(DisasContext *ctx, arg_c_flw_ld *a)
|
||||||
|
{
|
||||||
|
#ifdef TARGET_RISCV32
|
||||||
|
/* C.FLW ( RV32FC-only ) */
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
/* C.LD ( RV64C/RV128C-only ) */
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool trans_c_fsd(DisasContext *ctx, arg_c_fsd *a)
|
||||||
|
{
|
||||||
|
arg_fsd arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm };
|
||||||
|
return trans_fsd(ctx, &arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool trans_c_sw(DisasContext *ctx, arg_c_sw *a)
|
||||||
|
{
|
||||||
|
arg_sw arg = { .rs1 = a->rs1, .rs2 = a->rs2, .imm = a->uimm };
|
||||||
|
return trans_sw(ctx, &arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool trans_c_fsw_sd(DisasContext *ctx, arg_c_fsw_sd *a)
|
||||||
|
{
|
||||||
|
#ifdef TARGET_RISCV32
|
||||||
|
/* C.FSW ( RV32FC-only ) */
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
/* C.SD ( RV64C/RV128C-only ) */
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -830,27 +830,6 @@ static void decode_RV32_64C0(DisasContext *ctx)
|
||||||
uint8_t rs1s = GET_C_RS1S(ctx->opcode);
|
uint8_t rs1s = GET_C_RS1S(ctx->opcode);
|
||||||
|
|
||||||
switch (funct3) {
|
switch (funct3) {
|
||||||
case 0:
|
|
||||||
/* illegal */
|
|
||||||
if (ctx->opcode == 0) {
|
|
||||||
gen_exception_illegal(ctx);
|
|
||||||
} else {
|
|
||||||
/* C.ADDI4SPN -> addi rd', x2, zimm[9:2]*/
|
|
||||||
gen_arith_imm(ctx, OPC_RISC_ADDI, rd_rs2, 2,
|
|
||||||
GET_C_ADDI4SPN_IMM(ctx->opcode));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
/* C.FLD -> fld rd', offset[7:3](rs1')*/
|
|
||||||
gen_fp_load(ctx, OPC_RISC_FLD, rd_rs2, rs1s,
|
|
||||||
GET_C_LD_IMM(ctx->opcode));
|
|
||||||
/* C.LQ(RV128) */
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
/* C.LW -> lw rd', offset[6:2](rs1') */
|
|
||||||
gen_load(ctx, OPC_RISC_LW, rd_rs2, rs1s,
|
|
||||||
GET_C_LW_IMM(ctx->opcode));
|
|
||||||
break;
|
|
||||||
case 3:
|
case 3:
|
||||||
#if defined(TARGET_RISCV64)
|
#if defined(TARGET_RISCV64)
|
||||||
/* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/
|
/* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/
|
||||||
|
@ -862,21 +841,6 @@ static void decode_RV32_64C0(DisasContext *ctx)
|
||||||
GET_C_LW_IMM(ctx->opcode));
|
GET_C_LW_IMM(ctx->opcode));
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case 4:
|
|
||||||
/* reserved */
|
|
||||||
gen_exception_illegal(ctx);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
/* C.FSD(RV32/64) -> fsd rs2', offset[7:3](rs1') */
|
|
||||||
gen_fp_store(ctx, OPC_RISC_FSD, rs1s, rd_rs2,
|
|
||||||
GET_C_LD_IMM(ctx->opcode));
|
|
||||||
/* C.SQ (RV128) */
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
/* C.SW -> sw rs2', offset[6:2](rs1')*/
|
|
||||||
gen_store(ctx, OPC_RISC_SW, rs1s, rd_rs2,
|
|
||||||
GET_C_LW_IMM(ctx->opcode));
|
|
||||||
break;
|
|
||||||
case 7:
|
case 7:
|
||||||
#if defined(TARGET_RISCV64)
|
#if defined(TARGET_RISCV64)
|
||||||
/* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/
|
/* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/
|
||||||
|
@ -1107,6 +1071,8 @@ static void decode_RV32_64C(DisasContext *ctx)
|
||||||
return imm << amount; \
|
return imm << amount; \
|
||||||
}
|
}
|
||||||
EX_SH(1)
|
EX_SH(1)
|
||||||
|
EX_SH(2)
|
||||||
|
EX_SH(3)
|
||||||
EX_SH(12)
|
EX_SH(12)
|
||||||
|
|
||||||
#define REQUIRE_EXT(ctx, ext) do { \
|
#define REQUIRE_EXT(ctx, ext) do { \
|
||||||
|
@ -1115,6 +1081,11 @@ EX_SH(12)
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
static int ex_rvc_register(int reg)
|
||||||
|
{
|
||||||
|
return 8 + reg;
|
||||||
|
}
|
||||||
|
|
||||||
bool decode_insn32(DisasContext *ctx, uint32_t insn);
|
bool decode_insn32(DisasContext *ctx, uint32_t insn);
|
||||||
/* Include the auto-generated decoder for 32 bit insn */
|
/* Include the auto-generated decoder for 32 bit insn */
|
||||||
#include "decode_insn32.inc.c"
|
#include "decode_insn32.inc.c"
|
||||||
|
@ -1126,6 +1097,11 @@ bool decode_insn32(DisasContext *ctx, uint32_t insn);
|
||||||
#include "insn_trans/trans_rvd.inc.c"
|
#include "insn_trans/trans_rvd.inc.c"
|
||||||
#include "insn_trans/trans_privileged.inc.c"
|
#include "insn_trans/trans_privileged.inc.c"
|
||||||
|
|
||||||
|
bool decode_insn16(DisasContext *ctx, uint16_t insn);
|
||||||
|
/* auto-generated decoder*/
|
||||||
|
#include "decode_insn16.inc.c"
|
||||||
|
#include "insn_trans/trans_rvc.inc.c"
|
||||||
|
|
||||||
static void decode_RV32_64G(DisasContext *ctx)
|
static void decode_RV32_64G(DisasContext *ctx)
|
||||||
{
|
{
|
||||||
int rs1, rd;
|
int rs1, rd;
|
||||||
|
@ -1159,8 +1135,11 @@ static void decode_opc(DisasContext *ctx)
|
||||||
gen_exception_illegal(ctx);
|
gen_exception_illegal(ctx);
|
||||||
} else {
|
} else {
|
||||||
ctx->pc_succ_insn = ctx->base.pc_next + 2;
|
ctx->pc_succ_insn = ctx->base.pc_next + 2;
|
||||||
|
if (!decode_insn16(ctx, ctx->opcode)) {
|
||||||
|
/* fall back to old decoder */
|
||||||
decode_RV32_64C(ctx);
|
decode_RV32_64C(ctx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ctx->pc_succ_insn = ctx->base.pc_next + 4;
|
ctx->pc_succ_insn = ctx->base.pc_next + 4;
|
||||||
if (!decode_insn32(ctx, ctx->opcode)) {
|
if (!decode_insn32(ctx, ctx->opcode)) {
|
||||||
|
|
Loading…
Reference in a new issue