17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
58cd45542Sraf * Common Development and Distribution License (the "License").
68cd45542Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
218cd45542Sraf
228cd45542Sraf /*
238cd45542Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
248cd45542Sraf * Use is subject to license terms.
258cd45542Sraf */
268cd45542Sraf
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
297c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T
307c478bd9Sstevel@tonic-gate * All Rights Reserved
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate * Establish the default settings for the floating-point state for a C language
377c478bd9Sstevel@tonic-gate * program:
387c478bd9Sstevel@tonic-gate * rounding mode -- round to nearest default by OS,
397c478bd9Sstevel@tonic-gate * exceptions enabled -- all masked
407c478bd9Sstevel@tonic-gate * sticky bits -- all clear by default by OS.
417c478bd9Sstevel@tonic-gate * precision control -- double extended
427c478bd9Sstevel@tonic-gate */
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate #pragma weak _fpstart = __fpstart
457c478bd9Sstevel@tonic-gate
46*7257d1b4Sraf #include "lint.h"
477c478bd9Sstevel@tonic-gate #include <sys/types.h>
487c478bd9Sstevel@tonic-gate #include <sys/sysi86.h> /* for SI86FPHW/SI86FPSTART definitions */
497c478bd9Sstevel@tonic-gate #include <sys/fp.h> /* for FPU_CW_INIT and SSE_MXCSR_INIT */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate int __flt_rounds; /* ANSI rounding mode */
527c478bd9Sstevel@tonic-gate
537c478bd9Sstevel@tonic-gate void
__fpstart()547c478bd9Sstevel@tonic-gate __fpstart()
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate int _fp_hw; /* default: bss: 0 == no hardware */
577c478bd9Sstevel@tonic-gate
587c478bd9Sstevel@tonic-gate /*
597c478bd9Sstevel@tonic-gate * query OS for HW status and ensure the x87 and (optional)
607c478bd9Sstevel@tonic-gate * SSE control words are (will be) set correctly.
617c478bd9Sstevel@tonic-gate * This "cannot fail".
627c478bd9Sstevel@tonic-gate */
638cd45542Sraf (void) sysi86(SI86FPSTART,
647c478bd9Sstevel@tonic-gate &_fp_hw, FPU_CW_INIT, SSE_MXCSR_INIT);
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate /*
677c478bd9Sstevel@tonic-gate * At this point the x87 fp environment that has been (or more
687c478bd9Sstevel@tonic-gate * hopefully, will be) established by the kernel is:
697c478bd9Sstevel@tonic-gate *
707c478bd9Sstevel@tonic-gate * affine infinity 0x1000
717c478bd9Sstevel@tonic-gate * round to nearest 0x0000
727c478bd9Sstevel@tonic-gate * 64-bit doubles 0x0300
737c478bd9Sstevel@tonic-gate * precision, underflow, overflow, zero-divide, denorm, invalid masked
747c478bd9Sstevel@tonic-gate * 0x003f
757c478bd9Sstevel@tonic-gate *
767c478bd9Sstevel@tonic-gate * which conforms to the 4th edition i386 ABI definition.
777c478bd9Sstevel@tonic-gate *
787c478bd9Sstevel@tonic-gate * Additionally, if we have SSE hardware, we've also masked all
797c478bd9Sstevel@tonic-gate * the same traps, and have round to nearest.
807c478bd9Sstevel@tonic-gate */
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate __flt_rounds = 1; /* ANSI way of saying round-to-nearest */
837c478bd9Sstevel@tonic-gate }
84