1 /* 2 * Linux 386 fpu support 3 * Mimic Plan9 floating point support 4 */ 5 6 static void 7 setfcr(ulong fcr) 8 { 9 __asm__( "xorb $0x3f, %%al\n\t" 10 "pushw %%ax\n\t" 11 "fwait\n\t" 12 "fldcw (%%esp)\n\t" 13 "popw %%ax\n\t" 14 : /* no output */ 15 : "al" (fcr) 16 ); 17 } 18 19 static ulong 20 getfcr(void) 21 { 22 ulong fcr = 0; 23 24 __asm__( "pushl %%eax\n\t" 25 "fwait\n\t" 26 "fstcw (%%esp)\n\t" 27 "popl %%eax\n\t" 28 "xorb $0x3f, %%al\n\t" 29 : "=a" (fcr) 30 : "eax" (fcr) 31 ); 32 return fcr; 33 } 34 35 static ulong 36 getfsr(void) 37 { 38 ulong fsr = -1; 39 40 __asm__( "fwait\n\t" 41 "fstsw (%%eax)\n\t" 42 "movl (%%eax), %%eax\n\t" 43 "andl $0xffff, %%eax\n\t" 44 : "=a" (fsr) 45 : "eax" (&fsr) 46 ); 47 return fsr; 48 } 49 50 static void 51 setfsr(ulong fsr) 52 { 53 __asm__("fclex\n\t"); 54 } 55 56 /* FCR */ 57 #define FPINEX (1<<5) 58 #define FPUNFL ((1<<4)|(1<<1)) 59 #define FPOVFL (1<<3) 60 #define FPZDIV (1<<2) 61 #define FPINVAL (1<<0) 62 #define FPRNR (0<<10) 63 #define FPRZ (3<<10) 64 #define FPRPINF (2<<10) 65 #define FPRNINF (1<<10) 66 #define FPRMASK (3<<10) 67 #define FPPEXT (3<<8) 68 #define FPPSGL (0<<8) 69 #define FPPDBL (2<<8) 70 #define FPPMASK (3<<8) 71 /* FSR */ 72 #define FPAINEX FPINEX 73 #define FPAOVFL FPOVFL 74 #define FPAUNFL FPUNFL 75 #define FPAZDIV FPZDIV 76 #define FPAINVAL FPINVAL 77