/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <sys/machtrap.h>
#include <sys/privregs.h>
int fpdispr = 0;
/*
* For use by procfs to save the floating point context of the thread.
* Note the if (ttolwp(lwp) == curthread) in prstop, which calls
* this function, ensures that it is safe to read the fprs here.
*/
void
{
if (fpu_exists) {
#ifdef DEBUG
if (fpdispr)
"fp_prsave with fp disabled!");
#endif
}
}
}
}
/*
* Copy the floating point context of the forked thread.
*/
void
{
int i;
/*
* copy the parents fpq
*/
/*
* save the context of the parent into the childs fpu structure
*/
} else {
for (i = 0; i < 32; i++)
for (i = 16; i < 32; i++)
}
}
/*
* Free any state associated with floating point context.
* Fp_free can be called in two cases:
* 1) from reaper -> thread_free -> lwp_freeregs -> fp_free
* fp context belongs to a thread on deathrow
* nothing to do, thread will never be resumed
* thread calling ctxfree is reaper
*
* 2) from exec -> lwp_freeregs -> fp_free
* fp context belongs to the current thread
* must disable fpu, thread calling ctxfree is curthread
*/
/*ARGSUSED1*/
void
{
int s;
s = splhigh();
splx(s);
}
}
#ifdef SF_ERRATA_30 /* call causes fp-disabled */
extern int spitfire_call_bug;
int ill_fpcalls;
#endif
void
fp_enable(void)
{
if (fpu_exists) {
#ifdef DEBUG
if (fpdispr)
"fpu disabled, but already enabled\n");
#endif
#ifdef DEBUG
if (fpdispr)
"fpu disabled, saved fprs disabled\n");
#endif
}
fp_restore(fp);
} else {
}
} else {
int i;
for (i = 0; i < 32; i++)
for (i = 16; i < 32; i++) /* NaN */
}
}
}
/*
* fp_disabled normally occurs when the first floating point in a non-threaded
* program causes an fp_disabled trap. For threaded programs, the ILP32 threads
* library calls the .setpsr fasttrap, which has been modified to also set the
* appropriate bits in fpu_en and fpu_fprs, as well as to enable the %fprs,
* as before. The LP64 threads library will write to the %fprs directly,
* so fpu_en will never get updated for LP64 threaded programs,
* although fpu_fprs will, via resume.
*/
void
{
int ftt;
#ifdef SF_ERRATA_30 /* call causes fp-disabled */
/*
* This code is here because sometimes the call instruction
* generates an fp_disabled trap when the call offset is large.
*/
if (spitfire_call_bug) {
} else {
}
ill_fpcalls++;
return;
}
}
#endif /* SF_ERRATA_30 - call causes fp-disabled */
#ifdef CHEETAH_ERRATUM_109 /* interrupts not taken during fpops */
/*
* UltraSPARC III will report spurious fp-disabled exceptions when
* the pipe is full of fpops and an interrupt is triggered. By the
* time we get here the interrupt has been taken and we just need
* to return to where we came from and try again.
*/
return;
#endif /* CHEETAH_ERRATUM_109 */
if (fpu_exists) {
#ifdef DEBUG
if (fpdispr)
"fpu disabled, but already enabled\n");
#endif
#ifdef DEBUG
if (fpdispr)
"fpu disabled, saved fprs disabled\n");
#endif
}
fp_restore(fp);
} else {
}
} else {
int i;
(void) flush_user_windows_to_stack(NULL);
for (i = 0; i < 32; i++)
for (i = 16; i < 32; i++) /* NaN */
}
}
}
}
/*
* Process the floating point queue in lwp->lwp_pcb.
*
* Each entry in the floating point queue is processed in turn.
* If processing an entry results in an exception fp_traps() is called to
* handle the exception - this usually results in the generation of a signal
* to be delivered to the user. There are 2 possible outcomes to this (note
* that hardware generated signals cannot be held!):
*
* 1. If the signal is being ignored we continue to process the rest
* of the entries in the queue.
*
* 2. If arrangements have been made for return to a user signal handler,
* sendsig() will have copied the floating point queue onto the user's
* signal stack and zero'ed the queue count in the u_pcb. Note that
* this has the side effect of terminating fp_runq's processing loop.
* We will re-run the floating point queue on return from the user
* signal handler if necessary as part of normal setcontext processing.
*/
void
{
/*
* don't preempt while manipulating the queue
*/
int fptrap;
if (fptrap) {
/*
* Instruction could not be simulated so we will
* attempt to deliver a signal.
* We may be called again upon signal exit (setcontext)
* and can continue to process the queue then.
*/
int i;
/*
* We need to normalize the floating queue so
* the excepting instruction is at the head,
* so that the queue may be copied onto the
* user signal stack by sendsig().
*/
}
}
/*
* fpu_simulator uses the fp registers directly but it
* uses the software copy of the fsr. We need to write
* that back to fpu so that fpu's state is current for
* ucontext.
*/
if (fpu_exists)
/* post signal */
/*
* Break from loop to allow signal to be sent.
* If there are other instructions in the fp queue
* from the signal handler with a non-empty queue.
*/
break;
}
fqp++;
}
/*
* fpu_simulator uses the fp registers directly, so we have
* to update the pcb copies to keep current, but it uses the
* software copy of the fsr, so we write that back to fpu
*/
if (fpu_exists) {
int i;
for (i = 0; i < 32; i++)
for (i = 16; i < 32; i++)
}
}
/*
* Get the precise trapped V9 floating point instruction.
* Fake up a queue to process. If getting the instruction results
* in an exception fp_traps() is called to handle the exception - this
* usually results in the generation of a signal to be delivered to the user.
*/
void
{
int inst_ftt;
union {
uint_t i;
} kluge;
int mstate;
if (fpu_exists)
/*
* Get the instruction to be emulated from the pc saved by the trap.
* Note that the kernel is NOT prepared to handle a kernel fp
* exception if it can't pass successfully through the fp simulator.
*
* If the trap occurred in user mode, set lwp_state to LWP_SYS for the
* purposes of clock accounting and switch to the LMS_TRAP microstate.
*/
} else {
}
/*
* Save the bad address and post the signal.
* It can only be an ftt_alignment or ftt_fault trap.
*/
} else {
/*
* to fake a deferred fp trap. We now run the fp simulator
* in fp_precise, while allowing setfpregs to call fp_runq,
* because this allows us to do the ugly machinations to
* bugid 1210159. fp_runq is still going to have the
* problem alluded to in bugid 1192883, which is only a
* problem for a restorecontext of a v8 fp queue on a
* v9 system, which seems like the .000000001% case (on v9)!
*/
int fptrap;
(void) flush_user_windows_to_stack(NULL);
/* update the hardware fp fsr state for sake of ucontext */
if (fpu_exists)
if (fptrap) {
/* back up the pc if the signal needs to be precise */
}
/* post signal */
/* decrement queue count for ieee exceptions */
}
} else {
}
/* update the software pcb copies of hardware fp registers */
if (fpu_exists) {
}
}
/*
* Reset lwp_state to LWP_USER for the purposes of clock accounting,
* and restore the previously saved microstate.
*/
}
}
/*
* Handle floating point traps generated by simulation/emulation.
*/
void
{
/*
* If we take a user's exception in kernel mode, we want to trap
* with the user's registers.
*/
switch (ftt) {
case ftt_ieee:
pfpsd->fp_trapcode);
break;
case ftt_fault:
break;
case ftt_alignment:
break;
case ftt_unimplemented:
break;
default:
/*
* We don't expect any of the other types here.
*/
}
}