xref: /illumos-gate/usr/src/lib/crt/i386/fsr.S (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
1*5d9d9091SRichard Lowe/*
2*5d9d9091SRichard Lowe * CDDL HEADER START
3*5d9d9091SRichard Lowe *
4*5d9d9091SRichard Lowe * The contents of this file are subject to the terms of the
5*5d9d9091SRichard Lowe * Common Development and Distribution License, Version 1.0 only
6*5d9d9091SRichard Lowe * (the "License").  You may not use this file except in compliance
7*5d9d9091SRichard Lowe * with the License.
8*5d9d9091SRichard Lowe *
9*5d9d9091SRichard Lowe * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*5d9d9091SRichard Lowe * or http://www.opensolaris.org/os/licensing.
11*5d9d9091SRichard Lowe * See the License for the specific language governing permissions
12*5d9d9091SRichard Lowe * and limitations under the License.
13*5d9d9091SRichard Lowe *
14*5d9d9091SRichard Lowe * When distributing Covered Code, include this CDDL HEADER in each
15*5d9d9091SRichard Lowe * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*5d9d9091SRichard Lowe * If applicable, add the following below this CDDL HEADER, with the
17*5d9d9091SRichard Lowe * fields enclosed by brackets "[]" replaced with your own identifying
18*5d9d9091SRichard Lowe * information: Portions Copyright [yyyy] [name of copyright owner]
19*5d9d9091SRichard Lowe *
20*5d9d9091SRichard Lowe * CDDL HEADER END
21*5d9d9091SRichard Lowe */
22*5d9d9091SRichard Lowe/*
23*5d9d9091SRichard Lowe * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*5d9d9091SRichard Lowe * Use is subject to license terms.
25*5d9d9091SRichard Lowe */
26*5d9d9091SRichard Lowe
27*5d9d9091SRichard Lowe#include <sys/asm_linkage.h>
28*5d9d9091SRichard Lowe
29*5d9d9091SRichard Lowe	.file	"fsr.s"
30*5d9d9091SRichard Lowe	.ident	""
31*5d9d9091SRichard Lowe
32*5d9d9091SRichard Lowe	.section	.data
33*5d9d9091SRichard Lowe	.align 4
34*5d9d9091SRichard Lowe
35*5d9d9091SRichard Lowe/*
36*5d9d9091SRichard Lowe * The following table maps trap enable bits in __fsr_init_value
37*5d9d9091SRichard Lowe * (after shifting right one bit):
38*5d9d9091SRichard Lowe *
39*5d9d9091SRichard Lowe * bit 0 - inexact trap
40*5d9d9091SRichard Lowe * bit 1 - division trap
41*5d9d9091SRichard Lowe * bit 2 - underflow trap
42*5d9d9091SRichard Lowe * bit 3 - overflow trap
43*5d9d9091SRichard Lowe * bit 4 - invalid trap
44*5d9d9091SRichard Lowe *
45*5d9d9091SRichard Lowe * to exception masks in the floating point control word
46*5d9d9091SRichard Lowe *
47*5d9d9091SRichard Lowe * bit 0 - invalid mask
48*5d9d9091SRichard Lowe * bit 2 - zero divide mask
49*5d9d9091SRichard Lowe * bit 3 - overflow mask
50*5d9d9091SRichard Lowe * bit 4 - underflow mask
51*5d9d9091SRichard Lowe * bit 5 - inexact mask
52*5d9d9091SRichard Lowe */
53*5d9d9091SRichard Lowe	.local	trap_table
54*5d9d9091SRichard Lowe	.type	trap_table,@object
55*5d9d9091SRichard Lowetrap_table:
56*5d9d9091SRichard Lowe	.byte	0b11111111
57*5d9d9091SRichard Lowe	.byte	0b11011111
58*5d9d9091SRichard Lowe	.byte	0b11111011
59*5d9d9091SRichard Lowe	.byte	0b11011011
60*5d9d9091SRichard Lowe	.byte	0b11101111
61*5d9d9091SRichard Lowe	.byte	0b11001111
62*5d9d9091SRichard Lowe	.byte	0b11101011
63*5d9d9091SRichard Lowe	.byte	0b11001011
64*5d9d9091SRichard Lowe	.byte	0b11110111
65*5d9d9091SRichard Lowe	.byte	0b11010111
66*5d9d9091SRichard Lowe	.byte	0b11110011
67*5d9d9091SRichard Lowe	.byte	0b11010011
68*5d9d9091SRichard Lowe	.byte	0b11100111
69*5d9d9091SRichard Lowe	.byte	0b11000111
70*5d9d9091SRichard Lowe	.byte	0b11100011
71*5d9d9091SRichard Lowe	.byte	0b11000011
72*5d9d9091SRichard Lowe	.byte	0b11111110
73*5d9d9091SRichard Lowe	.byte	0b11011110
74*5d9d9091SRichard Lowe	.byte	0b11111010
75*5d9d9091SRichard Lowe	.byte	0b11011010
76*5d9d9091SRichard Lowe	.byte	0b11101110
77*5d9d9091SRichard Lowe	.byte	0b11001110
78*5d9d9091SRichard Lowe	.byte	0b11101010
79*5d9d9091SRichard Lowe	.byte	0b11001010
80*5d9d9091SRichard Lowe	.byte	0b11110110
81*5d9d9091SRichard Lowe	.byte	0b11010110
82*5d9d9091SRichard Lowe	.byte	0b11110010
83*5d9d9091SRichard Lowe	.byte	0b11010010
84*5d9d9091SRichard Lowe	.byte	0b11100110
85*5d9d9091SRichard Lowe	.byte	0b11000110
86*5d9d9091SRichard Lowe	.byte	0b11100010
87*5d9d9091SRichard Lowe	.byte	0b11000010
88*5d9d9091SRichard Lowe
89*5d9d9091SRichard Lowe	.size	trap_table,32
90*5d9d9091SRichard Lowe
91*5d9d9091SRichard LoweENTRY_NP(__fsr)
92*5d9d9091SRichard Lowe	pushl	%ebp
93*5d9d9091SRichard Lowe	movl	%esp,%ebp
94*5d9d9091SRichard Lowe	pushl	%edx
95*5d9d9091SRichard Lowe	pushl	%ecx
96*5d9d9091SRichard Lowe	pushl	%ebx
97*5d9d9091SRichard Lowe	subl	$4,%esp
98*5d9d9091SRichard Lowe
99*5d9d9091SRichard Lowe	/* Setup PIC */
100*5d9d9091SRichard Lowe	call	9f
101*5d9d9091SRichard Lowe9:	popl	%ebx
102*5d9d9091SRichard Lowe	addl	$_GLOBAL_OFFSET_TABLE_ + [. - 9b], %ebx
103*5d9d9091SRichard Lowe
104*5d9d9091SRichard Lowe	movl	8(%ebp), %ecx		/* the value set by CG is passed in */
105*5d9d9091SRichard Lowe	shrl	$1,%ecx			/* get rid of fns bit */
106*5d9d9091SRichard Lowe	cmpl	$0,%ecx			/* if remaining bits are zero */
107*5d9d9091SRichard Lowe	je	3f			/*   there's nothing to do */
108*5d9d9091SRichard Lowe
109*5d9d9091SRichard Lowe	fstcw	0(%esp)			/* store the control word */
110*5d9d9091SRichard Lowe
111*5d9d9091SRichard Lowe	movl	%ecx,%edx
112*5d9d9091SRichard Lowe	andl	$0x1f,%edx		/* get the trap enable bits */
113*5d9d9091SRichard Lowe	movl	trap_table@GOT(%ebx), %eax
114*5d9d9091SRichard Lowe	addl	%eax,%edx
115*5d9d9091SRichard Lowe	movb	(%edx),%al
116*5d9d9091SRichard Lowe	andb	%al,0(%esp)	/* unmask the corresponding exceptions */
117*5d9d9091SRichard Lowe
118*5d9d9091SRichard Lowe	testl	$0x200,%ecx		/* test denormal trap enable */
119*5d9d9091SRichard Lowe	jz	1f			/* skip if zero */
120*5d9d9091SRichard Lowe
121*5d9d9091SRichard Lowe	andb	$0xfd,0(%esp)	/* unmask denormal exception */
122*5d9d9091SRichard Lowe
123*5d9d9091SRichard Lowe1:
124*5d9d9091SRichard Lowe	movl	%ecx,%edx
125*5d9d9091SRichard Lowe	andl	$0x60,%edx		/* get the rounding direction */
126*5d9d9091SRichard Lowe	jz	1f			/* skip if zero */
127*5d9d9091SRichard Lowe
128*5d9d9091SRichard Lowe	movl	%edx,%eax		/* exchange negative<->tozero */
129*5d9d9091SRichard Lowe	andl	$0x20,%eax		/*   leaving nearest and positive */
130*5d9d9091SRichard Lowe	shll	$1,%eax			/*   as is */
131*5d9d9091SRichard Lowe	xorl	%eax,%edx
132*5d9d9091SRichard Lowe	shll	$5,%edx
133*5d9d9091SRichard Lowe	andw	$0xf3ff,0(%esp)		/* update rounding direction */
134*5d9d9091SRichard Lowe	orw	%dx,0(%esp)
135*5d9d9091SRichard Lowe
136*5d9d9091SRichard Lowe1:
137*5d9d9091SRichard Lowe	andl	$0x180,%ecx		/* get the rounding precision */
138*5d9d9091SRichard Lowe	jz	1f			/* skip if zero */
139*5d9d9091SRichard Lowe
140*5d9d9091SRichard Lowe	xorl	$0x180,%ecx		/* reverse bits */
141*5d9d9091SRichard Lowe	shll	$1,%ecx
142*5d9d9091SRichard Lowe	andw	$0xfcff,0(%esp)		/* update rounding precision */
143*5d9d9091SRichard Lowe	orw	%cx,0(%esp)
144*5d9d9091SRichard Lowe
145*5d9d9091SRichard Lowe1:
146*5d9d9091SRichard Lowe	fldcw	0(%esp)			/* load the modified control word */
147*5d9d9091SRichard Lowe
148*5d9d9091SRichard Lowe3:
149*5d9d9091SRichard Lowe	addl	$4,%esp
150*5d9d9091SRichard Lowe	popl	%ebx
151*5d9d9091SRichard Lowe	popl	%ecx
152*5d9d9091SRichard Lowe	popl	%edx
153*5d9d9091SRichard Lowe	popl	%ebp
154*5d9d9091SRichard Lowe	ret
155*5d9d9091SRichard LoweSET_SIZE(__fsr)
156