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
227c478bd9Sstevel@tonic-gate /*
238cd45542Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
248cd45542Sraf * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate */
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
288cd45542Sraf * Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
298cd45542Sraf * Copyright (c) 1988 AT&T
308cd45542Sraf * All Rights Reserved
317c478bd9Sstevel@tonic-gate */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate * Establish the default settings for the floating-point state for a C language
357c478bd9Sstevel@tonic-gate * program:
367c478bd9Sstevel@tonic-gate * rounding mode -- round to nearest default by OS,
377c478bd9Sstevel@tonic-gate * exceptions enabled -- all masked
387c478bd9Sstevel@tonic-gate * sticky bits -- all clear by default by OS.
397c478bd9Sstevel@tonic-gate * precision control -- double extended
407c478bd9Sstevel@tonic-gate */
417c478bd9Sstevel@tonic-gate
427c478bd9Sstevel@tonic-gate #pragma weak _fpstart = __fpstart
437c478bd9Sstevel@tonic-gate
44*7257d1b4Sraf #include "lint.h"
457c478bd9Sstevel@tonic-gate #include <sys/types.h>
467c478bd9Sstevel@tonic-gate #include <sys/sysi86.h> /* for SI86FPHW/SI86FPSTART definitions */
477c478bd9Sstevel@tonic-gate #include <sys/fp.h> /* for FPU_CW_INIT and SSE_MXCSR_INIT */
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate int __flt_rounds; /* ANSI rounding mode */
507c478bd9Sstevel@tonic-gate
517c478bd9Sstevel@tonic-gate void
__fpstart()527c478bd9Sstevel@tonic-gate __fpstart()
537c478bd9Sstevel@tonic-gate {
547c478bd9Sstevel@tonic-gate int _fp_hw; /* default: bss: 0 == no hardware */
557c478bd9Sstevel@tonic-gate
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate * query OS for HW status and ensure the x87 and (optional)
587c478bd9Sstevel@tonic-gate * SSE control words are (will be) set correctly.
597c478bd9Sstevel@tonic-gate * This "cannot fail".
607c478bd9Sstevel@tonic-gate */
618cd45542Sraf (void) sysi86(SI86FPSTART,
627c478bd9Sstevel@tonic-gate &_fp_hw, FPU_CW_INIT, SSE_MXCSR_INIT);
637c478bd9Sstevel@tonic-gate
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate * At this point the x87 fp environment that has been (or more
667c478bd9Sstevel@tonic-gate * hopefully, will be) established by the kernel is:
677c478bd9Sstevel@tonic-gate *
687c478bd9Sstevel@tonic-gate * affine infinity 0x1000
697c478bd9Sstevel@tonic-gate * round to nearest 0x0000
707c478bd9Sstevel@tonic-gate * 64-bit doubles 0x0300
717c478bd9Sstevel@tonic-gate * precision, underflow, overflow, zero-divide, denorm, invalid masked
727c478bd9Sstevel@tonic-gate * 0x003f
737c478bd9Sstevel@tonic-gate *
747c478bd9Sstevel@tonic-gate * which conforms to the 4th edition i386 ABI definition.
757c478bd9Sstevel@tonic-gate *
767c478bd9Sstevel@tonic-gate * Additionally, if we have SSE hardware, we've also masked all
777c478bd9Sstevel@tonic-gate * the same traps, and have round to nearest.
787c478bd9Sstevel@tonic-gate */
797c478bd9Sstevel@tonic-gate
807c478bd9Sstevel@tonic-gate __flt_rounds = 1; /* ANSI way of saying round-to-nearest */
817c478bd9Sstevel@tonic-gate }
82