Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed32949e authored by Vincent Chen's avatar Vincent Chen Committed by Greentime Hu
Browse files

nds32: Avoid IEX status being incorrectly modified



In order for kernel to capture each denormalized output, the UDF
trapping enable bit is always raised in $fpcsr. Because underflow case will
issue not an underflow exception but also an inexact exception, it causes
that the IEX, IEX cumulative exception, flag in $fpcsr to be raised in each
denormalized output handling. To make the emulation transparent to the
user, the emulator needs to clear the IEX flag in $fpcsr if the result is a
denormalized number. However, if the IEX flag has been raised before this
floating point emulation, this cleanup may be incorrect. To avoid the IEX
flags in $fpcsr be raised in each denormalized output handling, the IEX
trap shall be always enabled.

Signed-off-by: default avatarVincent Chen <vincentc@andestech.com>
Acked-by: default avatarGreentime Hu <greentime@andestech.com>
Signed-off-by: default avatarGreentime Hu <greentime@andestech.com>
parent 8183db10
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -937,7 +937,7 @@
#define FPCSR_mskDNIT           ( 0x1  << FPCSR_offDNIT )
#define FPCSR_mskRIT		( 0x1  << FPCSR_offRIT )
#define FPCSR_mskALL		(FPCSR_mskIVO | FPCSR_mskDBZ | FPCSR_mskOVF | FPCSR_mskUDF | FPCSR_mskIEX)
#define FPCSR_mskALLE_NO_UDFE	(FPCSR_mskIVOE | FPCSR_mskDBZE | FPCSR_mskOVFE | FPCSR_mskIEXE)
#define FPCSR_mskALLE_NO_UDF_IEXE (FPCSR_mskIVOE | FPCSR_mskDBZE | FPCSR_mskOVFE)
#define FPCSR_mskALLE		(FPCSR_mskIVOE | FPCSR_mskDBZE | FPCSR_mskOVFE | FPCSR_mskUDFE | FPCSR_mskIEXE)
#define FPCSR_mskALLT           (FPCSR_mskIVOT | FPCSR_mskDBZT | FPCSR_mskOVFT | FPCSR_mskUDFT | FPCSR_mskIEXT |FPCSR_mskDNIT | FPCSR_mskRIT)

+1 −1
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ extern int do_fpuemu(struct pt_regs *regs, struct fpu_struct *fpu);
 * enabled by default and kerenl will re-execute it by fpu emulator
 * when getting underflow exception.
 */
#define FPCSR_INIT  FPCSR_mskUDFE
#define FPCSR_INIT  (FPCSR_mskUDFE | FPCSR_mskIEXE)
#else
#define FPCSR_INIT  0x0UL
#endif
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@
asmlinkage long sys_cacheflush(unsigned long addr, unsigned long len, unsigned int op);
asmlinkage long sys_fadvise64_64_wrapper(int fd, int advice, loff_t offset, loff_t len);
asmlinkage long sys_rt_sigreturn_wrapper(void);
asmlinkage long sys_udftrap(int option);
asmlinkage long sys_fp_udfiex_crtl(int cmd, int act);

#include <asm-generic/syscalls.h>

+16 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2005-2019 Andes Technology Corporation */
#ifndef	_FP_UDF_IEX_CRTL_H
#define	_FP_UDF_IEX_CRTL_H

/*
 * The cmd list of sys_fp_udfiex_crtl()
 */
/* Disable UDF or IEX trap based on the content of parameter act */
#define DISABLE_UDF_IEX_TRAP	0
/* Enable UDF or IEX trap based on the content of parameter act */
#define ENABLE_UDF_IEX_TRAP	1
/* Get current status of UDF and IEX trap */
#define GET_UDF_IEX_TRAP	2

#endif /* _FP_UDF_IEX_CRTL_H */
+17 −7
Original line number Diff line number Diff line
@@ -13,14 +13,24 @@ struct fpu_struct {
	unsigned long long fd_regs[32];
	unsigned long fpcsr;
	/*
	 * UDF_trap is used to recognize whether underflow trap is enabled
	 * or not. When UDF_trap == 1, this process will be traped and then
	 * get a SIGFPE signal when encountering an underflow exception.
	 * UDF_trap is only modified through setfputrap syscall. Therefore,
	 * UDF_trap needn't be saved or loaded to context in each context
	 * switch.
	 * When CONFIG_SUPPORT_DENORMAL_ARITHMETIC is defined, kernel prevents
	 * hardware from treating the denormalized output as an underflow case
	 * and rounding it to a normal number. Hence kernel enables the UDF and
	 * IEX trap in the fpcsr register to step in the calculation.
	 * However, the UDF and IEX trap enable bit in $fpcsr also lose
	 * their use.
	 *
	 * UDF_IEX_trap replaces the feature of UDF and IEX trap enable bit in
	 * $fpcsr to control the trap of underflow and inexact. The bit filed
	 * of UDF_IEX_trap is the same as $fpcsr, 10th bit is used to enable UDF
	 * exception trapping and 11th bit is used to enable IEX exception
	 * trapping.
	 *
	 * UDF_IEX_trap is only modified through fp_udfiex_crtl syscall.
	 * Therefore, UDF_IEX_trap needn't be saved and restored in each
	 * context switch.
	 */
	unsigned long UDF_trap;
	unsigned long UDF_IEX_trap;
};

struct zol_struct {
Loading