2005-01-19 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / ppc-sysv-tdep.c
index 01438c159a288efdb2810f14eb3c7f81832abf42..7913c2c2397ca9cb9382bc9f3cc47c92de62cc8c 100644 (file)
@@ -29,6 +29,8 @@
 #include "gdb_assert.h"
 #include "ppc-tdep.h"
 #include "target.h"
+#include "objfiles.h"
+#include "infcall.h"
 
 /* Pass the arguments in either registers, or in the stack. Using the
    ppc sysv ABI, the first eight words of the argument list (that might
@@ -42,7 +44,7 @@
    starting from r4. */
 
 CORE_ADDR
-ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
+ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                              struct regcache *regcache, CORE_ADDR bp_addr,
                              int nargs, struct value **args, CORE_ADDR sp,
                              int struct_return, CORE_ADDR struct_addr)
@@ -95,7 +97,7 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
       for (argno = 0; argno < nargs; argno++)
        {
          struct value *arg = args[argno];
-         struct type *type = check_typedef (VALUE_TYPE (arg));
+         struct type *type = check_typedef (value_type (arg));
          int len = TYPE_LENGTH (type);
          char *val = VALUE_CONTENTS (arg);
 
@@ -113,9 +115,10 @@ ppc_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
                         the register's floating-point format.  */
                      char regval[MAX_REGISTER_SIZE];
                      struct type *regtype
-                       = register_type (gdbarch, FP0_REGNUM + freg);
+                       = register_type (gdbarch, tdep->ppc_fp0_regnum + freg);
                      convert_typed_floating (val, type, regval, regtype);
-                     regcache_cooked_write (regcache, FP0_REGNUM + freg,
+                     regcache_cooked_write (regcache,
+                                             tdep->ppc_fp0_regnum + freg,
                                             regval);
                    }
                  freg++;
@@ -337,8 +340,9 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
          /* Floats and doubles stored in "f1".  Convert the value to
             the required type.  */
          char regval[MAX_REGISTER_SIZE];
-         struct type *regtype = register_type (gdbarch, FP0_REGNUM + 1);
-         regcache_cooked_read (regcache, FP0_REGNUM + 1, regval);
+         struct type *regtype = register_type (gdbarch,
+                                                tdep->ppc_fp0_regnum + 1);
+         regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
          convert_typed_floating (regval, regtype, readbuf, type);
        }
       if (writebuf)
@@ -346,9 +350,9 @@ do_ppc_sysv_return_value (struct gdbarch *gdbarch, struct type *type,
          /* Floats and doubles stored in "f1".  Convert the value to
             the register's "double" type.  */
          char regval[MAX_REGISTER_SIZE];
-         struct type *regtype = register_type (gdbarch, FP0_REGNUM);
+         struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
          convert_typed_floating (writebuf, type, regval, regtype);
-         regcache_cooked_write (regcache, FP0_REGNUM + 1, regval);
+         regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
        }
       return RETURN_VALUE_REGISTER_CONVENTION;
     }
@@ -537,11 +541,12 @@ ppc_sysv_abi_broken_return_value (struct gdbarch *gdbarch,
    greatly simplifies the logic. */
 
 CORE_ADDR
-ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
+ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
                                struct regcache *regcache, CORE_ADDR bp_addr,
                                int nargs, struct value **args, CORE_ADDR sp,
                                int struct_return, CORE_ADDR struct_addr)
 {
+  CORE_ADDR func_addr = find_function_addr (function, NULL);
   struct gdbarch_tdep *tdep = gdbarch_tdep (current_gdbarch);
   /* By this stage in the proceedings, SP has been decremented by "red
      zone size" + "struct return size".  Fetch the stack-pointer from
@@ -629,7 +634,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
       for (argno = 0; argno < nargs; argno++)
        {
          struct value *arg = args[argno];
-         struct type *type = check_typedef (VALUE_TYPE (arg));
+         struct type *type = check_typedef (value_type (arg));
          char *val = VALUE_CONTENTS (arg);
          if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8)
            {
@@ -642,10 +647,11 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
                      && freg <= 13)
                    {
                      char regval[MAX_REGISTER_SIZE];
-                     struct type *regtype = register_type (gdbarch,
-                                                           FP0_REGNUM);
+                     struct type *regtype
+                        = register_type (gdbarch, tdep->ppc_fp0_regnum);
                      convert_typed_floating (val, type, regval, regtype);
-                     regcache_cooked_write (regcache, FP0_REGNUM + freg,
+                     regcache_cooked_write (regcache,
+                                             tdep->ppc_fp0_regnum + freg,
                                             regval);
                    }
                  if (greg <= 10)
@@ -790,27 +796,38 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, CORE_ADDR func_addr,
      ".FN" and "FN" in the minimal symbol table.  "FN" points at the
      FN's descriptor, while ".FN" points at the entry point (which
      matches FUNC_ADDR).  Need to reverse from FUNC_ADDR back to the
-     FN's descriptor address.  */
+     FN's descriptor address (while at the same time being careful to
+     find "FN" in the same object file as ".FN").  */
   {
     /* Find the minimal symbol that corresponds to FUNC_ADDR (should
        have the name ".FN").  */
     struct minimal_symbol *dot_fn = lookup_minimal_symbol_by_pc (func_addr);
     if (dot_fn != NULL && SYMBOL_LINKAGE_NAME (dot_fn)[0] == '.')
       {
-       /* Now find the corresponding "FN" (dropping ".") minimal
-          symbol's address.  */
-       struct minimal_symbol *fn =
-         lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
-                                NULL);
-       if (fn != NULL)
+       /* Get the section that contains FUNC_ADR.  Need this for the
+           "objfile" that it contains.  */
+       struct obj_section *dot_fn_section = find_pc_section (func_addr);
+       if (dot_fn_section != NULL && dot_fn_section->objfile != NULL)
          {
-           /* Got the address of that descriptor.  The TOC is the
-              second double word.  */
-           CORE_ADDR toc =
-             read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn) +
-                                           tdep->wordsize, tdep->wordsize);
-           regcache_cooked_write_unsigned (regcache,
-                                           tdep->ppc_gp0_regnum + 2, toc);
+           /* Now find the corresponding "FN" (dropping ".") minimal
+              symbol's address.  Only look for the minimal symbol in
+              ".FN"'s object file - avoids problems when two object
+              files (i.e., shared libraries) contain a minimal symbol
+              with the same name.  */
+           struct minimal_symbol *fn =
+             lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (dot_fn) + 1, NULL,
+                                    dot_fn_section->objfile);
+           if (fn != NULL)
+             {
+               /* Got the address of that descriptor.  The TOC is the
+                  second double word.  */
+               CORE_ADDR toc =
+                 read_memory_unsigned_integer (SYMBOL_VALUE_ADDRESS (fn)
+                                               + tdep->wordsize,
+                                               tdep->wordsize);
+               regcache_cooked_write_unsigned (regcache,
+                                               tdep->ppc_gp0_regnum + 2, toc);
+             }
          }
       }
   }
