Created
September 18, 2015 13:27
-
-
Save pimeys/41e629a9fde9cc420842 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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