From 245cba6795c0c80d8c0b08b7273f2bf138d38dbb Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Tue, 8 Apr 2025 12:59:35 +0200 Subject: [PATCH] cpu/x86/smm: Add support for exception handling Add an exception handler to SMM to debug crashes when a serial console is enabled and DEBUG_SMI is set. This allows for narrowing down issues faster than letting the machine triple fault. Change-Id: I2ccaf8d23d508d773ce56912983884ad6832ede6 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/c/coreboot/+/87208 Tested-by: build bot (Jenkins) Reviewed-by: Shuo Liu Reviewed-by: Maximilian Brune --- src/arch/x86/exception.c | 2 ++ src/cpu/x86/smm/smm_module_handler.c | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/arch/x86/exception.c b/src/arch/x86/exception.c index 224f0e1d41..e21cfa6de5 100644 --- a/src/arch/x86/exception.c +++ b/src/arch/x86/exception.c @@ -665,6 +665,8 @@ asmlinkage void exception_init(void) load_idt(idt, sizeof(idt)); +#if !ENV_SMM null_breakpoint_init(); stack_canary_breakpoint_init(); +#endif } diff --git a/src/cpu/x86/smm/smm_module_handler.c b/src/cpu/x86/smm/smm_module_handler.c index d25b5f47cf..d9f64204d6 100644 --- a/src/cpu/x86/smm/smm_module_handler.c +++ b/src/cpu/x86/smm/smm_module_handler.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0-only */ #include +#include #include #include #include @@ -169,6 +170,9 @@ asmlinkage void smm_handler_start(void *arg) printk(BIOS_SPEW, "\nSMI# #%d\n", cpu); + if (CONFIG(DEBUG_SMI) && CONFIG(CONSOLE_SERIAL)) + exception_init(); + /* Allow drivers to initialize variables in SMM context. */ if (do_driver_init) { #if CONFIG(SPI_FLASH_SMM)