0

Im working on a Linux kernel module in which i need to read the CPUID of a processor to see if a feature is present. The chipset documentation states:

"Accesses to this MSR are supported when either CPUID (EAX=14H, ECX=0):ECX[bit 0] or CPUID.(EAX=14H, ECX=0):ECX[bit2]"

However I am using the following code to read CPUID:

int func()
{
  int a, b;

  for (a = 0; a < 5; a++)
  {
    __asm__("cpuid"
            :"=a"(b)                 // EAX into b (output)
            :"0"(a)                  // a into EAX (input)
            :"%ebx","%ecx","%edx");  // clobbered registers

    printk("The code %i gives %llx\n", a, b);
  }

  return 0;
}

Adapted from: https://en.wikipedia.org/wiki/CPUID#EAX.3D1:_Processor_Info_and_Feature_Bits

but i have no idea how it works or which values I am reading. Can someone explain to me how this code works and also how i can go about reading the above CPUID registers as well as EAX=80000008h.

Thanks

vitamike
  • 123
  • 1
  • 15
  • Use a CPUID wrapper function if you don't understand inline asm yourself. There are several to choose from. – Peter Cordes Nov 18 '16 at 11:29
  • @ Peter Cordes. Thanks for that... – vitamike Nov 18 '16 at 11:39
  • 1
    Possible duplicate of [Intel Processor : "If CPUID.06H:EAX.\[7\] = 1" Meaning?](https://stackoverflow.com/questions/45883852/intel-processor-if-cpuid-06heax-7-1-meaning), which is also a linux-kernel question, and the answer shows Linux's CPUID wrapper functions – Peter Cordes Aug 28 '17 at 22:01

1 Answers1

0

Unless you already found it, one such popular utility is called simply "cpuid" and is available as an rpm package in Fedora and as an Ubuntu package and also in other distros. This utility uses the "cpuid" instruction.

See: http://www.etallen.com/cpuid.html

Pang
  • 9,564
  • 146
  • 81
  • 122
Rami Rosen
  • 330
  • 2
  • 2