cpuid_count(leaf, subleaf, eax, ebx, ecx, edx);
}
-void pv_cpuid(struct cpu_user_regs *regs)
+void pv_cpuid(uint32_t leaf, uint32_t subleaf,
+ uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
{
- uint32_t leaf, subleaf, a, b, c, d;
+ uint32_t a, b, c, d;
+ const struct cpu_user_regs *regs = guest_cpu_user_regs();
struct vcpu *curr = current;
struct domain *currd = curr->domain;
- leaf = a = regs->eax;
- b = regs->ebx;
- subleaf = c = regs->ecx;
- d = regs->edx;
-
if ( cpuid_hypervisor_leaves(leaf, subleaf, &a, &b, &c, &d) )
goto out;
_domain_cpuid(currd, limit, 0, &limit, &dummy, &dummy, &dummy);
if ( leaf > limit )
- {
- regs->eax = 0;
- regs->ebx = 0;
- regs->ecx = 0;
- regs->edx = 0;
- return;
- }
+ goto unsupported;
}
_domain_cpuid(currd, leaf, subleaf, &a, &b, &c, &d);
case 0x8000001e: /* Extended topology reporting */
unsupported:
a = b = c = d = 0;
- break;
+ goto out;
}
- out:
/* VPMU may decide to modify some of the leaves */
vpmu_do_cpuid(leaf, &a, &b, &c, &d);
- regs->eax = a;
- regs->ebx = b;
- regs->ecx = c;
- regs->edx = d;
+ out:
+ if ( eax )
+ *eax = a;
+ if ( ebx )
+ *ebx = b;
+ if ( ecx )
+ *ecx = c;
+ if ( edx )
+ *edx = d;
}
static int emulate_invalid_rdtscp(struct cpu_user_regs *regs)
eip += sizeof(instr);
- pv_cpuid(regs);
+ pv_cpuid_regs(regs);
instruction_done(regs, eip, 0);
int pv_emul_cpuid(unsigned int *eax, unsigned int *ebx, unsigned int *ecx,
unsigned int *edx, struct x86_emulate_ctxt *ctxt)
{
- struct cpu_user_regs regs = *ctxt->regs;
-
- regs._eax = *eax;
- regs._ecx = *ecx;
-
- pv_cpuid(®s);
-
- *eax = regs._eax;
- *ebx = regs._ebx;
- *ecx = regs._ecx;
- *edx = regs._edx;
+ pv_cpuid(*eax, *ecx, eax, ebx, ecx, edx);
return X86EMUL_OKAY;
}
if ( v->arch.cpuid_faulting && !guest_kernel_mode(v, regs) )
goto fail;
- pv_cpuid(regs);
+ pv_cpuid_regs(regs);
break;
default:
static uint64_t guest_xcr0_max(const struct domain *d)
{
+ uint32_t eax, edx;
+
if ( has_hvm_container_domain(d) )
{
- uint32_t eax, ecx = 0, edx;
+ uint32_t ecx = 0;
hvm_cpuid(XSTATE_CPUID, &eax, NULL, &ecx, &edx);
-
- return ((uint64_t)edx << 32) | eax;
}
else
- {
- struct cpu_user_regs regs = { };
+ pv_cpuid(XSTATE_CPUID, 0, &eax, NULL, NULL, &edx);
- regs._eax = XSTATE_CPUID;
- regs._ecx = 0;
- pv_cpuid(®s);
-
- return (regs.rdx << 32) | regs._eax;
- }
+ return ((uint64_t)edx << 32) | eax;
}
int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
};
int get_cpu_vendor(const char vendor_id[], enum get_cpu_vendor);
-void pv_cpuid(struct cpu_user_regs *regs);
+void pv_cpuid(uint32_t leaf, uint32_t subleaf,
+ uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx);
+
+static inline void pv_cpuid_regs(struct cpu_user_regs *regs)
+{
+ pv_cpuid(regs->_eax, regs->_ecx,
+ ®s->_eax, ®s->_ebx, ®s->_ecx, ®s->_edx);
+}
#endif /* !__ASSEMBLY__ */