From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E684D3857C4E for ; Thu, 22 Sep 2022 16:53:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E684D3857C4E ARC-Seal: i=2; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=pass; b=CyqNOAmfRMSFyN6edhoX0fze4Zwi1cyWBG9ZihOmnK9zKoPCgHeG2GsCF11iqdWuRXo/F0TRIKUlPJgGx8Dajpe1Ww+ONo13YjZ+aqCnoZOYOegcBp3wqH3pv2mloIKLveUpTVfcDFsGbYpr3B51ZFVM2mdfVh4L+J7MryPZcZgK7CdTr41eB1IuQ1a94B4N8J02c4vnBp8jB8iogv3y4JCXXXW4KmoSHd6Z5DXJkG2aaRvMGHF9X04ZTNl3YNwzXIlwI/pNaOG7YPSOlkqhYIj1AzdSbp/y57yX5E3Iwl8fWBStUClPmLMeb/OPquPFYuz7w8OnYR4kzweiajxvng== ARC-Message-Signature: i=2; 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=usbmrG5F531fjbbIBdo/0ppKXLyRWmb70cNluQpeWec=; b=d/yevhNCL6IupOzykNdeQ/HuCcD2ON9UveN7WtH/2RMpwH57wuGO+rxhqNMgqhyNg1ZwNMAEizSGgJ3mVAamRDG7Xf92qS54QpcsKVC7yXz5mUlw5UMhTlyT9wnXRa2EhA4nCOgTWvWN5hUSMViB0J1nn8aAHYsr4BAAppsdfDhjIEIx1UHHMzkwqrdV28/Kn2nUrIpPy2LgbYbJA+4EKq7eT0Tgk1mpexEVdVSPYTmcOynRksJfiHAUR/zpj1SY5Cp666hxPtyiBvPjvp5IUwPc/G2fZLnOjXtTgh0aiTNS5qn4JdbaICHjtPfM3AYj6e838LSCycGjm0urshTKLw== ARC-Authentication-Results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 63.35.35.123) smtp.rcpttodomain=sourceware.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com; arc=pass (0 oda=1 ltdi=1 spf=[1, 1, smtp.mailfrom=arm.com] dmarc=[1, 1, header.from=arm.com]) Received: from FR0P281CA0133.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:97::11) by AS8PR08MB8946.eurprd08.prod.outlook.com (2603:10a6:20b:5b4::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.16; Thu, 22 Sep 2022 16:53:10 +0000 Received: from VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com (2603:10a6:d10:97:cafe::6b) by FR0P281CA0133.outlook.office365.com (2603:10a6:d10:97::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.7 via Frontend Transport; Thu, 22 Sep 2022 16:53:10 +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 VE1EUR03FT009.mail.protection.outlook.com (10.152.18.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.14 via Frontend Transport; Thu, 22 Sep 2022 16:53:09 +0000 Received: ("Tessian outbound 0a0431bdcdb4:v124"); Thu, 22 Sep 2022 16:53:09 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: ad222f0acc374564 X-CR-MTA-TID: 64aa7808 Received: from 766b7c9aacc6.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id A1332C45-C03B-40DC-AA2F-BA7E780B1553.1; Thu, 22 Sep 2022 16:53:01 +0000 Received: from EUR04-VI1-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 766b7c9aacc6.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Thu, 22 Sep 2022 16:53:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SRa0o3OcjA0XS2a3w3kdjwndPeo1aX3xHeuixmPxm7B8zWy59wXaU7HaG9eQStQZFPaYBSjhOhd85yvBrap2mXHKgcSmMDz7zfkzZUFhxFVXgvFmaZTYDGld6nf8fpY6PS1xqXkohVaOcrRwFfKqLvwq3vwSyxh+ilR8hcapolPjKbfO2kCDTX6rl8hO1bGFBr2P+mL4o0cP/kcZsFP61lL+K8gMUfByNBnK7IcLcD5rxmo9VMQlN/ORchyrNLKxPILAkNvW7rRm/FJe1PLAkkvlK7aO3lK5MVVdgmb0lmf5YqSDK0HtesP4H+whrbkuo7bqWQQ0OwNdSn884D4Tyg== 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=usbmrG5F531fjbbIBdo/0ppKXLyRWmb70cNluQpeWec=; b=WKOpGISTkKsr0seCWQq/4b340CyaHt/7za9CF2HYxJ52CYxGMyZ6au4yhACPPgs71JpcBsa5gf//iGiBBOglAPN1BU0QmicUDjGrRR4jHC/3DPwlxGYa6knqlyWotjyUVq4CrAr3GxxnHCHnR8hxoDM+jMNs9avOjD7mdmfDWjemQK/NcDssICMn1jZEqMLTRdzXxhqRhF6ysTk9tGdw/j8/Gj+cka2S7oBOEBFqY3n5fWyrfiMM0MbufLB6JCGfQfWUAKYIkqhWUyXxId15/tbcJqgrTNC0P5c2Ik0Vv//mlcQ6knE2rGxAskUkfnBeFWIVe+HEziN6m23HT9FWQQ== 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 DB6PR07CA0002.eurprd07.prod.outlook.com (2603:10a6:6:2d::12) by DB4PR08MB9333.eurprd08.prod.outlook.com (2603:10a6:10:3f6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5654.18; Thu, 22 Sep 2022 16:52:59 +0000 Received: from DBAEUR03FT050.eop-EUR03.prod.protection.outlook.com (2603:10a6:6:2d:cafe::a7) by DB6PR07CA0002.outlook.office365.com (2603:10a6:6:2d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.7 via Frontend Transport; Thu, 22 Sep 2022 16:52:59 +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 DBAEUR03FT050.mail.protection.outlook.com (100.127.142.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5654.14 via Frontend Transport; Thu, 22 Sep 2022 16:52:59 +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.9; Thu, 22 Sep 2022 16:52:58 +0000 Received: from AZ-NEU-EX03.Arm.com (10.251.24.31) 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.9; Thu, 22 Sep 2022 16:52:58 +0000 Received: from e129171.cambridge.arm.com (10.1.25.31) by mail.arm.com (10.251.24.31) with Microsoft SMTP Server id 15.1.2507.9 via Frontend Transport; Thu, 22 Sep 2022 16:52:58 +0000 From: Luis Machado To: Subject: [PATCH] [AArch64] Handle W registers as pseudo-registers instead of aliases of X registers Date: Thu, 22 Sep 2022 17:52:56 +0100 Message-ID: <20220922165256.57290-1-luis.machado@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-EOPAttributedMessage: 1 X-MS-TrafficTypeDiagnostic: DBAEUR03FT050:EE_|DB4PR08MB9333:EE_|VE1EUR03FT009:EE_|AS8PR08MB8946:EE_ X-MS-Office365-Filtering-Correlation-Id: 1555a273-35c1-41a3-088b-08da9cbaee24 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: y0JnGLFz2gmv8o0P488qwfHrXKn+mIMSPOUfmMCkrcTKZ7GN1NPTyOFNtkgX28E5eaA+v4pQnXXFYNcqNpuru6AKq2nQs9wkojpzxPNcj1aNgT5Eb6FbUbPPPdF81SROVx8g2r6oxciQGC/wksZjuRs6j6OhJD7rEKdyMYW0rjMudsZov1UXXk02u5n3EvQ4ZKAM2VQPJXH3jMXyc64t0TBfYvDIqzd1C2CgGyRf65aKaa6mDO5XH/8o31n+ywdha7y+eVbgaMT6HV+YkVypqBqaNkVEJ4wpAIBMpEfWH3clgsR2hrvs2BJcFGzZg6OC8i9biF4chNytrqlNXWXJsYwvI4c+CuPY7XI1ZkFoUaCJDAuWpHGvPi51iuNiaj16yztikCWLQmV9ljM9A/hHp/uUIO7jbRdBrB3tr6ZtIS60pIYY0U3Qzw97u+CVgenaQOkXIT5VXcSiG1Q4nX+/GTSitl43vm675Ly4klKM6h4Vv8XAPiY1NbWGhtxEryDUycn7mP7YSWYeLPb52nTLSH0L5ciYg2MQACAA/Ow8k+NgCQN8joWpir71pQR2DvLnAsAtA1DZwGCzu2ijzH72oCe4YrSUJanQynrdfVjn8KC104P1BCSdi/1friiyoL72OH7cVDvQ1AHyx7QvrhagdCEp5oPSJfLocW6Pn0T5Tel0rO3IpGdenPv1ZeQepHfBga5qlimY4i6XE9AvUh9eOfyXWmBS2e00IM6viyZXHoB9dEYdWwUxpyPCVfaVsFDvJv4rRgyZH2sDeIIZIY/nqkCy2ycG+VcojSe2ivv/Sff0ZkE1dmtGpjm4EWHu6tI/ZSyeHJQCjnnrmmatp0ZUL7vQ+ODPOWa+wR5JX3XSgT0= 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:(13230022)(4636009)(396003)(136003)(376002)(39860400002)(346002)(451199015)(46966006)(40470700004)(36840700001)(70206006)(36860700001)(356005)(81166007)(86362001)(5660300002)(82740400003)(44832011)(30864003)(8936002)(70586007)(1076003)(40480700001)(478600001)(6916009)(316002)(41300700001)(8676002)(426003)(47076005)(186003)(336012)(83380400001)(2616005)(7696005)(26005)(40460700003)(2906002)(82310400005)(36756003)(2004002)(36900700001); DIR:OUT; SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR08MB9333 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: d48cc03a-789e-4f47-7686-08da9cbae7a1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gizcEOVVhivvZSTZLAsRscYgyFmSNm0eZvxn5T/JDF3stx3R8+aSAeRANqQy4eGQwrIDb5X+ETuhxjUAq79+FaWIZ4ZfQ6K9q72NVXU39lbzj3iMpTpS2Gwy8gw2GhD9PnM7WQ6CMkgzAziZvV4f8BDytUhSMoAJKPkOO9AEzcGUAYh0jqjAMWsnen8C65Z8oTF/3752Z0ivhQv35MzamhETJzlFG6k4vcvFXNgGGiAuarvLeLMYtLeT+kymsNapZuGC4uOAeQzSrNRyDU8aSXYXFZapGF1ymyYxbJSD3Xzo85iXKpj6PSsIBokSItH3aqgtKQQ7KdLIfHha4H9/m1LuSOf6nbeHyMSUVoQfPybdieElaccgsCGCqWBFdEj1DcAEw9Vrkxbap8hkkUeo9zETKuM37Ir5PhQQtJPQPGcG33/id4UGtwrPNNI1IKVMUOOzsVuAR4V+JX45awcaSE5Ow9gdO4ftCmKTgO6F/Ziy+3JPjowin+/lJFZXFZE9HWOBJMviVrj4Nha0dz8hhgq2adbOAHLG4A65OTtTiDTnV23vHlhl2hIyAid528fAt0zHjxeScgQpXdNx77Ne48WQre26MeMA1fucOu/LQjV397n70wrakRNib5Kiu8b0H7+DtFD5lToHFIT91cE9HhrdacBiAyQa2DthBm+Csy3gFpXFjY8GU4n2M2sEVK17mMd444epPdJJtozCsNbD/sbXVDRT5qybfqeNpl3pDor/k0to9WauROTLi2ij0feu+hWb8TjLfvUYm0PwXT3pyNPNlTCOofsOnlmSnxaLV8tVRMsX9mYrIxS7ftT4J7/W 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:(13230022)(4636009)(136003)(396003)(376002)(346002)(39860400002)(451199015)(40470700004)(46966006)(36840700001)(40480700001)(82740400003)(83380400001)(86362001)(47076005)(1076003)(426003)(81166007)(41300700001)(186003)(2616005)(36860700001)(5660300002)(44832011)(2906002)(8676002)(8936002)(316002)(6916009)(30864003)(70206006)(70586007)(7696005)(40460700003)(336012)(26005)(478600001)(82310400005)(36756003)(2004002); DIR:OUT; SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Sep 2022 16:53:09.7973 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1555a273-35c1-41a3-088b-08da9cbaee24 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: VE1EUR03FT009.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR08MB8946 X-Spam-Status: No, score=-12.4 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 22 Sep 2022 16:53:18 -0000 The aarch64 port handles W registers as aliases of X registers. This is incorrect because X registers are 64-bit and W registers are 32-bit. This patch teaches GDB how to handle W registers as pseudo-registers of 32-bit, the bottom half of the X registers. Testcase included. --- gdb/aarch64-tdep.c | 120 +++++++++++++----- gdb/aarch64-tdep.h | 4 + gdb/testsuite/gdb.arch/aarch64-w-registers.c | 22 ++++ .../gdb.arch/aarch64-w-registers.exp | 100 +++++++++++++++ 4 files changed, 212 insertions(+), 34 deletions(-) create mode 100644 gdb/testsuite/gdb.arch/aarch64-w-registers.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-w-registers.exp diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index f94e810f904..2ad31df2738 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -72,40 +72,6 @@ static const struct {"fp", AARCH64_FP_REGNUM}, {"lr", AARCH64_LR_REGNUM}, {"sp", AARCH64_SP_REGNUM}, - - /* 32-bit register names. */ - {"w0", AARCH64_X0_REGNUM + 0}, - {"w1", AARCH64_X0_REGNUM + 1}, - {"w2", AARCH64_X0_REGNUM + 2}, - {"w3", AARCH64_X0_REGNUM + 3}, - {"w4", AARCH64_X0_REGNUM + 4}, - {"w5", AARCH64_X0_REGNUM + 5}, - {"w6", AARCH64_X0_REGNUM + 6}, - {"w7", AARCH64_X0_REGNUM + 7}, - {"w8", AARCH64_X0_REGNUM + 8}, - {"w9", AARCH64_X0_REGNUM + 9}, - {"w10", AARCH64_X0_REGNUM + 10}, - {"w11", AARCH64_X0_REGNUM + 11}, - {"w12", AARCH64_X0_REGNUM + 12}, - {"w13", AARCH64_X0_REGNUM + 13}, - {"w14", AARCH64_X0_REGNUM + 14}, - {"w15", AARCH64_X0_REGNUM + 15}, - {"w16", AARCH64_X0_REGNUM + 16}, - {"w17", AARCH64_X0_REGNUM + 17}, - {"w18", AARCH64_X0_REGNUM + 18}, - {"w19", AARCH64_X0_REGNUM + 19}, - {"w20", AARCH64_X0_REGNUM + 20}, - {"w21", AARCH64_X0_REGNUM + 21}, - {"w22", AARCH64_X0_REGNUM + 22}, - {"w23", AARCH64_X0_REGNUM + 23}, - {"w24", AARCH64_X0_REGNUM + 24}, - {"w25", AARCH64_X0_REGNUM + 25}, - {"w26", AARCH64_X0_REGNUM + 26}, - {"w27", AARCH64_X0_REGNUM + 27}, - {"w28", AARCH64_X0_REGNUM + 28}, - {"w29", AARCH64_X0_REGNUM + 29}, - {"w30", AARCH64_X0_REGNUM + 30}, - /* specials */ {"ip0", AARCH64_X0_REGNUM + 16}, {"ip1", AARCH64_X0_REGNUM + 17} @@ -2556,6 +2522,21 @@ aarch64_gen_return_address (struct gdbarch *gdbarch, } +/* Return TRUE if REGNUM is a W pseudo-register number. Return FALSE + otherwise. */ + +static bool +is_w_pseudo_register (struct gdbarch *gdbarch, int regnum) +{ + aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + if (tdep->w_pseudo_base <= regnum + && regnum < tdep->w_pseudo_base + tdep->w_pseudo_count) + return true; + + return false; +} + /* Return the pseudo register name corresponding to register regnum. */ static const char * @@ -2563,6 +2544,19 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum) { aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + /* W pseudo-registers. Bottom halves of the X registers. */ + static const char *const w_name[] = + { + "w0", "w1", "w2", "w3", + "w4", "w5", "w6", "w7", + "w8", "w9", "w10", "w11", + "w12", "w13", "w14", "w15", + "w16", "w17", "w18", "w19", + "w20", "w21", "w22", "w23", + "w24", "w25", "w26", "w27", + "w28", "w29", "w30", + }; + static const char *const q_name[] = { "q0", "q1", "q2", "q3", @@ -2640,6 +2634,10 @@ aarch64_pseudo_register_name (struct gdbarch *gdbarch, int regnum) if (p_regnum >= AARCH64_B0_REGNUM && p_regnum < AARCH64_B0_REGNUM + 32) return b_name[p_regnum - AARCH64_B0_REGNUM]; + /* W pseudo-registers? */ + if (is_w_pseudo_register (gdbarch, regnum)) + return w_name[regnum - tdep->w_pseudo_base]; + if (tdep->has_sve ()) { static const char *const sve_v_name[] = @@ -2698,6 +2696,10 @@ aarch64_pseudo_register_type (struct gdbarch *gdbarch, int regnum) && p_regnum < AARCH64_SVE_V0_REGNUM + AARCH64_V_REGS_NUM) return aarch64_vnv_type (gdbarch); + /* W pseudo-registers are 32-bit. */ + if (is_w_pseudo_register (gdbarch, regnum)) + return builtin_type (gdbarch)->builtin_uint32; + if (tdep->has_pauth () && regnum == tdep->ra_sign_state_regnum) return builtin_type (gdbarch)->builtin_uint64; @@ -2772,6 +2774,28 @@ aarch64_pseudo_read_value (struct gdbarch *gdbarch, readable_regcache *regcache, VALUE_LVAL (result_value) = lval_register; VALUE_REGNUM (result_value) = regnum; + if (is_w_pseudo_register (gdbarch, regnum)) + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + /* Default offset for little endian. */ + int offset = 0; + + if (byte_order == BFD_ENDIAN_BIG) + offset = 4; + + /* Find the correct X register to extract the data from. */ + int x_regnum = AARCH64_X0_REGNUM + (regnum - tdep->w_pseudo_base); + gdb_byte data[4]; + + /* Read the bottom 4 bytes of X. */ + if (regcache->raw_read_part (x_regnum, offset, 4, data) != REG_VALID) + mark_value_bytes_unavailable (result_value, 0, 4); + else + memcpy (value_contents_raw (result_value).data (), data, 4); + + return result_value; + } + regnum -= gdbarch_num_regs (gdbarch); if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32) @@ -2837,6 +2861,27 @@ aarch64_pseudo_write (struct gdbarch *gdbarch, struct regcache *regcache, int regnum, const gdb_byte *buf) { aarch64_gdbarch_tdep *tdep = gdbarch_tdep (gdbarch); + + if (is_w_pseudo_register (gdbarch, regnum)) + { + enum bfd_endian byte_order = gdbarch_byte_order (gdbarch); + /* Default offset for little endian. */ + int offset = 0; + + if (byte_order == BFD_ENDIAN_BIG) + offset = 4; + + /* Find the correct X register to extract the data from. */ + int x_regnum = AARCH64_X0_REGNUM + (regnum - tdep->w_pseudo_base); + + /* First zero-out the contents of X. */ + ULONGEST zero = 0; + regcache->raw_write (x_regnum, zero); + /* Write to the bottom 4 bytes of X. */ + regcache->raw_write_part (x_regnum, offset, 4, buf); + return; + } + regnum -= gdbarch_num_regs (gdbarch); if (regnum >= AARCH64_Q0_REGNUM && regnum < AARCH64_Q0_REGNUM + 32) @@ -3582,6 +3627,9 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) num_regs += i; } + /* W pseudo-registers */ + int first_w_regnum = num_pseudo_regs; + num_pseudo_regs += 31; if (!valid_p) return nullptr; @@ -3705,6 +3753,10 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) /* With the number of real registers updated, setup the pseudo-registers and record their numbers. */ + /* Setup W pseudo-register numbers. */ + tdep->w_pseudo_base = first_w_regnum + num_regs; + tdep->w_pseudo_count = 31; + /* Pointer authentication pseudo-registers. */ if (tdep->has_pauth ()) tdep->ra_sign_state_regnum = ra_sign_state_offset + num_regs; diff --git a/gdb/aarch64-tdep.h b/gdb/aarch64-tdep.h index d8513023c37..55ccf2e777d 100644 --- a/gdb/aarch64-tdep.h +++ b/gdb/aarch64-tdep.h @@ -118,6 +118,10 @@ struct aarch64_gdbarch_tdep : gdbarch_tdep_base { return tls_regnum != -1; } + + /* The W pseudo-registers. */ + int w_pseudo_base = 0; + int w_pseudo_count = 0; }; const target_desc *aarch64_read_description (const aarch64_features &features); diff --git a/gdb/testsuite/gdb.arch/aarch64-w-registers.c b/gdb/testsuite/gdb.arch/aarch64-w-registers.c new file mode 100644 index 00000000000..7d12a20c520 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-w-registers.c @@ -0,0 +1,22 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2022 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 . */ + +int +main () +{ + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-w-registers.exp b/gdb/testsuite/gdb.arch/aarch64-w-registers.exp new file mode 100644 index 00000000000..72711fe660f --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-w-registers.exp @@ -0,0 +1,100 @@ +# Copyright (C) 2022 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 . + +# Check if the W registers have the expected size and if setting/fetching +# values from W registers works correctly for both big and little endian. + +if {![is_aarch64_target]} { + verbose "Skipping ${gdb_test_file_name}." + return +} + +standard_testfile +if { [prepare_for_testing "failed to prepare" $testfile $srcfile {nodebug}]} { + return -1 +} + +if ![runto_main] { + untested "could not run to main" + return -1 +} + +array set w_values { + 0 0x0 + 1 0x10 + 2 0x2010 + 3 0x302010 + 4 0x40302010 + 5 0x40302010 + 6 0x40302010 + 7 0x40302010 + 8 0x40302010 +} + +array set x_values { + 0 0x0 + 1 0x10 + 2 0x2010 + 3 0x302010 + 4 0x40302010 + 5 0x5040302010 + 6 0x605040302010 + 7 0x70605040302010 + 8 0x8070605040302010 +} + +# Exercise various things for register w + +proc test_register { rn } { + gdb_test "ptype \$w${rn}" "type = uint32_t" + gdb_test "p sizeof(\$w${rn})" " = 4" + + # Set all bits of x + gdb_test_no_output "set \$x${rn}=0xffffffffffffffff" \ + "set all bits of x${rn}" + + # Test setting/fetching values + for {set i 0} {$i < 9} {incr i} { + global w_values + global x_values + + with_test_prefix "set w${rn} to $x_values($i)" { + # Set value of W and see the effects on W and X. + gdb_test_no_output "set \$w${rn}=$x_values($i)" + gdb_test "p/x \$w${rn}" "= $w_values($i)" + gdb_test "p/x \$x${rn}" "= $w_values($i)" + } + + with_test_prefix "set x${rn} to $x_values($i)" { + # Set value of X and see the effects on W and X. + gdb_test_no_output "set \$x${rn}=$x_values($i)" + gdb_test "p/x \$w${rn}" "= $w_values($i)" + gdb_test "p/x \$x${rn}" "= $x_values($i)" + + # Set all bits of x + gdb_test_no_output "set \$x${rn}=0xffffffffffffffff" \ + "set all bits of x${rn}" + } + } +} + +# Run tests +foreach_with_prefix endian {"little" "big"} { + gdb_test "set endian ${endian}" "The target is set to ${endian} endian\." + + for {set i 0} {$i < 31} {incr i} { + test_register $i + } +} -- 2.25.1