[coreboot] [PATCH] v3: determine global variable location

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Thu Oct 16 03:37:34 CEST 2008


New version which takes into account everything mentioned in the discussion.

We need a way to find out where our stack and our global variables are
at any given moment. The code is generic enough to handle this in a
processor-specific way behind the scenes if needed.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>

Index: corebootv3-globalvariablelocation/include/arch/x86/cpu.h
===================================================================
--- corebootv3-globalvariablelocation/include/arch/x86/cpu.h	(Revision 931)
+++ corebootv3-globalvariablelocation/include/arch/x86/cpu.h	(Arbeitskopie)
@@ -266,11 +266,17 @@
 struct global_vars * global_vars(void);
 EXPORT_SYMBOL(global_vars);
 
+#define CAR_STACK_BASE (CONFIG_CARBASE + CONFIG_CARSIZE - 4)
+#define RAM_STACK_BASE 0x88ffc
+
 #ifdef CONFIG_CONSOLE_BUFFER
 #define PRINTK_BUF_SIZE_CAR (CONFIG_CARSIZE / 2)
 #define PRINTK_BUF_ADDR_CAR CONFIG_CARBASE
 #define PRINTK_BUF_SIZE_RAM 65536
 #define PRINTK_BUF_ADDR_RAM 0x90000
+#define CAR_STACK_SIZE ((CONFIG_CARSIZE / 2) - 4)
+#else
+#define CAR_STACK_SIZE (CONFIG_CARSIZE - 4)
 #endif
 
 /* resource maps. These started out as special for the K8 but now have more general usage */
Index: corebootv3-globalvariablelocation/arch/x86/stage1.c
===================================================================
--- corebootv3-globalvariablelocation/arch/x86/stage1.c	(Revision 931)
+++ corebootv3-globalvariablelocation/arch/x86/stage1.c	(Arbeitskopie)
@@ -70,11 +70,21 @@
 /*
  * The name is slightly misleading because this is the initial stack pointer,
  * not the address of the first element on the stack.
+ * NOTE: This function is very processor specific.
  */
 void *bottom_of_stack(void)
 {
-	/* -4 because CONFIG_CARBASE + CONFIG_CARSIZE - 4 is initial %esp */
-	return (void *)(CONFIG_CARBASE + CONFIG_CARSIZE - 4);
+	u32 onstack = (u32)&onstack;
+
+	/* Check whether the variable onstack is inside the CAR stack area.
+	 * If it is, assume we're still in CAR or the stack has not moved.
+	 * Otherwise return initial %esp for the RAM-based stack location.
+	 */
+	if ((onstack >= CAR_STACK_BASE - CAR_STACK_SIZE) &&
+	    (onstack < CAR_STACK_BASE))
+		return (void *)CAR_STACK_BASE;
+	/* OK, so current %esp is not inside the CAR stack area. */
+	return (void *)RAM_STACK_BASE;
 }
 
 struct global_vars *global_vars(void)



-- 
http://www.hailfinger.org/





More information about the coreboot mailing list