This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] sh-tdep.c: Use calling convention ifo in use_struct_convention


Hi,

this is the first patch which actually uses the calling convention
information.  This patch only introduces the Renesas ABI differences
into use_struct_convention.  The differences are added to the
appropriate comment:

- All aggregate types are always returned on the stack.
- In the no-FPU ABI, long longs and doubles (resp.long doubles) are
  returned on the stack.


Corinna


	* sh-tdep.c (sh_use_struct_convention_fpu): Renamed from
	sh_use_struct_convention.  Take function type instead of gcc_p as
	parameter.  Take Renesas ABI into account.
	(sh_use_struct_convention_nofpu): New function.  Take no-FPU Renesas
	ABI into account, call sh_use_struct_convention_fpu otherwise.
	(sh_return_value_nofpu): Call sh_use_struct_convention_nofpu.
	(sh_return_value_fpu): Call sh_use_struct_convention_fpu.

--- sh-tdep.c.PRE-USE-CC	2004-10-20 11:25:42.000000000 +0200
+++ sh-tdep.c	2004-10-20 11:59:23.000000000 +0200
@@ -747,7 +747,7 @@ sh_skip_prologue (CORE_ADDR start_pc)
   return pc;
 }
 
-/* The ABI says:
+/* The GCC ABI says:
 
    Aggregate types not bigger than 8 bytes that have the same size and
    alignment as one of the integer scalar types are returned in the
@@ -794,14 +794,24 @@ sh_skip_prologue (CORE_ADDR start_pc)
    type that has alignment 1 and size 2, so the struct is returned in
    memory.
 
+   Two exceptions in the Renesas ABI:
+
+   - All aggregate types are always returned on the stack.
+
+   - In the no-FPU ABI, long longs and doubles are returned on the stack.
 */
 
 static int
-sh_use_struct_convention (int gcc_p, struct type *type)
+sh_use_struct_convention_fpu (struct type *functype, struct type *type)
 {
   int len = TYPE_LENGTH (type);
   int nelem = TYPE_NFIELDS (type);
 
+  /* The Renesas ABI returns aggregate types always on stack */
+  if (sh_effective_calling_convention (functype) == sh_cc_renesas
+      && (TYPE_CODE (type) == TYPE_CODE_STRUCT
+          || TYPE_CODE (type) == TYPE_CODE_UNION))
+    return 1;
   /* Non-power of 2 length types and types bigger than 8 bytes (which don't
      fit in two registers anyway) use struct convention.  */
   if (len != 1 && len != 2 && len != 4 && len != 8)
@@ -827,6 +837,16 @@ sh_use_struct_convention (int gcc_p, str
   return 1;
 }
 
+static int
+sh_use_struct_convention_nofpu (struct type *functype, struct type *type)
+{
+  /* The Renesas ABI returns long longs/doubles etc. always on stack. */
+  if (sh_effective_calling_convention (functype) == sh_cc_renesas
+      && TYPE_NFIELDS (type) == 0 && TYPE_LENGTH (type) >= 8)
+    return 1;
+  return sh_use_struct_convention_fpu (functype, type);
+}
+
 /* Extract from an array REGBUF containing the (raw) register state
    the address in which a function should return its structure value,
    as a CORE_ADDR (or an expression that can be used as one).  */
@@ -1318,7 +1338,7 @@ sh_return_value_nofpu (struct gdbarch *g
 		       struct type *type, struct regcache *regcache,
 		       void *readbuf, const void *writebuf)
 {
-  if (sh_use_struct_convention (0, type))
+  if (sh_use_struct_convention_nofpu (functype, type))
     return RETURN_VALUE_STRUCT_CONVENTION;
   if (writebuf)
     sh_store_return_value_nofpu (type, regcache, writebuf);
@@ -1332,7 +1352,7 @@ sh_return_value_fpu (struct gdbarch *gdb
 		     struct type *type, struct regcache *regcache,
 		     void *readbuf, const void *writebuf)
 {
-  if (sh_use_struct_convention (0, type))
+  if (sh_use_struct_convention_fpu (functype, type))
     return RETURN_VALUE_STRUCT_CONVENTION;
   if (writebuf)
     sh_store_return_value_fpu (type, regcache, writebuf);

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]