@samitouri / QOSamiQemu / commits / af58a69046

disas: diassemble RISC-V xlrbr (crc32) instructions

Placed in a separate file as a vendor extension. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org> Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Message-ID: <20260320134254.217123-4-james.wainwright@lowrisc.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>

Emmanuel Blot committed Mar 20, 2026 at 13:42 UTC af58a69046e951b351155718dac2a1b0798a71a2
5 files changed +103 -2
MAINTAINERS
+1 -1
@@ -4135,7 +4135,7 @@ R: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>
4135 L: qemu-riscv@nongnu.org
4136 S: Maintained
4137 F: tcg/riscv64/
4138 -F: disas/riscv.[ch]
4138 +F: disas/riscv*.[ch]
4139
4140 S390 TCG target
4141 M: Richard Henderson <richard.henderson@linaro.org>
disas/meson.build
+2 -1
@@ -7,7 +7,8 @@ common_ss.add(when: 'CONFIG_MIPS_DIS', if_true: files('mips.c', 'nanomips.c'))
7 common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files(
8 'riscv.c',
9 'riscv-xthead.c',
10 - 'riscv-xventana.c'
10 + 'riscv-xventana.c',
11 + 'riscv-xlrbr.c'
12 ))
13 common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
14 common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))
disas/riscv-xlrbr.c new
+79
@@ -0,0 +1,79 @@
1 +/*
2 + * QEMU RISC-V Disassembler for xlrbr matching the unratified Zbr CRC32
3 + * bitmanip extension v0.93.
4 + *
5 + * Copyright (c) 2023 Rivos Inc
6 + *
7 + * SPDX-License-Identifier: GPL-2.0-or-later
8 + */
9 +
10 +#include "qemu/osdep.h"
11 +
12 +#include "disas/riscv.h"
13 +#include "disas/riscv-xlrbr.h"
14 +
15 +typedef enum {
16 + /* 0 is reserved for rv_op_illegal. */
17 + rv_op_crc32_b = 1,
18 + rv_op_crc32_h = 2,
19 + rv_op_crc32_w = 3,
20 + rv_op_crc32_d = 4,
21 + rv_op_crc32c_b = 5,
22 + rv_op_crc32c_h = 6,
23 + rv_op_crc32c_w = 7,
24 + rv_op_crc32c_d = 8,
25 +} rv_xlrbr_op;
26 +
27 +const rv_opcode_data rv_xlrbr_opcode_data[] = {
28 + { "illegal", rv_codec_illegal, rv_fmt_none, NULL, 0, 0, 0 },
29 + { "crc32.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
30 + { "crc32.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
31 + { "crc32.w", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
32 + { "crc32.d", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
33 + { "crc32c.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
34 + { "crc32c.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
35 + { "crc32c.w", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
36 + { "crc32c.d", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
37 +};
38 +
39 +void decode_xlrbr(rv_decode *dec, rv_isa isa)
40 +{
41 + rv_inst inst = dec->inst;
42 + rv_opcode op = rv_op_illegal;
43 +
44 + switch ((inst >> 0) & 0b1111111) {
45 + case 0b0010011:
46 + switch ((inst >> 12) & 0b111) {
47 + case 0b001:
48 + switch ((inst >> 20 & 0b111111111111)) {
49 + case 0b011000010000:
50 + op = rv_op_crc32_b;
51 + break;
52 + case 0b011000010001:
53 + op = rv_op_crc32_h;
54 + break;
55 + case 0b011000010010:
56 + op = rv_op_crc32_w;
57 + break;
58 + case 0b011000010011:
59 + op = rv_op_crc32_d;
60 + break;
61 + case 0b011000011000:
62 + op = rv_op_crc32c_b;
63 + break;
64 + case 0b011000011001:
65 + op = rv_op_crc32c_h;
66 + break;
67 + case 0b011000011010:
68 + op = rv_op_crc32c_w;
69 + break;
70 + case 0b011000011011:
71 + op = rv_op_crc32c_d;
72 + break;
73 + }
74 + break;
75 + }
76 + break;
77 + }
78 + dec->op = op;
79 +}
disas/riscv-xlrbr.h new
+19
@@ -0,0 +1,19 @@
1 +/*
2 + * QEMU RISC-V Disassembler for xlrbr matching the unratified Zbr CRC32
3 + * bitmanip extension v0.93.
4 + *
5 + * Copyright (c) 2023 Rivos Inc
6 + *
7 + * SPDX-License-Identifier: GPL-2.0-or-later
8 + */
9 +
10 +#ifndef DISAS_RISCV_XLRBR_H
11 +#define DISAS_RISCV_XLRBR_H
12 +
13 +#include "disas/riscv.h"
14 +
15 +extern const rv_opcode_data rv_xlrbr_opcode_data[];
16 +
17 +void decode_xlrbr(rv_decode *, rv_isa);
18 +
19 +#endif /* DISAS_RISCV_XLRBR_H */
disas/riscv.c
+2
@@ -26,6 +26,7 @@
26 /* Vendor extensions */
27 #include "disas/riscv-xthead.h"
28 #include "disas/riscv-xventana.h"
29 +#include "disas/riscv-xlrbr.h"
30
31 typedef enum {
32 /* 0 is reserved for rv_op_illegal. */
@@ -5434,6 +5435,7 @@ static GString *disasm_inst(rv_isa isa, uint64_t pc, rv_inst inst,
5435 { has_xtheadmempair_p, xthead_opcode_data, decode_xtheadmempair },
5436 { has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
5437 { has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
5438 + { has_xlrbr_p, rv_xlrbr_opcode_data, decode_xlrbr },
5439 };
5440
5441 for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {