[PATCH 10/13] RISC-V: Add support for literal instruction arguments
Christoph Muellner
christoph.muellner@vrull.eu
Tue Sep 6 12:22:10 GMT 2022
From: Christoph Müllner <christoph.muellner@vrull.eu>
This patch introduces support for arbitrary literal instruction
arguments, that are not encoded in the opcode.
A typical use case for this feature would be an instruction that
applies an implicit shift by a constant value on an immediate
(that is a real operand). With this patch it is possible to make
this shift visible in the dissasembly and support such artificial
parameter as part of the asssembly code.
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
---
gas/config/tc-riscv.c | 14 ++++++++++++++
opcodes/riscv-dis.c | 10 ++++++++++
2 files changed, 24 insertions(+)
diff --git a/gas/config/tc-riscv.c b/gas/config/tc-riscv.c
index 7f0db9fdb80..e89e9f492d9 100644
--- a/gas/config/tc-riscv.c
+++ b/gas/config/tc-riscv.c
@@ -1258,6 +1258,10 @@ validate_riscv_insn (const struct riscv_opcode *opc, int length)
goto unknown_validate_operand;
}
break;
+ case 'L': /* Literal. */
+ oparg += strcspn(oparg, ",") - 1;
+ break;
+
case 'X': /* Integer immediate. */
{
size_t n;
@@ -3295,6 +3299,16 @@ riscv_ip (char *str, struct riscv_cl_insn *ip, expressionS *imm_expr,
asarg = expr_end;
continue;
+ case 'L': /* Literal. */
+ {
+ size_t n = strcspn (++oparg, ",");
+ if (strncmp (oparg, asarg, n))
+ as_bad (_("unexpected literal (%s)"), asarg);
+ oparg += n - 1;
+ asarg += n;
+ }
+ continue;
+
case 'X': /* Integer immediate. */
{
size_t n;
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index c6ddea16dda..a4b030aa415 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -563,6 +563,16 @@ 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 'L': /* Literal. */
+ oparg++;
+ while (*oparg && *oparg != ',')
+ {
+ print (info->stream, dis_style_text, "%c", *oparg);
+ oparg++;
+ }
+ oparg--;
+ break;
+
case 'X': /* Integer immediate. */
{
size_t n;
--
2.37.2
More information about the Binutils
mailing list