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