mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
We are woefully unaware about how much stack v3 really uses.
This is a complete rewrite of my earlier stack checker proposal. It works for CAR and RAM, has better abstraction and actually gives us nice results. The stack checker is default off due to its rather measurable impact on boot speed. Diagnostic messages are printed on first initialization, directly after RAM init and directly before passing control to the payload. Sample qemu log is attached. Extract from that log follows: coreboot-3.0.986 Fri Nov 7 04:04:37 CET 2008 starting... (console_loglevel=8) Initial lowest stack is 0x0008fe98 Choosing fallback boot. [...] Done RAM init code After RAM init, lowest stack is 0x0008fe30 Done printk() buffer move [...] LAR: load_file_segments: Failed for normal/payload Before handoff to payload, lowest stack is 0x0008bf50 FATAL: No usable payload found. Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net> Acked-by: Peter Stuge <peter@stuge.se> git-svn-id: svn://coreboot.org/repository/coreboot-v3@1012 f3766cd6-281f-0410-b1cd-43a5c92072e9
This commit is contained in:
parent
35b5759efb
commit
cb9db3b6d0
5 changed files with 56 additions and 0 deletions
|
@ -239,4 +239,13 @@ config CARTEST
|
|||
help
|
||||
Test the CAR area after it has been set up.
|
||||
|
||||
config CHECK_STACK_USAGE
|
||||
bool "Check stack usage"
|
||||
default n
|
||||
help
|
||||
Continuously monitor stack usage and keep statistics.
|
||||
The monitoring code is invoked from printk because printk is
|
||||
a leaf function and consumes quite a bit of stack for itself.
|
||||
This slows down booting a LOT.
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -105,6 +105,28 @@ void global_vars_init(struct global_vars *globvars)
|
|||
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CHECK_STACK_USAGE
|
||||
/* STACKFILL_BYTE could be a special value like 0x6b. Just make sure the stage0
|
||||
* code fills the complete CAR area with it. And the stack switching needs to
|
||||
* overwrite the unused parts of the stack with STACKFILL_BYTE as well.
|
||||
*/
|
||||
#define STACKFILL_BYTE 0x0
|
||||
void check_stack()
|
||||
{
|
||||
unsigned long stacksize, i;
|
||||
char *lowestaddr;
|
||||
if (global_vars()->ram_available)
|
||||
stacksize = RAM_STACK_SIZE;
|
||||
else
|
||||
stacksize = CAR_STACK_SIZE;
|
||||
lowestaddr = bottom_of_stack() - stacksize;
|
||||
for (i = 0; i < stacksize; i++)
|
||||
if (lowestaddr[i] != STACKFILL_BYTE)
|
||||
break;
|
||||
global_vars()->loweststack = lowestaddr + i;
|
||||
}
|
||||
#endif
|
||||
|
||||
void dump_mem_range(int msg_level, unsigned char *buf, int size)
|
||||
{
|
||||
int i;
|
||||
|
@ -194,6 +216,10 @@ void __attribute__((stdcall)) stage1_phase1(u32 bist, u32 init_detected)
|
|||
*/
|
||||
console_init();
|
||||
|
||||
#ifdef CONFIG_CHECK_STACK_USAGE
|
||||
printk(BIOS_DEBUG, "Initial lowest stack is %p\n",
|
||||
global_vars()->loweststack);
|
||||
#endif
|
||||
if (bist!=0) {
|
||||
printk(BIOS_INFO, "BIST FAILED: %08x", bist);
|
||||
die("");
|
||||
|
@ -227,6 +253,10 @@ void __attribute__((stdcall)) stage1_phase1(u32 bist, u32 init_detected)
|
|||
die("Failed RAM init code\n");
|
||||
|
||||
printk(BIOS_DEBUG, "Done RAM init code\n");
|
||||
#ifdef CONFIG_CHECK_STACK_USAGE
|
||||
printk(BIOS_DEBUG, "After RAM init, lowest stack is %p\n",
|
||||
global_vars()->loweststack);
|
||||
#endif
|
||||
|
||||
/* Switch the stack location from CAR to RAM, rebuild the stack,
|
||||
* disable CAR and continue at stage1_phase3(). This is all wrapped in
|
||||
|
@ -299,6 +329,9 @@ void __attribute__((stdcall)) stage1_phase3(void)
|
|||
mem->map[0].type = LB_MEM_RAM;
|
||||
#endif /* CONFIG_PAYLOAD_ELF_LOADER */
|
||||
|
||||
/* Provide an easy way to check whether RAM is available. */
|
||||
global_vars()->ram_available = 1;
|
||||
|
||||
// location and size of image.
|
||||
init_archive(&archive);
|
||||
|
||||
|
@ -318,6 +351,10 @@ void __attribute__((stdcall)) stage1_phase3(void)
|
|||
#endif /* CONFIG_PAYLOAD_ELF_LOADER */
|
||||
|
||||
entry = load_file_segments(&archive, "normal/payload");
|
||||
#ifdef CONFIG_CHECK_STACK_USAGE
|
||||
printk(BIOS_DEBUG, "Before handoff to payload, lowest stack is %p\n",
|
||||
global_vars()->loweststack);
|
||||
#endif
|
||||
if (entry != (void*)-1) {
|
||||
/* Final coreboot call before handing off to the payload. */
|
||||
mainboard_pre_payload();
|
||||
|
|
|
@ -265,6 +265,7 @@ void * bottom_of_stack(void);
|
|||
EXPORT_SYMBOL(bottom_of_stack);
|
||||
struct global_vars * global_vars(void);
|
||||
EXPORT_SYMBOL(global_vars);
|
||||
void check_stack(void);
|
||||
|
||||
#define CAR_STACK_BASE (CONFIG_CARBASE + CONFIG_CARSIZE - 4)
|
||||
#define RAM_STACK_BASE 0x88ffc
|
||||
|
@ -278,6 +279,8 @@ EXPORT_SYMBOL(global_vars);
|
|||
#else
|
||||
#define CAR_STACK_SIZE (CONFIG_CARSIZE - 4)
|
||||
#endif
|
||||
/* To be honest, this limit is arbitrary and only used for stack checking. */
|
||||
#define RAM_STACK_SIZE (65536 - 4)
|
||||
|
||||
/* resource maps. These started out as special for the K8 but now have more general usage */
|
||||
/* it's not totally clear that the type and union are a great idea, but see the v2 code:
|
||||
|
|
|
@ -63,6 +63,10 @@ struct global_vars {
|
|||
struct sys_info sys_info;
|
||||
/* has the spd hardware been set up? */
|
||||
int spd_inited;
|
||||
int ram_available;
|
||||
#ifdef CONFIG_CHECK_STACK_USAGE
|
||||
void *loweststack;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* GLOBALVARS_H */
|
||||
|
|
|
@ -150,6 +150,9 @@ int printk(int msg_level, const char *fmt, ...)
|
|||
i += vtxprintf(console_tx_byte, (void *)0, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
#ifdef CONFIG_CHECK_STACK_USAGE
|
||||
check_stack();
|
||||
#endif
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue