From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19445 invoked by alias); 15 Jan 2008 20:34:22 -0000 Received: (qmail 19436 invoked by uid 22791); 15 Jan 2008 20:34:22 -0000 X-Spam-Check-By: sourceware.org Received: from igw3.br.ibm.com (HELO igw3.br.ibm.com) (32.104.18.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 15 Jan 2008 20:33:58 +0000 Received: from mailhub3.br.ibm.com (unknown [9.18.232.110]) by igw3.br.ibm.com (Postfix) with ESMTP id EE1D23900C5 for ; Tue, 15 Jan 2008 18:25:44 -0200 (BRDT) Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.18.232.47]) by mailhub3.br.ibm.com (8.13.8/8.13.8/NCO v8.7) with ESMTP id m0FKXtbH3870780 for ; Tue, 15 Jan 2008 18:33:55 -0200 Received: from d24av02.br.ibm.com (loopback [127.0.0.1]) by d24av02.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id m0FKXtkE013239 for ; Tue, 15 Jan 2008 18:33:55 -0200 Received: from [9.18.238.41] ([9.18.238.41]) by d24av02.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id m0FKXt0Z013210; Tue, 15 Jan 2008 18:33:55 -0200 Subject: Re: [RFA] Fix float argument passing in inferior function calls for ppc64 From: Thiago Jung Bauermann To: Mark Kettenis Cc: gdb-patches@sourceware.org In-Reply-To: <1200418789.3158.71.camel@localhost.localdomain> References: <1200400434.3158.64.camel@localhost.localdomain> <200801151443.m0FEhxN3021953@brahms.sibelius.xs4all.nl> <1200418789.3158.71.camel@localhost.localdomain> Content-Type: multipart/mixed; boundary="=-A85/FlzqS62W/SVO7VZ9" Date: Tue, 15 Jan 2008 20:34:00 -0000 Message-Id: <1200429235.20287.10.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.12.2 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2008-01/txt/msg00359.txt.bz2 --=-A85/FlzqS62W/SVO7VZ9 Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1062 On Tue, 2008-01-15 at 15:39 -0200, Thiago Jung Bauermann wrote: > > Is the first word used for anything in the new ABI? If not, you could > > support both ABIs by copying the value into both the first and the > > second word. > > Great idea. I will resend the patch using that approach then. What about this patch? > > > I didn't touch the code which writes the float to a general register in > > > the first word because I'm not sure how to test it. It is probably > > > related to soft-float, I guess. > > > > Actually, it may be related to varargs. Or perhaps it is a leftover > > from the 32-bit ABI code that was copied. > > I'll play with varargs and see if I can trigger that code and create a > test for it. I tried it, but turns out it's not possible to pass a 32-bit float to a variadic function, you need to explicitly promote it to double first. So if that if code writing to a general register is not used by soft-float, then it may be dead code as you suggested. -- []'s Thiago Jung Bauermann Software Engineer IBM Linux Technology Center --=-A85/FlzqS62W/SVO7VZ9 Content-Disposition: attachment; filename=ppc64-abi-float-fix.diff Content-Type: text/x-patch; name=ppc64-abi-float-fix.diff; charset=utf-8 Content-Transfer-Encoding: 7bit Content-length: 3276 2008-01-15 Thiago Jung Bauermann * ppc-sysv-tdep.c (ppc64_sysv_abi_push_dummy_call): Write 32-bit float in both first and second word in the doubleword, to support old and new ABIs. diff --git a/gdb/ppc-sysv-tdep.c b/gdb/ppc-sysv-tdep.c index c2952f5..466b37f 100644 --- a/gdb/ppc-sysv-tdep.c +++ b/gdb/ppc-sysv-tdep.c @@ -829,6 +829,7 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, struct value *arg = args[argno]; struct type *type = check_typedef (value_type (arg)); const bfd_byte *val = value_contents (arg); + if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) <= 8) { /* Floats and Doubles go in f1 .. f13. They also @@ -836,40 +837,53 @@ ppc64_sysv_abi_push_dummy_call (struct gdbarch *gdbarch, struct value *function, memory. */ if (write_pass) { + gdb_byte regval[MAX_REGISTER_SIZE]; + const gdb_byte *p; + + /* Version 1.7 of the 64-bit PowerPC ELF ABI says: + + "Single precision floating point values are mapped to + the first word in a single doubleword." + + And version 1.9 says: + + "Single precision floating point values are mapped to + the second word in a single doubleword." + + GDB then writes single precision floating point values + at both words in a doubleword, to support both ABIs. */ + if (TYPE_LENGTH (type) == 4) + { + memcpy (regval, val, 4); + memcpy (regval + 4, val, 4); + p = regval; + } + else + p = val; + + /* Write value in the stack's parameter save area. */ + write_memory (gparam, p, 8); + if (freg <= 13) { - gdb_byte regval[MAX_REGISTER_SIZE]; struct type *regtype = register_type (gdbarch, tdep->ppc_fp0_regnum); + convert_typed_floating (val, type, regval, regtype); regcache_cooked_write (regcache, tdep->ppc_fp0_regnum + freg, regval); } if (greg <= 10) - { - /* The ABI states "Single precision floating - point values are mapped to the first word in - a single doubleword" and "... floating point - values mapped to the first eight doublewords - of the parameter save area are also passed in - general registers"). - - This code interprets that to mean: store it, - left aligned, in the general register. */ - gdb_byte regval[MAX_REGISTER_SIZE]; - memset (regval, 0, sizeof regval); - memcpy (regval, val, TYPE_LENGTH (type)); - regcache_cooked_write (regcache, - tdep->ppc_gp0_regnum + greg, - regval); - } - write_memory (gparam, val, TYPE_LENGTH (type)); + regcache_cooked_write (regcache, + tdep->ppc_gp0_regnum + greg, + regval); } - /* Always consume parameter stack space. */ + freg++; greg++; - gparam = align_up (gparam + TYPE_LENGTH (type), tdep->wordsize); + /* Always consume parameter stack space. */ + gparam = align_up (gparam + 8, tdep->wordsize); } else if (TYPE_CODE (type) == TYPE_CODE_FLT && TYPE_LENGTH (type) == 16 --=-A85/FlzqS62W/SVO7VZ9--