summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Forsyth <charles.forsyth@gmail.com>2015-07-18 11:44:11 +0100
committerCharles Forsyth <charles.forsyth@gmail.com>2015-07-18 11:44:11 +0100
commit799f9c8c85c76c3ef40091c1f469049343650f16 (patch)
treef5820f004a85dc999944a44869c3a3283b5ef3be
parentdf5abc5961ad92c71ad314c6c4c5e9cf1d742579 (diff)
reintroduce setfcr-MacOSX-386.c, with 387 instructions
-rw-r--r--lib9/setfcr-MacOSX-386.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib9/setfcr-MacOSX-386.c b/lib9/setfcr-MacOSX-386.c
new file mode 100644
index 00000000..3589dd80
--- /dev/null
+++ b/lib9/setfcr-MacOSX-386.c
@@ -0,0 +1,56 @@
+/*
+ * Linux 386 fpu support
+ * Mimic Plan9 floating point support
+ */
+
+#include "lib9.h"
+
+void
+setfcr(ulong fcr)
+{
+ __asm__( "xorb $0x3f, %%al\n\t"
+ "pushw %%ax\n\t"
+ "fwait\n\t"
+ "fldcw (%%esp)\n\t"
+ "popw %%ax\n\t"
+ : /* no output */
+ : "al" (fcr)
+ );
+}
+
+ulong
+getfcr(void)
+{
+ ulong fcr = 0;
+
+ __asm__( "pushl %%eax\n\t"
+ "fwait\n\t"
+ "fstcw (%%esp)\n\t"
+ "popl %%eax\n\t"
+ "xorb $0x3f, %%al\n\t"
+ : "=a" (fcr)
+ : "eax" (fcr)
+ );
+ return fcr;
+}
+
+ulong
+getfsr(void)
+{
+ ulong fsr = -1;
+
+ __asm__( "fwait\n\t"
+ "fstsw (%%eax)\n\t"
+ "movl (%%eax), %%eax\n\t"
+ "andl $0xffff, %%eax\n\t"
+ : "=a" (fsr)
+ : "eax" (&fsr)
+ );
+ return fsr;
+}
+
+void
+setfsr(ulong fsr)
+{
+ __asm__("fclex\n\t");
+}