diff options
| author | charles forsyth <charles.forsyth@gmail.com> | 2014-05-18 14:19:01 +0100 |
|---|---|---|
| committer | charles forsyth <charles.forsyth@gmail.com> | 2014-05-18 14:19:01 +0100 |
| commit | 37e9221a5d1905cba45c96ac44dbe26d947bc4af (patch) | |
| tree | 87bf6a76dc94bc638418883e0ca21afcfa2ad78f /lib9/setfcr-MacOSX-386.c | |
| parent | 7e479951464b9bb71e87aeef19d908e9fb9be494 (diff) | |
20140518-1419
Diffstat (limited to 'lib9/setfcr-MacOSX-386.c')
| -rw-r--r-- | lib9/setfcr-MacOSX-386.c | 56 |
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"); +} |
