From 0fdffb71df7c99301c6430a95af207159cbe9655 Mon Sep 17 00:00:00 2001 From: Chao Li Date: Wed, 18 Dec 2024 10:45:24 +0800 Subject: [PATCH] UefiCpuPkg: Adjust the exception handler logic on LoongArch64 There is a problem with LoongArch64 exception handler, it returns a unhandled value when we get an exception type, the correct value should be right shifted 16 bits, so fix it. Cc: Ray Ni Cc: Jiaxin Wu Cc: Zhiguang Liu Cc: Dun Tan Cc: Rahul Kumar Cc: Gerd Hoffmann Cc: Jiaxin Wu Signed-off-by: Chao Li --- .../LoongArch/DxeExceptionLib.c | 15 +++++++-------- .../LoongArch/LoongArch64/ArchExceptionHandler.c | 2 +- .../LoongArch/SecPeiExceptionLib.c | 7 ------- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExceptionLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExceptionLib.c index eed5644552..1c60be8312 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExceptionLib.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/DxeExceptionLib.c @@ -115,23 +115,22 @@ CommonExceptionHandler ( // Interrupt // InterruptType = GetInterruptType (SystemContext); - if (InterruptType == 0xFF) { - ExceptionType = InterruptType; - } else { + if (InterruptType != 0xFF) { if ((ExternalInterruptHandler != NULL) && (ExternalInterruptHandler[InterruptType] != NULL)) { ExternalInterruptHandler[InterruptType](InterruptType, SystemContext); return; } } - } else if (ExceptionType == EXCEPT_LOONGARCH_FPD) { - EnableFloatingPointUnits (); - InitializeFloatingPointUnits (); - return; } else { // // Exception // - ExceptionType >>= CSR_ESTAT_EXC_SHIFT; + if (ExceptionType == EXCEPT_LOONGARCH_FPD) { + EnableFloatingPointUnits (); + InitializeFloatingPointUnits (); + return; + } + if ((ExceptionHandler != NULL) && (ExceptionHandler[ExceptionType] != NULL)) { ExceptionHandler[ExceptionType](ExceptionType, SystemContext); return; diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch64/ArchExceptionHandler.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch64/ArchExceptionHandler.c index 519fe1e24e..ea299475f5 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch64/ArchExceptionHandler.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/LoongArch64/ArchExceptionHandler.c @@ -27,7 +27,7 @@ GetExceptionType ( { EFI_EXCEPTION_TYPE ExceptionType; - ExceptionType = (SystemContext.SystemContextLoongArch64->ESTAT & CSR_ESTAT_EXC); + ExceptionType = (SystemContext.SystemContextLoongArch64->ESTAT & CSR_ESTAT_EXC) >> CSR_ESTAT_EXC_SHIFT; return ExceptionType; } diff --git a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExceptionLib.c b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExceptionLib.c index 7588d2050b..dc395c092c 100644 --- a/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExceptionLib.c +++ b/UefiCpuPkg/Library/CpuExceptionHandlerLib/LoongArch/SecPeiExceptionLib.c @@ -68,14 +68,7 @@ CommonExceptionHandler ( // IpiInterruptHandler (InterruptType, SystemContext); return; - } else { - ExceptionType = InterruptType; } - } else { - // - // Exception - // - ExceptionType >>= CSR_ESTAT_EXC_SHIFT; } DefaultExceptionHandler (ExceptionType, SystemContext);