[coreboot] Patch set updated for coreboot: c926200 Clean up stack checking code

Stefan Reinauer (stefan.reinauer@coreboot.org) gerrit at coreboot.org
Tue Nov 13 00:19:35 CET 2012


Stefan Reinauer (stefan.reinauer at coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/1787

-gerrit

commit c926200f9807578e48a45f54831a0c582f1981cf
Author: Stefan Reinauer <reinauer at chromium.org>
Date:   Mon Oct 15 15:19:43 2012 -0700

    Clean up stack checking code
    
    Several small improvements of the stack checking code:
    - move the CPU0 stack check right before jumping to the payload
      and out of hardwaremain (that file is too crowded anyways)
    - fix prototype in lib.h
    - print size of used stack
    - use checkstack function both on CPU0 and CPU1-x
    - print amount of stack used per core
    
    Signed-off-by: Stefan Reinauer <reinauer at google.com>
    
    Test: Boot coreboot on Link, see the following output:
         ...
         CPU1: stack: 00156000 - 00157000, lowest used address 00156c68,
               stack used: 920 bytes
         CPU2: stack: 00155000 - 00156000, lowest used address 00155c68,
               stack used: 920 bytes
         CPU3: stack: 00154000 - 00155000, lowest used address 00154c68,
               stack used: 920 bytes
         ...
         Jumping to boot code at 1110008
         CPU0: stack: 00157000 - 00158000, lowest used address 00157af8,
               stack used: 1288 bytes
    
    Change-Id: I7b83eeee0186559a0a62daa12e3f7782990fd2df
---
 src/boot/hardwaremain.c            |  6 ------
 src/boot/selfboot.c                |  5 +++++
 src/cpu/x86/lapic/lapic_cpu_init.c | 19 +++----------------
 src/include/lib.h                  |  4 ++--
 src/lib/stack.c                    | 14 ++++++++------
 5 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/src/boot/hardwaremain.c b/src/boot/hardwaremain.c
index b08fe79..51936c4 100644
--- a/src/boot/hardwaremain.c
+++ b/src/boot/hardwaremain.c
@@ -155,12 +155,6 @@ void hardwaremain(int boot_complete)
 	if (! payload)
 		die("Could not find a payload\n");
 
-	printk(BIOS_DEBUG, "Got a payload\n");
-	/* Before we go off to run the payload, see if
-	 * we stayed within our bounds.
-	 */
-	checkstack(&_estack, 0);
-
 	selfboot(lb_mem, payload);
 	printk(BIOS_EMERG, "Boot failed");
 }
diff --git a/src/boot/selfboot.c b/src/boot/selfboot.c
index fd5b382..2556a14 100644
--- a/src/boot/selfboot.c
+++ b/src/boot/selfboot.c
@@ -519,6 +519,11 @@ int selfboot(struct lb_memory *mem, struct cbfs_payload *payload)
 	timestamp_add_now(TS_SELFBOOT_JUMP);
 #endif
 
+	/* Before we go off to run the payload, see if
+	 * we stayed within our bounds.
+	 */
+	checkstack(_estack, 0);
+
 	/* Jump to kernel */
 	jmp_to_elf_entry((void*)entry, bounce_buffer, bounce_size);
 	return 1;
diff --git a/src/cpu/x86/lapic/lapic_cpu_init.c b/src/cpu/x86/lapic/lapic_cpu_init.c
index 6c01d8c..621990c 100644
--- a/src/cpu/x86/lapic/lapic_cpu_init.c
+++ b/src/cpu/x86/lapic/lapic_cpu_init.c
@@ -22,6 +22,7 @@
 
 #include <cpu/x86/lapic.h>
 #include <delay.h>
+#include <lib.h>
 #include <string.h>
 #include <console/console.h>
 #include <arch/hlt.h>
@@ -240,7 +241,6 @@ volatile unsigned int secondary_cpu_index;
 
 int start_cpu(device_t cpu)
 {
-	extern unsigned char _estack[];
 	struct cpu_info *info;
 	unsigned long stack_end;
 	unsigned long stack_base;
@@ -503,21 +503,8 @@ static void wait_other_cpus_stop(struct bus *cpu_bus)
 		}
 	}
 	printk(BIOS_DEBUG, "All AP CPUs stopped (%ld loops)\n", loopcount);
-	for(i = 1; i <= last_cpu_index; i++){
-		unsigned long *stack = stacks[i];
-		int lowest;
-		int maxstack = (CONFIG_STACK_SIZE - sizeof(struct cpu_info))
-					/sizeof(*stack) - 1;
-		if (stack[0] != 0xDEADBEEF)
-			printk(BIOS_ERR, "CPU%d overran its stack\n", i);
-		for(lowest = 0; lowest < maxstack; lowest++)
-			if (stack[lowest] != 0xDEADBEEF)
-				break;
-		printk(BIOS_SPEW, "CPU%d: stack allocated from %p to %p:", i,
-			stack, &stack[maxstack]);
-		printk(BIOS_SPEW, "lowest stack address was %p\n",
-			&stack[lowest]);
-	}
+	for(i = 1; i <= last_cpu_index; i++)
+		checkstack((void *)stacks[i] + CONFIG_STACK_SIZE, i);
 }
 
 #endif /* CONFIG_SMP */
diff --git a/src/include/lib.h b/src/include/lib.h
index b2f38a8..9d81085 100644
--- a/src/include/lib.h
+++ b/src/include/lib.h
@@ -41,10 +41,10 @@ int ram_check_nodie(unsigned long start, unsigned long stop);
 void quick_ram_check(void);
 
 /* Defined in src/lib/stack.c */
-int checkstack(void *top_of_stack, int stacksize);
+int checkstack(void *top_of_stack, int core);
 
 /* currently defined by a ldscript */
-extern u8 _estack;
+extern unsigned char _estack[];
 
 /* Defined in romstage.c */
 #if CONFIG_CPU_AMD_GEODE_LX
diff --git a/src/lib/stack.c b/src/lib/stack.c
index 3f04b63..0a6637f 100644
--- a/src/lib/stack.c
+++ b/src/lib/stack.c
@@ -35,15 +35,17 @@ int checkstack(void *top_of_stack, int core)
 		return -1;
 	}
 
-	for(i = 0; i < CONFIG_STACK_SIZE/sizeof(stack[0]); i++){
+	for(i = 1; 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,
+		printk(BIOS_SPEW, "CPU%d: stack: %p - %p, ",
+			core, stack,
 			&stack[CONFIG_STACK_SIZE/sizeof(stack[0])]);
-		printk(BIOS_SPEW, "Lowest stack address %p\n", &stack[i]);
-		return -1;
+		printk(BIOS_SPEW, "lowest used address %p, ", &stack[i]);
+		printk(BIOS_SPEW, "stack used: %ld bytes\n",
+			(unsigned long)&stack[CONFIG_STACK_SIZE /
+			sizeof(stack[0])] - (unsigned long)&stack[i]);
+		return 0;
 	}
 
 	return 0;




More information about the coreboot mailing list