Commit | Line | Data |
---|---|---|
d6e58945 | 1 | /* Target-dependent code for GNU/Linux on s390. |
ca557f44 | 2 | |
e2882c85 | 3 | Copyright (C) 2001-2018 Free Software Foundation, Inc. |
ca557f44 | 4 | |
5769d3cd AC |
5 | Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com) |
6 | for IBM Deutschland Entwicklung GmbH, IBM Corporation. | |
7 | ||
8 | This file is part of GDB. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 12 | the Free Software Foundation; either version 3 of the License, or |
5769d3cd AC |
13 | (at your option) any later version. |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5769d3cd | 22 | |
d0f54f9d | 23 | #include "defs.h" |
5769d3cd AC |
24 | #include "arch-utils.h" |
25 | #include "frame.h" | |
26 | #include "inferior.h" | |
45741a9c | 27 | #include "infrun.h" |
5769d3cd AC |
28 | #include "symtab.h" |
29 | #include "target.h" | |
30 | #include "gdbcore.h" | |
31 | #include "gdbcmd.h" | |
5769d3cd | 32 | #include "objfiles.h" |
7042632b | 33 | #include "osabi.h" |
5769d3cd | 34 | #include "regcache.h" |
a8c99f38 JB |
35 | #include "trad-frame.h" |
36 | #include "frame-base.h" | |
37 | #include "frame-unwind.h" | |
a431654a | 38 | #include "dwarf2-frame.h" |
d0f54f9d JB |
39 | #include "reggroups.h" |
40 | #include "regset.h" | |
fd0407d6 | 41 | #include "value.h" |
a89aa300 | 42 | #include "dis-asm.h" |
76a9d10f | 43 | #include "solib-svr4.h" |
3fc46200 | 44 | #include "prologue-value.h" |
70728992 | 45 | #include "linux-tdep.h" |
d6e58945 | 46 | #include "s390-tdep.h" |
0e5fae36 | 47 | #include "s390-linux-tdep.h" |
566c56c9 MK |
48 | #include "linux-record.h" |
49 | #include "record-full.h" | |
4ac33720 | 50 | #include "auxv.h" |
237b092b | 51 | #include "xml-syscall.h" |
5769d3cd | 52 | |
55aa24fb SDJ |
53 | #include "stap-probe.h" |
54 | #include "ax.h" | |
55 | #include "ax-gdb.h" | |
56 | #include "user-regs.h" | |
57 | #include "cli/cli-utils.h" | |
58 | #include <ctype.h> | |
04a83fee | 59 | #include "elf/common.h" |
417c80f9 AA |
60 | #include "elf/s390.h" |
61 | #include "elf-bfd.h" | |
325fac50 | 62 | #include <algorithm> |
55aa24fb | 63 | |
7803799a | 64 | #include "features/s390-linux32.c" |
c642a434 UW |
65 | #include "features/s390-linux32v1.c" |
66 | #include "features/s390-linux32v2.c" | |
7803799a | 67 | #include "features/s390-linux64.c" |
c642a434 UW |
68 | #include "features/s390-linux64v1.c" |
69 | #include "features/s390-linux64v2.c" | |
4ac33720 | 70 | #include "features/s390-te-linux64.c" |
550bdf96 AA |
71 | #include "features/s390-vx-linux64.c" |
72 | #include "features/s390-tevx-linux64.c" | |
1b63490c | 73 | #include "features/s390-gs-linux64.c" |
7803799a | 74 | #include "features/s390x-linux64.c" |
c642a434 UW |
75 | #include "features/s390x-linux64v1.c" |
76 | #include "features/s390x-linux64v2.c" | |
4ac33720 | 77 | #include "features/s390x-te-linux64.c" |
550bdf96 AA |
78 | #include "features/s390x-vx-linux64.c" |
79 | #include "features/s390x-tevx-linux64.c" | |
1b63490c | 80 | #include "features/s390x-gs-linux64.c" |
7803799a | 81 | |
237b092b AA |
82 | #define XML_SYSCALL_FILENAME_S390 "syscalls/s390-linux.xml" |
83 | #define XML_SYSCALL_FILENAME_S390X "syscalls/s390x-linux.xml" | |
84 | ||
c642a434 UW |
85 | static int |
86 | s390_cannot_store_register (struct gdbarch *gdbarch, int regnum) | |
87 | { | |
88 | /* The last-break address is read-only. */ | |
89 | return regnum == S390_LAST_BREAK_REGNUM; | |
90 | } | |
91 | ||
92 | static void | |
93 | s390_write_pc (struct regcache *regcache, CORE_ADDR pc) | |
94 | { | |
ac7936df | 95 | struct gdbarch *gdbarch = regcache->arch (); |
c642a434 UW |
96 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
97 | ||
98 | regcache_cooked_write_unsigned (regcache, tdep->pc_regnum, pc); | |
99 | ||
100 | /* Set special SYSTEM_CALL register to 0 to prevent the kernel from | |
101 | messing with the PC we just installed, if we happen to be within | |
102 | an interrupted system call that the kernel wants to restart. | |
103 | ||
104 | Note that after we return from the dummy call, the SYSTEM_CALL and | |
105 | ORIG_R2 registers will be automatically restored, and the kernel | |
106 | continues to restart the system call at this point. */ | |
107 | if (register_size (gdbarch, S390_SYSTEM_CALL_REGNUM) > 0) | |
108 | regcache_cooked_write_unsigned (regcache, S390_SYSTEM_CALL_REGNUM, 0); | |
109 | } | |
110 | ||
d6e58945 | 111 | /* Maps for register sets. */ |
f79a3bae | 112 | |
d6e58945 PR |
113 | static const struct regcache_map_entry s390_gregmap[] = |
114 | { | |
115 | { 1, S390_PSWM_REGNUM }, | |
116 | { 1, S390_PSWA_REGNUM }, | |
117 | { 16, S390_R0_REGNUM }, | |
118 | { 16, S390_A0_REGNUM }, | |
119 | { 1, S390_ORIG_R2_REGNUM }, | |
120 | { 0 } | |
121 | }; | |
f79a3bae | 122 | |
d6e58945 PR |
123 | static const struct regcache_map_entry s390_fpregmap[] = |
124 | { | |
125 | { 1, S390_FPC_REGNUM, 8 }, | |
126 | { 16, S390_F0_REGNUM, 8 }, | |
127 | { 0 } | |
128 | }; | |
f79a3bae | 129 | |
d6e58945 PR |
130 | static const struct regcache_map_entry s390_regmap_upper[] = |
131 | { | |
132 | { 16, S390_R0_UPPER_REGNUM, 4 }, | |
133 | { 0 } | |
134 | }; | |
f79a3bae | 135 | |
d6e58945 PR |
136 | static const struct regcache_map_entry s390_regmap_last_break[] = |
137 | { | |
138 | { 1, REGCACHE_MAP_SKIP, 4 }, | |
139 | { 1, S390_LAST_BREAK_REGNUM, 4 }, | |
140 | { 0 } | |
141 | }; | |
f79a3bae | 142 | |
d6e58945 PR |
143 | static const struct regcache_map_entry s390x_regmap_last_break[] = |
144 | { | |
145 | { 1, S390_LAST_BREAK_REGNUM, 8 }, | |
146 | { 0 } | |
147 | }; | |
7803799a | 148 | |
d6e58945 PR |
149 | static const struct regcache_map_entry s390_regmap_system_call[] = |
150 | { | |
151 | { 1, S390_SYSTEM_CALL_REGNUM, 4 }, | |
152 | { 0 } | |
153 | }; | |
d0f54f9d | 154 | |
d6e58945 PR |
155 | static const struct regcache_map_entry s390_regmap_tdb[] = |
156 | { | |
157 | { 1, S390_TDB_DWORD0_REGNUM, 8 }, | |
158 | { 1, S390_TDB_ABORT_CODE_REGNUM, 8 }, | |
159 | { 1, S390_TDB_CONFLICT_TOKEN_REGNUM, 8 }, | |
160 | { 1, S390_TDB_ATIA_REGNUM, 8 }, | |
161 | { 12, REGCACHE_MAP_SKIP, 8 }, | |
162 | { 16, S390_TDB_R0_REGNUM, 8 }, | |
163 | { 0 } | |
164 | }; | |
d0f54f9d | 165 | |
d6e58945 PR |
166 | static const struct regcache_map_entry s390_regmap_vxrs_low[] = |
167 | { | |
168 | { 16, S390_V0_LOWER_REGNUM, 8 }, | |
169 | { 0 } | |
170 | }; | |
550bdf96 | 171 | |
d6e58945 PR |
172 | static const struct regcache_map_entry s390_regmap_vxrs_high[] = |
173 | { | |
174 | { 16, S390_V16_REGNUM, 16 }, | |
175 | { 0 } | |
176 | }; | |
7803799a | 177 | |
d6e58945 PR |
178 | static const struct regcache_map_entry s390_regmap_gs[] = |
179 | { | |
180 | { 1, REGCACHE_MAP_SKIP, 8 }, | |
181 | { 1, S390_GSD_REGNUM, 8 }, | |
182 | { 1, S390_GSSM_REGNUM, 8 }, | |
183 | { 1, S390_GSEPLA_REGNUM, 8 }, | |
184 | { 0 } | |
185 | }; | |
d0f54f9d | 186 | |
d6e58945 PR |
187 | static const struct regcache_map_entry s390_regmap_gsbc[] = |
188 | { | |
189 | { 1, REGCACHE_MAP_SKIP, 8 }, | |
190 | { 1, S390_BC_GSD_REGNUM, 8 }, | |
191 | { 1, S390_BC_GSSM_REGNUM, 8 }, | |
192 | { 1, S390_BC_GSEPLA_REGNUM, 8 }, | |
193 | { 0 } | |
194 | }; | |
550bdf96 | 195 | |
d0f54f9d | 196 | |
d6e58945 PR |
197 | /* Supply the TDB regset. Like regcache_supply_regset, but invalidate |
198 | the TDB registers unless the TDB format field is valid. */ | |
d0f54f9d | 199 | |
d6e58945 PR |
200 | static void |
201 | s390_supply_tdb_regset (const struct regset *regset, struct regcache *regcache, | |
202 | int regnum, const void *regs, size_t len) | |
7803799a | 203 | { |
d6e58945 PR |
204 | ULONGEST tdw; |
205 | enum register_status ret; | |
d0f54f9d | 206 | |
d6e58945 PR |
207 | regcache_supply_regset (regset, regcache, regnum, regs, len); |
208 | ret = regcache_cooked_read_unsigned (regcache, S390_TDB_DWORD0_REGNUM, &tdw); | |
209 | if (ret != REG_VALID || (tdw >> 56) != 1) | |
210 | regcache_supply_regset (regset, regcache, regnum, NULL, len); | |
211 | } | |
d0f54f9d | 212 | |
d6e58945 PR |
213 | const struct regset s390_gregset = { |
214 | s390_gregmap, | |
215 | regcache_supply_regset, | |
216 | regcache_collect_regset | |
217 | }; | |
7803799a | 218 | |
d6e58945 PR |
219 | const struct regset s390_fpregset = { |
220 | s390_fpregmap, | |
221 | regcache_supply_regset, | |
222 | regcache_collect_regset | |
223 | }; | |
2ccd1468 | 224 | |
d6e58945 PR |
225 | static const struct regset s390_upper_regset = { |
226 | s390_regmap_upper, | |
227 | regcache_supply_regset, | |
228 | regcache_collect_regset | |
229 | }; | |
550bdf96 | 230 | |
d6e58945 PR |
231 | const struct regset s390_last_break_regset = { |
232 | s390_regmap_last_break, | |
233 | regcache_supply_regset, | |
234 | regcache_collect_regset | |
235 | }; | |
550bdf96 | 236 | |
d6e58945 PR |
237 | const struct regset s390x_last_break_regset = { |
238 | s390x_regmap_last_break, | |
239 | regcache_supply_regset, | |
240 | regcache_collect_regset | |
241 | }; | |
550bdf96 | 242 | |
d6e58945 PR |
243 | const struct regset s390_system_call_regset = { |
244 | s390_regmap_system_call, | |
245 | regcache_supply_regset, | |
246 | regcache_collect_regset | |
247 | }; | |
550bdf96 | 248 | |
d6e58945 PR |
249 | const struct regset s390_tdb_regset = { |
250 | s390_regmap_tdb, | |
251 | s390_supply_tdb_regset, | |
252 | regcache_collect_regset | |
253 | }; | |
d0f54f9d | 254 | |
d6e58945 PR |
255 | const struct regset s390_vxrs_low_regset = { |
256 | s390_regmap_vxrs_low, | |
257 | regcache_supply_regset, | |
258 | regcache_collect_regset | |
259 | }; | |
d0f54f9d | 260 | |
d6e58945 PR |
261 | const struct regset s390_vxrs_high_regset = { |
262 | s390_regmap_vxrs_high, | |
263 | regcache_supply_regset, | |
264 | regcache_collect_regset | |
265 | }; | |
d0f54f9d | 266 | |
d6e58945 PR |
267 | const struct regset s390_gs_regset = { |
268 | s390_regmap_gs, | |
269 | regcache_supply_regset, | |
270 | regcache_collect_regset | |
271 | }; | |
7803799a | 272 | |
d6e58945 PR |
273 | const struct regset s390_gsbc_regset = { |
274 | s390_regmap_gsbc, | |
275 | regcache_supply_regset, | |
276 | regcache_collect_regset | |
277 | }; | |
550bdf96 | 278 | |
d6e58945 | 279 | /* Iterate over supported core file register note sections. */ |
d0f54f9d | 280 | |
d6e58945 PR |
281 | static void |
282 | s390_iterate_over_regset_sections (struct gdbarch *gdbarch, | |
283 | iterate_over_regset_sections_cb *cb, | |
284 | void *cb_data, | |
285 | const struct regcache *regcache) | |
5769d3cd | 286 | { |
7803799a | 287 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
d6e58945 PR |
288 | const int gregset_size = (tdep->abi == ABI_LINUX_S390 ? |
289 | s390_sizeof_gregset : s390x_sizeof_gregset); | |
d0f54f9d | 290 | |
d6e58945 PR |
291 | cb (".reg", gregset_size, &s390_gregset, NULL, cb_data); |
292 | cb (".reg2", s390_sizeof_fpregset, &s390_fpregset, NULL, cb_data); | |
d0f54f9d | 293 | |
d6e58945 PR |
294 | if (tdep->abi == ABI_LINUX_S390 && tdep->gpr_full_regnum != -1) |
295 | cb (".reg-s390-high-gprs", 16 * 4, &s390_upper_regset, | |
296 | "s390 GPR upper halves", cb_data); | |
7803799a | 297 | |
d6e58945 PR |
298 | if (tdep->have_linux_v1) |
299 | cb (".reg-s390-last-break", 8, | |
300 | (gdbarch_ptr_bit (gdbarch) == 32 | |
301 | ? &s390_last_break_regset : &s390x_last_break_regset), | |
302 | "s390 last-break address", cb_data); | |
550bdf96 | 303 | |
d6e58945 PR |
304 | if (tdep->have_linux_v2) |
305 | cb (".reg-s390-system-call", 4, &s390_system_call_regset, | |
306 | "s390 system-call", cb_data); | |
5769d3cd | 307 | |
d6e58945 PR |
308 | /* If regcache is set, we are in "write" (gcore) mode. In this |
309 | case, don't iterate over the TDB unless its registers are | |
310 | available. */ | |
311 | if (tdep->have_tdb | |
312 | && (regcache == NULL | |
313 | || REG_VALID == regcache_register_status (regcache, | |
314 | S390_TDB_DWORD0_REGNUM))) | |
315 | cb (".reg-s390-tdb", s390_sizeof_tdbregset, &s390_tdb_regset, | |
316 | "s390 TDB", cb_data); | |
d0f54f9d | 317 | |
d6e58945 | 318 | if (tdep->v0_full_regnum != -1) |
d0f54f9d | 319 | { |
d6e58945 PR |
320 | cb (".reg-s390-vxrs-low", 16 * 8, &s390_vxrs_low_regset, |
321 | "s390 vector registers 0-15 lower half", cb_data); | |
322 | cb (".reg-s390-vxrs-high", 16 * 16, &s390_vxrs_high_regset, | |
323 | "s390 vector registers 16-31", cb_data); | |
7803799a | 324 | } |
d0f54f9d | 325 | |
d6e58945 PR |
326 | /* Iterate over the guarded-storage regsets if in "read" mode, or if |
327 | their registers are available. */ | |
328 | if (tdep->have_gs) | |
7803799a | 329 | { |
d6e58945 PR |
330 | if (regcache == NULL |
331 | || REG_VALID == regcache_register_status (regcache, | |
332 | S390_GSD_REGNUM)) | |
333 | cb (".reg-s390-gs-cb", 4 * 8, &s390_gs_regset, | |
334 | "s390 guarded-storage registers", cb_data); | |
7803799a | 335 | |
d6e58945 PR |
336 | if (regcache == NULL |
337 | || REG_VALID == regcache_register_status (regcache, | |
338 | S390_BC_GSD_REGNUM)) | |
339 | cb (".reg-s390-gs-bc", 4 * 8, &s390_gsbc_regset, | |
340 | "s390 guarded-storage broadcast control", cb_data); | |
550bdf96 | 341 | } |
d0f54f9d JB |
342 | } |
343 | ||
d6e58945 PR |
344 | static const struct target_desc * |
345 | s390_core_read_description (struct gdbarch *gdbarch, | |
346 | struct target_ops *target, bfd *abfd) | |
d0f54f9d | 347 | { |
d6e58945 PR |
348 | asection *section = bfd_get_section_by_name (abfd, ".reg"); |
349 | CORE_ADDR hwcap = 0; | |
350 | bool high_gprs, v1, v2, te, vx, gs; | |
c4b3e547 | 351 | |
d6e58945 PR |
352 | target_auxv_search (target, AT_HWCAP, &hwcap); |
353 | if (!section) | |
354 | return NULL; | |
c4b3e547 | 355 | |
d6e58945 PR |
356 | high_gprs = (bfd_get_section_by_name (abfd, ".reg-s390-high-gprs") |
357 | != NULL); | |
358 | v1 = (bfd_get_section_by_name (abfd, ".reg-s390-last-break") != NULL); | |
359 | v2 = (bfd_get_section_by_name (abfd, ".reg-s390-system-call") != NULL); | |
360 | vx = (hwcap & HWCAP_S390_VX); | |
361 | te = (hwcap & HWCAP_S390_TE); | |
362 | gs = (hwcap & HWCAP_S390_GS); | |
c4b3e547 | 363 | |
d6e58945 | 364 | switch (bfd_section_size (abfd, section)) |
c4b3e547 | 365 | { |
d6e58945 PR |
366 | case s390_sizeof_gregset: |
367 | if (high_gprs) | |
368 | return (gs ? tdesc_s390_gs_linux64 : | |
369 | te && vx ? tdesc_s390_tevx_linux64 : | |
370 | vx ? tdesc_s390_vx_linux64 : | |
371 | te ? tdesc_s390_te_linux64 : | |
372 | v2 ? tdesc_s390_linux64v2 : | |
373 | v1 ? tdesc_s390_linux64v1 : tdesc_s390_linux64); | |
c4b3e547 | 374 | else |
d6e58945 PR |
375 | return (v2 ? tdesc_s390_linux32v2 : |
376 | v1 ? tdesc_s390_linux32v1 : tdesc_s390_linux32); | |
550bdf96 | 377 | |
d6e58945 PR |
378 | case s390x_sizeof_gregset: |
379 | return (gs ? tdesc_s390x_gs_linux64 : | |
380 | te && vx ? tdesc_s390x_tevx_linux64 : | |
381 | vx ? tdesc_s390x_vx_linux64 : | |
382 | te ? tdesc_s390x_te_linux64 : | |
383 | v2 ? tdesc_s390x_linux64v2 : | |
384 | v1 ? tdesc_s390x_linux64v1 : tdesc_s390x_linux64); | |
7803799a UW |
385 | |
386 | default: | |
d6e58945 PR |
387 | return NULL; |
388 | } | |
389 | } | |
5769d3cd | 390 | |
a8c99f38 | 391 | /* Signal trampoline stack frames. */ |
5769d3cd | 392 | |
a8c99f38 JB |
393 | struct s390_sigtramp_unwind_cache { |
394 | CORE_ADDR frame_base; | |
395 | struct trad_frame_saved_reg *saved_regs; | |
396 | }; | |
5769d3cd | 397 | |
a8c99f38 | 398 | static struct s390_sigtramp_unwind_cache * |
f089c433 | 399 | s390_sigtramp_frame_unwind_cache (struct frame_info *this_frame, |
a8c99f38 | 400 | void **this_prologue_cache) |
5769d3cd | 401 | { |
f089c433 | 402 | struct gdbarch *gdbarch = get_frame_arch (this_frame); |
7803799a | 403 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
a8c99f38 | 404 | int word_size = gdbarch_ptr_bit (gdbarch) / 8; |
e17a4113 | 405 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); |
a8c99f38 JB |
406 | struct s390_sigtramp_unwind_cache *info; |
407 | ULONGEST this_sp, prev_sp; | |
7803799a | 408 | CORE_ADDR next_ra, next_cfa, sigreg_ptr, sigreg_high_off; |
a8c99f38 JB |
409 | int i; |
410 | ||
411 | if (*this_prologue_cache) | |
19ba03f4 | 412 | return (struct s390_sigtramp_unwind_cache *) *this_prologue_cache; |
5769d3cd | 413 | |
a8c99f38 JB |
414 | info = FRAME_OBSTACK_ZALLOC (struct s390_sigtramp_unwind_cache); |
415 | *this_prologue_cache = info; | |
f089c433 | 416 | info->saved_regs = trad_frame_alloc_saved_regs (this_frame); |
a8c99f38 | 417 | |
f089c433 UW |
418 | this_sp = get_frame_register_unsigned (this_frame, S390_SP_REGNUM); |
419 | next_ra = get_frame_pc (this_frame); | |
a8c99f38 JB |
420 | next_cfa = this_sp + 16*word_size + 32; |
421 | ||
422 | /* New-style RT frame: | |
423 | retcode + alignment (8 bytes) | |
424 | siginfo (128 bytes) | |
c378eb4e | 425 | ucontext (contains sigregs at offset 5 words). */ |
a8c99f38 JB |
426 | if (next_ra == next_cfa) |
427 | { | |
f0f63663 | 428 | sigreg_ptr = next_cfa + 8 + 128 + align_up (5*word_size, 8); |
7803799a UW |
429 | /* sigregs are followed by uc_sigmask (8 bytes), then by the |
430 | upper GPR halves if present. */ | |
431 | sigreg_high_off = 8; | |
a8c99f38 JB |
432 | } |
433 | ||
434 | /* Old-style RT frame and all non-RT frames: | |
435 | old signal mask (8 bytes) | |
c378eb4e | 436 | pointer to sigregs. */ |
5769d3cd AC |
437 | else |
438 | { | |
e17a4113 UW |
439 | sigreg_ptr = read_memory_unsigned_integer (next_cfa + 8, |
440 | word_size, byte_order); | |
7803799a UW |
441 | /* sigregs are followed by signo (4 bytes), then by the |
442 | upper GPR halves if present. */ | |
443 | sigreg_high_off = 4; | |
a8c99f38 | 444 | } |
5769d3cd | 445 | |
a8c99f38 | 446 | /* The sigregs structure looks like this: |
34201ae3 UW |
447 | long psw_mask; |
448 | long psw_addr; | |
449 | long gprs[16]; | |
450 | int acrs[16]; | |
451 | int fpc; | |
452 | int __pad; | |
453 | double fprs[16]; */ | |
5769d3cd | 454 | |
7803799a UW |
455 | /* PSW mask and address. */ |
456 | info->saved_regs[S390_PSWM_REGNUM].addr = sigreg_ptr; | |
a8c99f38 | 457 | sigreg_ptr += word_size; |
7803799a | 458 | info->saved_regs[S390_PSWA_REGNUM].addr = sigreg_ptr; |
a8c99f38 JB |
459 | sigreg_ptr += word_size; |
460 | ||
461 | /* Then the GPRs. */ | |
462 | for (i = 0; i < 16; i++) | |
463 | { | |
464 | info->saved_regs[S390_R0_REGNUM + i].addr = sigreg_ptr; | |
465 | sigreg_ptr += word_size; | |
466 | } | |
467 | ||
468 | /* Then the ACRs. */ | |
469 | for (i = 0; i < 16; i++) | |
470 | { | |
471 | info->saved_regs[S390_A0_REGNUM + i].addr = sigreg_ptr; | |
472 | sigreg_ptr += 4; | |
5769d3cd | 473 | } |
5769d3cd | 474 | |
a8c99f38 JB |
475 | /* The floating-point control word. */ |
476 | info->saved_regs[S390_FPC_REGNUM].addr = sigreg_ptr; | |
477 | sigreg_ptr += 8; | |
5769d3cd | 478 | |
a8c99f38 JB |
479 | /* And finally the FPRs. */ |
480 | for (i = 0; i < 16; i++) | |
481 | { | |
482 | info->saved_regs[S390_F0_REGNUM + i].addr = sigreg_ptr; | |
483 | sigreg_ptr += 8; | |
484 | } | |
485 | ||
7803799a UW |
486 | /* If we have them, the GPR upper halves are appended at the end. */ |
487 | sigreg_ptr += sigreg_high_off; | |
488 | if (tdep->gpr_full_regnum != -1) | |
489 | for (i = 0; i < 16; i++) | |
490 | { | |
34201ae3 | 491 | info->saved_regs[S390_R0_UPPER_REGNUM + i].addr = sigreg_ptr; |
7803799a UW |
492 | sigreg_ptr += 4; |
493 | } | |
494 | ||
a8c99f38 JB |
495 | /* Restore the previous frame's SP. */ |
496 | prev_sp = read_memory_unsigned_integer ( | |
497 | info->saved_regs[S390_SP_REGNUM].addr, | |
e17a4113 | 498 | word_size, byte_order); |
5769d3cd | 499 | |
a8c99f38 JB |
500 | /* Determine our frame base. */ |
501 | info->frame_base = prev_sp + 16*word_size + 32; | |
5769d3cd | 502 | |
a8c99f38 | 503 | return info; |
5769d3cd AC |
504 | } |
505 | ||
a8c99f38 | 506 | static void |
f089c433 | 507 | s390_sigtramp_frame_this_id (struct frame_info *this_frame, |
a8c99f38 JB |
508 | void **this_prologue_cache, |
509 | struct frame_id *this_id) | |
5769d3cd | 510 | { |
a8c99f38 | 511 | struct s390_sigtramp_unwind_cache *info |
f089c433 UW |
512 | = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache); |
513 | *this_id = frame_id_build (info->frame_base, get_frame_pc (this_frame)); | |
5769d3cd AC |
514 | } |
515 | ||
f089c433 UW |
516 | static struct value * |
517 | s390_sigtramp_frame_prev_register (struct frame_info *this_frame, | |
518 | void **this_prologue_cache, int regnum) | |
a8c99f38 JB |
519 | { |
520 | struct s390_sigtramp_unwind_cache *info | |
f089c433 | 521 | = s390_sigtramp_frame_unwind_cache (this_frame, this_prologue_cache); |
d6db1fab | 522 | return s390_trad_frame_prev_register (this_frame, info->saved_regs, regnum); |
a8c99f38 JB |
523 | } |
524 | ||
f089c433 UW |
525 | static int |
526 | s390_sigtramp_frame_sniffer (const struct frame_unwind *self, | |
527 | struct frame_info *this_frame, | |
528 | void **this_prologue_cache) | |
5769d3cd | 529 | { |
f089c433 | 530 | CORE_ADDR pc = get_frame_pc (this_frame); |
a8c99f38 | 531 | bfd_byte sigreturn[2]; |
4c8287ac | 532 | |
8defab1a | 533 | if (target_read_memory (pc, sigreturn, 2)) |
f089c433 | 534 | return 0; |
4c8287ac | 535 | |
237b092b | 536 | if (sigreturn[0] != op_svc) |
f089c433 | 537 | return 0; |
5769d3cd | 538 | |
a8c99f38 JB |
539 | if (sigreturn[1] != 119 /* sigreturn */ |
540 | && sigreturn[1] != 173 /* rt_sigreturn */) | |
f089c433 | 541 | return 0; |
34201ae3 | 542 | |
f089c433 | 543 | return 1; |
5769d3cd AC |
544 | } |
545 | ||
f089c433 UW |
546 | static const struct frame_unwind s390_sigtramp_frame_unwind = { |
547 | SIGTRAMP_FRAME, | |
8fbca658 | 548 | default_frame_unwind_stop_reason, |
f089c433 UW |
549 | s390_sigtramp_frame_this_id, |
550 | s390_sigtramp_frame_prev_register, | |
551 | NULL, | |
552 | s390_sigtramp_frame_sniffer | |
553 | }; | |
554 | ||
237b092b AA |
555 | /* Retrieve the syscall number at a ptrace syscall-stop. Return -1 |
556 | upon error. */ | |
557 | ||
558 | static LONGEST | |
559 | s390_linux_get_syscall_number (struct gdbarch *gdbarch, | |
560 | ptid_t ptid) | |
561 | { | |
562 | struct regcache *regs = get_thread_regcache (ptid); | |
563 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
564 | enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); | |
565 | ULONGEST pc; | |
566 | ULONGEST svc_number = -1; | |
567 | unsigned opcode; | |
568 | ||
569 | /* Assume that the PC points after the 2-byte SVC instruction. We | |
570 | don't currently support SVC via EXECUTE. */ | |
571 | regcache_cooked_read_unsigned (regs, tdep->pc_regnum, &pc); | |
572 | pc -= 2; | |
573 | opcode = read_memory_unsigned_integer ((CORE_ADDR) pc, 1, byte_order); | |
574 | if (opcode != op_svc) | |
575 | return -1; | |
576 | ||
577 | svc_number = read_memory_unsigned_integer ((CORE_ADDR) pc + 1, 1, | |
578 | byte_order); | |
579 | if (svc_number == 0) | |
580 | regcache_cooked_read_unsigned (regs, S390_R1_REGNUM, &svc_number); | |
581 | ||
582 | return svc_number; | |
583 | } | |
584 | ||
566c56c9 MK |
585 | /* Process record-replay */ |
586 | ||
587 | static struct linux_record_tdep s390_linux_record_tdep; | |
588 | static struct linux_record_tdep s390x_linux_record_tdep; | |
589 | ||
590 | /* Record all registers but PC register for process-record. */ | |
591 | ||
592 | static int | |
593 | s390_all_but_pc_registers_record (struct regcache *regcache) | |
594 | { | |
ac7936df | 595 | struct gdbarch *gdbarch = regcache->arch (); |
566c56c9 MK |
596 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
597 | int i; | |
598 | ||
599 | for (i = 0; i < 16; i++) | |
600 | { | |
601 | if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i)) | |
602 | return -1; | |
603 | if (record_full_arch_list_add_reg (regcache, S390_A0_REGNUM + i)) | |
604 | return -1; | |
605 | if (record_full_arch_list_add_reg (regcache, S390_F0_REGNUM + i)) | |
606 | return -1; | |
607 | if (tdep->gpr_full_regnum != -1) | |
608 | if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i)) | |
609 | return -1; | |
610 | if (tdep->v0_full_regnum != -1) | |
611 | { | |
612 | if (record_full_arch_list_add_reg (regcache, S390_V0_LOWER_REGNUM + i)) | |
613 | return -1; | |
614 | if (record_full_arch_list_add_reg (regcache, S390_V16_REGNUM + i)) | |
615 | return -1; | |
616 | } | |
617 | } | |
618 | if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM)) | |
619 | return -1; | |
620 | if (record_full_arch_list_add_reg (regcache, S390_FPC_REGNUM)) | |
621 | return -1; | |
622 | ||
623 | return 0; | |
624 | } | |
625 | ||
626 | static enum gdb_syscall | |
627 | s390_canonicalize_syscall (int syscall, enum s390_abi_kind abi) | |
628 | { | |
629 | switch (syscall) | |
630 | { | |
631 | /* s390 syscall numbers < 222 are mostly the same as x86, so just list | |
632 | the exceptions. */ | |
633 | case 0: | |
634 | return gdb_sys_no_syscall; | |
635 | case 7: | |
636 | return gdb_sys_restart_syscall; | |
637 | /* These syscalls work only on 31-bit. */ | |
638 | case 13: /* time */ | |
639 | case 16: /* lchown[16] */ | |
640 | case 23: /* setuid[16] */ | |
641 | case 24: /* getuid[16] */ | |
642 | case 25: /* stime */ | |
643 | case 46: /* setgid[16] */ | |
644 | case 47: /* getgid[16] */ | |
645 | case 49: /* seteuid[16] */ | |
646 | case 50: /* getegid[16] */ | |
647 | case 70: /* setreuid[16] */ | |
648 | case 71: /* setregid[16] */ | |
649 | case 76: /* [old_]getrlimit */ | |
650 | case 80: /* getgroups[16] */ | |
651 | case 81: /* setgroups[16] */ | |
652 | case 95: /* fchown[16] */ | |
653 | case 101: /* ioperm */ | |
654 | case 138: /* setfsuid[16] */ | |
655 | case 139: /* setfsgid[16] */ | |
656 | case 140: /* _llseek */ | |
657 | case 164: /* setresuid[16] */ | |
658 | case 165: /* getresuid[16] */ | |
659 | case 170: /* setresgid[16] */ | |
660 | case 171: /* getresgid[16] */ | |
661 | case 182: /* chown[16] */ | |
662 | case 192: /* mmap2 */ | |
663 | case 193: /* truncate64 */ | |
664 | case 194: /* ftruncate64 */ | |
665 | case 195: /* stat64 */ | |
666 | case 196: /* lstat64 */ | |
667 | case 197: /* fstat64 */ | |
668 | case 221: /* fcntl64 */ | |
669 | if (abi == ABI_LINUX_S390) | |
4d193179 | 670 | return (enum gdb_syscall) syscall; |
566c56c9 MK |
671 | return gdb_sys_no_syscall; |
672 | /* These syscalls don't exist on s390. */ | |
673 | case 17: /* break */ | |
674 | case 18: /* oldstat */ | |
675 | case 28: /* oldfstat */ | |
676 | case 31: /* stty */ | |
677 | case 32: /* gtty */ | |
678 | case 35: /* ftime */ | |
679 | case 44: /* prof */ | |
680 | case 53: /* lock */ | |
681 | case 56: /* mpx */ | |
682 | case 58: /* ulimit */ | |
683 | case 59: /* oldolduname */ | |
684 | case 68: /* sgetmask */ | |
685 | case 69: /* ssetmask */ | |
686 | case 82: /* [old_]select */ | |
687 | case 84: /* oldlstat */ | |
688 | case 98: /* profil */ | |
689 | case 109: /* olduname */ | |
690 | case 113: /* vm86old */ | |
691 | case 123: /* modify_ldt */ | |
692 | case 166: /* vm86 */ | |
693 | return gdb_sys_no_syscall; | |
694 | case 110: | |
695 | return gdb_sys_lookup_dcookie; | |
696 | /* Here come the differences. */ | |
697 | case 222: | |
698 | return gdb_sys_readahead; | |
699 | case 223: | |
700 | if (abi == ABI_LINUX_S390) | |
701 | return gdb_sys_sendfile64; | |
702 | return gdb_sys_no_syscall; | |
703 | /* 224-235 handled below */ | |
704 | case 236: | |
705 | return gdb_sys_gettid; | |
706 | case 237: | |
707 | return gdb_sys_tkill; | |
708 | case 238: | |
709 | return gdb_sys_futex; | |
710 | case 239: | |
711 | return gdb_sys_sched_setaffinity; | |
712 | case 240: | |
713 | return gdb_sys_sched_getaffinity; | |
714 | case 241: | |
715 | return gdb_sys_tgkill; | |
716 | /* 242 reserved */ | |
717 | case 243: | |
718 | return gdb_sys_io_setup; | |
719 | case 244: | |
720 | return gdb_sys_io_destroy; | |
721 | case 245: | |
722 | return gdb_sys_io_getevents; | |
723 | case 246: | |
724 | return gdb_sys_io_submit; | |
725 | case 247: | |
726 | return gdb_sys_io_cancel; | |
727 | case 248: | |
728 | return gdb_sys_exit_group; | |
729 | case 249: | |
730 | return gdb_sys_epoll_create; | |
731 | case 250: | |
732 | return gdb_sys_epoll_ctl; | |
733 | case 251: | |
734 | return gdb_sys_epoll_wait; | |
735 | case 252: | |
736 | return gdb_sys_set_tid_address; | |
737 | case 253: | |
738 | return gdb_sys_fadvise64; | |
739 | /* 254-262 handled below */ | |
740 | /* 263 reserved */ | |
741 | case 264: | |
742 | if (abi == ABI_LINUX_S390) | |
743 | return gdb_sys_fadvise64_64; | |
744 | return gdb_sys_no_syscall; | |
745 | case 265: | |
746 | return gdb_sys_statfs64; | |
747 | case 266: | |
748 | return gdb_sys_fstatfs64; | |
749 | case 267: | |
750 | return gdb_sys_remap_file_pages; | |
751 | /* 268-270 reserved */ | |
752 | /* 271-277 handled below */ | |
753 | case 278: | |
754 | return gdb_sys_add_key; | |
755 | case 279: | |
756 | return gdb_sys_request_key; | |
757 | case 280: | |
758 | return gdb_sys_keyctl; | |
759 | case 281: | |
760 | return gdb_sys_waitid; | |
761 | /* 282-312 handled below */ | |
762 | case 293: | |
763 | if (abi == ABI_LINUX_S390) | |
764 | return gdb_sys_fstatat64; | |
765 | return gdb_sys_newfstatat; | |
766 | /* 313+ not yet supported */ | |
d6e58945 PR |
767 | default: |
768 | { | |
769 | int ret; | |
78f8b424 | 770 | |
d6e58945 PR |
771 | /* Most "old" syscalls copied from i386. */ |
772 | if (syscall <= 221) | |
773 | ret = syscall; | |
774 | /* xattr syscalls. */ | |
775 | else if (syscall >= 224 && syscall <= 235) | |
776 | ret = syscall + 2; | |
777 | /* timer syscalls. */ | |
778 | else if (syscall >= 254 && syscall <= 262) | |
779 | ret = syscall + 5; | |
780 | /* mq_* and kexec_load */ | |
781 | else if (syscall >= 271 && syscall <= 277) | |
782 | ret = syscall + 6; | |
783 | /* ioprio_set .. epoll_pwait */ | |
784 | else if (syscall >= 282 && syscall <= 312) | |
785 | ret = syscall + 7; | |
786 | else | |
787 | ret = gdb_sys_no_syscall; | |
80f75320 | 788 | |
d6e58945 PR |
789 | return (enum gdb_syscall) ret; |
790 | } | |
8de7d199 | 791 | } |
4074e13c JB |
792 | } |
793 | ||
d6e58945 PR |
794 | static int |
795 | s390_linux_syscall_record (struct regcache *regcache, LONGEST syscall_native) | |
c8f9d51c | 796 | { |
d6e58945 PR |
797 | struct gdbarch *gdbarch = regcache->arch (); |
798 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
799 | int ret; | |
800 | enum gdb_syscall syscall_gdb; | |
4e65a17e | 801 | |
d6e58945 PR |
802 | /* On s390, syscall number can be passed either as immediate field of svc |
803 | instruction, or in %r1 (with svc 0). */ | |
804 | if (syscall_native == 0) | |
805 | regcache_raw_read_signed (regcache, S390_R1_REGNUM, &syscall_native); | |
56b9d9ac | 806 | |
d6e58945 | 807 | syscall_gdb = s390_canonicalize_syscall (syscall_native, tdep->abi); |
56b9d9ac | 808 | |
d6e58945 | 809 | if (syscall_gdb < 0) |
b0cf273e | 810 | { |
d6e58945 PR |
811 | printf_unfiltered (_("Process record and replay target doesn't " |
812 | "support syscall number %s\n"), | |
813 | plongest (syscall_native)); | |
814 | return -1; | |
b0cf273e | 815 | } |
5769d3cd | 816 | |
d6e58945 PR |
817 | if (syscall_gdb == gdb_sys_sigreturn |
818 | || syscall_gdb == gdb_sys_rt_sigreturn) | |
4e65a17e | 819 | { |
d6e58945 PR |
820 | if (s390_all_but_pc_registers_record (regcache)) |
821 | return -1; | |
822 | return 0; | |
b0cf273e JB |
823 | } |
824 | ||
d6e58945 PR |
825 | if (tdep->abi == ABI_LINUX_ZSERIES) |
826 | ret = record_linux_system_call (syscall_gdb, regcache, | |
827 | &s390x_linux_record_tdep); | |
828 | else | |
829 | ret = record_linux_system_call (syscall_gdb, regcache, | |
830 | &s390_linux_record_tdep); | |
a8c99f38 | 831 | |
d6e58945 PR |
832 | if (ret) |
833 | return ret; | |
5769d3cd | 834 | |
d6e58945 PR |
835 | /* Record the return value of the system call. */ |
836 | if (record_full_arch_list_add_reg (regcache, S390_R2_REGNUM)) | |
837 | return -1; | |
5769d3cd | 838 | |
d6e58945 | 839 | return 0; |
5769d3cd AC |
840 | } |
841 | ||
ffc65945 | 842 | static int |
d6e58945 PR |
843 | s390_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache, |
844 | enum gdb_signal signal) | |
ffc65945 | 845 | { |
d6e58945 PR |
846 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
847 | /* There are two kinds of signal frames on s390. rt_sigframe is always | |
848 | the larger one, so don't even bother with sigframe. */ | |
849 | const int sizeof_rt_sigframe = (tdep->abi == ABI_LINUX_ZSERIES ? | |
850 | 160 + 8 + 128 + 1024 : 96 + 8 + 128 + 1000); | |
851 | ULONGEST sp; | |
852 | int i; | |
ffc65945 | 853 | |
d6e58945 | 854 | for (i = 0; i < 16; i++) |
ffc65945 | 855 | { |
d6e58945 PR |
856 | if (record_full_arch_list_add_reg (regcache, S390_R0_REGNUM + i)) |
857 | return -1; | |
858 | if (tdep->gpr_full_regnum != -1) | |
859 | if (record_full_arch_list_add_reg (regcache, S390_R0_UPPER_REGNUM + i)) | |
860 | return -1; | |
ffc65945 | 861 | } |
d6e58945 PR |
862 | if (record_full_arch_list_add_reg (regcache, S390_PSWA_REGNUM)) |
863 | return -1; | |
864 | if (record_full_arch_list_add_reg (regcache, S390_PSWM_REGNUM)) | |
865 | return -1; | |
60abeae4 | 866 | |
d6e58945 PR |
867 | /* Record the change in the stack. |
868 | frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */ | |
869 | regcache_raw_read_unsigned (regcache, S390_SP_REGNUM, &sp); | |
870 | sp -= sizeof_rt_sigframe; | |
60abeae4 | 871 | |
d6e58945 PR |
872 | if (record_full_arch_list_add_mem (sp, sizeof_rt_sigframe)) |
873 | return -1; | |
a2658feb | 874 | |
d6e58945 PR |
875 | if (record_full_arch_list_add_end ()) |
876 | return -1; | |
55aa24fb | 877 | |
d6e58945 | 878 | return 0; |
55aa24fb SDJ |
879 | } |
880 | ||
566c56c9 MK |
881 | /* Initialize linux_record_tdep if not initialized yet. */ |
882 | ||
883 | static void | |
884 | s390_init_linux_record_tdep (struct linux_record_tdep *record_tdep, | |
885 | enum s390_abi_kind abi) | |
886 | { | |
887 | /* These values are the size of the type that will be used in a system | |
888 | call. They are obtained from Linux Kernel source. */ | |
889 | ||
890 | if (abi == ABI_LINUX_ZSERIES) | |
891 | { | |
892 | record_tdep->size_pointer = 8; | |
893 | /* no _old_kernel_stat */ | |
894 | record_tdep->size_tms = 32; | |
895 | record_tdep->size_loff_t = 8; | |
896 | record_tdep->size_flock = 32; | |
897 | record_tdep->size_ustat = 32; | |
898 | record_tdep->size_old_sigaction = 32; | |
899 | record_tdep->size_old_sigset_t = 8; | |
900 | record_tdep->size_rlimit = 16; | |
901 | record_tdep->size_rusage = 144; | |
902 | record_tdep->size_timeval = 16; | |
903 | record_tdep->size_timezone = 8; | |
904 | /* old_[ug]id_t never used */ | |
905 | record_tdep->size_fd_set = 128; | |
906 | record_tdep->size_old_dirent = 280; | |
907 | record_tdep->size_statfs = 88; | |
908 | record_tdep->size_statfs64 = 88; | |
909 | record_tdep->size_sockaddr = 16; | |
910 | record_tdep->size_int = 4; | |
911 | record_tdep->size_long = 8; | |
912 | record_tdep->size_ulong = 8; | |
913 | record_tdep->size_msghdr = 56; | |
914 | record_tdep->size_itimerval = 32; | |
915 | record_tdep->size_stat = 144; | |
916 | /* old_utsname unused */ | |
917 | record_tdep->size_sysinfo = 112; | |
918 | record_tdep->size_msqid_ds = 120; | |
919 | record_tdep->size_shmid_ds = 112; | |
920 | record_tdep->size_new_utsname = 390; | |
921 | record_tdep->size_timex = 208; | |
922 | record_tdep->size_mem_dqinfo = 24; | |
923 | record_tdep->size_if_dqblk = 72; | |
924 | record_tdep->size_fs_quota_stat = 80; | |
925 | record_tdep->size_timespec = 16; | |
926 | record_tdep->size_pollfd = 8; | |
927 | record_tdep->size_NFS_FHSIZE = 32; | |
928 | record_tdep->size_knfsd_fh = 132; | |
929 | record_tdep->size_TASK_COMM_LEN = 16; | |
930 | record_tdep->size_sigaction = 32; | |
931 | record_tdep->size_sigset_t = 8; | |
932 | record_tdep->size_siginfo_t = 128; | |
933 | record_tdep->size_cap_user_data_t = 12; | |
934 | record_tdep->size_stack_t = 24; | |
935 | record_tdep->size_off_t = 8; | |
936 | /* stat64 unused */ | |
937 | record_tdep->size_gid_t = 4; | |
938 | record_tdep->size_uid_t = 4; | |
939 | record_tdep->size_PAGE_SIZE = 0x1000; /* 4KB */ | |
940 | record_tdep->size_flock64 = 32; | |
941 | record_tdep->size_io_event = 32; | |
942 | record_tdep->size_iocb = 64; | |
943 | record_tdep->size_epoll_event = 16; | |
944 | record_tdep->size_itimerspec = 32; | |
945 | record_tdep->size_mq_attr = 64; | |
946 | record_tdep->size_termios = 36; | |
947 | record_tdep->size_termios2 = 44; | |
948 | record_tdep->size_pid_t = 4; | |
949 | record_tdep->size_winsize = 8; | |
950 | record_tdep->size_serial_struct = 72; | |
951 | record_tdep->size_serial_icounter_struct = 80; | |
952 | record_tdep->size_size_t = 8; | |
953 | record_tdep->size_iovec = 16; | |
954 | record_tdep->size_time_t = 8; | |
955 | } | |
956 | else if (abi == ABI_LINUX_S390) | |
957 | { | |
958 | record_tdep->size_pointer = 4; | |
959 | record_tdep->size__old_kernel_stat = 32; | |
960 | record_tdep->size_tms = 16; | |
961 | record_tdep->size_loff_t = 8; | |
962 | record_tdep->size_flock = 16; | |
963 | record_tdep->size_ustat = 20; | |
964 | record_tdep->size_old_sigaction = 16; | |
965 | record_tdep->size_old_sigset_t = 4; | |
966 | record_tdep->size_rlimit = 8; | |
967 | record_tdep->size_rusage = 72; | |
968 | record_tdep->size_timeval = 8; | |
969 | record_tdep->size_timezone = 8; | |
970 | record_tdep->size_old_gid_t = 2; | |
971 | record_tdep->size_old_uid_t = 2; | |
972 | record_tdep->size_fd_set = 128; | |
973 | record_tdep->size_old_dirent = 268; | |
974 | record_tdep->size_statfs = 64; | |
975 | record_tdep->size_statfs64 = 88; | |
976 | record_tdep->size_sockaddr = 16; | |
977 | record_tdep->size_int = 4; | |
978 | record_tdep->size_long = 4; | |
979 | record_tdep->size_ulong = 4; | |
980 | record_tdep->size_msghdr = 28; | |
981 | record_tdep->size_itimerval = 16; | |
982 | record_tdep->size_stat = 64; | |
983 | /* old_utsname unused */ | |
984 | record_tdep->size_sysinfo = 64; | |
985 | record_tdep->size_msqid_ds = 88; | |
986 | record_tdep->size_shmid_ds = 84; | |
987 | record_tdep->size_new_utsname = 390; | |
988 | record_tdep->size_timex = 128; | |
989 | record_tdep->size_mem_dqinfo = 24; | |
990 | record_tdep->size_if_dqblk = 72; | |
991 | record_tdep->size_fs_quota_stat = 80; | |
992 | record_tdep->size_timespec = 8; | |
993 | record_tdep->size_pollfd = 8; | |
994 | record_tdep->size_NFS_FHSIZE = 32; | |
995 | record_tdep->size_knfsd_fh = 132; | |
996 | record_tdep->size_TASK_COMM_LEN = 16; | |
997 | record_tdep->size_sigaction = 20; | |
998 | record_tdep->size_sigset_t = 8; | |
999 | record_tdep->size_siginfo_t = 128; | |
1000 | record_tdep->size_cap_user_data_t = 12; | |
1001 | record_tdep->size_stack_t = 12; | |
1002 | record_tdep->size_off_t = 4; | |
1003 | record_tdep->size_stat64 = 104; | |
1004 | record_tdep->size_gid_t = 4; | |
1005 | record_tdep->size_uid_t = 4; | |
1006 | record_tdep->size_PAGE_SIZE = 0x1000; /* 4KB */ | |
1007 | record_tdep->size_flock64 = 32; | |
1008 | record_tdep->size_io_event = 32; | |
1009 | record_tdep->size_iocb = 64; | |
1010 | record_tdep->size_epoll_event = 16; | |
1011 | record_tdep->size_itimerspec = 16; | |
1012 | record_tdep->size_mq_attr = 32; | |
1013 | record_tdep->size_termios = 36; | |
1014 | record_tdep->size_termios2 = 44; | |
1015 | record_tdep->size_pid_t = 4; | |
1016 | record_tdep->size_winsize = 8; | |
1017 | record_tdep->size_serial_struct = 60; | |
1018 | record_tdep->size_serial_icounter_struct = 80; | |
1019 | record_tdep->size_size_t = 4; | |
1020 | record_tdep->size_iovec = 8; | |
1021 | record_tdep->size_time_t = 4; | |
1022 | } | |
1023 | ||
1024 | /* These values are the second argument of system call "sys_fcntl" | |
1025 | and "sys_fcntl64". They are obtained from Linux Kernel source. */ | |
1026 | record_tdep->fcntl_F_GETLK = 5; | |
1027 | record_tdep->fcntl_F_GETLK64 = 12; | |
1028 | record_tdep->fcntl_F_SETLK64 = 13; | |
1029 | record_tdep->fcntl_F_SETLKW64 = 14; | |
1030 | ||
1031 | record_tdep->arg1 = S390_R2_REGNUM; | |
1032 | record_tdep->arg2 = S390_R3_REGNUM; | |
1033 | record_tdep->arg3 = S390_R4_REGNUM; | |
1034 | record_tdep->arg4 = S390_R5_REGNUM; | |
1035 | record_tdep->arg5 = S390_R6_REGNUM; | |
1036 | ||
1037 | /* These values are the second argument of system call "sys_ioctl". | |
1038 | They are obtained from Linux Kernel source. | |
1039 | See arch/s390/include/uapi/asm/ioctls.h. */ | |
1040 | ||
1041 | record_tdep->ioctl_TCGETS = 0x5401; | |
1042 | record_tdep->ioctl_TCSETS = 0x5402; | |
1043 | record_tdep->ioctl_TCSETSW = 0x5403; | |
1044 | record_tdep->ioctl_TCSETSF = 0x5404; | |
1045 | record_tdep->ioctl_TCGETA = 0x5405; | |
1046 | record_tdep->ioctl_TCSETA = 0x5406; | |
1047 | record_tdep->ioctl_TCSETAW = 0x5407; | |
1048 | record_tdep->ioctl_TCSETAF = 0x5408; | |
1049 | record_tdep->ioctl_TCSBRK = 0x5409; | |
1050 | record_tdep->ioctl_TCXONC = 0x540a; | |
1051 | record_tdep->ioctl_TCFLSH = 0x540b; | |
1052 | record_tdep->ioctl_TIOCEXCL = 0x540c; | |
1053 | record_tdep->ioctl_TIOCNXCL = 0x540d; | |
1054 | record_tdep->ioctl_TIOCSCTTY = 0x540e; | |
1055 | record_tdep->ioctl_TIOCGPGRP = 0x540f; | |
1056 | record_tdep->ioctl_TIOCSPGRP = 0x5410; | |
1057 | record_tdep->ioctl_TIOCOUTQ = 0x5411; | |
1058 | record_tdep->ioctl_TIOCSTI = 0x5412; | |
1059 | record_tdep->ioctl_TIOCGWINSZ = 0x5413; | |
1060 | record_tdep->ioctl_TIOCSWINSZ = 0x5414; | |
1061 | record_tdep->ioctl_TIOCMGET = 0x5415; | |
1062 | record_tdep->ioctl_TIOCMBIS = 0x5416; | |
1063 | record_tdep->ioctl_TIOCMBIC = 0x5417; | |
1064 | record_tdep->ioctl_TIOCMSET = 0x5418; | |
1065 | record_tdep->ioctl_TIOCGSOFTCAR = 0x5419; | |
1066 | record_tdep->ioctl_TIOCSSOFTCAR = 0x541a; | |
1067 | record_tdep->ioctl_FIONREAD = 0x541b; | |
1068 | record_tdep->ioctl_TIOCINQ = 0x541b; /* alias */ | |
1069 | record_tdep->ioctl_TIOCLINUX = 0x541c; | |
1070 | record_tdep->ioctl_TIOCCONS = 0x541d; | |
1071 | record_tdep->ioctl_TIOCGSERIAL = 0x541e; | |
1072 | record_tdep->ioctl_TIOCSSERIAL = 0x541f; | |
1073 | record_tdep->ioctl_TIOCPKT = 0x5420; | |
1074 | record_tdep->ioctl_FIONBIO = 0x5421; | |
1075 | record_tdep->ioctl_TIOCNOTTY = 0x5422; | |
1076 | record_tdep->ioctl_TIOCSETD = 0x5423; | |
1077 | record_tdep->ioctl_TIOCGETD = 0x5424; | |
1078 | record_tdep->ioctl_TCSBRKP = 0x5425; | |
1079 | record_tdep->ioctl_TIOCSBRK = 0x5427; | |
1080 | record_tdep->ioctl_TIOCCBRK = 0x5428; | |
1081 | record_tdep->ioctl_TIOCGSID = 0x5429; | |
1082 | record_tdep->ioctl_TCGETS2 = 0x802c542a; | |
1083 | record_tdep->ioctl_TCSETS2 = 0x402c542b; | |
1084 | record_tdep->ioctl_TCSETSW2 = 0x402c542c; | |
1085 | record_tdep->ioctl_TCSETSF2 = 0x402c542d; | |
1086 | record_tdep->ioctl_TIOCGPTN = 0x80045430; | |
1087 | record_tdep->ioctl_TIOCSPTLCK = 0x40045431; | |
1088 | record_tdep->ioctl_FIONCLEX = 0x5450; | |
1089 | record_tdep->ioctl_FIOCLEX = 0x5451; | |
1090 | record_tdep->ioctl_FIOASYNC = 0x5452; | |
1091 | record_tdep->ioctl_TIOCSERCONFIG = 0x5453; | |
1092 | record_tdep->ioctl_TIOCSERGWILD = 0x5454; | |
1093 | record_tdep->ioctl_TIOCSERSWILD = 0x5455; | |
1094 | record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456; | |
1095 | record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457; | |
1096 | record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458; | |
1097 | record_tdep->ioctl_TIOCSERGETLSR = 0x5459; | |
1098 | record_tdep->ioctl_TIOCSERGETMULTI = 0x545a; | |
1099 | record_tdep->ioctl_TIOCSERSETMULTI = 0x545b; | |
1100 | record_tdep->ioctl_TIOCMIWAIT = 0x545c; | |
1101 | record_tdep->ioctl_TIOCGICOUNT = 0x545d; | |
1102 | record_tdep->ioctl_FIOQSIZE = 0x545e; | |
1103 | } | |
1104 | ||
7042632b | 1105 | /* Initialize OSABI common for GNU/Linux on 31- and 64-bit systems. */ |
70728992 | 1106 | |
7042632b PR |
1107 | static void |
1108 | s390_linux_init_abi_any (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1109 | { | |
9c0b896e PR |
1110 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); |
1111 | ||
1112 | tdep->s390_syscall_record = s390_linux_syscall_record; | |
1113 | ||
7042632b | 1114 | linux_init_abi (info, gdbarch); |
c642a434 | 1115 | |
7042632b PR |
1116 | /* Register handling. */ |
1117 | set_gdbarch_core_read_description (gdbarch, s390_core_read_description); | |
1118 | set_gdbarch_iterate_over_regset_sections (gdbarch, | |
1119 | s390_iterate_over_regset_sections); | |
1120 | set_gdbarch_write_pc (gdbarch, s390_write_pc); | |
1121 | set_gdbarch_cannot_store_register (gdbarch, s390_cannot_store_register); | |
b0cf273e | 1122 | |
7042632b PR |
1123 | /* Syscall handling. */ |
1124 | set_gdbarch_get_syscall_number (gdbarch, s390_linux_get_syscall_number); | |
5769d3cd | 1125 | |
7042632b PR |
1126 | /* Frame handling. */ |
1127 | frame_unwind_append_unwinder (gdbarch, &s390_sigtramp_frame_unwind); | |
982e9687 UW |
1128 | set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target); |
1129 | ||
b2756930 KB |
1130 | /* Enable TLS support. */ |
1131 | set_gdbarch_fetch_tls_load_module_address (gdbarch, | |
34201ae3 | 1132 | svr4_fetch_objfile_link_map); |
b2756930 | 1133 | |
566c56c9 | 1134 | /* Support reverse debugging. */ |
566c56c9 | 1135 | set_gdbarch_process_record_signal (gdbarch, s390_linux_record_signal); |
566c56c9 MK |
1136 | s390_init_linux_record_tdep (&s390_linux_record_tdep, ABI_LINUX_S390); |
1137 | s390_init_linux_record_tdep (&s390x_linux_record_tdep, ABI_LINUX_ZSERIES); | |
7042632b | 1138 | } |
566c56c9 | 1139 | |
7042632b | 1140 | /* Initialize OSABI for GNU/Linux on 31-bit systems. */ |
65b48a81 | 1141 | |
7042632b PR |
1142 | static void |
1143 | s390_linux_init_abi_31 (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1144 | { | |
1145 | const struct target_desc *tdesc = info.target_desc; | |
1146 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1147 | ||
1148 | tdep->abi = ABI_LINUX_S390; | |
1149 | if (!tdesc_has_registers (tdesc)) | |
1150 | tdesc = tdesc_s390_linux32; | |
1151 | tdep->tdesc = tdesc; | |
1152 | ||
1153 | s390_linux_init_abi_any (info, gdbarch); | |
1154 | ||
1155 | set_solib_svr4_fetch_link_map_offsets (gdbarch, | |
1156 | svr4_ilp32_fetch_link_map_offsets); | |
1157 | set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_S390); | |
1158 | } | |
1159 | ||
1160 | /* Initialize OSABI for GNU/Linux on 64-bit systems. */ | |
1161 | ||
1162 | static void | |
1163 | s390_linux_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch) | |
1164 | { | |
1165 | const struct target_desc *tdesc = info.target_desc; | |
1166 | struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); | |
1167 | ||
1168 | tdep->abi = ABI_LINUX_ZSERIES; | |
1169 | if (!tdesc_has_registers (tdesc)) | |
1170 | tdesc = tdesc_s390x_linux64; | |
1171 | tdep->tdesc = tdesc; | |
1172 | ||
1173 | s390_linux_init_abi_any (info, gdbarch); | |
1174 | ||
1175 | set_solib_svr4_fetch_link_map_offsets (gdbarch, | |
1176 | svr4_lp64_fetch_link_map_offsets); | |
1177 | set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_S390X); | |
5769d3cd AC |
1178 | } |
1179 | ||
5769d3cd | 1180 | void |
d6e58945 | 1181 | _initialize_s390_linux_tdep (void) |
5769d3cd | 1182 | { |
7042632b PR |
1183 | /* Hook us into the OSABI mechanism. */ |
1184 | gdbarch_register_osabi (bfd_arch_s390, bfd_mach_s390_31, GDB_OSABI_LINUX, | |
1185 | s390_linux_init_abi_31); | |
1186 | gdbarch_register_osabi (bfd_arch_s390, bfd_mach_s390_64, GDB_OSABI_LINUX, | |
1187 | s390_linux_init_abi_64); | |
1188 | ||
94eae614 | 1189 | /* Initialize the GNU/Linux target descriptions. */ |
7803799a | 1190 | initialize_tdesc_s390_linux32 (); |
c642a434 UW |
1191 | initialize_tdesc_s390_linux32v1 (); |
1192 | initialize_tdesc_s390_linux32v2 (); | |
7803799a | 1193 | initialize_tdesc_s390_linux64 (); |
c642a434 UW |
1194 | initialize_tdesc_s390_linux64v1 (); |
1195 | initialize_tdesc_s390_linux64v2 (); | |
4ac33720 | 1196 | initialize_tdesc_s390_te_linux64 (); |
550bdf96 AA |
1197 | initialize_tdesc_s390_vx_linux64 (); |
1198 | initialize_tdesc_s390_tevx_linux64 (); | |
1b63490c | 1199 | initialize_tdesc_s390_gs_linux64 (); |
7803799a | 1200 | initialize_tdesc_s390x_linux64 (); |
c642a434 UW |
1201 | initialize_tdesc_s390x_linux64v1 (); |
1202 | initialize_tdesc_s390x_linux64v2 (); | |
4ac33720 | 1203 | initialize_tdesc_s390x_te_linux64 (); |
550bdf96 AA |
1204 | initialize_tdesc_s390x_vx_linux64 (); |
1205 | initialize_tdesc_s390x_tevx_linux64 (); | |
1b63490c | 1206 | initialize_tdesc_s390x_gs_linux64 (); |
5769d3cd | 1207 | } |