vgabios: Move initialization code to new file vgainit.c.

Move the initialization code out of vgabios.c to a new file to reduce
the size of the vgabios.c file.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
diff --git a/Makefile b/Makefile
index 59aae99..8a3c9d1 100644
--- a/Makefile
+++ b/Makefile
@@ -202,7 +202,8 @@
 
 # VGA src files
 SRCVGA=src/output.c src/string.c src/hw/pci.c src/hw/serialio.c \
-    vgasrc/vgabios.c vgasrc/vgafb.c vgasrc/vgafonts.c vgasrc/vbe.c \
+    vgasrc/vgainit.c vgasrc/vgabios.c vgasrc/vgafb.c \
+    vgasrc/vgafonts.c vgasrc/vbe.c \
     vgasrc/stdvga.c vgasrc/stdvgamodes.c vgasrc/stdvgaio.c \
     vgasrc/clext.c vgasrc/bochsvga.c vgasrc/geodevga.c
 
diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c
index d93b190..57f1c1f 100644
--- a/vgasrc/vgabios.c
+++ b/vgasrc/vgabios.c
@@ -1,6 +1,6 @@
 // VGA bios implementation
 //
-// Copyright (C) 2009-2012  Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2009-2013  Kevin O'Connor <kevin@koconnor.net>
 // Copyright (C) 2001-2008 the LGPL VGABios developers Team
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
@@ -9,48 +9,13 @@
 #include "bregs.h" // struct bregs
 #include "clext.h" // clext_1012
 #include "config.h" // CONFIG_*
-#include "hw/pci.h" // pci_config_readw
-#include "hw/pci_regs.h" // PCI_VENDOR_ID
 #include "output.h" // dprintf
-#include "std/optionrom.h" // struct pci_data
-#include "std/pmm.h" // struct pmmheader
 #include "std/vbe.h" // VBE_RETURN_STATUS_FAILED
 #include "stdvga.h" // stdvga_set_cursor_shape
 #include "string.h" // memset_far
-#include "util.h" // VERSION
 #include "vgabios.h" // calc_page_size
 #include "vgahw.h" // vgahw_set_mode
 
-// Standard Video Save Pointer Table
-struct VideoSavePointer_s {
-    struct segoff_s videoparam;
-    struct segoff_s paramdynamicsave;
-    struct segoff_s textcharset;
-    struct segoff_s graphcharset;
-    struct segoff_s secsavepointer;
-    u8 reserved[8];
-} PACKED;
-
-static struct VideoSavePointer_s video_save_pointer_table VAR16;
-
-struct VideoParam_s video_param_table[29] VAR16;
-
-
-/****************************************************************
- * PCI Data
- ****************************************************************/
-
-struct pci_data rom_pci_data VAR16 VISIBLE16 = {
-    .signature = PCI_ROM_SIGNATURE,
-    .vendor = CONFIG_VGA_VID,
-    .device = CONFIG_VGA_DID,
-    .dlen = 0x18,
-    .class_hi = 0x300,
-    .irevision = 1,
-    .type = PCIROM_CODETYPE_X86,
-    .indicator = 0x80,
-};
-
 
 /****************************************************************
  * Helper functions
@@ -1249,120 +1214,3 @@
     default:   handle_10XX(regs); break;
     }
 }
-
-
-/****************************************************************
- * VGA post
- ****************************************************************/
-
-static void
-init_bios_area(void)
-{
-    // init detected hardware BIOS Area
-    // set 80x25 color (not clear from RBIL but usual)
-    set_equipment_flags(0x30, 0x20);
-
-    // the default char height
-    SET_BDA(char_height, 0x10);
-
-    // Clear the screen
-    SET_BDA(video_ctl, 0x60);
-
-    // Set the basic screen we have
-    SET_BDA(video_switches, 0xf9);
-
-    // Set the basic modeset options
-    SET_BDA(modeset_ctl, 0x51);
-
-    // Set the  default MSR
-    SET_BDA(video_msr, 0x09);
-}
-
-u16 ExtraStackSeg VAR16 VISIBLE16;
-
-static void
-allocate_extra_stack(void)
-{
-    if (!CONFIG_VGA_ALLOCATE_EXTRA_STACK)
-        return;
-    void *pmmscan = (void*)BUILD_BIOS_ADDR;
-    for (; pmmscan < (void*)BUILD_BIOS_ADDR+BUILD_BIOS_SIZE; pmmscan+=16) {
-        struct pmmheader *pmm = pmmscan;
-        if (pmm->signature != PMM_SIGNATURE)
-            continue;
-        if (checksum_far(0, pmm, pmm->length))
-            continue;
-        struct segoff_s entry = pmm->entry;
-        dprintf(1, "Attempting to allocate VGA stack via pmm call to %04x:%04x\n"
-                , entry.seg, entry.offset);
-        u16 res1, res2;
-        asm volatile(
-            "pushl %0\n"
-            "pushw $(8|1)\n"            // Permanent low memory request
-            "pushl $0xffffffff\n"       // Anonymous handle
-            "pushl $" __stringify(CONFIG_VGA_EXTRA_STACK_SIZE) "\n"
-            "pushw $0x00\n"             // PMM allocation request
-            "lcallw *12(%%esp)\n"
-            "addl $16, %%esp\n"
-            "cli\n"
-            "cld\n"
-            : "+r" (entry.segoff), "=a" (res1), "=d" (res2) : : "cc", "memory");
-        u32 res = res1 | (res2 << 16);
-        if (!res || res == PMM_FUNCTION_NOT_SUPPORTED)
-            return;
-        dprintf(1, "VGA stack allocated at %x\n", res);
-        SET_VGA(ExtraStackSeg, res >> 4);
-        extern void entry_10_extrastack(void);
-        SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10_extrastack));
-        return;
-    }
-}
-
-int VgaBDF VAR16 = -1;
-int HaveRunInit VAR16;
-
-void VISIBLE16
-vga_post(struct bregs *regs)
-{
-    debug_preinit();
-    dprintf(1, "Start SeaVGABIOS (version %s)\n", VERSION);
-    debug_enter(regs, DEBUG_VGA_POST);
-
-    if (CONFIG_VGA_PCI && !GET_GLOBAL(HaveRunInit)) {
-        u16 bdf = regs->ax;
-        if ((pci_config_readw(bdf, PCI_VENDOR_ID)
-             == GET_GLOBAL(rom_pci_data.vendor))
-            && (pci_config_readw(bdf, PCI_DEVICE_ID)
-                == GET_GLOBAL(rom_pci_data.device)))
-            SET_VGA(VgaBDF, bdf);
-    }
-
-    int ret = vgahw_setup();
-    if (ret) {
-        dprintf(1, "Failed to initialize VGA hardware.  Exiting.\n");
-        return;
-    }
-
-    if (GET_GLOBAL(HaveRunInit))
-        return;
-
-    init_bios_area();
-
-    SET_VGA(video_save_pointer_table.videoparam
-            , SEGOFF(get_global_seg(), (u32)video_param_table));
-    stdvga_build_video_param();
-
-    extern void entry_10(void);
-    SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
-
-    allocate_extra_stack();
-
-    SET_VGA(HaveRunInit, 1);
-
-    // Fixup checksum
-    extern u8 _rom_header_size, _rom_header_checksum;
-    SET_VGA(_rom_header_checksum, 0);
-    u8 sum = -checksum_far(get_global_seg(), 0,
-                           GET_GLOBAL(_rom_header_size) * 512);
-    SET_VGA(_rom_header_checksum, sum);
-}
diff --git a/vgasrc/vgabios.h b/vgasrc/vgabios.h
index 5adbf4b..800b61f 100644
--- a/vgasrc/vgabios.h
+++ b/vgasrc/vgabios.h
@@ -78,6 +78,9 @@
 #define DEBUG_VGA_POST 1
 #define DEBUG_VGA_10 3
 
