CPUID.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Types.h>
  8. namespace Kernel {
  9. class CPUID {
  10. public:
  11. explicit CPUID(u32 function, u32 ecx = 0) { asm volatile("cpuid"
  12. : "=a"(m_eax), "=b"(m_ebx), "=c"(m_ecx), "=d"(m_edx)
  13. : "a"(function), "c"(ecx)); }
  14. u32 eax() const { return m_eax; }
  15. u32 ebx() const { return m_ebx; }
  16. u32 ecx() const { return m_ecx; }
  17. u32 edx() const { return m_edx; }
  18. private:
  19. u32 m_eax { 0xffffffff };
  20. u32 m_ebx { 0xffffffff };
  21. u32 m_ecx { 0xffffffff };
  22. u32 m_edx { 0xffffffff };
  23. };
  24. // FIXME: This can't hold every CPU feature as-is.
  25. enum class CPUFeature : u32 {
  26. NX = (1 << 0),
  27. PAE = (1 << 1),
  28. PGE = (1 << 2),
  29. RDRAND = (1 << 3),
  30. RDSEED = (1 << 4),
  31. SMAP = (1 << 5),
  32. SMEP = (1 << 6),
  33. SSE = (1 << 7),
  34. TSC = (1 << 8),
  35. RDTSCP = (1 << 9),
  36. CONSTANT_TSC = (1 << 10),
  37. NONSTOP_TSC = (1 << 11),
  38. UMIP = (1 << 12),
  39. SEP = (1 << 13),
  40. SYSCALL = (1 << 14),
  41. MMX = (1 << 15),
  42. SSE2 = (1 << 16),
  43. SSE3 = (1 << 17),
  44. SSSE3 = (1 << 18),
  45. SSE4_1 = (1 << 19),
  46. SSE4_2 = (1 << 20),
  47. XSAVE = (1 << 21),
  48. AVX = (1 << 22),
  49. FXSR = (1 << 23),
  50. LM = (1 << 24),
  51. HYPERVISOR = (1 << 25),
  52. };
  53. }