* [PULL 0/3] OpenRISC FPU Updates for 8.1 @ 2023-05-13 8:05 Stafford Horne 2023-05-13 8:05 ` [PULL 1/3] target/openrisc: Allow fpcsr access in user mode Stafford Horne ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: Stafford Horne @ 2023-05-13 8:05 UTC (permalink / raw) To: QEMU Development; +Cc: Stafford Horne The following changes since commit c1eb2ddf0f8075faddc5f7c3d39feae3e8e9d6b4: Update version for v8.0.0 release (2023-04-19 17:27:13 +0100) are available in the Git repository at: https://github.com/stffrdhrn/qemu.git tags/or1k-pull-request-20230513 for you to fetch changes up to 874c52991e1fbe020812b4b15440b6875369aacf: target/openrisc: Setup FPU for detecting tininess before rounding (2023-05-11 15:40:28 +0100) ---------------------------------------------------------------- OpenRISC FPU Updates for 8.1 A few fixes and updates to bring OpenRISC inline with the latest architecture spec updates: - Allow FPCSR to be accessed in user mode - Select tininess detection before rounding - Fix FPE Exception PC value ---------------------------------------------------------------- Stafford Horne (3): target/openrisc: Allow fpcsr access in user mode target/openrisc: Set PC to cpu state on FPU exception target/openrisc: Setup FPU for detecting tininess before rounding target/openrisc/cpu.c | 4 +++ target/openrisc/fpu_helper.c | 13 ++++++-- target/openrisc/sys_helper.c | 45 ++++++++++++++++++++------- target/openrisc/translate.c | 72 ++++++++++++++++++++------------------------ 4 files changed, 81 insertions(+), 53 deletions(-) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PULL 1/3] target/openrisc: Allow fpcsr access in user mode 2023-05-13 8:05 [PULL 0/3] OpenRISC FPU Updates for 8.1 Stafford Horne @ 2023-05-13 8:05 ` Stafford Horne 2023-05-13 8:05 ` [PULL 2/3] target/openrisc: Set PC to cpu state on FPU exception Stafford Horne ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: Stafford Horne @ 2023-05-13 8:05 UTC (permalink / raw) To: QEMU Development; +Cc: Stafford Horne, Richard Henderson As per OpenRISC spec 1.4 FPCSR can be read and written in user mode. Update mtspr and mfspr helpers to support this by moving the is_user check into the helper. Link: https://raw.githubusercontent.com/openrisc/doc/master/openrisc-arch-1.4-rev0.pdf Signed-off-by: Stafford Horne <shorne@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/openrisc/sys_helper.c | 45 ++++++++++++++++------ target/openrisc/translate.c | 72 ++++++++++++++++-------------------- 2 files changed, 66 insertions(+), 51 deletions(-) diff --git a/target/openrisc/sys_helper.c b/target/openrisc/sys_helper.c index ec145960e3..ccdee3b8be 100644 --- a/target/openrisc/sys_helper.c +++ b/target/openrisc/sys_helper.c @@ -29,17 +29,37 @@ #define TO_SPR(group, number) (((group) << 11) + (number)) +static inline bool is_user(CPUOpenRISCState *env) +{ +#ifdef CONFIG_USER_ONLY + return true; +#else + return (env->sr & SR_SM) == 0; +#endif +} + void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) { -#ifndef CONFIG_USER_ONLY OpenRISCCPU *cpu = env_archcpu(env); +#ifndef CONFIG_USER_ONLY CPUState *cs = env_cpu(env); target_ulong mr; int idx; #endif + /* Handle user accessible SPRs first. */ switch (spr) { + case TO_SPR(0, 20): /* FPCSR */ + cpu_set_fpcsr(env, rb); + return; + } + + if (is_user(env)) { + raise_exception(cpu, EXCP_ILLEGAL); + } + #ifndef CONFIG_USER_ONLY + switch (spr) { case TO_SPR(0, 11): /* EVBAR */ env->evbar = rb; break; @@ -187,27 +207,33 @@ void HELPER(mtspr)(CPUOpenRISCState *env, target_ulong spr, target_ulong rb) cpu_openrisc_timer_update(cpu); qemu_mutex_unlock_iothread(); break; -#endif - - case TO_SPR(0, 20): /* FPCSR */ - cpu_set_fpcsr(env, rb); - break; } +#endif } target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd, target_ulong spr) { + OpenRISCCPU *cpu = env_archcpu(env); #ifndef CONFIG_USER_ONLY uint64_t data[TARGET_INSN_START_WORDS]; MachineState *ms = MACHINE(qdev_get_machine()); - OpenRISCCPU *cpu = env_archcpu(env); CPUState *cs = env_cpu(env); int idx; #endif + /* Handle user accessible SPRs first. */ switch (spr) { + case TO_SPR(0, 20): /* FPCSR */ + return env->fpcsr; + } + + if (is_user(env)) { + raise_exception(cpu, EXCP_ILLEGAL); + } + #ifndef CONFIG_USER_ONLY + switch (spr) { case TO_SPR(0, 0): /* VR */ return env->vr; @@ -324,11 +350,8 @@ target_ulong HELPER(mfspr)(CPUOpenRISCState *env, target_ulong rd, cpu_openrisc_count_update(cpu); qemu_mutex_unlock_iothread(); return cpu_openrisc_count_get(cpu); -#endif - - case TO_SPR(0, 20): /* FPCSR */ - return env->fpcsr; } +#endif /* for rd is passed in, if rd unchanged, just keep it back. */ return rd; diff --git a/target/openrisc/translate.c b/target/openrisc/translate.c index 76e53c78d4..43ba0cc1ad 100644 --- a/target/openrisc/translate.c +++ b/target/openrisc/translate.c @@ -819,45 +819,12 @@ static bool trans_l_xori(DisasContext *dc, arg_rri *a) static bool trans_l_mfspr(DisasContext *dc, arg_l_mfspr *a) { - check_r0_write(dc, a->d); - - if (is_user(dc)) { - gen_illegal_exception(dc); - } else { - TCGv spr = tcg_temp_new(); - - if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) { - gen_io_start(); - if (dc->delayed_branch) { - tcg_gen_mov_tl(cpu_pc, jmp_pc); - tcg_gen_discard_tl(jmp_pc); - } else { - tcg_gen_movi_tl(cpu_pc, dc->base.pc_next + 4); - } - dc->base.is_jmp = DISAS_EXIT; - } + TCGv spr = tcg_temp_new(); - tcg_gen_ori_tl(spr, cpu_R(dc, a->a), a->k); - gen_helper_mfspr(cpu_R(dc, a->d), cpu_env, cpu_R(dc, a->d), spr); - } - return true; -} - -static bool trans_l_mtspr(DisasContext *dc, arg_l_mtspr *a) -{ - if (is_user(dc)) { - gen_illegal_exception(dc); - } else { - TCGv spr; + check_r0_write(dc, a->d); - if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) { - gen_io_start(); - } - /* For SR, we will need to exit the TB to recognize the new - * exception state. For NPC, in theory this counts as a branch - * (although the SPR only exists for use by an ICE). Save all - * of the cpu state first, allowing it to be overwritten. - */ + if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); if (dc->delayed_branch) { tcg_gen_mov_tl(cpu_pc, jmp_pc); tcg_gen_discard_tl(jmp_pc); @@ -865,11 +832,36 @@ static bool trans_l_mtspr(DisasContext *dc, arg_l_mtspr *a) tcg_gen_movi_tl(cpu_pc, dc->base.pc_next + 4); } dc->base.is_jmp = DISAS_EXIT; + } + + tcg_gen_ori_tl(spr, cpu_R(dc, a->a), a->k); + gen_helper_mfspr(cpu_R(dc, a->d), cpu_env, cpu_R(dc, a->d), spr); + return true; +} + +static bool trans_l_mtspr(DisasContext *dc, arg_l_mtspr *a) +{ + TCGv spr = tcg_temp_new(); - spr = tcg_temp_new(); - tcg_gen_ori_tl(spr, cpu_R(dc, a->a), a->k); - gen_helper_mtspr(cpu_env, spr, cpu_R(dc, a->b)); + if (tb_cflags(dc->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); } + /* + * For SR, we will need to exit the TB to recognize the new + * exception state. For NPC, in theory this counts as a branch + * (although the SPR only exists for use by an ICE). Save all + * of the cpu state first, allowing it to be overwritten. + */ + if (dc->delayed_branch) { + tcg_gen_mov_tl(cpu_pc, jmp_pc); + tcg_gen_discard_tl(jmp_pc); + } else { + tcg_gen_movi_tl(cpu_pc, dc->base.pc_next + 4); + } + dc->base.is_jmp = DISAS_EXIT; + + tcg_gen_ori_tl(spr, cpu_R(dc, a->a), a->k); + gen_helper_mtspr(cpu_env, spr, cpu_R(dc, a->b)); return true; } -- 2.39.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PULL 2/3] target/openrisc: Set PC to cpu state on FPU exception 2023-05-13 8:05 [PULL 0/3] OpenRISC FPU Updates for 8.1 Stafford Horne 2023-05-13 8:05 ` [PULL 1/3] target/openrisc: Allow fpcsr access in user mode Stafford Horne @ 2023-05-13 8:05 ` Stafford Horne 2023-05-13 8:05 ` [PULL 3/3] target/openrisc: Setup FPU for detecting tininess before rounding Stafford Horne 2023-05-14 1:24 ` [PULL 0/3] OpenRISC FPU Updates for 8.1 Richard Henderson 3 siblings, 0 replies; 5+ messages in thread From: Stafford Horne @ 2023-05-13 8:05 UTC (permalink / raw) To: QEMU Development; +Cc: Stafford Horne, Richard Henderson Store the PC to ensure the correct value can be read in the exception handler. Signed-off-by: Stafford Horne <shorne@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/openrisc/fpu_helper.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/target/openrisc/fpu_helper.c b/target/openrisc/fpu_helper.c index f9e34fa2cc..8b81d2f62f 100644 --- a/target/openrisc/fpu_helper.c +++ b/target/openrisc/fpu_helper.c @@ -20,8 +20,8 @@ #include "qemu/osdep.h" #include "cpu.h" +#include "exec/exec-all.h" #include "exec/helper-proto.h" -#include "exception.h" #include "fpu/softfloat.h" static int ieee_ex_to_openrisc(int fexcp) @@ -45,6 +45,15 @@ static int ieee_ex_to_openrisc(int fexcp) return ret; } +static G_NORETURN +void do_fpe(CPUOpenRISCState *env, uintptr_t pc) +{ + CPUState *cs = env_cpu(env); + + cs->exception_index = EXCP_FPE; + cpu_loop_exit_restore(cs, pc); +} + void HELPER(update_fpcsr)(CPUOpenRISCState *env) { int tmp = get_float_exception_flags(&env->fp_status); @@ -55,7 +64,7 @@ void HELPER(update_fpcsr)(CPUOpenRISCState *env) if (tmp) { env->fpcsr |= tmp; if (env->fpcsr & FPCSR_FPEE) { - helper_exception(env, EXCP_FPE); + do_fpe(env, GETPC()); } } } -- 2.39.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PULL 3/3] target/openrisc: Setup FPU for detecting tininess before rounding 2023-05-13 8:05 [PULL 0/3] OpenRISC FPU Updates for 8.1 Stafford Horne 2023-05-13 8:05 ` [PULL 1/3] target/openrisc: Allow fpcsr access in user mode Stafford Horne 2023-05-13 8:05 ` [PULL 2/3] target/openrisc: Set PC to cpu state on FPU exception Stafford Horne @ 2023-05-13 8:05 ` Stafford Horne 2023-05-14 1:24 ` [PULL 0/3] OpenRISC FPU Updates for 8.1 Richard Henderson 3 siblings, 0 replies; 5+ messages in thread From: Stafford Horne @ 2023-05-13 8:05 UTC (permalink / raw) To: QEMU Development; +Cc: Stafford Horne, Richard Henderson OpenRISC defines tininess to be detected before rounding. Setup qemu to obey this. Signed-off-by: Stafford Horne <shorne@gmail.com> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> --- target/openrisc/cpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/target/openrisc/cpu.c b/target/openrisc/cpu.c index 0ce4f796fa..61d748cfdc 100644 --- a/target/openrisc/cpu.c +++ b/target/openrisc/cpu.c @@ -22,6 +22,7 @@ #include "qemu/qemu-print.h" #include "cpu.h" #include "exec/exec-all.h" +#include "fpu/softfloat-helpers.h" #include "tcg/tcg.h" static void openrisc_cpu_set_pc(CPUState *cs, vaddr value) @@ -90,6 +91,9 @@ static void openrisc_cpu_reset_hold(Object *obj) s->exception_index = -1; cpu_set_fpcsr(&cpu->env, 0); + set_float_detect_tininess(float_tininess_before_rounding, + &cpu->env.fp_status); + #ifndef CONFIG_USER_ONLY cpu->env.picmr = 0x00000000; cpu->env.picsr = 0x00000000; -- 2.39.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PULL 0/3] OpenRISC FPU Updates for 8.1 2023-05-13 8:05 [PULL 0/3] OpenRISC FPU Updates for 8.1 Stafford Horne ` (2 preceding siblings ...) 2023-05-13 8:05 ` [PULL 3/3] target/openrisc: Setup FPU for detecting tininess before rounding Stafford Horne @ 2023-05-14 1:24 ` Richard Henderson 3 siblings, 0 replies; 5+ messages in thread From: Richard Henderson @ 2023-05-14 1:24 UTC (permalink / raw) To: Stafford Horne, QEMU Development On 5/13/23 01:05, Stafford Horne wrote: > The following changes since commit c1eb2ddf0f8075faddc5f7c3d39feae3e8e9d6b4: > > Update version for v8.0.0 release (2023-04-19 17:27:13 +0100) > > are available in the Git repository at: > > https://github.com/stffrdhrn/qemu.git tags/or1k-pull-request-20230513 > > for you to fetch changes up to 874c52991e1fbe020812b4b15440b6875369aacf: > > target/openrisc: Setup FPU for detecting tininess before rounding (2023-05-11 15:40:28 +0100) > > ---------------------------------------------------------------- > OpenRISC FPU Updates for 8.1 > > A few fixes and updates to bring OpenRISC inline with the latest > architecture spec updates: > > - Allow FPCSR to be accessed in user mode > - Select tininess detection before rounding > - Fix FPE Exception PC value Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/8.1 as appropriate. r~ ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-05-14 1:25 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-05-13 8:05 [PULL 0/3] OpenRISC FPU Updates for 8.1 Stafford Horne 2023-05-13 8:05 ` [PULL 1/3] target/openrisc: Allow fpcsr access in user mode Stafford Horne 2023-05-13 8:05 ` [PULL 2/3] target/openrisc: Set PC to cpu state on FPU exception Stafford Horne 2023-05-13 8:05 ` [PULL 3/3] target/openrisc: Setup FPU for detecting tininess before rounding Stafford Horne 2023-05-14 1:24 ` [PULL 0/3] OpenRISC FPU Updates for 8.1 Richard Henderson
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).