Skip to content

Commit fdcd59b

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 e4a223e commit fdcd59b

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
@@ -4144,7 +4144,7 @@ M: Alistair Francis <Alistair.Francis@wdc.com>
41444144
L: qemu-riscv@nongnu.org
41454145
S: Maintained
41464146
F: tcg/riscv64/
4147-
F: disas/riscv.[ch]
4147+
F: disas/riscv*.[ch]
41484148

41494149
S390 TCG target
41504150
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-xbr0p93.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-xbr0p93.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* QEMU RISC-V Disassembler for Zbr v0.93 (unratified)
3+
*
4+
* Copyright (c) 2023 Rivos Inc
5+
*
6+
* SPDX-License-Identifier: GPL-2.0-or-later
7+
*/
8+
9+
#include "qemu/osdep.h"
10+
11+
#include "disas/riscv.h"
12+
#include "disas/riscv-xbr0p93.h"
13+
14+
typedef enum {
15+
/* 0 is reserved for rv_op_illegal. */
16+
rv_op_crc32_b = 1,
17+
rv_op_crc32_h = 2,
18+
rv_op_crc32_w = 3,
19+
rv_op_crc32_d = 4,
20+
rv_op_crc32c_b = 5,
21+
rv_op_crc32c_h = 6,
22+
rv_op_crc32c_w = 7,
23+
rv_op_crc32c_d = 8,
24+
} rv_xbr0p93_op;
25+
26+
const rv_opcode_data rv_xbr0p93_opcode_data[] = {
27+
{ "illegal", rv_codec_illegal, rv_fmt_none, NULL, 0, 0, 0 },
28+
{ "crc32.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
29+
{ "crc32.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
30+
{ "crc32.w", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
31+
{ "crc32.d", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
32+
{ "crc32c.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
33+
{ "crc32c.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
34+
{ "crc32c.w", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
35+
{ "crc32c.d", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 },
36+
};
37+
38+
void decode_xbr0p93(rv_decode *dec, rv_isa isa)
39+
{
40+
rv_inst inst = dec->inst;
41+
rv_opcode op = rv_op_illegal;
42+
43+
switch ((inst >> 0) & 0b1111111) {
44+
case 0b0010011:
45+
switch ((inst >> 12) & 0b111) {
46+
case 0b001:
47+
switch ((inst >> 20 & 0b111111111111)) {
48+
case 0b011000010000:
49+
op = rv_op_crc32_b;
50+
break;
51+
case 0b011000010001:
52+
op = rv_op_crc32_h;
53+
break;
54+
case 0b011000010010:
55+
op = rv_op_crc32_w;
56+
break;
57+
case 0b011000010011:
58+
op = rv_op_crc32_d;
59+
break;
60+
case 0b011000011000:
61+
op = rv_op_crc32c_b;
62+
break;
63+
case 0b011000011001:
64+
op = rv_op_crc32c_h;
65+
break;
66+
case 0b011000011010:
67+
op = rv_op_crc32c_w;
68+
break;
69+
case 0b011000011011:
70+
op = rv_op_crc32c_d;
71+
break;
72+
}
73+
break;
74+
}
75+
break;
76+
}
77+
dec->op = op;
78+
}

disas/riscv-xbr0p93.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* QEMU RISC-V Disassembler for Zbr v0.93 (unratified)
3+
*
4+
* Copyright (c) 2023 Rivos Inc
5+
*
6+
* SPDX-License-Identifier: GPL-2.0-or-later
7+
*/
8+
9+
#ifndef DISAS_RISCV_XBR0P93_H
10+
#define DISAS_RISCV_XBR0P93_H
11+
12+
#include "disas/riscv.h"
13+
14+
extern const rv_opcode_data rv_xbr0p93_opcode_data[];
15+
16+
void decode_xbr0p93(rv_decode *, rv_isa);
17+
18+
#endif /* DISAS_RISCV_XBR0P93_H */

disas/riscv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include "disas/riscv-xthead.h"
2828
#include "disas/riscv-xventana.h"
2929

30+
/* Unratified extensions */
31+
#include "disas/riscv-xbr0p93.h"
32+
3033
typedef enum {
3134
/* 0 is reserved for rv_op_illegal. */
3235
rv_op_lui = 1,
@@ -5434,6 +5437,7 @@ static GString *disasm_inst(rv_isa isa, uint64_t pc, rv_inst inst,
54345437
{ has_xtheadmempair_p, xthead_opcode_data, decode_xtheadmempair },
54355438
{ has_xtheadsync_p, xthead_opcode_data, decode_xtheadsync },
54365439
{ has_XVentanaCondOps_p, ventana_opcode_data, decode_xventanacondops },
5440+
{ has_xbr0p93_p, rv_xbr0p93_opcode_data, decode_xbr0p93 },
54375441
};
54385442

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

0 commit comments

Comments
 (0)