Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/vmm/x86.c
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
static __inline int | static __inline int | ||||
log2(u_int x) | log2(u_int x) | ||||
{ | { | ||||
return (fls(x << (1 - powerof2(x))) - 1); | return (fls(x << (1 - powerof2(x))) - 1); | ||||
} | } | ||||
int | int | ||||
x86_emulate_cpuid(struct vm *vm, int vcpu_id, uint64_t *rax, uint64_t *rbx, | x86_emulate_cpuid(struct vcpu *vcpu, uint64_t *rax, uint64_t *rbx, | ||||
uint64_t *rcx, uint64_t *rdx) | uint64_t *rcx, uint64_t *rdx) | ||||
{ | { | ||||
struct vm *vm = vcpu_vm(vcpu); | |||||
int vcpu_id = vcpu_vcpuid(vcpu); | |||||
const struct xsave_limits *limits; | const struct xsave_limits *limits; | ||||
uint64_t cr4; | uint64_t cr4; | ||||
int error, enable_invpcid, enable_rdpid, enable_rdtscp, level, | int error, enable_invpcid, enable_rdpid, enable_rdtscp, level, | ||||
width, x2apic_id; | width, x2apic_id; | ||||
unsigned int func, regs[4], logical_cpus, param; | unsigned int func, regs[4], logical_cpus, param; | ||||
enum x2apic_state x2apic_state; | enum x2apic_state x2apic_state; | ||||
uint16_t cores, maxcpus, sockets, threads; | uint16_t cores, maxcpus, sockets, threads; | ||||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Lines | case CPUID_0000_0001: | ||||
/* | /* | ||||
* If CPUID2_XSAVE is being advertised and the | * If CPUID2_XSAVE is being advertised and the | ||||
* guest has set CR4_XSAVE, set | * guest has set CR4_XSAVE, set | ||||
* CPUID2_OSXSAVE. | * CPUID2_OSXSAVE. | ||||
*/ | */ | ||||
regs[2] &= ~CPUID2_OSXSAVE; | regs[2] &= ~CPUID2_OSXSAVE; | ||||
if (regs[2] & CPUID2_XSAVE) { | if (regs[2] & CPUID2_XSAVE) { | ||||
error = vm_get_register(vm_vcpu(vm, vcpu_id), | error = vm_get_register(vcpu, | ||||
VM_REG_GUEST_CR4, &cr4); | VM_REG_GUEST_CR4, &cr4); | ||||
if (error) | if (error) | ||||
panic("x86_emulate_cpuid: error %d " | panic("x86_emulate_cpuid: error %d " | ||||
"fetching %%cr4", error); | "fetching %%cr4", error); | ||||
if (cr4 & CR4_XSAVE) | if (cr4 & CR4_XSAVE) | ||||
regs[2] |= CPUID2_OSXSAVE; | regs[2] |= CPUID2_OSXSAVE; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 271 Lines • ▼ Show 20 Lines | default_leaf: | ||||
*rbx = regs[1]; | *rbx = regs[1]; | ||||
*rcx = regs[2]; | *rcx = regs[2]; | ||||
*rdx = regs[3]; | *rdx = regs[3]; | ||||
return (1); | return (1); | ||||
} | } | ||||
bool | bool | ||||
vm_cpuid_capability(struct vm *vm, int vcpuid, enum vm_cpuid_capability cap) | vm_cpuid_capability(struct vcpu *vcpu, enum vm_cpuid_capability cap) | ||||
{ | { | ||||
bool rv; | bool rv; | ||||
KASSERT(cap > 0 && cap < VCC_LAST, ("%s: invalid vm_cpu_capability %d", | KASSERT(cap > 0 && cap < VCC_LAST, ("%s: invalid vm_cpu_capability %d", | ||||
__func__, cap)); | __func__, cap)); | ||||
/* | /* | ||||
* Simply passthrough the capabilities of the host cpu for now. | * Simply passthrough the capabilities of the host cpu for now. | ||||
▲ Show 20 Lines • Show All 102 Lines • Show Last 20 Lines |