rtai-core/include/asm-i386/rtai_fpu.h

00001 /*
00002  *   ARTI -- RTAI-compatible Adeos-based Real-Time Interface. Based on
00003  *   the original RTAI layer for x86.
00004  *
00005  *   Copyright (C) 1994 Linus Torvalds
00006  *   Copyright (C) 2000 Gareth Hughes <gareth@valinux.com>,
00007  *   Copyright (C) 2000 Pierre Cloutier <pcloutier@PoseidonControls.com>
00008  *   and others.
00009  *
00010  *   RTAI/x86 rewrite over Adeos:
00011  *   Copyright (C) 2002 Philippe Gerum.
00012  *
00013  *   This program is free software; you can redistribute it and/or modify
00014  *   it under the terms of the GNU General Public License as published by
00015  *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
00016  *   USA; either version 2 of the License, or (at your option) any later
00017  *   version.
00018  *
00019  *   This program is distributed in the hope that it will be useful,
00020  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  *   GNU General Public License for more details.
00023  *
00024  *   You should have received a copy of the GNU General Public License
00025  *   along with this program; if not, write to the Free Software
00026  *   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00027  */
00028 
00029 #ifndef _RTAI_ASM_I386_FPU_H
00030 #define _RTAI_ASM_I386_FPU_H
00031 
00032 #ifndef __cplusplus
00033 #include <asm/processor.h>
00034 #endif /* !__cplusplus */
00035 
00036 typedef union i387_union FPU_ENV;
00037    
00038 #ifdef CONFIG_RTAI_FPU_SUPPORT
00039 
00040 #define load_mxcsr(val) \
00041         do { \
00042                 unsigned long __mxcsr = ((unsigned long)(val) & 0xffbf); \
00043                 __asm__ __volatile__ ("ldmxcsr %0": : "m" (__mxcsr)); \
00044         } while (0)
00045 
00046 #define save_cr0_and_clts(x) \
00047         do { \
00048                 __asm__ __volatile__ ("movl %%cr0,%0; clts": "=r" (x)); \
00049         } while (0)
00050 
00051 #define restore_cr0(x) \
00052         do { \
00053                 if (x & 8) { \
00054                        unsigned long flags; \
00055                        rtai_hw_lock(flags); \
00056                         __asm__ __volatile__ ("movl %%cr0, %0": "=r" (x)); \
00057                         __asm__ __volatile__ ("movl %0, %%cr0": :"r" (8 | x)); \
00058                        rtai_hw_unlock(flags); \
00059                 } \
00060         } while (0)
00061 
00062 #define enable_fpu() \
00063         do { \
00064                 __asm__ __volatile__ ("clts"); \
00065         } while (0)
00066 
00067 #define init_xfpu() \
00068         do { \
00069                 __asm__ __volatile__ ("clts; fninit"); \
00070                 if (cpu_has_xmm) { \
00071                         load_mxcsr(0x1f80); \
00072                 } \
00073         } while (0)
00074 
00075 #define save_fpenv(x) \
00076         do { \
00077                 if (cpu_has_fxsr) { \
00078                         __asm__ __volatile__ ("fxsave %0; fnclex": "=m" (x)); \
00079                 } else { \
00080                         __asm__ __volatile__ ("fnsave %0; fwait": "=m" (x)); \
00081                 } \
00082         } while (0)
00083 
00084 #define restore_fpenv(x) \
00085         do { \
00086                 if (cpu_has_fxsr) { \
00087                         __asm__ __volatile__ ("fxrstor %0": : "m" (x)); \
00088                 } else { \
00089                         __asm__ __volatile__ ("frstor %0": : "m" (x)); \
00090                 } \
00091         } while (0)
00092 
00093 #define restore_task_fpenv(t) \
00094         do { \
00095                clts(); \
00096                restore_fpenv((t)->thread.i387.fsave); \
00097         } while (0)
00098 
00099 #define restore_fpenv_lxrt(t) restore_task_fpenv(t)
00100 
00101 #else /* !CONFIG_RTAI_FPU_SUPPORT */
00102 
00103 #define save_cr0_and_clts(x)
00104 #define restore_cr0(x)
00105 #define enable_fpu()
00106 #define load_mxcsr(val)
00107 #define init_xfpu()
00108 #define save_fpenv(x)
00109 #define restore_fpenv(x)
00110 #define restore_task_fpenv(t)
00111 #define restore_fpenv_lxrt(t)
00112 
00113 #endif /* CONFIG_RTAI_FPU_SUPPORT */
00114 
00115 #endif /* !_RTAI_ASM_I386_FPU_H */

Generated on Sat Jul 24 19:36:02 2004 for RTAI API by doxygen 1.3.4