You've already forked linux-rockchip
mirror of
https://github.com/armbian/linux-rockchip.git
synced 2026-01-06 11:08:10 -08:00
sh: math-emu support
This implements initial math-emu support, aimed primarily at SH-3. Signed-off-by: Takashi YOSHII <takasi-y@ops.dti.ne.jp> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
This commit is contained in:
committed by
Paul Mundt
parent
317a6104a9
commit
4b565680d1
@@ -339,6 +339,15 @@ config SH_FPU
|
||||
|
||||
This option must be set in order to enable the FPU.
|
||||
|
||||
config SH_FPU_EMU
|
||||
bool "FPU emulation support"
|
||||
depends on !SH_FPU && EXPERIMENTAL
|
||||
default n
|
||||
help
|
||||
Selecting this option will enable support for software FPU emulation.
|
||||
Most SH-3 users will want to say Y here, whereas most SH-4 users will
|
||||
want to say N.
|
||||
|
||||
config SH_DSP
|
||||
bool "DSP support"
|
||||
depends on !CPU_SH4
|
||||
|
||||
@@ -79,6 +79,7 @@ head-y := arch/sh/kernel/head.o arch/sh/kernel/init_task.o
|
||||
LIBGCC := $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
|
||||
|
||||
core-y += arch/sh/kernel/ arch/sh/mm/
|
||||
core-$(CONFIG_SH_FPU_EMU) += arch/sh/math-emu/
|
||||
|
||||
# Boards
|
||||
machdir-$(CONFIG_SH_SOLUTION_ENGINE) := se/770x
|
||||
|
||||
@@ -36,40 +36,15 @@
|
||||
|
||||
#ifdef CONFIG_SH_KGDB
|
||||
#include <asm/kgdb.h>
|
||||
#define CHK_REMOTE_DEBUG(regs) \
|
||||
{ \
|
||||
if ((kgdb_debug_hook != (kgdb_debug_hook_t *) NULL) && (!user_mode(regs))) \
|
||||
{ \
|
||||
(*kgdb_debug_hook)(regs); \
|
||||
} \
|
||||
#define CHK_REMOTE_DEBUG(regs) \
|
||||
{ \
|
||||
if (kgdb_debug_hook && !user_mode(regs))\
|
||||
(*kgdb_debug_hook)(regs); \
|
||||
}
|
||||
#else
|
||||
#define CHK_REMOTE_DEBUG(regs)
|
||||
#endif
|
||||
|
||||
#define DO_ERROR(trapnr, signr, str, name, tsk) \
|
||||
asmlinkage void do_##name(unsigned long r4, unsigned long r5, \
|
||||
unsigned long r6, unsigned long r7, \
|
||||
struct pt_regs regs) \
|
||||
{ \
|
||||
unsigned long error_code; \
|
||||
\
|
||||
/* Check if it's a DSP instruction */ \
|
||||
if (is_dsp_inst(®s)) { \
|
||||
/* Enable DSP mode, and restart instruction. */ \
|
||||
regs.sr |= SR_DSP; \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
asm volatile("stc r2_bank, %0": "=r" (error_code)); \
|
||||
local_irq_enable(); \
|
||||
tsk->thread.error_code = error_code; \
|
||||
tsk->thread.trap_no = trapnr; \
|
||||
CHK_REMOTE_DEBUG(®s); \
|
||||
force_sig(signr, tsk); \
|
||||
die_if_no_fixup(str,®s,error_code); \
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CPU_SH2
|
||||
#define TRAP_RESERVED_INST 4
|
||||
#define TRAP_ILLEGAL_SLOT_INST 6
|
||||
@@ -575,8 +550,117 @@ int is_dsp_inst(struct pt_regs *regs)
|
||||
#define is_dsp_inst(regs) (0)
|
||||
#endif /* CONFIG_SH_DSP */
|
||||
|
||||
DO_ERROR(TRAP_RESERVED_INST, SIGILL, "reserved instruction", reserved_inst, current)
|
||||
DO_ERROR(TRAP_ILLEGAL_SLOT_INST, SIGILL, "illegal slot instruction", illegal_slot_inst, current)
|
||||
extern int do_fpu_inst(unsigned short, struct pt_regs*);
|
||||
|
||||
asmlinkage void do_reserved_inst(unsigned long r4, unsigned long r5,
|
||||
unsigned long r6, unsigned long r7,
|
||||
struct pt_regs regs)
|
||||
{
|
||||
unsigned long error_code;
|
||||
struct task_struct *tsk = current;
|
||||
|
||||
#ifdef CONFIG_SH_FPU_EMU
|
||||
unsigned short inst;
|
||||
int err;
|
||||
|
||||
get_user(inst, (unsigned short*)regs.pc);
|
||||
|
||||
err = do_fpu_inst(inst, ®s);
|
||||
if (!err) {
|
||||
regs.pc += 2;
|
||||
return;
|
||||
}
|
||||
/* not a FPU inst. */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SH_DSP
|
||||
/* Check if it's a DSP instruction */
|
||||
if (is_dsp_inst(®s)) {
|
||||
/* Enable DSP mode, and restart instruction. */
|
||||
regs.sr |= SR_DSP;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
asm volatile("stc r2_bank, %0": "=r" (error_code));
|
||||
local_irq_enable();
|
||||
tsk->thread.error_code = error_code;
|
||||
tsk->thread.trap_no = TRAP_RESERVED_INST;
|
||||
CHK_REMOTE_DEBUG(®s);
|
||||
force_sig(SIGILL, tsk);
|
||||
die_if_no_fixup("reserved instruction", ®s, error_code);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SH_FPU_EMU
|
||||
static int emulate_branch(unsigned short inst, struct pt_regs* regs)
|
||||
{
|
||||
/*
|
||||
* bfs: 8fxx: PC+=d*2+4;
|
||||
* bts: 8dxx: PC+=d*2+4;
|
||||
* bra: axxx: PC+=D*2+4;
|
||||
* bsr: bxxx: PC+=D*2+4 after PR=PC+4;
|
||||
* braf:0x23: PC+=Rn*2+4;
|
||||
* bsrf:0x03: PC+=Rn*2+4 after PR=PC+4;
|
||||
* jmp: 4x2b: PC=Rn;
|
||||
* jsr: 4x0b: PC=Rn after PR=PC+4;
|
||||
* rts: 000b: PC=PR;
|
||||
*/
|
||||
if ((inst & 0xfd00) == 0x8d00) {
|
||||
regs->pc += SH_PC_8BIT_OFFSET(inst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((inst & 0xe000) == 0xa000) {
|
||||
regs->pc += SH_PC_12BIT_OFFSET(inst);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((inst & 0xf0df) == 0x0003) {
|
||||
regs->pc += regs->regs[(inst & 0x0f00) >> 8] + 4;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((inst & 0xf0df) == 0x400b) {
|
||||
regs->pc = regs->regs[(inst & 0x0f00) >> 8];
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((inst & 0xffff) == 0x000b) {
|
||||
regs->pc = regs->pr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
asmlinkage void do_illegal_slot_inst(unsigned long r4, unsigned long r5,
|
||||
unsigned long r6, unsigned long r7,
|
||||
struct pt_regs regs)
|
||||
{
|
||||
unsigned long error_code;
|
||||
struct task_struct *tsk = current;
|
||||
#ifdef CONFIG_SH_FPU_EMU
|
||||
unsigned short inst;
|
||||
|
||||
get_user(inst, (unsigned short *)regs.pc + 1);
|
||||
if (!do_fpu_inst(inst, ®s)) {
|
||||
get_user(inst, (unsigned short *)regs.pc);
|
||||
if (!emulate_branch(inst, ®s))
|
||||
return;
|
||||
/* fault in branch.*/
|
||||
}
|
||||
/* not a FPU inst. */
|
||||
#endif
|
||||
|
||||
asm volatile("stc r2_bank, %0": "=r" (error_code));
|
||||
local_irq_enable();
|
||||
tsk->thread.error_code = error_code;
|
||||
tsk->thread.trap_no = TRAP_RESERVED_INST;
|
||||
CHK_REMOTE_DEBUG(®s);
|
||||
force_sig(SIGILL, tsk);
|
||||
die_if_no_fixup("illegal slot instruction", ®s, error_code);
|
||||
}
|
||||
|
||||
asmlinkage void do_exception_error(unsigned long r4, unsigned long r5,
|
||||
unsigned long r6, unsigned long r7,
|
||||
@@ -634,14 +718,16 @@ void __init trap_init(void)
|
||||
exception_handling_table[TRAP_ILLEGAL_SLOT_INST]
|
||||
= (void *)do_illegal_slot_inst;
|
||||
|
||||
#ifdef CONFIG_CPU_SH4
|
||||
if (!(cpu_data->flags & CPU_HAS_FPU)) {
|
||||
/* For SH-4 lacking an FPU, treat floating point instructions
|
||||
as reserved. */
|
||||
/* entry 64 corresponds to EXPEVT=0x800 */
|
||||
exception_handling_table[64] = (void *)do_reserved_inst;
|
||||
exception_handling_table[65] = (void *)do_illegal_slot_inst;
|
||||
}
|
||||
#if defined(CONFIG_CPU_SH4) && !defined(CONFIG_SH_FPU) || \
|
||||
defined(CONFIG_SH_FPU_EMU)
|
||||
/*
|
||||
* For SH-4 lacking an FPU, treat floating point instructions as
|
||||
* reserved. They'll be handled in the math-emu case, or faulted on
|
||||
* otherwise.
|
||||
*/
|
||||
/* entry 64 corresponds to EXPEVT=0x800 */
|
||||
exception_handling_table[64] = (void *)do_reserved_inst;
|
||||
exception_handling_table[65] = (void *)do_illegal_slot_inst;
|
||||
#endif
|
||||
|
||||
/* Setup VBR for boot cpu */
|
||||
|
||||
1
arch/sh/math-emu/Makefile
Normal file
1
arch/sh/math-emu/Makefile
Normal file
@@ -0,0 +1 @@
|
||||
obj-y := math.o
|
||||
624
arch/sh/math-emu/math.c
Normal file
624
arch/sh/math-emu/math.c
Normal file
File diff suppressed because it is too large
Load Diff
72
arch/sh/math-emu/sfp-util.h
Normal file
72
arch/sh/math-emu/sfp-util.h
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* These are copied from glibc/stdlib/longlong.h
|
||||
*/
|
||||
|
||||
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
|
||||
do { \
|
||||
UWtype __x; \
|
||||
__x = (al) + (bl); \
|
||||
(sh) = (ah) + (bh) + (__x < (al)); \
|
||||
(sl) = __x; \
|
||||
} while (0)
|
||||
|
||||
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
|
||||
do { \
|
||||
UWtype __x; \
|
||||
__x = (al) - (bl); \
|
||||
(sh) = (ah) - (bh) - (__x > (al)); \
|
||||
(sl) = __x; \
|
||||
} while (0)
|
||||
|
||||
#define umul_ppmm(w1, w0, u, v) \
|
||||
__asm__ ("dmulu.l %2,%3\n\tsts macl,%1\n\tsts mach,%0" \
|
||||
: "=r" ((u32)(w1)), "=r" ((u32)(w0)) \
|
||||
: "r" ((u32)(u)), "r" ((u32)(v)) \
|
||||
: "macl", "mach")
|
||||
|
||||
#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
|
||||
#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
|
||||
#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))
|
||||
|
||||
#define udiv_qrnnd(q, r, n1, n0, d) \
|
||||
do { \
|
||||
UWtype __d1, __d0, __q1, __q0; \
|
||||
UWtype __r1, __r0, __m; \
|
||||
__d1 = __ll_highpart (d); \
|
||||
__d0 = __ll_lowpart (d); \
|
||||
\
|
||||
__r1 = (n1) % __d1; \
|
||||
__q1 = (n1) / __d1; \
|
||||
__m = (UWtype) __q1 * __d0; \
|
||||
__r1 = __r1 * __ll_B | __ll_highpart (n0); \
|
||||
if (__r1 < __m) \
|
||||
{ \
|
||||
__q1--, __r1 += (d); \
|
||||
if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
|
||||
if (__r1 < __m) \
|
||||
__q1--, __r1 += (d); \
|
||||
} \
|
||||
__r1 -= __m; \
|
||||
\
|
||||
__r0 = __r1 % __d1; \
|
||||
__q0 = __r1 / __d1; \
|
||||
__m = (UWtype) __q0 * __d0; \
|
||||
__r0 = __r0 * __ll_B | __ll_lowpart (n0); \
|
||||
if (__r0 < __m) \
|
||||
{ \
|
||||
__q0--, __r0 += (d); \
|
||||
if (__r0 >= (d)) \
|
||||
if (__r0 < __m) \
|
||||
__q0--, __r0 += (d); \
|
||||
} \
|
||||
__r0 -= __m; \
|
||||
\
|
||||
(q) = (UWtype) __q1 * __ll_B | __q0; \
|
||||
(r) = __r0; \
|
||||
} while (0)
|
||||
|
||||
#define abort() return 0
|
||||
|
||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||
|
||||
|
||||
86
include/asm-sh/sfp-machine.h
Normal file
86
include/asm-sh/sfp-machine.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/* Machine-dependent software floating-point definitions.
|
||||
SuperH kernel version.
|
||||
Copyright (C) 1997,1998,1999 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Richard Henderson (rth@cygnus.com),
|
||||
Jakub Jelinek (jj@ultra.linux.cz),
|
||||
David S. Miller (davem@redhat.com) and
|
||||
Peter Maydell (pmaydell@chiark.greenend.org.uk).
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public License as
|
||||
published by the Free Software Foundation; either version 2 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
#ifndef _SFP_MACHINE_H
|
||||
#define _SFP_MACHINE_H
|
||||
|
||||
#include <linux/config.h>
|
||||
|
||||
#define _FP_W_TYPE_SIZE 32
|
||||
#define _FP_W_TYPE unsigned long
|
||||
#define _FP_WS_TYPE signed long
|
||||
#define _FP_I_TYPE long
|
||||
|
||||
#define _FP_MUL_MEAT_S(R,X,Y) \
|
||||
_FP_MUL_MEAT_1_wide(_FP_WFRACBITS_S,R,X,Y,umul_ppmm)
|
||||
#define _FP_MUL_MEAT_D(R,X,Y) \
|
||||
_FP_MUL_MEAT_2_wide(_FP_WFRACBITS_D,R,X,Y,umul_ppmm)
|
||||
#define _FP_MUL_MEAT_Q(R,X,Y) \
|
||||
_FP_MUL_MEAT_4_wide(_FP_WFRACBITS_Q,R,X,Y,umul_ppmm)
|
||||
|
||||
#define _FP_DIV_MEAT_S(R,X,Y) _FP_DIV_MEAT_1_udiv(S,R,X,Y)
|
||||
#define _FP_DIV_MEAT_D(R,X,Y) _FP_DIV_MEAT_2_udiv(D,R,X,Y)
|
||||
#define _FP_DIV_MEAT_Q(R,X,Y) _FP_DIV_MEAT_4_udiv(Q,R,X,Y)
|
||||
|
||||
#define _FP_NANFRAC_S ((_FP_QNANBIT_S << 1) - 1)
|
||||
#define _FP_NANFRAC_D ((_FP_QNANBIT_D << 1) - 1), -1
|
||||
#define _FP_NANFRAC_Q ((_FP_QNANBIT_Q << 1) - 1), -1, -1, -1
|
||||
#define _FP_NANSIGN_S 0
|
||||
#define _FP_NANSIGN_D 0
|
||||
#define _FP_NANSIGN_Q 0
|
||||
|
||||
#define _FP_KEEPNANFRACP 1
|
||||
|
||||
/*
|
||||
* If one NaN is signaling and the other is not,
|
||||
* we choose that one, otherwise we choose X.
|
||||
*/
|
||||
#define _FP_CHOOSENAN(fs, wc, R, X, Y, OP) \
|
||||
do { \
|
||||
if ((_FP_FRAC_HIGH_RAW_##fs(X) & _FP_QNANBIT_##fs) \
|
||||
&& !(_FP_FRAC_HIGH_RAW_##fs(Y) & _FP_QNANBIT_##fs)) \
|
||||
{ \
|
||||
R##_s = Y##_s; \
|
||||
_FP_FRAC_COPY_##wc(R,Y); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
R##_s = X##_s; \
|
||||
_FP_FRAC_COPY_##wc(R,X); \
|
||||
} \
|
||||
R##_c = FP_CLS_NAN; \
|
||||
} while (0)
|
||||
|
||||
//#define FP_ROUNDMODE FPSCR_RM
|
||||
#define FP_DENORM_ZERO 1/*FPSCR_DN*/
|
||||
|
||||
/* Exception flags. */
|
||||
#define FP_EX_INVALID (1<<4)
|
||||
#define FP_EX_DIVZERO (1<<3)
|
||||
#define FP_EX_OVERFLOW (1<<2)
|
||||
#define FP_EX_UNDERFLOW (1<<1)
|
||||
#define FP_EX_INEXACT (1<<0)
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user