我想使用cpuid指令來識別Intel CPU的功能。我在Kernel.framework中找到了cpuid.h頭文件,所以我將Kernel.framework添加到了我的項目中,並在我的源文件中包含了<Kernel/i386/cpuid.h>
。那生產如何在Mac框架中調用cpuid指令?
kern/kern_types.h: No such file or directory
我不明白。但是我認爲我想使用的功能do_cpuid
是內聯定義的,所以我嘗試將其複製到我的源代碼中。
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));
}
這給了我的錯誤:
error: can't find a register in class 'BREG' while reloading 'asm'
error: 'asm' operand has impossible constraints
谷歌搜索的錯誤導致我這樣一個問題:Problem on Mac : "Can't find a register in class BREG while reloading asm"
但是解決這個問題是使用動態無pic選項(編譯設置),Xcode對編譯設置的幫助表示「不適合共享庫(它們需要與位置無關)」。我正在構建一個框架,我認爲這是一個共享庫。那我該如何做這項工作?