From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.13815.1676033677923413833 for ; Fri, 10 Feb 2023 04:54:38 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=QGgq4E8F; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: ray.ni@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1676033677; x=1707569677; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=MGnvyXhHbPVuKyRUyBeYDu+wkEvkbV9fFJezLy0Md10=; b=QGgq4E8Fca5J7QFeAJaSxAKIHqIKiDftR4zLjgyhPKBGyDFly2ep8qIQ QtAO8SgFuX6Raord86UIw4nWrWG/3SWfZEzQSZldm26q9AM/ZFgDvHSzs jfIUndR2RKlP+LvxqiQaOqALuQILnnBtYUEEz5EbQAayiotXoOyIYFWIR Qbg2GJhOi/8F+Q4zQXl9c3j8UQKsK/JogfFV0W51JLA0MJon4h86wpsxg r0YzZtME0QpQTFvY8xg5p+n5z2NUH/Dk40Fp+QXlQvLXqNABeg2yxkOrk /FAFyakOr0xJax0Uv/uBtC2rwynhbJg13WU9PYGWF7tNKJfEdL0Aask4S A==; X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="331717842" X-IronPort-AV: E=Sophos;i="5.97,287,1669104000"; d="scan'208";a="331717842" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2023 04:54:37 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10616"; a="698417389" X-IronPort-AV: E=Sophos;i="5.97,287,1669104000"; d="scan'208";a="698417389" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by orsmga008.jf.intel.com with ESMTP; 10 Feb 2023 04:54:36 -0800 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 10 Feb 2023 04:54:36 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Fri, 10 Feb 2023 04:54:36 -0800 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.45) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Fri, 10 Feb 2023 04:54:36 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V3jivrHmzKL0WfdMD6ALTlow74SDGlRVJ1o1xeEKPSIEBb/HFd4fDzi3qNP0i0qmpoFGZGNWjJ8jU4gkyt+RUs1xadugvFiNdoVAJuLWDCjFQrWpWX/FC+DpE06GiI+u+rGOkRyG8LOJrK0ntnNo1Ihxi5tkeT4KLNvbY9sTDjy1XxwMhAkDNv2diYuYmsjMz2JmV94Gny4E6Zx3TZBR2xeaz0vdzjh18AfDld5B7BxmnkQF792twDS1aZayZvCkIQ4GRRIxgfr0oNYkpIwrNNjF6vEeTSZqAM0fSS1zvr1oycLtJjEM/4kioOYFpCKsSRvOC4zAQ9KJnMOKMtGWpQ== 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=J4lu0/i8Oc+o0as7vW9Qy+lIWjxqpxt6bzS4IDWgPO0=; b=mgB3vC45DqlM+2OgMIqKqu4Pskeko3Rhd8aVAL8ybHzmISZIHGlNW343+jW4a9CbWNeFenahfpiYzbc+1jUSmIA4KmCdEBxPYbcjiD2T06A6mqYItk4/FnnaV2ibOimbVnQw+jrqNBGO1slx+YRRGYq25mhXHdIcaV1ENNVniVvgHSIdH2YOE3U9ru7/A9hh27aniGeJlFdv8Qj41huGwd/PIX22kQCX7ueUiAyR95iIi0+e2F2FqOvv+AfUXvdZj/IImQeg4ZdojRArtE5mrKeklFOQgSXEzjsKg3l4YNqAqTKgQk755pgExesz/AneUN4BNK2QUJbeFhjnGvcp+A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from MN6PR11MB8244.namprd11.prod.outlook.com (2603:10b6:208:470::14) by SA1PR11MB6782.namprd11.prod.outlook.com (2603:10b6:806:25e::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6086.19; Fri, 10 Feb 2023 12:54:31 +0000 Received: from MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::f890:e4ec:e2d8:5831]) by MN6PR11MB8244.namprd11.prod.outlook.com ([fe80::f890:e4ec:e2d8:5831%3]) with mapi id 15.20.6086.017; Fri, 10 Feb 2023 12:54:31 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: "Dong, Eric" , "Kumar, Rahul R" , Daniel Schaefer , "Abner Chang" , Gerd Hoffmann , "Warkentin, Andrei" Subject: Re: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V8 05/19] UefiCpuPkg: Add BaseRiscV64CpuExceptionHandlerLib Thread-Topic: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V8 05/19] UefiCpuPkg: Add BaseRiscV64CpuExceptionHandlerLib Thread-Index: AQHZPUuUiCZxWqsxmUyuc49R1mTsg67IIv5A Date: Fri, 10 Feb 2023 12:54:31 +0000 Message-ID: References: <20230210123041.1489506-1-sunilvl@ventanamicro.com> <20230210123041.1489506-6-sunilvl@ventanamicro.com> In-Reply-To: <20230210123041.1489506-6-sunilvl@ventanamicro.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: MN6PR11MB8244:EE_|SA1PR11MB6782:EE_ x-ms-office365-filtering-correlation-id: 258ef66c-b305-4a73-a635-08db0b65f3ba x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: iGs2Q76930tdDF7PrJZLrXtMykwhnVPF7Z8Q23AHhU92oJUGF9hCM6SqDLG1SXJYrNJgGYFhk3AjrjsDWH1yKGvQplGw/Am8RaekyTZvqmBWo436IJU33WVBLYWhttrh7rAG2YIpIOWFEk5djepWlTv3YGzN2hzFZ1U/NWwuSeiAUREYfrwjF3EMIul3J0s+zvwPlGivmsm8VO0YesF7+hSlIT35Dxi/NiCc3uCiAC62VJq07+TBP7gZlS/4NNmgFGhTHhmSvSdDnjAu2N6dOj6+MRA1IScMNruttM33GIulW32BaXD1+AqUOGmT3sopsv2mX8mkc4h4ok1A7GiIT7bSBmL7lQj2d7E6tNejIP1ZbpQTWLibxSxCaHfk+hny0+B0PdRH10gFPul8+bSmqkRxaVbOHX7ERMzdmmkEiK6v5g+5ztnOmgDQ4HC3wTqPk3DdljvLlxbuoihSi7zmB/NwY1+gPeK08tuGAjEARR11sq+aO9qxBURGSgBEG3j+5LnRxhMUapBoIJTp9JB2Qh83VdzJhdy2+qDnc+zx3R+hpMpNMSEKBKpVMn8CjWc18bJYg01ZKiaAcmQZ4erLD0ZfZLdcEtmd9xU6EGYwWQfYXkZcpKO+7jOdALDbUsLj0FCZHWrL/6zwOBGkBRYyqV2Xto88knXUQN4roHdt6ippIslkpDs0jl1RmoAAxuvEQIkhh1MTYc2E3JqwexhOyqpQvhd/J0TmFts9WnSv/MQiApKYSQ9fw0SR32w/qD1lne2/UtTlb2/QPhm+2q2IRQ== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MN6PR11MB8244.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(366004)(39860400002)(376002)(346002)(396003)(136003)(451199018)(33656002)(55016003)(83380400001)(66899018)(82960400001)(38100700002)(186003)(9686003)(6506007)(54906003)(107886003)(71200400001)(478600001)(53546011)(2906002)(26005)(19627235002)(966005)(316002)(7696005)(38070700005)(41300700001)(8936002)(5660300002)(30864003)(122000001)(86362001)(66946007)(66556008)(76116006)(4326008)(66446008)(8676002)(64756008)(110136005)(66476007)(52536014);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?T1JC4FKUnmRKPvTgb7LeMI/LIxtcwESLaTNgamIaPe4/bB+Wl7mt9KRIoOs4?= =?us-ascii?Q?IJlGQWYQyg9Rybj++w9Lo2mwUC/0GhZ9JMPKTIPUHGGfob/n3zrzcX3CN4kY?= =?us-ascii?Q?yV/S9EPzMKH3NB91Z7887fwxz2TK659NiNVzdUysxl+dzZqm1STFSiR7oTmp?= =?us-ascii?Q?j/JYrplWb5/lqh0ukfGZ9W/W8FjxGrfqayAz1KH3P1A+OfSXnKyXtMLZN3J9?= =?us-ascii?Q?EVhVGV3NU1NujbQG94RhrGbGHmDf0c/3GtMpdCOCbXjfPT7/EqMybUJeGxMp?= =?us-ascii?Q?tbEj56MykaAznckWXzGpcecvulUuj+cWpOldUqMHNuuAjHJDr+XKlUGcn6pn?= =?us-ascii?Q?K+GCdJV1JviIFTDOvUe2cx9ye0q7OcxxWfpx+ahmt7ncUuDGqDiuJGObqBuh?= =?us-ascii?Q?IU0Rhfw+ml0Npcpno1N/+gdLoz75ZVWAj7DMtkxK52mFb2kEvWwHX6VfKwse?= =?us-ascii?Q?cDzj6ynQgYu6EcqSSefIiqOEM7SMlrneCgQgSXKumCEvKynPkvhdEOLfOWwY?= =?us-ascii?Q?FozQrZTt3uqavhJlI+ETuUm/FjGRq+NZ4hnE0OEQGhxDZAx6jgiX91Tatc6a?= =?us-ascii?Q?5Vc0l45GTTdgWGvWTbkDqIO8kzeGU0a90iKHapDnSrnopA9yc62aEJ95If8E?= =?us-ascii?Q?mWVm1NsleO+T+JnG0wZlkh7hIKkCRVWAJUDupCm29zKSNbnw0TJyele51Nxe?= =?us-ascii?Q?hUX5IlNqiwbmhO7xVQqCX9J/4VeDerOqlKsVa0sR9N6qtdwnj3vsknXpSxCz?= =?us-ascii?Q?FeH5K7/qw56L2E0CQUipCryi9PHl1Pdw9RudQ/elocufHJ7CAs34W+W+fiR8?= =?us-ascii?Q?XZBwiMAUfblQyO9hvm8H2kGJ/uYtbJ1lOdNDAqvvGXcRWn7lA4kAOcO2+GUn?= =?us-ascii?Q?zvdOAe2AT6PAR1Dx6CnM99UzReZwmmygTheT3yptAM+aRdyneTJpCRiAbD6k?= =?us-ascii?Q?mAD//LAMh2oRvev4W5qOjndsEqyGWPbe++3CCwO7+IbsxnSl8FGQQizmfm41?= =?us-ascii?Q?gNvPN6ZxmaG0doGS9ygmTPZ2sYOUgIXqleIgd/atryEoRtaP5tieLDIQ+i7f?= =?us-ascii?Q?EP2jcsAvkfHQKDXgF9M9HtynD5weLKadYohVLmDv5N7Q8rwTHxW6KqUaSY4D?= =?us-ascii?Q?qgJTzBYF0xDw7N/kIYL9XM0279lApDf2fkOeMDRNBbmnDIzTaQCIKdBHupSD?= =?us-ascii?Q?FpKL7X5ADl3arm7c4jkmIKMGjjFsXX/ViJu+nkdZ5z9E+TvPqctOmNaCHJMM?= =?us-ascii?Q?ptoehLI6e41O3N9/lma6y7h+wawN62BGF39Tnt/hm+IijXaVEbsFeN6wSNRo?= =?us-ascii?Q?gm27Wfz1JADfahS4avMv5MTPF4xvHkDay5KoPT6fq9ct9Ezt2lOm6T+VMh1z?= =?us-ascii?Q?QZ/J8COayRT9r/rbXuFYzRsHNiHgkB4jZummhqU/fM+58Fh7ecm4FxLDBsp2?= =?us-ascii?Q?PbMBfppGfuFpFfAfbQ/cV1hbm02mB00brxyJkIwLV4SivLoS98tRhAvlQRjO?= =?us-ascii?Q?5y3u5YpUauQp6y74zjegCFjkntToX9GEx5uqRHHcoNHQND3n2tRzB/isUDVo?= =?us-ascii?Q?ImHOQTWfHdyNsXUndGFf2N9qU4YFZtymSvKAV4CX?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MN6PR11MB8244.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 258ef66c-b305-4a73-a635-08db0b65f3ba X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Feb 2023 12:54:31.1118 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: p3AtMlTA4GBK01OIKjdFnH5gZZceBRwD9ViXX1sl66P7feZ802MDN0ZUe2MeMuZ0h7Tf2khG388iBJMP+ye5WA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR11MB6782 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Acked-by: Ray Ni > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > Sent: Friday, February 10, 2023 8:30 PM > To: devel@edk2.groups.io > Cc: Dong, Eric ; Ni, Ray ; Kumar, > Rahul R ; Daniel Schaefer ; > Abner Chang ; Gerd Hoffmann ; > Warkentin, Andrei > Subject: [edk2-devel] [edk2-staging/RiscV64QemuVirt PATCH V8 05/19] > UefiCpuPkg: Add BaseRiscV64CpuExceptionHandlerLib >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4076 >=20 > Add Cpu Exception Handler library for RISC-V. This is copied > from edk2-platforms/Silicon/RISC-V/ProcessorPkg/Library/RiscVExceptionLib >=20 > Cc: Eric Dong > Cc: Ray Ni > Cc: Rahul Kumar > Cc: Daniel Schaefer > Cc: Abner Chang > Cc: Gerd Hoffmann > Signed-off-by: Sunil V L > Acked-by: Abner Chang > Reviewed-by: Andrei Warkentin > --- > UefiCpuPkg/UefiCpuPkg.dsc = | 3 + >=20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExce > ptionHandlerLib.inf | 42 +++++++ >=20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandler > Lib.h | 116 +++++++++++++++++ >=20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandler > Lib.c | 133 ++++++++++++++++++++ >=20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExce > ptionHandlerLib.uni | 13 ++ >=20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHandle > r.S | 105 ++++++++++++++++ > 6 files changed, 412 insertions(+) >=20 > diff --git a/UefiCpuPkg/UefiCpuPkg.dsc b/UefiCpuPkg/UefiCpuPkg.dsc > index f9a46089d2c7..35e66d93efa6 100644 > --- a/UefiCpuPkg/UefiCpuPkg.dsc > +++ b/UefiCpuPkg/UefiCpuPkg.dsc > @@ -195,5 +195,8 @@ [Components.IA32, Components.X64] > [Components.X64] >=20 > UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandler > LibUnitTest.inf >=20 > +[Components.RISCV64] > + > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExce > ptionHandlerLib.inf > + > [BuildOptions] > *_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES > diff --git > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExc > eptionHandlerLib.inf > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExc > eptionHandlerLib.inf > new file mode 100644 > index 000000000000..d80462943645 > --- /dev/null > +++ > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExc > eptionHandlerLib.inf > @@ -0,0 +1,42 @@ > +## @file > +# RISC-V CPU Exception Handler Library > +# > +# Copyright (c) 2022-2023, Ventana Micro Systems Inc. All rights reserve= d.
> +# > +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION =3D 0x0001001B > + BASE_NAME =3D BaseRiscV64CpuExceptionHandlerLib > + MODULE_UNI_FILE =3D BaseRiscV64CpuExceptionHandlerLib.u= ni > + FILE_GUID =3D 6AB0D5FD-E615-45A3-9374-E284FB061FC= 9 > + MODULE_TYPE =3D BASE > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D CpuExceptionHandlerLib > + > +# > +# The following information is for reference only and not required by th= e build > tools. > +# > +# VALID_ARCHITECTURES =3D RISCV64 > +# > + > +[Sources] > + SupervisorTrapHandler.S > + CpuExceptionHandlerLib.c > + CpuExceptionHandlerLib.h > + > +[Packages] > + MdePkg/MdePkg.dec > + MdeModulePkg/MdeModulePkg.dec > + UefiCpuPkg/UefiCpuPkg.dec > + > +[LibraryClasses] > + BaseLib > + SerialPortLib > + PrintLib > + SynchronizationLib > + PeCoffGetEntryPointLib > + MemoryAllocationLib > + DebugLib > diff --git > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.h > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.h > new file mode 100644 > index 000000000000..30f47e87552b > --- /dev/null > +++ > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.h > @@ -0,0 +1,116 @@ > +/** @file > + > + RISC-V Exception Handler library definition file. > + > + Copyright (c) 2019-2022, Hewlett Packard Enterprise Development LP. Al= l > 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/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.c > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.c > new file mode 100644 > index 000000000000..f1ee7d236aec > --- /dev/null > +++ > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.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 vector= s 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 Interrupt= Handler > for a processor > + interrupt or exception type specified by InterruptType. If InterruptHa= ndler is > NULL, then the > + handler for the processor interrupt or exception type specified by > InterruptType is uninstalled. > + The installed handler is called once for each processor interrupt or e= xception. > + NOTE: This function should be invoked after InitializeCpuExceptionHand= lers() > 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 hand= ler > 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/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExc > eptionHandlerLib.uni > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExc > eptionHandlerLib.uni > new file mode 100644 > index 000000000000..00cca2213096 > --- /dev/null > +++ > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/BaseRiscV64CpuExc > eptionHandlerLib.uni > @@ -0,0 +1,13 @@ > +// /** @file > +// > +// Copyright (c) 2016 - 2019, Hewlett Packard Enterprise Development LP.= All > rights reserved.
> +// > +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +// **/ > + > + > +#string STR_MODULE_ABSTRACT #language en-US "RISC-V CPU > Exception Handler Librarys." > + > +#string STR_MODULE_DESCRIPTION #language en-US "RISC-V CPU > Exception Handler Librarys." > + > diff --git > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHan > dler.S > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHan > dler.S > new file mode 100644 > index 000000000000..649c4c5becf4 > --- /dev/null > +++ > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHan > dler.S > @@ -0,0 +1,105 @@ > +/** @file > + RISC-V Processor supervisor mode trap handler > + > + Copyright (c) 2019, Hewlett Packard Enterprise Development LP. All rig= hts > 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.34.1 >=20 >=20 >=20 >=20 >=20