1 | target-arm queue: | 1 | The following changes since commit ad1b4ec39caa5b3f17cbd8160283a03a3dcfe2ae: |
---|---|---|---|
2 | * mostly my latest v8M stuff, plus a couple of minor patches | ||
3 | 2 | ||
4 | The following changes since commit a0b261db8c030813e30a39eae47359ac2a37f7e2: | 3 | Merge remote-tracking branch 'remotes/kraxel/tags/input-20180515-pull-request' into staging (2018-05-15 12:50:06 +0100) |
5 | 4 | ||
6 | Merge remote-tracking branch 'remotes/ehabkost/tags/python-next-pull-request' into staging (2017-10-12 10:02:09 +0100) | 5 | are available in the Git repository at: |
7 | 6 | ||
8 | are available in the git repository at: | 7 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180515 |
9 | 8 | ||
10 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20171012 | 9 | for you to fetch changes up to ae7651804748c6b479d5ae09aeac4edb9c44f76e: |
11 | 10 | ||
12 | for you to fetch changes up to cf5f7937b05c84d5565134f058c00cd48304a117: | 11 | tcg: Optionally log FPU state in TCG -d cpu logging (2018-05-15 14:58:44 +0100) |
13 | |||
14 | nvic: Fix miscalculation of offsets into ITNS array (2017-10-12 16:33:16 +0100) | ||
15 | 12 | ||
16 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
17 | target-arm queue: | 14 | target-arm queue: |
18 | * v8M: SG, BLXNS, secure-return | 15 | * Fix coverity nit in int_to_float code |
19 | * v8M: fixes for coverity issues in previous patches | 16 | * Don't set Invalid for float-to-int(MAXINT) |
20 | * arm: fix armv7m_init() declaration to match definition | 17 | * Fix fp_status_f16 tininess before rounding |
21 | * watchdog/aspeed: fix variable type to store reload value | 18 | * Add various missing insns from the v8.2-FP16 extension |
19 | * Fix sqrt_f16 exception raising | ||
20 | * sdcard: Correct CRC16 offset in sd_function_switch() | ||
21 | * tcg: Optionally log FPU state in TCG -d cpu logging | ||
22 | 22 | ||
23 | ---------------------------------------------------------------- | 23 | ---------------------------------------------------------------- |
24 | Cédric Le Goater (1): | 24 | Alex Bennée (5): |
25 | watchdog/aspeed: fix variable type to store reload value | 25 | fpu/softfloat: int_to_float ensure r fully initialised |
26 | target/arm: Implement FCMP for fp16 | ||
27 | target/arm: Implement FCSEL for fp16 | ||
28 | target/arm: Implement FMOV (immediate) for fp16 | ||
29 | target/arm: Fix sqrt_f16 exception raising | ||
26 | 30 | ||
27 | Igor Mammedov (1): | 31 | Peter Maydell (3): |
28 | arm: fix armv7m_init() declaration to match definition | 32 | fpu/softfloat: Don't set Invalid for float-to-int(MAXINT) |
33 | target/arm: Fix fp_status_f16 tininess before rounding | ||
34 | tcg: Optionally log FPU state in TCG -d cpu logging | ||
29 | 35 | ||
30 | Peter Maydell (11): | 36 | Philippe Mathieu-Daudé (1): |
31 | target/arm: Add M profile secure MMU index values to get_a32_user_mem_index() | 37 | sdcard: Correct CRC16 offset in sd_function_switch() |
32 | target/arm: Implement SG instruction | ||
33 | target/arm: Implement BLXNS | ||
34 | target/arm: Implement secure function return | ||
35 | target-arm: Don't check for "Thumb2 or M profile" for not-Thumb1 | ||
36 | target/arm: Pull Thumb insn word loads up to top level | ||
37 | target-arm: Simplify insn_crosses_page() | ||
38 | target/arm: Support some Thumb insns being always unconditional | ||
39 | target/arm: Implement SG instruction corner cases | ||
40 | nvic: Add missing 'break' | ||
41 | nvic: Fix miscalculation of offsets into ITNS array | ||
42 | 38 | ||
43 | include/hw/arm/arm.h | 2 +- | 39 | Richard Henderson (7): |
44 | target/arm/helper.h | 1 + | 40 | target/arm: Implement FMOV (general) for fp16 |
45 | target/arm/internals.h | 8 ++ | 41 | target/arm: Early exit after unallocated_encoding in disas_fp_int_conv |
46 | hw/intc/armv7m_nvic.c | 5 +- | 42 | target/arm: Implement FCVT (scalar, integer) for fp16 |
47 | hw/watchdog/wdt_aspeed.c | 4 +- | 43 | target/arm: Implement FCVT (scalar, fixed-point) for fp16 |
48 | target/arm/helper.c | 306 ++++++++++++++++++++++++++++++++++++++++++++-- | 44 | target/arm: Introduce and use read_fp_hreg |
49 | target/arm/translate.c | 310 ++++++++++++++++++++++++++++++++--------------- | 45 | target/arm: Implement FP data-processing (2 source) for fp16 |
50 | 7 files changed, 521 insertions(+), 115 deletions(-) | 46 | target/arm: Implement FP data-processing (3 source) for fp16 |
51 | 47 | ||
48 | include/qemu/log.h | 1 + | ||
49 | target/arm/helper-a64.h | 2 + | ||
50 | target/arm/helper.h | 6 + | ||
51 | accel/tcg/cpu-exec.c | 9 +- | ||
52 | fpu/softfloat.c | 6 +- | ||
53 | hw/sd/sd.c | 2 +- | ||
54 | target/arm/cpu.c | 2 + | ||
55 | target/arm/helper-a64.c | 10 ++ | ||
56 | target/arm/helper.c | 38 +++- | ||
57 | target/arm/translate-a64.c | 421 ++++++++++++++++++++++++++++++++++++++------- | ||
58 | util/log.c | 2 + | ||
59 | 11 files changed, 428 insertions(+), 71 deletions(-) | ||
60 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alex Bennée <alex.bennee@linaro.org> | ||
1 | 2 | ||
3 | Reported by Coverity (CID1390635). We ensure this for uint_to_float | ||
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> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | fpu/softfloat.c | 2 +- | ||
12 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/fpu/softfloat.c | ||
17 | +++ b/fpu/softfloat.c | ||
18 | @@ -XXX,XX +XXX,XX @@ FLOAT_TO_UINT(64, 64) | ||
19 | |||
20 | static FloatParts int_to_float(int64_t a, float_status *status) | ||
21 | { | ||
22 | - FloatParts r; | ||
23 | + FloatParts r = {}; | ||
24 | if (a == 0) { | ||
25 | r.cls = float_class_zero; | ||
26 | r.sign = false; | ||
27 | -- | ||
28 | 2.17.0 | ||
29 | |||
30 | diff view generated by jsdifflib |
1 | This calculation of the first exception vector in | 1 | In float-to-integer conversion, if the floating point input |
---|---|---|---|
2 | the ITNS<n> register being accessed: | 2 | converts exactly to the largest or smallest integer that |
3 | int startvec = 32 * (offset - 0x380) + NVIC_FIRST_IRQ; | 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. | ||
4 | 8 | ||
5 | is incorrect, because offset is in bytes, so we only want | 9 | Fix the boundary case to take the right half of the if() |
6 | to multiply by 8. | 10 | statements. |
7 | 11 | ||
8 | Spotted by Coverity (CID 1381484, CID 1381488), though it is | 12 | This fixes a regression from 2.11 introduced by the softfloat |
9 | not correct that it actually overflows the buffer, because | 13 | refactoring. |
10 | we have a 'startvec + i < s->num_irq' guard. | ||
11 | 14 | ||
15 | Cc: qemu-stable@nongnu.org | ||
16 | Fixes: ab52f973a50 | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 18 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
14 | Message-id: 1507650856-11718-1-git-send-email-peter.maydell@linaro.org | 19 | Message-id: 20180510140141.12120-1-peter.maydell@linaro.org |
15 | --- | 20 | --- |
16 | hw/intc/armv7m_nvic.c | 4 ++-- | 21 | fpu/softfloat.c | 4 ++-- |
17 | 1 file changed, 2 insertions(+), 2 deletions(-) | 22 | 1 file changed, 2 insertions(+), 2 deletions(-) |
18 | 23 | ||
19 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 24 | diff --git a/fpu/softfloat.c b/fpu/softfloat.c |
20 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/intc/armv7m_nvic.c | 26 | --- a/fpu/softfloat.c |
22 | +++ b/hw/intc/armv7m_nvic.c | 27 | +++ b/fpu/softfloat.c |
23 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | 28 | @@ -XXX,XX +XXX,XX @@ static int64_t round_to_int_and_pack(FloatParts in, int rmode, |
24 | return ((s->num_irq - NVIC_FIRST_IRQ) / 32) - 1; | 29 | r = UINT64_MAX; |
25 | case 0x380 ... 0x3bf: /* NVIC_ITNS<n> */ | 30 | } |
26 | { | 31 | if (p.sign) { |
27 | - int startvec = 32 * (offset - 0x380) + NVIC_FIRST_IRQ; | 32 | - if (r < -(uint64_t) min) { |
28 | + int startvec = 8 * (offset - 0x380) + NVIC_FIRST_IRQ; | 33 | + if (r <= -(uint64_t) min) { |
29 | int i; | 34 | return -r; |
30 | 35 | } else { | |
31 | if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) { | 36 | s->float_exception_flags = orig_flags | float_flag_invalid; |
32 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | 37 | return min; |
33 | switch (offset) { | 38 | } |
34 | case 0x380 ... 0x3bf: /* NVIC_ITNS<n> */ | 39 | } else { |
35 | { | 40 | - if (r < max) { |
36 | - int startvec = 32 * (offset - 0x380) + NVIC_FIRST_IRQ; | 41 | + if (r <= max) { |
37 | + int startvec = 8 * (offset - 0x380) + NVIC_FIRST_IRQ; | 42 | return r; |
38 | int i; | 43 | } else { |
39 | 44 | s->float_exception_flags = orig_flags | float_flag_invalid; | |
40 | if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) { | ||
41 | -- | 45 | -- |
42 | 2.7.4 | 46 | 2.17.0 |
43 | 47 | ||
44 | 48 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | In commit d81ce0ef2c4f105 we added an extra float_status field | ||
2 | fp_status_fp16 for Arm, but forgot to initialize it correctly | ||
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. | ||
1 | 8 | ||
9 | Add the missing initialization. | ||
10 | |||
11 | Fixes: d81ce0ef2c4f105 | ||
12 | Cc: qemu-stable@nongnu.org | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | Message-id: 20180512004311.9299-16-richard.henderson@linaro.org | ||
17 | --- | ||
18 | target/arm/cpu.c | 2 ++ | ||
19 | 1 file changed, 2 insertions(+) | ||
20 | |||
21 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/arm/cpu.c | ||
24 | +++ b/target/arm/cpu.c | ||
25 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) | ||
26 | &env->vfp.fp_status); | ||
27 | set_float_detect_tininess(float_tininess_before_rounding, | ||
28 | &env->vfp.standard_fp_status); | ||
29 | + set_float_detect_tininess(float_tininess_before_rounding, | ||
30 | + &env->vfp.fp_status_f16); | ||
31 | #ifndef CONFIG_USER_ONLY | ||
32 | if (kvm_enabled()) { | ||
33 | kvm_arm_reset_vcpu(cpu); | ||
34 | -- | ||
35 | 2.17.0 | ||
36 | |||
37 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Initially from Anton D. Kachalov" <mouse@yandex-team.ru> but the SoB was | 3 | Adding the fp16 moves to/from general registers. |
4 | missing. | ||
5 | 4 | ||
6 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 5 | Cc: qemu-stable@nongnu.org |
7 | Acked-by: Andrew Jeffery <andrew@aj.id.au> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20170920064915.30027-1-clg@kaod.org | 7 | Tested-by: Alex Bennée <alex.bennee@linaro.org> |
9 | [clg: change commit log and subject | 8 | Message-id: 20180512003217.9105-2-richard.henderson@linaro.org |
10 | replace UL suffix by ULL ] | ||
11 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@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 | hw/watchdog/wdt_aspeed.c | 4 ++-- | 12 | target/arm/translate-a64.c | 21 +++++++++++++++++++++ |
16 | 1 file changed, 2 insertions(+), 2 deletions(-) | 13 | 1 file changed, 21 insertions(+) |
17 | 14 | ||
18 | diff --git a/hw/watchdog/wdt_aspeed.c b/hw/watchdog/wdt_aspeed.c | 15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
19 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/watchdog/wdt_aspeed.c | 17 | --- a/target/arm/translate-a64.c |
21 | +++ b/hw/watchdog/wdt_aspeed.c | 18 | +++ b/target/arm/translate-a64.c |
22 | @@ -XXX,XX +XXX,XX @@ static uint64_t aspeed_wdt_read(void *opaque, hwaddr offset, unsigned size) | 19 | @@ -XXX,XX +XXX,XX @@ static void handle_fmov(DisasContext *s, int rd, int rn, int type, bool itof) |
23 | 20 | tcg_gen_st_i64(tcg_rn, cpu_env, fp_reg_hi_offset(s, rd)); | |
24 | static void aspeed_wdt_reload(AspeedWDTState *s, bool pclk) | 21 | clear_vec_high(s, true, rd); |
25 | { | 22 | break; |
26 | - uint32_t reload; | 23 | + case 3: |
27 | + uint64_t reload; | 24 | + /* 16 bit */ |
28 | 25 | + tmp = tcg_temp_new_i64(); | |
29 | if (pclk) { | 26 | + tcg_gen_ext16u_i64(tmp, tcg_rn); |
30 | reload = muldiv64(s->regs[WDT_RELOAD_VALUE], NANOSECONDS_PER_SECOND, | 27 | + write_fp_dreg(s, rd, tmp); |
31 | s->pclk_freq); | 28 | + tcg_temp_free_i64(tmp); |
29 | + break; | ||
30 | + default: | ||
31 | + g_assert_not_reached(); | ||
32 | } | ||
32 | } else { | 33 | } else { |
33 | - reload = s->regs[WDT_RELOAD_VALUE] * 1000; | 34 | TCGv_i64 tcg_rd = cpu_reg(s, rd); |
34 | + reload = s->regs[WDT_RELOAD_VALUE] * 1000ULL; | 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 | } | ||
35 | } | 46 | } |
36 | 47 | } | |
37 | if (aspeed_wdt_is_enabled(s)) { | 48 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) |
49 | case 0xa: /* 64 bit */ | ||
50 | case 0xd: /* 64 bit to top half of quad */ | ||
51 | break; | ||
52 | + case 0x6: /* 16-bit float, 32-bit int */ | ||
53 | + case 0xe: /* 16-bit float, 64-bit int */ | ||
54 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
55 | + break; | ||
56 | + } | ||
57 | + /* fallthru */ | ||
58 | default: | ||
59 | /* all other sf/type/rmode combinations are invalid */ | ||
60 | unallocated_encoding(s); | ||
38 | -- | 61 | -- |
39 | 2.7.4 | 62 | 2.17.0 |
40 | 63 | ||
41 | 64 | diff view generated by jsdifflib |
1 | From: Igor Mammedov <imammedo@redhat.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | s/cpu_model/cpu_type/ that has been forgotten during | 3 | No sense in emitting code after the exception. |
4 | conversion (ba1ba5cc), while touching the line also | ||
5 | fixup alignment. | ||
6 | 4 | ||
7 | Signed-off-by: Igor Mammedov <imammedo@redhat.com> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 1507710805-221721-1-git-send-email-imammedo@redhat.com | 6 | Tested-by: Alex Bennée <alex.bennee@linaro.org> |
7 | Message-id: 20180512003217.9105-3-richard.henderson@linaro.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 10 | --- |
12 | include/hw/arm/arm.h | 2 +- | 11 | target/arm/translate-a64.c | 2 +- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 13 | ||
15 | diff --git a/include/hw/arm/arm.h b/include/hw/arm/arm.h | 14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/hw/arm/arm.h | 16 | --- a/target/arm/translate-a64.c |
18 | +++ b/include/hw/arm/arm.h | 17 | +++ b/target/arm/translate-a64.c |
19 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 18 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) |
20 | 19 | default: | |
21 | /* armv7m.c */ | 20 | /* all other sf/type/rmode combinations are invalid */ |
22 | DeviceState *armv7m_init(MemoryRegion *system_memory, int mem_size, int num_irq, | 21 | unallocated_encoding(s); |
23 | - const char *kernel_filename, const char *cpu_model); | 22 | - break; |
24 | + const char *kernel_filename, const char *cpu_type); | 23 | + return; |
25 | /** | 24 | } |
26 | * armv7m_load_kernel: | 25 | |
27 | * @cpu: CPU | 26 | if (!fp_access_check(s)) { |
28 | -- | 27 | -- |
29 | 2.7.4 | 28 | 2.17.0 |
30 | 29 | ||
31 | 30 | diff view generated by jsdifflib |
1 | Implement the BLXNS instruction, which allows secure code to | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | call non-secure code. | 2 | |
3 | 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 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 1507556919-24992-4-git-send-email-peter.maydell@linaro.org | ||
7 | --- | 9 | --- |
8 | target/arm/helper.h | 1 + | 10 | target/arm/helper.h | 6 +++ |
9 | target/arm/internals.h | 1 + | 11 | target/arm/helper.c | 38 ++++++++++++++- |
10 | target/arm/helper.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ | 12 | target/arm/translate-a64.c | 96 +++++++++++++++++++++++++++++++------- |
11 | target/arm/translate.c | 17 +++++++++++++-- | 13 | 3 files changed, 122 insertions(+), 18 deletions(-) |
12 | 4 files changed, 76 insertions(+), 2 deletions(-) | ||
13 | 14 | ||
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 15 | diff --git a/target/arm/helper.h b/target/arm/helper.h |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 17 | --- a/target/arm/helper.h |
17 | +++ b/target/arm/helper.h | 18 | +++ b/target/arm/helper.h |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(v7m_msr, void, env, i32, i32) | 19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_touhd_round_to_zero, i64, f64, i32, ptr) |
19 | DEF_HELPER_2(v7m_mrs, i32, env, i32) | 20 | DEF_HELPER_3(vfp_tould_round_to_zero, i64, f64, i32, ptr) |
20 | 21 | DEF_HELPER_3(vfp_touhh, i32, f16, i32, ptr) | |
21 | DEF_HELPER_2(v7m_bxns, void, env, i32) | 22 | DEF_HELPER_3(vfp_toshh, i32, f16, i32, ptr) |
22 | +DEF_HELPER_2(v7m_blxns, void, env, i32) | 23 | +DEF_HELPER_3(vfp_toulh, i32, f16, i32, ptr) |
23 | 24 | +DEF_HELPER_3(vfp_toslh, i32, f16, i32, ptr) | |
24 | DEF_HELPER_4(access_check_cp_reg, void, env, ptr, i32, i32) | 25 | +DEF_HELPER_3(vfp_touqh, i64, f16, i32, ptr) |
25 | DEF_HELPER_3(set_cp_reg, void, env, ptr, i32) | 26 | +DEF_HELPER_3(vfp_tosqh, i64, f16, i32, ptr) |
26 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 27 | DEF_HELPER_3(vfp_toshs, i32, f32, i32, ptr) |
27 | index XXXXXXX..XXXXXXX 100644 | 28 | DEF_HELPER_3(vfp_tosls, i32, f32, i32, ptr) |
28 | --- a/target/arm/internals.h | 29 | DEF_HELPER_3(vfp_tosqs, i64, f32, i32, ptr) |
29 | +++ b/target/arm/internals.h | 30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_ultod, f64, i64, i32, ptr) |
30 | @@ -XXX,XX +XXX,XX @@ static inline bool excp_is_internal(int excp) | 31 | DEF_HELPER_3(vfp_uqtod, f64, i64, i32, ptr) |
31 | FIELD(V7M_CONTROL, NPRIV, 0, 1) | 32 | DEF_HELPER_3(vfp_sltoh, f16, i32, i32, ptr) |
32 | FIELD(V7M_CONTROL, SPSEL, 1, 1) | 33 | DEF_HELPER_3(vfp_ultoh, f16, i32, i32, ptr) |
33 | FIELD(V7M_CONTROL, FPCA, 2, 1) | 34 | +DEF_HELPER_3(vfp_sqtoh, f16, i64, i32, ptr) |
34 | +FIELD(V7M_CONTROL, SFPA, 3, 1) | 35 | +DEF_HELPER_3(vfp_uqtoh, f16, i64, i32, ptr) |
35 | 36 | ||
36 | /* Bit definitions for v7M exception return payload */ | 37 | DEF_HELPER_FLAGS_2(set_rmode, TCG_CALL_NO_RWG, i32, i32, ptr) |
37 | FIELD(V7M_EXCRET, ES, 0, 1) | 38 | DEF_HELPER_FLAGS_2(set_neon_rmode, TCG_CALL_NO_RWG, i32, i32, env) |
38 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 39 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
39 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/arm/helper.c | 41 | --- a/target/arm/helper.c |
41 | +++ b/target/arm/helper.c | 42 | +++ b/target/arm/helper.c |
42 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest) | 43 | @@ -XXX,XX +XXX,XX @@ VFP_CONV_FIX_A64(uq, s, 32, 64, uint64) |
43 | g_assert_not_reached(); | 44 | #undef VFP_CONV_FIX_A64 |
45 | |||
46 | /* Conversion to/from f16 can overflow to infinity before/after scaling. | ||
47 | - * Therefore we convert to f64 (which does not round), scale, | ||
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); | ||
44 | } | 60 | } |
45 | 61 | ||
46 | +void HELPER(v7m_blxns)(CPUARMState *env, uint32_t dest) | 62 | +float16 HELPER(vfp_sqtoh)(uint64_t x, uint32_t shift, void *fpst) |
47 | +{ | 63 | +{ |
48 | + /* translate.c should never generate calls here in user-only mode */ | 64 | + return do_postscale_fp16(int64_to_float64(x, fpst), shift, fpst); |
49 | + g_assert_not_reached(); | 65 | +} |
50 | +} | 66 | + |
51 | + | 67 | +float16 HELPER(vfp_uqtoh)(uint64_t x, uint32_t shift, void *fpst) |
52 | void switch_mode(CPUARMState *env, int mode) | 68 | +{ |
69 | + return do_postscale_fp16(uint64_to_float64(x, fpst), shift, fpst); | ||
70 | +} | ||
71 | + | ||
72 | static float64 do_prescale_fp16(float16 f, int shift, float_status *fpst) | ||
53 | { | 73 | { |
54 | ARMCPU *cpu = arm_env_get_cpu(env); | 74 | if (unlikely(float16_is_any_nan(f))) { |
55 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest) | 75 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(vfp_touhh)(float16 x, uint32_t shift, void *fpst) |
56 | env->regs[15] = dest & ~1; | 76 | return float64_to_uint16(do_prescale_fp16(x, shift, fpst), fpst); |
57 | } | 77 | } |
58 | 78 | ||
59 | +void HELPER(v7m_blxns)(CPUARMState *env, uint32_t dest) | 79 | +uint32_t HELPER(vfp_toslh)(float16 x, uint32_t shift, void *fpst) |
60 | +{ | 80 | +{ |
61 | + /* Handle v7M BLXNS: | 81 | + return float64_to_int32(do_prescale_fp16(x, shift, fpst), fpst); |
62 | + * - bit 0 of the destination address is the target security state | 82 | +} |
63 | + */ | 83 | + |
64 | + | 84 | +uint32_t HELPER(vfp_toulh)(float16 x, uint32_t shift, void *fpst) |
65 | + /* At this point regs[15] is the address just after the BLXNS */ | 85 | +{ |
66 | + uint32_t nextinst = env->regs[15] | 1; | 86 | + return float64_to_uint32(do_prescale_fp16(x, shift, fpst), fpst); |
67 | + uint32_t sp = env->regs[13] - 8; | 87 | +} |
68 | + uint32_t saved_psr; | 88 | + |
69 | + | 89 | +uint64_t HELPER(vfp_tosqh)(float16 x, uint32_t shift, void *fpst) |
70 | + /* translate.c will have made BLXNS UNDEF unless we're secure */ | 90 | +{ |
71 | + assert(env->v7m.secure); | 91 | + return float64_to_int64(do_prescale_fp16(x, shift, fpst), fpst); |
72 | + | 92 | +} |
73 | + if (dest & 1) { | 93 | + |
74 | + /* target is Secure, so this is just a normal BLX, | 94 | +uint64_t HELPER(vfp_touqh)(float16 x, uint32_t shift, void *fpst) |
75 | + * except that the low bit doesn't indicate Thumb/not. | 95 | +{ |
76 | + */ | 96 | + return float64_to_uint64(do_prescale_fp16(x, shift, fpst), fpst); |
77 | + env->regs[14] = nextinst; | 97 | +} |
78 | + env->thumb = 1; | 98 | + |
79 | + env->regs[15] = dest & ~1; | 99 | /* Set the current fp rounding mode and return the old one. |
80 | + return; | 100 | * The argument is a softfloat float_round_ value. |
81 | + } | 101 | */ |
82 | + | 102 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
83 | + /* Target is non-secure: first push a stack frame */ | 103 | index XXXXXXX..XXXXXXX 100644 |
84 | + if (!QEMU_IS_ALIGNED(sp, 8)) { | 104 | --- a/target/arm/translate-a64.c |
85 | + qemu_log_mask(LOG_GUEST_ERROR, | 105 | +++ b/target/arm/translate-a64.c |
86 | + "BLXNS with misaligned SP is UNPREDICTABLE\n"); | 106 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, |
87 | + } | 107 | bool itof, int rmode, int scale, int sf, int type) |
88 | + | ||
89 | + saved_psr = env->v7m.exception; | ||
90 | + if (env->v7m.control[M_REG_S] & R_V7M_CONTROL_SFPA_MASK) { | ||
91 | + saved_psr |= XPSR_SFPA; | ||
92 | + } | ||
93 | + | ||
94 | + /* Note that these stores can throw exceptions on MPU faults */ | ||
95 | + cpu_stl_data(env, sp, nextinst); | ||
96 | + cpu_stl_data(env, sp + 4, saved_psr); | ||
97 | + | ||
98 | + env->regs[13] = sp; | ||
99 | + env->regs[14] = 0xfeffffff; | ||
100 | + if (arm_v7m_is_handler_mode(env)) { | ||
101 | + /* Write a dummy value to IPSR, to avoid leaking the current secure | ||
102 | + * exception number to non-secure code. This is guaranteed not | ||
103 | + * to cause write_v7m_exception() to actually change stacks. | ||
104 | + */ | ||
105 | + write_v7m_exception(env, 1); | ||
106 | + } | ||
107 | + switch_v7m_security_state(env, 0); | ||
108 | + env->thumb = 1; | ||
109 | + env->regs[15] = dest; | ||
110 | +} | ||
111 | + | ||
112 | static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | ||
113 | bool spsel) | ||
114 | { | 108 | { |
115 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 109 | bool is_signed = !(opcode & 1); |
116 | index XXXXXXX..XXXXXXX 100644 | 110 | - bool is_double = type; |
117 | --- a/target/arm/translate.c | 111 | TCGv_ptr tcg_fpstatus; |
118 | +++ b/target/arm/translate.c | 112 | - TCGv_i32 tcg_shift; |
119 | @@ -XXX,XX +XXX,XX @@ static inline void gen_bxns(DisasContext *s, int rm) | 113 | + TCGv_i32 tcg_shift, tcg_single; |
120 | s->base.is_jmp = DISAS_EXIT; | 114 | + TCGv_i64 tcg_double; |
121 | } | 115 | |
122 | 116 | - tcg_fpstatus = get_fpstatus_ptr(false); | |
123 | +static inline void gen_blxns(DisasContext *s, int rm) | 117 | + tcg_fpstatus = get_fpstatus_ptr(type == 3); |
124 | +{ | 118 | |
125 | + TCGv_i32 var = load_reg(s, rm); | 119 | tcg_shift = tcg_const_i32(64 - scale); |
126 | + | 120 | |
127 | + /* We don't need to sync condexec state, for the same reason as bxns. | 121 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, |
128 | + * We do however need to set the PC, because the blxns helper reads it. | 122 | tcg_int = tcg_extend; |
129 | + * The blxns helper may throw an exception. | 123 | } |
130 | + */ | 124 | |
131 | + gen_set_pc_im(s, s->pc); | 125 | - if (is_double) { |
132 | + gen_helper_v7m_blxns(cpu_env, var); | 126 | - TCGv_i64 tcg_double = tcg_temp_new_i64(); |
133 | + tcg_temp_free_i32(var); | 127 | + switch (type) { |
134 | + s->base.is_jmp = DISAS_EXIT; | 128 | + case 1: /* float64 */ |
135 | +} | 129 | + tcg_double = tcg_temp_new_i64(); |
136 | + | 130 | if (is_signed) { |
137 | /* Variant of store_reg which uses branch&exchange logic when storing | 131 | gen_helper_vfp_sqtod(tcg_double, tcg_int, |
138 | to r15 in ARM architecture v7 and above. The source must be a temporary | 132 | tcg_shift, tcg_fpstatus); |
139 | and will be marked as dead. */ | 133 | @@ -XXX,XX +XXX,XX @@ static void handle_fpfpcvt(DisasContext *s, int rd, int rn, int opcode, |
140 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb_insn(CPUARMState *env, DisasContext *s) | 134 | } |
141 | goto undef; | 135 | write_fp_dreg(s, rd, tcg_double); |
142 | } | 136 | tcg_temp_free_i64(tcg_double); |
143 | if (link) { | 137 | - } else { |
144 | - /* BLXNS: not yet implemented */ | 138 | - TCGv_i32 tcg_single = tcg_temp_new_i32(); |
145 | - goto undef; | 139 | + break; |
146 | + gen_blxns(s, rm); | 140 | + |
147 | } else { | 141 | + case 0: /* float32 */ |
148 | gen_bxns(s, rm); | 142 | + tcg_single = tcg_temp_new_i32(); |
149 | } | 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 | } | ||
150 | -- | 265 | -- |
151 | 2.7.4 | 266 | 2.17.0 |
152 | 267 | ||
153 | 268 | diff view generated by jsdifflib |
1 | Coverity points out that we forgot the 'break' for | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | the SAU_CTRL write case (CID1381683). This has | ||
3 | no actual visible consequences because it happens | ||
4 | that the following case is effectively a no-op. | ||
5 | 2 | ||
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-5-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 1507742676-9908-1-git-send-email-peter.maydell@linaro.org | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | --- | 9 | --- |
11 | hw/intc/armv7m_nvic.c | 1 + | 10 | target/arm/translate-a64.c | 17 +++++++++++++++-- |
12 | 1 file changed, 1 insertion(+) | 11 | 1 file changed, 15 insertions(+), 2 deletions(-) |
13 | 12 | ||
14 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
15 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/intc/armv7m_nvic.c | 15 | --- a/target/arm/translate-a64.c |
17 | +++ b/hw/intc/armv7m_nvic.c | 16 | +++ b/target/arm/translate-a64.c |
18 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | 17 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn) |
19 | return; | 18 | bool sf = extract32(insn, 31, 1); |
20 | } | 19 | bool itof; |
21 | cpu->env.sau.ctrl = value & 3; | 20 | |
21 | - if (sbit || (type > 1) | ||
22 | - || (!sf && scale < 32)) { | ||
23 | + if (sbit || (!sf && scale < 32)) { | ||
24 | + unallocated_encoding(s); | ||
25 | + return; | ||
26 | + } | ||
27 | + | ||
28 | + switch (type) { | ||
29 | + case 0: /* float32 */ | ||
30 | + case 1: /* float64 */ | ||
22 | + break; | 31 | + break; |
23 | case 0xdd4: /* SAU_TYPE */ | 32 | + case 3: /* float16 */ |
24 | if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) { | 33 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { |
25 | goto bad_offset; | 34 | + break; |
35 | + } | ||
36 | + /* fallthru */ | ||
37 | + default: | ||
38 | unallocated_encoding(s); | ||
39 | return; | ||
40 | } | ||
26 | -- | 41 | -- |
27 | 2.7.4 | 42 | 2.17.0 |
28 | 43 | ||
29 | 44 | diff view generated by jsdifflib |
1 | A few Thumb instructions are always unconditional even inside an | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | IT block (as opposed to being UNPREDICTABLE if used inside an | ||
3 | IT block): BKPT, the v8M SG instruction, and the A profile | ||
4 | HLT (debug halt) instruction. | ||
5 | 2 | ||
6 | This means we need to suppress the jump-over-instruction-on-condfail | 3 | Cc: qemu-stable@nongnu.org |
7 | code generation (though the IT state still advances as usual and | 4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | subsequent insns in the IT block may be conditional). | 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> | ||
9 | --- | ||
10 | target/arm/translate-a64.c | 30 ++++++++++++++---------------- | ||
11 | 1 file changed, 14 insertions(+), 16 deletions(-) | ||
9 | 12 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 1507556919-24992-9-git-send-email-peter.maydell@linaro.org | ||
13 | --- | ||
14 | target/arm/translate.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- | ||
15 | 1 file changed, 47 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/translate.c | 15 | --- a/target/arm/translate-a64.c |
20 | +++ b/target/arm/translate.c | 16 | +++ b/target/arm/translate-a64.c |
21 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) | 17 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 read_fp_sreg(DisasContext *s, int reg) |
22 | in init_disas_context by adjusting max_insns. */ | 18 | return v; |
23 | } | 19 | } |
24 | 20 | ||
25 | +static bool thumb_insn_is_unconditional(DisasContext *s, uint32_t insn) | 21 | +static TCGv_i32 read_fp_hreg(DisasContext *s, int reg) |
26 | +{ | 22 | +{ |
27 | + /* Return true if this Thumb insn is always unconditional, | 23 | + TCGv_i32 v = tcg_temp_new_i32(); |
28 | + * even inside an IT block. This is true of only a very few | ||
29 | + * instructions: BKPT, HLT, and SG. | ||
30 | + * | ||
31 | + * A larger class of instructions are UNPREDICTABLE if used | ||
32 | + * inside an IT block; we do not need to detect those here, because | ||
33 | + * what we do by default (perform the cc check and update the IT | ||
34 | + * bits state machine) is a permitted CONSTRAINED UNPREDICTABLE | ||
35 | + * choice for those situations. | ||
36 | + * | ||
37 | + * insn is either a 16-bit or a 32-bit instruction; the two are | ||
38 | + * distinguishable because for the 16-bit case the top 16 bits | ||
39 | + * are zeroes, and that isn't a valid 32-bit encoding. | ||
40 | + */ | ||
41 | + if ((insn & 0xffffff00) == 0xbe00) { | ||
42 | + /* BKPT */ | ||
43 | + return true; | ||
44 | + } | ||
45 | + | 24 | + |
46 | + if ((insn & 0xffffffc0) == 0xba80 && arm_dc_feature(s, ARM_FEATURE_V8) && | 25 | + tcg_gen_ld16u_i32(v, cpu_env, fp_reg_offset(s, reg, MO_16)); |
47 | + !arm_dc_feature(s, ARM_FEATURE_M)) { | 26 | + return v; |
48 | + /* HLT: v8A only. This is unconditional even when it is going to | ||
49 | + * UNDEF; see the v8A ARM ARM DDI0487B.a H3.3. | ||
50 | + * For v7 cores this was a plain old undefined encoding and so | ||
51 | + * honours its cc check. (We might be using the encoding as | ||
52 | + * a semihosting trap, but we don't change the cc check behaviour | ||
53 | + * on that account, because a debugger connected to a real v7A | ||
54 | + * core and emulating semihosting traps by catching the UNDEF | ||
55 | + * exception would also only see cases where the cc check passed. | ||
56 | + * No guest code should be trying to do a HLT semihosting trap | ||
57 | + * in an IT block anyway. | ||
58 | + */ | ||
59 | + return true; | ||
60 | + } | ||
61 | + | ||
62 | + if (insn == 0xe97fe97f && arm_dc_feature(s, ARM_FEATURE_V8) && | ||
63 | + arm_dc_feature(s, ARM_FEATURE_M)) { | ||
64 | + /* SG: v8M only */ | ||
65 | + return true; | ||
66 | + } | ||
67 | + | ||
68 | + return false; | ||
69 | +} | 27 | +} |
70 | + | 28 | + |
71 | static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) | 29 | /* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64). |
30 | * If SVE is not enabled, then there are only 128 bits in the vector. | ||
31 | */ | ||
32 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) | ||
33 | static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn) | ||
72 | { | 34 | { |
73 | DisasContext *dc = container_of(dcbase, DisasContext, base); | 35 | TCGv_ptr fpst = NULL; |
74 | @@ -XXX,XX +XXX,XX @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) | 36 | - TCGv_i32 tcg_op = tcg_temp_new_i32(); |
75 | dc->pc += 2; | 37 | + TCGv_i32 tcg_op = read_fp_hreg(s, rn); |
38 | TCGv_i32 tcg_res = tcg_temp_new_i32(); | ||
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) | ||
76 | } | 78 | } |
77 | 79 | ||
78 | - if (dc->condexec_mask) { | 80 | if (is_scalar) { |
79 | + if (dc->condexec_mask && !thumb_insn_is_unconditional(dc, insn)) { | 81 | - TCGv_i32 tcg_op = tcg_temp_new_i32(); |
80 | uint32_t cond = dc->condexec_cond; | 82 | + TCGv_i32 tcg_op = read_fp_hreg(s, rn); |
81 | 83 | TCGv_i32 tcg_res = tcg_temp_new_i32(); | |
82 | if (cond != 0x0e) { /* Skip conditional when condition is AL. */ | 84 | |
85 | - read_vec_element_i32(s, tcg_op, rn, 0, MO_16); | ||
86 | - | ||
87 | switch (fpop) { | ||
88 | case 0x1a: /* FCVTNS */ | ||
89 | case 0x1b: /* FCVTMS */ | ||
83 | -- | 90 | -- |
84 | 2.7.4 | 91 | 2.17.0 |
85 | 92 | ||
86 | 93 | diff view generated by jsdifflib |
1 | Refactor the Thumb decode to do the loads of the instruction words at | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | the top level rather than only loading the second half of a 32-bit | ||
3 | Thumb insn in the middle of the decode. | ||
4 | 2 | ||
5 | This is simple apart from the awkward case of Thumb1, where the | 3 | We missed all of the scalar fp16 binary operations. |
6 | BL/BLX prefix and suffix instructions live in what in Thumb2 is the | ||
7 | 32-bit insn space. To handle these we decode enough to identify | ||
8 | whether we're looking at a prefix/suffix that we handle as a 16 bit | ||
9 | insn, or a prefix that we're going to merge with the following suffix | ||
10 | to consider as a 32 bit insn. The translation of the 16 bit cases | ||
11 | then moves from disas_thumb2_insn() to disas_thumb_insn(). | ||
12 | 4 | ||
13 | The refactoring has the benefit that we don't need to pass the | 5 | Cc: qemu-stable@nongnu.org |
14 | CPUARMState* down into the decoder code any more, but the major | 6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
15 | reason for doing this is that some Thumb instructions must be always | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
16 | unconditional regardless of the IT state bits, so we need to know the | 8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> |
17 | whole insn before we emit the "skip this insn if the IT bits and cond | 9 | Message-id: 20180512003217.9105-7-richard.henderson@linaro.org |
18 | state tell us to" code. (The always unconditional insns are BKPT, | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
19 | HLT and SG; the last of these is 32 bits.) | 11 | --- |
12 | target/arm/translate-a64.c | 65 ++++++++++++++++++++++++++++++++++++++ | ||
13 | 1 file changed, 65 insertions(+) | ||
20 | 14 | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
22 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
23 | Message-id: 1507556919-24992-7-git-send-email-peter.maydell@linaro.org | ||
24 | --- | ||
25 | target/arm/translate.c | 178 ++++++++++++++++++++++++++++++------------------- | ||
26 | 1 file changed, 108 insertions(+), 70 deletions(-) | ||
27 | |||
28 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate.c | 17 | --- a/target/arm/translate-a64.c |
31 | +++ b/target/arm/translate.c | 18 | +++ b/target/arm/translate-a64.c |
32 | @@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) | 19 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_2src_double(DisasContext *s, int opcode, |
33 | } | 20 | tcg_temp_free_i64(tcg_res); |
34 | } | 21 | } |
35 | 22 | ||
36 | +static bool thumb_insn_is_16bit(DisasContext *s, uint32_t insn) | 23 | +/* Floating-point data-processing (2 source) - half precision */ |
24 | +static void handle_fp_2src_half(DisasContext *s, int opcode, | ||
25 | + int rd, int rn, int rm) | ||
37 | +{ | 26 | +{ |
38 | + /* Return true if this is a 16 bit instruction. We must be precise | 27 | + TCGv_i32 tcg_op1; |
39 | + * about this (matching the decode). We assume that s->pc still | 28 | + TCGv_i32 tcg_op2; |
40 | + * points to the first 16 bits of the insn. | 29 | + TCGv_i32 tcg_res; |
41 | + */ | 30 | + TCGv_ptr fpst; |
42 | + if ((insn >> 11) < 0x1d) { | 31 | + |
43 | + /* Definitely a 16-bit instruction */ | 32 | + tcg_res = tcg_temp_new_i32(); |
44 | + return true; | 33 | + fpst = get_fpstatus_ptr(true); |
34 | + tcg_op1 = read_fp_hreg(s, rn); | ||
35 | + tcg_op2 = read_fp_hreg(s, rm); | ||
36 | + | ||
37 | + switch (opcode) { | ||
38 | + case 0x0: /* FMUL */ | ||
39 | + gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
40 | + break; | ||
41 | + case 0x1: /* FDIV */ | ||
42 | + gen_helper_advsimd_divh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
43 | + break; | ||
44 | + case 0x2: /* FADD */ | ||
45 | + gen_helper_advsimd_addh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
46 | + break; | ||
47 | + case 0x3: /* FSUB */ | ||
48 | + gen_helper_advsimd_subh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
49 | + break; | ||
50 | + case 0x4: /* FMAX */ | ||
51 | + gen_helper_advsimd_maxh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
52 | + break; | ||
53 | + case 0x5: /* FMIN */ | ||
54 | + gen_helper_advsimd_minh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
55 | + break; | ||
56 | + case 0x6: /* FMAXNM */ | ||
57 | + gen_helper_advsimd_maxnumh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
58 | + break; | ||
59 | + case 0x7: /* FMINNM */ | ||
60 | + gen_helper_advsimd_minnumh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
61 | + break; | ||
62 | + case 0x8: /* FNMUL */ | ||
63 | + gen_helper_advsimd_mulh(tcg_res, tcg_op1, tcg_op2, fpst); | ||
64 | + tcg_gen_xori_i32(tcg_res, tcg_res, 0x8000); | ||
65 | + break; | ||
66 | + default: | ||
67 | + g_assert_not_reached(); | ||
45 | + } | 68 | + } |
46 | + | 69 | + |
47 | + /* Top five bits 0b11101 / 0b11110 / 0b11111 : this is the | 70 | + write_fp_sreg(s, rd, tcg_res); |
48 | + * first half of a 32-bit Thumb insn. Thumb-1 cores might | ||
49 | + * end up actually treating this as two 16-bit insns, though, | ||
50 | + * if it's half of a bl/blx pair that might span a page boundary. | ||
51 | + */ | ||
52 | + if (arm_dc_feature(s, ARM_FEATURE_THUMB2)) { | ||
53 | + /* Thumb2 cores (including all M profile ones) always treat | ||
54 | + * 32-bit insns as 32-bit. | ||
55 | + */ | ||
56 | + return false; | ||
57 | + } | ||
58 | + | 71 | + |
59 | + if ((insn >> 11) == 0x1e && (s->pc < s->next_page_start - 3)) { | 72 | + tcg_temp_free_ptr(fpst); |
60 | + /* 0b1111_0xxx_xxxx_xxxx : BL/BLX prefix, and the suffix | 73 | + tcg_temp_free_i32(tcg_op1); |
61 | + * is not on the next page; we merge this into a 32-bit | 74 | + tcg_temp_free_i32(tcg_op2); |
62 | + * insn. | 75 | + tcg_temp_free_i32(tcg_res); |
63 | + */ | ||
64 | + return false; | ||
65 | + } | ||
66 | + /* 0b1110_1xxx_xxxx_xxxx : BLX suffix (or UNDEF); | ||
67 | + * 0b1111_1xxx_xxxx_xxxx : BL suffix; | ||
68 | + * 0b1111_0xxx_xxxx_xxxx : BL/BLX prefix on the end of a page | ||
69 | + * -- handle as single 16 bit insn | ||
70 | + */ | ||
71 | + return true; | ||
72 | +} | 76 | +} |
73 | + | 77 | + |
74 | /* Return true if this is a Thumb-2 logical op. */ | 78 | /* Floating point data-processing (2 source) |
75 | static int | 79 | * 31 30 29 28 24 23 22 21 20 16 15 12 11 10 9 5 4 0 |
76 | thumb2_logic_op(int op) | 80 | * +---+---+---+-----------+------+---+------+--------+-----+------+------+ |
77 | @@ -XXX,XX +XXX,XX @@ gen_thumb2_data_op(DisasContext *s, int op, int conds, uint32_t shifter_out, | 81 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_2src(DisasContext *s, uint32_t insn) |
78 | 82 | } | |
79 | /* Translate a 32-bit thumb instruction. Returns nonzero if the instruction | 83 | handle_fp_2src_double(s, opcode, rd, rn, rm); |
80 | is not legal. */ | 84 | break; |
81 | -static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw1) | 85 | + case 3: |
82 | +static int disas_thumb2_insn(DisasContext *s, uint32_t insn) | 86 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { |
83 | { | 87 | + unallocated_encoding(s); |
84 | - uint32_t insn, imm, shift, offset; | 88 | + return; |
85 | + uint32_t imm, shift, offset; | 89 | + } |
86 | uint32_t rd, rn, rm, rs; | 90 | + if (!fp_access_check(s)) { |
87 | TCGv_i32 tmp; | 91 | + return; |
88 | TCGv_i32 tmp2; | 92 | + } |
89 | @@ -XXX,XX +XXX,XX @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw | 93 | + handle_fp_2src_half(s, opcode, rd, rn, rm); |
90 | int conds; | 94 | + break; |
91 | int logic_cc; | 95 | default: |
92 | 96 | unallocated_encoding(s); | |
93 | - if (!arm_dc_feature(s, ARM_FEATURE_THUMB2)) { | ||
94 | - /* Thumb-1 cores may need to treat bl and blx as a pair of | ||
95 | - 16-bit instructions to get correct prefetch abort behavior. */ | ||
96 | - insn = insn_hw1; | ||
97 | - if ((insn & (1 << 12)) == 0) { | ||
98 | - ARCH(5); | ||
99 | - /* Second half of blx. */ | ||
100 | - offset = ((insn & 0x7ff) << 1); | ||
101 | - tmp = load_reg(s, 14); | ||
102 | - tcg_gen_addi_i32(tmp, tmp, offset); | ||
103 | - tcg_gen_andi_i32(tmp, tmp, 0xfffffffc); | ||
104 | - | ||
105 | - tmp2 = tcg_temp_new_i32(); | ||
106 | - tcg_gen_movi_i32(tmp2, s->pc | 1); | ||
107 | - store_reg(s, 14, tmp2); | ||
108 | - gen_bx(s, tmp); | ||
109 | - return 0; | ||
110 | - } | ||
111 | - if (insn & (1 << 11)) { | ||
112 | - /* Second half of bl. */ | ||
113 | - offset = ((insn & 0x7ff) << 1) | 1; | ||
114 | - tmp = load_reg(s, 14); | ||
115 | - tcg_gen_addi_i32(tmp, tmp, offset); | ||
116 | - | ||
117 | - tmp2 = tcg_temp_new_i32(); | ||
118 | - tcg_gen_movi_i32(tmp2, s->pc | 1); | ||
119 | - store_reg(s, 14, tmp2); | ||
120 | - gen_bx(s, tmp); | ||
121 | - return 0; | ||
122 | - } | ||
123 | - if ((s->pc & ~TARGET_PAGE_MASK) == 0) { | ||
124 | - /* Instruction spans a page boundary. Implement it as two | ||
125 | - 16-bit instructions in case the second half causes an | ||
126 | - prefetch abort. */ | ||
127 | - offset = ((int32_t)insn << 21) >> 9; | ||
128 | - tcg_gen_movi_i32(cpu_R[14], s->pc + 2 + offset); | ||
129 | - return 0; | ||
130 | - } | ||
131 | - /* Fall through to 32-bit decode. */ | ||
132 | - } | ||
133 | - | ||
134 | - insn = arm_lduw_code(env, s->pc, s->sctlr_b); | ||
135 | - s->pc += 2; | ||
136 | - insn |= (uint32_t)insn_hw1 << 16; | ||
137 | - | ||
138 | + /* The only 32 bit insn that's allowed for Thumb1 is the combined | ||
139 | + * BL/BLX prefix and suffix. | ||
140 | + */ | ||
141 | if ((insn & 0xf800e800) != 0xf000e800) { | ||
142 | ARCH(6T2); | ||
143 | } | 97 | } |
144 | @@ -XXX,XX +XXX,XX @@ illegal_op: | ||
145 | return 1; | ||
146 | } | ||
147 | |||
148 | -static void disas_thumb_insn(CPUARMState *env, DisasContext *s) | ||
149 | +static void disas_thumb_insn(DisasContext *s, uint32_t insn) | ||
150 | { | ||
151 | - uint32_t val, insn, op, rm, rn, rd, shift, cond; | ||
152 | + uint32_t val, op, rm, rn, rd, shift, cond; | ||
153 | int32_t offset; | ||
154 | int i; | ||
155 | TCGv_i32 tmp; | ||
156 | TCGv_i32 tmp2; | ||
157 | TCGv_i32 addr; | ||
158 | |||
159 | - if (s->condexec_mask) { | ||
160 | - cond = s->condexec_cond; | ||
161 | - if (cond != 0x0e) { /* Skip conditional when condition is AL. */ | ||
162 | - s->condlabel = gen_new_label(); | ||
163 | - arm_gen_test_cc(cond ^ 1, s->condlabel); | ||
164 | - s->condjmp = 1; | ||
165 | - } | ||
166 | - } | ||
167 | - | ||
168 | - insn = arm_lduw_code(env, s->pc, s->sctlr_b); | ||
169 | - s->pc += 2; | ||
170 | - | ||
171 | switch (insn >> 12) { | ||
172 | case 0: case 1: | ||
173 | |||
174 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb_insn(CPUARMState *env, DisasContext *s) | ||
175 | |||
176 | case 14: | ||
177 | if (insn & (1 << 11)) { | ||
178 | - if (disas_thumb2_insn(env, s, insn)) | ||
179 | - goto undef32; | ||
180 | + /* thumb_insn_is_16bit() ensures we can't get here for | ||
181 | + * a Thumb2 CPU, so this must be a thumb1 split BL/BLX: | ||
182 | + * 0b1110_1xxx_xxxx_xxxx : BLX suffix (or UNDEF) | ||
183 | + */ | ||
184 | + assert(!arm_dc_feature(s, ARM_FEATURE_THUMB2)); | ||
185 | + ARCH(5); | ||
186 | + offset = ((insn & 0x7ff) << 1); | ||
187 | + tmp = load_reg(s, 14); | ||
188 | + tcg_gen_addi_i32(tmp, tmp, offset); | ||
189 | + tcg_gen_andi_i32(tmp, tmp, 0xfffffffc); | ||
190 | + | ||
191 | + tmp2 = tcg_temp_new_i32(); | ||
192 | + tcg_gen_movi_i32(tmp2, s->pc | 1); | ||
193 | + store_reg(s, 14, tmp2); | ||
194 | + gen_bx(s, tmp); | ||
195 | break; | ||
196 | } | ||
197 | /* unconditional branch */ | ||
198 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb_insn(CPUARMState *env, DisasContext *s) | ||
199 | break; | ||
200 | |||
201 | case 15: | ||
202 | - if (disas_thumb2_insn(env, s, insn)) | ||
203 | - goto undef32; | ||
204 | + /* thumb_insn_is_16bit() ensures we can't get here for | ||
205 | + * a Thumb2 CPU, so this must be a thumb1 split BL/BLX. | ||
206 | + */ | ||
207 | + assert(!arm_dc_feature(s, ARM_FEATURE_THUMB2)); | ||
208 | + | ||
209 | + if (insn & (1 << 11)) { | ||
210 | + /* 0b1111_1xxx_xxxx_xxxx : BL suffix */ | ||
211 | + offset = ((insn & 0x7ff) << 1) | 1; | ||
212 | + tmp = load_reg(s, 14); | ||
213 | + tcg_gen_addi_i32(tmp, tmp, offset); | ||
214 | + | ||
215 | + tmp2 = tcg_temp_new_i32(); | ||
216 | + tcg_gen_movi_i32(tmp2, s->pc | 1); | ||
217 | + store_reg(s, 14, tmp2); | ||
218 | + gen_bx(s, tmp); | ||
219 | + } else { | ||
220 | + /* 0b1111_0xxx_xxxx_xxxx : BL/BLX prefix */ | ||
221 | + uint32_t uoffset = ((int32_t)insn << 21) >> 9; | ||
222 | + | ||
223 | + tcg_gen_movi_i32(cpu_R[14], s->pc + 2 + uoffset); | ||
224 | + } | ||
225 | break; | ||
226 | } | ||
227 | return; | ||
228 | -undef32: | ||
229 | - gen_exception_insn(s, 4, EXCP_UDEF, syn_uncategorized(), | ||
230 | - default_exception_el(s)); | ||
231 | - return; | ||
232 | illegal_op: | ||
233 | undef: | ||
234 | gen_exception_insn(s, 2, EXCP_UDEF, syn_uncategorized(), | ||
235 | @@ -XXX,XX +XXX,XX @@ static void thumb_tr_translate_insn(DisasContextBase *dcbase, CPUState *cpu) | ||
236 | { | ||
237 | DisasContext *dc = container_of(dcbase, DisasContext, base); | ||
238 | CPUARMState *env = cpu->env_ptr; | ||
239 | + uint32_t insn; | ||
240 | + bool is_16bit; | ||
241 | |||
242 | if (arm_pre_translate_insn(dc)) { | ||
243 | return; | ||
244 | } | ||
245 | |||
246 | - disas_thumb_insn(env, dc); | ||
247 | + insn = arm_lduw_code(env, dc->pc, dc->sctlr_b); | ||
248 | + is_16bit = thumb_insn_is_16bit(dc, insn); | ||
249 | + dc->pc += 2; | ||
250 | + if (!is_16bit) { | ||
251 | + uint32_t insn2 = arm_lduw_code(env, dc->pc, dc->sctlr_b); | ||
252 | + | ||
253 | + insn = insn << 16 | insn2; | ||
254 | + dc->pc += 2; | ||
255 | + } | ||
256 | + | ||
257 | + if (dc->condexec_mask) { | ||
258 | + uint32_t cond = dc->condexec_cond; | ||
259 | + | ||
260 | + if (cond != 0x0e) { /* Skip conditional when condition is AL. */ | ||
261 | + dc->condlabel = gen_new_label(); | ||
262 | + arm_gen_test_cc(cond ^ 1, dc->condlabel); | ||
263 | + dc->condjmp = 1; | ||
264 | + } | ||
265 | + } | ||
266 | + | ||
267 | + if (is_16bit) { | ||
268 | + disas_thumb_insn(dc, insn); | ||
269 | + } else { | ||
270 | + disas_thumb2_insn(dc, insn); | ||
271 | + } | ||
272 | |||
273 | /* Advance the Thumb condexec condition. */ | ||
274 | if (dc->condexec_mask) { | ||
275 | -- | 98 | -- |
276 | 2.7.4 | 99 | 2.17.0 |
277 | 100 | ||
278 | 101 | diff view generated by jsdifflib |
1 | Secure function return happens when a non-secure function has been | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | called using BLXNS and so has a particular magic LR value (either | ||
3 | 0xfefffffe or 0xfeffffff). The function return via BX behaves | ||
4 | specially when the new PC value is this magic value, in the same | ||
5 | way that exception returns are handled. | ||
6 | 2 | ||
7 | Adjust our BX excret guards so that they recognize the function | 3 | We missed all of the scalar fp16 fma operations. |
8 | return magic number as well, and perform the function-return | ||
9 | unstacking in do_v7m_exception_exit(). | ||
10 | 4 | ||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Message-id: 20180512003217.9105-8-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 1507556919-24992-5-git-send-email-peter.maydell@linaro.org | ||
15 | --- | 11 | --- |
16 | target/arm/internals.h | 7 +++ | 12 | target/arm/translate-a64.c | 48 ++++++++++++++++++++++++++++++++++++++ |
17 | target/arm/helper.c | 115 +++++++++++++++++++++++++++++++++++++++++++++---- | 13 | 1 file changed, 48 insertions(+) |
18 | target/arm/translate.c | 14 +++++- | ||
19 | 3 files changed, 126 insertions(+), 10 deletions(-) | ||
20 | 14 | ||
21 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
22 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/arm/internals.h | 17 | --- a/target/arm/translate-a64.c |
24 | +++ b/target/arm/internals.h | 18 | +++ b/target/arm/translate-a64.c |
25 | @@ -XXX,XX +XXX,XX @@ FIELD(V7M_EXCRET, DCRS, 5, 1) | 19 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_3src_double(DisasContext *s, bool o0, bool o1, |
26 | FIELD(V7M_EXCRET, S, 6, 1) | 20 | tcg_temp_free_i64(tcg_res); |
27 | FIELD(V7M_EXCRET, RES1, 7, 25) /* including the must-be-1 prefix */ | 21 | } |
28 | 22 | ||
29 | +/* Minimum value which is a magic number for exception return */ | 23 | +/* Floating-point data-processing (3 source) - half precision */ |
30 | +#define EXC_RETURN_MIN_MAGIC 0xff000000 | 24 | +static void handle_fp_3src_half(DisasContext *s, bool o0, bool o1, |
31 | +/* Minimum number which is a magic number for function or exception return | 25 | + int rd, int rn, int rm, int ra) |
32 | + * when using v8M security extension | 26 | +{ |
33 | + */ | 27 | + TCGv_i32 tcg_op1, tcg_op2, tcg_op3; |
34 | +#define FNC_RETURN_MIN_MAGIC 0xfefffffe | 28 | + TCGv_i32 tcg_res = tcg_temp_new_i32(); |
29 | + TCGv_ptr fpst = get_fpstatus_ptr(true); | ||
35 | + | 30 | + |
36 | /* We use a few fake FSR values for internal purposes in M profile. | 31 | + tcg_op1 = read_fp_hreg(s, rn); |
37 | * M profile cores don't have A/R format FSRs, but currently our | 32 | + tcg_op2 = read_fp_hreg(s, rm); |
38 | * get_phys_addr() code assumes A/R profile and reports failures via | 33 | + tcg_op3 = read_fp_hreg(s, ra); |
39 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/arm/helper.c | ||
42 | +++ b/target/arm/helper.c | ||
43 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_bxns)(CPUARMState *env, uint32_t dest) | ||
44 | * - if the return value is a magic value, do exception return (like BX) | ||
45 | * - otherwise bit 0 of the return value is the target security state | ||
46 | */ | ||
47 | - if (dest >= 0xff000000) { | ||
48 | + uint32_t min_magic; | ||
49 | + | 34 | + |
50 | + if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { | 35 | + /* These are fused multiply-add, and must be done as one |
51 | + /* Covers FNC_RETURN and EXC_RETURN magic */ | 36 | + * floating point operation with no rounding between the |
52 | + min_magic = FNC_RETURN_MIN_MAGIC; | 37 | + * multiplication and addition steps. |
53 | + } else { | 38 | + * NB that doing the negations here as separate steps is |
54 | + /* EXC_RETURN magic only */ | 39 | + * correct : an input NaN should come out with its sign bit |
55 | + min_magic = EXC_RETURN_MIN_MAGIC; | 40 | + * flipped if it is a negated-input. |
41 | + */ | ||
42 | + if (o1 == true) { | ||
43 | + tcg_gen_xori_i32(tcg_op3, tcg_op3, 0x8000); | ||
56 | + } | 44 | + } |
57 | + | 45 | + |
58 | + if (dest >= min_magic) { | 46 | + if (o0 != o1) { |
59 | /* This is an exception return magic value; put it where | 47 | + tcg_gen_xori_i32(tcg_op1, tcg_op1, 0x8000); |
60 | * do_v7m_exception_exit() expects and raise EXCEPTION_EXIT. | ||
61 | * Note that if we ever add gen_ss_advance() singlestep support to | ||
62 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
63 | bool exc_secure = false; | ||
64 | bool return_to_secure; | ||
65 | |||
66 | - /* We can only get here from an EXCP_EXCEPTION_EXIT, and | ||
67 | - * gen_bx_excret() enforces the architectural rule | ||
68 | - * that jumps to magic addresses don't have magic behaviour unless | ||
69 | - * we're in Handler mode (compare pseudocode BXWritePC()). | ||
70 | + /* If we're not in Handler mode then jumps to magic exception-exit | ||
71 | + * addresses don't have magic behaviour. However for the v8M | ||
72 | + * security extensions the magic secure-function-return has to | ||
73 | + * work in thread mode too, so to avoid doing an extra check in | ||
74 | + * the generated code we allow exception-exit magic to also cause the | ||
75 | + * internal exception and bring us here in thread mode. Correct code | ||
76 | + * will never try to do this (the following insn fetch will always | ||
77 | + * fault) so we the overhead of having taken an unnecessary exception | ||
78 | + * doesn't matter. | ||
79 | */ | ||
80 | - assert(arm_v7m_is_handler_mode(env)); | ||
81 | + if (!arm_v7m_is_handler_mode(env)) { | ||
82 | + return; | ||
83 | + } | ||
84 | |||
85 | /* In the spec pseudocode ExceptionReturn() is called directly | ||
86 | * from BXWritePC() and gets the full target PC value including | ||
87 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
88 | qemu_log_mask(CPU_LOG_INT, "...successful exception return\n"); | ||
89 | } | ||
90 | |||
91 | +static bool do_v7m_function_return(ARMCPU *cpu) | ||
92 | +{ | ||
93 | + /* v8M security extensions magic function return. | ||
94 | + * We may either: | ||
95 | + * (1) throw an exception (longjump) | ||
96 | + * (2) return true if we successfully handled the function return | ||
97 | + * (3) return false if we failed a consistency check and have | ||
98 | + * pended a UsageFault that needs to be taken now | ||
99 | + * | ||
100 | + * At this point the magic return value is split between env->regs[15] | ||
101 | + * and env->thumb. We don't bother to reconstitute it because we don't | ||
102 | + * need it (all values are handled the same way). | ||
103 | + */ | ||
104 | + CPUARMState *env = &cpu->env; | ||
105 | + uint32_t newpc, newpsr, newpsr_exc; | ||
106 | + | ||
107 | + qemu_log_mask(CPU_LOG_INT, "...really v7M secure function return\n"); | ||
108 | + | ||
109 | + { | ||
110 | + bool threadmode, spsel; | ||
111 | + TCGMemOpIdx oi; | ||
112 | + ARMMMUIdx mmu_idx; | ||
113 | + uint32_t *frame_sp_p; | ||
114 | + uint32_t frameptr; | ||
115 | + | ||
116 | + /* Pull the return address and IPSR from the Secure stack */ | ||
117 | + threadmode = !arm_v7m_is_handler_mode(env); | ||
118 | + spsel = env->v7m.control[M_REG_S] & R_V7M_CONTROL_SPSEL_MASK; | ||
119 | + | ||
120 | + frame_sp_p = get_v7m_sp_ptr(env, true, threadmode, spsel); | ||
121 | + frameptr = *frame_sp_p; | ||
122 | + | ||
123 | + /* These loads may throw an exception (for MPU faults). We want to | ||
124 | + * do them as secure, so work out what MMU index that is. | ||
125 | + */ | ||
126 | + mmu_idx = arm_v7m_mmu_idx_for_secstate(env, true); | ||
127 | + oi = make_memop_idx(MO_LE, arm_to_core_mmu_idx(mmu_idx)); | ||
128 | + newpc = helper_le_ldul_mmu(env, frameptr, oi, 0); | ||
129 | + newpsr = helper_le_ldul_mmu(env, frameptr + 4, oi, 0); | ||
130 | + | ||
131 | + /* Consistency checks on new IPSR */ | ||
132 | + newpsr_exc = newpsr & XPSR_EXCP; | ||
133 | + if (!((env->v7m.exception == 0 && newpsr_exc == 0) || | ||
134 | + (env->v7m.exception == 1 && newpsr_exc != 0))) { | ||
135 | + /* Pend the fault and tell our caller to take it */ | ||
136 | + env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
137 | + armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, | ||
138 | + env->v7m.secure); | ||
139 | + qemu_log_mask(CPU_LOG_INT, | ||
140 | + "...taking INVPC UsageFault: " | ||
141 | + "IPSR consistency check failed\n"); | ||
142 | + return false; | ||
143 | + } | ||
144 | + | ||
145 | + *frame_sp_p = frameptr + 8; | ||
146 | + } | 48 | + } |
147 | + | 49 | + |
148 | + /* This invalidates frame_sp_p */ | 50 | + gen_helper_advsimd_muladdh(tcg_res, tcg_op1, tcg_op2, tcg_op3, fpst); |
149 | + switch_v7m_security_state(env, true); | ||
150 | + env->v7m.exception = newpsr_exc; | ||
151 | + env->v7m.control[M_REG_S] &= ~R_V7M_CONTROL_SFPA_MASK; | ||
152 | + if (newpsr & XPSR_SFPA) { | ||
153 | + env->v7m.control[M_REG_S] |= R_V7M_CONTROL_SFPA_MASK; | ||
154 | + } | ||
155 | + xpsr_write(env, 0, XPSR_IT); | ||
156 | + env->thumb = newpc & 1; | ||
157 | + env->regs[15] = newpc & ~1; | ||
158 | + | 51 | + |
159 | + qemu_log_mask(CPU_LOG_INT, "...function return successful\n"); | 52 | + write_fp_sreg(s, rd, tcg_res); |
160 | + return true; | 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); | ||
161 | +} | 59 | +} |
162 | + | 60 | + |
163 | static void arm_log_exception(int idx) | 61 | /* Floating point data-processing (3 source) |
164 | { | 62 | * 31 30 29 28 24 23 22 21 20 16 15 14 10 9 5 4 0 |
165 | if (qemu_loglevel_mask(CPU_LOG_INT)) { | 63 | * +---+---+---+-----------+------+----+------+----+------+------+------+ |
166 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | 64 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_3src(DisasContext *s, uint32_t insn) |
167 | case EXCP_IRQ: | 65 | } |
66 | handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra); | ||
168 | break; | 67 | break; |
169 | case EXCP_EXCEPTION_EXIT: | 68 | + case 3: |
170 | - do_v7m_exception_exit(cpu); | 69 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { |
171 | - return; | 70 | + unallocated_encoding(s); |
172 | + if (env->regs[15] < EXC_RETURN_MIN_MAGIC) { | ||
173 | + /* Must be v8M security extension function return */ | ||
174 | + assert(env->regs[15] >= FNC_RETURN_MIN_MAGIC); | ||
175 | + assert(arm_feature(env, ARM_FEATURE_M_SECURITY)); | ||
176 | + if (do_v7m_function_return(cpu)) { | ||
177 | + return; | ||
178 | + } | ||
179 | + } else { | ||
180 | + do_v7m_exception_exit(cpu); | ||
181 | + return; | 71 | + return; |
182 | + } | 72 | + } |
73 | + if (!fp_access_check(s)) { | ||
74 | + return; | ||
75 | + } | ||
76 | + handle_fp_3src_half(s, o0, o1, rd, rn, rm, ra); | ||
183 | + break; | 77 | + break; |
184 | default: | 78 | default: |
185 | cpu_abort(cs, "Unhandled exception 0x%x\n", cs->exception_index); | 79 | unallocated_encoding(s); |
186 | return; /* Never happens. Keep compiler happy. */ | ||
187 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
188 | index XXXXXXX..XXXXXXX 100644 | ||
189 | --- a/target/arm/translate.c | ||
190 | +++ b/target/arm/translate.c | ||
191 | @@ -XXX,XX +XXX,XX @@ static inline void gen_bx_excret(DisasContext *s, TCGv_i32 var) | ||
192 | * s->base.is_jmp that we need to do the rest of the work later. | ||
193 | */ | ||
194 | gen_bx(s, var); | ||
195 | - if (s->v7m_handler_mode && arm_dc_feature(s, ARM_FEATURE_M)) { | ||
196 | + if (arm_dc_feature(s, ARM_FEATURE_M_SECURITY) || | ||
197 | + (s->v7m_handler_mode && arm_dc_feature(s, ARM_FEATURE_M))) { | ||
198 | s->base.is_jmp = DISAS_BX_EXCRET; | ||
199 | } | 80 | } |
200 | } | ||
201 | @@ -XXX,XX +XXX,XX @@ static inline void gen_bx_excret_final_code(DisasContext *s) | ||
202 | { | ||
203 | /* Generate the code to finish possible exception return and end the TB */ | ||
204 | TCGLabel *excret_label = gen_new_label(); | ||
205 | + uint32_t min_magic; | ||
206 | + | ||
207 | + if (arm_dc_feature(s, ARM_FEATURE_M_SECURITY)) { | ||
208 | + /* Covers FNC_RETURN and EXC_RETURN magic */ | ||
209 | + min_magic = FNC_RETURN_MIN_MAGIC; | ||
210 | + } else { | ||
211 | + /* EXC_RETURN magic only */ | ||
212 | + min_magic = EXC_RETURN_MIN_MAGIC; | ||
213 | + } | ||
214 | |||
215 | /* Is the new PC value in the magic range indicating exception return? */ | ||
216 | - tcg_gen_brcondi_i32(TCG_COND_GEU, cpu_R[15], 0xff000000, excret_label); | ||
217 | + tcg_gen_brcondi_i32(TCG_COND_GEU, cpu_R[15], min_magic, excret_label); | ||
218 | /* No: end the TB as we would for a DISAS_JMP */ | ||
219 | if (is_singlestepping(s)) { | ||
220 | gen_singlestep_exception(s); | ||
221 | -- | 81 | -- |
222 | 2.7.4 | 82 | 2.17.0 |
223 | 83 | ||
224 | 84 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Alex Bennée <alex.bennee@linaro.org> | |
2 | |||
3 | These where missed out from the rest of the half-precision work. | ||
4 | |||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20180512003217.9105-9-richard.henderson@linaro.org | ||
11 | [rth: Diagnose lack of FP16 before fp_access_check] | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | target/arm/helper-a64.h | 2 + | ||
16 | target/arm/helper-a64.c | 10 +++++ | ||
17 | target/arm/translate-a64.c | 88 ++++++++++++++++++++++++++++++-------- | ||
18 | 3 files changed, 83 insertions(+), 17 deletions(-) | ||
19 | |||
20 | diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/arm/helper-a64.h | ||
23 | +++ b/target/arm/helper-a64.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | DEF_HELPER_FLAGS_2(udiv64, TCG_CALL_NO_RWG_SE, i64, i64, i64) | ||
26 | DEF_HELPER_FLAGS_2(sdiv64, TCG_CALL_NO_RWG_SE, s64, s64, s64) | ||
27 | DEF_HELPER_FLAGS_1(rbit64, TCG_CALL_NO_RWG_SE, i64, i64) | ||
28 | +DEF_HELPER_3(vfp_cmph_a64, i64, f16, f16, ptr) | ||
29 | +DEF_HELPER_3(vfp_cmpeh_a64, i64, f16, f16, ptr) | ||
30 | DEF_HELPER_3(vfp_cmps_a64, i64, f32, f32, ptr) | ||
31 | DEF_HELPER_3(vfp_cmpes_a64, i64, f32, f32, ptr) | ||
32 | DEF_HELPER_3(vfp_cmpd_a64, i64, f64, f64, ptr) | ||
33 | diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/arm/helper-a64.c | ||
36 | +++ b/target/arm/helper-a64.c | ||
37 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t float_rel_to_flags(int res) | ||
38 | return flags; | ||
39 | } | ||
40 | |||
41 | +uint64_t HELPER(vfp_cmph_a64)(float16 x, float16 y, void *fp_status) | ||
42 | +{ | ||
43 | + return float_rel_to_flags(float16_compare_quiet(x, y, fp_status)); | ||
44 | +} | ||
45 | + | ||
46 | +uint64_t HELPER(vfp_cmpeh_a64)(float16 x, float16 y, void *fp_status) | ||
47 | +{ | ||
48 | + return float_rel_to_flags(float16_compare(x, y, fp_status)); | ||
49 | +} | ||
50 | + | ||
51 | uint64_t HELPER(vfp_cmps_a64)(float32 x, float32 y, void *fp_status) | ||
52 | { | ||
53 | return float_rel_to_flags(float32_compare_quiet(x, y, fp_status)); | ||
54 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/arm/translate-a64.c | ||
57 | +++ b/target/arm/translate-a64.c | ||
58 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_reg(DisasContext *s, uint32_t insn) | ||
59 | } | ||
60 | } | ||
61 | |||
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 | + | ||
98 | + switch (size) { | ||
99 | + case MO_32: | ||
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; | ||
139 | + } | ||
140 | + | ||
141 | + switch (type) { | ||
142 | + case 0: | ||
143 | + size = MO_32; | ||
144 | + break; | ||
145 | + case 1: | ||
146 | + size = MO_64; | ||
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; | ||
186 | + } | ||
187 | + | ||
188 | + switch (type) { | ||
189 | + case 0: | ||
190 | + size = MO_32; | ||
191 | + break; | ||
192 | + case 1: | ||
193 | + size = MO_64; | ||
194 | + break; | ||
195 | + case 3: | ||
196 | + size = MO_16; | ||
197 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
198 | + break; | ||
199 | + } | ||
200 | + /* fallthru */ | ||
201 | + default: | ||
202 | unallocated_encoding(s); | ||
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 | -- | ||
215 | 2.17.0 | ||
216 | |||
217 | diff view generated by jsdifflib |
1 | Implement the SG instruction, which we emulate 'by hand' in the | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | exception handling code path. | ||
3 | 2 | ||
3 | These were missed out from the rest of the half-precision work. | ||
4 | |||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
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> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 1507556919-24992-3-git-send-email-peter.maydell@linaro.org | ||
7 | --- | 14 | --- |
8 | target/arm/helper.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++-- | 15 | target/arm/translate-a64.c | 31 +++++++++++++++++++++++++------ |
9 | 1 file changed, 127 insertions(+), 5 deletions(-) | 16 | 1 file changed, 25 insertions(+), 6 deletions(-) |
10 | 17 | ||
11 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 18 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
12 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/helper.c | 20 | --- a/target/arm/translate-a64.c |
14 | +++ b/target/arm/helper.c | 21 | +++ b/target/arm/translate-a64.c |
15 | @@ -XXX,XX +XXX,XX @@ typedef struct V8M_SAttributes { | 22 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) |
16 | bool irvalid; | 23 | unsigned int mos, type, rm, cond, rn, rd; |
17 | } V8M_SAttributes; | 24 | TCGv_i64 t_true, t_false, t_zero; |
18 | 25 | DisasCompare64 c; | |
19 | +static void v8m_security_lookup(CPUARMState *env, uint32_t address, | 26 | + TCGMemOp sz; |
20 | + MMUAccessType access_type, ARMMMUIdx mmu_idx, | 27 | |
21 | + V8M_SAttributes *sattrs); | 28 | mos = extract32(insn, 29, 3); |
22 | + | 29 | - type = extract32(insn, 22, 2); /* 0 = single, 1 = double */ |
23 | /* Definitions for the PMCCNTR and PMCR registers */ | 30 | + type = extract32(insn, 22, 2); |
24 | #define PMCRD 0x8 | 31 | rm = extract32(insn, 16, 5); |
25 | #define PMCRC 0x4 | 32 | cond = extract32(insn, 12, 4); |
26 | @@ -XXX,XX +XXX,XX @@ static void arm_log_exception(int idx) | 33 | rn = extract32(insn, 5, 5); |
27 | } | 34 | rd = extract32(insn, 0, 5); |
28 | } | 35 | |
29 | 36 | - if (mos || type > 1) { | |
30 | +static bool v7m_read_half_insn(ARMCPU *cpu, ARMMMUIdx mmu_idx, | 37 | + if (mos) { |
31 | + uint32_t addr, uint16_t *insn) | 38 | + unallocated_encoding(s); |
32 | +{ | 39 | + return; |
33 | + /* Load a 16-bit portion of a v7M instruction, returning true on success, | ||
34 | + * or false on failure (in which case we will have pended the appropriate | ||
35 | + * exception). | ||
36 | + * We need to do the instruction fetch's MPU and SAU checks | ||
37 | + * like this because there is no MMU index that would allow | ||
38 | + * doing the load with a single function call. Instead we must | ||
39 | + * first check that the security attributes permit the load | ||
40 | + * and that they don't mismatch on the two halves of the instruction, | ||
41 | + * and then we do the load as a secure load (ie using the security | ||
42 | + * attributes of the address, not the CPU, as architecturally required). | ||
43 | + */ | ||
44 | + CPUState *cs = CPU(cpu); | ||
45 | + CPUARMState *env = &cpu->env; | ||
46 | + V8M_SAttributes sattrs = {}; | ||
47 | + MemTxAttrs attrs = {}; | ||
48 | + ARMMMUFaultInfo fi = {}; | ||
49 | + MemTxResult txres; | ||
50 | + target_ulong page_size; | ||
51 | + hwaddr physaddr; | ||
52 | + int prot; | ||
53 | + uint32_t fsr; | ||
54 | + | ||
55 | + v8m_security_lookup(env, addr, MMU_INST_FETCH, mmu_idx, &sattrs); | ||
56 | + if (!sattrs.nsc || sattrs.ns) { | ||
57 | + /* This must be the second half of the insn, and it straddles a | ||
58 | + * region boundary with the second half not being S&NSC. | ||
59 | + */ | ||
60 | + env->v7m.sfsr |= R_V7M_SFSR_INVEP_MASK; | ||
61 | + armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
62 | + qemu_log_mask(CPU_LOG_INT, | ||
63 | + "...really SecureFault with SFSR.INVEP\n"); | ||
64 | + return false; | ||
65 | + } | ||
66 | + if (get_phys_addr(env, addr, MMU_INST_FETCH, mmu_idx, | ||
67 | + &physaddr, &attrs, &prot, &page_size, &fsr, &fi)) { | ||
68 | + /* the MPU lookup failed */ | ||
69 | + env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_IACCVIOL_MASK; | ||
70 | + armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_MEM, env->v7m.secure); | ||
71 | + qemu_log_mask(CPU_LOG_INT, "...really MemManage with CFSR.IACCVIOL\n"); | ||
72 | + return false; | ||
73 | + } | ||
74 | + *insn = address_space_lduw_le(arm_addressspace(cs, attrs), physaddr, | ||
75 | + attrs, &txres); | ||
76 | + if (txres != MEMTX_OK) { | ||
77 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_IBUSERR_MASK; | ||
78 | + armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_BUS, false); | ||
79 | + qemu_log_mask(CPU_LOG_INT, "...really BusFault with CFSR.IBUSERR\n"); | ||
80 | + return false; | ||
81 | + } | ||
82 | + return true; | ||
83 | +} | ||
84 | + | ||
85 | +static bool v7m_handle_execute_nsc(ARMCPU *cpu) | ||
86 | +{ | ||
87 | + /* Check whether this attempt to execute code in a Secure & NS-Callable | ||
88 | + * memory region is for an SG instruction; if so, then emulate the | ||
89 | + * effect of the SG instruction and return true. Otherwise pend | ||
90 | + * the correct kind of exception and return false. | ||
91 | + */ | ||
92 | + CPUARMState *env = &cpu->env; | ||
93 | + ARMMMUIdx mmu_idx; | ||
94 | + uint16_t insn; | ||
95 | + | ||
96 | + /* We should never get here unless get_phys_addr_pmsav8() caused | ||
97 | + * an exception for NS executing in S&NSC memory. | ||
98 | + */ | ||
99 | + assert(!env->v7m.secure); | ||
100 | + assert(arm_feature(env, ARM_FEATURE_M_SECURITY)); | ||
101 | + | ||
102 | + /* We want to do the MPU lookup as secure; work out what mmu_idx that is */ | ||
103 | + mmu_idx = arm_v7m_mmu_idx_for_secstate(env, true); | ||
104 | + | ||
105 | + if (!v7m_read_half_insn(cpu, mmu_idx, env->regs[15], &insn)) { | ||
106 | + return false; | ||
107 | + } | 40 | + } |
108 | + | 41 | + |
109 | + if (!env->thumb) { | 42 | + switch (type) { |
110 | + goto gen_invep; | 43 | + case 0: |
111 | + } | 44 | + sz = MO_32; |
112 | + | 45 | + break; |
113 | + if (insn != 0xe97f) { | 46 | + case 1: |
114 | + /* Not an SG instruction first half (we choose the IMPDEF | 47 | + sz = MO_64; |
115 | + * early-SG-check option). | 48 | + break; |
116 | + */ | 49 | + case 3: |
117 | + goto gen_invep; | 50 | + sz = MO_16; |
118 | + } | 51 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { |
119 | + | 52 | + break; |
120 | + if (!v7m_read_half_insn(cpu, mmu_idx, env->regs[15] + 2, &insn)) { | 53 | + } |
121 | + return false; | 54 | + /* fallthru */ |
122 | + } | 55 | + default: |
123 | + | 56 | unallocated_encoding(s); |
124 | + if (insn != 0xe97f) { | 57 | return; |
125 | + /* Not an SG instruction second half (yes, both halves of the SG | 58 | } |
126 | + * insn have the same hex value) | 59 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) |
127 | + */ | 60 | return; |
128 | + goto gen_invep; | 61 | } |
129 | + } | 62 | |
130 | + | 63 | - /* Zero extend sreg inputs to 64 bits now. */ |
131 | + /* OK, we have confirmed that we really have an SG instruction. | 64 | + /* Zero extend sreg & hreg inputs to 64 bits now. */ |
132 | + * We know we're NS in S memory so don't need to repeat those checks. | 65 | t_true = tcg_temp_new_i64(); |
133 | + */ | 66 | t_false = tcg_temp_new_i64(); |
134 | + qemu_log_mask(CPU_LOG_INT, "...really an SG instruction at 0x%08" PRIx32 | 67 | - read_vec_element(s, t_true, rn, 0, type ? MO_64 : MO_32); |
135 | + ", executing it\n", env->regs[15]); | 68 | - read_vec_element(s, t_false, rm, 0, type ? MO_64 : MO_32); |
136 | + env->regs[14] &= ~1; | 69 | + read_vec_element(s, t_true, rn, 0, sz); |
137 | + switch_v7m_security_state(env, true); | 70 | + read_vec_element(s, t_false, rm, 0, sz); |
138 | + xpsr_write(env, 0, XPSR_IT); | 71 | |
139 | + env->regs[15] += 4; | 72 | a64_test_cc(&c, cond); |
140 | + return true; | 73 | t_zero = tcg_const_i64(0); |
141 | + | 74 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) |
142 | +gen_invep: | 75 | tcg_temp_free_i64(t_false); |
143 | + env->v7m.sfsr |= R_V7M_SFSR_INVEP_MASK; | 76 | a64_free_cc(&c); |
144 | + armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | 77 | |
145 | + qemu_log_mask(CPU_LOG_INT, | 78 | - /* Note that sregs write back zeros to the high bits, |
146 | + "...really SecureFault with SFSR.INVEP\n"); | 79 | + /* Note that sregs & hregs write back zeros to the high bits, |
147 | + return false; | 80 | and we've already done the zero-extension. */ |
148 | +} | 81 | write_fp_dreg(s, rd, t_true); |
149 | + | 82 | tcg_temp_free_i64(t_true); |
150 | void arm_v7m_cpu_do_interrupt(CPUState *cs) | ||
151 | { | ||
152 | ARMCPU *cpu = ARM_CPU(cs); | ||
153 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | ||
154 | * the SG instruction have the same security attributes.) | ||
155 | * Everything else must generate an INVEP SecureFault, so we | ||
156 | * emulate the SG instruction here. | ||
157 | - * TODO: actually emulate SG. | ||
158 | */ | ||
159 | - env->v7m.sfsr |= R_V7M_SFSR_INVEP_MASK; | ||
160 | - armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
161 | - qemu_log_mask(CPU_LOG_INT, | ||
162 | - "...really SecureFault with SFSR.INVEP\n"); | ||
163 | + if (v7m_handle_execute_nsc(cpu)) { | ||
164 | + return; | ||
165 | + } | ||
166 | break; | ||
167 | case M_FAKE_FSR_SFAULT: | ||
168 | /* Various flavours of SecureFault for attempts to execute or | ||
169 | -- | 83 | -- |
170 | 2.7.4 | 84 | 2.17.0 |
171 | 85 | ||
172 | 86 | diff view generated by jsdifflib |
1 | The common situation of the SG instruction is that it is | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | executed from S&NSC memory by a CPU in NS state. That case | ||
3 | is handled by v7m_handle_execute_nsc(). However the instruction | ||
4 | also has defined behaviour in a couple of other cases: | ||
5 | * SG instruction in NS memory (behaves as a NOP) | ||
6 | * SG in S memory but CPU already secure (clears IT bits and | ||
7 | does nothing else) | ||
8 | * SG instruction in v8M without Security Extension (NOP) | ||
9 | 2 | ||
10 | These can be implemented in translate.c. | 3 | All the hard work is already done by vfp_expand_imm, we just need to |
4 | make sure we pick up the correct size. | ||
11 | 5 | ||
6 | Cc: qemu-stable@nongnu.org | ||
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> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 1507556919-24992-10-git-send-email-peter.maydell@linaro.org | ||
15 | --- | 15 | --- |
16 | target/arm/translate.c | 23 ++++++++++++++++++++++- | 16 | target/arm/translate-a64.c | 20 +++++++++++++++++--- |
17 | 1 file changed, 22 insertions(+), 1 deletion(-) | 17 | 1 file changed, 17 insertions(+), 3 deletions(-) |
18 | 18 | ||
19 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 19 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
20 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/translate.c | 21 | --- a/target/arm/translate-a64.c |
22 | +++ b/target/arm/translate.c | 22 | +++ b/target/arm/translate-a64.c |
23 | @@ -XXX,XX +XXX,XX @@ static int disas_thumb2_insn(DisasContext *s, uint32_t insn) | 23 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_imm(DisasContext *s, uint32_t insn) |
24 | * - load/store doubleword, load/store exclusive, ldacq/strel, | 24 | { |
25 | * table branch. | 25 | int rd = extract32(insn, 0, 5); |
26 | */ | 26 | int imm8 = extract32(insn, 13, 8); |
27 | - if (insn & 0x01200000) { | 27 | - int is_double = extract32(insn, 22, 2); |
28 | + if (insn == 0xe97fe97f && arm_dc_feature(s, ARM_FEATURE_M) && | 28 | + int type = extract32(insn, 22, 2); |
29 | + arm_dc_feature(s, ARM_FEATURE_V8)) { | 29 | uint64_t imm; |
30 | + /* 0b1110_1001_0111_1111_1110_1001_0111_111 | 30 | TCGv_i64 tcg_res; |
31 | + * - SG (v8M only) | 31 | + TCGMemOp sz; |
32 | + * The bulk of the behaviour for this instruction is implemented | 32 | |
33 | + * in v7m_handle_execute_nsc(), which deals with the insn when | 33 | - if (is_double > 1) { |
34 | + * it is executed by a CPU in non-secure state from memory | 34 | + switch (type) { |
35 | + * which is Secure & NonSecure-Callable. | 35 | + case 0: |
36 | + * Here we only need to handle the remaining cases: | 36 | + sz = MO_32; |
37 | + * * in NS memory (including the "security extension not | 37 | + break; |
38 | + * implemented" case) : NOP | 38 | + case 1: |
39 | + * * in S memory but CPU already secure (clear IT bits) | 39 | + sz = MO_64; |
40 | + * We know that the attribute for the memory this insn is | 40 | + break; |
41 | + * in must match the current CPU state, because otherwise | 41 | + case 3: |
42 | + * get_phys_addr_pmsav8 would have generated an exception. | 42 | + sz = MO_16; |
43 | + */ | 43 | + if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { |
44 | + if (s->v8m_secure) { | 44 | + break; |
45 | + /* Like the IT insn, we don't need to generate any code */ | 45 | + } |
46 | + s->condexec_cond = 0; | 46 | + /* fallthru */ |
47 | + s->condexec_mask = 0; | 47 | + default: |
48 | + } | 48 | unallocated_encoding(s); |
49 | + } else if (insn & 0x01200000) { | 49 | return; |
50 | /* 0b1110_1000_x11x_xxxx_xxxx_xxxx_xxxx_xxxx | 50 | } |
51 | * - load/store dual (post-indexed) | 51 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_imm(DisasContext *s, uint32_t insn) |
52 | * 0b1111_1001_x10x_xxxx_xxxx_xxxx_xxxx_xxxx | 52 | return; |
53 | } | ||
54 | |||
55 | - imm = vfp_expand_imm(MO_32 + is_double, imm8); | ||
56 | + imm = vfp_expand_imm(sz, imm8); | ||
57 | |||
58 | tcg_res = tcg_const_i64(imm); | ||
59 | write_fp_dreg(s, rd, tcg_res); | ||
53 | -- | 60 | -- |
54 | 2.7.4 | 61 | 2.17.0 |
55 | 62 | ||
56 | 63 | diff view generated by jsdifflib |
1 | The code which implements the Thumb1 split BL/BLX instructions | 1 | From: Alex Bennée <alex.bennee@linaro.org> |
---|---|---|---|
2 | is guarded by a check on "not M or THUMB2". All we really need | ||
3 | to check here is "not THUMB2" (and we assume that elsewhere too, | ||
4 | eg in the ARCH(6T2) test that UNDEFs the Thumb2 insns). | ||
5 | 2 | ||
6 | This doesn't change behaviour because all M profile cores | 3 | We are meant to explicitly pass fpst, not cpu_env. |
7 | have Thumb2 and so ARM_FEATURE_M implies ARM_FEATURE_THUMB2. | ||
8 | (v6M implements a very restricted subset of Thumb2, but we | ||
9 | can cross that bridge when we get to it with appropriate | ||
10 | feature bits.) | ||
11 | 4 | ||
5 | Cc: qemu-stable@nongnu.org | ||
6 | Signed-off-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Tested-by: Alex Bennée <alex.bennee@linaro.org> | ||
10 | Message-id: 20180512003217.9105-12-richard.henderson@linaro.org | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 1507556919-24992-6-git-send-email-peter.maydell@linaro.org | ||
15 | --- | 12 | --- |
16 | target/arm/translate.c | 3 +-- | 13 | target/arm/translate-a64.c | 3 ++- |
17 | 1 file changed, 1 insertion(+), 2 deletions(-) | 14 | 1 file changed, 2 insertions(+), 1 deletion(-) |
18 | 15 | ||
19 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 16 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/translate.c | 18 | --- a/target/arm/translate-a64.c |
22 | +++ b/target/arm/translate.c | 19 | +++ b/target/arm/translate-a64.c |
23 | @@ -XXX,XX +XXX,XX @@ static int disas_thumb2_insn(CPUARMState *env, DisasContext *s, uint16_t insn_hw | 20 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn) |
24 | int conds; | 21 | tcg_gen_xori_i32(tcg_res, tcg_op, 0x8000); |
25 | int logic_cc; | 22 | break; |
26 | 23 | case 0x3: /* FSQRT */ | |
27 | - if (!(arm_dc_feature(s, ARM_FEATURE_THUMB2) | 24 | - gen_helper_sqrt_f16(tcg_res, tcg_op, cpu_env); |
28 | - || arm_dc_feature(s, ARM_FEATURE_M))) { | 25 | + fpst = get_fpstatus_ptr(true); |
29 | + if (!arm_dc_feature(s, ARM_FEATURE_THUMB2)) { | 26 | + gen_helper_sqrt_f16(tcg_res, tcg_op, fpst); |
30 | /* Thumb-1 cores may need to treat bl and blx as a pair of | 27 | break; |
31 | 16-bit instructions to get correct prefetch abort behavior. */ | 28 | case 0x8: /* FRINTN */ |
32 | insn = insn_hw1; | 29 | case 0x9: /* FRINTP */ |
33 | -- | 30 | -- |
34 | 2.7.4 | 31 | 2.17.0 |
35 | 32 | ||
36 | 33 | diff view generated by jsdifflib |
1 | Recent changes have left insn_crosses_page() more complicated | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | than it needed to be: | ||
3 | * it's only called from thumb_tr_translate_insn() so we know | ||
4 | for certain that we're looking at a Thumb insn | ||
5 | * the caller's check for dc->pc >= dc->next_page_start - 3 | ||
6 | means that dc->pc can't possibly be 4 aligned, so there's | ||
7 | no need to check that (the check was partly there to ensure | ||
8 | that we didn't treat an ARM insn as Thumb, I think) | ||
9 | * we now have thumb_insn_is_16bit() which lets us do a precise | ||
10 | check of the length of the next insn, rather than opencoding | ||
11 | an inaccurate check | ||
12 | 2 | ||
13 | Simplify it down to just loading the first half of the insn | 3 | Per the Physical Layer Simplified Spec. "4.3.10.4 Switch Function Status": |
14 | and calling thumb_insn_is_16bit() on it. | ||
15 | 4 | ||
5 | The block length is predefined to 512 bits | ||
6 | |||
7 | and "4.10.2 SD Status": | ||
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> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
18 | Message-id: 1507556919-24992-8-git-send-email-peter.maydell@linaro.org | ||
19 | --- | 20 | --- |
20 | target/arm/translate.c | 27 ++++++--------------------- | 21 | hw/sd/sd.c | 2 +- |
21 | 1 file changed, 6 insertions(+), 21 deletions(-) | 22 | 1 file changed, 1 insertion(+), 1 deletion(-) |
22 | 23 | ||
23 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 24 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c |
24 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/arm/translate.c | 26 | --- a/hw/sd/sd.c |
26 | +++ b/target/arm/translate.c | 27 | +++ b/hw/sd/sd.c |
27 | @@ -XXX,XX +XXX,XX @@ static bool insn_crosses_page(CPUARMState *env, DisasContext *s) | 28 | @@ -XXX,XX +XXX,XX @@ static void sd_function_switch(SDState *sd, uint32_t arg) |
28 | { | 29 | sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4); |
29 | /* Return true if the insn at dc->pc might cross a page boundary. | 30 | } |
30 | * (False positives are OK, false negatives are not.) | 31 | memset(&sd->data[17], 0, 47); |
31 | + * We know this is a Thumb insn, and our caller ensures we are | 32 | - stw_be_p(sd->data + 65, sd_crc16(sd->data, 64)); |
32 | + * only called if dc->pc is less than 4 bytes from the page | 33 | + stw_be_p(sd->data + 64, sd_crc16(sd->data, 64)); |
33 | + * boundary, so we cross the page if the first 16 bits indicate | ||
34 | + * that this is a 32 bit insn. | ||
35 | */ | ||
36 | - uint16_t insn; | ||
37 | + uint16_t insn = arm_lduw_code(env, s->pc, s->sctlr_b); | ||
38 | |||
39 | - if ((s->pc & 3) == 0) { | ||
40 | - /* At a 4-aligned address we can't be crossing a page */ | ||
41 | - return false; | ||
42 | - } | ||
43 | - | ||
44 | - /* This must be a Thumb insn */ | ||
45 | - insn = arm_lduw_code(env, s->pc, s->sctlr_b); | ||
46 | - | ||
47 | - if ((insn >> 11) >= 0x1d) { | ||
48 | - /* Top five bits 0b11101 / 0b11110 / 0b11111 : this is the | ||
49 | - * First half of a 32-bit Thumb insn. Thumb-1 cores might | ||
50 | - * end up actually treating this as two 16-bit insns (see the | ||
51 | - * code at the start of disas_thumb2_insn()) but we don't bother | ||
52 | - * to check for that as it is unlikely, and false positives here | ||
53 | - * are harmless. | ||
54 | - */ | ||
55 | - return true; | ||
56 | - } | ||
57 | - /* Definitely a 16-bit insn, can't be crossing a page. */ | ||
58 | - return false; | ||
59 | + return !thumb_insn_is_16bit(s, insn); | ||
60 | } | 34 | } |
61 | 35 | ||
62 | static int arm_tr_init_disas_context(DisasContextBase *dcbase, | 36 | static inline bool sd_wp_addr(SDState *sd, uint64_t addr) |
63 | -- | 37 | -- |
64 | 2.7.4 | 38 | 2.17.0 |
65 | 39 | ||
66 | 40 | diff view generated by jsdifflib |
1 | Add the M profile secure MMU index values to the switch in | 1 | Usually the logging of the CPU state produced by -d cpu is sufficient |
---|---|---|---|
2 | get_a32_user_mem_index() so that LDRT/STRT work correctly | 2 | to diagnose problems, but sometimes you want to see the state of |
3 | rather than asserting at translate time. | 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. | ||
4 | 6 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 1507556919-24992-2-git-send-email-peter.maydell@linaro.org | 9 | Message-id: 20180510130024.31678-1-peter.maydell@linaro.org |
8 | --- | 10 | --- |
9 | target/arm/translate.c | 4 ++++ | 11 | include/qemu/log.h | 1 + |
10 | 1 file changed, 4 insertions(+) | 12 | accel/tcg/cpu-exec.c | 9 ++++++--- |
13 | util/log.c | 2 ++ | ||
14 | 3 files changed, 9 insertions(+), 3 deletions(-) | ||
11 | 15 | ||
12 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 16 | diff --git a/include/qemu/log.h b/include/qemu/log.h |
13 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/translate.c | 18 | --- a/include/qemu/log.h |
15 | +++ b/target/arm/translate.c | 19 | +++ b/include/qemu/log.h |
16 | @@ -XXX,XX +XXX,XX @@ static inline int get_a32_user_mem_index(DisasContext *s) | 20 | @@ -XXX,XX +XXX,XX @@ static inline bool qemu_log_separate(void) |
17 | case ARMMMUIdx_MPriv: | 21 | #define CPU_LOG_PAGE (1 << 14) |
18 | case ARMMMUIdx_MNegPri: | 22 | /* LOG_TRACE (1 << 15) is defined in log-for-trace.h */ |
19 | return arm_to_core_mmu_idx(ARMMMUIdx_MUser); | 23 | #define CPU_LOG_TB_OP_IND (1 << 16) |
20 | + case ARMMMUIdx_MSUser: | 24 | +#define CPU_LOG_TB_FPU (1 << 17) |
21 | + case ARMMMUIdx_MSPriv: | 25 | |
22 | + case ARMMMUIdx_MSNegPri: | 26 | /* Lock output for a series of related logs. Since this is not needed |
23 | + return arm_to_core_mmu_idx(ARMMMUIdx_MSUser); | 27 | * for a single qemu_log / qemu_log_mask / qemu_log_mask_and_addr, we |
24 | case ARMMMUIdx_S2NS: | 28 | diff --git a/accel/tcg/cpu-exec.c b/accel/tcg/cpu-exec.c |
25 | default: | 29 | index XXXXXXX..XXXXXXX 100644 |
26 | g_assert_not_reached(); | 30 | --- a/accel/tcg/cpu-exec.c |
31 | +++ b/accel/tcg/cpu-exec.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb) | ||
33 | if (qemu_loglevel_mask(CPU_LOG_TB_CPU) | ||
34 | && qemu_log_in_addr_range(itb->pc)) { | ||
35 | qemu_log_lock(); | ||
36 | + int flags = 0; | ||
37 | + if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) { | ||
38 | + flags |= CPU_DUMP_FPU; | ||
39 | + } | ||
40 | #if defined(TARGET_I386) | ||
41 | - log_cpu_state(cpu, CPU_DUMP_CCOP); | ||
42 | -#else | ||
43 | - log_cpu_state(cpu, 0); | ||
44 | + flags |= CPU_DUMP_CCOP; | ||
45 | #endif | ||
46 | + log_cpu_state(cpu, flags); | ||
47 | qemu_log_unlock(); | ||
48 | } | ||
49 | #endif /* DEBUG_DISAS */ | ||
50 | diff --git a/util/log.c b/util/log.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/util/log.c | ||
53 | +++ b/util/log.c | ||
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", | ||
27 | -- | 63 | -- |
28 | 2.7.4 | 64 | 2.17.0 |
29 | 65 | ||
30 | 66 | diff view generated by jsdifflib |