1 /* GNU/Linux S/390 specific low level interface, for the remote server
3 Copyright (C) 2001-2016 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 /* This file is used for both 31-bit and 64-bit S/390 systems. */
23 #include "linux-low.h"
24 #include "elf/common.h"
26 #include <asm/ptrace.h>
27 #include "nat/gdb_ptrace.h"
32 #include "linux-s390-tdesc.h"
34 #ifndef HWCAP_S390_HIGH_GPRS
35 #define HWCAP_S390_HIGH_GPRS 512
39 #define HWCAP_S390_TE 1024
43 #define HWCAP_S390_VX 2048
46 #define s390_num_regs 52
48 static int s390_regmap
[] = {
49 PT_PSWMASK
, PT_PSWADDR
,
51 PT_GPR0
, PT_GPR1
, PT_GPR2
, PT_GPR3
,
52 PT_GPR4
, PT_GPR5
, PT_GPR6
, PT_GPR7
,
53 PT_GPR8
, PT_GPR9
, PT_GPR10
, PT_GPR11
,
54 PT_GPR12
, PT_GPR13
, PT_GPR14
, PT_GPR15
,
56 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
57 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
58 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
59 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
64 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
65 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
66 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
67 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
69 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
70 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
71 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
72 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
78 #define s390_num_regs_3264 68
81 static int s390_regmap_3264
[] = {
82 PT_PSWMASK
, PT_PSWADDR
,
84 PT_GPR0
, PT_GPR0
, PT_GPR1
, PT_GPR1
,
85 PT_GPR2
, PT_GPR2
, PT_GPR3
, PT_GPR3
,
86 PT_GPR4
, PT_GPR4
, PT_GPR5
, PT_GPR5
,
87 PT_GPR6
, PT_GPR6
, PT_GPR7
, PT_GPR7
,
88 PT_GPR8
, PT_GPR8
, PT_GPR9
, PT_GPR9
,
89 PT_GPR10
, PT_GPR10
, PT_GPR11
, PT_GPR11
,
90 PT_GPR12
, PT_GPR12
, PT_GPR13
, PT_GPR13
,
91 PT_GPR14
, PT_GPR14
, PT_GPR15
, PT_GPR15
,
93 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
94 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
95 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
96 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
100 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
101 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
102 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
103 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
108 static int s390_regmap_3264
[] = {
109 PT_PSWMASK
, PT_PSWADDR
,
111 -1, PT_GPR0
, -1, PT_GPR1
,
112 -1, PT_GPR2
, -1, PT_GPR3
,
113 -1, PT_GPR4
, -1, PT_GPR5
,
114 -1, PT_GPR6
, -1, PT_GPR7
,
115 -1, PT_GPR8
, -1, PT_GPR9
,
116 -1, PT_GPR10
, -1, PT_GPR11
,
117 -1, PT_GPR12
, -1, PT_GPR13
,
118 -1, PT_GPR14
, -1, PT_GPR15
,
120 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
121 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
122 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
123 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
127 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
128 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
129 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
130 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
138 s390_cannot_fetch_register (int regno
)
144 s390_cannot_store_register (int regno
)
150 s390_collect_ptrace_register (struct regcache
*regcache
, int regno
, char *buf
)
152 int size
= register_size (regcache
->tdesc
, regno
);
153 const struct regs_info
*regs_info
= (*the_low_target
.regs_info
) ();
154 struct usrregs_info
*usr
= regs_info
->usrregs
;
155 int regaddr
= usr
->regmap
[regno
];
157 if (size
< sizeof (long))
159 memset (buf
, 0, sizeof (long));
161 if ((regno
^ 1) < usr
->num_regs
162 && usr
->regmap
[regno
^ 1] == regaddr
)
164 collect_register (regcache
, regno
& ~1, buf
);
165 collect_register (regcache
, (regno
& ~1) + 1,
166 buf
+ sizeof (long) - size
);
168 else if (regaddr
== PT_PSWMASK
)
170 /* Convert 4-byte PSW mask to 8 bytes by clearing bit 12 and copying
171 the basic addressing mode bit from the PSW address. */
172 char *addr
= alloca (register_size (regcache
->tdesc
, regno
^ 1));
173 collect_register (regcache
, regno
, buf
);
174 collect_register (regcache
, regno
^ 1, addr
);
176 buf
[size
] |= (addr
[0] & 0x80);
178 else if (regaddr
== PT_PSWADDR
)
180 /* Convert 4-byte PSW address to 8 bytes by clearing the addressing
181 mode bit (which gets copied to the PSW mask instead). */
182 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
183 buf
[sizeof (long) - size
] &= ~0x80;
185 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
186 || regaddr
== PT_ORIGGPR2
)
187 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
189 collect_register (regcache
, regno
, buf
);
191 else if (regaddr
!= -1)
192 collect_register (regcache
, regno
, buf
);
196 s390_supply_ptrace_register (struct regcache
*regcache
,
197 int regno
, const char *buf
)
199 int size
= register_size (regcache
->tdesc
, regno
);
200 const struct regs_info
*regs_info
= (*the_low_target
.regs_info
) ();
201 struct usrregs_info
*usr
= regs_info
->usrregs
;
202 int regaddr
= usr
->regmap
[regno
];
204 if (size
< sizeof (long))
206 if ((regno
^ 1) < usr
->num_regs
207 && usr
->regmap
[regno
^ 1] == regaddr
)
209 supply_register (regcache
, regno
& ~1, buf
);
210 supply_register (regcache
, (regno
& ~1) + 1,
211 buf
+ sizeof (long) - size
);
213 else if (regaddr
== PT_PSWMASK
)
215 /* Convert 8-byte PSW mask to 4 bytes by setting bit 12 and copying
216 the basic addressing mode into the PSW address. */
217 char *mask
= alloca (size
);
218 char *addr
= alloca (register_size (regcache
->tdesc
, regno
^ 1));
219 memcpy (mask
, buf
, size
);
221 supply_register (regcache
, regno
, mask
);
223 collect_register (regcache
, regno
^ 1, addr
);
225 addr
[0] |= (buf
[size
] & 0x80);
226 supply_register (regcache
, regno
^ 1, addr
);
228 else if (regaddr
== PT_PSWADDR
)
230 /* Convert 8-byte PSW address to 4 bytes by truncating, but
231 keeping the addressing mode bit (which was set from the mask). */
232 char *addr
= alloca (size
);
234 collect_register (regcache
, regno
, addr
);
235 amode
= addr
[0] & 0x80;
236 memcpy (addr
, buf
+ sizeof (long) - size
, size
);
239 supply_register (regcache
, regno
, addr
);
241 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
242 || regaddr
== PT_ORIGGPR2
)
243 supply_register (regcache
, regno
, buf
+ sizeof (long) - size
);
245 supply_register (regcache
, regno
, buf
);
247 else if (regaddr
!= -1)
248 supply_register (regcache
, regno
, buf
);
251 /* Provide only a fill function for the general register set. ps_lgetregs
252 will use this for NPTL support. */
255 s390_fill_gregset (struct regcache
*regcache
, void *buf
)
258 const struct regs_info
*regs_info
= (*the_low_target
.regs_info
) ();
259 struct usrregs_info
*usr
= regs_info
->usrregs
;
261 for (i
= 0; i
< usr
->num_regs
; i
++)
263 if (usr
->regmap
[i
] < PT_PSWMASK
264 || usr
->regmap
[i
] > PT_ACR15
)
267 s390_collect_ptrace_register (regcache
, i
,
268 (char *) buf
+ usr
->regmap
[i
]);
272 /* Fill and store functions for extended register sets. */
276 s390_fill_gprs_high (struct regcache
*regcache
, void *buf
)
278 int r0h
= find_regno (regcache
->tdesc
, "r0h");
281 for (i
= 0; i
< 16; i
++)
282 collect_register (regcache
, r0h
+ 2 * i
, (char *) buf
+ 4 * i
);
286 s390_store_gprs_high (struct regcache
*regcache
, const void *buf
)
288 int r0h
= find_regno (regcache
->tdesc
, "r0h");
291 for (i
= 0; i
< 16; i
++)
292 supply_register (regcache
, r0h
+ 2 * i
, (const char *) buf
+ 4 * i
);
297 s390_store_last_break (struct regcache
*regcache
, const void *buf
)
301 p
= (const char *) buf
+ 8 - register_size (regcache
->tdesc
, 0);
302 supply_register_by_name (regcache
, "last_break", p
);
306 s390_fill_system_call (struct regcache
*regcache
, void *buf
)
308 collect_register_by_name (regcache
, "system_call", buf
);
312 s390_store_system_call (struct regcache
*regcache
, const void *buf
)
314 supply_register_by_name (regcache
, "system_call", buf
);
318 s390_store_tdb (struct regcache
*regcache
, const void *buf
)
320 int tdb0
= find_regno (regcache
->tdesc
, "tdb0");
321 int tr0
= find_regno (regcache
->tdesc
, "tr0");
324 for (i
= 0; i
< 4; i
++)
325 supply_register (regcache
, tdb0
+ i
, (const char *) buf
+ 8 * i
);
327 for (i
= 0; i
< 16; i
++)
328 supply_register (regcache
, tr0
+ i
, (const char *) buf
+ 8 * (16 + i
));
332 s390_fill_vxrs_low (struct regcache
*regcache
, void *buf
)
334 int v0
= find_regno (regcache
->tdesc
, "v0l");
337 for (i
= 0; i
< 16; i
++)
338 collect_register (regcache
, v0
+ i
, (char *) buf
+ 8 * i
);
342 s390_store_vxrs_low (struct regcache
*regcache
, const void *buf
)
344 int v0
= find_regno (regcache
->tdesc
, "v0l");
347 for (i
= 0; i
< 16; i
++)
348 supply_register (regcache
, v0
+ i
, (const char *) buf
+ 8 * i
);
352 s390_fill_vxrs_high (struct regcache
*regcache
, void *buf
)
354 int v16
= find_regno (regcache
->tdesc
, "v16");
357 for (i
= 0; i
< 16; i
++)
358 collect_register (regcache
, v16
+ i
, (char *) buf
+ 16 * i
);
362 s390_store_vxrs_high (struct regcache
*regcache
, const void *buf
)
364 int v16
= find_regno (regcache
->tdesc
, "v16");
367 for (i
= 0; i
< 16; i
++)
368 supply_register (regcache
, v16
+ i
, (const char *) buf
+ 16 * i
);
371 static struct regset_info s390_regsets
[] = {
372 { 0, 0, 0, 0, GENERAL_REGS
, s390_fill_gregset
, NULL
},
374 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_HIGH_GPRS
, 0,
375 EXTENDED_REGS
, s390_fill_gprs_high
, s390_store_gprs_high
},
377 /* Last break address is read-only; no fill function. */
378 { PTRACE_GETREGSET
, -1, NT_S390_LAST_BREAK
, 0, EXTENDED_REGS
,
379 NULL
, s390_store_last_break
},
380 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_SYSTEM_CALL
, 0,
381 EXTENDED_REGS
, s390_fill_system_call
, s390_store_system_call
},
382 /* TDB is read-only. */
383 { PTRACE_GETREGSET
, -1, NT_S390_TDB
, 0, EXTENDED_REGS
,
384 NULL
, s390_store_tdb
},
385 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_VXRS_LOW
, 0,
386 EXTENDED_REGS
, s390_fill_vxrs_low
, s390_store_vxrs_low
},
387 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_VXRS_HIGH
, 0,
388 EXTENDED_REGS
, s390_fill_vxrs_high
, s390_store_vxrs_high
},
393 static const gdb_byte s390_breakpoint
[] = { 0, 1 };
394 #define s390_breakpoint_len 2
396 /* Implementation of linux_target_ops method "sw_breakpoint_from_kind". */
398 static const gdb_byte
*
399 s390_sw_breakpoint_from_kind (int kind
, int *size
)
401 *size
= s390_breakpoint_len
;
402 return s390_breakpoint
;
406 s390_get_pc (struct regcache
*regcache
)
408 if (register_size (regcache
->tdesc
, 0) == 4)
411 collect_register_by_name (regcache
, "pswa", &pswa
);
412 return pswa
& 0x7fffffff;
417 collect_register_by_name (regcache
, "pswa", &pc
);
423 s390_set_pc (struct regcache
*regcache
, CORE_ADDR newpc
)
425 if (register_size (regcache
->tdesc
, 0) == 4)
428 collect_register_by_name (regcache
, "pswa", &pswa
);
429 pswa
= (pswa
& 0x80000000) | (newpc
& 0x7fffffff);
430 supply_register_by_name (regcache
, "pswa", &pswa
);
434 unsigned long pc
= newpc
;
435 supply_register_by_name (regcache
, "pswa", &pc
);
440 s390_get_hwcap (const struct target_desc
*tdesc
)
442 int wordsize
= register_size (tdesc
, 0);
443 unsigned char *data
= alloca (2 * wordsize
);
446 while ((*the_target
->read_auxv
) (offset
, data
, 2 * wordsize
) == 2 * wordsize
)
450 unsigned int *data_p
= (unsigned int *)data
;
451 if (data_p
[0] == AT_HWCAP
)
456 unsigned long *data_p
= (unsigned long *)data
;
457 if (data_p
[0] == AT_HWCAP
)
461 offset
+= 2 * wordsize
;
468 s390_check_regset (int pid
, int regset
, int regsize
)
470 gdb_byte
*buf
= alloca (regsize
);
474 iov
.iov_len
= regsize
;
476 if (ptrace (PTRACE_GETREGSET
, pid
, (long) regset
, (long) &iov
) >= 0
482 /* For a 31-bit inferior, whether the kernel supports using the full
484 static int have_hwcap_s390_high_gprs
= 0;
485 static int have_hwcap_s390_vx
= 0;
488 s390_arch_setup (void)
490 const struct target_desc
*tdesc
;
491 struct regset_info
*regset
;
493 /* Check whether the kernel supports extra register sets. */
494 int pid
= pid_of (current_thread
);
495 int have_regset_last_break
496 = s390_check_regset (pid
, NT_S390_LAST_BREAK
, 8);
497 int have_regset_system_call
498 = s390_check_regset (pid
, NT_S390_SYSTEM_CALL
, 4);
499 int have_regset_tdb
= s390_check_regset (pid
, NT_S390_TDB
, 256);
500 int have_regset_vxrs
= s390_check_regset (pid
, NT_S390_VXRS_LOW
, 128)
501 && s390_check_regset (pid
, NT_S390_VXRS_HIGH
, 256);
503 /* Assume 31-bit inferior process. */
504 if (have_regset_system_call
)
505 tdesc
= tdesc_s390_linux32v2
;
506 else if (have_regset_last_break
)
507 tdesc
= tdesc_s390_linux32v1
;
509 tdesc
= tdesc_s390_linux32
;
511 /* On a 64-bit host, check the low bit of the (31-bit) PSWM
512 -- if this is one, we actually have a 64-bit inferior. */
516 struct regcache
*regcache
= new_register_cache (tdesc
);
518 fetch_inferior_registers (regcache
, find_regno (tdesc
, "pswm"));
519 collect_register_by_name (regcache
, "pswm", &pswm
);
520 free_register_cache (regcache
);
526 (s390_get_hwcap (tdesc_s390x_linux64v2
) & HWCAP_S390_TE
) != 0;
527 if (have_regset_vxrs
)
529 (s390_get_hwcap (tdesc_s390x_linux64v2
) & HWCAP_S390_VX
) != 0;
531 if (have_regset_vxrs
)
532 tdesc
= (have_regset_tdb
? tdesc_s390x_tevx_linux64
:
533 tdesc_s390x_vx_linux64
);
534 else if (have_regset_tdb
)
535 tdesc
= tdesc_s390x_te_linux64
;
536 else if (have_regset_system_call
)
537 tdesc
= tdesc_s390x_linux64v2
;
538 else if (have_regset_last_break
)
539 tdesc
= tdesc_s390x_linux64v1
;
541 tdesc
= tdesc_s390x_linux64
;
544 /* For a 31-bit inferior, check whether the kernel supports
545 using the full 64-bit GPRs. */
548 if (s390_get_hwcap (tdesc
) & HWCAP_S390_HIGH_GPRS
)
550 have_hwcap_s390_high_gprs
= 1;
552 have_regset_tdb
= (s390_get_hwcap (tdesc
) & HWCAP_S390_TE
) != 0;
553 if (have_regset_vxrs
)
554 have_regset_vxrs
= (s390_get_hwcap (tdesc
) & HWCAP_S390_VX
) != 0;
556 if (have_regset_vxrs
)
557 tdesc
= (have_regset_tdb
? tdesc_s390_tevx_linux64
:
558 tdesc_s390_vx_linux64
);
559 else if (have_regset_tdb
)
560 tdesc
= tdesc_s390_te_linux64
;
561 else if (have_regset_system_call
)
562 tdesc
= tdesc_s390_linux64v2
;
563 else if (have_regset_last_break
)
564 tdesc
= tdesc_s390_linux64v1
;
566 tdesc
= tdesc_s390_linux64
;
569 have_hwcap_s390_vx
= have_regset_vxrs
;
572 /* Update target_regsets according to available register sets. */
573 for (regset
= s390_regsets
; regset
->size
>= 0; regset
++)
574 if (regset
->get_request
== PTRACE_GETREGSET
)
575 switch (regset
->nt_type
)
578 case NT_S390_HIGH_GPRS
:
579 regset
->size
= have_hwcap_s390_high_gprs
? 64 : 0;
582 case NT_S390_LAST_BREAK
:
583 regset
->size
= have_regset_last_break
? 8 : 0;
585 case NT_S390_SYSTEM_CALL
:
586 regset
->size
= have_regset_system_call
? 4 : 0;
589 regset
->size
= have_regset_tdb
? 256 : 0;
591 case NT_S390_VXRS_LOW
:
592 regset
->size
= have_regset_vxrs
? 128 : 0;
594 case NT_S390_VXRS_HIGH
:
595 regset
->size
= have_regset_vxrs
? 256 : 0;
601 current_process ()->tdesc
= tdesc
;
606 s390_breakpoint_at (CORE_ADDR pc
)
608 unsigned char c
[s390_breakpoint_len
];
609 read_inferior_memory (pc
, c
, s390_breakpoint_len
);
610 return memcmp (c
, s390_breakpoint
, s390_breakpoint_len
) == 0;
613 /* Breakpoint/Watchpoint support. */
615 /* The "supports_z_point_type" linux_target_ops method. */
618 s390_supports_z_point_type (char z_type
)
629 /* Support for hardware single step. */
632 s390_supports_hardware_single_step (void)
637 static struct usrregs_info s390_usrregs_info
=
643 static struct regsets_info s390_regsets_info
=
645 s390_regsets
, /* regsets */
647 NULL
, /* disabled_regsets */
650 static struct regs_info regs_info
=
652 NULL
, /* regset_bitmap */
657 static struct usrregs_info s390_usrregs_info_3264
=
663 static struct regsets_info s390_regsets_info_3264
=
665 s390_regsets
, /* regsets */
667 NULL
, /* disabled_regsets */
670 static struct regs_info regs_info_3264
=
672 NULL
, /* regset_bitmap */
673 &s390_usrregs_info_3264
,
674 &s390_regsets_info_3264
677 static const struct regs_info
*
678 s390_regs_info (void)
680 if (have_hwcap_s390_high_gprs
)
683 const struct target_desc
*tdesc
= current_process ()->tdesc
;
685 if (register_size (tdesc
, 0) == 4)
686 return ®s_info_3264
;
688 return ®s_info_3264
;
694 /* The "supports_tracepoints" linux_target_ops method. */
697 s390_supports_tracepoints (void)
702 /* Implementation of linux_target_ops method "get_thread_area". */
705 s390_get_thread_area (int lwpid
, CORE_ADDR
*addrp
)
707 CORE_ADDR res
= ptrace (PTRACE_PEEKUSER
, lwpid
, (long) PT_ACR0
, (long) 0);
709 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
711 if (register_size (regcache
->tdesc
, 0) == 4)
712 res
&= 0xffffffffull
;
719 /* Fast tracepoint support.
721 The register save area on stack is identical for all targets:
723 0x000+i*0x10: VR0-VR31
730 If we're on 31-bit linux, we just don't store the high parts of the GPRs.
731 Likewise, if there's no VX support, we just store the FRs into the slots
732 of low VR halves. The agent code is responsible for rearranging that
735 /* Code sequence saving GPRs for 31-bit target with no high GPRs. There's
736 one trick used at the very beginning: since there's no way to allocate
737 stack space without destroying CC (lay instruction can do it, but it's
738 only supported on later CPUs), we take 4 different execution paths for
739 every possible value of CC, allocate stack space, save %r0, stuff the
740 CC value in %r0 (shifted to match its position in PSWM high word),
741 then branch to common path. */
743 static const unsigned char s390_ft_entry_gpr_esa
[] = {
744 0xa7, 0x14, 0x00, 0x1e, /* jo .Lcc3 */
745 0xa7, 0x24, 0x00, 0x14, /* jh .Lcc2 */
746 0xa7, 0x44, 0x00, 0x0a, /* jl .Lcc1 */
748 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
749 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
750 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
751 0xa7, 0xf4, 0x00, 0x18, /* j .Lccdone */
753 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
754 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
755 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
756 0xa7, 0xf4, 0x00, 0x10, /* j .Lccdone */
758 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
759 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
760 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
761 0xa7, 0xf4, 0x00, 0x08, /* j .Lccdone */
763 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
764 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
765 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
767 0x50, 0x10, 0xf2, 0x0c, /* st %r1, 0x20c(%r15) */
768 0x50, 0x20, 0xf2, 0x14, /* st %r2, 0x214(%r15) */
769 0x50, 0x30, 0xf2, 0x1c, /* st %r3, 0x21c(%r15) */
770 0x50, 0x40, 0xf2, 0x24, /* st %r4, 0x224(%r15) */
771 0x50, 0x50, 0xf2, 0x2c, /* st %r5, 0x22c(%r15) */
772 0x50, 0x60, 0xf2, 0x34, /* st %r6, 0x234(%r15) */
773 0x50, 0x70, 0xf2, 0x3c, /* st %r7, 0x23c(%r15) */
774 0x50, 0x80, 0xf2, 0x44, /* st %r8, 0x244(%r15) */
775 0x50, 0x90, 0xf2, 0x4c, /* st %r9, 0x24c(%r15) */
776 0x50, 0xa0, 0xf2, 0x54, /* st %r10, 0x254(%r15) */
777 0x50, 0xb0, 0xf2, 0x5c, /* st %r11, 0x25c(%r15) */
778 0x50, 0xc0, 0xf2, 0x64, /* st %r12, 0x264(%r15) */
779 0x50, 0xd0, 0xf2, 0x6c, /* st %r13, 0x26c(%r15) */
780 0x50, 0xe0, 0xf2, 0x74, /* st %r14, 0x274(%r15) */
781 /* Compute original value of %r15 and store it. We use ahi instead
782 of la to preserve the whole value, and not just the low 31 bits.
783 This is not particularly important here, but essential in the
784 zarch case where someone might be using the high word of %r15
785 as an extra register. */
786 0x18, 0x1f, /* lr %r1, %r15 */
787 0xa7, 0x1a, 0x03, 0x00, /* ahi %r1, 0x300 */
788 0x50, 0x10, 0xf2, 0x7c, /* st %r1, 0x27c(%r15) */
791 /* Code sequence saving GPRs for 31-bit target with high GPRs and for 64-bit
792 target. Same as above, except this time we can use load/store multiple,
793 since the 64-bit regs are tightly packed. */
795 static const unsigned char s390_ft_entry_gpr_zarch
[] = {
796 0xa7, 0x14, 0x00, 0x21, /* jo .Lcc3 */
797 0xa7, 0x24, 0x00, 0x16, /* jh .Lcc2 */
798 0xa7, 0x44, 0x00, 0x0b, /* jl .Lcc1 */
800 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
801 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
802 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
803 0xa7, 0xf4, 0x00, 0x1b, /* j .Lccdone */
805 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
806 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
807 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
808 0xa7, 0xf4, 0x00, 0x12, /* j .Lccdone */
810 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
811 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
812 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
813 0xa7, 0xf4, 0x00, 0x09, /* j .Lccdone */
815 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
816 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
817 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
819 0xb9, 0x04, 0x00, 0x1f, /* lgr %r1, %r15 */
820 0xa7, 0x1b, 0x03, 0x00, /* aghi %r1, 0x300 */
821 0xe3, 0x10, 0xf2, 0x78, 0x00, 0x24, /* stg %r1, 0x278(%r15) */
824 /* Code sequence saving ARs, PSWM and FPC. PSWM has to be assembled from
825 current PSWM (read by epsw) and CC from entry (in %r0). */
827 static const unsigned char s390_ft_entry_misc
[] = {
828 0x9b, 0x0f, 0xf2, 0x80, /* stam %a0, %a15, 0x20(%%r15) */
829 0xb9, 0x8d, 0x00, 0x23, /* epsw %r2, %r3 */
830 0xa7, 0x18, 0xcf, 0xff, /* lhi %r1, ~0x3000 */
831 0x14, 0x21, /* nr %r2, %r1 */
832 0x16, 0x20, /* or %r2, %r0 */
833 0x50, 0x20, 0xf2, 0xc0, /* st %r2, 0x2c0(%r15) */
834 0x50, 0x30, 0xf2, 0xc4, /* st %r3, 0x2c4(%r15) */
835 0xb2, 0x9c, 0xf2, 0xd0, /* stfpc 0x2d0(%r15) */
838 /* Code sequence saving FRs, used if VX not supported. */
840 static const unsigned char s390_ft_entry_fr
[] = {
841 0x60, 0x00, 0xf0, 0x00, /* std %f0, 0x000(%r15) */
842 0x60, 0x10, 0xf0, 0x10, /* std %f1, 0x010(%r15) */
843 0x60, 0x20, 0xf0, 0x20, /* std %f2, 0x020(%r15) */
844 0x60, 0x30, 0xf0, 0x30, /* std %f3, 0x030(%r15) */
845 0x60, 0x40, 0xf0, 0x40, /* std %f4, 0x040(%r15) */
846 0x60, 0x50, 0xf0, 0x50, /* std %f5, 0x050(%r15) */
847 0x60, 0x60, 0xf0, 0x60, /* std %f6, 0x060(%r15) */
848 0x60, 0x70, 0xf0, 0x70, /* std %f7, 0x070(%r15) */
849 0x60, 0x80, 0xf0, 0x80, /* std %f8, 0x080(%r15) */
850 0x60, 0x90, 0xf0, 0x90, /* std %f9, 0x090(%r15) */
851 0x60, 0xa0, 0xf0, 0xa0, /* std %f10, 0x0a0(%r15) */
852 0x60, 0xb0, 0xf0, 0xb0, /* std %f11, 0x0b0(%r15) */
853 0x60, 0xc0, 0xf0, 0xc0, /* std %f12, 0x0c0(%r15) */
854 0x60, 0xd0, 0xf0, 0xd0, /* std %f13, 0x0d0(%r15) */
855 0x60, 0xe0, 0xf0, 0xe0, /* std %f14, 0x0e0(%r15) */
856 0x60, 0xf0, 0xf0, 0xf0, /* std %f15, 0x0f0(%r15) */
859 /* Code sequence saving VRs, used if VX not supported. */
861 static const unsigned char s390_ft_entry_vr
[] = {
862 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x3e, /* vstm %v0, %v15, 0x000(%r15) */
863 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x3e, /* vstm %v16, %v31, 0x100(%r15) */
866 /* Code sequence doing the collection call for 31-bit target. %r1 contains
867 the address of the literal pool. */
869 static const unsigned char s390_ft_main_31
[] = {
870 /* Load the literals into registers. */
871 0x58, 0x50, 0x10, 0x00, /* l %r5, 0x0(%r1) */
872 0x58, 0x20, 0x10, 0x04, /* l %r2, 0x4(%r1) */
873 0x58, 0x40, 0x10, 0x08, /* l %r4, 0x8(%r1) */
874 0x58, 0x60, 0x10, 0x0c, /* l %r6, 0xc(%r1) */
875 /* Save original PSWA (tracepoint address | 0x80000000). */
876 0x50, 0x50, 0xf2, 0xcc, /* st %r5, 0x2cc(%r15) */
877 /* Construct a collecting_t object at %r15+0x2e0. */
878 0x50, 0x20, 0xf2, 0xe0, /* st %r2, 0x2e0(%r15) */
879 0x9b, 0x00, 0xf2, 0xe4, /* stam %a0, %a0, 0x2e4(%r15) */
880 /* Move its address to %r0. */
881 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
884 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
885 0xba, 0x10, 0x60, 0x00, /* cs %r1, %r0, 0(%r6) */
886 0xa7, 0x74, 0xff, 0xfc, /* jne .Lloop */
887 /* Address of the register save block to %r3. */
888 0x18, 0x3f, /* lr %r3, %r15 */
889 /* Make a stack frame, so that we can call the collector. */
890 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
892 0x0d, 0xe4, /* basr %r14, %r4 */
893 /* And get rid of the stack frame again. */
894 0x41, 0xf0, 0xf0, 0x60, /* la %r15, 0x60(%r15) */
895 /* Leave the lock. */
896 0x07, 0xf0, /* br %r0 */
897 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
898 0x50, 0x10, 0x60, 0x00, /* st %t1, 0(%r6) */
901 /* Code sequence doing the collection call for 64-bit target. %r1 contains
902 the address of the literal pool. */
904 static const unsigned char s390_ft_main_64
[] = {
905 /* Load the literals into registers. */
906 0xe3, 0x50, 0x10, 0x00, 0x00, 0x04, /* lg %r5, 0x00(%r1) */
907 0xe3, 0x20, 0x10, 0x08, 0x00, 0x04, /* lg %r2, 0x08(%r1) */
908 0xe3, 0x40, 0x10, 0x10, 0x00, 0x04, /* lg %r4, 0x10(%r1) */
909 0xe3, 0x60, 0x10, 0x18, 0x00, 0x04, /* lg %r6, 0x18(%r1) */
910 /* Save original PSWA (tracepoint address). */
911 0xe3, 0x50, 0xf2, 0xc8, 0x00, 0x24, /* stg %r5, 0x2c8(%r15) */
912 /* Construct a collecting_t object at %r15+0x2e0. */
913 0xe3, 0x20, 0xf2, 0xe0, 0x00, 0x24, /* stg %r2, 0x2e0(%r15) */
914 0x9b, 0x01, 0xf2, 0xe8, /* stam %a0, %a1, 0x2e8(%r15) */
915 /* Move its address to %r0. */
916 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
919 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
920 0xeb, 0x10, 0x60, 0x00, 0x00, 0x30, /* csg %r1, %r0, 0(%r6) */
921 0xa7, 0x74, 0xff, 0xfb, /* jne .Lloop */
922 /* Address of the register save block to %r3. */
923 0xb9, 0x04, 0x00, 0x3f, /* lgr %r3, %r15 */
924 /* Make a stack frame, so that we can call the collector. */
925 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
927 0x0d, 0xe4, /* basr %r14, %r4 */
928 /* And get rid of the stack frame again. */
929 0x41, 0xf0, 0xf0, 0xa0, /* la %r15, 0xa0(%r15) */
930 /* Leave the lock. */
931 0x07, 0xf0, /* br %r0 */
932 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
933 0xe3, 0x10, 0x60, 0x00, 0x00, 0x24, /* stg %t1, 0(%r6) */
936 /* Code sequence restoring FRs, for targets with no VX support. */
938 static const unsigned char s390_ft_exit_fr
[] = {
939 0x68, 0x00, 0xf0, 0x00, /* ld %f0, 0x000(%r15) */
940 0x68, 0x10, 0xf0, 0x10, /* ld %f1, 0x010(%r15) */
941 0x68, 0x20, 0xf0, 0x20, /* ld %f2, 0x020(%r15) */
942 0x68, 0x30, 0xf0, 0x30, /* ld %f3, 0x030(%r15) */
943 0x68, 0x40, 0xf0, 0x40, /* ld %f4, 0x040(%r15) */
944 0x68, 0x50, 0xf0, 0x50, /* ld %f5, 0x050(%r15) */
945 0x68, 0x60, 0xf0, 0x60, /* ld %f6, 0x060(%r15) */
946 0x68, 0x70, 0xf0, 0x70, /* ld %f7, 0x070(%r15) */
947 0x68, 0x80, 0xf0, 0x80, /* ld %f8, 0x080(%r15) */
948 0x68, 0x90, 0xf0, 0x90, /* ld %f9, 0x090(%r15) */
949 0x68, 0xa0, 0xf0, 0xa0, /* ld %f10, 0x0a0(%r15) */
950 0x68, 0xb0, 0xf0, 0xb0, /* ld %f11, 0x0b0(%r15) */
951 0x68, 0xc0, 0xf0, 0xc0, /* ld %f12, 0x0c0(%r15) */
952 0x68, 0xd0, 0xf0, 0xd0, /* ld %f13, 0x0d0(%r15) */
953 0x68, 0xe0, 0xf0, 0xe0, /* ld %f14, 0x0e0(%r15) */
954 0x68, 0xf0, 0xf0, 0xf0, /* ld %f15, 0x0f0(%r15) */
957 /* Code sequence restoring VRs. */
959 static const unsigned char s390_ft_exit_vr
[] = {
960 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x36, /* vlm %v0, %v15, 0x000(%r15) */
961 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x36, /* vlm %v16, %v31, 0x100(%r15) */
964 /* Code sequence restoring misc registers. As for PSWM, only CC should be
965 modified by C code, so we use the alr instruction to restore it by
966 manufacturing an operand that'll result in the original flags. */
968 static const unsigned char s390_ft_exit_misc
[] = {
969 0xb2, 0x9d, 0xf2, 0xd0, /* lfpc 0x2d0(%r15) */
970 0x58, 0x00, 0xf2, 0xc0, /* l %r0, 0x2c0(%r15) */
971 /* Extract CC to high 2 bits of %r0. */
972 0x88, 0x00, 0x00, 0x0c, /* srl %r0, 12 */
973 0x89, 0x00, 0x00, 0x1e, /* sll %r0, 30 */
974 /* Add %r0 to itself. Result will be nonzero iff CC bit 0 is set, and
975 will have carry iff CC bit 1 is set - resulting in the same flags
977 0x1e, 0x00, /* alr %r0, %r0 */
978 0x9a, 0x0f, 0xf2, 0x80, /* lam %a0, %a15, 0x280(%r15) */
981 /* Code sequence restoring GPRs, for 31-bit targets with no high GPRs. */
983 static const unsigned char s390_ft_exit_gpr_esa
[] = {
984 0x58, 0x00, 0xf2, 0x04, /* l %r0, 0x204(%r15) */
985 0x58, 0x10, 0xf2, 0x0c, /* l %r1, 0x20c(%r15) */
986 0x58, 0x20, 0xf2, 0x14, /* l %r2, 0x214(%r15) */
987 0x58, 0x30, 0xf2, 0x1c, /* l %r3, 0x21c(%r15) */
988 0x58, 0x40, 0xf2, 0x24, /* l %r4, 0x224(%r15) */
989 0x58, 0x50, 0xf2, 0x2c, /* l %r5, 0x22c(%r15) */
990 0x58, 0x60, 0xf2, 0x34, /* l %r6, 0x234(%r15) */
991 0x58, 0x70, 0xf2, 0x3c, /* l %r7, 0x23c(%r15) */
992 0x58, 0x80, 0xf2, 0x44, /* l %r8, 0x244(%r15) */
993 0x58, 0x90, 0xf2, 0x4c, /* l %r9, 0x24c(%r15) */
994 0x58, 0xa0, 0xf2, 0x54, /* l %r10, 0x254(%r15) */
995 0x58, 0xb0, 0xf2, 0x5c, /* l %r11, 0x25c(%r15) */
996 0x58, 0xc0, 0xf2, 0x64, /* l %r12, 0x264(%r15) */
997 0x58, 0xd0, 0xf2, 0x6c, /* l %r13, 0x26c(%r15) */
998 0x58, 0xe0, 0xf2, 0x74, /* l %r14, 0x274(%r15) */
999 0x58, 0xf0, 0xf2, 0x7c, /* l %r15, 0x27c(%r15) */
1002 /* Code sequence restoring GPRs, for 64-bit targets and 31-bit targets
1005 static const unsigned char s390_ft_exit_gpr_zarch
[] = {
1006 0xeb, 0x0f, 0xf2, 0x00, 0x00, 0x04, /* lmg %r0, %r15, 0x200(%r15) */
1009 /* Writes instructions to target, updating the to pointer. */
1012 append_insns (CORE_ADDR
*to
, size_t len
, const unsigned char *buf
)
1014 write_inferior_memory (*to
, buf
, len
);
1018 /* Relocates an instruction from oldloc to *to, updating to. */
1021 s390_relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
, int is_64
)
1026 /* 0: no fixup, 1: PC16DBL fixup, 2: PC32DBL fixup. */
1029 read_inferior_memory (oldloc
, buf
, sizeof buf
);
1032 else if (buf
[0] < 0xc0)
1038 case 0x05: /* BALR */
1039 case 0x0c: /* BASSM */
1040 case 0x0d: /* BASR */
1041 case 0x45: /* BAL */
1042 case 0x4d: /* BAS */
1043 /* These save a return address and mess around with registers.
1044 We can't relocate them. */
1046 case 0x84: /* BRXH */
1047 case 0x85: /* BRXLE */
1052 /* BRC, BRAS, BRCT, BRCTG */
1053 if (op2
>= 4 && op2
<= 7)
1061 /* LARL, BRCL, BRASL */
1062 if (op2
== 0 || op2
== 4 || op2
== 5)
1070 /* PC-relative addressing instructions. */
1073 case 0xc5: /* BPRP */
1074 case 0xc7: /* BPP */
1075 /* Branch prediction - just skip it. */
1087 case 0x44: /* BRXHG */
1088 case 0x45: /* BRXLG */
1089 case 0x64: /* CGRJ */
1090 case 0x65: /* CLGRJ */
1091 case 0x76: /* CRJ */
1092 case 0x77: /* CLRJ */
1101 /* We'll have to relocate an instruction with a PC-relative field.
1102 First, compute the target. */
1103 int64_t loffset
= 0;
1107 int16_t soffset
= 0;
1108 memcpy (&soffset
, buf
+ 2, 2);
1113 int32_t soffset
= 0;
1114 memcpy (&soffset
, buf
+ 2, 4);
1117 target
= oldloc
+ loffset
* 2;
1119 target
&= 0x7fffffff;
1123 /* BRAS or BRASL was used. We cannot just relocate those, since
1124 they save the return address in a register. We can, however,
1125 replace them with a LARL+JG sequence. */
1127 /* Make the LARL. */
1131 loffset
= oldloc
+ ilen
- *to
;
1134 if (soffset
!= loffset
&& is_64
)
1136 memcpy (buf
+ 2, &soffset
, 4);
1137 append_insns (to
, 6, buf
);
1139 /* Note: this is not fully correct. In 31-bit mode, LARL will write
1140 an address with the top bit 0, while BRAS/BRASL will write it
1141 with top bit 1. It should not matter much, since linux compilers
1142 use BR and not BSM to return from functions, but it could confuse
1143 some poor stack unwinder. */
1145 /* We'll now be writing a JG. */
1152 /* Compute the new offset and write it to the buffer. */
1153 loffset
= target
- *to
;
1158 int16_t soffset
= loffset
;
1159 if (soffset
!= loffset
)
1161 memcpy (buf
+ 2, &soffset
, 2);
1165 int32_t soffset
= loffset
;
1166 if (soffset
!= loffset
&& is_64
)
1168 memcpy (buf
+ 2, &soffset
, 4);
1171 append_insns (to
, ilen
, buf
);
1175 /* Implementation of linux_target_ops method
1176 "install_fast_tracepoint_jump_pad". */
1179 s390_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint
,
1181 CORE_ADDR collector
,
1184 CORE_ADDR
*jump_entry
,
1185 CORE_ADDR
*trampoline
,
1186 ULONGEST
*trampoline_size
,
1187 unsigned char *jjump_pad_insn
,
1188 ULONGEST
*jjump_pad_insn_size
,
1189 CORE_ADDR
*adjusted_insn_addr
,
1190 CORE_ADDR
*adjusted_insn_addr_end
,
1196 unsigned char jbuf
[6] = { 0xc0, 0xf4, 0, 0, 0, 0 }; /* jg ... */
1197 CORE_ADDR buildaddr
= *jump_entry
;
1199 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1200 int is_64
= register_size (regcache
->tdesc
, 0) == 8;
1201 int is_zarch
= is_64
|| have_hwcap_s390_high_gprs
;
1202 int has_vx
= have_hwcap_s390_vx
;
1204 int is_64
= 0, is_zarch
= 0, has_vx
= 0;
1206 CORE_ADDR literals
[4] = {
1213 /* First, store the GPRs. */
1215 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_zarch
,
1216 s390_ft_entry_gpr_zarch
);
1218 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_esa
,
1219 s390_ft_entry_gpr_esa
);
1221 /* Second, misc registers (ARs, PSWM, FPC). PSWA will be stored below. */
1222 append_insns (&buildaddr
, sizeof s390_ft_entry_misc
, s390_ft_entry_misc
);
1224 /* Third, FRs or VRs. */
1226 append_insns (&buildaddr
, sizeof s390_ft_entry_vr
, s390_ft_entry_vr
);
1228 append_insns (&buildaddr
, sizeof s390_ft_entry_fr
, s390_ft_entry_fr
);
1230 /* Now, the main part of code - store PSWA, take lock, call collector,
1231 leave lock. First, we'll need to fetch 4 literals. */
1233 unsigned char buf
[] = {
1234 0x07, 0x07, /* nopr %r7 */
1235 0x07, 0x07, /* nopr %r7 */
1236 0x07, 0x07, /* nopr %r7 */
1237 0xa7, 0x15, 0x00, 0x12, /* bras %r1, .Lend */
1238 0, 0, 0, 0, 0, 0, 0, 0, /* tpaddr */
1239 0, 0, 0, 0, 0, 0, 0, 0, /* tpoint */
1240 0, 0, 0, 0, 0, 0, 0, 0, /* collector */
1241 0, 0, 0, 0, 0, 0, 0, 0, /* lockaddr */
1244 /* Find the proper start place in buf, so that literals will be
1246 int bufpos
= (buildaddr
+ 2) & 7;
1247 /* Stuff the literals into the buffer. */
1248 for (i
= 0; i
< 4; i
++) {
1249 uint64_t lit
= literals
[i
];
1250 memcpy (&buf
[sizeof buf
- 32 + i
* 8], &lit
, 8);
1252 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1253 append_insns (&buildaddr
, sizeof s390_ft_main_64
, s390_ft_main_64
);
1255 unsigned char buf
[] = {
1256 0x07, 0x07, /* nopr %r7 */
1257 0xa7, 0x15, 0x00, 0x0a, /* bras %r1, .Lend */
1258 0, 0, 0, 0, /* tpaddr */
1259 0, 0, 0, 0, /* tpoint */
1260 0, 0, 0, 0, /* collector */
1261 0, 0, 0, 0, /* lockaddr */
1264 /* Find the proper start place in buf, so that literals will be
1266 int bufpos
= (buildaddr
+ 2) & 3;
1267 /* First literal will be saved as the PSWA, make sure it has the high bit
1269 literals
[0] |= 0x80000000;
1270 /* Stuff the literals into the buffer. */
1271 for (i
= 0; i
< 4; i
++) {
1272 uint32_t lit
= literals
[i
];
1273 memcpy (&buf
[sizeof buf
- 16 + i
* 4], &lit
, 4);
1275 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1276 append_insns (&buildaddr
, sizeof s390_ft_main_31
, s390_ft_main_31
);
1279 /* Restore FRs or VRs. */
1281 append_insns (&buildaddr
, sizeof s390_ft_exit_vr
, s390_ft_exit_vr
);
1283 append_insns (&buildaddr
, sizeof s390_ft_exit_fr
, s390_ft_exit_fr
);
1285 /* Restore misc registers. */
1286 append_insns (&buildaddr
, sizeof s390_ft_exit_misc
, s390_ft_exit_misc
);
1288 /* Restore the GPRs. */
1290 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_zarch
,
1291 s390_ft_exit_gpr_zarch
);
1293 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_esa
,
1294 s390_ft_exit_gpr_esa
);
1296 /* Now, adjust the original instruction to execute in the jump
1298 *adjusted_insn_addr
= buildaddr
;
1299 if (s390_relocate_instruction (&buildaddr
, tpaddr
, is_64
))
1301 sprintf (err
, "E.Could not relocate instruction for tracepoint.");
1304 *adjusted_insn_addr_end
= buildaddr
;
1306 /* Finally, write a jump back to the program. */
1308 loffset
= (tpaddr
+ orig_size
) - buildaddr
;
1311 if (is_64
&& offset
!= loffset
)
1314 "E.Jump back from jump pad too far from tracepoint "
1315 "(offset 0x%" PRIx64
" > int33).", loffset
);
1318 memcpy (jbuf
+ 2, &offset
, 4);
1319 append_insns (&buildaddr
, sizeof jbuf
, jbuf
);
1321 /* The jump pad is now built. Wire in a jump to our jump pad. This
1322 is always done last (by our caller actually), so that we can
1323 install fast tracepoints with threads running. This relies on
1324 the agent's atomic write support. */
1325 loffset
= *jump_entry
- tpaddr
;
1328 if (is_64
&& offset
!= loffset
)
1331 "E.Jump back from jump pad too far from tracepoint "
1332 "(offset 0x%" PRIx64
" > int33).", loffset
);
1335 memcpy (jbuf
+ 2, &offset
, 4);
1336 memcpy (jjump_pad_insn
, jbuf
, sizeof jbuf
);
1337 *jjump_pad_insn_size
= sizeof jbuf
;
1339 /* Return the end address of our pad. */
1340 *jump_entry
= buildaddr
;
1345 /* Implementation of linux_target_ops method
1346 "get_min_fast_tracepoint_insn_len". */
1349 s390_get_min_fast_tracepoint_insn_len (void)
1351 /* We only support using 6-byte jumps to reach the tracepoint code.
1352 If the tracepoint buffer were allocated sufficiently close (64kiB)
1353 to the executable code, and the traced instruction itself was close
1354 enough to the beginning, we could use 4-byte jumps, but this doesn't
1355 seem to be worth the effort. */
1359 /* Implementation of linux_target_ops method "get_ipa_tdesc_idx". */
1362 s390_get_ipa_tdesc_idx (void)
1364 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1365 const struct target_desc
*tdesc
= regcache
->tdesc
;
1368 if (tdesc
== tdesc_s390x_linux64
)
1369 return S390_TDESC_64
;
1370 if (tdesc
== tdesc_s390x_linux64v1
)
1371 return S390_TDESC_64V1
;
1372 if (tdesc
== tdesc_s390x_linux64v2
)
1373 return S390_TDESC_64V2
;
1374 if (tdesc
== tdesc_s390x_te_linux64
)
1375 return S390_TDESC_TE
;
1376 if (tdesc
== tdesc_s390x_vx_linux64
)
1377 return S390_TDESC_VX
;
1378 if (tdesc
== tdesc_s390x_tevx_linux64
)
1379 return S390_TDESC_TEVX
;
1382 if (tdesc
== tdesc_s390_linux32
)
1383 return S390_TDESC_32
;
1384 if (tdesc
== tdesc_s390_linux32v1
)
1385 return S390_TDESC_32V1
;
1386 if (tdesc
== tdesc_s390_linux32v2
)
1387 return S390_TDESC_32V2
;
1388 if (tdesc
== tdesc_s390_linux64
)
1389 return S390_TDESC_64
;
1390 if (tdesc
== tdesc_s390_linux64v1
)
1391 return S390_TDESC_64V1
;
1392 if (tdesc
== tdesc_s390_linux64v2
)
1393 return S390_TDESC_64V2
;
1394 if (tdesc
== tdesc_s390_te_linux64
)
1395 return S390_TDESC_TE
;
1396 if (tdesc
== tdesc_s390_vx_linux64
)
1397 return S390_TDESC_VX
;
1398 if (tdesc
== tdesc_s390_tevx_linux64
)
1399 return S390_TDESC_TEVX
;
1404 struct linux_target_ops the_low_target
= {
1407 s390_cannot_fetch_register
,
1408 s390_cannot_store_register
,
1409 NULL
, /* fetch_register */
1412 NULL
, /* breakpoint_kind_from_pc */
1413 s390_sw_breakpoint_from_kind
,
1415 s390_breakpoint_len
,
1417 s390_supports_z_point_type
,
1422 s390_collect_ptrace_register
,
1423 s390_supply_ptrace_register
,
1424 NULL
, /* siginfo_fixup */
1425 NULL
, /* new_process */
1426 NULL
, /* new_thread */
1427 NULL
, /* new_fork */
1428 NULL
, /* prepare_to_resume */
1429 NULL
, /* process_qsupported */
1430 s390_supports_tracepoints
,
1431 s390_get_thread_area
,
1432 s390_install_fast_tracepoint_jump_pad
,
1433 NULL
, /* emit_ops */
1434 s390_get_min_fast_tracepoint_insn_len
,
1435 NULL
, /* supports_range_stepping */
1436 NULL
, /* breakpoint_kind_from_current_state */
1437 s390_supports_hardware_single_step
,
1438 NULL
, /* get_syscall_trapinfo */
1439 s390_get_ipa_tdesc_idx
,
1443 initialize_low_arch (void)
1445 /* Initialize the Linux target descriptions. */
1447 init_registers_s390_linux32 ();
1448 init_registers_s390_linux32v1 ();
1449 init_registers_s390_linux32v2 ();
1450 init_registers_s390_linux64 ();
1451 init_registers_s390_linux64v1 ();
1452 init_registers_s390_linux64v2 ();
1453 init_registers_s390_te_linux64 ();
1454 init_registers_s390_vx_linux64 ();
1455 init_registers_s390_tevx_linux64 ();
1457 init_registers_s390x_linux64 ();
1458 init_registers_s390x_linux64v1 ();
1459 init_registers_s390x_linux64v2 ();
1460 init_registers_s390x_te_linux64 ();
1461 init_registers_s390x_vx_linux64 ();
1462 init_registers_s390x_tevx_linux64 ();
1465 initialize_regsets_info (&s390_regsets_info
);
1466 initialize_regsets_info (&s390_regsets_info_3264
);