xref: /inferno-os/lib9/setfcr-MacOSX-386.c (revision e45fa0eb0763b57d6fb0649c064bc3b95ccdea6c)
1 /*
2  * Linux 386 fpu support
3  * Mimic Plan9 floating point support
4  */
5 
6 #include "lib9.h"
7 
8 void
9 setfcr(ulong fcr)
10 {
11 	__asm__(	"xorb	$0x3f, %%al\n\t"
12 			"pushw	%%ax\n\t"
13 			"fwait\n\t"
14 			"fldcw	(%%esp)\n\t"
15 			"popw	%%ax\n\t"
16 			: /* no output */
17 			: "al" (fcr)
18 	);
19 }
20 
21 ulong
22 getfcr(void)
23 {
24 	ulong fcr = 0;
25 
26 	__asm__(	"pushl	%%eax\n\t"
27 			"fwait\n\t"
28 			"fstcw	(%%esp)\n\t"
29 			"popl	%%eax\n\t"
30 			"xorb	$0x3f, %%al\n\t"
31 			: "=a"  (fcr)
32 			: "eax"	(fcr)
33 	);
34 	return fcr;
35 }
36 
37 ulong
38 getfsr(void)
39 {
40 	ulong fsr = -1;
41 
42 	__asm__(	"fwait\n\t"
43 			"fstsw	(%%eax)\n\t"
44 			"movl	(%%eax), %%eax\n\t"
45 			"andl	$0xffff, %%eax\n\t"
46 			: "=a"  (fsr)
47 			: "eax" (&fsr)
48 	);
49 	return fsr;
50 }
51 
52 void
53 setfsr(ulong fsr)
54 {
55 	__asm__("fclex\n\t");
56 }
57