linux-user/sh4: Initialize the FPSCR register on signal
PATCH 1/1 linux-user/sh4: Initialize the FPSCR register on signal
On the SH4 architecture, the instructions that perform single precision and double precision floating point operations are encoded in the same way. The bit PR in the FPSCR register determines if the CPU performs single or double operation.
According to the ABI, the PR bit must be set at function entry and function exit.
GCC generates code that flips this bit as needed during function execution. If we get a signal, we must set the PR bit, so that the signal handler finds the bit in the expected state. Qemu lacked this logic, so that if the signal interrupts single-precision floating point calculation, the PR bit would be incorrectly clear at signal handler entry. If the signal handler performed some floating-point calculation, it would get incorrect result.
This patch fixes the bug, by initializing the FPSCR register at signal entry. Note that we initialize the whole register, because the Linux kernel initializes the whole register too.
--- linux-user/sh4/signal.c | 4 ++++ 1 file changed, 4 insertions(+)
linux-user/sh4/signal.c +4 -0
@@ -206,6 +206,8 @@ void setup_frame(int sig, struct target___put_user (set->sig[i +1 ], &frame->extramask[i]); } + regs->fpscr =FPSCR_PR ; +/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags &TARGET_SA_RESTORER ) {
@@ -258,6 +260,8 @@ void setup_rt_frame(int sig, struct targ__put_user (set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } + regs->fpscr =FPSCR_PR ; +/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags &TARGET_SA_RESTORER ) {
Quoted 43 lines · Mikulas Patocka
On the SH4 architecture, the instructions that perform single precision and double precision floating point operations are encoded in the same way. The bit PR in the FPSCR register determines if the CPU performs single or double operation.
According to the ABI, the PR bit must be set at function entry and function exit.
GCC generates code that flips this bit as needed during function execution. If we get a signal, we must set the PR bit, so that the signal handler finds the bit in the expected state. Qemu lacked this logic, so that if the signal interrupts single-precision floating point calculation, the PR bit would be incorrectly clear at signal handler entry. If the signal handler performed some floating-point calculation, it would get incorrect result.
This patch fixes the bug, by initializing the FPSCR register at signal entry. Note that we initialize the whole register, because the Linux kernel initializes the whole register too.
Signed-off-by Mikulas Patocka <[email protected]>--- linux-user/sh4/signal.c | 4 ++++ 1 file changed, 4 insertions(+)Index:
qemu/linux-user/sh4/signal.c
===================================================================linux-user/sh4/signal.c +2
-0@@ -206,6 +206,8 @@ void setup_frame(int sig, struct target___put_user (set->sig[i +1 ], &frame->extramask[i]); } + regs->fpscr =FPSCR_PR ; +/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags &TARGET_SA_RESTORER ) {
linux-user/sh4/signal.c void setup_rt_frame(int sig, struct targ · line 267
Quoted 8 lines
linux-user/sh4/signal.c +2
-0@@ -258,6 +260,8 @@ void setup_rt_frame(int sig, struct targ__put_user (set->sig[i], &frame->uc.tuc_sigmask.sig[i]); } + regs->fpscr =FPSCR_PR ; +/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa_flags &TARGET_SA_RESTORER ) {
Signature · 1 line
Yosinori Sato