From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2102.outbound.protection.outlook.com [40.107.8.102]) by sourceware.org (Postfix) with ESMTPS id 7A06B3858D20 for ; Wed, 15 May 2024 20:19:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A06B3858D20 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=Syrmia.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Syrmia.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7A06B3858D20 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=40.107.8.102 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1715804351; cv=pass; b=HF+BriocOZGoG2fsiUWC/HLUx+rT5kb09ltpW/jRgroyjV2u77bAGGRPj3L/TuyJt7bCcWXCAet59/Wj3M3d/YhcTaSxIpWeqYZEYlMxS+V/GEUCpWlVP3DcWFkP9j8CEMJK2KQXXowmEV1QdQlyrDf5SPe+jIuAIwQViulhWWA= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1715804351; c=relaxed/simple; bh=kpkXuS0YyJMV+tZpLYn0ruhqN6qRWIbPpcQZcrGHBrg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K3OvypttlPQIJkIutRcE+DvOvo7BSM9DGFLsPjGR/4Vq/Sr8fth9t0XpSLnUUCg4PwxC0lWMONPKQl33qQzfmzmPitazzh/DygFPuM16EeeF1bUtnEFgkV5kH7aFAvFYr5uB3+O7E+S4HGMwmVkkYZsj71IemEB51RDKmkPmw6I= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QiFP71O93FAl00Pjh004NboLM7tuxJd/Dv1dO7Vf5acHGc++ivEAFLodf9VFnBgmlCcMbV+PvkCEgJa6SlVVKxKshxPrWWxrMYr4VEfniFgUVSWyaW8oandYls5nw7QHCk6njkCHtfRdwWipJVrGdIaSy4PpVOlLSJbN3IRbNciqtGWtWAD35lTS83r7tkOWiSRcGgQitLppVCOCLsWeZIpLclDViaUN4xKyjAoQ96dLVpRKYUlAwOOnaoTeB7LICSAMg+BjqiFEQwQAn/74JWDS6gtgkTl4Aka+4pQ9JgJgsDzCuKX01U376RnpQTr0rmy/UK0mT5ZLh7h/pLBT8g== 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=lKtzueK9sXhtn4GXJRl9lmAgtT27siErEV8qOKSmqlQ=; b=Gv79hJ8R06LIj/uqz7XbwYJ4gmeuQAfplHQT3Dy532ovRZFkV9qJCYxvvL9ULttw0Mdxm/tz1WmaOdWQGsnQPza990Uoc+VOnyJ5XIloirBB1OsrmlOld/dTQ/yoS6UwIS3FOzsrwXIiz28RQOknny55WMozUuJlf5FklsL8KH707lGpUvhCPqlxNRHOLBuWq5KGWuFkaKpf6FlO1F2Rq6uprEQpfr7yIHyHzbJRQRAHZKyiUk0KoTxjUMd+k/3I+kxxr1iolqOAsVioF3BIp4RXrpkkrA697X+L1zwZy9UQvnAJDddjzg5WOko9oJm0El1vmEKzp6VlT2CxDd7Qdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=syrmia.com; dmarc=pass action=none header.from=syrmia.com; dkim=pass header.d=syrmia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syrmia.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lKtzueK9sXhtn4GXJRl9lmAgtT27siErEV8qOKSmqlQ=; b=WCWTXnkRiU6vb829feADlN/gBYzaEo+r1ee6oVPealzs98nGq91ScegjXQSmC9ZKbMWBVN0GoEXpqKJXduJG9nPniTa3A3h6c9oTvHMe+R/gY8JyJaUU2iHbXLhRp9Ak3PeDu1z9Xqr7S6+21qwAuB/FRovTjlgOnwSwF3PxfpE= Received: from AS8PR03MB9698.eurprd03.prod.outlook.com (2603:10a6:20b:61e::8) by DB9PR03MB7771.eurprd03.prod.outlook.com (2603:10a6:10:2ce::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7587.27; Wed, 15 May 2024 20:19:01 +0000 Received: from AS8PR03MB9698.eurprd03.prod.outlook.com ([fe80::32ef:303c:9c7b:c167]) by AS8PR03MB9698.eurprd03.prod.outlook.com ([fe80::32ef:303c:9c7b:c167%4]) with mapi id 15.20.7587.025; Wed, 15 May 2024 20:19:01 +0000 From: Milos Kalicanin To: "gdb-patches@sourceware.org" CC: Djordje Todorovic , Dragan Mladjenovic , Andrew Burgess , Simon Marchi , "Maciej W . Rozycki" , Chao-ying Fu Subject: [PATCH^5] gdb: mips: Add MIPSR6 support Thread-Topic: [PATCH^5] gdb: mips: Add MIPSR6 support Thread-Index: AQHapwTPDRzXAUprwUy8j/wkgZbrZw== Date: Wed, 15 May 2024 20:19:01 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=Syrmia.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: AS8PR03MB9698:EE_|DB9PR03MB7771:EE_ x-ms-office365-filtering-correlation-id: 3a2a9514-a995-4ba7-b96b-08dc751c428d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0;ARA:13230031|376005|1800799015|366007|38070700009; x-microsoft-antispam-message-info: =?iso-8859-1?Q?pUtZG+2Isp8tgGLGtRAedImSHqjr6SQLAM6SjeD3N5CNRFAlkDatSEs9CN?= =?iso-8859-1?Q?r7/34Gzy1hZd3fpFNEv7vcDUjtxdj2qj9YAnfFqltmXlhtakgnOWxMmJsT?= =?iso-8859-1?Q?R+7Q3m1wQPXo++A0aeAWFF7zLl5fPjpFIAzQLl0VCCs135XmIsGzqiJB78?= =?iso-8859-1?Q?U/behrc++sV2r7RQ+CLLnKSwQFiTRQAMB2nQUsOTq5wZjG/1hxPmq5o7zx?= =?iso-8859-1?Q?27gLfFAJF/elPnCG1omsyODQfcar/K8+0x/vCvJnqJi9knQ5F1ElTkekVz?= =?iso-8859-1?Q?/ItrcXTU/xBRUlwsUJ+v5oGrzMBdJ3pax+Rf0fI2UuR6oQODtQfzM/i+MX?= =?iso-8859-1?Q?oAxBxMmf2F05NDYJkmKudmDfxrSfcYGQPpsid7pAGgeFOIZtaMWZH9n+dX?= =?iso-8859-1?Q?9lpT8vyq9afOuMqb/qn7UD1Wiouw1XzgFT1lKo/Q9rTL+raL8jvdZTPl+o?= =?iso-8859-1?Q?DPxzmgXVxUTJ3m9HoZ+ucWOyHHZHjxyojd7NICUUtSeVc0Fu6fx/rD73f6?= =?iso-8859-1?Q?u6vyzMbm4yC0maDSOnTSFCcuLA2PpHgxbSt2aaVF2f/Pf9dLedSQHFbZIi?= =?iso-8859-1?Q?7ROQdYMleGgXuKOQ3ZUACYCGAZKOdaNiNVraGv78kM7/mh4KHlyUrCkXxv?= =?iso-8859-1?Q?2OOn+GBFEyWQg+Vtd4h/7oV/k4a8tTykwEAOtusbyUz+UVbSzMk+TZucdl?= =?iso-8859-1?Q?Qxd3yO+urwVGw6RPs8QdjfJ10It7kMdf5XemYVpEf5rBAupmgyxI6Okj4s?= =?iso-8859-1?Q?Q2p0hGVN0I54TLXjtpvUsH1Lc1KHvzRtUV/iSCB1Hc+VNyAqt5/g8823vd?= =?iso-8859-1?Q?h2aPq/e9NZk7e3USBShbY3LNR3rQVvg9rQmn7GpkOf6qRMk96vemInUcsN?= =?iso-8859-1?Q?3kKPClcwdpHNMrhtl2jJYFRqGbUhBBaJB2K/0SRkNPqdgaAzHNkieA2x5b?= =?iso-8859-1?Q?lHag3/XH69tuZFKIebgeZOuhzFocQQ4VZ5xgXZoLlv0UbBjatsYzVZ4wMv?= =?iso-8859-1?Q?X041GGkhy1DOjZ2snUU5ST5Ior0N5ES3G66mEMlDA9WfcCrWG71c1etL8W?= =?iso-8859-1?Q?wC9ytJnG3gdh+YOXpxgH8zdpxNFfoqR4TMwm29m9yjW66wJ0Pf8OEvwjE3?= =?iso-8859-1?Q?uCUGSW5LK0tUVxJaZC7WjOQgdBJ2jiTm3SLUo0u+M+zvd9tqpu2yBl18+1?= =?iso-8859-1?Q?tB8PsYcXvdrAoHe2NI8toqBaF0I5WmMnzj5AxAMG0W0Q0HOPFdAZc7bXXF?= =?iso-8859-1?Q?aA7bb7RgL0vkEpdPFpiXoLZulsEoEhMNujkMwnRFpkhWYzRRJJa+QarOC/?= =?iso-8859-1?Q?Nc0m5E5radozrZut9B007mh+pA=3D=3D?= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR03MB9698.eurprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376005)(1800799015)(366007)(38070700009);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?4+6uFBUd1VQv0TIHfsljdxgAl4M60uo6N+hb8dJuh1Qa6mtbPxW81Te9dX?= =?iso-8859-1?Q?vkA4N4pYAjDB196g5bJP8caxsXPFmhCST+qmDGdKAuC15rCEL3FvWWiTCO?= =?iso-8859-1?Q?I5aA1iU4QwUdDpChXBe6Ye20+0dRsK7WCN33sB6nEwjzTN6BJoyMVZqR8f?= =?iso-8859-1?Q?qzxXeSw7a90jnPHFARVnEsRwL41nI9J2VqKC/+PpF1/BqCwtagBlMzyShQ?= =?iso-8859-1?Q?KNba99WSUuq9cQ5oU0/uEValGpL8yL8te7ebYVravNebPSyGTxjUxg08s9?= =?iso-8859-1?Q?ijDDaRLUX8sCSxop/MqL8C+Du1ZpMh+mJANLpZY+pMnER/GroOJ1MqUwtZ?= =?iso-8859-1?Q?ZBzXnbNGQYtGERkWl9XPggxm1CbHUtetfrifjZVkis5RHM80KB32oR1BXH?= =?iso-8859-1?Q?r0Zc/fM3bsg+umL/s+RHUQggQEVvYmM26DE8YmfkwaVmnFZl3APNMWdhXe?= =?iso-8859-1?Q?0k9kq7mjtcCegmSzu2hfIUSesAABKpqA4StBP2oXRBIBt4laX6ToU3Wm6x?= =?iso-8859-1?Q?JJ0oKJ5yOuim0P2YzMS+SbVWdKeblkQWZBJQffy5p1j2w0P/aJJNDUmbL/?= =?iso-8859-1?Q?giHuoR+oGCEWsrfXY68s5vEs+IQQXhTzJmOp5oz1D/Jxq/zN+xoosRatp2?= =?iso-8859-1?Q?AVs1YKSy4dNOcFOk04uVxCS0bUrOH3yjF+sfeeUmUixT7StsXfWLKgtaIS?= =?iso-8859-1?Q?ZnZI6UyuMJ71bKBP7XhMTXYrlFB1JoRjfaWIBn4NITtj+Ffdtc3i6lVDTa?= =?iso-8859-1?Q?fAXjHM08fRDPjs05a7KIKkPD81dU6oSckbLxf44E14LIUAhDdaW8EJ+mah?= =?iso-8859-1?Q?IBBBNYJ0BwJazhG7vBPFyJlkmC6gInKC5TnQvYjxXZD8Q0zQMsC6VujkBU?= =?iso-8859-1?Q?olrDPogRZpIDglvRJvdLhF/At/ADB7YX3lU1la16tXA0KOgRfWoQDz6eTL?= =?iso-8859-1?Q?pW0QxwdiW4FQtEDSnZGsqUlUnBFoPCrsb9yUyzBaSzdRsBPiRdB5ozl5bU?= =?iso-8859-1?Q?qckfS3fr5sssagDtOTPQTfXMFWShbqE4XGZKqihsFZrUsOZ+3/SbyF8Xqq?= =?iso-8859-1?Q?28iL9525XAfpHCjgRJm6URnVqVFzMxopmiqWbUbPdST/DqLykT8HPdmLDS?= =?iso-8859-1?Q?vKH7jaLwtcl3GFrRUH/gIOV8i4FVjgYu88G8MhiCfk4DCur6GUYD1OCNkP?= =?iso-8859-1?Q?Y1v7fhekAerTx3PWhxWJbbASIM2IZsCNWyD5j4yrr7aN0BQpmBCE1uV2wL?= =?iso-8859-1?Q?WLhZr2IU/Q3ClzBC4761KH7voO5g1Rv8ck64a5c0RIMXHiIuFrpkNlVocz?= =?iso-8859-1?Q?+hlblxWwfkGMxn5f4lY+orRFSYxjVLDBVN5QTRjJn36zYGAl8KRcsqZGpn?= =?iso-8859-1?Q?0YJOBR9FT34zHwgbWVoiTcxiLFnmTCesjFLWkVhQdER5zkI0Fyvn/TdF5h?= =?iso-8859-1?Q?h4PIYs0vBkleHzoE1M4Y20nl4Xmtkkh5ajWmU8J6zePZev0TpC8W1Nb3Tk?= =?iso-8859-1?Q?i/6j9PlFF7gBtCjSVlQsWkCxHHTReqpt84B+gAswVILT4ajzPu3k5ej2Wd?= =?iso-8859-1?Q?URFBi6V9ZidXDnYeu0gH/qH18JiELlIxhWWurBJqkEGXo4jgThPBwlqNBS?= =?iso-8859-1?Q?ajOR9A/5mrLEmoNp6ymGfBlWA/SY69stpY?= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: syrmia.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: AS8PR03MB9698.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3a2a9514-a995-4ba7-b96b-08dc751c428d X-MS-Exchange-CrossTenant-originalarrivaltime: 15 May 2024 20:19:01.5349 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 19214a73-c1ab-4e19-8f59-14bdcb09a66e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: kt1OpMyXeSzlEArFG/fVgBQ0ZHawgzpZqfKgl1g1my0gBJQRM08okVmdUrkKNa0MElk2fLjpMyDl0pP9Y+bdP0vyf/IXOSvNWD6V3UEsGHw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR03MB7771 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Introduce new instruction encodings from Release 6 of the MIPS=0A= architecture [1]. Support breakpoints and single stepping with=0A= compact branches, forbidden slots, new branch instruction and=0A= new atomic load-store instruction encodings.=0A= =0A= Changes from v4: Apply code formatting as Andrew Burgess suggested.=0A= =0A= [1] "MIPS64 Architecture for Programmers Volume II-A: The MIPS64=0A= Instruction Set Reference Manual", Document Number: MD00087,=0A= Revision 6.06, December 15, 2016, Section 3 "The MIPS64=0A= Instruction Set", pp. 42-530=0A= https://s3-eu-west-1.amazonaws.com/downloads-mips/documents/MD00087-2B-MIPS= 64BIS-AFP-6.06.pdf=0A= =0A= 2024-05-15=0A= Andrew Bennett =0A= Matthew Fortune =0A= Faraz Shahbazker =0A= =0A= gdb/ChangeLog:=0A= * mips-tdep.c (is_mipsr6_isa): New.=0A= (b0s21_imm): New define.=0A= (mips32_relative_offset21, mips32_relative_offset26): New.=0A= (is_add32bit_overflow, is_add64bit_overflow): New.=0A= (mips32_next_pc): Handle r6 compact and fpu coprocessor branches.=0A= Move handling of BLEZ, BGTZ opcode into ...=0A= (mips32_blez_pc): New.=0A= (mips32_instruction_is_compact_branch): New.=0A= (mips32_insn_at_pc_has_forbidden_slot): New.=0A= (mips32_scan_prologue): Ignore pre-r6 addi encoding on r6.=0A= Stop at compact branch also.=0A= (LLSC_R6_OPCODE,LL_R6_FUNCT,LLE_FUNCT,=0A= LLD_R6_FUNCT,SC_R6_FUNCT,SCE_FUNCT,=0A= SCD_R6_FUNCT: New defines.=0A= (is_ll_insn, is_sc_insn): New.=0A= (mips_deal_with_atomic_sequence): Use is_ll_insn/is_sc_insn.=0A= Handle compact branches.=0A= (mips_about_to_return): Handle jrc and macro jr.=0A= (mips32_stack_frame_destroyed_p): Likewise.=0A= (mips32_instruction_has_delay_slot): Don't handle JALX on r6.=0A= Handle compact branches and coprocessor branches.=0A= (mips_adjust_breakpoint_address): Skip forbidden slot for=0A= compact branches.=0A= ---=0A= gdb/mips-tdep.c | 532 +++++++++++++--=0A= gdb/testsuite/gdb.arch/mips-64-r6.c | 918 ++++++++++++++++++++++++++=0A= gdb/testsuite/gdb.arch/mips-64-r6.exp | 76 +++=0A= 3 files changed, 1483 insertions(+), 43 deletions(-)=0A= create mode 100644 gdb/testsuite/gdb.arch/mips-64-r6.c=0A= create mode 100644 gdb/testsuite/gdb.arch/mips-64-r6.exp=0A= =0A= diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c=0A= index ae58d7c8720..bdaeb6a8999 100644=0A= --- a/gdb/mips-tdep.c=0A= +++ b/gdb/mips-tdep.c=0A= @@ -76,6 +76,10 @@ static int mips16_insn_at_pc_has_delay_slot (struct gdba= rch *gdbarch,=0A= static void mips_print_float_info (struct gdbarch *, struct ui_file *,=0A= const frame_info_ptr &, const char *);=0A= =0A= +static void=0A= +mips_read_fp_register_single (const frame_info_ptr &frame, int regno,=0A= + gdb_byte *rare_buffer);=0A= +=0A= /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */=0A= /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */= =0A= #define ST0_FR (1 << 26)=0A= @@ -325,6 +329,16 @@ mips_abi_regsize (struct gdbarch *gdbarch)=0A= }=0A= }=0A= =0A= +/* Return true if the gdbarch is based on MIPS Release 6. */=0A= +static bool=0A= +is_mipsr6_isa (struct gdbarch *gdbarch)=0A= +{=0A= + const struct bfd_arch_info *info =3D gdbarch_bfd_arch_info (gdbarch);=0A= +=0A= + return (info->mach =3D=3D bfd_mach_mipsisa32r6=0A= + || info->mach =3D=3D bfd_mach_mipsisa64r6);=0A= +}=0A= +=0A= /* MIPS16/microMIPS function addresses are odd (bit 0 is set). Here=0A= are some functions to handle addresses associated with compressed=0A= code including but not limited to testing, setting, or clearing=0A= @@ -1500,6 +1514,7 @@ mips_fetch_instruction (struct gdbarch *gdbarch,=0A= return extract_unsigned_integer (buf, instlen, byte_order);=0A= }=0A= =0A= +=0A= /* These are the fields of 32 bit mips instructions. */=0A= #define mips32_op(x) (x >> 26)=0A= #define itype_op(x) (x >> 26)=0A= @@ -1542,6 +1557,7 @@ mips_fetch_instruction (struct gdbarch *gdbarch,=0A= #define b0s11_op(x) ((x) & 0x7ff)=0A= #define b0s12_imm(x) ((x) & 0xfff)=0A= #define b0s16_imm(x) ((x) & 0xffff)=0A= +#define b0s21_imm(x) ((x) & 0x1fffff)=0A= #define b0s26_imm(x) ((x) & 0x3ffffff)=0A= #define b6s10_ext(x) (((x) >> 6) & 0x3ff)=0A= #define b11s5_reg(x) (((x) >> 11) & 0x1f)=0A= @@ -1578,6 +1594,18 @@ mips32_relative_offset (ULONGEST inst)=0A= return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2;=0A= }=0A= =0A= +static LONGEST=0A= +mips32_relative_offset21 (ULONGEST insn)=0A= +{=0A= + return ((b0s21_imm (insn) ^ 0x100000) - 0x100000) << 2;=0A= +}=0A= +=0A= +static LONGEST=0A= +mips32_relative_offset26 (ULONGEST insn)=0A= +{=0A= + return ((b0s26_imm (insn) ^ 0x2000000) - 0x2000000) << 2;=0A= +}=0A= +=0A= /* Determine the address of the next instruction executed after the INST= =0A= floating condition branch instruction at PC. COUNT specifies the=0A= number of the floating condition bits tested by the branch. */=0A= @@ -1636,6 +1664,71 @@ is_octeon_bbit_op (int op, struct gdbarch *gdbarch)= =0A= return 0;=0A= }=0A= =0A= +static int=0A= +is_add32bit_overflow (int32_t a, int32_t b)=0A= +{=0A= + int32_t r =3D (uint32_t) a + (uint32_t) b;=0A= + return (a < 0 && b < 0 && r >=3D 0) || (a >=3D 0 && b >=3D 0 && r < 0);= =0A= +}=0A= +=0A= +static int=0A= +is_add64bit_overflow (int64_t a, int64_t b)=0A= +{=0A= + if (a !=3D (int32_t)a)=0A= + return 1;=0A= + if (b !=3D (int32_t)b)=0A= + return 1;=0A= + return is_add32bit_overflow ((int32_t)a, (int32_t)b);=0A= +}=0A= +=0A= +/* Calculate address of next instruction after BLEZ. */=0A= +=0A= +static CORE_ADDR=0A= +mips32_blez_pc (struct gdbarch *gdbarch, struct regcache *regcache,=0A= + ULONGEST inst, CORE_ADDR pc, int invert)=0A= +{=0A= + int rs =3D itype_rs (inst);=0A= + int rt =3D itype_rt (inst);=0A= + LONGEST val_rs =3D regcache_raw_get_signed (regcache, rs);=0A= + LONGEST val_rt =3D regcache_raw_get_signed (regcache, rt);=0A= + ULONGEST uval_rs =3D regcache_raw_get_unsigned (regcache, rs);=0A= + ULONGEST uval_rt =3D regcache_raw_get_unsigned (regcache, rt);=0A= + int taken =3D 0;=0A= + int delay_slot_size =3D 4;=0A= +=0A= + /* BLEZ, BLEZL, BGTZ, BGTZL */=0A= + if (rt =3D=3D 0)=0A= + taken =3D (val_rs <=3D 0);=0A= + else if (is_mipsr6_isa (gdbarch))=0A= + {=0A= + /* BLEZALC, BGTZALC */=0A= + if (rs =3D=3D 0 && rt !=3D 0)=0A= + taken =3D (val_rt <=3D 0);=0A= + /* BGEZALC, BLTZALC */=0A= + else if (rs =3D=3D rt && rt !=3D 0)=0A= + taken =3D (val_rt >=3D 0);=0A= + /* BGEUC, BLTUC */=0A= + else if (rs !=3D rt && rs !=3D 0 && rt !=3D 0)=0A= + taken =3D (uval_rs >=3D uval_rt);=0A= +=0A= + /* Step through the forbidden slot to avoid repeated exceptions we d= o=0A= + not currently have access to the BD bit when hitting a breakpoint=0A= + and therefore cannot tell if the breakpoint hit on the branch or the=0A= + forbidden slot. */=0A= + /* delay_slot_size =3D 0; */=0A= + }=0A= +=0A= + if (invert)=0A= + taken =3D !taken;=0A= +=0A= + /* Calculate branch target. */=0A= + if (taken)=0A= + pc +=3D mips32_relative_offset (inst);=0A= + else=0A= + pc +=3D delay_slot_size;=0A= +=0A= + return pc;=0A= +}=0A= =0A= /* Determine where to set a single step breakpoint while considering=0A= branch prediction. */=0A= @@ -1646,12 +1739,17 @@ mips32_next_pc (struct regcache *regcache, CORE_ADD= R pc)=0A= struct gdbarch *gdbarch =3D regcache->arch ();=0A= unsigned long inst;=0A= int op;=0A= + int mips64bitreg =3D 0;=0A= +=0A= + if (mips_isa_regsize (gdbarch) =3D=3D 8)=0A= + mips64bitreg =3D 1;=0A= +=0A= inst =3D mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL);=0A= op =3D itype_op (inst);=0A= if ((inst & 0xe0000000) !=3D 0) /* Not a special, jump or branch=0A= instruction. */=0A= {=0A= - if (op >> 2 =3D=3D 5)=0A= + if (op >> 2 =3D=3D 5 && ((op & 0x02) =3D=3D 0 || itype_rt (inst) =3D= =3D 0))=0A= /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */=0A= {=0A= switch (op & 0x03)=0A= @@ -1661,7 +1759,7 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR = pc)=0A= case 1: /* BNEL */=0A= goto neq_branch;=0A= case 2: /* BLEZL */=0A= - goto less_branch;=0A= + goto lez_branch;=0A= case 3: /* BGTZL */=0A= goto greater_branch;=0A= default:=0A= @@ -1671,15 +1769,19 @@ mips32_next_pc (struct regcache *regcache, CORE_ADD= R pc)=0A= else if (op =3D=3D 17 && itype_rs (inst) =3D=3D 8)=0A= /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */=0A= pc =3D mips32_bc1_pc (gdbarch, regcache, inst, pc + 4, 1);=0A= - else if (op =3D=3D 17 && itype_rs (inst) =3D=3D 9=0A= + else if (!is_mipsr6_isa (gdbarch)=0A= + && op =3D=3D 17=0A= + && itype_rs (inst) =3D=3D 9=0A= && (itype_rt (inst) & 2) =3D=3D 0)=0A= /* BC1ANY2F, BC1ANY2T: 010001 01001 xxx0x */=0A= pc =3D mips32_bc1_pc (gdbarch, regcache, inst, pc + 4, 2);=0A= - else if (op =3D=3D 17 && itype_rs (inst) =3D=3D 10=0A= + else if (!is_mipsr6_isa (gdbarch)=0A= + && op =3D=3D 17=0A= + && itype_rs (inst) =3D=3D 10=0A= && (itype_rt (inst) & 2) =3D=3D 0)=0A= /* BC1ANY4F, BC1ANY4T: 010001 01010 xxx0x */=0A= pc =3D mips32_bc1_pc (gdbarch, regcache, inst, pc + 4, 4);=0A= - else if (op =3D=3D 29)=0A= + else if (!is_mipsr6_isa (gdbarch) && op =3D=3D 29)=0A= /* JALX: 011101 */=0A= /* The new PC will be alternate mode. */=0A= {=0A= @@ -1707,7 +1809,128 @@ mips32_next_pc (struct regcache *regcache, CORE_ADD= R pc)=0A= else=0A= pc +=3D 8; /* After the delay slot. */=0A= }=0A= + else if (is_mipsr6_isa (gdbarch))=0A= + {=0A= + /* BOVC, BEQZALC, BEQC and BNVC, BNEZALC, BNEC */=0A= + if (op =3D=3D 8 || op =3D=3D 24)=0A= + {=0A= + int rs =3D rtype_rs (inst);=0A= + int rt =3D rtype_rt (inst);=0A= + LONGEST val_rs =3D regcache_raw_get_signed (regcache, rs);=0A= + LONGEST val_rt =3D regcache_raw_get_signed (regcache, rt);=0A= + int taken =3D 0;=0A= + /* BOVC (BNVC) */=0A= + if (rs >=3D rt)=0A= + {=0A= + if (mips64bitreg =3D=3D 1)=0A= + taken =3D is_add64bit_overflow (val_rs, val_rt);=0A= + else=0A= + taken =3D is_add32bit_overflow (val_rs, val_rt);=0A= + }=0A= + /* BEQZALC (BNEZALC) */=0A= + else if (rs < rt && rs =3D=3D 0)=0A= + taken =3D (val_rt =3D=3D 0);=0A= + /* BEQC (BNEC) */=0A= + else=0A= + taken =3D (val_rs =3D=3D val_rt);=0A= +=0A= + /* BNVC, BNEZALC, BNEC */=0A= + if (op =3D=3D 24)=0A= + taken =3D !taken;=0A= =0A= + if (taken)=0A= + pc +=3D mips32_relative_offset (inst) + 4;=0A= + else=0A= + /* Step through the forbidden slot to avoid repeated exceptions=0A= + we do not currently have access to the BD bit when hitting a=0A= + breakpoint and therefore cannot tell if the breakpoint=0A= + hit on the branch or the forbidden slot. */=0A= + pc +=3D 8;=0A= + }=0A= + /* BC1EQZ, BC1NEZ */=0A= + else if (op =3D=3D 17 && (itype_rs (inst) =3D=3D 9 || itype_rs (inst) = =3D=3D 13))=0A= + {=0A= + gdb_byte status;=0A= + gdb_byte true_val =3D 0;=0A= + unsigned int fp =3D (gdbarch_num_regs (gdbarch)=0A= + + mips_regnum (gdbarch)->fp0=0A= + + itype_rt (inst));=0A= + struct frame_info_ptr frame =3D get_current_frame ();=0A= + gdb_byte *raw_buffer =3D (gdb_byte *) alloca (sizeof (gdb_byte) * 4= );=0A= + mips_read_fp_register_single (frame, fp, raw_buffer);=0A= +=0A= + if (gdbarch_byte_order (gdbarch) =3D=3D BFD_ENDIAN_BIG)=0A= + status =3D *(raw_buffer + 3);=0A= + else=0A= + status =3D *(raw_buffer);=0A= +=0A= + if (itype_rs (inst) =3D=3D 13)=0A= + true_val =3D 1;=0A= +=0A= + if ((status & 0x1) =3D=3D true_val)=0A= + pc +=3D mips32_relative_offset (inst) + 4;=0A= + else=0A= + pc +=3D 8;=0A= + }=0A= + else if (op =3D=3D 22 || op =3D=3D 23)=0A= + /* BLEZC, BGEZC, BGEC, BGTZC, BLTZC, BLTC */=0A= + {=0A= + int rs =3D rtype_rs (inst);=0A= + int rt =3D rtype_rt (inst);=0A= + LONGEST val_rs =3D regcache_raw_get_signed (regcache, rs);=0A= + LONGEST val_rt =3D regcache_raw_get_signed (regcache, rt);=0A= + int taken =3D 0;=0A= + /* The R5 rt =3D=3D 0 case is handled above so we treat it as=0A= + an unknown instruction here for future ISA usage. */=0A= + if (rs =3D=3D 0 && rt !=3D 0)=0A= + taken =3D (val_rt <=3D 0);=0A= + else if (rs =3D=3D rt && rt !=3D 0)=0A= + taken =3D (val_rt >=3D 0);=0A= + else if (rs !=3D rt && rs !=3D 0 && rt !=3D 0)=0A= + taken =3D (val_rs >=3D val_rt);=0A= +=0A= + if (op =3D=3D 23)=0A= + taken =3D !taken;=0A= +=0A= + if (taken)=0A= + pc +=3D mips32_relative_offset (inst) + 4;=0A= + else=0A= + /* Step through the forbidden slot to avoid repeated exceptions=0A= + we do not currently have access to the BD bit when hitting a=0A= + breakpoint and therefore cannot tell if the breakpoint=0A= + hit on the branch or the forbidden slot. */=0A= + pc +=3D 8;=0A= + }=0A= + else if (op =3D=3D 50 || op =3D=3D 58)=0A= + /* BC, BALC */=0A= + pc +=3D mips32_relative_offset26 (inst) + 4;=0A= + else if ((op =3D=3D 54 || op =3D=3D 62)=0A= + && rtype_rs (inst) =3D=3D 0)=0A= + /* JIC, JIALC */=0A= + {=0A= + pc =3D regcache_raw_get_signed (regcache, itype_rt (inst));=0A= + pc +=3D (itype_immediate (inst) ^ 0x8000) - 0x8000;=0A= + }=0A= + else if (op =3D=3D 54 || op =3D=3D 62)=0A= + /* BEQZC, BNEZC */=0A= + {=0A= + int rs =3D itype_rs (inst);=0A= + LONGEST rs_val =3D regcache_raw_get_signed (regcache, rs);=0A= + int taken =3D (rs_val =3D=3D 0);=0A= + if (op =3D=3D 62)=0A= + taken =3D !taken;=0A= + if (taken)=0A= + pc +=3D mips32_relative_offset21 (inst) + 4;=0A= + else=0A= + /* Step through the forbidden slot to avoid repeated exceptions=0A= + we do not currently have access to the BD bit when hitting a=0A= + breakpoint and therefore cannot tell if the breakpoint=0A= + hit on the branch or the forbidden slot. */=0A= + pc +=3D 8;=0A= + }=0A= + else=0A= + pc +=3D 4; /* Not a branch, next instruction is easy. */=0A= + }=0A= else=0A= pc +=3D 4; /* Not a branch, next instruction is easy. */=0A= }=0A= @@ -1751,7 +1974,6 @@ mips32_next_pc (struct regcache *regcache, CORE_ADDR = pc)=0A= case 2: /* BLTZL */=0A= case 16: /* BLTZAL */=0A= case 18: /* BLTZALL */=0A= - less_branch:=0A= if (regcache_raw_get_signed (regcache, itype_rs (inst)) < 0)=0A= pc +=3D mips32_relative_offset (inst) + 4;=0A= else=0A= @@ -1767,22 +1989,38 @@ mips32_next_pc (struct regcache *regcache, CORE_ADD= R pc)=0A= pc +=3D 8; /* after the delay slot */=0A= break;=0A= case 0x1c: /* BPOSGE32 */=0A= + case 0x1d: /* BPOSGE32C */=0A= case 0x1e: /* BPOSGE64 */=0A= pc +=3D 4;=0A= if (itype_rs (inst) =3D=3D 0)=0A= {=0A= unsigned int pos =3D (op & 2) ? 64 : 32;=0A= int dspctl =3D mips_regnum (gdbarch)->dspctl;=0A= + int delay_slot_size =3D 4;=0A= =0A= if (dspctl =3D=3D -1)=0A= /* No way to handle; it'll most likely trap anyway. */=0A= break;=0A= =0A= + /* BPOSGE32C */=0A= + if (op =3D=3D 0x1d)=0A= + {=0A= + if (!is_mipsr6_isa (gdbarch))=0A= + break;=0A= +=0A= + /* Step through the forbidden slot to avoid repeated=0A= + exceptions we do not currently have access to the BD=0A= + bit when hitting a breakpoint and therefore cannot=0A= + tell if the breakpoint hit on the branch or the=0A= + forbidden slot. */=0A= + /* delay_slot_size =3D 0; */=0A= + }=0A= +=0A= if ((regcache_raw_get_unsigned (regcache,=0A= dspctl) & 0x7f) >=3D pos)=0A= pc +=3D mips32_relative_offset (inst);=0A= else=0A= - pc +=3D 4;=0A= + pc +=3D delay_slot_size;=0A= }=0A= break;=0A= /* All of the other instructions in the REGIMM category */=0A= @@ -1816,19 +2054,14 @@ mips32_next_pc (struct regcache *regcache, CORE_ADD= R pc)=0A= else=0A= pc +=3D 8;=0A= break;=0A= - case 6: /* BLEZ, BLEZL */=0A= - if (regcache_raw_get_signed (regcache, itype_rs (inst)) <=3D 0)=0A= - pc +=3D mips32_relative_offset (inst) + 4;=0A= - else=0A= - pc +=3D 8;=0A= + case 6: /* BLEZ, BLEZL, BLEZALC, BGEZALC, BGEUC */=0A= + lez_branch:=0A= + pc =3D mips32_blez_pc (gdbarch, regcache, inst, pc + 4, 0);=0A= break;=0A= case 7:=0A= default:=0A= - greater_branch: /* BGTZ, BGTZL */=0A= - if (regcache_raw_get_signed (regcache, itype_rs (inst)) > 0)=0A= - pc +=3D mips32_relative_offset (inst) + 4;=0A= - else=0A= - pc +=3D 8;=0A= + greater_branch: /* BGTZ, BGTZL, BGTZALC, BLTZALC, BLTUC */=0A= + pc =3D mips32_blez_pc (gdbarch, regcache, inst, pc + 4, 1);=0A= break;=0A= } /* switch */=0A= } /* else */=0A= @@ -2451,6 +2684,72 @@ micromips_instruction_is_compact_branch (unsigned sh= ort insn)=0A= }=0A= }=0A= =0A= +/* Return non-zero if the MIPS instruction INSN is a compact branch=0A= + or jump. A value of 1 indicates an unconditional compact branch=0A= + and a value of 2 indicates a conditional compact branch. */=0A= +=0A= +static int=0A= +mips32_instruction_is_compact_branch (struct gdbarch *gdbarch, ULONGEST in= sn)=0A= +{=0A= + switch (itype_op (insn))=0A= + {=0A= + /* BC */=0A= + case 50:=0A= + /* BALC */=0A= + case 58:=0A= + if (is_mipsr6_isa (gdbarch))=0A= + return 1;=0A= + break;=0A= + /* BOVC, BEQZALC, BEQC */=0A= + case 8:=0A= + /* BNVC, BNEZALC, BNEC */=0A= + case 24:=0A= + if (is_mipsr6_isa (gdbarch))=0A= + return 2;=0A= + break;=0A= + /* BEQZC, JIC */=0A= + case 54:=0A= + /* BNEZC, JIALC */=0A= + case 62:=0A= + if (is_mipsr6_isa (gdbarch))=0A= + /* JIC, JIALC are unconditional */=0A= + return (itype_rs (insn) =3D=3D 0) ? 1 : 2;=0A= + break;=0A= + /* BLEZC, BGEZC, BGEC */=0A= + case 22:=0A= + /* BGTZC, BLTZC, BLTC */=0A= + case 23:=0A= + /* BLEZALC, BGEZALC, BGEUC */=0A= + case 6:=0A= + /* BGTZALC, BLTZALC, BLTUC */=0A= + case 7:=0A= + if (is_mipsr6_isa (gdbarch)=0A= + && itype_rt (insn) !=3D 0)=0A= + return 2;=0A= + break;=0A= + /* BPOSGE32C */=0A= + case 1:=0A= + if (is_mipsr6_isa (gdbarch)=0A= + && itype_rt (insn) =3D=3D 0x1d && itype_rs (insn) =3D=3D 0)=0A= + return 2;=0A= + }=0A= + return 0;=0A= +}=0A= +=0A= +/* Return true if a standard MIPS instruction at ADDR has a branch=0A= + forbidden slot (i.e. it is a conditional compact branch instruction). = */=0A= +=0A= +static bool=0A= +mips32_insn_at_pc_has_forbidden_slot (struct gdbarch *gdbarch, CORE_ADDR a= ddr)=0A= +{=0A= + int status;=0A= + ULONGEST insn =3D mips_fetch_instruction (gdbarch, ISA_MIPS, addr, &stat= us);=0A= + if (status)=0A= + return false;=0A= +=0A= + return mips32_instruction_is_compact_branch (gdbarch, insn) =3D=3D 2;=0A= +}=0A= +=0A= struct mips_frame_cache=0A= {=0A= CORE_ADDR base;=0A= @@ -3494,7 +3793,8 @@ mips32_scan_prologue (struct gdbarch *gdbarch,=0A= reg =3D high_word & 0x1f;=0A= =0A= if (high_word =3D=3D 0x27bd /* addiu $sp,$sp,-i */=0A= - || high_word =3D=3D 0x23bd /* addi $sp,$sp,-i */=0A= + || (high_word =3D=3D 0x23bd /* addi $sp,$sp,-i */=0A= + && !is_mipsr6_isa (gdbarch))=0A= || high_word =3D=3D 0x67bd) /* daddiu $sp,$sp,-i */=0A= {=0A= if (offset < 0) /* Negative stack adjustment? */=0A= @@ -3632,7 +3932,9 @@ mips32_scan_prologue (struct gdbarch *gdbarch,=0A= =0A= /* A jump or branch, or enough non-prologue insns seen? If so,=0A= then we must have reached the end of the prologue by now. */=0A= - if (prev_delay_slot || non_prologue_insns > 1)=0A= + if (prev_delay_slot=0A= + || non_prologue_insns > 1=0A= + || mips32_instruction_is_compact_branch (gdbarch, inst))=0A= break;=0A= =0A= prev_non_prologue_insn =3D this_non_prologue_insn;=0A= @@ -3938,6 +4240,67 @@ mips_addr_bits_remove (struct gdbarch *gdbarch, CORE= _ADDR addr)=0A= #define LLD_OPCODE 0x34=0A= #define SC_OPCODE 0x38=0A= #define SCD_OPCODE 0x3c=0A= +#define LLSC_R6_OPCODE 0x1f=0A= +#define LL_R6_FUNCT 0x36=0A= +#define LLE_FUNCT 0x2e=0A= +#define LLD_R6_FUNCT 0x37=0A= +#define SC_R6_FUNCT 0x26=0A= +#define SCE_FUNCT 0x1e=0A= +#define SCD_R6_FUNCT 0x27=0A= +=0A= +/* Determine whether instruction 'insn' is of 'load linked X' type.=0A= + LL/SC instructions provide primitives to implement atomic =0A= + read-modify-write operations for synchronizable memory locations. */= =0A= +=0A= +static bool=0A= +is_ll_insn (struct gdbarch *gdbarch, ULONGEST insn)=0A= +{=0A= + if (itype_op (insn) =3D=3D LL_OPCODE=0A= + || itype_op (insn) =3D=3D LLD_OPCODE)=0A= + return true;=0A= +=0A= + if (rtype_op (insn) =3D=3D LLSC_R6_OPCODE=0A= + && rtype_funct (insn) =3D=3D LLE_FUNCT=0A= + && (insn & 0x40) =3D=3D 0)=0A= + return true;=0A= +=0A= + /* Handle LL and LLP varieties. */=0A= + if (is_mipsr6_isa (gdbarch)=0A= + && rtype_op (insn) =3D=3D LLSC_R6_OPCODE=0A= + && (rtype_funct (insn) =3D=3D LL_R6_FUNCT=0A= + || rtype_funct (insn) =3D=3D LLD_R6_FUNCT=0A= + || rtype_funct (insn) =3D=3D LLE_FUNCT))=0A= + return true;=0A= +=0A= + return false;=0A= +}=0A= +=0A= +/* Determine whether instruction 'insn' is of 'store conditional X' type.= =0A= + SC instructions and varieties perform completion of read-modify-write= =0A= + atomic sequence. */=0A= +=0A= +static bool=0A= +is_sc_insn (struct gdbarch *gdbarch, ULONGEST insn)=0A= +{=0A= + if (itype_op (insn) =3D=3D SC_OPCODE=0A= + || itype_op (insn) =3D=3D SCD_OPCODE)=0A= + return true;=0A= +=0A= + if (rtype_op (insn) =3D=3D LLSC_R6_OPCODE=0A= + && rtype_funct (insn) =3D=3D SCE_FUNCT=0A= + && (insn & 0x40) =3D=3D 0)=0A= + return true;=0A= +=0A= + /* Handle SC and SCP varieties. */=0A= + if (is_mipsr6_isa (gdbarch)=0A= + && rtype_op (insn) =3D=3D LLSC_R6_OPCODE=0A= + && (rtype_funct (insn) =3D=3D SC_R6_FUNCT=0A= + || rtype_funct (insn) =3D=3D SCD_R6_FUNCT=0A= + || rtype_funct (insn) =3D=3D SCE_FUNCT))=0A= + return true;=0A= +=0A= + return false;=0A= +}=0A= =0A= static std::vector=0A= mips_deal_with_atomic_sequence (struct gdbarch *gdbarch, CORE_ADDR pc)=0A= @@ -3950,10 +4313,11 @@ mips_deal_with_atomic_sequence (struct gdbarch *gdb= arch, CORE_ADDR pc)=0A= int index;=0A= int last_breakpoint =3D 0; /* Defaults to 0 (no breakpoints placed). */= =0A= const int atomic_sequence_length =3D 16; /* Instruction sequence length.= */=0A= + bool is_mipsr6 =3D is_mipsr6_isa (gdbarch);=0A= =0A= insn =3D mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL);=0A= /* Assume all atomic sequences start with a ll/lld instruction. */=0A= - if (itype_op (insn) !=3D LL_OPCODE && itype_op (insn) !=3D LLD_OPCODE)= =0A= + if (!is_ll_insn (gdbarch, insn))=0A= return {};=0A= =0A= /* Assume that no atomic sequence is longer than "atomic_sequence_length= " =0A= @@ -3983,28 +4347,72 @@ mips_deal_with_atomic_sequence (struct gdbarch *gdb= arch, CORE_ADDR pc)=0A= return {}; /* fallback to the standard single-step code. */=0A= case 4: /* BEQ */=0A= case 5: /* BNE */=0A= - case 6: /* BLEZ */=0A= - case 7: /* BGTZ */=0A= case 20: /* BEQL */=0A= case 21: /* BNEL */=0A= - case 22: /* BLEZL */=0A= - case 23: /* BGTTL */=0A= + case 22: /* BLEZL (BLEZC, BGEZC, BGEC) */=0A= + case 23: /* BGTZL (BGTZC, BLTZC, BLTC) */=0A= is_branch =3D 1;=0A= break;=0A= + case 6: /* BLEZ (BLEZALC, BGEZALC, BGEUC) */=0A= + case 7: /* BGTZ (BGTZALC, BLTZALC, BLTUC) */=0A= + if (is_mipsr6)=0A= + {=0A= + /* BLEZALC, BGTZALC */=0A= + if (itype_rs (insn) =3D=3D 0 && itype_rt (insn) !=3D 0)=0A= + return {}; /* fallback to the standard single-step code. */=0A= + /* BGEZALC, BLTZALC */=0A= + else if (itype_rs (insn) =3D=3D itype_rt (insn)=0A= + && itype_rt (insn) !=3D 0)=0A= + return {}; /* fallback to the standard single-step code. */=0A= + }=0A= + is_branch =3D 1;=0A= + break;=0A= + case 8: /* BOVC, BEQZALC, BEQC */=0A= + case 24: /* BNVC, BNEZALC, BNEC */=0A= + if (is_mipsr6)=0A= + is_branch =3D 1;=0A= + break;=0A= + case 50: /* BC */=0A= + case 58: /* BALC */=0A= + if (is_mipsr6)=0A= + return {}; /* fallback to the standard single-step code. */=0A= + break;=0A= + case 54: /* BEQZC, JIC */=0A= + case 62: /* BNEZC, JIALC */=0A= + if (is_mipsr6)=0A= + {=0A= + if (itype_rs (insn) =3D=3D 0) /* JIC, JIALC */=0A= + return {}; /* fallback to the standard single-step code. */=0A= + else=0A= + is_branch =3D 2; /* Marker for branches with a 21-bit offset. */=0A= + }=0A= + break;=0A= case 17: /* COP1 */=0A= - is_branch =3D ((itype_rs (insn) =3D=3D 9 || itype_rs (insn) =3D=3D 10)= =0A= - && (itype_rt (insn) & 0x2) =3D=3D 0);=0A= - if (is_branch) /* BC1ANY2F, BC1ANY2T, BC1ANY4F, BC1ANY4T */=0A= + is_branch =3D ((!is_mipsr6=0A= + /* BC1ANY2F, BC1ANY2T, BC1ANY4F, BC1ANY4T */=0A= + && (itype_rs (insn) =3D=3D 9 || itype_rs (insn) =3D=3D 10)=0A= + && (itype_rt (insn) & 0x2) =3D=3D 0)=0A= + /* BZ.df: 010001 110xx */=0A= + || (itype_rs (insn) & 0x18) =3D=3D 0x18);=0A= + if (is_branch !=3D 0)=0A= break;=0A= [[fallthrough]];=0A= case 18: /* COP2 */=0A= case 19: /* COP3 */=0A= - is_branch =3D (itype_rs (insn) =3D=3D 8); /* BCzF, BCzFL, BCzT, BCzTL *= /=0A= + /* BCzF, BCzFL, BCzT, BCzTL, BC*EQZ, BC*NEZ */=0A= + is_branch =3D ((itype_rs (insn) =3D=3D 8)=0A= + || (is_mipsr6=0A= + && (itype_rs (insn) =3D=3D 9=0A= + || itype_rs (insn) =3D=3D 13)));=0A= break;=0A= }=0A= - if (is_branch)=0A= + if (is_branch !=3D 0)=0A= {=0A= - branch_bp =3D loc + mips32_relative_offset (insn) + 4;=0A= + /* Is this a special PC21_S2 branch? */=0A= + if (is_branch =3D=3D 2)=0A= + branch_bp =3D loc + mips32_relative_offset21 (insn) + 4;=0A= + else=0A= + branch_bp =3D loc + mips32_relative_offset (insn) + 4;=0A= if (last_breakpoint >=3D 1)=0A= return {}; /* More than one branch found, fallback to the=0A= standard single-step code. */=0A= @@ -4012,12 +4420,12 @@ mips_deal_with_atomic_sequence (struct gdbarch *gdb= arch, CORE_ADDR pc)=0A= last_breakpoint++;=0A= }=0A= =0A= - if (itype_op (insn) =3D=3D SC_OPCODE || itype_op (insn) =3D=3D SCD_O= PCODE)=0A= + if (is_sc_insn (gdbarch, insn))=0A= break;=0A= }=0A= =0A= /* Assume that the atomic sequence ends with a sc/scd instruction. */= =0A= - if (itype_op (insn) !=3D SC_OPCODE && itype_op (insn) !=3D SCD_OPCODE)= =0A= + if (!is_sc_insn (gdbarch, insn))=0A= return {};=0A= =0A= loc +=3D MIPS_INSN32_SIZE;=0A= @@ -4166,7 +4574,7 @@ micromips_deal_with_atomic_sequence (struct gdbarch *= gdbarch,=0A= }=0A= break;=0A= }=0A= - if (is_branch)=0A= + if (is_branch !=3D 0)=0A= {=0A= if (last_breakpoint >=3D 1)=0A= return {}; /* More than one branch found, fallback to the=0A= @@ -4242,8 +4650,14 @@ mips_about_to_return (struct gdbarch *gdbarch, CORE_= ADDR pc)=0A= gdb_assert (mips_pc_is_mips (pc));=0A= =0A= insn =3D mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL);=0A= - hint =3D 0x7c0;=0A= - return (insn & ~hint) =3D=3D 0x3e00008; /* jr(.hb) $ra */=0A= + /* Mask the hint and the jalr/jr bit. */=0A= + hint =3D 0x7c1;=0A= +=0A= + if (is_mipsr6_isa (gdbarch) && insn =3D=3D 0xd81f0000) /* jrc $31 */=0A= + return 1;=0A= +=0A= + /* jr(.hb) $ra and "jalr(.hb) $ra" */=0A= + return ((insn & ~hint) =3D=3D 0x3e00008);=0A= }=0A= =0A= =0A= @@ -6760,7 +7174,9 @@ mips32_stack_frame_destroyed_p (struct gdbarch *gdbar= ch, CORE_ADDR pc)=0A= =0A= if (high_word !=3D 0x27bd /* addiu $sp,$sp,offset */=0A= && high_word !=3D 0x67bd /* daddiu $sp,$sp,offset */=0A= - && inst !=3D 0x03e00008 /* jr $ra */=0A= + && (inst & ~0x1) !=3D 0x03e00008 /* jr $31 or jalr $0, $31 */=0A= + && (!is_mipsr6_isa (gdbarch)=0A= + || inst !=3D 0xd81f0000) /* jrc $31 */=0A= && inst !=3D 0x00000000) /* nop */=0A= return 0;=0A= }=0A= @@ -7139,22 +7555,31 @@ mips32_instruction_has_delay_slot (struct gdbarch *= gdbarch, ULONGEST inst)=0A= int op;=0A= int rs;=0A= int rt;=0A= + bool is_mipsr6 =3D is_mipsr6_isa (gdbarch);=0A= =0A= op =3D itype_op (inst);=0A= if ((inst & 0xe0000000) !=3D 0)=0A= {=0A= rs =3D itype_rs (inst);=0A= rt =3D itype_rt (inst);=0A= - return (is_octeon_bbit_op (op, gdbarch) =0A= - || op >> 2 =3D=3D 5 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */=0A= - || op =3D=3D 29 /* JALX: bits 011101 */=0A= + return (is_octeon_bbit_op (op, gdbarch)=0A= + || (op >> 1 =3D=3D 10) /* BEQL, BNEL: bits 01010x */=0A= + || (op >> 1 =3D=3D 11 && rt =3D=3D 0) /* BLEZL, BGTZL: bits 01011x = */=0A= + || (!is_mipsr6 && op =3D=3D 29) /* JALX: bits 011101 */=0A= || (op =3D=3D 17=0A= && (rs =3D=3D 8=0A= /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */=0A= - || (rs =3D=3D 9 && (rt & 0x2) =3D=3D 0)=0A= + || (!is_mipsr6 && rs =3D=3D 9 && (rt & 0x2) =3D=3D 0)=0A= /* BC1ANY2F, BC1ANY2T: bits 010001 01001 */=0A= - || (rs =3D=3D 10 && (rt & 0x2) =3D=3D 0))));=0A= + || (!is_mipsr6 && rs =3D=3D 10 && (rt & 0x2) =3D=3D 0)))=0A= /* BC1ANY4F, BC1ANY4T: bits 010001 01010 */=0A= + || (is_mipsr6=0A= + && ((op =3D=3D 17=0A= + && (rs =3D=3D 9 /* BC1EQZ: 010001 01001 */=0A= + || rs =3D=3D 13)) /* BC1NEZ: 010001 01101 */=0A= + || (op =3D=3D 18=0A= + && (rs =3D=3D 9 /* BC2EQZ: 010010 01001 */=0A= + || rs =3D=3D 13))))); /* BC2NEZ: 010010 01101 */=0A= }=0A= else=0A= switch (op & 0x07) /* extract bits 28,27,26 */=0A= @@ -7173,7 +7598,11 @@ mips32_instruction_has_delay_slot (struct gdbarch *g= dbarch, ULONGEST inst)=0A= || ((rt & 0x1e) =3D=3D 0x1c && rs =3D=3D 0));=0A= /* BPOSGE32, BPOSGE64: bits 1110x */=0A= break; /* end REGIMM */=0A= - default: /* J, JAL, BEQ, BNE, BLEZ, BGTZ */=0A= + case 6: /* BLEZ */=0A= + case 7: /* BGTZ */=0A= + return (itype_rt (inst) =3D=3D 0);=0A= + break;=0A= + default: /* J, JAL, BEQ, BNE */=0A= return 1;=0A= break;=0A= }=0A= @@ -7385,7 +7814,18 @@ mips_adjust_breakpoint_address (struct gdbarch *gdba= rch, CORE_ADDR bpaddr)=0A= =0A= So, we'll use the second solution. To do this we need to know if=0A= the instruction we're trying to set the breakpoint on is in the=0A= - branch delay slot. */=0A= + branch delay slot.=0A= +=0A= + A similar problem occurs for breakpoints on forbidden slots where=0A= + the trap will be reported for the branch with the BD bit set.=0A= + In this case it would be ideal to recover using solution 1 from=0A= + above as there is no problem with the branch being skipped=0A= + (since the forbidden slot only exists on not-taken branches).=0A= + However, the BD bit is not available in all scenarios currently=0A= + so instead we move the breakpoint on to the next instruction.=0A= + This means that it is not possible to stop on an instruction=0A= + that can be in a forbidden slot even if that instruction is=0A= + jumped to directly. */=0A= =0A= boundary =3D mips_segment_boundary (bpaddr);=0A= =0A= @@ -7407,6 +7847,12 @@ mips_adjust_breakpoint_address (struct gdbarch *gdba= rch, CORE_ADDR bpaddr)=0A= prev_addr =3D bpaddr - 4;=0A= if (mips32_insn_at_pc_has_delay_slot (gdbarch, prev_addr))=0A= bpaddr =3D prev_addr;=0A= + /* If the previous instruction has a forbidden slot, we have to=0A= + move the breakpoint to the following instruction to prevent=0A= + breakpoints in forbidden slots being reported as unknown=0A= + traps. */=0A= + else if (mips32_insn_at_pc_has_forbidden_slot (gdbarch, prev_addr))= =0A= + bpaddr +=3D 4;=0A= }=0A= else=0A= {=0A= diff --git a/gdb/testsuite/gdb.arch/mips-64-r6.c b/gdb/testsuite/gdb.arch/m= ips-64-r6.c=0A= new file mode 100644=0A= index 00000000000..13f43ee24d0=0A= --- /dev/null=0A= +++ b/gdb/testsuite/gdb.arch/mips-64-r6.c=0A= @@ -0,0 +1,918 @@=0A= +/*=0A= + Copyright 2023-2024 Free Software Foundation, Inc.=0A= +=0A= + This file is part of GDB.=0A= +=0A= + This program is free software; you can redistribute it and/or modify=0A= + it under the terms of the GNU General Public License as published by=0A= + the Free Software Foundation; either version 3 of the License, or=0A= + (at your option) any later version.=0A= +=0A= + This program is distributed in the hope that it will be useful,=0A= + but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= + GNU General Public License for more details.=0A= +=0A= + You should have received a copy of the GNU General Public License=0A= + along with this program. If not, see .= =0A= +*/=0A= +=0A= +#define xstr(s) str(s)=0A= +#define str(s) #s=0A= +=0A= +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D macros from sim/testutils/mips/uti= ls-r6.inc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */=0A= +=0A= +/* 58 is local label to exit with errcode !=3D 0, indicating error. */=0A= +#define fp_assert(a, b) "beq " xstr (a) ", " xstr (b) ", 1f \n\t" \=0A= + "nop \n\t" \=0A= + "b 58f \n\t" \=0A= + "nop \n\t" \=0A= + "1: \n\t"=0A= +=0A= +/* Clobbers: $4,$6,$7. */=0A= +#define r6ck_1r(inst, a, ret) \=0A= + "li $4, " xstr (a) " \n\t" \=0A= + "li $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4 \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$6,$7. */=0A= +#define r6ck_1dr(inst, a, ret) \=0A= + "ld $4, " xstr (a) " \n\t" \=0A= + "ld $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4 \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7. */=0A= +#define r6ck_2r(inst, a, b, ret) \=0A= + "li $4, " xstr (a) " \n\t" \=0A= + "li $5, " xstr (b) " \n\t" \=0A= + "li $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4, $5 \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7. */=0A= +#define r6ck_2dr(inst, a, b, ret) \=0A= + "ld $4, " xstr (a) " \n\t" \=0A= + "ld $5, " xstr (b) " \n\t" \=0A= + "ld $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4, $5 \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7. */=0A= +#define r6ck_2dr1i(inst, a, b, imm, ret) \=0A= + "ld $4, " xstr (a) " \n\t" \=0A= + "ld $5, " xstr (b) " \n\t" \=0A= + "ld $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4, $5, " xstr (imm) " \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$6,$7. */=0A= +#define r6ck_1r1i(inst, a, imm, ret) \=0A= + "li $4, " xstr (a) " \n\t" \=0A= + "li $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4, " xstr (imm) " \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$6,$7. */=0A= +#define r6ck_1dr1i(inst, a, imm, ret) \=0A= + "ld $4, " xstr (a) " \n\t" \=0A= + "ld $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4, " xstr (imm) " \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$6. */=0A= +#define r6ck_0dr1i(inst, a, imm, ret) \=0A= + "ld $4, " xstr (a) " \n\t" \=0A= + "ld $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $4, $4, " xstr (imm) " \n\t" \=0A= + fp_assert ($6, $4)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7. */=0A= +#define r6ck_2r1i(inst, a, b, imm, ret) \=0A= + "li $4, " xstr (a) " \n\t" \=0A= + "li $5, " xstr (b) " \n\t" \=0A= + "li $6, " xstr (ret) " \n\t" \=0A= + xstr (inst) " $7, $4, $5, " xstr (imm) " \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7,$8,$f2,$f4,$f6. */=0A= +#define r6ck_3s(inst, a, b, c, ret) \=0A= + "li $4, " xstr (a) " \n\t" \=0A= + "li $5, " xstr (b) " \n\t" \=0A= + "li $6, " xstr (c) " \n\t" \=0A= + "li $7, " xstr (ret) " \n\t" \=0A= + "mtc1 $4, $f2 \n\t" \=0A= + "mtc1 $5, $f4 \n\t" \=0A= + "mtc1 $6, $f6 \n\t" \=0A= + xstr (inst) " $f2, $f4, $f6 \n\t" \=0A= + "mfc1 $8, $f2 \n\t" \=0A= + fp_assert ($7, $8)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7,$f2,$f4. */=0A= +#define r6ck_2s(inst, a, b, ret) \=0A= + "li $4, " xstr (a) " \n\t" \=0A= + "li $5, " xstr (b) " \n\t" \=0A= + "li $6, " xstr (ret) " \n\t" \=0A= + "mtc1 $4, $f2 \n\t" \=0A= + "mtc1 $5, $f4 \n\t" \=0A= + xstr (inst) " $f2, $f4 \n\t" \=0A= + "mfc1 $7, $f2 \n\t" \=0A= + fp_assert ($6, $7)=0A= +=0A= +/* Clobbers: $4,$5,$6,$7,$8,$9,$10,$f2,$f4. */=0A= +#define r6ck_2d(inst, a, b, ret) \=0A= + ".data \n\t" \=0A= + "1: .dword " xstr (a) " \n\t" \=0A= + "2: .dword " xstr (b) " \n\t" \=0A= + "3: .dword " xstr (ret) " \n\t" \=0A= + ".text \n\t" \=0A= + "dla $4, 1b \n\t" \=0A= + "dla $5, 2b \n\t" \=0A= + "dla $6, 3b \n\t" \=0A= + "ldc1 $f2, 0($4) \n\t" \=0A= + "ldc1 $f4, 0($5) \n\t" \=0A= + "lw $7, 0($6) \n\t" \=0A= + "lw $8, 4($6) \n\t" \=0A= + xstr (inst) " $f2, $f4 \n\t" \=0A= + "mfhc1 $9, $f2 \n\t" \=0A= + "mfc1 $10, $f2 \n\t" \=0A= + fp_assert ($7, $9) \=0A= + fp_assert ($8, $10)=0A= +=0A= +/* Clobbers: $2,$4,$5,$6,$7,$8,$9,$10,$f2,$f4,$f6. */=0A= +#define r6ck_3d(inst, a, b, c, ret) \=0A= + ".data \n\t" \=0A= + "1: .dword " xstr (a) " \n\t" \=0A= + "2: .dword " xstr (b) " \n\t" \=0A= + "3: .dword " xstr (c) " \n\t" \=0A= + "4: .dword " xstr (ret) " \n\t" \=0A= + ".text \n\t" \=0A= + "dla $4, 1b \n\t" \=0A= + "dla $5, 2b \n\t" \=0A= + "dla $6, 3b \n\t" \=0A= + "dla $2, 4b \n\t" \=0A= + "ldc1 $f2, 0($4) \n\t" \=0A= + "ldc1 $f4, 0($5) \n\t" \=0A= + "ldc1 $f6, 0($6) \n\t" \=0A= + "lw $7, 0($2) \n\t" \=0A= + "lw $8, 4($2) \n\t" \=0A= + xstr (inst) " $f2, $f4, $f6 \n\t" \=0A= + "mfhc1 $9, $f2 \n\t" \=0A= + "mfc1 $10, $f2 \n\t" \=0A= + fp_assert ($7, $9) \=0A= + fp_assert ($8, $10)=0A= +=0A= +=0A= +/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D macros from sim/testutils/mips/tes= tutils.inc =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */=0A= +=0A= +/* Put value 'val' into register 'reg'.=0A= + Clobbers: None. */=0A= +#define load32(reg, val) \=0A= + "li " xstr (reg) ", " xstr (val) " \n\t"=0A= +=0A= +/* Check whether two registers contain the same value.=0A= + Clobbers: None. */=0A= +#define checkreg(reg, expreg) \=0A= + ".set push \n\t" \=0A= + ".set noat \n\t" \=0A= + ".set noreorder \n\t" \=0A= + "beq " xstr (expreg) ", " xstr (reg) ", 901f \n\t" \=0A= + "nop \n\t" \=0A= + "b 58f \n\t" \=0A= + "nop \n\t" \=0A= + "901: \n\t" \=0A= + ".set pop \n\t"=0A= +=0A= +/* Check if register 'reg' contains value 'val'.=0A= + Clobbers: $1. */=0A= +#define check32(reg, val) \=0A= + ".set push \n\t" \=0A= + ".set noat \n\t" \=0A= + load32 ($1, val) \=0A= + checkreg (reg, $1) \=0A= + ".set pop \n\t"=0A= +=0A= +/* Checkpair based on endianess=0A= + Clobbers: $1. */=0A= +#define checkpair_xendian(lo, hi, base, ec, w) \=0A= + ".set noat \n\t" \=0A= + "lw $1, " xstr (ec) " \n\t" \=0A= + "andi $1, $1, 0x1 \n\t" \=0A= + "beqz $1, 2f \n\t" \=0A= + ".set at \n\t" \=0A= + "1: \n\t" \=0A= + checkpair_be_##w (lo, hi, base) \=0A= + "b 3f \n\t" \=0A= + "nop \n\t" \=0A= + "2: \n\t" \=0A= + checkpair_le_##w (lo, hi, base) \=0A= + "3: \n\t"=0A= +=0A= +=0A= +/* Check hi-lo register pair against data stored at base+o1 and base+o2.= =0A= + Clobbers: $1 - $5. */=0A= +#define checkpair(lo, hi, base, w, o1, o2) \=0A= + "move $2, " xstr (lo) " \n\t" \=0A= + "move $3, " xstr (hi) " \n\t" \=0A= + ".set noat \n\t" \=0A= + "dla $1, " xstr (base) " \n\t" \=0A= + "l" xstr (w) " $4, " xstr (o1) "($1) \n\t" \=0A= + "l" xstr (w) " $5, " xstr (o2) "($1) \n\t" \=0A= + ".set at \n\t" \=0A= + checkreg ($2, $4) \=0A= + checkreg ($3, $5)=0A= +=0A= +#define checkpair_le_d(lo, hi, base) \=0A= + checkpair (lo, hi, base, w, 0, 4)=0A= +=0A= +#define checkpair_be_d(lo, hi, base) \=0A= + checkpair (lo, hi, base, w, 4, 0)=0A= +=0A= +=0A= +#define checkpair_le_q(lo, hi, base) \=0A= + checkpair (lo, hi, base, d, 0, 8)=0A= +=0A= +#define checkpair_be_q(lo, hi, base) \=0A= + checkpair (lo, hi, base, d, 8, 0)=0A= +=0A= +#define checkpair_qword(lo, hi, base, oe) \=0A= + checkpair_xendian (lo, hi, base, oe, q)=0A= +=0A= +#define checkpair_dword(lo, hi, base, oe) \=0A= + checkpair_xendian (lo, hi, base, oe, d)=0A= +=0A= +void=0A= +abort (void);=0A= +=0A= +/* Tests branch instructions. */=0A= +=0A= +int=0A= +test_r6_branch (void)=0A= +{=0A= +/* Using volatile to prevent certain optimizations which could cause=0A= + * instruction deletion.=0A= + * 'err' identifies instruction which (eventually) caused error.=0A= + * (err =3D=3D 0) =3D=3D> all instructions executed successfully. */=0A= +=0A= + volatile int err =3D -1;=0A= + volatile int a14 =3D 0xffffffff;=0A= + volatile int a13 =3D 0x123;=0A= + volatile int a12 =3D 0x45;=0A= + volatile int a7 =3D 0x45;=0A= + volatile int a8 =3D 0xfffffffe;=0A= + volatile int a9 =3D 2147483647;=0A= + volatile int a11 =3D 0;=0A= + volatile int a10 =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t" /* Create new scope for asm configuration. = */=0A= + ".set noreorder \n\t" /* Don't allow reordering of instructions. = */=0A= + "li %[err], 1 \n\t"=0A= + "bovc %[a12], %[a13], Lfail \n\t" /* BOVC */=0A= + "nop \n\t"=0A= + "bovc %[a9], %[a13], L2 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L2: \n\t"=0A= + "li %[err], 2 \n\t"=0A= + "bnvc %[a9], %[a13], Lfail \n\t" /* BNVC */=0A= + "nop \n\t"=0A= + "bnvc %[a12], %[a13], L3 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L3: \n\t"=0A= + "li %[err], 3 \n\t"=0A= + "beqc %[a12], %[a13], Lfail \n\t" /* BEQC */=0A= + "nop \n\t"=0A= + "beqc %[a12], %[a7], L4 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L4: \n\t"=0A= + "li %[err], 4 \n\t"=0A= + "bnec %[a12], %[a7], Lfail \n\t" /* BNEC */=0A= + "nop \n\t"=0A= + "bnec %[a12], %[a13], L5 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L5: \n\t"=0A= + "li %[err], 5 \n\t"=0A= + "bltc %[a13], %[a12], Lfail \n\t" /* BLTC */=0A= + "nop \n\t"=0A= + "bltc %[a12], %[a13], L6 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L6: \n\t"=0A= + "L7: \n\t"=0A= + "li %[err], 7 \n\t"=0A= + "bgec %[a12], %[a13], Lfail \n\t" /* BGEC */=0A= + "nop \n\t"=0A= + "bgec %[a13], %[a12], L8 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L8: \n\t"=0A= + "L9: \n\t"=0A= + "li %[err], 9 \n\t"=0A= + "bltuc %[a14], %[a13], Lfail \n\t" /* BLTUC */=0A= + "nop \n\t"=0A= + "bltuc %[a8], %[a14], L10 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L10: \n\t"=0A= + "L11: \n\t"=0A= + "li %[err], 11 \n\t"=0A= + "bgeuc %[a13], %[a14], Lfail \n\t" /* BGEUC */=0A= + "nop \n\t"=0A= + "bgeuc %[a14], %[a8], L12 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L12: \n\t"=0A= + "L13: \n\t"=0A= + "li %[err], 13 \n\t"=0A= + "bltzc %[a13], Lfail \n\t" /* BLTZC */=0A= + "nop \n\t"=0A= + "bltzc %[a11], Lfail \n\t"=0A= + "nop \n\t"=0A= + "bltzc %[a14], L14 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L14: \n\t"=0A= + "li %[err], 14 \n\t"=0A= + "blezc %[a13], Lfail \n\t" /* BLEZC */=0A= + "nop \n\t"=0A= + "blezc %[a11], L145 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L145: \n\t"=0A= + "blezc %[a14], L15 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L15: \n\t"=0A= + "li %[err], 15 \n\t"=0A= + "bgezc %[a8], Lfail \n\t" /* BGEZC */=0A= + "nop \n\t"=0A= + "bgezc %[a11], L155 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L155: \n\t"=0A= + "bgezc %[a13], L16 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L16: \n\t"=0A= + "li %[err], 16 \n\t"=0A= + "bgtzc %[a8], Lfail \n\t" /* BGTZC */=0A= + "nop \n\t"=0A= + "bgtzc %[a11], Lfail \n\t"=0A= + "nop \n\t"=0A= + "bgtzc %[a13], L17 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "li %[a10], 0 \n\t"=0A= + "L17: \n\t"=0A= + "li %[err], 17 \n\t"=0A= + "blezalc %[a12], Lfail \n\t" /* BLEZALC */=0A= + "nop \n\t"=0A= + "blezalc %[a11], Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L175 \n\t" /* BEQZC */=0A= + "nop \n\t"=0A= + "li %[err], 8531 \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L175: \n\t"=0A= + "li %[err], 23531 \n\t"=0A= + "blezalc %[a14], Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L18 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L18: \n\t"=0A= + "li %[err], 18 \n\t"=0A= + "bgezalc %[a14], Lfail \n\t" /* BGEZALC */=0A= + "nop \n\t"=0A= + "bgezalc %[a11], Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L185 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L185: \n\t"=0A= + "bgezalc %[a12], Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L19 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L19: \n\t"=0A= + "li %[err], 19 \n\t"=0A= + "bgtzalc %[a14], Lfail \n\t" /* BGTZALC */=0A= + "nop \n\t"=0A= + "bgtzalc %[a11], Lfail \n\t"=0A= + "nop \n\t"=0A= + "bgtzalc %[a12], Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L20 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L20: \n\t"=0A= + "li %[err], 20 \n\t"=0A= + "bltzalc %[a12], Lfail \n\t" /* BLTZALC */=0A= + "nop \n\t"=0A= + "bltzalc %[a11], Lfail \n\t"=0A= + "nop \n\t"=0A= + "bltzalc %[a14], Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L21 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L21: \n\t"=0A= + "li %[err], 21 \n\t"=0A= + "bc L22 \n\t" /* BC */=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L22: \n\t"=0A= + "li %[err], 22 \n\t"=0A= + "balc Lret \n\t" /* BALC */=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], L23 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L23: \n\t"=0A= + "li %[err], 23 \n\t"=0A= + "jal GetPC \n\t" /* JAL */=0A= + "nop \n\t"=0A= + "jic $6, 4 \n\t" /* JIC */=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L24: \n\t"=0A= + "li %[err], 24 \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "jal GetPC \n\t"=0A= + "nop \n\t"=0A= + "jialc $6, 20 \n\t" /* JIALC */=0A= + "nop \n\t"=0A= + "beqzc %[a10], L25 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "LJIALCRET: \n\t"=0A= + "li %[a10], 0 \n\t"=0A= + "jr $31 \n\t" /* JR */=0A= + "nop \n\t"=0A= + "L25: \n\t"=0A= + "li %[err], 25 \n\t"=0A= + "jal GetPC \n\t"=0A= + "nop \n\t"=0A= + "move %[a11], $6 \n\t"=0A= + "nal \n\t"=0A= + "nop \n\t"=0A= + "addiu %[a11], 12 \n\t" /* ADDIU */=0A= + "beqc %[a11], $31, L26 \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "L26: \n\t"=0A= + "li %[err], 26 \n\t"=0A= + "balc Lret \n\t"=0A= + "li %[a10], 1 \n\t"=0A= + "beqzc %[a10], Lend \n\t"=0A= + "nop \n\t"=0A= + "b Lfail \n\t"=0A= + "nop \n\t"=0A= + "Lret: \n\t"=0A= + "li %[a10], 0 \n\t"=0A= + "daddiu $31, 4 \n\t" /* DADDIU */=0A= + "jrc $31 \n\t" /* JRC */=0A= + "nop \n\t"=0A= + "GetPC: \n\t"=0A= + "move $6, $31 \n\t"=0A= + "jr $31 \n\t"=0A= + "Lend: \n\t"=0A= + "li %[err], 0 \n\t"=0A= + "Lfail: \n\t"=0A= + ".set pop \n\t" /* Restore previous config */=0A= + : [err] "+r"(err), [a14] "+r"(a14), [a13] "+r"(a13), [a12] "+r"(a12),=0A= + [a7] "+r"(a7), [a8] "+r"(a8), [a9] "+r"(a9), [a10] "+r"(a10), [a11] "+= r"(a11)=0A= + : /* inputs */=0A= + : "$31", "$6" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +/* Tests forbidden slot branching i.e. conditional compact branch=0A= + instructions. */=0A= +=0A= +int=0A= +test_r6_forbidden (void)=0A= +{=0A= + volatile int err =3D -1;=0A= + volatile int a4 =3D 0;=0A= + volatile int a2 =3D 0;=0A= + volatile int a1 =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t"=0A= + ".set noreorder \n\t"=0A= +/* Test if FS is ignored when branch is taken */=0A= + "li %[err], 1 \n\t"=0A= + "li %[a4], 0 \n\t"=0A= + "beqzalc %[a4], L41 \n\t"=0A= + "li %[err], -85 \n\t"=0A= + "L42: \n\t"=0A= + "b Lfail2 \n\t"=0A= + "nop \n\t"=0A= + "L41: \n\t"=0A= + "blez %[err], Lfail2 \n\t"=0A= +/* Test if FS is used when branch is not taken */=0A= + "li %[err], 2 \n\t"=0A= + "li %[a4], 1 \n\t"=0A= + "blezc %[a4], L43 \n\t"=0A= + "addiu %[a4], %[a4], 1 \n\t"=0A= + "li %[a2], 2 \n\t"=0A= + "beq %[a4], %[a2], L44 \n\t"=0A= + "nop \n\t"=0A= + "L43: \n\t"=0A= + "nop \n\t"=0A= + "b Lfail2 \n\t"=0A= + "nop \n\t"=0A= + "L44: \n\t"=0A= + "li %[err], 3 \n\t"=0A= + "li %[a4], 3 \n\t"=0A= + "beqzalc %[a4], Lfail2 \n\t"=0A= +/* Note: 'bc L45' instead nop would cause SegFault: Illegal instruction:= =0A= + Forbidden slot causes an error when it contains a branch. */=0A= + "nop \n\t"=0A= + "b Lend2 \n\t"=0A= + "nop \n\t"=0A= + "L45: \n\t"=0A= + "nop \n\t"=0A= + "b Lfail2 \n\t"=0A= + "nop \n\t"=0A= + "Lend2: \n\t"=0A= + "li %[err], 0 \n\t"=0A= + "Lfail2: \n\t"=0A= + "nop \n\t"=0A= + ".set pop \n\t"=0A= + : [err] "+r" (err), [a4] "+r"(a4), [a2] "+r"(a2), [a1] "+r"(a1) /* outpu= ts */=0A= + : /* inputs */=0A= + : "$31" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +int=0A= +test_r6_64 (void)=0A= +{=0A= + volatile int err =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t"=0A= + ".set noreorder \n\t"=0A= + ".data \n\t"=0A= + "dval: .dword 0xaa55bb66cc77dd88 \n\t"=0A= + "d1: .dword 0xaaaabbbbccccdddd \n\t"=0A= + "d5: .dword 0x00000000000000dd \n\t"=0A= + "d7: .dword 0xeeeeffff00001111 \n\t"=0A= + "d8: .dword 0xbbccccddddeeeeff \n\t"=0A= + "d9: .dword 0x000000ddaaaabbbb \n\t"=0A= + "dval1: .word 0x1234abcd \n\t"=0A= + "dval2: .word 0xffee0000 \n\t"=0A= + "dval3: .dword 0xffffffffffffffff \n\t"=0A= + " .fill 240,1,0 \n\t"=0A= + "dval4: .dword 0x5555555555555555 \n\t"=0A= + " .fill 264,1,0 \n\t"=0A= +=0A= +/* Register $11 stores instruction currently being tested and hence=0A= + * identifies error if it occurs. */=0A= + ".text \n\t"=0A= +=0A= + "li $11, 1 \n\t" /* Test DALIGN */=0A= + r6ck_2dr1i (dalign, d7, d1, 3, d8)=0A= + r6ck_2dr1i (dalign, d1, d5, 4, d9)=0A= +=0A= + "li $11, 2 \n\t" /* Test LDPC */=0A= + "ld $5, dval \n\t"=0A= + "nop \n\t"=0A= + "ldpc $4, dval \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 3 \n\t" /* Test LWUPC */=0A= + "lwu $5, dval1 \n\t"=0A= + "lwupc $4, dval1 \n\t"=0A= + fp_assert ($4, $5)=0A= + "lwu $5, dval2 \n\t"=0A= + "lwupc $4, dval2 \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 4 \n\t" /* Test LLD */=0A= + "ld $5, dval3 \n\t"=0A= + "dla $3, dval4 \n\t"=0A= + "lld $4, -248($3) \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 5 \n\t" /* Test SCD */=0A= + "lld $4, -248($3) \n\t"=0A= + "dli $4, 0xafaf \n\t"=0A= + "scd $4, -248($3) \n\t"=0A= + "ld $5, dval3 \n\t"=0A= + "dli $4, 0xafaf \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "Lend3: \n\t"=0A= + "li $11, 0 \n\t"=0A= + "58: \n\t"=0A= + "move %[err], $11 \n\t"=0A= + ".set pop \n\t"=0A= + : [err] "+r" (err) /* outputs */=0A= + : /* inputs */=0A= + : "$3", "$4", "$5", "$6", "$7", "$11" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +int=0A= +test_r6 (void)=0A= +{=0A= + volatile int err =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t"=0A= + ".set noreorder \n\t"=0A= + ".data \n\t"=0A= + "dval_1: .word 0xabcd1234 \n\t"=0A= + "dval_2: .word 0x1234eeff \n\t"=0A= + ".fill 248,1,0 \n\t"=0A= + "dval_3: .word 0x55555555 \n\t"=0A= + ".fill 260,1,0 \n\t"=0A= + "dval_4: .word 0xaaaaaaaa \n\t"=0A= + ".text \n\t"=0A= + "li $11, 1 \n\t" /* ADDIUPC */=0A= + "jal GetPC_2 \n\t"=0A= + "nop \n\t"=0A= + "addiu $4, $6, 8 \n\t"=0A= + "addiupc $5, 4 \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 2 \n\t" /* AUIPC */=0A= + "jal GetPC_2 \n\t"=0A= + "nop \n\t"=0A= + "addiu $4, $6, 8 \n\t"=0A= + "aui $4, $4, 8 \n\t"=0A= + "auipc $5, 8 \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 3 \n\t" /* ALUIPC */=0A= + "jal GetPC_2 \n\t"=0A= + "nop \n\t"=0A= + "addiu $4, $6, 16 \n\t"=0A= + "aui $4, $4, 8 \n\t"=0A= + "li $7, 0xffff0000 \n\t"=0A= + "and $4, $4, $7 \n\t"=0A= + "aluipc $5, 8 \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 4 \n\t" /* LWPC */=0A= + "lw $5, dval_1 \n\t"=0A= + "lwpc $4, dval_1 \n\t"=0A= + fp_assert ($4, $5)=0A= + "lw $5, dval_2 \n\t"=0A= + "lwpc $4, dval_2 \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= +/* Testing LL follows.=0A= + * NOTE: May be redundant because SC already contains LL in its test. */= =0A= + "li $11, 5 \n\t"=0A= + "lw $5, dval_2 \n\t"=0A= + "dla $3, dval_3 \n\t"=0A= + "ll $4, -252($3) \n\t"=0A= + fp_assert ($4, $5)=0A= +=0A= + "li $11, 6 \n\t" /* LL-SC sequence */=0A= + "ll $4, -252($3) \n\t"=0A= + "li $4, 0xafaf \n\t"=0A= + "sc $4, -252($3) \n\t"=0A= + "lw $5, dval_2 \n\t"=0A= + "li $4, 0xafaf \n\t"=0A= + fp_assert ($4, $5)=0A= + "b Lend4 \n\t"=0A= + "nop \n\t"=0A= + "GetPC_2: \n\t"=0A= + "move $6, $31 \n\t"=0A= + "jr $31 \n\t"=0A= + "Lend4: \n\t"=0A= + "li $11, 0 \n\t"=0A= + "58: \n\t"=0A= + "move %[err], $11 \n\t"=0A= + ".set pop \n\t"=0A= + : [err] "+r"(err) /* outputs */=0A= + : /* inputs */=0A= + : "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10",=0A= + "$11", "$31" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +/* For fpu-branching testing, bc1eq/eqz are enough. */=0A= +=0A= +int=0A= +test_r6_fpu (void)=0A= +{=0A= + volatile int err =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t"=0A= + ".set noreorder \n\t"=0A= +/* Test qNaN format is 754-2008 */=0A= + "li $11, 1 \n\t"=0A= + "li $4, 0x0 \n\t"=0A= + "li $5, 0x0 \n\t"=0A= + "li $6, 0x7fc00000 \n\t"=0A= + "mtc1 $4, $f2 \n\t"=0A= + "mtc1 $5, $f4 \n\t"=0A= + "div.s $f6, $f2, $f4 \n\t"=0A= + "mfc1 $8, $f6 \n\t"=0A= + fp_assert ($6, $8)=0A= +=0A= + "li $11, 2 \n\t" /* bc1eqz */=0A= + "li $10, 0x01 \n\t"=0A= + "mtc1 $10, $f2 \n\t"=0A= + "mtc1 $0, $f4 \n\t"=0A= + "bc1eqz $f2, 58f \n\t"=0A= + "nop \n\t"=0A= + "bc1eqz $f4, L62 \n\t"=0A= + "nop \n\t"=0A= + "b 58f \n\t"=0A= + "nop \n\t"=0A= +"L62: \n\t"=0A= + "li $11, 3 \n\t" /* bc1nez */=0A= + "bc1nez $f4, 58f \n\t"=0A= + "nop \n\t"=0A= + "bc1nez $f2, Lend8 \n\t"=0A= + "nop \n\t"=0A= + "b 58f \n\t"=0A= + "nop \n\t"=0A= +"Lend8: \n\t"=0A= + "li $11, 0 \n\t"=0A= + "58: \n\t"=0A= + "move %[err], $11 \n\t"=0A= + ".set pop \n\t"=0A= + : [err] "+r"(err) /* outputs */=0A= + : /* inputs */=0A= + : "$4", "$5", "$6", "$8", "$10", "$11", "$31",=0A= + "$f2", "$f4", "$f6" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +/* R6 specific tests for mips64 (64-bit). */=0A= +=0A= +int=0A= +test_r6_llsc_dp (void)=0A= +{=0A= + volatile int err =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t"=0A= + ".set noreorder \n\t"=0A= + ".data \n\t"=0A= + ".align 16 \n\t"=0A= + "test_data: \n\t"=0A= + ".word 0xaaaaaaaa \n\t"=0A= + ".word 0xbbbbbbbb \n\t"=0A= + ".word 0xcccccccc \n\t"=0A= + ".word 0xdddddddd \n\t"=0A= + ".align 16 \n\t"=0A= + "end_check: \n\t"=0A= + ".byte 0 \n\t"=0A= + ".byte 0 \n\t"=0A= + ".byte 0 \n\t"=0A= + ".byte 0x1 \n\t"=0A= + ".text \n\t"=0A= + "li $11, 1 \n\t" /* LLWP */= =0A= + "llwp $2, $3, test_data \n\t"=0A= + checkpair_dword ($2, $3, test_data, end_check)=0A= + "sll $2, $2, 1 \n\t"=0A= + "srl $3, $3, 1 \n\t"=0A= + "move $s0, $2 \n\t"=0A= + "scwp $2, $3, test_data \n\t"=0A= + check32 ($2, 1)=0A= + checkpair_dword ($s0, $3, test_data, end_check)=0A= + /* Test SCWP, done */=0A= + "li $11, 2 \n\t"=0A= + "li $11, 3 \n\t" /* LLDP */= =0A= + "lldp $2, $3, test_data \n\t"=0A= + checkpair_qword ($2, $3, test_data, end_check)=0A= + "dsll $2, $2, 1 \n\t"=0A= + "dsrl $3, $3, 1 \n\t"=0A= + "move $s0, $2 \n\t"=0A= + "scdp $2, $3, test_data \n\t"=0A= + check32 ($2, 1)=0A= + checkpair_qword ($s0, $3, test_data, end_check)=0A= + "li $11, 4 \n\t" /* SCDP done= */=0A= + "Lend5: \n\t"=0A= + "li $11, 0 \n\t"=0A= + "58: \n\t"=0A= + "move %[err], $11 \n\t"=0A= + ".set pop \n\t"=0A= + : [err] "+r"(err) /* outputs */=0A= + : /* inputs */=0A= + : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10", "$11",=0A= + "$31", "$s0" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +/* R6 specific tests for mips32 (32-bit). */=0A= +=0A= +int=0A= +test_r6_llsc_wp (void)=0A= +{=0A= + volatile int err =3D 0;=0A= +=0A= + asm (=0A= + ".set push \n\t"=0A= + ".set noreorder \n\t"=0A= + ".data \n\t"=0A= + ".align 8 \n\t"=0A= + "test_data_2: \n\t"=0A= + ".word 0xaaaaaaaa \n\t"=0A= + ".word 0xbbbbbbbb \n\t"=0A= + ".align 8 \n\t"=0A= + "end_check_2: \n\t"=0A= + ".byte 0 \n\t"=0A= + ".byte 0 \n\t"=0A= + ".byte 0 \n\t"=0A= + ".byte 0x1 \n\t"=0A= + ".text \n\t"=0A= + "li $11, 1 \n\t" /* Test LLWP= */=0A= + "llwp $2, $3, test_data_2 \n\t"=0A= + checkpair_dword ($2, $3, test_data_2, end_check_2)=0A= + "sll $2, $2, 1 \n\t"=0A= + "srl $3, $3, 1 \n\t"=0A= + "move $s0, $2 \n\t"=0A= + "scwp $2, $3, test_data_2 \n\t"=0A= + check32 ($2, 1)=0A= + checkpair_dword ($s0, $3, test_data_2, end_check_2)=0A= +/* Test SCWP, done. */=0A= + "li $11, 2 \n\t"=0A= + "Lend6: \n\t"=0A= + "li $11, 0 \n\t"=0A= + "58: \n\t"=0A= + "move %[err], $11 \n\t"=0A= + ".set pop \n\t"=0A= + : [err] "+r"(err) /* outputs */=0A= + : /* inputs */=0A= + : "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9", "$10",=0A= + "$11", "$31", "$s0" /* clobbers */=0A= + );=0A= +=0A= + return err;=0A= +}=0A= +=0A= +/* Any test_r6_* function returns non-zero =3D> failure. */=0A= +#define EXPECT(X) if ((X)) abort ();=0A= +=0A= +int=0A= +main (void)=0A= +{=0A= + EXPECT (test_r6_branch ());=0A= +=0A= + EXPECT (test_r6_forbidden ());=0A= +=0A= + EXPECT (test_r6_64 ());=0A= +=0A= + EXPECT (test_r6 ());=0A= +=0A= + EXPECT (test_r6_fpu ());=0A= +=0A= + EXPECT (test_r6_llsc_dp ());=0A= +=0A= + EXPECT (test_r6_llsc_wp ());=0A= +=0A= + return 0;=0A= +}=0A= diff --git a/gdb/testsuite/gdb.arch/mips-64-r6.exp b/gdb/testsuite/gdb.arch= /mips-64-r6.exp=0A= new file mode 100644=0A= index 00000000000..2cce6abc6fa=0A= --- /dev/null=0A= +++ b/gdb/testsuite/gdb.arch/mips-64-r6.exp=0A= @@ -0,0 +1,76 @@=0A= +# Copyright (C) 2023-2024 Free Software Foundation, Inc.=0A= +=0A= +# This program is free software; you can redistribute it and/or modify=0A= +# it under the terms of the GNU General Public License as published by=0A= +# the Free Software Foundation; either version 3 of the License, or=0A= +# (at your option) any later version.=0A= +#=0A= +# This program is distributed in the hope that it will be useful,=0A= +# but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= +# GNU General Public License for more details.=0A= +#=0A= +# You should have received a copy of the GNU General Public License=0A= +# along with this program; if not, see .=0A= +=0A= +################################################################=0A= +################## MIPS Release 6 patch tests ##################=0A= +################################################################=0A= +=0A= +# Send 'si' to gdb until inferior exits.=0A= +proc stepi {} {=0A= + global gdb_prompt=0A= + set timeout [get_largest_timeout]=0A= + set start [timestamp]=0A= + while { [timestamp] - $start < 3*$timeout } {=0A= + gdb_test_multiple "stepi" "" {=0A= + -re ".*exited normally.*" {=0A= + pass "success"=0A= + return=0A= + }=0A= + -re ".*The program is not being run.*" {=0A= + fail "failure"=0A= + return=0A= + }=0A= + -re ".*Breakpoint.*test_.*$gdb_prompt $" {=0A= + }=0A= + -re "$gdb_prompt.*" {=0A= + }=0A= + }=0A= + }=0A= + fail "test failed"=0A= + return=0A= +}=0A= +=0A= +require {istarget "*mips*"}=0A= +=0A= +set testfile "mips-64-r6"=0A= +set srcfile ${testfile}.c=0A= +set binfile ${objdir}/${subdir}/${testfile}=0A= +=0A= +if {[prepare_for_testing "failed to prepare" "${binfile}" "${srcfile}" {de= bug nowarnings}]} {=0A= + untested "failed to prepare"=0A= + return=0A= +}=0A= +=0A= +# Native needs run.=0A= +if { ![runto_main] } {=0A= + untested "couldn't run to main"=0A= + return=0A= +}=0A= +=0A= +set tests ""=0A= +foreach n [list "r6_branch" "r6_forbidden" "r6_64" "r6" "r6_fpu" "r6_llsc_= dp" "r6_llsc_wp"] {=0A= + lappend tests "test_$n"=0A= +}=0A= +=0A= +# Put breakpoint on each test-function=0A= +foreach func $tests {=0A= + if {![gdb_breakpoint "$func"]} {=0A= + untested "couldn't put breakpoint to $func"=0A= + return=0A= + }=0A= +}=0A= +=0A= +# Step through the binary=0A= +stepi=0A= -- =0A= 2.40.1=0A= =0A=