NMI handler in uefi bios under uefi mode

Post Reply
future
Member
Posts: 6
Joined: Sun Apr 08, 2018 11:28 am

NMI handler in uefi bios under uefi mode

Post by future » Wed Apr 11, 2018 11:26 pm

uefi how to handle NMI interrupt under uefi mode ?anyone can help on this ?thanks !

User avatar
BobJC
Member
Posts: 20
Joined: Wed Apr 04, 2018 2:07 pm

Re: NMI handler in uefi bios under uefi mode

Post by BobJC » Thu Apr 12, 2018 2:06 am

It would be better if you could specify the question. Did you encounter some NMI handler issue or just would like to know the common handling mechanism?

User avatar
armstrong
Member
Posts: 22
Joined: Sun Apr 01, 2018 4:34 pm

Re: NMI handler in uefi bios under uefi mode

Post by armstrong » Thu Apr 12, 2018 2:24 am

NMI handling in UEFI and legacy mode are totally different.

For UEFI mode, UEFI code disables NMI through port 70h, and enable NMI2SMI.All following NMIs will trigger corresponding SMI, of which UEFI could register SMI handler to take care.
Implementation wise, EDK2 CPU driver (Exception.c\InitializeException() ) registers CommonExceptionHandler() for exceptions, the handler would print exception msg and DEADLOOP().
Since UEFI is running in protected mode, so interrupts/exceptions are registered in IDT, for which CPU driver will take care of the initialization and loading.

Code: Select all

EFI_EXCEPTION_HANDLER mExceptionTable[] = {
          { EFI_SW_EC_IA32_DIVIDE_ERROR,     INTERRUPT_HANDLER_DIVIDE_ZERO },
          { EFI_SW_EC_IA32_DEBUG,            INTERRUPT_HANDLER_DEBUG },
          { EFI_SW_EC_IA32_NMI,              INTERRUPT_HANDLER_NMI },
          { EFI_SW_EC_IA32_BREAKPOINT,       INTERRUPT_HANDLER_BREAKPOINT },
          { EFI_SW_EC_IA32_OVERFLOW,         INTERRUPT_HANDLER_OVERFLOW },
          ...
          };
          
#define INTERRUPT_HANDLER_DIVIDE_ZERO           0x00
#define INTERRUPT_HANDLER_DIVIDE_ZERO           0x00
#define INTERRUPT_HANDLER_DEBUG                 0x01
#define INTERRUPT_HANDLER_NMI                   0x02
#define INTERRUPT_HANDLER_BREAKPOINT            0x03
#define INTERRUPT_HANDLER_OVERFLOW              0x04
		...
          

future
Member
Posts: 6
Joined: Sun Apr 08, 2018 11:28 am

Re: NMI handler in uefi bios under uefi mode

Post by future » Thu Apr 12, 2018 3:25 am

BobJC wrote:
Thu Apr 12, 2018 2:06 am
It would be better if you could specify the question. Did you encounter some NMI handler issue or just would like to know the common handling mechanism?
thanks for your reply, i want to know the common handling mechanism, i just want to know how bios deal with NMI interrupt in uefi mode, and how to register a NMI callback.

future
Member
Posts: 6
Joined: Sun Apr 08, 2018 11:28 am

Re: NMI handler in uefi bios under uefi mode

Post by future » Thu Apr 12, 2018 3:39 am

armstrong wrote:
Thu Apr 12, 2018 2:24 am
NMI handling in UEFI and legacy mode are totally different.

For UEFI mode, UEFI code disables NMI through port 70h, and enable NMI2SMI.All following NMIs will trigger corresponding SMI, of which UEFI could register SMI handler to take care.
Implementation wise, EDK2 CPU driver (Exception.c\InitializeException() ) registers CommonExceptionHandler() for exceptions, the handler would print exception msg and DEADLOOP().
Since UEFI is running in protected mode, so interrupts/exceptions are registered in IDT, for which CPU driver will take care of the initialization and loading.

Code: Select all

EFI_EXCEPTION_HANDLER mExceptionTable[] = {
          { EFI_SW_EC_IA32_DIVIDE_ERROR,     INTERRUPT_HANDLER_DIVIDE_ZERO },
          { EFI_SW_EC_IA32_DEBUG,            INTERRUPT_HANDLER_DEBUG },
          { EFI_SW_EC_IA32_NMI,              INTERRUPT_HANDLER_NMI },
          { EFI_SW_EC_IA32_BREAKPOINT,       INTERRUPT_HANDLER_BREAKPOINT },
          { EFI_SW_EC_IA32_OVERFLOW,         INTERRUPT_HANDLER_OVERFLOW },
          ...
          };
          
#define INTERRUPT_HANDLER_DIVIDE_ZERO           0x00
#define INTERRUPT_HANDLER_DIVIDE_ZERO           0x00
#define INTERRUPT_HANDLER_DEBUG                 0x01
#define INTERRUPT_HANDLER_NMI                   0x02
#define INTERRUPT_HANDLER_BREAKPOINT            0x03
#define INTERRUPT_HANDLER_OVERFLOW              0x04
		...
          
thanks for your reply, there are still some questions,

1. all of NMI will be changed to smi if enable nmi2smi ??
2.when will idt exception be executed since nmi was changed to smi?

User avatar
armstrong
Member
Posts: 22
Joined: Sun Apr 01, 2018 4:34 pm

Re: NMI handler in uefi bios under uefi mode

Post by armstrong » Thu Apr 12, 2018 12:47 pm

What I mentioned above is the normal handling during runtime. During POST, the exception handler would service the NMI.
Yes, it covers all of the NMI. Source of the NMI could be identified by specific PCH registers.
In the handler of the NMI triggered SMI, an NMI could be triggered to notify OS.

Post Reply