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