From patchwork Wed Apr 22 17:51:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Arnez X-Patchwork-Id: 6387 Received: (qmail 52139 invoked by alias); 22 Apr 2015 17:51:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 52123 invoked by uid 89); 22 Apr 2015 17:51:55 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: e06smtp12.uk.ibm.com Received: from e06smtp12.uk.ibm.com (HELO e06smtp12.uk.ibm.com) (195.75.94.108) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 22 Apr 2015 17:51:54 +0000 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Apr 2015 18:51:51 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Apr 2015 18:51:48 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 07FAA1B0804B for ; Wed, 22 Apr 2015 18:52:25 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t3MHpmO063897624 for ; Wed, 22 Apr 2015 17:51:48 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t3MHplKX028238 for ; Wed, 22 Apr 2015 11:51:47 -0600 Received: from br87z6lw.de.ibm.com (dyn-9-152-212-115.boeblingen.de.ibm.com [9.152.212.115]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t3MHpkr3028228; Wed, 22 Apr 2015 11:51:46 -0600 From: Andreas Arnez To: gdb-patches@sourceware.org Cc: Sergio Durigan Junior , Ulrich Weigand Subject: [PATCH 3/4] S390: Re-arrange implementation of s390_return_value References: <1429724743-4603-1-git-send-email-arnez@linux.vnet.ibm.com> Date: Wed, 22 Apr 2015 19:51:46 +0200 In-Reply-To: <1429724743-4603-1-git-send-email-arnez@linux.vnet.ibm.com> (Andreas Arnez's message of "Wed, 22 Apr 2015 19:44:59 +0200") Message-ID: <878udk830t.fsf@br87z6lw.de.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15042217-0009-0000-0000-000003EA20E5 X-IsSubscribed: yes Move related logic in the implementation of s390_return_value closer together. This makes it easier to read and extend. gdb/ChangeLog: * s390-linux-tdep.c (s390_return_value_convention): Remove function. Inline its logic... (s390_return_value): ...here. Instead, move the handling of the "register" return value convention... (s390_register_return_value): ...here. New function. --- gdb/s390-linux-tdep.c | 158 +++++++++++++++++++++++--------------------------- 1 file changed, 73 insertions(+), 85 deletions(-) diff --git a/gdb/s390-linux-tdep.c b/gdb/s390-linux-tdep.c index 3b7e4b6..bb9b28e 100644 --- a/gdb/s390-linux-tdep.c +++ b/gdb/s390-linux-tdep.c @@ -2708,110 +2708,98 @@ s390_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr) } -/* Function return value access. */ +/* Helper for s390_return_value: Set or retrieve a function return + value if it resides in a register. */ -static enum return_value_convention -s390_return_value_convention (struct gdbarch *gdbarch, struct type *type) +static void +s390_register_return_value (struct gdbarch *gdbarch, struct type *type, + struct regcache *regcache, + gdb_byte *out, const gdb_byte *in) { - if (TYPE_LENGTH (type) > 8) - return RETURN_VALUE_STRUCT_CONVENTION; + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + int word_size = gdbarch_ptr_bit (gdbarch) / 8; + int length = TYPE_LENGTH (type); + int code = TYPE_CODE (type); - switch (TYPE_CODE (type)) + if (code == TYPE_CODE_FLT || code == TYPE_CODE_DECFLOAT) { - case TYPE_CODE_STRUCT: - case TYPE_CODE_UNION: - case TYPE_CODE_ARRAY: - case TYPE_CODE_COMPLEX: - return RETURN_VALUE_STRUCT_CONVENTION; - - default: - return RETURN_VALUE_REGISTER_CONVENTION; + /* Float-like value: left-aligned in f0. */ + if (in != NULL) + regcache_cooked_write_part (regcache, S390_F0_REGNUM, + 0, length, in); + else + regcache_cooked_read_part (regcache, S390_F0_REGNUM, + 0, length, out); + } + else if (length <= word_size) + { + /* Integer: zero- or sign-extended in r2. */ + if (out != NULL) + regcache_cooked_read_part (regcache, S390_R2_REGNUM, + word_size - length, length, out); + else if (TYPE_UNSIGNED (type)) + regcache_cooked_write_unsigned + (regcache, S390_R2_REGNUM, + extract_unsigned_integer (in, length, byte_order)); + else + regcache_cooked_write_signed + (regcache, S390_R2_REGNUM, + extract_signed_integer (in, length, byte_order)); + } + else if (length == 2 * word_size) + { + /* Double word: in r2 and r3. */ + if (in != NULL) + { + regcache_cooked_write (regcache, S390_R2_REGNUM, in); + regcache_cooked_write (regcache, S390_R3_REGNUM, + in + word_size); + } + else + { + regcache_cooked_read (regcache, S390_R2_REGNUM, out); + regcache_cooked_read (regcache, S390_R3_REGNUM, + out + word_size); + } } + else + internal_error (__FILE__, __LINE__, _("invalid return type")); } + +/* Implement the 'return_value' gdbarch method. */ + static enum return_value_convention s390_return_value (struct gdbarch *gdbarch, struct value *function, struct type *type, struct regcache *regcache, gdb_byte *out, const gdb_byte *in) { - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - int word_size = gdbarch_ptr_bit (gdbarch) / 8; enum return_value_convention rvc; - int length; type = check_typedef (type); - rvc = s390_return_value_convention (gdbarch, type); - length = TYPE_LENGTH (type); - if (in) + switch (TYPE_CODE (type)) { - switch (rvc) - { - case RETURN_VALUE_REGISTER_CONVENTION: - if (TYPE_CODE (type) == TYPE_CODE_FLT - || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) - { - /* When we store a single-precision value in an FP register, - it occupies the leftmost bits. */ - regcache_cooked_write_part (regcache, S390_F0_REGNUM, - 0, length, in); - } - else if (length <= word_size) - { - /* Integer arguments are always extended to word size. */ - if (TYPE_UNSIGNED (type)) - regcache_cooked_write_unsigned (regcache, S390_R2_REGNUM, - extract_unsigned_integer (in, length, byte_order)); - else - regcache_cooked_write_signed (regcache, S390_R2_REGNUM, - extract_signed_integer (in, length, byte_order)); - } - else if (length == 2*word_size) - { - regcache_cooked_write (regcache, S390_R2_REGNUM, in); - regcache_cooked_write (regcache, S390_R3_REGNUM, in + word_size); - } - else - internal_error (__FILE__, __LINE__, _("invalid return type")); - break; - - case RETURN_VALUE_STRUCT_CONVENTION: - error (_("Cannot set function return value.")); - break; - } + case TYPE_CODE_STRUCT: + case TYPE_CODE_UNION: + case TYPE_CODE_ARRAY: + case TYPE_CODE_COMPLEX: + rvc = RETURN_VALUE_STRUCT_CONVENTION; + break; + default: + rvc = TYPE_LENGTH (type) <= 8 + ? RETURN_VALUE_REGISTER_CONVENTION + : RETURN_VALUE_STRUCT_CONVENTION; } - else if (out) - { - switch (rvc) - { - case RETURN_VALUE_REGISTER_CONVENTION: - if (TYPE_CODE (type) == TYPE_CODE_FLT - || TYPE_CODE (type) == TYPE_CODE_DECFLOAT) - { - /* When we store a single-precision value in an FP register, - it occupies the leftmost bits. */ - regcache_cooked_read_part (regcache, S390_F0_REGNUM, - 0, length, out); - } - else if (length <= word_size) - { - /* Integer arguments occupy the rightmost bits. */ - regcache_cooked_read_part (regcache, S390_R2_REGNUM, - word_size - length, length, out); - } - else if (length == 2*word_size) - { - regcache_cooked_read (regcache, S390_R2_REGNUM, out); - regcache_cooked_read (regcache, S390_R3_REGNUM, out + word_size); - } - else - internal_error (__FILE__, __LINE__, _("invalid return type")); - break; - case RETURN_VALUE_STRUCT_CONVENTION: - error (_("Function return value unknown.")); - break; - } + if (in != NULL || out != NULL) + { + if (rvc == RETURN_VALUE_REGISTER_CONVENTION) + s390_register_return_value (gdbarch, type, regcache, out, in); + else if (in != NULL) + error (_("Cannot set function return value.")); + else + error (_("Function return value unknown.")); } return rvc;