1 /* Target-dependent code for GDB, the GNU debugger.
3 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
5 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
8 This file is part of GDB.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #define S390_TDEP /* for special macros in tm-s390.h */
27 #include "arch-utils.h"
37 #include "../bfd/bfd.h"
38 #include "floatformat.h"
41 #include "gdb_assert.h"
46 /* Number of bytes of storage in the actual machine representation
49 s390_register_raw_size (int reg_nr
)
51 if (S390_FP0_REGNUM
<= reg_nr
52 && reg_nr
< S390_FP0_REGNUM
+ S390_NUM_FPRS
)
59 s390x_register_raw_size (int reg_nr
)
61 return (reg_nr
== S390_FPC_REGNUM
)
62 || (reg_nr
>= S390_FIRST_ACR
&& reg_nr
<= S390_LAST_ACR
) ? 4 : 8;
66 s390_cannot_fetch_register (int regno
)
68 return (regno
>= S390_FIRST_CR
&& regno
< (S390_FIRST_CR
+ 9)) ||
69 (regno
>= (S390_FIRST_CR
+ 12) && regno
<= S390_LAST_CR
);
73 s390_register_byte (int reg_nr
)
75 if (reg_nr
<= S390_GP_LAST_REGNUM
)
76 return reg_nr
* S390_GPR_SIZE
;
77 if (reg_nr
<= S390_LAST_ACR
)
78 return S390_ACR0_OFFSET
+ (((reg_nr
) - S390_FIRST_ACR
) * S390_ACR_SIZE
);
79 if (reg_nr
<= S390_LAST_CR
)
80 return S390_CR0_OFFSET
+ (((reg_nr
) - S390_FIRST_CR
) * S390_CR_SIZE
);
81 if (reg_nr
== S390_FPC_REGNUM
)
82 return S390_FPC_OFFSET
;
84 return S390_FP0_OFFSET
+ (((reg_nr
) - S390_FP0_REGNUM
) * S390_FPR_SIZE
);
87 #define S390_MAX_INSTR_SIZE (6)
88 #define S390_SYSCALL_OPCODE (0x0a)
89 #define S390_SYSCALL_SIZE (2)
90 #define S390_SIGCONTEXT_SREGS_OFFSET (8)
91 #define S390X_SIGCONTEXT_SREGS_OFFSET (8)
92 #define S390_SIGREGS_FP0_OFFSET (144)
93 #define S390X_SIGREGS_FP0_OFFSET (216)
94 #define S390_UC_MCONTEXT_OFFSET (256)
95 #define S390X_UC_MCONTEXT_OFFSET (344)
96 #define S390_STACK_FRAME_OVERHEAD 16*DEPRECATED_REGISTER_SIZE+32
97 #define S390_STACK_PARAMETER_ALIGNMENT DEPRECATED_REGISTER_SIZE
98 #define S390_NUM_FP_PARAMETER_REGISTERS (GDB_TARGET_IS_ESAME ? 4:2)
99 #define S390_SIGNAL_FRAMESIZE (GDB_TARGET_IS_ESAME ? 160:96)
100 #define s390_NR_sigreturn 119
101 #define s390_NR_rt_sigreturn 173
105 struct frame_extra_info
109 CORE_ADDR function_start
;
110 CORE_ADDR skip_prologue_function_start
;
111 CORE_ADDR saved_pc_valid
;
113 CORE_ADDR sig_fixed_saved_pc_valid
;
114 CORE_ADDR sig_fixed_saved_pc
;
115 CORE_ADDR frame_pointer_saved_pc
; /* frame pointer needed for alloca */
116 CORE_ADDR stack_bought_valid
;
117 CORE_ADDR stack_bought
; /* amount we decrement the stack pointer by */
118 CORE_ADDR sigcontext
;
122 static CORE_ADDR
s390_frame_saved_pc_nofix (struct frame_info
*fi
);
125 s390_readinstruction (bfd_byte instr
[], CORE_ADDR at
)
129 static int s390_instrlen
[] = {
135 if (target_read_memory (at
, &instr
[0], 2))
137 instrlen
= s390_instrlen
[instr
[0] >> 6];
140 if (target_read_memory (at
+ 2, &instr
[2], instrlen
- 2))
147 s390_memset_extra_info (struct frame_extra_info
*fextra_info
)
149 memset (fextra_info
, 0, sizeof (struct frame_extra_info
));
155 s390_register_name (int reg_nr
)
157 static char *register_names
[] = {
159 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
160 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
161 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
162 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15",
163 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
164 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
166 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
167 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
170 if (reg_nr
<= S390_LAST_REGNUM
)
171 return register_names
[reg_nr
];
180 s390_stab_reg_to_regnum (int regno
)
182 return regno
>= 64 ? S390_PSWM_REGNUM
- 64 :
183 regno
>= 48 ? S390_FIRST_ACR
- 48 :
184 regno
>= 32 ? S390_FIRST_CR
- 32 :
185 regno
<= 15 ? (regno
+ 2) :
186 S390_FP0_REGNUM
+ ((regno
- 16) & 8) + (((regno
- 16) & 3) << 1) +
187 (((regno
- 16) & 4) >> 2);
191 /* Prologue analysis. */
193 /* When we analyze a prologue, we're really doing 'abstract
194 interpretation' or 'pseudo-evaluation': running the function's code
195 in simulation, but using conservative approximations of the values
196 it would have when it actually runs. For example, if our function
197 starts with the instruction:
199 ahi r1, 42 # add halfword immediate 42 to r1
201 we don't know exactly what value will be in r1 after executing this
202 instruction, but we do know it'll be 42 greater than its original
205 If we then see an instruction like:
207 ahi r1, 22 # add halfword immediate 22 to r1
209 we still don't know what r1's value is, but again, we can say it is
210 now 64 greater than its original value.
212 If the next instruction were:
214 lr r2, r1 # set r2 to r1's value
216 then we can say that r2's value is now the original value of r1
219 Of course, this can only go so far before it gets unreasonable. If
220 we wanted to be able to say anything about the value of r1 after
223 xr r1, r3 # exclusive-or r1 and r3, place result in r1
225 then things would get pretty complex. But remember, we're just
226 doing a conservative approximation; if exclusive-or instructions
227 aren't relevant to prologues, we can just say r1's value is now
228 'unknown'. We can ignore things that are too complex, if that loss
229 of information is acceptable for our application.
231 Once you've reached an instruction that you don't know how to
232 simulate, you stop. Now you examine the state of the registers and
233 stack slots you've kept track of. For example:
235 - To see how large your stack frame is, just check the value of sp;
236 if it's the original value of sp minus a constant, then that
237 constant is the stack frame's size. If the sp's value has been
238 marked as 'unknown', then that means the prologue has done
239 something too complex for us to track, and we don't know the
242 - To see whether we've saved the SP in the current frame's back
243 chain slot, we just check whether the current value of the back
244 chain stack slot is the original value of the sp.
246 Sure, this takes some work. But prologue analyzers aren't
247 quick-and-simple pattern patching to recognize a few fixed prologue
248 forms any more; they're big, hairy functions. Along with inferior
249 function calls, prologue analysis accounts for a substantial
250 portion of the time needed to stabilize a GDB port. So I think
251 it's worthwhile to look for an approach that will be easier to
252 understand and maintain. In the approach used here:
254 - It's easier to see that the analyzer is correct: you just see
255 whether the analyzer properly (albiet conservatively) simulates
256 the effect of each instruction.
258 - It's easier to extend the analyzer: you can add support for new
259 instructions, and know that you haven't broken anything that
260 wasn't already broken before.
262 - It's orthogonal: to gather new information, you don't need to
263 complicate the code for each instruction. As long as your domain
264 of conservative values is already detailed enough to tell you
265 what you need, then all the existing instruction simulations are
266 already gathering the right data for you.
268 A 'struct prologue_value' is a conservative approximation of the
269 real value the register or stack slot will have. */
271 struct prologue_value
{
273 /* What sort of value is this? This determines the interpretation
274 of subsequent fields. */
277 /* We don't know anything about the value. This is also used for
278 values we could have kept track of, when doing so would have
279 been too complex and we don't want to bother. The bottom of
283 /* A known constant. K is its value. */
286 /* The value that register REG originally had *UPON ENTRY TO THE
287 FUNCTION*, plus K. If K is zero, this means, obviously, just
288 the value REG had upon entry to the function. REG is a GDB
289 register number. Before we start interpreting, we initialize
290 every register R to { pv_register, R, 0 }. */
295 /* The meanings of the following fields depend on 'kind'; see the
296 comments for the specific 'kind' values. */
302 /* Set V to be unknown. */
304 pv_set_to_unknown (struct prologue_value
*v
)
306 v
->kind
= pv_unknown
;
310 /* Set V to the constant K. */
312 pv_set_to_constant (struct prologue_value
*v
, CORE_ADDR k
)
314 v
->kind
= pv_constant
;
319 /* Set V to the original value of register REG, plus K. */
321 pv_set_to_register (struct prologue_value
*v
, int reg
, CORE_ADDR k
)
323 v
->kind
= pv_register
;
329 /* If one of *A and *B is a constant, and the other isn't, swap the
330 pointers as necessary to ensure that *B points to the constant.
331 This can reduce the number of cases we need to analyze in the
334 pv_constant_last (struct prologue_value
**a
,
335 struct prologue_value
**b
)
337 if ((*a
)->kind
== pv_constant
338 && (*b
)->kind
!= pv_constant
)
340 struct prologue_value
*temp
= *a
;
347 /* Set SUM to the sum of A and B. SUM, A, and B may point to the same
348 'struct prologue_value' object. */
350 pv_add (struct prologue_value
*sum
,
351 struct prologue_value
*a
,
352 struct prologue_value
*b
)
354 pv_constant_last (&a
, &b
);
356 /* We can handle adding constants to registers, and other constants. */
357 if (b
->kind
== pv_constant
358 && (a
->kind
== pv_register
359 || a
->kind
== pv_constant
))
362 sum
->reg
= a
->reg
; /* not meaningful if a is pv_constant, but
364 sum
->k
= a
->k
+ b
->k
;
367 /* Anything else we don't know how to add. We don't have a
368 representation for, say, the sum of two registers, or a multiple
369 of a register's value (adding a register to itself). */
371 sum
->kind
= pv_unknown
;
375 /* Add the constant K to V. */
377 pv_add_constant (struct prologue_value
*v
, CORE_ADDR k
)
379 struct prologue_value pv_k
;
381 /* Rather than thinking of all the cases we can and can't handle,
382 we'll just let pv_add take care of that for us. */
383 pv_set_to_constant (&pv_k
, k
);
384 pv_add (v
, v
, &pv_k
);
388 /* Subtract B from A, and put the result in DIFF.
390 This isn't quite the same as negating B and adding it to A, since
391 we don't have a representation for the negation of anything but a
392 constant. For example, we can't negate { pv_register, R1, 10 },
393 but we do know that { pv_register, R1, 10 } minus { pv_register,
394 R1, 5 } is { pv_constant, <ignored>, 5 }.
396 This means, for example, that we can subtract two stack addresses;
397 they're both relative to the original SP. Since the frame pointer
398 is set based on the SP, its value will be the original SP plus some
399 constant (probably zero), so we can use its value just fine. */
401 pv_subtract (struct prologue_value
*diff
,
402 struct prologue_value
*a
,
403 struct prologue_value
*b
)
405 pv_constant_last (&a
, &b
);
407 /* We can subtract a constant from another constant, or from a
409 if (b
->kind
== pv_constant
410 && (a
->kind
== pv_register
411 || a
->kind
== pv_constant
))
413 diff
->kind
= a
->kind
;
414 diff
->reg
= a
->reg
; /* not always meaningful, but harmless */
415 diff
->k
= a
->k
- b
->k
;
418 /* We can subtract a register from itself, yielding a constant. */
419 else if (a
->kind
== pv_register
420 && b
->kind
== pv_register
423 diff
->kind
= pv_constant
;
424 diff
->k
= a
->k
- b
->k
;
427 /* We don't know how to subtract anything else. */
429 diff
->kind
= pv_unknown
;
433 /* Set AND to the logical and of A and B. */
435 pv_logical_and (struct prologue_value
*and,
436 struct prologue_value
*a
,
437 struct prologue_value
*b
)
439 pv_constant_last (&a
, &b
);
441 /* We can 'and' two constants. */
442 if (a
->kind
== pv_constant
443 && b
->kind
== pv_constant
)
445 and->kind
= pv_constant
;
446 and->k
= a
->k
& b
->k
;
449 /* We can 'and' anything with the constant zero. */
450 else if (b
->kind
== pv_constant
453 and->kind
= pv_constant
;
457 /* We can 'and' anything with ~0. */
458 else if (b
->kind
== pv_constant
459 && b
->k
== ~ (CORE_ADDR
) 0)
462 /* We can 'and' a register with itself. */
463 else if (a
->kind
== pv_register
464 && b
->kind
== pv_register
469 /* Otherwise, we don't know. */
471 pv_set_to_unknown (and);
475 /* Return non-zero iff A and B are identical expressions.
477 This is not the same as asking if the two values are equal; the
478 result of such a comparison would have to be a pv_boolean, and
479 asking whether two 'unknown' values were equal would give you
480 pv_maybe. Same for comparing, say, { pv_register, R1, 0 } and {
481 pv_register, R2, 0}. Instead, this is asking whether the two
482 representations are the same. */
484 pv_is_identical (struct prologue_value
*a
,
485 struct prologue_value
*b
)
487 if (a
->kind
!= b
->kind
)
495 return (a
->k
== b
->k
);
497 return (a
->reg
== b
->reg
&& a
->k
== b
->k
);
504 /* Return non-zero if A is the original value of register number R
505 plus K, zero otherwise. */
507 pv_is_register (struct prologue_value
*a
, int r
, CORE_ADDR k
)
509 return (a
->kind
== pv_register
515 /* A prologue-value-esque boolean type, including "maybe", when we
516 can't figure out whether something is true or not. */
524 /* Decide whether a reference to SIZE bytes at ADDR refers exactly to
525 an element of an array. The array starts at ARRAY_ADDR, and has
526 ARRAY_LEN values of ELT_SIZE bytes each. If ADDR definitely does
527 refer to an array element, set *I to the index of the referenced
528 element in the array, and return pv_definite_yes. If it definitely
529 doesn't, return pv_definite_no. If we can't tell, return pv_maybe.
531 If the reference does touch the array, but doesn't fall exactly on
532 an element boundary, or doesn't refer to the whole element, return
534 static enum pv_boolean
535 pv_is_array_ref (struct prologue_value
*addr
,
537 struct prologue_value
*array_addr
,
542 struct prologue_value offset
;
544 /* Note that, since ->k is a CORE_ADDR, and CORE_ADDR is unsigned,
545 if addr is *before* the start of the array, then this isn't going
547 pv_subtract (&offset
, addr
, array_addr
);
549 if (offset
.kind
== pv_constant
)
551 /* This is a rather odd test. We want to know if the SIZE bytes
552 at ADDR don't overlap the array at all, so you'd expect it to
553 be an || expression: "if we're completely before || we're
554 completely after". But with unsigned arithmetic, things are
555 different: since it's a number circle, not a number line, the
556 right values for offset.k are actually one contiguous range. */
557 if (offset
.k
<= -size
558 && offset
.k
>= array_len
* elt_size
)
559 return pv_definite_no
;
560 else if (offset
.k
% elt_size
!= 0
565 *i
= offset
.k
/ elt_size
;
566 return pv_definite_yes
;
575 /* Decoding S/390 instructions. */
577 /* Named opcode values for the S/390 instructions we recognize. Some
578 instructions have their opcode split across two fields; those are the
579 op1_* and op2_* enums. */
582 op1_aghi
= 0xa7, op2_aghi
= 0xb,
583 op1_ahi
= 0xa7, op2_ahi
= 0xa,
586 op1_bras
= 0xa7, op2_bras
= 0x5,
589 op1_larl
= 0xc0, op2_larl
= 0x0,
591 op1_lghi
= 0xa7, op2_lghi
= 0x9,
592 op1_lhi
= 0xa7, op2_lhi
= 0x8,
599 op1_stg
= 0xe3, op2_stg
= 0x24,
601 op1_stmg
= 0xeb, op2_stmg
= 0x24,
606 /* The functions below are for recognizing and decoding S/390
607 instructions of various formats. Each of them checks whether INSN
608 is an instruction of the given format, with the specified opcodes.
609 If it is, it sets the remaining arguments to the values of the
610 instruction's fields, and returns a non-zero value; otherwise, it
613 These functions' arguments appear in the order they appear in the
614 instruction, not in the machine-language form. So, opcodes always
615 come first, even though they're sometimes scattered around the
616 instructions. And displacements appear before base and extension
617 registers, as they do in the assembly syntax, not at the end, as
618 they do in the machine language. */
620 is_ri (bfd_byte
*insn
, int op1
, int op2
, unsigned int *r1
, int *i2
)
622 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
624 *r1
= (insn
[1] >> 4) & 0xf;
625 /* i2 is a 16-bit signed quantity. */
626 *i2
= (((insn
[2] << 8) | insn
[3]) ^ 0x8000) - 0x8000;
635 is_ril (bfd_byte
*insn
, int op1
, int op2
,
636 unsigned int *r1
, int *i2
)
638 if (insn
[0] == op1
&& (insn
[1] & 0xf) == op2
)
640 *r1
= (insn
[1] >> 4) & 0xf;
641 /* i2 is a signed quantity. If the host 'int' is 32 bits long,
642 no sign extension is necessary, but we don't want to assume
644 *i2
= (((insn
[2] << 24)
647 | (insn
[5])) ^ 0x80000000) - 0x80000000;
656 is_rr (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
660 *r1
= (insn
[1] >> 4) & 0xf;
670 is_rre (bfd_byte
*insn
, int op
, unsigned int *r1
, unsigned int *r2
)
672 if (((insn
[0] << 8) | insn
[1]) == op
)
674 /* Yes, insn[3]. insn[2] is unused in RRE format. */
675 *r1
= (insn
[3] >> 4) & 0xf;
685 is_rs (bfd_byte
*insn
, int op
,
686 unsigned int *r1
, unsigned int *r3
, unsigned int *d2
, unsigned int *b2
)
690 *r1
= (insn
[1] >> 4) & 0xf;
692 *b2
= (insn
[2] >> 4) & 0xf;
693 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
702 is_rse (bfd_byte
*insn
, int op1
, int op2
,
703 unsigned int *r1
, unsigned int *r3
, unsigned int *d2
, unsigned int *b2
)
706 /* Yes, insn[5]. insn[4] is unused. */
709 *r1
= (insn
[1] >> 4) & 0xf;
711 *b2
= (insn
[2] >> 4) & 0xf;
712 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
721 is_rx (bfd_byte
*insn
, int op
,
722 unsigned int *r1
, unsigned int *d2
, unsigned int *x2
, unsigned int *b2
)
726 *r1
= (insn
[1] >> 4) & 0xf;
728 *b2
= (insn
[2] >> 4) & 0xf;
729 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
738 is_rxe (bfd_byte
*insn
, int op1
, int op2
,
739 unsigned int *r1
, unsigned int *d2
, unsigned int *x2
, unsigned int *b2
)
742 /* Yes, insn[5]. insn[4] is unused. */
745 *r1
= (insn
[1] >> 4) & 0xf;
747 *b2
= (insn
[2] >> 4) & 0xf;
748 *d2
= ((insn
[2] & 0xf) << 8) | insn
[3];
756 /* Set ADDR to the effective address for an X-style instruction, like:
760 Here, X2 and B2 are registers, and D2 is an unsigned 12-bit
761 constant; the effective address is the sum of all three. If either
762 X2 or B2 are zero, then it doesn't contribute to the sum --- this
763 means that r0 can't be used as either X2 or B2.
765 GPR is an array of general register values, indexed by GPR number,
766 not GDB register number. */
768 compute_x_addr (struct prologue_value
*addr
,
769 struct prologue_value
*gpr
,
770 unsigned int d2
, unsigned int x2
, unsigned int b2
)
772 /* We can't just add stuff directly in addr; it might alias some of
773 the registers we need to read. */
774 struct prologue_value result
;
776 pv_set_to_constant (&result
, d2
);
778 pv_add (&result
, &result
, &gpr
[x2
]);
780 pv_add (&result
, &result
, &gpr
[b2
]);
786 /* The number of GPR and FPR spill slots in an S/390 stack frame. We
787 track general-purpose registers r2 -- r15, and floating-point
788 registers f0, f2, f4, and f6. */
789 #define S390_NUM_SPILL_SLOTS (14 + 4)
792 /* If the SIZE bytes at ADDR are a stack slot we're actually tracking,
793 return pv_definite_yes and set *STACK to point to the slot. If
794 we're sure that they are not any of our stack slots, then return
795 pv_definite_no. Otherwise, return pv_maybe.
796 - GPR is an array indexed by GPR number giving the current values
797 of the general-purpose registers.
798 - SPILL is an array tracking the spill area of the caller's frame;
799 SPILL[i] is the i'th spill slot. The spill slots are designated
800 for r2 -- r15, and then f0, f2, f4, and f6.
801 - BACK_CHAIN is the value of the back chain slot; it's only valid
802 when the current frame actually has some space for a back chain
803 slot --- that is, when the current value of the stack pointer
804 (according to GPR) is at least S390_STACK_FRAME_OVERHEAD bytes
805 less than its original value. */
806 static enum pv_boolean
807 s390_on_stack (struct prologue_value
*addr
,
809 struct prologue_value
*gpr
,
810 struct prologue_value
*spill
,
811 struct prologue_value
*back_chain
,
812 struct prologue_value
**stack
)
814 struct prologue_value gpr_spill_addr
;
815 struct prologue_value fpr_spill_addr
;
816 struct prologue_value back_chain_addr
;
820 /* Construct the addresses of the spill arrays and the back chain. */
821 pv_set_to_register (&gpr_spill_addr
, S390_SP_REGNUM
, 2 * S390_GPR_SIZE
);
822 pv_set_to_register (&fpr_spill_addr
, S390_SP_REGNUM
, 16 * S390_GPR_SIZE
);
823 back_chain_addr
= gpr
[S390_SP_REGNUM
- S390_GP0_REGNUM
];
825 /* We have to check for GPR and FPR references using two separate
826 calls to pv_is_array_ref, since the GPR and FPR spill slots are
827 different sizes. (SPILL is an array, but the thing it tracks
828 isn't really an array.) */
830 /* Was it a reference to the GPR spill array? */
831 b
= pv_is_array_ref (addr
, size
, &gpr_spill_addr
, 14, S390_GPR_SIZE
, &i
);
832 if (b
== pv_definite_yes
)
835 return pv_definite_yes
;
840 /* Was it a reference to the FPR spill array? */
841 b
= pv_is_array_ref (addr
, size
, &fpr_spill_addr
, 4, S390_FPR_SIZE
, &i
);
842 if (b
== pv_definite_yes
)
844 *stack
= &spill
[14 + i
];
845 return pv_definite_yes
;
850 /* Was it a reference to the back chain?
851 This isn't quite right. We ought to check whether we have
852 actually allocated any new frame at all. */
853 b
= pv_is_array_ref (addr
, size
, &back_chain_addr
, 1, S390_GPR_SIZE
, &i
);
854 if (b
== pv_definite_yes
)
857 return pv_definite_yes
;
862 /* All the above queries returned definite 'no's. */
863 return pv_definite_no
;
867 /* Do a SIZE-byte store of VALUE to ADDR. GPR, SPILL, and BACK_CHAIN,
868 and the return value are as described for s390_on_stack, above.
869 Note that, when this returns pv_maybe, we have to assume that all
870 of our memory now contains unknown values. */
871 static enum pv_boolean
872 s390_store (struct prologue_value
*addr
,
874 struct prologue_value
*value
,
875 struct prologue_value
*gpr
,
876 struct prologue_value
*spill
,
877 struct prologue_value
*back_chain
)
879 struct prologue_value
*stack
;
880 enum pv_boolean on_stack
881 = s390_on_stack (addr
, size
, gpr
, spill
, back_chain
, &stack
);
883 if (on_stack
== pv_definite_yes
)
890 /* The current frame looks like a signal delivery frame: the first
891 instruction is an 'svc' opcode. If the next frame is a signal
892 handler's frame, set FI's saved register map to point into the
893 signal context structure. */
895 s390_get_signal_frame_info (struct frame_info
*fi
)
897 struct frame_info
*next_frame
= get_next_frame (fi
);
900 && get_frame_extra_info (next_frame
)
901 && get_frame_extra_info (next_frame
)->sigcontext
)
903 /* We're definitely backtracing from a signal handler. */
904 CORE_ADDR
*saved_regs
= deprecated_get_frame_saved_regs (fi
);
905 CORE_ADDR save_reg_addr
= (get_frame_extra_info (next_frame
)->sigcontext
906 + DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM
));
909 for (reg
= 0; reg
< S390_NUM_GPRS
; reg
++)
911 saved_regs
[S390_GP0_REGNUM
+ reg
] = save_reg_addr
;
912 save_reg_addr
+= S390_GPR_SIZE
;
915 save_reg_addr
= (get_frame_extra_info (next_frame
)->sigcontext
916 + (GDB_TARGET_IS_ESAME
? S390X_SIGREGS_FP0_OFFSET
:
917 S390_SIGREGS_FP0_OFFSET
));
918 for (reg
= 0; reg
< S390_NUM_FPRS
; reg
++)
920 saved_regs
[S390_FP0_REGNUM
+ reg
] = save_reg_addr
;
921 save_reg_addr
+= S390_FPR_SIZE
;
928 s390_get_frame_info (CORE_ADDR start_pc
,
929 struct frame_extra_info
*fextra_info
,
930 struct frame_info
*fi
,
934 zero if we were able to read all the instructions we wanted, or
935 -1 if we got an error trying to read memory. */
938 /* The current PC for our abstract interpretation. */
941 /* The address of the next instruction after that. */
944 /* The general-purpose registers. */
945 struct prologue_value gpr
[S390_NUM_GPRS
];
947 /* The floating-point registers. */
948 struct prologue_value fpr
[S390_NUM_FPRS
];
950 /* The register spill stack slots in the caller's frame ---
951 general-purpose registers r2 through r15, and floating-point
952 registers. spill[i] is where gpr i+2 gets spilled;
953 spill[(14, 15, 16, 17)] is where (f0, f2, f4, f6) get spilled. */
954 struct prologue_value spill
[S390_NUM_SPILL_SLOTS
];
956 /* The value of the back chain slot. This is only valid if the stack
957 pointer is known to be less than its original value --- that is,
958 if we have indeed allocated space on the stack. */
959 struct prologue_value back_chain
;
961 /* The address of the instruction after the last one that changed
962 the SP, FP, or back chain. */
963 CORE_ADDR after_last_frame_setup_insn
= start_pc
;
965 /* Set up everything's initial value. */
969 for (i
= 0; i
< S390_NUM_GPRS
; i
++)
970 pv_set_to_register (&gpr
[i
], S390_GP0_REGNUM
+ i
, 0);
972 for (i
= 0; i
< S390_NUM_FPRS
; i
++)
973 pv_set_to_register (&fpr
[i
], S390_FP0_REGNUM
+ i
, 0);
975 for (i
= 0; i
< S390_NUM_SPILL_SLOTS
; i
++)
976 pv_set_to_unknown (&spill
[i
]);
978 pv_set_to_unknown (&back_chain
);
981 /* Start interpreting instructions, until we hit something we don't
982 know how to interpret. (Ideally, we should stop at the frame's
983 real current PC, but at the moment, our callers don't give us
985 for (pc
= start_pc
; ; pc
= next_pc
)
987 bfd_byte insn
[S390_MAX_INSTR_SIZE
];
988 int insn_len
= s390_readinstruction (insn
, pc
);
990 /* Fields for various kinds of instructions. */
991 unsigned int b2
, r1
, r2
, d2
, x2
, r3
;
994 /* The values of SP, FP, and back chain before this instruction,
995 for detecting instructions that change them. */
996 struct prologue_value pre_insn_sp
, pre_insn_fp
, pre_insn_back_chain
;
998 /* If we got an error trying to read the instruction, report it. */
1005 next_pc
= pc
+ insn_len
;
1007 pre_insn_sp
= gpr
[S390_SP_REGNUM
- S390_GP0_REGNUM
];
1008 pre_insn_fp
= gpr
[S390_FRAME_REGNUM
- S390_GP0_REGNUM
];
1009 pre_insn_back_chain
= back_chain
;
1011 /* A special case, first --- only recognized as the very first
1012 instruction of the function, for signal delivery frames:
1013 SVC i --- system call */
1015 && is_rr (insn
, op_svc
, &r1
, &r2
))
1018 s390_get_signal_frame_info (fi
);
1022 /* AHI r1, i2 --- add halfword immediate */
1023 else if (is_ri (insn
, op1_ahi
, op2_ahi
, &r1
, &i2
))
1024 pv_add_constant (&gpr
[r1
], i2
);
1027 /* AGHI r1, i2 --- add halfword immediate (64-bit version) */
1028 else if (GDB_TARGET_IS_ESAME
1029 && is_ri (insn
, op1_aghi
, op2_aghi
, &r1
, &i2
))
1030 pv_add_constant (&gpr
[r1
], i2
);
1032 /* AR r1, r2 -- add register */
1033 else if (is_rr (insn
, op_ar
, &r1
, &r2
))
1034 pv_add (&gpr
[r1
], &gpr
[r1
], &gpr
[r2
]);
1036 /* BASR r1, 0 --- branch and save
1037 Since r2 is zero, this saves the PC in r1, but doesn't branch. */
1038 else if (is_rr (insn
, op_basr
, &r1
, &r2
)
1040 pv_set_to_constant (&gpr
[r1
], next_pc
);
1042 /* BRAS r1, i2 --- branch relative and save */
1043 else if (is_ri (insn
, op1_bras
, op2_bras
, &r1
, &i2
))
1045 pv_set_to_constant (&gpr
[r1
], next_pc
);
1046 next_pc
= pc
+ i2
* 2;
1048 /* We'd better not interpret any backward branches. We'll
1054 /* L r1, d2(x2, b2) --- load */
1055 else if (is_rx (insn
, op_l
, &r1
, &d2
, &x2
, &b2
))
1057 struct prologue_value addr
;
1058 struct prologue_value
*stack
;
1060 compute_x_addr (&addr
, gpr
, d2
, x2
, b2
);
1062 /* If it's a load from an in-line constant pool, then we can
1063 simulate that, under the assumption that the code isn't
1064 going to change between the time the processor actually
1065 executed it creating the current frame, and the time when
1066 we're analyzing the code to unwind past that frame. */
1067 if (addr
.kind
== pv_constant
1068 && start_pc
<= addr
.k
1069 && addr
.k
< next_pc
)
1070 pv_set_to_constant (&gpr
[r1
],
1071 read_memory_integer (addr
.k
, 4));
1073 /* If it's definitely a reference to something on the stack,
1075 else if (s390_on_stack (&addr
, 4, gpr
, spill
, &back_chain
, &stack
)
1079 /* Otherwise, we don't know the value. */
1081 pv_set_to_unknown (&gpr
[r1
]);
1084 /* LA r1, d2(x2, b2) --- load address */
1085 else if (is_rx (insn
, op_la
, &r1
, &d2
, &x2
, &b2
))
1086 compute_x_addr (&gpr
[r1
], gpr
, d2
, x2
, b2
);
1088 /* LARL r1, i2 --- load address relative long */
1089 else if (GDB_TARGET_IS_ESAME
1090 && is_ril (insn
, op1_larl
, op2_larl
, &r1
, &i2
))
1091 pv_set_to_constant (&gpr
[r1
], pc
+ i2
* 2);
1093 /* LGR r1, r2 --- load from register */
1094 else if (GDB_TARGET_IS_ESAME
1095 && is_rre (insn
, op_lgr
, &r1
, &r2
))
1098 /* LHI r1, i2 --- load halfword immediate */
1099 else if (is_ri (insn
, op1_lhi
, op2_lhi
, &r1
, &i2
))
1100 pv_set_to_constant (&gpr
[r1
], i2
);
1102 /* LGHI r1, i2 --- load halfword immediate --- 64-bit version */
1103 else if (is_ri (insn
, op1_lghi
, op2_lghi
, &r1
, &i2
))
1104 pv_set_to_constant (&gpr
[r1
], i2
);
1106 /* LR r1, r2 --- load from register */
1107 else if (is_rr (insn
, op_lr
, &r1
, &r2
))
1110 /* NGR r1, r2 --- logical and --- 64-bit version */
1111 else if (GDB_TARGET_IS_ESAME
1112 && is_rre (insn
, op_ngr
, &r1
, &r2
))
1113 pv_logical_and (&gpr
[r1
], &gpr
[r1
], &gpr
[r2
]);
1115 /* NR r1, r2 --- logical and */
1116 else if (is_rr (insn
, op_nr
, &r1
, &r2
))
1117 pv_logical_and (&gpr
[r1
], &gpr
[r1
], &gpr
[r2
]);
1119 /* NGR r1, r2 --- logical and --- 64-bit version */
1120 else if (GDB_TARGET_IS_ESAME
1121 && is_rre (insn
, op_ngr
, &r1
, &r2
))
1122 pv_logical_and (&gpr
[r1
], &gpr
[r1
], &gpr
[r2
]);
1124 /* NR r1, r2 --- logical and */
1125 else if (is_rr (insn
, op_nr
, &r1
, &r2
))
1126 pv_logical_and (&gpr
[r1
], &gpr
[r1
], &gpr
[r2
]);
1128 /* S r1, d2(x2, b2) --- subtract from memory */
1129 else if (is_rx (insn
, op_s
, &r1
, &d2
, &x2
, &b2
))
1131 struct prologue_value addr
;
1132 struct prologue_value value
;
1133 struct prologue_value
*stack
;
1135 compute_x_addr (&addr
, gpr
, d2
, x2
, b2
);
1137 /* If it's a load from an in-line constant pool, then we can
1138 simulate that, under the assumption that the code isn't
1139 going to change between the time the processor actually
1140 executed it and the time when we're analyzing it. */
1141 if (addr
.kind
== pv_constant
1142 && start_pc
<= addr
.k
1144 pv_set_to_constant (&value
, read_memory_integer (addr
.k
, 4));
1146 /* If it's definitely a reference to something on the stack,
1147 we could do that. */
1148 else if (s390_on_stack (&addr
, 4, gpr
, spill
, &back_chain
, &stack
)
1152 /* Otherwise, we don't know the value. */
1154 pv_set_to_unknown (&value
);
1156 pv_subtract (&gpr
[r1
], &gpr
[r1
], &value
);
1159 /* ST r1, d2(x2, b2) --- store */
1160 else if (is_rx (insn
, op_st
, &r1
, &d2
, &x2
, &b2
))
1162 struct prologue_value addr
;
1164 compute_x_addr (&addr
, gpr
, d2
, x2
, b2
);
1166 /* The below really should be '4', not 'S390_GPR_SIZE'; this
1167 instruction always stores 32 bits, regardless of the full
1169 if (s390_store (&addr
, 4, &gpr
[r1
], gpr
, spill
, &back_chain
)
1171 /* If we can't be sure that it's *not* a store to
1172 something we're tracing, then we would have to mark all
1173 our memory as unknown --- after all, it *could* be a
1174 store to any of them --- so we might as well just stop
1179 /* STD r1, d2(x2,b2) --- store floating-point register */
1180 else if (is_rx (insn
, op_std
, &r1
, &d2
, &x2
, &b2
))
1182 struct prologue_value addr
;
1184 compute_x_addr (&addr
, gpr
, d2
, x2
, b2
);
1186 if (s390_store (&addr
, 8, &fpr
[r1
], gpr
, spill
, &back_chain
)
1188 /* If we can't be sure that it's *not* a store to
1189 something we're tracing, then we would have to mark all
1190 our memory as unknown --- after all, it *could* be a
1191 store to any of them --- so we might as well just stop
1196 /* STG r1, d2(x2, b2) --- 64-bit store */
1197 else if (GDB_TARGET_IS_ESAME
1198 && is_rxe (insn
, op1_stg
, op2_stg
, &r1
, &d2
, &x2
, &b2
))
1200 struct prologue_value addr
;
1202 compute_x_addr (&addr
, gpr
, d2
, x2
, b2
);
1204 /* The below really should be '8', not 'S390_GPR_SIZE'; this
1205 instruction always stores 64 bits, regardless of the full
1207 if (s390_store (&addr
, 8, &gpr
[r1
], gpr
, spill
, &back_chain
)
1209 /* If we can't be sure that it's *not* a store to
1210 something we're tracing, then we would have to mark all
1211 our memory as unknown --- after all, it *could* be a
1212 store to any of them --- so we might as well just stop
1217 /* STM r1, r3, d2(b2) --- store multiple */
1218 else if (is_rs (insn
, op_stm
, &r1
, &r3
, &d2
, &b2
))
1222 struct prologue_value addr
;
1224 for (regnum
= r1
, offset
= 0;
1226 regnum
++, offset
+= 4)
1228 compute_x_addr (&addr
, gpr
, d2
+ offset
, 0, b2
);
1230 if (s390_store (&addr
, 4, &gpr
[regnum
], gpr
, spill
, &back_chain
)
1232 /* If we can't be sure that it's *not* a store to
1233 something we're tracing, then we would have to mark all
1234 our memory as unknown --- after all, it *could* be a
1235 store to any of them --- so we might as well just stop
1240 /* If we left the loop early, we should stop interpreting
1246 /* STMG r1, r3, d2(b2) --- store multiple, 64-bit */
1247 else if (GDB_TARGET_IS_ESAME
1248 && is_rse (insn
, op1_stmg
, op2_stmg
, &r1
, &r3
, &d2
, &b2
))
1252 struct prologue_value addr
;
1254 for (regnum
= r1
, offset
= 0;
1256 regnum
++, offset
+= 8)
1258 compute_x_addr (&addr
, gpr
, d2
+ offset
, 0, b2
);
1260 if (s390_store (&addr
, 8, &gpr
[regnum
], gpr
, spill
, &back_chain
)
1262 /* If we can't be sure that it's *not* a store to
1263 something we're tracing, then we would have to mark all
1264 our memory as unknown --- after all, it *could* be a
1265 store to any of them --- so we might as well just stop
1270 /* If we left the loop early, we should stop interpreting
1277 /* An instruction we don't know how to simulate. The only
1278 safe thing to do would be to set every value we're tracking
1279 to 'unknown'. Instead, we'll be optimistic: we just stop
1280 interpreting, and assume that the machine state we've got
1281 now is good enough for unwinding the stack. */
1284 /* Record the address after the last instruction that changed
1285 the FP, SP, or backlink. Ignore instructions that changed
1286 them back to their original values --- those are probably
1287 restore instructions. (The back chain is never restored,
1290 struct prologue_value
*sp
= &gpr
[S390_SP_REGNUM
- S390_GP0_REGNUM
];
1291 struct prologue_value
*fp
= &gpr
[S390_FRAME_REGNUM
- S390_GP0_REGNUM
];
1293 if ((! pv_is_identical (&pre_insn_sp
, sp
)
1294 && ! pv_is_register (sp
, S390_SP_REGNUM
, 0))
1295 || (! pv_is_identical (&pre_insn_fp
, fp
)
1296 && ! pv_is_register (fp
, S390_FRAME_REGNUM
, 0))
1297 || ! pv_is_identical (&pre_insn_back_chain
, &back_chain
))
1298 after_last_frame_setup_insn
= next_pc
;
1302 /* Okay, now gpr[], fpr[], spill[], and back_chain reflect the state
1303 of the machine as of the first instruction we couldn't interpret
1304 (hopefully the first non-prologue instruction). */
1306 /* The size of the frame, or (CORE_ADDR) -1 if we couldn't figure
1308 CORE_ADDR frame_size
= -1;
1310 /* The value the SP had upon entry to the function, or
1311 (CORE_ADDR) -1 if we can't figure that out. */
1312 CORE_ADDR original_sp
= -1;
1314 /* Are we using S390_FRAME_REGNUM as a frame pointer register? */
1315 int using_frame_pointer
= 0;
1317 /* If S390_FRAME_REGNUM is some constant offset from the SP, then
1318 that strongly suggests that we're going to use that as our
1319 frame pointer register, not the SP. */
1321 struct prologue_value
*fp
= &gpr
[S390_FRAME_REGNUM
- S390_GP0_REGNUM
];
1323 if (fp
->kind
== pv_register
1324 && fp
->reg
== S390_SP_REGNUM
)
1325 using_frame_pointer
= 1;
1328 /* If we were given a frame_info structure, we may be able to use
1329 the frame's base address to figure out the actual value of the
1331 if (fi
&& get_frame_base (fi
))
1333 int frame_base_regno
;
1334 struct prologue_value
*frame_base
;
1336 /* The meaning of the frame base depends on whether the
1337 function uses a frame pointer register other than the SP or
1338 not (see s390_read_fp):
1339 - If the function does use a frame pointer register other
1340 than the SP, then the frame base is that register's
1342 - If the function doesn't use a frame pointer, then the
1343 frame base is the SP itself.
1344 We're duplicating some of the logic of s390_fp_regnum here,
1345 but we don't want to call that, because it would just do
1346 exactly the same analysis we've already done above. */
1347 if (using_frame_pointer
)
1348 frame_base_regno
= S390_FRAME_REGNUM
;
1350 frame_base_regno
= S390_SP_REGNUM
;
1352 frame_base
= &gpr
[frame_base_regno
- S390_GP0_REGNUM
];
1354 /* We know the frame base address; if the value of whatever
1355 register it came from is a constant offset from the
1356 original SP, then we can reconstruct the original SP just
1357 by subtracting off that constant. */
1358 if (frame_base
->kind
== pv_register
1359 && frame_base
->reg
== S390_SP_REGNUM
)
1360 original_sp
= get_frame_base (fi
) - frame_base
->k
;
1363 /* If the analysis said that the current SP value is the original
1364 value less some constant, then that constant is the frame size. */
1366 struct prologue_value
*sp
= &gpr
[S390_SP_REGNUM
- S390_GP0_REGNUM
];
1368 if (sp
->kind
== pv_register
1369 && sp
->reg
== S390_SP_REGNUM
)
1370 frame_size
= -sp
->k
;
1373 /* If we knew other registers' current values, we could check if
1374 the analysis said any of those were related to the original SP
1375 value, too. But for now, we'll just punt. */
1377 /* If the caller passed in an 'extra info' structure, fill in the
1381 if (init_extra_info
|| ! fextra_info
->initialised
)
1383 s390_memset_extra_info (fextra_info
);
1384 fextra_info
->function_start
= start_pc
;
1385 fextra_info
->initialised
= 1;
1388 if (frame_size
!= -1)
1390 fextra_info
->stack_bought_valid
= 1;
1391 fextra_info
->stack_bought
= frame_size
;
1394 /* Assume everything was okay, and indicate otherwise when we
1395 find something amiss. */
1396 fextra_info
->good_prologue
= 1;
1398 if (using_frame_pointer
)
1399 /* Actually, nobody cares about the exact PC, so any
1400 non-zero value will do here. */
1401 fextra_info
->frame_pointer_saved_pc
= 1;
1403 /* If we weren't able to find the size of the frame, or find
1404 the original sp based on actual current register values,
1405 then we're not going to be able to unwind this frame.
1407 (If we're just doing prologue analysis to set a breakpoint,
1408 then frame_size might be known, but original_sp unknown; if
1409 we're analyzing a real frame which uses alloca, then
1410 original_sp might be known (from the frame pointer
1411 register), but the frame size might be unknown.) */
1412 if (original_sp
== -1 && frame_size
== -1)
1413 fextra_info
->good_prologue
= 0;
1415 if (fextra_info
->good_prologue
)
1416 fextra_info
->skip_prologue_function_start
1417 = after_last_frame_setup_insn
;
1419 /* If the prologue was too complex for us to make sense of,
1420 then perhaps it's better to just not skip anything at
1422 fextra_info
->skip_prologue_function_start
= start_pc
;
1425 /* Indicate where registers were saved on the stack, if:
1426 - the caller seems to want to know,
1427 - the caller provided an actual SP, and
1428 - the analysis gave us enough information to actually figure it
1431 && deprecated_get_frame_saved_regs (fi
)
1432 && original_sp
!= -1)
1435 CORE_ADDR slot_addr
;
1436 CORE_ADDR
*saved_regs
= deprecated_get_frame_saved_regs (fi
);
1438 /* Scan the spill array; if a spill slot says it holds the
1439 original value of some register, then record that slot's
1440 address as the place that register was saved.
1442 Just for kicks, note that, even if registers aren't saved
1443 in their officially-sanctioned slots, this will still work
1444 --- we know what really got put where. */
1446 /* First, the slots for r2 -- r15. */
1447 for (slot_num
= 0, slot_addr
= original_sp
+ 2 * S390_GPR_SIZE
;
1449 slot_num
++, slot_addr
+= S390_GPR_SIZE
)
1451 struct prologue_value
*slot
= &spill
[slot_num
];
1453 if (slot
->kind
== pv_register
1455 saved_regs
[slot
->reg
] = slot_addr
;
1458 /* Then, the slots for f0, f2, f4, and f6. They're a
1460 for (slot_num
= 14, slot_addr
= original_sp
+ 16 * S390_GPR_SIZE
;
1461 slot_num
< S390_NUM_SPILL_SLOTS
;
1462 slot_num
++, slot_addr
+= S390_FPR_SIZE
)
1464 struct prologue_value
*slot
= &spill
[slot_num
];
1466 if (slot
->kind
== pv_register
1468 saved_regs
[slot
->reg
] = slot_addr
;
1471 /* The stack pointer's element of saved_regs[] is special. */
1472 saved_regs
[S390_SP_REGNUM
] = original_sp
;
1481 s390_check_function_end (CORE_ADDR pc
)
1483 bfd_byte instr
[S390_MAX_INSTR_SIZE
];
1484 int regidx
, instrlen
;
1486 instrlen
= s390_readinstruction (instr
, pc
);
1490 if (instrlen
!= 2 || instr
[0] != 07 || (instr
[1] >> 4) != 0xf)
1492 regidx
= instr
[1] & 0xf;
1493 /* Check for LMG or LG */
1495 s390_readinstruction (instr
, pc
- (GDB_TARGET_IS_ESAME
? 6 : 4));
1498 if (GDB_TARGET_IS_ESAME
)
1501 if (instrlen
!= 6 || instr
[0] != 0xeb || instr
[5] != 0x4)
1504 else if (instrlen
!= 4 || instr
[0] != 0x98)
1508 if ((instr
[2] >> 4) != 0xf)
1512 instrlen
= s390_readinstruction (instr
, pc
- (GDB_TARGET_IS_ESAME
? 12 : 8));
1515 if (GDB_TARGET_IS_ESAME
)
1518 if (instrlen
!= 6 || instr
[0] != 0xe3 || instr
[5] != 0x4)
1524 if (instrlen
!= 4 || instr
[0] != 0x58)
1527 if (instr
[2] >> 4 != 0xf)
1529 if (instr
[1] >> 4 != regidx
)
1535 s390_sniff_pc_function_start (CORE_ADDR pc
, struct frame_info
*fi
)
1537 CORE_ADDR function_start
, test_function_start
;
1538 int loop_cnt
, err
, function_end
;
1539 struct frame_extra_info fextra_info
;
1540 function_start
= get_pc_function_start (pc
);
1542 if (function_start
== 0)
1544 test_function_start
= pc
;
1545 if (test_function_start
& 1)
1546 return 0; /* This has to be bogus */
1552 s390_get_frame_info (test_function_start
, &fextra_info
, fi
, 1);
1554 test_function_start
-= 2;
1555 function_end
= s390_check_function_end (test_function_start
);
1557 while (!(function_end
== 1 || err
|| loop_cnt
>= 4096 ||
1558 (fextra_info
.good_prologue
)));
1559 if (fextra_info
.good_prologue
)
1560 function_start
= fextra_info
.function_start
;
1561 else if (function_end
== 1)
1562 function_start
= test_function_start
;
1564 return function_start
;
1569 s390_frameless_function_invocation (struct frame_info
*fi
)
1571 struct frame_extra_info fextra_info
, *fextra_info_ptr
;
1574 if (get_next_frame (fi
) == NULL
) /* no may be frameless */
1576 if (get_frame_extra_info (fi
))
1577 fextra_info_ptr
= get_frame_extra_info (fi
);
1580 fextra_info_ptr
= &fextra_info
;
1581 s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi
), fi
),
1582 fextra_info_ptr
, fi
, 1);
1584 frameless
= (fextra_info_ptr
->stack_bought_valid
1585 && fextra_info_ptr
->stack_bought
== 0);
1593 s390_is_sigreturn (CORE_ADDR pc
, struct frame_info
*sighandler_fi
,
1594 CORE_ADDR
*sregs
, CORE_ADDR
*sigcaller_pc
)
1596 bfd_byte instr
[S390_MAX_INSTR_SIZE
];
1601 CORE_ADDR temp_sregs
;
1603 scontext
= temp_sregs
= 0;
1605 instrlen
= s390_readinstruction (instr
, pc
);
1608 if (((instrlen
== S390_SYSCALL_SIZE
) &&
1609 (instr
[0] == S390_SYSCALL_OPCODE
)) &&
1610 ((instr
[1] == s390_NR_sigreturn
) || (instr
[1] == s390_NR_rt_sigreturn
)))
1614 if (s390_frameless_function_invocation (sighandler_fi
))
1615 orig_sp
= get_frame_base (sighandler_fi
);
1617 orig_sp
= ADDR_BITS_REMOVE ((CORE_ADDR
)
1618 read_memory_integer (get_frame_base (sighandler_fi
),
1620 if (orig_sp
&& sigcaller_pc
)
1622 scontext
= orig_sp
+ S390_SIGNAL_FRAMESIZE
;
1623 if (pc
== scontext
&& instr
[1] == s390_NR_rt_sigreturn
)
1625 /* We got a new style rt_signal */
1626 /* get address of read ucontext->uc_mcontext */
1627 temp_sregs
= orig_sp
+ (GDB_TARGET_IS_ESAME
?
1628 S390X_UC_MCONTEXT_OFFSET
:
1629 S390_UC_MCONTEXT_OFFSET
);
1633 /* read sigcontext->sregs */
1634 temp_sregs
= ADDR_BITS_REMOVE ((CORE_ADDR
)
1635 read_memory_integer (scontext
1637 (GDB_TARGET_IS_ESAME
1639 S390X_SIGCONTEXT_SREGS_OFFSET
1641 S390_SIGCONTEXT_SREGS_OFFSET
),
1645 /* read sigregs->psw.addr */
1647 ADDR_BITS_REMOVE ((CORE_ADDR
)
1648 read_memory_integer (temp_sregs
+
1649 DEPRECATED_REGISTER_BYTE (S390_PC_REGNUM
),
1650 S390_PSW_ADDR_SIZE
));
1656 *sregs
= temp_sregs
;
1661 We need to do something better here but this will keep us out of trouble
1663 For some reason the blockframe.c calls us with fi->next->fromleaf
1664 so this seems of little use to us. */
1666 s390_init_frame_pc_first (int next_fromleaf
, struct frame_info
*fi
)
1668 CORE_ADDR sigcaller_pc
;
1672 pc
= ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM
));
1673 /* fix signal handlers */
1675 else if (get_next_frame (fi
) && get_frame_pc (get_next_frame (fi
)))
1676 pc
= s390_frame_saved_pc_nofix (get_next_frame (fi
));
1677 if (pc
&& get_next_frame (fi
) && get_frame_base (get_next_frame (fi
))
1678 && s390_is_sigreturn (pc
, get_next_frame (fi
), NULL
, &sigcaller_pc
))
1686 s390_init_extra_frame_info (int fromleaf
, struct frame_info
*fi
)
1688 frame_extra_info_zalloc (fi
, sizeof (struct frame_extra_info
));
1689 if (get_frame_pc (fi
))
1690 s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi
), fi
),
1691 get_frame_extra_info (fi
), fi
, 1);
1693 s390_memset_extra_info (get_frame_extra_info (fi
));
1696 /* If saved registers of frame FI are not known yet, read and cache them.
1697 &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL,
1698 in which case the framedata are read. */
1701 s390_frame_init_saved_regs (struct frame_info
*fi
)
1706 if (deprecated_get_frame_saved_regs (fi
) == NULL
)
1708 /* zalloc memsets the saved regs */
1709 frame_saved_regs_zalloc (fi
);
1710 if (get_frame_pc (fi
))
1712 quick
= (get_frame_extra_info (fi
)
1713 && get_frame_extra_info (fi
)->initialised
1714 && get_frame_extra_info (fi
)->good_prologue
);
1715 s390_get_frame_info (quick
1716 ? get_frame_extra_info (fi
)->function_start
1717 : s390_sniff_pc_function_start (get_frame_pc (fi
), fi
),
1718 get_frame_extra_info (fi
), fi
, !quick
);
1726 s390_frame_saved_pc_nofix (struct frame_info
*fi
)
1728 if (get_frame_extra_info (fi
) && get_frame_extra_info (fi
)->saved_pc_valid
)
1729 return get_frame_extra_info (fi
)->saved_pc
;
1731 if (deprecated_generic_find_dummy_frame (get_frame_pc (fi
),
1732 get_frame_base (fi
)))
1733 return deprecated_read_register_dummy (get_frame_pc (fi
),
1734 get_frame_base (fi
), S390_PC_REGNUM
);
1736 s390_frame_init_saved_regs (fi
);
1737 if (get_frame_extra_info (fi
))
1739 get_frame_extra_info (fi
)->saved_pc_valid
= 1;
1740 if (get_frame_extra_info (fi
)->good_prologue
1741 && deprecated_get_frame_saved_regs (fi
)[S390_RETADDR_REGNUM
])
1742 get_frame_extra_info (fi
)->saved_pc
1743 = ADDR_BITS_REMOVE (read_memory_integer
1744 (deprecated_get_frame_saved_regs (fi
)[S390_RETADDR_REGNUM
],
1747 get_frame_extra_info (fi
)->saved_pc
1748 = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM
));
1749 return get_frame_extra_info (fi
)->saved_pc
;
1755 s390_frame_saved_pc (struct frame_info
*fi
)
1757 CORE_ADDR saved_pc
= 0, sig_pc
;
1759 if (get_frame_extra_info (fi
)
1760 && get_frame_extra_info (fi
)->sig_fixed_saved_pc_valid
)
1761 return get_frame_extra_info (fi
)->sig_fixed_saved_pc
;
1762 saved_pc
= s390_frame_saved_pc_nofix (fi
);
1764 if (get_frame_extra_info (fi
))
1766 get_frame_extra_info (fi
)->sig_fixed_saved_pc_valid
= 1;
1769 if (s390_is_sigreturn (saved_pc
, fi
, NULL
, &sig_pc
))
1772 get_frame_extra_info (fi
)->sig_fixed_saved_pc
= saved_pc
;
1780 /* We want backtraces out of signal handlers so we don't set
1781 (get_frame_type (thisframe) == SIGTRAMP_FRAME) to 1 */
1784 s390_frame_chain (struct frame_info
*thisframe
)
1786 CORE_ADDR prev_fp
= 0;
1788 if (deprecated_generic_find_dummy_frame (get_frame_pc (thisframe
),
1789 get_frame_base (thisframe
)))
1790 return deprecated_read_register_dummy (get_frame_pc (thisframe
),
1791 get_frame_base (thisframe
),
1796 CORE_ADDR sregs
= 0;
1797 struct frame_extra_info prev_fextra_info
;
1799 memset (&prev_fextra_info
, 0, sizeof (prev_fextra_info
));
1800 if (get_frame_pc (thisframe
))
1802 CORE_ADDR saved_pc
, sig_pc
;
1804 saved_pc
= s390_frame_saved_pc_nofix (thisframe
);
1808 s390_is_sigreturn (saved_pc
, thisframe
, &sregs
, &sig_pc
)))
1810 s390_get_frame_info (s390_sniff_pc_function_start
1811 (saved_pc
, NULL
), &prev_fextra_info
, NULL
,
1817 /* read sigregs,regs.gprs[11 or 15] */
1818 prev_fp
= read_memory_integer (sregs
+
1819 DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM
+
1821 frame_pointer_saved_pc
1824 get_frame_extra_info (thisframe
)->sigcontext
= sregs
;
1828 if (deprecated_get_frame_saved_regs (thisframe
))
1832 if (prev_fextra_info
.frame_pointer_saved_pc
1833 && deprecated_get_frame_saved_regs (thisframe
)[S390_FRAME_REGNUM
])
1834 regno
= S390_FRAME_REGNUM
;
1836 regno
= S390_SP_REGNUM
;
1838 if (deprecated_get_frame_saved_regs (thisframe
)[regno
])
1840 /* The SP's entry of `saved_regs' is special. */
1841 if (regno
== S390_SP_REGNUM
)
1842 prev_fp
= deprecated_get_frame_saved_regs (thisframe
)[regno
];
1845 read_memory_integer (deprecated_get_frame_saved_regs (thisframe
)[regno
],
1851 return ADDR_BITS_REMOVE (prev_fp
);
1855 Whether struct frame_extra_info is actually needed I'll have to figure
1856 out as our frames are similar to rs6000 there is a possibility
1857 i386 dosen't need it. */
1861 /* NOTE: cagney/2003-10-31: "return_value" makes
1862 "extract_struct_value_address", "extract_return_value", and
1863 "use_struct_convention" redundant. */
1865 s390_cannot_extract_struct_value_address (struct regcache
*regcache
)
1870 /* a given return value in `regbuf' with a type `valtype', extract and copy its
1871 value into `valbuf' */
1873 s390_extract_return_value (struct type
*valtype
, char *regbuf
, char *valbuf
)
1875 /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes.
1876 We need to truncate the return value into float size (4 byte) if
1878 int len
= TYPE_LENGTH (valtype
);
1880 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1881 memcpy (valbuf
, ®buf
[DEPRECATED_REGISTER_BYTE (S390_FP0_REGNUM
)], len
);
1885 /* return value is copied starting from r2. */
1886 if (TYPE_LENGTH (valtype
) < S390_GPR_SIZE
)
1887 offset
= S390_GPR_SIZE
- TYPE_LENGTH (valtype
);
1889 regbuf
+ DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM
+ 2) + offset
,
1890 TYPE_LENGTH (valtype
));
1896 s390_promote_integer_argument (struct type
*valtype
, char *valbuf
,
1897 char *reg_buff
, int *arglen
)
1899 char *value
= valbuf
;
1900 int len
= TYPE_LENGTH (valtype
);
1902 if (len
< S390_GPR_SIZE
)
1904 /* We need to upgrade this value to a register to pass it correctly */
1905 int idx
, diff
= S390_GPR_SIZE
- len
, negative
=
1906 (!TYPE_UNSIGNED (valtype
) && value
[0] & 0x80);
1907 for (idx
= 0; idx
< S390_GPR_SIZE
; idx
++)
1909 reg_buff
[idx
] = (idx
< diff
? (negative
? 0xff : 0x0) :
1913 *arglen
= S390_GPR_SIZE
;
1917 if (len
& (S390_GPR_SIZE
- 1))
1919 fprintf_unfiltered (gdb_stderr
,
1920 "s390_promote_integer_argument detected an argument not "
1921 "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE "
1922 "we might not deal with this correctly.\n");
1931 s390_store_return_value (struct type
*valtype
, char *valbuf
)
1934 char *reg_buff
= alloca (max (S390_FPR_SIZE
, DEPRECATED_REGISTER_SIZE
)), *value
;
1936 if (TYPE_CODE (valtype
) == TYPE_CODE_FLT
)
1938 if (TYPE_LENGTH (valtype
) == 4
1939 || TYPE_LENGTH (valtype
) == 8)
1940 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_FP0_REGNUM
),
1941 valbuf
, TYPE_LENGTH (valtype
));
1943 error ("GDB is unable to return `long double' values "
1944 "on this architecture.");
1949 s390_promote_integer_argument (valtype
, valbuf
, reg_buff
, &arglen
);
1950 /* Everything else is returned in GPR2 and up. */
1951 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM
+ 2),
1957 /* Not the most efficent code in the world */
1959 s390_fp_regnum (void)
1961 int regno
= S390_SP_REGNUM
;
1962 struct frame_extra_info fextra_info
;
1964 CORE_ADDR pc
= ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM
));
1966 s390_get_frame_info (s390_sniff_pc_function_start (pc
, NULL
), &fextra_info
,
1968 if (fextra_info
.frame_pointer_saved_pc
)
1969 regno
= S390_FRAME_REGNUM
;
1976 return read_register (s390_fp_regnum ());
1981 s390_pop_frame_regular (struct frame_info
*frame
)
1985 write_register (S390_PC_REGNUM
, DEPRECATED_FRAME_SAVED_PC (frame
));
1987 /* Restore any saved registers. */
1988 if (deprecated_get_frame_saved_regs (frame
))
1990 for (regnum
= 0; regnum
< NUM_REGS
; regnum
++)
1991 if (deprecated_get_frame_saved_regs (frame
)[regnum
] != 0)
1995 value
= read_memory_unsigned_integer (deprecated_get_frame_saved_regs (frame
)[regnum
],
1996 DEPRECATED_REGISTER_RAW_SIZE (regnum
));
1997 write_register (regnum
, value
);
2000 /* Actually cut back the stack. Remember that the SP's element of
2001 saved_regs is the old SP itself, not the address at which it is
2003 write_register (S390_SP_REGNUM
, deprecated_get_frame_saved_regs (frame
)[S390_SP_REGNUM
]);
2006 /* Throw away any cached frame information. */
2007 flush_cached_frames ();
2011 /* Destroy the innermost (Top-Of-Stack) stack frame, restoring the
2012 machine state that was in effect before the frame was created.
2013 Used in the contexts of the "return" command, and of
2014 target function calls from the debugger. */
2016 s390_pop_frame (void)
2018 /* This function checks for and handles generic dummy frames, and
2019 calls back to our function for ordinary frames. */
2020 generic_pop_current_frame (s390_pop_frame_regular
);
2024 /* Return non-zero if TYPE is an integer-like type, zero otherwise.
2025 "Integer-like" types are those that should be passed the way
2026 integers are: integers, enums, ranges, characters, and booleans. */
2028 is_integer_like (struct type
*type
)
2030 enum type_code code
= TYPE_CODE (type
);
2032 return (code
== TYPE_CODE_INT
2033 || code
== TYPE_CODE_ENUM
2034 || code
== TYPE_CODE_RANGE
2035 || code
== TYPE_CODE_CHAR
2036 || code
== TYPE_CODE_BOOL
);
2040 /* Return non-zero if TYPE is a pointer-like type, zero otherwise.
2041 "Pointer-like" types are those that should be passed the way
2042 pointers are: pointers and references. */
2044 is_pointer_like (struct type
*type
)
2046 enum type_code code
= TYPE_CODE (type
);
2048 return (code
== TYPE_CODE_PTR
2049 || code
== TYPE_CODE_REF
);
2053 /* Return non-zero if TYPE is a `float singleton' or `double
2054 singleton', zero otherwise.
2056 A `T singleton' is a struct type with one member, whose type is
2057 either T or a `T singleton'. So, the following are all float
2061 struct { struct { float x; } x; };
2062 struct { struct { struct { float x; } x; } x; };
2066 WHY THE HECK DO WE CARE ABOUT THIS??? Well, it turns out that GCC
2067 passes all float singletons and double singletons as if they were
2068 simply floats or doubles. This is *not* what the ABI says it
2071 is_float_singleton (struct type
*type
)
2073 return (TYPE_CODE (type
) == TYPE_CODE_STRUCT
2074 && TYPE_NFIELDS (type
) == 1
2075 && (TYPE_CODE (TYPE_FIELD_TYPE (type
, 0)) == TYPE_CODE_FLT
2076 || is_float_singleton (TYPE_FIELD_TYPE (type
, 0))));
2080 /* Return non-zero if TYPE is a struct-like type, zero otherwise.
2081 "Struct-like" types are those that should be passed as structs are:
2084 As an odd quirk, not mentioned in the ABI, GCC passes float and
2085 double singletons as if they were a plain float, double, etc. (The
2086 corresponding union types are handled normally.) So we exclude
2087 those types here. *shrug* */
2089 is_struct_like (struct type
*type
)
2091 enum type_code code
= TYPE_CODE (type
);
2093 return (code
== TYPE_CODE_UNION
2094 || (code
== TYPE_CODE_STRUCT
&& ! is_float_singleton (type
)));
2098 /* Return non-zero if TYPE is a float-like type, zero otherwise.
2099 "Float-like" types are those that should be passed as
2100 floating-point values are.
2102 You'd think this would just be floats, doubles, long doubles, etc.
2103 But as an odd quirk, not mentioned in the ABI, GCC passes float and
2104 double singletons as if they were a plain float, double, etc. (The
2105 corresponding union types are handled normally.) So we include
2106 those types here. *shrug* */
2108 is_float_like (struct type
*type
)
2110 return (TYPE_CODE (type
) == TYPE_CODE_FLT
2111 || is_float_singleton (type
));
2115 /* Return non-zero if TYPE is considered a `DOUBLE_OR_FLOAT', as
2116 defined by the parameter passing conventions described in the
2117 "GNU/Linux for S/390 ELF Application Binary Interface Supplement".
2118 Otherwise, return zero. */
2120 is_double_or_float (struct type
*type
)
2122 return (is_float_like (type
)
2123 && (TYPE_LENGTH (type
) == 4
2124 || TYPE_LENGTH (type
) == 8));
2128 /* Return non-zero if TYPE is a `DOUBLE_ARG', as defined by the
2129 parameter passing conventions described in the "GNU/Linux for S/390
2130 ELF Application Binary Interface Supplement". Return zero
2133 is_double_arg (struct type
*type
)
2135 unsigned length
= TYPE_LENGTH (type
);
2137 /* The s390x ABI doesn't handle DOUBLE_ARGS specially. */
2138 if (GDB_TARGET_IS_ESAME
)
2141 return ((is_integer_like (type
)
2142 || is_struct_like (type
))
2147 /* Return non-zero if TYPE is considered a `SIMPLE_ARG', as defined by
2148 the parameter passing conventions described in the "GNU/Linux for
2149 S/390 ELF Application Binary Interface Supplement". Return zero
2152 is_simple_arg (struct type
*type
)
2154 unsigned length
= TYPE_LENGTH (type
);
2156 /* This is almost a direct translation of the ABI's language, except
2157 that we have to exclude 8-byte structs; those are DOUBLE_ARGs. */
2158 return ((is_integer_like (type
) && length
<= DEPRECATED_REGISTER_SIZE
)
2159 || is_pointer_like (type
)
2160 || (is_struct_like (type
) && !is_double_arg (type
)));
2165 is_power_of_two (unsigned int n
)
2167 return ((n
& (n
- 1)) == 0);
2170 /* Return non-zero if TYPE should be passed as a pointer to a copy,
2171 zero otherwise. TYPE must be a SIMPLE_ARG, as recognized by
2174 pass_by_copy_ref (struct type
*type
)
2176 unsigned length
= TYPE_LENGTH (type
);
2178 return (is_struct_like (type
)
2179 && !(is_power_of_two (length
) && length
<= DEPRECATED_REGISTER_SIZE
));
2183 /* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
2184 word as required for the ABI. */
2186 extend_simple_arg (struct value
*arg
)
2188 struct type
*type
= VALUE_TYPE (arg
);
2190 /* Even structs get passed in the least significant bits of the
2191 register / memory word. It's not really right to extract them as
2192 an integer, but it does take care of the extension. */
2193 if (TYPE_UNSIGNED (type
))
2194 return extract_unsigned_integer (VALUE_CONTENTS (arg
),
2195 TYPE_LENGTH (type
));
2197 return extract_signed_integer (VALUE_CONTENTS (arg
),
2198 TYPE_LENGTH (type
));
2202 /* Return the alignment required by TYPE. */
2204 alignment_of (struct type
*type
)
2208 if (is_integer_like (type
)
2209 || is_pointer_like (type
)
2210 || TYPE_CODE (type
) == TYPE_CODE_FLT
)
2211 alignment
= TYPE_LENGTH (type
);
2212 else if (TYPE_CODE (type
) == TYPE_CODE_STRUCT
2213 || TYPE_CODE (type
) == TYPE_CODE_UNION
)
2218 for (i
= 0; i
< TYPE_NFIELDS (type
); i
++)
2220 int field_alignment
= alignment_of (TYPE_FIELD_TYPE (type
, i
));
2222 if (field_alignment
> alignment
)
2223 alignment
= field_alignment
;
2229 /* Check that everything we ever return is a power of two. Lots of
2230 code doesn't want to deal with aligning things to arbitrary
2232 gdb_assert ((alignment
& (alignment
- 1)) == 0);
2238 /* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
2239 place to be passed to a function, as specified by the "GNU/Linux
2240 for S/390 ELF Application Binary Interface Supplement".
2242 SP is the current stack pointer. We must put arguments, links,
2243 padding, etc. whereever they belong, and return the new stack
2246 If STRUCT_RETURN is non-zero, then the function we're calling is
2247 going to return a structure by value; STRUCT_ADDR is the address of
2248 a block we've allocated for it on the stack.
2250 Our caller has taken care of any type promotions needed to satisfy
2251 prototypes or the old K&R argument-passing rules. */
2253 s390_push_arguments (int nargs
, struct value
**args
, CORE_ADDR sp
,
2254 int struct_return
, CORE_ADDR struct_addr
)
2257 int pointer_size
= (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
);
2259 /* The number of arguments passed by reference-to-copy. */
2262 /* If the i'th argument is passed as a reference to a copy, then
2263 copy_addr[i] is the address of the copy we made. */
2264 CORE_ADDR
*copy_addr
= alloca (nargs
* sizeof (CORE_ADDR
));
2266 /* Build the reference-to-copy area. */
2268 for (i
= 0; i
< nargs
; i
++)
2270 struct value
*arg
= args
[i
];
2271 struct type
*type
= VALUE_TYPE (arg
);
2272 unsigned length
= TYPE_LENGTH (type
);
2274 if (is_simple_arg (type
)
2275 && pass_by_copy_ref (type
))
2278 sp
= align_down (sp
, alignment_of (type
));
2279 write_memory (sp
, VALUE_CONTENTS (arg
), length
);
2285 /* Reserve space for the parameter area. As a conservative
2286 simplification, we assume that everything will be passed on the
2291 for (i
= 0; i
< nargs
; i
++)
2293 struct value
*arg
= args
[i
];
2294 struct type
*type
= VALUE_TYPE (arg
);
2295 int length
= TYPE_LENGTH (type
);
2297 sp
= align_down (sp
, alignment_of (type
));
2299 /* SIMPLE_ARG values get extended to DEPRECATED_REGISTER_SIZE bytes.
2300 Assume every argument is. */
2301 if (length
< DEPRECATED_REGISTER_SIZE
) length
= DEPRECATED_REGISTER_SIZE
;
2306 /* Include space for any reference-to-copy pointers. */
2307 sp
= align_down (sp
, pointer_size
);
2308 sp
-= num_copies
* pointer_size
;
2310 /* After all that, make sure it's still aligned on an eight-byte
2312 sp
= align_down (sp
, 8);
2314 /* Finally, place the actual parameters, working from SP towards
2315 higher addresses. The code above is supposed to reserve enough
2320 CORE_ADDR starg
= sp
;
2322 /* A struct is returned using general register 2 */
2326 for (i
= 0; i
< nargs
; i
++)
2328 struct value
*arg
= args
[i
];
2329 struct type
*type
= VALUE_TYPE (arg
);
2331 if (is_double_or_float (type
)
2332 && fr
<= S390_NUM_FP_PARAMETER_REGISTERS
* 2 - 2)
2334 /* When we store a single-precision value in an FP register,
2335 it occupies the leftmost bits. */
2336 deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_FP0_REGNUM
+ fr
),
2337 VALUE_CONTENTS (arg
),
2338 TYPE_LENGTH (type
));
2341 else if (is_simple_arg (type
)
2344 /* Do we need to pass a pointer to our copy of this
2346 if (pass_by_copy_ref (type
))
2347 write_register (S390_GP0_REGNUM
+ gr
, copy_addr
[i
]);
2349 write_register (S390_GP0_REGNUM
+ gr
, extend_simple_arg (arg
));
2353 else if (is_double_arg (type
)
2356 deprecated_write_register_gen (S390_GP0_REGNUM
+ gr
,
2357 VALUE_CONTENTS (arg
));
2358 deprecated_write_register_gen (S390_GP0_REGNUM
+ gr
+ 1,
2359 VALUE_CONTENTS (arg
) + DEPRECATED_REGISTER_SIZE
);
2364 /* The `OTHER' case. */
2365 enum type_code code
= TYPE_CODE (type
);
2366 unsigned length
= TYPE_LENGTH (type
);
2368 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
2369 in it, then don't go back and use it again later. */
2370 if (is_double_arg (type
) && gr
== 6)
2373 if (is_simple_arg (type
))
2375 /* Simple args are always extended to
2376 DEPRECATED_REGISTER_SIZE bytes. */
2377 starg
= align_up (starg
, DEPRECATED_REGISTER_SIZE
);
2379 /* Do we need to pass a pointer to our copy of this
2381 if (pass_by_copy_ref (type
))
2382 write_memory_signed_integer (starg
, pointer_size
,
2385 /* Simple args are always extended to
2386 DEPRECATED_REGISTER_SIZE bytes. */
2387 write_memory_signed_integer (starg
, DEPRECATED_REGISTER_SIZE
,
2388 extend_simple_arg (arg
));
2389 starg
+= DEPRECATED_REGISTER_SIZE
;
2393 /* You'd think we should say:
2394 starg = align_up (starg, alignment_of (type));
2395 Unfortunately, GCC seems to simply align the stack on
2396 a four/eight-byte boundary, even when passing doubles. */
2397 starg
= align_up (starg
, S390_STACK_PARAMETER_ALIGNMENT
);
2398 write_memory (starg
, VALUE_CONTENTS (arg
), length
);
2405 /* Allocate the standard frame areas: the register save area, the
2406 word reserved for the compiler (which seems kind of meaningless),
2407 and the back chain pointer. */
2408 sp
-= S390_STACK_FRAME_OVERHEAD
;
2410 /* Write the back chain pointer into the first word of the stack
2411 frame. This will help us get backtraces from within functions
2413 write_memory_unsigned_integer (sp
, (TARGET_PTR_BIT
/ TARGET_CHAR_BIT
),
2414 deprecated_read_fp ());
2421 s390_frame_align (struct gdbarch
*gdbarch
, CORE_ADDR addr
)
2423 /* Both the 32- and 64-bit ABI's say that the stack pointer should
2424 always be aligned on an eight-byte boundary. */
2430 s390_use_struct_convention (int gcc_p
, struct type
*value_type
)
2432 enum type_code code
= TYPE_CODE (value_type
);
2434 return (code
== TYPE_CODE_STRUCT
2435 || code
== TYPE_CODE_UNION
);
2439 /* Return the GDB type object for the "standard" data type
2440 of data in register N. */
2441 static struct type
*
2442 s390_register_virtual_type (int regno
)
2444 if (S390_FP0_REGNUM
<= regno
&& regno
< S390_FP0_REGNUM
+ S390_NUM_FPRS
)
2445 return builtin_type_double
;
2447 return builtin_type_int
;
2451 static struct type
*
2452 s390x_register_virtual_type (int regno
)
2454 return (regno
== S390_FPC_REGNUM
) ||
2455 (regno
>= S390_FIRST_ACR
&& regno
<= S390_LAST_ACR
) ? builtin_type_int
:
2456 (regno
>= S390_FP0_REGNUM
) ? builtin_type_double
: builtin_type_long
;
2462 s390_store_struct_return (CORE_ADDR addr
, CORE_ADDR sp
)
2464 write_register (S390_GP0_REGNUM
+ 2, addr
);
2469 static const unsigned char *
2470 s390_breakpoint_from_pc (CORE_ADDR
*pcptr
, int *lenptr
)
2472 static unsigned char breakpoint
[] = { 0x0, 0x1 };
2474 *lenptr
= sizeof (breakpoint
);
2478 /* Advance PC across any function entry prologue instructions to reach some
2481 s390_skip_prologue (CORE_ADDR pc
)
2483 struct frame_extra_info fextra_info
;
2485 s390_get_frame_info (pc
, &fextra_info
, NULL
, 1);
2486 return fextra_info
.skip_prologue_function_start
;
2489 /* Immediately after a function call, return the saved pc.
2490 Can't go through the frames for this because on some machines
2491 the new frame is not set up until the new function executes
2492 some instructions. */
2494 s390_saved_pc_after_call (struct frame_info
*frame
)
2496 return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM
));
2500 s390_addr_bits_remove (CORE_ADDR addr
)
2502 return (addr
) & 0x7fffffff;
2507 s390_push_return_address (CORE_ADDR pc
, CORE_ADDR sp
)
2509 write_register (S390_RETADDR_REGNUM
, entry_point_address ());
2514 s390_address_class_type_flags (int byte_size
, int dwarf2_addr_class
)
2517 return TYPE_FLAG_ADDRESS_CLASS_1
;
2523 s390_address_class_type_flags_to_name (struct gdbarch
*gdbarch
, int type_flags
)
2525 if (type_flags
& TYPE_FLAG_ADDRESS_CLASS_1
)
2532 s390_address_class_name_to_type_flags (struct gdbarch
*gdbarch
, const char *name
,
2533 int *type_flags_ptr
)
2535 if (strcmp (name
, "mode32") == 0)
2537 *type_flags_ptr
= TYPE_FLAG_ADDRESS_CLASS_1
;
2544 static struct gdbarch
*
2545 s390_gdbarch_init (struct gdbarch_info info
, struct gdbarch_list
*arches
)
2547 static LONGEST s390_call_dummy_words
[] = { 0 };
2548 struct gdbarch
*gdbarch
;
2549 struct gdbarch_tdep
*tdep
;
2552 /* First see if there is already a gdbarch that can satisfy the request. */
2553 arches
= gdbarch_list_lookup_by_info (arches
, &info
);
2555 return arches
->gdbarch
;
2557 /* None found: is the request for a s390 architecture? */
2558 if (info
.bfd_arch_info
->arch
!= bfd_arch_s390
)
2559 return NULL
; /* No; then it's not for us. */
2561 /* Yes: create a new gdbarch for the specified machine type. */
2562 gdbarch
= gdbarch_alloc (&info
, NULL
);
2564 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
2565 ready to unwind the PC first (see frame.c:get_prev_frame()). */
2566 set_gdbarch_deprecated_init_frame_pc (gdbarch
, deprecated_init_frame_pc_default
);
2568 set_gdbarch_believe_pcc_promotion (gdbarch
, 0);
2569 set_gdbarch_char_signed (gdbarch
, 0);
2571 set_gdbarch_deprecated_frame_chain (gdbarch
, s390_frame_chain
);
2572 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch
, s390_frame_init_saved_regs
);
2573 set_gdbarch_deprecated_store_struct_return (gdbarch
, s390_store_struct_return
);
2574 set_gdbarch_deprecated_extract_return_value (gdbarch
, s390_extract_return_value
);
2575 set_gdbarch_deprecated_store_return_value (gdbarch
, s390_store_return_value
);
2576 /* Amount PC must be decremented by after a breakpoint. This is
2577 often the number of bytes returned by BREAKPOINT_FROM_PC but not
2579 set_gdbarch_decr_pc_after_break (gdbarch
, 2);
2580 set_gdbarch_deprecated_pop_frame (gdbarch
, s390_pop_frame
);
2581 /* Stack grows downward. */
2582 set_gdbarch_inner_than (gdbarch
, core_addr_lessthan
);
2583 set_gdbarch_deprecated_max_register_raw_size (gdbarch
, 8);
2584 set_gdbarch_deprecated_max_register_virtual_size (gdbarch
, 8);
2585 set_gdbarch_breakpoint_from_pc (gdbarch
, s390_breakpoint_from_pc
);
2586 set_gdbarch_skip_prologue (gdbarch
, s390_skip_prologue
);
2587 set_gdbarch_deprecated_init_extra_frame_info (gdbarch
, s390_init_extra_frame_info
);
2588 set_gdbarch_deprecated_init_frame_pc_first (gdbarch
, s390_init_frame_pc_first
);
2589 set_gdbarch_deprecated_target_read_fp (gdbarch
, s390_read_fp
);
2590 /* This function that tells us whether the function invocation represented
2591 by FI does not have a frame on the stack associated with it. If it
2592 does not, FRAMELESS is set to 1, else 0. */
2593 set_gdbarch_frameless_function_invocation (gdbarch
,
2594 s390_frameless_function_invocation
);
2595 /* Return saved PC from a frame */
2596 set_gdbarch_deprecated_frame_saved_pc (gdbarch
, s390_frame_saved_pc
);
2597 /* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and
2598 produces the frame's chain-pointer. */
2599 set_gdbarch_deprecated_frame_chain (gdbarch
, s390_frame_chain
);
2600 set_gdbarch_deprecated_saved_pc_after_call (gdbarch
, s390_saved_pc_after_call
);
2601 set_gdbarch_deprecated_register_byte (gdbarch
, s390_register_byte
);
2602 set_gdbarch_pc_regnum (gdbarch
, S390_PC_REGNUM
);
2603 set_gdbarch_sp_regnum (gdbarch
, S390_SP_REGNUM
);
2604 set_gdbarch_deprecated_fp_regnum (gdbarch
, S390_FP_REGNUM
);
2605 set_gdbarch_fp0_regnum (gdbarch
, S390_FP0_REGNUM
);
2606 set_gdbarch_num_regs (gdbarch
, S390_NUM_REGS
);
2607 set_gdbarch_cannot_fetch_register (gdbarch
, s390_cannot_fetch_register
);
2608 set_gdbarch_cannot_store_register (gdbarch
, s390_cannot_fetch_register
);
2609 set_gdbarch_use_struct_convention (gdbarch
, s390_use_struct_convention
);
2610 set_gdbarch_register_name (gdbarch
, s390_register_name
);
2611 set_gdbarch_stab_reg_to_regnum (gdbarch
, s390_stab_reg_to_regnum
);
2612 set_gdbarch_dwarf_reg_to_regnum (gdbarch
, s390_stab_reg_to_regnum
);
2613 set_gdbarch_dwarf2_reg_to_regnum (gdbarch
, s390_stab_reg_to_regnum
);
2614 set_gdbarch_deprecated_extract_struct_value_address (gdbarch
, s390_cannot_extract_struct_value_address
);
2616 /* Parameters for inferior function calls. */
2617 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch
, deprecated_pc_in_call_dummy_at_entry_point
);
2618 set_gdbarch_frame_align (gdbarch
, s390_frame_align
);
2619 set_gdbarch_deprecated_push_arguments (gdbarch
, s390_push_arguments
);
2620 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch
, generic_save_dummy_frame_tos
);
2621 set_gdbarch_deprecated_push_return_address (gdbarch
,
2622 s390_push_return_address
);
2623 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch
, sizeof (s390_call_dummy_words
));
2624 set_gdbarch_deprecated_call_dummy_words (gdbarch
, s390_call_dummy_words
);
2626 switch (info
.bfd_arch_info
->mach
)
2628 case bfd_mach_s390_31
:
2629 set_gdbarch_deprecated_register_size (gdbarch
, 4);
2630 set_gdbarch_deprecated_register_raw_size (gdbarch
, s390_register_raw_size
);
2631 set_gdbarch_deprecated_register_virtual_size (gdbarch
, s390_register_raw_size
);
2632 set_gdbarch_deprecated_register_virtual_type (gdbarch
, s390_register_virtual_type
);
2634 set_gdbarch_addr_bits_remove (gdbarch
, s390_addr_bits_remove
);
2635 set_gdbarch_deprecated_register_bytes (gdbarch
, S390_REGISTER_BYTES
);
2637 case bfd_mach_s390_64
:
2638 set_gdbarch_deprecated_register_size (gdbarch
, 8);
2639 set_gdbarch_deprecated_register_raw_size (gdbarch
, s390x_register_raw_size
);
2640 set_gdbarch_deprecated_register_virtual_size (gdbarch
, s390x_register_raw_size
);
2641 set_gdbarch_deprecated_register_virtual_type (gdbarch
, s390x_register_virtual_type
);
2643 set_gdbarch_long_bit (gdbarch
, 64);
2644 set_gdbarch_long_long_bit (gdbarch
, 64);
2645 set_gdbarch_ptr_bit (gdbarch
, 64);
2646 set_gdbarch_deprecated_register_bytes (gdbarch
, S390X_REGISTER_BYTES
);
2647 set_gdbarch_address_class_type_flags (gdbarch
,
2648 s390_address_class_type_flags
);
2649 set_gdbarch_address_class_type_flags_to_name (gdbarch
,
2650 s390_address_class_type_flags_to_name
);
2651 set_gdbarch_address_class_name_to_type_flags (gdbarch
,
2652 s390_address_class_name_to_type_flags
);
2656 /* Should be using push_dummy_call. */
2657 set_gdbarch_deprecated_dummy_write_sp (gdbarch
, deprecated_write_sp
);
2659 set_gdbarch_print_insn (gdbarch
, print_insn_s390
);
2666 extern initialize_file_ftype _initialize_s390_tdep
; /* -Wmissing-prototypes */
2669 _initialize_s390_tdep (void)
2672 /* Hook us into the gdbarch mechanism. */
2673 register_gdbarch_init (bfd_arch_s390
, s390_gdbarch_init
);