Name of user not set #1005756 has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/86562?usp=email )
Change subject: src/cpu/intel/car/romstage.c: Refactor stack guard code in romstage. ......................................................................
src/cpu/intel/car/romstage.c: Refactor stack guard code in romstage.
Refactor stack guard code in romstage. It's just for improving readability. :)
Change-Id: I754e422c0023cd7824dd6109f031239756acff4b Signed-off-by: melongmelong knw0507@naver.com --- M src/cpu/intel/car/romstage.c 1 file changed, 31 insertions(+), 12 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/62/86562/1
diff --git a/src/cpu/intel/car/romstage.c b/src/cpu/intel/car/romstage.c index 63a83ab..a2dec35 100644 --- a/src/cpu/intel/car/romstage.c +++ b/src/cpu/intel/car/romstage.c @@ -15,14 +15,14 @@ /* If we do not have a constrained _car_stack region size, use the following as a guideline for acceptable stack usage. */ #define DCACHE_RAM_ROMSTAGE_STACK_SIZE 0x2000 +#define NUM_STACK_GUARDS 64 +#define STACK_GUARD 0xdeadbeef
-void __noreturn romstage_main(void) +static u32 *stack_guard_set(void) { int i; - const int num_guards = 64; - const u32 stack_guard = 0xdeadbeef; - u32 *stack_base; u32 size; + u32 *stack_base; const size_t stack_size = MAX(CONFIG_DCACHE_BSP_STACK_SIZE, DCACHE_RAM_ROMSTAGE_STACK_SIZE);
@@ -34,8 +34,33 @@ printk(BIOS_DEBUG, "Romstage stack size limited to 0x%x!\n", size);
+ /* Set stack guard */ stack_base = (u32 *)(_ecar_stack - size);
+ for (i = 0; i < NUM_STACK_GUARDS; i++) + stack_base[i] = STACK_GUARD; + + return stack_base; +} + +static void stack_guard_check(u32 *stack_base) +{ + int i; + + if (stack_base == NULL) { + die("Cannot check stack guard because NULL stack base.\n"); + } + + /* Check the stack. */ + for (i = 0; i < NUM_STACK_GUARDS; i++) { + if (stack_base[i] == STACK_GUARD) + continue; + printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); + } +} + +void __noreturn romstage_main(void) +{ /* Disable breakpoint since stack is intentionally corrupted */ stack_canary_breakpoint_remove();
@@ -51,8 +76,7 @@ * report the instruction pointer immediately, which can hint at which function * may be using too much stack. FSP might disable HW breakpoints, though. */ - for (i = 0; i < num_guards; i++) - stack_base[i] = stack_guard; + u32 *stack_base = stack_guard_set();
stack_canary_breakpoint_init();
@@ -73,12 +97,7 @@
mainboard_romstage_entry();
- /* Check the stack. */ - for (i = 0; i < num_guards; i++) { - if (stack_base[i] == stack_guard) - continue; - printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); - } + stack_guard_check(stack_base);
if (CONFIG(SMM_TSEG)) smm_list_regions();