198944Sobrien/* Native macro definitions for GDB on an Intel i[3456]86.
2130803Smarcel   Copyright 2001, 2004 Free Software Foundation, Inc.
398944Sobrien
498944Sobrien   This file is part of GDB.
598944Sobrien
698944Sobrien   This program is free software; you can redistribute it and/or modify
798944Sobrien   it under the terms of the GNU General Public License as published by
898944Sobrien   the Free Software Foundation; either version 2 of the License, or
998944Sobrien   (at your option) any later version.
1098944Sobrien
1198944Sobrien   This program is distributed in the hope that it will be useful,
1298944Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
1398944Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1498944Sobrien   GNU General Public License for more details.
1598944Sobrien
1698944Sobrien   You should have received a copy of the GNU General Public License
1798944Sobrien   along with this program; if not, write to the Free Software
1898944Sobrien   Foundation, Inc., 59 Temple Place - Suite 330,
1998944Sobrien   Boston, MA 02111-1307, USA.  */
2098944Sobrien
2198944Sobrien#ifndef NM_I386_H
2298944Sobrien#define NM_I386_H 1
2398944Sobrien
2498944Sobrien/* Hardware-assisted breakpoints and watchpoints.  */
2598944Sobrien
2698944Sobrien/* Targets should define this to use the generic x86 watchpoint support.  */
2798944Sobrien#ifdef I386_USE_GENERIC_WATCHPOINTS
2898944Sobrien
2998944Sobrien#ifndef TARGET_HAS_HARDWARE_WATCHPOINTS
3098944Sobrien#define TARGET_HAS_HARDWARE_WATCHPOINTS
3198944Sobrien#endif
3298944Sobrien
3398944Sobrien/* Clear the reference counts and forget everything we knew about DRi.  */
3498944Sobrienextern void i386_cleanup_dregs (void);
3598944Sobrien
3698944Sobrien/* Insert a watchpoint to watch a memory region which starts at
3798944Sobrien   address ADDR and whose length is LEN bytes.  Watch memory accesses
3898944Sobrien   of the type TYPE.  Return 0 on success, -1 on failure.  */
3998944Sobrienextern int i386_insert_watchpoint (CORE_ADDR addr, int len, int type);
4098944Sobrien
4198944Sobrien/* Remove a watchpoint that watched the memory region which starts at
4298944Sobrien   address ADDR, whose length is LEN bytes, and for accesses of the
4398944Sobrien   type TYPE.  Return 0 on success, -1 on failure.  */
4498944Sobrienextern int i386_remove_watchpoint (CORE_ADDR addr, int len, int type);
4598944Sobrien
4698944Sobrien/* Return non-zero if we can watch a memory region that starts at
4798944Sobrien   address ADDR and whose length is LEN bytes.  */
4898944Sobrienextern int i386_region_ok_for_watchpoint (CORE_ADDR addr, int len);
4998944Sobrien
5098944Sobrien/* Return non-zero if the inferior has some break/watchpoint that
5198944Sobrien   triggered.  */
5298944Sobrienextern int i386_stopped_by_hwbp (void);
5398944Sobrien
5498944Sobrien/* If the inferior has some break/watchpoint that triggered, return
5598944Sobrien   the address associated with that break/watchpoint.  Otherwise,
5698944Sobrien   return zero.  */
5798944Sobrienextern CORE_ADDR i386_stopped_data_address (void);
5898944Sobrien
5998944Sobrien/* Insert a hardware-assisted breakpoint at address ADDR.  SHADOW is
6098944Sobrien   unused.  Return 0 on success, EBUSY on failure.  */
6198944Sobrienextern int i386_insert_hw_breakpoint (CORE_ADDR addr, void *shadow);
6298944Sobrien
6398944Sobrien/* Remove a hardware-assisted breakpoint at address ADDR.  SHADOW is
6498944Sobrien   unused. Return 0 on success, -1 on failure.  */
6598944Sobrienextern int  i386_remove_hw_breakpoint (CORE_ADDR addr, void *shadow);
6698944Sobrien
6798944Sobrien/* Returns the number of hardware watchpoints of type TYPE that we can
6898944Sobrien   set.  Value is positive if we can set CNT watchpoints, zero if
6998944Sobrien   setting watchpoints of type TYPE is not supported, and negative if
7098944Sobrien   CNT is more than the maximum number of watchpoints of type TYPE
7198944Sobrien   that we can support.  TYPE is one of bp_hardware_watchpoint,
7298944Sobrien   bp_read_watchpoint, bp_write_watchpoint, or bp_hardware_breakpoint.
7398944Sobrien   CNT is the number of such watchpoints used so far (including this
7498944Sobrien   one).  OTHERTYPE is non-zero if other types of watchpoints are
7598944Sobrien   currently enabled.
7698944Sobrien
7798944Sobrien   We always return 1 here because we don't have enough information
7898944Sobrien   about possible overlap of addresses that they want to watch.  As an
7998944Sobrien   extreme example, consider the case where all the watchpoints watch
8098944Sobrien   the same address and the same region length: then we can handle a
8198944Sobrien   virtually unlimited number of watchpoints, due to debug register
8298944Sobrien   sharing implemented via reference counts in i386-nat.c.  */
8398944Sobrien
8498944Sobrien#define TARGET_CAN_USE_HARDWARE_WATCHPOINT(type, cnt, ot) 1
8598944Sobrien
8698944Sobrien/* Returns non-zero if we can use hardware watchpoints to watch a
8798944Sobrien   region whose address is ADDR and whose length is LEN.  */
8898944Sobrien
8998944Sobrien#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(addr, len) \
9098944Sobrien  i386_region_ok_for_watchpoint (addr, len)
9198944Sobrien
9298944Sobrien/* After a watchpoint trap, the PC points to the instruction after the
9398944Sobrien   one that caused the trap.  Therefore we don't need to step over it.
9498944Sobrien   But we do need to reset the status register to avoid another trap.  */
9598944Sobrien
96130803Smarcel#define HAVE_CONTINUABLE_WATCHPOINT 1
9798944Sobrien
9898944Sobrien#define STOPPED_BY_WATCHPOINT(W)       (i386_stopped_data_address () != 0)
9998944Sobrien
10098944Sobrien#define target_stopped_data_address()  i386_stopped_data_address ()
10198944Sobrien
10298944Sobrien/* Use these macros for watchpoint insertion/removal.  */
10398944Sobrien
10498944Sobrien#define target_insert_watchpoint(addr, len, type) \
10598944Sobrien  i386_insert_watchpoint (addr, len, type)
10698944Sobrien
10798944Sobrien#define target_remove_watchpoint(addr, len, type) \
10898944Sobrien  i386_remove_watchpoint (addr, len, type)
10998944Sobrien
11098944Sobrien#define target_insert_hw_breakpoint(addr, shadow) \
11198944Sobrien  i386_insert_hw_breakpoint (addr, shadow)
11298944Sobrien
11398944Sobrien#define target_remove_hw_breakpoint(addr, shadow) \
11498944Sobrien  i386_remove_hw_breakpoint (addr, shadow)
11598944Sobrien
116104990Smp/* child_post_startup_inferior used to
117104990Smp   reset all debug registers by calling i386_cleanup_dregs ().  */
118104990Smp#define CHILD_POST_STARTUP_INFERIOR
119104990Smp
12098944Sobrien#endif /* I386_USE_GENERIC_WATCHPOINTS */
12198944Sobrien
12298944Sobrien#endif /* NM_I386_H */
123