1 | The following changes since commit ad1b4ec39caa5b3f17cbd8160283a03a3dcfe2ae: | 1 | arm queue: big stuff here is my MVE codegen optimisation, |
---|---|---|---|
2 | and Alex's Apple Silicon hvf support. | ||
2 | 3 | ||
3 | Merge remote-tracking branch 'remotes/kraxel/tags/input-20180515-pull-request' into staging (2018-05-15 12:50:06 +0100) | 4 | -- PMM |
5 | |||
6 | The following changes since commit 7adb961995a3744f51396502b33ad04a56a317c3: | ||
7 | |||
8 | Merge remote-tracking branch 'remotes/dgilbert-gitlab/tags/pull-virtiofs-20210916' into staging (2021-09-19 18:53:29 +0100) | ||
4 | 9 | ||
5 | are available in the Git repository at: | 10 | are available in the Git repository at: |
6 | 11 | ||
7 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180515 | 12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210920 |
8 | 13 | ||
9 | for you to fetch changes up to ae7651804748c6b479d5ae09aeac4edb9c44f76e: | 14 | for you to fetch changes up to 1dc5a60bfe406bc1122d68cbdefda38d23134b27: |
10 | 15 | ||
11 | tcg: Optionally log FPU state in TCG -d cpu logging (2018-05-15 14:58:44 +0100) | 16 | target/arm: Optimize MVE 1op-immediate insns (2021-09-20 14:18:01 +0100) |
12 | 17 | ||
13 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
14 | target-arm queue: | 19 | target-arm queue: |
15 | * Fix coverity nit in int_to_float code | 20 | * Optimize codegen for MVE when predication not active |
16 | * Don't set Invalid for float-to-int(MAXINT) | 21 | * hvf: Add Apple Silicon support |
17 | * Fix fp_status_f16 tininess before rounding | 22 | * hw/intc: Set GIC maintenance interrupt level to only 0 or 1 |
18 | * Add various missing insns from the v8.2-FP16 extension | 23 | * Fix mishandling of MVE FPSCR.LTPSIZE reset for usermode emulator |
19 | * Fix sqrt_f16 exception raising | 24 | * elf2dmp: Fix coverity nits |
20 | * sdcard: Correct CRC16 offset in sd_function_switch() | ||
21 | * tcg: Optionally log FPU state in TCG -d cpu logging | ||
22 | 25 | ||
23 | ---------------------------------------------------------------- | 26 | ---------------------------------------------------------------- |
24 | Alex Bennée (5): | 27 | Alexander Graf (7): |
25 | fpu/softfloat: int_to_float ensure r fully initialised | 28 | arm: Move PMC register definitions to internals.h |
26 | target/arm: Implement FCMP for fp16 | 29 | hvf: Add execute to dirty log permission bitmap |
27 | target/arm: Implement FCSEL for fp16 | 30 | hvf: Introduce hvf_arch_init() callback |
28 | target/arm: Implement FMOV (immediate) for fp16 | 31 | hvf: Add Apple Silicon support |
29 | target/arm: Fix sqrt_f16 exception raising | 32 | hvf: arm: Implement PSCI handling |
33 | arm: Add Hypervisor.framework build target | ||
34 | hvf: arm: Add rudimentary PMC support | ||
30 | 35 | ||
31 | Peter Maydell (3): | 36 | Peter Collingbourne (1): |
32 | fpu/softfloat: Don't set Invalid for float-to-int(MAXINT) | 37 | arm/hvf: Add a WFI handler |
33 | target/arm: Fix fp_status_f16 tininess before rounding | ||
34 | tcg: Optionally log FPU state in TCG -d cpu logging | ||
35 | 38 | ||
36 | Philippe Mathieu-Daudé (1): | 39 | Peter Maydell (18): |
37 | sdcard: Correct CRC16 offset in sd_function_switch() | 40 | elf2dmp: Check curl_easy_setopt() return value |
41 | elf2dmp: Fail cleanly if PDB file specifies zero block_size | ||
42 | target/arm: Don't skip M-profile reset entirely in user mode | ||
43 | target/arm: Always clear exclusive monitor on reset | ||
44 | target/arm: Consolidate ifdef blocks in reset | ||
45 | hvf: arm: Implement -cpu host | ||
46 | target/arm: Avoid goto_tb if we're trying to exit to the main loop | ||
47 | target/arm: Enforce that FPDSCR.LTPSIZE is 4 on inbound migration | ||
48 | target/arm: Add TB flag for "MVE insns not predicated" | ||
49 | target/arm: Optimize MVE logic ops | ||
50 | target/arm: Optimize MVE arithmetic ops | ||
51 | target/arm: Optimize MVE VNEG, VABS | ||
52 | target/arm: Optimize MVE VDUP | ||
53 | target/arm: Optimize MVE VMVN | ||
54 | target/arm: Optimize MVE VSHL, VSHR immediate forms | ||
55 | target/arm: Optimize MVE VSHLL and VMOVL | ||
56 | target/arm: Optimize MVE VSLI and VSRI | ||
57 | target/arm: Optimize MVE 1op-immediate insns | ||
38 | 58 | ||
39 | Richard Henderson (7): | 59 | Shashi Mallela (1): |
40 | target/arm: Implement FMOV (general) for fp16 | 60 | hw/intc: Set GIC maintenance interrupt level to only 0 or 1 |
41 | target/arm: Early exit after unallocated_encoding in disas_fp_int_conv | ||
42 | target/arm: Implement FCVT (scalar, integer) for fp16 | ||
43 | target/arm: Implement FCVT (scalar, fixed-point) for fp16 | ||
44 | target/arm: Introduce and use read_fp_hreg | ||
45 | target/arm: Implement FP data-processing (2 source) for fp16 | ||
46 | target/arm: Implement FP data-processing (3 source) for fp16 | ||
47 | 61 | ||
48 | include/qemu/log.h | 1 + | 62 | meson.build | 8 + |
49 | target/arm/helper-a64.h | 2 + | 63 | include/sysemu/hvf_int.h | 12 +- |
50 | target/arm/helper.h | 6 + | 64 | target/arm/cpu.h | 6 +- |
51 | accel/tcg/cpu-exec.c | 9 +- | 65 | target/arm/hvf_arm.h | 18 + |
52 | fpu/softfloat.c | 6 +- | 66 | target/arm/internals.h | 44 ++ |
53 | hw/sd/sd.c | 2 +- | 67 | target/arm/kvm_arm.h | 2 - |
54 | target/arm/cpu.c | 2 + | 68 | target/arm/translate.h | 2 + |
55 | target/arm/helper-a64.c | 10 ++ | 69 | accel/hvf/hvf-accel-ops.c | 21 +- |
56 | target/arm/helper.c | 38 +++- | 70 | contrib/elf2dmp/download.c | 22 +- |
57 | target/arm/translate-a64.c | 421 ++++++++++++++++++++++++++++++++++++++------- | 71 | contrib/elf2dmp/pdb.c | 4 + |
58 | util/log.c | 2 + | 72 | hw/intc/arm_gicv3_cpuif.c | 5 +- |
59 | 11 files changed, 428 insertions(+), 71 deletions(-) | 73 | target/arm/cpu.c | 56 +- |
74 | target/arm/helper.c | 77 ++- | ||
75 | target/arm/hvf/hvf.c | 1278 +++++++++++++++++++++++++++++++++++++++++ | ||
76 | target/arm/machine.c | 13 + | ||
77 | target/arm/translate-m-nocp.c | 8 +- | ||
78 | target/arm/translate-mve.c | 310 +++++++--- | ||
79 | target/arm/translate-vfp.c | 33 +- | ||
80 | target/arm/translate.c | 42 +- | ||
81 | target/i386/hvf/hvf.c | 10 + | ||
82 | MAINTAINERS | 5 + | ||
83 | target/arm/hvf/meson.build | 3 + | ||
84 | target/arm/hvf/trace-events | 11 + | ||
85 | target/arm/meson.build | 2 + | ||
86 | 24 files changed, 1824 insertions(+), 168 deletions(-) | ||
87 | create mode 100644 target/arm/hvf_arm.h | ||
88 | create mode 100644 target/arm/hvf/hvf.c | ||
89 | create mode 100644 target/arm/hvf/meson.build | ||
90 | create mode 100644 target/arm/hvf/trace-events | ||
60 | 91 | diff view generated by jsdifflib |
1 | From: Alex Bennée <alex.bennee@linaro.org> | 1 | Coverity points out that we aren't checking the return value |
---|---|---|---|
2 | from curl_easy_setopt(). | ||
2 | 3 | ||
3 | These were missed out from the rest of the half-precision work. | 4 | Fixes: Coverity CID 1458895 |
4 | 5 | Inspired-by: Peter Maydell <peter.maydell@linaro.org> | |
5 | Cc: qemu-stable@nongnu.org | 6 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> |
7 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | 8 | Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> |
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 9 | Message-id: 20210910170656.366592-2-philmd@redhat.com |
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20180512003217.9105-10-richard.henderson@linaro.org | ||
11 | [rth: Fix erroneous check vs type] | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 11 | --- |
15 | target/arm/translate-a64.c | 31 +++++++++++++++++++++++++------ | 12 | contrib/elf2dmp/download.c | 22 ++++++++++------------ |
16 | 1 file changed, 25 insertions(+), 6 deletions(-) | 13 | 1 file changed, 10 insertions(+), 12 deletions(-) |
17 | 14 | ||
18 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 15 | diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c |
19 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/translate-a64.c | 17 | --- a/contrib/elf2dmp/download.c |
21 | +++ b/target/arm/translate-a64.c | 18 | +++ b/contrib/elf2dmp/download.c |
22 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) | 19 | @@ -XXX,XX +XXX,XX @@ int download_url(const char *name, const char *url) |
23 | unsigned int mos, type, rm, cond, rn, rd; | 20 | goto out_curl; |
24 | TCGv_i64 t_true, t_false, t_zero; | ||
25 | DisasCompare64 c; | ||
26 | + TCGMemOp sz; | ||
27 | |||
28 | mos = extract32(insn, 29, 3); | ||
29 | - type = extract32(insn, 22, 2); /* 0 = single, 1 = double */ | ||
30 | + type = extract32(insn, 22, 2); | ||
31 | rm = extract32(insn, 16, 5); | ||
32 | cond = extract32(insn, 12, 4); | ||
33 | rn = extract32(insn, 5, 5); | ||
34 | rd = extract32(insn, 0, 5); | ||
35 | |||
36 | - if (mos || type > 1) { | ||
37 | + if (mos) { | ||
38 | + unallocated_encoding(s); | ||
39 | + return; | ||
40 | + } | ||
41 | + | ||
42 | + switch (type) { | ||
43 | + case 0: | ||
44 | + sz = MO_32; | ||
45 | + break; | ||
46 | + case 1: | ||
47 | + sz = MO_64; | ||
48 | + break; | ||
49 | + case 3: | ||
50 | + sz = MO_16; | ||
51 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
52 | + break; | ||
53 | + } | ||
54 | + /* fallthru */ | ||
55 | + default: | ||
56 | unallocated_encoding(s); | ||
57 | return; | ||
58 | } | 21 | } |
59 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) | 22 | |
60 | return; | 23 | - curl_easy_setopt(curl, CURLOPT_URL, url); |
24 | - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL); | ||
25 | - curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); | ||
26 | - curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1); | ||
27 | - curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); | ||
28 | - | ||
29 | - if (curl_easy_perform(curl) != CURLE_OK) { | ||
30 | - err = 1; | ||
31 | - fclose(file); | ||
32 | + if (curl_easy_setopt(curl, CURLOPT_URL, url) != CURLE_OK | ||
33 | + || curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL) != CURLE_OK | ||
34 | + || curl_easy_setopt(curl, CURLOPT_WRITEDATA, file) != CURLE_OK | ||
35 | + || curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1) != CURLE_OK | ||
36 | + || curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0) != CURLE_OK | ||
37 | + || curl_easy_perform(curl) != CURLE_OK) { | ||
38 | unlink(name); | ||
39 | - goto out_curl; | ||
40 | + fclose(file); | ||
41 | + err = 1; | ||
42 | + } else { | ||
43 | + err = fclose(file); | ||
61 | } | 44 | } |
62 | 45 | ||
63 | - /* Zero extend sreg inputs to 64 bits now. */ | 46 | - err = fclose(file); |
64 | + /* Zero extend sreg & hreg inputs to 64 bits now. */ | 47 | - |
65 | t_true = tcg_temp_new_i64(); | 48 | out_curl: |
66 | t_false = tcg_temp_new_i64(); | 49 | curl_easy_cleanup(curl); |
67 | - read_vec_element(s, t_true, rn, 0, type ? MO_64 : MO_32); | 50 | |
68 | - read_vec_element(s, t_false, rm, 0, type ? MO_64 : MO_32); | ||
69 | + read_vec_element(s, t_true, rn, 0, sz); | ||
70 | + read_vec_element(s, t_false, rm, 0, sz); | ||
71 | |||
72 | a64_test_cc(&c, cond); | ||
73 | t_zero = tcg_const_i64(0); | ||
74 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) | ||
75 | tcg_temp_free_i64(t_false); | ||
76 | a64_free_cc(&c); | ||
77 | |||
78 | - /* Note that sregs write back zeros to the high bits, | ||
79 | + /* Note that sregs & hregs write back zeros to the high bits, | ||
80 | and we've already done the zero-extension. */ | ||
81 | write_fp_dreg(s, rd, t_true); | ||
82 | tcg_temp_free_i64(t_true); | ||
83 | -- | 51 | -- |
84 | 2.17.0 | 52 | 2.20.1 |
85 | 53 | ||
86 | 54 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Coverity points out that if the PDB file we're trying to read | ||
2 | has a header specifying a block_size of zero then we will | ||
3 | end up trying to divide by zero in pdb_ds_read_file(). | ||
4 | Check for this and fail cleanly instead. | ||
1 | 5 | ||
6 | Fixes: Coverity CID 1458869 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Reviewed-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> | ||
9 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Tested-by: Viktor Prutyanov <viktor.prutyanov@phystech.edu> | ||
11 | Message-id: 20210910170656.366592-3-philmd@redhat.com | ||
12 | Message-Id: <20210901143910.17112-3-peter.maydell@linaro.org> | ||
13 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | --- | ||
15 | contrib/elf2dmp/pdb.c | 4 ++++ | ||
16 | 1 file changed, 4 insertions(+) | ||
17 | |||
18 | diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/contrib/elf2dmp/pdb.c | ||
21 | +++ b/contrib/elf2dmp/pdb.c | ||
22 | @@ -XXX,XX +XXX,XX @@ out_symbols: | ||
23 | |||
24 | static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) | ||
25 | { | ||
26 | + if (hdr->block_size == 0) { | ||
27 | + return 1; | ||
28 | + } | ||
29 | + | ||
30 | memset(r->file_used, 0, sizeof(r->file_used)); | ||
31 | r->ds.header = hdr; | ||
32 | r->ds.toc = pdb_ds_read(hdr, (uint32_t *)((uint8_t *)hdr + | ||
33 | -- | ||
34 | 2.20.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently all of the M-profile specific code in arm_cpu_reset() is | ||
2 | inside a !defined(CONFIG_USER_ONLY) ifdef block. This is | ||
3 | unintentional: it happened because originally the only | ||
4 | M-profile-specific handling was the setup of the initial SP and PC | ||
5 | from the vector table, which is system-emulation only. But then we | ||
6 | added a lot of other M-profile setup to the same "if (ARM_FEATURE_M)" | ||
7 | code block without noticing that it was all inside a not-user-mode | ||
8 | ifdef. This has generally been harmless, but with the addition of | ||
9 | v8.1M low-overhead-loop support we ran into a problem: the reset of | ||
10 | FPSCR.LTPSIZE to 4 was only being done for system emulation mode, so | ||
11 | if a user-mode guest tried to execute the LE instruction it would | ||
12 | incorrectly take a UsageFault. | ||
1 | 13 | ||
14 | Adjust the ifdefs so only the really system-emulation specific parts | ||
15 | are covered. Because this means we now run some reset code that sets | ||
16 | up initial values in the FPCCR and similar FPU related registers, | ||
17 | explicitly set up the registers controlling FPU context handling in | ||
18 | user-emulation mode so that the FPU works by design and not by | ||
19 | chance. | ||
20 | |||
21 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/613 | ||
22 | Cc: qemu-stable@nongnu.org | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
25 | Message-id: 20210914120725.24992-2-peter.maydell@linaro.org | ||
26 | --- | ||
27 | target/arm/cpu.c | 19 +++++++++++++++++++ | ||
28 | 1 file changed, 19 insertions(+) | ||
29 | |||
30 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/cpu.c | ||
33 | +++ b/target/arm/cpu.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) | ||
35 | env->uncached_cpsr = ARM_CPU_MODE_SVC; | ||
36 | } | ||
37 | env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F; | ||
38 | +#endif | ||
39 | |||
40 | if (arm_feature(env, ARM_FEATURE_M)) { | ||
41 | +#ifndef CONFIG_USER_ONLY | ||
42 | uint32_t initial_msp; /* Loaded from 0x0 */ | ||
43 | uint32_t initial_pc; /* Loaded from 0x4 */ | ||
44 | uint8_t *rom; | ||
45 | uint32_t vecbase; | ||
46 | +#endif | ||
47 | |||
48 | if (cpu_isar_feature(aa32_lob, cpu)) { | ||
49 | /* | ||
50 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) | ||
51 | env->v7m.fpccr[M_REG_S] = R_V7M_FPCCR_ASPEN_MASK | | ||
52 | R_V7M_FPCCR_LSPEN_MASK | R_V7M_FPCCR_S_MASK; | ||
53 | } | ||
54 | + | ||
55 | +#ifndef CONFIG_USER_ONLY | ||
56 | /* Unlike A/R profile, M profile defines the reset LR value */ | ||
57 | env->regs[14] = 0xffffffff; | ||
58 | |||
59 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) | ||
60 | env->regs[13] = initial_msp & 0xFFFFFFFC; | ||
61 | env->regs[15] = initial_pc & ~1; | ||
62 | env->thumb = initial_pc & 1; | ||
63 | +#else | ||
64 | + /* | ||
65 | + * For user mode we run non-secure and with access to the FPU. | ||
66 | + * The FPU context is active (ie does not need further setup) | ||
67 | + * and is owned by non-secure. | ||
68 | + */ | ||
69 | + env->v7m.secure = false; | ||
70 | + env->v7m.nsacr = 0xcff; | ||
71 | + env->v7m.cpacr[M_REG_NS] = 0xf0ffff; | ||
72 | + env->v7m.fpccr[M_REG_S] &= | ||
73 | + ~(R_V7M_FPCCR_LSPEN_MASK | R_V7M_FPCCR_S_MASK); | ||
74 | + env->v7m.control[M_REG_S] |= R_V7M_CONTROL_FPCA_MASK; | ||
75 | +#endif | ||
76 | } | ||
77 | |||
78 | +#ifndef CONFIG_USER_ONLY | ||
79 | /* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently | ||
80 | * executing as AArch32 then check if highvecs are enabled and | ||
81 | * adjust the PC accordingly. | ||
82 | -- | ||
83 | 2.20.1 | ||
84 | |||
85 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | There's no particular reason why the exclusive monitor should | ||
2 | be only cleared on reset in system emulation mode. It doesn't | ||
3 | hurt if it isn't cleared in user mode, but we might as well | ||
4 | reduce the amount of code we have that's inside an ifdef. | ||
1 | 5 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20210914120725.24992-3-peter.maydell@linaro.org | ||
9 | --- | ||
10 | target/arm/cpu.c | 6 +++--- | ||
11 | 1 file changed, 3 insertions(+), 3 deletions(-) | ||
12 | |||
13 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/cpu.c | ||
16 | +++ b/target/arm/cpu.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) | ||
18 | env->regs[15] = 0xFFFF0000; | ||
19 | } | ||
20 | |||
21 | + env->vfp.xregs[ARM_VFP_FPEXC] = 0; | ||
22 | +#endif | ||
23 | + | ||
24 | /* M profile requires that reset clears the exclusive monitor; | ||
25 | * A profile does not, but clearing it makes more sense than having it | ||
26 | * set with an exclusive access on address zero. | ||
27 | */ | ||
28 | arm_clear_exclusive(env); | ||
29 | |||
30 | - env->vfp.xregs[ARM_VFP_FPEXC] = 0; | ||
31 | -#endif | ||
32 | - | ||
33 | if (arm_feature(env, ARM_FEATURE_PMSA)) { | ||
34 | if (cpu->pmsav7_dregion > 0) { | ||
35 | if (arm_feature(env, ARM_FEATURE_V8)) { | ||
36 | -- | ||
37 | 2.20.1 | ||
38 | |||
39 | diff view generated by jsdifflib |
1 | In commit d81ce0ef2c4f105 we added an extra float_status field | 1 | Move an ifndef CONFIG_USER_ONLY code block up in arm_cpu_reset() so |
---|---|---|---|
2 | fp_status_fp16 for Arm, but forgot to initialize it correctly | 2 | it can be merged with another earlier one. |
3 | by setting it to float_tininess_before_rounding. This currently | ||
4 | will only cause problems for the new V8_FP16 feature, since the | ||
5 | float-to-float conversion code doesn't use it yet. The effect | ||
6 | would be that we failed to set the Underflow IEEE exception flag | ||
7 | in all the cases where we should. | ||
8 | 3 | ||
9 | Add the missing initialization. | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | |||
11 | Fixes: d81ce0ef2c4f105 | ||
12 | Cc: qemu-stable@nongnu.org | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
14 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | Message-id: 20210914120725.24992-4-peter.maydell@linaro.org |
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | Message-id: 20180512004311.9299-16-richard.henderson@linaro.org | ||
17 | --- | 7 | --- |
18 | target/arm/cpu.c | 2 ++ | 8 | target/arm/cpu.c | 22 ++++++++++------------ |
19 | 1 file changed, 2 insertions(+) | 9 | 1 file changed, 10 insertions(+), 12 deletions(-) |
20 | 10 | ||
21 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 11 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/arm/cpu.c | 13 | --- a/target/arm/cpu.c |
24 | +++ b/target/arm/cpu.c | 14 | +++ b/target/arm/cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) | 15 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
26 | &env->vfp.fp_status); | 16 | env->uncached_cpsr = ARM_CPU_MODE_SVC; |
27 | set_float_detect_tininess(float_tininess_before_rounding, | 17 | } |
28 | &env->vfp.standard_fp_status); | 18 | env->daif = PSTATE_D | PSTATE_A | PSTATE_I | PSTATE_F; |
29 | + set_float_detect_tininess(float_tininess_before_rounding, | 19 | + |
30 | + &env->vfp.fp_status_f16); | 20 | + /* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently |
31 | #ifndef CONFIG_USER_ONLY | 21 | + * executing as AArch32 then check if highvecs are enabled and |
32 | if (kvm_enabled()) { | 22 | + * adjust the PC accordingly. |
33 | kvm_arm_reset_vcpu(cpu); | 23 | + */ |
24 | + if (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_V) { | ||
25 | + env->regs[15] = 0xFFFF0000; | ||
26 | + } | ||
27 | + | ||
28 | + env->vfp.xregs[ARM_VFP_FPEXC] = 0; | ||
29 | #endif | ||
30 | |||
31 | if (arm_feature(env, ARM_FEATURE_M)) { | ||
32 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) | ||
33 | #endif | ||
34 | } | ||
35 | |||
36 | -#ifndef CONFIG_USER_ONLY | ||
37 | - /* AArch32 has a hard highvec setting of 0xFFFF0000. If we are currently | ||
38 | - * executing as AArch32 then check if highvecs are enabled and | ||
39 | - * adjust the PC accordingly. | ||
40 | - */ | ||
41 | - if (A32_BANKED_CURRENT_REG_GET(env, sctlr) & SCTLR_V) { | ||
42 | - env->regs[15] = 0xFFFF0000; | ||
43 | - } | ||
44 | - | ||
45 | - env->vfp.xregs[ARM_VFP_FPEXC] = 0; | ||
46 | -#endif | ||
47 | - | ||
48 | /* M profile requires that reset clears the exclusive monitor; | ||
49 | * A profile does not, but clearing it makes more sense than having it | ||
50 | * set with an exclusive access on address zero. | ||
34 | -- | 51 | -- |
35 | 2.17.0 | 52 | 2.20.1 |
36 | 53 | ||
37 | 54 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Adding the fp16 moves to/from general registers. | 3 | During sbsa acs level 3 testing, it is seen that the GIC maintenance |
4 | interrupts are not triggered and the related test cases fail. This | ||
5 | is because we were incorrectly passing the value of the MISR register | ||
6 | (from maintenance_interrupt_state()) to qemu_set_irq() as the level | ||
7 | argument, whereas the device on the other end of this irq line | ||
8 | expects a 0/1 value. | ||
4 | 9 | ||
5 | Cc: qemu-stable@nongnu.org | 10 | Fix the logic to pass a 0/1 level indication, rather than a |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 11 | 0/not-0 value. |
7 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 12 | |
8 | Message-id: 20180512003217.9105-2-richard.henderson@linaro.org | 13 | Fixes: c5fc89b36c0 ("hw/intc/arm_gicv3: Implement gicv3_cpuif_virt_update()") |
14 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> | ||
15 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
16 | Message-id: 20210915205809.59068-1-shashi.mallela@linaro.org | ||
17 | [PMM: tweaked commit message; collapsed nested if()s into one] | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 20 | --- |
12 | target/arm/translate-a64.c | 21 +++++++++++++++++++++ | 21 | hw/intc/arm_gicv3_cpuif.c | 5 +++-- |
13 | 1 file changed, 21 insertions(+) | 22 | 1 file changed, 3 insertions(+), 2 deletions(-) |
14 | 23 | ||
15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 24 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c |
16 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate-a64.c | 26 | --- a/hw/intc/arm_gicv3_cpuif.c |
18 | +++ b/target/arm/translate-a64.c | 27 | +++ b/hw/intc/arm_gicv3_cpuif.c |
19 | @@ -XXX,XX +XXX,XX @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof) | 28 | @@ -XXX,XX +XXX,XX @@ static void gicv3_cpuif_virt_update(GICv3CPUState *cs) |
20 | tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(s, rd)); | ||
21 | clear_vec_high(s, true, rd); | ||
22 | break; | ||
23 | + case 3: | ||
24 | + /* 16 bit */ | ||
25 | + tmp = tcg_temp_new_i64(); | ||
26 | + tcg_gen_ext16u_i64(tmp, tcg_rn); | ||
27 | + write_fp_dreg(s, rd, tmp); | ||
28 | + tcg_temp_free_i64(tmp); | ||
29 | + break; | ||
30 | + default: | ||
31 | + g_assert_not_reached(); | ||
32 | } | ||
33 | } else { | ||
34 | TCGv_i64 tcg_rd = cpu_reg(s, rd); | ||
35 | @@ -XXX,XX +XXX,XX @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof) | ||
36 | /* 64 bits from top half */ | ||
37 | tcg_gen_ld_i64(tcg_rd, cpu_env, fp_reg_hi_offset(s, rn)); | ||
38 | break; | ||
39 | + case 3: | ||
40 | + /* 16 bit */ | ||
41 | + tcg_gen_ld16u_i64(tcg_rd, cpu_env, fp_reg_offset(s, rn, MO_16)); | ||
42 | + break; | ||
43 | + default: | ||
44 | + g_assert_not_reached(); | ||
45 | } | 29 | } |
46 | } | 30 | } |
47 | } | 31 | |
48 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) | 32 | - if (cs->ich_hcr_el2 & ICH_HCR_EL2_EN) { |
49 | case 0xa: /* 64 bit */ | 33 | - maintlevel = maintenance_interrupt_state(cs); |
50 | case 0xd: /* 64 bit to top half of quad */ | 34 | + if ((cs->ich_hcr_el2 & ICH_HCR_EL2_EN) && |
51 | break; | 35 | + maintenance_interrupt_state(cs) != 0) { |
52 | + case 0x6: /* 16-bit float, 32-bit int */ | 36 | + maintlevel = 1; |
53 | + case 0xe: /* 16-bit float, 64-bit int */ | 37 | } |
54 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 38 | |
55 | + break; | 39 | trace_gicv3_cpuif_virt_set_irqs(gicv3_redist_affid(cs), fiqlevel, |
56 | + } | ||
57 | + /* fallthru */ | ||
58 | default: | ||
59 | /* all other sf/type/rmode combinations are invalid */ | ||
60 | unallocated_encoding(s); | ||
61 | -- | 40 | -- |
62 | 2.17.0 | 41 | 2.20.1 |
63 | 42 | ||
64 | 43 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Alexander Graf <agraf@csgraf.de> |
---|---|---|---|
2 | 2 | ||
3 | No sense in emitting code after the exception. | 3 | We will need PMC register definitions in accel specific code later. |
4 | Move all constant definitions to common arm headers so we can reuse | ||
5 | them. | ||
4 | 6 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Alexander Graf <agraf@csgraf.de> |
6 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Message-id: 20180512003217.9105-3-richard.henderson@linaro.org | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Message-id: 20210916155404.86958-2-agraf@csgraf.de | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 11 | --- |
11 | target/arm/translate-a64.c | 2 +- | 12 | target/arm/internals.h | 44 ++++++++++++++++++++++++++++++++++++++++++ |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 13 | target/arm/helper.c | 44 ------------------------------------------ |
14 | 2 files changed, 44 insertions(+), 44 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 16 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/translate-a64.c | 18 | --- a/target/arm/internals.h |
17 | +++ b/target/arm/translate-a64.c | 19 | +++ b/target/arm/internals.h |
18 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) | 20 | @@ -XXX,XX +XXX,XX @@ enum MVEECIState { |
19 | default: | 21 | /* All other values reserved */ |
20 | /* all other sf/type/rmode combinations are invalid */ | 22 | }; |
21 | unallocated_encoding(s); | 23 | |
22 | - break; | 24 | +/* Definitions for the PMU registers */ |
23 | + return; | 25 | +#define PMCRN_MASK 0xf800 |
24 | } | 26 | +#define PMCRN_SHIFT 11 |
25 | 27 | +#define PMCRLC 0x40 | |
26 | if (!fp_access_check(s)) { | 28 | +#define PMCRDP 0x20 |
29 | +#define PMCRX 0x10 | ||
30 | +#define PMCRD 0x8 | ||
31 | +#define PMCRC 0x4 | ||
32 | +#define PMCRP 0x2 | ||
33 | +#define PMCRE 0x1 | ||
34 | +/* | ||
35 | + * Mask of PMCR bits writeable by guest (not including WO bits like C, P, | ||
36 | + * which can be written as 1 to trigger behaviour but which stay RAZ). | ||
37 | + */ | ||
38 | +#define PMCR_WRITEABLE_MASK (PMCRLC | PMCRDP | PMCRX | PMCRD | PMCRE) | ||
39 | + | ||
40 | +#define PMXEVTYPER_P 0x80000000 | ||
41 | +#define PMXEVTYPER_U 0x40000000 | ||
42 | +#define PMXEVTYPER_NSK 0x20000000 | ||
43 | +#define PMXEVTYPER_NSU 0x10000000 | ||
44 | +#define PMXEVTYPER_NSH 0x08000000 | ||
45 | +#define PMXEVTYPER_M 0x04000000 | ||
46 | +#define PMXEVTYPER_MT 0x02000000 | ||
47 | +#define PMXEVTYPER_EVTCOUNT 0x0000ffff | ||
48 | +#define PMXEVTYPER_MASK (PMXEVTYPER_P | PMXEVTYPER_U | PMXEVTYPER_NSK | \ | ||
49 | + PMXEVTYPER_NSU | PMXEVTYPER_NSH | \ | ||
50 | + PMXEVTYPER_M | PMXEVTYPER_MT | \ | ||
51 | + PMXEVTYPER_EVTCOUNT) | ||
52 | + | ||
53 | +#define PMCCFILTR 0xf8000000 | ||
54 | +#define PMCCFILTR_M PMXEVTYPER_M | ||
55 | +#define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M) | ||
56 | + | ||
57 | +static inline uint32_t pmu_num_counters(CPUARMState *env) | ||
58 | +{ | ||
59 | + return (env->cp15.c9_pmcr & PMCRN_MASK) >> PMCRN_SHIFT; | ||
60 | +} | ||
61 | + | ||
62 | +/* Bits allowed to be set/cleared for PMCNTEN* and PMINTEN* */ | ||
63 | +static inline uint64_t pmu_counter_mask(CPUARMState *env) | ||
64 | +{ | ||
65 | + return (1 << 31) | ((1 << pmu_num_counters(env)) - 1); | ||
66 | +} | ||
67 | + | ||
68 | #endif | ||
69 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/arm/helper.c | ||
72 | +++ b/target/arm/helper.c | ||
73 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = { | ||
74 | REGINFO_SENTINEL | ||
75 | }; | ||
76 | |||
77 | -/* Definitions for the PMU registers */ | ||
78 | -#define PMCRN_MASK 0xf800 | ||
79 | -#define PMCRN_SHIFT 11 | ||
80 | -#define PMCRLC 0x40 | ||
81 | -#define PMCRDP 0x20 | ||
82 | -#define PMCRX 0x10 | ||
83 | -#define PMCRD 0x8 | ||
84 | -#define PMCRC 0x4 | ||
85 | -#define PMCRP 0x2 | ||
86 | -#define PMCRE 0x1 | ||
87 | -/* | ||
88 | - * Mask of PMCR bits writeable by guest (not including WO bits like C, P, | ||
89 | - * which can be written as 1 to trigger behaviour but which stay RAZ). | ||
90 | - */ | ||
91 | -#define PMCR_WRITEABLE_MASK (PMCRLC | PMCRDP | PMCRX | PMCRD | PMCRE) | ||
92 | - | ||
93 | -#define PMXEVTYPER_P 0x80000000 | ||
94 | -#define PMXEVTYPER_U 0x40000000 | ||
95 | -#define PMXEVTYPER_NSK 0x20000000 | ||
96 | -#define PMXEVTYPER_NSU 0x10000000 | ||
97 | -#define PMXEVTYPER_NSH 0x08000000 | ||
98 | -#define PMXEVTYPER_M 0x04000000 | ||
99 | -#define PMXEVTYPER_MT 0x02000000 | ||
100 | -#define PMXEVTYPER_EVTCOUNT 0x0000ffff | ||
101 | -#define PMXEVTYPER_MASK (PMXEVTYPER_P | PMXEVTYPER_U | PMXEVTYPER_NSK | \ | ||
102 | - PMXEVTYPER_NSU | PMXEVTYPER_NSH | \ | ||
103 | - PMXEVTYPER_M | PMXEVTYPER_MT | \ | ||
104 | - PMXEVTYPER_EVTCOUNT) | ||
105 | - | ||
106 | -#define PMCCFILTR 0xf8000000 | ||
107 | -#define PMCCFILTR_M PMXEVTYPER_M | ||
108 | -#define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M) | ||
109 | - | ||
110 | -static inline uint32_t pmu_num_counters(CPUARMState *env) | ||
111 | -{ | ||
112 | - return (env->cp15.c9_pmcr & PMCRN_MASK) >> PMCRN_SHIFT; | ||
113 | -} | ||
114 | - | ||
115 | -/* Bits allowed to be set/cleared for PMCNTEN* and PMINTEN* */ | ||
116 | -static inline uint64_t pmu_counter_mask(CPUARMState *env) | ||
117 | -{ | ||
118 | - return (1 << 31) | ((1 << pmu_num_counters(env)) - 1); | ||
119 | -} | ||
120 | - | ||
121 | typedef struct pm_event { | ||
122 | uint16_t number; /* PMEVTYPER.evtCount is 16 bits wide */ | ||
123 | /* If the event is supported on this CPU (used to generate PMCEID[01]) */ | ||
27 | -- | 124 | -- |
28 | 2.17.0 | 125 | 2.20.1 |
29 | 126 | ||
30 | 127 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Alexander Graf <agraf@csgraf.de> |
---|---|---|---|
2 | 2 | ||
3 | Per the Physical Layer Simplified Spec. "4.3.10.4 Switch Function Status": | 3 | Hvf's permission bitmap during and after dirty logging does not include |
4 | the HV_MEMORY_EXEC permission. At least on Apple Silicon, this leads to | ||
5 | instruction faults once dirty logging was enabled. | ||
4 | 6 | ||
5 | The block length is predefined to 512 bits | 7 | Add the bit to make it work properly. |
6 | 8 | ||
7 | and "4.10.2 SD Status": | 9 | Signed-off-by: Alexander Graf <agraf@csgraf.de> |
8 | |||
9 | The SD Status contains status bits that are related to the SD Memory Card | ||
10 | proprietary features and may be used for future application-specific usage. | ||
11 | The size of the SD Status is one data block of 512 bit. The content of this | ||
12 | register is transmitted to the Host over the DAT bus along with a 16-bit CRC. | ||
13 | |||
14 | Thus the 16-bit CRC goes at offset 64. | ||
15 | |||
16 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Message-id: 20180509060104.4458-3-f4bug@amsat.org | ||
18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Message-id: 20210916155404.86958-3-agraf@csgraf.de | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 13 | --- |
21 | hw/sd/sd.c | 2 +- | 14 | accel/hvf/hvf-accel-ops.c | 4 ++-- |
22 | 1 file changed, 1 insertion(+), 1 deletion(-) | 15 | 1 file changed, 2 insertions(+), 2 deletions(-) |
23 | 16 | ||
24 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 17 | diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c |
25 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/sd/sd.c | 19 | --- a/accel/hvf/hvf-accel-ops.c |
27 | +++ b/hw/sd/sd.c | 20 | +++ b/accel/hvf/hvf-accel-ops.c |
28 | @@ -XXX,XX +XXX,XX @@ static void sd_function_switch(SDState *sd, uint32_t arg) | 21 | @@ -XXX,XX +XXX,XX @@ static void hvf_set_dirty_tracking(MemoryRegionSection *section, bool on) |
29 | sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4); | 22 | if (on) { |
23 | slot->flags |= HVF_SLOT_LOG; | ||
24 | hv_vm_protect((uintptr_t)slot->start, (size_t)slot->size, | ||
25 | - HV_MEMORY_READ); | ||
26 | + HV_MEMORY_READ | HV_MEMORY_EXEC); | ||
27 | /* stop tracking region*/ | ||
28 | } else { | ||
29 | slot->flags &= ~HVF_SLOT_LOG; | ||
30 | hv_vm_protect((uintptr_t)slot->start, (size_t)slot->size, | ||
31 | - HV_MEMORY_READ | HV_MEMORY_WRITE); | ||
32 | + HV_MEMORY_READ | HV_MEMORY_WRITE | HV_MEMORY_EXEC); | ||
30 | } | 33 | } |
31 | memset(&sd->data[17], 0, 47); | ||
32 | - stw_be_p(sd->data + 65, sd_crc16(sd->data, 64)); | ||
33 | + stw_be_p(sd->data + 64, sd_crc16(sd->data, 64)); | ||
34 | } | 34 | } |
35 | 35 | ||
36 | static inline bool sd_wp_addr(SDState *sd, uint64_t addr) | ||
37 | -- | 36 | -- |
38 | 2.17.0 | 37 | 2.20.1 |
39 | 38 | ||
40 | 39 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Alexander Graf <agraf@csgraf.de> |
---|---|---|---|
2 | 2 | ||
3 | We missed all of the scalar fp16 fma operations. | 3 | We will need to install a migration helper for the ARM hvf backend. |
4 | Let's introduce an arch callback for the overall hvf init chain to | ||
5 | do so. | ||
4 | 6 | ||
5 | Cc: qemu-stable@nongnu.org | 7 | Signed-off-by: Alexander Graf <agraf@csgraf.de> |
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Message-id: 20210916155404.86958-4-agraf@csgraf.de |
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Message-id: 20180512003217.9105-8-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 11 | --- |
12 | target/arm/translate-a64.c | 48 ++++++++++++++++++++++++++++++++++++++ | 12 | include/sysemu/hvf_int.h | 1 + |
13 | 1 file changed, 48 insertions(+) | 13 | accel/hvf/hvf-accel-ops.c | 3 ++- |
14 | target/i386/hvf/hvf.c | 5 +++++ | ||
15 | 3 files changed, 8 insertions(+), 1 deletion(-) | ||
14 | 16 | ||
15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 17 | diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate-a64.c | 19 | --- a/include/sysemu/hvf_int.h |
18 | +++ b/target/arm/translate-a64.c | 20 | +++ b/include/sysemu/hvf_int.h |
19 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1, | 21 | @@ -XXX,XX +XXX,XX @@ struct hvf_vcpu_state { |
20 | tcg_temp_free_i64(tcg_res); | 22 | }; |
23 | |||
24 | void assert_hvf_ok(hv_return_t ret); | ||
25 | +int hvf_arch_init(void); | ||
26 | int hvf_arch_init_vcpu(CPUState *cpu); | ||
27 | void hvf_arch_vcpu_destroy(CPUState *cpu); | ||
28 | int hvf_vcpu_exec(CPUState *); | ||
29 | diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/accel/hvf/hvf-accel-ops.c | ||
32 | +++ b/accel/hvf/hvf-accel-ops.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static int hvf_accel_init(MachineState *ms) | ||
34 | |||
35 | hvf_state = s; | ||
36 | memory_listener_register(&hvf_memory_listener, &address_space_memory); | ||
37 | - return 0; | ||
38 | + | ||
39 | + return hvf_arch_init(); | ||
21 | } | 40 | } |
22 | 41 | ||
23 | +/* Floating-point data-processing (3 source) - half precision */ | 42 | static void hvf_accel_class_init(ObjectClass *oc, void *data) |
24 | +static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1, | 43 | diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c |
25 | + int rd, int rn, int rm, int ra) | 44 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/target/i386/hvf/hvf.c | ||
46 | +++ b/target/i386/hvf/hvf.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static inline bool apic_bus_freq_is_known(CPUX86State *env) | ||
48 | return env->apic_bus_freq != 0; | ||
49 | } | ||
50 | |||
51 | +int hvf_arch_init(void) | ||
26 | +{ | 52 | +{ |
27 | + TCGv_i32 tcg_op1, tcg_op2, tcg_op3; | 53 | + return 0; |
28 | + TCGv_i32 tcg_res = tcg_temp_new_i32(); | ||
29 | + TCGv_ptr fpst = get_fpstatus_ptr(true); | ||
30 | + | ||
31 | + tcg_op1 = read_fp_hreg(s, rn); | ||
32 | + tcg_op2 = read_fp_hreg(s, rm); | ||
33 | + tcg_op3 = read_fp_hreg(s, ra); | ||
34 | + | ||
35 | + /* These are fused multiply-add, and must be done as one | ||
36 | + * floating point operation with no rounding between the | ||
37 | + * multiplication and addition steps. | ||
38 | + * NB that doing the negations here as separate steps is | ||
39 | + * correct : an input NaN should come out with its sign bit | ||
40 | + * flipped if it is a negated-input. | ||
41 | + */ | ||
42 | + if (o1 == true) { | ||
43 | + tcg_gen_xori_i32(tcg_op3, tcg_op3, 0x8000); | ||
44 | + } | ||
45 | + | ||
46 | + if (o0 != o1) { | ||
47 | + tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000); | ||
48 | + } | ||
49 | + | ||
50 | + gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst); | ||
51 | + | ||
52 | + write_fp_sreg(s, rd, tcg_res); | ||
53 | + | ||
54 | + tcg_temp_free_ptr(fpst); | ||
55 | + tcg_temp_free_i32(tcg_op1); | ||
56 | + tcg_temp_free_i32(tcg_op2); | ||
57 | + tcg_temp_free_i32(tcg_op3); | ||
58 | + tcg_temp_free_i32(tcg_res); | ||
59 | +} | 54 | +} |
60 | + | 55 | + |
61 | /* Floating point data-processing (3 source) | 56 | int hvf_arch_init_vcpu(CPUState *cpu) |
62 | * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0 | 57 | { |
63 | * +---+---+---+-----------+------+----+------+----+------+------+------+ | 58 | X86CPU *x86cpu = X86_CPU(cpu); |
64 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_3src(DisasContext *s, uint32_t insn) | ||
65 | } | ||
66 | handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra); | ||
67 | break; | ||
68 | + case 3: | ||
69 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
70 | + unallocated_encoding(s); | ||
71 | + return; | ||
72 | + } | ||
73 | + if (!fp_access_check(s)) { | ||
74 | + return; | ||
75 | + } | ||
76 | + handle_fp_3src_half(s, o0, o1, rd, rn, rm, ra); | ||
77 | + break; | ||
78 | default: | ||
79 | unallocated_encoding(s); | ||
80 | } | ||
81 | -- | 59 | -- |
82 | 2.17.0 | 60 | 2.20.1 |
83 | 61 | ||
84 | 62 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Alexander Graf <agraf@csgraf.de> |
---|---|---|---|
2 | 2 | ||
3 | Cc: qemu-stable@nongnu.org | 3 | With Apple Silicon available to the masses, it's a good time to add support |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | for driving its virtualization extensions from QEMU. |
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | |
6 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 6 | This patch adds all necessary architecture specific code to get basic VMs |
7 | Message-id: 20180512003217.9105-5-richard.henderson@linaro.org | 7 | working, including save/restore. |
8 | |||
9 | Known limitations: | ||
10 | |||
11 | - WFI handling is missing (follows in later patch) | ||
12 | - No watchpoint/breakpoint support | ||
13 | |||
14 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | ||
15 | Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com> | ||
16 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Message-id: 20210916155404.86958-5-agraf@csgraf.de | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 20 | --- |
10 | target/arm/translate-a64.c | 17 +++++++++++++++-- | 21 | meson.build | 1 + |
11 | 1 file changed, 15 insertions(+), 2 deletions(-) | 22 | include/sysemu/hvf_int.h | 10 +- |
23 | accel/hvf/hvf-accel-ops.c | 9 + | ||
24 | target/arm/hvf/hvf.c | 794 ++++++++++++++++++++++++++++++++++++ | ||
25 | target/i386/hvf/hvf.c | 5 + | ||
26 | MAINTAINERS | 5 + | ||
27 | target/arm/hvf/trace-events | 10 + | ||
28 | 7 files changed, 833 insertions(+), 1 deletion(-) | ||
29 | create mode 100644 target/arm/hvf/hvf.c | ||
30 | create mode 100644 target/arm/hvf/trace-events | ||
12 | 31 | ||
13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 32 | diff --git a/meson.build b/meson.build |
14 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate-a64.c | 34 | --- a/meson.build |
16 | +++ b/target/arm/translate-a64.c | 35 | +++ b/meson.build |
17 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn) | 36 | @@ -XXX,XX +XXX,XX @@ if have_system or have_user |
18 | bool sf = extract32(insn, 31, 1); | 37 | 'accel/tcg', |
19 | bool itof; | 38 | 'hw/core', |
20 | 39 | 'target/arm', | |
21 | - if (sbit || (type > 1) | 40 | + 'target/arm/hvf', |
22 | - || (!sf && scale < 32)) { | 41 | 'target/hppa', |
23 | + if (sbit || (!sf && scale < 32)) { | 42 | 'target/i386', |
24 | + unallocated_encoding(s); | 43 | 'target/i386/kvm', |
44 | diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/include/sysemu/hvf_int.h | ||
47 | +++ b/include/sysemu/hvf_int.h | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | #ifndef HVF_INT_H | ||
50 | #define HVF_INT_H | ||
51 | |||
52 | +#ifdef __aarch64__ | ||
53 | +#include <Hypervisor/Hypervisor.h> | ||
54 | +#else | ||
55 | #include <Hypervisor/hv.h> | ||
56 | +#endif | ||
57 | |||
58 | /* hvf_slot flags */ | ||
59 | #define HVF_SLOT_LOG (1 << 0) | ||
60 | @@ -XXX,XX +XXX,XX @@ struct HVFState { | ||
61 | int num_slots; | ||
62 | |||
63 | hvf_vcpu_caps *hvf_caps; | ||
64 | + uint64_t vtimer_offset; | ||
65 | }; | ||
66 | extern HVFState *hvf_state; | ||
67 | |||
68 | struct hvf_vcpu_state { | ||
69 | - int fd; | ||
70 | + uint64_t fd; | ||
71 | + void *exit; | ||
72 | + bool vtimer_masked; | ||
73 | }; | ||
74 | |||
75 | void assert_hvf_ok(hv_return_t ret); | ||
76 | @@ -XXX,XX +XXX,XX @@ int hvf_vcpu_exec(CPUState *); | ||
77 | hvf_slot *hvf_find_overlap_slot(uint64_t, uint64_t); | ||
78 | int hvf_put_registers(CPUState *); | ||
79 | int hvf_get_registers(CPUState *); | ||
80 | +void hvf_kick_vcpu_thread(CPUState *cpu); | ||
81 | |||
82 | #endif | ||
83 | diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/accel/hvf/hvf-accel-ops.c | ||
86 | +++ b/accel/hvf/hvf-accel-ops.c | ||
87 | @@ -XXX,XX +XXX,XX @@ | ||
88 | |||
89 | HVFState *hvf_state; | ||
90 | |||
91 | +#ifdef __aarch64__ | ||
92 | +#define HV_VM_DEFAULT NULL | ||
93 | +#endif | ||
94 | + | ||
95 | /* Memory slots */ | ||
96 | |||
97 | hvf_slot *hvf_find_overlap_slot(uint64_t start, uint64_t size) | ||
98 | @@ -XXX,XX +XXX,XX @@ static int hvf_init_vcpu(CPUState *cpu) | ||
99 | pthread_sigmask(SIG_BLOCK, NULL, &set); | ||
100 | sigdelset(&set, SIG_IPI); | ||
101 | |||
102 | +#ifdef __aarch64__ | ||
103 | + r = hv_vcpu_create(&cpu->hvf->fd, (hv_vcpu_exit_t **)&cpu->hvf->exit, NULL); | ||
104 | +#else | ||
105 | r = hv_vcpu_create((hv_vcpuid_t *)&cpu->hvf->fd, HV_VCPU_DEFAULT); | ||
106 | +#endif | ||
107 | cpu->vcpu_dirty = 1; | ||
108 | assert_hvf_ok(r); | ||
109 | |||
110 | @@ -XXX,XX +XXX,XX @@ static void hvf_accel_ops_class_init(ObjectClass *oc, void *data) | ||
111 | AccelOpsClass *ops = ACCEL_OPS_CLASS(oc); | ||
112 | |||
113 | ops->create_vcpu_thread = hvf_start_vcpu_thread; | ||
114 | + ops->kick_vcpu_thread = hvf_kick_vcpu_thread; | ||
115 | |||
116 | ops->synchronize_post_reset = hvf_cpu_synchronize_post_reset; | ||
117 | ops->synchronize_post_init = hvf_cpu_synchronize_post_init; | ||
118 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | ||
119 | new file mode 100644 | ||
120 | index XXXXXXX..XXXXXXX | ||
121 | --- /dev/null | ||
122 | +++ b/target/arm/hvf/hvf.c | ||
123 | @@ -XXX,XX +XXX,XX @@ | ||
124 | +/* | ||
125 | + * QEMU Hypervisor.framework support for Apple Silicon | ||
126 | + | ||
127 | + * Copyright 2020 Alexander Graf <agraf@csgraf.de> | ||
128 | + * | ||
129 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
130 | + * See the COPYING file in the top-level directory. | ||
131 | + * | ||
132 | + */ | ||
133 | + | ||
134 | +#include "qemu/osdep.h" | ||
135 | +#include "qemu-common.h" | ||
136 | +#include "qemu/error-report.h" | ||
137 | + | ||
138 | +#include "sysemu/runstate.h" | ||
139 | +#include "sysemu/hvf.h" | ||
140 | +#include "sysemu/hvf_int.h" | ||
141 | +#include "sysemu/hw_accel.h" | ||
142 | + | ||
143 | +#include <mach/mach_time.h> | ||
144 | + | ||
145 | +#include "exec/address-spaces.h" | ||
146 | +#include "hw/irq.h" | ||
147 | +#include "qemu/main-loop.h" | ||
148 | +#include "sysemu/cpus.h" | ||
149 | +#include "target/arm/cpu.h" | ||
150 | +#include "target/arm/internals.h" | ||
151 | +#include "trace/trace-target_arm_hvf.h" | ||
152 | +#include "migration/vmstate.h" | ||
153 | + | ||
154 | +#define HVF_SYSREG(crn, crm, op0, op1, op2) \ | ||
155 | + ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP, crn, crm, op0, op1, op2) | ||
156 | +#define PL1_WRITE_MASK 0x4 | ||
157 | + | ||
158 | +#define SYSREG(op0, op1, crn, crm, op2) \ | ||
159 | + ((op0 << 20) | (op2 << 17) | (op1 << 14) | (crn << 10) | (crm << 1)) | ||
160 | +#define SYSREG_MASK SYSREG(0x3, 0x7, 0xf, 0xf, 0x7) | ||
161 | +#define SYSREG_OSLAR_EL1 SYSREG(2, 0, 1, 0, 4) | ||
162 | +#define SYSREG_OSLSR_EL1 SYSREG(2, 0, 1, 1, 4) | ||
163 | +#define SYSREG_OSDLR_EL1 SYSREG(2, 0, 1, 3, 4) | ||
164 | +#define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 14, 0, 1) | ||
165 | + | ||
166 | +#define WFX_IS_WFE (1 << 0) | ||
167 | + | ||
168 | +#define TMR_CTL_ENABLE (1 << 0) | ||
169 | +#define TMR_CTL_IMASK (1 << 1) | ||
170 | +#define TMR_CTL_ISTATUS (1 << 2) | ||
171 | + | ||
172 | +typedef struct HVFVTimer { | ||
173 | + /* Vtimer value during migration and paused state */ | ||
174 | + uint64_t vtimer_val; | ||
175 | +} HVFVTimer; | ||
176 | + | ||
177 | +static HVFVTimer vtimer; | ||
178 | + | ||
179 | +struct hvf_reg_match { | ||
180 | + int reg; | ||
181 | + uint64_t offset; | ||
182 | +}; | ||
183 | + | ||
184 | +static const struct hvf_reg_match hvf_reg_match[] = { | ||
185 | + { HV_REG_X0, offsetof(CPUARMState, xregs[0]) }, | ||
186 | + { HV_REG_X1, offsetof(CPUARMState, xregs[1]) }, | ||
187 | + { HV_REG_X2, offsetof(CPUARMState, xregs[2]) }, | ||
188 | + { HV_REG_X3, offsetof(CPUARMState, xregs[3]) }, | ||
189 | + { HV_REG_X4, offsetof(CPUARMState, xregs[4]) }, | ||
190 | + { HV_REG_X5, offsetof(CPUARMState, xregs[5]) }, | ||
191 | + { HV_REG_X6, offsetof(CPUARMState, xregs[6]) }, | ||
192 | + { HV_REG_X7, offsetof(CPUARMState, xregs[7]) }, | ||
193 | + { HV_REG_X8, offsetof(CPUARMState, xregs[8]) }, | ||
194 | + { HV_REG_X9, offsetof(CPUARMState, xregs[9]) }, | ||
195 | + { HV_REG_X10, offsetof(CPUARMState, xregs[10]) }, | ||
196 | + { HV_REG_X11, offsetof(CPUARMState, xregs[11]) }, | ||
197 | + { HV_REG_X12, offsetof(CPUARMState, xregs[12]) }, | ||
198 | + { HV_REG_X13, offsetof(CPUARMState, xregs[13]) }, | ||
199 | + { HV_REG_X14, offsetof(CPUARMState, xregs[14]) }, | ||
200 | + { HV_REG_X15, offsetof(CPUARMState, xregs[15]) }, | ||
201 | + { HV_REG_X16, offsetof(CPUARMState, xregs[16]) }, | ||
202 | + { HV_REG_X17, offsetof(CPUARMState, xregs[17]) }, | ||
203 | + { HV_REG_X18, offsetof(CPUARMState, xregs[18]) }, | ||
204 | + { HV_REG_X19, offsetof(CPUARMState, xregs[19]) }, | ||
205 | + { HV_REG_X20, offsetof(CPUARMState, xregs[20]) }, | ||
206 | + { HV_REG_X21, offsetof(CPUARMState, xregs[21]) }, | ||
207 | + { HV_REG_X22, offsetof(CPUARMState, xregs[22]) }, | ||
208 | + { HV_REG_X23, offsetof(CPUARMState, xregs[23]) }, | ||
209 | + { HV_REG_X24, offsetof(CPUARMState, xregs[24]) }, | ||
210 | + { HV_REG_X25, offsetof(CPUARMState, xregs[25]) }, | ||
211 | + { HV_REG_X26, offsetof(CPUARMState, xregs[26]) }, | ||
212 | + { HV_REG_X27, offsetof(CPUARMState, xregs[27]) }, | ||
213 | + { HV_REG_X28, offsetof(CPUARMState, xregs[28]) }, | ||
214 | + { HV_REG_X29, offsetof(CPUARMState, xregs[29]) }, | ||
215 | + { HV_REG_X30, offsetof(CPUARMState, xregs[30]) }, | ||
216 | + { HV_REG_PC, offsetof(CPUARMState, pc) }, | ||
217 | +}; | ||
218 | + | ||
219 | +static const struct hvf_reg_match hvf_fpreg_match[] = { | ||
220 | + { HV_SIMD_FP_REG_Q0, offsetof(CPUARMState, vfp.zregs[0]) }, | ||
221 | + { HV_SIMD_FP_REG_Q1, offsetof(CPUARMState, vfp.zregs[1]) }, | ||
222 | + { HV_SIMD_FP_REG_Q2, offsetof(CPUARMState, vfp.zregs[2]) }, | ||
223 | + { HV_SIMD_FP_REG_Q3, offsetof(CPUARMState, vfp.zregs[3]) }, | ||
224 | + { HV_SIMD_FP_REG_Q4, offsetof(CPUARMState, vfp.zregs[4]) }, | ||
225 | + { HV_SIMD_FP_REG_Q5, offsetof(CPUARMState, vfp.zregs[5]) }, | ||
226 | + { HV_SIMD_FP_REG_Q6, offsetof(CPUARMState, vfp.zregs[6]) }, | ||
227 | + { HV_SIMD_FP_REG_Q7, offsetof(CPUARMState, vfp.zregs[7]) }, | ||
228 | + { HV_SIMD_FP_REG_Q8, offsetof(CPUARMState, vfp.zregs[8]) }, | ||
229 | + { HV_SIMD_FP_REG_Q9, offsetof(CPUARMState, vfp.zregs[9]) }, | ||
230 | + { HV_SIMD_FP_REG_Q10, offsetof(CPUARMState, vfp.zregs[10]) }, | ||
231 | + { HV_SIMD_FP_REG_Q11, offsetof(CPUARMState, vfp.zregs[11]) }, | ||
232 | + { HV_SIMD_FP_REG_Q12, offsetof(CPUARMState, vfp.zregs[12]) }, | ||
233 | + { HV_SIMD_FP_REG_Q13, offsetof(CPUARMState, vfp.zregs[13]) }, | ||
234 | + { HV_SIMD_FP_REG_Q14, offsetof(CPUARMState, vfp.zregs[14]) }, | ||
235 | + { HV_SIMD_FP_REG_Q15, offsetof(CPUARMState, vfp.zregs[15]) }, | ||
236 | + { HV_SIMD_FP_REG_Q16, offsetof(CPUARMState, vfp.zregs[16]) }, | ||
237 | + { HV_SIMD_FP_REG_Q17, offsetof(CPUARMState, vfp.zregs[17]) }, | ||
238 | + { HV_SIMD_FP_REG_Q18, offsetof(CPUARMState, vfp.zregs[18]) }, | ||
239 | + { HV_SIMD_FP_REG_Q19, offsetof(CPUARMState, vfp.zregs[19]) }, | ||
240 | + { HV_SIMD_FP_REG_Q20, offsetof(CPUARMState, vfp.zregs[20]) }, | ||
241 | + { HV_SIMD_FP_REG_Q21, offsetof(CPUARMState, vfp.zregs[21]) }, | ||
242 | + { HV_SIMD_FP_REG_Q22, offsetof(CPUARMState, vfp.zregs[22]) }, | ||
243 | + { HV_SIMD_FP_REG_Q23, offsetof(CPUARMState, vfp.zregs[23]) }, | ||
244 | + { HV_SIMD_FP_REG_Q24, offsetof(CPUARMState, vfp.zregs[24]) }, | ||
245 | + { HV_SIMD_FP_REG_Q25, offsetof(CPUARMState, vfp.zregs[25]) }, | ||
246 | + { HV_SIMD_FP_REG_Q26, offsetof(CPUARMState, vfp.zregs[26]) }, | ||
247 | + { HV_SIMD_FP_REG_Q27, offsetof(CPUARMState, vfp.zregs[27]) }, | ||
248 | + { HV_SIMD_FP_REG_Q28, offsetof(CPUARMState, vfp.zregs[28]) }, | ||
249 | + { HV_SIMD_FP_REG_Q29, offsetof(CPUARMState, vfp.zregs[29]) }, | ||
250 | + { HV_SIMD_FP_REG_Q30, offsetof(CPUARMState, vfp.zregs[30]) }, | ||
251 | + { HV_SIMD_FP_REG_Q31, offsetof(CPUARMState, vfp.zregs[31]) }, | ||
252 | +}; | ||
253 | + | ||
254 | +struct hvf_sreg_match { | ||
255 | + int reg; | ||
256 | + uint32_t key; | ||
257 | + uint32_t cp_idx; | ||
258 | +}; | ||
259 | + | ||
260 | +static struct hvf_sreg_match hvf_sreg_match[] = { | ||
261 | + { HV_SYS_REG_DBGBVR0_EL1, HVF_SYSREG(0, 0, 14, 0, 4) }, | ||
262 | + { HV_SYS_REG_DBGBCR0_EL1, HVF_SYSREG(0, 0, 14, 0, 5) }, | ||
263 | + { HV_SYS_REG_DBGWVR0_EL1, HVF_SYSREG(0, 0, 14, 0, 6) }, | ||
264 | + { HV_SYS_REG_DBGWCR0_EL1, HVF_SYSREG(0, 0, 14, 0, 7) }, | ||
265 | + | ||
266 | + { HV_SYS_REG_DBGBVR1_EL1, HVF_SYSREG(0, 1, 14, 0, 4) }, | ||
267 | + { HV_SYS_REG_DBGBCR1_EL1, HVF_SYSREG(0, 1, 14, 0, 5) }, | ||
268 | + { HV_SYS_REG_DBGWVR1_EL1, HVF_SYSREG(0, 1, 14, 0, 6) }, | ||
269 | + { HV_SYS_REG_DBGWCR1_EL1, HVF_SYSREG(0, 1, 14, 0, 7) }, | ||
270 | + | ||
271 | + { HV_SYS_REG_DBGBVR2_EL1, HVF_SYSREG(0, 2, 14, 0, 4) }, | ||
272 | + { HV_SYS_REG_DBGBCR2_EL1, HVF_SYSREG(0, 2, 14, 0, 5) }, | ||
273 | + { HV_SYS_REG_DBGWVR2_EL1, HVF_SYSREG(0, 2, 14, 0, 6) }, | ||
274 | + { HV_SYS_REG_DBGWCR2_EL1, HVF_SYSREG(0, 2, 14, 0, 7) }, | ||
275 | + | ||
276 | + { HV_SYS_REG_DBGBVR3_EL1, HVF_SYSREG(0, 3, 14, 0, 4) }, | ||
277 | + { HV_SYS_REG_DBGBCR3_EL1, HVF_SYSREG(0, 3, 14, 0, 5) }, | ||
278 | + { HV_SYS_REG_DBGWVR3_EL1, HVF_SYSREG(0, 3, 14, 0, 6) }, | ||
279 | + { HV_SYS_REG_DBGWCR3_EL1, HVF_SYSREG(0, 3, 14, 0, 7) }, | ||
280 | + | ||
281 | + { HV_SYS_REG_DBGBVR4_EL1, HVF_SYSREG(0, 4, 14, 0, 4) }, | ||
282 | + { HV_SYS_REG_DBGBCR4_EL1, HVF_SYSREG(0, 4, 14, 0, 5) }, | ||
283 | + { HV_SYS_REG_DBGWVR4_EL1, HVF_SYSREG(0, 4, 14, 0, 6) }, | ||
284 | + { HV_SYS_REG_DBGWCR4_EL1, HVF_SYSREG(0, 4, 14, 0, 7) }, | ||
285 | + | ||
286 | + { HV_SYS_REG_DBGBVR5_EL1, HVF_SYSREG(0, 5, 14, 0, 4) }, | ||
287 | + { HV_SYS_REG_DBGBCR5_EL1, HVF_SYSREG(0, 5, 14, 0, 5) }, | ||
288 | + { HV_SYS_REG_DBGWVR5_EL1, HVF_SYSREG(0, 5, 14, 0, 6) }, | ||
289 | + { HV_SYS_REG_DBGWCR5_EL1, HVF_SYSREG(0, 5, 14, 0, 7) }, | ||
290 | + | ||
291 | + { HV_SYS_REG_DBGBVR6_EL1, HVF_SYSREG(0, 6, 14, 0, 4) }, | ||
292 | + { HV_SYS_REG_DBGBCR6_EL1, HVF_SYSREG(0, 6, 14, 0, 5) }, | ||
293 | + { HV_SYS_REG_DBGWVR6_EL1, HVF_SYSREG(0, 6, 14, 0, 6) }, | ||
294 | + { HV_SYS_REG_DBGWCR6_EL1, HVF_SYSREG(0, 6, 14, 0, 7) }, | ||
295 | + | ||
296 | + { HV_SYS_REG_DBGBVR7_EL1, HVF_SYSREG(0, 7, 14, 0, 4) }, | ||
297 | + { HV_SYS_REG_DBGBCR7_EL1, HVF_SYSREG(0, 7, 14, 0, 5) }, | ||
298 | + { HV_SYS_REG_DBGWVR7_EL1, HVF_SYSREG(0, 7, 14, 0, 6) }, | ||
299 | + { HV_SYS_REG_DBGWCR7_EL1, HVF_SYSREG(0, 7, 14, 0, 7) }, | ||
300 | + | ||
301 | + { HV_SYS_REG_DBGBVR8_EL1, HVF_SYSREG(0, 8, 14, 0, 4) }, | ||
302 | + { HV_SYS_REG_DBGBCR8_EL1, HVF_SYSREG(0, 8, 14, 0, 5) }, | ||
303 | + { HV_SYS_REG_DBGWVR8_EL1, HVF_SYSREG(0, 8, 14, 0, 6) }, | ||
304 | + { HV_SYS_REG_DBGWCR8_EL1, HVF_SYSREG(0, 8, 14, 0, 7) }, | ||
305 | + | ||
306 | + { HV_SYS_REG_DBGBVR9_EL1, HVF_SYSREG(0, 9, 14, 0, 4) }, | ||
307 | + { HV_SYS_REG_DBGBCR9_EL1, HVF_SYSREG(0, 9, 14, 0, 5) }, | ||
308 | + { HV_SYS_REG_DBGWVR9_EL1, HVF_SYSREG(0, 9, 14, 0, 6) }, | ||
309 | + { HV_SYS_REG_DBGWCR9_EL1, HVF_SYSREG(0, 9, 14, 0, 7) }, | ||
310 | + | ||
311 | + { HV_SYS_REG_DBGBVR10_EL1, HVF_SYSREG(0, 10, 14, 0, 4) }, | ||
312 | + { HV_SYS_REG_DBGBCR10_EL1, HVF_SYSREG(0, 10, 14, 0, 5) }, | ||
313 | + { HV_SYS_REG_DBGWVR10_EL1, HVF_SYSREG(0, 10, 14, 0, 6) }, | ||
314 | + { HV_SYS_REG_DBGWCR10_EL1, HVF_SYSREG(0, 10, 14, 0, 7) }, | ||
315 | + | ||
316 | + { HV_SYS_REG_DBGBVR11_EL1, HVF_SYSREG(0, 11, 14, 0, 4) }, | ||
317 | + { HV_SYS_REG_DBGBCR11_EL1, HVF_SYSREG(0, 11, 14, 0, 5) }, | ||
318 | + { HV_SYS_REG_DBGWVR11_EL1, HVF_SYSREG(0, 11, 14, 0, 6) }, | ||
319 | + { HV_SYS_REG_DBGWCR11_EL1, HVF_SYSREG(0, 11, 14, 0, 7) }, | ||
320 | + | ||
321 | + { HV_SYS_REG_DBGBVR12_EL1, HVF_SYSREG(0, 12, 14, 0, 4) }, | ||
322 | + { HV_SYS_REG_DBGBCR12_EL1, HVF_SYSREG(0, 12, 14, 0, 5) }, | ||
323 | + { HV_SYS_REG_DBGWVR12_EL1, HVF_SYSREG(0, 12, 14, 0, 6) }, | ||
324 | + { HV_SYS_REG_DBGWCR12_EL1, HVF_SYSREG(0, 12, 14, 0, 7) }, | ||
325 | + | ||
326 | + { HV_SYS_REG_DBGBVR13_EL1, HVF_SYSREG(0, 13, 14, 0, 4) }, | ||
327 | + { HV_SYS_REG_DBGBCR13_EL1, HVF_SYSREG(0, 13, 14, 0, 5) }, | ||
328 | + { HV_SYS_REG_DBGWVR13_EL1, HVF_SYSREG(0, 13, 14, 0, 6) }, | ||
329 | + { HV_SYS_REG_DBGWCR13_EL1, HVF_SYSREG(0, 13, 14, 0, 7) }, | ||
330 | + | ||
331 | + { HV_SYS_REG_DBGBVR14_EL1, HVF_SYSREG(0, 14, 14, 0, 4) }, | ||
332 | + { HV_SYS_REG_DBGBCR14_EL1, HVF_SYSREG(0, 14, 14, 0, 5) }, | ||
333 | + { HV_SYS_REG_DBGWVR14_EL1, HVF_SYSREG(0, 14, 14, 0, 6) }, | ||
334 | + { HV_SYS_REG_DBGWCR14_EL1, HVF_SYSREG(0, 14, 14, 0, 7) }, | ||
335 | + | ||
336 | + { HV_SYS_REG_DBGBVR15_EL1, HVF_SYSREG(0, 15, 14, 0, 4) }, | ||
337 | + { HV_SYS_REG_DBGBCR15_EL1, HVF_SYSREG(0, 15, 14, 0, 5) }, | ||
338 | + { HV_SYS_REG_DBGWVR15_EL1, HVF_SYSREG(0, 15, 14, 0, 6) }, | ||
339 | + { HV_SYS_REG_DBGWCR15_EL1, HVF_SYSREG(0, 15, 14, 0, 7) }, | ||
340 | + | ||
341 | +#ifdef SYNC_NO_RAW_REGS | ||
342 | + /* | ||
343 | + * The registers below are manually synced on init because they are | ||
344 | + * marked as NO_RAW. We still list them to make number space sync easier. | ||
345 | + */ | ||
346 | + { HV_SYS_REG_MDCCINT_EL1, HVF_SYSREG(0, 2, 2, 0, 0) }, | ||
347 | + { HV_SYS_REG_MIDR_EL1, HVF_SYSREG(0, 0, 3, 0, 0) }, | ||
348 | + { HV_SYS_REG_MPIDR_EL1, HVF_SYSREG(0, 0, 3, 0, 5) }, | ||
349 | + { HV_SYS_REG_ID_AA64PFR0_EL1, HVF_SYSREG(0, 4, 3, 0, 0) }, | ||
350 | +#endif | ||
351 | + { HV_SYS_REG_ID_AA64PFR1_EL1, HVF_SYSREG(0, 4, 3, 0, 2) }, | ||
352 | + { HV_SYS_REG_ID_AA64DFR0_EL1, HVF_SYSREG(0, 5, 3, 0, 0) }, | ||
353 | + { HV_SYS_REG_ID_AA64DFR1_EL1, HVF_SYSREG(0, 5, 3, 0, 1) }, | ||
354 | + { HV_SYS_REG_ID_AA64ISAR0_EL1, HVF_SYSREG(0, 6, 3, 0, 0) }, | ||
355 | + { HV_SYS_REG_ID_AA64ISAR1_EL1, HVF_SYSREG(0, 6, 3, 0, 1) }, | ||
356 | +#ifdef SYNC_NO_MMFR0 | ||
357 | + /* We keep the hardware MMFR0 around. HW limits are there anyway */ | ||
358 | + { HV_SYS_REG_ID_AA64MMFR0_EL1, HVF_SYSREG(0, 7, 3, 0, 0) }, | ||
359 | +#endif | ||
360 | + { HV_SYS_REG_ID_AA64MMFR1_EL1, HVF_SYSREG(0, 7, 3, 0, 1) }, | ||
361 | + { HV_SYS_REG_ID_AA64MMFR2_EL1, HVF_SYSREG(0, 7, 3, 0, 2) }, | ||
362 | + | ||
363 | + { HV_SYS_REG_MDSCR_EL1, HVF_SYSREG(0, 2, 2, 0, 2) }, | ||
364 | + { HV_SYS_REG_SCTLR_EL1, HVF_SYSREG(1, 0, 3, 0, 0) }, | ||
365 | + { HV_SYS_REG_CPACR_EL1, HVF_SYSREG(1, 0, 3, 0, 2) }, | ||
366 | + { HV_SYS_REG_TTBR0_EL1, HVF_SYSREG(2, 0, 3, 0, 0) }, | ||
367 | + { HV_SYS_REG_TTBR1_EL1, HVF_SYSREG(2, 0, 3, 0, 1) }, | ||
368 | + { HV_SYS_REG_TCR_EL1, HVF_SYSREG(2, 0, 3, 0, 2) }, | ||
369 | + | ||
370 | + { HV_SYS_REG_APIAKEYLO_EL1, HVF_SYSREG(2, 1, 3, 0, 0) }, | ||
371 | + { HV_SYS_REG_APIAKEYHI_EL1, HVF_SYSREG(2, 1, 3, 0, 1) }, | ||
372 | + { HV_SYS_REG_APIBKEYLO_EL1, HVF_SYSREG(2, 1, 3, 0, 2) }, | ||
373 | + { HV_SYS_REG_APIBKEYHI_EL1, HVF_SYSREG(2, 1, 3, 0, 3) }, | ||
374 | + { HV_SYS_REG_APDAKEYLO_EL1, HVF_SYSREG(2, 2, 3, 0, 0) }, | ||
375 | + { HV_SYS_REG_APDAKEYHI_EL1, HVF_SYSREG(2, 2, 3, 0, 1) }, | ||
376 | + { HV_SYS_REG_APDBKEYLO_EL1, HVF_SYSREG(2, 2, 3, 0, 2) }, | ||
377 | + { HV_SYS_REG_APDBKEYHI_EL1, HVF_SYSREG(2, 2, 3, 0, 3) }, | ||
378 | + { HV_SYS_REG_APGAKEYLO_EL1, HVF_SYSREG(2, 3, 3, 0, 0) }, | ||
379 | + { HV_SYS_REG_APGAKEYHI_EL1, HVF_SYSREG(2, 3, 3, 0, 1) }, | ||
380 | + | ||
381 | + { HV_SYS_REG_SPSR_EL1, HVF_SYSREG(4, 0, 3, 0, 0) }, | ||
382 | + { HV_SYS_REG_ELR_EL1, HVF_SYSREG(4, 0, 3, 0, 1) }, | ||
383 | + { HV_SYS_REG_SP_EL0, HVF_SYSREG(4, 1, 3, 0, 0) }, | ||
384 | + { HV_SYS_REG_AFSR0_EL1, HVF_SYSREG(5, 1, 3, 0, 0) }, | ||
385 | + { HV_SYS_REG_AFSR1_EL1, HVF_SYSREG(5, 1, 3, 0, 1) }, | ||
386 | + { HV_SYS_REG_ESR_EL1, HVF_SYSREG(5, 2, 3, 0, 0) }, | ||
387 | + { HV_SYS_REG_FAR_EL1, HVF_SYSREG(6, 0, 3, 0, 0) }, | ||
388 | + { HV_SYS_REG_PAR_EL1, HVF_SYSREG(7, 4, 3, 0, 0) }, | ||
389 | + { HV_SYS_REG_MAIR_EL1, HVF_SYSREG(10, 2, 3, 0, 0) }, | ||
390 | + { HV_SYS_REG_AMAIR_EL1, HVF_SYSREG(10, 3, 3, 0, 0) }, | ||
391 | + { HV_SYS_REG_VBAR_EL1, HVF_SYSREG(12, 0, 3, 0, 0) }, | ||
392 | + { HV_SYS_REG_CONTEXTIDR_EL1, HVF_SYSREG(13, 0, 3, 0, 1) }, | ||
393 | + { HV_SYS_REG_TPIDR_EL1, HVF_SYSREG(13, 0, 3, 0, 4) }, | ||
394 | + { HV_SYS_REG_CNTKCTL_EL1, HVF_SYSREG(14, 1, 3, 0, 0) }, | ||
395 | + { HV_SYS_REG_CSSELR_EL1, HVF_SYSREG(0, 0, 3, 2, 0) }, | ||
396 | + { HV_SYS_REG_TPIDR_EL0, HVF_SYSREG(13, 0, 3, 3, 2) }, | ||
397 | + { HV_SYS_REG_TPIDRRO_EL0, HVF_SYSREG(13, 0, 3, 3, 3) }, | ||
398 | + { HV_SYS_REG_CNTV_CTL_EL0, HVF_SYSREG(14, 3, 3, 3, 1) }, | ||
399 | + { HV_SYS_REG_CNTV_CVAL_EL0, HVF_SYSREG(14, 3, 3, 3, 2) }, | ||
400 | + { HV_SYS_REG_SP_EL1, HVF_SYSREG(4, 1, 3, 4, 0) }, | ||
401 | +}; | ||
402 | + | ||
403 | +int hvf_get_registers(CPUState *cpu) | ||
404 | +{ | ||
405 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
406 | + CPUARMState *env = &arm_cpu->env; | ||
407 | + hv_return_t ret; | ||
408 | + uint64_t val; | ||
409 | + hv_simd_fp_uchar16_t fpval; | ||
410 | + int i; | ||
411 | + | ||
412 | + for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) { | ||
413 | + ret = hv_vcpu_get_reg(cpu->hvf->fd, hvf_reg_match[i].reg, &val); | ||
414 | + *(uint64_t *)((void *)env + hvf_reg_match[i].offset) = val; | ||
415 | + assert_hvf_ok(ret); | ||
416 | + } | ||
417 | + | ||
418 | + for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) { | ||
419 | + ret = hv_vcpu_get_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg, | ||
420 | + &fpval); | ||
421 | + memcpy((void *)env + hvf_fpreg_match[i].offset, &fpval, sizeof(fpval)); | ||
422 | + assert_hvf_ok(ret); | ||
423 | + } | ||
424 | + | ||
425 | + val = 0; | ||
426 | + ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPCR, &val); | ||
427 | + assert_hvf_ok(ret); | ||
428 | + vfp_set_fpcr(env, val); | ||
429 | + | ||
430 | + val = 0; | ||
431 | + ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_FPSR, &val); | ||
432 | + assert_hvf_ok(ret); | ||
433 | + vfp_set_fpsr(env, val); | ||
434 | + | ||
435 | + ret = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_CPSR, &val); | ||
436 | + assert_hvf_ok(ret); | ||
437 | + pstate_write(env, val); | ||
438 | + | ||
439 | + for (i = 0; i < ARRAY_SIZE(hvf_sreg_match); i++) { | ||
440 | + if (hvf_sreg_match[i].cp_idx == -1) { | ||
441 | + continue; | ||
442 | + } | ||
443 | + | ||
444 | + ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, &val); | ||
445 | + assert_hvf_ok(ret); | ||
446 | + | ||
447 | + arm_cpu->cpreg_values[hvf_sreg_match[i].cp_idx] = val; | ||
448 | + } | ||
449 | + assert(write_list_to_cpustate(arm_cpu)); | ||
450 | + | ||
451 | + aarch64_restore_sp(env, arm_current_el(env)); | ||
452 | + | ||
453 | + return 0; | ||
454 | +} | ||
455 | + | ||
456 | +int hvf_put_registers(CPUState *cpu) | ||
457 | +{ | ||
458 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
459 | + CPUARMState *env = &arm_cpu->env; | ||
460 | + hv_return_t ret; | ||
461 | + uint64_t val; | ||
462 | + hv_simd_fp_uchar16_t fpval; | ||
463 | + int i; | ||
464 | + | ||
465 | + for (i = 0; i < ARRAY_SIZE(hvf_reg_match); i++) { | ||
466 | + val = *(uint64_t *)((void *)env + hvf_reg_match[i].offset); | ||
467 | + ret = hv_vcpu_set_reg(cpu->hvf->fd, hvf_reg_match[i].reg, val); | ||
468 | + assert_hvf_ok(ret); | ||
469 | + } | ||
470 | + | ||
471 | + for (i = 0; i < ARRAY_SIZE(hvf_fpreg_match); i++) { | ||
472 | + memcpy(&fpval, (void *)env + hvf_fpreg_match[i].offset, sizeof(fpval)); | ||
473 | + ret = hv_vcpu_set_simd_fp_reg(cpu->hvf->fd, hvf_fpreg_match[i].reg, | ||
474 | + fpval); | ||
475 | + assert_hvf_ok(ret); | ||
476 | + } | ||
477 | + | ||
478 | + ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPCR, vfp_get_fpcr(env)); | ||
479 | + assert_hvf_ok(ret); | ||
480 | + | ||
481 | + ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_FPSR, vfp_get_fpsr(env)); | ||
482 | + assert_hvf_ok(ret); | ||
483 | + | ||
484 | + ret = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_CPSR, pstate_read(env)); | ||
485 | + assert_hvf_ok(ret); | ||
486 | + | ||
487 | + aarch64_save_sp(env, arm_current_el(env)); | ||
488 | + | ||
489 | + assert(write_cpustate_to_list(arm_cpu, false)); | ||
490 | + for (i = 0; i < ARRAY_SIZE(hvf_sreg_match); i++) { | ||
491 | + if (hvf_sreg_match[i].cp_idx == -1) { | ||
492 | + continue; | ||
493 | + } | ||
494 | + | ||
495 | + val = arm_cpu->cpreg_values[hvf_sreg_match[i].cp_idx]; | ||
496 | + ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, hvf_sreg_match[i].reg, val); | ||
497 | + assert_hvf_ok(ret); | ||
498 | + } | ||
499 | + | ||
500 | + ret = hv_vcpu_set_vtimer_offset(cpu->hvf->fd, hvf_state->vtimer_offset); | ||
501 | + assert_hvf_ok(ret); | ||
502 | + | ||
503 | + return 0; | ||
504 | +} | ||
505 | + | ||
506 | +static void flush_cpu_state(CPUState *cpu) | ||
507 | +{ | ||
508 | + if (cpu->vcpu_dirty) { | ||
509 | + hvf_put_registers(cpu); | ||
510 | + cpu->vcpu_dirty = false; | ||
511 | + } | ||
512 | +} | ||
513 | + | ||
514 | +static void hvf_set_reg(CPUState *cpu, int rt, uint64_t val) | ||
515 | +{ | ||
516 | + hv_return_t r; | ||
517 | + | ||
518 | + flush_cpu_state(cpu); | ||
519 | + | ||
520 | + if (rt < 31) { | ||
521 | + r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_X0 + rt, val); | ||
522 | + assert_hvf_ok(r); | ||
523 | + } | ||
524 | +} | ||
525 | + | ||
526 | +static uint64_t hvf_get_reg(CPUState *cpu, int rt) | ||
527 | +{ | ||
528 | + uint64_t val = 0; | ||
529 | + hv_return_t r; | ||
530 | + | ||
531 | + flush_cpu_state(cpu); | ||
532 | + | ||
533 | + if (rt < 31) { | ||
534 | + r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_X0 + rt, &val); | ||
535 | + assert_hvf_ok(r); | ||
536 | + } | ||
537 | + | ||
538 | + return val; | ||
539 | +} | ||
540 | + | ||
541 | +void hvf_arch_vcpu_destroy(CPUState *cpu) | ||
542 | +{ | ||
543 | +} | ||
544 | + | ||
545 | +int hvf_arch_init_vcpu(CPUState *cpu) | ||
546 | +{ | ||
547 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
548 | + CPUARMState *env = &arm_cpu->env; | ||
549 | + uint32_t sregs_match_len = ARRAY_SIZE(hvf_sreg_match); | ||
550 | + uint32_t sregs_cnt = 0; | ||
551 | + uint64_t pfr; | ||
552 | + hv_return_t ret; | ||
553 | + int i; | ||
554 | + | ||
555 | + env->aarch64 = 1; | ||
556 | + asm volatile("mrs %0, cntfrq_el0" : "=r"(arm_cpu->gt_cntfrq_hz)); | ||
557 | + | ||
558 | + /* Allocate enough space for our sysreg sync */ | ||
559 | + arm_cpu->cpreg_indexes = g_renew(uint64_t, arm_cpu->cpreg_indexes, | ||
560 | + sregs_match_len); | ||
561 | + arm_cpu->cpreg_values = g_renew(uint64_t, arm_cpu->cpreg_values, | ||
562 | + sregs_match_len); | ||
563 | + arm_cpu->cpreg_vmstate_indexes = g_renew(uint64_t, | ||
564 | + arm_cpu->cpreg_vmstate_indexes, | ||
565 | + sregs_match_len); | ||
566 | + arm_cpu->cpreg_vmstate_values = g_renew(uint64_t, | ||
567 | + arm_cpu->cpreg_vmstate_values, | ||
568 | + sregs_match_len); | ||
569 | + | ||
570 | + memset(arm_cpu->cpreg_values, 0, sregs_match_len * sizeof(uint64_t)); | ||
571 | + | ||
572 | + /* Populate cp list for all known sysregs */ | ||
573 | + for (i = 0; i < sregs_match_len; i++) { | ||
574 | + const ARMCPRegInfo *ri; | ||
575 | + uint32_t key = hvf_sreg_match[i].key; | ||
576 | + | ||
577 | + ri = get_arm_cp_reginfo(arm_cpu->cp_regs, key); | ||
578 | + if (ri) { | ||
579 | + assert(!(ri->type & ARM_CP_NO_RAW)); | ||
580 | + hvf_sreg_match[i].cp_idx = sregs_cnt; | ||
581 | + arm_cpu->cpreg_indexes[sregs_cnt++] = cpreg_to_kvm_id(key); | ||
582 | + } else { | ||
583 | + hvf_sreg_match[i].cp_idx = -1; | ||
584 | + } | ||
585 | + } | ||
586 | + arm_cpu->cpreg_array_len = sregs_cnt; | ||
587 | + arm_cpu->cpreg_vmstate_array_len = sregs_cnt; | ||
588 | + | ||
589 | + assert(write_cpustate_to_list(arm_cpu, false)); | ||
590 | + | ||
591 | + /* Set CP_NO_RAW system registers on init */ | ||
592 | + ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MIDR_EL1, | ||
593 | + arm_cpu->midr); | ||
594 | + assert_hvf_ok(ret); | ||
595 | + | ||
596 | + ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_MPIDR_EL1, | ||
597 | + arm_cpu->mp_affinity); | ||
598 | + assert_hvf_ok(ret); | ||
599 | + | ||
600 | + ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, &pfr); | ||
601 | + assert_hvf_ok(ret); | ||
602 | + pfr |= env->gicv3state ? (1 << 24) : 0; | ||
603 | + ret = hv_vcpu_set_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64PFR0_EL1, pfr); | ||
604 | + assert_hvf_ok(ret); | ||
605 | + | ||
606 | + /* We're limited to underlying hardware caps, override internal versions */ | ||
607 | + ret = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_ID_AA64MMFR0_EL1, | ||
608 | + &arm_cpu->isar.id_aa64mmfr0); | ||
609 | + assert_hvf_ok(ret); | ||
610 | + | ||
611 | + return 0; | ||
612 | +} | ||
613 | + | ||
614 | +void hvf_kick_vcpu_thread(CPUState *cpu) | ||
615 | +{ | ||
616 | + hv_vcpus_exit(&cpu->hvf->fd, 1); | ||
617 | +} | ||
618 | + | ||
619 | +static void hvf_raise_exception(CPUState *cpu, uint32_t excp, | ||
620 | + uint32_t syndrome) | ||
621 | +{ | ||
622 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
623 | + CPUARMState *env = &arm_cpu->env; | ||
624 | + | ||
625 | + cpu->exception_index = excp; | ||
626 | + env->exception.target_el = 1; | ||
627 | + env->exception.syndrome = syndrome; | ||
628 | + | ||
629 | + arm_cpu_do_interrupt(cpu); | ||
630 | +} | ||
631 | + | ||
632 | +static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint32_t rt) | ||
633 | +{ | ||
634 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
635 | + CPUARMState *env = &arm_cpu->env; | ||
636 | + uint64_t val = 0; | ||
637 | + | ||
638 | + switch (reg) { | ||
639 | + case SYSREG_CNTPCT_EL0: | ||
640 | + val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / | ||
641 | + gt_cntfrq_period_ns(arm_cpu); | ||
642 | + break; | ||
643 | + case SYSREG_OSLSR_EL1: | ||
644 | + val = env->cp15.oslsr_el1; | ||
645 | + break; | ||
646 | + case SYSREG_OSDLR_EL1: | ||
647 | + /* Dummy register */ | ||
648 | + break; | ||
649 | + default: | ||
650 | + cpu_synchronize_state(cpu); | ||
651 | + trace_hvf_unhandled_sysreg_read(env->pc, reg, | ||
652 | + (reg >> 20) & 0x3, | ||
653 | + (reg >> 14) & 0x7, | ||
654 | + (reg >> 10) & 0xf, | ||
655 | + (reg >> 1) & 0xf, | ||
656 | + (reg >> 17) & 0x7); | ||
657 | + hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized()); | ||
658 | + return 1; | ||
659 | + } | ||
660 | + | ||
661 | + trace_hvf_sysreg_read(reg, | ||
662 | + (reg >> 20) & 0x3, | ||
663 | + (reg >> 14) & 0x7, | ||
664 | + (reg >> 10) & 0xf, | ||
665 | + (reg >> 1) & 0xf, | ||
666 | + (reg >> 17) & 0x7, | ||
667 | + val); | ||
668 | + hvf_set_reg(cpu, rt, val); | ||
669 | + | ||
670 | + return 0; | ||
671 | +} | ||
672 | + | ||
673 | +static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val) | ||
674 | +{ | ||
675 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
676 | + CPUARMState *env = &arm_cpu->env; | ||
677 | + | ||
678 | + trace_hvf_sysreg_write(reg, | ||
679 | + (reg >> 20) & 0x3, | ||
680 | + (reg >> 14) & 0x7, | ||
681 | + (reg >> 10) & 0xf, | ||
682 | + (reg >> 1) & 0xf, | ||
683 | + (reg >> 17) & 0x7, | ||
684 | + val); | ||
685 | + | ||
686 | + switch (reg) { | ||
687 | + case SYSREG_OSLAR_EL1: | ||
688 | + env->cp15.oslsr_el1 = val & 1; | ||
689 | + break; | ||
690 | + case SYSREG_OSDLR_EL1: | ||
691 | + /* Dummy register */ | ||
692 | + break; | ||
693 | + default: | ||
694 | + cpu_synchronize_state(cpu); | ||
695 | + trace_hvf_unhandled_sysreg_write(env->pc, reg, | ||
696 | + (reg >> 20) & 0x3, | ||
697 | + (reg >> 14) & 0x7, | ||
698 | + (reg >> 10) & 0xf, | ||
699 | + (reg >> 1) & 0xf, | ||
700 | + (reg >> 17) & 0x7); | ||
701 | + hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized()); | ||
702 | + return 1; | ||
703 | + } | ||
704 | + | ||
705 | + return 0; | ||
706 | +} | ||
707 | + | ||
708 | +static int hvf_inject_interrupts(CPUState *cpu) | ||
709 | +{ | ||
710 | + if (cpu->interrupt_request & CPU_INTERRUPT_FIQ) { | ||
711 | + trace_hvf_inject_fiq(); | ||
712 | + hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_FIQ, | ||
713 | + true); | ||
714 | + } | ||
715 | + | ||
716 | + if (cpu->interrupt_request & CPU_INTERRUPT_HARD) { | ||
717 | + trace_hvf_inject_irq(); | ||
718 | + hv_vcpu_set_pending_interrupt(cpu->hvf->fd, HV_INTERRUPT_TYPE_IRQ, | ||
719 | + true); | ||
720 | + } | ||
721 | + | ||
722 | + return 0; | ||
723 | +} | ||
724 | + | ||
725 | +static uint64_t hvf_vtimer_val_raw(void) | ||
726 | +{ | ||
727 | + /* | ||
728 | + * mach_absolute_time() returns the vtimer value without the VM | ||
729 | + * offset that we define. Add our own offset on top. | ||
730 | + */ | ||
731 | + return mach_absolute_time() - hvf_state->vtimer_offset; | ||
732 | +} | ||
733 | + | ||
734 | +static void hvf_sync_vtimer(CPUState *cpu) | ||
735 | +{ | ||
736 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
737 | + hv_return_t r; | ||
738 | + uint64_t ctl; | ||
739 | + bool irq_state; | ||
740 | + | ||
741 | + if (!cpu->hvf->vtimer_masked) { | ||
742 | + /* We will get notified on vtimer changes by hvf, nothing to do */ | ||
25 | + return; | 743 | + return; |
26 | + } | 744 | + } |
27 | + | 745 | + |
28 | + switch (type) { | 746 | + r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl); |
29 | + case 0: /* float32 */ | 747 | + assert_hvf_ok(r); |
30 | + case 1: /* float64 */ | 748 | + |
31 | + break; | 749 | + irq_state = (ctl & (TMR_CTL_ENABLE | TMR_CTL_IMASK | TMR_CTL_ISTATUS)) == |
32 | + case 3: /* float16 */ | 750 | + (TMR_CTL_ENABLE | TMR_CTL_ISTATUS); |
33 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 751 | + qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], irq_state); |
34 | + break; | 752 | + |
753 | + if (!irq_state) { | ||
754 | + /* Timer no longer asserting, we can unmask it */ | ||
755 | + hv_vcpu_set_vtimer_mask(cpu->hvf->fd, false); | ||
756 | + cpu->hvf->vtimer_masked = false; | ||
757 | + } | ||
758 | +} | ||
759 | + | ||
760 | +int hvf_vcpu_exec(CPUState *cpu) | ||
761 | +{ | ||
762 | + ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
763 | + CPUARMState *env = &arm_cpu->env; | ||
764 | + hv_vcpu_exit_t *hvf_exit = cpu->hvf->exit; | ||
765 | + hv_return_t r; | ||
766 | + bool advance_pc = false; | ||
767 | + | ||
768 | + if (hvf_inject_interrupts(cpu)) { | ||
769 | + return EXCP_INTERRUPT; | ||
770 | + } | ||
771 | + | ||
772 | + if (cpu->halted) { | ||
773 | + return EXCP_HLT; | ||
774 | + } | ||
775 | + | ||
776 | + flush_cpu_state(cpu); | ||
777 | + | ||
778 | + qemu_mutex_unlock_iothread(); | ||
779 | + assert_hvf_ok(hv_vcpu_run(cpu->hvf->fd)); | ||
780 | + | ||
781 | + /* handle VMEXIT */ | ||
782 | + uint64_t exit_reason = hvf_exit->reason; | ||
783 | + uint64_t syndrome = hvf_exit->exception.syndrome; | ||
784 | + uint32_t ec = syn_get_ec(syndrome); | ||
785 | + | ||
786 | + qemu_mutex_lock_iothread(); | ||
787 | + switch (exit_reason) { | ||
788 | + case HV_EXIT_REASON_EXCEPTION: | ||
789 | + /* This is the main one, handle below. */ | ||
790 | + break; | ||
791 | + case HV_EXIT_REASON_VTIMER_ACTIVATED: | ||
792 | + qemu_set_irq(arm_cpu->gt_timer_outputs[GTIMER_VIRT], 1); | ||
793 | + cpu->hvf->vtimer_masked = true; | ||
794 | + return 0; | ||
795 | + case HV_EXIT_REASON_CANCELED: | ||
796 | + /* we got kicked, no exit to process */ | ||
797 | + return 0; | ||
798 | + default: | ||
799 | + assert(0); | ||
800 | + } | ||
801 | + | ||
802 | + hvf_sync_vtimer(cpu); | ||
803 | + | ||
804 | + switch (ec) { | ||
805 | + case EC_DATAABORT: { | ||
806 | + bool isv = syndrome & ARM_EL_ISV; | ||
807 | + bool iswrite = (syndrome >> 6) & 1; | ||
808 | + bool s1ptw = (syndrome >> 7) & 1; | ||
809 | + uint32_t sas = (syndrome >> 22) & 3; | ||
810 | + uint32_t len = 1 << sas; | ||
811 | + uint32_t srt = (syndrome >> 16) & 0x1f; | ||
812 | + uint64_t val = 0; | ||
813 | + | ||
814 | + trace_hvf_data_abort(env->pc, hvf_exit->exception.virtual_address, | ||
815 | + hvf_exit->exception.physical_address, isv, | ||
816 | + iswrite, s1ptw, len, srt); | ||
817 | + | ||
818 | + assert(isv); | ||
819 | + | ||
820 | + if (iswrite) { | ||
821 | + val = hvf_get_reg(cpu, srt); | ||
822 | + address_space_write(&address_space_memory, | ||
823 | + hvf_exit->exception.physical_address, | ||
824 | + MEMTXATTRS_UNSPECIFIED, &val, len); | ||
825 | + } else { | ||
826 | + address_space_read(&address_space_memory, | ||
827 | + hvf_exit->exception.physical_address, | ||
828 | + MEMTXATTRS_UNSPECIFIED, &val, len); | ||
829 | + hvf_set_reg(cpu, srt, val); | ||
35 | + } | 830 | + } |
36 | + /* fallthru */ | 831 | + |
832 | + advance_pc = true; | ||
833 | + break; | ||
834 | + } | ||
835 | + case EC_SYSTEMREGISTERTRAP: { | ||
836 | + bool isread = (syndrome >> 0) & 1; | ||
837 | + uint32_t rt = (syndrome >> 5) & 0x1f; | ||
838 | + uint32_t reg = syndrome & SYSREG_MASK; | ||
839 | + uint64_t val; | ||
840 | + int ret = 0; | ||
841 | + | ||
842 | + if (isread) { | ||
843 | + ret = hvf_sysreg_read(cpu, reg, rt); | ||
844 | + } else { | ||
845 | + val = hvf_get_reg(cpu, rt); | ||
846 | + ret = hvf_sysreg_write(cpu, reg, val); | ||
847 | + } | ||
848 | + | ||
849 | + advance_pc = !ret; | ||
850 | + break; | ||
851 | + } | ||
852 | + case EC_WFX_TRAP: | ||
853 | + advance_pc = true; | ||
854 | + break; | ||
855 | + case EC_AA64_HVC: | ||
856 | + cpu_synchronize_state(cpu); | ||
857 | + trace_hvf_unknown_hvc(env->xregs[0]); | ||
858 | + /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */ | ||
859 | + env->xregs[0] = -1; | ||
860 | + break; | ||
861 | + case EC_AA64_SMC: | ||
862 | + cpu_synchronize_state(cpu); | ||
863 | + trace_hvf_unknown_smc(env->xregs[0]); | ||
864 | + hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized()); | ||
865 | + break; | ||
37 | + default: | 866 | + default: |
38 | unallocated_encoding(s); | 867 | + cpu_synchronize_state(cpu); |
39 | return; | 868 | + trace_hvf_exit(syndrome, ec, env->pc); |
40 | } | 869 | + error_report("0x%llx: unhandled exception ec=0x%x", env->pc, ec); |
870 | + } | ||
871 | + | ||
872 | + if (advance_pc) { | ||
873 | + uint64_t pc; | ||
874 | + | ||
875 | + flush_cpu_state(cpu); | ||
876 | + | ||
877 | + r = hv_vcpu_get_reg(cpu->hvf->fd, HV_REG_PC, &pc); | ||
878 | + assert_hvf_ok(r); | ||
879 | + pc += 4; | ||
880 | + r = hv_vcpu_set_reg(cpu->hvf->fd, HV_REG_PC, pc); | ||
881 | + assert_hvf_ok(r); | ||
882 | + } | ||
883 | + | ||
884 | + return 0; | ||
885 | +} | ||
886 | + | ||
887 | +static const VMStateDescription vmstate_hvf_vtimer = { | ||
888 | + .name = "hvf-vtimer", | ||
889 | + .version_id = 1, | ||
890 | + .minimum_version_id = 1, | ||
891 | + .fields = (VMStateField[]) { | ||
892 | + VMSTATE_UINT64(vtimer_val, HVFVTimer), | ||
893 | + VMSTATE_END_OF_LIST() | ||
894 | + }, | ||
895 | +}; | ||
896 | + | ||
897 | +static void hvf_vm_state_change(void *opaque, bool running, RunState state) | ||
898 | +{ | ||
899 | + HVFVTimer *s = opaque; | ||
900 | + | ||
901 | + if (running) { | ||
902 | + /* Update vtimer offset on all CPUs */ | ||
903 | + hvf_state->vtimer_offset = mach_absolute_time() - s->vtimer_val; | ||
904 | + cpu_synchronize_all_states(); | ||
905 | + } else { | ||
906 | + /* Remember vtimer value on every pause */ | ||
907 | + s->vtimer_val = hvf_vtimer_val_raw(); | ||
908 | + } | ||
909 | +} | ||
910 | + | ||
911 | +int hvf_arch_init(void) | ||
912 | +{ | ||
913 | + hvf_state->vtimer_offset = mach_absolute_time(); | ||
914 | + vmstate_register(NULL, 0, &vmstate_hvf_vtimer, &vtimer); | ||
915 | + qemu_add_vm_change_state_handler(hvf_vm_state_change, &vtimer); | ||
916 | + return 0; | ||
917 | +} | ||
918 | diff --git a/target/i386/hvf/hvf.c b/target/i386/hvf/hvf.c | ||
919 | index XXXXXXX..XXXXXXX 100644 | ||
920 | --- a/target/i386/hvf/hvf.c | ||
921 | +++ b/target/i386/hvf/hvf.c | ||
922 | @@ -XXX,XX +XXX,XX @@ static inline bool apic_bus_freq_is_known(CPUX86State *env) | ||
923 | return env->apic_bus_freq != 0; | ||
924 | } | ||
925 | |||
926 | +void hvf_kick_vcpu_thread(CPUState *cpu) | ||
927 | +{ | ||
928 | + cpus_kick_thread(cpu); | ||
929 | +} | ||
930 | + | ||
931 | int hvf_arch_init(void) | ||
932 | { | ||
933 | return 0; | ||
934 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
935 | index XXXXXXX..XXXXXXX 100644 | ||
936 | --- a/MAINTAINERS | ||
937 | +++ b/MAINTAINERS | ||
938 | @@ -XXX,XX +XXX,XX @@ F: accel/accel-*.c | ||
939 | F: accel/Makefile.objs | ||
940 | F: accel/stubs/Makefile.objs | ||
941 | |||
942 | +Apple Silicon HVF CPUs | ||
943 | +M: Alexander Graf <agraf@csgraf.de> | ||
944 | +S: Maintained | ||
945 | +F: target/arm/hvf/ | ||
946 | + | ||
947 | X86 HVF CPUs | ||
948 | M: Cameron Esfahani <dirty@apple.com> | ||
949 | M: Roman Bolshakov <r.bolshakov@yadro.com> | ||
950 | diff --git a/target/arm/hvf/trace-events b/target/arm/hvf/trace-events | ||
951 | new file mode 100644 | ||
952 | index XXXXXXX..XXXXXXX | ||
953 | --- /dev/null | ||
954 | +++ b/target/arm/hvf/trace-events | ||
955 | @@ -XXX,XX +XXX,XX @@ | ||
956 | +hvf_unhandled_sysreg_read(uint64_t pc, uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2) "unhandled sysreg read at pc=0x%"PRIx64": 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d)" | ||
957 | +hvf_unhandled_sysreg_write(uint64_t pc, uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2) "unhandled sysreg write at pc=0x%"PRIx64": 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d)" | ||
958 | +hvf_inject_fiq(void) "injecting FIQ" | ||
959 | +hvf_inject_irq(void) "injecting IRQ" | ||
960 | +hvf_data_abort(uint64_t pc, uint64_t va, uint64_t pa, bool isv, bool iswrite, bool s1ptw, uint32_t len, uint32_t srt) "data abort: [pc=0x%"PRIx64" va=0x%016"PRIx64" pa=0x%016"PRIx64" isv=%d iswrite=%d s1ptw=%d len=%d srt=%d]" | ||
961 | +hvf_sysreg_read(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg read 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d) = 0x%016"PRIx64 | ||
962 | +hvf_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_t crm, uint32_t op2, uint64_t val) "sysreg write 0x%08x (op0=%d op1=%d crn=%d crm=%d op2=%d, val=0x%016"PRIx64")" | ||
963 | +hvf_unknown_hvc(uint64_t x0) "unknown HVC! 0x%016"PRIx64 | ||
964 | +hvf_unknown_smc(uint64_t x0) "unknown SMC! 0x%016"PRIx64 | ||
965 | +hvf_exit(uint64_t syndrome, uint32_t ec, uint64_t pc) "exit: 0x%"PRIx64" [ec=0x%x pc=0x%"PRIx64"]" | ||
41 | -- | 966 | -- |
42 | 2.17.0 | 967 | 2.20.1 |
43 | 968 | ||
44 | 969 | diff view generated by jsdifflib |
1 | From: Alex Bennée <alex.bennee@linaro.org> | 1 | From: Peter Collingbourne <pcc@google.com> |
---|---|---|---|
2 | 2 | ||
3 | These where missed out from the rest of the half-precision work. | 3 | Sleep on WFI until the VTIMER is due but allow ourselves to be woken |
4 | up on IPI. | ||
4 | 5 | ||
5 | Cc: qemu-stable@nongnu.org | 6 | In this implementation IPI is blocked on the CPU thread at startup and |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | pselect() is used to atomically unblock the signal and begin sleeping. |
7 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | 8 | The signal is sent unconditionally so there's no need to worry about |
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 9 | races between actually sleeping and the "we think we're sleeping" |
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | state. It may lead to an extra wakeup but that's better than missing |
10 | Message-id: 20180512003217.9105-9-richard.henderson@linaro.org | 11 | it entirely. |
11 | [rth: Diagnose lack of FP16 before fp_access_check] | 12 | |
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Signed-off-by: Peter Collingbourne <pcc@google.com> |
14 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | ||
15 | Acked-by: Roman Bolshakov <r.bolshakov@yadro.com> | ||
16 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
17 | Message-id: 20210916155404.86958-6-agraf@csgraf.de | ||
18 | [agraf: Remove unused 'set' variable, always advance PC on WFX trap, | ||
19 | support vm stop / continue operations and cntv offsets] | ||
20 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | ||
21 | Acked-by: Roman Bolshakov <r.bolshakov@yadro.com> | ||
22 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 24 | --- |
15 | target/arm/helper-a64.h | 2 + | 25 | include/sysemu/hvf_int.h | 1 + |
16 | target/arm/helper-a64.c | 10 +++++ | 26 | accel/hvf/hvf-accel-ops.c | 5 +-- |
17 | target/arm/translate-a64.c | 88 ++++++++++++++++++++++++++++++-------- | 27 | target/arm/hvf/hvf.c | 79 +++++++++++++++++++++++++++++++++++++++ |
18 | 3 files changed, 83 insertions(+), 17 deletions(-) | 28 | 3 files changed, 82 insertions(+), 3 deletions(-) |
19 | 29 | ||
20 | diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h | 30 | diff --git a/include/sysemu/hvf_int.h b/include/sysemu/hvf_int.h |
21 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/arm/helper-a64.h | 32 | --- a/include/sysemu/hvf_int.h |
23 | +++ b/target/arm/helper-a64.h | 33 | +++ b/include/sysemu/hvf_int.h |
34 | @@ -XXX,XX +XXX,XX @@ struct hvf_vcpu_state { | ||
35 | uint64_t fd; | ||
36 | void *exit; | ||
37 | bool vtimer_masked; | ||
38 | + sigset_t unblock_ipi_mask; | ||
39 | }; | ||
40 | |||
41 | void assert_hvf_ok(hv_return_t ret); | ||
42 | diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/accel/hvf/hvf-accel-ops.c | ||
45 | +++ b/accel/hvf/hvf-accel-ops.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static int hvf_init_vcpu(CPUState *cpu) | ||
47 | cpu->hvf = g_malloc0(sizeof(*cpu->hvf)); | ||
48 | |||
49 | /* init cpu signals */ | ||
50 | - sigset_t set; | ||
51 | struct sigaction sigact; | ||
52 | |||
53 | memset(&sigact, 0, sizeof(sigact)); | ||
54 | sigact.sa_handler = dummy_signal; | ||
55 | sigaction(SIG_IPI, &sigact, NULL); | ||
56 | |||
57 | - pthread_sigmask(SIG_BLOCK, NULL, &set); | ||
58 | - sigdelset(&set, SIG_IPI); | ||
59 | + pthread_sigmask(SIG_BLOCK, NULL, &cpu->hvf->unblock_ipi_mask); | ||
60 | + sigdelset(&cpu->hvf->unblock_ipi_mask, SIG_IPI); | ||
61 | |||
62 | #ifdef __aarch64__ | ||
63 | r = hv_vcpu_create(&cpu->hvf->fd, (hv_vcpu_exit_t **)&cpu->hvf->exit, NULL); | ||
64 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/target/arm/hvf/hvf.c | ||
67 | +++ b/target/arm/hvf/hvf.c | ||
24 | @@ -XXX,XX +XXX,XX @@ | 68 | @@ -XXX,XX +XXX,XX @@ |
25 | DEF_HELPER_FLAGS_2(udiv64, TCG_CALL_NO_RWG_SE, i64, i64, i64) | 69 | * QEMU Hypervisor.framework support for Apple Silicon |
26 | DEF_HELPER_FLAGS_2(sdiv64, TCG_CALL_NO_RWG_SE, s64, s64, s64) | 70 | |
27 | DEF_HELPER_FLAGS_1(rbit64, TCG_CALL_NO_RWG_SE, i64, i64) | 71 | * Copyright 2020 Alexander Graf <agraf@csgraf.de> |
28 | +DEF_HELPER_3(vfp_cmph_a64, i64, f16, f16, ptr) | 72 | + * Copyright 2020 Google LLC |
29 | +DEF_HELPER_3(vfp_cmpeh_a64, i64, f16, f16, ptr) | 73 | * |
30 | DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr) | 74 | * This work is licensed under the terms of the GNU GPL, version 2 or later. |
31 | DEF_HELPER_3(vfp_cmpes_a64, i64, f32, f32, ptr) | 75 | * See the COPYING file in the top-level directory. |
32 | DEF_HELPER_3(vfp_cmpd_a64, i64, f64, f64, ptr) | 76 | @@ -XXX,XX +XXX,XX @@ int hvf_arch_init_vcpu(CPUState *cpu) |
33 | diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c | 77 | |
34 | index XXXXXXX..XXXXXXX 100644 | 78 | void hvf_kick_vcpu_thread(CPUState *cpu) |
35 | --- a/target/arm/helper-a64.c | 79 | { |
36 | +++ b/target/arm/helper-a64.c | 80 | + cpus_kick_thread(cpu); |
37 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t float_rel_to_flags(int res) | 81 | hv_vcpus_exit(&cpu->hvf->fd, 1); |
38 | return flags; | ||
39 | } | 82 | } |
40 | 83 | ||
41 | +uint64_t HELPER(vfp_cmph_a64)(float16 x, float16 y, void *fp_status) | 84 | @@ -XXX,XX +XXX,XX @@ static uint64_t hvf_vtimer_val_raw(void) |
85 | return mach_absolute_time() - hvf_state->vtimer_offset; | ||
86 | } | ||
87 | |||
88 | +static uint64_t hvf_vtimer_val(void) | ||
42 | +{ | 89 | +{ |
43 | + return float_rel_to_flags(float16_compare_quiet(x, y, fp_status)); | 90 | + if (!runstate_is_running()) { |
91 | + /* VM is paused, the vtimer value is in vtimer.vtimer_val */ | ||
92 | + return vtimer.vtimer_val; | ||
93 | + } | ||
94 | + | ||
95 | + return hvf_vtimer_val_raw(); | ||
44 | +} | 96 | +} |
45 | + | 97 | + |
46 | +uint64_t HELPER(vfp_cmpeh_a64)(float16 x, float16 y, void *fp_status) | 98 | +static void hvf_wait_for_ipi(CPUState *cpu, struct timespec *ts) |
47 | +{ | 99 | +{ |
48 | + return float_rel_to_flags(float16_compare(x, y, fp_status)); | 100 | + /* |
101 | + * Use pselect to sleep so that other threads can IPI us while we're | ||
102 | + * sleeping. | ||
103 | + */ | ||
104 | + qatomic_mb_set(&cpu->thread_kicked, false); | ||
105 | + qemu_mutex_unlock_iothread(); | ||
106 | + pselect(0, 0, 0, 0, ts, &cpu->hvf->unblock_ipi_mask); | ||
107 | + qemu_mutex_lock_iothread(); | ||
49 | +} | 108 | +} |
50 | + | 109 | + |
51 | uint64_t HELPER(vfp_cmps_a64)(float32 x, float32 y, void *fp_status) | 110 | +static void hvf_wfi(CPUState *cpu) |
52 | { | 111 | +{ |
53 | return float_rel_to_flags(float32_compare_quiet(x, y, fp_status)); | 112 | + ARMCPU *arm_cpu = ARM_CPU(cpu); |
54 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 113 | + struct timespec ts; |
55 | index XXXXXXX..XXXXXXX 100644 | 114 | + hv_return_t r; |
56 | --- a/target/arm/translate-a64.c | 115 | + uint64_t ctl; |
57 | +++ b/target/arm/translate-a64.c | 116 | + uint64_t cval; |
58 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_reg(DisasContext *s, uint32_t insn) | 117 | + int64_t ticks_to_sleep; |
59 | } | 118 | + uint64_t seconds; |
60 | } | 119 | + uint64_t nanos; |
61 | 120 | + uint32_t cntfrq; | |
62 | -static void handle_fp_compare(DisasContext *s, bool is_double, | ||
63 | +static void handle_fp_compare(DisasContext *s, int size, | ||
64 | unsigned int rn, unsigned int rm, | ||
65 | bool cmp_with_zero, bool signal_all_nans) | ||
66 | { | ||
67 | TCGv_i64 tcg_flags = tcg_temp_new_i64(); | ||
68 | - TCGv_ptr fpst = get_fpstatus_ptr(false); | ||
69 | + TCGv_ptr fpst = get_fpstatus_ptr(size == MO_16); | ||
70 | |||
71 | - if (is_double) { | ||
72 | + if (size == MO_64) { | ||
73 | TCGv_i64 tcg_vn, tcg_vm; | ||
74 | |||
75 | tcg_vn = read_fp_dreg(s, rn); | ||
76 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_compare(DisasContext *s, bool is_double, | ||
77 | tcg_temp_free_i64(tcg_vn); | ||
78 | tcg_temp_free_i64(tcg_vm); | ||
79 | } else { | ||
80 | - TCGv_i32 tcg_vn, tcg_vm; | ||
81 | + TCGv_i32 tcg_vn = tcg_temp_new_i32(); | ||
82 | + TCGv_i32 tcg_vm = tcg_temp_new_i32(); | ||
83 | |||
84 | - tcg_vn = read_fp_sreg(s, rn); | ||
85 | + read_vec_element_i32(s, tcg_vn, rn, 0, size); | ||
86 | if (cmp_with_zero) { | ||
87 | - tcg_vm = tcg_const_i32(0); | ||
88 | + tcg_gen_movi_i32(tcg_vm, 0); | ||
89 | } else { | ||
90 | - tcg_vm = read_fp_sreg(s, rm); | ||
91 | + read_vec_element_i32(s, tcg_vm, rm, 0, size); | ||
92 | } | ||
93 | - if (signal_all_nans) { | ||
94 | - gen_helper_vfp_cmpes_a64(tcg_flags, tcg_vn, tcg_vm, fpst); | ||
95 | - } else { | ||
96 | - gen_helper_vfp_cmps_a64(tcg_flags, tcg_vn, tcg_vm, fpst); | ||
97 | + | 121 | + |
98 | + switch (size) { | 122 | + if (cpu->interrupt_request & (CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIQ)) { |
99 | + case MO_32: | 123 | + /* Interrupt pending, no need to wait */ |
100 | + if (signal_all_nans) { | ||
101 | + gen_helper_vfp_cmpes_a64(tcg_flags, tcg_vn, tcg_vm, fpst); | ||
102 | + } else { | ||
103 | + gen_helper_vfp_cmps_a64(tcg_flags, tcg_vn, tcg_vm, fpst); | ||
104 | + } | ||
105 | + break; | ||
106 | + case MO_16: | ||
107 | + if (signal_all_nans) { | ||
108 | + gen_helper_vfp_cmpeh_a64(tcg_flags, tcg_vn, tcg_vm, fpst); | ||
109 | + } else { | ||
110 | + gen_helper_vfp_cmph_a64(tcg_flags, tcg_vn, tcg_vm, fpst); | ||
111 | + } | ||
112 | + break; | ||
113 | + default: | ||
114 | + g_assert_not_reached(); | ||
115 | } | ||
116 | + | ||
117 | tcg_temp_free_i32(tcg_vn); | ||
118 | tcg_temp_free_i32(tcg_vm); | ||
119 | } | ||
120 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_compare(DisasContext *s, bool is_double, | ||
121 | static void disas_fp_compare(DisasContext *s, uint32_t insn) | ||
122 | { | ||
123 | unsigned int mos, type, rm, op, rn, opc, op2r; | ||
124 | + int size; | ||
125 | |||
126 | mos = extract32(insn, 29, 3); | ||
127 | - type = extract32(insn, 22, 2); /* 0 = single, 1 = double */ | ||
128 | + type = extract32(insn, 22, 2); | ||
129 | rm = extract32(insn, 16, 5); | ||
130 | op = extract32(insn, 14, 2); | ||
131 | rn = extract32(insn, 5, 5); | ||
132 | opc = extract32(insn, 3, 2); | ||
133 | op2r = extract32(insn, 0, 3); | ||
134 | |||
135 | - if (mos || op || op2r || type > 1) { | ||
136 | + if (mos || op || op2r) { | ||
137 | + unallocated_encoding(s); | ||
138 | + return; | 124 | + return; |
139 | + } | 125 | + } |
140 | + | 126 | + |
141 | + switch (type) { | 127 | + r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CTL_EL0, &ctl); |
142 | + case 0: | 128 | + assert_hvf_ok(r); |
143 | + size = MO_32; | 129 | + |
144 | + break; | 130 | + if (!(ctl & 1) || (ctl & 2)) { |
145 | + case 1: | 131 | + /* Timer disabled or masked, just wait for an IPI. */ |
146 | + size = MO_64; | 132 | + hvf_wait_for_ipi(cpu, NULL); |
147 | + break; | ||
148 | + case 3: | ||
149 | + size = MO_16; | ||
150 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
151 | + break; | ||
152 | + } | ||
153 | + /* fallthru */ | ||
154 | + default: | ||
155 | unallocated_encoding(s); | ||
156 | return; | ||
157 | } | ||
158 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_compare(DisasContext *s, uint32_t insn) | ||
159 | return; | ||
160 | } | ||
161 | |||
162 | - handle_fp_compare(s, type, rn, rm, opc & 1, opc & 2); | ||
163 | + handle_fp_compare(s, size, rn, rm, opc & 1, opc & 2); | ||
164 | } | ||
165 | |||
166 | /* Floating point conditional compare | ||
167 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn) | ||
168 | unsigned int mos, type, rm, cond, rn, op, nzcv; | ||
169 | TCGv_i64 tcg_flags; | ||
170 | TCGLabel *label_continue = NULL; | ||
171 | + int size; | ||
172 | |||
173 | mos = extract32(insn, 29, 3); | ||
174 | - type = extract32(insn, 22, 2); /* 0 = single, 1 = double */ | ||
175 | + type = extract32(insn, 22, 2); | ||
176 | rm = extract32(insn, 16, 5); | ||
177 | cond = extract32(insn, 12, 4); | ||
178 | rn = extract32(insn, 5, 5); | ||
179 | op = extract32(insn, 4, 1); | ||
180 | nzcv = extract32(insn, 0, 4); | ||
181 | |||
182 | - if (mos || type > 1) { | ||
183 | + if (mos) { | ||
184 | + unallocated_encoding(s); | ||
185 | + return; | 133 | + return; |
186 | + } | 134 | + } |
187 | + | 135 | + |
188 | + switch (type) { | 136 | + r = hv_vcpu_get_sys_reg(cpu->hvf->fd, HV_SYS_REG_CNTV_CVAL_EL0, &cval); |
189 | + case 0: | 137 | + assert_hvf_ok(r); |
190 | + size = MO_32; | 138 | + |
191 | + break; | 139 | + ticks_to_sleep = cval - hvf_vtimer_val(); |
192 | + case 1: | 140 | + if (ticks_to_sleep < 0) { |
193 | + size = MO_64; | 141 | + return; |
194 | + break; | 142 | + } |
195 | + case 3: | 143 | + |
196 | + size = MO_16; | 144 | + cntfrq = gt_cntfrq_period_ns(arm_cpu); |
197 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 145 | + seconds = muldiv64(ticks_to_sleep, cntfrq, NANOSECONDS_PER_SECOND); |
198 | + break; | 146 | + ticks_to_sleep -= muldiv64(seconds, NANOSECONDS_PER_SECOND, cntfrq); |
147 | + nanos = ticks_to_sleep * cntfrq; | ||
148 | + | ||
149 | + /* | ||
150 | + * Don't sleep for less than the time a context switch would take, | ||
151 | + * so that we can satisfy fast timer requests on the same CPU. | ||
152 | + * Measurements on M1 show the sweet spot to be ~2ms. | ||
153 | + */ | ||
154 | + if (!seconds && nanos < (2 * SCALE_MS)) { | ||
155 | + return; | ||
156 | + } | ||
157 | + | ||
158 | + ts = (struct timespec) { seconds, nanos }; | ||
159 | + hvf_wait_for_ipi(cpu, &ts); | ||
160 | +} | ||
161 | + | ||
162 | static void hvf_sync_vtimer(CPUState *cpu) | ||
163 | { | ||
164 | ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
165 | @@ -XXX,XX +XXX,XX @@ int hvf_vcpu_exec(CPUState *cpu) | ||
166 | } | ||
167 | case EC_WFX_TRAP: | ||
168 | advance_pc = true; | ||
169 | + if (!(syndrome & WFX_IS_WFE)) { | ||
170 | + hvf_wfi(cpu); | ||
199 | + } | 171 | + } |
200 | + /* fallthru */ | 172 | break; |
201 | + default: | 173 | case EC_AA64_HVC: |
202 | unallocated_encoding(s); | 174 | cpu_synchronize_state(cpu); |
203 | return; | ||
204 | } | ||
205 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn) | ||
206 | gen_set_label(label_match); | ||
207 | } | ||
208 | |||
209 | - handle_fp_compare(s, type, rn, rm, false, op); | ||
210 | + handle_fp_compare(s, size, rn, rm, false, op); | ||
211 | |||
212 | if (cond < 0x0e) { | ||
213 | gen_set_label(label_continue); | ||
214 | -- | 175 | -- |
215 | 2.17.0 | 176 | 2.20.1 |
216 | 177 | ||
217 | 178 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Now that we have working system register sync, we push more target CPU | |
2 | properties into the virtual machine. That might be useful in some | ||
3 | situations, but is not the typical case that users want. | ||
4 | |||
5 | So let's add a -cpu host option that allows them to explicitly pass all | ||
6 | CPU capabilities of their host CPU into the guest. | ||
7 | |||
8 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | ||
9 | Acked-by: Roman Bolshakov <r.bolshakov@yadro.com> | ||
10 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Message-id: 20210916155404.86958-7-agraf@csgraf.de | ||
13 | [PMM: drop unnecessary #include line from .h file] | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | --- | ||
16 | target/arm/cpu.h | 2 + | ||
17 | target/arm/hvf_arm.h | 18 +++++++++ | ||
18 | target/arm/kvm_arm.h | 2 - | ||
19 | target/arm/cpu.c | 13 ++++-- | ||
20 | target/arm/hvf/hvf.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ | ||
21 | 5 files changed, 124 insertions(+), 6 deletions(-) | ||
22 | create mode 100644 target/arm/hvf_arm.h | ||
23 | |||
24 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/arm/cpu.h | ||
27 | +++ b/target/arm/cpu.h | ||
28 | @@ -XXX,XX +XXX,XX @@ bool write_cpustate_to_list(ARMCPU *cpu, bool kvm_sync); | ||
29 | #define ARM_CPU_TYPE_NAME(name) (name ARM_CPU_TYPE_SUFFIX) | ||
30 | #define CPU_RESOLVING_TYPE TYPE_ARM_CPU | ||
31 | |||
32 | +#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU | ||
33 | + | ||
34 | #define cpu_signal_handler cpu_arm_signal_handler | ||
35 | #define cpu_list arm_cpu_list | ||
36 | |||
37 | diff --git a/target/arm/hvf_arm.h b/target/arm/hvf_arm.h | ||
38 | new file mode 100644 | ||
39 | index XXXXXXX..XXXXXXX | ||
40 | --- /dev/null | ||
41 | +++ b/target/arm/hvf_arm.h | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | +/* | ||
44 | + * QEMU Hypervisor.framework (HVF) support -- ARM specifics | ||
45 | + * | ||
46 | + * Copyright (c) 2021 Alexander Graf | ||
47 | + * | ||
48 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
49 | + * See the COPYING file in the top-level directory. | ||
50 | + * | ||
51 | + */ | ||
52 | + | ||
53 | +#ifndef QEMU_HVF_ARM_H | ||
54 | +#define QEMU_HVF_ARM_H | ||
55 | + | ||
56 | +#include "cpu.h" | ||
57 | + | ||
58 | +void hvf_arm_set_cpu_features_from_host(struct ARMCPU *cpu); | ||
59 | + | ||
60 | +#endif | ||
61 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/target/arm/kvm_arm.h | ||
64 | +++ b/target/arm/kvm_arm.h | ||
65 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, | ||
66 | */ | ||
67 | void kvm_arm_destroy_scratch_host_vcpu(int *fdarray); | ||
68 | |||
69 | -#define TYPE_ARM_HOST_CPU "host-" TYPE_ARM_CPU | ||
70 | - | ||
71 | /** | ||
72 | * ARMHostCPUFeatures: information about the host CPU (identified | ||
73 | * by asking the host kernel) | ||
74 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/target/arm/cpu.c | ||
77 | +++ b/target/arm/cpu.c | ||
78 | @@ -XXX,XX +XXX,XX @@ | ||
79 | #include "sysemu/tcg.h" | ||
80 | #include "sysemu/hw_accel.h" | ||
81 | #include "kvm_arm.h" | ||
82 | +#include "hvf_arm.h" | ||
83 | #include "disas/capstone.h" | ||
84 | #include "fpu/softfloat.h" | ||
85 | |||
86 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | ||
87 | * this is the first point where we can report it. | ||
88 | */ | ||
89 | if (cpu->host_cpu_probe_failed) { | ||
90 | - if (!kvm_enabled()) { | ||
91 | - error_setg(errp, "The 'host' CPU type can only be used with KVM"); | ||
92 | + if (!kvm_enabled() && !hvf_enabled()) { | ||
93 | + error_setg(errp, "The 'host' CPU type can only be used with KVM or HVF"); | ||
94 | } else { | ||
95 | error_setg(errp, "Failed to retrieve host CPU features"); | ||
96 | } | ||
97 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) | ||
98 | #endif /* CONFIG_TCG */ | ||
99 | } | ||
100 | |||
101 | -#ifdef CONFIG_KVM | ||
102 | +#if defined(CONFIG_KVM) || defined(CONFIG_HVF) | ||
103 | static void arm_host_initfn(Object *obj) | ||
104 | { | ||
105 | ARMCPU *cpu = ARM_CPU(obj); | ||
106 | |||
107 | +#ifdef CONFIG_KVM | ||
108 | kvm_arm_set_cpu_features_from_host(cpu); | ||
109 | if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { | ||
110 | aarch64_add_sve_properties(obj); | ||
111 | } | ||
112 | +#else | ||
113 | + hvf_arm_set_cpu_features_from_host(cpu); | ||
114 | +#endif | ||
115 | arm_cpu_post_init(obj); | ||
116 | } | ||
117 | |||
118 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_register_types(void) | ||
119 | { | ||
120 | type_register_static(&arm_cpu_type_info); | ||
121 | |||
122 | -#ifdef CONFIG_KVM | ||
123 | +#if defined(CONFIG_KVM) || defined(CONFIG_HVF) | ||
124 | type_register_static(&host_arm_cpu_type_info); | ||
125 | #endif | ||
126 | } | ||
127 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | ||
128 | index XXXXXXX..XXXXXXX 100644 | ||
129 | --- a/target/arm/hvf/hvf.c | ||
130 | +++ b/target/arm/hvf/hvf.c | ||
131 | @@ -XXX,XX +XXX,XX @@ | ||
132 | #include "sysemu/hvf.h" | ||
133 | #include "sysemu/hvf_int.h" | ||
134 | #include "sysemu/hw_accel.h" | ||
135 | +#include "hvf_arm.h" | ||
136 | |||
137 | #include <mach/mach_time.h> | ||
138 | |||
139 | @@ -XXX,XX +XXX,XX @@ typedef struct HVFVTimer { | ||
140 | |||
141 | static HVFVTimer vtimer; | ||
142 | |||
143 | +typedef struct ARMHostCPUFeatures { | ||
144 | + ARMISARegisters isar; | ||
145 | + uint64_t features; | ||
146 | + uint64_t midr; | ||
147 | + uint32_t reset_sctlr; | ||
148 | + const char *dtb_compatible; | ||
149 | +} ARMHostCPUFeatures; | ||
150 | + | ||
151 | +static ARMHostCPUFeatures arm_host_cpu_features; | ||
152 | + | ||
153 | struct hvf_reg_match { | ||
154 | int reg; | ||
155 | uint64_t offset; | ||
156 | @@ -XXX,XX +XXX,XX @@ static uint64_t hvf_get_reg(CPUState *cpu, int rt) | ||
157 | return val; | ||
158 | } | ||
159 | |||
160 | +static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) | ||
161 | +{ | ||
162 | + ARMISARegisters host_isar = {}; | ||
163 | + const struct isar_regs { | ||
164 | + int reg; | ||
165 | + uint64_t *val; | ||
166 | + } regs[] = { | ||
167 | + { HV_SYS_REG_ID_AA64PFR0_EL1, &host_isar.id_aa64pfr0 }, | ||
168 | + { HV_SYS_REG_ID_AA64PFR1_EL1, &host_isar.id_aa64pfr1 }, | ||
169 | + { HV_SYS_REG_ID_AA64DFR0_EL1, &host_isar.id_aa64dfr0 }, | ||
170 | + { HV_SYS_REG_ID_AA64DFR1_EL1, &host_isar.id_aa64dfr1 }, | ||
171 | + { HV_SYS_REG_ID_AA64ISAR0_EL1, &host_isar.id_aa64isar0 }, | ||
172 | + { HV_SYS_REG_ID_AA64ISAR1_EL1, &host_isar.id_aa64isar1 }, | ||
173 | + { HV_SYS_REG_ID_AA64MMFR0_EL1, &host_isar.id_aa64mmfr0 }, | ||
174 | + { HV_SYS_REG_ID_AA64MMFR1_EL1, &host_isar.id_aa64mmfr1 }, | ||
175 | + { HV_SYS_REG_ID_AA64MMFR2_EL1, &host_isar.id_aa64mmfr2 }, | ||
176 | + }; | ||
177 | + hv_vcpu_t fd; | ||
178 | + hv_return_t r = HV_SUCCESS; | ||
179 | + hv_vcpu_exit_t *exit; | ||
180 | + int i; | ||
181 | + | ||
182 | + ahcf->dtb_compatible = "arm,arm-v8"; | ||
183 | + ahcf->features = (1ULL << ARM_FEATURE_V8) | | ||
184 | + (1ULL << ARM_FEATURE_NEON) | | ||
185 | + (1ULL << ARM_FEATURE_AARCH64) | | ||
186 | + (1ULL << ARM_FEATURE_PMU) | | ||
187 | + (1ULL << ARM_FEATURE_GENERIC_TIMER); | ||
188 | + | ||
189 | + /* We set up a small vcpu to extract host registers */ | ||
190 | + | ||
191 | + if (hv_vcpu_create(&fd, &exit, NULL) != HV_SUCCESS) { | ||
192 | + return false; | ||
193 | + } | ||
194 | + | ||
195 | + for (i = 0; i < ARRAY_SIZE(regs); i++) { | ||
196 | + r |= hv_vcpu_get_sys_reg(fd, regs[i].reg, regs[i].val); | ||
197 | + } | ||
198 | + r |= hv_vcpu_get_sys_reg(fd, HV_SYS_REG_MIDR_EL1, &ahcf->midr); | ||
199 | + r |= hv_vcpu_destroy(fd); | ||
200 | + | ||
201 | + ahcf->isar = host_isar; | ||
202 | + | ||
203 | + /* | ||
204 | + * A scratch vCPU returns SCTLR 0, so let's fill our default with the M1 | ||
205 | + * boot SCTLR from https://github.com/AsahiLinux/m1n1/issues/97 | ||
206 | + */ | ||
207 | + ahcf->reset_sctlr = 0x30100180; | ||
208 | + /* | ||
209 | + * SPAN is disabled by default when SCTLR.SPAN=1. To improve compatibility, | ||
210 | + * let's disable it on boot and then allow guest software to turn it on by | ||
211 | + * setting it to 0. | ||
212 | + */ | ||
213 | + ahcf->reset_sctlr |= 0x00800000; | ||
214 | + | ||
215 | + /* Make sure we don't advertise AArch32 support for EL0/EL1 */ | ||
216 | + if ((host_isar.id_aa64pfr0 & 0xff) != 0x11) { | ||
217 | + return false; | ||
218 | + } | ||
219 | + | ||
220 | + return r == HV_SUCCESS; | ||
221 | +} | ||
222 | + | ||
223 | +void hvf_arm_set_cpu_features_from_host(ARMCPU *cpu) | ||
224 | +{ | ||
225 | + if (!arm_host_cpu_features.dtb_compatible) { | ||
226 | + if (!hvf_enabled() || | ||
227 | + !hvf_arm_get_host_cpu_features(&arm_host_cpu_features)) { | ||
228 | + /* | ||
229 | + * We can't report this error yet, so flag that we need to | ||
230 | + * in arm_cpu_realizefn(). | ||
231 | + */ | ||
232 | + cpu->host_cpu_probe_failed = true; | ||
233 | + return; | ||
234 | + } | ||
235 | + } | ||
236 | + | ||
237 | + cpu->dtb_compatible = arm_host_cpu_features.dtb_compatible; | ||
238 | + cpu->isar = arm_host_cpu_features.isar; | ||
239 | + cpu->env.features = arm_host_cpu_features.features; | ||
240 | + cpu->midr = arm_host_cpu_features.midr; | ||
241 | + cpu->reset_sctlr = arm_host_cpu_features.reset_sctlr; | ||
242 | +} | ||
243 | + | ||
244 | void hvf_arch_vcpu_destroy(CPUState *cpu) | ||
245 | { | ||
246 | } | ||
247 | -- | ||
248 | 2.20.1 | ||
249 | |||
250 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Alexander Graf <agraf@csgraf.de> |
---|---|---|---|
2 | 2 | ||
3 | We missed all of the scalar fp16 binary operations. | 3 | We need to handle PSCI calls. Most of the TCG code works for us, |
4 | 4 | but we can simplify it to only handle aa64 mode and we need to | |
5 | Cc: qemu-stable@nongnu.org | 5 | handle SUSPEND differently. |
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 6 | |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | This patch takes the TCG code as template and duplicates it in HVF. |
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 8 | |
9 | Message-id: 20180512003217.9105-7-richard.henderson@linaro.org | 9 | To tell the guest that we support PSCI 0.2 now, update the check in |
10 | arm_cpu_initfn() as well. | ||
11 | |||
12 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | ||
13 | Reviewed-by: Sergio Lopez <slp@redhat.com> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Message-id: 20210916155404.86958-8-agraf@csgraf.de | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 17 | --- |
12 | target/arm/translate-a64.c | 65 ++++++++++++++++++++++++++++++++++++++ | 18 | target/arm/cpu.c | 4 +- |
13 | 1 file changed, 65 insertions(+) | 19 | target/arm/hvf/hvf.c | 141 ++++++++++++++++++++++++++++++++++-- |
14 | 20 | target/arm/hvf/trace-events | 1 + | |
15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 21 | 3 files changed, 139 insertions(+), 7 deletions(-) |
22 | |||
23 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate-a64.c | 25 | --- a/target/arm/cpu.c |
18 | +++ b/target/arm/translate-a64.c | 26 | +++ b/target/arm/cpu.c |
19 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_2src_double(DisasContext *s, int opcode, | 27 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_initfn(Object *obj) |
20 | tcg_temp_free_i64(tcg_res); | 28 | cpu->psci_version = 1; /* By default assume PSCI v0.1 */ |
29 | cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE; | ||
30 | |||
31 | - if (tcg_enabled()) { | ||
32 | - cpu->psci_version = 2; /* TCG implements PSCI 0.2 */ | ||
33 | + if (tcg_enabled() || hvf_enabled()) { | ||
34 | + cpu->psci_version = 2; /* TCG and HVF implement PSCI 0.2 */ | ||
35 | } | ||
21 | } | 36 | } |
22 | 37 | ||
23 | +/* Floating-point data-processing (2 source) - half precision */ | 38 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c |
24 | +static void handle_fp_2src_half(DisasContext *s, int opcode, | 39 | index XXXXXXX..XXXXXXX 100644 |
25 | + int rd, int rn, int rm) | 40 | --- a/target/arm/hvf/hvf.c |
41 | +++ b/target/arm/hvf/hvf.c | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | #include "hw/irq.h" | ||
44 | #include "qemu/main-loop.h" | ||
45 | #include "sysemu/cpus.h" | ||
46 | +#include "arm-powerctl.h" | ||
47 | #include "target/arm/cpu.h" | ||
48 | #include "target/arm/internals.h" | ||
49 | #include "trace/trace-target_arm_hvf.h" | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | #define TMR_CTL_IMASK (1 << 1) | ||
52 | #define TMR_CTL_ISTATUS (1 << 2) | ||
53 | |||
54 | +static void hvf_wfi(CPUState *cpu); | ||
55 | + | ||
56 | typedef struct HVFVTimer { | ||
57 | /* Vtimer value during migration and paused state */ | ||
58 | uint64_t vtimer_val; | ||
59 | @@ -XXX,XX +XXX,XX @@ static void hvf_raise_exception(CPUState *cpu, uint32_t excp, | ||
60 | arm_cpu_do_interrupt(cpu); | ||
61 | } | ||
62 | |||
63 | +static void hvf_psci_cpu_off(ARMCPU *arm_cpu) | ||
26 | +{ | 64 | +{ |
27 | + TCGv_i32 tcg_op1; | 65 | + int32_t ret = arm_set_cpu_off(arm_cpu->mp_affinity); |
28 | + TCGv_i32 tcg_op2; | 66 | + assert(ret == QEMU_ARM_POWERCTL_RET_SUCCESS); |
29 | + TCGv_i32 tcg_res; | 67 | +} |
30 | + TCGv_ptr fpst; | 68 | + |
31 | + | 69 | +/* |
32 | + tcg_res = tcg_temp_new_i32(); | 70 | + * Handle a PSCI call. |
33 | + fpst = get_fpstatus_ptr(true); | 71 | + * |
34 | + tcg_op1 = read_fp_hreg(s, rn); | 72 | + * Returns 0 on success |
35 | + tcg_op2 = read_fp_hreg(s, rm); | 73 | + * -1 when the PSCI call is unknown, |
36 | + | 74 | + */ |
37 | + switch (opcode) { | 75 | +static bool hvf_handle_psci_call(CPUState *cpu) |
38 | + case 0x0: /* FMUL */ | 76 | +{ |
39 | + gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst); | 77 | + ARMCPU *arm_cpu = ARM_CPU(cpu); |
40 | + break; | 78 | + CPUARMState *env = &arm_cpu->env; |
41 | + case 0x1: /* FDIV */ | 79 | + uint64_t param[4] = { |
42 | + gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst); | 80 | + env->xregs[0], |
43 | + break; | 81 | + env->xregs[1], |
44 | + case 0x2: /* FADD */ | 82 | + env->xregs[2], |
45 | + gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst); | 83 | + env->xregs[3] |
46 | + break; | 84 | + }; |
47 | + case 0x3: /* FSUB */ | 85 | + uint64_t context_id, mpidr; |
48 | + gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst); | 86 | + bool target_aarch64 = true; |
49 | + break; | 87 | + CPUState *target_cpu_state; |
50 | + case 0x4: /* FMAX */ | 88 | + ARMCPU *target_cpu; |
51 | + gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst); | 89 | + target_ulong entry; |
52 | + break; | 90 | + int target_el = 1; |
53 | + case 0x5: /* FMIN */ | 91 | + int32_t ret = 0; |
54 | + gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst); | 92 | + |
55 | + break; | 93 | + trace_hvf_psci_call(param[0], param[1], param[2], param[3], |
56 | + case 0x6: /* FMAXNM */ | 94 | + arm_cpu->mp_affinity); |
57 | + gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst); | 95 | + |
58 | + break; | 96 | + switch (param[0]) { |
59 | + case 0x7: /* FMINNM */ | 97 | + case QEMU_PSCI_0_2_FN_PSCI_VERSION: |
60 | + gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst); | 98 | + ret = QEMU_PSCI_0_2_RET_VERSION_0_2; |
61 | + break; | 99 | + break; |
62 | + case 0x8: /* FNMUL */ | 100 | + case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE: |
63 | + gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst); | 101 | + ret = QEMU_PSCI_0_2_RET_TOS_MIGRATION_NOT_REQUIRED; /* No trusted OS */ |
64 | + tcg_gen_xori_i32(tcg_res, tcg_res, 0x8000); | 102 | + break; |
103 | + case QEMU_PSCI_0_2_FN_AFFINITY_INFO: | ||
104 | + case QEMU_PSCI_0_2_FN64_AFFINITY_INFO: | ||
105 | + mpidr = param[1]; | ||
106 | + | ||
107 | + switch (param[2]) { | ||
108 | + case 0: | ||
109 | + target_cpu_state = arm_get_cpu_by_id(mpidr); | ||
110 | + if (!target_cpu_state) { | ||
111 | + ret = QEMU_PSCI_RET_INVALID_PARAMS; | ||
112 | + break; | ||
113 | + } | ||
114 | + target_cpu = ARM_CPU(target_cpu_state); | ||
115 | + | ||
116 | + ret = target_cpu->power_state; | ||
117 | + break; | ||
118 | + default: | ||
119 | + /* Everything above affinity level 0 is always on. */ | ||
120 | + ret = 0; | ||
121 | + } | ||
122 | + break; | ||
123 | + case QEMU_PSCI_0_2_FN_SYSTEM_RESET: | ||
124 | + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); | ||
125 | + /* | ||
126 | + * QEMU reset and shutdown are async requests, but PSCI | ||
127 | + * mandates that we never return from the reset/shutdown | ||
128 | + * call, so power the CPU off now so it doesn't execute | ||
129 | + * anything further. | ||
130 | + */ | ||
131 | + hvf_psci_cpu_off(arm_cpu); | ||
132 | + break; | ||
133 | + case QEMU_PSCI_0_2_FN_SYSTEM_OFF: | ||
134 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | ||
135 | + hvf_psci_cpu_off(arm_cpu); | ||
136 | + break; | ||
137 | + case QEMU_PSCI_0_1_FN_CPU_ON: | ||
138 | + case QEMU_PSCI_0_2_FN_CPU_ON: | ||
139 | + case QEMU_PSCI_0_2_FN64_CPU_ON: | ||
140 | + mpidr = param[1]; | ||
141 | + entry = param[2]; | ||
142 | + context_id = param[3]; | ||
143 | + ret = arm_set_cpu_on(mpidr, entry, context_id, | ||
144 | + target_el, target_aarch64); | ||
145 | + break; | ||
146 | + case QEMU_PSCI_0_1_FN_CPU_OFF: | ||
147 | + case QEMU_PSCI_0_2_FN_CPU_OFF: | ||
148 | + hvf_psci_cpu_off(arm_cpu); | ||
149 | + break; | ||
150 | + case QEMU_PSCI_0_1_FN_CPU_SUSPEND: | ||
151 | + case QEMU_PSCI_0_2_FN_CPU_SUSPEND: | ||
152 | + case QEMU_PSCI_0_2_FN64_CPU_SUSPEND: | ||
153 | + /* Affinity levels are not supported in QEMU */ | ||
154 | + if (param[1] & 0xfffe0000) { | ||
155 | + ret = QEMU_PSCI_RET_INVALID_PARAMS; | ||
156 | + break; | ||
157 | + } | ||
158 | + /* Powerdown is not supported, we always go into WFI */ | ||
159 | + env->xregs[0] = 0; | ||
160 | + hvf_wfi(cpu); | ||
161 | + break; | ||
162 | + case QEMU_PSCI_0_1_FN_MIGRATE: | ||
163 | + case QEMU_PSCI_0_2_FN_MIGRATE: | ||
164 | + ret = QEMU_PSCI_RET_NOT_SUPPORTED; | ||
65 | + break; | 165 | + break; |
66 | + default: | 166 | + default: |
67 | + g_assert_not_reached(); | 167 | + return false; |
68 | + } | 168 | + } |
69 | + | 169 | + |
70 | + write_fp_sreg(s, rd, tcg_res); | 170 | + env->xregs[0] = ret; |
71 | + | 171 | + return true; |
72 | + tcg_temp_free_ptr(fpst); | ||
73 | + tcg_temp_free_i32(tcg_op1); | ||
74 | + tcg_temp_free_i32(tcg_op2); | ||
75 | + tcg_temp_free_i32(tcg_res); | ||
76 | +} | 172 | +} |
77 | + | 173 | + |
78 | /* Floating point data-processing (2 source) | 174 | static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint32_t rt) |
79 | * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0 | 175 | { |
80 | * +---+---+---+-----------+------+---+------+--------+-----+------+------+ | 176 | ARMCPU *arm_cpu = ARM_CPU(cpu); |
81 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_2src(DisasContext *s, uint32_t insn) | 177 | @@ -XXX,XX +XXX,XX @@ int hvf_vcpu_exec(CPUState *cpu) |
82 | } | ||
83 | handle_fp_2src_double(s, opcode, rd, rn, rm); | ||
84 | break; | 178 | break; |
85 | + case 3: | 179 | case EC_AA64_HVC: |
86 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 180 | cpu_synchronize_state(cpu); |
87 | + unallocated_encoding(s); | 181 | - trace_hvf_unknown_hvc(env->xregs[0]); |
88 | + return; | 182 | - /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */ |
89 | + } | 183 | - env->xregs[0] = -1; |
90 | + if (!fp_access_check(s)) { | 184 | + if (arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_HVC) { |
91 | + return; | 185 | + if (!hvf_handle_psci_call(cpu)) { |
92 | + } | 186 | + trace_hvf_unknown_hvc(env->xregs[0]); |
93 | + handle_fp_2src_half(s, opcode, rd, rn, rm); | 187 | + /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */ |
94 | + break; | 188 | + env->xregs[0] = -1; |
189 | + } | ||
190 | + } else { | ||
191 | + trace_hvf_unknown_hvc(env->xregs[0]); | ||
192 | + hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized()); | ||
193 | + } | ||
194 | break; | ||
195 | case EC_AA64_SMC: | ||
196 | cpu_synchronize_state(cpu); | ||
197 | - trace_hvf_unknown_smc(env->xregs[0]); | ||
198 | - hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized()); | ||
199 | + if (arm_cpu->psci_conduit == QEMU_PSCI_CONDUIT_SMC) { | ||
200 | + advance_pc = true; | ||
201 | + | ||
202 | + if (!hvf_handle_psci_call(cpu)) { | ||
203 | + trace_hvf_unknown_smc(env->xregs[0]); | ||
204 | + /* SMCCC 1.3 section 5.2 says every unknown SMCCC call returns -1 */ | ||
205 | + env->xregs[0] = -1; | ||
206 | + } | ||
207 | + } else { | ||
208 | + trace_hvf_unknown_smc(env->xregs[0]); | ||
209 | + hvf_raise_exception(cpu, EXCP_UDEF, syn_uncategorized()); | ||
210 | + } | ||
211 | break; | ||
95 | default: | 212 | default: |
96 | unallocated_encoding(s); | 213 | cpu_synchronize_state(cpu); |
97 | } | 214 | diff --git a/target/arm/hvf/trace-events b/target/arm/hvf/trace-events |
215 | index XXXXXXX..XXXXXXX 100644 | ||
216 | --- a/target/arm/hvf/trace-events | ||
217 | +++ b/target/arm/hvf/trace-events | ||
218 | @@ -XXX,XX +XXX,XX @@ hvf_sysreg_write(uint32_t reg, uint32_t op0, uint32_t op1, uint32_t crn, uint32_ | ||
219 | hvf_unknown_hvc(uint64_t x0) "unknown HVC! 0x%016"PRIx64 | ||
220 | hvf_unknown_smc(uint64_t x0) "unknown SMC! 0x%016"PRIx64 | ||
221 | hvf_exit(uint64_t syndrome, uint32_t ec, uint64_t pc) "exit: 0x%"PRIx64" [ec=0x%x pc=0x%"PRIx64"]" | ||
222 | +hvf_psci_call(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3, uint32_t cpuid) "PSCI Call x0=0x%016"PRIx64" x1=0x%016"PRIx64" x2=0x%016"PRIx64" x3=0x%016"PRIx64" cpu=0x%x" | ||
98 | -- | 223 | -- |
99 | 2.17.0 | 224 | 2.20.1 |
100 | 225 | ||
101 | 226 | diff view generated by jsdifflib |
1 | From: Alex Bennée <alex.bennee@linaro.org> | 1 | From: Alexander Graf <agraf@csgraf.de> |
---|---|---|---|
2 | 2 | ||
3 | We are meant to explicitly pass fpst, not cpu_env. | 3 | Now that we have all logic in place that we need to handle Hypervisor.framework |
4 | on Apple Silicon systems, let's add CONFIG_HVF for aarch64 as well so that we | ||
5 | can build it. | ||
4 | 6 | ||
5 | Cc: qemu-stable@nongnu.org | 7 | Signed-off-by: Alexander Graf <agraf@csgraf.de> |
6 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | 8 | Reviewed-by: Roman Bolshakov <r.bolshakov@yadro.com> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Tested-by: Roman Bolshakov <r.bolshakov@yadro.com> (x86 only) |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | 11 | Reviewed-by: Sergio Lopez <slp@redhat.com> |
10 | Message-id: 20180512003217.9105-12-richard.henderson@linaro.org | 12 | Message-id: 20210916155404.86958-9-agraf@csgraf.de |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 14 | --- |
13 | target/arm/translate-a64.c | 3 ++- | 15 | meson.build | 7 +++++++ |
14 | 1 file changed, 2 insertions(+), 1 deletion(-) | 16 | target/arm/hvf/meson.build | 3 +++ |
17 | target/arm/meson.build | 2 ++ | ||
18 | 3 files changed, 12 insertions(+) | ||
19 | create mode 100644 target/arm/hvf/meson.build | ||
15 | 20 | ||
16 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 21 | diff --git a/meson.build b/meson.build |
17 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/translate-a64.c | 23 | --- a/meson.build |
19 | +++ b/target/arm/translate-a64.c | 24 | +++ b/meson.build |
20 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn) | 25 | @@ -XXX,XX +XXX,XX @@ else |
21 | tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000); | 26 | endif |
22 | break; | 27 | |
23 | case 0x3: /* FSQRT */ | 28 | accelerator_targets = { 'CONFIG_KVM': kvm_targets } |
24 | - gen_helper_sqrt_f16(tcg_res, tcg_op, cpu_env); | 29 | + |
25 | + fpst = get_fpstatus_ptr(true); | 30 | +if cpu in ['aarch64'] |
26 | + gen_helper_sqrt_f16(tcg_res, tcg_op, fpst); | 31 | + accelerator_targets += { |
27 | break; | 32 | + 'CONFIG_HVF': ['aarch64-softmmu'] |
28 | case 0x8: /* FRINTN */ | 33 | + } |
29 | case 0x9: /* FRINTP */ | 34 | +endif |
35 | + | ||
36 | if cpu in ['x86', 'x86_64', 'arm', 'aarch64'] | ||
37 | # i386 emulator provides xenpv machine type for multiple architectures | ||
38 | accelerator_targets += { | ||
39 | diff --git a/target/arm/hvf/meson.build b/target/arm/hvf/meson.build | ||
40 | new file mode 100644 | ||
41 | index XXXXXXX..XXXXXXX | ||
42 | --- /dev/null | ||
43 | +++ b/target/arm/hvf/meson.build | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | +arm_softmmu_ss.add(when: [hvf, 'CONFIG_HVF'], if_true: files( | ||
46 | + 'hvf.c', | ||
47 | +)) | ||
48 | diff --git a/target/arm/meson.build b/target/arm/meson.build | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/arm/meson.build | ||
51 | +++ b/target/arm/meson.build | ||
52 | @@ -XXX,XX +XXX,XX @@ arm_softmmu_ss.add(files( | ||
53 | 'psci.c', | ||
54 | )) | ||
55 | |||
56 | +subdir('hvf') | ||
57 | + | ||
58 | target_arch += {'arm': arm_ss} | ||
59 | target_softmmu_arch += {'arm': arm_softmmu_ss} | ||
30 | -- | 60 | -- |
31 | 2.17.0 | 61 | 2.20.1 |
32 | 62 | ||
33 | 63 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Alexander Graf <agraf@csgraf.de> | |
2 | |||
3 | We can expose cycle counters on the PMU easily. To be as compatible as | ||
4 | possible, let's do so, but make sure we don't expose any other architectural | ||
5 | counters that we can not model yet. | ||
6 | |||
7 | This allows OSs to work that require PMU support. | ||
8 | |||
9 | Signed-off-by: Alexander Graf <agraf@csgraf.de> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Message-id: 20210916155404.86958-10-agraf@csgraf.de | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | target/arm/hvf/hvf.c | 179 +++++++++++++++++++++++++++++++++++++++++++ | ||
15 | 1 file changed, 179 insertions(+) | ||
16 | |||
17 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/arm/hvf/hvf.c | ||
20 | +++ b/target/arm/hvf/hvf.c | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #define SYSREG_OSLSR_EL1 SYSREG(2, 0, 1, 1, 4) | ||
23 | #define SYSREG_OSDLR_EL1 SYSREG(2, 0, 1, 3, 4) | ||
24 | #define SYSREG_CNTPCT_EL0 SYSREG(3, 3, 14, 0, 1) | ||
25 | +#define SYSREG_PMCR_EL0 SYSREG(3, 3, 9, 12, 0) | ||
26 | +#define SYSREG_PMUSERENR_EL0 SYSREG(3, 3, 9, 14, 0) | ||
27 | +#define SYSREG_PMCNTENSET_EL0 SYSREG(3, 3, 9, 12, 1) | ||
28 | +#define SYSREG_PMCNTENCLR_EL0 SYSREG(3, 3, 9, 12, 2) | ||
29 | +#define SYSREG_PMINTENCLR_EL1 SYSREG(3, 0, 9, 14, 2) | ||
30 | +#define SYSREG_PMOVSCLR_EL0 SYSREG(3, 3, 9, 12, 3) | ||
31 | +#define SYSREG_PMSWINC_EL0 SYSREG(3, 3, 9, 12, 4) | ||
32 | +#define SYSREG_PMSELR_EL0 SYSREG(3, 3, 9, 12, 5) | ||
33 | +#define SYSREG_PMCEID0_EL0 SYSREG(3, 3, 9, 12, 6) | ||
34 | +#define SYSREG_PMCEID1_EL0 SYSREG(3, 3, 9, 12, 7) | ||
35 | +#define SYSREG_PMCCNTR_EL0 SYSREG(3, 3, 9, 13, 0) | ||
36 | +#define SYSREG_PMCCFILTR_EL0 SYSREG(3, 3, 14, 15, 7) | ||
37 | |||
38 | #define WFX_IS_WFE (1 << 0) | ||
39 | |||
40 | @@ -XXX,XX +XXX,XX @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint32_t rt) | ||
41 | val = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) / | ||
42 | gt_cntfrq_period_ns(arm_cpu); | ||
43 | break; | ||
44 | + case SYSREG_PMCR_EL0: | ||
45 | + val = env->cp15.c9_pmcr; | ||
46 | + break; | ||
47 | + case SYSREG_PMCCNTR_EL0: | ||
48 | + pmu_op_start(env); | ||
49 | + val = env->cp15.c15_ccnt; | ||
50 | + pmu_op_finish(env); | ||
51 | + break; | ||
52 | + case SYSREG_PMCNTENCLR_EL0: | ||
53 | + val = env->cp15.c9_pmcnten; | ||
54 | + break; | ||
55 | + case SYSREG_PMOVSCLR_EL0: | ||
56 | + val = env->cp15.c9_pmovsr; | ||
57 | + break; | ||
58 | + case SYSREG_PMSELR_EL0: | ||
59 | + val = env->cp15.c9_pmselr; | ||
60 | + break; | ||
61 | + case SYSREG_PMINTENCLR_EL1: | ||
62 | + val = env->cp15.c9_pminten; | ||
63 | + break; | ||
64 | + case SYSREG_PMCCFILTR_EL0: | ||
65 | + val = env->cp15.pmccfiltr_el0; | ||
66 | + break; | ||
67 | + case SYSREG_PMCNTENSET_EL0: | ||
68 | + val = env->cp15.c9_pmcnten; | ||
69 | + break; | ||
70 | + case SYSREG_PMUSERENR_EL0: | ||
71 | + val = env->cp15.c9_pmuserenr; | ||
72 | + break; | ||
73 | + case SYSREG_PMCEID0_EL0: | ||
74 | + case SYSREG_PMCEID1_EL0: | ||
75 | + /* We can't really count anything yet, declare all events invalid */ | ||
76 | + val = 0; | ||
77 | + break; | ||
78 | case SYSREG_OSLSR_EL1: | ||
79 | val = env->cp15.oslsr_el1; | ||
80 | break; | ||
81 | @@ -XXX,XX +XXX,XX @@ static int hvf_sysreg_read(CPUState *cpu, uint32_t reg, uint32_t rt) | ||
82 | return 0; | ||
83 | } | ||
84 | |||
85 | +static void pmu_update_irq(CPUARMState *env) | ||
86 | +{ | ||
87 | + ARMCPU *cpu = env_archcpu(env); | ||
88 | + qemu_set_irq(cpu->pmu_interrupt, (env->cp15.c9_pmcr & PMCRE) && | ||
89 | + (env->cp15.c9_pminten & env->cp15.c9_pmovsr)); | ||
90 | +} | ||
91 | + | ||
92 | +static bool pmu_event_supported(uint16_t number) | ||
93 | +{ | ||
94 | + return false; | ||
95 | +} | ||
96 | + | ||
97 | +/* Returns true if the counter (pass 31 for PMCCNTR) should count events using | ||
98 | + * the current EL, security state, and register configuration. | ||
99 | + */ | ||
100 | +static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) | ||
101 | +{ | ||
102 | + uint64_t filter; | ||
103 | + bool enabled, filtered = true; | ||
104 | + int el = arm_current_el(env); | ||
105 | + | ||
106 | + enabled = (env->cp15.c9_pmcr & PMCRE) && | ||
107 | + (env->cp15.c9_pmcnten & (1 << counter)); | ||
108 | + | ||
109 | + if (counter == 31) { | ||
110 | + filter = env->cp15.pmccfiltr_el0; | ||
111 | + } else { | ||
112 | + filter = env->cp15.c14_pmevtyper[counter]; | ||
113 | + } | ||
114 | + | ||
115 | + if (el == 0) { | ||
116 | + filtered = filter & PMXEVTYPER_U; | ||
117 | + } else if (el == 1) { | ||
118 | + filtered = filter & PMXEVTYPER_P; | ||
119 | + } | ||
120 | + | ||
121 | + if (counter != 31) { | ||
122 | + /* | ||
123 | + * If not checking PMCCNTR, ensure the counter is setup to an event we | ||
124 | + * support | ||
125 | + */ | ||
126 | + uint16_t event = filter & PMXEVTYPER_EVTCOUNT; | ||
127 | + if (!pmu_event_supported(event)) { | ||
128 | + return false; | ||
129 | + } | ||
130 | + } | ||
131 | + | ||
132 | + return enabled && !filtered; | ||
133 | +} | ||
134 | + | ||
135 | +static void pmswinc_write(CPUARMState *env, uint64_t value) | ||
136 | +{ | ||
137 | + unsigned int i; | ||
138 | + for (i = 0; i < pmu_num_counters(env); i++) { | ||
139 | + /* Increment a counter's count iff: */ | ||
140 | + if ((value & (1 << i)) && /* counter's bit is set */ | ||
141 | + /* counter is enabled and not filtered */ | ||
142 | + pmu_counter_enabled(env, i) && | ||
143 | + /* counter is SW_INCR */ | ||
144 | + (env->cp15.c14_pmevtyper[i] & PMXEVTYPER_EVTCOUNT) == 0x0) { | ||
145 | + /* | ||
146 | + * Detect if this write causes an overflow since we can't predict | ||
147 | + * PMSWINC overflows like we can for other events | ||
148 | + */ | ||
149 | + uint32_t new_pmswinc = env->cp15.c14_pmevcntr[i] + 1; | ||
150 | + | ||
151 | + if (env->cp15.c14_pmevcntr[i] & ~new_pmswinc & INT32_MIN) { | ||
152 | + env->cp15.c9_pmovsr |= (1 << i); | ||
153 | + pmu_update_irq(env); | ||
154 | + } | ||
155 | + | ||
156 | + env->cp15.c14_pmevcntr[i] = new_pmswinc; | ||
157 | + } | ||
158 | + } | ||
159 | +} | ||
160 | + | ||
161 | static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val) | ||
162 | { | ||
163 | ARMCPU *arm_cpu = ARM_CPU(cpu); | ||
164 | @@ -XXX,XX +XXX,XX @@ static int hvf_sysreg_write(CPUState *cpu, uint32_t reg, uint64_t val) | ||
165 | val); | ||
166 | |||
167 | switch (reg) { | ||
168 | + case SYSREG_PMCCNTR_EL0: | ||
169 | + pmu_op_start(env); | ||
170 | + env->cp15.c15_ccnt = val; | ||
171 | + pmu_op_finish(env); | ||
172 | + break; | ||
173 | + case SYSREG_PMCR_EL0: | ||
174 | + pmu_op_start(env); | ||
175 | + | ||
176 | + if (val & PMCRC) { | ||
177 | + /* The counter has been reset */ | ||
178 | + env->cp15.c15_ccnt = 0; | ||
179 | + } | ||
180 | + | ||
181 | + if (val & PMCRP) { | ||
182 | + unsigned int i; | ||
183 | + for (i = 0; i < pmu_num_counters(env); i++) { | ||
184 | + env->cp15.c14_pmevcntr[i] = 0; | ||
185 | + } | ||
186 | + } | ||
187 | + | ||
188 | + env->cp15.c9_pmcr &= ~PMCR_WRITEABLE_MASK; | ||
189 | + env->cp15.c9_pmcr |= (val & PMCR_WRITEABLE_MASK); | ||
190 | + | ||
191 | + pmu_op_finish(env); | ||
192 | + break; | ||
193 | + case SYSREG_PMUSERENR_EL0: | ||
194 | + env->cp15.c9_pmuserenr = val & 0xf; | ||
195 | + break; | ||
196 | + case SYSREG_PMCNTENSET_EL0: | ||
197 | + env->cp15.c9_pmcnten |= (val & pmu_counter_mask(env)); | ||
198 | + break; | ||
199 | + case SYSREG_PMCNTENCLR_EL0: | ||
200 | + env->cp15.c9_pmcnten &= ~(val & pmu_counter_mask(env)); | ||
201 | + break; | ||
202 | + case SYSREG_PMINTENCLR_EL1: | ||
203 | + pmu_op_start(env); | ||
204 | + env->cp15.c9_pminten |= val; | ||
205 | + pmu_op_finish(env); | ||
206 | + break; | ||
207 | + case SYSREG_PMOVSCLR_EL0: | ||
208 | + pmu_op_start(env); | ||
209 | + env->cp15.c9_pmovsr &= ~val; | ||
210 | + pmu_op_finish(env); | ||
211 | + break; | ||
212 | + case SYSREG_PMSWINC_EL0: | ||
213 | + pmu_op_start(env); | ||
214 | + pmswinc_write(env, val); | ||
215 | + pmu_op_finish(env); | ||
216 | + break; | ||
217 | + case SYSREG_PMSELR_EL0: | ||
218 | + env->cp15.c9_pmselr = val & 0x1f; | ||
219 | + break; | ||
220 | + case SYSREG_PMCCFILTR_EL0: | ||
221 | + pmu_op_start(env); | ||
222 | + env->cp15.pmccfiltr_el0 = val & PMCCFILTR_EL0; | ||
223 | + pmu_op_finish(env); | ||
224 | + break; | ||
225 | case SYSREG_OSLAR_EL1: | ||
226 | env->cp15.oslsr_el1 = val & 1; | ||
227 | break; | ||
228 | -- | ||
229 | 2.20.1 | ||
230 | |||
231 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Currently gen_jmp_tb() assumes that if it is called then the jump it | ||
2 | is handling is the only reason that we might be trying to end the TB, | ||
3 | so it will use goto_tb if it can. This is usually the case: mostly | ||
4 | "we did something that means we must end the TB" happens on a | ||
5 | non-branch instruction. However, there are cases where we decide | ||
6 | early in handling an instruction that we need to end the TB and | ||
7 | return to the main loop, and then the insn is a complex one that | ||
8 | involves gen_jmp_tb(). For instance, for M-profile FP instructions, | ||
9 | in gen_preserve_fp_state() which is called from vfp_access_check() we | ||
10 | want to force an exit to the main loop if lazy state preservation is | ||
11 | active and we are in icount mode. | ||
1 | 12 | ||
13 | Make gen_jmp_tb() look at the current value of is_jmp, and only use | ||
14 | goto_tb if the previous is_jmp was DISAS_NEXT or DISAS_TOO_MANY. | ||
15 | |||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
18 | Message-id: 20210913095440.13462-2-peter.maydell@linaro.org | ||
19 | --- | ||
20 | target/arm/translate.c | 34 +++++++++++++++++++++++++++++++++- | ||
21 | 1 file changed, 33 insertions(+), 1 deletion(-) | ||
22 | |||
23 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/target/arm/translate.c | ||
26 | +++ b/target/arm/translate.c | ||
27 | @@ -XXX,XX +XXX,XX @@ static inline void gen_jmp_tb(DisasContext *s, uint32_t dest, int tbno) | ||
28 | /* An indirect jump so that we still trigger the debug exception. */ | ||
29 | gen_set_pc_im(s, dest); | ||
30 | s->base.is_jmp = DISAS_JUMP; | ||
31 | - } else { | ||
32 | + return; | ||
33 | + } | ||
34 | + switch (s->base.is_jmp) { | ||
35 | + case DISAS_NEXT: | ||
36 | + case DISAS_TOO_MANY: | ||
37 | + case DISAS_NORETURN: | ||
38 | + /* | ||
39 | + * The normal case: just go to the destination TB. | ||
40 | + * NB: NORETURN happens if we generate code like | ||
41 | + * gen_brcondi(l); | ||
42 | + * gen_jmp(); | ||
43 | + * gen_set_label(l); | ||
44 | + * gen_jmp(); | ||
45 | + * on the second call to gen_jmp(). | ||
46 | + */ | ||
47 | gen_goto_tb(s, tbno, dest); | ||
48 | + break; | ||
49 | + case DISAS_UPDATE_NOCHAIN: | ||
50 | + case DISAS_UPDATE_EXIT: | ||
51 | + /* | ||
52 | + * We already decided we're leaving the TB for some other reason. | ||
53 | + * Avoid using goto_tb so we really do exit back to the main loop | ||
54 | + * and don't chain to another TB. | ||
55 | + */ | ||
56 | + gen_set_pc_im(s, dest); | ||
57 | + gen_goto_ptr(); | ||
58 | + s->base.is_jmp = DISAS_NORETURN; | ||
59 | + break; | ||
60 | + default: | ||
61 | + /* | ||
62 | + * We shouldn't be emitting code for a jump and also have | ||
63 | + * is_jmp set to one of the special cases like DISAS_SWI. | ||
64 | + */ | ||
65 | + g_assert_not_reached(); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | -- | ||
70 | 2.20.1 | ||
71 | |||
72 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Architecturally, for an M-profile CPU with the LOB feature the | ||
2 | LTPSIZE field in FPDSCR is always constant 4. QEMU's implementation | ||
3 | enforces this everywhere, except that we don't check that it is true | ||
4 | in incoming migration data. | ||
1 | 5 | ||
6 | We're going to add come in gen_update_fp_context() which relies on | ||
7 | the "always 4" property. Since this is TCG-only, we don't actually | ||
8 | need to be robust to bogus incoming migration data, and the effect of | ||
9 | it being wrong would be wrong code generation rather than a QEMU | ||
10 | crash; but if it did ever happen somehow it would be very difficult | ||
11 | to track down the cause. Add a check so that we fail the inbound | ||
12 | migration if the FPDSCR.LTPSIZE value is incorrect. | ||
13 | |||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Message-id: 20210913095440.13462-3-peter.maydell@linaro.org | ||
17 | --- | ||
18 | target/arm/machine.c | 13 +++++++++++++ | ||
19 | 1 file changed, 13 insertions(+) | ||
20 | |||
21 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/arm/machine.c | ||
24 | +++ b/target/arm/machine.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static int cpu_post_load(void *opaque, int version_id) | ||
26 | hw_breakpoint_update_all(cpu); | ||
27 | hw_watchpoint_update_all(cpu); | ||
28 | |||
29 | + /* | ||
30 | + * TCG gen_update_fp_context() relies on the invariant that | ||
31 | + * FPDSCR.LTPSIZE is constant 4 for M-profile with the LOB extension; | ||
32 | + * forbid bogus incoming data with some other value. | ||
33 | + */ | ||
34 | + if (arm_feature(env, ARM_FEATURE_M) && cpu_isar_feature(aa32_lob, cpu)) { | ||
35 | + if (extract32(env->v7m.fpdscr[M_REG_NS], | ||
36 | + FPCR_LTPSIZE_SHIFT, FPCR_LTPSIZE_LENGTH) != 4 || | ||
37 | + extract32(env->v7m.fpdscr[M_REG_S], | ||
38 | + FPCR_LTPSIZE_SHIFT, FPCR_LTPSIZE_LENGTH) != 4) { | ||
39 | + return -1; | ||
40 | + } | ||
41 | + } | ||
42 | if (!kvm_enabled()) { | ||
43 | pmu_op_finish(&cpu->env); | ||
44 | } | ||
45 | -- | ||
46 | 2.20.1 | ||
47 | |||
48 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Our current codegen for MVE always calls out to helper functions, | |
2 | because some byte lanes might be predicated. The common case is that | ||
3 | in fact there is no predication active and all lanes should be | ||
4 | updated together, so we can produce better code by detecting that and | ||
5 | using the TCG generic vector infrastructure. | ||
6 | |||
7 | Add a TB flag that is set when we can guarantee that there is no | ||
8 | active MVE predication, and a bool in the DisasContext. Subsequent | ||
9 | patches will use this flag to generate improved code for some | ||
10 | instructions. | ||
11 | |||
12 | In most cases when the predication state changes we simply end the TB | ||
13 | after that instruction. For the code called from vfp_access_check() | ||
14 | that handles lazy state preservation and creating a new FP context, | ||
15 | we can usually avoid having to try to end the TB because luckily the | ||
16 | new value of the flag following the register changes in those | ||
17 | sequences doesn't depend on any runtime decisions. We do have to end | ||
18 | the TB if the guest has enabled lazy FP state preservation but not | ||
19 | automatic state preservation, but this is an odd corner case that is | ||
20 | not going to be common in real-world code. | ||
21 | |||
22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
23 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
24 | Message-id: 20210913095440.13462-4-peter.maydell@linaro.org | ||
25 | --- | ||
26 | target/arm/cpu.h | 4 +++- | ||
27 | target/arm/translate.h | 2 ++ | ||
28 | target/arm/helper.c | 33 +++++++++++++++++++++++++++++++++ | ||
29 | target/arm/translate-m-nocp.c | 8 +++++++- | ||
30 | target/arm/translate-mve.c | 13 ++++++++++++- | ||
31 | target/arm/translate-vfp.c | 33 +++++++++++++++++++++++++++------ | ||
32 | target/arm/translate.c | 8 ++++++++ | ||
33 | 7 files changed, 92 insertions(+), 9 deletions(-) | ||
34 | |||
35 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/arm/cpu.h | ||
38 | +++ b/target/arm/cpu.h | ||
39 | @@ -XXX,XX +XXX,XX @@ typedef ARMCPU ArchCPU; | ||
40 | * | TBFLAG_AM32 | +-----+----------+ | ||
41 | * | | |TBFLAG_M32| | ||
42 | * +-------------+----------------+----------+ | ||
43 | - * 31 23 5 4 0 | ||
44 | + * 31 23 6 5 0 | ||
45 | * | ||
46 | * Unless otherwise noted, these bits are cached in env->hflags. | ||
47 | */ | ||
48 | @@ -XXX,XX +XXX,XX @@ FIELD(TBFLAG_M32, LSPACT, 2, 1) /* Not cached. */ | ||
49 | FIELD(TBFLAG_M32, NEW_FP_CTXT_NEEDED, 3, 1) /* Not cached. */ | ||
50 | /* Set if FPCCR.S does not match current security state */ | ||
51 | FIELD(TBFLAG_M32, FPCCR_S_WRONG, 4, 1) /* Not cached. */ | ||
52 | +/* Set if MVE insns are definitely not predicated by VPR or LTPSIZE */ | ||
53 | +FIELD(TBFLAG_M32, MVE_NO_PRED, 5, 1) /* Not cached. */ | ||
54 | |||
55 | /* | ||
56 | * Bit usage when in AArch64 state | ||
57 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/target/arm/translate.h | ||
60 | +++ b/target/arm/translate.h | ||
61 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
62 | bool align_mem; | ||
63 | /* True if PSTATE.IL is set */ | ||
64 | bool pstate_il; | ||
65 | + /* True if MVE insns are definitely not predicated by VPR or LTPSIZE */ | ||
66 | + bool mve_no_pred; | ||
67 | /* | ||
68 | * >= 0, a copy of PSTATE.BTYPE, which will be 0 without v8.5-BTI. | ||
69 | * < 0, set by the current instruction. | ||
70 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/target/arm/helper.c | ||
73 | +++ b/target/arm/helper.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static inline void assert_hflags_rebuild_correctly(CPUARMState *env) | ||
75 | #endif | ||
76 | } | ||
77 | |||
78 | +static bool mve_no_pred(CPUARMState *env) | ||
79 | +{ | ||
80 | + /* | ||
81 | + * Return true if there is definitely no predication of MVE | ||
82 | + * instructions by VPR or LTPSIZE. (Returning false even if there | ||
83 | + * isn't any predication is OK; generated code will just be | ||
84 | + * a little worse.) | ||
85 | + * If the CPU does not implement MVE then this TB flag is always 0. | ||
86 | + * | ||
87 | + * NOTE: if you change this logic, the "recalculate s->mve_no_pred" | ||
88 | + * logic in gen_update_fp_context() needs to be updated to match. | ||
89 | + * | ||
90 | + * We do not include the effect of the ECI bits here -- they are | ||
91 | + * tracked in other TB flags. This simplifies the logic for | ||
92 | + * "when did we emit code that changes the MVE_NO_PRED TB flag | ||
93 | + * and thus need to end the TB?". | ||
94 | + */ | ||
95 | + if (cpu_isar_feature(aa32_mve, env_archcpu(env))) { | ||
96 | + return false; | ||
97 | + } | ||
98 | + if (env->v7m.vpr) { | ||
99 | + return false; | ||
100 | + } | ||
101 | + if (env->v7m.ltpsize < 4) { | ||
102 | + return false; | ||
103 | + } | ||
104 | + return true; | ||
105 | +} | ||
106 | + | ||
107 | void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
108 | target_ulong *cs_base, uint32_t *pflags) | ||
109 | { | ||
110 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
111 | if (env->v7m.fpccr[is_secure] & R_V7M_FPCCR_LSPACT_MASK) { | ||
112 | DP_TBFLAG_M32(flags, LSPACT, 1); | ||
113 | } | ||
114 | + | ||
115 | + if (mve_no_pred(env)) { | ||
116 | + DP_TBFLAG_M32(flags, MVE_NO_PRED, 1); | ||
117 | + } | ||
118 | } else { | ||
119 | /* | ||
120 | * Note that XSCALE_CPAR shares bits with VECSTRIDE. | ||
121 | diff --git a/target/arm/translate-m-nocp.c b/target/arm/translate-m-nocp.c | ||
122 | index XXXXXXX..XXXXXXX 100644 | ||
123 | --- a/target/arm/translate-m-nocp.c | ||
124 | +++ b/target/arm/translate-m-nocp.c | ||
125 | @@ -XXX,XX +XXX,XX @@ static bool trans_VLLDM_VLSTM(DisasContext *s, arg_VLLDM_VLSTM *a) | ||
126 | |||
127 | clear_eci_state(s); | ||
128 | |||
129 | - /* End the TB, because we have updated FP control bits */ | ||
130 | + /* | ||
131 | + * End the TB, because we have updated FP control bits, | ||
132 | + * and possibly VPR or LTPSIZE. | ||
133 | + */ | ||
134 | s->base.is_jmp = DISAS_UPDATE_EXIT; | ||
135 | return true; | ||
136 | } | ||
137 | @@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, | ||
138 | store_cpu_field(control, v7m.control[M_REG_S]); | ||
139 | tcg_gen_andi_i32(tmp, tmp, ~FPCR_NZCV_MASK); | ||
140 | gen_helper_vfp_set_fpscr(cpu_env, tmp); | ||
141 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
142 | tcg_temp_free_i32(tmp); | ||
143 | tcg_temp_free_i32(sfpa); | ||
144 | break; | ||
145 | @@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, | ||
146 | } | ||
147 | tmp = loadfn(s, opaque, true); | ||
148 | store_cpu_field(tmp, v7m.vpr); | ||
149 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
150 | break; | ||
151 | case ARM_VFP_P0: | ||
152 | { | ||
153 | @@ -XXX,XX +XXX,XX @@ static bool gen_M_fp_sysreg_write(DisasContext *s, int regno, | ||
154 | tcg_gen_deposit_i32(vpr, vpr, tmp, | ||
155 | R_V7M_VPR_P0_SHIFT, R_V7M_VPR_P0_LENGTH); | ||
156 | store_cpu_field(vpr, v7m.vpr); | ||
157 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
158 | tcg_temp_free_i32(tmp); | ||
159 | break; | ||
160 | } | ||
161 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/target/arm/translate-mve.c | ||
164 | +++ b/target/arm/translate-mve.c | ||
165 | @@ -XXX,XX +XXX,XX @@ DO_LOGIC(VORR, gen_helper_mve_vorr) | ||
166 | DO_LOGIC(VORN, gen_helper_mve_vorn) | ||
167 | DO_LOGIC(VEOR, gen_helper_mve_veor) | ||
168 | |||
169 | -DO_LOGIC(VPSEL, gen_helper_mve_vpsel) | ||
170 | +static bool trans_VPSEL(DisasContext *s, arg_2op *a) | ||
171 | +{ | ||
172 | + /* This insn updates predication bits */ | ||
173 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
174 | + return do_2op(s, a, gen_helper_mve_vpsel); | ||
175 | +} | ||
176 | |||
177 | #define DO_2OP(INSN, FN) \ | ||
178 | static bool trans_##INSN(DisasContext *s, arg_2op *a) \ | ||
179 | @@ -XXX,XX +XXX,XX @@ static bool trans_VPNOT(DisasContext *s, arg_VPNOT *a) | ||
180 | } | ||
181 | |||
182 | gen_helper_mve_vpnot(cpu_env); | ||
183 | + /* This insn updates predication bits */ | ||
184 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
185 | mve_update_eci(s); | ||
186 | return true; | ||
187 | } | ||
188 | @@ -XXX,XX +XXX,XX @@ static bool do_vcmp(DisasContext *s, arg_vcmp *a, MVEGenCmpFn *fn) | ||
189 | /* VPT */ | ||
190 | gen_vpst(s, a->mask); | ||
191 | } | ||
192 | + /* This insn updates predication bits */ | ||
193 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
194 | mve_update_eci(s); | ||
195 | return true; | ||
196 | } | ||
197 | @@ -XXX,XX +XXX,XX @@ static bool do_vcmp_scalar(DisasContext *s, arg_vcmp_scalar *a, | ||
198 | /* VPT */ | ||
199 | gen_vpst(s, a->mask); | ||
200 | } | ||
201 | + /* This insn updates predication bits */ | ||
202 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
203 | mve_update_eci(s); | ||
204 | return true; | ||
205 | } | ||
206 | diff --git a/target/arm/translate-vfp.c b/target/arm/translate-vfp.c | ||
207 | index XXXXXXX..XXXXXXX 100644 | ||
208 | --- a/target/arm/translate-vfp.c | ||
209 | +++ b/target/arm/translate-vfp.c | ||
210 | @@ -XXX,XX +XXX,XX @@ static inline long vfp_f16_offset(unsigned reg, bool top) | ||
211 | * Generate code for M-profile lazy FP state preservation if needed; | ||
212 | * this corresponds to the pseudocode PreserveFPState() function. | ||
213 | */ | ||
214 | -static void gen_preserve_fp_state(DisasContext *s) | ||
215 | +static void gen_preserve_fp_state(DisasContext *s, bool skip_context_update) | ||
216 | { | ||
217 | if (s->v7m_lspact) { | ||
218 | /* | ||
219 | @@ -XXX,XX +XXX,XX @@ static void gen_preserve_fp_state(DisasContext *s) | ||
220 | * any further FP insns in this TB. | ||
221 | */ | ||
222 | s->v7m_lspact = false; | ||
223 | + /* | ||
224 | + * The helper might have zeroed VPR, so we do not know the | ||
225 | + * correct value for the MVE_NO_PRED TB flag any more. | ||
226 | + * If we're about to create a new fp context then that | ||
227 | + * will precisely determine the MVE_NO_PRED value (see | ||
228 | + * gen_update_fp_context()). Otherwise, we must: | ||
229 | + * - set s->mve_no_pred to false, so this instruction | ||
230 | + * is generated to use helper functions | ||
231 | + * - end the TB now, without chaining to the next TB | ||
232 | + */ | ||
233 | + if (skip_context_update || !s->v7m_new_fp_ctxt_needed) { | ||
234 | + s->mve_no_pred = false; | ||
235 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
236 | + } | ||
237 | } | ||
238 | } | ||
239 | |||
240 | @@ -XXX,XX +XXX,XX @@ static void gen_update_fp_context(DisasContext *s) | ||
241 | TCGv_i32 z32 = tcg_const_i32(0); | ||
242 | store_cpu_field(z32, v7m.vpr); | ||
243 | } | ||
244 | - | ||
245 | /* | ||
246 | - * We don't need to arrange to end the TB, because the only | ||
247 | - * parts of FPSCR which we cache in the TB flags are the VECLEN | ||
248 | - * and VECSTRIDE, and those don't exist for M-profile. | ||
249 | + * We just updated the FPSCR and VPR. Some of this state is cached | ||
250 | + * in the MVE_NO_PRED TB flag. We want to avoid having to end the | ||
251 | + * TB here, which means we need the new value of the MVE_NO_PRED | ||
252 | + * flag to be exactly known here and the same for all executions. | ||
253 | + * Luckily FPDSCR.LTPSIZE is always constant 4 and the VPR is | ||
254 | + * always set to 0, so the new MVE_NO_PRED flag is always 1 | ||
255 | + * if and only if we have MVE. | ||
256 | + * | ||
257 | + * (The other FPSCR state cached in TB flags is VECLEN and VECSTRIDE, | ||
258 | + * but those do not exist for M-profile, so are not relevant here.) | ||
259 | */ | ||
260 | + s->mve_no_pred = dc_isar_feature(aa32_mve, s); | ||
261 | |||
262 | if (s->v8m_secure) { | ||
263 | bits |= R_V7M_CONTROL_SFPA_MASK; | ||
264 | @@ -XXX,XX +XXX,XX @@ bool vfp_access_check_m(DisasContext *s, bool skip_context_update) | ||
265 | /* Handle M-profile lazy FP state mechanics */ | ||
266 | |||
267 | /* Trigger lazy-state preservation if necessary */ | ||
268 | - gen_preserve_fp_state(s); | ||
269 | + gen_preserve_fp_state(s, skip_context_update); | ||
270 | |||
271 | if (!skip_context_update) { | ||
272 | /* Update ownership of FP context and create new FP context if needed */ | ||
273 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
274 | index XXXXXXX..XXXXXXX 100644 | ||
275 | --- a/target/arm/translate.c | ||
276 | +++ b/target/arm/translate.c | ||
277 | @@ -XXX,XX +XXX,XX @@ static bool trans_DLS(DisasContext *s, arg_DLS *a) | ||
278 | /* DLSTP: set FPSCR.LTPSIZE */ | ||
279 | tmp = tcg_const_i32(a->size); | ||
280 | store_cpu_field(tmp, v7m.ltpsize); | ||
281 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
282 | } | ||
283 | return true; | ||
284 | } | ||
285 | @@ -XXX,XX +XXX,XX @@ static bool trans_WLS(DisasContext *s, arg_WLS *a) | ||
286 | assert(ok); | ||
287 | tmp = tcg_const_i32(a->size); | ||
288 | store_cpu_field(tmp, v7m.ltpsize); | ||
289 | + /* | ||
290 | + * LTPSIZE updated, but MVE_NO_PRED will always be the same thing (0) | ||
291 | + * when we take this upcoming exit from this TB, so gen_jmp_tb() is OK. | ||
292 | + */ | ||
293 | } | ||
294 | gen_jmp_tb(s, s->base.pc_next, 1); | ||
295 | |||
296 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCTP(DisasContext *s, arg_VCTP *a) | ||
297 | gen_helper_mve_vctp(cpu_env, masklen); | ||
298 | tcg_temp_free_i32(masklen); | ||
299 | tcg_temp_free_i32(rn_shifted); | ||
300 | + /* This insn updates predication bits */ | ||
301 | + s->base.is_jmp = DISAS_UPDATE_NOCHAIN; | ||
302 | mve_update_eci(s); | ||
303 | return true; | ||
304 | } | ||
305 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
306 | dc->v7m_new_fp_ctxt_needed = | ||
307 | EX_TBFLAG_M32(tb_flags, NEW_FP_CTXT_NEEDED); | ||
308 | dc->v7m_lspact = EX_TBFLAG_M32(tb_flags, LSPACT); | ||
309 | + dc->mve_no_pred = EX_TBFLAG_M32(tb_flags, MVE_NO_PRED); | ||
310 | } else { | ||
311 | dc->debug_target_el = EX_TBFLAG_ANY(tb_flags, DEBUG_TARGET_EL); | ||
312 | dc->sctlr_b = EX_TBFLAG_A32(tb_flags, SCTLR__B); | ||
313 | -- | ||
314 | 2.20.1 | ||
315 | |||
316 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | When not predicating, implement the MVE bitwise logical insns | ||
2 | directly using TCG vector operations. | ||
1 | 3 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20210913095440.13462-5-peter.maydell@linaro.org | ||
8 | --- | ||
9 | target/arm/translate-mve.c | 51 +++++++++++++++++++++++++++----------- | ||
10 | 1 file changed, 36 insertions(+), 15 deletions(-) | ||
11 | |||
12 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/arm/translate-mve.c | ||
15 | +++ b/target/arm/translate-mve.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static TCGv_ptr mve_qreg_ptr(unsigned reg) | ||
17 | return ret; | ||
18 | } | ||
19 | |||
20 | +static bool mve_no_predication(DisasContext *s) | ||
21 | +{ | ||
22 | + /* | ||
23 | + * Return true if we are executing the entire MVE instruction | ||
24 | + * with no predication or partial-execution, and so we can safely | ||
25 | + * use an inline TCG vector implementation. | ||
26 | + */ | ||
27 | + return s->eci == 0 && s->mve_no_pred; | ||
28 | +} | ||
29 | + | ||
30 | static bool mve_check_qreg_bank(DisasContext *s, int qmask) | ||
31 | { | ||
32 | /* | ||
33 | @@ -XXX,XX +XXX,XX @@ static bool trans_VNEG_fp(DisasContext *s, arg_1op *a) | ||
34 | return do_1op(s, a, fns[a->size]); | ||
35 | } | ||
36 | |||
37 | -static bool do_2op(DisasContext *s, arg_2op *a, MVEGenTwoOpFn fn) | ||
38 | +static bool do_2op_vec(DisasContext *s, arg_2op *a, MVEGenTwoOpFn fn, | ||
39 | + GVecGen3Fn *vecfn) | ||
40 | { | ||
41 | TCGv_ptr qd, qn, qm; | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ static bool do_2op(DisasContext *s, arg_2op *a, MVEGenTwoOpFn fn) | ||
44 | return true; | ||
45 | } | ||
46 | |||
47 | - qd = mve_qreg_ptr(a->qd); | ||
48 | - qn = mve_qreg_ptr(a->qn); | ||
49 | - qm = mve_qreg_ptr(a->qm); | ||
50 | - fn(cpu_env, qd, qn, qm); | ||
51 | - tcg_temp_free_ptr(qd); | ||
52 | - tcg_temp_free_ptr(qn); | ||
53 | - tcg_temp_free_ptr(qm); | ||
54 | + if (vecfn && mve_no_predication(s)) { | ||
55 | + vecfn(a->size, mve_qreg_offset(a->qd), mve_qreg_offset(a->qn), | ||
56 | + mve_qreg_offset(a->qm), 16, 16); | ||
57 | + } else { | ||
58 | + qd = mve_qreg_ptr(a->qd); | ||
59 | + qn = mve_qreg_ptr(a->qn); | ||
60 | + qm = mve_qreg_ptr(a->qm); | ||
61 | + fn(cpu_env, qd, qn, qm); | ||
62 | + tcg_temp_free_ptr(qd); | ||
63 | + tcg_temp_free_ptr(qn); | ||
64 | + tcg_temp_free_ptr(qm); | ||
65 | + } | ||
66 | mve_update_eci(s); | ||
67 | return true; | ||
68 | } | ||
69 | |||
70 | -#define DO_LOGIC(INSN, HELPER) \ | ||
71 | +static bool do_2op(DisasContext *s, arg_2op *a, MVEGenTwoOpFn *fn) | ||
72 | +{ | ||
73 | + return do_2op_vec(s, a, fn, NULL); | ||
74 | +} | ||
75 | + | ||
76 | +#define DO_LOGIC(INSN, HELPER, VECFN) \ | ||
77 | static bool trans_##INSN(DisasContext *s, arg_2op *a) \ | ||
78 | { \ | ||
79 | - return do_2op(s, a, HELPER); \ | ||
80 | + return do_2op_vec(s, a, HELPER, VECFN); \ | ||
81 | } | ||
82 | |||
83 | -DO_LOGIC(VAND, gen_helper_mve_vand) | ||
84 | -DO_LOGIC(VBIC, gen_helper_mve_vbic) | ||
85 | -DO_LOGIC(VORR, gen_helper_mve_vorr) | ||
86 | -DO_LOGIC(VORN, gen_helper_mve_vorn) | ||
87 | -DO_LOGIC(VEOR, gen_helper_mve_veor) | ||
88 | +DO_LOGIC(VAND, gen_helper_mve_vand, tcg_gen_gvec_and) | ||
89 | +DO_LOGIC(VBIC, gen_helper_mve_vbic, tcg_gen_gvec_andc) | ||
90 | +DO_LOGIC(VORR, gen_helper_mve_vorr, tcg_gen_gvec_or) | ||
91 | +DO_LOGIC(VORN, gen_helper_mve_vorn, tcg_gen_gvec_orc) | ||
92 | +DO_LOGIC(VEOR, gen_helper_mve_veor, tcg_gen_gvec_xor) | ||
93 | |||
94 | static bool trans_VPSEL(DisasContext *s, arg_2op *a) | ||
95 | { | ||
96 | -- | ||
97 | 2.20.1 | ||
98 | |||
99 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Optimize MVE arithmetic ops when we have a TCG | ||
2 | vector operation we can use. | ||
1 | 3 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20210913095440.13462-6-peter.maydell@linaro.org | ||
8 | --- | ||
9 | target/arm/translate-mve.c | 20 +++++++++++--------- | ||
10 | 1 file changed, 11 insertions(+), 9 deletions(-) | ||
11 | |||
12 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/arm/translate-mve.c | ||
15 | +++ b/target/arm/translate-mve.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static bool trans_VPSEL(DisasContext *s, arg_2op *a) | ||
17 | return do_2op(s, a, gen_helper_mve_vpsel); | ||
18 | } | ||
19 | |||
20 | -#define DO_2OP(INSN, FN) \ | ||
21 | +#define DO_2OP_VEC(INSN, FN, VECFN) \ | ||
22 | static bool trans_##INSN(DisasContext *s, arg_2op *a) \ | ||
23 | { \ | ||
24 | static MVEGenTwoOpFn * const fns[] = { \ | ||
25 | @@ -XXX,XX +XXX,XX @@ static bool trans_VPSEL(DisasContext *s, arg_2op *a) | ||
26 | gen_helper_mve_##FN##w, \ | ||
27 | NULL, \ | ||
28 | }; \ | ||
29 | - return do_2op(s, a, fns[a->size]); \ | ||
30 | + return do_2op_vec(s, a, fns[a->size], VECFN); \ | ||
31 | } | ||
32 | |||
33 | -DO_2OP(VADD, vadd) | ||
34 | -DO_2OP(VSUB, vsub) | ||
35 | -DO_2OP(VMUL, vmul) | ||
36 | +#define DO_2OP(INSN, FN) DO_2OP_VEC(INSN, FN, NULL) | ||
37 | + | ||
38 | +DO_2OP_VEC(VADD, vadd, tcg_gen_gvec_add) | ||
39 | +DO_2OP_VEC(VSUB, vsub, tcg_gen_gvec_sub) | ||
40 | +DO_2OP_VEC(VMUL, vmul, tcg_gen_gvec_mul) | ||
41 | DO_2OP(VMULH_S, vmulhs) | ||
42 | DO_2OP(VMULH_U, vmulhu) | ||
43 | DO_2OP(VRMULH_S, vrmulhs) | ||
44 | DO_2OP(VRMULH_U, vrmulhu) | ||
45 | -DO_2OP(VMAX_S, vmaxs) | ||
46 | -DO_2OP(VMAX_U, vmaxu) | ||
47 | -DO_2OP(VMIN_S, vmins) | ||
48 | -DO_2OP(VMIN_U, vminu) | ||
49 | +DO_2OP_VEC(VMAX_S, vmaxs, tcg_gen_gvec_smax) | ||
50 | +DO_2OP_VEC(VMAX_U, vmaxu, tcg_gen_gvec_umax) | ||
51 | +DO_2OP_VEC(VMIN_S, vmins, tcg_gen_gvec_smin) | ||
52 | +DO_2OP_VEC(VMIN_U, vminu, tcg_gen_gvec_umin) | ||
53 | DO_2OP(VABD_S, vabds) | ||
54 | DO_2OP(VABD_U, vabdu) | ||
55 | DO_2OP(VHADD_S, vhadds) | ||
56 | -- | ||
57 | 2.20.1 | ||
58 | |||
59 | diff view generated by jsdifflib |
1 | From: Alex Bennée <alex.bennee@linaro.org> | 1 | Optimize the MVE VNEG and VABS insns by using TCG |
---|---|---|---|
2 | vector ops when possible. | ||
2 | 3 | ||
3 | All the hard work is already done by vfp_expand_imm, we just need to | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | make sure we pick up the correct size. | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20210913095440.13462-7-peter.maydell@linaro.org | ||
8 | --- | ||
9 | target/arm/translate-mve.c | 32 ++++++++++++++++++++++---------- | ||
10 | 1 file changed, 22 insertions(+), 10 deletions(-) | ||
5 | 11 | ||
6 | Cc: qemu-stable@nongnu.org | 12 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20180512003217.9105-11-richard.henderson@linaro.org | ||
12 | [rth: Merge unallocated_encoding check with TCGMemOp conversion.] | ||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | --- | ||
16 | target/arm/translate-a64.c | 20 +++++++++++++++++--- | ||
17 | 1 file changed, 17 insertions(+), 3 deletions(-) | ||
18 | |||
19 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/translate-a64.c | 14 | --- a/target/arm/translate-mve.c |
22 | +++ b/target/arm/translate-a64.c | 15 | +++ b/target/arm/translate-mve.c |
23 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_imm(DisasContext *s, uint32_t insn) | 16 | @@ -XXX,XX +XXX,XX @@ static bool trans_VDUP(DisasContext *s, arg_VDUP *a) |
17 | return true; | ||
18 | } | ||
19 | |||
20 | -static bool do_1op(DisasContext *s, arg_1op *a, MVEGenOneOpFn fn) | ||
21 | +static bool do_1op_vec(DisasContext *s, arg_1op *a, MVEGenOneOpFn fn, | ||
22 | + GVecGen2Fn vecfn) | ||
24 | { | 23 | { |
25 | int rd = extract32(insn, 0, 5); | 24 | TCGv_ptr qd, qm; |
26 | int imm8 = extract32(insn, 13, 8); | 25 | |
27 | - int is_double = extract32(insn, 22, 2); | 26 | @@ -XXX,XX +XXX,XX @@ static bool do_1op(DisasContext *s, arg_1op *a, MVEGenOneOpFn fn) |
28 | + int type = extract32(insn, 22, 2); | 27 | return true; |
29 | uint64_t imm; | ||
30 | TCGv_i64 tcg_res; | ||
31 | + TCGMemOp sz; | ||
32 | |||
33 | - if (is_double > 1) { | ||
34 | + switch (type) { | ||
35 | + case 0: | ||
36 | + sz = MO_32; | ||
37 | + break; | ||
38 | + case 1: | ||
39 | + sz = MO_64; | ||
40 | + break; | ||
41 | + case 3: | ||
42 | + sz = MO_16; | ||
43 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
44 | + break; | ||
45 | + } | ||
46 | + /* fallthru */ | ||
47 | + default: | ||
48 | unallocated_encoding(s); | ||
49 | return; | ||
50 | } | 28 | } |
51 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_imm(DisasContext *s, uint32_t insn) | 29 | |
52 | return; | 30 | - qd = mve_qreg_ptr(a->qd); |
31 | - qm = mve_qreg_ptr(a->qm); | ||
32 | - fn(cpu_env, qd, qm); | ||
33 | - tcg_temp_free_ptr(qd); | ||
34 | - tcg_temp_free_ptr(qm); | ||
35 | + if (vecfn && mve_no_predication(s)) { | ||
36 | + vecfn(a->size, mve_qreg_offset(a->qd), mve_qreg_offset(a->qm), 16, 16); | ||
37 | + } else { | ||
38 | + qd = mve_qreg_ptr(a->qd); | ||
39 | + qm = mve_qreg_ptr(a->qm); | ||
40 | + fn(cpu_env, qd, qm); | ||
41 | + tcg_temp_free_ptr(qd); | ||
42 | + tcg_temp_free_ptr(qm); | ||
43 | + } | ||
44 | mve_update_eci(s); | ||
45 | return true; | ||
46 | } | ||
47 | |||
48 | -#define DO_1OP(INSN, FN) \ | ||
49 | +static bool do_1op(DisasContext *s, arg_1op *a, MVEGenOneOpFn fn) | ||
50 | +{ | ||
51 | + return do_1op_vec(s, a, fn, NULL); | ||
52 | +} | ||
53 | + | ||
54 | +#define DO_1OP_VEC(INSN, FN, VECFN) \ | ||
55 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
56 | { \ | ||
57 | static MVEGenOneOpFn * const fns[] = { \ | ||
58 | @@ -XXX,XX +XXX,XX @@ static bool do_1op(DisasContext *s, arg_1op *a, MVEGenOneOpFn fn) | ||
59 | gen_helper_mve_##FN##w, \ | ||
60 | NULL, \ | ||
61 | }; \ | ||
62 | - return do_1op(s, a, fns[a->size]); \ | ||
63 | + return do_1op_vec(s, a, fns[a->size], VECFN); \ | ||
53 | } | 64 | } |
54 | 65 | ||
55 | - imm = vfp_expand_imm(MO_32 + is_double, imm8); | 66 | +#define DO_1OP(INSN, FN) DO_1OP_VEC(INSN, FN, NULL) |
56 | + imm = vfp_expand_imm(sz, imm8); | 67 | + |
57 | 68 | DO_1OP(VCLZ, vclz) | |
58 | tcg_res = tcg_const_i64(imm); | 69 | DO_1OP(VCLS, vcls) |
59 | write_fp_dreg(s, rd, tcg_res); | 70 | -DO_1OP(VABS, vabs) |
71 | -DO_1OP(VNEG, vneg) | ||
72 | +DO_1OP_VEC(VABS, vabs, tcg_gen_gvec_abs) | ||
73 | +DO_1OP_VEC(VNEG, vneg, tcg_gen_gvec_neg) | ||
74 | DO_1OP(VQABS, vqabs) | ||
75 | DO_1OP(VQNEG, vqneg) | ||
76 | DO_1OP(VMAXA, vmaxa) | ||
60 | -- | 77 | -- |
61 | 2.17.0 | 78 | 2.20.1 |
62 | 79 | ||
63 | 80 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Optimize the MVE VDUP insns by using TCG vector ops when possible. | ||
1 | 2 | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20210913095440.13462-8-peter.maydell@linaro.org | ||
6 | --- | ||
7 | target/arm/translate-mve.c | 12 ++++++++---- | ||
8 | 1 file changed, 8 insertions(+), 4 deletions(-) | ||
9 | |||
10 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/target/arm/translate-mve.c | ||
13 | +++ b/target/arm/translate-mve.c | ||
14 | @@ -XXX,XX +XXX,XX @@ static bool trans_VDUP(DisasContext *s, arg_VDUP *a) | ||
15 | return true; | ||
16 | } | ||
17 | |||
18 | - qd = mve_qreg_ptr(a->qd); | ||
19 | rt = load_reg(s, a->rt); | ||
20 | - tcg_gen_dup_i32(a->size, rt, rt); | ||
21 | - gen_helper_mve_vdup(cpu_env, qd, rt); | ||
22 | - tcg_temp_free_ptr(qd); | ||
23 | + if (mve_no_predication(s)) { | ||
24 | + tcg_gen_gvec_dup_i32(a->size, mve_qreg_offset(a->qd), 16, 16, rt); | ||
25 | + } else { | ||
26 | + qd = mve_qreg_ptr(a->qd); | ||
27 | + tcg_gen_dup_i32(a->size, rt, rt); | ||
28 | + gen_helper_mve_vdup(cpu_env, qd, rt); | ||
29 | + tcg_temp_free_ptr(qd); | ||
30 | + } | ||
31 | tcg_temp_free_i32(rt); | ||
32 | mve_update_eci(s); | ||
33 | return true; | ||
34 | -- | ||
35 | 2.20.1 | ||
36 | |||
37 | diff view generated by jsdifflib |
1 | From: Alex Bennée <alex.bennee@linaro.org> | 1 | Optimize the MVE VMVN insn by using TCG vector ops when possible. |
---|---|---|---|
2 | 2 | ||
3 | Reported by Coverity (CID1390635). We ensure this for uint_to_float | 3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | later on so we might as well mirror that. | ||
5 | |||
6 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Message-id: 20210913095440.13462-9-peter.maydell@linaro.org |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | 6 | --- |
11 | fpu/softfloat.c | 2 +- | 7 | target/arm/translate-mve.c | 2 +- |
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | 8 | 1 file changed, 1 insertion(+), 1 deletion(-) |
13 | 9 | ||
14 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | 10 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
15 | index XXXXXXX..XXXXXXX 100644 | 11 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/fpu/softfloat.c | 12 | --- a/target/arm/translate-mve.c |
17 | +++ b/fpu/softfloat.c | 13 | +++ b/target/arm/translate-mve.c |
18 | @@ -XXX,XX +XXX,XX @@ FLOAT_TO_UINT(64, 64) | 14 | @@ -XXX,XX +XXX,XX @@ static bool trans_VREV64(DisasContext *s, arg_1op *a) |
19 | 15 | ||
20 | static FloatParts int_to_float(int64_t a, float_status *status) | 16 | static bool trans_VMVN(DisasContext *s, arg_1op *a) |
21 | { | 17 | { |
22 | - FloatParts r; | 18 | - return do_1op(s, a, gen_helper_mve_vmvn); |
23 | + FloatParts r = {}; | 19 | + return do_1op_vec(s, a, gen_helper_mve_vmvn, tcg_gen_gvec_not); |
24 | if (a == 0) { | 20 | } |
25 | r.cls = float_class_zero; | 21 | |
26 | r.sign = false; | 22 | static bool trans_VABS_fp(DisasContext *s, arg_1op *a) |
27 | -- | 23 | -- |
28 | 2.17.0 | 24 | 2.20.1 |
29 | 25 | ||
30 | 26 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | Optimize the MVE VSHL and VSHR immediate forms by using TCG vector |
---|---|---|---|
2 | ops when possible. | ||
2 | 3 | ||
3 | Cc: qemu-stable@nongnu.org | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Message-id: 20180512003217.9105-6-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20210913095440.13462-10-peter.maydell@linaro.org | ||
9 | --- | 7 | --- |
10 | target/arm/translate-a64.c | 30 ++++++++++++++---------------- | 8 | target/arm/translate-mve.c | 83 +++++++++++++++++++++++++++++--------- |
11 | 1 file changed, 14 insertions(+), 16 deletions(-) | 9 | 1 file changed, 63 insertions(+), 20 deletions(-) |
12 | 10 | ||
13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 11 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
14 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate-a64.c | 13 | --- a/target/arm/translate-mve.c |
16 | +++ b/target/arm/translate-a64.c | 14 | +++ b/target/arm/translate-mve.c |
17 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 read_fp_sreg(DisasContext *s, int reg) | 15 | @@ -XXX,XX +XXX,XX @@ static bool trans_Vimm_1r(DisasContext *s, arg_1imm *a) |
18 | return v; | 16 | return do_1imm(s, a, fn); |
19 | } | 17 | } |
20 | 18 | ||
21 | +static TCGv_i32 read_fp_hreg(DisasContext *s, int reg) | 19 | -static bool do_2shift(DisasContext *s, arg_2shift *a, MVEGenTwoOpShiftFn fn, |
20 | - bool negateshift) | ||
21 | +static bool do_2shift_vec(DisasContext *s, arg_2shift *a, MVEGenTwoOpShiftFn fn, | ||
22 | + bool negateshift, GVecGen2iFn vecfn) | ||
23 | { | ||
24 | TCGv_ptr qd, qm; | ||
25 | int shift = a->shift; | ||
26 | @@ -XXX,XX +XXX,XX @@ static bool do_2shift(DisasContext *s, arg_2shift *a, MVEGenTwoOpShiftFn fn, | ||
27 | shift = -shift; | ||
28 | } | ||
29 | |||
30 | - qd = mve_qreg_ptr(a->qd); | ||
31 | - qm = mve_qreg_ptr(a->qm); | ||
32 | - fn(cpu_env, qd, qm, tcg_constant_i32(shift)); | ||
33 | - tcg_temp_free_ptr(qd); | ||
34 | - tcg_temp_free_ptr(qm); | ||
35 | + if (vecfn && mve_no_predication(s)) { | ||
36 | + vecfn(a->size, mve_qreg_offset(a->qd), mve_qreg_offset(a->qm), | ||
37 | + shift, 16, 16); | ||
38 | + } else { | ||
39 | + qd = mve_qreg_ptr(a->qd); | ||
40 | + qm = mve_qreg_ptr(a->qm); | ||
41 | + fn(cpu_env, qd, qm, tcg_constant_i32(shift)); | ||
42 | + tcg_temp_free_ptr(qd); | ||
43 | + tcg_temp_free_ptr(qm); | ||
44 | + } | ||
45 | mve_update_eci(s); | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | -#define DO_2SHIFT(INSN, FN, NEGATESHIFT) \ | ||
50 | - static bool trans_##INSN(DisasContext *s, arg_2shift *a) \ | ||
51 | - { \ | ||
52 | - static MVEGenTwoOpShiftFn * const fns[] = { \ | ||
53 | - gen_helper_mve_##FN##b, \ | ||
54 | - gen_helper_mve_##FN##h, \ | ||
55 | - gen_helper_mve_##FN##w, \ | ||
56 | - NULL, \ | ||
57 | - }; \ | ||
58 | - return do_2shift(s, a, fns[a->size], NEGATESHIFT); \ | ||
59 | +static bool do_2shift(DisasContext *s, arg_2shift *a, MVEGenTwoOpShiftFn fn, | ||
60 | + bool negateshift) | ||
22 | +{ | 61 | +{ |
23 | + TCGv_i32 v = tcg_temp_new_i32(); | 62 | + return do_2shift_vec(s, a, fn, negateshift, NULL); |
24 | + | ||
25 | + tcg_gen_ld16u_i32(v, cpu_env, fp_reg_offset(s, reg, MO_16)); | ||
26 | + return v; | ||
27 | +} | 63 | +} |
28 | + | 64 | + |
29 | /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64). | 65 | +#define DO_2SHIFT_VEC(INSN, FN, NEGATESHIFT, VECFN) \ |
30 | * If SVE is not enabled, then there are only 128 bits in the vector. | 66 | + static bool trans_##INSN(DisasContext *s, arg_2shift *a) \ |
31 | */ | 67 | + { \ |
32 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) | 68 | + static MVEGenTwoOpShiftFn * const fns[] = { \ |
33 | static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn) | 69 | + gen_helper_mve_##FN##b, \ |
34 | { | 70 | + gen_helper_mve_##FN##h, \ |
35 | TCGv_ptr fpst = NULL; | 71 | + gen_helper_mve_##FN##w, \ |
36 | - TCGv_i32 tcg_op = tcg_temp_new_i32(); | 72 | + NULL, \ |
37 | + TCGv_i32 tcg_op = read_fp_hreg(s, rn); | 73 | + }; \ |
38 | TCGv_i32 tcg_res = tcg_temp_new_i32(); | 74 | + return do_2shift_vec(s, a, fns[a->size], NEGATESHIFT, VECFN); \ |
39 | |||
40 | - read_vec_element_i32(s, tcg_op, rn, 0, MO_16); | ||
41 | - | ||
42 | switch (opcode) { | ||
43 | case 0x0: /* FMOV */ | ||
44 | tcg_gen_mov_i32(tcg_res, tcg_op); | ||
45 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn) | ||
46 | tcg_temp_free_i64(tcg_op2); | ||
47 | tcg_temp_free_i64(tcg_res); | ||
48 | } else { | ||
49 | - TCGv_i32 tcg_op1 = tcg_temp_new_i32(); | ||
50 | - TCGv_i32 tcg_op2 = tcg_temp_new_i32(); | ||
51 | + TCGv_i32 tcg_op1 = read_fp_hreg(s, rn); | ||
52 | + TCGv_i32 tcg_op2 = read_fp_hreg(s, rm); | ||
53 | TCGv_i64 tcg_res = tcg_temp_new_i64(); | ||
54 | |||
55 | - read_vec_element_i32(s, tcg_op1, rn, 0, MO_16); | ||
56 | - read_vec_element_i32(s, tcg_op2, rm, 0, MO_16); | ||
57 | - | ||
58 | gen_helper_neon_mull_s16(tcg_res, tcg_op1, tcg_op2); | ||
59 | gen_helper_neon_addl_saturate_s32(tcg_res, cpu_env, tcg_res, tcg_res); | ||
60 | |||
61 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s, | ||
62 | |||
63 | fpst = get_fpstatus_ptr(true); | ||
64 | |||
65 | - tcg_op1 = tcg_temp_new_i32(); | ||
66 | - tcg_op2 = tcg_temp_new_i32(); | ||
67 | + tcg_op1 = read_fp_hreg(s, rn); | ||
68 | + tcg_op2 = read_fp_hreg(s, rm); | ||
69 | tcg_res = tcg_temp_new_i32(); | ||
70 | |||
71 | - read_vec_element_i32(s, tcg_op1, rn, 0, MO_16); | ||
72 | - read_vec_element_i32(s, tcg_op2, rm, 0, MO_16); | ||
73 | - | ||
74 | switch (fpopcode) { | ||
75 | case 0x03: /* FMULX */ | ||
76 | gen_helper_advsimd_mulxh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
77 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn) | ||
78 | } | 75 | } |
79 | 76 | ||
80 | if (is_scalar) { | 77 | -DO_2SHIFT(VSHLI, vshli_u, false) |
81 | - TCGv_i32 tcg_op = tcg_temp_new_i32(); | 78 | +#define DO_2SHIFT(INSN, FN, NEGATESHIFT) \ |
82 | + TCGv_i32 tcg_op = read_fp_hreg(s, rn); | 79 | + DO_2SHIFT_VEC(INSN, FN, NEGATESHIFT, NULL) |
83 | TCGv_i32 tcg_res = tcg_temp_new_i32(); | 80 | + |
84 | 81 | +static void do_gvec_shri_s(unsigned vece, uint32_t dofs, uint32_t aofs, | |
85 | - read_vec_element_i32(s, tcg_op, rn, 0, MO_16); | 82 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) |
86 | - | 83 | +{ |
87 | switch (fpop) { | 84 | + /* |
88 | case 0x1a: /* FCVTNS */ | 85 | + * We get here with a negated shift count, and we must handle |
89 | case 0x1b: /* FCVTMS */ | 86 | + * shifts by the element size, which tcg_gen_gvec_sari() does not do. |
87 | + */ | ||
88 | + shift = -shift; | ||
89 | + if (shift == (8 << vece)) { | ||
90 | + shift--; | ||
91 | + } | ||
92 | + tcg_gen_gvec_sari(vece, dofs, aofs, shift, oprsz, maxsz); | ||
93 | +} | ||
94 | + | ||
95 | +static void do_gvec_shri_u(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
96 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) | ||
97 | +{ | ||
98 | + /* | ||
99 | + * We get here with a negated shift count, and we must handle | ||
100 | + * shifts by the element size, which tcg_gen_gvec_shri() does not do. | ||
101 | + */ | ||
102 | + shift = -shift; | ||
103 | + if (shift == (8 << vece)) { | ||
104 | + tcg_gen_gvec_dup_imm(vece, dofs, oprsz, maxsz, 0); | ||
105 | + } else { | ||
106 | + tcg_gen_gvec_shri(vece, dofs, aofs, shift, oprsz, maxsz); | ||
107 | + } | ||
108 | +} | ||
109 | + | ||
110 | +DO_2SHIFT_VEC(VSHLI, vshli_u, false, tcg_gen_gvec_shli) | ||
111 | DO_2SHIFT(VQSHLI_S, vqshli_s, false) | ||
112 | DO_2SHIFT(VQSHLI_U, vqshli_u, false) | ||
113 | DO_2SHIFT(VQSHLUI, vqshlui_s, false) | ||
114 | /* These right shifts use a left-shift helper with negated shift count */ | ||
115 | -DO_2SHIFT(VSHRI_S, vshli_s, true) | ||
116 | -DO_2SHIFT(VSHRI_U, vshli_u, true) | ||
117 | +DO_2SHIFT_VEC(VSHRI_S, vshli_s, true, do_gvec_shri_s) | ||
118 | +DO_2SHIFT_VEC(VSHRI_U, vshli_u, true, do_gvec_shri_u) | ||
119 | DO_2SHIFT(VRSHRI_S, vrshli_s, true) | ||
120 | DO_2SHIFT(VRSHRI_U, vrshli_u, true) | ||
121 | |||
90 | -- | 122 | -- |
91 | 2.17.0 | 123 | 2.20.1 |
92 | 124 | ||
93 | 125 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | Optimize the MVE VSHLL insns by using TCG vector ops when possible. |
---|---|---|---|
2 | This includes the VMOVL insn, which we handle in mve.decode as "VSHLL | ||
3 | with zero shift count". | ||
2 | 4 | ||
3 | Cc: qemu-stable@nongnu.org | ||
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Message-id: 20180512003217.9105-4-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20210913095440.13462-11-peter.maydell@linaro.org | ||
9 | --- | 8 | --- |
10 | target/arm/helper.h | 6 +++ | 9 | target/arm/translate-mve.c | 67 +++++++++++++++++++++++++++++++++----- |
11 | target/arm/helper.c | 38 ++++++++++++++- | 10 | 1 file changed, 59 insertions(+), 8 deletions(-) |
12 | target/arm/translate-a64.c | 96 +++++++++++++++++++++++++++++++------- | ||
13 | 3 files changed, 122 insertions(+), 18 deletions(-) | ||
14 | 11 | ||
15 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 12 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
16 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.h | 14 | --- a/target/arm/translate-mve.c |
18 | +++ b/target/arm/helper.h | 15 | +++ b/target/arm/translate-mve.c |
19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_touhd_round_to_zero, i64, f64, i32, ptr) | 16 | @@ -XXX,XX +XXX,XX @@ DO_2SHIFT_SCALAR(VQSHL_U_scalar, vqshli_u) |
20 | DEF_HELPER_3(vfp_tould_round_to_zero, i64, f64, i32, ptr) | 17 | DO_2SHIFT_SCALAR(VQRSHL_S_scalar, vqrshli_s) |
21 | DEF_HELPER_3(vfp_touhh, i32, f16, i32, ptr) | 18 | DO_2SHIFT_SCALAR(VQRSHL_U_scalar, vqrshli_u) |
22 | DEF_HELPER_3(vfp_toshh, i32, f16, i32, ptr) | 19 | |
23 | +DEF_HELPER_3(vfp_toulh, i32, f16, i32, ptr) | 20 | -#define DO_VSHLL(INSN, FN) \ |
24 | +DEF_HELPER_3(vfp_toslh, i32, f16, i32, ptr) | 21 | - static bool trans_##INSN(DisasContext *s, arg_2shift *a) \ |
25 | +DEF_HELPER_3(vfp_touqh, i64, f16, i32, ptr) | 22 | - { \ |
26 | +DEF_HELPER_3(vfp_tosqh, i64, f16, i32, ptr) | 23 | - static MVEGenTwoOpShiftFn * const fns[] = { \ |
27 | DEF_HELPER_3(vfp_toshs, i32, f32, i32, ptr) | 24 | - gen_helper_mve_##FN##b, \ |
28 | DEF_HELPER_3(vfp_tosls, i32, f32, i32, ptr) | 25 | - gen_helper_mve_##FN##h, \ |
29 | DEF_HELPER_3(vfp_tosqs, i64, f32, i32, ptr) | 26 | - }; \ |
30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_ultod, f64, i64, i32, ptr) | 27 | - return do_2shift(s, a, fns[a->size], false); \ |
31 | DEF_HELPER_3(vfp_uqtod, f64, i64, i32, ptr) | 28 | +#define DO_VSHLL(INSN, FN) \ |
32 | DEF_HELPER_3(vfp_sltoh, f16, i32, i32, ptr) | 29 | + static bool trans_##INSN(DisasContext *s, arg_2shift *a) \ |
33 | DEF_HELPER_3(vfp_ultoh, f16, i32, i32, ptr) | 30 | + { \ |
34 | +DEF_HELPER_3(vfp_sqtoh, f16, i64, i32, ptr) | 31 | + static MVEGenTwoOpShiftFn * const fns[] = { \ |
35 | +DEF_HELPER_3(vfp_uqtoh, f16, i64, i32, ptr) | 32 | + gen_helper_mve_##FN##b, \ |
36 | 33 | + gen_helper_mve_##FN##h, \ | |
37 | DEF_HELPER_FLAGS_2(set_rmode, TCG_CALL_NO_RWG, i32, i32, ptr) | 34 | + }; \ |
38 | DEF_HELPER_FLAGS_2(set_neon_rmode, TCG_CALL_NO_RWG, i32, i32, env) | 35 | + return do_2shift_vec(s, a, fns[a->size], false, do_gvec_##FN); \ |
39 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 36 | } |
40 | index XXXXXXX..XXXXXXX 100644 | 37 | |
41 | --- a/target/arm/helper.c | 38 | +/* |
42 | +++ b/target/arm/helper.c | 39 | + * For the VSHLL vector helpers, the vece is the size of the input |
43 | @@ -XXX,XX +XXX,XX @@ VFP_CONV_FIX_A64(uq, s, 32, 64, uint64) | 40 | + * (ie MO_8 or MO_16); the helpers want to work in the output size. |
44 | #undef VFP_CONV_FIX_A64 | 41 | + * The shift count can be 0..<input size>, inclusive. (0 is VMOVL.) |
45 | 42 | + */ | |
46 | /* Conversion to/from f16 can overflow to infinity before/after scaling. | 43 | +static void do_gvec_vshllbs(unsigned vece, uint32_t dofs, uint32_t aofs, |
47 | - * Therefore we convert to f64 (which does not round), scale, | 44 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) |
48 | - * and then convert f64 to f16 (which may round). | ||
49 | + * Therefore we convert to f64, scale, and then convert f64 to f16; or | ||
50 | + * vice versa for conversion to integer. | ||
51 | + * | ||
52 | + * For 16- and 32-bit integers, the conversion to f64 never rounds. | ||
53 | + * For 64-bit integers, any integer that would cause rounding will also | ||
54 | + * overflow to f16 infinity, so there is no double rounding problem. | ||
55 | */ | ||
56 | |||
57 | static float16 do_postscale_fp16(float64 f, int shift, float_status *fpst) | ||
58 | @@ -XXX,XX +XXX,XX @@ float16 HELPER(vfp_ultoh)(uint32_t x, uint32_t shift, void *fpst) | ||
59 | return do_postscale_fp16(uint32_to_float64(x, fpst), shift, fpst); | ||
60 | } | ||
61 | |||
62 | +float16 HELPER(vfp_sqtoh)(uint64_t x, uint32_t shift, void *fpst) | ||
63 | +{ | 45 | +{ |
64 | + return do_postscale_fp16(int64_to_float64(x, fpst), shift, fpst); | 46 | + unsigned ovece = vece + 1; |
47 | + unsigned ibits = vece == MO_8 ? 8 : 16; | ||
48 | + tcg_gen_gvec_shli(ovece, dofs, aofs, ibits, oprsz, maxsz); | ||
49 | + tcg_gen_gvec_sari(ovece, dofs, dofs, ibits - shift, oprsz, maxsz); | ||
65 | +} | 50 | +} |
66 | + | 51 | + |
67 | +float16 HELPER(vfp_uqtoh)(uint64_t x, uint32_t shift, void *fpst) | 52 | +static void do_gvec_vshllbu(unsigned vece, uint32_t dofs, uint32_t aofs, |
53 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) | ||
68 | +{ | 54 | +{ |
69 | + return do_postscale_fp16(uint64_to_float64(x, fpst), shift, fpst); | 55 | + unsigned ovece = vece + 1; |
56 | + tcg_gen_gvec_andi(ovece, dofs, aofs, | ||
57 | + ovece == MO_16 ? 0xff : 0xffff, oprsz, maxsz); | ||
58 | + tcg_gen_gvec_shli(ovece, dofs, dofs, shift, oprsz, maxsz); | ||
70 | +} | 59 | +} |
71 | + | 60 | + |
72 | static float64 do_prescale_fp16(float16 f, int shift, float_status *fpst) | 61 | +static void do_gvec_vshllts(unsigned vece, uint32_t dofs, uint32_t aofs, |
73 | { | 62 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) |
74 | if (unlikely(float16_is_any_nan(f))) { | ||
75 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(vfp_touhh)(float16 x, uint32_t shift, void *fpst) | ||
76 | return float64_to_uint16(do_prescale_fp16(x, shift, fpst), fpst); | ||
77 | } | ||
78 | |||
79 | +uint32_t HELPER(vfp_toslh)(float16 x, uint32_t shift, void *fpst) | ||
80 | +{ | 63 | +{ |
81 | + return float64_to_int32(do_prescale_fp16(x, shift, fpst), fpst); | 64 | + unsigned ovece = vece + 1; |
65 | + unsigned ibits = vece == MO_8 ? 8 : 16; | ||
66 | + if (shift == 0) { | ||
67 | + tcg_gen_gvec_sari(ovece, dofs, aofs, ibits, oprsz, maxsz); | ||
68 | + } else { | ||
69 | + tcg_gen_gvec_andi(ovece, dofs, aofs, | ||
70 | + ovece == MO_16 ? 0xff00 : 0xffff0000, oprsz, maxsz); | ||
71 | + tcg_gen_gvec_sari(ovece, dofs, dofs, ibits - shift, oprsz, maxsz); | ||
72 | + } | ||
82 | +} | 73 | +} |
83 | + | 74 | + |
84 | +uint32_t HELPER(vfp_toulh)(float16 x, uint32_t shift, void *fpst) | 75 | +static void do_gvec_vshlltu(unsigned vece, uint32_t dofs, uint32_t aofs, |
76 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) | ||
85 | +{ | 77 | +{ |
86 | + return float64_to_uint32(do_prescale_fp16(x, shift, fpst), fpst); | 78 | + unsigned ovece = vece + 1; |
79 | + unsigned ibits = vece == MO_8 ? 8 : 16; | ||
80 | + if (shift == 0) { | ||
81 | + tcg_gen_gvec_shri(ovece, dofs, aofs, ibits, oprsz, maxsz); | ||
82 | + } else { | ||
83 | + tcg_gen_gvec_andi(ovece, dofs, aofs, | ||
84 | + ovece == MO_16 ? 0xff00 : 0xffff0000, oprsz, maxsz); | ||
85 | + tcg_gen_gvec_shri(ovece, dofs, dofs, ibits - shift, oprsz, maxsz); | ||
86 | + } | ||
87 | +} | 87 | +} |
88 | + | 88 | + |
89 | +uint64_t HELPER(vfp_tosqh)(float16 x, uint32_t shift, void *fpst) | 89 | DO_VSHLL(VSHLL_BS, vshllbs) |
90 | +{ | 90 | DO_VSHLL(VSHLL_BU, vshllbu) |
91 | + return float64_to_int64(do_prescale_fp16(x, shift, fpst), fpst); | 91 | DO_VSHLL(VSHLL_TS, vshllts) |
92 | +} | ||
93 | + | ||
94 | +uint64_t HELPER(vfp_touqh)(float16 x, uint32_t shift, void *fpst) | ||
95 | +{ | ||
96 | + return float64_to_uint64(do_prescale_fp16(x, shift, fpst), fpst); | ||
97 | +} | ||
98 | + | ||
99 | /* Set the current fp rounding mode and return the old one. | ||
100 | * The argument is a softfloat float_round_ value. | ||
101 | */ | ||
102 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/target/arm/translate-a64.c | ||
105 | +++ b/target/arm/translate-a64.c | ||
106 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
107 | bool itof, int rmode, int scale, int sf, int type) | ||
108 | { | ||
109 | bool is_signed = !(opcode & 1); | ||
110 | - bool is_double = type; | ||
111 | TCGv_ptr tcg_fpstatus; | ||
112 | - TCGv_i32 tcg_shift; | ||
113 | + TCGv_i32 tcg_shift, tcg_single; | ||
114 | + TCGv_i64 tcg_double; | ||
115 | |||
116 | - tcg_fpstatus = get_fpstatus_ptr(false); | ||
117 | + tcg_fpstatus = get_fpstatus_ptr(type == 3); | ||
118 | |||
119 | tcg_shift = tcg_const_i32(64 - scale); | ||
120 | |||
121 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
122 | tcg_int = tcg_extend; | ||
123 | } | ||
124 | |||
125 | - if (is_double) { | ||
126 | - TCGv_i64 tcg_double = tcg_temp_new_i64(); | ||
127 | + switch (type) { | ||
128 | + case 1: /* float64 */ | ||
129 | + tcg_double = tcg_temp_new_i64(); | ||
130 | if (is_signed) { | ||
131 | gen_helper_vfp_sqtod(tcg_double, tcg_int, | ||
132 | tcg_shift, tcg_fpstatus); | ||
133 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
134 | } | ||
135 | write_fp_dreg(s, rd, tcg_double); | ||
136 | tcg_temp_free_i64(tcg_double); | ||
137 | - } else { | ||
138 | - TCGv_i32 tcg_single = tcg_temp_new_i32(); | ||
139 | + break; | ||
140 | + | ||
141 | + case 0: /* float32 */ | ||
142 | + tcg_single = tcg_temp_new_i32(); | ||
143 | if (is_signed) { | ||
144 | gen_helper_vfp_sqtos(tcg_single, tcg_int, | ||
145 | tcg_shift, tcg_fpstatus); | ||
146 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
147 | } | ||
148 | write_fp_sreg(s, rd, tcg_single); | ||
149 | tcg_temp_free_i32(tcg_single); | ||
150 | + break; | ||
151 | + | ||
152 | + case 3: /* float16 */ | ||
153 | + tcg_single = tcg_temp_new_i32(); | ||
154 | + if (is_signed) { | ||
155 | + gen_helper_vfp_sqtoh(tcg_single, tcg_int, | ||
156 | + tcg_shift, tcg_fpstatus); | ||
157 | + } else { | ||
158 | + gen_helper_vfp_uqtoh(tcg_single, tcg_int, | ||
159 | + tcg_shift, tcg_fpstatus); | ||
160 | + } | ||
161 | + write_fp_sreg(s, rd, tcg_single); | ||
162 | + tcg_temp_free_i32(tcg_single); | ||
163 | + break; | ||
164 | + | ||
165 | + default: | ||
166 | + g_assert_not_reached(); | ||
167 | } | ||
168 | } else { | ||
169 | TCGv_i64 tcg_int = cpu_reg(s, rd); | ||
170 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
171 | |||
172 | gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus); | ||
173 | |||
174 | - if (is_double) { | ||
175 | - TCGv_i64 tcg_double = read_fp_dreg(s, rn); | ||
176 | + switch (type) { | ||
177 | + case 1: /* float64 */ | ||
178 | + tcg_double = read_fp_dreg(s, rn); | ||
179 | if (is_signed) { | ||
180 | if (!sf) { | ||
181 | gen_helper_vfp_tosld(tcg_int, tcg_double, | ||
182 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
183 | tcg_shift, tcg_fpstatus); | ||
184 | } | ||
185 | } | ||
186 | + if (!sf) { | ||
187 | + tcg_gen_ext32u_i64(tcg_int, tcg_int); | ||
188 | + } | ||
189 | tcg_temp_free_i64(tcg_double); | ||
190 | - } else { | ||
191 | - TCGv_i32 tcg_single = read_fp_sreg(s, rn); | ||
192 | + break; | ||
193 | + | ||
194 | + case 0: /* float32 */ | ||
195 | + tcg_single = read_fp_sreg(s, rn); | ||
196 | if (sf) { | ||
197 | if (is_signed) { | ||
198 | gen_helper_vfp_tosqs(tcg_int, tcg_single, | ||
199 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, | ||
200 | tcg_temp_free_i32(tcg_dest); | ||
201 | } | ||
202 | tcg_temp_free_i32(tcg_single); | ||
203 | + break; | ||
204 | + | ||
205 | + case 3: /* float16 */ | ||
206 | + tcg_single = read_fp_sreg(s, rn); | ||
207 | + if (sf) { | ||
208 | + if (is_signed) { | ||
209 | + gen_helper_vfp_tosqh(tcg_int, tcg_single, | ||
210 | + tcg_shift, tcg_fpstatus); | ||
211 | + } else { | ||
212 | + gen_helper_vfp_touqh(tcg_int, tcg_single, | ||
213 | + tcg_shift, tcg_fpstatus); | ||
214 | + } | ||
215 | + } else { | ||
216 | + TCGv_i32 tcg_dest = tcg_temp_new_i32(); | ||
217 | + if (is_signed) { | ||
218 | + gen_helper_vfp_toslh(tcg_dest, tcg_single, | ||
219 | + tcg_shift, tcg_fpstatus); | ||
220 | + } else { | ||
221 | + gen_helper_vfp_toulh(tcg_dest, tcg_single, | ||
222 | + tcg_shift, tcg_fpstatus); | ||
223 | + } | ||
224 | + tcg_gen_extu_i32_i64(tcg_int, tcg_dest); | ||
225 | + tcg_temp_free_i32(tcg_dest); | ||
226 | + } | ||
227 | + tcg_temp_free_i32(tcg_single); | ||
228 | + break; | ||
229 | + | ||
230 | + default: | ||
231 | + g_assert_not_reached(); | ||
232 | } | ||
233 | |||
234 | gen_helper_set_rmode(tcg_rmode, tcg_rmode, tcg_fpstatus); | ||
235 | tcg_temp_free_i32(tcg_rmode); | ||
236 | - | ||
237 | - if (!sf) { | ||
238 | - tcg_gen_ext32u_i64(tcg_int, tcg_int); | ||
239 | - } | ||
240 | } | ||
241 | |||
242 | tcg_temp_free_ptr(tcg_fpstatus); | ||
243 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) | ||
244 | /* actual FP conversions */ | ||
245 | bool itof = extract32(opcode, 1, 1); | ||
246 | |||
247 | - if (type > 1 || (rmode != 0 && opcode > 1)) { | ||
248 | + if (rmode != 0 && opcode > 1) { | ||
249 | + unallocated_encoding(s); | ||
250 | + return; | ||
251 | + } | ||
252 | + switch (type) { | ||
253 | + case 0: /* float32 */ | ||
254 | + case 1: /* float64 */ | ||
255 | + break; | ||
256 | + case 3: /* float16 */ | ||
257 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
258 | + break; | ||
259 | + } | ||
260 | + /* fallthru */ | ||
261 | + default: | ||
262 | unallocated_encoding(s); | ||
263 | return; | ||
264 | } | ||
265 | -- | 92 | -- |
266 | 2.17.0 | 93 | 2.20.1 |
267 | 94 | ||
268 | 95 | diff view generated by jsdifflib |
1 | In float-to-integer conversion, if the floating point input | 1 | Optimize the MVE shift-and-insert insns by using TCG |
---|---|---|---|
2 | converts exactly to the largest or smallest integer that | 2 | vector ops when possible. |
3 | fits in to the result type, this is not an overflow. | ||
4 | In this situation we were producing the correct result value, | ||
5 | but were incorrectly setting the Invalid flag. | ||
6 | For example for Arm A64, "FCVTAS w0, d0" on an input of | ||
7 | 0x41dfffffffc00000 should produce 0x7fffffff and set no flags. | ||
8 | 3 | ||
9 | Fix the boundary case to take the right half of the if() | ||
10 | statements. | ||
11 | |||
12 | This fixes a regression from 2.11 introduced by the softfloat | ||
13 | refactoring. | ||
14 | |||
15 | Cc: qemu-stable@nongnu.org | ||
16 | Fixes: ab52f973a50 | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
19 | Message-id: 20180510140141.12120-1-peter.maydell@linaro.org | 6 | Message-id: 20210913095440.13462-12-peter.maydell@linaro.org |
20 | --- | 7 | --- |
21 | fpu/softfloat.c | 4 ++-- | 8 | target/arm/translate-mve.c | 4 ++-- |
22 | 1 file changed, 2 insertions(+), 2 deletions(-) | 9 | 1 file changed, 2 insertions(+), 2 deletions(-) |
23 | 10 | ||
24 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | 11 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
25 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/fpu/softfloat.c | 13 | --- a/target/arm/translate-mve.c |
27 | +++ b/fpu/softfloat.c | 14 | +++ b/target/arm/translate-mve.c |
28 | @@ -XXX,XX +XXX,XX @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode, | 15 | @@ -XXX,XX +XXX,XX @@ DO_2SHIFT_VEC(VSHRI_U, vshli_u, true, do_gvec_shri_u) |
29 | r = UINT64_MAX; | 16 | DO_2SHIFT(VRSHRI_S, vrshli_s, true) |
30 | } | 17 | DO_2SHIFT(VRSHRI_U, vrshli_u, true) |
31 | if (p.sign) { | 18 | |
32 | - if (r < -(uint64_t) min) { | 19 | -DO_2SHIFT(VSRI, vsri, false) |
33 | + if (r <= -(uint64_t) min) { | 20 | -DO_2SHIFT(VSLI, vsli, false) |
34 | return -r; | 21 | +DO_2SHIFT_VEC(VSRI, vsri, false, gen_gvec_sri) |
35 | } else { | 22 | +DO_2SHIFT_VEC(VSLI, vsli, false, gen_gvec_sli) |
36 | s->float_exception_flags = orig_flags | float_flag_invalid; | 23 | |
37 | return min; | 24 | #define DO_2SHIFT_FP(INSN, FN) \ |
38 | } | 25 | static bool trans_##INSN(DisasContext *s, arg_2shift *a) \ |
39 | } else { | ||
40 | - if (r < max) { | ||
41 | + if (r <= max) { | ||
42 | return r; | ||
43 | } else { | ||
44 | s->float_exception_flags = orig_flags | float_flag_invalid; | ||
45 | -- | 26 | -- |
46 | 2.17.0 | 27 | 2.20.1 |
47 | 28 | ||
48 | 29 | diff view generated by jsdifflib |
1 | Usually the logging of the CPU state produced by -d cpu is sufficient | 1 | Optimize the MVE 1op-immediate insns (VORR, VBIC, VMOV) to |
---|---|---|---|
2 | to diagnose problems, but sometimes you want to see the state of | 2 | use TCG vector ops when possible. |
3 | the floating point registers as well. We don't want to enable that | ||
4 | by default as it adds a lot of extra data to the log; instead, | ||
5 | allow it to be optionally enabled via -d fpu. | ||
6 | 3 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20180510130024.31678-1-peter.maydell@linaro.org | 6 | Message-id: 20210913095440.13462-13-peter.maydell@linaro.org |
10 | --- | 7 | --- |
11 | include/qemu/log.h | 1 + | 8 | target/arm/translate-mve.c | 26 +++++++++++++++++++++----- |
12 | accel/tcg/cpu-exec.c | 9 ++++++--- | 9 | 1 file changed, 21 insertions(+), 5 deletions(-) |
13 | util/log.c | 2 ++ | ||
14 | 3 files changed, 9 insertions(+), 3 deletions(-) | ||
15 | 10 | ||
16 | diff --git a/include/qemu/log.h b/include/qemu/log.h | 11 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
17 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/include/qemu/log.h | 13 | --- a/target/arm/translate-mve.c |
19 | +++ b/include/qemu/log.h | 14 | +++ b/target/arm/translate-mve.c |
20 | @@ -XXX,XX +XXX,XX @@ static inline bool qemu_log_separate(void) | 15 | @@ -XXX,XX +XXX,XX @@ static bool trans_VADDLV(DisasContext *s, arg_VADDLV *a) |
21 | #define CPU_LOG_PAGE (1 << 14) | 16 | return true; |
22 | /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ | 17 | } |
23 | #define CPU_LOG_TB_OP_IND (1 << 16) | 18 | |
24 | +#define CPU_LOG_TB_FPU (1 << 17) | 19 | -static bool do_1imm(DisasContext *s, arg_1imm *a, MVEGenOneOpImmFn *fn) |
25 | 20 | +static bool do_1imm(DisasContext *s, arg_1imm *a, MVEGenOneOpImmFn *fn, | |
26 | /* Lock output for a series of related logs. Since this is not needed | 21 | + GVecGen2iFn *vecfn) |
27 | * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we | 22 | { |
28 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c | 23 | TCGv_ptr qd; |
29 | index XXXXXXX..XXXXXXX 100644 | 24 | uint64_t imm; |
30 | --- a/accel/tcg/cpu-exec.c | 25 | @@ -XXX,XX +XXX,XX @@ static bool do_1imm(DisasContext *s, arg_1imm *a, MVEGenOneOpImmFn *fn) |
31 | +++ b/accel/tcg/cpu-exec.c | 26 | |
32 | @@ -XXX,XX +XXX,XX @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) | 27 | imm = asimd_imm_const(a->imm, a->cmode, a->op); |
33 | if (qemu_loglevel_mask(CPU_LOG_TB_CPU) | 28 | |
34 | && qemu_log_in_addr_range(itb->pc)) { | 29 | - qd = mve_qreg_ptr(a->qd); |
35 | qemu_log_lock(); | 30 | - fn(cpu_env, qd, tcg_constant_i64(imm)); |
36 | + int flags = 0; | 31 | - tcg_temp_free_ptr(qd); |
37 | + if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) { | 32 | + if (vecfn && mve_no_predication(s)) { |
38 | + flags |= CPU_DUMP_FPU; | 33 | + vecfn(MO_64, mve_qreg_offset(a->qd), mve_qreg_offset(a->qd), |
39 | + } | 34 | + imm, 16, 16); |
40 | #if defined(TARGET_I386) | 35 | + } else { |
41 | - log_cpu_state(cpu, CPU_DUMP_CCOP); | 36 | + qd = mve_qreg_ptr(a->qd); |
42 | -#else | 37 | + fn(cpu_env, qd, tcg_constant_i64(imm)); |
43 | - log_cpu_state(cpu, 0); | 38 | + tcg_temp_free_ptr(qd); |
44 | + flags |= CPU_DUMP_CCOP; | 39 | + } |
45 | #endif | 40 | mve_update_eci(s); |
46 | + log_cpu_state(cpu, flags); | 41 | return true; |
47 | qemu_log_unlock(); | 42 | } |
43 | |||
44 | +static void gen_gvec_vmovi(unsigned vece, uint32_t dofs, uint32_t aofs, | ||
45 | + int64_t c, uint32_t oprsz, uint32_t maxsz) | ||
46 | +{ | ||
47 | + tcg_gen_gvec_dup_imm(vece, dofs, oprsz, maxsz, c); | ||
48 | +} | ||
49 | + | ||
50 | static bool trans_Vimm_1r(DisasContext *s, arg_1imm *a) | ||
51 | { | ||
52 | /* Handle decode of cmode/op here between VORR/VBIC/VMOV */ | ||
53 | MVEGenOneOpImmFn *fn; | ||
54 | + GVecGen2iFn *vecfn; | ||
55 | |||
56 | if ((a->cmode & 1) && a->cmode < 12) { | ||
57 | if (a->op) { | ||
58 | @@ -XXX,XX +XXX,XX @@ static bool trans_Vimm_1r(DisasContext *s, arg_1imm *a) | ||
59 | * so the VBIC becomes a logical AND operation. | ||
60 | */ | ||
61 | fn = gen_helper_mve_vandi; | ||
62 | + vecfn = tcg_gen_gvec_andi; | ||
63 | } else { | ||
64 | fn = gen_helper_mve_vorri; | ||
65 | + vecfn = tcg_gen_gvec_ori; | ||
66 | } | ||
67 | } else { | ||
68 | /* There is one unallocated cmode/op combination in this space */ | ||
69 | @@ -XXX,XX +XXX,XX @@ static bool trans_Vimm_1r(DisasContext *s, arg_1imm *a) | ||
70 | } | ||
71 | /* asimd_imm_const() sorts out VMVNI vs VMOVI for us */ | ||
72 | fn = gen_helper_mve_vmovi; | ||
73 | + vecfn = gen_gvec_vmovi; | ||
48 | } | 74 | } |
49 | #endif /* DEBUG_DISAS */ | 75 | - return do_1imm(s, a, fn); |
50 | diff --git a/util/log.c b/util/log.c | 76 | + return do_1imm(s, a, fn, vecfn); |
51 | index XXXXXXX..XXXXXXX 100644 | 77 | } |
52 | --- a/util/log.c | 78 | |
53 | +++ b/util/log.c | 79 | static bool do_2shift_vec(DisasContext *s, arg_2shift *a, MVEGenTwoOpShiftFn fn, |
54 | @@ -XXX,XX +XXX,XX @@ const QEMULogItem qemu_log_items[] = { | ||
55 | "show trace before each executed TB (lots of logs)" }, | ||
56 | { CPU_LOG_TB_CPU, "cpu", | ||
57 | "show CPU registers before entering a TB (lots of logs)" }, | ||
58 | + { CPU_LOG_TB_FPU, "fpu", | ||
59 | + "include FPU registers in the 'cpu' logging" }, | ||
60 | { CPU_LOG_MMU, "mmu", | ||
61 | "log MMU-related activities" }, | ||
62 | { CPU_LOG_PCALL, "pcall", | ||
63 | -- | 80 | -- |
64 | 2.17.0 | 81 | 2.20.1 |
65 | 82 | ||
66 | 83 | diff view generated by jsdifflib |