Skip to content

Instantly share code, notes, and snippets.

@yalla
Created July 20, 2012 21:41
Show Gist options
  • Save yalla/3153430 to your computer and use it in GitHub Desktop.
Save yalla/3153430 to your computer and use it in GitHub Desktop.
Test variations of xgetbv
#include <stdio.h>
static unsigned long long _xgetbv(unsigned int index){
unsigned int eax, edx;
/* original code
__asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index));
*/
/* Nokia code */
__asm__ __volatile__(".byte 0x0f, 0x01, 0xd0"
: "=a"(eax), "=d"(edx) : "c"(index));
/* modified code, segfaults
__asm__ __volatile__ (".byte 0x0f\n");
__asm__ __volatile__ (".byte 0x01\n");
__asm__ __volatile__ (".byte 0xd0\n" // xgetbv instruction
: "=a"(eax), "=d"(edx) : "c"(index));
*/
return ((unsigned long long)edx << 32) | eax;
}
int main() {
printf("666 is %i\n", _xgetbv(666));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment