*** empty log message ***
[deliverable/binutils-gdb.git] / gdb / s390-tdep.c
CommitLineData
5769d3cd 1/* Target-dependent code for GDB, the GNU debugger.
ca557f44 2
1e698235 3 Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
ca557f44 4
5769d3cd
AC
5 Contributed by D.J. Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com)
6 for IBM Deutschland Entwicklung GmbH, IBM Corporation.
7
8 This file is part of GDB.
9
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.
14
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.
19
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
23 02111-1307, USA. */
24
25#define S390_TDEP /* for special macros in tm-s390.h */
26#include <defs.h>
27#include "arch-utils.h"
28#include "frame.h"
29#include "inferior.h"
30#include "symtab.h"
31#include "target.h"
32#include "gdbcore.h"
33#include "gdbcmd.h"
34#include "symfile.h"
35#include "objfiles.h"
36#include "tm.h"
37#include "../bfd/bfd.h"
38#include "floatformat.h"
39#include "regcache.h"
fd0407d6 40#include "value.h"
78f8b424 41#include "gdb_assert.h"
5769d3cd
AC
42
43
44
60e6cc42 45
5769d3cd 46/* Number of bytes of storage in the actual machine representation
23b7362f 47 for register N. */
a78f21af 48static int
5769d3cd
AC
49s390_register_raw_size (int reg_nr)
50{
23b7362f
JB
51 if (S390_FP0_REGNUM <= reg_nr
52 && reg_nr < S390_FP0_REGNUM + S390_NUM_FPRS)
53 return S390_FPR_SIZE;
54 else
55 return 4;
5769d3cd
AC
56}
57
a78f21af 58static int
5769d3cd
AC
59s390x_register_raw_size (int reg_nr)
60{
61 return (reg_nr == S390_FPC_REGNUM)
62 || (reg_nr >= S390_FIRST_ACR && reg_nr <= S390_LAST_ACR) ? 4 : 8;
63}
64
a78f21af 65static int
5769d3cd
AC
66s390_cannot_fetch_register (int regno)
67{
68 return (regno >= S390_FIRST_CR && regno < (S390_FIRST_CR + 9)) ||
69 (regno >= (S390_FIRST_CR + 12) && regno <= S390_LAST_CR);
70}
71
a78f21af 72static int
5769d3cd
AC
73s390_register_byte (int reg_nr)
74{
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;
83 else
84 return S390_FP0_OFFSET + (((reg_nr) - S390_FP0_REGNUM) * S390_FPR_SIZE);
85}
86
5769d3cd
AC
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 (GDB_TARGET_IS_ESAME ? 160:96)
97#define S390_SIGNAL_FRAMESIZE (GDB_TARGET_IS_ESAME ? 160:96)
98#define s390_NR_sigreturn 119
99#define s390_NR_rt_sigreturn 173
100
101
102
103struct frame_extra_info
104{
105 int initialised;
106 int good_prologue;
107 CORE_ADDR function_start;
108 CORE_ADDR skip_prologue_function_start;
109 CORE_ADDR saved_pc_valid;
110 CORE_ADDR saved_pc;
111 CORE_ADDR sig_fixed_saved_pc_valid;
112 CORE_ADDR sig_fixed_saved_pc;
113 CORE_ADDR frame_pointer_saved_pc; /* frame pointer needed for alloca */
114 CORE_ADDR stack_bought; /* amount we decrement the stack pointer by */
115 CORE_ADDR sigcontext;
116};
117
118
119static CORE_ADDR s390_frame_saved_pc_nofix (struct frame_info *fi);
120
a78f21af 121static int
5769d3cd
AC
122s390_readinstruction (bfd_byte instr[], CORE_ADDR at,
123 struct disassemble_info *info)
124{
125 int instrlen;
126
127 static int s390_instrlen[] = {
128 2,
129 4,
130 4,
131 6
132 };
133 if ((*info->read_memory_func) (at, &instr[0], 2, info))
134 return -1;
135 instrlen = s390_instrlen[instr[0] >> 6];
c5e243bb
JB
136 if (instrlen > 2)
137 {
138 if ((*info->read_memory_func) (at + 2, &instr[2], instrlen - 2, info))
139 return -1;
140 }
5769d3cd
AC
141 return instrlen;
142}
143
144static void
145s390_memset_extra_info (struct frame_extra_info *fextra_info)
146{
147 memset (fextra_info, 0, sizeof (struct frame_extra_info));
148}
149
150
151
a78f21af 152static const char *
5769d3cd
AC
153s390_register_name (int reg_nr)
154{
155 static char *register_names[] = {
156 "pswm", "pswa",
4ed90530
JB
157 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
158 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
5769d3cd
AC
159 "acr0", "acr1", "acr2", "acr3", "acr4", "acr5", "acr6", "acr7",
160 "acr8", "acr9", "acr10", "acr11", "acr12", "acr13", "acr14", "acr15",
161 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
162 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
163 "fpc",
4ed90530
JB
164 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
165 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15"
5769d3cd
AC
166 };
167
b09677dc
JB
168 if (reg_nr <= S390_LAST_REGNUM)
169 return register_names[reg_nr];
170 else
5769d3cd 171 return NULL;
5769d3cd
AC
172}
173
174
175
176
a78f21af 177static int
5769d3cd
AC
178s390_stab_reg_to_regnum (int regno)
179{
180 return regno >= 64 ? S390_PSWM_REGNUM - 64 :
181 regno >= 48 ? S390_FIRST_ACR - 48 :
182 regno >= 32 ? S390_FIRST_CR - 32 :
183 regno <= 15 ? (regno + 2) :
184 S390_FP0_REGNUM + ((regno - 16) & 8) + (((regno - 16) & 3) << 1) +
185 (((regno - 16) & 4) >> 2);
186}
187
188
12bffad7
JB
189/* Return true if REGIDX is the number of a register used to pass
190 arguments, false otherwise. */
191static int
192is_arg_reg (int regidx)
193{
194 return 2 <= regidx && regidx <= 6;
195}
196
5769d3cd
AC
197
198/* s390_get_frame_info based on Hartmuts
199 prologue definition in
200 gcc-2.8.1/config/l390/linux.c
201
202 It reads one instruction at a time & based on whether
203 it looks like prologue code or not it makes a decision on
204 whether the prologue is over, there are various state machines
205 in the code to determine if the prologue code is possilby valid.
206
207 This is done to hopefully allow the code survive minor revs of
208 calling conventions.
209
210 */
211
a78f21af 212static int
5769d3cd
AC
213s390_get_frame_info (CORE_ADDR pc, struct frame_extra_info *fextra_info,
214 struct frame_info *fi, int init_extra_info)
215{
216#define CONST_POOL_REGIDX 13
217#define GOT_REGIDX 12
218 bfd_byte instr[S390_MAX_INSTR_SIZE];
219 CORE_ADDR test_pc = pc, test_pc2;
220 CORE_ADDR orig_sp = 0, save_reg_addr = 0, *saved_regs = NULL;
221 int valid_prologue, good_prologue = 0;
222 int gprs_saved[S390_NUM_GPRS];
223 int fprs_saved[S390_NUM_FPRS];
224 int regidx, instrlen;
6df29de2 225 int const_pool_state;
7286245e 226 int varargs_state;
5769d3cd 227 int loop_cnt, gdb_gpr_store, gdb_fpr_store;
5769d3cd
AC
228 int offset, expected_offset;
229 int err = 0;
230 disassemble_info info;
8ac0e65a 231
7286245e
JB
232 /* Have we seen an instruction initializing the frame pointer yet?
233 If we've seen an `lr %r11, %r15', then frame_pointer_found is
234 non-zero, and frame_pointer_regidx == 11. Otherwise,
235 frame_pointer_found is zero and frame_pointer_regidx is 15,
236 indicating that we're using the stack pointer as our frame
237 pointer. */
238 int frame_pointer_found = 0;
239 int frame_pointer_regidx = 0xf;
240
6df29de2
JB
241 /* What we've seen so far regarding saving the back chain link:
242 0 -- nothing yet; sp still has the same value it had at the entry
243 point. Since not all functions allocate frames, this is a
244 valid state for the prologue to finish in.
245 1 -- We've saved the original sp in some register other than the
246 frame pointer (hard-coded to be %r11, yuck).
247 save_link_regidx is the register we saved it in.
248 2 -- We've seen the initial `bras' instruction of the sequence for
249 reserving more than 32k of stack:
250 bras %rX, .+8
251 .long N
252 s %r15, 0(%rX)
253 where %rX is not the constant pool register.
254 subtract_sp_regidx is %rX, and fextra_info->stack_bought is N.
255 3 -- We've reserved space for a new stack frame. This means we
256 either saw a simple `ahi %r15,-N' in state 1, or the final
257 `s %r15, ...' in state 2.
258 4 -- The frame and link are now fully initialized. We've
259 reserved space for the new stack frame, and stored the old
260 stack pointer captured in the back chain pointer field. */
7286245e 261 int save_link_state = 0;
6df29de2
JB
262 int save_link_regidx, subtract_sp_regidx;
263
8ac0e65a
JB
264 /* What we've seen so far regarding r12 --- the GOT (Global Offset
265 Table) pointer. We expect to see `l %r12, N(%r13)', which loads
266 r12 with the offset from the constant pool to the GOT, and then
267 an `ar %r12, %r13', which adds the constant pool address,
268 yielding the GOT's address. Here's what got_state means:
269 0 -- seen nothing
270 1 -- seen `l %r12, N(%r13)', but no `ar'
271 2 -- seen load and add, so GOT pointer is totally initialized
272 When got_state is 1, then got_load_addr is the address of the
273 load instruction, and got_load_len is the length of that
274 instruction. */
7286245e 275 int got_state= 0;
64f9bb98 276 CORE_ADDR got_load_addr = 0, got_load_len = 0;
8ac0e65a 277
7286245e
JB
278 const_pool_state = varargs_state = 0;
279
5769d3cd
AC
280 memset (gprs_saved, 0, sizeof (gprs_saved));
281 memset (fprs_saved, 0, sizeof (fprs_saved));
810ecf9f 282 info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func;
5769d3cd
AC
283
284 save_link_regidx = subtract_sp_regidx = 0;
285 if (fextra_info)
286 {
1e2330ba 287 if (fi && get_frame_base (fi))
5769d3cd 288 {
1e2330ba 289 orig_sp = get_frame_base (fi);
386e4208 290 if (! init_extra_info && fextra_info->initialised)
76cc2cf0 291 orig_sp += fextra_info->stack_bought;
b2fb4676 292 saved_regs = get_frame_saved_regs (fi);
5769d3cd
AC
293 }
294 if (init_extra_info || !fextra_info->initialised)
295 {
296 s390_memset_extra_info (fextra_info);
297 fextra_info->function_start = pc;
298 fextra_info->initialised = 1;
299 }
300 }
301 instrlen = 0;
302 do
303 {
304 valid_prologue = 0;
305 test_pc += instrlen;
306 /* add the previous instruction len */
307 instrlen = s390_readinstruction (instr, test_pc, &info);
308 if (instrlen < 0)
309 {
310 good_prologue = 0;
311 err = -1;
312 break;
313 }
314 /* We probably are in a glibc syscall */
315 if (instr[0] == S390_SYSCALL_OPCODE && test_pc == pc)
316 {
317 good_prologue = 1;
11c02a10 318 if (saved_regs && fextra_info && get_next_frame (fi)
da50a4b7
AC
319 && get_frame_extra_info (get_next_frame (fi))
320 && get_frame_extra_info (get_next_frame (fi))->sigcontext)
5769d3cd
AC
321 {
322 /* We are backtracing from a signal handler */
da50a4b7 323 save_reg_addr = get_frame_extra_info (get_next_frame (fi))->sigcontext +
5769d3cd
AC
324 REGISTER_BYTE (S390_GP0_REGNUM);
325 for (regidx = 0; regidx < S390_NUM_GPRS; regidx++)
326 {
327 saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr;
328 save_reg_addr += S390_GPR_SIZE;
329 }
da50a4b7 330 save_reg_addr = get_frame_extra_info (get_next_frame (fi))->sigcontext +
5769d3cd
AC
331 (GDB_TARGET_IS_ESAME ? S390X_SIGREGS_FP0_OFFSET :
332 S390_SIGREGS_FP0_OFFSET);
333 for (regidx = 0; regidx < S390_NUM_FPRS; regidx++)
334 {
335 saved_regs[S390_FP0_REGNUM + regidx] = save_reg_addr;
336 save_reg_addr += S390_FPR_SIZE;
337 }
338 }
339 break;
340 }
341 if (save_link_state == 0)
342 {
343 /* check for a stack relative STMG or STM */
344 if (((GDB_TARGET_IS_ESAME &&
345 ((instr[0] == 0xeb) && (instr[5] == 0x24))) ||
346 (instr[0] == 0x90)) && ((instr[2] >> 4) == 0xf))
347 {
348 regidx = (instr[1] >> 4);
349 if (regidx < 6)
350 varargs_state = 1;
351 offset = ((instr[2] & 0xf) << 8) + instr[3];
352 expected_offset =
353 S390_GPR6_STACK_OFFSET + (S390_GPR_SIZE * (regidx - 6));
354 if (offset != expected_offset)
355 {
356 good_prologue = 0;
357 break;
358 }
359 if (saved_regs)
360 save_reg_addr = orig_sp + offset;
361 for (; regidx <= (instr[1] & 0xf); regidx++)
362 {
363 if (gprs_saved[regidx])
364 {
365 good_prologue = 0;
366 break;
367 }
368 good_prologue = 1;
369 gprs_saved[regidx] = 1;
370 if (saved_regs)
371 {
372 saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr;
373 save_reg_addr += S390_GPR_SIZE;
374 }
375 }
376 valid_prologue = 1;
377 continue;
378 }
379 }
380 /* check for a stack relative STG or ST */
381 if ((save_link_state == 0 || save_link_state == 3) &&
382 ((GDB_TARGET_IS_ESAME &&
383 ((instr[0] == 0xe3) && (instr[5] == 0x24))) ||
384 (instr[0] == 0x50)) && ((instr[2] >> 4) == 0xf))
385 {
386 regidx = instr[1] >> 4;
387 offset = ((instr[2] & 0xf) << 8) + instr[3];
388 if (offset == 0)
389 {
390 if (save_link_state == 3 && regidx == save_link_regidx)
391 {
392 save_link_state = 4;
393 valid_prologue = 1;
394 continue;
395 }
396 else
397 break;
398 }
399 if (regidx < 6)
400 varargs_state = 1;
401 expected_offset =
402 S390_GPR6_STACK_OFFSET + (S390_GPR_SIZE * (regidx - 6));
403 if (offset != expected_offset)
404 {
405 good_prologue = 0;
406 break;
407 }
408 if (gprs_saved[regidx])
409 {
410 good_prologue = 0;
411 break;
412 }
413 good_prologue = 1;
414 gprs_saved[regidx] = 1;
415 if (saved_regs)
416 {
417 save_reg_addr = orig_sp + offset;
418 saved_regs[S390_GP0_REGNUM + regidx] = save_reg_addr;
419 }
420 valid_prologue = 1;
421 continue;
422 }
423
12bffad7 424 /* Check for an fp-relative STG, ST, or STM. This is probably
7666f43c
JB
425 spilling an argument from a register out into a stack slot.
426 This could be a user instruction, but if we haven't included
427 any other suspicious instructions in the prologue, this
428 could only be an initializing store, which isn't too bad to
429 skip. The consequences of not including arg-to-stack spills
430 are more serious, though --- you don't see the proper values
431 of the arguments. */
432 if ((save_link_state == 3 || save_link_state == 4)
12bffad7
JB
433 && ((instr[0] == 0x50 /* st %rA, D(%rX,%rB) */
434 && (instr[1] & 0xf) == 0 /* %rX is zero, no index reg */
435 && is_arg_reg ((instr[1] >> 4) & 0xf)
436 && ((instr[2] >> 4) & 0xf) == frame_pointer_regidx)
437 || (instr[0] == 0x90 /* stm %rA, %rB, D(%rC) */
438 && is_arg_reg ((instr[1] >> 4) & 0xf)
439 && is_arg_reg (instr[1] & 0xf)
440 && ((instr[2] >> 4) & 0xf) == frame_pointer_regidx)))
7666f43c
JB
441 {
442 valid_prologue = 1;
443 continue;
444 }
445
5769d3cd
AC
446 /* check for STD */
447 if (instr[0] == 0x60 && (instr[2] >> 4) == 0xf)
448 {
449 regidx = instr[1] >> 4;
450 if (regidx == 0 || regidx == 2)
451 varargs_state = 1;
452 if (fprs_saved[regidx])
453 {
454 good_prologue = 0;
455 break;
456 }
457 fprs_saved[regidx] = 1;
458 if (saved_regs)
459 {
460 save_reg_addr = orig_sp + (((instr[2] & 0xf) << 8) + instr[3]);
461 saved_regs[S390_FP0_REGNUM + regidx] = save_reg_addr;
462 }
463 valid_prologue = 1;
464 continue;
465 }
466
467
468 if (const_pool_state == 0)
469 {
470
471 if (GDB_TARGET_IS_ESAME)
472 {
473 /* Check for larl CONST_POOL_REGIDX,offset on ESAME */
474 if ((instr[0] == 0xc0)
475 && (instr[1] == (CONST_POOL_REGIDX << 4)))
476 {
477 const_pool_state = 2;
478 valid_prologue = 1;
479 continue;
480 }
481 }
482 else
483 {
484 /* Check for BASR gpr13,gpr0 used to load constant pool pointer to r13 in old compiler */
485 if (instr[0] == 0xd && (instr[1] & 0xf) == 0
486 && ((instr[1] >> 4) == CONST_POOL_REGIDX))
487 {
488 const_pool_state = 1;
489 valid_prologue = 1;
490 continue;
491 }
492 }
493 /* Check for new fangled bras %r13,newpc to load new constant pool */
494 /* embedded in code, older pre abi compilers also emitted this stuff. */
495 if ((instr[0] == 0xa7) && ((instr[1] & 0xf) == 0x5) &&
496 ((instr[1] >> 4) == CONST_POOL_REGIDX)
497 && ((instr[2] & 0x80) == 0))
498 {
499 const_pool_state = 2;
500 test_pc +=
501 (((((instr[2] & 0xf) << 8) + instr[3]) << 1) - instrlen);
502 valid_prologue = 1;
503 continue;
504 }
505 }
506 /* Check for AGHI or AHI CONST_POOL_REGIDX,val */
507 if (const_pool_state == 1 && (instr[0] == 0xa7) &&
508 ((GDB_TARGET_IS_ESAME &&
509 (instr[1] == ((CONST_POOL_REGIDX << 4) | 0xb))) ||
510 (instr[1] == ((CONST_POOL_REGIDX << 4) | 0xa))))
511 {
512 const_pool_state = 2;
513 valid_prologue = 1;
514 continue;
515 }
516 /* Check for LGR or LR gprx,15 */
517 if ((GDB_TARGET_IS_ESAME &&
518 instr[0] == 0xb9 && instr[1] == 0x04 && (instr[3] & 0xf) == 0xf) ||
519 (instr[0] == 0x18 && (instr[1] & 0xf) == 0xf))
520 {
521 if (GDB_TARGET_IS_ESAME)
522 regidx = instr[3] >> 4;
523 else
524 regidx = instr[1] >> 4;
525 if (save_link_state == 0 && regidx != 0xb)
526 {
527 /* Almost defintely code for
528 decrementing the stack pointer
529 ( i.e. a non leaf function
530 or else leaf with locals ) */
531 save_link_regidx = regidx;
532 save_link_state = 1;
533 valid_prologue = 1;
534 continue;
535 }
536 /* We use this frame pointer for alloca
537 unfortunately we need to assume its gpr11
538 otherwise we would need a smarter prologue
539 walker. */
540 if (!frame_pointer_found && regidx == 0xb)
541 {
542 frame_pointer_regidx = 0xb;
543 frame_pointer_found = 1;
544 if (fextra_info)
545 fextra_info->frame_pointer_saved_pc = test_pc;
546 valid_prologue = 1;
547 continue;
548 }
549 }
550 /* Check for AHI or AGHI gpr15,val */
551 if (save_link_state == 1 && (instr[0] == 0xa7) &&
552 ((GDB_TARGET_IS_ESAME && (instr[1] == 0xfb)) || (instr[1] == 0xfa)))
553 {
554 if (fextra_info)
555 fextra_info->stack_bought =
556 -extract_signed_integer (&instr[2], 2);
557 save_link_state = 3;
558 valid_prologue = 1;
559 continue;
560 }
561 /* Alternatively check for the complex construction for
562 buying more than 32k of stack
563 BRAS gprx,.+8
6df29de2
JB
564 long val
565 s %r15,0(%gprx) gprx currently r1 */
5769d3cd
AC
566 if ((save_link_state == 1) && (instr[0] == 0xa7)
567 && ((instr[1] & 0xf) == 0x5) && (instr[2] == 0)
568 && (instr[3] == 0x4) && ((instr[1] >> 4) != CONST_POOL_REGIDX))
569 {
570 subtract_sp_regidx = instr[1] >> 4;
571 save_link_state = 2;
572 if (fextra_info)
573 target_read_memory (test_pc + instrlen,
574 (char *) &fextra_info->stack_bought,
575 sizeof (fextra_info->stack_bought));
576 test_pc += 4;
577 valid_prologue = 1;
578 continue;
579 }
580 if (save_link_state == 2 && instr[0] == 0x5b
581 && instr[1] == 0xf0 &&
582 instr[2] == (subtract_sp_regidx << 4) && instr[3] == 0)
583 {
584 save_link_state = 3;
585 valid_prologue = 1;
586 continue;
587 }
588 /* check for LA gprx,offset(15) used for varargs */
589 if ((instr[0] == 0x41) && ((instr[2] >> 4) == 0xf) &&
590 ((instr[1] & 0xf) == 0))
591 {
592 /* some code uses gpr7 to point to outgoing args */
593 if (((instr[1] >> 4) == 7) && (save_link_state == 0) &&
594 ((instr[2] & 0xf) == 0)
595 && (instr[3] == S390_STACK_FRAME_OVERHEAD))
596 {
597 valid_prologue = 1;
598 continue;
599 }
600 if (varargs_state == 1)
601 {
602 varargs_state = 2;
603 valid_prologue = 1;
604 continue;
605 }
606 }
607 /* Check for a GOT load */
608
609 if (GDB_TARGET_IS_ESAME)
610 {
611 /* Check for larl GOT_REGIDX, on ESAME */
612 if ((got_state == 0) && (instr[0] == 0xc0)
613 && (instr[1] == (GOT_REGIDX << 4)))
614 {
615 got_state = 2;
616 valid_prologue = 1;
617 continue;
618 }
619 }
620 else
621 {
622 /* check for l GOT_REGIDX,x(CONST_POOL_REGIDX) */
623 if (got_state == 0 && const_pool_state == 2 && instr[0] == 0x58
624 && (instr[2] == (CONST_POOL_REGIDX << 4))
625 && ((instr[1] >> 4) == GOT_REGIDX))
626 {
8ac0e65a
JB
627 got_state = 1;
628 got_load_addr = test_pc;
629 got_load_len = instrlen;
5769d3cd
AC
630 valid_prologue = 1;
631 continue;
632 }
633 /* Check for subsequent ar got_regidx,basr_regidx */
634 if (got_state == 1 && instr[0] == 0x1a &&
635 instr[1] == ((GOT_REGIDX << 4) | CONST_POOL_REGIDX))
636 {
637 got_state = 2;
638 valid_prologue = 1;
639 continue;
640 }
641 }
642 }
643 while (valid_prologue && good_prologue);
644 if (good_prologue)
645 {
8ac0e65a
JB
646 /* If this function doesn't reference the global offset table,
647 then the compiler may use r12 for other things. If the last
648 instruction we saw was a load of r12 from the constant pool,
649 with no subsequent add to make the address PC-relative, then
650 the load was probably a genuine body instruction; don't treat
651 it as part of the prologue. */
652 if (got_state == 1
653 && got_load_addr + got_load_len == test_pc)
654 {
655 test_pc = got_load_addr;
656 instrlen = got_load_len;
657 }
658
659 good_prologue = (((const_pool_state == 0) || (const_pool_state == 2)) &&
5769d3cd
AC
660 ((save_link_state == 0) || (save_link_state == 4)) &&
661 ((varargs_state == 0) || (varargs_state == 2)));
662 }
663 if (fextra_info)
664 {
665 fextra_info->good_prologue = good_prologue;
666 fextra_info->skip_prologue_function_start =
667 (good_prologue ? test_pc : pc);
668 }
09025237
JB
669 if (saved_regs)
670 /* The SP's element of the saved_regs array holds the old SP,
671 not the address at which it is saved. */
672 saved_regs[S390_SP_REGNUM] = orig_sp;
5769d3cd
AC
673 return err;
674}
675
676
a78f21af 677static int
5769d3cd
AC
678s390_check_function_end (CORE_ADDR pc)
679{
680 bfd_byte instr[S390_MAX_INSTR_SIZE];
681 disassemble_info info;
682 int regidx, instrlen;
683
810ecf9f 684 info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func;
5769d3cd
AC
685 instrlen = s390_readinstruction (instr, pc, &info);
686 if (instrlen < 0)
687 return -1;
688 /* check for BR */
689 if (instrlen != 2 || instr[0] != 07 || (instr[1] >> 4) != 0xf)
690 return 0;
691 regidx = instr[1] & 0xf;
692 /* Check for LMG or LG */
693 instrlen =
694 s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4), &info);
695 if (instrlen < 0)
696 return -1;
697 if (GDB_TARGET_IS_ESAME)
698 {
699
700 if (instrlen != 6 || instr[0] != 0xeb || instr[5] != 0x4)
701 return 0;
702 }
703 else if (instrlen != 4 || instr[0] != 0x98)
704 {
705 return 0;
706 }
707 if ((instr[2] >> 4) != 0xf)
708 return 0;
709 if (regidx == 14)
710 return 1;
711 instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8),
712 &info);
713 if (instrlen < 0)
714 return -1;
715 if (GDB_TARGET_IS_ESAME)
716 {
717 /* Check for LG */
718 if (instrlen != 6 || instr[0] != 0xe3 || instr[5] != 0x4)
719 return 0;
720 }
721 else
722 {
723 /* Check for L */
724 if (instrlen != 4 || instr[0] != 0x58)
725 return 0;
726 }
727 if (instr[2] >> 4 != 0xf)
728 return 0;
729 if (instr[1] >> 4 != regidx)
730 return 0;
731 return 1;
732}
733
734static CORE_ADDR
735s390_sniff_pc_function_start (CORE_ADDR pc, struct frame_info *fi)
736{
737 CORE_ADDR function_start, test_function_start;
738 int loop_cnt, err, function_end;
739 struct frame_extra_info fextra_info;
740 function_start = get_pc_function_start (pc);
741
742 if (function_start == 0)
743 {
744 test_function_start = pc;
745 if (test_function_start & 1)
746 return 0; /* This has to be bogus */
747 loop_cnt = 0;
748 do
749 {
750
751 err =
752 s390_get_frame_info (test_function_start, &fextra_info, fi, 1);
753 loop_cnt++;
754 test_function_start -= 2;
755 function_end = s390_check_function_end (test_function_start);
756 }
757 while (!(function_end == 1 || err || loop_cnt >= 4096 ||
758 (fextra_info.good_prologue)));
759 if (fextra_info.good_prologue)
760 function_start = fextra_info.function_start;
761 else if (function_end == 1)
762 function_start = test_function_start;
763 }
764 return function_start;
765}
766
767
768
a78f21af 769static CORE_ADDR
5769d3cd
AC
770s390_function_start (struct frame_info *fi)
771{
772 CORE_ADDR function_start = 0;
773
da50a4b7
AC
774 if (get_frame_extra_info (fi) && get_frame_extra_info (fi)->initialised)
775 function_start = get_frame_extra_info (fi)->function_start;
50abf9e5 776 else if (get_frame_pc (fi))
be41e9f4 777 function_start = get_frame_func (fi);
5769d3cd
AC
778 return function_start;
779}
780
781
782
783
a78f21af 784static int
5769d3cd
AC
785s390_frameless_function_invocation (struct frame_info *fi)
786{
787 struct frame_extra_info fextra_info, *fextra_info_ptr;
788 int frameless = 0;
789
11c02a10 790 if (get_next_frame (fi) == NULL) /* no may be frameless */
5769d3cd 791 {
da50a4b7
AC
792 if (get_frame_extra_info (fi))
793 fextra_info_ptr = get_frame_extra_info (fi);
5769d3cd
AC
794 else
795 {
796 fextra_info_ptr = &fextra_info;
50abf9e5 797 s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi),
5769d3cd
AC
798 fextra_info_ptr, fi, 1);
799 }
800 frameless = ((fextra_info_ptr->stack_bought == 0));
801 }
802 return frameless;
803
804}
805
806
807static int
808s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi,
809 CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc)
810{
811 bfd_byte instr[S390_MAX_INSTR_SIZE];
812 disassemble_info info;
813 int instrlen;
814 CORE_ADDR scontext;
815 int retval = 0;
816 CORE_ADDR orig_sp;
817 CORE_ADDR temp_sregs;
818
819 scontext = temp_sregs = 0;
820
810ecf9f 821 info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func;
5769d3cd
AC
822 instrlen = s390_readinstruction (instr, pc, &info);
823 if (sigcaller_pc)
824 *sigcaller_pc = 0;
825 if (((instrlen == S390_SYSCALL_SIZE) &&
826 (instr[0] == S390_SYSCALL_OPCODE)) &&
827 ((instr[1] == s390_NR_sigreturn) || (instr[1] == s390_NR_rt_sigreturn)))
828 {
829 if (sighandler_fi)
830 {
831 if (s390_frameless_function_invocation (sighandler_fi))
1e2330ba 832 orig_sp = get_frame_base (sighandler_fi);
5769d3cd
AC
833 else
834 orig_sp = ADDR_BITS_REMOVE ((CORE_ADDR)
1e2330ba 835 read_memory_integer (get_frame_base (sighandler_fi),
5769d3cd
AC
836 S390_GPR_SIZE));
837 if (orig_sp && sigcaller_pc)
838 {
839 scontext = orig_sp + S390_SIGNAL_FRAMESIZE;
840 if (pc == scontext && instr[1] == s390_NR_rt_sigreturn)
841 {
842 /* We got a new style rt_signal */
843 /* get address of read ucontext->uc_mcontext */
844 temp_sregs = orig_sp + (GDB_TARGET_IS_ESAME ?
845 S390X_UC_MCONTEXT_OFFSET :
846 S390_UC_MCONTEXT_OFFSET);
847 }
848 else
849 {
850 /* read sigcontext->sregs */
851 temp_sregs = ADDR_BITS_REMOVE ((CORE_ADDR)
852 read_memory_integer (scontext
853 +
854 (GDB_TARGET_IS_ESAME
855 ?
856 S390X_SIGCONTEXT_SREGS_OFFSET
857 :
858 S390_SIGCONTEXT_SREGS_OFFSET),
859 S390_GPR_SIZE));
860
861 }
862 /* read sigregs->psw.addr */
863 *sigcaller_pc =
864 ADDR_BITS_REMOVE ((CORE_ADDR)
865 read_memory_integer (temp_sregs +
866 REGISTER_BYTE
867 (S390_PC_REGNUM),
868 S390_PSW_ADDR_SIZE));
869 }
870 }
871 retval = 1;
872 }
873 if (sregs)
874 *sregs = temp_sregs;
875 return retval;
876}
877
878/*
879 We need to do something better here but this will keep us out of trouble
880 for the moment.
881 For some reason the blockframe.c calls us with fi->next->fromleaf
882 so this seems of little use to us. */
a78f21af 883static CORE_ADDR
5769d3cd
AC
884s390_init_frame_pc_first (int next_fromleaf, struct frame_info *fi)
885{
886 CORE_ADDR sigcaller_pc;
97f46953 887 CORE_ADDR pc = 0;
5769d3cd
AC
888 if (next_fromleaf)
889 {
97f46953 890 pc = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
5769d3cd
AC
891 /* fix signal handlers */
892 }
97f46953
AC
893 else if (get_next_frame (fi) && get_frame_pc (get_next_frame (fi)))
894 pc = s390_frame_saved_pc_nofix (get_next_frame (fi));
895 if (pc && get_next_frame (fi) && get_frame_base (get_next_frame (fi))
896 && s390_is_sigreturn (pc, get_next_frame (fi), NULL, &sigcaller_pc))
5769d3cd 897 {
97f46953 898 pc = sigcaller_pc;
5769d3cd 899 }
97f46953 900 return pc;
5769d3cd
AC
901}
902
a78f21af 903static void
5769d3cd
AC
904s390_init_extra_frame_info (int fromleaf, struct frame_info *fi)
905{
a00a19e9 906 frame_extra_info_zalloc (fi, sizeof (struct frame_extra_info));
50abf9e5
AC
907 if (get_frame_pc (fi))
908 s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi),
da50a4b7 909 get_frame_extra_info (fi), fi, 1);
5769d3cd 910 else
da50a4b7 911 s390_memset_extra_info (get_frame_extra_info (fi));
5769d3cd
AC
912}
913
914/* If saved registers of frame FI are not known yet, read and cache them.
915 &FEXTRA_INFOP contains struct frame_extra_info; TDATAP can be NULL,
916 in which case the framedata are read. */
917
a78f21af 918static void
5769d3cd
AC
919s390_frame_init_saved_regs (struct frame_info *fi)
920{
921
922 int quick;
923
b2fb4676 924 if (get_frame_saved_regs (fi) == NULL)
5769d3cd
AC
925 {
926 /* zalloc memsets the saved regs */
927 frame_saved_regs_zalloc (fi);
50abf9e5 928 if (get_frame_pc (fi))
5769d3cd 929 {
da50a4b7
AC
930 quick = (get_frame_extra_info (fi)
931 && get_frame_extra_info (fi)->initialised
932 && get_frame_extra_info (fi)->good_prologue);
933 s390_get_frame_info (quick
934 ? get_frame_extra_info (fi)->function_start
935 : s390_sniff_pc_function_start (get_frame_pc (fi), fi),
936 get_frame_extra_info (fi), fi, !quick);
5769d3cd
AC
937 }
938 }
939}
940
941
942
5769d3cd
AC
943static CORE_ADDR
944s390_frame_saved_pc_nofix (struct frame_info *fi)
945{
da50a4b7
AC
946 if (get_frame_extra_info (fi) && get_frame_extra_info (fi)->saved_pc_valid)
947 return get_frame_extra_info (fi)->saved_pc;
5c3cf190 948
1e2330ba
AC
949 if (deprecated_generic_find_dummy_frame (get_frame_pc (fi),
950 get_frame_base (fi)))
951 return deprecated_read_register_dummy (get_frame_pc (fi),
952 get_frame_base (fi), S390_PC_REGNUM);
5c3cf190 953
5769d3cd 954 s390_frame_init_saved_regs (fi);
da50a4b7 955 if (get_frame_extra_info (fi))
5769d3cd 956 {
da50a4b7
AC
957 get_frame_extra_info (fi)->saved_pc_valid = 1;
958 if (get_frame_extra_info (fi)->good_prologue
b2fb4676 959 && get_frame_saved_regs (fi)[S390_RETADDR_REGNUM])
da50a4b7 960 get_frame_extra_info (fi)->saved_pc
529765f4 961 = ADDR_BITS_REMOVE (read_memory_integer
b2fb4676 962 (get_frame_saved_regs (fi)[S390_RETADDR_REGNUM],
529765f4
JB
963 S390_GPR_SIZE));
964 else
da50a4b7 965 get_frame_extra_info (fi)->saved_pc
529765f4 966 = ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
da50a4b7 967 return get_frame_extra_info (fi)->saved_pc;
5769d3cd
AC
968 }
969 return 0;
970}
971
a78f21af 972static CORE_ADDR
5769d3cd
AC
973s390_frame_saved_pc (struct frame_info *fi)
974{
975 CORE_ADDR saved_pc = 0, sig_pc;
976
da50a4b7
AC
977 if (get_frame_extra_info (fi)
978 && get_frame_extra_info (fi)->sig_fixed_saved_pc_valid)
979 return get_frame_extra_info (fi)->sig_fixed_saved_pc;
5769d3cd
AC
980 saved_pc = s390_frame_saved_pc_nofix (fi);
981
da50a4b7 982 if (get_frame_extra_info (fi))
5769d3cd 983 {
da50a4b7 984 get_frame_extra_info (fi)->sig_fixed_saved_pc_valid = 1;
5769d3cd
AC
985 if (saved_pc)
986 {
987 if (s390_is_sigreturn (saved_pc, fi, NULL, &sig_pc))
988 saved_pc = sig_pc;
989 }
da50a4b7 990 get_frame_extra_info (fi)->sig_fixed_saved_pc = saved_pc;
5769d3cd
AC
991 }
992 return saved_pc;
993}
994
995
996
997
5a203e44
AC
998/* We want backtraces out of signal handlers so we don't set
999 (get_frame_type (thisframe) == SIGTRAMP_FRAME) to 1 */
5769d3cd 1000
a78f21af 1001static CORE_ADDR
5769d3cd
AC
1002s390_frame_chain (struct frame_info *thisframe)
1003{
1004 CORE_ADDR prev_fp = 0;
1005
1e2330ba
AC
1006 if (deprecated_generic_find_dummy_frame (get_frame_pc (thisframe),
1007 get_frame_base (thisframe)))
1008 return deprecated_read_register_dummy (get_frame_pc (thisframe),
1009 get_frame_base (thisframe),
135c175f 1010 S390_SP_REGNUM);
5769d3cd
AC
1011 else
1012 {
1013 int sigreturn = 0;
1014 CORE_ADDR sregs = 0;
1015 struct frame_extra_info prev_fextra_info;
1016
1017 memset (&prev_fextra_info, 0, sizeof (prev_fextra_info));
50abf9e5 1018 if (get_frame_pc (thisframe))
5769d3cd
AC
1019 {
1020 CORE_ADDR saved_pc, sig_pc;
1021
1022 saved_pc = s390_frame_saved_pc_nofix (thisframe);
1023 if (saved_pc)
1024 {
1025 if ((sigreturn =
1026 s390_is_sigreturn (saved_pc, thisframe, &sregs, &sig_pc)))
1027 saved_pc = sig_pc;
1028 s390_get_frame_info (s390_sniff_pc_function_start
1029 (saved_pc, NULL), &prev_fextra_info, NULL,
1030 1);
1031 }
1032 }
1033 if (sigreturn)
1034 {
1035 /* read sigregs,regs.gprs[11 or 15] */
1036 prev_fp = read_memory_integer (sregs +
1037 REGISTER_BYTE (S390_GP0_REGNUM +
1038 (prev_fextra_info.
1039 frame_pointer_saved_pc
1040 ? 11 : 15)),
1041 S390_GPR_SIZE);
da50a4b7 1042 get_frame_extra_info (thisframe)->sigcontext = sregs;
5769d3cd
AC
1043 }
1044 else
1045 {
b2fb4676 1046 if (get_frame_saved_regs (thisframe))
5769d3cd 1047 {
5769d3cd
AC
1048 int regno;
1049
31c4d430 1050 if (prev_fextra_info.frame_pointer_saved_pc
b2fb4676 1051 && get_frame_saved_regs (thisframe)[S390_FRAME_REGNUM])
31c4d430
JB
1052 regno = S390_FRAME_REGNUM;
1053 else
1054 regno = S390_SP_REGNUM;
1055
b2fb4676 1056 if (get_frame_saved_regs (thisframe)[regno])
31c4d430
JB
1057 {
1058 /* The SP's entry of `saved_regs' is special. */
1059 if (regno == S390_SP_REGNUM)
b2fb4676 1060 prev_fp = get_frame_saved_regs (thisframe)[regno];
31c4d430
JB
1061 else
1062 prev_fp =
b2fb4676 1063 read_memory_integer (get_frame_saved_regs (thisframe)[regno],
31c4d430
JB
1064 S390_GPR_SIZE);
1065 }
5769d3cd
AC
1066 }
1067 }
1068 }
1069 return ADDR_BITS_REMOVE (prev_fp);
1070}
1071
1072/*
1073 Whether struct frame_extra_info is actually needed I'll have to figure
1074 out as our frames are similar to rs6000 there is a possibility
1075 i386 dosen't need it. */
1076
1077
1078
1079/* a given return value in `regbuf' with a type `valtype', extract and copy its
1080 value into `valbuf' */
a78f21af 1081static void
5769d3cd
AC
1082s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
1083{
1084 /* floats and doubles are returned in fpr0. fpr's have a size of 8 bytes.
1085 We need to truncate the return value into float size (4 byte) if
1086 necessary. */
1087 int len = TYPE_LENGTH (valtype);
1088
1089 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
f2c6cfba 1090 memcpy (valbuf, &regbuf[REGISTER_BYTE (S390_FP0_REGNUM)], len);
5769d3cd
AC
1091 else
1092 {
1093 int offset = 0;
1094 /* return value is copied starting from r2. */
1095 if (TYPE_LENGTH (valtype) < S390_GPR_SIZE)
1096 offset = S390_GPR_SIZE - TYPE_LENGTH (valtype);
1097 memcpy (valbuf,
1098 regbuf + REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset,
1099 TYPE_LENGTH (valtype));
1100 }
1101}
1102
1103
1104static char *
1105s390_promote_integer_argument (struct type *valtype, char *valbuf,
1106 char *reg_buff, int *arglen)
1107{
1108 char *value = valbuf;
1109 int len = TYPE_LENGTH (valtype);
1110
1111 if (len < S390_GPR_SIZE)
1112 {
1113 /* We need to upgrade this value to a register to pass it correctly */
1114 int idx, diff = S390_GPR_SIZE - len, negative =
1115 (!TYPE_UNSIGNED (valtype) && value[0] & 0x80);
1116 for (idx = 0; idx < S390_GPR_SIZE; idx++)
1117 {
1118 reg_buff[idx] = (idx < diff ? (negative ? 0xff : 0x0) :
1119 value[idx - diff]);
1120 }
1121 value = reg_buff;
1122 *arglen = S390_GPR_SIZE;
1123 }
1124 else
1125 {
1126 if (len & (S390_GPR_SIZE - 1))
1127 {
1128 fprintf_unfiltered (gdb_stderr,
1129 "s390_promote_integer_argument detected an argument not "
1130 "a multiple of S390_GPR_SIZE & greater than S390_GPR_SIZE "
1131 "we might not deal with this correctly.\n");
1132 }
1133 *arglen = len;
1134 }
1135
1136 return (value);
1137}
1138
a78f21af 1139static void
5769d3cd
AC
1140s390_store_return_value (struct type *valtype, char *valbuf)
1141{
1142 int arglen;
b1e29e33 1143 char *reg_buff = alloca (max (S390_FPR_SIZE, DEPRECATED_REGISTER_SIZE)), *value;
5769d3cd
AC
1144
1145 if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
1146 {
03a013f4
JB
1147 if (TYPE_LENGTH (valtype) == 4
1148 || TYPE_LENGTH (valtype) == 8)
73937e03
AC
1149 deprecated_write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM),
1150 valbuf, TYPE_LENGTH (valtype));
03a013f4
JB
1151 else
1152 error ("GDB is unable to return `long double' values "
1153 "on this architecture.");
5769d3cd
AC
1154 }
1155 else
1156 {
1157 value =
1158 s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen);
1159 /* Everything else is returned in GPR2 and up. */
73937e03
AC
1160 deprecated_write_register_bytes (REGISTER_BYTE (S390_GP0_REGNUM + 2),
1161 value, arglen);
5769d3cd
AC
1162 }
1163}
1164static int
1165gdb_print_insn_s390 (bfd_vma memaddr, disassemble_info * info)
1166{
1167 bfd_byte instrbuff[S390_MAX_INSTR_SIZE];
1168 int instrlen, cnt;
1169
1170 instrlen = s390_readinstruction (instrbuff, (CORE_ADDR) memaddr, info);
1171 if (instrlen < 0)
1172 {
1173 (*info->memory_error_func) (instrlen, memaddr, info);
1174 return -1;
1175 }
1176 for (cnt = 0; cnt < instrlen; cnt++)
1177 info->fprintf_func (info->stream, "%02X ", instrbuff[cnt]);
1178 for (cnt = instrlen; cnt < S390_MAX_INSTR_SIZE; cnt++)
1179 info->fprintf_func (info->stream, " ");
1180 instrlen = print_insn_s390 (memaddr, info);
1181 return instrlen;
1182}
1183
1184
1185
1186/* Not the most efficent code in the world */
a78f21af 1187static int
5ae5f592 1188s390_fp_regnum (void)
5769d3cd
AC
1189{
1190 int regno = S390_SP_REGNUM;
1191 struct frame_extra_info fextra_info;
1192
1193 CORE_ADDR pc = ADDR_BITS_REMOVE (read_register (S390_PC_REGNUM));
1194
1195 s390_get_frame_info (s390_sniff_pc_function_start (pc, NULL), &fextra_info,
1196 NULL, 1);
1197 if (fextra_info.frame_pointer_saved_pc)
1198 regno = S390_FRAME_REGNUM;
1199 return regno;
1200}
1201
a78f21af 1202static CORE_ADDR
5ae5f592 1203s390_read_fp (void)
5769d3cd
AC
1204{
1205 return read_register (s390_fp_regnum ());
1206}
1207
1208
4c8287ac
JB
1209static void
1210s390_pop_frame_regular (struct frame_info *frame)
5769d3cd 1211{
4c8287ac
JB
1212 int regnum;
1213
8bedc050 1214 write_register (S390_PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
4c8287ac
JB
1215
1216 /* Restore any saved registers. */
b2fb4676 1217 if (get_frame_saved_regs (frame))
1a889ea5
JB
1218 {
1219 for (regnum = 0; regnum < NUM_REGS; regnum++)
b2fb4676 1220 if (get_frame_saved_regs (frame)[regnum] != 0)
1a889ea5
JB
1221 {
1222 ULONGEST value;
1223
b2fb4676 1224 value = read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
1a889ea5
JB
1225 REGISTER_RAW_SIZE (regnum));
1226 write_register (regnum, value);
1227 }
1228
1229 /* Actually cut back the stack. Remember that the SP's element of
1230 saved_regs is the old SP itself, not the address at which it is
1231 saved. */
b2fb4676 1232 write_register (S390_SP_REGNUM, get_frame_saved_regs (frame)[S390_SP_REGNUM]);
1a889ea5 1233 }
5769d3cd 1234
4c8287ac
JB
1235 /* Throw away any cached frame information. */
1236 flush_cached_frames ();
5769d3cd
AC
1237}
1238
4c8287ac
JB
1239
1240/* Destroy the innermost (Top-Of-Stack) stack frame, restoring the
1241 machine state that was in effect before the frame was created.
1242 Used in the contexts of the "return" command, and of
1243 target function calls from the debugger. */
a78f21af 1244static void
5ae5f592 1245s390_pop_frame (void)
4c8287ac
JB
1246{
1247 /* This function checks for and handles generic dummy frames, and
1248 calls back to our function for ordinary frames. */
1249 generic_pop_current_frame (s390_pop_frame_regular);
1250}
1251
1252
78f8b424
JB
1253/* Return non-zero if TYPE is an integer-like type, zero otherwise.
1254 "Integer-like" types are those that should be passed the way
1255 integers are: integers, enums, ranges, characters, and booleans. */
1256static int
1257is_integer_like (struct type *type)
1258{
1259 enum type_code code = TYPE_CODE (type);
1260
1261 return (code == TYPE_CODE_INT
1262 || code == TYPE_CODE_ENUM
1263 || code == TYPE_CODE_RANGE
1264 || code == TYPE_CODE_CHAR
1265 || code == TYPE_CODE_BOOL);
1266}
1267
1268
1269/* Return non-zero if TYPE is a pointer-like type, zero otherwise.
1270 "Pointer-like" types are those that should be passed the way
1271 pointers are: pointers and references. */
1272static int
1273is_pointer_like (struct type *type)
1274{
1275 enum type_code code = TYPE_CODE (type);
1276
1277 return (code == TYPE_CODE_PTR
1278 || code == TYPE_CODE_REF);
1279}
1280
1281
20a940cc
JB
1282/* Return non-zero if TYPE is a `float singleton' or `double
1283 singleton', zero otherwise.
1284
1285 A `T singleton' is a struct type with one member, whose type is
1286 either T or a `T singleton'. So, the following are all float
1287 singletons:
1288
1289 struct { float x };
1290 struct { struct { float x; } x; };
1291 struct { struct { struct { float x; } x; } x; };
1292
1293 ... and so on.
1294
1295 WHY THE HECK DO WE CARE ABOUT THIS??? Well, it turns out that GCC
1296 passes all float singletons and double singletons as if they were
1297 simply floats or doubles. This is *not* what the ABI says it
1298 should do. */
1299static int
1300is_float_singleton (struct type *type)
1301{
1302 return (TYPE_CODE (type) == TYPE_CODE_STRUCT
1303 && TYPE_NFIELDS (type) == 1
1304 && (TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_FLT
1305 || is_float_singleton (TYPE_FIELD_TYPE (type, 0))));
1306}
1307
1308
1309/* Return non-zero if TYPE is a struct-like type, zero otherwise.
1310 "Struct-like" types are those that should be passed as structs are:
1311 structs and unions.
1312
1313 As an odd quirk, not mentioned in the ABI, GCC passes float and
1314 double singletons as if they were a plain float, double, etc. (The
1315 corresponding union types are handled normally.) So we exclude
1316 those types here. *shrug* */
1317static int
1318is_struct_like (struct type *type)
1319{
1320 enum type_code code = TYPE_CODE (type);
1321
1322 return (code == TYPE_CODE_UNION
1323 || (code == TYPE_CODE_STRUCT && ! is_float_singleton (type)));
1324}
1325
1326
1327/* Return non-zero if TYPE is a float-like type, zero otherwise.
1328 "Float-like" types are those that should be passed as
1329 floating-point values are.
1330
1331 You'd think this would just be floats, doubles, long doubles, etc.
1332 But as an odd quirk, not mentioned in the ABI, GCC passes float and
1333 double singletons as if they were a plain float, double, etc. (The
1334 corresponding union types are handled normally.) So we exclude
1335 those types here. *shrug* */
1336static int
1337is_float_like (struct type *type)
1338{
1339 return (TYPE_CODE (type) == TYPE_CODE_FLT
1340 || is_float_singleton (type));
1341}
1342
1343
78f8b424
JB
1344/* Return non-zero if TYPE is considered a `DOUBLE_OR_FLOAT', as
1345 defined by the parameter passing conventions described in the
ca557f44 1346 "GNU/Linux for S/390 ELF Application Binary Interface Supplement".
78f8b424
JB
1347 Otherwise, return zero. */
1348static int
1349is_double_or_float (struct type *type)
1350{
20a940cc 1351 return (is_float_like (type)
78f8b424
JB
1352 && (TYPE_LENGTH (type) == 4
1353 || TYPE_LENGTH (type) == 8));
1354}
1355
5769d3cd 1356
78f8b424 1357/* Return non-zero if TYPE is considered a `SIMPLE_ARG', as defined by
ca557f44
AC
1358 the parameter passing conventions described in the "GNU/Linux for
1359 S/390 ELF Application Binary Interface Supplement". Return zero
1360 otherwise. */
78f8b424
JB
1361static int
1362is_simple_arg (struct type *type)
1363{
78f8b424
JB
1364 unsigned length = TYPE_LENGTH (type);
1365
a1677dfb
JB
1366 /* This is almost a direct translation of the ABI's language, except
1367 that we have to exclude 8-byte structs; those are DOUBLE_ARGs. */
78f8b424
JB
1368 return ((is_integer_like (type) && length <= 4)
1369 || is_pointer_like (type)
20a940cc
JB
1370 || (is_struct_like (type) && length != 8)
1371 || (is_float_like (type) && length == 16));
78f8b424
JB
1372}
1373
1374
1375/* Return non-zero if TYPE should be passed as a pointer to a copy,
1376 zero otherwise. TYPE must be a SIMPLE_ARG, as recognized by
1377 `is_simple_arg'. */
1378static int
1379pass_by_copy_ref (struct type *type)
1380{
78f8b424
JB
1381 unsigned length = TYPE_LENGTH (type);
1382
20a940cc
JB
1383 return ((is_struct_like (type) && length != 1 && length != 2 && length != 4)
1384 || (is_float_like (type) && length == 16));
78f8b424
JB
1385}
1386
1387
1388/* Return ARG, a `SIMPLE_ARG', sign-extended or zero-extended to a full
1389 word as required for the ABI. */
1390static LONGEST
1391extend_simple_arg (struct value *arg)
1392{
1393 struct type *type = VALUE_TYPE (arg);
1394
1395 /* Even structs get passed in the least significant bits of the
1396 register / memory word. It's not really right to extract them as
1397 an integer, but it does take care of the extension. */
1398 if (TYPE_UNSIGNED (type))
1399 return extract_unsigned_integer (VALUE_CONTENTS (arg),
1400 TYPE_LENGTH (type));
1401 else
1402 return extract_signed_integer (VALUE_CONTENTS (arg),
1403 TYPE_LENGTH (type));
1404}
1405
1406
1407/* Return non-zero if TYPE is a `DOUBLE_ARG', as defined by the
ca557f44
AC
1408 parameter passing conventions described in the "GNU/Linux for S/390
1409 ELF Application Binary Interface Supplement". Return zero
1410 otherwise. */
78f8b424
JB
1411static int
1412is_double_arg (struct type *type)
1413{
78f8b424
JB
1414 unsigned length = TYPE_LENGTH (type);
1415
1416 return ((is_integer_like (type)
20a940cc 1417 || is_struct_like (type))
78f8b424
JB
1418 && length == 8);
1419}
1420
1421
1422/* Round ADDR up to the next N-byte boundary. N must be a power of
1423 two. */
1424static CORE_ADDR
1425round_up (CORE_ADDR addr, int n)
1426{
1427 /* Check that N is really a power of two. */
1428 gdb_assert (n && (n & (n-1)) == 0);
1429 return ((addr + n - 1) & -n);
1430}
1431
1432
1433/* Round ADDR down to the next N-byte boundary. N must be a power of
1434 two. */
1435static CORE_ADDR
1436round_down (CORE_ADDR addr, int n)
1437{
1438 /* Check that N is really a power of two. */
1439 gdb_assert (n && (n & (n-1)) == 0);
1440 return (addr & -n);
1441}
1442
1443
1444/* Return the alignment required by TYPE. */
1445static int
1446alignment_of (struct type *type)
1447{
1448 int alignment;
1449
1450 if (is_integer_like (type)
1451 || is_pointer_like (type)
1452 || TYPE_CODE (type) == TYPE_CODE_FLT)
1453 alignment = TYPE_LENGTH (type);
1454 else if (TYPE_CODE (type) == TYPE_CODE_STRUCT
1455 || TYPE_CODE (type) == TYPE_CODE_UNION)
1456 {
1457 int i;
1458
1459 alignment = 1;
1460 for (i = 0; i < TYPE_NFIELDS (type); i++)
1461 {
1462 int field_alignment = alignment_of (TYPE_FIELD_TYPE (type, i));
1463
1464 if (field_alignment > alignment)
1465 alignment = field_alignment;
1466 }
1467 }
1468 else
1469 alignment = 1;
1470
1471 /* Check that everything we ever return is a power of two. Lots of
1472 code doesn't want to deal with aligning things to arbitrary
1473 boundaries. */
1474 gdb_assert ((alignment & (alignment - 1)) == 0);
1475
1476 return alignment;
1477}
1478
1479
1480/* Put the actual parameter values pointed to by ARGS[0..NARGS-1] in
ca557f44
AC
1481 place to be passed to a function, as specified by the "GNU/Linux
1482 for S/390 ELF Application Binary Interface Supplement".
78f8b424
JB
1483
1484 SP is the current stack pointer. We must put arguments, links,
1485 padding, etc. whereever they belong, and return the new stack
1486 pointer value.
1487
1488 If STRUCT_RETURN is non-zero, then the function we're calling is
1489 going to return a structure by value; STRUCT_ADDR is the address of
1490 a block we've allocated for it on the stack.
1491
1492 Our caller has taken care of any type promotions needed to satisfy
1493 prototypes or the old K&R argument-passing rules. */
a78f21af 1494static CORE_ADDR
d45fc520 1495s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
5769d3cd
AC
1496 int struct_return, CORE_ADDR struct_addr)
1497{
78f8b424
JB
1498 int i;
1499 int pointer_size = (TARGET_PTR_BIT / TARGET_CHAR_BIT);
5769d3cd 1500
78f8b424
JB
1501 /* The number of arguments passed by reference-to-copy. */
1502 int num_copies;
5769d3cd 1503
78f8b424
JB
1504 /* If the i'th argument is passed as a reference to a copy, then
1505 copy_addr[i] is the address of the copy we made. */
1506 CORE_ADDR *copy_addr = alloca (nargs * sizeof (CORE_ADDR));
5769d3cd 1507
78f8b424
JB
1508 /* Build the reference-to-copy area. */
1509 num_copies = 0;
1510 for (i = 0; i < nargs; i++)
1511 {
1512 struct value *arg = args[i];
1513 struct type *type = VALUE_TYPE (arg);
1514 unsigned length = TYPE_LENGTH (type);
5769d3cd 1515
78f8b424
JB
1516 if (is_simple_arg (type)
1517 && pass_by_copy_ref (type))
01c464e9 1518 {
78f8b424
JB
1519 sp -= length;
1520 sp = round_down (sp, alignment_of (type));
1521 write_memory (sp, VALUE_CONTENTS (arg), length);
1522 copy_addr[i] = sp;
1523 num_copies++;
01c464e9 1524 }
5769d3cd 1525 }
5769d3cd 1526
78f8b424
JB
1527 /* Reserve space for the parameter area. As a conservative
1528 simplification, we assume that everything will be passed on the
1529 stack. */
1530 {
1531 int i;
1532
1533 for (i = 0; i < nargs; i++)
1534 {
1535 struct value *arg = args[i];
1536 struct type *type = VALUE_TYPE (arg);
1537 int length = TYPE_LENGTH (type);
1538
1539 sp = round_down (sp, alignment_of (type));
1540
1541 /* SIMPLE_ARG values get extended to 32 bits. Assume every
1542 argument is. */
1543 if (length < 4) length = 4;
1544 sp -= length;
1545 }
1546 }
1547
1548 /* Include space for any reference-to-copy pointers. */
1549 sp = round_down (sp, pointer_size);
1550 sp -= num_copies * pointer_size;
1551
1552 /* After all that, make sure it's still aligned on an eight-byte
1553 boundary. */
1554 sp = round_down (sp, 8);
1555
1556 /* Finally, place the actual parameters, working from SP towards
1557 higher addresses. The code above is supposed to reserve enough
1558 space for this. */
1559 {
1560 int fr = 0;
1561 int gr = 2;
1562 CORE_ADDR starg = sp;
1563
1564 for (i = 0; i < nargs; i++)
1565 {
1566 struct value *arg = args[i];
1567 struct type *type = VALUE_TYPE (arg);
1568
1569 if (is_double_or_float (type)
1570 && fr <= 2)
1571 {
1572 /* When we store a single-precision value in an FP register,
1573 it occupies the leftmost bits. */
73937e03
AC
1574 deprecated_write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM + fr),
1575 VALUE_CONTENTS (arg),
1576 TYPE_LENGTH (type));
78f8b424
JB
1577 fr += 2;
1578 }
1579 else if (is_simple_arg (type)
1580 && gr <= 6)
1581 {
1582 /* Do we need to pass a pointer to our copy of this
1583 argument? */
1584 if (pass_by_copy_ref (type))
1585 write_register (S390_GP0_REGNUM + gr, copy_addr[i]);
1586 else
1587 write_register (S390_GP0_REGNUM + gr, extend_simple_arg (arg));
1588
1589 gr++;
1590 }
1591 else if (is_double_arg (type)
1592 && gr <= 5)
1593 {
4caf0990
AC
1594 deprecated_write_register_gen (S390_GP0_REGNUM + gr,
1595 VALUE_CONTENTS (arg));
1596 deprecated_write_register_gen (S390_GP0_REGNUM + gr + 1,
1597 VALUE_CONTENTS (arg) + 4);
78f8b424
JB
1598 gr += 2;
1599 }
1600 else
1601 {
1602 /* The `OTHER' case. */
1603 enum type_code code = TYPE_CODE (type);
1604 unsigned length = TYPE_LENGTH (type);
1605
1606 /* If we skipped r6 because we couldn't fit a DOUBLE_ARG
1607 in it, then don't go back and use it again later. */
1608 if (is_double_arg (type) && gr == 6)
1609 gr = 7;
1610
1611 if (is_simple_arg (type))
1612 {
1613 /* Simple args are always either extended to 32 bits,
1614 or pointers. */
1615 starg = round_up (starg, 4);
1616
1617 /* Do we need to pass a pointer to our copy of this
1618 argument? */
1619 if (pass_by_copy_ref (type))
1620 write_memory_signed_integer (starg, pointer_size,
1621 copy_addr[i]);
1622 else
1623 /* Simple args are always extended to 32 bits. */
1624 write_memory_signed_integer (starg, 4,
1625 extend_simple_arg (arg));
1626 starg += 4;
1627 }
1628 else
1629 {
20a940cc
JB
1630 /* You'd think we should say:
1631 starg = round_up (starg, alignment_of (type));
1632 Unfortunately, GCC seems to simply align the stack on
1633 a four-byte boundary, even when passing doubles. */
1634 starg = round_up (starg, 4);
78f8b424
JB
1635 write_memory (starg, VALUE_CONTENTS (arg), length);
1636 starg += length;
1637 }
1638 }
1639 }
1640 }
1641
1642 /* Allocate the standard frame areas: the register save area, the
1643 word reserved for the compiler (which seems kind of meaningless),
1644 and the back chain pointer. */
1645 sp -= 96;
1646
1647 /* Write the back chain pointer into the first word of the stack
1648 frame. This will help us get backtraces from within functions
1649 called from GDB. */
1650 write_memory_unsigned_integer (sp, (TARGET_PTR_BIT / TARGET_CHAR_BIT),
0ba6dca9 1651 deprecated_read_fp ());
78f8b424
JB
1652
1653 return sp;
5769d3cd
AC
1654}
1655
c8f9d51c 1656
4074e13c
JB
1657static CORE_ADDR
1658s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
1659{
1660 /* Both the 32- and 64-bit ABI's say that the stack pointer should
1661 always be aligned on an eight-byte boundary. */
1662 return (addr & -8);
1663}
1664
1665
c8f9d51c
JB
1666static int
1667s390_use_struct_convention (int gcc_p, struct type *value_type)
1668{
1669 enum type_code code = TYPE_CODE (value_type);
1670
1671 return (code == TYPE_CODE_STRUCT
1672 || code == TYPE_CODE_UNION);
1673}
1674
1675
5769d3cd
AC
1676/* Return the GDB type object for the "standard" data type
1677 of data in register N. */
a78f21af 1678static struct type *
5769d3cd
AC
1679s390_register_virtual_type (int regno)
1680{
b09677dc
JB
1681 if (S390_FP0_REGNUM <= regno && regno < S390_FP0_REGNUM + S390_NUM_FPRS)
1682 return builtin_type_double;
1683 else
1684 return builtin_type_int;
5769d3cd
AC
1685}
1686
1687
a78f21af 1688static struct type *
5769d3cd
AC
1689s390x_register_virtual_type (int regno)
1690{
1691 return (regno == S390_FPC_REGNUM) ||
1692 (regno >= S390_FIRST_ACR && regno <= S390_LAST_ACR) ? builtin_type_int :
1693 (regno >= S390_FP0_REGNUM) ? builtin_type_double : builtin_type_long;
1694}
1695
1696
1697
a78f21af 1698static void
5769d3cd
AC
1699s390_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
1700{
1701 write_register (S390_GP0_REGNUM + 2, addr);
1702}
1703
1704
1705
a78f21af 1706static const unsigned char *
5769d3cd
AC
1707s390_breakpoint_from_pc (CORE_ADDR *pcptr, int *lenptr)
1708{
1709 static unsigned char breakpoint[] = { 0x0, 0x1 };
1710
1711 *lenptr = sizeof (breakpoint);
1712 return breakpoint;
1713}
1714
1715/* Advance PC across any function entry prologue instructions to reach some
1716 "real" code. */
a78f21af 1717static CORE_ADDR
5769d3cd
AC
1718s390_skip_prologue (CORE_ADDR pc)
1719{
1720 struct frame_extra_info fextra_info;
1721
1722 s390_get_frame_info (pc, &fextra_info, NULL, 1);
1723 return fextra_info.skip_prologue_function_start;
1724}
1725
5769d3cd
AC
1726/* Immediately after a function call, return the saved pc.
1727 Can't go through the frames for this because on some machines
1728 the new frame is not set up until the new function executes
1729 some instructions. */
a78f21af 1730static CORE_ADDR
5769d3cd
AC
1731s390_saved_pc_after_call (struct frame_info *frame)
1732{
1733 return ADDR_BITS_REMOVE (read_register (S390_RETADDR_REGNUM));
1734}
1735
1736static CORE_ADDR
1737s390_addr_bits_remove (CORE_ADDR addr)
1738{
1739 return (addr) & 0x7fffffff;
1740}
1741
1742
1743static CORE_ADDR
1744s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
1745{
d4d0c21e 1746 write_register (S390_RETADDR_REGNUM, CALL_DUMMY_ADDRESS ());
5769d3cd
AC
1747 return sp;
1748}
1749
ffc65945
KB
1750static int
1751s390_address_class_type_flags (int byte_size, int dwarf2_addr_class)
1752{
1753 if (byte_size == 4)
1754 return TYPE_FLAG_ADDRESS_CLASS_1;
1755 else
1756 return 0;
1757}
1758
1759static const char *
1760s390_address_class_type_flags_to_name (struct gdbarch *gdbarch, int type_flags)
1761{
1762 if (type_flags & TYPE_FLAG_ADDRESS_CLASS_1)
1763 return "mode32";
1764 else
1765 return NULL;
1766}
1767
a78f21af 1768static int
ffc65945
KB
1769s390_address_class_name_to_type_flags (struct gdbarch *gdbarch, const char *name,
1770 int *type_flags_ptr)
1771{
1772 if (strcmp (name, "mode32") == 0)
1773 {
1774 *type_flags_ptr = TYPE_FLAG_ADDRESS_CLASS_1;
1775 return 1;
1776 }
1777 else
1778 return 0;
1779}
1780
a78f21af 1781static struct gdbarch *
5769d3cd
AC
1782s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
1783{
d4d0c21e 1784 static LONGEST s390_call_dummy_words[] = { 0 };
5769d3cd
AC
1785 struct gdbarch *gdbarch;
1786 struct gdbarch_tdep *tdep;
1787 int elf_flags;
1788
1789 /* First see if there is already a gdbarch that can satisfy the request. */
1790 arches = gdbarch_list_lookup_by_info (arches, &info);
1791 if (arches != NULL)
1792 return arches->gdbarch;
1793
1794 /* None found: is the request for a s390 architecture? */
1795 if (info.bfd_arch_info->arch != bfd_arch_s390)
1796 return NULL; /* No; then it's not for us. */
1797
1798 /* Yes: create a new gdbarch for the specified machine type. */
1799 gdbarch = gdbarch_alloc (&info, NULL);
1800
a5afb99f
AC
1801 /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
1802 ready to unwind the PC first (see frame.c:get_prev_frame()). */
1803 set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
1804
5769d3cd 1805 set_gdbarch_believe_pcc_promotion (gdbarch, 0);
4e409299 1806 set_gdbarch_char_signed (gdbarch, 0);
5769d3cd 1807
5769d3cd 1808 set_gdbarch_frame_args_skip (gdbarch, 0);
618ce49f 1809 set_gdbarch_deprecated_frame_chain (gdbarch, s390_frame_chain);
f30ee0bc 1810 set_gdbarch_deprecated_frame_init_saved_regs (gdbarch, s390_frame_init_saved_regs);
4183d812 1811 set_gdbarch_deprecated_store_struct_return (gdbarch, s390_store_struct_return);
26e9b323 1812 set_gdbarch_deprecated_extract_return_value (gdbarch, s390_extract_return_value);
ebba8386 1813 set_gdbarch_deprecated_store_return_value (gdbarch, s390_store_return_value);
aaab4dba
AC
1814 /* Amount PC must be decremented by after a breakpoint. This is
1815 often the number of bytes returned by BREAKPOINT_FROM_PC but not
1816 always. */
5769d3cd 1817 set_gdbarch_decr_pc_after_break (gdbarch, 2);
749b82f6 1818 set_gdbarch_deprecated_pop_frame (gdbarch, s390_pop_frame);
5769d3cd
AC
1819 /* Stack grows downward. */
1820 set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
1821 /* Offset from address of function to start of its code.
1822 Zero on most machines. */
1823 set_gdbarch_function_start_offset (gdbarch, 0);
a0ed5532
AC
1824 set_gdbarch_deprecated_max_register_raw_size (gdbarch, 8);
1825 set_gdbarch_deprecated_max_register_virtual_size (gdbarch, 8);
5769d3cd
AC
1826 set_gdbarch_breakpoint_from_pc (gdbarch, s390_breakpoint_from_pc);
1827 set_gdbarch_skip_prologue (gdbarch, s390_skip_prologue);
e9582e71 1828 set_gdbarch_deprecated_init_extra_frame_info (gdbarch, s390_init_extra_frame_info);
2ca6c561 1829 set_gdbarch_deprecated_init_frame_pc_first (gdbarch, s390_init_frame_pc_first);
0ba6dca9 1830 set_gdbarch_deprecated_target_read_fp (gdbarch, s390_read_fp);
5769d3cd
AC
1831 /* This function that tells us whether the function invocation represented
1832 by FI does not have a frame on the stack associated with it. If it
1833 does not, FRAMELESS is set to 1, else 0. */
1834 set_gdbarch_frameless_function_invocation (gdbarch,
1835 s390_frameless_function_invocation);
1836 /* Return saved PC from a frame */
8bedc050 1837 set_gdbarch_deprecated_frame_saved_pc (gdbarch, s390_frame_saved_pc);
618ce49f
AC
1838 /* DEPRECATED_FRAME_CHAIN takes a frame's nominal address and
1839 produces the frame's chain-pointer. */
1840 set_gdbarch_deprecated_frame_chain (gdbarch, s390_frame_chain);
6913c89a 1841 set_gdbarch_deprecated_saved_pc_after_call (gdbarch, s390_saved_pc_after_call);
9c04cab7 1842 set_gdbarch_deprecated_register_byte (gdbarch, s390_register_byte);
5769d3cd
AC
1843 set_gdbarch_pc_regnum (gdbarch, S390_PC_REGNUM);
1844 set_gdbarch_sp_regnum (gdbarch, S390_SP_REGNUM);
0ba6dca9 1845 set_gdbarch_deprecated_fp_regnum (gdbarch, S390_FP_REGNUM);
5769d3cd
AC
1846 set_gdbarch_fp0_regnum (gdbarch, S390_FP0_REGNUM);
1847 set_gdbarch_num_regs (gdbarch, S390_NUM_REGS);
1848 set_gdbarch_cannot_fetch_register (gdbarch, s390_cannot_fetch_register);
1849 set_gdbarch_cannot_store_register (gdbarch, s390_cannot_fetch_register);
c8f9d51c 1850 set_gdbarch_use_struct_convention (gdbarch, s390_use_struct_convention);
5769d3cd
AC
1851 set_gdbarch_register_name (gdbarch, s390_register_name);
1852 set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum);
1853 set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum);
1854 set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum);
26e9b323 1855 set_gdbarch_deprecated_extract_struct_value_address
c8f9d51c 1856 (gdbarch, generic_cannot_extract_struct_value_address);
5769d3cd 1857
d4d0c21e 1858 /* Parameters for inferior function calls. */
ae45cd16 1859 set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
4074e13c 1860 set_gdbarch_frame_align (gdbarch, s390_frame_align);
b81774d8 1861 set_gdbarch_deprecated_push_arguments (gdbarch, s390_push_arguments);
a59fe496 1862 set_gdbarch_deprecated_save_dummy_frame_tos (gdbarch, generic_save_dummy_frame_tos);
6e691f7a
JB
1863 set_gdbarch_deprecated_push_return_address (gdbarch,
1864 s390_push_return_address);
b1e29e33
AC
1865 set_gdbarch_deprecated_sizeof_call_dummy_words (gdbarch, sizeof (s390_call_dummy_words));
1866 set_gdbarch_deprecated_call_dummy_words (gdbarch, s390_call_dummy_words);
5769d3cd
AC
1867
1868 switch (info.bfd_arch_info->mach)
1869 {
b8b8b047 1870 case bfd_mach_s390_31:
b1e29e33 1871 set_gdbarch_deprecated_register_size (gdbarch, 4);
9c04cab7
AC
1872 set_gdbarch_deprecated_register_raw_size (gdbarch, s390_register_raw_size);
1873 set_gdbarch_deprecated_register_virtual_size (gdbarch, s390_register_raw_size);
1874 set_gdbarch_deprecated_register_virtual_type (gdbarch, s390_register_virtual_type);
5769d3cd
AC
1875
1876 set_gdbarch_addr_bits_remove (gdbarch, s390_addr_bits_remove);
b8b527c5 1877 set_gdbarch_deprecated_register_bytes (gdbarch, S390_REGISTER_BYTES);
5769d3cd 1878 break;
b8b8b047 1879 case bfd_mach_s390_64:
b1e29e33 1880 set_gdbarch_deprecated_register_size (gdbarch, 8);
9c04cab7
AC
1881 set_gdbarch_deprecated_register_raw_size (gdbarch, s390x_register_raw_size);
1882 set_gdbarch_deprecated_register_virtual_size (gdbarch, s390x_register_raw_size);
1883 set_gdbarch_deprecated_register_virtual_type (gdbarch, s390x_register_virtual_type);
5769d3cd
AC
1884
1885 set_gdbarch_long_bit (gdbarch, 64);
1886 set_gdbarch_long_long_bit (gdbarch, 64);
1887 set_gdbarch_ptr_bit (gdbarch, 64);
b8b527c5 1888 set_gdbarch_deprecated_register_bytes (gdbarch, S390X_REGISTER_BYTES);
ffc65945
KB
1889 set_gdbarch_address_class_type_flags (gdbarch,
1890 s390_address_class_type_flags);
1891 set_gdbarch_address_class_type_flags_to_name (gdbarch,
1892 s390_address_class_type_flags_to_name);
1893 set_gdbarch_address_class_name_to_type_flags (gdbarch,
1894 s390_address_class_name_to_type_flags);
5769d3cd
AC
1895 break;
1896 }
1897
6c0e89ed 1898 /* Should be using push_dummy_call. */
b46e02f6 1899 set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
6c0e89ed 1900
5769d3cd
AC
1901 return gdbarch;
1902}
1903
1904
1905
a78f21af
AC
1906extern initialize_file_ftype _initialize_s390_tdep; /* -Wmissing-prototypes */
1907
5769d3cd 1908void
5ae5f592 1909_initialize_s390_tdep (void)
5769d3cd
AC
1910{
1911
1912 /* Hook us into the gdbarch mechanism. */
1913 register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init);
d7a27068
AC
1914 if (!deprecated_tm_print_insn) /* Someone may have already set it */
1915 deprecated_tm_print_insn = gdb_print_insn_s390;
5769d3cd 1916}
This page took 0.312916 seconds and 4 git commands to generate.