Last active
October 10, 2015 22:57
-
-
Save shermaza/853140ccc3baee2e082e to your computer and use it in GitHub Desktop.
Finding the 30th bit of the *ecx register
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 "processor.h" | |
| void native_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx, unsigned int *edx) { | |
| /* ecx is often an input as well as an output. */ | |
| asm volatile("cpuid" | |
| : "=a" (*eax), | |
| "=b" (*ebx), | |
| "=c" (*ecx), | |
| "=d" (*edx) | |
| : "0" (*eax), "2" (*ecx)); | |
| } | |
| int get_bit(unsigned int k, unsigned int n) | |
| { | |
| int mask = 1 << k; | |
| int masked_n = n & mask; | |
| int the_bit = masked_n >> k; | |
| return the_bit; | |
| } | |
| RDRAND_AVAILABLE = 0; | |
| /* Check for RDRAND support using CPUID */ | |
| unsigned eax, ebx, ecx, edx; | |
| eax = 1; /* processor info and feature bits? Took this from elesewhere... */ | |
| native_cpuid( &eax, &ebx, &ecx, &edx ); | |
| RDRAND_AVAILABLE = get_bit( 30, ecx ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment