1 | The following changes since commit c95bd5ff1660883d15ad6e0005e4c8571604f51a: | 1 | From: Alistair Francis <alistair.francis@wdc.com> |
---|---|---|---|
2 | 2 | ||
3 | Merge remote-tracking branch 'remotes/philmd/tags/mips-fixes-20210322' into staging (2021-03-22 14:26:13 +0000) | 3 | The following changes since commit ca61fa4b803e5d0abaf6f1ceb690f23bb78a4def: |
4 | |||
5 | Merge remote-tracking branch 'remotes/quic/tags/pull-hex-20211006' into staging (2021-10-06 12:11:14 -0700) | ||
4 | 6 | ||
5 | are available in the Git repository at: | 7 | are available in the Git repository at: |
6 | 8 | ||
7 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20210322-2 | 9 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20211007 |
8 | 10 | ||
9 | for you to fetch changes up to 9a27f69bd668d9d71674407badc412ce1231c7d5: | 11 | for you to fetch changes up to 9ae6ecd848dcd1b32003526ab65a0d4c644dfb07: |
10 | 12 | ||
11 | target/riscv: Prevent lost illegal instruction exceptions (2021-03-22 21:54:40 -0400) | 13 | hw/riscv: shakti_c: Mark as not user creatable (2021-10-07 08:41:33 +1000) |
12 | 14 | ||
13 | ---------------------------------------------------------------- | 15 | ---------------------------------------------------------------- |
14 | RISC-V PR for 6.0 | 16 | Third RISC-V PR for QEMU 6.2 |
15 | 17 | ||
16 | This PR includes: | 18 | - Add Zb[abcs] instruction support |
17 | - Fix for vector CSR access | 19 | - Remove RVB support |
18 | - Improvements to the Ibex UART device | 20 | - Bug fix of setting mstatus_hs.[SD|FS] bits |
19 | - PMP improvements and bug fixes | 21 | - Mark some UART devices as 'input' |
20 | - Hypervisor extension bug fixes | 22 | - QOMify PolarFire MMUART |
21 | - ramfb support for the virt machine | 23 | - Fixes for sifive PDMA |
22 | - Fast read support for SST flash | 24 | - Mark shakti_c as not user creatable |
23 | - Improvements to the microchip_pfsoc machine | ||
24 | 25 | ||
25 | ---------------------------------------------------------------- | 26 | ---------------------------------------------------------------- |
26 | Alexander Wagner (1): | 27 | Alistair Francis (1): |
27 | hw/char: disable ibex uart receive if the buffer is full | 28 | hw/riscv: shakti_c: Mark as not user creatable |
28 | 29 | ||
29 | Asherah Connor (2): | 30 | Bin Meng (5): |
30 | hw/riscv: Add fw_cfg support to virt | 31 | hw/char: ibex_uart: Register device in 'input' category |
31 | hw/riscv: allow ramfb on virt | 32 | hw/char: shakti_uart: Register device in 'input' category |
32 | 33 | hw/char: sifive_uart: Register device in 'input' category | |
33 | Bin Meng (3): | 34 | hw/dma: sifive_pdma: Fix Control.claim bit detection |
34 | hw/block: m25p80: Support fast read for SST flashes | 35 | hw/dma: sifive_pdma: Don't run DMA when channel is disclaimed |
35 | hw/riscv: microchip_pfsoc: Map EMMC/SD mux register | ||
36 | docs/system: riscv: Add documentation for 'microchip-icicle-kit' machine | ||
37 | 36 | ||
38 | Frank Chang (1): | 37 | Frank Chang (1): |
39 | target/riscv: fix vs() to return proper error code | 38 | target/riscv: Set mstatus_hs.[SD|FS] bits if Clean and V=1 in mark_fs_dirty() |
40 | 39 | ||
41 | Georg Kotheimer (6): | 40 | Philipp Tomsich (16): |
42 | target/riscv: Adjust privilege level for HLV(X)/HSV instructions | 41 | target/riscv: Introduce temporary in gen_add_uw() |
43 | target/riscv: Make VSTIP and VSEIP read-only in hip | 42 | target/riscv: fix clzw implementation to operate on arg1 |
44 | target/riscv: Use background registers also for MSTATUS_MPV | 43 | target/riscv: clwz must ignore high bits (use shift-left & changed logic) |
45 | target/riscv: Fix read and write accesses to vsip and vsie | 44 | target/riscv: Add x-zba, x-zbb, x-zbc and x-zbs properties |
46 | target/riscv: Add proper two-stage lookup exception detection | 45 | target/riscv: Reassign instructions to the Zba-extension |
47 | target/riscv: Prevent lost illegal instruction exceptions | 46 | target/riscv: Remove the W-form instructions from Zbs |
47 | target/riscv: Remove shift-one instructions (proposed Zbo in pre-0.93 draft-B) | ||
48 | target/riscv: Reassign instructions to the Zbs-extension | ||
49 | target/riscv: Add instructions of the Zbc-extension | ||
50 | target/riscv: Reassign instructions to the Zbb-extension | ||
51 | target/riscv: Add orc.b instruction for Zbb, removing gorc/gorci | ||
52 | target/riscv: Add a REQUIRE_32BIT macro | ||
53 | target/riscv: Add rev8 instruction, removing grev/grevi | ||
54 | target/riscv: Add zext.h instructions to Zbb, removing pack/packu/packh | ||
55 | target/riscv: Remove RVB (replaced by Zb[abcs]) | ||
56 | disas/riscv: Add Zb[abcs] instructions | ||
48 | 57 | ||
49 | Jim Shu (3): | 58 | Philippe Mathieu-Daudé (3): |
50 | target/riscv: propagate PMP permission to TLB page | 59 | hw/char/mchp_pfsoc_mmuart: Simplify MCHP_PFSOC_MMUART_REG definition |
51 | target/riscv: add log of PMP permission checking | 60 | hw/char/mchp_pfsoc_mmuart: Use a MemoryRegion container |
52 | target/riscv: flush TLB pages if PMP permission has been changed | 61 | hw/char/mchp_pfsoc_mmuart: QOM'ify PolarFire MMUART |
53 | 62 | ||
54 | docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++ | 63 | include/hw/char/mchp_pfsoc_mmuart.h | 17 +- |
55 | docs/system/target-riscv.rst | 1 + | 64 | target/riscv/cpu.h | 11 +- |
56 | include/hw/char/ibex_uart.h | 4 + | 65 | target/riscv/helper.h | 6 +- |
57 | include/hw/riscv/microchip_pfsoc.h | 1 + | 66 | target/riscv/insn32.decode | 115 ++++----- |
58 | include/hw/riscv/virt.h | 2 + | 67 | disas/riscv.c | 157 +++++++++++- |
59 | target/riscv/cpu.h | 4 + | 68 | hw/char/ibex_uart.c | 1 + |
60 | target/riscv/pmp.h | 4 +- | 69 | hw/char/mchp_pfsoc_mmuart.c | 116 +++++++-- |
61 | hw/block/m25p80.c | 3 + | 70 | hw/char/shakti_uart.c | 1 + |
62 | hw/char/ibex_uart.c | 23 +++- | 71 | hw/char/sifive_uart.c | 1 + |
63 | hw/riscv/microchip_pfsoc.c | 6 + | 72 | hw/dma/sifive_pdma.c | 13 +- |
64 | hw/riscv/virt.c | 33 ++++++ | 73 | hw/riscv/shakti_c.c | 7 + |
65 | target/riscv/cpu.c | 1 + | 74 | target/riscv/bitmanip_helper.c | 65 +---- |
66 | target/riscv/cpu_helper.c | 144 +++++++++++++++-------- | 75 | target/riscv/cpu.c | 30 +-- |
67 | target/riscv/csr.c | 77 +++++++------ | 76 | target/riscv/translate.c | 36 ++- |
68 | target/riscv/pmp.c | 84 ++++++++++---- | 77 | target/riscv/insn_trans/trans_rvb.c.inc | 419 ++++++++++---------------------- |
69 | target/riscv/translate.c | 179 +---------------------------- | 78 | 15 files changed, 516 insertions(+), 479 deletions(-) |
70 | hw/riscv/Kconfig | 1 + | ||
71 | 17 files changed, 367 insertions(+), 289 deletions(-) | ||
72 | create mode 100644 docs/system/riscv/microchip-icicle-kit.rst | ||
73 | 79 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | Following the recent changes in translate.c, gen_add_uw() causes | ||
4 | failures on CF3 and SPEC2017 due to the reuse of arg1. Fix these | ||
5 | regressions by introducing a temporary. | ||
6 | |||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20210911140016.834071-2-philipp.tomsich@vrull.eu | ||
12 | Fixes: 191d1dafae9c ("target/riscv: Add DisasExtend to gen_arith*") | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/insn_trans/trans_rvb.c.inc | 6 ++++-- | ||
16 | 1 file changed, 4 insertions(+), 2 deletions(-) | ||
17 | |||
18 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
21 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
22 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD_UW(3) | ||
23 | |||
24 | static void gen_add_uw(TCGv ret, TCGv arg1, TCGv arg2) | ||
25 | { | ||
26 | - tcg_gen_ext32u_tl(arg1, arg1); | ||
27 | - tcg_gen_add_tl(ret, arg1, arg2); | ||
28 | + TCGv t = tcg_temp_new(); | ||
29 | + tcg_gen_ext32u_tl(t, arg1); | ||
30 | + tcg_gen_add_tl(ret, t, arg2); | ||
31 | + tcg_temp_free(t); | ||
32 | } | ||
33 | |||
34 | static bool trans_add_uw(DisasContext *ctx, arg_add_uw *a) | ||
35 | -- | ||
36 | 2.31.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | The current condition for the use of background registers only | 3 | The refactored gen_clzw() uses ret as its argument, instead of arg1. |
4 | considers the hypervisor load and store instructions, | 4 | Fix it. |
5 | but not accesses from M mode via MSTATUS_MPRV+MPV. | ||
6 | 5 | ||
7 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 6 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20210311103036.1401073-1-georg.kotheimer@kernkonzept.com | 8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20210911140016.834071-3-philipp.tomsich@vrull.eu | ||
11 | Fixes: 60903915050 ("target/riscv: Add DisasExtend to gen_unary") | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 13 | --- |
12 | target/riscv/cpu_helper.c | 2 +- | 14 | target/riscv/insn_trans/trans_rvb.c.inc | 2 +- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 16 | ||
15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 17 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu_helper.c | 19 | --- a/target/riscv/insn_trans/trans_rvb.c.inc |
18 | +++ b/target/riscv/cpu_helper.c | 20 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc |
19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 21 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD(3) |
20 | * was called. Background registers will be used if the guest has | 22 | |
21 | * forced a two stage translation to be on (in HS or M mode). | 23 | static void gen_clzw(TCGv ret, TCGv arg1) |
22 | */ | 24 | { |
23 | - if (!riscv_cpu_virt_enabled(env) && riscv_cpu_two_stage_lookup(mmu_idx)) { | 25 | - tcg_gen_clzi_tl(ret, ret, 64); |
24 | + if (!riscv_cpu_virt_enabled(env) && two_stage) { | 26 | + tcg_gen_clzi_tl(ret, arg1, 64); |
25 | use_background = true; | 27 | tcg_gen_subi_tl(ret, ret, 32); |
26 | } | 28 | } |
27 | 29 | ||
28 | -- | 30 | -- |
29 | 2.30.1 | 31 | 2.31.1 |
30 | 32 | ||
31 | 33 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | Assume clzw being executed on a register that is not sign-extended, such | ||
4 | as for the following sequence that uses (1ULL << 63) | 392 as the operand | ||
5 | to clzw: | ||
6 | bseti a2, zero, 63 | ||
7 | addi a2, a2, 392 | ||
8 | clzw a3, a2 | ||
9 | The correct result of clzw would be 23, but the current implementation | ||
10 | returns -32 (as it performs a 64bit clz, which results in 0 leading zero | ||
11 | bits, and then subtracts 32). | ||
12 | |||
13 | Fix this by changing the implementation to: | ||
14 | 1. shift the original register up by 32 | ||
15 | 2. performs a target-length (64bit) clz | ||
16 | 3. return 32 if no bits are set | ||
17 | |||
18 | Marking this instruction as 'w-form' (i.e., setting ctx->w) would not | ||
19 | correctly model the behaviour, as the instruction should not perform | ||
20 | a zero-extensions on the input (after all, it is not a .uw instruction) | ||
21 | and the result is always in the range 0..32 (so neither a sign-extension | ||
22 | nor a zero-extension on the result will ever be needed). Consequently, | ||
23 | we do not set ctx->w and mark the instruction as EXT_NONE. | ||
24 | |||
25 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
26 | Reviewed-by: LIU Zhiwei<zhiwei_liu@c-sky.com> | ||
27 | Message-id: 20210911140016.834071-4-philipp.tomsich@vrull.eu | ||
28 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
29 | --- | ||
30 | target/riscv/insn_trans/trans_rvb.c.inc | 8 +++++--- | ||
31 | 1 file changed, 5 insertions(+), 3 deletions(-) | ||
32 | |||
33 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
36 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
37 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD(3) | ||
38 | |||
39 | static void gen_clzw(TCGv ret, TCGv arg1) | ||
40 | { | ||
41 | - tcg_gen_clzi_tl(ret, arg1, 64); | ||
42 | - tcg_gen_subi_tl(ret, ret, 32); | ||
43 | + TCGv t = tcg_temp_new(); | ||
44 | + tcg_gen_shli_tl(t, arg1, 32); | ||
45 | + tcg_gen_clzi_tl(ret, t, 32); | ||
46 | + tcg_temp_free(t); | ||
47 | } | ||
48 | |||
49 | static bool trans_clzw(DisasContext *ctx, arg_clzw *a) | ||
50 | { | ||
51 | REQUIRE_64BIT(ctx); | ||
52 | REQUIRE_EXT(ctx, RVB); | ||
53 | - return gen_unary(ctx, a, EXT_ZERO, gen_clzw); | ||
54 | + return gen_unary(ctx, a, EXT_NONE, gen_clzw); | ||
55 | } | ||
56 | |||
57 | static void gen_ctzw(TCGv ret, TCGv arg1) | ||
58 | -- | ||
59 | 2.31.1 | ||
60 | |||
61 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | The bitmanipulation ISA extensions will be ratified as individual | ||
4 | small extension packages instead of a large B-extension. The first | ||
5 | new instructions through the door (these have completed public review) | ||
6 | are Zb[abcs]. | ||
7 | |||
8 | This adds new 'x-zba', 'x-zbb', 'x-zbc' and 'x-zbs' properties for | ||
9 | these in target/riscv/cpu.[ch]. | ||
10 | |||
11 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
15 | Message-id: 20210911140016.834071-5-philipp.tomsich@vrull.eu | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | --- | ||
18 | target/riscv/cpu.h | 4 ++++ | ||
19 | target/riscv/cpu.c | 4 ++++ | ||
20 | 2 files changed, 8 insertions(+) | ||
21 | |||
22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/riscv/cpu.h | ||
25 | +++ b/target/riscv/cpu.h | ||
26 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | ||
27 | bool ext_u; | ||
28 | bool ext_h; | ||
29 | bool ext_v; | ||
30 | + bool ext_zba; | ||
31 | + bool ext_zbb; | ||
32 | + bool ext_zbc; | ||
33 | + bool ext_zbs; | ||
34 | bool ext_counters; | ||
35 | bool ext_ifencei; | ||
36 | bool ext_icsr; | ||
37 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/riscv/cpu.c | ||
40 | +++ b/target/riscv/cpu.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | ||
42 | DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), | ||
43 | /* This is experimental so mark with 'x-' */ | ||
44 | DEFINE_PROP_BOOL("x-b", RISCVCPU, cfg.ext_b, false), | ||
45 | + DEFINE_PROP_BOOL("x-zba", RISCVCPU, cfg.ext_zba, false), | ||
46 | + DEFINE_PROP_BOOL("x-zbb", RISCVCPU, cfg.ext_zbb, false), | ||
47 | + DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false), | ||
48 | + DEFINE_PROP_BOOL("x-zbs", RISCVCPU, cfg.ext_zbs, false), | ||
49 | DEFINE_PROP_BOOL("x-h", RISCVCPU, cfg.ext_h, false), | ||
50 | DEFINE_PROP_BOOL("x-v", RISCVCPU, cfg.ext_v, false), | ||
51 | DEFINE_PROP_BOOL("Counters", RISCVCPU, cfg.ext_counters, true), | ||
52 | -- | ||
53 | 2.31.1 | ||
54 | |||
55 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | The following instructions are part of Zba: | ||
4 | - add.uw (RV64 only) | ||
5 | - sh[123]add (RV32 and RV64) | ||
6 | - sh[123]add.uw (RV64-only) | ||
7 | - slli.uw (RV64-only) | ||
8 | |||
9 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | ||
13 | Message-id: 20210911140016.834071-6-philipp.tomsich@vrull.eu | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | target/riscv/insn32.decode | 20 ++++++++++++-------- | ||
17 | target/riscv/insn_trans/trans_rvb.c.inc | 16 +++++++++++----- | ||
18 | 2 files changed, 23 insertions(+), 13 deletions(-) | ||
19 | |||
20 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/riscv/insn32.decode | ||
23 | +++ b/target/riscv/insn32.decode | ||
24 | @@ -XXX,XX +XXX,XX @@ vamomaxd_v 10100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
25 | vamominud_v 11000 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
26 | vamomaxud_v 11100 . . ..... ..... 111 ..... 0101111 @r_wdvm | ||
27 | |||
28 | +# *** RV32 Zba Standard Extension *** | ||
29 | +sh1add 0010000 .......... 010 ..... 0110011 @r | ||
30 | +sh2add 0010000 .......... 100 ..... 0110011 @r | ||
31 | +sh3add 0010000 .......... 110 ..... 0110011 @r | ||
32 | + | ||
33 | +# *** RV64 Zba Standard Extension (in addition to RV32 Zba) *** | ||
34 | +add_uw 0000100 .......... 000 ..... 0111011 @r | ||
35 | +sh1add_uw 0010000 .......... 010 ..... 0111011 @r | ||
36 | +sh2add_uw 0010000 .......... 100 ..... 0111011 @r | ||
37 | +sh3add_uw 0010000 .......... 110 ..... 0111011 @r | ||
38 | +slli_uw 00001 ............ 001 ..... 0011011 @sh | ||
39 | + | ||
40 | # *** RV32B Standard Extension *** | ||
41 | clz 011000 000000 ..... 001 ..... 0010011 @r2 | ||
42 | ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
43 | @@ -XXX,XX +XXX,XX @@ ror 0110000 .......... 101 ..... 0110011 @r | ||
44 | rol 0110000 .......... 001 ..... 0110011 @r | ||
45 | grev 0110100 .......... 101 ..... 0110011 @r | ||
46 | gorc 0010100 .......... 101 ..... 0110011 @r | ||
47 | -sh1add 0010000 .......... 010 ..... 0110011 @r | ||
48 | -sh2add 0010000 .......... 100 ..... 0110011 @r | ||
49 | -sh3add 0010000 .......... 110 ..... 0110011 @r | ||
50 | |||
51 | bseti 00101. ........... 001 ..... 0010011 @sh | ||
52 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
53 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | ||
54 | rolw 0110000 .......... 001 ..... 0111011 @r | ||
55 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
56 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
57 | -sh1add_uw 0010000 .......... 010 ..... 0111011 @r | ||
58 | -sh2add_uw 0010000 .......... 100 ..... 0111011 @r | ||
59 | -sh3add_uw 0010000 .......... 110 ..... 0111011 @r | ||
60 | -add_uw 0000100 .......... 000 ..... 0111011 @r | ||
61 | |||
62 | bsetiw 0010100 .......... 001 ..... 0011011 @sh5 | ||
63 | bclriw 0100100 .......... 001 ..... 0011011 @sh5 | ||
64 | @@ -XXX,XX +XXX,XX @@ roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
65 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
66 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
67 | |||
68 | -slli_uw 00001. ........... 001 ..... 0011011 @sh | ||
69 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
72 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
73 | @@ -XXX,XX +XXX,XX @@ | ||
74 | /* | ||
75 | - * RISC-V translation routines for the RVB Standard Extension. | ||
76 | + * RISC-V translation routines for the RVB draft and Zba Standard Extension. | ||
77 | * | ||
78 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
79 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
80 | + * Copyright (c) 2021 Philipp Tomsich, philipp.tomsich@vrull.eu | ||
81 | * | ||
82 | * This program is free software; you can redistribute it and/or modify it | ||
83 | * under the terms and conditions of the GNU General Public License, | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
86 | */ | ||
87 | |||
88 | +#define REQUIRE_ZBA(ctx) do { \ | ||
89 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zba) { \ | ||
90 | + return false; \ | ||
91 | + } \ | ||
92 | +} while (0) | ||
93 | |||
94 | static void gen_clz(TCGv ret, TCGv arg1) | ||
95 | { | ||
96 | @@ -XXX,XX +XXX,XX @@ GEN_SHADD(3) | ||
97 | #define GEN_TRANS_SHADD(SHAMT) \ | ||
98 | static bool trans_sh##SHAMT##add(DisasContext *ctx, arg_sh##SHAMT##add *a) \ | ||
99 | { \ | ||
100 | - REQUIRE_EXT(ctx, RVB); \ | ||
101 | + REQUIRE_ZBA(ctx); \ | ||
102 | return gen_arith(ctx, a, EXT_NONE, gen_sh##SHAMT##add); \ | ||
103 | } | ||
104 | |||
105 | @@ -XXX,XX +XXX,XX @@ static bool trans_sh##SHAMT##add_uw(DisasContext *ctx, \ | ||
106 | arg_sh##SHAMT##add_uw *a) \ | ||
107 | { \ | ||
108 | REQUIRE_64BIT(ctx); \ | ||
109 | - REQUIRE_EXT(ctx, RVB); \ | ||
110 | + REQUIRE_ZBA(ctx); \ | ||
111 | return gen_arith(ctx, a, EXT_NONE, gen_sh##SHAMT##add_uw); \ | ||
112 | } | ||
113 | |||
114 | @@ -XXX,XX +XXX,XX @@ static void gen_add_uw(TCGv ret, TCGv arg1, TCGv arg2) | ||
115 | static bool trans_add_uw(DisasContext *ctx, arg_add_uw *a) | ||
116 | { | ||
117 | REQUIRE_64BIT(ctx); | ||
118 | - REQUIRE_EXT(ctx, RVB); | ||
119 | + REQUIRE_ZBA(ctx); | ||
120 | return gen_arith(ctx, a, EXT_NONE, gen_add_uw); | ||
121 | } | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ static void gen_slli_uw(TCGv dest, TCGv src, target_long shamt) | ||
124 | static bool trans_slli_uw(DisasContext *ctx, arg_slli_uw *a) | ||
125 | { | ||
126 | REQUIRE_64BIT(ctx); | ||
127 | - REQUIRE_EXT(ctx, RVB); | ||
128 | + REQUIRE_ZBA(ctx); | ||
129 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_slli_uw); | ||
130 | } | ||
131 | -- | ||
132 | 2.31.1 | ||
133 | |||
134 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | Zbs 1.0.0 (just as the 0.93 draft-B before) does not provide for W-form | ||
4 | instructions for Zbs (single-bit instructions). Remove them. | ||
5 | |||
6 | Note that these instructions had already been removed for the 0.93 | ||
7 | version of the draft-B extention and have not been present in the | ||
8 | binutils patches circulating in January 2021. | ||
9 | |||
10 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | ||
14 | Message-id: 20210911140016.834071-7-philipp.tomsich@vrull.eu | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | target/riscv/insn32.decode | 7 ---- | ||
18 | target/riscv/insn_trans/trans_rvb.c.inc | 56 ------------------------- | ||
19 | 2 files changed, 63 deletions(-) | ||
20 | |||
21 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/insn32.decode | ||
24 | +++ b/target/riscv/insn32.decode | ||
25 | @@ -XXX,XX +XXX,XX @@ cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
26 | |||
27 | packw 0000100 .......... 100 ..... 0111011 @r | ||
28 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
29 | -bsetw 0010100 .......... 001 ..... 0111011 @r | ||
30 | -bclrw 0100100 .......... 001 ..... 0111011 @r | ||
31 | -binvw 0110100 .......... 001 ..... 0111011 @r | ||
32 | -bextw 0100100 .......... 101 ..... 0111011 @r | ||
33 | slow 0010000 .......... 001 ..... 0111011 @r | ||
34 | srow 0010000 .......... 101 ..... 0111011 @r | ||
35 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
36 | @@ -XXX,XX +XXX,XX @@ rolw 0110000 .......... 001 ..... 0111011 @r | ||
37 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
38 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
39 | |||
40 | -bsetiw 0010100 .......... 001 ..... 0011011 @sh5 | ||
41 | -bclriw 0100100 .......... 001 ..... 0011011 @sh5 | ||
42 | -binviw 0110100 .......... 001 ..... 0011011 @sh5 | ||
43 | sloiw 0010000 .......... 001 ..... 0011011 @sh5 | ||
44 | sroiw 0010000 .......... 101 ..... 0011011 @sh5 | ||
45 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
46 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
49 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
50 | @@ -XXX,XX +XXX,XX @@ static bool trans_packuw(DisasContext *ctx, arg_packuw *a) | ||
51 | return gen_arith(ctx, a, EXT_NONE, gen_packuw); | ||
52 | } | ||
53 | |||
54 | -static bool trans_bsetw(DisasContext *ctx, arg_bsetw *a) | ||
55 | -{ | ||
56 | - REQUIRE_64BIT(ctx); | ||
57 | - REQUIRE_EXT(ctx, RVB); | ||
58 | - ctx->w = true; | ||
59 | - return gen_shift(ctx, a, EXT_NONE, gen_bset); | ||
60 | -} | ||
61 | - | ||
62 | -static bool trans_bsetiw(DisasContext *ctx, arg_bsetiw *a) | ||
63 | -{ | ||
64 | - REQUIRE_64BIT(ctx); | ||
65 | - REQUIRE_EXT(ctx, RVB); | ||
66 | - ctx->w = true; | ||
67 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bset); | ||
68 | -} | ||
69 | - | ||
70 | -static bool trans_bclrw(DisasContext *ctx, arg_bclrw *a) | ||
71 | -{ | ||
72 | - REQUIRE_64BIT(ctx); | ||
73 | - REQUIRE_EXT(ctx, RVB); | ||
74 | - ctx->w = true; | ||
75 | - return gen_shift(ctx, a, EXT_NONE, gen_bclr); | ||
76 | -} | ||
77 | - | ||
78 | -static bool trans_bclriw(DisasContext *ctx, arg_bclriw *a) | ||
79 | -{ | ||
80 | - REQUIRE_64BIT(ctx); | ||
81 | - REQUIRE_EXT(ctx, RVB); | ||
82 | - ctx->w = true; | ||
83 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bclr); | ||
84 | -} | ||
85 | - | ||
86 | -static bool trans_binvw(DisasContext *ctx, arg_binvw *a) | ||
87 | -{ | ||
88 | - REQUIRE_64BIT(ctx); | ||
89 | - REQUIRE_EXT(ctx, RVB); | ||
90 | - ctx->w = true; | ||
91 | - return gen_shift(ctx, a, EXT_NONE, gen_binv); | ||
92 | -} | ||
93 | - | ||
94 | -static bool trans_binviw(DisasContext *ctx, arg_binviw *a) | ||
95 | -{ | ||
96 | - REQUIRE_64BIT(ctx); | ||
97 | - REQUIRE_EXT(ctx, RVB); | ||
98 | - ctx->w = true; | ||
99 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_binv); | ||
100 | -} | ||
101 | - | ||
102 | -static bool trans_bextw(DisasContext *ctx, arg_bextw *a) | ||
103 | -{ | ||
104 | - REQUIRE_64BIT(ctx); | ||
105 | - REQUIRE_EXT(ctx, RVB); | ||
106 | - ctx->w = true; | ||
107 | - return gen_shift(ctx, a, EXT_NONE, gen_bext); | ||
108 | -} | ||
109 | - | ||
110 | static bool trans_slow(DisasContext *ctx, arg_slow *a) | ||
111 | { | ||
112 | REQUIRE_64BIT(ctx); | ||
113 | -- | ||
114 | 2.31.1 | ||
115 | |||
116 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | The Zb[abcs] ratification package does not include the proposed | ||
4 | shift-one instructions. There currently is no clear plan to whether | ||
5 | these (or variants of them) will be ratified as Zbo (or a different | ||
6 | extension) or what the timeframe for such a decision could be. | ||
7 | |||
8 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | ||
12 | Message-id: 20210911140016.834071-8-philipp.tomsich@vrull.eu | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/insn32.decode | 8 --- | ||
16 | target/riscv/insn_trans/trans_rvb.c.inc | 70 ------------------------- | ||
17 | 2 files changed, 78 deletions(-) | ||
18 | |||
19 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/insn32.decode | ||
22 | +++ b/target/riscv/insn32.decode | ||
23 | @@ -XXX,XX +XXX,XX @@ bset 0010100 .......... 001 ..... 0110011 @r | ||
24 | bclr 0100100 .......... 001 ..... 0110011 @r | ||
25 | binv 0110100 .......... 001 ..... 0110011 @r | ||
26 | bext 0100100 .......... 101 ..... 0110011 @r | ||
27 | -slo 0010000 .......... 001 ..... 0110011 @r | ||
28 | -sro 0010000 .......... 101 ..... 0110011 @r | ||
29 | ror 0110000 .......... 101 ..... 0110011 @r | ||
30 | rol 0110000 .......... 001 ..... 0110011 @r | ||
31 | grev 0110100 .......... 101 ..... 0110011 @r | ||
32 | @@ -XXX,XX +XXX,XX @@ bseti 00101. ........... 001 ..... 0010011 @sh | ||
33 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
34 | binvi 01101. ........... 001 ..... 0010011 @sh | ||
35 | bexti 01001. ........... 101 ..... 0010011 @sh | ||
36 | -sloi 00100. ........... 001 ..... 0010011 @sh | ||
37 | -sroi 00100. ........... 101 ..... 0010011 @sh | ||
38 | rori 01100. ........... 101 ..... 0010011 @sh | ||
39 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
40 | gorci 00101. ........... 101 ..... 0010011 @sh | ||
41 | @@ -XXX,XX +XXX,XX @@ cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
42 | |||
43 | packw 0000100 .......... 100 ..... 0111011 @r | ||
44 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
45 | -slow 0010000 .......... 001 ..... 0111011 @r | ||
46 | -srow 0010000 .......... 101 ..... 0111011 @r | ||
47 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
48 | rolw 0110000 .......... 001 ..... 0111011 @r | ||
49 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
50 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
51 | |||
52 | -sloiw 0010000 .......... 001 ..... 0011011 @sh5 | ||
53 | -sroiw 0010000 .......... 101 ..... 0011011 @sh5 | ||
54 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
55 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
56 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
57 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
60 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
61 | @@ -XXX,XX +XXX,XX @@ static bool trans_bexti(DisasContext *ctx, arg_bexti *a) | ||
62 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext); | ||
63 | } | ||
64 | |||
65 | -static void gen_slo(TCGv ret, TCGv arg1, TCGv arg2) | ||
66 | -{ | ||
67 | - tcg_gen_not_tl(ret, arg1); | ||
68 | - tcg_gen_shl_tl(ret, ret, arg2); | ||
69 | - tcg_gen_not_tl(ret, ret); | ||
70 | -} | ||
71 | - | ||
72 | -static bool trans_slo(DisasContext *ctx, arg_slo *a) | ||
73 | -{ | ||
74 | - REQUIRE_EXT(ctx, RVB); | ||
75 | - return gen_shift(ctx, a, EXT_NONE, gen_slo); | ||
76 | -} | ||
77 | - | ||
78 | -static bool trans_sloi(DisasContext *ctx, arg_sloi *a) | ||
79 | -{ | ||
80 | - REQUIRE_EXT(ctx, RVB); | ||
81 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_slo); | ||
82 | -} | ||
83 | - | ||
84 | -static void gen_sro(TCGv ret, TCGv arg1, TCGv arg2) | ||
85 | -{ | ||
86 | - tcg_gen_not_tl(ret, arg1); | ||
87 | - tcg_gen_shr_tl(ret, ret, arg2); | ||
88 | - tcg_gen_not_tl(ret, ret); | ||
89 | -} | ||
90 | - | ||
91 | -static bool trans_sro(DisasContext *ctx, arg_sro *a) | ||
92 | -{ | ||
93 | - REQUIRE_EXT(ctx, RVB); | ||
94 | - return gen_shift(ctx, a, EXT_ZERO, gen_sro); | ||
95 | -} | ||
96 | - | ||
97 | -static bool trans_sroi(DisasContext *ctx, arg_sroi *a) | ||
98 | -{ | ||
99 | - REQUIRE_EXT(ctx, RVB); | ||
100 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_sro); | ||
101 | -} | ||
102 | - | ||
103 | static bool trans_ror(DisasContext *ctx, arg_ror *a) | ||
104 | { | ||
105 | REQUIRE_EXT(ctx, RVB); | ||
106 | @@ -XXX,XX +XXX,XX @@ static bool trans_packuw(DisasContext *ctx, arg_packuw *a) | ||
107 | return gen_arith(ctx, a, EXT_NONE, gen_packuw); | ||
108 | } | ||
109 | |||
110 | -static bool trans_slow(DisasContext *ctx, arg_slow *a) | ||
111 | -{ | ||
112 | - REQUIRE_64BIT(ctx); | ||
113 | - REQUIRE_EXT(ctx, RVB); | ||
114 | - ctx->w = true; | ||
115 | - return gen_shift(ctx, a, EXT_NONE, gen_slo); | ||
116 | -} | ||
117 | - | ||
118 | -static bool trans_sloiw(DisasContext *ctx, arg_sloiw *a) | ||
119 | -{ | ||
120 | - REQUIRE_64BIT(ctx); | ||
121 | - REQUIRE_EXT(ctx, RVB); | ||
122 | - ctx->w = true; | ||
123 | - return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_slo); | ||
124 | -} | ||
125 | - | ||
126 | -static bool trans_srow(DisasContext *ctx, arg_srow *a) | ||
127 | -{ | ||
128 | - REQUIRE_64BIT(ctx); | ||
129 | - REQUIRE_EXT(ctx, RVB); | ||
130 | - ctx->w = true; | ||
131 | - return gen_shift(ctx, a, EXT_ZERO, gen_sro); | ||
132 | -} | ||
133 | - | ||
134 | -static bool trans_sroiw(DisasContext *ctx, arg_sroiw *a) | ||
135 | -{ | ||
136 | - REQUIRE_64BIT(ctx); | ||
137 | - REQUIRE_EXT(ctx, RVB); | ||
138 | - ctx->w = true; | ||
139 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_sro); | ||
140 | -} | ||
141 | - | ||
142 | static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | ||
143 | { | ||
144 | TCGv_i32 t1 = tcg_temp_new_i32(); | ||
145 | -- | ||
146 | 2.31.1 | ||
147 | |||
148 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
1 | 2 | ||
3 | The following instructions are part of Zbs: | ||
4 | - b{set,clr,ext,inv} | ||
5 | - b{set,clr,ext,inv}i | ||
6 | |||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | ||
11 | Message-id: 20210911140016.834071-9-philipp.tomsich@vrull.eu | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/insn32.decode | 17 +++++++++-------- | ||
15 | target/riscv/insn_trans/trans_rvb.c.inc | 25 +++++++++++++++---------- | ||
16 | 2 files changed, 24 insertions(+), 18 deletions(-) | ||
17 | |||
18 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/insn32.decode | ||
21 | +++ b/target/riscv/insn32.decode | ||
22 | @@ -XXX,XX +XXX,XX @@ min 0000101 .......... 100 ..... 0110011 @r | ||
23 | minu 0000101 .......... 101 ..... 0110011 @r | ||
24 | max 0000101 .......... 110 ..... 0110011 @r | ||
25 | maxu 0000101 .......... 111 ..... 0110011 @r | ||
26 | -bset 0010100 .......... 001 ..... 0110011 @r | ||
27 | -bclr 0100100 .......... 001 ..... 0110011 @r | ||
28 | -binv 0110100 .......... 001 ..... 0110011 @r | ||
29 | -bext 0100100 .......... 101 ..... 0110011 @r | ||
30 | ror 0110000 .......... 101 ..... 0110011 @r | ||
31 | rol 0110000 .......... 001 ..... 0110011 @r | ||
32 | grev 0110100 .......... 101 ..... 0110011 @r | ||
33 | gorc 0010100 .......... 101 ..... 0110011 @r | ||
34 | |||
35 | -bseti 00101. ........... 001 ..... 0010011 @sh | ||
36 | -bclri 01001. ........... 001 ..... 0010011 @sh | ||
37 | -binvi 01101. ........... 001 ..... 0010011 @sh | ||
38 | -bexti 01001. ........... 101 ..... 0010011 @sh | ||
39 | rori 01100. ........... 101 ..... 0010011 @sh | ||
40 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
41 | gorci 00101. ........... 101 ..... 0010011 @sh | ||
42 | @@ -XXX,XX +XXX,XX @@ roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
43 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
44 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
45 | |||
46 | +# *** RV32 Zbs Standard Extension *** | ||
47 | +bclr 0100100 .......... 001 ..... 0110011 @r | ||
48 | +bclri 01001. ........... 001 ..... 0010011 @sh | ||
49 | +bext 0100100 .......... 101 ..... 0110011 @r | ||
50 | +bexti 01001. ........... 101 ..... 0010011 @sh | ||
51 | +binv 0110100 .......... 001 ..... 0110011 @r | ||
52 | +binvi 01101. ........... 001 ..... 0010011 @sh | ||
53 | +bset 0010100 .......... 001 ..... 0110011 @r | ||
54 | +bseti 00101. ........... 001 ..... 0010011 @sh | ||
55 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
58 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
59 | @@ -XXX,XX +XXX,XX @@ | ||
60 | /* | ||
61 | - * RISC-V translation routines for the RVB draft and Zba Standard Extension. | ||
62 | + * RISC-V translation routines for the RVB draft Zb[as] Standard Extension. | ||
63 | * | ||
64 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
65 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
66 | @@ -XXX,XX +XXX,XX @@ | ||
67 | } \ | ||
68 | } while (0) | ||
69 | |||
70 | +#define REQUIRE_ZBS(ctx) do { \ | ||
71 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ | ||
72 | + return false; \ | ||
73 | + } \ | ||
74 | +} while (0) | ||
75 | + | ||
76 | static void gen_clz(TCGv ret, TCGv arg1) | ||
77 | { | ||
78 | tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS); | ||
79 | } | ||
80 | - | ||
81 | static bool trans_clz(DisasContext *ctx, arg_clz *a) | ||
82 | { | ||
83 | REQUIRE_EXT(ctx, RVB); | ||
84 | @@ -XXX,XX +XXX,XX @@ static void gen_bset(TCGv ret, TCGv arg1, TCGv shamt) | ||
85 | |||
86 | static bool trans_bset(DisasContext *ctx, arg_bset *a) | ||
87 | { | ||
88 | - REQUIRE_EXT(ctx, RVB); | ||
89 | + REQUIRE_ZBS(ctx); | ||
90 | return gen_shift(ctx, a, EXT_NONE, gen_bset); | ||
91 | } | ||
92 | |||
93 | static bool trans_bseti(DisasContext *ctx, arg_bseti *a) | ||
94 | { | ||
95 | - REQUIRE_EXT(ctx, RVB); | ||
96 | + REQUIRE_ZBS(ctx); | ||
97 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bset); | ||
98 | } | ||
99 | |||
100 | @@ -XXX,XX +XXX,XX @@ static void gen_bclr(TCGv ret, TCGv arg1, TCGv shamt) | ||
101 | |||
102 | static bool trans_bclr(DisasContext *ctx, arg_bclr *a) | ||
103 | { | ||
104 | - REQUIRE_EXT(ctx, RVB); | ||
105 | + REQUIRE_ZBS(ctx); | ||
106 | return gen_shift(ctx, a, EXT_NONE, gen_bclr); | ||
107 | } | ||
108 | |||
109 | static bool trans_bclri(DisasContext *ctx, arg_bclri *a) | ||
110 | { | ||
111 | - REQUIRE_EXT(ctx, RVB); | ||
112 | + REQUIRE_ZBS(ctx); | ||
113 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bclr); | ||
114 | } | ||
115 | |||
116 | @@ -XXX,XX +XXX,XX @@ static void gen_binv(TCGv ret, TCGv arg1, TCGv shamt) | ||
117 | |||
118 | static bool trans_binv(DisasContext *ctx, arg_binv *a) | ||
119 | { | ||
120 | - REQUIRE_EXT(ctx, RVB); | ||
121 | + REQUIRE_ZBS(ctx); | ||
122 | return gen_shift(ctx, a, EXT_NONE, gen_binv); | ||
123 | } | ||
124 | |||
125 | static bool trans_binvi(DisasContext *ctx, arg_binvi *a) | ||
126 | { | ||
127 | - REQUIRE_EXT(ctx, RVB); | ||
128 | + REQUIRE_ZBS(ctx); | ||
129 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_binv); | ||
130 | } | ||
131 | |||
132 | @@ -XXX,XX +XXX,XX @@ static void gen_bext(TCGv ret, TCGv arg1, TCGv shamt) | ||
133 | |||
134 | static bool trans_bext(DisasContext *ctx, arg_bext *a) | ||
135 | { | ||
136 | - REQUIRE_EXT(ctx, RVB); | ||
137 | + REQUIRE_ZBS(ctx); | ||
138 | return gen_shift(ctx, a, EXT_NONE, gen_bext); | ||
139 | } | ||
140 | |||
141 | static bool trans_bexti(DisasContext *ctx, arg_bexti *a) | ||
142 | { | ||
143 | - REQUIRE_EXT(ctx, RVB); | ||
144 | + REQUIRE_ZBS(ctx); | ||
145 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_bext); | ||
146 | } | ||
147 | |||
148 | -- | ||
149 | 2.31.1 | ||
150 | |||
151 | diff view generated by jsdifflib |
1 | From: Jim Shu <cwshu@andestech.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | Currently, PMP permission checking of TLB page is bypassed if TLB hits | 3 | The following instructions are part of Zbc: |
4 | Fix it by propagating PMP permission to TLB page permission. | 4 | - clmul |
5 | - clmulh | ||
6 | - clmulr | ||
5 | 7 | ||
6 | PMP permission checking also use MMU-style API to change TLB permission | 8 | Note that these instructions were already defined in the pre-0.93 and |
7 | and size. | 9 | the 0.93 draft-B proposals, but had not been omitted in the earlier |
10 | addition of draft-B to QEmu. | ||
8 | 11 | ||
9 | Signed-off-by: Jim Shu <cwshu@andestech.com> | 12 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Message-id: 1613916082-19528-2-git-send-email-cwshu@andestech.com | 15 | Message-id: 20210911140016.834071-10-philipp.tomsich@vrull.eu |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 17 | --- |
14 | target/riscv/pmp.h | 4 +- | 18 | target/riscv/helper.h | 2 ++ |
15 | target/riscv/cpu_helper.c | 84 +++++++++++++++++++++++++++++---------- | 19 | target/riscv/insn32.decode | 5 ++++ |
16 | target/riscv/pmp.c | 80 +++++++++++++++++++++++++++---------- | 20 | target/riscv/bitmanip_helper.c | 27 +++++++++++++++++++++ |
17 | 3 files changed, 125 insertions(+), 43 deletions(-) | 21 | target/riscv/insn_trans/trans_rvb.c.inc | 32 ++++++++++++++++++++++++- |
22 | 4 files changed, 65 insertions(+), 1 deletion(-) | ||
18 | 23 | ||
19 | diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h | 24 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
20 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/pmp.h | 26 | --- a/target/riscv/helper.h |
22 | +++ b/target/riscv/pmp.h | 27 | +++ b/target/riscv/helper.h |
23 | @@ -XXX,XX +XXX,XX @@ void pmpaddr_csr_write(CPURISCVState *env, uint32_t addr_index, | 28 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
24 | target_ulong val); | 29 | DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
25 | target_ulong pmpaddr_csr_read(CPURISCVState *env, uint32_t addr_index); | 30 | DEF_HELPER_FLAGS_2(gorc, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
26 | bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | 31 | DEF_HELPER_FLAGS_2(gorcw, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
27 | - target_ulong size, pmp_priv_t priv, target_ulong mode); | 32 | +DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
28 | + target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs, | 33 | +DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
29 | + target_ulong mode); | 34 | |
30 | bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, | 35 | /* Special functions */ |
31 | target_ulong *tlb_size); | 36 | DEF_HELPER_2(csrr, tl, env, int) |
32 | void pmp_update_rule_addr(CPURISCVState *env, uint32_t pmp_index); | 37 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode |
33 | void pmp_update_rule_nums(CPURISCVState *env); | ||
34 | uint32_t pmp_get_num_rules(CPURISCVState *env); | ||
35 | +int pmp_priv_to_page_prot(pmp_priv_t pmp_priv); | ||
36 | |||
37 | #endif | ||
38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
39 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu_helper.c | 39 | --- a/target/riscv/insn32.decode |
41 | +++ b/target/riscv/cpu_helper.c | 40 | +++ b/target/riscv/insn32.decode |
42 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_set_mode(CPURISCVState *env, target_ulong newpriv) | 41 | @@ -XXX,XX +XXX,XX @@ roriw 0110000 .......... 101 ..... 0011011 @sh5 |
43 | env->load_res = -1; | 42 | greviw 0110100 .......... 101 ..... 0011011 @sh5 |
43 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
44 | |||
45 | +# *** RV32 Zbc Standard Extension *** | ||
46 | +clmul 0000101 .......... 001 ..... 0110011 @r | ||
47 | +clmulh 0000101 .......... 011 ..... 0110011 @r | ||
48 | +clmulr 0000101 .......... 010 ..... 0110011 @r | ||
49 | + | ||
50 | # *** RV32 Zbs Standard Extension *** | ||
51 | bclr 0100100 .......... 001 ..... 0110011 @r | ||
52 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
53 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/bitmanip_helper.c | ||
56 | +++ b/target/riscv/bitmanip_helper.c | ||
57 | @@ -XXX,XX +XXX,XX @@ | ||
58 | * | ||
59 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
60 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
61 | + * Copyright (c) 2021 Philipp Tomsich, philipp.tomsich@vrull.eu | ||
62 | * | ||
63 | * This program is free software; you can redistribute it and/or modify it | ||
64 | * under the terms and conditions of the GNU General Public License, | ||
65 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(gorcw)(target_ulong rs1, target_ulong rs2) | ||
66 | { | ||
67 | return do_gorc(rs1, rs2, 32); | ||
44 | } | 68 | } |
45 | 69 | + | |
46 | +/* | 70 | +target_ulong HELPER(clmul)(target_ulong rs1, target_ulong rs2) |
47 | + * get_physical_address_pmp - check PMP permission for this physical address | ||
48 | + * | ||
49 | + * Match the PMP region and check permission for this physical address and it's | ||
50 | + * TLB page. Returns 0 if the permission checking was successful | ||
51 | + * | ||
52 | + * @env: CPURISCVState | ||
53 | + * @prot: The returned protection attributes | ||
54 | + * @tlb_size: TLB page size containing addr. It could be modified after PMP | ||
55 | + * permission checking. NULL if not set TLB page for addr. | ||
56 | + * @addr: The physical address to be checked permission | ||
57 | + * @access_type: The type of MMU access | ||
58 | + * @mode: Indicates current privilege level. | ||
59 | + */ | ||
60 | +static int get_physical_address_pmp(CPURISCVState *env, int *prot, | ||
61 | + target_ulong *tlb_size, hwaddr addr, | ||
62 | + int size, MMUAccessType access_type, | ||
63 | + int mode) | ||
64 | +{ | 71 | +{ |
65 | + pmp_priv_t pmp_priv; | 72 | + target_ulong result = 0; |
66 | + target_ulong tlb_size_pmp = 0; | ||
67 | + | 73 | + |
68 | + if (!riscv_feature(env, RISCV_FEATURE_PMP)) { | 74 | + for (int i = 0; i < TARGET_LONG_BITS; i++) { |
69 | + *prot = PAGE_READ | PAGE_WRITE | PAGE_EXEC; | 75 | + if ((rs2 >> i) & 1) { |
70 | + return TRANSLATE_SUCCESS; | 76 | + result ^= (rs1 << i); |
71 | + } | ||
72 | + | ||
73 | + if (!pmp_hart_has_privs(env, addr, size, 1 << access_type, &pmp_priv, | ||
74 | + mode)) { | ||
75 | + *prot = 0; | ||
76 | + return TRANSLATE_PMP_FAIL; | ||
77 | + } | ||
78 | + | ||
79 | + *prot = pmp_priv_to_page_prot(pmp_priv); | ||
80 | + if (tlb_size != NULL) { | ||
81 | + if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) { | ||
82 | + *tlb_size = tlb_size_pmp; | ||
83 | + } | 77 | + } |
84 | + } | 78 | + } |
85 | + | 79 | + |
86 | + return TRANSLATE_SUCCESS; | 80 | + return result; |
87 | +} | 81 | +} |
88 | + | 82 | + |
89 | /* get_physical_address - get the physical address for this virtual address | 83 | +target_ulong HELPER(clmulr)(target_ulong rs1, target_ulong rs2) |
90 | * | 84 | +{ |
91 | * Do a page table walk to obtain the physical address corresponding to a | 85 | + target_ulong result = 0; |
92 | @@ -XXX,XX +XXX,XX @@ restart: | 86 | + |
93 | pte_addr = base + idx * ptesize; | 87 | + for (int i = 0; i < TARGET_LONG_BITS; i++) { |
94 | } | 88 | + if ((rs2 >> i) & 1) { |
95 | 89 | + result ^= (rs1 >> (TARGET_LONG_BITS - i - 1)); | |
96 | - if (riscv_feature(env, RISCV_FEATURE_PMP) && | ||
97 | - !pmp_hart_has_privs(env, pte_addr, sizeof(target_ulong), | ||
98 | - 1 << MMU_DATA_LOAD, PRV_S)) { | ||
99 | + int pmp_prot; | ||
100 | + int pmp_ret = get_physical_address_pmp(env, &pmp_prot, NULL, pte_addr, | ||
101 | + sizeof(target_ulong), | ||
102 | + MMU_DATA_LOAD, PRV_S); | ||
103 | + if (pmp_ret != TRANSLATE_SUCCESS) { | ||
104 | return TRANSLATE_PMP_FAIL; | ||
105 | } | ||
106 | |||
107 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
108 | #ifndef CONFIG_USER_ONLY | ||
109 | vaddr im_address; | ||
110 | hwaddr pa = 0; | ||
111 | - int prot, prot2; | ||
112 | + int prot, prot2, prot_pmp; | ||
113 | bool pmp_violation = false; | ||
114 | bool first_stage_error = true; | ||
115 | bool two_stage_lookup = false; | ||
116 | int ret = TRANSLATE_FAIL; | ||
117 | int mode = mmu_idx; | ||
118 | - target_ulong tlb_size = 0; | ||
119 | + /* default TLB page size */ | ||
120 | + target_ulong tlb_size = TARGET_PAGE_SIZE; | ||
121 | |||
122 | env->guest_phys_fault_addr = 0; | ||
123 | |||
124 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
125 | |||
126 | prot &= prot2; | ||
127 | |||
128 | - if (riscv_feature(env, RISCV_FEATURE_PMP) && | ||
129 | - (ret == TRANSLATE_SUCCESS) && | ||
130 | - !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) { | ||
131 | - ret = TRANSLATE_PMP_FAIL; | ||
132 | + if (ret == TRANSLATE_SUCCESS) { | ||
133 | + ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | ||
134 | + size, access_type, mode); | ||
135 | + prot &= prot_pmp; | ||
136 | } | ||
137 | |||
138 | if (ret != TRANSLATE_SUCCESS) { | ||
139 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
140 | "%s address=%" VADDR_PRIx " ret %d physical " | ||
141 | TARGET_FMT_plx " prot %d\n", | ||
142 | __func__, address, ret, pa, prot); | ||
143 | - } | ||
144 | |||
145 | - if (riscv_feature(env, RISCV_FEATURE_PMP) && | ||
146 | - (ret == TRANSLATE_SUCCESS) && | ||
147 | - !pmp_hart_has_privs(env, pa, size, 1 << access_type, mode)) { | ||
148 | - ret = TRANSLATE_PMP_FAIL; | ||
149 | + if (ret == TRANSLATE_SUCCESS) { | ||
150 | + ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | ||
151 | + size, access_type, mode); | ||
152 | + prot &= prot_pmp; | ||
153 | + } | 90 | + } |
154 | } | ||
155 | + | ||
156 | if (ret == TRANSLATE_PMP_FAIL) { | ||
157 | pmp_violation = true; | ||
158 | } | ||
159 | |||
160 | if (ret == TRANSLATE_SUCCESS) { | ||
161 | - if (pmp_is_range_in_tlb(env, pa & TARGET_PAGE_MASK, &tlb_size)) { | ||
162 | - tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1), | ||
163 | - prot, mmu_idx, tlb_size); | ||
164 | - } else { | ||
165 | - tlb_set_page(cs, address & TARGET_PAGE_MASK, pa & TARGET_PAGE_MASK, | ||
166 | - prot, mmu_idx, TARGET_PAGE_SIZE); | ||
167 | - } | ||
168 | + tlb_set_page(cs, address & ~(tlb_size - 1), pa & ~(tlb_size - 1), | ||
169 | + prot, mmu_idx, tlb_size); | ||
170 | return true; | ||
171 | } else if (probe) { | ||
172 | return false; | ||
173 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | ||
174 | index XXXXXXX..XXXXXXX 100644 | ||
175 | --- a/target/riscv/pmp.c | ||
176 | +++ b/target/riscv/pmp.c | ||
177 | @@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr) | ||
178 | return result; | ||
179 | } | ||
180 | |||
181 | +/* | ||
182 | + * Check if the address has required RWX privs when no PMP entry is matched. | ||
183 | + */ | ||
184 | +static bool pmp_hart_has_privs_default(CPURISCVState *env, target_ulong addr, | ||
185 | + target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs, | ||
186 | + target_ulong mode) | ||
187 | +{ | ||
188 | + bool ret; | ||
189 | + | ||
190 | + if ((!riscv_feature(env, RISCV_FEATURE_PMP)) || (mode == PRV_M)) { | ||
191 | + /* | ||
192 | + * Privileged spec v1.10 states if HW doesn't implement any PMP entry | ||
193 | + * or no PMP entry matches an M-Mode access, the access succeeds. | ||
194 | + */ | ||
195 | + ret = true; | ||
196 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
197 | + } else { | ||
198 | + /* | ||
199 | + * Other modes are not allowed to succeed if they don't * match a rule, | ||
200 | + * but there are rules. We've checked for no rule earlier in this | ||
201 | + * function. | ||
202 | + */ | ||
203 | + ret = false; | ||
204 | + *allowed_privs = 0; | ||
205 | + } | 91 | + } |
206 | + | 92 | + |
207 | + return ret; | 93 | + return result; |
94 | +} | ||
95 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
96 | index XXXXXXX..XXXXXXX 100644 | ||
97 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
98 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
99 | @@ -XXX,XX +XXX,XX @@ | ||
100 | /* | ||
101 | - * RISC-V translation routines for the RVB draft Zb[as] Standard Extension. | ||
102 | + * RISC-V translation routines for the Zb[acs] Standard Extension. | ||
103 | * | ||
104 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
105 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
106 | @@ -XXX,XX +XXX,XX @@ | ||
107 | } \ | ||
108 | } while (0) | ||
109 | |||
110 | +#define REQUIRE_ZBC(ctx) do { \ | ||
111 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ | ||
112 | + return false; \ | ||
113 | + } \ | ||
114 | +} while (0) | ||
115 | + | ||
116 | #define REQUIRE_ZBS(ctx) do { \ | ||
117 | if (!RISCV_CPU(ctx->cs)->cfg.ext_zbs) { \ | ||
118 | return false; \ | ||
119 | @@ -XXX,XX +XXX,XX @@ static bool trans_slli_uw(DisasContext *ctx, arg_slli_uw *a) | ||
120 | REQUIRE_ZBA(ctx); | ||
121 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_slli_uw); | ||
122 | } | ||
123 | + | ||
124 | +static bool trans_clmul(DisasContext *ctx, arg_clmul *a) | ||
125 | +{ | ||
126 | + REQUIRE_ZBC(ctx); | ||
127 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_clmul); | ||
208 | +} | 128 | +} |
209 | + | 129 | + |
210 | 130 | +static void gen_clmulh(TCGv dst, TCGv src1, TCGv src2) | |
211 | /* | 131 | +{ |
212 | * Public Interface | 132 | + gen_helper_clmulr(dst, src1, src2); |
213 | @@ -XXX,XX +XXX,XX @@ static int pmp_is_in_range(CPURISCVState *env, int pmp_index, target_ulong addr) | 133 | + tcg_gen_shri_tl(dst, dst, 1); |
214 | * Check if the address has required RWX privs to complete desired operation | 134 | +} |
215 | */ | ||
216 | bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | ||
217 | - target_ulong size, pmp_priv_t privs, target_ulong mode) | ||
218 | + target_ulong size, pmp_priv_t privs, pmp_priv_t *allowed_privs, | ||
219 | + target_ulong mode) | ||
220 | { | ||
221 | int i = 0; | ||
222 | int ret = -1; | ||
223 | int pmp_size = 0; | ||
224 | target_ulong s = 0; | ||
225 | target_ulong e = 0; | ||
226 | - pmp_priv_t allowed_privs = 0; | ||
227 | |||
228 | /* Short cut if no rules */ | ||
229 | if (0 == pmp_get_num_rules(env)) { | ||
230 | - return (env->priv == PRV_M) ? true : false; | ||
231 | + return pmp_hart_has_privs_default(env, addr, size, privs, | ||
232 | + allowed_privs, mode); | ||
233 | } | ||
234 | |||
235 | if (size == 0) { | ||
236 | @@ -XXX,XX +XXX,XX @@ bool pmp_hart_has_privs(CPURISCVState *env, target_ulong addr, | ||
237 | * check | ||
238 | */ | ||
239 | if (((s + e) == 2) && (PMP_AMATCH_OFF != a_field)) { | ||
240 | - allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
241 | + *allowed_privs = PMP_READ | PMP_WRITE | PMP_EXEC; | ||
242 | if ((mode != PRV_M) || pmp_is_locked(env, i)) { | ||
243 | - allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
244 | + *allowed_privs &= env->pmp_state.pmp[i].cfg_reg; | ||
245 | } | ||
246 | |||
247 | - if ((privs & allowed_privs) == privs) { | ||
248 | - ret = 1; | ||
249 | - break; | ||
250 | - } else { | ||
251 | - ret = 0; | ||
252 | - break; | ||
253 | - } | ||
254 | + ret = ((privs & *allowed_privs) == privs); | ||
255 | + break; | ||
256 | } | ||
257 | } | ||
258 | |||
259 | /* No rule matched */ | ||
260 | if (ret == -1) { | ||
261 | - if (mode == PRV_M) { | ||
262 | - ret = 1; /* Privileged spec v1.10 states if no PMP entry matches an | ||
263 | - * M-Mode access, the access succeeds */ | ||
264 | - } else { | ||
265 | - ret = 0; /* Other modes are not allowed to succeed if they don't | ||
266 | - * match a rule, but there are rules. We've checked for | ||
267 | - * no rule earlier in this function. */ | ||
268 | - } | ||
269 | + return pmp_hart_has_privs_default(env, addr, size, privs, | ||
270 | + allowed_privs, mode); | ||
271 | } | ||
272 | |||
273 | return ret == 1 ? true : false; | ||
274 | } | ||
275 | |||
276 | - | ||
277 | /* | ||
278 | * Handle a write to a pmpcfg CSP | ||
279 | */ | ||
280 | @@ -XXX,XX +XXX,XX @@ bool pmp_is_range_in_tlb(CPURISCVState *env, hwaddr tlb_sa, | ||
281 | |||
282 | return false; | ||
283 | } | ||
284 | + | 135 | + |
285 | +/* | 136 | +static bool trans_clmulh(DisasContext *ctx, arg_clmulr *a) |
286 | + * Convert PMP privilege to TLB page privilege. | ||
287 | + */ | ||
288 | +int pmp_priv_to_page_prot(pmp_priv_t pmp_priv) | ||
289 | +{ | 137 | +{ |
290 | + int prot = 0; | 138 | + REQUIRE_ZBC(ctx); |
139 | + return gen_arith(ctx, a, EXT_NONE, gen_clmulh); | ||
140 | +} | ||
291 | + | 141 | + |
292 | + if (pmp_priv & PMP_READ) { | 142 | +static bool trans_clmulr(DisasContext *ctx, arg_clmulh *a) |
293 | + prot |= PAGE_READ; | 143 | +{ |
294 | + } | 144 | + REQUIRE_ZBC(ctx); |
295 | + if (pmp_priv & PMP_WRITE) { | 145 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_clmulr); |
296 | + prot |= PAGE_WRITE; | ||
297 | + } | ||
298 | + if (pmp_priv & PMP_EXEC) { | ||
299 | + prot |= PAGE_EXEC; | ||
300 | + } | ||
301 | + | ||
302 | + return prot; | ||
303 | +} | 146 | +} |
304 | -- | 147 | -- |
305 | 2.30.1 | 148 | 2.31.1 |
306 | 149 | ||
307 | 150 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | |
2 | |||
3 | This reassigns the instructions that are part of Zbb into it, with the | ||
4 | notable exceptions of the instructions (rev8, zext.w and orc.b) that | ||
5 | changed due to gorci, grevi and pack not being part of Zb[abcs]. | ||
6 | |||
7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Acked-by: Bin Meng <bmeng.cn@gmail.com> | ||
11 | Message-id: 20210911140016.834071-11-philipp.tomsich@vrull.eu | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/insn32.decode | 40 ++++++++++--------- | ||
15 | target/riscv/insn_trans/trans_rvb.c.inc | 51 ++++++++++++++----------- | ||
16 | 2 files changed, 50 insertions(+), 41 deletions(-) | ||
17 | |||
18 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/insn32.decode | ||
21 | +++ b/target/riscv/insn32.decode | ||
22 | @@ -XXX,XX +XXX,XX @@ sh2add_uw 0010000 .......... 100 ..... 0111011 @r | ||
23 | sh3add_uw 0010000 .......... 110 ..... 0111011 @r | ||
24 | slli_uw 00001 ............ 001 ..... 0011011 @sh | ||
25 | |||
26 | -# *** RV32B Standard Extension *** | ||
27 | +# *** RV32 Zbb Standard Extension *** | ||
28 | +andn 0100000 .......... 111 ..... 0110011 @r | ||
29 | clz 011000 000000 ..... 001 ..... 0010011 @r2 | ||
30 | -ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
31 | cpop 011000 000010 ..... 001 ..... 0010011 @r2 | ||
32 | +ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
33 | +max 0000101 .......... 110 ..... 0110011 @r | ||
34 | +maxu 0000101 .......... 111 ..... 0110011 @r | ||
35 | +min 0000101 .......... 100 ..... 0110011 @r | ||
36 | +minu 0000101 .......... 101 ..... 0110011 @r | ||
37 | +orn 0100000 .......... 110 ..... 0110011 @r | ||
38 | +rol 0110000 .......... 001 ..... 0110011 @r | ||
39 | +ror 0110000 .......... 101 ..... 0110011 @r | ||
40 | +rori 01100 ............ 101 ..... 0010011 @sh | ||
41 | sext_b 011000 000100 ..... 001 ..... 0010011 @r2 | ||
42 | sext_h 011000 000101 ..... 001 ..... 0010011 @r2 | ||
43 | - | ||
44 | -andn 0100000 .......... 111 ..... 0110011 @r | ||
45 | -orn 0100000 .......... 110 ..... 0110011 @r | ||
46 | xnor 0100000 .......... 100 ..... 0110011 @r | ||
47 | + | ||
48 | +# *** RV64 Zbb Standard Extension (in addition to RV32 Zbb) *** | ||
49 | +clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
50 | +ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
51 | +cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
52 | +rolw 0110000 .......... 001 ..... 0111011 @r | ||
53 | +roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
54 | +rorw 0110000 .......... 101 ..... 0111011 @r | ||
55 | + | ||
56 | +# *** RV32B Standard Extension *** | ||
57 | pack 0000100 .......... 100 ..... 0110011 @r | ||
58 | packu 0100100 .......... 100 ..... 0110011 @r | ||
59 | packh 0000100 .......... 111 ..... 0110011 @r | ||
60 | -min 0000101 .......... 100 ..... 0110011 @r | ||
61 | -minu 0000101 .......... 101 ..... 0110011 @r | ||
62 | -max 0000101 .......... 110 ..... 0110011 @r | ||
63 | -maxu 0000101 .......... 111 ..... 0110011 @r | ||
64 | -ror 0110000 .......... 101 ..... 0110011 @r | ||
65 | -rol 0110000 .......... 001 ..... 0110011 @r | ||
66 | grev 0110100 .......... 101 ..... 0110011 @r | ||
67 | gorc 0010100 .......... 101 ..... 0110011 @r | ||
68 | |||
69 | -rori 01100. ........... 101 ..... 0010011 @sh | ||
70 | grevi 01101. ........... 101 ..... 0010011 @sh | ||
71 | gorci 00101. ........... 101 ..... 0010011 @sh | ||
72 | |||
73 | # *** RV64B Standard Extension (in addition to RV32B) *** | ||
74 | -clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
75 | -ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
76 | -cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
77 | - | ||
78 | packw 0000100 .......... 100 ..... 0111011 @r | ||
79 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
80 | -rorw 0110000 .......... 101 ..... 0111011 @r | ||
81 | -rolw 0110000 .......... 001 ..... 0111011 @r | ||
82 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
83 | gorcw 0010100 .......... 101 ..... 0111011 @r | ||
84 | |||
85 | -roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
86 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
87 | gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
88 | |||
89 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
92 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | /* | ||
95 | - * RISC-V translation routines for the Zb[acs] Standard Extension. | ||
96 | + * RISC-V translation routines for the Zb[abcs] Standard Extension. | ||
97 | * | ||
98 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
99 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
100 | @@ -XXX,XX +XXX,XX @@ | ||
101 | } \ | ||
102 | } while (0) | ||
103 | |||
104 | +#define REQUIRE_ZBB(ctx) do { \ | ||
105 | + if (!RISCV_CPU(ctx->cs)->cfg.ext_zbb) { \ | ||
106 | + return false; \ | ||
107 | + } \ | ||
108 | +} while (0) | ||
109 | + | ||
110 | #define REQUIRE_ZBC(ctx) do { \ | ||
111 | if (!RISCV_CPU(ctx->cs)->cfg.ext_zbc) { \ | ||
112 | return false; \ | ||
113 | @@ -XXX,XX +XXX,XX @@ static void gen_clz(TCGv ret, TCGv arg1) | ||
114 | { | ||
115 | tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS); | ||
116 | } | ||
117 | + | ||
118 | static bool trans_clz(DisasContext *ctx, arg_clz *a) | ||
119 | { | ||
120 | - REQUIRE_EXT(ctx, RVB); | ||
121 | + REQUIRE_ZBB(ctx); | ||
122 | return gen_unary(ctx, a, EXT_ZERO, gen_clz); | ||
123 | } | ||
124 | |||
125 | @@ -XXX,XX +XXX,XX @@ static void gen_ctz(TCGv ret, TCGv arg1) | ||
126 | |||
127 | static bool trans_ctz(DisasContext *ctx, arg_ctz *a) | ||
128 | { | ||
129 | - REQUIRE_EXT(ctx, RVB); | ||
130 | + REQUIRE_ZBB(ctx); | ||
131 | return gen_unary(ctx, a, EXT_ZERO, gen_ctz); | ||
132 | } | ||
133 | |||
134 | static bool trans_cpop(DisasContext *ctx, arg_cpop *a) | ||
135 | { | ||
136 | - REQUIRE_EXT(ctx, RVB); | ||
137 | + REQUIRE_ZBB(ctx); | ||
138 | return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl); | ||
139 | } | ||
140 | |||
141 | static bool trans_andn(DisasContext *ctx, arg_andn *a) | ||
142 | { | ||
143 | - REQUIRE_EXT(ctx, RVB); | ||
144 | + REQUIRE_ZBB(ctx); | ||
145 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_andc_tl); | ||
146 | } | ||
147 | |||
148 | static bool trans_orn(DisasContext *ctx, arg_orn *a) | ||
149 | { | ||
150 | - REQUIRE_EXT(ctx, RVB); | ||
151 | + REQUIRE_ZBB(ctx); | ||
152 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_orc_tl); | ||
153 | } | ||
154 | |||
155 | static bool trans_xnor(DisasContext *ctx, arg_xnor *a) | ||
156 | { | ||
157 | - REQUIRE_EXT(ctx, RVB); | ||
158 | + REQUIRE_ZBB(ctx); | ||
159 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_eqv_tl); | ||
160 | } | ||
161 | |||
162 | @@ -XXX,XX +XXX,XX @@ static bool trans_packh(DisasContext *ctx, arg_packh *a) | ||
163 | |||
164 | static bool trans_min(DisasContext *ctx, arg_min *a) | ||
165 | { | ||
166 | - REQUIRE_EXT(ctx, RVB); | ||
167 | + REQUIRE_ZBB(ctx); | ||
168 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_smin_tl); | ||
169 | } | ||
170 | |||
171 | static bool trans_max(DisasContext *ctx, arg_max *a) | ||
172 | { | ||
173 | - REQUIRE_EXT(ctx, RVB); | ||
174 | + REQUIRE_ZBB(ctx); | ||
175 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_smax_tl); | ||
176 | } | ||
177 | |||
178 | static bool trans_minu(DisasContext *ctx, arg_minu *a) | ||
179 | { | ||
180 | - REQUIRE_EXT(ctx, RVB); | ||
181 | + REQUIRE_ZBB(ctx); | ||
182 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_umin_tl); | ||
183 | } | ||
184 | |||
185 | static bool trans_maxu(DisasContext *ctx, arg_maxu *a) | ||
186 | { | ||
187 | - REQUIRE_EXT(ctx, RVB); | ||
188 | + REQUIRE_ZBB(ctx); | ||
189 | return gen_arith(ctx, a, EXT_SIGN, tcg_gen_umax_tl); | ||
190 | } | ||
191 | |||
192 | static bool trans_sext_b(DisasContext *ctx, arg_sext_b *a) | ||
193 | { | ||
194 | - REQUIRE_EXT(ctx, RVB); | ||
195 | + REQUIRE_ZBB(ctx); | ||
196 | return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext8s_tl); | ||
197 | } | ||
198 | |||
199 | static bool trans_sext_h(DisasContext *ctx, arg_sext_h *a) | ||
200 | { | ||
201 | - REQUIRE_EXT(ctx, RVB); | ||
202 | + REQUIRE_ZBB(ctx); | ||
203 | return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16s_tl); | ||
204 | } | ||
205 | |||
206 | @@ -XXX,XX +XXX,XX @@ static bool trans_bexti(DisasContext *ctx, arg_bexti *a) | ||
207 | |||
208 | static bool trans_ror(DisasContext *ctx, arg_ror *a) | ||
209 | { | ||
210 | - REQUIRE_EXT(ctx, RVB); | ||
211 | + REQUIRE_ZBB(ctx); | ||
212 | return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotr_tl); | ||
213 | } | ||
214 | |||
215 | static bool trans_rori(DisasContext *ctx, arg_rori *a) | ||
216 | { | ||
217 | - REQUIRE_EXT(ctx, RVB); | ||
218 | + REQUIRE_ZBB(ctx); | ||
219 | return gen_shift_imm_fn(ctx, a, EXT_NONE, tcg_gen_rotri_tl); | ||
220 | } | ||
221 | |||
222 | static bool trans_rol(DisasContext *ctx, arg_rol *a) | ||
223 | { | ||
224 | - REQUIRE_EXT(ctx, RVB); | ||
225 | + REQUIRE_ZBB(ctx); | ||
226 | return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl); | ||
227 | } | ||
228 | |||
229 | @@ -XXX,XX +XXX,XX @@ static void gen_clzw(TCGv ret, TCGv arg1) | ||
230 | static bool trans_clzw(DisasContext *ctx, arg_clzw *a) | ||
231 | { | ||
232 | REQUIRE_64BIT(ctx); | ||
233 | - REQUIRE_EXT(ctx, RVB); | ||
234 | + REQUIRE_ZBB(ctx); | ||
235 | return gen_unary(ctx, a, EXT_NONE, gen_clzw); | ||
236 | } | ||
237 | |||
238 | @@ -XXX,XX +XXX,XX @@ static void gen_ctzw(TCGv ret, TCGv arg1) | ||
239 | static bool trans_ctzw(DisasContext *ctx, arg_ctzw *a) | ||
240 | { | ||
241 | REQUIRE_64BIT(ctx); | ||
242 | - REQUIRE_EXT(ctx, RVB); | ||
243 | + REQUIRE_ZBB(ctx); | ||
244 | return gen_unary(ctx, a, EXT_NONE, gen_ctzw); | ||
245 | } | ||
246 | |||
247 | static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a) | ||
248 | { | ||
249 | REQUIRE_64BIT(ctx); | ||
250 | - REQUIRE_EXT(ctx, RVB); | ||
251 | + REQUIRE_ZBB(ctx); | ||
252 | ctx->w = true; | ||
253 | return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl); | ||
254 | } | ||
255 | @@ -XXX,XX +XXX,XX @@ static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | ||
256 | static bool trans_rorw(DisasContext *ctx, arg_rorw *a) | ||
257 | { | ||
258 | REQUIRE_64BIT(ctx); | ||
259 | - REQUIRE_EXT(ctx, RVB); | ||
260 | + REQUIRE_ZBB(ctx); | ||
261 | ctx->w = true; | ||
262 | return gen_shift(ctx, a, EXT_NONE, gen_rorw); | ||
263 | } | ||
264 | @@ -XXX,XX +XXX,XX @@ static bool trans_rorw(DisasContext *ctx, arg_rorw *a) | ||
265 | static bool trans_roriw(DisasContext *ctx, arg_roriw *a) | ||
266 | { | ||
267 | REQUIRE_64BIT(ctx); | ||
268 | - REQUIRE_EXT(ctx, RVB); | ||
269 | + REQUIRE_ZBB(ctx); | ||
270 | ctx->w = true; | ||
271 | return gen_shift_imm_tl(ctx, a, EXT_NONE, gen_rorw); | ||
272 | } | ||
273 | @@ -XXX,XX +XXX,XX @@ static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2) | ||
274 | static bool trans_rolw(DisasContext *ctx, arg_rolw *a) | ||
275 | { | ||
276 | REQUIRE_64BIT(ctx); | ||
277 | - REQUIRE_EXT(ctx, RVB); | ||
278 | + REQUIRE_ZBB(ctx); | ||
279 | ctx->w = true; | ||
280 | return gen_shift(ctx, a, EXT_NONE, gen_rolw); | ||
281 | } | ||
282 | -- | ||
283 | 2.31.1 | ||
284 | |||
285 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | When decode_insn16() fails, we fall back to decode_RV32_64C() for | 3 | The 1.0.0 version of Zbb does not contain gorc/gorci. Instead, a |
4 | further compressed instruction decoding. However, prior to this change, | 4 | orc.b instruction (equivalent to the orc.b pseudo-instruction built on |
5 | we did not raise an illegal instruction exception, if decode_RV32_64C() | 5 | gorci from pre-0.93 draft-B) is available, mainly targeting |
6 | fails to decode the instruction. This means that we skipped illegal | 6 | string-processing workloads. |
7 | compressed instructions instead of raising an illegal instruction | ||
8 | exception. | ||
9 | 7 | ||
10 | Instead of patching decode_RV32_64C(), we can just remove it, | 8 | This commit adds the new orc.b instruction and removed gorc/gorci. |
11 | as it is dead code since f330433b363 anyway. | ||
12 | 9 | ||
13 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 10 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Message-id: 20210911140016.834071-12-philipp.tomsich@vrull.eu |
16 | Message-id: 20210322121609.3097928-1-georg.kotheimer@kernkonzept.com | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 15 | --- |
19 | target/riscv/translate.c | 179 +-------------------------------------- | 16 | target/riscv/helper.h | 2 -- |
20 | 1 file changed, 1 insertion(+), 178 deletions(-) | 17 | target/riscv/insn32.decode | 6 +--- |
18 | target/riscv/bitmanip_helper.c | 26 ----------------- | ||
19 | target/riscv/insn_trans/trans_rvb.c.inc | 39 +++++++++++-------------- | ||
20 | 4 files changed, 18 insertions(+), 55 deletions(-) | ||
21 | 21 | ||
22 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | 22 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
23 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/translate.c | 24 | --- a/target/riscv/helper.h |
25 | +++ b/target/riscv/translate.c | 25 | +++ b/target/riscv/helper.h |
26 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 26 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) |
27 | CPUState *cs; | 27 | /* Bitmanip */ |
28 | } DisasContext; | 28 | DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
29 | 29 | DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) | |
30 | -#ifdef TARGET_RISCV64 | 30 | -DEF_HELPER_FLAGS_2(gorc, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
31 | -/* convert riscv funct3 to qemu memop for load/store */ | 31 | -DEF_HELPER_FLAGS_2(gorcw, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
32 | -static const int tcg_memop_lookup[8] = { | 32 | DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
33 | - [0 ... 7] = -1, | 33 | DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
34 | - [0] = MO_SB, | 34 | |
35 | - [1] = MO_TESW, | 35 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode |
36 | - [2] = MO_TESL, | 36 | index XXXXXXX..XXXXXXX 100644 |
37 | - [3] = MO_TEQ, | 37 | --- a/target/riscv/insn32.decode |
38 | - [4] = MO_UB, | 38 | +++ b/target/riscv/insn32.decode |
39 | - [5] = MO_TEUW, | 39 | @@ -XXX,XX +XXX,XX @@ max 0000101 .......... 110 ..... 0110011 @r |
40 | - [6] = MO_TEUL, | 40 | maxu 0000101 .......... 111 ..... 0110011 @r |
41 | -}; | 41 | min 0000101 .......... 100 ..... 0110011 @r |
42 | -#endif | 42 | minu 0000101 .......... 101 ..... 0110011 @r |
43 | +orc_b 001010 000111 ..... 101 ..... 0010011 @r2 | ||
44 | orn 0100000 .......... 110 ..... 0110011 @r | ||
45 | rol 0110000 .......... 001 ..... 0110011 @r | ||
46 | ror 0110000 .......... 101 ..... 0110011 @r | ||
47 | @@ -XXX,XX +XXX,XX @@ pack 0000100 .......... 100 ..... 0110011 @r | ||
48 | packu 0100100 .......... 100 ..... 0110011 @r | ||
49 | packh 0000100 .......... 111 ..... 0110011 @r | ||
50 | grev 0110100 .......... 101 ..... 0110011 @r | ||
51 | -gorc 0010100 .......... 101 ..... 0110011 @r | ||
43 | - | 52 | - |
44 | #ifdef TARGET_RISCV64 | 53 | grevi 01101. ........... 101 ..... 0010011 @sh |
45 | #define CASE_OP_32_64(X) case X: case glue(X, W) | 54 | -gorci 00101. ........... 101 ..... 0010011 @sh |
46 | #else | 55 | |
47 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | 56 | # *** RV64B Standard Extension (in addition to RV32B) *** |
48 | ctx->base.is_jmp = DISAS_NORETURN; | 57 | packw 0000100 .......... 100 ..... 0111011 @r |
58 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
59 | grevw 0110100 .......... 101 ..... 0111011 @r | ||
60 | -gorcw 0010100 .......... 101 ..... 0111011 @r | ||
61 | |||
62 | greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
63 | -gorciw 0010100 .......... 101 ..... 0011011 @sh5 | ||
64 | |||
65 | # *** RV32 Zbc Standard Extension *** | ||
66 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
67 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
68 | index XXXXXXX..XXXXXXX 100644 | ||
69 | --- a/target/riscv/bitmanip_helper.c | ||
70 | +++ b/target/riscv/bitmanip_helper.c | ||
71 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(grevw)(target_ulong rs1, target_ulong rs2) | ||
72 | return do_grev(rs1, rs2, 32); | ||
49 | } | 73 | } |
50 | 74 | ||
51 | -#ifdef TARGET_RISCV64 | 75 | -static target_ulong do_gorc(target_ulong rs1, |
52 | -static void gen_load_c(DisasContext *ctx, uint32_t opc, int rd, int rs1, | 76 | - target_ulong rs2, |
53 | - target_long imm) | 77 | - int bits) |
54 | -{ | 78 | -{ |
55 | - TCGv t0 = tcg_temp_new(); | 79 | - target_ulong x = rs1; |
56 | - TCGv t1 = tcg_temp_new(); | 80 | - int i, shift; |
57 | - gen_get_gpr(t0, rs1); | ||
58 | - tcg_gen_addi_tl(t0, t0, imm); | ||
59 | - int memop = tcg_memop_lookup[(opc >> 12) & 0x7]; | ||
60 | - | 81 | - |
61 | - if (memop < 0) { | 82 | - for (i = 0, shift = 1; shift < bits; i++, shift <<= 1) { |
62 | - gen_exception_illegal(ctx); | 83 | - if (rs2 & shift) { |
63 | - return; | 84 | - x |= do_swap(x, adjacent_masks[i], shift); |
85 | - } | ||
64 | - } | 86 | - } |
65 | - | 87 | - |
66 | - tcg_gen_qemu_ld_tl(t1, t0, ctx->mem_idx, memop); | 88 | - return x; |
67 | - gen_set_gpr(rd, t1); | ||
68 | - tcg_temp_free(t0); | ||
69 | - tcg_temp_free(t1); | ||
70 | -} | 89 | -} |
71 | - | 90 | - |
72 | -static void gen_store_c(DisasContext *ctx, uint32_t opc, int rs1, int rs2, | 91 | -target_ulong HELPER(gorc)(target_ulong rs1, target_ulong rs2) |
73 | - target_long imm) | ||
74 | -{ | 92 | -{ |
75 | - TCGv t0 = tcg_temp_new(); | 93 | - return do_gorc(rs1, rs2, TARGET_LONG_BITS); |
76 | - TCGv dat = tcg_temp_new(); | ||
77 | - gen_get_gpr(t0, rs1); | ||
78 | - tcg_gen_addi_tl(t0, t0, imm); | ||
79 | - gen_get_gpr(dat, rs2); | ||
80 | - int memop = tcg_memop_lookup[(opc >> 12) & 0x7]; | ||
81 | - | ||
82 | - if (memop < 0) { | ||
83 | - gen_exception_illegal(ctx); | ||
84 | - return; | ||
85 | - } | ||
86 | - | ||
87 | - tcg_gen_qemu_st_tl(dat, t0, ctx->mem_idx, memop); | ||
88 | - tcg_temp_free(t0); | ||
89 | - tcg_temp_free(dat); | ||
90 | -} | ||
91 | -#endif | ||
92 | - | ||
93 | #ifndef CONFIG_USER_ONLY | ||
94 | /* The states of mstatus_fs are: | ||
95 | * 0 = disabled, 1 = initial, 2 = clean, 3 = dirty | ||
96 | @@ -XXX,XX +XXX,XX @@ static void mark_fs_dirty(DisasContext *ctx) | ||
97 | static inline void mark_fs_dirty(DisasContext *ctx) { } | ||
98 | #endif | ||
99 | |||
100 | -#if !defined(TARGET_RISCV64) | ||
101 | -static void gen_fp_load(DisasContext *ctx, uint32_t opc, int rd, | ||
102 | - int rs1, target_long imm) | ||
103 | -{ | ||
104 | - TCGv t0; | ||
105 | - | ||
106 | - if (ctx->mstatus_fs == 0) { | ||
107 | - gen_exception_illegal(ctx); | ||
108 | - return; | ||
109 | - } | ||
110 | - | ||
111 | - t0 = tcg_temp_new(); | ||
112 | - gen_get_gpr(t0, rs1); | ||
113 | - tcg_gen_addi_tl(t0, t0, imm); | ||
114 | - | ||
115 | - switch (opc) { | ||
116 | - case OPC_RISC_FLW: | ||
117 | - if (!has_ext(ctx, RVF)) { | ||
118 | - goto do_illegal; | ||
119 | - } | ||
120 | - tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEUL); | ||
121 | - /* RISC-V requires NaN-boxing of narrower width floating point values */ | ||
122 | - tcg_gen_ori_i64(cpu_fpr[rd], cpu_fpr[rd], 0xffffffff00000000ULL); | ||
123 | - break; | ||
124 | - case OPC_RISC_FLD: | ||
125 | - if (!has_ext(ctx, RVD)) { | ||
126 | - goto do_illegal; | ||
127 | - } | ||
128 | - tcg_gen_qemu_ld_i64(cpu_fpr[rd], t0, ctx->mem_idx, MO_TEQ); | ||
129 | - break; | ||
130 | - do_illegal: | ||
131 | - default: | ||
132 | - gen_exception_illegal(ctx); | ||
133 | - break; | ||
134 | - } | ||
135 | - tcg_temp_free(t0); | ||
136 | - | ||
137 | - mark_fs_dirty(ctx); | ||
138 | -} | 94 | -} |
139 | - | 95 | - |
140 | -static void gen_fp_store(DisasContext *ctx, uint32_t opc, int rs1, | 96 | -target_ulong HELPER(gorcw)(target_ulong rs1, target_ulong rs2) |
141 | - int rs2, target_long imm) | ||
142 | -{ | 97 | -{ |
143 | - TCGv t0; | 98 | - return do_gorc(rs1, rs2, 32); |
144 | - | ||
145 | - if (ctx->mstatus_fs == 0) { | ||
146 | - gen_exception_illegal(ctx); | ||
147 | - return; | ||
148 | - } | ||
149 | - | ||
150 | - t0 = tcg_temp_new(); | ||
151 | - gen_get_gpr(t0, rs1); | ||
152 | - tcg_gen_addi_tl(t0, t0, imm); | ||
153 | - | ||
154 | - switch (opc) { | ||
155 | - case OPC_RISC_FSW: | ||
156 | - if (!has_ext(ctx, RVF)) { | ||
157 | - goto do_illegal; | ||
158 | - } | ||
159 | - tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEUL); | ||
160 | - break; | ||
161 | - case OPC_RISC_FSD: | ||
162 | - if (!has_ext(ctx, RVD)) { | ||
163 | - goto do_illegal; | ||
164 | - } | ||
165 | - tcg_gen_qemu_st_i64(cpu_fpr[rs2], t0, ctx->mem_idx, MO_TEQ); | ||
166 | - break; | ||
167 | - do_illegal: | ||
168 | - default: | ||
169 | - gen_exception_illegal(ctx); | ||
170 | - break; | ||
171 | - } | ||
172 | - | ||
173 | - tcg_temp_free(t0); | ||
174 | -} | ||
175 | -#endif | ||
176 | - | ||
177 | static void gen_set_rm(DisasContext *ctx, int rm) | ||
178 | { | ||
179 | TCGv_i32 t0; | ||
180 | @@ -XXX,XX +XXX,XX @@ static void gen_set_rm(DisasContext *ctx, int rm) | ||
181 | tcg_temp_free_i32(t0); | ||
182 | } | ||
183 | |||
184 | -static void decode_RV32_64C0(DisasContext *ctx, uint16_t opcode) | ||
185 | -{ | ||
186 | - uint8_t funct3 = extract16(opcode, 13, 3); | ||
187 | - uint8_t rd_rs2 = GET_C_RS2S(opcode); | ||
188 | - uint8_t rs1s = GET_C_RS1S(opcode); | ||
189 | - | ||
190 | - switch (funct3) { | ||
191 | - case 3: | ||
192 | -#if defined(TARGET_RISCV64) | ||
193 | - /* C.LD(RV64/128) -> ld rd', offset[7:3](rs1')*/ | ||
194 | - gen_load_c(ctx, OPC_RISC_LD, rd_rs2, rs1s, | ||
195 | - GET_C_LD_IMM(opcode)); | ||
196 | -#else | ||
197 | - /* C.FLW (RV32) -> flw rd', offset[6:2](rs1')*/ | ||
198 | - gen_fp_load(ctx, OPC_RISC_FLW, rd_rs2, rs1s, | ||
199 | - GET_C_LW_IMM(opcode)); | ||
200 | -#endif | ||
201 | - break; | ||
202 | - case 7: | ||
203 | -#if defined(TARGET_RISCV64) | ||
204 | - /* C.SD (RV64/128) -> sd rs2', offset[7:3](rs1')*/ | ||
205 | - gen_store_c(ctx, OPC_RISC_SD, rs1s, rd_rs2, | ||
206 | - GET_C_LD_IMM(opcode)); | ||
207 | -#else | ||
208 | - /* C.FSW (RV32) -> fsw rs2', offset[6:2](rs1')*/ | ||
209 | - gen_fp_store(ctx, OPC_RISC_FSW, rs1s, rd_rs2, | ||
210 | - GET_C_LW_IMM(opcode)); | ||
211 | -#endif | ||
212 | - break; | ||
213 | - } | ||
214 | -} | 99 | -} |
215 | - | 100 | - |
216 | -static void decode_RV32_64C(DisasContext *ctx, uint16_t opcode) | 101 | target_ulong HELPER(clmul)(target_ulong rs1, target_ulong rs2) |
102 | { | ||
103 | target_ulong result = 0; | ||
104 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
107 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
108 | @@ -XXX,XX +XXX,XX @@ static bool trans_grevi(DisasContext *ctx, arg_grevi *a) | ||
109 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_grevi); | ||
110 | } | ||
111 | |||
112 | -static bool trans_gorc(DisasContext *ctx, arg_gorc *a) | ||
113 | +static void gen_orc_b(TCGv ret, TCGv source1) | ||
114 | { | ||
115 | - REQUIRE_EXT(ctx, RVB); | ||
116 | - return gen_shift(ctx, a, EXT_ZERO, gen_helper_gorc); | ||
117 | + TCGv tmp = tcg_temp_new(); | ||
118 | + TCGv ones = tcg_constant_tl(dup_const_tl(MO_8, 0x01)); | ||
119 | + | ||
120 | + /* Set lsb in each byte if the byte was zero. */ | ||
121 | + tcg_gen_sub_tl(tmp, source1, ones); | ||
122 | + tcg_gen_andc_tl(tmp, tmp, source1); | ||
123 | + tcg_gen_shri_tl(tmp, tmp, 7); | ||
124 | + tcg_gen_andc_tl(tmp, ones, tmp); | ||
125 | + | ||
126 | + /* Replicate the lsb of each byte across the byte. */ | ||
127 | + tcg_gen_muli_tl(ret, tmp, 0xff); | ||
128 | + | ||
129 | + tcg_temp_free(tmp); | ||
130 | } | ||
131 | |||
132 | -static bool trans_gorci(DisasContext *ctx, arg_gorci *a) | ||
133 | +static bool trans_orc_b(DisasContext *ctx, arg_orc_b *a) | ||
134 | { | ||
135 | - REQUIRE_EXT(ctx, RVB); | ||
136 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_gorc); | ||
137 | + REQUIRE_ZBB(ctx); | ||
138 | + return gen_unary(ctx, a, EXT_ZERO, gen_orc_b); | ||
139 | } | ||
140 | |||
141 | #define GEN_SHADD(SHAMT) \ | ||
142 | @@ -XXX,XX +XXX,XX @@ static bool trans_greviw(DisasContext *ctx, arg_greviw *a) | ||
143 | return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_grev); | ||
144 | } | ||
145 | |||
146 | -static bool trans_gorcw(DisasContext *ctx, arg_gorcw *a) | ||
217 | -{ | 147 | -{ |
218 | - uint8_t op = extract16(opcode, 0, 2); | 148 | - REQUIRE_64BIT(ctx); |
219 | - | 149 | - REQUIRE_EXT(ctx, RVB); |
220 | - switch (op) { | 150 | - ctx->w = true; |
221 | - case 0: | 151 | - return gen_shift(ctx, a, EXT_ZERO, gen_helper_gorc); |
222 | - decode_RV32_64C0(ctx, opcode); | ||
223 | - break; | ||
224 | - } | ||
225 | -} | 152 | -} |
226 | - | 153 | - |
227 | static int ex_plus_1(DisasContext *ctx, int nf) | 154 | -static bool trans_gorciw(DisasContext *ctx, arg_gorciw *a) |
228 | { | 155 | -{ |
229 | return nf + 1; | 156 | - REQUIRE_64BIT(ctx); |
230 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | 157 | - REQUIRE_EXT(ctx, RVB); |
231 | } else { | 158 | - ctx->w = true; |
232 | ctx->pc_succ_insn = ctx->base.pc_next + 2; | 159 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_gorc); |
233 | if (!decode_insn16(ctx, opcode)) { | 160 | -} |
234 | - /* fall back to old decoder */ | 161 | - |
235 | - decode_RV32_64C(ctx, opcode); | 162 | #define GEN_SHADD_UW(SHAMT) \ |
236 | + gen_exception_illegal(ctx); | 163 | static void gen_sh##SHAMT##add_uw(TCGv ret, TCGv arg1, TCGv arg2) \ |
237 | } | 164 | { \ |
238 | } | ||
239 | } else { | ||
240 | -- | 165 | -- |
241 | 2.30.1 | 166 | 2.31.1 |
242 | 167 | ||
243 | 168 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | This adds the documentation to describe what is supported for the | 3 | With the changes to Zb[abcs], there's some encodings that are |
4 | 'microchip-icicle-kit' machine, and how to boot the machine in QEMU. | 4 | different in RV64 and RV32 (e.g., for rev8 and zext.h). For these, |
5 | we'll need a helper macro allowing us to select on RV32, as well. | ||
5 | 6 | ||
6 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 7 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 20210322075248.136255-2-bmeng.cn@gmail.com | 10 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
11 | Message-id: 20210911140016.834071-13-philipp.tomsich@vrull.eu | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 13 | --- |
11 | docs/system/riscv/microchip-icicle-kit.rst | 89 ++++++++++++++++++++++ | 14 | target/riscv/translate.c | 6 ++++++ |
12 | docs/system/target-riscv.rst | 1 + | 15 | 1 file changed, 6 insertions(+) |
13 | 2 files changed, 90 insertions(+) | ||
14 | create mode 100644 docs/system/riscv/microchip-icicle-kit.rst | ||
15 | 16 | ||
16 | diff --git a/docs/system/riscv/microchip-icicle-kit.rst b/docs/system/riscv/microchip-icicle-kit.rst | 17 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
17 | new file mode 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | index XXXXXXX..XXXXXXX | 19 | --- a/target/riscv/translate.c |
19 | --- /dev/null | 20 | +++ b/target/riscv/translate.c |
20 | +++ b/docs/system/riscv/microchip-icicle-kit.rst | 21 | @@ -XXX,XX +XXX,XX @@ EX_SH(12) |
21 | @@ -XXX,XX +XXX,XX @@ | 22 | } \ |
22 | +Microchip PolarFire SoC Icicle Kit (``microchip-icicle-kit``) | 23 | } while (0) |
23 | +============================================================= | 24 | |
25 | +#define REQUIRE_32BIT(ctx) do { \ | ||
26 | + if (!is_32bit(ctx)) { \ | ||
27 | + return false; \ | ||
28 | + } \ | ||
29 | +} while (0) | ||
24 | + | 30 | + |
25 | +Microchip PolarFire SoC Icicle Kit integrates a PolarFire SoC, with one | 31 | #define REQUIRE_64BIT(ctx) do { \ |
26 | +SiFive's E51 plus four U54 cores and many on-chip peripherals and an FPGA. | 32 | if (is_32bit(ctx)) { \ |
27 | + | 33 | return false; \ |
28 | +For more details about Microchip PolarFire SoC, please see: | ||
29 | +https://www.microsemi.com/product-directory/soc-fpgas/5498-polarfire-soc-fpga | ||
30 | + | ||
31 | +The Icicle Kit board information can be found here: | ||
32 | +https://www.microsemi.com/existing-parts/parts/152514 | ||
33 | + | ||
34 | +Supported devices | ||
35 | +----------------- | ||
36 | + | ||
37 | +The ``microchip-icicle-kit`` machine supports the following devices: | ||
38 | + | ||
39 | + * 1 E51 core | ||
40 | + * 4 U54 cores | ||
41 | + * Core Level Interruptor (CLINT) | ||
42 | + * Platform-Level Interrupt Controller (PLIC) | ||
43 | + * L2 Loosely Integrated Memory (L2-LIM) | ||
44 | + * DDR memory controller | ||
45 | + * 5 MMUARTs | ||
46 | + * 1 DMA controller | ||
47 | + * 2 GEM Ethernet controllers | ||
48 | + * 1 SDHC storage controller | ||
49 | + | ||
50 | +Boot options | ||
51 | +------------ | ||
52 | + | ||
53 | +The ``microchip-icicle-kit`` machine can start using the standard -bios | ||
54 | +functionality for loading its BIOS image, aka Hart Software Services (HSS_). | ||
55 | +HSS loads the second stage bootloader U-Boot from an SD card. It does not | ||
56 | +support direct kernel loading via the -kernel option. One has to load kernel | ||
57 | +from U-Boot. | ||
58 | + | ||
59 | +The memory is set to 1537 MiB by default which is the minimum required high | ||
60 | +memory size by HSS. A sanity check on ram size is performed in the machine | ||
61 | +init routine to prompt user to increase the RAM size to > 1537 MiB when less | ||
62 | +than 1537 MiB ram is detected. | ||
63 | + | ||
64 | +Boot the machine | ||
65 | +---------------- | ||
66 | + | ||
67 | +HSS 2020.12 release is tested at the time of writing. To build an HSS image | ||
68 | +that can be booted by the ``microchip-icicle-kit`` machine, type the following | ||
69 | +in the HSS source tree: | ||
70 | + | ||
71 | +.. code-block:: bash | ||
72 | + | ||
73 | + $ export CROSS_COMPILE=riscv64-linux- | ||
74 | + $ cp boards/mpfs-icicle-kit-es/def_config .config | ||
75 | + $ make BOARD=mpfs-icicle-kit-es | ||
76 | + | ||
77 | +Download the official SD card image released by Microchip and prepare it for | ||
78 | +QEMU usage: | ||
79 | + | ||
80 | +.. code-block:: bash | ||
81 | + | ||
82 | + $ wget ftp://ftpsoc.microsemi.com/outgoing/core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz | ||
83 | + $ gunzip core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic.gz | ||
84 | + $ qemu-img resize core-image-minimal-dev-icicle-kit-es-sd-20201009141623.rootfs.wic 4G | ||
85 | + | ||
86 | +Then we can boot the machine by: | ||
87 | + | ||
88 | +.. code-block:: bash | ||
89 | + | ||
90 | + $ qemu-system-riscv64 -M microchip-icicle-kit -smp 5 \ | ||
91 | + -bios path/to/hss.bin -sd path/to/sdcard.img \ | ||
92 | + -nic user,model=cadence_gem \ | ||
93 | + -nic tap,ifname=tap,model=cadence_gem,script=no \ | ||
94 | + -display none -serial stdio \ | ||
95 | + -chardev socket,id=serial1,path=serial1.sock,server=on,wait=on \ | ||
96 | + -serial chardev:serial1 | ||
97 | + | ||
98 | +With above command line, current terminal session will be used for the first | ||
99 | +serial port. Open another terminal window, and use `minicom` to connect the | ||
100 | +second serial port. | ||
101 | + | ||
102 | +.. code-block:: bash | ||
103 | + | ||
104 | + $ minicom -D unix\#serial1.sock | ||
105 | + | ||
106 | +HSS output is on the first serial port (stdio) and U-Boot outputs on the | ||
107 | +second serial port. U-Boot will automatically load the Linux kernel from | ||
108 | +the SD card image. | ||
109 | + | ||
110 | +.. _HSS: https://github.com/polarfire-soc/hart-software-services | ||
111 | diff --git a/docs/system/target-riscv.rst b/docs/system/target-riscv.rst | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/docs/system/target-riscv.rst | ||
114 | +++ b/docs/system/target-riscv.rst | ||
115 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running | ||
116 | .. toctree:: | ||
117 | :maxdepth: 1 | ||
118 | |||
119 | + riscv/microchip-icicle-kit | ||
120 | riscv/sifive_u | ||
121 | |||
122 | RISC-V CPU features | ||
123 | -- | 34 | -- |
124 | 2.30.1 | 35 | 2.31.1 |
125 | 36 | ||
126 | 37 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | Since HSS commit c20a89f8dcac, the Icicle Kit reference design has | 3 | The 1.0.0 version of Zbb does not contain grev/grevi. Instead, a |
4 | been updated to use a register mapped at 0x4f000000 instead of a | 4 | rev8 instruction (equivalent to the rev8 pseudo-instruction built on |
5 | GPIO to control whether eMMC or SD card is to be used. With this | 5 | grevi from pre-0.93 draft-B) is available. |
6 | support the same HSS image can be used for both eMMC and SD card | ||
7 | boot flow, while previously two different board configurations were | ||
8 | used. This is undocumented but one can take a look at the HSS code | ||
9 | HSS_MMCInit() in services/mmc/mmc_api.c. | ||
10 | 6 | ||
11 | With this commit, HSS image built from 2020.12 release boots again. | 7 | This commit adds the new rev8 instruction and removes grev/grevi. |
12 | 8 | ||
13 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 9 | Note that there is no W-form of this instruction (both a |
10 | sign-extending and zero-extending 32-bit version can easily be | ||
11 | synthesized by following rev8 with either a srai or srli instruction | ||
12 | on RV64) and that the opcode encodings for rev8 in RV32 and RV64 are | ||
13 | different. | ||
14 | |||
15 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
16 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
15 | Message-id: 20210322075248.136255-1-bmeng.cn@gmail.com | 18 | Message-id: 20210911140016.834071-14-philipp.tomsich@vrull.eu |
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
17 | --- | 20 | --- |
18 | include/hw/riscv/microchip_pfsoc.h | 1 + | 21 | target/riscv/helper.h | 2 -- |
19 | hw/riscv/microchip_pfsoc.c | 6 ++++++ | 22 | target/riscv/insn32.decode | 12 ++++---- |
20 | 2 files changed, 7 insertions(+) | 23 | target/riscv/bitmanip_helper.c | 40 ------------------------- |
24 | target/riscv/insn_trans/trans_rvb.c.inc | 40 +++++-------------------- | ||
25 | 4 files changed, 15 insertions(+), 79 deletions(-) | ||
21 | 26 | ||
22 | diff --git a/include/hw/riscv/microchip_pfsoc.h b/include/hw/riscv/microchip_pfsoc.h | 27 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
23 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/riscv/microchip_pfsoc.h | 29 | --- a/target/riscv/helper.h |
25 | +++ b/include/hw/riscv/microchip_pfsoc.h | 30 | +++ b/target/riscv/helper.h |
26 | @@ -XXX,XX +XXX,XX @@ enum { | 31 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(fcvt_d_lu, TCG_CALL_NO_RWG, i64, env, tl) |
27 | MICROCHIP_PFSOC_ENVM_DATA, | 32 | DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) |
28 | MICROCHIP_PFSOC_QSPI_XIP, | 33 | |
29 | MICROCHIP_PFSOC_IOSCB, | 34 | /* Bitmanip */ |
30 | + MICROCHIP_PFSOC_EMMC_SD_MUX, | 35 | -DEF_HELPER_FLAGS_2(grev, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
31 | MICROCHIP_PFSOC_DRAM_LO, | 36 | -DEF_HELPER_FLAGS_2(grevw, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
32 | MICROCHIP_PFSOC_DRAM_LO_ALIAS, | 37 | DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
33 | MICROCHIP_PFSOC_DRAM_HI, | 38 | DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) |
34 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | 39 | |
40 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
35 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/hw/riscv/microchip_pfsoc.c | 42 | --- a/target/riscv/insn32.decode |
37 | +++ b/hw/riscv/microchip_pfsoc.c | 43 | +++ b/target/riscv/insn32.decode |
38 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry microchip_pfsoc_memmap[] = { | 44 | @@ -XXX,XX +XXX,XX @@ min 0000101 .......... 100 ..... 0110011 @r |
39 | [MICROCHIP_PFSOC_ENVM_DATA] = { 0x20220000, 0x20000 }, | 45 | minu 0000101 .......... 101 ..... 0110011 @r |
40 | [MICROCHIP_PFSOC_QSPI_XIP] = { 0x21000000, 0x1000000 }, | 46 | orc_b 001010 000111 ..... 101 ..... 0010011 @r2 |
41 | [MICROCHIP_PFSOC_IOSCB] = { 0x30000000, 0x10000000 }, | 47 | orn 0100000 .......... 110 ..... 0110011 @r |
42 | + [MICROCHIP_PFSOC_EMMC_SD_MUX] = { 0x4f000000, 0x4 }, | 48 | +# The encoding for rev8 differs between RV32 and RV64. |
43 | [MICROCHIP_PFSOC_DRAM_LO] = { 0x80000000, 0x40000000 }, | 49 | +# rev8_32 denotes the RV32 variant. |
44 | [MICROCHIP_PFSOC_DRAM_LO_ALIAS] = { 0xc0000000, 0x40000000 }, | 50 | +rev8_32 011010 011000 ..... 101 ..... 0010011 @r2 |
45 | [MICROCHIP_PFSOC_DRAM_HI] = { 0x1000000000, 0x0 }, | 51 | rol 0110000 .......... 001 ..... 0110011 @r |
46 | @@ -XXX,XX +XXX,XX @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp) | 52 | ror 0110000 .......... 101 ..... 0110011 @r |
47 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->ioscb), 0, | 53 | rori 01100 ............ 101 ..... 0010011 @sh |
48 | memmap[MICROCHIP_PFSOC_IOSCB].base); | 54 | @@ -XXX,XX +XXX,XX @@ xnor 0100000 .......... 100 ..... 0110011 @r |
49 | 55 | clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | |
50 | + /* eMMC/SD mux */ | 56 | ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 |
51 | + create_unimplemented_device("microchip.pfsoc.emmc_sd_mux", | 57 | cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 |
52 | + memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].base, | 58 | +# The encoding for rev8 differs between RV32 and RV64. |
53 | + memmap[MICROCHIP_PFSOC_EMMC_SD_MUX].size); | 59 | +# When executing on RV64, the encoding used in RV32 is an illegal |
54 | + | 60 | +# instruction, so we use different handler functions to differentiate. |
55 | /* QSPI Flash */ | 61 | +rev8_64 011010 111000 ..... 101 ..... 0010011 @r2 |
56 | memory_region_init_rom(qspi_xip_mem, OBJECT(dev), | 62 | rolw 0110000 .......... 001 ..... 0111011 @r |
57 | "microchip.pfsoc.qspi_xip", | 63 | roriw 0110000 .......... 101 ..... 0011011 @sh5 |
64 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
65 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | ||
66 | pack 0000100 .......... 100 ..... 0110011 @r | ||
67 | packu 0100100 .......... 100 ..... 0110011 @r | ||
68 | packh 0000100 .......... 111 ..... 0110011 @r | ||
69 | -grev 0110100 .......... 101 ..... 0110011 @r | ||
70 | -grevi 01101. ........... 101 ..... 0010011 @sh | ||
71 | |||
72 | # *** RV64B Standard Extension (in addition to RV32B) *** | ||
73 | packw 0000100 .......... 100 ..... 0111011 @r | ||
74 | packuw 0100100 .......... 100 ..... 0111011 @r | ||
75 | -grevw 0110100 .......... 101 ..... 0111011 @r | ||
76 | - | ||
77 | -greviw 0110100 .......... 101 ..... 0011011 @sh5 | ||
78 | |||
79 | # *** RV32 Zbc Standard Extension *** | ||
80 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
81 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/riscv/bitmanip_helper.c | ||
84 | +++ b/target/riscv/bitmanip_helper.c | ||
85 | @@ -XXX,XX +XXX,XX @@ | ||
86 | #include "exec/helper-proto.h" | ||
87 | #include "tcg/tcg.h" | ||
88 | |||
89 | -static const uint64_t adjacent_masks[] = { | ||
90 | - dup_const(MO_8, 0x55), | ||
91 | - dup_const(MO_8, 0x33), | ||
92 | - dup_const(MO_8, 0x0f), | ||
93 | - dup_const(MO_16, 0xff), | ||
94 | - dup_const(MO_32, 0xffff), | ||
95 | - UINT32_MAX | ||
96 | -}; | ||
97 | - | ||
98 | -static inline target_ulong do_swap(target_ulong x, uint64_t mask, int shift) | ||
99 | -{ | ||
100 | - return ((x & mask) << shift) | ((x & ~mask) >> shift); | ||
101 | -} | ||
102 | - | ||
103 | -static target_ulong do_grev(target_ulong rs1, | ||
104 | - target_ulong rs2, | ||
105 | - int bits) | ||
106 | -{ | ||
107 | - target_ulong x = rs1; | ||
108 | - int i, shift; | ||
109 | - | ||
110 | - for (i = 0, shift = 1; shift < bits; i++, shift <<= 1) { | ||
111 | - if (rs2 & shift) { | ||
112 | - x = do_swap(x, adjacent_masks[i], shift); | ||
113 | - } | ||
114 | - } | ||
115 | - | ||
116 | - return x; | ||
117 | -} | ||
118 | - | ||
119 | -target_ulong HELPER(grev)(target_ulong rs1, target_ulong rs2) | ||
120 | -{ | ||
121 | - return do_grev(rs1, rs2, TARGET_LONG_BITS); | ||
122 | -} | ||
123 | - | ||
124 | -target_ulong HELPER(grevw)(target_ulong rs1, target_ulong rs2) | ||
125 | -{ | ||
126 | - return do_grev(rs1, rs2, 32); | ||
127 | -} | ||
128 | - | ||
129 | target_ulong HELPER(clmul)(target_ulong rs1, target_ulong rs2) | ||
130 | { | ||
131 | target_ulong result = 0; | ||
132 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
135 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
136 | @@ -XXX,XX +XXX,XX @@ static bool trans_rol(DisasContext *ctx, arg_rol *a) | ||
137 | return gen_shift(ctx, a, EXT_NONE, tcg_gen_rotl_tl); | ||
138 | } | ||
139 | |||
140 | -static bool trans_grev(DisasContext *ctx, arg_grev *a) | ||
141 | +static bool trans_rev8_32(DisasContext *ctx, arg_rev8_32 *a) | ||
142 | { | ||
143 | - REQUIRE_EXT(ctx, RVB); | ||
144 | - return gen_shift(ctx, a, EXT_NONE, gen_helper_grev); | ||
145 | -} | ||
146 | - | ||
147 | -static void gen_grevi(TCGv dest, TCGv src, target_long shamt) | ||
148 | -{ | ||
149 | - if (shamt == TARGET_LONG_BITS - 8) { | ||
150 | - /* rev8, byte swaps */ | ||
151 | - tcg_gen_bswap_tl(dest, src); | ||
152 | - } else { | ||
153 | - gen_helper_grev(dest, src, tcg_constant_tl(shamt)); | ||
154 | - } | ||
155 | + REQUIRE_32BIT(ctx); | ||
156 | + REQUIRE_ZBB(ctx); | ||
157 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_bswap_tl); | ||
158 | } | ||
159 | |||
160 | -static bool trans_grevi(DisasContext *ctx, arg_grevi *a) | ||
161 | +static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a) | ||
162 | { | ||
163 | - REQUIRE_EXT(ctx, RVB); | ||
164 | - return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_grevi); | ||
165 | + REQUIRE_64BIT(ctx); | ||
166 | + REQUIRE_ZBB(ctx); | ||
167 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_bswap_tl); | ||
168 | } | ||
169 | |||
170 | static void gen_orc_b(TCGv ret, TCGv source1) | ||
171 | @@ -XXX,XX +XXX,XX @@ static bool trans_rolw(DisasContext *ctx, arg_rolw *a) | ||
172 | return gen_shift(ctx, a, EXT_NONE, gen_rolw); | ||
173 | } | ||
174 | |||
175 | -static bool trans_grevw(DisasContext *ctx, arg_grevw *a) | ||
176 | -{ | ||
177 | - REQUIRE_64BIT(ctx); | ||
178 | - REQUIRE_EXT(ctx, RVB); | ||
179 | - ctx->w = true; | ||
180 | - return gen_shift(ctx, a, EXT_ZERO, gen_helper_grev); | ||
181 | -} | ||
182 | - | ||
183 | -static bool trans_greviw(DisasContext *ctx, arg_greviw *a) | ||
184 | -{ | ||
185 | - REQUIRE_64BIT(ctx); | ||
186 | - REQUIRE_EXT(ctx, RVB); | ||
187 | - ctx->w = true; | ||
188 | - return gen_shift_imm_tl(ctx, a, EXT_ZERO, gen_helper_grev); | ||
189 | -} | ||
190 | - | ||
191 | #define GEN_SHADD_UW(SHAMT) \ | ||
192 | static void gen_sh##SHAMT##add_uw(TCGv ret, TCGv arg1, TCGv arg2) \ | ||
193 | { \ | ||
58 | -- | 194 | -- |
59 | 2.30.1 | 195 | 2.31.1 |
60 | 196 | ||
61 | 197 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | The previous implementation was broken in many ways: | 3 | The 1.0.0 version of Zbb does not contain pack/packu/packh. However, a |
4 | - Used mideleg instead of hideleg to mask accesses | 4 | zext.h instruction is provided (built on pack/packh from pre-0.93 |
5 | - Used MIP_VSSIP instead of VS_MODE_INTERRUPTS to mask writes to vsie | 5 | draft-B) is available. |
6 | - Did not shift between S bits and VS bits (VSEIP <-> SEIP, ...) | ||
7 | 6 | ||
8 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 7 | This commit adds zext.h and removes the pack* instructions. |
8 | |||
9 | Note that the encodings for zext.h are different between RV32 and | ||
10 | RV64, which is handled through REQUIRE_32BIT. | ||
11 | |||
12 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-id: 20210311094738.1376795-1-georg.kotheimer@kernkonzept.com | 15 | Message-id: 20210911140016.834071-15-philipp.tomsich@vrull.eu |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 17 | --- |
13 | target/riscv/csr.c | 68 +++++++++++++++++++++++----------------------- | 18 | target/riscv/insn32.decode | 12 ++-- |
14 | 1 file changed, 34 insertions(+), 34 deletions(-) | 19 | target/riscv/insn_trans/trans_rvb.c.inc | 86 ++++--------------------- |
20 | 2 files changed, 21 insertions(+), 77 deletions(-) | ||
15 | 21 | ||
16 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 22 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode |
17 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/csr.c | 24 | --- a/target/riscv/insn32.decode |
19 | +++ b/target/riscv/csr.c | 25 | +++ b/target/riscv/insn32.decode |
20 | @@ -XXX,XX +XXX,XX @@ static int write_sstatus(CPURISCVState *env, int csrno, target_ulong val) | 26 | @@ -XXX,XX +XXX,XX @@ rori 01100 ............ 101 ..... 0010011 @sh |
21 | return write_mstatus(env, CSR_MSTATUS, newval); | 27 | sext_b 011000 000100 ..... 001 ..... 0010011 @r2 |
28 | sext_h 011000 000101 ..... 001 ..... 0010011 @r2 | ||
29 | xnor 0100000 .......... 100 ..... 0110011 @r | ||
30 | +# The encoding for zext.h differs between RV32 and RV64. | ||
31 | +# zext_h_32 denotes the RV32 variant. | ||
32 | +zext_h_32 0000100 00000 ..... 100 ..... 0110011 @r2 | ||
33 | |||
34 | # *** RV64 Zbb Standard Extension (in addition to RV32 Zbb) *** | ||
35 | clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
36 | @@ -XXX,XX +XXX,XX @@ rev8_64 011010 111000 ..... 101 ..... 0010011 @r2 | ||
37 | rolw 0110000 .......... 001 ..... 0111011 @r | ||
38 | roriw 0110000 .......... 101 ..... 0011011 @sh5 | ||
39 | rorw 0110000 .......... 101 ..... 0111011 @r | ||
40 | +# The encoding for zext.h differs between RV32 and RV64. | ||
41 | +# When executing on RV64, the encoding used in RV32 is an illegal | ||
42 | +# instruction, so we use different handler functions to differentiate. | ||
43 | +zext_h_64 0000100 00000 ..... 100 ..... 0111011 @r2 | ||
44 | |||
45 | # *** RV32B Standard Extension *** | ||
46 | -pack 0000100 .......... 100 ..... 0110011 @r | ||
47 | -packu 0100100 .......... 100 ..... 0110011 @r | ||
48 | -packh 0000100 .......... 111 ..... 0110011 @r | ||
49 | |||
50 | # *** RV64B Standard Extension (in addition to RV32B) *** | ||
51 | -packw 0000100 .......... 100 ..... 0111011 @r | ||
52 | -packuw 0100100 .......... 100 ..... 0111011 @r | ||
53 | |||
54 | # *** RV32 Zbc Standard Extension *** | ||
55 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
56 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
59 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
60 | @@ -XXX,XX +XXX,XX @@ static bool trans_xnor(DisasContext *ctx, arg_xnor *a) | ||
61 | return gen_arith(ctx, a, EXT_NONE, tcg_gen_eqv_tl); | ||
22 | } | 62 | } |
23 | 63 | ||
24 | +static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) | 64 | -static void gen_pack(TCGv ret, TCGv arg1, TCGv arg2) |
65 | -{ | ||
66 | - tcg_gen_deposit_tl(ret, arg1, arg2, | ||
67 | - TARGET_LONG_BITS / 2, | ||
68 | - TARGET_LONG_BITS / 2); | ||
69 | -} | ||
70 | - | ||
71 | -static bool trans_pack(DisasContext *ctx, arg_pack *a) | ||
72 | -{ | ||
73 | - REQUIRE_EXT(ctx, RVB); | ||
74 | - return gen_arith(ctx, a, EXT_NONE, gen_pack); | ||
75 | -} | ||
76 | - | ||
77 | -static void gen_packu(TCGv ret, TCGv arg1, TCGv arg2) | ||
78 | -{ | ||
79 | - TCGv t = tcg_temp_new(); | ||
80 | - tcg_gen_shri_tl(t, arg1, TARGET_LONG_BITS / 2); | ||
81 | - tcg_gen_deposit_tl(ret, arg2, t, 0, TARGET_LONG_BITS / 2); | ||
82 | - tcg_temp_free(t); | ||
83 | -} | ||
84 | - | ||
85 | -static bool trans_packu(DisasContext *ctx, arg_packu *a) | ||
86 | -{ | ||
87 | - REQUIRE_EXT(ctx, RVB); | ||
88 | - return gen_arith(ctx, a, EXT_NONE, gen_packu); | ||
89 | -} | ||
90 | - | ||
91 | -static void gen_packh(TCGv ret, TCGv arg1, TCGv arg2) | ||
92 | -{ | ||
93 | - TCGv t = tcg_temp_new(); | ||
94 | - tcg_gen_ext8u_tl(t, arg2); | ||
95 | - tcg_gen_deposit_tl(ret, arg1, t, 8, TARGET_LONG_BITS - 8); | ||
96 | - tcg_temp_free(t); | ||
97 | -} | ||
98 | - | ||
99 | -static bool trans_packh(DisasContext *ctx, arg_packh *a) | ||
100 | -{ | ||
101 | - REQUIRE_EXT(ctx, RVB); | ||
102 | - return gen_arith(ctx, a, EXT_NONE, gen_packh); | ||
103 | -} | ||
104 | - | ||
105 | static bool trans_min(DisasContext *ctx, arg_min *a) | ||
106 | { | ||
107 | REQUIRE_ZBB(ctx); | ||
108 | @@ -XXX,XX +XXX,XX @@ GEN_TRANS_SHADD(1) | ||
109 | GEN_TRANS_SHADD(2) | ||
110 | GEN_TRANS_SHADD(3) | ||
111 | |||
112 | +static bool trans_zext_h_32(DisasContext *ctx, arg_zext_h_32 *a) | ||
25 | +{ | 113 | +{ |
26 | + /* Shift the VS bits to their S bit location in vsie */ | 114 | + REQUIRE_32BIT(ctx); |
27 | + *val = (env->mie & env->hideleg & VS_MODE_INTERRUPTS) >> 1; | 115 | + REQUIRE_ZBB(ctx); |
28 | + return 0; | 116 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16u_tl); |
29 | +} | 117 | +} |
30 | + | 118 | + |
31 | static int read_sie(CPURISCVState *env, int csrno, target_ulong *val) | 119 | +static bool trans_zext_h_64(DisasContext *ctx, arg_zext_h_64 *a) |
32 | { | ||
33 | if (riscv_cpu_virt_enabled(env)) { | ||
34 | - /* Tell the guest the VS bits, shifted to the S bit locations */ | ||
35 | - *val = (env->mie & env->mideleg & VS_MODE_INTERRUPTS) >> 1; | ||
36 | + read_vsie(env, CSR_VSIE, val); | ||
37 | } else { | ||
38 | *val = env->mie & env->mideleg; | ||
39 | } | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | -static int write_sie(CPURISCVState *env, int csrno, target_ulong val) | ||
44 | +static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) | ||
45 | { | ||
46 | - target_ulong newval; | ||
47 | + /* Shift the S bits to their VS bit location in mie */ | ||
48 | + target_ulong newval = (env->mie & ~VS_MODE_INTERRUPTS) | | ||
49 | + ((val << 1) & env->hideleg & VS_MODE_INTERRUPTS); | ||
50 | + return write_mie(env, CSR_MIE, newval); | ||
51 | +} | ||
52 | |||
53 | +static int write_sie(CPURISCVState *env, int csrno, target_ulong val) | ||
54 | +{ | 120 | +{ |
55 | if (riscv_cpu_virt_enabled(env)) { | 121 | + REQUIRE_64BIT(ctx); |
56 | - /* Shift the guests S bits to VS */ | 122 | + REQUIRE_ZBB(ctx); |
57 | - newval = (env->mie & ~VS_MODE_INTERRUPTS) | | 123 | + return gen_unary(ctx, a, EXT_NONE, tcg_gen_ext16u_tl); |
58 | - ((val << 1) & VS_MODE_INTERRUPTS); | ||
59 | + write_vsie(env, CSR_VSIE, val); | ||
60 | } else { | ||
61 | - newval = (env->mie & ~S_MODE_INTERRUPTS) | (val & S_MODE_INTERRUPTS); | ||
62 | + target_ulong newval = (env->mie & ~S_MODE_INTERRUPTS) | | ||
63 | + (val & S_MODE_INTERRUPTS); | ||
64 | + write_mie(env, CSR_MIE, newval); | ||
65 | } | ||
66 | |||
67 | - return write_mie(env, CSR_MIE, newval); | ||
68 | + return 0; | ||
69 | } | ||
70 | |||
71 | static int read_stvec(CPURISCVState *env, int csrno, target_ulong *val) | ||
72 | @@ -XXX,XX +XXX,XX @@ static int write_sbadaddr(CPURISCVState *env, int csrno, target_ulong val) | ||
73 | return 0; | ||
74 | } | ||
75 | |||
76 | +static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | ||
77 | + target_ulong new_value, target_ulong write_mask) | ||
78 | +{ | ||
79 | + /* Shift the S bits to their VS bit location in mip */ | ||
80 | + int ret = rmw_mip(env, 0, ret_value, new_value << 1, | ||
81 | + (write_mask << 1) & vsip_writable_mask & env->hideleg); | ||
82 | + *ret_value &= VS_MODE_INTERRUPTS; | ||
83 | + /* Shift the VS bits to their S bit location in vsip */ | ||
84 | + *ret_value >>= 1; | ||
85 | + return ret; | ||
86 | +} | 124 | +} |
87 | + | 125 | + |
88 | static int rmw_sip(CPURISCVState *env, int csrno, target_ulong *ret_value, | 126 | static void gen_clzw(TCGv ret, TCGv arg1) |
89 | target_ulong new_value, target_ulong write_mask) | ||
90 | { | 127 | { |
91 | int ret; | 128 | TCGv t = tcg_temp_new(); |
92 | 129 | @@ -XXX,XX +XXX,XX @@ static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a) | |
93 | if (riscv_cpu_virt_enabled(env)) { | 130 | return gen_unary(ctx, a, EXT_ZERO, tcg_gen_ctpop_tl); |
94 | - /* Shift the new values to line up with the VS bits */ | ||
95 | - ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value << 1, | ||
96 | - (write_mask & sip_writable_mask) << 1 & env->mideleg); | ||
97 | - ret &= vsip_writable_mask; | ||
98 | - ret >>= 1; | ||
99 | + ret = rmw_vsip(env, CSR_VSIP, ret_value, new_value, write_mask); | ||
100 | } else { | ||
101 | ret = rmw_mip(env, CSR_MSTATUS, ret_value, new_value, | ||
102 | write_mask & env->mideleg & sip_writable_mask); | ||
103 | @@ -XXX,XX +XXX,XX @@ static int write_vsstatus(CPURISCVState *env, int csrno, target_ulong val) | ||
104 | return 0; | ||
105 | } | 131 | } |
106 | 132 | ||
107 | -static int rmw_vsip(CPURISCVState *env, int csrno, target_ulong *ret_value, | 133 | -static void gen_packw(TCGv ret, TCGv arg1, TCGv arg2) |
108 | - target_ulong new_value, target_ulong write_mask) | ||
109 | -{ | 134 | -{ |
110 | - int ret = rmw_mip(env, 0, ret_value, new_value, | 135 | - TCGv t = tcg_temp_new(); |
111 | - write_mask & env->mideleg & vsip_writable_mask); | 136 | - tcg_gen_ext16s_tl(t, arg2); |
112 | - return ret; | 137 | - tcg_gen_deposit_tl(ret, arg1, t, 16, 48); |
138 | - tcg_temp_free(t); | ||
113 | -} | 139 | -} |
114 | - | 140 | - |
115 | -static int read_vsie(CPURISCVState *env, int csrno, target_ulong *val) | 141 | -static bool trans_packw(DisasContext *ctx, arg_packw *a) |
116 | -{ | 142 | -{ |
117 | - *val = env->mie & env->mideleg & VS_MODE_INTERRUPTS; | 143 | - REQUIRE_64BIT(ctx); |
118 | - return 0; | 144 | - REQUIRE_EXT(ctx, RVB); |
145 | - return gen_arith(ctx, a, EXT_NONE, gen_packw); | ||
119 | -} | 146 | -} |
120 | - | 147 | - |
121 | -static int write_vsie(CPURISCVState *env, int csrno, target_ulong val) | 148 | -static void gen_packuw(TCGv ret, TCGv arg1, TCGv arg2) |
122 | -{ | 149 | -{ |
123 | - target_ulong newval = (env->mie & ~env->mideleg) | (val & env->mideleg & MIP_VSSIP); | 150 | - TCGv t = tcg_temp_new(); |
124 | - return write_mie(env, CSR_MIE, newval); | 151 | - tcg_gen_shri_tl(t, arg1, 16); |
152 | - tcg_gen_deposit_tl(ret, arg2, t, 0, 16); | ||
153 | - tcg_gen_ext32s_tl(ret, ret); | ||
154 | - tcg_temp_free(t); | ||
125 | -} | 155 | -} |
126 | - | 156 | - |
127 | static int read_vstvec(CPURISCVState *env, int csrno, target_ulong *val) | 157 | -static bool trans_packuw(DisasContext *ctx, arg_packuw *a) |
158 | -{ | ||
159 | - REQUIRE_64BIT(ctx); | ||
160 | - REQUIRE_EXT(ctx, RVB); | ||
161 | - return gen_arith(ctx, a, EXT_NONE, gen_packuw); | ||
162 | -} | ||
163 | - | ||
164 | static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | ||
128 | { | 165 | { |
129 | *val = env->vstvec; | 166 | TCGv_i32 t1 = tcg_temp_new_i32(); |
130 | -- | 167 | -- |
131 | 2.30.1 | 168 | 2.31.1 |
132 | 169 | ||
133 | 170 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | The current two-stage lookup detection in riscv_cpu_do_interrupt falls | 3 | With everything classified as Zb[abcs] and pre-0.93 draft-B |
4 | short of its purpose, as all it checks is whether two-stage address | 4 | instructions that are not part of Zb[abcs] removed, we can remove the |
5 | translation either via the hypervisor-load store instructions or the | 5 | remaining support code for RVB. |
6 | MPRV feature would be allowed. | ||
7 | 6 | ||
8 | What we really need instead is whether two-stage address translation was | 7 | Note that RVB has been retired for good and misa.B will neither mean |
9 | active when the exception was raised. However, in riscv_cpu_do_interrupt | 8 | 'some' or 'all of' Zb*: |
10 | we do not have the information to reliably detect this. Therefore, when | 9 | https://lists.riscv.org/g/tech-bitmanip/message/532 |
11 | we raise a memory fault exception we have to record whether two-stage | ||
12 | address translation is active. | ||
13 | 10 | ||
14 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 11 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> |
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
16 | Message-id: 20210319141459.1196741-1-georg.kotheimer@kernkonzept.com | 14 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> |
15 | Message-id: 20210911140016.834071-16-philipp.tomsich@vrull.eu | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 17 | --- |
19 | target/riscv/cpu.h | 4 ++++ | 18 | target/riscv/cpu.h | 3 --- |
20 | target/riscv/cpu.c | 1 + | 19 | target/riscv/insn32.decode | 4 ---- |
21 | target/riscv/cpu_helper.c | 21 ++++++++------------- | 20 | target/riscv/cpu.c | 26 -------------------------- |
22 | 3 files changed, 13 insertions(+), 13 deletions(-) | 21 | 3 files changed, 33 deletions(-) |
23 | 22 | ||
24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 23 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
25 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/riscv/cpu.h | 25 | --- a/target/riscv/cpu.h |
27 | +++ b/target/riscv/cpu.h | 26 | +++ b/target/riscv/cpu.h |
28 | @@ -XXX,XX +XXX,XX @@ struct CPURISCVState { | 27 | @@ -XXX,XX +XXX,XX @@ |
29 | target_ulong satp_hs; | 28 | #define RVS RV('S') |
30 | uint64_t mstatus_hs; | 29 | #define RVU RV('U') |
31 | 30 | #define RVH RV('H') | |
32 | + /* Signals whether the current exception occurred with two-stage address | 31 | -#define RVB RV('B') |
33 | + translation active. */ | 32 | |
34 | + bool two_stage_lookup; | 33 | /* S extension denotes that Supervisor mode exists, however it is possible |
35 | + | 34 | to have a core that support S mode but does not have an MMU and there |
36 | target_ulong scounteren; | 35 | @@ -XXX,XX +XXX,XX @@ enum { |
37 | target_ulong mcounteren; | 36 | #define PRIV_VERSION_1_10_0 0x00011000 |
38 | 37 | #define PRIV_VERSION_1_11_0 0x00011100 | |
38 | |||
39 | -#define BEXT_VERSION_0_93_0 0x00009300 | ||
40 | #define VEXT_VERSION_0_07_1 0x00000701 | ||
41 | |||
42 | enum { | ||
43 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPU { | ||
44 | bool ext_f; | ||
45 | bool ext_d; | ||
46 | bool ext_c; | ||
47 | - bool ext_b; | ||
48 | bool ext_s; | ||
49 | bool ext_u; | ||
50 | bool ext_h; | ||
51 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/riscv/insn32.decode | ||
54 | +++ b/target/riscv/insn32.decode | ||
55 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | ||
56 | # instruction, so we use different handler functions to differentiate. | ||
57 | zext_h_64 0000100 00000 ..... 100 ..... 0111011 @r2 | ||
58 | |||
59 | -# *** RV32B Standard Extension *** | ||
60 | - | ||
61 | -# *** RV64B Standard Extension (in addition to RV32B) *** | ||
62 | - | ||
63 | # *** RV32 Zbc Standard Extension *** | ||
64 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
65 | clmulh 0000101 .......... 011 ..... 0110011 @r | ||
39 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 66 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
40 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/target/riscv/cpu.c | 68 | --- a/target/riscv/cpu.c |
42 | +++ b/target/riscv/cpu.c | 69 | +++ b/target/riscv/cpu.c |
43 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_reset(DeviceState *dev) | 70 | @@ -XXX,XX +XXX,XX @@ static void set_priv_version(CPURISCVState *env, int priv_ver) |
44 | env->mstatus &= ~(MSTATUS_MIE | MSTATUS_MPRV); | 71 | env->priv_ver = priv_ver; |
45 | env->mcause = 0; | ||
46 | env->pc = env->resetvec; | ||
47 | + env->two_stage_lookup = false; | ||
48 | #endif | ||
49 | cs->exception_index = EXCP_NONE; | ||
50 | env->load_res = -1; | ||
51 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/riscv/cpu_helper.c | ||
54 | +++ b/target/riscv/cpu_helper.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, | ||
56 | g_assert_not_reached(); | ||
57 | } | ||
58 | env->badaddr = address; | ||
59 | + env->two_stage_lookup = two_stage; | ||
60 | } | 72 | } |
61 | 73 | ||
62 | hwaddr riscv_cpu_get_phys_page_debug(CPUState *cs, vaddr addr) | 74 | -static void set_bext_version(CPURISCVState *env, int bext_ver) |
63 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, | 75 | -{ |
64 | } | 76 | - env->bext_ver = bext_ver; |
65 | 77 | -} | |
66 | env->badaddr = addr; | 78 | - |
67 | + env->two_stage_lookup = riscv_cpu_virt_enabled(env) || | 79 | static void set_vext_version(CPURISCVState *env, int vext_ver) |
68 | + riscv_cpu_two_stage_lookup(mmu_idx); | 80 | { |
69 | riscv_raise_exception(&cpu->env, cs->exception_index, retaddr); | 81 | env->vext_ver = vext_ver; |
70 | } | 82 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) |
71 | 83 | if (cpu->cfg.ext_h) { | |
72 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_unaligned_access(CPUState *cs, vaddr addr, | 84 | target_misa |= RVH; |
73 | g_assert_not_reached(); | 85 | } |
74 | } | 86 | - if (cpu->cfg.ext_b) { |
75 | env->badaddr = addr; | 87 | - int bext_version = BEXT_VERSION_0_93_0; |
76 | + env->two_stage_lookup = riscv_cpu_virt_enabled(env) || | 88 | - target_misa |= RVB; |
77 | + riscv_cpu_two_stage_lookup(mmu_idx); | 89 | - |
78 | riscv_raise_exception(env, cs->exception_index, retaddr); | 90 | - if (cpu->cfg.bext_spec) { |
79 | } | 91 | - if (!g_strcmp0(cpu->cfg.bext_spec, "v0.93")) { |
80 | #endif /* !CONFIG_USER_ONLY */ | 92 | - bext_version = BEXT_VERSION_0_93_0; |
81 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 93 | - } else { |
82 | /* handle the trap in S-mode */ | 94 | - error_setg(errp, |
83 | if (riscv_has_ext(env, RVH)) { | 95 | - "Unsupported bitmanip spec version '%s'", |
84 | target_ulong hdeleg = async ? env->hideleg : env->hedeleg; | 96 | - cpu->cfg.bext_spec); |
85 | - bool two_stage_lookup = false; | 97 | - return; |
86 | 98 | - } | |
87 | - if (env->priv == PRV_M || | 99 | - } else { |
88 | - (env->priv == PRV_S && !riscv_cpu_virt_enabled(env)) || | 100 | - qemu_log("bitmanip version is not specified, " |
89 | - (env->priv == PRV_U && !riscv_cpu_virt_enabled(env) && | 101 | - "use the default value v0.93\n"); |
90 | - get_field(env->hstatus, HSTATUS_HU))) { | ||
91 | - two_stage_lookup = true; | ||
92 | - } | 102 | - } |
93 | - | 103 | - set_bext_version(env, bext_version); |
94 | - if ((riscv_cpu_virt_enabled(env) || two_stage_lookup) && write_tval) { | 104 | - } |
95 | + if (env->two_stage_lookup && write_tval) { | 105 | if (cpu->cfg.ext_v) { |
96 | /* | 106 | int vext_version = VEXT_VERSION_0_07_1; |
97 | * If we are writing a guest virtual address to stval, set | 107 | target_misa |= RVV; |
98 | * this to 1. If we are trapping to VS we will set this to 0 | 108 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { |
99 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 109 | DEFINE_PROP_BOOL("s", RISCVCPU, cfg.ext_s, true), |
100 | riscv_cpu_set_force_hs_excep(env, 0); | 110 | DEFINE_PROP_BOOL("u", RISCVCPU, cfg.ext_u, true), |
101 | } else { | 111 | /* This is experimental so mark with 'x-' */ |
102 | /* Trap into HS mode */ | 112 | - DEFINE_PROP_BOOL("x-b", RISCVCPU, cfg.ext_b, false), |
103 | - if (!two_stage_lookup) { | 113 | DEFINE_PROP_BOOL("x-zba", RISCVCPU, cfg.ext_zba, false), |
104 | - env->hstatus = set_field(env->hstatus, HSTATUS_SPV, | 114 | DEFINE_PROP_BOOL("x-zbb", RISCVCPU, cfg.ext_zbb, false), |
105 | - riscv_cpu_virt_enabled(env)); | 115 | DEFINE_PROP_BOOL("x-zbc", RISCVCPU, cfg.ext_zbc, false), |
106 | - } | 116 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { |
107 | + env->hstatus = set_field(env->hstatus, HSTATUS_SPV, false); | 117 | DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), |
108 | htval = env->guest_phys_fault_addr; | 118 | DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), |
109 | } | 119 | DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), |
110 | } | 120 | - DEFINE_PROP_STRING("bext_spec", RISCVCPU, cfg.bext_spec), |
111 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) | 121 | DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), |
112 | * RISC-V ISA Specification. | 122 | DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), |
113 | */ | 123 | DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), |
114 | |||
115 | + env->two_stage_lookup = false; | ||
116 | #endif | ||
117 | cs->exception_index = EXCP_NONE; /* mark handled to qemu */ | ||
118 | } | ||
119 | -- | 124 | -- |
120 | 2.30.1 | 125 | 2.31.1 |
121 | 126 | ||
122 | 127 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Philipp Tomsich <philipp.tomsich@vrull.eu> | |
2 | |||
3 | With the addition of Zb[abcs], we also need to add disassembler | ||
4 | support for these new instructions. | ||
5 | |||
6 | Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu> | ||
7 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20210911140016.834071-17-philipp.tomsich@vrull.eu | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | --- | ||
11 | disas/riscv.c | 157 +++++++++++++++++++++++++++++++++++++++++++++++++- | ||
12 | 1 file changed, 154 insertions(+), 3 deletions(-) | ||
13 | |||
14 | diff --git a/disas/riscv.c b/disas/riscv.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/disas/riscv.c | ||
17 | +++ b/disas/riscv.c | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
19 | rv_op_fsflags = 316, | ||
20 | rv_op_fsrmi = 317, | ||
21 | rv_op_fsflagsi = 318, | ||
22 | + rv_op_bseti = 319, | ||
23 | + rv_op_bclri = 320, | ||
24 | + rv_op_binvi = 321, | ||
25 | + rv_op_bexti = 322, | ||
26 | + rv_op_rori = 323, | ||
27 | + rv_op_clz = 324, | ||
28 | + rv_op_ctz = 325, | ||
29 | + rv_op_cpop = 326, | ||
30 | + rv_op_sext_h = 327, | ||
31 | + rv_op_sext_b = 328, | ||
32 | + rv_op_xnor = 329, | ||
33 | + rv_op_orn = 330, | ||
34 | + rv_op_andn = 331, | ||
35 | + rv_op_rol = 332, | ||
36 | + rv_op_ror = 333, | ||
37 | + rv_op_sh1add = 334, | ||
38 | + rv_op_sh2add = 335, | ||
39 | + rv_op_sh3add = 336, | ||
40 | + rv_op_sh1add_uw = 337, | ||
41 | + rv_op_sh2add_uw = 338, | ||
42 | + rv_op_sh3add_uw = 339, | ||
43 | + rv_op_clmul = 340, | ||
44 | + rv_op_clmulr = 341, | ||
45 | + rv_op_clmulh = 342, | ||
46 | + rv_op_min = 343, | ||
47 | + rv_op_minu = 344, | ||
48 | + rv_op_max = 345, | ||
49 | + rv_op_maxu = 346, | ||
50 | + rv_op_clzw = 347, | ||
51 | + rv_op_ctzw = 348, | ||
52 | + rv_op_cpopw = 349, | ||
53 | + rv_op_slli_uw = 350, | ||
54 | + rv_op_add_uw = 351, | ||
55 | + rv_op_rolw = 352, | ||
56 | + rv_op_rorw = 353, | ||
57 | + rv_op_rev8 = 354, | ||
58 | + rv_op_zext_h = 355, | ||
59 | + rv_op_roriw = 356, | ||
60 | + rv_op_orc_b = 357, | ||
61 | + rv_op_bset = 358, | ||
62 | + rv_op_bclr = 359, | ||
63 | + rv_op_binv = 360, | ||
64 | + rv_op_bext = 361, | ||
65 | } rv_op; | ||
66 | |||
67 | /* structures */ | ||
68 | @@ -XXX,XX +XXX,XX @@ const rv_opcode_data opcode_data[] = { | ||
69 | { "fsflags", rv_codec_i_csr, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
70 | { "fsrmi", rv_codec_i_csr, rv_fmt_rd_zimm, NULL, 0, 0, 0 }, | ||
71 | { "fsflagsi", rv_codec_i_csr, rv_fmt_rd_zimm, NULL, 0, 0, 0 }, | ||
72 | + { "bseti", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
73 | + { "bclri", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
74 | + { "binvi", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
75 | + { "bexti", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
76 | + { "rori", rv_codec_i_sh7, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
77 | + { "clz", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
78 | + { "ctz", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
79 | + { "cpop", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
80 | + { "sext.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
81 | + { "sext.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
82 | + { "xnor", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
83 | + { "orn", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
84 | + { "andn", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
85 | + { "rol", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
86 | + { "ror", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
87 | + { "sh1add", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
88 | + { "sh2add", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
89 | + { "sh3add", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
90 | + { "sh1add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
91 | + { "sh2add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
92 | + { "sh3add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
93 | + { "clmul", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
94 | + { "clmulr", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
95 | + { "clmulh", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
96 | + { "min", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
97 | + { "minu", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
98 | + { "max", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
99 | + { "maxu", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
100 | + { "clzw", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
101 | + { "clzw", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
102 | + { "cpopw", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
103 | + { "slli.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
104 | + { "add.uw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
105 | + { "rolw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
106 | + { "rorw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
107 | + { "rev8", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
108 | + { "zext.h", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
109 | + { "roriw", rv_codec_i_sh5, rv_fmt_rd_rs1_imm, NULL, 0, 0, 0 }, | ||
110 | + { "orc.b", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
111 | + { "bset", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
112 | + { "bclr", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
113 | + { "binv", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
114 | + { "bext", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
115 | }; | ||
116 | |||
117 | /* CSR names */ | ||
118 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
119 | case 0: op = rv_op_addi; break; | ||
120 | case 1: | ||
121 | switch (((inst >> 27) & 0b11111)) { | ||
122 | - case 0: op = rv_op_slli; break; | ||
123 | + case 0b00000: op = rv_op_slli; break; | ||
124 | + case 0b00101: op = rv_op_bseti; break; | ||
125 | + case 0b01001: op = rv_op_bclri; break; | ||
126 | + case 0b01101: op = rv_op_binvi; break; | ||
127 | + case 0b01100: | ||
128 | + switch (((inst >> 20) & 0b1111111)) { | ||
129 | + case 0b0000000: op = rv_op_clz; break; | ||
130 | + case 0b0000001: op = rv_op_ctz; break; | ||
131 | + case 0b0000010: op = rv_op_cpop; break; | ||
132 | + /* 0b0000011 */ | ||
133 | + case 0b0000100: op = rv_op_sext_b; break; | ||
134 | + case 0b0000101: op = rv_op_sext_h; break; | ||
135 | + } | ||
136 | + break; | ||
137 | } | ||
138 | break; | ||
139 | case 2: op = rv_op_slti; break; | ||
140 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
141 | case 4: op = rv_op_xori; break; | ||
142 | case 5: | ||
143 | switch (((inst >> 27) & 0b11111)) { | ||
144 | - case 0: op = rv_op_srli; break; | ||
145 | - case 8: op = rv_op_srai; break; | ||
146 | + case 0b00000: op = rv_op_srli; break; | ||
147 | + case 0b00101: op = rv_op_orc_b; break; | ||
148 | + case 0b01000: op = rv_op_srai; break; | ||
149 | + case 0b01001: op = rv_op_bexti; break; | ||
150 | + case 0b01100: op = rv_op_rori; break; | ||
151 | + case 0b01101: | ||
152 | + switch ((inst >> 20) & 0b1111111) { | ||
153 | + case 0b0111000: op = rv_op_rev8; break; | ||
154 | + } | ||
155 | + break; | ||
156 | } | ||
157 | break; | ||
158 | case 6: op = rv_op_ori; break; | ||
159 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
160 | case 1: | ||
161 | switch (((inst >> 25) & 0b1111111)) { | ||
162 | case 0: op = rv_op_slliw; break; | ||
163 | + case 4: op = rv_op_slli_uw; break; | ||
164 | + case 48: | ||
165 | + switch ((inst >> 20) & 0b11111) { | ||
166 | + case 0b00000: op = rv_op_clzw; break; | ||
167 | + case 0b00001: op = rv_op_ctzw; break; | ||
168 | + case 0b00010: op = rv_op_cpopw; break; | ||
169 | + } | ||
170 | + break; | ||
171 | } | ||
172 | break; | ||
173 | case 5: | ||
174 | switch (((inst >> 25) & 0b1111111)) { | ||
175 | case 0: op = rv_op_srliw; break; | ||
176 | case 32: op = rv_op_sraiw; break; | ||
177 | + case 48: op = rv_op_roriw; break; | ||
178 | } | ||
179 | break; | ||
180 | } | ||
181 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
182 | case 13: op = rv_op_divu; break; | ||
183 | case 14: op = rv_op_rem; break; | ||
184 | case 15: op = rv_op_remu; break; | ||
185 | + case 36: | ||
186 | + switch ((inst >> 20) & 0b11111) { | ||
187 | + case 0: op = rv_op_zext_h; break; | ||
188 | + } | ||
189 | + break; | ||
190 | + case 41: op = rv_op_clmul; break; | ||
191 | + case 42: op = rv_op_clmulr; break; | ||
192 | + case 43: op = rv_op_clmulh; break; | ||
193 | + case 44: op = rv_op_min; break; | ||
194 | + case 45: op = rv_op_minu; break; | ||
195 | + case 46: op = rv_op_max; break; | ||
196 | + case 47: op = rv_op_maxu; break; | ||
197 | + case 130: op = rv_op_sh1add; break; | ||
198 | + case 132: op = rv_op_sh2add; break; | ||
199 | + case 134: op = rv_op_sh3add; break; | ||
200 | + case 161: op = rv_op_bset; break; | ||
201 | case 256: op = rv_op_sub; break; | ||
202 | + case 260: op = rv_op_xnor; break; | ||
203 | case 261: op = rv_op_sra; break; | ||
204 | + case 262: op = rv_op_orn; break; | ||
205 | + case 263: op = rv_op_andn; break; | ||
206 | + case 289: op = rv_op_bclr; break; | ||
207 | + case 293: op = rv_op_bext; break; | ||
208 | + case 385: op = rv_op_rol; break; | ||
209 | + case 386: op = rv_op_ror; break; | ||
210 | + case 417: op = rv_op_binv; break; | ||
211 | } | ||
212 | break; | ||
213 | case 13: op = rv_op_lui; break; | ||
214 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
215 | case 13: op = rv_op_divuw; break; | ||
216 | case 14: op = rv_op_remw; break; | ||
217 | case 15: op = rv_op_remuw; break; | ||
218 | + case 32: op = rv_op_add_uw; break; | ||
219 | + case 36: | ||
220 | + switch ((inst >> 20) & 0b11111) { | ||
221 | + case 0: op = rv_op_zext_h; break; | ||
222 | + } | ||
223 | + break; | ||
224 | + case 130: op = rv_op_sh1add_uw; break; | ||
225 | + case 132: op = rv_op_sh2add_uw; break; | ||
226 | + case 134: op = rv_op_sh3add_uw; break; | ||
227 | case 256: op = rv_op_subw; break; | ||
228 | case 261: op = rv_op_sraw; break; | ||
229 | + case 385: op = rv_op_rolw; break; | ||
230 | + case 389: op = rv_op_rorw; break; | ||
231 | } | ||
232 | break; | ||
233 | case 16: | ||
234 | -- | ||
235 | 2.31.1 | ||
236 | |||
237 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Frank Chang <frank.chang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | vs() should return -RISCV_EXCP_ILLEGAL_INST instead of -1 if rvv feature | 3 | When V=1, both vsstauts.FS and HS-level sstatus.FS are in effect. |
4 | is not enabled. | 4 | Modifying the floating-point state when V=1 causes both fields to |
5 | be set to 3 (Dirty). | ||
5 | 6 | ||
6 | If -1 is returned, exception will be raised and cs->exception_index will | 7 | However, it's possible that HS-level sstatus.FS is Clean and VS-level |
7 | be set to the negative return value. The exception will then be treated | 8 | vsstatus.FS is Dirty at the time mark_fs_dirty() is called when V=1. |
8 | as an instruction access fault instead of illegal instruction fault. | 9 | We can't early return for this case because we still need to set |
10 | sstatus.FS to Dirty according to spec. | ||
9 | 11 | ||
10 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 12 | Signed-off-by: Frank Chang <frank.chang@sifive.com> |
13 | Reviewed-by: Vincent Chen <vincent.chen@sifive.com> | ||
14 | Tested-by: Vincent Chen <vincent.chen@sifive.com> | ||
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Message-id: 20210223065935.20208-1-frank.chang@sifive.com | 17 | Message-id: 20210921020234.123448-1-frank.chang@sifive.com |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 19 | --- |
16 | target/riscv/csr.c | 2 +- | 20 | target/riscv/cpu.h | 4 ++++ |
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | 21 | target/riscv/translate.c | 30 +++++++++++++++++------------- |
22 | 2 files changed, 21 insertions(+), 13 deletions(-) | ||
18 | 23 | ||
19 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
20 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/csr.c | 26 | --- a/target/riscv/cpu.h |
22 | +++ b/target/riscv/csr.c | 27 | +++ b/target/riscv/cpu.h |
23 | @@ -XXX,XX +XXX,XX @@ static int vs(CPURISCVState *env, int csrno) | 28 | @@ -XXX,XX +XXX,XX @@ FIELD(TB_FLAGS, SEW, 5, 3) |
24 | if (env->misa & RVV) { | 29 | FIELD(TB_FLAGS, VILL, 8, 1) |
25 | return 0; | 30 | /* Is a Hypervisor instruction load/store allowed? */ |
31 | FIELD(TB_FLAGS, HLSX, 9, 1) | ||
32 | +FIELD(TB_FLAGS, MSTATUS_HS_FS, 10, 2) | ||
33 | |||
34 | bool riscv_cpu_is_32bit(CPURISCVState *env); | ||
35 | |||
36 | @@ -XXX,XX +XXX,XX @@ static inline void cpu_get_tb_cpu_state(CPURISCVState *env, target_ulong *pc, | ||
37 | get_field(env->hstatus, HSTATUS_HU))) { | ||
38 | flags = FIELD_DP32(flags, TB_FLAGS, HLSX, 1); | ||
39 | } | ||
40 | + | ||
41 | + flags = FIELD_DP32(flags, TB_FLAGS, MSTATUS_HS_FS, | ||
42 | + get_field(env->mstatus_hs, MSTATUS_FS)); | ||
26 | } | 43 | } |
27 | - return -1; | 44 | #endif |
28 | + return -RISCV_EXCP_ILLEGAL_INST; | 45 | |
46 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/riscv/translate.c | ||
49 | +++ b/target/riscv/translate.c | ||
50 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
51 | target_ulong misa; | ||
52 | uint32_t opcode; | ||
53 | uint32_t mstatus_fs; | ||
54 | + uint32_t mstatus_hs_fs; | ||
55 | uint32_t mem_idx; | ||
56 | /* Remember the rounding mode encoded in the previous fp instruction, | ||
57 | which we have already installed into env->fp_status. Or -1 for | ||
58 | @@ -XXX,XX +XXX,XX @@ static void gen_jal(DisasContext *ctx, int rd, target_ulong imm) | ||
59 | static void mark_fs_dirty(DisasContext *ctx) | ||
60 | { | ||
61 | TCGv tmp; | ||
62 | - target_ulong sd; | ||
63 | + target_ulong sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD; | ||
64 | |||
65 | - if (ctx->mstatus_fs == MSTATUS_FS) { | ||
66 | - return; | ||
67 | - } | ||
68 | - /* Remember the state change for the rest of the TB. */ | ||
69 | - ctx->mstatus_fs = MSTATUS_FS; | ||
70 | + if (ctx->mstatus_fs != MSTATUS_FS) { | ||
71 | + /* Remember the state change for the rest of the TB. */ | ||
72 | + ctx->mstatus_fs = MSTATUS_FS; | ||
73 | |||
74 | - tmp = tcg_temp_new(); | ||
75 | - sd = is_32bit(ctx) ? MSTATUS32_SD : MSTATUS64_SD; | ||
76 | + tmp = tcg_temp_new(); | ||
77 | + tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
78 | + tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
79 | + tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
80 | + tcg_temp_free(tmp); | ||
81 | + } | ||
82 | |||
83 | - tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
84 | - tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
85 | - tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus)); | ||
86 | + if (ctx->virt_enabled && ctx->mstatus_hs_fs != MSTATUS_FS) { | ||
87 | + /* Remember the stage change for the rest of the TB. */ | ||
88 | + ctx->mstatus_hs_fs = MSTATUS_FS; | ||
89 | |||
90 | - if (ctx->virt_enabled) { | ||
91 | + tmp = tcg_temp_new(); | ||
92 | tcg_gen_ld_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
93 | tcg_gen_ori_tl(tmp, tmp, MSTATUS_FS | sd); | ||
94 | tcg_gen_st_tl(tmp, cpu_env, offsetof(CPURISCVState, mstatus_hs)); | ||
95 | + tcg_temp_free(tmp); | ||
96 | } | ||
97 | - tcg_temp_free(tmp); | ||
29 | } | 98 | } |
30 | 99 | #else | |
31 | static int ctr(CPURISCVState *env, int csrno) | 100 | static inline void mark_fs_dirty(DisasContext *ctx) { } |
101 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
102 | ctx->frm = -1; /* unknown rounding mode */ | ||
103 | ctx->ext_ifencei = cpu->cfg.ext_ifencei; | ||
104 | ctx->vlen = cpu->cfg.vlen; | ||
105 | + ctx->mstatus_hs_fs = FIELD_EX32(tb_flags, TB_FLAGS, MSTATUS_HS_FS); | ||
106 | ctx->hlsx = FIELD_EX32(tb_flags, TB_FLAGS, HLSX); | ||
107 | ctx->vill = FIELD_EX32(tb_flags, TB_FLAGS, VILL); | ||
108 | ctx->sew = FIELD_EX32(tb_flags, TB_FLAGS, SEW); | ||
32 | -- | 109 | -- |
33 | 2.30.1 | 110 | 2.31.1 |
34 | 111 | ||
35 | 112 | diff view generated by jsdifflib |
1 | From: Alexander Wagner <alexander.wagner@ulal.de> | 1 | From: Bin Meng <bmeng.cn@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Not disabling the UART leads to QEMU overwriting the UART receive buffer with | 3 | The category of ibex_uart device is not set. Put it into the |
4 | the newest received byte. The rx_level variable is added to allow the use of | 4 | 'input' category. |
5 | the existing OpenTitan driver libraries. | ||
6 | 5 | ||
7 | Signed-off-by: Alexander Wagner <alexander.wagner@ulal.de> | 6 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20210309152130.13038-1-alexander.wagner@ulal.de | 9 | Message-id: 20210926105003.2716-1-bmeng.cn@gmail.com |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | include/hw/char/ibex_uart.h | 4 ++++ | 12 | hw/char/ibex_uart.c | 1 + |
13 | hw/char/ibex_uart.c | 23 ++++++++++++++++++----- | 13 | 1 file changed, 1 insertion(+) |
14 | 2 files changed, 22 insertions(+), 5 deletions(-) | ||
15 | 14 | ||
16 | diff --git a/include/hw/char/ibex_uart.h b/include/hw/char/ibex_uart.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/hw/char/ibex_uart.h | ||
19 | +++ b/include/hw/char/ibex_uart.h | ||
20 | @@ -XXX,XX +XXX,XX @@ REG32(FIFO_CTRL, 0x1c) | ||
21 | FIELD(FIFO_CTRL, RXILVL, 2, 3) | ||
22 | FIELD(FIFO_CTRL, TXILVL, 5, 2) | ||
23 | REG32(FIFO_STATUS, 0x20) | ||
24 | + FIELD(FIFO_STATUS, TXLVL, 0, 5) | ||
25 | + FIELD(FIFO_STATUS, RXLVL, 16, 5) | ||
26 | REG32(OVRD, 0x24) | ||
27 | REG32(VAL, 0x28) | ||
28 | REG32(TIMEOUT_CTRL, 0x2c) | ||
29 | @@ -XXX,XX +XXX,XX @@ struct IbexUartState { | ||
30 | uint8_t tx_fifo[IBEX_UART_TX_FIFO_SIZE]; | ||
31 | uint32_t tx_level; | ||
32 | |||
33 | + uint32_t rx_level; | ||
34 | + | ||
35 | QEMUTimer *fifo_trigger_handle; | ||
36 | uint64_t char_tx_time; | ||
37 | |||
38 | diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c | 15 | diff --git a/hw/char/ibex_uart.c b/hw/char/ibex_uart.c |
39 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/hw/char/ibex_uart.c | 17 | --- a/hw/char/ibex_uart.c |
41 | +++ b/hw/char/ibex_uart.c | 18 | +++ b/hw/char/ibex_uart.c |
42 | @@ -XXX,XX +XXX,XX @@ static int ibex_uart_can_receive(void *opaque) | 19 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_class_init(ObjectClass *klass, void *data) |
43 | { | 20 | dc->realize = ibex_uart_realize; |
44 | IbexUartState *s = opaque; | 21 | dc->vmsd = &vmstate_ibex_uart; |
45 | 22 | device_class_set_props(dc, ibex_uart_properties); | |
46 | - if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) { | 23 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
47 | + if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) | 24 | } |
48 | + && !(s->uart_status & R_STATUS_RXFULL_MASK)) { | 25 | |
49 | return 1; | 26 | static const TypeInfo ibex_uart_info = { |
50 | } | ||
51 | |||
52 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_receive(void *opaque, const uint8_t *buf, int size) | ||
53 | |||
54 | s->uart_status &= ~R_STATUS_RXIDLE_MASK; | ||
55 | s->uart_status &= ~R_STATUS_RXEMPTY_MASK; | ||
56 | + /* The RXFULL is set after receiving a single byte | ||
57 | + * as the FIFO buffers are not yet implemented. | ||
58 | + */ | ||
59 | + s->uart_status |= R_STATUS_RXFULL_MASK; | ||
60 | + s->rx_level += 1; | ||
61 | |||
62 | if (size > rx_fifo_level) { | ||
63 | s->uart_intr_state |= R_INTR_STATE_RX_WATERMARK_MASK; | ||
64 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_reset(DeviceState *dev) | ||
65 | s->uart_timeout_ctrl = 0x00000000; | ||
66 | |||
67 | s->tx_level = 0; | ||
68 | + s->rx_level = 0; | ||
69 | |||
70 | s->char_tx_time = (NANOSECONDS_PER_SECOND / 230400) * 10; | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr, | ||
73 | |||
74 | case R_RDATA: | ||
75 | retvalue = s->uart_rdata; | ||
76 | - if (s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) { | ||
77 | + if ((s->uart_ctrl & R_CTRL_RX_ENABLE_MASK) && (s->rx_level > 0)) { | ||
78 | qemu_chr_fe_accept_input(&s->chr); | ||
79 | |||
80 | - s->uart_status |= R_STATUS_RXIDLE_MASK; | ||
81 | - s->uart_status |= R_STATUS_RXEMPTY_MASK; | ||
82 | + s->rx_level -= 1; | ||
83 | + s->uart_status &= ~R_STATUS_RXFULL_MASK; | ||
84 | + if (s->rx_level == 0) { | ||
85 | + s->uart_status |= R_STATUS_RXIDLE_MASK; | ||
86 | + s->uart_status |= R_STATUS_RXEMPTY_MASK; | ||
87 | + } | ||
88 | } | ||
89 | break; | ||
90 | case R_WDATA: | ||
91 | @@ -XXX,XX +XXX,XX @@ static uint64_t ibex_uart_read(void *opaque, hwaddr addr, | ||
92 | case R_FIFO_STATUS: | ||
93 | retvalue = s->uart_fifo_status; | ||
94 | |||
95 | - retvalue |= s->tx_level & 0x1F; | ||
96 | + retvalue |= (s->rx_level & 0x1F) << R_FIFO_STATUS_RXLVL_SHIFT; | ||
97 | + retvalue |= (s->tx_level & 0x1F) << R_FIFO_STATUS_TXLVL_SHIFT; | ||
98 | |||
99 | qemu_log_mask(LOG_UNIMP, | ||
100 | "%s: RX fifos are not supported\n", __func__); | ||
101 | @@ -XXX,XX +XXX,XX @@ static void ibex_uart_write(void *opaque, hwaddr addr, | ||
102 | s->uart_fifo_ctrl = value; | ||
103 | |||
104 | if (value & R_FIFO_CTRL_RXRST_MASK) { | ||
105 | + s->rx_level = 0; | ||
106 | qemu_log_mask(LOG_UNIMP, | ||
107 | "%s: RX fifos are not supported\n", __func__); | ||
108 | } | ||
109 | -- | 27 | -- |
110 | 2.30.1 | 28 | 2.31.1 |
111 | 29 | ||
112 | 30 | diff view generated by jsdifflib |
1 | From: Asherah Connor <ashe@kivikakk.ee> | 1 | From: Bin Meng <bmeng.cn@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Allow ramfb on virt. This lets `-device ramfb' work. | 3 | The category of shakti_uart device is not set. Put it into the |
4 | 'input' category. | ||
4 | 5 | ||
5 | Signed-off-by: Asherah Connor <ashe@kivikakk.ee> | 6 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
6 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 20210318235041.17175-3-ashe@kivikakk.ee | 9 | Message-id: 20210926105003.2716-2-bmeng.cn@gmail.com |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 11 | --- |
11 | hw/riscv/virt.c | 3 +++ | 12 | hw/char/shakti_uart.c | 1 + |
12 | 1 file changed, 3 insertions(+) | 13 | 1 file changed, 1 insertion(+) |
13 | 14 | ||
14 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 15 | diff --git a/hw/char/shakti_uart.c b/hw/char/shakti_uart.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/virt.c | 17 | --- a/hw/char/shakti_uart.c |
17 | +++ b/hw/riscv/virt.c | 18 | +++ b/hw/char/shakti_uart.c |
18 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static void shakti_uart_class_init(ObjectClass *klass, void *data) |
19 | #include "sysemu/sysemu.h" | 20 | dc->reset = shakti_uart_reset; |
20 | #include "hw/pci/pci.h" | 21 | dc->realize = shakti_uart_realize; |
21 | #include "hw/pci-host/gpex.h" | 22 | device_class_set_props(dc, shakti_uart_properties); |
22 | +#include "hw/display/ramfb.h" | 23 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
23 | |||
24 | static const MemMapEntry virt_memmap[] = { | ||
25 | [VIRT_DEBUG] = { 0x0, 0x100 }, | ||
26 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) | ||
27 | mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props; | ||
28 | mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id; | ||
29 | mc->numa_mem_supported = true; | ||
30 | + | ||
31 | + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); | ||
32 | } | 24 | } |
33 | 25 | ||
34 | static const TypeInfo virt_machine_typeinfo = { | 26 | static const TypeInfo shakti_uart_info = { |
35 | -- | 27 | -- |
36 | 2.30.1 | 28 | 2.31.1 |
37 | 29 | ||
38 | 30 | diff view generated by jsdifflib |
1 | From: Jim Shu <cwshu@andestech.com> | 1 | From: Bin Meng <bmeng.cn@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | If PMP permission of any address has been changed by updating PMP entry, | 3 | The category of sifive_uart device is not set. Put it into the |
4 | flush all TLB pages to prevent from getting old permission. | 4 | 'input' category. |
5 | 5 | ||
6 | Signed-off-by: Jim Shu <cwshu@andestech.com> | 6 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-id: 1613916082-19528-4-git-send-email-cwshu@andestech.com | 9 | Message-id: 20210926105003.2716-3-bmeng.cn@gmail.com |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 11 | --- |
11 | target/riscv/pmp.c | 4 ++++ | 12 | hw/char/sifive_uart.c | 1 + |
12 | 1 file changed, 4 insertions(+) | 13 | 1 file changed, 1 insertion(+) |
13 | 14 | ||
14 | diff --git a/target/riscv/pmp.c b/target/riscv/pmp.c | 15 | diff --git a/hw/char/sifive_uart.c b/hw/char/sifive_uart.c |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/pmp.c | 17 | --- a/hw/char/sifive_uart.c |
17 | +++ b/target/riscv/pmp.c | 18 | +++ b/hw/char/sifive_uart.c |
18 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static void sifive_uart_class_init(ObjectClass *oc, void *data) |
19 | #include "qapi/error.h" | 20 | rc->phases.enter = sifive_uart_reset_enter; |
20 | #include "cpu.h" | 21 | rc->phases.hold = sifive_uart_reset_hold; |
21 | #include "trace.h" | 22 | device_class_set_props(dc, sifive_uart_properties); |
22 | +#include "exec/exec-all.h" | 23 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); |
23 | |||
24 | static void pmp_write_cfg(CPURISCVState *env, uint32_t addr_index, | ||
25 | uint8_t val); | ||
26 | @@ -XXX,XX +XXX,XX @@ void pmpcfg_csr_write(CPURISCVState *env, uint32_t reg_index, | ||
27 | cfg_val = (val >> 8 * i) & 0xff; | ||
28 | pmp_write_cfg(env, (reg_index * 4) + i, cfg_val); | ||
29 | } | ||
30 | + | ||
31 | + /* If PMP permission of any addr has been changed, flush TLB pages. */ | ||
32 | + tlb_flush(env_cpu(env)); | ||
33 | } | 24 | } |
34 | 25 | ||
35 | 26 | static const TypeInfo sifive_uart_info = { | |
36 | -- | 27 | -- |
37 | 2.30.1 | 28 | 2.31.1 |
38 | 29 | ||
39 | 30 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | According to the specification the "field SPVP of hstatus controls the | 3 | The current MCHP_PFSOC_MMUART_REG_SIZE definition represent the |
4 | privilege level of the access" for the hypervisor virtual-machine load | 4 | size occupied by all the registers. However all registers are |
5 | and store instructions HLV, HLVX and HSV. | 5 | 32-bit wide, and the MemoryRegionOps handlers are restricted to |
6 | 32-bit: | ||
6 | 7 | ||
7 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 8 | static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { |
9 | .read = mchp_pfsoc_mmuart_read, | ||
10 | .write = mchp_pfsoc_mmuart_write, | ||
11 | .impl = { | ||
12 | .min_access_size = 4, | ||
13 | .max_access_size = 4, | ||
14 | }, | ||
15 | |||
16 | Avoid being triskaidekaphobic, simplify by using the number of | ||
17 | registers. | ||
18 | |||
19 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | Reviewed-by: Bin Meng <bin.meng@windriver.com> | ||
21 | Tested-by: Bin Meng <bin.meng@windriver.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20210311103005.1400718-1-georg.kotheimer@kernkonzept.com | 23 | Message-id: 20210925133407.1259392-2-f4bug@amsat.org |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 25 | --- |
12 | target/riscv/cpu_helper.c | 25 ++++++++++++++----------- | 26 | include/hw/char/mchp_pfsoc_mmuart.h | 4 ++-- |
13 | 1 file changed, 14 insertions(+), 11 deletions(-) | 27 | hw/char/mchp_pfsoc_mmuart.c | 14 ++++++++------ |
28 | 2 files changed, 10 insertions(+), 8 deletions(-) | ||
14 | 29 | ||
15 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 30 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h |
16 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu_helper.c | 32 | --- a/include/hw/char/mchp_pfsoc_mmuart.h |
18 | +++ b/target/riscv/cpu_helper.c | 33 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h |
19 | @@ -XXX,XX +XXX,XX @@ static int get_physical_address(CPURISCVState *env, hwaddr *physical, | 34 | @@ -XXX,XX +XXX,XX @@ |
20 | use_background = true; | 35 | |
36 | #include "hw/char/serial.h" | ||
37 | |||
38 | -#define MCHP_PFSOC_MMUART_REG_SIZE 52 | ||
39 | +#define MCHP_PFSOC_MMUART_REG_COUNT 13 | ||
40 | |||
41 | typedef struct MchpPfSoCMMUartState { | ||
42 | MemoryRegion iomem; | ||
43 | @@ -XXX,XX +XXX,XX @@ typedef struct MchpPfSoCMMUartState { | ||
44 | |||
45 | SerialMM *serial; | ||
46 | |||
47 | - uint32_t reg[MCHP_PFSOC_MMUART_REG_SIZE / sizeof(uint32_t)]; | ||
48 | + uint32_t reg[MCHP_PFSOC_MMUART_REG_COUNT]; | ||
49 | } MchpPfSoCMMUartState; | ||
50 | |||
51 | /** | ||
52 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/char/mchp_pfsoc_mmuart.c | ||
55 | +++ b/hw/char/mchp_pfsoc_mmuart.c | ||
56 | @@ -XXX,XX +XXX,XX @@ static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size) | ||
57 | { | ||
58 | MchpPfSoCMMUartState *s = opaque; | ||
59 | |||
60 | - if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) { | ||
61 | + addr >>= 2; | ||
62 | + if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) { | ||
63 | qemu_log_mask(LOG_GUEST_ERROR, "%s: read: addr=0x%" HWADDR_PRIx "\n", | ||
64 | - __func__, addr); | ||
65 | + __func__, addr << 2); | ||
66 | return 0; | ||
21 | } | 67 | } |
22 | 68 | ||
23 | - if (mode == PRV_M && access_type != MMU_INST_FETCH) { | 69 | - return s->reg[addr / sizeof(uint32_t)]; |
24 | + /* MPRV does not affect the virtual-machine load/store | 70 | + return s->reg[addr]; |
25 | + instructions, HLV, HLVX, and HSV. */ | 71 | } |
26 | + if (riscv_cpu_two_stage_lookup(mmu_idx)) { | 72 | |
27 | + mode = get_field(env->hstatus, HSTATUS_SPVP); | 73 | static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr, |
28 | + } else if (mode == PRV_M && access_type != MMU_INST_FETCH) { | 74 | @@ -XXX,XX +XXX,XX @@ static void mchp_pfsoc_mmuart_write(void *opaque, hwaddr addr, |
29 | if (get_field(env->mstatus, MSTATUS_MPRV)) { | 75 | MchpPfSoCMMUartState *s = opaque; |
30 | mode = get_field(env->mstatus, MSTATUS_MPP); | 76 | uint32_t val32 = (uint32_t)value; |
31 | } | 77 | |
32 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 78 | - if (addr >= MCHP_PFSOC_MMUART_REG_SIZE) { |
33 | qemu_log_mask(CPU_LOG_MMU, "%s ad %" VADDR_PRIx " rw %d mmu_idx %d\n", | 79 | + addr >>= 2; |
34 | __func__, address, access_type, mmu_idx); | 80 | + if (addr >= MCHP_PFSOC_MMUART_REG_COUNT) { |
35 | 81 | qemu_log_mask(LOG_GUEST_ERROR, "%s: bad write: addr=0x%" HWADDR_PRIx | |
36 | - if (mode == PRV_M && access_type != MMU_INST_FETCH) { | 82 | - " v=0x%x\n", __func__, addr, val32); |
37 | - if (get_field(env->mstatus, MSTATUS_MPRV)) { | 83 | + " v=0x%x\n", __func__, addr << 2, val32); |
38 | - mode = get_field(env->mstatus, MSTATUS_MPP); | 84 | return; |
39 | + /* MPRV does not affect the virtual-machine load/store | ||
40 | + instructions, HLV, HLVX, and HSV. */ | ||
41 | + if (riscv_cpu_two_stage_lookup(mmu_idx)) { | ||
42 | + mode = get_field(env->hstatus, HSTATUS_SPVP); | ||
43 | + } else if (mode == PRV_M && access_type != MMU_INST_FETCH && | ||
44 | + get_field(env->mstatus, MSTATUS_MPRV)) { | ||
45 | + mode = get_field(env->mstatus, MSTATUS_MPP); | ||
46 | + if (riscv_has_ext(env, RVH) && get_field(env->mstatus, MSTATUS_MPV)) { | ||
47 | + two_stage_lookup = true; | ||
48 | } | ||
49 | } | 85 | } |
50 | 86 | ||
51 | - if (riscv_has_ext(env, RVH) && env->priv == PRV_M && | 87 | - s->reg[addr / sizeof(uint32_t)] = val32; |
52 | - access_type != MMU_INST_FETCH && | 88 | + s->reg[addr] = val32; |
53 | - get_field(env->mstatus, MSTATUS_MPRV) && | 89 | } |
54 | - get_field(env->mstatus, MSTATUS_MPV)) { | 90 | |
55 | - two_stage_lookup = true; | 91 | static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { |
56 | - } | ||
57 | - | ||
58 | if (riscv_cpu_virt_enabled(env) || | ||
59 | ((riscv_cpu_two_stage_lookup(mmu_idx) || two_stage_lookup) && | ||
60 | access_type != MMU_INST_FETCH)) { | ||
61 | -- | 92 | -- |
62 | 2.30.1 | 93 | 2.31.1 |
63 | 94 | ||
64 | 95 | diff view generated by jsdifflib |
1 | From: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Georg Kotheimer <georg.kotheimer@kernkonzept.com> | 3 | Our device have 2 different I/O regions: |
4 | - a 16550 UART mapped for 32-bit accesses | ||
5 | - 13 extra registers | ||
6 | |||
7 | Instead of mapping each region on the main bus, introduce | ||
8 | a container, map the 2 devices regions on the container, | ||
9 | and map the container on the main bus. | ||
10 | |||
11 | Before: | ||
12 | |||
13 | (qemu) info mtree | ||
14 | ... | ||
15 | 0000000020100000-000000002010001f (prio 0, i/o): serial | ||
16 | 0000000020100020-000000002010101f (prio 0, i/o): mchp.pfsoc.mmuart | ||
17 | 0000000020102000-000000002010201f (prio 0, i/o): serial | ||
18 | 0000000020102020-000000002010301f (prio 0, i/o): mchp.pfsoc.mmuart | ||
19 | 0000000020104000-000000002010401f (prio 0, i/o): serial | ||
20 | 0000000020104020-000000002010501f (prio 0, i/o): mchp.pfsoc.mmuart | ||
21 | 0000000020106000-000000002010601f (prio 0, i/o): serial | ||
22 | 0000000020106020-000000002010701f (prio 0, i/o): mchp.pfsoc.mmuart | ||
23 | |||
24 | After: | ||
25 | |||
26 | (qemu) info mtree | ||
27 | ... | ||
28 | 0000000020100000-0000000020100fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
29 | 0000000020100000-000000002010001f (prio 0, i/o): serial | ||
30 | 0000000020100020-0000000020100fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
31 | 0000000020102000-0000000020102fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
32 | 0000000020102000-000000002010201f (prio 0, i/o): serial | ||
33 | 0000000020102020-0000000020102fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
34 | 0000000020104000-0000000020104fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
35 | 0000000020104000-000000002010401f (prio 0, i/o): serial | ||
36 | 0000000020104020-0000000020104fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
37 | 0000000020106000-0000000020106fff (prio 0, i/o): mchp.pfsoc.mmuart | ||
38 | 0000000020106000-000000002010601f (prio 0, i/o): serial | ||
39 | 0000000020106020-0000000020106fff (prio 0, i/o): mchp.pfsoc.mmuart.regs | ||
40 | |||
41 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
42 | Reviewed-by: Bin Meng <bin.meng@windriver.com> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 43 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
5 | Message-id: 20210311094902.1377593-1-georg.kotheimer@kernkonzept.com | 44 | Tested-by: Bin Meng <bin.meng@windriver.com> |
45 | Message-id: 20210925133407.1259392-3-f4bug@amsat.org | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 46 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | --- | 47 | --- |
8 | target/riscv/csr.c | 7 ++++--- | 48 | include/hw/char/mchp_pfsoc_mmuart.h | 1 + |
9 | 1 file changed, 4 insertions(+), 3 deletions(-) | 49 | hw/char/mchp_pfsoc_mmuart.c | 11 ++++++++--- |
50 | 2 files changed, 9 insertions(+), 3 deletions(-) | ||
10 | 51 | ||
11 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 52 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h |
12 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/riscv/csr.c | 54 | --- a/include/hw/char/mchp_pfsoc_mmuart.h |
14 | +++ b/target/riscv/csr.c | 55 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h |
15 | @@ -XXX,XX +XXX,XX @@ static const target_ulong sstatus_v1_10_mask = SSTATUS_SIE | SSTATUS_SPIE | | 56 | @@ -XXX,XX +XXX,XX @@ |
16 | SSTATUS_UIE | SSTATUS_UPIE | SSTATUS_SPP | SSTATUS_FS | SSTATUS_XS | | 57 | #define MCHP_PFSOC_MMUART_REG_COUNT 13 |
17 | SSTATUS_SUM | SSTATUS_MXR | SSTATUS_SD; | 58 | |
18 | static const target_ulong sip_writable_mask = SIP_SSIP | MIP_USIP | MIP_UEIP; | 59 | typedef struct MchpPfSoCMMUartState { |
19 | -static const target_ulong hip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; | 60 | + MemoryRegion container; |
20 | +static const target_ulong hip_writable_mask = MIP_VSSIP; | 61 | MemoryRegion iomem; |
21 | +static const target_ulong hvip_writable_mask = MIP_VSSIP | MIP_VSTIP | MIP_VSEIP; | 62 | hwaddr base; |
22 | static const target_ulong vsip_writable_mask = MIP_VSSIP; | 63 | qemu_irq irq; |
23 | 64 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | |
24 | static const char valid_vm_1_10_32[16] = { | 65 | index XXXXXXX..XXXXXXX 100644 |
25 | @@ -XXX,XX +XXX,XX @@ static int rmw_hvip(CPURISCVState *env, int csrno, target_ulong *ret_value, | 66 | --- a/hw/char/mchp_pfsoc_mmuart.c |
26 | target_ulong new_value, target_ulong write_mask) | 67 | +++ b/hw/char/mchp_pfsoc_mmuart.c |
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | #include "chardev/char.h" | ||
70 | #include "hw/char/mchp_pfsoc_mmuart.h" | ||
71 | |||
72 | +#define REGS_OFFSET 0x20 | ||
73 | + | ||
74 | static uint64_t mchp_pfsoc_mmuart_read(void *opaque, hwaddr addr, unsigned size) | ||
27 | { | 75 | { |
28 | int ret = rmw_mip(env, 0, ret_value, new_value, | 76 | MchpPfSoCMMUartState *s = opaque; |
29 | - write_mask & hip_writable_mask); | 77 | @@ -XXX,XX +XXX,XX @@ MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, |
30 | + write_mask & hvip_writable_mask); | 78 | |
31 | 79 | s = g_new0(MchpPfSoCMMUartState, 1); | |
32 | - *ret_value &= hip_writable_mask; | 80 | |
33 | + *ret_value &= hvip_writable_mask; | 81 | + memory_region_init(&s->container, NULL, "mchp.pfsoc.mmuart", 0x1000); |
34 | 82 | + | |
35 | return ret; | 83 | memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s, |
84 | - "mchp.pfsoc.mmuart", 0x1000); | ||
85 | + "mchp.pfsoc.mmuart.regs", 0x1000 - REGS_OFFSET); | ||
86 | + memory_region_add_subregion(&s->container, REGS_OFFSET, &s->iomem); | ||
87 | |||
88 | s->base = base; | ||
89 | s->irq = irq; | ||
90 | |||
91 | - s->serial = serial_mm_init(sysmem, base, 2, irq, 399193, chr, | ||
92 | + s->serial = serial_mm_init(&s->container, 0, 2, irq, 399193, chr, | ||
93 | DEVICE_LITTLE_ENDIAN); | ||
94 | |||
95 | - memory_region_add_subregion(sysmem, base + 0x20, &s->iomem); | ||
96 | + memory_region_add_subregion(sysmem, base, &s->container); | ||
97 | |||
98 | return s; | ||
36 | } | 99 | } |
37 | -- | 100 | -- |
38 | 2.30.1 | 101 | 2.31.1 |
39 | 102 | ||
40 | 103 | diff view generated by jsdifflib |
1 | From: Asherah Connor <ashe@kivikakk.ee> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Provides fw_cfg for the virt machine on riscv. This enables | 3 | - Embed SerialMM in MchpPfSoCMMUartState and QOM-initialize it |
4 | using e.g. ramfb later. | 4 | - Alias SERIAL_MM 'chardev' property on MCHP_PFSOC_UART |
5 | - Forward SerialMM sysbus IRQ in mchp_pfsoc_mmuart_realize() | ||
6 | - Add DeviceReset() method | ||
7 | - Add vmstate structure for migration | ||
8 | - Register device in 'input' category | ||
9 | - Keep mchp_pfsoc_mmuart_create() behavior | ||
5 | 10 | ||
6 | Signed-off-by: Asherah Connor <ashe@kivikakk.ee> | 11 | Note, serial_mm_init() calls qdev_set_legacy_instance_id(). |
7 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 12 | This call is only needed for backwards-compatibility of incoming |
13 | migration data with old versions of QEMU which implemented migration | ||
14 | of devices with hand-rolled code. Since this device didn't previously | ||
15 | handle migration at all, then it doesn't need to set the legacy | ||
16 | instance ID. | ||
17 | |||
18 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Reviewed-by: Bin Meng <bin.meng@windriver.com> | ||
20 | Tested-by: Bin Meng <bin.meng@windriver.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-id: 20210318235041.17175-2-ashe@kivikakk.ee | 22 | Message-id: 20210925133407.1259392-4-f4bug@amsat.org |
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 23 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 24 | --- |
12 | include/hw/riscv/virt.h | 2 ++ | 25 | include/hw/char/mchp_pfsoc_mmuart.h | 12 +++- |
13 | hw/riscv/virt.c | 30 ++++++++++++++++++++++++++++++ | 26 | hw/char/mchp_pfsoc_mmuart.c | 97 +++++++++++++++++++++++++---- |
14 | hw/riscv/Kconfig | 1 + | 27 | 2 files changed, 93 insertions(+), 16 deletions(-) |
15 | 3 files changed, 33 insertions(+) | ||
16 | 28 | ||
17 | diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h | 29 | diff --git a/include/hw/char/mchp_pfsoc_mmuart.h b/include/hw/char/mchp_pfsoc_mmuart.h |
18 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/riscv/virt.h | 31 | --- a/include/hw/char/mchp_pfsoc_mmuart.h |
20 | +++ b/include/hw/riscv/virt.h | 32 | +++ b/include/hw/char/mchp_pfsoc_mmuart.h |
21 | @@ -XXX,XX +XXX,XX @@ struct RISCVVirtState { | 33 | @@ -XXX,XX +XXX,XX @@ |
22 | RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; | 34 | #ifndef HW_MCHP_PFSOC_MMUART_H |
23 | DeviceState *plic[VIRT_SOCKETS_MAX]; | 35 | #define HW_MCHP_PFSOC_MMUART_H |
24 | PFlashCFI01 *flash[2]; | 36 | |
25 | + FWCfgState *fw_cfg; | 37 | +#include "hw/sysbus.h" |
26 | 38 | #include "hw/char/serial.h" | |
27 | int fdt_size; | 39 | |
40 | #define MCHP_PFSOC_MMUART_REG_COUNT 13 | ||
41 | |||
42 | +#define TYPE_MCHP_PFSOC_UART "mchp.pfsoc.uart" | ||
43 | +OBJECT_DECLARE_SIMPLE_TYPE(MchpPfSoCMMUartState, MCHP_PFSOC_UART) | ||
44 | + | ||
45 | typedef struct MchpPfSoCMMUartState { | ||
46 | + /*< private >*/ | ||
47 | + SysBusDevice parent_obj; | ||
48 | + | ||
49 | + /*< public >*/ | ||
50 | MemoryRegion container; | ||
51 | MemoryRegion iomem; | ||
52 | - hwaddr base; | ||
53 | - qemu_irq irq; | ||
54 | |||
55 | - SerialMM *serial; | ||
56 | + SerialMM serial_mm; | ||
57 | |||
58 | uint32_t reg[MCHP_PFSOC_MMUART_REG_COUNT]; | ||
59 | } MchpPfSoCMMUartState; | ||
60 | diff --git a/hw/char/mchp_pfsoc_mmuart.c b/hw/char/mchp_pfsoc_mmuart.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/hw/char/mchp_pfsoc_mmuart.c | ||
63 | +++ b/hw/char/mchp_pfsoc_mmuart.c | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | |||
66 | #include "qemu/osdep.h" | ||
67 | #include "qemu/log.h" | ||
68 | -#include "chardev/char.h" | ||
69 | +#include "qapi/error.h" | ||
70 | +#include "migration/vmstate.h" | ||
71 | #include "hw/char/mchp_pfsoc_mmuart.h" | ||
72 | +#include "hw/qdev-properties.h" | ||
73 | |||
74 | #define REGS_OFFSET 0x20 | ||
75 | |||
76 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps mchp_pfsoc_mmuart_ops = { | ||
77 | }, | ||
28 | }; | 78 | }; |
29 | @@ -XXX,XX +XXX,XX @@ enum { | 79 | |
30 | VIRT_PLIC, | 80 | -MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, |
31 | VIRT_UART0, | 81 | - hwaddr base, qemu_irq irq, Chardev *chr) |
32 | VIRT_VIRTIO, | 82 | +static void mchp_pfsoc_mmuart_reset(DeviceState *dev) |
33 | + VIRT_FW_CFG, | ||
34 | VIRT_FLASH, | ||
35 | VIRT_DRAM, | ||
36 | VIRT_PCIE_MMIO, | ||
37 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/hw/riscv/virt.c | ||
40 | +++ b/hw/riscv/virt.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry virt_memmap[] = { | ||
42 | [VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) }, | ||
43 | [VIRT_UART0] = { 0x10000000, 0x100 }, | ||
44 | [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, | ||
45 | + [VIRT_FW_CFG] = { 0x10100000, 0x18 }, | ||
46 | [VIRT_FLASH] = { 0x20000000, 0x4000000 }, | ||
47 | [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, | ||
48 | [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 }, | ||
49 | @@ -XXX,XX +XXX,XX @@ static inline DeviceState *gpex_pcie_init(MemoryRegion *sys_mem, | ||
50 | return dev; | ||
51 | } | ||
52 | |||
53 | +static FWCfgState *create_fw_cfg(const MachineState *mc) | ||
54 | +{ | 83 | +{ |
55 | + hwaddr base = virt_memmap[VIRT_FW_CFG].base; | 84 | + MchpPfSoCMMUartState *s = MCHP_PFSOC_UART(dev); |
56 | + hwaddr size = virt_memmap[VIRT_FW_CFG].size; | ||
57 | + FWCfgState *fw_cfg; | ||
58 | + char *nodename; | ||
59 | + | 85 | + |
60 | + fw_cfg = fw_cfg_init_mem_wide(base + 8, base, 8, base + 16, | 86 | + memset(s->reg, 0, sizeof(s->reg)); |
61 | + &address_space_memory); | 87 | + device_cold_reset(DEVICE(&s->serial_mm)); |
62 | + fw_cfg_add_i16(fw_cfg, FW_CFG_NB_CPUS, (uint16_t)mc->smp.cpus); | ||
63 | + | ||
64 | + nodename = g_strdup_printf("/fw-cfg@%" PRIx64, base); | ||
65 | + qemu_fdt_add_subnode(mc->fdt, nodename); | ||
66 | + qemu_fdt_setprop_string(mc->fdt, nodename, | ||
67 | + "compatible", "qemu,fw-cfg-mmio"); | ||
68 | + qemu_fdt_setprop_sized_cells(mc->fdt, nodename, "reg", | ||
69 | + 2, base, 2, size); | ||
70 | + qemu_fdt_setprop(mc->fdt, nodename, "dma-coherent", NULL, 0); | ||
71 | + g_free(nodename); | ||
72 | + return fw_cfg; | ||
73 | +} | 88 | +} |
74 | + | 89 | + |
75 | static void virt_machine_init(MachineState *machine) | 90 | +static void mchp_pfsoc_mmuart_init(Object *obj) |
76 | { | 91 | { |
77 | const MemMapEntry *memmap = virt_memmap; | 92 | - MchpPfSoCMMUartState *s; |
78 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 93 | + MchpPfSoCMMUartState *s = MCHP_PFSOC_UART(obj); |
79 | start_addr = virt_memmap[VIRT_FLASH].base; | 94 | |
80 | } | 95 | - s = g_new0(MchpPfSoCMMUartState, 1); |
81 | 96 | + object_initialize_child(obj, "serial-mm", &s->serial_mm, TYPE_SERIAL_MM); | |
82 | + /* | 97 | + object_property_add_alias(obj, "chardev", OBJECT(&s->serial_mm), "chardev"); |
83 | + * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device | 98 | +} |
84 | + * tree cannot be altered and we get FDT_ERR_NOSPACE. | 99 | |
85 | + */ | 100 | - memory_region_init(&s->container, NULL, "mchp.pfsoc.mmuart", 0x1000); |
86 | + s->fw_cfg = create_fw_cfg(machine); | 101 | +static void mchp_pfsoc_mmuart_realize(DeviceState *dev, Error **errp) |
87 | + rom_set_fw(s->fw_cfg); | 102 | +{ |
103 | + MchpPfSoCMMUartState *s = MCHP_PFSOC_UART(dev); | ||
104 | |||
105 | - memory_region_init_io(&s->iomem, NULL, &mchp_pfsoc_mmuart_ops, s, | ||
106 | + qdev_prop_set_uint8(DEVICE(&s->serial_mm), "regshift", 2); | ||
107 | + qdev_prop_set_uint32(DEVICE(&s->serial_mm), "baudbase", 399193); | ||
108 | + qdev_prop_set_uint8(DEVICE(&s->serial_mm), "endianness", | ||
109 | + DEVICE_LITTLE_ENDIAN); | ||
110 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->serial_mm), errp)) { | ||
111 | + return; | ||
112 | + } | ||
88 | + | 113 | + |
89 | /* Compute the fdt load address in dram */ | 114 | + sysbus_pass_irq(SYS_BUS_DEVICE(dev), SYS_BUS_DEVICE(&s->serial_mm)); |
90 | fdt_load_addr = riscv_load_fdt(memmap[VIRT_DRAM].base, | 115 | + |
91 | machine->ram_size, machine->fdt); | 116 | + memory_region_init(&s->container, OBJECT(s), "mchp.pfsoc.mmuart", 0x1000); |
92 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | 117 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container); |
93 | index XXXXXXX..XXXXXXX 100644 | 118 | + |
94 | --- a/hw/riscv/Kconfig | 119 | + memory_region_add_subregion(&s->container, 0, |
95 | +++ b/hw/riscv/Kconfig | 120 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->serial_mm), 0)); |
96 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | 121 | + |
97 | select SIFIVE_PLIC | 122 | + memory_region_init_io(&s->iomem, OBJECT(s), &mchp_pfsoc_mmuart_ops, s, |
98 | select SIFIVE_TEST | 123 | "mchp.pfsoc.mmuart.regs", 0x1000 - REGS_OFFSET); |
99 | select VIRTIO_MMIO | 124 | memory_region_add_subregion(&s->container, REGS_OFFSET, &s->iomem); |
100 | + select FW_CFG_DMA | 125 | +} |
101 | 126 | ||
102 | config SIFIVE_E | 127 | - s->base = base; |
103 | bool | 128 | - s->irq = irq; |
129 | +static const VMStateDescription mchp_pfsoc_mmuart_vmstate = { | ||
130 | + .name = "mchp.pfsoc.uart", | ||
131 | + .version_id = 0, | ||
132 | + .minimum_version_id = 0, | ||
133 | + .fields = (VMStateField[]) { | ||
134 | + VMSTATE_UINT32_ARRAY(reg, MchpPfSoCMMUartState, | ||
135 | + MCHP_PFSOC_MMUART_REG_COUNT), | ||
136 | + VMSTATE_END_OF_LIST() | ||
137 | + } | ||
138 | +}; | ||
139 | + | ||
140 | +static void mchp_pfsoc_mmuart_class_init(ObjectClass *oc, void *data) | ||
141 | +{ | ||
142 | + DeviceClass *dc = DEVICE_CLASS(oc); | ||
143 | + | ||
144 | + dc->realize = mchp_pfsoc_mmuart_realize; | ||
145 | + dc->reset = mchp_pfsoc_mmuart_reset; | ||
146 | + dc->vmsd = &mchp_pfsoc_mmuart_vmstate; | ||
147 | + set_bit(DEVICE_CATEGORY_INPUT, dc->categories); | ||
148 | +} | ||
149 | + | ||
150 | +static const TypeInfo mchp_pfsoc_mmuart_info = { | ||
151 | + .name = TYPE_MCHP_PFSOC_UART, | ||
152 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
153 | + .instance_size = sizeof(MchpPfSoCMMUartState), | ||
154 | + .instance_init = mchp_pfsoc_mmuart_init, | ||
155 | + .class_init = mchp_pfsoc_mmuart_class_init, | ||
156 | +}; | ||
157 | + | ||
158 | +static void mchp_pfsoc_mmuart_register_types(void) | ||
159 | +{ | ||
160 | + type_register_static(&mchp_pfsoc_mmuart_info); | ||
161 | +} | ||
162 | + | ||
163 | +type_init(mchp_pfsoc_mmuart_register_types) | ||
164 | + | ||
165 | +MchpPfSoCMMUartState *mchp_pfsoc_mmuart_create(MemoryRegion *sysmem, | ||
166 | + hwaddr base, | ||
167 | + qemu_irq irq, Chardev *chr) | ||
168 | +{ | ||
169 | + DeviceState *dev = qdev_new(TYPE_MCHP_PFSOC_UART); | ||
170 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
171 | |||
172 | - s->serial = serial_mm_init(&s->container, 0, 2, irq, 399193, chr, | ||
173 | - DEVICE_LITTLE_ENDIAN); | ||
174 | + qdev_prop_set_chr(dev, "chardev", chr); | ||
175 | + sysbus_realize(sbd, &error_fatal); | ||
176 | |||
177 | - memory_region_add_subregion(sysmem, base, &s->container); | ||
178 | + memory_region_add_subregion(sysmem, base, sysbus_mmio_get_region(sbd, 0)); | ||
179 | + sysbus_connect_irq(sbd, 0, irq); | ||
180 | |||
181 | - return s; | ||
182 | + return MCHP_PFSOC_UART(dev); | ||
183 | } | ||
104 | -- | 184 | -- |
105 | 2.30.1 | 185 | 2.31.1 |
106 | 186 | ||
107 | 187 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Bin Meng <bmeng.cn@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Per SST25VF016B datasheet [1], SST flash requires a dummy byte after | 3 | At present the codes detect whether the DMA channel is claimed by: |
4 | the address bytes. Note only SPI mode is supported by SST flashes. | ||
5 | 4 | ||
6 | [1] http://ww1.microchip.com/downloads/en/devicedoc/s71271_04.pdf | 5 | claimed = !!s->chan[ch].control & CONTROL_CLAIM; |
7 | 6 | ||
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 7 | As ! has higher precedence over & (bitwise and), this is essentially |
9 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 8 | |
10 | Message-id: 20210306060152.7250-1-bmeng.cn@gmail.com | 9 | claimed = (!!s->chan[ch].control) & CONTROL_CLAIM; |
10 | |||
11 | which is wrong, as any non-zero bit set in the control register will | ||
12 | produce a result of a claimed channel. | ||
13 | |||
14 | Fixes: de7c7988d25d ("hw/dma: sifive_pdma: reset Next* registers when Control.claim is set") | ||
15 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Message-id: 20210927072124.1564129-1-bmeng.cn@gmail.com | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 19 | --- |
13 | hw/block/m25p80.c | 3 +++ | 20 | hw/dma/sifive_pdma.c | 2 +- |
14 | 1 file changed, 3 insertions(+) | 21 | 1 file changed, 1 insertion(+), 1 deletion(-) |
15 | 22 | ||
16 | diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c | 23 | diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c |
17 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/block/m25p80.c | 25 | --- a/hw/dma/sifive_pdma.c |
19 | +++ b/hw/block/m25p80.c | 26 | +++ b/hw/dma/sifive_pdma.c |
20 | @@ -XXX,XX +XXX,XX @@ static void decode_fast_read_cmd(Flash *s) | 27 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, |
21 | s->needed_bytes = get_addr_length(s); | 28 | offset &= 0xfff; |
22 | switch (get_man(s)) { | 29 | switch (offset) { |
23 | /* Dummy cycles - modeled with bytes writes instead of bits */ | 30 | case DMA_CONTROL: |
24 | + case MAN_SST: | 31 | - claimed = !!s->chan[ch].control & CONTROL_CLAIM; |
25 | + s->needed_bytes += 1; | 32 | + claimed = !!(s->chan[ch].control & CONTROL_CLAIM); |
26 | + break; | 33 | |
27 | case MAN_WINBOND: | 34 | if (!claimed && (value & CONTROL_CLAIM)) { |
28 | s->needed_bytes += 8; | 35 | /* reset Next* registers */ |
29 | break; | ||
30 | -- | 36 | -- |
31 | 2.30.1 | 37 | 2.31.1 |
32 | 38 | ||
33 | 39 | diff view generated by jsdifflib |
1 | From: Jim Shu <cwshu@andestech.com> | 1 | From: Bin Meng <bmeng.cn@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Like MMU translation, add qemu log of PMP permission checking for | 3 | If Control.run bit is set while not preserving the Control.claim |
4 | debugging. | 4 | bit, the DMA transfer shall not be started. |
5 | 5 | ||
6 | Signed-off-by: Jim Shu <cwshu@andestech.com> | 6 | The following result is PDMA tested in U-Boot on Unleashed board: |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | |
8 | Message-id: 1613916082-19528-3-git-send-email-cwshu@andestech.com | 8 | => mw.l 0x3000000 0x0 <= Disclaim channel 0 |
9 | => mw.l 0x3000000 0x1 <= Claim channel 0 | ||
10 | => mw.l 0x3000004 0x55000000 <= wsize = rsize = 5 (2^5 = 32 bytes) | ||
11 | => mw.q 0x3000008 0x2 <= NextBytes = 2 | ||
12 | => mw.q 0x3000010 0x84000000 <= NextDestination = 0x84000000 | ||
13 | => mw.q 0x3000018 0x84001000 <= NextSource = 0x84001000 | ||
14 | => mw.l 0x84000000 0x87654321 <= Fill test data to dst | ||
15 | => mw.l 0x84001000 0x12345678 <= Fill test data to src | ||
16 | => md.l 0x84000000 1; md.l 0x84001000 1 <= Dump src/dst memory contents | ||
17 | 84000000: 87654321 !Ce. | ||
18 | 84001000: 12345678 xV4. | ||
19 | => md.l 0x3000000 8 <= Dump PDMA status | ||
20 | 03000000: 00000001 55000000 00000002 00000000 .......U........ | ||
21 | 03000010: 84000000 00000000 84001000 00000000 ................ | ||
22 | => mw.l 0x3000000 0x2 <= Set channel 0 run bit only | ||
23 | => md.l 0x3000000 8 <= Dump PDMA status | ||
24 | 03000000: 00000000 55000000 00000002 00000000 .......U........ | ||
25 | 03000010: 84000000 00000000 84001000 00000000 ................ | ||
26 | => md.l 0x84000000 1; md.l 0x84001000 1 <= Dump src/dst memory contents | ||
27 | 84000000: 87654321 !Ce. | ||
28 | 84001000: 12345678 xV4. | ||
29 | |||
30 | Signed-off-by: Bin Meng <bmeng.cn@gmail.com> | ||
31 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
32 | Message-id: 20210927072124.1564129-2-bmeng.cn@gmail.com | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 34 | --- |
11 | target/riscv/cpu_helper.c | 12 ++++++++++++ | 35 | hw/dma/sifive_pdma.c | 11 +++++++++-- |
12 | 1 file changed, 12 insertions(+) | 36 | 1 file changed, 9 insertions(+), 2 deletions(-) |
13 | 37 | ||
14 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 38 | diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c |
15 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/riscv/cpu_helper.c | 40 | --- a/hw/dma/sifive_pdma.c |
17 | +++ b/target/riscv/cpu_helper.c | 41 | +++ b/hw/dma/sifive_pdma.c |
18 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 42 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, |
19 | if (ret == TRANSLATE_SUCCESS) { | 43 | { |
20 | ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | 44 | SiFivePDMAState *s = opaque; |
21 | size, access_type, mode); | 45 | int ch = SIFIVE_PDMA_CHAN_NO(offset); |
46 | - bool claimed; | ||
47 | + bool claimed, run; | ||
48 | |||
49 | if (ch >= SIFIVE_PDMA_CHANS) { | ||
50 | qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid channel no %d\n", | ||
51 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, | ||
52 | switch (offset) { | ||
53 | case DMA_CONTROL: | ||
54 | claimed = !!(s->chan[ch].control & CONTROL_CLAIM); | ||
55 | + run = !!(s->chan[ch].control & CONTROL_RUN); | ||
56 | |||
57 | if (!claimed && (value & CONTROL_CLAIM)) { | ||
58 | /* reset Next* registers */ | ||
59 | @@ -XXX,XX +XXX,XX @@ static void sifive_pdma_write(void *opaque, hwaddr offset, | ||
60 | s->chan[ch].next_src = 0; | ||
61 | } | ||
62 | |||
63 | + /* claim bit can only be cleared when run is low */ | ||
64 | + if (run && !(value & CONTROL_CLAIM)) { | ||
65 | + value |= CONTROL_CLAIM; | ||
66 | + } | ||
22 | + | 67 | + |
23 | + qemu_log_mask(CPU_LOG_MMU, | 68 | s->chan[ch].control = value; |
24 | + "%s PMP address=" TARGET_FMT_plx " ret %d prot" | 69 | |
25 | + " %d tlb_size " TARGET_FMT_lu "\n", | 70 | /* |
26 | + __func__, pa, ret, prot_pmp, tlb_size); | 71 | * If channel was not claimed before run bit is set, |
27 | + | 72 | + * or if the channel is disclaimed when run was low, |
28 | prot &= prot_pmp; | 73 | * DMA won't run. |
29 | } | 74 | */ |
30 | 75 | - if (!claimed) { | |
31 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 76 | + if (!claimed || (!run && !(value & CONTROL_CLAIM))) { |
32 | if (ret == TRANSLATE_SUCCESS) { | 77 | s->chan[ch].control &= ~CONTROL_RUN; |
33 | ret = get_physical_address_pmp(env, &prot_pmp, &tlb_size, pa, | 78 | return; |
34 | size, access_type, mode); | ||
35 | + | ||
36 | + qemu_log_mask(CPU_LOG_MMU, | ||
37 | + "%s PMP address=" TARGET_FMT_plx " ret %d prot" | ||
38 | + " %d tlb_size " TARGET_FMT_lu "\n", | ||
39 | + __func__, pa, ret, prot_pmp, tlb_size); | ||
40 | + | ||
41 | prot &= prot_pmp; | ||
42 | } | 79 | } |
43 | } | ||
44 | -- | 80 | -- |
45 | 2.30.1 | 81 | 2.31.1 |
46 | 82 | ||
47 | 83 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alistair Francis <alistair.francis@wdc.com> | ||
1 | 2 | ||
3 | Mark the shakti_c machine as not user creatable. | ||
4 | |||
5 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/639 | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-Id: <c617a04d4e3dd041a3427b47a1b1d5ab475a2edd.1632871759.git.alistair.francis@wdc.com> | ||
11 | --- | ||
12 | hw/riscv/shakti_c.c | 7 +++++++ | ||
13 | 1 file changed, 7 insertions(+) | ||
14 | |||
15 | diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/riscv/shakti_c.c | ||
18 | +++ b/hw/riscv/shakti_c.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void shakti_c_soc_class_init(ObjectClass *klass, void *data) | ||
20 | { | ||
21 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
22 | dc->realize = shakti_c_soc_state_realize; | ||
23 | + /* | ||
24 | + * Reasons: | ||
25 | + * - Creates CPUS in riscv_hart_realize(), and can create unintended | ||
26 | + * CPUs | ||
27 | + * - Uses serial_hds in realize function, thus can't be used twice | ||
28 | + */ | ||
29 | + dc->user_creatable = false; | ||
30 | } | ||
31 | |||
32 | static void shakti_c_soc_instance_init(Object *obj) | ||
33 | -- | ||
34 | 2.31.1 | ||
35 | |||
36 | diff view generated by jsdifflib |