]> xenbits.xensource.com Git - osstest/rumprun.git/commitdiff
Remove broken abstraction in x86_cpuid()
authorMartin Lucina <martin@lucina.net>
Thu, 1 Oct 2015 15:32:05 +0000 (17:32 +0200)
committerMartin Lucina <martin@lucina.net>
Thu, 1 Oct 2015 15:32:05 +0000 (17:32 +0200)
CPUID is a mess, remove the broken abstraction in x86_cpuid() which
tries to detect the maximum supported level, as it gets in the way of
using other CPUID leaves (hypervisor detection).

platform/hw/arch/x86/clock.c
platform/hw/arch/x86/x86_subr.c

index 6af0f137d2bfe2b1cf54b12b5136936aefa93cd2..838dc7137fe811ac16b35f86f2cc19087ea7f513 100644 (file)
@@ -191,14 +191,23 @@ x86_initclocks(void)
 {
        uint64_t tsc_freq;
        uint32_t eax, ebx, ecx, edx;
+       uint32_t have_tsc = 0, invariant_tsc = 0;
 
        /* Verify that TSC is supported. */
-       x86_cpuid(0x1, &eax, &ebx, &ecx, &edx);
-       if (!(edx & (1 << 4)))
+       x86_cpuid(0x0, &eax, &ebx, &ecx, &edx);
+       if (eax >= 0x1) {
+               x86_cpuid(0x1, &eax, &ebx, &ecx, &edx);
+               have_tsc = edx & (1 << 4);
+       }
+       if (!have_tsc)
                bmk_platform_halt("Processor does not support RDTSC");
        /* And that it is invariant. TODO: Potentially halt here if not? */
-       x86_cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
-       if (!(edx & (1 << 8)))
+       x86_cpuid(0x80000000, &eax, &ebx, &ecx, &edx);
+       if (eax >= 0x80000007) {
+               x86_cpuid(0x80000007, &eax, &ebx, &ecx, &edx);
+               invariant_tsc = edx & (1 << 8);
+       }
+       if (!invariant_tsc)
                bmk_printf("WARNING: Processor claims to not support "
                    "invariant TSC.\n");
 
index 6cb75a2b141ef08a6b985e66cd37b077d8a59a87..7a56d367522a4f787f9d04a9d7ccb37dcc14e23f 100644 (file)
@@ -84,27 +84,6 @@ x86_cpuid(uint32_t level, uint32_t *eax_out, uint32_t *ebx_out,
 {
        uint32_t eax_, ebx_, ecx_, edx_;
 
-       /*
-        * Verify if the requested CPUID level is supported. If not, just
-        * zero everything and return, hoping the caller knows what to do.
-        * This is better than the documented operation for invalid values of
-        * level, which is to behave as if CPUID had been called with the
-        * maximum supported level.
-        */
-       eax_ = (level < 0x80000000) ? 0 : 0x80000000;
-       __asm__(
-               "cpuid"
-               : "=a" (eax_), "=b" (ebx_), "=c" (ecx_), "=d" (edx_)
-               : "0" (eax_)
-       );
-       if (eax_ < level) {
-               *eax_out = *ebx_out = *ecx_out = *edx_out = 0;
-               return;
-       }
-
-       /*
-        * Call requested CPUID level.
-        */
        __asm__(
                "cpuid"
                : "=a" (eax_), "=b" (ebx_), "=c" (ecx_), "=d" (edx_)