Skip to content

Commit

Permalink
RISC-V: Non-standard encodings of `fence.i' (disasm)
Browse files Browse the repository at this point in the history
This commit adds disassembler support for non-standard encodings of the
`fence.i' instruction.  Those fields are supposed to be zero but base
implementation shall ignore those fields.

gas/ChangeLog:

	* config/tc-riscv.c (validate_riscv_insn): Add ignored bit fields.
	(riscv_ip): Add support for ignored bit fields.
	* testsuite/gas/riscv/zifencei-dis-nonstd.s: New disasm test.
	* testsuite/gas/riscv/zifencei-dis-nonstd.d: Likewise.

opcodes/ChangeLog:

	* riscv-dis.c (print_insn_args): Add support for ignored bit fields.
	* riscv-opc.c (riscv_opcodes): Ignore RD/RS1/immediate (I-type)
	fields on the `fence.i' instruction.
  • Loading branch information
a4lg committed Jul 26, 2022
1 parent a66c11f commit 85bc9be
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
30 changes: 30 additions & 0 deletions gas/config/tc-riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,20 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
goto unknown_validate_operand;
}
break;
case '~': /* Ignored fields (w/o defaults). */
while (*++oparg)
{
switch (*oparg)
{
case 'd': USE_BITS (OP_MASK_RD, OP_SH_RD); break;
case 's': USE_BITS (OP_MASK_RS1, OP_SH_RS1); break;
case 'j': used_bits |= ENCODE_ITYPE_IMM (-1U); break;
default:
goto unknown_validate_operand;
}
}
--oparg;
break;
case '!': /* Operand with special handlings. */
switch (*++oparg)
{
Expand Down Expand Up @@ -3274,6 +3288,22 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
asarg = expr_end;
continue;

case '~': /* Ignored fields (w/o defaults). */
while (*++oparg)
{
switch (*oparg)
{
case 'd': /* Ignored RD. */
case 's': /* Ignored RS1. */
case 'j': /* Ignored immediate (I-type). */
break;
default:
goto unknown_riscv_ip_operand;
}
}
--oparg;
continue;

case '!': /* Operand with special handlings. */
switch (*++oparg)
{
Expand Down
15 changes: 15 additions & 0 deletions gas/testsuite/gas/riscv/zifencei-dis-nonstd.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#as: -march=rv32i_zifencei
#source: zifencei-dis-nonstd.s
#objdump: -dr

.*:[ ]+file format .*


Disassembly of section .text:

0+000 <target>:
[ ]+[0-9a-f]+:[ ]+0000100f[ ]+fence\.i
[ ]+[0-9a-f]+:[ ]+0000100f[ ]+fence\.i
[ ]+[0-9a-f]+:[ ]+00001f8f[ ]+fence\.i
[ ]+[0-9a-f]+:[ ]+000f900f[ ]+fence\.i
[ ]+[0-9a-f]+:[ ]+fff0100f[ ]+fence\.i
8 changes: 8 additions & 0 deletions gas/testsuite/gas/riscv/zifencei-dis-nonstd.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target:
fence.i
# Standard encoding of fence.i
.insn i MISC_MEM, 1, x0, x0, 0
# Following are non-standard encodings
.insn i MISC_MEM, 1, x31, x0, 0
.insn i MISC_MEM, 1, x0, x31, 0
.insn i MISC_MEM, 1, x0, x0, -1
5 changes: 4 additions & 1 deletion opcodes/riscv-dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
fprintf_styled_ftype print = info->fprintf_styled_func;
const char *opargStart;

if (*oparg != '\0')
if (*oparg != '\0' && *oparg != '~')
print (info->stream, dis_style_text, "\t");

for (; *oparg != '\0'; oparg++)
Expand Down Expand Up @@ -554,6 +554,9 @@ print_insn_args (const char *oparg, insn_t l, bfd_vma pc, disassemble_info *info
print (info->stream, dis_style_text, "%d", rs1);
break;

case '~': /* Ignored fields. */
return;

case '!': /* Operand with special handlings. */
switch (*++oparg)
{
Expand Down
2 changes: 1 addition & 1 deletion opcodes/riscv-opc.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ const struct riscv_opcode riscv_opcodes[] =
{"pause", 0, INSN_CLASS_ZIHINTPAUSE, "",MATCH_PAUSE, MASK_PAUSE, match_opcode, 0 },
{"fence", 0, INSN_CLASS_I, "", MATCH_FENCE|MASK_PRED|MASK_SUCC, MASK_FENCE|MASK_RD|MASK_RS1|MASK_IMM, match_opcode, INSN_ALIAS },
{"fence", 0, INSN_CLASS_I, "P,Q", MATCH_FENCE, MASK_FENCE|MASK_RD|MASK_RS1|(MASK_IMM & ~MASK_PRED & ~MASK_SUCC), match_opcode, 0 },
{"fence.i", 0, INSN_CLASS_ZIFENCEI, "", MATCH_FENCE_I, MASK_FENCE|MASK_RD|MASK_RS1|MASK_IMM, match_opcode, 0 },
{"fence.i", 0, INSN_CLASS_ZIFENCEI, "~dsj", MATCH_FENCE_I, MASK_FENCE_I, match_opcode, 0 },
{"fence.tso", 0, INSN_CLASS_I, "", MATCH_FENCE_TSO, MASK_FENCE_TSO|MASK_RD|MASK_RS1, match_opcode, INSN_ALIAS },
{"rdcycle", 0, INSN_CLASS_I, "d", MATCH_RDCYCLE, MASK_RDCYCLE, match_opcode, INSN_ALIAS },
{"rdinstret", 0, INSN_CLASS_I, "d", MATCH_RDINSTRET, MASK_RDINSTRET, match_opcode, INSN_ALIAS },
Expand Down

0 comments on commit 85bc9be

Please sign in to comment.