unsigned int x86_merge_dr6(const struct cpu_policy *p, unsigned int dr6,
unsigned int new);
+/*
+ * Calculate the width of a breakpoint from its dr7 encoding.
+ *
+ * The LEN encoding in dr7 is 2 bits wide per breakpoint and encoded as a X-1
+ * (0, 1 and 3) for widths of 1, 2 and 4 respectively in the 32bit days.
+ *
+ * In 64bit, the unused value (2) was given a meaning of width 8, which is
+ * great for efficiency but less great for nicely calculating the width.
+ */
+static inline unsigned int x86_bp_width(unsigned int dr7, unsigned int bp)
+{
+ unsigned int raw = (dr7 >> (DR_CONTROL_SHIFT +
+ DR_CONTROL_SIZE * bp + 2)) & 3;
+
+ /*
+ * If the top bit is set (i.e. we've got an 4 or 8 byte wide breakpoint),
+ * flip the bottom to reverse their order, making them sorted properly.
+ * Then it's a simple shift to calculate the width.
+ */
+ if ( raw & 2 )
+ raw ^= 1;
+
+ return 1U << raw;
+}
+
#endif /* _X86_DEBUGREG_H */
unsigned int port,
unsigned int len)
{
- unsigned int width, i, match = 0;
- unsigned long start;
+ unsigned int i, match = 0;
if ( !v->arch.pv.dr7_emul || !(v->arch.pv.ctrlreg[4] & X86_CR4_DE) )
return 0;
for ( i = 0; i < 4; i++ )
{
+ unsigned long start;
+ unsigned int width;
+
if ( !(v->arch.pv.dr7_emul & (3 << (i * DR_ENABLE_SIZE))) )
continue;
- start = v->arch.dr[i];
- width = 0;
-
- switch ( (v->arch.dr7 >>
- (DR_CONTROL_SHIFT + i * DR_CONTROL_SIZE)) & 0xc )
- {
- case DR_LEN_1: width = 1; break;
- case DR_LEN_2: width = 2; break;
- case DR_LEN_4: width = 4; break;
- case DR_LEN_8: width = 8; break;
- }
-
- start &= ~(width - 1UL);
+ width = x86_bp_width(v->arch.dr7, i);
+ start = v->arch.dr[i] & ~(width - 1UL);
if ( (start < (port + len)) && ((start + width) > port) )
match |= 1u << i;