Home | History | Annotate | Download | only in x86
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 int main(int argc, char **argv)
      5 {
      6   unsigned long  sp1;
      7   unsigned long  sp2;
      8   unsigned long  sp3;
      9   unsigned short fs1;
     10   unsigned short fs2;
     11 
     12   fs1 = 0x0003;
     13 
     14   asm("movw %4, %%fs\n"
     15       "movl %%esp, %0\n"
     16       "pushw %%fs\n"
     17       "movl %%esp, %1\n"
     18       "popw %%fs\n"
     19       "movl %%esp, %2\n"
     20       "movw %%fs, %3\n"
     21       : "=r" (sp1), "=r" (sp2), "=r" (sp3), "=r" (fs2)
     22       : "r" (fs1)
     23       : "ax"
     24       );
     25 
     26   printf("sp change after push = %ld\n", sp2 - sp1);
     27   printf("sp change after pop = %ld\n", sp3 - sp2);
     28   printf("fs after push and pop = %04x\n", fs1);
     29 
     30   asm("movw %4, %%fs\n"
     31       "movl %%esp, %0\n"
     32       "pushl %%fs\n"
     33       "movl %%esp, %1\n"
     34       "popl %%fs\n"
     35       "movl %%esp, %2\n"
     36       "movw %%fs, %3\n"
     37       : "=r" (sp1), "=r" (sp2), "=r" (sp3), "=r" (fs2)
     38       : "r" (fs1)
     39       : "ax"
     40       );
     41 
     42   printf("sp change after push = %ld\n", sp2 - sp1);
     43   printf("sp change after pop = %ld\n", sp3 - sp2);
     44   printf("fs after push and pop = %04x\n", fs1);
     45 
     46   exit(0);
     47 }
     48