Commit b4051334d853da807cf9f4fbc834261b2f630f82

Authored by aliguori
1 parent db8886d3

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 <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5740 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 20 additions and 10 deletions
... ... @@ -1301,14 +1301,21 @@ static void breakpoint_invalidate(CPUState *env, target_ulong pc)
1301 1301 int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
1302 1302 int flags, CPUWatchpoint **watchpoint)
1303 1303 {
  1304 + target_ulong len_mask = ~(len - 1);
1304 1305 CPUWatchpoint *wp;
1305 1306  
  1307 + /* sanity checks: allow power-of-2 lengths, deny unaligned watchpoints */
  1308 + if ((len != 1 && len != 2 && len != 4 && len != 8) || (addr & ~len_mask)) {
  1309 + fprintf(stderr, "qemu: tried to set invalid watchpoint at "
  1310 + TARGET_FMT_lx ", len=" TARGET_FMT_lu "\n", addr, len);
  1311 + return -EINVAL;
  1312 + }
1306 1313 wp = qemu_malloc(sizeof(*wp));
1307 1314 if (!wp)
1308 1315 return -ENOBUFS;
1309 1316  
1310 1317 wp->vaddr = addr;
1311   - wp->len_mask = 0;
  1318 + wp->len_mask = len_mask;
1312 1319 wp->flags = flags;
1313 1320  
1314 1321 wp->next = env->watchpoints;
... ... @@ -1332,10 +1339,12 @@ int cpu_watchpoint_insert(CPUState *env, target_ulong addr, target_ulong len,
1332 1339 int cpu_watchpoint_remove(CPUState *env, target_ulong addr, target_ulong len,
1333 1340 int flags)
1334 1341 {
  1342 + target_ulong len_mask = ~(len - 1);
1335 1343 CPUWatchpoint *wp;
1336 1344  
1337 1345 for (wp = env->watchpoints; wp != NULL; wp = wp->next) {
1338   - if (addr == wp->vaddr && flags == wp->flags) {
  1346 + if (addr == wp->vaddr && len_mask == wp->len_mask
  1347 + && flags == wp->flags) {
1339 1348 cpu_watchpoint_remove_by_ref(env, wp);
1340 1349 return 0;
1341 1350 }
... ... @@ -2494,7 +2503,7 @@ static CPUWriteMemoryFunc *notdirty_mem_write[3] = {
2494 2503 };
2495 2504  
2496 2505 /* Generate a debug exception if a watchpoint has been hit. */
2497   -static void check_watchpoint(int offset, int flags)
  2506 +static void check_watchpoint(int offset, int len_mask, int flags)
2498 2507 {
2499 2508 CPUState *env = cpu_single_env;
2500 2509 target_ulong vaddr;
... ... @@ -2502,7 +2511,8 @@ static void check_watchpoint(int offset, int flags)
2502 2511  
2503 2512 vaddr = (env->mem_io_vaddr & TARGET_PAGE_MASK) + offset;
2504 2513 for (wp = env->watchpoints; wp != NULL; wp = wp->next) {
2505   - if (vaddr == wp->vaddr && (wp->flags & flags)) {
  2514 + if ((vaddr == (wp->vaddr & len_mask) ||
  2515 + (vaddr & wp->len_mask) == wp->vaddr) && (wp->flags & flags)) {
2506 2516 env->watchpoint_hit = wp;
2507 2517 cpu_interrupt(env, CPU_INTERRUPT_DEBUG);
2508 2518 break;
... ... @@ -2515,40 +2525,40 @@ static void check_watchpoint(int offset, int flags)
2515 2525 phys routines. */
2516 2526 static uint32_t watch_mem_readb(void *opaque, target_phys_addr_t addr)
2517 2527 {
2518   - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_READ);
  2528 + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x0, BP_MEM_READ);
2519 2529 return ldub_phys(addr);
2520 2530 }
2521 2531  
2522 2532 static uint32_t watch_mem_readw(void *opaque, target_phys_addr_t addr)
2523 2533 {
2524   - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_READ);
  2534 + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x1, BP_MEM_READ);
2525 2535 return lduw_phys(addr);
2526 2536 }
2527 2537  
2528 2538 static uint32_t watch_mem_readl(void *opaque, target_phys_addr_t addr)
2529 2539 {
2530   - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_READ);
  2540 + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x3, BP_MEM_READ);
2531 2541 return ldl_phys(addr);
2532 2542 }
2533 2543  
2534 2544 static void watch_mem_writeb(void *opaque, target_phys_addr_t addr,
2535 2545 uint32_t val)
2536 2546 {
2537   - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_WRITE);
  2547 + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x0, BP_MEM_WRITE);
2538 2548 stb_phys(addr, val);
2539 2549 }
2540 2550  
2541 2551 static void watch_mem_writew(void *opaque, target_phys_addr_t addr,
2542 2552 uint32_t val)
2543 2553 {
2544   - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_WRITE);
  2554 + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x1, BP_MEM_WRITE);
2545 2555 stw_phys(addr, val);
2546 2556 }
2547 2557  
2548 2558 static void watch_mem_writel(void *opaque, target_phys_addr_t addr,
2549 2559 uint32_t val)
2550 2560 {
2551   - check_watchpoint(addr & ~TARGET_PAGE_MASK, BP_MEM_WRITE);
  2561 + check_watchpoint(addr & ~TARGET_PAGE_MASK, ~0x3, BP_MEM_WRITE);
2552 2562 stl_phys(addr, val);
2553 2563 }
2554 2564  
... ...