Skip to content

Commit 29547bb

Browse files
rivos-eblotjwnrt
authored andcommitted
disas: diassemble RISC-V Zbr0p93 instructions
Placed in a separate file as an unratified extension. Signed-off-by: James Wainwright <james.wainwright@lowrisc.org>
1 parent 865c069 commit 29547bb

5 files changed

Lines changed: 103 additions & 2 deletions

File tree

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4151,7 +4151,7 @@ M: Alistair Francis <Alistair.Francis@wdc.com>
41514151
L: qemu-riscv@nongnu.org
41524152
S: Maintained
41534153
F: tcg/riscv64/
4154-
F: disas/riscv.[ch]
4154+
F: disas/riscv*.[ch]
41554155

41564156
S390 TCG target
41574157
M: Richard Henderson <richard.henderson@linaro.org>

disas/meson.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ common_ss.add(when: 'CONFIG_MIPS_DIS', if_true: files('mips.c', 'nanomips.c'))
77
common_ss.add(when: 'CONFIG_RISCV_DIS', if_true: files(
88
'riscv.c',
99
'riscv-xthead.c',
10-
'riscv-xventana.c'
10+
'riscv-xventana.c',
11+
'riscv-xlrbr.c'
1112
))
1213
common_ss.add(when: 'CONFIG_SH4_DIS', if_true: files('sh4.c'))
1314
common_ss.add(when: 'CONFIG_SPARC_DIS', if_true: files('sparc.c'))

disas/riscv-xlrbr.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
/* Vendor extensions */
2727
#include "disas/riscv-xthead.h"
2828
#include "disas/riscv-xventana.h"
29+
#include "disas/riscv-xlrbr.h"
2930

3031
typedef enum {
3132
/* 0 is reserved for rv_op_illegal. */
@@ -5434,6 +5435,7 @@ static GString *disasm_inst(rv_isa isa, uint64_t pc, rv_inst inst,
54345435
{ has_xtheadmempair_p, xthead_opcode_data, decode_xtheadmempair },
54355436
{ has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
54365437
{ has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
5438+
{ has_xlrbr_p, rv_xlrbr_opcode_data, decode_xlrbr },
54375439
};
54385440

54395441
for (size_t i = 0; i < ARRAY_SIZE(decoders); i++) {

0 commit comments

Comments
 (0)