vitamike
vitamike

Reputation: 123

CPUID and MSR reads Linux-x86

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

Upvotes: 0

Views: 1583

Answers (1)

Rami Rosen
Rami Rosen

Reputation: 350

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

Upvotes: 0

Related Questions