+// vgainit.c
+extern struct VideoSavePointer_s video_save_pointer_table;
+
 // vgabios.c
 extern int VgaBDF;
 extern int HaveRunInit;
diff --git a/vgasrc/vgaentry.S b/vgasrc/vgaentry.S
index 1d2fe92..35747b7 100644
--- a/vgasrc/vgaentry.S
+++ b/vgasrc/vgaentry.S
@@ -1,6 +1,6 @@
 // Rom layout and bios assembler to C interface.
 //
-// Copyright (C) 2009-2012  Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2009-2013  Kevin O'Connor <kevin@koconnor.net>
 //
 // This file may be distributed under the terms of the GNU LGPLv3 license.
 
diff --git a/vgasrc/vgainit.c b/vgasrc/vgainit.c
new file mode 100644
index 0000000..7b01e03
--- /dev/null
+++ b/vgasrc/vgainit.c
@@ -0,0 +1,170 @@
+// Main VGA bios initialization
+//
+// Copyright (C) 2009-2013  Kevin O'Connor <kevin@koconnor.net>
+// Copyright (C) 2001-2008 the LGPL VGABios developers Team
+//
+// This file may be distributed under the terms of the GNU LGPLv3 license.
+
+#include "biosvar.h" // SET_BDA
+#include "bregs.h" // struct bregs
+#include "hw/pci.h" // pci_config_readw
+#include "hw/pci_regs.h" // PCI_VENDOR_ID
+#include "output.h" // dprintf
+#include "std/optionrom.h" // struct pci_data
+#include "std/pmm.h" // struct pmmheader
+#include "string.h" // checksum_far
+#include "util.h" // VERSION
+#include "vgabios.h" // struct VideoSavePointer_s
+#include "vgahw.h" // vgahw_setup
+
+// Standard Video Save Pointer Table
+struct VideoSavePointer_s {
+    struct segoff_s videoparam;
+    struct segoff_s paramdynamicsave;
+    struct segoff_s textcharset;
+    struct segoff_s graphcharset;
+    struct segoff_s secsavepointer;
+    u8 reserved[8];
+} PACKED;
+
+struct VideoSavePointer_s video_save_pointer_table VAR16;
+
+struct VideoParam_s video_param_table[29] VAR16;
+
+
+/****************************************************************
+ * PCI Data
+ ****************************************************************/
+
+struct pci_data rom_pci_data VAR16 VISIBLE16 = {
+    .signature = PCI_ROM_SIGNATURE,
+    .vendor = CONFIG_VGA_VID,
+    .device = CONFIG_VGA_DID,
+    .dlen = 0x18,
+    .class_hi = 0x300,
+    .irevision = 1,
+    .type = PCIROM_CODETYPE_X86,
+    .indicator = 0x80,
+};
+
+
+/****************************************************************
+ * PMM call and extra stack setup
+ ****************************************************************/
+
+u16 ExtraStackSeg VAR16 VISIBLE16;
+
+static void
+allocate_extra_stack(void)
+{
+    if (!CONFIG_VGA_ALLOCATE_EXTRA_STACK)
+        return;
+    void *pmmscan = (void*)BUILD_BIOS_ADDR;
+    for (; pmmscan < (void*)BUILD_BIOS_ADDR+BUILD_BIOS_SIZE; pmmscan+=16) {
+        struct pmmheader *pmm = pmmscan;
+        if (pmm->signature != PMM_SIGNATURE)
+            continue;
+        if (checksum_far(0, pmm, pmm->length))
+            continue;
+        struct segoff_s entry = pmm->entry;
+        dprintf(1, "Attempting to allocate VGA stack via pmm call to %04x:%04x\n"
+                , entry.seg, entry.offset);
+        u16 res1, res2;
+        asm volatile(
+            "pushl %0\n"
+            "pushw $(8|1)\n"            // Permanent low memory request
+            "pushl $0xffffffff\n"       // Anonymous handle
+            "pushl $" __stringify(CONFIG_VGA_EXTRA_STACK_SIZE) "\n"
+            "pushw $0x00\n"             // PMM allocation request
+            "lcallw *12(%%esp)\n"
+            "addl $16, %%esp\n"
+            "cli\n"
+            "cld\n"
+            : "+r" (entry.segoff), "=a" (res1), "=d" (res2) : : "cc", "memory");
+        u32 res = res1 | (res2 << 16);
+        if (!res || res == PMM_FUNCTION_NOT_SUPPORTED)
+            return;
+        dprintf(1, "VGA stack allocated at %x\n", res);
+        SET_VGA(ExtraStackSeg, res >> 4);
+        extern void entry_10_extrastack(void);
+        SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10_extrastack));
+        return;
+    }
+}
+
+
+/****************************************************************
+ * VGA post
+ ****************************************************************/
+
+static void
+init_bios_area(void)
+{
+    // init detected hardware BIOS Area
+    // set 80x25 color (not clear from RBIL but usual)
+    set_equipment_flags(0x30, 0x20);
+
+    // the default char height
+    SET_BDA(char_height, 0x10);
+
+    // Clear the screen
+    SET_BDA(video_ctl, 0x60);
+
+    // Set the basic screen we have
+    SET_BDA(video_switches, 0xf9);
+
+    // Set the basic modeset options
+    SET_BDA(modeset_ctl, 0x51);
+
+    // Set the  default MSR
+    SET_BDA(video_msr, 0x09);
+}
+
+int VgaBDF VAR16 = -1;
+int HaveRunInit VAR16;
+
+void VISIBLE16
+vga_post(struct bregs *regs)
+{
+    debug_preinit();
+    dprintf(1, "Start SeaVGABIOS (version %s)\n", VERSION);
+    debug_enter(regs, DEBUG_VGA_POST);
+
+    if (CONFIG_VGA_PCI && !GET_GLOBAL(HaveRunInit)) {
+        u16 bdf = regs->ax;
+        if ((pci_config_readw(bdf, PCI_VENDOR_ID)
+             == GET_GLOBAL(rom_pci_data.vendor))
+            && (pci_config_readw(bdf, PCI_DEVICE_ID)
+                == GET_GLOBAL(rom_pci_data.device)))
+            SET_VGA(VgaBDF, bdf);
+    }
+
+    int ret = vgahw_setup();
+    if (ret) {
+        dprintf(1, "Failed to initialize VGA hardware.  Exiting.\n");
+        return;
+    }
+
+    if (GET_GLOBAL(HaveRunInit))
+        return;
+
+    init_bios_area();
+
+    SET_VGA(video_save_pointer_table.videoparam
+            , SEGOFF(get_global_seg(), (u32)video_param_table));
+    stdvga_build_video_param();
+
+    extern void entry_10(void);
+    SET_IVT(0x10, SEGOFF(get_global_seg(), (u32)entry_10));
+
+    allocate_extra_stack();
+
+    SET_VGA(HaveRunInit, 1);
+
+    // Fixup checksum
+    extern u8 _rom_header_size, _rom_header_checksum;
+    SET_VGA(_rom_header_checksum, 0);
+    u8 sum = -checksum_far(get_global_seg(), 0,
+                           GET_GLOBAL(_rom_header_size) * 512);
+    SET_VGA(_rom_header_checksum, sum);
+}