Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void init_tsc_freq(CPUX86State *env)
- {
- size_t length;
- uint64_t tsc_freq;
- if (env->tsc_khz != 0) {
- return;
- }
- length = sizeof(uint64_t);
- if (sysctlbyname("machdep.tsc.frequency", &tsc_freq, &length, NULL, 0)) {
- /* fprintf(stderr, "sysctl machdep.tsc.frequency errored %s\n", __func__); */
- return;
- }
- env->tsc_khz = tsc_freq / 1000; /* Hz to KHz */
- }
- static void init_apic_bus_freq(CPUX86State *env)
- {
- size_t length;
- uint64_t bus_freq;
- if (env->apic_bus_freq != 0) {
- return;
- }
- length = sizeof(uint64_t);
- if (sysctlbyname("hw.busfrequency", &bus_freq, &length, NULL, 0)) {
- /* fprintf(stderr, "sysctl hw.busfrequency errored %s\n", __func__); */
- return;
- }
- env->apic_bus_freq = bus_freq;
- }
- static inline bool tsc_is_known(CPUX86State *env)
- {
- return env->tsc_khz != 0;
- }
- static inline bool apic_bus_freq_is_known(CPUX86State *env)
- {
- return env->apic_bus_freq != 0;
- }
- ////
- if (x86cpu->vmware_cpuid_freq) {
- init_tsc_freq(env);
- init_apic_bus_freq(env);
- if (!tsc_is_known(env) || !apic_bus_freq_is_known(env)) {
- error_report("vmware-cpuid-freq: feature couldn't be enabled");
- }
- }
- ////
- /*
- * A wrapper extends cpu_x86_cpuid with 0x40000000 and 0x40000010 leafs
- * Provides vmware-cpuid-freq support to hvf
- */
- static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
- uint32_t *eax, uint32_t *ebx,
- uint32_t *ecx, uint32_t *edx)
- {
- uint32_t signature[3];
- if (!tsc_is_known(env) || !apic_bus_freq_is_known(env)) {
- cpu_x86_cpuid(env, index, count, eax, ebx, ecx, edx);
- return;
- }
- switch (index) {
- case 0x40000000:
- memcpy(signature, "TCGTCGTCGTCG", 12); /* QEMU Signature */
- *eax = 0x40000010; /* Max available cpuid leaf */
- *ebx = signature[0];
- *ecx = signature[1];
- *edx = signature[2];
- break;
- case 0x40000010:
- *eax = env->tsc_khz;
- *ebx = env->apic_bus_freq / 1000; /* Hz to KHz */
- *ecx = 0;
- *edx = 0;
- break;
- default:
- cpu_x86_cpuid(env, index, count, eax, ebx, ecx, edx);
- break;
- }
- }
- hvf_cpu_x86_cpuid(env, rax, rcx, &rax, &rbx, &rcx, &rdx);
- #define MSR_CORE_THREAD_COUNT 0x35
- case MSR_CORE_THREAD_COUNT:
- val = cs->nr_threads * cs->nr_cores; /* thread count, bits 15..0 */
- val |= ((uint32_t)cs->nr_cores << 16u); /* core count, bits 31..16 */
- break;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement