From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51127) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO731-0005yx-Py for qemu-devel@nongnu.org; Thu, 13 Mar 2014 10:55:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WO72v-0006BY-31 for qemu-devel@nongnu.org; Thu, 13 Mar 2014 10:55:51 -0400 Received: from cantor2.suse.de ([195.135.220.15]:59814 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO72t-0006BF-V3 for qemu-devel@nongnu.org; Thu, 13 Mar 2014 10:55:44 -0400 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 13 Mar 2014 15:54:50 +0100 Message-Id: <1394722501-32326-48-git-send-email-afaerber@suse.de> In-Reply-To: <1394722501-32326-1-git-send-email-afaerber@suse.de> References: <1394722501-32326-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL for-2.0-rc0 47/58] exec: Change cpu_watchpoint_{insert, remove{, _by_ref, _all}} argument List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Max Filippov , Michael Walle , Riku Voipio , =?UTF-8?q?Andreas=20F=C3=A4rber?= Use CPUState. This lets us drop a few local env usages. Signed-off-by: Andreas F=C3=A4rber --- exec.c | 34 +++++++++++++++++----------------- gdbstub.c | 17 +++++++++-------- include/exec/cpu-all.h | 6 ------ include/qom/cpu.h | 7 +++++++ linux-user/main.c | 5 +++-- target-i386/cpu.c | 2 +- target-i386/helper.c | 11 ++++++++--- target-i386/machine.c | 3 ++- target-lm32/helper.c | 7 +++++-- target-xtensa/op_helper.c | 9 ++++++--- 10 files changed, 58 insertions(+), 43 deletions(-) diff --git a/exec.c b/exec.c index 6f8b2ca..e89653e 100644 --- a/exec.c +++ b/exec.c @@ -33,6 +33,7 @@ #include "hw/xen/xen.h" #include "qemu/timer.h" #include "qemu/config-file.h" +#include "qemu/error-report.h" #include "exec/memory.h" #include "sysemu/dma.h" #include "exec/address-spaces.h" @@ -527,30 +528,30 @@ static void breakpoint_invalidate(CPUState *cpu, ta= rget_ulong pc) #endif /* TARGET_HAS_ICE */ =20 #if defined(CONFIG_USER_ONLY) -void cpu_watchpoint_remove_all(CPUArchState *env, int mask) +void cpu_watchpoint_remove_all(CPUState *cpu, int mask) =20 { } =20 -int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_u= long len, +int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, int flags, CPUWatchpoint **watchpoint) { return -ENOSYS; } #else /* Add a watchpoint. */ -int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_u= long len, +int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, int flags, CPUWatchpoint **watchpoint) { - CPUState *cpu =3D ENV_GET_CPU(env); - target_ulong len_mask =3D ~(len - 1); + CPUArchState *env =3D cpu->env_ptr; + vaddr len_mask =3D ~(len - 1); CPUWatchpoint *wp; =20 /* sanity checks: allow power-of-2 lengths, deny unaligned watchpoin= ts */ if ((len & (len - 1)) || (addr & ~len_mask) || len =3D=3D 0 || len > TARGET_PAGE_SIZE) { - fprintf(stderr, "qemu: tried to set invalid watchpoint at " - TARGET_FMT_lx ", len=3D" TARGET_FMT_lu "\n", addr, len); + error_report("tried to set invalid watchpoint at %" + VADDR_PRIx ", len=3D%" VADDR_PRIu, addr, len); return -EINVAL; } wp =3D g_malloc(sizeof(*wp)); @@ -574,17 +575,16 @@ int cpu_watchpoint_insert(CPUArchState *env, target= _ulong addr, target_ulong len } =20 /* Remove a specific watchpoint. */ -int cpu_watchpoint_remove(CPUArchState *env, target_ulong addr, target_u= long len, +int cpu_watchpoint_remove(CPUState *cpu, vaddr addr, vaddr len, int flags) { - CPUState *cpu =3D ENV_GET_CPU(env); - target_ulong len_mask =3D ~(len - 1); + vaddr len_mask =3D ~(len - 1); CPUWatchpoint *wp; =20 QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { if (addr =3D=3D wp->vaddr && len_mask =3D=3D wp->len_mask && flags =3D=3D (wp->flags & ~BP_WATCHPOINT_HIT)) { - cpu_watchpoint_remove_by_ref(env, wp); + cpu_watchpoint_remove_by_ref(cpu, wp); return 0; } } @@ -592,9 +592,9 @@ int cpu_watchpoint_remove(CPUArchState *env, target_u= long addr, target_ulong len } =20 /* Remove a specific watchpoint by reference. */ -void cpu_watchpoint_remove_by_ref(CPUArchState *env, CPUWatchpoint *watc= hpoint) +void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoi= nt) { - CPUState *cpu =3D ENV_GET_CPU(env); + CPUArchState *env =3D cpu->env_ptr; =20 QTAILQ_REMOVE(&cpu->watchpoints, watchpoint, entry); =20 @@ -604,14 +604,14 @@ void cpu_watchpoint_remove_by_ref(CPUArchState *env= , CPUWatchpoint *watchpoint) } =20 /* Remove all matching watchpoints. */ -void cpu_watchpoint_remove_all(CPUArchState *env, int mask) +void cpu_watchpoint_remove_all(CPUState *cpu, int mask) { - CPUState *cpu =3D ENV_GET_CPU(env); CPUWatchpoint *wp, *next; =20 QTAILQ_FOREACH_SAFE(wp, &cpu->watchpoints, entry, next) { - if (wp->flags & mask) - cpu_watchpoint_remove_by_ref(env, wp); + if (wp->flags & mask) { + cpu_watchpoint_remove_by_ref(cpu, wp); + } } } #endif diff --git a/gdbstub.c b/gdbstub.c index 0176b3f..cd10781 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -657,8 +657,7 @@ static int gdb_breakpoint_insert(target_ulong addr, t= arget_ulong len, int type) case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: CPU_FOREACH(cpu) { - env =3D cpu->env_ptr; - err =3D cpu_watchpoint_insert(env, addr, len, xlat_gdb_type[= type], + err =3D cpu_watchpoint_insert(cpu, addr, len, xlat_gdb_type[= type], NULL); if (err) break; @@ -695,8 +694,7 @@ static int gdb_breakpoint_remove(target_ulong addr, t= arget_ulong len, int type) case GDB_WATCHPOINT_READ: case GDB_WATCHPOINT_ACCESS: CPU_FOREACH(cpu) { - env =3D cpu->env_ptr; - err =3D cpu_watchpoint_remove(env, addr, len, xlat_gdb_type[= type]); + err =3D cpu_watchpoint_remove(cpu, addr, len, xlat_gdb_type[= type]); if (err) break; } @@ -721,7 +719,7 @@ static void gdb_breakpoint_remove_all(void) env =3D cpu->env_ptr; cpu_breakpoint_remove_all(env, BP_GDB); #ifndef CONFIG_USER_ONLY - cpu_watchpoint_remove_all(env, BP_GDB); + cpu_watchpoint_remove_all(cpu, BP_GDB); #endif } } @@ -1593,13 +1591,16 @@ int gdbserver_start(int port) /* Disable gdb stub for child processes. */ void gdbserver_fork(CPUArchState *env) { + CPUState *cpu =3D ENV_GET_CPU(env); GDBState *s =3D gdbserver_state; - if (gdbserver_fd < 0 || s->fd < 0) - return; + + if (gdbserver_fd < 0 || s->fd < 0) { + return; + } close(s->fd); s->fd =3D -1; cpu_breakpoint_remove_all(env, BP_GDB); - cpu_watchpoint_remove_all(env, BP_GDB); + cpu_watchpoint_remove_all(cpu, BP_GDB); } #else static int gdb_chr_can_receive(void *opaque) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index 4cb4b4a..ea90aee 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -427,12 +427,6 @@ int cpu_breakpoint_insert(CPUArchState *env, target_= ulong pc, int flags, int cpu_breakpoint_remove(CPUArchState *env, target_ulong pc, int flags)= ; void cpu_breakpoint_remove_by_ref(CPUArchState *env, CPUBreakpoint *brea= kpoint); void cpu_breakpoint_remove_all(CPUArchState *env, int mask); -int cpu_watchpoint_insert(CPUArchState *env, target_ulong addr, target_u= long len, - int flags, CPUWatchpoint **watchpoint); -int cpu_watchpoint_remove(CPUArchState *env, target_ulong addr, - target_ulong len, int flags); -void cpu_watchpoint_remove_by_ref(CPUArchState *env, CPUWatchpoint *watc= hpoint); -void cpu_watchpoint_remove_all(CPUArchState *env, int mask); =20 #if !defined(CONFIG_USER_ONLY) =20 diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 3bbda08..4127438 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -595,6 +595,13 @@ void qemu_init_vcpu(CPUState *cpu); */ void cpu_single_step(CPUState *cpu, int enabled); =20 +int cpu_watchpoint_insert(CPUState *cpu, vaddr addr, vaddr len, + int flags, CPUWatchpoint **watchpoint); +int cpu_watchpoint_remove(CPUState *cpu, vaddr addr, + vaddr len, int flags); +void cpu_watchpoint_remove_by_ref(CPUState *cpu, CPUWatchpoint *watchpoi= nt); +void cpu_watchpoint_remove_all(CPUState *cpu, int mask); + #ifdef CONFIG_SOFTMMU extern const struct VMStateDescription vmstate_cpu_common; #else diff --git a/linux-user/main.c b/linux-user/main.c index dbc04b7..280e295 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -3437,13 +3437,14 @@ CPUArchState *cpu_copy(CPUArchState *env) { CPUState *cpu =3D ENV_GET_CPU(env); CPUArchState *new_env =3D cpu_init(cpu_model); + CPUState *new_cpu =3D ENV_GET_CPU(new_env); #if defined(TARGET_HAS_ICE) CPUBreakpoint *bp; CPUWatchpoint *wp; #endif =20 /* Reset non arch specific state */ - cpu_reset(ENV_GET_CPU(new_env)); + cpu_reset(new_cpu); =20 memcpy(new_env, env, sizeof(CPUArchState)); =20 @@ -3457,7 +3458,7 @@ CPUArchState *cpu_copy(CPUArchState *env) cpu_breakpoint_insert(new_env, bp->pc, bp->flags, NULL); } QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) { - cpu_watchpoint_insert(new_env, wp->vaddr, (~wp->len_mask) + 1, + cpu_watchpoint_insert(new_cpu, wp->vaddr, (~wp->len_mask) + 1, wp->flags, NULL); } #endif diff --git a/target-i386/cpu.c b/target-i386/cpu.c index da254b1..4527727 100644 --- a/target-i386/cpu.c +++ b/target-i386/cpu.c @@ -2470,7 +2470,7 @@ static void x86_cpu_reset(CPUState *s) env->dr[6] =3D DR6_FIXED_1; env->dr[7] =3D DR7_FIXED_1; cpu_breakpoint_remove_all(env, BP_CPU); - cpu_watchpoint_remove_all(env, BP_CPU); + cpu_watchpoint_remove_all(s, BP_CPU); =20 env->tsc_adjust =3D 0; env->tsc =3D 0; diff --git a/target-i386/helper.c b/target-i386/helper.c index cb29aa4..dd6d824 100644 --- a/target-i386/helper.c +++ b/target-i386/helper.c @@ -993,6 +993,7 @@ hwaddr x86_cpu_get_phys_page_debug(CPUState *cs, vadd= r addr) =20 void hw_breakpoint_insert(CPUX86State *env, int index) { + CPUState *cs =3D CPU(x86_env_get_cpu(env)); int type =3D 0, err =3D 0; =20 switch (hw_breakpoint_type(env->dr[7], index)) { @@ -1014,7 +1015,7 @@ void hw_breakpoint_insert(CPUX86State *env, int ind= ex) } =20 if (type !=3D 0) { - err =3D cpu_watchpoint_insert(env, env->dr[index], + err =3D cpu_watchpoint_insert(cs, env->dr[index], hw_breakpoint_len(env->dr[7], index)= , type, &env->cpu_watchpoint[index]); } @@ -1026,8 +1027,12 @@ void hw_breakpoint_insert(CPUX86State *env, int in= dex) =20 void hw_breakpoint_remove(CPUX86State *env, int index) { - if (!env->cpu_breakpoint[index]) + CPUState *cs; + + if (!env->cpu_breakpoint[index]) { return; + } + cs =3D CPU(x86_env_get_cpu(env)); switch (hw_breakpoint_type(env->dr[7], index)) { case DR7_TYPE_BP_INST: if (hw_breakpoint_enabled(env->dr[7], index)) { @@ -1036,7 +1041,7 @@ void hw_breakpoint_remove(CPUX86State *env, int ind= ex) break; case DR7_TYPE_DATA_WR: case DR7_TYPE_DATA_RW: - cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[index]); + cpu_watchpoint_remove_by_ref(cs, env->cpu_watchpoint[index]); break; case DR7_TYPE_IO_RW: /* No support for I/O watchpoints yet */ diff --git a/target-i386/machine.c b/target-i386/machine.c index d548c05..d49398c 100644 --- a/target-i386/machine.c +++ b/target-i386/machine.c @@ -290,6 +290,7 @@ static void cpu_pre_save(void *opaque) static int cpu_post_load(void *opaque, int version_id) { X86CPU *cpu =3D opaque; + CPUState *cs =3D CPU(cpu); CPUX86State *env =3D &cpu->env; int i; =20 @@ -320,7 +321,7 @@ static int cpu_post_load(void *opaque, int version_id= ) } =20 cpu_breakpoint_remove_all(env, BP_CPU); - cpu_watchpoint_remove_all(env, BP_CPU); + cpu_watchpoint_remove_all(cs, BP_CPU); for (i =3D 0; i < DR7_MAX_BP; i++) { hw_breakpoint_insert(env, i); } diff --git a/target-lm32/helper.c b/target-lm32/helper.c index eadc727..8633375 100644 --- a/target-lm32/helper.c +++ b/target-lm32/helper.c @@ -69,6 +69,7 @@ void lm32_breakpoint_remove(CPULM32State *env, int idx) void lm32_watchpoint_insert(CPULM32State *env, int idx, target_ulong add= ress, lm32_wp_t wp_type) { + LM32CPU *cpu =3D lm32_env_get_cpu(env); int flags =3D 0; =20 switch (wp_type) { @@ -87,18 +88,20 @@ void lm32_watchpoint_insert(CPULM32State *env, int id= x, target_ulong address, } =20 if (flags !=3D 0) { - cpu_watchpoint_insert(env, address, 1, flags, + cpu_watchpoint_insert(CPU(cpu), address, 1, flags, &env->cpu_watchpoint[idx]); } } =20 void lm32_watchpoint_remove(CPULM32State *env, int idx) { + LM32CPU *cpu =3D lm32_env_get_cpu(env); + if (!env->cpu_watchpoint[idx]) { return; } =20 - cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[idx]); + cpu_watchpoint_remove_by_ref(CPU(cpu), env->cpu_watchpoint[idx]); env->cpu_watchpoint[idx] =3D NULL; } =20 diff --git a/target-xtensa/op_helper.c b/target-xtensa/op_helper.c index 8233443..07b00a4 100644 --- a/target-xtensa/op_helper.c +++ b/target-xtensa/op_helper.c @@ -790,11 +790,12 @@ void HELPER(wsr_ibreaka)(CPUXtensaState *env, uint3= 2_t i, uint32_t v) static void set_dbreak(CPUXtensaState *env, unsigned i, uint32_t dbreaka= , uint32_t dbreakc) { + CPUState *cs =3D CPU(xtensa_env_get_cpu(env)); int flags =3D BP_CPU | BP_STOP_BEFORE_ACCESS; uint32_t mask =3D dbreakc | ~DBREAKC_MASK; =20 if (env->cpu_watchpoint[i]) { - cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[i]); + cpu_watchpoint_remove_by_ref(cs, env->cpu_watchpoint[i]); } if (dbreakc & DBREAKC_SB) { flags |=3D BP_MEM_WRITE; @@ -808,7 +809,7 @@ static void set_dbreak(CPUXtensaState *env, unsigned = i, uint32_t dbreaka, /* cut mask after the first zero bit */ mask =3D 0xffffffff << (32 - clo32(mask)); } - if (cpu_watchpoint_insert(env, dbreaka & mask, ~mask + 1, + if (cpu_watchpoint_insert(cs, dbreaka & mask, ~mask + 1, flags, &env->cpu_watchpoint[i])) { env->cpu_watchpoint[i] =3D NULL; qemu_log("Failed to set data breakpoint at 0x%08x/%d\n", @@ -834,7 +835,9 @@ void HELPER(wsr_dbreakc)(CPUXtensaState *env, uint32_= t i, uint32_t v) set_dbreak(env, i, env->sregs[DBREAKA + i], v); } else { if (env->cpu_watchpoint[i]) { - cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[i]= ); + CPUState *cs =3D CPU(xtensa_env_get_cpu(env)); + + cpu_watchpoint_remove_by_ref(cs, env->cpu_watchpoint[i])= ; env->cpu_watchpoint[i] =3D NULL; } } --=20 1.8.4.5