#include "util.h" // memcpy
#include "memmap.h" // bios_table_cur_addr
#include "pci.h" // pci_find_device
+#include "biosvar.h" // GET_EBDA
/****************************************************/
// 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)
#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
#define __BIOSVAR_H
#include "types.h" // u8
-#include "farptr.h" // SET_SEG
+#include "farptr.h" // GET_FARVAR
#include "config.h" // CONFIG_*
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)
SET_FARVAR(SEG_EBDA, ((struct extended_bios_data_area_s *)0)->var, (val))
-/****************************************************************
- * 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
****************************************************************/
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
// 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
--- /dev/null
+// 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
#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
/****************************************************************
//
// 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
// 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.
#include "util.h" // dprintf
#include "pci.h" // struct pir_header
#include "acpi.h" // struct rsdp_descriptor
+#include "biosvar.h" // GET_EBDA
/****************************************************************
// 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);
// 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
/****************************************************************
#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
} 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))
#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 */
//
// 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
#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];
//
// 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";
#include "util.h" // dprintf
#include "memmap.h" // bios_table_cur_addr
+#include "config.h" // CONFIG_*
static void putb(u8 **pp, int val)
{
#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
#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
#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
//
// 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()
#define __PIC_H
#include "ioport.h" // PORT_PIC*
-#include "util.h" // dprintf
// PORT_PIC1 bitdefs
#define PIC1_IRQ0 (1<<0)
#include "pci.h" // struct pir_header
#include "util.h" // checksum
+#include "biosvar.h" // SET_EBDA
struct pir_table {
struct pir_header pir;
#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))
#include "biosvar.h" // GET_EBDA
#include "util.h" // usleep
+#include "bregs.h" // struct bregs
static u8
check_for_keystroke()
//
// 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
/****************************************************************
#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) ({ \
#include "util.h" // dprintf
#include "memmap.h" // bios_table_cur_addr
+#include "biosvar.h" // GET_EBDA
/****************************************************************
#include "pci.h" // PCIDevice
#include "util.h" // wbinvd
+#include "config.h" // CONFIG_*
+#include "ioport.h" // outb
asm(
".global smm_relocation_start\n"
// 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)
#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
+// 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
#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)
{
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 (); \
#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);