1//
2// sys_dosa.s
3// x86 assembly-language DOS-dependent routines.
4
5#include "qasm.h"
6
7
8	.data
9
10	.align	4
11fpenv:
12	.long	0, 0, 0, 0, 0, 0, 0, 0
13
14	.text
15
16.globl C(MaskExceptions)
17C(MaskExceptions):
18	fnstenv	fpenv
19	orl		$0x3F,fpenv
20	fldenv	fpenv
21
22	ret
23
24#if 0
25.globl C(unmaskexceptions)
26C(unmaskexceptions):
27	fnstenv	fpenv
28	andl		$0xFFFFFFE0,fpenv
29	fldenv	fpenv
30
31	ret
32#endif
33
34	.data
35
36	.align	4
37.globl	ceil_cw, single_cw, full_cw, cw, pushed_cw
38ceil_cw:	.long	0
39single_cw:	.long	0
40full_cw:	.long	0
41cw:			.long	0
42pushed_cw:	.long	0
43
44	.text
45
46.globl C(Sys_LowFPPrecision)
47C(Sys_LowFPPrecision):
48	fldcw	single_cw
49
50	ret
51
52.globl C(Sys_HighFPPrecision)
53C(Sys_HighFPPrecision):
54	fldcw	full_cw
55
56	ret
57
58.globl C(Sys_PushFPCW_SetHigh)
59C(Sys_PushFPCW_SetHigh):
60	fnstcw	pushed_cw
61	fldcw	full_cw
62
63	ret
64
65.globl C(Sys_PopFPCW)
66C(Sys_PopFPCW):
67	fldcw	pushed_cw
68
69	ret
70
71.globl C(Sys_SetFPCW)
72C(Sys_SetFPCW):
73	fnstcw	cw
74	movl	cw,%eax
75#if	id386
76	andb	$0xF0,%ah
77	orb		$0x03,%ah	// round mode, 64-bit precision
78#endif
79	movl	%eax,full_cw
80
81#if	id386
82	andb	$0xF0,%ah
83	orb		$0x0C,%ah	// chop mode, single precision
84#endif
85	movl	%eax,single_cw
86
87#if	id386
88	andb	$0xF0,%ah
89	orb		$0x08,%ah	// ceil mode, single precision
90#endif
91	movl	%eax,ceil_cw
92
93	ret
94
95