1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946: |
---|---|---|---|
2 | 2 | ||
3 | The following changes since commit ca61fa4b803e5d0abaf6f1ceb690f23bb78a4def: | 3 | Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700) |
4 | |||
5 | Merge remote-tracking branch 'remotes/quic/tags/pull-hex-20211006' into staging (2021-10-06 12:11:14 -0700) | ||
6 | 4 | ||
7 | are available in the Git repository at: | 5 | are available in the Git repository at: |
8 | 6 | ||
9 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20211007 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528 |
10 | 8 | ||
11 | for you to fetch changes up to 9ae6ecd848dcd1b32003526ab65a0d4c644dfb07: | 9 | for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393: |
12 | 10 | ||
13 | hw/riscv: shakti_c: Mark as not user creatable (2021-10-07 08:41:33 +1000) | 11 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000) |
14 | 12 | ||
15 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
16 | Third RISC-V PR for QEMU 6.2 | 14 | RISC-V PR for 9.1 |
17 | 15 | ||
18 | - Add Zb[abcs] instruction support | 16 | * APLICs add child earlier than realize |
19 | - Remove RVB support | 17 | * Fix exposure of Zkr |
20 | - Bug fix of setting mstatus_hs.[SD|FS] bits | 18 | * Raise exceptions on wrs.nto |
21 | - Mark some UART devices as 'input' | 19 | * Implement SBI debug console (DBCN) calls for KVM |
22 | - QOMify PolarFire MMUART | 20 | * Support 64-bit addresses for initrd |
23 | - Fixes for sifive PDMA | 21 | * Change RISCV_EXCP_SEMIHOST exception number to 63 |
24 | - Mark shakti_c as not user creatable | 22 | * Tolerate KVM disable ext errors |
23 | * Set tval in breakpoints | ||
24 | * Add support for Zve32x extension | ||
25 | * Add support for Zve64x extension | ||
26 | * Relax vector register check in RISCV gdbstub | ||
27 | * Fix the element agnostic Vector function problem | ||
28 | * Fix Zvkb extension config | ||
29 | * Implement dynamic establishment of custom decoder | ||
30 | * Add th.sxstatus CSR emulation | ||
31 | * Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | ||
32 | * Check single width operator for vector fp widen instructions | ||
33 | * Check single width operator for vfncvt.rod.f.f.w | ||
34 | * Remove redudant SEW checking for vector fp narrow/widen instructions | ||
35 | * Prioritize pmp errors in raise_mmu_exception() | ||
36 | * Do not set mtval2 for non guest-page faults | ||
37 | * Remove experimental prefix from "B" extension | ||
38 | * Fixup CBO extension register calculation | ||
39 | * Fix the hart bit setting of AIA | ||
40 | * Fix reg_width in ricsv_gen_dynamic_vector_feature() | ||
41 | * Decode all of the pmpcfg and pmpaddr CSRs | ||
42 | * Raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
25 | 43 | ||
26 | ---------------------------------------------------------------- | 44 | ---------------------------------------------------------------- |
27 | Alistair Francis (1): | 45 | Alexei Filippov (1): |
28 | hw/riscv: shakti_c: Mark as not user creatable | 46 | target/riscv: do not set mtval2 for non guest-page faults |
29 | 47 | ||
30 | Bin Meng (5): | 48 | Alistair Francis (2): |
31 | hw/char: ibex_uart: Register device in 'input' category | 49 | target/riscv: rvzicbo: Fixup CBO extension register calculation |
32 | hw/char: shakti_uart: Register device in 'input' category | 50 | disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs |
33 | hw/char: sifive_uart: Register device in 'input' category | ||
34 | hw/dma: sifive_pdma: Fix Control.claim bit detection | ||
35 | hw/dma: sifive_pdma: Don't run DMA when channel is disclaimed | ||
36 | 51 | ||
37 | Frank Chang (1): | 52 | Andrew Jones (2): |
38 | target/riscv: Set mstatus_hs.[SD|FS] bits if Clean and V=1 in mark_fs_dirty() | 53 | target/riscv/kvm: Fix exposure of Zkr |
54 | target/riscv: Raise exceptions on wrs.nto | ||
39 | 55 | ||
40 | Philipp Tomsich (16): | 56 | Cheng Yang (1): |
41 | target/riscv: Introduce temporary in gen_add_uw() | 57 | hw/riscv/boot.c: Support 64-bit address for initrd |
42 | target/riscv: fix clzw implementation to operate on arg1 | ||
43 | target/riscv: clwz must ignore high bits (use shift-left & changed logic) | ||
44 | target/riscv: Add x-zba, x-zbb, x-zbc and x-zbs properties | ||
45 | target/riscv: Reassign instructions to the Zba-extension | ||
46 | target/riscv: Remove the W-form instructions from Zbs | ||
47 | target/riscv: Remove shift-one instructions (proposed Zbo in pre-0.93 draft-B) | ||
48 | target/riscv: Reassign instructions to the Zbs-extension | ||
49 | target/riscv: Add instructions of the Zbc-extension | ||
50 | target/riscv: Reassign instructions to the Zbb-extension | ||
51 | target/riscv: Add orc.b instruction for Zbb, removing gorc/gorci | ||
52 | target/riscv: Add a REQUIRE_32BIT macro | ||
53 | target/riscv: Add rev8 instruction, removing grev/grevi | ||
54 | target/riscv: Add zext.h instructions to Zbb, removing pack/packu/packh | ||
55 | target/riscv: Remove RVB (replaced by Zb[abcs]) | ||
56 | disas/riscv: Add Zb[abcs] instructions | ||
57 | 58 | ||
58 | Philippe Mathieu-Daudé (3): | 59 | Christoph Müllner (1): |
59 | hw/char/mchp_pfsoc_mmuart: Simplify MCHP_PFSOC_MMUART_REG definition | 60 | riscv: thead: Add th.sxstatus CSR emulation |
60 | hw/char/mchp_pfsoc_mmuart: Use a MemoryRegion container | ||
61 | hw/char/mchp_pfsoc_mmuart: QOM'ify PolarFire MMUART | ||
62 | 61 | ||
63 | include/hw/char/mchp_pfsoc_mmuart.h | 17 +- | 62 | Clément Léger (1): |
64 | target/riscv/cpu.h | 11 +- | 63 | target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63 |
65 | target/riscv/helper.h | 6 +- | ||
66 | target/riscv/insn32.decode | 115 ++++----- | ||
67 | disas/riscv.c | 157 +++++++++++- | ||
68 | hw/char/ibex_uart.c | 1 + | ||
69 | hw/char/mchp_pfsoc_mmuart.c | 116 +++++++-- | ||
70 | hw/char/shakti_uart.c | 1 + | ||
71 | hw/char/sifive_uart.c | 1 + | ||
72 | hw/dma/sifive_pdma.c | 13 +- | ||
73 | hw/riscv/shakti_c.c | 7 + | ||
74 | target/riscv/bitmanip_helper.c | 65 +---- | ||
75 | target/riscv/cpu.c | 30 +-- | ||
76 | target/riscv/translate.c | 36 ++- | ||
77 | target/riscv/insn_trans/trans_rvb.c.inc | 419 ++++++++++---------------------- | ||
78 | 15 files changed, 516 insertions(+), 479 deletions(-) | ||
79 | 64 | ||
65 | Daniel Henrique Barboza (6): | ||
66 | target/riscv/kvm: implement SBI debug console (DBCN) calls | ||
67 | target/riscv/kvm: tolerate KVM disable ext errors | ||
68 | target/riscv/debug: set tval=pc in breakpoint exceptions | ||
69 | trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint | ||
70 | target/riscv: prioritize pmp errors in raise_mmu_exception() | ||
71 | riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature() | ||
72 | |||
73 | Huang Tao (2): | ||
74 | target/riscv: Fix the element agnostic function problem | ||
75 | target/riscv: Implement dynamic establishment of custom decoder | ||
76 | |||
77 | Jason Chien (3): | ||
78 | target/riscv: Add support for Zve32x extension | ||
79 | target/riscv: Add support for Zve64x extension | ||
80 | target/riscv: Relax vector register check in RISCV gdbstub | ||
81 | |||
82 | Max Chou (4): | ||
83 | target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | ||
84 | target/riscv: rvv: Check single width operator for vector fp widen instructions | ||
85 | target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w | ||
86 | target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions | ||
87 | |||
88 | Rob Bradford (1): | ||
89 | target/riscv: Remove experimental prefix from "B" extension | ||
90 | |||
91 | Yangyu Chen (1): | ||
92 | target/riscv/cpu.c: fix Zvkb extension config | ||
93 | |||
94 | Yong-Xuan Wang (1): | ||
95 | target/riscv/kvm.c: Fix the hart bit setting of AIA | ||
96 | |||
97 | Yu-Ming Chang (1): | ||
98 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
99 | |||
100 | yang.zhang (1): | ||
101 | hw/intc/riscv_aplic: APLICs should add child earlier than realize | ||
102 | |||
103 | MAINTAINERS | 1 + | ||
104 | target/riscv/cpu.h | 11 ++ | ||
105 | target/riscv/cpu_bits.h | 2 +- | ||
106 | target/riscv/cpu_cfg.h | 2 + | ||
107 | target/riscv/helper.h | 1 + | ||
108 | target/riscv/sbi_ecall_interface.h | 17 +++ | ||
109 | target/riscv/tcg/tcg-cpu.h | 15 +++ | ||
110 | disas/riscv.c | 65 +++++++++- | ||
111 | hw/intc/riscv_aplic.c | 8 +- | ||
112 | hw/riscv/boot.c | 4 +- | ||
113 | target/riscv/cpu.c | 10 +- | ||
114 | target/riscv/cpu_helper.c | 37 +++--- | ||
115 | target/riscv/csr.c | 71 +++++++++-- | ||
116 | target/riscv/debug.c | 3 + | ||
117 | target/riscv/gdbstub.c | 8 +- | ||
118 | target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++- | ||
119 | target/riscv/op_helper.c | 17 ++- | ||
120 | target/riscv/tcg/tcg-cpu.c | 50 +++++--- | ||
121 | target/riscv/th_csr.c | 79 +++++++++++++ | ||
122 | target/riscv/translate.c | 31 +++-- | ||
123 | target/riscv/vector_internals.c | 22 ++++ | ||
124 | target/riscv/insn_trans/trans_privileged.c.inc | 2 + | ||
125 | target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++--- | ||
126 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++-- | ||
127 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++- | ||
128 | target/riscv/meson.build | 1 + | ||
129 | 26 files changed, 596 insertions(+), 109 deletions(-) | ||
130 | create mode 100644 target/riscv/th_csr.c | ||
131 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: "yang.zhang" <yang.zhang@hexintek.com> |
---|---|---|---|
2 | 2 | ||
3 | Our device have 2 different I/O regions: | 3 | Since only root APLICs can have hw IRQ lines, aplic->parent should |
4 | - a 16550 UART mapped for 32-bit accesses | 4 | be initialized first. |
5 | - 13 extra registers | ||
6 | 5 | ||
7 | Instead of mapping each region on the main bus, introduce | 6 | Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation") |
8 | a container, map the 2 devices regions on the container, | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | and map the container on the main bus. | 8 | Signed-off-by: yang.zhang <yang.zhang@hexintek.com> |
10 | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> | |
11 | Before: | 10 | Message-ID: <20240409014445.278-1-gaoshanliukou@163.com> |
12 | |||
13 | (qemu) info mtree | ||
14 | ... | ||
15 | 0000000020100000-000000002010001f (prio 0, i/o): serial | ||
16 | 0000000020100020-000000002010101f (prio 0, i/o): mchp.pfsoc.mmuart | ||
17 | 0000000020102000-000000002010201f (prio 0, i/o): serial | ||
18 | 0000000020102020-000000002010301f (prio 0, i/o): mchp.pfsoc.mmuart | ||
19 | 0000000020104000-000000002010401f (prio 0, i/o): serial | ||
20 | 0000000020104020-000000002010501f (prio 0, i/o): mchp.pfsoc.mmuart | ||
21 | 0000000020106000-000000002010601f (prio 0, i/o): serial | ||
22 | 0000000020106020-000000002010701f (prio 0, i/o): mchp.pfsoc.mmuart | ||
23 | |||
24 | After: | ||
25 | |||
26 | (qemu) info mtree | ||
27 | ... | ||
28 | 0000000020100000-0000000020100fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
29 | 0000000020100000-000000002010001f (prio 0, i/o): serial | ||
30 | 0000000020100020-0000000020100fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
31 | 0000000020102000-0000000020102fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
32 | 0000000020102000-000000002010201f (prio 0, i/o): serial | ||
33 | 0000000020102020-0000000020102fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
34 | 0000000020104000-0000000020104fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
35 | 0000000020104000-000000002010401f (prio 0, i/o): serial | ||
36 | 0000000020104020-0000000020104fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
37 | 0000000020106000-0000000020106fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
38 | 0000000020106000-000000002010601f (prio 0, i/o): serial | ||
39 | 0000000020106020-0000000020106fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
40 | |||
41 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
42 | Reviewed-by: Bin Meng <bin.meng@windriver.com> | ||
43 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
44 | Tested-by: Bin Meng <bin.meng@windriver.com> | ||
45 | Message-id: 20210925133407.1259392-3-f4bug@amsat.org | ||
46 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
47 | --- | 12 | --- |
48 | include/hw/char/mchp_pfsoc_mmuart.h | 1 + | 13 | hw/intc/riscv_aplic.c | 8 ++++---- |
49 | hw/char/mchp_pfsoc_mmuart.c | 11 ++++++++--- | 14 | 1 file changed, 4 insertions(+), 4 deletions(-) |
50 | 2 files changed, 9 insertions(+), 3 deletions(-) | ||
51 | 15 | ||
52 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h | 16 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
53 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/include/hw/char/mchp_pfsoc_mmuart.h | 18 | --- a/hw/intc/riscv_aplic.c |
55 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h | 19 | +++ b/hw/intc/riscv_aplic.c |
56 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
57 | #define MCHP_PFSOC_MMUART_REG_COUNT 13 | 21 | qdev_prop_set_bit(dev, "msimode", msimode); |
58 | 22 | qdev_prop_set_bit(dev, "mmode", mmode); | |
59 | typedef struct MchpPfSoCMMUartState { | 23 | |
60 | + MemoryRegion container; | 24 | + if (parent) { |
61 | MemoryRegion iomem; | 25 | + riscv_aplic_add_child(parent, dev); |
62 | hwaddr base; | 26 | + } |
63 | qemu_irq irq; | ||
64 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/hw/char/mchp_pfsoc_mmuart.c | ||
67 | +++ b/hw/char/mchp_pfsoc_mmuart.c | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | #include "chardev/char.h" | ||
70 | #include "hw/char/mchp_pfsoc_mmuart.h" | ||
71 | |||
72 | +#define REGS_OFFSET 0x20 | ||
73 | + | 27 | + |
74 | static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size) | 28 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
75 | { | 29 | |
76 | MchpPfSoCMMUartState *s = opaque; | 30 | if (!is_kvm_aia(msimode)) { |
77 | @@ -XXX,XX +XXX,XX @@ MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, | 31 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); |
78 | 32 | } | |
79 | s = g_new0(MchpPfSoCMMUartState, 1); | 33 | |
80 | 34 | - if (parent) { | |
81 | + memory_region_init(&s->container, NULL, "mchp.pfsoc.mmuart", 0x1000); | 35 | - riscv_aplic_add_child(parent, dev); |
82 | + | 36 | - } |
83 | memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s, | 37 | - |
84 | - "mchp.pfsoc.mmuart", 0x1000); | 38 | if (!msimode) { |
85 | + "mchp.pfsoc.mmuart.regs", 0x1000 - REGS_OFFSET); | 39 | for (i = 0; i < num_harts; i++) { |
86 | + memory_region_add_subregion(&s->container, REGS_OFFSET, &s->iomem); | 40 | CPUState *cpu = cpu_by_arch_id(hartid_base + i); |
87 | |||
88 | s->base = base; | ||
89 | s->irq = irq; | ||
90 | |||
91 | - s->serial = serial_mm_init(sysmem, base, 2, irq, 399193, chr, | ||
92 | + s->serial = serial_mm_init(&s->container, 0, 2, irq, 399193, chr, | ||
93 | DEVICE_LITTLE_ENDIAN); | ||
94 | |||
95 | - memory_region_add_subregion(sysmem, base + 0x20, &s->iomem); | ||
96 | + memory_region_add_subregion(sysmem, base, &s->container); | ||
97 | |||
98 | return s; | ||
99 | } | ||
100 | -- | 41 | -- |
101 | 2.31.1 | 42 | 2.45.1 |
102 | |||
103 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - Embed SerialMM in MchpPfSoCMMUartState and QOM-initialize it | 3 | The Zkr extension may only be exposed to KVM guests if the VMM |
4 | - Alias SERIAL_MM 'chardev' property on MCHP_PFSOC_UART | 4 | implements the SEED CSR. Use the same implementation as TCG. |
5 | - Forward SerialMM sysbus IRQ in mchp_pfsoc_mmuart_realize() | ||
6 | - Add DeviceReset() method | ||
7 | - Add vmstate structure for migration | ||
8 | - Register device in 'input' category | ||
9 | - Keep mchp_pfsoc_mmuart_create() behavior | ||
10 | 5 | ||
11 | Note, serial_mm_init() calls qdev_set_legacy_instance_id(). | 6 | Without this patch, running with a KVM which does not forward the |
12 | This call is only needed for backwards-compatibility of incoming | 7 | SEED CSR access to QEMU will result in an ILL exception being |
13 | migration data with old versions of QEMU which implemented migration | 8 | injected into the guest (this results in Linux guests crashing on |
14 | of devices with hand-rolled code. Since this device didn't previously | 9 | boot). And, when running with a KVM which does forward the access, |
15 | handle migration at all, then it doesn't need to set the legacy | 10 | QEMU will crash, since QEMU doesn't know what to do with the exit. |
16 | instance ID. | ||
17 | 11 | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 12 | Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8") |
19 | Reviewed-by: Bin Meng <bin.meng@windriver.com> | 13 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
20 | Tested-by: Bin Meng <bin.meng@windriver.com> | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Cc: qemu-stable <qemu-stable@nongnu.org> |
22 | Message-id: 20210925133407.1259392-4-f4bug@amsat.org | 16 | Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com> |
23 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
24 | --- | 18 | --- |
25 | include/hw/char/mchp_pfsoc_mmuart.h | 12 +++- | 19 | target/riscv/cpu.h | 3 +++ |
26 | hw/char/mchp_pfsoc_mmuart.c | 97 +++++++++++++++++++++++++---- | 20 | target/riscv/csr.c | 18 ++++++++++++++---- |
27 | 2 files changed, 93 insertions(+), 16 deletions(-) | 21 | target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++ |
22 | 3 files changed, 42 insertions(+), 4 deletions(-) | ||
28 | 23 | ||
29 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
30 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/include/hw/char/mchp_pfsoc_mmuart.h | 26 | --- a/target/riscv/cpu.h |
32 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h | 27 | +++ b/target/riscv/cpu.h |
33 | @@ -XXX,XX +XXX,XX @@ | 28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); |
34 | #ifndef HW_MCHP_PFSOC_MMUART_H | 29 | |
35 | #define HW_MCHP_PFSOC_MMUART_H | 30 | void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); |
36 | 31 | ||
37 | +#include "hw/sysbus.h" | 32 | +target_ulong riscv_new_csr_seed(target_ulong new_value, |
38 | #include "hw/char/serial.h" | 33 | + target_ulong write_mask); |
39 | |||
40 | #define MCHP_PFSOC_MMUART_REG_COUNT 13 | ||
41 | |||
42 | +#define TYPE_MCHP_PFSOC_UART "mchp.pfsoc.uart" | ||
43 | +OBJECT_DECLARE_SIMPLE_TYPE(MchpPfSoCMMUartState, MCHP_PFSOC_UART) | ||
44 | + | 34 | + |
45 | typedef struct MchpPfSoCMMUartState { | 35 | uint8_t satp_mode_max_from_map(uint32_t map); |
46 | + /*< private >*/ | 36 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
47 | + SysBusDevice parent_obj; | 37 | |
48 | + | 38 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
49 | + /*< public >*/ | ||
50 | MemoryRegion container; | ||
51 | MemoryRegion iomem; | ||
52 | - hwaddr base; | ||
53 | - qemu_irq irq; | ||
54 | |||
55 | - SerialMM *serial; | ||
56 | + SerialMM serial_mm; | ||
57 | |||
58 | uint32_t reg[MCHP_PFSOC_MMUART_REG_COUNT]; | ||
59 | } MchpPfSoCMMUartState; | ||
60 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
62 | --- a/hw/char/mchp_pfsoc_mmuart.c | 40 | --- a/target/riscv/csr.c |
63 | +++ b/hw/char/mchp_pfsoc_mmuart.c | 41 | +++ b/target/riscv/csr.c |
64 | @@ -XXX,XX +XXX,XX @@ | 42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, |
65 | 43 | #endif | |
66 | #include "qemu/osdep.h" | 44 | |
67 | #include "qemu/log.h" | 45 | /* Crypto Extension */ |
68 | -#include "chardev/char.h" | 46 | -static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
69 | +#include "qapi/error.h" | 47 | - target_ulong *ret_value, |
70 | +#include "migration/vmstate.h" | 48 | - target_ulong new_value, |
71 | #include "hw/char/mchp_pfsoc_mmuart.h" | 49 | - target_ulong write_mask) |
72 | +#include "hw/qdev-properties.h" | 50 | +target_ulong riscv_new_csr_seed(target_ulong new_value, |
73 | 51 | + target_ulong write_mask) | |
74 | #define REGS_OFFSET 0x20 | 52 | { |
75 | 53 | uint16_t random_v; | |
76 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { | 54 | Error *random_e = NULL; |
77 | }, | 55 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
78 | }; | 56 | rval = random_v | SEED_OPST_ES16; |
79 | 57 | } | |
80 | -MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, | 58 | |
81 | - hwaddr base, qemu_irq irq, Chardev *chr) | 59 | + return rval; |
82 | +static void mchp_pfsoc_mmuart_reset(DeviceState *dev) | ||
83 | +{ | ||
84 | + MchpPfSoCMMUartState *s = MCHP_PFSOC_UART(dev); | ||
85 | + | ||
86 | + memset(s->reg, 0, sizeof(s->reg)); | ||
87 | + device_cold_reset(DEVICE(&s->serial_mm)); | ||
88 | +} | 60 | +} |
89 | + | 61 | + |
90 | +static void mchp_pfsoc_mmuart_init(Object *obj) | 62 | +static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
91 | { | 63 | + target_ulong *ret_value, |
92 | - MchpPfSoCMMUartState *s; | 64 | + target_ulong new_value, |
93 | + MchpPfSoCMMUartState *s = MCHP_PFSOC_UART(obj); | 65 | + target_ulong write_mask) |
94 | |||
95 | - s = g_new0(MchpPfSoCMMUartState, 1); | ||
96 | + object_initialize_child(obj, "serial-mm", &s->serial_mm, TYPE_SERIAL_MM); | ||
97 | + object_property_add_alias(obj, "chardev", OBJECT(&s->serial_mm), "chardev"); | ||
98 | +} | ||
99 | |||
100 | - memory_region_init(&s->container, NULL, "mchp.pfsoc.mmuart", 0x1000); | ||
101 | +static void mchp_pfsoc_mmuart_realize(DeviceState *dev, Error **errp) | ||
102 | +{ | 66 | +{ |
103 | + MchpPfSoCMMUartState *s = MCHP_PFSOC_UART(dev); | 67 | + target_ulong rval; |
104 | 68 | + | |
105 | - memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s, | 69 | + rval = riscv_new_csr_seed(new_value, write_mask); |
106 | + qdev_prop_set_uint8(DEVICE(&s->serial_mm), "regshift", 2); | 70 | + |
107 | + qdev_prop_set_uint32(DEVICE(&s->serial_mm), "baudbase", 399193); | 71 | if (ret_value) { |
108 | + qdev_prop_set_uint8(DEVICE(&s->serial_mm), "endianness", | 72 | *ret_value = rval; |
109 | + DEVICE_LITTLE_ENDIAN); | 73 | } |
110 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->serial_mm), errp)) { | 74 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
111 | + return; | 75 | index XXXXXXX..XXXXXXX 100644 |
76 | --- a/target/riscv/kvm/kvm-cpu.c | ||
77 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
79 | return ret; | ||
80 | } | ||
81 | |||
82 | +static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run) | ||
83 | +{ | ||
84 | + target_ulong csr_num = run->riscv_csr.csr_num; | ||
85 | + target_ulong new_value = run->riscv_csr.new_value; | ||
86 | + target_ulong write_mask = run->riscv_csr.write_mask; | ||
87 | + int ret = 0; | ||
88 | + | ||
89 | + switch (csr_num) { | ||
90 | + case CSR_SEED: | ||
91 | + run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask); | ||
92 | + break; | ||
93 | + default: | ||
94 | + qemu_log_mask(LOG_UNIMP, | ||
95 | + "%s: un-handled CSR EXIT for CSR %lx\n", | ||
96 | + __func__, csr_num); | ||
97 | + ret = -1; | ||
98 | + break; | ||
112 | + } | 99 | + } |
113 | + | 100 | + |
114 | + sysbus_pass_irq(SYS_BUS_DEVICE(dev), SYS_BUS_DEVICE(&s->serial_mm)); | 101 | + return ret; |
115 | + | ||
116 | + memory_region_init(&s->container, OBJECT(s), "mchp.pfsoc.mmuart", 0x1000); | ||
117 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container); | ||
118 | + | ||
119 | + memory_region_add_subregion(&s->container, 0, | ||
120 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->serial_mm), 0)); | ||
121 | + | ||
122 | + memory_region_init_io(&s->iomem, OBJECT(s), &mchp_pfsoc_mmuart_ops, s, | ||
123 | "mchp.pfsoc.mmuart.regs", 0x1000 - REGS_OFFSET); | ||
124 | memory_region_add_subregion(&s->container, REGS_OFFSET, &s->iomem); | ||
125 | +} | ||
126 | |||
127 | - s->base = base; | ||
128 | - s->irq = irq; | ||
129 | +static const VMStateDescription mchp_pfsoc_mmuart_vmstate = { | ||
130 | + .name = "mchp.pfsoc.uart", | ||
131 | + .version_id = 0, | ||
132 | + .minimum_version_id = 0, | ||
133 | + .fields = (VMStateField[]) { | ||
134 | + VMSTATE_UINT32_ARRAY(reg, MchpPfSoCMMUartState, | ||
135 | + MCHP_PFSOC_MMUART_REG_COUNT), | ||
136 | + VMSTATE_END_OF_LIST() | ||
137 | + } | ||
138 | +}; | ||
139 | + | ||
140 | +static void mchp_pfsoc_mmuart_class_init(ObjectClass *oc, void *data) | ||
141 | +{ | ||
142 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
143 | + | ||
144 | + dc->realize = mchp_pfsoc_mmuart_realize; | ||
145 | + dc->reset = mchp_pfsoc_mmuart_reset; | ||
146 | + dc->vmsd = &mchp_pfsoc_mmuart_vmstate; | ||
147 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | ||
148 | +} | 102 | +} |
149 | + | 103 | + |
150 | +static const TypeInfo mchp_pfsoc_mmuart_info = { | 104 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
151 | + .name = TYPE_MCHP_PFSOC_UART, | 105 | { |
152 | + .parent = TYPE_SYS_BUS_DEVICE, | 106 | int ret = 0; |
153 | + .instance_size = sizeof(MchpPfSoCMMUartState), | 107 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
154 | + .instance_init = mchp_pfsoc_mmuart_init, | 108 | case KVM_EXIT_RISCV_SBI: |
155 | + .class_init = mchp_pfsoc_mmuart_class_init, | 109 | ret = kvm_riscv_handle_sbi(cs, run); |
156 | +}; | 110 | break; |
157 | + | 111 | + case KVM_EXIT_RISCV_CSR: |
158 | +static void mchp_pfsoc_mmuart_register_types(void) | 112 | + ret = kvm_riscv_handle_csr(cs, run); |
159 | +{ | 113 | + break; |
160 | + type_register_static(&mchp_pfsoc_mmuart_info); | 114 | default: |
161 | +} | 115 | qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", |
162 | + | 116 | __func__, run->exit_reason); |
163 | +type_init(mchp_pfsoc_mmuart_register_types) | ||
164 | + | ||
165 | +MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, | ||
166 | + hwaddr base, | ||
167 | + qemu_irq irq, Chardev *chr) | ||
168 | +{ | ||
169 | + DeviceState *dev = qdev_new(TYPE_MCHP_PFSOC_UART); | ||
170 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
171 | |||
172 | - s->serial = serial_mm_init(&s->container, 0, 2, irq, 399193, chr, | ||
173 | - DEVICE_LITTLE_ENDIAN); | ||
174 | + qdev_prop_set_chr(dev, "chardev", chr); | ||
175 | + sysbus_realize(sbd, &error_fatal); | ||
176 | |||
177 | - memory_region_add_subregion(sysmem, base, &s->container); | ||
178 | + memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(sbd, 0)); | ||
179 | + sysbus_connect_irq(sbd, 0, irq); | ||
180 | |||
181 | - return s; | ||
182 | + return MCHP_PFSOC_UART(dev); | ||
183 | } | ||
184 | -- | 117 | -- |
185 | 2.31.1 | 118 | 2.45.1 |
186 | |||
187 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The following instructions are part of Zbc: | 3 | Implementing wrs.nto to always just return is consistent with the |
4 | - clmul | 4 | specification, as the instruction is permitted to terminate the |
5 | - clmulh | 5 | stall for any reason, but it's not useful for virtualization, where |
6 | - clmulr | 6 | we'd like the guest to trap to the hypervisor in order to allow |
7 | scheduling of the lock holding VCPU. Change to always immediately | ||
8 | raise exceptions when the appropriate conditions are present, | ||
9 | otherwise continue to just return. Note, immediately raising | ||
10 | exceptions is also consistent with the specification since the | ||
11 | time limit that should expire prior to the exception is | ||
12 | implementation-specific. | ||
7 | 13 | ||
8 | Note that these instructions were already defined in the pre-0.93 and | 14 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
9 | the 0.93 draft-B proposals, but had not been omitted in the earlier | 15 | Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu> |
10 | addition of draft-B to QEmu. | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | |||
12 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
15 | Message-id: 20210911140016.834071-10-philipp.tomsich@vrull.eu | 18 | Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com> |
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 20 | --- |
18 | target/riscv/helper.h | 2 ++ | 21 | target/riscv/helper.h | 1 + |
19 | target/riscv/insn32.decode | 5 ++++ | 22 | target/riscv/op_helper.c | 11 ++++++++ |
20 | target/riscv/bitmanip_helper.c | 27 +++++++++++++++++++++ | 23 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++------- |
21 | target/riscv/insn_trans/trans_rvb.c.inc | 32 ++++++++++++++++++++++++- | 24 | 3 files changed, 32 insertions(+), 9 deletions(-) |
22 | 4 files changed, 65 insertions(+), 1 deletion(-) | ||
23 | 25 | ||
24 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 26 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
25 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/riscv/helper.h | 28 | --- a/target/riscv/helper.h |
27 | +++ b/target/riscv/helper.h | 29 | +++ b/target/riscv/helper.h |
28 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) |
29 | DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 31 | DEF_HELPER_1(sret, tl, env) |
30 | DEF_HELPER_FLAGS_2(gorc, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 32 | DEF_HELPER_1(mret, tl, env) |
31 | DEF_HELPER_FLAGS_2(gorcw, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 33 | DEF_HELPER_1(wfi, void, env) |
32 | +DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 34 | +DEF_HELPER_1(wrs_nto, void, env) |
33 | +DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 35 | DEF_HELPER_1(tlb_flush, void, env) |
34 | 36 | DEF_HELPER_1(tlb_flush_all, void, env) | |
35 | /* Special functions */ | 37 | /* Native Debug */ |
36 | DEF_HELPER_2(csrr, tl, env, int) | 38 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
37 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
38 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/riscv/insn32.decode | 40 | --- a/target/riscv/op_helper.c |
40 | +++ b/target/riscv/insn32.decode | 41 | +++ b/target/riscv/op_helper.c |
41 | @@ -XXX,XX +XXX,XX @@ roriw 0110000 .......... 101 ..... 0011011 @sh5 | 42 | @@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env) |
42 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | 43 | } |
43 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
44 | |||
45 | +# *** RV32 Zbc Standard Extension *** | ||
46 | +clmul 0000101 .......... 001 ..... 0110011 @r | ||
47 | +clmulh 0000101 .......... 011 ..... 0110011 @r | ||
48 | +clmulr 0000101 .......... 010 ..... 0110011 @r | ||
49 | + | ||
50 | # *** RV32 Zbs Standard Extension *** | ||
51 | bclr 0100100 .......... 001 ..... 0110011 @r | ||
52 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
53 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/bitmanip_helper.c | ||
56 | +++ b/target/riscv/bitmanip_helper.c | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | * | ||
59 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
60 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
61 | + * Copyright (c) 2021 Philipp Tomsich, philipp.tomsich@vrull.eu | ||
62 | * | ||
63 | * This program is free software; you can redistribute it and/or modify it | ||
64 | * under the terms and conditions of the GNU General Public License, | ||
65 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(gorcw)(target_ulong rs1, target_ulong rs2) | ||
66 | { | ||
67 | return do_gorc(rs1, rs2, 32); | ||
68 | } | 44 | } |
69 | + | 45 | |
70 | +target_ulong HELPER(clmul)(target_ulong rs1, target_ulong rs2) | 46 | +void helper_wrs_nto(CPURISCVState *env) |
71 | +{ | 47 | +{ |
72 | + target_ulong result = 0; | 48 | + if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) && |
73 | + | 49 | + get_field(env->hstatus, HSTATUS_VTW) && |
74 | + for (int i = 0; i < TARGET_LONG_BITS; i++) { | 50 | + !get_field(env->mstatus, MSTATUS_TW)) { |
75 | + if ((rs2 >> i) & 1) { | 51 | + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); |
76 | + result ^= (rs1 << i); | 52 | + } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) { |
77 | + } | 53 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); |
78 | + } | 54 | + } |
79 | + | ||
80 | + return result; | ||
81 | +} | 55 | +} |
82 | + | 56 | + |
83 | +target_ulong HELPER(clmulr)(target_ulong rs1, target_ulong rs2) | 57 | void helper_tlb_flush(CPURISCVState *env) |
58 | { | ||
59 | CPUState *cs = env_cpu(env); | ||
60 | diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
63 | +++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
66 | */ | ||
67 | |||
68 | -static bool trans_wrs(DisasContext *ctx) | ||
69 | +static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a) | ||
70 | { | ||
71 | if (!ctx->cfg_ptr->ext_zawrs) { | ||
72 | return false; | ||
73 | @@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx) | ||
74 | return true; | ||
75 | } | ||
76 | |||
77 | -#define GEN_TRANS_WRS(insn) \ | ||
78 | -static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ | ||
79 | -{ \ | ||
80 | - (void)a; \ | ||
81 | - return trans_wrs(ctx); \ | ||
82 | -} | ||
83 | +static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a) | ||
84 | +{ | 84 | +{ |
85 | + target_ulong result = 0; | 85 | + if (!ctx->cfg_ptr->ext_zawrs) { |
86 | + return false; | ||
87 | + } | ||
88 | |||
89 | -GEN_TRANS_WRS(wrs_nto) | ||
90 | -GEN_TRANS_WRS(wrs_sto) | ||
91 | + /* | ||
92 | + * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto | ||
93 | + * should raise an exception when the implementation-specific bounded time | ||
94 | + * limit has expired. Our time limit is zero, so we either return | ||
95 | + * immediately, as does our implementation of wrs.sto, or raise an | ||
96 | + * exception, as handled by the wrs.nto helper. | ||
97 | + */ | ||
98 | +#ifndef CONFIG_USER_ONLY | ||
99 | + gen_helper_wrs_nto(tcg_env); | ||
100 | +#endif | ||
86 | + | 101 | + |
87 | + for (int i = 0; i < TARGET_LONG_BITS; i++) { | 102 | + /* We only get here when helper_wrs_nto() doesn't raise an exception. */ |
88 | + if ((rs2 >> i) & 1) { | 103 | + return trans_wrs_sto(ctx, NULL); |
89 | + result ^= (rs1 >> (TARGET_LONG_BITS - i - 1)); | ||
90 | + } | ||
91 | + } | ||
92 | + | ||
93 | + return result; | ||
94 | +} | ||
95 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
98 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
99 | @@ -XXX,XX +XXX,XX @@ | ||
100 | /* | ||
101 | - * RISC-V translation routines for the RVB draft Zb[as] Standard Extension. | ||
102 | + * RISC-V translation routines for the Zb[acs] Standard Extension. | ||
103 | * | ||
104 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
105 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
106 | @@ -XXX,XX +XXX,XX @@ | ||
107 | } \ | ||
108 | } while (0) | ||
109 | |||
110 | +#define REQUIRE_ZBC(ctx) do { \ | ||
111 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ | ||
112 | + return false; \ | ||
113 | + } \ | ||
114 | +} while (0) | ||
115 | + | ||
116 | #define REQUIRE_ZBS(ctx) do { \ | ||
117 | if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ | ||
118 | return false; \ | ||
119 | @@ -XXX,XX +XXX,XX @@ static bool trans_slli_uw(DisasContext *ctx, arg_slli_uw *a) | ||
120 | REQUIRE_ZBA(ctx); | ||
121 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_slli_uw); | ||
122 | } | ||
123 | + | ||
124 | +static bool trans_clmul(DisasContext *ctx, arg_clmul *a) | ||
125 | +{ | ||
126 | + REQUIRE_ZBC(ctx); | ||
127 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_clmul); | ||
128 | +} | ||
129 | + | ||
130 | +static void gen_clmulh(TCGv dst, TCGv src1, TCGv src2) | ||
131 | +{ | ||
132 | + gen_helper_clmulr(dst, src1, src2); | ||
133 | + tcg_gen_shri_tl(dst, dst, 1); | ||
134 | +} | ||
135 | + | ||
136 | +static bool trans_clmulh(DisasContext *ctx, arg_clmulr *a) | ||
137 | +{ | ||
138 | + REQUIRE_ZBC(ctx); | ||
139 | + return gen_arith(ctx, a, EXT_NONE, gen_clmulh); | ||
140 | +} | ||
141 | + | ||
142 | +static bool trans_clmulr(DisasContext *ctx, arg_clmulh *a) | ||
143 | +{ | ||
144 | + REQUIRE_ZBC(ctx); | ||
145 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_clmulr); | ||
146 | +} | 104 | +} |
147 | -- | 105 | -- |
148 | 2.31.1 | 106 | 2.45.1 |
149 | 107 | ||
150 | 108 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The 1.0.0 version of Zbb does not contain pack/packu/packh. However, a | 3 | SBI defines a Debug Console extension "DBCN" that will, in time, replace |
4 | zext.h instruction is provided (built on pack/packh from pre-0.93 | 4 | the legacy console putchar and getchar SBI extensions. |
5 | draft-B) is available. | 5 | |
6 | 6 | The appeal of the DBCN extension is that it allows multiple bytes to be | |
7 | This commit adds zext.h and removes the pack* instructions. | 7 | read/written in the SBI console in a single SBI call. |
8 | 8 | ||
9 | Note that the encodings for zext.h are different between RV32 and | 9 | As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM |
10 | RV64, which is handled through REQUIRE_32BIT. | 10 | module to userspace. But this will only happens if the KVM module |
11 | 11 | actually supports this SBI extension and we activate it. | |
12 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 12 | |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 13 | We'll check for DBCN support during init time, checking if get-reg-list |
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via |
15 | Message-id: 20210911140016.834071-15-philipp.tomsich@vrull.eu | 15 | kvm_set_one_reg() during kvm_arch_init_vcpu(). |
16 | |||
17 | Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for | ||
18 | SBI_EXT_DBCN, reading and writing as required. | ||
19 | |||
20 | A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V | ||
21 | host, takes around 20 seconds to boot without using DBCN. With this | ||
22 | patch we're taking around 14 seconds to boot due to the speed-up in the | ||
23 | terminal output. There's no change in boot time if the guest isn't | ||
24 | using earlycon. | ||
25 | |||
26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
28 | Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 30 | --- |
18 | target/riscv/insn32.decode | 12 ++-- | 31 | target/riscv/sbi_ecall_interface.h | 17 +++++ |
19 | target/riscv/insn_trans/trans_rvb.c.inc | 86 ++++--------------------- | 32 | target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++ |
20 | 2 files changed, 21 insertions(+), 77 deletions(-) | 33 | 2 files changed, 128 insertions(+) |
21 | 34 | ||
22 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 35 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h |
23 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/insn32.decode | 37 | --- a/target/riscv/sbi_ecall_interface.h |
25 | +++ b/target/riscv/insn32.decode | 38 | +++ b/target/riscv/sbi_ecall_interface.h |
26 | @@ -XXX,XX +XXX,XX @@ rori 01100 ............ 101 ..... 0010011 @sh | 39 | @@ -XXX,XX +XXX,XX @@ |
27 | sext_b 011000 000100 ..... 001 ..... 0010011 @r2 | 40 | |
28 | sext_h 011000 000101 ..... 001 ..... 0010011 @r2 | 41 | /* clang-format off */ |
29 | xnor 0100000 .......... 100 ..... 0110011 @r | 42 | |
30 | +# The encoding for zext.h differs between RV32 and RV64. | 43 | +#define SBI_SUCCESS 0 |
31 | +# zext_h_32 denotes the RV32 variant. | 44 | +#define SBI_ERR_FAILED -1 |
32 | +zext_h_32 0000100 00000 ..... 100 ..... 0110011 @r2 | 45 | +#define SBI_ERR_NOT_SUPPORTED -2 |
33 | 46 | +#define SBI_ERR_INVALID_PARAM -3 | |
34 | # *** RV64 Zbb Standard Extension (in addition to RV32 Zbb) *** | 47 | +#define SBI_ERR_DENIED -4 |
35 | clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | 48 | +#define SBI_ERR_INVALID_ADDRESS -5 |
36 | @@ -XXX,XX +XXX,XX @@ rev8_64 011010 111000 ..... 101 ..... 0010011 @r2 | 49 | +#define SBI_ERR_ALREADY_AVAILABLE -6 |
37 | rolw 0110000 .......... 001 ..... 0111011 @r | 50 | +#define SBI_ERR_ALREADY_STARTED -7 |
38 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | 51 | +#define SBI_ERR_ALREADY_STOPPED -8 |
39 | rorw 0110000 .......... 101 ..... 0111011 @r | 52 | +#define SBI_ERR_NO_SHMEM -9 |
40 | +# The encoding for zext.h differs between RV32 and RV64. | 53 | + |
41 | +# When executing on RV64, the encoding used in RV32 is an illegal | 54 | /* SBI Extension IDs */ |
42 | +# instruction, so we use different handler functions to differentiate. | 55 | #define SBI_EXT_0_1_SET_TIMER 0x0 |
43 | +zext_h_64 0000100 00000 ..... 100 ..... 0111011 @r2 | 56 | #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 |
44 | 57 | @@ -XXX,XX +XXX,XX @@ | |
45 | # *** RV32B Standard Extension *** | 58 | #define SBI_EXT_IPI 0x735049 |
46 | -pack 0000100 .......... 100 ..... 0110011 @r | 59 | #define SBI_EXT_RFENCE 0x52464E43 |
47 | -packu 0100100 .......... 100 ..... 0110011 @r | 60 | #define SBI_EXT_HSM 0x48534D |
48 | -packh 0000100 .......... 111 ..... 0110011 @r | 61 | +#define SBI_EXT_DBCN 0x4442434E |
49 | 62 | ||
50 | # *** RV64B Standard Extension (in addition to RV32B) *** | 63 | /* SBI function IDs for BASE extension */ |
51 | -packw 0000100 .......... 100 ..... 0111011 @r | 64 | #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 |
52 | -packuw 0100100 .......... 100 ..... 0111011 @r | 65 | @@ -XXX,XX +XXX,XX @@ |
53 | 66 | #define SBI_EXT_HSM_HART_STOP 0x1 | |
54 | # *** RV32 Zbc Standard Extension *** | 67 | #define SBI_EXT_HSM_HART_GET_STATUS 0x2 |
55 | clmul 0000101 .......... 001 ..... 0110011 @r | 68 | |
56 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | 69 | +/* SBI function IDs for DBCN extension */ |
70 | +#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0 | ||
71 | +#define SBI_EXT_DBCN_CONSOLE_READ 0x1 | ||
72 | +#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2 | ||
73 | + | ||
74 | #define SBI_HSM_HART_STATUS_STARTED 0x0 | ||
75 | #define SBI_HSM_HART_STATUS_STOPPED 0x1 | ||
76 | #define SBI_HSM_HART_STATUS_START_PENDING 0x2 | ||
77 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | 78 | index XXXXXXX..XXXXXXX 100644 |
58 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 79 | --- a/target/riscv/kvm/kvm-cpu.c |
59 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 80 | +++ b/target/riscv/kvm/kvm-cpu.c |
60 | @@ -XXX,XX +XXX,XX @@ static bool trans_xnor(DisasContext *ctx, arg_xnor *a) | 81 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = { |
61 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_eqv_tl); | 82 | KVM_REG_RISCV_VECTOR_CSR_REG(vlenb) |
62 | } | 83 | }; |
63 | 84 | ||
64 | -static void gen_pack(TCGv ret, TCGv arg1, TCGv arg2) | 85 | +static KVMCPUConfig kvm_sbi_dbcn = { |
65 | -{ | 86 | + .name = "sbi_dbcn", |
66 | - tcg_gen_deposit_tl(ret, arg1, arg2, | 87 | + .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 | |
67 | - TARGET_LONG_BITS / 2, | 88 | + KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN |
68 | - TARGET_LONG_BITS / 2); | 89 | +}; |
69 | -} | 90 | + |
70 | - | 91 | static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
71 | -static bool trans_pack(DisasContext *ctx, arg_pack *a) | 92 | { |
72 | -{ | 93 | CPURISCVState *env = &cpu->env; |
73 | - REQUIRE_EXT(ctx, RVB); | 94 | @@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b) |
74 | - return gen_arith(ctx, a, EXT_NONE, gen_pack); | 95 | return 0; |
75 | -} | 96 | } |
76 | - | 97 | |
77 | -static void gen_packu(TCGv ret, TCGv arg1, TCGv arg2) | 98 | +static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu, |
78 | -{ | 99 | + KVMScratchCPU *kvmcpu, |
79 | - TCGv t = tcg_temp_new(); | 100 | + struct kvm_reg_list *reglist) |
80 | - tcg_gen_shri_tl(t, arg1, TARGET_LONG_BITS / 2); | ||
81 | - tcg_gen_deposit_tl(ret, arg2, t, 0, TARGET_LONG_BITS / 2); | ||
82 | - tcg_temp_free(t); | ||
83 | -} | ||
84 | - | ||
85 | -static bool trans_packu(DisasContext *ctx, arg_packu *a) | ||
86 | -{ | ||
87 | - REQUIRE_EXT(ctx, RVB); | ||
88 | - return gen_arith(ctx, a, EXT_NONE, gen_packu); | ||
89 | -} | ||
90 | - | ||
91 | -static void gen_packh(TCGv ret, TCGv arg1, TCGv arg2) | ||
92 | -{ | ||
93 | - TCGv t = tcg_temp_new(); | ||
94 | - tcg_gen_ext8u_tl(t, arg2); | ||
95 | - tcg_gen_deposit_tl(ret, arg1, t, 8, TARGET_LONG_BITS - 8); | ||
96 | - tcg_temp_free(t); | ||
97 | -} | ||
98 | - | ||
99 | -static bool trans_packh(DisasContext *ctx, arg_packh *a) | ||
100 | -{ | ||
101 | - REQUIRE_EXT(ctx, RVB); | ||
102 | - return gen_arith(ctx, a, EXT_NONE, gen_packh); | ||
103 | -} | ||
104 | - | ||
105 | static bool trans_min(DisasContext *ctx, arg_min *a) | ||
106 | { | ||
107 | REQUIRE_ZBB(ctx); | ||
108 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD(1) | ||
109 | GEN_TRANS_SHADD(2) | ||
110 | GEN_TRANS_SHADD(3) | ||
111 | |||
112 | +static bool trans_zext_h_32(DisasContext *ctx, arg_zext_h_32 *a) | ||
113 | +{ | 101 | +{ |
114 | + REQUIRE_32BIT(ctx); | 102 | + struct kvm_reg_list *reg_search; |
115 | + REQUIRE_ZBB(ctx); | 103 | + |
116 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16u_tl); | 104 | + reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n, |
105 | + sizeof(uint64_t), uint64_cmp); | ||
106 | + | ||
107 | + if (reg_search) { | ||
108 | + kvm_sbi_dbcn.supported = true; | ||
109 | + } | ||
117 | +} | 110 | +} |
118 | + | 111 | + |
119 | +static bool trans_zext_h_64(DisasContext *ctx, arg_zext_h_64 *a) | 112 | static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, |
113 | struct kvm_reg_list *reglist) | ||
114 | { | ||
115 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
116 | if (riscv_has_ext(&cpu->env, RVV)) { | ||
117 | kvm_riscv_read_vlenb(cpu, kvmcpu, reglist); | ||
118 | } | ||
119 | + | ||
120 | + kvm_riscv_check_sbi_dbcn_support(cpu, kvmcpu, reglist); | ||
121 | } | ||
122 | |||
123 | static void riscv_init_kvm_registers(Object *cpu_obj) | ||
124 | @@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs) | ||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | +static int kvm_vcpu_enable_sbi_dbcn(RISCVCPU *cpu, CPUState *cs) | ||
120 | +{ | 129 | +{ |
121 | + REQUIRE_64BIT(ctx); | 130 | + target_ulong reg = 1; |
122 | + REQUIRE_ZBB(ctx); | 131 | + |
123 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16u_tl); | 132 | + if (!kvm_sbi_dbcn.supported) { |
133 | + return 0; | ||
134 | + } | ||
135 | + | ||
136 | + return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, ®); | ||
124 | +} | 137 | +} |
125 | + | 138 | + |
126 | static void gen_clzw(TCGv ret, TCGv arg1) | 139 | int kvm_arch_init_vcpu(CPUState *cs) |
127 | { | 140 | { |
128 | TCGv t = tcg_temp_new(); | 141 | int ret = 0; |
129 | @@ -XXX,XX +XXX,XX @@ static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a) | 142 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) |
130 | return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl); | 143 | kvm_riscv_update_cpu_misa_ext(cpu, cs); |
131 | } | 144 | kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs); |
132 | 145 | ||
133 | -static void gen_packw(TCGv ret, TCGv arg1, TCGv arg2) | 146 | + ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs); |
134 | -{ | 147 | + |
135 | - TCGv t = tcg_temp_new(); | 148 | return ret; |
136 | - tcg_gen_ext16s_tl(t, arg2); | 149 | } |
137 | - tcg_gen_deposit_tl(ret, arg1, t, 16, 48); | 150 | |
138 | - tcg_temp_free(t); | 151 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) |
139 | -} | 152 | return true; |
140 | - | 153 | } |
141 | -static bool trans_packw(DisasContext *ctx, arg_packw *a) | 154 | |
142 | -{ | 155 | +static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run) |
143 | - REQUIRE_64BIT(ctx); | 156 | +{ |
144 | - REQUIRE_EXT(ctx, RVB); | 157 | + g_autofree uint8_t *buf = NULL; |
145 | - return gen_arith(ctx, a, EXT_NONE, gen_packw); | 158 | + RISCVCPU *cpu = RISCV_CPU(cs); |
146 | -} | 159 | + target_ulong num_bytes; |
147 | - | 160 | + uint64_t addr; |
148 | -static void gen_packuw(TCGv ret, TCGv arg1, TCGv arg2) | 161 | + unsigned char ch; |
149 | -{ | 162 | + int ret; |
150 | - TCGv t = tcg_temp_new(); | 163 | + |
151 | - tcg_gen_shri_tl(t, arg1, 16); | 164 | + switch (run->riscv_sbi.function_id) { |
152 | - tcg_gen_deposit_tl(ret, arg2, t, 0, 16); | 165 | + case SBI_EXT_DBCN_CONSOLE_READ: |
153 | - tcg_gen_ext32s_tl(ret, ret); | 166 | + case SBI_EXT_DBCN_CONSOLE_WRITE: |
154 | - tcg_temp_free(t); | 167 | + num_bytes = run->riscv_sbi.args[0]; |
155 | -} | 168 | + |
156 | - | 169 | + if (num_bytes == 0) { |
157 | -static bool trans_packuw(DisasContext *ctx, arg_packuw *a) | 170 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; |
158 | -{ | 171 | + run->riscv_sbi.ret[1] = 0; |
159 | - REQUIRE_64BIT(ctx); | 172 | + break; |
160 | - REQUIRE_EXT(ctx, RVB); | 173 | + } |
161 | - return gen_arith(ctx, a, EXT_NONE, gen_packuw); | 174 | + |
162 | -} | 175 | + addr = run->riscv_sbi.args[1]; |
163 | - | 176 | + |
164 | static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | 177 | + /* |
165 | { | 178 | + * Handle the case where a 32 bit CPU is running in a |
166 | TCGv_i32 t1 = tcg_temp_new_i32(); | 179 | + * 64 bit addressing env. |
180 | + */ | ||
181 | + if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) { | ||
182 | + addr |= (uint64_t)run->riscv_sbi.args[2] << 32; | ||
183 | + } | ||
184 | + | ||
185 | + buf = g_malloc0(num_bytes); | ||
186 | + | ||
187 | + if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) { | ||
188 | + ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes); | ||
189 | + if (ret < 0) { | ||
190 | + error_report("SBI_EXT_DBCN_CONSOLE_READ: error when " | ||
191 | + "reading chardev"); | ||
192 | + exit(1); | ||
193 | + } | ||
194 | + | ||
195 | + cpu_physical_memory_write(addr, buf, ret); | ||
196 | + } else { | ||
197 | + cpu_physical_memory_read(addr, buf, num_bytes); | ||
198 | + | ||
199 | + ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes); | ||
200 | + if (ret < 0) { | ||
201 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when " | ||
202 | + "writing chardev"); | ||
203 | + exit(1); | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
208 | + run->riscv_sbi.ret[1] = ret; | ||
209 | + break; | ||
210 | + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: | ||
211 | + ch = run->riscv_sbi.args[0]; | ||
212 | + ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); | ||
213 | + | ||
214 | + if (ret < 0) { | ||
215 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when " | ||
216 | + "writing chardev"); | ||
217 | + exit(1); | ||
218 | + } | ||
219 | + | ||
220 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
221 | + run->riscv_sbi.ret[1] = 0; | ||
222 | + break; | ||
223 | + default: | ||
224 | + run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED; | ||
225 | + } | ||
226 | +} | ||
227 | + | ||
228 | static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
229 | { | ||
230 | int ret = 0; | ||
231 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
232 | } | ||
233 | ret = 0; | ||
234 | break; | ||
235 | + case SBI_EXT_DBCN: | ||
236 | + kvm_riscv_handle_sbi_dbcn(cs, run); | ||
237 | + break; | ||
238 | default: | ||
239 | qemu_log_mask(LOG_UNIMP, | ||
240 | "%s: un-handled SBI EXIT, specific reasons is %lu\n", | ||
167 | -- | 241 | -- |
168 | 2.31.1 | 242 | 2.45.1 |
169 | |||
170 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Cheng Yang <yangcheng.work@foxmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Mark the shakti_c machine as not user creatable. | 3 | Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell() |
4 | to set the address of initrd in FDT to support 64-bit address. | ||
4 | 5 | ||
5 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/639 | 6 | Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com> | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-Id: <c617a04d4e3dd041a3427b47a1b1d5ab475a2edd.1632871759.git.alistair.francis@wdc.com> | ||
11 | --- | 10 | --- |
12 | hw/riscv/shakti_c.c | 7 +++++++ | 11 | hw/riscv/boot.c | 4 ++-- |
13 | 1 file changed, 7 insertions(+) | 12 | 1 file changed, 2 insertions(+), 2 deletions(-) |
14 | 13 | ||
15 | diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c | 14 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/riscv/shakti_c.c | 16 | --- a/hw/riscv/boot.c |
18 | +++ b/hw/riscv/shakti_c.c | 17 | +++ b/hw/riscv/boot.c |
19 | @@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_class_init(ObjectClass *klass, void *data) | 18 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) |
20 | { | 19 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ |
21 | DeviceClass *dc = DEVICE_CLASS(klass); | 20 | if (fdt) { |
22 | dc->realize = shakti_c_soc_state_realize; | 21 | end = start + size; |
23 | + /* | 22 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); |
24 | + * Reasons: | 23 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); |
25 | + * - Creates CPUS in riscv_hart_realize(), and can create unintended | 24 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start); |
26 | + * CPUs | 25 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end); |
27 | + * - Uses serial_hds in realize function, thus can't be used twice | 26 | } |
28 | + */ | ||
29 | + dc->user_creatable = false; | ||
30 | } | 27 | } |
31 | 28 | ||
32 | static void shakti_c_soc_instance_init(Object *obj) | ||
33 | -- | 29 | -- |
34 | 2.31.1 | 30 | 2.45.1 |
35 | |||
36 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng.cn@gmail.com> | 1 | From: Clément Léger <cleger@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | If Control.run bit is set while not preserving the Control.claim | 3 | The current semihost exception number (16) is a reserved number (range |
4 | bit, the DMA transfer shall not be started. | 4 | [16-17]). The upcoming double trap specification uses that number for |
5 | the double trap exception. Since the privileged spec (Table 22) defines | ||
6 | ranges for custom uses change the semihosting exception number to 63 | ||
7 | which belongs to the range [48-63] in order to avoid any future | ||
8 | collisions with reserved exception. | ||
5 | 9 | ||
6 | The following result is PDMA tested in U-Boot on Unleashed board: | 10 | Signed-off-by: Clément Léger <cleger@rivosinc.com> |
7 | 11 | ||
8 | => mw.l 0x3000000 0x0 <= Disclaim channel 0 | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | => mw.l 0x3000000 0x1 <= Claim channel 0 | 13 | Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com> |
10 | => mw.l 0x3000004 0x55000000 <= wsize = rsize = 5 (2^5 = 32 bytes) | ||
11 | => mw.q 0x3000008 0x2 <= NextBytes = 2 | ||
12 | => mw.q 0x3000010 0x84000000 <= NextDestination = 0x84000000 | ||
13 | => mw.q 0x3000018 0x84001000 <= NextSource = 0x84001000 | ||
14 | => mw.l 0x84000000 0x87654321 <= Fill test data to dst | ||
15 | => mw.l 0x84001000 0x12345678 <= Fill test data to src | ||
16 | => md.l 0x84000000 1; md.l 0x84001000 1 <= Dump src/dst memory contents | ||
17 | 84000000: 87654321 !Ce. | ||
18 | 84001000: 12345678 xV4. | ||
19 | => md.l 0x3000000 8 <= Dump PDMA status | ||
20 | 03000000: 00000001 55000000 00000002 00000000 .......U........ | ||
21 | 03000010: 84000000 00000000 84001000 00000000 ................ | ||
22 | => mw.l 0x3000000 0x2 <= Set channel 0 run bit only | ||
23 | => md.l 0x3000000 8 <= Dump PDMA status | ||
24 | 03000000: 00000000 55000000 00000002 00000000 .......U........ | ||
25 | 03000010: 84000000 00000000 84001000 00000000 ................ | ||
26 | => md.l 0x84000000 1; md.l 0x84001000 1 <= Dump src/dst memory contents | ||
27 | 84000000: 87654321 !Ce. | ||
28 | 84001000: 12345678 xV4. | ||
29 | |||
30 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
31 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
32 | Message-id: 20210927072124.1564129-2-bmeng.cn@gmail.com | ||
33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
34 | --- | 15 | --- |
35 | hw/dma/sifive_pdma.c | 11 +++++++++-- | 16 | target/riscv/cpu_bits.h | 2 +- |
36 | 1 file changed, 9 insertions(+), 2 deletions(-) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
37 | 18 | ||
38 | diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c | 19 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
39 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/hw/dma/sifive_pdma.c | 21 | --- a/target/riscv/cpu_bits.h |
41 | +++ b/hw/dma/sifive_pdma.c | 22 | +++ b/target/riscv/cpu_bits.h |
42 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, | 23 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
43 | { | 24 | RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ |
44 | SiFivePDMAState *s = opaque; | 25 | RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ |
45 | int ch = SIFIVE_PDMA_CHAN_NO(offset); | 26 | RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ |
46 | - bool claimed; | 27 | - RISCV_EXCP_SEMIHOST = 0x10, |
47 | + bool claimed, run; | 28 | RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, |
48 | 29 | RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, | |
49 | if (ch >= SIFIVE_PDMA_CHANS) { | 30 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, |
50 | qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid channel no %d\n", | 31 | RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, |
51 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, | 32 | + RISCV_EXCP_SEMIHOST = 0x3f, |
52 | switch (offset) { | 33 | } RISCVException; |
53 | case DMA_CONTROL: | 34 | |
54 | claimed = !!(s->chan[ch].control & CONTROL_CLAIM); | 35 | #define RISCV_EXCP_INT_FLAG 0x80000000 |
55 | + run = !!(s->chan[ch].control & CONTROL_RUN); | ||
56 | |||
57 | if (!claimed && (value & CONTROL_CLAIM)) { | ||
58 | /* reset Next* registers */ | ||
59 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, | ||
60 | s->chan[ch].next_src = 0; | ||
61 | } | ||
62 | |||
63 | + /* claim bit can only be cleared when run is low */ | ||
64 | + if (run && !(value & CONTROL_CLAIM)) { | ||
65 | + value |= CONTROL_CLAIM; | ||
66 | + } | ||
67 | + | ||
68 | s->chan[ch].control = value; | ||
69 | |||
70 | /* | ||
71 | * If channel was not claimed before run bit is set, | ||
72 | + * or if the channel is disclaimed when run was low, | ||
73 | * DMA won't run. | ||
74 | */ | ||
75 | - if (!claimed) { | ||
76 | + if (!claimed || (!run && !(value & CONTROL_CLAIM))) { | ||
77 | s->chan[ch].control &= ~CONTROL_RUN; | ||
78 | return; | ||
79 | } | ||
80 | -- | 36 | -- |
81 | 2.31.1 | 37 | 2.45.1 |
82 | 38 | ||
83 | 39 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | The following instructions are part of Zba: | 3 | Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr |
4 | - add.uw (RV64 only) | 4 | enabled, will fail with a kernel oops SIGILL right at the start. The |
5 | - sh[123]add (RV32 and RV64) | 5 | reason is that we can't expose zkr without implementing the SEED CSR. |
6 | - sh[123]add.uw (RV64-only) | 6 | Disabling zkr in the guest would be a workaround, but if the KVM doesn't |
7 | - slli.uw (RV64-only) | 7 | allow it we'll error out and never boot. |
8 | 8 | ||
9 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 9 | In hindsight this is too strict. If we keep proceeding, despite not |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 10 | disabling the extension in the KVM vcpu, we'll not add the extension in |
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | the riscv,isa. The guest kernel will be unaware of the extension, i.e. |
12 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | 12 | it doesn't matter if the KVM vcpu has it enabled underneath or not. So |
13 | Message-id: 20210911140016.834071-6-philipp.tomsich@vrull.eu | 13 | it's ok to keep booting in this case. |
14 | |||
15 | Change our current logic to not error out if we fail to disable an | ||
16 | extension in kvm_set_one_reg(), but show a warning and keep booting. It | ||
17 | is important to throw a warning because we must make the user aware that | ||
18 | the extension is still available in the vcpu, meaning that an | ||
19 | ill-behaved guest can ignore the riscv,isa settings and use the | ||
20 | extension. | ||
21 | |||
22 | The case we're handling happens with an EINVAL error code. If we fail to | ||
23 | disable the extension in KVM for any other reason, error out. | ||
24 | |||
25 | We'll also keep erroring out when we fail to enable an extension in KVM, | ||
26 | since adding the extension in riscv,isa at this point will cause a guest | ||
27 | malfunction because the extension isn't enabled in the vcpu. | ||
28 | |||
29 | Suggested-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
31 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
33 | Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 35 | --- |
16 | target/riscv/insn32.decode | 20 ++++++++++++-------- | 36 | target/riscv/kvm/kvm-cpu.c | 12 ++++++++---- |
17 | target/riscv/insn_trans/trans_rvb.c.inc | 16 +++++++++++----- | 37 | 1 file changed, 8 insertions(+), 4 deletions(-) |
18 | 2 files changed, 23 insertions(+), 13 deletions(-) | ||
19 | 38 | ||
20 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 39 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
21 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/insn32.decode | 41 | --- a/target/riscv/kvm/kvm-cpu.c |
23 | +++ b/target/riscv/insn32.decode | 42 | +++ b/target/riscv/kvm/kvm-cpu.c |
24 | @@ -XXX,XX +XXX,XX @@ vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm | 43 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
25 | vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm | 44 | reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); |
26 | vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm | 45 | ret = kvm_set_one_reg(cs, id, ®); |
27 | 46 | if (ret != 0) { | |
28 | +# *** RV32 Zba Standard Extension *** | 47 | - error_report("Unable to %s extension %s in KVM, error %d", |
29 | +sh1add 0010000 .......... 010 ..... 0110011 @r | 48 | - reg ? "enable" : "disable", |
30 | +sh2add 0010000 .......... 100 ..... 0110011 @r | 49 | - multi_ext_cfg->name, ret); |
31 | +sh3add 0010000 .......... 110 ..... 0110011 @r | 50 | - exit(EXIT_FAILURE); |
32 | + | 51 | + if (!reg && ret == -EINVAL) { |
33 | +# *** RV64 Zba Standard Extension (in addition to RV32 Zba) *** | 52 | + warn_report("KVM cannot disable extension %s", |
34 | +add_uw 0000100 .......... 000 ..... 0111011 @r | 53 | + multi_ext_cfg->name); |
35 | +sh1add_uw 0010000 .......... 010 ..... 0111011 @r | 54 | + } else { |
36 | +sh2add_uw 0010000 .......... 100 ..... 0111011 @r | 55 | + error_report("Unable to enable extension %s in KVM, error %d", |
37 | +sh3add_uw 0010000 .......... 110 ..... 0111011 @r | 56 | + multi_ext_cfg->name, ret); |
38 | +slli_uw 00001 ............ 001 ..... 0011011 @sh | 57 | + exit(EXIT_FAILURE); |
39 | + | 58 | + } |
40 | # *** RV32B Standard Extension *** | 59 | } |
41 | clz 011000 000000 ..... 001 ..... 0010011 @r2 | 60 | } |
42 | ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
43 | @@ -XXX,XX +XXX,XX @@ ror 0110000 .......... 101 ..... 0110011 @r | ||
44 | rol 0110000 .......... 001 ..... 0110011 @r | ||
45 | grev 0110100 .......... 101 ..... 0110011 @r | ||
46 | gorc 0010100 .......... 101 ..... 0110011 @r | ||
47 | -sh1add 0010000 .......... 010 ..... 0110011 @r | ||
48 | -sh2add 0010000 .......... 100 ..... 0110011 @r | ||
49 | -sh3add 0010000 .......... 110 ..... 0110011 @r | ||
50 | |||
51 | bseti 00101. ........... 001 ..... 0010011 @sh | ||
52 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
53 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | ||
54 | rolw 0110000 .......... 001 ..... 0111011 @r | ||
55 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
56 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
57 | -sh1add_uw 0010000 .......... 010 ..... 0111011 @r | ||
58 | -sh2add_uw 0010000 .......... 100 ..... 0111011 @r | ||
59 | -sh3add_uw 0010000 .......... 110 ..... 0111011 @r | ||
60 | -add_uw 0000100 .......... 000 ..... 0111011 @r | ||
61 | |||
62 | bsetiw 0010100 .......... 001 ..... 0011011 @sh5 | ||
63 | bclriw 0100100 .......... 001 ..... 0011011 @sh5 | ||
64 | @@ -XXX,XX +XXX,XX @@ roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
65 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
66 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
67 | |||
68 | -slli_uw 00001. ........... 001 ..... 0011011 @sh | ||
69 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
72 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
73 | @@ -XXX,XX +XXX,XX @@ | ||
74 | /* | ||
75 | - * RISC-V translation routines for the RVB Standard Extension. | ||
76 | + * RISC-V translation routines for the RVB draft and Zba Standard Extension. | ||
77 | * | ||
78 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
79 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
80 | + * Copyright (c) 2021 Philipp Tomsich, philipp.tomsich@vrull.eu | ||
81 | * | ||
82 | * This program is free software; you can redistribute it and/or modify it | ||
83 | * under the terms and conditions of the GNU General Public License, | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
86 | */ | ||
87 | |||
88 | +#define REQUIRE_ZBA(ctx) do { \ | ||
89 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zba) { \ | ||
90 | + return false; \ | ||
91 | + } \ | ||
92 | +} while (0) | ||
93 | |||
94 | static void gen_clz(TCGv ret, TCGv arg1) | ||
95 | { | ||
96 | @@ -XXX,XX +XXX,XX @@ GEN_SHADD(3) | ||
97 | #define GEN_TRANS_SHADD(SHAMT) \ | ||
98 | static bool trans_sh##SHAMT##add(DisasContext *ctx, arg_sh##SHAMT##add *a) \ | ||
99 | { \ | ||
100 | - REQUIRE_EXT(ctx, RVB); \ | ||
101 | + REQUIRE_ZBA(ctx); \ | ||
102 | return gen_arith(ctx, a, EXT_NONE, gen_sh##SHAMT##add); \ | ||
103 | } | ||
104 | |||
105 | @@ -XXX,XX +XXX,XX @@ static bool trans_sh##SHAMT##add_uw(DisasContext *ctx, \ | ||
106 | arg_sh##SHAMT##add_uw *a) \ | ||
107 | { \ | ||
108 | REQUIRE_64BIT(ctx); \ | ||
109 | - REQUIRE_EXT(ctx, RVB); \ | ||
110 | + REQUIRE_ZBA(ctx); \ | ||
111 | return gen_arith(ctx, a, EXT_NONE, gen_sh##SHAMT##add_uw); \ | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ static void gen_add_uw(TCGv ret, TCGv arg1, TCGv arg2) | ||
115 | static bool trans_add_uw(DisasContext *ctx, arg_add_uw *a) | ||
116 | { | ||
117 | REQUIRE_64BIT(ctx); | ||
118 | - REQUIRE_EXT(ctx, RVB); | ||
119 | + REQUIRE_ZBA(ctx); | ||
120 | return gen_arith(ctx, a, EXT_NONE, gen_add_uw); | ||
121 | } | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ static void gen_slli_uw(TCGv dest, TCGv src, target_long shamt) | ||
124 | static bool trans_slli_uw(DisasContext *ctx, arg_slli_uw *a) | ||
125 | { | ||
126 | REQUIRE_64BIT(ctx); | ||
127 | - REQUIRE_EXT(ctx, RVB); | ||
128 | + REQUIRE_ZBA(ctx); | ||
129 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_slli_uw); | ||
130 | } | 61 | } |
131 | -- | 62 | -- |
132 | 2.31.1 | 63 | 2.45.1 |
133 | |||
134 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | We're not setting (s/m)tval when triggering breakpoints of type 2 | ||
4 | (mcontrol) and 6 (mcontrol6). According to the debug spec section | ||
5 | 5.7.12, "Match Control Type 6": | ||
6 | |||
7 | "The Privileged Spec says that breakpoint exceptions that occur on | ||
8 | instruction fetches, loads, or stores update the tval CSR with either | ||
9 | zero or the faulting virtual address. The faulting virtual address for | ||
10 | an mcontrol6 trigger with action = 0 is the address being accessed and | ||
11 | which caused that trigger to fire." | ||
12 | |||
13 | A similar text is also found in the Debug spec section 5.7.11 w.r.t. | ||
14 | mcontrol. | ||
15 | |||
16 | Note that what we're doing ATM is not violating the spec, but it's | ||
17 | simple enough to set mtval/stval and it makes life easier for any | ||
18 | software that relies on this info. | ||
19 | |||
20 | Given that we always use action = 0, save the faulting address for the | ||
21 | mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is | ||
22 | used as as scratch area for traps with address information. 'tval' is | ||
23 | then set during riscv_cpu_do_interrupt(). | ||
24 | |||
25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
27 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
28 | Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com> | ||
29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
30 | --- | ||
31 | target/riscv/cpu_helper.c | 1 + | ||
32 | target/riscv/debug.c | 3 +++ | ||
33 | 2 files changed, 4 insertions(+) | ||
34 | |||
35 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/riscv/cpu_helper.c | ||
38 | +++ b/target/riscv/cpu_helper.c | ||
39 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | ||
40 | tval = env->bins; | ||
41 | break; | ||
42 | case RISCV_EXCP_BREAKPOINT: | ||
43 | + tval = env->badaddr; | ||
44 | if (cs->watchpoint_hit) { | ||
45 | tval = cs->watchpoint_hit->hitaddr; | ||
46 | cs->watchpoint_hit = NULL; | ||
47 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/riscv/debug.c | ||
50 | +++ b/target/riscv/debug.c | ||
51 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | ||
52 | if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { | ||
53 | /* check U/S/M bit against current privilege level */ | ||
54 | if ((ctrl >> 3) & BIT(env->priv)) { | ||
55 | + env->badaddr = pc; | ||
56 | return true; | ||
57 | } | ||
58 | } | ||
59 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) | ||
60 | if (env->virt_enabled) { | ||
61 | /* check VU/VS bit against current privilege level */ | ||
62 | if ((ctrl >> 23) & BIT(env->priv)) { | ||
63 | + env->badaddr = pc; | ||
64 | return true; | ||
65 | } | ||
66 | } else { | ||
67 | /* check U/S/M bit against current privilege level */ | ||
68 | if ((ctrl >> 3) & BIT(env->priv)) { | ||
69 | + env->badaddr = pc; | ||
70 | return true; | ||
71 | } | ||
72 | } | ||
73 | -- | ||
74 | 2.45.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Privileged spec section 4.1.9 mentions: | ||
4 | |||
5 | "When a trap is taken into S-mode, stval is written with | ||
6 | exception-specific information to assist software in handling the trap. | ||
7 | (...) | ||
8 | |||
9 | If stval is written with a nonzero value when a breakpoint, | ||
10 | address-misaligned, access-fault, or page-fault exception occurs on an | ||
11 | instruction fetch, load, or store, then stval will contain the faulting | ||
12 | virtual address." | ||
13 | |||
14 | A similar text is found for mtval in section 3.1.16. | ||
15 | |||
16 | Setting mtval/stval in this scenario is optional, but some softwares read | ||
17 | these regs when handling ebreaks. | ||
18 | |||
19 | Write 'badaddr' in all ebreak breakpoints to write the appropriate | ||
20 | 'tval' during riscv_do_cpu_interrrupt(). | ||
21 | |||
22 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | --- | ||
29 | target/riscv/insn_trans/trans_privileged.c.inc | 2 ++ | ||
30 | 1 file changed, 2 insertions(+) | ||
31 | |||
32 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/insn_trans/trans_privileged.c.inc | ||
35 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) | ||
37 | if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { | ||
38 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); | ||
39 | } else { | ||
40 | + tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, | ||
41 | + offsetof(CPURISCVState, badaddr)); | ||
42 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); | ||
43 | } | ||
44 | return true; | ||
45 | -- | ||
46 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The following instructions are part of Zbs: | 3 | Add support for Zve32x extension and replace some checks for Zve32f with |
4 | - b{set,clr,ext,inv} | 4 | Zve32x, since Zve32f depends on Zve32x. |
5 | - b{set,clr,ext,inv}i | ||
6 | 5 | ||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Max Chou <max.chou@sifive.com> |
10 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | 9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | Message-id: 20210911140016.834071-9-philipp.tomsich@vrull.eu | 10 | Message-ID: <20240328022343.6871-2-jason.chien@sifive.com> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 12 | --- |
14 | target/riscv/insn32.decode | 17 +++++++++-------- | 13 | target/riscv/cpu_cfg.h | 1 + |
15 | target/riscv/insn_trans/trans_rvb.c.inc | 25 +++++++++++++++---------- | 14 | target/riscv/cpu.c | 2 ++ |
16 | 2 files changed, 24 insertions(+), 18 deletions(-) | 15 | target/riscv/cpu_helper.c | 2 +- |
16 | target/riscv/csr.c | 2 +- | ||
17 | target/riscv/tcg/tcg-cpu.c | 16 ++++++++-------- | ||
18 | target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- | ||
19 | 6 files changed, 15 insertions(+), 12 deletions(-) | ||
17 | 20 | ||
18 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 21 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
19 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/insn32.decode | 23 | --- a/target/riscv/cpu_cfg.h |
21 | +++ b/target/riscv/insn32.decode | 24 | +++ b/target/riscv/cpu_cfg.h |
22 | @@ -XXX,XX +XXX,XX @@ min 0000101 .......... 100 ..... 0110011 @r | 25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
23 | minu 0000101 .......... 101 ..... 0110011 @r | 26 | bool ext_zhinx; |
24 | max 0000101 .......... 110 ..... 0110011 @r | 27 | bool ext_zhinxmin; |
25 | maxu 0000101 .......... 111 ..... 0110011 @r | 28 | bool ext_zve32f; |
26 | -bset 0010100 .......... 001 ..... 0110011 @r | 29 | + bool ext_zve32x; |
27 | -bclr 0100100 .......... 001 ..... 0110011 @r | 30 | bool ext_zve64f; |
28 | -binv 0110100 .......... 001 ..... 0110011 @r | 31 | bool ext_zve64d; |
29 | -bext 0100100 .......... 101 ..... 0110011 @r | 32 | bool ext_zvbb; |
30 | ror 0110000 .......... 101 ..... 0110011 @r | 33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
31 | rol 0110000 .......... 001 ..... 0110011 @r | ||
32 | grev 0110100 .......... 101 ..... 0110011 @r | ||
33 | gorc 0010100 .......... 101 ..... 0110011 @r | ||
34 | |||
35 | -bseti 00101. ........... 001 ..... 0010011 @sh | ||
36 | -bclri 01001. ........... 001 ..... 0010011 @sh | ||
37 | -binvi 01101. ........... 001 ..... 0010011 @sh | ||
38 | -bexti 01001. ........... 101 ..... 0010011 @sh | ||
39 | rori 01100. ........... 101 ..... 0010011 @sh | ||
40 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
41 | gorci 00101. ........... 101 ..... 0010011 @sh | ||
42 | @@ -XXX,XX +XXX,XX @@ roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
43 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
44 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
45 | |||
46 | +# *** RV32 Zbs Standard Extension *** | ||
47 | +bclr 0100100 .......... 001 ..... 0110011 @r | ||
48 | +bclri 01001. ........... 001 ..... 0010011 @sh | ||
49 | +bext 0100100 .......... 101 ..... 0110011 @r | ||
50 | +bexti 01001. ........... 101 ..... 0010011 @sh | ||
51 | +binv 0110100 .......... 001 ..... 0110011 @r | ||
52 | +binvi 01101. ........... 001 ..... 0010011 @sh | ||
53 | +bset 0010100 .......... 001 ..... 0110011 @r | ||
54 | +bseti 00101. ........... 001 ..... 0010011 @sh | ||
55 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
56 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
57 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 35 | --- a/target/riscv/cpu.c |
58 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 36 | +++ b/target/riscv/cpu.c |
59 | @@ -XXX,XX +XXX,XX @@ | 37 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
60 | /* | 38 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), |
61 | - * RISC-V translation routines for the RVB draft and Zba Standard Extension. | 39 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), |
62 | + * RISC-V translation routines for the RVB draft Zb[as] Standard Extension. | 40 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), |
63 | * | 41 | + ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
64 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | 42 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
65 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | 43 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), |
66 | @@ -XXX,XX +XXX,XX @@ | 44 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
67 | } \ | 45 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
68 | } while (0) | 46 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), |
69 | 47 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | |
70 | +#define REQUIRE_ZBS(ctx) do { \ | 48 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), |
71 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ | 49 | + MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), |
72 | + return false; \ | 50 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), |
73 | + } \ | 51 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), |
74 | +} while (0) | 52 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), |
75 | + | 53 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
76 | static void gen_clz(TCGv ret, TCGv arg1) | 54 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/target/riscv/cpu_helper.c | ||
56 | +++ b/target/riscv/cpu_helper.c | ||
57 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | ||
58 | *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; | ||
59 | *cs_base = 0; | ||
60 | |||
61 | - if (cpu->cfg.ext_zve32f) { | ||
62 | + if (cpu->cfg.ext_zve32x) { | ||
63 | /* | ||
64 | * If env->vl equals to VLMAX, we can use generic vector operation | ||
65 | * expanders (GVEC) to accerlate the vector operations. | ||
66 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/target/riscv/csr.c | ||
69 | +++ b/target/riscv/csr.c | ||
70 | @@ -XXX,XX +XXX,XX @@ static RISCVException fs(CPURISCVState *env, int csrno) | ||
71 | |||
72 | static RISCVException vs(CPURISCVState *env, int csrno) | ||
77 | { | 73 | { |
78 | tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS); | 74 | - if (riscv_cpu_cfg(env)->ext_zve32f) { |
79 | } | 75 | + if (riscv_cpu_cfg(env)->ext_zve32x) { |
80 | - | 76 | #if !defined(CONFIG_USER_ONLY) |
81 | static bool trans_clz(DisasContext *ctx, arg_clz *a) | 77 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { |
78 | return RISCV_EXCP_ILLEGAL_INST; | ||
79 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/target/riscv/tcg/tcg-cpu.c | ||
82 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
83 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
84 | return; | ||
85 | } | ||
86 | |||
87 | - if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { | ||
88 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
89 | - return; | ||
90 | + /* The Zve32f extension depends on the Zve32x extension */ | ||
91 | + if (cpu->cfg.ext_zve32f) { | ||
92 | + if (!riscv_has_ext(env, RVF)) { | ||
93 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
94 | + return; | ||
95 | + } | ||
96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
97 | } | ||
98 | |||
99 | if (cpu->cfg.ext_zvfh) { | ||
100 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
101 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true); | ||
102 | } | ||
103 | |||
104 | - /* | ||
105 | - * In principle Zve*x would also suffice here, were they supported | ||
106 | - * in qemu | ||
107 | - */ | ||
108 | if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg || | ||
109 | cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || | ||
110 | - cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
111 | + cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) { | ||
112 | error_setg(errp, | ||
113 | "Vector crypto extensions require V or Zve* extensions"); | ||
114 | return; | ||
115 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
118 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
119 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
82 | { | 120 | { |
83 | REQUIRE_EXT(ctx, RVB); | 121 | TCGv s1, dst; |
84 | @@ -XXX,XX +XXX,XX @@ static void gen_bset(TCGv ret, TCGv arg1, TCGv shamt) | 122 | |
85 | 123 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | |
86 | static bool trans_bset(DisasContext *ctx, arg_bset *a) | 124 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { |
125 | return false; | ||
126 | } | ||
127 | |||
128 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) | ||
87 | { | 129 | { |
88 | - REQUIRE_EXT(ctx, RVB); | 130 | TCGv dst; |
89 | + REQUIRE_ZBS(ctx); | 131 | |
90 | return gen_shift(ctx, a, EXT_NONE, gen_bset); | 132 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { |
91 | } | 133 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { |
92 | 134 | return false; | |
93 | static bool trans_bseti(DisasContext *ctx, arg_bseti *a) | 135 | } |
94 | { | ||
95 | - REQUIRE_EXT(ctx, RVB); | ||
96 | + REQUIRE_ZBS(ctx); | ||
97 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bset); | ||
98 | } | ||
99 | |||
100 | @@ -XXX,XX +XXX,XX @@ static void gen_bclr(TCGv ret, TCGv arg1, TCGv shamt) | ||
101 | |||
102 | static bool trans_bclr(DisasContext *ctx, arg_bclr *a) | ||
103 | { | ||
104 | - REQUIRE_EXT(ctx, RVB); | ||
105 | + REQUIRE_ZBS(ctx); | ||
106 | return gen_shift(ctx, a, EXT_NONE, gen_bclr); | ||
107 | } | ||
108 | |||
109 | static bool trans_bclri(DisasContext *ctx, arg_bclri *a) | ||
110 | { | ||
111 | - REQUIRE_EXT(ctx, RVB); | ||
112 | + REQUIRE_ZBS(ctx); | ||
113 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bclr); | ||
114 | } | ||
115 | |||
116 | @@ -XXX,XX +XXX,XX @@ static void gen_binv(TCGv ret, TCGv arg1, TCGv shamt) | ||
117 | |||
118 | static bool trans_binv(DisasContext *ctx, arg_binv *a) | ||
119 | { | ||
120 | - REQUIRE_EXT(ctx, RVB); | ||
121 | + REQUIRE_ZBS(ctx); | ||
122 | return gen_shift(ctx, a, EXT_NONE, gen_binv); | ||
123 | } | ||
124 | |||
125 | static bool trans_binvi(DisasContext *ctx, arg_binvi *a) | ||
126 | { | ||
127 | - REQUIRE_EXT(ctx, RVB); | ||
128 | + REQUIRE_ZBS(ctx); | ||
129 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_binv); | ||
130 | } | ||
131 | |||
132 | @@ -XXX,XX +XXX,XX @@ static void gen_bext(TCGv ret, TCGv arg1, TCGv shamt) | ||
133 | |||
134 | static bool trans_bext(DisasContext *ctx, arg_bext *a) | ||
135 | { | ||
136 | - REQUIRE_EXT(ctx, RVB); | ||
137 | + REQUIRE_ZBS(ctx); | ||
138 | return gen_shift(ctx, a, EXT_NONE, gen_bext); | ||
139 | } | ||
140 | |||
141 | static bool trans_bexti(DisasContext *ctx, arg_bexti *a) | ||
142 | { | ||
143 | - REQUIRE_EXT(ctx, RVB); | ||
144 | + REQUIRE_ZBS(ctx); | ||
145 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext); | ||
146 | } | ||
147 | 136 | ||
148 | -- | 137 | -- |
149 | 2.31.1 | 138 | 2.45.1 |
150 | |||
151 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The current MCHP_PFSOC_MMUART_REG_SIZE definition represent the | 3 | Add support for Zve64x extension. Enabling Zve64f enables Zve64x and |
4 | size occupied by all the registers. However all registers are | 4 | enabling Zve64x enables Zve32x according to their dependency. |
5 | 32-bit wide, and the MemoryRegionOps handlers are restricted to | ||
6 | 32-bit: | ||
7 | 5 | ||
8 | static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { | 6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107 |
9 | .read = mchp_pfsoc_mmuart_read, | 7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
10 | .write = mchp_pfsoc_mmuart_write, | 8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
11 | .impl = { | 9 | Reviewed-by: Max Chou <max.chou@sifive.com> |
12 | .min_access_size = 4, | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
13 | .max_access_size = 4, | 11 | Message-ID: <20240328022343.6871-3-jason.chien@sifive.com> |
14 | }, | ||
15 | |||
16 | Avoid being triskaidekaphobic, simplify by using the number of | ||
17 | registers. | ||
18 | |||
19 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | Reviewed-by: Bin Meng <bin.meng@windriver.com> | ||
21 | Tested-by: Bin Meng <bin.meng@windriver.com> | ||
22 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
23 | Message-id: 20210925133407.1259392-2-f4bug@amsat.org | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 13 | --- |
26 | include/hw/char/mchp_pfsoc_mmuart.h | 4 ++-- | 14 | target/riscv/cpu_cfg.h | 1 + |
27 | hw/char/mchp_pfsoc_mmuart.c | 14 ++++++++------ | 15 | target/riscv/cpu.c | 2 ++ |
28 | 2 files changed, 10 insertions(+), 8 deletions(-) | 16 | target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------ |
17 | 3 files changed, 14 insertions(+), 6 deletions(-) | ||
29 | 18 | ||
30 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h | 19 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
31 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/include/hw/char/mchp_pfsoc_mmuart.h | 21 | --- a/target/riscv/cpu_cfg.h |
33 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h | 22 | +++ b/target/riscv/cpu_cfg.h |
34 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
35 | 24 | bool ext_zve32x; | |
36 | #include "hw/char/serial.h" | 25 | bool ext_zve64f; |
37 | 26 | bool ext_zve64d; | |
38 | -#define MCHP_PFSOC_MMUART_REG_SIZE 52 | 27 | + bool ext_zve64x; |
39 | +#define MCHP_PFSOC_MMUART_REG_COUNT 13 | 28 | bool ext_zvbb; |
40 | 29 | bool ext_zvbc; | |
41 | typedef struct MchpPfSoCMMUartState { | 30 | bool ext_zvkb; |
42 | MemoryRegion iomem; | 31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
43 | @@ -XXX,XX +XXX,XX @@ typedef struct MchpPfSoCMMUartState { | ||
44 | |||
45 | SerialMM *serial; | ||
46 | |||
47 | - uint32_t reg[MCHP_PFSOC_MMUART_REG_SIZE / sizeof(uint32_t)]; | ||
48 | + uint32_t reg[MCHP_PFSOC_MMUART_REG_COUNT]; | ||
49 | } MchpPfSoCMMUartState; | ||
50 | |||
51 | /** | ||
52 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/hw/char/mchp_pfsoc_mmuart.c | 33 | --- a/target/riscv/cpu.c |
55 | +++ b/hw/char/mchp_pfsoc_mmuart.c | 34 | +++ b/target/riscv/cpu.c |
56 | @@ -XXX,XX +XXX,XX @@ static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size) | 35 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
57 | { | 36 | ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
58 | MchpPfSoCMMUartState *s = opaque; | 37 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
59 | 38 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | |
60 | - if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) { | 39 | + ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x), |
61 | + addr >>= 2; | 40 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
62 | + if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) { | 41 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), |
63 | qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%" HWADDR_PRIx "\n", | 42 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), |
64 | - __func__, addr); | 43 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
65 | + __func__, addr << 2); | 44 | MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), |
66 | return 0; | 45 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), |
46 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
47 | + MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false), | ||
48 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
49 | MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), | ||
50 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), | ||
51 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/riscv/tcg/tcg-cpu.c | ||
54 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
55 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
56 | |||
57 | /* The Zve64d extension depends on the Zve64f extension */ | ||
58 | if (cpu->cfg.ext_zve64d) { | ||
59 | + if (!riscv_has_ext(env, RVD)) { | ||
60 | + error_setg(errp, "Zve64d/V extensions require D extension"); | ||
61 | + return; | ||
62 | + } | ||
63 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
67 | } | 64 | } |
68 | 65 | ||
69 | - return s->reg[addr / sizeof(uint32_t)]; | 66 | - /* The Zve64f extension depends on the Zve32f extension */ |
70 | + return s->reg[addr]; | 67 | + /* The Zve64f extension depends on the Zve64x and Zve32f extensions */ |
71 | } | 68 | if (cpu->cfg.ext_zve64f) { |
72 | 69 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true); | |
73 | static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr, | 70 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); |
74 | @@ -XXX,XX +XXX,XX @@ static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr, | 71 | } |
75 | MchpPfSoCMMUartState *s = opaque; | 72 | |
76 | uint32_t val32 = (uint32_t)value; | 73 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { |
77 | 74 | - error_setg(errp, "Zve64d/V extensions require D extension"); | |
78 | - if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) { | 75 | - return; |
79 | + addr >>= 2; | 76 | + /* The Zve64x extension depends on the Zve32x extension */ |
80 | + if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) { | 77 | + if (cpu->cfg.ext_zve64x) { |
81 | qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%" HWADDR_PRIx | 78 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); |
82 | - " v=0x%x\n", __func__, addr, val32); | 79 | } |
83 | + " v=0x%x\n", __func__, addr << 2, val32); | 80 | |
81 | /* The Zve32f extension depends on the Zve32x extension */ | ||
82 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
84 | return; | 83 | return; |
85 | } | 84 | } |
86 | 85 | ||
87 | - s->reg[addr / sizeof(uint32_t)] = val32; | 86 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { |
88 | + s->reg[addr] = val32; | 87 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { |
89 | } | 88 | error_setg( |
90 | 89 | errp, | |
91 | static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { | 90 | - "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); |
91 | + "Zvbc and Zvknhb extensions require V or Zve64x extensions"); | ||
92 | return; | ||
93 | } | ||
94 | |||
92 | -- | 95 | -- |
93 | 2.31.1 | 96 | 2.45.1 |
94 | |||
95 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng.cn@gmail.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | At present the codes detect whether the DMA channel is claimed by: | 3 | In current implementation, the gdbstub allows reading vector registers |
4 | only if V extension is supported. However, all vector extensions and | ||
5 | vector crypto extensions have the vector registers and they all depend | ||
6 | on Zve32x. The gdbstub should check for Zve32x instead. | ||
4 | 7 | ||
5 | claimed = !!s->chan[ch].control & CONTROL_CLAIM; | 8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
6 | 9 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | |
7 | As ! has higher precedence over & (bitwise and), this is essentially | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
8 | 11 | Message-ID: <20240328022343.6871-4-jason.chien@sifive.com> | |
9 | claimed = (!!s->chan[ch].control) & CONTROL_CLAIM; | ||
10 | |||
11 | which is wrong, as any non-zero bit set in the control register will | ||
12 | produce a result of a claimed channel. | ||
13 | |||
14 | Fixes: de7c7988d25d ("hw/dma: sifive_pdma: reset Next* registers when Control.claim is set") | ||
15 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Message-id: 20210927072124.1564129-1-bmeng.cn@gmail.com | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 13 | --- |
20 | hw/dma/sifive_pdma.c | 2 +- | 14 | target/riscv/gdbstub.c | 2 +- |
21 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
22 | 16 | ||
23 | diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c | 17 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
24 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/hw/dma/sifive_pdma.c | 19 | --- a/target/riscv/gdbstub.c |
26 | +++ b/hw/dma/sifive_pdma.c | 20 | +++ b/target/riscv/gdbstub.c |
27 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, | 21 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) |
28 | offset &= 0xfff; | 22 | gdb_find_static_feature("riscv-32bit-fpu.xml"), |
29 | switch (offset) { | 23 | 0); |
30 | case DMA_CONTROL: | 24 | } |
31 | - claimed = !!s->chan[ch].control & CONTROL_CLAIM; | 25 | - if (env->misa_ext & RVV) { |
32 | + claimed = !!(s->chan[ch].control & CONTROL_CLAIM); | 26 | + if (cpu->cfg.ext_zve32x) { |
33 | 27 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, | |
34 | if (!claimed && (value & CONTROL_CLAIM)) { | 28 | riscv_gdb_set_vector, |
35 | /* reset Next* registers */ | 29 | ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs), |
36 | -- | 30 | -- |
37 | 2.31.1 | 31 | 2.45.1 |
38 | |||
39 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng.cn@gmail.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | The category of sifive_uart device is not set. Put it into the | 3 | In RVV and vcrypto instructions, the masked and tail elements are set to 1s |
4 | 'input' category. | 4 | using vext_set_elems_1s function if the vma/vta bit is set. It is the element |
5 | agnostic policy. | ||
5 | 6 | ||
6 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | 7 | However, this function can't deal the big endian situation. This patch fixes |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | the problem by adding handling of such case. |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | |
9 | Message-id: 20210926105003.2716-3-bmeng.cn@gmail.com | 10 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
11 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 16 | --- |
12 | hw/char/sifive_uart.c | 1 + | 17 | target/riscv/vector_internals.c | 22 ++++++++++++++++++++++ |
13 | 1 file changed, 1 insertion(+) | 18 | 1 file changed, 22 insertions(+) |
14 | 19 | ||
15 | diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c | 20 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c |
16 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/char/sifive_uart.c | 22 | --- a/target/riscv/vector_internals.c |
18 | +++ b/hw/char/sifive_uart.c | 23 | +++ b/target/riscv/vector_internals.c |
19 | @@ -XXX,XX +XXX,XX @@ static void sifive_uart_class_init(ObjectClass *oc, void *data) | 24 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, |
20 | rc->phases.enter = sifive_uart_reset_enter; | 25 | if (tot - cnt == 0) { |
21 | rc->phases.hold = sifive_uart_reset_hold; | 26 | return ; |
22 | device_class_set_props(dc, sifive_uart_properties); | 27 | } |
23 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | 28 | + |
29 | + if (HOST_BIG_ENDIAN) { | ||
30 | + /* | ||
31 | + * Deal the situation when the elements are insdie | ||
32 | + * only one uint64 block including setting the | ||
33 | + * masked-off element. | ||
34 | + */ | ||
35 | + if (((tot - 1) ^ cnt) < 8) { | ||
36 | + memset(base + H1(tot - 1), -1, tot - cnt); | ||
37 | + return; | ||
38 | + } | ||
39 | + /* | ||
40 | + * Otherwise, at least cross two uint64_t blocks. | ||
41 | + * Set first unaligned block. | ||
42 | + */ | ||
43 | + if (cnt % 8 != 0) { | ||
44 | + uint32_t j = ROUND_UP(cnt, 8); | ||
45 | + memset(base + H1(j - 1), -1, j - cnt); | ||
46 | + cnt = j; | ||
47 | + } | ||
48 | + /* Set other 64bit aligend blocks */ | ||
49 | + } | ||
50 | memset(base + cnt, -1, tot - cnt); | ||
24 | } | 51 | } |
25 | 52 | ||
26 | static const TypeInfo sifive_uart_info = { | ||
27 | -- | 53 | -- |
28 | 2.31.1 | 54 | 2.45.1 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Yangyu Chen <cyy@cyyself.name> |
---|---|---|---|
2 | 2 | ||
3 | The refactored gen_clzw() uses ret as its argument, instead of arg1. | 3 | This code has a typo that writes zvkb to zvkg, causing users can't |
4 | Fix it. | 4 | enable zvkb through the config. This patch gets this fixed. |
5 | 5 | ||
6 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 6 | Signed-off-by: Yangyu Chen <cyy@cyyself.name> |
7 | Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions") | ||
8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Reviewed-by: Weiwei Li <liwei1518@gmail.com> |
10 | Message-id: 20210911140016.834071-3-philipp.tomsich@vrull.eu | 12 | Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com> |
11 | Fixes: 60903915050 ("target/riscv: Add DisasExtend to gen_unary") | 13 | Cc: qemu-stable <qemu-stable@nongnu.org> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 15 | --- |
14 | target/riscv/insn_trans/trans_rvb.c.inc | 2 +- | 16 | target/riscv/cpu.c | 2 +- |
15 | 1 file changed, 1 insertion(+), 1 deletion(-) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
16 | 18 | ||
17 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | 19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
18 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 21 | --- a/target/riscv/cpu.c |
20 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 22 | +++ b/target/riscv/cpu.c |
21 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD(3) | 23 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
22 | 24 | /* Vector cryptography extensions */ | |
23 | static void gen_clzw(TCGv ret, TCGv arg1) | 25 | MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false), |
24 | { | 26 | MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false), |
25 | - tcg_gen_clzi_tl(ret, ret, 64); | 27 | - MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false), |
26 | + tcg_gen_clzi_tl(ret, arg1, 64); | 28 | + MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false), |
27 | tcg_gen_subi_tl(ret, ret, 32); | 29 | MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false), |
28 | } | 30 | MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false), |
29 | 31 | MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false), | |
30 | -- | 32 | -- |
31 | 2.31.1 | 33 | 2.45.1 |
32 | 34 | ||
33 | 35 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | With everything classified as Zb[abcs] and pre-0.93 draft-B | 3 | In this patch, we modify the decoder to be a freely composable data |
4 | instructions that are not part of Zb[abcs] removed, we can remove the | 4 | structure instead of a hardcoded one. It can be dynamically builded up |
5 | remaining support code for RVB. | 5 | according to the extensions. |
6 | This approach has several benefits: | ||
7 | 1. Provides support for heterogeneous cpu architectures. As we add decoder in | ||
8 | RISCVCPU, each cpu can have their own decoder, and the decoders can be | ||
9 | different due to cpu's features. | ||
10 | 2. Improve the decoding efficiency. We run the guard_func to see if the decoder | ||
11 | can be added to the dynamic_decoder when building up the decoder. Therefore, | ||
12 | there is no need to run the guard_func when decoding each instruction. It can | ||
13 | improve the decoding efficiency | ||
14 | 3. For vendor or dynamic cpus, it allows them to customize their own decoder | ||
15 | functions to improve decoding efficiency, especially when vendor-defined | ||
16 | instruction sets increase. Because of dynamic building up, it can skip the other | ||
17 | decoder guard functions when decoding. | ||
18 | 4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal | ||
19 | overhead for users that don't need this particular vendor decoder. | ||
6 | 20 | ||
7 | Note that RVB has been retired for good and misa.B will neither mean | 21 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
8 | 'some' or 'all of' Zb*: | 22 | Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu> |
9 | https://lists.riscv.org/g/tech-bitmanip/message/532 | 23 | Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
10 | |||
11 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 26 | Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com> |
15 | Message-id: 20210911140016.834071-16-philipp.tomsich@vrull.eu | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 28 | --- |
18 | target/riscv/cpu.h | 3 --- | 29 | target/riscv/cpu.h | 1 + |
19 | target/riscv/insn32.decode | 4 ---- | 30 | target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++ |
20 | target/riscv/cpu.c | 26 -------------------------- | 31 | target/riscv/cpu.c | 1 + |
21 | 3 files changed, 33 deletions(-) | 32 | target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++ |
33 | target/riscv/translate.c | 31 +++++++++++++++---------------- | ||
34 | 5 files changed, 47 insertions(+), 16 deletions(-) | ||
22 | 35 | ||
23 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 36 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
24 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/riscv/cpu.h | 38 | --- a/target/riscv/cpu.h |
26 | +++ b/target/riscv/cpu.h | 39 | +++ b/target/riscv/cpu.h |
27 | @@ -XXX,XX +XXX,XX @@ | 40 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
28 | #define RVS RV('S') | 41 | uint32_t pmu_avail_ctrs; |
29 | #define RVU RV('U') | 42 | /* Mapping of events to counters */ |
30 | #define RVH RV('H') | 43 | GHashTable *pmu_event_ctr_map; |
31 | -#define RVB RV('B') | 44 | + const GPtrArray *decoders; |
32 | 45 | }; | |
33 | /* S extension denotes that Supervisor mode exists, however it is possible | 46 | |
34 | to have a core that support S mode but does not have an MMU and there | 47 | /** |
35 | @@ -XXX,XX +XXX,XX @@ enum { | 48 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h |
36 | #define PRIV_VERSION_1_10_0 0x00011000 | ||
37 | #define PRIV_VERSION_1_11_0 0x00011100 | ||
38 | |||
39 | -#define BEXT_VERSION_0_93_0 0x00009300 | ||
40 | #define VEXT_VERSION_0_07_1 0x00000701 | ||
41 | |||
42 | enum { | ||
43 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | ||
44 | bool ext_f; | ||
45 | bool ext_d; | ||
46 | bool ext_c; | ||
47 | - bool ext_b; | ||
48 | bool ext_s; | ||
49 | bool ext_u; | ||
50 | bool ext_h; | ||
51 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
52 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/target/riscv/insn32.decode | 50 | --- a/target/riscv/tcg/tcg-cpu.h |
54 | +++ b/target/riscv/insn32.decode | 51 | +++ b/target/riscv/tcg/tcg-cpu.h |
55 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | 52 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); |
56 | # instruction, so we use different handler functions to differentiate. | 53 | void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp); |
57 | zext_h_64 0000100 00000 ..... 100 ..... 0111011 @r2 | 54 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu); |
58 | 55 | ||
59 | -# *** RV32B Standard Extension *** | 56 | +struct DisasContext; |
60 | - | 57 | +struct RISCVCPUConfig; |
61 | -# *** RV64B Standard Extension (in addition to RV32B) *** | 58 | +typedef struct RISCVDecoder { |
62 | - | 59 | + bool (*guard_func)(const struct RISCVCPUConfig *); |
63 | # *** RV32 Zbc Standard Extension *** | 60 | + bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); |
64 | clmul 0000101 .......... 001 ..... 0110011 @r | 61 | +} RISCVDecoder; |
65 | clmulh 0000101 .......... 011 ..... 0110011 @r | 62 | + |
63 | +typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
64 | + | ||
65 | +extern const size_t decoder_table_size; | ||
66 | + | ||
67 | +extern const RISCVDecoder decoder_table[]; | ||
68 | + | ||
69 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu); | ||
70 | + | ||
71 | #endif | ||
66 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 72 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
67 | index XXXXXXX..XXXXXXX 100644 | 73 | index XXXXXXX..XXXXXXX 100644 |
68 | --- a/target/riscv/cpu.c | 74 | --- a/target/riscv/cpu.c |
69 | +++ b/target/riscv/cpu.c | 75 | +++ b/target/riscv/cpu.c |
70 | @@ -XXX,XX +XXX,XX @@ static void set_priv_version(CPURISCVState *env, int priv_ver) | 76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) |
71 | env->priv_ver = priv_ver; | 77 | error_propagate(errp, local_err); |
78 | return; | ||
79 | } | ||
80 | + riscv_tcg_cpu_finalize_dynamic_decoder(cpu); | ||
81 | } else if (kvm_enabled()) { | ||
82 | riscv_kvm_cpu_finalize_features(cpu, &local_err); | ||
83 | if (local_err != NULL) { | ||
84 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/target/riscv/tcg/tcg-cpu.c | ||
87 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
88 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
89 | } | ||
72 | } | 90 | } |
73 | 91 | ||
74 | -static void set_bext_version(CPURISCVState *env, int bext_ver) | 92 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) |
75 | -{ | 93 | +{ |
76 | - env->bext_ver = bext_ver; | 94 | + GPtrArray *dynamic_decoders; |
77 | -} | 95 | + dynamic_decoders = g_ptr_array_sized_new(decoder_table_size); |
96 | + for (size_t i = 0; i < decoder_table_size; ++i) { | ||
97 | + if (decoder_table[i].guard_func && | ||
98 | + decoder_table[i].guard_func(&cpu->cfg)) { | ||
99 | + g_ptr_array_add(dynamic_decoders, | ||
100 | + (gpointer)decoder_table[i].riscv_cpu_decode_fn); | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + cpu->decoders = dynamic_decoders; | ||
105 | +} | ||
106 | + | ||
107 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu) | ||
108 | { | ||
109 | return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL; | ||
110 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
111 | index XXXXXXX..XXXXXXX 100644 | ||
112 | --- a/target/riscv/translate.c | ||
113 | +++ b/target/riscv/translate.c | ||
114 | @@ -XXX,XX +XXX,XX @@ | ||
115 | #include "exec/helper-info.c.inc" | ||
116 | #undef HELPER_H | ||
117 | |||
118 | +#include "tcg/tcg-cpu.h" | ||
119 | + | ||
120 | /* global register indices */ | ||
121 | static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart; | ||
122 | static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ | ||
123 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
124 | /* FRM is known to contain a valid value. */ | ||
125 | bool frm_valid; | ||
126 | bool insn_start_updated; | ||
127 | + const GPtrArray *decoders; | ||
128 | } DisasContext; | ||
129 | |||
130 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | ||
131 | @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) | ||
132 | return (first_word & 3) == 3 ? 4 : 2; | ||
133 | } | ||
134 | |||
135 | +const RISCVDecoder decoder_table[] = { | ||
136 | + { always_true_p, decode_insn32 }, | ||
137 | + { has_xthead_p, decode_xthead}, | ||
138 | + { has_XVentanaCondOps_p, decode_XVentanaCodeOps}, | ||
139 | +}; | ||
140 | + | ||
141 | +const size_t decoder_table_size = ARRAY_SIZE(decoder_table); | ||
142 | + | ||
143 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
144 | { | ||
145 | - /* | ||
146 | - * A table with predicate (i.e., guard) functions and decoder functions | ||
147 | - * that are tested in-order until a decoder matches onto the opcode. | ||
148 | - */ | ||
149 | - static const struct { | ||
150 | - bool (*guard_func)(const RISCVCPUConfig *); | ||
151 | - bool (*decode_func)(DisasContext *, uint32_t); | ||
152 | - } decoders[] = { | ||
153 | - { always_true_p, decode_insn32 }, | ||
154 | - { has_xthead_p, decode_xthead }, | ||
155 | - { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, | ||
156 | - }; | ||
78 | - | 157 | - |
79 | static void set_vext_version(CPURISCVState *env, int vext_ver) | 158 | ctx->virt_inst_excp = false; |
80 | { | 159 | ctx->cur_insn_len = insn_len(opcode); |
81 | env->vext_ver = vext_ver; | 160 | /* Check for compressed insn */ |
82 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 161 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) |
83 | if (cpu->cfg.ext_h) { | 162 | ctx->base.pc_next + 2)); |
84 | target_misa |= RVH; | 163 | ctx->opcode = opcode32; |
164 | |||
165 | - for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) { | ||
166 | - if (decoders[i].guard_func(ctx->cfg_ptr) && | ||
167 | - decoders[i].decode_func(ctx, opcode32)) { | ||
168 | + for (guint i = 0; i < ctx->decoders->len; ++i) { | ||
169 | + riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i); | ||
170 | + if (func(ctx, opcode32)) { | ||
171 | return; | ||
172 | } | ||
85 | } | 173 | } |
86 | - if (cpu->cfg.ext_b) { | 174 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) |
87 | - int bext_version = BEXT_VERSION_0_93_0; | 175 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); |
88 | - target_misa |= RVB; | 176 | ctx->zero = tcg_constant_tl(0); |
89 | - | 177 | ctx->virt_inst_excp = false; |
90 | - if (cpu->cfg.bext_spec) { | 178 | + ctx->decoders = cpu->decoders; |
91 | - if (!g_strcmp0(cpu->cfg.bext_spec, "v0.93")) { | 179 | } |
92 | - bext_version = BEXT_VERSION_0_93_0; | 180 | |
93 | - } else { | 181 | static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) |
94 | - error_setg(errp, | ||
95 | - "Unsupported bitmanip spec version '%s'", | ||
96 | - cpu->cfg.bext_spec); | ||
97 | - return; | ||
98 | - } | ||
99 | - } else { | ||
100 | - qemu_log("bitmanip version is not specified, " | ||
101 | - "use the default value v0.93\n"); | ||
102 | - } | ||
103 | - set_bext_version(env, bext_version); | ||
104 | - } | ||
105 | if (cpu->cfg.ext_v) { | ||
106 | int vext_version = VEXT_VERSION_0_07_1; | ||
107 | target_misa |= RVV; | ||
108 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | ||
109 | DEFINE_PROP_BOOL("s", RISCVCPU, cfg.ext_s, true), | ||
110 | DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), | ||
111 | /* This is experimental so mark with 'x-' */ | ||
112 | - DEFINE_PROP_BOOL("x-b", RISCVCPU, cfg.ext_b, false), | ||
113 | DEFINE_PROP_BOOL("x-zba", RISCVCPU, cfg.ext_zba, false), | ||
114 | DEFINE_PROP_BOOL("x-zbb", RISCVCPU, cfg.ext_zbb, false), | ||
115 | DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false), | ||
116 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | ||
117 | DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), | ||
118 | DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), | ||
119 | DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), | ||
120 | - DEFINE_PROP_STRING("bext_spec", RISCVCPU, cfg.bext_spec), | ||
121 | DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), | ||
122 | DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), | ||
123 | DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), | ||
124 | -- | 182 | -- |
125 | 2.31.1 | 183 | 2.45.1 |
126 | |||
127 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Christoph Müllner <christoph.muellner@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | The bitmanipulation ISA extensions will be ratified as individual | 3 | The th.sxstatus CSR can be used to identify available custom extension |
4 | small extension packages instead of a large B-extension. The first | 4 | on T-Head CPUs. The CSR is documented here: |
5 | new instructions through the door (these have completed public review) | 5 | https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc |
6 | are Zb[abcs]. | ||
7 | 6 | ||
8 | This adds new 'x-zba', 'x-zbb', 'x-zbc' and 'x-zbs' properties for | 7 | An important property of this patch is, that the th.sxstatus MAEE field |
9 | these in target/riscv/cpu.[ch]. | 8 | is not set (indicating that XTheadMae is not available). |
9 | XTheadMae is a memory attribute extension (similar to Svpbmt) which is | ||
10 | implemented in many T-Head CPUs (C906, C910, etc.) and utilizes bits | ||
11 | in PTEs that are marked as reserved. QEMU maintainers prefer to not | ||
12 | implement XTheadMae, so we need give kernels a mechanism to identify | ||
13 | if XTheadMae is available in a system or not. And this patch introduces | ||
14 | this mechanism in QEMU in a way that's compatible with real HW | ||
15 | (i.e., probing the th.sxstatus.MAEE bit). | ||
10 | 16 | ||
11 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 17 | Further context can be found on the list: |
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 18 | https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html |
19 | |||
20 | Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 22 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> |
15 | Message-id: 20210911140016.834071-5-philipp.tomsich@vrull.eu | 23 | Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu> |
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 25 | --- |
18 | target/riscv/cpu.h | 4 ++++ | 26 | MAINTAINERS | 1 + |
19 | target/riscv/cpu.c | 4 ++++ | 27 | target/riscv/cpu.h | 3 ++ |
20 | 2 files changed, 8 insertions(+) | 28 | target/riscv/cpu.c | 1 + |
29 | target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++ | ||
30 | target/riscv/meson.build | 1 + | ||
31 | 5 files changed, 85 insertions(+) | ||
32 | create mode 100644 target/riscv/th_csr.c | ||
21 | 33 | ||
34 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/MAINTAINERS | ||
37 | +++ b/MAINTAINERS | ||
38 | @@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org | ||
39 | S: Supported | ||
40 | F: target/riscv/insn_trans/trans_xthead.c.inc | ||
41 | F: target/riscv/xthead*.decode | ||
42 | +F: target/riscv/th_* | ||
43 | F: disas/riscv-xthead* | ||
44 | |||
45 | RISC-V XVentanaCondOps extension | ||
22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 46 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
23 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/cpu.h | 48 | --- a/target/riscv/cpu.h |
25 | +++ b/target/riscv/cpu.h | 49 | +++ b/target/riscv/cpu.h |
26 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | 50 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value, |
27 | bool ext_u; | 51 | uint8_t satp_mode_max_from_map(uint32_t map); |
28 | bool ext_h; | 52 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
29 | bool ext_v; | 53 | |
30 | + bool ext_zba; | 54 | +/* Implemented in th_csr.c */ |
31 | + bool ext_zbb; | 55 | +void th_register_custom_csrs(RISCVCPU *cpu); |
32 | + bool ext_zbc; | 56 | + |
33 | + bool ext_zbs; | 57 | #endif /* RISCV_CPU_H */ |
34 | bool ext_counters; | ||
35 | bool ext_ifencei; | ||
36 | bool ext_icsr; | ||
37 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
38 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/riscv/cpu.c | 60 | --- a/target/riscv/cpu.c |
40 | +++ b/target/riscv/cpu.c | 61 | +++ b/target/riscv/cpu.c |
41 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 62 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) |
42 | DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), | 63 | cpu->cfg.mvendorid = THEAD_VENDOR_ID; |
43 | /* This is experimental so mark with 'x-' */ | 64 | #ifndef CONFIG_USER_ONLY |
44 | DEFINE_PROP_BOOL("x-b", RISCVCPU, cfg.ext_b, false), | 65 | set_satp_mode_max_supported(cpu, VM_1_10_SV39); |
45 | + DEFINE_PROP_BOOL("x-zba", RISCVCPU, cfg.ext_zba, false), | 66 | + th_register_custom_csrs(cpu); |
46 | + DEFINE_PROP_BOOL("x-zbb", RISCVCPU, cfg.ext_zbb, false), | 67 | #endif |
47 | + DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false), | 68 | |
48 | + DEFINE_PROP_BOOL("x-zbs", RISCVCPU, cfg.ext_zbs, false), | 69 | /* inherited from parent obj via riscv_cpu_init() */ |
49 | DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false), | 70 | diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c |
50 | DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false), | 71 | new file mode 100644 |
51 | DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true), | 72 | index XXXXXXX..XXXXXXX |
73 | --- /dev/null | ||
74 | +++ b/target/riscv/th_csr.c | ||
75 | @@ -XXX,XX +XXX,XX @@ | ||
76 | +/* | ||
77 | + * T-Head-specific CSRs. | ||
78 | + * | ||
79 | + * Copyright (c) 2024 VRULL GmbH | ||
80 | + * | ||
81 | + * This program is free software; you can redistribute it and/or modify it | ||
82 | + * under the terms and conditions of the GNU General Public License, | ||
83 | + * version 2 or later, as published by the Free Software Foundation. | ||
84 | + * | ||
85 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
86 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
87 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
88 | + * more details. | ||
89 | + * | ||
90 | + * You should have received a copy of the GNU General Public License along with | ||
91 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
92 | + */ | ||
93 | + | ||
94 | +#include "qemu/osdep.h" | ||
95 | +#include "cpu.h" | ||
96 | +#include "cpu_vendorid.h" | ||
97 | + | ||
98 | +#define CSR_TH_SXSTATUS 0x5c0 | ||
99 | + | ||
100 | +/* TH_SXSTATUS bits */ | ||
101 | +#define TH_SXSTATUS_UCME BIT(16) | ||
102 | +#define TH_SXSTATUS_MAEE BIT(21) | ||
103 | +#define TH_SXSTATUS_THEADISAEE BIT(22) | ||
104 | + | ||
105 | +typedef struct { | ||
106 | + int csrno; | ||
107 | + int (*insertion_test)(RISCVCPU *cpu); | ||
108 | + riscv_csr_operations csr_ops; | ||
109 | +} riscv_csr; | ||
110 | + | ||
111 | +static RISCVException smode(CPURISCVState *env, int csrno) | ||
112 | +{ | ||
113 | + if (riscv_has_ext(env, RVS)) { | ||
114 | + return RISCV_EXCP_NONE; | ||
115 | + } | ||
116 | + | ||
117 | + return RISCV_EXCP_ILLEGAL_INST; | ||
118 | +} | ||
119 | + | ||
120 | +static int test_thead_mvendorid(RISCVCPU *cpu) | ||
121 | +{ | ||
122 | + if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) { | ||
123 | + return -1; | ||
124 | + } | ||
125 | + | ||
126 | + return 0; | ||
127 | +} | ||
128 | + | ||
129 | +static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno, | ||
130 | + target_ulong *val) | ||
131 | +{ | ||
132 | + /* We don't set MAEE here, because QEMU does not implement MAEE. */ | ||
133 | + *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE; | ||
134 | + return RISCV_EXCP_NONE; | ||
135 | +} | ||
136 | + | ||
137 | +static riscv_csr th_csr_list[] = { | ||
138 | + { | ||
139 | + .csrno = CSR_TH_SXSTATUS, | ||
140 | + .insertion_test = test_thead_mvendorid, | ||
141 | + .csr_ops = { "th.sxstatus", smode, read_th_sxstatus } | ||
142 | + } | ||
143 | +}; | ||
144 | + | ||
145 | +void th_register_custom_csrs(RISCVCPU *cpu) | ||
146 | +{ | ||
147 | + for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) { | ||
148 | + int csrno = th_csr_list[i].csrno; | ||
149 | + riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops; | ||
150 | + if (!th_csr_list[i].insertion_test(cpu)) { | ||
151 | + riscv_set_csr_ops(csrno, csr_ops); | ||
152 | + } | ||
153 | + } | ||
154 | +} | ||
155 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/target/riscv/meson.build | ||
158 | +++ b/target/riscv/meson.build | ||
159 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( | ||
160 | 'monitor.c', | ||
161 | 'machine.c', | ||
162 | 'pmu.c', | ||
163 | + 'th_csr.c', | ||
164 | 'time_helper.c', | ||
165 | 'riscv-qmp-cmds.c', | ||
166 | )) | ||
52 | -- | 167 | -- |
53 | 2.31.1 | 168 | 2.45.1 |
54 | 169 | ||
55 | 170 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng.cn@gmail.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The category of shakti_uart device is not set. Put it into the | 3 | According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w |
4 | 'input' category. | 4 | instructions will be affected by Zvfhmin extension. |
5 | And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the | ||
6 | conversions of | ||
5 | 7 | ||
6 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | 8 | * From 1*SEW(16/32) to 2*SEW(32/64) |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | * From 2*SEW(32/64) to 1*SEW(16/32) |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | |
9 | Message-id: 20210926105003.2716-2-bmeng.cn@gmail.com | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240322092600.1198921-2-max.chou@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 16 | --- |
12 | hw/char/shakti_uart.c | 1 + | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++-- |
13 | 1 file changed, 1 insertion(+) | 18 | 1 file changed, 18 insertions(+), 2 deletions(-) |
14 | 19 | ||
15 | diff --git a/hw/char/shakti_uart.c b/hw/char/shakti_uart.c | 20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
16 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/char/shakti_uart.c | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
18 | +++ b/hw/char/shakti_uart.c | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
19 | @@ -XXX,XX +XXX,XX @@ static void shakti_uart_class_init(ObjectClass *klass, void *data) | 24 | @@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s) |
20 | dc->reset = shakti_uart_reset; | 25 | } |
21 | dc->realize = shakti_uart_realize; | ||
22 | device_class_set_props(dc, shakti_uart_properties); | ||
23 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | ||
24 | } | 26 | } |
25 | 27 | ||
26 | static const TypeInfo shakti_uart_info = { | 28 | +static bool require_rvfmin(DisasContext *s) |
29 | +{ | ||
30 | + if (s->mstatus_fs == EXT_STATUS_DISABLED) { | ||
31 | + return false; | ||
32 | + } | ||
33 | + | ||
34 | + switch (s->sew) { | ||
35 | + case MO_16: | ||
36 | + return s->cfg_ptr->ext_zvfhmin; | ||
37 | + case MO_32: | ||
38 | + return s->cfg_ptr->ext_zve32f; | ||
39 | + default: | ||
40 | + return false; | ||
41 | + } | ||
42 | +} | ||
43 | + | ||
44 | static bool require_scale_rvf(DisasContext *s) | ||
45 | { | ||
46 | if (s->mstatus_fs == EXT_STATUS_DISABLED) { | ||
47 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s) | ||
48 | } | ||
49 | |||
50 | switch (s->sew) { | ||
51 | - case MO_8: | ||
52 | - return s->cfg_ptr->ext_zvfhmin; | ||
53 | case MO_16: | ||
54 | return s->cfg_ptr->ext_zve32f; | ||
55 | case MO_32: | ||
56 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) | ||
57 | static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
58 | { | ||
59 | return opfv_widen_check(s, a) && | ||
60 | + require_rvfmin(s) && | ||
61 | require_scale_rvfmin(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) | ||
65 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
66 | { | ||
67 | return opfv_narrow_check(s, a) && | ||
68 | + require_rvfmin(s) && | ||
69 | require_scale_rvfmin(s) && | ||
70 | (s->sew != MO_8); | ||
71 | } | ||
27 | -- | 72 | -- |
28 | 2.31.1 | 73 | 2.45.1 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | This reassigns the instructions that are part of Zbb into it, with the | 3 | The require_scale_rvf function only checks the double width operator for |
4 | notable exceptions of the instructions (rev8, zext.w and orc.b) that | 4 | the vector floating point widen instructions, so most of the widen |
5 | changed due to gorci, grevi and pack not being part of Zb[abcs]. | 5 | checking functions need to add require_rvf for single width operator. |
6 | 6 | ||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 7 | The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | integer to double width float, so the opfxv_widen_check function doesn’t |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | need require_rvf for the single width operator(integer). |
10 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | 10 | |
11 | Message-id: 20210911140016.834071-11-philipp.tomsich@vrull.eu | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240322092600.1198921-3-max.chou@sifive.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 16 | --- |
14 | target/riscv/insn32.decode | 40 ++++++++++--------- | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++ |
15 | target/riscv/insn_trans/trans_rvb.c.inc | 51 ++++++++++++++----------- | 18 | 1 file changed, 5 insertions(+) |
16 | 2 files changed, 50 insertions(+), 41 deletions(-) | ||
17 | 19 | ||
18 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
19 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/insn32.decode | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
21 | +++ b/target/riscv/insn32.decode | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
22 | @@ -XXX,XX +XXX,XX @@ sh2add_uw 0010000 .......... 100 ..... 0111011 @r | 24 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check) |
23 | sh3add_uw 0010000 .......... 110 ..... 0111011 @r | 25 | static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
24 | slli_uw 00001 ............ 001 ..... 0011011 @sh | ||
25 | |||
26 | -# *** RV32B Standard Extension *** | ||
27 | +# *** RV32 Zbb Standard Extension *** | ||
28 | +andn 0100000 .......... 111 ..... 0110011 @r | ||
29 | clz 011000 000000 ..... 001 ..... 0010011 @r2 | ||
30 | -ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
31 | cpop 011000 000010 ..... 001 ..... 0010011 @r2 | ||
32 | +ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
33 | +max 0000101 .......... 110 ..... 0110011 @r | ||
34 | +maxu 0000101 .......... 111 ..... 0110011 @r | ||
35 | +min 0000101 .......... 100 ..... 0110011 @r | ||
36 | +minu 0000101 .......... 101 ..... 0110011 @r | ||
37 | +orn 0100000 .......... 110 ..... 0110011 @r | ||
38 | +rol 0110000 .......... 001 ..... 0110011 @r | ||
39 | +ror 0110000 .......... 101 ..... 0110011 @r | ||
40 | +rori 01100 ............ 101 ..... 0010011 @sh | ||
41 | sext_b 011000 000100 ..... 001 ..... 0010011 @r2 | ||
42 | sext_h 011000 000101 ..... 001 ..... 0010011 @r2 | ||
43 | - | ||
44 | -andn 0100000 .......... 111 ..... 0110011 @r | ||
45 | -orn 0100000 .......... 110 ..... 0110011 @r | ||
46 | xnor 0100000 .......... 100 ..... 0110011 @r | ||
47 | + | ||
48 | +# *** RV64 Zbb Standard Extension (in addition to RV32 Zbb) *** | ||
49 | +clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
50 | +ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
51 | +cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
52 | +rolw 0110000 .......... 001 ..... 0111011 @r | ||
53 | +roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
54 | +rorw 0110000 .......... 101 ..... 0111011 @r | ||
55 | + | ||
56 | +# *** RV32B Standard Extension *** | ||
57 | pack 0000100 .......... 100 ..... 0110011 @r | ||
58 | packu 0100100 .......... 100 ..... 0110011 @r | ||
59 | packh 0000100 .......... 111 ..... 0110011 @r | ||
60 | -min 0000101 .......... 100 ..... 0110011 @r | ||
61 | -minu 0000101 .......... 101 ..... 0110011 @r | ||
62 | -max 0000101 .......... 110 ..... 0110011 @r | ||
63 | -maxu 0000101 .......... 111 ..... 0110011 @r | ||
64 | -ror 0110000 .......... 101 ..... 0110011 @r | ||
65 | -rol 0110000 .......... 001 ..... 0110011 @r | ||
66 | grev 0110100 .......... 101 ..... 0110011 @r | ||
67 | gorc 0010100 .......... 101 ..... 0110011 @r | ||
68 | |||
69 | -rori 01100. ........... 101 ..... 0010011 @sh | ||
70 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
71 | gorci 00101. ........... 101 ..... 0010011 @sh | ||
72 | |||
73 | # *** RV64B Standard Extension (in addition to RV32B) *** | ||
74 | -clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
75 | -ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
76 | -cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
77 | - | ||
78 | packw 0000100 .......... 100 ..... 0111011 @r | ||
79 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
80 | -rorw 0110000 .......... 101 ..... 0111011 @r | ||
81 | -rolw 0110000 .......... 001 ..... 0111011 @r | ||
82 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
83 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
84 | |||
85 | -roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
86 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
87 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
88 | |||
89 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
92 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | /* | ||
95 | - * RISC-V translation routines for the Zb[acs] Standard Extension. | ||
96 | + * RISC-V translation routines for the Zb[abcs] Standard Extension. | ||
97 | * | ||
98 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
99 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
100 | @@ -XXX,XX +XXX,XX @@ | ||
101 | } \ | ||
102 | } while (0) | ||
103 | |||
104 | +#define REQUIRE_ZBB(ctx) do { \ | ||
105 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zbb) { \ | ||
106 | + return false; \ | ||
107 | + } \ | ||
108 | +} while (0) | ||
109 | + | ||
110 | #define REQUIRE_ZBC(ctx) do { \ | ||
111 | if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ | ||
112 | return false; \ | ||
113 | @@ -XXX,XX +XXX,XX @@ static void gen_clz(TCGv ret, TCGv arg1) | ||
114 | { | 26 | { |
115 | tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS); | 27 | return require_rvv(s) && |
116 | } | 28 | + require_rvf(s) && |
117 | + | 29 | require_scale_rvf(s) && |
118 | static bool trans_clz(DisasContext *ctx, arg_clz *a) | 30 | (s->sew != MO_8) && |
31 | vext_check_isa_ill(s) && | ||
32 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check) | ||
33 | static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
119 | { | 34 | { |
120 | - REQUIRE_EXT(ctx, RVB); | 35 | return require_rvv(s) && |
121 | + REQUIRE_ZBB(ctx); | 36 | + require_rvf(s) && |
122 | return gen_unary(ctx, a, EXT_ZERO, gen_clz); | 37 | require_scale_rvf(s) && |
123 | } | 38 | (s->sew != MO_8) && |
124 | 39 | vext_check_isa_ill(s) && | |
125 | @@ -XXX,XX +XXX,XX @@ static void gen_ctz(TCGv ret, TCGv arg1) | 40 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf) |
126 | 41 | static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | |
127 | static bool trans_ctz(DisasContext *ctx, arg_ctz *a) | ||
128 | { | 42 | { |
129 | - REQUIRE_EXT(ctx, RVB); | 43 | return require_rvv(s) && |
130 | + REQUIRE_ZBB(ctx); | 44 | + require_rvf(s) && |
131 | return gen_unary(ctx, a, EXT_ZERO, gen_ctz); | 45 | require_scale_rvf(s) && |
132 | } | 46 | (s->sew != MO_8) && |
133 | 47 | vext_check_isa_ill(s) && | |
134 | static bool trans_cpop(DisasContext *ctx, arg_cpop *a) | 48 | @@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv) |
49 | static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
135 | { | 50 | { |
136 | - REQUIRE_EXT(ctx, RVB); | 51 | return require_rvv(s) && |
137 | + REQUIRE_ZBB(ctx); | 52 | + require_rvf(s) && |
138 | return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl); | 53 | require_scale_rvf(s) && |
139 | } | 54 | (s->sew != MO_8) && |
140 | 55 | vext_check_isa_ill(s) && | |
141 | static bool trans_andn(DisasContext *ctx, arg_andn *a) | 56 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) |
57 | static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
142 | { | 58 | { |
143 | - REQUIRE_EXT(ctx, RVB); | 59 | return reduction_widen_check(s, a) && |
144 | + REQUIRE_ZBB(ctx); | 60 | + require_rvf(s) && |
145 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_andc_tl); | 61 | require_scale_rvf(s) && |
146 | } | 62 | (s->sew != MO_8); |
147 | |||
148 | static bool trans_orn(DisasContext *ctx, arg_orn *a) | ||
149 | { | ||
150 | - REQUIRE_EXT(ctx, RVB); | ||
151 | + REQUIRE_ZBB(ctx); | ||
152 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_orc_tl); | ||
153 | } | ||
154 | |||
155 | static bool trans_xnor(DisasContext *ctx, arg_xnor *a) | ||
156 | { | ||
157 | - REQUIRE_EXT(ctx, RVB); | ||
158 | + REQUIRE_ZBB(ctx); | ||
159 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_eqv_tl); | ||
160 | } | ||
161 | |||
162 | @@ -XXX,XX +XXX,XX @@ static bool trans_packh(DisasContext *ctx, arg_packh *a) | ||
163 | |||
164 | static bool trans_min(DisasContext *ctx, arg_min *a) | ||
165 | { | ||
166 | - REQUIRE_EXT(ctx, RVB); | ||
167 | + REQUIRE_ZBB(ctx); | ||
168 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_smin_tl); | ||
169 | } | ||
170 | |||
171 | static bool trans_max(DisasContext *ctx, arg_max *a) | ||
172 | { | ||
173 | - REQUIRE_EXT(ctx, RVB); | ||
174 | + REQUIRE_ZBB(ctx); | ||
175 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_smax_tl); | ||
176 | } | ||
177 | |||
178 | static bool trans_minu(DisasContext *ctx, arg_minu *a) | ||
179 | { | ||
180 | - REQUIRE_EXT(ctx, RVB); | ||
181 | + REQUIRE_ZBB(ctx); | ||
182 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_umin_tl); | ||
183 | } | ||
184 | |||
185 | static bool trans_maxu(DisasContext *ctx, arg_maxu *a) | ||
186 | { | ||
187 | - REQUIRE_EXT(ctx, RVB); | ||
188 | + REQUIRE_ZBB(ctx); | ||
189 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_umax_tl); | ||
190 | } | ||
191 | |||
192 | static bool trans_sext_b(DisasContext *ctx, arg_sext_b *a) | ||
193 | { | ||
194 | - REQUIRE_EXT(ctx, RVB); | ||
195 | + REQUIRE_ZBB(ctx); | ||
196 | return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext8s_tl); | ||
197 | } | ||
198 | |||
199 | static bool trans_sext_h(DisasContext *ctx, arg_sext_h *a) | ||
200 | { | ||
201 | - REQUIRE_EXT(ctx, RVB); | ||
202 | + REQUIRE_ZBB(ctx); | ||
203 | return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16s_tl); | ||
204 | } | ||
205 | |||
206 | @@ -XXX,XX +XXX,XX @@ static bool trans_bexti(DisasContext *ctx, arg_bexti *a) | ||
207 | |||
208 | static bool trans_ror(DisasContext *ctx, arg_ror *a) | ||
209 | { | ||
210 | - REQUIRE_EXT(ctx, RVB); | ||
211 | + REQUIRE_ZBB(ctx); | ||
212 | return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotr_tl); | ||
213 | } | ||
214 | |||
215 | static bool trans_rori(DisasContext *ctx, arg_rori *a) | ||
216 | { | ||
217 | - REQUIRE_EXT(ctx, RVB); | ||
218 | + REQUIRE_ZBB(ctx); | ||
219 | return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_rotri_tl); | ||
220 | } | ||
221 | |||
222 | static bool trans_rol(DisasContext *ctx, arg_rol *a) | ||
223 | { | ||
224 | - REQUIRE_EXT(ctx, RVB); | ||
225 | + REQUIRE_ZBB(ctx); | ||
226 | return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl); | ||
227 | } | ||
228 | |||
229 | @@ -XXX,XX +XXX,XX @@ static void gen_clzw(TCGv ret, TCGv arg1) | ||
230 | static bool trans_clzw(DisasContext *ctx, arg_clzw *a) | ||
231 | { | ||
232 | REQUIRE_64BIT(ctx); | ||
233 | - REQUIRE_EXT(ctx, RVB); | ||
234 | + REQUIRE_ZBB(ctx); | ||
235 | return gen_unary(ctx, a, EXT_NONE, gen_clzw); | ||
236 | } | ||
237 | |||
238 | @@ -XXX,XX +XXX,XX @@ static void gen_ctzw(TCGv ret, TCGv arg1) | ||
239 | static bool trans_ctzw(DisasContext *ctx, arg_ctzw *a) | ||
240 | { | ||
241 | REQUIRE_64BIT(ctx); | ||
242 | - REQUIRE_EXT(ctx, RVB); | ||
243 | + REQUIRE_ZBB(ctx); | ||
244 | return gen_unary(ctx, a, EXT_NONE, gen_ctzw); | ||
245 | } | ||
246 | |||
247 | static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a) | ||
248 | { | ||
249 | REQUIRE_64BIT(ctx); | ||
250 | - REQUIRE_EXT(ctx, RVB); | ||
251 | + REQUIRE_ZBB(ctx); | ||
252 | ctx->w = true; | ||
253 | return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl); | ||
254 | } | ||
255 | @@ -XXX,XX +XXX,XX @@ static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | ||
256 | static bool trans_rorw(DisasContext *ctx, arg_rorw *a) | ||
257 | { | ||
258 | REQUIRE_64BIT(ctx); | ||
259 | - REQUIRE_EXT(ctx, RVB); | ||
260 | + REQUIRE_ZBB(ctx); | ||
261 | ctx->w = true; | ||
262 | return gen_shift(ctx, a, EXT_NONE, gen_rorw); | ||
263 | } | ||
264 | @@ -XXX,XX +XXX,XX @@ static bool trans_rorw(DisasContext *ctx, arg_rorw *a) | ||
265 | static bool trans_roriw(DisasContext *ctx, arg_roriw *a) | ||
266 | { | ||
267 | REQUIRE_64BIT(ctx); | ||
268 | - REQUIRE_EXT(ctx, RVB); | ||
269 | + REQUIRE_ZBB(ctx); | ||
270 | ctx->w = true; | ||
271 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_rorw); | ||
272 | } | ||
273 | @@ -XXX,XX +XXX,XX @@ static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2) | ||
274 | static bool trans_rolw(DisasContext *ctx, arg_rolw *a) | ||
275 | { | ||
276 | REQUIRE_64BIT(ctx); | ||
277 | - REQUIRE_EXT(ctx, RVB); | ||
278 | + REQUIRE_ZBB(ctx); | ||
279 | ctx->w = true; | ||
280 | return gen_shift(ctx, a, EXT_NONE, gen_rolw); | ||
281 | } | 63 | } |
282 | -- | 64 | -- |
283 | 2.31.1 | 65 | 2.45.1 |
284 | 66 | ||
285 | 67 | diff view generated by jsdifflib |
1 | From: Bin Meng <bmeng.cn@gmail.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The category of ibex_uart device is not set. Put it into the | 3 | The opfv_narrow_check needs to check the single width float operator by |
4 | 'input' category. | 4 | require_rvf. |
5 | 5 | ||
6 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | 6 | Signed-off-by: Max Chou <max.chou@sifive.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Cc: qemu-stable <qemu-stable@nongnu.org> |
9 | Message-id: 20210926105003.2716-1-bmeng.cn@gmail.com | 9 | Message-ID: <20240322092600.1198921-4-max.chou@sifive.com> |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | hw/char/ibex_uart.c | 1 + | 12 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + |
13 | 1 file changed, 1 insertion(+) | 13 | 1 file changed, 1 insertion(+) |
14 | 14 | ||
15 | diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c | 15 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/char/ibex_uart.c | 17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
18 | +++ b/hw/char/ibex_uart.c | 18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
19 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_class_init(ObjectClass *klass, void *data) | 19 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
20 | dc->realize = ibex_uart_realize; | 20 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
21 | dc->vmsd = &vmstate_ibex_uart; | 21 | { |
22 | device_class_set_props(dc, ibex_uart_properties); | 22 | return opfv_narrow_check(s, a) && |
23 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | 23 | + require_rvf(s) && |
24 | require_scale_rvf(s) && | ||
25 | (s->sew != MO_8); | ||
24 | } | 26 | } |
25 | |||
26 | static const TypeInfo ibex_uart_info = { | ||
27 | -- | 27 | -- |
28 | 2.31.1 | 28 | 2.45.1 |
29 | |||
30 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The 1.0.0 version of Zbb does not contain gorc/gorci. Instead, a | 3 | If the checking functions check both the single and double width |
4 | orc.b instruction (equivalent to the orc.b pseudo-instruction built on | 4 | operators at the same time, then the single width operator checking |
5 | gorci from pre-0.93 draft-B) is available, mainly targeting | 5 | functions (require_rvf[min]) will check whether the SEW is 8. |
6 | string-processing workloads. | ||
7 | 6 | ||
8 | This commit adds the new orc.b instruction and removed gorc/gorci. | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> |
9 | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
10 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Message-ID: <20240322092600.1198921-5-max.chou@sifive.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-id: 20210911140016.834071-12-philipp.tomsich@vrull.eu | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 12 | --- |
16 | target/riscv/helper.h | 2 -- | 13 | target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------ |
17 | target/riscv/insn32.decode | 6 +--- | 14 | 1 file changed, 4 insertions(+), 12 deletions(-) |
18 | target/riscv/bitmanip_helper.c | 26 ----------------- | ||
19 | target/riscv/insn_trans/trans_rvb.c.inc | 39 +++++++++++-------------- | ||
20 | 4 files changed, 18 insertions(+), 55 deletions(-) | ||
21 | 15 | ||
22 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
23 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/helper.h | 18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
25 | +++ b/target/riscv/helper.h | 19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
26 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) | 20 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
27 | /* Bitmanip */ | 21 | return require_rvv(s) && |
28 | DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 22 | require_rvf(s) && |
29 | DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 23 | require_scale_rvf(s) && |
30 | -DEF_HELPER_FLAGS_2(gorc, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 24 | - (s->sew != MO_8) && |
31 | -DEF_HELPER_FLAGS_2(gorcw, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 25 | vext_check_isa_ill(s) && |
32 | DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 26 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); |
33 | DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
34 | |||
35 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/riscv/insn32.decode | ||
38 | +++ b/target/riscv/insn32.decode | ||
39 | @@ -XXX,XX +XXX,XX @@ max 0000101 .......... 110 ..... 0110011 @r | ||
40 | maxu 0000101 .......... 111 ..... 0110011 @r | ||
41 | min 0000101 .......... 100 ..... 0110011 @r | ||
42 | minu 0000101 .......... 101 ..... 0110011 @r | ||
43 | +orc_b 001010 000111 ..... 101 ..... 0010011 @r2 | ||
44 | orn 0100000 .......... 110 ..... 0110011 @r | ||
45 | rol 0110000 .......... 001 ..... 0110011 @r | ||
46 | ror 0110000 .......... 101 ..... 0110011 @r | ||
47 | @@ -XXX,XX +XXX,XX @@ pack 0000100 .......... 100 ..... 0110011 @r | ||
48 | packu 0100100 .......... 100 ..... 0110011 @r | ||
49 | packh 0000100 .......... 111 ..... 0110011 @r | ||
50 | grev 0110100 .......... 101 ..... 0110011 @r | ||
51 | -gorc 0010100 .......... 101 ..... 0110011 @r | ||
52 | - | ||
53 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
54 | -gorci 00101. ........... 101 ..... 0010011 @sh | ||
55 | |||
56 | # *** RV64B Standard Extension (in addition to RV32B) *** | ||
57 | packw 0000100 .......... 100 ..... 0111011 @r | ||
58 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
59 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
60 | -gorcw 0010100 .......... 101 ..... 0111011 @r | ||
61 | |||
62 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
63 | -gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
64 | |||
65 | # *** RV32 Zbc Standard Extension *** | ||
66 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
67 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/target/riscv/bitmanip_helper.c | ||
70 | +++ b/target/riscv/bitmanip_helper.c | ||
71 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(grevw)(target_ulong rs1, target_ulong rs2) | ||
72 | return do_grev(rs1, rs2, 32); | ||
73 | } | 27 | } |
74 | 28 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | |
75 | -static target_ulong do_gorc(target_ulong rs1, | 29 | return require_rvv(s) && |
76 | - target_ulong rs2, | 30 | require_rvf(s) && |
77 | - int bits) | 31 | require_scale_rvf(s) && |
78 | -{ | 32 | - (s->sew != MO_8) && |
79 | - target_ulong x = rs1; | 33 | vext_check_isa_ill(s) && |
80 | - int i, shift; | 34 | vext_check_ds(s, a->rd, a->rs2, a->vm); |
81 | - | 35 | } |
82 | - for (i = 0, shift = 1; shift < bits; i++, shift <<= 1) { | 36 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) |
83 | - if (rs2 & shift) { | 37 | return require_rvv(s) && |
84 | - x |= do_swap(x, adjacent_masks[i], shift); | 38 | require_rvf(s) && |
85 | - } | 39 | require_scale_rvf(s) && |
86 | - } | 40 | - (s->sew != MO_8) && |
87 | - | 41 | vext_check_isa_ill(s) && |
88 | - return x; | 42 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); |
89 | -} | 43 | } |
90 | - | 44 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) |
91 | -target_ulong HELPER(gorc)(target_ulong rs1, target_ulong rs2) | 45 | return require_rvv(s) && |
92 | -{ | 46 | require_rvf(s) && |
93 | - return do_gorc(rs1, rs2, TARGET_LONG_BITS); | 47 | require_scale_rvf(s) && |
94 | -} | 48 | - (s->sew != MO_8) && |
95 | - | 49 | vext_check_isa_ill(s) && |
96 | -target_ulong HELPER(gorcw)(target_ulong rs1, target_ulong rs2) | 50 | vext_check_dd(s, a->rd, a->rs2, a->vm); |
97 | -{ | 51 | } |
98 | - return do_gorc(rs1, rs2, 32); | 52 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) |
99 | -} | ||
100 | - | ||
101 | target_ulong HELPER(clmul)(target_ulong rs1, target_ulong rs2) | ||
102 | { | 53 | { |
103 | target_ulong result = 0; | 54 | return opfv_widen_check(s, a) && |
104 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | 55 | require_rvfmin(s) && |
105 | index XXXXXXX..XXXXXXX 100644 | 56 | - require_scale_rvfmin(s) && |
106 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 57 | - (s->sew != MO_8); |
107 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 58 | + require_scale_rvfmin(s); |
108 | @@ -XXX,XX +XXX,XX @@ static bool trans_grevi(DisasContext *ctx, arg_grevi *a) | ||
109 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_grevi); | ||
110 | } | 59 | } |
111 | 60 | ||
112 | -static bool trans_gorc(DisasContext *ctx, arg_gorc *a) | 61 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ |
113 | +static void gen_orc_b(TCGv ret, TCGv source1) | 62 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
114 | { | 63 | { |
115 | - REQUIRE_EXT(ctx, RVB); | 64 | return opfv_narrow_check(s, a) && |
116 | - return gen_shift(ctx, a, EXT_ZERO, gen_helper_gorc); | 65 | require_rvfmin(s) && |
117 | + TCGv tmp = tcg_temp_new(); | 66 | - require_scale_rvfmin(s) && |
118 | + TCGv ones = tcg_constant_tl(dup_const_tl(MO_8, 0x01)); | 67 | - (s->sew != MO_8); |
119 | + | 68 | + require_scale_rvfmin(s); |
120 | + /* Set lsb in each byte if the byte was zero. */ | ||
121 | + tcg_gen_sub_tl(tmp, source1, ones); | ||
122 | + tcg_gen_andc_tl(tmp, tmp, source1); | ||
123 | + tcg_gen_shri_tl(tmp, tmp, 7); | ||
124 | + tcg_gen_andc_tl(tmp, ones, tmp); | ||
125 | + | ||
126 | + /* Replicate the lsb of each byte across the byte. */ | ||
127 | + tcg_gen_muli_tl(ret, tmp, 0xff); | ||
128 | + | ||
129 | + tcg_temp_free(tmp); | ||
130 | } | 69 | } |
131 | 70 | ||
132 | -static bool trans_gorci(DisasContext *ctx, arg_gorci *a) | 71 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
133 | +static bool trans_orc_b(DisasContext *ctx, arg_orc_b *a) | ||
134 | { | 72 | { |
135 | - REQUIRE_EXT(ctx, RVB); | 73 | return opfv_narrow_check(s, a) && |
136 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_gorc); | 74 | require_rvf(s) && |
137 | + REQUIRE_ZBB(ctx); | 75 | - require_scale_rvf(s) && |
138 | + return gen_unary(ctx, a, EXT_ZERO, gen_orc_b); | 76 | - (s->sew != MO_8); |
77 | + require_scale_rvf(s); | ||
139 | } | 78 | } |
140 | 79 | ||
141 | #define GEN_SHADD(SHAMT) \ | 80 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ |
142 | @@ -XXX,XX +XXX,XX @@ static bool trans_greviw(DisasContext *ctx, arg_greviw *a) | 81 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) |
143 | return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_grev); | 82 | { |
83 | return reduction_widen_check(s, a) && | ||
84 | require_rvf(s) && | ||
85 | - require_scale_rvf(s) && | ||
86 | - (s->sew != MO_8); | ||
87 | + require_scale_rvf(s); | ||
144 | } | 88 | } |
145 | 89 | ||
146 | -static bool trans_gorcw(DisasContext *ctx, arg_gorcw *a) | 90 | GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) |
147 | -{ | ||
148 | - REQUIRE_64BIT(ctx); | ||
149 | - REQUIRE_EXT(ctx, RVB); | ||
150 | - ctx->w = true; | ||
151 | - return gen_shift(ctx, a, EXT_ZERO, gen_helper_gorc); | ||
152 | -} | ||
153 | - | ||
154 | -static bool trans_gorciw(DisasContext *ctx, arg_gorciw *a) | ||
155 | -{ | ||
156 | - REQUIRE_64BIT(ctx); | ||
157 | - REQUIRE_EXT(ctx, RVB); | ||
158 | - ctx->w = true; | ||
159 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_gorc); | ||
160 | -} | ||
161 | - | ||
162 | #define GEN_SHADD_UW(SHAMT) \ | ||
163 | static void gen_sh##SHAMT##add_uw(TCGv ret, TCGv arg1, TCGv arg2) \ | ||
164 | { \ | ||
165 | -- | 91 | -- |
166 | 2.31.1 | 92 | 2.45.1 |
167 | |||
168 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | With the changes to Zb[abcs], there's some encodings that are | 3 | raise_mmu_exception(), as is today, is prioritizing guest page faults by |
4 | different in RV64 and RV32 (e.g., for rev8 and zext.h). For these, | 4 | checking first if virt_enabled && !first_stage, and then considering the |
5 | we'll need a helper macro allowing us to select on RV32, as well. | 5 | regular inst/load/store faults. |
6 | 6 | ||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 7 | There's no mention in the spec about guest page fault being a higher |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | priority that PMP faults. In fact, privileged spec section 3.7.1 says: |
9 | |||
10 | "Attempting to fetch an instruction from a PMP region that does not have | ||
11 | execute permissions raises an instruction access-fault exception. | ||
12 | Attempting to execute a load or load-reserved instruction which accesses | ||
13 | a physical address within a PMP region without read permissions raises a | ||
14 | load access-fault exception. Attempting to execute a store, | ||
15 | store-conditional, or AMO instruction which accesses a physical address | ||
16 | within a PMP region without write permissions raises a store | ||
17 | access-fault exception." | ||
18 | |||
19 | So, in fact, we're doing it wrong - PMP faults should always be thrown, | ||
20 | regardless of also being a first or second stage fault. | ||
21 | |||
22 | The way riscv_cpu_tlb_fill() and get_physical_address() work is | ||
23 | adequate: a TRANSLATE_PMP_FAIL error is immediately reported and | ||
24 | reflected in the 'pmp_violation' flag. What we need is to change | ||
25 | raise_mmu_exception() to prioritize it. | ||
26 | |||
27 | Reported-by: Joseph Chan <jchan@ventanamicro.com> | ||
28 | Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage") | ||
29 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 31 | Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com> |
11 | Message-id: 20210911140016.834071-13-philipp.tomsich@vrull.eu | 32 | Cc: qemu-stable <qemu-stable@nongnu.org> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 34 | --- |
14 | target/riscv/translate.c | 6 ++++++ | 35 | target/riscv/cpu_helper.c | 22 ++++++++++++---------- |
15 | 1 file changed, 6 insertions(+) | 36 | 1 file changed, 12 insertions(+), 10 deletions(-) |
16 | 37 | ||
17 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
18 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/translate.c | 40 | --- a/target/riscv/cpu_helper.c |
20 | +++ b/target/riscv/translate.c | 41 | +++ b/target/riscv/cpu_helper.c |
21 | @@ -XXX,XX +XXX,XX @@ EX_SH(12) | 42 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, |
22 | } \ | 43 | |
23 | } while (0) | 44 | switch (access_type) { |
24 | 45 | case MMU_INST_FETCH: | |
25 | +#define REQUIRE_32BIT(ctx) do { \ | 46 | - if (env->virt_enabled && !first_stage) { |
26 | + if (!is_32bit(ctx)) { \ | 47 | + if (pmp_violation) { |
27 | + return false; \ | 48 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; |
28 | + } \ | 49 | + } else if (env->virt_enabled && !first_stage) { |
29 | +} while (0) | 50 | cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT; |
30 | + | 51 | } else { |
31 | #define REQUIRE_64BIT(ctx) do { \ | 52 | - cs->exception_index = pmp_violation ? |
32 | if (is_32bit(ctx)) { \ | 53 | - RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT; |
33 | return false; \ | 54 | + cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; |
55 | } | ||
56 | break; | ||
57 | case MMU_DATA_LOAD: | ||
58 | - if (two_stage && !first_stage) { | ||
59 | + if (pmp_violation) { | ||
60 | + cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; | ||
61 | + } else if (two_stage && !first_stage) { | ||
62 | cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT; | ||
63 | } else { | ||
64 | - cs->exception_index = pmp_violation ? | ||
65 | - RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT; | ||
66 | + cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT; | ||
67 | } | ||
68 | break; | ||
69 | case MMU_DATA_STORE: | ||
70 | - if (two_stage && !first_stage) { | ||
71 | + if (pmp_violation) { | ||
72 | + cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; | ||
73 | + } else if (two_stage && !first_stage) { | ||
74 | cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; | ||
75 | } else { | ||
76 | - cs->exception_index = pmp_violation ? | ||
77 | - RISCV_EXCP_STORE_AMO_ACCESS_FAULT : | ||
78 | - RISCV_EXCP_STORE_PAGE_FAULT; | ||
79 | + cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; | ||
80 | } | ||
81 | break; | ||
82 | default: | ||
34 | -- | 83 | -- |
35 | 2.31.1 | 84 | 2.45.1 |
36 | |||
37 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Alexei Filippov <alexei.filippov@syntacore.com> |
---|---|---|---|
2 | 2 | ||
3 | The Zb[abcs] ratification package does not include the proposed | 3 | Previous patch fixed the PMP priority in raise_mmu_exception() but we're still |
4 | shift-one instructions. There currently is no clear plan to whether | 4 | setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage |
5 | these (or variants of them) will be ratified as Zbo (or a different | 5 | translation part, mtval2 will be set in case of successes 2 stage translation but |
6 | extension) or what the timeframe for such a decision could be. | 6 | failed pmp check. |
7 | 7 | ||
8 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 8 | In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 9 | riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2 |
10 | should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest | ||
11 | page-fault is taken into M-mode, mtval2 is written with either zero or guest | ||
12 | physical address that faulted, shifted by 2 bits. *For other traps, mtval2 | ||
13 | is set to zero...* | ||
14 | |||
15 | Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com> | ||
16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | 18 | Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> |
12 | Message-id: 20210911140016.834071-8-philipp.tomsich@vrull.eu | 19 | Cc: qemu-stable <qemu-stable@nongnu.org> |
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 21 | --- |
15 | target/riscv/insn32.decode | 8 --- | 22 | target/riscv/cpu_helper.c | 12 ++++++------ |
16 | target/riscv/insn_trans/trans_rvb.c.inc | 70 ------------------------- | 23 | 1 file changed, 6 insertions(+), 6 deletions(-) |
17 | 2 files changed, 78 deletions(-) | ||
18 | 24 | ||
19 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 25 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
20 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/insn32.decode | 27 | --- a/target/riscv/cpu_helper.c |
22 | +++ b/target/riscv/insn32.decode | 28 | +++ b/target/riscv/cpu_helper.c |
23 | @@ -XXX,XX +XXX,XX @@ bset 0010100 .......... 001 ..... 0110011 @r | 29 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
24 | bclr 0100100 .......... 001 ..... 0110011 @r | 30 | __func__, pa, ret, prot_pmp, tlb_size); |
25 | binv 0110100 .......... 001 ..... 0110011 @r | 31 | |
26 | bext 0100100 .......... 101 ..... 0110011 @r | 32 | prot &= prot_pmp; |
27 | -slo 0010000 .......... 001 ..... 0110011 @r | 33 | - } |
28 | -sro 0010000 .......... 101 ..... 0110011 @r | ||
29 | ror 0110000 .......... 101 ..... 0110011 @r | ||
30 | rol 0110000 .......... 001 ..... 0110011 @r | ||
31 | grev 0110100 .......... 101 ..... 0110011 @r | ||
32 | @@ -XXX,XX +XXX,XX @@ bseti 00101. ........... 001 ..... 0010011 @sh | ||
33 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
34 | binvi 01101. ........... 001 ..... 0010011 @sh | ||
35 | bexti 01001. ........... 101 ..... 0010011 @sh | ||
36 | -sloi 00100. ........... 001 ..... 0010011 @sh | ||
37 | -sroi 00100. ........... 101 ..... 0010011 @sh | ||
38 | rori 01100. ........... 101 ..... 0010011 @sh | ||
39 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
40 | gorci 00101. ........... 101 ..... 0010011 @sh | ||
41 | @@ -XXX,XX +XXX,XX @@ cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
42 | |||
43 | packw 0000100 .......... 100 ..... 0111011 @r | ||
44 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
45 | -slow 0010000 .......... 001 ..... 0111011 @r | ||
46 | -srow 0010000 .......... 101 ..... 0111011 @r | ||
47 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
48 | rolw 0110000 .......... 001 ..... 0111011 @r | ||
49 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
50 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
51 | |||
52 | -sloiw 0010000 .......... 001 ..... 0011011 @sh5 | ||
53 | -sroiw 0010000 .......... 101 ..... 0011011 @sh5 | ||
54 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
55 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
56 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
57 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
60 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
61 | @@ -XXX,XX +XXX,XX @@ static bool trans_bexti(DisasContext *ctx, arg_bexti *a) | ||
62 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext); | ||
63 | } | ||
64 | |||
65 | -static void gen_slo(TCGv ret, TCGv arg1, TCGv arg2) | ||
66 | -{ | ||
67 | - tcg_gen_not_tl(ret, arg1); | ||
68 | - tcg_gen_shl_tl(ret, ret, arg2); | ||
69 | - tcg_gen_not_tl(ret, ret); | ||
70 | -} | ||
71 | - | 34 | - |
72 | -static bool trans_slo(DisasContext *ctx, arg_slo *a) | 35 | - if (ret != TRANSLATE_SUCCESS) { |
73 | -{ | 36 | + } else { |
74 | - REQUIRE_EXT(ctx, RVB); | 37 | /* |
75 | - return gen_shift(ctx, a, EXT_NONE, gen_slo); | 38 | * Guest physical address translation failed, this is a HS |
76 | -} | 39 | * level exception |
77 | - | 40 | */ |
78 | -static bool trans_sloi(DisasContext *ctx, arg_sloi *a) | 41 | first_stage_error = false; |
79 | -{ | 42 | - env->guest_phys_fault_addr = (im_address | |
80 | - REQUIRE_EXT(ctx, RVB); | 43 | - (address & |
81 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_slo); | 44 | - (TARGET_PAGE_SIZE - 1))) >> 2; |
82 | -} | 45 | + if (ret != TRANSLATE_PMP_FAIL) { |
83 | - | 46 | + env->guest_phys_fault_addr = (im_address | |
84 | -static void gen_sro(TCGv ret, TCGv arg1, TCGv arg2) | 47 | + (address & |
85 | -{ | 48 | + (TARGET_PAGE_SIZE - 1))) >> 2; |
86 | - tcg_gen_not_tl(ret, arg1); | 49 | + } |
87 | - tcg_gen_shr_tl(ret, ret, arg2); | 50 | } |
88 | - tcg_gen_not_tl(ret, ret); | 51 | } |
89 | -} | 52 | } else { |
90 | - | ||
91 | -static bool trans_sro(DisasContext *ctx, arg_sro *a) | ||
92 | -{ | ||
93 | - REQUIRE_EXT(ctx, RVB); | ||
94 | - return gen_shift(ctx, a, EXT_ZERO, gen_sro); | ||
95 | -} | ||
96 | - | ||
97 | -static bool trans_sroi(DisasContext *ctx, arg_sroi *a) | ||
98 | -{ | ||
99 | - REQUIRE_EXT(ctx, RVB); | ||
100 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_sro); | ||
101 | -} | ||
102 | - | ||
103 | static bool trans_ror(DisasContext *ctx, arg_ror *a) | ||
104 | { | ||
105 | REQUIRE_EXT(ctx, RVB); | ||
106 | @@ -XXX,XX +XXX,XX @@ static bool trans_packuw(DisasContext *ctx, arg_packuw *a) | ||
107 | return gen_arith(ctx, a, EXT_NONE, gen_packuw); | ||
108 | } | ||
109 | |||
110 | -static bool trans_slow(DisasContext *ctx, arg_slow *a) | ||
111 | -{ | ||
112 | - REQUIRE_64BIT(ctx); | ||
113 | - REQUIRE_EXT(ctx, RVB); | ||
114 | - ctx->w = true; | ||
115 | - return gen_shift(ctx, a, EXT_NONE, gen_slo); | ||
116 | -} | ||
117 | - | ||
118 | -static bool trans_sloiw(DisasContext *ctx, arg_sloiw *a) | ||
119 | -{ | ||
120 | - REQUIRE_64BIT(ctx); | ||
121 | - REQUIRE_EXT(ctx, RVB); | ||
122 | - ctx->w = true; | ||
123 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_slo); | ||
124 | -} | ||
125 | - | ||
126 | -static bool trans_srow(DisasContext *ctx, arg_srow *a) | ||
127 | -{ | ||
128 | - REQUIRE_64BIT(ctx); | ||
129 | - REQUIRE_EXT(ctx, RVB); | ||
130 | - ctx->w = true; | ||
131 | - return gen_shift(ctx, a, EXT_ZERO, gen_sro); | ||
132 | -} | ||
133 | - | ||
134 | -static bool trans_sroiw(DisasContext *ctx, arg_sroiw *a) | ||
135 | -{ | ||
136 | - REQUIRE_64BIT(ctx); | ||
137 | - REQUIRE_EXT(ctx, RVB); | ||
138 | - ctx->w = true; | ||
139 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_sro); | ||
140 | -} | ||
141 | - | ||
142 | static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | ||
143 | { | ||
144 | TCGv_i32 t1 = tcg_temp_new_i32(); | ||
145 | -- | 53 | -- |
146 | 2.31.1 | 54 | 2.45.1 |
147 | |||
148 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Rob Bradford <rbradford@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Zbs 1.0.0 (just as the 0.93 draft-B before) does not provide for W-form | 3 | This extension has now been ratified: |
4 | instructions for Zbs (single-bit instructions). Remove them. | 4 | https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be |
5 | removed. | ||
5 | 6 | ||
6 | Note that these instructions had already been removed for the 0.93 | 7 | Since this is now a ratified extension add it to the list of extensions |
7 | version of the draft-B extention and have not been present in the | 8 | included in the "max" CPU variant. |
8 | binutils patches circulating in January 2021. | ||
9 | 9 | ||
10 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 10 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | 13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
14 | Message-id: 20210911140016.834071-7-philipp.tomsich@vrull.eu | 14 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
15 | Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 17 | --- |
17 | target/riscv/insn32.decode | 7 ---- | 18 | target/riscv/cpu.c | 2 +- |
18 | target/riscv/insn_trans/trans_rvb.c.inc | 56 ------------------------- | 19 | target/riscv/tcg/tcg-cpu.c | 2 +- |
19 | 2 files changed, 63 deletions(-) | 20 | 2 files changed, 2 insertions(+), 2 deletions(-) |
20 | 21 | ||
21 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 22 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/insn32.decode | 24 | --- a/target/riscv/cpu.c |
24 | +++ b/target/riscv/insn32.decode | 25 | +++ b/target/riscv/cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | 26 | @@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = { |
26 | 27 | MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), | |
27 | packw 0000100 .......... 100 ..... 0111011 @r | 28 | MISA_EXT_INFO(RVV, "v", "Vector operations"), |
28 | packuw 0100100 .......... 100 ..... 0111011 @r | 29 | MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), |
29 | -bsetw 0010100 .......... 001 ..... 0111011 @r | 30 | - MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") |
30 | -bclrw 0100100 .......... 001 ..... 0111011 @r | 31 | + MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") |
31 | -binvw 0110100 .......... 001 ..... 0111011 @r | 32 | }; |
32 | -bextw 0100100 .......... 101 ..... 0111011 @r | 33 | |
33 | slow 0010000 .......... 001 ..... 0111011 @r | 34 | static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc) |
34 | srow 0010000 .......... 101 ..... 0111011 @r | 35 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
35 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
36 | @@ -XXX,XX +XXX,XX @@ rolw 0110000 .......... 001 ..... 0111011 @r | ||
37 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
38 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
39 | |||
40 | -bsetiw 0010100 .......... 001 ..... 0011011 @sh5 | ||
41 | -bclriw 0100100 .......... 001 ..... 0011011 @sh5 | ||
42 | -binviw 0110100 .......... 001 ..... 0011011 @sh5 | ||
43 | sloiw 0010000 .......... 001 ..... 0011011 @sh5 | ||
44 | sroiw 0010000 .......... 101 ..... 0011011 @sh5 | ||
45 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
46 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
47 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 37 | --- a/target/riscv/tcg/tcg-cpu.c |
49 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 38 | +++ b/target/riscv/tcg/tcg-cpu.c |
50 | @@ -XXX,XX +XXX,XX @@ static bool trans_packuw(DisasContext *ctx, arg_packuw *a) | 39 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) |
51 | return gen_arith(ctx, a, EXT_NONE, gen_packuw); | 40 | const RISCVCPUMultiExtConfig *prop; |
52 | } | 41 | |
53 | 42 | /* Enable RVG, RVJ and RVV that are disabled by default */ | |
54 | -static bool trans_bsetw(DisasContext *ctx, arg_bsetw *a) | 43 | - riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV); |
55 | -{ | 44 | + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); |
56 | - REQUIRE_64BIT(ctx); | 45 | |
57 | - REQUIRE_EXT(ctx, RVB); | 46 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { |
58 | - ctx->w = true; | 47 | isa_ext_update_enabled(cpu, prop->offset, true); |
59 | - return gen_shift(ctx, a, EXT_NONE, gen_bset); | ||
60 | -} | ||
61 | - | ||
62 | -static bool trans_bsetiw(DisasContext *ctx, arg_bsetiw *a) | ||
63 | -{ | ||
64 | - REQUIRE_64BIT(ctx); | ||
65 | - REQUIRE_EXT(ctx, RVB); | ||
66 | - ctx->w = true; | ||
67 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bset); | ||
68 | -} | ||
69 | - | ||
70 | -static bool trans_bclrw(DisasContext *ctx, arg_bclrw *a) | ||
71 | -{ | ||
72 | - REQUIRE_64BIT(ctx); | ||
73 | - REQUIRE_EXT(ctx, RVB); | ||
74 | - ctx->w = true; | ||
75 | - return gen_shift(ctx, a, EXT_NONE, gen_bclr); | ||
76 | -} | ||
77 | - | ||
78 | -static bool trans_bclriw(DisasContext *ctx, arg_bclriw *a) | ||
79 | -{ | ||
80 | - REQUIRE_64BIT(ctx); | ||
81 | - REQUIRE_EXT(ctx, RVB); | ||
82 | - ctx->w = true; | ||
83 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bclr); | ||
84 | -} | ||
85 | - | ||
86 | -static bool trans_binvw(DisasContext *ctx, arg_binvw *a) | ||
87 | -{ | ||
88 | - REQUIRE_64BIT(ctx); | ||
89 | - REQUIRE_EXT(ctx, RVB); | ||
90 | - ctx->w = true; | ||
91 | - return gen_shift(ctx, a, EXT_NONE, gen_binv); | ||
92 | -} | ||
93 | - | ||
94 | -static bool trans_binviw(DisasContext *ctx, arg_binviw *a) | ||
95 | -{ | ||
96 | - REQUIRE_64BIT(ctx); | ||
97 | - REQUIRE_EXT(ctx, RVB); | ||
98 | - ctx->w = true; | ||
99 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_binv); | ||
100 | -} | ||
101 | - | ||
102 | -static bool trans_bextw(DisasContext *ctx, arg_bextw *a) | ||
103 | -{ | ||
104 | - REQUIRE_64BIT(ctx); | ||
105 | - REQUIRE_EXT(ctx, RVB); | ||
106 | - ctx->w = true; | ||
107 | - return gen_shift(ctx, a, EXT_NONE, gen_bext); | ||
108 | -} | ||
109 | - | ||
110 | static bool trans_slow(DisasContext *ctx, arg_slow *a) | ||
111 | { | ||
112 | REQUIRE_64BIT(ctx); | ||
113 | -- | 48 | -- |
114 | 2.31.1 | 49 | 2.45.1 |
115 | |||
116 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The 1.0.0 version of Zbb does not contain grev/grevi. Instead, a | 3 | When running the instruction |
4 | rev8 instruction (equivalent to the rev8 pseudo-instruction built on | ||
5 | grevi from pre-0.93 draft-B) is available. | ||
6 | 4 | ||
7 | This commit adds the new rev8 instruction and removes grev/grevi. | 5 | ``` |
6 | cbo.flush 0(x0) | ||
7 | ``` | ||
8 | 8 | ||
9 | Note that there is no W-form of this instruction (both a | 9 | QEMU would segfault. |
10 | sign-extending and zero-extending 32-bit version can easily be | ||
11 | synthesized by following rev8 with either a srai or srli instruction | ||
12 | on RV64) and that the opcode encodings for rev8 in RV32 and RV64 are | ||
13 | different. | ||
14 | 10 | ||
15 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 11 | The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0] |
12 | allocated. | ||
13 | |||
14 | In order to fix this let's use the existing get_address() | ||
15 | helper. This also has the benefit of performing pointer mask | ||
16 | calculations on the address specified in rs1. | ||
17 | |||
18 | The pointer masking specificiation specifically states: | ||
19 | |||
20 | """ | ||
21 | Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz | ||
22 | """ | ||
23 | |||
24 | So this is the correct behaviour and we previously have been incorrectly | ||
25 | not masking the address. | ||
26 | |||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | Reported-by: Fabian Thomas <fabian.thomas@cispa.de> | ||
29 | Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension") | ||
16 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 30 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 31 | Cc: qemu-stable <qemu-stable@nongnu.org> |
18 | Message-id: 20210911140016.834071-14-philipp.tomsich@vrull.eu | 32 | Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com> |
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
20 | --- | 34 | --- |
21 | target/riscv/helper.h | 2 -- | 35 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++---- |
22 | target/riscv/insn32.decode | 12 ++++---- | 36 | 1 file changed, 12 insertions(+), 4 deletions(-) |
23 | target/riscv/bitmanip_helper.c | 40 ------------------------- | ||
24 | target/riscv/insn_trans/trans_rvb.c.inc | 40 +++++-------------------- | ||
25 | 4 files changed, 15 insertions(+), 79 deletions(-) | ||
26 | 37 | ||
27 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 38 | diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
28 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/riscv/helper.h | 40 | --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc |
30 | +++ b/target/riscv/helper.h | 41 | +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
31 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl) | ||
32 | DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) | ||
33 | |||
34 | /* Bitmanip */ | ||
35 | -DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
36 | -DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
37 | DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
38 | DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
39 | |||
40 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/riscv/insn32.decode | ||
43 | +++ b/target/riscv/insn32.decode | ||
44 | @@ -XXX,XX +XXX,XX @@ min 0000101 .......... 100 ..... 0110011 @r | ||
45 | minu 0000101 .......... 101 ..... 0110011 @r | ||
46 | orc_b 001010 000111 ..... 101 ..... 0010011 @r2 | ||
47 | orn 0100000 .......... 110 ..... 0110011 @r | ||
48 | +# The encoding for rev8 differs between RV32 and RV64. | ||
49 | +# rev8_32 denotes the RV32 variant. | ||
50 | +rev8_32 011010 011000 ..... 101 ..... 0010011 @r2 | ||
51 | rol 0110000 .......... 001 ..... 0110011 @r | ||
52 | ror 0110000 .......... 101 ..... 0110011 @r | ||
53 | rori 01100 ............ 101 ..... 0010011 @sh | ||
54 | @@ -XXX,XX +XXX,XX @@ xnor 0100000 .......... 100 ..... 0110011 @r | ||
55 | clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
56 | ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
57 | cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
58 | +# The encoding for rev8 differs between RV32 and RV64. | ||
59 | +# When executing on RV64, the encoding used in RV32 is an illegal | ||
60 | +# instruction, so we use different handler functions to differentiate. | ||
61 | +rev8_64 011010 111000 ..... 101 ..... 0010011 @r2 | ||
62 | rolw 0110000 .......... 001 ..... 0111011 @r | ||
63 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
64 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
65 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | ||
66 | pack 0000100 .......... 100 ..... 0110011 @r | ||
67 | packu 0100100 .......... 100 ..... 0110011 @r | ||
68 | packh 0000100 .......... 111 ..... 0110011 @r | ||
69 | -grev 0110100 .......... 101 ..... 0110011 @r | ||
70 | -grevi 01101. ........... 101 ..... 0010011 @sh | ||
71 | |||
72 | # *** RV64B Standard Extension (in addition to RV32B) *** | ||
73 | packw 0000100 .......... 100 ..... 0111011 @r | ||
74 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
75 | -grevw 0110100 .......... 101 ..... 0111011 @r | ||
76 | - | ||
77 | -greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
78 | |||
79 | # *** RV32 Zbc Standard Extension *** | ||
80 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
81 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/riscv/bitmanip_helper.c | ||
84 | +++ b/target/riscv/bitmanip_helper.c | ||
85 | @@ -XXX,XX +XXX,XX @@ | 42 | @@ -XXX,XX +XXX,XX @@ |
86 | #include "exec/helper-proto.h" | 43 | static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) |
87 | #include "tcg/tcg.h" | ||
88 | |||
89 | -static const uint64_t adjacent_masks[] = { | ||
90 | - dup_const(MO_8, 0x55), | ||
91 | - dup_const(MO_8, 0x33), | ||
92 | - dup_const(MO_8, 0x0f), | ||
93 | - dup_const(MO_16, 0xff), | ||
94 | - dup_const(MO_32, 0xffff), | ||
95 | - UINT32_MAX | ||
96 | -}; | ||
97 | - | ||
98 | -static inline target_ulong do_swap(target_ulong x, uint64_t mask, int shift) | ||
99 | -{ | ||
100 | - return ((x & mask) << shift) | ((x & ~mask) >> shift); | ||
101 | -} | ||
102 | - | ||
103 | -static target_ulong do_grev(target_ulong rs1, | ||
104 | - target_ulong rs2, | ||
105 | - int bits) | ||
106 | -{ | ||
107 | - target_ulong x = rs1; | ||
108 | - int i, shift; | ||
109 | - | ||
110 | - for (i = 0, shift = 1; shift < bits; i++, shift <<= 1) { | ||
111 | - if (rs2 & shift) { | ||
112 | - x = do_swap(x, adjacent_masks[i], shift); | ||
113 | - } | ||
114 | - } | ||
115 | - | ||
116 | - return x; | ||
117 | -} | ||
118 | - | ||
119 | -target_ulong HELPER(grev)(target_ulong rs1, target_ulong rs2) | ||
120 | -{ | ||
121 | - return do_grev(rs1, rs2, TARGET_LONG_BITS); | ||
122 | -} | ||
123 | - | ||
124 | -target_ulong HELPER(grevw)(target_ulong rs1, target_ulong rs2) | ||
125 | -{ | ||
126 | - return do_grev(rs1, rs2, 32); | ||
127 | -} | ||
128 | - | ||
129 | target_ulong HELPER(clmul)(target_ulong rs1, target_ulong rs2) | ||
130 | { | 44 | { |
131 | target_ulong result = 0; | 45 | REQUIRE_ZICBOM(ctx); |
132 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | 46 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
133 | index XXXXXXX..XXXXXXX 100644 | 47 | + TCGv src = get_address(ctx, a->rs1, 0); |
134 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 48 | + |
135 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 49 | + gen_helper_cbo_clean_flush(tcg_env, src); |
136 | @@ -XXX,XX +XXX,XX @@ static bool trans_rol(DisasContext *ctx, arg_rol *a) | 50 | return true; |
137 | return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl); | ||
138 | } | 51 | } |
139 | 52 | ||
140 | -static bool trans_grev(DisasContext *ctx, arg_grev *a) | 53 | static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) |
141 | +static bool trans_rev8_32(DisasContext *ctx, arg_rev8_32 *a) | ||
142 | { | 54 | { |
143 | - REQUIRE_EXT(ctx, RVB); | 55 | REQUIRE_ZICBOM(ctx); |
144 | - return gen_shift(ctx, a, EXT_NONE, gen_helper_grev); | 56 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
145 | -} | 57 | + TCGv src = get_address(ctx, a->rs1, 0); |
146 | - | 58 | + |
147 | -static void gen_grevi(TCGv dest, TCGv src, target_long shamt) | 59 | + gen_helper_cbo_clean_flush(tcg_env, src); |
148 | -{ | 60 | return true; |
149 | - if (shamt == TARGET_LONG_BITS - 8) { | ||
150 | - /* rev8, byte swaps */ | ||
151 | - tcg_gen_bswap_tl(dest, src); | ||
152 | - } else { | ||
153 | - gen_helper_grev(dest, src, tcg_constant_tl(shamt)); | ||
154 | - } | ||
155 | + REQUIRE_32BIT(ctx); | ||
156 | + REQUIRE_ZBB(ctx); | ||
157 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_bswap_tl); | ||
158 | } | 61 | } |
159 | 62 | ||
160 | -static bool trans_grevi(DisasContext *ctx, arg_grevi *a) | 63 | static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) |
161 | +static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a) | ||
162 | { | 64 | { |
163 | - REQUIRE_EXT(ctx, RVB); | 65 | REQUIRE_ZICBOM(ctx); |
164 | - return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_grevi); | 66 | - gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]); |
165 | + REQUIRE_64BIT(ctx); | 67 | + TCGv src = get_address(ctx, a->rs1, 0); |
166 | + REQUIRE_ZBB(ctx); | 68 | + |
167 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_bswap_tl); | 69 | + gen_helper_cbo_inval(tcg_env, src); |
70 | return true; | ||
168 | } | 71 | } |
169 | 72 | ||
170 | static void gen_orc_b(TCGv ret, TCGv source1) | 73 | static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) |
171 | @@ -XXX,XX +XXX,XX @@ static bool trans_rolw(DisasContext *ctx, arg_rolw *a) | 74 | { |
172 | return gen_shift(ctx, a, EXT_NONE, gen_rolw); | 75 | REQUIRE_ZICBOZ(ctx); |
76 | - gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]); | ||
77 | + TCGv src = get_address(ctx, a->rs1, 0); | ||
78 | + | ||
79 | + gen_helper_cbo_zero(tcg_env, src); | ||
80 | return true; | ||
173 | } | 81 | } |
174 | |||
175 | -static bool trans_grevw(DisasContext *ctx, arg_grevw *a) | ||
176 | -{ | ||
177 | - REQUIRE_64BIT(ctx); | ||
178 | - REQUIRE_EXT(ctx, RVB); | ||
179 | - ctx->w = true; | ||
180 | - return gen_shift(ctx, a, EXT_ZERO, gen_helper_grev); | ||
181 | -} | ||
182 | - | ||
183 | -static bool trans_greviw(DisasContext *ctx, arg_greviw *a) | ||
184 | -{ | ||
185 | - REQUIRE_64BIT(ctx); | ||
186 | - REQUIRE_EXT(ctx, RVB); | ||
187 | - ctx->w = true; | ||
188 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_grev); | ||
189 | -} | ||
190 | - | ||
191 | #define GEN_SHADD_UW(SHAMT) \ | ||
192 | static void gen_sh##SHAMT##add_uw(TCGv ret, TCGv arg1, TCGv arg2) \ | ||
193 | { \ | ||
194 | -- | 82 | -- |
195 | 2.31.1 | 83 | 2.45.1 |
196 | |||
197 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Assume clzw being executed on a register that is not sign-extended, such | 3 | In AIA spec, each hart (or each hart within a group) has a unique hart |
4 | as for the following sequence that uses (1ULL << 63) | 392 as the operand | 4 | number to locate the memory pages of interrupt files in the address |
5 | to clzw: | 5 | space. The number of bits required to represent any hart number is equal |
6 | bseti a2, zero, 63 | 6 | to ceil(log2(hmax + 1)), where hmax is the largest hart number among |
7 | addi a2, a2, 392 | 7 | groups. |
8 | clzw a3, a2 | ||
9 | The correct result of clzw would be 23, but the current implementation | ||
10 | returns -32 (as it performs a 64bit clz, which results in 0 leading zero | ||
11 | bits, and then subtracts 32). | ||
12 | 8 | ||
13 | Fix this by changing the implementation to: | 9 | However, if the largest hart number among groups is a power of 2, QEMU |
14 | 1. shift the original register up by 32 | 10 | will pass an inaccurate hart-index-bit setting to Linux. For example, when |
15 | 2. performs a target-length (64bit) clz | 11 | the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient |
16 | 3. return 32 if no bits are set | 12 | to represent 4 harts, but we passes 3 to Linux. The code needs to be |
13 | updated to ensure accurate hart-index-bit settings. | ||
17 | 14 | ||
18 | Marking this instruction as 'w-form' (i.e., setting ctx->w) would not | 15 | Additionally, a Linux patch[1] is necessary to correctly recover the hart |
19 | correctly model the behaviour, as the instruction should not perform | 16 | index when the guest OS has only 1 hart, where the hart-index-bit is 0. |
20 | a zero-extensions on the input (after all, it is not a .uw instruction) | ||
21 | and the result is always in the range 0..32 (so neither a sign-extension | ||
22 | nor a zero-extension on the result will ever be needed). Consequently, | ||
23 | we do not set ctx->w and mark the instruction as EXT_NONE. | ||
24 | 17 | ||
25 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 18 | [1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/ |
26 | Reviewed-by: LIU Zhiwei<zhiwei_liu@c-sky.com> | 19 | |
27 | Message-id: 20210911140016.834071-4-philipp.tomsich@vrull.eu | 20 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
22 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
23 | Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com> | ||
28 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
29 | --- | 25 | --- |
30 | target/riscv/insn_trans/trans_rvb.c.inc | 8 +++++--- | 26 | target/riscv/kvm/kvm-cpu.c | 9 ++++++++- |
31 | 1 file changed, 5 insertions(+), 3 deletions(-) | 27 | 1 file changed, 8 insertions(+), 1 deletion(-) |
32 | 28 | ||
33 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | 29 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
34 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 31 | --- a/target/riscv/kvm/kvm-cpu.c |
36 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 32 | +++ b/target/riscv/kvm/kvm-cpu.c |
37 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD(3) | 33 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
38 | 34 | } | |
39 | static void gen_clzw(TCGv ret, TCGv arg1) | 35 | } |
40 | { | 36 | |
41 | - tcg_gen_clzi_tl(ret, arg1, 64); | 37 | - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
42 | - tcg_gen_subi_tl(ret, ret, 32); | 38 | + |
43 | + TCGv t = tcg_temp_new(); | 39 | + if (max_hart_per_socket > 1) { |
44 | + tcg_gen_shli_tl(t, arg1, 32); | 40 | + max_hart_per_socket--; |
45 | + tcg_gen_clzi_tl(ret, t, 32); | 41 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
46 | + tcg_temp_free(t); | 42 | + } else { |
47 | } | 43 | + hart_bits = 0; |
48 | 44 | + } | |
49 | static bool trans_clzw(DisasContext *ctx, arg_clzw *a) | 45 | + |
50 | { | 46 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, |
51 | REQUIRE_64BIT(ctx); | 47 | KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, |
52 | REQUIRE_EXT(ctx, RVB); | 48 | &hart_bits, true, NULL); |
53 | - return gen_unary(ctx, a, EXT_ZERO, gen_clzw); | ||
54 | + return gen_unary(ctx, a, EXT_NONE, gen_clzw); | ||
55 | } | ||
56 | |||
57 | static void gen_ctzw(TCGv ret, TCGv arg1) | ||
58 | -- | 49 | -- |
59 | 2.31.1 | 50 | 2.45.1 |
60 | |||
61 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Following the recent changes in translate.c, gen_add_uw() causes | 3 | Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length |
4 | failures on CF3 and SPEC2017 due to the reuse of arg1. Fix these | 4 | in bytes, when in this context we want 'reg_width' as the length in |
5 | regressions by introducing a temporary. | 5 | bits. |
6 | 6 | ||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 7 | Fix 'reg_width' back to the value in bits like 7cb59921c05a |
8 | ("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set | ||
9 | beforehand. | ||
10 | |||
11 | While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more | ||
12 | clarity about what the variable represents. 'bitsize' is also used in | ||
13 | riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to | ||
14 | gdb_feature_builder_append_reg(). | ||
15 | |||
16 | Cc: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
17 | Cc: Alex Bennée <alex.bennee@linaro.org> | ||
18 | Reported-by: Robin Dapp <rdapp.gcc@gmail.com> | ||
19 | Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML") | ||
20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
21 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
22 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
23 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 25 | Cc: qemu-stable <qemu-stable@nongnu.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 26 | Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com> |
11 | Message-id: 20210911140016.834071-2-philipp.tomsich@vrull.eu | ||
12 | Fixes: 191d1dafae9c ("target/riscv: Add DisasExtend to gen_arith*") | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 28 | --- |
15 | target/riscv/insn_trans/trans_rvb.c.inc | 6 ++++-- | 29 | target/riscv/gdbstub.c | 6 +++--- |
16 | 1 file changed, 4 insertions(+), 2 deletions(-) | 30 | 1 file changed, 3 insertions(+), 3 deletions(-) |
17 | 31 | ||
18 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | 32 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
19 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | 34 | --- a/target/riscv/gdbstub.c |
21 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | 35 | +++ b/target/riscv/gdbstub.c |
22 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD_UW(3) | 36 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) |
23 | 37 | static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | |
24 | static void gen_add_uw(TCGv ret, TCGv arg1, TCGv arg2) | ||
25 | { | 38 | { |
26 | - tcg_gen_ext32u_tl(arg1, arg1); | 39 | RISCVCPU *cpu = RISCV_CPU(cs); |
27 | - tcg_gen_add_tl(ret, arg1, arg2); | 40 | - int reg_width = cpu->cfg.vlenb; |
28 | + TCGv t = tcg_temp_new(); | 41 | + int bitsize = cpu->cfg.vlenb << 3; |
29 | + tcg_gen_ext32u_tl(t, arg1); | 42 | GDBFeatureBuilder builder; |
30 | + tcg_gen_add_tl(ret, t, arg2); | 43 | int i; |
31 | + tcg_temp_free(t); | 44 | |
32 | } | 45 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
33 | 46 | ||
34 | static bool trans_add_uw(DisasContext *ctx, arg_add_uw *a) | 47 | /* First define types and totals in a whole VL */ |
48 | for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { | ||
49 | - int count = reg_width / vec_lanes[i].size; | ||
50 | + int count = bitsize / vec_lanes[i].size; | ||
51 | gdb_feature_builder_append_tag( | ||
52 | &builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>", | ||
53 | vec_lanes[i].id, vec_lanes[i].gdb_type, count); | ||
54 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | ||
55 | /* Define vector registers */ | ||
56 | for (i = 0; i < 32; i++) { | ||
57 | gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), | ||
58 | - reg_width, i, "riscv_vector", "vector"); | ||
59 | + bitsize, i, "riscv_vector", "vector"); | ||
60 | } | ||
61 | |||
62 | gdb_feature_builder_end(&builder); | ||
35 | -- | 63 | -- |
36 | 2.31.1 | 64 | 2.45.1 |
37 | 65 | ||
38 | 66 | diff view generated by jsdifflib |
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | With the addition of Zb[abcs], we also need to add disassembler | 3 | Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr |
4 | support for these new instructions. | 4 | CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr |
5 | CSRs are part of the disassembly. | ||
5 | 6 | ||
6 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | 7 | Reported-by: Eric DeVolder <eric_devolder@yahoo.com> |
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 20210911140016.834071-17-philipp.tomsich@vrull.eu | 9 | Fixes: ea10325917 ("RISC-V Disassembler") |
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
12 | Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 14 | --- |
11 | disas/riscv.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++- | 15 | disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- |
12 | 1 file changed, 154 insertions(+), 3 deletions(-) | 16 | 1 file changed, 64 insertions(+), 1 deletion(-) |
13 | 17 | ||
14 | diff --git a/disas/riscv.c b/disas/riscv.c | 18 | diff --git a/disas/riscv.c b/disas/riscv.c |
15 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/disas/riscv.c | 20 | --- a/disas/riscv.c |
17 | +++ b/disas/riscv.c | 21 | +++ b/disas/riscv.c |
18 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 22 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
19 | rv_op_fsflags = 316, | 23 | case 0x0383: return "mibound"; |
20 | rv_op_fsrmi = 317, | 24 | case 0x0384: return "mdbase"; |
21 | rv_op_fsflagsi = 318, | 25 | case 0x0385: return "mdbound"; |
22 | + rv_op_bseti = 319, | 26 | - case 0x03a0: return "pmpcfg3"; |
23 | + rv_op_bclri = 320, | 27 | + case 0x03a0: return "pmpcfg0"; |
24 | + rv_op_binvi = 321, | 28 | + case 0x03a1: return "pmpcfg1"; |
25 | + rv_op_bexti = 322, | 29 | + case 0x03a2: return "pmpcfg2"; |
26 | + rv_op_rori = 323, | 30 | + case 0x03a3: return "pmpcfg3"; |
27 | + rv_op_clz = 324, | 31 | + case 0x03a4: return "pmpcfg4"; |
28 | + rv_op_ctz = 325, | 32 | + case 0x03a5: return "pmpcfg5"; |
29 | + rv_op_cpop = 326, | 33 | + case 0x03a6: return "pmpcfg6"; |
30 | + rv_op_sext_h = 327, | 34 | + case 0x03a7: return "pmpcfg7"; |
31 | + rv_op_sext_b = 328, | 35 | + case 0x03a8: return "pmpcfg8"; |
32 | + rv_op_xnor = 329, | 36 | + case 0x03a9: return "pmpcfg9"; |
33 | + rv_op_orn = 330, | 37 | + case 0x03aa: return "pmpcfg10"; |
34 | + rv_op_andn = 331, | 38 | + case 0x03ab: return "pmpcfg11"; |
35 | + rv_op_rol = 332, | 39 | + case 0x03ac: return "pmpcfg12"; |
36 | + rv_op_ror = 333, | 40 | + case 0x03ad: return "pmpcfg13"; |
37 | + rv_op_sh1add = 334, | 41 | + case 0x03ae: return "pmpcfg14"; |
38 | + rv_op_sh2add = 335, | 42 | + case 0x03af: return "pmpcfg15"; |
39 | + rv_op_sh3add = 336, | 43 | case 0x03b0: return "pmpaddr0"; |
40 | + rv_op_sh1add_uw = 337, | 44 | case 0x03b1: return "pmpaddr1"; |
41 | + rv_op_sh2add_uw = 338, | 45 | case 0x03b2: return "pmpaddr2"; |
42 | + rv_op_sh3add_uw = 339, | 46 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
43 | + rv_op_clmul = 340, | 47 | case 0x03bd: return "pmpaddr13"; |
44 | + rv_op_clmulr = 341, | 48 | case 0x03be: return "pmpaddr14"; |
45 | + rv_op_clmulh = 342, | 49 | case 0x03bf: return "pmpaddr15"; |
46 | + rv_op_min = 343, | 50 | + case 0x03c0: return "pmpaddr16"; |
47 | + rv_op_minu = 344, | 51 | + case 0x03c1: return "pmpaddr17"; |
48 | + rv_op_max = 345, | 52 | + case 0x03c2: return "pmpaddr18"; |
49 | + rv_op_maxu = 346, | 53 | + case 0x03c3: return "pmpaddr19"; |
50 | + rv_op_clzw = 347, | 54 | + case 0x03c4: return "pmpaddr20"; |
51 | + rv_op_ctzw = 348, | 55 | + case 0x03c5: return "pmpaddr21"; |
52 | + rv_op_cpopw = 349, | 56 | + case 0x03c6: return "pmpaddr22"; |
53 | + rv_op_slli_uw = 350, | 57 | + case 0x03c7: return "pmpaddr23"; |
54 | + rv_op_add_uw = 351, | 58 | + case 0x03c8: return "pmpaddr24"; |
55 | + rv_op_rolw = 352, | 59 | + case 0x03c9: return "pmpaddr25"; |
56 | + rv_op_rorw = 353, | 60 | + case 0x03ca: return "pmpaddr26"; |
57 | + rv_op_rev8 = 354, | 61 | + case 0x03cb: return "pmpaddr27"; |
58 | + rv_op_zext_h = 355, | 62 | + case 0x03cc: return "pmpaddr28"; |
59 | + rv_op_roriw = 356, | 63 | + case 0x03cd: return "pmpaddr29"; |
60 | + rv_op_orc_b = 357, | 64 | + case 0x03ce: return "pmpaddr30"; |
61 | + rv_op_bset = 358, | 65 | + case 0x03cf: return "pmpaddr31"; |
62 | + rv_op_bclr = 359, | 66 | + case 0x03d0: return "pmpaddr32"; |
63 | + rv_op_binv = 360, | 67 | + case 0x03d1: return "pmpaddr33"; |
64 | + rv_op_bext = 361, | 68 | + case 0x03d2: return "pmpaddr34"; |
65 | } rv_op; | 69 | + case 0x03d3: return "pmpaddr35"; |
66 | 70 | + case 0x03d4: return "pmpaddr36"; | |
67 | /* structures */ | 71 | + case 0x03d5: return "pmpaddr37"; |
68 | @@ -XXX,XX +XXX,XX @@ const rv_opcode_data opcode_data[] = { | 72 | + case 0x03d6: return "pmpaddr38"; |
69 | { "fsflags", rv_codec_i_csr, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 73 | + case 0x03d7: return "pmpaddr39"; |
70 | { "fsrmi", rv_codec_i_csr, rv_fmt_rd_zimm, NULL, 0, 0, 0 }, | 74 | + case 0x03d8: return "pmpaddr40"; |
71 | { "fsflagsi", rv_codec_i_csr, rv_fmt_rd_zimm, NULL, 0, 0, 0 }, | 75 | + case 0x03d9: return "pmpaddr41"; |
72 | + { "bseti", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | 76 | + case 0x03da: return "pmpaddr42"; |
73 | + { "bclri", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | 77 | + case 0x03db: return "pmpaddr43"; |
74 | + { "binvi", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | 78 | + case 0x03dc: return "pmpaddr44"; |
75 | + { "bexti", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | 79 | + case 0x03dd: return "pmpaddr45"; |
76 | + { "rori", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | 80 | + case 0x03de: return "pmpaddr46"; |
77 | + { "clz", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 81 | + case 0x03df: return "pmpaddr47"; |
78 | + { "ctz", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 82 | + case 0x03e0: return "pmpaddr48"; |
79 | + { "cpop", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 83 | + case 0x03e1: return "pmpaddr49"; |
80 | + { "sext.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 84 | + case 0x03e2: return "pmpaddr50"; |
81 | + { "sext.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 85 | + case 0x03e3: return "pmpaddr51"; |
82 | + { "xnor", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 86 | + case 0x03e4: return "pmpaddr52"; |
83 | + { "orn", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 87 | + case 0x03e5: return "pmpaddr53"; |
84 | + { "andn", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | 88 | + case 0x03e6: return "pmpaddr54"; |
85 | + { "rol", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 89 | + case 0x03e7: return "pmpaddr55"; |
86 | + { "ror", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 90 | + case 0x03e8: return "pmpaddr56"; |
87 | + { "sh1add", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 91 | + case 0x03e9: return "pmpaddr57"; |
88 | + { "sh2add", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 92 | + case 0x03ea: return "pmpaddr58"; |
89 | + { "sh3add", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 93 | + case 0x03eb: return "pmpaddr59"; |
90 | + { "sh1add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 94 | + case 0x03ec: return "pmpaddr60"; |
91 | + { "sh2add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 95 | + case 0x03ed: return "pmpaddr61"; |
92 | + { "sh3add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 96 | + case 0x03ee: return "pmpaddr62"; |
93 | + { "clmul", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 97 | + case 0x03ef: return "pmpaddr63"; |
94 | + { "clmulr", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 98 | case 0x0780: return "mtohost"; |
95 | + { "clmulh", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 99 | case 0x0781: return "mfromhost"; |
96 | + { "min", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 100 | case 0x0782: return "mreset"; |
97 | + { "minu", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
98 | + { "max", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
99 | + { "maxu", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
100 | + { "clzw", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
101 | + { "clzw", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
102 | + { "cpopw", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
103 | + { "slli.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
104 | + { "add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
105 | + { "rolw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
106 | + { "rorw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
107 | + { "rev8", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
108 | + { "zext.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
109 | + { "roriw", rv_codec_i_sh5, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
110 | + { "orc.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
111 | + { "bset", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
112 | + { "bclr", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
113 | + { "binv", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
114 | + { "bext", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
115 | }; | ||
116 | |||
117 | /* CSR names */ | ||
118 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
119 | case 0: op = rv_op_addi; break; | ||
120 | case 1: | ||
121 | switch (((inst >> 27) & 0b11111)) { | ||
122 | - case 0: op = rv_op_slli; break; | ||
123 | + case 0b00000: op = rv_op_slli; break; | ||
124 | + case 0b00101: op = rv_op_bseti; break; | ||
125 | + case 0b01001: op = rv_op_bclri; break; | ||
126 | + case 0b01101: op = rv_op_binvi; break; | ||
127 | + case 0b01100: | ||
128 | + switch (((inst >> 20) & 0b1111111)) { | ||
129 | + case 0b0000000: op = rv_op_clz; break; | ||
130 | + case 0b0000001: op = rv_op_ctz; break; | ||
131 | + case 0b0000010: op = rv_op_cpop; break; | ||
132 | + /* 0b0000011 */ | ||
133 | + case 0b0000100: op = rv_op_sext_b; break; | ||
134 | + case 0b0000101: op = rv_op_sext_h; break; | ||
135 | + } | ||
136 | + break; | ||
137 | } | ||
138 | break; | ||
139 | case 2: op = rv_op_slti; break; | ||
140 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
141 | case 4: op = rv_op_xori; break; | ||
142 | case 5: | ||
143 | switch (((inst >> 27) & 0b11111)) { | ||
144 | - case 0: op = rv_op_srli; break; | ||
145 | - case 8: op = rv_op_srai; break; | ||
146 | + case 0b00000: op = rv_op_srli; break; | ||
147 | + case 0b00101: op = rv_op_orc_b; break; | ||
148 | + case 0b01000: op = rv_op_srai; break; | ||
149 | + case 0b01001: op = rv_op_bexti; break; | ||
150 | + case 0b01100: op = rv_op_rori; break; | ||
151 | + case 0b01101: | ||
152 | + switch ((inst >> 20) & 0b1111111) { | ||
153 | + case 0b0111000: op = rv_op_rev8; break; | ||
154 | + } | ||
155 | + break; | ||
156 | } | ||
157 | break; | ||
158 | case 6: op = rv_op_ori; break; | ||
159 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
160 | case 1: | ||
161 | switch (((inst >> 25) & 0b1111111)) { | ||
162 | case 0: op = rv_op_slliw; break; | ||
163 | + case 4: op = rv_op_slli_uw; break; | ||
164 | + case 48: | ||
165 | + switch ((inst >> 20) & 0b11111) { | ||
166 | + case 0b00000: op = rv_op_clzw; break; | ||
167 | + case 0b00001: op = rv_op_ctzw; break; | ||
168 | + case 0b00010: op = rv_op_cpopw; break; | ||
169 | + } | ||
170 | + break; | ||
171 | } | ||
172 | break; | ||
173 | case 5: | ||
174 | switch (((inst >> 25) & 0b1111111)) { | ||
175 | case 0: op = rv_op_srliw; break; | ||
176 | case 32: op = rv_op_sraiw; break; | ||
177 | + case 48: op = rv_op_roriw; break; | ||
178 | } | ||
179 | break; | ||
180 | } | ||
181 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
182 | case 13: op = rv_op_divu; break; | ||
183 | case 14: op = rv_op_rem; break; | ||
184 | case 15: op = rv_op_remu; break; | ||
185 | + case 36: | ||
186 | + switch ((inst >> 20) & 0b11111) { | ||
187 | + case 0: op = rv_op_zext_h; break; | ||
188 | + } | ||
189 | + break; | ||
190 | + case 41: op = rv_op_clmul; break; | ||
191 | + case 42: op = rv_op_clmulr; break; | ||
192 | + case 43: op = rv_op_clmulh; break; | ||
193 | + case 44: op = rv_op_min; break; | ||
194 | + case 45: op = rv_op_minu; break; | ||
195 | + case 46: op = rv_op_max; break; | ||
196 | + case 47: op = rv_op_maxu; break; | ||
197 | + case 130: op = rv_op_sh1add; break; | ||
198 | + case 132: op = rv_op_sh2add; break; | ||
199 | + case 134: op = rv_op_sh3add; break; | ||
200 | + case 161: op = rv_op_bset; break; | ||
201 | case 256: op = rv_op_sub; break; | ||
202 | + case 260: op = rv_op_xnor; break; | ||
203 | case 261: op = rv_op_sra; break; | ||
204 | + case 262: op = rv_op_orn; break; | ||
205 | + case 263: op = rv_op_andn; break; | ||
206 | + case 289: op = rv_op_bclr; break; | ||
207 | + case 293: op = rv_op_bext; break; | ||
208 | + case 385: op = rv_op_rol; break; | ||
209 | + case 386: op = rv_op_ror; break; | ||
210 | + case 417: op = rv_op_binv; break; | ||
211 | } | ||
212 | break; | ||
213 | case 13: op = rv_op_lui; break; | ||
214 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
215 | case 13: op = rv_op_divuw; break; | ||
216 | case 14: op = rv_op_remw; break; | ||
217 | case 15: op = rv_op_remuw; break; | ||
218 | + case 32: op = rv_op_add_uw; break; | ||
219 | + case 36: | ||
220 | + switch ((inst >> 20) & 0b11111) { | ||
221 | + case 0: op = rv_op_zext_h; break; | ||
222 | + } | ||
223 | + break; | ||
224 | + case 130: op = rv_op_sh1add_uw; break; | ||
225 | + case 132: op = rv_op_sh2add_uw; break; | ||
226 | + case 134: op = rv_op_sh3add_uw; break; | ||
227 | case 256: op = rv_op_subw; break; | ||
228 | case 261: op = rv_op_sraw; break; | ||
229 | + case 385: op = rv_op_rolw; break; | ||
230 | + case 389: op = rv_op_rorw; break; | ||
231 | } | ||
232 | break; | ||
233 | case 16: | ||
234 | -- | 101 | -- |
235 | 2.31.1 | 102 | 2.45.1 |
236 | |||
237 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Yu-Ming Chang <yumin686@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | When V=1, both vsstauts.FS and HS-level sstatus.FS are in effect. | 3 | Both CSRRS and CSRRC always read the addressed CSR and cause any read side |
4 | Modifying the floating-point state when V=1 causes both fields to | 4 | effects regardless of rs1 and rd fields. Note that if rs1 specifies a register |
5 | be set to 3 (Dirty). | 5 | holding a zero value other than x0, the instruction will still attempt to write |
6 | the unmodified value back to the CSR and will cause any attendant side effects. | ||
6 | 7 | ||
7 | However, it's possible that HS-level sstatus.FS is Clean and VS-level | 8 | So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies |
8 | vsstatus.FS is Dirty at the time mark_fs_dirty() is called when V=1. | 9 | a register holding a zero value, an illegal instruction exception should be |
9 | We can't early return for this case because we still need to set | 10 | raised. |
10 | sstatus.FS to Dirty according to spec. | ||
11 | 11 | ||
12 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 12 | Signed-off-by: Yu-Ming Chang <yumin686@andestech.com> |
13 | Reviewed-by: Vincent Chen <vincent.chen@sifive.com> | ||
14 | Tested-by: Vincent Chen <vincent.chen@sifive.com> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
17 | Message-id: 20210921020234.123448-1-frank.chang@sifive.com | 14 | Message-ID: <20240403070823.80897-1-yumin686@andestech.com> |
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 16 | --- |
20 | target/riscv/cpu.h | 4 ++++ | 17 | target/riscv/cpu.h | 4 ++++ |
21 | target/riscv/translate.c | 30 +++++++++++++++++------------- | 18 | target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++---- |
22 | 2 files changed, 21 insertions(+), 13 deletions(-) | 19 | target/riscv/op_helper.c | 6 ++--- |
20 | 3 files changed, 53 insertions(+), 8 deletions(-) | ||
23 | 21 | ||
24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
25 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/riscv/cpu.h | 24 | --- a/target/riscv/cpu.h |
27 | +++ b/target/riscv/cpu.h | 25 | +++ b/target/riscv/cpu.h |
28 | @@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, SEW, 5, 3) | 26 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
29 | FIELD(TB_FLAGS, VILL, 8, 1) | 27 | void riscv_cpu_update_mask(CPURISCVState *env); |
30 | /* Is a Hypervisor instruction load/store allowed? */ | 28 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
31 | FIELD(TB_FLAGS, HLSX, 9, 1) | 29 | |
32 | +FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2) | 30 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
33 | 31 | + target_ulong *ret_value); | |
34 | bool riscv_cpu_is_32bit(CPURISCVState *env); | 32 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
35 | 33 | target_ulong *ret_value, | |
36 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | 34 | target_ulong new_value, target_ulong write_mask); |
37 | get_field(env->hstatus, HSTATUS_HU))) { | 35 | @@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, |
38 | flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1); | 36 | target_ulong new_value, |
39 | } | 37 | target_ulong write_mask); |
38 | |||
39 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, | ||
40 | + Int128 *ret_value); | ||
41 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, | ||
42 | Int128 *ret_value, | ||
43 | Int128 new_value, Int128 write_mask); | ||
44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/riscv/csr.c | ||
47 | +++ b/target/riscv/csr.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, | ||
49 | |||
50 | static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | ||
51 | int csrno, | ||
52 | - bool write_mask) | ||
53 | + bool write) | ||
54 | { | ||
55 | /* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ | ||
56 | bool read_only = get_field(csrno, 0xC00) == 3; | ||
57 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | ||
58 | } | ||
59 | |||
60 | /* read / write check */ | ||
61 | - if (write_mask && read_only) { | ||
62 | + if (write && read_only) { | ||
63 | return RISCV_EXCP_ILLEGAL_INST; | ||
64 | } | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno, | ||
67 | return RISCV_EXCP_NONE; | ||
68 | } | ||
69 | |||
70 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, | ||
71 | + target_ulong *ret_value) | ||
72 | +{ | ||
73 | + RISCVException ret = riscv_csrrw_check(env, csrno, false); | ||
74 | + if (ret != RISCV_EXCP_NONE) { | ||
75 | + return ret; | ||
76 | + } | ||
40 | + | 77 | + |
41 | + flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS, | 78 | + return riscv_csrrw_do64(env, csrno, ret_value, 0, 0); |
42 | + get_field(env->mstatus_hs, MSTATUS_FS)); | 79 | +} |
80 | + | ||
81 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
82 | target_ulong *ret_value, | ||
83 | target_ulong new_value, target_ulong write_mask) | ||
84 | { | ||
85 | - RISCVException ret = riscv_csrrw_check(env, csrno, write_mask); | ||
86 | + RISCVException ret = riscv_csrrw_check(env, csrno, true); | ||
87 | if (ret != RISCV_EXCP_NONE) { | ||
88 | return ret; | ||
43 | } | 89 | } |
44 | #endif | 90 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, |
45 | 91 | return RISCV_EXCP_NONE; | |
46 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 92 | } |
93 | |||
94 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, | ||
95 | + Int128 *ret_value) | ||
96 | +{ | ||
97 | + RISCVException ret; | ||
98 | + | ||
99 | + ret = riscv_csrrw_check(env, csrno, false); | ||
100 | + if (ret != RISCV_EXCP_NONE) { | ||
101 | + return ret; | ||
102 | + } | ||
103 | + | ||
104 | + if (csr_ops[csrno].read128) { | ||
105 | + return riscv_csrrw_do128(env, csrno, ret_value, | ||
106 | + int128_zero(), int128_zero()); | ||
107 | + } | ||
108 | + | ||
109 | + /* | ||
110 | + * Fall back to 64-bit version for now, if the 128-bit alternative isn't | ||
111 | + * at all defined. | ||
112 | + * Note, some CSRs don't need to extend to MXLEN (64 upper bits non | ||
113 | + * significant), for those, this fallback is correctly handling the | ||
114 | + * accesses | ||
115 | + */ | ||
116 | + target_ulong old_value; | ||
117 | + ret = riscv_csrrw_do64(env, csrno, &old_value, | ||
118 | + (target_ulong)0, | ||
119 | + (target_ulong)0); | ||
120 | + if (ret == RISCV_EXCP_NONE && ret_value) { | ||
121 | + *ret_value = int128_make64(old_value); | ||
122 | + } | ||
123 | + return ret; | ||
124 | +} | ||
125 | + | ||
126 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, | ||
127 | Int128 *ret_value, | ||
128 | Int128 new_value, Int128 write_mask) | ||
129 | { | ||
130 | RISCVException ret; | ||
131 | |||
132 | - ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask)); | ||
133 | + ret = riscv_csrrw_check(env, csrno, true); | ||
134 | if (ret != RISCV_EXCP_NONE) { | ||
135 | return ret; | ||
136 | } | ||
137 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | 138 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/riscv/translate.c | 139 | --- a/target/riscv/op_helper.c |
49 | +++ b/target/riscv/translate.c | 140 | +++ b/target/riscv/op_helper.c |
50 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 141 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr) |
51 | target_ulong misa; | 142 | } |
52 | uint32_t opcode; | 143 | |
53 | uint32_t mstatus_fs; | 144 | target_ulong val = 0; |
54 | + uint32_t mstatus_hs_fs; | 145 | - RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0); |
55 | uint32_t mem_idx; | 146 | + RISCVException ret = riscv_csrr(env, csr, &val); |
56 | /* Remember the rounding mode encoded in the previous fp instruction, | 147 | |
57 | which we have already installed into env->fp_status. Or -1 for | 148 | if (ret != RISCV_EXCP_NONE) { |
58 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | 149 | riscv_raise_exception(env, ret, GETPC()); |
59 | static void mark_fs_dirty(DisasContext *ctx) | 150 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr, |
151 | target_ulong helper_csrr_i128(CPURISCVState *env, int csr) | ||
60 | { | 152 | { |
61 | TCGv tmp; | 153 | Int128 rv = int128_zero(); |
62 | - target_ulong sd; | 154 | - RISCVException ret = riscv_csrrw_i128(env, csr, &rv, |
63 | + target_ulong sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD; | 155 | - int128_zero(), |
64 | 156 | - int128_zero()); | |
65 | - if (ctx->mstatus_fs == MSTATUS_FS) { | 157 | + RISCVException ret = riscv_csrr_i128(env, csr, &rv); |
66 | - return; | 158 | |
67 | - } | 159 | if (ret != RISCV_EXCP_NONE) { |
68 | - /* Remember the state change for the rest of the TB. */ | 160 | riscv_raise_exception(env, ret, GETPC()); |
69 | - ctx->mstatus_fs = MSTATUS_FS; | ||
70 | + if (ctx->mstatus_fs != MSTATUS_FS) { | ||
71 | + /* Remember the state change for the rest of the TB. */ | ||
72 | + ctx->mstatus_fs = MSTATUS_FS; | ||
73 | |||
74 | - tmp = tcg_temp_new(); | ||
75 | - sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD; | ||
76 | + tmp = tcg_temp_new(); | ||
77 | + tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
78 | + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
79 | + tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
80 | + tcg_temp_free(tmp); | ||
81 | + } | ||
82 | |||
83 | - tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
84 | - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
85 | - tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
86 | + if (ctx->virt_enabled && ctx->mstatus_hs_fs != MSTATUS_FS) { | ||
87 | + /* Remember the stage change for the rest of the TB. */ | ||
88 | + ctx->mstatus_hs_fs = MSTATUS_FS; | ||
89 | |||
90 | - if (ctx->virt_enabled) { | ||
91 | + tmp = tcg_temp_new(); | ||
92 | tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
93 | tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
94 | tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
95 | + tcg_temp_free(tmp); | ||
96 | } | ||
97 | - tcg_temp_free(tmp); | ||
98 | } | ||
99 | #else | ||
100 | static inline void mark_fs_dirty(DisasContext *ctx) { } | ||
101 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
102 | ctx->frm = -1; /* unknown rounding mode */ | ||
103 | ctx->ext_ifencei = cpu->cfg.ext_ifencei; | ||
104 | ctx->vlen = cpu->cfg.vlen; | ||
105 | + ctx->mstatus_hs_fs = FIELD_EX32(tb_flags, TB_FLAGS, MSTATUS_HS_FS); | ||
106 | ctx->hlsx = FIELD_EX32(tb_flags, TB_FLAGS, HLSX); | ||
107 | ctx->vill = FIELD_EX32(tb_flags, TB_FLAGS, VILL); | ||
108 | ctx->sew = FIELD_EX32(tb_flags, TB_FLAGS, SEW); | ||
109 | -- | 161 | -- |
110 | 2.31.1 | 162 | 2.45.1 |
111 | |||
112 | diff view generated by jsdifflib |