I want to use the cpuid instruction to identify features of an Intel CPU. I found the cpuid.h header in Kernel.framework, so I added Kernel.framework to my project and included <Kernel/i386/cpuid.h>
in my source file. That produced
kern/kern_types.h: No such file or directory
which I don't understand. But the function do_cpuid
, which is what I think I want to use, is defined inline, so I tried just copying that into my source.
static inline void
do_cpuid(uint32_t selector, uint32_t *data)
{
asm("cpuid"
: "=a" (data[0]),
"=b" (data[1]),
"=c" (data[2]),
"=d" (data[3])
: "a"(selector));
}
That gave me errors:
error: can't find a register in class 'BREG' while reloading 'asm'
error: 'asm' operand has impossible constraints
Googling that error led me to this question: Problem on Mac : "Can't find a register in class BREG while reloading asm"
But the solution to that question was to use the dynamic-no-pic option (GCC_DYNAMIC_NO_PIC
build setting), and Xcode's help on build settings says "Not appropriate for shared libraries (which need to be position-independent)." I'm building a framework, which I think counts as a shared library. So how can I make this work?