1 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 void do_fsave ( void* p ) 6 { 7 asm __volatile__("fninit"); 8 asm __volatile__("fldpi"); 9 asm __volatile__("fld1"); 10 asm __volatile__("fldln2"); 11 asm __volatile__("fsave (%0)" : : "r" (p) : "memory" ); 12 } 13 14 int isFPLsbs ( int i ) 15 { 16 int q; 17 q = 0; if (i == q || i == q+1) return 1; 18 q = 10; if (i == q || i == q+1) return 1; 19 q = 20; if (i == q || i == q+1) return 1; 20 q = 30; if (i == q || i == q+1) return 1; 21 q = 40; if (i == q || i == q+1) return 1; 22 q = 50; if (i == q || i == q+1) return 1; 23 q = 60; if (i == q || i == q+1) return 1; 24 q = 70; if (i == q || i == q+1) return 1; 25 return 0; 26 } 27 28 void show_fpustate ( unsigned char* buf, int hide64to80 ) 29 { 30 int i; 31 printf(" 0 "); 32 for (i = 0; i < 14; i++) 33 printf("%02x ", buf[i]); 34 printf("\n"); 35 36 printf(" 14 "); 37 for (i = 14; i < 28; i++) 38 printf("%02x ", buf[i]); 39 printf("\n"); 40 41 for (i = 0; i < 80; i++) { 42 if ((i % 10) == 0) 43 printf("%3d ", i+28); 44 if (hide64to80 && isFPLsbs(i)) 45 printf("xx "); 46 else 47 printf("%02x ", buf[i+28]); 48 if (i > 0 && ((i % 10) == 9)) 49 printf("\n"); 50 } 51 } 52 53 int main ( int argc, char** argv ) 54 { 55 int i; 56 unsigned char* buf = malloc(108); 57 int xx = argc > 1; 58 printf("Re-run with any arg to suppress least-significant\n" 59 " 16 bits of FP numbers\n"); 60 for (i = 0; i < 108; i++) 61 buf[i] = 0xAA; 62 63 /* dump FPU state in buf, and show it. */ 64 do_fsave(buf); 65 show_fpustate( buf, xx ); 66 67 return 0; 68 } 69