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