Skip to content

Instantly share code, notes, and snippets.

@pimeys
Created September 18, 2015 13:27
Show Gist options
  • Save pimeys/41e629a9fde9cc420842 to your computer and use it in GitHub Desktop.
Save pimeys/41e629a9fde9cc420842 to your computer and use it in GitHub Desktop.
#include <cstdlib>
#include <iostream>
struct register_
{
unsigned short low;
unsigned short high;
};
int main()
{
#define cpuid(code, a, b, c) \
asm volatile("cpuid" : "=a"(a), "=b"(b), "=c"(c) : "a"(code) : "edx")
register_ eax, ebx, ecx;
cpuid(0x5, eax, ebx, ecx);
std::cout << "eax[" << eax.high << ", " << eax.low << "]" << std::endl;
std::cout << "ebx[" << ebx.high << ", " << ebx.low << "]" << std::endl;
std::cout << "ecx[" << ecx.high << ", " << ecx.low << "]" << std::endl;
unsigned int monitor_size = eax.low;
std::cout << "Use size: " << monitor_size << std::endl;
void* test = malloc(monitor_size);
std::cout << "monitor:" << std::endl;
__builtin_ia32_monitor(test, 0, 0);
std::cout << "wait:" << std::endl;
__builtin_ia32_mwait(0, 0);
std::cout << "Exit" << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment