[coreboot] [PATCH] v3: introduce generic global variable storage

Carl-Daniel Hailfinger c-d.hailfinger.devel.2006 at gmx.net
Sun Aug 10 02:45:24 CEST 2008


Introduce a generic global variable storage mechanism and switch the
printk buffer management to it.

Build tested and boot tested and result tested on Qemu.

Please note the following pitfalls:
- Adding a new global variable is not as easy as it looks.
- Don't try to add one without consulting me.

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

Index: corebootv3-global_vars/include/console.h
===================================================================
--- corebootv3-global_vars/include/console.h	(Revision 730)
+++ corebootv3-global_vars/include/console.h	(Arbeitskopie)
@@ -60,6 +60,12 @@
 };
 #endif
 
+struct global_vars {
+#ifdef CONFIG_CONSOLE_BUFFER
+	struct printk_buffer *printk_buffer;
+#endif
+};
+
 SHARED_WITH_ATTRIBUTES(printk, int, __attribute__((format (printf, 2, 3))),
 					int msg_level, const char *fmt, ...);
 SHARED(banner, void, int msg_level, const char *msg);
Index: corebootv3-global_vars/include/arch/x86/cpu.h
===================================================================
--- corebootv3-global_vars/include/arch/x86/cpu.h	(Revision 730)
+++ corebootv3-global_vars/include/arch/x86/cpu.h	(Arbeitskopie)
@@ -198,6 +198,7 @@
 }
 
 SHARED(bottom_of_stack, void *, void);
+SHARED(global_vars, struct global_vars *, void);
 
 #ifdef CONFIG_CONSOLE_BUFFER
 #define PRINTK_BUF_SIZE_CAR (CONFIG_CARSIZE / 2)
Index: corebootv3-global_vars/lib/console.c
===================================================================
--- corebootv3-global_vars/lib/console.c	(Revision 730)
+++ corebootv3-global_vars/lib/console.c	(Arbeitskopie)
@@ -35,13 +35,16 @@
 }
 
 #ifdef CONFIG_CONSOLE_BUFFER
+struct printk_buffer *printk_buffer_addr(void)
+{
+	return global_vars()->printk_buffer;
+}
+
 void printk_buffer_move(void *newaddr, int newsize)
 {
-	struct printk_buffer **p;
 	struct printk_buffer *oldbuf, *newbuf;
 	int copylen;
-	p = bottom_of_stack();
-	oldbuf = *p;
+	oldbuf = printk_buffer_addr();
 	newbuf = newaddr;
 	newbuf->len = newsize;
 	newbuf->readoffset = 0;
@@ -68,17 +71,10 @@
 			&oldbuf->buffer[0], copylen);
 		newbuf->writeoffset += copylen;
 	}
-	*p = newbuf;
+	global_vars()->printk_buffer = newbuf;
 	return;
 }
 
-struct printk_buffer *printk_buffer_addr(void)
-{
-	struct printk_buffer **p;
-	p = bottom_of_stack();
-	return *p;
-}
-
 void printk_buffer_init(void)
 {
 	struct printk_buffer *buf = printk_buffer_addr();
Index: corebootv3-global_vars/arch/x86/stage1.c
===================================================================
--- corebootv3-global_vars/arch/x86/stage1.c	(Revision 730)
+++ corebootv3-global_vars/arch/x86/stage1.c	(Arbeitskopie)
@@ -70,12 +70,21 @@
 
 }
 
+/*
+ * The name is slightly misleading because this is the initial stack pointer,
+ * not the address of the first element on the stack.
+ */
 void *bottom_of_stack(void)
 {
-	/* -4-4 because CONFIG_CARBASE + CONFIG_CARSIZE - 4 is initial %esp */
-	return (void *)(CONFIG_CARBASE + CONFIG_CARSIZE - 4 - 4);
+	/* -4 because CONFIG_CARBASE + CONFIG_CARSIZE - 4 is initial %esp */
+	return (void *)(CONFIG_CARBASE + CONFIG_CARSIZE - 4);
 }
 
+struct global_vars *global_vars(void)
+{
+	return (struct global_vars *)(bottom_of_stack() - sizeof(struct global_vars));
+}
+
 void dump_mem_range(int msg_level, unsigned char *buf, int size)
 {
 	int i;


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

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: linuxbios3_global_vars.diff
URL: <http://www.coreboot.org/pipermail/coreboot/attachments/20080810/d775c95c/attachment.ksh>


More information about the coreboot mailing list