/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/* Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
/* Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T */
/* All Rights Reserved */
/* Copyright (c) 1987, 1988 Microsoft Corporation */
/* All Rights Reserved */
/*
* Copyright (c) 2009, Intel Corporation.
* All rights reserved.
*/
#include <sys/asm_linkage.h>
#include <sys/asm_misc.h>
#include <sys/privregs.h>
#include <sys/x86_archext.h>
#if defined(__lint)
#else
#include "assym.h"
#endif
#if defined(__lint)
fpu_initial_probe(void)
{ return (0); }
#else /* __lint */
/*
* Returns zero if x87 "chip" is present(!)
*/
#endif /* __lint */
#if defined(__lint)
/*ARGSUSED*/
void
{}
#else /* __lint */
#if defined(__amd64)
#endif
#endif /* __lint */
#if defined(__i386)
/*
*/
#if defined(__lint)
int
{ return (0); }
#else /* __lint */
jae 0f
.align 4
#endif /* __lint */
/*
* instructions, patch hot paths in the kernel to use them only
* when that feature has been detected.
*/
#if defined(__lint)
void
patch_sse(void)
{}
void
patch_sse2(void)
{}
void
patch_xsave(void)
{}
#else /* __lint */
/
/
/
/
/
/
/*
* Patch lazy fp restore instructions in the trap handler
* to use xrstor instead of frstor
*/
/
/
#endif /* __lint */
#endif /* __i386 */
#if defined(__amd64)
#if defined(__lint)
void
patch_xsave(void)
{}
#else /* __lint */
/*
* Patch lazy fp restore instructions in the trap handler
* to use xrstor instead of fxrstorq
*/
/
/
1:
jnz 1b
#endif /* __lint */
#endif /* __amd64 */
/*
* One of these routines is called from any lwp with floating
* point context as part of the prolog of a context switch.
*/
#if defined(__lint)
/*ARGSUSED*/
void
xsave_ctxt(void *arg)
{}
/*ARGSUSED*/
void
fpxsave_ctxt(void *arg)
{}
/*ARGSUSED*/
void
fpnsave_ctxt(void *arg)
{}
#else /* __lint */
#if defined(__amd64)
jne 1f
/*
* On certain AMD processors, the "exception pointers" i.e. the last
* instruction pointer, last data pointer, and last opcode
* are saved by the fxsave instruction ONLY if the exception summary
* bit is set.
*
* To ensure that we don't leak these values into the next context
* on the cpu, we could just issue an fninit here, but that's
* rather slow and so we issue an instruction sequence that
* clears them more quickly, if a little obscurely.
*/
jnc 0f /* jump if ES = 0 */
fnclex /* clear pending x87 exceptions */
/* dummy load changes all exception pointers */
/* AMD Software Optimization Guide - Section 6.2 */
jne 1f
/*
* Setup xsave flags in EDX:EAX
*/
/*
* (see notes above about "exception pointers")
* TODO: does it apply to any machine that uses xsave?
*/
jnc 0f /* jump if ES = 0 */
fnclex /* clear pending x87 exceptions */
/* dummy load changes all exception pointers */
1: ret
jne 1f
/* (fnsave also reinitializes x87 state) */
/* AMD Software Optimization Guide - Section 6.2 */
jne 1f
/* (see notes above about "exception pointers") */
jnc 0f /* jump if ES = 0 */
fnclex /* clear pending x87 exceptions */
/* dummy load changes all exception pointers */
/* AMD Software Optimization Guide - Section 6.2 */
jne 1f
/*
* (see notes above about "exception pointers")
* TODO: does it apply to any machine that uses xsave?
*/
jnc 0f /* jump if ES = 0 */
fnclex /* clear pending x87 exceptions */
/* dummy load changes all exception pointers */
1: ret
#endif /* __i386 */
.align 8
#endif /* __lint */
#if defined(__lint)
/*ARGSUSED*/
void
fpsave(struct fnsave_state *f)
{}
/*ARGSUSED*/
void
fpxsave(struct fxsave_state *f)
{}
/*ARGSUSED*/
void
{}
#else /* __lint */
#if defined(__amd64)
fninit /* clear exceptions, init x87 tags */
fninit /* clear exceptions, init x87 tags */
fninit /* clear exceptions, init x87 tags */
fninit /* clear exceptions, init x87 tags */
#endif /* __i386 */
#endif /* __lint */
#if defined(__lint)
/*ARGSUSED*/
void
fprestore(struct fnsave_state *f)
{}
/*ARGSUSED*/
void
fpxrestore(struct fxsave_state *f)
{}
/*ARGSUSED*/
void
{}
#else /* __lint */
#if defined(__amd64)
#endif /* __i386 */
#endif /* __lint */
/*
* Disable the floating point unit.
*/
#if defined(__lint)
void
fpdisable(void)
{}
#else /* __lint */
#if defined(__amd64)
#endif /* __i386 */
#endif /* __lint */
/*
* Initialize the fpu hardware.
*/
#if defined(__lint)
void
fpinit(void)
{}
#else /* __lint */
#if defined(__amd64)
je 1f
/* fxsave */
1: /* xsave */
/* xrstor (%rcx) */
je 1f
je 2f
/* fnsave */
1: /* fxsave */
2: /* xsave */
/* xrstor (%ecx) */
#endif /* __i386 */
#endif /* __lint */
/*
* Clears FPU exception state.
* Returns the FP status word.
*/
#if defined(__lint)
fperr_reset(void)
{ return (0); }
fpxerr_reset(void)
{ return (0); }
#else /* __lint */
#if defined(__amd64)
#endif /* __i386 */
#endif /* __lint */
#if defined(__lint)
fpgetcwsw(void)
{
return (0);
}
#else /* __lint */
#if defined(__amd64)
#endif /* __i386 */
#endif /* __lint */
/*
* Returns the MXCSR register.
*/
#if defined(__lint)
fpgetmxcsr(void)
{
return (0);
}
#else /* __lint */
#if defined(__amd64)
#endif /* __i386 */
#endif /* __lint */