return X86EMUL_UNHANDLEABLE;
}
-static int read_dr(unsigned int reg, unsigned long *val,
- struct x86_emulate_ctxt *ctxt)
-{
- unsigned long res = do_get_debugreg(reg);
-
- if ( IS_ERR_VALUE(res) )
- return X86EMUL_UNHANDLEABLE;
-
- *val = res;
-
- return X86EMUL_OKAY;
-}
-
static int write_dr(unsigned int reg, unsigned long val,
struct x86_emulate_ctxt *ctxt)
{
.read_segment = read_segment,
.read_cr = read_cr,
.write_cr = write_cr,
- .read_dr = read_dr,
+ .read_dr = x86emul_read_dr,
.write_dr = write_dr,
.write_xcr = x86emul_write_xcr,
.read_msr = read_msr,
unsigned long do_get_debugreg(int reg)
{
- struct vcpu *curr = current;
+ unsigned long val;
+ int res = x86emul_read_dr(reg, &val, NULL);
- switch ( reg )
- {
- case 0 ... 3:
- case 6:
- return curr->arch.debugreg[reg];
- case 7:
- return (curr->arch.debugreg[7] |
- curr->arch.debugreg[5]);
- case 4 ... 5:
- return ((curr->arch.pv_vcpu.ctrlreg[4] & X86_CR4_DE) ?
- curr->arch.debugreg[reg + 2] : 0);
- }
-
- return -EINVAL;
+ return res == X86EMUL_OKAY ? val : -ENODEV;
}
long do_fpu_taskswitch(int set)
return X86EMUL_OKAY;
}
+
+/* Called with NULL ctxt in hypercall context. */
+int x86emul_read_dr(unsigned int reg, unsigned long *val,
+ struct x86_emulate_ctxt *ctxt)
+{
+ struct vcpu *curr = current;
+
+ /* HVM support requires a bit more plumbing before it will work. */
+ ASSERT(is_pv_vcpu(curr));
+
+ switch ( reg )
+ {
+ case 0 ... 3:
+ case 6:
+ *val = curr->arch.debugreg[reg];
+ break;
+
+ case 7:
+ *val = (curr->arch.debugreg[7] |
+ curr->arch.debugreg[5]);
+ break;
+
+ case 4 ... 5:
+ if ( !(curr->arch.pv_vcpu.ctrlreg[4] & X86_CR4_DE) )
+ {
+ *val = curr->arch.debugreg[reg + 2];
+ break;
+ }
+
+ /* Fallthrough */
+ default:
+ if ( ctxt )
+ x86_emul_hw_exception(TRAP_invalid_op, X86_EVENT_NO_EC, ctxt);
+
+ return X86EMUL_EXCEPTION;
+ }
+
+ return X86EMUL_OKAY;
+}
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * tab-width: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
int x86emul_write_xcr(unsigned int reg, uint64_t val,
struct x86_emulate_ctxt *ctxt);
+int x86emul_read_dr(unsigned int reg, unsigned long *val,
+ struct x86_emulate_ctxt *ctxt);
+
#endif
int