From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.1076.1670459409851199689 for ; Wed, 07 Dec 2022 16:30:09 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=dXUS4rHX; spf=pass (domain: intel.com, ip: 192.55.52.43, 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=1670459409; x=1701995409; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=S1nzx0GWGt4tmeaWF/Ml3VEQ2hU6VIPKqsE4F4/1K98=; b=dXUS4rHXy4ik2wKuHWLkjf0q5v4teyFSJid0EImOcpf/IHB7pr7TK/GS XSkfyJ2xttLxlqtQt0cNV3k1pOs1MhPKKMYBIR4Ysnccl0ECdYgEQG9rF 5cGkAuCB66EJfIkJw+sO6TGJcW4ZNI/f4UgRYK+ksJWcLfpKGeekaqV8L YJLGxSxppanku6wndAEaWr07Wcz1D4WczsAo/kiBFt+Q22VuAO43T2xEH EviEjs79DCpy75n7R9zZmMDCMUkoJYZDvfHTKhjAvm9It0/ccmO/6pk+H Rrq1uLKWDbC8Lb6TQ5GJkDIyLzg+AOoseMD5NdkZz8FMPvFEws4+WoW7B Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10554"; a="403306215" X-IronPort-AV: E=Sophos;i="5.96,226,1665471600"; d="scan'208";a="403306215" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2022 16:30:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10554"; a="789099634" X-IronPort-AV: E=Sophos;i="5.96,226,1665471600"; d="scan'208";a="789099634" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga001.fm.intel.com with ESMTP; 07 Dec 2022 16:30:08 -0800 Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Wed, 7 Dec 2022 16:30:07 -0800 Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Wed, 7 Dec 2022 16:30:07 -0800 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (104.47.57.173) 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; Wed, 7 Dec 2022 16:30:07 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=O0HKPs7VgSiVZiehmlP/MFlCU/gKMMCXl9PD/w2X3HymWA4nUn2doglJc/N+/NX1mWlfPI3yn+1P1QXwkAqBsvvh2h1aPQ5CnUL6CfWcJHn4a/2i3quuPeRY9qcHwO6YaxS/4WwTqAdvhFdBEmGZLGzyJ136A1dPTYsQl/mMSJutMYlbJPHnFKtumjI9hMZ4AXgHDybMytJfGAjC0v43SFihWMLw0z7UiTzJhRBOtqczJSHwl0c13b1sIEwoUkej3Ai/e2pw9NDJ9eMBNkx1T78czk7CiAh2TaAnJJ1i0FDpWcwrtLhiEBJag5lyHMbPFrvCEdoQ6h8IhsEXz03DYQ== 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=Q8W7nyu/nVeSNIA6L7Hdwqxs6JY7PGeADNkMng3JXmU=; b=b2DDKhgy1558kb5+YPtTPSPdkBuy4PybC7unZoesOJNnSzocYmA9W2/G13qXmj152Uk1Y1kZjFjnozZEY5q0I9QIHaHwUjVXHfihhsJP3olgSHYBEez9fsLJY9+bprFKs+cc/lGn3kgHTsnZ58jHhovXSeczuKaTtO5r1ZEM9su3whKDfnXkImyLbLRozTsG2pr14vHaDWNoCKTx3r3UoykAgZBzU6g2Prh1+h1VgGVr12j3469kXqQ6ANyGs0VgGIjmdE626fdBZEJwnTpAJrvVRfYXjzKGDhluzqbkgRjXh+WKyKb11WC554hImlAvS0xQ3rf4D506zzFNqhH/OA== 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 MWHPR11MB1631.namprd11.prod.outlook.com (2603:10b6:301:10::10) by PH7PR11MB7719.namprd11.prod.outlook.com (2603:10b6:510:2b4::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5880.14; Thu, 8 Dec 2022 00:30:05 +0000 Received: from MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::69c8:2676:4674:1d2e]) by MWHPR11MB1631.namprd11.prod.outlook.com ([fe80::69c8:2676:4674:1d2e%12]) with mapi id 15.20.5880.014; Thu, 8 Dec 2022 00:30:05 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: "Wang, Jian J" , "Gao, Liming" , "Dong, Eric" , "Kumar, Rahul R" , "De, Debkumar" , "West, Catharine" , Daniel Schaefer , Abner Chang , Leif Lindholm , Andrew Fish , Ard Biesheuvel , Heinrich Schuchardt , Anup Patel Subject: Re: [edk2-devel] [RFC PATCH V2 10/19] UefiCpuPkg: Add RISC-V support in DxeCpuExceptionHandlerLib Thread-Topic: [edk2-devel] [RFC PATCH V2 10/19] UefiCpuPkg: Add RISC-V support in DxeCpuExceptionHandlerLib Thread-Index: AQHYwq48vhYxUeZHmU+SsZg7QrtLf65jsmBg Date: Thu, 8 Dec 2022 00:30:04 +0000 Message-ID: References: <20220907113626.540065-1-sunilvl@ventanamicro.com> <20220907113626.540065-11-sunilvl@ventanamicro.com> In-Reply-To: <20220907113626.540065-11-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: MWHPR11MB1631:EE_|PH7PR11MB7719:EE_ x-ms-office365-filtering-correlation-id: c04483e6-826e-4adf-a590-08dad8b35a21 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: v0q1hlB6FKodV3yMTbaVcnVnL36fRv55wHvHqI3Wyb6c5EhLy4hwgTEQ2mlPgZa9Sk3e298NIpF9nL04+LS7BTEWQTf8H2fH+2WisYr9t2x1hThcl0jkStovX/7rQ6DHSmGEdS9FWHUHTmjFfTmQGAdFCGl3hxRh+xEyc6mUHW2YKfbPiq0RwgIDhmaAKka+uJWaUYieFRlSQtNUSMER32Eh8Ax0zy+CDVpExMxyO9am9mg65M/8SQYUgNzHjH+dIodfodp9mBtiKjlnQpAssle9JwoMIPRUmsu8zVIsP53WXdTWSSDlZBZqiKwwXh9REIePJkUzGnvvFtnhOVHbETjaE/f8PgSfARf5egyES4zAbY8DFeDPsefYh4+aFedIcwXtwRje+E8f9sjm3ZyZ0WDCfWShuuDC8kgYMsQN7yrvmpZM6MsawRrbWTWceAtSc2TTv66ZNEFeZguKjm81O2myHV3tsa0d5xDqDohwsJXFljSIOnwfHRlouTG5iYmrpbrItRtzY4Qpq62y6AkiDl0Tx0SYsc4hX3yA2K0Lu0oWgScbQByv4CXo8O4VafON9Y4DTE5xBRL9yzkEn7Od9zgqwsXL1VFsAS2G3KpJtIhW/GlAl3KetD6e8psq4x3AhwMIKzu+iHyYPMOCxhWxKIM2aHwCtzgJh1W/VxfVjBB7kptM0T0yDd9/8Y4bOYsXsJB++9wMOYhDE29+s2h511hOunOvBlIjkvceJsQMFaNnGsmBMS9+BejiUEeDPumCPCXqO/V2gxA2BaRXGbMmftShO5UZgm8gjOPP96AeN5Q= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1631.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(346002)(396003)(39860400002)(136003)(366004)(376002)(451199015)(66446008)(64756008)(66946007)(66556008)(8676002)(186003)(33656002)(76116006)(66476007)(4326008)(53546011)(83380400001)(9686003)(19627235002)(26005)(7696005)(316002)(478600001)(966005)(54906003)(86362001)(110136005)(66899015)(71200400001)(82960400001)(6506007)(2906002)(38070700005)(52536014)(7416002)(41300700001)(30864003)(55016003)(8936002)(38100700002)(5660300002)(122000001)(213903007);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?QhU21OkHhIWRwOkG5DQiZo4seERQMnTH5zK8mV4Xg/ehEny1CJNn0rWhrhWn?= =?us-ascii?Q?Jid3+u3i8y6Ml7sWJSGhLNfQGQTGUPV7T1+Ctzkvjv1HgcSCI1ML0EKx212K?= =?us-ascii?Q?/6wAY7od3+03X3TJ9K0E8217LU9VWSNn/zF9zx/Vnge+vGhJBwEcqGgXw9e5?= =?us-ascii?Q?sb/MVEmEXHS8EQcUv/SBJBE8QkwJx2yn9smD2j9Xd77QuS6ti5pkeoq+r7Za?= =?us-ascii?Q?aMt7YDEB1VlHtqVS5ARtQCxPOzLPBzKYpX7wHHVp/HeaC6SZ3hwOm1fqKzT5?= =?us-ascii?Q?L9CbNsA83zOZvMvw+MG18g0VQBAUM6vYhYh4fcj6Lzn0ZBmaEQ2sgGqxmguj?= =?us-ascii?Q?rlzh23FawOXITy9r8/u/CnVHPBb0qBDS6nqExyPnVLvk/xInaLxQSG6DWsVz?= =?us-ascii?Q?/z3JoqjrB4FnuI/q8kD8cbYBZGRC3pB6A1UKjN9zZ6UNGYVVAecaORY/J2gY?= =?us-ascii?Q?N7T+zCvXiGQZdevlEkOWIJ4+8LeHNOPYnXaWMG2g+Ip5egH6G+srEutdiLE4?= =?us-ascii?Q?RGmiC2VVSC0fWDe/EwzXK5u1FDr5DBewhRuEwUG7ZiexqDZ6WClz6DBeFtX3?= =?us-ascii?Q?5jF3tjFQq0vmhQ3BF8uFuifAprLItV8dPUNfYtn2S3ikM7ZWGbUM5H9NG54A?= =?us-ascii?Q?/zpHmtkzOsF5UjCK9bHKtvEmAtjmePOv0uir5AdL6j2toq/UJS4FQlHWqQB0?= =?us-ascii?Q?altKW07scK1WnPBRhmQgimP0Bdt7nDTxt3AYIYxTn+RGhg+gAwU9IozYjnLJ?= =?us-ascii?Q?G19ZSmsrVamfibnh75zY5ib4qMmYlRFfJ5lrSKrTTFiCmOkNjjvUTjkjFfz+?= =?us-ascii?Q?CpBW+5CvUqLuMTmDhe+jPgUtps9m3+qHDACCU+HcceVlPcHFwp7CkTjn+Oc8?= =?us-ascii?Q?t3d58E60UYR571Yvx0wLOnU+ur3enzgqhNQ4YtgRgs5e+J2JgaYaFLDomhPV?= =?us-ascii?Q?Nfjv5qVE0mHULkl8H3eMnfqYpGkm/LrQLQO48L4QeWt8d8Zc9GbOx8OHLBAn?= =?us-ascii?Q?oY0S6AmsvuQyUQ/jTNOt7tq4tjm31cCRO7v/DQT1RKt9OW19ik4eP8MWaZG3?= =?us-ascii?Q?w0cwuJfUzaHihfbv96t+mJPUtlSBfVBzgVyvn4J6QxVRW+Z7Cw2x4Zw5PpH6?= =?us-ascii?Q?oOAjtLBoCb/4SUyjAUtMokeMxAGVetPFwlkEQQnrVlPJbdlEZVdVKhox8fbX?= =?us-ascii?Q?nloEIbRnkAGXFL19FQjXFbz60karoro8zz99yvJ+S+6pXPeO6MVQTZ6z1FuM?= =?us-ascii?Q?D3Fd+ExTpGo9F7ugaa7UxGRdepPHRqmZUwzFiwy0ONp8wimDdvE6dkxBkjEQ?= =?us-ascii?Q?Ov5DKv9r7bZgqkFZcxv6bv9146LMUxfN6079FAdS5n6jOEit9wgl2mgxm/Xi?= =?us-ascii?Q?HphgEKbpfCR6kXoPpUQ8vUxvLgispo222QTzeadOKegwrhjU2UtXcEYcA1Yy?= =?us-ascii?Q?m+F3PWqEBv4FYS9X7zfTUk5l0Q+/JkRZzHOyz9nRlMgUq8WXRAhDCOpzIJiE?= =?us-ascii?Q?GUzPAbsXv/n3s8VTlhTtmJJcI3IwyEyAQtK3R6ITBNo5JaBWV+3Gu/zJ4V8Q?= =?us-ascii?Q?v9Jmfc+64jVN0oE22ICEmSfa0Ifkk6AfxFYBMQPo?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1631.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c04483e6-826e-4adf-a590-08dad8b35a21 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Dec 2022 00:30:04.8777 (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: XqciyJD3fSgUleU2VogbxAuSZ0gAI925CpWNPbnp8pqkQW+KRWrjRZfERK80MPhN1wEOklqDRvVNge9hjvfhYw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR11MB7719 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 Sunil, Is there any source code sharing between Risc-V and IA32X64? >>From the patch, I cannot see any. If that's the case, I would prefer we don't mix the two separate implementa= tions together into one component. Can you please create a new CpuExceptionHandlerLib instance for Risc-V inst= ead of including the Risc-V sources into the existing INF? Thanks, Ray > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Sunil V L > Sent: Wednesday, September 7, 2022 7:36 PM > To: devel@edk2.groups.io > Cc: Wang, Jian J ; Gao, Liming ; Dong, Eric ; Ni, > Ray ; Kumar, Rahul R ; De, Deb= kumar ; West, > Catharine ; Daniel Schaefer ; Abner Chang > ; Leif Lindholm ; Andrew = Fish ; Ard Biesheuvel > ; Heinrich Schuchardt ; Anup Patel ; > Sunil V L > Subject: [edk2-devel] [RFC PATCH V2 10/19] UefiCpuPkg: Add RISC-V support= in DxeCpuExceptionHandlerLib >=20 > Add low level interfaces to register exception and interrupt handlers > for RISC-V. >=20 > Signed-off-by: Sunil V L > --- > UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf = | 7 +- > UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib= .h | 112 ++++++++++++++++ > UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLib= .c | 136 ++++++++++++++++++++ > UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHandler.= S | 105 +++++++++++++++ > 4 files changed, 359 insertions(+), 1 deletion(-) >=20 > diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHan= dlerLib.inf > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf > index bf33d54bae13..8570b83e8afb 100644 > --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib= .inf > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib= .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] > PeiDxeSmmCpuException.c > 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/RiscV64/CpuExcepti= onHandlerLib.h > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLi= b.h > new file mode 100644 > index 000000000000..1cc6dbe73420 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandl= erLib.h > @@ -0,0 +1,112 @@ > +/** @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 > +#include > +extern 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_POI= NTER__) > +#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/CpuExcepti= onHandlerLib.c > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandlerLi= b.c > new file mode 100644 > index 000000000000..f4427599a6b7 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/CpuExceptionHandl= erLib.c > @@ -0,0 +1,136 @@ > +/** @file > + RISC-V Exception Handler library implementation. > + > + Copyright (c) 2016 - 2022, Hewlett Packard Enterprise Development LP. = All rights reserved.
> + Copyright (c) 2022, Ventana Micro Systems Inc. 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 > + ) > +{ > + csr_write (CSR_STVEC, 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 Int= erruptType 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 re= turned. > + > + @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__, Interru= ptType, 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_RISCV6= 4 *)SmodeTrapReg; > + // > + // Check scasue register. > + // > + SCause =3D (UINTN)csr_read (CSR_SCAUSE); > + 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/Supervisor= TrapHandler.S > b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/SupervisorTrapHandler= .S > new file mode 100644 > index 000000000000..649c4c5becf4 > --- /dev/null > +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/RiscV64/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.25.1 >=20 >=20 >=20 >=20 >=20