From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web12.3149.1649402673909537514 for ; Fri, 08 Apr 2022 00:24:34 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=C71yDpd8; spf=permerror, err=parse error for token &{10 18 %{ir}.%{v}.%{d}.spf.has.pphosted.com}: invalid domain name (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=0097613c5e=abner.chang@hpe.com) Received: from pps.filterd (m0134423.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.1.2/8.16.1.2) with ESMTP id 2381WekH017002; Fri, 8 Apr 2022 07:24:25 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pps0720; bh=nw/7WmEgHCfHiqR/XW+1sY2eLeHXAKcZEAVffmnnae8=; b=C71yDpd83+UP8onfajgRkTTiT5Hoz4qffKnLKO06k6ibdX+ZFZAMfFLznRI/3K+h1PXb X/WewKNb8GYtTwcvMwRwqaA3XR2yTpOA2H/PmGLTJCKTIytylrjOqLg+UoN7iYLihN4F 2mPbfbtK3qM9zRE2/bsr/5vRicrabFQuAhfeOJRypLhS5FLbsRo17n6JbVEtAjyWLMFY 2xetVvgdgPSAyrCDfITnjVCiK2wSqxzpY037TxK8vBdkuQ9GCnBnebZk/dsb1ntwKsZu 9sOHU5GLcA+Iqqp6JfUUgPpCBAgA6WQ6evP2MXXfYT26vMPeEJWk83wzkpvZj/DjWjGK lg== Received: from p1lg14880.it.hpe.com (p1lg14880.it.hpe.com [16.230.97.201]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3f9t9hurpc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 08 Apr 2022 07:24:24 +0000 Received: from p1wg14926.americas.hpqcorp.net (unknown [10.119.18.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by p1lg14880.it.hpe.com (Postfix) with ESMTPS id 733F7800399; Fri, 8 Apr 2022 07:24:23 +0000 (UTC) Received: from p1wg14925.americas.hpqcorp.net (10.119.18.114) by p1wg14926.americas.hpqcorp.net (10.119.18.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Thu, 7 Apr 2022 19:24:23 -1200 Received: from p1wg14919.americas.hpqcorp.net (16.230.19.122) by p1wg14925.americas.hpqcorp.net (10.119.18.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15 via Frontend Transport; Thu, 7 Apr 2022 19:24:23 -1200 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (192.58.206.38) by edge.it.hpe.com (16.230.19.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.15; Thu, 7 Apr 2022 19:24:10 -1200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JDfu7WcSSuZ1p0lVnK8LVK19xLycasGocdFH+3KqsgyoREdeEU6lc+cHxfsg57AabkMoQV05nFsGNy3uRKpqV3R9vQPgz7xF8N2sI95OHeBbTQCtySXwe4OPnS4eaoRep8CPWMygnOagchkLnBV3HIinJ+O3mJaFBTBj6SeAs0DOJAJjskSJ3JwKLKOlYDkEG4/B2gk9EXr0rJeWTh9j4zVAjGBsLJjfcDtz+T7sTnE71SXMQYC6MpEx4c7ZOxOoEwIAJE3FTrFEL4+1ZbsZ/M4nO8tsGD5GOoMR8agejaicRbHXUAYgFWmrLlDQgxiP8LGV6vQQPidioIlUTOIyGQ== 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=YQRSoVdChyXzUNu0jPxSOLFAmjbQbAqxHOjkRfmdm/c=; b=dewfDSV/BlQ+dpqoosDMekuwNE7WpJTHrYPLzMvS85ez4eTSSDVxNXR/9tzE/XgXBbukauJ++VgLB0sgZpw5I8F1yuVtiU3KF37r6I2vhEVwLlNvKEs1EAqp8oFCkmrmgExCveqEtU4LW6ZOab1RqUO79bT2dfID/pvTWlk3Ddu5dzepnRwh5GWl2oBvhR77Pc8Dcr0BX1JFsLv6aXN1Ixn6Lr703lhBD/1FMjOYT4K7KDpgfnvZM6dWqhfTLfe87wArP76DCUXppQ7qDtfexjwpG3izfV404yql+l4s/IAw+4n1g9mElsKCfb/0KCzjzST5yFMV6pnKn0o/f3ZYlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Received: from PH7PR84MB1885.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:510:154::18) by DM4PR84MB1685.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:8:48::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.19; Fri, 8 Apr 2022 07:23:37 +0000 Received: from PH7PR84MB1885.NAMPRD84.PROD.OUTLOOK.COM ([fe80::2053:811f:bd4a:7c21]) by PH7PR84MB1885.NAMPRD84.PROD.OUTLOOK.COM ([fe80::2053:811f:bd4a:7c21%8]) with mapi id 15.20.5144.022; Fri, 8 Apr 2022 07:23:37 +0000 From: "Abner Chang" To: "devel@edk2.groups.io" , "lichao@loongson.cn" CC: Michael D Kinney , Liming Gao , Zhiguang Liu , "Baoqi Zhang" Subject: Re: [edk2-devel] [staging/LoongArch RESEND PATCH v1 21/33] MdePkg/BaseLib: BaseLib for LOONGARCH64 architecture. Thread-Topic: [edk2-devel] [staging/LoongArch RESEND PATCH v1 21/33] MdePkg/BaseLib: BaseLib for LOONGARCH64 architecture. Thread-Index: AQHYHYIoWzPy1phOkEGrmCS9mEuGA6zl+BVA Date: Fri, 8 Apr 2022 07:23:37 +0000 Message-ID: References: <20220209065542.2986555-1-lichao@loongson.cn> In-Reply-To: <20220209065542.2986555-1-lichao@loongson.cn> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 191946fd-a8b7-4b6c-e98c-08da1930b2a9 x-ms-traffictypediagnostic: DM4PR84MB1685:EE_ x-microsoft-antispam-prvs: x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: YbL9jyzF7DBhQOLU4gNijlO9O7P4WY6b8sQYQHfyr2hIOiqvHhu5a4wefI+ohxopXSHTacG2koKvvHyg5mQBJmYIaMWRDUE63oGmhQd+PEngfb320QW4ixZMC94k+xHPT841Rka/iFDRQm04q5QYyc70Um2neSGtjC0BH1zuhz4fOF8c577XpTnuM6AG769317ibE/yWkKHZo5pU2c40FUTjCMdNBK/KYNdA7k/2I0vd+hvh4d1zHoJ1OqAiti0o6Kbfzpk0j/DdVo8wZLFDPXbFbrwr3mfr1ZnJd0uryxiZCoM/5h5gsEP9Z15z5USh/0mcrR82QGB6gyafKFfmz3QL0Xx43u+KN8ffrWr8D6+YFVazTCTBe7TDagAz+wgzragEl46opgdnpHt8lTVZsjwK15rqcrE6u9jSM8yGDPHt2qCcJX9ofA4/ynFw2ozhOtmk/vlxk2B7WBBvXd3bTlnnoFtlkrooFSqkES/jnWTRRyL0oEjkL+AVDmSF7rwRlYZ+o1/BBXBCmwtkiM/aIVrqQzWzAClUXzbfOSL6ANc2fmFGSHhxb5n9t8nDYfhyDAsn9A3yZfE4XCV0bbYLR89FQgbDPhJanH6o971xgWa0n20lPurZr8yj0ZN5qjG6umP7CaoFn2RDNCv56QFIAiXjJJ7ihw3B5VT1oaZCvayy9ReE+xvQ4+ng1YTnUIlr2m8xDvzrHdjE4RVYwB3AGXCCBauP7uQ1r4yDrgIY1d3FG87KAaY9E6TYC7WpFfevrRWer4cuvkpxq4f66P8a8YexGUhpTW7mmn/VrTNTYfzyUiIp9chyKhrbT1VWfU5pxU7IYdfmWKAeckGKXTCYGA== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH7PR84MB1885.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230001)(366004)(316002)(6506007)(8936002)(966005)(53546011)(33656002)(5660300002)(55016003)(8676002)(66476007)(86362001)(2906002)(52536014)(30864003)(508600001)(26005)(7696005)(186003)(45080400002)(54906003)(66446008)(9686003)(64756008)(38100700002)(83380400001)(122000001)(19627235002)(71200400001)(82960400001)(38070700005)(76116006)(66946007)(110136005)(66556008)(4326008)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?jMM2Qp2fNb6vlNzYwcLPbTfuI9lPFoBpSCGVe7l0KCY8ZbysvO5eAIgnIvzo?= =?us-ascii?Q?d5kujHr3/gDd29/9ZhpaBVNplW32neytMZorlsYU4o+tSbmH9UuFTx3I4een?= =?us-ascii?Q?79SP7hXY3NnET3+ysQ2QB3uPNCccTsfuPMH5c8c4iS6xaE5pwcZ8vMNhattA?= =?us-ascii?Q?WRUFIp7aAyZm2yvNfIul5R600vOciNFd+byQyx1KDxrILe4P6QuQH4mDGAzl?= =?us-ascii?Q?nS5jXYc3ejU9E6ISPh8WnKlGpUiQD6UUmtIL3vcWIVei7ARqB+ByubpkwA8f?= =?us-ascii?Q?y0f4ohQgAGdy0AH7I4cfRe+Uj3/vB78ZTTiVB/OIHXPfISNXUtswE7ukDzob?= =?us-ascii?Q?9EoVRa3e4FfccXdMzFHW6F4I7jHilpyssx74KsIFH+yGu+PCCI9pg+zI7AeS?= =?us-ascii?Q?GqODU/1McrM3dSWruifCZIQziPKXsj9E9UYM/JuAKAXzv6H1uWCrgUpS/O4S?= =?us-ascii?Q?cdVcw9TBSA1bf1GwsR50brgr16OIOZYPGXbIvEkvB9AJ6Dkqt17cGCmqq4GD?= =?us-ascii?Q?5MYto6zaVw2D4LiLzV4XzUx0RqNij4gyBBJgYYTgRIjN9IR8SA17SqgVcZUY?= =?us-ascii?Q?9BuPrSjr1LMXTL9u4+8CA+htJTL2xNQLcOsbrVaX9PFqu5a8+Zzgtx4ircdd?= =?us-ascii?Q?9aY8ITt/cQo6slp/cmfPyHRIAhr+qNV3CqRGAmF7PCXQBNrvCSWmin2/PeWs?= =?us-ascii?Q?KZMTzU3tnSG1vE4+/445CbWrPhmGsvkZJdUPLBCVNva2DwI47iP+i7LYqCwy?= =?us-ascii?Q?MuIon1E6Ckfs40Iq6y+c9BmKnyGCMXXqs7Lb0blX9v04WpWw1e5xGOTpK5fh?= =?us-ascii?Q?+Nu5shJ1SLaiyvCxHZxUpClKTc9GvZ1tiMVD7cSKzQVmt+a+9ma8SpMGsvnW?= =?us-ascii?Q?6ZbIuADwFeZEpteYK+1xSD+aI/pkxCew0zwoU3tmxX02ohNKyOCKmNGeIwW4?= =?us-ascii?Q?1Kwv3SB+sV+hYKCJVLtzEY1zJAxiVtmsTB4kvXlhkjRWSpPViWjSVP2ZQqiY?= =?us-ascii?Q?8wGV/LDKnHv5BuB7pedRCZPW7HVW8lz4+c5ICxH25c0m+fZsoXOUWUoVl5Jj?= =?us-ascii?Q?JnST+m3d0j3vzEQ2hQMZ915hcQ6y+d3FQXto9rcwErcuK/TWChifZcwMw+5J?= =?us-ascii?Q?SGkzGcfNbAcHmiyGF9VIyb5H5ljou8Ik2XLNVZOkFRwYm1F4Xgm6T932TbR/?= =?us-ascii?Q?LM1skVU8W4eOfUf9BNpvvd3Dw0XYfMYmW0mxG+kYYDd4aStl/RmVFNxedQ7O?= =?us-ascii?Q?W6Ea7xvrYPMNJo4IpXhDzw7TGWKb9H5qiOIWXbyTqqWT3lnfoRbRkTchcq1E?= =?us-ascii?Q?MQN2mjejgpfBjNm5sDafVebXzXZkPqrUwicW+t45M0+giz/S4IE7T1ZZl0Px?= =?us-ascii?Q?TooeCqdkvWMV1pEY6633EeIO4ctj580D6XBEmKIJ3S/tCNd0p4tPzN4re+yi?= =?us-ascii?Q?XfFfmDBmrXTnSEz9YR0hrZGhH2GQYdVfmZhm6VfSKgQ4PsYIybj2QgKHGDob?= =?us-ascii?Q?ZgnGGN+6/TbHGylrnfZ+cMFXhBvCuqeH1fZ8OqVnJZYgPvQuRgU/xx9g5w84?= =?us-ascii?Q?cExqgxsZqw3VkcK568bCONMghnQjOtDr25EDq2POSuXvXnIQPSBSwX946H0M?= =?us-ascii?Q?4zH2mEASlMn/ayTICcOO1EeNxqK+IEKwA18FbCcq75/Fjdmyks7SEzh9xZUI?= =?us-ascii?Q?EYiHfebbJ0SVv/Q5Ew7SR17e+UiYkJM1VBtqGiJjp/25fHjzA+8WyMXaFT41?= =?us-ascii?Q?PXhxDvyfSw=3D=3D?= X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH7PR84MB1885.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 191946fd-a8b7-4b6c-e98c-08da1930b2a9 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Apr 2022 07:23:37.1532 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Acqjf4qvsFBgCHklI+n7omT1Ln7IKBqxBWMFPMBLGF65zt4gfLrnCK87VYfy4RVYcDcFu0clY84S/BF0Mbftzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR84MB1685 X-OriginatorOrg: hpe.com X-Proofpoint-ORIG-GUID: fF1EnuPrYPcWmYqVxd-c_LotQdQB6Zkj X-Proofpoint-GUID: fF1EnuPrYPcWmYqVxd-c_LotQdQB6Zkj X-Proofpoint-UnRewURL: 2 URL's were un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.425,FMLib:17.11.64.514 definitions=2022-04-08_02,2022-04-07_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 mlxscore=0 adultscore=0 malwarescore=0 suspectscore=0 clxscore=1015 impostorscore=0 priorityscore=1501 lowpriorityscore=0 mlxlogscore=839 bulkscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2204080039 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Acked-by: Abner Chang > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Chao Li > Sent: Wednesday, February 9, 2022 2:56 PM > To: devel@edk2.groups.io > Cc: Michael D Kinney ; Liming Gao > ; Zhiguang Liu ; Baoqi > Zhang > Subject: [edk2-devel] [staging/LoongArch RESEND PATCH v1 21/33] > MdePkg/BaseLib: BaseLib for LOONGARCH64 architecture. >=20 > Add LoongArch LOONGARCH64 BaseLib functions. >=20 > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu >=20 > Signed-off-by: Chao Li > Co-authored-by: Baoqi Zhang > --- > MdePkg/Include/Library/BaseLib.h | 24 ++ > MdePkg/Library/BaseLib/BaseLib.inf | 13 + > .../BaseLib/LoongArch64/CpuBreakpoint.S | 24 ++ > MdePkg/Library/BaseLib/LoongArch64/CpuPause.S | 31 +++ > .../BaseLib/LoongArch64/DisableInterrupts.S | 21 ++ > .../BaseLib/LoongArch64/EnableInterrupts.S | 21 ++ > .../BaseLib/LoongArch64/GetInterruptState.S | 35 +++ > .../BaseLib/LoongArch64/InternalSwitchStack.c | 58 +++++ > .../Library/BaseLib/LoongArch64/MemoryFence.S | 19 ++ > .../BaseLib/LoongArch64/SetJumpLongJump.S | 49 ++++ > .../Library/BaseLib/LoongArch64/SwitchStack.S | 39 +++ > .../Library/BaseLib/LoongArch64/Unaligned.c | 244 ++++++++++++++++++ > 12 files changed, 578 insertions(+) > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/CpuBreakpoint.S > create mode 100644 MdePkg/Library/BaseLib/LoongArch64/CpuPause.S > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/GetInterruptState.S > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/MemoryFence.S > create mode 100644 > MdePkg/Library/BaseLib/LoongArch64/SetJumpLongJump.S > create mode 100644 MdePkg/Library/BaseLib/LoongArch64/SwitchStack.S > create mode 100644 MdePkg/Library/BaseLib/LoongArch64/Unaligned.c >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 6aa0d97218..3c27e2ea93 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -6,6 +6,7 @@ Copyright (c) 2006 - 2021, Intel Corporation. All rights > reserved.
> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
> Copyright (c) Microsoft Corporation.
> Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. = All > rights reserved.
> +Portions Copyright (c) 2022, Loongson Technology Corporation Limited. Al= l > rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -152,6 +153,29 @@ typedef struct { >=20 > #endif // defined (MDE_CPU_RISCV64) >=20 > +#if defined (MDE_CPU_LOONGARCH64) > +/// > +/// The LoongArch architecture context buffer used by SetJump() and > LongJump() > +/// > +typedef struct { > + UINT64 S0; > + UINT64 S1; > + UINT64 S2; > + UINT64 S3; > + UINT64 S4; > + UINT64 S5; > + UINT64 S6; > + UINT64 S7; > + UINT64 S8; > + UINT64 SP; > + UINT64 FP; > + UINT64 RA; > +} BASE_LIBRARY_JUMP_BUFFER; > + > +#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8 > + > +#endif // defined (MDE_CPU_LOONGARCH64) > + > // > // String Services > // > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index cebda3b210..4c9b6b50dd 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -409,6 +409,19 @@ > RiscV64/RiscVInterrupt.S | GCC > RiscV64/FlushCache.S | GCC >=20 > +[Sources.LOONGARCH64] > + Math64.c > + LoongArch64/Unaligned.c > + LoongArch64/InternalSwitchStack.c > + LoongArch64/GetInterruptState.S | GCC > + LoongArch64/EnableInterrupts.S | GCC > + LoongArch64/DisableInterrupts.S | GCC > + LoongArch64/MemoryFence.S | GCC > + LoongArch64/CpuBreakpoint.S | GCC > + LoongArch64/CpuPause.S | GCC > + LoongArch64/SetJumpLongJump.S | GCC > + LoongArch64/SwitchStack.S | GCC > + > [Packages] > MdePkg/MdePkg.dec >=20 > diff --git a/MdePkg/Library/BaseLib/LoongArch64/CpuBreakpoint.S > b/MdePkg/Library/BaseLib/LoongArch64/CpuBreakpoint.S > new file mode 100644 > index 0000000000..4e022e9bb5 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/CpuBreakpoint.S > @@ -0,0 +1,24 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# CpuBreakpoint for LoongArch > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +ASM_GLOBAL ASM_PFX(CpuBreakpoint) > + > +#/** > +# Generates a breakpoint on the CPU. > +# > +# Generates a breakpoint on the CPU. The breakpoint must be > implemented such > +# that code can resume normal execution after the breakpoint. > +# > +#**/ > + > +ASM_PFX(CpuBreakpoint): > + break 3 > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/CpuPause.S > b/MdePkg/Library/BaseLib/LoongArch64/CpuPause.S > new file mode 100644 > index 0000000000..b98dd48f4d > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/CpuPause.S > @@ -0,0 +1,31 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# CpuPause for LoongArch > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +ASM_GLOBAL ASM_PFX(CpuPause) > + > +#/** > +# Requests CPU to pause for a short period of time. > +# > +# Requests CPU to pause for a short period of time. Typically used in M= P > +# systems to prevent memory starvation while waiting for a spin lock. > +# > +#**/ > + > +ASM_PFX(CpuPause): > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + andi $zero, $zero, 0x0 //nop > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S > b/MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S > new file mode 100644 > index 0000000000..0f228339af > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/DisableInterrupts.S > @@ -0,0 +1,21 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# LoongArch interrupt disable > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +ASM_GLOBAL ASM_PFX(DisableInterrupts) > + > +#/** > +# Disables CPU interrupts. > +#**/ > + > +ASM_PFX(DisableInterrupts): > + li.w $t0, 0x4 > + csrxchg $zero, $t0, 0x0 > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S > b/MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S > new file mode 100644 > index 0000000000..3c34fb2cdd > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/EnableInterrupts.S > @@ -0,0 +1,21 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# LoongArch interrupt enable > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +ASM_GLOBAL ASM_PFX(EnableInterrupts) > + > +#/** > +# Enables CPU interrupts. > +#**/ > + > +ASM_PFX(EnableInterrupts): > + li.w $t0, 0x4 > + csrxchg $t0, $t0, 0x0 > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/GetInterruptState.S > b/MdePkg/Library/BaseLib/LoongArch64/GetInterruptState.S > new file mode 100644 > index 0000000000..bfd1f2d5f7 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/GetInterruptState.S > @@ -0,0 +1,35 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# Get LoongArch interrupt status > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +ASM_GLOBAL ASM_PFX(GetInterruptState) > + > +#/** > +# Retrieves the current CPU interrupt state. > +# > +# Returns TRUE means interrupts are currently enabled. Otherwise, > +# returns FALSE. > +# > +# @retval TRUE CPU interrupts are enabled. > +# @retval FALSE CPU interrupts are disabled. > +# > +#**/ > + > +ASM_PFX(GetInterruptState): > + li.w $t1, 0x4 > + csrrd $t0, 0x0 > + and $t0, $t0, $t1 > + beqz $t0, 1f > + li.w $a0, 0x1 > + b 2f > +1: > + li.w $a0, 0x0 > +2: > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c > b/MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c > new file mode 100644 > index 0000000000..1f1e43106f > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/InternalSwitchStack.c > @@ -0,0 +1,58 @@ > +/** @file > + SwitchStack() function for LoongArch. > + > + Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > +**/ > + > +#include "BaseLibInternals.h" > + > +UINTN > +EFIAPI > +InternalSwitchStackAsm ( > + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer > + ); > + > +/** > + Transfers control to a function starting with a new stack. > + > + Transfers control to the function specified by EntryPoint using the > + new stack specified by NewStack and passing in the parameters specifie= d > + by Context1 and Context2. Context1 and Context2 are optional and may > + be NULL. The function EntryPoint must never return. > + > + If EntryPoint is NULL, then ASSERT(). > + If NewStack is NULL, then ASSERT(). > + > + @param EntryPoint A pointer to function to call with the new stack. > + @param Context1 A pointer to the context to pass into the EntryPoi= nt > + function. > + @param Context2 A pointer to the context to pass into the EntryPoi= nt > + function. > + @param NewStack A pointer to the new stack to use for the EntryPoi= nt > + function. > + @param Marker VA_LIST marker for the variable argument list. > + > +**/ > +VOID > +EFIAPI > +InternalSwitchStack ( > + IN SWITCH_STACK_ENTRY_POINT EntryPoint, > + IN VOID *Context1, OPTIONAL > + IN VOID *Context2, OPTIONAL > + IN VOID *NewStack, > + IN VA_LIST Marker > + ) > + > +{ > + BASE_LIBRARY_JUMP_BUFFER JumpBuffer; > + > + JumpBuffer.RA =3D (UINTN)EntryPoint; > + JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID*); > + JumpBuffer.SP -=3D sizeof (Context1) + sizeof (Context2); > + ((VOID **)(UINTN)JumpBuffer.SP)[0] =3D Context1; > + ((VOID **)(UINTN)JumpBuffer.SP)[1] =3D Context2; > + > + InternalSwitchStackAsm(&JumpBuffer); > +} > diff --git a/MdePkg/Library/BaseLib/LoongArch64/MemoryFence.S > b/MdePkg/Library/BaseLib/LoongArch64/MemoryFence.S > new file mode 100644 > index 0000000000..0d8dc10914 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/MemoryFence.S > @@ -0,0 +1,19 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# MemoryFence() for LoongArch64 > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +ASM_GLOBAL ASM_PFX(MemoryFence) > + > +# > +# Memory fence for LoongArch64 > +# > +ASM_PFX(MemoryFence): > + dbar 0 > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/SetJumpLongJump.S > b/MdePkg/Library/BaseLib/LoongArch64/SetJumpLongJump.S > new file mode 100644 > index 0000000000..35267c925f > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/SetJumpLongJump.S > @@ -0,0 +1,49 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# Set/Long jump for LoongArch > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +#define STORE st.d /* 64 bit mode regsave instruction */ > +#define LOAD ld.d /* 64 bit mode regload instruction */ > +#define RSIZE 8 /* 64 bit mode register size */ > + > +ASM_GLOBAL ASM_PFX(SetJump) > +ASM_GLOBAL ASM_PFX(InternalLongJump) > + > +ASM_PFX(SetJump): > + STORE $s0, $a0, RSIZE * 0 > + STORE $s1, $a0, RSIZE * 1 > + STORE $s2, $a0, RSIZE * 2 > + STORE $s3, $a0, RSIZE * 3 > + STORE $s4, $a0, RSIZE * 4 > + STORE $s5, $a0, RSIZE * 5 > + STORE $s6, $a0, RSIZE * 6 > + STORE $s7, $a0, RSIZE * 7 > + STORE $s8, $a0, RSIZE * 8 > + STORE $sp, $a0, RSIZE * 9 > + STORE $fp, $a0, RSIZE * 10 > + STORE $ra, $a0, RSIZE * 11 > + li.w $a0, 0 # Setjmp return > + jirl $zero, $ra, 0 > + > +ASM_PFX(InternalLongJump): > + LOAD $ra, $a0, RSIZE * 11 > + LOAD $s0, $a0, RSIZE * 0 > + LOAD $s1, $a0, RSIZE * 1 > + LOAD $s2, $a0, RSIZE * 2 > + LOAD $s3, $a0, RSIZE * 3 > + LOAD $s4, $a0, RSIZE * 4 > + LOAD $s5, $a0, RSIZE * 5 > + LOAD $s6, $a0, RSIZE * 6 > + LOAD $s7, $a0, RSIZE * 7 > + LOAD $s8, $a0, RSIZE * 8 > + LOAD $sp, $a0, RSIZE * 9 > + LOAD $fp, $a0, RSIZE * 10 > + move $a0, $a1 > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/SwitchStack.S > b/MdePkg/Library/BaseLib/LoongArch64/SwitchStack.S > new file mode 100644 > index 0000000000..4facc76082 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/SwitchStack.S > @@ -0,0 +1,39 @@ > +#-----------------------------------------------------------------------= ------- > +# > +# InternalSwitchStackAsm for LoongArch > +# > +# Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +#-----------------------------------------------------------------------= ------- > + > +#define STORE st.d /* 64 bit mode regsave instruction */ > +#define LOAD ld.d /* 64 bit mode regload instruction */ > +#define RSIZE 8 /* 64 bit mode register size */ > + > +ASM_GLOBAL ASM_PFX(InternalSwitchStackAsm) > + > +/** > + This allows the caller to switch the stack and goes to the new entry p= oint > + > + @param JumpBuffer A pointer to CPU context buffer. > +**/ > + > +ASM_PFX(InternalSwitchStackAsm): > + LOAD $ra, $a0, RSIZE * 11 > + LOAD $s0, $a0, RSIZE * 0 > + LOAD $s1, $a0, RSIZE * 1 > + LOAD $s2, $a0, RSIZE * 2 > + LOAD $s3, $a0, RSIZE * 3 > + LOAD $s4, $a0, RSIZE * 4 > + LOAD $s5, $a0, RSIZE * 5 > + LOAD $s6, $a0, RSIZE * 6 > + LOAD $s7, $a0, RSIZE * 7 > + LOAD $s8, $a0, RSIZE * 8 > + LOAD $sp, $a0, RSIZE * 9 > + LOAD $fp, $a0, RSIZE * 10 > + LOAD $a0, $sp, 0 > + LOAD $a1, $sp, 8 > + jirl $zero, $ra, 0 > + .end > diff --git a/MdePkg/Library/BaseLib/LoongArch64/Unaligned.c > b/MdePkg/Library/BaseLib/LoongArch64/Unaligned.c > new file mode 100644 > index 0000000000..33fa3d2eed > --- /dev/null > +++ b/MdePkg/Library/BaseLib/LoongArch64/Unaligned.c > @@ -0,0 +1,244 @@ > +/** @file > + Unaligned access functions of BaseLib for LoongArch. > + > + Copyright (c) 2022, Loongson Technology Corporation Limited. All right= s > reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include "BaseLibInternals.h" > + > +/** > + Reads a 16-bit value from memory that may be unaligned. > + > + This function returns the 16-bit value pointed to by Buffer. The funct= ion > + guarantees that the read operation does not produce an alignment fault= . > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 16-bit value that may be unaligned. > + > + @return The 16-bit value read from Buffer. > + > +**/ > +UINT16 > +EFIAPI > +ReadUnaligned16 ( > + IN CONST UINT16 *Buffer > + ) > +{ > + volatile UINT8 LowerByte; > + volatile UINT8 HigherByte; > + > + ASSERT (Buffer !=3D NULL); > + > + LowerByte =3D ((UINT8*)Buffer)[0]; > + HigherByte =3D ((UINT8*)Buffer)[1]; > + > + return (UINT16)(LowerByte | (HigherByte << 8)); > +} > + > +/** > + Writes a 16-bit value to memory that may be unaligned. > + > + This function writes the 16-bit value specified by Value to Buffer. Va= lue is > + returned. The function guarantees that the write operation does not > produce > + an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 16-bit value that may be unaligned. > + @param Value 16-bit value to write to Buffer. > + > + @return The 16-bit value to write to Buffer. > + > +**/ > +UINT16 > +EFIAPI > +WriteUnaligned16 ( > + OUT UINT16 *Buffer, > + IN UINT16 Value > + ) > +{ > + ASSERT (Buffer !=3D NULL); > + > + ((volatile UINT8*)Buffer)[0] =3D (UINT8)Value; > + ((volatile UINT8*)Buffer)[1] =3D (UINT8)(Value >> 8); > + > + return Value; > +} > + > +/** > + Reads a 24-bit value from memory that may be unaligned. > + > + This function returns the 24-bit value pointed to by Buffer. The funct= ion > + guarantees that the read operation does not produce an alignment fault= . > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 24-bit value that may be unaligned. > + > + @return The 24-bit value read from Buffer. > + > +**/ > +UINT32 > +EFIAPI > +ReadUnaligned24 ( > + IN CONST UINT32 *Buffer > + ) > +{ > + ASSERT (Buffer !=3D NULL); > + > + return (UINT32)( > + ReadUnaligned16 ((UINT16*)Buffer) | > + (((UINT8*)Buffer)[2] << 16) > + ); > +} > + > +/** > + Writes a 24-bit value to memory that may be unaligned. > + > + This function writes the 24-bit value specified by Value to Buffer. Va= lue is > + returned. The function guarantees that the write operation does not > produce > + an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 24-bit value that may be unaligned. > + @param Value 24-bit value to write to Buffer. > + > + @return The 24-bit value to write to Buffer. > + > +**/ > +UINT32 > +EFIAPI > +WriteUnaligned24 ( > + OUT UINT32 *Buffer, > + IN UINT32 Value > + ) > +{ > + ASSERT (Buffer !=3D NULL); > + > + WriteUnaligned16 ((UINT16*)Buffer, (UINT16)Value); > + *(UINT8*)((UINT16*)Buffer + 1) =3D (UINT8)(Value >> 16); > + return Value; > +} > + > +/** > + Reads a 32-bit value from memory that may be unaligned. > + > + This function returns the 32-bit value pointed to by Buffer. The funct= ion > + guarantees that the read operation does not produce an alignment fault= . > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 32-bit value that may be unaligned. > + > + @return The 32-bit value read from Buffer. > + > +**/ > +UINT32 > +EFIAPI > +ReadUnaligned32 ( > + IN CONST UINT32 *Buffer > + ) > +{ > + UINT16 LowerBytes; > + UINT16 HigherBytes; > + > + ASSERT (Buffer !=3D NULL); > + > + LowerBytes =3D ReadUnaligned16 ((UINT16*) Buffer); > + HigherBytes =3D ReadUnaligned16 ((UINT16*) Buffer + 1); > + > + return (UINT32) (LowerBytes | (HigherBytes << 16)); > +} > + > +/** > + Writes a 32-bit value to memory that may be unaligned. > + > + This function writes the 32-bit value specified by Value to Buffer. Va= lue is > + returned. The function guarantees that the write operation does not > produce > + an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 32-bit value that may be unaligned. > + @param Value 32-bit value to write to Buffer. > + > + @return The 32-bit value to write to Buffer. > + > +**/ > +UINT32 > +EFIAPI > +WriteUnaligned32 ( > + OUT UINT32 *Buffer, > + IN UINT32 Value > + ) > +{ > + ASSERT (Buffer !=3D NULL); > + > + WriteUnaligned16 ((UINT16*)Buffer, (UINT16)Value); > + WriteUnaligned16 ((UINT16*)Buffer + 1, (UINT16)(Value >> 16)); > + return Value; > +} > + > +/** > + Reads a 64-bit value from memory that may be unaligned. > + > + This function returns the 64-bit value pointed to by Buffer. The funct= ion > + guarantees that the read operation does not produce an alignment fault= . > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 64-bit value that may be unaligned. > + > + @return The 64-bit value read from Buffer. > + > +**/ > +UINT64 > +EFIAPI > +ReadUnaligned64 ( > + IN CONST UINT64 *Buffer > + ) > +{ > + UINT32 LowerBytes; > + UINT32 HigherBytes; > + > + ASSERT (Buffer !=3D NULL); > + > + LowerBytes =3D ReadUnaligned32 ((UINT32*) Buffer); > + HigherBytes =3D ReadUnaligned32 ((UINT32*) Buffer + 1); > + > + return (UINT64) (LowerBytes | LShiftU64 (HigherBytes, 32)); > +} > + > +/** > + Writes a 64-bit value to memory that may be unaligned. > + > + This function writes the 64-bit value specified by Value to Buffer. Va= lue is > + returned. The function guarantees that the write operation does not > produce > + an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer The pointer to a 64-bit value that may be unaligned. > + @param Value 64-bit value to write to Buffer. > + > + @return The 64-bit value to write to Buffer. > + > +**/ > +UINT64 > +EFIAPI > +WriteUnaligned64 ( > + OUT UINT64 *Buffer, > + IN UINT64 Value > + ) > +{ > + ASSERT (Buffer !=3D NULL); > + > + WriteUnaligned32 ((UINT32*)Buffer, (UINT32)Value); > + WriteUnaligned32 ((UINT32*)Buffer + 1, (UINT32)RShiftU64 (Value, 32)); > + return Value; > +} > -- > 2.27.0 >=20 >=20 >=20 >=20 >=20