[coreboot] [PATCH] v3: determine global variable location
Carl-Daniel Hailfinger
c-d.hailfinger.devel.2006 at gmx.net
Wed Oct 15 02:39:57 CEST 2008
We need a way to find out where our stack and our global variables are
at any given moment. This is a first generic try, but doing this in a
processor-specific way would be more appropriate.
Please note that this needs a new #define or Kconfig variable somewhere:
CONFIG_RAM_STACK_LOCATION. As an alternative, we could declare the top
of memory as optimal stack location.
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006 at gmx.net>
Index: corebootv3-globalvariablelocation/arch/x86/stage1.c
===================================================================
--- corebootv3-globalvariablelocation/arch/x86/stage1.c (Revision 925)
+++ corebootv3-globalvariablelocation/arch/x86/stage1.c (Arbeitskopie)
@@ -70,11 +70,22 @@
/*
* 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 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 >= CONFIG_CARBASE) &&
+ (onstack < CONFIG_CARBASE + CONFIG_CARSIZE - 4))
+ /* CONFIG_CARBASE + CONFIG_CARSIZE - 4 is initial %esp */
+ return (void *)(CONFIG_CARBASE + CONFIG_CARSIZE - 4);
+ /* OK, so current %esp is not inside the CAR area. */
+ return (void *) CONFIG_RAM_STACK_LOCATION;
}
struct global_vars *global_vars(void)
--
http://www.hailfinger.org/
More information about the coreboot
mailing list