[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 43/76] target/microblaze: Unwind properly when raising divide-by-z
From: |
Richard Henderson |
Subject: |
[PULL 43/76] target/microblaze: Unwind properly when raising divide-by-zero |
Date: |
Mon, 31 Aug 2020 09:05:28 -0700 |
Restore the correct pc when raising divide-by-zero. Also, the
MSR[DZO] bit is sticky -- it is not cleared with a successful divide.
Tested-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/microblaze/helper.h | 4 ++--
target/microblaze/op_helper.c | 23 ++++++++++++-----------
2 files changed, 14 insertions(+), 13 deletions(-)
diff --git a/target/microblaze/helper.h b/target/microblaze/helper.h
index 6f7f96421f..79e1e8ecc7 100644
--- a/target/microblaze/helper.h
+++ b/target/microblaze/helper.h
@@ -1,7 +1,7 @@
DEF_HELPER_FLAGS_2(raise_exception, TCG_CALL_NO_WG, noreturn, env, i32)
-DEF_HELPER_3(divs, i32, env, i32, i32)
-DEF_HELPER_3(divu, i32, env, i32, i32)
+DEF_HELPER_FLAGS_3(divs, TCG_CALL_NO_WG, i32, env, i32, i32)
+DEF_HELPER_FLAGS_3(divu, TCG_CALL_NO_WG, i32, env, i32, i32)
DEF_HELPER_3(fadd, i32, env, i32, i32)
DEF_HELPER_3(frsub, i32, env, i32, i32)
diff --git a/target/microblaze/op_helper.c b/target/microblaze/op_helper.c
index f976d112eb..d99d98051a 100644
--- a/target/microblaze/op_helper.c
+++ b/target/microblaze/op_helper.c
@@ -69,26 +69,27 @@ void helper_raise_exception(CPUMBState *env, uint32_t index)
cpu_loop_exit(cs);
}
-static inline int div_prepare(CPUMBState *env, uint32_t a, uint32_t b)
+static bool check_divz(CPUMBState *env, uint32_t a, uint32_t b, uintptr_t ra)
{
- MicroBlazeCPU *cpu = env_archcpu(env);
-
- if (b == 0) {
+ if (unlikely(b == 0)) {
env->msr |= MSR_DZ;
- if ((env->msr & MSR_EE) && cpu->cfg.div_zero_exception) {
+ if ((env->msr & MSR_EE) &&
+ env_archcpu(env)->cfg.div_zero_exception) {
+ CPUState *cs = env_cpu(env);
+
env->esr = ESR_EC_DIVZERO;
- helper_raise_exception(env, EXCP_HW_EXCP);
+ cs->exception_index = EXCP_HW_EXCP;
+ cpu_loop_exit_restore(cs, ra);
}
- return 0;
+ return false;
}
- env->msr &= ~MSR_DZ;
- return 1;
+ return true;
}
uint32_t helper_divs(CPUMBState *env, uint32_t a, uint32_t b)
{
- if (!div_prepare(env, a, b)) {
+ if (!check_divz(env, a, b, GETPC())) {
return 0;
}
return (int32_t)a / (int32_t)b;
@@ -96,7 +97,7 @@ uint32_t helper_divs(CPUMBState *env, uint32_t a, uint32_t b)
uint32_t helper_divu(CPUMBState *env, uint32_t a, uint32_t b)
{
- if (!div_prepare(env, a, b)) {
+ if (!check_divz(env, a, b, GETPC())) {
return 0;
}
return a / b;
--
2.25.1
- [PULL 33/76] target/microblaze: Remove LOG_DIS, (continued)
- [PULL 33/76] target/microblaze: Remove LOG_DIS, Richard Henderson, 2020/08/31
- [PULL 34/76] target/microblaze: Ensure imm constant is always available, Richard Henderson, 2020/08/31
- [PULL 35/76] target/microblaze: Add decodetree infrastructure, Richard Henderson, 2020/08/31
- [PULL 36/76] target/microblaze: Convert dec_add to decodetree, Richard Henderson, 2020/08/31
- [PULL 37/76] target/microblaze: Convert dec_sub to decodetree, Richard Henderson, 2020/08/31
- [PULL 38/76] target/microblaze: Implement cmp and cmpu inline, Richard Henderson, 2020/08/31
- [PULL 39/76] target/microblaze: Convert dec_pattern to decodetree, Richard Henderson, 2020/08/31
- [PULL 40/76] target/microblaze: Convert dec_and, dec_or, dec_xor to decodetree, Richard Henderson, 2020/08/31
- [PULL 41/76] target/microblaze: Convert dec_mul to decodetree, Richard Henderson, 2020/08/31
- [PULL 42/76] target/microblaze: Convert dec_div to decodetree, Richard Henderson, 2020/08/31
- [PULL 43/76] target/microblaze: Unwind properly when raising divide-by-zero,
Richard Henderson <=
- [PULL 44/76] target/microblaze: Convert dec_bit to decodetree, Richard Henderson, 2020/08/31
- [PULL 45/76] target/microblaze: Convert dec_barrel to decodetree, Richard Henderson, 2020/08/31
- [PULL 46/76] target/microblaze: Convert dec_imm to decodetree, Richard Henderson, 2020/08/31
- [PULL 47/76] target/microblaze: Convert dec_fpu to decodetree, Richard Henderson, 2020/08/31
- [PULL 48/76] target/microblaze: Fix cpu unwind for fpu exceptions, Richard Henderson, 2020/08/31
- [PULL 49/76] target/microblaze: Mark fpu helpers TCG_CALL_NO_WG, Richard Henderson, 2020/08/31
- [PULL 51/76] target/microblaze: Cache mem_index in DisasContext, Richard Henderson, 2020/08/31
- [PULL 50/76] target/microblaze: Replace MSR_EE_FLAG with MSR_EE, Richard Henderson, 2020/08/31
- [PULL 52/76] target/microblaze: Fix cpu unwind for stackprot, Richard Henderson, 2020/08/31
- [PULL 54/76] target/microblaze: Assert no overlap in flags making up tb_flags, Richard Henderson, 2020/08/31