Extract 'struct bregs' out of biosvar.h; clean up header includes.
diff --git a/src/acpi.c b/src/acpi.c
index 51f8161..c7d0430 100644
--- a/src/acpi.c
+++ b/src/acpi.c
@@ -9,6 +9,7 @@
 #include "util.h" // memcpy
 #include "memmap.h" // bios_table_cur_addr
 #include "pci.h" // pci_find_device
+#include "biosvar.h" // GET_EBDA
 
 
 /****************************************************/
diff --git a/src/apm.c b/src/apm.c
index 19885aa..20786c0 100644
--- a/src/apm.c
+++ b/src/apm.c
@@ -7,9 +7,10 @@
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
 #include "farptr.h" // GET_VAR
-#include "biosvar.h" // struct bregs
+#include "bregs.h" // struct bregs
 #include "ioport.h" // outb
 #include "util.h" // irq_enable
+#include "config.h" // CONFIG_*
 
 static void
 out_str(const char *str_cs)
diff --git a/src/ata.c b/src/ata.c
index 724ad62..04b0a43 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -11,6 +11,7 @@
 #include "util.h" // dprintf
 #include "cmos.h" // inb_cmos
 #include "pic.h" // unmask_pic2
+#include "biosvar.h" // GET_EBDA
 
 #define TIMEOUT 0
 #define BSY 1
diff --git a/src/biosvar.h b/src/biosvar.h
index 348161d..808f83b 100644
--- a/src/biosvar.h
+++ b/src/biosvar.h
@@ -7,7 +7,7 @@
 #define __BIOSVAR_H
 
 #include "types.h" // u8
-#include "farptr.h" // SET_SEG
+#include "farptr.h" // GET_FARVAR
 #include "config.h" // CONFIG_*
 
 
@@ -274,6 +274,9 @@
     struct ipl_s ipl;
 } PACKED;
 
+#define EBDA_SIZE DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
+#define BASE_MEM_IN_K (640 - EBDA_SIZE)
+
 // Accessor functions
 #define GET_EBDA(var) \
     GET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var)
@@ -282,43 +285,6 @@
 
 
 /****************************************************************
- * Registers saved/restored in romlayout.S
- ****************************************************************/
-
-#define UREG(ER, R, RH, RL) union { u32 ER; struct { u16 R; u16 R ## _hi; }; struct { u8 RL; u8 RH; u8 R ## _hilo; u8 R ## _hihi; }; }
-
-// Layout of registers passed in to irq handlers.  Note that this
-// layout corresponds to code in romlayout.S - don't change it here
-// without also updating the assembler code.
-struct bregs {
-    u16 ds;
-    u16 es;
-    UREG(edi, di, di_hi, di_lo);
-    UREG(esi, si, si_hi, si_lo);
-    UREG(ebx, bx, bh, bl);
-    UREG(edx, dx, dh, dl);
-    UREG(ecx, cx, ch, cl);
-    UREG(eax, ax, ah, al);
-    u16 ip;
-    u16 cs;
-    u16 flags;
-} PACKED;
-
-// bregs flags bitdefs
-#define F_ZF (1<<6)
-#define F_CF (1<<0)
-
-static inline void
-set_cf(struct bregs *regs, int cond)
-{
-    if (cond)
-        regs->flags |= F_CF;
-    else
-        regs->flags &= ~F_CF;
-}
-
-
-/****************************************************************
  * Bios Config Table
  ****************************************************************/
 
@@ -332,16 +298,4 @@
 
 extern struct bios_config_table_s BIOS_CONFIG_TABLE;
 
-
-/****************************************************************
- * Memory layout info
- ****************************************************************/
-
-#define SEG_BIOS     0xf000
-#define SEG_EBDA     0x9fc0
-#define SEG_BDA      0x0000
-
-#define EBDA_SIZE DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024)
-#define BASE_MEM_IN_K (640 - EBDA_SIZE)
-
 #endif // __BIOSVAR_H
diff --git a/src/boot.c b/src/boot.c
index ff41930..687be34 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -6,10 +6,11 @@
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
 #include "util.h" // irq_enable
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // GET_EBDA
 #include "config.h" // CONFIG_*
 #include "ata.h" // ata_detect
 #include "disk.h" // cdrom_boot
+#include "bregs.h" // struct bregs
 
 // We need a copy of this string, but we are not actually a PnP BIOS,
 // so make sure it is *not* aligned, so OSes will not see it if they
diff --git a/src/bregs.h b/src/bregs.h
new file mode 100644
index 0000000..8da6c52
--- /dev/null
+++ b/src/bregs.h
@@ -0,0 +1,90 @@
+// Structure layout of cpu registers the the bios uses.
+//
+// Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
+#ifndef __BREGS_H
+#define __BREGS_H
+
+
+/****************************************************************
+ * Registers saved/restored in romlayout.S
+ ****************************************************************/
+
+#define UREG(ER, R, RH, RL) union { u32 ER; struct { u16 R; u16 R ## _hi; }; struct { u8 RL; u8 RH; u8 R ## _hilo; u8 R ## _hihi; }; }
+
+// Layout of registers passed in to irq handlers.  Note that this
+// layout corresponds to code in romlayout.S - don't change it here
+// without also updating the assembler code.
+struct bregs {
+    u16 ds;
+    u16 es;
+    UREG(edi, di, di_hi, di_lo);
+    UREG(esi, si, si_hi, si_lo);
+    UREG(ebx, bx, bh, bl);
+    UREG(edx, dx, dh, dl);
+    UREG(ecx, cx, ch, cl);
+    UREG(eax, ax, ah, al);
+    u16 ip;
+    u16 cs;
+    u16 flags;
+} PACKED;
+
+
+/****************************************************************
+ * Helper functions
+ ****************************************************************/
+
+// bregs flags bitdefs
+#define F_ZF (1<<6)
+#define F_CF (1<<0)
+
+static inline void
+set_cf(struct bregs *regs, int cond)
+{
+    if (cond)
+        regs->flags |= F_CF;
+    else
+        regs->flags &= ~F_CF;
+}
+
+// Frequently used return codes
+#define RET_EUNSUPPORTED 0x86
+
+static inline void
+set_success(struct bregs *regs)
+{
+    set_cf(regs, 0);
+}
+
+static inline void
+set_code_success(struct bregs *regs)
+{
+    regs->ah = 0;
+    set_cf(regs, 0);
+}
+
+static inline void
+set_fail_silent(struct bregs *regs)
+{
+    set_cf(regs, 1);
+}
+
+static inline void
+set_code_fail_silent(struct bregs *regs, u8 code)
+{
+    regs->ah = code;
+    set_cf(regs, 1);
+}
+
+#define set_fail(regs) \
+    __set_fail(__func__, (regs))
+#define set_code_fail(regs, code)               \
+    __set_code_fail(__func__, (regs), (code))
+
+// util.c
+void __set_fail(const char *fname, struct bregs *regs);
+void __set_code_fail(const char *fname, struct bregs *regs, u8 code);
+
+#endif // bregs.h
diff --git a/src/cdrom.c b/src/cdrom.c
index adb2cfc..57c2ce4 100644
--- a/src/cdrom.c
+++ b/src/cdrom.c
@@ -8,6 +8,8 @@
 #include "disk.h" // cdrom_13
 #include "util.h" // memset
 #include "ata.h" // ATA_CMD_READ_SECTORS
+#include "bregs.h" // struct bregs
+#include "biosvar.h" // GET_EBDA
 
 
 /****************************************************************
diff --git a/src/clock.c b/src/clock.c
index 4162570..d375686 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -5,11 +5,12 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // SET_BDA
 #include "util.h" // debug_enter
 #include "disk.h" // floppy_tick
 #include "cmos.h" // inb_cmos
 #include "pic.h" // unmask_pic1
+#include "bregs.h" // struct bregs
 
 // RTC register flags
 #define RTC_A_UIP 0x80
diff --git a/src/config.h b/src/config.h
index dc123b6..9adb3c3 100644
--- a/src/config.h
+++ b/src/config.h
@@ -64,6 +64,11 @@
 // Start of fixed addresses in 0xf0000 segment.
 #define BUILD_START_FIXED       0xe050
 
+// Important 16-bit segments
+#define SEG_BIOS     0xf000
+#define SEG_EBDA     0x9fc0
+#define SEG_BDA      0x0000
+
 // Debugging levels.  If non-zero and CONFIG_DEBUG_LEVEL is greater
 // than the specified value, then the corresponding irq handler will
 // report every enter event.
diff --git a/src/coreboot.c b/src/coreboot.c
index 534a3c0..d7aeef1 100644
--- a/src/coreboot.c
+++ b/src/coreboot.c
@@ -8,6 +8,7 @@
 #include "util.h" // dprintf
 #include "pci.h" // struct pir_header
 #include "acpi.h" // struct rsdp_descriptor
+#include "biosvar.h" // GET_EBDA
 
 
 /****************************************************************
@@ -85,7 +86,7 @@
 
 // Attempt to find (and relocate) any standard bios tables found in a
 // given address range.
-void
+static void
 scan_tables(u32 start, u32 size)
 {
     void *p = (void*)ALIGN(start, 16);
diff --git a/src/disk.c b/src/disk.c
index 8f26c4b..e22afd7 100644
--- a/src/disk.c
+++ b/src/disk.c
@@ -6,11 +6,12 @@
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
 #include "disk.h" // floppy_13
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // SET_BDA
 #include "config.h" // CONFIG_*
 #include "util.h" // debug_enter
 #include "ata.h" // ATA_*
 #include "pic.h" // eoi_pic2
+#include "bregs.h" // struct bregs
 
 
 /****************************************************************
diff --git a/src/disk.h b/src/disk.h
index 3339b0d..54df9cd 100644
--- a/src/disk.h
+++ b/src/disk.h
@@ -6,9 +6,7 @@
 #ifndef __DISK_H
 #define __DISK_H
 
-#include "ioport.h" // outb
-#include "biosvar.h" // struct bregs
-#include "util.h" // set_code_fail
+#include "types.h" // u8
 
 #define DISK_RET_SUCCESS       0x00
 #define DISK_RET_EPARAM        0x01
@@ -93,6 +91,7 @@
 } PACKED;
 
 // Helper function for setting up a return code.
+struct bregs;
 void __disk_ret(const char *fname, struct bregs *regs, u8 code);
 #define disk_ret(regs, code) \
     __disk_ret(__func__, (regs), (code))
diff --git a/src/floppy.c b/src/floppy.c
index afb8778..a7908dc 100644
--- a/src/floppy.c
+++ b/src/floppy.c
@@ -8,10 +8,11 @@
 #include "types.h" // u8
 #include "disk.h" // DISK_RET_SUCCESS
 #include "config.h" // CONFIG_FLOPPY_SUPPORT
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // SET_BDA
 #include "util.h" // irq_disable
 #include "cmos.h" // inb_cmos
 #include "pic.h" // unmask_pic1
+#include "bregs.h" // struct bregs
 
 #define BX_FLOPPY_ON_CNT 37   /* 2 seconds */
 
diff --git a/src/kbd.c b/src/kbd.c
index 4304c0d..5dbb257 100644
--- a/src/kbd.c
+++ b/src/kbd.c
@@ -5,10 +5,11 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // GET_BDA
 #include "util.h" // debug_enter
 #include "config.h" // CONFIG_*
 #include "pic.h" // eoi_pic1
+#include "bregs.h" // struct bregs
 
 //--------------------------------------------------------------------------
 // keyboard_panic
diff --git a/src/memmap.c b/src/memmap.c
index 81d15f4..67f10e8 100644
--- a/src/memmap.c
+++ b/src/memmap.c
@@ -6,6 +6,7 @@
 
 #include "memmap.h" // struct e820entry
 #include "util.h" // dprintf.h
+#include "biosvar.h" // SET_EBDA
 
 // Temporary storage used during map building.
 static struct e820entry e820_list[64];
diff --git a/src/mouse.c b/src/mouse.c
index 163d849..08beafe 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -5,9 +5,10 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // GET_EBDA
 #include "util.h" // debug_isr
 #include "pic.h" // unmask_pic2
+#include "bregs.h" // struct bregs
 
 static char panic_msg_keyb_buffer_full[] = "%s: keyboard input buffer full\n";
 
diff --git a/src/mptable.c b/src/mptable.c
index b1b05e1..90b8d2f 100644
--- a/src/mptable.c
+++ b/src/mptable.c
@@ -7,6 +7,7 @@
 
 #include "util.h" // dprintf
 #include "memmap.h" // bios_table_cur_addr
