seb15753

sleepbefore.c

Jul 22nd, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. void main(int argc,char *argv[])
  5. {
  6.     long long *mesure=memalign(4096,8*0xf);
  7.     if(mesure == NULL)
  8.     {
  9.         perror("alloc\n");
  10.         return;
  11.     }
  12.     asm volatile("movq %0,%%r14\n\t"::"a"(&err));
  13.     asm volatile("movq %0,%%r15"::"a"(mesure));
  14.     asm volatile("xor %rcx,%rcx\n\t");
  15.     asm volatile("jmp set0\n\t");
  16.     asm volatile(
  17.         ".align 4096\n\t"//align to L1 cache : = #set * lineSize
  18.   "set0: \n\t"
  19.     "mov $30,%rdi\n\t"
  20.         "push %rcx\n\t"
  21.         "call sleep\n\t"
  22.         "pop %rcx\n\t"
  23.     /*".rept 14\n\t"
  24.     "nop\n\t"
  25.     ".endr\n\t"*/
  26.  
  27.     "mfence\n\t" //line 0 in RAM => set 0
  28.         "rdtsc\n\t"
  29.         "mov %rax,%r11\n\t"//low[i]
  30.         "mov %rdx,%r12\n\t"//high[i]
  31.  
  32.     "jmp set35\n\t"
  33.     ".rept 34\n\t"//34 si haut, 48 sinon
  34.     "nop\n\t"
  35.     ".endr\n\t"
  36.    
  37.    
  38.     ".rept 411712\n\t"//6272\n\t"//2176,64(j-i-1)
  39.     "nop\n\t"
  40.     ".endr\n\t"
  41.  
  42.  
  43.    "set35 : \n\t"   //line 65 in RAM => set 65 % 64 = 1
  44.     "mfence\n\t" //set 1
  45.     "rdtsc\n\t"
  46.    
  47.     "shl $32,%rdx\n\t"//high[i+1]<<32
  48.         "shl $32,%r12\n\t"//high[i]<<32
  49.  
  50.         "or %r12,%r11\n\t"//start=(high[i]<<32) | low[i]
  51.         "or %rax,%rdx\n\t"//end=(high[i+1]<<32) |low[i+1]
  52.  
  53.         "sub %r11,%rdx\n\t"//end-start
  54.  
  55.         "mov %rdx,(%r15)\n\t"
  56.  
  57.         "add $8,%r15\n\t"
  58.  
  59.     /*"mov $30,%rdi\n\t"
  60.     "push %rcx\n\t"
  61.         "call sleep\n\t"
  62.     "pop %rcx\n\t"*/
  63.     ".rept 14\n\t"// some nops to replace the previous commented code (it's size is 14Bytes)
  64.         "nop\n\t"
  65.         ".endr\n\t"
  66.  
  67.     "inc %rcx\n\t"
  68.         "cmp $0x5,%rcx\n\t"
  69.     "jne set0\n\t"
  70.  
  71.     "END:\n\t"
  72.     );
  73.     int i=0;
  74.     unsigned int count = 0;
  75.     for(i=0;i<0xf;i++)
  76.     {
  77.         printf("\n%llx",mesure[i]);
  78.         if(mesure[i]>0x100)
  79.             count++;
  80.        
  81.     }
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment