Skip to content

Commit

Permalink
target-i386: Introduce hw_{local,global}_breakpoint_enabled()
Browse files Browse the repository at this point in the history
hw_breakpoint_enabled() returned a bit field indicating whether a local
breakpoint and/or global breakpoint was enabled. Avoid this number magic
by using explicit boolean helper functions hw_local_breakpoint_enabled()
and hw_global_breakpoint_enabled(), to aid readability.

Reuse them for the hw_breakpoint_enabled() implementation and change
its return type to bool.

While at it, fix Coding Style issues (missing braces).

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
  • Loading branch information
liguang authored and afaerber committed Jan 15, 2013
1 parent 428065c commit 5902564
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
15 changes: 13 additions & 2 deletions target-i386/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -1014,9 +1014,20 @@ int cpu_x86_handle_mmu_fault(CPUX86State *env, target_ulong addr,
#define cpu_handle_mmu_fault cpu_x86_handle_mmu_fault
void cpu_x86_set_a20(CPUX86State *env, int a20_state);

static inline int hw_breakpoint_enabled(unsigned long dr7, int index)
static inline bool hw_local_breakpoint_enabled(unsigned long dr7, int index)
{
return (dr7 >> (index * 2)) & 3;
return (dr7 >> (index * 2)) & 1;
}

static inline bool hw_global_breakpoint_enabled(unsigned long dr7, int index)
{
return (dr7 >> (index * 2)) & 2;

}
static inline bool hw_breakpoint_enabled(unsigned long dr7, int index)
{
return hw_global_breakpoint_enabled(dr7, index) ||
hw_local_breakpoint_enabled(dr7, index);
}

static inline int hw_breakpoint_type(unsigned long dr7, int index)
Expand Down
9 changes: 6 additions & 3 deletions target-i386/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,10 @@ void hw_breakpoint_insert(CPUX86State *env, int index)

switch (hw_breakpoint_type(env->dr[7], index)) {
case DR7_TYPE_BP_INST:
if (hw_breakpoint_enabled(env->dr[7], index))
if (hw_breakpoint_enabled(env->dr[7], index)) {
err = cpu_breakpoint_insert(env, env->dr[index], BP_CPU,
&env->cpu_breakpoint[index]);
}
break;
case DR7_TYPE_DATA_WR:
type = BP_CPU | BP_MEM_WRITE;
Expand All @@ -998,8 +999,9 @@ void hw_breakpoint_remove(CPUX86State *env, int index)
return;
switch (hw_breakpoint_type(env->dr[7], index)) {
case DR7_TYPE_BP_INST:
if (hw_breakpoint_enabled(env->dr[7], index))
if (hw_breakpoint_enabled(env->dr[7], index)) {
cpu_breakpoint_remove_by_ref(env, env->cpu_breakpoint[index]);
}
break;
case DR7_TYPE_DATA_WR:
case DR7_TYPE_DATA_RW:
Expand All @@ -1024,8 +1026,9 @@ int check_hw_breakpoints(CPUX86State *env, int force_dr6_update)
((type & 1) && env->cpu_watchpoint[reg] &&
(env->cpu_watchpoint[reg]->flags & BP_WATCHPOINT_HIT))) {
dr6 |= 1 << reg;
if (hw_breakpoint_enabled(env->dr[7], reg))
if (hw_breakpoint_enabled(env->dr[7], reg)) {
hit_enabled = 1;
}
}
}
if (hit_enabled || force_dr6_update)
Expand Down
3 changes: 2 additions & 1 deletion target-i386/seg_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ static void switch_tss(CPUX86State *env, int tss_selector,
/* reset local breakpoints */
if (env->dr[7] & DR7_LOCAL_BP_MASK) {
for (i = 0; i < DR7_MAX_BP; i++) {
if (hw_breakpoint_enabled(env->dr[7], i) == 0x1) {
if (hw_local_breakpoint_enabled(env->dr[7], i) &&
!hw_global_breakpoint_enabled(env->dr[7], i)) {
hw_breakpoint_remove(env, i);
}
}
Expand Down

0 comments on commit 5902564

Please sign in to comment.