From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 108336 invoked by alias); 10 Aug 2018 16:09:17 -0000 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 Received: (qmail 108202 invoked by uid 89); 10 Aug 2018 16:09:16 -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= X-HELO: EUR04-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr70083.outbound.protection.outlook.com (HELO EUR04-HE1-obe.outbound.protection.outlook.com) (40.107.7.83) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 10 Aug 2018 16:09:14 +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=fKfk8DevCnXulhxupA907f5f0fCJtyBV0wueM9uqJ2w=; b=gO4emfMKOPRQvuCQ01TgeOtmF2YpCUF2bHzW4IV5E6NNsG9HQzBsuJXBzhUSOg3dgFx8GQQbK2fG00hkNy9/c2I49CmQKgreebwPoQBSKHZ0X6iPMczkvsdP+ZD/E+3Qrw/8RQWKWdvad/jxAgAz/E5hLeWA6Nk6VpytAHCiSLs= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Alan.Hayward@arm.com; Received: from C02TF0U7HF1T.manchester.arm.com (217.140.106.32) by AM4PR0802MB2130.eurprd08.prod.outlook.com (2603:10a6:200:5c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1038.19; Fri, 10 Aug 2018 16:09:07 +0000 From: Alan Hayward To: gdb-patches@sourceware.org Cc: nd@arm.com, Alan Hayward Subject: [PATCH v3 2/3] Detect SVE when reading aarch64 core files Date: Fri, 10 Aug 2018 16:09:00 -0000 Message-Id: <20180810160849.68985-3-alan.hayward@arm.com> In-Reply-To: <20180810160849.68985-1-alan.hayward@arm.com> References: <20180810160849.68985-1-alan.hayward@arm.com> MIME-Version: 1.0 Content-Type: text/plain Return-Path: alan.hayward@arm.com Received-SPF: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-IsSubscribed: yes X-SW-Source: 2018-08/txt/msg00285.txt.bz2 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. Add defines to easily access the header fields within a buffer. 2018-08-10 Alan Hayward * aarch64-linux-tdep.c (SVE_HEADER_SIZE_LENGTH): Add define. (SVE_HEADER_MAX_SIZE_LENGTH): Likewise. (SVE_HEADER_VL_LENGTH): Likewise. (SVE_HEADER_MAX_VL_LENGTH): Likewise. (SVE_HEADER_FLAGS_LENGTH): Likewise. (SVE_HEADER_RESERVED_LENGTH): Likewise. (SVE_HEADER_SIZE_OFFSET): Likewise. (SVE_HEADER_MAX_SIZE_OFFSET): Likewise. (SVE_HEADER_VL_OFFSET): Likewise. (SVE_HEADER_MAX_VL_OFFSET): Likewise. (SVE_HEADER_FLAGS_OFFSET): Likewise. (SVE_HEADER_RESERVED_OFFSET): Likewise. (SVE_HEADER_SIZE): Likewise. (aarch64_linux_core_read_vq): Add function. (aarch64_linux_core_read_description): Check for SVE section. --- gdb/aarch64-linux-tdep.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 7b63cddbe6..73cb9ea714 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -219,6 +219,74 @@ const struct regset aarch64_linux_fpregset = regcache_supply_regset, regcache_collect_regset }; +/* The fields in an SVE header at the start of a SVE regset. */ + +#define SVE_HEADER_SIZE_LENGTH 4 +#define SVE_HEADER_MAX_SIZE_LENGTH 4 +#define SVE_HEADER_VL_LENGTH 2 +#define SVE_HEADER_MAX_VL_LENGTH 2 +#define SVE_HEADER_FLAGS_LENGTH 2 +#define SVE_HEADER_RESERVED_LENGTH 2 + +#define SVE_HEADER_SIZE_OFFSET 0 +#define SVE_HEADER_MAX_SIZE_OFFSET \ + (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH) +#define SVE_HEADER_VL_OFFSET \ + (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH) +#define SVE_HEADER_MAX_VL_OFFSET \ + (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH) +#define SVE_HEADER_FLAGS_OFFSET \ + (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH) +#define SVE_HEADER_RESERVED_OFFSET \ + (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH) +#define SVE_HEADER_SIZE \ + (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH) + +/* 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 == nullptr) + { + /* 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 vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET, + SVE_HEADER_VL_LENGTH, byte_order); + uint64_t vq = sve_vq_from_vl (vl); + + if (vq > AARCH64_MAX_SVE_VQ || vq == 0) + { + 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 +301,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 +312,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 -- 2.15.2 (Apple Git-101.1)