5 void do_fsave_interesting_stuff ( void* p
)
7 asm __volatile__("fninit");
8 asm __volatile__("fldpi");
9 asm __volatile__("fld1");
10 asm __volatile__("fldln2");
11 asm __volatile__("fsave (%0)" : : "r" (p
) : "memory" );
14 void do_fsave ( void* p
)
16 asm __volatile__("fsave (%0)" : : "r" (p
) : "memory" );
19 void do_frstor ( void* p
)
21 asm __volatile__("frstor (%0)" : : "r" (p
) : "memory" );
25 int isFPLsbs ( int i
)
28 q
= 0; if (i
== q
|| i
== q
+1) return 1;
29 q
= 10; if (i
== q
|| i
== q
+1) return 1;
30 q
= 20; if (i
== q
|| i
== q
+1) return 1;
31 q
= 30; if (i
== q
|| i
== q
+1) return 1;
32 q
= 40; if (i
== q
|| i
== q
+1) return 1;
33 q
= 50; if (i
== q
|| i
== q
+1) return 1;
34 q
= 60; if (i
== q
|| i
== q
+1) return 1;
35 q
= 70; if (i
== q
|| i
== q
+1) return 1;
39 void show_fpustate ( unsigned char* buf
, int hide64to80
)
43 for (i
= 0; i
< 14; i
++)
44 printf("%02x ", buf
[i
]);
48 for (i
= 14; i
< 28; i
++)
49 printf("%02x ", buf
[i
]);
52 for (i
= 0; i
< 80; i
++) {
55 if (hide64to80
&& isFPLsbs(i
))
58 printf("%02x ", buf
[i
+28]);
59 if (i
> 0 && ((i
% 10) == 9))
64 int main ( int argc
, char** argv
)
66 unsigned short* buf1
= malloc(54*sizeof(short));
67 unsigned short* buf2
= malloc(54*sizeof(short));
69 printf("Re-run with any arg to suppress least-significant\n"
70 " 16 bits of FP numbers\n");
72 /* Create an initial image. */
73 do_fsave_interesting_stuff(buf1
);
74 show_fpustate( (unsigned char*)buf1
, xx
);
76 /* Reload it into buf2. */
79 show_fpustate( (unsigned char*)buf2
, xx
);