@@ -835,19 +852,25 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
                             const void *writebuf)
 {
   struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
+
+  /* This function exists to support a calling convention that
+     requires floating-point registers.  It shouldn't be used on
+     processors that lack them.  */
+  gdb_assert (ppc_floating_point_unit_p (gdbarch));
+
   /* Floats and doubles in F1.  */
   if (TYPE_CODE (valtype) == TYPE_CODE_FLT && TYPE_LENGTH (valtype) <= 8)
     {
       char regval[MAX_REGISTER_SIZE];
-      struct type *regtype = register_type (gdbarch, FP0_REGNUM);
+      struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum);
       if (writebuf != NULL)
        {
          convert_typed_floating (writebuf, valtype, regval, regtype);
-         regcache_cooked_write (regcache, FP0_REGNUM + 1, regval);
+         regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1, regval);
        }
       if (readbuf != NULL)
        {
-         regcache_cooked_read (regcache, FP0_REGNUM + 1, regval);
+         regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1, regval);
          convert_typed_floating (regval, regtype, readbuf, valtype);
        }
       return RETURN_VALUE_REGISTER_CONVENTION;
@@ -909,10 +932,10 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
          for (i = 0; i < TYPE_LENGTH (valtype) / 8; i++)
            {
              if (writebuf != NULL)
-               regcache_cooked_write (regcache, FP0_REGNUM + 1 + i,
+               regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
                                       (const bfd_byte *) writebuf + i * 8);
              if (readbuf != NULL)
-               regcache_cooked_read (regcache, FP0_REGNUM + 1 + i,
+               regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
                                      (bfd_byte *) readbuf + i * 8);
            }
        }
@@ -929,18 +952,21 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
            {
              char regval[MAX_REGISTER_SIZE];
              struct type *regtype =
-               register_type (current_gdbarch, FP0_REGNUM);
+               register_type (current_gdbarch, tdep->ppc_fp0_regnum);
              if (writebuf != NULL)
                {
                  convert_typed_floating ((const bfd_byte *) writebuf +
                                          i * (TYPE_LENGTH (valtype) / 2),
                                          valtype, regval, regtype);
-                 regcache_cooked_write (regcache, FP0_REGNUM + 1 + i,
+                 regcache_cooked_write (regcache,
+                                         tdep->ppc_fp0_regnum + 1 + i,
                                         regval);
                }
              if (readbuf != NULL)
                {
-                 regcache_cooked_read (regcache, FP0_REGNUM + 1 + i, regval);
+                 regcache_cooked_read (regcache,
+                                        tdep->ppc_fp0_regnum + 1 + i,
+                                        regval);
                  convert_typed_floating (regval, regtype,
                                          (bfd_byte *) readbuf +
                                          i * (TYPE_LENGTH (valtype) / 2),
@@ -959,10 +985,10 @@ ppc64_sysv_abi_return_value (struct gdbarch *gdbarch, struct type *valtype,
          for (i = 0; i < 4; i++)
            {
              if (writebuf != NULL)
-               regcache_cooked_write (regcache, FP0_REGNUM + 1 + i,
+               regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + 1 + i,
                                       (const bfd_byte *) writebuf + i * 8);
              if (readbuf != NULL)
-               regcache_cooked_read (regcache, FP0_REGNUM + 1 + i,
+               regcache_cooked_read (regcache, tdep->ppc_fp0_regnum + 1 + i,
                                      (bfd_byte *) readbuf + i * 8);
            }
        }
This page took 0.04034 seconds and 4 git commands to generate.