UefiCpuPkg: BaseRiscV64CpuExceptionHandlerLib: clean up

RegisterCpuInterruptHandler did not allow setting
exception handlers for anything beyond the timer IRQ.
Beyond that, it didn't meet the spec around handling
of inputs.

RiscVSupervisorModeTrapHandler now will invoke
set handlers for both exceptions and interrupts.
Two arrays of handlers are maintained - one for exceptions
and one for interrupts.

For unhandled traps, RiscVSupervisorModeTrapHandler dumps
state using the now implemented DumpCpuContext.

For EFI_SYSTEM_CONTEXT_RISCV64, extend this with the trapped
PC address (SEPC), just like on AArch64 (ELR). This is
necessary for X86EmulatorPkg to work as it allows a trap
handler to return execution to a different place. Add
SSTATUS/STVAL as well, at least for debugging purposes. There
is no value in hiding this.

Fix nested exception handling. Handler code should not
be saving SIE (the value is saved in SSTATUS.SPIE) or
directly restored (that's done by SRET). Save and
restore the entire SSTATUS and STVAL, too.

Cc: Daniel Schaefer <git@danielschaefer.me>
Reviewed-by: Sunil V L <sunilvl@ventanamicro.com>
Signed-off-by: Andrei Warkentin <andrei.warkentin@intel.com>
This commit is contained in:
Andrei Warkentin
2023-02-17 18:42:29 -06:00
committed by mergify[bot]
parent 5ad2592ab3
commit 69da506c92
5 changed files with 260 additions and 44 deletions

View File

@@ -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
#define SMODE_TRAP_REGS_OFFSET(x) ((SMODE_TRAP_REGS_##x) * __SIZEOF_POINTER__)
@@ -68,7 +68,7 @@ SupervisorModeTrap (
#pragma 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()