From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (NAM10-BN7-obe.outbound.protection.outlook.com [40.107.92.74]) by mx.groups.io with SMTP id smtpd.web10.29941.1665929193318731579 for ; Sun, 16 Oct 2022 07:06:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@amd.com header.s=selector1 header.b=ARprrYC8; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.92.74, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bzOtwyJ7CVGSngUSTj725dlYLIEoQrgSfZjy2tbEw7wAZy2fhwvMVaDZW1Ul0KTtEE0RrUzPVPMw3gsP/Ruu+EL4ItKTYgapk2CAp2kMMsVluV7aiWf0ODINq6UgaFXpXDpkO9UX7RCkFPC4OsdJYTezKrJL0/iG3tlIS6xG9pxsUXaNq5MEs2BDytWWY89Fgh2DiQi4qFfjd2rotoI9S4c/geYHZRCILPWYhy1V6UHxEIfsli5qTJgyvxS7haqSN7o/3QH9vC/SQGgvBxQKnUjRavlr1jAmEGb65y33NOaT1TxJzchapzhbBcz8DEBM6CGYSjiy6eNWS8W5av/1Sg== 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=20OvPv5zHbBSWz0EMRxon476rdnn0dUtgNMBG+h/R78=; b=PIBGKCP4C4JRgFJQgpPF/SJ1cshsFgTLVbsSEGd2b1XaQ5HeKCe6PzZEMxPQNwipCYe4Nfg7xoskwdwS2YEd/YhU8UbHJCuQfdNMMM+e7EgawNOKtYJe4dQ4rsQHXgdu+2iUAKnvhHawg/irPxz87VoVal9lUx3olF9bOBYqxDfRWQr0r29fpZkuCSiMEgNOiDzSEIDwYenhO5kljLwx3rF9y8GjQkKxQk021FlR1Fpy4jRKmgXnL3Pdxz9FCYyCltzTY65L03gS9VaIlMk99ldGy9AOH1SCkyvh+HQq2ruXkfxs85U+LCqOHZ4j9j+ZfM069A8TIn+dUsBhDbbrtA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=20OvPv5zHbBSWz0EMRxon476rdnn0dUtgNMBG+h/R78=; b=ARprrYC8EMKzTU41cnIEeuOgiTnViyya0E/fMhYOR8CU5dq/lqNW1ZZxiE7PjdrojAdjKG6SK9yjRzv+orbZvfdzQVs5f8WspK3Vane9tmgDmtDcC8Ng8XcXssRGUaU65SkgkMhG1lPTjgFE1m3Uj3ah4ItUoj1yuJiUZHj/KiI= Received: from MN2PR12MB3966.namprd12.prod.outlook.com (2603:10b6:208:165::18) by BL1PR12MB5377.namprd12.prod.outlook.com (2603:10b6:208:31f::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5723.30; Sun, 16 Oct 2022 14:06:30 +0000 Received: from MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::2eab:b851:827c:1d88]) by MN2PR12MB3966.namprd12.prod.outlook.com ([fe80::2eab:b851:827c:1d88%3]) with mapi id 15.20.5723.032; Sun, 16 Oct 2022 14:06:30 +0000 From: "Chang, Abner" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Eric Dong , Ray Ni , Rahul Kumar , Daniel Schaefer Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 16/34] UefiCpuPkg/CpuExceptionHandlerLib: Add support for RISC-V Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 16/34] UefiCpuPkg/CpuExceptionHandlerLib: Add support for RISC-V Thread-Index: AQHY3+0iZe7z3KnYlECjnOh+bRkBwK4RERag Date: Sun, 16 Oct 2022 14:06:30 +0000 Message-ID: References: <20221014164836.1513036-1-sunilvl@ventanamicro.com> <20221014164836.1513036-17-sunilvl@ventanamicro.com> In-Reply-To: <20221014164836.1513036-17-sunilvl@ventanamicro.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: msip_labels: MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Enabled=true; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SetDate=2022-10-16T14:06:28Z; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Method=Standard; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_Name=General; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_SiteId=3dd8961f-e488-4e60-8e11-a82d994e183d; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ActionId=69faeaf2-5aaf-4c02-95ac-45ebdaedb7e3; MSIP_Label_4342314e-0df4-4b58-84bf-38bed6170a0f_ContentBits=1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN2PR12MB3966:EE_|BL1PR12MB5377:EE_ x-ms-office365-filtering-correlation-id: c8ba4917-d5b6-4974-506e-08daaf7f9ffc x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Uji6FIhGiON2i7SSJe3Y5CrME6S6/hGrNdUhHtNDgjFOAM/Pco6zjbnwPIcsadaZa1KiL6cz/w8AHRCCoZwQHOUEJR0TQMw4wJZEIoO8HaWtpfUAFwZZ8fUts1qX2lK0/2LLhCDp9+UhoDbONr8jlkdqo46cuofq+cIGum92PtzCzV/5fD7gIzfwFDkHA5I4z4LVOgisCVhec29B3gosgne034O9PQQ5FYHmP52hBp4hRP5iUgQbwoGBO2f87YAyR+l/pzcgNKGHNMLv7acgg8RNibrM60GZL8OSe3/ZN+1+i5gRPujLimrBA3Rb22gVKG8iEbMrSzrJjYA7OYS/JiRBj0tGn0dhgb3XRsXSRc69RGfCtuyNgJbtmJHgkqQ/zT7svFMsGbZU5hNc0vCPsITc1H9/AkPDT2cSIXlQSbzdEN3PU10Vm6U+hravlcMvti+YvKeoGSHaQxfHfVRfRTzGx1lU6asueYObIMa2nGVeb3mar0LYetjqJYDylMCugBJNwCFv7Rr+/7w6Gep6ZY8L0fIw4WE2EdP9gGAPc/2enwzsIvNqyqdV3d0o3xbc6YNCcAi3FeeY3mYpNQk79C6rRZjFRoGNlqoeFgOIK+paK1LgfFGhOOP1Sutzd+Dfm6SAqyEI8Jwv/FzGJdi3tgW7q+sI5SXKPpMnAsny+gM3uQUja2jhurO92ghqiEkCdV7oM8+hSGRokQA9I/WSrsovwBo1G67ZU08EZa/MMPEza8mfRmD3JIDQxCiqGs6732LdY/yzKJlLLWV3zr6v1V+kuafb2SbdpwzjAeZenRGttASb+d47xgCHc8CZRk9w3/RKKgmskbkRoOMl3WU4Dw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN2PR12MB3966.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(346002)(136003)(396003)(366004)(39860400002)(376002)(451199015)(110136005)(66899015)(5660300002)(30864003)(64756008)(66446008)(66476007)(8676002)(316002)(19627235002)(54906003)(478600001)(9686003)(66556008)(7696005)(45080400002)(6506007)(26005)(53546011)(52536014)(41300700001)(71200400001)(186003)(2906002)(4326008)(966005)(8936002)(38070700005)(83380400001)(38100700002)(66946007)(76116006)(122000001)(55016003)(86362001)(33656002);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?5dN+q+qzdCJv/urZAMksEWnjR+nXoKW3FP7Q1EHYxygCgKQT3pr3YwX4Yft9?= =?us-ascii?Q?fd2ma5rVdVK1oJ8xIFukWleQfhwXQSIc06hCo8PGjJoMvM/2epVdgKFdIeGs?= =?us-ascii?Q?rEhmL+AZhRia15klvvBzvVkhfrMPovEM3GDaj0+mRjgXO2ZR0+UBFMTrg8D4?= =?us-ascii?Q?PH86+V8MIr9XMDgMoJDLvNIjrxCV6BIeZS1pkFuFi5c0j+WIOkh9y8vCZymo?= =?us-ascii?Q?GouEvyiU/yxksVdt1Ov4aMvlGrnKvUKbhsLAsGfTx0WBh50uAc7RH01nOvBa?= =?us-ascii?Q?3OLAT7SC8iT6mv/NBTWzGJjrO+BQoEPM7fWRFUdoaOrkyfnLbvczu97Xwfgt?= =?us-ascii?Q?L4ijsmThbgI+TX/UsNhkluY6SYLLlahUghaQe/mSKRwNNrtGgS3OjmI9T9Ep?= =?us-ascii?Q?Ck0OGIPKYA1DtlyW/OyypGNFXth0n/U8SwMOO6KPpgUW51lO5y6oroT2CvT8?= =?us-ascii?Q?+mmZJOS0sEtWZT5/MoMvdY8FWbU3siLofwi6UZSnvd/PWAdj8+xl5p0x9UA6?= =?us-ascii?Q?MsQzvWJ1ZP22sF6ydiWVw8DOsKYZlaqHFAV82C7Y5wxlZ9JRyQhEH+8oV0/g?= =?us-ascii?Q?/vk+C4xhmJLySjABYMeVAYNbkUYC+yyJVfo8gMXG6TCtTzxMpYV6U4L2HjQ+?= =?us-ascii?Q?00f8v5RhqOV+OT09XXvgZpFO+1qN6mkJkmyyLak8bn3TJeFoWA1T/vg2OlF9?= =?us-ascii?Q?exFClTAtjGq//4WC6ARUs6xn8ouAnGVNxYSn7XJcKPWTJQwrMV9h/Y90NCgC?= =?us-ascii?Q?ErlfuIG/ls+Xi3SIPFxqUot6uOeNq0Awk3aMevoKcknKr1mnXop3S/DIjxUm?= =?us-ascii?Q?+gP7JMbgKlmjFr8Kpmxs1BvwqkSg3eW29ZHC1nkb+0QLYVK+/pyu5ShhuPE7?= =?us-ascii?Q?yoRD510u7fjhyL5FNhuH4NISKo6VxLDKr1G55/d3VvJnnTFd7j647TsKqvgI?= =?us-ascii?Q?ZSqOTAhi1eDz0MWu6Xn2ywra7zDOFzDVNAT1jC39cIXIrl/JKk7DDM0aj01q?= =?us-ascii?Q?pPm3rKbvVoJVyQAt1NL0ETl/+ArFA77F3jbNuPsSoaUovDYV2A5VdvY7IwsU?= =?us-ascii?Q?IyTaMzRblE6gQzB25LFkqe1zcbubEjmeb0QIC1/gipUJvLyvPozIcO6d62Lf?= =?us-ascii?Q?qVugh47hAfxgN2o4bp1jHHPGnmP5NmnqGXKRqg/607M6rsZ+j2KKjABpeVdX?= =?us-ascii?Q?qfaWKBabumlH3lvB15VRBEYLI8NPXtAr0F1o+26CTGvZQs56Pa2GmN8AVGKZ?= =?us-ascii?Q?svuL0SY1eCu63IL7zl9HkEHdcMDsSTmA8KBSQB13Erp+SaX8yq7Ky+wslpAn?= =?us-ascii?Q?/bu/qEiNjSPXa6qDBpyTbtftmR7yAXkkzqr2z+ETUjQBxTwFN8O316pYuW+l?= =?us-ascii?Q?KSPaiyP6AKL+GddphPh0iQX3IGXmsOpz10PtI5DsW8JbJt+OdMCw4LMjdPjd?= =?us-ascii?Q?a9r1SrdV6Hpb+PUuqTYNu0FKEcEJihdf2MC/h6kV8c19VywIpVVFNnGU8aJq?= =?us-ascii?Q?27rBnC3NOuDUVfVfBwZ2ydAs2QwCYAwv1ZAt1pQcInuAZVyL91YuZwUcO7sp?= =?us-ascii?Q?Cr7UH07+Y+RMkmHXRb8U7M+O+o+cG7dZmyYVgdbx?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN2PR12MB3966.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8ba4917-d5b6-4974-506e-08daaf7f9ffc X-MS-Exchange-CrossTenant-originalarrivaltime: 16 Oct 2022 14:06:30.5854 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VngeRc7Pv70yJoLVz++ts6+TO0EKZTGTqpUF4cBEJvnzECc7vo+pFROlblRrZEwuXrj4p9TXWrHhXna0LHiIWw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5377 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable [AMD Official Use Only - General] Acked-by: Abner Chang However, this one has the dependency with 15/34. > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > via groups.io > Sent: Saturday, October 15, 2022 12:48 AM > To: devel@edk2.groups.io > Cc: Eric Dong ; Ray Ni ; Rahul > Kumar ; Daniel Schaefer > > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V4 16/34] > UefiCpuPkg/CpuExceptionHandlerLib: Add support for RISC-V >=20 > Caution: This message originated from an External Source. Use proper > caution when opening attachments, clicking links, or responding. >=20 >=20 > REF: > https://nam11.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F%2Fbugz > illa.tianocore.org%2Fshow_bug.cgi%3Fid%3D4076&data=3D05%7C01%7Ca > bner.chang%40amd.com%7C5f84890c5ca74c00184608daae044414%7C3dd896 > 1fe4884e608e11a82d994e183d%7C0%7C0%7C638013630593336705%7CUnkn > own%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik > 1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=3DY4Sz1pulv2MG > WHhlTIKf1w88MZR1d%2Bub5DPMksFV1Nc%3D&reserved=3D0 >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Daniel Schaefer > Signed-off-by: Sunil V L > --- >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.in > f | 7 +- >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandlerLib > .inf | 7 +- >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerL > ib.h | 116 +++++++++++++++++ > UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerL > ib.c | 133 ++++++++++++++++++++ > UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHandle > r.S | 105 ++++++++++++++++ > 5 files changed, 366 insertions(+), 2 deletions(-) >=20 > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib. > inf > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib > .inf > index 8fdf2b756c2c..b24140d1f26b 100644 > --- > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib. > inf > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLi > +++ b.inf > @@ -18,7 +18,7 @@ [Defines] > # > # The following information is for reference only and not required by th= e > build tools. > # > -# VALID_ARCHITECTURES =3D IA32 X64 > +# VALID_ARCHITECTURES =3D IA32 X64 RISCV64 > # >=20 > [Sources.Ia32] > @@ -38,6 +38,11 @@ [Sources.IA32, Sources.X64] > Ia32X64/PeiDxeSmmCpuException.c > Ia32X64/DxeException.c >=20 > +[Sources.RISCV64] > + RiscV64/SupervisorTrapHandler.S > + RiscV64/CpuExceptionHandlerLib.c > + RiscV64/CpuExceptionHandlerLib.h > + > [Pcd] > gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard > gUefiCpuPkgTokenSpaceGuid.PcdCpuStackSwitchExceptionList > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler > Lib.inf > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler > Lib.inf > index 79911b21f62d..60c92ecf65bf 100644 > --- > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandler > Lib.inf > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/SecPeiCpuExceptionHandle > +++ rLib.inf > @@ -18,7 +18,7 @@ [Defines] > # > # The following information is for reference only and not required by th= e > build tools. > # > -# VALID_ARCHITECTURES =3D IA32 X64 > +# VALID_ARCHITECTURES =3D IA32 X64 RISCV64 > # >=20 > [Sources.Ia32] > @@ -37,6 +37,11 @@ [Sources.IA32, Sources.X64] > Ia32X64/CpuExceptionCommon.c > Ia32X64/SecPeiCpuException.c >=20 > +[Sources.RISCV64] > + RiscV64/SupervisorTrapHandler.S > + RiscV64/CpuExceptionHandlerLib.c > + RiscV64/CpuExceptionHandlerLib.h > + > [Packages] > MdePkg/MdePkg.dec > MdeModulePkg/MdeModulePkg.dec > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandl > erLib.h > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandl > erLib.h > new file mode 100644 > index 000000000000..30f47e87552b > --- /dev/null > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHand > +++ lerLib.h > @@ -0,0 +1,116 @@ > +/** @file > + > + RISC-V Exception Handler library definition file. > + > + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#ifndef RISCV_CPU_EXECPTION_HANDLER_LIB_H_ > +#define RISCV_CPU_EXECPTION_HANDLER_LIB_H_ > + > +#include > + > +/** > + Trap Handler for S-mode > + > +**/ > +VOID > +SupervisorModeTrap ( > + VOID > + ); > + > +// > +// Index of SMode trap register > +// > +#define SMODE_TRAP_REGS_zero 0 > +#define SMODE_TRAP_REGS_ra 1 > +#define SMODE_TRAP_REGS_sp 2 > +#define SMODE_TRAP_REGS_gp 3 > +#define SMODE_TRAP_REGS_tp 4 > +#define SMODE_TRAP_REGS_t0 5 > +#define SMODE_TRAP_REGS_t1 6 > +#define SMODE_TRAP_REGS_t2 7 > +#define SMODE_TRAP_REGS_s0 8 > +#define SMODE_TRAP_REGS_s1 9 > +#define SMODE_TRAP_REGS_a0 10 > +#define SMODE_TRAP_REGS_a1 11 > +#define SMODE_TRAP_REGS_a2 12 > +#define SMODE_TRAP_REGS_a3 13 > +#define SMODE_TRAP_REGS_a4 14 > +#define SMODE_TRAP_REGS_a5 15 > +#define SMODE_TRAP_REGS_a6 16 > +#define SMODE_TRAP_REGS_a7 17 > +#define SMODE_TRAP_REGS_s2 18 > +#define SMODE_TRAP_REGS_s3 19 > +#define SMODE_TRAP_REGS_s4 20 > +#define SMODE_TRAP_REGS_s5 21 > +#define SMODE_TRAP_REGS_s6 22 > +#define SMODE_TRAP_REGS_s7 23 > +#define SMODE_TRAP_REGS_s8 24 > +#define SMODE_TRAP_REGS_s9 25 > +#define SMODE_TRAP_REGS_s10 26 > +#define SMODE_TRAP_REGS_s11 27 > +#define SMODE_TRAP_REGS_t3 28 > +#define SMODE_TRAP_REGS_t4 29 > +#define SMODE_TRAP_REGS_t5 30 > +#define SMODE_TRAP_REGS_t6 31 > +#define SMODE_TRAP_REGS_sepc 32 > +#define SMODE_TRAP_REGS_sstatus 33 > +#define SMODE_TRAP_REGS_sie 34 > +#define SMODE_TRAP_REGS_last 35 > + > +#define SMODE_TRAP_REGS_OFFSET(x) ((SMODE_TRAP_REGS_##x) * > +__SIZEOF_POINTER__) #define SMODE_TRAP_REGS_SIZE > +SMODE_TRAP_REGS_OFFSET(last) > + > +#pragma pack(1) > +typedef struct { > + // > + // Below are follow the format of EFI_SYSTEM_CONTEXT > + // > + UINT64 zero; > + UINT64 ra; > + UINT64 sp; > + UINT64 gp; > + UINT64 tp; > + UINT64 t0; > + UINT64 t1; > + UINT64 t2; > + UINT64 s0; > + UINT64 s1; > + UINT64 a0; > + UINT64 a1; > + UINT64 a2; > + UINT64 a3; > + UINT64 a4; > + UINT64 a5; > + UINT64 a6; > + UINT64 a7; > + UINT64 s2; > + UINT64 s3; > + UINT64 s4; > + UINT64 s5; > + UINT64 s6; > + UINT64 s7; > + UINT64 s8; > + UINT64 s9; > + UINT64 s10; > + UINT64 s11; > + UINT64 t3; > + UINT64 t4; > + UINT64 t5; > + UINT64 t6; > + // > + // Below are the additional information to > + // EFI_SYSTEM_CONTEXT, private to supervisor mode trap > + // and not public to EFI environment. > + // > + UINT64 sepc; > + UINT64 sstatus; > + UINT64 sie; > +} SMODE_TRAP_REGISTERS; > +#pragma pack() > + > +#endif > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandl > erLib.c > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandl > erLib.c > new file mode 100644 > index 000000000000..f1ee7d236aec > --- /dev/null > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHand > +++ lerLib.c > @@ -0,0 +1,133 @@ > +/** @file > + RISC-V Exception Handler library implementation. > + > + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. > + All rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include > +#include > +#include > +#include > + > +#include "CpuExceptionHandlerLib.h" > + > +STATIC EFI_CPU_INTERRUPT_HANDLER mInterruptHandlers[2]; > + > +/** > + Initializes all CPU exceptions entries and provides the default except= ion > handlers. > + > + Caller should try to get an array of interrupt and/or exception > + vectors that are in use and need to persist by > EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification. > + If caller cannot get reserved vector list or it does not exists, set V= ectorInfo > to NULL. > + If VectorInfo is not NULL, the exception vectors will be initialized p= er > vector attribute accordingly. > + > + @param[in] VectorInfo Pointer to reserved vector list. > + > + @retval EFI_SUCCESS CPU Exception Entries have been successf= ully > initialized > + with default exception handlers. > + @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content > if VectorInfo is not NULL. > + @retval EFI_UNSUPPORTED This function is not supported. > + > +**/ > +EFI_STATUS > +EFIAPI > +InitializeCpuExceptionHandlers ( > + IN EFI_VECTOR_HANDOFF_INFO *VectorInfo OPTIONAL > + ) > +{ > + RiscVSetSupervisorStvec ((UINT64)SupervisorModeTrap); > + return EFI_SUCCESS; > +} > + > +/** > + Registers a function to be called from the processor interrupt handler= . > + > + This function registers and enables the handler specified by > + InterruptHandler for a processor interrupt or exception type > + specified by InterruptType. If InterruptHandler is NULL, then the hand= ler > for the processor interrupt or exception type specified by InterruptType = is > uninstalled. > + The installed handler is called once for each processor interrupt or > exception. > + NOTE: This function should be invoked after > + InitializeCpuExceptionHandlers() or > + InitializeCpuInterruptHandlers() invoked, otherwise EFI_UNSUPPORTED > returned. > + > + @param[in] InterruptType Defines which interrupt or exception to = hook. > + @param[in] InterruptHandler A pointer to a function of type > EFI_CPU_INTERRUPT_HANDLER that is called > + when a processor interrupt occurs. If th= is parameter is NULL, > then the handler > + will be uninstalled. > + > + @retval EFI_SUCCESS The handler for the processor interrupt = was > successfully installed or uninstalled. > + @retval EFI_ALREADY_STARTED InterruptHandler is not NULL, and a > handler for InterruptType was > + previously installed. > + @retval EFI_INVALID_PARAMETER InterruptHandler is NULL, and a handler > for InterruptType was not > + previously installed. > + @retval EFI_UNSUPPORTED The interrupt specified by InterruptType= is > not supported, > + or this function is not supported. > +**/ > +EFI_STATUS > +EFIAPI > +RegisterCpuInterruptHandler ( > + IN EFI_EXCEPTION_TYPE InterruptType, > + IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler > + ) > +{ > + DEBUG ((DEBUG_INFO, "%a: Type:%x Handler: %x\n", __FUNCTION__, > +InterruptType, InterruptHandler)); > + mInterruptHandlers[InterruptType] =3D InterruptHandler; > + return EFI_SUCCESS; > +} > + > +/** > + Setup separate stacks for certain exception handlers. > + If the input Buffer and BufferSize are both NULL, use global variable = if > possible. > + > + @param[in] Buffer Point to buffer used to separate except= ion stack. > + @param[in, out] BufferSize On input, it indicates the byte size of= Buffer. > + If the size is not enough, the return s= tatus will > + be EFI_BUFFER_TOO_SMALL, and output Buf= ferSize > + will be the size it needs. > + > + @retval EFI_SUCCESS The stacks are assigned successfully. > + @retval EFI_UNSUPPORTED This function is not supported. > + @retval EFI_BUFFER_TOO_SMALL This BufferSize is too small. > +**/ > +EFI_STATUS > +EFIAPI > +InitializeSeparateExceptionStacks ( > + IN VOID *Buffer, > + IN OUT UINTN *BufferSize > + ) > +{ > + return EFI_SUCCESS; > +} > + > +/** > + Supervisor mode trap handler. > + > + @param[in] SmodeTrapReg Registers before trap occurred. > + > +**/ > +VOID > +RiscVSupervisorModeTrapHandler ( > + SMODE_TRAP_REGISTERS *SmodeTrapReg > + ) > +{ > + UINTN SCause; > + EFI_SYSTEM_CONTEXT RiscVSystemContext; > + > + RiscVSystemContext.SystemContextRiscV64 =3D > (EFI_SYSTEM_CONTEXT_RISCV64 > +*)SmodeTrapReg; > + // > + // Check scasue register. > + // > + SCause =3D (UINTN)RiscVGetSupervisorTrapCause (); > + if ((SCause & (1UL << (sizeof (UINTN) * 8- 1))) !=3D 0) { > + // > + // This is interrupt event. > + // > + SCause &=3D ~(1UL << (sizeof (UINTN) * 8- 1)); > + if ((SCause =3D=3D IRQ_S_TIMER) && > (mInterruptHandlers[EXCEPT_RISCV_TIMER_INT] !=3D NULL)) { > + > mInterruptHandlers[EXCEPT_RISCV_TIMER_INT](EXCEPT_RISCV_TIMER_INT, > RiscVSystemContext); > + } > + } > +} > diff --git > a/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHand > ler.S > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHand > ler.S > new file mode 100644 > index 000000000000..649c4c5becf4 > --- /dev/null > +++ > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHa > +++ ndler.S > @@ -0,0 +1,105 @@ > +/** @file > + RISC-V Processor supervisor mode trap handler > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All > + rights reserved.
> + > + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > +#include "CpuExceptionHandlerLib.h" > + > + .align 3 > + .section .entry, "ax", %progbits > + .globl SupervisorModeTrap > +SupervisorModeTrap: > + addi sp, sp, -SMODE_TRAP_REGS_SIZE > + > + /* Save all general regisers except SP */ > + sd t0, SMODE_TRAP_REGS_OFFSET(t0)(sp) > + > + csrr t0, CSR_SSTATUS > + and t0, t0, (SSTATUS_SIE | SSTATUS_SPIE) > + sd t0, SMODE_TRAP_REGS_OFFSET(sstatus)(sp) > + csrr t0, CSR_SEPC > + sd t0, SMODE_TRAP_REGS_OFFSET(sepc)(sp) > + csrr t0, CSR_SIE > + sd t0, SMODE_TRAP_REGS_OFFSET(sie)(sp) > + ld t0, SMODE_TRAP_REGS_OFFSET(t0)(sp) > + > + sd ra, SMODE_TRAP_REGS_OFFSET(ra)(sp) > + sd gp, SMODE_TRAP_REGS_OFFSET(gp)(sp) > + sd tp, SMODE_TRAP_REGS_OFFSET(tp)(sp) > + sd t1, SMODE_TRAP_REGS_OFFSET(t1)(sp) > + sd t2, SMODE_TRAP_REGS_OFFSET(t2)(sp) > + sd s0, SMODE_TRAP_REGS_OFFSET(s0)(sp) > + sd s1, SMODE_TRAP_REGS_OFFSET(s1)(sp) > + sd a0, SMODE_TRAP_REGS_OFFSET(a0)(sp) > + sd a1, SMODE_TRAP_REGS_OFFSET(a1)(sp) > + sd a2, SMODE_TRAP_REGS_OFFSET(a2)(sp) > + sd a3, SMODE_TRAP_REGS_OFFSET(a3)(sp) > + sd a4, SMODE_TRAP_REGS_OFFSET(a4)(sp) > + sd a5, SMODE_TRAP_REGS_OFFSET(a5)(sp) > + sd a6, SMODE_TRAP_REGS_OFFSET(a6)(sp) > + sd a7, SMODE_TRAP_REGS_OFFSET(a7)(sp) > + sd s2, SMODE_TRAP_REGS_OFFSET(s2)(sp) > + sd s3, SMODE_TRAP_REGS_OFFSET(s3)(sp) > + sd s4, SMODE_TRAP_REGS_OFFSET(s4)(sp) > + sd s5, SMODE_TRAP_REGS_OFFSET(s5)(sp) > + sd s6, SMODE_TRAP_REGS_OFFSET(s6)(sp) > + sd s7, SMODE_TRAP_REGS_OFFSET(s7)(sp) > + sd s8, SMODE_TRAP_REGS_OFFSET(s8)(sp) > + sd s9, SMODE_TRAP_REGS_OFFSET(s9)(sp) > + sd s10, SMODE_TRAP_REGS_OFFSET(s10)(sp) > + sd s11, SMODE_TRAP_REGS_OFFSET(s11)(sp) > + sd t3, SMODE_TRAP_REGS_OFFSET(t3)(sp) > + sd t4, SMODE_TRAP_REGS_OFFSET(t4)(sp) > + sd t5, SMODE_TRAP_REGS_OFFSET(t5)(sp) > + sd t6, SMODE_TRAP_REGS_OFFSET(t6)(sp) > + > + /* Call to Supervisor mode trap handler in CpuExceptionHandlerLib.c > + */ call RiscVSupervisorModeTrapHandler > + > + /* Restore all general regisers except SP */ > + ld ra, SMODE_TRAP_REGS_OFFSET(ra)(sp) > + ld gp, SMODE_TRAP_REGS_OFFSET(gp)(sp) > + ld tp, SMODE_TRAP_REGS_OFFSET(tp)(sp) > + ld t2, SMODE_TRAP_REGS_OFFSET(t2)(sp) > + ld s0, SMODE_TRAP_REGS_OFFSET(s0)(sp) > + ld s1, SMODE_TRAP_REGS_OFFSET(s1)(sp) > + ld a0, SMODE_TRAP_REGS_OFFSET(a0)(sp) > + ld a1, SMODE_TRAP_REGS_OFFSET(a1)(sp) > + ld a2, SMODE_TRAP_REGS_OFFSET(a2)(sp) > + ld a3, SMODE_TRAP_REGS_OFFSET(a3)(sp) > + ld a4, SMODE_TRAP_REGS_OFFSET(a4)(sp) > + ld a5, SMODE_TRAP_REGS_OFFSET(a5)(sp) > + ld a6, SMODE_TRAP_REGS_OFFSET(a6)(sp) > + ld a7, SMODE_TRAP_REGS_OFFSET(a7)(sp) > + ld s2, SMODE_TRAP_REGS_OFFSET(s2)(sp) > + ld s3, SMODE_TRAP_REGS_OFFSET(s3)(sp) > + ld s4, SMODE_TRAP_REGS_OFFSET(s4)(sp) > + ld s5, SMODE_TRAP_REGS_OFFSET(s5)(sp) > + ld s6, SMODE_TRAP_REGS_OFFSET(s6)(sp) > + ld s7, SMODE_TRAP_REGS_OFFSET(s7)(sp) > + ld s8, SMODE_TRAP_REGS_OFFSET(s8)(sp) > + ld s9, SMODE_TRAP_REGS_OFFSET(s9)(sp) > + ld s10, SMODE_TRAP_REGS_OFFSET(s10)(sp) > + ld s11, SMODE_TRAP_REGS_OFFSET(s11)(sp) > + ld t3, SMODE_TRAP_REGS_OFFSET(t3)(sp) > + ld t4, SMODE_TRAP_REGS_OFFSET(t4)(sp) > + ld t5, SMODE_TRAP_REGS_OFFSET(t5)(sp) > + ld t6, SMODE_TRAP_REGS_OFFSET(t6)(sp) > + > + ld t0, SMODE_TRAP_REGS_OFFSET(sepc)(sp) > + csrw CSR_SEPC, t0 > + ld t0, SMODE_TRAP_REGS_OFFSET(sie)(sp) > + csrw CSR_SIE, t0 > + csrr t0, CSR_SSTATUS > + ld t1, SMODE_TRAP_REGS_OFFSET(sstatus)(sp) > + or t0, t0, t1 > + csrw CSR_SSTATUS, t0 > + ld t1, SMODE_TRAP_REGS_OFFSET(t1)(sp) > + ld t0, SMODE_TRAP_REGS_OFFSET(t0)(sp) > + addi sp, sp, SMODE_TRAP_REGS_SIZE > + sret > -- > 2.38.0 >=20 >=20 >=20 >=20 >=20