Skip to content

cpuid: Refactor, fix mock data representation

Simon McVittie requested to merge wip/smcv/cpuid into master
  • cpu-feature, virtualization: Use macros for leaves and feature bits

  • cpu-feature: Use struct { leaf, subleaf } as key for mock data

    Now that we handle leaves that require a specific sub-leaf in ECX, a single pointer-sized key is not enough: on 32-bit x86, the leaf is pointer-sized, leaving no space to encode a sub-leaf correctly. Use a pointer to a struct as the key, with custom equals and hash functions.

    Fixes: 9b3741ad "cpu-feature: Add support for CPUID subleaf functions"
    Resolves: #94 (closed)

  • cpu-feature: Re-combine _srt_x86_cpuid and _srt_x86_cpuid_count

    __cpuid_count issues the CPUID instruction with EAX and ECX set to the leaf and subleaf respectively, whereas __cpuid issues the CPUID instruction with EAX set to the leaf and ECX left set to a garbage value (in effect, older leaves treat all subleaves as equivalent). As a result, everything we can do with __cpuid, we can do equally well with __cpuid_count by setting ECX to an arbitrary value. We might as well standardize on ECX = 0 as our arbitrary value.

    The only other benefit that our previous _srt_x86_cpuid had over _srt_x86_cpuid_count was that it could do feature- and range-checking, which is part of __get_cpuid(). Newer versions of gcc implement a __get_cpuid_count(), but we can't use that in software that targets gcc 6.2 or older; instead, use the lower-level __get_cpuid_max() and __cpuid_count() directly.

  • virtualization: Assume that FEX-Emu will set Hypervisor Present bit

    Older versions didn't set this and had to be identified by uname(2), but newer versions set the Hypervisor Present bit in CPUID, the same as qemu.

  • virtualization: Define more constants for magic numbers

Edited by Simon McVittie

Merge request reports