qemu/target/openrisc
Stafford Horne 765fdc1e83 target/openrisc: Set EPCR to next PC on FPE exceptions
The architecture specification calls for the EPCR to be set to "Address
of next not executed instruction" when there is a floating point
exception (FPE).  This was not being done, so fix it by using the same
pattern as syscall.  Also, we move this logic down to be done for
instructions not in the delay slot as called for by the architecture
manual.

Without this patch FPU exceptions will loop, as the exception handling
will always return back to the failed floating point instruction.

This was not noticed in earlier testing because:

 1. The compiler usually generates code which clobbers the input operand
    such as:

      lf.div.s r19,r17,r19

 2. The target will store the operation output before to the register
    before handling the exception.  So an operation such as:

      float a = 100.0f;
      float b = 0.0f;
      float c = a / b;    /* lf.div.s r19,r17,r19 */

    Will first execute:

      100 / 0    -> Store inf to c (r19)
                 -> triggering divide by zero exception
                 -> handle and return

    Then it will execute:

      100 / inf  -> Store 0 to c  (no exception)

To confirm the looping behavior and the fix I used the following:

    float fpu_div(float a, float b) {
	float c;
	asm volatile("lf.div.s %0, %1, %2"
		      : "+r" (c)
		      : "r" (a), "r" (b));
	return c;
    }

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Stafford Horne <shorne@gmail.com>
2023-07-31 22:01:03 +01:00
..
cpu-param.h target/openrisc: Remove NB_MMU_MODES define 2023-03-13 06:44:37 -07:00
cpu.c target/openrisc: Setup FPU for detecting tininess before rounding 2023-05-11 15:40:28 +01:00
cpu.h other architectures: spelling fixes 2023-07-25 17:14:07 +03:00
disas.c
exception.c compiler.h: replace QEMU_NORETURN with G_NORETURN 2022-04-21 17:03:51 +04:00
exception.h compiler.h: replace QEMU_NORETURN with G_NORETURN 2022-04-21 17:03:51 +04:00
exception_helper.c compiler.h: replace QEMU_NORETURN with G_NORETURN 2022-04-21 17:03:51 +04:00
fpu_helper.c target/openrisc: Set PC to cpu state on FPU exception 2023-05-11 15:40:03 +01:00
gdbstub.c gdbstub: move register helpers into standalone include 2023-03-07 20:44:08 +00:00
helper.h
insns.decode
interrupt.c target/openrisc: Set EPCR to next PC on FPE exceptions 2023-07-31 22:01:03 +01:00
interrupt_helper.c
Kconfig meson: Introduce target-specific Kconfig 2021-07-09 18:21:34 +02:00
machine.c Remove unnecessary minimum_version_id_old fields 2022-01-28 15:38:23 +01:00
meson.build meson: Replace softmmu_ss -> system_ss 2023-06-20 10:01:30 +02:00
mmu.c gdbstub: move register helpers into standalone include 2023-03-07 20:44:08 +00:00
sys_helper.c tcg: Add insn_start_words to TCGContext 2023-06-05 12:04:29 -07:00
translate.c other architectures: spelling fixes 2023-07-25 17:14:07 +03:00