diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2008-07-04 13:04:29 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2008-07-04 13:04:29 -0400 |
commit | 9521e26a164eb4689b34d82a5de0d998bdd4c4dc (patch) | |
tree | d3ba8e12b31213defe5fa794e4d0bcec711c871f /src | |
parent | 0525d29af0803bdfca40f9bb8b1f8cf5b9a84c05 (diff) | |
download | seabios-9521e26a164eb4689b34d82a5de0d998bdd4c4dc.tar.gz |
Extract 'struct bregs' out of biosvar.h; clean up header includes.
Diffstat (limited to 'src')
-rw-r--r-- | src/acpi.c | 1 | ||||
-rw-r--r-- | src/apm.c | 3 | ||||
-rw-r--r-- | src/ata.c | 1 | ||||
-rw-r--r-- | src/biosvar.h | 54 | ||||
-rw-r--r-- | src/boot.c | 3 | ||||
-rw-r--r-- | src/bregs.h | 90 | ||||
-rw-r--r-- | src/cdrom.c | 2 | ||||
-rw-r--r-- | src/clock.c | 3 | ||||
-rw-r--r-- | src/config.h | 5 | ||||
-rw-r--r-- | src/coreboot.c | 3 | ||||
-rw-r--r-- | src/disk.c | 3 | ||||
-rw-r--r-- | src/disk.h | 5 | ||||
-rw-r--r-- | src/floppy.c | 3 | ||||
-rw-r--r-- | src/kbd.c | 3 | ||||
-rw-r--r-- | src/memmap.c | 1 | ||||
-rw-r--r-- | src/mouse.c | 3 | ||||
-rw-r--r-- | src/mptable.c | 1 | ||||
-rw-r--r-- | src/output.c | 3 | ||||
-rw-r--r-- | src/pcibios.c | 2 | ||||
-rw-r--r-- | src/pciinit.c | 1 | ||||
-rw-r--r-- | src/pic.c | 4 | ||||
-rw-r--r-- | src/pic.h | 1 | ||||
-rw-r--r-- | src/pirtable.c | 1 | ||||
-rw-r--r-- | src/post.c | 1 | ||||
-rw-r--r-- | src/post_menu.c | 1 | ||||
-rw-r--r-- | src/serial.c | 3 | ||||
-rw-r--r-- | src/shadow.c | 1 | ||||
-rw-r--r-- | src/smbios.c | 1 | ||||
-rw-r--r-- | src/smm.c | 2 | ||||
-rw-r--r-- | src/smpdetect.c | 1 | ||||
-rw-r--r-- | src/system.c | 1 | ||||
-rw-r--r-- | src/util.c | 33 | ||||
-rw-r--r-- | src/util.h | 66 |
33 files changed, 179 insertions, 127 deletions
@@ -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 /****************************************************/ @@ -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) @@ -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 348161d4..808f83b8 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 extended_bios_data_area_s { 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 @@ struct extended_bios_data_area_s { /**************************************************************** - * 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 @@ struct bios_config_table_s { 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 @@ -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 00000000..8da6c524 --- /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 adb2cfca..57c2ce48 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 41625704..d3756865 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 dc123b62..9adb3c33 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 534a3c04..d7aeef13 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 @@ copy_acpi_rsdp(void *pos) // 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); @@ -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 /**************************************************************** @@ -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 @@ struct floppy_ext_dbt_s { } 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 afb87786..a7908dc5 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 */ @@ -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 81d15f4d..67f10e89 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 163d849d..08beafe6 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 b1b05e1e..90b8d2f0 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 6d4767ba..27fca330 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 436c106b..05d78565 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 303f581e..15fa9b7c 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 @@ -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() @@ -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 433b889c..75c46938 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; @@ -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 4526e44d..5115321e 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 6c38086e..46a9558b 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 887851d1..b9457c55 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 fe78e12a..020d7c4c 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 /**************************************************************** @@ -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 2d03d7cb..1c4630cb 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 e73fe5ca..d9ff5a76 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 @@ -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 @@ -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 *memset(void *s, int c, size_t n); 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 @@ void __debug_isr(const char *fname); #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); |