From patchwork Mon Jul 30 09:25:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Hayward X-Patchwork-Id: 28677 Received: (qmail 57784 invoked by alias); 30 Jul 2018 09:25:52 -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 57772 invoked by uid 89); 30 Jul 2018 09:25:51 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:sk:2018073, alan, Alan, H*r:10a6 X-HELO: EUR02-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr20072.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.107.2.72) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 30 Jul 2018 09:25:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=wdc/god/VQv3qY38D18japQG7iA70EjnRlpSesbbL/E=; b=PRtxd+SCGZYGroBQH7bLaK9ltIJY1ThHYrg0+A2zx4ctWeUTRmDBDaOE7Koj1jCc23GJmKNQxq/xuPKN8xYbhkTD0ahKRTlHBfD98qLvr/M4+AdrRVQdTbF/x0uzwGGiL5fyXogZyWtkdjy0I9U1jy/kex21DpOPspdLbs7UsgY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.manchester.arm.com (217.140.106.32) by DB6PR0802MB2133.eurprd08.prod.outlook.com (2603:10a6:4:83::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.21; Mon, 30 Jul 2018 09:25:46 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH v2 2/3] Detect SVE when reading aarch64 core files Date: Mon, 30 Jul 2018 10:25:27 +0100 Message-Id: <20180730092528.98739-3-alan.hayward@arm.com> In-Reply-To: <20180730092528.98739-1-alan.hayward@arm.com> References: <20180730092528.98739-1-alan.hayward@arm.com> MIME-Version: 1.0 Return-Path: alan.hayward@arm.com Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes Add a function which reads the vector length from the SVE section within an aarch64 core file. The SVE section in a core file contains a header followed by the registers. All macros to parse access this structure. 2018-07-30 Alan Hayward * aarch64-linux-tdep.c (struct struct_contents): Add struct. (SVE_HEADER_SIZE): Add Macro. (SVE_HEADER_WRITE): Likewise. (SVE_HEADER_READ): Likewise. (aarch64_linux_core_read_vq): Add function. (aarch64_linux_core_read_description): Check for SVE section. --- gdb/aarch64-linux-tdep.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 3 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 7b63cddbe6..f9a95950da 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -219,6 +219,75 @@ const struct regset aarch64_linux_fpregset = regcache_supply_regset, regcache_collect_regset }; +/* Description of the fields in an SVE header at the start of a SVE regset. */ + +struct struct_contents { + int len; + int offset; +} sve_header[] = + { + { 4, 0 }, /* __u32 size. */ + { 4, 4 }, /* __u32 max_size. */ + { 2, 8 }, /* __u16 vl. */ + { 2, 10 }, /* __u16 max_vl. */ + { 2, 12 }, /* __u16 flags. */ + { 2, 14 }, /* __u16 reserved. */ + { -1, 16 } + }; + +#define SVE_HEADER_SIZE (sve_header[6].offset) + +#define SVE_HEADER_WRITE(header, entry, byte_order, value) \ + store_unsigned_integer ((gdb_byte *) header + sve_header[entry].offset, \ + sve_header[entry].len, byte_order, value) + +#define SVE_HEADER_READ(header, entry, byte_order) \ + extract_unsigned_integer ((gdb_byte *) header + sve_header[entry].offset, \ + sve_header[entry].len, byte_order) + +/* Get VQ value from SVE section in the core dump. */ + +static uint64_t +aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd) +{ + gdb_byte header[SVE_HEADER_SIZE]; + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve"); + + if (!sve_section) + { + /* No SVE state. */ + return 0; + } + + size_t size = bfd_section_size (abfd, sve_section); + + /* Check extended state size. */ + if (size < SVE_HEADER_SIZE) + { + warning (_("'.reg-aarch-sve' section in core file too small.")); + return 0; + } + + if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE)) + { + warning (_("Couldn't read sve header from " + "'.reg-aarch-sve' section in core file.")); + return 0; + } + + uint64_t vq = sve_vq_from_vl (SVE_HEADER_READ (header, 2, byte_order)); + + if (vq > AARCH64_MAX_SVE_VQ) + { + warning (_("sve header invalid in " + "'.reg-aarch-sve' section in core file.")); + return 0; + } + + return vq; +} + /* Implement the "regset_from_core_section" gdbarch method. */ static void @@ -233,8 +302,7 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, &aarch64_linux_fpregset, NULL, cb_data); } -/* Implement the "core_read_description" gdbarch method. SVE not yet - supported. */ +/* Implement the "core_read_description" gdbarch method. */ static const struct target_desc * aarch64_linux_core_read_description (struct gdbarch *gdbarch, @@ -245,7 +313,7 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch, if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1) return NULL; - return aarch64_read_description (0); + return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd)); } /* Implementation of `gdbarch_stap_is_single_operand', as defined in