core: Add firmware backend support
authorMatt Fleming <matt.fleming@intel.com>
Thu, 10 Nov 2011 10:23:27 +0000 (10:23 +0000)
committerMatt Fleming <matt.fleming@intel.com>
Fri, 16 Dec 2011 16:31:18 +0000 (16:31 +0000)
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@intel.com>
13 files changed:
com32/include/syslinux/firmware.h [new file with mode: 0644]
com32/include/syslinux/memscan.h
com32/lib/Makefile
com32/lib/syslinux/firmware.c [new file with mode: 0644]
com32/lib/syslinux/memscan.c
core/cleanup.c
core/font.c
core/graphics.c
core/init.c
core/init.inc
core/mem/init.c
core/pxelinux.asm
core/timer.inc

diff --git a/com32/include/syslinux/firmware.h b/com32/include/syslinux/firmware.h
new file mode 100644 (file)
index 0000000..edb0f94
--- /dev/null
@@ -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 */
index db79543..c3ebf84 100644 (file)
@@ -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 */
index 10fb4de..11c7c48 100644 (file)
@@ -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 (file)
index 0000000..e5dc68b
--- /dev/null
@@ -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;
+}
index fc676cb..ccd0e5c 100644 (file)
@@ -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);
+}
index 7bf1df2..4abefcd 100644 (file)
  */
 #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();
+}
index b14d3d2..ff98635 100644 (file)
@@ -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();
 }
index 864550b..ff3a189 100644 (file)
@@ -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);
        }
 }
index c1ba298..46492c5 100644 (file)
@@ -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();
+}
index 286b380..4ee68b2 100644 (file)
@@ -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
 
 ;
index 2951bb0..39a34e3 100644 (file)
@@ -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");
 
index 68cb864..e4c2f83 100644 (file)
@@ -341,7 +341,7 @@ pxenv:
                jnz .store_stack
 
 .disable_timer:
-               call timer_cleanup
+               call bios_timer_cleanup
 
 .store_stack:
                mov [cs:PXEStack],sp
index 2bf0a21..9f42fdf 100644 (file)
@@ -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