{
int rc;
- hvm_monitor_crX(XCR0, new_bv, current->arch.xcr0);
+ if ( index == 0 )
+ hvm_monitor_crX(XCR0, new_bv, current->arch.xcr0);
- rc = handle_xsetbv(index, new_bv);
- if ( rc )
+ rc = x86emul_write_xcr(index, new_bv, NULL);
+ if ( rc != X86EMUL_OKAY )
hvm_inject_hw_exception(TRAP_gp_fault, 0);
return rc;
if ( vmcb_get_cpl(vmcb) )
hvm_inject_hw_exception(TRAP_gp_fault, 0);
else if ( (inst_len = __get_instruction_length(v, INSTR_XSETBV)) &&
- hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == 0 )
+ hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == X86EMUL_OKAY )
__update_guest_eip(regs, inst_len);
break;
break;
case EXIT_REASON_XSETBV:
- if ( hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == 0 )
+ if ( hvm_handle_xsetbv(regs->ecx, msr_fold(regs)) == X86EMUL_OKAY )
update_guest_eip(); /* Safe: XSETBV */
break;
return X86EMUL_OKAY;
}
+/* Note: May be called with ctxt=NULL. */
int x86emul_write_xcr(unsigned int reg, uint64_t val,
struct x86_emulate_ctxt *ctxt)
{
default:
gp_fault:
- x86_emul_hw_exception(TRAP_gp_fault, 0, ctxt);
+ if ( ctxt )
+ x86_emul_hw_exception(TRAP_gp_fault, 0, ctxt);
return X86EMUL_EXCEPTION;
}