From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: hpe.com, ip: 148.163.143.35, mailfrom: prvs=01703bcc39=abner.chang@hpe.com) Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by groups.io with SMTP; Mon, 23 Sep 2019 18:53:33 -0700 Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id x8O1pi4i009854 for ; Tue, 24 Sep 2019 01:53:32 GMT Received: from g4t3427.houston.hpe.com (g4t3427.houston.hpe.com [15.241.140.73]) by mx0b-002e3701.pphosted.com with ESMTP id 2v6tjjpdve-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 24 Sep 2019 01:53:31 +0000 Received: from G9W8453.americas.hpqcorp.net (exchangepmrr1.us.hpecorp.net [16.216.160.211]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g4t3427.houston.hpe.com (Postfix) with ESMTPS id 8036C66 for ; Tue, 24 Sep 2019 01:53:31 +0000 (UTC) Received: from G9W8453.americas.hpqcorp.net (2002:10d8:a0d3::10d8:a0d3) by G9W8453.americas.hpqcorp.net (2002:10d8:a0d3::10d8:a0d3) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 24 Sep 2019 01:53:31 +0000 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (15.241.52.10) by G9W8453.americas.hpqcorp.net (16.216.160.211) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Tue, 24 Sep 2019 01:53:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZrEG/Csb7+1zaBqQJdJdCSGDXRD330khSZCM1Pi5NcM40HS7Ywy+m/Mzrp5GaHYhkBnlZRhj2kHG7x11y3iT4jmU67AK+hEOYT4oRA50m+C1XHBNfBQtHa0MSZpsoUz5+pPnBbaP9aRXRZGr+djC/J4PU6DLiLUmK7pZSTxCCvOykhEmCIEjO4iiXPUIwSeyZM2XTA8aLM8lzjDitteDhhxpAa+HOI9rZysx02CS9kAhuP4CHXZTKQYNuxeAQfaZDEQXxdL8Lro8XSl2mvaFkkxl5icIzr4366qh8VYGLUGWdI7zZx0CcgOJnRiVALhq2qCi8XOhgOcQcYxOXJb5ww== 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-SenderADCheck; bh=eUwuCRkB7ZrwMyIe8n5QBLrOaZsSclCouDXJCcEnZiE=; b=RVRAZDi24S5HYXnUobXmqPBA7WBR4tZM7ev1AWNH8jw479z1x0D2vgYAWUu0Gb15eqp/NNXlNoQt/jSrvdLjwEEzp9E9rU20mv+s6T/IyV7bJCEDHFQta+fDnmi8CHpUmuV4VsQ9apxLFd/b0pkuu3ngYzf78q8aZmvPCGjEd+XkCcKy4c1ludthADCH0krGnGM3CjE5gjDa8k6/pPMCwyNyR/eoYZ1Xpcwobf6pKYQkd2K51fH2meaAGCiOBkNyTNWK0bqw/BzlPfKK6MMsO7UfqBNg28fxXR4FZU6O55DFuwCpibOP+hJeVzTBuGFfDf5GQXJJfmrOsas0GhyDPQ== 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 CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM (10.169.12.151) by CS1PR8401MB0983.NAMPRD84.PROD.OUTLOOK.COM (10.169.16.18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2284.26; Tue, 24 Sep 2019 01:53:28 +0000 Received: from CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM ([fe80::4fb:84b9:76e6:1cde]) by CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM ([fe80::4fb:84b9:76e6:1cde%8]) with mapi id 15.20.2284.023; Tue, 24 Sep 2019 01:53:28 +0000 From: "Abner Chang" To: "devel@edk2.groups.io" , "Chang, Abner (HPS SW/FW Technologist)" CC: Liming Gao , Michael D Kinney Subject: Re: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 07/29] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor. Thread-Topic: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 07/29] MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor. Thread-Index: AQHVcaqkPO36pTijX0mTe1rLA0STV6c6EkgQ Date: Tue, 24 Sep 2019 01:53:28 +0000 Message-ID: References: <1569198715-31552-1-git-send-email-abner.chang@hpe.com> <15C6EB9950232DB5.29693@groups.io> In-Reply-To: <15C6EB9950232DB5.29693@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [16.242.247.131] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3690d4f8-4ab5-4ab2-7942-08d74091ff07 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600167)(711020)(4605104)(1401327)(4618075)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:CS1PR8401MB0983; x-ms-traffictypediagnostic: CS1PR8401MB0983: x-ms-exchange-purlcount: 1 x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:972; x-forefront-prvs: 0170DAF08C x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(366004)(396003)(136003)(39860400002)(346002)(199004)(189003)(13464003)(2906002)(71200400001)(9686003)(71190400001)(30864003)(229853002)(52536014)(110136005)(99286004)(14454004)(316002)(66066001)(478600001)(5660300002)(966005)(256004)(86362001)(6116002)(26005)(6246003)(4326008)(74316002)(102836004)(54906003)(25786009)(8936002)(81156014)(486006)(476003)(81166006)(33656002)(66556008)(446003)(6436002)(11346002)(8676002)(305945005)(66946007)(3846002)(2501003)(76176011)(6306002)(19627235002)(7696005)(14444005)(76116006)(66476007)(7736002)(53546011)(6506007)(55016002)(186003)(64756008)(66446008)(579004)(559001);DIR:OUT;SFP:1102;SCL:1;SRVR:CS1PR8401MB0983;H:CS1PR8401MB1192.NAMPRD84.PROD.OUTLOOK.COM;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: hpe.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: MagA0Mmu9oG0ASRn9eScl0Cak+zidjlkA6T/oL4LBeyC34JGy4CJYajwk3FsY8YMiojPaOZTtcMoM9W1Vlm4SIWfV86r+p7jPMuEf+gUtZKi1SVS/VEf6NTjX+rzH6hGTkxOGak0uGLebubpeUzGQKxjIbPMv35diBXH3WOA/ACVnS1GigBIUcEgxo37Z8R7z7pyhLfHkBgPUnzWvG6x2WAK3pwhoyD+LGupfNqqmHIXYtOrppUaT6LwOcDD2cQ1pElmdXc6HEWu16u+wHUxhO/CSq6jI8Lk200e/TPOhMaD3EvYmzS4xmbNxEes5dEQZ1JWbFXfo0hKTHbN9R9pQMbQEKbiimr3rL6zr2o/ca8crNrSXSNyG/5LcMVMX/nXWhGIPUvsWaoN2fehDW/KzdEfLuDE+TcWkOfboSHkfA0= X-MS-Exchange-CrossTenant-Network-Message-Id: 3690d4f8-4ab5-4ab2-7942-08d74091ff07 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2019 01:53:28.7840 (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: gndL4zRKYCCWYztT0GyVw74Utk82EnHfeYyaf42Rwrc3uy4bv8P1vuVFazjCH9nHPf4Ahu6Etr+a7tTACwmglw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CS1PR8401MB0983 X-OriginatorOrg: hpe.com X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,1.0.8 definitions=2019-09-23_10:2019-09-23,2019-09-23 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 phishscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-1908290000 definitions=main-1909240017 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable CC Maintainers. > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of > Abner Chang > Sent: Monday, September 23, 2019 8:32 AM > To: devel@edk2.groups.io > Cc: Chang, Abner (HPS SW/FW Technologist) > Subject: [edk2-devel] [edk2-staging/RISC-V-V2 PATCH v2 07/29] > MdePkg/BaseLib: BaseLib for RISC-V RV64 Processor. >=20 > Add RISC-V RV64 BaseLib functions. >=20 > Signed-off-by: Abner Chang > --- > MdePkg/Include/Library/BaseLib.h | 26 ++ > MdePkg/Library/BaseLib/BaseLib.inf | 18 +- > MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c | 27 +++ > MdePkg/Library/BaseLib/RiscV64/CpuPause.c | 29 +++ > MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c | 24 ++ > MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c | 25 ++ > MdePkg/Library/BaseLib/RiscV64/FlushCache.S | 21 ++ > MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c | 35 > +++ .../Library/BaseLib/RiscV64/InternalSwitchStack.c | 55 +++++ > MdePkg/Library/BaseLib/RiscV64/LongJump.c | 32 +++ > .../Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S | 14 ++ > MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S | 14 ++ > MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S | 32 +++ > .../Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S | 55 +++++ > MdePkg/Library/BaseLib/RiscV64/Unaligned.c | 264 > +++++++++++++++++++++ > 15 files changed, 670 insertions(+), 1 deletion(-) create mode 100644 > MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c > create mode 100644 MdePkg/Library/BaseLib/RiscV64/CpuPause.c > create mode 100644 MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c > create mode 100644 MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c > create mode 100644 MdePkg/Library/BaseLib/RiscV64/FlushCache.S > create mode 100644 MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c > create mode 100644 MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > create mode 100644 MdePkg/Library/BaseLib/RiscV64/LongJump.c > create mode 100644 > MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S > create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S > create mode 100644 MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S > create mode 100644 > MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S > create mode 100644 MdePkg/Library/BaseLib/RiscV64/Unaligned.c >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h > b/MdePkg/Include/Library/BaseLib.h > index 2a75bc0..b8c8512 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -4,6 +4,8 @@ >=20 > Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
> +Portions Copyright (c) 2016 - 2019, Hewlett Packard Enterprise > +Development LP. All rights reserved.
> + > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > **/ > @@ -124,6 +126,30 @@ typedef struct { >=20 > #endif // defined (MDE_CPU_AARCH64) >=20 > +#if defined (MDE_CPU_RISCV64) > +/// > +/// The RISC-V architecture context buffer used by SetJump() and > LongJump(). > +/// > +typedef struct { > + UINT64 RA; > + UINT64 S0; > + UINT64 S1; > + UINT64 S2; > + UINT64 S3; > + UINT64 S4; > + UINT64 S5; > + UINT64 S6; > + UINT64 S7; > + UINT64 S8; > + UINT64 S9; > + UINT64 S10; > + UINT64 S11; > + UINT64 SP; > +} BASE_LIBRARY_JUMP_BUFFER; > + > +#define BASE_LIBRARY_JUMP_BUFFER_ALIGNMENT 8 > + > +#endif // defined (MDE_CPU_RISCV64) >=20 > // > // String Services > diff --git a/MdePkg/Library/BaseLib/BaseLib.inf > b/MdePkg/Library/BaseLib/BaseLib.inf > index 3586beb..28d5795 100644 > --- a/MdePkg/Library/BaseLib/BaseLib.inf > +++ b/MdePkg/Library/BaseLib/BaseLib.inf > @@ -4,6 +4,7 @@ > # Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved. # > Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
= # > Portions copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
> +# Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > +rights reserved.
> # > # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -20,7 +21,7 @@ > LIBRARY_CLASS =3D BaseLib >=20 > # > -# VALID_ARCHITECTURES =3D IA32 X64 EBC ARM AARCH64 > +# VALID_ARCHITECTURES =3D IA32 X64 EBC ARM AARCH64 RISCV64 > # >=20 > [Sources] > @@ -381,6 +382,21 @@ > AArch64/CpuBreakpoint.asm | MSFT > AArch64/SpeculationBarrier.asm | MSFT >=20 > +[Sources.RISCV64] > + Math64.c > + RiscV64/Unaligned.c > + RiscV64/InternalSwitchStack.c > + RiscV64/CpuBreakpoint.c > + RiscV64/GetInterruptState.c > + RiscV64/DisableInterrupts.c > + RiscV64/EnableInterrupts.c > + RiscV64/CpuPause.c > + RiscV64/RiscVSetJumpLongJump.S | GCC > + RiscV64/RiscVCpuBreakpoint.S | GCC > + RiscV64/RiscVCpuPause.S | GCC > + RiscV64/RiscVInterrupt.S | GCC > + RiscV64/FlushCache.S | GCC > + > [Packages] > MdePkg/MdePkg.dec >=20 > diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c > b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c > new file mode 100644 > index 0000000..d82b1d5 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/CpuBreakpoint.c > @@ -0,0 +1,27 @@ > +/** @file > + CPU breakpoint for RISC-V > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ > + > +#include "BaseLibInternals.h" > + > +extern VOID RiscVCpuBreakpoint (VOID); > + > +/** > + 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. > + > +**/ > +VOID > +EFIAPI > +CpuBreakpoint ( > + VOID > + ) > +{ > + RiscVCpuBreakpoint (); > +} > diff --git a/MdePkg/Library/BaseLib/RiscV64/CpuPause.c > b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c > new file mode 100644 > index 0000000..8eb6b65 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/CpuPause.c > @@ -0,0 +1,29 @@ > +/** @file > + CPU pause for RISC-V > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ > + > +#include "BaseLibInternals.h" > + > +extern VOID RiscVCpuPause (VOID); > + > + > +/** > + Requests CPU to pause for a short period of time. > + > + Requests CPU to pause for a short period of time. Typically used in > + MP systems to prevent memory starvation while waiting for a spin lock= . > + > +**/ > +VOID > +EFIAPI > +CpuPause ( > + VOID > + ) > +{ > + RiscVCpuPause (); > +} > + > diff --git a/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c > b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c > new file mode 100644 > index 0000000..7ee5eb1 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/DisableInterrupts.c > @@ -0,0 +1,24 @@ > +/** @file > + CPU disable interrupt function for RISC-V > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include > +"BaseLibInternals.h" > + > +extern VOID RiscVDisableSupervisorModeInterrupts (VOID); > + > +/** > + Disables CPU interrupts. > + > +**/ > +VOID > +EFIAPI > +DisableInterrupts ( > + VOID > + ) > +{ > + RiscVDisableSupervisorModeInterrupts (); } > + > diff --git a/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c > b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c > new file mode 100644 > index 0000000..9aa0d9a > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/EnableInterrupts.c > @@ -0,0 +1,25 @@ > +/** @file > + CPU enable interrupt function for RISC-V > + > + Copyright (c) 2016-2019, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ > + > +#include "BaseLibInternals.h" > + > +extern VOID RiscVEnableSupervisorModeInterrupt (VOID); > + > +/** > + Enables CPU interrupts. > + > +**/ > +VOID > +EFIAPI > +EnableInterrupts ( > + VOID > + ) > +{ > + RiscVEnableSupervisorModeInterrupt (); } > + > diff --git a/MdePkg/Library/BaseLib/RiscV64/FlushCache.S > b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S > new file mode 100644 > index 0000000..0ef0213 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/FlushCache.S > @@ -0,0 +1,21 @@ > +//--------------------------------------------------------------------- > +--------- > +// > +// RISC-V cache operation. > +// > +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development > +LP. All rights reserved.
// // SPDX-License-Identifier: > +BSD-2-Clause-Patent // > +//--------------------------------------------------------------------- > +--------- > + > +.align 3 > +ASM_GLOBAL ASM_PFX(RiscVInvalidateInstCacheAsm) > +ASM_GLOBAL ASM_PFX(RiscVInvalidateDataCacheAsm) > + > +ASM_PFX(RiscVInvalidateInstCacheAsm): > + fence.i > + ret > + > +ASM_PFX(RiscVInvalidateDataCacheAsm): > + fence > + ret > diff --git a/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c > b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c > new file mode 100644 > index 0000000..8f764fb > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/GetInterruptState.c > @@ -0,0 +1,35 @@ > +/** @file > + CPU get interrupt state function for RISC-V > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ > + > +#include "BaseLibInternals.h" > + > +extern UINT32 RiscVGetSupervisorModeInterrupts (VOID); > + > +/** > + Retrieves the current CPU interrupt state. > + > + Returns TRUE is interrupts are currently enabled. Otherwise returns > + FALSE. > + > + @retval TRUE CPU interrupts are enabled. > + @retval FALSE CPU interrupts are disabled. > + > +**/ > +BOOLEAN > +EFIAPI > +GetInterruptState ( > + VOID > + ) > +{ > + unsigned long RetValue; > + > + RetValue =3D RiscVGetSupervisorModeInterrupts (); > + return RetValue? TRUE: FALSE; > +} > + > + > diff --git a/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > new file mode 100644 > index 0000000..1082d4e > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/InternalSwitchStack.c > @@ -0,0 +1,55 @@ > +/** @file > + Switch stack function for RISC-V > + > + Copyright (c) 2016, Hewlett Packard Enterprise Development LP. All > + rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ > + > +#include "BaseLibInternals.h" > + > +/** > + 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 > + specified by Context1 and Context2. Context1 and Context2 are > + optional and may be NULL. The function EntryPoint must never return. > + Marker will be ignored on IA-32, x64, and EBC. > + IPF CPUs expect one additional parameter of type VOID * that > + specifies the new backing store pointer. > + > + 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 EntryPo= int > + function. > + @param Context2 A pointer to the context to pass into the EntryPo= int > + function. > + @param NewStack A pointer to the new stack to use for the EntryPo= int > + 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; > + > + DEBUG ((DEBUG_INFO, "RISC-V InternalSwitchStack Entry:%x Context1:%x > Context2:%x NewStack%x\n", \ > + EntryPoint, Context1, Context2, NewStack)); > + JumpBuffer.RA =3D (UINTN)EntryPoint; > + JumpBuffer.SP =3D (UINTN)NewStack - sizeof (VOID *); > + JumpBuffer.S0 =3D (UINT64)(UINTN)Context1; > + JumpBuffer.S1 =3D (UINT64)(UINTN)Context2; > + LongJump (&JumpBuffer, (UINTN)-1); > + ASSERT(FALSE); > +} > diff --git a/MdePkg/Library/BaseLib/RiscV64/LongJump.c > b/MdePkg/Library/BaseLib/RiscV64/LongJump.c > new file mode 100644 > index 0000000..a62b882 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/LongJump.c > @@ -0,0 +1,32 @@ > +/** @file > + Long jump implementation of RISC-V > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent **/ > + > +#include "BaseLibInternals.h" > + > + > +/** > + Restores the CPU context that was saved with SetJump(). > + > + Restores the CPU context from the buffer specified by JumpBuffer. > + This function never returns to the caller. > + Instead is resumes execution based on the state of JumpBuffer. > + > + @param JumpBuffer A pointer to CPU context buffer. > + @param Value The value to return when the SetJump() context = is > restored. > + > +**/ > +VOID > +EFIAPI > +InternalLongJump ( > + IN BASE_LIBRARY_JUMP_BUFFER *JumpBuffer, > + IN UINTN Value > + ) > +{ > + ASSERT (FALSE); > +} > + > diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S > b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S > new file mode 100644 > index 0000000..1a45e2a > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuBreakpoint.S > @@ -0,0 +1,14 @@ > +//--------------------------------------------------------------------- > +--------- > +// > +// CpuBreakpoint for RISC-V > +// > +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development > +LP. All rights reserved.
// // SPDX-License-Identifier: > +BSD-2-Clause-Patent // > +//--------------------------------------------------------------------- > +--------- > + > +ASM_GLOBAL ASM_PFX(RiscVCpuBreakpoint) > +ASM_PFX(RiscVCpuBreakpoint): > + ebreak > + ret > diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S > b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S > new file mode 100644 > index 0000000..ceba0c0 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVCpuPause.S > @@ -0,0 +1,14 @@ > +//--------------------------------------------------------------------- > +--------- > +// > +// CpuPause for RISC-V > +// > +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development > +LP. All rights reserved.
// // SPDX-License-Identifier: > +BSD-2-Clause-Patent // > +//--------------------------------------------------------------------- > +--------- > + > +ASM_GLOBAL ASM_PFX(RiscVCpuPause) > +ASM_PFX(RiscVCpuPause): > + nop > + ret > diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S > b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S > new file mode 100644 > index 0000000..8fdb544 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVInterrupt.S > @@ -0,0 +1,32 @@ > +//--------------------------------------------------------------------- > +--------- > +// > +// RISC-V Supervisor Mode interrupt enable/disable // // Copyright (c) > +2016 - 2019, Hewlett Packard Enterprise Development LP. All rights > +reserved.
// // SPDX-License-Identifier: BSD-2-Clause-Patent // > +//--------------------------------------------------------------------- > +--------- > + > +ASM_GLOBAL ASM_PFX(RiscVDisableSupervisorModeInterrupts) > +ASM_GLOBAL ASM_PFX(RiscVEnableSupervisorModeInterrupt) > +ASM_GLOBAL ASM_PFX(RiscVGetSupervisorModeInterrupts) > + > +# define MSTATUS_SIE 0x00000002 > +# define CSR_SSTATUS 0x100 > + > +ASM_PFX(RiscVDisableSupervisorModeInterrupts): > + li a1, MSTATUS_SIE > + csrc CSR_SSTATUS, a1 > + ret > + > +ASM_PFX(RiscVEnableSupervisorModeInterrupt): > + li a1, MSTATUS_SIE > + csrs CSR_SSTATUS, a1 > + ret > + > +ASM_PFX(RiscVGetSupervisorModeInterrupts): > + csrr a0, CSR_SSTATUS > + andi a0, a0, MSTATUS_SIE > + ret > + > diff --git a/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S > b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S > new file mode 100644 > index 0000000..e72dd7f > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/RiscVSetJumpLongJump.S > @@ -0,0 +1,55 @@ > +//--------------------------------------------------------------------- > +--------- > +// > +// Set/Long jump for RISC-V > +// > +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development > +LP. All rights reserved.
// // SPDX-License-Identifier: > +BSD-2-Clause-Patent // > +//--------------------------------------------------------------------- > +--------- > +# define REG_S sd > +# define REG_L ld > +# define SZREG 8 > +.align 3 > + .globl SetJump > + > +SetJump: > + REG_S ra, 0*SZREG(a0) > + REG_S s0, 1*SZREG(a0) > + REG_S s1, 2*SZREG(a0) > + REG_S s2, 3*SZREG(a0) > + REG_S s3, 4*SZREG(a0) > + REG_S s4, 5*SZREG(a0) > + REG_S s5, 6*SZREG(a0) > + REG_S s6, 7*SZREG(a0) > + REG_S s7, 8*SZREG(a0) > + REG_S s8, 9*SZREG(a0) > + REG_S s9, 10*SZREG(a0) > + REG_S s10,11*SZREG(a0) > + REG_S s11,12*SZREG(a0) > + REG_S sp, 13*SZREG(a0) > + li a0, 0 > + ret > + > + .globl InternalLongJump > +InternalLongJump: > + REG_L ra, 0*SZREG(a0) > + REG_L s0, 1*SZREG(a0) > + REG_L s1, 2*SZREG(a0) > + REG_L s2, 3*SZREG(a0) > + REG_L s3, 4*SZREG(a0) > + REG_L s4, 5*SZREG(a0) > + REG_L s5, 6*SZREG(a0) > + REG_L s6, 7*SZREG(a0) > + REG_L s7, 8*SZREG(a0) > + REG_L s8, 9*SZREG(a0) > + REG_L s9, 10*SZREG(a0) > + REG_L s10,11*SZREG(a0) > + REG_L s11,12*SZREG(a0) > + REG_L sp, 13*SZREG(a0) > + > + add a0, s0, 0 > + add a1, s1, 0 > + add a2, s2, 0 > + add a3, s3, 0 > + ret > diff --git a/MdePkg/Library/BaseLib/RiscV64/Unaligned.c > b/MdePkg/Library/BaseLib/RiscV64/Unaligned.c > new file mode 100644 > index 0000000..012d913 > --- /dev/null > +++ b/MdePkg/Library/BaseLib/RiscV64/Unaligned.c > @@ -0,0 +1,264 @@ > +/** @file > + RISC-V specific functionality for (un)aligned memory read/write. > + > + Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP. > + All rights 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 > + function guarantees that the read operation does not produce an > alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A 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 > + ) > +{ > + UINT16 Value; > + INT8 Count; > + > + ASSERT (Buffer !=3D NULL); > + > + for (Count =3D sizeof (UINT16) - 1, Value =3D 0; Count >=3D 0 ; Count= --) { > + Value =3D Value << 8; > + Value |=3D *((UINT8*)Buffer + Count); > + } > + return Value; > +} > + > +/** > + Writes a 16-bit value to memory that may be unaligned. > + > + This function writes the 16-bit value specified by Value to Buffer. > + Value is returned. The function guarantees that the write operation > + does not produce an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A 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 > + ) > +{ > + INT8 Count; > + UINT16 ValueTemp; > + > + ASSERT (Buffer !=3D NULL); > + > + for (Count =3D 0, ValueTemp =3D Value; Count < sizeof (UINT16) ; Coun= t ++) { > + *((UINT8*)Buffer + Count) =3D (UINT8)(ValueTemp & 0xff); > + ValueTemp =3D ValueTemp >> 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 > + function guarantees that the read operation does not produce an > alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A 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 > + ) > +{ > + UINT32 Value; > + INT8 Count; > + > + ASSERT (Buffer !=3D NULL); > + for (Count =3D 2, Value =3D 0; Count >=3D 0 ; Count --) { > + Value =3D Value << 8; > + Value |=3D *((UINT8*)Buffer + Count); > + } > + return Value; > +} > + > +/** > + Writes a 24-bit value to memory that may be unaligned. > + > + This function writes the 24-bit value specified by Value to Buffer. > + Value is returned. The function guarantees that the write operation > + does not produce an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A 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 > + ) > +{ > + INT8 Count; > + UINT32 ValueTemp; > + > + ASSERT (Buffer !=3D NULL); > + for (Count =3D 0, ValueTemp =3D Value; Count < 3 ; Count ++) { > + *((UINT8*)Buffer + Count) =3D (UINT8)(ValueTemp & 0xff); > + ValueTemp =3D ValueTemp >> 8; > + } > + 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 > + function guarantees that the read operation does not produce an > alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A 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 > + ) > +{ > + UINT32 Value; > + INT8 Count; > + > + ASSERT (Buffer !=3D NULL); > + > + for (Count =3D sizeof (UINT32) - 1, Value =3D 0; Count >=3D 0 ; Count= --) { > + Value =3D Value << 8; > + Value |=3D *((UINT8*)Buffer + Count); > + } > + return Value; > +} > + > +/** > + Writes a 32-bit value to memory that may be unaligned. > + > + This function writes the 32-bit value specified by Value to Buffer. > + Value is returned. The function guarantees that the write operation > + does not produce an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A pointer to a 32-bit value that may be unaligned. > + @param Value The 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 > + ) > +{ > + INT8 Count; > + UINT32 ValueTemp; > + > + ASSERT (Buffer !=3D NULL); > + for (Count =3D 0, ValueTemp =3D Value; Count < sizeof (UINT32) ; Coun= t ++) { > + *((UINT8*)Buffer + Count) =3D (UINT8)(ValueTemp & 0xff); > + ValueTemp =3D ValueTemp >> 8; > + } > + 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 > + function guarantees that the read operation does not produce an > alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A 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 > + ) > +{ > + UINT64 Value; > + INT8 Count; > + > + ASSERT (Buffer !=3D NULL); > + for (Count =3D sizeof (UINT64) - 1, Value =3D 0; Count >=3D 0 ; Count= --) { > + Value =3D Value << 8; > + Value |=3D *((UINT8*)Buffer + Count); > + } > + return Value; > +} > + > +/** > + Writes a 64-bit value to memory that may be unaligned. > + > + This function writes the 64-bit value specified by Value to Buffer. > + Value is returned. The function guarantees that the write operation > + does not produce an alignment fault. > + > + If the Buffer is NULL, then ASSERT(). > + > + @param Buffer A pointer to a 64-bit value that may be unaligned. > + @param Value The 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 > + ) > +{ > + INT8 Count; > + UINT64 ValueTemp; > + > + ASSERT (Buffer !=3D NULL); > + for (Count =3D 0, ValueTemp =3D Value; Count < sizeof (UINT64) ; Coun= t ++) { > + *((UINT8*)Buffer + Count) =3D (UINT8)(ValueTemp & 0xff); > + ValueTemp =3D ValueTemp >> 8; > + } > + return Value; > +} > -- > 2.7.4 >=20 >=20 >=20