linux/arch/nds32/kernel/sys_nds32.c
Vincent Chen ed32949e0a 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: Vincent Chen <vincentc@andestech.com>
Acked-by: Greentime Hu <greentime@andestech.com>
Signed-off-by: Greentime Hu <greentime@andestech.com>
2019-05-31 15:23:26 +08:00

85 lines
1.8 KiB
C

// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2005-2017 Andes Technology Corporation
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <asm/cachectl.h>
#include <asm/proc-fns.h>
#include <asm/fpu.h>
#include <asm/fp_udfiex_crtl.h>
SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
unsigned long, prot, unsigned long, flags,
unsigned long, fd, unsigned long, pgoff)
{
if (pgoff & (~PAGE_MASK >> 12))
return -EINVAL;
return sys_mmap_pgoff(addr, len, prot, flags, fd,
pgoff >> (PAGE_SHIFT - 12));
}
SYSCALL_DEFINE4(fadvise64_64_wrapper,int, fd, int, advice, loff_t, offset,
loff_t, len)
{
return sys_fadvise64_64(fd, offset, len, advice);
}
SYSCALL_DEFINE3(cacheflush, unsigned int, start, unsigned int, end, int, cache)
{
struct vm_area_struct *vma;
bool flushi = true, wbd = true;
vma = find_vma(current->mm, start);
if (!vma)
return -EFAULT;
switch (cache) {
case ICACHE:
wbd = false;
break;
case DCACHE:
flushi = false;
break;
case BCACHE:
break;
default:
return -EINVAL;
}
cpu_cache_wbinval_range_check(vma, start, end, flushi, wbd);
return 0;
}
SYSCALL_DEFINE2(fp_udfiex_crtl, unsigned int, cmd, unsigned int, act)
{
#if IS_ENABLED(CONFIG_SUPPORT_DENORMAL_ARITHMETIC)
int old_udf_iex;
if (!used_math()) {
load_fpu(&init_fpuregs);
current->thread.fpu.UDF_IEX_trap = init_fpuregs.UDF_IEX_trap;
set_used_math();
}
old_udf_iex = current->thread.fpu.UDF_IEX_trap;
act &= (FPCSR_mskUDFE | FPCSR_mskIEXE);
switch (cmd) {
case DISABLE_UDF_IEX_TRAP:
current->thread.fpu.UDF_IEX_trap &= ~act;
break;
case ENABLE_UDF_IEX_TRAP:
current->thread.fpu.UDF_IEX_trap |= act;
break;
case GET_UDF_IEX_TRAP:
break;
default:
return -EINVAL;
}
return old_udf_iex;
#else
return -ENOTSUPP;
#endif
}