Implement stack overflow checking for the BSP

Previous patches implemented stack overflow checking for the APs.
This patch builds on the BSP stack poisoning patch to implement
stack overflow checking for the BSP, and also prints out maximum
stack usage. It reveals that our 32K stack is ridiculously oversized,
especially now that the lzma decoder doesn't use a giant 16K on-stack
array.

Break the stack checking out into a separate function, which
we will later use for the APs.

CPU0: stack from 00180000 to 00188000:Lowest stack address 00187ad8

To test failure, change the DEADBEEF stack poison value in c_start.S
to something else. Then we should get an error like this:
Stack overrun on BSP.Increase stack from current 32768 bytes
CPU0: stack from 00180000 to 00188000:Lowest stack address 00180000

Separate the act of loading from the act of starting the payload. This
allows us better error management and reporting of stack use. Now we
see:
CPU0: stack from 00180000 to 00188000:Lowest stack address 00187ad8

Tested for both success and failure on Link. At the same time, feel free
to carefully check my manipulation of _estack.

Change-Id: Ibb09738b15ec6a5510ac81e45dd82756bfa5aac2
Signed-off-by: Ronald G. Minnich <rminnich@chromium.org>
Reviewed-on: http://review.coreboot.org/1286
Tested-by: build bot (Jenkins)
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
This commit is contained in:
Ronald G. Minnich
2012-06-12 16:29:32 -07:00
committed by Ronald G. Minnich
parent 9842ad8ac5
commit 9764d4c690
6 changed files with 77 additions and 11 deletions

51
src/lib/stack.c Normal file
View File

@ -0,0 +1,51 @@
/*
This software and ancillary information (herein called SOFTWARE )
called LinuxBIOS is made available under the terms described
here. The SOFTWARE has been approved for release with associated
LA-CC Number 00-34 . Unless otherwise indicated, this SOFTWARE has
been authored by an employee or employees of the University of
California, operator of the Los Alamos National Laboratory under
Contract No. W-7405-ENG-36 with the U.S. Department of Energy. The
U.S. Government has rights to use, reproduce, and distribute this
SOFTWARE. The public may copy, distribute, prepare derivative works
and publicly display this SOFTWARE without charge, provided that this
Notice and any statement of authorship are reproduced on all copies.
Neither the Government nor the University makes any warranty, express
or implied, or assumes any liability or responsibility for the use of
this SOFTWARE. If SOFTWARE is modified to produce derivative works,
such modified SOFTWARE should be clearly marked, so as not to confuse
it with the version available from LANL.
*/
/* Copyright 2000, Ron Minnich, Advanced Computing Lab, LANL
* rminnich@lanl.gov
*/
#include <lib.h>
#include <console/console.h>
int checkstack(void *top_of_stack, int core)
{
int i;
u32 *stack = (u32 *) (top_of_stack - CONFIG_STACK_SIZE);
if (stack[0] != 0xDEADBEEF){
printk(BIOS_ERR, "Stack overrun on CPU%d."
"Increase stack from current %d bytes\n",
CONFIG_STACK_SIZE, core);
return -1;
}
for(i = 0; i < CONFIG_STACK_SIZE/sizeof(stack[0]); i++){
if (stack[i] == 0xDEADBEEF)
continue;
printk(BIOS_SPEW, "CPU%d: stack from %p to %p:",
core,
stack,
&stack[CONFIG_STACK_SIZE/sizeof(stack[0])]);
printk(BIOS_SPEW, "Lowest stack address %p\n", &stack[i]);
return -1;
}
return 0;
}