]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/gdbserver/linux-s390-low.c
Remove redundant WIFSTOPPED check
[thirdparty/binutils-gdb.git] / gdb / gdbserver / linux-s390-low.c
1 /* GNU/Linux S/390 specific low level interface, for the remote server
2 for GDB.
3 Copyright (C) 2001-2016 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 /* This file is used for both 31-bit and 64-bit S/390 systems. */
21
22 #include "server.h"
23 #include "linux-low.h"
24 #include "elf/common.h"
25
26 #include <asm/ptrace.h>
27 #include "nat/gdb_ptrace.h"
28 #include <sys/uio.h>
29 #include <elf.h>
30
31 #ifndef HWCAP_S390_HIGH_GPRS
32 #define HWCAP_S390_HIGH_GPRS 512
33 #endif
34
35 #ifndef HWCAP_S390_TE
36 #define HWCAP_S390_TE 1024
37 #endif
38
39 #ifndef HWCAP_S390_VX
40 #define HWCAP_S390_VX 2048
41 #endif
42
43 /* Defined in auto-generated file s390-linux32.c. */
44 void init_registers_s390_linux32 (void);
45 extern const struct target_desc *tdesc_s390_linux32;
46
47 /* Defined in auto-generated file s390-linux32v1.c. */
48 void init_registers_s390_linux32v1 (void);
49 extern const struct target_desc *tdesc_s390_linux32v1;
50
51 /* Defined in auto-generated file s390-linux32v2.c. */
52 void init_registers_s390_linux32v2 (void);
53 extern const struct target_desc *tdesc_s390_linux32v2;
54
55 /* Defined in auto-generated file s390-linux64.c. */
56 void init_registers_s390_linux64 (void);
57 extern const struct target_desc *tdesc_s390_linux64;
58
59 /* Defined in auto-generated file s390-linux64v1.c. */
60 void init_registers_s390_linux64v1 (void);
61 extern const struct target_desc *tdesc_s390_linux64v1;
62
63 /* Defined in auto-generated file s390-linux64v2.c. */
64 void init_registers_s390_linux64v2 (void);
65 extern const struct target_desc *tdesc_s390_linux64v2;
66
67 /* Defined in auto-generated file s390-te-linux64.c. */
68 void init_registers_s390_te_linux64 (void);
69 extern const struct target_desc *tdesc_s390_te_linux64;
70
71 /* Defined in auto-generated file s390-vx-linux64.c. */
72 void init_registers_s390_vx_linux64 (void);
73 extern const struct target_desc *tdesc_s390_vx_linux64;
74
75 /* Defined in auto-generated file s390-tevx-linux64.c. */
76 void init_registers_s390_tevx_linux64 (void);
77 extern const struct target_desc *tdesc_s390_tevx_linux64;
78
79 /* Defined in auto-generated file s390x-linux64.c. */
80 void init_registers_s390x_linux64 (void);
81 extern const struct target_desc *tdesc_s390x_linux64;
82
83 /* Defined in auto-generated file s390x-linux64v1.c. */
84 void init_registers_s390x_linux64v1 (void);
85 extern const struct target_desc *tdesc_s390x_linux64v1;
86
87 /* Defined in auto-generated file s390x-linux64v2.c. */
88 void init_registers_s390x_linux64v2 (void);
89 extern const struct target_desc *tdesc_s390x_linux64v2;
90
91 /* Defined in auto-generated file s390x-te-linux64.c. */
92 void init_registers_s390x_te_linux64 (void);
93 extern const struct target_desc *tdesc_s390x_te_linux64;
94
95 /* Defined in auto-generated file s390x-vx-linux64.c. */
96 void init_registers_s390x_vx_linux64 (void);
97 extern const struct target_desc *tdesc_s390x_vx_linux64;
98
99 /* Defined in auto-generated file s390x-tevx-linux64.c. */
100 void init_registers_s390x_tevx_linux64 (void);
101 extern const struct target_desc *tdesc_s390x_tevx_linux64;
102
103 #define s390_num_regs 52
104
105 static int s390_regmap[] = {
106 PT_PSWMASK, PT_PSWADDR,
107
108 PT_GPR0, PT_GPR1, PT_GPR2, PT_GPR3,
109 PT_GPR4, PT_GPR5, PT_GPR6, PT_GPR7,
110 PT_GPR8, PT_GPR9, PT_GPR10, PT_GPR11,
111 PT_GPR12, PT_GPR13, PT_GPR14, PT_GPR15,
112
113 PT_ACR0, PT_ACR1, PT_ACR2, PT_ACR3,
114 PT_ACR4, PT_ACR5, PT_ACR6, PT_ACR7,
115 PT_ACR8, PT_ACR9, PT_ACR10, PT_ACR11,
116 PT_ACR12, PT_ACR13, PT_ACR14, PT_ACR15,
117
118 PT_FPC,
119
120 #ifndef __s390x__
121 PT_FPR0_HI, PT_FPR1_HI, PT_FPR2_HI, PT_FPR3_HI,
122 PT_FPR4_HI, PT_FPR5_HI, PT_FPR6_HI, PT_FPR7_HI,
123 PT_FPR8_HI, PT_FPR9_HI, PT_FPR10_HI, PT_FPR11_HI,
124 PT_FPR12_HI, PT_FPR13_HI, PT_FPR14_HI, PT_FPR15_HI,
125 #else
126 PT_FPR0, PT_FPR1, PT_FPR2, PT_FPR3,
127 PT_FPR4, PT_FPR5, PT_FPR6, PT_FPR7,
128 PT_FPR8, PT_FPR9, PT_FPR10, PT_FPR11,
129 PT_FPR12, PT_FPR13, PT_FPR14, PT_FPR15,
130 #endif
131
132 PT_ORIGGPR2,
133 };
134
135 #define s390_num_regs_3264 68
136
137 #ifdef __s390x__
138 static int s390_regmap_3264[] = {
139 PT_PSWMASK, PT_PSWADDR,
140
141 PT_GPR0, PT_GPR0, PT_GPR1, PT_GPR1,
142 PT_GPR2, PT_GPR2, PT_GPR3, PT_GPR3,
143 PT_GPR4, PT_GPR4, PT_GPR5, PT_GPR5,
144 PT_GPR6, PT_GPR6, PT_GPR7, PT_GPR7,
145 PT_GPR8, PT_GPR8, PT_GPR9, PT_GPR9,
146 PT_GPR10, PT_GPR10, PT_GPR11, PT_GPR11,
147 PT_GPR12, PT_GPR12, PT_GPR13, PT_GPR13,
148 PT_GPR14, PT_GPR14, PT_GPR15, PT_GPR15,
149
150 PT_ACR0, PT_ACR1, PT_ACR2, PT_ACR3,
151 PT_ACR4, PT_ACR5, PT_ACR6, PT_ACR7,
152 PT_ACR8, PT_ACR9, PT_ACR10, PT_ACR11,
153 PT_ACR12, PT_ACR13, PT_ACR14, PT_ACR15,
154
155 PT_FPC,
156
157 PT_FPR0, PT_FPR1, PT_FPR2, PT_FPR3,
158 PT_FPR4, PT_FPR5, PT_FPR6, PT_FPR7,
159 PT_FPR8, PT_FPR9, PT_FPR10, PT_FPR11,
160 PT_FPR12, PT_FPR13, PT_FPR14, PT_FPR15,
161
162 PT_ORIGGPR2,
163 };
164 #else
165 static int s390_regmap_3264[] = {
166 PT_PSWMASK, PT_PSWADDR,
167
168 -1, PT_GPR0, -1, PT_GPR1,
169 -1, PT_GPR2, -1, PT_GPR3,
170 -1, PT_GPR4, -1, PT_GPR5,
171 -1, PT_GPR6, -1, PT_GPR7,
172 -1, PT_GPR8, -1, PT_GPR9,
173 -1, PT_GPR10, -1, PT_GPR11,
174 -1, PT_GPR12, -1, PT_GPR13,
175 -1, PT_GPR14, -1, PT_GPR15,
176
177 PT_ACR0, PT_ACR1, PT_ACR2, PT_ACR3,
178 PT_ACR4, PT_ACR5, PT_ACR6, PT_ACR7,
179 PT_ACR8, PT_ACR9, PT_ACR10, PT_ACR11,
180 PT_ACR12, PT_ACR13, PT_ACR14, PT_ACR15,
181
182 PT_FPC,
183
184 PT_FPR0_HI, PT_FPR1_HI, PT_FPR2_HI, PT_FPR3_HI,
185 PT_FPR4_HI, PT_FPR5_HI, PT_FPR6_HI, PT_FPR7_HI,
186 PT_FPR8_HI, PT_FPR9_HI, PT_FPR10_HI, PT_FPR11_HI,
187 PT_FPR12_HI, PT_FPR13_HI, PT_FPR14_HI, PT_FPR15_HI,
188
189 PT_ORIGGPR2,
190 };
191 #endif
192
193
194 static int
195 s390_cannot_fetch_register (int regno)
196 {
197 return 0;
198 }
199
200 static int
201 s390_cannot_store_register (int regno)
202 {
203 return 0;
204 }
205
206 static void
207 s390_collect_ptrace_register (struct regcache *regcache, int regno, char *buf)
208 {
209 int size = register_size (regcache->tdesc, regno);
210 const struct regs_info *regs_info = (*the_low_target.regs_info) ();
211 struct usrregs_info *usr = regs_info->usrregs;
212 int regaddr = usr->regmap[regno];
213
214 if (size < sizeof (long))
215 {
216 memset (buf, 0, sizeof (long));
217
218 if ((regno ^ 1) < usr->num_regs
219 && usr->regmap[regno ^ 1] == regaddr)
220 {
221 collect_register (regcache, regno & ~1, buf);
222 collect_register (regcache, (regno & ~1) + 1,
223 buf + sizeof (long) - size);
224 }
225 else if (regaddr == PT_PSWMASK)
226 {
227 /* Convert 4-byte PSW mask to 8 bytes by clearing bit 12 and copying
228 the basic addressing mode bit from the PSW address. */
229 char *addr = alloca (register_size (regcache->tdesc, regno ^ 1));
230 collect_register (regcache, regno, buf);
231 collect_register (regcache, regno ^ 1, addr);
232 buf[1] &= ~0x8;
233 buf[size] |= (addr[0] & 0x80);
234 }
235 else if (regaddr == PT_PSWADDR)
236 {
237 /* Convert 4-byte PSW address to 8 bytes by clearing the addressing
238 mode bit (which gets copied to the PSW mask instead). */
239 collect_register (regcache, regno, buf + sizeof (long) - size);
240 buf[sizeof (long) - size] &= ~0x80;
241 }
242 else if ((regaddr >= PT_GPR0 && regaddr <= PT_GPR15)
243 || regaddr == PT_ORIGGPR2)
244 collect_register (regcache, regno, buf + sizeof (long) - size);
245 else
246 collect_register (regcache, regno, buf);
247 }
248 else if (regaddr != -1)
249 collect_register (regcache, regno, buf);
250 }
251
252 static void
253 s390_supply_ptrace_register (struct regcache *regcache,
254 int regno, const char *buf)
255 {
256 int size = register_size (regcache->tdesc, regno);
257 const struct regs_info *regs_info = (*the_low_target.regs_info) ();
258 struct usrregs_info *usr = regs_info->usrregs;
259 int regaddr = usr->regmap[regno];
260
261 if (size < sizeof (long))
262 {
263 if ((regno ^ 1) < usr->num_regs
264 && usr->regmap[regno ^ 1] == regaddr)
265 {
266 supply_register (regcache, regno & ~1, buf);
267 supply_register (regcache, (regno & ~1) + 1,
268 buf + sizeof (long) - size);
269 }
270 else if (regaddr == PT_PSWMASK)
271 {
272 /* Convert 8-byte PSW mask to 4 bytes by setting bit 12 and copying
273 the basic addressing mode into the PSW address. */
274 char *mask = alloca (size);
275 char *addr = alloca (register_size (regcache->tdesc, regno ^ 1));
276 memcpy (mask, buf, size);
277 mask[1] |= 0x8;
278 supply_register (regcache, regno, mask);
279
280 collect_register (regcache, regno ^ 1, addr);
281 addr[0] &= ~0x80;
282 addr[0] |= (buf[size] & 0x80);
283 supply_register (regcache, regno ^ 1, addr);
284 }
285 else if (regaddr == PT_PSWADDR)
286 {
287 /* Convert 8-byte PSW address to 4 bytes by truncating, but
288 keeping the addressing mode bit (which was set from the mask). */
289 char *addr = alloca (size);
290 char amode;
291 collect_register (regcache, regno, addr);
292 amode = addr[0] & 0x80;
293 memcpy (addr, buf + sizeof (long) - size, size);
294 addr[0] &= ~0x80;
295 addr[0] |= amode;
296 supply_register (regcache, regno, addr);
297 }
298 else if ((regaddr >= PT_GPR0 && regaddr <= PT_GPR15)
299 || regaddr == PT_ORIGGPR2)
300 supply_register (regcache, regno, buf + sizeof (long) - size);
301 else
302 supply_register (regcache, regno, buf);
303 }
304 else if (regaddr != -1)
305 supply_register (regcache, regno, buf);
306 }
307
308 /* Provide only a fill function for the general register set. ps_lgetregs
309 will use this for NPTL support. */
310
311 static void
312 s390_fill_gregset (struct regcache *regcache, void *buf)
313 {
314 int i;
315 const struct regs_info *regs_info = (*the_low_target.regs_info) ();
316 struct usrregs_info *usr = regs_info->usrregs;
317
318 for (i = 0; i < usr->num_regs; i++)
319 {
320 if (usr->regmap[i] < PT_PSWMASK
321 || usr->regmap[i] > PT_ACR15)
322 continue;
323
324 s390_collect_ptrace_register (regcache, i,
325 (char *) buf + usr->regmap[i]);
326 }
327 }
328
329 /* Fill and store functions for extended register sets. */
330
331 #ifndef __s390x__
332 static void
333 s390_fill_gprs_high (struct regcache *regcache, void *buf)
334 {
335 int r0h = find_regno (regcache->tdesc, "r0h");
336 int i;
337
338 for (i = 0; i < 16; i++)
339 collect_register (regcache, r0h + 2 * i, (char *) buf + 4 * i);
340 }
341
342 static void
343 s390_store_gprs_high (struct regcache *regcache, const void *buf)
344 {
345 int r0h = find_regno (regcache->tdesc, "r0h");
346 int i;
347
348 for (i = 0; i < 16; i++)
349 supply_register (regcache, r0h + 2 * i, (const char *) buf + 4 * i);
350 }
351 #endif
352
353 static void
354 s390_store_last_break (struct regcache *regcache, const void *buf)
355 {
356 const char *p;
357
358 p = (const char *) buf + 8 - register_size (regcache->tdesc, 0);
359 supply_register_by_name (regcache, "last_break", p);
360 }
361
362 static void
363 s390_fill_system_call (struct regcache *regcache, void *buf)
364 {
365 collect_register_by_name (regcache, "system_call", buf);
366 }
367
368 static void
369 s390_store_system_call (struct regcache *regcache, const void *buf)
370 {
371 supply_register_by_name (regcache, "system_call", buf);
372 }
373
374 static void
375 s390_store_tdb (struct regcache *regcache, const void *buf)
376 {
377 int tdb0 = find_regno (regcache->tdesc, "tdb0");
378 int tr0 = find_regno (regcache->tdesc, "tr0");
379 int i;
380
381 for (i = 0; i < 4; i++)
382 supply_register (regcache, tdb0 + i, (const char *) buf + 8 * i);
383
384 for (i = 0; i < 16; i++)
385 supply_register (regcache, tr0 + i, (const char *) buf + 8 * (16 + i));
386 }
387
388 static void
389 s390_fill_vxrs_low (struct regcache *regcache, void *buf)
390 {
391 int v0 = find_regno (regcache->tdesc, "v0l");
392 int i;
393
394 for (i = 0; i < 16; i++)
395 collect_register (regcache, v0 + i, (char *) buf + 8 * i);
396 }
397
398 static void
399 s390_store_vxrs_low (struct regcache *regcache, const void *buf)
400 {
401 int v0 = find_regno (regcache->tdesc, "v0l");
402 int i;
403
404 for (i = 0; i < 16; i++)
405 supply_register (regcache, v0 + i, (const char *) buf + 8 * i);
406 }
407
408 static void
409 s390_fill_vxrs_high (struct regcache *regcache, void *buf)
410 {
411 int v16 = find_regno (regcache->tdesc, "v16");
412 int i;
413
414 for (i = 0; i < 16; i++)
415 collect_register (regcache, v16 + i, (char *) buf + 16 * i);
416 }
417
418 static void
419 s390_store_vxrs_high (struct regcache *regcache, const void *buf)
420 {
421 int v16 = find_regno (regcache->tdesc, "v16");
422 int i;
423
424 for (i = 0; i < 16; i++)
425 supply_register (regcache, v16 + i, (const char *) buf + 16 * i);
426 }
427
428 static struct regset_info s390_regsets[] = {
429 { 0, 0, 0, 0, GENERAL_REGS, s390_fill_gregset, NULL },
430 #ifndef __s390x__
431 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_HIGH_GPRS, 0,
432 EXTENDED_REGS, s390_fill_gprs_high, s390_store_gprs_high },
433 #endif
434 /* Last break address is read-only; no fill function. */
435 { PTRACE_GETREGSET, -1, NT_S390_LAST_BREAK, 0, EXTENDED_REGS,
436 NULL, s390_store_last_break },
437 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_SYSTEM_CALL, 0,
438 EXTENDED_REGS, s390_fill_system_call, s390_store_system_call },
439 /* TDB is read-only. */
440 { PTRACE_GETREGSET, -1, NT_S390_TDB, 0, EXTENDED_REGS,
441 NULL, s390_store_tdb },
442 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_VXRS_LOW, 0,
443 EXTENDED_REGS, s390_fill_vxrs_low, s390_store_vxrs_low },
444 { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_S390_VXRS_HIGH, 0,
445 EXTENDED_REGS, s390_fill_vxrs_high, s390_store_vxrs_high },
446 NULL_REGSET
447 };
448
449
450 static const gdb_byte s390_breakpoint[] = { 0, 1 };
451 #define s390_breakpoint_len 2
452
453 /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
454
455 static const gdb_byte *
456 s390_sw_breakpoint_from_kind (int kind, int *size)
457 {
458 *size = s390_breakpoint_len;
459 return s390_breakpoint;
460 }
461
462 static CORE_ADDR
463 s390_get_pc (struct regcache *regcache)
464 {
465 if (register_size (regcache->tdesc, 0) == 4)
466 {
467 unsigned int pswa;
468 collect_register_by_name (regcache, "pswa", &pswa);
469 return pswa & 0x7fffffff;
470 }
471 else
472 {
473 unsigned long pc;
474 collect_register_by_name (regcache, "pswa", &pc);
475 return pc;
476 }
477 }
478
479 static void
480 s390_set_pc (struct regcache *regcache, CORE_ADDR newpc)
481 {
482 if (register_size (regcache->tdesc, 0) == 4)
483 {
484 unsigned int pswa;
485 collect_register_by_name (regcache, "pswa", &pswa);
486 pswa = (pswa & 0x80000000) | (newpc & 0x7fffffff);
487 supply_register_by_name (regcache, "pswa", &pswa);
488 }
489 else
490 {
491 unsigned long pc = newpc;
492 supply_register_by_name (regcache, "pswa", &pc);
493 }
494 }
495
496 static unsigned long
497 s390_get_hwcap (const struct target_desc *tdesc)
498 {
499 int wordsize = register_size (tdesc, 0);
500 unsigned char *data = alloca (2 * wordsize);
501 int offset = 0;
502
503 while ((*the_target->read_auxv) (offset, data, 2 * wordsize) == 2 * wordsize)
504 {
505 if (wordsize == 4)
506 {
507 unsigned int *data_p = (unsigned int *)data;
508 if (data_p[0] == AT_HWCAP)
509 return data_p[1];
510 }
511 else
512 {
513 unsigned long *data_p = (unsigned long *)data;
514 if (data_p[0] == AT_HWCAP)
515 return data_p[1];
516 }
517
518 offset += 2 * wordsize;
519 }
520
521 return 0;
522 }
523
524 static int
525 s390_check_regset (int pid, int regset, int regsize)
526 {
527 gdb_byte *buf = alloca (regsize);
528 struct iovec iov;
529
530 iov.iov_base = buf;
531 iov.iov_len = regsize;
532
533 if (ptrace (PTRACE_GETREGSET, pid, (long) regset, (long) &iov) >= 0
534 || errno == ENODATA)
535 return 1;
536 return 0;
537 }
538
539 /* For a 31-bit inferior, whether the kernel supports using the full
540 64-bit GPRs. */
541 static int have_hwcap_s390_high_gprs = 0;
542
543 static void
544 s390_arch_setup (void)
545 {
546 const struct target_desc *tdesc;
547 struct regset_info *regset;
548
549 /* Check whether the kernel supports extra register sets. */
550 int pid = pid_of (current_thread);
551 int have_regset_last_break
552 = s390_check_regset (pid, NT_S390_LAST_BREAK, 8);
553 int have_regset_system_call
554 = s390_check_regset (pid, NT_S390_SYSTEM_CALL, 4);
555 int have_regset_tdb = s390_check_regset (pid, NT_S390_TDB, 256);
556 int have_regset_vxrs = s390_check_regset (pid, NT_S390_VXRS_LOW, 128)
557 && s390_check_regset (pid, NT_S390_VXRS_HIGH, 256);
558
559 /* Assume 31-bit inferior process. */
560 if (have_regset_system_call)
561 tdesc = tdesc_s390_linux32v2;
562 else if (have_regset_last_break)
563 tdesc = tdesc_s390_linux32v1;
564 else
565 tdesc = tdesc_s390_linux32;
566
567 /* On a 64-bit host, check the low bit of the (31-bit) PSWM
568 -- if this is one, we actually have a 64-bit inferior. */
569 {
570 #ifdef __s390x__
571 unsigned int pswm;
572 struct regcache *regcache = new_register_cache (tdesc);
573
574 fetch_inferior_registers (regcache, find_regno (tdesc, "pswm"));
575 collect_register_by_name (regcache, "pswm", &pswm);
576 free_register_cache (regcache);
577
578 if (pswm & 1)
579 {
580 if (have_regset_tdb)
581 have_regset_tdb =
582 (s390_get_hwcap (tdesc_s390x_linux64v2) & HWCAP_S390_TE) != 0;
583 if (have_regset_vxrs)
584 have_regset_vxrs =
585 (s390_get_hwcap (tdesc_s390x_linux64v2) & HWCAP_S390_VX) != 0;
586
587 if (have_regset_vxrs)
588 tdesc = (have_regset_tdb ? tdesc_s390x_tevx_linux64 :
589 tdesc_s390x_vx_linux64);
590 else if (have_regset_tdb)
591 tdesc = tdesc_s390x_te_linux64;
592 else if (have_regset_system_call)
593 tdesc = tdesc_s390x_linux64v2;
594 else if (have_regset_last_break)
595 tdesc = tdesc_s390x_linux64v1;
596 else
597 tdesc = tdesc_s390x_linux64;
598 }
599
600 /* For a 31-bit inferior, check whether the kernel supports
601 using the full 64-bit GPRs. */
602 else
603 #endif
604 if (s390_get_hwcap (tdesc) & HWCAP_S390_HIGH_GPRS)
605 {
606 have_hwcap_s390_high_gprs = 1;
607 if (have_regset_tdb)
608 have_regset_tdb = (s390_get_hwcap (tdesc) & HWCAP_S390_TE) != 0;
609 if (have_regset_vxrs)
610 have_regset_vxrs = (s390_get_hwcap (tdesc) & HWCAP_S390_VX) != 0;
611
612 if (have_regset_vxrs)
613 tdesc = (have_regset_tdb ? tdesc_s390_tevx_linux64 :
614 tdesc_s390_vx_linux64);
615 else if (have_regset_tdb)
616 tdesc = tdesc_s390_te_linux64;
617 else if (have_regset_system_call)
618 tdesc = tdesc_s390_linux64v2;
619 else if (have_regset_last_break)
620 tdesc = tdesc_s390_linux64v1;
621 else
622 tdesc = tdesc_s390_linux64;
623 }
624 }
625
626 /* Update target_regsets according to available register sets. */
627 for (regset = s390_regsets; regset->size >= 0; regset++)
628 if (regset->get_request == PTRACE_GETREGSET)
629 switch (regset->nt_type)
630 {
631 #ifndef __s390x__
632 case NT_S390_HIGH_GPRS:
633 regset->size = have_hwcap_s390_high_gprs ? 64 : 0;
634 break;
635 #endif
636 case NT_S390_LAST_BREAK:
637 regset->size = have_regset_last_break ? 8 : 0;
638 break;
639 case NT_S390_SYSTEM_CALL:
640 regset->size = have_regset_system_call ? 4 : 0;
641 break;
642 case NT_S390_TDB:
643 regset->size = have_regset_tdb ? 256 : 0;
644 break;
645 case NT_S390_VXRS_LOW:
646 regset->size = have_regset_vxrs ? 128 : 0;
647 break;
648 case NT_S390_VXRS_HIGH:
649 regset->size = have_regset_vxrs ? 256 : 0;
650 break;
651 default:
652 break;
653 }
654
655 current_process ()->tdesc = tdesc;
656 }
657
658
659 static int
660 s390_breakpoint_at (CORE_ADDR pc)
661 {
662 unsigned char c[s390_breakpoint_len];
663 read_inferior_memory (pc, c, s390_breakpoint_len);
664 return memcmp (c, s390_breakpoint, s390_breakpoint_len) == 0;
665 }
666
667 /* Breakpoint/Watchpoint support. */
668
669 /* The "supports_z_point_type" linux_target_ops method. */
670
671 static int
672 s390_supports_z_point_type (char z_type)
673 {
674 switch (z_type)
675 {
676 case Z_PACKET_SW_BP:
677 return 1;
678 default:
679 return 0;
680 }
681 }
682
683 /* Support for hardware single step. */
684
685 static int
686 s390_supports_hardware_single_step (void)
687 {
688 return 1;
689 }
690
691 static struct usrregs_info s390_usrregs_info =
692 {
693 s390_num_regs,
694 s390_regmap,
695 };
696
697 static struct regsets_info s390_regsets_info =
698 {
699 s390_regsets, /* regsets */
700 0, /* num_regsets */
701 NULL, /* disabled_regsets */
702 };
703
704 static struct regs_info regs_info =
705 {
706 NULL, /* regset_bitmap */
707 &s390_usrregs_info,
708 &s390_regsets_info
709 };
710
711 static struct usrregs_info s390_usrregs_info_3264 =
712 {
713 s390_num_regs_3264,
714 s390_regmap_3264
715 };
716
717 static struct regsets_info s390_regsets_info_3264 =
718 {
719 s390_regsets, /* regsets */
720 0, /* num_regsets */
721 NULL, /* disabled_regsets */
722 };
723
724 static struct regs_info regs_info_3264 =
725 {
726 NULL, /* regset_bitmap */
727 &s390_usrregs_info_3264,
728 &s390_regsets_info_3264
729 };
730
731 static const struct regs_info *
732 s390_regs_info (void)
733 {
734 if (have_hwcap_s390_high_gprs)
735 {
736 #ifdef __s390x__
737 const struct target_desc *tdesc = current_process ()->tdesc;
738
739 if (register_size (tdesc, 0) == 4)
740 return &regs_info_3264;
741 #else
742 return &regs_info_3264;
743 #endif
744 }
745 return &regs_info;
746 }
747
748 struct linux_target_ops the_low_target = {
749 s390_arch_setup,
750 s390_regs_info,
751 s390_cannot_fetch_register,
752 s390_cannot_store_register,
753 NULL, /* fetch_register */
754 s390_get_pc,
755 s390_set_pc,
756 NULL, /* breakpoint_kind_from_pc */
757 s390_sw_breakpoint_from_kind,
758 NULL,
759 s390_breakpoint_len,
760 s390_breakpoint_at,
761 s390_supports_z_point_type,
762 NULL,
763 NULL,
764 NULL,
765 NULL,
766 s390_collect_ptrace_register,
767 s390_supply_ptrace_register,
768 NULL, /* siginfo_fixup */
769 NULL, /* new_process */
770 NULL, /* new_thread */
771 NULL, /* new_fork */
772 NULL, /* prepare_to_resume */
773 NULL, /* process_qsupported */
774 NULL, /* supports_tracepoints */
775 NULL, /* get_thread_area */
776 NULL, /* install_fast_tracepoint_jump_pad */
777 NULL, /* emit_ops */
778 NULL, /* get_min_fast_tracepoint_insn_len */
779 NULL, /* supports_range_stepping */
780 NULL, /* breakpoint_kind_from_current_state */
781 s390_supports_hardware_single_step,
782 };
783
784 void
785 initialize_low_arch (void)
786 {
787 /* Initialize the Linux target descriptions. */
788
789 init_registers_s390_linux32 ();
790 init_registers_s390_linux32v1 ();
791 init_registers_s390_linux32v2 ();
792 init_registers_s390_linux64 ();
793 init_registers_s390_linux64v1 ();
794 init_registers_s390_linux64v2 ();
795 init_registers_s390_te_linux64 ();
796 init_registers_s390_vx_linux64 ();
797 init_registers_s390_tevx_linux64 ();
798 init_registers_s390x_linux64 ();
799 init_registers_s390x_linux64v1 ();
800 init_registers_s390x_linux64v2 ();
801 init_registers_s390x_te_linux64 ();
802 init_registers_s390x_vx_linux64 ();
803 init_registers_s390x_tevx_linux64 ();
804
805 initialize_regsets_info (&s390_regsets_info);
806 initialize_regsets_info (&s390_regsets_info_3264);
807 }