【问题标题】:How do I check if CPUID.(EAX=14H, ECX=0)?如何检查 CPUID.(EAX=14H, ECX=0)?
【发布时间】:2017-04-05 13:31:06
【问题描述】:

根据英特尔参考手册,如果CPUID.(EAX=14H, ECX=0):EBX.PTWRITE [Bit 4] = 0,该指令将引发#UD 异常

如何检查这些值?

如果我使用<cpuid.h> 中的int __get_cpuid (unsigned int __level, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx),那么参数应该是什么?

【问题讨论】:

    标签: c++ linux assembly x86 cpuid


    【解决方案1】:

    你不能使用它。您需要一个可以传入ecx 的版本,因为它必须为零。如果可用,您可以使用__cpuid_count,例如:

    unsigned eax, ebx, ecx, edx;
    if (__get_cpuid(0x00, &eax, &ebx, &ecx, &edx) == 0) {
        // cpuid not supported
    }
    if (eax < 0x14) {
        // leaf 0x14 not supported
    }
    __cpuid_count(0x14, 0x00, eax, ebx, ecx, edx);
    if ((ebx & 0x10) == 0) {
        // PTWRITE not supported
    }
    

    【讨论】:

    • 请修复它。它应该是: ((ebx & 0x10) == 0) 我花了几天时间弄清楚为什么我的代码给了我一个非法指令异常,即使它是受支持的。最后用不同的编译器编译了你的代码,它给了我一个关于运算符优先级的警告。大声笑
    • 糟糕,很抱歉。
    • 在 gcc 6.4.1 中,标题 cpuid.h 定义了一个函数 __get_cpuid_count() 和一个内联汇编宏 __cpuid_count。我不知道 2016 年发生了什么,但对于最近的 gcc,您需要调用 __get_cpuid_count()(或正确设置内联汇编语句)。
    猜你喜欢
    • 2023-03-29
    • 2018-08-25
    • 2015-01-03
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    • 2012-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多