From: Richard Bagley <rbagley@ventanamicro.com>
To: qemu-devel@nongnu.org
Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com,
bmeng@tinylab.org, liweiwei@iscas.ac.cn,
zhiwei_liu@linux.alibaba.com, palmer@rivosinc.com,
dbarboza@ventanamicro.com,
Richard Bagley <rbagley@ventanamicro.com>
Subject: [PATCH] disas/riscv: Further correction to LUI disassembly
Date: Mon, 31 Jul 2023 11:33:20 -0700 [thread overview]
Message-ID: <20230731183320.410922-1-rbagley@ventanamicro.com> (raw)
The recent commit 36df75a0a9 corrected one aspect of LUI disassembly
by recovering the immediate argument from the result of LUI with a
shift right by 12. However, the shift right will left-fill with the
sign. By applying a mask we recover an unsigned representation of the
20-bit field (which includes a sign bit).
Example:
0xfffff000 >> 12 = 0xffffffff
0xfffff000 >> 12 & 0xfffff = 0x000fffff
Fixes: 36df75a0a9 ("riscv/disas: Fix disas output of upper immediates")
Signed-off-by: Richard Bagley <rbagley@ventanamicro.com>
---
disas/riscv.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/disas/riscv.c b/disas/riscv.c
index 4023e3fc65..690eb4a1ac 100644
--- a/disas/riscv.c
+++ b/disas/riscv.c
@@ -4723,9 +4723,12 @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)
break;
case 'U':
fmt++;
- snprintf(tmp, sizeof(tmp), "%d", dec->imm >> 12);
- append(buf, tmp, buflen);
- if (*fmt == 'o') {
+ if (*fmt == 'i') {
+ snprintf(tmp, sizeof(tmp), "%d", dec->imm >> 12 & 0xfffff);
+ append(buf, tmp, buflen);
+ } else if (*fmt == 'o') {
+ snprintf(tmp, sizeof(tmp), "%d", dec->imm >> 12);
+ append(buf, tmp, buflen);
while (strlen(buf) < tab * 2) {
append(buf, " ", buflen);
}
--
2.34.1
next reply other threads:[~2023-07-31 18:33 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 18:33 Richard Bagley [this message]
2023-07-31 20:37 ` [PATCH] disas/riscv: Further correction to LUI disassembly Richard Henderson
2023-08-07 22:01 ` Richard Bagley
2023-08-07 22:59 ` Richard Henderson
2023-08-10 15:31 ` Andrew Jones
2023-08-10 16:12 ` Palmer Dabbelt
2023-08-10 16:27 ` Andrew Jones
2023-08-11 8:25 ` Andrew Jones
2023-08-11 11:55 ` Andrew Jones
2024-03-08 0:08 ` Richard Bagley
2024-03-09 4:22 ` Richard Bagley
2024-03-09 12:01 ` Andrew Jones
2024-03-11 18:56 ` Richard Bagley
2024-03-11 20:00 ` Richard Bagley
2024-03-12 11:09 ` Andrew Jones
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=20230731183320.410922-1-rbagley@ventanamicro.com \
--to=rbagley@ventanamicro.com \
--cc=alistair.francis@wdc.com \
--cc=bmeng@tinylab.org \
--cc=dbarboza@ventanamicro.com \
--cc=liweiwei@iscas.ac.cn \
--cc=palmer@rivosinc.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-riscv@nongnu.org \
--cc=zhiwei_liu@linux.alibaba.com \
/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 read-only IMAP folder(s) and NNTP newsgroup(s).