Kevin O'Connor | b9c6a96 | 2013-09-14 13:01:30 -0400 | [diff] [blame] | 1 | // X86 utility functions. |
| 2 | // |
| 3 | // Copyright (C) 2013 Kevin O'Connor <kevin@koconnor.net> |
| 4 | // |
| 5 | // This file may be distributed under the terms of the GNU LGPLv3 license. |
| 6 | |
| 7 | #include "x86.h" // __cpuid |
| 8 | |
| 9 | void |
| 10 | cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) |
| 11 | { |
| 12 | // Check for cpu id |
| 13 | u32 origflags = save_flags(); |
| 14 | restore_flags(origflags ^ F_ID); |
| 15 | u32 newflags = save_flags(); |
| 16 | restore_flags(origflags); |
| 17 | |
| 18 | if (((origflags ^ newflags) & F_ID) != F_ID) |
| 19 | // no cpuid |
| 20 | *eax = *ebx = *ecx = *edx = 0; |
| 21 | else |
| 22 | __cpuid(index, eax, ebx, ecx, edx); |
| 23 | } |