1 /* S390 native-dependent code for GDB, the GNU debugger.
2 Copyright 2001, 2003 Free Software Foundation, Inc
4 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
5 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 #include "s390-tdep.h"
31 #include <asm/ptrace.h>
32 #include <sys/ptrace.h>
33 #include <asm/types.h>
34 #include <sys/procfs.h>
36 #include <sys/ucontext.h>
39 /* Map registers to gregset/ptrace offsets.
40 These arrays are defined in s390-tdep.c. */
43 #define regmap_gregset s390x_regmap_gregset
45 #define regmap_gregset s390_regmap_gregset
48 #define regmap_fpregset s390_regmap_fpregset
51 /* Fill GDB's register array with the general-purpose register values
54 supply_gregset (gregset_t
*regp
)
57 for (i
= 0; i
< S390_NUM_REGS
; i
++)
58 if (regmap_gregset
[i
] != -1)
59 regcache_raw_supply (current_regcache
, i
,
60 (char *)regp
+ regmap_gregset
[i
]);
63 /* Fill register REGNO (if it is a general-purpose register) in
64 *REGP with the value in GDB's register array. If REGNO is -1,
65 do this for all registers. */
67 fill_gregset (gregset_t
*regp
, int regno
)
70 for (i
= 0; i
< S390_NUM_REGS
; i
++)
71 if (regmap_gregset
[i
] != -1)
72 if (regno
== -1 || regno
== i
)
73 regcache_raw_collect (current_regcache
, i
,
74 (char *)regp
+ regmap_gregset
[i
]);
77 /* Fill GDB's register array with the floating-point register values
80 supply_fpregset (fpregset_t
*regp
)
83 for (i
= 0; i
< S390_NUM_REGS
; i
++)
84 if (regmap_fpregset
[i
] != -1)
85 regcache_raw_supply (current_regcache
, i
,
86 ((char *)regp
) + regmap_fpregset
[i
]);
89 /* Fill register REGNO (if it is a general-purpose register) in
90 *REGP with the value in GDB's register array. If REGNO is -1,
91 do this for all registers. */
93 fill_fpregset (fpregset_t
*regp
, int regno
)
96 for (i
= 0; i
< S390_NUM_REGS
; i
++)
97 if (regmap_fpregset
[i
] != -1)
98 if (regno
== -1 || regno
== i
)
99 regcache_raw_collect (current_regcache
, i
,
100 ((char *)regp
) + regmap_fpregset
[i
]);
103 /* Find the TID for the current inferior thread to use with ptrace. */
105 s390_inferior_tid (void)
107 /* GNU/Linux LWP ID's are process ID's. */
108 int tid
= TIDGET (inferior_ptid
);
110 tid
= PIDGET (inferior_ptid
); /* Not a threaded program. */
115 /* Fetch all general-purpose registers from process/thread TID and
116 store their values in GDB's register cache. */
123 parea
.len
= sizeof (regs
);
124 parea
.process_addr
= (addr_t
) ®s
;
125 parea
.kernel_addr
= offsetof (struct user_regs_struct
, psw
);
126 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
) < 0)
127 perror_with_name ("Couldn't get registers");
129 supply_gregset (®s
);
132 /* Store all valid general-purpose registers in GDB's register cache
133 into the process/thread specified by TID. */
135 store_regs (int tid
, int regnum
)
140 parea
.len
= sizeof (regs
);
141 parea
.process_addr
= (addr_t
) ®s
;
142 parea
.kernel_addr
= offsetof (struct user_regs_struct
, psw
);
143 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
) < 0)
144 perror_with_name ("Couldn't get registers");
146 fill_gregset (®s
, regnum
);
148 if (ptrace (PTRACE_POKEUSR_AREA
, tid
, (long) &parea
) < 0)
149 perror_with_name ("Couldn't write registers");
152 /* Fetch all floating-point registers from process/thread TID and store
153 their values in GDB's register cache. */
155 fetch_fpregs (int tid
)
160 parea
.len
= sizeof (fpregs
);
161 parea
.process_addr
= (addr_t
) &fpregs
;
162 parea
.kernel_addr
= offsetof (struct user_regs_struct
, fp_regs
);
163 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
) < 0)
164 perror_with_name ("Couldn't get floating point status");
166 supply_fpregset (&fpregs
);
169 /* Store all valid floating-point registers in GDB's register cache
170 into the process/thread specified by TID. */
172 store_fpregs (int tid
, int regnum
)
177 parea
.len
= sizeof (fpregs
);
178 parea
.process_addr
= (addr_t
) &fpregs
;
179 parea
.kernel_addr
= offsetof (struct user_regs_struct
, fp_regs
);
180 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, (long) &parea
) < 0)
181 perror_with_name ("Couldn't get floating point status");
183 fill_fpregset (&fpregs
, regnum
);
185 if (ptrace (PTRACE_POKEUSR_AREA
, tid
, (long) &parea
) < 0)
186 perror_with_name ("Couldn't write floating point status");
189 /* Fetch register REGNUM from the child process. If REGNUM is -1, do
190 this for all registers. */
192 fetch_inferior_registers (int regnum
)
194 int tid
= s390_inferior_tid ();
197 || (regnum
< S390_NUM_REGS
&& regmap_gregset
[regnum
] != -1))
201 || (regnum
< S390_NUM_REGS
&& regmap_fpregset
[regnum
] != -1))
205 /* Store register REGNUM back into the child process. If REGNUM is
206 -1, do this for all registers. */
208 store_inferior_registers (int regnum
)
210 int tid
= s390_inferior_tid ();
213 || (regnum
< S390_NUM_REGS
&& regmap_gregset
[regnum
] != -1))
214 store_regs (tid
, regnum
);
217 || (regnum
< S390_NUM_REGS
&& regmap_fpregset
[regnum
] != -1))
218 store_fpregs (tid
, regnum
);
222 /* Hardware-assisted watchpoint handling. */
224 /* We maintain a list of all currently active watchpoints in order
225 to properly handle watchpoint removal.
227 The only thing we actually need is the total address space area
228 spanned by the watchpoints. */
232 struct watch_area
*next
;
237 static struct watch_area
*watch_base
= NULL
;
240 s390_stopped_by_watchpoint (void)
242 per_lowcore_bits per_lowcore
;
245 /* Speed up common case. */
249 parea
.len
= sizeof (per_lowcore
);
250 parea
.process_addr
= (addr_t
) & per_lowcore
;
251 parea
.kernel_addr
= offsetof (struct user_regs_struct
, per_info
.lowcore
);
252 if (ptrace (PTRACE_PEEKUSR_AREA
, s390_inferior_tid (), &parea
) < 0)
253 perror_with_name ("Couldn't retrieve watchpoint status");
255 return per_lowcore
.perc_storage_alteration
== 1
256 && per_lowcore
.perc_store_real_address
== 0;
260 s390_fix_watch_points (void)
262 int tid
= s390_inferior_tid ();
267 CORE_ADDR watch_lo_addr
= (CORE_ADDR
)-1, watch_hi_addr
= 0;
268 struct watch_area
*area
;
270 for (area
= watch_base
; area
; area
= area
->next
)
272 watch_lo_addr
= min (watch_lo_addr
, area
->lo_addr
);
273 watch_hi_addr
= max (watch_hi_addr
, area
->hi_addr
);
276 parea
.len
= sizeof (per_info
);
277 parea
.process_addr
= (addr_t
) & per_info
;
278 parea
.kernel_addr
= offsetof (struct user_regs_struct
, per_info
);
279 if (ptrace (PTRACE_PEEKUSR_AREA
, tid
, &parea
) < 0)
280 perror_with_name ("Couldn't retrieve watchpoint status");
284 per_info
.control_regs
.bits
.em_storage_alteration
= 1;
285 per_info
.control_regs
.bits
.storage_alt_space_ctl
= 1;
289 per_info
.control_regs
.bits
.em_storage_alteration
= 0;
290 per_info
.control_regs
.bits
.storage_alt_space_ctl
= 0;
292 per_info
.starting_addr
= watch_lo_addr
;
293 per_info
.ending_addr
= watch_hi_addr
;
295 if (ptrace (PTRACE_POKEUSR_AREA
, tid
, &parea
) < 0)
296 perror_with_name ("Couldn't modify watchpoint status");
300 s390_insert_watchpoint (CORE_ADDR addr
, int len
)
302 struct watch_area
*area
= xmalloc (sizeof (struct watch_area
));
306 area
->lo_addr
= addr
;
307 area
->hi_addr
= addr
+ len
- 1;
309 area
->next
= watch_base
;
312 s390_fix_watch_points ();
317 s390_remove_watchpoint (CORE_ADDR addr
, int len
)
319 struct watch_area
*area
, **parea
;
321 for (parea
= &watch_base
; *parea
; parea
= &(*parea
)->next
)
322 if ((*parea
)->lo_addr
== addr
323 && (*parea
)->hi_addr
== addr
+ len
- 1)
328 fprintf_unfiltered (gdb_stderr
,
329 "Attempt to remove nonexistent watchpoint.\n");
337 s390_fix_watch_points ();
345 return sizeof (struct user
);