drivers/intel/fsp1_1: Add stack guards

This allows to check if stack overflows the car globals.

Change-Id: I369b2d846f35914facb3e69cc762f7e555271bec
Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Reviewed-on: https://review.coreboot.org/c/30751
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Arthur Heymans 2019-01-08 23:25:04 +01:00 committed by Patrick Georgi
parent 0421ea277c
commit 61b22cb930
1 changed files with 22 additions and 0 deletions

View File

@ -35,6 +35,21 @@ static inline void set_fih_car(FSP_INFO_HEADER *fih)
asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params)
{
int i;
const int num_guards = 4;
const u32 stack_guard = 0xdeadbeef;
u32 *stack_base;
u32 size;
/* Size of unallocated CAR. */
size = _car_region_end - _car_relocatable_data_end;
size = ALIGN_DOWN(size, 16);
stack_base = (u32 *) (_car_region_end - size);
for (i = 0; i < num_guards; i++)
stack_base[i] = stack_guard;
/* Initialize timestamp book keeping only once. */
timestamp_init(car_params->tsc);
@ -63,6 +78,13 @@ asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params)
set_fih_car(car_params->fih);
/* 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");
}
/* Return new stack value in RAM back to assembly stub. */
return cache_as_ram_stage_main(car_params->fih);
}