1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946: |
---|---|---|---|
2 | 2 | ||
3 | The following changes since commit 3757b0d08b399c609954cf57f273b1167e5d7a8d: | 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 tag 'pull-request-2022-05-18' of https://gitlab.com/thuth/qemu into staging (2022-05-20 08:04:30 -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-20220525 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528 |
10 | 8 | ||
11 | for you to fetch changes up to 8fe63fe8e512d77583d6798acd2164f1fa1e40ab: | 9 | for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393: |
12 | 10 | ||
13 | hw/core: loader: Set is_linux to true for VxWorks uImage (2022-05-24 10:38:50 +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 7.1 | 14 | RISC-V PR for 9.1 |
17 | 15 | ||
18 | * Fixes for accessing VS hypervisor CSRs | 16 | * APLICs add child earlier than realize |
19 | * Improvements for RISC-V Vector extension | 17 | * Fix exposure of Zkr |
20 | * Fixes for accessing mtimecmp | 18 | * Raise exceptions on wrs.nto |
21 | * Add new short-isa-string CPU option | 19 | * Implement SBI debug console (DBCN) calls for KVM |
22 | * Improvements to RISC-V machine error handling | 20 | * Support 64-bit addresses for initrd |
23 | * Disable the "G" extension by default internally, no functional change | 21 | * Change RISCV_EXCP_SEMIHOST exception number to 63 |
24 | * Enforce floating point extension requirements | 22 | * Tolerate KVM disable ext errors |
25 | * Cleanup ISA extension checks | 23 | * Set tval in breakpoints |
26 | * Resolve redundant property accessors | 24 | * Add support for Zve32x extension |
27 | * Fix typo of mimpid cpu option | 25 | * Add support for Zve64x extension |
28 | * Improvements for virtulisation | 26 | * Relax vector register check in RISCV gdbstub |
29 | * Add zicsr/zifencei to isa_string | 27 | * Fix the element agnostic Vector function problem |
30 | * Support for VxWorks uImage | 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 | ||
31 | 43 | ||
32 | ---------------------------------------------------------------- | 44 | ---------------------------------------------------------------- |
33 | Anup Patel (4): | 45 | Alexei Filippov (1): |
34 | target/riscv: Fix csr number based privilege checking | 46 | target/riscv: do not set mtval2 for non guest-page faults |
35 | target/riscv: Fix hstatus.GVA bit setting for traps taken from HS-mode | ||
36 | target/riscv: Set [m|s]tval for both illegal and virtual instruction traps | ||
37 | hw/riscv: virt: Fix interrupt parent for dynamic platform devices | ||
38 | 47 | ||
39 | Atish Patra (1): | 48 | Alistair Francis (2): |
40 | hw/intc: Pass correct hartid while updating mtimecmp | 49 | target/riscv: rvzicbo: Fixup CBO extension register calculation |
50 | disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs | ||
41 | 51 | ||
42 | Bernhard Beschow (2): | 52 | Andrew Jones (2): |
43 | hw/vfio/pci-quirks: Resolve redundant property getters | 53 | target/riscv/kvm: Fix exposure of Zkr |
44 | hw/riscv/sifive_u: Resolve redundant property accessors | 54 | target/riscv: Raise exceptions on wrs.nto |
45 | 55 | ||
46 | Bin Meng (2): | 56 | Cheng Yang (1): |
47 | hw/core: Sync uboot_image.h from U-Boot v2022.01 | 57 | hw/riscv/boot.c: Support 64-bit address for initrd |
48 | hw/core: loader: Set is_linux to true for VxWorks uImage | ||
49 | 58 | ||
50 | Dylan Reid (1): | 59 | Christoph Müllner (1): |
51 | target/riscv: Fix VS mode hypervisor CSR access | 60 | riscv: thead: Add th.sxstatus CSR emulation |
52 | 61 | ||
53 | Frank Chang (1): | 62 | Clément Léger (1): |
54 | target/riscv: Fix typo of mimpid cpu option | 63 | target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63 |
55 | 64 | ||
56 | Hongren (Zenithal) Zheng (1): | 65 | Daniel Henrique Barboza (6): |
57 | target/riscv: add zicsr/zifencei to isa_string | 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() | ||
58 | 72 | ||
59 | Tsukasa OI (9): | 73 | Huang Tao (2): |
60 | target/riscv: Move Zhinx* extensions on ISA string | 74 | target/riscv: Fix the element agnostic function problem |
61 | target/riscv: Add short-isa-string option | 75 | target/riscv: Implement dynamic establishment of custom decoder |
62 | hw/riscv: Make CPU config error handling generous (virt/spike) | ||
63 | hw/riscv: Make CPU config error handling generous (sifive_e/u/opentitan) | ||
64 | target/riscv: Fix coding style on "G" expansion | ||
65 | target/riscv: Disable "G" by default | ||
66 | target/riscv: Change "G" expansion | ||
67 | target/riscv: FP extension requirements | ||
68 | target/riscv: Move/refactor ISA extension checks | ||
69 | 76 | ||
70 | Weiwei Li (1): | 77 | Jason Chien (3): |
71 | target/riscv: check 'I' and 'E' after checking 'G' in riscv_cpu_realize | 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 | ||
72 | 81 | ||
73 | eopXD (1): | 82 | Max Chou (4): |
74 | target/riscv: rvv: Fix early exit condition for whole register load/store | 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 | ||
75 | 87 | ||
76 | hw/core/uboot_image.h | 213 +++++++++++++++++++++----------- | 88 | Rob Bradford (1): |
77 | target/riscv/cpu.h | 12 +- | 89 | target/riscv: Remove experimental prefix from "B" extension |
78 | hw/core/loader.c | 15 +++ | 90 | |
79 | hw/intc/riscv_aclint.c | 3 +- | 91 | Yangyu Chen (1): |
80 | hw/riscv/opentitan.c | 2 +- | 92 | target/riscv/cpu.c: fix Zvkb extension config |
81 | hw/riscv/sifive_e.c | 2 +- | 93 | |
82 | hw/riscv/sifive_u.c | 28 +---- | 94 | Yong-Xuan Wang (1): |
83 | hw/riscv/spike.c | 2 +- | 95 | target/riscv/kvm.c: Fix the hart bit setting of AIA |
84 | hw/riscv/virt.c | 27 ++-- | 96 | |
85 | hw/vfio/pci-quirks.c | 34 ++--- | 97 | Yu-Ming Chang (1): |
86 | target/riscv/cpu.c | 91 ++++++++++---- | 98 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR |
87 | target/riscv/cpu_helper.c | 4 +- | 99 | |
88 | target/riscv/csr.c | 26 ++-- | 100 | yang.zhang (1): |
89 | target/riscv/translate.c | 17 ++- | 101 | hw/intc/riscv_aplic: APLICs should add child earlier than realize |
90 | target/riscv/insn_trans/trans_rvv.c.inc | 58 +++++---- | 102 | |
91 | 15 files changed, 325 insertions(+), 209 deletions(-) | 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: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: "yang.zhang" <yang.zhang@hexintek.com> |
---|---|---|---|
2 | 2 | ||
3 | On ISA version 20190608 or later, "G" expands to "IMAFD_Zicsr_Zifencei". | 3 | Since only root APLICs can have hw IRQ lines, aplic->parent should |
4 | Both "Zicsr" and "Zifencei" are enabled by default and "G" is supposed to | 4 | be initialized first. |
5 | be (virtually) enabled as well, it should be safe to change its expansion. | ||
6 | 5 | ||
7 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | 6 | Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation") |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Message-Id: <d1b5be550a2893a0fd32c928f832d2ff7bfafe35.1652583332.git.research_trasio@irq.a4lg.com> | 8 | Signed-off-by: yang.zhang <yang.zhang@hexintek.com> |
9 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
10 | Message-ID: <20240409014445.278-1-gaoshanliukou@163.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 12 | --- |
12 | target/riscv/cpu.c | 7 +++++-- | 13 | hw/intc/riscv_aplic.c | 8 ++++---- |
13 | 1 file changed, 5 insertions(+), 2 deletions(-) | 14 | 1 file changed, 4 insertions(+), 4 deletions(-) |
14 | 15 | ||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 16 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu.c | 18 | --- a/hw/intc/riscv_aplic.c |
18 | +++ b/target/riscv/cpu.c | 19 | +++ b/hw/intc/riscv_aplic.c |
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 20 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
20 | 21 | qdev_prop_set_bit(dev, "msimode", msimode); | |
21 | if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && | 22 | qdev_prop_set_bit(dev, "mmode", mmode); |
22 | cpu->cfg.ext_a && cpu->cfg.ext_f && | 23 | |
23 | - cpu->cfg.ext_d)) { | 24 | + if (parent) { |
24 | - warn_report("Setting G will also set IMAFD"); | 25 | + riscv_aplic_add_child(parent, dev); |
25 | + cpu->cfg.ext_d && | 26 | + } |
26 | + cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { | 27 | + |
27 | + warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | 28 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
28 | cpu->cfg.ext_i = true; | 29 | |
29 | cpu->cfg.ext_m = true; | 30 | if (!is_kvm_aia(msimode)) { |
30 | cpu->cfg.ext_a = true; | 31 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); |
31 | cpu->cfg.ext_f = true; | 32 | } |
32 | cpu->cfg.ext_d = true; | 33 | |
33 | + cpu->cfg.ext_icsr = true; | 34 | - if (parent) { |
34 | + cpu->cfg.ext_ifencei = true; | 35 | - riscv_aplic_add_child(parent, dev); |
35 | } | 36 | - } |
36 | 37 | - | |
37 | if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || | 38 | if (!msimode) { |
39 | for (i = 0; i < num_harts; i++) { | ||
40 | CPUState *cpu = cpu_by_arch_id(hartid_base + i); | ||
38 | -- | 41 | -- |
39 | 2.35.3 | 42 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Dylan Reid <dylan@rivosinc.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | VS mode access to hypervisor CSRs should generate virtual, not illegal, | 3 | The Zkr extension may only be exposed to KVM guests if the VMM |
4 | instruction exceptions. | 4 | implements the SEED CSR. Use the same implementation as TCG. |
5 | 5 | ||
6 | Don't return early and indicate an illegal instruction exception when | 6 | Without this patch, running with a KVM which does not forward the |
7 | accessing a hypervisor CSR from VS mode. Instead, fall through to the | 7 | SEED CSR access to QEMU will result in an ILL exception being |
8 | `hmode` predicate to return the correct virtual instruction exception. | 8 | injected into the guest (this results in Linux guests crashing on |
9 | boot). And, when running with a KVM which does forward the access, | ||
10 | QEMU will crash, since QEMU doesn't know what to do with the exit. | ||
9 | 11 | ||
10 | Signed-off-by: Dylan Reid <dgreid@rivosinc.com> | 12 | Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8") |
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
12 | Message-Id: <20220506165456.297058-1-dgreid@rivosinc.com> | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
15 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
16 | Message-ID: <20240422134605.534207-2-ajones@ventanamicro.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 18 | --- |
15 | target/riscv/csr.c | 10 +++++----- | 19 | target/riscv/cpu.h | 3 +++ |
16 | 1 file changed, 5 insertions(+), 5 deletions(-) | 20 | target/riscv/csr.c | 18 ++++++++++++++---- |
21 | target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++ | ||
22 | 3 files changed, 42 insertions(+), 4 deletions(-) | ||
17 | 23 | ||
24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/riscv/cpu.h | ||
27 | +++ b/target/riscv/cpu.h | ||
28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); | ||
29 | |||
30 | void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); | ||
31 | |||
32 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | ||
33 | + target_ulong write_mask); | ||
34 | + | ||
35 | uint8_t satp_mode_max_from_map(uint32_t map); | ||
36 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); | ||
37 | |||
18 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 38 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
19 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/csr.c | 40 | --- a/target/riscv/csr.c |
21 | +++ b/target/riscv/csr.c | 41 | +++ b/target/riscv/csr.c |
22 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | 42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, |
23 | #if !defined(CONFIG_USER_ONLY) | 43 | #endif |
24 | int effective_priv = env->priv; | 44 | |
25 | 45 | /* Crypto Extension */ | |
26 | - if (riscv_has_ext(env, RVH) && | 46 | -static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
27 | - env->priv == PRV_S && | 47 | - target_ulong *ret_value, |
28 | - !riscv_cpu_virt_enabled(env)) { | 48 | - target_ulong new_value, |
29 | + if (riscv_has_ext(env, RVH) && env->priv == PRV_S) { | 49 | - target_ulong write_mask) |
30 | /* | 50 | +target_ulong riscv_new_csr_seed(target_ulong new_value, |
31 | - * We are in S mode without virtualisation, therefore we are in HS Mode. | 51 | + target_ulong write_mask) |
32 | + * We are in either HS or VS mode. | 52 | { |
33 | * Add 1 to the effective privledge level to allow us to access the | 53 | uint16_t random_v; |
34 | - * Hypervisor CSRs. | 54 | Error *random_e = NULL; |
35 | + * Hypervisor CSRs. The `hmode` predicate will determine if access | 55 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
36 | + * should be allowed(HS) or if a virtual instruction exception should be | 56 | rval = random_v | SEED_OPST_ES16; |
37 | + * raised(VS). | ||
38 | */ | ||
39 | effective_priv++; | ||
40 | } | 57 | } |
58 | |||
59 | + return rval; | ||
60 | +} | ||
61 | + | ||
62 | +static RISCVException rmw_seed(CPURISCVState *env, int csrno, | ||
63 | + target_ulong *ret_value, | ||
64 | + target_ulong new_value, | ||
65 | + target_ulong write_mask) | ||
66 | +{ | ||
67 | + target_ulong rval; | ||
68 | + | ||
69 | + rval = riscv_new_csr_seed(new_value, write_mask); | ||
70 | + | ||
71 | if (ret_value) { | ||
72 | *ret_value = rval; | ||
73 | } | ||
74 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
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; | ||
99 | + } | ||
100 | + | ||
101 | + return ret; | ||
102 | +} | ||
103 | + | ||
104 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
105 | { | ||
106 | int ret = 0; | ||
107 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
108 | case KVM_EXIT_RISCV_SBI: | ||
109 | ret = kvm_riscv_handle_sbi(cs, run); | ||
110 | break; | ||
111 | + case KVM_EXIT_RISCV_CSR: | ||
112 | + ret = kvm_riscv_handle_csr(cs, run); | ||
113 | + break; | ||
114 | default: | ||
115 | qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", | ||
116 | __func__, run->exit_reason); | ||
41 | -- | 117 | -- |
42 | 2.35.3 | 118 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Anup Patel <apatel@ventanamicro.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | When both APLIC and IMSIC are present in virt machine, the APLIC should | 3 | Implementing wrs.nto to always just return is consistent with the |
4 | be used as parent interrupt controller for dynamic platform devices. | 4 | specification, as the instruction is permitted to terminate the |
5 | stall for any reason, but it's not useful for virtualization, where | ||
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. | ||
5 | 13 | ||
6 | In case of multiple sockets, we should prefer interrupt controller of | 14 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
7 | socket0 for dynamic platform devices. | 15 | Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu> |
8 | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
9 | Fixes: 3029fab64309 ("hw/riscv: virt: Add support for generating | ||
10 | platform FDT entries") | ||
11 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Message-Id: <20220511144528.393530-9-apatel@ventanamicro.com> | 18 | Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com> |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 20 | --- |
16 | hw/riscv/virt.c | 25 ++++++++++++------------- | 21 | target/riscv/helper.h | 1 + |
17 | 1 file changed, 12 insertions(+), 13 deletions(-) | 22 | target/riscv/op_helper.c | 11 ++++++++ |
23 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++------- | ||
24 | 3 files changed, 32 insertions(+), 9 deletions(-) | ||
18 | 25 | ||
19 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 26 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
20 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/riscv/virt.c | 28 | --- a/target/riscv/helper.h |
22 | +++ b/hw/riscv/virt.c | 29 | +++ b/target/riscv/helper.h |
23 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s, | 30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) |
24 | qemu_fdt_setprop_cell(mc->fdt, plic_name, "phandle", | 31 | DEF_HELPER_1(sret, tl, env) |
25 | plic_phandles[socket]); | 32 | DEF_HELPER_1(mret, tl, env) |
26 | 33 | DEF_HELPER_1(wfi, void, env) | |
27 | - platform_bus_add_all_fdt_nodes(mc->fdt, plic_name, | 34 | +DEF_HELPER_1(wrs_nto, void, env) |
28 | - memmap[VIRT_PLATFORM_BUS].base, | 35 | DEF_HELPER_1(tlb_flush, void, env) |
29 | - memmap[VIRT_PLATFORM_BUS].size, | 36 | DEF_HELPER_1(tlb_flush_all, void, env) |
30 | - VIRT_PLATFORM_BUS_IRQ); | 37 | /* Native Debug */ |
31 | + if (!socket) { | 38 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
32 | + platform_bus_add_all_fdt_nodes(mc->fdt, plic_name, | 39 | index XXXXXXX..XXXXXXX 100644 |
33 | + memmap[VIRT_PLATFORM_BUS].base, | 40 | --- a/target/riscv/op_helper.c |
34 | + memmap[VIRT_PLATFORM_BUS].size, | 41 | +++ b/target/riscv/op_helper.c |
35 | + VIRT_PLATFORM_BUS_IRQ); | 42 | @@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env) |
43 | } | ||
44 | } | ||
45 | |||
46 | +void helper_wrs_nto(CPURISCVState *env) | ||
47 | +{ | ||
48 | + if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) && | ||
49 | + get_field(env->hstatus, HSTATUS_VTW) && | ||
50 | + !get_field(env->mstatus, MSTATUS_TW)) { | ||
51 | + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); | ||
52 | + } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) { | ||
53 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
36 | + } | 54 | + } |
37 | 55 | +} | |
38 | g_free(plic_name); | 56 | + |
39 | 57 | void helper_tlb_flush(CPURISCVState *env) | |
40 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, | 58 | { |
41 | } | 59 | CPUState *cs = env_cpu(env); |
42 | qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_m_phandle); | 60 | diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc |
43 | 61 | index XXXXXXX..XXXXXXX 100644 | |
44 | - platform_bus_add_all_fdt_nodes(mc->fdt, imsic_name, | 62 | --- a/target/riscv/insn_trans/trans_rvzawrs.c.inc |
45 | - memmap[VIRT_PLATFORM_BUS].base, | 63 | +++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc |
46 | - memmap[VIRT_PLATFORM_BUS].size, | 64 | @@ -XXX,XX +XXX,XX @@ |
47 | - VIRT_PLATFORM_BUS_IRQ); | 65 | * this program. If not, see <http://www.gnu.org/licenses/>. |
48 | - | 66 | */ |
49 | g_free(imsic_name); | 67 | |
50 | 68 | -static bool trans_wrs(DisasContext *ctx) | |
51 | /* S-level IMSIC node */ | 69 | +static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a) |
52 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | 70 | { |
53 | riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); | 71 | if (!ctx->cfg_ptr->ext_zawrs) { |
54 | qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle); | 72 | return false; |
55 | 73 | @@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx) | |
56 | - platform_bus_add_all_fdt_nodes(mc->fdt, aplic_name, | 74 | return true; |
57 | - memmap[VIRT_PLATFORM_BUS].base, | 75 | } |
58 | - memmap[VIRT_PLATFORM_BUS].size, | 76 | |
59 | - VIRT_PLATFORM_BUS_IRQ); | 77 | -#define GEN_TRANS_WRS(insn) \ |
60 | + if (!socket) { | 78 | -static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ |
61 | + platform_bus_add_all_fdt_nodes(mc->fdt, aplic_name, | 79 | -{ \ |
62 | + memmap[VIRT_PLATFORM_BUS].base, | 80 | - (void)a; \ |
63 | + memmap[VIRT_PLATFORM_BUS].size, | 81 | - return trans_wrs(ctx); \ |
64 | + VIRT_PLATFORM_BUS_IRQ); | 82 | -} |
83 | +static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a) | ||
84 | +{ | ||
85 | + if (!ctx->cfg_ptr->ext_zawrs) { | ||
86 | + return false; | ||
65 | + } | 87 | + } |
66 | 88 | ||
67 | g_free(aplic_name); | 89 | -GEN_TRANS_WRS(wrs_nto) |
68 | 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 | ||
101 | + | ||
102 | + /* We only get here when helper_wrs_nto() doesn't raise an exception. */ | ||
103 | + return trans_wrs_sto(ctx, NULL); | ||
104 | +} | ||
69 | -- | 105 | -- |
70 | 2.35.3 | 106 | 2.45.1 |
107 | |||
108 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
2 | |||
3 | SBI defines a Debug Console extension "DBCN" that will, in time, replace | ||
4 | the legacy console putchar and getchar SBI extensions. | ||
5 | |||
6 | The appeal of the DBCN extension is that it allows multiple bytes to be | ||
7 | read/written in the SBI console in a single SBI call. | ||
8 | |||
9 | As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM | ||
10 | module to userspace. But this will only happens if the KVM module | ||
11 | actually supports this SBI extension and we activate it. | ||
12 | |||
13 | We'll check for DBCN support during init time, checking if get-reg-list | ||
14 | is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via | ||
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> | ||
29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
30 | --- | ||
31 | target/riscv/sbi_ecall_interface.h | 17 +++++ | ||
32 | target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++ | ||
33 | 2 files changed, 128 insertions(+) | ||
34 | |||
35 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/riscv/sbi_ecall_interface.h | ||
38 | +++ b/target/riscv/sbi_ecall_interface.h | ||
39 | @@ -XXX,XX +XXX,XX @@ | ||
40 | |||
41 | /* clang-format off */ | ||
42 | |||
43 | +#define SBI_SUCCESS 0 | ||
44 | +#define SBI_ERR_FAILED -1 | ||
45 | +#define SBI_ERR_NOT_SUPPORTED -2 | ||
46 | +#define SBI_ERR_INVALID_PARAM -3 | ||
47 | +#define SBI_ERR_DENIED -4 | ||
48 | +#define SBI_ERR_INVALID_ADDRESS -5 | ||
49 | +#define SBI_ERR_ALREADY_AVAILABLE -6 | ||
50 | +#define SBI_ERR_ALREADY_STARTED -7 | ||
51 | +#define SBI_ERR_ALREADY_STOPPED -8 | ||
52 | +#define SBI_ERR_NO_SHMEM -9 | ||
53 | + | ||
54 | /* SBI Extension IDs */ | ||
55 | #define SBI_EXT_0_1_SET_TIMER 0x0 | ||
56 | #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | #define SBI_EXT_IPI 0x735049 | ||
59 | #define SBI_EXT_RFENCE 0x52464E43 | ||
60 | #define SBI_EXT_HSM 0x48534D | ||
61 | +#define SBI_EXT_DBCN 0x4442434E | ||
62 | |||
63 | /* SBI function IDs for BASE extension */ | ||
64 | #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 | ||
65 | @@ -XXX,XX +XXX,XX @@ | ||
66 | #define SBI_EXT_HSM_HART_STOP 0x1 | ||
67 | #define SBI_EXT_HSM_HART_GET_STATUS 0x2 | ||
68 | |||
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 | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/target/riscv/kvm/kvm-cpu.c | ||
80 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
81 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = { | ||
82 | KVM_REG_RISCV_VECTOR_CSR_REG(vlenb) | ||
83 | }; | ||
84 | |||
85 | +static KVMCPUConfig kvm_sbi_dbcn = { | ||
86 | + .name = "sbi_dbcn", | ||
87 | + .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 | | ||
88 | + KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN | ||
89 | +}; | ||
90 | + | ||
91 | static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) | ||
92 | { | ||
93 | CPURISCVState *env = &cpu->env; | ||
94 | @@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b) | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | +static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu, | ||
99 | + KVMScratchCPU *kvmcpu, | ||
100 | + struct kvm_reg_list *reglist) | ||
101 | +{ | ||
102 | + struct kvm_reg_list *reg_search; | ||
103 | + | ||
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 | + } | ||
110 | +} | ||
111 | + | ||
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) | ||
129 | +{ | ||
130 | + target_ulong reg = 1; | ||
131 | + | ||
132 | + if (!kvm_sbi_dbcn.supported) { | ||
133 | + return 0; | ||
134 | + } | ||
135 | + | ||
136 | + return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, ®); | ||
137 | +} | ||
138 | + | ||
139 | int kvm_arch_init_vcpu(CPUState *cs) | ||
140 | { | ||
141 | int ret = 0; | ||
142 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
143 | kvm_riscv_update_cpu_misa_ext(cpu, cs); | ||
144 | kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs); | ||
145 | |||
146 | + ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs); | ||
147 | + | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) | ||
152 | return true; | ||
153 | } | ||
154 | |||
155 | +static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run) | ||
156 | +{ | ||
157 | + g_autofree uint8_t *buf = NULL; | ||
158 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
159 | + target_ulong num_bytes; | ||
160 | + uint64_t addr; | ||
161 | + unsigned char ch; | ||
162 | + int ret; | ||
163 | + | ||
164 | + switch (run->riscv_sbi.function_id) { | ||
165 | + case SBI_EXT_DBCN_CONSOLE_READ: | ||
166 | + case SBI_EXT_DBCN_CONSOLE_WRITE: | ||
167 | + num_bytes = run->riscv_sbi.args[0]; | ||
168 | + | ||
169 | + if (num_bytes == 0) { | ||
170 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
171 | + run->riscv_sbi.ret[1] = 0; | ||
172 | + break; | ||
173 | + } | ||
174 | + | ||
175 | + addr = run->riscv_sbi.args[1]; | ||
176 | + | ||
177 | + /* | ||
178 | + * Handle the case where a 32 bit CPU is running in a | ||
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", | ||
241 | -- | ||
242 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Cheng Yang <yangcheng.work@foxmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Because ext_? members are boolean variables, operator `&&' should be | 3 | Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell() |
4 | used instead of `&'. | 4 | to set the address of initrd in FDT to support 64-bit address. |
5 | 5 | ||
6 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | 6 | Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Reviewed-by: Víctor Colombo <victor.colombo@eldorado.org.br> | 8 | Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com> |
9 | Message-Id: <91633f8349253656dd08bc8dc36498a9c7538b10.1652583332.git.research_trasio@irq.a4lg.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 10 | --- |
12 | target/riscv/cpu.c | 4 ++-- | 11 | hw/riscv/boot.c | 4 ++-- |
13 | 1 file changed, 2 insertions(+), 2 deletions(-) | 12 | 1 file changed, 2 insertions(+), 2 deletions(-) |
14 | 13 | ||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.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/target/riscv/cpu.c | 16 | --- a/hw/riscv/boot.c |
18 | +++ b/target/riscv/cpu.c | 17 | +++ b/hw/riscv/boot.c |
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 18 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) |
20 | return; | 19 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ |
21 | } | 20 | if (fdt) { |
22 | 21 | end = start + size; | |
23 | - if (cpu->cfg.ext_g && !(cpu->cfg.ext_i & cpu->cfg.ext_m & | 22 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); |
24 | - cpu->cfg.ext_a & cpu->cfg.ext_f & | 23 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); |
25 | + if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && | 24 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start); |
26 | + cpu->cfg.ext_a && cpu->cfg.ext_f && | 25 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end); |
27 | cpu->cfg.ext_d)) { | 26 | } |
28 | warn_report("Setting G will also set IMAFD"); | 27 | } |
29 | cpu->cfg.ext_i = true; | 28 | |
30 | -- | 29 | -- |
31 | 2.35.3 | 30 | 2.45.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Clément Léger <cleger@rivosinc.com> | ||
1 | 2 | ||
3 | The current semihost exception number (16) is a reserved number (range | ||
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. | ||
9 | |||
10 | Signed-off-by: Clément Léger <cleger@rivosinc.com> | ||
11 | |||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-ID: <20240422135840.1959967-1-cleger@rivosinc.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | target/riscv/cpu_bits.h | 2 +- | ||
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu_bits.h | ||
22 | +++ b/target/riscv/cpu_bits.h | ||
23 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | ||
24 | RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ | ||
25 | RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ | ||
26 | RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ | ||
27 | - RISCV_EXCP_SEMIHOST = 0x10, | ||
28 | RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, | ||
29 | RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, | ||
30 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, | ||
31 | RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, | ||
32 | + RISCV_EXCP_SEMIHOST = 0x3f, | ||
33 | } RISCVException; | ||
34 | |||
35 | #define RISCV_EXCP_INT_FLAG 0x80000000 | ||
36 | -- | ||
37 | 2.45.1 | ||
38 | |||
39 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr | ||
4 | enabled, will fail with a kernel oops SIGILL right at the start. The | ||
5 | reason is that we can't expose zkr without implementing the SEED CSR. | ||
6 | Disabling zkr in the guest would be a workaround, but if the KVM doesn't | ||
7 | allow it we'll error out and never boot. | ||
8 | |||
9 | In hindsight this is too strict. If we keep proceeding, despite not | ||
10 | disabling the extension in the KVM vcpu, we'll not add the extension in | ||
11 | the riscv,isa. The guest kernel will be unaware of the extension, i.e. | ||
12 | it doesn't matter if the KVM vcpu has it enabled underneath or not. So | ||
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> | ||
34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
35 | --- | ||
36 | target/riscv/kvm/kvm-cpu.c | 12 ++++++++---- | ||
37 | 1 file changed, 8 insertions(+), 4 deletions(-) | ||
38 | |||
39 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/riscv/kvm/kvm-cpu.c | ||
42 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) | ||
44 | reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); | ||
45 | ret = kvm_set_one_reg(cs, id, ®); | ||
46 | if (ret != 0) { | ||
47 | - error_report("Unable to %s extension %s in KVM, error %d", | ||
48 | - reg ? "enable" : "disable", | ||
49 | - multi_ext_cfg->name, ret); | ||
50 | - exit(EXIT_FAILURE); | ||
51 | + if (!reg && ret == -EINVAL) { | ||
52 | + warn_report("KVM cannot disable extension %s", | ||
53 | + multi_ext_cfg->name); | ||
54 | + } else { | ||
55 | + error_report("Unable to enable extension %s in KVM, error %d", | ||
56 | + multi_ext_cfg->name, ret); | ||
57 | + exit(EXIT_FAILURE); | ||
58 | + } | ||
59 | } | ||
60 | } | ||
61 | } | ||
62 | -- | ||
63 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Anup Patel <apatel@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Currently, QEMU does not set hstatus.GVA bit for traps taken from | 3 | We're not setting (s/m)tval when triggering breakpoints of type 2 |
4 | HS-mode into HS-mode which breaks the Xvisor nested MMU test suite | 4 | (mcontrol) and 6 (mcontrol6). According to the debug spec section |
5 | on QEMU. This was working previously. | 5 | 5.7.12, "Match Control Type 6": |
6 | 6 | ||
7 | This patch updates riscv_cpu_do_interrupt() to fix the above issue. | 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." | ||
8 | 12 | ||
9 | Fixes: 86d0c457396b ("target/riscv: Fixup setting GVA") | 13 | A similar text is also found in the Debug spec section 5.7.11 w.r.t. |
10 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | 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> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-Id: <20220511144528.393530-3-apatel@ventanamicro.com> | 27 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
28 | Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 30 | --- |
15 | target/riscv/cpu_helper.c | 3 +-- | 31 | target/riscv/cpu_helper.c | 1 + |
16 | 1 file changed, 1 insertion(+), 2 deletions(-) | 32 | target/riscv/debug.c | 3 +++ |
33 | 2 files changed, 4 insertions(+) | ||
17 | 34 | ||
18 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 35 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
19 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/cpu_helper.c | 37 | --- a/target/riscv/cpu_helper.c |
21 | +++ b/target/riscv/cpu_helper.c | 38 | +++ b/target/riscv/cpu_helper.c |
22 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 39 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
23 | case RISCV_EXCP_INST_PAGE_FAULT: | 40 | tval = env->bins; |
24 | case RISCV_EXCP_LOAD_PAGE_FAULT: | ||
25 | case RISCV_EXCP_STORE_PAGE_FAULT: | ||
26 | - write_gva = true; | ||
27 | + write_gva = env->two_stage_lookup; | ||
28 | tval = env->badaddr; | ||
29 | break; | 41 | break; |
30 | case RISCV_EXCP_ILLEGAL_INST: | 42 | case RISCV_EXCP_BREAKPOINT: |
31 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 43 | + tval = env->badaddr; |
32 | /* Trap into HS mode */ | 44 | if (cs->watchpoint_hit) { |
33 | env->hstatus = set_field(env->hstatus, HSTATUS_SPV, false); | 45 | tval = cs->watchpoint_hit->hitaddr; |
34 | htval = env->guest_phys_fault_addr; | 46 | cs->watchpoint_hit = NULL; |
35 | - write_gva = false; | 47 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
36 | } | 48 | index XXXXXXX..XXXXXXX 100644 |
37 | env->hstatus = set_field(env->hstatus, HSTATUS_GVA, write_gva); | 49 | --- a/target/riscv/debug.c |
38 | } | 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 | } | ||
39 | -- | 73 | -- |
40 | 2.35.3 | 74 | 2.45.1 | diff view generated by jsdifflib |
1 | From: "Hongren (Zenithal) Zheng" <i@zenithal.me> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Zicsr/Zifencei is not in 'I' since ISA version 20190608, | 3 | Privileged spec section 4.1.9 mentions: |
4 | thus to fully express the capability of the CPU, | ||
5 | they should be exposed in isa_string. | ||
6 | 4 | ||
7 | Signed-off-by: Hongren (Zenithal) Zheng <i@zenithal.me> | 5 | "When a trap is taken into S-mode, stval is written with |
8 | Tested-by: Jiatai He <jiatai2021@iscas.ac.cn> | 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> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <YoTqwpfrodveJ7CR@Sun> | 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> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 28 | --- |
13 | target/riscv/cpu.c | 2 ++ | 29 | target/riscv/insn_trans/trans_privileged.c.inc | 2 ++ |
14 | 1 file changed, 2 insertions(+) | 30 | 1 file changed, 2 insertions(+) |
15 | 31 | ||
16 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 32 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc |
17 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/cpu.c | 34 | --- a/target/riscv/insn_trans/trans_privileged.c.inc |
19 | +++ b/target/riscv/cpu.c | 35 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) | 36 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) |
21 | * extensions by an underscore. | 37 | if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { |
22 | */ | 38 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); |
23 | struct isa_ext_data isa_edata_arr[] = { | 39 | } else { |
24 | + ISA_EDATA_ENTRY(zicsr, ext_icsr), | 40 | + tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, |
25 | + ISA_EDATA_ENTRY(zifencei, ext_ifencei), | 41 | + offsetof(CPURISCVState, badaddr)); |
26 | ISA_EDATA_ENTRY(zfh, ext_zfh), | 42 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); |
27 | ISA_EDATA_ENTRY(zfhmin, ext_zfhmin), | 43 | } |
28 | ISA_EDATA_ENTRY(zfinx, ext_zfinx), | 44 | return true; |
29 | -- | 45 | -- |
30 | 2.35.3 | 46 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | We should separate "check" and "configure" steps as possible. | 3 | Add support for Zve32x extension and replace some checks for Zve32f with |
4 | This commit separates both steps except vector/Zfinx-related checks. | 4 | Zve32x, since Zve32f depends on Zve32x. |
5 | 5 | ||
6 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | 6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
8 | Message-Id: <c3145fa37a529484cf3047c8cb9841e9effad4b0.1652583332.git.research_trasio@irq.a4lg.com> | 8 | Reviewed-by: Max Chou <max.chou@sifive.com> |
9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Message-ID: <20240328022343.6871-2-jason.chien@sifive.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 12 | --- |
11 | target/riscv/cpu.c | 31 ++++++++++++++++--------------- | 13 | target/riscv/cpu_cfg.h | 1 + |
12 | 1 file changed, 16 insertions(+), 15 deletions(-) | 14 | target/riscv/cpu.c | 2 ++ |
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(-) | ||
13 | 20 | ||
21 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu_cfg.h | ||
24 | +++ b/target/riscv/cpu_cfg.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
26 | bool ext_zhinx; | ||
27 | bool ext_zhinxmin; | ||
28 | bool ext_zve32f; | ||
29 | + bool ext_zve32x; | ||
30 | bool ext_zve64f; | ||
31 | bool ext_zve64d; | ||
32 | bool ext_zvbb; | ||
14 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu.c | 35 | --- a/target/riscv/cpu.c |
17 | +++ b/target/riscv/cpu.c | 36 | +++ b/target/riscv/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 37 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
19 | return; | 38 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), |
20 | } | 39 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), |
21 | 40 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), | |
22 | + if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { | 41 | + ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
42 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | ||
43 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | ||
44 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), | ||
45 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
46 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | ||
47 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | ||
48 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), | ||
49 | + MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
50 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
51 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
52 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
53 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
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) | ||
73 | { | ||
74 | - if (riscv_cpu_cfg(env)->ext_zve32f) { | ||
75 | + if (riscv_cpu_cfg(env)->ext_zve32x) { | ||
76 | #if !defined(CONFIG_USER_ONLY) | ||
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)) { | ||
23 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | 93 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); |
24 | + return; | 94 | + return; |
25 | + } | 95 | + } |
26 | + | 96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); |
27 | + /* Set the ISA extensions, checks should have happened above */ | ||
28 | if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || | ||
29 | cpu->cfg.ext_zhinxmin) { | ||
30 | cpu->cfg.ext_zfinx = true; | ||
31 | } | ||
32 | |||
33 | - if (cpu->cfg.ext_zfinx && !cpu->cfg.ext_icsr) { | ||
34 | - error_setg(errp, "Zfinx extension requires Zicsr"); | ||
35 | - return; | ||
36 | + if (cpu->cfg.ext_zfinx) { | ||
37 | + if (!cpu->cfg.ext_icsr) { | ||
38 | + error_setg(errp, "Zfinx extension requires Zicsr"); | ||
39 | + return; | ||
40 | + } | ||
41 | + if (cpu->cfg.ext_f) { | ||
42 | + error_setg(errp, | ||
43 | + "Zfinx cannot be supported together with F extension"); | ||
44 | + return; | ||
45 | + } | ||
46 | } | ||
47 | |||
48 | if (cpu->cfg.ext_zk) { | ||
49 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
50 | cpu->cfg.ext_zksh = true; | ||
51 | } | ||
52 | |||
53 | - /* Set the ISA extensions, checks should have happened above */ | ||
54 | if (cpu->cfg.ext_i) { | ||
55 | ext |= RVI; | ||
56 | } | ||
57 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
58 | } | ||
59 | set_vext_version(env, vext_version); | ||
60 | } | ||
61 | - if ((cpu->cfg.ext_zve32f || cpu->cfg.ext_zve64f) && !cpu->cfg.ext_f) { | ||
62 | - error_setg(errp, "Zve32f/Zve64f extension depends upon RVF."); | ||
63 | - return; | ||
64 | - } | ||
65 | if (cpu->cfg.ext_j) { | ||
66 | ext |= RVJ; | ||
67 | } | ||
68 | - if (cpu->cfg.ext_zfinx && ((ext & (RVF | RVD)) || cpu->cfg.ext_zfh || | ||
69 | - cpu->cfg.ext_zfhmin)) { | ||
70 | - error_setg(errp, | ||
71 | - "'Zfinx' cannot be supported together with 'F', 'D', 'Zfh'," | ||
72 | - " 'Zfhmin'"); | ||
73 | - return; | ||
74 | - } | ||
75 | |||
76 | set_misa(env, env->misa_mxl, ext); | ||
77 | } | 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) | ||
120 | { | ||
121 | TCGv s1, dst; | ||
122 | |||
123 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
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) | ||
129 | { | ||
130 | TCGv dst; | ||
131 | |||
132 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
133 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | ||
134 | return false; | ||
135 | } | ||
136 | |||
78 | -- | 137 | -- |
79 | 2.35.3 | 138 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | - setting ext_g will implicitly set ext_i | 3 | Add support for Zve64x extension. Enabling Zve64f enables Zve64x and |
4 | enabling Zve64x enables Zve32x according to their dependency. | ||
4 | 5 | ||
5 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107 |
6 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
8 | Message-Id: <20220518012611.6772-1-liweiwei@iscas.ac.cn> | 9 | Reviewed-by: Max Chou <max.chou@sifive.com> |
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Message-ID: <20240328022343.6871-3-jason.chien@sifive.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 13 | --- |
11 | target/riscv/cpu.c | 24 ++++++++++++------------ | 14 | target/riscv/cpu_cfg.h | 1 + |
12 | 1 file changed, 12 insertions(+), 12 deletions(-) | 15 | target/riscv/cpu.c | 2 ++ |
16 | target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------ | ||
17 | 3 files changed, 14 insertions(+), 6 deletions(-) | ||
13 | 18 | ||
19 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu_cfg.h | ||
22 | +++ b/target/riscv/cpu_cfg.h | ||
23 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
24 | bool ext_zve32x; | ||
25 | bool ext_zve64f; | ||
26 | bool ext_zve64d; | ||
27 | + bool ext_zve64x; | ||
28 | bool ext_zvbb; | ||
29 | bool ext_zvbc; | ||
30 | bool ext_zvkb; | ||
14 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu.c | 33 | --- a/target/riscv/cpu.c |
17 | +++ b/target/riscv/cpu.c | 34 | +++ b/target/riscv/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 35 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
19 | uint32_t ext = 0; | 36 | ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
20 | 37 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | |
21 | /* Do some ISA extension error checking */ | 38 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), |
22 | - if (cpu->cfg.ext_i && cpu->cfg.ext_e) { | 39 | + ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x), |
23 | - error_setg(errp, | 40 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
24 | - "I and E extensions are incompatible"); | 41 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), |
25 | - return; | 42 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), |
26 | - } | 43 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
27 | - | 44 | MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), |
28 | - if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { | 45 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), |
29 | - error_setg(errp, | 46 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), |
30 | - "Either I or E extension must be set"); | 47 | + MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false), |
31 | - return; | 48 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), |
32 | - } | 49 | MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), |
33 | - | 50 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), |
34 | if (cpu->cfg.ext_g && !(cpu->cfg.ext_i && cpu->cfg.ext_m && | 51 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
35 | cpu->cfg.ext_a && cpu->cfg.ext_f && | 52 | index XXXXXXX..XXXXXXX 100644 |
36 | cpu->cfg.ext_d && | 53 | --- a/target/riscv/tcg/tcg-cpu.c |
37 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 54 | +++ b/target/riscv/tcg/tcg-cpu.c |
38 | cpu->cfg.ext_ifencei = true; | 55 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
39 | } | 56 | |
40 | 57 | /* The Zve64d extension depends on the Zve64f extension */ | |
41 | + if (cpu->cfg.ext_i && cpu->cfg.ext_e) { | 58 | if (cpu->cfg.ext_zve64d) { |
42 | + error_setg(errp, | 59 | + if (!riscv_has_ext(env, RVD)) { |
43 | + "I and E extensions are incompatible"); | 60 | + error_setg(errp, "Zve64d/V extensions require D extension"); |
44 | + return; | 61 | + return; |
45 | + } | 62 | + } |
46 | + | 63 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); |
47 | + if (!cpu->cfg.ext_i && !cpu->cfg.ext_e) { | 64 | } |
48 | + error_setg(errp, | 65 | |
49 | + "Either I or E extension must be set"); | 66 | - /* The Zve64f extension depends on the Zve32f extension */ |
50 | + return; | 67 | + /* The Zve64f extension depends on the Zve64x and Zve32f extensions */ |
51 | + } | 68 | if (cpu->cfg.ext_zve64f) { |
52 | + | 69 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true); |
53 | if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { | 70 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); |
54 | error_setg(errp, "F extension requires Zicsr"); | 71 | } |
55 | return; | 72 | |
73 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { | ||
74 | - error_setg(errp, "Zve64d/V extensions require D extension"); | ||
75 | - return; | ||
76 | + /* The Zve64x extension depends on the Zve32x extension */ | ||
77 | + if (cpu->cfg.ext_zve64x) { | ||
78 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
79 | } | ||
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) | ||
83 | return; | ||
84 | } | ||
85 | |||
86 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
87 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { | ||
88 | error_setg( | ||
89 | errp, | ||
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 | |||
56 | -- | 95 | -- |
57 | 2.35.3 | 96 | 2.45.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Jason Chien <jason.chien@sifive.com> | ||
1 | 2 | ||
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. | ||
7 | |||
8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> | ||
9 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
10 | Reviewed-by: Max Chou <max.chou@sifive.com> | ||
11 | Message-ID: <20240328022343.6871-4-jason.chien@sifive.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/gdbstub.c | 2 +- | ||
15 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/riscv/gdbstub.c | ||
20 | +++ b/target/riscv/gdbstub.c | ||
21 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) | ||
22 | gdb_find_static_feature("riscv-32bit-fpu.xml"), | ||
23 | 0); | ||
24 | } | ||
25 | - if (env->misa_ext & RVV) { | ||
26 | + if (cpu->cfg.ext_zve32x) { | ||
27 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, | ||
28 | riscv_gdb_set_vector, | ||
29 | ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs), | ||
30 | -- | ||
31 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | QEMU allowed inconsistent configurations that made floating point | 3 | In RVV and vcrypto instructions, the masked and tail elements are set to 1s |
4 | arithmetic effectively unusable. | 4 | using vext_set_elems_1s function if the vma/vta bit is set. It is the element |
5 | agnostic policy. | ||
5 | 6 | ||
6 | This commit adds certain checks for consistent FP arithmetic: | 7 | However, this function can't deal the big endian situation. This patch fixes |
8 | the problem by adding handling of such case. | ||
7 | 9 | ||
8 | - F requires Zicsr | 10 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
9 | - Zfinx requires Zicsr | 11 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> |
10 | - Zfh/Zfhmin require F | 12 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
11 | - D requires F | 13 | Cc: qemu-stable <qemu-stable@nongnu.org> |
12 | - V requires D | 14 | Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com> |
13 | |||
14 | Because F/D/Zicsr are enabled by default (and an error will not occur unless | ||
15 | we manually disable one or more of prerequisites), this commit just enforces | ||
16 | the user to give consistent combinations. | ||
17 | |||
18 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | ||
19 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
20 | Message-Id: <00e7b1c6060dab32ac7d49813b1ca84d3eb63298.1652583332.git.research_trasio@irq.a4lg.com> | ||
21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
22 | --- | 16 | --- |
23 | target/riscv/cpu.c | 25 +++++++++++++++++++++++++ | 17 | target/riscv/vector_internals.c | 22 ++++++++++++++++++++++ |
24 | 1 file changed, 25 insertions(+) | 18 | 1 file changed, 22 insertions(+) |
25 | 19 | ||
26 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 20 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c |
27 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/riscv/cpu.c | 22 | --- a/target/riscv/vector_internals.c |
29 | +++ b/target/riscv/cpu.c | 23 | +++ b/target/riscv/vector_internals.c |
30 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 24 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, |
31 | cpu->cfg.ext_ifencei = true; | 25 | if (tot - cnt == 0) { |
32 | } | 26 | return ; |
33 | 27 | } | |
34 | + if (cpu->cfg.ext_f && !cpu->cfg.ext_icsr) { | 28 | + |
35 | + error_setg(errp, "F extension requires Zicsr"); | 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); | ||
36 | + return; | 37 | + return; |
37 | + } | 38 | + } |
38 | + | 39 | + /* |
39 | + if ((cpu->cfg.ext_zfh || cpu->cfg.ext_zfhmin) && !cpu->cfg.ext_f) { | 40 | + * Otherwise, at least cross two uint64_t blocks. |
40 | + error_setg(errp, "Zfh/Zfhmin extensions require F extension"); | 41 | + * Set first unaligned block. |
41 | + return; | 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; | ||
42 | + } | 47 | + } |
43 | + | 48 | + /* Set other 64bit aligend blocks */ |
44 | + if (cpu->cfg.ext_d && !cpu->cfg.ext_f) { | 49 | + } |
45 | + error_setg(errp, "D extension requires F extension"); | 50 | memset(base + cnt, -1, tot - cnt); |
46 | + return; | 51 | } |
47 | + } | 52 | |
48 | + | ||
49 | + if (cpu->cfg.ext_v && !cpu->cfg.ext_d) { | ||
50 | + error_setg(errp, "V extension requires D extension"); | ||
51 | + return; | ||
52 | + } | ||
53 | + | ||
54 | if (cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinx || | ||
55 | cpu->cfg.ext_zhinxmin) { | ||
56 | cpu->cfg.ext_zfinx = true; | ||
57 | } | ||
58 | |||
59 | + if (cpu->cfg.ext_zfinx && !cpu->cfg.ext_icsr) { | ||
60 | + error_setg(errp, "Zfinx extension requires Zicsr"); | ||
61 | + return; | ||
62 | + } | ||
63 | + | ||
64 | if (cpu->cfg.ext_zk) { | ||
65 | cpu->cfg.ext_zkn = true; | ||
66 | cpu->cfg.ext_zkr = true; | ||
67 | -- | 53 | -- |
68 | 2.35.3 | 54 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Yangyu Chen <cyy@cyyself.name> |
---|---|---|---|
2 | 2 | ||
3 | Because "G" virtual extension expands to "IMAFD", we cannot separately | 3 | This code has a typo that writes zvkb to zvkg, causing users can't |
4 | disable extensions like "F" or "D" without disabling "G". Because all | 4 | enable zvkb through the config. This patch gets this fixed. |
5 | "IMAFD" are enabled by default, it's harmless to disable "G" by default. | ||
6 | 5 | ||
7 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | 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> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <cab7205f1d7668f642fa242386543334af6bc1bd.1652583332.git.research_trasio@irq.a4lg.com> | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
11 | Reviewed-by: Weiwei Li <liwei1518@gmail.com> | ||
12 | Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 15 | --- |
12 | target/riscv/cpu.c | 2 +- | 16 | target/riscv/cpu.c | 2 +- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 18 | ||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
16 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu.c | 21 | --- a/target/riscv/cpu.c |
18 | +++ b/target/riscv/cpu.c | 22 | +++ b/target/riscv/cpu.c |
19 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 23 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
20 | /* Defaults for standard extensions */ | 24 | /* Vector cryptography extensions */ |
21 | DEFINE_PROP_BOOL("i", RISCVCPU, cfg.ext_i, true), | 25 | MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false), |
22 | DEFINE_PROP_BOOL("e", RISCVCPU, cfg.ext_e, false), | 26 | MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false), |
23 | - DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, true), | 27 | - MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false), |
24 | + DEFINE_PROP_BOOL("g", RISCVCPU, cfg.ext_g, false), | 28 | + MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false), |
25 | DEFINE_PROP_BOOL("m", RISCVCPU, cfg.ext_m, true), | 29 | MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false), |
26 | DEFINE_PROP_BOOL("a", RISCVCPU, cfg.ext_a, true), | 30 | MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false), |
27 | DEFINE_PROP_BOOL("f", RISCVCPU, cfg.ext_f, true), | 31 | MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false), |
28 | -- | 32 | -- |
29 | 2.35.3 | 33 | 2.45.1 |
34 | |||
35 | diff view generated by jsdifflib |
1 | From: Anup Patel <apatel@ventanamicro.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | Currently, the [m|s]tval CSRs are set with trapping instruction encoding | 3 | In this patch, we modify the decoder to be a freely composable data |
4 | only for illegal instruction traps taken at the time of instruction | 4 | structure instead of a hardcoded one. It can be dynamically builded up |
5 | decoding. | 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 | In RISC-V world, a valid instructions might also trap as illegal or | 21 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
8 | virtual instruction based to trapping bits in various CSRs (such as | 22 | Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu> |
9 | mstatus.TVM or hstatus.VTVM). | 23 | Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
10 | 24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | |
11 | We improve setting of [m|s]tval CSRs for all types of illegal and | ||
12 | virtual instruction traps. | ||
13 | |||
14 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | ||
15 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
17 | Message-Id: <20220511144528.393530-4-apatel@ventanamicro.com> | 26 | Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com> |
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 28 | --- |
20 | target/riscv/cpu.h | 8 +++++++- | 29 | target/riscv/cpu.h | 1 + |
21 | target/riscv/cpu.c | 2 ++ | 30 | target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++ |
22 | target/riscv/cpu_helper.c | 1 + | 31 | target/riscv/cpu.c | 1 + |
23 | target/riscv/translate.c | 17 +++++++++++++---- | 32 | target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++ |
24 | 4 files changed, 23 insertions(+), 5 deletions(-) | 33 | target/riscv/translate.c | 31 +++++++++++++++---------------- |
34 | 5 files changed, 47 insertions(+), 16 deletions(-) | ||
25 | 35 | ||
26 | 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 |
27 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/riscv/cpu.h | 38 | --- a/target/riscv/cpu.h |
29 | +++ b/target/riscv/cpu.h | 39 | +++ b/target/riscv/cpu.h |
30 | @@ -XXX,XX +XXX,XX @@ | 40 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
31 | 41 | uint32_t pmu_avail_ctrs; | |
32 | #define TCG_GUEST_DEFAULT_MO 0 | 42 | /* Mapping of events to counters */ |
33 | 43 | GHashTable *pmu_event_ctr_map; | |
34 | +/* | 44 | + const GPtrArray *decoders; |
35 | + * RISC-V-specific extra insn start words: | 45 | }; |
36 | + * 1: Original instruction opcode | 46 | |
37 | + */ | 47 | /** |
38 | +#define TARGET_INSN_START_EXTRA_WORDS 1 | 48 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h |
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/riscv/tcg/tcg-cpu.h | ||
51 | +++ b/target/riscv/tcg/tcg-cpu.h | ||
52 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); | ||
53 | void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp); | ||
54 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu); | ||
55 | |||
56 | +struct DisasContext; | ||
57 | +struct RISCVCPUConfig; | ||
58 | +typedef struct RISCVDecoder { | ||
59 | + bool (*guard_func)(const struct RISCVCPUConfig *); | ||
60 | + bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
61 | +} RISCVDecoder; | ||
39 | + | 62 | + |
40 | #define TYPE_RISCV_CPU "riscv-cpu" | 63 | +typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); |
41 | 64 | + | |
42 | #define RISCV_CPU_TYPE_SUFFIX "-" TYPE_RISCV_CPU | 65 | +extern const size_t decoder_table_size; |
43 | @@ -XXX,XX +XXX,XX @@ struct CPUArchState { | 66 | + |
44 | target_ulong frm; | 67 | +extern const RISCVDecoder decoder_table[]; |
45 | 68 | + | |
46 | target_ulong badaddr; | 69 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu); |
47 | - uint32_t bins; | 70 | + |
48 | + target_ulong bins; | 71 | #endif |
49 | |||
50 | target_ulong guest_phys_fault_addr; | ||
51 | |||
52 | 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 |
53 | index XXXXXXX..XXXXXXX 100644 | 73 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/target/riscv/cpu.c | 74 | --- a/target/riscv/cpu.c |
55 | +++ b/target/riscv/cpu.c | 75 | +++ b/target/riscv/cpu.c |
56 | @@ -XXX,XX +XXX,XX @@ void restore_state_to_opc(CPURISCVState *env, TranslationBlock *tb, | 76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) |
57 | } else { | 77 | error_propagate(errp, local_err); |
58 | env->pc = data[0]; | 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) | ||
59 | } | 89 | } |
60 | + env->bins = data[1]; | ||
61 | } | 90 | } |
62 | 91 | ||
63 | static void riscv_cpu_reset(DeviceState *dev) | 92 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) |
64 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | 93 | +{ |
65 | env->mcause = 0; | 94 | + GPtrArray *dynamic_decoders; |
66 | env->miclaim = MIP_SGEIP; | 95 | + dynamic_decoders = g_ptr_array_sized_new(decoder_table_size); |
67 | env->pc = env->resetvec; | 96 | + for (size_t i = 0; i < decoder_table_size; ++i) { |
68 | + env->bins = 0; | 97 | + if (decoder_table[i].guard_func && |
69 | env->two_stage_lookup = false; | 98 | + decoder_table[i].guard_func(&cpu->cfg)) { |
70 | 99 | + g_ptr_array_add(dynamic_decoders, | |
71 | /* Initialized default priorities of local interrupts. */ | 100 | + (gpointer)decoder_table[i].riscv_cpu_decode_fn); |
72 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 101 | + } |
73 | index XXXXXXX..XXXXXXX 100644 | 102 | + } |
74 | --- a/target/riscv/cpu_helper.c | 103 | + |
75 | +++ b/target/riscv/cpu_helper.c | 104 | + cpu->decoders = dynamic_decoders; |
76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 105 | +} |
77 | tval = env->badaddr; | 106 | + |
78 | break; | 107 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu) |
79 | case RISCV_EXCP_ILLEGAL_INST: | 108 | { |
80 | + case RISCV_EXCP_VIRT_INSTRUCTION_FAULT: | 109 | return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL; |
81 | tval = env->bins; | ||
82 | break; | ||
83 | default: | ||
84 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 110 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
85 | index XXXXXXX..XXXXXXX 100644 | 111 | index XXXXXXX..XXXXXXX 100644 |
86 | --- a/target/riscv/translate.c | 112 | --- a/target/riscv/translate.c |
87 | +++ b/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 */ | ||
88 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 123 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
89 | /* PointerMasking extension */ | 124 | /* FRM is known to contain a valid value. */ |
90 | bool pm_mask_enabled; | 125 | bool frm_valid; |
91 | bool pm_base_enabled; | 126 | bool insn_start_updated; |
92 | + /* TCG of the current insn_start */ | 127 | + const GPtrArray *decoders; |
93 | + TCGOp *insn_start; | ||
94 | } DisasContext; | 128 | } DisasContext; |
95 | 129 | ||
96 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) | 130 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) |
97 | @@ -XXX,XX +XXX,XX @@ static void generate_exception_mtval(DisasContext *ctx, int excp) | 131 | @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) |
98 | 132 | return (first_word & 3) == 3 ? 4 : 2; | |
99 | static void gen_exception_illegal(DisasContext *ctx) | ||
100 | { | ||
101 | - tcg_gen_st_i32(tcg_constant_i32(ctx->opcode), cpu_env, | ||
102 | - offsetof(CPURISCVState, bins)); | ||
103 | - | ||
104 | generate_exception(ctx, RISCV_EXCP_ILLEGAL_INST); | ||
105 | } | 133 | } |
106 | 134 | ||
107 | @@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) | 135 | +const RISCVDecoder decoder_table[] = { |
108 | /* Include decoders for factored-out extensions */ | 136 | + { always_true_p, decode_insn32 }, |
109 | #include "decode-XVentanaCondOps.c.inc" | 137 | + { has_xthead_p, decode_xthead}, |
110 | 138 | + { has_XVentanaCondOps_p, decode_XVentanaCodeOps}, | |
111 | +static inline void decode_save_opc(DisasContext *ctx, target_ulong opc) | 139 | +}; |
112 | +{ | 140 | + |
113 | + assert(ctx->insn_start != NULL); | 141 | +const size_t decoder_table_size = ARRAY_SIZE(decoder_table); |
114 | + tcg_set_insn_start_param(ctx->insn_start, 1, opc); | ||
115 | + ctx->insn_start = NULL; | ||
116 | +} | ||
117 | + | 142 | + |
118 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | 143 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) |
119 | { | 144 | { |
120 | /* | 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 | - }; | ||
157 | - | ||
158 | ctx->virt_inst_excp = false; | ||
159 | ctx->cur_insn_len = insn_len(opcode); | ||
160 | /* Check for compressed insn */ | ||
121 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | 161 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) |
122 | |||
123 | /* Check for compressed insn */ | ||
124 | if (extract16(opcode, 0, 2) != 3) { | ||
125 | + decode_save_opc(ctx, opcode); | ||
126 | if (!has_ext(ctx, RVC)) { | ||
127 | gen_exception_illegal(ctx); | ||
128 | } else { | ||
129 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
130 | opcode32 = deposit32(opcode32, 16, 16, | ||
131 | translator_lduw(env, &ctx->base, | ||
132 | ctx->base.pc_next + 2)); | 162 | ctx->base.pc_next + 2)); |
133 | + decode_save_opc(ctx, opcode32); | ||
134 | ctx->opcode = opcode32; | 163 | ctx->opcode = opcode32; |
135 | ctx->pc_succ_insn = ctx->base.pc_next + 4; | 164 | |
136 | 165 | - for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) { | |
137 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | 166 | - if (decoders[i].guard_func(ctx->cfg_ptr) && |
138 | { | 167 | - decoders[i].decode_func(ctx, opcode32)) { |
139 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | 168 | + for (guint i = 0; i < ctx->decoders->len; ++i) { |
140 | 169 | + riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i); | |
141 | - tcg_gen_insn_start(ctx->base.pc_next); | 170 | + if (func(ctx, opcode32)) { |
142 | + tcg_gen_insn_start(ctx->base.pc_next, 0); | 171 | return; |
143 | + ctx->insn_start = tcg_last_op(); | 172 | } |
173 | } | ||
174 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
175 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); | ||
176 | ctx->zero = tcg_constant_tl(0); | ||
177 | ctx->virt_inst_excp = false; | ||
178 | + ctx->decoders = cpu->decoders; | ||
144 | } | 179 | } |
145 | 180 | ||
146 | static void riscv_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) | 181 | static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) |
147 | -- | 182 | -- |
148 | 2.35.3 | 183 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Christoph Müllner <christoph.muellner@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | Because some operating systems don't correctly parse long ISA extension | 3 | The th.sxstatus CSR can be used to identify available custom extension |
4 | string, this commit adds short-isa-string boolean option to disable | 4 | on T-Head CPUs. The CSR is documented here: |
5 | generating long ISA extension strings on Device Tree. | 5 | https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc |
6 | 6 | ||
7 | For instance, enabling Zfinx and Zdinx extensions and booting Linux (5.17 or | 7 | An important property of this patch is, that the th.sxstatus MAEE field |
8 | earlier) with FPU support caused a kernel panic. | 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). | ||
9 | 16 | ||
10 | Operating Systems which short-isa-string might be helpful: | 17 | Further context can be found on the list: |
18 | https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html | ||
11 | 19 | ||
12 | 1. Linux (5.17 or earlier) | 20 | Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com> |
13 | 2. FreeBSD (at least 14.0-CURRENT) | 21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | 3. OpenBSD (at least current development version) | 22 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> |
15 | 23 | Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu> | |
16 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | ||
17 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
18 | Message-Id: <7c1fe5f06b0a7646a47e9bcdddb1042bb60c69c8.1652181972.git.research_trasio@irq.a4lg.com> | ||
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
20 | --- | 25 | --- |
21 | target/riscv/cpu.h | 2 ++ | 26 | MAINTAINERS | 1 + |
22 | target/riscv/cpu.c | 6 +++++- | 27 | target/riscv/cpu.h | 3 ++ |
23 | 2 files changed, 7 insertions(+), 1 deletion(-) | 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 | ||
24 | 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 | ||
25 | 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 |
26 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/target/riscv/cpu.h | 48 | --- a/target/riscv/cpu.h |
28 | +++ b/target/riscv/cpu.h | 49 | +++ b/target/riscv/cpu.h |
29 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 50 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value, |
30 | bool aia; | 51 | uint8_t satp_mode_max_from_map(uint32_t map); |
31 | bool debug; | 52 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
32 | uint64_t resetvec; | 53 | |
54 | +/* Implemented in th_csr.c */ | ||
55 | +void th_register_custom_csrs(RISCVCPU *cpu); | ||
33 | + | 56 | + |
34 | + bool short_isa_string; | 57 | #endif /* RISCV_CPU_H */ |
35 | }; | ||
36 | |||
37 | typedef struct RISCVCPUConfig RISCVCPUConfig; | ||
38 | 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 |
39 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu.c | 60 | --- a/target/riscv/cpu.c |
41 | +++ b/target/riscv/cpu.c | 61 | +++ b/target/riscv/cpu.c |
42 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 62 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) |
43 | DEFINE_PROP_BOOL("x-aia", RISCVCPU, cfg.aia, false), | 63 | cpu->cfg.mvendorid = THEAD_VENDOR_ID; |
44 | 64 | #ifndef CONFIG_USER_ONLY | |
45 | DEFINE_PROP_UINT64("resetvec", RISCVCPU, cfg.resetvec, DEFAULT_RSTVEC), | 65 | set_satp_mode_max_supported(cpu, VM_1_10_SV39); |
66 | + th_register_custom_csrs(cpu); | ||
67 | #endif | ||
68 | |||
69 | /* inherited from parent obj via riscv_cpu_init() */ | ||
70 | diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c | ||
71 | new file mode 100644 | ||
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 | + */ | ||
46 | + | 93 | + |
47 | + DEFINE_PROP_BOOL("short-isa-string", RISCVCPU, cfg.short_isa_string, false), | 94 | +#include "qemu/osdep.h" |
48 | DEFINE_PROP_END_OF_LIST(), | 95 | +#include "cpu.h" |
49 | }; | 96 | +#include "cpu_vendorid.h" |
50 | 97 | + | |
51 | @@ -XXX,XX +XXX,XX @@ char *riscv_isa_string(RISCVCPU *cpu) | 98 | +#define CSR_TH_SXSTATUS 0x5c0 |
52 | } | 99 | + |
53 | } | 100 | +/* TH_SXSTATUS bits */ |
54 | *p = '\0'; | 101 | +#define TH_SXSTATUS_UCME BIT(16) |
55 | - riscv_isa_string_ext(cpu, &isa_str, maxlen); | 102 | +#define TH_SXSTATUS_MAEE BIT(21) |
56 | + if (!cpu->cfg.short_isa_string) { | 103 | +#define TH_SXSTATUS_THEADISAEE BIT(22) |
57 | + riscv_isa_string_ext(cpu, &isa_str, maxlen); | 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; | ||
58 | + } | 115 | + } |
59 | return isa_str; | 116 | + |
60 | } | 117 | + return RISCV_EXCP_ILLEGAL_INST; |
61 | 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 | )) | ||
62 | -- | 167 | -- |
63 | 2.35.3 | 168 | 2.45.1 |
169 | |||
170 | diff view generated by jsdifflib |
1 | From: Bernhard Beschow <shentey@gmail.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The QOM API already provides getters for uint64 and uint32 values, so reuse | 3 | According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w |
4 | them. | 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: Bernhard Beschow <shentey@gmail.com> | 8 | * From 1*SEW(16/32) to 2*SEW(32/64) |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | * From 2*SEW(32/64) to 1*SEW(16/32) |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 10 | |
9 | Message-Id: <20220301225220.239065-2-shentey@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/vfio/pci-quirks.c | 34 +++++++++------------------------- | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++-- |
13 | 1 file changed, 9 insertions(+), 25 deletions(-) | 18 | 1 file changed, 18 insertions(+), 2 deletions(-) |
14 | 19 | ||
15 | diff --git a/hw/vfio/pci-quirks.c b/hw/vfio/pci-quirks.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/vfio/pci-quirks.c | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
18 | +++ b/hw/vfio/pci-quirks.c | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
19 | @@ -XXX,XX +XXX,XX @@ static int vfio_add_nv_gpudirect_cap(VFIOPCIDevice *vdev, Error **errp) | 24 | @@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s) |
20 | return 0; | 25 | } |
21 | } | 26 | } |
22 | 27 | ||
23 | -static void vfio_pci_nvlink2_get_tgt(Object *obj, Visitor *v, | 28 | +static bool require_rvfmin(DisasContext *s) |
24 | - const char *name, | 29 | +{ |
25 | - void *opaque, Error **errp) | 30 | + if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
26 | -{ | 31 | + return false; |
27 | - uint64_t tgt = (uintptr_t) opaque; | 32 | + } |
28 | - visit_type_uint64(v, name, &tgt, errp); | 33 | + |
29 | -} | 34 | + switch (s->sew) { |
30 | - | 35 | + case MO_16: |
31 | -static void vfio_pci_nvlink2_get_link_speed(Object *obj, Visitor *v, | 36 | + return s->cfg_ptr->ext_zvfhmin; |
32 | - const char *name, | 37 | + case MO_32: |
33 | - void *opaque, Error **errp) | 38 | + return s->cfg_ptr->ext_zve32f; |
34 | -{ | 39 | + default: |
35 | - uint32_t link_speed = (uint32_t)(uintptr_t) opaque; | 40 | + return false; |
36 | - visit_type_uint32(v, name, &link_speed, errp); | 41 | + } |
37 | -} | 42 | +} |
38 | - | 43 | + |
39 | int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp) | 44 | static bool require_scale_rvf(DisasContext *s) |
40 | { | 45 | { |
41 | int ret; | 46 | if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
42 | @@ -XXX,XX +XXX,XX @@ int vfio_pci_nvidia_v100_ram_init(VFIOPCIDevice *vdev, Error **errp) | 47 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s) |
43 | nv2reg->size, p); | ||
44 | QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next); | ||
45 | |||
46 | - object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64", | ||
47 | - vfio_pci_nvlink2_get_tgt, NULL, NULL, | ||
48 | - (void *) (uintptr_t) cap->tgt); | ||
49 | + object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt", | ||
50 | + (uint64_t *) &cap->tgt, | ||
51 | + OBJ_PROP_FLAG_READ); | ||
52 | trace_vfio_pci_nvidia_gpu_setup_quirk(vdev->vbasedev.name, cap->tgt, | ||
53 | nv2reg->size); | ||
54 | free_exit: | ||
55 | @@ -XXX,XX +XXX,XX @@ int vfio_pci_nvlink2_init(VFIOPCIDevice *vdev, Error **errp) | ||
56 | QLIST_INSERT_HEAD(&vdev->bars[0].quirks, quirk, next); | ||
57 | } | 48 | } |
58 | 49 | ||
59 | - object_property_add(OBJECT(vdev), "nvlink2-tgt", "uint64", | 50 | switch (s->sew) { |
60 | - vfio_pci_nvlink2_get_tgt, NULL, NULL, | 51 | - case MO_8: |
61 | - (void *) (uintptr_t) captgt->tgt); | 52 | - return s->cfg_ptr->ext_zvfhmin; |
62 | + object_property_add_uint64_ptr(OBJECT(vdev), "nvlink2-tgt", | 53 | case MO_16: |
63 | + (uint64_t *) &captgt->tgt, | 54 | return s->cfg_ptr->ext_zve32f; |
64 | + OBJ_PROP_FLAG_READ); | 55 | case MO_32: |
65 | trace_vfio_pci_nvlink2_setup_quirk_ssatgt(vdev->vbasedev.name, captgt->tgt, | 56 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) |
66 | atsdreg->size); | 57 | static bool opffv_widen_check(DisasContext *s, arg_rmr *a) |
67 | 58 | { | |
68 | - object_property_add(OBJECT(vdev), "nvlink2-link-speed", "uint32", | 59 | return opfv_widen_check(s, a) && |
69 | - vfio_pci_nvlink2_get_link_speed, NULL, NULL, | 60 | + require_rvfmin(s) && |
70 | - (void *) (uintptr_t) capspeed->link_speed); | 61 | require_scale_rvfmin(s) && |
71 | + object_property_add_uint32_ptr(OBJECT(vdev), "nvlink2-link-speed", | 62 | (s->sew != MO_8); |
72 | + &capspeed->link_speed, | 63 | } |
73 | + OBJ_PROP_FLAG_READ); | 64 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) |
74 | trace_vfio_pci_nvlink2_setup_quirk_lnkspd(vdev->vbasedev.name, | 65 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
75 | capspeed->link_speed); | 66 | { |
76 | free_exit: | 67 | return opfv_narrow_check(s, a) && |
68 | + require_rvfmin(s) && | ||
69 | require_scale_rvfmin(s) && | ||
70 | (s->sew != MO_8); | ||
71 | } | ||
77 | -- | 72 | -- |
78 | 2.35.3 | 73 | 2.45.1 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Max Chou <max.chou@sifive.com> | ||
1 | 2 | ||
3 | The require_scale_rvf function only checks the double width operator for | ||
4 | the vector floating point widen instructions, so most of the widen | ||
5 | checking functions need to add require_rvf for single width operator. | ||
6 | |||
7 | The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width | ||
8 | integer to double width float, so the opfxv_widen_check function doesn’t | ||
9 | need require_rvf for the single width operator(integer). | ||
10 | |||
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> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++ | ||
18 | 1 file changed, 5 insertions(+) | ||
19 | |||
20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
24 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check) | ||
25 | static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) | ||
26 | { | ||
27 | return require_rvv(s) && | ||
28 | + require_rvf(s) && | ||
29 | require_scale_rvf(s) && | ||
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) | ||
34 | { | ||
35 | return require_rvv(s) && | ||
36 | + require_rvf(s) && | ||
37 | require_scale_rvf(s) && | ||
38 | (s->sew != MO_8) && | ||
39 | vext_check_isa_ill(s) && | ||
40 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf) | ||
41 | static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
42 | { | ||
43 | return require_rvv(s) && | ||
44 | + require_rvf(s) && | ||
45 | require_scale_rvf(s) && | ||
46 | (s->sew != MO_8) && | ||
47 | vext_check_isa_ill(s) && | ||
48 | @@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv) | ||
49 | static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
50 | { | ||
51 | return require_rvv(s) && | ||
52 | + require_rvf(s) && | ||
53 | require_scale_rvf(s) && | ||
54 | (s->sew != MO_8) && | ||
55 | vext_check_isa_ill(s) && | ||
56 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) | ||
57 | static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
58 | { | ||
59 | return reduction_widen_check(s, a) && | ||
60 | + require_rvf(s) && | ||
61 | require_scale_rvf(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
64 | -- | ||
65 | 2.45.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | VxWorks 7 uses the same boot interface as the Linux kernel on Arm | 3 | The opfv_narrow_check needs to check the single width float operator by |
4 | (64-bit only), PowerPC and RISC-V architectures. Add logic to set | 4 | require_rvf. |
5 | is_linux to true for VxWorks uImage for these architectures in | ||
6 | load_uboot_image(). | ||
7 | 5 | ||
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 6 | Signed-off-by: Max Chou <max.chou@sifive.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Cc: qemu-stable <qemu-stable@nongnu.org> |
11 | Message-Id: <20220324134812.541274-2-bmeng.cn@gmail.com> | 9 | Message-ID: <20240322092600.1198921-4-max.chou@sifive.com> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 11 | --- |
14 | hw/core/loader.c | 15 +++++++++++++++ | 12 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + |
15 | 1 file changed, 15 insertions(+) | 13 | 1 file changed, 1 insertion(+) |
16 | 14 | ||
17 | diff --git a/hw/core/loader.c b/hw/core/loader.c | 15 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
18 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/core/loader.c | 17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
20 | +++ b/hw/core/loader.c | 18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
21 | @@ -XXX,XX +XXX,XX @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr, | 19 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
22 | if (is_linux) { | 20 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
23 | if (hdr->ih_os == IH_OS_LINUX) { | 21 | { |
24 | *is_linux = 1; | 22 | return opfv_narrow_check(s, a) && |
25 | + } else if (hdr->ih_os == IH_OS_VXWORKS) { | 23 | + require_rvf(s) && |
26 | + /* | 24 | require_scale_rvf(s) && |
27 | + * VxWorks 7 uses the same boot interface as the Linux kernel | 25 | (s->sew != MO_8); |
28 | + * on Arm (64-bit only), PowerPC and RISC-V architectures. | 26 | } |
29 | + */ | ||
30 | + switch (hdr->ih_arch) { | ||
31 | + case IH_ARCH_ARM64: | ||
32 | + case IH_ARCH_PPC: | ||
33 | + case IH_ARCH_RISCV: | ||
34 | + *is_linux = 1; | ||
35 | + break; | ||
36 | + default: | ||
37 | + *is_linux = 0; | ||
38 | + break; | ||
39 | + } | ||
40 | } else { | ||
41 | *is_linux = 0; | ||
42 | } | ||
43 | -- | 27 | -- |
44 | 2.35.3 | 28 | 2.45.1 | diff view generated by jsdifflib |
1 | From: eopXD <eop.chen@sifive.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Vector whole register load instructions have EEW encoded in the opcode, | 3 | If the checking functions check both the single and double width |
4 | so we shouldn't take SEW here. Vector whole register store instructions | 4 | operators at the same time, then the single width operator checking |
5 | are always EEW=8. | 5 | functions (require_rvf[min]) will check whether the SEW is 8. |
6 | 6 | ||
7 | Signed-off-by: eop Chen <eop.chen@sifive.com> | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> |
8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
10 | Message-Id: <165181414065.18540.14828125053334599921-0@git.sr.ht> | 10 | Message-ID: <20240322092600.1198921-5-max.chou@sifive.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 12 | --- |
13 | target/riscv/insn_trans/trans_rvv.c.inc | 58 +++++++++++++------------ | 13 | target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------ |
14 | 1 file changed, 31 insertions(+), 27 deletions(-) | 14 | 1 file changed, 4 insertions(+), 12 deletions(-) |
15 | 15 | ||
16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | 16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | 18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | 19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ GEN_VEXT_TRANS(vle64ff_v, MO_64, r2nfvm, ldff_op, ld_us_check) | 20 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
21 | typedef void gen_helper_ldst_whole(TCGv_ptr, TCGv, TCGv_env, TCGv_i32); | 21 | return require_rvv(s) && |
22 | 22 | require_rvf(s) && | |
23 | static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, | 23 | require_scale_rvf(s) && |
24 | - gen_helper_ldst_whole *fn, DisasContext *s, | 24 | - (s->sew != MO_8) && |
25 | - bool is_store) | 25 | vext_check_isa_ill(s) && |
26 | + uint32_t width, gen_helper_ldst_whole *fn, | 26 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); |
27 | + DisasContext *s, bool is_store) | 27 | } |
28 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
29 | return require_rvv(s) && | ||
30 | require_rvf(s) && | ||
31 | require_scale_rvf(s) && | ||
32 | - (s->sew != MO_8) && | ||
33 | vext_check_isa_ill(s) && | ||
34 | vext_check_ds(s, a->rd, a->rs2, a->vm); | ||
35 | } | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
37 | return require_rvv(s) && | ||
38 | require_rvf(s) && | ||
39 | require_scale_rvf(s) && | ||
40 | - (s->sew != MO_8) && | ||
41 | vext_check_isa_ill(s) && | ||
42 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); | ||
43 | } | ||
44 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
45 | return require_rvv(s) && | ||
46 | require_rvf(s) && | ||
47 | require_scale_rvf(s) && | ||
48 | - (s->sew != MO_8) && | ||
49 | vext_check_isa_ill(s) && | ||
50 | vext_check_dd(s, a->rd, a->rs2, a->vm); | ||
51 | } | ||
52 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
28 | { | 53 | { |
29 | - uint32_t evl = (s->cfg_ptr->vlen / 8) * nf / (1 << s->sew); | 54 | return opfv_widen_check(s, a) && |
30 | + uint32_t evl = (s->cfg_ptr->vlen / 8) * nf / width; | 55 | require_rvfmin(s) && |
31 | TCGLabel *over = gen_new_label(); | 56 | - require_scale_rvfmin(s) && |
32 | tcg_gen_brcondi_tl(TCG_COND_GEU, cpu_vstart, evl, over); | 57 | - (s->sew != MO_8); |
33 | 58 | + require_scale_rvfmin(s); | |
34 | @@ -XXX,XX +XXX,XX @@ static bool ldst_whole_trans(uint32_t vd, uint32_t rs1, uint32_t nf, | ||
35 | * load and store whole register instructions ignore vtype and vl setting. | ||
36 | * Thus, we don't need to check vill bit. (Section 7.9) | ||
37 | */ | ||
38 | -#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, IS_STORE) \ | ||
39 | +#define GEN_LDST_WHOLE_TRANS(NAME, ARG_NF, WIDTH, IS_STORE) \ | ||
40 | static bool trans_##NAME(DisasContext *s, arg_##NAME * a) \ | ||
41 | { \ | ||
42 | if (require_rvv(s) && \ | ||
43 | QEMU_IS_ALIGNED(a->rd, ARG_NF)) { \ | ||
44 | - return ldst_whole_trans(a->rd, a->rs1, ARG_NF, gen_helper_##NAME, \ | ||
45 | - s, IS_STORE); \ | ||
46 | + return ldst_whole_trans(a->rd, a->rs1, ARG_NF, WIDTH, \ | ||
47 | + gen_helper_##NAME, s, IS_STORE); \ | ||
48 | } \ | ||
49 | return false; \ | ||
50 | } | 59 | } |
51 | 60 | ||
52 | -GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, false) | 61 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ |
53 | -GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, false) | 62 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
54 | -GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, false) | 63 | { |
55 | -GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, false) | 64 | return opfv_narrow_check(s, a) && |
56 | -GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, false) | 65 | require_rvfmin(s) && |
57 | -GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, false) | 66 | - require_scale_rvfmin(s) && |
58 | -GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, false) | 67 | - (s->sew != MO_8); |
59 | -GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, false) | 68 | + require_scale_rvfmin(s); |
60 | -GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, false) | 69 | } |
61 | -GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, false) | 70 | |
62 | -GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, false) | 71 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
63 | -GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, false) | 72 | { |
64 | -GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, false) | 73 | return opfv_narrow_check(s, a) && |
65 | -GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, false) | 74 | require_rvf(s) && |
66 | -GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, false) | 75 | - require_scale_rvf(s) && |
67 | -GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, false) | 76 | - (s->sew != MO_8); |
68 | - | 77 | + require_scale_rvf(s); |
69 | -GEN_LDST_WHOLE_TRANS(vs1r_v, 1, true) | 78 | } |
70 | -GEN_LDST_WHOLE_TRANS(vs2r_v, 2, true) | 79 | |
71 | -GEN_LDST_WHOLE_TRANS(vs4r_v, 4, true) | 80 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ |
72 | -GEN_LDST_WHOLE_TRANS(vs8r_v, 8, true) | 81 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) |
73 | +GEN_LDST_WHOLE_TRANS(vl1re8_v, 1, 1, false) | 82 | { |
74 | +GEN_LDST_WHOLE_TRANS(vl1re16_v, 1, 2, false) | 83 | return reduction_widen_check(s, a) && |
75 | +GEN_LDST_WHOLE_TRANS(vl1re32_v, 1, 4, false) | 84 | require_rvf(s) && |
76 | +GEN_LDST_WHOLE_TRANS(vl1re64_v, 1, 8, false) | 85 | - require_scale_rvf(s) && |
77 | +GEN_LDST_WHOLE_TRANS(vl2re8_v, 2, 1, false) | 86 | - (s->sew != MO_8); |
78 | +GEN_LDST_WHOLE_TRANS(vl2re16_v, 2, 2, false) | 87 | + require_scale_rvf(s); |
79 | +GEN_LDST_WHOLE_TRANS(vl2re32_v, 2, 4, false) | 88 | } |
80 | +GEN_LDST_WHOLE_TRANS(vl2re64_v, 2, 8, false) | 89 | |
81 | +GEN_LDST_WHOLE_TRANS(vl4re8_v, 4, 1, false) | 90 | GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) |
82 | +GEN_LDST_WHOLE_TRANS(vl4re16_v, 4, 2, false) | ||
83 | +GEN_LDST_WHOLE_TRANS(vl4re32_v, 4, 4, false) | ||
84 | +GEN_LDST_WHOLE_TRANS(vl4re64_v, 4, 8, false) | ||
85 | +GEN_LDST_WHOLE_TRANS(vl8re8_v, 8, 1, false) | ||
86 | +GEN_LDST_WHOLE_TRANS(vl8re16_v, 8, 2, false) | ||
87 | +GEN_LDST_WHOLE_TRANS(vl8re32_v, 8, 4, false) | ||
88 | +GEN_LDST_WHOLE_TRANS(vl8re64_v, 8, 8, false) | ||
89 | + | ||
90 | +/* | ||
91 | + * The vector whole register store instructions are encoded similar to | ||
92 | + * unmasked unit-stride store of elements with EEW=8. | ||
93 | + */ | ||
94 | +GEN_LDST_WHOLE_TRANS(vs1r_v, 1, 1, true) | ||
95 | +GEN_LDST_WHOLE_TRANS(vs2r_v, 2, 1, true) | ||
96 | +GEN_LDST_WHOLE_TRANS(vs4r_v, 4, 1, true) | ||
97 | +GEN_LDST_WHOLE_TRANS(vs8r_v, 8, 1, true) | ||
98 | |||
99 | /* | ||
100 | *** Vector Integer Arithmetic Instructions | ||
101 | -- | 91 | -- |
102 | 2.35.3 | 92 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Sync uboot_image.h from upstream U-Boot v2022.01 release [1]. | 3 | raise_mmu_exception(), as is today, is prioritizing guest page faults by |
4 | checking first if virt_enabled && !first_stage, and then considering the | ||
5 | regular inst/load/store faults. | ||
4 | 6 | ||
5 | [1] https://source.denx.de/u-boot/u-boot/-/blob/v2022.01/include/image.h | 7 | There's no mention in the spec about guest page fault being a higher |
8 | priority that PMP faults. In fact, privileged spec section 3.7.1 says: | ||
6 | 9 | ||
7 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 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> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <20220324134812.541274-1-bmeng.cn@gmail.com> | 31 | Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com> |
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 34 | --- |
12 | hw/core/uboot_image.h | 213 ++++++++++++++++++++++++++++-------------- | 35 | target/riscv/cpu_helper.c | 22 ++++++++++++---------- |
13 | 1 file changed, 142 insertions(+), 71 deletions(-) | 36 | 1 file changed, 12 insertions(+), 10 deletions(-) |
14 | 37 | ||
15 | diff --git a/hw/core/uboot_image.h b/hw/core/uboot_image.h | 38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/core/uboot_image.h | 40 | --- a/target/riscv/cpu_helper.c |
18 | +++ b/hw/core/uboot_image.h | 41 | +++ b/target/riscv/cpu_helper.c |
19 | @@ -XXX,XX +XXX,XX @@ | 42 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, |
20 | +/* SPDX-License-Identifier: GPL-2.0+ */ | 43 | |
21 | /* | 44 | switch (access_type) { |
22 | + * (C) Copyright 2008 Semihalf | 45 | case MMU_INST_FETCH: |
23 | + * | 46 | - if (env->virt_enabled && !first_stage) { |
24 | * (C) Copyright 2000-2005 | 47 | + if (pmp_violation) { |
25 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | 48 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; |
26 | - * | 49 | + } else if (env->virt_enabled && !first_stage) { |
27 | - * See file CREDITS for list of people who contributed to this | 50 | cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT; |
28 | - * project. | 51 | } else { |
29 | - * | 52 | - cs->exception_index = pmp_violation ? |
30 | - * This program is free software; you can redistribute it and/or | 53 | - RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT; |
31 | - * modify it under the terms of the GNU General Public License as | 54 | + cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; |
32 | - * published by the Free Software Foundation; either version 2 of | 55 | } |
33 | - * the License, or (at your option) any later version. | 56 | break; |
34 | - * | 57 | case MMU_DATA_LOAD: |
35 | - * This program is distributed in the hope that it will be useful, | 58 | - if (two_stage && !first_stage) { |
36 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | 59 | + if (pmp_violation) { |
37 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 60 | + cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; |
38 | - * GNU General Public License for more details. | 61 | + } else if (two_stage && !first_stage) { |
39 | - * | 62 | cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT; |
40 | - * You should have received a copy of the GNU General Public License along | 63 | } else { |
41 | - * with this program; if not, see <http://www.gnu.org/licenses/>. | 64 | - cs->exception_index = pmp_violation ? |
42 | - * | 65 | - RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT; |
43 | ******************************************************************** | 66 | + cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT; |
44 | * NOTE: This header file defines an interface to U-Boot. Including | 67 | } |
45 | * this (unmodified) header file in another file is considered normal | 68 | break; |
46 | @@ -XXX,XX +XXX,XX @@ | 69 | case MMU_DATA_STORE: |
47 | 70 | - if (two_stage && !first_stage) { | |
48 | /* | 71 | + if (pmp_violation) { |
49 | * Operating System Codes | 72 | + cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; |
50 | + * | 73 | + } else if (two_stage && !first_stage) { |
51 | + * The following are exposed to uImage header. | 74 | cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; |
52 | + * New IDs *MUST* be appended at the end of the list and *NEVER* | 75 | } else { |
53 | + * inserted for backward compatibility. | 76 | - cs->exception_index = pmp_violation ? |
54 | */ | 77 | - RISCV_EXCP_STORE_AMO_ACCESS_FAULT : |
55 | -#define IH_OS_INVALID 0 /* Invalid OS */ | 78 | - RISCV_EXCP_STORE_PAGE_FAULT; |
56 | -#define IH_OS_OPENBSD 1 /* OpenBSD */ | 79 | + cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; |
57 | -#define IH_OS_NETBSD 2 /* NetBSD */ | 80 | } |
58 | -#define IH_OS_FREEBSD 3 /* FreeBSD */ | 81 | break; |
59 | -#define IH_OS_4_4BSD 4 /* 4.4BSD */ | 82 | default: |
60 | -#define IH_OS_LINUX 5 /* Linux */ | ||
61 | -#define IH_OS_SVR4 6 /* SVR4 */ | ||
62 | -#define IH_OS_ESIX 7 /* Esix */ | ||
63 | -#define IH_OS_SOLARIS 8 /* Solaris */ | ||
64 | -#define IH_OS_IRIX 9 /* Irix */ | ||
65 | -#define IH_OS_SCO 10 /* SCO */ | ||
66 | -#define IH_OS_DELL 11 /* Dell */ | ||
67 | -#define IH_OS_NCR 12 /* NCR */ | ||
68 | -#define IH_OS_LYNXOS 13 /* LynxOS */ | ||
69 | -#define IH_OS_VXWORKS 14 /* VxWorks */ | ||
70 | -#define IH_OS_PSOS 15 /* pSOS */ | ||
71 | -#define IH_OS_QNX 16 /* QNX */ | ||
72 | -#define IH_OS_U_BOOT 17 /* Firmware */ | ||
73 | -#define IH_OS_RTEMS 18 /* RTEMS */ | ||
74 | -#define IH_OS_ARTOS 19 /* ARTOS */ | ||
75 | -#define IH_OS_UNITY 20 /* Unity OS */ | ||
76 | +enum { | ||
77 | + IH_OS_INVALID = 0, /* Invalid OS */ | ||
78 | + IH_OS_OPENBSD, /* OpenBSD */ | ||
79 | + IH_OS_NETBSD, /* NetBSD */ | ||
80 | + IH_OS_FREEBSD, /* FreeBSD */ | ||
81 | + IH_OS_4_4BSD, /* 4.4BSD */ | ||
82 | + IH_OS_LINUX, /* Linux */ | ||
83 | + IH_OS_SVR4, /* SVR4 */ | ||
84 | + IH_OS_ESIX, /* Esix */ | ||
85 | + IH_OS_SOLARIS, /* Solaris */ | ||
86 | + IH_OS_IRIX, /* Irix */ | ||
87 | + IH_OS_SCO, /* SCO */ | ||
88 | + IH_OS_DELL, /* Dell */ | ||
89 | + IH_OS_NCR, /* NCR */ | ||
90 | + IH_OS_LYNXOS, /* LynxOS */ | ||
91 | + IH_OS_VXWORKS, /* VxWorks */ | ||
92 | + IH_OS_PSOS, /* pSOS */ | ||
93 | + IH_OS_QNX, /* QNX */ | ||
94 | + IH_OS_U_BOOT, /* Firmware */ | ||
95 | + IH_OS_RTEMS, /* RTEMS */ | ||
96 | + IH_OS_ARTOS, /* ARTOS */ | ||
97 | + IH_OS_UNITY, /* Unity OS */ | ||
98 | + IH_OS_INTEGRITY, /* INTEGRITY */ | ||
99 | + IH_OS_OSE, /* OSE */ | ||
100 | + IH_OS_PLAN9, /* Plan 9 */ | ||
101 | + IH_OS_OPENRTOS, /* OpenRTOS */ | ||
102 | + IH_OS_ARM_TRUSTED_FIRMWARE, /* ARM Trusted Firmware */ | ||
103 | + IH_OS_TEE, /* Trusted Execution Environment */ | ||
104 | + IH_OS_OPENSBI, /* RISC-V OpenSBI */ | ||
105 | + IH_OS_EFI, /* EFI Firmware (e.g. GRUB2) */ | ||
106 | + | ||
107 | + IH_OS_COUNT, | ||
108 | +}; | ||
109 | |||
110 | /* | ||
111 | * CPU Architecture Codes (supported by Linux) | ||
112 | + * | ||
113 | + * The following are exposed to uImage header. | ||
114 | + * New IDs *MUST* be appended at the end of the list and *NEVER* | ||
115 | + * inserted for backward compatibility. | ||
116 | */ | ||
117 | -#define IH_CPU_INVALID 0 /* Invalid CPU */ | ||
118 | -#define IH_CPU_ALPHA 1 /* Alpha */ | ||
119 | -#define IH_CPU_ARM 2 /* ARM */ | ||
120 | -#define IH_CPU_I386 3 /* Intel x86 */ | ||
121 | -#define IH_CPU_IA64 4 /* IA64 */ | ||
122 | -#define IH_CPU_MIPS 5 /* MIPS */ | ||
123 | -#define IH_CPU_MIPS64 6 /* MIPS 64 Bit */ | ||
124 | -#define IH_CPU_PPC 7 /* PowerPC */ | ||
125 | -#define IH_CPU_S390 8 /* IBM S390 */ | ||
126 | -#define IH_CPU_SH 9 /* SuperH */ | ||
127 | -#define IH_CPU_SPARC 10 /* Sparc */ | ||
128 | -#define IH_CPU_SPARC64 11 /* Sparc 64 Bit */ | ||
129 | -#define IH_CPU_M68K 12 /* M68K */ | ||
130 | -#define IH_CPU_NIOS 13 /* Nios-32 */ | ||
131 | -#define IH_CPU_MICROBLAZE 14 /* MicroBlaze */ | ||
132 | -#define IH_CPU_NIOS2 15 /* Nios-II */ | ||
133 | -#define IH_CPU_BLACKFIN 16 /* Blackfin */ | ||
134 | -#define IH_CPU_AVR32 17 /* AVR32 */ | ||
135 | +enum { | ||
136 | + IH_ARCH_INVALID = 0, /* Invalid CPU */ | ||
137 | + IH_ARCH_ALPHA, /* Alpha */ | ||
138 | + IH_ARCH_ARM, /* ARM */ | ||
139 | + IH_ARCH_I386, /* Intel x86 */ | ||
140 | + IH_ARCH_IA64, /* IA64 */ | ||
141 | + IH_ARCH_MIPS, /* MIPS */ | ||
142 | + IH_ARCH_MIPS64, /* MIPS 64 Bit */ | ||
143 | + IH_ARCH_PPC, /* PowerPC */ | ||
144 | + IH_ARCH_S390, /* IBM S390 */ | ||
145 | + IH_ARCH_SH, /* SuperH */ | ||
146 | + IH_ARCH_SPARC, /* Sparc */ | ||
147 | + IH_ARCH_SPARC64, /* Sparc 64 Bit */ | ||
148 | + IH_ARCH_M68K, /* M68K */ | ||
149 | + IH_ARCH_NIOS, /* Nios-32 */ | ||
150 | + IH_ARCH_MICROBLAZE, /* MicroBlaze */ | ||
151 | + IH_ARCH_NIOS2, /* Nios-II */ | ||
152 | + IH_ARCH_BLACKFIN, /* Blackfin */ | ||
153 | + IH_ARCH_AVR32, /* AVR32 */ | ||
154 | + IH_ARCH_ST200, /* STMicroelectronics ST200 */ | ||
155 | + IH_ARCH_SANDBOX, /* Sandbox architecture (test only) */ | ||
156 | + IH_ARCH_NDS32, /* ANDES Technology - NDS32 */ | ||
157 | + IH_ARCH_OPENRISC, /* OpenRISC 1000 */ | ||
158 | + IH_ARCH_ARM64, /* ARM64 */ | ||
159 | + IH_ARCH_ARC, /* Synopsys DesignWare ARC */ | ||
160 | + IH_ARCH_X86_64, /* AMD x86_64, Intel and Via */ | ||
161 | + IH_ARCH_XTENSA, /* Xtensa */ | ||
162 | + IH_ARCH_RISCV, /* RISC-V */ | ||
163 | + | ||
164 | + IH_ARCH_COUNT, | ||
165 | +}; | ||
166 | |||
167 | /* | ||
168 | * Image Types | ||
169 | @@ -XXX,XX +XXX,XX @@ | ||
170 | * U-Boot's command interpreter; this feature is especially | ||
171 | * useful when you configure U-Boot to use a real shell (hush) | ||
172 | * as command interpreter (=> Shell Scripts). | ||
173 | + * | ||
174 | + * The following are exposed to uImage header. | ||
175 | + * New IDs *MUST* be appended at the end of the list and *NEVER* | ||
176 | + * inserted for backward compatibility. | ||
177 | */ | ||
178 | |||
179 | -#define IH_TYPE_INVALID 0 /* Invalid Image */ | ||
180 | -#define IH_TYPE_STANDALONE 1 /* Standalone Program */ | ||
181 | -#define IH_TYPE_KERNEL 2 /* OS Kernel Image */ | ||
182 | -#define IH_TYPE_RAMDISK 3 /* RAMDisk Image */ | ||
183 | -#define IH_TYPE_MULTI 4 /* Multi-File Image */ | ||
184 | -#define IH_TYPE_FIRMWARE 5 /* Firmware Image */ | ||
185 | -#define IH_TYPE_SCRIPT 6 /* Script file */ | ||
186 | -#define IH_TYPE_FILESYSTEM 7 /* Filesystem Image (any type) */ | ||
187 | -#define IH_TYPE_FLATDT 8 /* Binary Flat Device Tree Blob */ | ||
188 | -#define IH_TYPE_KERNEL_NOLOAD 14 /* OS Kernel Image (noload) */ | ||
189 | +enum { | ||
190 | + IH_TYPE_INVALID = 0, /* Invalid Image */ | ||
191 | + IH_TYPE_STANDALONE, /* Standalone Program */ | ||
192 | + IH_TYPE_KERNEL, /* OS Kernel Image */ | ||
193 | + IH_TYPE_RAMDISK, /* RAMDisk Image */ | ||
194 | + IH_TYPE_MULTI, /* Multi-File Image */ | ||
195 | + IH_TYPE_FIRMWARE, /* Firmware Image */ | ||
196 | + IH_TYPE_SCRIPT, /* Script file */ | ||
197 | + IH_TYPE_FILESYSTEM, /* Filesystem Image (any type) */ | ||
198 | + IH_TYPE_FLATDT, /* Binary Flat Device Tree Blob */ | ||
199 | + IH_TYPE_KWBIMAGE, /* Kirkwood Boot Image */ | ||
200 | + IH_TYPE_IMXIMAGE, /* Freescale IMXBoot Image */ | ||
201 | + IH_TYPE_UBLIMAGE, /* Davinci UBL Image */ | ||
202 | + IH_TYPE_OMAPIMAGE, /* TI OMAP Config Header Image */ | ||
203 | + IH_TYPE_AISIMAGE, /* TI Davinci AIS Image */ | ||
204 | + /* OS Kernel Image, can run from any load address */ | ||
205 | + IH_TYPE_KERNEL_NOLOAD, | ||
206 | + IH_TYPE_PBLIMAGE, /* Freescale PBL Boot Image */ | ||
207 | + IH_TYPE_MXSIMAGE, /* Freescale MXSBoot Image */ | ||
208 | + IH_TYPE_GPIMAGE, /* TI Keystone GPHeader Image */ | ||
209 | + IH_TYPE_ATMELIMAGE, /* ATMEL ROM bootable Image */ | ||
210 | + IH_TYPE_SOCFPGAIMAGE, /* Altera SOCFPGA CV/AV Preloader */ | ||
211 | + IH_TYPE_X86_SETUP, /* x86 setup.bin Image */ | ||
212 | + IH_TYPE_LPC32XXIMAGE, /* x86 setup.bin Image */ | ||
213 | + IH_TYPE_LOADABLE, /* A list of typeless images */ | ||
214 | + IH_TYPE_RKIMAGE, /* Rockchip Boot Image */ | ||
215 | + IH_TYPE_RKSD, /* Rockchip SD card */ | ||
216 | + IH_TYPE_RKSPI, /* Rockchip SPI image */ | ||
217 | + IH_TYPE_ZYNQIMAGE, /* Xilinx Zynq Boot Image */ | ||
218 | + IH_TYPE_ZYNQMPIMAGE, /* Xilinx ZynqMP Boot Image */ | ||
219 | + IH_TYPE_ZYNQMPBIF, /* Xilinx ZynqMP Boot Image (bif) */ | ||
220 | + IH_TYPE_FPGA, /* FPGA Image */ | ||
221 | + IH_TYPE_VYBRIDIMAGE, /* VYBRID .vyb Image */ | ||
222 | + IH_TYPE_TEE, /* Trusted Execution Environment OS Image */ | ||
223 | + IH_TYPE_FIRMWARE_IVT, /* Firmware Image with HABv4 IVT */ | ||
224 | + IH_TYPE_PMMC, /* TI Power Management Micro-Controller Firmware */ | ||
225 | + IH_TYPE_STM32IMAGE, /* STMicroelectronics STM32 Image */ | ||
226 | + IH_TYPE_SOCFPGAIMAGE_V1, /* Altera SOCFPGA A10 Preloader */ | ||
227 | + IH_TYPE_MTKIMAGE, /* MediaTek BootROM loadable Image */ | ||
228 | + IH_TYPE_IMX8MIMAGE, /* Freescale IMX8MBoot Image */ | ||
229 | + IH_TYPE_IMX8IMAGE, /* Freescale IMX8Boot Image */ | ||
230 | + IH_TYPE_COPRO, /* Coprocessor Image for remoteproc*/ | ||
231 | + IH_TYPE_SUNXI_EGON, /* Allwinner eGON Boot Image */ | ||
232 | + | ||
233 | + IH_TYPE_COUNT, /* Number of image types */ | ||
234 | +}; | ||
235 | |||
236 | /* | ||
237 | * Compression Types | ||
238 | + * | ||
239 | + * The following are exposed to uImage header. | ||
240 | + * New IDs *MUST* be appended at the end of the list and *NEVER* | ||
241 | + * inserted for backward compatibility. | ||
242 | */ | ||
243 | -#define IH_COMP_NONE 0 /* No Compression Used */ | ||
244 | -#define IH_COMP_GZIP 1 /* gzip Compression Used */ | ||
245 | -#define IH_COMP_BZIP2 2 /* bzip2 Compression Used */ | ||
246 | +enum { | ||
247 | + IH_COMP_NONE = 0, /* No Compression Used */ | ||
248 | + IH_COMP_GZIP, /* gzip Compression Used */ | ||
249 | + IH_COMP_BZIP2, /* bzip2 Compression Used */ | ||
250 | + IH_COMP_LZMA, /* lzma Compression Used */ | ||
251 | + IH_COMP_LZO, /* lzo Compression Used */ | ||
252 | + IH_COMP_LZ4, /* lz4 Compression Used */ | ||
253 | + IH_COMP_ZSTD, /* zstd Compression Used */ | ||
254 | + | ||
255 | + IH_COMP_COUNT, | ||
256 | +}; | ||
257 | |||
258 | #define IH_MAGIC 0x27051956 /* Image Magic Number */ | ||
259 | #define IH_NMLEN 32 /* Image Name Length */ | ||
260 | |||
261 | /* | ||
262 | - * all data in network byte order (aka natural aka bigendian) | ||
263 | + * Legacy format image header, | ||
264 | + * all data in network byte order (aka natural aka bigendian). | ||
265 | */ | ||
266 | - | ||
267 | typedef struct uboot_image_header { | ||
268 | uint32_t ih_magic; /* Image Header Magic Number */ | ||
269 | uint32_t ih_hcrc; /* Image Header CRC Checksum */ | ||
270 | -- | 83 | -- |
271 | 2.35.3 | 84 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Alexei Filippov <alexei.filippov@syntacore.com> |
---|---|---|---|
2 | 2 | ||
3 | If specified CPU configuration is not valid, not just it prints error | 3 | Previous patch fixed the PMP priority in raise_mmu_exception() but we're still |
4 | message, it aborts and generates core dumps (depends on the operating | 4 | setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage |
5 | system). This kind of error handling should be used only when a serious | 5 | translation part, mtval2 will be set in case of successes 2 stage translation but |
6 | runtime error occurs. | 6 | failed pmp check. |
7 | 7 | ||
8 | This commit makes error handling on CPU configuration more generous on | 8 | In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of |
9 | sifive_e/u and opentitan machines. It now just prints error message and | 9 | riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2 |
10 | quits (without coredumps and aborts). | 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...* | ||
11 | 14 | ||
12 | This is separate from spike/virt because it involves different type | 15 | Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com> |
13 | (TYPE_RISCV_HART_ARRAY) on sifive_e/u and opentitan machines. | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
14 | |||
15 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
17 | Message-Id: <09e61e58a7543da44bdb0e0f5368afc8903b4aa6.1652509778.git.research_trasio@irq.a4lg.com> | 18 | Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> |
19 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 21 | --- |
20 | hw/riscv/opentitan.c | 2 +- | 22 | target/riscv/cpu_helper.c | 12 ++++++------ |
21 | hw/riscv/sifive_e.c | 2 +- | 23 | 1 file changed, 6 insertions(+), 6 deletions(-) |
22 | hw/riscv/sifive_u.c | 4 ++-- | ||
23 | 3 files changed, 4 insertions(+), 4 deletions(-) | ||
24 | 24 | ||
25 | diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c | 25 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
26 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/riscv/opentitan.c | 27 | --- a/target/riscv/cpu_helper.c |
28 | +++ b/hw/riscv/opentitan.c | 28 | +++ b/target/riscv/cpu_helper.c |
29 | @@ -XXX,XX +XXX,XX @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp) | 29 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
30 | object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus, | 30 | __func__, pa, ret, prot_pmp, tlb_size); |
31 | &error_abort); | 31 | |
32 | object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x8080, &error_abort); | 32 | prot &= prot_pmp; |
33 | - sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); | 33 | - } |
34 | + sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal); | 34 | - |
35 | 35 | - if (ret != TRANSLATE_SUCCESS) { | |
36 | /* Boot ROM */ | 36 | + } else { |
37 | memory_region_init_rom(&s->rom, OBJECT(dev_soc), "riscv.lowrisc.ibex.rom", | 37 | /* |
38 | diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c | 38 | * Guest physical address translation failed, this is a HS |
39 | index XXXXXXX..XXXXXXX 100644 | 39 | * level exception |
40 | --- a/hw/riscv/sifive_e.c | 40 | */ |
41 | +++ b/hw/riscv/sifive_e.c | 41 | first_stage_error = false; |
42 | @@ -XXX,XX +XXX,XX @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp) | 42 | - env->guest_phys_fault_addr = (im_address | |
43 | 43 | - (address & | |
44 | object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type, | 44 | - (TARGET_PAGE_SIZE - 1))) >> 2; |
45 | &error_abort); | 45 | + if (ret != TRANSLATE_PMP_FAIL) { |
46 | - sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_abort); | 46 | + env->guest_phys_fault_addr = (im_address | |
47 | + sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal); | 47 | + (address & |
48 | 48 | + (TARGET_PAGE_SIZE - 1))) >> 2; | |
49 | /* Mask ROM */ | 49 | + } |
50 | memory_region_init_rom(&s->mask_rom, OBJECT(dev), "riscv.sifive.e.mrom", | 50 | } |
51 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 51 | } |
52 | index XXXXXXX..XXXXXXX 100644 | 52 | } else { |
53 | --- a/hw/riscv/sifive_u.c | ||
54 | +++ b/hw/riscv/sifive_u.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp) | ||
56 | qdev_prop_set_string(DEVICE(&s->u_cpus), "cpu-type", s->cpu_type); | ||
57 | qdev_prop_set_uint64(DEVICE(&s->u_cpus), "resetvec", 0x1004); | ||
58 | |||
59 | - sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_abort); | ||
60 | - sysbus_realize(SYS_BUS_DEVICE(&s->u_cpus), &error_abort); | ||
61 | + sysbus_realize(SYS_BUS_DEVICE(&s->e_cpus), &error_fatal); | ||
62 | + sysbus_realize(SYS_BUS_DEVICE(&s->u_cpus), &error_fatal); | ||
63 | /* | ||
64 | * The cluster must be realized after the RISC-V hart array container, | ||
65 | * as the container's CPU object is only created on realize, and the | ||
66 | -- | 53 | -- |
67 | 2.35.3 | 54 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Rob Bradford <rbradford@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | This commit moves ISA string conversion for Zhinx and Zhinxmin extensions. | 3 | This extension has now been ratified: |
4 | Because extension category ordering of "H" is going to be after "V", | 4 | https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be |
5 | their ordering is going to be valid (on canonical order). | 5 | removed. |
6 | 6 | ||
7 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | 7 | Since this is now a ratified extension add it to the list of extensions |
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 8 | included in the "max" CPU variant. |
9 | Message-Id: <7a988aedb249b6709f9ce5464ff359b60958ca54.1652181972.git.research_trasio@irq.a4lg.com> | 9 | |
10 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> | ||
11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
14 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
15 | Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 17 | --- |
12 | target/riscv/cpu.c | 4 ++-- | 18 | target/riscv/cpu.c | 2 +- |
13 | 1 file changed, 2 insertions(+), 2 deletions(-) | 19 | target/riscv/tcg/tcg-cpu.c | 2 +- |
20 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
14 | 21 | ||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 22 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
16 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu.c | 24 | --- a/target/riscv/cpu.c |
18 | +++ b/target/riscv/cpu.c | 25 | +++ b/target/riscv/cpu.c |
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) | 26 | @@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = { |
20 | ISA_EDATA_ENTRY(zfh, ext_zfh), | 27 | MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), |
21 | ISA_EDATA_ENTRY(zfhmin, ext_zfhmin), | 28 | MISA_EXT_INFO(RVV, "v", "Vector operations"), |
22 | ISA_EDATA_ENTRY(zfinx, ext_zfinx), | 29 | MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), |
23 | - ISA_EDATA_ENTRY(zhinx, ext_zhinx), | 30 | - MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") |
24 | - ISA_EDATA_ENTRY(zhinxmin, ext_zhinxmin), | 31 | + MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") |
25 | ISA_EDATA_ENTRY(zdinx, ext_zdinx), | 32 | }; |
26 | ISA_EDATA_ENTRY(zba, ext_zba), | 33 | |
27 | ISA_EDATA_ENTRY(zbb, ext_zbb), | 34 | static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc) |
28 | @@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) | 35 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
29 | ISA_EDATA_ENTRY(zkt, ext_zkt), | 36 | index XXXXXXX..XXXXXXX 100644 |
30 | ISA_EDATA_ENTRY(zve32f, ext_zve32f), | 37 | --- a/target/riscv/tcg/tcg-cpu.c |
31 | ISA_EDATA_ENTRY(zve64f, ext_zve64f), | 38 | +++ b/target/riscv/tcg/tcg-cpu.c |
32 | + ISA_EDATA_ENTRY(zhinx, ext_zhinx), | 39 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) |
33 | + ISA_EDATA_ENTRY(zhinxmin, ext_zhinxmin), | 40 | const RISCVCPUMultiExtConfig *prop; |
34 | ISA_EDATA_ENTRY(svinval, ext_svinval), | 41 | |
35 | ISA_EDATA_ENTRY(svnapot, ext_svnapot), | 42 | /* Enable RVG, RVJ and RVV that are disabled by default */ |
36 | ISA_EDATA_ENTRY(svpbmt, ext_svpbmt), | 43 | - riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV); |
44 | + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); | ||
45 | |||
46 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
47 | isa_ext_update_enabled(cpu, prop->offset, true); | ||
37 | -- | 48 | -- |
38 | 2.35.3 | 49 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Bernhard Beschow <shentey@gmail.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The QOM API already provides accessors for uint32 values, so reuse them. | 3 | When running the instruction |
4 | 4 | ||
5 | Signed-off-by: Bernhard Beschow <shentey@gmail.com> | 5 | ``` |
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | cbo.flush 0(x0) |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | ``` |
8 | Message-Id: <20220301225220.239065-3-shentey@gmail.com> | 8 | |
9 | QEMU would segfault. | ||
10 | |||
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") | ||
30 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
31 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
32 | Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 34 | --- |
11 | hw/riscv/sifive_u.c | 24 ++++-------------------- | 35 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++---- |
12 | 1 file changed, 4 insertions(+), 20 deletions(-) | 36 | 1 file changed, 12 insertions(+), 4 deletions(-) |
13 | 37 | ||
14 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 38 | diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
15 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/sifive_u.c | 40 | --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc |
17 | +++ b/hw/riscv/sifive_u.c | 41 | +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
18 | @@ -XXX,XX +XXX,XX @@ static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error * | 42 | @@ -XXX,XX +XXX,XX @@ |
19 | s->start_in_flash = value; | 43 | static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) |
44 | { | ||
45 | REQUIRE_ZICBOM(ctx); | ||
46 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); | ||
47 | + TCGv src = get_address(ctx, a->rs1, 0); | ||
48 | + | ||
49 | + gen_helper_cbo_clean_flush(tcg_env, src); | ||
50 | return true; | ||
20 | } | 51 | } |
21 | 52 | ||
22 | -static void sifive_u_machine_get_uint32_prop(Object *obj, Visitor *v, | 53 | static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) |
23 | - const char *name, void *opaque, | ||
24 | - Error **errp) | ||
25 | -{ | ||
26 | - visit_type_uint32(v, name, (uint32_t *)opaque, errp); | ||
27 | -} | ||
28 | - | ||
29 | -static void sifive_u_machine_set_uint32_prop(Object *obj, Visitor *v, | ||
30 | - const char *name, void *opaque, | ||
31 | - Error **errp) | ||
32 | -{ | ||
33 | - visit_type_uint32(v, name, (uint32_t *)opaque, errp); | ||
34 | -} | ||
35 | - | ||
36 | static void sifive_u_machine_instance_init(Object *obj) | ||
37 | { | 54 | { |
38 | SiFiveUState *s = RISCV_U_MACHINE(obj); | 55 | REQUIRE_ZICBOM(ctx); |
39 | 56 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); | |
40 | s->start_in_flash = false; | 57 | + TCGv src = get_address(ctx, a->rs1, 0); |
41 | s->msel = 0; | 58 | + |
42 | - object_property_add(obj, "msel", "uint32", | 59 | + gen_helper_cbo_clean_flush(tcg_env, src); |
43 | - sifive_u_machine_get_uint32_prop, | 60 | return true; |
44 | - sifive_u_machine_set_uint32_prop, NULL, &s->msel); | ||
45 | + object_property_add_uint32_ptr(obj, "msel", &s->msel, | ||
46 | + OBJ_PROP_FLAG_READWRITE); | ||
47 | object_property_set_description(obj, "msel", | ||
48 | "Mode Select (MSEL[3:0]) pin state"); | ||
49 | |||
50 | s->serial = OTP_SERIAL; | ||
51 | - object_property_add(obj, "serial", "uint32", | ||
52 | - sifive_u_machine_get_uint32_prop, | ||
53 | - sifive_u_machine_set_uint32_prop, NULL, &s->serial); | ||
54 | + object_property_add_uint32_ptr(obj, "serial", &s->serial, | ||
55 | + OBJ_PROP_FLAG_READWRITE); | ||
56 | object_property_set_description(obj, "serial", "Board serial number"); | ||
57 | } | 61 | } |
58 | 62 | ||
63 | static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) | ||
64 | { | ||
65 | REQUIRE_ZICBOM(ctx); | ||
66 | - gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]); | ||
67 | + TCGv src = get_address(ctx, a->rs1, 0); | ||
68 | + | ||
69 | + gen_helper_cbo_inval(tcg_env, src); | ||
70 | return true; | ||
71 | } | ||
72 | |||
73 | static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) | ||
74 | { | ||
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; | ||
81 | } | ||
59 | -- | 82 | -- |
60 | 2.35.3 | 83 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Anup Patel <apatel@ventanamicro.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | When hypervisor and VS CSRs are accessed from VS-mode or VU-mode, | 3 | In AIA spec, each hart (or each hart within a group) has a unique hart |
4 | the riscv_csrrw_check() function should generate virtual instruction | 4 | number to locate the memory pages of interrupt files in the address |
5 | trap instead illegal instruction trap. | 5 | space. The number of bits required to represent any hart number is equal |
6 | to ceil(log2(hmax + 1)), where hmax is the largest hart number among | ||
7 | groups. | ||
6 | 8 | ||
7 | Fixes: 0a42f4c44088 (" target/riscv: Fix CSR perm checking for HS mode") | 9 | However, if the largest hart number among groups is a power of 2, QEMU |
8 | Signed-off-by: Anup Patel <apatel@ventanamicro.com> | 10 | will pass an inaccurate hart-index-bit setting to Linux. For example, when |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 11 | the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient |
10 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 12 | to represent 4 harts, but we passes 3 to Linux. The code needs to be |
11 | Message-Id: <20220511144528.393530-2-apatel@ventanamicro.com> | 13 | updated to ensure accurate hart-index-bit settings. |
14 | |||
15 | Additionally, a Linux patch[1] is necessary to correctly recover the hart | ||
16 | index when the guest OS has only 1 hart, where the hart-index-bit is 0. | ||
17 | |||
18 | [1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/ | ||
19 | |||
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> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 25 | --- |
14 | target/riscv/csr.c | 8 ++++++-- | 26 | target/riscv/kvm/kvm-cpu.c | 9 ++++++++- |
15 | 1 file changed, 6 insertions(+), 2 deletions(-) | 27 | 1 file changed, 8 insertions(+), 1 deletion(-) |
16 | 28 | ||
17 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 29 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
18 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/csr.c | 31 | --- a/target/riscv/kvm/kvm-cpu.c |
20 | +++ b/target/riscv/csr.c | 32 | +++ b/target/riscv/kvm/kvm-cpu.c |
21 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | 33 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
22 | int read_only = get_field(csrno, 0xC00) == 3; | 34 | } |
23 | int csr_min_priv = csr_ops[csrno].min_priv_ver; | ||
24 | #if !defined(CONFIG_USER_ONLY) | ||
25 | - int effective_priv = env->priv; | ||
26 | + int csr_priv, effective_priv = env->priv; | ||
27 | |||
28 | if (riscv_has_ext(env, RVH) && env->priv == PRV_S) { | ||
29 | /* | ||
30 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, | ||
31 | effective_priv++; | ||
32 | } | 35 | } |
33 | 36 | ||
34 | - if (!env->debugger && (effective_priv < get_field(csrno, 0x300))) { | 37 | - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
35 | + csr_priv = get_field(csrno, 0x300); | 38 | + |
36 | + if (!env->debugger && (effective_priv < csr_priv)) { | 39 | + if (max_hart_per_socket > 1) { |
37 | + if (csr_priv == (PRV_S + 1) && riscv_cpu_virt_enabled(env)) { | 40 | + max_hart_per_socket--; |
38 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | 41 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; |
39 | + } | 42 | + } else { |
40 | return RISCV_EXCP_ILLEGAL_INST; | 43 | + hart_bits = 0; |
41 | } | 44 | + } |
42 | #endif | 45 | + |
46 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, | ||
47 | KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, | ||
48 | &hart_bits, true, NULL); | ||
43 | -- | 49 | -- |
44 | 2.35.3 | 50 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Tsukasa OI <research_trasio@irq.a4lg.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | If specified CPU configuration is not valid, not just it prints error | 3 | Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length |
4 | message, it aborts and generates core dumps (depends on the operating | 4 | in bytes, when in this context we want 'reg_width' as the length in |
5 | system). This kind of error handling should be used only when a serious | 5 | bits. |
6 | runtime error occurs. | ||
7 | 6 | ||
8 | This commit makes error handling on CPU configuration more generous on | 7 | Fix 'reg_width' back to the value in bits like 7cb59921c05a |
9 | virt/spike machines. It now just prints error message and quits (without | 8 | ("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set |
10 | coredumps and aborts). | 9 | beforehand. |
11 | 10 | ||
12 | Signed-off-by: Tsukasa OI <research_trasio@irq.a4lg.com> | 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> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
14 | Message-Id: <d17381d3ea4992808cf1894f379ca67220f61b45.1652509778.git.research_trasio@irq.a4lg.com> | 25 | Cc: qemu-stable <qemu-stable@nongnu.org> |
26 | Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
16 | --- | 28 | --- |
17 | hw/riscv/spike.c | 2 +- | 29 | target/riscv/gdbstub.c | 6 +++--- |
18 | hw/riscv/virt.c | 2 +- | 30 | 1 file changed, 3 insertions(+), 3 deletions(-) |
19 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
20 | 31 | ||
21 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 32 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
22 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/riscv/spike.c | 34 | --- a/target/riscv/gdbstub.c |
24 | +++ b/hw/riscv/spike.c | 35 | +++ b/target/riscv/gdbstub.c |
25 | @@ -XXX,XX +XXX,XX @@ static void spike_board_init(MachineState *machine) | 36 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) |
26 | base_hartid, &error_abort); | 37 | static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
27 | object_property_set_int(OBJECT(&s->soc[i]), "num-harts", | 38 | { |
28 | hart_count, &error_abort); | 39 | RISCVCPU *cpu = RISCV_CPU(cs); |
29 | - sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_abort); | 40 | - int reg_width = cpu->cfg.vlenb; |
30 | + sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal); | 41 | + int bitsize = cpu->cfg.vlenb << 3; |
31 | 42 | GDBFeatureBuilder builder; | |
32 | /* Core Local Interruptor (timer and IPI) for each socket */ | 43 | int i; |
33 | riscv_aclint_swi_create( | 44 | |
34 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 45 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
35 | index XXXXXXX..XXXXXXX 100644 | 46 | |
36 | --- a/hw/riscv/virt.c | 47 | /* First define types and totals in a whole VL */ |
37 | +++ b/hw/riscv/virt.c | 48 | for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { |
38 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 49 | - int count = reg_width / vec_lanes[i].size; |
39 | base_hartid, &error_abort); | 50 | + int count = bitsize / vec_lanes[i].size; |
40 | object_property_set_int(OBJECT(&s->soc[i]), "num-harts", | 51 | gdb_feature_builder_append_tag( |
41 | hart_count, &error_abort); | 52 | &builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>", |
42 | - sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_abort); | 53 | vec_lanes[i].id, vec_lanes[i].gdb_type, count); |
43 | + sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal); | 54 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
44 | 55 | /* Define vector registers */ | |
45 | if (!kvm_enabled()) { | 56 | for (i = 0; i < 32; i++) { |
46 | if (s->have_aclint) { | 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); | ||
47 | -- | 63 | -- |
48 | 2.35.3 | 64 | 2.45.1 |
65 | |||
66 | diff view generated by jsdifflib |
1 | From: Atish Patra <atishp@rivosinc.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | timecmp update function should be invoked with hartid for which | 3 | Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr |
4 | timecmp is being updated. The following patch passes the incorrect | 4 | CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr |
5 | hartid to the update function. | 5 | CSRs are part of the disassembly. |
6 | 6 | ||
7 | Fixes: e2f01f3c2e13 ("hw/intc: Make RISC-V ACLINT mtime MMIO register writable") | 7 | Reported-by: Eric DeVolder <eric_devolder@yahoo.com> |
8 | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | |
9 | Signed-off-by: Atish Patra <atishp@rivosinc.com> | 9 | Fixes: ea10325917 ("RISC-V Disassembler") |
10 | Reviewed-by: Frank Chang <frank.chang@sifive.com> | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | Reviewed-by: Anup Patel <anup@brainfault.org> | 11 | Cc: qemu-stable <qemu-stable@nongnu.org> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com> |
13 | Message-Id: <20220513221458.1192933-1-atishp@rivosinc.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 14 | --- |
16 | hw/intc/riscv_aclint.c | 3 ++- | 15 | disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- |
17 | 1 file changed, 2 insertions(+), 1 deletion(-) | 16 | 1 file changed, 64 insertions(+), 1 deletion(-) |
18 | 17 | ||
19 | diff --git a/hw/intc/riscv_aclint.c b/hw/intc/riscv_aclint.c | 18 | diff --git a/disas/riscv.c b/disas/riscv.c |
20 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/intc/riscv_aclint.c | 20 | --- a/disas/riscv.c |
22 | +++ b/hw/intc/riscv_aclint.c | 21 | +++ b/disas/riscv.c |
23 | @@ -XXX,XX +XXX,XX @@ static void riscv_aclint_mtimer_write(void *opaque, hwaddr addr, | 22 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
24 | continue; | 23 | case 0x0383: return "mibound"; |
25 | } | 24 | case 0x0384: return "mdbase"; |
26 | riscv_aclint_mtimer_write_timecmp(mtimer, RISCV_CPU(cpu), | 25 | case 0x0385: return "mdbound"; |
27 | - i, env->timecmp); | 26 | - case 0x03a0: return "pmpcfg3"; |
28 | + mtimer->hartid_base + i, | 27 | + case 0x03a0: return "pmpcfg0"; |
29 | + env->timecmp); | 28 | + case 0x03a1: return "pmpcfg1"; |
30 | } | 29 | + case 0x03a2: return "pmpcfg2"; |
31 | return; | 30 | + case 0x03a3: return "pmpcfg3"; |
32 | } | 31 | + case 0x03a4: return "pmpcfg4"; |
32 | + case 0x03a5: return "pmpcfg5"; | ||
33 | + case 0x03a6: return "pmpcfg6"; | ||
34 | + case 0x03a7: return "pmpcfg7"; | ||
35 | + case 0x03a8: return "pmpcfg8"; | ||
36 | + case 0x03a9: return "pmpcfg9"; | ||
37 | + case 0x03aa: return "pmpcfg10"; | ||
38 | + case 0x03ab: return "pmpcfg11"; | ||
39 | + case 0x03ac: return "pmpcfg12"; | ||
40 | + case 0x03ad: return "pmpcfg13"; | ||
41 | + case 0x03ae: return "pmpcfg14"; | ||
42 | + case 0x03af: return "pmpcfg15"; | ||
43 | case 0x03b0: return "pmpaddr0"; | ||
44 | case 0x03b1: return "pmpaddr1"; | ||
45 | case 0x03b2: return "pmpaddr2"; | ||
46 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | ||
47 | case 0x03bd: return "pmpaddr13"; | ||
48 | case 0x03be: return "pmpaddr14"; | ||
49 | case 0x03bf: return "pmpaddr15"; | ||
50 | + case 0x03c0: return "pmpaddr16"; | ||
51 | + case 0x03c1: return "pmpaddr17"; | ||
52 | + case 0x03c2: return "pmpaddr18"; | ||
53 | + case 0x03c3: return "pmpaddr19"; | ||
54 | + case 0x03c4: return "pmpaddr20"; | ||
55 | + case 0x03c5: return "pmpaddr21"; | ||
56 | + case 0x03c6: return "pmpaddr22"; | ||
57 | + case 0x03c7: return "pmpaddr23"; | ||
58 | + case 0x03c8: return "pmpaddr24"; | ||
59 | + case 0x03c9: return "pmpaddr25"; | ||
60 | + case 0x03ca: return "pmpaddr26"; | ||
61 | + case 0x03cb: return "pmpaddr27"; | ||
62 | + case 0x03cc: return "pmpaddr28"; | ||
63 | + case 0x03cd: return "pmpaddr29"; | ||
64 | + case 0x03ce: return "pmpaddr30"; | ||
65 | + case 0x03cf: return "pmpaddr31"; | ||
66 | + case 0x03d0: return "pmpaddr32"; | ||
67 | + case 0x03d1: return "pmpaddr33"; | ||
68 | + case 0x03d2: return "pmpaddr34"; | ||
69 | + case 0x03d3: return "pmpaddr35"; | ||
70 | + case 0x03d4: return "pmpaddr36"; | ||
71 | + case 0x03d5: return "pmpaddr37"; | ||
72 | + case 0x03d6: return "pmpaddr38"; | ||
73 | + case 0x03d7: return "pmpaddr39"; | ||
74 | + case 0x03d8: return "pmpaddr40"; | ||
75 | + case 0x03d9: return "pmpaddr41"; | ||
76 | + case 0x03da: return "pmpaddr42"; | ||
77 | + case 0x03db: return "pmpaddr43"; | ||
78 | + case 0x03dc: return "pmpaddr44"; | ||
79 | + case 0x03dd: return "pmpaddr45"; | ||
80 | + case 0x03de: return "pmpaddr46"; | ||
81 | + case 0x03df: return "pmpaddr47"; | ||
82 | + case 0x03e0: return "pmpaddr48"; | ||
83 | + case 0x03e1: return "pmpaddr49"; | ||
84 | + case 0x03e2: return "pmpaddr50"; | ||
85 | + case 0x03e3: return "pmpaddr51"; | ||
86 | + case 0x03e4: return "pmpaddr52"; | ||
87 | + case 0x03e5: return "pmpaddr53"; | ||
88 | + case 0x03e6: return "pmpaddr54"; | ||
89 | + case 0x03e7: return "pmpaddr55"; | ||
90 | + case 0x03e8: return "pmpaddr56"; | ||
91 | + case 0x03e9: return "pmpaddr57"; | ||
92 | + case 0x03ea: return "pmpaddr58"; | ||
93 | + case 0x03eb: return "pmpaddr59"; | ||
94 | + case 0x03ec: return "pmpaddr60"; | ||
95 | + case 0x03ed: return "pmpaddr61"; | ||
96 | + case 0x03ee: return "pmpaddr62"; | ||
97 | + case 0x03ef: return "pmpaddr63"; | ||
98 | case 0x0780: return "mtohost"; | ||
99 | case 0x0781: return "mfromhost"; | ||
100 | case 0x0782: return "mreset"; | ||
33 | -- | 101 | -- |
34 | 2.35.3 | 102 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Yu-Ming Chang <yumin686@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | "mimpid" cpu option was mistyped to "mipid". | 3 | Both CSRRS and CSRRC always read the addressed CSR and cause any read side |
4 | effects regardless of rs1 and rd fields. Note that if rs1 specifies a register | ||
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. | ||
4 | 7 | ||
5 | Fixes: 9951ba94 ("target/riscv: Support configuarable marchid, mvendorid, mipid CSR values") | 8 | So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies |
6 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 9 | a register holding a zero value, an illegal instruction exception should be |
10 | raised. | ||
11 | |||
12 | Signed-off-by: Yu-Ming Chang <yumin686@andestech.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-Id: <20220523153147.15371-1-frank.chang@sifive.com> | 14 | Message-ID: <20240403070823.80897-1-yumin686@andestech.com> |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 16 | --- |
11 | target/riscv/cpu.h | 2 +- | 17 | target/riscv/cpu.h | 4 ++++ |
12 | target/riscv/cpu.c | 4 ++-- | 18 | target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++---- |
13 | target/riscv/csr.c | 8 ++++---- | 19 | target/riscv/op_helper.c | 6 ++--- |
14 | 3 files changed, 7 insertions(+), 7 deletions(-) | 20 | 3 files changed, 53 insertions(+), 8 deletions(-) |
15 | 21 | ||
16 | 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 |
17 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/cpu.h | 24 | --- a/target/riscv/cpu.h |
19 | +++ b/target/riscv/cpu.h | 25 | +++ b/target/riscv/cpu.h |
20 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 26 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
21 | 27 | void riscv_cpu_update_mask(CPURISCVState *env); | |
22 | uint32_t mvendorid; | 28 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
23 | uint64_t marchid; | 29 | |
24 | - uint64_t mipid; | 30 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
25 | + uint64_t mimpid; | 31 | + target_ulong *ret_value); |
26 | 32 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | |
27 | /* Vendor-specific custom extensions */ | 33 | target_ulong *ret_value, |
28 | bool ext_XVentanaCondOps; | 34 | target_ulong new_value, target_ulong write_mask); |
29 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 35 | @@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, |
30 | index XXXXXXX..XXXXXXX 100644 | 36 | target_ulong new_value, |
31 | --- a/target/riscv/cpu.c | 37 | target_ulong write_mask); |
32 | +++ b/target/riscv/cpu.c | 38 | |
33 | @@ -XXX,XX +XXX,XX @@ | 39 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, |
34 | #define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \ | 40 | + Int128 *ret_value); |
35 | (QEMU_VERSION_MINOR << 8) | \ | 41 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, |
36 | (QEMU_VERSION_MICRO)) | 42 | Int128 *ret_value, |
37 | -#define RISCV_CPU_MIPID RISCV_CPU_MARCHID | 43 | Int128 new_value, Int128 write_mask); |
38 | +#define RISCV_CPU_MIMPID RISCV_CPU_MARCHID | ||
39 | |||
40 | static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; | ||
41 | |||
42 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | ||
43 | |||
44 | DEFINE_PROP_UINT32("mvendorid", RISCVCPU, cfg.mvendorid, 0), | ||
45 | DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID), | ||
46 | - DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, RISCV_CPU_MIPID), | ||
47 | + DEFINE_PROP_UINT64("mimpid", RISCVCPU, cfg.mimpid, RISCV_CPU_MIMPID), | ||
48 | |||
49 | DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false), | ||
50 | DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false), | ||
51 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
52 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
53 | --- a/target/riscv/csr.c | 46 | --- a/target/riscv/csr.c |
54 | +++ b/target/riscv/csr.c | 47 | +++ b/target/riscv/csr.c |
55 | @@ -XXX,XX +XXX,XX @@ static RISCVException read_marchid(CPURISCVState *env, int csrno, | 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, | ||
56 | return RISCV_EXCP_NONE; | 67 | return RISCV_EXCP_NONE; |
57 | } | 68 | } |
58 | 69 | ||
59 | -static RISCVException read_mipid(CPURISCVState *env, int csrno, | 70 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
60 | - target_ulong *val) | 71 | + target_ulong *ret_value) |
61 | +static RISCVException read_mimpid(CPURISCVState *env, int csrno, | 72 | +{ |
62 | + target_ulong *val) | 73 | + RISCVException ret = riscv_csrrw_check(env, csrno, false); |
74 | + if (ret != RISCV_EXCP_NONE) { | ||
75 | + return ret; | ||
76 | + } | ||
77 | + | ||
78 | + return riscv_csrrw_do64(env, csrno, ret_value, 0, 0); | ||
79 | +} | ||
80 | + | ||
81 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
82 | target_ulong *ret_value, | ||
83 | target_ulong new_value, target_ulong write_mask) | ||
63 | { | 84 | { |
64 | CPUState *cs = env_cpu(env); | 85 | - RISCVException ret = riscv_csrrw_check(env, csrno, write_mask); |
65 | RISCVCPU *cpu = RISCV_CPU(cs); | 86 | + RISCVException ret = riscv_csrrw_check(env, csrno, true); |
66 | 87 | if (ret != RISCV_EXCP_NONE) { | |
67 | - *val = cpu->cfg.mipid; | 88 | return ret; |
68 | + *val = cpu->cfg.mimpid; | 89 | } |
90 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, | ||
69 | return RISCV_EXCP_NONE; | 91 | return RISCV_EXCP_NONE; |
70 | } | 92 | } |
71 | 93 | ||
72 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | 94 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, |
73 | /* Machine Information Registers */ | 95 | + Int128 *ret_value) |
74 | [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, | 96 | +{ |
75 | [CSR_MARCHID] = { "marchid", any, read_marchid }, | 97 | + RISCVException ret; |
76 | - [CSR_MIMPID] = { "mimpid", any, read_mipid }, | 98 | + |
77 | + [CSR_MIMPID] = { "mimpid", any, read_mimpid }, | 99 | + ret = riscv_csrrw_check(env, csrno, false); |
78 | [CSR_MHARTID] = { "mhartid", any, read_mhartid }, | 100 | + if (ret != RISCV_EXCP_NONE) { |
79 | 101 | + return ret; | |
80 | [CSR_MCONFIGPTR] = { "mconfigptr", any, read_zero, | 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 | ||
138 | index XXXXXXX..XXXXXXX 100644 | ||
139 | --- a/target/riscv/op_helper.c | ||
140 | +++ b/target/riscv/op_helper.c | ||
141 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr) | ||
142 | } | ||
143 | |||
144 | target_ulong val = 0; | ||
145 | - RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0); | ||
146 | + RISCVException ret = riscv_csrr(env, csr, &val); | ||
147 | |||
148 | if (ret != RISCV_EXCP_NONE) { | ||
149 | riscv_raise_exception(env, ret, GETPC()); | ||
150 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr, | ||
151 | target_ulong helper_csrr_i128(CPURISCVState *env, int csr) | ||
152 | { | ||
153 | Int128 rv = int128_zero(); | ||
154 | - RISCVException ret = riscv_csrrw_i128(env, csr, &rv, | ||
155 | - int128_zero(), | ||
156 | - int128_zero()); | ||
157 | + RISCVException ret = riscv_csrr_i128(env, csr, &rv); | ||
158 | |||
159 | if (ret != RISCV_EXCP_NONE) { | ||
160 | riscv_raise_exception(env, ret, GETPC()); | ||
81 | -- | 161 | -- |
82 | 2.35.3 | 162 | 2.45.1 | diff view generated by jsdifflib |