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