From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by mx.groups.io with SMTP id smtpd.web11.3613.1677052450951678937 for ; Tue, 21 Feb 2023 23:54:11 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=ngjpTUPQ; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: andrei.warkentin@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1677052450; x=1708588450; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=sQZQDXQHUuGk7b6L1k0WEc3o4RK6cdIurMkTkZHt+hM=; b=ngjpTUPQv52B9j9SRAwCFqINGhmTBpK5NYIeTkgxe0CtquOTNr9MA9H0 sE/VsnUy50WVpLkfZZTVIUEPrTlqVWIhqWCa9OvD6dJsNL8QTbDHE/iQd d9RhYS4Lkio+xQBml4zYGhB2zUGcuTb73Vg3TtzkYv63iUwz5/dMxJKLG Qk9h3ff+sNLqgIerDScsICSx/9QxZjgSKOosfA3HJOxIOw2StGGXwHM9f I4ancgPi6iXLkHxHq2YjrirdImQSNhufOjA3FRGAXFET3aw7YZVVXWWGR o90GLBZjWpAw0Q6LjXwsH7d5spVnQRh+J758qtsBWwpEvldaCkot9D1Yp Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10628"; a="313234424" X-IronPort-AV: E=Sophos;i="5.97,318,1669104000"; d="scan'208";a="313234424" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Feb 2023 23:54:10 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10628"; a="846025290" X-IronPort-AV: E=Sophos;i="5.97,318,1669104000"; d="scan'208";a="846025290" Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by orsmga005.jf.intel.com with ESMTP; 21 Feb 2023 23:54:10 -0800 Received: from orsmsx601.amr.corp.intel.com (10.22.229.14) 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; Tue, 21 Feb 2023 23:54:09 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16 via Frontend Transport; Tue, 21 Feb 2023 23:54:09 -0800 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.106) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.16; Tue, 21 Feb 2023 23:54:05 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Rbrb0M3tJcSVvA68daJNxyAqQBGEoMp+XsUQZGGgEq7XKfV10xfUwyOkpWfBjUHwvM505Xdv1zABhcAQ3tumeJPqHfTEbokQjd7zRXqJLjxUSpcmkG52pYcfPul+wlff0IYLXd2MgROa0h8ovmiiNhLAscsgQ0j4vAEtQGmpLVCit+iH4AA48rrP3oRGs7bsgi12nMtdoAn5NT+wzFQsU9OT1bSW9LDeQqvzojfpxDt2YigC/5IpiNF5f83aKX+mnJZI/wbPtfznLGViSUCZ6a7pvzSjIwK+0VLfu/YOaiSVhK6wEqkgKRjHn6mX7aw9a51UVNpDGTI4jxhMyi49bQ== 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=ymiSteW1fQ4FvJ2v9gPP4l24SmZHIVwexLLsAeDbD7A=; b=aYayXp4mLsklyhc6Rczj0JOI1jzyx9hPglKLX5OEVW89CKsbWBNS2gmMWhVHa4DgZymH9L9YUblfN2FJvgaxxBIjR3g7stC5oX93CzqFIGiLVkBRw+Ne9MNvvrs6c6QRm2s7UvPAXa0VBWil+TET2B2mP6lfuHUcvhUWwcb31HVxj5uMTUZbsMHDPYuiTNZ0zNWMh0Q3OFNwDq+HJiEGPpDZxP3IduQM1FuJoiadbSPsOdspSJwUJzFLATzCPRSXm8JNbr/hjUksPXix2JQ/OM1oUCBSvQYaXm52vpkgSiKoVCrsI5AYwHOVrHlKiYue+Oh+01OQOAwvYRzDKE2Cnw== 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 PH8PR11MB6856.namprd11.prod.outlook.com (2603:10b6:510:22b::7) by IA1PR11MB6444.namprd11.prod.outlook.com (2603:10b6:208:3a7::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6134.19; Wed, 22 Feb 2023 07:54:04 +0000 Received: from PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::f480:22ed:c915:13f1]) by PH8PR11MB6856.namprd11.prod.outlook.com ([fe80::f480:22ed:c915:13f1%8]) with mapi id 15.20.6111.021; Wed, 22 Feb 2023 07:54:03 +0000 From: "Andrei Warkentin" To: "devel@edk2.groups.io" , "sunilvl@ventanamicro.com" CC: Daniel Schaefer Subject: Re: [edk2-devel] [edk2 1/1] RISCV: clean up exception handling Thread-Topic: [edk2-devel] [edk2 1/1] RISCV: clean up exception handling Thread-Index: AQHZQ1Fv2CAOCZaR1kijS2GDKYKH8a7Y/gSAgAGfieA= Date: Wed, 22 Feb 2023 07:54:03 +0000 Message-ID: References: <20230218042809.851-1-andrei.warkentin@intel.com> In-Reply-To: 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: PH8PR11MB6856:EE_|IA1PR11MB6444:EE_ x-ms-office365-filtering-correlation-id: 673ff509-7be5-4f88-319c-08db14a9f76d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Mf3j23L9/if7M+d7HxsJEHPZm/LoqLWxiuDO+xH4o36JE+EtqNKloN3e3bqCxnHaMuFv5VsFmGzTZ8mAxkeOpfbnlcFXkt5l8GtSgVbf8f/u7ryKcZ7waTCMgk6KBqANHpTkCQxlsaYEF7qpfIflLHmy07c9/rHFCai0FjDgONZqlItltToa6H1IAXqGjXuMu8R7ldtadlTOM5N2MJKGI85N1tnS8e9C/BQSHtu+nt2Q5OZcd/J7oTqitD55AHOOY3Gx+ZZvVbLzA8xBhimBySUoSudd9LTNbx38d0oKl5akACvd+79P7hr1Zl8eNjTntC5hvp6OLiukqMwzB2eyhHNsF++bY3kAF8ChRX50RXYYsOw931IUa169PfFgzKr+SgPsxMdcgqkblqMLFf0wR5bOOKAv4VH3tKiMmKDjLTtrsxjLOO+/Ubf2ADC896QKr8kpF82kzjZvW0p0mZqn8Yv2riB5MJf2DcB9Q/S0LLdgG2+P/bM5IJ/FFFKj+T8r2K1/vx3OxTqo/yLotCaX+Ch84kw/kt0lbUBnmY8KZKpFGNVFeQsZskz7oXzUH8aUaoSQW6RqEe08wVIbOsJVHXVxioj9CuaxphCPjP0oppzrgg2aMVRCsQCh/+6pQU1d2BxXZqn3IYeB4wFPQgPA5irnovhYrzr6OwM0JKvLbfS9brYej+tL+lIz7Ib0B/gCqrLrXs/Gie6ycUG3T+yZm7BKPvUD0DCIyJTwx/JSKE4FMGlNKZyMy3EPfJ/h/eIf x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH8PR11MB6856.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(346002)(39860400002)(366004)(396003)(376002)(136003)(451199018)(30864003)(5660300002)(9686003)(2906002)(83380400001)(38070700005)(26005)(186003)(122000001)(38100700002)(55016003)(76116006)(66946007)(82960400001)(64756008)(66446008)(66476007)(316002)(8936002)(19627235002)(8676002)(4326008)(66556008)(41300700001)(52536014)(33656002)(53546011)(6506007)(478600001)(86362001)(110136005)(966005)(7696005)(71200400001)(66899018)(21314003);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?S3qKJoUe3QrZPL3QUD2s5hA7IiioFiK/dBc6sImNOj1CVjl4dIEoYYEmUy0F?= =?us-ascii?Q?DeAxtCOLQRyJ3VeipnsbkSfL0KdbROVZFhZMmz5dMYc2VaiOi1YfuyJoF/0e?= =?us-ascii?Q?VnZ2/mbXF0whi0nYu2qL7Si3wRN2ZvJcUj3noigNTuEW/6nsEBqIrq1Miz/Z?= =?us-ascii?Q?Jdi+7zOZwjVX9wN8NalRHs+55j1d+rZigmoWaNb4XA5pipWJeFLVpiPHDSpN?= =?us-ascii?Q?FQL4sF5XCtnb882djBsTZWw1qJQNyUo0UCAaHOGxwAd0Q5QNk+o2eX+SUDlS?= =?us-ascii?Q?ROGPWFTO2zVxdlg8foUlOZJjJJt8r9YFSOdPLzf3ONJbpQDPKCurpT4eHt/P?= =?us-ascii?Q?wDiGPQzYKQfWRnU16WcXP2sVmty4Nk1KqHGShKf1dY29EgEzm+SDO4DvO3CH?= =?us-ascii?Q?7IoEWNEPoIx+DFjfvXycVna/NAOmMM0cdvTnD53qkwAvwgmMw/vKCA26TsWN?= =?us-ascii?Q?NrMkPkEcoMgYv977ZnBoXGmydGd7rS07BtOb8dhtdXZPzhQmYImGVe5D7CBO?= =?us-ascii?Q?VNCo/czUCWPJ+7aQDTo/71lw1vbvv1fxhNZx/vdNWaRMXlgk6IEHsJ1n7tOU?= =?us-ascii?Q?gK97UDJfoVrXCIwO4PDQEmSD3uc6Jvfv38gxrPRzMGnhwgsQqSpO5b1H/ou6?= =?us-ascii?Q?FfX3EpMASHcA3v1VaLqN9WIaM/m5wZnuLIlbhgdIVoQd89/MT5H0kZJydr1M?= =?us-ascii?Q?t0/dLLtAEf9B6l+C92eoP3E8eYQJnfxIc7KsYjjVyb3BzJ9M4A9q0GwlESVl?= =?us-ascii?Q?5E3aX7/eihL4ny0zFf8fO4Y8czOW092qyQGudGtqjcYcv2W6M2KD2u8T1ss4?= =?us-ascii?Q?gj6uGlRZo6OMkNmg5cI+dPGifjM496YaAircqaomhGAURXlDlapxN98tY8+U?= =?us-ascii?Q?JSma58F1YO4IX/9GVnCDfiFAeChQ04Q1AxsKqoaExq3wY6JL6mlAFHKaBnok?= =?us-ascii?Q?7rHNuYtOgA1NZdII1Wj13IHSv8IRLF8oiP+XaVbjWVcAWnQp7pbyrMFFdAru?= =?us-ascii?Q?APQJDb6qukEWU7kqRLcWNpbYbU7pdTn4NUHIrjjDkVHqvURFvGwkNti5ey35?= =?us-ascii?Q?H+OO3+g7Ejxe9Vm0SRMfDZunndZWl7TOFRTY1PNqAErxiuCYhhtRu5u4NOLy?= =?us-ascii?Q?ZkR62X2L2dtaKXVAqHLdyEldWUYZYndbxQBNRB0YIFJW/2pVsVZskxuW4JLn?= =?us-ascii?Q?thRQTsN2rh9x/tHB6f0O0kv1nTrvr/ZSPjKcVw19U0Zq5CWZ99msC33/5UBX?= =?us-ascii?Q?KA9VOn8hV4SGNquOsmjwR5KrdY2c4HRUcoRhCGz0hFFDnSBXNxu0rFiOOnCn?= =?us-ascii?Q?rhvvNY4RRo+GTOGwy5N0aMoNVwTTCtdxBxKw9MaNg10LM/TUUXqbntbFOxgx?= =?us-ascii?Q?DXEeJ1lCluCOf8wZWwPo1LROUltC2qpRVPLq9IxN905H+TaBzUm3X8ObT+/j?= =?us-ascii?Q?JjDIH7dLeRA+KH4HfkHuDWBY+FyqRZ8Kl3rP9u+LvIIr97syfv7jBOf6JKoZ?= =?us-ascii?Q?aGTskBgMjpAYfXqrnmGK+Ga24HO3IctgQ1w7gGxtJ8CYcxXL/sS36iCoQu+0?= =?us-ascii?Q?D+DRuVf+zMHrAg3655jnesWFs00th0kfvU+AXnQpLIokXocdO54N+Ip3YKO+?= =?us-ascii?Q?nA=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH8PR11MB6856.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 673ff509-7be5-4f88-319c-08db14a9f76d X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Feb 2023 07:54:03.5902 (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: BNjhl6cqmJyuL/xpGG+VzK/kXXOGDo6uccZn7nYJ399yn00EM/mTFYC4mEFj4yMMo/ntz9yTsimQNAKoJ0tRkGxvshGspepO3DmITR7xzlo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR11MB6444 Return-Path: andrei.warkentin@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Sunil, Thank you for the thorough review! - Thanks for catching EXCEPT_RISCV_STORE_ACCESS_PAGE_FAULT not being 15 - The EXCEPT_RISCV_XXX defines are needed for other drivers to pass as EFI_= EXCEPTION_TYPE to RegisterCpuInterruptHandler. For example, this is used by= our (soon to be made available) port of the X86EmulatorPkg to RISC-V. - RegisterCpuInterruptHandler should be a STATIC function - DumpCpuContext is not a STATIC function - it's actually declared in MdeMo= dulePkg/Include/Library/CpuExceptionHandlerLib.h and is for use in exceptio= n handlers set by RegisterCpuInterruptHandler. Will resend shortly. A -----Original Message----- From: devel@edk2.groups.io On Behalf Of Sunil V L Sent: Tuesday, February 21, 2023 1:02 AM To: Warkentin, Andrei Cc: devel@edk2.groups.io; Daniel Schaefer Subject: Re: [edk2-devel] [edk2 1/1] RISCV: clean up exception handling Hi Andrei, Happy to see this patch! On Fri, Feb 17, 2023 at 10:28:09PM -0600, Andrei Warkentin wrote: > RegisterCpuInterruptHandler did not allow setting exception handlers=20 > for anything beyond the timer IRQ. > Beyond that, it didn't meet the spec around handling of inputs. >=20 > RiscVSupervisorModeTrapHandler now will invoke set handlers for both=20 > exceptions and interrupts. > Two arrays of handlers are maintained - one for exceptions and one for=20 > interrupts. >=20 > For unhandled traps, RiscVSupervisorModeTrapHandler dumps state using=20 > the now implemented DumpCpuContext. >=20 > For EFI_SYSTEM_CONTEXT_RISCV64, extend this with the trapped PC=20 > address (SEPC), just like on AArch64 (ELR). This is necessary for=20 > X86EmulatorPkg to work as it allows a trap handler to return execution=20 > to a different place. Add SSTATUS/STVAL as well, at least for=20 > debugging purposes. There is no value in hiding this. >=20 > Fix nested exception handling. Handler code should not be saving SIE=20 > (the value is saved in SSTATUS.SPIE) or directly restored (that's done=20 > by SRET). Save and restore the entire SSTATUS and STVAL, too. >=20 > Cc: Sunil V L > Cc: Daniel Schaefer > Signed-off-by: Andrei Warkentin > --- > MdePkg/Include/Protocol/DebugSupport.h = | 23 ++- > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandler= Lib.h | 11 +- > UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c = | 3 +- > =20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHandl > erLib.c | 215 +++++++++++++++++--- =20 > UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/SupervisorTrapHan > dler.S | 17 +- > 5 files changed, 225 insertions(+), 44 deletions(-) >=20 > diff --git a/MdePkg/Include/Protocol/DebugSupport.h=20 > b/MdePkg/Include/Protocol/DebugSupport.h > index 2b0ae2d1577b..0d94c409448c 100644 > --- a/MdePkg/Include/Protocol/DebugSupport.h > +++ b/MdePkg/Include/Protocol/DebugSupport.h > @@ -613,11 +613,25 @@ typedef struct { > #define EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT 7 > #define EXCEPT_RISCV_ENV_CALL_FROM_UMODE 8 > #define EXCEPT_RISCV_ENV_CALL_FROM_SMODE 9 > -#define EXCEPT_RISCV_ENV_CALL_FROM_HMODE 10 > +#define EXCEPT_RISCV_10 10 Why do we need this change? mExceptionNameStr has a string. Also, should we= name these with exact words from the spec like VSMODE? > #define EXCEPT_RISCV_ENV_CALL_FROM_MMODE 11 > +#define EXCEPT_RISCV_INST_ACCESS_PAGE_FAULT 12 > +#define EXCEPT_RISCV_LOAD_ACCESS_PAGE_FAULT 13 > +#define EXCEPT_RISCV_STORE_ACCESS_PAGE_FAULT 14 Shouldn't this be 15? > +#define EXCEPT_RISCV_MAX_EXCEPTIONS (EXCEPT_RISCV_STORE_A= CCESS_PAGE_FAULT) > =20 > -#define EXCEPT_RISCV_SOFTWARE_INT 0x0 > -#define EXCEPT_RISCV_TIMER_INT 0x1 > +/// > +/// RISC-V processor exception types for interrupts. > +/// > +#define EXCEPT_RISCV_IS_IRQ(x) ((x & 0x8000000000000= 000UL) !=3D 0) > +#define EXCEPT_RISCV_IRQ_INDEX(x) (x & 0x7FFFFFFFFFFFFF= FFUL) Please run uncrustify. > +#define EXCEPT_RISCV_IRQ_0 0x8000000000000000UL > +#define EXCEPT_RISCV_IRQ_SOFT_FROM_SMODE 0x8000000000000001UL > +#define EXCEPT_RISCV_IRQ_2 0x8000000000000002UL > +#define EXCEPT_RISCV_IRQ_SOFT_FROM_MMODE 0x8000000000000003UL > +#define EXCEPT_RISCV_IRQ_4 0x8000000000000004UL > +#define EXCEPT_RISCV_IRQ_TIMER_FROM_SMODE 0x8000000000000005UL > +#define EXCEPT_RISCV_MAX_IRQS (EXCEPT_RISCV_IRQ_IND= EX(EXCEPT_RISCV_IRQ_TIMER_FROM_SMODE)) > =20 > typedef struct { > UINT64 X0; > @@ -652,6 +666,9 @@ typedef struct { > UINT64 X29; > UINT64 X30; > UINT64 X31; > + UINT64 SEPC; > + UINT32 SSTATUS; > + UINT32 STVAL; > } EFI_SYSTEM_CONTEXT_RISCV64; > =20 > // > diff --git=20 > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHan > dlerLib.h=20 > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHan > dlerLib.h index 30f47e87552b..9b7e1304dd3b 100644 > ---=20 > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHan > dlerLib.h > +++ b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptio > +++ nHandlerLib.h > @@ -59,7 +59,7 @@ SupervisorModeTrap ( > #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_stval 34 > #define SMODE_TRAP_REGS_last 35 > =20 > #define SMODE_TRAP_REGS_OFFSET(x) ((SMODE_TRAP_REGS_##x) *=20 > __SIZEOF_POINTER__) @@ -68,7 +68,7 @@ SupervisorModeTrap ( #pragma=20 > pack(1) typedef struct { > // > - // Below are follow the format of EFI_SYSTEM_CONTEXT > + // Below follow the format of EFI_SYSTEM_CONTEXT. > // > UINT64 zero; > UINT64 ra; > @@ -102,14 +102,9 @@ typedef struct { > 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; > + UINT64 stval; > } SMODE_TRAP_REGISTERS; > #pragma pack() > =20 > diff --git a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c=20 > b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c > index db153f715e60..0ecefddf1f18 100644 > --- a/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c > +++ b/UefiCpuPkg/CpuTimerDxeRiscV64/Timer.c > @@ -271,7 +271,8 @@ TimerDriverInitialize ( > // > // Install interrupt handler for RISC-V Timer. > // > - Status =3D mCpu->RegisterInterruptHandler (mCpu,=20 > EXCEPT_RISCV_TIMER_INT, TimerInterruptHandler); > + Status =3D mCpu->RegisterInterruptHandler (mCpu, EXCEPT_RISCV_IRQ_TIME= R_FROM_SMODE, > + TimerInterruptHandler); > ASSERT_EFI_ERROR (Status); > =20 > // > diff --git=20 > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHan > dlerLib.c=20 > b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHan > dlerLib.c index f1ee7d236aec..7e8be41cfb9b 100644 > ---=20 > a/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptionHan > dlerLib.c > +++ b/UefiCpuPkg/Library/BaseRiscV64CpuExceptionHandlerLib/CpuExceptio > +++ nHandlerLib.c > @@ -11,11 +11,151 @@ > #include > #include > #include > +#include > +#include > #include > - > #include "CpuExceptionHandlerLib.h" > =20 > -STATIC EFI_CPU_INTERRUPT_HANDLER mInterruptHandlers[2]; > +// > +// Define the maximum message length > +// > +#define MAX_DEBUG_MESSAGE_LENGTH 0x100 > + > +STATIC EFI_CPU_INTERRUPT_HANDLER=20 > +mExceptionHandlers[EXCEPT_RISCV_MAX_EXCEPTIONS + 1]; STATIC=20 > +EFI_CPU_INTERRUPT_HANDLER mIrqHandlers[EXCEPT_RISCV_MAX_IRQS + 1]; > + > +STATIC CONST CHAR8 mExceptionOrIrqUnknown[] =3D "Unknown"; STATIC CONST= =20 > +CHAR8 *mExceptionNameStr[EXCEPT_RISCV_MAX_EXCEPTIONS + 1] =3D { > + "EXCEPT_RISCV_INST_MISALIGNED", > + "EXCEPT_RISCV_INST_ACCESS_FAULT", > + "EXCEPT_RISCV_ILLEGAL_INST", > + "EXCEPT_RISCV_BREAKPOINT", > + "EXCEPT_RISCV_LOAD_ADDRESS_MISALIGNED", > + "EXCEPT_RISCV_LOAD_ACCESS_FAULT", > + "EXCEPT_RISCV_STORE_AMO_ADDRESS_MISALIGNED", > + "EXCEPT_RISCV_STORE_AMO_ACCESS_FAULT", > + "EXCEPT_RISCV_ENV_CALL_FROM_UMODE", > + "EXCEPT_RISCV_ENV_CALL_FROM_SMODE", > + "EXCEPT_RISCV_ENV_CALL_FROM_HMODE", > + "EXCEPT_RISCV_ENV_CALL_FROM_MMODE", > + "EXCEPT_RISCV_INST_ACCESS_PAGE_FAULT", > + "EXCEPT_RISCV_INST_ACCESS_PAGE_FAULT", > + "EXCEPT_RISCV_STORE_ACCESS_PAGE_FAULT" > +}; > + > +STATIC CONST CHAR8 *mIrqNameStr[EXCEPT_RISCV_MAX_IRQS + 1] =3D { > + "EXCEPT_RISCV_IRQ_0", > + "EXCEPT_RISCV_IRQ_SOFT_FROM_SMODE", > + "EXCEPT_RISCV_IRQ_2", > + "EXCEPT_RISCV_IRQ_SOFT_FROM_MMODE", > + "EXCEPT_RISCV_IRQ_4", > + "EXCEPT_RISCV_IRQ_TIMER_FROM_SMODE", > +}; > + > +/** > + Prints a message to the serial port. > + > + @param Format Format string for the message to print. > + @param ... Variable argument list whose contents are accessed > + based on the format string specified by Format. > + > +**/ > +VOID > +EFIAPI > +InternalPrintMessage ( > + IN CONST CHAR8 *Format, > + ... > + ) Should this be a static function? > +{ > + CHAR8 Buffer[MAX_DEBUG_MESSAGE_LENGTH]; > + VA_LIST Marker; > + > + // > + // Convert the message to an ASCII String // VA_START (Marker,=20 > + Format); AsciiVSPrint (Buffer, sizeof (Buffer), Format, Marker); =20 > + VA_END (Marker); > + > + // > + // Send the print string to a Serial Port > + // > + SerialPortWrite ((UINT8 *)Buffer, AsciiStrLen (Buffer)); } > + > +/** > + Get ASCII format string exception name by exception type. > + > + @param ExceptionType Exception type. > + > + @return ASCII format string exception name. > +**/ > +STATIC > +CONST CHAR8 * > +GetExceptionNameStr ( > + IN EFI_EXCEPTION_TYPE ExceptionType > + ) > +{ > + if (EXCEPT_RISCV_IS_IRQ(ExceptionType)) { > + if (EXCEPT_RISCV_IRQ_INDEX(ExceptionType) > EXCEPT_RISCV_MAX_IRQS) { > + return mExceptionOrIrqUnknown; > + } > + > + return mIrqNameStr[EXCEPT_RISCV_IRQ_INDEX(ExceptionType)]; > + } > + > + if (ExceptionType > EXCEPT_RISCV_MAX_EXCEPTIONS) { > + return mExceptionOrIrqUnknown; > + } > + > + return mExceptionNameStr[ExceptionType]; } > + > +/** > + Display CPU information. > + > + @param ExceptionType Exception type. > + @param SystemContext Pointer to EFI_SYSTEM_CONTEXT. > +**/ > +VOID > +EFIAPI > +DumpCpuContext ( Should this be a static function? Thanks, Sunil