+#include "config.h" // CONFIG_*
 
 static void putb(u8 **pp, int val)
 {
diff --git a/src/output.c b/src/output.c
index 6d4767b..27fca33 100644
--- a/src/output.c
+++ b/src/output.c
@@ -8,7 +8,8 @@
 
 #include "farptr.h" // GET_VAR
 #include "util.h" // printf
-#include "biosvar.h" // struct bregs
+#include "bregs.h" // struct bregs
+#include "config.h" // CONFIG_*
 
 #define DEBUG_PORT 0x03f8
 #define DEBUG_TIMEOUT 100000
diff --git a/src/pcibios.c b/src/pcibios.c
index 436c106..05d7856 100644
--- a/src/pcibios.c
+++ b/src/pcibios.c
@@ -8,6 +8,8 @@
 #include "types.h" // u32
 #include "util.h" // handle_1ab1
 #include "pci.h" // pci_config_readl
+#include "bregs.h" // struct bregs
+#include "biosvar.h" // GET_EBDA
 
 #define RET_FUNC_NOT_SUPPORTED 0x81
 #define RET_BAD_VENDOR_ID      0x83
diff --git a/src/pciinit.c b/src/pciinit.c
index 303f581..15fa9b7 100644
--- a/src/pciinit.c
+++ b/src/pciinit.c
@@ -7,6 +7,7 @@
 
 #include "util.h" // dprintf
 #include "pci.h" // PCIDevice
+#include "biosvar.h" // GET_EBDA
 
 #define PCI_ADDRESS_SPACE_MEM		0x00
 #define PCI_ADDRESS_SPACE_IO		0x01
diff --git a/src/pic.c b/src/pic.c
index 7088724..129fc34 100644
--- a/src/pic.c
+++ b/src/pic.c
@@ -5,7 +5,9 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "pic.h"
+#include "pic.h" // get_pic1_isr
+#include "util.h" // dprintf
+#include "config.h" // CONFIG_*
 
 void
 pic_setup()
diff --git a/src/pic.h b/src/pic.h
index 8775191..f020f55 100644
--- a/src/pic.h
+++ b/src/pic.h
@@ -8,7 +8,6 @@
 #define __PIC_H
 
 #include "ioport.h" // PORT_PIC*
-#include "util.h" // dprintf
 
 // PORT_PIC1 bitdefs
 #define PIC1_IRQ0  (1<<0)
diff --git a/src/pirtable.c b/src/pirtable.c
index 433b889..75c4693 100644
--- a/src/pirtable.c
+++ b/src/pirtable.c
@@ -7,6 +7,7 @@
 
 #include "pci.h" // struct pir_header
 #include "util.h" // checksum
+#include "biosvar.h" // SET_EBDA
 
 struct pir_table {
     struct pir_header pir;
diff --git a/src/post.c b/src/post.c
index e1ec630..8c3b20a 100644
--- a/src/post.c
+++ b/src/post.c
@@ -18,6 +18,7 @@
 #include "pic.h" // pic_setup
 #include "pci.h" // create_pirtable
 #include "acpi.h" // acpi_bios_init
+#include "bregs.h" // struct bregs
 
 #define bda ((struct bios_data_area_s *)MAKE_FARPTR(SEG_BDA, 0))
 #define ebda ((struct extended_bios_data_area_s *)MAKE_FARPTR(SEG_EBDA, 0))
diff --git a/src/post_menu.c b/src/post_menu.c
index 4526e44..5115321 100644
--- a/src/post_menu.c
+++ b/src/post_menu.c
@@ -7,6 +7,7 @@
 
 #include "biosvar.h" // GET_EBDA
 #include "util.h" // usleep
+#include "bregs.h" // struct bregs
 
 static u8
 check_for_keystroke()
diff --git a/src/serial.c b/src/serial.c
index 6c38086..46a9558 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -5,8 +5,9 @@
 //
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
-#include "biosvar.h" // struct bregs
+#include "biosvar.h" // SET_BDA
 #include "util.h" // debug_enter
+#include "bregs.h" // struct bregs
 
 
 /****************************************************************
diff --git a/src/shadow.c b/src/shadow.c
index 887851d..b9457c5 100644
--- a/src/shadow.c
+++ b/src/shadow.c
@@ -7,6 +7,7 @@
 
 #include "util.h" // memcpy
 #include "pci.h" // pci_config_writeb
+#include "config.h" // CONFIG_*
 
 // Test if 'addr' is in the range from 'start'..'start+size'
 #define IN_RANGE(addr, start, size) ({   \
diff --git a/src/smbios.c b/src/smbios.c
index fe78e12..020d7c4 100644
--- a/src/smbios.c
+++ b/src/smbios.c
@@ -7,6 +7,7 @@
 
 #include "util.h" // dprintf
 #include "memmap.h" // bios_table_cur_addr
+#include "biosvar.h" // GET_EBDA
 
 
 /****************************************************************
diff --git a/src/smm.c b/src/smm.c
index 9a9edb8..9500e92 100644
--- a/src/smm.c
+++ b/src/smm.c
@@ -7,6 +7,8 @@
 
 #include "pci.h" // PCIDevice
 #include "util.h" // wbinvd
+#include "config.h" // CONFIG_*
+#include "ioport.h" // outb
 
 asm(
     ".global smm_relocation_start\n"
diff --git a/src/smpdetect.c b/src/smpdetect.c
index 2d03d7c..1c4630c 100644
--- a/src/smpdetect.c
+++ b/src/smpdetect.c
@@ -6,6 +6,7 @@
 // This file may be distributed under the terms of the GNU GPLv3 license.
 
 #include "util.h" // dprintf
+#include "config.h" // CONFIG_*
 
 #define CPUID_APIC (1 << 9)
 
diff --git a/src/system.c b/src/system.c
index e73fe5c..d9ff5a7 100644
--- a/src/system.c
+++ b/src/system.c
@@ -10,6 +10,7 @@
 #include "ioport.h" // inb
 #include "memmap.h" // E820_RAM
 #include "pic.h" // eoi_pic2
+#include "bregs.h" // struct bregs
 
 // Use PS2 System Control port A to set A20 enable
 static inline u8
diff --git a/src/util.c b/src/util.c
index 6b2d9db..c4f61c5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,4 +1,37 @@
+// Misc utility functions.
+//
+// Copyright (C) 2008  Kevin O'Connor <kevin@koconnor.net>
+//
+// This file may be distributed under the terms of the GNU GPLv3 license.
+
 #include "util.h" // usleep
+#include "bregs.h" // struct bregs
+#include "config.h" // SEG_BIOS
+#include "farptr.h" // GET_FARPTR
+
+// Call a function with a specified register state.  Note that on
+// return, the interrupt enable/disable flag may be altered.
+inline void
+call16(struct bregs *callregs)
+{
+    asm volatile(
+#ifdef MODE16
+        "calll __call16\n"
+#else
+        "calll __call16_from32\n"
+#endif
+        : "+a" (callregs), "+m" (*callregs)
+        :
+        : "ebx", "ecx", "edx", "esi", "edi", "ebp", "cc");
+}
+
+inline void
+__call16_int(struct bregs *callregs, u16 offset)
+{
+    callregs->cs = SEG_BIOS;
+    callregs->ip = offset;
+    call16(callregs);
+}
 
 // Sum the bytes in the specified area.
 u8
diff --git a/src/util.h b/src/util.h
index 3f7283f..47ce0c7 100644
--- a/src/util.h
+++ b/src/util.h
@@ -6,8 +6,7 @@
 #ifndef __UTIL_H
 #define __UTIL_H
 
-#include "ioport.h" // outb
-#include "biosvar.h" // struct bregs
+#include "types.h" // u32
 
 static inline void irq_disable(void)
 {
@@ -63,30 +62,9 @@
 void *memcpy(void *d1, const void *s1, size_t len);
 void *memmove(void *d, const void *s, size_t len);
 
-// Call a function with a specified register state.  Note that on
-// return, the interrupt enable/disable flag may be altered.
-static inline
-void call16(struct bregs *callregs)
-{
-    asm volatile(
-#ifdef MODE16
-        "calll __call16\n"
-#else
-        "calll __call16_from32\n"
-#endif
-        : "+a" (callregs), "+m" (*callregs)
-        :
-        : "ebx", "ecx", "edx", "esi", "edi", "ebp", "cc");
-}
-
-static inline
-void __call16_int(struct bregs *callregs, u16 offset)
-{
-    callregs->cs = SEG_BIOS;
-    callregs->ip = offset;
-    call16(callregs);
-}
-
+struct bregs;
+inline void call16(struct bregs *callregs);
+inline void __call16_int(struct bregs *callregs, u16 offset);
 #ifdef MODE16
 #define call16_int(nr, callregs) do {                           \
         extern void irq_trampoline_ ##nr ();                    \
@@ -126,42 +104,6 @@
 #define debug_stub(regs) \
     __debug_stub(__func__, regs)
 
-// Frequently used return codes
-#define RET_EUNSUPPORTED 0x86
-static inline void
-set_success(struct bregs *regs)
-{
-    set_cf(regs, 0);
-}
-
-static inline void
-set_code_success(struct bregs *regs)
-{
-    regs->ah = 0;
-    set_cf(regs, 0);
-}
-
-static inline void
-set_fail_silent(struct bregs *regs)
-{
-    set_cf(regs, 1);
-}
-
-static inline void
-set_code_fail_silent(struct bregs *regs, u8 code)
-{
-    regs->ah = code;
-    set_cf(regs, 1);
-}
-
-void __set_fail(const char *fname, struct bregs *regs);
-void __set_code_fail(const char *fname, struct bregs *regs, u8 code);
-
-#define set_fail(regs) \
-    __set_fail(__func__, (regs))
-#define set_code_fail(regs, code)               \
-    __set_code_fail(__func__, (regs), (code))
-
 // kbd.c
 void handle_15c2(struct bregs *regs);