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
;
64 bool supports_z_point_type (char z_type
) override
;
66 bool supports_tracepoints () override
;
68 bool supports_fast_tracepoints () override
;
70 int install_fast_tracepoint_jump_pad
71 (CORE_ADDR tpoint
, CORE_ADDR tpaddr
, CORE_ADDR collector
,
72 CORE_ADDR lockaddr
, ULONGEST orig_size
, CORE_ADDR
*jump_entry
,
73 CORE_ADDR
*trampoline
, ULONGEST
*trampoline_size
,
74 unsigned char *jjump_pad_insn
, ULONGEST
*jjump_pad_insn_size
,
75 CORE_ADDR
*adjusted_insn_addr
, CORE_ADDR
*adjusted_insn_addr_end
,
78 int get_min_fast_tracepoint_insn_len () override
;
80 void low_collect_ptrace_register (regcache
*regcache
, int regno
,
83 void low_supply_ptrace_register (regcache
*regcache
, int regno
,
84 const char *buf
) override
;
88 void low_arch_setup () override
;
90 bool low_cannot_fetch_register (int regno
) override
;
92 bool low_cannot_store_register (int regno
) override
;
94 bool low_supports_breakpoints () override
;
96 CORE_ADDR
low_get_pc (regcache
*regcache
) override
;
98 void low_set_pc (regcache
*regcache
, CORE_ADDR newpc
) override
;
100 int low_decr_pc_after_break () override
;
102 bool low_breakpoint_at (CORE_ADDR pc
) override
;
104 int low_get_thread_area (int lwpid
, CORE_ADDR
*addrp
) override
;
107 /* The singleton target ops object. */
109 static s390_target the_s390_target
;
111 static int s390_regmap
[] = {
112 PT_PSWMASK
, PT_PSWADDR
,
114 PT_GPR0
, PT_GPR1
, PT_GPR2
, PT_GPR3
,
115 PT_GPR4
, PT_GPR5
, PT_GPR6
, PT_GPR7
,
116 PT_GPR8
, PT_GPR9
, PT_GPR10
, PT_GPR11
,
117 PT_GPR12
, PT_GPR13
, PT_GPR14
, PT_GPR15
,
119 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
120 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
121 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
122 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
,
132 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
133 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
134 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
135 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
141 #define s390_num_regs_3264 68
144 static int s390_regmap_3264
[] = {
145 PT_PSWMASK
, PT_PSWADDR
,
147 PT_GPR0
, PT_GPR0
, PT_GPR1
, PT_GPR1
,
148 PT_GPR2
, PT_GPR2
, PT_GPR3
, PT_GPR3
,
149 PT_GPR4
, PT_GPR4
, PT_GPR5
, PT_GPR5
,
150 PT_GPR6
, PT_GPR6
, PT_GPR7
, PT_GPR7
,
151 PT_GPR8
, PT_GPR8
, PT_GPR9
, PT_GPR9
,
152 PT_GPR10
, PT_GPR10
, PT_GPR11
, PT_GPR11
,
153 PT_GPR12
, PT_GPR12
, PT_GPR13
, PT_GPR13
,
154 PT_GPR14
, PT_GPR14
, PT_GPR15
, PT_GPR15
,
156 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
157 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
158 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
159 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
163 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
164 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
165 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
166 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
171 static int s390_regmap_3264
[] = {
172 PT_PSWMASK
, PT_PSWADDR
,
174 -1, PT_GPR0
, -1, PT_GPR1
,
175 -1, PT_GPR2
, -1, PT_GPR3
,
176 -1, PT_GPR4
, -1, PT_GPR5
,
177 -1, PT_GPR6
, -1, PT_GPR7
,
178 -1, PT_GPR8
, -1, PT_GPR9
,
179 -1, PT_GPR10
, -1, PT_GPR11
,
180 -1, PT_GPR12
, -1, PT_GPR13
,
181 -1, PT_GPR14
, -1, PT_GPR15
,
183 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
184 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
185 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
186 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
190 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
191 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
192 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
193 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
201 s390_target::low_cannot_fetch_register (int regno
)
207 s390_target::low_cannot_store_register (int regno
)
213 s390_target::low_collect_ptrace_register (regcache
*regcache
, int regno
,
216 int size
= register_size (regcache
->tdesc
, regno
);
217 const struct regs_info
*regs_info
= get_regs_info ();
218 struct usrregs_info
*usr
= regs_info
->usrregs
;
219 int regaddr
= usr
->regmap
[regno
];
221 if (size
< sizeof (long))
223 memset (buf
, 0, sizeof (long));
225 if ((regno
^ 1) < usr
->num_regs
226 && usr
->regmap
[regno
^ 1] == regaddr
)
228 collect_register (regcache
, regno
& ~1, buf
);
229 collect_register (regcache
, (regno
& ~1) + 1,
230 buf
+ sizeof (long) - size
);
232 else if (regaddr
== PT_PSWMASK
)
234 /* Convert 4-byte PSW mask to 8 bytes by clearing bit 12 and copying
235 the basic addressing mode bit from the PSW address. */
236 gdb_byte
*addr
= (gdb_byte
*) alloca (register_size (regcache
->tdesc
, regno
^ 1));
237 collect_register (regcache
, regno
, buf
);
238 collect_register (regcache
, regno
^ 1, addr
);
240 buf
[size
] |= (addr
[0] & 0x80);
242 else if (regaddr
== PT_PSWADDR
)
244 /* Convert 4-byte PSW address to 8 bytes by clearing the addressing
245 mode bit (which gets copied to the PSW mask instead). */
246 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
247 buf
[sizeof (long) - size
] &= ~0x80;
249 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
250 || regaddr
== PT_ORIGGPR2
)
251 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
253 collect_register (regcache
, regno
, buf
);
255 else if (regaddr
!= -1)
256 collect_register (regcache
, regno
, buf
);
260 s390_target::low_supply_ptrace_register (regcache
*regcache
, int regno
,
263 int size
= register_size (regcache
->tdesc
, regno
);
264 const struct regs_info
*regs_info
= get_regs_info ();
265 struct usrregs_info
*usr
= regs_info
->usrregs
;
266 int regaddr
= usr
->regmap
[regno
];
268 if (size
< sizeof (long))
270 if ((regno
^ 1) < usr
->num_regs
271 && usr
->regmap
[regno
^ 1] == regaddr
)
273 supply_register (regcache
, regno
& ~1, buf
);
274 supply_register (regcache
, (regno
& ~1) + 1,
275 buf
+ sizeof (long) - size
);
277 else if (regaddr
== PT_PSWMASK
)
279 /* Convert 8-byte PSW mask to 4 bytes by setting bit 12 and copying
280 the basic addressing mode into the PSW address. */
281 gdb_byte
*mask
= (gdb_byte
*) alloca (size
);
282 gdb_byte
*addr
= (gdb_byte
*) alloca (register_size (regcache
->tdesc
, regno
^ 1));
283 memcpy (mask
, buf
, size
);
285 supply_register (regcache
, regno
, mask
);
287 collect_register (regcache
, regno
^ 1, addr
);
289 addr
[0] |= (buf
[size
] & 0x80);
290 supply_register (regcache
, regno
^ 1, addr
);
292 else if (regaddr
== PT_PSWADDR
)
294 /* Convert 8-byte PSW address to 4 bytes by truncating, but
295 keeping the addressing mode bit (which was set from the mask). */
296 gdb_byte
*addr
= (gdb_byte
*) alloca (size
);
298 collect_register (regcache
, regno
, addr
);
299 amode
= addr
[0] & 0x80;
300 memcpy (addr
, buf
+ sizeof (long) - size
, size
);
303 supply_register (regcache
, regno
, addr
);
305 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
306 || regaddr
== PT_ORIGGPR2
)
307 supply_register (regcache
, regno
, buf
+ sizeof (long) - size
);
309 supply_register (regcache
, regno
, buf
);
311 else if (regaddr
!= -1)
312 supply_register (regcache
, regno
, buf
);
315 /* Provide only a fill function for the general register set. ps_lgetregs
316 will use this for NPTL support. */
319 s390_fill_gregset (struct regcache
*regcache
, void *buf
)
322 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
323 struct usrregs_info
*usr
= regs_info
->usrregs
;
325 for (i
= 0; i
< usr
->num_regs
; i
++)
327 if (usr
->regmap
[i
] < PT_PSWMASK
328 || usr
->regmap
[i
] > PT_ACR15
)
331 ((s390_target
*) the_linux_target
)->low_collect_ptrace_register
332 (regcache
, i
, (char *) buf
+ usr
->regmap
[i
]);
336 /* Fill and store functions for extended register sets. */
340 s390_fill_gprs_high (struct regcache
*regcache
, void *buf
)
342 int r0h
= find_regno (regcache
->tdesc
, "r0h");
345 for (i
= 0; i
< 16; i
++)
346 collect_register (regcache
, r0h
+ 2 * i
, (char *) buf
+ 4 * i
);
350 s390_store_gprs_high (struct regcache
*regcache
, const void *buf
)
352 int r0h
= find_regno (regcache
->tdesc
, "r0h");
355 for (i
= 0; i
< 16; i
++)
356 supply_register (regcache
, r0h
+ 2 * i
, (const char *) buf
+ 4 * i
);
361 s390_store_last_break (struct regcache
*regcache
, const void *buf
)
365 p
= (const char *) buf
+ 8 - register_size (regcache
->tdesc
, 0);
366 supply_register_by_name (regcache
, "last_break", p
);
370 s390_fill_system_call (struct regcache
*regcache
, void *buf
)
372 collect_register_by_name (regcache
, "system_call", buf
);
376 s390_store_system_call (struct regcache
*regcache
, const void *buf
)
378 supply_register_by_name (regcache
, "system_call", buf
);
382 s390_store_tdb (struct regcache
*regcache
, const void *buf
)
384 int tdb0
= find_regno (regcache
->tdesc
, "tdb0");
385 int tr0
= find_regno (regcache
->tdesc
, "tr0");
388 for (i
= 0; i
< 4; i
++)
389 supply_register (regcache
, tdb0
+ i
, (const char *) buf
+ 8 * i
);
391 for (i
= 0; i
< 16; i
++)
392 supply_register (regcache
, tr0
+ i
, (const char *) buf
+ 8 * (16 + i
));
396 s390_fill_vxrs_low (struct regcache
*regcache
, void *buf
)
398 int v0
= find_regno (regcache
->tdesc
, "v0l");
401 for (i
= 0; i
< 16; i
++)
402 collect_register (regcache
, v0
+ i
, (char *) buf
+ 8 * i
);
406 s390_store_vxrs_low (struct regcache
*regcache
, const void *buf
)
408 int v0
= find_regno (regcache
->tdesc
, "v0l");
411 for (i
= 0; i
< 16; i
++)
412 supply_register (regcache
, v0
+ i
, (const char *) buf
+ 8 * i
);
416 s390_fill_vxrs_high (struct regcache
*regcache
, void *buf
)
418 int v16
= find_regno (regcache
->tdesc
, "v16");
421 for (i
= 0; i
< 16; i
++)
422 collect_register (regcache
, v16
+ i
, (char *) buf
+ 16 * i
);
426 s390_store_vxrs_high (struct regcache
*regcache
, const void *buf
)
428 int v16
= find_regno (regcache
->tdesc
, "v16");
431 for (i
= 0; i
< 16; i
++)
432 supply_register (regcache
, v16
+ i
, (const char *) buf
+ 16 * i
);
436 s390_store_gs (struct regcache
*regcache
, const void *buf
)
438 int gsd
= find_regno (regcache
->tdesc
, "gsd");
441 for (i
= 0; i
< 3; i
++)
442 supply_register (regcache
, gsd
+ i
, (const char *) buf
+ 8 * (i
+ 1));
446 s390_store_gsbc (struct regcache
*regcache
, const void *buf
)
448 int bc_gsd
= find_regno (regcache
->tdesc
, "bc_gsd");
451 for (i
= 0; i
< 3; i
++)
452 supply_register (regcache
, bc_gsd
+ i
, (const char *) buf
+ 8 * (i
+ 1));
455 static struct regset_info s390_regsets
[] = {
456 { 0, 0, 0, 0, GENERAL_REGS
, s390_fill_gregset
, NULL
},
458 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_HIGH_GPRS
, 0,
459 EXTENDED_REGS
, s390_fill_gprs_high
, s390_store_gprs_high
},
461 /* Last break address is read-only; no fill function. */
462 { PTRACE_GETREGSET
, -1, NT_S390_LAST_BREAK
, 0, EXTENDED_REGS
,
463 NULL
, s390_store_last_break
},
464 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_SYSTEM_CALL
, 0,
465 EXTENDED_REGS
, s390_fill_system_call
, s390_store_system_call
},
466 /* TDB is read-only. */
467 { PTRACE_GETREGSET
, -1, NT_S390_TDB
, 0, EXTENDED_REGS
,
468 NULL
, s390_store_tdb
},
469 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_VXRS_LOW
, 0,
470 EXTENDED_REGS
, s390_fill_vxrs_low
, s390_store_vxrs_low
},
471 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_VXRS_HIGH
, 0,
472 EXTENDED_REGS
, s390_fill_vxrs_high
, s390_store_vxrs_high
},
473 /* Guarded storage registers are read-only. */
474 { PTRACE_GETREGSET
, -1, NT_S390_GS_CB
, 0, EXTENDED_REGS
,
475 NULL
, s390_store_gs
},
476 { PTRACE_GETREGSET
, -1, NT_S390_GS_BC
, 0, EXTENDED_REGS
,
477 NULL
, s390_store_gsbc
},
482 static const gdb_byte s390_breakpoint
[] = { 0, 1 };
483 #define s390_breakpoint_len 2
485 /* Implementation of target ops method "sw_breakpoint_from_kind". */
488 s390_target::sw_breakpoint_from_kind (int kind
, int *size
)
490 *size
= s390_breakpoint_len
;
491 return s390_breakpoint
;
495 s390_target::low_supports_breakpoints ()
501 s390_target::low_get_pc (regcache
*regcache
)
503 if (register_size (regcache
->tdesc
, 0) == 4)
506 collect_register_by_name (regcache
, "pswa", &pswa
);
507 return pswa
& 0x7fffffff;
512 collect_register_by_name (regcache
, "pswa", &pc
);
518 s390_target::low_set_pc (regcache
*regcache
, CORE_ADDR newpc
)
520 if (register_size (regcache
->tdesc
, 0) == 4)
523 collect_register_by_name (regcache
, "pswa", &pswa
);
524 pswa
= (pswa
& 0x80000000) | (newpc
& 0x7fffffff);
525 supply_register_by_name (regcache
, "pswa", &pswa
);
529 unsigned long pc
= newpc
;
530 supply_register_by_name (regcache
, "pswa", &pc
);
535 s390_target::low_decr_pc_after_break ()
537 return s390_breakpoint_len
;
540 /* Determine the word size for the given PID, in bytes. */
544 s390_get_wordsize (int pid
)
547 PTRACE_XFER_TYPE pswm
= ptrace (PTRACE_PEEKUSER
, pid
,
548 (PTRACE_TYPE_ARG3
) 0,
549 (PTRACE_TYPE_ARG4
) 0);
552 warning (_("Couldn't determine word size, assuming 64-bit."));
555 /* Derive word size from extended addressing mode (PSW bit 31). */
556 return pswm
& (1L << 32) ? 8 : 4;
559 #define s390_get_wordsize(pid) 4
563 s390_check_regset (int pid
, int regset
, int regsize
)
565 void *buf
= alloca (regsize
);
569 iov
.iov_len
= regsize
;
571 if (ptrace (PTRACE_GETREGSET
, pid
, (long) regset
, (long) &iov
) >= 0
577 /* For a 31-bit inferior, whether the kernel supports using the full
579 static int have_hwcap_s390_high_gprs
= 0;
580 static int have_hwcap_s390_vx
= 0;
583 s390_target::low_arch_setup ()
585 const struct target_desc
*tdesc
;
586 struct regset_info
*regset
;
588 /* Determine word size and HWCAP. */
589 int pid
= pid_of (current_thread
);
590 int wordsize
= s390_get_wordsize (pid
);
591 unsigned long hwcap
= linux_get_hwcap (wordsize
);
593 /* Check whether the kernel supports extra register sets. */
594 int have_regset_last_break
595 = s390_check_regset (pid
, NT_S390_LAST_BREAK
, 8);
596 int have_regset_system_call
597 = s390_check_regset (pid
, NT_S390_SYSTEM_CALL
, 4);
599 = (s390_check_regset (pid
, NT_S390_TDB
, 256)
600 && (hwcap
& HWCAP_S390_TE
) != 0);
602 = (s390_check_regset (pid
, NT_S390_VXRS_LOW
, 128)
603 && s390_check_regset (pid
, NT_S390_VXRS_HIGH
, 256)
604 && (hwcap
& HWCAP_S390_VX
) != 0);
606 = (s390_check_regset (pid
, NT_S390_GS_CB
, 32)
607 && s390_check_regset (pid
, NT_S390_GS_BC
, 32)
608 && (hwcap
& HWCAP_S390_GS
) != 0);
615 tdesc
= tdesc_s390x_gs_linux64
;
616 else if (have_regset_vxrs
)
617 tdesc
= (have_regset_tdb
? tdesc_s390x_tevx_linux64
:
618 tdesc_s390x_vx_linux64
);
619 else if (have_regset_tdb
)
620 tdesc
= tdesc_s390x_te_linux64
;
621 else if (have_regset_system_call
)
622 tdesc
= tdesc_s390x_linux64v2
;
623 else if (have_regset_last_break
)
624 tdesc
= tdesc_s390x_linux64v1
;
626 tdesc
= tdesc_s390x_linux64
;
629 /* For a 31-bit inferior, check whether the kernel supports
630 using the full 64-bit GPRs. */
633 if (hwcap
& HWCAP_S390_HIGH_GPRS
)
635 have_hwcap_s390_high_gprs
= 1;
637 tdesc
= tdesc_s390_gs_linux64
;
638 else if (have_regset_vxrs
)
639 tdesc
= (have_regset_tdb
? tdesc_s390_tevx_linux64
:
640 tdesc_s390_vx_linux64
);
641 else if (have_regset_tdb
)
642 tdesc
= tdesc_s390_te_linux64
;
643 else if (have_regset_system_call
)
644 tdesc
= tdesc_s390_linux64v2
;
645 else if (have_regset_last_break
)
646 tdesc
= tdesc_s390_linux64v1
;
648 tdesc
= tdesc_s390_linux64
;
652 /* Assume 31-bit inferior process. */
653 if (have_regset_system_call
)
654 tdesc
= tdesc_s390_linux32v2
;
655 else if (have_regset_last_break
)
656 tdesc
= tdesc_s390_linux32v1
;
658 tdesc
= tdesc_s390_linux32
;
661 have_hwcap_s390_vx
= have_regset_vxrs
;
664 /* Update target_regsets according to available register sets. */
665 for (regset
= s390_regsets
; regset
->size
>= 0; regset
++)
666 if (regset
->get_request
== PTRACE_GETREGSET
)
667 switch (regset
->nt_type
)
670 case NT_S390_HIGH_GPRS
:
671 regset
->size
= have_hwcap_s390_high_gprs
? 64 : 0;
674 case NT_S390_LAST_BREAK
:
675 regset
->size
= have_regset_last_break
? 8 : 0;
677 case NT_S390_SYSTEM_CALL
:
678 regset
->size
= have_regset_system_call
? 4 : 0;
681 regset
->size
= have_regset_tdb
? 256 : 0;
683 case NT_S390_VXRS_LOW
:
684 regset
->size
= have_regset_vxrs
? 128 : 0;
686 case NT_S390_VXRS_HIGH
:
687 regset
->size
= have_regset_vxrs
? 256 : 0;
691 regset
->size
= have_regset_gs
? 32 : 0;
696 current_process ()->tdesc
= tdesc
;
701 s390_target::low_breakpoint_at (CORE_ADDR pc
)
703 unsigned char c
[s390_breakpoint_len
];
704 read_inferior_memory (pc
, c
, s390_breakpoint_len
);
705 return memcmp (c
, s390_breakpoint
, s390_breakpoint_len
) == 0;
708 /* Breakpoint/Watchpoint support. */
710 /* The "supports_z_point_type" target ops method. */
713 s390_target::supports_z_point_type (char z_type
)
724 /* Support for hardware single step. */
727 s390_supports_hardware_single_step (void)
732 static struct usrregs_info s390_usrregs_info
=
738 static struct regsets_info s390_regsets_info
=
740 s390_regsets
, /* regsets */
742 NULL
, /* disabled_regsets */
745 static struct regs_info myregs_info
=
747 NULL
, /* regset_bitmap */
752 static struct usrregs_info s390_usrregs_info_3264
=
758 static struct regsets_info s390_regsets_info_3264
=
760 s390_regsets
, /* regsets */
762 NULL
, /* disabled_regsets */
765 static struct regs_info regs_info_3264
=
767 NULL
, /* regset_bitmap */
768 &s390_usrregs_info_3264
,
769 &s390_regsets_info_3264
773 s390_target::get_regs_info ()
775 if (have_hwcap_s390_high_gprs
)
778 const struct target_desc
*tdesc
= current_process ()->tdesc
;
780 if (register_size (tdesc
, 0) == 4)
781 return ®s_info_3264
;
783 return ®s_info_3264
;
789 /* The "supports_tracepoints" target ops method. */
792 s390_target::supports_tracepoints ()
797 /* Implementation of linux target ops method "low_get_thread_area". */
800 s390_target::low_get_thread_area (int lwpid
, CORE_ADDR
*addrp
)
802 CORE_ADDR res
= ptrace (PTRACE_PEEKUSER
, lwpid
, (long) PT_ACR0
, (long) 0);
804 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
806 if (register_size (regcache
->tdesc
, 0) == 4)
807 res
&= 0xffffffffull
;
814 /* Fast tracepoint support.
816 The register save area on stack is identical for all targets:
818 0x000+i*0x10: VR0-VR31
825 If we're on 31-bit linux, we just don't store the high parts of the GPRs.
826 Likewise, if there's no VX support, we just store the FRs into the slots
827 of low VR halves. The agent code is responsible for rearranging that
830 /* Code sequence saving GPRs for 31-bit target with no high GPRs. There's
831 one trick used at the very beginning: since there's no way to allocate
832 stack space without destroying CC (lay instruction can do it, but it's
833 only supported on later CPUs), we take 4 different execution paths for
834 every possible value of CC, allocate stack space, save %r0, stuff the
835 CC value in %r0 (shifted to match its position in PSWM high word),
836 then branch to common path. */
838 static const unsigned char s390_ft_entry_gpr_esa
[] = {
839 0xa7, 0x14, 0x00, 0x1e, /* jo .Lcc3 */
840 0xa7, 0x24, 0x00, 0x14, /* jh .Lcc2 */
841 0xa7, 0x44, 0x00, 0x0a, /* jl .Lcc1 */
843 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
844 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
845 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
846 0xa7, 0xf4, 0x00, 0x18, /* j .Lccdone */
848 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
849 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
850 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
851 0xa7, 0xf4, 0x00, 0x10, /* j .Lccdone */
853 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
854 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
855 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
856 0xa7, 0xf4, 0x00, 0x08, /* j .Lccdone */
858 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
859 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
860 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
862 0x50, 0x10, 0xf2, 0x0c, /* st %r1, 0x20c(%r15) */
863 0x50, 0x20, 0xf2, 0x14, /* st %r2, 0x214(%r15) */
864 0x50, 0x30, 0xf2, 0x1c, /* st %r3, 0x21c(%r15) */
865 0x50, 0x40, 0xf2, 0x24, /* st %r4, 0x224(%r15) */
866 0x50, 0x50, 0xf2, 0x2c, /* st %r5, 0x22c(%r15) */
867 0x50, 0x60, 0xf2, 0x34, /* st %r6, 0x234(%r15) */
868 0x50, 0x70, 0xf2, 0x3c, /* st %r7, 0x23c(%r15) */
869 0x50, 0x80, 0xf2, 0x44, /* st %r8, 0x244(%r15) */
870 0x50, 0x90, 0xf2, 0x4c, /* st %r9, 0x24c(%r15) */
871 0x50, 0xa0, 0xf2, 0x54, /* st %r10, 0x254(%r15) */
872 0x50, 0xb0, 0xf2, 0x5c, /* st %r11, 0x25c(%r15) */
873 0x50, 0xc0, 0xf2, 0x64, /* st %r12, 0x264(%r15) */
874 0x50, 0xd0, 0xf2, 0x6c, /* st %r13, 0x26c(%r15) */
875 0x50, 0xe0, 0xf2, 0x74, /* st %r14, 0x274(%r15) */
876 /* Compute original value of %r15 and store it. We use ahi instead
877 of la to preserve the whole value, and not just the low 31 bits.
878 This is not particularly important here, but essential in the
879 zarch case where someone might be using the high word of %r15
880 as an extra register. */
881 0x18, 0x1f, /* lr %r1, %r15 */
882 0xa7, 0x1a, 0x03, 0x00, /* ahi %r1, 0x300 */
883 0x50, 0x10, 0xf2, 0x7c, /* st %r1, 0x27c(%r15) */
886 /* Code sequence saving GPRs for 31-bit target with high GPRs and for 64-bit
887 target. Same as above, except this time we can use load/store multiple,
888 since the 64-bit regs are tightly packed. */
890 static const unsigned char s390_ft_entry_gpr_zarch
[] = {
891 0xa7, 0x14, 0x00, 0x21, /* jo .Lcc3 */
892 0xa7, 0x24, 0x00, 0x16, /* jh .Lcc2 */
893 0xa7, 0x44, 0x00, 0x0b, /* jl .Lcc1 */
895 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
896 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
897 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
898 0xa7, 0xf4, 0x00, 0x1b, /* j .Lccdone */
900 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
901 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
902 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
903 0xa7, 0xf4, 0x00, 0x12, /* j .Lccdone */
905 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
906 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
907 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
908 0xa7, 0xf4, 0x00, 0x09, /* j .Lccdone */
910 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
911 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
912 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
914 0xb9, 0x04, 0x00, 0x1f, /* lgr %r1, %r15 */
915 0xa7, 0x1b, 0x03, 0x00, /* aghi %r1, 0x300 */
916 0xe3, 0x10, 0xf2, 0x78, 0x00, 0x24, /* stg %r1, 0x278(%r15) */
919 /* Code sequence saving ARs, PSWM and FPC. PSWM has to be assembled from
920 current PSWM (read by epsw) and CC from entry (in %r0). */
922 static const unsigned char s390_ft_entry_misc
[] = {
923 0x9b, 0x0f, 0xf2, 0x80, /* stam %a0, %a15, 0x20(%%r15) */
924 0xb9, 0x8d, 0x00, 0x23, /* epsw %r2, %r3 */
925 0xa7, 0x18, 0xcf, 0xff, /* lhi %r1, ~0x3000 */
926 0x14, 0x21, /* nr %r2, %r1 */
927 0x16, 0x20, /* or %r2, %r0 */
928 0x50, 0x20, 0xf2, 0xc0, /* st %r2, 0x2c0(%r15) */
929 0x50, 0x30, 0xf2, 0xc4, /* st %r3, 0x2c4(%r15) */
930 0xb2, 0x9c, 0xf2, 0xd0, /* stfpc 0x2d0(%r15) */
933 /* Code sequence saving FRs, used if VX not supported. */
935 static const unsigned char s390_ft_entry_fr
[] = {
936 0x60, 0x00, 0xf0, 0x00, /* std %f0, 0x000(%r15) */
937 0x60, 0x10, 0xf0, 0x10, /* std %f1, 0x010(%r15) */
938 0x60, 0x20, 0xf0, 0x20, /* std %f2, 0x020(%r15) */
939 0x60, 0x30, 0xf0, 0x30, /* std %f3, 0x030(%r15) */
940 0x60, 0x40, 0xf0, 0x40, /* std %f4, 0x040(%r15) */
941 0x60, 0x50, 0xf0, 0x50, /* std %f5, 0x050(%r15) */
942 0x60, 0x60, 0xf0, 0x60, /* std %f6, 0x060(%r15) */
943 0x60, 0x70, 0xf0, 0x70, /* std %f7, 0x070(%r15) */
944 0x60, 0x80, 0xf0, 0x80, /* std %f8, 0x080(%r15) */
945 0x60, 0x90, 0xf0, 0x90, /* std %f9, 0x090(%r15) */
946 0x60, 0xa0, 0xf0, 0xa0, /* std %f10, 0x0a0(%r15) */
947 0x60, 0xb0, 0xf0, 0xb0, /* std %f11, 0x0b0(%r15) */
948 0x60, 0xc0, 0xf0, 0xc0, /* std %f12, 0x0c0(%r15) */
949 0x60, 0xd0, 0xf0, 0xd0, /* std %f13, 0x0d0(%r15) */
950 0x60, 0xe0, 0xf0, 0xe0, /* std %f14, 0x0e0(%r15) */
951 0x60, 0xf0, 0xf0, 0xf0, /* std %f15, 0x0f0(%r15) */
954 /* Code sequence saving VRs, used if VX not supported. */
956 static const unsigned char s390_ft_entry_vr
[] = {
957 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x3e, /* vstm %v0, %v15, 0x000(%r15) */
958 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x3e, /* vstm %v16, %v31, 0x100(%r15) */
961 /* Code sequence doing the collection call for 31-bit target. %r1 contains
962 the address of the literal pool. */
964 static const unsigned char s390_ft_main_31
[] = {
965 /* Load the literals into registers. */
966 0x58, 0x50, 0x10, 0x00, /* l %r5, 0x0(%r1) */
967 0x58, 0x20, 0x10, 0x04, /* l %r2, 0x4(%r1) */
968 0x58, 0x40, 0x10, 0x08, /* l %r4, 0x8(%r1) */
969 0x58, 0x60, 0x10, 0x0c, /* l %r6, 0xc(%r1) */
970 /* Save original PSWA (tracepoint address | 0x80000000). */
971 0x50, 0x50, 0xf2, 0xcc, /* st %r5, 0x2cc(%r15) */
972 /* Construct a collecting_t object at %r15+0x2e0. */
973 0x50, 0x20, 0xf2, 0xe0, /* st %r2, 0x2e0(%r15) */
974 0x9b, 0x00, 0xf2, 0xe4, /* stam %a0, %a0, 0x2e4(%r15) */
975 /* Move its address to %r0. */
976 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
979 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
980 0xba, 0x10, 0x60, 0x00, /* cs %r1, %r0, 0(%r6) */
981 0xa7, 0x74, 0xff, 0xfc, /* jne .Lloop */
982 /* Address of the register save block to %r3. */
983 0x18, 0x3f, /* lr %r3, %r15 */
984 /* Make a stack frame, so that we can call the collector. */
985 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
987 0x0d, 0xe4, /* basr %r14, %r4 */
988 /* And get rid of the stack frame again. */
989 0x41, 0xf0, 0xf0, 0x60, /* la %r15, 0x60(%r15) */
990 /* Leave the lock. */
991 0x07, 0xf0, /* br %r0 */
992 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
993 0x50, 0x10, 0x60, 0x00, /* st %t1, 0(%r6) */
996 /* Code sequence doing the collection call for 64-bit target. %r1 contains
997 the address of the literal pool. */
999 static const unsigned char s390_ft_main_64
[] = {
1000 /* Load the literals into registers. */
1001 0xe3, 0x50, 0x10, 0x00, 0x00, 0x04, /* lg %r5, 0x00(%r1) */
1002 0xe3, 0x20, 0x10, 0x08, 0x00, 0x04, /* lg %r2, 0x08(%r1) */
1003 0xe3, 0x40, 0x10, 0x10, 0x00, 0x04, /* lg %r4, 0x10(%r1) */
1004 0xe3, 0x60, 0x10, 0x18, 0x00, 0x04, /* lg %r6, 0x18(%r1) */
1005 /* Save original PSWA (tracepoint address). */
1006 0xe3, 0x50, 0xf2, 0xc8, 0x00, 0x24, /* stg %r5, 0x2c8(%r15) */
1007 /* Construct a collecting_t object at %r15+0x2e0. */
1008 0xe3, 0x20, 0xf2, 0xe0, 0x00, 0x24, /* stg %r2, 0x2e0(%r15) */
1009 0x9b, 0x01, 0xf2, 0xe8, /* stam %a0, %a1, 0x2e8(%r15) */
1010 /* Move its address to %r0. */
1011 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
1012 /* Take the lock. */
1014 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
1015 0xeb, 0x10, 0x60, 0x00, 0x00, 0x30, /* csg %r1, %r0, 0(%r6) */
1016 0xa7, 0x74, 0xff, 0xfb, /* jne .Lloop */
1017 /* Address of the register save block to %r3. */
1018 0xb9, 0x04, 0x00, 0x3f, /* lgr %r3, %r15 */
1019 /* Make a stack frame, so that we can call the collector. */
1020 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
1022 0x0d, 0xe4, /* basr %r14, %r4 */
1023 /* And get rid of the stack frame again. */
1024 0x41, 0xf0, 0xf0, 0xa0, /* la %r15, 0xa0(%r15) */
1025 /* Leave the lock. */
1026 0x07, 0xf0, /* br %r0 */
1027 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
1028 0xe3, 0x10, 0x60, 0x00, 0x00, 0x24, /* stg %t1, 0(%r6) */
1031 /* Code sequence restoring FRs, for targets with no VX support. */
1033 static const unsigned char s390_ft_exit_fr
[] = {
1034 0x68, 0x00, 0xf0, 0x00, /* ld %f0, 0x000(%r15) */
1035 0x68, 0x10, 0xf0, 0x10, /* ld %f1, 0x010(%r15) */
1036 0x68, 0x20, 0xf0, 0x20, /* ld %f2, 0x020(%r15) */
1037 0x68, 0x30, 0xf0, 0x30, /* ld %f3, 0x030(%r15) */
1038 0x68, 0x40, 0xf0, 0x40, /* ld %f4, 0x040(%r15) */
1039 0x68, 0x50, 0xf0, 0x50, /* ld %f5, 0x050(%r15) */
1040 0x68, 0x60, 0xf0, 0x60, /* ld %f6, 0x060(%r15) */
1041 0x68, 0x70, 0xf0, 0x70, /* ld %f7, 0x070(%r15) */
1042 0x68, 0x80, 0xf0, 0x80, /* ld %f8, 0x080(%r15) */
1043 0x68, 0x90, 0xf0, 0x90, /* ld %f9, 0x090(%r15) */
1044 0x68, 0xa0, 0xf0, 0xa0, /* ld %f10, 0x0a0(%r15) */
1045 0x68, 0xb0, 0xf0, 0xb0, /* ld %f11, 0x0b0(%r15) */
1046 0x68, 0xc0, 0xf0, 0xc0, /* ld %f12, 0x0c0(%r15) */
1047 0x68, 0xd0, 0xf0, 0xd0, /* ld %f13, 0x0d0(%r15) */
1048 0x68, 0xe0, 0xf0, 0xe0, /* ld %f14, 0x0e0(%r15) */
1049 0x68, 0xf0, 0xf0, 0xf0, /* ld %f15, 0x0f0(%r15) */
1052 /* Code sequence restoring VRs. */
1054 static const unsigned char s390_ft_exit_vr
[] = {
1055 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x36, /* vlm %v0, %v15, 0x000(%r15) */
1056 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x36, /* vlm %v16, %v31, 0x100(%r15) */
1059 /* Code sequence restoring misc registers. As for PSWM, only CC should be
1060 modified by C code, so we use the alr instruction to restore it by
1061 manufacturing an operand that'll result in the original flags. */
1063 static const unsigned char s390_ft_exit_misc
[] = {
1064 0xb2, 0x9d, 0xf2, 0xd0, /* lfpc 0x2d0(%r15) */
1065 0x58, 0x00, 0xf2, 0xc0, /* l %r0, 0x2c0(%r15) */
1066 /* Extract CC to high 2 bits of %r0. */
1067 0x88, 0x00, 0x00, 0x0c, /* srl %r0, 12 */
1068 0x89, 0x00, 0x00, 0x1e, /* sll %r0, 30 */
1069 /* Add %r0 to itself. Result will be nonzero iff CC bit 0 is set, and
1070 will have carry iff CC bit 1 is set - resulting in the same flags
1072 0x1e, 0x00, /* alr %r0, %r0 */
1073 0x9a, 0x0f, 0xf2, 0x80, /* lam %a0, %a15, 0x280(%r15) */
1076 /* Code sequence restoring GPRs, for 31-bit targets with no high GPRs. */
1078 static const unsigned char s390_ft_exit_gpr_esa
[] = {
1079 0x58, 0x00, 0xf2, 0x04, /* l %r0, 0x204(%r15) */
1080 0x58, 0x10, 0xf2, 0x0c, /* l %r1, 0x20c(%r15) */
1081 0x58, 0x20, 0xf2, 0x14, /* l %r2, 0x214(%r15) */
1082 0x58, 0x30, 0xf2, 0x1c, /* l %r3, 0x21c(%r15) */
1083 0x58, 0x40, 0xf2, 0x24, /* l %r4, 0x224(%r15) */
1084 0x58, 0x50, 0xf2, 0x2c, /* l %r5, 0x22c(%r15) */
1085 0x58, 0x60, 0xf2, 0x34, /* l %r6, 0x234(%r15) */
1086 0x58, 0x70, 0xf2, 0x3c, /* l %r7, 0x23c(%r15) */
1087 0x58, 0x80, 0xf2, 0x44, /* l %r8, 0x244(%r15) */
1088 0x58, 0x90, 0xf2, 0x4c, /* l %r9, 0x24c(%r15) */
1089 0x58, 0xa0, 0xf2, 0x54, /* l %r10, 0x254(%r15) */
1090 0x58, 0xb0, 0xf2, 0x5c, /* l %r11, 0x25c(%r15) */
1091 0x58, 0xc0, 0xf2, 0x64, /* l %r12, 0x264(%r15) */
1092 0x58, 0xd0, 0xf2, 0x6c, /* l %r13, 0x26c(%r15) */
1093 0x58, 0xe0, 0xf2, 0x74, /* l %r14, 0x274(%r15) */
1094 0x58, 0xf0, 0xf2, 0x7c, /* l %r15, 0x27c(%r15) */
1097 /* Code sequence restoring GPRs, for 64-bit targets and 31-bit targets
1100 static const unsigned char s390_ft_exit_gpr_zarch
[] = {
1101 0xeb, 0x0f, 0xf2, 0x00, 0x00, 0x04, /* lmg %r0, %r15, 0x200(%r15) */
1104 /* Writes instructions to target, updating the to pointer. */
1107 append_insns (CORE_ADDR
*to
, size_t len
, const unsigned char *buf
)
1109 target_write_memory (*to
, buf
, len
);
1113 /* Relocates an instruction from oldloc to *to, updating to. */
1116 s390_relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
, int is_64
)
1121 /* 0: no fixup, 1: PC16DBL fixup, 2: PC32DBL fixup. */
1124 read_inferior_memory (oldloc
, buf
, sizeof buf
);
1127 else if (buf
[0] < 0xc0)
1133 case 0x05: /* BALR */
1134 case 0x0c: /* BASSM */
1135 case 0x0d: /* BASR */
1136 case 0x45: /* BAL */
1137 case 0x4d: /* BAS */
1138 /* These save a return address and mess around with registers.
1139 We can't relocate them. */
1141 case 0x84: /* BRXH */
1142 case 0x85: /* BRXLE */
1147 /* BRC, BRAS, BRCT, BRCTG */
1148 if (op2
>= 4 && op2
<= 7)
1156 /* LARL, BRCL, BRASL */
1157 if (op2
== 0 || op2
== 4 || op2
== 5)
1165 /* PC-relative addressing instructions. */
1168 case 0xc5: /* BPRP */
1169 case 0xc7: /* BPP */
1170 /* Branch prediction - just skip it. */
1182 case 0x44: /* BRXHG */
1183 case 0x45: /* BRXLG */
1184 case 0x64: /* CGRJ */
1185 case 0x65: /* CLGRJ */
1186 case 0x76: /* CRJ */
1187 case 0x77: /* CLRJ */
1196 /* We'll have to relocate an instruction with a PC-relative field.
1197 First, compute the target. */
1198 int64_t loffset
= 0;
1202 int16_t soffset
= 0;
1203 memcpy (&soffset
, buf
+ 2, 2);
1208 int32_t soffset
= 0;
1209 memcpy (&soffset
, buf
+ 2, 4);
1212 target
= oldloc
+ loffset
* 2;
1214 target
&= 0x7fffffff;
1218 /* BRAS or BRASL was used. We cannot just relocate those, since
1219 they save the return address in a register. We can, however,
1220 replace them with a LARL+JG sequence. */
1222 /* Make the LARL. */
1226 loffset
= oldloc
+ ilen
- *to
;
1229 if (soffset
!= loffset
&& is_64
)
1231 memcpy (buf
+ 2, &soffset
, 4);
1232 append_insns (to
, 6, buf
);
1234 /* Note: this is not fully correct. In 31-bit mode, LARL will write
1235 an address with the top bit 0, while BRAS/BRASL will write it
1236 with top bit 1. It should not matter much, since linux compilers
1237 use BR and not BSM to return from functions, but it could confuse
1238 some poor stack unwinder. */
1240 /* We'll now be writing a JG. */
1247 /* Compute the new offset and write it to the buffer. */
1248 loffset
= target
- *to
;
1253 int16_t soffset
= loffset
;
1254 if (soffset
!= loffset
)
1256 memcpy (buf
+ 2, &soffset
, 2);
1260 int32_t soffset
= loffset
;
1261 if (soffset
!= loffset
&& is_64
)
1263 memcpy (buf
+ 2, &soffset
, 4);
1266 append_insns (to
, ilen
, buf
);
1271 s390_target::supports_fast_tracepoints ()
1276 /* Implementation of target ops method
1277 "install_fast_tracepoint_jump_pad". */
1280 s390_target::install_fast_tracepoint_jump_pad
1281 (CORE_ADDR tpoint
, CORE_ADDR tpaddr
, CORE_ADDR collector
,
1282 CORE_ADDR lockaddr
, ULONGEST orig_size
, CORE_ADDR
*jump_entry
,
1283 CORE_ADDR
*trampoline
, ULONGEST
*trampoline_size
,
1284 unsigned char *jjump_pad_insn
, ULONGEST
*jjump_pad_insn_size
,
1285 CORE_ADDR
*adjusted_insn_addr
, CORE_ADDR
*adjusted_insn_addr_end
,
1291 unsigned char jbuf
[6] = { 0xc0, 0xf4, 0, 0, 0, 0 }; /* jg ... */
1292 CORE_ADDR buildaddr
= *jump_entry
;
1294 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1295 int is_64
= register_size (regcache
->tdesc
, 0) == 8;
1296 int is_zarch
= is_64
|| have_hwcap_s390_high_gprs
;
1297 int has_vx
= have_hwcap_s390_vx
;
1299 int is_64
= 0, is_zarch
= 0, has_vx
= 0;
1301 CORE_ADDR literals
[4] = {
1308 /* First, store the GPRs. */
1310 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_zarch
,
1311 s390_ft_entry_gpr_zarch
);
1313 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_esa
,
1314 s390_ft_entry_gpr_esa
);
1316 /* Second, misc registers (ARs, PSWM, FPC). PSWA will be stored below. */
1317 append_insns (&buildaddr
, sizeof s390_ft_entry_misc
, s390_ft_entry_misc
);
1319 /* Third, FRs or VRs. */
1321 append_insns (&buildaddr
, sizeof s390_ft_entry_vr
, s390_ft_entry_vr
);
1323 append_insns (&buildaddr
, sizeof s390_ft_entry_fr
, s390_ft_entry_fr
);
1325 /* Now, the main part of code - store PSWA, take lock, call collector,
1326 leave lock. First, we'll need to fetch 4 literals. */
1328 unsigned char buf
[] = {
1329 0x07, 0x07, /* nopr %r7 */
1330 0x07, 0x07, /* nopr %r7 */
1331 0x07, 0x07, /* nopr %r7 */
1332 0xa7, 0x15, 0x00, 0x12, /* bras %r1, .Lend */
1333 0, 0, 0, 0, 0, 0, 0, 0, /* tpaddr */
1334 0, 0, 0, 0, 0, 0, 0, 0, /* tpoint */
1335 0, 0, 0, 0, 0, 0, 0, 0, /* collector */
1336 0, 0, 0, 0, 0, 0, 0, 0, /* lockaddr */
1339 /* Find the proper start place in buf, so that literals will be
1341 int bufpos
= (buildaddr
+ 2) & 7;
1342 /* Stuff the literals into the buffer. */
1343 for (i
= 0; i
< 4; i
++) {
1344 uint64_t lit
= literals
[i
];
1345 memcpy (&buf
[sizeof buf
- 32 + i
* 8], &lit
, 8);
1347 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1348 append_insns (&buildaddr
, sizeof s390_ft_main_64
, s390_ft_main_64
);
1350 unsigned char buf
[] = {
1351 0x07, 0x07, /* nopr %r7 */
1352 0xa7, 0x15, 0x00, 0x0a, /* bras %r1, .Lend */
1353 0, 0, 0, 0, /* tpaddr */
1354 0, 0, 0, 0, /* tpoint */
1355 0, 0, 0, 0, /* collector */
1356 0, 0, 0, 0, /* lockaddr */
1359 /* Find the proper start place in buf, so that literals will be
1361 int bufpos
= (buildaddr
+ 2) & 3;
1362 /* First literal will be saved as the PSWA, make sure it has the high bit
1364 literals
[0] |= 0x80000000;
1365 /* Stuff the literals into the buffer. */
1366 for (i
= 0; i
< 4; i
++) {
1367 uint32_t lit
= literals
[i
];
1368 memcpy (&buf
[sizeof buf
- 16 + i
* 4], &lit
, 4);
1370 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1371 append_insns (&buildaddr
, sizeof s390_ft_main_31
, s390_ft_main_31
);
1374 /* Restore FRs or VRs. */
1376 append_insns (&buildaddr
, sizeof s390_ft_exit_vr
, s390_ft_exit_vr
);
1378 append_insns (&buildaddr
, sizeof s390_ft_exit_fr
, s390_ft_exit_fr
);
1380 /* Restore misc registers. */
1381 append_insns (&buildaddr
, sizeof s390_ft_exit_misc
, s390_ft_exit_misc
);
1383 /* Restore the GPRs. */
1385 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_zarch
,
1386 s390_ft_exit_gpr_zarch
);
1388 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_esa
,
1389 s390_ft_exit_gpr_esa
);
1391 /* Now, adjust the original instruction to execute in the jump
1393 *adjusted_insn_addr
= buildaddr
;
1394 if (s390_relocate_instruction (&buildaddr
, tpaddr
, is_64
))
1396 sprintf (err
, "E.Could not relocate instruction for tracepoint.");
1399 *adjusted_insn_addr_end
= buildaddr
;
1401 /* Finally, write a jump back to the program. */
1403 loffset
= (tpaddr
+ orig_size
) - buildaddr
;
1406 if (is_64
&& offset
!= loffset
)
1409 "E.Jump back from jump pad too far from tracepoint "
1410 "(offset 0x%" PRIx64
" > int33).", loffset
);
1413 memcpy (jbuf
+ 2, &offset
, 4);
1414 append_insns (&buildaddr
, sizeof jbuf
, jbuf
);
1416 /* The jump pad is now built. Wire in a jump to our jump pad. This
1417 is always done last (by our caller actually), so that we can
1418 install fast tracepoints with threads running. This relies on
1419 the agent's atomic write support. */
1420 loffset
= *jump_entry
- tpaddr
;
1423 if (is_64
&& offset
!= loffset
)
1426 "E.Jump back from jump pad too far from tracepoint "
1427 "(offset 0x%" PRIx64
" > int33).", loffset
);
1430 memcpy (jbuf
+ 2, &offset
, 4);
1431 memcpy (jjump_pad_insn
, jbuf
, sizeof jbuf
);
1432 *jjump_pad_insn_size
= sizeof jbuf
;
1434 /* Return the end address of our pad. */
1435 *jump_entry
= buildaddr
;
1440 /* Implementation of target ops method
1441 "get_min_fast_tracepoint_insn_len". */
1444 s390_target::get_min_fast_tracepoint_insn_len ()
1446 /* We only support using 6-byte jumps to reach the tracepoint code.
1447 If the tracepoint buffer were allocated sufficiently close (64kiB)
1448 to the executable code, and the traced instruction itself was close
1449 enough to the beginning, we could use 4-byte jumps, but this doesn't
1450 seem to be worth the effort. */
1454 /* Implementation of linux_target_ops method "get_ipa_tdesc_idx". */
1457 s390_get_ipa_tdesc_idx (void)
1459 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1460 const struct target_desc
*tdesc
= regcache
->tdesc
;
1463 if (tdesc
== tdesc_s390x_linux64
)
1464 return S390_TDESC_64
;
1465 if (tdesc
== tdesc_s390x_linux64v1
)
1466 return S390_TDESC_64V1
;
1467 if (tdesc
== tdesc_s390x_linux64v2
)
1468 return S390_TDESC_64V2
;
1469 if (tdesc
== tdesc_s390x_te_linux64
)
1470 return S390_TDESC_TE
;
1471 if (tdesc
== tdesc_s390x_vx_linux64
)
1472 return S390_TDESC_VX
;
1473 if (tdesc
== tdesc_s390x_tevx_linux64
)
1474 return S390_TDESC_TEVX
;
1475 if (tdesc
== tdesc_s390x_gs_linux64
)
1476 return S390_TDESC_GS
;
1479 if (tdesc
== tdesc_s390_linux32
)
1480 return S390_TDESC_32
;
1481 if (tdesc
== tdesc_s390_linux32v1
)
1482 return S390_TDESC_32V1
;
1483 if (tdesc
== tdesc_s390_linux32v2
)
1484 return S390_TDESC_32V2
;
1485 if (tdesc
== tdesc_s390_linux64
)
1486 return S390_TDESC_64
;
1487 if (tdesc
== tdesc_s390_linux64v1
)
1488 return S390_TDESC_64V1
;
1489 if (tdesc
== tdesc_s390_linux64v2
)
1490 return S390_TDESC_64V2
;
1491 if (tdesc
== tdesc_s390_te_linux64
)
1492 return S390_TDESC_TE
;
1493 if (tdesc
== tdesc_s390_vx_linux64
)
1494 return S390_TDESC_VX
;
1495 if (tdesc
== tdesc_s390_tevx_linux64
)
1496 return S390_TDESC_TEVX
;
1497 if (tdesc
== tdesc_s390_gs_linux64
)
1498 return S390_TDESC_GS
;
1503 /* Appends given buffer to current_insn_ptr in the target. */
1506 add_insns (const unsigned char *start
, int len
)
1508 CORE_ADDR buildaddr
= current_insn_ptr
;
1511 debug_printf ("Adding %d bytes of insn at %s\n",
1512 len
, paddress (buildaddr
));
1514 append_insns (&buildaddr
, len
, start
);
1515 current_insn_ptr
= buildaddr
;
1518 /* Register usage in emit:
1521 - %r2: top of stack (high word for 31-bit)
1522 - %r3: low word of top of stack (for 31-bit)
1524 - %r6, %r7, %r8: don't use
1527 - %r11: frame pointer
1528 - %r12: saved top of stack for void_call_2 (high word for 31-bit)
1529 - %r13: low word of saved top of stack (for 31-bit)
1530 - %r14: return address for calls
1531 - %r15: stack pointer
1535 /* The "emit_prologue" emit_ops method for s390. */
1538 s390_emit_prologue (void)
1540 static const unsigned char buf
[] = {
1541 0x90, 0x9f, 0xf0, 0x24, /* stm %r9, %r15, 0x24(%r15) */
1542 0x18, 0x92, /* lr %r9, %r2 */
1543 0x18, 0xa3, /* lr %r10, %r3 */
1544 0x18, 0xbf, /* lr %r11, %r15 */
1546 add_insns (buf
, sizeof buf
);
1549 /* The "emit_epilogue" emit_ops method for s390. */
1552 s390_emit_epilogue (void)
1554 static const unsigned char buf
[] = {
1555 0x90, 0x23, 0xa0, 0x00, /* stm %r2, %r3, 0(%r10) */
1556 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1557 0x98, 0x9f, 0xb0, 0x24, /* lm %r9, %r15, 0x24(%r11) */
1558 0x07, 0xfe, /* br %r14 */
1560 add_insns (buf
, sizeof buf
);
1563 /* The "emit_add" emit_ops method for s390. */
1566 s390_emit_add (void)
1568 static const unsigned char buf
[] = {
1569 0x5e, 0x30, 0xf0, 0x04, /* al %r3, 4(%r15) */
1570 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x98, /* al %r2, 0(%r15) */
1571 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1573 add_insns (buf
, sizeof buf
);
1576 /* The "emit_sub" emit_ops method for s390. */
1579 s390_emit_sub (void)
1581 static const unsigned char buf
[] = {
1582 0x98, 0x45, 0xf0, 0x00, /* lm %r4, %r5, 0(%r15) */
1583 0x1f, 0x53, /* slr %r5, %r3 */
1584 0xb9, 0x99, 0x00, 0x42, /* slbr %r4, %r2 */
1585 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1586 0x18, 0x35, /* lr %r3, %r5 */
1587 0x18, 0x24, /* lr %r2, %r4 */
1589 add_insns (buf
, sizeof buf
);
1592 /* The "emit_mul" emit_ops method for s390. */
1595 s390_emit_mul (void)
1600 /* The "emit_lsh" emit_ops method for s390. */
1603 s390_emit_lsh (void)
1605 static const unsigned char buf
[] = {
1606 0x18, 0x43, /* lr %r4, %r3 */
1607 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1608 0x8d, 0x20, 0x40, 0x00, /* sldl %r2, 0(%r4) */
1609 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1611 add_insns (buf
, sizeof buf
);
1614 /* The "emit_rsh_signed" emit_ops method for s390. */
1617 s390_emit_rsh_signed (void)
1619 static const unsigned char buf
[] = {
1620 0x18, 0x43, /* lr %r4, %r3 */
1621 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1622 0x8e, 0x20, 0x40, 0x00, /* srda %r2, 0(%r4) */
1623 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1625 add_insns (buf
, sizeof buf
);
1628 /* The "emit_rsh_unsigned" emit_ops method for s390. */
1631 s390_emit_rsh_unsigned (void)
1633 static const unsigned char buf
[] = {
1634 0x18, 0x43, /* lr %r4, %r3 */
1635 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1636 0x8c, 0x20, 0x40, 0x00, /* srdl %r2, 0(%r4) */
1637 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1639 add_insns (buf
, sizeof buf
);
1642 /* The "emit_ext" emit_ops method for s390. */
1645 s390_emit_ext (int arg
)
1647 unsigned char buf
[] = {
1648 0x8d, 0x20, 0x00, (unsigned char) (64 - arg
), /* sldl %r2, <64-arg> */
1649 0x8e, 0x20, 0x00, (unsigned char) (64 - arg
), /* srda %r2, <64-arg> */
1651 add_insns (buf
, sizeof buf
);
1654 /* The "emit_log_not" emit_ops method for s390. */
1657 s390_emit_log_not (void)
1659 static const unsigned char buf
[] = {
1660 0x16, 0x23, /* or %r2, %r3 */
1661 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1662 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1663 0xa7, 0x74, 0x00, 0x04, /* jne .Lskip */
1664 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1667 add_insns (buf
, sizeof buf
);
1670 /* The "emit_bit_and" emit_ops method for s390. */
1673 s390_emit_bit_and (void)
1675 static const unsigned char buf
[] = {
1676 0x54, 0x20, 0xf0, 0x00, /* n %r2, 0(%r15) */
1677 0x54, 0x30, 0xf0, 0x04, /* n %r3, 4(%r15) */
1678 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1680 add_insns (buf
, sizeof buf
);
1683 /* The "emit_bit_or" emit_ops method for s390. */
1686 s390_emit_bit_or (void)
1688 static const unsigned char buf
[] = {
1689 0x56, 0x20, 0xf0, 0x00, /* o %r2, 0(%r15) */
1690 0x56, 0x30, 0xf0, 0x04, /* o %r3, 4(%r15) */
1691 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1693 add_insns (buf
, sizeof buf
);
1696 /* The "emit_bit_xor" emit_ops method for s390. */
1699 s390_emit_bit_xor (void)
1701 static const unsigned char buf
[] = {
1702 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
1703 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
1704 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1706 add_insns (buf
, sizeof buf
);
1709 /* The "emit_bit_not" emit_ops method for s390. */
1712 s390_emit_bit_not (void)
1714 static const unsigned char buf
[] = {
1715 0xa7, 0x48, 0xff, 0xff, /* lhi %r4, -1 */
1716 0x17, 0x24, /* xr %r2, %r4 */
1717 0x17, 0x34, /* xr %r3, %r4 */
1719 add_insns (buf
, sizeof buf
);
1722 /* The "emit_equal" emit_ops method for s390. */
1725 s390_emit_equal (void)
1727 s390_emit_bit_xor ();
1728 s390_emit_log_not ();
1731 /* The "emit_less_signed" emit_ops method for s390. */
1734 s390_emit_less_signed (void)
1736 static const unsigned char buf
[] = {
1737 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
1738 0xa7, 0x24, 0x00, 0x0c, /* jh .Lless */
1739 0xa7, 0x44, 0x00, 0x06, /* jl .Lhigh */
1740 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
1741 0xa7, 0x24, 0x00, 0x06, /* jh .Lless */
1743 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1744 0xa7, 0xf4, 0x00, 0x04, /* j .Lend */
1746 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1748 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1749 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1751 add_insns (buf
, sizeof buf
);
1754 /* The "emit_less_unsigned" emit_ops method for s390. */
1757 s390_emit_less_unsigned (void)
1759 static const unsigned char buf
[] = {
1760 0x55, 0x20, 0xf0, 0x00, /* cl %r2, 0(%r15) */
1761 0xa7, 0x24, 0x00, 0x0c, /* jh .Lless */
1762 0xa7, 0x44, 0x00, 0x06, /* jl .Lhigh */
1763 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
1764 0xa7, 0x24, 0x00, 0x06, /* jh .Lless */
1766 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1767 0xa7, 0xf4, 0x00, 0x04, /* j .Lend */
1769 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1771 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1772 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1774 add_insns (buf
, sizeof buf
);
1777 /* The "emit_ref" emit_ops method for s390. */
1780 s390_emit_ref (int size
)
1782 static const unsigned char buf1
[] = {
1783 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1784 0x43, 0x30, 0x30, 0x00, /* ic %r3, 0(%r3) */
1786 static const unsigned char buf2
[] = {
1787 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1788 0x48, 0x30, 0x30, 0x00, /* lh %r3, 0(%r3) */
1790 static const unsigned char buf4
[] = {
1791 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1792 0x58, 0x30, 0x30, 0x00, /* l %r3, 0(%r3) */
1794 static const unsigned char buf8
[] = {
1795 0x98, 0x23, 0x30, 0x00, /* lm %r2, %r3, 0(%r3) */
1800 add_insns (buf1
, sizeof buf1
);
1803 add_insns (buf2
, sizeof buf2
);
1806 add_insns (buf4
, sizeof buf4
);
1809 add_insns (buf8
, sizeof buf8
);
1816 /* The "emit_if_goto" emit_ops method for s390. */
1819 s390_emit_if_goto (int *offset_p
, int *size_p
)
1821 static const unsigned char buf
[] = {
1822 0x16, 0x23, /* or %r2, %r3 */
1823 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1824 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1825 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00 /* jgne <fillme> */
1827 add_insns (buf
, sizeof buf
);
1834 /* The "emit_goto" emit_ops method for s390 and s390x. */
1837 s390_emit_goto (int *offset_p
, int *size_p
)
1839 static const unsigned char buf
[] = {
1840 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
1842 add_insns (buf
, sizeof buf
);
1849 /* The "write_goto_address" emit_ops method for s390 and s390x. */
1852 s390_write_goto_address (CORE_ADDR from
, CORE_ADDR to
, int size
)
1854 long diff
= ((long) (to
- (from
- 2))) / 2;
1856 unsigned char buf
[sizeof sdiff
];
1858 /* We're only doing 4-byte sizes at the moment. */
1859 if (size
!= sizeof sdiff
|| sdiff
!= diff
)
1865 memcpy (buf
, &sdiff
, sizeof sdiff
);
1866 target_write_memory (from
, buf
, sizeof sdiff
);
1869 /* Preparation for emitting a literal pool of given size. Loads the address
1870 of the pool into %r1, and jumps over it. Called should emit the pool data
1871 immediately afterwards. Used for both s390 and s390x. */
1874 s390_emit_litpool (int size
)
1876 static const unsigned char nop
[] = {
1879 unsigned char buf
[] = {
1881 (unsigned char) ((size
+ 4) / 2), /* bras %r1, .Lend+size */
1886 /* buf needs to start at even halfword for litpool to be aligned */
1887 if (current_insn_ptr
& 2)
1888 add_insns (nop
, sizeof nop
);
1892 while ((current_insn_ptr
& 6) != 4)
1893 add_insns (nop
, sizeof nop
);
1895 add_insns (buf
, sizeof buf
);
1898 /* The "emit_const" emit_ops method for s390. */
1901 s390_emit_const (LONGEST num
)
1903 unsigned long long n
= num
;
1904 unsigned char buf_s
[] = {
1905 /* lhi %r3, <num> */
1907 (unsigned char) (num
>> 8), (unsigned char) num
,
1911 static const unsigned char buf_l
[] = {
1912 0x98, 0x23, 0x10, 0x00, /* lm %r2, %r3, 0(%r1) */
1914 if (num
< 0x8000 && num
>= 0)
1916 add_insns (buf_s
, sizeof buf_s
);
1920 s390_emit_litpool (8);
1921 add_insns ((unsigned char *) &n
, sizeof n
);
1922 add_insns (buf_l
, sizeof buf_l
);
1926 /* The "emit_call" emit_ops method for s390. */
1929 s390_emit_call (CORE_ADDR fn
)
1931 unsigned int n
= fn
;
1932 static const unsigned char buf
[] = {
1933 0x58, 0x10, 0x10, 0x00, /* l %r1, 0(%r1) */
1934 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
1935 0x0d, 0xe1, /* basr %r14, %r1 */
1936 0xa7, 0xfa, 0x00, 0x60, /* ahi %r15, 0x60 */
1938 s390_emit_litpool (4);
1939 add_insns ((unsigned char *) &n
, sizeof n
);
1940 add_insns (buf
, sizeof buf
);
1943 /* The "emit_reg" emit_ops method for s390. */
1946 s390_emit_reg (int reg
)
1948 unsigned char bufpre
[] = {
1951 /* lhi %r3, <reg> */
1952 0xa7, 0x38, (unsigned char) (reg
>> 8), (unsigned char) reg
,
1954 add_insns (bufpre
, sizeof bufpre
);
1955 s390_emit_call (get_raw_reg_func_addr ());
1958 /* The "emit_pop" emit_ops method for s390. */
1961 s390_emit_pop (void)
1963 static const unsigned char buf
[] = {
1964 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1965 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1967 add_insns (buf
, sizeof buf
);
1970 /* The "emit_stack_flush" emit_ops method for s390. */
1973 s390_emit_stack_flush (void)
1975 static const unsigned char buf
[] = {
1976 0xa7, 0xfa, 0xff, 0xf8, /* ahi %r15, -8 */
1977 0x90, 0x23, 0xf0, 0x00, /* stm %r2, %r3, 0(%r15) */
1979 add_insns (buf
, sizeof buf
);
1982 /* The "emit_zero_ext" emit_ops method for s390. */
1985 s390_emit_zero_ext (int arg
)
1987 unsigned char buf
[] = {
1988 0x8d, 0x20, 0x00, (unsigned char) (64 - arg
), /* sldl %r2, <64-arg> */
1989 0x8c, 0x20, 0x00, (unsigned char) (64 - arg
), /* srdl %r2, <64-arg> */
1991 add_insns (buf
, sizeof buf
);
1994 /* The "emit_swap" emit_ops method for s390. */
1997 s390_emit_swap (void)
1999 static const unsigned char buf
[] = {
2000 0x98, 0x45, 0xf0, 0x00, /* lm %r4, %r5, 0(%r15) */
2001 0x90, 0x23, 0xf0, 0x00, /* stm %r2, %r3, 0(%r15) */
2002 0x18, 0x24, /* lr %r2, %r4 */
2003 0x18, 0x35, /* lr %r3, %r5 */
2005 add_insns (buf
, sizeof buf
);
2008 /* The "emit_stack_adjust" emit_ops method for s390. */
2011 s390_emit_stack_adjust (int n
)
2013 unsigned char buf
[] = {
2016 (unsigned char ) (n
* 8 >> 8), (unsigned char) (n
* 8),
2018 add_insns (buf
, sizeof buf
);
2021 /* Sets %r2 to a 32-bit constant. */
2024 s390_emit_set_r2 (int arg1
)
2026 unsigned char buf_s
[] = {
2027 /* lhi %r2, <arg1> */
2028 0xa7, 0x28, (unsigned char) (arg1
>> 8), (unsigned char) arg1
,
2030 static const unsigned char buf_l
[] = {
2031 0x58, 0x20, 0x10, 0x00, /* l %r2, 0(%r1) */
2033 if (arg1
< 0x8000 && arg1
>= -0x8000)
2035 add_insns (buf_s
, sizeof buf_s
);
2039 s390_emit_litpool (4);
2040 add_insns ((unsigned char *) &arg1
, sizeof arg1
);
2041 add_insns (buf_l
, sizeof buf_l
);
2045 /* The "emit_int_call_1" emit_ops method for s390. */
2048 s390_emit_int_call_1 (CORE_ADDR fn
, int arg1
)
2050 /* FN's prototype is `LONGEST(*fn)(int)'. */
2051 s390_emit_set_r2 (arg1
);
2052 s390_emit_call (fn
);
2055 /* The "emit_void_call_2" emit_ops method for s390. */
2058 s390_emit_void_call_2 (CORE_ADDR fn
, int arg1
)
2060 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
2061 static const unsigned char buf
[] = {
2062 0x18, 0xc2, /* lr %r12, %r2 */
2063 0x18, 0xd3, /* lr %r13, %r3 */
2064 0x18, 0x43, /* lr %r4, %r3 */
2065 0x18, 0x32, /* lr %r3, %r2 */
2067 static const unsigned char buf2
[] = {
2068 0x18, 0x2c, /* lr %r2, %r12 */
2069 0x18, 0x3d, /* lr %r3, %r13 */
2071 add_insns (buf
, sizeof buf
);
2072 s390_emit_set_r2 (arg1
);
2073 s390_emit_call (fn
);
2074 add_insns (buf2
, sizeof buf2
);
2077 /* The "emit_eq_goto" emit_ops method for s390. */
2080 s390_emit_eq_goto (int *offset_p
, int *size_p
)
2082 static const unsigned char buf
[] = {
2083 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
2084 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
2085 0x16, 0x23, /* or %r2, %r3 */
2086 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2087 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2088 0xc0, 0x84, 0x00, 0x00, 0x00, 0x00, /* jge <fillme> */
2090 add_insns (buf
, sizeof buf
);
2097 /* The "emit_ne_goto" emit_ops method for s390. */
2100 s390_emit_ne_goto (int *offset_p
, int *size_p
)
2102 static const unsigned char buf
[] = {
2103 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
2104 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
2105 0x16, 0x23, /* or %r2, %r3 */
2106 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2107 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2108 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2110 add_insns (buf
, sizeof buf
);
2117 /* The "emit_lt_goto" emit_ops method for s390. */
2120 s390_emit_lt_goto (int *offset_p
, int *size_p
)
2122 static const unsigned char buf
[] = {
2123 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2124 0xa7, 0x24, 0x00, 0x0e, /* jh .Ltrue */
2125 0xa7, 0x44, 0x00, 0x06, /* jl .Lfalse */
2126 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2127 0xa7, 0x24, 0x00, 0x08, /* jh .Ltrue */
2129 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2130 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2131 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2133 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2134 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2135 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2138 add_insns (buf
, sizeof buf
);
2145 /* The "emit_le_goto" emit_ops method for s390. */
2148 s390_emit_le_goto (int *offset_p
, int *size_p
)
2150 static const unsigned char buf
[] = {
2151 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2152 0xa7, 0x24, 0x00, 0x0e, /* jh .Ltrue */
2153 0xa7, 0x44, 0x00, 0x06, /* jl .Lfalse */
2154 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2155 0xa7, 0xa4, 0x00, 0x08, /* jhe .Ltrue */
2157 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2158 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2159 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2161 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2162 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2163 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2166 add_insns (buf
, sizeof buf
);
2173 /* The "emit_gt_goto" emit_ops method for s390. */
2176 s390_emit_gt_goto (int *offset_p
, int *size_p
)
2178 static const unsigned char buf
[] = {
2179 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2180 0xa7, 0x44, 0x00, 0x0e, /* jl .Ltrue */
2181 0xa7, 0x24, 0x00, 0x06, /* jh .Lfalse */
2182 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2183 0xa7, 0x44, 0x00, 0x08, /* jl .Ltrue */
2185 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2186 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2187 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2189 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2190 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2191 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2194 add_insns (buf
, sizeof buf
);
2201 /* The "emit_ge_goto" emit_ops method for s390. */
2204 s390_emit_ge_goto (int *offset_p
, int *size_p
)
2206 static const unsigned char buf
[] = {
2207 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2208 0xa7, 0x44, 0x00, 0x0e, /* jl .Ltrue */
2209 0xa7, 0x24, 0x00, 0x06, /* jh .Lfalse */
2210 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2211 0xa7, 0xc4, 0x00, 0x08, /* jle .Ltrue */
2213 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2214 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2215 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2217 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2218 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2219 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2222 add_insns (buf
, sizeof buf
);
2229 /* The "emit_ops" structure for s390. Named _impl to avoid name
2230 collision with s390_emit_ops function. */
2232 static struct emit_ops s390_emit_ops_impl
=
2240 s390_emit_rsh_signed
,
2241 s390_emit_rsh_unsigned
,
2249 s390_emit_less_signed
,
2250 s390_emit_less_unsigned
,
2254 s390_write_goto_address
,
2259 s390_emit_stack_flush
,
2262 s390_emit_stack_adjust
,
2263 s390_emit_int_call_1
,
2264 s390_emit_void_call_2
,
2275 /* The "emit_prologue" emit_ops method for s390x. */
2278 s390x_emit_prologue (void)
2280 static const unsigned char buf
[] = {
2281 0xeb, 0x9f, 0xf0, 0x48, 0x00, 0x24, /* stmg %r9, %r15, 0x48(%r15) */
2282 0xb9, 0x04, 0x00, 0x92, /* lgr %r9, %r2 */
2283 0xb9, 0x04, 0x00, 0xa3, /* lgr %r10, %r3 */
2284 0xb9, 0x04, 0x00, 0xbf, /* lgr %r11, %r15 */
2286 add_insns (buf
, sizeof buf
);
2289 /* The "emit_epilogue" emit_ops method for s390x. */
2292 s390x_emit_epilogue (void)
2294 static const unsigned char buf
[] = {
2295 0xe3, 0x20, 0xa0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r10) */
2296 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2297 0xeb, 0x9f, 0xf0, 0x48, 0x00, 0x04, /* lmg %r9, %r15, 0x48(%r15) */
2298 0x07, 0xfe, /* br %r14 */
2300 add_insns (buf
, sizeof buf
);
2303 /* The "emit_add" emit_ops method for s390x. */
2306 s390x_emit_add (void)
2308 static const unsigned char buf
[] = {
2309 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x0a, /* alg %r2, 0(%r15) */
2310 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2312 add_insns (buf
, sizeof buf
);
2315 /* The "emit_sub" emit_ops method for s390x. */
2318 s390x_emit_sub (void)
2320 static const unsigned char buf
[] = {
2321 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2322 0xb9, 0x0b, 0x00, 0x32, /* slgr %r3, %r2 */
2323 0xb9, 0x04, 0x00, 0x23, /* lgr %r2, %r3 */
2324 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2326 add_insns (buf
, sizeof buf
);
2329 /* The "emit_mul" emit_ops method for s390x. */
2332 s390x_emit_mul (void)
2337 /* The "emit_lsh" emit_ops method for s390x. */
2340 s390x_emit_lsh (void)
2342 static const unsigned char buf
[] = {
2343 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2344 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0d, /* sllg %r2, %r3, 0(%r2) */
2345 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2347 add_insns (buf
, sizeof buf
);
2350 /* The "emit_rsh_signed" emit_ops method for s390x. */
2353 s390x_emit_rsh_signed (void)
2355 static const unsigned char buf
[] = {
2356 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2357 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0a, /* srag %r2, %r3, 0(%r2) */
2358 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2360 add_insns (buf
, sizeof buf
);
2363 /* The "emit_rsh_unsigned" emit_ops method for s390x. */
2366 s390x_emit_rsh_unsigned (void)
2368 static const unsigned char buf
[] = {
2369 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2370 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0c, /* srlg %r2, %r3, 0(%r2) */
2371 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2373 add_insns (buf
, sizeof buf
);
2376 /* The "emit_ext" emit_ops method for s390x. */
2379 s390x_emit_ext (int arg
)
2381 unsigned char buf
[] = {
2382 /* sllg %r2, %r2, <64-arg> */
2383 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0d,
2384 /* srag %r2, %r2, <64-arg> */
2385 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0a,
2387 add_insns (buf
, sizeof buf
);
2390 /* The "emit_log_not" emit_ops method for s390x. */
2393 s390x_emit_log_not (void)
2395 static const unsigned char buf
[] = {
2396 0xb9, 0x00, 0x00, 0x22, /* lpgr %r2, %r2 */
2397 0xa7, 0x2b, 0xff, 0xff, /* aghi %r2, -1 */
2398 0xeb, 0x22, 0x00, 0x3f, 0x00, 0x0c, /* srlg %r2, %r2, 63 */
2400 add_insns (buf
, sizeof buf
);
2403 /* The "emit_bit_and" emit_ops method for s390x. */
2406 s390x_emit_bit_and (void)
2408 static const unsigned char buf
[] = {
2409 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x80, /* ng %r2, 0(%r15) */
2410 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2412 add_insns (buf
, sizeof buf
);
2415 /* The "emit_bit_or" emit_ops method for s390x. */
2418 s390x_emit_bit_or (void)
2420 static const unsigned char buf
[] = {
2421 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x81, /* og %r2, 0(%r15) */
2422 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2424 add_insns (buf
, sizeof buf
);
2427 /* The "emit_bit_xor" emit_ops method for s390x. */
2430 s390x_emit_bit_xor (void)
2432 static const unsigned char buf
[] = {
2433 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x82, /* xg %r2, 0(%r15) */
2434 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2436 add_insns (buf
, sizeof buf
);
2439 /* The "emit_bit_not" emit_ops method for s390x. */
2442 s390x_emit_bit_not (void)
2444 static const unsigned char buf
[] = {
2445 0xa7, 0x39, 0xff, 0xff, /* lghi %r3, -1 */
2446 0xb9, 0x82, 0x00, 0x23, /* xgr %r2, %r3 */
2448 add_insns (buf
, sizeof buf
);
2451 /* The "emit_equal" emit_ops method for s390x. */
2454 s390x_emit_equal (void)
2456 s390x_emit_bit_xor ();
2457 s390x_emit_log_not ();
2460 /* The "emit_less_signed" emit_ops method for s390x. */
2463 s390x_emit_less_signed (void)
2465 static const unsigned char buf
[] = {
2466 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2467 0xa7, 0x29, 0x00, 0x01, /* lghi %r2, 1 */
2468 0xa7, 0x24, 0x00, 0x04, /* jh .Lend */
2469 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2471 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2473 add_insns (buf
, sizeof buf
);
2476 /* The "emit_less_unsigned" emit_ops method for s390x. */
2479 s390x_emit_less_unsigned (void)
2481 static const unsigned char buf
[] = {
2482 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x21, /* clg %r2, 0(%r15) */
2483 0xa7, 0x29, 0x00, 0x01, /* lghi %r2, 1 */
2484 0xa7, 0x24, 0x00, 0x04, /* jh .Lend */
2485 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2487 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2489 add_insns (buf
, sizeof buf
);
2492 /* The "emit_ref" emit_ops method for s390x. */
2495 s390x_emit_ref (int size
)
2497 static const unsigned char buf1
[] = {
2498 0xe3, 0x20, 0x20, 0x00, 0x00, 0x90, /* llgc %r2, 0(%r2) */
2500 static const unsigned char buf2
[] = {
2501 0xe3, 0x20, 0x20, 0x00, 0x00, 0x91 /* llgh %r2, 0(%r2) */
2503 static const unsigned char buf4
[] = {
2504 0xe3, 0x20, 0x20, 0x00, 0x00, 0x16, /* llgf %r2, 0(%r2) */
2506 static const unsigned char buf8
[] = {
2507 0xe3, 0x20, 0x20, 0x00, 0x00, 0x04, /* lg %r2, 0(%r2) */
2512 add_insns (buf1
, sizeof buf1
);
2515 add_insns (buf2
, sizeof buf2
);
2518 add_insns (buf4
, sizeof buf4
);
2521 add_insns (buf8
, sizeof buf8
);
2528 /* The "emit_if_goto" emit_ops method for s390x. */
2531 s390x_emit_if_goto (int *offset_p
, int *size_p
)
2533 static const unsigned char buf
[] = {
2534 0xb9, 0x02, 0x00, 0x22, /* ltgr %r2, %r2 */
2535 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x04, /* lg %r2, 0(%r15) */
2536 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2537 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2539 add_insns (buf
, sizeof buf
);
2546 /* The "emit_const" emit_ops method for s390x. */
2549 s390x_emit_const (LONGEST num
)
2551 unsigned long long n
= num
;
2552 unsigned char buf_s
[] = {
2553 /* lghi %r2, <num> */
2554 0xa7, 0x29, (unsigned char) (num
>> 8), (unsigned char) num
,
2556 static const unsigned char buf_l
[] = {
2557 0xe3, 0x20, 0x10, 0x00, 0x00, 0x04, /* lg %r2, 0(%r1) */
2559 if (num
< 0x8000 && num
>= -0x8000)
2561 add_insns (buf_s
, sizeof buf_s
);
2565 s390_emit_litpool (8);
2566 add_insns ((unsigned char *) &n
, sizeof n
);
2567 add_insns (buf_l
, sizeof buf_l
);
2571 /* The "emit_call" emit_ops method for s390x. */
2574 s390x_emit_call (CORE_ADDR fn
)
2576 unsigned long n
= fn
;
2577 static const unsigned char buf
[] = {
2578 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, /* lg %r1, 0(%r1) */
2579 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
2580 0x0d, 0xe1, /* basr %r14, %r1 */
2581 0xa7, 0xfb, 0x00, 0xa0, /* aghi %r15, 0xa0 */
2583 s390_emit_litpool (8);
2584 add_insns ((unsigned char *) &n
, sizeof n
);
2585 add_insns (buf
, sizeof buf
);
2588 /* The "emit_reg" emit_ops method for s390x. */
2591 s390x_emit_reg (int reg
)
2593 unsigned char buf
[] = {
2595 0xb9, 0x04, 0x00, 0x29,
2596 /* lghi %r3, <reg> */
2597 0xa7, 0x39, (unsigned char) (reg
>> 8), (unsigned char) reg
,
2599 add_insns (buf
, sizeof buf
);
2600 s390x_emit_call (get_raw_reg_func_addr ());
2603 /* The "emit_pop" emit_ops method for s390x. */
2606 s390x_emit_pop (void)
2608 static const unsigned char buf
[] = {
2609 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x04, /* lg %r2, 0(%r15) */
2610 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2612 add_insns (buf
, sizeof buf
);
2615 /* The "emit_stack_flush" emit_ops method for s390x. */
2618 s390x_emit_stack_flush (void)
2620 static const unsigned char buf
[] = {
2621 0xa7, 0xfb, 0xff, 0xf8, /* aghi %r15, -8 */
2622 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r15) */
2624 add_insns (buf
, sizeof buf
);
2627 /* The "emit_zero_ext" emit_ops method for s390x. */
2630 s390x_emit_zero_ext (int arg
)
2632 unsigned char buf
[] = {
2633 /* sllg %r2, %r2, <64-arg> */
2634 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0d,
2635 /* srlg %r2, %r2, <64-arg> */
2636 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0c,
2638 add_insns (buf
, sizeof buf
);
2641 /* The "emit_swap" emit_ops method for s390x. */
2644 s390x_emit_swap (void)
2646 static const unsigned char buf
[] = {
2647 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2648 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r15) */
2649 0xb9, 0x04, 0x00, 0x23, /* lgr %r2, %r3 */
2651 add_insns (buf
, sizeof buf
);
2654 /* The "emit_stack_adjust" emit_ops method for s390x. */
2657 s390x_emit_stack_adjust (int n
)
2659 unsigned char buf
[] = {
2660 /* aghi %r15, 8*n */
2662 (unsigned char) (n
* 8 >> 8), (unsigned char) (n
* 8),
2664 add_insns (buf
, sizeof buf
);
2667 /* The "emit_int_call_1" emit_ops method for s390x. */
2670 s390x_emit_int_call_1 (CORE_ADDR fn
, int arg1
)
2672 /* FN's prototype is `LONGEST(*fn)(int)'. */
2673 s390x_emit_const (arg1
);
2674 s390x_emit_call (fn
);
2677 /* The "emit_void_call_2" emit_ops method for s390x. */
2680 s390x_emit_void_call_2 (CORE_ADDR fn
, int arg1
)
2682 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
2683 static const unsigned char buf
[] = {
2684 0xb9, 0x04, 0x00, 0x32, /* lgr %r3, %r2 */
2685 0xb9, 0x04, 0x00, 0xc2, /* lgr %r12, %r2 */
2687 static const unsigned char buf2
[] = {
2688 0xb9, 0x04, 0x00, 0x2c, /* lgr %r2, %r12 */
2690 add_insns (buf
, sizeof buf
);
2691 s390x_emit_const (arg1
);
2692 s390x_emit_call (fn
);
2693 add_insns (buf2
, sizeof buf2
);
2696 /* The "emit_eq_goto" emit_ops method for s390x. */
2699 s390x_emit_eq_goto (int *offset_p
, int *size_p
)
2701 static const unsigned char buf
[] = {
2702 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2703 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2704 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2705 0xc0, 0x84, 0x00, 0x00, 0x00, 0x00, /* jge <fillme> */
2707 add_insns (buf
, sizeof buf
);
2714 /* The "emit_ne_goto" emit_ops method for s390x. */
2717 s390x_emit_ne_goto (int *offset_p
, int *size_p
)
2719 static const unsigned char buf
[] = {
2720 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2721 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2722 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2723 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2725 add_insns (buf
, sizeof buf
);
2732 /* The "emit_lt_goto" emit_ops method for s390x. */
2735 s390x_emit_lt_goto (int *offset_p
, int *size_p
)
2737 static const unsigned char buf
[] = {
2738 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2739 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2740 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2741 0xc0, 0x24, 0x00, 0x00, 0x00, 0x00, /* jgh <fillme> */
2743 add_insns (buf
, sizeof buf
);
2750 /* The "emit_le_goto" emit_ops method for s390x. */
2753 s390x_emit_le_goto (int *offset_p
, int *size_p
)
2755 static const unsigned char buf
[] = {
2756 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2757 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2758 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2759 0xc0, 0xa4, 0x00, 0x00, 0x00, 0x00, /* jghe <fillme> */
2761 add_insns (buf
, sizeof buf
);
2768 /* The "emit_gt_goto" emit_ops method for s390x. */
2771 s390x_emit_gt_goto (int *offset_p
, int *size_p
)
2773 static const unsigned char buf
[] = {
2774 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2775 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2776 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2777 0xc0, 0x44, 0x00, 0x00, 0x00, 0x00, /* jgl <fillme> */
2779 add_insns (buf
, sizeof buf
);
2786 /* The "emit_ge_goto" emit_ops method for s390x. */
2789 s390x_emit_ge_goto (int *offset_p
, int *size_p
)
2791 static const unsigned char buf
[] = {
2792 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2793 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2794 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2795 0xc0, 0xc4, 0x00, 0x00, 0x00, 0x00, /* jgle <fillme> */
2797 add_insns (buf
, sizeof buf
);
2804 /* The "emit_ops" structure for s390x. */
2806 static struct emit_ops s390x_emit_ops
=
2808 s390x_emit_prologue
,
2809 s390x_emit_epilogue
,
2814 s390x_emit_rsh_signed
,
2815 s390x_emit_rsh_unsigned
,
2823 s390x_emit_less_signed
,
2824 s390x_emit_less_unsigned
,
2828 s390_write_goto_address
,
2833 s390x_emit_stack_flush
,
2834 s390x_emit_zero_ext
,
2836 s390x_emit_stack_adjust
,
2837 s390x_emit_int_call_1
,
2838 s390x_emit_void_call_2
,
2848 /* The "emit_ops" linux_target_ops method. */
2850 static struct emit_ops
*
2851 s390_emit_ops (void)
2854 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
2856 if (register_size (regcache
->tdesc
, 0) == 8)
2857 return &s390x_emit_ops
;
2860 return &s390_emit_ops_impl
;
2863 struct linux_target_ops the_low_target
= {
2865 NULL
, /* supports_range_stepping */
2866 s390_supports_hardware_single_step
,
2867 NULL
, /* get_syscall_trapinfo */
2868 s390_get_ipa_tdesc_idx
,
2871 /* The linux target ops object. */
2873 linux_process_target
*the_linux_target
= &the_s390_target
;
2876 initialize_low_arch (void)
2878 /* Initialize the Linux target descriptions. */
2880 init_registers_s390_linux32 ();
2881 init_registers_s390_linux32v1 ();
2882 init_registers_s390_linux32v2 ();
2883 init_registers_s390_linux64 ();
2884 init_registers_s390_linux64v1 ();
2885 init_registers_s390_linux64v2 ();
2886 init_registers_s390_te_linux64 ();
2887 init_registers_s390_vx_linux64 ();
2888 init_registers_s390_tevx_linux64 ();
2889 init_registers_s390_gs_linux64 ();
2891 init_registers_s390x_linux64 ();
2892 init_registers_s390x_linux64v1 ();
2893 init_registers_s390x_linux64v2 ();
2894 init_registers_s390x_te_linux64 ();
2895 init_registers_s390x_vx_linux64 ();
2896 init_registers_s390x_tevx_linux64 ();
2897 init_registers_s390x_gs_linux64 ();
2900 initialize_regsets_info (&s390_regsets_info
);
2901 initialize_regsets_info (&s390_regsets_info_3264
);