diff options
author | Christoph Müllner <christoph.muellner@vrull.eu> | 2022-06-28 17:44:15 +0200 |
---|---|---|
committer | Philipp Tomsich <philipp.tomsich@vrull.eu> | 2022-09-22 18:06:09 +0200 |
commit | 8b7419c429919884adced1fd2eae8c805b45b49a (patch) | |
tree | 0ac96804e7726bb8ff28a03a429309f3a9e0665b /opcodes | |
parent | 547c18d9bb95571261dbd17f4767194037eb82bd (diff) | |
download | gdb-8b7419c429919884adced1fd2eae8c805b45b49a.zip gdb-8b7419c429919884adced1fd2eae8c805b45b49a.tar.gz gdb-8b7419c429919884adced1fd2eae8c805b45b49a.tar.bz2 |
RISC-V: Add support for arbitrary immediate encoding formats
This patch introduces support for arbitrary signed or unsigned immediate
encoding formats. The formats have the form "XsN@S" and "XuN@S" with N
being the number of bits and S the LSB position.
For example an immediate field of 5 bytes that encodes a signed value
and is stored in the bits 24-20 of the instruction word can use the
format specifier "Xs5@20".
Co-developed-by: Lifang Xia <lifang_xia@linux.alibaba.com>
Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
Diffstat (limited to 'opcodes')
-rw-r--r-- | opcodes/riscv-dis.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c index 99cebf3..2594e81 100644 --- a/opcodes/riscv-dis.c +++ b/opcodes/riscv-dis.c @@ -562,7 +562,41 @@ 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 'X': /* Integer immediate. */ + { + size_t n; + size_t s; + bool sign; + + switch (*++oparg) + { + case 's': /* 'XsN@S' ... N-bit signed immediate at bit S. */ + sign = true; + goto print_imm; + case 'u': /* 'XuN@S' ... N-bit unsigned immediate at bit S. */ + sign = false; + goto print_imm; + print_imm: + n = strtol (++oparg, (char **)&oparg, 10); + if (*oparg != '@') + goto undefined_modifier; + s = strtol (++oparg, (char **)&oparg, 10); + oparg--; + + if (!sign) + print (info->stream, dis_style_immediate, "%u", + (unsigned)EXTRACT_U_IMM (n, s, l)); + else + print (info->stream, dis_style_immediate, "%i", + (unsigned)EXTRACT_S_IMM (n, s, l)); + break; + default: + goto undefined_modifier; + } + } + break; default: + undefined_modifier: /* xgettext:c-format */ print (info->stream, dis_style_text, _("# internal error, undefined modifier (%c)"), |