1 /* GNU/Linux S/390 specific low level interface, for the remote server
3 Copyright (C) 2001-2020 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 "tracepoint.h"
28 #include <asm/ptrace.h>
29 #include "nat/gdb_ptrace.h"
34 #include "linux-s390-tdesc.h"
36 #ifndef HWCAP_S390_HIGH_GPRS
37 #define HWCAP_S390_HIGH_GPRS 512
41 #define HWCAP_S390_TE 1024
45 #define HWCAP_S390_VX 2048
49 #define HWCAP_S390_GS 16384
52 #define s390_num_regs 52
54 /* Linux target op definitions for the S/390 architecture. */
56 class s390_target
: public linux_process_target
60 const regs_info
*get_regs_info () override
;
62 const gdb_byte
*sw_breakpoint_from_kind (int kind
, int *size
) override
;
66 void low_arch_setup () override
;
68 bool low_cannot_fetch_register (int regno
) override
;
70 bool low_cannot_store_register (int regno
) override
;
72 bool low_supports_breakpoints () override
;
74 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
76 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
78 int low_decr_pc_after_break () override
;
81 /* The singleton target ops object. */
83 static s390_target the_s390_target
;
85 static int s390_regmap
[] = {
86 PT_PSWMASK
, PT_PSWADDR
,
88 PT_GPR0
, PT_GPR1
, PT_GPR2
, PT_GPR3
,
89 PT_GPR4
, PT_GPR5
, PT_GPR6
, PT_GPR7
,
90 PT_GPR8
, PT_GPR9
, PT_GPR10
, PT_GPR11
,
91 PT_GPR12
, PT_GPR13
, PT_GPR14
, 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
,
101 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
102 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
103 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
104 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
106 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
107 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
108 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
109 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
115 #define s390_num_regs_3264 68
118 static int s390_regmap_3264
[] = {
119 PT_PSWMASK
, PT_PSWADDR
,
121 PT_GPR0
, PT_GPR0
, PT_GPR1
, PT_GPR1
,
122 PT_GPR2
, PT_GPR2
, PT_GPR3
, PT_GPR3
,
123 PT_GPR4
, PT_GPR4
, PT_GPR5
, PT_GPR5
,
124 PT_GPR6
, PT_GPR6
, PT_GPR7
, PT_GPR7
,
125 PT_GPR8
, PT_GPR8
, PT_GPR9
, PT_GPR9
,
126 PT_GPR10
, PT_GPR10
, PT_GPR11
, PT_GPR11
,
127 PT_GPR12
, PT_GPR12
, PT_GPR13
, PT_GPR13
,
128 PT_GPR14
, PT_GPR14
, PT_GPR15
, PT_GPR15
,
130 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
131 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
132 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
133 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
137 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
138 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
139 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
140 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
145 static int s390_regmap_3264
[] = {
146 PT_PSWMASK
, PT_PSWADDR
,
148 -1, PT_GPR0
, -1, PT_GPR1
,
149 -1, PT_GPR2
, -1, PT_GPR3
,
150 -1, PT_GPR4
, -1, PT_GPR5
,
151 -1, PT_GPR6
, -1, PT_GPR7
,
152 -1, PT_GPR8
, -1, PT_GPR9
,
153 -1, PT_GPR10
, -1, PT_GPR11
,
154 -1, PT_GPR12
, -1, PT_GPR13
,
155 -1, PT_GPR14
, -1, PT_GPR15
,
157 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
158 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
159 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
160 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
164 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
165 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
166 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
167 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
175 s390_target::low_cannot_fetch_register (int regno
)
181 s390_target::low_cannot_store_register (int regno
)
187 s390_collect_ptrace_register (struct regcache
*regcache
, int regno
, char *buf
)
189 int size
= register_size (regcache
->tdesc
, regno
);
190 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
191 struct usrregs_info
*usr
= regs_info
->usrregs
;
192 int regaddr
= usr
->regmap
[regno
];
194 if (size
< sizeof (long))
196 memset (buf
, 0, sizeof (long));
198 if ((regno
^ 1) < usr
->num_regs
199 && usr
->regmap
[regno
^ 1] == regaddr
)
201 collect_register (regcache
, regno
& ~1, buf
);
202 collect_register (regcache
, (regno
& ~1) + 1,
203 buf
+ sizeof (long) - size
);
205 else if (regaddr
== PT_PSWMASK
)
207 /* Convert 4-byte PSW mask to 8 bytes by clearing bit 12 and copying
208 the basic addressing mode bit from the PSW address. */
209 gdb_byte
*addr
= (gdb_byte
*) alloca (register_size (regcache
->tdesc
, regno
^ 1));
210 collect_register (regcache
, regno
, buf
);
211 collect_register (regcache
, regno
^ 1, addr
);
213 buf
[size
] |= (addr
[0] & 0x80);
215 else if (regaddr
== PT_PSWADDR
)
217 /* Convert 4-byte PSW address to 8 bytes by clearing the addressing
218 mode bit (which gets copied to the PSW mask instead). */
219 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
220 buf
[sizeof (long) - size
] &= ~0x80;
222 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
223 || regaddr
== PT_ORIGGPR2
)
224 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
226 collect_register (regcache
, regno
, buf
);
228 else if (regaddr
!= -1)
229 collect_register (regcache
, regno
, buf
);
233 s390_supply_ptrace_register (struct regcache
*regcache
,
234 int regno
, const char *buf
)
236 int size
= register_size (regcache
->tdesc
, regno
);
237 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
238 struct usrregs_info
*usr
= regs_info
->usrregs
;
239 int regaddr
= usr
->regmap
[regno
];
241 if (size
< sizeof (long))
243 if ((regno
^ 1) < usr
->num_regs
244 && usr
->regmap
[regno
^ 1] == regaddr
)
246 supply_register (regcache
, regno
& ~1, buf
);
247 supply_register (regcache
, (regno
& ~1) + 1,
248 buf
+ sizeof (long) - size
);
250 else if (regaddr
== PT_PSWMASK
)
252 /* Convert 8-byte PSW mask to 4 bytes by setting bit 12 and copying
253 the basic addressing mode into the PSW address. */
254 gdb_byte
*mask
= (gdb_byte
*) alloca (size
);
255 gdb_byte
*addr
= (gdb_byte
*) alloca (register_size (regcache
->tdesc
, regno
^ 1));
256 memcpy (mask
, buf
, size
);
258 supply_register (regcache
, regno
, mask
);
260 collect_register (regcache
, regno
^ 1, addr
);
262 addr
[0] |= (buf
[size
] & 0x80);
263 supply_register (regcache
, regno
^ 1, addr
);
265 else if (regaddr
== PT_PSWADDR
)
267 /* Convert 8-byte PSW address to 4 bytes by truncating, but
268 keeping the addressing mode bit (which was set from the mask). */
269 gdb_byte
*addr
= (gdb_byte
*) alloca (size
);
271 collect_register (regcache
, regno
, addr
);
272 amode
= addr
[0] & 0x80;
273 memcpy (addr
, buf
+ sizeof (long) - size
, size
);
276 supply_register (regcache
, regno
, addr
);
278 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
279 || regaddr
== PT_ORIGGPR2
)
280 supply_register (regcache
, regno
, buf
+ sizeof (long) - size
);
282 supply_register (regcache
, regno
, buf
);
284 else if (regaddr
!= -1)
285 supply_register (regcache
, regno
, buf
);
288 /* Provide only a fill function for the general register set. ps_lgetregs
289 will use this for NPTL support. */
292 s390_fill_gregset (struct regcache
*regcache
, void *buf
)
295 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
296 struct usrregs_info
*usr
= regs_info
->usrregs
;
298 for (i
= 0; i
< usr
->num_regs
; i
++)
300 if (usr
->regmap
[i
] < PT_PSWMASK
301 || usr
->regmap
[i
] > PT_ACR15
)
304 s390_collect_ptrace_register (regcache
, i
,
305 (char *) buf
+ usr
->regmap
[i
]);
309 /* Fill and store functions for extended register sets. */
313 s390_fill_gprs_high (struct regcache
*regcache
, void *buf
)
315 int r0h
= find_regno (regcache
->tdesc
, "r0h");
318 for (i
= 0; i
< 16; i
++)
319 collect_register (regcache
, r0h
+ 2 * i
, (char *) buf
+ 4 * i
);
323 s390_store_gprs_high (struct regcache
*regcache
, const void *buf
)
325 int r0h
= find_regno (regcache
->tdesc
, "r0h");
328 for (i
= 0; i
< 16; i
++)
329 supply_register (regcache
, r0h
+ 2 * i
, (const char *) buf
+ 4 * i
);
334 s390_store_last_break (struct regcache
*regcache
, const void *buf
)
338 p
= (const char *) buf
+ 8 - register_size (regcache
->tdesc
, 0);
339 supply_register_by_name (regcache
, "last_break", p
);
343 s390_fill_system_call (struct regcache
*regcache
, void *buf
)
345 collect_register_by_name (regcache
, "system_call", buf
);
349 s390_store_system_call (struct regcache
*regcache
, const void *buf
)
351 supply_register_by_name (regcache
, "system_call", buf
);
355 s390_store_tdb (struct regcache
*regcache
, const void *buf
)
357 int tdb0
= find_regno (regcache
->tdesc
, "tdb0");
358 int tr0
= find_regno (regcache
->tdesc
, "tr0");
361 for (i
= 0; i
< 4; i
++)
362 supply_register (regcache
, tdb0
+ i
, (const char *) buf
+ 8 * i
);
364 for (i
= 0; i
< 16; i
++)
365 supply_register (regcache
, tr0
+ i
, (const char *) buf
+ 8 * (16 + i
));
369 s390_fill_vxrs_low (struct regcache
*regcache
, void *buf
)
371 int v0
= find_regno (regcache
->tdesc
, "v0l");
374 for (i
= 0; i
< 16; i
++)
375 collect_register (regcache
, v0
+ i
, (char *) buf
+ 8 * i
);
379 s390_store_vxrs_low (struct regcache
*regcache
, const void *buf
)
381 int v0
= find_regno (regcache
->tdesc
, "v0l");
384 for (i
= 0; i
< 16; i
++)
385 supply_register (regcache
, v0
+ i
, (const char *) buf
+ 8 * i
);
389 s390_fill_vxrs_high (struct regcache
*regcache
, void *buf
)
391 int v16
= find_regno (regcache
->tdesc
, "v16");
394 for (i
= 0; i
< 16; i
++)
395 collect_register (regcache
, v16
+ i
, (char *) buf
+ 16 * i
);
399 s390_store_vxrs_high (struct regcache
*regcache
, const void *buf
)
401 int v16
= find_regno (regcache
->tdesc
, "v16");
404 for (i
= 0; i
< 16; i
++)
405 supply_register (regcache
, v16
+ i
, (const char *) buf
+ 16 * i
);
409 s390_store_gs (struct regcache
*regcache
, const void *buf
)
411 int gsd
= find_regno (regcache
->tdesc
, "gsd");
414 for (i
= 0; i
< 3; i
++)
415 supply_register (regcache
, gsd
+ i
, (const char *) buf
+ 8 * (i
+ 1));
419 s390_store_gsbc (struct regcache
*regcache
, const void *buf
)
421 int bc_gsd
= find_regno (regcache
->tdesc
, "bc_gsd");
424 for (i
= 0; i
< 3; i
++)
425 supply_register (regcache
, bc_gsd
+ i
, (const char *) buf
+ 8 * (i
+ 1));
428 static struct regset_info s390_regsets
[] = {
429 { 0, 0, 0, 0, GENERAL_REGS
, s390_fill_gregset
, NULL
},
431 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_HIGH_GPRS
, 0,
432 EXTENDED_REGS
, s390_fill_gprs_high
, s390_store_gprs_high
},
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 /* Guarded storage registers are read-only. */
447 { PTRACE_GETREGSET
, -1, NT_S390_GS_CB
, 0, EXTENDED_REGS
,
448 NULL
, s390_store_gs
},
449 { PTRACE_GETREGSET
, -1, NT_S390_GS_BC
, 0, EXTENDED_REGS
,
450 NULL
, s390_store_gsbc
},
455 static const gdb_byte s390_breakpoint
[] = { 0, 1 };
456 #define s390_breakpoint_len 2
458 /* Implementation of target ops method "sw_breakpoint_from_kind". */
461 s390_target::sw_breakpoint_from_kind (int kind
, int *size
)
463 *size
= s390_breakpoint_len
;
464 return s390_breakpoint
;
468 s390_target::low_supports_breakpoints ()
474 s390_target::low_get_pc (regcache
*regcache
)
476 if (register_size (regcache
->tdesc
, 0) == 4)
479 collect_register_by_name (regcache
, "pswa", &pswa
);
480 return pswa
& 0x7fffffff;
485 collect_register_by_name (regcache
, "pswa", &pc
);
491 s390_target::low_set_pc (regcache
*regcache
, CORE_ADDR newpc
)
493 if (register_size (regcache
->tdesc
, 0) == 4)
496 collect_register_by_name (regcache
, "pswa", &pswa
);
497 pswa
= (pswa
& 0x80000000) | (newpc
& 0x7fffffff);
498 supply_register_by_name (regcache
, "pswa", &pswa
);
502 unsigned long pc
= newpc
;
503 supply_register_by_name (regcache
, "pswa", &pc
);
508 s390_target::low_decr_pc_after_break ()
510 return s390_breakpoint_len
;
513 /* Determine the word size for the given PID, in bytes. */
517 s390_get_wordsize (int pid
)
520 PTRACE_XFER_TYPE pswm
= ptrace (PTRACE_PEEKUSER
, pid
,
521 (PTRACE_TYPE_ARG3
) 0,
522 (PTRACE_TYPE_ARG4
) 0);
525 warning (_("Couldn't determine word size, assuming 64-bit."));
528 /* Derive word size from extended addressing mode (PSW bit 31). */
529 return pswm
& (1L << 32) ? 8 : 4;
532 #define s390_get_wordsize(pid) 4
536 s390_check_regset (int pid
, int regset
, int regsize
)
538 void *buf
= alloca (regsize
);
542 iov
.iov_len
= regsize
;
544 if (ptrace (PTRACE_GETREGSET
, pid
, (long) regset
, (long) &iov
) >= 0
550 /* For a 31-bit inferior, whether the kernel supports using the full
552 static int have_hwcap_s390_high_gprs
= 0;
553 static int have_hwcap_s390_vx
= 0;
556 s390_target::low_arch_setup ()
558 const struct target_desc
*tdesc
;
559 struct regset_info
*regset
;
561 /* Determine word size and HWCAP. */
562 int pid
= pid_of (current_thread
);
563 int wordsize
= s390_get_wordsize (pid
);
564 unsigned long hwcap
= linux_get_hwcap (wordsize
);
566 /* Check whether the kernel supports extra register sets. */
567 int have_regset_last_break
568 = s390_check_regset (pid
, NT_S390_LAST_BREAK
, 8);
569 int have_regset_system_call
570 = s390_check_regset (pid
, NT_S390_SYSTEM_CALL
, 4);
572 = (s390_check_regset (pid
, NT_S390_TDB
, 256)
573 && (hwcap
& HWCAP_S390_TE
) != 0);
575 = (s390_check_regset (pid
, NT_S390_VXRS_LOW
, 128)
576 && s390_check_regset (pid
, NT_S390_VXRS_HIGH
, 256)
577 && (hwcap
& HWCAP_S390_VX
) != 0);
579 = (s390_check_regset (pid
, NT_S390_GS_CB
, 32)
580 && s390_check_regset (pid
, NT_S390_GS_BC
, 32)
581 && (hwcap
& HWCAP_S390_GS
) != 0);
588 tdesc
= tdesc_s390x_gs_linux64
;
589 else if (have_regset_vxrs
)
590 tdesc
= (have_regset_tdb
? tdesc_s390x_tevx_linux64
:
591 tdesc_s390x_vx_linux64
);
592 else if (have_regset_tdb
)
593 tdesc
= tdesc_s390x_te_linux64
;
594 else if (have_regset_system_call
)
595 tdesc
= tdesc_s390x_linux64v2
;
596 else if (have_regset_last_break
)
597 tdesc
= tdesc_s390x_linux64v1
;
599 tdesc
= tdesc_s390x_linux64
;
602 /* For a 31-bit inferior, check whether the kernel supports
603 using the full 64-bit GPRs. */
606 if (hwcap
& HWCAP_S390_HIGH_GPRS
)
608 have_hwcap_s390_high_gprs
= 1;
610 tdesc
= tdesc_s390_gs_linux64
;
611 else if (have_regset_vxrs
)
612 tdesc
= (have_regset_tdb
? tdesc_s390_tevx_linux64
:
613 tdesc_s390_vx_linux64
);
614 else if (have_regset_tdb
)
615 tdesc
= tdesc_s390_te_linux64
;
616 else if (have_regset_system_call
)
617 tdesc
= tdesc_s390_linux64v2
;
618 else if (have_regset_last_break
)
619 tdesc
= tdesc_s390_linux64v1
;
621 tdesc
= tdesc_s390_linux64
;
625 /* Assume 31-bit inferior process. */
626 if (have_regset_system_call
)
627 tdesc
= tdesc_s390_linux32v2
;
628 else if (have_regset_last_break
)
629 tdesc
= tdesc_s390_linux32v1
;
631 tdesc
= tdesc_s390_linux32
;
634 have_hwcap_s390_vx
= have_regset_vxrs
;
637 /* Update target_regsets according to available register sets. */
638 for (regset
= s390_regsets
; regset
->size
>= 0; regset
++)
639 if (regset
->get_request
== PTRACE_GETREGSET
)
640 switch (regset
->nt_type
)
643 case NT_S390_HIGH_GPRS
:
644 regset
->size
= have_hwcap_s390_high_gprs
? 64 : 0;
647 case NT_S390_LAST_BREAK
:
648 regset
->size
= have_regset_last_break
? 8 : 0;
650 case NT_S390_SYSTEM_CALL
:
651 regset
->size
= have_regset_system_call
? 4 : 0;
654 regset
->size
= have_regset_tdb
? 256 : 0;
656 case NT_S390_VXRS_LOW
:
657 regset
->size
= have_regset_vxrs
? 128 : 0;
659 case NT_S390_VXRS_HIGH
:
660 regset
->size
= have_regset_vxrs
? 256 : 0;
664 regset
->size
= have_regset_gs
? 32 : 0;
669 current_process ()->tdesc
= tdesc
;
674 s390_breakpoint_at (CORE_ADDR pc
)
676 unsigned char c
[s390_breakpoint_len
];
677 read_inferior_memory (pc
, c
, s390_breakpoint_len
);
678 return memcmp (c
, s390_breakpoint
, s390_breakpoint_len
) == 0;
681 /* Breakpoint/Watchpoint support. */
683 /* The "supports_z_point_type" linux_target_ops method. */
686 s390_supports_z_point_type (char z_type
)
697 /* Support for hardware single step. */
700 s390_supports_hardware_single_step (void)
705 static struct usrregs_info s390_usrregs_info
=
711 static struct regsets_info s390_regsets_info
=
713 s390_regsets
, /* regsets */
715 NULL
, /* disabled_regsets */
718 static struct regs_info myregs_info
=
720 NULL
, /* regset_bitmap */
725 static struct usrregs_info s390_usrregs_info_3264
=
731 static struct regsets_info s390_regsets_info_3264
=
733 s390_regsets
, /* regsets */
735 NULL
, /* disabled_regsets */
738 static struct regs_info regs_info_3264
=
740 NULL
, /* regset_bitmap */
741 &s390_usrregs_info_3264
,
742 &s390_regsets_info_3264
746 s390_target::get_regs_info ()
748 if (have_hwcap_s390_high_gprs
)
751 const struct target_desc
*tdesc
= current_process ()->tdesc
;
753 if (register_size (tdesc
, 0) == 4)
754 return ®s_info_3264
;
756 return ®s_info_3264
;
762 /* The "supports_tracepoints" linux_target_ops method. */
765 s390_supports_tracepoints (void)
770 /* Implementation of linux_target_ops method "get_thread_area". */
773 s390_get_thread_area (int lwpid
, CORE_ADDR
*addrp
)
775 CORE_ADDR res
= ptrace (PTRACE_PEEKUSER
, lwpid
, (long) PT_ACR0
, (long) 0);
777 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
779 if (register_size (regcache
->tdesc
, 0) == 4)
780 res
&= 0xffffffffull
;
787 /* Fast tracepoint support.
789 The register save area on stack is identical for all targets:
791 0x000+i*0x10: VR0-VR31
798 If we're on 31-bit linux, we just don't store the high parts of the GPRs.
799 Likewise, if there's no VX support, we just store the FRs into the slots
800 of low VR halves. The agent code is responsible for rearranging that
803 /* Code sequence saving GPRs for 31-bit target with no high GPRs. There's
804 one trick used at the very beginning: since there's no way to allocate
805 stack space without destroying CC (lay instruction can do it, but it's
806 only supported on later CPUs), we take 4 different execution paths for
807 every possible value of CC, allocate stack space, save %r0, stuff the
808 CC value in %r0 (shifted to match its position in PSWM high word),
809 then branch to common path. */
811 static const unsigned char s390_ft_entry_gpr_esa
[] = {
812 0xa7, 0x14, 0x00, 0x1e, /* jo .Lcc3 */
813 0xa7, 0x24, 0x00, 0x14, /* jh .Lcc2 */
814 0xa7, 0x44, 0x00, 0x0a, /* jl .Lcc1 */
816 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
817 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
818 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
819 0xa7, 0xf4, 0x00, 0x18, /* j .Lccdone */
821 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
822 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
823 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
824 0xa7, 0xf4, 0x00, 0x10, /* j .Lccdone */
826 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
827 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
828 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
829 0xa7, 0xf4, 0x00, 0x08, /* j .Lccdone */
831 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
832 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
833 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
835 0x50, 0x10, 0xf2, 0x0c, /* st %r1, 0x20c(%r15) */
836 0x50, 0x20, 0xf2, 0x14, /* st %r2, 0x214(%r15) */
837 0x50, 0x30, 0xf2, 0x1c, /* st %r3, 0x21c(%r15) */
838 0x50, 0x40, 0xf2, 0x24, /* st %r4, 0x224(%r15) */
839 0x50, 0x50, 0xf2, 0x2c, /* st %r5, 0x22c(%r15) */
840 0x50, 0x60, 0xf2, 0x34, /* st %r6, 0x234(%r15) */
841 0x50, 0x70, 0xf2, 0x3c, /* st %r7, 0x23c(%r15) */
842 0x50, 0x80, 0xf2, 0x44, /* st %r8, 0x244(%r15) */
843 0x50, 0x90, 0xf2, 0x4c, /* st %r9, 0x24c(%r15) */
844 0x50, 0xa0, 0xf2, 0x54, /* st %r10, 0x254(%r15) */
845 0x50, 0xb0, 0xf2, 0x5c, /* st %r11, 0x25c(%r15) */
846 0x50, 0xc0, 0xf2, 0x64, /* st %r12, 0x264(%r15) */
847 0x50, 0xd0, 0xf2, 0x6c, /* st %r13, 0x26c(%r15) */
848 0x50, 0xe0, 0xf2, 0x74, /* st %r14, 0x274(%r15) */
849 /* Compute original value of %r15 and store it. We use ahi instead
850 of la to preserve the whole value, and not just the low 31 bits.
851 This is not particularly important here, but essential in the
852 zarch case where someone might be using the high word of %r15
853 as an extra register. */
854 0x18, 0x1f, /* lr %r1, %r15 */
855 0xa7, 0x1a, 0x03, 0x00, /* ahi %r1, 0x300 */
856 0x50, 0x10, 0xf2, 0x7c, /* st %r1, 0x27c(%r15) */
859 /* Code sequence saving GPRs for 31-bit target with high GPRs and for 64-bit
860 target. Same as above, except this time we can use load/store multiple,
861 since the 64-bit regs are tightly packed. */
863 static const unsigned char s390_ft_entry_gpr_zarch
[] = {
864 0xa7, 0x14, 0x00, 0x21, /* jo .Lcc3 */
865 0xa7, 0x24, 0x00, 0x16, /* jh .Lcc2 */
866 0xa7, 0x44, 0x00, 0x0b, /* jl .Lcc1 */
868 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
869 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
870 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
871 0xa7, 0xf4, 0x00, 0x1b, /* j .Lccdone */
873 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
874 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
875 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
876 0xa7, 0xf4, 0x00, 0x12, /* j .Lccdone */
878 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
879 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
880 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
881 0xa7, 0xf4, 0x00, 0x09, /* j .Lccdone */
883 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
884 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
885 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
887 0xb9, 0x04, 0x00, 0x1f, /* lgr %r1, %r15 */
888 0xa7, 0x1b, 0x03, 0x00, /* aghi %r1, 0x300 */
889 0xe3, 0x10, 0xf2, 0x78, 0x00, 0x24, /* stg %r1, 0x278(%r15) */
892 /* Code sequence saving ARs, PSWM and FPC. PSWM has to be assembled from
893 current PSWM (read by epsw) and CC from entry (in %r0). */
895 static const unsigned char s390_ft_entry_misc
[] = {
896 0x9b, 0x0f, 0xf2, 0x80, /* stam %a0, %a15, 0x20(%%r15) */
897 0xb9, 0x8d, 0x00, 0x23, /* epsw %r2, %r3 */
898 0xa7, 0x18, 0xcf, 0xff, /* lhi %r1, ~0x3000 */
899 0x14, 0x21, /* nr %r2, %r1 */
900 0x16, 0x20, /* or %r2, %r0 */
901 0x50, 0x20, 0xf2, 0xc0, /* st %r2, 0x2c0(%r15) */
902 0x50, 0x30, 0xf2, 0xc4, /* st %r3, 0x2c4(%r15) */
903 0xb2, 0x9c, 0xf2, 0xd0, /* stfpc 0x2d0(%r15) */
906 /* Code sequence saving FRs, used if VX not supported. */
908 static const unsigned char s390_ft_entry_fr
[] = {
909 0x60, 0x00, 0xf0, 0x00, /* std %f0, 0x000(%r15) */
910 0x60, 0x10, 0xf0, 0x10, /* std %f1, 0x010(%r15) */
911 0x60, 0x20, 0xf0, 0x20, /* std %f2, 0x020(%r15) */
912 0x60, 0x30, 0xf0, 0x30, /* std %f3, 0x030(%r15) */
913 0x60, 0x40, 0xf0, 0x40, /* std %f4, 0x040(%r15) */
914 0x60, 0x50, 0xf0, 0x50, /* std %f5, 0x050(%r15) */
915 0x60, 0x60, 0xf0, 0x60, /* std %f6, 0x060(%r15) */
916 0x60, 0x70, 0xf0, 0x70, /* std %f7, 0x070(%r15) */
917 0x60, 0x80, 0xf0, 0x80, /* std %f8, 0x080(%r15) */
918 0x60, 0x90, 0xf0, 0x90, /* std %f9, 0x090(%r15) */
919 0x60, 0xa0, 0xf0, 0xa0, /* std %f10, 0x0a0(%r15) */
920 0x60, 0xb0, 0xf0, 0xb0, /* std %f11, 0x0b0(%r15) */
921 0x60, 0xc0, 0xf0, 0xc0, /* std %f12, 0x0c0(%r15) */
922 0x60, 0xd0, 0xf0, 0xd0, /* std %f13, 0x0d0(%r15) */
923 0x60, 0xe0, 0xf0, 0xe0, /* std %f14, 0x0e0(%r15) */
924 0x60, 0xf0, 0xf0, 0xf0, /* std %f15, 0x0f0(%r15) */
927 /* Code sequence saving VRs, used if VX not supported. */
929 static const unsigned char s390_ft_entry_vr
[] = {
930 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x3e, /* vstm %v0, %v15, 0x000(%r15) */
931 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x3e, /* vstm %v16, %v31, 0x100(%r15) */
934 /* Code sequence doing the collection call for 31-bit target. %r1 contains
935 the address of the literal pool. */
937 static const unsigned char s390_ft_main_31
[] = {
938 /* Load the literals into registers. */
939 0x58, 0x50, 0x10, 0x00, /* l %r5, 0x0(%r1) */
940 0x58, 0x20, 0x10, 0x04, /* l %r2, 0x4(%r1) */
941 0x58, 0x40, 0x10, 0x08, /* l %r4, 0x8(%r1) */
942 0x58, 0x60, 0x10, 0x0c, /* l %r6, 0xc(%r1) */
943 /* Save original PSWA (tracepoint address | 0x80000000). */
944 0x50, 0x50, 0xf2, 0xcc, /* st %r5, 0x2cc(%r15) */
945 /* Construct a collecting_t object at %r15+0x2e0. */
946 0x50, 0x20, 0xf2, 0xe0, /* st %r2, 0x2e0(%r15) */
947 0x9b, 0x00, 0xf2, 0xe4, /* stam %a0, %a0, 0x2e4(%r15) */
948 /* Move its address to %r0. */
949 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
952 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
953 0xba, 0x10, 0x60, 0x00, /* cs %r1, %r0, 0(%r6) */
954 0xa7, 0x74, 0xff, 0xfc, /* jne .Lloop */
955 /* Address of the register save block to %r3. */
956 0x18, 0x3f, /* lr %r3, %r15 */
957 /* Make a stack frame, so that we can call the collector. */
958 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
960 0x0d, 0xe4, /* basr %r14, %r4 */
961 /* And get rid of the stack frame again. */
962 0x41, 0xf0, 0xf0, 0x60, /* la %r15, 0x60(%r15) */
963 /* Leave the lock. */
964 0x07, 0xf0, /* br %r0 */
965 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
966 0x50, 0x10, 0x60, 0x00, /* st %t1, 0(%r6) */
969 /* Code sequence doing the collection call for 64-bit target. %r1 contains
970 the address of the literal pool. */
972 static const unsigned char s390_ft_main_64
[] = {
973 /* Load the literals into registers. */
974 0xe3, 0x50, 0x10, 0x00, 0x00, 0x04, /* lg %r5, 0x00(%r1) */
975 0xe3, 0x20, 0x10, 0x08, 0x00, 0x04, /* lg %r2, 0x08(%r1) */
976 0xe3, 0x40, 0x10, 0x10, 0x00, 0x04, /* lg %r4, 0x10(%r1) */
977 0xe3, 0x60, 0x10, 0x18, 0x00, 0x04, /* lg %r6, 0x18(%r1) */
978 /* Save original PSWA (tracepoint address). */
979 0xe3, 0x50, 0xf2, 0xc8, 0x00, 0x24, /* stg %r5, 0x2c8(%r15) */
980 /* Construct a collecting_t object at %r15+0x2e0. */
981 0xe3, 0x20, 0xf2, 0xe0, 0x00, 0x24, /* stg %r2, 0x2e0(%r15) */
982 0x9b, 0x01, 0xf2, 0xe8, /* stam %a0, %a1, 0x2e8(%r15) */
983 /* Move its address to %r0. */
984 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
987 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
988 0xeb, 0x10, 0x60, 0x00, 0x00, 0x30, /* csg %r1, %r0, 0(%r6) */
989 0xa7, 0x74, 0xff, 0xfb, /* jne .Lloop */
990 /* Address of the register save block to %r3. */
991 0xb9, 0x04, 0x00, 0x3f, /* lgr %r3, %r15 */
992 /* Make a stack frame, so that we can call the collector. */
993 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
995 0x0d, 0xe4, /* basr %r14, %r4 */
996 /* And get rid of the stack frame again. */
997 0x41, 0xf0, 0xf0, 0xa0, /* la %r15, 0xa0(%r15) */
998 /* Leave the lock. */
999 0x07, 0xf0, /* br %r0 */
1000 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
1001 0xe3, 0x10, 0x60, 0x00, 0x00, 0x24, /* stg %t1, 0(%r6) */
1004 /* Code sequence restoring FRs, for targets with no VX support. */
1006 static const unsigned char s390_ft_exit_fr
[] = {
1007 0x68, 0x00, 0xf0, 0x00, /* ld %f0, 0x000(%r15) */
1008 0x68, 0x10, 0xf0, 0x10, /* ld %f1, 0x010(%r15) */
1009 0x68, 0x20, 0xf0, 0x20, /* ld %f2, 0x020(%r15) */
1010 0x68, 0x30, 0xf0, 0x30, /* ld %f3, 0x030(%r15) */
1011 0x68, 0x40, 0xf0, 0x40, /* ld %f4, 0x040(%r15) */
1012 0x68, 0x50, 0xf0, 0x50, /* ld %f5, 0x050(%r15) */
1013 0x68, 0x60, 0xf0, 0x60, /* ld %f6, 0x060(%r15) */
1014 0x68, 0x70, 0xf0, 0x70, /* ld %f7, 0x070(%r15) */
1015 0x68, 0x80, 0xf0, 0x80, /* ld %f8, 0x080(%r15) */
1016 0x68, 0x90, 0xf0, 0x90, /* ld %f9, 0x090(%r15) */
1017 0x68, 0xa0, 0xf0, 0xa0, /* ld %f10, 0x0a0(%r15) */
1018 0x68, 0xb0, 0xf0, 0xb0, /* ld %f11, 0x0b0(%r15) */
1019 0x68, 0xc0, 0xf0, 0xc0, /* ld %f12, 0x0c0(%r15) */
1020 0x68, 0xd0, 0xf0, 0xd0, /* ld %f13, 0x0d0(%r15) */
1021 0x68, 0xe0, 0xf0, 0xe0, /* ld %f14, 0x0e0(%r15) */
1022 0x68, 0xf0, 0xf0, 0xf0, /* ld %f15, 0x0f0(%r15) */
1025 /* Code sequence restoring VRs. */
1027 static const unsigned char s390_ft_exit_vr
[] = {
1028 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x36, /* vlm %v0, %v15, 0x000(%r15) */
1029 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x36, /* vlm %v16, %v31, 0x100(%r15) */
1032 /* Code sequence restoring misc registers. As for PSWM, only CC should be
1033 modified by C code, so we use the alr instruction to restore it by
1034 manufacturing an operand that'll result in the original flags. */
1036 static const unsigned char s390_ft_exit_misc
[] = {
1037 0xb2, 0x9d, 0xf2, 0xd0, /* lfpc 0x2d0(%r15) */
1038 0x58, 0x00, 0xf2, 0xc0, /* l %r0, 0x2c0(%r15) */
1039 /* Extract CC to high 2 bits of %r0. */
1040 0x88, 0x00, 0x00, 0x0c, /* srl %r0, 12 */
1041 0x89, 0x00, 0x00, 0x1e, /* sll %r0, 30 */
1042 /* Add %r0 to itself. Result will be nonzero iff CC bit 0 is set, and
1043 will have carry iff CC bit 1 is set - resulting in the same flags
1045 0x1e, 0x00, /* alr %r0, %r0 */
1046 0x9a, 0x0f, 0xf2, 0x80, /* lam %a0, %a15, 0x280(%r15) */
1049 /* Code sequence restoring GPRs, for 31-bit targets with no high GPRs. */
1051 static const unsigned char s390_ft_exit_gpr_esa
[] = {
1052 0x58, 0x00, 0xf2, 0x04, /* l %r0, 0x204(%r15) */
1053 0x58, 0x10, 0xf2, 0x0c, /* l %r1, 0x20c(%r15) */
1054 0x58, 0x20, 0xf2, 0x14, /* l %r2, 0x214(%r15) */
1055 0x58, 0x30, 0xf2, 0x1c, /* l %r3, 0x21c(%r15) */
1056 0x58, 0x40, 0xf2, 0x24, /* l %r4, 0x224(%r15) */
1057 0x58, 0x50, 0xf2, 0x2c, /* l %r5, 0x22c(%r15) */
1058 0x58, 0x60, 0xf2, 0x34, /* l %r6, 0x234(%r15) */
1059 0x58, 0x70, 0xf2, 0x3c, /* l %r7, 0x23c(%r15) */
1060 0x58, 0x80, 0xf2, 0x44, /* l %r8, 0x244(%r15) */
1061 0x58, 0x90, 0xf2, 0x4c, /* l %r9, 0x24c(%r15) */
1062 0x58, 0xa0, 0xf2, 0x54, /* l %r10, 0x254(%r15) */
1063 0x58, 0xb0, 0xf2, 0x5c, /* l %r11, 0x25c(%r15) */
1064 0x58, 0xc0, 0xf2, 0x64, /* l %r12, 0x264(%r15) */
1065 0x58, 0xd0, 0xf2, 0x6c, /* l %r13, 0x26c(%r15) */
1066 0x58, 0xe0, 0xf2, 0x74, /* l %r14, 0x274(%r15) */
1067 0x58, 0xf0, 0xf2, 0x7c, /* l %r15, 0x27c(%r15) */
1070 /* Code sequence restoring GPRs, for 64-bit targets and 31-bit targets
1073 static const unsigned char s390_ft_exit_gpr_zarch
[] = {
1074 0xeb, 0x0f, 0xf2, 0x00, 0x00, 0x04, /* lmg %r0, %r15, 0x200(%r15) */
1077 /* Writes instructions to target, updating the to pointer. */
1080 append_insns (CORE_ADDR
*to
, size_t len
, const unsigned char *buf
)
1082 target_write_memory (*to
, buf
, len
);
1086 /* Relocates an instruction from oldloc to *to, updating to. */
1089 s390_relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
, int is_64
)
1094 /* 0: no fixup, 1: PC16DBL fixup, 2: PC32DBL fixup. */
1097 read_inferior_memory (oldloc
, buf
, sizeof buf
);
1100 else if (buf
[0] < 0xc0)
1106 case 0x05: /* BALR */
1107 case 0x0c: /* BASSM */
1108 case 0x0d: /* BASR */
1109 case 0x45: /* BAL */
1110 case 0x4d: /* BAS */
1111 /* These save a return address and mess around with registers.
1112 We can't relocate them. */
1114 case 0x84: /* BRXH */
1115 case 0x85: /* BRXLE */
1120 /* BRC, BRAS, BRCT, BRCTG */
1121 if (op2
>= 4 && op2
<= 7)
1129 /* LARL, BRCL, BRASL */
1130 if (op2
== 0 || op2
== 4 || op2
== 5)
1138 /* PC-relative addressing instructions. */
1141 case 0xc5: /* BPRP */
1142 case 0xc7: /* BPP */
1143 /* Branch prediction - just skip it. */
1155 case 0x44: /* BRXHG */
1156 case 0x45: /* BRXLG */
1157 case 0x64: /* CGRJ */
1158 case 0x65: /* CLGRJ */
1159 case 0x76: /* CRJ */
1160 case 0x77: /* CLRJ */
1169 /* We'll have to relocate an instruction with a PC-relative field.
1170 First, compute the target. */
1171 int64_t loffset
= 0;
1175 int16_t soffset
= 0;
1176 memcpy (&soffset
, buf
+ 2, 2);
1181 int32_t soffset
= 0;
1182 memcpy (&soffset
, buf
+ 2, 4);
1185 target
= oldloc
+ loffset
* 2;
1187 target
&= 0x7fffffff;
1191 /* BRAS or BRASL was used. We cannot just relocate those, since
1192 they save the return address in a register. We can, however,
1193 replace them with a LARL+JG sequence. */
1195 /* Make the LARL. */
1199 loffset
= oldloc
+ ilen
- *to
;
1202 if (soffset
!= loffset
&& is_64
)
1204 memcpy (buf
+ 2, &soffset
, 4);
1205 append_insns (to
, 6, buf
);
1207 /* Note: this is not fully correct. In 31-bit mode, LARL will write
1208 an address with the top bit 0, while BRAS/BRASL will write it
1209 with top bit 1. It should not matter much, since linux compilers
1210 use BR and not BSM to return from functions, but it could confuse
1211 some poor stack unwinder. */
1213 /* We'll now be writing a JG. */
1220 /* Compute the new offset and write it to the buffer. */
1221 loffset
= target
- *to
;
1226 int16_t soffset
= loffset
;
1227 if (soffset
!= loffset
)
1229 memcpy (buf
+ 2, &soffset
, 2);
1233 int32_t soffset
= loffset
;
1234 if (soffset
!= loffset
&& is_64
)
1236 memcpy (buf
+ 2, &soffset
, 4);
1239 append_insns (to
, ilen
, buf
);
1243 /* Implementation of linux_target_ops method
1244 "install_fast_tracepoint_jump_pad". */
1247 s390_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint
,
1249 CORE_ADDR collector
,
1252 CORE_ADDR
*jump_entry
,
1253 CORE_ADDR
*trampoline
,
1254 ULONGEST
*trampoline_size
,
1255 unsigned char *jjump_pad_insn
,
1256 ULONGEST
*jjump_pad_insn_size
,
1257 CORE_ADDR
*adjusted_insn_addr
,
1258 CORE_ADDR
*adjusted_insn_addr_end
,
1264 unsigned char jbuf
[6] = { 0xc0, 0xf4, 0, 0, 0, 0 }; /* jg ... */
1265 CORE_ADDR buildaddr
= *jump_entry
;
1267 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1268 int is_64
= register_size (regcache
->tdesc
, 0) == 8;
1269 int is_zarch
= is_64
|| have_hwcap_s390_high_gprs
;
1270 int has_vx
= have_hwcap_s390_vx
;
1272 int is_64
= 0, is_zarch
= 0, has_vx
= 0;
1274 CORE_ADDR literals
[4] = {
1281 /* First, store the GPRs. */
1283 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_zarch
,
1284 s390_ft_entry_gpr_zarch
);
1286 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_esa
,
1287 s390_ft_entry_gpr_esa
);
1289 /* Second, misc registers (ARs, PSWM, FPC). PSWA will be stored below. */
1290 append_insns (&buildaddr
, sizeof s390_ft_entry_misc
, s390_ft_entry_misc
);
1292 /* Third, FRs or VRs. */
1294 append_insns (&buildaddr
, sizeof s390_ft_entry_vr
, s390_ft_entry_vr
);
1296 append_insns (&buildaddr
, sizeof s390_ft_entry_fr
, s390_ft_entry_fr
);
1298 /* Now, the main part of code - store PSWA, take lock, call collector,
1299 leave lock. First, we'll need to fetch 4 literals. */
1301 unsigned char buf
[] = {
1302 0x07, 0x07, /* nopr %r7 */
1303 0x07, 0x07, /* nopr %r7 */
1304 0x07, 0x07, /* nopr %r7 */
1305 0xa7, 0x15, 0x00, 0x12, /* bras %r1, .Lend */
1306 0, 0, 0, 0, 0, 0, 0, 0, /* tpaddr */
1307 0, 0, 0, 0, 0, 0, 0, 0, /* tpoint */
1308 0, 0, 0, 0, 0, 0, 0, 0, /* collector */
1309 0, 0, 0, 0, 0, 0, 0, 0, /* lockaddr */
1312 /* Find the proper start place in buf, so that literals will be
1314 int bufpos
= (buildaddr
+ 2) & 7;
1315 /* Stuff the literals into the buffer. */
1316 for (i
= 0; i
< 4; i
++) {
1317 uint64_t lit
= literals
[i
];
1318 memcpy (&buf
[sizeof buf
- 32 + i
* 8], &lit
, 8);
1320 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1321 append_insns (&buildaddr
, sizeof s390_ft_main_64
, s390_ft_main_64
);
1323 unsigned char buf
[] = {
1324 0x07, 0x07, /* nopr %r7 */
1325 0xa7, 0x15, 0x00, 0x0a, /* bras %r1, .Lend */
1326 0, 0, 0, 0, /* tpaddr */
1327 0, 0, 0, 0, /* tpoint */
1328 0, 0, 0, 0, /* collector */
1329 0, 0, 0, 0, /* lockaddr */
1332 /* Find the proper start place in buf, so that literals will be
1334 int bufpos
= (buildaddr
+ 2) & 3;
1335 /* First literal will be saved as the PSWA, make sure it has the high bit
1337 literals
[0] |= 0x80000000;
1338 /* Stuff the literals into the buffer. */
1339 for (i
= 0; i
< 4; i
++) {
1340 uint32_t lit
= literals
[i
];
1341 memcpy (&buf
[sizeof buf
- 16 + i
* 4], &lit
, 4);
1343 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1344 append_insns (&buildaddr
, sizeof s390_ft_main_31
, s390_ft_main_31
);
1347 /* Restore FRs or VRs. */
1349 append_insns (&buildaddr
, sizeof s390_ft_exit_vr
, s390_ft_exit_vr
);
1351 append_insns (&buildaddr
, sizeof s390_ft_exit_fr
, s390_ft_exit_fr
);
1353 /* Restore misc registers. */
1354 append_insns (&buildaddr
, sizeof s390_ft_exit_misc
, s390_ft_exit_misc
);
1356 /* Restore the GPRs. */
1358 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_zarch
,
1359 s390_ft_exit_gpr_zarch
);
1361 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_esa
,
1362 s390_ft_exit_gpr_esa
);
1364 /* Now, adjust the original instruction to execute in the jump
1366 *adjusted_insn_addr
= buildaddr
;
1367 if (s390_relocate_instruction (&buildaddr
, tpaddr
, is_64
))
1369 sprintf (err
, "E.Could not relocate instruction for tracepoint.");
1372 *adjusted_insn_addr_end
= buildaddr
;
1374 /* Finally, write a jump back to the program. */
1376 loffset
= (tpaddr
+ orig_size
) - buildaddr
;
1379 if (is_64
&& offset
!= loffset
)
1382 "E.Jump back from jump pad too far from tracepoint "
1383 "(offset 0x%" PRIx64
" > int33).", loffset
);
1386 memcpy (jbuf
+ 2, &offset
, 4);
1387 append_insns (&buildaddr
, sizeof jbuf
, jbuf
);
1389 /* The jump pad is now built. Wire in a jump to our jump pad. This
1390 is always done last (by our caller actually), so that we can
1391 install fast tracepoints with threads running. This relies on
1392 the agent's atomic write support. */
1393 loffset
= *jump_entry
- tpaddr
;
1396 if (is_64
&& offset
!= loffset
)
1399 "E.Jump back from jump pad too far from tracepoint "
1400 "(offset 0x%" PRIx64
" > int33).", loffset
);
1403 memcpy (jbuf
+ 2, &offset
, 4);
1404 memcpy (jjump_pad_insn
, jbuf
, sizeof jbuf
);
1405 *jjump_pad_insn_size
= sizeof jbuf
;
1407 /* Return the end address of our pad. */
1408 *jump_entry
= buildaddr
;
1413 /* Implementation of linux_target_ops method
1414 "get_min_fast_tracepoint_insn_len". */
1417 s390_get_min_fast_tracepoint_insn_len (void)
1419 /* We only support using 6-byte jumps to reach the tracepoint code.
1420 If the tracepoint buffer were allocated sufficiently close (64kiB)
1421 to the executable code, and the traced instruction itself was close
1422 enough to the beginning, we could use 4-byte jumps, but this doesn't
1423 seem to be worth the effort. */
1427 /* Implementation of linux_target_ops method "get_ipa_tdesc_idx". */
1430 s390_get_ipa_tdesc_idx (void)
1432 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1433 const struct target_desc
*tdesc
= regcache
->tdesc
;
1436 if (tdesc
== tdesc_s390x_linux64
)
1437 return S390_TDESC_64
;
1438 if (tdesc
== tdesc_s390x_linux64v1
)
1439 return S390_TDESC_64V1
;
1440 if (tdesc
== tdesc_s390x_linux64v2
)
1441 return S390_TDESC_64V2
;
1442 if (tdesc
== tdesc_s390x_te_linux64
)
1443 return S390_TDESC_TE
;
1444 if (tdesc
== tdesc_s390x_vx_linux64
)
1445 return S390_TDESC_VX
;
1446 if (tdesc
== tdesc_s390x_tevx_linux64
)
1447 return S390_TDESC_TEVX
;
1448 if (tdesc
== tdesc_s390x_gs_linux64
)
1449 return S390_TDESC_GS
;
1452 if (tdesc
== tdesc_s390_linux32
)
1453 return S390_TDESC_32
;
1454 if (tdesc
== tdesc_s390_linux32v1
)
1455 return S390_TDESC_32V1
;
1456 if (tdesc
== tdesc_s390_linux32v2
)
1457 return S390_TDESC_32V2
;
1458 if (tdesc
== tdesc_s390_linux64
)
1459 return S390_TDESC_64
;
1460 if (tdesc
== tdesc_s390_linux64v1
)
1461 return S390_TDESC_64V1
;
1462 if (tdesc
== tdesc_s390_linux64v2
)
1463 return S390_TDESC_64V2
;
1464 if (tdesc
== tdesc_s390_te_linux64
)
1465 return S390_TDESC_TE
;
1466 if (tdesc
== tdesc_s390_vx_linux64
)
1467 return S390_TDESC_VX
;
1468 if (tdesc
== tdesc_s390_tevx_linux64
)
1469 return S390_TDESC_TEVX
;
1470 if (tdesc
== tdesc_s390_gs_linux64
)
1471 return S390_TDESC_GS
;
1476 /* Appends given buffer to current_insn_ptr in the target. */
1479 add_insns (const unsigned char *start
, int len
)
1481 CORE_ADDR buildaddr
= current_insn_ptr
;
1484 debug_printf ("Adding %d bytes of insn at %s\n",
1485 len
, paddress (buildaddr
));
1487 append_insns (&buildaddr
, len
, start
);
1488 current_insn_ptr
= buildaddr
;
1491 /* Register usage in emit:
1494 - %r2: top of stack (high word for 31-bit)
1495 - %r3: low word of top of stack (for 31-bit)
1497 - %r6, %r7, %r8: don't use
1500 - %r11: frame pointer
1501 - %r12: saved top of stack for void_call_2 (high word for 31-bit)
1502 - %r13: low word of saved top of stack (for 31-bit)
1503 - %r14: return address for calls
1504 - %r15: stack pointer
1508 /* The "emit_prologue" emit_ops method for s390. */
1511 s390_emit_prologue (void)
1513 static const unsigned char buf
[] = {
1514 0x90, 0x9f, 0xf0, 0x24, /* stm %r9, %r15, 0x24(%r15) */
1515 0x18, 0x92, /* lr %r9, %r2 */
1516 0x18, 0xa3, /* lr %r10, %r3 */
1517 0x18, 0xbf, /* lr %r11, %r15 */
1519 add_insns (buf
, sizeof buf
);
1522 /* The "emit_epilogue" emit_ops method for s390. */
1525 s390_emit_epilogue (void)
1527 static const unsigned char buf
[] = {
1528 0x90, 0x23, 0xa0, 0x00, /* stm %r2, %r3, 0(%r10) */
1529 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1530 0x98, 0x9f, 0xb0, 0x24, /* lm %r9, %r15, 0x24(%r11) */
1531 0x07, 0xfe, /* br %r14 */
1533 add_insns (buf
, sizeof buf
);
1536 /* The "emit_add" emit_ops method for s390. */
1539 s390_emit_add (void)
1541 static const unsigned char buf
[] = {
1542 0x5e, 0x30, 0xf0, 0x04, /* al %r3, 4(%r15) */
1543 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x98, /* al %r2, 0(%r15) */
1544 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1546 add_insns (buf
, sizeof buf
);
1549 /* The "emit_sub" emit_ops method for s390. */
1552 s390_emit_sub (void)
1554 static const unsigned char buf
[] = {
1555 0x98, 0x45, 0xf0, 0x00, /* lm %r4, %r5, 0(%r15) */
1556 0x1f, 0x53, /* slr %r5, %r3 */
1557 0xb9, 0x99, 0x00, 0x42, /* slbr %r4, %r2 */
1558 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1559 0x18, 0x35, /* lr %r3, %r5 */
1560 0x18, 0x24, /* lr %r2, %r4 */
1562 add_insns (buf
, sizeof buf
);
1565 /* The "emit_mul" emit_ops method for s390. */
1568 s390_emit_mul (void)
1573 /* The "emit_lsh" emit_ops method for s390. */
1576 s390_emit_lsh (void)
1578 static const unsigned char buf
[] = {
1579 0x18, 0x43, /* lr %r4, %r3 */
1580 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1581 0x8d, 0x20, 0x40, 0x00, /* sldl %r2, 0(%r4) */
1582 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1584 add_insns (buf
, sizeof buf
);
1587 /* The "emit_rsh_signed" emit_ops method for s390. */
1590 s390_emit_rsh_signed (void)
1592 static const unsigned char buf
[] = {
1593 0x18, 0x43, /* lr %r4, %r3 */
1594 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1595 0x8e, 0x20, 0x40, 0x00, /* srda %r2, 0(%r4) */
1596 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1598 add_insns (buf
, sizeof buf
);
1601 /* The "emit_rsh_unsigned" emit_ops method for s390. */
1604 s390_emit_rsh_unsigned (void)
1606 static const unsigned char buf
[] = {
1607 0x18, 0x43, /* lr %r4, %r3 */
1608 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1609 0x8c, 0x20, 0x40, 0x00, /* srdl %r2, 0(%r4) */
1610 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1612 add_insns (buf
, sizeof buf
);
1615 /* The "emit_ext" emit_ops method for s390. */
1618 s390_emit_ext (int arg
)
1620 unsigned char buf
[] = {
1621 0x8d, 0x20, 0x00, (unsigned char) (64 - arg
), /* sldl %r2, <64-arg> */
1622 0x8e, 0x20, 0x00, (unsigned char) (64 - arg
), /* srda %r2, <64-arg> */
1624 add_insns (buf
, sizeof buf
);
1627 /* The "emit_log_not" emit_ops method for s390. */
1630 s390_emit_log_not (void)
1632 static const unsigned char buf
[] = {
1633 0x16, 0x23, /* or %r2, %r3 */
1634 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1635 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1636 0xa7, 0x74, 0x00, 0x04, /* jne .Lskip */
1637 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1640 add_insns (buf
, sizeof buf
);
1643 /* The "emit_bit_and" emit_ops method for s390. */
1646 s390_emit_bit_and (void)
1648 static const unsigned char buf
[] = {
1649 0x54, 0x20, 0xf0, 0x00, /* n %r2, 0(%r15) */
1650 0x54, 0x30, 0xf0, 0x04, /* n %r3, 4(%r15) */
1651 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1653 add_insns (buf
, sizeof buf
);
1656 /* The "emit_bit_or" emit_ops method for s390. */
1659 s390_emit_bit_or (void)
1661 static const unsigned char buf
[] = {
1662 0x56, 0x20, 0xf0, 0x00, /* o %r2, 0(%r15) */
1663 0x56, 0x30, 0xf0, 0x04, /* o %r3, 4(%r15) */
1664 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1666 add_insns (buf
, sizeof buf
);
1669 /* The "emit_bit_xor" emit_ops method for s390. */
1672 s390_emit_bit_xor (void)
1674 static const unsigned char buf
[] = {
1675 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
1676 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
1677 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1679 add_insns (buf
, sizeof buf
);
1682 /* The "emit_bit_not" emit_ops method for s390. */
1685 s390_emit_bit_not (void)
1687 static const unsigned char buf
[] = {
1688 0xa7, 0x48, 0xff, 0xff, /* lhi %r4, -1 */
1689 0x17, 0x24, /* xr %r2, %r4 */
1690 0x17, 0x34, /* xr %r3, %r4 */
1692 add_insns (buf
, sizeof buf
);
1695 /* The "emit_equal" emit_ops method for s390. */
1698 s390_emit_equal (void)
1700 s390_emit_bit_xor ();
1701 s390_emit_log_not ();
1704 /* The "emit_less_signed" emit_ops method for s390. */
1707 s390_emit_less_signed (void)
1709 static const unsigned char buf
[] = {
1710 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
1711 0xa7, 0x24, 0x00, 0x0c, /* jh .Lless */
1712 0xa7, 0x44, 0x00, 0x06, /* jl .Lhigh */
1713 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
1714 0xa7, 0x24, 0x00, 0x06, /* jh .Lless */
1716 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1717 0xa7, 0xf4, 0x00, 0x04, /* j .Lend */
1719 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1721 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1722 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1724 add_insns (buf
, sizeof buf
);
1727 /* The "emit_less_unsigned" emit_ops method for s390. */
1730 s390_emit_less_unsigned (void)
1732 static const unsigned char buf
[] = {
1733 0x55, 0x20, 0xf0, 0x00, /* cl %r2, 0(%r15) */
1734 0xa7, 0x24, 0x00, 0x0c, /* jh .Lless */
1735 0xa7, 0x44, 0x00, 0x06, /* jl .Lhigh */
1736 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
1737 0xa7, 0x24, 0x00, 0x06, /* jh .Lless */
1739 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1740 0xa7, 0xf4, 0x00, 0x04, /* j .Lend */
1742 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1744 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1745 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1747 add_insns (buf
, sizeof buf
);
1750 /* The "emit_ref" emit_ops method for s390. */
1753 s390_emit_ref (int size
)
1755 static const unsigned char buf1
[] = {
1756 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1757 0x43, 0x30, 0x30, 0x00, /* ic %r3, 0(%r3) */
1759 static const unsigned char buf2
[] = {
1760 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1761 0x48, 0x30, 0x30, 0x00, /* lh %r3, 0(%r3) */
1763 static const unsigned char buf4
[] = {
1764 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1765 0x58, 0x30, 0x30, 0x00, /* l %r3, 0(%r3) */
1767 static const unsigned char buf8
[] = {
1768 0x98, 0x23, 0x30, 0x00, /* lm %r2, %r3, 0(%r3) */
1773 add_insns (buf1
, sizeof buf1
);
1776 add_insns (buf2
, sizeof buf2
);
1779 add_insns (buf4
, sizeof buf4
);
1782 add_insns (buf8
, sizeof buf8
);
1789 /* The "emit_if_goto" emit_ops method for s390. */
1792 s390_emit_if_goto (int *offset_p
, int *size_p
)
1794 static const unsigned char buf
[] = {
1795 0x16, 0x23, /* or %r2, %r3 */
1796 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1797 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1798 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00 /* jgne <fillme> */
1800 add_insns (buf
, sizeof buf
);
1807 /* The "emit_goto" emit_ops method for s390 and s390x. */
1810 s390_emit_goto (int *offset_p
, int *size_p
)
1812 static const unsigned char buf
[] = {
1813 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
1815 add_insns (buf
, sizeof buf
);
1822 /* The "write_goto_address" emit_ops method for s390 and s390x. */
1825 s390_write_goto_address (CORE_ADDR from
, CORE_ADDR to
, int size
)
1827 long diff
= ((long) (to
- (from
- 2))) / 2;
1829 unsigned char buf
[sizeof sdiff
];
1831 /* We're only doing 4-byte sizes at the moment. */
1832 if (size
!= sizeof sdiff
|| sdiff
!= diff
)
1838 memcpy (buf
, &sdiff
, sizeof sdiff
);
1839 target_write_memory (from
, buf
, sizeof sdiff
);
1842 /* Preparation for emitting a literal pool of given size. Loads the address
1843 of the pool into %r1, and jumps over it. Called should emit the pool data
1844 immediately afterwards. Used for both s390 and s390x. */
1847 s390_emit_litpool (int size
)
1849 static const unsigned char nop
[] = {
1852 unsigned char buf
[] = {
1854 (unsigned char) ((size
+ 4) / 2), /* bras %r1, .Lend+size */
1859 /* buf needs to start at even halfword for litpool to be aligned */
1860 if (current_insn_ptr
& 2)
1861 add_insns (nop
, sizeof nop
);
1865 while ((current_insn_ptr
& 6) != 4)
1866 add_insns (nop
, sizeof nop
);
1868 add_insns (buf
, sizeof buf
);
1871 /* The "emit_const" emit_ops method for s390. */
1874 s390_emit_const (LONGEST num
)
1876 unsigned long long n
= num
;
1877 unsigned char buf_s
[] = {
1878 /* lhi %r3, <num> */
1880 (unsigned char) (num
>> 8), (unsigned char) num
,
1884 static const unsigned char buf_l
[] = {
1885 0x98, 0x23, 0x10, 0x00, /* lm %r2, %r3, 0(%r1) */
1887 if (num
< 0x8000 && num
>= 0)
1889 add_insns (buf_s
, sizeof buf_s
);
1893 s390_emit_litpool (8);
1894 add_insns ((unsigned char *) &n
, sizeof n
);
1895 add_insns (buf_l
, sizeof buf_l
);
1899 /* The "emit_call" emit_ops method for s390. */
1902 s390_emit_call (CORE_ADDR fn
)
1904 unsigned int n
= fn
;
1905 static const unsigned char buf
[] = {
1906 0x58, 0x10, 0x10, 0x00, /* l %r1, 0(%r1) */
1907 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
1908 0x0d, 0xe1, /* basr %r14, %r1 */
1909 0xa7, 0xfa, 0x00, 0x60, /* ahi %r15, 0x60 */
1911 s390_emit_litpool (4);
1912 add_insns ((unsigned char *) &n
, sizeof n
);
1913 add_insns (buf
, sizeof buf
);
1916 /* The "emit_reg" emit_ops method for s390. */
1919 s390_emit_reg (int reg
)
1921 unsigned char bufpre
[] = {
1924 /* lhi %r3, <reg> */
1925 0xa7, 0x38, (unsigned char) (reg
>> 8), (unsigned char) reg
,
1927 add_insns (bufpre
, sizeof bufpre
);
1928 s390_emit_call (get_raw_reg_func_addr ());
1931 /* The "emit_pop" emit_ops method for s390. */
1934 s390_emit_pop (void)
1936 static const unsigned char buf
[] = {
1937 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1938 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1940 add_insns (buf
, sizeof buf
);
1943 /* The "emit_stack_flush" emit_ops method for s390. */
1946 s390_emit_stack_flush (void)
1948 static const unsigned char buf
[] = {
1949 0xa7, 0xfa, 0xff, 0xf8, /* ahi %r15, -8 */
1950 0x90, 0x23, 0xf0, 0x00, /* stm %r2, %r3, 0(%r15) */
1952 add_insns (buf
, sizeof buf
);
1955 /* The "emit_zero_ext" emit_ops method for s390. */
1958 s390_emit_zero_ext (int arg
)
1960 unsigned char buf
[] = {
1961 0x8d, 0x20, 0x00, (unsigned char) (64 - arg
), /* sldl %r2, <64-arg> */
1962 0x8c, 0x20, 0x00, (unsigned char) (64 - arg
), /* srdl %r2, <64-arg> */
1964 add_insns (buf
, sizeof buf
);
1967 /* The "emit_swap" emit_ops method for s390. */
1970 s390_emit_swap (void)
1972 static const unsigned char buf
[] = {
1973 0x98, 0x45, 0xf0, 0x00, /* lm %r4, %r5, 0(%r15) */
1974 0x90, 0x23, 0xf0, 0x00, /* stm %r2, %r3, 0(%r15) */
1975 0x18, 0x24, /* lr %r2, %r4 */
1976 0x18, 0x35, /* lr %r3, %r5 */
1978 add_insns (buf
, sizeof buf
);
1981 /* The "emit_stack_adjust" emit_ops method for s390. */
1984 s390_emit_stack_adjust (int n
)
1986 unsigned char buf
[] = {
1989 (unsigned char ) (n
* 8 >> 8), (unsigned char) (n
* 8),
1991 add_insns (buf
, sizeof buf
);
1994 /* Sets %r2 to a 32-bit constant. */
1997 s390_emit_set_r2 (int arg1
)
1999 unsigned char buf_s
[] = {
2000 /* lhi %r2, <arg1> */
2001 0xa7, 0x28, (unsigned char) (arg1
>> 8), (unsigned char) arg1
,
2003 static const unsigned char buf_l
[] = {
2004 0x58, 0x20, 0x10, 0x00, /* l %r2, 0(%r1) */
2006 if (arg1
< 0x8000 && arg1
>= -0x8000)
2008 add_insns (buf_s
, sizeof buf_s
);
2012 s390_emit_litpool (4);
2013 add_insns ((unsigned char *) &arg1
, sizeof arg1
);
2014 add_insns (buf_l
, sizeof buf_l
);
2018 /* The "emit_int_call_1" emit_ops method for s390. */
2021 s390_emit_int_call_1 (CORE_ADDR fn
, int arg1
)
2023 /* FN's prototype is `LONGEST(*fn)(int)'. */
2024 s390_emit_set_r2 (arg1
);
2025 s390_emit_call (fn
);
2028 /* The "emit_void_call_2" emit_ops method for s390. */
2031 s390_emit_void_call_2 (CORE_ADDR fn
, int arg1
)
2033 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
2034 static const unsigned char buf
[] = {
2035 0x18, 0xc2, /* lr %r12, %r2 */
2036 0x18, 0xd3, /* lr %r13, %r3 */
2037 0x18, 0x43, /* lr %r4, %r3 */
2038 0x18, 0x32, /* lr %r3, %r2 */
2040 static const unsigned char buf2
[] = {
2041 0x18, 0x2c, /* lr %r2, %r12 */
2042 0x18, 0x3d, /* lr %r3, %r13 */
2044 add_insns (buf
, sizeof buf
);
2045 s390_emit_set_r2 (arg1
);
2046 s390_emit_call (fn
);
2047 add_insns (buf2
, sizeof buf2
);
2050 /* The "emit_eq_goto" emit_ops method for s390. */
2053 s390_emit_eq_goto (int *offset_p
, int *size_p
)
2055 static const unsigned char buf
[] = {
2056 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
2057 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
2058 0x16, 0x23, /* or %r2, %r3 */
2059 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2060 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2061 0xc0, 0x84, 0x00, 0x00, 0x00, 0x00, /* jge <fillme> */
2063 add_insns (buf
, sizeof buf
);
2070 /* The "emit_ne_goto" emit_ops method for s390. */
2073 s390_emit_ne_goto (int *offset_p
, int *size_p
)
2075 static const unsigned char buf
[] = {
2076 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
2077 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
2078 0x16, 0x23, /* or %r2, %r3 */
2079 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2080 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2081 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2083 add_insns (buf
, sizeof buf
);
2090 /* The "emit_lt_goto" emit_ops method for s390. */
2093 s390_emit_lt_goto (int *offset_p
, int *size_p
)
2095 static const unsigned char buf
[] = {
2096 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2097 0xa7, 0x24, 0x00, 0x0e, /* jh .Ltrue */
2098 0xa7, 0x44, 0x00, 0x06, /* jl .Lfalse */
2099 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2100 0xa7, 0x24, 0x00, 0x08, /* jh .Ltrue */
2102 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2103 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2104 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2106 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2107 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2108 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2111 add_insns (buf
, sizeof buf
);
2118 /* The "emit_le_goto" emit_ops method for s390. */
2121 s390_emit_le_goto (int *offset_p
, int *size_p
)
2123 static const unsigned char buf
[] = {
2124 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2125 0xa7, 0x24, 0x00, 0x0e, /* jh .Ltrue */
2126 0xa7, 0x44, 0x00, 0x06, /* jl .Lfalse */
2127 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2128 0xa7, 0xa4, 0x00, 0x08, /* jhe .Ltrue */
2130 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2131 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2132 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2134 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2135 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2136 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2139 add_insns (buf
, sizeof buf
);
2146 /* The "emit_gt_goto" emit_ops method for s390. */
2149 s390_emit_gt_goto (int *offset_p
, int *size_p
)
2151 static const unsigned char buf
[] = {
2152 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2153 0xa7, 0x44, 0x00, 0x0e, /* jl .Ltrue */
2154 0xa7, 0x24, 0x00, 0x06, /* jh .Lfalse */
2155 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2156 0xa7, 0x44, 0x00, 0x08, /* jl .Ltrue */
2158 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2159 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2160 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2162 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2163 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2164 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2167 add_insns (buf
, sizeof buf
);
2174 /* The "emit_ge_goto" emit_ops method for s390. */
2177 s390_emit_ge_goto (int *offset_p
, int *size_p
)
2179 static const unsigned char buf
[] = {
2180 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2181 0xa7, 0x44, 0x00, 0x0e, /* jl .Ltrue */
2182 0xa7, 0x24, 0x00, 0x06, /* jh .Lfalse */
2183 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2184 0xa7, 0xc4, 0x00, 0x08, /* jle .Ltrue */
2186 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2187 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2188 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2190 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2191 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2192 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2195 add_insns (buf
, sizeof buf
);
2202 /* The "emit_ops" structure for s390. Named _impl to avoid name
2203 collision with s390_emit_ops function. */
2205 static struct emit_ops s390_emit_ops_impl
=
2213 s390_emit_rsh_signed
,
2214 s390_emit_rsh_unsigned
,
2222 s390_emit_less_signed
,
2223 s390_emit_less_unsigned
,
2227 s390_write_goto_address
,
2232 s390_emit_stack_flush
,
2235 s390_emit_stack_adjust
,
2236 s390_emit_int_call_1
,
2237 s390_emit_void_call_2
,
2248 /* The "emit_prologue" emit_ops method for s390x. */
2251 s390x_emit_prologue (void)
2253 static const unsigned char buf
[] = {
2254 0xeb, 0x9f, 0xf0, 0x48, 0x00, 0x24, /* stmg %r9, %r15, 0x48(%r15) */
2255 0xb9, 0x04, 0x00, 0x92, /* lgr %r9, %r2 */
2256 0xb9, 0x04, 0x00, 0xa3, /* lgr %r10, %r3 */
2257 0xb9, 0x04, 0x00, 0xbf, /* lgr %r11, %r15 */
2259 add_insns (buf
, sizeof buf
);
2262 /* The "emit_epilogue" emit_ops method for s390x. */
2265 s390x_emit_epilogue (void)
2267 static const unsigned char buf
[] = {
2268 0xe3, 0x20, 0xa0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r10) */
2269 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2270 0xeb, 0x9f, 0xf0, 0x48, 0x00, 0x04, /* lmg %r9, %r15, 0x48(%r15) */
2271 0x07, 0xfe, /* br %r14 */
2273 add_insns (buf
, sizeof buf
);
2276 /* The "emit_add" emit_ops method for s390x. */
2279 s390x_emit_add (void)
2281 static const unsigned char buf
[] = {
2282 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x0a, /* alg %r2, 0(%r15) */
2283 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2285 add_insns (buf
, sizeof buf
);
2288 /* The "emit_sub" emit_ops method for s390x. */
2291 s390x_emit_sub (void)
2293 static const unsigned char buf
[] = {
2294 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2295 0xb9, 0x0b, 0x00, 0x32, /* slgr %r3, %r2 */
2296 0xb9, 0x04, 0x00, 0x23, /* lgr %r2, %r3 */
2297 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2299 add_insns (buf
, sizeof buf
);
2302 /* The "emit_mul" emit_ops method for s390x. */
2305 s390x_emit_mul (void)
2310 /* The "emit_lsh" emit_ops method for s390x. */
2313 s390x_emit_lsh (void)
2315 static const unsigned char buf
[] = {
2316 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2317 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0d, /* sllg %r2, %r3, 0(%r2) */
2318 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2320 add_insns (buf
, sizeof buf
);
2323 /* The "emit_rsh_signed" emit_ops method for s390x. */
2326 s390x_emit_rsh_signed (void)
2328 static const unsigned char buf
[] = {
2329 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2330 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0a, /* srag %r2, %r3, 0(%r2) */
2331 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2333 add_insns (buf
, sizeof buf
);
2336 /* The "emit_rsh_unsigned" emit_ops method for s390x. */
2339 s390x_emit_rsh_unsigned (void)
2341 static const unsigned char buf
[] = {
2342 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2343 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0c, /* srlg %r2, %r3, 0(%r2) */
2344 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2346 add_insns (buf
, sizeof buf
);
2349 /* The "emit_ext" emit_ops method for s390x. */
2352 s390x_emit_ext (int arg
)
2354 unsigned char buf
[] = {
2355 /* sllg %r2, %r2, <64-arg> */
2356 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0d,
2357 /* srag %r2, %r2, <64-arg> */
2358 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0a,
2360 add_insns (buf
, sizeof buf
);
2363 /* The "emit_log_not" emit_ops method for s390x. */
2366 s390x_emit_log_not (void)
2368 static const unsigned char buf
[] = {
2369 0xb9, 0x00, 0x00, 0x22, /* lpgr %r2, %r2 */
2370 0xa7, 0x2b, 0xff, 0xff, /* aghi %r2, -1 */
2371 0xeb, 0x22, 0x00, 0x3f, 0x00, 0x0c, /* srlg %r2, %r2, 63 */
2373 add_insns (buf
, sizeof buf
);
2376 /* The "emit_bit_and" emit_ops method for s390x. */
2379 s390x_emit_bit_and (void)
2381 static const unsigned char buf
[] = {
2382 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x80, /* ng %r2, 0(%r15) */
2383 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2385 add_insns (buf
, sizeof buf
);
2388 /* The "emit_bit_or" emit_ops method for s390x. */
2391 s390x_emit_bit_or (void)
2393 static const unsigned char buf
[] = {
2394 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x81, /* og %r2, 0(%r15) */
2395 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2397 add_insns (buf
, sizeof buf
);
2400 /* The "emit_bit_xor" emit_ops method for s390x. */
2403 s390x_emit_bit_xor (void)
2405 static const unsigned char buf
[] = {
2406 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x82, /* xg %r2, 0(%r15) */
2407 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2409 add_insns (buf
, sizeof buf
);
2412 /* The "emit_bit_not" emit_ops method for s390x. */
2415 s390x_emit_bit_not (void)
2417 static const unsigned char buf
[] = {
2418 0xa7, 0x39, 0xff, 0xff, /* lghi %r3, -1 */
2419 0xb9, 0x82, 0x00, 0x23, /* xgr %r2, %r3 */
2421 add_insns (buf
, sizeof buf
);
2424 /* The "emit_equal" emit_ops method for s390x. */
2427 s390x_emit_equal (void)
2429 s390x_emit_bit_xor ();
2430 s390x_emit_log_not ();
2433 /* The "emit_less_signed" emit_ops method for s390x. */
2436 s390x_emit_less_signed (void)
2438 static const unsigned char buf
[] = {
2439 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2440 0xa7, 0x29, 0x00, 0x01, /* lghi %r2, 1 */
2441 0xa7, 0x24, 0x00, 0x04, /* jh .Lend */
2442 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2444 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2446 add_insns (buf
, sizeof buf
);
2449 /* The "emit_less_unsigned" emit_ops method for s390x. */
2452 s390x_emit_less_unsigned (void)
2454 static const unsigned char buf
[] = {
2455 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x21, /* clg %r2, 0(%r15) */
2456 0xa7, 0x29, 0x00, 0x01, /* lghi %r2, 1 */
2457 0xa7, 0x24, 0x00, 0x04, /* jh .Lend */
2458 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2460 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2462 add_insns (buf
, sizeof buf
);
2465 /* The "emit_ref" emit_ops method for s390x. */
2468 s390x_emit_ref (int size
)
2470 static const unsigned char buf1
[] = {
2471 0xe3, 0x20, 0x20, 0x00, 0x00, 0x90, /* llgc %r2, 0(%r2) */
2473 static const unsigned char buf2
[] = {
2474 0xe3, 0x20, 0x20, 0x00, 0x00, 0x91 /* llgh %r2, 0(%r2) */
2476 static const unsigned char buf4
[] = {
2477 0xe3, 0x20, 0x20, 0x00, 0x00, 0x16, /* llgf %r2, 0(%r2) */
2479 static const unsigned char buf8
[] = {
2480 0xe3, 0x20, 0x20, 0x00, 0x00, 0x04, /* lg %r2, 0(%r2) */
2485 add_insns (buf1
, sizeof buf1
);
2488 add_insns (buf2
, sizeof buf2
);
2491 add_insns (buf4
, sizeof buf4
);
2494 add_insns (buf8
, sizeof buf8
);
2501 /* The "emit_if_goto" emit_ops method for s390x. */
2504 s390x_emit_if_goto (int *offset_p
, int *size_p
)
2506 static const unsigned char buf
[] = {
2507 0xb9, 0x02, 0x00, 0x22, /* ltgr %r2, %r2 */
2508 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x04, /* lg %r2, 0(%r15) */
2509 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2510 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2512 add_insns (buf
, sizeof buf
);
2519 /* The "emit_const" emit_ops method for s390x. */
2522 s390x_emit_const (LONGEST num
)
2524 unsigned long long n
= num
;
2525 unsigned char buf_s
[] = {
2526 /* lghi %r2, <num> */
2527 0xa7, 0x29, (unsigned char) (num
>> 8), (unsigned char) num
,
2529 static const unsigned char buf_l
[] = {
2530 0xe3, 0x20, 0x10, 0x00, 0x00, 0x04, /* lg %r2, 0(%r1) */
2532 if (num
< 0x8000 && num
>= -0x8000)
2534 add_insns (buf_s
, sizeof buf_s
);
2538 s390_emit_litpool (8);
2539 add_insns ((unsigned char *) &n
, sizeof n
);
2540 add_insns (buf_l
, sizeof buf_l
);
2544 /* The "emit_call" emit_ops method for s390x. */
2547 s390x_emit_call (CORE_ADDR fn
)
2549 unsigned long n
= fn
;
2550 static const unsigned char buf
[] = {
2551 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, /* lg %r1, 0(%r1) */
2552 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
2553 0x0d, 0xe1, /* basr %r14, %r1 */
2554 0xa7, 0xfb, 0x00, 0xa0, /* aghi %r15, 0xa0 */
2556 s390_emit_litpool (8);
2557 add_insns ((unsigned char *) &n
, sizeof n
);
2558 add_insns (buf
, sizeof buf
);
2561 /* The "emit_reg" emit_ops method for s390x. */
2564 s390x_emit_reg (int reg
)
2566 unsigned char buf
[] = {
2568 0xb9, 0x04, 0x00, 0x29,
2569 /* lghi %r3, <reg> */
2570 0xa7, 0x39, (unsigned char) (reg
>> 8), (unsigned char) reg
,
2572 add_insns (buf
, sizeof buf
);
2573 s390x_emit_call (get_raw_reg_func_addr ());
2576 /* The "emit_pop" emit_ops method for s390x. */
2579 s390x_emit_pop (void)
2581 static const unsigned char buf
[] = {
2582 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x04, /* lg %r2, 0(%r15) */
2583 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2585 add_insns (buf
, sizeof buf
);
2588 /* The "emit_stack_flush" emit_ops method for s390x. */
2591 s390x_emit_stack_flush (void)
2593 static const unsigned char buf
[] = {
2594 0xa7, 0xfb, 0xff, 0xf8, /* aghi %r15, -8 */
2595 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r15) */
2597 add_insns (buf
, sizeof buf
);
2600 /* The "emit_zero_ext" emit_ops method for s390x. */
2603 s390x_emit_zero_ext (int arg
)
2605 unsigned char buf
[] = {
2606 /* sllg %r2, %r2, <64-arg> */
2607 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0d,
2608 /* srlg %r2, %r2, <64-arg> */
2609 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0c,
2611 add_insns (buf
, sizeof buf
);
2614 /* The "emit_swap" emit_ops method for s390x. */
2617 s390x_emit_swap (void)
2619 static const unsigned char buf
[] = {
2620 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2621 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r15) */
2622 0xb9, 0x04, 0x00, 0x23, /* lgr %r2, %r3 */
2624 add_insns (buf
, sizeof buf
);
2627 /* The "emit_stack_adjust" emit_ops method for s390x. */
2630 s390x_emit_stack_adjust (int n
)
2632 unsigned char buf
[] = {
2633 /* aghi %r15, 8*n */
2635 (unsigned char) (n
* 8 >> 8), (unsigned char) (n
* 8),
2637 add_insns (buf
, sizeof buf
);
2640 /* The "emit_int_call_1" emit_ops method for s390x. */
2643 s390x_emit_int_call_1 (CORE_ADDR fn
, int arg1
)
2645 /* FN's prototype is `LONGEST(*fn)(int)'. */
2646 s390x_emit_const (arg1
);
2647 s390x_emit_call (fn
);
2650 /* The "emit_void_call_2" emit_ops method for s390x. */
2653 s390x_emit_void_call_2 (CORE_ADDR fn
, int arg1
)
2655 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
2656 static const unsigned char buf
[] = {
2657 0xb9, 0x04, 0x00, 0x32, /* lgr %r3, %r2 */
2658 0xb9, 0x04, 0x00, 0xc2, /* lgr %r12, %r2 */
2660 static const unsigned char buf2
[] = {
2661 0xb9, 0x04, 0x00, 0x2c, /* lgr %r2, %r12 */
2663 add_insns (buf
, sizeof buf
);
2664 s390x_emit_const (arg1
);
2665 s390x_emit_call (fn
);
2666 add_insns (buf2
, sizeof buf2
);
2669 /* The "emit_eq_goto" emit_ops method for s390x. */
2672 s390x_emit_eq_goto (int *offset_p
, int *size_p
)
2674 static const unsigned char buf
[] = {
2675 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2676 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2677 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2678 0xc0, 0x84, 0x00, 0x00, 0x00, 0x00, /* jge <fillme> */
2680 add_insns (buf
, sizeof buf
);
2687 /* The "emit_ne_goto" emit_ops method for s390x. */
2690 s390x_emit_ne_goto (int *offset_p
, int *size_p
)
2692 static const unsigned char buf
[] = {
2693 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2694 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2695 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2696 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2698 add_insns (buf
, sizeof buf
);
2705 /* The "emit_lt_goto" emit_ops method for s390x. */
2708 s390x_emit_lt_goto (int *offset_p
, int *size_p
)
2710 static const unsigned char buf
[] = {
2711 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2712 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2713 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2714 0xc0, 0x24, 0x00, 0x00, 0x00, 0x00, /* jgh <fillme> */
2716 add_insns (buf
, sizeof buf
);
2723 /* The "emit_le_goto" emit_ops method for s390x. */
2726 s390x_emit_le_goto (int *offset_p
, int *size_p
)
2728 static const unsigned char buf
[] = {
2729 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2730 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2731 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2732 0xc0, 0xa4, 0x00, 0x00, 0x00, 0x00, /* jghe <fillme> */
2734 add_insns (buf
, sizeof buf
);
2741 /* The "emit_gt_goto" emit_ops method for s390x. */
2744 s390x_emit_gt_goto (int *offset_p
, int *size_p
)
2746 static const unsigned char buf
[] = {
2747 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2748 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2749 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2750 0xc0, 0x44, 0x00, 0x00, 0x00, 0x00, /* jgl <fillme> */
2752 add_insns (buf
, sizeof buf
);
2759 /* The "emit_ge_goto" emit_ops method for s390x. */
2762 s390x_emit_ge_goto (int *offset_p
, int *size_p
)
2764 static const unsigned char buf
[] = {
2765 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2766 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2767 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2768 0xc0, 0xc4, 0x00, 0x00, 0x00, 0x00, /* jgle <fillme> */
2770 add_insns (buf
, sizeof buf
);
2777 /* The "emit_ops" structure for s390x. */
2779 static struct emit_ops s390x_emit_ops
=
2781 s390x_emit_prologue
,
2782 s390x_emit_epilogue
,
2787 s390x_emit_rsh_signed
,
2788 s390x_emit_rsh_unsigned
,
2796 s390x_emit_less_signed
,
2797 s390x_emit_less_unsigned
,
2801 s390_write_goto_address
,
2806 s390x_emit_stack_flush
,
2807 s390x_emit_zero_ext
,
2809 s390x_emit_stack_adjust
,
2810 s390x_emit_int_call_1
,
2811 s390x_emit_void_call_2
,
2821 /* The "emit_ops" linux_target_ops method. */
2823 static struct emit_ops
*
2824 s390_emit_ops (void)
2827 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
2829 if (register_size (regcache
->tdesc
, 0) == 8)
2830 return &s390x_emit_ops
;
2833 return &s390_emit_ops_impl
;
2836 struct linux_target_ops the_low_target
= {
2838 s390_supports_z_point_type
,
2843 s390_collect_ptrace_register
,
2844 s390_supply_ptrace_register
,
2845 NULL
, /* siginfo_fixup */
2846 NULL
, /* new_process */
2847 NULL
, /* delete_process */
2848 NULL
, /* new_thread */
2849 NULL
, /* delete_thread */
2850 NULL
, /* new_fork */
2851 NULL
, /* prepare_to_resume */
2852 NULL
, /* process_qsupported */
2853 s390_supports_tracepoints
,
2854 s390_get_thread_area
,
2855 s390_install_fast_tracepoint_jump_pad
,
2857 s390_get_min_fast_tracepoint_insn_len
,
2858 NULL
, /* supports_range_stepping */
2859 s390_supports_hardware_single_step
,
2860 NULL
, /* get_syscall_trapinfo */
2861 s390_get_ipa_tdesc_idx
,
2864 /* The linux target ops object. */
2866 linux_process_target
*the_linux_target
= &the_s390_target
;
2869 initialize_low_arch (void)
2871 /* Initialize the Linux target descriptions. */
2873 init_registers_s390_linux32 ();
2874 init_registers_s390_linux32v1 ();
2875 init_registers_s390_linux32v2 ();
2876 init_registers_s390_linux64 ();
2877 init_registers_s390_linux64v1 ();
2878 init_registers_s390_linux64v2 ();
2879 init_registers_s390_te_linux64 ();
2880 init_registers_s390_vx_linux64 ();
2881 init_registers_s390_tevx_linux64 ();
2882 init_registers_s390_gs_linux64 ();
2884 init_registers_s390x_linux64 ();
2885 init_registers_s390x_linux64v1 ();
2886 init_registers_s390x_linux64v2 ();
2887 init_registers_s390x_te_linux64 ();
2888 init_registers_s390x_vx_linux64 ();
2889 init_registers_s390x_tevx_linux64 ();
2890 init_registers_s390x_gs_linux64 ();
2893 initialize_regsets_info (&s390_regsets_info
);
2894 initialize_regsets_info (&s390_regsets_info_3264
);