4 * Copyright (c) 2003 Fabrice Bellard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu/error-report.h"
22 #include "exec/exec-all.h"
23 #include "hw/core/cpu.h"
25 /* Add a watchpoint. */
26 int cpu_watchpoint_insert(CPUState
*cpu
, vaddr addr
, vaddr len
,
27 int flags
, CPUWatchpoint
**watchpoint
)
32 /* forbid ranges which are empty or run off the end of the address space */
33 if (len
== 0 || (addr
+ len
- 1) < addr
) {
34 error_report("tried to set invalid watchpoint at %"
35 VADDR_PRIx
", len=%" VADDR_PRIu
, addr
, len
);
38 wp
= g_malloc(sizeof(*wp
));
44 /* keep all GDB-injected watchpoints in front */
46 QTAILQ_INSERT_HEAD(&cpu
->watchpoints
, wp
, entry
);
48 QTAILQ_INSERT_TAIL(&cpu
->watchpoints
, wp
, entry
);
51 in_page
= -(addr
| TARGET_PAGE_MASK
);
53 tlb_flush_page(cpu
, addr
);
64 /* Remove a specific watchpoint. */
65 int cpu_watchpoint_remove(CPUState
*cpu
, vaddr addr
, vaddr len
,
70 QTAILQ_FOREACH(wp
, &cpu
->watchpoints
, entry
) {
71 if (addr
== wp
->vaddr
&& len
== wp
->len
72 && flags
== (wp
->flags
& ~BP_WATCHPOINT_HIT
)) {
73 cpu_watchpoint_remove_by_ref(cpu
, wp
);
80 /* Remove a specific watchpoint by reference. */
81 void cpu_watchpoint_remove_by_ref(CPUState
*cpu
, CPUWatchpoint
*watchpoint
)
83 QTAILQ_REMOVE(&cpu
->watchpoints
, watchpoint
, entry
);
85 tlb_flush_page(cpu
, watchpoint
->vaddr
);
90 /* Remove all matching watchpoints. */
91 void cpu_watchpoint_remove_all(CPUState
*cpu
, int mask
)
93 CPUWatchpoint
*wp
, *next
;
95 QTAILQ_FOREACH_SAFE(wp
, &cpu
->watchpoints
, entry
, next
) {
96 if (wp
->flags
& mask
) {
97 cpu_watchpoint_remove_by_ref(cpu
, wp
);