1 /* Intel 386 native support for SYSV systems (pre-SVR4).
2 Copyright (C) 1988, 89, 91, 92, 94, 96, 1998 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program 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
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
26 #ifdef HAVE_SYS_PTRACE_H
27 #include <sys/ptrace.h>
37 #include <sys/types.h>
40 #include <sys/param.h>
44 #include <sys/ioctl.h>
48 /* FIXME: The following used to be just "#include <sys/debugreg.h>", but
49 * the the Linux 2.1.x kernel and glibc 2.0.x are not in sync; including
50 * <sys/debugreg.h> will result in an error. With luck, these losers
51 * will get their act together and we can trash this hack in the near future.
55 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
56 #ifdef HAVE_ASM_DEBUGREG_H
57 #include <asm/debugreg.h>
59 #include <sys/debugreg.h>
70 #include "floatformat.h"
75 /* this table must line up with REGISTER_NAMES in tm-i386v.h */
76 /* symbols like 'EAX' come from <sys/reg.h> */
85 /* blockend is the value of u.u_ar0, and points to the
86 * place where GS is stored
90 i386_register_u_addr (int blockend
, int regnum
)
97 /* FIXME: Should have better way to test floating point range */
98 if (regnum
>= FP0_REGNUM
&& regnum
<= (FP0_REGNUM
+ 7))
100 #ifdef KSTKSZ /* SCO, and others? */
101 ubase
+= 4 * (SS
+ 1) - KSTKSZ
;
102 fpstate
= ubase
+ ((char *) &u
.u_fps
.u_fpstate
- (char *) &u
);
103 return (fpstate
+ 0x1c + 10 * (regnum
- FP0_REGNUM
));
105 fpstate
= ubase
+ ((char *) &u
.i387
.st_space
- (char *) &u
);
106 return (fpstate
+ 10 * (regnum
- FP0_REGNUM
));
111 return (ubase
+ 4 * regmap
[regnum
]);
119 return (sizeof (struct user
));
122 #ifdef TARGET_HAS_HARDWARE_WATCHPOINTS
124 #if !defined (offsetof)
125 #define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
128 /* Record the value of the debug control register. */
129 static int debug_control_mirror
;
131 /* Record which address associates with which register. */
132 static CORE_ADDR address_lookup
[DR_LASTADDR
- DR_FIRSTADDR
+ 1];
135 i386_insert_aligned_watchpoint (int, CORE_ADDR
, CORE_ADDR
, int, int);
138 i386_insert_nonaligned_watchpoint (int, CORE_ADDR
, CORE_ADDR
, int, int);
140 /* Insert a watchpoint. */
143 i386_insert_watchpoint (int pid
, CORE_ADDR addr
, int len
, int rw
)
145 return i386_insert_aligned_watchpoint (pid
, addr
, addr
, len
, rw
);
149 i386_insert_aligned_watchpoint (int pid
, CORE_ADDR waddr
, CORE_ADDR addr
,
153 int read_write_bits
, len_bits
;
154 int free_debug_register
;
157 /* Look for a free debug register. */
158 for (i
= DR_FIRSTADDR
; i
<= DR_LASTADDR
; i
++)
160 if (address_lookup
[i
- DR_FIRSTADDR
] == 0)
164 /* No more debug registers! */
168 read_write_bits
= (rw
& 1) ? DR_RW_READ
: DR_RW_WRITE
;
175 return i386_insert_nonaligned_watchpoint (pid
, waddr
, addr
, len
, rw
);
182 return i386_insert_nonaligned_watchpoint (pid
, waddr
, addr
, len
, rw
);
186 return i386_insert_nonaligned_watchpoint (pid
, waddr
, addr
, len
, rw
);
188 free_debug_register
= i
;
189 register_number
= free_debug_register
- DR_FIRSTADDR
;
190 debug_control_mirror
|=
191 ((read_write_bits
| len_bits
)
192 << (DR_CONTROL_SHIFT
+ DR_CONTROL_SIZE
* register_number
));
193 debug_control_mirror
|=
194 (1 << (DR_LOCAL_ENABLE_SHIFT
+ DR_ENABLE_SIZE
* register_number
));
195 debug_control_mirror
|= DR_LOCAL_SLOWDOWN
;
196 debug_control_mirror
&= ~DR_CONTROL_RESERVED
;
198 ptrace (6, pid
, offsetof (struct user
, u_debugreg
[DR_CONTROL
]),
199 debug_control_mirror
);
200 ptrace (6, pid
, offsetof (struct user
, u_debugreg
[free_debug_register
]),
203 /* Record where we came from. */
204 address_lookup
[register_number
] = addr
;
209 i386_insert_nonaligned_watchpoint (int pid
, CORE_ADDR waddr
, CORE_ADDR addr
,
216 static int size_try_array
[4][4] =
218 { 1, 1, 1, 1 }, /* trying size one */
219 { 2, 1, 2, 1 }, /* trying size two */
220 { 2, 1, 2, 1 }, /* trying size three */
221 { 4, 1, 2, 1 } /* trying size four */
228 /* Four is the maximum length for 386. */
229 size
= size_try_array
[len
> 4 ? 3 : len
- 1][align
];
231 rv
= i386_insert_aligned_watchpoint (pid
, waddr
, addr
, size
, rw
);
234 i386_remove_watchpoint (pid
, waddr
, size
);
243 /* Remove a watchpoint. */
246 i386_remove_watchpoint (int pid
, CORE_ADDR addr
, int len
)
251 for (i
= DR_FIRSTADDR
; i
<= DR_LASTADDR
; i
++)
253 register_number
= i
- DR_FIRSTADDR
;
254 if (address_lookup
[register_number
] == addr
)
256 debug_control_mirror
&=
257 ~(1 << (DR_LOCAL_ENABLE_SHIFT
+ DR_ENABLE_SIZE
* register_number
));
258 address_lookup
[register_number
] = 0;
261 ptrace (6, pid
, offsetof (struct user
, u_debugreg
[DR_CONTROL
]),
262 debug_control_mirror
);
263 ptrace (6, pid
, offsetof (struct user
, u_debugreg
[DR_STATUS
]), 0);
268 /* Check if stopped by a watchpoint. */
271 i386_stopped_by_watchpoint (int pid
)
276 status
= ptrace (3, pid
, offsetof (struct user
, u_debugreg
[DR_STATUS
]), 0);
277 ptrace (6, pid
, offsetof (struct user
, u_debugreg
[DR_STATUS
]), 0);
279 for (i
= DR_FIRSTADDR
; i
<= DR_LASTADDR
; i
++)
281 if (status
& (1 << (i
- DR_FIRSTADDR
)))
282 return address_lookup
[i
- DR_FIRSTADDR
];
288 #endif /* TARGET_HAS_HARDWARE_WATCHPOINTS */
This page took 0.035052 seconds and 4 git commands to generate.