From patchwork Mon Sep 18 21:26:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76318 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5881385694E for ; Mon, 18 Sep 2023 21:28:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E5881385694E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072536; bh=ZnAQp6MYZ8yW++AQpDycZ3H9ZkUFxJeWHPrI7lcDTz0=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=wZlV3eCbWdtV5116ilDjYHHE7S0WLaScoHxnCzl9nInl4BexQlWxxgzC6iPf0A5O7 tmhtszv24ckk9P+y8meX9Ebx8kSq3dY2VNhSFLw1lh/FYowBTI5hgqPGaWEyHc47+f WvD2UmxoxJ2q4fXn9spz2PPyWvU7Hm9d12UABBrw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2045.outbound.protection.outlook.com [40.107.7.45]) by sourceware.org (Postfix) with ESMTPS id E033138582B7 for ; Mon, 18 Sep 2023 21:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E033138582B7 Received: from DB8PR06CA0043.eurprd06.prod.outlook.com (2603:10a6:10:120::17) by AS8PR08MB9814.eurprd08.prod.outlook.com (2603:10a6:20b:615::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 18 Sep 2023 21:27:14 +0000 Received: from DBAEUR03FT018.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:120:cafe::b3) by DB8PR06CA0043.outlook.office365.com (2603:10a6:10:120::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21 via Frontend Transport; Mon, 18 Sep 2023 21:27:14 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT018.mail.protection.outlook.com (100.127.142.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.15 via Frontend Transport; Mon, 18 Sep 2023 21:27:14 +0000 Received: ("Tessian outbound c99fbc01d472:v175"); Mon, 18 Sep 2023 21:27:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: aadca86edc201de5 X-CR-MTA-TID: 64aa7808 Received: from ce0ab2095205.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 12090FCB-E802-46C2-8BD5-0AF75D373A52.1; Mon, 18 Sep 2023 21:27:08 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ce0ab2095205.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IauDVgnBPca/I18ZvHZPGHgmMhmSg0PmrIzPnkOWNmDWjnon08DtMAZ6ku6TC8DfzAteHluEzXaLOLAzPnOLrZn86HlmXrsBP2iqyPA61v0BeBwfeTEeMVw0yGWawnc4J4rDyp6hEnzPjahlVfLwTwjn7CjMR23udOBP+KSjXvl3OWqX3l7rrPPbNE8fsIHR/r62oGX+xuwBvtGaFINs52ZBx83rgVZm4gat1EdnShP3CA3QhpciH8CoXA+igTqu5As96xrGPBxSh3pKueLmIt1/ir9Ns+PVMlxip2XpicYlNwNyJF6xtL+sgIBrLm/vSwxgETdDpgLgA0BtJo5a+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ZnAQp6MYZ8yW++AQpDycZ3H9ZkUFxJeWHPrI7lcDTz0=; b=BwrTEbvFP2+UCUVcGDkX8GHosq3ez81Tc45com6CwcXzXdcQsl2YWFrZI6z9jHrY9rjUDag6K4mtIQRUrvE7YPvxlhFOuOu7XHBKpwsf0UvqQf4o2TbP/lEkXYo4BCSFERd36N9qji+po3fZkjAxvSJN8wE0F5J3eSvonF+2CQBhSqYP0kIISzDcdgOuiBkauWd36llzbXZqCPTGA5Wdwcofc5lgOGpTBy9Es/WU4T7JoP5AYh5Ke+XuFWuoozm+aWbS5I4bAM655zeGoq0pJY/3MGfnmoLFdX0b6VWcwftyDc89Lk5GtVg9qIXhjEkpdlC6hfHXdWUkOILujFzoIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); arc=none Received: from AM6P193CA0133.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::38) by AS8PR08MB5928.eurprd08.prod.outlook.com (2603:10a6:20b:29b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 18 Sep 2023 21:27:05 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::49) by AM6P193CA0133.outlook.office365.com (2603:10a6:209:85::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27 via Frontend Transport; Mon, 18 Sep 2023 21:27:05 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 40.67.248.234) smtp.mailfrom=arm.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 40.67.248.234 as permitted sender) receiver=protection.outlook.com; client-ip=40.67.248.234; helo=nebula.arm.com; pr=C Received: from nebula.arm.com (40.67.248.234) by AM7EUR03FT009.mail.protection.outlook.com (100.127.140.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:05 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX04.Arm.com (10.251.24.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Mon, 18 Sep 2023 21:27:04 +0000 Received: from e129171.arm.com (10.57.64.238) by mail.arm.com (10.251.24.32) with Microsoft SMTP Server id 15.1.2507.27 via Frontend Transport; Mon, 18 Sep 2023 21:27:04 +0000 To: Subject: [PATCH v7 09/18] [gdb/aarch64] sve: Fix signal frame z/v register restore Date: Mon, 18 Sep 2023 22:26:42 +0100 Message-ID: <20230918212651.660141-10-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230918212651.660141-1-luis.machado@arm.com> References: <20230918212651.660141-1-luis.machado@arm.com> MIME-Version: 1.0 X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: AM7EUR03FT009:EE_|AS8PR08MB5928:EE_|DBAEUR03FT018:EE_|AS8PR08MB9814:EE_ X-MS-Office365-Filtering-Correlation-Id: a0df0c40-54e0-4c2a-8e7b-08dbb88e06ff x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: PgG8zhdxzg5BjX95hibYWNiSDX5/Ju6Da92egIIV28Q+8pkb8crQ/4dbssKn9QVH2KqQsFwdRzmV7Ltcyxfdoxn7bp20Ug86MtXcG35h7Zc3vSw4nY8xkSZa8sdvlGl4Puf24iPXVeb+7xnRsExRXBrN/hKVxA/eC9POXnva7xrq2LB7RgG2XQyTxYXbq7J4V3PmkQFn9l5QKP8hCdRQ88I8SzneM9rfvs9sGI9To3WqVBE8gIvfudu16aRhRuw86oq0IYNdqAIiE9/EvtmLXUojyd5ZKODvv9gnYlKQ24ismusZ8oCADPzEEuU8Jg99ByeHO6/7IZb7V8di4wiCCI8Ik4VRYYs/GkbRWsvGDKOuQ2AaNcKkWWeEv9nbfEf+Hb/D1TXWZYk47tZxYzvJtZbO3TXSGTfPwwgnpO7wM/mzkJFWqbZjaZp5QlaUCfwAn4CumFshY3fq9B7IiLKfIJw+9JBwGAlo/vJUXyLzvA+EjbEXwq9v5nowtBmBxRFyrUcULFDszqlewY+OikIuJiOuNsH/JSJTVqSP04ViVhKP/7+ppxb0EmIS3ridyvjw8/S6ZUpRnKmG9KI0a+jS9Sr23HztJ8cA9aihlkRtceCUaJxrFrTyubXAlXch/7CXr0B9COZ5Vv/oiXRFVoRO+729pAehdDK1tlDo6b+HRd8qsADPPomZtzaOC/AcrHUq9R2bbgnQ5YSYx5ZFqSgt1Ddy/ZjJclrpeJrqdzUQW1819NDpp0Ype5WgNkWeAlke5X6Pma/9EMj9UbdcxcMOkQ== X-Forefront-Antispam-Report-Untrusted: CIP:40.67.248.234; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:nebula.arm.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230031)(4636009)(396003)(346002)(136003)(39860400002)(376002)(82310400011)(186009)(1800799009)(451199024)(46966006)(40470700004)(36840700001)(2906002)(44832011)(5660300002)(8936002)(4326008)(8676002)(1076003)(41300700001)(54906003)(6916009)(316002)(40460700003)(70586007)(70206006)(478600001)(6666004)(36756003)(7696005)(2616005)(83380400001)(26005)(40480700001)(426003)(336012)(36860700001)(47076005)(82740400003)(356005)(81166007)(86362001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB5928 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT018.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 3a32dc9e-0131-4ad7-d0e9-08dbb88e01be X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kaV+L6oNPtMhsQeKN7rB01w//tyM5rd76euSbABg8JIGsUfQIgB7wNnZeWICg/CMvJYsGWQsxo6BNASRfgd2qdjJPpRgCrGIfMdICyNz0oSsDie9psx/bAXtJ5FFKs7y1JqfuBkUN+3M73P1bU1iae0TgHPgAPTUf73lgIwXWzSkpmVLtYE+5MIalprjp2p0pwtVfKEyZ+tD3POl3bpdEXd+c1yaRyOdgzxJ96PEEJTEI8LWjwDEn6hXqGVncp8ptMyGo0VH6k3oqO/NKTjc/n/Q0doCJdtS8PGZSVgYUq3WAj4dL3IJfz52LyWt93mM3pew2m2xDVsJf6s3mPLkaIBQ6zVqg3A1iB99TAaVxxwNTu2Og4D0KjpQI3Kf4gyF3TflAx8mhaAB0a1YJt6Ze5RTeKJd6j8wEZoGTjRRLMgJ76SzXY9BGUahd1rLxXFxoTgAu9rKnyFWv+xhLeYmhPt6ObFk9+A1mh1iNKmdJMhR0CVv1WAJFyJiqwBLS1Cy+cq3BinSDXeMYexWd5G0aGwgLYBnpdUtnS+gP0CbV5WRHoyWLnwV1AYWGU+0ycvRKbAeCXYU8iXlfhvuLsBAeyauZQxAK4GfH4aFCOfkV6NfuOhPIcE5rD+epzHTDXKuBkbrBr/rXW+G10DHYQ6EEpUAEu+oJ9zuRBgAR7Cj/7bK0/vo1wsKUYL1sN4PD3DiB2GpyztqqBqGt0tylufGv6/8Brck36WAmjdKo8ck+UTKZZsEUvF0TO0e9vD52j3+ X-Forefront-Antispam-Report: CIP:63.35.35.123; CTRY:IE; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:64aa7808-outbound-1.mta.getcheckrecipient.com; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; CAT:NONE; SFS:(13230031)(4636009)(346002)(396003)(376002)(136003)(39860400002)(186009)(82310400011)(1800799009)(451199024)(40470700004)(36840700001)(46966006)(81166007)(26005)(82740400003)(8936002)(2616005)(40460700003)(1076003)(8676002)(4326008)(107886003)(83380400001)(36860700001)(2906002)(36756003)(47076005)(336012)(426003)(40480700001)(44832011)(86362001)(7696005)(478600001)(5660300002)(6666004)(6916009)(316002)(54906003)(70586007)(70206006)(41300700001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:14.5335 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0df0c40-54e0-4c2a-8e7b-08dbb88e06ff X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT018.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9814 X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Luis Machado via Gdb-patches From: Luis Machado Reply-To: Luis Machado Cc: thiago.bauermann@linaro.org Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" While doing some SME work, I ran into the situation where the Z register contents restored from a signal frame are incorrect if the signal frame only contains fpsimd state and no sve state. This happens because we only restore the v register values in that case, and don't do anything for the z registers. Fix this by initializing the z registers to 0 and then copying over the overlapping part of the v registers to the z registers. While at it, refactor the code a bit to simplify it and make it smaller. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-tdep.c | 107 +++++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 45 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index b183a3c9a38..bdd5cb05c10 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -196,14 +196,13 @@ read_aarch64_ctx (CORE_ADDR ctx_addr, enum bfd_endian byte_order, /* Given CACHE, use the trad_frame* functions to restore the FPSIMD registers from a signal frame. - VREG_NUM is the number of the V register being restored, OFFSET is the - address containing the register value, BYTE_ORDER is the endianness and - HAS_SVE tells us if we have a valid SVE context or not. */ + FPSIMD_CONTEXT is the address of the signal frame context containing FPSIMD + data. */ static void -aarch64_linux_restore_vreg (struct trad_frame_cache *cache, int num_regs, - int vreg_num, CORE_ADDR offset, - enum bfd_endian byte_order, bool has_sve) +aarch64_linux_restore_vregs (struct gdbarch *gdbarch, + struct trad_frame_cache *cache, + CORE_ADDR fpsimd_context) { /* WARNING: SIMD state is laid out in memory in target-endian format. @@ -215,11 +214,22 @@ aarch64_linux_restore_vreg (struct trad_frame_cache *cache, int num_regs, 2 - If the target is little endian, then SIMD state is little endian, so no byteswap is needed. */ - if (byte_order == BFD_ENDIAN_BIG) + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + int num_regs = gdbarch_num_regs (gdbarch); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + for (int i = 0; i < 32; i++) { + CORE_ADDR offset = (fpsimd_context + AARCH64_FPSIMD_V0_OFFSET + + (i * AARCH64_FPSIMD_VREG_SIZE)); + gdb_byte buf[V_REGISTER_SIZE]; - if (target_read_memory (offset, buf, V_REGISTER_SIZE) != 0) + /* Read the contents of the V register. */ + if (target_read_memory (offset, buf, V_REGISTER_SIZE)) + error (_("Failed to read fpsimd register from signal context.")); + + if (byte_order == BFD_ENDIAN_BIG) { size_t size = V_REGISTER_SIZE/2; @@ -234,50 +244,66 @@ aarch64_linux_restore_vreg (struct trad_frame_cache *cache, int num_regs, store_unsigned_integer (buf + size , size, BFD_ENDIAN_LITTLE, u64); /* Now we can store the correct bytes for the V register. */ - trad_frame_set_reg_value_bytes (cache, AARCH64_V0_REGNUM + vreg_num, + trad_frame_set_reg_value_bytes (cache, AARCH64_V0_REGNUM + i, {buf, V_REGISTER_SIZE}); trad_frame_set_reg_value_bytes (cache, num_regs + AARCH64_Q0_REGNUM - + vreg_num, {buf, Q_REGISTER_SIZE}); + + i, {buf, Q_REGISTER_SIZE}); trad_frame_set_reg_value_bytes (cache, num_regs + AARCH64_D0_REGNUM - + vreg_num, {buf, D_REGISTER_SIZE}); + + i, {buf, D_REGISTER_SIZE}); trad_frame_set_reg_value_bytes (cache, num_regs + AARCH64_S0_REGNUM - + vreg_num, {buf, S_REGISTER_SIZE}); + + i, {buf, S_REGISTER_SIZE}); trad_frame_set_reg_value_bytes (cache, num_regs + AARCH64_H0_REGNUM - + vreg_num, {buf, H_REGISTER_SIZE}); + + i, {buf, H_REGISTER_SIZE}); trad_frame_set_reg_value_bytes (cache, num_regs + AARCH64_B0_REGNUM - + vreg_num, {buf, B_REGISTER_SIZE}); + + i, {buf, B_REGISTER_SIZE}); - if (has_sve) + if (tdep->has_sve ()) trad_frame_set_reg_value_bytes (cache, num_regs + AARCH64_SVE_V0_REGNUM - + vreg_num, {buf, V_REGISTER_SIZE}); + + i, {buf, V_REGISTER_SIZE}); } - return; - } + else + { + /* Little endian, just point at the address containing the register + value. */ + trad_frame_set_reg_addr (cache, AARCH64_V0_REGNUM + i, offset); + trad_frame_set_reg_addr (cache, num_regs + AARCH64_Q0_REGNUM + i, + offset); + trad_frame_set_reg_addr (cache, num_regs + AARCH64_D0_REGNUM + i, + offset); + trad_frame_set_reg_addr (cache, num_regs + AARCH64_S0_REGNUM + i, + offset); + trad_frame_set_reg_addr (cache, num_regs + AARCH64_H0_REGNUM + i, + offset); + trad_frame_set_reg_addr (cache, num_regs + AARCH64_B0_REGNUM + i, + offset); - /* Little endian, just point at the address containing the register - value. */ - trad_frame_set_reg_addr (cache, AARCH64_V0_REGNUM + vreg_num, offset); - trad_frame_set_reg_addr (cache, num_regs + AARCH64_Q0_REGNUM + vreg_num, - offset); - trad_frame_set_reg_addr (cache, num_regs + AARCH64_D0_REGNUM + vreg_num, - offset); - trad_frame_set_reg_addr (cache, num_regs + AARCH64_S0_REGNUM + vreg_num, - offset); - trad_frame_set_reg_addr (cache, num_regs + AARCH64_H0_REGNUM + vreg_num, - offset); - trad_frame_set_reg_addr (cache, num_regs + AARCH64_B0_REGNUM + vreg_num, - offset); - - if (has_sve) - trad_frame_set_reg_addr (cache, num_regs + AARCH64_SVE_V0_REGNUM - + vreg_num, offset); + if (tdep->has_sve ()) + trad_frame_set_reg_addr (cache, num_regs + AARCH64_SVE_V0_REGNUM + + i, offset); + } + if (tdep->has_sve ()) + { + /* If SVE is supported for this target, zero out the Z + registers then copy the first 16 bytes of each of the V + registers to the associated Z register. Otherwise the Z + registers will contain uninitialized data. */ + std::vector z_buffer (tdep->vq * 16); + + /* We have already handled the endianness swap above, so we don't need + to worry about it here. */ + memcpy (z_buffer.data (), buf, V_REGISTER_SIZE); + trad_frame_set_reg_value_bytes (cache, + AARCH64_SVE_Z0_REGNUM + i, + z_buffer); + } + } } /* Implement the "init" method of struct tramp_frame. */ @@ -432,16 +458,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, /* If there was no SVE section then set up the V registers. */ if (sve_regs == 0) - { - for (int i = 0; i < 32; i++) - { - CORE_ADDR offset = (fpsimd + AARCH64_FPSIMD_V0_OFFSET - + (i * AARCH64_FPSIMD_VREG_SIZE)); - - aarch64_linux_restore_vreg (this_cache, num_regs, i, offset, - byte_order, tdep->has_sve ()); - } - } + aarch64_linux_restore_vregs (gdbarch, this_cache, fpsimd); } trad_frame_set_id (this_cache, frame_id_build (sp, func));