Advertisement
DavidsonDFGL

FPU Context

Feb 22nd, 2016
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/wait.h>
  5.  
  6. //#define RUIN_STACK 1
  7.  
  8. int main()
  9. {
  10.     //__asm__("xchg %bx, %bx");
  11.     float a = 5.7, b = 1.2;
  12.  
  13.     union ud
  14.     {
  15.         float c;
  16.         int cc;
  17.     };
  18.  
  19.     union ud u;
  20.    
  21.     __asm__ __volatile__(
  22.         "flds %1;"
  23.         "flds %0;"
  24.         "fdivrp %%st,%%st(1);"
  25.         :
  26.         : "m" (b), "m" (a)
  27.     );
  28.  
  29. #ifdef RUIN_STACK
  30.     pid_t pid;
  31.     if ( (pid = fork()) == 0 )
  32.     {
  33.         float t;
  34.  
  35.         __asm__ __volatile__(
  36.             "fstps %0;"
  37.             "fldz;"
  38.             "fldz;"
  39.             "fldz;"
  40.             "fldz;"
  41.             "fldz;"
  42.             "fldz;"
  43.             "fldz;"
  44.             "fldz;"
  45.             : "=m" (t)
  46.             :
  47.         );
  48.         exit(0);
  49.     }
  50.     wait(NULL);
  51. #endif
  52.  
  53.     __asm__ __volatile__(
  54.         "fstps %0;"
  55.         : "=m" (u.c)
  56.         :
  57.         );
  58.  
  59.     fprintf(stderr,"rrrFather: %x\n",u.cc);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement