[syslinux:firmware] core: Add firmware backend support

syslinux-bot for Matt Fleming matt.fleming at intel.com
Fri Nov 9 09:06:06 PST 2012


Commit-ID:  a941bb474f0c7044edb66eaed3199501215081a0
Gitweb:     http://www.syslinux.org/commit/a941bb474f0c7044edb66eaed3199501215081a0
Author:     Matt Fleming <matt.fleming at intel.com>
AuthorDate: Thu, 10 Nov 2011 10:23:27 +0000
Committer:  Matt Fleming <matt.fleming at intel.com>
CommitDate: Fri, 16 Dec 2011 16:31:18 +0000

core: Add firmware backend support

In an upcoming patch series we're going to need to abstract the
firmware operations because they will be provided by both BIOS and
EFI.

Signed-off-by: Matt Fleming <matt.fleming at intel.com>

---
 com32/include/syslinux/firmware.h |   15 +++++++++++++++
 com32/include/syslinux/memscan.h  |    1 +
 com32/lib/Makefile                |    2 +-
 com32/lib/syslinux/firmware.c     |   19 +++++++++++++++++++
 com32/lib/syslinux/memscan.c      |    8 +++++++-
 core/cleanup.c                    |   23 +++++++++++++++--------
 core/font.c                       |   13 +++++++------
 core/graphics.c                   |    2 +-
 core/init.c                       |   15 +++++++++++++--
 core/init.inc                     |    4 +++-
 core/mem/init.c                   |    2 +-
 core/pxelinux.asm                 |    2 +-
 core/timer.inc                    |    4 ++--
 13 files changed, 86 insertions(+), 24 deletions(-)

diff --git a/com32/include/syslinux/firmware.h b/com32/include/syslinux/firmware.h
new file mode 100644
index 0000000..edb0f94
--- /dev/null
+++ b/com32/include/syslinux/firmware.h
@@ -0,0 +1,15 @@
+#ifndef _SYSLINUX_FIRMWARE_H
+#define _SYSLINUX_FIRMWARE_H
+
+struct firmware {
+	void (*init)(void);
+	int (*scan_memory)(scan_memory_callback_t, void *);
+	void (*adjust_screen)(void);
+	void (*cleanup)(void);
+};
+
+extern struct firmware *firmware;
+
+extern void syslinux_register_bios(void);
+
+#endif /* _SYSLINUX_FIRMWARE_H */
diff --git a/com32/include/syslinux/memscan.h b/com32/include/syslinux/memscan.h
index db79543..c3ebf84 100644
--- a/com32/include/syslinux/memscan.h
+++ b/com32/include/syslinux/memscan.h
@@ -34,5 +34,6 @@
 
 typedef int (*scan_memory_callback_t) (void *, addr_t, addr_t, bool);
 int syslinux_scan_memory(scan_memory_callback_t callback, void *data);
+int bios_scan_memory(scan_memory_callback_t callback, void *data);
 
 #endif /* _SYSLINUX_MEMSCAN_H */
diff --git a/com32/lib/Makefile b/com32/lib/Makefile
index 10fb4de..11c7c48 100644
--- a/com32/lib/Makefile
+++ b/com32/lib/Makefile
@@ -169,7 +169,7 @@ LIBOTHER_OBJS = \
 	\
 	sys/x86_init_fpu.o math/pow.o math/strtod.o			\
 	\
-	syslinux/memscan.o
+	syslinux/memscan.o syslinux/firmware.o
 
 MINLIBOBJS = \
 	$(LIBOTHER_OBJS) \
diff --git a/com32/lib/syslinux/firmware.c b/com32/lib/syslinux/firmware.c
new file mode 100644
index 0000000..e5dc68b
--- /dev/null
+++ b/com32/lib/syslinux/firmware.c
@@ -0,0 +1,19 @@
+#include <sys/io.h>
+#include <fs.h>
+#include <syslinux/memscan.h>
+#include <bios.h>
+#include <syslinux/firmware.h>
+
+struct firmware *firmware = NULL;
+
+struct firmware bios_fw = {
+	.init = bios_init,
+	.scan_memory = bios_scan_memory,
+	.adjust_screen = bios_adjust_screen,
+	.cleanup = bios_cleanup_hardware,
+};
+
+void syslinux_register_bios(void)
+{
+	firmware = &bios_fw;
+}
diff --git a/com32/lib/syslinux/memscan.c b/com32/lib/syslinux/memscan.c
index fc676cb..ccd0e5c 100644
--- a/com32/lib/syslinux/memscan.c
+++ b/com32/lib/syslinux/memscan.c
@@ -40,6 +40,7 @@
 #include <com32.h>
 
 #include <syslinux/memscan.h>
+#include <syslinux/firmware.h>
 
 struct e820_entry {
     uint64_t start;
@@ -47,7 +48,7 @@ struct e820_entry {
     uint32_t type;
 };
 
-int syslinux_scan_memory(scan_memory_callback_t callback, void *data)
+int bios_scan_memory(scan_memory_callback_t callback, void *data)
 {
     static com32sys_t ireg;
     com32sys_t oreg;
@@ -156,3 +157,8 @@ int syslinux_scan_memory(scan_memory_callback_t callback, void *data)
 
     return 0;
 }
+
+int syslinux_scan_memory(scan_memory_callback_t callback, void *data)
+{
+	return firmware->scan_memory(callback, data);
+}
diff --git a/core/cleanup.c b/core/cleanup.c
index 7bf1df2..4abefcd 100644
--- a/core/cleanup.c
+++ b/core/cleanup.c
@@ -12,9 +12,11 @@
  */
 #include <com32.h>
 #include <core.h>
+#include <syslinux/memscan.h>
+#include <syslinux/firmware.h>
 
-extern void timer_cleanup(void);
 extern void comboot_cleanup_api(void);
+extern void bios_timer_cleanup(void);
 
 /*
  * cleanup.c
@@ -22,12 +24,7 @@ extern void comboot_cleanup_api(void);
  * Some final tidying before jumping to a kernel or bootsector
  */
 
-/*
- * cleanup_hardware:
- *
- *	Shut down anything transient.
- */
-void cleanup_hardware(void)
+void bios_cleanup_hardware(void)
 {
 	/*
 	 * TODO
@@ -39,8 +36,18 @@ void cleanup_hardware(void)
 	__intcall(0x13, &zero_regs, NULL);
 
 	call16(comboot_cleanup_api, &zero_regs, NULL);
-	call16(timer_cleanup, &zero_regs, NULL);
+	call16(bios_timer_cleanup, &zero_regs, NULL);
 
 	/* If we enabled serial port interrupts, clean them up now */
 	sirq_cleanup();
 }
+
+/*
+ * cleanup_hardware:
+ *
+ *	Shut down anything transient.
+ */
+void cleanup_hardware(void)
+{
+	firmware->cleanup();
+}
diff --git a/core/font.c b/core/font.c
index b14d3d2..ff98635 100644
--- a/core/font.c
+++ b/core/font.c
@@ -103,7 +103,7 @@ void loadfont(char *filename)
 /*
  * use_font:
  *	This routine activates whatever font happens to be in the
- *	vgafontbuf, and updates the adjust_screen data.
+ *	vgafontbuf, and updates the bios_adjust_screen data.
  *      Must be called with CS = DS
  */
 void use_font(void)
@@ -141,7 +141,7 @@ void use_font(void)
 			/* 8 pixels/character */
 			VidCols = ((GXPixCols >> 3) - 1);
 
-			/* No need to call adjust_screen */
+			/* No need to call bios_adjust_screen */
 			return;
 		} else {
 			ireg.eax.w[0] = 0x1110;	/* Load into VGA RAM */
@@ -156,16 +156,17 @@ void use_font(void)
 			ireg.eax.w[0] = 0x1103; /* Select page 0 */
 			__intcall(0x10, &ireg, NULL);
 		}
+
 	}
 
-	adjust_screen();
+	bios_adjust_screen();
 }
 
 /*
- * adjust_screen: Set the internal variables associated with the screen size.
+ * bios_adjust_screen: Set the internal variables associated with the screen size.
  *		This is a subroutine in case we're loading a custom font.
  */
-void adjust_screen(void)
+void bios_adjust_screen(void)
 {
 	com32sys_t ireg, oreg;
 	volatile uint8_t *vidrows = BIOS_vidrows;
@@ -191,5 +192,5 @@ void adjust_screen(void)
 
 void pm_adjust_screen(com32sys_t *regs)
 {
-	adjust_screen();
+	bios_adjust_screen();
 }
diff --git a/core/graphics.c b/core/graphics.c
index 864550b..ff3a189 100644
--- a/core/graphics.c
+++ b/core/graphics.c
@@ -370,7 +370,7 @@ void pm_usingvga(com32sys_t *regs)
 	if (UsingVGA & 0x08)
 		regs->eflags.l &= ~EFLAGS_CF;
 	else {
-		adjust_screen();
+		bios_adjust_screen();
 		set_flags(regs, EFLAGS_CF);
 	}
 }
diff --git a/core/init.c b/core/init.c
index c1ba298..46492c5 100644
--- a/core/init.c
+++ b/core/init.c
@@ -4,6 +4,9 @@
 #include <fs.h>
 #include <bios.h>
 
+#include <syslinux/memscan.h>
+#include <syslinux/firmware.h>
+
 static uint16_t min_lowmem_heap = 65536;
 extern char __lowmem_heap[];
 uint8_t KbdFlags;		/* Check for keyboard escapes */
@@ -61,7 +64,9 @@ static inline void bios_timer_init(void)
 	*hook = &timer_irq;
 }
 
-void init(com32sys_t *regs)
+extern uint8_t KbdMap[];
+extern uint8_t bios_free_mem;
+void bios_init(void)
 {
 	int i;
 
@@ -71,12 +76,18 @@ void init(com32sys_t *regs)
 	for (i = 0; i < 256; i++)
 		KbdMap[i] = i;
 
-	adjust_screen();
+	bios_adjust_screen();
 	printf_init();
 
 	/* Init the memory subsystem */
+	bios_free_mem = (uint16_t *)0x413;
 	mem_init();
 
 	/* CPU-dependent initialization and related checks. */
 	check_escapes();
 }
+
+void init(com32sys_t *regs)
+{
+	firmware->init();
+}
diff --git a/core/init.inc b/core/init.inc
index 286b380..4ee68b2 100644
--- a/core/init.inc
+++ b/core/init.inc
@@ -28,7 +28,9 @@ common_init:
 		cmp eax,__pm_code_len
 		jne kaboom
 
-		extern init
+		extern syslinux_register_bios, init
+
+		pm_call syslinux_register_bios
 		pm_call init
 
 ;
diff --git a/core/mem/init.c b/core/mem/init.c
index 2951bb0..39a34e3 100644
--- a/core/mem/init.c
+++ b/core/mem/init.c
@@ -66,11 +66,11 @@ static void mpool_dump(enum heap heap)
 }
 #endif
 
+uint16_t *bios_free_mem;
 void mem_init(void)
 {
 	struct free_arena_header *fp;
 	int i;
-	uint16_t *bios_free_mem = (uint16_t *)0x413;
 
 	//dprintf("enter");
 
diff --git a/core/pxelinux.asm b/core/pxelinux.asm
index 68cb864..e4c2f83 100644
--- a/core/pxelinux.asm
+++ b/core/pxelinux.asm
@@ -341,7 +341,7 @@ pxenv:
 		jnz .store_stack
 
 .disable_timer:
-		call timer_cleanup
+		call bios_timer_cleanup
 
 .store_stack:
 		mov [cs:PXEStack],sp
diff --git a/core/timer.inc b/core/timer.inc
index 2bf0a21..9f42fdf 100644
--- a/core/timer.inc
+++ b/core/timer.inc
@@ -32,8 +32,8 @@ timer_init:
 		mov dword [BIOS_timer_hook],timer_irq
 		ret
 
-		global timer_cleanup
-timer_cleanup:
+		global bios_timer_cleanup
+bios_timer_cleanup:
 		; Unhook INT 1Ch
 		mov eax,[BIOS_timer_next]
 		mov [BIOS_timer_hook],eax


More information about the Syslinux-commits mailing list