Advertisement
shchuko

qemu-fix-darwin

Nov 17th, 2020
983
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.73 KB | None | 0 0
  1. static void init_tsc_freq(CPUX86State *env)
  2. {
  3.     size_t length;
  4.     uint64_t tsc_freq;
  5.  
  6.     if (env->tsc_khz != 0) {
  7.         return;
  8.     }
  9.  
  10.     length = sizeof(uint64_t);
  11.     if (sysctlbyname("machdep.tsc.frequency", &tsc_freq, &length, NULL, 0)) {
  12.         /* fprintf(stderr, "sysctl machdep.tsc.frequency errored %s\n", __func__); */
  13.         return;
  14.     }
  15.     env->tsc_khz = tsc_freq / 1000;  /* Hz to KHz */
  16. }
  17.  
  18. static void init_apic_bus_freq(CPUX86State *env)
  19. {
  20.     size_t length;
  21.     uint64_t bus_freq;
  22.  
  23.     if (env->apic_bus_freq != 0) {
  24.         return;
  25.     }
  26.  
  27.     length = sizeof(uint64_t);
  28.     if (sysctlbyname("hw.busfrequency", &bus_freq, &length, NULL, 0)) {
  29.         /* fprintf(stderr, "sysctl hw.busfrequency errored %s\n", __func__); */
  30.         return;
  31.     }
  32.     env->apic_bus_freq = bus_freq;
  33. }
  34.  
  35. static inline bool tsc_is_known(CPUX86State *env)
  36. {
  37.     return env->tsc_khz != 0;
  38. }
  39.  
  40. static inline bool apic_bus_freq_is_known(CPUX86State *env)
  41. {
  42.     return env->apic_bus_freq != 0;
  43. }
  44.  
  45. ////
  46.     if (x86cpu->vmware_cpuid_freq) {
  47.         init_tsc_freq(env);
  48.         init_apic_bus_freq(env);
  49.  
  50.         if (!tsc_is_known(env) || !apic_bus_freq_is_known(env)) {
  51.             error_report("vmware-cpuid-freq: feature couldn't be enabled");
  52.         }
  53.     }
  54. ////
  55.  
  56.  
  57. /*
  58.  * A wrapper extends cpu_x86_cpuid with 0x40000000 and 0x40000010 leafs
  59.  * Provides vmware-cpuid-freq support to hvf
  60.  */
  61. static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
  62.                               uint32_t *eax, uint32_t *ebx,
  63.                               uint32_t *ecx, uint32_t *edx)
  64. {
  65.     uint32_t signature[3];
  66.  
  67.     if (!tsc_is_known(env) || !apic_bus_freq_is_known(env)) {
  68.         cpu_x86_cpuid(env, index, count, eax, ebx, ecx, edx);
  69.         return;
  70.     }
  71.  
  72.     switch (index) {
  73.         case 0x40000000:
  74.             memcpy(signature, "TCGTCGTCGTCG", 12); /* QEMU Signature */
  75.             *eax = 0x40000010;                     /* Max available cpuid leaf */
  76.             *ebx = signature[0];
  77.             *ecx = signature[1];
  78.             *edx = signature[2];
  79.             break;
  80.         case 0x40000010:
  81.  
  82.             *eax = env->tsc_khz;
  83.             *ebx = env->apic_bus_freq / 1000; /* Hz to KHz */
  84.             *ecx = 0;
  85.             *edx = 0;
  86.             break;
  87.         default:
  88.             cpu_x86_cpuid(env, index, count, eax, ebx, ecx, edx);
  89.             break;
  90.     }
  91. }
  92.  
  93.             hvf_cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
  94.  
  95. #define MSR_CORE_THREAD_COUNT           0x35
  96.  
  97.     case MSR_CORE_THREAD_COUNT:
  98.         val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
  99.         val |= ((uint32_t)cs->nr_cores << 16u); /* core count, bits 31..16 */
  100.         break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement