2004-01-07 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / gdb / s390-tdep.c
index 69463ab83cae30340afe63696ee683dce27820db..eb4a62ef3c45f47ed2d029559f71b06919c035da 100644 (file)
@@ -39,7 +39,7 @@
 #include "regcache.h"
 #include "value.h"
 #include "gdb_assert.h"
-
+#include "dis-asm.h"
 
 
 
@@ -113,6 +113,7 @@ struct frame_extra_info
   CORE_ADDR sig_fixed_saved_pc_valid;
   CORE_ADDR sig_fixed_saved_pc;
   CORE_ADDR frame_pointer_saved_pc;    /* frame pointer needed for alloca */
+  CORE_ADDR stack_bought_valid;
   CORE_ADDR stack_bought;      /* amount we decrement the stack pointer by */
   CORE_ADDR sigcontext;
 };
@@ -121,8 +122,7 @@ struct frame_extra_info
 static CORE_ADDR s390_frame_saved_pc_nofix (struct frame_info *fi);
 
 static int
-s390_readinstruction (bfd_byte instr[], CORE_ADDR at,
-                     struct disassemble_info *info)
+s390_readinstruction (bfd_byte instr[], CORE_ADDR at)
 {
   int instrlen;
 
@@ -132,12 +132,12 @@ s390_readinstruction (bfd_byte instr[], CORE_ADDR at,
     4,
     6
   };
-  if ((*info->read_memory_func) (at, &instr[0], 2, info))
+  if (target_read_memory (at, &instr[0], 2))
     return -1;
   instrlen = s390_instrlen[instr[0] >> 6];
   if (instrlen > 2)
     {
-      if ((*info->read_memory_func) (at + 2, &instr[2], instrlen - 2, info))
+      if (target_read_memory (at + 2, &instr[2], instrlen - 2))
         return -1;
     }
   return instrlen;
@@ -901,9 +901,9 @@ s390_get_signal_frame_info (struct frame_info *fi)
       && get_frame_extra_info (next_frame)->sigcontext)
     {
       /* We're definitely backtracing from a signal handler.  */
-      CORE_ADDR *saved_regs = get_frame_saved_regs (fi);
+      CORE_ADDR *saved_regs = deprecated_get_frame_saved_regs (fi);
       CORE_ADDR save_reg_addr = (get_frame_extra_info (next_frame)->sigcontext
-                                 + REGISTER_BYTE (S390_GP0_REGNUM));
+                                 + DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM));
       int reg;
 
       for (reg = 0; reg < S390_NUM_GPRS; reg++)
@@ -935,9 +935,6 @@ s390_get_frame_info (CORE_ADDR start_pc,
      -1 if we got an error trying to read memory.  */
   int result = 0;
 
-  /* We just use this for reading instructions.  */
-  disassemble_info info;
-
   /* The current PC for our abstract interpretation.  */
   CORE_ADDR pc;
 
@@ -965,8 +962,6 @@ s390_get_frame_info (CORE_ADDR start_pc,
      the SP, FP, or back chain.  */
   CORE_ADDR after_last_frame_setup_insn = start_pc;
 
-  info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func;
-
   /* Set up everything's initial value.  */
   {
     int i;
@@ -990,7 +985,7 @@ s390_get_frame_info (CORE_ADDR start_pc,
   for (pc = start_pc; ; pc = next_pc)
     {
       bfd_byte insn[S390_MAX_INSTR_SIZE];
-      int insn_len = s390_readinstruction (insn, pc, &info);
+      int insn_len = s390_readinstruction (insn, pc);
 
       /* Fields for various kinds of instructions.  */
       unsigned int b2, r1, r2, d2, x2, r3;
@@ -1392,6 +1387,7 @@ s390_get_frame_info (CORE_ADDR start_pc,
 
         if (frame_size != -1)
           {
+            fextra_info->stack_bought_valid = 1;
             fextra_info->stack_bought = frame_size;
           }
 
@@ -1432,12 +1428,12 @@ s390_get_frame_info (CORE_ADDR start_pc,
        - the analysis gave us enough information to actually figure it
          out.  */
     if (fi
-        && get_frame_saved_regs (fi)
+        && deprecated_get_frame_saved_regs (fi)
         && original_sp != -1)
       {
         int slot_num;
         CORE_ADDR slot_addr;
-        CORE_ADDR *saved_regs = get_frame_saved_regs (fi);
+        CORE_ADDR *saved_regs = deprecated_get_frame_saved_regs (fi);
 
         /* Scan the spill array; if a spill slot says it holds the
            original value of some register, then record that slot's
@@ -1485,11 +1481,9 @@ static int
 s390_check_function_end (CORE_ADDR pc)
 {
   bfd_byte instr[S390_MAX_INSTR_SIZE];
-  disassemble_info info;
   int regidx, instrlen;
 
-  info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func;
-  instrlen = s390_readinstruction (instr, pc, &info);
+  instrlen = s390_readinstruction (instr, pc);
   if (instrlen < 0)
     return -1;
   /* check for BR */
@@ -1498,7 +1492,7 @@ s390_check_function_end (CORE_ADDR pc)
   regidx = instr[1] & 0xf;
   /* Check for LMG or LG */
   instrlen =
-    s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4), &info);
+    s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 6 : 4));
   if (instrlen < 0)
     return -1;
   if (GDB_TARGET_IS_ESAME)
@@ -1515,8 +1509,7 @@ s390_check_function_end (CORE_ADDR pc)
     return 0;
   if (regidx == 14)
     return 1;
-  instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8),
-                                  &info);
+  instrlen = s390_readinstruction (instr, pc - (GDB_TARGET_IS_ESAME ? 12 : 8));
   if (instrlen < 0)
     return -1;
   if (GDB_TARGET_IS_ESAME)
@@ -1604,7 +1597,8 @@ s390_frameless_function_invocation (struct frame_info *fi)
          s390_get_frame_info (s390_sniff_pc_function_start (get_frame_pc (fi), fi),
                               fextra_info_ptr, fi, 1);
        }
-      frameless = ((fextra_info_ptr->stack_bought == 0));
+      frameless = (fextra_info_ptr->stack_bought_valid
+                   && fextra_info_ptr->stack_bought == 0);
     }
   return frameless;
 
@@ -1616,7 +1610,6 @@ s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi,
                   CORE_ADDR *sregs, CORE_ADDR *sigcaller_pc)
 {
   bfd_byte instr[S390_MAX_INSTR_SIZE];
-  disassemble_info info;
   int instrlen;
   CORE_ADDR scontext;
   int retval = 0;
@@ -1625,8 +1618,7 @@ s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi,
 
   scontext = temp_sregs = 0;
 
-  info.read_memory_func = deprecated_tm_print_insn_info.read_memory_func;
-  instrlen = s390_readinstruction (instr, pc, &info);
+  instrlen = s390_readinstruction (instr, pc);
   if (sigcaller_pc)
     *sigcaller_pc = 0;
   if (((instrlen == S390_SYSCALL_SIZE) &&
@@ -1670,8 +1662,7 @@ s390_is_sigreturn (CORE_ADDR pc, struct frame_info *sighandler_fi,
              *sigcaller_pc =
                ADDR_BITS_REMOVE ((CORE_ADDR)
                                  read_memory_integer (temp_sregs +
-                                                      REGISTER_BYTE
-                                                      (S390_PC_REGNUM),
+                                                      DEPRECATED_REGISTER_BYTE (S390_PC_REGNUM),
                                                       S390_PSW_ADDR_SIZE));
            }
        }
@@ -1728,7 +1719,7 @@ s390_frame_init_saved_regs (struct frame_info *fi)
 
   int quick;
 
-  if (get_frame_saved_regs (fi) == NULL)
+  if (deprecated_get_frame_saved_regs (fi) == NULL)
     {
       /* zalloc memsets the saved regs */
       frame_saved_regs_zalloc (fi);
@@ -1763,10 +1754,10 @@ s390_frame_saved_pc_nofix (struct frame_info *fi)
     {
       get_frame_extra_info (fi)->saved_pc_valid = 1;
       if (get_frame_extra_info (fi)->good_prologue
-          && get_frame_saved_regs (fi)[S390_RETADDR_REGNUM])
+          && deprecated_get_frame_saved_regs (fi)[S390_RETADDR_REGNUM])
         get_frame_extra_info (fi)->saved_pc
           = ADDR_BITS_REMOVE (read_memory_integer
-                              (get_frame_saved_regs (fi)[S390_RETADDR_REGNUM],
+                              (deprecated_get_frame_saved_regs (fi)[S390_RETADDR_REGNUM],
                                S390_GPR_SIZE));
       else
         get_frame_extra_info (fi)->saved_pc
@@ -1841,7 +1832,7 @@ s390_frame_chain (struct frame_info *thisframe)
        {
          /* read sigregs,regs.gprs[11 or 15] */
          prev_fp = read_memory_integer (sregs +
-                                        REGISTER_BYTE (S390_GP0_REGNUM +
+                                        DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM +
                                                        (prev_fextra_info.
                                                         frame_pointer_saved_pc
                                                         ? 11 : 15)),
@@ -1850,24 +1841,24 @@ s390_frame_chain (struct frame_info *thisframe)
        }
       else
        {
-         if (get_frame_saved_regs (thisframe))
+         if (deprecated_get_frame_saved_regs (thisframe))
            {
              int regno;
 
               if (prev_fextra_info.frame_pointer_saved_pc
-                  && get_frame_saved_regs (thisframe)[S390_FRAME_REGNUM])
+                  && deprecated_get_frame_saved_regs (thisframe)[S390_FRAME_REGNUM])
                 regno = S390_FRAME_REGNUM;
               else
                 regno = S390_SP_REGNUM;
 
-             if (get_frame_saved_regs (thisframe)[regno])
+             if (deprecated_get_frame_saved_regs (thisframe)[regno])
                 {
                   /* The SP's entry of `saved_regs' is special.  */
                   if (regno == S390_SP_REGNUM)
-                    prev_fp = get_frame_saved_regs (thisframe)[regno];
+                    prev_fp = deprecated_get_frame_saved_regs (thisframe)[regno];
                   else
                     prev_fp =
-                      read_memory_integer (get_frame_saved_regs (thisframe)[regno],
+                      read_memory_integer (deprecated_get_frame_saved_regs (thisframe)[regno],
                                            S390_GPR_SIZE);
                 }
            }
@@ -1883,6 +1874,15 @@ s390_frame_chain (struct frame_info *thisframe)
 
 
 
+/* NOTE: cagney/2003-10-31: "return_value" makes
+   "extract_struct_value_address", "extract_return_value", and
+   "use_struct_convention" redundant.  */
+static CORE_ADDR
+s390_cannot_extract_struct_value_address (struct regcache *regcache)
+{
+  return 0;
+}
+
 /* a given return value in `regbuf' with a type `valtype', extract and copy its
    value into `valbuf' */
 static void
@@ -1894,7 +1894,7 @@ s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
   int len = TYPE_LENGTH (valtype);
 
   if (TYPE_CODE (valtype) == TYPE_CODE_FLT)
-    memcpy (valbuf, &regbuf[REGISTER_BYTE (S390_FP0_REGNUM)], len);
+    memcpy (valbuf, &regbuf[DEPRECATED_REGISTER_BYTE (S390_FP0_REGNUM)], len);
   else
     {
       int offset = 0;
@@ -1902,7 +1902,7 @@ s390_extract_return_value (struct type *valtype, char *regbuf, char *valbuf)
       if (TYPE_LENGTH (valtype) < S390_GPR_SIZE)
        offset = S390_GPR_SIZE - TYPE_LENGTH (valtype);
       memcpy (valbuf,
-             regbuf + REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset,
+             regbuf + DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM + 2) + offset,
              TYPE_LENGTH (valtype));
     }
 }
@@ -1953,7 +1953,7 @@ s390_store_return_value (struct type *valtype, char *valbuf)
     {
       if (TYPE_LENGTH (valtype) == 4
           || TYPE_LENGTH (valtype) == 8)
-        deprecated_write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM),
+        deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_FP0_REGNUM),
                                         valbuf, TYPE_LENGTH (valtype));
       else
         error ("GDB is unable to return `long double' values "
@@ -1964,30 +1964,10 @@ s390_store_return_value (struct type *valtype, char *valbuf)
       value =
        s390_promote_integer_argument (valtype, valbuf, reg_buff, &arglen);
       /* Everything else is returned in GPR2 and up. */
-      deprecated_write_register_bytes (REGISTER_BYTE (S390_GP0_REGNUM + 2),
+      deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_GP0_REGNUM + 2),
                                       value, arglen);
     }
 }
-static int
-gdb_print_insn_s390 (bfd_vma memaddr, disassemble_info * info)
-{
-  bfd_byte instrbuff[S390_MAX_INSTR_SIZE];
-  int instrlen, cnt;
-
-  instrlen = s390_readinstruction (instrbuff, (CORE_ADDR) memaddr, info);
-  if (instrlen < 0)
-    {
-      (*info->memory_error_func) (instrlen, memaddr, info);
-      return -1;
-    }
-  for (cnt = 0; cnt < instrlen; cnt++)
-    info->fprintf_func (info->stream, "%02X ", instrbuff[cnt]);
-  for (cnt = instrlen; cnt < S390_MAX_INSTR_SIZE; cnt++)
-    info->fprintf_func (info->stream, "   ");
-  instrlen = print_insn_s390 (memaddr, info);
-  return instrlen;
-}
-
 
 
 /* Not the most efficent code in the world */
@@ -2021,22 +2001,22 @@ s390_pop_frame_regular (struct frame_info *frame)
   write_register (S390_PC_REGNUM, DEPRECATED_FRAME_SAVED_PC (frame));
 
   /* Restore any saved registers.  */
-  if (get_frame_saved_regs (frame))
+  if (deprecated_get_frame_saved_regs (frame))
     {
       for (regnum = 0; regnum < NUM_REGS; regnum++)
-        if (get_frame_saved_regs (frame)[regnum] != 0)
+        if (deprecated_get_frame_saved_regs (frame)[regnum] != 0)
           {
             ULONGEST value;
             
-            value = read_memory_unsigned_integer (get_frame_saved_regs (frame)[regnum],
-                                                  REGISTER_RAW_SIZE (regnum));
+            value = read_memory_unsigned_integer (deprecated_get_frame_saved_regs (frame)[regnum],
+                                                  DEPRECATED_REGISTER_RAW_SIZE (regnum));
             write_register (regnum, value);
           }
 
       /* Actually cut back the stack.  Remember that the SP's element of
          saved_regs is the old SP itself, not the address at which it is
          saved.  */
-      write_register (S390_SP_REGNUM, get_frame_saved_regs (frame)[S390_SP_REGNUM]);
+      write_register (S390_SP_REGNUM, deprecated_get_frame_saved_regs (frame)[S390_SP_REGNUM]);
     }
 
   /* Throw away any cached frame information.  */
@@ -2235,28 +2215,6 @@ extend_simple_arg (struct value *arg)
 }
 
 
-/* Round ADDR up to the next N-byte boundary.  N must be a power of
-   two.  */
-static CORE_ADDR
-round_up (CORE_ADDR addr, int n)
-{
-  /* Check that N is really a power of two.  */
-  gdb_assert (n && (n & (n-1)) == 0);
-  return ((addr + n - 1) & -n);
-}
-
-
-/* Round ADDR down to the next N-byte boundary.  N must be a power of
-   two.  */
-static CORE_ADDR
-round_down (CORE_ADDR addr, int n)
-{
-  /* Check that N is really a power of two.  */
-  gdb_assert (n && (n & (n-1)) == 0);
-  return (addr & -n);
-}
-
-
 /* Return the alignment required by TYPE.  */
 static int
 alignment_of (struct type *type)
@@ -2333,7 +2291,7 @@ s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
           && pass_by_copy_ref (type))
         {
           sp -= length;
-          sp = round_down (sp, alignment_of (type));
+          sp = align_down (sp, alignment_of (type));
           write_memory (sp, VALUE_CONTENTS (arg), length);
           copy_addr[i] = sp;
           num_copies++;
@@ -2352,7 +2310,7 @@ s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
         struct type *type = VALUE_TYPE (arg);
         int length = TYPE_LENGTH (type);
         
-        sp = round_down (sp, alignment_of (type));
+        sp = align_down (sp, alignment_of (type));
 
         /* SIMPLE_ARG values get extended to DEPRECATED_REGISTER_SIZE bytes. 
            Assume every argument is.  */
@@ -2362,12 +2320,12 @@ s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
   }
 
   /* Include space for any reference-to-copy pointers.  */
-  sp = round_down (sp, pointer_size);
+  sp = align_down (sp, pointer_size);
   sp -= num_copies * pointer_size;
     
   /* After all that, make sure it's still aligned on an eight-byte
      boundary.  */
-  sp = round_down (sp, 8);
+  sp = align_down (sp, 8);
 
   /* Finally, place the actual parameters, working from SP towards
      higher addresses.  The code above is supposed to reserve enough
@@ -2391,7 +2349,7 @@ s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
           {
             /* When we store a single-precision value in an FP register,
                it occupies the leftmost bits.  */
-            deprecated_write_register_bytes (REGISTER_BYTE (S390_FP0_REGNUM + fr),
+            deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (S390_FP0_REGNUM + fr),
                                             VALUE_CONTENTS (arg),
                                             TYPE_LENGTH (type));
             fr += 2;
@@ -2432,7 +2390,7 @@ s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
               {
                 /* Simple args are always extended to 
                    DEPRECATED_REGISTER_SIZE bytes.  */
-                starg = round_up (starg, DEPRECATED_REGISTER_SIZE);
+                starg = align_up (starg, DEPRECATED_REGISTER_SIZE);
 
                 /* Do we need to pass a pointer to our copy of this
                    argument?  */
@@ -2449,10 +2407,10 @@ s390_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
             else
               {
                 /* You'd think we should say:
-                   starg = round_up (starg, alignment_of (type));
+                   starg = align_up (starg, alignment_of (type));
                    Unfortunately, GCC seems to simply align the stack on
                    a four/eight-byte boundary, even when passing doubles. */
-                starg = round_up (starg, S390_STACK_PARAMETER_ALIGNMENT);
+                starg = align_up (starg, S390_STACK_PARAMETER_ALIGNMENT);
                 write_memory (starg, VALUE_CONTENTS (arg), length);
                 starg += length;
               }
@@ -2564,7 +2522,7 @@ s390_addr_bits_remove (CORE_ADDR addr)
 static CORE_ADDR
 s390_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
 {
-  write_register (S390_RETADDR_REGNUM, CALL_DUMMY_ADDRESS ());
+  write_register (S390_RETADDR_REGNUM, entry_point_address ());
   return sp;
 }
 
@@ -2621,7 +2579,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* NOTE: cagney/2002-12-06: This can be deleted when this arch is
      ready to unwind the PC first (see frame.c:get_prev_frame()).  */
-  set_gdbarch_deprecated_init_frame_pc (gdbarch, init_frame_pc_default);
+  set_gdbarch_deprecated_init_frame_pc (gdbarch, deprecated_init_frame_pc_default);
 
   set_gdbarch_believe_pcc_promotion (gdbarch, 0);
   set_gdbarch_char_signed (gdbarch, 0);
@@ -2673,8 +2631,7 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   set_gdbarch_stab_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum);
   set_gdbarch_dwarf_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum);
   set_gdbarch_dwarf2_reg_to_regnum (gdbarch, s390_stab_reg_to_regnum);
-  set_gdbarch_deprecated_extract_struct_value_address
-    (gdbarch, generic_cannot_extract_struct_value_address);
+  set_gdbarch_extract_struct_value_address (gdbarch, s390_cannot_extract_struct_value_address);
 
   /* Parameters for inferior function calls.  */
   set_gdbarch_deprecated_pc_in_call_dummy (gdbarch, deprecated_pc_in_call_dummy_at_entry_point);
@@ -2719,6 +2676,8 @@ s390_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
   /* Should be using push_dummy_call.  */
   set_gdbarch_deprecated_dummy_write_sp (gdbarch, deprecated_write_sp);
 
+  set_gdbarch_print_insn (gdbarch, print_insn_s390);
+
   return gdbarch;
 }
 
@@ -2732,6 +2691,4 @@ _initialize_s390_tdep (void)
 
   /* Hook us into the gdbarch mechanism.  */
   register_gdbarch_init (bfd_arch_s390, s390_gdbarch_init);
-  if (!deprecated_tm_print_insn)       /* Someone may have already set it */
-    deprecated_tm_print_insn = gdb_print_insn_s390;
 }
This page took 0.03182 seconds and 4 git commands to generate.