From patchwork Mon Sep 18 21:26:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76312 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 E8EB33856943 for ; Mon, 18 Sep 2023 21:27:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8EB33856943 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072463; bh=iCETcDpaCaaJdYb2L8yoKjyzHEIo4Vqb4DDvG7hzG5Q=; 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=kuDMHF4DdFJm4tuzRIA2Cj62pQntbAsRAhatc6ohi7vAYwmTXJ5dOVeRxb5AT4+ul hVEId1nLRldjkxXP5i0C4NbWi66vTWCMNNRFGqAkB/EJpxfyIzZXZtYCVG5DgcnxhJ 0WtSnUbfCEsO9S7boIWvGFW9TRbf5N1T9G1ufshk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2042.outbound.protection.outlook.com [40.107.8.42]) by sourceware.org (Postfix) with ESMTPS id D52E03857713 for ; Mon, 18 Sep 2023 21:27:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D52E03857713 Received: from DUZPR01CA0170.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b3::28) by AS8PR08MB8874.eurprd08.prod.outlook.com (2603:10a6:20b:5b8::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:12 +0000 Received: from DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:4b3:cafe::b9) by DUZPR01CA0170.outlook.office365.com (2603:10a6:10:4b3::28) 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:11 +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 DBAEUR03FT025.mail.protection.outlook.com (100.127.142.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:11 +0000 Received: ("Tessian outbound 30c9f5e988c5:v175"); Mon, 18 Sep 2023 21:27:11 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 404f9a431713f1bd X-CR-MTA-TID: 64aa7808 Received: from d9a271e6ed10.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 9C2EBFB7-D967-4FD1-823A-E27858DD784F.1; Mon, 18 Sep 2023 21:27:04 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d9a271e6ed10.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O4LiZSTDajMS+aVxouORstkvo+I64wuFdhxBpD9Wh5Rj823hNPUS+l+Ad0WILZrnt7NBDvvVEcWxKkQvZOtcfaiZ5jemz93buyyKgm5M5BurtK+a5ZifaZgFnqnJwHDeSlB1r8AVdLgMbswcX+lajHQAovCZeXNJVW1DpEs1f4cdSExseYhMWQZkedMY/xho/OEq/X6gt4zSGT2k2LES9UR4Jq3qI4AdHyf4xX2LOgDdCnnk6L/HgVEVovwTUDktrRhVDbNFdJWKcLHx1JWXuSwLuUHVxpenYItmT29u7rajMH9S8zWpLEWjtLLcvNsi26dKE72yjQO2qbEkSh/2FQ== 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=iCETcDpaCaaJdYb2L8yoKjyzHEIo4Vqb4DDvG7hzG5Q=; b=cBDOSC1RL2zgfalYa9nyusMx1ueavXB6856oLRLbY3NQHTMY8ZUTHmsDSVheERDAkCYsK84MHyAszeJgtgU6PuJAg3fxLI5+gsPi6+AA5Kkw6HG7iPi+ZOriYnJ2PXfG47ao0gW5DTt2fxWg8RQ8J20n/pL1ujvagTD5EFzPOKU0oSO750Wc71MwQgByak+yxSNKOlL2EmlnU7cvAhytfo49bNw2Zt742unlt7ALCMCpwjdBxER2UKL/qBtHQFPGll/akhys1eL0RZw6pTEyWVHshaI8MgnY+1gswzeXU3zx9TAo/WbBrZ/A7u/MLi7ig+ggXW55KgoTKu11plq78Q== 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 AM6P193CA0136.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::41) by DU0PR08MB8373.eurprd08.prod.outlook.com (2603:10a6:10:40a::12) 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:02 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::5a) by AM6P193CA0136.outlook.office365.com (2603:10a6:209:85::41) 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:02 +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:02 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) 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:01 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:01 +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:01 +0000 To: Subject: [PATCH v7 01/18] [gdb/aarch64] Fix register fetch/store order for native AArch64 Linux Date: Mon, 18 Sep 2023 22:26:34 +0100 Message-ID: <20230918212651.660141-2-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_|DU0PR08MB8373:EE_|DBAEUR03FT025:EE_|AS8PR08MB8874:EE_ X-MS-Office365-Filtering-Correlation-Id: a4ce32d8-df59-41e9-d2f4-08dbb88e0573 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: x/6elwL0Jv8iQGUqM2KOqQVWm1lfIKnWteXSBqP1ewoTQF4oVuZQe2/Yp3Iu+KGawBp3NqYOlcwzcK6JSvpZPFl1octIVXckn+CTrvXHMTn6MIQgFlX2iiBhuabjpADgIumxFU9pyzuiUXqQ9nln3dqseJPBwv9R8RJkG1lIslVlI9uCOcOia5g6TYuej6f5ZGmcSrzh4qEWGBvWIPY3wN7AyqgiBRs+mfOj+HFF+biraBiewuEdXnCePKBV4to/O9ADfRxHjeIqvsAsPsJIhq/200lieSwG47MMh4+85a7Zcb6v6kTAN3dJlcps6dcNCJvS9rzec49bi5pRLZz8GddahMBVYSY+avFrXEa1P/GdT2K5/YQ5ZNCD8JLqV2S1WNwhB7GI+cpfHi/a6KUB4mscTU/8YBOHjBYTLswG+F0RSvwNBmlf+CnAbC+LEICo6OVb3fStRnpa5rJoN13ziomxt05o4uCkD0gkItmaeEBYb9qyePYqmBhX1/CTFmKwHLT10LKDE4PbfVQw9ZqH9iEdPybi5hJIyT28C9e7DoXWrq4sJ9SD6lvDClenuXgiPtfk0/B7rzV3pI22K0+90+b7dPX9diEo/vRvU2PgWaT9uU18TkiT06597AAtET+2AIfVoFF3cfE8UiS2WzeFtW4mZlMOCGvtkXeu4OyzQnvC11Hkvr+SA58a9zmaFNKpQTRE2PVc32xjVg9biKsHwhv6idlyMG49xmBWberixwm55qqeYEN0rRTsBjAeBH3dbs3wlyfXinajNi7938dRfg== 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)(39860400002)(136003)(376002)(346002)(396003)(82310400011)(186009)(1800799009)(451199024)(36840700001)(40470700004)(46966006)(36756003)(40480700001)(40460700003)(7696005)(2616005)(6666004)(2906002)(478600001)(1076003)(5660300002)(83380400001)(86362001)(336012)(426003)(26005)(6916009)(316002)(70206006)(70586007)(54906003)(41300700001)(4326008)(8676002)(8936002)(44832011)(81166007)(356005)(82740400003)(47076005)(36860700001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8373 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: ae81ab17-4660-400d-92cc-08dbb88dff8e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cSkoduVrfU9MEEr6sNhZSLQKdf7XVZKD/VG/oNT+LDeb08nO67ulHyMZ+T92wzVs6+WUH1kkY7QrgxPArk6OeK0UIjbK2rg+gFBCGR2M/k4+rL1WN7pkfchaW/t/rBIIY6wW2WCjt0bP6Oi9fBLtEPxbdsEtO99OCe6/wny52GfvXgmUDmK8TK0W9uO3vS2UyWxhWVf2RZUCtDKlfBiSYOANoJLxRXX1vNxLfSCzhjkP+n2FP/W8+2ugnD/jKIkEjAjpReNFNazGjCmT6Irqe+8MrZJPJi/lPIGObemowedIIv7fpO1+JkIZBID5BZ04iMvKJNK/PjPk99UKlVtfn/z2h0h5EXSYRH8bPT7lRo3RQqMFhh0OW7d1rUGZsgfgxyAFokUtIap2ZV9ZXU+pS41ddpAxBf8pruZR13IX8wYsyn8lg0pQyZJGeGXxVm8t687DQlD89C95hpqDX9ScVtEYUWQVzsV5XdEbyGWYZRSx0PsECHTfdWsOQI36DPPLBg+KcJxKsqpJQZ96PXJ1wHlm3c/U5PLDeaRzNGv2INa8tEz4DZge5dZd1jYIFC3VYY63skKoCrv/1ZC+1/f5fi4WVzt2rvQZaOt21bOLeicGglslekDWuOwpkpG/+bN4osCJeqsP6flcgIQGk7XJcwbTwdjUnXLb9FriPZBpIaJjsyFRTFvRowD0IjIz7SED0hAmRtMO+hOO2hVwNVzyhxbSIWx4cyrJUsTWKyWGVOubMBsVOvRK7FX5/Ngxa7UQ 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)(39860400002)(376002)(396003)(346002)(136003)(1800799009)(82310400011)(186009)(451199024)(46966006)(40470700004)(36840700001)(54906003)(478600001)(70586007)(70206006)(316002)(26005)(336012)(426003)(1076003)(7696005)(2616005)(6666004)(6916009)(40480700001)(8676002)(41300700001)(44832011)(8936002)(5660300002)(4326008)(2906002)(82740400003)(81166007)(86362001)(83380400001)(47076005)(107886003)(36756003)(36860700001)(40460700003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:11.9400 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a4ce32d8-df59-41e9-d2f4-08dbb88e0573 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: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8874 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" Updates on v4: - Fix FPCR comparison and other review comments. --- I noticed we don't handle register reads/writes in the best way for native AArch64 Linux. Some registers are fetched/stored even if upper level code told us to fetch a particular register number. Fix this by being more strict about which registers we touch when reading/writing them in the native AArch64 Linux layer. There should be no user-visible changes due to this patch. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-nat.c | 60 ++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index eeb9761bfe5..8844fc722cf 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -504,6 +504,7 @@ aarch64_fetch_registers (struct regcache *regcache, int regno) aarch64_gdbarch_tdep *tdep = gdbarch_tdep (regcache->arch ()); + /* Do we need to fetch all registers? */ if (regno == -1) { fetch_gregs_from_thread (regcache); @@ -521,28 +522,28 @@ aarch64_fetch_registers (struct regcache *regcache, int regno) if (tdep->has_tls ()) fetch_tlsregs_from_thread (regcache); } + /* General purpose register? */ else if (regno < AARCH64_V0_REGNUM) fetch_gregs_from_thread (regcache); - else if (tdep->has_sve ()) + /* SVE register? */ + else if (tdep->has_sve () && regno <= AARCH64_SVE_VG_REGNUM) fetch_sveregs_from_thread (regcache); - else + /* FPSIMD register? */ + else if (regno <= AARCH64_FPCR_REGNUM) fetch_fpregs_from_thread (regcache); - - if (tdep->has_pauth ()) - { - if (regno == AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base) - || regno == AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base)) - fetch_pauth_masks_from_thread (regcache); - } - - /* Fetch individual MTE registers. */ - if (tdep->has_mte () - && (regno == tdep->mte_reg_base)) + /* PAuth register? */ + else if (tdep->has_pauth () + && (regno == AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base) + || regno == AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base))) + fetch_pauth_masks_from_thread (regcache); + /* MTE register? */ + else if (tdep->has_mte () + && (regno == tdep->mte_reg_base)) fetch_mteregs_from_thread (regcache); - - if (tdep->has_tls () - && regno >= tdep->tls_regnum_base - && regno < tdep->tls_regnum_base + tdep->tls_register_count) + /* TLS register? */ + else if (tdep->has_tls () + && regno >= tdep->tls_regnum_base + && regno < tdep->tls_regnum_base + tdep->tls_register_count) fetch_tlsregs_from_thread (regcache); } @@ -592,6 +593,7 @@ aarch64_store_registers (struct regcache *regcache, int regno) aarch64_gdbarch_tdep *tdep = gdbarch_tdep (regcache->arch ()); + /* Do we need to store all registers? */ if (regno == -1) { store_gregs_to_thread (regcache); @@ -606,22 +608,26 @@ aarch64_store_registers (struct regcache *regcache, int regno) if (tdep->has_tls ()) store_tlsregs_to_thread (regcache); } + /* General purpose register? */ else if (regno < AARCH64_V0_REGNUM) store_gregs_to_thread (regcache); - else if (tdep->has_sve ()) + /* SVE register? */ + else if (tdep->has_sve () && regno <= AARCH64_SVE_VG_REGNUM) store_sveregs_to_thread (regcache); - else + /* FPSIMD register? */ + else if (regno <= AARCH64_FPCR_REGNUM) store_fpregs_to_thread (regcache); - - /* Store MTE registers. */ - if (tdep->has_mte () - && (regno == tdep->mte_reg_base)) + /* MTE register? */ + else if (tdep->has_mte () + && (regno == tdep->mte_reg_base)) store_mteregs_to_thread (regcache); - - if (tdep->has_tls () - && regno >= tdep->tls_regnum_base - && regno < tdep->tls_regnum_base + tdep->tls_register_count) + /* TLS register? */ + else if (tdep->has_tls () + && regno >= tdep->tls_regnum_base + && regno < tdep->tls_regnum_base + tdep->tls_register_count) store_tlsregs_to_thread (regcache); + + /* PAuth registers are read-only. */ } /* A version of the "store_registers" target_ops method used when running From patchwork Mon Sep 18 21:26:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76314 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 3AC9A3854178 for ; Mon, 18 Sep 2023 21:28:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AC9A3854178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072484; bh=DYJ9HDmD5xpMZux8zle+8qw+dk/hXB0rCsN79ef3iL8=; 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=FhVu+qe8C7umR6u8AB4jDexQflTbkMKrzrXr1nfFZq2h0MYzGKobZz0PFNcRIqvfV q6izPWcxHZDE81Ve9GogACKP8aF6D0SAhvD/rRWrg8KMadfMef4jwDFvmDBbel4170 LWuvDjeiQUnGCXtLZycAihu47kAYHXhYN6JPd7wo= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2057.outbound.protection.outlook.com [40.107.104.57]) by sourceware.org (Postfix) with ESMTPS id 2F3F8385771C for ; Mon, 18 Sep 2023 21:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F3F8385771C Received: from AS8PR04CA0148.eurprd04.prod.outlook.com (2603:10a6:20b:127::33) by AS8PR08MB9043.eurprd08.prod.outlook.com (2603:10a6:20b:5c1::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30; Mon, 18 Sep 2023 21:27:14 +0000 Received: from AM7EUR03FT055.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:127:cafe::e3) by AS8PR04CA0148.outlook.office365.com (2603:10a6:20b:127::33) 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: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 AM7EUR03FT055.mail.protection.outlook.com (100.127.141.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:14 +0000 Received: ("Tessian outbound 169aaa6bf2b7:v175"); Mon, 18 Sep 2023 21:27:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d5397d932a3b904f X-CR-MTA-TID: 64aa7808 Received: from a30ef453b03a.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id BFA82439-02FC-4239-A086-167E0892C7CC.1; Mon, 18 Sep 2023 21:27:07 +0000 Received: from EUR02-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a30ef453b03a.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NOi0nIlq/8/paodMQ0OO3+9FfQubXap6VT++vSAb7rydwDSy2UJHCWeDMD12/UZFRX8xUikwQq/FStqy3RERwkby3N1QiJAFkQU/d5X9BYkYVsiLNXrT9GXx89RUvo10FjiLyvem3cbAX+irjyzwz2BfUlTUtEEpj8LZrNGRQ6qdcXJadhUQUg1iW1bw41v9wgXqzZZouFj5HIqlOuFSJWE3eigkfD2C6RGV1rKSXpG9sHHAkTbqENATFtPc3xvJhQOm8I9gRIO3Z4ri39iePNvWHzc95emQIxoboJI23XTZNvHnUfzUvvOFIvR7ytD5FOJjns33ZSgtB2pz33jFdA== 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=DYJ9HDmD5xpMZux8zle+8qw+dk/hXB0rCsN79ef3iL8=; b=EpG1w/nCvlwbRL8DOY/zUyS48WEO0Naqo0lZLOgYkwgHuVwM9BkjbO3lfOc6FKGu/fflw2pazHqm9HoFgb/zKC1QYZpDt5ZLy2aG5hamsUe8Je03ES8c1vqe7EBLklgbb76hPZ6mk5UedjBbBJJ/R22iOG0SrLMogU/ZZrRL1tS3fkOkxzN1xmLHUM0UsOI2RPolg2VsxRAHG96HV7IUiv0G5fMzfI9Zmnrd9Xc0Eu2//d/+x3kV2m7sJKSdCWN8igwdCvF2Zk1q52jPo1k0NXSpNjQiLDcrYtdP7+Itu/tM3bz3FdNav2PygFFFsEL2TstPlQ/mrUYT0BhFBp2iAw== 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 AS8PR07CA0029.eurprd07.prod.outlook.com (2603:10a6:20b:451::30) by DU0PR08MB7662.eurprd08.prod.outlook.com (2603:10a6:10:318::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 21:27:02 +0000 Received: from AM7EUR03FT058.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:451:cafe::80) by AS8PR07CA0029.outlook.office365.com (2603:10a6:20b:451::30) 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:02 +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 AM7EUR03FT058.mail.protection.outlook.com (100.127.140.247) 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:02 +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:01 +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:01 +0000 To: Subject: [PATCH v7 02/18] [gdb/aarch64] refactor: Rename SVE-specific files Date: Mon, 18 Sep 2023 22:26:35 +0100 Message-ID: <20230918212651.660141-3-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: AM7EUR03FT058:EE_|DU0PR08MB7662:EE_|AM7EUR03FT055:EE_|AS8PR08MB9043:EE_ X-MS-Office365-Filtering-Correlation-Id: 82c63add-2aa9-4479-26ca-08dbb88e070b 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: Gr9YCkRhSyNIo+I+waKLWPJQ7/OQjLn+/GU57UdbCKj8ECffoO7bLxmpEm3Em94XJlgLKgjN13rOeZR9ygTv2ciyx84knEnwPo5Xa+7nRnK3vt0BDjrngrFXJY2dJ/WgVhKOGWmK5Bk4Hfqqz94Xql9V9b8Cipt7Hb2f5qY1CENlaFVTzLVyx0itiLgLIIJwTQFV1vbxic3peDzNJ+YCrDSofZdvsJCTgWe0MhpZbvc9u2WmWnngP4K+8yWzsi4Euz+nweXplb9b0fIRlMj7AK95tsRs4+sl2PCCUWNL5u8eLgzZY/ZTx2XlmmfYSug+e97LxKgIwA7VgO14rn2xSPgumYdTifgFHFyNMkfIYJW/BLeI0pj1AnPf8zznsHjcsiOw73pYMY0Apt49GAeQZZfVFmASVBwTwlFFyWXR4xZYkNK6vpT+kmp0Qzemj/BK27dcesJ/eTKN80FJPOWonRpre+IPs8rNunGf2V/JKxGKjVncdlECzHcRhO2MuH5yuF1c20dSLu/6Eo1ruIwTgbmiJzGkH5+KinQG0GUxSQPZYczL6YzymKH9IzLCCrl+in+kP+qleJ6MIM3EInlgCyTDF3qH2QyQ6RmwsnGDbDZ1hJaGC1u8La1YKEYPFwOZ3iG6gfpf3h64uNssYO7Z1+KcXe8NQ8Scf6/TUugfI/nlTR2dyv1BnSWVxRTzAWUrQM3BLgePJy57EYA0YJmfA598lIAqyky9bOg/QASydQRWh/Ai7maE3TvP3Z4ls8sPUhGn+GTdtXAwbxsjK8xS4YHAILoYMu3sF8VYJunU5x8= 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)(39860400002)(346002)(376002)(136003)(396003)(451199024)(82310400011)(186009)(1800799009)(40470700004)(36840700001)(46966006)(40480700001)(44832011)(7696005)(86362001)(54906003)(316002)(41300700001)(70586007)(70206006)(5660300002)(6666004)(478600001)(6916009)(8936002)(2616005)(8676002)(356005)(81166007)(26005)(82740400003)(2906002)(36860700001)(36756003)(47076005)(426003)(336012)(1076003)(4326008)(40460700003)(83380400001)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB7662 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 9004cab6-7fa3-4701-3e2c-08dbb88dffd9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1435SAGMa8ZKLj7ZMcoxjZlYePCjkDub7hIT29jaWhl8y6t9+uMIN4duCDsMlmkNOCrsE2Rsr1fxjFMRvG+p1Ko6N2UN2JiL9pPX7s997mVlSG9sK0LwTSeCd4bE3R9GJ4Y1+n8vlFZEf1RMwJ7z8M7yVufYS0Ba0KEGbKM7dP5C/tjKolsyqITkQpI+yOSjaUCSbyFfdIYUOPz45bH7hmdUbgxfafcSrkfGTWYQgn9AHN//ogR8cpiLV+5ZrP0b/YhJhqLMJx/8iQO2RDM8JZKyHRK/Xvk1PxDc5Q++Lsrth8BBilexbXESLWjUP17ETlEKyP+CsT9C4KZ54ni49GL6U4q0eTh2dZgl+TXfYU+aYZllX5TuAKCSOnqo7wfAXD5Pwi20DUG/Yofg/yC+9o3E2RVnynU5PFObdeZ31kGGt3zPbtPTa/Lr/ZISiM6Tz4JKciW1i1bifHeUDkYRlfkEyxis1Aas6dbJX4M65K0Ii8QBJb8MIKNlQSkz//0gfxfp+kHDfcYMiujKpxGaxjtyvPibmYpSTDALJlaZsp4gZeexSIBfAnNpHIPxzgugY4Nek2kUMFVmReuO8BhpsCbshqqHVAmQWmY9EtTeYEDjF0J5hZgh73VAur/Gva977zgNCK6KWy2G1HPlESH56tPhaeSfH/4qKYVEE+d1ogjnsAmXvCu4lN6S0IUj2BA2ILTP4IzrFhyut5LOx9Y1W2dnFvsCoxHL/UwYUFVZM+RpanAOuqEx1+dD96iMF82V 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)(376002)(346002)(39860400002)(396003)(136003)(451199024)(82310400011)(186009)(1800799009)(36840700001)(40470700004)(46966006)(2906002)(40460700003)(83380400001)(107886003)(1076003)(36756003)(86362001)(7696005)(6666004)(2616005)(478600001)(336012)(426003)(26005)(40480700001)(36860700001)(8676002)(8936002)(4326008)(41300700001)(47076005)(5660300002)(44832011)(6916009)(82740400003)(70586007)(54906003)(316002)(70206006)(81166007)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:14.5314 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82c63add-2aa9-4479-26ca-08dbb88e070b 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: AM7EUR03FT055.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB9043 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, 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" In preparation to the SME support patches, rename the SVE-specific files to something a bit more meaningful that can be shared with the SME code. In this case, I've renamed the "sve" in the names to "scalable". No functional changes. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/Makefile.in | 2 +- gdb/aarch64-linux-nat.c | 2 +- gdb/configure.nat | 2 +- ...ptrace.c => aarch64-scalable-linux-ptrace.c} | 17 +++++++++-------- ...ptrace.h => aarch64-scalable-linux-ptrace.h} | 11 ++++++----- ...xt.h => aarch64-scalable-linux-sigcontext.h} | 11 +++++++---- gdbserver/Makefile.in | 2 +- gdbserver/configure.srv | 2 +- gdbserver/linux-aarch64-low.cc | 2 +- 9 files changed, 28 insertions(+), 23 deletions(-) rename gdb/nat/{aarch64-sve-linux-ptrace.c => aarch64-scalable-linux-ptrace.c} (96%) rename gdb/nat/{aarch64-sve-linux-ptrace.h => aarch64-scalable-linux-ptrace.h} (90%) rename gdb/nat/{aarch64-sve-linux-sigcontext.h => aarch64-scalable-linux-sigcontext.h} (96%) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 9b992a3d8c0..cdfbad4deed 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1561,7 +1561,7 @@ HFILES_NO_SRCDIR = \ nat/aarch64-linux.h \ nat/aarch64-linux-hw-point.h \ nat/aarch64-mte-linux-ptrace.h \ - nat/aarch64-sve-linux-ptrace.h \ + nat/aarch64-scalable-linux-ptrace.h \ nat/amd64-linux-siginfo.h \ nat/gdb_ptrace.h \ nat/gdb_thread_db.h \ diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 8844fc722cf..9f32279c0ac 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -35,7 +35,7 @@ #include "arch/arm.h" #include "nat/aarch64-linux.h" #include "nat/aarch64-linux-hw-point.h" -#include "nat/aarch64-sve-linux-ptrace.h" +#include "nat/aarch64-scalable-linux-ptrace.h" #include "elf/external.h" #include "elf/common.h" diff --git a/gdb/configure.nat b/gdb/configure.nat index 2739d14a1c4..1dc4206b69c 100644 --- a/gdb/configure.nat +++ b/gdb/configure.nat @@ -239,7 +239,7 @@ case ${gdb_host} in aarch32-linux-nat.o nat/aarch64-hw-point.o \ nat/aarch64-linux-hw-point.o \ nat/aarch64-linux.o \ - nat/aarch64-sve-linux-ptrace.o \ + nat/aarch64-scalable-linux-ptrace.o \ nat/aarch64-mte-linux-ptrace.o" ;; arc) diff --git a/gdb/nat/aarch64-sve-linux-ptrace.c b/gdb/nat/aarch64-scalable-linux-ptrace.c similarity index 96% rename from gdb/nat/aarch64-sve-linux-ptrace.c rename to gdb/nat/aarch64-scalable-linux-ptrace.c index 51146535672..cc43f510892 100644 --- a/gdb/nat/aarch64-sve-linux-ptrace.c +++ b/gdb/nat/aarch64-scalable-linux-ptrace.c @@ -1,4 +1,5 @@ -/* Common target dependent for AArch64 systems. +/* Common target dependent routines for AArch64 Scalable Extensions + (SVE/SME). Copyright (C) 2018-2023 Free Software Foundation, Inc. @@ -22,13 +23,13 @@ #include "gdbsupport/common-defs.h" #include "elf/external.h" #include "elf/common.h" -#include "aarch64-sve-linux-ptrace.h" +#include "aarch64-scalable-linux-ptrace.h" #include "arch/aarch64.h" #include "gdbsupport/common-regcache.h" #include "gdbsupport/byte-vector.h" #include -/* See nat/aarch64-sve-linux-ptrace.h. */ +/* See nat/aarch64-scalable-linux-ptrace.h. */ uint64_t aarch64_sve_get_vq (int tid) @@ -60,7 +61,7 @@ aarch64_sve_get_vq (int tid) return vq; } -/* See nat/aarch64-sve-linux-ptrace.h. */ +/* See nat/aarch64-scalable-linux-ptrace.h. */ bool aarch64_sve_set_vq (int tid, uint64_t vq) @@ -88,7 +89,7 @@ aarch64_sve_set_vq (int tid, uint64_t vq) return true; } -/* See nat/aarch64-sve-linux-ptrace.h. */ +/* See nat/aarch64-scalable-linux-ptrace.h. */ bool aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf) @@ -117,7 +118,7 @@ aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf) return aarch64_sve_set_vq (tid, sve_vq_from_vg (reg_vg)); } -/* See nat/aarch64-sve-linux-ptrace.h. */ +/* See nat/aarch64-scalable-linux-ptrace.h. */ std::unique_ptr aarch64_sve_get_sveregs (int tid) @@ -161,7 +162,7 @@ aarch64_maybe_swab128 (gdb_byte *dst, const gdb_byte *src, size_t size) #endif } -/* See nat/aarch64-sve-linux-ptrace.h. */ +/* See nat/aarch64-scalable-linux-ptrace.h. */ void aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, @@ -250,7 +251,7 @@ aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, } } -/* See nat/aarch64-sve-linux-ptrace.h. */ +/* See nat/aarch64-scalable-linux-ptrace.h. */ void aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, diff --git a/gdb/nat/aarch64-sve-linux-ptrace.h b/gdb/nat/aarch64-scalable-linux-ptrace.h similarity index 90% rename from gdb/nat/aarch64-sve-linux-ptrace.h rename to gdb/nat/aarch64-scalable-linux-ptrace.h index 9539e199d34..2847c4e0263 100644 --- a/gdb/nat/aarch64-sve-linux-ptrace.h +++ b/gdb/nat/aarch64-scalable-linux-ptrace.h @@ -1,4 +1,5 @@ -/* Common target dependent for AArch64 systems. +/* Common target dependent definitions for AArch64 Scalable Extensions + (SVE/SME). Copyright (C) 2018-2023 Free Software Foundation, Inc. @@ -17,8 +18,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef NAT_AARCH64_SVE_LINUX_PTRACE_H -#define NAT_AARCH64_SVE_LINUX_PTRACE_H +#ifndef NAT_AARCH64_SCALABLE_LINUX_PTRACE_H +#define NAT_AARCH64_SCALABLE_LINUX_PTRACE_H #include #include @@ -32,7 +33,7 @@ #include #ifndef SVE_SIG_ZREGS_SIZE -#include "aarch64-sve-linux-sigcontext.h" +#include "aarch64-scalable-linux-sigcontext.h" #endif /* Indicates whether a SVE ptrace header is followed by SVE registers or a @@ -69,4 +70,4 @@ extern void aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, void *buf); -#endif /* NAT_AARCH64_SVE_LINUX_PTRACE_H */ +#endif /* NAT_AARCH64_SCALABLE_LINUX_PTRACE_H */ diff --git a/gdb/nat/aarch64-sve-linux-sigcontext.h b/gdb/nat/aarch64-scalable-linux-sigcontext.h similarity index 96% rename from gdb/nat/aarch64-sve-linux-sigcontext.h rename to gdb/nat/aarch64-scalable-linux-sigcontext.h index aba3c1595d0..e0120e093a0 100644 --- a/gdb/nat/aarch64-sve-linux-sigcontext.h +++ b/gdb/nat/aarch64-scalable-linux-sigcontext.h @@ -1,4 +1,7 @@ -/* Copyright (C) 2018-2023 Free Software Foundation, Inc. +/* Linux Kernel sigcontext definitions for AArch64 Scalable Extensions + (SVE/SME). + + Copyright (C) 2018-2023 Free Software Foundation, Inc. Contributed by Arm Ltd. This file is part of GDB. @@ -16,8 +19,8 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef NAT_AARCH64_SVE_LINUX_SIGCONTEXT_H -#define NAT_AARCH64_SVE_LINUX_SIGCONTEXT_H +#ifndef NAT_AARCH64_SCALABLE_LINUX_SIGCONTEXT_H +#define NAT_AARCH64_SCALABLE_LINUX_SIGCONTEXT_H #define SVE_MAGIC 0x53564501 @@ -264,4 +267,4 @@ struct user_sve_header { SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags) \ : SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags)) -#endif /* NAT_AARCH64_SVE_LINUX_SIGCONTEXT_H */ +#endif /* NAT_AARCH64_SCALABLE_LINUX_SIGCONTEXT_H */ diff --git a/gdbserver/Makefile.in b/gdbserver/Makefile.in index 39cb9e7a151..b597515d428 100644 --- a/gdbserver/Makefile.in +++ b/gdbserver/Makefile.in @@ -218,7 +218,7 @@ SFILES = \ $(srcdir)/../gdb/arch/ppc-linux-common.c \ $(srcdir)/../gdb/arch/riscv.c \ $(srcdir)/../gdb/nat/aarch64-mte-linux-ptrace.c \ - $(srcdir)/../gdb/nat/aarch64-sve-linux-ptrace.c \ + $(srcdir)/../gdb/nat/aarch64-scalable-linux-ptrace.c \ $(srcdir)/../gdb/nat/linux-btrace.c \ $(srcdir)/../gdb/nat/linux-namespaces.c \ $(srcdir)/../gdb/nat/linux-osdata.c \ diff --git a/gdbserver/configure.srv b/gdbserver/configure.srv index 72256f82871..7a7575ac43b 100644 --- a/gdbserver/configure.srv +++ b/gdbserver/configure.srv @@ -51,7 +51,7 @@ case "${gdbserver_host}" in srv_tgtobj="$srv_tgtobj arch/aarch64-mte-linux.o" srv_tgtobj="$srv_tgtobj linux-aarch64-tdesc.o" srv_tgtobj="$srv_tgtobj nat/aarch64-mte-linux-ptrace.o" - srv_tgtobj="$srv_tgtobj nat/aarch64-sve-linux-ptrace.o" + srv_tgtobj="$srv_tgtobj nat/aarch64-scalable-linux-ptrace.o" srv_tgtobj="${srv_tgtobj} $srv_linux_obj" srv_linux_regsets=yes srv_linux_thread_db=yes diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 2474a000ea3..8b22f1979d6 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -44,7 +44,7 @@ #include "linux-aarch32-tdesc.h" #include "linux-aarch64-tdesc.h" #include "nat/aarch64-mte-linux-ptrace.h" -#include "nat/aarch64-sve-linux-ptrace.h" +#include "nat/aarch64-scalable-linux-ptrace.h" #include "tdesc.h" #ifdef HAVE_SYS_REG_H From patchwork Mon Sep 18 21:26:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76315 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 2B6F3385483C for ; Mon, 18 Sep 2023 21:28:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2B6F3385483C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072502; bh=Zv/1bQNFmNvFvuk1goC+B4yMsdSXDChvqldo0mK6biw=; 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=gnDt3EJoZDbM6S9c9TvK9wU/JTbCMu72a3jTOplJZjqL+AGYf6YPmg9cccOdQwL1d yhou+RDC4m3vyenUhrjruZk2OLlgZ/Vql6BJrCm0C0KhJ9zw8Ukw8FoOWQwr2alnLi XD4yj2cshe7PP0gZ9ddpC+h+g8jxwg5tDF296TM0= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2072.outbound.protection.outlook.com [40.107.21.72]) by sourceware.org (Postfix) with ESMTPS id 92A613858425 for ; Mon, 18 Sep 2023 21:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92A613858425 Received: from DUZPR01CA0185.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b3::11) by GV2PR08MB8629.eurprd08.prod.outlook.com (2603:10a6:150:b9::20) 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:11 +0000 Received: from DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:4b3:cafe::6f) by DUZPR01CA0185.outlook.office365.com (2603:10a6:10:4b3::11) 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:11 +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 DBAEUR03FT025.mail.protection.outlook.com (100.127.142.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:11 +0000 Received: ("Tessian outbound 169aaa6bf2b7:v175"); Mon, 18 Sep 2023 21:27:11 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 56fceb44fd0ae065 X-CR-MTA-TID: 64aa7808 Received: from a131454d909c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 00C00690-067E-44E2-A8D1-099CDE13C822.1; Mon, 18 Sep 2023 21:27:04 +0000 Received: from EUR02-DB5-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a131454d909c.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EfjxdpPAi2p6ZvhFCAynj0WBCmWNXUJB8nVA9tFAvLQL2KVqsKSYC6QpyR4OqZSUWAHwkv0fvxOMW+kNWVCfhZpDQwUzKjnjhg68iA9YwgeCqlJ14CxhfQBdUT7nC2LhdtuOxdvavyjutNvVpzsKo1/stTjO3NU7EMUtOAWc8twIDXwqL7F0wa8Q2IWIl7Sc6GstnmC7RUY4N0w/8vhJ3PnKTuGS80FU/OYw256xi7TiVw+K0y3Ap4f6d0mzC957Bv6Tkpa7pHeNMH8IXqM9lhnE5tlyuT5hTheIqrZ3cAY4ZCkmwcMTTRITS63tMxt0hUnaRQcysmtDC1GLv4uzvA== 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=Zv/1bQNFmNvFvuk1goC+B4yMsdSXDChvqldo0mK6biw=; b=F5MfhC1UJQgTIFLV9+e56u8fl1qAgAf35XWvUkwVm8k43h4WM+Fz8yik+TW+ZzRT8tQzndON11n5+EGBxnRIQQ4kITDMUkRnk3r+WKaoaB8VhC1uA0x72BkQQAOJh3M5hDM3H98qshXb5Nf2KfvGYgBDCR4Dyupv1YeJWCWM4obAAyuQPAE82pavyzxANwVva3+6yrwvtnDlcwob4dAkT5Kzn3zfYGF8iNIcORVTx1B+PGajpuFoLss42RNBH0gTpQcLvb16zv25wHMpJm4JLBZAcMPFPCZ/86HSlQ0q/6Tn12nv7MAVmo00DioVWLacbVVb2OT0lSzGEIhMMlKWtw== 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 AS8PR07CA0017.eurprd07.prod.outlook.com (2603:10a6:20b:451::26) by PAWPR08MB9966.eurprd08.prod.outlook.com (2603:10a6:102:35e::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:03 +0000 Received: from AM7EUR03FT058.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:451:cafe::ae) by AS8PR07CA0017.outlook.office365.com (2603:10a6:20b:451::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:02 +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 AM7EUR03FT058.mail.protection.outlook.com (100.127.140.247) 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:02 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:02 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:02 +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:01 +0000 To: Subject: [PATCH v7 03/18] [gdb/gdbserver] refactor: Simplify SVE interface to read/write registers Date: Mon, 18 Sep 2023 22:26:36 +0100 Message-ID: <20230918212651.660141-4-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: AM7EUR03FT058:EE_|PAWPR08MB9966:EE_|DBAEUR03FT025:EE_|GV2PR08MB8629:EE_ X-MS-Office365-Filtering-Correlation-Id: df74144b-ad81-4785-8968-08dbb88e0527 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: W8xuevqOXKl9TW3KXbTN/vdVpRQeJd340d/rLsLHlQAa5snIQJHTMENCcEYo1fHJfnvCqgftuzTc0rux9jKWqBPJdFgTvMQxtgWIYA0S8zZotD2hRo7q5kZx1BwH7HuxlkWMPTjcO6Cc+2Mr8rCp9y0sNPGSfco16xqoyjHhkImV7KhiLzMzG56V7rf3BREip9lttPPZUjOqCGH/D9IASAVAr6KSZN+c3dlj6+HmFER6gyFzV0HtZJpMvootUDusB6IRlU6VYMcwooEEb1SoJ3LpBnAmwF5MHcgC173U893rISXhN4jJnO3Sv1aBYeP63EIKWub75qQ+HxJlblK/8BQw7SEdVPr4zqY6LrtkDZWJPrT7RRAtAcnF1SzO9T3cjEo0/tPw8kPF2FMUhZE9fQPJA0fuVtn7VyoHYSenA+D2JeqnGp2mWkqQLAAdM92FSJpQd0blFp4xnp4fm8iK7uS5madaIgixa2C0m0rIU1RsijOPbrDQAqomUEiSGCtKA6mnkVePULIs7yoOBMb2gBofhCVrRuNrXuq4UB3Nopy6oPMXCeS/G2nOMTW4EVTwfweVTKV4I7omXcPqlT+kQbIsr9kfA6S4JFQJgOqz1CkOHvBuYu4N/OMx5W28Cw1/QgJFatVU6zlGyq8AKPGA42KrOgmaxK/Oed+rYykufBeh5r2B2ZfxDVDUMu33504iVTI8L1YrwkoeeHYD7nVKmJEZEHY2T9mNvFVBIh4TgWi+So3RbZTbN5zgUWZzM4i0YQ0Mrxs9UH7WC0yAnnn6uA== 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)(346002)(376002)(136003)(39860400002)(396003)(1800799009)(82310400011)(186009)(451199024)(36840700001)(46966006)(40470700004)(356005)(81166007)(26005)(82740400003)(2616005)(8936002)(8676002)(1076003)(4326008)(40460700003)(83380400001)(36860700001)(2906002)(36756003)(30864003)(47076005)(426003)(336012)(40480700001)(5660300002)(44832011)(86362001)(7696005)(6666004)(478600001)(6916009)(316002)(54906003)(70206006)(70586007)(41300700001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB9966 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 017d58bc-4378-4737-5f9e-08dbb88e001e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NnjR0/lkAP/I2uzmNdbfbuitnvdqJqLey0fWMQSSPP50Rj0SuXmIDd6OUAGG1+FQeXso/+z+D8Os8BGLIHzSfx/GH7nuWYtHZZ0YGM7WTjvSitLudK9tpwmc66Ue0WhfGfos9GuIHA5TSpa4xxTxnTC/gt+hhGYYQHIi9repNTCiR4MZqwsavEhumgiWhk5tbdn2d/1WzHRzJNSKZY5dT6YWA3Bt/FcmNqDDcblgLdjP8W70KzcJtvOKO9yUb7bm4ebW3Y5vos+56ROXSVUAVosy6QQHneR/VRyVoYm4inmiit08Nr5nEnmezR4sFCv8JRnNyRlHlkkfGksWVMiSuQxe57+NuOCzVg7VCFntf+CBtJ/JWHmXlX5vg2NfV4mteoP7wfUj5z9th3kA1ef/FfdJNkOIY+nbcIsdHU7eVehuSJYUc/B6RFGgXPK26n9+qp/RNt3rjHw2LoBSOZgqQ56+ksloW6NEg5Ea0YSIy8PVeBMLFSki6iWWNkkZK2VC/YzIAky/1gZelAOGonaFNoxetG3rr+iJB9tNLKjigKmXtZTIPiyB2Oxzly7j0nKYwq9+GJQpuC69ijkbcwxlyKle+UvFL9eXHIPEr5+ZFJVZ30ue+smyEoKB/cI84JsmBYa0694tn0Jj5tO/+uaIw20F9BDLDzd+E5StgfCMQMvgK4bNro9IPG73m/KVdMh6nYo4oMeu4fVlaV6qdSJE5ET6NRgdEBztvxzt0sgDTgxOlKVPe2zDrq5iVUv0A0Ee 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)(396003)(346002)(376002)(136003)(39860400002)(451199024)(186009)(1800799009)(82310400011)(36840700001)(40470700004)(46966006)(41300700001)(4326008)(6916009)(54906003)(316002)(70206006)(70586007)(8676002)(8936002)(44832011)(478600001)(30864003)(6666004)(2616005)(2906002)(107886003)(26005)(426003)(336012)(83380400001)(1076003)(5660300002)(86362001)(47076005)(36860700001)(82740400003)(81166007)(40480700001)(36756003)(40460700003)(7696005); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:11.4401 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: df74144b-ad81-4785-8968-08dbb88e0527 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: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8629 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" Updates on v4: - Removed unused return value. - Fixed buffer overrun in a for loop. --- This is a patch in preparation to upcoming patches enabling SME support. It attempts to simplify the gdb/gdbserver shared interface used to read/write SVE registers. Where the current code makes use of unique_ptr, allocating a new buffer by hand and passing a buffer around, this patch makes that code use gdb::byte_vector and passes a reference to this byte vector to the functions, allowing the functions to have ready access to the size of the buffer. It also shares a bit more code between gdb and gdbserver, in particular around handling of ptrace get/set requests for SVE. I think gdbserver could be refactored to handle register reads/writes more like gdb's native layer as opposed to letting the generic linux-low layer do the ptrace calls. This is not very flexible and assumes one size for the responses. If you have something like NT_ARM_SVE, where you can have either FPSIMD or SVE contents, it doesn't work that well. I didn't want to change that interface right now as it is a bit too much work and touches all the targets, some of which I can't easily test. Hence the reason why the buffer the generic linux-now passes down to linux-aarch64-low is unused or ignored. No user-visible changes should happen as part of this refactor other than a slightly reworded warning message. While doing the refactor, I also noticed what seems to be a mistake in checking if the register cache contains active (non-zero) SVE data. For instance, the original code did something like this in aarch64_sve_regs_copy_from_reg_buf: has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_Z0_REGNUM + i reg, sizeof (__int128_t)); "reg" is a zeroed-out buffer that we compare the Z register contents past the first 128 bits. The problem here is that raw_compare returns 1 if the contents compare the same, which means has_sve_state will be true. But if we compared the Z register contents to 0, it means we *do not* have SVE state, and therefore has_sve_state should be false. The consequence of this mistake is that we convert the initial FPSIMD-formatted data we get from ptrace for the NT_ARM_SVE register set to a SVE-formatted one. In the end, this doesn't cause user-visible differences because the values of both the Z and V registers will still be the same. But the logic is not correct. I used the opportunity to fix this, and it gets tested later on by the additional SME tests. I do plan on submitting some SVE-specific tests to make sure we have a bit more coverage in GDB's testsuite. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-nat.c | 30 +--- gdb/nat/aarch64-scalable-linux-ptrace.c | 202 +++++++++++++++--------- gdb/nat/aarch64-scalable-linux-ptrace.h | 27 ++-- gdbserver/linux-aarch64-low.cc | 24 ++- 4 files changed, 173 insertions(+), 110 deletions(-) diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 9f32279c0ac..267a1ca0e79 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -319,9 +319,8 @@ store_fpregs_to_thread (const struct regcache *regcache) static void fetch_sveregs_from_thread (struct regcache *regcache) { - std::unique_ptr base - = aarch64_sve_get_sveregs (regcache->ptid ().lwp ()); - aarch64_sve_regs_copy_to_reg_buf (regcache, base.get ()); + /* Fetch SVE state from the thread and copy it into the register cache. */ + aarch64_sve_regs_copy_to_reg_buf (regcache->ptid ().lwp (), regcache); } /* Store to the current thread the valid sve register @@ -330,28 +329,9 @@ fetch_sveregs_from_thread (struct regcache *regcache) static void store_sveregs_to_thread (struct regcache *regcache) { - int ret; - struct iovec iovec; - int tid = regcache->ptid ().lwp (); - - /* First store vector length to the thread. This is done first to ensure the - ptrace buffers read from the kernel are the correct size. */ - if (!aarch64_sve_set_vq (tid, regcache)) - perror_with_name (_("Unable to set VG register")); - - /* Obtain a dump of SVE registers from ptrace. */ - std::unique_ptr base = aarch64_sve_get_sveregs (tid); - - /* Overwrite with regcache state. */ - aarch64_sve_regs_copy_from_reg_buf (regcache, base.get ()); - - /* Write back to the kernel. */ - iovec.iov_base = base.get (); - iovec.iov_len = ((struct user_sve_header *) base.get ())->size; - ret = ptrace (PTRACE_SETREGSET, tid, NT_ARM_SVE, &iovec); - - if (ret < 0) - perror_with_name (_("Unable to store sve registers")); + /* Fetch SVE state from the register cache and update the thread TID with + it. */ + aarch64_sve_regs_copy_from_reg_buf (regcache->ptid ().lwp (), regcache); } /* Fill GDB's register array with the pointer authentication mask values from diff --git a/gdb/nat/aarch64-scalable-linux-ptrace.c b/gdb/nat/aarch64-scalable-linux-ptrace.c index cc43f510892..6eea9104cef 100644 --- a/gdb/nat/aarch64-scalable-linux-ptrace.c +++ b/gdb/nat/aarch64-scalable-linux-ptrace.c @@ -120,28 +120,43 @@ aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf) /* See nat/aarch64-scalable-linux-ptrace.h. */ -std::unique_ptr -aarch64_sve_get_sveregs (int tid) +gdb::byte_vector +aarch64_fetch_sve_regset (int tid) { - struct iovec iovec; uint64_t vq = aarch64_sve_get_vq (tid); if (vq == 0) - perror_with_name (_("Unable to fetch SVE register header")); + perror_with_name (_("Unable to fetch SVE vector length")); /* A ptrace call with NT_ARM_SVE will return a header followed by either a dump of all the SVE and FP registers, or an fpsimd structure (identical to the one returned by NT_FPREGSET) if the kernel has not yet executed any SVE code. Make sure we allocate enough space for a full SVE dump. */ - iovec.iov_len = SVE_PT_SIZE (vq, SVE_PT_REGS_SVE); - std::unique_ptr buf (new gdb_byte[iovec.iov_len]); - iovec.iov_base = buf.get (); + gdb::byte_vector sve_state (SVE_PT_SIZE (vq, SVE_PT_REGS_SVE), 0); + + struct iovec iovec; + iovec.iov_base = sve_state.data (); + iovec.iov_len = sve_state.size (); if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0) perror_with_name (_("Unable to fetch SVE registers")); - return buf; + return sve_state; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +void +aarch64_store_sve_regset (int tid, const gdb::byte_vector &sve_state) +{ + struct iovec iovec; + /* We need to cast from (const void *) here. */ + iovec.iov_base = (void *) sve_state.data (); + iovec.iov_len = sve_state.size (); + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_SVE, &iovec) < 0) + perror_with_name (_("Unable to store SVE registers")); } /* If we are running in BE mode, byteswap the contents @@ -165,11 +180,13 @@ aarch64_maybe_swab128 (gdb_byte *dst, const gdb_byte *src, size_t size) /* See nat/aarch64-scalable-linux-ptrace.h. */ void -aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, - const void *buf) +aarch64_sve_regs_copy_to_reg_buf (int tid, struct reg_buffer_common *reg_buf) { - char *base = (char *) buf; - struct user_sve_header *header = (struct user_sve_header *) buf; + gdb::byte_vector sve_state = aarch64_fetch_sve_regset (tid); + + char *base = (char *) sve_state.data (); + struct user_sve_header *header + = (struct user_sve_header *) sve_state.data (); uint64_t vq = sve_vq_from_vl (header->vl); uint64_t vg = sve_vg_from_vl (header->vl); @@ -249,18 +266,33 @@ aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, reg_buf->raw_supply (AARCH64_SVE_FFR_REGNUM, reg); } + + /* At this point we have updated the register cache with the contents of + the NT_ARM_SVE register set. */ } /* See nat/aarch64-scalable-linux-ptrace.h. */ void -aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, - void *buf) +aarch64_sve_regs_copy_from_reg_buf (int tid, + struct reg_buffer_common *reg_buf) { - struct user_sve_header *header = (struct user_sve_header *) buf; - char *base = (char *) buf; + /* First store the vector length to the thread. This is done first to + ensure the ptrace buffers read from the kernel are the correct size. */ + if (!aarch64_sve_set_vq (tid, reg_buf)) + perror_with_name (_("Unable to set VG register")); + + /* Obtain a dump of SVE registers from ptrace. */ + gdb::byte_vector sve_state = aarch64_fetch_sve_regset (tid); + + struct user_sve_header *header = (struct user_sve_header *) sve_state.data (); uint64_t vq = sve_vq_from_vl (header->vl); + gdb::byte_vector new_state (SVE_PT_SIZE (32, SVE_PT_REGS_SVE), 0); + memcpy (new_state.data (), sve_state.data (), sve_state.size ()); + header = (struct user_sve_header *) new_state.data (); + char *base = (char *) new_state.data (); + /* Sanity check the data in the header. */ if (!sve_vl_valid (header->vl) || SVE_PT_SIZE (vq, header->flags) != header->size) @@ -275,36 +307,40 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, resulting in the initialization of SVE state written back to the kernel, which is why we try to avoid it. */ - bool has_sve_state = false; - gdb_byte *reg = (gdb_byte *) alloca (SVE_PT_SVE_ZREG_SIZE (vq)); - struct user_fpsimd_state *fpsimd - = (struct user_fpsimd_state *)(base + SVE_PT_FPSIMD_OFFSET); - - memset (reg, 0, SVE_PT_SVE_ZREG_SIZE (vq)); + /* Buffer (using the maximum size a Z register) used to look for zeroed + out sve state. */ + gdb_byte reg[256]; + memset (reg, 0, sizeof (reg)); /* Check in the reg_buf if any of the Z registers are set after the first 128 bits, or if any of the other SVE registers are set. */ - + bool has_sve_state = false; for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++) { - has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_Z0_REGNUM + i, - reg, sizeof (__int128_t)); - if (has_sve_state) - break; + if (!reg_buf->raw_compare (AARCH64_SVE_Z0_REGNUM + i, reg, + V_REGISTER_SIZE)) + { + has_sve_state = true; + break; + } } if (!has_sve_state) for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++) { - has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_P0_REGNUM + i, - reg, 0); - if (has_sve_state) - break; + if (!reg_buf->raw_compare (AARCH64_SVE_P0_REGNUM + i, reg, 0)) + { + has_sve_state = true; + break; + } } if (!has_sve_state) - has_sve_state |= reg_buf->raw_compare (AARCH64_SVE_FFR_REGNUM, - reg, 0); + has_sve_state + = !reg_buf->raw_compare (AARCH64_SVE_FFR_REGNUM, reg, 0); + + struct user_fpsimd_state *fpsimd + = (struct user_fpsimd_state *)(base + SVE_PT_FPSIMD_OFFSET); /* If no SVE state exists, then use the existing fpsimd structure to write out state and return. */ @@ -344,50 +380,74 @@ aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, if (REG_VALID == reg_buf->get_register_status (AARCH64_FPCR_REGNUM)) reg_buf->raw_collect (AARCH64_FPCR_REGNUM, &fpsimd->fpcr); - return; - } - - /* Otherwise, reformat the fpsimd structure into a full SVE set, by - expanding the V registers (working backwards so we don't splat - registers before they are copied) and using null for everything else. - Note that enough space for a full SVE dump was originally allocated - for base. */ + /* At this point we have collected all the data from the register + cache and we are ready to update the FPSIMD register content + of the thread. */ - header->flags |= SVE_PT_REGS_SVE; - header->size = SVE_PT_SIZE (vq, SVE_PT_REGS_SVE); + /* Fall through so we can update the thread's contents with the + FPSIMD register cache values. */ + } + else + { + /* Otherwise, reformat the fpsimd structure into a full SVE set, by + expanding the V registers (working backwards so we don't splat + registers before they are copied) and using zero for everything + else. + Note that enough space for a full SVE dump was originally allocated + for base. */ + + header->flags |= SVE_PT_REGS_SVE; + header->size = SVE_PT_SIZE (vq, SVE_PT_REGS_SVE); + + memcpy (base + SVE_PT_SVE_FPSR_OFFSET (vq), &fpsimd->fpsr, + sizeof (uint32_t)); + memcpy (base + SVE_PT_SVE_FPCR_OFFSET (vq), &fpsimd->fpcr, + sizeof (uint32_t)); + + for (int i = AARCH64_SVE_Z_REGS_NUM - 1; i >= 0 ; i--) + { + memcpy (base + SVE_PT_SVE_ZREG_OFFSET (vq, i), &fpsimd->vregs[i], + sizeof (__int128_t)); + } - memcpy (base + SVE_PT_SVE_FPSR_OFFSET (vq), &fpsimd->fpsr, - sizeof (uint32_t)); - memcpy (base + SVE_PT_SVE_FPCR_OFFSET (vq), &fpsimd->fpcr, - sizeof (uint32_t)); + /* At this point we have converted the FPSIMD layout to an SVE + layout and copied the register data. - for (int i = AARCH64_SVE_Z_REGS_NUM; i >= 0 ; i--) - { - memcpy (base + SVE_PT_SVE_ZREG_OFFSET (vq, i), &fpsimd->vregs[i], - sizeof (__int128_t)); + Fall through so we can update the thread's contents with the SVE + register cache values. */ } } + else + { + /* We already have SVE state for this thread, so we just need to update + the values of the registers. */ + for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++) + if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_Z0_REGNUM + + i)) + reg_buf->raw_collect (AARCH64_SVE_Z0_REGNUM + i, + base + SVE_PT_SVE_ZREG_OFFSET (vq, i)); - /* Replace the kernel values with those from reg_buf. */ - - for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++) - if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_Z0_REGNUM + i)) - reg_buf->raw_collect (AARCH64_SVE_Z0_REGNUM + i, - base + SVE_PT_SVE_ZREG_OFFSET (vq, i)); - - for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++) - if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_P0_REGNUM + i)) - reg_buf->raw_collect (AARCH64_SVE_P0_REGNUM + i, - base + SVE_PT_SVE_PREG_OFFSET (vq, i)); + for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++) + if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_P0_REGNUM + + i)) + reg_buf->raw_collect (AARCH64_SVE_P0_REGNUM + i, + base + SVE_PT_SVE_PREG_OFFSET (vq, i)); + + if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_FFR_REGNUM)) + reg_buf->raw_collect (AARCH64_SVE_FFR_REGNUM, + base + SVE_PT_SVE_FFR_OFFSET (vq)); + if (REG_VALID == reg_buf->get_register_status (AARCH64_FPSR_REGNUM)) + reg_buf->raw_collect (AARCH64_FPSR_REGNUM, + base + SVE_PT_SVE_FPSR_OFFSET (vq)); + if (REG_VALID == reg_buf->get_register_status (AARCH64_FPCR_REGNUM)) + reg_buf->raw_collect (AARCH64_FPCR_REGNUM, + base + SVE_PT_SVE_FPCR_OFFSET (vq)); + } - if (REG_VALID == reg_buf->get_register_status (AARCH64_SVE_FFR_REGNUM)) - reg_buf->raw_collect (AARCH64_SVE_FFR_REGNUM, - base + SVE_PT_SVE_FFR_OFFSET (vq)); - if (REG_VALID == reg_buf->get_register_status (AARCH64_FPSR_REGNUM)) - reg_buf->raw_collect (AARCH64_FPSR_REGNUM, - base + SVE_PT_SVE_FPSR_OFFSET (vq)); - if (REG_VALID == reg_buf->get_register_status (AARCH64_FPCR_REGNUM)) - reg_buf->raw_collect (AARCH64_FPCR_REGNUM, - base + SVE_PT_SVE_FPCR_OFFSET (vq)); + /* At this point we have collected all the data from the register cache and + we are ready to update the SVE/FPSIMD register contents of the thread. + sve_state should contain all the data in the correct format, ready to be + passed on to ptrace. */ + aarch64_store_sve_regset (tid, new_state); } diff --git a/gdb/nat/aarch64-scalable-linux-ptrace.h b/gdb/nat/aarch64-scalable-linux-ptrace.h index 2847c4e0263..167782c493d 100644 --- a/gdb/nat/aarch64-scalable-linux-ptrace.h +++ b/gdb/nat/aarch64-scalable-linux-ptrace.h @@ -52,22 +52,27 @@ uint64_t aarch64_sve_get_vq (int tid); bool aarch64_sve_set_vq (int tid, uint64_t vq); bool aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf); -/* Read the current SVE register set using ptrace, allocating space as - required. */ +/* Read the current SVE register set from thread TID and return its data + through a byte vector. */ -extern std::unique_ptr aarch64_sve_get_sveregs (int tid); +extern gdb::byte_vector aarch64_fetch_sve_regset (int tid); -/* Put the registers from linux structure buf into register buffer. Assumes the - vector lengths in the register buffer match the size in the kernel. */ +/* Write the SVE contents from SVE_STATE to thread TID. */ -extern void aarch64_sve_regs_copy_to_reg_buf (struct reg_buffer_common *reg_buf, - const void *buf); +extern void +aarch64_store_sve_regset (int tid, const gdb::byte_vector &sve_state); + +/* Given a thread id TID and a register buffer REG_BUF, update the register + buffer with the SVE state from thread TID. */ + +extern void +aarch64_sve_regs_copy_to_reg_buf (int tid, struct reg_buffer_common *reg_buf); -/* Put the registers from register buffer into linux structure buf. Assumes the - vector lengths in the register buffer match the size in the kernel. */ +/* Given a thread id TID and a register buffer REG_BUF containing SVE + register data, write the SVE data to thread TID. */ extern void -aarch64_sve_regs_copy_from_reg_buf (const struct reg_buffer_common *reg_buf, - void *buf); +aarch64_sve_regs_copy_from_reg_buf (int tid, + struct reg_buffer_common *reg_buf); #endif /* NAT_AARCH64_SCALABLE_LINUX_PTRACE_H */ diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 8b22f1979d6..7c633c212f3 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -719,9 +719,18 @@ aarch64_target::low_new_fork (process_info *parent, /* Wrapper for aarch64_sve_regs_copy_to_reg_buf. */ static void -aarch64_sve_regs_copy_to_regcache (struct regcache *regcache, const void *buf) +aarch64_sve_regs_copy_to_regcache (struct regcache *regcache, + ATTRIBUTE_UNUSED const void *buf) { - return aarch64_sve_regs_copy_to_reg_buf (regcache, buf); + /* BUF is unused here since we collect the data straight from a ptrace + request in aarch64_sve_regs_copy_to_reg_buf, therefore bypassing + gdbserver's own call to ptrace. */ + + int tid = lwpid_of (current_thread); + + /* Update the register cache. aarch64_sve_regs_copy_to_reg_buf handles + fetching the NT_ARM_SVE state from thread TID. */ + aarch64_sve_regs_copy_to_reg_buf (tid, regcache); } /* Wrapper for aarch64_sve_regs_copy_from_reg_buf. */ @@ -729,7 +738,16 @@ aarch64_sve_regs_copy_to_regcache (struct regcache *regcache, const void *buf) static void aarch64_sve_regs_copy_from_regcache (struct regcache *regcache, void *buf) { - return aarch64_sve_regs_copy_from_reg_buf (regcache, buf); + int tid = lwpid_of (current_thread); + + /* Update the thread SVE state. aarch64_sve_regs_copy_from_reg_buf + handles writing the SVE/FPSIMD state back to thread TID. */ + aarch64_sve_regs_copy_from_reg_buf (tid, regcache); + + /* We need to return the expected data in BUF, so copy whatever the kernel + already has to BUF. */ + gdb::byte_vector sve_state = aarch64_fetch_sve_regset (tid); + memcpy (buf, sve_state.data (), sve_state.size ()); } /* Array containing all the possible register sets for AArch64/Linux. During From patchwork Mon Sep 18 21:26:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76317 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 19C2E385C6F9 for ; Mon, 18 Sep 2023 21:28:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19C2E385C6F9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072532; bh=OFswgQHWfr72XoqwXLCGiCCryhlkUSoIcgrJUyGN4cs=; 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=aIn5G4EIA1rIIIqE8Qj0Geh3V3ehBhirBMY2OIDmlWmGb9Bl3jX7blf3u1Jp/SOoF amqHJg0ws8fWXMNnCS0DzdbNAnmYX6E0+LKgwfF36SyCylXBUCsqBnNtPgz8E3Dy0t ntBPzJtILwBrFFDxlVWTSvAHEW01h9lIdn6c9PuY= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2083.outbound.protection.outlook.com [40.107.8.83]) by sourceware.org (Postfix) with ESMTPS id 095893857730 for ; Mon, 18 Sep 2023 21:27:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 095893857730 Received: from DUZPR01CA0080.eurprd01.prod.exchangelabs.com (2603:10a6:10:46a::9) by GV2PR08MB8704.eurprd08.prod.outlook.com (2603:10a6:150:b9::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 21:27:15 +0000 Received: from DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:46a:cafe::f) by DUZPR01CA0080.outlook.office365.com (2603:10a6:10:46a::9) 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:15 +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 DBAEUR03FT059.mail.protection.outlook.com (100.127.142.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.14 via Frontend Transport; Mon, 18 Sep 2023 21:27:15 +0000 Received: ("Tessian outbound d084e965c4eb:v175"); Mon, 18 Sep 2023 21:27:15 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 22c302db4197cb5d X-CR-MTA-TID: 64aa7808 Received: from ca8a8f99bc65.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A02B993F-38C5-43D0-8413-68F0FD5EA823.1; Mon, 18 Sep 2023 21:27:07 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id ca8a8f99bc65.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L0pNRhhDqV1XepuHgdrz/X1ks+5bT+tQtj56FNuPMA3/shiHaS+tluknx9Op5OAdT+hLDmn9Cc29Sl0+Msc1KwHU4Qh+BV1tNwv74ENlSr1AOcXuRqE1BvitzIsqpNm05VqCYwa3ThqBPES1f0Sd3HR6MpXFL32CLuez+XgEUIRzWas8f0452V7/LbynDHwQZ/eEEnkYQ3ThhtLMoeaAsr0GSK0aStcxj5+Fi1enLQ0yU1SgUIOC5h9ViUdAIf1EtT9JSaB1J7kU8EnPhxhZSMyC8PIgskIlfg+wYj4uFu9FXbkVzFBF22EC1SZM1NKrDi/QGYc5BnLKOpQ52fJxHg== 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=OFswgQHWfr72XoqwXLCGiCCryhlkUSoIcgrJUyGN4cs=; b=Mtzm0ZpULGWzPA06P6W+W087avOhC8/k//6/HVpbugN1dspbMIjfImaOkju/YD6sAzoX3EpoNG55SQXy4vSnwXJYWFId8t3lvT2vDRKzrJywBUpm3YiwMzCvxbXplSm95OFB+B39kMtuqLE8j/wjgOrA35hMxgS2CbQpqiN16u5dfZEJDETDj1MR35w95HAsP0naYVQOdK9BKFxnPdiWtRNV7UskUWeLSDy4OtjIiepHQ1SDz56lvycYYXrJPdyj96i3Oh07Ip5gpDZNzetZFWMNsGbmgwDTuetdTPVWJdO2CvAQJfIadx/TiRY94iphxrAOxKD5B3kjRmJ4UjDtxg== 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 AS8PR07CA0022.eurprd07.prod.outlook.com (2603:10a6:20b:451::17) by AM9PR08MB5987.eurprd08.prod.outlook.com (2603:10a6:20b:2da::16) 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:03 +0000 Received: from AM7EUR03FT058.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:451:cafe::2f) by AS8PR07CA0022.outlook.office365.com (2603:10a6:20b:451::17) 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:03 +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 AM7EUR03FT058.mail.protection.outlook.com (100.127.140.247) 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:03 +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:02 +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:02 +0000 To: Subject: [PATCH v7 04/18] [gdb/aarch64] sve: Fix return command when using V registers in a SVE-enabled target Date: Mon, 18 Sep 2023 22:26:37 +0100 Message-ID: <20230918212651.660141-5-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: AM7EUR03FT058:EE_|AM9PR08MB5987:EE_|DBAEUR03FT059:EE_|GV2PR08MB8704:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bdda96b-06ab-44bf-4d04-08dbb88e076f 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: k8a3hrBeHIPQyDmfmWbWj57YRcaKbGwUgXed3aGh+mUZq82+s4gXNHQTAQMAugcOhROAmMuDwk3X9+lepbOtTMEFE15F34D4m2ycjdnCtZ8u9ojo9oLrP782wIWFzljZBBPu9+cdFZuugFZFeZd+PL5AasipzGKrhNNI1DWXm5BpjYv/Kj+HTuLH0QcGDALDiHAz2TmMQAawL5+NziBSBdL02SpNFz94+9HXZ8R+qJk4EoRF+zqVax/KJv7iJn0ToM07ZZv8G5VCJMAYe8IXvAFyCXOBOUHpZR9GSMyY2CNVPnW3BpfDXLUak3doDNY6Hxz8YahhYuZ09B6q6Ng4rn/NDdpZgF8yhmGBnJ8gyFiVXcj1cU5n558CALQW45qR5WXM+e8SsQCE84HzKZwPlziqcJiogTdjHsl5LSPYhhHnytC5gdxLmXHy38RsZnumIZhldbGiA6FFa9zWpszrwM21ZHDYBJO+ZIT6NfurzlIzL+CksmzmPByv9RGM3d28c7fYMlFgoQvxL8DsYbvRvDUeEp07Zs5Fl2Kv/9QJ4BxeOTQA0mg7gtFFJgG76N4UbL/oXNLZL9ZR08cUJJhceDaKpBJ7XLMNaWy8iGJKV0t2kmIMJNvD+CU7rkA2947AV3hi21KO7FubnVsz+bEIqzJQGH3EG+M/UxjE5BvrzyHDXWuC4CHC0Mtjo47r3xSpWnK0tPyrxSupabQODF79OeT3CuY8gGfTsJmjhevJGTgLfge+5u77ugmhcUoPGmml361RGrIV5M+2v8yGmVFNjA== 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)(376002)(396003)(39860400002)(136003)(346002)(1800799009)(186009)(82310400011)(451199024)(36840700001)(40470700004)(46966006)(40460700003)(426003)(336012)(83380400001)(2616005)(26005)(1076003)(47076005)(41300700001)(36860700001)(316002)(6916009)(7696005)(54906003)(70206006)(5660300002)(8676002)(70586007)(8936002)(2906002)(6666004)(4326008)(478600001)(44832011)(86362001)(356005)(82740400003)(81166007)(36756003)(40480700001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR08MB5987 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 49eaa243-f56d-4fc1-e6ca-08dbb88e0046 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pqbr/tlJRIxON75akUMZhRe9x7yvmO0vZShNhZkQVRqYB/4L2qx2RBUkWwM/+YWSlRCITle314EiyKnTJiA43F0KtwY/g3HZoDFCzgzi7q+t+nWwGwwOvCpu+tH6e9yR/8tBrjyYspX69MgqRvUhsoZ3xl/+qfzG8MaAp704OjzXLstl9Veusvg6pkDiakWkG91pyUQni33lgRDw6aYzTTszjxmUTVwzOgHvBbsJzFRLyD/wsKqFXEiX9g8jhK6BnMiprzSwka616wUNg2OJS+oJY2p7N68Pwa7d0D7JYsgumDH1iEVLUTl40ZJP6o9f8DSTw1YxFSdKAEzE969SJoJHc3zA9IGn1rmb2lKOkIgPzR02pEUX2a2AxV8jg5JR1JC4h1STaI9FuwRoT55aEG2kU3d4poq/hOASZ7IUSbZTPp1wl0AVCXGY9psb/BodGjn5jqKbTQ+YyJYJjY4a6XJxK4MEPJpFfiO2fLrNqjhChHhzPGo4KP6Hucm/t5NaRSwik+HbAPv1F6PPspySWKlwZaZK0cSBQl2d2KTxxY6poOtofeJkwe1Qu7HgMunvlj5DtWqG4929fnMigLWUNWXc1FJi0zIa4NUUrMPy/S48aQLxny/KdaSJ54EE67MFwkCwbzp6bW4BFAsrNiHmE7+SBjJ8FCP5rB4UhWLdbOMQZJIOu7RDxhb51pZ4cb0U+DXnd07FhSw0KKg+K1o4sh8RiQmPeTPYGli80DymlBjNvbfYQ/8t9nVNLOBhRmT7 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)(39860400002)(346002)(396003)(136003)(376002)(451199024)(82310400011)(186009)(1800799009)(36840700001)(40470700004)(46966006)(70586007)(70206006)(7696005)(54906003)(40480700001)(44832011)(316002)(6916009)(41300700001)(6666004)(478600001)(4326008)(8936002)(8676002)(40460700003)(1076003)(107886003)(5660300002)(26005)(36756003)(36860700001)(81166007)(82740400003)(83380400001)(426003)(336012)(2906002)(47076005)(2616005)(86362001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:15.2658 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7bdda96b-06ab-44bf-4d04-08dbb88e076f 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: DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8704 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" In a target without SVE support, the V registers have a size of 16 bytes, otherwise they may have a size bigger than 16 bytes (depending on the current vector length for the Z registers, as they overlap the V registers). In aarch64-tdep.c:aarch64_store_return_value, the code is laid out in a way that allocates the buffer with the size of the register, but only updates the amount of bytes for the particular type we're returning. This may cause a situation where we have a register size of 32 bytes but are returning a floating point value of 8 bytes. The temporary buffer will therefore have 32 bytes, but we'll only update 8 bytes of it. When we write the entire register back, it will have potentially 24 bytes of garbage in it. Fix this by first reading the original contents of the register and then overriding only the bytes that we need for the return value. Tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-tdep.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index 21dd6c7a38c..b1d7da91754 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -2417,6 +2417,11 @@ aarch64_store_return_value (struct type *type, struct regcache *regs, ("write HFA or HVA return value element %d to %s", i + 1, gdbarch_register_name (gdbarch, regno)); + /* Depending on whether the target supports SVE or not, the V + registers may report a size > 16 bytes. In that case, read the + original contents of the register before overriding it with a new + value that has a potential size <= 16 bytes. */ + regs->cooked_read (regno, tmpbuf); memcpy (tmpbuf, valbuf, len > V_REGISTER_SIZE ? V_REGISTER_SIZE : len); regs->cooked_write (regno, tmpbuf); From patchwork Mon Sep 18 21:26:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76331 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 DD6D638768A4 for ; Mon, 18 Sep 2023 21:31:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DD6D638768A4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072677; bh=JwmytyxBsbpaze2SHayzlTItQdY1bW2z3xGw3QBqiTU=; 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=KMpIC0HzKZa0dfChFFZDIUrcktTA+/TEfpUZh3qJReptSSqaqBPlSBDLAEq697ALT E/q8puuOYU7xrULEccO2DQShnI0E7unzWO1vhr9gKcEfzw/ToAk0L/TGHJHDaleMni 9mc99/qBOkgtYh34w1zUSAx7slQ9qwpAlD8ryZ/Q= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2050.outbound.protection.outlook.com [40.107.105.50]) by sourceware.org (Postfix) with ESMTPS id 2D4493857355 for ; Mon, 18 Sep 2023 21:27:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2D4493857355 Received: from DB7PR05CA0035.eurprd05.prod.outlook.com (2603:10a6:10:36::48) by AS8PR08MB6038.eurprd08.prod.outlook.com (2603:10a6:20b:23f::24) 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:16 +0000 Received: from DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:36:cafe::8b) by DB7PR05CA0035.outlook.office365.com (2603:10a6:10:36::48) 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:16 +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 DBAEUR03FT012.mail.protection.outlook.com (100.127.142.126) 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:16 +0000 Received: ("Tessian outbound c99fbc01d472:v175"); Mon, 18 Sep 2023 21:27:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: fe4f3458a27a3e32 X-CR-MTA-TID: 64aa7808 Received: from 3bb083092994.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C7750864-0195-4841-8D9B-F47F6B3BDA2D.1; Mon, 18 Sep 2023 21:27:08 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3bb083092994.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=MPPzaGB7VTHY66uRkAWSjr/Er9uWS+e2DOd/gBRi2rHV7JpvOm8YOwL+N4XzXMUqjApJx79zmVzDl5pQmMvbqAmO70TAEnXNG4v6kbFUunA5sfai3fIpbuN19syQQqLGKFRXzYavx4zqEfes3i/WLpKOYRZgnUW3bNw2/zJYGhFbjrC0ZQ8YZpcuoH3xf5fMhwZKAPPiwel6GT0Y+k8f6VF9IKgQnEJlQR8rEs5/rTMLuuAW+UyiNtMmwATGm1ZOqBtXsborAem9zQGltSIEtvyGdZZLNX2wepXDG5K6K+h07v0AcCVNfO0dZ7kq+yuKuZk+FNsTqKR3aGRv/2BaJg== 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=JwmytyxBsbpaze2SHayzlTItQdY1bW2z3xGw3QBqiTU=; b=HOX5nyV3A0m+ckZkaFn9NsansNgK1hdGIwt3sFZDD24pHpnhdLrs6GRTsOicMCqaBIndF3Ks8J6cTCMc2XE3DGiTHuj8J5pJFcxk1mjNT2vjt45tYTNJsicrh4M+96ewA1hCuoofXvYBPTEXZzz36HiJkOkIcJ36KbiXGg7xtidg7Qk6cp0DABefaPDD79QmIMt/KfqCSqcoOm32BERZg2+TxN5ZXmX/LMNgH8s3pvDbSPU4/nLIC1jpYchI/GQhE9u5R1xt0WvBUDMMMKEwFrqRRuJLksvl2UF+AXvg8Pe4jWzqACiLnNPTS0i0oGU1RbfPpHH00nzwFQ3cuueDJg== 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 AM6P193CA0138.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::43) by DB9PR08MB6460.eurprd08.prod.outlook.com (2603:10a6:10:254::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:04 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::ea) by AM6P193CA0138.outlook.office365.com (2603:10a6:209:85::43) 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:03 +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:03 +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:03 +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:02 +0000 To: Subject: [PATCH v7 05/18] [gdb/aarch64] sme: Enable SME registers and pseudo-registers Date: Mon, 18 Sep 2023 22:26:38 +0100 Message-ID: <20230918212651.660141-6-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_|DB9PR08MB6460:EE_|DBAEUR03FT012:EE_|AS8PR08MB6038:EE_ X-MS-Office365-Filtering-Correlation-Id: b6de2d28-bee9-403d-e6ed-08dbb88e0833 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: 8Uz6JVA8yZgjg34AmChLX+9LQW7gzZ+5d8lPegInPQTtEazzaJsl54b2JhN0Kyo/cUa9m0qFpuvk9XbqEb98XD69sHrHNhQ50T05YX+KnO8Tf6QpZRE1n4Yj1O0i5XsKB1SXFOW4KBKFZipN8y4GBtsY6DWVQ9bVW62IWGpjKFRYO3xtp3/jxWXchJDMYfCmsHSX344wqx7RvOK6ArgG6GWmEj6qvaglHbaari7zrIyCRzNEFoQ453LXGEGD7QSlh2hGlvd3V8hrY2JN96KdAgNesVXw2u1iAQpponR+iZXJ+8OzmHU2vCf4mgJH1mA/aRkR6FXYHAzVV+Y7qHIAHMjO4FqoUMrNdNFxYuNsu8DEWn6OnySyV+991GjSVNKKyvvM3+AJpviYasFbWrW5OGzu9UbVqbDHXlCTGdweJljnZvzBy564xAJLltIh8ZfQd+v9+RewWaLjjRax53qywQmzjMX5zNjFD1EYJ7UMgP9Rxc/tZ+Lv+H0DuSnlsh8UQor/naujk7lNq1H2mT9QE1GoBGAhnBfk8tvL377BNAoEeU3jZa/Gedc2YmeXzi/eoedCtfQdCPQBrH46cPXXcPBXdQRLBPgsYNekHxNVkI/d1ogIW3jT9B4SSpPSuqnJZWrIyZn6QtlkF0AqHpA8AFev+DhLNb05dwZeUiOZXeOc7+m9SZEXHgy9iyY1Xw/3jtmJwd9ivs9j4MGfz0lDBeyPcy7T+42qtz91+EuW9ysw1ATEccJofrFOceKvlx6He6B4cWRTX1iV8edartIhNJ6jbFrv8EEr7TqkNE3UZjoKuQGz04SAZyNXImO5QzqY 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)(346002)(376002)(39860400002)(396003)(136003)(82310400011)(1800799009)(186009)(451199024)(46966006)(36840700001)(40470700004)(66899024)(40460700003)(336012)(426003)(83380400001)(2616005)(1076003)(26005)(47076005)(41300700001)(36860700001)(316002)(6916009)(30864003)(7696005)(70586007)(5660300002)(54906003)(70206006)(8676002)(4326008)(44832011)(8936002)(2906002)(6666004)(478600001)(966005)(86362001)(82740400003)(356005)(81166007)(36756003)(40480700001)(2004002)(36900700001)(559001)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB6460 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 2e423bc7-f4b7-4d65-59d3-08dbb88e009e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qbEwtnhUT9kLogbLsOO9dy215z3cA34010aYs6TSbpwyQdt/krpST0jEUFxKTDH2ykJRGyF3nfMdY4dXqO5c3ivYpPkF7egiDHfYdd5PlLxHvxb5s85jW0uZS4gPkvjEVGmiLFAIkSgxp/kxAfdj2SwyV4703J3cm2IQHHpZLuET2dHAKgvLtyL74WpE/3mF1NIFE0QrGKdWGtEcB/Hzg5Q7LiKNs+jJeBrtqh88QYu8Ywhcof9oe0DeB/56v/QZ73lbfw6Vekkd6WEGm6BFq0lciebGUFHsEBxsnVwVmGGAeXM7oT9jI8wG2LP45e6PojzrLflyMPLkfb/5kfvL3lqrEHFQBkMLQ6H9rIsbCU26J08Jzw5z+9KqivvKG5GZ00Fl5OHWoBzdcSaeBP3gTYpE7oRCpu6QWI+MXgshrAivnFuv67RBu9nz2lTED6SZLIV+ouyvTD5HQAzVL3qBAWI+wBjtu1b0eD67SAYrupjXYSwQZheZfhYR9kpbhgCyKX2iV5cqzufButeKmT9O5YAjQSX5D1n394h5gwQUBy87k3j0ua+7zZPftUVej0UZGez8kDvt3+NpuPun6MpNekHZu9d13bC9TNg4PrxGlk2EuLkDwxhN/daOfPVEFQmXTXo8/lzUfpQtEjAClmVesQQvUP8idy2JAmaqlwc+cd2sXav56P3RkEG3z6K9EMf3jenkwcRWJRUFdtxQNGDaeWR+CrAB84OklbFof9JHyiUu+LaK39rP8QwEfZUp9idBLNINWqotHS26Yq5LduRZmXF5+/0z9KLzsJMC9i+wLUM= 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)(396003)(39860400002)(136003)(376002)(346002)(186009)(1800799009)(451199024)(82310400011)(36840700001)(46966006)(40470700004)(40480700001)(81166007)(36756003)(82740400003)(86362001)(40460700003)(66899024)(478600001)(5660300002)(54906003)(44832011)(70206006)(8676002)(2906002)(6666004)(8936002)(4326008)(70586007)(966005)(7696005)(426003)(336012)(83380400001)(36860700001)(47076005)(41300700001)(30864003)(316002)(6916009)(107886003)(26005)(2616005)(1076003)(2004002)(559001)(579004); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:16.5230 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b6de2d28-bee9-403d-e6ed-08dbb88e0833 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: DBAEUR03FT012.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6038 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, KAM_SHORT, 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" Changes in v4: - Remove unused return value for aarch64_store_za_regset. --- The SME (Scalable Matrix Extension) [1] exposes a new matrix register ZA with variable sizes. It also exposes a new mode called streaming mode. Similarly to SVE, the ZA register size is dictated by a vector length, but the SME vector length is called streaming vetor length. The total size for ZA in a given moment is svl x svl. In streaming mode, the SVE registers have their sizes based on svl rather than the regular vector length (vl). The feature detection is controlled by the HWCAP2_SME bit, but actual support should be validated by attempting a ptrace call for one of the new register sets: NT_ARM_ZA and NT_ARM_SSVE. Due to its large size, the ZA register is exposed as a vector of bytes, but we introduce a number of pseudo-registers that gives various different views into the ZA contents. These can be arranged in a couple categories: tiles and tile slices. Tiles are matrices the same size or smaller than ZA. Tile slices are vectors which map to ZA's rows/columns in different ways. A new dynamic target description is provided containing the ZA register, the SVG register and the SVCR register. The size of ZA, like the SVE vector registers, is based on the vector length register SVG (VG for SVE). This patch enables SME register support for gdb. [1] https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/scalable-matrix-extension-armv9-a-architecture Co-Authored-By: Ezra Sitorus Reviewed-by: Thiago Jung Bauermann --- gdb/Makefile.in | 4 + gdb/aarch64-linux-nat.c | 98 ++- gdb/aarch64-tdep.c | 719 +++++++++++++++++++- gdb/aarch64-tdep.h | 47 ++ gdb/arch/aarch64-scalable-linux.c | 21 + gdb/arch/aarch64-scalable-linux.h | 38 ++ gdb/arch/aarch64.c | 5 + gdb/arch/aarch64.h | 57 +- gdb/configure.tgt | 1 + gdb/features/aarch64-sme.c | 63 ++ gdb/nat/aarch64-scalable-linux-ptrace.c | 572 +++++++++++++++- gdb/nat/aarch64-scalable-linux-ptrace.h | 108 ++- gdb/nat/aarch64-scalable-linux-sigcontext.h | 57 +- gdbserver/configure.srv | 1 + 14 files changed, 1737 insertions(+), 54 deletions(-) create mode 100644 gdb/arch/aarch64-scalable-linux.c create mode 100644 gdb/arch/aarch64-scalable-linux.h create mode 100644 gdb/features/aarch64-sme.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index cdfbad4deed..9c0a0bff2cd 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -728,6 +728,7 @@ ALL_64_TARGET_OBS = \ arch/aarch64.o \ arch/aarch64-insn.o \ arch/aarch64-mte-linux.o \ + arch/aarch64-scalable-linux.o \ arch/amd64.o \ arch/riscv.o \ bpf-tdep.o \ @@ -1524,6 +1525,7 @@ HFILES_NO_SRCDIR = \ arch/aarch64.h \ arch/aarch64-insn.h \ arch/aarch64-mte-linux.h \ + arch/aarch64-scalable-linux.h \ arch/arc.h \ arch/arm.h \ arch/i386.h \ @@ -1562,6 +1564,7 @@ HFILES_NO_SRCDIR = \ nat/aarch64-linux-hw-point.h \ nat/aarch64-mte-linux-ptrace.h \ nat/aarch64-scalable-linux-ptrace.h \ + nat/aarch64-scalable-linux-sigcontext.h \ nat/amd64-linux-siginfo.h \ nat/gdb_ptrace.h \ nat/gdb_thread_db.h \ @@ -1627,6 +1630,7 @@ ALLDEPFILES = \ arch/aarch64.c \ arch/aarch64-insn.c \ arch/aarch64-mte-linux.c \ + arch/aarch64-scalable-linux.c \ arch/amd64.c \ arch/arc.c \ arch/arm.c \ diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 267a1ca0e79..d7fcef5a0db 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -55,6 +55,7 @@ #include "arch/aarch64-mte-linux.h" #include "nat/aarch64-mte-linux-ptrace.h" +#include "arch/aarch64-scalable-linux.h" #include @@ -313,8 +314,11 @@ store_fpregs_to_thread (const struct regcache *regcache) } } -/* Fill GDB's register array with the sve register values - from the current thread. */ +/* Fill GDB's REGCACHE with the valid SVE register values from the thread + associated with REGCACHE. + + This function handles reading data from SVE or SSVE states, depending + on which state is active at the moment. */ static void fetch_sveregs_from_thread (struct regcache *regcache) @@ -323,8 +327,11 @@ fetch_sveregs_from_thread (struct regcache *regcache) aarch64_sve_regs_copy_to_reg_buf (regcache->ptid ().lwp (), regcache); } -/* Store to the current thread the valid sve register - values in the GDB's register array. */ +/* Store the valid SVE register values from GDB's REGCACHE to the thread + associated with REGCACHE. + + This function handles writing data to SVE or SSVE states, depending + on which state is active at the moment. */ static void store_sveregs_to_thread (struct regcache *regcache) @@ -334,6 +341,41 @@ store_sveregs_to_thread (struct regcache *regcache) aarch64_sve_regs_copy_from_reg_buf (regcache->ptid ().lwp (), regcache); } +/* Fill GDB's REGCACHE with the ZA register set contents from the + thread associated with REGCACHE. If there is no active ZA register state, + make the ZA register contents zero. */ + +static void +fetch_za_from_thread (struct regcache *regcache) +{ + aarch64_gdbarch_tdep *tdep + = gdbarch_tdep (regcache->arch ()); + + /* Read ZA state from the thread to the register cache. */ + aarch64_za_regs_copy_to_reg_buf (regcache->ptid ().lwp (), + regcache, + tdep->sme_za_regnum, + tdep->sme_svg_regnum, + tdep->sme_svcr_regnum); +} + +/* Store the NT_ARM_ZA register set contents from GDB's REGCACHE to the thread + associated with REGCACHE. */ + +static void +store_za_to_thread (struct regcache *regcache) +{ + aarch64_gdbarch_tdep *tdep + = gdbarch_tdep (regcache->arch ()); + + /* Write ZA state from the register cache to the thread. */ + aarch64_za_regs_copy_from_reg_buf (regcache->ptid ().lwp (), + regcache, + tdep->sme_za_regnum, + tdep->sme_svg_regnum, + tdep->sme_svcr_regnum); +} + /* Fill GDB's register array with the pointer authentication mask values from the current thread. */ @@ -488,7 +530,10 @@ aarch64_fetch_registers (struct regcache *regcache, int regno) if (regno == -1) { fetch_gregs_from_thread (regcache); - if (tdep->has_sve ()) + + /* We attempt to fetch SVE registers if there is support for either + SVE or SME (due to the SSVE state of SME). */ + if (tdep->has_sve () || tdep->has_sme ()) fetch_sveregs_from_thread (regcache); else fetch_fpregs_from_thread (regcache); @@ -501,12 +546,16 @@ aarch64_fetch_registers (struct regcache *regcache, int regno) if (tdep->has_tls ()) fetch_tlsregs_from_thread (regcache); + + if (tdep->has_sme ()) + fetch_za_from_thread (regcache); } /* General purpose register? */ else if (regno < AARCH64_V0_REGNUM) fetch_gregs_from_thread (regcache); /* SVE register? */ - else if (tdep->has_sve () && regno <= AARCH64_SVE_VG_REGNUM) + else if ((tdep->has_sve () || tdep->has_sme ()) + && regno <= AARCH64_SVE_VG_REGNUM) fetch_sveregs_from_thread (regcache); /* FPSIMD register? */ else if (regno <= AARCH64_FPCR_REGNUM) @@ -516,6 +565,10 @@ aarch64_fetch_registers (struct regcache *regcache, int regno) && (regno == AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base) || regno == AARCH64_PAUTH_CMASK_REGNUM (tdep->pauth_reg_base))) fetch_pauth_masks_from_thread (regcache); + /* SME register? */ + else if (tdep->has_sme () && regno >= tdep->sme_reg_base + && regno < tdep->sme_reg_base + 3) + fetch_za_from_thread (regcache); /* MTE register? */ else if (tdep->has_mte () && (regno == tdep->mte_reg_base)) @@ -577,7 +630,10 @@ aarch64_store_registers (struct regcache *regcache, int regno) if (regno == -1) { store_gregs_to_thread (regcache); - if (tdep->has_sve ()) + + /* We attempt to store SVE registers if there is support for either + SVE or SME (due to the SSVE state of SME). */ + if (tdep->has_sve () || tdep->has_sme ()) store_sveregs_to_thread (regcache); else store_fpregs_to_thread (regcache); @@ -587,16 +643,24 @@ aarch64_store_registers (struct regcache *regcache, int regno) if (tdep->has_tls ()) store_tlsregs_to_thread (regcache); + + if (tdep->has_sme ()) + store_za_to_thread (regcache); } /* General purpose register? */ else if (regno < AARCH64_V0_REGNUM) store_gregs_to_thread (regcache); /* SVE register? */ - else if (tdep->has_sve () && regno <= AARCH64_SVE_VG_REGNUM) + else if ((tdep->has_sve () || tdep->has_sme ()) + && regno <= AARCH64_SVE_VG_REGNUM) store_sveregs_to_thread (regcache); /* FPSIMD register? */ else if (regno <= AARCH64_FPCR_REGNUM) store_fpregs_to_thread (regcache); + /* SME register? */ + else if (tdep->has_sme () && regno >= tdep->sme_reg_base + && regno < tdep->sme_reg_base + 3) + store_za_to_thread (regcache); /* MTE register? */ else if (tdep->has_mte () && (regno == tdep->mte_reg_base)) @@ -787,10 +851,15 @@ aarch64_linux_nat_target::read_description () CORE_ADDR hwcap2 = linux_get_hwcap2 (); aarch64_features features; + /* SVE/SSVE check. Reading VQ may return either the regular vector length + or the streaming vector length, depending on whether streaming mode is + active or not. */ features.vq = aarch64_sve_get_vq (tid); features.pauth = hwcap & AARCH64_HWCAP_PACA; features.mte = hwcap2 & HWCAP2_MTE; features.tls = aarch64_tls_register_count (tid); + /* SME feature check. */ + features.svq = aarch64_za_get_svq (tid); return aarch64_read_description (features); } @@ -893,21 +962,24 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid) if (gdbarch_bfd_arch_info (inf->gdbarch)->bits_per_word == 32) return inf->gdbarch; - /* Only return it if the current vector length matches the one in the tdep. */ + /* Only return the inferior's gdbarch if both vq and svq match the ones in + the tdep. */ aarch64_gdbarch_tdep *tdep = gdbarch_tdep (inf->gdbarch); uint64_t vq = aarch64_sve_get_vq (ptid.lwp ()); - if (vq == tdep->vq) + uint64_t svq = aarch64_za_get_svq (ptid.lwp ()); + if (vq == tdep->vq && svq == tdep->sme_svq) return inf->gdbarch; - /* We reach here if the vector length for the thread is different from its + /* We reach here if any vector length for the thread is different from its value at process start. Lookup gdbarch via info (potentially creating a - new one) by using a target description that corresponds to the new vq value - and the current architecture features. */ + new one) by using a target description that corresponds to the new vq/svq + value and the current architecture features. */ const struct target_desc *tdesc = gdbarch_target_desc (inf->gdbarch); aarch64_features features = aarch64_features_from_target_desc (tdesc); features.vq = vq; + features.svq = svq; struct gdbarch_info info; info.bfd_arch_info = bfd_lookup_arch (bfd_arch_aarch64, bfd_mach_aarch64); diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index b1d7da91754..8e7259a6f42 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -57,6 +57,8 @@ /* For inferior_ptid and current_inferior (). */ #include "inferior.h" +/* For std::sqrt and std::pow. */ +#include /* A Homogeneous Floating-Point or Short-Vector Aggregate may have at most four members. */ @@ -190,6 +192,43 @@ struct aarch64_prologue_cache trad_frame_saved_reg *saved_regs; }; +/* Holds information used to read/write from/to ZA + pseudo-registers. + + With this information, the read/write code can be simplified so it + deals only with the required information to map a ZA pseudo-register + to the exact bytes into the ZA contents buffer. Otherwise we'd need + to use a lot of conditionals. */ + +struct za_offsets +{ + /* Offset, into ZA, of the starting byte of the pseudo-register. */ + size_t starting_offset; + /* The size of the contiguous chunks of the pseudo-register. */ + size_t chunk_size; + /* The number of pseudo-register chunks contained in ZA. */ + size_t chunks; + /* The offset between each contiguous chunk. */ + size_t stride_size; +}; + +/* Holds data that is helpful to determine the individual fields that make + up the names of the ZA pseudo-registers. It is also very helpful to + determine offsets, stride and sizes for reading ZA tiles and tile + slices. */ + +struct za_pseudo_encoding +{ + /* The slice index (0 ~ svl). Only used for tile slices. */ + uint8_t slice_index; + /* The tile number (0 ~ 15). */ + uint8_t tile_index; + /* Direction (horizontal/vertical). Only used for tile slices. */ + bool horizontal; + /* Qualifier index (0 ~ 4). These map to B, H, S, D and Q. */ + uint8_t qualifier_index; +}; + static void show_aarch64_debug (struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value) @@ -2147,6 +2186,214 @@ aarch64_vnb_type (struct gdbarch *gdbarch) return tdep->vnb_type; } +/* Return TRUE if REGNUM is a ZA tile slice pseudo-register number. Return + FALSE otherwise. */ + +static bool +is_sme_tile_slice_pseudo_register (struct gdbarch *gdbarch, int regnum) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + gdb_assert (tdep->sme_pseudo_base <= regnum); + gdb_assert (regnum < tdep->sme_pseudo_base + tdep->sme_pseudo_count); + + if (tdep->sme_tile_slice_pseudo_base <= regnum + && regnum < tdep->sme_tile_slice_pseudo_base + + tdep->sme_tile_slice_pseudo_count) + return true; + + return false; +} + +/* Given REGNUM, a ZA pseudo-register number, return, in ENCODING, the + decoded fields that make up its name. */ + +static void +aarch64_za_decode_pseudos (struct gdbarch *gdbarch, int regnum, + struct za_pseudo_encoding &encoding) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + gdb_assert (tdep->sme_pseudo_base <= regnum); + gdb_assert (regnum < tdep->sme_pseudo_base + tdep->sme_pseudo_count); + + if (is_sme_tile_slice_pseudo_register (gdbarch, regnum)) + { + /* Calculate the tile slice pseudo-register offset relative to the other + tile slice pseudo-registers. */ + int offset = regnum - tdep->sme_tile_slice_pseudo_base; + + /* Fetch the qualifier. We can have 160 to 2560 possible tile slice + pseudo-registers. Each qualifier (we have 5 of them: B, H, S, D + and Q) covers 32 * svq pseudo-registers, so we divide the offset by + that constant. */ + size_t qualifier = offset / (tdep->sme_svq * 32); + encoding.qualifier_index = qualifier; + + /* Prepare to fetch the direction (d), tile number (t) and slice + number (s). */ + int dts = offset % (tdep->sme_svq * 32); + + /* The direction is represented by the even/odd numbers. Even-numbered + pseudo-registers are horizontal tile slices and odd-numbered + pseudo-registers are vertical tile slices. */ + encoding.horizontal = !(dts & 1); + + /* Fetch the tile number. The tile number is closely related to the + qualifier. B has 1 tile, H has 2 tiles, S has 4 tiles, D has 8 tiles + and Q has 16 tiles. */ + encoding.tile_index = (dts >> 1) & ((1 << qualifier) - 1); + + /* Fetch the slice number. The slice number is closely related to the + qualifier and the svl. */ + encoding.slice_index = dts >> (qualifier + 1); + } + else + { + /* Calculate the tile pseudo-register offset relative to the other + tile pseudo-registers. */ + int offset = regnum - tdep->sme_tile_pseudo_base; + + encoding.qualifier_index = std::floor (std::log2 (offset + 1)); + /* Calculate the tile number. */ + encoding.tile_index = (offset + 1) - (1 << encoding.qualifier_index); + /* Direction and slice index don't get used for tiles. Set them to + 0/false values. */ + encoding.slice_index = 0; + encoding.horizontal = false; + } +} + +/* Return the type for a ZA tile slice pseudo-register based on ENCODING. */ + +static struct type * +aarch64_za_tile_slice_type (struct gdbarch *gdbarch, + const struct za_pseudo_encoding &encoding) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + + if (tdep->sme_tile_slice_type_q == nullptr) + { + /* Q tile slice type. */ + tdep->sme_tile_slice_type_q + = init_vector_type (builtin_type (gdbarch)->builtin_uint128, + tdep->sme_svq); + /* D tile slice type. */ + tdep->sme_tile_slice_type_d + = init_vector_type (builtin_type (gdbarch)->builtin_uint64, + tdep->sme_svq * 2); + /* S tile slice type. */ + tdep->sme_tile_slice_type_s + = init_vector_type (builtin_type (gdbarch)->builtin_uint32, + tdep->sme_svq * 4); + /* H tile slice type. */ + tdep->sme_tile_slice_type_h + = init_vector_type (builtin_type (gdbarch)->builtin_uint16, + tdep->sme_svq * 8); + /* B tile slice type. */ + tdep->sme_tile_slice_type_b + = init_vector_type (builtin_type (gdbarch)->builtin_uint8, + tdep->sme_svq * 16); + } + + switch (encoding.qualifier_index) + { + case 4: + return tdep->sme_tile_slice_type_q; + case 3: + return tdep->sme_tile_slice_type_d; + case 2: + return tdep->sme_tile_slice_type_s; + case 1: + return tdep->sme_tile_slice_type_h; + case 0: + return tdep->sme_tile_slice_type_b; + default: + error (_("Invalid qualifier index %s for tile slice pseudo register."), + pulongest (encoding.qualifier_index)); + } + + gdb_assert_not_reached ("Unknown qualifier for ZA tile slice register"); +} + +/* Return the type for a ZA tile pseudo-register based on ENCODING. */ + +static struct type * +aarch64_za_tile_type (struct gdbarch *gdbarch, + const struct za_pseudo_encoding &encoding) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + + if (tdep->sme_tile_type_q == nullptr) + { + struct type *inner_vectors_type; + + /* Q tile type. */ + inner_vectors_type + = init_vector_type (builtin_type (gdbarch)->builtin_uint128, + tdep->sme_svq); + tdep->sme_tile_type_q + = init_vector_type (inner_vectors_type, tdep->sme_svq); + + /* D tile type. */ + inner_vectors_type + = init_vector_type (builtin_type (gdbarch)->builtin_uint64, + tdep->sme_svq * 2); + tdep->sme_tile_type_d + = init_vector_type (inner_vectors_type, tdep->sme_svq * 2); + + /* S tile type. */ + inner_vectors_type + = init_vector_type (builtin_type (gdbarch)->builtin_uint32, + tdep->sme_svq * 4); + tdep->sme_tile_type_s + = init_vector_type (inner_vectors_type, tdep->sme_svq * 4); + + /* H tile type. */ + inner_vectors_type + = init_vector_type (builtin_type (gdbarch)->builtin_uint16, + tdep->sme_svq * 8); + tdep->sme_tile_type_h + = init_vector_type (inner_vectors_type, tdep->sme_svq * 8); + + /* B tile type. */ + inner_vectors_type + = init_vector_type (builtin_type (gdbarch)->builtin_uint8, + tdep->sme_svq * 16); + tdep->sme_tile_type_b + = init_vector_type (inner_vectors_type, tdep->sme_svq * 16); + } + + switch (encoding.qualifier_index) + { + case 4: + return tdep->sme_tile_type_q; + case 3: + return tdep->sme_tile_type_d; + case 2: + return tdep->sme_tile_type_s; + case 1: + return tdep->sme_tile_type_h; + case 0: + return tdep->sme_tile_type_b; + default: + error (_("Invalid qualifier index %s for ZA tile pseudo register."), + pulongest (encoding.qualifier_index)); + } + + gdb_assert_not_reached ("unknown qualifier for tile pseudo-register"); +} + /* Return the type for an AdvSISD V register. */ static struct type * @@ -2579,6 +2826,73 @@ is_w_pseudo_register (struct gdbarch *gdbarch, int regnum) return false; } +/* Return TRUE if REGNUM is a SME pseudo-register number. Return FALSE + otherwise. */ + +static bool +is_sme_pseudo_register (struct gdbarch *gdbarch, int regnum) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + if (tdep->has_sme () && tdep->sme_pseudo_base <= regnum + && regnum < tdep->sme_pseudo_base + tdep->sme_pseudo_count) + return true; + + return false; +} + +/* Convert ENCODING into a ZA tile slice name. */ + +static const std::string +aarch64_za_tile_slice_name (const struct za_pseudo_encoding &encoding) +{ + gdb_assert (encoding.qualifier_index >= 0); + gdb_assert (encoding.qualifier_index <= 4); + gdb_assert (encoding.tile_index >= 0); + gdb_assert (encoding.tile_index <= 15); + gdb_assert (encoding.slice_index >= 0); + gdb_assert (encoding.slice_index <= 255); + + const char orientation = encoding.horizontal ? 'h' : 'v'; + + const char qualifiers[6] = "bhsdq"; + const char qualifier = qualifiers [encoding.qualifier_index]; + return string_printf ("za%d%c%c%d", encoding.tile_index, orientation, + qualifier, encoding.slice_index); +} + +/* Convert ENCODING into a ZA tile name. */ + +static const std::string +aarch64_za_tile_name (const struct za_pseudo_encoding &encoding) +{ + /* Tiles don't use the slice number and the direction fields. */ + gdb_assert (encoding.qualifier_index >= 0); + gdb_assert (encoding.qualifier_index <= 4); + gdb_assert (encoding.tile_index >= 0); + gdb_assert (encoding.tile_index <= 15); + + const char qualifiers[6] = "bhsdq"; + const char qualifier = qualifiers [encoding.qualifier_index]; + return (string_printf ("za%d%c", encoding.tile_index, qualifier)); +} + +/* Given a SME pseudo-register REGNUM, return its type. */ + +static struct type * +aarch64_sme_pseudo_register_type (struct gdbarch *gdbarch, int regnum) +{ + struct za_pseudo_encoding encoding; + + /* Decode the SME pseudo-register number. */ + aarch64_za_decode_pseudos (gdbarch, regnum, encoding); + + if (is_sme_tile_slice_pseudo_register (gdbarch, regnum)) + return aarch64_za_tile_slice_type (gdbarch, encoding); + else + return aarch64_za_tile_type (gdbarch, encoding); +} + /* Return the pseudo register name corresponding to register regnum. */ static const char * @@ -2699,6 +3013,9 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum) return sve_v_name[p_regnum - AARCH64_SVE_V0_REGNUM]; } + if (is_sme_pseudo_register (gdbarch, regnum)) + return tdep->sme_pseudo_names[regnum - tdep->sme_pseudo_base].c_str (); + /* RA_STATE is used for unwinding only. Do not assign it a name - this prevents it from being read by methods such as mi_cmd_trace_frame_collected. */ @@ -2741,6 +3058,9 @@ aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum) if (is_w_pseudo_register (gdbarch, regnum)) return builtin_type (gdbarch)->builtin_uint32; + if (is_sme_pseudo_register (gdbarch, regnum)) + return aarch64_sme_pseudo_register_type (gdbarch, regnum); + if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum) return builtin_type (gdbarch)->builtin_uint64; @@ -2773,6 +3093,8 @@ aarch64_pseudo_register_reggroup_p (struct gdbarch *gdbarch, int regnum, else if (tdep->has_sve () && p_regnum >= AARCH64_SVE_V0_REGNUM && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM) return group == all_reggroup || group == vector_reggroup; + else if (is_sme_pseudo_register (gdbarch, regnum)) + return group == all_reggroup || group == vector_reggroup; /* RA_STATE is used for unwinding only. Do not assign it to any groups. */ if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum) return 0; @@ -2802,6 +3124,122 @@ aarch64_pseudo_read_value_1 (struct gdbarch *gdbarch, return result_value; } +/* Helper function for reading/writing ZA pseudo-registers. Given REGNUM, + a ZA pseudo-register number, return, in OFFSETS, the information on positioning + of the bytes that must be read from/written to. */ + +static void +aarch64_za_offsets_from_regnum (struct gdbarch *gdbarch, int regnum, + struct za_offsets &offsets) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + gdb_assert (tdep->sme_pseudo_base <= regnum); + gdb_assert (regnum < tdep->sme_pseudo_base + tdep->sme_pseudo_count); + + struct za_pseudo_encoding encoding; + + /* Decode the ZA pseudo-register number. */ + aarch64_za_decode_pseudos (gdbarch, regnum, encoding); + + /* Fetch the streaming vector length. */ + size_t svl = sve_vl_from_vq (tdep->sme_svq); + + if (is_sme_tile_slice_pseudo_register (gdbarch, regnum)) + { + if (encoding.horizontal) + { + /* Horizontal tile slices are contiguous ranges of svl bytes. */ + + /* The starting offset depends on the tile index (to locate the tile + in the ZA buffer), the slice index (to locate the slice within the + tile) and the qualifier. */ + offsets.starting_offset + = encoding.tile_index * svl + encoding.slice_index + * (svl >> encoding.qualifier_index); + /* Horizontal tile slice data is contiguous and thus doesn't have + a stride. */ + offsets.stride_size = 0; + /* Horizontal tile slice data is contiguous and thus only has 1 + chunk. */ + offsets.chunks = 1; + /* The chunk size is always svl bytes. */ + offsets.chunk_size = svl; + } + else + { + /* Vertical tile slices are non-contiguous ranges of + (1 << qualifier_index) bytes. */ + + /* The starting offset depends on the tile number (to locate the + tile in the ZA buffer), the slice index (to locate the element + within the tile slice) and the qualifier. */ + offsets.starting_offset + = encoding.tile_index * svl + encoding.slice_index + * (1 << encoding.qualifier_index); + /* The offset between vertical tile slices depends on the qualifier + and svl. */ + offsets.stride_size = svl << encoding.qualifier_index; + /* The number of chunks depends on svl and the qualifier size. */ + offsets.chunks = svl >> encoding.qualifier_index; + /* The chunk size depends on the qualifier. */ + offsets.chunk_size = 1 << encoding.qualifier_index; + } + } + else + { + /* ZA tile pseudo-register. */ + + /* Starting offset depends on the tile index and qualifier. */ + offsets.starting_offset = encoding.tile_index * svl; + /* The offset between tile slices depends on the qualifier and svl. */ + offsets.stride_size = svl << encoding.qualifier_index; + /* The number of chunks depends on the qualifier and svl. */ + offsets.chunks = svl >> encoding.qualifier_index; + /* The chunk size is always svl bytes. */ + offsets.chunk_size = svl; + } +} + +/* Given REGNUM, a SME pseudo-register number, return its value in RESULT. */ + +static struct value * +aarch64_sme_pseudo_register_read (struct gdbarch *gdbarch, + readable_regcache *regcache, int regnum, + struct value *result) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + gdb_assert (tdep->sme_pseudo_base <= regnum); + gdb_assert (regnum < tdep->sme_pseudo_base + tdep->sme_pseudo_count); + + /* Fetch the offsets that we need in order to read from the correct blocks + of ZA. */ + struct za_offsets offsets; + aarch64_za_offsets_from_regnum (gdbarch, regnum, offsets); + + /* Fetch the contents of ZA. */ + size_t svl = sve_vl_from_vq (tdep->sme_svq); + gdb::byte_vector za (std::pow (svl, 2)); + regcache->raw_read (tdep->sme_za_regnum, za.data ()); + + /* Copy the requested data. */ + for (int chunks = 0; chunks < offsets.chunks; chunks++) + { + const gdb_byte *source + = za.data () + offsets.starting_offset + chunks * offsets.stride_size; + gdb_byte *destination + = result->contents_raw ().data () + chunks * offsets.chunk_size; + + memcpy (destination, source, offsets.chunk_size); + } + return result; +} + /* Implement the "pseudo_register_read_value" gdbarch method. */ static struct value * @@ -2835,6 +3273,9 @@ aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache, return result_value; } + else if (is_sme_pseudo_register (gdbarch, regnum)) + return aarch64_sme_pseudo_register_read (gdbarch, regcache, regnum, + result_value); regnum -= gdbarch_num_regs (gdbarch); @@ -2894,6 +3335,44 @@ aarch64_pseudo_write_1 (struct gdbarch *gdbarch, struct regcache *regcache, regcache->raw_write (v_regnum, reg_buf); } +/* Given REGNUM, a SME pseudo-register number, store the bytes from DATA to the + pseudo-register. */ + +static void +aarch64_sme_pseudo_register_write (struct gdbarch *gdbarch, + struct regcache *regcache, + int regnum, const gdb_byte *data) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_svq > 0); + gdb_assert (tdep->sme_pseudo_base <= regnum); + gdb_assert (regnum < tdep->sme_pseudo_base + tdep->sme_pseudo_count); + + /* Fetch the offsets that we need in order to write to the correct blocks + of ZA. */ + struct za_offsets offsets; + aarch64_za_offsets_from_regnum (gdbarch, regnum, offsets); + + /* Fetch the contents of ZA. */ + size_t svl = sve_vl_from_vq (tdep->sme_svq); + gdb::byte_vector za (std::pow (svl, 2)); + + /* Copy the requested data. */ + for (int chunks = 0; chunks < offsets.chunks; chunks++) + { + const gdb_byte *source = data + chunks * offsets.chunk_size; + gdb_byte *destination + = za.data () + offsets.starting_offset + chunks * offsets.stride_size; + + memcpy (destination, source, offsets.chunk_size); + } + + /* Write back to ZA. */ + regcache->raw_write (tdep->sme_za_regnum, za.data ()); +} + /* Implement the "pseudo_register_write" gdbarch method. */ static void @@ -2921,6 +3400,11 @@ aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache, regcache->raw_write_part (x_regnum, offset, 4, buf); return; } + else if (is_sme_pseudo_register (gdbarch, regnum)) + { + aarch64_sme_pseudo_register_write (gdbarch, regcache, regnum, buf); + return; + } regnum -= gdbarch_num_regs (gdbarch); @@ -3500,6 +3984,33 @@ aarch64_get_tdesc_vq (const struct target_desc *tdesc) return sve_vq_from_vl (vl); } + +/* Return the svq (streaming vector quotient) used when creating the target + description TDESC. */ + +static uint64_t +aarch64_get_tdesc_svq (const struct target_desc *tdesc) +{ + const struct tdesc_feature *feature_sme; + + if (!tdesc_has_registers (tdesc)) + return 0; + + feature_sme = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.sme"); + + if (feature_sme == nullptr) + return 0; + + size_t svl_squared = tdesc_register_bitsize (feature_sme, "za"); + + /* We have the total size of the ZA matrix, in bits. Figure out the svl + value. */ + size_t svl = std::sqrt (svl_squared / 8); + + /* Now extract svq. */ + return sve_vq_from_vl (svl); +} + /* Get the AArch64 features present in the given target description. */ aarch64_features @@ -3535,6 +4046,8 @@ aarch64_features_from_target_desc (const struct target_desc *tdesc) features.tls = 1; } + features.svq = aarch64_get_tdesc_svq (tdesc); + return features; } @@ -3654,6 +4167,35 @@ aarch64_remove_non_address_bits (struct gdbarch *gdbarch, CORE_ADDR pointer) return aarch64_remove_top_bits (pointer, mask); } +/* Given NAMES, a vector of strings, initialize it with all the SME + pseudo-register names for the current streaming vector length. */ + +static void +aarch64_initialize_sme_pseudo_names (struct gdbarch *gdbarch, + std::vector &names) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + gdb_assert (tdep->has_sme ()); + gdb_assert (tdep->sme_tile_slice_pseudo_base > 0); + gdb_assert (tdep->sme_tile_pseudo_base > 0); + + for (int i = 0; i < tdep->sme_tile_slice_pseudo_count; i++) + { + int regnum = tdep->sme_tile_slice_pseudo_base + i; + struct za_pseudo_encoding encoding; + aarch64_za_decode_pseudos (gdbarch, regnum, encoding); + names.push_back (aarch64_za_tile_slice_name (encoding)); + } + for (int i = 0; i < AARCH64_ZA_TILES_NUM; i++) + { + int regnum = tdep->sme_tile_pseudo_base + i; + struct za_pseudo_encoding encoding; + aarch64_za_decode_pseudos (gdbarch, regnum, encoding); + names.push_back (aarch64_za_tile_name (encoding)); + } +} + /* Initialize the current architecture based on INFO. If possible, re-use an architecture from ARCHES, which is a list of architectures already created during this debugging session. @@ -3671,11 +4213,17 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) int first_pauth_regnum = -1, ra_sign_state_offset = -1; int first_mte_regnum = -1, first_tls_regnum = -1; uint64_t vq = aarch64_get_tdesc_vq (info.target_desc); + uint64_t svq = aarch64_get_tdesc_svq (info.target_desc); if (vq > AARCH64_MAX_SVE_VQ) internal_error (_("VQ out of bounds: %s (max %d)"), pulongest (vq), AARCH64_MAX_SVE_VQ); + if (svq > AARCH64_MAX_SVE_VQ) + internal_error (_("Streaming vector quotient (svq) out of bounds: %s" + " (max %d)"), + pulongest (svq), AARCH64_MAX_SVE_VQ); + /* If there is already a candidate, use it. */ for (gdbarch_list *best_arch = gdbarch_list_lookup_by_info (arches, &info); best_arch != nullptr; @@ -3683,15 +4231,21 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) { aarch64_gdbarch_tdep *tdep = gdbarch_tdep (best_arch->gdbarch); - if (tdep && tdep->vq == vq) + if (tdep && tdep->vq == vq && tdep->sme_svq == svq) return best_arch->gdbarch; } /* Ensure we always have a target descriptor, and that it is for the given VQ value. */ const struct target_desc *tdesc = info.target_desc; - if (!tdesc_has_registers (tdesc)) - tdesc = aarch64_read_description ({}); + if (!tdesc_has_registers (tdesc) || vq != aarch64_get_tdesc_vq (tdesc) + || svq != aarch64_get_tdesc_svq (tdesc)) + { + aarch64_features features; + features.vq = vq; + features.svq = svq; + tdesc = aarch64_read_description (features); + } gdb_assert (tdesc); feature_core = tdesc_find_feature (tdesc,"org.gnu.gdb.aarch64.core"); @@ -3755,6 +4309,35 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) num_pseudo_regs += 32; /* add the Bn scalar register pseudos */ } + int first_sme_regnum = -1; + int first_sme_pseudo_regnum = -1; + const struct tdesc_feature *feature_sme + = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.sme"); + if (feature_sme != nullptr) + { + /* Record the first SME register. */ + first_sme_regnum = num_regs; + + valid_p &= tdesc_numbered_register (feature_sme, tdesc_data.get (), + num_regs++, "svg"); + + valid_p &= tdesc_numbered_register (feature_sme, tdesc_data.get (), + num_regs++, "svcr"); + + valid_p &= tdesc_numbered_register (feature_sme, tdesc_data.get (), + num_regs++, "za"); + + /* Record the first SME pseudo register. */ + first_sme_pseudo_regnum = num_pseudo_regs; + + /* Add the ZA tile slice pseudo registers. The number of tile slice + pseudo-registers depend on the svl, and is always a multiple of 5. */ + num_pseudo_regs += (svq << 5) * 5; + + /* Add the ZA tile pseudo registers. */ + num_pseudo_regs += AARCH64_ZA_TILES_NUM; + } + /* Add the TLS register. */ int tls_register_count = 0; if (feature_tls != nullptr) @@ -3868,6 +4451,14 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) tdep->tls_regnum_base = first_tls_regnum; tdep->tls_register_count = tls_register_count; + /* Set the SME register set details. The pseudo-registers will be adjusted + later. */ + tdep->sme_reg_base = first_sme_regnum; + tdep->sme_svg_regnum = first_sme_regnum; + tdep->sme_svcr_regnum = first_sme_regnum + 1; + tdep->sme_za_regnum = first_sme_regnum + 2; + tdep->sme_svq = svq; + set_gdbarch_push_dummy_call (gdbarch, aarch64_push_dummy_call); set_gdbarch_frame_align (gdbarch, aarch64_frame_align); @@ -3984,6 +4575,86 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) set_gdbarch_remove_non_address_bits (gdbarch, aarch64_remove_non_address_bits); + /* SME pseudo-registers. */ + if (tdep->has_sme ()) + { + tdep->sme_pseudo_base = num_regs + first_sme_pseudo_regnum; + tdep->sme_tile_slice_pseudo_base = tdep->sme_pseudo_base; + tdep->sme_tile_slice_pseudo_count = (svq * 32) * 5; + tdep->sme_tile_pseudo_base + = tdep->sme_pseudo_base + tdep->sme_tile_slice_pseudo_count; + tdep->sme_pseudo_count + = tdep->sme_tile_slice_pseudo_count + AARCH64_ZA_TILES_NUM; + + /* The SME ZA pseudo-registers are a set of 160 to 2560 pseudo-registers + depending on the value of svl. + + The tile pseudo-registers are organized around their qualifiers + (b, h, s, d and q). Their numbers are distributed as follows: + + b 0 + h 1~2 + s 3~6 + d 7~14 + q 15~30 + + The naming of the tile pseudo-registers follows the pattern za, + where: + + is the tile number, with the following possible values based on + the qualifiers: + + Qualifier - Allocated indexes + + b - 0 + h - 0~1 + s - 0~3 + d - 0~7 + q - 0~15 + + is the qualifier: b, h, s, d and q. + + The tile slice pseudo-registers are organized around their + qualifiers as well (b, h, s, d and q), but also around their + direction (h - horizontal and v - vertical). + + Even-numbered tile slice pseudo-registers are horizontally-oriented + and odd-numbered tile slice pseudo-registers are vertically-oriented. + + Their numbers are distributed as follows: + + Qualifier - Allocated indexes + + b tile slices - 0~511 + h tile slices - 512~1023 + s tile slices - 1024~1535 + d tile slices - 1536~2047 + q tile slices - 2048~2559 + + The naming of the tile slice pseudo-registers follows the pattern + za, where: + + is the tile number as described for the tile pseudo-registers. + is the direction of the tile slice (h or v) + is the qualifier of the tile slice (b, h, s, d or q) + is the slice number, defined as follows: + + Qualifier - Allocated indexes + + b - 0~15 + h - 0~7 + s - 0~3 + d - 0~1 + q - 0 + + We have helper functions to translate to/from register index from/to + the set of fields that make the pseudo-register names. */ + + /* Build the array of pseudo-register names available for this + particular gdbarch configuration. */ + aarch64_initialize_sme_pseudo_names (gdbarch, tdep->sme_pseudo_names); + } + /* Add standard register aliases. */ for (i = 0; i < ARRAY_SIZE (aarch64_register_aliases); i++) user_reg_add (gdbarch, aarch64_register_aliases[i].name, @@ -4005,6 +4676,48 @@ aarch64_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file) gdb_printf (file, _("aarch64_dump_tdep: Lowest pc = 0x%s\n"), paddress (gdbarch, tdep->lowest_pc)); + + /* SME fields. */ + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_type_q = %s\n"), + host_address_to_string (tdep->sme_tile_type_q)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_type_d = %s\n"), + host_address_to_string (tdep->sme_tile_type_d)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_type_s = %s\n"), + host_address_to_string (tdep->sme_tile_type_s)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_type_h = %s\n"), + host_address_to_string (tdep->sme_tile_type_h)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_type_n = %s\n"), + host_address_to_string (tdep->sme_tile_type_b)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_type_q = %s\n"), + host_address_to_string (tdep->sme_tile_slice_type_q)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_type_d = %s\n"), + host_address_to_string (tdep->sme_tile_slice_type_d)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_type_s = %s\n"), + host_address_to_string (tdep->sme_tile_slice_type_s)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_type_h = %s\n"), + host_address_to_string (tdep->sme_tile_slice_type_h)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_type_b = %s\n"), + host_address_to_string (tdep->sme_tile_slice_type_b)); + gdb_printf (file, _("aarch64_dump_tdep: sme_reg_base = %s\n"), + pulongest (tdep->sme_reg_base)); + gdb_printf (file, _("aarch64_dump_tdep: sme_svg_regnum = %s\n"), + pulongest (tdep->sme_svg_regnum)); + gdb_printf (file, _("aarch64_dump_tdep: sme_svcr_regnum = %s\n"), + pulongest (tdep->sme_svcr_regnum)); + gdb_printf (file, _("aarch64_dump_tdep: sme_za_regnum = %s\n"), + pulongest (tdep->sme_za_regnum)); + gdb_printf (file, _("aarch64_dump_tdep: sme_pseudo_base = %s\n"), + pulongest (tdep->sme_pseudo_base)); + gdb_printf (file, _("aarch64_dump_tdep: sme_pseudo_count = %s\n"), + pulongest (tdep->sme_pseudo_count)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_pseudo_base = %s\n"), + pulongest (tdep->sme_tile_slice_pseudo_base)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_slice_pseudo_count = %s\n"), + pulongest (tdep->sme_tile_slice_pseudo_count)); + gdb_printf (file, _("aarch64_dump_tdep: sme_tile_pseudo_base = %s\n"), + pulongest (tdep->sme_tile_pseudo_base)); + gdb_printf (file, _("aarch64_dump_tdep: sme_svq = %s\n"), + pulongest (tdep->sme_svq)); } #if GDB_SELF_TEST diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h index 505e050ba48..9297487a584 100644 --- a/gdb/aarch64-tdep.h +++ b/gdb/aarch64-tdep.h @@ -80,6 +80,22 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base struct type *vnb_type = nullptr; struct type *vnv_type = nullptr; + /* Types for SME ZA tiles and tile slices pseudo-registers. */ + struct type *sme_tile_type_q = nullptr; + struct type *sme_tile_type_d = nullptr; + struct type *sme_tile_type_s = nullptr; + struct type *sme_tile_type_h = nullptr; + struct type *sme_tile_type_b = nullptr; + struct type *sme_tile_slice_type_q = nullptr; + struct type *sme_tile_slice_type_d = nullptr; + struct type *sme_tile_slice_type_s = nullptr; + struct type *sme_tile_slice_type_h = nullptr; + struct type *sme_tile_slice_type_b = nullptr; + + /* Vector of names for SME pseudo-registers. The number of elements is + different for each distinct svl value. */ + std::vector sme_pseudo_names; + /* syscall record. */ int (*aarch64_syscall_record) (struct regcache *regcache, unsigned long svc_number) = nullptr; @@ -125,6 +141,37 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base /* The W pseudo-registers. */ int w_pseudo_base = 0; int w_pseudo_count = 0; + + /* SME feature fields. */ + + /* Index of the first SME register. This is -1 if SME is not supported. */ + int sme_reg_base = 0; + /* svg register index. */ + int sme_svg_regnum = 0; + /* svcr register index. */ + int sme_svcr_regnum = 0; + /* ZA register index. */ + int sme_za_regnum = 0; + /* Index of the first SME pseudo-register. This is -1 if SME is not + supported. */ + int sme_pseudo_base = 0; + /* Total number of SME pseudo-registers. */ + int sme_pseudo_count = 0; + /* First tile slice pseudo-register index. */ + int sme_tile_slice_pseudo_base = 0; + /* Total number of tile slice pseudo-registers. */ + int sme_tile_slice_pseudo_count = 0; + /* First tile pseudo-register index. */ + int sme_tile_pseudo_base = 0; + /* The streaming vector quotient (svq) for SME, or zero if SME is not + supported. */ + size_t sme_svq = 0; + + /* Return true if the target supports SME, and false otherwise. */ + bool has_sme () const + { + return sme_svq != 0; + } }; const target_desc *aarch64_read_description (const aarch64_features &features); diff --git a/gdb/arch/aarch64-scalable-linux.c b/gdb/arch/aarch64-scalable-linux.c new file mode 100644 index 00000000000..3803acfd9a8 --- /dev/null +++ b/gdb/arch/aarch64-scalable-linux.c @@ -0,0 +1,21 @@ +/* Common Linux arch-specific functionality for AArch64 scalable + extensions: SVE and SME. + + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "arch/aarch64-scalable-linux.h" diff --git a/gdb/arch/aarch64-scalable-linux.h b/gdb/arch/aarch64-scalable-linux.h new file mode 100644 index 00000000000..df1741004ed --- /dev/null +++ b/gdb/arch/aarch64-scalable-linux.h @@ -0,0 +1,38 @@ +/* Common AArch64 Linux arch-specific definitions for the scalable + extensions: SVE and SME. + + Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef ARCH_AARCH64_SCALABLE_LINUX_H +#define ARCH_AARCH64_SCALABLE_LINUX_H + +#include "gdbsupport/common-defs.h" + +/* Feature check for Scalable Matrix Extension. */ +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +/* Streaming mode enabled/disabled bit. */ +#define SVCR_SM_BIT (1 << 0) +/* ZA enabled/disabled bit. */ +#define SVCR_ZA_BIT (1 << 1) +/* Mask including all valid SVCR bits. */ +#define SVCR_BIT_MASK (SVCR_SM_BIT | SVCR_ZA_BIT) + +#endif /* ARCH_AARCH64_SCALABLE_LINUX_H */ diff --git a/gdb/arch/aarch64.c b/gdb/arch/aarch64.c index 8644b9afcef..e1f4948aa25 100644 --- a/gdb/arch/aarch64.c +++ b/gdb/arch/aarch64.c @@ -24,6 +24,7 @@ #include "../features/aarch64-sve.c" #include "../features/aarch64-pauth.c" #include "../features/aarch64-mte.c" +#include "../features/aarch64-sme.c" #include "../features/aarch64-tls.c" /* See arch/aarch64.h. */ @@ -57,6 +58,10 @@ aarch64_create_target_description (const aarch64_features &features) if (features.tls > 0) regnum = create_feature_aarch64_tls (tdesc.get (), regnum, features.tls); + if (features.svq) + regnum = create_feature_aarch64_sme (tdesc.get (), regnum, + sve_vl_from_vq (features.svq)); + return tdesc.release (); } diff --git a/gdb/arch/aarch64.h b/gdb/arch/aarch64.h index 4b3f1b8eff8..c1cd233c51e 100644 --- a/gdb/arch/aarch64.h +++ b/gdb/arch/aarch64.h @@ -27,15 +27,27 @@ struct aarch64_features { /* A non zero VQ value indicates both the presence of SVE and the - Vector Quotient - the number of 128bit chunks in an SVE Z - register. */ - uint64_t vq = 0; + Vector Quotient - the number of 128-bit chunks in an SVE Z + register. + The maximum value for VQ is 16 (5 bits). */ + uint64_t vq = 0; bool pauth = false; bool mte = false; /* A positive TLS value indicates the number of TLS registers available. */ uint8_t tls = 0; + /* The allowed values for SVQ are the following: + + 0 - SME is not supported/available. + 1 - SME is available, SVL is 16 bytes / 128-bit. + 2 - SME is available, SVL is 32 bytes / 256-bit. + 4 - SME is available, SVL is 64 bytes / 512-bit. + 8 - SME is available, SVL is 128 bytes / 1024-bit. + 16 - SME is available, SVL is 256 bytes / 2048-bit. + + These use at most 5 bits to represent. */ + uint8_t svq = 0; }; inline bool operator==(const aarch64_features &lhs, const aarch64_features &rhs) @@ -43,7 +55,8 @@ inline bool operator==(const aarch64_features &lhs, const aarch64_features &rhs) return lhs.vq == rhs.vq && lhs.pauth == rhs.pauth && lhs.mte == rhs.mte - && lhs.tls == rhs.tls; + && lhs.tls == rhs.tls + && lhs.svq == rhs.svq; } namespace std @@ -61,6 +74,11 @@ namespace std /* Shift by two bits for now. We may need to increase this in the future if more TLS registers get added. */ h = h << 2 | features.tls; + + /* Make sure the SVQ values are within the limits. */ + gdb_assert (features.svq >= 0); + gdb_assert (features.svq <= 16); + h = h << 5 | (features.svq & 0x5); return h; } }; @@ -171,4 +189,35 @@ enum aarch64_regnum /* Maximum supported VQ value. Increase if required. */ #define AARCH64_MAX_SVE_VQ 16 +/* SME definitions + + Some of these definitions are not found in the Architecture Reference + Manual, but we use them so we can keep a similar standard compared to the + SVE definitions that the Linux Kernel uses. Otherwise it can get + confusing. + + SVL : Streaming Vector Length. + Although the documentation handles SVL in bits, we do it in + bytes to match what we do for SVE. + + The streaming vector length dictates the size of the ZA register and + the size of the SVE registers when in streaming mode. + + SVQ : Streaming Vector Quotient. + The number of 128-bit chunks in an SVE Z register or the size of + each dimension of the SME ZA matrix. + + SVG : Streaming Vector Granule. + The number of 64-bit chunks in an SVE Z register or the size of + half a SME ZA matrix dimension. The SVG definition was added so + we keep a familiar definition when dealing with SVE registers in + streaming mode. */ + +/* The total number of tiles. This is always fixed regardless of the + streaming vector length (svl). */ +#define AARCH64_ZA_TILES_NUM 31 +/* svl limits for SME. */ +#define AARCH64_SME_MIN_SVL 128 +#define AARCH64_SME_MAX_SVL 2048 + #endif /* ARCH_AARCH64_H */ diff --git a/gdb/configure.tgt b/gdb/configure.tgt index d5b7dd1e7d7..47a674201f9 100644 --- a/gdb/configure.tgt +++ b/gdb/configure.tgt @@ -146,6 +146,7 @@ aarch64*-*-linux*) # Target: AArch64 linux gdb_target_obs="aarch64-linux-tdep.o arch/aarch64.o\ arch/aarch64-mte-linux.o \ + arch/aarch64-scalable-linux.o \ arch/arm.o arch/arm-linux.o arch/arm-get-next-pcs.o \ arm-tdep.o arm-linux-tdep.o \ glibc-tdep.o linux-tdep.o solib-svr4.o \ diff --git a/gdb/features/aarch64-sme.c b/gdb/features/aarch64-sme.c new file mode 100644 index 00000000000..697a3014093 --- /dev/null +++ b/gdb/features/aarch64-sme.c @@ -0,0 +1,63 @@ +/* Copyright (C) 2023 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "gdbsupport/tdesc.h" +#include + +/* This function is NOT auto generated from xml. Create the AArch64 SME + feature into RESULT. SVL is the streaming vector length in bytes. + + The ZA register has a total size of SVL x SVL. + + When in Streaming SVE mode, the effective SVE vector length, VL, is equal + to SVL. */ + +static int +create_feature_aarch64_sme (struct target_desc *result, long regnum, + size_t svl) +{ + struct tdesc_feature *feature; + tdesc_type *element_type; + + feature = tdesc_create_feature (result, "org.gnu.gdb.aarch64.sme"); + + /* The SVG register. */ + tdesc_create_reg (feature, "svg", regnum++, 1, nullptr, 64, "int"); + + /* SVCR flags type. */ + tdesc_type_with_fields *type_with_fields + = tdesc_create_flags (feature, "svcr_flags", 8); + tdesc_add_flag (type_with_fields, 0, "SM"); + tdesc_add_flag (type_with_fields, 1, "ZA"); + + /* The SVCR register. */ + tdesc_create_reg (feature, "svcr", regnum++, 1, nullptr, 64, "svcr_flags"); + + /* Byte type. */ + element_type = tdesc_named_type (feature, "uint8"); + /* Vector of bytes. */ + element_type = tdesc_create_vector (feature, "sme_bv", element_type, + svl); + /* Vector of vector of bytes (Matrix). */ + element_type = tdesc_create_vector (feature, "sme_bvv", element_type, + svl); + + /* The following is the ZA register set. */ + tdesc_create_reg (feature, "za", regnum++, 1, nullptr, + std::pow (svl, 2) * 8, "sme_bvv"); + return regnum; +} diff --git a/gdb/nat/aarch64-scalable-linux-ptrace.c b/gdb/nat/aarch64-scalable-linux-ptrace.c index 6eea9104cef..d3a50ed0c81 100644 --- a/gdb/nat/aarch64-scalable-linux-ptrace.c +++ b/gdb/nat/aarch64-scalable-linux-ptrace.c @@ -1,5 +1,4 @@ -/* Common target dependent routines for AArch64 Scalable Extensions - (SVE/SME). +/* Common native Linux code for the AArch64 scalable extensions: SVE and SME. Copyright (C) 2018-2023 Free Software Foundation, Inc. @@ -28,6 +27,193 @@ #include "gdbsupport/common-regcache.h" #include "gdbsupport/byte-vector.h" #include +#include "arch/aarch64-scalable-linux.h" + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +aarch64_has_sve_state (int tid) +{ + struct user_sve_header header; + + if (!read_sve_header (tid, header)) + return false; + + if ((header.flags & SVE_PT_REGS_SVE) == 0) + return false; + + if (sizeof (header) == header.size) + return false; + + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +aarch64_has_ssve_state (int tid) +{ + struct user_sve_header header; + + if (!read_ssve_header (tid, header)) + return false; + + if ((header.flags & SVE_PT_REGS_SVE) == 0) + return false; + + if (sizeof (header) == header.size) + return false; + + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +aarch64_has_za_state (int tid) +{ + struct user_za_header header; + + if (!read_za_header (tid, header)) + return false; + + if (sizeof (header) == header.size) + return false; + + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +read_sve_header (int tid, struct user_sve_header &header) +{ + struct iovec iovec; + + iovec.iov_len = sizeof (header); + iovec.iov_base = &header; + + if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0) + { + /* SVE is not supported. */ + return false; + } + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +write_sve_header (int tid, const struct user_sve_header &header) +{ + struct iovec iovec; + + iovec.iov_len = sizeof (header); + iovec.iov_base = (void *) &header; + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_SVE, &iovec) < 0) + { + /* SVE is not supported. */ + return false; + } + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +read_ssve_header (int tid, struct user_sve_header &header) +{ + struct iovec iovec; + + iovec.iov_len = sizeof (header); + iovec.iov_base = &header; + + if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SSVE, &iovec) < 0) + { + /* SSVE is not supported. */ + return false; + } + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +write_ssve_header (int tid, const struct user_sve_header &header) +{ + struct iovec iovec; + + iovec.iov_len = sizeof (header); + iovec.iov_base = (void *) &header; + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_SSVE, &iovec) < 0) + { + /* SSVE is not supported. */ + return false; + } + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +read_za_header (int tid, struct user_za_header &header) +{ + struct iovec iovec; + + iovec.iov_len = sizeof (header); + iovec.iov_base = &header; + + if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_ZA, &iovec) < 0) + { + /* ZA is not supported. */ + return false; + } + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +write_za_header (int tid, const struct user_za_header &header) +{ + struct iovec iovec; + + iovec.iov_len = sizeof (header); + iovec.iov_base = (void *) &header; + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_ZA, &iovec) < 0) + { + /* ZA is not supported. */ + return false; + } + return true; +} + +/* Given VL, the streaming vector length for SME, return true if it is valid + and false otherwise. */ + +static bool +aarch64_sme_vl_valid (size_t vl) +{ + return (vl == 16 || vl == 32 || vl == 64 || vl == 128 || vl == 256); +} + +/* Given VL, the vector length for SVE, return true if it is valid and false + otherwise. SVE_state is true when the check is for the SVE register set. + Otherwise the check is for the SSVE register set. */ + +static bool +aarch64_sve_vl_valid (const bool sve_state, size_t vl) +{ + if (sve_state) + return sve_vl_valid (vl); + + /* We have an active SSVE state, where the valid vector length values are + more restrictive. */ + return aarch64_sme_vl_valid (vl); +} /* See nat/aarch64-scalable-linux-ptrace.h. */ @@ -36,23 +222,25 @@ aarch64_sve_get_vq (int tid) { struct iovec iovec; struct user_sve_header header; - iovec.iov_len = sizeof (header); iovec.iov_base = &header; - /* Ptrace gives the vector length in bytes. Convert it to VQ, the number of - 128bit chunks in a Z register. We use VQ because 128bits is the minimum - a Z register can increase in size. */ - - if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0) + /* Figure out which register set to use for the request. The vector length + for SVE can be different from the vector length for SSVE. */ + bool has_sve_state = !aarch64_has_ssve_state (tid); + if (ptrace (PTRACE_GETREGSET, tid, has_sve_state? NT_ARM_SVE : NT_ARM_SSVE, + &iovec) < 0) { /* SVE is not supported. */ return 0; } + /* Ptrace gives the vector length in bytes. Convert it to VQ, the number of + 128bit chunks in a Z register. We use VQ because 128 bits is the minimum + a Z register can increase in size. */ uint64_t vq = sve_vq_from_vl (header.vl); - if (!sve_vl_valid (header.vl)) + if (!aarch64_sve_vl_valid (has_sve_state, header.vl)) { warning (_("Invalid SVE state from kernel; SVE disabled.")); return 0; @@ -72,15 +260,20 @@ aarch64_sve_set_vq (int tid, uint64_t vq) iovec.iov_len = sizeof (header); iovec.iov_base = &header; - if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0) + /* Figure out which register set to use for the request. The vector length + for SVE can be different from the vector length for SSVE. */ + bool has_sve_state = !aarch64_has_ssve_state (tid); + if (ptrace (PTRACE_GETREGSET, tid, has_sve_state? NT_ARM_SVE : NT_ARM_SSVE, + &iovec) < 0) { - /* SVE is not supported. */ + /* SVE/SSVE is not supported. */ return false; } header.vl = sve_vl_from_vq (vq); - if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_SVE, &iovec) < 0) + if (ptrace (PTRACE_SETREGSET, tid, has_sve_state? NT_ARM_SVE : NT_ARM_SSVE, + &iovec) < 0) { /* Vector length change failed. */ return false; @@ -120,13 +313,108 @@ aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf) /* See nat/aarch64-scalable-linux-ptrace.h. */ +uint64_t +aarch64_za_get_svq (int tid) +{ + struct user_za_header header; + if (!read_za_header (tid, header)) + return 0; + + uint64_t vq = sve_vq_from_vl (header.vl); + + if (!aarch64_sve_vl_valid (false, header.vl)) + { + warning (_("Invalid ZA state from kernel; ZA disabled.")); + return 0; + } + + return vq; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +aarch64_za_set_svq (int tid, uint64_t vq) +{ + struct iovec iovec; + + /* Read the NT_ARM_ZA header. */ + struct user_za_header header; + if (!read_za_header (tid, header)) + { + /* ZA is not supported. */ + return false; + } + + /* If the size is the correct one already, don't update it. If we do + update the streaming vector length, we will invalidate the register + state for ZA, and we do not want that. */ + if (header.vl == sve_vl_from_vq (vq)) + return true; + + /* The streaming vector length is about to get updated. Set the new value + in the NT_ARM_ZA header and adjust the size as well. */ + + header.vl = sve_vl_from_vq (vq); + header.size = sizeof (struct user_za_header); + + /* Update the NT_ARM_ZA register set with the new streaming vector + length. */ + iovec.iov_len = sizeof (header); + iovec.iov_base = &header; + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_ZA, &iovec) < 0) + { + /* Streaming vector length change failed. */ + return false; + } + + /* At this point we have successfully adjusted the streaming vector length + for the NT_ARM_ZA register set, and it should have no payload + (no ZA state). */ + + return true; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +bool +aarch64_za_set_svq (int tid, const struct reg_buffer_common *reg_buf, + int svg_regnum) +{ + uint64_t reg_svg = 0; + + /* The svg register may not be valid if we've not collected any value yet. + This can happen, for example, if we're restoring the regcache after an + inferior function call, and the svg register comes after the Z + registers. */ + if (reg_buf->get_register_status (svg_regnum) != REG_VALID) + { + /* If svg is not available yet, fetch it from ptrace. The svg value from + ptrace is likely the correct one. */ + uint64_t svq = aarch64_za_get_svq (tid); + + /* If something went wrong, just bail out. */ + if (svq == 0) + return false; + + reg_svg = sve_vg_from_vq (svq); + } + else + reg_buf->raw_collect (svg_regnum, ®_svg); + + return aarch64_za_set_svq (tid, sve_vq_from_vg (reg_svg)); +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + gdb::byte_vector aarch64_fetch_sve_regset (int tid) { uint64_t vq = aarch64_sve_get_vq (tid); if (vq == 0) - perror_with_name (_("Unable to fetch SVE vector length")); + perror_with_name (_("Unable to fetch SVE/SSVE vector length")); /* A ptrace call with NT_ARM_SVE will return a header followed by either a dump of all the SVE and FP registers, or an fpsimd structure (identical to @@ -139,8 +427,10 @@ aarch64_fetch_sve_regset (int tid) iovec.iov_base = sve_state.data (); iovec.iov_len = sve_state.size (); - if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_SVE, &iovec) < 0) - perror_with_name (_("Unable to fetch SVE registers")); + bool has_sve_state = !aarch64_has_ssve_state (tid); + if (ptrace (PTRACE_GETREGSET, tid, has_sve_state? NT_ARM_SVE : NT_ARM_SSVE, + &iovec) < 0) + perror_with_name (_("Unable to fetch SVE/SSVE registers")); return sve_state; } @@ -155,8 +445,82 @@ aarch64_store_sve_regset (int tid, const gdb::byte_vector &sve_state) iovec.iov_base = (void *) sve_state.data (); iovec.iov_len = sve_state.size (); - if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_SVE, &iovec) < 0) - perror_with_name (_("Unable to store SVE registers")); + bool has_sve_state = !aarch64_has_ssve_state (tid); + if (ptrace (PTRACE_SETREGSET, tid, has_sve_state? NT_ARM_SVE : NT_ARM_SSVE, + &iovec) < 0) + perror_with_name (_("Unable to store SVE/SSVE registers")); +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +gdb::byte_vector +aarch64_fetch_za_regset (int tid) +{ + struct user_za_header header; + if (!read_za_header (tid, header)) + error (_("Failed to read NT_ARM_ZA header.")); + + if (!aarch64_sme_vl_valid (header.vl)) + error (_("Found invalid vector length for NT_ARM_ZA.")); + + struct iovec iovec; + iovec.iov_len = header.size; + gdb::byte_vector za_state (header.size); + iovec.iov_base = za_state.data (); + + if (ptrace (PTRACE_GETREGSET, tid, NT_ARM_ZA, &iovec) < 0) + perror_with_name (_("Failed to fetch NT_ARM_ZA register set.")); + + return za_state; +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +void +aarch64_store_za_regset (int tid, const gdb::byte_vector &za_state) +{ + struct iovec iovec; + /* We need to cast from (const void *) here. */ + iovec.iov_base = (void *) za_state.data (); + iovec.iov_len = za_state.size (); + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_ZA, &iovec) < 0) + perror_with_name (_("Failed to write to the NT_ARM_ZA register set.")); +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +void +aarch64_initialize_za_regset (int tid) +{ + /* First fetch the NT_ARM_ZA header so we can fetch the streaming vector + length. */ + struct user_za_header header; + if (!read_za_header (tid, header)) + error (_("Failed to read NT_ARM_ZA header.")); + + /* The vector should be default-initialized to zero, and we should account + for the payload as well. */ + std::vector za_new_state (ZA_PT_SIZE (sve_vq_from_vl (header.vl))); + + /* Adjust the header size since we are adding the initialized ZA + payload. */ + header.size = ZA_PT_SIZE (sve_vq_from_vl (header.vl)); + + /* Overlay the modified header onto the new ZA state. */ + const gdb_byte *base = (gdb_byte *) &header; + memcpy (za_new_state.data (), base, sizeof (user_za_header)); + + /* Set the ptrace request up and update the NT_ARM_ZA register set. */ + struct iovec iovec; + iovec.iov_len = za_new_state.size (); + iovec.iov_base = za_new_state.data (); + + if (ptrace (PTRACE_SETREGSET, tid, NT_ARM_ZA, &iovec) < 0) + perror_with_name (_("Failed to initialize the NT_ARM_ZA register set.")); + + /* The NT_ARM_ZA register set should now contain a zero-initialized ZA + payload. */ } /* If we are running in BE mode, byteswap the contents @@ -451,3 +815,177 @@ aarch64_sve_regs_copy_from_reg_buf (int tid, passed on to ptrace. */ aarch64_store_sve_regset (tid, new_state); } + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +void +aarch64_za_regs_copy_to_reg_buf (int tid, struct reg_buffer_common *reg_buf, + int za_regnum, int svg_regnum, + int svcr_regnum) +{ + /* Fetch the current ZA state from the thread. */ + gdb::byte_vector za_state = aarch64_fetch_za_regset (tid); + + /* Sanity check. */ + gdb_assert (!za_state.empty ()); + + char *base = (char *) za_state.data (); + struct user_za_header *header = (struct user_za_header *) base; + + /* If we have ZA state, read it. Otherwise, make the contents of ZA + in the register cache all zeroes. This is how we present the ZA + state when it is not initialized. */ + uint64_t svcr_value = 0; + if (aarch64_has_za_state (tid)) + { + /* Sanity check the data in the header. */ + if (!sve_vl_valid (header->vl) + || ZA_PT_SIZE (sve_vq_from_vl (header->vl)) != header->size) + { + error (_("Found invalid streaming vector length in NT_ARM_ZA" + " register set")); + } + + reg_buf->raw_supply (za_regnum, base + ZA_PT_ZA_OFFSET); + svcr_value |= SVCR_ZA_BIT; + } + else + { + size_t za_bytes = header->vl * header->vl; + gdb_byte za_zeroed[za_bytes]; + memset (za_zeroed, 0, za_bytes); + reg_buf->raw_supply (za_regnum, za_zeroed); + } + + /* Handle the svg and svcr registers separately. We need to calculate + their values manually, as the Linux Kernel doesn't expose those + explicitly. */ + svcr_value |= aarch64_has_ssve_state (tid)? SVCR_SM_BIT : 0; + uint64_t svg_value = sve_vg_from_vl (header->vl); + + /* Update the contents of svg and svcr registers. */ + reg_buf->raw_supply (svg_regnum, &svg_value); + reg_buf->raw_supply (svcr_regnum, &svcr_value); + + /* The register buffer should now contain the updated copy of the NT_ARM_ZA + state. */ +} + +/* See nat/aarch64-scalable-linux-ptrace.h. */ + +void +aarch64_za_regs_copy_from_reg_buf (int tid, + struct reg_buffer_common *reg_buf, + int za_regnum, int svg_regnum, + int svcr_regnum) +{ + /* REG_BUF contains the updated ZA state. We need to extract that state + and write it to the thread TID. */ + + + /* First check if there is a change to the streaming vector length. Two + outcomes are possible here: + + 1 - The streaming vector length in the register cache differs from the + one currently on the thread state. This means that we will need to + update the NT_ARM_ZA register set to reflect the new streaming vector + length. + + 2 - The streaming vector length in the register cache is the same as in + the thread state. This means we do not need to update the NT_ARM_ZA + register set for a new streaming vector length, and we only need to + deal with changes to za, svg and svcr. + + None of the two possibilities above imply that the ZA state actually + exists. They only determine what needs to be done with any ZA content + based on the state of the streaming vector length. */ + + /* First fetch the NT_ARM_ZA header so we can fetch the streaming vector + length. */ + struct user_za_header header; + if (!read_za_header (tid, header)) + error (_("Failed to read NT_ARM_ZA header.")); + + /* Fetch the current streaming vector length. */ + uint64_t old_svg = sve_vg_from_vl (header.vl); + + /* Fetch the (potentially) new streaming vector length. */ + uint64_t new_svg; + reg_buf->raw_collect (svg_regnum, &new_svg); + + /* Did the streaming vector length change? */ + bool svg_changed = new_svg != old_svg; + + /* First store the streaming vector length to the thread. This is done + first to ensure the ptrace buffers read from the kernel are the correct + size. If the streaming vector length is the same as the current one, it + won't be updated. */ + if (!aarch64_za_set_svq (tid, reg_buf, svg_regnum)) + error (_("Unable to set svg register")); + + bool has_za_state = aarch64_has_za_state (tid); + + size_t za_bytes = sve_vl_from_vg (old_svg) * sve_vl_from_vg (old_svg); + gdb_byte za_zeroed[za_bytes]; + memset (za_zeroed, 0, za_bytes); + + /* If the streaming vector length changed, zero out the contents of ZA in + the register cache. Otherwise, we will need to update the ZA contents + in the thread with the ZA contents from the register cache, and they will + differ in size. */ + if (svg_changed) + reg_buf->raw_supply (za_regnum, za_zeroed); + + /* When we update svg, we don't automatically initialize the ZA buffer. If + we have no ZA state and the ZA register contents in the register cache are + zero, just return and leave the ZA register cache contents as zero. */ + if (!has_za_state + && reg_buf->raw_compare (za_regnum, za_zeroed, 0)) + { + /* No ZA state in the thread or in the register cache. This was likely + just an adjustment of the streaming vector length. Let this fall + through and update svcr and svg in the register cache. */ + } + else + { + /* If there is no ZA state but the register cache contains ZA data, we + need to initialize the ZA data through ptrace. First we initialize + all the bytes of ZA to zero. */ + if (!has_za_state + && !reg_buf->raw_compare (za_regnum, za_zeroed, 0)) + aarch64_initialize_za_regset (tid); + + /* From this point onwards, it is assumed we have a ZA payload in + the NT_ARM_ZA register set for this thread, and we need to update + such state based on the contents of the register cache. */ + + /* Fetch the current ZA state from the thread. */ + gdb::byte_vector za_state = aarch64_fetch_za_regset (tid); + + char *base = (char *) za_state.data (); + struct user_za_header *za_header = (struct user_za_header *) base; + uint64_t svq = sve_vq_from_vl (za_header->vl); + + /* Sanity check the data in the header. */ + if (!sve_vl_valid (za_header->vl) + || ZA_PT_SIZE (svq) != za_header->size) + error (_("Invalid vector length or payload size when reading ZA.")); + + /* Overwrite the ZA state contained in the thread with the ZA state from + the register cache. */ + if (REG_VALID == reg_buf->get_register_status (za_regnum)) + reg_buf->raw_collect (za_regnum, base + ZA_PT_ZA_OFFSET); + + /* Write back the ZA state to the thread's NT_ARM_ZA register set. */ + aarch64_store_za_regset (tid, za_state); + } + + /* Update svcr and svg accordingly. */ + uint64_t svcr_value = 0; + svcr_value |= aarch64_has_ssve_state (tid)? SVCR_SM_BIT : 0; + svcr_value |= aarch64_has_za_state (tid)? SVCR_ZA_BIT : 0; + reg_buf->raw_supply (svcr_regnum, &svcr_value); + + /* At this point we have written the data contained in the register cache to + the thread's NT_ARM_ZA register set. */ +} diff --git a/gdb/nat/aarch64-scalable-linux-ptrace.h b/gdb/nat/aarch64-scalable-linux-ptrace.h index 167782c493d..d609933801d 100644 --- a/gdb/nat/aarch64-scalable-linux-ptrace.h +++ b/gdb/nat/aarch64-scalable-linux-ptrace.h @@ -1,5 +1,5 @@ -/* Common target dependent definitions for AArch64 Scalable Extensions - (SVE/SME). +/* Common native Linux definitions for the AArch64 scalable + extensions: SVE and SME. Copyright (C) 2018-2023 Free Software Foundation, Inc. @@ -31,19 +31,58 @@ result when is included before . */ #include #include - -#ifndef SVE_SIG_ZREGS_SIZE +#include +#include "aarch64-scalable-linux-ptrace.h" #include "aarch64-scalable-linux-sigcontext.h" -#endif /* Indicates whether a SVE ptrace header is followed by SVE registers or a fpsimd structure. */ - #define HAS_SVE_STATE(header) ((header).flags & SVE_PT_REGS_SVE) +/* Return true if there is an active SVE state in TID. + Return false otherwise. */ +bool aarch64_has_sve_state (int tid); + +/* Return true if there is an active SSVE state in TID. + Return false otherwise. */ +bool aarch64_has_ssve_state (int tid); + +/* Return true if there is an active ZA state in TID. + Return false otherwise. */ +bool aarch64_has_za_state (int tid); + +/* Given TID, read the SVE header into HEADER. + + Return true if successful, false otherwise. */ +bool read_sve_header (int tid, struct user_sve_header &header); + +/* Given TID, store the SVE HEADER. + + Return true if successful, false otherwise. */ +bool write_sve_header (int tid, const struct user_sve_header &header); + +/* Given TID, read the SSVE header into HEADER. + + Return true if successful, false otherwise. */ +bool read_ssve_header (int tid, struct user_sve_header &header); + +/* Given TID, store the SSVE HEADER. + + Return true if successful, false otherwise. */ +bool write_ssve_header (int tid, const struct user_sve_header &header); + +/* Given TID, read the ZA header into HEADER. + + Return true if successful, false otherwise. */ +bool read_za_header (int tid, struct user_za_header &header); + +/* Given TID, store the ZA HEADER. + + Return true if successful, false otherwise. */ +bool write_za_header (int tid, const struct user_za_header &header); + /* Read VQ for the given tid using ptrace. If SVE is not supported then zero is returned (on a system that supports SVE, then VQ cannot be zero). */ - uint64_t aarch64_sve_get_vq (int tid); /* Set VQ in the kernel for the given tid, using either the value VQ or @@ -52,27 +91,64 @@ uint64_t aarch64_sve_get_vq (int tid); bool aarch64_sve_set_vq (int tid, uint64_t vq); bool aarch64_sve_set_vq (int tid, struct reg_buffer_common *reg_buf); -/* Read the current SVE register set from thread TID and return its data - through a byte vector. */ +/* Read the streaming mode vq (svq) for the given TID. If the ZA state is not + supported or active, return 0. */ +uint64_t aarch64_za_get_svq (int tid); + +/* Set the vector quotient (vq) in the kernel for the given TID using the + value VQ. + Return true if successful, false otherwise. */ +bool aarch64_za_set_svq (int tid, uint64_t vq); +bool aarch64_za_set_svq (int tid, const struct reg_buffer_common *reg_buf, + int svg_regnum); + +/* Given TID, return the SVE/SSVE data as a vector of bytes. */ extern gdb::byte_vector aarch64_fetch_sve_regset (int tid); -/* Write the SVE contents from SVE_STATE to thread TID. */ +/* Write the SVE/SSVE contents from SVE_STATE to TID. */ +extern void aarch64_store_sve_regset (int tid, + const gdb::byte_vector &sve_state); -extern void -aarch64_store_sve_regset (int tid, const gdb::byte_vector &sve_state); +/* Given TID, return the ZA data as a vector of bytes. */ +extern gdb::byte_vector aarch64_fetch_za_regset (int tid); -/* Given a thread id TID and a register buffer REG_BUF, update the register - buffer with the SVE state from thread TID. */ +/* Write ZA_STATE for TID. */ +extern void aarch64_store_za_regset (int tid, const gdb::byte_vector &za_state); +/* Given TID, initialize the ZA register set so the header contains the right + size. The bytes of the ZA register are initialized to zero. */ +extern void aarch64_initialize_za_regset (int tid); + +/* Given a register buffer REG_BUF, update it with SVE/SSVE register data + from SVE_STATE. */ extern void aarch64_sve_regs_copy_to_reg_buf (int tid, struct reg_buffer_common *reg_buf); -/* Given a thread id TID and a register buffer REG_BUF containing SVE +/* Given a thread id TID and a register buffer REG_BUF containing SVE/SSVE register data, write the SVE data to thread TID. */ - extern void aarch64_sve_regs_copy_from_reg_buf (int tid, struct reg_buffer_common *reg_buf); +/* Given a thread id TID and a register buffer REG_BUF, update the register + buffer with the ZA state from thread TID. + + ZA_REGNUM, SVG_REGNUM and SVCR_REGNUM are the register numbers for ZA, + SVG and SVCR registers. */ +extern void aarch64_za_regs_copy_to_reg_buf (int tid, + struct reg_buffer_common *reg_buf, + int za_regnum, int svg_regnum, + int svcr_regnum); + +/* Given a thread id TID and a register buffer REG_BUF containing ZA register + data, write the ZA data to thread TID. + + ZA_REGNUM, SVG_REGNUM and SVCR_REGNUM are the register numbers for ZA, + SVG and SVCR registers. */ +extern void +aarch64_za_regs_copy_from_reg_buf (int tid, + struct reg_buffer_common *reg_buf, + int za_regnum, int svg_regnum, + int svcr_regnum); #endif /* NAT_AARCH64_SCALABLE_LINUX_PTRACE_H */ diff --git a/gdb/nat/aarch64-scalable-linux-sigcontext.h b/gdb/nat/aarch64-scalable-linux-sigcontext.h index e0120e093a0..74407bd266a 100644 --- a/gdb/nat/aarch64-scalable-linux-sigcontext.h +++ b/gdb/nat/aarch64-scalable-linux-sigcontext.h @@ -22,8 +22,11 @@ #ifndef NAT_AARCH64_SCALABLE_LINUX_SIGCONTEXT_H #define NAT_AARCH64_SCALABLE_LINUX_SIGCONTEXT_H +#ifndef SVE_SIG_ZREGS_SIZE + #define SVE_MAGIC 0x53564501 + struct sve_context { struct _aarch64_ctx head; __u16 vl; @@ -132,7 +135,7 @@ struct sve_context { #define SVE_SIG_CONTEXT_SIZE(vq) (SVE_SIG_REGS_OFFSET + SVE_SIG_REGS_SIZE(vq)) -/* SVE/FP/SIMD state (NT_ARM_SVE) */ +/* SVE/FP/SIMD state (NT_ARM_SVE and NT_ARM_SSVE) */ struct user_sve_header { __u32 size; /* total meaningful regset content in bytes */ @@ -242,6 +245,7 @@ struct user_sve_header { (SVE_PT_SVE_PREG_OFFSET(vq, SVE_NUM_PREGS) - \ SVE_PT_SVE_PREGS_OFFSET(vq)) +/* For streaming mode SVE (SSVE) FFR must be read and written as zero. */ #define SVE_PT_SVE_FFR_OFFSET(vq) \ __SVE_SIG_TO_PT(SVE_SIG_FFR_OFFSET(vq)) @@ -267,4 +271,55 @@ struct user_sve_header { SVE_PT_SVE_OFFSET + SVE_PT_SVE_SIZE(vq, flags) \ : SVE_PT_FPSIMD_OFFSET + SVE_PT_FPSIMD_SIZE(vq, flags)) +#endif /* SVE_SIG_ZREGS_SIZE */ + +/* Scalable Matrix Extensions (SME) definitions. */ + +/* Make sure we only define these if the kernel header doesn't. */ +#ifndef ZA_PT_SIZE + +/* ZA state (NT_ARM_ZA) */ +struct user_za_header { + __u32 size; /* total meaningful regset content in bytes */ + __u32 max_size; /* maximum possible size for this thread */ + __u16 vl; /* current vector length */ + __u16 max_vl; /* maximum possible vector length */ + __u16 flags; + __u16 __reserved; +}; + +/* The remainder of the ZA state follows struct user_za_header. The + total size of the ZA state (including header) depends on the + metadata in the header: ZA_PT_SIZE(vq, flags) gives the total size + of the state in bytes, including the header. + + Refer to arch/arm64/include/uapi/asm/sigcontext.h from the Linux kernel + for details of how to pass the correct "vq" argument to these macros. */ + +/* Offset from the start of struct user_za_header to the register data */ +#define ZA_PT_ZA_OFFSET \ + ((sizeof (struct user_za_header) + (__SVE_VQ_BYTES - 1)) \ + / __SVE_VQ_BYTES * __SVE_VQ_BYTES) + +/* The payload starts at offset ZA_PT_ZA_OFFSET, and is of size + ZA_PT_ZA_SIZE(vq, flags). + + The ZA array is stored as a sequence of horizontal vectors ZAV of SVL/8 + bytes each, starting from vector 0. + + Additional data might be appended in the future. + + The ZA matrix is represented in memory in an endianness-invariant layout + which differs from the layout used for the FPSIMD V-registers on big-endian + systems: see sigcontext.h for more explanation. */ + +#define ZA_PT_ZAV_OFFSET(vq, n) \ + (ZA_PT_ZA_OFFSET + ((vq * __SVE_VQ_BYTES) * n)) + +#define ZA_PT_ZA_SIZE(vq) ((vq * __SVE_VQ_BYTES) * (vq * __SVE_VQ_BYTES)) + +#define ZA_PT_SIZE(vq) \ + (ZA_PT_ZA_OFFSET + ZA_PT_ZA_SIZE(vq)) +#endif /* ZA_PT_SIZE */ + #endif /* NAT_AARCH64_SCALABLE_LINUX_SIGCONTEXT_H */ diff --git a/gdbserver/configure.srv b/gdbserver/configure.srv index 7a7575ac43b..9e861a75088 100644 --- a/gdbserver/configure.srv +++ b/gdbserver/configure.srv @@ -49,6 +49,7 @@ case "${gdbserver_host}" in srv_tgtobj="$srv_tgtobj arch/aarch64-insn.o" srv_tgtobj="$srv_tgtobj arch/aarch64.o" srv_tgtobj="$srv_tgtobj arch/aarch64-mte-linux.o" + srv_tgtobj="$srv_tgtobj arch/aarch64-scalable-linux.o" srv_tgtobj="$srv_tgtobj linux-aarch64-tdesc.o" srv_tgtobj="$srv_tgtobj nat/aarch64-mte-linux-ptrace.o" srv_tgtobj="$srv_tgtobj nat/aarch64-scalable-linux-ptrace.o" From patchwork Mon Sep 18 21:26:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76319 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 2378B3860765 for ; Mon, 18 Sep 2023 21:29:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2378B3860765 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072552; bh=ZNSz36M2+AE+x9ujWcDhDu94gh0A7q2m79rI4JTM1S8=; 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=C4KCR0oeA9a5+hK2Q4nWYznkh00CORBOj4J49tRwnH0ha4aFBPwCQiXhXlWS03BXT A54EmEyv4xxvm9lc4QBTU9wHdJiedCK4kCF6P6PDQYRmrsPHEdOx5TQIN0nRg16MDF SZSTcURRvRHBpKTH/G1QYistwmqoeidOvG7yO4XU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2058.outbound.protection.outlook.com [40.107.20.58]) by sourceware.org (Postfix) with ESMTPS id CFF593857724 for ; Mon, 18 Sep 2023 21:27:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFF593857724 Received: from AS9PR04CA0160.eurprd04.prod.outlook.com (2603:10a6:20b:530::28) by AS2PR08MB8806.eurprd08.prod.outlook.com (2603:10a6:20b:5f2::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.20; Mon, 18 Sep 2023 21:27:14 +0000 Received: from AM7EUR03FT036.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:530:cafe::1b) by AS9PR04CA0160.outlook.office365.com (2603:10a6:20b:530::28) 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: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 AM7EUR03FT036.mail.protection.outlook.com (100.127.140.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:13 +0000 Received: ("Tessian outbound 0b7d6027328f:v175"); Mon, 18 Sep 2023 21:27:13 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 55d4df9221705917 X-CR-MTA-TID: 64aa7808 Received: from 41dff4dd77a0.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C5CADACA-5CAA-41F5-9D9D-3F178B0EB38C.1; Mon, 18 Sep 2023 21:27:07 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 41dff4dd77a0.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZrmEzhUxuJL+Frfp1QcR/vLJmoLiQsuTCHrJEZXy4IdFcEV2NR8xziwoDEeOIXhtAOdZqfK3uUocrLAsbtPYh9r84/J3TVijTSVQJ7naRyf3dYRIlMMrJvv5iCbXMmIKo9ACSBEfHkJI7Bq93IbQuTFkFwFFih+rqbUHHvRLiJ/yINrF+UAcX/BBTG5olT8ifUMiceZo4FecyYlICSE/uuR9D3WB8H4QmO1ICa1XNwqaUbkcn+AKX0vBGgJTSPEYfuBWmSM0F88+U/n/sy1D4orlgmH10zWmoIOdnUxreXeQh/OFJahrgNkegEHDCi7/mmKQcyGGkPYBhu5zENhVYA== 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=ZNSz36M2+AE+x9ujWcDhDu94gh0A7q2m79rI4JTM1S8=; b=hb6NBCphGtOXCEzytqFJ139qD4lLvBGe2uXVUt6X7Uce7QDpb5Bm3CZ4vWFun8HeC2BdlSynmO2b0KxpX73JbuXC4+9eX3koVGgL9FsJ0g7MKWk44iNlzXeIpQRnCqq+T5u102uEXXyk+58UarkMpjksrSzxA9rrdN83WsW4GPsiZOXuO8tsreb5dcpxFKF/lpQqfc4d8dNSOIW8mUEypi29XOoIoHlk5vvmB4eLuXNI7A+QMRoL0P/2BVKAd06vLDhz+TV5VJnjGNPnWR63KyGYJKq1s8hbsyQ+DBIKz7Y+E4upFYYBIOfZxFLntWNA/F6Gbb3UneY88Gd4IGT2FQ== 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 AM6P193CA0127.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::32) by PAVPR08MB10331.eurprd08.prod.outlook.com (2603:10a6:102:32a::6) 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:04 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::14) by AM6P193CA0127.outlook.office365.com (2603:10a6:209:85::32) 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:04 +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:04 +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:03 +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:03 +0000 To: Subject: [PATCH v7 06/18] [gdbserver/generic] Convert tdesc's expedite_regs to a string vector Date: Mon, 18 Sep 2023 22:26:39 +0100 Message-ID: <20230918212651.660141-7-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_|PAVPR08MB10331:EE_|AM7EUR03FT036:EE_|AS2PR08MB8806:EE_ X-MS-Office365-Filtering-Correlation-Id: 3a1fbeef-3c11-4cb6-852e-08dbb88e06b6 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: 6apj1FCwP/dhW8e3g99A0uOvHikt8y1zmMShJCC4mQn0Z5gsXaX65e10wTOjyrVkff0MuNrVJi5MMKvwDpKn1DHzi5H6k96arY8/3iNyiNRZXF+Kz2MHiTMzXmdPwSTbtU7j8S/WYfGY1247f7Jm1cj2K9q0kkNF1HBOFvPcdny4TVhN4+S8pDFxU6xfjyjWTtEP9NKc8YhaPt0tSkjV7IRTWQzomdnxLOlZaeuckUvPpXC/NAC9VSC5YF3O8Mzqg5RUF0M6+ej5cXZIqKVnFwKgwmiCJwmgMF+jndwY4dSVK/8UKF1vjc9BE25fEwKGgtmqPU4RMde4Lz8Eo3qJI0+/xOFwzPjBJnLkbI+KN6CIjy0ppWmS/d5g3aEXNi3DpR/PvQ/2QPX4x5mFCKEYNCuN3UvYU+mM/cuRo5gj3Rwd6selCL7Hf9+qpsor6F6/u3thg7oyD8ythAeQpl64cjg3NeEB09OBwI0rpkHav76Sf7Fy48gi4Hv2wFWDnXyL4OPQGgEgj3cUD2xHylu/d9Sbwpzjtlc+avdFwFgh4QAhqz4qi7jbfnU69XEfoiIOqqC5cpvJ4pTiJlDRlnHfQl0m+AKfPsNujBRSFC7zNTtqWb9mNXxm/i48K/kfW5GPif3nv/553EyaUV5o6wUwjIJDt7EierkahsPgyztHLam0vnATPfkXKaVhJ6ifJn1yNw5N3QC8736mEDsSyKzM9mM0D+4ZFGtVXMD0Kqa5l/ZfbQ/+elMbTtyooYOqcnmxQq1tkEGHX/bRLtNJQZsW1yMzUe1uVG3WvVkApkXtY+E= 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)(346002)(396003)(376002)(136003)(39860400002)(451199024)(186009)(82310400011)(1800799009)(46966006)(40470700004)(36840700001)(478600001)(316002)(6916009)(44832011)(5660300002)(83380400001)(41300700001)(40480700001)(6666004)(2906002)(8936002)(8676002)(4326008)(70206006)(54906003)(70586007)(7696005)(26005)(40460700003)(1076003)(2616005)(426003)(336012)(36860700001)(47076005)(36756003)(356005)(81166007)(86362001)(82740400003)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB10331 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT036.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e637214e-41fe-44fd-4fbe-08dbb88e0139 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RxzS6CxnR9Qqc/JIFeZKqbFD01XFQo0vEiWwWGX2rtvj6JZ9BEuul2ApJme+6SZAOGcmUTHK41kZgaUQzGU4O+48hoOWiTaMZphssiUg5e65JeW3y3aEI0vnXdz8hWdLCQpmxGFBi4zxeUNfot4gQ2cks4pl8pufawGKuDUq36x9VbUSFDLSJRR4GRxP+M4QhMGyRRnChSUm/NFUuJMYAi4V8wXxibLLDJ/UP0xpox+ZJ8iUiYmGMv6H6miP5Vtvjv+UnLyMzVThyLupRodDSWF5f78HZ3zDi7J+hsWu4aXM7jfhtw5glYVV082P5xlmRqn4z8czqTCrCpZQfXn+1yX2mfSOUuFoitED6v6P6EvFrFIS7fKzSonnvavmcMhbjnX3Tw4xHHwJWa3WH9kb/uGTuBeUH1H27HkxRt/Dr/zyUM6FWN1iT3AlEUtvhOolPYvhMb2SZruMYk4v0g08wjQAnfKCjSt8ymg7oYJ7y0HSGsMWOE7OPpk5FDs70yxBPLoFC5YX/w/antWx72QRVZ1MLQHUWW/fMhLiaFTv/qN11YwZjQoTsS1mFkOpC2g3NYZKOcFl2VGEOosFqXhEv5XBseP51aSrLx7DJxI/1fK0Sw2v1UgbOfnqOf3mPIaiywtewpxvUO3e8Aajgi+K4kE2ZW2dHj7Jn9AHwB6cL0xzYlHbva2fY8gOh9sZKf2CNzGvuW+uEXr/5ji5HYvkvKB4lW2LY5AWE86XsKiHFa+kzAd+hAgobgixwIV6r9KvH5gf7JEO1yj99baDxzBl+g== 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)(136003)(346002)(376002)(396003)(39860400002)(1800799009)(82310400011)(186009)(451199024)(40470700004)(36840700001)(46966006)(26005)(40480700001)(40460700003)(316002)(2906002)(36860700001)(6666004)(47076005)(83380400001)(81166007)(6916009)(82740400003)(44832011)(5660300002)(4326008)(70206006)(54906003)(7696005)(426003)(336012)(41300700001)(8936002)(8676002)(107886003)(70586007)(2616005)(1076003)(478600001)(36756003)(86362001)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:13.9923 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a1fbeef-3c11-4cb6-852e-08dbb88e06b6 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: AM7EUR03FT036.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8806 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" Right now the list of expedited registers is stored as an array of char *, with a nullptr element at the end to signal its last element. Convert expedite_regs to a std::vector of std::string so it is easier to manage the elements and the storage is handled automatically. Eventually we might want to convert all the target functions so they pass a std::vector of std::string as well. Or maybe expose an interface that target can use to add expedited registers on-by-one depending on the target description discovery needs, as opposed to just a static list of char *. Reviewed-by: Thiago Jung Bauermann Approved-By: Tom Tromey --- gdbserver/remote-utils.cc | 13 +++++-------- gdbserver/tdesc.cc | 23 ++++++++++++++--------- gdbserver/tdesc.h | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/gdbserver/remote-utils.cc b/gdbserver/remote-utils.cc index 722915d30f2..fb5c38d4522 100644 --- a/gdbserver/remote-utils.cc +++ b/gdbserver/remote-utils.cc @@ -1068,7 +1068,6 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status) case TARGET_WAITKIND_SYSCALL_ENTRY: case TARGET_WAITKIND_SYSCALL_RETURN: { - const char **regp; struct regcache *regcache; char *buf_start = buf; @@ -1155,8 +1154,6 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status) switch_to_thread (the_target, ptid); - regp = current_target_desc ()->expedite_regs; - regcache = get_thread_regcache (current_thread, 1); if (the_target->stopped_by_watchpoint ()) @@ -1188,11 +1185,11 @@ prepare_resume_reply (char *buf, ptid_t ptid, const target_waitstatus &status) buf += strlen (buf); } - while (*regp) - { - buf = outreg (regcache, find_regno (regcache->tdesc, *regp), buf); - regp ++; - } + /* Handle the expedited registers. */ + for (const std::string &expedited_reg : + current_target_desc ()->expedite_regs) + buf = outreg (regcache, find_regno (regcache->tdesc, + expedited_reg.c_str ()), buf); *buf = '\0'; /* Formerly, if the debugger had not used any thread features diff --git a/gdbserver/tdesc.cc b/gdbserver/tdesc.cc index 2c7257c458f..072b88481b2 100644 --- a/gdbserver/tdesc.cc +++ b/gdbserver/tdesc.cc @@ -32,14 +32,13 @@ bool target_desc::operator== (const target_desc &other) const if (reg_defs != other.reg_defs) return false; - /* Compare expedite_regs. */ - int i = 0; - for (; expedite_regs[i] != NULL; i++) - { - if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0) - return false; - } - if (other.expedite_regs[i] != NULL) + /* Compare the two vectors of expedited registers. They will only match + if the following conditions are met: + + - Both vectors have the same number of elements. + - Both vectors contain the same elements. + - The elements of both vectors appear in the same order. */ + if (expedite_regs != other.expedite_regs) return false; return true; @@ -89,7 +88,13 @@ init_target_desc (struct target_desc *tdesc, gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ); #ifndef IN_PROCESS_AGENT - tdesc->expedite_regs = expedite_regs; + /* Drop the contents of the previous vector, if any. */ + tdesc->expedite_regs.clear (); + + /* Initialize the vector with new expedite registers contents. */ + int expedite_count = 0; + while (expedite_regs[expedite_count] != nullptr) + tdesc->expedite_regs.push_back (expedite_regs[expedite_count++]); #endif } diff --git a/gdbserver/tdesc.h b/gdbserver/tdesc.h index 7fe7d0d8eb3..8a29fc6fe6d 100644 --- a/gdbserver/tdesc.h +++ b/gdbserver/tdesc.h @@ -40,9 +40,9 @@ struct target_desc final : tdesc_element std::vector features; #ifndef IN_PROCESS_AGENT - /* An array of register names. These are the "expedite" registers: + /* A vector of register names. These are the "expedite" registers: registers whose values are sent along with stop replies. */ - const char **expedite_regs = NULL; + std::vector expedite_regs; /* Defines what to return when looking for the "target.xml" file in response to qXfer:features:read. Its contents can either be From patchwork Mon Sep 18 21:26:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76313 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 BAE7D385C6E2 for ; Mon, 18 Sep 2023 21:27:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAE7D385C6E2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072477; bh=3KMh76uEo7YbVQtVn5KtnJymSqD92efYLD4gL/8fdVE=; 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=kdUaOOfan7SmQLZZY3C0Jr0lUQJVKbxobw3zSyrzGbw0g1ranhdE34J7xZBwwj/rN ueR+PBRNSEn8A0hqFELUVSwgH/ObZRC3/5MdfwQZLMF7Jh9jRyTOn+RlaYmklQ2r92 IbkgpTj3mDjncsiHs6PTRL2sXP6HwhXpGiJRt4Uw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2042.outbound.protection.outlook.com [40.107.22.42]) by sourceware.org (Postfix) with ESMTPS id 88EF83858C2A for ; Mon, 18 Sep 2023 21:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 88EF83858C2A Received: from DUZPR01CA0345.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b8::28) by PAVPR08MB9307.eurprd08.prod.outlook.com (2603:10a6:102:304::5) 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 DBAEUR03FT003.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:4b8:cafe::51) by DUZPR01CA0345.outlook.office365.com (2603:10a6:10:4b8::28) 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: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 DBAEUR03FT003.mail.protection.outlook.com (100.127.142.89) 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 d084e965c4eb:v175"); Mon, 18 Sep 2023 21:27:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 22c9db0d9bc19b8e X-CR-MTA-TID: 64aa7808 Received: from 710f09a800e3.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id D620215D-4297-4F1D-B9F1-7969AEC6A35E.1; Mon, 18 Sep 2023 21:27:06 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 710f09a800e3.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QTu7c00EASoSnTWvE/cGKC7+3i5VgxKH9n0RtfRkO8Nu7aJ7SdIfchoxFOtrcmvkC0rAqWMobPLYjWyHf2TbrEhws7MdPLOnB+qw+SgdYLDNhmZmTfIDRBWvRKtyu/KTxzZftXumyDeYKJ7UezgS08pPDU8wylq2wNDApAK1ij1xIkITrog/mUlQ8NxMwMTDQCTueSGELMizZf/mKc43mFT/4BJTFkgP4nBiDw+CZCl2c+dZNZiCstFZ4p42+7OGGWqCaZAmhuJJlqreu2fm0/7H8Rh5R043FTWVahhN/E1+tCaBFwZ2waZBnyO1yUd4bqShbz+9+Q0fu3FnYw95EA== 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=3KMh76uEo7YbVQtVn5KtnJymSqD92efYLD4gL/8fdVE=; b=kFbXgogxPx4p1uPADE6k+4o/NxplnZDMyxfVudbHWmVfnHswoX7LAKNgWiDAjPaP3bb20VYFm1qnDSAoDcqjVRt0J8McepQpCWZUgz9mg5eWIczx/N2KpUZw/p2DrqPhZfrLaF5ECYnJvLioMtucBQrqhZLb7uLSV4xVwFuFV9H8om6xzJSWt5Li+vii/QvC5AYJ9MVQn3M9fL/uKB8RgJAzbSidfAM99BpiKq/ywAZ1HFXVgCxklQyA7r7aWMyn3aubgP94L8JYbZIXBJIJWqDXVtKw50pqTFVF4bbT5fI9oj2oXVrhu6oByipDakNntsKALIDofbOx4kp/x3WlWQ== 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 AS9PR06CA0212.eurprd06.prod.outlook.com (2603:10a6:20b:45e::33) by AS2PR08MB8805.eurprd08.prod.outlook.com (2603:10a6:20b:5f5::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.23; Mon, 18 Sep 2023 21:27:04 +0000 Received: from AM7EUR03FT061.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45e:cafe::99) by AS9PR06CA0212.outlook.office365.com (2603:10a6:20b:45e::33) 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:04 +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 AM7EUR03FT061.mail.protection.outlook.com (100.127.140.72) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6813.15 via Frontend Transport; Mon, 18 Sep 2023 21:27:04 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) 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 AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:03 +0000 To: Subject: [PATCH v7 07/18] [gdbserver/aarch64] refactor: Adjust expedited registers dynamically Date: Mon, 18 Sep 2023 22:26:40 +0100 Message-ID: <20230918212651.660141-8-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: AM7EUR03FT061:EE_|AS2PR08MB8805:EE_|DBAEUR03FT003:EE_|PAVPR08MB9307:EE_ X-MS-Office365-Filtering-Correlation-Id: 5774c816-4563-4aa8-ea72-08dbb88e06d7 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: UFQNVDee2LSUsaXY0nmwjzbSJ+a/qaHysVrEVe+lRql8VXgtvX8fIKREbvid1Gt0MMgImD3OVPs4q0amVl4Wslcvw0orYzkpmXsfnBl+/kgwQUoWzU5Qi2MwxoC6Ezmh6Vr5BYo1vkhLHdUhDwPDNRPa+zDdi9ZU+eyA/ZabCqBWJzFH6++T4aJ2e1w4HAiwzyS6mslAZHbQ1a3tNsoQqscKTFQ7ZEUtjK6440IH786pG0nygVZAn+PCb6EEL60KRTM2Qdgo0brmeTDeCJxxu9QnVIbVyXFNS/Z0zJ8P7t0hKvcdVBN6NO5/s1SqLAngwTwMXF3Bur7phPyEwlPEtn49GoCj5y+qtA2VPxmfoAdskWzz1WaA1ib101OpWIytn9hCKDbH2WQge32xtKa9C/OrJF9mmS0D4JLMnQoxAVu0IRJj3deFyuJH9nmQqGYSkXUWHMJjQdXsv4swzjDj/RwiSg33zzUSrOB3CAf2q0yETRdYnPguciH0MQqIZVBXYd57eh7aFff+/zbjRtKrQJ+m2lbCdUKQSzwJBph8mq5cJvqEyxtfVYszH/WNNNLwyiuehksnAJIVDzllO4cNcOD4MPejvTAX9WZvYunTXVHjOthMs3jssGDp/1JoN/LH/9IsBY+CRGt7WXmSRrlJxdQ2snXRmYm5g7mBfPR/rA4poGyEd+yvPpmX6TCzugg80j6s2PLw2zTf3ch5UTMkFFSJ3YSblmKIijTUykRsB8Zfsldib587K353bnxMS3HxQ2P7JsJrdi9jCqZ5ZfK88A== 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)(346002)(136003)(396003)(376002)(39860400002)(82310400011)(451199024)(186009)(1800799009)(36840700001)(40470700004)(46966006)(7696005)(6666004)(478600001)(426003)(2616005)(1076003)(26005)(44832011)(47076005)(2906002)(336012)(6916009)(316002)(70206006)(70586007)(54906003)(41300700001)(5660300002)(4326008)(8936002)(8676002)(356005)(40460700003)(81166007)(36756003)(36860700001)(40480700001)(86362001)(82740400003)(83380400001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB8805 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 234dd5e2-7c52-4967-e575-08dbb88e0114 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wi0faAhYpIqwPnHiajzniemIu2uVqq4rAF5bzVcsi/Ow9mmf0qNFMYFsOcGE9dhgOV+Rja3Q9lOxPbjhqFCWQJ9X6LvuFRuexL2U1hv6/ajCksGxRlVrVaK5yxbX5kpb8rBgUBCNYpAoABmhs7wiaP8d8PpvQJYcNsKHot5gvyk40u+1CTYzpglNqOdZNRv8aaX0Nmssv+p4gzJPge+sFkpR8wc+XXVahUxn1iFf8NPqD4trHY2434L6R9ILgYx6nbkmfG7heB7oU7/LNC8VAe9rdiPvx6Fi9efZuhuOzCYa0gWOg56H5Xs0WY/UOn25457T3Pnlwi1Id7GXsMB+63SeAthbEAerA59Yfj+xTNE99KoLYlNJSvnXgSC6NGmdRCAQ6dKmc+kKMNpsWAXj5BL3d4Pw0XSwSax8l2LdoGs+gKVL307lOOmHAprweXSztfOuKy27UuM9IhogpHz73XxgBN9TBkNgMAiTxnaHN5MOpCL8Ps5Nhp7RTyKBQfzxZ2rnMp839iSjiYGR2Nr7e+XEL/WS4+DtEsaS+Q9cRYLRC4LZiBkkwWJ65dZWl5peMezVkoIE8RuzH6orSLgauODR+aw0VZAvCm7OKSom1HiwOD7qw1PaIt3D93UIu0v4Gx8DHlWL59uV7XSLOSddnuzf3mPrJPLym/ugwsoUQ9AIprHrYuI7dyAZf9tZ7BYpgfTgkq8jJp6TxnHZ4fe812weF0qVb1nBBfom6ecGDDB7PCIIwhbbR8tRn1VnKHdR 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)(136003)(376002)(39860400002)(346002)(396003)(82310400011)(1800799009)(186009)(451199024)(36840700001)(46966006)(40470700004)(478600001)(8936002)(6666004)(40460700003)(7696005)(36860700001)(316002)(40480700001)(2906002)(2616005)(36756003)(1076003)(336012)(426003)(86362001)(26005)(107886003)(81166007)(41300700001)(4326008)(82740400003)(8676002)(83380400001)(54906003)(5660300002)(44832011)(6916009)(47076005)(70206006)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:14.2424 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5774c816-4563-4aa8-ea72-08dbb88e06d7 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: DBAEUR03FT003.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAVPR08MB9307 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" Instead of using static arrays, build the list of expedited registers dynamically using a std::vector. This refactor shouldn't cause any user-visible changes. Regression-tested for aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdbserver/linux-aarch64-tdesc.cc | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tdesc.cc index 633134955e5..3c60e1a4db0 100644 --- a/gdbserver/linux-aarch64-tdesc.cc +++ b/gdbserver/linux-aarch64-tdesc.cc @@ -30,6 +30,8 @@ /* All possible aarch64 target descriptors. */ static std::unordered_map tdesc_aarch64_map; +static std::vector expedited_registers; + /* Create the aarch64 target description. */ const target_desc * @@ -44,15 +46,20 @@ aarch64_linux_read_description (const aarch64_features &features) if (tdesc == NULL) { tdesc = aarch64_create_target_description (features); + expedited_registers.clear (); + + /* Configure the expedited registers. By default we include x29, sp and + pc. */ + expedited_registers.push_back ("x29"); + expedited_registers.push_back ("sp"); + expedited_registers.push_back ("pc"); + + if (features.vq > 0) + expedited_registers.push_back ("vg"); - static const char *expedite_regs_aarch64[] = { "x29", "sp", "pc", NULL }; - static const char *expedite_regs_aarch64_sve[] = { "x29", "sp", "pc", - "vg", NULL }; + expedited_registers.push_back (nullptr); - if (features.vq == 0) - init_target_desc (tdesc, expedite_regs_aarch64); - else - init_target_desc (tdesc, expedite_regs_aarch64_sve); + init_target_desc (tdesc, (const char **) expedited_registers.data ()); tdesc_aarch64_map[features] = tdesc; } From patchwork Mon Sep 18 21:26:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76316 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 A9864384DD13 for ; Mon, 18 Sep 2023 21:28:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A9864384DD13 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072511; bh=Yb5ensiN01lD7sAN2N/BoeKgXi2M4/s2lqBTT1PAIoE=; 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=GROxgV3CDkm1RcHZ5EC+2wM8B6Pg82Wx9sOZBhBlBouFYIaQCi7tTRa0nhQobUKAb oE12yg/qTNL7wWIHG6XJwnLkwuUZcg4sFkewp6Ti4WYoAw7Uu78SrZW+Cy/Tw1lTSa gPUQvcyEarVtXtBxJ+0a5RxJyAwC9LLwItJpAEHI= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2075.outbound.protection.outlook.com [40.107.7.75]) by sourceware.org (Postfix) with ESMTPS id 81549385772F for ; Mon, 18 Sep 2023 21:27:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 81549385772F Received: from AS4P195CA0042.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:65a::16) by AS4PR08MB7406.eurprd08.prod.outlook.com (2603:10a6:20b:4e1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 21:27:14 +0000 Received: from AM7EUR03FT005.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:65a:cafe::b8) by AS4P195CA0042.outlook.office365.com (2603:10a6:20b:65a::16) 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: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 AM7EUR03FT005.mail.protection.outlook.com (100.127.140.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:14 +0000 Received: ("Tessian outbound 5c548696a0e7:v175"); Mon, 18 Sep 2023 21:27:14 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d42b118a96658b0d X-CR-MTA-TID: 64aa7808 Received: from b426b9289374.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F4FCFDF3-C21E-4545-8682-DD5B6508FC4D.1; Mon, 18 Sep 2023 21:27:07 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b426b9289374.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jnRjXS6SQ3vkv40RFlaR7V4HJgUHC9k3Z1lzfkcI7xWKifGj8yyiPVyUPyivoAKItVNQsG8pgf/38tMe473dd+F+wP/lIuBW6diUf6TKksAxSzMB7QXcNCpV0GpSqMmKTq8f2Zguw/6x0/QqmIboqlnxXlBqyMPeHEXaWiDZsLE1NOKXADAhZFGuSXoykwevcWFogHaoRr8llDRXD8MsC1m5TPp7FgmhewTHBLH/MM0hUrnUY1RqqEDzKidH+xGG16VGmirqvtNbvWR+XNkriEG1CIHP9aQVXLhsYLycYQUezzSZPZEGOVU2qxmtKwJudxs/fPeow1JsLpjbSnHLqw== 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=Yb5ensiN01lD7sAN2N/BoeKgXi2M4/s2lqBTT1PAIoE=; b=CZ3DU0grOf8ViwG45u85EYFiNs9aUiHuc5MZJGhQetBuLF00p7stBhtZBHYs00qCCqlZqOFx6eP8CwjSwMCph7h9Oa9ovklprC3xmfPK3lrYmMfMw3PP74OJDNHrshPa3lMjN0VKo/4D1eBhXo94XWL66qrjTh1lR6BB0NsH3eJljnXKFCYIR3cBEUy0YsqidowUum0c6GMo1wlxXGu5EdoA+Xla50F1fmPtgT4Za4f7xBITdGpaPuX1Hzgqre+Ujx6cgvUMePQvNoepeU2zfb5TyziLtLUBhucugoUBU6lw4zIDw8czC8o/D2iepp68jYpQtz387JuPHcVKFnl+cg== 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 AM6P193CA0112.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::17) by AS2PR08MB9595.eurprd08.prod.outlook.com (2603:10a6:20b:609::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:05 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::c3) by AM6P193CA0112.outlook.office365.com (2603:10a6:209:85::17) 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 08/18] [gdbserver/aarch64] sme: Add support for SME Date: Mon, 18 Sep 2023 22:26:41 +0100 Message-ID: <20230918212651.660141-9-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_|AS2PR08MB9595:EE_|AM7EUR03FT005:EE_|AS4PR08MB7406:EE_ X-MS-Office365-Filtering-Correlation-Id: 10aa3525-259a-48aa-1d17-08dbb88e06f1 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: /E0r+r32KXxvI1sZctuLDYf/gRQBHpN6DrBSZaEm76nDXFFBVcZw+gsakxTZ1AuR8lcmxgt+wCqdREk5zA3GfqbODy0oHFCDlVjBvV2O+Bomi7ipjSDMXxdP9Hheza2r11C2UfRDCd7ru/QufV4mgwtopaR/xbJkqRFV4J2pmZYwM9K1SGPu7EKwxFYc32tzS2BzTTj1FYZ2Ip9q/mRfqfYABx3QuF9hj9TFcgsQ79b1ZC9/iO1GcTN3n1OmsfjNZBVHWkOnUQQuUd6m6UNk4qfrgF8rEAealLbJwgSTeWLYu1Iv0dknjWUV2pc9IuqDkg0CflSaQb3IKGZmv3w9SNgolKvNKBXhql0ADMBpP43rzgUIBPaY0FWrXEulN3r12eH1VulqoYFybhilR43HQrerVclTDsZUcC+/podEjera4dsjSqiHOdxPSfwlALQW3Z+ByYTxNnwgfewl5QHmfeZV9+A3gwfj4mKKOU1AIv0n/0JV0yVP/6+rpqIyxkpOFIRTgrTxxm5qEo/w3LJmw9q/Nq/aZrSmLkbUPdLfYKD1gt3ZkKBn38H03Z45JGBFag/SVhPVsb8/C591gh0QkfErTdu2zlng/FX6ZPyFtLsc+7LuUzuUJyWFYjdlfwRj4MvMroqG46P+5GliDVMqapkfYXAb4T8BZCPSqdacLxr3XhW6Wm7kRFvAAr+FtAWM6DJrkoyy+vfm5ot0PlwOtIqVobtmWMXbMtegqXOOnZEFJ2VZOFVSH9Uyj7YXMETuXJcgN/7YPMQKKKV5Uoap8A== 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)(346002)(39860400002)(376002)(136003)(396003)(1800799009)(451199024)(186009)(82310400011)(36840700001)(46966006)(40470700004)(40460700003)(7696005)(66899024)(6666004)(83380400001)(82740400003)(81166007)(86362001)(356005)(36860700001)(47076005)(2616005)(36756003)(336012)(40480700001)(1076003)(26005)(54906003)(70586007)(6916009)(70206006)(41300700001)(316002)(2906002)(44832011)(5660300002)(4326008)(8676002)(8936002)(426003)(478600001)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9595 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d2e6e92d-967b-4f85-fbdd-08dbb88e0187 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jJNi/YvizKhn+ivo2GvukPuGBfb4kXW8n2Ze94IQaHgB6HDianCUAI89TRwjK8TOAYqkyPjkcFBTWPgrYMsu/ZNiu9G6bOoLYbAx8tt/05UPZ9nRqFHJnZLJ1xgXwZuLH7kFhXbUTcp3rfpK+VIQkEz8IcKfoQjhytpCUi053HF1VrGySyDvQ4kn3EohTW9GnOyxAKLpA95dExMt5b7E4+tmdpDudCE1DukYRT7Nu4W7gcPxflq18874UOzpKGt3cxqx9DpfFCxfj6wM8s6yavud8EulYRszmn3Vm8Lo9kkAr7i8+k++BtR/kpjfvZ+WL0KhG47Knhq8W8OPTJWx+3eLOP+Fk4YVTB8CMLAMVJaJTf4E5Yl+LfL62cIqhHnWV520BX9b9hQe7DWUBMMQvSHyt4tpcr9tLJ1gy6sydq3MrZSdpILXm/SRdR1YeWVOquTVk0Uy52iiABq8lKxoU3nYhHbJooGhb+VGO7J+85nr2s4LQUfLqZqIeCCvTA+bbA/2yYGjMY8+/oorPHyg0SzY8Rfnb9Mg+unYcXQwHgDilFJqHowFdhBIg/2nPKcOTxFNKQNJlHUlSYc2cJahFGG8yEypEKiarP5Yv7rHIV5X1F4Ue3Oq+ZkAajVOV4oGQcQiHHmq4fJ6g7nsO0Wz1nuaF5xAowKg/BGKzcfEGML/Qi5TtNY6WysV34sLLl9aOqLzxjslcq30VG06igLe3WdKfLVBnLAphiWwRBf9rMfcfzx6ATvdjB3bWQ6Kwqr8 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)(376002)(39860400002)(346002)(396003)(136003)(451199024)(82310400011)(1800799009)(186009)(36840700001)(46966006)(40470700004)(66899024)(6666004)(7696005)(478600001)(40460700003)(82740400003)(86362001)(40480700001)(36756003)(36860700001)(81166007)(1076003)(107886003)(26005)(2616005)(2906002)(426003)(336012)(47076005)(83380400001)(5660300002)(4326008)(316002)(8936002)(8676002)(41300700001)(54906003)(6916009)(44832011)(70206006)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:14.3607 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 10aa3525-259a-48aa-1d17-08dbb88e06f1 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: AM7EUR03FT005.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7406 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" v5: - Used find_regno instead of find_regno_no_throw. It would be a fatal error to not find the registers in these particular functions. --- Enable SME support in gdbserver by adjusting the usual fields. There is not much to this patch because the code is either in gdb or it is shared between gdbserver and gdb. One exception is the bump to gdbserver's PBUFSIZ from 18432 to 131104. Since the ZA register can be quite big (256 * 256 bytes), the g/G remote packet will also become quite big From gdbserver/tdesc.cc:init_target_desc, I estimated the new size should be at least (2 * 256 * 256 + 32), which yields 131104. It is also unlikely we will find a process starting up with SVL set to 256. Ideally we'd adjust the packet size dynamically based on what we need, but for now this should do. Please note we have the same limitation for SME that we have for SVE, and that is the fact gdbserver cannot communicate vector length changes to gdb via the remote protocol. Thiago is working on this improvement, which hopefully will be able to be adapted to SME in an easy way. Co-Authored-By: Ezra Sitorus Reviewed-by: Thiago Jung Bauermann --- gdbserver/linux-aarch64-low.cc | 60 ++++++++++++++++++++++++++++++++ gdbserver/linux-aarch64-tdesc.cc | 7 ++++ gdbserver/server.h | 2 +- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index 7c633c212f3..e887e39b1c2 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -41,6 +41,7 @@ #include "gdb_proc_service.h" #include "arch/aarch64.h" #include "arch/aarch64-mte-linux.h" +#include "arch/aarch64-scalable-linux.h" #include "linux-aarch32-tdesc.h" #include "linux-aarch64-tdesc.h" #include "nat/aarch64-mte-linux-ptrace.h" @@ -750,6 +751,52 @@ aarch64_sve_regs_copy_from_regcache (struct regcache *regcache, void *buf) memcpy (buf, sve_state.data (), sve_state.size ()); } +/* Wrapper for aarch64_za_regs_copy_to_reg_buf, to help copying NT_ARM_ZA + state from the thread (BUF) to the register cache. */ + +static void +aarch64_za_regs_copy_to_regcache (struct regcache *regcache, + ATTRIBUTE_UNUSED const void *buf) +{ + /* BUF is unused here since we collect the data straight from a ptrace + request, therefore bypassing gdbserver's own call to ptrace. */ + int tid = lwpid_of (current_thread); + + int za_regnum = find_regno (regcache->tdesc, "za"); + int svg_regnum = find_regno (regcache->tdesc, "svg"); + int svcr_regnum = find_regno (regcache->tdesc, "svcr"); + + /* Update the register cache. aarch64_za_regs_copy_to_reg_buf handles + fetching the NT_ARM_ZA state from thread TID. */ + aarch64_za_regs_copy_to_reg_buf (tid, regcache, za_regnum, svg_regnum, + svcr_regnum); +} + +/* Wrapper for aarch64_za_regs_copy_from_reg_buf, to help copying NT_ARM_ZA + state from the register cache to the thread (BUF). */ + +static void +aarch64_za_regs_copy_from_regcache (struct regcache *regcache, void *buf) +{ + int tid = lwpid_of (current_thread); + + int za_regnum = find_regno (regcache->tdesc, "za"); + int svg_regnum = find_regno (regcache->tdesc, "svg"); + int svcr_regnum = find_regno (regcache->tdesc, "svcr"); + + /* Update the thread NT_ARM_ZA state. aarch64_za_regs_copy_from_reg_buf + handles writing the ZA state back to thread TID. */ + aarch64_za_regs_copy_from_reg_buf (tid, regcache, za_regnum, svg_regnum, + svcr_regnum); + + /* We need to return the expected data in BUF, so copy whatever the kernel + already has to BUF. */ + + /* Obtain a dump of ZA from ptrace. */ + gdb::byte_vector za_state = aarch64_fetch_za_regset (tid); + memcpy (buf, za_state.data (), za_state.size ()); +} + /* Array containing all the possible register sets for AArch64/Linux. During architecture setup, these will be checked against the HWCAP/HWCAP2 bits for validity and enabled/disabled accordingly. @@ -772,6 +819,11 @@ static struct regset_info aarch64_regsets[] = 0, EXTENDED_REGS, aarch64_sve_regs_copy_from_regcache, aarch64_sve_regs_copy_to_regcache }, + /* Scalable Matrix Extension (SME) ZA register. */ + { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_ZA, + 0, EXTENDED_REGS, + aarch64_za_regs_copy_from_regcache, aarch64_za_regs_copy_to_regcache + }, /* PAC registers. */ { PTRACE_GETREGSET, PTRACE_SETREGSET, NT_ARM_PAC_MASK, 0, OPTIONAL_REGS, @@ -839,6 +891,10 @@ aarch64_adjust_register_sets (const struct aarch64_features &features) if (features.tls > 0) regset->size = AARCH64_TLS_REGISTER_SIZE * features.tls; break; + case NT_ARM_ZA: + if (features.svq > 0) + regset->size = ZA_PT_SIZE (features.svq); + break; default: gdb_assert_not_reached ("Unknown register set found."); } @@ -873,6 +929,10 @@ aarch64_target::low_arch_setup () features.mte = linux_get_hwcap2 (pid, 8) & HWCAP2_MTE; features.tls = aarch64_tls_register_count (tid); + /* Scalable Matrix Extension feature and size check. */ + if (linux_get_hwcap2 (pid, 8) & HWCAP2_SME) + features.svq = aarch64_za_get_svq (tid); + current_process ()->tdesc = aarch64_linux_read_description (features); /* Adjust the register sets we should use for this particular set of diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tdesc.cc index 3c60e1a4db0..b6b622ba4f2 100644 --- a/gdbserver/linux-aarch64-tdesc.cc +++ b/gdbserver/linux-aarch64-tdesc.cc @@ -41,6 +41,11 @@ aarch64_linux_read_description (const aarch64_features &features) error (_("VQ is %" PRIu64 ", maximum supported value is %d"), features.vq, AARCH64_MAX_SVE_VQ); + if (features.svq > AARCH64_MAX_SVE_VQ) + error (_("Streaming svq is %" PRIu8 ", maximum supported value is %d"), + features.svq, + AARCH64_MAX_SVE_VQ); + struct target_desc *tdesc = tdesc_aarch64_map[features]; if (tdesc == NULL) @@ -56,6 +61,8 @@ aarch64_linux_read_description (const aarch64_features &features) if (features.vq > 0) expedited_registers.push_back ("vg"); + if (features.svq > 0) + expedited_registers.push_back ("svg"); expedited_registers.push_back (nullptr); diff --git a/gdbserver/server.h b/gdbserver/server.h index fde7dfe7060..306d75d4e9b 100644 --- a/gdbserver/server.h +++ b/gdbserver/server.h @@ -104,7 +104,7 @@ extern int in_queued_stop_replies (ptid_t ptid); /* Buffer sizes for transferring memory, registers, etc. Set to a constant value to accommodate multiple register formats. This value must be at least as large as the largest register set supported by gdbserver. */ -#define PBUFSIZ 18432 +#define PBUFSIZ 131104 /* Definition for an unknown syscall, used basically in error-cases. */ #define UNKNOWN_SYSCALL (-1) 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)); From patchwork Mon Sep 18 21:26:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76321 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 ADB5B3857732 for ; Mon, 18 Sep 2023 21:29:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADB5B3857732 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072568; bh=NMYaSnFumKM6bUKjXIriBsbwoQNovqZrQJXB+MXxO0A=; 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=qbIztwIKVVAPzgROgjX5Zsc2CyI+5Dk45rP82xhrNrH05UfUzLe+7HHwMogV5fkNA WP4Cq2PUpO7BKPQcJ0ws/LtJh9+wc4dG6rGiNmKfq2uBaWC6mG8V8aVJx996kgZFEe GU+FnWeBOMfCM5o+oE3GCKVoemrOsmNo5CW/JgQM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2083.outbound.protection.outlook.com [40.107.21.83]) by sourceware.org (Postfix) with ESMTPS id 0198B3857736 for ; Mon, 18 Sep 2023 21:27:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0198B3857736 Received: from AM6PR10CA0012.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:89::25) by AS4PR08MB7577.eurprd08.prod.outlook.com (2603:10a6:20b:4fc::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:17 +0000 Received: from AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:89:cafe::25) by AM6PR10CA0012.outlook.office365.com (2603:10a6:209:89::25) 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:17 +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 AM7EUR03FT047.mail.protection.outlook.com (100.127.140.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:16 +0000 Received: ("Tessian outbound 1eb4e931b055:v175"); Mon, 18 Sep 2023 21:27:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 01962679db6585db X-CR-MTA-TID: 64aa7808 Received: from 59732eeb41c9.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 832E5003-2DFE-453D-8119-ABF04ACB5837.1; Mon, 18 Sep 2023 21:27:09 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 59732eeb41c9.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CTm4uSbkIbPXKogmFlrcbJs0sEDSa9mmlBwlPvE5u+RXzOQ+h3pK9r/bPF987sxa14WMOWzuPNAoj9/XCm2I5yibbK7EkvRVu5YEfjkkegksDNkJrXgjkJ6RI9mtmCasYzWtBjoC+M0ymbxZ3yLLcW2gtF6AJDQQh1pcU4bJ9UmqNqOlhX7J2JemMmlqXP6Y9Dx3aezO+aaJeOyOu3ZS62Y6ntCWZLsaPOmd/lORGhpABgoJQhNlAl8QJhqjKiB2jXSPXmK9SD+gzqmPSuaQPUEmuyPREs/nkWW3PpxeEQkDzdAeXWUxvoxjkLW+UEwNmTEiGmGIM1+skY0zZWPYLw== 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=NMYaSnFumKM6bUKjXIriBsbwoQNovqZrQJXB+MXxO0A=; b=hexVGgaxEvbV3LcWcv+LvgD3bW5YNyMik6KfaUY75mjPWrSgsWx62QBx/7oa7Y9kSsVzLAnrDyrRKT1WQ7mAHlUYCdIiyOqJFpfX4Gg/Kz8Ksyx1NGGSIOunDdVCaMOhGxzH0oUh/SpPGAVjI0UDpAPiWG3F/7+bR6FDROy7WZEE0WPJTADrwbnVg6FvNypn7+/r5EIqYBfE2RB1fiX8hOV1ANPdsx5mC9V/sT/OCF7bTvyLRJCfkKketaGroGNrZOXE0sPOjSaXRX+owDxeR2MuGWYK+sYS6qrmCj7LBN+Xoa5Jc/J2l8Yz2mKEWAzFZ9mGCHuNKxnUebsHbHOq5w== 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 AM6P193CA0127.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::32) by VI1PR08MB10032.eurprd08.prod.outlook.com (2603:10a6:800:1cc::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 21:27:06 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::6e) by AM6P193CA0127.outlook.office365.com (2603:10a6:209:85::32) 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-EX02.Emea.Arm.com (10.251.26.5) 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:05 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:05 +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:05 +0000 To: Subject: [PATCH v7 10/18] [gdb/aarch64] sme: Signal frame support Date: Mon, 18 Sep 2023 22:26:43 +0100 Message-ID: <20230918212651.660141-11-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_|VI1PR08MB10032:EE_|AM7EUR03FT047:EE_|AS4PR08MB7577:EE_ X-MS-Office365-Filtering-Correlation-Id: bf941e4c-6aee-45aa-13d0-08dbb88e0870 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: sX3PV9xgeMqdCHFzpSwpbiuedxt/sCEPNDbKuWiMlEMi3Bki6+OCCFmId0EaFaJM3/ejUtVFuT3Ytc10Ur4Evbbo3qkRIBrLwms5CLxWCRGJTtIZpMtKJzJJjfg0F821kVpDQYVjwIpmj/G8mYZC/703eMadsOQQOnhwIDSLWSVKJVoNwBLgcY8eWbRuLB6zlMfD0LJLmOSGFyuCNCAw4g0YpbDnSCRnQ1Oa904EK9SdrTPz0l841flb1qprJ29XuE8+ZhlLsaTeej7RQmiq87BumD2L+Kj+LmQAApaEehkl18Ry4J1e+yi5+cv/K+HX/sGkoJ5ovFlmBhh6re9EDdz4mhxvHhDqBFBkYbyhChUYduKk+jPcZrCjmXIjHBMjtbp2QAygQGRUni4JQ7zklDxkuodcN86Cw9Wux7CujbmEQrVQ6RVioyjJIuZjaedSjlULngw9rkMkOi+oeo+GLC7sXHxatBHm/bdmbzMXkZtuJjySSOS0Mhiyz+Apc0boHtsW/oiPbwGpJH7dLyYEWms8bThh7ui6wMwhBfqkRLsoqcBRl6fUZNE6etqcasc0BXgETYtTS3wGAyllCOInHOtS5gAOSrdEQYViw5liEAXPsAkKxEeiFP9LB0pJaBdJpbOStOLbBUwWLKcuemf/iYkEPxtjDHSysb88IQUEfq2Z+CR315v/UOGNB9nAbqViOkAoJy48fd8/BRq1o6ylBXtG4XRCZHZCRMC132T2szygAZa1SLdcFgU60wA9wFcM 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)(376002)(346002)(136003)(39850400004)(82310400011)(186009)(1800799009)(451199024)(36840700001)(46966006)(81166007)(86362001)(36756003)(82740400003)(40480700001)(356005)(6916009)(7696005)(44832011)(70586007)(4326008)(70206006)(316002)(8936002)(41300700001)(6666004)(2906002)(478600001)(1076003)(83380400001)(426003)(8676002)(5660300002)(47076005)(36860700001)(54906003)(26005)(336012)(2616005)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB10032 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 6a18eb70-fba3-447b-938d-08dbb88e01e2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NCgJbae+jdRurAX8VAMsT7Ae+ZmN5o/isSQjVcJlT0YsYMorueWBviju/b3JBbf9sRQf0W8GdoUOb3JOjjsjgaJ0Qoopdaz1UGppiNhz1rmmaFLr2FbGwnQEzCtwuOB+YE3zpuWolOoV3PPssoEBjxWBWKyEjJQqDQiGGPZ2kLU7P5rg9/pmVN6ZIsjU/R8C9VIyJCpdJ+A1EEoXefinFRiR9yUaS3/xuxH3M/rBt+auoL98as1d8zWC67RgkM1Dj9vghsz/RxbcSDVz6kqfJued4sgU2CtDG1XPdAf6W7bjuqM4qOiClI+9wiDNIy6PpYt2++DWkGFlIQmE1NuzJIl9+kOw9V3iLxL0qkF7gGhOvkLI3i/2epGaUSyg8BkTrHghX/KC1/UDzez5TMb+4zQuywh48vamMkdK23eE4z2JISkj6BQf7F9zmXej9be3aiGCMPPYD1uzL24ryPWFPCIjhICspHmnccE56gMABxi26+YSsv5iRvGWvizK/a6H8oNMaE4fCRCQbNdgIbzxoEHomEAy3GBUX0DF9aozaRvjhYcI8b6FgLvbgXQTC2L4EEqm+N0kjMiO/Jv5ELHtf6BfYXAdgZ+UkJABiTfrRoSHEIeFzSy+EaKpuQkV4wqP90PCa9swo3oDs64IvL0zih/GfdqIotgSlTulPHAtqUWg5ZmYA0CNe6JdAoi1qBagguMwTsbGYsAoM+7DpgpRd2AkcC3sb4xws0GltqEkciUXTIafrRgAYqXl8fAfV14Q 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)(136003)(396003)(376002)(39860400002)(451199024)(186009)(82310400011)(1800799009)(46966006)(40470700004)(36840700001)(40460700003)(86362001)(47076005)(83380400001)(81166007)(82740400003)(36860700001)(36756003)(107886003)(2616005)(26005)(1076003)(426003)(336012)(6916009)(7696005)(6666004)(316002)(54906003)(478600001)(70586007)(70206006)(5660300002)(2906002)(4326008)(40480700001)(41300700001)(8676002)(8936002)(44832011); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:16.8861 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: bf941e4c-6aee-45aa-13d0-08dbb88e0870 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: AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS4PR08MB7577 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" Teach gdb about the ZA/SSVE state on signal frames and how to restore the contents of the registers. There is a new ZA_MAGIC context that the Linux Kernel uses to communicate the ZA register state to gdb. The SVE_MAGIC context has also been adjusted to contain a flag indicating whether it is a SVE or SSVE state. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-tdep.c | 88 +++++++++++++++++++-- gdb/nat/aarch64-scalable-linux-sigcontext.h | 5 +- 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index bdd5cb05c10..f76d1888072 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -48,6 +48,7 @@ #include "linux-record.h" #include "arch/aarch64-mte-linux.h" +#include "arch/aarch64-scalable-linux.h" #include "arch-utils.h" #include "value.h" @@ -152,6 +153,7 @@ #define AARCH64_EXTRA_MAGIC 0x45585401 #define AARCH64_FPSIMD_MAGIC 0x46508001 #define AARCH64_SVE_MAGIC 0x53564501 +#define AARCH64_ZA_MAGIC 0x54366345 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */ #define AARCH64_EXTRA_DATAP_OFFSET 8 @@ -164,13 +166,23 @@ /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */ #define AARCH64_SVE_CONTEXT_VL_OFFSET 8 +#define AARCH64_SVE_CONTEXT_FLAGS_OFFSET 10 #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16 #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16) #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \ (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2)) #define AARCH64_SVE_CONTEXT_SIZE(vq) \ (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2)) +/* Flag indicating the SVE Context describes streaming mode. */ +#define SVE_SIG_FLAG_SM 0x1 +/* SME constants. */ +#define AARCH64_SME_CONTEXT_SVL_OFFSET 8 +#define AARCH64_SME_CONTEXT_REGS_OFFSET 16 +#define AARCH64_SME_CONTEXT_ZA_SIZE(svq) \ + ((sve_vl_from_vq (svq) * sve_vl_from_vq (svq))) +#define AARCH64_SME_CONTEXT_SIZE(svq) \ + (AARCH64_SME_CONTEXT_REGS_OFFSET + AARCH64_SME_CONTEXT_ZA_SIZE (svq)) /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the size, or return 0 on error. */ @@ -324,7 +336,10 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE; CORE_ADDR fpsimd = 0; CORE_ADDR sve_regs = 0; + CORE_ADDR za_state = 0; + uint64_t svcr = 0; uint32_t size, magic; + size_t vq = 0, svq = 0; bool extra_found = false; int num_regs = gdbarch_num_regs (gdbarch); @@ -360,7 +375,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, /* Check if the section is followed by a full SVE dump, and set sve_regs if it is. */ gdb_byte buf[4]; - uint16_t vq; + uint16_t flags; if (!tdep->has_sve ()) break; @@ -373,9 +388,23 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, } vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order)); - if (vq != tdep->vq) - error (_("Invalid vector length in signal frame %d vs %s."), vq, - pulongest (tdep->vq)); + /* If SME is supported, also read the flags field. It may + indicate if this SVE context is for streaming mode (SSVE). */ + if (tdep->has_sme ()) + { + if (target_read_memory (section + + AARCH64_SVE_CONTEXT_FLAGS_OFFSET, + buf, 2) != 0) + { + section += size; + break; + } + flags = extract_unsigned_integer (buf, 2, byte_order); + + /* Is this SSVE data? If so, enable the SM bit in SVCR. */ + if (flags & SVE_SIG_FLAG_SM) + svcr |= SVCR_SM_BIT; + } if (size >= AARCH64_SVE_CONTEXT_SIZE (vq)) sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET; @@ -384,6 +413,38 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, break; } + case AARCH64_ZA_MAGIC: + { + if (!tdep->has_sme ()) + { + section += size; + break; + } + + /* Check if the section is followed by a full ZA dump, and set + za_state if it is. */ + gdb_byte buf[2]; + + if (target_read_memory (section + AARCH64_SME_CONTEXT_SVL_OFFSET, + buf, 2) != 0) + { + section += size; + break; + } + svq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, + byte_order)); + + if (size >= AARCH64_SME_CONTEXT_SIZE (svq)) + { + za_state = section + AARCH64_SME_CONTEXT_REGS_OFFSET; + /* We have ZA data. Enable the ZA bit in SVCR. */ + svcr |= SVCR_ZA_BIT; + } + + section += size; + break; + } + case AARCH64_EXTRA_MAGIC: { /* Extra is always the last valid section in reserved and points to @@ -422,7 +483,7 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, for (int i = 0; i < 32; i++) { - offset = sve_regs + (i * tdep->vq * 16); + offset = sve_regs + (i * vq * 16); trad_frame_set_reg_addr (this_cache, AARCH64_SVE_Z0_REGNUM + i, offset); trad_frame_set_reg_addr (this_cache, @@ -440,12 +501,12 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, offset); } - offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (tdep->vq); + offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq); for (int i = 0; i < 16; i++) trad_frame_set_reg_addr (this_cache, AARCH64_SVE_P0_REGNUM + i, - offset + (i * tdep->vq * 2)); + offset + (i * vq * 2)); - offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (tdep->vq); + offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (vq); trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset); } @@ -461,6 +522,17 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, aarch64_linux_restore_vregs (gdbarch, this_cache, fpsimd); } + if (za_state != 0) + { + /* Restore the ZA state. */ + trad_frame_set_reg_addr (this_cache, tdep->sme_za_regnum, + za_state); + } + + /* If SME is supported, set SVCR as well. */ + if (tdep->has_sme ()) + trad_frame_set_reg_value (this_cache, tdep->sme_svcr_regnum, svcr); + trad_frame_set_id (this_cache, frame_id_build (sp, func)); } diff --git a/gdb/nat/aarch64-scalable-linux-sigcontext.h b/gdb/nat/aarch64-scalable-linux-sigcontext.h index 74407bd266a..18623443744 100644 --- a/gdb/nat/aarch64-scalable-linux-sigcontext.h +++ b/gdb/nat/aarch64-scalable-linux-sigcontext.h @@ -30,7 +30,10 @@ struct sve_context { struct _aarch64_ctx head; __u16 vl; - __u16 __reserved[3]; + /* Holds flags. This field was defined for SME support. Prior to it, + this used to be a reserved 16-bit value. */ + __u16 flags; + __u16 __reserved[2]; }; /* From patchwork Mon Sep 18 21:26:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76323 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 F141E3853D34 for ; Mon, 18 Sep 2023 21:29:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F141E3853D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072584; bh=AAi6OpWekDG/mBvfopWnDs4dEBzAQVGjlYAp3AhrCwo=; 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=mGzVeFa/GKqeY8TXEBYvA5QPhG+12+exTqvrslW3tXUWOD6grAEt8lLDW+zu+/Tvy yK1V3vmVlyg1T/LrQm9yjLIhtSC75JI523YZG89AaQokh92J0mgSEZWLeM1+oS+AEk xfn39hIR2XanswxG1jrYQsGaI8+U6HOv2c1sx6rk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2066.outbound.protection.outlook.com [40.107.21.66]) by sourceware.org (Postfix) with ESMTPS id A42163858D39 for ; Mon, 18 Sep 2023 21:27:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A42163858D39 Received: from DBBPR09CA0047.eurprd09.prod.outlook.com (2603:10a6:10:d4::35) by PAWPR08MB8837.eurprd08.prod.outlook.com (2603:10a6:102:336::16) 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:17 +0000 Received: from DBAEUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:d4:cafe::9a) by DBBPR09CA0047.outlook.office365.com (2603:10a6:10:d4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:17 +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 DBAEUR03FT064.mail.protection.outlook.com (100.127.143.3) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.13 via Frontend Transport; Mon, 18 Sep 2023 21:27:17 +0000 Received: ("Tessian outbound d084e965c4eb:v175"); Mon, 18 Sep 2023 21:27:17 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 3d62304cd03b7a45 X-CR-MTA-TID: 64aa7808 Received: from 3fb58d1d2eff.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 47AC993A-57A0-4D86-8466-D5CC2181ACB2.1; Mon, 18 Sep 2023 21:27:09 +0000 Received: from EUR05-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3fb58d1d2eff.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bM/Xup0OQe+j9+pQ+Hc6uiGdme9Ne2+ubJaU34JaiSM+eiytdcTCAikuzvnL4UxP1pPIW5baOnxeV3EximIJuSsdESHE3jGzzyYxZ/pUetgWsMIxAmgeZYxUH6PlmvP5j3z6uFo1x3t1ykEloYmahedA5dulvJQGSobjd2XesjwczOKLNODFD110ooa45pehCwxl46gc55IXEdCToIH+VxSWcNKMbw/USmY/wYPpDxiUNJeLopfS5PkA55wyojU8SFaPMW8TlR19DeoHomT+U0b5jCCi+bnWGkU4LV2WK5Hetx6gptqqd3g7mnIU4jmeG3iDMSc0Nvgc7TDirqWWGQ== 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=AAi6OpWekDG/mBvfopWnDs4dEBzAQVGjlYAp3AhrCwo=; b=LqIFiaCX0eaG/g4rO//+iiduAQXgvkmL3ErLcSqrVwzRP1O+0ga45FMTBdmdTMoKzyilflTUymV3R4IFqcGl0lLbW9K7SiTYZ+sDy05Tx0yxuP5gj2mH9lSVl6o4v2W56VZSEPsxntJQT/g3AQWsmdxBeeaEq6dPORKrIGAofYYF4abklfUkkN0vfgol8g49gXvADRaODBQOAiu4oewIpnvjOh5M36JYOOIPV/7B9o4hzL6VdlJfKhezK/1cO2cwcBBIzxg47MIMaIxN00vh1ML+MiLztXjv2gHhZO6RHDjvK/DNxxbkw+2KGRXJxQRcpDfGwYqyvqoX8ueHTw0Eng== 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 AM6P193CA0116.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::21) by DB9PR08MB9633.eurprd08.prod.outlook.com (2603:10a6:10:454::7) 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:06 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::8c) by AM6P193CA0116.outlook.office365.com (2603:10a6:209:85::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:06 +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:06 +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:05 +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:05 +0000 To: Subject: [PATCH v7 11/18] [gdb/aarch64] sme: Fixup sigframe gdbarch when vg/svg changes Date: Mon, 18 Sep 2023 22:26:44 +0100 Message-ID: <20230918212651.660141-12-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_|DB9PR08MB9633:EE_|DBAEUR03FT064:EE_|PAWPR08MB8837:EE_ X-MS-Office365-Filtering-Correlation-Id: d20c9d82-6547-4e0e-ef8d-08dbb88e08ab 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: ZbEpRszkqMlhpoz1gEd8j9BOdHvYZvjmn7LsLEu1YoYqKDFgFHTmtVKk4Zi+IrWZHErFI2EgQps8C+suhfkB4LOy+H0iWZTxH5BzS9lctitAeQWPDjLm4kYMF58H63xxSmFIx2A6Cs6HZtQul9Cf9vTdLe4CWMEMoYsuMZ12JhucpA/VRgbX/vjveLQMqOW8DislmhN+d1M44D3+Hr8K1K17cATu2GtE7EacBwIlcYscw+JA46JIxaydB3QJWuOPQmdo6mB/+OL8n/zNtySXW2STJt7kR9227j6ONZ8eLcfx4+Exw7bsTuQDP4j6Kuht+KKu+XRq25h9UlB+uPTdXCdEZY/U5PphLqzapEvMewPYQcuJidJKkIPDzVrLrGGVg8TIiOrD9UT9x3iRjmJqhEKfEqYCPiVj9TXh5rjgRCwlV4RoYQF+17fTV6XvWM5xjNvDvf0AYSomGrbYGTrnjvPimQ0PtM6JMdFSSGRlVtUz3MhcWDHw4oACisWfh/S4g2gKeN5O9RFh9s0j3CAYQbqnZuxdZaBUURnIsQ10MrIcAafkE9G4IOQKXCXhkLYR3oxCzOnd3iWI2+6LLa9sXfTcViD3SZK9kLTAYwzUkqUJ2LMw17ukIAi1EsratgDJ4ASH3dPeoD5iCnA3btQdfQJe2Nkri6rP8D/xqvKwQrSLgaBabWnbrcZTuVoBqpZDV+4hObI5X32jMbkORjwxblYx0a66UJidyCG4rp8hSUM1zvJea1o3A/sukOY1xDI00sn0nQaXIhkTuMweeutPFA== 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)(39860400002)(346002)(136003)(396003)(376002)(1800799009)(451199024)(82310400011)(186009)(36840700001)(46966006)(40470700004)(4326008)(2906002)(8676002)(8936002)(316002)(6916009)(41300700001)(26005)(426003)(1076003)(336012)(40480700001)(478600001)(30864003)(70206006)(70586007)(54906003)(44832011)(5660300002)(7696005)(40460700003)(36756003)(36860700001)(47076005)(2616005)(83380400001)(6666004)(66899024)(356005)(81166007)(86362001)(82740400003)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB9633 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 77cf040a-1473-497e-7b0c-08dbb88e022c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cHhCRW/VyiUmQtZGJuzUNhbL38a3LLn5MJJOZVS6+lIrIPR4GwWQhKJUKZV5CwcGNjDzdvxCX3A3ZxUawnIV7MzGUujtPWegTqYWs5aIsUY9kENhXy0as7Zy2ko+/shxwrT1VU+m/D5pxbkU3B+0XbklZXNiFPZ6DlKfFzELMDNS8VWPPBTWXf+OmlPAa5ez9cL5Yyp4HnKsSVgo3hh/Dbhac20ngzTj+PWEDx5R11nBkELYuRzrSBatCDZgJdaGuFhNZRXlVx2Pq2OHtpZbENjEj0IOdCFAyjAuCgAAbGqpZSB6nYHajeJkrb0cAqwRHlaL/eTZErxQRTGGxyvAHCGhOgF9b22IMgzdm/Yd2UfwAktdPF/tw+4E2KmisewHlfp29SkzmtY/bOdcuvkxQG9L4LIorl7uFymOZaxdWbHSuH931/lusfyrO2nddypDc1Fy1n6zEdLxxWcoH+JFlHrJJ5X4Ch3qrwUGasvVdjqeGWAFCpd7ft4W8ZyEaWQcTFSU+zBvKCSX59IofrQbKChUIVWDMjtM/LdjhnuJCxUSQGpRpEkT40a3JjecifRi2cZK+qWFO22XEcfnvL2OMR3VlC6ybT2WvKrvpYqzwt0FSDdyyHVcxWtWbcSr/UcQNkui4PuLbgWyY8kQITK8b6hIcFk7XOJE1FdJ7qTE1aCW30xCA8kyaMMGr8GHHJ0BiVR+W09i+fAE8mbyrHu5PVCoRiKGHOFWNHRk8U2khJypNSsHgg3o7dq0fZsIKenk 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)(136003)(346002)(376002)(39860400002)(396003)(451199024)(82310400011)(186009)(1800799009)(40470700004)(46966006)(36840700001)(66899024)(40480700001)(40460700003)(54906003)(6916009)(316002)(70586007)(70206006)(478600001)(2906002)(30864003)(86362001)(8936002)(8676002)(4326008)(41300700001)(44832011)(5660300002)(81166007)(83380400001)(36860700001)(47076005)(2616005)(82740400003)(6666004)(7696005)(426003)(336012)(1076003)(107886003)(26005)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:17.3253 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d20c9d82-6547-4e0e-ef8d-08dbb88e08ab 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: DBAEUR03FT064.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR08MB8837 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" Updates in v6: - Made gdb/tram-frame.h include gdb/frame-unwind.h for the function type. Updates in v4: - Addressed review comments --- With SME, where you have two different vector lengths (vl and svl), it may be the case that the current frame has a set of vector lengths (A) but the signal context has a distinct set of vector lengths (B). In this case, we may run into a situation where GDB attempts to use a gdbarch created for set A, but it is really dealing with a frame that was using set B. This is problematic, specially with SME, because now we have a different number of pseudo-registers and types that gets cached on creation of each gdbarch variation. For AArch64 we really need to be able to use the correct gdbarch for each frame, and I noticed the signal frame (tramp-frame) doesn't have a settable prev_arch field. So it ends up using the default frame_unwind_arch function and eventually calling get_frame_arch (next_frame). That means the previous frame will always have the same gdbarch as the current frame. This patch first refactors the AArch64/Linux signal context code, simplifying it and making it reusable for our purposes of calculating the previous frame's gdbarch. I introduced a struct that holds information that we have found in the signal context, and with which we can make various decisions. Finally, a small change to tramp-frame.c and tramp-frame.h to expose a prev_arch hook that the architecture can set. With this new field, AArch64/Linux can implement a hook that looks at the signal context and infers the gdbarch for the previous frame. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Approved-By: Simon Marchi Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-tdep.c | 278 +++++++++++++++++++++++++++------------ gdb/tramp-frame.c | 1 + gdb/tramp-frame.h | 5 + 3 files changed, 198 insertions(+), 86 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index f76d1888072..39855844ad0 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -184,6 +184,39 @@ #define AARCH64_SME_CONTEXT_SIZE(svq) \ (AARCH64_SME_CONTEXT_REGS_OFFSET + AARCH64_SME_CONTEXT_ZA_SIZE (svq)) +/* Holds information about the signal frame. */ +struct aarch64_linux_sigframe +{ + /* The stack pointer value. */ + CORE_ADDR sp = 0; + /* The sigcontext address. */ + CORE_ADDR sigcontext_address = 0; + /* The start/end signal frame section addresses. */ + CORE_ADDR section = 0; + CORE_ADDR section_end = 0; + + /* Starting address of the section containing the general purpose + registers. */ + CORE_ADDR gpr_section = 0; + /* Starting address of the section containing the FPSIMD registers. */ + CORE_ADDR fpsimd_section = 0; + /* Starting address of the section containing the SVE registers. */ + CORE_ADDR sve_section = 0; + /* Starting address of the section containing the ZA register. */ + CORE_ADDR za_section = 0; + /* Starting address of the section containing extra information. */ + CORE_ADDR extra_section = 0; + + /* The vector length (SVE or SSVE). */ + ULONGEST vl = 0; + /* The streaming vector length (SSVE/ZA). */ + ULONGEST svl = 0; + /* True if we are in streaming mode, false otherwise. */ + bool streaming_mode = false; + /* True if we have a ZA payload, false otherwise. */ + bool za_payload = false; +}; + /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the size, or return 0 on error. */ @@ -318,129 +351,115 @@ aarch64_linux_restore_vregs (struct gdbarch *gdbarch, } } -/* Implement the "init" method of struct tramp_frame. */ +/* Given a signal frame THIS_FRAME, read the signal frame information into + SIGNAL_FRAME. */ static void -aarch64_linux_sigframe_init (const struct tramp_frame *self, - frame_info_ptr this_frame, - struct trad_frame_cache *this_cache, - CORE_ADDR func) +aarch64_linux_read_signal_frame_info (frame_info_ptr this_frame, + struct aarch64_linux_sigframe &signal_frame) { - struct gdbarch *gdbarch = get_frame_arch (this_frame); - enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); - aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); - CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); - CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET - + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET ); - CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET; - CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE; - CORE_ADDR fpsimd = 0; - CORE_ADDR sve_regs = 0; - CORE_ADDR za_state = 0; - uint64_t svcr = 0; + signal_frame.sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM); + signal_frame.sigcontext_address + = signal_frame.sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET + + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET; + signal_frame.section + = signal_frame.sigcontext_address + AARCH64_SIGCONTEXT_RESERVED_OFFSET; + signal_frame.section_end + = signal_frame.section + AARCH64_SIGCONTEXT_RESERVED_SIZE; + + signal_frame.gpr_section + = signal_frame.sigcontext_address + AARCH64_SIGCONTEXT_XO_OFFSET; + + /* Search for all the other sections, stopping at null. */ + CORE_ADDR section = signal_frame.section; + CORE_ADDR section_end = signal_frame.section_end; uint32_t size, magic; - size_t vq = 0, svq = 0; bool extra_found = false; - int num_regs = gdbarch_num_regs (gdbarch); - - /* Read in the integer registers. */ + enum bfd_endian byte_order + = gdbarch_byte_order (get_frame_arch (this_frame)); - for (int i = 0; i < 31; i++) - { - trad_frame_set_reg_addr (this_cache, - AARCH64_X0_REGNUM + i, - sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET - + i * AARCH64_SIGCONTEXT_REG_SIZE); - } - trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, - sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET - + 31 * AARCH64_SIGCONTEXT_REG_SIZE); - trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, - sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET - + 32 * AARCH64_SIGCONTEXT_REG_SIZE); - - /* Search for the FP and SVE sections, stopping at null. */ while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0 && size != 0) { switch (magic) { case AARCH64_FPSIMD_MAGIC: - fpsimd = section; - section += size; - break; + { + signal_frame.fpsimd_section = section; + section += size; + break; + } case AARCH64_SVE_MAGIC: { /* Check if the section is followed by a full SVE dump, and set sve_regs if it is. */ gdb_byte buf[4]; - uint16_t flags; - - if (!tdep->has_sve ()) - break; + /* Extract the vector length. */ if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET, buf, 2) != 0) { + warning (_("Failed to read the vector length from the SVE " + "signal frame context.")); section += size; break; } - vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order)); - /* If SME is supported, also read the flags field. It may - indicate if this SVE context is for streaming mode (SSVE). */ - if (tdep->has_sme ()) + signal_frame.vl = extract_unsigned_integer (buf, 2, byte_order); + + /* Extract the flags to check if we are in streaming mode. */ + if (target_read_memory (section + + AARCH64_SVE_CONTEXT_FLAGS_OFFSET, + buf, 2) != 0) { - if (target_read_memory (section - + AARCH64_SVE_CONTEXT_FLAGS_OFFSET, - buf, 2) != 0) - { - section += size; - break; - } - flags = extract_unsigned_integer (buf, 2, byte_order); - - /* Is this SSVE data? If so, enable the SM bit in SVCR. */ - if (flags & SVE_SIG_FLAG_SM) - svcr |= SVCR_SM_BIT; + warning (_("Failed to read the flags from the SVE signal frame" + " context.")); + section += size; + break; } - if (size >= AARCH64_SVE_CONTEXT_SIZE (vq)) - sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET; + uint16_t flags = extract_unsigned_integer (buf, 2, byte_order); + /* Is this SSVE data? If so, we are in streaming mode. */ + signal_frame.streaming_mode + = (flags & SVE_SIG_FLAG_SM) ? true : false; + + ULONGEST vq = sve_vq_from_vl (signal_frame.vl); + if (size >= AARCH64_SVE_CONTEXT_SIZE (vq)) + { + signal_frame.sve_section + = section + AARCH64_SVE_CONTEXT_REGS_OFFSET; + } section += size; break; } case AARCH64_ZA_MAGIC: { - if (!tdep->has_sme ()) - { - section += size; - break; - } - /* Check if the section is followed by a full ZA dump, and set za_state if it is. */ gdb_byte buf[2]; + /* Extract the streaming vector length. */ if (target_read_memory (section + AARCH64_SME_CONTEXT_SVL_OFFSET, buf, 2) != 0) { + warning (_("Failed to read the streaming vector length from " + "ZA signal frame context.")); section += size; break; } - svq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, - byte_order)); + + signal_frame.svl = extract_unsigned_integer (buf, 2, byte_order); + ULONGEST svq = sve_vq_from_vl (signal_frame.svl); if (size >= AARCH64_SME_CONTEXT_SIZE (svq)) { - za_state = section + AARCH64_SME_CONTEXT_REGS_OFFSET; - /* We have ZA data. Enable the ZA bit in SVCR. */ - svcr |= SVCR_ZA_BIT; + signal_frame.za_section + = section + AARCH64_SME_CONTEXT_REGS_OFFSET; + signal_frame.za_payload = true; } - section += size; break; } @@ -456,11 +475,14 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET, buf, 8) != 0) { + warning (_("Failed to read the extra section address from the" + " signal frame context.")); section += size; break; } section = extract_unsigned_integer (buf, 8, byte_order); + signal_frame.extra_section = section; extra_found = true; break; } @@ -476,11 +498,48 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, if (!extra_found && section > section_end) break; } +} + +/* Implement the "init" method of struct tramp_frame. */ + +static void +aarch64_linux_sigframe_init (const struct tramp_frame *self, + frame_info_ptr this_frame, + struct trad_frame_cache *this_cache, + CORE_ADDR func) +{ + /* Read the signal context information. */ + struct aarch64_linux_sigframe signal_frame; + aarch64_linux_read_signal_frame_info (this_frame, signal_frame); + + /* Now we have all the data required to restore the registers from the + signal frame. */ + + /* Restore the general purpose registers. */ + CORE_ADDR offset = signal_frame.gpr_section; + for (int i = 0; i < 31; i++) + { + trad_frame_set_reg_addr (this_cache, AARCH64_X0_REGNUM + i, offset); + offset += AARCH64_SIGCONTEXT_REG_SIZE; + } + trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM, offset); + offset += AARCH64_SIGCONTEXT_REG_SIZE; + trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM, offset); - if (sve_regs != 0) + struct gdbarch *gdbarch = get_frame_arch (this_frame); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + /* Restore the SVE / FPSIMD registers. */ + if (tdep->has_sve () && signal_frame.sve_section != 0) { - CORE_ADDR offset; + ULONGEST vq = sve_vq_from_vl (signal_frame.vl); + CORE_ADDR sve_regs = signal_frame.sve_section; + + /* Restore VG. */ + trad_frame_set_reg_value (this_cache, AARCH64_SVE_VG_REGNUM, + sve_vg_from_vl (signal_frame.vl)); + int num_regs = gdbarch_num_regs (gdbarch); for (int i = 0; i < 32; i++) { offset = sve_regs + (i * vq * 16); @@ -510,30 +569,75 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset); } - if (fpsimd != 0) + /* Restore the FPSIMD registers. */ + if (signal_frame.fpsimd_section != 0) { + CORE_ADDR fpsimd = signal_frame.fpsimd_section; + trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM, fpsimd + AARCH64_FPSIMD_FPSR_OFFSET); trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM, fpsimd + AARCH64_FPSIMD_FPCR_OFFSET); /* If there was no SVE section then set up the V registers. */ - if (sve_regs == 0) + if (!tdep->has_sve () || signal_frame.sve_section == 0) aarch64_linux_restore_vregs (gdbarch, this_cache, fpsimd); } - if (za_state != 0) + /* Restore the SME registers. */ + if (tdep->has_sme ()) { - /* Restore the ZA state. */ - trad_frame_set_reg_addr (this_cache, tdep->sme_za_regnum, - za_state); + if (signal_frame.za_section != 0) + { + /* Restore the ZA state. */ + trad_frame_set_reg_addr (this_cache, tdep->sme_za_regnum, + signal_frame.za_section); + } + + /* Restore/Reconstruct SVCR. */ + ULONGEST svcr = 0; + svcr |= signal_frame.za_payload ? SVCR_ZA_BIT : 0; + svcr |= signal_frame.streaming_mode ? SVCR_SM_BIT : 0; + trad_frame_set_reg_value (this_cache, tdep->sme_svcr_regnum, svcr); + + /* Restore SVG. */ + trad_frame_set_reg_value (this_cache, tdep->sme_svg_regnum, + sve_vg_from_vl (signal_frame.svl)); } - /* If SME is supported, set SVCR as well. */ - if (tdep->has_sme ()) - trad_frame_set_reg_value (this_cache, tdep->sme_svcr_regnum, svcr); + trad_frame_set_id (this_cache, frame_id_build (signal_frame.sp, func)); +} - trad_frame_set_id (this_cache, frame_id_build (sp, func)); +/* Implements the "prev_arch" method of struct tramp_frame. */ + +static struct gdbarch * +aarch64_linux_sigframe_prev_arch (frame_info_ptr this_frame, + void **frame_cache) +{ + struct trad_frame_cache *cache + = (struct trad_frame_cache *) *frame_cache; + + gdb_assert (cache != nullptr); + + struct aarch64_linux_sigframe signal_frame; + aarch64_linux_read_signal_frame_info (this_frame, signal_frame); + + /* The SVE vector length and the SME vector length may change from frame to + frame. Make sure we report the correct architecture to the previous + frame. + + We can reuse the next frame's architecture here, as it should be mostly + the same, except for potential different vg and svg values. */ + const struct target_desc *tdesc + = gdbarch_target_desc (get_frame_arch (this_frame)); + aarch64_features features = aarch64_features_from_target_desc (tdesc); + features.vq = sve_vq_from_vl (signal_frame.vl); + features.svq = (uint8_t) sve_vq_from_vl (signal_frame.svl); + + struct gdbarch_info info; + info.bfd_arch_info = bfd_lookup_arch (bfd_arch_aarch64, bfd_mach_aarch64); + info.target_desc = aarch64_read_description (features); + return gdbarch_find_by_info (info); } static const struct tramp_frame aarch64_linux_rt_sigframe = @@ -550,7 +654,9 @@ static const struct tramp_frame aarch64_linux_rt_sigframe = {0xd4000001, ULONGEST_MAX}, {TRAMP_SENTINEL_INSN, ULONGEST_MAX} }, - aarch64_linux_sigframe_init + aarch64_linux_sigframe_init, + nullptr, /* validate */ + aarch64_linux_sigframe_prev_arch, /* prev_arch */ }; /* Register maps. */ diff --git a/gdb/tramp-frame.c b/gdb/tramp-frame.c index c69ee6efc2c..94e42e9fec1 100644 --- a/gdb/tramp-frame.c +++ b/gdb/tramp-frame.c @@ -170,5 +170,6 @@ tramp_frame_prepend_unwinder (struct gdbarch *gdbarch, unwinder->stop_reason = default_frame_unwind_stop_reason; unwinder->this_id = tramp_frame_this_id; unwinder->prev_register = tramp_frame_prev_register; + unwinder->prev_arch = tramp_frame->prev_arch; frame_unwind_prepend_unwinder (gdbarch, unwinder); } diff --git a/gdb/tramp-frame.h b/gdb/tramp-frame.h index fa0241acb2d..0ab082dbc64 100644 --- a/gdb/tramp-frame.h +++ b/gdb/tramp-frame.h @@ -21,6 +21,7 @@ #define TRAMP_FRAME_H #include "frame.h" /* For "enum frame_type". */ +#include "frame-unwind.h" /* For frame_prev_arch_ftype. */ class frame_info_ptr; struct trad_frame_cache; @@ -75,6 +76,10 @@ struct tramp_frame int (*validate) (const struct tramp_frame *self, frame_info_ptr this_frame, CORE_ADDR *pc); + + /* Given the current frame in THIS_FRAME and a frame cache in FRAME_CACHE, + return the architecture of the previous frame. */ + frame_prev_arch_ftype *prev_arch; }; void tramp_frame_prepend_unwinder (struct gdbarch *gdbarch, From patchwork Mon Sep 18 21:26:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76325 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 D8A053872C17 for ; Mon, 18 Sep 2023 21:30:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D8A053872C17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072611; bh=0lvMPLWmM2b1RL2bR4i0X6K+4NBJJD30jsq6B25iMVk=; 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=jJN79yD3jily2iBxlfJtC8ZFUTaOUBp5GAOMkZfLX2yxq5bkiQWbw5SZ7oS6REGdE b4oTyjlsRC7ngXngLR4K1m1Rlm4Py9GseDcxZ2kRCnIKt3tAT3azpjv+mQQBzJYBQj IoHZBFTXnPEz4wlqwMZsvcd2fggYdrT62AYt6x2M= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2058.outbound.protection.outlook.com [40.107.20.58]) by sourceware.org (Postfix) with ESMTPS id 40601385840D for ; Mon, 18 Sep 2023 21:27:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 40601385840D Received: from AM6PR10CA0032.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:89::45) by DU2PR08MB7374.eurprd08.prod.outlook.com (2603:10a6:10:2f2::16) 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:19 +0000 Received: from AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:89:cafe::9c) by AM6PR10CA0032.outlook.office365.com (2603:10a6:209:89::45) 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:18 +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 AM7EUR03FT047.mail.protection.outlook.com (100.127.140.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:18 +0000 Received: ("Tessian outbound 1eb4e931b055:v175"); Mon, 18 Sep 2023 21:27:18 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: e6855c966f11ea32 X-CR-MTA-TID: 64aa7808 Received: from e09ae13c50ea.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C383B6E6-D98E-4AE6-B8E2-568B1323892A.1; Mon, 18 Sep 2023 21:27:12 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id e09ae13c50ea.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b/a7mMe3rss/6/UaaeXUgsxTfeXY6jxKed5QkwDrZ+8qjKH9OmMnG+2OqBsZnpkDPqDyiQ2c+JFIlz54/eppf1oPgonFxyPzCWs/OBujEVCsGdCB88yIbv1/Z9Arb/JfeyMkC/L2qRrbvh7M5+JHxiJU5lY1KnugsaMiiYU+zmYscE+/1QybiISgz40aBh9REUS6Kl6AYmWBV7GqN83z+YxyAhZog/C7EYsGj8Scax3YMA9+pn2Iuw5V2C7/R8oC17ZLXjtGvBkAcRGpZ+GOdUtYOQIachYdwTZI9qJsfbNXioqlPpvt4SuFydYA6LPI4kwHyVt8mLlj5ojTTVb9VA== 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=0lvMPLWmM2b1RL2bR4i0X6K+4NBJJD30jsq6B25iMVk=; b=cXsLqPHRQZG2WBd3A6D0rYdu/CxNZw5lNfn8dHwOL9rWV/9LyWZzL9vasJ2W+DwOfYeXyxvb3em+DY1Qvw+gcGcApQjzLw0F56CREfvE+2YMAj1PvSWQbiYxGMRxWtRO3cPujdSvdj8pDWNBK8MIJ0OhdJZalHKTcwryPCT7Svhf6/jKGMUngZ68Lgy5O1fdfaLjdcBne66KUD2h0WdBs1iMuxSHEZOkCxCr0YiX5dOMgJJi1BBqRQtxugkwc0ZwpinzJJ6Og8uzlPcAUx4wdMwFELU1ScQldddlkQ3tRsfnbbJoOlN4W1ysuWb0fAQJYMUZz06ENj50ntA7lyxi8Q== 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 AS8PR05CA0024.eurprd05.prod.outlook.com (2603:10a6:20b:311::29) by GV2PR08MB8097.eurprd08.prod.outlook.com (2603:10a6:150:75::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 21:27:08 +0000 Received: from AM7EUR03FT064.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:311:cafe::50) by AS8PR05CA0024.outlook.office365.com (2603:10a6:20b:311::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:07 +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 AM7EUR03FT064.mail.protection.outlook.com (100.127.140.127) 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:07 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) 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:06 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:06 +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:05 +0000 To: Subject: [PATCH v7 12/18] [gdb/aarch64] sme: Support TPIDR2 signal frame context Date: Mon, 18 Sep 2023 22:26:45 +0100 Message-ID: <20230918212651.660141-13-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: AM7EUR03FT064:EE_|GV2PR08MB8097:EE_|AM7EUR03FT047:EE_|DU2PR08MB7374:EE_ X-MS-Office365-Filtering-Correlation-Id: f967298d-bebb-42ff-00df-08dbb88e0993 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: Und+BbOOh4+P9to/5BOOxnWDaIg+P2q8SQ38J5488NlJ5S9s2N0Zz6hD+8Zj1esdwNhgqpf0P648NRYwYK37JOJAJ+aQO7LlKAD7dQVxVPEuWsDv/1sPNfOPaDtvj8uBYGmAOEvEyXmLTuk8KbdMWjRh0tZqtnPIn5BPUlY/IYVW8opwNd4SeQ4Bh3vPDjMBYCJPw0umBRjSM9BjnuNsI/PUQqz2NFap64wa5lTqc98D/kymnyujM9dPo/qLvPf7qsfKfsXSuXFI3uBM5Efuns2kA0S0zNmzBElDRsnxDmvXFq+3bYO1G3qeI83XRtcQr3HZ1fvICAtekOujtpNmbAlfphKARXNaCfxODg83tScC5sQ6LfxcldbU7HaoDOhFMCkboId3o6SyHJS+LkX3iRrpBM9GTtx5d/7qmn2oci9sTM519RecfseC+e9pyuVy8d6danzcLDgI8Rl6Ag1l4l3tcSCEvbNggUHba1gESNygVB4WF2pVoCbZlzS/CFePNnc8gk0xFKMwHxWfkddQG9cLYOTm/tUX4IbqzbmL8qWpgyl3PNPvpz9k0CKEXWWEitiTeMSvKMmuadrkv5vChwFMJ5HnMlhbrICRbWTCzbcXcd2uRU46IgSLvfbJYgAIAdX0CGsrIHiX6sAtLbu14wYoH5qXDV/NVH2zK18qw9zIlwvxUdD+eTupCNO3oZX4Wz5i2Z/blPcV162KtTPsOhxgJqOQ5k27w1Pg7GTS7TKwdwDQqlYVYUWPoH/Z6spTfmYPzb8ZgLncBxZ2U/DPkQ== 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)(39860400002)(376002)(396003)(136003)(346002)(451199024)(1800799009)(186009)(82310400011)(36840700001)(46966006)(40470700004)(6666004)(7696005)(83380400001)(82740400003)(36756003)(40460700003)(86362001)(81166007)(40480700001)(356005)(36860700001)(1076003)(26005)(2616005)(47076005)(2906002)(426003)(336012)(478600001)(44832011)(8936002)(8676002)(6916009)(4326008)(5660300002)(41300700001)(316002)(70586007)(70206006)(54906003)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8097 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 6b9f7148-5924-4315-4bee-08dbb88e02ef X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Px6hga1ihyLqonRaG6uaQQXe61S4tXKt7SeOUB1sPBXHuvasaW7dcobKVUIV2wgVgYc+w4geqYMwmLN4sLwJXPTEbq/7hee/OP9gd2S3B40qbjxqDe/CQ3xwvxlvxzmFxOkSwn9OhYqagX3nss/j4GIZhnWCld4Mtb/TlV7SqtuA1oPbN+CrMxqsIJ8/GoHBN5LgDcwXkBGN4z1bx4PDyu5sNcWjyb3NM6CKSF6PfvGxN7/FVzYLA1fixA1xSjY2/hMB8bnzbTKoEIYLxt/lg+MvbSqOtqMAc83s5OEgfWDDIS7wrl+hbBfg5Qvs7bwKdkujdtl72QU1QktF0QTGYnt0SZYdlEB+Dry9+U6+l3befJMbf4ekRPh90oPM6/scFv+GJyPPCmSfreZfjG8Th7qbx0Rf0DghStKoJmXRQRrPROrY3YfglP8YeDgEJIjpXd9fhTQ3a89UMF3iN4G7S2hHWjRUMleHiiBx+3rRHeaiP2IEoWsvIPK2mV+DSE/OqOo1f1UhFdmeXcY7W4B10ez3VCV1tpuCYPIxHgtECrXMDD7+okyf0ap55L4HbThWT0qMEeqRbHtfIFpokLSb0hGchFKCasb3B1wRviSQsFv7wCYbozjHYBuNZfwK3sd4hNz3LW3EySpqK7et7dgHuUD5g5EycvkGQWGJyS+BwQ726pr6HYUmSYc3NTnHMPmybRxC/YW8dISkYCSdmZTkgyhfp6da+bAdHRbpOQZ5vJIcrHopk9ozNZKhFRzoDvVq 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)(39850400004)(396003)(376002)(346002)(136003)(1800799009)(186009)(451199024)(82310400011)(40470700004)(36840700001)(46966006)(107886003)(47076005)(1076003)(2616005)(336012)(426003)(44832011)(5660300002)(4326008)(8936002)(8676002)(7696005)(82740400003)(36860700001)(83380400001)(26005)(478600001)(6666004)(81166007)(40480700001)(316002)(70586007)(70206006)(41300700001)(54906003)(6916009)(86362001)(36756003)(2906002)(40460700003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:18.7927 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f967298d-bebb-42ff-00df-08dbb88e0993 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: AM7EUR03FT047.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR08MB7374 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" The Linux Kernel defines a separate context for the TPIDR2 register in a signal frame. Handle this additional context in gdb so this register gets restored properly when unwinding through signal frames. The TPIDR2 register is closely related to SME, and is available when SME support is reported. This is tested by testcases that are available in a later patch in the series. Regressions-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-tdep.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 39855844ad0..47e5e1db641 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -154,6 +154,7 @@ #define AARCH64_FPSIMD_MAGIC 0x46508001 #define AARCH64_SVE_MAGIC 0x53564501 #define AARCH64_ZA_MAGIC 0x54366345 +#define AARCH64_TPIDR2_MAGIC 0x54504902 /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */ #define AARCH64_EXTRA_DATAP_OFFSET 8 @@ -184,6 +185,9 @@ #define AARCH64_SME_CONTEXT_SIZE(svq) \ (AARCH64_SME_CONTEXT_REGS_OFFSET + AARCH64_SME_CONTEXT_ZA_SIZE (svq)) +/* TPIDR2 register value offset in the TPIDR2 signal frame context. */ +#define AARCH64_TPIDR2_CONTEXT_TPIDR2_OFFSET 8 + /* Holds information about the signal frame. */ struct aarch64_linux_sigframe { @@ -204,6 +208,8 @@ struct aarch64_linux_sigframe CORE_ADDR sve_section = 0; /* Starting address of the section containing the ZA register. */ CORE_ADDR za_section = 0; + /* Starting address of the section containing the TPIDR2 register. */ + CORE_ADDR tpidr2_section = 0; /* Starting address of the section containing extra information. */ CORE_ADDR extra_section = 0; @@ -464,6 +470,13 @@ aarch64_linux_read_signal_frame_info (frame_info_ptr this_frame, break; } + case AARCH64_TPIDR2_MAGIC: + { + /* This is context containing the tpidr2 register. */ + signal_frame.tpidr2_section = section; + section += size; + break; + } case AARCH64_EXTRA_MAGIC: { /* Extra is always the last valid section in reserved and points to @@ -605,6 +618,17 @@ aarch64_linux_sigframe_init (const struct tramp_frame *self, sve_vg_from_vl (signal_frame.svl)); } + /* Restore the tpidr2 register, if the target supports it and if there is + an entry for it. */ + if (signal_frame.tpidr2_section != 0 && tdep->has_tls () + && tdep->tls_register_count >= 2) + { + /* Restore tpidr2. */ + trad_frame_set_reg_addr (this_cache, tdep->tls_regnum_base + 1, + signal_frame.tpidr2_section + + AARCH64_TPIDR2_CONTEXT_TPIDR2_OFFSET); + } + trad_frame_set_id (this_cache, frame_id_build (signal_frame.sp, func)); } From patchwork Mon Sep 18 21:26:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76322 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 D71DE386F5F3 for ; Mon, 18 Sep 2023 21:29:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D71DE386F5F3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072573; bh=9UmdYXnaxTBc4xXVGN7BKdoeEX0de5ebIDwrzj0KK2c=; 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=nwEu1Vgi2OqZcV/becSAttEvsUPwVU5+YSpYdpI+d1yyecGSWfcW+D9piavSPBhzD EXJyscNcOKz1Vorpp4hylXQwaOPi2ABzULMar5KmHItrfa+QlrjCYi/b+KwlUX8mVD ciDY3knalGut2JDJiYYYMQpi0tIuNV4iPCcRPSIU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2072.outbound.protection.outlook.com [40.107.14.72]) by sourceware.org (Postfix) with ESMTPS id C60FC3857438 for ; Mon, 18 Sep 2023 21:27:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C60FC3857438 Received: from AS9PR06CA0243.eurprd06.prod.outlook.com (2603:10a6:20b:45f::6) by DU0PR08MB8640.eurprd08.prod.outlook.com (2603:10a6:10:400::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.24; Mon, 18 Sep 2023 21:27:16 +0000 Received: from AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45f:cafe::e) by AS9PR06CA0243.outlook.office365.com (2603:10a6:20b:45f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:16 +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 AM7EUR03FT039.mail.protection.outlook.com (100.127.140.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:16 +0000 Received: ("Tessian outbound 5c548696a0e7:v175"); Mon, 18 Sep 2023 21:27:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 2bb4972aaa581a3b X-CR-MTA-TID: 64aa7808 Received: from d5e1bc342ab8.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 91B17659-F263-4A31-8449-D9A18D25F075.1; Mon, 18 Sep 2023 21:27:09 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id d5e1bc342ab8.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MhJi+asOb492ANcDXKIRPu9YpK9Db9rHKm88z+gdWJ+44db/mZ4CsmBYybnBPxQSgfQLL8QnOyKUhkFNBINMNkP3+ljxMVb2v6Mwr7p9Z4FDXA+DMeppZDgRwtEH/81NIzt1uvYDgDDkA2px+8j/cu2FXSobAqzsTF+792fFMjX3msYtExwFR1YO32CunSZs/Y22abrvKxx61C7nGkiDAbrRL/OMc5k1CUXzjHKwtyj8jHV7tTu6y2ju3+21V0ElziB7XZUB5uLfUJqoKx8+WNErsw2W53HyPe1MSGEZ7IsZdO6Qq/ZBPrGtfRHQUVpo4MALzfXig9nACYSJDoHfDw== 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=9UmdYXnaxTBc4xXVGN7BKdoeEX0de5ebIDwrzj0KK2c=; b=hEFuu3VT93A6D+36J8BPuIvybFzwF7/WiJUvYd56cu0GDJXBGoskpKQj/faSGq1VAJ7ThWRpTYAf0FU0izQDIicjFFEpdNs7HIjClPycUDhdoWDCj2O/njK0EleGI1XDKONdwuU7x3gt0rLhVuYY+lp8KO8fJjC+IBNXHcydzI+nHS6Y8vwb1M7c4SlpAx2b0qkaT6fC4lLwXx4vLUHIs4nJZ+zprxinW7PPl8iT0PHCuO6wY5lYGWS+GNouz5X9xYsQ96f5vuzQXLEkunuNmxQY5o2RAJD8EgggVhrT1boFQGZTvT7VvgCkHrHrO1bK97SfO/4Vy3oPfHLS1M9BTg== 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 AM6P193CA0124.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::29) by AM8PR08MB6577.eurprd08.prod.outlook.com (2603:10a6:20b:355::11) 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:07 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::c0) by AM6P193CA0124.outlook.office365.com (2603:10a6:209:85::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:07 +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:07 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:06 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:06 +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:06 +0000 To: Subject: [PATCH v7 13/18] [gdb/generic] Get rid of linux-core-thread-data Date: Mon, 18 Sep 2023 22:26:46 +0100 Message-ID: <20230918212651.660141-14-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_|AM8PR08MB6577:EE_|AM7EUR03FT039:EE_|DU0PR08MB8640:EE_ X-MS-Office365-Filtering-Correlation-Id: 0b132503-7726-481a-ce0a-08dbb88e080d 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: 3kIVo1wzOexCrzJFundqx5v2VpskaxF6F2E7Rx/KZ4NoBNKggF3oOx/Hu4/ltqlAcALbhr8QAFAXUT8DMsXOtXSVXDghj+BM6hljSpsKhSIQN4s4H0YJ93TYPqt/WLu6NDjGoHsy/JzGAWqWHkMmArV/wc4zmzrPZzPiYLPFHmm+SbsO+m89pcqjCxDQhI8RZ74pKZ6iP04cvD+Go5JGGnp7SPJdEobQytWMctY9M8ek3GyQO0eMBuxvBVrYRE6FOW8oJymukhA/iF4IoODW/XwUOJQ+MOUEXAa9sJtJ/a1wXQtsahL847H9Rt+1WHQA5trEUKiOXpoU4ifiV8j4xPvX1hGbtb6+9ZZ5LqMBHFQU6nNCXANn3mNeRgd370VkrTozirHNrTviK1j1iHDW+FBENoZDVMSzts1fFVXz5xo6yJABnwrBBFJO/rHov2vUzKT32dSj1Lz5ipt8asS2MIDP+l3U0imIwVSyNqY/1v8JVEpFd7JEpqniC2Xw84yqQUdWONANNurOdkz7rrcWdm/PhRUuO8Gy6tHi3j2g7065Tz0DCSknnbjV1U/1JjBrZjclSSlDtangUJhjz/Lu3+P00r2rxc9+AZc1M9s2FcxW6NeHh/n15TsV/l+OWkKenfZRw8bj7TuJzkvPQprEue37bo58KI+LuZIINjIc/B6X3wsDJ7r413fAP6LNEH4V84iA1iWvf/zQZODeqG7OkApmANZf0gss3r+uuRCKVcDnUcomlXBXK1HjsjEAqYMQnC7MUdm5B5YgVe2aEgb7ejH0vaXbC+V7TEI+GkJbjvdZOFbqELQNJfxn5YYul9KO 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)(346002)(39860400002)(136003)(376002)(396003)(82310400011)(1800799009)(451199024)(186009)(46966006)(36840700001)(40470700004)(2616005)(70586007)(70206006)(54906003)(316002)(6916009)(82740400003)(41300700001)(36860700001)(7696005)(6666004)(5660300002)(8936002)(1076003)(4326008)(8676002)(86362001)(478600001)(44832011)(26005)(426003)(336012)(83380400001)(36756003)(40460700003)(40480700001)(356005)(81166007)(2906002)(47076005)(26583001)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6577 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e454b01b-b112-4c20-fc42-08dbb88e02b1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u7JnnhLjKfSPrY9axea65ZaFnen7NauJWutHBwjryGP86gRarjfHgRvUvbOV3tlpNydBgtA9d7Ac8H8mJTywr7eJo4KOL10ot7S3otaPBV+JfyS7MH/WFXzoXHNf7JFRxFjVxY7rHicAN1vn45iN0wtrmdrXw5z404C0OEIg2rOeixpz7k68eTn+wVVoisZ8vX/WFiTmANbAG+4TdlW0UgnRoMGiglWpgvoOgVO3ximMeO+0kznvSr6EqbN6/99TxzxtQEpgmtzLoz5yTspMEEGlVi0lywHFIpATtcTq/KHJJpHGUSqdJArDTM2MqjUObRElBdovU0iu3Tc7pAjCH6mwR3+4Er+y7HA8Uk9boJTXwR0q/rlD9m2P10VjvgQmRxtO06o1opDZjsFCT9NZut+pROHBPnzSiGmGbqyfts0HBUVVDZgnjZpixl043zzGdQN8gGzYAoFXlCTqVecw/+qAJnuyYCpn6nptG972lus3VArdZ17y7/JKs/aZGKQhuP4OnUJFp4vKeIZYEyFGlUhXmUOS5agW8ayfvcgX8IuWN6AvcW8ojWKOhizv0OTFRNLuPQbdB+pIEDiAjVz5bBdTCwMlY3klJFAGpRI2MUiePMzoO39LJvhOSp+1Q6BqfSMq0MUfVtQBq3/9Tsj0mEiHeRULq+WkIyG015Dt0Ba7+RIU21Qu2cSc/cuqFz7TEv3OuQ1BgxBDLmQAV+Z0L8eceBWXctgxr9c3tWQvX/EoDClHio0yFtZfFMf+kE0lcj7UbMwNtlSSbgFrtWBt421+gl6M7Ln/Sa8VmiV0qA8= 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)(376002)(39860400002)(346002)(396003)(136003)(451199024)(82310400011)(186009)(1800799009)(36840700001)(46966006)(40470700004)(40480700001)(5660300002)(44832011)(7696005)(86362001)(54906003)(316002)(41300700001)(70586007)(70206006)(6666004)(478600001)(6916009)(8936002)(2616005)(8676002)(81166007)(26005)(82740400003)(2906002)(36860700001)(36756003)(47076005)(336012)(426003)(107886003)(40460700003)(1076003)(4326008)(83380400001)(26583001)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:16.2421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 0b132503-7726-481a-ce0a-08dbb88e080d 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: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8640 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" This struct type seems to have been used in the past as a callback parameter. Now it seems that case is no longer true, so we can simplify things by passing the individual parameters linux_core_thread_data encapsulates directly to the functions. This is just a cleanup before the next change. Approved-By: Simon Marchi --- gdb/linux-tdep.c | 49 +++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index b5eee5e108c..a4a86b01bdb 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -1820,47 +1820,29 @@ linux_get_siginfo_data (thread_info *thread, struct gdbarch *gdbarch) return buf; } -struct linux_corefile_thread_data -{ - linux_corefile_thread_data (struct gdbarch *gdbarch, bfd *obfd, - gdb::unique_xmalloc_ptr ¬e_data, - int *note_size, gdb_signal stop_signal) - : gdbarch (gdbarch), obfd (obfd), note_data (note_data), - note_size (note_size), stop_signal (stop_signal) - {} - - struct gdbarch *gdbarch; - bfd *obfd; - gdb::unique_xmalloc_ptr ¬e_data; - int *note_size; - enum gdb_signal stop_signal; -}; - /* Records the thread's register state for the corefile note section. */ static void linux_corefile_thread (struct thread_info *info, - struct linux_corefile_thread_data *args) + struct gdbarch *gdbarch, bfd *obfd, + gdb::unique_xmalloc_ptr ¬e_data, + int *note_size, gdb_signal stop_signal) { - gcore_elf_build_thread_register_notes (args->gdbarch, info, - args->stop_signal, - args->obfd, &args->note_data, - args->note_size); + gcore_elf_build_thread_register_notes (gdbarch, info, stop_signal, obfd, + ¬e_data, note_size); /* Don't return anything if we got no register information above, such a core file is useless. */ - if (args->note_data != NULL) + if (note_data != nullptr) { gdb::byte_vector siginfo_data - = linux_get_siginfo_data (info, args->gdbarch); + = linux_get_siginfo_data (info, gdbarch); if (!siginfo_data.empty ()) - args->note_data.reset (elfcore_write_note (args->obfd, - args->note_data.release (), - args->note_size, - "CORE", NT_SIGINFO, - siginfo_data.data (), - siginfo_data.size ())); + note_data.reset (elfcore_write_note (obfd, note_data.release (), + note_size, "CORE", NT_SIGINFO, + siginfo_data.data (), + siginfo_data.size ())); } } @@ -2095,17 +2077,16 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) else stop_signal = GDB_SIGNAL_0; - linux_corefile_thread_data thread_args (gdbarch, obfd, note_data, note_size, - stop_signal); - if (signalled_thr != nullptr) - linux_corefile_thread (signalled_thr, &thread_args); + linux_corefile_thread (signalled_thr, gdbarch, obfd, note_data, note_size, + stop_signal); for (thread_info *thr : current_inferior ()->non_exited_threads ()) { if (thr == signalled_thr) continue; - linux_corefile_thread (thr, &thread_args); + linux_corefile_thread (thr, gdbarch, obfd, note_data, note_size, + stop_signal); } if (!note_data) From patchwork Mon Sep 18 21:26:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76329 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 DE4B8383CAAC for ; Mon, 18 Sep 2023 21:30:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DE4B8383CAAC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072645; bh=xlZ+UHdC6mDnVmWZlDPVyBXmN8XiqtRTeQvl3R5DY30=; 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=PlxC/15h0YSZwltmAlB4leycmWvJdJ9c9AqAzmk54qqt5QU19crm1lm+JxXhpMR2O NSzhc4KyERN3cehxtkPYeGboi8EKQk/yKYw4e0psajMoMX49NnZn52dwxxES09oJdV oa+M6QJzVFGI3J5XXAUwqJRULAUe01havzbJXul4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2083.outbound.protection.outlook.com [40.107.21.83]) by sourceware.org (Postfix) with ESMTPS id 6ACD23858C50 for ; Mon, 18 Sep 2023 21:27:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6ACD23858C50 Received: from DUZPR01CA0086.eurprd01.prod.exchangelabs.com (2603:10a6:10:46a::13) by DU0PR08MB8042.eurprd08.prod.outlook.com (2603:10a6:10:3e6::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:16 +0000 Received: from DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:46a:cafe::32) by DUZPR01CA0086.outlook.office365.com (2603:10a6:10:46a::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:16 +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 DBAEUR03FT059.mail.protection.outlook.com (100.127.142.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.14 via Frontend Transport; Mon, 18 Sep 2023 21:27:16 +0000 Received: ("Tessian outbound d084e965c4eb:v175"); Mon, 18 Sep 2023 21:27:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: d81631a5b2a8102c X-CR-MTA-TID: 64aa7808 Received: from a57c0351156c.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 0A0FD283-9F6C-4774-917C-DB029E13AFA8.1; Mon, 18 Sep 2023 21:27:08 +0000 Received: from EUR05-DB8-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id a57c0351156c.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=fAUaO8JMo856YE1CtXEY94J4AejSjASyn1j2b719L6G+WOrW1Lb1l0OFHsoFnDZsGZI5McfwNUNarUKNXX6a3SUkPWyXzy6EazembrDKMOvfp4+9Ca+GwbOzSmZHtJUCcVVJKTQsTOPTZM0fg4Ltt9PkHByXylqjWnA4WU/L2YBJMwE/kw0mkA0nclL33CMkEtnuP0N/kxSEaukrOhe4oa+rQrwimguYNnjazds5zD44uF1ywqEFzr0AsMGCWxnGnT3O4TZdblheVQyFKSg4aEGFhAkdu0NJVHt/m2g/oA0zvxgBUZ9ByPUegdltSYENTMQvYCjCaC/mOIp0rBUQLQ== 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=xlZ+UHdC6mDnVmWZlDPVyBXmN8XiqtRTeQvl3R5DY30=; b=TZH+cpbOBriRnWEKHYFdQUfbrSRRURaAU09qiEO+lu/RV42cyiY9yJxfWtiBJrhXefOclIfF8MoAUh60TZuCREjkwEvjwum4QNxtXcrSK1zaQaf0XkAGU6khNP0cTyhz01sELBnElk2ShxEbCDE/KT+8oH4BmH2tKdUrpb7nbyuntalPObF+68bU6Jidt60dglNY9tfUVYCuMp4pSmSOGRdoVWBOIh9dUdsbQnfXxZvo69oWdikKiwT8+MXtZZSNBkXVZ+3R7L/KIoNUoUgymPb4gJJiBt8eCzHpke3SE1QeALpRKz8THyCP13OCmC/Hggw8zjijnAT0IyhLn6+wXQ== 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 AM6P193CA0142.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::47) by DB5PR08MB10048.eurprd08.prod.outlook.com (2603:10a6:10:48e::22) 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:07 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::9a) by AM6P193CA0142.outlook.office365.com (2603:10a6:209:85::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:07 +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:07 +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:07 +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:06 +0000 To: Subject: [PATCH v7 14/18] [gdb/generic] corefile/bug: Use thread-specific gdbarch when dumping register state to core files Date: Mon, 18 Sep 2023 22:26:47 +0100 Message-ID: <20230918212651.660141-15-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_|DB5PR08MB10048:EE_|DBAEUR03FT059:EE_|DU0PR08MB8042:EE_ X-MS-Office365-Filtering-Correlation-Id: 1fb96950-68db-40a5-a52a-08dbb88e080c 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: npotTvnoDAwhOHjizrSlE8Fk2a7kOn78lZTEz1hlyEFjTmkxhJDCDOZozu0gKwvUVrQ1/YuhTPwwDavmL5IUeGxR2pYsYu+8wsaYxF3/U6l6IvCmt6qmkqHi8AmYJxFZD8hFQYKgFLTVynwkX7/mRl0t+Lmba8ku4bJyXnqVkLVjl4Si5KDWvxdVt56wv+B+bylJyeWXjZiohbZBWRZX1YNmwXeTPPFLEMtcEq6trLodTluDGMc4Ja8JYIpBkA1sdm/lMYat575y11I1cl/r350qprOlkyvC0bvqEH4Ld2bfFr+n5+t1scihWh31bLapN4o8Qx0KvLdMVaWFiFXyj3o9INQ0p6oaaBH6m+zegMoTjmWWvoVkL7YJIKJCXkPZbWFOY0KCDxxn4l+0jfQjHklNe9vSdQ+MYJn25cQgovJZZXFvsC7sGlwCJfR9Qb5TDD8Ak30wyOCHiaYP1jtBx1DgES7LR/z12UvvXjK9iipWS/6ydRjpFgFIBWY7mUl628XcjBNahCUMkFm5AjP6jcOCk9ga9DBe0VtiO4FOV4SXp93grN6+grg/QDPgKPdQ0Y+7DwnuRXmuF6MUP8ovBgKqRL5jqvUZbJOITJnxagojlZpQW/m8DPzDOd9UhZG6F6ilOfg/RDg1h/gWYqupVPXEE2g3+kWhVgsJ71aGfe7wF10JNGBgb7CueVAFuQM1K+Pf0Z8DqR3zr4gA4YJBqdGQpxLxvfLapkVL41MKBSAPpam+6ScUtl9imShTX99+LvSxORWbdQ8XqsubLbJ0og== 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)(39850400004)(376002)(346002)(396003)(136003)(82310400011)(451199024)(186009)(1800799009)(36840700001)(46966006)(7696005)(6666004)(83380400001)(82740400003)(81166007)(356005)(86362001)(36860700001)(47076005)(36756003)(2616005)(426003)(336012)(1076003)(40480700001)(26005)(6916009)(316002)(54906003)(70586007)(70206006)(41300700001)(2906002)(5660300002)(44832011)(8936002)(8676002)(4326008)(478600001)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR08MB10048 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 01797a9b-2661-4280-bed9-08dbb88e02d5 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LZbE0bZiA+pzoYyMqMEbvqlKdfYQHw/JaGASalq+INZFReUprD2tK0+LtMNT2cqEapHCQOnmgvZGfVPkVMtZHQCtw4Qo4asxSt9dKTqgeS/dbxqWcod1MqKspNTtgQqoxn+QMvwFzKA9N+LJ/BHIWmHOBi31c3vXju4k9EhwO7c2jLjeHAgbhozkymD3oSC7w766Og7Pa8tSI8GhvgDqumW7PQVDrMsycvIoSMd+a34yx1TduJFv8aXOiT9CyIfYiEHUvp+te8fF728/WFiDcmJvJ25AGro7vEibBbSmhVZSFd+7Rr3RduCKtlE44LsN6Jwn/0hTDZWUKue1wa2OE8Ga1gT/hX2rabE5c8rXPn53D21VkQVa9ifDQTplRZ0KIqG8fYRfsaCtF6SmCbH25TRroOZ3lmMIM8Dm6ZXxrXGBLknCp6OL7V3k9Zd475GYgg1zsxTPThUBl0NkLfu3wFL1DMbnZ6bSdhmdUSi98j2UoTSh5E1RBFo9U8PFHbJ6BqCxri+Or9JT9SkMxL2oDIb3L1ui8Bwi18zu1/EzM37k/BwJegVLDcBXWCzuYAI4ZWM6oTh5wG2aZJJUvMCVFnoNCpOHiN3VSoEtsuHXfO58cNnO1sosdUYnr4cj2XKRQpgxF9/F8QIYB/CjmYwkgmK7j8pw3OyCFAdqGUeIe6xRZgYFKCKh9YTtyRYrzR2YWWdYAd8m+JC2F/e7mVZNpHMWi0Zm5BPGf0UH0fe6mMdsTAArJUJuFeqTW3wDrwt2BERM3vBGNSCVzLdVNxHD9Q== 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)(136003)(346002)(39860400002)(396003)(376002)(82310400011)(186009)(1800799009)(451199024)(36840700001)(46966006)(40470700004)(81166007)(26005)(82740400003)(2616005)(8936002)(8676002)(4326008)(1076003)(40460700003)(107886003)(83380400001)(36860700001)(2906002)(36756003)(47076005)(426003)(336012)(5660300002)(40480700001)(44832011)(86362001)(7696005)(478600001)(6666004)(6916009)(316002)(54906003)(70206006)(70586007)(41300700001)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:16.2970 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1fb96950-68db-40a5-a52a-08dbb88e080c 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: DBAEUR03FT059.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB8042 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" When we have a core file generated by gdb (via the gcore command), gdb dumps the target description to a note. During loading of that core file, gdb will first try to load that saved target description. This works fine for almost all architectures. But AArch64 has a few dynamically-generated target descriptions/gdbarch depending on the vector length that was in use at the time the core file was generated. The target description gdb dumps to the core file note is the one generated at the time of attachment/startup. If, for example, the SVE vector length changed during execution, this would not reflect on the core file, as gdb would still dump the initial target description. Another issue is that the gdbarch potentially doesn't match the thread's real gdbarch, and so things like the register cache may have different formats and sizes. To address this, fetch the thread's architecture before dumping its register state. That way we will always use the correct target description/gdbarch. Approved-By: Simon Marchi Approved-By: Tom Tromey Reviewed-by: Thiago Jung Bauermann --- gdb/linux-tdep.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index a4a86b01bdb..2885afd60c7 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -2078,15 +2078,30 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) stop_signal = GDB_SIGNAL_0; if (signalled_thr != nullptr) - linux_corefile_thread (signalled_thr, gdbarch, obfd, note_data, note_size, - stop_signal); + { + /* On some architectures, like AArch64, each thread can have a distinct + gdbarch (due to scalable extensions), and using the inferior gdbarch + is incorrect. + + Fetch each thread's gdbarch and pass it down to the lower layers so + we can dump the right set of registers. */ + linux_corefile_thread (signalled_thr, + target_thread_architecture (signalled_thr->ptid), + obfd, note_data, note_size, stop_signal); + } for (thread_info *thr : current_inferior ()->non_exited_threads ()) { if (thr == signalled_thr) continue; - linux_corefile_thread (thr, gdbarch, obfd, note_data, note_size, - stop_signal); + /* On some architectures, like AArch64, each thread can have a distinct + gdbarch (due to scalable extensions), and using the inferior gdbarch + is incorrect. + + Fetch each thread's gdbarch and pass it down to the lower layers so + we can dump the right set of registers. */ + linux_corefile_thread (thr, target_thread_architecture (thr->ptid), + obfd, note_data, note_size, stop_signal); } if (!note_data) From patchwork Mon Sep 18 21:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76324 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 928E23853D15 for ; Mon, 18 Sep 2023 21:30:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 928E23853D15 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072607; bh=mnYzuh2bHbaa1WJoZGINrxYKB0wUeKyN7riCChuD9BY=; 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=yJ4Dq20Mb/sObpU5sy3vdogj7qQaYLQZswHZkVxfUwfQzvAkcdmxzBmlltEGFAw22 EGTMn2NvMpUMFN2YMimqWzItatkXjYMTuUq+vkbF00qNRC4GkSnY6AT9zKxlA/EiF3 Vwtt66Ewx6Qh+i9MGPHzhdQTReDHZ+CUHFSUxe+4= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2058.outbound.protection.outlook.com [40.107.7.58]) by sourceware.org (Postfix) with ESMTPS id 4C8DD3857004 for ; Mon, 18 Sep 2023 21:27:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4C8DD3857004 Received: from DUZPR01CA0178.eurprd01.prod.exchangelabs.com (2603:10a6:10:4b3::20) by DU2PR08MB10263.eurprd08.prod.outlook.com (2603:10a6:10:491::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21; Mon, 18 Sep 2023 21:27:19 +0000 Received: from DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com (2603:10a6:10:4b3:cafe::3a) by DUZPR01CA0178.outlook.office365.com (2603:10a6:10:4b3::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:19 +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 DBAEUR03FT025.mail.protection.outlook.com (100.127.142.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:19 +0000 Received: ("Tessian outbound 169aaa6bf2b7:v175"); Mon, 18 Sep 2023 21:27:19 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 9df5e70ec9a5978e X-CR-MTA-TID: 64aa7808 Received: from 67ddc84cc824.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 952A1911-448D-4781-AAF8-BABD1BBFB30E.1; Mon, 18 Sep 2023 21:27:13 +0000 Received: from EUR04-HE1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 67ddc84cc824.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MxtEBwlAuvWpRmGVI2V137IrDs75CN7qM7RZQkZzG64TH7/RQxopmGe1nm9LC+E/TsAcWKBeVfgr+EpbdwM0HNrInEBrV6QOlYI7JXJC8YrcvAK6eX4pjiD9zCYl15H8jyGP6yDTtZ10h7M7OxtX965mw3pQ1YP927yazmJOri0fdxU6RN3D7tKO5tcUc+bz7KWvcr9yZABLu7/zVyMR/M0nudUhu+6WXqF6LSyEHr1I73lqtA5eYv9NuYYPEillhWfFI5TYI4uFyQoxr8DQo5LE1ko/YyHAhYGJvTuC14/FF992MACFkOG51ibKDVDfCFpXlE3n01mXM3JzefkYVw== 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=mnYzuh2bHbaa1WJoZGINrxYKB0wUeKyN7riCChuD9BY=; b=lXqGTLSv5s7KGBvuz6lg9PgNPVDEOGRjid+twvSs9rsg63In9mgXeOlQMLhWOGMfeGSAiWXLATi35lW960hIv57DYJgHdjigrf842qjVN2vTLtMNp8pDAHZZByGx5IpxrCFTVRp5AX7nr+UQ/N/tHy2GN301Lr5eLxrtZ1zSEq8cUkH5gjoY4qo1ctmsCZDFOecIiwjCdyMwekhn4VicIg457Klp7XnO2vOZVFMDP9Ed26AXzi76svpvwgClCgIk6bmQtaOohtyrhyMYIk1NM9B8UWY0GKW2UBpO5f2/7sS9gsOAHg9E4rFo9IIkTdAQleOn+qTY2dUWt0p71MKiIg== 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 AM6P193CA0128.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::33) by GV2PR08MB8512.eurprd08.prod.outlook.com (2603:10a6:150:c2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.23; Mon, 18 Sep 2023 21:27:08 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::6a) by AM6P193CA0128.outlook.office365.com (2603:10a6:209:85::33) 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:08 +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:08 +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:07 +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:07 +0000 To: Subject: [PATCH v7 15/18] [gdb/generic] corefile/bug: Add hook to control the use of target description notes from corefiles Date: Mon, 18 Sep 2023 22:26:48 +0100 Message-ID: <20230918212651.660141-16-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_|GV2PR08MB8512:EE_|DBAEUR03FT025:EE_|DU2PR08MB10263:EE_ X-MS-Office365-Filtering-Correlation-Id: b9208501-4dd6-48fd-24c2-08dbb88e0a0b 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: 9AHZLDbLklI6VeM1In+ZM92+7q8sdVFvW/9hObBITkegflF7y0LZewZXyA9gNSGYlyAEoViArdExUBF4gwLfswNME5hwxF9xJKYnJLzUv6Xcq9AIg9bhbv9CbbxEoecP2SnK0sowPjIJpg9K6dYyb41pkYXOsF0D8V3ZiCcVsxgHDEytFNhSSMZA9nJwxjRrFcqFLwPQLuZt1XkKQPA2OFYF4Vdzuf70kTrpHbgVKQNGPi2VLEckZmpBp+PhW4BQT0BdWdRy7kBMvYobTpEZvbGOLCFKHFICMuYN6n8Z49fJl7LZYHH1CbbJ8hySCm/Yep/9vRDOauxxZgiOmKiwkgnFuftj7gMF7dem/CM4vhJe1Y4G0TKunCS83JCsYdrJtjCM4z00QnoaQRxPLBO8YDMD0Wuc4R7Y3yIFcpCgw3hfJdXheqixF5F7vlGWiiZhNRoCa+S7soyVbE6t8vpdq3HEMkFv7j5eapqGaTIX154pddVeQJOBsKazQNaCgssRVTJfbHVygNn4PqGRZdeAJSkBwC3AGMK5/Ye+ABQIyFDGe991yq/YWRsj/RiYjFFQK8g8etgOKvjHX7sXZmncsFMrGMgCxw7qWQ2rdAwSzZQDi+rllL+LgHpS3Xlke+xebwGgmCG+hehtfdSr/Zcojx+hOxGz7H1U/yQ04PTEixqI7pUy36aDjO1V+TdMfQ2830Xv7u6G7ew/RKPWuRH0CixFP8B5i/slcB+xjjgIYC3ajV7ZE1ChvjxMbkhxH+Gd5fmXcmdlY6fIjRtHowodRsCAcPY811zBwZhdbLw8PAQ= 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)(346002)(39860400002)(376002)(136003)(396003)(451199024)(1800799009)(186009)(82310400011)(40470700004)(36840700001)(46966006)(40480700001)(44832011)(7696005)(86362001)(54906003)(316002)(41300700001)(70206006)(70586007)(5660300002)(6666004)(478600001)(6916009)(8936002)(2616005)(8676002)(356005)(81166007)(26005)(82740400003)(2906002)(36860700001)(36756003)(30864003)(336012)(426003)(47076005)(40460700003)(1076003)(4326008)(83380400001)(41533002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV2PR08MB8512 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: fd0d1775-bc9a-4321-68ef-08dbb88e0343 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xPpM3U5qEb2lkK5XH4xonoZkUv6aeD7tEyS1vhA9CpAkiIvTbmbBolIJBTh0/JuXOFiqsRASKa8GNRmYM038Y0esH2jfBedvTM9J+u50fQdotezstqyZBGdEDsJ9ZRTKiyqevYso0TDc0KB/4vWpJo/4Q12WTSvWS+JfCExtbwDHkD7381n+nTJ9Ji6EPMfMQ+gswj8jtVNLJgaLg7LACeHR7/RHbIqUZlh3ylIz3uEfXIq9fGOc6y2INrsknF3FBnKyg7AsBRilf/Y45aBFjI2FDZuXhm5ziwYKN7/Z3FdguNTvhv/rND/5MFFNdBcXp0iSIE6/ltCz4ykh+1z6J9iyTs/Q9sl+N++pAbNr27YBv9c1JDyKGfDm9KtEnGxAg77darD7eOEAd01CfiNHkgF2wiHiCvWfxbjTMa8iV4uAf+vLk1VESQcT7pmem008l9YDRV5GLkJEeCkBmlt4WW/TrfGOsyGmyn4Cz7b/Ex5O2bep6Py6v+CZuKQQ4CFi5cg2RqPke6/gjsOGw9Nw2f+XiSwmwmnIrKlKV/43KTT61ksLd2l+PkUGxTBVSJ2wFqwIkFY1WtPEv4g5bqmEBjxKOl046ugd4ge2hl+fjrFW9m1lqjTgC+srKoyGCjdcno6xiMjKozK3ago5EltkzbNy24UamFHHM4Iv3udwupkoSnY8xYBPOomvl4wTV++9BwxboWQJuZwxlqiI0ykIJXgqht3XLCTQof09nUuDGV0VmLXfCtX1qXsk36m7p8FU9Qil51to+fCRDjJhpOJSAw== 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)(39850400004)(346002)(136003)(376002)(396003)(451199024)(186009)(1800799009)(82310400011)(36840700001)(40470700004)(46966006)(83380400001)(5660300002)(4326008)(6666004)(7696005)(82740400003)(40480700001)(36756003)(81166007)(86362001)(107886003)(36860700001)(1076003)(2616005)(26005)(2906002)(336012)(426003)(30864003)(478600001)(6916009)(41300700001)(47076005)(40460700003)(8676002)(8936002)(70586007)(70206006)(316002)(44832011)(54906003)(41533002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:19.6270 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b9208501-4dd6-48fd-24c2-08dbb88e0a0b 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: DBAEUR03FT025.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR08MB10263 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" New entry in v7. --- Due to the nature of the AArch64 SVE/SME extensions in GDB, each thread can potentially have distinct target descriptions/gdbarches. When loading a gcore-generated core file, at the moment GDB gives priority to the target description dumped to NT_GDB_TDESC. Though technically correct for most targets, it doesn't work correctly for AArch64 with SVE or SME support. The correct approach for AArch64/Linux is to either have per-thread target description notes in the corefiles or to rely on the gdbarch_core_read_description hook, so it can figure out the proper target description for a given thread based on the various available register notes. The former, although more correct, doesn't address the case of existing gdb's that only output a single target description note. This patch goes for the latter, and adds a new gdbarch hook to conditionalize the use of the corefile target description note. The hook is called use_target_description_from_corefile_notes. The hook defaults to returning true, meaning targets will use the corefile target description note. AArch64 Linux overrides the hook to return false when it detects any of the SVE or SME register notes in the corefile. Otherwise it should be fine for AArch64 Linux to use the corefile target description note. When we support per-thread target description notes, then we can augment the AArch64 Linux hook to rely on those notes. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. --- gdb/aarch64-linux-tdep.c | 33 ++++++++++++++++++++++++++ gdb/arch-utils.c | 10 ++++++++ gdb/arch-utils.h | 6 +++++ gdb/corelow.c | 50 ++++++++++++++++++++++++--------------- gdb/gdbarch-gen.h | 14 +++++++++++ gdb/gdbarch.c | 22 +++++++++++++++++ gdb/gdbarch_components.py | 19 +++++++++++++++ 7 files changed, 135 insertions(+), 19 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 47e5e1db641..21ac7ebdc56 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -2199,6 +2199,33 @@ aarch64_linux_decode_memtag_section (struct gdbarch *gdbarch, return tags; } +/* AArch64 Linux implementation of the + gdbarch_use_target_description_from_corefile_notes hook. */ + +static bool +aarch64_use_target_description_from_corefile_notes (gdbarch *gdbarch, + bfd *obfd) +{ + /* Sanity check. */ + gdb_assert (obfd != nullptr); + + /* If the corefile contains any SVE or SME register data, we don't want to + use the target description note, as it may be incorrect. + + Currently the target description note contains a potentially incorrect + target description if the originating program changed the SVE or SME + vector lengths mid-execution. + + Once we support per-thread target description notes in the corefiles, we + can always trust those notes whenever they are available. */ + if (bfd_get_section_by_name (obfd, ".reg-aarch-sve") != nullptr + || bfd_get_section_by_name (obfd, ".reg-aarch-za") != nullptr + || bfd_get_section_by_name (obfd, ".reg-aarch-zt") != nullptr) + return false; + + return true; +} + static void aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) { @@ -2469,6 +2496,12 @@ aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch) aarch64_displaced_step_hw_singlestep); set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options); + + /* Hook to decide if the target description should be obtained from + corefile target description note(s) or inferred from the corefile + sections. */ + set_gdbarch_use_target_description_from_corefile_notes (gdbarch, + aarch64_use_target_description_from_corefile_notes); } #if GDB_SELF_TEST diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c index ee34fc07d33..c1d2c939eb9 100644 --- a/gdb/arch-utils.c +++ b/gdb/arch-utils.c @@ -1092,6 +1092,16 @@ default_read_core_file_mappings { } +/* See arch-utils.h. */ +bool +default_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, + struct bfd *obfd) +{ + /* Always trust the corefile target description contained in the target + description note. */ + return true; +} + CORE_ADDR default_get_return_buf_addr (struct type *val_type, frame_info_ptr cur_frame) { diff --git a/gdb/arch-utils.h b/gdb/arch-utils.h index 2bdc3251c9c..5df3de7b5d9 100644 --- a/gdb/arch-utils.h +++ b/gdb/arch-utils.h @@ -305,6 +305,12 @@ extern void default_read_core_file_mappings read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); +/* Default implementation of gdbarch + use_target_description_from_corefile_notes. */ +extern bool default_use_target_description_from_corefile_notes + (struct gdbarch *gdbarch, + struct bfd *obfd); + /* Default implementation of gdbarch default_get_return_buf_addr method. */ extern CORE_ADDR default_get_return_buf_addr (struct type *val_typegdbarch, frame_info_ptr cur_frame); diff --git a/gdb/corelow.c b/gdb/corelow.c index 439270f5559..114ce3054d5 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -1229,35 +1229,47 @@ core_target::thread_alive (ptid_t ptid) const struct target_desc * core_target::read_description () { - /* If the core file contains a target description note then we will use - that in preference to anything else. */ - bfd_size_type tdesc_note_size = 0; - struct bfd_section *tdesc_note_section - = bfd_get_section_by_name (core_bfd, ".gdb-tdesc"); - if (tdesc_note_section != nullptr) - tdesc_note_size = bfd_section_size (tdesc_note_section); - if (tdesc_note_size > 0) + /* First check whether the target wants us to use the corefile target + description notes. */ + if (gdbarch_use_target_description_from_corefile_notes (m_core_gdbarch, + core_bfd)) { - gdb::char_vector contents (tdesc_note_size + 1); - if (bfd_get_section_contents (core_bfd, tdesc_note_section, - contents.data (), (file_ptr) 0, - tdesc_note_size)) + /* If the core file contains a target description note then go ahead and + use that. */ + bfd_size_type tdesc_note_size = 0; + struct bfd_section *tdesc_note_section + = bfd_get_section_by_name (core_bfd, ".gdb-tdesc"); + if (tdesc_note_section != nullptr) + tdesc_note_size = bfd_section_size (tdesc_note_section); + if (tdesc_note_size > 0) { - /* Ensure we have a null terminator. */ - contents[tdesc_note_size] = '\0'; - const struct target_desc *result - = string_read_description_xml (contents.data ()); - if (result != nullptr) - return result; + gdb::char_vector contents (tdesc_note_size + 1); + if (bfd_get_section_contents (core_bfd, tdesc_note_section, + contents.data (), (file_ptr) 0, + tdesc_note_size)) + { + /* Ensure we have a null terminator. */ + contents[tdesc_note_size] = '\0'; + const struct target_desc *result + = string_read_description_xml (contents.data ()); + if (result != nullptr) + return result; + } } } + /* If the architecture provides a corefile target description hook, use + it now. Even if the core file contains a target description in a note + section, it is not useful for targets that can potentially have distinct + descriptions for each thread. One example is AArch64's SVE/SME + extensions that allow per-thread vector length changes, resulting in + registers with different sizes. */ if (m_core_gdbarch && gdbarch_core_read_description_p (m_core_gdbarch)) { const struct target_desc *result; result = gdbarch_core_read_description (m_core_gdbarch, this, core_bfd); - if (result != NULL) + if (result != nullptr) return result; } diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h index d62eefa1c5b..33276aa1c43 100644 --- a/gdb/gdbarch-gen.h +++ b/gdb/gdbarch-gen.h @@ -1717,3 +1717,17 @@ extern void set_gdbarch_get_pc_address_flags (struct gdbarch *gdbarch, gdbarch_g typedef void (gdbarch_read_core_file_mappings_ftype) (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); extern void gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, struct bfd *cbfd, read_core_file_mappings_pre_loop_ftype pre_loop_cb, read_core_file_mappings_loop_ftype loop_cb); extern void set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, gdbarch_read_core_file_mappings_ftype *read_core_file_mappings); + +/* Return true if the target description for all threads should be read from the + target description core file note(s). Return false if the target description + for all threads should be inferred from the core file contents/sections. + + The corefile's bfd is passed through OBFD. + + This hook should be used by targets that can have distinct target descriptions + for each thread when the core file only holds a single target description + note. */ + +typedef bool (gdbarch_use_target_description_from_corefile_notes_ftype) (struct gdbarch *gdbarch, struct bfd *obfd); +extern bool gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, struct bfd *obfd); +extern void set_gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, gdbarch_use_target_description_from_corefile_notes_ftype *use_target_description_from_corefile_notes); diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c index 1fc254d3d6e..ee868908598 100644 --- a/gdb/gdbarch.c +++ b/gdb/gdbarch.c @@ -256,6 +256,7 @@ struct gdbarch gdbarch_type_align_ftype *type_align = default_type_align; gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags; gdbarch_read_core_file_mappings_ftype *read_core_file_mappings = default_read_core_file_mappings; + gdbarch_use_target_description_from_corefile_notes_ftype *use_target_description_from_corefile_notes = default_use_target_description_from_corefile_notes; }; /* Create a new ``struct gdbarch'' based on information provided by @@ -523,6 +524,7 @@ verify_gdbarch (struct gdbarch *gdbarch) /* Skip verify of type_align, invalid_p == 0 */ /* Skip verify of get_pc_address_flags, invalid_p == 0 */ /* Skip verify of read_core_file_mappings, invalid_p == 0 */ + /* Skip verify of use_target_description_from_corefile_notes, invalid_p == 0 */ if (!log.empty ()) internal_error (_("verify_gdbarch: the following are invalid ...%s"), log.c_str ()); @@ -1373,6 +1375,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file) gdb_printf (file, "gdbarch_dump: read_core_file_mappings = <%s>\n", host_address_to_string (gdbarch->read_core_file_mappings)); + gdb_printf (file, + "gdbarch_dump: use_target_description_from_corefile_notes = <%s>\n", + host_address_to_string (gdbarch->use_target_description_from_corefile_notes)); if (gdbarch->dump_tdep != NULL) gdbarch->dump_tdep (gdbarch, file); } @@ -5409,3 +5414,20 @@ set_gdbarch_read_core_file_mappings (struct gdbarch *gdbarch, { gdbarch->read_core_file_mappings = read_core_file_mappings; } + +bool +gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, struct bfd *obfd) +{ + gdb_assert (gdbarch != NULL); + gdb_assert (gdbarch->use_target_description_from_corefile_notes != NULL); + if (gdbarch_debug >= 2) + gdb_printf (gdb_stdlog, "gdbarch_use_target_description_from_corefile_notes called\n"); + return gdbarch->use_target_description_from_corefile_notes (gdbarch, obfd); +} + +void +set_gdbarch_use_target_description_from_corefile_notes (struct gdbarch *gdbarch, + gdbarch_use_target_description_from_corefile_notes_ftype use_target_description_from_corefile_notes) +{ + gdbarch->use_target_description_from_corefile_notes = use_target_description_from_corefile_notes; +} diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py index 846467b8d83..bbb9b188286 100644 --- a/gdb/gdbarch_components.py +++ b/gdb/gdbarch_components.py @@ -2732,3 +2732,22 @@ Read core file mappings predefault="default_read_core_file_mappings", invalid=False, ) + +Method( + comment=""" +Return true if the target description for all threads should be read from the +target description core file note(s). Return false if the target description +for all threads should be inferred from the core file contents/sections. + +The corefile's bfd is passed through OBFD. + +This hook should be used by targets that can have distinct target descriptions +for each thread when the core file only holds a single target description +note. +""", + type="bool", + name="use_target_description_from_corefile_notes", + params=[("struct bfd *", "obfd")], + predefault="default_use_target_description_from_corefile_notes", + invalid=False, +) From patchwork Mon Sep 18 21:26:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76328 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 C3256383CA82 for ; Mon, 18 Sep 2023 21:30:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3256383CA82 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072643; bh=gYfCtEyETqDTg1GI4gubzrOpqCZ+UYAqrzUkb3itvGk=; 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=Dwb6wtrPEDw71v11VtRRZ3U+9pZna0b/ayC5/JtuN/XyN7QI+7tVCNLRBa0TLVTgx Gusncd7gVBwVmpei6PePt71hzDb2mptjeaw6vbyHibFEaqgYpAp2XSp6PPNzgH19EW cYTy+nu1XiW31qTVcPtmIB1qUYh1RpYuqHZPtF34= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2089.outbound.protection.outlook.com [40.107.105.89]) by sourceware.org (Postfix) with ESMTPS id 38128385700D for ; Mon, 18 Sep 2023 21:27:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38128385700D Received: from AS9PR06CA0245.eurprd06.prod.outlook.com (2603:10a6:20b:45f::13) by AS2PR08MB9810.eurprd08.prod.outlook.com (2603:10a6:20b:605::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:19 +0000 Received: from AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45f:cafe::f2) by AS9PR06CA0245.outlook.office365.com (2603:10a6:20b:45f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:19 +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 AM7EUR03FT039.mail.protection.outlook.com (100.127.140.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:18 +0000 Received: ("Tessian outbound b5a0f4347031:v175"); Mon, 18 Sep 2023 21:27:18 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 84fe36105971efbe X-CR-MTA-TID: 64aa7808 Received: from 3599492623d1.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A947219F-1AB3-495B-BE8C-819EC33967B7.1; Mon, 18 Sep 2023 21:27:11 +0000 Received: from EUR02-AM0-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 3599492623d1.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UeXDTMsstPI12GMlxM8jdYgU8xFnttAtt3OJWIB3aR9mS3zeIAglv61QUy1FYSXrNab3QrOBwkOclEmC3Nc/ejwrIEUAeiW2pHrySZUf7KqwnZupyFd21DL8NwS9J8lebOqGAOfj1/BbajjjwzYaSWhGZcREBVfh5OFqM/GLnn2N2veTDN2n1YaQcvbV9gpWeZSLJx8VNwwke51JwHoWqkRmb8UJjm9wZm3Z0+z1rAGEau41XMTv54Al5BL6N/1AmnrhzBpU51xPFmk19m6NYLaHV+WTPxn1ooDsGwK+cMJNJI7jjinpcpN7e+0W2w35x7R7M3RRCF14ZvW0zDBhFg== 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=gYfCtEyETqDTg1GI4gubzrOpqCZ+UYAqrzUkb3itvGk=; b=jOuyzY/MH87phx2QKILBosZYVXIbVPoK3/ndZq8rqkgHs7Imlmm+BN2qArtEi8jBq6tYN4yNa9OsrRYN0BZnlsxCLUrHGCNjqjVR3Me9LfbqlDs0Hb1G7Cgysz+26T+KKRA8Sa+/kyLrLm6cZsqcYu6U9C9O2b9PnXc7eU1814SYkC1wr/ZB7+Vye71oR/Xwhy8X/mY3i30LgLH6EfREN+4vdBub3sDSQkXTJevkyAQp3mGGwWVDwx0zyJx3z+MQMrgr8IvPSyrRWsYgnFKZIKBORiNUMQBlFFvxuwYZ5ZfYzpTg9nCq6e5a3KRrvy/Kln5kPoHn63cLps5pj9RGOw== 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 AM6P193CA0139.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::44) by DU0PR08MB9485.eurprd08.prod.outlook.com (2603:10a6:10:42e::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.21; Mon, 18 Sep 2023 21:27:09 +0000 Received: from AM7EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:209:85:cafe::2c) by AM6P193CA0139.outlook.office365.com (2603:10a6:209:85::44) 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:08 +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:08 +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:07 +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:07 +0000 To: Subject: [PATCH v7 16/18] [gdb/aarch64] sme: Core file support for Linux Date: Mon, 18 Sep 2023 22:26:49 +0100 Message-ID: <20230918212651.660141-17-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_|DU0PR08MB9485:EE_|AM7EUR03FT039:EE_|AS2PR08MB9810:EE_ X-MS-Office365-Filtering-Correlation-Id: 480cc0cd-6445-4169-03d2-08dbb88e0990 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: iNJLCo72X7Y1UfOnEhF9RCIhpNpFL6bg5j5bW101OF7vQhjjL7b+hSK8hHTBCM3e6XGUJB/J93sF+Si+iSXCjxNfSLS23ms5nVy2jT9MAL01vINaRK3EfKt03SOgNXAhQeM6LYMTHCcc5O7CzoF18I7AfkUg277oHmPnFD8B7D7DDnFi1TW9Igu3Wj7AVjno7FC1g6dmsyr5dKyJ9vgD1kHws3NWG2CCRCoAUjCOyprwsh8yVKEre2EW59m5TqVJtA5aQNFR1g94TUCnjaTOhacuGnzHFo9xqImSX06QdIN9O6sH+FKHyvs++GSAd+Y055GB4hlasS9AB+Q56oUSbKcNphBoDhihSbo4G9faUnZyH8zxj2rwEICSL3ymzR1LWv/wVM0MtxlnS5QMbRLHjMGR3qAEEzGg8ly9TNhJURdTTIuiiEqJZcVo6kJ2jB1ixooT9g2sSexh0r/mty68jlGB6QwaJ5R8w4WlQUYr7yeVYtuSentxS7V/HuEh6+rYCbTrcw+bgcWkp5LudeTriz/uv84Bt1VXe1A4ZhlWnvpQVD0dM6/hiTNefVRWHgScQMSaUfMNvShMattLPZcCD1k6clE2OmijMDsHx46PWM9/deoBbr53PzwOriyfAZvcp66qA75dps3wldcUWXAU0FROlcLqWUjnrayBvQKlyrBpXcDeka1WUvjmYRpp8/XDJl7FcNyTlnlfhgjfbBOmeizZeJy4MKqspInYxj/v4xJteuO0AnqQhqFpHyVydFLLcBHGP1YYU9ongIg6IFuDLg== 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)(346002)(136003)(396003)(376002)(39860400002)(82310400011)(451199024)(186009)(1800799009)(46966006)(40470700004)(36840700001)(36860700001)(40480700001)(478600001)(40460700003)(47076005)(4326008)(8676002)(44832011)(8936002)(81166007)(356005)(6916009)(54906003)(70586007)(316002)(70206006)(41300700001)(5660300002)(36756003)(82740400003)(86362001)(30864003)(1076003)(336012)(26005)(2616005)(426003)(2906002)(83380400001)(7696005)(6666004)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU0PR08MB9485 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 815d7225-5eac-4e3d-c535-08dbb88e03a2 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WpPFEJ5Q4zPpK2pq6oFQcjxGb5xQn0xT4RW682SK3JrKnriuzpCOkCTajPltVZbiKwT9pQApOMSrpUNoCIWGxVIIvTNG9lDY3v5ygQiUT2KquJQ2I8eMhHVpzB8t43b0QufPTG4U03ghPMd6xJXWcABNvz7/VA1dm+1MWjmILOt8oBMcqGRNbmWXHkThrepXGFRnoabEJFImsHHMpr2FniX7kLlohqoKOkYeMTFnTOERkWxqLqo1+t1PhJSJyG3rcNtixRB1J8aCpZGVY7t5Gf0QmWU7oolIn7NbLDY5DxJciA9Lgm62UJr5r7cGFH87GXQDj7pZwiLniqxXmhhXsW8nSV/hr5MuPkxqg1gilcirfz3oPDbQuJ5zRUGEJ/yRXr5xBeSc+xjO9T6cE8kMpQ/4Aa5qTqCj6BVR/Cs9ogGMs0KI4vp5BGePjGSXwIiW2PsJjwG1fYPTtWg8bY9BcP+FEYKDNoLb54+0+yfRKRmZMNUO8Xm1y9z7IgRMONyJznW/lKM8DFAlVY0f03A0I60l68LN17V8WPznLfe+ZEhNIliYYB+GIjaNTSWxz2L2taBw5/4weMYwsW2ymP36MvbUFQ8kcaGXWRa2EjVoybVDLfK8eTxd2sDbnLhRk8EtkZ7mVHDO5/N/wF2EQX0WZUHQy8q28h7OX6X+B4b3HRJa6JAUIsA90zlctTyRlC4uinhcK+bbgGdKi/RWy1wLl8pusY+fIA6Z+2wyoRb2Mhw= 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)(39860400002)(136003)(396003)(376002)(346002)(186009)(1800799009)(82310400011)(451199024)(36840700001)(40470700004)(46966006)(36756003)(40480700001)(40460700003)(7696005)(2906002)(6666004)(2616005)(107886003)(478600001)(30864003)(1076003)(83380400001)(86362001)(426003)(336012)(26005)(6916009)(316002)(70586007)(70206006)(54906003)(41300700001)(4326008)(8676002)(8936002)(44832011)(5660300002)(81166007)(82740400003)(47076005)(36860700001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:18.7575 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 480cc0cd-6445-4169-03d2-08dbb88e0990 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: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS2PR08MB9810 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, KAM_SHORT, 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" Updates in v5: - Fixed spurious 4-byte gap between FPCR and the two reserved 4-byte fields when collecting an inactive sve regset. --- This patch enables dumping SME state via gdb's gcore command and also enables gdb to read SME state from a core file generated by the Linux Kernel. Regression-tested on aarch64-linux Ubuntu 22.04/20.04. Reviewed-by: Thiago Jung Bauermann --- gdb/aarch64-linux-tdep.c | 542 ++++++++++++++++++++++++++++-- gdb/arch/aarch64-scalable-linux.c | 34 ++ gdb/arch/aarch64-scalable-linux.h | 15 + 3 files changed, 558 insertions(+), 33 deletions(-) diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 21ac7ebdc56..21efa42b2e6 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -57,6 +57,10 @@ #include "elf/common.h" #include "elf/aarch64.h" +#include "arch/aarch64-insn.h" + +/* For std::pow */ +#include /* Signal frame handling. @@ -741,50 +745,55 @@ const struct regset aarch64_linux_fpregset = #define SVE_HEADER_FLAG_SVE 1 -/* Get VQ value from SVE section in the core dump. */ +/* Get the vector quotient (VQ) or streaming vector quotient (SVQ) value + from the section named SECTION_NAME. + + Return non-zero if successful and 0 otherwise. */ static uint64_t -aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd) +aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd, + const char *section_name) { - 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"); + gdb_assert (section_name != nullptr); - if (sve_section == nullptr) + asection *section = bfd_get_section_by_name (abfd, section_name); + + if (section == nullptr) { /* No SVE state. */ return 0; } - size_t size = bfd_section_size (sve_section); + size_t size = bfd_section_size (section); /* Check extended state size. */ if (size < SVE_HEADER_SIZE) { - warning (_("'.reg-aarch-sve' section in core file too small.")); + warning (_("'%s' core file section is too small. " + "Expected %s bytes, got %s bytes"), section_name, + pulongest (SVE_HEADER_SIZE), pulongest (size)); return 0; } - if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE)) + gdb_byte header[SVE_HEADER_SIZE]; + + if (!bfd_get_section_contents (abfd, section, header, 0, SVE_HEADER_SIZE)) { warning (_("Couldn't read sve header from " - "'.reg-aarch-sve' section in core file.")); + "'%s' core file section."), section_name); 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); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + uint64_t vq + = sve_vq_from_vl (extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET, + SVE_HEADER_VL_LENGTH, + byte_order)); - if (vq > AARCH64_MAX_SVE_VQ) - { - warning (_("SVE Vector length in core file not supported by this version" - " of GDB. (VQ=%s)"), pulongest (vq)); - return 0; - } - else if (vq == 0) + if (vq > AARCH64_MAX_SVE_VQ || vq == 0) { - warning (_("SVE Vector length in core file is invalid. (VQ=%s"), + warning (_("SVE/SSVE vector length in core file is invalid." + " (max vq=%d) (detected vq=%s)"), AARCH64_MAX_SVE_VQ, pulongest (vq)); return 0; } @@ -792,14 +801,53 @@ aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd) return vq; } +/* Get the vector quotient (VQ) value from CORE_BFD's sections. + + Return non-zero if successful and 0 otherwise. */ + +static uint64_t +aarch64_linux_core_read_vq_from_sections (struct gdbarch *gdbarch, + bfd *core_bfd) +{ + /* First check if we have a SSVE section. If so, check if it is active. */ + asection *section = bfd_get_section_by_name (core_bfd, ".reg-aarch-ssve"); + + if (section != nullptr) + { + /* We've found a SSVE section, so now fetch its data. */ + gdb_byte header[SVE_HEADER_SIZE]; + + if (bfd_get_section_contents (core_bfd, section, header, 0, + SVE_HEADER_SIZE)) + { + /* Check if the SSVE section has SVE contents. */ + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + uint16_t flags + = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, + SVE_HEADER_FLAGS_LENGTH, byte_order); + + if (flags & SVE_HEADER_FLAG_SVE) + { + /* The SSVE state is active, so return the vector length from the + the SSVE section. */ + return aarch64_linux_core_read_vq (gdbarch, core_bfd, + ".reg-aarch-ssve"); + } + } + } + + /* No valid SSVE section. Return the vq from the SVE section (if any). */ + return aarch64_linux_core_read_vq (gdbarch, core_bfd, ".reg-aarch-sve"); +} + /* Supply register REGNUM from BUF to REGCACHE, using the register map in REGSET. If REGNUM is -1, do this for all registers in REGSET. - If BUF is NULL, set the registers to "unavailable" status. */ + If BUF is nullptr, set the registers to "unavailable" status. */ static void -aarch64_linux_supply_sve_regset (const struct regset *regset, - struct regcache *regcache, - int regnum, const void *buf, size_t size) +supply_sve_regset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *buf, size_t size) { gdb_byte *header = (gdb_byte *) buf; struct gdbarch *gdbarch = regcache->arch (); @@ -851,14 +899,89 @@ aarch64_linux_supply_sve_regset (const struct regset *regset, } } +/* Collect an inactive SVE register set state. This is equivalent to a + fpsimd layout. + + Collect the data from REGCACHE to BUF, using the register + map in REGSET. */ + +static void +collect_inactive_sve_regset (const struct regcache *regcache, + void *buf, size_t size, int vg_regnum) +{ + gdb_byte *header = (gdb_byte *) buf; + struct gdbarch *gdbarch = regcache->arch (); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + + gdb_assert (buf != nullptr); + gdb_assert (size >= SVE_CORE_DUMMY_SIZE); + + /* Zero out everything first. */ + memset ((gdb_byte *) buf, 0, SVE_CORE_DUMMY_SIZE); + + /* BUF starts with a SVE header prior to the register dump. */ + + /* Dump the default size of an empty SVE payload. */ + uint32_t real_size = SVE_CORE_DUMMY_SIZE; + store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET, + SVE_HEADER_SIZE_LENGTH, byte_order, real_size); + + /* Dump a dummy max size. */ + uint32_t max_size = SVE_CORE_DUMMY_MAX_SIZE; + store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET, + SVE_HEADER_MAX_SIZE_LENGTH, byte_order, max_size); + + /* Dump the vector length. */ + ULONGEST vg = 0; + regcache->raw_collect (vg_regnum, &vg); + uint16_t vl = sve_vl_from_vg (vg); + store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH, + byte_order, vl); + + /* Dump the standard maximum vector length. */ + uint16_t max_vl = SVE_CORE_DUMMY_MAX_VL; + store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET, + SVE_HEADER_MAX_VL_LENGTH, byte_order, + max_vl); + + /* The rest of the fields are zero. */ + uint16_t flags = SVE_CORE_DUMMY_FLAGS; + store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, + SVE_HEADER_FLAGS_LENGTH, byte_order, + flags); + uint16_t reserved = SVE_CORE_DUMMY_RESERVED; + store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET, + SVE_HEADER_RESERVED_LENGTH, byte_order, reserved); + + /* We are done with the header part of it. Now dump the register state + in the FPSIMD format. */ + + /* Dump the first 128 bits of each of the Z registers. */ + header += AARCH64_SVE_CONTEXT_REGS_OFFSET; + for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++) + regcache->raw_collect_part (AARCH64_SVE_Z0_REGNUM + i, 0, V_REGISTER_SIZE, + header + V_REGISTER_SIZE * i); + + /* Dump FPSR and FPCR. */ + header += 32 * V_REGISTER_SIZE; + regcache->raw_collect (AARCH64_FPSR_REGNUM, header); + regcache->raw_collect (AARCH64_FPCR_REGNUM, header + 4); + + /* Dump two reserved empty fields of 4 bytes. */ + header += 8; + memset (header, 0, 8); + + /* We should have a FPSIMD-formatted register dump now. */ +} + /* Collect register REGNUM from REGCACHE to BUF, using the register map in REGSET. If REGNUM is -1, do this for all registers in REGSET. */ static void -aarch64_linux_collect_sve_regset (const struct regset *regset, - const struct regcache *regcache, - int regnum, void *buf, size_t size) +collect_sve_regset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *buf, size_t size) { gdb_byte *header = (gdb_byte *) buf; struct gdbarch *gdbarch = regcache->arch (); @@ -873,24 +996,318 @@ aarch64_linux_collect_sve_regset (const struct regset *regset, store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET, SVE_HEADER_SIZE_LENGTH, byte_order, size); + uint32_t max_size = SVE_CORE_DUMMY_MAX_SIZE; store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET, - SVE_HEADER_MAX_SIZE_LENGTH, byte_order, size); + SVE_HEADER_MAX_SIZE_LENGTH, byte_order, max_size); store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH, byte_order, sve_vl_from_vq (vq)); + uint16_t max_vl = SVE_CORE_DUMMY_MAX_VL; store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET, SVE_HEADER_MAX_VL_LENGTH, byte_order, - sve_vl_from_vq (vq)); + max_vl); + uint16_t flags = SVE_HEADER_FLAG_SVE; store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, SVE_HEADER_FLAGS_LENGTH, byte_order, - SVE_HEADER_FLAG_SVE); + flags); + uint16_t reserved = SVE_CORE_DUMMY_RESERVED; store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET, - SVE_HEADER_RESERVED_LENGTH, byte_order, 0); + SVE_HEADER_RESERVED_LENGTH, byte_order, reserved); /* The SVE register dump follows. */ regcache->collect_regset (regset, regnum, (gdb_byte *) buf + SVE_HEADER_SIZE, size - SVE_HEADER_SIZE); } +/* Supply register REGNUM from BUF to REGCACHE, using the register map + in REGSET. If REGNUM is -1, do this for all registers in REGSET. + If BUF is NULL, set the registers to "unavailable" status. */ + +static void +aarch64_linux_supply_sve_regset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *buf, size_t size) +{ + struct gdbarch *gdbarch = regcache->arch (); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + if (tdep->has_sme ()) + { + ULONGEST svcr = 0; + regcache->raw_collect (tdep->sme_svcr_regnum, &svcr); + + /* Is streaming mode enabled? */ + if (svcr & SVCR_SM_BIT) + /* If so, don't load SVE data from the SVE section. The data to be + used is in the SSVE section. */ + return; + } + /* If streaming mode is not enabled, load the SVE regcache data from the SVE + section. */ + supply_sve_regset (regset, regcache, regnum, buf, size); +} + +/* Collect register REGNUM from REGCACHE to BUF, using the register + map in REGSET. If REGNUM is -1, do this for all registers in + REGSET. */ + +static void +aarch64_linux_collect_sve_regset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *buf, size_t size) +{ + struct gdbarch *gdbarch = regcache->arch (); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + bool streaming_mode = false; + + if (tdep->has_sme ()) + { + ULONGEST svcr = 0; + regcache->raw_collect (tdep->sme_svcr_regnum, &svcr); + + /* Is streaming mode enabled? */ + if (svcr & SVCR_SM_BIT) + { + /* If so, don't dump SVE regcache data to the SVE section. The SVE + data should be dumped to the SSVE section. Dump an empty SVE + block instead. */ + streaming_mode = true; + } + } + + /* If streaming mode is not enabled or there is no SME support, dump the + SVE regcache data to the SVE section. */ + + /* Check if we have an active SVE state (non-zero Z/P/FFR registers). + If so, then we need to dump registers in the SVE format. + + Otherwise we should dump the registers in the FPSIMD format. */ + if (sve_state_is_empty (regcache) || streaming_mode) + collect_inactive_sve_regset (regcache, buf, size, AARCH64_SVE_VG_REGNUM); + else + collect_sve_regset (regset, regcache, regnum, buf, size); +} + +/* Supply register REGNUM from BUF to REGCACHE, using the register map + in REGSET. If REGNUM is -1, do this for all registers in REGSET. + If BUF is NULL, set the registers to "unavailable" status. */ + +static void +aarch64_linux_supply_ssve_regset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *buf, size_t size) +{ + gdb_byte *header = (gdb_byte *) buf; + struct gdbarch *gdbarch = regcache->arch (); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + uint16_t flags = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, + SVE_HEADER_FLAGS_LENGTH, + byte_order); + + /* Since SVCR's bits are inferred from the data we have in the header of the + SSVE section, we need to initialize it to zero first, so that it doesn't + carry garbage data. */ + ULONGEST svcr = 0; + regcache->raw_supply (tdep->sme_svcr_regnum, &svcr); + + /* Is streaming mode enabled? */ + if (flags & SVE_HEADER_FLAG_SVE) + { + /* Streaming mode is active, so flip the SM bit. */ + svcr = SVCR_SM_BIT; + regcache->raw_supply (tdep->sme_svcr_regnum, &svcr); + + /* Fetch the SVE data from the SSVE section. */ + supply_sve_regset (regset, regcache, regnum, buf, size); + } +} + +/* Collect register REGNUM from REGCACHE to BUF, using the register + map in REGSET. If REGNUM is -1, do this for all registers in + REGSET. */ + +static void +aarch64_linux_collect_ssve_regset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *buf, size_t size) +{ + struct gdbarch *gdbarch = regcache->arch (); + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + ULONGEST svcr = 0; + regcache->raw_collect (tdep->sme_svcr_regnum, &svcr); + + /* Is streaming mode enabled? */ + if (svcr & SVCR_SM_BIT) + { + /* If so, dump SVE regcache data to the SSVE section. */ + collect_sve_regset (regset, regcache, regnum, buf, size); + } + else + { + /* Otherwise dump an empty SVE block to the SSVE section with the + streaming vector length. */ + collect_inactive_sve_regset (regcache, buf, size, tdep->sme_svg_regnum); + } +} + +/* Supply register REGNUM from BUF to REGCACHE, using the register map + in REGSET. If REGNUM is -1, do this for all registers in REGSET. + If BUF is NULL, set the registers to "unavailable" status. */ + +static void +aarch64_linux_supply_za_regset (const struct regset *regset, + struct regcache *regcache, + int regnum, const void *buf, size_t size) +{ + gdb_byte *header = (gdb_byte *) buf; + struct gdbarch *gdbarch = regcache->arch (); + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + + /* Handle an empty buffer. */ + if (buf == nullptr) + return regcache->supply_regset (regset, regnum, nullptr, size); + + if (size < SVE_HEADER_SIZE) + error (_("ZA state header size (%s) invalid. Should be at least %s."), + pulongest (size), pulongest (SVE_HEADER_SIZE)); + + /* The ZA register note in a core file can have a couple of states: + + 1 - Just the header without the payload. This means that there is no + ZA data, and we should populate only SVCR and SVG registers on GDB's + side. The ZA data should be marked as unavailable. + + 2 - The header with an additional data payload. This means there is + actual ZA data, and we should populate ZA, SVCR and SVG. */ + + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + /* Populate SVG. */ + ULONGEST svg + = sve_vg_from_vl (extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET, + SVE_HEADER_VL_LENGTH, + byte_order)); + regcache->raw_supply (tdep->sme_svg_regnum, &svg); + + size_t data_size + = extract_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET, + SVE_HEADER_SIZE_LENGTH, byte_order) + - SVE_HEADER_SIZE; + + /* Populate SVCR. */ + bool has_za_payload = (data_size > 0); + ULONGEST svcr; + regcache->raw_collect (tdep->sme_svcr_regnum, &svcr); + + /* If we have a ZA payload, enable bit 2 of SVCR, otherwise clear it. This + register gets updated by the SVE/SSVE-handling functions as well, as they + report the SM bit 1. */ + if (has_za_payload) + svcr |= SVCR_ZA_BIT; + else + svcr &= ~SVCR_ZA_BIT; + + /* Update SVCR in the register buffer. */ + regcache->raw_supply (tdep->sme_svcr_regnum, &svcr); + + /* Populate the register cache with ZA register contents, if we have any. */ + buf = has_za_payload ? (gdb_byte *) buf + SVE_HEADER_SIZE : nullptr; + + size_t za_bytes = std::pow (sve_vl_from_vg (svg), 2); + + /* Update ZA in the register buffer. */ + if (has_za_payload) + { + /* Check that the payload size is sane. */ + if (size < SVE_HEADER_SIZE + za_bytes) + { + error (_("ZA header + payload size (%s) invalid. Should be at " + "least %s."), + pulongest (size), pulongest (SVE_HEADER_SIZE + za_bytes)); + } + + regcache->raw_supply (tdep->sme_za_regnum, buf); + } + else + { + gdb_byte za_zeroed[za_bytes]; + memset (za_zeroed, 0, za_bytes); + regcache->raw_supply (tdep->sme_za_regnum, za_zeroed); + } +} + +/* Collect register REGNUM from REGCACHE to BUF, using the register + map in REGSET. If REGNUM is -1, do this for all registers in + REGSET. */ + +static void +aarch64_linux_collect_za_regset (const struct regset *regset, + const struct regcache *regcache, + int regnum, void *buf, size_t size) +{ + gdb_assert (buf != nullptr); + + /* Sanity check the dump size. */ + gdb_assert (size >= SVE_HEADER_SIZE); + + /* The ZA register note in a core file can have a couple of states: + + 1 - Just the header without the payload. This means that there is no + ZA data, and we should dump just the header. + + 2 - The header with an additional data payload. This means there is + actual ZA data, and we should dump both the header and the ZA data + payload. */ + + aarch64_gdbarch_tdep *tdep + = gdbarch_tdep (regcache->arch ()); + + /* Determine if we have ZA state from the SVCR register ZA bit. */ + ULONGEST svcr; + regcache->raw_collect (tdep->sme_svcr_regnum, &svcr); + + /* Check the ZA payload. */ + bool has_za_payload = (svcr & SVCR_ZA_BIT) != 0; + size = has_za_payload ? size : SVE_HEADER_SIZE; + + /* Write the size and max_size fields. */ + gdb_byte *header = (gdb_byte *) buf; + enum bfd_endian byte_order = gdbarch_byte_order (regcache->arch ()); + store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET, + SVE_HEADER_SIZE_LENGTH, byte_order, size); + + uint32_t max_size + = SVE_HEADER_SIZE + std::pow (sve_vl_from_vq (tdep->sme_svq), 2); + store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET, + SVE_HEADER_MAX_SIZE_LENGTH, byte_order, max_size); + + /* Output the other fields of the ZA header (vl, max_vl, flags and + reserved). */ + uint64_t svq = tdep->sme_svq; + store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH, + byte_order, sve_vl_from_vq (svq)); + + uint16_t max_vl = SVE_CORE_DUMMY_MAX_VL; + store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET, + SVE_HEADER_MAX_VL_LENGTH, byte_order, + max_vl); + + uint16_t flags = SVE_CORE_DUMMY_FLAGS; + store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET, + SVE_HEADER_FLAGS_LENGTH, byte_order, flags); + + uint16_t reserved = SVE_CORE_DUMMY_RESERVED; + store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET, + SVE_HEADER_RESERVED_LENGTH, byte_order, reserved); + + buf = has_za_payload ? (gdb_byte *) buf + SVE_HEADER_SIZE : nullptr; + + /* Dump the register cache contents for the ZA register to the buffer. */ + regcache->collect_regset (regset, regnum, (gdb_byte *) buf, + size - SVE_HEADER_SIZE); +} + /* Implement the "iterate_over_regset_sections" gdbarch method. */ static void @@ -917,6 +1334,30 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, { 0 } }; + const struct regset aarch64_linux_ssve_regset = + { + sve_regmap, + aarch64_linux_supply_ssve_regset, aarch64_linux_collect_ssve_regset, + REGSET_VARIABLE_SIZE + }; + + /* If SME is supported in the core file, process the SSVE section first, + and the SVE section last. This is because we need information from + the SSVE set to determine if streaming mode is active. If streaming + mode is active, we need to extract the data from the SSVE section. + + Otherwise, if streaming mode is not active, we fetch the data from the + SVE section. */ + if (tdep->has_sme ()) + { + cb (".reg-aarch-ssve", + SVE_HEADER_SIZE + + regcache_map_entry_size (aarch64_linux_fpregmap), + SVE_HEADER_SIZE + regcache_map_entry_size (sve_regmap), + &aarch64_linux_ssve_regset, "SSVE registers", cb_data); + } + + /* Handle the SVE register set. */ const struct regset aarch64_linux_sve_regset = { sve_regmap, @@ -933,6 +1374,29 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, AARCH64_LINUX_SIZEOF_FPREGSET, &aarch64_linux_fpregset, NULL, cb_data); + if (tdep->has_sme ()) + { + /* Setup the register set information for a ZA register set core + dump. */ + + /* Create this on the fly in order to handle the ZA register size. */ + const struct regcache_map_entry za_regmap[] = + { + { 1, tdep->sme_za_regnum, (int) std::pow (sve_vl_from_vq (tdep->sme_svq), 2) } + }; + + const struct regset aarch64_linux_za_regset = + { + za_regmap, + aarch64_linux_supply_za_regset, aarch64_linux_collect_za_regset, + REGSET_VARIABLE_SIZE + }; + + cb (".reg-aarch-za", + SVE_HEADER_SIZE, + SVE_HEADER_SIZE + std::pow (sve_vl_from_vq (tdep->sme_svq), 2), + &aarch64_linux_za_regset, "ZA register", cb_data); + } if (tdep->has_pauth ()) { @@ -1011,7 +1475,16 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch, CORE_ADDR hwcap2 = linux_get_hwcap2 (auxv, target, gdbarch); aarch64_features features; - features.vq = aarch64_linux_core_read_vq (gdbarch, abfd); + + /* We need to extract the SVE data from the .reg-aarch-sve section or the + .reg-aarch-ssve section depending on which one was active when the core + file was generated. + + If the SSVE section contains SVE data, then it is considered active. + Otherwise the SVE section is considered active. This guarantees we will + have the correct target description with the correct SVE vector + length. */ + features.vq = aarch64_linux_core_read_vq_from_sections (gdbarch, abfd); features.pauth = hwcap & AARCH64_HWCAP_PACA; features.mte = hwcap2 & HWCAP2_MTE; @@ -1025,6 +1498,9 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch, features.tls = size / AARCH64_TLS_REGISTER_SIZE; } + features.svq + = aarch64_linux_core_read_vq (gdbarch, abfd, ".reg-aarch-za"); + return aarch64_read_description (features); } diff --git a/gdb/arch/aarch64-scalable-linux.c b/gdb/arch/aarch64-scalable-linux.c index 3803acfd9a8..2e4aa92e36f 100644 --- a/gdb/arch/aarch64-scalable-linux.c +++ b/gdb/arch/aarch64-scalable-linux.c @@ -19,3 +19,37 @@ along with this program. If not, see . */ #include "arch/aarch64-scalable-linux.h" +#include "arch/aarch64.h" +#include "gdbsupport/byte-vector.h" +#include "gdbsupport/common-regcache.h" + +/* See arch/aarch64-scalable-linux.h */ + +bool +sve_state_is_empty (const struct reg_buffer_common *reg_buf) +{ + /* Instead of allocating a buffer with the size of the current vector + length, just use a buffer that is big enough for all cases. */ + gdb_byte zero_buffer[256]; + + /* Zero it out. */ + memset (zero_buffer, 0, 256); + + /* Are any of the Z registers set (non-zero) after the first 128 bits? */ + for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++) + { + if (!reg_buf->raw_compare (AARCH64_SVE_Z0_REGNUM + i, zero_buffer, + V_REGISTER_SIZE)) + return false; + } + + /* Are any of the P registers set (non-zero)? */ + for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++) + { + if (!reg_buf->raw_compare (AARCH64_SVE_P0_REGNUM + i, zero_buffer, 0)) + return false; + } + + /* Is the FFR register set (non-zero)? */ + return reg_buf->raw_compare (AARCH64_SVE_FFR_REGNUM, zero_buffer, 0); +} diff --git a/gdb/arch/aarch64-scalable-linux.h b/gdb/arch/aarch64-scalable-linux.h index df1741004ed..cb9d85a9d5d 100644 --- a/gdb/arch/aarch64-scalable-linux.h +++ b/gdb/arch/aarch64-scalable-linux.h @@ -22,6 +22,7 @@ #define ARCH_AARCH64_SCALABLE_LINUX_H #include "gdbsupport/common-defs.h" +#include "gdbsupport/common-regcache.h" /* Feature check for Scalable Matrix Extension. */ #ifndef HWCAP2_SME @@ -35,4 +36,18 @@ /* Mask including all valid SVCR bits. */ #define SVCR_BIT_MASK (SVCR_SM_BIT | SVCR_ZA_BIT) +/* SVE/SSVE-related constants used for an empty SVE/SSVE register set + dumped to a core file. When SME is supported, either the SVE state or + the SSVE state will be empty when it is dumped to a core file. */ +#define SVE_CORE_DUMMY_SIZE 0x220 +#define SVE_CORE_DUMMY_MAX_SIZE 0x2240 +#define SVE_CORE_DUMMY_VL 0x10 +#define SVE_CORE_DUMMY_MAX_VL 0x100 +#define SVE_CORE_DUMMY_FLAGS 0x0 +#define SVE_CORE_DUMMY_RESERVED 0x0 + +/* Return TRUE if the SVE state in the register cache REGCACHE + is empty (zero). Return FALSE otherwise. */ +extern bool sve_state_is_empty (const struct reg_buffer_common *reg_buf); + #endif /* ARCH_AARCH64_SCALABLE_LINUX_H */ From patchwork Mon Sep 18 21:26:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76334 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 30A9D38555B9 for ; Mon, 18 Sep 2023 21:32:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30A9D38555B9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072743; bh=8AeRCBEkfawlx/0Tj/9VhXoLqadhQSxOEJVUcT/8ZM8=; 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=jX1PjVEXL9annWPTgrB/hjmK49dqU/PORaPEij5byQAzQWvR1iLrhDLqezcIqafms A3+dCCrnUxcPfIYb9Ecigu9Kd3Sk9sHEBUil9u+b8iX/dee4joJF/WiBTFjgQjGZHw 8LHpxIGm57gz1uZZsxiuBqDRWJDW1cN6Rt4ji2vM= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2071.outbound.protection.outlook.com [40.107.13.71]) by sourceware.org (Postfix) with ESMTPS id 810BC385703F for ; Mon, 18 Sep 2023 21:27:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 810BC385703F Received: from FR3P281CA0179.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:a0::16) by PAXPR08MB6494.eurprd08.prod.outlook.com (2603:10a6:102:154::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:25 +0000 Received: from VI1EUR03FT033.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:a0:cafe::9e) by FR3P281CA0179.outlook.office365.com (2603:10a6:d10:a0::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:25 +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 VI1EUR03FT033.mail.protection.outlook.com (100.127.144.234) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:24 +0000 Received: ("Tessian outbound 5c548696a0e7:v175"); Mon, 18 Sep 2023 21:27:23 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: f159a735e91404b2 X-CR-MTA-TID: 64aa7808 Received: from 327a7d3fca3d.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id 2C557F52-A0B3-4442-8EEA-63E3BC17780E.1; Mon, 18 Sep 2023 21:27:17 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 327a7d3fca3d.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lSyGoqpRth6IINuWN/smNh+wQXDc7ZUaRBi98W6ohnqfL21QIB+G5Ce1DmmQXuFgyJ8pIfL3Is2LwmO79YZNC5MTdpbXKPIEUf2cAf5TEAU5HE8SJ1afMjpkgO10GjorMZUfZOVOL47mk/NTYXQiWmn3/zC18Vu3nJh7nprpY7bKM4n7cTA20BTayoKLU6cxx0yjY7t9OgaGOGdCRF6VlWe0NDGLLXqsjiybOzkpnM0xDvtFCNRf/d+fIuYGfOJHQqXFcknMNhDagx6VnP85uHi7NAzlLf6xF4vdd88PXnU6bu2yJ5NoV/d3LHMjLal+eKf4BHTBhmG1PAwonfv7jA== 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=8AeRCBEkfawlx/0Tj/9VhXoLqadhQSxOEJVUcT/8ZM8=; b=n9KIdijx4R5W128KEZX2Xwq1uAI469qgMyOkJXpO4IkYocysAJFhBrd6Bv9fSS/F7Sro8oxNv/zXv/AsD3YXnwSE3Nw4QqMKEd9BX46c2OL5qucnhZ/dZjdwortJTZxfksqQccgYx1VE/7tdCQg2OGv75pLNObhswRW6Ms/trnGpAkrbVJBojkCv1ALtcUFfEshfcW7xUWjcWzFibVmCYJVzTFIH6AhhRZizg2vXpWjHzrJcVcJjAJJ9LOWYj/9C17up9LKDLHJTQ82eJvoZELyhwwDM2mS62u5/lrlaq7LBcHVW/vGlw71/cdfPuBlnjK4fV6J+RbRrhnLwPPxoVw== 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 DB5PR08MB10285.eurprd08.prod.outlook.com (2603:10a6:10:4a9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6768.30; Mon, 18 Sep 2023 21:27:09 +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:09 +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:09 +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:08 +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:08 +0000 To: Subject: [PATCH v7 17/18] [gdb/testsuite] sme: Add SVE/SME testcases Date: Mon, 18 Sep 2023 22:26:50 +0100 Message-ID: <20230918212651.660141-18-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_|DB5PR08MB10285:EE_|VI1EUR03FT033:EE_|PAXPR08MB6494:EE_ X-MS-Office365-Filtering-Correlation-Id: 742c3db8-0639-4769-1285-08dbb88e0cf5 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: iJdwi7NAUA4tCfgMWceXt66xOEZVmV1QFdRUwo3gXTT5Rztmp4C/s44D84P8vFudPPJwFdYBjT+ka302qwgUEY1KSG/ZHDdTZsDI9Q2YHiu4t3QWScCS/8KPgAbPuzOjSXiHl+QSIOsmlly91Kv9M7USkWqPVbd2MRTop3SJm8uTHhlr3tpbSxsN9+l0RPSukfSE3mTFhWEKlnoHu7BrOmt0T3MDHeir3mv5oZFzNxa9Lm0V8Lvn4wWMpAXq+E3lsNzCdupoYI7fQbe8fwxLgI7YZrUllF1c3CoZNs02DRrKscxbYeFFJno26Q33e71FTJe8CgnchlGjFqgGR47EGpTTUWtdjORar/zekNoNOTdncyMv3adD8TSX6mHxnabGZN/Q6QL3uk1avfE2cCGQn8jmgurLAQesUKBimItu7hVg534ypeKOvUhJ8aKu9ql7UtXbEA+k+zQyD/CqY5WzDnf5/nHrn00fEFWkUoMHF2YYVNJTNVlqXBbAqlb56MltQ4bTXVAk3i5tbFeayXjgVAN0D3wXQrsrucs13pQHeHjoDeQissGiAt1jjS1LuGPkxw3KIy6XvRQSgR4q6zwKp5/YxVWy2b8U2r51iPJm2vBTr+3360zuixRkZozkohHIvS3tcc00hGvnWPpvO5dpw5cuQ9t+f9e2hdY8ZgT/ha7FavBJ4RlsFeHXOd490vZSjsJ9H7DIlYqhjdu3DvZamBVrcxO4tFBy4W9ZWn1AGplCA/+eKbC7In/S+Qe+VCID 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)(136003)(39850400004)(376002)(346002)(396003)(186009)(1800799009)(82310400011)(451199024)(46966006)(36840700001)(7696005)(6666004)(47076005)(44832011)(83380400001)(82740400003)(81166007)(86362001)(356005)(36756003)(5660300002)(36860700001)(26005)(1076003)(2616005)(40480700001)(426003)(336012)(2906002)(41300700001)(8676002)(8936002)(4326008)(70586007)(70206006)(54906003)(30864003)(6916009)(316002)(478600001)(2004002)(36900700001)(579004)(559001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR08MB10285 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VI1EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: e13d11fb-d3bf-4005-c131-08dbb88e03e0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bpziWf5u6XxetwROxR/E0IpJuqPgWo2g8iGBRd+C9OS+UqNRsTIjepqC6oEfjze+CDuRJDfoNTHgsnViByYzONifUkTfPUp/wV6ywwrtU1yICr32mtz5BPG0aPFOsoWkexpKsjVeSXQbR6STQa17mlGdQOdS8SOPV4c7in6a0bp0n7LuUqnZogjB5vhe+HPDtDoIk8H/X+KflHvTh+ITaeg9oiqCRMFH+tc9WPQLjpDsqdfsr2XmG5FBC2zPaSF8T2CWfJpbK/zK4uKDNCdckRp5tVpi5mHk0hVErVXhYPzLRVaQ5s4GiPin2to9Pk6G+0LEMStMdjEuDQzkbYE7B5Uil9BFCoY7ox55Mz9ZPq8raHJIQqnkcN8OMVMBJpUUjJYq/aoPQLlDL8YVAxeAbEQ6Q0Xsx94wzTS+1gDxC/PzFcQXcFpPs1LK8LROw7wbO/KKTTsW6nU/IpqbI29dJxodMfN5F+4/F6I+PMtV5bcPRnVQ5/z2G+valKsGkczzm9+G66zU7SaJwJO+bSgBhgcxfQz6bZgsB7ieJzZ0GhlyEqgTQv1SDQmWBdrB4bVmLKiNIUhdTkj+ydkUVW26GnkGvBvVh5CdzKhAOjJgfCFko0AJncgusO29zpVqi0Yg6XajDarCR9qj2OvLn3gAjkGyN194turIlmeOIa6+oIVZ2/W9JFxQF0C83WxdIl3RMQA/voO3BRxTu6wlXOS4SemAsKX5j0n7ozITM0lMa90pJPEmxy8CAAcTwPn0Xo5O 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)(136003)(39860400002)(396003)(376002)(346002)(1800799009)(451199024)(186009)(82310400011)(40470700004)(46966006)(36840700001)(54906003)(40460700003)(70206006)(70586007)(36860700001)(6916009)(81166007)(316002)(8936002)(8676002)(4326008)(47076005)(82740400003)(41300700001)(7696005)(6666004)(478600001)(83380400001)(107886003)(336012)(1076003)(426003)(2616005)(26005)(86362001)(30864003)(2906002)(44832011)(5660300002)(40480700001)(36756003)(2004002)(579004)(559001); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:24.3749 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 742c3db8-0639-4769-1285-08dbb88e0cf5 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: VI1EUR03FT033.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR08MB6494 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, KAM_DMARC_NONE, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SCC_5_SHORT_WORD_LINES, 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" v7: - Bail out from sme tests if we have a remote target, due to lack of support in the RSP. v3: - Additional documentation for some testcases based on upstream reviews. - Addressed upstream review comments. v2: - Introduced a couple helper functions to determine the available SVE and SME vector lengths. - Before running a batch of tests, validate that the target supports a certain SVE vector length or SME streaming vector length. If not supported, skip that batch of tests. - Fixed up native core file testing to remove generation of a spurious core file, which later would be reported as unexpected by the testsuite. - Fixed tpidr2 dump in core file tests. --- Add 5 SVE/SME tests to exercise all the new features like reading/writing registers, pseudo-registers, signal frames and core files. - Sanity check for SME: Gives a brief smoke test to make sure the most basic of features are working correctly. - ZA unavailability tests: Validates the behavior/content of the ZA register is correct when no payload is available. It also exercises changing the vector lengths. - ZA Availability tests: These tests exercise reading/writing to all the possible ZA pseudo-registers, and validates the state is correct. - Core file tests: Validates that core file reading and writing works correctly and that all state dumped/loaded is sane. This is exercised for both Linux Kernel core files and gcore core files. - Signal frame tests: Validates the correct restoration of SME/SVE/FPSIMD values across signal frames. Since some of these tests are very lengthy and take a little while to run (under QEMU at the moment), I decided to parallelize them into smaller chunks so we can throw some more CPU power at them so they run faster. I'd still like to add a few more tests to give the testsuite more coverage in the areas of SME/SVE. Hopefully in the near future that will happen. Just a reminder that these SME tests are currently unsupported when gdb is connected to a remote target. That's because the RSP doesn't support communicating changes in vector lenghts mid-execution, so gdb will always get wrong state from the remote target. Co-Authored-By: Ezra Sitorus Reviewed-by: Thiago Jung Bauermann --- gdb/testsuite/gdb.arch/aarch64-sme-core-0.exp | 23 ++ gdb/testsuite/gdb.arch/aarch64-sme-core-1.exp | 23 ++ gdb/testsuite/gdb.arch/aarch64-sme-core-2.exp | 23 ++ gdb/testsuite/gdb.arch/aarch64-sme-core-3.exp | 23 ++ gdb/testsuite/gdb.arch/aarch64-sme-core-4.exp | 23 ++ gdb/testsuite/gdb.arch/aarch64-sme-core.c | 372 ++++++++++++++++++ .../gdb.arch/aarch64-sme-core.exp.tcl | 188 +++++++++ .../gdb.arch/aarch64-sme-regs-available-0.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-1.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-2.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-3.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-4.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-5.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-6.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-7.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-8.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available-9.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-available.c | 178 +++++++++ .../aarch64-sme-regs-available.exp.tcl | 245 ++++++++++++ .../gdb.arch/aarch64-sme-regs-sigframe-0.exp | 23 ++ .../gdb.arch/aarch64-sme-regs-sigframe-1.exp | 23 ++ .../gdb.arch/aarch64-sme-regs-sigframe-2.exp | 23 ++ .../gdb.arch/aarch64-sme-regs-sigframe-3.exp | 23 ++ .../gdb.arch/aarch64-sme-regs-sigframe-4.exp | 23 ++ .../gdb.arch/aarch64-sme-regs-sigframe.c | 366 +++++++++++++++++ .../aarch64-sme-regs-sigframe.exp.tcl | 179 +++++++++ .../aarch64-sme-regs-unavailable-0.exp | 26 ++ .../aarch64-sme-regs-unavailable-1.exp | 26 ++ .../aarch64-sme-regs-unavailable-2.exp | 26 ++ .../aarch64-sme-regs-unavailable-3.exp | 26 ++ .../aarch64-sme-regs-unavailable-4.exp | 26 ++ .../aarch64-sme-regs-unavailable-5.exp | 26 ++ .../aarch64-sme-regs-unavailable-6.exp | 26 ++ .../aarch64-sme-regs-unavailable-7.exp | 26 ++ .../aarch64-sme-regs-unavailable-8.exp | 26 ++ .../aarch64-sme-regs-unavailable-9.exp | 26 ++ .../gdb.arch/aarch64-sme-regs-unavailable.c | 152 +++++++ .../aarch64-sme-regs-unavailable.exp.tcl | 212 ++++++++++ gdb/testsuite/gdb.arch/aarch64-sme-sanity.c | 249 ++++++++++++ gdb/testsuite/gdb.arch/aarch64-sme-sanity.exp | 72 ++++ gdb/testsuite/lib/aarch64-scalable.exp | 239 +++++++++++ gdb/testsuite/lib/aarch64-test-sme.c | 90 +++++ gdb/testsuite/lib/aarch64-test-sve.c | 90 +++++ gdb/testsuite/lib/aarch64.exp | 153 +++++++ gdb/testsuite/lib/gdb.exp | 249 ++++++++++++ 45 files changed, 3784 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core-0.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core-1.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core-2.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core-3.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core-4.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-core.exp.tcl create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-0.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-1.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-2.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-3.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-4.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-5.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-6.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-7.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-8.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available-9.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-available.exp.tcl create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-0.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-1.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-2.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-3.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-4.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.exp.tcl create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-0.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-1.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-2.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-3.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-4.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-5.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-6.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-7.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-8.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-9.exp create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.exp.tcl create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-sanity.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sme-sanity.exp create mode 100644 gdb/testsuite/lib/aarch64-scalable.exp create mode 100644 gdb/testsuite/lib/aarch64-test-sme.c create mode 100644 gdb/testsuite/lib/aarch64-test-sve.c create mode 100644 gdb/testsuite/lib/aarch64.exp diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core-0.exp b/gdb/testsuite/gdb.arch/aarch64-sme-core-0.exp new file mode 100644 index 00000000000..5a51bbd8a1d --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core-0.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: FPSIMD +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (0 ~ 24) out of 125 tests. +set id_start 0 +set id_end 24 +source $srcdir/$subdir/aarch64-sme-core.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core-1.exp b/gdb/testsuite/gdb.arch/aarch64-sme-core-1.exp new file mode 100644 index 00000000000..41e93b15834 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core-1.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: SVE +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (25 ~ 49) out of 125 tests. +set id_start 25 +set id_end 49 +source $srcdir/$subdir/aarch64-sme-core.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core-2.exp b/gdb/testsuite/gdb.arch/aarch64-sme-core-2.exp new file mode 100644 index 00000000000..05144d9f560 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core-2.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: SSVE +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (50 ~ 74) out of 125 tests. +set id_start 50 +set id_end 74 +source $srcdir/$subdir/aarch64-sme-core.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core-3.exp b/gdb/testsuite/gdb.arch/aarch64-sme-core-3.exp new file mode 100644 index 00000000000..fa8931a46d1 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core-3.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: ZA only +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (75 ~ 99) out of 125 tests. +set id_start 75 +set id_end 99 +source $srcdir/$subdir/aarch64-sme-core.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core-4.exp b/gdb/testsuite/gdb.arch/aarch64-sme-core-4.exp new file mode 100644 index 00000000000..8881898b370 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core-4.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: ZA + SSVE +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (100 ~ 124) out of 125 tests. +set id_start 100 +set id_end 124 +source $srcdir/$subdir/aarch64-sme-core.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core.c b/gdb/testsuite/gdb.arch/aarch64-sme-core.c new file mode 100644 index 00000000000..d71d18ebd3b --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core.c @@ -0,0 +1,372 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Exercise AArch64's Scalable Vector/Matrix Extension core file generation + for GDB. This includes reading Linux Kernel-generated core files and + writing GDB core files via the gcore command and making sure the contents + are sane. */ + +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +#ifndef PR_SVE_SET_VL +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#define PR_SVE_VL_LEN_MASK 0xffff +#endif + +#ifndef PR_SME_SET_VL +#define PR_SME_SET_VL 63 +#define PR_SME_GET_VL 64 +#define PR_SME_VL_LEN_MASK 0xffff +#endif + +static void +enable_za () +{ + /* smstart za */ + __asm __volatile (".word 0xD503457F"); +} + +static void +disable_za () +{ + /* smstop za */ + __asm __volatile (".word 0xD503447F"); +} + +static void +enable_sm () +{ + /* smstart sm */ + __asm __volatile (".word 0xD503437F"); +} + +static void +disable_sm () +{ + /* smstop sm */ + __asm __volatile (".word 0xD503427F"); +} + +static void +initialize_fpsimd_state () +{ + char buffer[16]; + + for (int i = 0; i < 16; i++) + buffer[i] = 0x55; + + __asm __volatile ("mov x0, %0\n\t" \ + : : "r" (buffer)); + + __asm __volatile ("ldr q0, [x0]"); + __asm __volatile ("ldr q1, [x0]"); + __asm __volatile ("ldr q2, [x0]"); + __asm __volatile ("ldr q3, [x0]"); + __asm __volatile ("ldr q4, [x0]"); + __asm __volatile ("ldr q5, [x0]"); + __asm __volatile ("ldr q6, [x0]"); + __asm __volatile ("ldr q7, [x0]"); + __asm __volatile ("ldr q8, [x0]"); + __asm __volatile ("ldr q9, [x0]"); + __asm __volatile ("ldr q10, [x0]"); + __asm __volatile ("ldr q11, [x0]"); + __asm __volatile ("ldr q12, [x0]"); + __asm __volatile ("ldr q13, [x0]"); + __asm __volatile ("ldr q14, [x0]"); + __asm __volatile ("ldr q15, [x0]"); + __asm __volatile ("ldr q16, [x0]"); + __asm __volatile ("ldr q17, [x0]"); + __asm __volatile ("ldr q18, [x0]"); + __asm __volatile ("ldr q19, [x0]"); + __asm __volatile ("ldr q20, [x0]"); + __asm __volatile ("ldr q21, [x0]"); + __asm __volatile ("ldr q22, [x0]"); + __asm __volatile ("ldr q23, [x0]"); + __asm __volatile ("ldr q24, [x0]"); + __asm __volatile ("ldr q25, [x0]"); + __asm __volatile ("ldr q26, [x0]"); + __asm __volatile ("ldr q27, [x0]"); + __asm __volatile ("ldr q28, [x0]"); + __asm __volatile ("ldr q29, [x0]"); + __asm __volatile ("ldr q30, [x0]"); + __asm __volatile ("ldr q31, [x0]"); +} + +static void +initialize_za_state () +{ + /* zero za */ + __asm __volatile (".word 0xC00800FF"); + + char buffer[256]; + + for (int i = 0; i < 256; i++) + buffer[i] = 0xaa; + + __asm __volatile ("mov x0, %0\n\t" \ + : : "r" (buffer)); + + /* Initialize loop boundaries. */ + __asm __volatile ("mov w12, 0"); + __asm __volatile ("mov w17, 256"); + + /* loop: ldr za[w12, 0], [x0] */ + __asm __volatile ("loop: .word 0xe1000000"); + __asm __volatile ("add w12, w12, 1"); + __asm __volatile ("cmp w12, w17"); + __asm __volatile ("bne loop"); +} + +static void +initialize_tpidr2 () +{ + __asm __volatile ("mov x0, #0xffffffffffffffff"); + + /* Write x0 to tpidr2. */ + __asm __volatile (".word 0xd51bd0a0"); +} + +static void +initialize_sve_state () +{ + __asm __volatile ("dup z0.b, -1"); + __asm __volatile ("dup z1.b, -1"); + __asm __volatile ("dup z2.b, -1"); + __asm __volatile ("dup z3.b, -1"); + __asm __volatile ("dup z4.b, -1"); + __asm __volatile ("dup z5.b, -1"); + __asm __volatile ("dup z6.b, -1"); + __asm __volatile ("dup z7.b, -1"); + __asm __volatile ("dup z8.b, -1"); + __asm __volatile ("dup z9.b, -1"); + __asm __volatile ("dup z10.b, -1"); + __asm __volatile ("dup z11.b, -1"); + __asm __volatile ("dup z12.b, -1"); + __asm __volatile ("dup z13.b, -1"); + __asm __volatile ("dup z14.b, -1"); + __asm __volatile ("dup z15.b, -1"); + __asm __volatile ("dup z16.b, -1"); + __asm __volatile ("dup z17.b, -1"); + __asm __volatile ("dup z18.b, -1"); + __asm __volatile ("dup z19.b, -1"); + __asm __volatile ("dup z20.b, -1"); + __asm __volatile ("dup z21.b, -1"); + __asm __volatile ("dup z22.b, -1"); + __asm __volatile ("dup z23.b, -1"); + __asm __volatile ("dup z24.b, -1"); + __asm __volatile ("dup z25.b, -1"); + __asm __volatile ("dup z26.b, -1"); + __asm __volatile ("dup z27.b, -1"); + __asm __volatile ("dup z28.b, -1"); + __asm __volatile ("dup z29.b, -1"); + __asm __volatile ("dup z30.b, -1"); + __asm __volatile ("dup z31.b, -1"); + __asm __volatile ("ptrue p0.b"); + __asm __volatile ("ptrue p1.b"); + __asm __volatile ("ptrue p2.b"); + __asm __volatile ("ptrue p3.b"); + __asm __volatile ("ptrue p4.b"); + __asm __volatile ("ptrue p5.b"); + __asm __volatile ("ptrue p6.b"); + __asm __volatile ("ptrue p7.b"); + __asm __volatile ("ptrue p8.b"); + __asm __volatile ("ptrue p9.b"); + __asm __volatile ("ptrue p10.b"); + __asm __volatile ("ptrue p11.b"); + __asm __volatile ("ptrue p12.b"); + __asm __volatile ("ptrue p13.b"); + __asm __volatile ("ptrue p14.b"); + __asm __volatile ("ptrue p15.b"); + __asm __volatile ("setffr"); +} + +static int get_vl_size () +{ + int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_GET_VL (%d)", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int get_svl_size () +{ + int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int set_vl_size (int new_vl) +{ + int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_SET_VL (%d)\n", res); + return -1; + } + + res = get_vl_size (); + if (res != new_vl) + { + printf ("Unexpected VL value (%d)\n", res); + return -1; + } + + return res; +} + +static int set_svl_size (int new_svl) +{ + int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_SET_VL (%d)\n", res); + return -1; + } + + res = get_svl_size (); + if (res != new_svl) + { + printf ("Unexpected SVL value (%d)\n", res); + return -1; + } + + return res; +} + +/* Enable register states based on STATE. + + 0 - FPSIMD + 1 - SVE + 2 - SSVE + 3 - ZA + 4 - ZA and SSVE. */ + +void enable_states (int state) +{ + disable_za (); + disable_sm (); + initialize_fpsimd_state (); + + if (state == 1) + { + initialize_sve_state (); + } + else if (state == 2) + { + enable_sm (); + initialize_sve_state (); + } + else if (state == 3) + { + enable_za (); + initialize_za_state (); + } + else if (state == 4) + { + enable_za (); + enable_sm (); + initialize_sve_state (); + initialize_za_state (); + } + + return; +} + +static int +test_id_to_state (int id) +{ + return id / 25; +} + +static int +test_id_to_vl (int id) +{ + return 16 << ((id / 5) % 5); +} + +static int +test_id_to_svl (int id) +{ + return 16 << (id % 5); +} + +static void +dummy () +{ +} + +int +main (int argc, char **argv) +{ + if (argc > 2) + printf ("Incorrect number of arguments passed to test.\n"); + + if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME) + { + long test_id = 0; + + /* If we have a test id passed as argument, read it now. */ + if (argc == 2) + test_id = strtol (argv[1], NULL, 0); + + dummy (); /* stop to initialize test_id */ + + int state = test_id_to_state (test_id); + int vl = test_id_to_vl (test_id); + int svl = test_id_to_svl (test_id); + + if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1) + return -1; + + enable_states (state); + + /* Also set the TPIDR2 register so we can test dumping its contents + to a core file. */ + initialize_tpidr2 (); + + char *p = 0x0; + *p = 0xff; /* crash point */ + } + else + { + printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n"); + return -1; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-core.exp.tcl b/gdb/testsuite/gdb.arch/aarch64-sme-core.exp.tcl new file mode 100644 index 00000000000..851e6e31ec3 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-core.exp.tcl @@ -0,0 +1,188 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Exercise core file reading/writing in the presence of SME support. +# This test exercises GDB's dumping/loading capability for Linux +# Kernel core files and for gcore core files. + +load_lib aarch64-scalable.exp + +# +# Validate that CORE_FILENAME can be read correctly and that the register +# state is sane. +# +proc check_sme_core_file { core_filename state vl svl } { + # Load the core file. + if [gdb_test "core $core_filename" \ + [multi_line \ + "Core was generated by.*\." \ + "Program terminated with signal SIGSEGV, Segmentation fault\." \ + "#0 ${::hex} in main \\(.*\\) at .*" \ + ".*p = 0xff;.* crash point .*"] \ + "load core file"] { + untested "failed to generate core file" + return -1 + } + + check_state $state $vl $svl + + # Check the value of TPIDR2 in the core file. + gdb_test "print/x \$tpidr2" " = 0xffffffffffffffff" \ + "tpidr2 contents from core file" +} + +# +# Generate two core files for EXECUTABLE, BINFILE with a test id of ID. +# STATE is the register state, VL is the SVE vector length and SVL is the +# SME vector length. +# One of the core files is generated by the kernel and the other by the +# gcore command. +# +proc generate_sme_core_files { executable binfile id state vl svl} { + # Run the program until the point where we need to adjust the + # test id. + set init_breakpoint "stop to initialize test_id" + gdb_breakpoint [gdb_get_line_number $init_breakpoint] + gdb_continue_to_breakpoint $init_breakpoint + gdb_test_no_output "set test_id = $id" + + # Run the program until just before the crash. + set crash_breakpoint "crash point" + gdb_breakpoint [gdb_get_line_number $crash_breakpoint] + gdb_continue_to_breakpoint $crash_breakpoint + gdb_test_no_output "set print repeats 1" "adjust repeat count pre-crash" + + # Adjust the register to custom values that we will check later when + # loading the core files. + check_state $state $vl $svl + + # Continue until a crash. + gdb_test "continue" \ + [multi_line \ + "Program received signal SIGSEGV, Segmentation fault\." \ + "${::hex} in main \\(.*\\) at .*" \ + ".*p = 0xff;.* crash point .*"] \ + "run to crash" + + # Generate the gcore core file. + set gcore_filename [standard_output_file "${executable}-${id}-${state}-${vl}-${svl}.gcore"] + set gcore_generated [gdb_gcore_cmd "$gcore_filename" "generate gcore file"] + +# # Continue until the end. +# gdb_test "continue" "Program terminated with signal SIGSEGV.*" \ +# "program terminated with SIGSEGV" + + # Generate a native core file. + set core_filename [core_find ${binfile} {} $id] + set core_generated [expr {$core_filename != ""}] + set native_core_name "${binfile}-${id}-${state}-${vl}-${svl}.core" + remote_exec build "mv $core_filename ${native_core_name}" + set core_filename ${native_core_name} + + # At this point we have a couple core files, the gcore one generated by GDB + # and the native one generated by the Linux Kernel. Make sure GDB can read + # both correctly. + if {$gcore_generated} { + clean_restart ${binfile} + gdb_test_no_output "set print repeats 1" \ + "adjust repeat count post-crash gcore" + + with_test_prefix "gcore corefile" { + check_sme_core_file $gcore_filename $state $vl $svl + } + } else { + fail "gcore corefile not generated" + } + + if {$core_generated} { + clean_restart ${binfile} + + gdb_test_no_output "set print repeats 1" \ + "adjust repeat count post-crash native core" + + with_test_prefix "native corefile" { + check_sme_core_file $core_filename $state $vl $svl + } + } else { + untested "native corefile not generated" + } +} + +# +# Exercise core file reading (kernel-generated core files) and writing +# (gcore command) for test id's ID_START through ID_END. +# +proc test_sme_core_file { id_start id_end } { + set compile_flags {"debug" "macros" "additional_flags=-march=armv8.5-a+sve"} + standard_testfile ${::srcdir}/${::subdir}/aarch64-sme-core.c + set executable "${::testfile}" + if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} { + return -1 + } + set binfile [standard_output_file ${executable}] + + for {set id $id_start} {$id <= $id_end} {incr id} { + set state [test_id_to_state $id] + set vl [test_id_to_vl $id] + set svl [test_id_to_svl $id] + + set skip_unsupported 0 + if {![aarch64_supports_sve_vl $vl] + || ![aarch64_supports_sme_svl $svl]} { + # We have a vector length or streaming vector length that + # is not supported by this target. Skip to the next iteration + # since it is no use running tests for an unsupported vector + # length. + if {![aarch64_supports_sve_vl $vl]} { + verbose -log "SVE vector length $vl not supported." + } elseif {![aarch64_supports_sme_svl $svl]} { + verbose -log "SME streaming vector length $svl not supported." + } + verbose -log "Skipping test." + set skip_unsupported 1 + } + + with_test_prefix "state=${state} vl=${vl} svl=${svl}" { + # If the SVE or SME vector length is not supported, just skip + # these next tests. + if {$skip_unsupported} { + untested "unsupported configuration on target" + continue + } + + if ![runto_main] { + untested "could not run to main" + return -1 + } + + # Check if we are talking to a remote target. If so, bail out, + # as right now remote targets can't communicate vector length (vl + # or svl) changes to gdb via the RSP. When this restriction is + # lifted, we can remove this guard. + if {[gdb_is_target_remote]} { + unsupported "aarch64 sve/sme tests not supported for remote targets" + return -1 + } + + generate_sme_core_files ${executable} ${binfile} $id $state $vl $svl + } + } +} + +require is_aarch64_target +require allow_aarch64_sve_tests +require allow_aarch64_sme_tests + +test_sme_core_file $id_start $id_end diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-0.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-0.exp new file mode 100644 index 00000000000..2a4980171e7 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-0.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 16 +# SVL: 16, 32, 64, 128 +# This set covers 4 (0 ~ 3) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 0 +set id_end 3 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-1.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-1.exp new file mode 100644 index 00000000000..a58e89caab3 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-1.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 16 +# SVL: 256 +# This set covers 1 (4) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 4 +set id_end 4 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-2.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-2.exp new file mode 100644 index 00000000000..8b78e9ec639 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-2.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 32 +# SVL: 16, 32, 64, 128 +# This set covers 4 (5 ~ 8) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 5 +set id_end 8 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-3.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-3.exp new file mode 100644 index 00000000000..57941758870 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-3.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 32 +# SVL: 256 +# This set covers 1 (9) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 9 +set id_end 9 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-4.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-4.exp new file mode 100644 index 00000000000..5d5e800d328 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-4.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 64 +# SVL: 16, 32, 64, 128 +# This set covers 4 (10 ~ 13) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 10 +set id_end 13 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-5.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-5.exp new file mode 100644 index 00000000000..42410d4eb20 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-5.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 64 +# SVL: 256 +# This set covers 1 (14) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 14 +set id_end 14 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-6.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-6.exp new file mode 100644 index 00000000000..36692ac31c1 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-6.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 128 +# SVL: 16, 32, 64, 128 +# This set covers 4 (15 ~ 18) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 15 +set id_end 18 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-7.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-7.exp new file mode 100644 index 00000000000..a3149e7fcae --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-7.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 128 +# SVL: 256 +# This set covers 1 (19) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 19 +set id_end 19 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-8.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-8.exp new file mode 100644 index 00000000000..1859eaf9960 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-8.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 256 +# SVL: 16, 32, 64, 128 +# This set covers 4 (20 ~ 23) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 20 +set id_end 23 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-9.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-9.exp new file mode 100644 index 00000000000..cb30fc63724 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available-9.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 256 +# SVL: 256 +# This set covers 1 (24) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 24 +set id_end 24 +source $srcdir/$subdir/aarch64-sme-regs-available.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available.c b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available.c new file mode 100644 index 00000000000..58c01d0bf9a --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available.c @@ -0,0 +1,178 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Exercise various cases of reading/writing ZA contents for AArch64's + Scalable Matrix Extension. */ + +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +#ifndef PR_SVE_SET_VL +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#define PR_SVE_VL_LEN_MASK 0xffff +#endif + +#ifndef PR_SME_SET_VL +#define PR_SME_SET_VL 63 +#define PR_SME_GET_VL 64 +#define PR_SME_VL_LEN_MASK 0xffff +#endif + +static void +enable_za () +{ + /* smstart za */ + __asm __volatile (".word 0xD503457F"); +} + +static void +disable_za () +{ + /* smstop za */ + __asm __volatile (".word 0xD503447F"); +} + +static int get_vl_size () +{ + int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int get_svl_size () +{ + int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int set_vl_size (int new_vl) +{ + int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_SET_VL (%d)\n", res); + return -1; + } + + res = get_vl_size (); + if (res != new_vl) + { + printf ("Unexpected VL value (%d)\n", res); + return -1; + } + + return res; +} + +static int set_svl_size (int new_svl) +{ + int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_SET_VL (%d)\n", res); + return -1; + } + + res = get_svl_size (); + if (res != new_svl) + { + printf ("Unexpected SVL value (%d)\n", res); + return -1; + } + + return res; +} + +static int +test_id_to_vl (int id) +{ + return 16 << ((id / 5) % 5); +} + +static int +test_id_to_svl (int id) +{ + return 16 << (id % 5); +} + +static void +dummy () +{ +} + +int +main (int argc, char **argv) +{ + if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME) + { + int id_start = ID_START; + int id_end = ID_END; + + for (int id = id_start; id <= id_end; id++) + { + int vl = test_id_to_vl (id); + int svl = test_id_to_svl (id); + + if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1) + continue; + + enable_za (); + dummy (); /* stop 1 */ + } + + for (int id = id_start; id <= id_end; id++) + { + int vl = test_id_to_vl (id); + int svl = test_id_to_svl (id); + + if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1) + continue; + + disable_za (); + dummy (); /* stop 2 */ + } + } + else + { + printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n"); + return -1; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-available.exp.tcl b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available.exp.tcl new file mode 100644 index 00000000000..71637f9cdc1 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-available.exp.tcl @@ -0,0 +1,245 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Exercise reading/writing ZA registers when there is ZA state. + +load_lib aarch64-scalable.exp + +# +# Cycle through all ZA registers and pseudo-registers and validate that their +# contents are available for vector length SVL. +# +# Make sure reading/writing to ZA registers work as expected. +# +proc check_regs { mode vl svl } { + # Check VG to make sure it is correct + set expected_vg [expr $vl / 8] + gdb_test "print \$vg" "= ${expected_vg}" + + # Check SVG to make sure it is correct + set expected_svg [expr $svl / 8] + gdb_test "print \$svg" "= ${expected_svg}" + + # If svl is adjusted by prctl, we will have ZA enabled. If gdb is + # adjusting svl, ZA will not be enabled by default. It will only be + # enabled when ZA is written to. + set za_state "= \\\[ ZA \\\]" + if {$mode == "gdb"} { + set za_state "= \\\[ \\\]" + } + + # Check SVCR. + if [gdb_test "print \$svcr" $za_state "svcr before assignments" ] { + fail "incorrect za state" + return -1 + } + + # Check the size of ZA. + set expected_za_size [expr $svl * $svl] + gdb_test "print sizeof \$za" " = $expected_za_size" + + # Check the size of Z0. + gdb_test "print sizeof \$z0" " = $vl" + + # Exercise reading/writing from/to ZA. + initialize_2d_array "\$za" 255 $svl $svl + set pattern [string_to_regexp [2d_array_value_pattern 255 $svl $svl]] + gdb_test "print \$za" " = $pattern" "read back from za" + + # Exercise reading/writing from/to the tile pseudo-registers. + set last_tile 1 + set expected_size [expr $svl * $svl] + set tile_svl $svl + set za_state "= \\\[ ZA \\\]" + foreach_with_prefix granularity {"b" "h" "s" "d" "q"} { + for {set tile 0} {$tile < $last_tile} {incr tile} { + set register_name "\$za${tile}${granularity}" + + # Test the size. + gdb_test "print sizeof ${register_name}" " = ${expected_size}" + + # Test reading/writing + initialize_2d_array $register_name 255 $tile_svl $tile_svl + + # Make sure we have ZA state. + if [gdb_test "print \$svcr" $za_state "svcr after assignment to ${register_name}" ] { + fail "incorrect za state" + return -1 + } + + set pattern [string_to_regexp [2d_array_value_pattern 255 $tile_svl $tile_svl]] + gdb_test "print $register_name" " = $pattern" "read back from $register_name" + } + set last_tile [expr $last_tile * 2] + set expected_size [expr $expected_size / 2] + set tile_svl [expr $tile_svl / 2] + } + + # Exercise reading/writing from/to the tile slice pseudo-registers. + set last_tile 1 + set last_slice $svl + set expected_size $svl + set num_elements $svl + foreach_with_prefix granularity {"b" "h" "s" "d" "q"} { + for {set tile 0} {$tile < $last_tile} {incr tile} { + for {set slice 0} {$slice < $last_slice} {incr slice} { + foreach_with_prefix direction {"h" "v"} { + set register_name "\$za${tile}${direction}${granularity}${slice}" + + # Test the size. + gdb_test "print sizeof ${register_name}" " = ${expected_size}" + + # Test reading/writing + initialize_1d_array $register_name 255 $num_elements + + # Make sure we have ZA state. + if [gdb_test "print \$svcr" $za_state "svcr after assignment of ${register_name}" ] { + fail "incorrect za state" + return -1 + } + + set pattern [string_to_regexp [1d_array_value_pattern 255 $num_elements]] + gdb_test "print $register_name" " = $pattern" "read back from $register_name" + } + } + } + set last_tile [expr $last_tile * 2] + set last_slice [expr ($last_slice / 2)] + set num_elements [expr $num_elements / 2] + } +} + +# +# Cycle through all ZA registers and pseudo-registers and validate their +# contents. +# +proc test_sme_registers_available { id_start id_end } { + + set compile_flags {"debug" "macros"} + lappend compile_flags "additional_flags=-DID_START=${id_start}" + lappend compile_flags "additional_flags=-DID_END=${id_end}" + + standard_testfile ${::srcdir}/${::subdir}/aarch64-sme-regs-available.c + set executable "${::testfile}-${id_start}-${id_end}" + if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} { + return -1 + } + set binfile [standard_output_file ${executable}] + + if ![runto_main] { + untested "could not run to main" + return -1 + } + + # Check if we are talking to a remote target. If so, bail out, as right now + # remote targets can't communicate vector length (vl or svl) changes to gdb + # via the RSP. When this restriction is lifted, we can remove this guard. + if {[gdb_is_target_remote]} { + unsupported "aarch64 sve/sme tests not supported for remote targets" + return -1 + } + + gdb_test_no_output "set print repeats 1" + + set prctl_breakpoint "stop 1" + gdb_breakpoint [gdb_get_line_number $prctl_breakpoint] + + for {set id $id_start} {$id <= $id_end} {incr id} { + set vl [test_id_to_vl $id] + set svl [test_id_to_svl $id] + + set skip_unsupported 0 + if {![aarch64_supports_sve_vl $vl] + || ![aarch64_supports_sme_svl $svl]} { + # We have a vector length or streaming vector length that + # is not supported by this target. Skip to the next iteration + # since it is no use running tests for an unsupported vector + # length. + if {![aarch64_supports_sve_vl $vl]} { + verbose -log "SVE vector length $vl not supported." + } elseif {![aarch64_supports_sme_svl $svl]} { + verbose -log "SME streaming vector length $svl not supported." + } + verbose -log "Skipping test." + set skip_unsupported 1 + } + + set mode "prctl" + with_test_prefix "$mode, vl=${vl} svl=${svl}" { + # If the SVE or SME vector length is not supported, just skip + # these next tests. + if {$skip_unsupported} { + untested "unsupported configuration on target" + continue + } + + # Run the program until it has adjusted svl. + gdb_continue_to_breakpoint $prctl_breakpoint + check_regs $mode $vl $svl + } + } + + set non_prctl_breakpoint "stop 2" + gdb_breakpoint [gdb_get_line_number $non_prctl_breakpoint] + + for {set id $id_start} {$id <= $id_end} {incr id} { + set vl [test_id_to_vl $id] + set svl [test_id_to_svl $id] + + set skip_unsupported 0 + if {![aarch64_supports_sve_vl $vl] + || ![aarch64_supports_sme_svl $svl]} { + # We have a vector length or streaming vector length that + # is not supported by this target. Skip to the next iteration + # since it is no use running tests for an unsupported vector + # length. + if {![aarch64_supports_sve_vl $vl]} { + verbose -log "SVE vector length $vl not supported." + } elseif {![aarch64_supports_sme_svl $svl]} { + verbose -log "SME streaming vector length $svl not supported." + } + verbose -log "Skipping test." + set skip_unsupported 1 + } + + set mode "gdb" + with_test_prefix "$mode, vl=${vl} svl=${svl}" { + # If the SVE or SME vector length is not supported, just skip + # these next tests. + if {$skip_unsupported} { + untested "unsupported configuration on target" + continue + } + + # Run the program until we stop at the point where gdb should + # adjust the SVE and SME vector lengths. + gdb_continue_to_breakpoint $non_prctl_breakpoint + + # Adjust svl via gdb. + set vg_value [expr $vl / 8] + set svg_value [expr $svl / 8] + gdb_test_no_output "set \$vg = ${vg_value}" + gdb_test_no_output "set \$svg = ${svg_value}" + + check_regs $mode $vl $svl + } + } +} + +require is_aarch64_target +require allow_aarch64_sve_tests +require allow_aarch64_sme_tests + +test_sme_registers_available $id_start $id_end diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-0.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-0.exp new file mode 100644 index 00000000000..ce8a7a703aa --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-0.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: FPSIMD +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (0 ~ 24) out of 125 tests. +set id_start 0 +set id_end 24 +source $srcdir/$subdir/aarch64-sme-regs-sigframe.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-1.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-1.exp new file mode 100644 index 00000000000..092d4b20c48 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-1.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: SVE +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (25 ~ 49) out of 125 tests. +set id_start 25 +set id_end 49 +source $srcdir/$subdir/aarch64-sme-regs-sigframe.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-2.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-2.exp new file mode 100644 index 00000000000..803d297f70d --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-2.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: SSVE +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (50 ~ 74) out of 125 tests. +set id_start 50 +set id_end 74 +source $srcdir/$subdir/aarch64-sme-regs-sigframe.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-3.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-3.exp new file mode 100644 index 00000000000..d1307571bfa --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-3.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: ZA only +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (75 ~ 99) out of 125 tests. +set id_start 75 +set id_end 99 +source $srcdir/$subdir/aarch64-sme-regs-sigframe.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-4.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-4.exp new file mode 100644 index 00000000000..2b84b5dcfc7 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe-4.exp @@ -0,0 +1,23 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# state: ZA + SSVE +# VL: 16, 32, 64, 128, 256 +# SVL: 16, 32, 64, 128, 256 +# This set covers 25 (100 ~ 124) out of 125 tests. +set id_start 100 +set id_end 124 +source $srcdir/$subdir/aarch64-sme-regs-sigframe.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.c b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.c new file mode 100644 index 00000000000..9bc3e9c16fc --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.c @@ -0,0 +1,366 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Exercise AArch64's Scalable Vector/Matrix Extension signal frame handling + for GDB. */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +#ifndef PR_SVE_SET_VL +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#define PR_SVE_VL_LEN_MASK 0xffff +#endif + +#ifndef PR_SME_SET_VL +#define PR_SME_SET_VL 63 +#define PR_SME_GET_VL 64 +#define PR_SME_VL_LEN_MASK 0xffff +#endif + +static int count = 0; + +static void +handler (int sig) +{ + count++; /* handler */ +} + +static void +enable_za () +{ + /* smstart za */ + __asm __volatile (".word 0xD503457F"); +} + +static void +disable_za () +{ + /* smstop za */ + __asm __volatile (".word 0xD503447F"); +} + +static void +enable_sm () +{ + /* smstart sm */ + __asm __volatile (".word 0xD503437F"); +} + +static void +disable_sm () +{ + /* smstop sm */ + __asm __volatile (".word 0xD503427F"); +} + +static void +initialize_fpsimd_state () +{ + char buffer[16]; + + for (int i = 0; i < 16; i++) + buffer[i] = 0x55; + + __asm __volatile ("mov x0, %0\n\t" \ + : : "r" (buffer)); + + __asm __volatile ("ldr q0, [x0]"); + __asm __volatile ("ldr q1, [x0]"); + __asm __volatile ("ldr q2, [x0]"); + __asm __volatile ("ldr q3, [x0]"); + __asm __volatile ("ldr q4, [x0]"); + __asm __volatile ("ldr q5, [x0]"); + __asm __volatile ("ldr q6, [x0]"); + __asm __volatile ("ldr q7, [x0]"); + __asm __volatile ("ldr q8, [x0]"); + __asm __volatile ("ldr q9, [x0]"); + __asm __volatile ("ldr q10, [x0]"); + __asm __volatile ("ldr q11, [x0]"); + __asm __volatile ("ldr q12, [x0]"); + __asm __volatile ("ldr q13, [x0]"); + __asm __volatile ("ldr q14, [x0]"); + __asm __volatile ("ldr q15, [x0]"); + __asm __volatile ("ldr q16, [x0]"); + __asm __volatile ("ldr q17, [x0]"); + __asm __volatile ("ldr q18, [x0]"); + __asm __volatile ("ldr q19, [x0]"); + __asm __volatile ("ldr q20, [x0]"); + __asm __volatile ("ldr q21, [x0]"); + __asm __volatile ("ldr q22, [x0]"); + __asm __volatile ("ldr q23, [x0]"); + __asm __volatile ("ldr q24, [x0]"); + __asm __volatile ("ldr q25, [x0]"); + __asm __volatile ("ldr q26, [x0]"); + __asm __volatile ("ldr q27, [x0]"); + __asm __volatile ("ldr q28, [x0]"); + __asm __volatile ("ldr q29, [x0]"); + __asm __volatile ("ldr q30, [x0]"); + __asm __volatile ("ldr q31, [x0]"); +} + +static void +initialize_za_state () +{ + /* zero za */ + __asm __volatile (".word 0xC00800FF"); + + char buffer[256]; + + for (int i = 0; i < 256; i++) + buffer[i] = 0xaa; + + __asm __volatile ("mov x0, %0\n\t" \ + : : "r" (buffer)); + + /* Initialize loop boundaries. */ + __asm __volatile ("mov w12, 0"); + __asm __volatile ("mov w17, 256"); + + /* loop: ldr za[w12, 0], [x0] */ + __asm __volatile ("loop: .word 0xe1000000"); + __asm __volatile ("add w12, w12, 1"); + __asm __volatile ("cmp w12, w17"); + __asm __volatile ("bne loop"); +} + +static void +initialize_sve_state () +{ + __asm __volatile ("dup z0.b, -1"); + __asm __volatile ("dup z1.b, -1"); + __asm __volatile ("dup z2.b, -1"); + __asm __volatile ("dup z3.b, -1"); + __asm __volatile ("dup z4.b, -1"); + __asm __volatile ("dup z5.b, -1"); + __asm __volatile ("dup z6.b, -1"); + __asm __volatile ("dup z7.b, -1"); + __asm __volatile ("dup z8.b, -1"); + __asm __volatile ("dup z9.b, -1"); + __asm __volatile ("dup z10.b, -1"); + __asm __volatile ("dup z11.b, -1"); + __asm __volatile ("dup z12.b, -1"); + __asm __volatile ("dup z13.b, -1"); + __asm __volatile ("dup z14.b, -1"); + __asm __volatile ("dup z15.b, -1"); + __asm __volatile ("dup z16.b, -1"); + __asm __volatile ("dup z17.b, -1"); + __asm __volatile ("dup z18.b, -1"); + __asm __volatile ("dup z19.b, -1"); + __asm __volatile ("dup z20.b, -1"); + __asm __volatile ("dup z21.b, -1"); + __asm __volatile ("dup z22.b, -1"); + __asm __volatile ("dup z23.b, -1"); + __asm __volatile ("dup z24.b, -1"); + __asm __volatile ("dup z25.b, -1"); + __asm __volatile ("dup z26.b, -1"); + __asm __volatile ("dup z27.b, -1"); + __asm __volatile ("dup z28.b, -1"); + __asm __volatile ("dup z29.b, -1"); + __asm __volatile ("dup z30.b, -1"); + __asm __volatile ("dup z31.b, -1"); + __asm __volatile ("ptrue p0.b"); + __asm __volatile ("ptrue p1.b"); + __asm __volatile ("ptrue p2.b"); + __asm __volatile ("ptrue p3.b"); + __asm __volatile ("ptrue p4.b"); + __asm __volatile ("ptrue p5.b"); + __asm __volatile ("ptrue p6.b"); + __asm __volatile ("ptrue p7.b"); + __asm __volatile ("ptrue p8.b"); + __asm __volatile ("ptrue p9.b"); + __asm __volatile ("ptrue p10.b"); + __asm __volatile ("ptrue p11.b"); + __asm __volatile ("ptrue p12.b"); + __asm __volatile ("ptrue p13.b"); + __asm __volatile ("ptrue p14.b"); + __asm __volatile ("ptrue p15.b"); + __asm __volatile ("setffr"); +} + +static int get_vl_size () +{ + int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int get_svl_size () +{ + int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int set_vl_size (int new_vl) +{ + int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_SET_VL (%d)\n", res); + return -1; + } + + res = get_vl_size (); + if (res != new_vl) + { + printf ("Unexpected VL value (%d)\n", res); + return -1; + } + + return res; +} + +static int set_svl_size (int new_svl) +{ + int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_SET_VL (%d)\n", res); + return -1; + } + + res = get_svl_size (); + if (res != new_svl) + { + printf ("Unexpected SVL value (%d)\n", res); + return -1; + } + + return res; +} + +/* Enable register states based on STATE. + + 0 - FPSIMD + 1 - SVE + 2 - SSVE + 3 - ZA + 4 - ZA and SSVE. */ + +void enable_states (int state) +{ + disable_za (); + disable_sm (); + initialize_fpsimd_state (); + + if (state == 1) + { + initialize_sve_state (); + } + else if (state == 2) + { + enable_sm (); + initialize_sve_state (); + } + else if (state == 3) + { + enable_za (); + initialize_za_state (); + } + else if (state == 4) + { + enable_za (); + enable_sm (); + initialize_sve_state (); + initialize_za_state (); + } + + return; +} + +static int +test_id_to_state (int id) +{ + return (id / 25); +} + +static int +test_id_to_vl (int id) +{ + return 16 << ((id / 5) % 5); +} + +static int +test_id_to_svl (int id) +{ + return 16 << (id % 5); +} + +static void +dummy () +{ +} + +int +main (int argc, char **argv) +{ + if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME) + { + int id_start = ID_START; + int id_end = ID_END; +#ifdef SIGILL + signal (SIGILL, handler); +#endif + + int signal_count = 0; + for (int id = id_start; id <= id_end; id++) + { + int state = test_id_to_state (id); + int vl = test_id_to_vl (id); + int svl = test_id_to_svl (id); + + if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1) + continue; + + signal_count++; + enable_states (state); + dummy (); /* stop before SIGILL */ + __asm __volatile (".word 0xDEADBEEF"); /* illegal instruction */ + while (signal_count != count); + } + } + else + { + printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n"); + return -1; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.exp.tcl b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.exp.tcl new file mode 100644 index 00000000000..c062e200edf --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-sigframe.exp.tcl @@ -0,0 +1,179 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Exercise restoring SME/TPIDR2 state from a signal frame. + +load_lib aarch64-scalable.exp + +# +# Validate the state of registers in the signal frame for various states. +# +proc test_sme_registers_sigframe { id_start id_end } { + + set compile_flags {"debug" "macros"} + lappend compile_flags "additional_flags=-march=armv8.5-a+sve" + lappend compile_flags "additional_flags=-DID_START=${id_start}" + lappend compile_flags "additional_flags=-DID_END=${id_end}" + + standard_testfile ${::srcdir}/${::subdir}/aarch64-sme-regs-sigframe.c + set executable "${::testfile}-${id_start}-${id_end}" + if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} { + return -1 + } + set binfile [standard_output_file ${executable}] + + if ![runto_main] { + untested "could not run to main" + return -1 + } + + # Check if we are talking to a remote target. If so, bail out, as right now + # remote targets can't communicate vector length (vl or svl) changes to gdb + # via the RSP. When this restriction is lifted, we can remove this guard. + if {[gdb_is_target_remote]} { + unsupported "aarch64 sve/sme tests not supported for remote targets" + return -1 + } + + set sigill_breakpoint "stop before SIGILL" + set handler_breakpoint "handler" + gdb_breakpoint [gdb_get_line_number $sigill_breakpoint] + gdb_breakpoint [gdb_get_line_number $handler_breakpoint] + + for {set id $id_start} {$id <= $id_end} {incr id} { + set state [test_id_to_state $id] + set vl [test_id_to_vl $id] + set svl [test_id_to_svl $id] + + set skip_unsupported 0 + if {![aarch64_supports_sve_vl $vl] + || ![aarch64_supports_sme_svl $svl]} { + # We have a vector length or streaming vector length that + # is not supported by this target. Skip to the next iteration + # since it is no use running tests for an unsupported vector + # length. + if {![aarch64_supports_sve_vl $vl]} { + verbose -log "SVE vector length $vl not supported." + } elseif {![aarch64_supports_sme_svl $svl]} { + verbose -log "SME streaming vector length $svl not supported." + } + verbose -log "Skipping test." + set skip_unsupported 1 + } + + with_test_prefix "state=${state} vl=${vl} svl=${svl}" { + + # If the SVE or SME vector length is not supported, just skip + # these next tests. + if {$skip_unsupported} { + untested "unsupported configuration on target" + continue + } + + # Run the program until it has adjusted the svl. + if [gdb_continue_to_breakpoint $sigill_breakpoint] { + return -1 + } + + # Check SVG to make sure it is correct + set expected_svg [expr $svl / 8] + gdb_test "print \$svg" "= ${expected_svg}" + + # Check the size of ZA. + set expected_za_size [expr $svl * $svl] + gdb_test "print sizeof \$za" " = $expected_za_size" + + # Check the value of SVCR. + gdb_test "print \$svcr" [get_svcr_value $state] "svcr before signal" + + # Handle SME ZA initialization and state. + set byte 0 + if { $state == "za" || $state == "za_ssve" } { + set byte 170 + } + + # Set the expected ZA pattern. + set za_pattern [string_to_regexp [2d_array_value_pattern $byte $svl $svl]] + + # Handle SVE/SSVE initialization and state. + set sve_vl $svl + if { $state == "ssve" || $state == "za_ssve" } { + # SVE state comes from SSVE. + set sve_vl $svl + } else { + # SVE state comes from regular SVE. + set sve_vl $vl + } + + # Initialize the SVE state. + set sve_pattern [string_to_regexp [sve_value_pattern $state $sve_vl 85 255]] + for {set row 0} {$row < 32} {incr row} { + set register_name "\$z${row}\.b\.u" + gdb_test "print sizeof $register_name" " = $sve_vl" "size of $register_name" + gdb_test "print $register_name" $sve_pattern "read back from $register_name" + } + + # Print ZA to check its value. + gdb_test "print \$za" $za_pattern "read back from za" + + # Test TPIDR2 restore from signal frame as well. + gdb_test_no_output "set \$tpidr2=0x0102030405060708" + + # Run to the illegal instruction. + if [gdb_test "continue" "Continuing\.\r\n\r\nProgram received signal SIGILL, Illegal instruction\..*in main.*"] { + return + } + + # Skip the illegal instruction. The signal handler will be called after we continue. + gdb_test_no_output "set \$pc=\$pc+4" + # Continue to the signal handler. + if [gdb_continue_to_breakpoint $handler_breakpoint] { + return -1 + } + + # Modify TPIDR2 so it is different from its value past the signal + # frame. + gdb_test_no_output "set \$tpidr2 = 0x0" + + # Select the frame that contains "main". + gdb_test "frame 2" "#2.* main \\\(.*\\\) at.*" + + for {set row 0} {$row < 32} {incr row} { + set register_name "\$z${row}\.b\.u" + gdb_test "print sizeof $register_name" " = $sve_vl" "size of $register_name in the signal frame" + gdb_test "print $register_name" $sve_pattern "$register_name contents from signal frame" + } + + # Check the size of ZA in the signal frame. + set expected_za_size [expr $svl * $svl] + gdb_test "print sizeof \$za" " = $expected_za_size" "size of za in signal frame" + + # Check the value of SVCR in the signal frame. + gdb_test "print \$svcr" [get_svcr_value $state] "svcr from signal frame" + + # Check the value of ZA in the signal frame. + gdb_test "print \$za" $za_pattern "za contents from signal frame" + + # Check the value of TPIDR2 in the signal frame. + gdb_test "print/x \$tpidr2" " = 0x102030405060708" "tpidr2 contents from signal frame" + } + } +} + +require is_aarch64_target +require allow_aarch64_sve_tests +require allow_aarch64_sme_tests + +test_sme_registers_sigframe $id_start $id_end diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-0.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-0.exp new file mode 100644 index 00000000000..835f28950df --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-0.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 16 +# SVL: 16, 32, 64, 128 +# This set covers 4 (0 ~ 3) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 0 +set id_end 3 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-1.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-1.exp new file mode 100644 index 00000000000..73ec3f67269 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-1.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 16 +# SVL: 256 +# This set covers 1 (4) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 4 +set id_end 4 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-2.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-2.exp new file mode 100644 index 00000000000..4d223ef4070 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-2.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 32 +# SVL: 16, 32, 64, 128 +# This set covers 4 (5 ~ 8) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 5 +set id_end 8 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-3.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-3.exp new file mode 100644 index 00000000000..3a26cd36975 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-3.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 32 +# SVL: 256 +# This set covers 1 (9) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 9 +set id_end 9 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-4.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-4.exp new file mode 100644 index 00000000000..c8e73b7cf73 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-4.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 64 +# SVL: 16, 32, 64, 128 +# This set covers 4 (10 ~ 13) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 10 +set id_end 13 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-5.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-5.exp new file mode 100644 index 00000000000..7b9f908b256 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-5.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 64 +# SVL: 256 +# This set covers 1 (14) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 14 +set id_end 14 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-6.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-6.exp new file mode 100644 index 00000000000..7a3d52f4333 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-6.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 128 +# SVL: 16, 32, 64, 128 +# This set covers 4 (15 ~ 18) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 15 +set id_end 18 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-7.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-7.exp new file mode 100644 index 00000000000..03cff0a0fe8 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-7.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 128 +# SVL: 256 +# This set covers 1 (19) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 19 +set id_end 19 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-8.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-8.exp new file mode 100644 index 00000000000..2379f3e79b4 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-8.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 256 +# SVL: 16, 32, 64, 128 +# This set covers 4 (20 ~ 23) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 20 +set id_end 23 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-9.exp b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-9.exp new file mode 100644 index 00000000000..623e75b1f64 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable-9.exp @@ -0,0 +1,26 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Exercise tests with the following parameters: +# VL: 256 +# SVL: 256 +# This set covers 1 (24) out of 25 tests. +# +# These tests are split this way for parallelization and for performance +# reasons. +# +set id_start 24 +set id_end 24 +source $srcdir/$subdir/aarch64-sme-regs-unavailable.exp.tcl diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.c b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.c new file mode 100644 index 00000000000..9c844c91c7c --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.c @@ -0,0 +1,152 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Exercise various cases of ZA contents not being available for AArch64's + Scalable Matrix Extension. */ + +#include +#include +#include +#include +#include + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +#ifndef PR_SVE_SET_VL +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#define PR_SVE_VL_LEN_MASK 0xffff +#endif + +#ifndef PR_SME_SET_VL +#define PR_SME_SET_VL 63 +#define PR_SME_GET_VL 64 +#define PR_SME_VL_LEN_MASK 0xffff +#endif + +static int get_vl_size () +{ + int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int get_svl_size () +{ + int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_GET_VL (%d)\n", res); + return -1; + } + return (res & PR_SVE_VL_LEN_MASK); +} + +static int set_vl_size (int new_vl) +{ + int res = prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SVE_SET_VL (%d)\n", res); + return -1; + } + + res = get_vl_size (); + if (res != new_vl) + { + printf ("Unexpected VL value (%d)\n", res); + return -1; + } + + return res; +} + +static int set_svl_size (int new_svl) +{ + int res = prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0); + if (res < 0) + { + printf ("FAILED to PR_SME_SET_VL (%d)\n", res); + return -1; + } + + res = get_svl_size (); + if (res != new_svl) + { + printf ("Unexpected SVL value (%d)\n", res); + return -1; + } + + return res; +} + +static int +test_id_to_vl (int id) +{ + return 16 << ((id / 5) % 5); +} + +static int +test_id_to_svl (int id) +{ + return 16 << (id % 5); +} + +static void +dummy () +{ +} + +int +main (int argc, char **argv) +{ + if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME) + { + int id_start = ID_START; + int id_end = ID_END; + + for (int id = id_start; id <= id_end; id++) + { + int vl = test_id_to_vl (id); + int svl = test_id_to_svl (id); + + if (set_vl_size (vl) == -1 || set_svl_size (svl) == -1) + continue; + + dummy (); /* stop 1 */ + } + + dummy (); /* stop 2 */ + } + else + { + printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n"); + return -1; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.exp.tcl b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.exp.tcl new file mode 100644 index 00000000000..1a5ebf1cdaa --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-regs-unavailable.exp.tcl @@ -0,0 +1,212 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Exercise the following: +# - Printing ZA registers when there is no ZA state. +# - Setting values of ZA registers when there is no ZA state. +# - Validating ZA state is activated when we write to ZA registers. + +load_lib aarch64-scalable.exp + +# +# Validate that the ZA registers have the expected state. +# +proc_with_prefix check_regs { vl svl } { + # Check VG to make sure it is correct + set expected_vg [expr $vl / 8] + gdb_test "print \$vg" "= ${expected_vg}" + + # Check SVG to make sure it is correct + set expected_svg [expr $svl / 8] + gdb_test "print \$svg" "= ${expected_svg}" + + # Make sure there is no SM or ZA state. + if [gdb_test "print \$svcr" "= \\\[ \\\]"] { + fail "incorrect ZA state" + return -1 + } + + # Check the size of ZA. + set expected_za_size [expr $svl * $svl] + gdb_test "print sizeof \$za" " = $expected_za_size" + + # Check the size of Z0. + gdb_test "print sizeof \$z0" " = $vl" + + # Set the expected ZA pattern. + set za_pattern [string_to_regexp [2d_array_value_pattern 0 $svl $svl]] + + # Check ZA. + gdb_test "print \$za" $za_pattern + + # Exercise reading/writing the tile slice pseudo-registers. + set last_tile 1 + set last_slice $svl + set elements $svl + set expected_size $svl + foreach_with_prefix granularity {"b" "h" "s" "d" "q"} { + set pattern [string_to_regexp [1d_array_value_pattern 0 $elements]] + for {set tile 0} {$tile < $last_tile} {incr tile} { + for {set slice 0} {$slice < $last_slice} {incr slice} { + foreach_with_prefix direction {"h" "v"} { + set register_name "\$za${tile}${direction}${granularity}${slice}" + # Test the size. + gdb_test "print sizeof ${register_name}" " = ${expected_size}" + gdb_test "print ${register_name}" $pattern + } + } + } + set last_tile [expr $last_tile * 2] + set last_slice [expr ($last_slice / 2)] + set elements [expr ($elements / 2)] + } + + # Exercise reading/writing the tile pseudo-registers. + set last_tile 1 + set elements $svl + set expected_size [expr $svl * $svl] + foreach_with_prefix granularity {"b" "h" "s" "d" "q"} { + set pattern [string_to_regexp [2d_array_value_pattern 0 $elements $elements]] + for {set tile 0} {$tile < $last_tile} {incr tile} { + set register_name "\$za${tile}${granularity}" + # Test the size. + gdb_test "print sizeof ${register_name}" " = ${expected_size}" + gdb_test "print ${register_name}" $pattern + } + set last_tile [expr $last_tile * 2] + set expected_size [expr $expected_size / 2] + set elements [expr ($elements / 2)] + } +} + +# +# Cycle through all ZA registers and pseudo-registers and validate that their +# contents are unavailable (zeroed out) for vector length SVL. +# +proc test_sme_registers_unavailable { id_start id_end } { + + set compile_flags {"debug" "macros"} + lappend compile_flags "additional_flags=-DID_START=${id_start}" + lappend compile_flags "additional_flags=-DID_END=${id_end}" + + standard_testfile ${::srcdir}/${::subdir}/aarch64-sme-regs-unavailable.c + set executable "${::testfile}-${id_start}-${id_end}" + if {[prepare_for_testing "failed to prepare" ${executable} ${::srcfile} ${compile_flags}]} { + return -1 + } + set binfile [standard_output_file ${executable}] + + if ![runto_main] { + untested "could not run to main" + return -1 + } + + # Check if we are talking to a remote target. If so, bail out, as right now + # remote targets can't communicate vector length (vl or svl) changes to gdb + # via the RSP. When this restriction is lifted, we can remove this guard. + if {[gdb_is_target_remote]} { + unsupported "aarch64 sve/sme tests not supported for remote targets" + return -1 + } + + gdb_test_no_output "set print repeats 1" + + set prctl_breakpoint "stop 1" + gdb_breakpoint [gdb_get_line_number $prctl_breakpoint] + + for {set id $id_start} {$id <= $id_end} {incr id} { + set vl [test_id_to_vl $id] + set svl [test_id_to_svl $id] + + set skip_unsupported 0 + if {![aarch64_supports_sve_vl $vl] + || ![aarch64_supports_sme_svl $svl]} { + # We have a vector length or streaming vector length that + # is not supported by this target. Skip to the next iteration + # since it is no use running tests for an unsupported vector + # length. + if {![aarch64_supports_sve_vl $vl]} { + verbose -log "SVE vector length $vl not supported." + } elseif {![aarch64_supports_sme_svl $svl]} { + verbose -log "SME streaming vector length $svl not supported." + } + verbose -log "Skipping test." + set skip_unsupported 1 + } + + with_test_prefix "prctl, vl=${vl} svl=${svl}" { + # If the SVE or SME vector length is not supported, just skip + # these next tests. + if {$skip_unsupported} { + untested "unsupported configuration on target" + continue + } + + # Run the program until it has adjusted svl. + gdb_continue_to_breakpoint $prctl_breakpoint + + check_regs $vl $svl + } + } + + set non_prctl_breakpoint "stop 2" + gdb_breakpoint [gdb_get_line_number $non_prctl_breakpoint] + gdb_continue_to_breakpoint $non_prctl_breakpoint + + for {set id $id_start} {$id <= $id_end} {incr id} { + set vl [test_id_to_vl $id] + set svl [test_id_to_svl $id] + + set skip_unsupported 0 + if {![aarch64_supports_sve_vl $vl] + || ![aarch64_supports_sme_svl $svl]} { + # We have a vector length or streaming vector length that + # is not supported by this target. Skip to the next iteration + # since it is no use running tests for an unsupported vector + # length. + if {![aarch64_supports_sve_vl $vl]} { + verbose -log "SVE vector length $vl not supported." + } elseif {![aarch64_supports_sme_svl $svl]} { + verbose -log "SME streaming vector length $svl not supported." + } + verbose -log "Skipping test." + set skip_unsupported 1 + } + + with_test_prefix "gdb, vl=${vl} svl=${svl}" { + + # If the SVE or SME vector length is not supported, just skip + # these next tests. + if {$skip_unsupported} { + untested "unsupported configuration on target" + continue + } + + # Adjust vg and svg. + set vg_value [expr $vl / 8] + set svg_value [expr $svl / 8] + gdb_test_no_output "set \$vg = ${vg_value}" + gdb_test_no_output "set \$svg = ${svg_value}" + + check_regs $vl $svl + } + } +} + +require is_aarch64_target +require allow_aarch64_sve_tests +require allow_aarch64_sme_tests + +test_sme_registers_unavailable $id_start $id_end diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-sanity.c b/gdb/testsuite/gdb.arch/aarch64-sme-sanity.c new file mode 100644 index 00000000000..694de0626d2 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-sanity.c @@ -0,0 +1,249 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Sanity test to exercise AArch64's Scalable Vector/Matrix Extension basic + functionality. It cycles through different combinations of state and + initializes different register sets. */ + +#include +#include +#include +#include +#include + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +static void +enable_za () +{ + /* smstart za */ + __asm __volatile (".word 0xD503457F"); +} + +static void +disable_za () +{ + /* smstop za */ + __asm __volatile (".word 0xD503447F"); +} + +static void +enable_sm () +{ + /* smstart sm */ + __asm __volatile (".word 0xD503437F"); +} + +static void +disable_sm () +{ + /* smstop sm */ + __asm __volatile (".word 0xD503427F"); +} + +static void +initialize_fpsimd_state () +{ + char buffer[16]; + + for (int i = 0; i < 16; i++) + buffer[i] = 0x55; + + __asm __volatile ("mov x0, %0\n\t" \ + : : "r" (buffer)); + + __asm __volatile ("ldr q0, [x0]"); + __asm __volatile ("ldr q1, [x0]"); + __asm __volatile ("ldr q2, [x0]"); + __asm __volatile ("ldr q3, [x0]"); + __asm __volatile ("ldr q4, [x0]"); + __asm __volatile ("ldr q5, [x0]"); + __asm __volatile ("ldr q6, [x0]"); + __asm __volatile ("ldr q7, [x0]"); + __asm __volatile ("ldr q8, [x0]"); + __asm __volatile ("ldr q9, [x0]"); + __asm __volatile ("ldr q10, [x0]"); + __asm __volatile ("ldr q11, [x0]"); + __asm __volatile ("ldr q12, [x0]"); + __asm __volatile ("ldr q13, [x0]"); + __asm __volatile ("ldr q14, [x0]"); + __asm __volatile ("ldr q15, [x0]"); + __asm __volatile ("ldr q16, [x0]"); + __asm __volatile ("ldr q17, [x0]"); + __asm __volatile ("ldr q18, [x0]"); + __asm __volatile ("ldr q19, [x0]"); + __asm __volatile ("ldr q20, [x0]"); + __asm __volatile ("ldr q21, [x0]"); + __asm __volatile ("ldr q22, [x0]"); + __asm __volatile ("ldr q23, [x0]"); + __asm __volatile ("ldr q24, [x0]"); + __asm __volatile ("ldr q25, [x0]"); + __asm __volatile ("ldr q26, [x0]"); + __asm __volatile ("ldr q27, [x0]"); + __asm __volatile ("ldr q28, [x0]"); + __asm __volatile ("ldr q29, [x0]"); + __asm __volatile ("ldr q30, [x0]"); + __asm __volatile ("ldr q31, [x0]"); +} + +static void +initialize_za_state () +{ + /* zero za */ + __asm __volatile (".word 0xC00800FF"); + + char buffer[256]; + + for (int i = 0; i < 256; i++) + buffer[i] = 0xaa; + + __asm __volatile ("mov x0, %0\n\t" \ + : : "r" (buffer)); + + /* Initialize loop boundaries. */ + __asm __volatile ("mov w12, 0"); + __asm __volatile ("mov w17, 256"); + + /* loop: ldr za[w12, 0], [x0] */ + __asm __volatile ("loop: .word 0xe1000000"); + __asm __volatile ("add w12, w12, 1"); + __asm __volatile ("cmp w12, w17"); + __asm __volatile ("bne loop"); +} + +static void +initialize_sve_state () +{ + __asm __volatile ("dup z0.b, -1"); + __asm __volatile ("dup z1.b, -1"); + __asm __volatile ("dup z2.b, -1"); + __asm __volatile ("dup z3.b, -1"); + __asm __volatile ("dup z4.b, -1"); + __asm __volatile ("dup z5.b, -1"); + __asm __volatile ("dup z6.b, -1"); + __asm __volatile ("dup z7.b, -1"); + __asm __volatile ("dup z8.b, -1"); + __asm __volatile ("dup z9.b, -1"); + __asm __volatile ("dup z10.b, -1"); + __asm __volatile ("dup z11.b, -1"); + __asm __volatile ("dup z12.b, -1"); + __asm __volatile ("dup z13.b, -1"); + __asm __volatile ("dup z14.b, -1"); + __asm __volatile ("dup z15.b, -1"); + __asm __volatile ("dup z16.b, -1"); + __asm __volatile ("dup z17.b, -1"); + __asm __volatile ("dup z18.b, -1"); + __asm __volatile ("dup z19.b, -1"); + __asm __volatile ("dup z20.b, -1"); + __asm __volatile ("dup z21.b, -1"); + __asm __volatile ("dup z22.b, -1"); + __asm __volatile ("dup z23.b, -1"); + __asm __volatile ("dup z24.b, -1"); + __asm __volatile ("dup z25.b, -1"); + __asm __volatile ("dup z26.b, -1"); + __asm __volatile ("dup z27.b, -1"); + __asm __volatile ("dup z28.b, -1"); + __asm __volatile ("dup z29.b, -1"); + __asm __volatile ("dup z30.b, -1"); + __asm __volatile ("dup z31.b, -1"); + __asm __volatile ("ptrue p0.b"); + __asm __volatile ("ptrue p1.b"); + __asm __volatile ("ptrue p2.b"); + __asm __volatile ("ptrue p3.b"); + __asm __volatile ("ptrue p4.b"); + __asm __volatile ("ptrue p5.b"); + __asm __volatile ("ptrue p6.b"); + __asm __volatile ("ptrue p7.b"); + __asm __volatile ("ptrue p8.b"); + __asm __volatile ("ptrue p9.b"); + __asm __volatile ("ptrue p10.b"); + __asm __volatile ("ptrue p11.b"); + __asm __volatile ("ptrue p12.b"); + __asm __volatile ("ptrue p13.b"); + __asm __volatile ("ptrue p14.b"); + __asm __volatile ("ptrue p15.b"); + __asm __volatile ("setffr"); +} + +/* Enable register states based on STATE. + + 0 - FPSIMD + 1 - SVE + 2 - SSVE + 3 - ZA + 4 - ZA and SSVE. */ + +void enable_states (int state) +{ + disable_za (); + disable_sm (); + initialize_fpsimd_state (); + + if (state == 1) + { + initialize_sve_state (); + } + else if (state == 2) + { + enable_sm (); + initialize_sve_state (); + } + else if (state == 3) + { + enable_za (); + initialize_za_state (); + } + else if (state == 4) + { + enable_za (); + enable_sm (); + initialize_sve_state (); + initialize_za_state (); + } + + return; +} + +void dummy () +{ +} + +int +main (int argc, char **argv) +{ + if (getauxval (AT_HWCAP) & HWCAP_SVE && getauxval (AT_HWCAP2) & HWCAP2_SME) + { + for (int state = 0; state < 5; state++) + { + enable_states (state); + dummy (); /* stop here */ + } + } + else + { + printf ("SKIP: no HWCAP_SVE or HWCAP2_SME on this system\n"); + return -1; + } + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sme-sanity.exp b/gdb/testsuite/gdb.arch/aarch64-sme-sanity.exp new file mode 100644 index 00000000000..3369976ef9b --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sme-sanity.exp @@ -0,0 +1,72 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# Sanity check for AArch64 Scalable Vector/Matrix Extensions functionality. + +load_lib aarch64-scalable.exp + +# +# Run a series of basic checks for SVE/SME states. +# +proc sanity_check { vl svl } { + # Run the program until the point where we start initializing the different + # register states. + set state_breakpoint "stop here" + gdb_breakpoint [gdb_get_line_number $state_breakpoint] + + for {set id 0} {$id < 5} {incr id} { + set state [state_id_to_state_string $id] + + with_test_prefix "state=${state} vl=${vl} svl=${svl}" { + gdb_continue_to_breakpoint $state_breakpoint + check_state $state $vl $svl + } + } +} + +require is_aarch64_target +require allow_aarch64_sve_tests +require allow_aarch64_sme_tests + +set compile_flags {"debug" "macros" "additional_flags=-march=armv8.5-a+sve"} +standard_testfile +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile} ${compile_flags}]} { + return -1 +} + +if {![runto_main]} { + return -1 +} + +# Check if we are talking to a remote target. If so, bail out, as right now +# remote targets can't communicate vector length (vl or svl) changes to gdb +# via the RSP. When this restriction is lifted, we can remove this guard. +if {[gdb_is_target_remote]} { + unsupported "aarch64 sve/sme tests not supported for remote targets" + return -1 +} + +# Adjust the repeat count for the test. +gdb_test_no_output "set print repeats 1" "adjust repeat count" + +# Fetch both the vector length and the streaming vector length the target +# system is using. We do not force any vector lengths and do not change +# it mid-execution. +set vl [expr [get_valueof "" "\$vg" "0" "fetch value of vl"] * 8] +set svl [expr [get_valueof "" "\$svg" "0" "fetch value of svl"] * 8] + +# Now we are at the point where we can start checking state and moving the +# testcase forward. +sanity_check $vl $svl diff --git a/gdb/testsuite/lib/aarch64-scalable.exp b/gdb/testsuite/lib/aarch64-scalable.exp new file mode 100644 index 00000000000..5512fcb9d1c --- /dev/null +++ b/gdb/testsuite/lib/aarch64-scalable.exp @@ -0,0 +1,239 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Support routines for aarch64 scalable extension tests + +# Load generic aarch64 test dependencies. +load_lib aarch64.exp + +# +# Return a regular expression that matches what gdb would print for a +# SVE Z register of length VL in state STATE. The Z register should be filled +# with BYTE_SVE and the FPSIMD registers should be filled with BYTE_FPSIMD. +# +# The pattern is of the form +# +# {BYTE_FPSIMD } +# +# or +# +# {BYTE_FPSIMD , 0 } +# +# or +# +# {BYTE_SVE } +# +proc sve_value_pattern { state vl byte_fpsimd byte_sve } { + set brace_open "{" + set brace_close "}" + + append data $brace_open + if { $state == "fpsimd" || $state == "za" } { + if { $vl > 16 } { + set sve_repeat_count [expr $vl - 16] + append data "$byte_fpsimd , 0 " + } else { + append data "$byte_fpsimd " + } + } else { + append data "$byte_sve " + } + append data $brace_close + + verbose -log "sve_value_pattern pattern string is..." + verbose -log $data + return $data +} + +# +# Return the SVCR value based on STATE. +# SVCR is only available when SME is available. +# +proc get_svcr_value { state } { + if { $state == "ssve" } { + return "= \\\[ SM \\\]" + } elseif { $state == "za" } { + return "= \\\[ ZA \\\]" + } elseif { $state == "za_ssve" } { + return "= \\\[ SM ZA \\\]" + } + + return "= \\\[ \\\]" +} + +# +# Return the state string based on STATE +# +proc state_id_to_state_string { state } { + if {$state == 0} { + return "fpsimd" + } elseif {$state == 1} { + return "sve" + } elseif {$state == 2} { + return "ssve" + } elseif {$state == 3} { + return "za" + } elseif {$state == 4} { + return "za_ssve" + } +} + +# +# Given a test ID, return the string representing the register state. +# The state is one of fpsimd, sve, ssve, za and za_ssve. +# +proc test_id_to_state { id } { + set state [expr $id / 25] + + return [state_id_to_state_string $state] +} + +# +# Given a test ID, return the associated vector length. +# +proc test_id_to_vl { id } { + return [expr 16 << (($id / 5) % 5)] +} + +# +# Given a test ID, return the associated streaming vector length. +# +proc test_id_to_svl { id } { + return [expr 16 << ($id % 5)] +} + +# +# Validate the values of the SVE registers. +# +proc check_sve_regs { byte state vl svl } { + + # If streaming mode is enabled, the vector length is the streaming + # vector length. + set z_pattern "" + set z_size 0 + if {$state == "ssve" || $state == "za_ssve"} { + set z_pattern [string_to_regexp [1d_array_value_pattern $byte $svl]] + set z_size $svl + } else { + set z_size $vl + + if {$state == "fpsimd" || $state == "za"} { + # If there is no SVE/SSVE state, the contents of the Z/P/FFR registers + # are zero. + if {$vl == 16} { + set z_pattern [string_to_regexp [1d_array_value_pattern $byte $vl]] + } else { + set z_repeats [expr $vl - 16] + set z_pattern [string_to_regexp "{$byte , 0 }"] + } + } else { + set z_pattern [string_to_regexp [1d_array_value_pattern $byte $vl]] + } + } + set p_size [expr $z_size / 8] + + # If there is no SVE/SSVE state, the contents of the Z/P/FFR registers + # are zero. + set p_byte $byte + if {$state == "fpsimd" || $state == "za"} { + set p_byte 0 + } + set p_pattern [string_to_regexp [1d_array_value_pattern $p_byte $p_size]] + + for {set number 0} {$number < 32} {incr number} { + set register_name "\$z${number}\.b\.u" + gdb_test "print sizeof $register_name" " = $z_size" + gdb_test "print $register_name" $z_pattern + } + + for {set number 0} {$number < 16} {incr number} { + set register_name "\$p${number}" + gdb_test "print sizeof $register_name" " = $p_size" + gdb_test "print $register_name" $p_pattern + } + + gdb_test "print \$ffr" $p_pattern +} + +# +# Validate the values of the SME registers. +# +proc check_sme_regs { byte state svl } { + # ZA contents are only available when the ZA state is enabled. Otherwise + # the ZA contents are unavailable (zeroed out). + set za_pattern "" + set expected_za_size [expr $svl * $svl] + + if {$state != "za" && $state != "za_ssve"} { + set byte 0 + } + + set za_pattern [string_to_regexp [2d_array_value_pattern $byte $svl $svl]] + + gdb_test "print sizeof \$za" " = $expected_za_size" + gdb_test "print \$za" $za_pattern +} + +# +# With register STATE, vector length VL and streaming vector length SVL, +# run some register state checks to make sure the values are the expected +# ones +# +proc check_state { state vl svl } { + # The FPSIMD registers are initialized with a value of 0x55 (85) + # for each byte. + # + # The SVE registers are initialized with a value of 0xff (255) for each + # byte, including the predicate registers and FFR. + # + # The SME (ZA) register is initialized with a value of 0xaa (170) for + # each byte. + + # Check VG to make sure it is correct + set expected_vg [expr $vl / 8] + # If streaming mode is enabled, then vg is actually svg. + if {$state == "ssve" || $state == "za_ssve"} { + set expected_vg [expr $svl / 8] + } + gdb_test "print \$vg" " = ${expected_vg}" + + # Check SVG to make sure it is correct + set expected_svg [expr $svl / 8] + gdb_test "print \$svg" " = ${expected_svg}" + + # Check the value of SVCR. + gdb_test "print \$svcr" [get_svcr_value $state] + + # When we have any SVE or SSVE state, the FPSIMD registers will have + # the same values as the SVE/SSVE Z registers. + set fpsimd_byte 85 + if {$state == "sve" || $state == "ssve" || $state == "za_ssve"} { + set fpsimd_byte 255 + } + + set sve_byte 255 + if {$state == "fpsimd" || $state == "za"} { + set sve_byte 85 + } + + # Check FPSIMD registers + check_fpsimd_regs $fpsimd_byte $state $vl $svl + # Check SVE registers + check_sve_regs $sve_byte $state $vl $svl + # Check SME registers + check_sme_regs 170 $state $svl +} + + diff --git a/gdb/testsuite/lib/aarch64-test-sme.c b/gdb/testsuite/lib/aarch64-test-sme.c new file mode 100644 index 00000000000..c123f37e0df --- /dev/null +++ b/gdb/testsuite/lib/aarch64-test-sme.c @@ -0,0 +1,90 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* AArch64 SME feature check. This test serves as a way for the GDB testsuite + to verify that a target supports SVE at runtime, and also reports data + about the various supported SME streaming vector lengths. */ + +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP2_SME +#define HWCAP2_SME (1 << 23) +#endif + +#ifndef PR_SME_SET_VL +#define PR_SME_SET_VL 63 +#define PR_SME_GET_VL 64 +#define PR_SME_VL_LEN_MASK 0xffff +#endif + +static int get_svl_size () +{ + int res = prctl (PR_SME_GET_VL, 0, 0, 0, 0); + + if (res < 0) + return -1; + + return (res & PR_SME_VL_LEN_MASK); +} + +static int set_svl_size (int new_svl) +{ + if (prctl (PR_SME_SET_VL, new_svl, 0, 0, 0, 0) < 0) + return -1; + + if (get_svl_size () != new_svl) + return -1; + + return 0; +} + +static void +dummy () +{ +} + +#define SVL_MIN 16 +#define SVL_MAX 256 +#define SVL_INCREMENT_POWER 1 + +int +main (int argc, char **argv) +{ + /* Number of supported SME streaming vector lengths. */ + size_t supported_svl_count = 0; + /* Vector containing the various supported SME streaming vector lengths. */ + size_t supported_svl[5]; + + if (getauxval (AT_HWCAP) & HWCAP2_SME) + { + for (int svl = SVL_MIN; svl <= SVL_MAX; svl <<= SVL_INCREMENT_POWER) + { + if (set_svl_size (svl) == 0) + { + supported_svl[supported_svl_count] = svl; + supported_svl_count++; + } + } + } + + return 0; /* stop here */ +} diff --git a/gdb/testsuite/lib/aarch64-test-sve.c b/gdb/testsuite/lib/aarch64-test-sve.c new file mode 100644 index 00000000000..4673581b467 --- /dev/null +++ b/gdb/testsuite/lib/aarch64-test-sve.c @@ -0,0 +1,90 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2023 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* AArch64 SVE feature check. This test serves as a way for the GDB testsuite + to verify that a target supports SVE at runtime, and also reports data + about the various supported SVE vector lengths. */ + +#include +#include +#include +#include +#include +#include + +#ifndef HWCAP_SVE +#define HWCAP_SVE (1 << 22) +#endif + +#ifndef PR_SVE_SET_VL +#define PR_SVE_SET_VL 50 +#define PR_SVE_GET_VL 51 +#define PR_SVE_VL_LEN_MASK 0xffff +#endif + +static int get_vl_size () +{ + int res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); + + if (res < 0) + return -1; + + return (res & PR_SVE_VL_LEN_MASK); +} + +static int set_vl_size (int new_vl) +{ + if (prctl (PR_SVE_SET_VL, new_vl, 0, 0, 0, 0) < 0) + return -1; + + if (get_vl_size () != new_vl) + return -1; + + return 0; +} + +static void +dummy () +{ +} + +#define VL_MIN 16 +#define VL_MAX 256 +#define VL_INCREMENT 16 + +int +main (int argc, char **argv) +{ + /* Number of supported SVE vector lengths. */ + size_t supported_vl_count = 0; + /* Vector containing the various supported SVE vector lengths. */ + size_t supported_vl[16]; + + if (getauxval (AT_HWCAP) & HWCAP_SVE) + { + for (int vl = VL_MIN; vl <= VL_MAX; vl += VL_INCREMENT) + { + if (set_vl_size (vl) == 0) + { + supported_vl[supported_vl_count] = vl; + supported_vl_count++; + } + } + } + + return 0; /* stop here */ +} diff --git a/gdb/testsuite/lib/aarch64.exp b/gdb/testsuite/lib/aarch64.exp new file mode 100644 index 00000000000..cd43a4c4f77 --- /dev/null +++ b/gdb/testsuite/lib/aarch64.exp @@ -0,0 +1,153 @@ +# Copyright 2023 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# Support routines for aarch64-specific tests + +# +# Return a regular expression that matches what gdb would print for a +# 1-dimension vector containing ELEMENTS elements of value BYTE. +# +# The pattern is of the form "{BYTE ". +# +proc 1d_array_value_pattern { byte elements } { + set brace_open "{" + set brace_close "}" + + append data $brace_open $byte + if {$elements > 1} { + append data " " + } + append data $brace_close + + verbose -log "1d_array_value_pattern Pattern string is..." + verbose -log $data + return $data +} + +# +# Return a regular expression that matches what gdb would print for a +# 2-dimension vector containing ROWS rows and COLUMNS columns of elements +# of value BYTE. +# +# The pattern is of the form +# "{{BYTE } }". +# +proc 2d_array_value_pattern { byte rows columns } { + set brace_open "{" + set brace_close "}" + + append data $brace_open [1d_array_value_pattern $byte $columns] + if {$rows > 1} { + append data " " + } + append data $brace_close + + verbose -log "2d_array_value_pattern Pattern string is..." + verbose -log $data + return $data +} + +# +# Initialize register NAME, a 1-dimension vector, with ELEMENTS elements +# by setting all elements to BYTE. ELEMENTS is limited at 256 for memory +# usage purposes. +# +# The initialization is of the form "{BYTE, BYTE, BYTE ...}". +# +proc initialize_1d_array { name byte elements } { + set brace_open "{" + set brace_close "}" + + append data $brace_open + + # Build the assignment in a single shot. + for {set element 0} {$element < $elements} {incr element} { + # Construct the initializer by appending elements to it. + append data $byte + + # If this isn't the last element, add a comma. + if {[expr $element + 1] < $elements} { + append data ", " + } + } + append data $brace_close + + verbose -log "initialization string is..." + verbose -log $data + gdb_test_no_output "set $name = $data" "write to $name" +} + +# +# Return an initializer string for a 2-dimension vector with ROWS rows and +# COLUMNS columns, initializing all elements to BYTE for register NAME. +# +# COLUMNS is limited to 256 elements for memory usage purposes. +# +# The initialization is of the form "{{BYTE, BYTE}, ..., {BYTE, BYTE}}}". +# +proc initialize_2d_array { name byte rows columns } { + set brace_open "{" + set brace_close "}" + + if {[expr $rows * $columns] <= 256} { + # Build the assignment in a single shot, as we have a maximum of 256 + # elements. + for {set row 0} {$row < $rows} {incr row} { + append data $brace_open + for {set column 0} {$column < $columns} {incr column} { + # Construct the initializer by appending elements to it. + append data $byte + + # If this isn't the last column, add a comma. + if {[expr $column + 1] < $columns} { + append data ", " + } + } + + append data $brace_close + + # If this isn't the last row, add a comma. + if {[expr $row + 1] < $rows} { + append data "," + } + } + + set data $brace_open$data + set data $data$brace_close + + verbose -log "initialization string is..." + verbose -log $data + gdb_test_no_output "set $name = $data" "write to $name" + } else { + # There are too many elements to initialize (more than 256), so we + # will do the initialization row by row. + for {set row 0} {$row < $rows} {incr row} { + initialize_1d_array "$name\[$row\]" $byte $columns + } + } +} + +# +# Validate the values of the FPSIMD registers. +# +proc check_fpsimd_regs { byte state vl svl} { + set fpsimd_pattern [string_to_regexp [1d_array_value_pattern $byte 16]] + + for {set number 0} {$number < 32} {incr number} { + set register_name "\$v${number}\.b\.u" + gdb_test "print sizeof $register_name" " = 16" + gdb_test "print $register_name" $fpsimd_pattern + } +} diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index 1b9179401c4..cf1d4a90e55 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4152,10 +4152,259 @@ gdb_caching_proc allow_aarch64_sve_tests {} { gdb_exit remote_file build delete $obj + # While testing for SVE support, also discover all the supported vector + # length values. + aarch64_initialize_sve_information + verbose "$me: returning $allow_sve_tests" 2 return $allow_sve_tests } +# Assuming SVE is supported by the target, run some checks to determine all +# the supported vector length values and return an array containing all of those +# values. Since this is a gdb_caching_proc, this proc will only be executed +# once. +# +# To check if a particular SVE vector length is supported, the following code +# can be used. For instance, for vl == 16: +# +# if {[aarch64_supports_sve_vl 16]} { +# verbose -log "SVE vector length 16 is supported." +# } +# +# This procedure should NEVER be called by hand, as it reinitializes the GDB +# session and will derail a test. This should be called automatically as part +# of the SVE support test routine allow_aarch64_sve_tests. Users should +# restrict themselves to calling the helper proc aarch64_supports_sve_vl. + +gdb_caching_proc aarch64_initialize_sve_information { } { + global srcdir + + set src "${srcdir}/lib/aarch64-test-sve.c" + set test_exec [standard_temp_file "aarch64-test-sve.x"] + set compile_flags "{additional_flags=-march=armv8-a+sve}" + array set supported_vl {} + + # Compile the SVE vector length test. + set result [gdb_compile $src $test_exec executable [list debug ${compile_flags} nowarnings]] + + if {$result != ""} { + verbose -log "Failed to compile SVE information gathering test." + return [array get supported_vl] + } + + clean_restart $test_exec + + if {![runto_main]} { + return [array get supported_vl] + } + + set stop_breakpoint "stop here" + gdb_breakpoint [gdb_get_line_number $stop_breakpoint $src] + gdb_continue_to_breakpoint $stop_breakpoint + + # Go through the data and extract the supported SVE vector lengths. + set vl_count [get_valueof "" "supported_vl_count" "0" \ + "fetch value of supported_vl_count"] + verbose -log "Found $vl_count supported SVE vector length values" + + for {set vl_index 0} {$vl_index < $vl_count} {incr vl_index} { + set test_vl [get_valueof "" "supported_vl\[$vl_index\]" "0" \ + "fetch value of supported_vl\[$vl_index\]"] + + # Mark this vector length as supported. + if {$test_vl != 0} { + verbose -log "Found supported SVE vector length $test_vl" + set supported_vl($test_vl) 1 + } + } + + gdb_exit + verbose -log "Cleaning up" + remote_file build delete $test_exec + + verbose -log "Done gathering information about AArch64 SVE vector lengths." + + # Return the array containing all of the supported SVE vl values. + return [array get supported_vl] +} + +# +# Return 1 if the target supports SVE vl LENGTH +# Return 0 otherwise. +# + +proc aarch64_supports_sve_vl { length } { + + # Fetch the cached array of supported SVE vl values. + array set supported_vl [aarch64_initialize_sve_information] + + # Do we have the global values cached? + if {![info exists supported_vl($length)]} { + verbose -log "Target does not support SVE vl $length" + return 0 + } + + # The target supports SVE vl LENGTH. + return 1 +} + +# Run a test on the target to see if it supports Aarch64 SME extensions. +# Return 0 if so, 1 if it does not. Note this causes a restart of GDB. + +gdb_caching_proc allow_aarch64_sme_tests {} { + global srcdir subdir gdb_prompt inferior_exited_re + + set me "allow_aarch64_sme_tests" + + if { ![is_aarch64_target]} { + return 0 + } + + set compile_flags "{additional_flags=-march=armv8-a+sme}" + + # Compile a test program containing SME instructions. + set src { + int main() { + asm volatile ("smstart za"); + return 0; + } + } + if {![gdb_simple_compile $me $src executable $compile_flags]} { + # Try again, but with a raw hex instruction so we don't rely on + # assembler support for SME. + + set compile_flags "{additional_flags=-march=armv8-a}" + + # Compile a test program containing SME instructions. + set src { + int main() { + asm volatile (".word 0xD503457F"); + return 0; + } + } + + if {![gdb_simple_compile $me $src executable $compile_flags]} { + return 0 + } + } + + # Compilation succeeded so now run it via gdb. + clean_restart $obj + gdb_run_cmd + gdb_expect { + -re ".*Illegal instruction.*${gdb_prompt} $" { + verbose -log "\n$me sme support not detected" + set allow_sme_tests 0 + } + -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { + verbose -log "\n$me: sme support detected" + set allow_sme_tests 1 + } + default { + warning "\n$me: default case taken" + set allow_sme_tests 0 + } + } + gdb_exit + remote_file build delete $obj + + # While testing for SME support, also discover all the supported vector + # length values. + aarch64_initialize_sme_information + + verbose "$me: returning $allow_sme_tests" 2 + return $allow_sme_tests +} + +# Assuming SME is supported by the target, run some checks to determine all +# the supported streaming vector length values and return an array containing +# all of those values. Since this is a gdb_caching_proc, this proc will only +# be executed once. +# +# To check if a particular SME streaming vector length is supported, the +# following code can be used. For instance, for svl == 32: +# +# if {[aarch64_supports_sme_svl 32]} { +# verbose -log "SME streaming vector length 32 is supported." +# } +# +# This procedure should NEVER be called by hand, as it reinitializes the GDB +# session and will derail a test. This should be called automatically as part +# of the SME support test routine allow_aarch64_sme_tests. Users should +# restrict themselves to calling the helper proc aarch64_supports_sme_svl. + +gdb_caching_proc aarch64_initialize_sme_information { } { + global srcdir + + set src "${srcdir}/lib/aarch64-test-sme.c" + set test_exec [standard_temp_file "aarch64-test-sme.x"] + set compile_flags "{additional_flags=-march=armv8-a+sme}" + array set supported_svl {} + + # Compile the SME vector length test. + set result [gdb_compile $src $test_exec executable [list debug ${compile_flags} nowarnings]] + + if {$result != ""} { + verbose -log "Failed to compile SME information gathering test." + return [array get supported_svl] + } + + clean_restart $test_exec + + if {![runto_main]} { + return [array get supported_svl] + } + + set stop_breakpoint "stop here" + gdb_breakpoint [gdb_get_line_number $stop_breakpoint $src] + gdb_continue_to_breakpoint $stop_breakpoint + + # Go through the data and extract the supported SME vector lengths. + set svl_count [get_valueof "" "supported_svl_count" "0" \ + "fetch value of supported_svl_count"] + verbose -log "Found $svl_count supported SME vector length values" + + for {set svl_index 0} {$svl_index < $svl_count} {incr svl_index} { + set test_svl [get_valueof "" "supported_svl\[$svl_index\]" "0" \ + "fetch value of supported_svl\[$svl_index\]"] + + # Mark this streaming vector length as supported. + if {$test_svl != 0} { + verbose -log "Found supported SME vector length $test_svl" + set supported_svl($test_svl) 1 + } + } + + gdb_exit + verbose -log "Cleaning up" + remote_file build delete $test_exec + + verbose -log "Done gathering information about AArch64 SME vector lengths." + + # Return the array containing all of the supported SME svl values. + return [array get supported_svl] +} + +# +# Return 1 if the target supports SME svl LENGTH +# Return 0 otherwise. +# + +proc aarch64_supports_sme_svl { length } { + + # Fetch the cached array of supported SME svl values. + array set supported_svl [aarch64_initialize_sme_information] + + # Do we have the global values cached? + if {![info exists supported_svl($length)]} { + verbose -log "Target does not support SME svl $length" + return 0 + } + + # The target supports SME svl LENGTH. + return 1 +} # A helper that compiles a test case to see if __int128 is supported. proc gdb_int128_helper {lang} { From patchwork Mon Sep 18 21:26:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luis Machado X-Patchwork-Id: 76320 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 BEA63385C6EF for ; Mon, 18 Sep 2023 21:29:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BEA63385C6EF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1695072558; bh=Ox2OJFnFMz0LGizRWoFN/3AffLxY8X/Cm8XRwTjU8mI=; 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=TgQCAYcf1qaWrNGC30LiWR3AE+luQaLoRSE16SYONrbFTVVBNJF0KWH2H/8ci8zVt RSDkd77qEb+ihSpgV6H5+hqrN7DqGfcZYmprfRl5fQNuoWmoBZdigbVUn7gZPupvr5 4cRGKomZgeMQbGoMDEKoMHEHOeKnH3j5oZIeJzfw= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2061.outbound.protection.outlook.com [40.107.22.61]) by sourceware.org (Postfix) with ESMTPS id EC0F63857030 for ; Mon, 18 Sep 2023 21:27:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC0F63857030 Received: from AS9PR06CA0263.eurprd06.prod.outlook.com (2603:10a6:20b:45f::17) by AM8PR08MB6356.eurprd08.prod.outlook.com (2603:10a6:20b:36b::23) 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:19 +0000 Received: from AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:45f:cafe::a3) by AS9PR06CA0263.outlook.office365.com (2603:10a6:20b:45f::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:19 +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 AM7EUR03FT039.mail.protection.outlook.com (100.127.140.224) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.16 via Frontend Transport; Mon, 18 Sep 2023 21:27:19 +0000 Received: ("Tessian outbound 5c548696a0e7:v175"); Mon, 18 Sep 2023 21:27:19 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: dd1cb71b0608c629 X-CR-MTA-TID: 64aa7808 Received: from b3ad7b057161.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id F033E5CF-95DA-40A6-AEE1-B7DF8F6387F5.1; Mon, 18 Sep 2023 21:27:12 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id b3ad7b057161.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Mon, 18 Sep 2023 21:27:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Gtd6bsZMIDZRiYED0bP6Ucfaf8Lsv3C6advCaoohAGnlMuvy7z5UggWlL4xOSi3JDCbJh8JE3cW3c3npaXImNh1GlDC1IPdXo1qiXOu764LwmxYzKS7P0DL2zkfOs0frBD8HNk6r/xrTSTHKrGs1k11XqcbZWr7CogI8WRUdqnvduFAaTWXejmRizaHtMuF5y7WrJlvk4UWJy1sujnOeR9aSSIx9XN9kugApfOrF1AI4zZmSHT0gDP1u5rTP1tkzyA84DYOVHDzAtJ5LauHkHux4DUS/eSpxc/o2m8X8t/Dt9raFRVjgDbJZyYe4mMV384k3jRzg12aH6iAoBks0uw== 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=Ox2OJFnFMz0LGizRWoFN/3AffLxY8X/Cm8XRwTjU8mI=; b=fAD64/izncmxtS7hMsdF9xzkkfXnHhsk3qtniCq5inR6Y83NL64mHHnpnON1kLhWDAHq0dZGC8qfkSVIdsuJOzGMBMsSckg47DS4M4c9CCRvzUEtEDVHnN4gI+xVE0Twt8HKqKrthcTuksjM262m2RBX69oJOo+sKUJkw9gQKWTQoR8nMre4o6AIjXCJFtxtBeRrMMwvvT4f2LCHNzs9w4E1JcY0gw+bMwHo2kGw5sZs719LINXm4Hzk1yehZzWtUt+2n7Vsds93rELdn2KZgzwrcfksxc9uxPQjJYZDvD4LtJYr/x8zzZkHqje3SvNHTJVrXiLVpoLYERR8swrHPA== 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 AM6PR02CA0023.eurprd02.prod.outlook.com (2603:10a6:20b:6e::36) by AS8PR08MB6231.eurprd08.prod.outlook.com (2603:10a6:20b:298::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Mon, 18 Sep 2023 21:27:09 +0000 Received: from AM7EUR03FT007.eop-EUR03.prod.protection.outlook.com (2603:10a6:20b:6e:cafe::53) by AM6PR02CA0023.outlook.office365.com (2603:10a6:20b:6e::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26 via Frontend Transport; Mon, 18 Sep 2023 21:27:09 +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 AM7EUR03FT007.mail.protection.outlook.com (100.127.140.242) 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:09 +0000 Received: from AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) by AZ-NEU-EX03.Arm.com (10.251.24.31) 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:09 +0000 Received: from AZ-NEU-EX04.Arm.com (10.251.24.32) by AZ-NEU-EX02.Emea.Arm.com (10.251.26.5) 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:09 +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:08 +0000 To: Subject: [PATCH v7 18/18] [gdb/docs] sme: Document SME registers and features Date: Mon, 18 Sep 2023 22:26:51 +0100 Message-ID: <20230918212651.660141-19-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: AM7EUR03FT007:EE_|AS8PR08MB6231:EE_|AM7EUR03FT039:EE_|AM8PR08MB6356:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d18cb52-0b75-445c-997a-08dbb88e0a09 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: ZAZr12LramMhQcHnObz9B+apdYhiEIQ/l5q3BPXuleU87NL204a/5E+tS0Cv0KG1xeYD/vnSZ66uTXP6YbxYecOrOLZCh6/E+vKFSBs9WKDuUbOW4rjnpPk6ApwYNr8pD8QJMwOwJ9A7A6I1w3Ll7RmvFfYTB8TwKlOGCi5v2q/qRIzStRMQwwnV8BT5vyIiOiCg/y9bvGXyU/cs5wqWwCh7aMRUXDqPB5+XG9M6gUWRhygYebJqqX3tQtRuYbGvZ721C8btMHU6VGl5bA8Ht3iiK74RqYlw9NTRg0cnssDS98dWM9jw9+0Ljn+A/lDe4Jtu6O9lX5ExZxM63eeAszoj6gG9xAeOB+XzcZ+iG/AelHoNVbvwYG15dujH8/yvnbu+GbcuCgEuhP1I7ZGD9dXOOlMpSPiCxIfRI6z2/HaYtQs+g7uGgPDupxCmFddRO7PQe7DY4JZlBLkDO5I69n2rpFd51LmA07+FSfD5NO0Z94UHhzEeX3xDNwcEW9lgR7Rgl941eF8ILesYh0pcaCiQf23eg+Ji6fe5+ws+Udl/2w0V8wsk98KJVOYdGwEGcK/Gbw36KO8fF7WI51Jn7DDAFf1bdaG48Rt2O6eh9M0/+YGZCMOen+i8UKHwk9S+dL0WzGvFlhuD3x9o8aq1GEsPNqSDd7jAukRw36rifJ23Rx9npabLAaVIO3N2WBONwwQlCBg0XDZRZF2yE0GESaQ8G5OoIqjQN62RNesTRvWS1v8LudS1s7/9xTqKTLNPlaG5fPcsuddF5Y9KKjvUuuTCrrre7U1ziW/QxXHA6w0= 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)(136003)(39860400002)(396003)(376002)(346002)(1800799009)(451199024)(186009)(82310400011)(40470700004)(46966006)(36840700001)(54906003)(40460700003)(70206006)(70586007)(36860700001)(6916009)(81166007)(316002)(8936002)(8676002)(4326008)(47076005)(82740400003)(41300700001)(356005)(7696005)(6666004)(478600001)(83380400001)(336012)(1076003)(426003)(2616005)(26005)(86362001)(30864003)(2906002)(44832011)(5660300002)(40480700001)(36756003)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB6231 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: 4463a673-b3f7-440b-630e-08dbb88e041a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zEG8mUQHuIzYHYC28TEEYFKuJcOU8Vt1/wwUyKGAQtKvrRbjld1+Sck6EMEJpf7+oDV1FDQ2WXloinW9vT4Z6M4hVBLu97s/scjEOSZtZVRQ7urV5+ZvPOD264CBmAhVGN2MIIWQODbgwSwP/xeQWA0Yft3qdBPpvYdLFEyVQKqtfQQqXYI4kYY3U+dDvAUDH2/fY9tWqPrH+wuahTWqMEXtqfBcxyWWpqMvSd6bWxbtGyg5wY27dikvUI3iuNkon1iu3yB+dSMGsNqXDmBo31GrlADiNiMSk85SaH5mKox6bsprO+LnOinLaOriDqsP8uoVxsWfXw1DGaIesbUzUh5A3rDnADcxIhDMm6Dln689HUiWWH+WG7qwukQ/WnpxGl3ap5u2HDSRCc9jAfl8WOhwSPNBdc9A/M34gNb9PM7R3E0fSQ08YUaenKhybYXPUWsbVlBO0FZrdscNCABAc4J6qRtB8zhWhkhRhu3gKPmGyaeLXk/JHeQC1z9Njh9Hx4Z7x6xdAGdGlYZsdD3BjU2dKvxs0My0Fc/U85eHeIPIto8rzb6R0Uk6PrHVkPMyUY3T5jDS7m8zBDRXYwhQ1BMdhExhOtybwidZD9ImjNIDAaTt3CMIrtJAwMpD+eK24lxxDArfQFsBsqdHsH2oamd3tfeGbu7jx91HNSwYdEMRdQHKZEl+DSLGJkmp0xe7rgadF6Ul/Vq/IR5WoCAWv7EUyz7W2Ytb63EnQG/kmpdXZlgN05pNicpFOEmErbynOazjukLAOrq98t97gn7vEg== 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)(451199024)(82310400011)(186009)(1800799009)(46966006)(40470700004)(36840700001)(6666004)(36756003)(478600001)(40460700003)(40480700001)(83380400001)(426003)(336012)(26005)(86362001)(30864003)(2906002)(5660300002)(47076005)(44832011)(36860700001)(7696005)(82740400003)(81166007)(2616005)(4326008)(54906003)(70586007)(70206006)(6916009)(316002)(41300700001)(8936002)(1076003)(8676002)(107886003); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Sep 2023 21:27:19.5544 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1d18cb52-0b75-445c-997a-08dbb88e0a09 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: AM7EUR03FT039.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR08MB6356 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" Updates since v3: - Fixed more lowercase/uppercase issues with @code{} and registers. - Added an explanation of the naming pattern for tile pseudo-registers. - Misc formatting issues. Updates since v2: - More adjustments based on reviews. - Fixed incorrect number of tile pseudo-registers. - Fixed naming of tile slice pseudo-registers. - More detail about SME and how gdb implements it. - Attempted to clarify the text a bit more. Updates since v1: - Made SME text more thorough. - Adjusted text based on upstream reviews. - Fixed documentation errors (missing itemization for SME registers). Provide documentation for the SME feature and other information that should be useful for users that need to debug a SME-capable target. Reviewed-By: Eli Zaretskii Reviewed-by: Thiago Jung Bauermann --- gdb/NEWS | 11 ++ gdb/doc/gdb.texinfo | 252 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+) diff --git a/gdb/NEWS b/gdb/NEWS index 98ff00d5efc..525ab15e7a6 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -3,6 +3,17 @@ *** Changes since GDB 13 +* GDB now supports the AArch64 Scalable Matrix Extension (SME), which includes + a new matrix register named ZA, a new thread register TPIDR2 and a new vector + length register SVG (streaming vector granule). GDB also supports tracking + ZA state across signal frames. + + Some features are still under development or are dependent on ABI specs that + are still in alpha stage. For example, manual function calls with ZA state + don't have any special handling, and tracking of SVG changes based on + DWARF information is still not implemented, but there are plans to do so in + the future. + * The AArch64 'org.gnu.gdb.aarch64.pauth' Pointer Authentication feature string has been deprecated in favor of the 'org.gnu.gdb.aarch64.pauth_v2' feature string. diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index aa3c6778887..b5a61aa8973 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -26140,6 +26140,227 @@ but the lengths of the @code{z} and @code{p} registers will not change. This is a known limitation of @value{GDBN} and does not affect the execution of the target process. +For SVE, the following definitions are used throughout @value{GDBN}'s source +code and in this document: + +@itemize + +@item +@var{vl}: The vector length, in bytes. It defines the size of each @code{Z} +register. +@anchor{vl} +@cindex vl + +@item +@var{vq}: The number of 128 bit units in @var{vl}. This is mostly used +internally by @value{GDBN} and the Linux Kernel. +@anchor{vq} +@cindex vq + +@item +@var{vg}: The number of 64 bit units in @var{vl}. This is mostly used +internally by @value{GDBN} and the Linux Kernel. +@anchor{vg} +@cindex vg + +@end itemize + +@subsubsection AArch64 SME. +@anchor{AArch64 SME} +@cindex SME +@cindex AArch64 SME +@cindex Scalable Matrix Extension + +The Scalable Matrix Extension (@url{https://community.arm.com/arm-community-blogs/b/architectures-and-processors-blog/posts/scalable-matrix-extension-armv9-a-architecture, @acronym{SME}}) +is an AArch64 architecture extension that expands on the concept of the +Scalable Vector Extension (@url{https://developer.arm.com/documentation/101726/4-0/Learn-about-the-Scalable-Vector-Extension--SVE-/What-is-the-Scalable-Vector-Extension-, @acronym{SVE}}) +by providing a 2-dimensional register @code{ZA}, which is a square +matrix of variable size, just like SVE provides a group of vector registers of +variable size. + +Similarly to SVE, where the size of each @code{Z} register is directly related +to the vector length (@var{vl} for short), the @acronym{SME} @code{ZA} matrix +register's size is directly related to the streaming vector length +(@var{svl} for short). @xref{vl}. @xref{svl}. + +The @code{ZA} register state can be either active or inactive, if it is not in +use. + +@acronym{SME} also introduces a new execution mode called streaming +@acronym{SVE} mode (streaming mode for short). When streaming mode is +enabled, the program supports execution of @acronym{SVE2} instructions and the +@acronym{SVE} registers will have vector length @var{svl}. When streaming +mode is disabled, the SVE registers have vector length @var{vl}. + +For more information about @acronym{SME} and @acronym{SVE}, please refer to +official @url{https://developer.arm.com/documentation/ddi0487/latest, +architecture documentation}. + +The following definitions are used throughout @value{GDBN}'s source code and +in this document: + +@itemize + +@item +@var{svl}: The streaming vector length, in bytes. It defines the size of each +dimension of the 2-dimensional square @code{ZA} matrix. The total size of +@code{ZA} is therefore @var{svl} by @var{svl}. + +When streaming mode is enabled, it defines the size of the @acronym{SVE} +registers as well. +@anchor{svl} +@cindex svl + +@item +@var{svq}: The number of 128 bit units in @var{svl}, also known as streaming +vector granule. This is mostly used internally by @value{GDBN} and the Linux +Kernel. +@anchor{svq} +@cindex svq + +@item +@var{svg}: The number of 64 bit units in @var{svl}. This is mostly used +internally by @value{GDBN} and the Linux Kernel. +@anchor{svg} +@cindex svg + +@end itemize + +When @value{GDBN} is debugging the AArch64 architecture, if the Scalable Matrix +Extension (@acronym{SME}) is present, then @value{GDBN} will make the @code{ZA} +register available. @value{GDBN} will also make the @code{SVG} register and +@code{SVCR} pseudo-register available. + +The @code{ZA} register is a 2-dimensional square @var{svl} by @var{svl} +matrix of bytes. To simplify the representation and access to the @code{ZA} +register in @value{GDBN}, it is defined as a vector of +@var{svl}x@var{svl} bytes. + +If the user wants to index the @code{ZA} register as a matrix, it is possible +to reference @code{ZA} as @code{ZA[@var{i}][@var{j}]}, where @var{i} is the +row number and @var{j} is the column number. + +The @code{SVG} register always contains the streaming vector granule +(@var{svg}) for the current thread. From the value of register @code{SVG} we +can easily derive the @var{svl} value. + +@anchor{aarch64 sme svcr} +The @code{SVCR} pseudo-register (streaming vector control register) is a status +register that holds two state bits: @sc{sm} in bit 0 and @sc{za} in bit 1. + +If the @sc{sm} bit is 1, it means the current thread is in streaming +mode, and the @acronym{SVE} registers will use @var{svl} for their sizes. If +the @sc{sm} bit is 0, the current thread is not in streaming mode, and the +@acronym{SVE} registers will use @var{vl} for their sizes. @xref{vl}. + +If the @sc{za} bit is 1, it means the @code{ZA} register is being used and +has meaningful contents. If the @sc{za} bit is 0, the @code{ZA} register is +unavailable and its contents are undefined. + +For convenience and simplicity, if the @sc{za} bit is 0, the @code{ZA} +register and all of its pseudo-registers will read as zero. + +If @var{svl} changes during the execution of a program, then the @code{ZA} +register size and the bits in the @code{SVCR} pseudo-register will be updated +to reflect it. + +It is possible for users to change @var{svl} during the execution of a +program by modifying the @code{SVG} register value. + +Whenever the @code{SVG} register is modified with a new value, the +following will be observed: + +@itemize + +@item The @sc{za} and @sc{sm} bits will be cleared in the @code{SVCR} +pseudo-register. + +@item The @code{ZA} register will have a new size and its state will be +cleared, forcing its contents and the contents of all of its pseudo-registers +back to zero. + +@item If the @sc{sm} bit was 1, the @acronym{SVE} registers will be reset to +having their sizes based on @var{vl} as opposed to @var{svl}. If the +@sc{sm} bit was 0 prior to modifying the @code{SVG} register, there will be no +observable effect on the @acronym{SVE} registers. + +@end itemize + +The possible values for the @code{SVG} register are 2, 4, 8, 16, 32. These +numbers correspond to streaming vector length (@var{svl}) values of 16 +bytes, 32 bytes, 64 bytes, 128 bytes and 256 bytes respectively. + +The minimum size of the @code{ZA} register is 16 x 16 (256) bytes, and the +maximum size is 256 x 256 (65536) bytes. In streaming mode, with bit @sc{sm} +set, the size of the @code{ZA} register is the size of all the SVE @code{Z} +registers combined. + +The @code{ZA} register can also be accessed using tiles and tile slices. + +Tile pseudo-registers are square, 2-dimensional sub-arrays of elements within +the @code{ZA} register. + +The tile pseudo-registers have the following naming pattern: +@code{ZA<@var{tile number}><@var{qualifier}>}. + +There is a total of 31 @code{ZA} tile pseudo-registers. They are +@code{ZA0B}, @code{ZA0H} through @code{ZA1H}, @code{ZA0S} through @code{ZA3S}, +@code{ZA0D} through @code{ZA7D} and @code{ZA0Q} through @code{ZA15Q}. + +Tile slice pseudo-registers are vectors of horizontally or vertically +contiguous elements within the @code{ZA} register. + +The tile slice pseudo-registers have the following naming pattern: +@code{ZA<@var{tile number}><@var{direction}><@var{qualifier}> +<@var{slice number}>}. + +There are up to 16 tiles (0 ~ 15), the direction can be either @code{v} +(vertical) or @code{h} (horizontal), the qualifiers can be @code{b} (byte), +@code{h} (halfword), @code{s} (word), @code{d} (doubleword) and @code{q} +(quadword) and there are up to 256 slices (0 ~ 255) depending on the value +of @var{svl}. The number of slices is the same as the value of @var{svl}. + +The number of available tile slice pseudo-registers can be large. For a +minimum @var{svl} of 16 bytes, there are 5 (number of qualifiers) x +2 (number of directions) x 16 (@var{svl}) pseudo-registers. For the +maximum @var{svl} of 256 bytes, there are 5 x 2 x 256 pseudo-registers. + +When listing all the available registers, users will see the +currently-available @code{ZA} pseudo-registers. Pseudo-registers that don't +exist for a given @var{svl} value will not be displayed. + +For more information on @acronym{SME} and its terminology, please refer to the +@url{https://developer.arm.com/documentation/ddi0616/aa/, +Arm Architecture Reference Manual Supplement}, The Scalable Matrix Extension +(@acronym{SME}), for Armv9-A. + +Some features are still under development and rely on +@url{https://github.com/ARM-software/acle/releases/latest, ACLE} and +@url{https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst, ABI} +definitions, so there are known limitations to the current @acronym{SME} +support in @value{GDBN}. + +One such example is calling functions in the program being debugged by +@value{GDBN}. Such calls are not @acronym{SME}-aware and thus don't take into +account the @code{SVCR} pseudo-register bits nor the @code{ZA} register +contents. @xref{Calling}. + +The @url{https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#the-za-lazy-saving-scheme, +lazy saving scheme} involving the @code{TPIDR2} register is not yet supported +by @value{GDBN}, though the @code{TPIDR2} register is known and supported +by @value{GDBN}. + +Lastly, an important limitation for @command{gdbserver} is its inability to +communicate @var{svl} changes to @value{GDBN}. This means @command{gdbserver}, +even though it is capable of adjusting its internal caches to reflect a change +in the value of @var{svl} mid-execution, will operate with a potentially +different @var{svl} value compared to @value{GDBN}. This can lead to +@value{GDBN} showing incorrect values for the @code{ZA} register and +incorrect values for SVE registers (when in streaming mode). + +This is the same limitation we have for the @acronym{SVE} registers, and there +are plans to address this limitation going forward. + @subsubsection AArch64 Pointer Authentication. @cindex AArch64 Pointer Authentication. @anchor{AArch64 PAC} @@ -48353,6 +48574,37 @@ This restriction may be lifted in the future. Extra registers are allowed in this feature, but they will not affect @value{GDBN}. +@subsubsection AArch64 SME registers feature + +The @samp{org.gnu.gdb.aarch64.sme} feature is optional. If present, +it should contain registers @code{ZA}, @code{SVG} and @code{SVCR}. +@xref{AArch64 SME}. + +@itemize @minus + +@item +@code{ZA} is a register represented by a vector of @var{svl}x@var{svl} +bytes. @xref{svl}. + +@item +@code{SVG} is a 64-bit register containing the value of @var{svg}. @xref{svg}. + +@item +@code{SVCR} is a 64-bit status pseudo-register with two valid bits. Bit 0 +(@sc{sm}) shows whether the streaming @acronym{SVE} mode is enabled or disabled. +Bit 1 (@sc{ZA}) shows whether the @code{ZA} register state is active (in use) or +not. +@xref{aarch64 sme svcr}. + +The rest of the unused bits of the @code{SVCR} pseudo-register is undefined +and reserved. Such bits should not be used and may be defined by future +extensions of the architecture. + +@end itemize + +Extra registers are allowed in this feature, but they will not affect +@value{GDBN}. + @node ARC Features @subsection ARC Features @cindex target descriptions, ARC Features