Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jim Wilson <jimw@sifive.com>
To: gdb-patches@sourceware.org
Cc: Jim Wilson <jimw@sifive.com>
Subject: [PATCH 3/3] RISC-V: gdb.base/gnu_vector fixes.
Date: Tue, 06 Nov 2018 21:44:00 -0000	[thread overview]
Message-ID: <20181106214446.22325-1-jimw@sifive.com> (raw)
In-Reply-To: <CAFyWVaYMo6sOfXQqZ3YuRyjSnsfGSB9vZTO43j6hKRva73_TCA@mail.gmail.com>

Unnamed arguments with 2*XLEN alignment are passed in aligned register pairs.

	gdb/
	* riscv-tdep.c (struct riscv_arg_info): New field is_unnamed.
	(riscv_call_arg_scalar_int): If unnamed arg with twice xlen alignment,
	then increment next_regnum if odd.
	(riscv_arg_location): New arg is_unnamed.  Set ainfo->is_unnamed.
	(riscv_push_dummy_call): New local ftype.  Call check_typedef to set
	function type.  Pass new arg to riscv_arg_location based on function
	type.
	(riscv_return_value): Pass new arg to riscv_arg_location.
---
 gdb/riscv-tdep.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 3d4f7e3dcc..93310c329f 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -1737,6 +1737,9 @@ struct riscv_arg_info
        then this offset will be set to 0.  */
     int c_offset;
   } argloc[2];
+
+  /* TRUE if this is an unnamed argument.  */
+  bool is_unnamed;
 };
 
 /* Information about a set of registers being used for passing arguments as
@@ -1932,6 +1935,12 @@ riscv_call_arg_scalar_int (struct riscv_arg_info *ainfo,
     {
       int len = (ainfo->length > cinfo->xlen) ? cinfo->xlen : ainfo->length;
 
+      /* Unnamed arguments in registers that require 2*XLEN alignment are
+	 passed in an aligned register pair.  */
+      if (ainfo->is_unnamed && (ainfo->align == cinfo->xlen * 2)
+	  && cinfo->int_regs.next_regnum & 1)
+	cinfo->int_regs.next_regnum++;
+
       if (!riscv_assign_reg_location (&ainfo->argloc[0],
 				      &cinfo->int_regs, len, 0))
 	riscv_assign_stack_location (&ainfo->argloc[0],
@@ -2222,11 +2231,12 @@ static void
 riscv_arg_location (struct gdbarch *gdbarch,
 		    struct riscv_arg_info *ainfo,
 		    struct riscv_call_info *cinfo,
-		    struct type *type)
+		    struct type *type, bool is_unnamed)
 {
   ainfo->type = type;
   ainfo->length = TYPE_LENGTH (ainfo->type);
   ainfo->align = riscv_type_alignment (ainfo->type);
+  ainfo->is_unnamed = is_unnamed;
   ainfo->contents = nullptr;
 
   switch (TYPE_CODE (ainfo->type))
@@ -2375,6 +2385,11 @@ riscv_push_dummy_call (struct gdbarch *gdbarch,
 
   CORE_ADDR osp = sp;
 
+  struct type *ftype = check_typedef (value_type (function));
+
+  if (TYPE_CODE (ftype) == TYPE_CODE_PTR)
+    ftype = check_typedef (TYPE_TARGET_TYPE (ftype));
+
   /* We'll use register $a0 if we're returning a struct.  */
   if (struct_return)
     ++call_info.int_regs.next_regnum;
@@ -2388,7 +2403,8 @@ riscv_push_dummy_call (struct gdbarch *gdbarch,
       arg_value = args[i];
       arg_type = check_typedef (value_type (arg_value));
 
-      riscv_arg_location (gdbarch, info, &call_info, arg_type);
+      riscv_arg_location (gdbarch, info, &call_info, arg_type,
+			  TYPE_VARARGS (ftype) && i >= TYPE_NFIELDS (ftype));
 
       if (info->type != arg_type)
 	arg_value = value_cast (info->type, arg_value);
@@ -2565,7 +2581,7 @@ riscv_return_value (struct gdbarch  *gdbarch,
   struct type *arg_type;
 
   arg_type = check_typedef (type);
-  riscv_arg_location (gdbarch, &info, &call_info, arg_type);
+  riscv_arg_location (gdbarch, &info, &call_info, arg_type, false);
 
   if (riscv_debug_infcall > 0)
     {
-- 
2.17.1


  parent reply	other threads:[~2018-11-06 21:44 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-06 21:43 [PATCH 0/3] " Jim Wilson
2018-11-06 21:44 ` [PATCH 2/3] " Jim Wilson
2018-11-08 14:37   ` Andrew Burgess
2018-11-06 21:44 ` Jim Wilson [this message]
2018-11-08 14:34   ` [PATCH 3/3] " Andrew Burgess
2018-11-08 14:44     ` Andrew Burgess
2018-11-06 21:44 ` [PATCH 1/3] " Jim Wilson
2018-11-08 15:43   ` Andrew Burgess
2018-11-13  1:52     ` Jim Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181106214446.22325-1-jimw@sifive.com \
    --to=jimw@sifive.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox