From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L2Wxq-0006ug-VD for qemu-devel@nongnu.org; Tue, 18 Nov 2008 15:14:22 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L2Wxq-0006uQ-GR for qemu-devel@nongnu.org; Tue, 18 Nov 2008 15:14:22 -0500 Received: from [199.232.76.173] (port=47446 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L2Wxq-0006uF-9I for qemu-devel@nongnu.org; Tue, 18 Nov 2008 15:14:22 -0500 Received: from savannah.gnu.org ([199.232.41.3]:44849 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L2Wxq-00071K-9K for qemu-devel@nongnu.org; Tue, 18 Nov 2008 15:14:22 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1L2Wxp-0008Oy-7m for qemu-devel@nongnu.org; Tue, 18 Nov 2008 20:14:21 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1L2Wxo-0008Ou-Pi for qemu-devel@nongnu.org; Tue, 18 Nov 2008 20:14:21 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 18 Nov 2008 20:14:20 +0000 Subject: [Qemu-devel] [5740] Respect length of watchpoints (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 5740 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5740 Author: aliguori Date: 2008-11-18 20:14:20 +0000 (Tue, 18 Nov 2008) Log Message: ----------- Respect length of watchpoints (Jan Kiszka) This adds length support for watchpoints. To keep things simple, only aligned watchpoints are accepted. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/exec.c Modified: trunk/exec.c =================================================================== --- trunk/exec.c 2008-11-18 20:09:43 UTC (rev 5739) +++ trunk/exec.c 2008-11-18 20:14:20 UTC (rev 5740) @@ -1301,14 +1301,21 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len, int flags, CPUWatchpoint **watchpoint) { + target_ulong len_mask = ~(len - 1); CPUWatchpoint *wp; + /* sanity checks: allow power-of-2 lengths, deny unaligned watchpoints */ + if ((len != 1 && len != 2 && len != 4 && len != 8) || (addr & ~len_mask)) { + fprintf(stderr, "qemu: tried to set invalid watchpoint at " + TARGET_FMT_lx ", len=" TARGET_FMT_lu "\n", addr, len); + return -EINVAL; + } wp = qemu_malloc(sizeof(*wp)); if (!wp) return -ENOBUFS; wp->vaddr = addr; - wp->len_mask = 0; + wp->len_mask = len_mask; wp->flags = flags; wp->next = env->watchpoints; @@ -1332,10 +1339,12 @@ int cpu_watchpoint_remove(CPUState *env, target_ulong addr, target_ulong len, int flags) { + target_ulong len_mask = ~(len - 1); CPUWatchpoint *wp; for (wp = env->watchpoints; wp != NULL; wp = wp->next) { - if (addr == wp->vaddr && flags == wp->flags) { + if (addr == wp->vaddr && len_mask == wp->len_mask + && flags == wp->flags) { cpu_watchpoint_remove_by_ref(env, wp); return 0; } @@ -2494,7 +2503,7 @@ }; /* Generate a debug exception if a watchpoint has been hit. */ -static void check_watchpoint(int offset, int flags) +static void check_watchpoint(int offset, int len_mask, int flags) { CPUState *env = cpu_single_env; target_ulong vaddr; @@ -2502,7 +2511,8 @@ vaddr = (env->mem_io_vaddr & TARGET_PAGE_MASK) + offset; for (wp = env->watchpoints; wp != NULL; wp = wp->next) { - if (vaddr == wp->vaddr && (wp->flags & flags)) { + if ((vaddr == (wp->vaddr & len_mask) || + (vaddr & wp->len_mask) == wp->vaddr) && (wp->flags & flags)) { env->watchpoint_hit = wp; cpu_interrupt(env, CPU_INTERRUPT_DEBUG); break; @@ -2515,40 +2525,40 @@ phys routines. */ static uint32_t watch_mem_readb(void *opaque, target_phys_addr_t addr) { - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_READ); + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x0, BP_MEM_READ); return ldub_phys(addr); } static uint32_t watch_mem_readw(void *opaque, target_phys_addr_t addr) { - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_READ); + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x1, BP_MEM_READ); return lduw_phys(addr); } static uint32_t watch_mem_readl(void *opaque, target_phys_addr_t addr) { - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_READ); + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x3, BP_MEM_READ); return ldl_phys(addr); } static void watch_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) { - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_WRITE); + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x0, BP_MEM_WRITE); stb_phys(addr, val); } static void watch_mem_writew(void *opaque, target_phys_addr_t addr, uint32_t val) { - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_WRITE); + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x1, BP_MEM_WRITE); stw_phys(addr, val); } static void watch_mem_writel(void *opaque, target_phys_addr_t addr, uint32_t val) { - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_WRITE); + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x3, BP_MEM_WRITE); stl_phys(addr, val); }