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
;
80 bool low_breakpoint_at (CORE_ADDR pc
) override
;
83 /* The singleton target ops object. */
85 static s390_target the_s390_target
;
87 static int s390_regmap
[] = {
88 PT_PSWMASK
, PT_PSWADDR
,
90 PT_GPR0
, PT_GPR1
, PT_GPR2
, PT_GPR3
,
91 PT_GPR4
, PT_GPR5
, PT_GPR6
, PT_GPR7
,
92 PT_GPR8
, PT_GPR9
, PT_GPR10
, PT_GPR11
,
93 PT_GPR12
, PT_GPR13
, PT_GPR14
, PT_GPR15
,
95 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
96 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
97 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
98 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
103 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
104 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
105 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
106 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
108 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
109 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
110 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
111 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
117 #define s390_num_regs_3264 68
120 static int s390_regmap_3264
[] = {
121 PT_PSWMASK
, PT_PSWADDR
,
123 PT_GPR0
, PT_GPR0
, PT_GPR1
, PT_GPR1
,
124 PT_GPR2
, PT_GPR2
, PT_GPR3
, PT_GPR3
,
125 PT_GPR4
, PT_GPR4
, PT_GPR5
, PT_GPR5
,
126 PT_GPR6
, PT_GPR6
, PT_GPR7
, PT_GPR7
,
127 PT_GPR8
, PT_GPR8
, PT_GPR9
, PT_GPR9
,
128 PT_GPR10
, PT_GPR10
, PT_GPR11
, PT_GPR11
,
129 PT_GPR12
, PT_GPR12
, PT_GPR13
, PT_GPR13
,
130 PT_GPR14
, PT_GPR14
, PT_GPR15
, PT_GPR15
,
132 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
133 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
134 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
135 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
139 PT_FPR0
, PT_FPR1
, PT_FPR2
, PT_FPR3
,
140 PT_FPR4
, PT_FPR5
, PT_FPR6
, PT_FPR7
,
141 PT_FPR8
, PT_FPR9
, PT_FPR10
, PT_FPR11
,
142 PT_FPR12
, PT_FPR13
, PT_FPR14
, PT_FPR15
,
147 static int s390_regmap_3264
[] = {
148 PT_PSWMASK
, PT_PSWADDR
,
150 -1, PT_GPR0
, -1, PT_GPR1
,
151 -1, PT_GPR2
, -1, PT_GPR3
,
152 -1, PT_GPR4
, -1, PT_GPR5
,
153 -1, PT_GPR6
, -1, PT_GPR7
,
154 -1, PT_GPR8
, -1, PT_GPR9
,
155 -1, PT_GPR10
, -1, PT_GPR11
,
156 -1, PT_GPR12
, -1, PT_GPR13
,
157 -1, PT_GPR14
, -1, PT_GPR15
,
159 PT_ACR0
, PT_ACR1
, PT_ACR2
, PT_ACR3
,
160 PT_ACR4
, PT_ACR5
, PT_ACR6
, PT_ACR7
,
161 PT_ACR8
, PT_ACR9
, PT_ACR10
, PT_ACR11
,
162 PT_ACR12
, PT_ACR13
, PT_ACR14
, PT_ACR15
,
166 PT_FPR0_HI
, PT_FPR1_HI
, PT_FPR2_HI
, PT_FPR3_HI
,
167 PT_FPR4_HI
, PT_FPR5_HI
, PT_FPR6_HI
, PT_FPR7_HI
,
168 PT_FPR8_HI
, PT_FPR9_HI
, PT_FPR10_HI
, PT_FPR11_HI
,
169 PT_FPR12_HI
, PT_FPR13_HI
, PT_FPR14_HI
, PT_FPR15_HI
,
177 s390_target::low_cannot_fetch_register (int regno
)
183 s390_target::low_cannot_store_register (int regno
)
189 s390_collect_ptrace_register (struct regcache
*regcache
, int regno
, char *buf
)
191 int size
= register_size (regcache
->tdesc
, regno
);
192 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
193 struct usrregs_info
*usr
= regs_info
->usrregs
;
194 int regaddr
= usr
->regmap
[regno
];
196 if (size
< sizeof (long))
198 memset (buf
, 0, sizeof (long));
200 if ((regno
^ 1) < usr
->num_regs
201 && usr
->regmap
[regno
^ 1] == regaddr
)
203 collect_register (regcache
, regno
& ~1, buf
);
204 collect_register (regcache
, (regno
& ~1) + 1,
205 buf
+ sizeof (long) - size
);
207 else if (regaddr
== PT_PSWMASK
)
209 /* Convert 4-byte PSW mask to 8 bytes by clearing bit 12 and copying
210 the basic addressing mode bit from the PSW address. */
211 gdb_byte
*addr
= (gdb_byte
*) alloca (register_size (regcache
->tdesc
, regno
^ 1));
212 collect_register (regcache
, regno
, buf
);
213 collect_register (regcache
, regno
^ 1, addr
);
215 buf
[size
] |= (addr
[0] & 0x80);
217 else if (regaddr
== PT_PSWADDR
)
219 /* Convert 4-byte PSW address to 8 bytes by clearing the addressing
220 mode bit (which gets copied to the PSW mask instead). */
221 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
222 buf
[sizeof (long) - size
] &= ~0x80;
224 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
225 || regaddr
== PT_ORIGGPR2
)
226 collect_register (regcache
, regno
, buf
+ sizeof (long) - size
);
228 collect_register (regcache
, regno
, buf
);
230 else if (regaddr
!= -1)
231 collect_register (regcache
, regno
, buf
);
235 s390_supply_ptrace_register (struct regcache
*regcache
,
236 int regno
, const char *buf
)
238 int size
= register_size (regcache
->tdesc
, regno
);
239 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
240 struct usrregs_info
*usr
= regs_info
->usrregs
;
241 int regaddr
= usr
->regmap
[regno
];
243 if (size
< sizeof (long))
245 if ((regno
^ 1) < usr
->num_regs
246 && usr
->regmap
[regno
^ 1] == regaddr
)
248 supply_register (regcache
, regno
& ~1, buf
);
249 supply_register (regcache
, (regno
& ~1) + 1,
250 buf
+ sizeof (long) - size
);
252 else if (regaddr
== PT_PSWMASK
)
254 /* Convert 8-byte PSW mask to 4 bytes by setting bit 12 and copying
255 the basic addressing mode into the PSW address. */
256 gdb_byte
*mask
= (gdb_byte
*) alloca (size
);
257 gdb_byte
*addr
= (gdb_byte
*) alloca (register_size (regcache
->tdesc
, regno
^ 1));
258 memcpy (mask
, buf
, size
);
260 supply_register (regcache
, regno
, mask
);
262 collect_register (regcache
, regno
^ 1, addr
);
264 addr
[0] |= (buf
[size
] & 0x80);
265 supply_register (regcache
, regno
^ 1, addr
);
267 else if (regaddr
== PT_PSWADDR
)
269 /* Convert 8-byte PSW address to 4 bytes by truncating, but
270 keeping the addressing mode bit (which was set from the mask). */
271 gdb_byte
*addr
= (gdb_byte
*) alloca (size
);
273 collect_register (regcache
, regno
, addr
);
274 amode
= addr
[0] & 0x80;
275 memcpy (addr
, buf
+ sizeof (long) - size
, size
);
278 supply_register (regcache
, regno
, addr
);
280 else if ((regaddr
>= PT_GPR0
&& regaddr
<= PT_GPR15
)
281 || regaddr
== PT_ORIGGPR2
)
282 supply_register (regcache
, regno
, buf
+ sizeof (long) - size
);
284 supply_register (regcache
, regno
, buf
);
286 else if (regaddr
!= -1)
287 supply_register (regcache
, regno
, buf
);
290 /* Provide only a fill function for the general register set. ps_lgetregs
291 will use this for NPTL support. */
294 s390_fill_gregset (struct regcache
*regcache
, void *buf
)
297 const struct regs_info
*regs_info
= the_linux_target
->get_regs_info ();
298 struct usrregs_info
*usr
= regs_info
->usrregs
;
300 for (i
= 0; i
< usr
->num_regs
; i
++)
302 if (usr
->regmap
[i
] < PT_PSWMASK
303 || usr
->regmap
[i
] > PT_ACR15
)
306 s390_collect_ptrace_register (regcache
, i
,
307 (char *) buf
+ usr
->regmap
[i
]);
311 /* Fill and store functions for extended register sets. */
315 s390_fill_gprs_high (struct regcache
*regcache
, void *buf
)
317 int r0h
= find_regno (regcache
->tdesc
, "r0h");
320 for (i
= 0; i
< 16; i
++)
321 collect_register (regcache
, r0h
+ 2 * i
, (char *) buf
+ 4 * i
);
325 s390_store_gprs_high (struct regcache
*regcache
, const void *buf
)
327 int r0h
= find_regno (regcache
->tdesc
, "r0h");
330 for (i
= 0; i
< 16; i
++)
331 supply_register (regcache
, r0h
+ 2 * i
, (const char *) buf
+ 4 * i
);
336 s390_store_last_break (struct regcache
*regcache
, const void *buf
)
340 p
= (const char *) buf
+ 8 - register_size (regcache
->tdesc
, 0);
341 supply_register_by_name (regcache
, "last_break", p
);
345 s390_fill_system_call (struct regcache
*regcache
, void *buf
)
347 collect_register_by_name (regcache
, "system_call", buf
);
351 s390_store_system_call (struct regcache
*regcache
, const void *buf
)
353 supply_register_by_name (regcache
, "system_call", buf
);
357 s390_store_tdb (struct regcache
*regcache
, const void *buf
)
359 int tdb0
= find_regno (regcache
->tdesc
, "tdb0");
360 int tr0
= find_regno (regcache
->tdesc
, "tr0");
363 for (i
= 0; i
< 4; i
++)
364 supply_register (regcache
, tdb0
+ i
, (const char *) buf
+ 8 * i
);
366 for (i
= 0; i
< 16; i
++)
367 supply_register (regcache
, tr0
+ i
, (const char *) buf
+ 8 * (16 + i
));
371 s390_fill_vxrs_low (struct regcache
*regcache
, void *buf
)
373 int v0
= find_regno (regcache
->tdesc
, "v0l");
376 for (i
= 0; i
< 16; i
++)
377 collect_register (regcache
, v0
+ i
, (char *) buf
+ 8 * i
);
381 s390_store_vxrs_low (struct regcache
*regcache
, const void *buf
)
383 int v0
= find_regno (regcache
->tdesc
, "v0l");
386 for (i
= 0; i
< 16; i
++)
387 supply_register (regcache
, v0
+ i
, (const char *) buf
+ 8 * i
);
391 s390_fill_vxrs_high (struct regcache
*regcache
, void *buf
)
393 int v16
= find_regno (regcache
->tdesc
, "v16");
396 for (i
= 0; i
< 16; i
++)
397 collect_register (regcache
, v16
+ i
, (char *) buf
+ 16 * i
);
401 s390_store_vxrs_high (struct regcache
*regcache
, const void *buf
)
403 int v16
= find_regno (regcache
->tdesc
, "v16");
406 for (i
= 0; i
< 16; i
++)
407 supply_register (regcache
, v16
+ i
, (const char *) buf
+ 16 * i
);
411 s390_store_gs (struct regcache
*regcache
, const void *buf
)
413 int gsd
= find_regno (regcache
->tdesc
, "gsd");
416 for (i
= 0; i
< 3; i
++)
417 supply_register (regcache
, gsd
+ i
, (const char *) buf
+ 8 * (i
+ 1));
421 s390_store_gsbc (struct regcache
*regcache
, const void *buf
)
423 int bc_gsd
= find_regno (regcache
->tdesc
, "bc_gsd");
426 for (i
= 0; i
< 3; i
++)
427 supply_register (regcache
, bc_gsd
+ i
, (const char *) buf
+ 8 * (i
+ 1));
430 static struct regset_info s390_regsets
[] = {
431 { 0, 0, 0, 0, GENERAL_REGS
, s390_fill_gregset
, NULL
},
433 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_HIGH_GPRS
, 0,
434 EXTENDED_REGS
, s390_fill_gprs_high
, s390_store_gprs_high
},
436 /* Last break address is read-only; no fill function. */
437 { PTRACE_GETREGSET
, -1, NT_S390_LAST_BREAK
, 0, EXTENDED_REGS
,
438 NULL
, s390_store_last_break
},
439 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_SYSTEM_CALL
, 0,
440 EXTENDED_REGS
, s390_fill_system_call
, s390_store_system_call
},
441 /* TDB is read-only. */
442 { PTRACE_GETREGSET
, -1, NT_S390_TDB
, 0, EXTENDED_REGS
,
443 NULL
, s390_store_tdb
},
444 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_VXRS_LOW
, 0,
445 EXTENDED_REGS
, s390_fill_vxrs_low
, s390_store_vxrs_low
},
446 { PTRACE_GETREGSET
, PTRACE_SETREGSET
, NT_S390_VXRS_HIGH
, 0,
447 EXTENDED_REGS
, s390_fill_vxrs_high
, s390_store_vxrs_high
},
448 /* Guarded storage registers are read-only. */
449 { PTRACE_GETREGSET
, -1, NT_S390_GS_CB
, 0, EXTENDED_REGS
,
450 NULL
, s390_store_gs
},
451 { PTRACE_GETREGSET
, -1, NT_S390_GS_BC
, 0, EXTENDED_REGS
,
452 NULL
, s390_store_gsbc
},
457 static const gdb_byte s390_breakpoint
[] = { 0, 1 };
458 #define s390_breakpoint_len 2
460 /* Implementation of target ops method "sw_breakpoint_from_kind". */
463 s390_target::sw_breakpoint_from_kind (int kind
, int *size
)
465 *size
= s390_breakpoint_len
;
466 return s390_breakpoint
;
470 s390_target::low_supports_breakpoints ()
476 s390_target::low_get_pc (regcache
*regcache
)
478 if (register_size (regcache
->tdesc
, 0) == 4)
481 collect_register_by_name (regcache
, "pswa", &pswa
);
482 return pswa
& 0x7fffffff;
487 collect_register_by_name (regcache
, "pswa", &pc
);
493 s390_target::low_set_pc (regcache
*regcache
, CORE_ADDR newpc
)
495 if (register_size (regcache
->tdesc
, 0) == 4)
498 collect_register_by_name (regcache
, "pswa", &pswa
);
499 pswa
= (pswa
& 0x80000000) | (newpc
& 0x7fffffff);
500 supply_register_by_name (regcache
, "pswa", &pswa
);
504 unsigned long pc
= newpc
;
505 supply_register_by_name (regcache
, "pswa", &pc
);
510 s390_target::low_decr_pc_after_break ()
512 return s390_breakpoint_len
;
515 /* Determine the word size for the given PID, in bytes. */
519 s390_get_wordsize (int pid
)
522 PTRACE_XFER_TYPE pswm
= ptrace (PTRACE_PEEKUSER
, pid
,
523 (PTRACE_TYPE_ARG3
) 0,
524 (PTRACE_TYPE_ARG4
) 0);
527 warning (_("Couldn't determine word size, assuming 64-bit."));
530 /* Derive word size from extended addressing mode (PSW bit 31). */
531 return pswm
& (1L << 32) ? 8 : 4;
534 #define s390_get_wordsize(pid) 4
538 s390_check_regset (int pid
, int regset
, int regsize
)
540 void *buf
= alloca (regsize
);
544 iov
.iov_len
= regsize
;
546 if (ptrace (PTRACE_GETREGSET
, pid
, (long) regset
, (long) &iov
) >= 0
552 /* For a 31-bit inferior, whether the kernel supports using the full
554 static int have_hwcap_s390_high_gprs
= 0;
555 static int have_hwcap_s390_vx
= 0;
558 s390_target::low_arch_setup ()
560 const struct target_desc
*tdesc
;
561 struct regset_info
*regset
;
563 /* Determine word size and HWCAP. */
564 int pid
= pid_of (current_thread
);
565 int wordsize
= s390_get_wordsize (pid
);
566 unsigned long hwcap
= linux_get_hwcap (wordsize
);
568 /* Check whether the kernel supports extra register sets. */
569 int have_regset_last_break
570 = s390_check_regset (pid
, NT_S390_LAST_BREAK
, 8);
571 int have_regset_system_call
572 = s390_check_regset (pid
, NT_S390_SYSTEM_CALL
, 4);
574 = (s390_check_regset (pid
, NT_S390_TDB
, 256)
575 && (hwcap
& HWCAP_S390_TE
) != 0);
577 = (s390_check_regset (pid
, NT_S390_VXRS_LOW
, 128)
578 && s390_check_regset (pid
, NT_S390_VXRS_HIGH
, 256)
579 && (hwcap
& HWCAP_S390_VX
) != 0);
581 = (s390_check_regset (pid
, NT_S390_GS_CB
, 32)
582 && s390_check_regset (pid
, NT_S390_GS_BC
, 32)
583 && (hwcap
& HWCAP_S390_GS
) != 0);
590 tdesc
= tdesc_s390x_gs_linux64
;
591 else if (have_regset_vxrs
)
592 tdesc
= (have_regset_tdb
? tdesc_s390x_tevx_linux64
:
593 tdesc_s390x_vx_linux64
);
594 else if (have_regset_tdb
)
595 tdesc
= tdesc_s390x_te_linux64
;
596 else if (have_regset_system_call
)
597 tdesc
= tdesc_s390x_linux64v2
;
598 else if (have_regset_last_break
)
599 tdesc
= tdesc_s390x_linux64v1
;
601 tdesc
= tdesc_s390x_linux64
;
604 /* For a 31-bit inferior, check whether the kernel supports
605 using the full 64-bit GPRs. */
608 if (hwcap
& HWCAP_S390_HIGH_GPRS
)
610 have_hwcap_s390_high_gprs
= 1;
612 tdesc
= tdesc_s390_gs_linux64
;
613 else if (have_regset_vxrs
)
614 tdesc
= (have_regset_tdb
? tdesc_s390_tevx_linux64
:
615 tdesc_s390_vx_linux64
);
616 else if (have_regset_tdb
)
617 tdesc
= tdesc_s390_te_linux64
;
618 else if (have_regset_system_call
)
619 tdesc
= tdesc_s390_linux64v2
;
620 else if (have_regset_last_break
)
621 tdesc
= tdesc_s390_linux64v1
;
623 tdesc
= tdesc_s390_linux64
;
627 /* Assume 31-bit inferior process. */
628 if (have_regset_system_call
)
629 tdesc
= tdesc_s390_linux32v2
;
630 else if (have_regset_last_break
)
631 tdesc
= tdesc_s390_linux32v1
;
633 tdesc
= tdesc_s390_linux32
;
636 have_hwcap_s390_vx
= have_regset_vxrs
;
639 /* Update target_regsets according to available register sets. */
640 for (regset
= s390_regsets
; regset
->size
>= 0; regset
++)
641 if (regset
->get_request
== PTRACE_GETREGSET
)
642 switch (regset
->nt_type
)
645 case NT_S390_HIGH_GPRS
:
646 regset
->size
= have_hwcap_s390_high_gprs
? 64 : 0;
649 case NT_S390_LAST_BREAK
:
650 regset
->size
= have_regset_last_break
? 8 : 0;
652 case NT_S390_SYSTEM_CALL
:
653 regset
->size
= have_regset_system_call
? 4 : 0;
656 regset
->size
= have_regset_tdb
? 256 : 0;
658 case NT_S390_VXRS_LOW
:
659 regset
->size
= have_regset_vxrs
? 128 : 0;
661 case NT_S390_VXRS_HIGH
:
662 regset
->size
= have_regset_vxrs
? 256 : 0;
666 regset
->size
= have_regset_gs
? 32 : 0;
671 current_process ()->tdesc
= tdesc
;
676 s390_target::low_breakpoint_at (CORE_ADDR pc
)
678 unsigned char c
[s390_breakpoint_len
];
679 read_inferior_memory (pc
, c
, s390_breakpoint_len
);
680 return memcmp (c
, s390_breakpoint
, s390_breakpoint_len
) == 0;
683 /* Breakpoint/Watchpoint support. */
685 /* The "supports_z_point_type" linux_target_ops method. */
688 s390_supports_z_point_type (char z_type
)
699 /* Support for hardware single step. */
702 s390_supports_hardware_single_step (void)
707 static struct usrregs_info s390_usrregs_info
=
713 static struct regsets_info s390_regsets_info
=
715 s390_regsets
, /* regsets */
717 NULL
, /* disabled_regsets */
720 static struct regs_info myregs_info
=
722 NULL
, /* regset_bitmap */
727 static struct usrregs_info s390_usrregs_info_3264
=
733 static struct regsets_info s390_regsets_info_3264
=
735 s390_regsets
, /* regsets */
737 NULL
, /* disabled_regsets */
740 static struct regs_info regs_info_3264
=
742 NULL
, /* regset_bitmap */
743 &s390_usrregs_info_3264
,
744 &s390_regsets_info_3264
748 s390_target::get_regs_info ()
750 if (have_hwcap_s390_high_gprs
)
753 const struct target_desc
*tdesc
= current_process ()->tdesc
;
755 if (register_size (tdesc
, 0) == 4)
756 return ®s_info_3264
;
758 return ®s_info_3264
;
764 /* The "supports_tracepoints" linux_target_ops method. */
767 s390_supports_tracepoints (void)
772 /* Implementation of linux_target_ops method "get_thread_area". */
775 s390_get_thread_area (int lwpid
, CORE_ADDR
*addrp
)
777 CORE_ADDR res
= ptrace (PTRACE_PEEKUSER
, lwpid
, (long) PT_ACR0
, (long) 0);
779 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
781 if (register_size (regcache
->tdesc
, 0) == 4)
782 res
&= 0xffffffffull
;
789 /* Fast tracepoint support.
791 The register save area on stack is identical for all targets:
793 0x000+i*0x10: VR0-VR31
800 If we're on 31-bit linux, we just don't store the high parts of the GPRs.
801 Likewise, if there's no VX support, we just store the FRs into the slots
802 of low VR halves. The agent code is responsible for rearranging that
805 /* Code sequence saving GPRs for 31-bit target with no high GPRs. There's
806 one trick used at the very beginning: since there's no way to allocate
807 stack space without destroying CC (lay instruction can do it, but it's
808 only supported on later CPUs), we take 4 different execution paths for
809 every possible value of CC, allocate stack space, save %r0, stuff the
810 CC value in %r0 (shifted to match its position in PSWM high word),
811 then branch to common path. */
813 static const unsigned char s390_ft_entry_gpr_esa
[] = {
814 0xa7, 0x14, 0x00, 0x1e, /* jo .Lcc3 */
815 0xa7, 0x24, 0x00, 0x14, /* jh .Lcc2 */
816 0xa7, 0x44, 0x00, 0x0a, /* jl .Lcc1 */
818 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
819 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
820 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
821 0xa7, 0xf4, 0x00, 0x18, /* j .Lccdone */
823 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
824 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
825 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
826 0xa7, 0xf4, 0x00, 0x10, /* j .Lccdone */
828 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
829 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
830 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
831 0xa7, 0xf4, 0x00, 0x08, /* j .Lccdone */
833 0xa7, 0xfa, 0xfd, 0x00, /* ahi %r15, -0x300 */
834 0x50, 0x00, 0xf2, 0x04, /* st %r0, 0x204(%r15) */
835 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
837 0x50, 0x10, 0xf2, 0x0c, /* st %r1, 0x20c(%r15) */
838 0x50, 0x20, 0xf2, 0x14, /* st %r2, 0x214(%r15) */
839 0x50, 0x30, 0xf2, 0x1c, /* st %r3, 0x21c(%r15) */
840 0x50, 0x40, 0xf2, 0x24, /* st %r4, 0x224(%r15) */
841 0x50, 0x50, 0xf2, 0x2c, /* st %r5, 0x22c(%r15) */
842 0x50, 0x60, 0xf2, 0x34, /* st %r6, 0x234(%r15) */
843 0x50, 0x70, 0xf2, 0x3c, /* st %r7, 0x23c(%r15) */
844 0x50, 0x80, 0xf2, 0x44, /* st %r8, 0x244(%r15) */
845 0x50, 0x90, 0xf2, 0x4c, /* st %r9, 0x24c(%r15) */
846 0x50, 0xa0, 0xf2, 0x54, /* st %r10, 0x254(%r15) */
847 0x50, 0xb0, 0xf2, 0x5c, /* st %r11, 0x25c(%r15) */
848 0x50, 0xc0, 0xf2, 0x64, /* st %r12, 0x264(%r15) */
849 0x50, 0xd0, 0xf2, 0x6c, /* st %r13, 0x26c(%r15) */
850 0x50, 0xe0, 0xf2, 0x74, /* st %r14, 0x274(%r15) */
851 /* Compute original value of %r15 and store it. We use ahi instead
852 of la to preserve the whole value, and not just the low 31 bits.
853 This is not particularly important here, but essential in the
854 zarch case where someone might be using the high word of %r15
855 as an extra register. */
856 0x18, 0x1f, /* lr %r1, %r15 */
857 0xa7, 0x1a, 0x03, 0x00, /* ahi %r1, 0x300 */
858 0x50, 0x10, 0xf2, 0x7c, /* st %r1, 0x27c(%r15) */
861 /* Code sequence saving GPRs for 31-bit target with high GPRs and for 64-bit
862 target. Same as above, except this time we can use load/store multiple,
863 since the 64-bit regs are tightly packed. */
865 static const unsigned char s390_ft_entry_gpr_zarch
[] = {
866 0xa7, 0x14, 0x00, 0x21, /* jo .Lcc3 */
867 0xa7, 0x24, 0x00, 0x16, /* jh .Lcc2 */
868 0xa7, 0x44, 0x00, 0x0b, /* jl .Lcc1 */
870 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
871 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
872 0xa7, 0x08, 0x00, 0x00, /* lhi %r0, 0 */
873 0xa7, 0xf4, 0x00, 0x1b, /* j .Lccdone */
875 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
876 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
877 0xa7, 0x08, 0x10, 0x00, /* lhi %r0, 0x1000 */
878 0xa7, 0xf4, 0x00, 0x12, /* j .Lccdone */
880 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
881 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
882 0xa7, 0x08, 0x20, 0x00, /* lhi %r0, 0x2000 */
883 0xa7, 0xf4, 0x00, 0x09, /* j .Lccdone */
885 0xa7, 0xfb, 0xfd, 0x00, /* aghi %r15, -0x300 */
886 0xeb, 0x0e, 0xf2, 0x00, 0x00, 0x24, /* stmg %r0, %r14, 0x200(%r15) */
887 0xa7, 0x08, 0x30, 0x00, /* lhi %r0, 0x3000 */
889 0xb9, 0x04, 0x00, 0x1f, /* lgr %r1, %r15 */
890 0xa7, 0x1b, 0x03, 0x00, /* aghi %r1, 0x300 */
891 0xe3, 0x10, 0xf2, 0x78, 0x00, 0x24, /* stg %r1, 0x278(%r15) */
894 /* Code sequence saving ARs, PSWM and FPC. PSWM has to be assembled from
895 current PSWM (read by epsw) and CC from entry (in %r0). */
897 static const unsigned char s390_ft_entry_misc
[] = {
898 0x9b, 0x0f, 0xf2, 0x80, /* stam %a0, %a15, 0x20(%%r15) */
899 0xb9, 0x8d, 0x00, 0x23, /* epsw %r2, %r3 */
900 0xa7, 0x18, 0xcf, 0xff, /* lhi %r1, ~0x3000 */
901 0x14, 0x21, /* nr %r2, %r1 */
902 0x16, 0x20, /* or %r2, %r0 */
903 0x50, 0x20, 0xf2, 0xc0, /* st %r2, 0x2c0(%r15) */
904 0x50, 0x30, 0xf2, 0xc4, /* st %r3, 0x2c4(%r15) */
905 0xb2, 0x9c, 0xf2, 0xd0, /* stfpc 0x2d0(%r15) */
908 /* Code sequence saving FRs, used if VX not supported. */
910 static const unsigned char s390_ft_entry_fr
[] = {
911 0x60, 0x00, 0xf0, 0x00, /* std %f0, 0x000(%r15) */
912 0x60, 0x10, 0xf0, 0x10, /* std %f1, 0x010(%r15) */
913 0x60, 0x20, 0xf0, 0x20, /* std %f2, 0x020(%r15) */
914 0x60, 0x30, 0xf0, 0x30, /* std %f3, 0x030(%r15) */
915 0x60, 0x40, 0xf0, 0x40, /* std %f4, 0x040(%r15) */
916 0x60, 0x50, 0xf0, 0x50, /* std %f5, 0x050(%r15) */
917 0x60, 0x60, 0xf0, 0x60, /* std %f6, 0x060(%r15) */
918 0x60, 0x70, 0xf0, 0x70, /* std %f7, 0x070(%r15) */
919 0x60, 0x80, 0xf0, 0x80, /* std %f8, 0x080(%r15) */
920 0x60, 0x90, 0xf0, 0x90, /* std %f9, 0x090(%r15) */
921 0x60, 0xa0, 0xf0, 0xa0, /* std %f10, 0x0a0(%r15) */
922 0x60, 0xb0, 0xf0, 0xb0, /* std %f11, 0x0b0(%r15) */
923 0x60, 0xc0, 0xf0, 0xc0, /* std %f12, 0x0c0(%r15) */
924 0x60, 0xd0, 0xf0, 0xd0, /* std %f13, 0x0d0(%r15) */
925 0x60, 0xe0, 0xf0, 0xe0, /* std %f14, 0x0e0(%r15) */
926 0x60, 0xf0, 0xf0, 0xf0, /* std %f15, 0x0f0(%r15) */
929 /* Code sequence saving VRs, used if VX not supported. */
931 static const unsigned char s390_ft_entry_vr
[] = {
932 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x3e, /* vstm %v0, %v15, 0x000(%r15) */
933 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x3e, /* vstm %v16, %v31, 0x100(%r15) */
936 /* Code sequence doing the collection call for 31-bit target. %r1 contains
937 the address of the literal pool. */
939 static const unsigned char s390_ft_main_31
[] = {
940 /* Load the literals into registers. */
941 0x58, 0x50, 0x10, 0x00, /* l %r5, 0x0(%r1) */
942 0x58, 0x20, 0x10, 0x04, /* l %r2, 0x4(%r1) */
943 0x58, 0x40, 0x10, 0x08, /* l %r4, 0x8(%r1) */
944 0x58, 0x60, 0x10, 0x0c, /* l %r6, 0xc(%r1) */
945 /* Save original PSWA (tracepoint address | 0x80000000). */
946 0x50, 0x50, 0xf2, 0xcc, /* st %r5, 0x2cc(%r15) */
947 /* Construct a collecting_t object at %r15+0x2e0. */
948 0x50, 0x20, 0xf2, 0xe0, /* st %r2, 0x2e0(%r15) */
949 0x9b, 0x00, 0xf2, 0xe4, /* stam %a0, %a0, 0x2e4(%r15) */
950 /* Move its address to %r0. */
951 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
954 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
955 0xba, 0x10, 0x60, 0x00, /* cs %r1, %r0, 0(%r6) */
956 0xa7, 0x74, 0xff, 0xfc, /* jne .Lloop */
957 /* Address of the register save block to %r3. */
958 0x18, 0x3f, /* lr %r3, %r15 */
959 /* Make a stack frame, so that we can call the collector. */
960 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
962 0x0d, 0xe4, /* basr %r14, %r4 */
963 /* And get rid of the stack frame again. */
964 0x41, 0xf0, 0xf0, 0x60, /* la %r15, 0x60(%r15) */
965 /* Leave the lock. */
966 0x07, 0xf0, /* br %r0 */
967 0xa7, 0x18, 0x00, 0x00, /* lhi %r1, 0 */
968 0x50, 0x10, 0x60, 0x00, /* st %t1, 0(%r6) */
971 /* Code sequence doing the collection call for 64-bit target. %r1 contains
972 the address of the literal pool. */
974 static const unsigned char s390_ft_main_64
[] = {
975 /* Load the literals into registers. */
976 0xe3, 0x50, 0x10, 0x00, 0x00, 0x04, /* lg %r5, 0x00(%r1) */
977 0xe3, 0x20, 0x10, 0x08, 0x00, 0x04, /* lg %r2, 0x08(%r1) */
978 0xe3, 0x40, 0x10, 0x10, 0x00, 0x04, /* lg %r4, 0x10(%r1) */
979 0xe3, 0x60, 0x10, 0x18, 0x00, 0x04, /* lg %r6, 0x18(%r1) */
980 /* Save original PSWA (tracepoint address). */
981 0xe3, 0x50, 0xf2, 0xc8, 0x00, 0x24, /* stg %r5, 0x2c8(%r15) */
982 /* Construct a collecting_t object at %r15+0x2e0. */
983 0xe3, 0x20, 0xf2, 0xe0, 0x00, 0x24, /* stg %r2, 0x2e0(%r15) */
984 0x9b, 0x01, 0xf2, 0xe8, /* stam %a0, %a1, 0x2e8(%r15) */
985 /* Move its address to %r0. */
986 0x41, 0x00, 0xf2, 0xe0, /* la %r0, 0x2e0(%r15) */
989 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
990 0xeb, 0x10, 0x60, 0x00, 0x00, 0x30, /* csg %r1, %r0, 0(%r6) */
991 0xa7, 0x74, 0xff, 0xfb, /* jne .Lloop */
992 /* Address of the register save block to %r3. */
993 0xb9, 0x04, 0x00, 0x3f, /* lgr %r3, %r15 */
994 /* Make a stack frame, so that we can call the collector. */
995 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
997 0x0d, 0xe4, /* basr %r14, %r4 */
998 /* And get rid of the stack frame again. */
999 0x41, 0xf0, 0xf0, 0xa0, /* la %r15, 0xa0(%r15) */
1000 /* Leave the lock. */
1001 0x07, 0xf0, /* br %r0 */
1002 0xa7, 0x19, 0x00, 0x00, /* lghi %r1, 0 */
1003 0xe3, 0x10, 0x60, 0x00, 0x00, 0x24, /* stg %t1, 0(%r6) */
1006 /* Code sequence restoring FRs, for targets with no VX support. */
1008 static const unsigned char s390_ft_exit_fr
[] = {
1009 0x68, 0x00, 0xf0, 0x00, /* ld %f0, 0x000(%r15) */
1010 0x68, 0x10, 0xf0, 0x10, /* ld %f1, 0x010(%r15) */
1011 0x68, 0x20, 0xf0, 0x20, /* ld %f2, 0x020(%r15) */
1012 0x68, 0x30, 0xf0, 0x30, /* ld %f3, 0x030(%r15) */
1013 0x68, 0x40, 0xf0, 0x40, /* ld %f4, 0x040(%r15) */
1014 0x68, 0x50, 0xf0, 0x50, /* ld %f5, 0x050(%r15) */
1015 0x68, 0x60, 0xf0, 0x60, /* ld %f6, 0x060(%r15) */
1016 0x68, 0x70, 0xf0, 0x70, /* ld %f7, 0x070(%r15) */
1017 0x68, 0x80, 0xf0, 0x80, /* ld %f8, 0x080(%r15) */
1018 0x68, 0x90, 0xf0, 0x90, /* ld %f9, 0x090(%r15) */
1019 0x68, 0xa0, 0xf0, 0xa0, /* ld %f10, 0x0a0(%r15) */
1020 0x68, 0xb0, 0xf0, 0xb0, /* ld %f11, 0x0b0(%r15) */
1021 0x68, 0xc0, 0xf0, 0xc0, /* ld %f12, 0x0c0(%r15) */
1022 0x68, 0xd0, 0xf0, 0xd0, /* ld %f13, 0x0d0(%r15) */
1023 0x68, 0xe0, 0xf0, 0xe0, /* ld %f14, 0x0e0(%r15) */
1024 0x68, 0xf0, 0xf0, 0xf0, /* ld %f15, 0x0f0(%r15) */
1027 /* Code sequence restoring VRs. */
1029 static const unsigned char s390_ft_exit_vr
[] = {
1030 0xe7, 0x0f, 0xf0, 0x00, 0x00, 0x36, /* vlm %v0, %v15, 0x000(%r15) */
1031 0xe7, 0x0f, 0xf1, 0x00, 0x0c, 0x36, /* vlm %v16, %v31, 0x100(%r15) */
1034 /* Code sequence restoring misc registers. As for PSWM, only CC should be
1035 modified by C code, so we use the alr instruction to restore it by
1036 manufacturing an operand that'll result in the original flags. */
1038 static const unsigned char s390_ft_exit_misc
[] = {
1039 0xb2, 0x9d, 0xf2, 0xd0, /* lfpc 0x2d0(%r15) */
1040 0x58, 0x00, 0xf2, 0xc0, /* l %r0, 0x2c0(%r15) */
1041 /* Extract CC to high 2 bits of %r0. */
1042 0x88, 0x00, 0x00, 0x0c, /* srl %r0, 12 */
1043 0x89, 0x00, 0x00, 0x1e, /* sll %r0, 30 */
1044 /* Add %r0 to itself. Result will be nonzero iff CC bit 0 is set, and
1045 will have carry iff CC bit 1 is set - resulting in the same flags
1047 0x1e, 0x00, /* alr %r0, %r0 */
1048 0x9a, 0x0f, 0xf2, 0x80, /* lam %a0, %a15, 0x280(%r15) */
1051 /* Code sequence restoring GPRs, for 31-bit targets with no high GPRs. */
1053 static const unsigned char s390_ft_exit_gpr_esa
[] = {
1054 0x58, 0x00, 0xf2, 0x04, /* l %r0, 0x204(%r15) */
1055 0x58, 0x10, 0xf2, 0x0c, /* l %r1, 0x20c(%r15) */
1056 0x58, 0x20, 0xf2, 0x14, /* l %r2, 0x214(%r15) */
1057 0x58, 0x30, 0xf2, 0x1c, /* l %r3, 0x21c(%r15) */
1058 0x58, 0x40, 0xf2, 0x24, /* l %r4, 0x224(%r15) */
1059 0x58, 0x50, 0xf2, 0x2c, /* l %r5, 0x22c(%r15) */
1060 0x58, 0x60, 0xf2, 0x34, /* l %r6, 0x234(%r15) */
1061 0x58, 0x70, 0xf2, 0x3c, /* l %r7, 0x23c(%r15) */
1062 0x58, 0x80, 0xf2, 0x44, /* l %r8, 0x244(%r15) */
1063 0x58, 0x90, 0xf2, 0x4c, /* l %r9, 0x24c(%r15) */
1064 0x58, 0xa0, 0xf2, 0x54, /* l %r10, 0x254(%r15) */
1065 0x58, 0xb0, 0xf2, 0x5c, /* l %r11, 0x25c(%r15) */
1066 0x58, 0xc0, 0xf2, 0x64, /* l %r12, 0x264(%r15) */
1067 0x58, 0xd0, 0xf2, 0x6c, /* l %r13, 0x26c(%r15) */
1068 0x58, 0xe0, 0xf2, 0x74, /* l %r14, 0x274(%r15) */
1069 0x58, 0xf0, 0xf2, 0x7c, /* l %r15, 0x27c(%r15) */
1072 /* Code sequence restoring GPRs, for 64-bit targets and 31-bit targets
1075 static const unsigned char s390_ft_exit_gpr_zarch
[] = {
1076 0xeb, 0x0f, 0xf2, 0x00, 0x00, 0x04, /* lmg %r0, %r15, 0x200(%r15) */
1079 /* Writes instructions to target, updating the to pointer. */
1082 append_insns (CORE_ADDR
*to
, size_t len
, const unsigned char *buf
)
1084 target_write_memory (*to
, buf
, len
);
1088 /* Relocates an instruction from oldloc to *to, updating to. */
1091 s390_relocate_instruction (CORE_ADDR
*to
, CORE_ADDR oldloc
, int is_64
)
1096 /* 0: no fixup, 1: PC16DBL fixup, 2: PC32DBL fixup. */
1099 read_inferior_memory (oldloc
, buf
, sizeof buf
);
1102 else if (buf
[0] < 0xc0)
1108 case 0x05: /* BALR */
1109 case 0x0c: /* BASSM */
1110 case 0x0d: /* BASR */
1111 case 0x45: /* BAL */
1112 case 0x4d: /* BAS */
1113 /* These save a return address and mess around with registers.
1114 We can't relocate them. */
1116 case 0x84: /* BRXH */
1117 case 0x85: /* BRXLE */
1122 /* BRC, BRAS, BRCT, BRCTG */
1123 if (op2
>= 4 && op2
<= 7)
1131 /* LARL, BRCL, BRASL */
1132 if (op2
== 0 || op2
== 4 || op2
== 5)
1140 /* PC-relative addressing instructions. */
1143 case 0xc5: /* BPRP */
1144 case 0xc7: /* BPP */
1145 /* Branch prediction - just skip it. */
1157 case 0x44: /* BRXHG */
1158 case 0x45: /* BRXLG */
1159 case 0x64: /* CGRJ */
1160 case 0x65: /* CLGRJ */
1161 case 0x76: /* CRJ */
1162 case 0x77: /* CLRJ */
1171 /* We'll have to relocate an instruction with a PC-relative field.
1172 First, compute the target. */
1173 int64_t loffset
= 0;
1177 int16_t soffset
= 0;
1178 memcpy (&soffset
, buf
+ 2, 2);
1183 int32_t soffset
= 0;
1184 memcpy (&soffset
, buf
+ 2, 4);
1187 target
= oldloc
+ loffset
* 2;
1189 target
&= 0x7fffffff;
1193 /* BRAS or BRASL was used. We cannot just relocate those, since
1194 they save the return address in a register. We can, however,
1195 replace them with a LARL+JG sequence. */
1197 /* Make the LARL. */
1201 loffset
= oldloc
+ ilen
- *to
;
1204 if (soffset
!= loffset
&& is_64
)
1206 memcpy (buf
+ 2, &soffset
, 4);
1207 append_insns (to
, 6, buf
);
1209 /* Note: this is not fully correct. In 31-bit mode, LARL will write
1210 an address with the top bit 0, while BRAS/BRASL will write it
1211 with top bit 1. It should not matter much, since linux compilers
1212 use BR and not BSM to return from functions, but it could confuse
1213 some poor stack unwinder. */
1215 /* We'll now be writing a JG. */
1222 /* Compute the new offset and write it to the buffer. */
1223 loffset
= target
- *to
;
1228 int16_t soffset
= loffset
;
1229 if (soffset
!= loffset
)
1231 memcpy (buf
+ 2, &soffset
, 2);
1235 int32_t soffset
= loffset
;
1236 if (soffset
!= loffset
&& is_64
)
1238 memcpy (buf
+ 2, &soffset
, 4);
1241 append_insns (to
, ilen
, buf
);
1245 /* Implementation of linux_target_ops method
1246 "install_fast_tracepoint_jump_pad". */
1249 s390_install_fast_tracepoint_jump_pad (CORE_ADDR tpoint
,
1251 CORE_ADDR collector
,
1254 CORE_ADDR
*jump_entry
,
1255 CORE_ADDR
*trampoline
,
1256 ULONGEST
*trampoline_size
,
1257 unsigned char *jjump_pad_insn
,
1258 ULONGEST
*jjump_pad_insn_size
,
1259 CORE_ADDR
*adjusted_insn_addr
,
1260 CORE_ADDR
*adjusted_insn_addr_end
,
1266 unsigned char jbuf
[6] = { 0xc0, 0xf4, 0, 0, 0, 0 }; /* jg ... */
1267 CORE_ADDR buildaddr
= *jump_entry
;
1269 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1270 int is_64
= register_size (regcache
->tdesc
, 0) == 8;
1271 int is_zarch
= is_64
|| have_hwcap_s390_high_gprs
;
1272 int has_vx
= have_hwcap_s390_vx
;
1274 int is_64
= 0, is_zarch
= 0, has_vx
= 0;
1276 CORE_ADDR literals
[4] = {
1283 /* First, store the GPRs. */
1285 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_zarch
,
1286 s390_ft_entry_gpr_zarch
);
1288 append_insns (&buildaddr
, sizeof s390_ft_entry_gpr_esa
,
1289 s390_ft_entry_gpr_esa
);
1291 /* Second, misc registers (ARs, PSWM, FPC). PSWA will be stored below. */
1292 append_insns (&buildaddr
, sizeof s390_ft_entry_misc
, s390_ft_entry_misc
);
1294 /* Third, FRs or VRs. */
1296 append_insns (&buildaddr
, sizeof s390_ft_entry_vr
, s390_ft_entry_vr
);
1298 append_insns (&buildaddr
, sizeof s390_ft_entry_fr
, s390_ft_entry_fr
);
1300 /* Now, the main part of code - store PSWA, take lock, call collector,
1301 leave lock. First, we'll need to fetch 4 literals. */
1303 unsigned char buf
[] = {
1304 0x07, 0x07, /* nopr %r7 */
1305 0x07, 0x07, /* nopr %r7 */
1306 0x07, 0x07, /* nopr %r7 */
1307 0xa7, 0x15, 0x00, 0x12, /* bras %r1, .Lend */
1308 0, 0, 0, 0, 0, 0, 0, 0, /* tpaddr */
1309 0, 0, 0, 0, 0, 0, 0, 0, /* tpoint */
1310 0, 0, 0, 0, 0, 0, 0, 0, /* collector */
1311 0, 0, 0, 0, 0, 0, 0, 0, /* lockaddr */
1314 /* Find the proper start place in buf, so that literals will be
1316 int bufpos
= (buildaddr
+ 2) & 7;
1317 /* Stuff the literals into the buffer. */
1318 for (i
= 0; i
< 4; i
++) {
1319 uint64_t lit
= literals
[i
];
1320 memcpy (&buf
[sizeof buf
- 32 + i
* 8], &lit
, 8);
1322 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1323 append_insns (&buildaddr
, sizeof s390_ft_main_64
, s390_ft_main_64
);
1325 unsigned char buf
[] = {
1326 0x07, 0x07, /* nopr %r7 */
1327 0xa7, 0x15, 0x00, 0x0a, /* bras %r1, .Lend */
1328 0, 0, 0, 0, /* tpaddr */
1329 0, 0, 0, 0, /* tpoint */
1330 0, 0, 0, 0, /* collector */
1331 0, 0, 0, 0, /* lockaddr */
1334 /* Find the proper start place in buf, so that literals will be
1336 int bufpos
= (buildaddr
+ 2) & 3;
1337 /* First literal will be saved as the PSWA, make sure it has the high bit
1339 literals
[0] |= 0x80000000;
1340 /* Stuff the literals into the buffer. */
1341 for (i
= 0; i
< 4; i
++) {
1342 uint32_t lit
= literals
[i
];
1343 memcpy (&buf
[sizeof buf
- 16 + i
* 4], &lit
, 4);
1345 append_insns (&buildaddr
, sizeof buf
- bufpos
, buf
+ bufpos
);
1346 append_insns (&buildaddr
, sizeof s390_ft_main_31
, s390_ft_main_31
);
1349 /* Restore FRs or VRs. */
1351 append_insns (&buildaddr
, sizeof s390_ft_exit_vr
, s390_ft_exit_vr
);
1353 append_insns (&buildaddr
, sizeof s390_ft_exit_fr
, s390_ft_exit_fr
);
1355 /* Restore misc registers. */
1356 append_insns (&buildaddr
, sizeof s390_ft_exit_misc
, s390_ft_exit_misc
);
1358 /* Restore the GPRs. */
1360 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_zarch
,
1361 s390_ft_exit_gpr_zarch
);
1363 append_insns (&buildaddr
, sizeof s390_ft_exit_gpr_esa
,
1364 s390_ft_exit_gpr_esa
);
1366 /* Now, adjust the original instruction to execute in the jump
1368 *adjusted_insn_addr
= buildaddr
;
1369 if (s390_relocate_instruction (&buildaddr
, tpaddr
, is_64
))
1371 sprintf (err
, "E.Could not relocate instruction for tracepoint.");
1374 *adjusted_insn_addr_end
= buildaddr
;
1376 /* Finally, write a jump back to the program. */
1378 loffset
= (tpaddr
+ orig_size
) - buildaddr
;
1381 if (is_64
&& offset
!= loffset
)
1384 "E.Jump back from jump pad too far from tracepoint "
1385 "(offset 0x%" PRIx64
" > int33).", loffset
);
1388 memcpy (jbuf
+ 2, &offset
, 4);
1389 append_insns (&buildaddr
, sizeof jbuf
, jbuf
);
1391 /* The jump pad is now built. Wire in a jump to our jump pad. This
1392 is always done last (by our caller actually), so that we can
1393 install fast tracepoints with threads running. This relies on
1394 the agent's atomic write support. */
1395 loffset
= *jump_entry
- tpaddr
;
1398 if (is_64
&& offset
!= loffset
)
1401 "E.Jump back from jump pad too far from tracepoint "
1402 "(offset 0x%" PRIx64
" > int33).", loffset
);
1405 memcpy (jbuf
+ 2, &offset
, 4);
1406 memcpy (jjump_pad_insn
, jbuf
, sizeof jbuf
);
1407 *jjump_pad_insn_size
= sizeof jbuf
;
1409 /* Return the end address of our pad. */
1410 *jump_entry
= buildaddr
;
1415 /* Implementation of linux_target_ops method
1416 "get_min_fast_tracepoint_insn_len". */
1419 s390_get_min_fast_tracepoint_insn_len (void)
1421 /* We only support using 6-byte jumps to reach the tracepoint code.
1422 If the tracepoint buffer were allocated sufficiently close (64kiB)
1423 to the executable code, and the traced instruction itself was close
1424 enough to the beginning, we could use 4-byte jumps, but this doesn't
1425 seem to be worth the effort. */
1429 /* Implementation of linux_target_ops method "get_ipa_tdesc_idx". */
1432 s390_get_ipa_tdesc_idx (void)
1434 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
1435 const struct target_desc
*tdesc
= regcache
->tdesc
;
1438 if (tdesc
== tdesc_s390x_linux64
)
1439 return S390_TDESC_64
;
1440 if (tdesc
== tdesc_s390x_linux64v1
)
1441 return S390_TDESC_64V1
;
1442 if (tdesc
== tdesc_s390x_linux64v2
)
1443 return S390_TDESC_64V2
;
1444 if (tdesc
== tdesc_s390x_te_linux64
)
1445 return S390_TDESC_TE
;
1446 if (tdesc
== tdesc_s390x_vx_linux64
)
1447 return S390_TDESC_VX
;
1448 if (tdesc
== tdesc_s390x_tevx_linux64
)
1449 return S390_TDESC_TEVX
;
1450 if (tdesc
== tdesc_s390x_gs_linux64
)
1451 return S390_TDESC_GS
;
1454 if (tdesc
== tdesc_s390_linux32
)
1455 return S390_TDESC_32
;
1456 if (tdesc
== tdesc_s390_linux32v1
)
1457 return S390_TDESC_32V1
;
1458 if (tdesc
== tdesc_s390_linux32v2
)
1459 return S390_TDESC_32V2
;
1460 if (tdesc
== tdesc_s390_linux64
)
1461 return S390_TDESC_64
;
1462 if (tdesc
== tdesc_s390_linux64v1
)
1463 return S390_TDESC_64V1
;
1464 if (tdesc
== tdesc_s390_linux64v2
)
1465 return S390_TDESC_64V2
;
1466 if (tdesc
== tdesc_s390_te_linux64
)
1467 return S390_TDESC_TE
;
1468 if (tdesc
== tdesc_s390_vx_linux64
)
1469 return S390_TDESC_VX
;
1470 if (tdesc
== tdesc_s390_tevx_linux64
)
1471 return S390_TDESC_TEVX
;
1472 if (tdesc
== tdesc_s390_gs_linux64
)
1473 return S390_TDESC_GS
;
1478 /* Appends given buffer to current_insn_ptr in the target. */
1481 add_insns (const unsigned char *start
, int len
)
1483 CORE_ADDR buildaddr
= current_insn_ptr
;
1486 debug_printf ("Adding %d bytes of insn at %s\n",
1487 len
, paddress (buildaddr
));
1489 append_insns (&buildaddr
, len
, start
);
1490 current_insn_ptr
= buildaddr
;
1493 /* Register usage in emit:
1496 - %r2: top of stack (high word for 31-bit)
1497 - %r3: low word of top of stack (for 31-bit)
1499 - %r6, %r7, %r8: don't use
1502 - %r11: frame pointer
1503 - %r12: saved top of stack for void_call_2 (high word for 31-bit)
1504 - %r13: low word of saved top of stack (for 31-bit)
1505 - %r14: return address for calls
1506 - %r15: stack pointer
1510 /* The "emit_prologue" emit_ops method for s390. */
1513 s390_emit_prologue (void)
1515 static const unsigned char buf
[] = {
1516 0x90, 0x9f, 0xf0, 0x24, /* stm %r9, %r15, 0x24(%r15) */
1517 0x18, 0x92, /* lr %r9, %r2 */
1518 0x18, 0xa3, /* lr %r10, %r3 */
1519 0x18, 0xbf, /* lr %r11, %r15 */
1521 add_insns (buf
, sizeof buf
);
1524 /* The "emit_epilogue" emit_ops method for s390. */
1527 s390_emit_epilogue (void)
1529 static const unsigned char buf
[] = {
1530 0x90, 0x23, 0xa0, 0x00, /* stm %r2, %r3, 0(%r10) */
1531 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1532 0x98, 0x9f, 0xb0, 0x24, /* lm %r9, %r15, 0x24(%r11) */
1533 0x07, 0xfe, /* br %r14 */
1535 add_insns (buf
, sizeof buf
);
1538 /* The "emit_add" emit_ops method for s390. */
1541 s390_emit_add (void)
1543 static const unsigned char buf
[] = {
1544 0x5e, 0x30, 0xf0, 0x04, /* al %r3, 4(%r15) */
1545 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x98, /* al %r2, 0(%r15) */
1546 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1548 add_insns (buf
, sizeof buf
);
1551 /* The "emit_sub" emit_ops method for s390. */
1554 s390_emit_sub (void)
1556 static const unsigned char buf
[] = {
1557 0x98, 0x45, 0xf0, 0x00, /* lm %r4, %r5, 0(%r15) */
1558 0x1f, 0x53, /* slr %r5, %r3 */
1559 0xb9, 0x99, 0x00, 0x42, /* slbr %r4, %r2 */
1560 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1561 0x18, 0x35, /* lr %r3, %r5 */
1562 0x18, 0x24, /* lr %r2, %r4 */
1564 add_insns (buf
, sizeof buf
);
1567 /* The "emit_mul" emit_ops method for s390. */
1570 s390_emit_mul (void)
1575 /* The "emit_lsh" emit_ops method for s390. */
1578 s390_emit_lsh (void)
1580 static const unsigned char buf
[] = {
1581 0x18, 0x43, /* lr %r4, %r3 */
1582 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1583 0x8d, 0x20, 0x40, 0x00, /* sldl %r2, 0(%r4) */
1584 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1586 add_insns (buf
, sizeof buf
);
1589 /* The "emit_rsh_signed" emit_ops method for s390. */
1592 s390_emit_rsh_signed (void)
1594 static const unsigned char buf
[] = {
1595 0x18, 0x43, /* lr %r4, %r3 */
1596 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1597 0x8e, 0x20, 0x40, 0x00, /* srda %r2, 0(%r4) */
1598 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1600 add_insns (buf
, sizeof buf
);
1603 /* The "emit_rsh_unsigned" emit_ops method for s390. */
1606 s390_emit_rsh_unsigned (void)
1608 static const unsigned char buf
[] = {
1609 0x18, 0x43, /* lr %r4, %r3 */
1610 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1611 0x8c, 0x20, 0x40, 0x00, /* srdl %r2, 0(%r4) */
1612 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1614 add_insns (buf
, sizeof buf
);
1617 /* The "emit_ext" emit_ops method for s390. */
1620 s390_emit_ext (int arg
)
1622 unsigned char buf
[] = {
1623 0x8d, 0x20, 0x00, (unsigned char) (64 - arg
), /* sldl %r2, <64-arg> */
1624 0x8e, 0x20, 0x00, (unsigned char) (64 - arg
), /* srda %r2, <64-arg> */
1626 add_insns (buf
, sizeof buf
);
1629 /* The "emit_log_not" emit_ops method for s390. */
1632 s390_emit_log_not (void)
1634 static const unsigned char buf
[] = {
1635 0x16, 0x23, /* or %r2, %r3 */
1636 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1637 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1638 0xa7, 0x74, 0x00, 0x04, /* jne .Lskip */
1639 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1642 add_insns (buf
, sizeof buf
);
1645 /* The "emit_bit_and" emit_ops method for s390. */
1648 s390_emit_bit_and (void)
1650 static const unsigned char buf
[] = {
1651 0x54, 0x20, 0xf0, 0x00, /* n %r2, 0(%r15) */
1652 0x54, 0x30, 0xf0, 0x04, /* n %r3, 4(%r15) */
1653 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1655 add_insns (buf
, sizeof buf
);
1658 /* The "emit_bit_or" emit_ops method for s390. */
1661 s390_emit_bit_or (void)
1663 static const unsigned char buf
[] = {
1664 0x56, 0x20, 0xf0, 0x00, /* o %r2, 0(%r15) */
1665 0x56, 0x30, 0xf0, 0x04, /* o %r3, 4(%r15) */
1666 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1668 add_insns (buf
, sizeof buf
);
1671 /* The "emit_bit_xor" emit_ops method for s390. */
1674 s390_emit_bit_xor (void)
1676 static const unsigned char buf
[] = {
1677 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
1678 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
1679 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1681 add_insns (buf
, sizeof buf
);
1684 /* The "emit_bit_not" emit_ops method for s390. */
1687 s390_emit_bit_not (void)
1689 static const unsigned char buf
[] = {
1690 0xa7, 0x48, 0xff, 0xff, /* lhi %r4, -1 */
1691 0x17, 0x24, /* xr %r2, %r4 */
1692 0x17, 0x34, /* xr %r3, %r4 */
1694 add_insns (buf
, sizeof buf
);
1697 /* The "emit_equal" emit_ops method for s390. */
1700 s390_emit_equal (void)
1702 s390_emit_bit_xor ();
1703 s390_emit_log_not ();
1706 /* The "emit_less_signed" emit_ops method for s390. */
1709 s390_emit_less_signed (void)
1711 static const unsigned char buf
[] = {
1712 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
1713 0xa7, 0x24, 0x00, 0x0c, /* jh .Lless */
1714 0xa7, 0x44, 0x00, 0x06, /* jl .Lhigh */
1715 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
1716 0xa7, 0x24, 0x00, 0x06, /* jh .Lless */
1718 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1719 0xa7, 0xf4, 0x00, 0x04, /* j .Lend */
1721 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1723 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1724 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1726 add_insns (buf
, sizeof buf
);
1729 /* The "emit_less_unsigned" emit_ops method for s390. */
1732 s390_emit_less_unsigned (void)
1734 static const unsigned char buf
[] = {
1735 0x55, 0x20, 0xf0, 0x00, /* cl %r2, 0(%r15) */
1736 0xa7, 0x24, 0x00, 0x0c, /* jh .Lless */
1737 0xa7, 0x44, 0x00, 0x06, /* jl .Lhigh */
1738 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
1739 0xa7, 0x24, 0x00, 0x06, /* jh .Lless */
1741 0xa7, 0x38, 0x00, 0x00, /* lhi %r3, 0 */
1742 0xa7, 0xf4, 0x00, 0x04, /* j .Lend */
1744 0xa7, 0x38, 0x00, 0x01, /* lhi %r3, 1 */
1746 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1747 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1749 add_insns (buf
, sizeof buf
);
1752 /* The "emit_ref" emit_ops method for s390. */
1755 s390_emit_ref (int size
)
1757 static const unsigned char buf1
[] = {
1758 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1759 0x43, 0x30, 0x30, 0x00, /* ic %r3, 0(%r3) */
1761 static const unsigned char buf2
[] = {
1762 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1763 0x48, 0x30, 0x30, 0x00, /* lh %r3, 0(%r3) */
1765 static const unsigned char buf4
[] = {
1766 0xa7, 0x28, 0x00, 0x00, /* lhi %r2, 0 */
1767 0x58, 0x30, 0x30, 0x00, /* l %r3, 0(%r3) */
1769 static const unsigned char buf8
[] = {
1770 0x98, 0x23, 0x30, 0x00, /* lm %r2, %r3, 0(%r3) */
1775 add_insns (buf1
, sizeof buf1
);
1778 add_insns (buf2
, sizeof buf2
);
1781 add_insns (buf4
, sizeof buf4
);
1784 add_insns (buf8
, sizeof buf8
);
1791 /* The "emit_if_goto" emit_ops method for s390. */
1794 s390_emit_if_goto (int *offset_p
, int *size_p
)
1796 static const unsigned char buf
[] = {
1797 0x16, 0x23, /* or %r2, %r3 */
1798 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1799 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1800 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00 /* jgne <fillme> */
1802 add_insns (buf
, sizeof buf
);
1809 /* The "emit_goto" emit_ops method for s390 and s390x. */
1812 s390_emit_goto (int *offset_p
, int *size_p
)
1814 static const unsigned char buf
[] = {
1815 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
1817 add_insns (buf
, sizeof buf
);
1824 /* The "write_goto_address" emit_ops method for s390 and s390x. */
1827 s390_write_goto_address (CORE_ADDR from
, CORE_ADDR to
, int size
)
1829 long diff
= ((long) (to
- (from
- 2))) / 2;
1831 unsigned char buf
[sizeof sdiff
];
1833 /* We're only doing 4-byte sizes at the moment. */
1834 if (size
!= sizeof sdiff
|| sdiff
!= diff
)
1840 memcpy (buf
, &sdiff
, sizeof sdiff
);
1841 target_write_memory (from
, buf
, sizeof sdiff
);
1844 /* Preparation for emitting a literal pool of given size. Loads the address
1845 of the pool into %r1, and jumps over it. Called should emit the pool data
1846 immediately afterwards. Used for both s390 and s390x. */
1849 s390_emit_litpool (int size
)
1851 static const unsigned char nop
[] = {
1854 unsigned char buf
[] = {
1856 (unsigned char) ((size
+ 4) / 2), /* bras %r1, .Lend+size */
1861 /* buf needs to start at even halfword for litpool to be aligned */
1862 if (current_insn_ptr
& 2)
1863 add_insns (nop
, sizeof nop
);
1867 while ((current_insn_ptr
& 6) != 4)
1868 add_insns (nop
, sizeof nop
);
1870 add_insns (buf
, sizeof buf
);
1873 /* The "emit_const" emit_ops method for s390. */
1876 s390_emit_const (LONGEST num
)
1878 unsigned long long n
= num
;
1879 unsigned char buf_s
[] = {
1880 /* lhi %r3, <num> */
1882 (unsigned char) (num
>> 8), (unsigned char) num
,
1886 static const unsigned char buf_l
[] = {
1887 0x98, 0x23, 0x10, 0x00, /* lm %r2, %r3, 0(%r1) */
1889 if (num
< 0x8000 && num
>= 0)
1891 add_insns (buf_s
, sizeof buf_s
);
1895 s390_emit_litpool (8);
1896 add_insns ((unsigned char *) &n
, sizeof n
);
1897 add_insns (buf_l
, sizeof buf_l
);
1901 /* The "emit_call" emit_ops method for s390. */
1904 s390_emit_call (CORE_ADDR fn
)
1906 unsigned int n
= fn
;
1907 static const unsigned char buf
[] = {
1908 0x58, 0x10, 0x10, 0x00, /* l %r1, 0(%r1) */
1909 0xa7, 0xfa, 0xff, 0xa0, /* ahi %r15, -0x60 */
1910 0x0d, 0xe1, /* basr %r14, %r1 */
1911 0xa7, 0xfa, 0x00, 0x60, /* ahi %r15, 0x60 */
1913 s390_emit_litpool (4);
1914 add_insns ((unsigned char *) &n
, sizeof n
);
1915 add_insns (buf
, sizeof buf
);
1918 /* The "emit_reg" emit_ops method for s390. */
1921 s390_emit_reg (int reg
)
1923 unsigned char bufpre
[] = {
1926 /* lhi %r3, <reg> */
1927 0xa7, 0x38, (unsigned char) (reg
>> 8), (unsigned char) reg
,
1929 add_insns (bufpre
, sizeof bufpre
);
1930 s390_emit_call (get_raw_reg_func_addr ());
1933 /* The "emit_pop" emit_ops method for s390. */
1936 s390_emit_pop (void)
1938 static const unsigned char buf
[] = {
1939 0x98, 0x23, 0xf0, 0x00, /* lm %r2, %r3, 0(%r15) */
1940 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
1942 add_insns (buf
, sizeof buf
);
1945 /* The "emit_stack_flush" emit_ops method for s390. */
1948 s390_emit_stack_flush (void)
1950 static const unsigned char buf
[] = {
1951 0xa7, 0xfa, 0xff, 0xf8, /* ahi %r15, -8 */
1952 0x90, 0x23, 0xf0, 0x00, /* stm %r2, %r3, 0(%r15) */
1954 add_insns (buf
, sizeof buf
);
1957 /* The "emit_zero_ext" emit_ops method for s390. */
1960 s390_emit_zero_ext (int arg
)
1962 unsigned char buf
[] = {
1963 0x8d, 0x20, 0x00, (unsigned char) (64 - arg
), /* sldl %r2, <64-arg> */
1964 0x8c, 0x20, 0x00, (unsigned char) (64 - arg
), /* srdl %r2, <64-arg> */
1966 add_insns (buf
, sizeof buf
);
1969 /* The "emit_swap" emit_ops method for s390. */
1972 s390_emit_swap (void)
1974 static const unsigned char buf
[] = {
1975 0x98, 0x45, 0xf0, 0x00, /* lm %r4, %r5, 0(%r15) */
1976 0x90, 0x23, 0xf0, 0x00, /* stm %r2, %r3, 0(%r15) */
1977 0x18, 0x24, /* lr %r2, %r4 */
1978 0x18, 0x35, /* lr %r3, %r5 */
1980 add_insns (buf
, sizeof buf
);
1983 /* The "emit_stack_adjust" emit_ops method for s390. */
1986 s390_emit_stack_adjust (int n
)
1988 unsigned char buf
[] = {
1991 (unsigned char ) (n
* 8 >> 8), (unsigned char) (n
* 8),
1993 add_insns (buf
, sizeof buf
);
1996 /* Sets %r2 to a 32-bit constant. */
1999 s390_emit_set_r2 (int arg1
)
2001 unsigned char buf_s
[] = {
2002 /* lhi %r2, <arg1> */
2003 0xa7, 0x28, (unsigned char) (arg1
>> 8), (unsigned char) arg1
,
2005 static const unsigned char buf_l
[] = {
2006 0x58, 0x20, 0x10, 0x00, /* l %r2, 0(%r1) */
2008 if (arg1
< 0x8000 && arg1
>= -0x8000)
2010 add_insns (buf_s
, sizeof buf_s
);
2014 s390_emit_litpool (4);
2015 add_insns ((unsigned char *) &arg1
, sizeof arg1
);
2016 add_insns (buf_l
, sizeof buf_l
);
2020 /* The "emit_int_call_1" emit_ops method for s390. */
2023 s390_emit_int_call_1 (CORE_ADDR fn
, int arg1
)
2025 /* FN's prototype is `LONGEST(*fn)(int)'. */
2026 s390_emit_set_r2 (arg1
);
2027 s390_emit_call (fn
);
2030 /* The "emit_void_call_2" emit_ops method for s390. */
2033 s390_emit_void_call_2 (CORE_ADDR fn
, int arg1
)
2035 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
2036 static const unsigned char buf
[] = {
2037 0x18, 0xc2, /* lr %r12, %r2 */
2038 0x18, 0xd3, /* lr %r13, %r3 */
2039 0x18, 0x43, /* lr %r4, %r3 */
2040 0x18, 0x32, /* lr %r3, %r2 */
2042 static const unsigned char buf2
[] = {
2043 0x18, 0x2c, /* lr %r2, %r12 */
2044 0x18, 0x3d, /* lr %r3, %r13 */
2046 add_insns (buf
, sizeof buf
);
2047 s390_emit_set_r2 (arg1
);
2048 s390_emit_call (fn
);
2049 add_insns (buf2
, sizeof buf2
);
2052 /* The "emit_eq_goto" emit_ops method for s390. */
2055 s390_emit_eq_goto (int *offset_p
, int *size_p
)
2057 static const unsigned char buf
[] = {
2058 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
2059 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
2060 0x16, 0x23, /* or %r2, %r3 */
2061 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2062 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2063 0xc0, 0x84, 0x00, 0x00, 0x00, 0x00, /* jge <fillme> */
2065 add_insns (buf
, sizeof buf
);
2072 /* The "emit_ne_goto" emit_ops method for s390. */
2075 s390_emit_ne_goto (int *offset_p
, int *size_p
)
2077 static const unsigned char buf
[] = {
2078 0x57, 0x20, 0xf0, 0x00, /* x %r2, 0(%r15) */
2079 0x57, 0x30, 0xf0, 0x04, /* x %r3, 4(%r15) */
2080 0x16, 0x23, /* or %r2, %r3 */
2081 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2082 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2083 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2085 add_insns (buf
, sizeof buf
);
2092 /* The "emit_lt_goto" emit_ops method for s390. */
2095 s390_emit_lt_goto (int *offset_p
, int *size_p
)
2097 static const unsigned char buf
[] = {
2098 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2099 0xa7, 0x24, 0x00, 0x0e, /* jh .Ltrue */
2100 0xa7, 0x44, 0x00, 0x06, /* jl .Lfalse */
2101 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2102 0xa7, 0x24, 0x00, 0x08, /* jh .Ltrue */
2104 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2105 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2106 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2108 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2109 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2110 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2113 add_insns (buf
, sizeof buf
);
2120 /* The "emit_le_goto" emit_ops method for s390. */
2123 s390_emit_le_goto (int *offset_p
, int *size_p
)
2125 static const unsigned char buf
[] = {
2126 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2127 0xa7, 0x24, 0x00, 0x0e, /* jh .Ltrue */
2128 0xa7, 0x44, 0x00, 0x06, /* jl .Lfalse */
2129 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2130 0xa7, 0xa4, 0x00, 0x08, /* jhe .Ltrue */
2132 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2133 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2134 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2136 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2137 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2138 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2141 add_insns (buf
, sizeof buf
);
2148 /* The "emit_gt_goto" emit_ops method for s390. */
2151 s390_emit_gt_goto (int *offset_p
, int *size_p
)
2153 static const unsigned char buf
[] = {
2154 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2155 0xa7, 0x44, 0x00, 0x0e, /* jl .Ltrue */
2156 0xa7, 0x24, 0x00, 0x06, /* jh .Lfalse */
2157 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2158 0xa7, 0x44, 0x00, 0x08, /* jl .Ltrue */
2160 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2161 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2162 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2164 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2165 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2166 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2169 add_insns (buf
, sizeof buf
);
2176 /* The "emit_ge_goto" emit_ops method for s390. */
2179 s390_emit_ge_goto (int *offset_p
, int *size_p
)
2181 static const unsigned char buf
[] = {
2182 0x59, 0x20, 0xf0, 0x00, /* c %r2, 0(%r15) */
2183 0xa7, 0x44, 0x00, 0x0e, /* jl .Ltrue */
2184 0xa7, 0x24, 0x00, 0x06, /* jh .Lfalse */
2185 0x55, 0x30, 0xf0, 0x04, /* cl %r3, 4(%r15) */
2186 0xa7, 0xc4, 0x00, 0x08, /* jle .Ltrue */
2188 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2189 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2190 0xa7, 0xf4, 0x00, 0x09, /* j .Lend */
2192 0x98, 0x23, 0xf0, 0x08, /* lm %r2, %r3, 8(%r15) */
2193 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2194 0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00, /* jg <fillme> */
2197 add_insns (buf
, sizeof buf
);
2204 /* The "emit_ops" structure for s390. Named _impl to avoid name
2205 collision with s390_emit_ops function. */
2207 static struct emit_ops s390_emit_ops_impl
=
2215 s390_emit_rsh_signed
,
2216 s390_emit_rsh_unsigned
,
2224 s390_emit_less_signed
,
2225 s390_emit_less_unsigned
,
2229 s390_write_goto_address
,
2234 s390_emit_stack_flush
,
2237 s390_emit_stack_adjust
,
2238 s390_emit_int_call_1
,
2239 s390_emit_void_call_2
,
2250 /* The "emit_prologue" emit_ops method for s390x. */
2253 s390x_emit_prologue (void)
2255 static const unsigned char buf
[] = {
2256 0xeb, 0x9f, 0xf0, 0x48, 0x00, 0x24, /* stmg %r9, %r15, 0x48(%r15) */
2257 0xb9, 0x04, 0x00, 0x92, /* lgr %r9, %r2 */
2258 0xb9, 0x04, 0x00, 0xa3, /* lgr %r10, %r3 */
2259 0xb9, 0x04, 0x00, 0xbf, /* lgr %r11, %r15 */
2261 add_insns (buf
, sizeof buf
);
2264 /* The "emit_epilogue" emit_ops method for s390x. */
2267 s390x_emit_epilogue (void)
2269 static const unsigned char buf
[] = {
2270 0xe3, 0x20, 0xa0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r10) */
2271 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2272 0xeb, 0x9f, 0xf0, 0x48, 0x00, 0x04, /* lmg %r9, %r15, 0x48(%r15) */
2273 0x07, 0xfe, /* br %r14 */
2275 add_insns (buf
, sizeof buf
);
2278 /* The "emit_add" emit_ops method for s390x. */
2281 s390x_emit_add (void)
2283 static const unsigned char buf
[] = {
2284 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x0a, /* alg %r2, 0(%r15) */
2285 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2287 add_insns (buf
, sizeof buf
);
2290 /* The "emit_sub" emit_ops method for s390x. */
2293 s390x_emit_sub (void)
2295 static const unsigned char buf
[] = {
2296 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2297 0xb9, 0x0b, 0x00, 0x32, /* slgr %r3, %r2 */
2298 0xb9, 0x04, 0x00, 0x23, /* lgr %r2, %r3 */
2299 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2301 add_insns (buf
, sizeof buf
);
2304 /* The "emit_mul" emit_ops method for s390x. */
2307 s390x_emit_mul (void)
2312 /* The "emit_lsh" emit_ops method for s390x. */
2315 s390x_emit_lsh (void)
2317 static const unsigned char buf
[] = {
2318 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2319 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0d, /* sllg %r2, %r3, 0(%r2) */
2320 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2322 add_insns (buf
, sizeof buf
);
2325 /* The "emit_rsh_signed" emit_ops method for s390x. */
2328 s390x_emit_rsh_signed (void)
2330 static const unsigned char buf
[] = {
2331 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2332 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0a, /* srag %r2, %r3, 0(%r2) */
2333 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2335 add_insns (buf
, sizeof buf
);
2338 /* The "emit_rsh_unsigned" emit_ops method for s390x. */
2341 s390x_emit_rsh_unsigned (void)
2343 static const unsigned char buf
[] = {
2344 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2345 0xeb, 0x23, 0x20, 0x00, 0x00, 0x0c, /* srlg %r2, %r3, 0(%r2) */
2346 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2348 add_insns (buf
, sizeof buf
);
2351 /* The "emit_ext" emit_ops method for s390x. */
2354 s390x_emit_ext (int arg
)
2356 unsigned char buf
[] = {
2357 /* sllg %r2, %r2, <64-arg> */
2358 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0d,
2359 /* srag %r2, %r2, <64-arg> */
2360 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0a,
2362 add_insns (buf
, sizeof buf
);
2365 /* The "emit_log_not" emit_ops method for s390x. */
2368 s390x_emit_log_not (void)
2370 static const unsigned char buf
[] = {
2371 0xb9, 0x00, 0x00, 0x22, /* lpgr %r2, %r2 */
2372 0xa7, 0x2b, 0xff, 0xff, /* aghi %r2, -1 */
2373 0xeb, 0x22, 0x00, 0x3f, 0x00, 0x0c, /* srlg %r2, %r2, 63 */
2375 add_insns (buf
, sizeof buf
);
2378 /* The "emit_bit_and" emit_ops method for s390x. */
2381 s390x_emit_bit_and (void)
2383 static const unsigned char buf
[] = {
2384 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x80, /* ng %r2, 0(%r15) */
2385 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2387 add_insns (buf
, sizeof buf
);
2390 /* The "emit_bit_or" emit_ops method for s390x. */
2393 s390x_emit_bit_or (void)
2395 static const unsigned char buf
[] = {
2396 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x81, /* og %r2, 0(%r15) */
2397 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2399 add_insns (buf
, sizeof buf
);
2402 /* The "emit_bit_xor" emit_ops method for s390x. */
2405 s390x_emit_bit_xor (void)
2407 static const unsigned char buf
[] = {
2408 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x82, /* xg %r2, 0(%r15) */
2409 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2411 add_insns (buf
, sizeof buf
);
2414 /* The "emit_bit_not" emit_ops method for s390x. */
2417 s390x_emit_bit_not (void)
2419 static const unsigned char buf
[] = {
2420 0xa7, 0x39, 0xff, 0xff, /* lghi %r3, -1 */
2421 0xb9, 0x82, 0x00, 0x23, /* xgr %r2, %r3 */
2423 add_insns (buf
, sizeof buf
);
2426 /* The "emit_equal" emit_ops method for s390x. */
2429 s390x_emit_equal (void)
2431 s390x_emit_bit_xor ();
2432 s390x_emit_log_not ();
2435 /* The "emit_less_signed" emit_ops method for s390x. */
2438 s390x_emit_less_signed (void)
2440 static const unsigned char buf
[] = {
2441 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2442 0xa7, 0x29, 0x00, 0x01, /* lghi %r2, 1 */
2443 0xa7, 0x24, 0x00, 0x04, /* jh .Lend */
2444 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2446 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2448 add_insns (buf
, sizeof buf
);
2451 /* The "emit_less_unsigned" emit_ops method for s390x. */
2454 s390x_emit_less_unsigned (void)
2456 static const unsigned char buf
[] = {
2457 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x21, /* clg %r2, 0(%r15) */
2458 0xa7, 0x29, 0x00, 0x01, /* lghi %r2, 1 */
2459 0xa7, 0x24, 0x00, 0x04, /* jh .Lend */
2460 0xa7, 0x29, 0x00, 0x00, /* lghi %r2, 0 */
2462 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2464 add_insns (buf
, sizeof buf
);
2467 /* The "emit_ref" emit_ops method for s390x. */
2470 s390x_emit_ref (int size
)
2472 static const unsigned char buf1
[] = {
2473 0xe3, 0x20, 0x20, 0x00, 0x00, 0x90, /* llgc %r2, 0(%r2) */
2475 static const unsigned char buf2
[] = {
2476 0xe3, 0x20, 0x20, 0x00, 0x00, 0x91 /* llgh %r2, 0(%r2) */
2478 static const unsigned char buf4
[] = {
2479 0xe3, 0x20, 0x20, 0x00, 0x00, 0x16, /* llgf %r2, 0(%r2) */
2481 static const unsigned char buf8
[] = {
2482 0xe3, 0x20, 0x20, 0x00, 0x00, 0x04, /* lg %r2, 0(%r2) */
2487 add_insns (buf1
, sizeof buf1
);
2490 add_insns (buf2
, sizeof buf2
);
2493 add_insns (buf4
, sizeof buf4
);
2496 add_insns (buf8
, sizeof buf8
);
2503 /* The "emit_if_goto" emit_ops method for s390x. */
2506 s390x_emit_if_goto (int *offset_p
, int *size_p
)
2508 static const unsigned char buf
[] = {
2509 0xb9, 0x02, 0x00, 0x22, /* ltgr %r2, %r2 */
2510 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x04, /* lg %r2, 0(%r15) */
2511 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2512 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2514 add_insns (buf
, sizeof buf
);
2521 /* The "emit_const" emit_ops method for s390x. */
2524 s390x_emit_const (LONGEST num
)
2526 unsigned long long n
= num
;
2527 unsigned char buf_s
[] = {
2528 /* lghi %r2, <num> */
2529 0xa7, 0x29, (unsigned char) (num
>> 8), (unsigned char) num
,
2531 static const unsigned char buf_l
[] = {
2532 0xe3, 0x20, 0x10, 0x00, 0x00, 0x04, /* lg %r2, 0(%r1) */
2534 if (num
< 0x8000 && num
>= -0x8000)
2536 add_insns (buf_s
, sizeof buf_s
);
2540 s390_emit_litpool (8);
2541 add_insns ((unsigned char *) &n
, sizeof n
);
2542 add_insns (buf_l
, sizeof buf_l
);
2546 /* The "emit_call" emit_ops method for s390x. */
2549 s390x_emit_call (CORE_ADDR fn
)
2551 unsigned long n
= fn
;
2552 static const unsigned char buf
[] = {
2553 0xe3, 0x10, 0x10, 0x00, 0x00, 0x04, /* lg %r1, 0(%r1) */
2554 0xa7, 0xfb, 0xff, 0x60, /* aghi %r15, -0xa0 */
2555 0x0d, 0xe1, /* basr %r14, %r1 */
2556 0xa7, 0xfb, 0x00, 0xa0, /* aghi %r15, 0xa0 */
2558 s390_emit_litpool (8);
2559 add_insns ((unsigned char *) &n
, sizeof n
);
2560 add_insns (buf
, sizeof buf
);
2563 /* The "emit_reg" emit_ops method for s390x. */
2566 s390x_emit_reg (int reg
)
2568 unsigned char buf
[] = {
2570 0xb9, 0x04, 0x00, 0x29,
2571 /* lghi %r3, <reg> */
2572 0xa7, 0x39, (unsigned char) (reg
>> 8), (unsigned char) reg
,
2574 add_insns (buf
, sizeof buf
);
2575 s390x_emit_call (get_raw_reg_func_addr ());
2578 /* The "emit_pop" emit_ops method for s390x. */
2581 s390x_emit_pop (void)
2583 static const unsigned char buf
[] = {
2584 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x04, /* lg %r2, 0(%r15) */
2585 0x41, 0xf0, 0xf0, 0x08, /* la %r15, 8(%r15) */
2587 add_insns (buf
, sizeof buf
);
2590 /* The "emit_stack_flush" emit_ops method for s390x. */
2593 s390x_emit_stack_flush (void)
2595 static const unsigned char buf
[] = {
2596 0xa7, 0xfb, 0xff, 0xf8, /* aghi %r15, -8 */
2597 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r15) */
2599 add_insns (buf
, sizeof buf
);
2602 /* The "emit_zero_ext" emit_ops method for s390x. */
2605 s390x_emit_zero_ext (int arg
)
2607 unsigned char buf
[] = {
2608 /* sllg %r2, %r2, <64-arg> */
2609 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0d,
2610 /* srlg %r2, %r2, <64-arg> */
2611 0xeb, 0x22, 0x00, (unsigned char) (64 - arg
), 0x00, 0x0c,
2613 add_insns (buf
, sizeof buf
);
2616 /* The "emit_swap" emit_ops method for s390x. */
2619 s390x_emit_swap (void)
2621 static const unsigned char buf
[] = {
2622 0xe3, 0x30, 0xf0, 0x00, 0x00, 0x04, /* lg %r3, 0(%r15) */
2623 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x24, /* stg %r2, 0(%r15) */
2624 0xb9, 0x04, 0x00, 0x23, /* lgr %r2, %r3 */
2626 add_insns (buf
, sizeof buf
);
2629 /* The "emit_stack_adjust" emit_ops method for s390x. */
2632 s390x_emit_stack_adjust (int n
)
2634 unsigned char buf
[] = {
2635 /* aghi %r15, 8*n */
2637 (unsigned char) (n
* 8 >> 8), (unsigned char) (n
* 8),
2639 add_insns (buf
, sizeof buf
);
2642 /* The "emit_int_call_1" emit_ops method for s390x. */
2645 s390x_emit_int_call_1 (CORE_ADDR fn
, int arg1
)
2647 /* FN's prototype is `LONGEST(*fn)(int)'. */
2648 s390x_emit_const (arg1
);
2649 s390x_emit_call (fn
);
2652 /* The "emit_void_call_2" emit_ops method for s390x. */
2655 s390x_emit_void_call_2 (CORE_ADDR fn
, int arg1
)
2657 /* FN's prototype is `void(*fn)(int,LONGEST)'. */
2658 static const unsigned char buf
[] = {
2659 0xb9, 0x04, 0x00, 0x32, /* lgr %r3, %r2 */
2660 0xb9, 0x04, 0x00, 0xc2, /* lgr %r12, %r2 */
2662 static const unsigned char buf2
[] = {
2663 0xb9, 0x04, 0x00, 0x2c, /* lgr %r2, %r12 */
2665 add_insns (buf
, sizeof buf
);
2666 s390x_emit_const (arg1
);
2667 s390x_emit_call (fn
);
2668 add_insns (buf2
, sizeof buf2
);
2671 /* The "emit_eq_goto" emit_ops method for s390x. */
2674 s390x_emit_eq_goto (int *offset_p
, int *size_p
)
2676 static const unsigned char buf
[] = {
2677 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2678 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2679 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2680 0xc0, 0x84, 0x00, 0x00, 0x00, 0x00, /* jge <fillme> */
2682 add_insns (buf
, sizeof buf
);
2689 /* The "emit_ne_goto" emit_ops method for s390x. */
2692 s390x_emit_ne_goto (int *offset_p
, int *size_p
)
2694 static const unsigned char buf
[] = {
2695 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2696 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2697 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2698 0xc0, 0x74, 0x00, 0x00, 0x00, 0x00, /* jgne <fillme> */
2700 add_insns (buf
, sizeof buf
);
2707 /* The "emit_lt_goto" emit_ops method for s390x. */
2710 s390x_emit_lt_goto (int *offset_p
, int *size_p
)
2712 static const unsigned char buf
[] = {
2713 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2714 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2715 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2716 0xc0, 0x24, 0x00, 0x00, 0x00, 0x00, /* jgh <fillme> */
2718 add_insns (buf
, sizeof buf
);
2725 /* The "emit_le_goto" emit_ops method for s390x. */
2728 s390x_emit_le_goto (int *offset_p
, int *size_p
)
2730 static const unsigned char buf
[] = {
2731 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2732 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2733 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2734 0xc0, 0xa4, 0x00, 0x00, 0x00, 0x00, /* jghe <fillme> */
2736 add_insns (buf
, sizeof buf
);
2743 /* The "emit_gt_goto" emit_ops method for s390x. */
2746 s390x_emit_gt_goto (int *offset_p
, int *size_p
)
2748 static const unsigned char buf
[] = {
2749 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2750 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2751 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2752 0xc0, 0x44, 0x00, 0x00, 0x00, 0x00, /* jgl <fillme> */
2754 add_insns (buf
, sizeof buf
);
2761 /* The "emit_ge_goto" emit_ops method for s390x. */
2764 s390x_emit_ge_goto (int *offset_p
, int *size_p
)
2766 static const unsigned char buf
[] = {
2767 0xe3, 0x20, 0xf0, 0x00, 0x00, 0x20, /* cg %r2, 0(%r15) */
2768 0xe3, 0x20, 0xf0, 0x08, 0x00, 0x04, /* lg %r2, 8(%r15) */
2769 0x41, 0xf0, 0xf0, 0x10, /* la %r15, 16(%r15) */
2770 0xc0, 0xc4, 0x00, 0x00, 0x00, 0x00, /* jgle <fillme> */
2772 add_insns (buf
, sizeof buf
);
2779 /* The "emit_ops" structure for s390x. */
2781 static struct emit_ops s390x_emit_ops
=
2783 s390x_emit_prologue
,
2784 s390x_emit_epilogue
,
2789 s390x_emit_rsh_signed
,
2790 s390x_emit_rsh_unsigned
,
2798 s390x_emit_less_signed
,
2799 s390x_emit_less_unsigned
,
2803 s390_write_goto_address
,
2808 s390x_emit_stack_flush
,
2809 s390x_emit_zero_ext
,
2811 s390x_emit_stack_adjust
,
2812 s390x_emit_int_call_1
,
2813 s390x_emit_void_call_2
,
2823 /* The "emit_ops" linux_target_ops method. */
2825 static struct emit_ops
*
2826 s390_emit_ops (void)
2829 struct regcache
*regcache
= get_thread_regcache (current_thread
, 0);
2831 if (register_size (regcache
->tdesc
, 0) == 8)
2832 return &s390x_emit_ops
;
2835 return &s390_emit_ops_impl
;
2838 struct linux_target_ops the_low_target
= {
2839 s390_supports_z_point_type
,
2844 s390_collect_ptrace_register
,
2845 s390_supply_ptrace_register
,
2846 NULL
, /* siginfo_fixup */
2847 NULL
, /* new_process */
2848 NULL
, /* delete_process */
2849 NULL
, /* new_thread */
2850 NULL
, /* delete_thread */
2851 NULL
, /* new_fork */
2852 NULL
, /* prepare_to_resume */
2853 NULL
, /* process_qsupported */
2854 s390_supports_tracepoints
,
2855 s390_get_thread_area
,
2856 s390_install_fast_tracepoint_jump_pad
,
2858 s390_get_min_fast_tracepoint_insn_len
,
2859 NULL
, /* supports_range_stepping */
2860 s390_supports_hardware_single_step
,
2861 NULL
, /* get_syscall_trapinfo */
2862 s390_get_ipa_tdesc_idx
,
2865 /* The linux target ops object. */
2867 linux_process_target
*the_linux_target
= &the_s390_target
;
2870 initialize_low_arch (void)
2872 /* Initialize the Linux target descriptions. */
2874 init_registers_s390_linux32 ();
2875 init_registers_s390_linux32v1 ();
2876 init_registers_s390_linux32v2 ();
2877 init_registers_s390_linux64 ();
2878 init_registers_s390_linux64v1 ();
2879 init_registers_s390_linux64v2 ();
2880 init_registers_s390_te_linux64 ();
2881 init_registers_s390_vx_linux64 ();
2882 init_registers_s390_tevx_linux64 ();
2883 init_registers_s390_gs_linux64 ();
2885 init_registers_s390x_linux64 ();
2886 init_registers_s390x_linux64v1 ();
2887 init_registers_s390x_linux64v2 ();
2888 init_registers_s390x_te_linux64 ();
2889 init_registers_s390x_vx_linux64 ();
2890 init_registers_s390x_tevx_linux64 ();
2891 init_registers_s390x_gs_linux64 ();
2894 initialize_regsets_info (&s390_regsets_info
);
2895 initialize_regsets_info (&s390_regsets_info_3264
);