This patch series attempts to cleanup some of the include files within SeaBIOS. There are three main goals: split out the complex users of util.h into their own header files, introduce a new directory std/ for header files that just define standard bios interfaces, and make sure no header files (with the exception of util.h) have declarations for more than one c file.
At the end of this series util.h, only contains simple function and variable prototypes (ie, no macros, inline code, or struct definitions).
This series is also available at:
https://github.com/KevinOConnor/seabios/tree/testing
-Kevin
Kevin O'Connor (23): Split x86 specific functions out of util.c/h to new files x86.c/h. Move keyboard calling code from util.c to boot.c. Rename util.c to string.c and introduce string.h. Move stacks.c definitions from util.h to new file stacks.h. Move stacks.c definitions from util.h to new file stacks.h. Move romfile definitions from util.h to new file romfile.h. Move malloc code from pmm.c to new files malloc.c and malloc.h. Move function definitions for output.c from util.h to new file output.h. Move definition of struct segoff_s from farptr.h to types.h. build: Fix import of gcc dependency files. Move pirtable definitions from hw/pci.h to std/pirtable.h and util.h. Move optionroms.h to std/optionrom.h and util.h. Move vbe.h to std/vbe.h. Move fw/LegacyBios.h to std/LegacyBios.h and remove csm.h. Move fw/smbios.h to std/smbios.h. Move fw/mptable.h to std/mptable.h. Move fw/acpi.h to std/acpi.h. Move pnpbios definition to new file std/pnpbios.h. Move pmm definitions to new file std/pmm.h. Split disk.h into block.h and std/disk.h. Move standard bda type info from biosvar.h to std/bda.h. Merge bmp.h, boot.h, jpeg.h, and post.h into util.h. Sort the sections of util.h.
Makefile | 12 +- src/apm.c | 9 +- src/biosvar.h | 161 +--------- src/block.c | 44 ++- src/block.h | 129 ++++++++ src/bmp.c | 18 +- src/bmp.h | 25 -- src/boot.c | 59 +++- src/boot.h | 26 -- src/bootsplash.c | 14 +- src/bregs.h | 21 +- src/byteorder.h | 2 + src/cdrom.c | 25 +- src/clock.c | 9 +- src/disk.c | 38 +-- src/disk.h | 292 ----------------- src/farptr.h | 10 - src/fw/acpi.c | 15 +- src/fw/biostables.c | 13 +- src/fw/coreboot.c | 16 +- src/fw/csm.c | 29 +- src/fw/csm.h | 18 -- src/fw/mptable.c | 9 +- src/fw/mtrr.c | 4 +- src/fw/paravirt.c | 18 +- src/fw/pciinit.c | 12 +- src/fw/pirtable.c | 5 +- src/fw/shadow.c | 10 +- src/fw/smbios.c | 9 +- src/fw/smm.c | 11 +- src/fw/smp.c | 6 +- src/fw/xen.c | 10 +- src/hw/ahci.c | 18 +- src/hw/ahci.h | 3 + src/hw/ata.c | 21 +- src/hw/ata.h | 4 +- src/hw/blockcmd.c | 20 +- src/hw/esp-scsi.c | 17 +- src/hw/floppy.c | 18 +- src/hw/lsi-scsi.c | 17 +- src/hw/megasas.c | 16 +- src/hw/pci.c | 14 +- src/hw/pci.h | 40 --- src/hw/pic.c | 6 +- src/hw/pic.h | 1 - src/hw/ps2port.c | 9 +- src/hw/ramdisk.c | 13 +- src/hw/timer.c | 11 +- src/hw/usb-ehci.c | 14 +- src/hw/usb-hid.c | 9 +- src/hw/usb-hub.c | 6 +- src/hw/usb-msc.c | 15 +- src/hw/usb-ohci.c | 12 +- src/hw/usb-uas.c | 13 +- src/hw/usb-uhci.c | 11 +- src/hw/usb.c | 18 +- src/hw/usb.h | 2 +- src/hw/virtio-blk.c | 13 +- src/hw/virtio-pci.c | 8 +- src/hw/virtio-ring.c | 4 +- src/hw/virtio-scsi.c | 15 +- src/jpeg.c | 3 +- src/jpeg.h | 11 - src/kbd.c | 7 +- src/malloc.c | 529 +++++++++++++++++++++++++++++++ src/malloc.h | 70 +++++ src/memmap.c | 5 +- src/misc.c | 6 +- src/mouse.c | 4 +- src/optionroms.c | 15 +- src/output.c | 6 +- src/output.h | 68 ++++ src/pcibios.c | 10 +- src/pmm.c | 573 ++-------------------------------- src/pnpbios.c | 23 +- src/post.c | 30 +- src/post.h | 10 - src/resume.c | 18 +- src/romfile.c | 5 +- src/romfile.h | 19 ++ src/romlayout.S | 2 +- src/serial.c | 4 +- src/stacks.c | 5 +- src/stacks.h | 34 ++ src/{fw => std}/LegacyBios.h | 0 src/{fw => std}/acpi.h | 10 - src/std/bda.h | 159 ++++++++++ src/std/disk.h | 177 +++++++++++ src/{fw => std}/mptable.h | 3 - src/{optionroms.h => std/optionrom.h} | 3 - src/std/pirtable.h | 35 +++ src/std/pmm.h | 19 ++ src/std/pnpbios.h | 24 ++ src/{fw => std}/smbios.h | 6 +- src/{ => std}/vbe.h | 1 - src/{util.c => string.c} | 67 +--- src/string.h | 30 ++ src/system.c | 11 +- src/types.h | 11 + src/util.h | 557 ++++++++++----------------------- src/vgahooks.c | 8 +- src/x86.c | 23 ++ src/x86.h | 168 ++++++++++ vgasrc/bochsvga.c | 10 +- vgasrc/clext.c | 9 +- vgasrc/geodevga.c | 10 +- vgasrc/stdvga.c | 2 +- vgasrc/stdvgamodes.c | 5 +- vgasrc/vbe.c | 11 +- vgasrc/vgabios.c | 18 +- vgasrc/vgafb.c | 5 +- 111 files changed, 2273 insertions(+), 2013 deletions(-) create mode 100644 src/block.h delete mode 100644 src/bmp.h delete mode 100644 src/boot.h delete mode 100644 src/disk.h delete mode 100644 src/fw/csm.h delete mode 100644 src/jpeg.h create mode 100644 src/malloc.c create mode 100644 src/malloc.h create mode 100644 src/output.h delete mode 100644 src/post.h create mode 100644 src/romfile.h create mode 100644 src/stacks.h rename src/{fw => std}/LegacyBios.h (100%) rename src/{fw => std}/acpi.h (96%) create mode 100644 src/std/bda.h create mode 100644 src/std/disk.h rename src/{fw => std}/mptable.h (96%) rename src/{optionroms.h => std/optionrom.h} (95%) create mode 100644 src/std/pirtable.h create mode 100644 src/std/pmm.h create mode 100644 src/std/pnpbios.h rename src/{fw => std}/smbios.h (97%) rename src/{ => std}/vbe.h (99%) rename src/{util.c => string.c} (76%) create mode 100644 src/string.h create mode 100644 src/x86.c create mode 100644 src/x86.h
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 2 +- src/bregs.h | 22 +------ src/fw/acpi.c | 1 + src/fw/mptable.c | 1 + src/fw/mtrr.c | 1 + src/fw/paravirt.c | 1 + src/fw/shadow.c | 1 + src/fw/smbios.c | 1 + src/fw/smm.c | 3 +- src/fw/smp.c | 1 + src/fw/xen.c | 1 + src/hw/pci.c | 1 + src/hw/timer.c | 1 + src/hw/usb-ehci.c | 1 + src/hw/usb-ohci.c | 1 + src/hw/usb.c | 1 + src/pmm.c | 1 + src/romlayout.S | 2 +- src/util.c | 16 ------ src/util.h | 141 --------------------------------------------- src/x86.c | 23 ++++++++ src/x86.h | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 22 files changed, 212 insertions(+), 179 deletions(-) create mode 100644 src/x86.c create mode 100644 src/x86.h
diff --git a/Makefile b/Makefile index 9b7ed33..46df1c6 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ OUT=out/
# Source files -SRCBOTH=misc.c stacks.c output.c util.c block.c cdrom.c mouse.c kbd.c \ +SRCBOTH=misc.c stacks.c output.c util.c x86.c block.c cdrom.c mouse.c kbd.c \ serial.c clock.c resume.c pnpbios.c vgahooks.c pcibios.c apm.c \ fw/smp.c \ hw/pci.c hw/timer.c hw/pic.c hw/ps2port.c \ diff --git a/src/bregs.h b/src/bregs.h index 577effc..009db99 100644 --- a/src/bregs.h +++ b/src/bregs.h @@ -7,29 +7,15 @@ #ifndef __BREGS_H #define __BREGS_H
-// CPU flag bitdefs -#define F_CF (1<<0) -#define F_ZF (1<<6) -#define F_IF (1<<9) -#define F_ID (1<<21) - -// CR0 flags -#define CR0_PG (1<<31) // Paging -#define CR0_CD (1<<30) // Cache disable -#define CR0_NW (1<<29) // Not Write-through -#define CR0_PE (1<<0) // Protection enable - - -#ifndef __ASSEMBLY__ - +#include "types.h" // u16 #include "farptr.h" // struct segoff_s +#include "x86.h" // F_CF +
/**************************************************************** * Registers saved/restored in romlayout.S ****************************************************************/
-#include "types.h" // u16 - #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 @@ -92,6 +78,4 @@ set_code_invalid_silent(struct bregs *regs, u8 code) set_cf(regs, 1); }
-#endif // !__ASSEMBLY__ - #endif // bregs.h diff --git a/src/fw/acpi.c b/src/fw/acpi.c index 9fd1c05..fcf11ea 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -15,6 +15,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "dev-q35.h" +#include "x86.h" // readl
#include "src/fw/acpi-dsdt.hex"
diff --git a/src/fw/mptable.c b/src/fw/mptable.c index 2d12865..47fe53d 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -10,6 +10,7 @@ #include "mptable.h" // MPTABLE_SIGNATURE #include "hw/pci.h" #include "hw/pci_regs.h" +#include "x86.h" // cpuid
void mptable_setup(void) diff --git a/src/fw/mtrr.c b/src/fw/mtrr.c index 001e275..855457a 100644 --- a/src/fw/mtrr.c +++ b/src/fw/mtrr.c @@ -8,6 +8,7 @@ #include "config.h" // CONFIG_* #include "hw/pci.h" // pcimem_start #include "paravirt.h" // RamSize +#include "x86.h" // cpuid
#define MSR_MTRRcap 0x000000fe #define MSR_MTRRfix64K_00000 0x00000250 diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index b1dd8b0..a68e3a1 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -20,6 +20,7 @@ #include "mptable.h" // mptable_setup #include "hw/pci.h" // create_pirtable #include "xen.h" // xen_biostable_setup +#include "x86.h" // cpuid
// Amount of continuous ram under 4Gig u32 RamSize; diff --git a/src/fw/shadow.c b/src/fw/shadow.c index 67e943f..767c6ea 100644 --- a/src/fw/shadow.c +++ b/src/fw/shadow.c @@ -12,6 +12,7 @@ #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "paravirt.h" // runningOnXen #include "dev-q35.h" // PCI_VENDOR_ID_INTEL +#include "x86.h" // wbinvd
// On the emulators, the bios at 0xf0000 is also at 0xffff0000 #define BIOS_SRC_OFFSET 0xfff00000 diff --git a/src/fw/smbios.c b/src/fw/smbios.c index fd63afb..93fb57f 100644 --- a/src/fw/smbios.c +++ b/src/fw/smbios.c @@ -9,6 +9,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "smbios.h" // struct smbios_entry_point +#include "x86.h" // cpuid
struct smbios_entry_point *SMBiosAddr;
diff --git a/src/fw/smm.c b/src/fw/smm.c index 3f01207..3a1a799 100644 --- a/src/fw/smm.c +++ b/src/fw/smm.c @@ -7,11 +7,12 @@
#include "hw/pci.h" // pci_config_writel #include "hw/pci_regs.h" // PCI_DEVICE_ID -#include "util.h" // wbinvd +#include "util.h" // dprintf #include "config.h" // CONFIG_* #include "ioport.h" // outb #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "dev-q35.h" +#include "x86.h" // wbinvd
extern u8 smm_relocation_start, smm_relocation_end; ASM32FLAT( diff --git a/src/fw/smp.c b/src/fw/smp.c index 6379d36..a8504ab 100644 --- a/src/fw/smp.c +++ b/src/fw/smp.c @@ -8,6 +8,7 @@ #include "util.h" // dprintf #include "config.h" // CONFIG_* #include "hw/cmos.h" // CMOS_BIOS_SMP_COUNT +#include "x86.h" // wrmsr
#define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300) #define APIC_SVR ((u8*)BUILD_APIC_ADDR + 0x0F0) diff --git a/src/fw/xen.c b/src/fw/xen.c index 5dfee9e..6e21bff 100644 --- a/src/fw/xen.c +++ b/src/fw/xen.c @@ -11,6 +11,7 @@ #include "types.h" // ASM32FLAT #include "util.h" // copy_acpi_rsdp #include "acpi.h" // find_acpi_features +#include "x86.h" // cpuid
#define INFO_PHYSICAL_ADDRESS 0x00001000
diff --git a/src/hw/pci.c b/src/hw/pci.c index dc62c5c..d1115a4 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -12,6 +12,7 @@ #include "farptr.h" // MAKE_FLATPTR #include "pci_regs.h" // PCI_VENDOR_ID #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA +#include "x86.h" // readl
void pci_config_writel(u16 bdf, u32 addr, u32 val) { diff --git a/src/hw/timer.c b/src/hw/timer.c index b368362..2547639 100644 --- a/src/hw/timer.c +++ b/src/hw/timer.c @@ -9,6 +9,7 @@ #include "ioport.h" // PORT_PIT_MODE #include "config.h" // CONFIG_* #include "biosvar.h" // GET_LOW +#include "x86.h" // cpuid
// Bits for PORT_PS2_CTRLB #define PPCB_T2GATE (1<<0) diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 978ca68..333679e 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -15,6 +15,7 @@ #include "biosvar.h" // GET_LOWFLAT #include "usb-uhci.h" // uhci_setup #include "usb-ohci.h" // ohci_setup +#include "x86.h" // readl
struct usb_ehci_s { struct usb_s usb; diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index e5c9fa5..c1806ff 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -11,6 +11,7 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT +#include "x86.h" // readl
#define FIT (1 << 31)
diff --git a/src/hw/usb.c b/src/hw/usb.c index 42541ff..647359e 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -18,6 +18,7 @@ #include "usb-uas.h" // usb_uas_setup #include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL +#include "x86.h" // __fls
/**************************************************************** diff --git a/src/pmm.c b/src/pmm.c index 9ea4313..c86d66f 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -11,6 +11,7 @@ #include "biosvar.h" // GET_BDA #include "optionroms.h" // OPTION_ROM_ALIGN #include "list.h" // hlist_node +#include "x86.h" // __ffs
// Information on a reserved area. struct allocinfo_s { diff --git a/src/romlayout.S b/src/romlayout.S index cc97f9a..17904ae 100644 --- a/src/romlayout.S +++ b/src/romlayout.S @@ -7,7 +7,7 @@
#include "config.h" // CONFIG_* #include "ioport.h" // PORT_A20 -#include "bregs.h" // CR0_* +#include "x86.h" // CR0_* #include "hw/cmos.h" // CMOS_RESET_CODE #include "asm-offsets.h" // BREGS_* #include "entryfuncs.S" // ENTRY_* diff --git a/src/util.c b/src/util.c index ffabd1c..dd7afdf 100644 --- a/src/util.c +++ b/src/util.c @@ -8,22 +8,6 @@ #include "bregs.h" // struct bregs #include "config.h" // BUILD_STACK_ADDR
-void -cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) -{ - // Check for cpu id - u32 origflags = save_flags(); - restore_flags(origflags ^ F_ID); - u32 newflags = save_flags(); - restore_flags(origflags); - - if (((origflags ^ newflags) & F_ID) != F_ID) - // no cpuid - *eax = *ebx = *ecx = *edx = 0; - else - __cpuid(index, eax, ebx, ecx, edx); -} -
/**************************************************************** * String ops diff --git a/src/util.h b/src/util.h index f2a1671..70114a6 100644 --- a/src/util.h +++ b/src/util.h @@ -8,148 +8,7 @@
#include "types.h" // u32
-static inline void irq_disable(void) -{ - asm volatile("cli": : :"memory"); -} - -static inline void irq_enable(void) -{ - asm volatile("sti": : :"memory"); -} - -static inline u32 save_flags(void) -{ - u32 flags; - asm volatile("pushfl ; popl %0" : "=rm" (flags)); - return flags; -} - -static inline void restore_flags(u32 flags) -{ - asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc"); -} - -static inline void cpu_relax(void) -{ - asm volatile("rep ; nop": : :"memory"); -} - -static inline void nop(void) -{ - asm volatile("nop"); -} - -static inline void hlt(void) -{ - asm volatile("hlt": : :"memory"); -} - -static inline void wbinvd(void) -{ - asm volatile("wbinvd": : :"memory"); -} - -#define CPUID_TSC (1 << 4) -#define CPUID_MSR (1 << 5) -#define CPUID_APIC (1 << 9) -#define CPUID_MTRR (1 << 12) -static inline void __cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) -{ - asm("cpuid" - : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) - : "0" (index)); -} - -static inline u32 getcr0(void) { - u32 cr0; - asm("movl %%cr0, %0" : "=r"(cr0)); - return cr0; -} -static inline void setcr0(u32 cr0) { - asm("movl %0, %%cr0" : : "r"(cr0)); -} - -static inline u64 rdmsr(u32 index) -{ - u64 ret; - asm ("rdmsr" : "=A"(ret) : "c"(index)); - return ret; -} - -static inline void wrmsr(u32 index, u64 val) -{ - asm volatile ("wrmsr" : : "c"(index), "A"(val)); -} - -static inline u64 rdtscll(void) -{ - u64 val; - asm volatile("rdtsc" : "=A" (val)); - return val; -} - -static inline u32 __ffs(u32 word) -{ - asm("bsf %1,%0" - : "=r" (word) - : "rm" (word)); - return word; -} -static inline u32 __fls(u32 word) -{ - asm("bsr %1,%0" - : "=r" (word) - : "rm" (word)); - return word; -} - -static inline u32 getesp(void) { - u32 esp; - asm("movl %%esp, %0" : "=rm"(esp)); - return esp; -} - -static inline void writel(void *addr, u32 val) { - *(volatile u32 *)addr = val; -} -static inline void writew(void *addr, u16 val) { - *(volatile u16 *)addr = val; -} -static inline void writeb(void *addr, u8 val) { - *(volatile u8 *)addr = val; -} -static inline u32 readl(const void *addr) { - return *(volatile const u32 *)addr; -} -static inline u16 readw(const void *addr) { - return *(volatile const u16 *)addr; -} -static inline u8 readb(const void *addr) { - return *(volatile const u8 *)addr; -} - -// GDT bits -#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set -#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set -#define GDT_B (0x1ULL << 54) // Big flag -#define GDT_G (0x1ULL << 55) // Granularity flag -// GDT bits for segment base -#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \ - | (((u64)(v) & 0x00ffffff) << 16)) -// GDT bits for segment limit (0-1Meg) -#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \ - | (((u64)(v) & 0x0000ffff) << 0)) -// GDT bits for segment limit (0-4Gig in 4K chunks) -#define GDT_GRANLIMIT(v) (GDT_G | GDT_LIMIT((v) >> 12)) - -struct descloc_s { - u16 length; - u32 addr; -} PACKED; - // util.c -void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); u8 checksum_far(u16 buf_seg, void *buf_far, u32 len); u8 checksum(void *buf, u32 len); size_t strlen(const char *s); diff --git a/src/x86.c b/src/x86.c new file mode 100644 index 0000000..0fdf86f --- /dev/null +++ b/src/x86.c @@ -0,0 +1,23 @@ +// X86 utility functions. +// +// Copyright (C) 2013 Kevin O'Connor kevin@koconnor.net +// +// This file may be distributed under the terms of the GNU LGPLv3 license. + +#include "x86.h" // __cpuid + +void +cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) +{ + // Check for cpu id + u32 origflags = save_flags(); + restore_flags(origflags ^ F_ID); + u32 newflags = save_flags(); + restore_flags(origflags); + + if (((origflags ^ newflags) & F_ID) != F_ID) + // no cpuid + *eax = *ebx = *ecx = *edx = 0; + else + __cpuid(index, eax, ebx, ecx, edx); +} diff --git a/src/x86.h b/src/x86.h new file mode 100644 index 0000000..389d747 --- /dev/null +++ b/src/x86.h @@ -0,0 +1,168 @@ +// Basic x86 asm functions. +#ifndef __X86_H +#define __X86_H + +// CPU flag bitdefs +#define F_CF (1<<0) +#define F_ZF (1<<6) +#define F_IF (1<<9) +#define F_ID (1<<21) + +// CR0 flags +#define CR0_PG (1<<31) // Paging +#define CR0_CD (1<<30) // Cache disable +#define CR0_NW (1<<29) // Not Write-through +#define CR0_PE (1<<0) // Protection enable + +#ifndef __ASSEMBLY__ + +#include "types.h" // u32 + +static inline void irq_disable(void) +{ + asm volatile("cli": : :"memory"); +} + +static inline void irq_enable(void) +{ + asm volatile("sti": : :"memory"); +} + +static inline u32 save_flags(void) +{ + u32 flags; + asm volatile("pushfl ; popl %0" : "=rm" (flags)); + return flags; +} + +static inline void restore_flags(u32 flags) +{ + asm volatile("pushl %0 ; popfl" : : "g" (flags) : "memory", "cc"); +} + +static inline void cpu_relax(void) +{ + asm volatile("rep ; nop": : :"memory"); +} + +static inline void nop(void) +{ + asm volatile("nop"); +} + +static inline void hlt(void) +{ + asm volatile("hlt": : :"memory"); +} + +static inline void wbinvd(void) +{ + asm volatile("wbinvd": : :"memory"); +} + +#define CPUID_TSC (1 << 4) +#define CPUID_MSR (1 << 5) +#define CPUID_APIC (1 << 9) +#define CPUID_MTRR (1 << 12) +static inline void __cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx) +{ + asm("cpuid" + : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) + : "0" (index)); +} + +static inline u32 getcr0(void) { + u32 cr0; + asm("movl %%cr0, %0" : "=r"(cr0)); + return cr0; +} +static inline void setcr0(u32 cr0) { + asm("movl %0, %%cr0" : : "r"(cr0)); +} + +static inline u64 rdmsr(u32 index) +{ + u64 ret; + asm ("rdmsr" : "=A"(ret) : "c"(index)); + return ret; +} + +static inline void wrmsr(u32 index, u64 val) +{ + asm volatile ("wrmsr" : : "c"(index), "A"(val)); +} + +static inline u64 rdtscll(void) +{ + u64 val; + asm volatile("rdtsc" : "=A" (val)); + return val; +} + +static inline u32 __ffs(u32 word) +{ + asm("bsf %1,%0" + : "=r" (word) + : "rm" (word)); + return word; +} +static inline u32 __fls(u32 word) +{ + asm("bsr %1,%0" + : "=r" (word) + : "rm" (word)); + return word; +} + +static inline u32 getesp(void) { + u32 esp; + asm("movl %%esp, %0" : "=rm"(esp)); + return esp; +} + +static inline void writel(void *addr, u32 val) { + *(volatile u32 *)addr = val; +} +static inline void writew(void *addr, u16 val) { + *(volatile u16 *)addr = val; +} +static inline void writeb(void *addr, u8 val) { + *(volatile u8 *)addr = val; +} +static inline u32 readl(const void *addr) { + return *(volatile const u32 *)addr; +} +static inline u16 readw(const void *addr) { + return *(volatile const u16 *)addr; +} +static inline u8 readb(const void *addr) { + return *(volatile const u8 *)addr; +} + +// GDT bits +#define GDT_CODE (0x9bULL << 40) // Code segment - P,R,A bits also set +#define GDT_DATA (0x93ULL << 40) // Data segment - W,A bits also set +#define GDT_B (0x1ULL << 54) // Big flag +#define GDT_G (0x1ULL << 55) // Granularity flag +// GDT bits for segment base +#define GDT_BASE(v) ((((u64)(v) & 0xff000000) << 32) \ + | (((u64)(v) & 0x00ffffff) << 16)) +// GDT bits for segment limit (0-1Meg) +#define GDT_LIMIT(v) ((((u64)(v) & 0x000f0000) << 32) \ + | (((u64)(v) & 0x0000ffff) << 0)) +// GDT bits for segment limit (0-4Gig in 4K chunks) +#define GDT_GRANLIMIT(v) (GDT_G | GDT_LIMIT((v) >> 12)) + +struct descloc_s { + u16 length; + u32 addr; +} PACKED; + + +// x86.c +void cpuid(u32 index, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx); + + +#endif // !__ASSEMBLY__ + +#endif // x86.h
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/boot.c | 44 +++++++++++++++++++++++++++++++++++++++++++- src/util.c | 41 ----------------------------------------- src/util.h | 1 - 3 files changed, 43 insertions(+), 43 deletions(-)
diff --git a/src/boot.c b/src/boot.c index bbe9155..3542283 100644 --- a/src/boot.c +++ b/src/boot.c @@ -1,6 +1,6 @@ // Code to load disk image and start system boot. // -// Copyright (C) 2008-2010 Kevin O'Connor kevin@koconnor.net +// Copyright (C) 2008-2013 Kevin O'Connor kevin@koconnor.net // Copyright (C) 2002 MandrakeSoft S.A. // // This file may be distributed under the terms of the GNU LGPLv3 license. @@ -396,6 +396,48 @@ boot_add_cbfs(void *data, const char *desc, int prio)
/**************************************************************** + * Keyboard calls + ****************************************************************/ + +// See if a keystroke is pending in the keyboard buffer. +static int +check_for_keystroke(void) +{ + struct bregs br; + memset(&br, 0, sizeof(br)); + br.flags = F_IF|F_ZF; + br.ah = 1; + call16_int(0x16, &br); + return !(br.flags & F_ZF); +} + +// Return a keystroke - waiting forever if necessary. +static int +get_raw_keystroke(void) +{ + struct bregs br; + memset(&br, 0, sizeof(br)); + br.flags = F_IF; + call16_int(0x16, &br); + return br.ah; +} + +// Read a keystroke - waiting up to 'msec' milliseconds. +static int +get_keystroke(int msec) +{ + u32 end = irqtimer_calc(msec); + for (;;) { + if (check_for_keystroke()) + return get_raw_keystroke(); + if (irqtimer_check(end)) + return -1; + yield_toirq(); + } +} + + +/**************************************************************** * Boot menu and BCV execution ****************************************************************/
diff --git a/src/util.c b/src/util.c index dd7afdf..ee59b13 100644 --- a/src/util.c +++ b/src/util.c @@ -233,44 +233,3 @@ nullTrailingSpace(char *buf) while (end >= buf && *end <= ' ') *(end--) = '\0'; } - -/**************************************************************** - * Keyboard calls - ****************************************************************/ - -// See if a keystroke is pending in the keyboard buffer. -static int -check_for_keystroke(void) -{ - struct bregs br; - memset(&br, 0, sizeof(br)); - br.flags = F_IF|F_ZF; - br.ah = 1; - call16_int(0x16, &br); - return !(br.flags & F_ZF); -} - -// Return a keystroke - waiting forever if necessary. -static int -get_raw_keystroke(void) -{ - struct bregs br; - memset(&br, 0, sizeof(br)); - br.flags = F_IF; - call16_int(0x16, &br); - return br.ah; -} - -// Read a keystroke - waiting up to 'msec' milliseconds. -int -get_keystroke(int msec) -{ - u32 end = irqtimer_calc(msec); - for (;;) { - if (check_for_keystroke()) - return get_raw_keystroke(); - if (irqtimer_check(end)) - return -1; - yield_toirq(); - } -} diff --git a/src/util.h b/src/util.h index 70114a6..4fa0939 100644 --- a/src/util.h +++ b/src/util.h @@ -30,7 +30,6 @@ void *memmove(void *d, const void *s, size_t len); char *strtcpy(char *dest, const char *src, size_t len); char *strchr(const char *s, int c); void nullTrailingSpace(char *buf); -int get_keystroke(int msec);
// stacks.c extern u8 ExtraStack[], *StackPos;
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 8 ++++---- src/block.c | 1 + src/bmp.c | 5 +++-- src/boot.c | 1 + src/bootsplash.c | 1 + src/cdrom.c | 3 ++- src/clock.c | 1 + src/disk.c | 1 + src/fw/acpi.c | 3 ++- src/fw/biostables.c | 1 + src/fw/coreboot.c | 1 + src/fw/csm.c | 2 +- src/fw/mptable.c | 1 + src/fw/paravirt.c | 1 + src/fw/pciinit.c | 1 + src/fw/pirtable.c | 3 ++- src/fw/shadow.c | 3 ++- src/fw/smbios.c | 1 + src/fw/smm.c | 1 + src/fw/xen.c | 1 + src/hw/ahci.c | 1 + src/hw/ata.c | 1 + src/hw/blockcmd.c | 1 + src/hw/esp-scsi.c | 1 + src/hw/floppy.c | 1 + src/hw/lsi-scsi.c | 1 + src/hw/megasas.c | 1 + src/hw/pci.c | 1 + src/hw/ramdisk.c | 1 + src/hw/usb-ehci.c | 1 + src/hw/usb-hub.c | 1 + src/hw/usb-msc.c | 1 + src/hw/usb-ohci.c | 1 + src/hw/usb-uas.c | 1 + src/hw/usb-uhci.c | 1 + src/hw/usb.c | 1 + src/hw/virtio-blk.c | 1 + src/hw/virtio-pci.c | 1 + src/hw/virtio-scsi.c | 1 + src/jpeg.c | 1 + src/kbd.c | 1 + src/memmap.c | 1 + src/misc.c | 1 + src/optionroms.c | 1 + src/output.c | 1 + src/pcibios.c | 1 + src/pmm.c | 3 ++- src/pnpbios.c | 3 ++- src/post.c | 3 ++- src/resume.c | 1 + src/romfile.c | 1 + src/{util.c => string.c} | 10 +++++----- src/string.h | 30 ++++++++++++++++++++++++++++++ src/system.c | 3 ++- src/util.h | 29 +---------------------------- src/vgahooks.c | 1 + vgasrc/clext.c | 1 + vgasrc/geodevga.c | 2 +- vgasrc/stdvga.c | 2 +- vgasrc/stdvgamodes.c | 3 ++- vgasrc/vbe.c | 1 + vgasrc/vgabios.c | 3 ++- vgasrc/vgafb.c | 3 ++- 63 files changed, 112 insertions(+), 53 deletions(-) rename src/{util.c => string.c} (96%) create mode 100644 src/string.h
diff --git a/Makefile b/Makefile index 46df1c6..3a88f45 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ OUT=out/
# Source files -SRCBOTH=misc.c stacks.c output.c util.c x86.c block.c cdrom.c mouse.c kbd.c \ +SRCBOTH=misc.c stacks.c output.c string.c x86.c block.c cdrom.c mouse.c kbd.c \ serial.c clock.c resume.c pnpbios.c vgahooks.c pcibios.c apm.c \ fw/smp.c \ hw/pci.c hw/timer.c hw/pic.c hw/ps2port.c \ @@ -24,7 +24,7 @@ SRC32FLAT=$(SRCBOTH) post.c memmap.c pmm.c romfile.c optionroms.c \ fw/coreboot.c fw/lzmadecode.c fw/csm.c fw/biostables.c \ fw/paravirt.c fw/shadow.c fw/pciinit.c fw/smm.c fw/mtrr.c fw/xen.c \ fw/acpi.c fw/mptable.c fw/pirtable.c fw/smbios.c -SRC32SEG=util.c output.c pcibios.c apm.c stacks.c hw/pci.c +SRC32SEG=string.c output.c pcibios.c apm.c stacks.c hw/pci.c DIRS=src src/hw src/fw vgasrc
# Default compiler flags @@ -180,14 +180,14 @@ $(OUT)bios.bin.elf $(OUT)bios.bin: $(OUT)rom.o scripts/checkrom.py ################ VGA build rules
# VGA src files -SRCVGA=src/output.c src/util.c src/hw/pci.c \ +SRCVGA=src/output.c src/string.c src/hw/pci.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
CFLAGS16VGA = $(CFLAGS16INC) -Isrc
-$(OUT)vgaccode16.raw.s: $(OUT)autoconf.h ; $(call whole-compile, $(CFLAGS16VGA) -S, $(SRCVGA),$@) +$(OUT)vgaccode16.raw.s: $(OUT)autoconf.h $(patsubst %.c, $(OUT)%.o,$(SRCVGA)) ; $(call whole-compile, $(CFLAGS16VGA) -S, $(SRCVGA),$@)
$(OUT)vgaccode16.o: $(OUT)vgaccode16.raw.s scripts/vgafixup.py @echo " Fixup VGA rom assembler" diff --git a/src/block.c b/src/block.c index 74c6497..c6e4167 100644 --- a/src/block.c +++ b/src/block.c @@ -13,6 +13,7 @@ #include "hw/ahci.h" // process_ahci_op #include "hw/virtio-blk.h" // process_virtio_blk_op #include "hw/blockcmd.h" // cdb_* +#include "string.h" // checksum
u8 FloppyCount VARFSEG; u8 CDCount; diff --git a/src/bmp.c b/src/bmp.c index 0d54efd..81be306 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -6,8 +6,9 @@ * * This work is licensed under the terms of the GNU LGPLv3. */ -#include "util.h" -#include "bmp.h" +#include "util.h" // malloc_tmphigh +#include "bmp.h" // struct bmp_decdata +#include "string.h" // memcpy
#define bmp_load4byte(addr) (*(u32 *)(addr)) #define bmp_load2byte(addr) (*(u16 *)(addr)) diff --git a/src/boot.c b/src/boot.c index 3542283..68a20d9 100644 --- a/src/boot.c +++ b/src/boot.c @@ -16,6 +16,7 @@ #include "hw/usb.h" // struct usbdevice_s #include "fw/csm.h" // csm_bootprio_* #include "list.h" // hlist_node +#include "string.h" // memset
/**************************************************************** diff --git a/src/bootsplash.c b/src/bootsplash.c index bd91102..f4f8ea9 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -13,6 +13,7 @@ #include "vbe.h" // struct vbe_info #include "bmp.h" // bmp_alloc #include "fw/smbios.h" // display_uuid +#include "string.h" // memset
/**************************************************************** diff --git a/src/cdrom.c b/src/cdrom.c index 94265b0..0d3fa1f 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -6,11 +6,12 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "disk.h" // cdrom_13 -#include "util.h" // memset +#include "util.h" // dprintf #include "bregs.h" // struct bregs #include "biosvar.h" // GET_GLOBAL #include "hw/ata.h" // ATA_CMD_REQUEST_SENSE #include "hw/blockcmd.h" // CDB_CMD_REQUEST_SENSE +#include "string.h" // memset
// Locks for removable devices u8 CDRom_locks[BUILD_MAX_EXTDRIVE] VARLOW; diff --git a/src/clock.c b/src/clock.c index cc962e4..fc91db7 100644 --- a/src/clock.c +++ b/src/clock.c @@ -14,6 +14,7 @@ #include "bregs.h" // struct bregs #include "biosvar.h" // GET_GLOBAL #include "hw/usb-hid.h" // usb_check_event +#include "string.h" // memset
// RTC register flags #define RTC_A_UIP 0x80 diff --git a/src/disk.c b/src/disk.c index 78252b1..fd80588 100644 --- a/src/disk.c +++ b/src/disk.c @@ -13,6 +13,7 @@ #include "bregs.h" // struct bregs #include "hw/pci.h" // pci_bdf_to_bus #include "hw/ata.h" // ATA_CB_DC +#include "string.h" // memset
/**************************************************************** diff --git a/src/fw/acpi.c b/src/fw/acpi.c index fcf11ea..8abd205 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -6,7 +6,7 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "acpi.h" // struct rsdp_descriptor -#include "util.h" // memcpy +#include "util.h" // dprintf #include "byteorder.h" // cpu_to_le16 #include "hw/pci.h" // pci_find_init_device #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL @@ -15,6 +15,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "dev-q35.h" +#include "string.h" // memset #include "x86.h" // readl
#include "src/fw/acpi-dsdt.hex" diff --git a/src/fw/biostables.c b/src/fw/biostables.c index beb0bed..cd58ff9 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -10,6 +10,7 @@ #include "acpi.h" // struct rsdp_descriptor #include "mptable.h" // MPTABLE_SIGNATURE #include "smbios.h" // struct smbios_entry_point +#include "string.h" // memcpy
static void copy_pir(void *pos) diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 126649a..6da90b5 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -15,6 +15,7 @@ #include "acpi.h" // find_acpi_features #include "hw/pci.h" // pci_probe_devices #include "paravirt.h" // PlatformRunningOn +#include "string.h" // memset
/**************************************************************** diff --git a/src/fw/csm.c b/src/fw/csm.c index 0093bee..4a78bac 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -6,7 +6,7 @@
#include "config.h" // CONFIG_* #include "csm.h" -#include "util.h" // checksum +#include "util.h" // dprintf #include "bregs.h" #include "optionroms.h" #include "hw/pci.h" diff --git a/src/fw/mptable.c b/src/fw/mptable.c index 47fe53d..ecc618a 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -10,6 +10,7 @@ #include "mptable.h" // MPTABLE_SIGNATURE #include "hw/pci.h" #include "hw/pci_regs.h" +#include "string.h" // memset #include "x86.h" // cpuid
void diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index a68e3a1..2be4281 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -20,6 +20,7 @@ #include "mptable.h" // mptable_setup #include "hw/pci.h" // create_pirtable #include "xen.h" // xen_biostable_setup +#include "string.h" // memset #include "x86.h" // cpuid
// Amount of continuous ram under 4Gig diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index ca32d43..ee8d5dd 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -16,6 +16,7 @@ #include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR #include "list.h" // struct hlist_node #include "acpi.h" // acpi_pm1a_cnt +#include "string.h" // memset
#define PCI_DEVICE_MEM_MIN 0x1000 #define PCI_BRIDGE_IO_MIN 0x1000 diff --git a/src/fw/pirtable.c b/src/fw/pirtable.c index 57fb48f..d66d21b 100644 --- a/src/fw/pirtable.c +++ b/src/fw/pirtable.c @@ -7,7 +7,8 @@
#include "hw/pci.h" // struct pir_header #include "config.h" // CONFIG_* -#include "util.h" // checksum +#include "util.h" // dprintf +#include "string.h" // checksum
struct pir_header *PirAddr VARFSEG;
diff --git a/src/fw/shadow.c b/src/fw/shadow.c index 767c6ea..45cfcaf 100644 --- a/src/fw/shadow.c +++ b/src/fw/shadow.c @@ -5,13 +5,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // memcpy +#include "util.h" // dprintf #include "hw/pci.h" // pci_config_writeb #include "config.h" // CONFIG_* #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "paravirt.h" // runningOnXen #include "dev-q35.h" // PCI_VENDOR_ID_INTEL +#include "string.h" // memset #include "x86.h" // wbinvd
// On the emulators, the bios at 0xf0000 is also at 0xffff0000 diff --git a/src/fw/smbios.c b/src/fw/smbios.c index 93fb57f..f80b42b 100644 --- a/src/fw/smbios.c +++ b/src/fw/smbios.c @@ -9,6 +9,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "smbios.h" // struct smbios_entry_point +#include "string.h" // memset #include "x86.h" // cpuid
struct smbios_entry_point *SMBiosAddr; diff --git a/src/fw/smm.c b/src/fw/smm.c index 3a1a799..8ca1e83 100644 --- a/src/fw/smm.c +++ b/src/fw/smm.c @@ -12,6 +12,7 @@ #include "ioport.h" // outb #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "dev-q35.h" +#include "string.h" // memcpy #include "x86.h" // wbinvd
extern u8 smm_relocation_start, smm_relocation_end; diff --git a/src/fw/xen.c b/src/fw/xen.c index 6e21bff..f181e5f 100644 --- a/src/fw/xen.c +++ b/src/fw/xen.c @@ -11,6 +11,7 @@ #include "types.h" // ASM32FLAT #include "util.h" // copy_acpi_rsdp #include "acpi.h" // find_acpi_features +#include "string.h" // memcpy #include "x86.h" // cpuid
#define INFO_PHYSICAL_ADDRESS 0x00001000 diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 0e99d14..2435b83 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -16,6 +16,7 @@ #include "ata.h" // ATA_CB_STAT #include "ahci.h" // CDB_CMD_READ_10 #include "blockcmd.h" // CDB_CMD_READ_10 +#include "string.h" // memset
#define AHCI_REQUEST_TIMEOUT 32000 // 32 seconds max for IDE ops #define AHCI_RESET_TIMEOUT 500 // 500 miliseconds diff --git a/src/hw/ata.c b/src/hw/ata.c index e319aa9..705e106 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -19,6 +19,7 @@ #include "disk.h" // struct ata_s #include "ata.h" // ATA_CB_STAT #include "blockcmd.h" // CDB_CMD_READ_10 +#include "string.h" // memset
#define IDE_TIMEOUT 32000 //32 seconds max for IDE ops
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 5cd4eb0..6f79cc5 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -19,6 +19,7 @@ #include "esp-scsi.h" // esp_scsi_cmd_data #include "megasas.h" // megasas_cmd_data #include "boot.h" // boot_add_hd +#include "string.h" // memset
// Route command to low-level handler. static int diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 42a790f..49c74ff 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -20,6 +20,7 @@ #include "blockcmd.h" // scsi_drive_setup #include "fw/paravirt.h" // runningOnQEMU #include "disk.h" +#include "string.h" // memset
#define ESP_TCLO 0x00 #define ESP_TCMID 0x04 diff --git a/src/hw/floppy.c b/src/hw/floppy.c index 37b7092..ae66bc0 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -16,6 +16,7 @@ #include "boot.h" // boot_add_floppy #include "pci.h" // pci_to_bdf #include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA +#include "string.h" // memset
#define FLOPPY_SIZE_CODE 0x02 // 512 byte sectors #define FLOPPY_DATALEN 0xff // Not used - because size code is 0x02 diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index cebe967..0563fab 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -20,6 +20,7 @@ #include "blockcmd.h" // scsi_drive_setup #include "fw/paravirt.h" // runningOnQEMU #include "disk.h" +#include "string.h" // memset
#define LSI_REG_DSTAT 0x0c #define LSI_REG_ISTAT0 0x14 diff --git a/src/hw/megasas.c b/src/hw/megasas.c index f4eeba0..144fb84 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -19,6 +19,7 @@ #include "boot.h" // bootprio_find_scsi_device #include "blockcmd.h" // scsi_drive_setup #include "disk.h" +#include "string.h" // memset
#define MFI_DB 0x0 // Doorbell #define MFI_OMSG0 0x18 // Outbound message 0 diff --git a/src/hw/pci.c b/src/hw/pci.c index d1115a4..7fdde2a 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -12,6 +12,7 @@ #include "farptr.h" // MAKE_FLATPTR #include "pci_regs.h" // PCI_VENDOR_ID #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA +#include "string.h" // memset #include "x86.h" // readl
void pci_config_writel(u16 bdf, u32 addr, u32 val) diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index b9da2ad..6e730bf 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -10,6 +10,7 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "string.h" // memset
void ramdisk_setup(void) diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 333679e..bb02293 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -15,6 +15,7 @@ #include "biosvar.h" // GET_LOWFLAT #include "usb-uhci.h" // uhci_setup #include "usb-ohci.h" // ohci_setup +#include "string.h" // memset #include "x86.h" // readl
struct usb_ehci_s { diff --git a/src/hw/usb-hub.c b/src/hw/usb-hub.c index 0b55d15..5bef26f 100644 --- a/src/hw/usb-hub.c +++ b/src/hw/usb-hub.c @@ -8,6 +8,7 @@ #include "config.h" // CONFIG_USB_HUB #include "usb-hub.h" // struct usb_hub_descriptor #include "usb.h" // struct usb_s +#include "string.h" // memset
static int get_hub_desc(struct usb_pipe *pipe, struct usb_hub_descriptor *desc) diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index 7b2524d..d5cf1b4 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -12,6 +12,7 @@ #include "blockcmd.h" // cdb_read #include "disk.h" // DTYPE_USB #include "boot.h" // bootprio_find_usb +#include "string.h" // memset
struct usbdrive_s { struct drive_s drive; diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index c1806ff..0febcca 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -11,6 +11,7 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT +#include "string.h" // memset #include "x86.h" // readl
#define FIT (1 << 31) diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 3169389..c205d7f 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -22,6 +22,7 @@ #include "disk.h" // DTYPE_UAS #include "boot.h" // bootprio_find_usb #include "usb-uas.h" // usb_uas_init +#include "string.h" // memset
#define UAS_UI_COMMAND 0x01 #define UAS_UI_SENSE 0x03 diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index d8f9b1e..4716d98 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -12,6 +12,7 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_4 #include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT +#include "string.h" // memset
struct usb_uhci_s { struct usb_s usb; diff --git a/src/hw/usb.c b/src/hw/usb.c index 647359e..4026555 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -18,6 +18,7 @@ #include "usb-uas.h" // usb_uas_setup #include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL +#include "string.h" // memset #include "x86.h" // __fls
diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 6c0cd74..761e64f 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -18,6 +18,7 @@ #include "virtio-ring.h" #include "virtio-blk.h" #include "disk.h" +#include "string.h" // memset
struct virtiodrive_s { struct drive_s drive; diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index 4b9ad0a..6a16463 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -21,6 +21,7 @@ #include "util.h" // dprintf #include "pci.h" // pci_config_readl #include "pci_regs.h" // PCI_BASE_ADDRESS_0 +#include "string.h" // memset
int vp_find_vq(unsigned int ioaddr, int queue_index, struct vring_virtqueue **p_vq) diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 4de1255..06f7b60 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -19,6 +19,7 @@ #include "virtio-ring.h" #include "virtio-scsi.h" #include "disk.h" +#include "string.h" // memset
struct virtio_lun_s { struct drive_s drive; diff --git a/src/jpeg.c b/src/jpeg.c index a96a9d7..e7fc337 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -42,6 +42,7 @@ #define __LITTLE_ENDIAN #include "util.h" #include "jpeg.h" +#include "string.h" #define ISHIFT 11
#define IFIX(a) ((int)((a) * (1 << ISHIFT) + .5)) diff --git a/src/kbd.c b/src/kbd.c index 2e2ced7..2257565 100644 --- a/src/kbd.c +++ b/src/kbd.c @@ -11,6 +11,7 @@ #include "bregs.h" // struct bregs #include "hw/ps2port.h" // ps2_kbd_command #include "hw/usb-hid.h" // usb_kbd_command +#include "string.h" // memset
// Bit definitions for BDA kbd_flag[012] #define KF0_RSHIFT (1<<0) diff --git a/src/memmap.c b/src/memmap.c index d617b81..ab1bcad 100644 --- a/src/memmap.c +++ b/src/memmap.c @@ -7,6 +7,7 @@ #include "memmap.h" // struct e820entry #include "config.h" // BUILD_MAX_E820 #include "util.h" // dprintf.h +#include "string.h" // memmove
/**************************************************************** diff --git a/src/misc.c b/src/misc.c index 338c607..8074234 100644 --- a/src/misc.c +++ b/src/misc.c @@ -9,6 +9,7 @@ #include "biosvar.h" // GET_BDA #include "util.h" // debug_enter #include "hw/pic.h" // enable_hwirq +#include "string.h" // memset
/**************************************************************** diff --git a/src/optionroms.c b/src/optionroms.c index ffa426d..8288e5f 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -14,6 +14,7 @@ #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "boot.h" // IPL #include "optionroms.h" // struct rom_header +#include "string.h" // memset
/**************************************************************** diff --git a/src/output.c b/src/output.c index 8b63d9a..918a6ed 100644 --- a/src/output.c +++ b/src/output.c @@ -12,6 +12,7 @@ #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL #include "fw/paravirt.h" // PlatformRunningOn +#include "string.h" // memset
struct putcinfo { void (*func)(struct putcinfo *info, char c); diff --git a/src/pcibios.c b/src/pcibios.c index 43eb547..5b242c9 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -11,6 +11,7 @@ #include "bregs.h" // struct bregs #include "biosvar.h" // GET_GLOBAL #include "hw/pci_regs.h" // PCI_VENDOR_ID +#include "string.h" // checksum
// romlayout.S extern void entry_bios32(void); diff --git a/src/pmm.c b/src/pmm.c index c86d66f..fef343b 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -4,13 +4,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // checksum +#include "util.h" // dprintf #include "config.h" // BUILD_BIOS_ADDR #include "memmap.h" // struct e820entry #include "farptr.h" // GET_FARVAR #include "biosvar.h" // GET_BDA #include "optionroms.h" // OPTION_ROM_ALIGN #include "list.h" // hlist_node +#include "string.h" // memset #include "x86.h" // __ffs
// Information on a reserved area. diff --git a/src/pnpbios.c b/src/pnpbios.c index fddcc81..e67425f 100644 --- a/src/pnpbios.c +++ b/src/pnpbios.c @@ -4,9 +4,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // checksum +#include "util.h" // dprintf #include "config.h" // BUILD_BIOS_ADDR #include "farptr.h" // SET_FARVAR +#include "string.h" // checksum
struct pnpheader { u32 signature; diff --git a/src/post.c b/src/post.c index 7d6fbd2..f1cb8a8 100644 --- a/src/post.c +++ b/src/post.c @@ -7,7 +7,7 @@
#include "config.h" // CONFIG_* #include "hw/cmos.h" // CMOS_* -#include "util.h" // memset +#include "util.h" // dprintf #include "biosvar.h" // struct bios_data_area_s #include "disk.h" // floppy_setup #include "hw/ata.h" // ata_setup @@ -26,6 +26,7 @@ #include "hw/esp-scsi.h" // esp_scsi_setup #include "hw/megasas.h" // megasas_setup #include "post.h" // interface_init +#include "string.h" // memset
/**************************************************************** diff --git a/src/resume.c b/src/resume.c index 5323d7e..7fb4a75 100644 --- a/src/resume.c +++ b/src/resume.c @@ -13,6 +13,7 @@ #include "hw/ps2port.h" // i8042_reboot #include "hw/pci.h" // pci_reboot #include "hw/cmos.h" // inb_cmos +#include "string.h" // memset
// Indicator if POST phase has been run. int HaveRunPost VARFSEG; diff --git a/src/romfile.c b/src/romfile.c index ea71d1f..f19f756 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -6,6 +6,7 @@
#include "config.h" // CONFIG_* #include "util.h" // dprintf +#include "string.h" // memcmp
static struct romfile_s *RomfileRoot VARVERIFY32INIT;
diff --git a/src/util.c b/src/string.c similarity index 96% rename from src/util.c rename to src/string.c index ee59b13..5f2dede 100644 --- a/src/util.c +++ b/src/string.c @@ -1,12 +1,12 @@ -// Misc utility functions. +// String manipulation functions. // -// Copyright (C) 2008,2009 Kevin O'Connor kevin@koconnor.net +// Copyright (C) 2008-2013 Kevin O'Connor kevin@koconnor.net // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // call16 -#include "bregs.h" // struct bregs -#include "config.h" // BUILD_STACK_ADDR +#include "util.h" // yield +#include "string.h" // memcpy +#include "farptr.h" // SET_SEG
/**************************************************************** diff --git a/src/string.h b/src/string.h new file mode 100644 index 0000000..7c4c5ee --- /dev/null +++ b/src/string.h @@ -0,0 +1,30 @@ +// String manipulation function defs. +#ifndef __STRING_H +#define __STRING_H + +#include "types.h" // u32 + +// string.c +u8 checksum_far(u16 buf_seg, void *buf_far, u32 len); +u8 checksum(void *buf, u32 len); +size_t strlen(const char *s); +int memcmp(const void *s1, const void *s2, size_t n); +int strcmp(const char *s1, const char *s2); +inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len); +inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len); +void *memset(void *s, int c, size_t n); +void memset_fl(void *ptr, u8 val, size_t size); +inline void memcpy_far(u16 d_seg, void *d_far + , u16 s_seg, const void *s_far, size_t len); +void memcpy_fl(void *d_fl, const void *s_fl, size_t len); +void *memcpy(void *d1, const void *s1, size_t len); +#if MODESEGMENT == 0 +#define memcpy __builtin_memcpy +#endif +void iomemcpy(void *d, const void *s, u32 len); +void *memmove(void *d, const void *s, size_t len); +char *strtcpy(char *dest, const char *src, size_t len); +char *strchr(const char *s, int c); +void nullTrailingSpace(char *buf); + +#endif // string.h diff --git a/src/system.c b/src/system.c index 5269ccf..af31db7 100644 --- a/src/system.c +++ b/src/system.c @@ -5,12 +5,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // memcpy_far +#include "util.h" // debug_enter #include "biosvar.h" // BIOS_CONFIG_TABLE #include "ioport.h" // inb #include "memmap.h" // E820_RAM #include "hw/pic.h" // pic_reset #include "bregs.h" // struct bregs +#include "string.h" // memcpy_far
// Use PS2 System Control port A to set A20 enable static inline u8 diff --git a/src/util.h b/src/util.h index 4fa0939..230db10 100644 --- a/src/util.h +++ b/src/util.h @@ -1,36 +1,9 @@ -// Basic x86 asm functions and function defs. -// -// Copyright (C) 2008-2010 Kevin O'Connor kevin@koconnor.net -// -// This file may be distributed under the terms of the GNU LGPLv3 license. +// Misc function and variable declarations. #ifndef __UTIL_H #define __UTIL_H
#include "types.h" // u32
-// util.c -u8 checksum_far(u16 buf_seg, void *buf_far, u32 len); -u8 checksum(void *buf, u32 len); -size_t strlen(const char *s); -int memcmp(const void *s1, const void *s2, size_t n); -int strcmp(const char *s1, const char *s2); -inline void memset_far(u16 d_seg, void *d_far, u8 c, size_t len); -inline void memset16_far(u16 d_seg, void *d_far, u16 c, size_t len); -void *memset(void *s, int c, size_t n); -void memset_fl(void *ptr, u8 val, size_t size); -inline void memcpy_far(u16 d_seg, void *d_far - , u16 s_seg, const void *s_far, size_t len); -void memcpy_fl(void *d_fl, const void *s_fl, size_t len); -void *memcpy(void *d1, const void *s1, size_t len); -#if MODESEGMENT == 0 -#define memcpy __builtin_memcpy -#endif -void iomemcpy(void *d, const void *s, u32 len); -void *memmove(void *d, const void *s, size_t len); -char *strtcpy(char *dest, const char *src, size_t len); -char *strchr(const char *s, int c); -void nullTrailingSpace(char *buf); - // stacks.c extern u8 ExtraStack[], *StackPos; u32 stack_hop(u32 eax, u32 edx, void *func); diff --git a/src/vgahooks.c b/src/vgahooks.c index 83d5a74..9917014 100644 --- a/src/vgahooks.c +++ b/src/vgahooks.c @@ -11,6 +11,7 @@ #include "hw/pci_ids.h" // PCI_VENDOR_ID_VIA #include "util.h" // handle_155f #include "config.h" // CONFIG_* +#include "string.h" // strcmp
#define VH_VIA 1 #define VH_INTEL 2 diff --git a/vgasrc/clext.c b/vgasrc/clext.c index 8377da1..6fc6337 100644 --- a/vgasrc/clext.c +++ b/vgasrc/clext.c @@ -13,6 +13,7 @@ #include "stdvga.h" // VGAREG_SEQU_ADDRESS #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_BASE_ADDRESS_0 +#include "string.h" // memset16_far
/**************************************************************** diff --git a/vgasrc/geodevga.c b/vgasrc/geodevga.c index cdc9e44..4a63068 100644 --- a/vgasrc/geodevga.c +++ b/vgasrc/geodevga.c @@ -10,7 +10,7 @@ #include "farptr.h" // SET_FARVAR #include "biosvar.h" // GET_BDA #include "vgabios.h" // VGAREG_* -#include "util.h" // memset +#include "util.h" // dprintf #include "stdvga.h" // stdvga_crtc_write #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_BASE_ADDRESS_0 diff --git a/vgasrc/stdvga.c b/vgasrc/stdvga.c index 3c92eec..baf8135 100644 --- a/vgasrc/stdvga.c +++ b/vgasrc/stdvga.c @@ -10,7 +10,7 @@ #include "ioport.h" // outb #include "farptr.h" // SET_FARVAR #include "biosvar.h" // GET_GLOBAL -#include "util.h" // memcpy_far +#include "string.h" // memset_far
/**************************************************************** diff --git a/vgasrc/stdvgamodes.c b/vgasrc/stdvgamodes.c index 1756ade..f22f82c 100644 --- a/vgasrc/stdvgamodes.c +++ b/vgasrc/stdvgamodes.c @@ -7,8 +7,9 @@
#include "vgabios.h" // struct VideoParamTableEntry_s #include "biosvar.h" // GET_GLOBAL -#include "util.h" // memcpy_far +#include "util.h" // warn_internalerror #include "stdvga.h" // stdvga_find_mode +#include "string.h" // memcpy_far
/**************************************************************** diff --git a/vgasrc/vbe.c b/vgasrc/vbe.c index 2c08736..8595e69 100644 --- a/vgasrc/vbe.c +++ b/vgasrc/vbe.c @@ -13,6 +13,7 @@ #include "util.h" // dprintf #include "biosvar.h" // GET_GLOBAL #include "vgahw.h" // vgahw_set_mode +#include "string.h" // memset_far
u32 VBE_total_memory VAR16 = 256 * 1024; u32 VBE_capabilities VAR16; diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 506dd8d..12cd782 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -7,7 +7,7 @@
#include "bregs.h" // struct bregs #include "biosvar.h" // GET_BDA -#include "util.h" // memset +#include "util.h" // dprintf #include "vgabios.h" // calc_page_size #include "optionroms.h" // struct pci_data #include "config.h" // CONFIG_* @@ -17,6 +17,7 @@ #include "vbe.h" // VBE_RETURN_STATUS_FAILED #include "hw/pci.h" // pci_config_readw #include "hw/pci_regs.h" // PCI_VENDOR_ID +#include "string.h" // memset_far
// Standard Video Save Pointer Table struct VideoSavePointer_s { diff --git a/vgasrc/vgafb.c b/vgasrc/vgafb.c index 3b2f367..1fa11b5 100644 --- a/vgasrc/vgafb.c +++ b/vgasrc/vgafb.c @@ -7,9 +7,10 @@
#include "vgabios.h" // vgafb_scroll #include "biosvar.h" // GET_BDA -#include "util.h" // memset_far +#include "util.h" // dprintf #include "byteorder.h" // cpu_to_be16 #include "stdvga.h" // stdvga_planar4_plane +#include "string.h" // memset_far
/****************************************************************
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/apm.c | 1 + src/block.c | 1 + src/bootsplash.c | 1 + src/clock.c | 1 + src/disk.c | 1 + src/fw/coreboot.c | 1 + src/fw/csm.c | 1 + src/fw/smp.c | 1 + src/hw/ahci.c | 1 + src/hw/ata.c | 1 + src/hw/floppy.c | 1 + src/hw/megasas.c | 1 + src/hw/pci.c | 1 + src/hw/ps2port.c | 1 + src/hw/ramdisk.c | 1 + src/hw/timer.c | 1 + src/hw/usb.h | 2 +- src/kbd.c | 1 + src/misc.c | 1 + src/mouse.c | 1 + src/optionroms.c | 1 + src/output.c | 1 + src/pmm.c | 1 + src/resume.c | 1 + src/serial.c | 1 + src/stacks.c | 1 + src/string.c | 2 +- src/util.h | 28 +--------------------------- 28 files changed, 28 insertions(+), 29 deletions(-)
diff --git a/src/apm.c b/src/apm.c index 211424c..32d1f4b 100644 --- a/src/apm.c +++ b/src/apm.c @@ -13,6 +13,7 @@ #include "biosvar.h" // GET_GLOBAL #include "fw/paravirt.h" // runningOnQEMU #include "fw/acpi.h" // acpi_pm_ctl +#include "stacks.h" // yield_toirq
static void out_str(const char *str_cs) diff --git a/src/block.c b/src/block.c index c6e4167..9cfd7dd 100644 --- a/src/block.c +++ b/src/block.c @@ -13,6 +13,7 @@ #include "hw/ahci.h" // process_ahci_op #include "hw/virtio-blk.h" // process_virtio_blk_op #include "hw/blockcmd.h" // cdb_* +#include "stacks.h" // stack_hop #include "string.h" // checksum
u8 FloppyCount VARFSEG; diff --git a/src/bootsplash.c b/src/bootsplash.c index f4f8ea9..340839b 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -13,6 +13,7 @@ #include "vbe.h" // struct vbe_info #include "bmp.h" // bmp_alloc #include "fw/smbios.h" // display_uuid +#include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/clock.c b/src/clock.c index fc91db7..6b27aa9 100644 --- a/src/clock.c +++ b/src/clock.c @@ -14,6 +14,7 @@ #include "bregs.h" // struct bregs #include "biosvar.h" // GET_GLOBAL #include "hw/usb-hid.h" // usb_check_event +#include "stacks.h" // yield #include "string.h" // memset
// RTC register flags diff --git a/src/disk.c b/src/disk.c index fd80588..2d335e6 100644 --- a/src/disk.c +++ b/src/disk.c @@ -13,6 +13,7 @@ #include "bregs.h" // struct bregs #include "hw/pci.h" // pci_bdf_to_bus #include "hw/ata.h" // ATA_CB_DC +#include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 6da90b5..c67a62b 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -15,6 +15,7 @@ #include "acpi.h" // find_acpi_features #include "hw/pci.h" // pci_probe_devices #include "paravirt.h" // PlatformRunningOn +#include "stacks.h" // yield #include "string.h" // memset
diff --git a/src/fw/csm.c b/src/fw/csm.c index 4a78bac..81159b3 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -17,6 +17,7 @@ #include "boot.h" #include "smbios.h" #include "hw/pic.h" +#include "stacks.h" // wait_threads
struct rsdp_descriptor csm_rsdp VARFSEG __aligned(16);
diff --git a/src/fw/smp.c b/src/fw/smp.c index a8504ab..1906255 100644 --- a/src/fw/smp.c +++ b/src/fw/smp.c @@ -8,6 +8,7 @@ #include "util.h" // dprintf #include "config.h" // CONFIG_* #include "hw/cmos.h" // CMOS_BIOS_SMP_COUNT +#include "stacks.h" // yield #include "x86.h" // wrmsr
#define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300) diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 2435b83..6f56cb1 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -16,6 +16,7 @@ #include "ata.h" // ATA_CB_STAT #include "ahci.h" // CDB_CMD_READ_10 #include "blockcmd.h" // CDB_CMD_READ_10 +#include "stacks.h" // yield #include "string.h" // memset
#define AHCI_REQUEST_TIMEOUT 32000 // 32 seconds max for IDE ops diff --git a/src/hw/ata.c b/src/hw/ata.c index 705e106..5e9b905 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -19,6 +19,7 @@ #include "disk.h" // struct ata_s #include "ata.h" // ATA_CB_STAT #include "blockcmd.h" // CDB_CMD_READ_10 +#include "stacks.h" // yield #include "string.h" // memset
#define IDE_TIMEOUT 32000 //32 seconds max for IDE ops diff --git a/src/hw/floppy.c b/src/hw/floppy.c index ae66bc0..c051f54 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -16,6 +16,7 @@ #include "boot.h" // boot_add_floppy #include "pci.h" // pci_to_bdf #include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA +#include "stacks.h" // yield #include "string.h" // memset
#define FLOPPY_SIZE_CODE 0x02 // 512 byte sectors diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 144fb84..19ed1b4 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -19,6 +19,7 @@ #include "boot.h" // bootprio_find_scsi_device #include "blockcmd.h" // scsi_drive_setup #include "disk.h" +#include "stacks.h" // yield #include "string.h" // memset
#define MFI_DB 0x0 // Doorbell diff --git a/src/hw/pci.c b/src/hw/pci.c index 7fdde2a..295a26d 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -12,6 +12,7 @@ #include "farptr.h" // MAKE_FLATPTR #include "pci_regs.h" // PCI_VENDOR_ID #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA +#include "stacks.h" // call32 #include "string.h" // memset #include "x86.h" // readl
diff --git a/src/hw/ps2port.c b/src/hw/ps2port.c index 4b6c5df..6fd0c3a 100644 --- a/src/hw/ps2port.c +++ b/src/hw/ps2port.c @@ -10,6 +10,7 @@ #include "biosvar.h" // GET_LOW #include "ps2port.h" // ps2_kbd_command #include "pic.h" // pic_eoi1 +#include "stacks.h" // yield
/**************************************************************** diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 6e730bf..cd517e7 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -10,6 +10,7 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "stacks.h" // call16_int #include "string.h" // memset
void diff --git a/src/hw/timer.c b/src/hw/timer.c index 2547639..56c4eca 100644 --- a/src/hw/timer.c +++ b/src/hw/timer.c @@ -9,6 +9,7 @@ #include "ioport.h" // PORT_PIT_MODE #include "config.h" // CONFIG_* #include "biosvar.h" // GET_LOW +#include "stacks.h" // yield #include "x86.h" // cpuid
// Bits for PORT_PS2_CTRLB diff --git a/src/hw/usb.h b/src/hw/usb.h index a43e829..1ac86c7 100644 --- a/src/hw/usb.h +++ b/src/hw/usb.h @@ -2,7 +2,7 @@ #ifndef __USB_H #define __USB_H
-#include "util.h" // struct mutex_s +#include "stacks.h" // struct mutex_s
// Information on a USB end point. struct usb_pipe { diff --git a/src/kbd.c b/src/kbd.c index 2257565..4302a05 100644 --- a/src/kbd.c +++ b/src/kbd.c @@ -11,6 +11,7 @@ #include "bregs.h" // struct bregs #include "hw/ps2port.h" // ps2_kbd_command #include "hw/usb-hid.h" // usb_kbd_command +#include "stacks.h" // stack_hop #include "string.h" // memset
// Bit definitions for BDA kbd_flag[012] diff --git a/src/misc.c b/src/misc.c index 8074234..642bbb1 100644 --- a/src/misc.c +++ b/src/misc.c @@ -9,6 +9,7 @@ #include "biosvar.h" // GET_BDA #include "util.h" // debug_enter #include "hw/pic.h" // enable_hwirq +#include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/mouse.c b/src/mouse.c index 5a7ae0a..8e8374c 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -10,6 +10,7 @@ #include "bregs.h" // struct bregs #include "hw/ps2port.h" // ps2_mouse_command #include "hw/usb-hid.h" // usb_mouse_command +#include "stacks.h" // stack_hop
void mouse_init(void) diff --git a/src/optionroms.c b/src/optionroms.c index 8288e5f..cc6083b 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -14,6 +14,7 @@ #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "boot.h" // IPL #include "optionroms.h" // struct rom_header +#include "stacks.h" // farcall16big #include "string.h" // memset
diff --git a/src/output.c b/src/output.c index 918a6ed..b5d7ae0 100644 --- a/src/output.c +++ b/src/output.c @@ -12,6 +12,7 @@ #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL #include "fw/paravirt.h" // PlatformRunningOn +#include "stacks.h" // call16_int #include "string.h" // memset
struct putcinfo { diff --git a/src/pmm.c b/src/pmm.c index fef343b..cd6ee89 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -11,6 +11,7 @@ #include "biosvar.h" // GET_BDA #include "optionroms.h" // OPTION_ROM_ALIGN #include "list.h" // hlist_node +#include "stacks.h" // wait_preempt #include "string.h" // memset #include "x86.h" // __ffs
diff --git a/src/resume.c b/src/resume.c index 7fb4a75..892c76c 100644 --- a/src/resume.c +++ b/src/resume.c @@ -13,6 +13,7 @@ #include "hw/ps2port.h" // i8042_reboot #include "hw/pci.h" // pci_reboot #include "hw/cmos.h" // inb_cmos +#include "stacks.h" // farcall16big #include "string.h" // memset
// Indicator if POST phase has been run. diff --git a/src/serial.c b/src/serial.c index b4a0a53..8fd3067 100644 --- a/src/serial.c +++ b/src/serial.c @@ -8,6 +8,7 @@ #include "biosvar.h" // SET_BDA #include "util.h" // debug_enter #include "bregs.h" // struct bregs +#include "stacks.h" // yield
/**************************************************************** diff --git a/src/stacks.c b/src/stacks.c index ac75497..b499872 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -8,6 +8,7 @@ #include "util.h" // dprintf #include "bregs.h" // CR0_PE #include "list.h" // hlist_node +#include "stacks.h" // struct mutex_s
/**************************************************************** diff --git a/src/string.c b/src/string.c index 5f2dede..574c13e 100644 --- a/src/string.c +++ b/src/string.c @@ -4,7 +4,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // yield +#include "stacks.h" // yield #include "string.h" // memcpy #include "farptr.h" // SET_SEG
diff --git a/src/util.h b/src/util.h index 230db10..0492e39 100644 --- a/src/util.h +++ b/src/util.h @@ -4,33 +4,6 @@
#include "types.h" // u32
-// stacks.c -extern u8 ExtraStack[], *StackPos; -u32 stack_hop(u32 eax, u32 edx, void *func); -u32 stack_hop_back(u32 eax, u32 edx, void *func); -u32 call32(void *func, u32 eax, u32 errret); -struct bregs; -inline void farcall16(struct bregs *callregs); -inline void farcall16big(struct bregs *callregs); -inline void __call16_int(struct bregs *callregs, u16 offset); -#define call16_int(nr, callregs) do { \ - extern void irq_trampoline_ ##nr (); \ - __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \ - } while (0) -extern struct thread_info MainThread; -struct thread_info *getCurThread(void); -void yield(void); -void yield_toirq(void); -void run_thread(void (*func)(void*), void *data); -void wait_threads(void); -struct mutex_s { u32 isLocked; }; -void mutex_lock(struct mutex_s *mutex); -void mutex_unlock(struct mutex_s *mutex); -void start_preempt(void); -void finish_preempt(void); -int wait_preempt(void); -void check_preempt(void); - // output.c extern u16 DebugOutputPort; void debug_serial_preinit(void); @@ -44,6 +17,7 @@ char * znprintf(size_t size, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); void __dprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +struct bregs; void __debug_enter(struct bregs *regs, const char *fname); void __debug_isr(const char *fname); void __debug_stub(struct bregs *regs, int lineno, const char *fname);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/stacks.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/stacks.h
diff --git a/src/stacks.h b/src/stacks.h new file mode 100644 index 0000000..5ee4adc --- /dev/null +++ b/src/stacks.h @@ -0,0 +1,34 @@ +// Misc function and variable declarations. +#ifndef __STACKS_H +#define __STACKS_H + +#include "types.h" // u32 + +// stacks.c +extern u8 ExtraStack[], *StackPos; +u32 stack_hop(u32 eax, u32 edx, void *func); +u32 stack_hop_back(u32 eax, u32 edx, void *func); +u32 call32(void *func, u32 eax, u32 errret); +struct bregs; +inline void farcall16(struct bregs *callregs); +inline void farcall16big(struct bregs *callregs); +inline void __call16_int(struct bregs *callregs, u16 offset); +#define call16_int(nr, callregs) do { \ + extern void irq_trampoline_ ##nr (); \ + __call16_int((callregs), (u32)&irq_trampoline_ ##nr ); \ + } while (0) +extern struct thread_info MainThread; +struct thread_info *getCurThread(void); +void yield(void); +void yield_toirq(void); +void run_thread(void (*func)(void*), void *data); +void wait_threads(void); +struct mutex_s { u32 isLocked; }; +void mutex_lock(struct mutex_s *mutex); +void mutex_unlock(struct mutex_s *mutex); +void start_preempt(void); +void finish_preempt(void); +int wait_preempt(void); +void check_preempt(void); + +#endif // stacks.h
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/boot.c | 1 + src/bootsplash.c | 1 + src/fw/acpi.c | 1 + src/fw/coreboot.c | 1 + src/fw/mptable.c | 1 + src/fw/paravirt.c | 1 + src/fw/smbios.c | 1 + src/fw/smp.c | 1 + src/hw/floppy.c | 1 + src/hw/pci.c | 1 + src/hw/ps2port.c | 1 + src/hw/ramdisk.c | 1 + src/optionroms.c | 1 + src/romfile.c | 1 + src/romfile.h | 19 +++++++++++++++++++ src/util.h | 13 ------------- 16 files changed, 33 insertions(+), 13 deletions(-) create mode 100644 src/romfile.h
diff --git a/src/boot.c b/src/boot.c index 68a20d9..08876fa 100644 --- a/src/boot.c +++ b/src/boot.c @@ -16,6 +16,7 @@ #include "hw/usb.h" // struct usbdevice_s #include "fw/csm.h" // csm_bootprio_* #include "list.h" // hlist_node +#include "romfile.h" // romfile_loadint #include "string.h" // memset
diff --git a/src/bootsplash.c b/src/bootsplash.c index 340839b..493d60d 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -13,6 +13,7 @@ #include "vbe.h" // struct vbe_info #include "bmp.h" // bmp_alloc #include "fw/smbios.h" // display_uuid +#include "romfile.h" // romfile_loadfile #include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/fw/acpi.c b/src/fw/acpi.c index 8abd205..f94a6fb 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -15,6 +15,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "dev-q35.h" +#include "romfile.h" // romfile_loadint #include "string.h" // memset #include "x86.h" // readl
diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index c67a62b..ba65dc6 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -15,6 +15,7 @@ #include "acpi.h" // find_acpi_features #include "hw/pci.h" // pci_probe_devices #include "paravirt.h" // PlatformRunningOn +#include "romfile.h" // romfile_findprefix #include "stacks.h" // yield #include "string.h" // memset
diff --git a/src/fw/mptable.c b/src/fw/mptable.c index ecc618a..c79f54f 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -10,6 +10,7 @@ #include "mptable.h" // MPTABLE_SIGNATURE #include "hw/pci.h" #include "hw/pci_regs.h" +#include "romfile.h" // romfile_loadint #include "string.h" // memset #include "x86.h" // cpuid
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 2be4281..fd58184 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -20,6 +20,7 @@ #include "mptable.h" // mptable_setup #include "hw/pci.h" // create_pirtable #include "xen.h" // xen_biostable_setup +#include "romfile.h" // romfile_loadint #include "string.h" // memset #include "x86.h" // cpuid
diff --git a/src/fw/smbios.c b/src/fw/smbios.c index f80b42b..2f95d96 100644 --- a/src/fw/smbios.c +++ b/src/fw/smbios.c @@ -9,6 +9,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "smbios.h" // struct smbios_entry_point +#include "romfile.h" // romfile_findprefix #include "string.h" // memset #include "x86.h" // cpuid
diff --git a/src/fw/smp.c b/src/fw/smp.c index 1906255..cc6fb80 100644 --- a/src/fw/smp.c +++ b/src/fw/smp.c @@ -8,6 +8,7 @@ #include "util.h" // dprintf #include "config.h" // CONFIG_* #include "hw/cmos.h" // CMOS_BIOS_SMP_COUNT +#include "romfile.h" // romfile_loadint #include "stacks.h" // yield #include "x86.h" // wrmsr
diff --git a/src/hw/floppy.c b/src/hw/floppy.c index c051f54..c8ae756 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -16,6 +16,7 @@ #include "boot.h" // boot_add_floppy #include "pci.h" // pci_to_bdf #include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA +#include "romfile.h" // romfile_loadint #include "stacks.h" // yield #include "string.h" // memset
diff --git a/src/hw/pci.c b/src/hw/pci.c index 295a26d..f171d10 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -12,6 +12,7 @@ #include "farptr.h" // MAKE_FLATPTR #include "pci_regs.h" // PCI_VENDOR_ID #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA +#include "romfile.h" // romfile_loadint #include "stacks.h" // call32 #include "string.h" // memset #include "x86.h" // readl diff --git a/src/hw/ps2port.c b/src/hw/ps2port.c index 6fd0c3a..6da297f 100644 --- a/src/hw/ps2port.c +++ b/src/hw/ps2port.c @@ -10,6 +10,7 @@ #include "biosvar.h" // GET_LOW #include "ps2port.h" // ps2_kbd_command #include "pic.h" // pic_eoi1 +#include "romfile.h" // romfile_loadint #include "stacks.h" // yield
diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index cd517e7..3eadd74 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -10,6 +10,7 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "romfile.h" // romfile_findprefix #include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/optionroms.c b/src/optionroms.c index cc6083b..5c79121 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -14,6 +14,7 @@ #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "boot.h" // IPL #include "optionroms.h" // struct rom_header +#include "romfile.h" // romfile_loadint #include "stacks.h" // farcall16big #include "string.h" // memset
diff --git a/src/romfile.c b/src/romfile.c index f19f756..94e1ed5 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -6,6 +6,7 @@
#include "config.h" // CONFIG_* #include "util.h" // dprintf +#include "romfile.h" // struct romfile_s #include "string.h" // memcmp
static struct romfile_s *RomfileRoot VARVERIFY32INIT; diff --git a/src/romfile.h b/src/romfile.h new file mode 100644 index 0000000..c6d62a1 --- /dev/null +++ b/src/romfile.h @@ -0,0 +1,19 @@ +#ifndef __ROMFILE_H +#define __ROMFILE_H + +#include "types.h" // u32 + +// romfile.c +struct romfile_s { + struct romfile_s *next; + char name[128]; + u32 size; + int (*copy)(struct romfile_s *file, void *dest, u32 maxlen); +}; +void romfile_add(struct romfile_s *file); +struct romfile_s *romfile_findprefix(const char *prefix, struct romfile_s *prev); +struct romfile_s *romfile_find(const char *name); +void *romfile_loadfile(const char *name, int *psize); +u64 romfile_loadint(const char *name, u64 defval); + +#endif // romfile.h diff --git a/src/util.h b/src/util.h index 0492e39..a1a10f4 100644 --- a/src/util.h +++ b/src/util.h @@ -239,19 +239,6 @@ static inline void free(void *data) { // fw/mtrr.c void mtrr_setup(void);
-// romfile.c -struct romfile_s { - struct romfile_s *next; - char name[128]; - u32 size; - int (*copy)(struct romfile_s *file, void *dest, u32 maxlen); -}; -void romfile_add(struct romfile_s *file); -struct romfile_s *romfile_findprefix(const char *prefix, struct romfile_s *prev); -struct romfile_s *romfile_find(const char *name); -void *romfile_loadfile(const char *name, int *psize); -u64 romfile_loadint(const char *name, u64 defval); - // romlayout.S void reset_vector(void) __noreturn;
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 2 +- src/block.c | 1 + src/bmp.c | 2 +- src/boot.c | 1 + src/bootsplash.c | 1 + src/cdrom.c | 1 + src/fw/acpi.c | 1 + src/fw/biostables.c | 1 + src/fw/coreboot.c | 1 + src/fw/csm.c | 5 +- src/fw/mptable.c | 1 + src/fw/paravirt.c | 1 + src/fw/pciinit.c | 1 + src/fw/shadow.c | 1 + src/fw/smbios.c | 1 + src/fw/xen.c | 1 + src/hw/ahci.c | 1 + src/hw/ata.c | 1 + src/hw/esp-scsi.c | 1 + src/hw/floppy.c | 1 + src/hw/lsi-scsi.c | 1 + src/hw/megasas.c | 1 + src/hw/pci.c | 1 + src/hw/ramdisk.c | 1 + src/hw/usb-ehci.c | 1 + src/hw/usb-msc.c | 1 + src/hw/usb-ohci.c | 1 + src/hw/usb-uas.c | 1 + src/hw/usb-uhci.c | 1 + src/hw/usb.c | 1 + src/hw/virtio-blk.c | 1 + src/hw/virtio-pci.c | 1 + src/hw/virtio-scsi.c | 1 + src/jpeg.c | 2 +- src/malloc.c | 529 ++++++++++++++++++++++++++++++++++++++++++++++++ src/malloc.h | 70 +++++++ src/optionroms.c | 1 + src/output.c | 1 + src/pmm.c | 558 ++------------------------------------------------- src/post.c | 1 + src/romfile.c | 1 + src/stacks.c | 1 + src/system.c | 1 + src/util.h | 59 ------ 44 files changed, 658 insertions(+), 605 deletions(-) create mode 100644 src/malloc.c create mode 100644 src/malloc.h
diff --git a/Makefile b/Makefile index 3a88f45..fb1f81f 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ SRCBOTH=misc.c stacks.c output.c string.c x86.c block.c cdrom.c mouse.c kbd.c \ hw/virtio-ring.c hw/virtio-pci.c hw/virtio-blk.c hw/virtio-scsi.c \ hw/lsi-scsi.c hw/esp-scsi.c hw/megasas.c SRC16=$(SRCBOTH) system.c disk.c font.c -SRC32FLAT=$(SRCBOTH) post.c memmap.c pmm.c romfile.c optionroms.c \ +SRC32FLAT=$(SRCBOTH) post.c memmap.c malloc.c pmm.c romfile.c optionroms.c \ boot.c bootsplash.c jpeg.c bmp.c \ hw/usb-hub.c \ fw/coreboot.c fw/lzmadecode.c fw/csm.c fw/biostables.c \ diff --git a/src/block.c b/src/block.c index 9cfd7dd..5c8bf75 100644 --- a/src/block.c +++ b/src/block.c @@ -13,6 +13,7 @@ #include "hw/ahci.h" // process_ahci_op #include "hw/virtio-blk.h" // process_virtio_blk_op #include "hw/blockcmd.h" // cdb_* +#include "malloc.h" // malloc_low #include "stacks.h" // stack_hop #include "string.h" // checksum
diff --git a/src/bmp.c b/src/bmp.c index 81be306..68952f6 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -6,8 +6,8 @@ * * This work is licensed under the terms of the GNU LGPLv3. */ -#include "util.h" // malloc_tmphigh #include "bmp.h" // struct bmp_decdata +#include "malloc.h" // malloc_tmphigh #include "string.h" // memcpy
#define bmp_load4byte(addr) (*(u32 *)(addr)) diff --git a/src/boot.c b/src/boot.c index 08876fa..cb85325 100644 --- a/src/boot.c +++ b/src/boot.c @@ -16,6 +16,7 @@ #include "hw/usb.h" // struct usbdevice_s #include "fw/csm.h" // csm_bootprio_* #include "list.h" // hlist_node +#include "malloc.h" // free #include "romfile.h" // romfile_loadint #include "string.h" // memset
diff --git a/src/bootsplash.c b/src/bootsplash.c index 493d60d..1bea722 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -13,6 +13,7 @@ #include "vbe.h" // struct vbe_info #include "bmp.h" // bmp_alloc #include "fw/smbios.h" // display_uuid +#include "malloc.h" // free #include "romfile.h" // romfile_loadfile #include "stacks.h" // call16_int #include "string.h" // memset diff --git a/src/cdrom.c b/src/cdrom.c index 0d3fa1f..a9ac9e4 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -11,6 +11,7 @@ #include "biosvar.h" // GET_GLOBAL #include "hw/ata.h" // ATA_CMD_REQUEST_SENSE #include "hw/blockcmd.h" // CDB_CMD_REQUEST_SENSE +#include "malloc.h" // free #include "string.h" // memset
// Locks for removable devices diff --git a/src/fw/acpi.c b/src/fw/acpi.c index f94a6fb..8ad3673 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -15,6 +15,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "dev-q35.h" +#include "malloc.h" // free #include "romfile.h" // romfile_loadint #include "string.h" // memset #include "x86.h" // readl diff --git a/src/fw/biostables.c b/src/fw/biostables.c index cd58ff9..06cd864 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -8,6 +8,7 @@ #include "util.h" // dprintf #include "hw/pci.h" // struct pir_header #include "acpi.h" // struct rsdp_descriptor +#include "malloc.h" // malloc_fseg #include "mptable.h" // MPTABLE_SIGNATURE #include "smbios.h" // struct smbios_entry_point #include "string.h" // memcpy diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index ba65dc6..9971f82 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -14,6 +14,7 @@ #include "config.h" // CONFIG_* #include "acpi.h" // find_acpi_features #include "hw/pci.h" // pci_probe_devices +#include "malloc.h" // free #include "paravirt.h" // PlatformRunningOn #include "romfile.h" // romfile_findprefix #include "stacks.h" // yield diff --git a/src/fw/csm.c b/src/fw/csm.c index 81159b3..9e73a40 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -17,6 +17,7 @@ #include "boot.h" #include "smbios.h" #include "hw/pic.h" +#include "malloc.h" // csm_malloc_preinit #include "stacks.h" // wait_threads
struct rsdp_descriptor csm_rsdp VARFSEG __aligned(16); @@ -250,9 +251,9 @@ handle_csm_0006(struct bregs *regs) size, align, region);
if (region & 2) - chunk = pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align); + chunk = _malloc(&ZoneLow, MALLOC_DEFAULT_HANDLE, size, align); if (!chunk && (region & 1)) - chunk = pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, align); + chunk = _malloc(&ZoneFSeg, MALLOC_DEFAULT_HANDLE, size, align);
dprintf(3, "Legacy16GetTableAddress size %x align %x region %d yields %p\n", size, align, region, chunk); diff --git a/src/fw/mptable.c b/src/fw/mptable.c index c79f54f..4562a46 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -10,6 +10,7 @@ #include "mptable.h" // MPTABLE_SIGNATURE #include "hw/pci.h" #include "hw/pci_regs.h" +#include "malloc.h" // free #include "romfile.h" // romfile_loadint #include "string.h" // memset #include "x86.h" // cpuid diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index fd58184..ea2bbfb 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -20,6 +20,7 @@ #include "mptable.h" // mptable_setup #include "hw/pci.h" // create_pirtable #include "xen.h" // xen_biostable_setup +#include "malloc.h" // malloc_tmp #include "romfile.h" // romfile_loadint #include "string.h" // memset #include "x86.h" // cpuid diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index ee8d5dd..549c940 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -16,6 +16,7 @@ #include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR #include "list.h" // struct hlist_node #include "acpi.h" // acpi_pm1a_cnt +#include "malloc.h" // free #include "string.h" // memset
#define PCI_DEVICE_MEM_MIN 0x1000 diff --git a/src/fw/shadow.c b/src/fw/shadow.c index 45cfcaf..c470592 100644 --- a/src/fw/shadow.c +++ b/src/fw/shadow.c @@ -12,6 +12,7 @@ #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "paravirt.h" // runningOnXen #include "dev-q35.h" // PCI_VENDOR_ID_INTEL +#include "malloc.h" // rom_get_last #include "string.h" // memset #include "x86.h" // wbinvd
diff --git a/src/fw/smbios.c b/src/fw/smbios.c index 2f95d96..beb3143 100644 --- a/src/fw/smbios.c +++ b/src/fw/smbios.c @@ -9,6 +9,7 @@ #include "config.h" // CONFIG_* #include "paravirt.h" // RamSize #include "smbios.h" // struct smbios_entry_point +#include "malloc.h" // free #include "romfile.h" // romfile_findprefix #include "string.h" // memset #include "x86.h" // cpuid diff --git a/src/fw/xen.c b/src/fw/xen.c index f181e5f..8412330 100644 --- a/src/fw/xen.c +++ b/src/fw/xen.c @@ -11,6 +11,7 @@ #include "types.h" // ASM32FLAT #include "util.h" // copy_acpi_rsdp #include "acpi.h" // find_acpi_features +#include "malloc.h" // memalign_high #include "string.h" // memcpy #include "x86.h" // cpuid
diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 6f56cb1..b3530f9 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -16,6 +16,7 @@ #include "ata.h" // ATA_CB_STAT #include "ahci.h" // CDB_CMD_READ_10 #include "blockcmd.h" // CDB_CMD_READ_10 +#include "malloc.h" // free #include "stacks.h" // yield #include "string.h" // memset
diff --git a/src/hw/ata.c b/src/hw/ata.c index 5e9b905..b58ecc3 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -19,6 +19,7 @@ #include "disk.h" // struct ata_s #include "ata.h" // ATA_CB_STAT #include "blockcmd.h" // CDB_CMD_READ_10 +#include "malloc.h" // malloc_fseg #include "stacks.h" // yield #include "string.h" // memset
diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 49c74ff..0f55bb9 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -20,6 +20,7 @@ #include "blockcmd.h" // scsi_drive_setup #include "fw/paravirt.h" // runningOnQEMU #include "disk.h" +#include "malloc.h" // free #include "string.h" // memset
#define ESP_TCLO 0x00 diff --git a/src/hw/floppy.c b/src/hw/floppy.c index c8ae756..baae88b 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -14,6 +14,7 @@ #include "pic.h" // pic_eoi1 #include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "malloc.h" // malloc_fseg #include "pci.h" // pci_to_bdf #include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA #include "romfile.h" // romfile_loadint diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 0563fab..91ed198 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -20,6 +20,7 @@ #include "blockcmd.h" // scsi_drive_setup #include "fw/paravirt.h" // runningOnQEMU #include "disk.h" +#include "malloc.h" // free #include "string.h" // memset
#define LSI_REG_DSTAT 0x0c diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 19ed1b4..29143eb 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -19,6 +19,7 @@ #include "boot.h" // bootprio_find_scsi_device #include "blockcmd.h" // scsi_drive_setup #include "disk.h" +#include "malloc.h" // free #include "stacks.h" // yield #include "string.h" // memset
diff --git a/src/hw/pci.c b/src/hw/pci.c index f171d10..9c287ee 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -10,6 +10,7 @@ #include "ioport.h" // outl #include "util.h" // dprintf #include "farptr.h" // MAKE_FLATPTR +#include "malloc.h" // malloc_tmp #include "pci_regs.h" // PCI_VENDOR_ID #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "romfile.h" // romfile_loadint diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 3eadd74..a50e7c0 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -10,6 +10,7 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "malloc.h" // malloc_fseg #include "romfile.h" // romfile_findprefix #include "stacks.h" // call16_int #include "string.h" // memset diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index bb02293..6786fd3 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -15,6 +15,7 @@ #include "biosvar.h" // GET_LOWFLAT #include "usb-uhci.h" // uhci_setup #include "usb-ohci.h" // ohci_setup +#include "malloc.h" // free #include "string.h" // memset #include "x86.h" // readl
diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index d5cf1b4..f592726 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -12,6 +12,7 @@ #include "blockcmd.h" // cdb_read #include "disk.h" // DTYPE_USB #include "boot.h" // bootprio_find_usb +#include "malloc.h" // free #include "string.h" // memset
struct usbdrive_s { diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index 0febcca..c96c1d7 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -11,6 +11,7 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT +#include "malloc.h" // free #include "string.h" // memset #include "x86.h" // readl
diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index c205d7f..ab9a050 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -22,6 +22,7 @@ #include "disk.h" // DTYPE_UAS #include "boot.h" // bootprio_find_usb #include "usb-uas.h" // usb_uas_init +#include "malloc.h" // free #include "string.h" // memset
#define UAS_UI_COMMAND 0x01 diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index 4716d98..2587a56 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -12,6 +12,7 @@ #include "pci_regs.h" // PCI_BASE_ADDRESS_4 #include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT +#include "malloc.h" // free #include "string.h" // memset
struct usb_uhci_s { diff --git a/src/hw/usb.c b/src/hw/usb.c index 4026555..5216cce 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -18,6 +18,7 @@ #include "usb-uas.h" // usb_uas_setup #include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL +#include "malloc.h" // free #include "string.h" // memset #include "x86.h" // __fls
diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 761e64f..6b628f3 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -18,6 +18,7 @@ #include "virtio-ring.h" #include "virtio-blk.h" #include "disk.h" +#include "malloc.h" // free #include "string.h" // memset
struct virtiodrive_s { diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index 6a16463..07177ac 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -19,6 +19,7 @@ #include "virtio-pci.h" #include "config.h" // CONFIG_DEBUG_LEVEL #include "util.h" // dprintf +#include "malloc.h" // free #include "pci.h" // pci_config_readl #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 06f7b60..8c9c670 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -19,6 +19,7 @@ #include "virtio-ring.h" #include "virtio-scsi.h" #include "disk.h" +#include "malloc.h" // free #include "string.h" // memset
struct virtio_lun_s { diff --git a/src/jpeg.c b/src/jpeg.c index e7fc337..925aa3d 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -40,7 +40,7 @@ */
#define __LITTLE_ENDIAN -#include "util.h" +#include "malloc.h" #include "jpeg.h" #include "string.h" #define ISHIFT 11 diff --git a/src/malloc.c b/src/malloc.c new file mode 100644 index 0000000..f4783af --- /dev/null +++ b/src/malloc.c @@ -0,0 +1,529 @@ +// Post memory manager (PMM) calls +// +// Copyright (C) 2009 Kevin O'Connor kevin@koconnor.net +// +// This file may be distributed under the terms of the GNU LGPLv3 license. + +#include "util.h" // dprintf +#include "config.h" // BUILD_BIOS_ADDR +#include "memmap.h" // struct e820entry +#include "biosvar.h" // GET_BDA +#include "optionroms.h" // OPTION_ROM_ALIGN +#include "list.h" // hlist_node +#include "malloc.h" // _malloc +#include "stacks.h" // wait_preempt +#include "string.h" // memset + +// Information on a reserved area. +struct allocinfo_s { + struct hlist_node node; + void *data, *dataend, *allocend; +}; + +// Information on a tracked memory allocation. +struct allocdetail_s { + struct allocinfo_s detailinfo; + struct allocinfo_s datainfo; + u32 handle; +}; + +// The various memory zones. +struct zone_s { + struct hlist_head head; +}; + +struct zone_s ZoneLow VARVERIFY32INIT, ZoneHigh VARVERIFY32INIT; +struct zone_s ZoneFSeg VARVERIFY32INIT; +struct zone_s ZoneTmpLow VARVERIFY32INIT, ZoneTmpHigh VARVERIFY32INIT; + +static struct zone_s *Zones[] VARVERIFY32INIT = { + &ZoneTmpLow, &ZoneLow, &ZoneFSeg, &ZoneTmpHigh, &ZoneHigh +}; + + +/**************************************************************** + * low-level memory reservations + ****************************************************************/ + +// Find and reserve space from a given zone +static void * +allocSpace(struct zone_s *zone, u32 size, u32 align, struct allocinfo_s *fill) +{ + struct allocinfo_s *info; + hlist_for_each_entry(info, &zone->head, node) { + void *dataend = info->dataend; + void *allocend = info->allocend; + void *newallocend = (void*)ALIGN_DOWN((u32)allocend - size, align); + if (newallocend >= dataend && newallocend <= allocend) { + // Found space - now reserve it. + if (!fill) + fill = newallocend; + fill->data = newallocend; + fill->dataend = newallocend + size; + fill->allocend = allocend; + + info->allocend = newallocend; + hlist_add_before(&fill->node, &info->node); + return newallocend; + } + } + return NULL; +} + +// Release space allocated with allocSpace() +static void +freeSpace(struct allocinfo_s *info) +{ + struct allocinfo_s *next = container_of_or_null( + info->node.next, struct allocinfo_s, node); + if (next && next->allocend == info->data) + next->allocend = info->allocend; + hlist_del(&info->node); +} + +// Add new memory to a zone +static void +addSpace(struct zone_s *zone, void *start, void *end) +{ + // Find position to add space + struct allocinfo_s *info; + struct hlist_node **pprev; + hlist_for_each_entry_pprev(info, pprev, &zone->head, node) { + if (info->data < start) + break; + } + + // Add space using temporary allocation info. + struct allocdetail_s tempdetail; + tempdetail.datainfo.data = tempdetail.datainfo.dataend = start; + tempdetail.datainfo.allocend = end; + hlist_add(&tempdetail.datainfo.node, pprev); + + // Allocate final allocation info. + struct allocdetail_s *detail = allocSpace( + &ZoneTmpHigh, sizeof(*detail), MALLOC_MIN_ALIGN, NULL); + if (!detail) { + detail = allocSpace(&ZoneTmpLow, sizeof(*detail) + , MALLOC_MIN_ALIGN, NULL); + if (!detail) { + hlist_del(&tempdetail.datainfo.node); + warn_noalloc(); + return; + } + } + + // Replace temp alloc space with final alloc space + pprev = tempdetail.datainfo.node.pprev; + hlist_del(&tempdetail.datainfo.node); + memcpy(&detail->datainfo, &tempdetail.datainfo, sizeof(detail->datainfo)); + detail->handle = MALLOC_DEFAULT_HANDLE; + hlist_add(&detail->datainfo.node, pprev); +} + +// Search all zones for an allocation obtained from allocSpace() +static struct allocinfo_s * +findAlloc(void *data) +{ + int i; + for (i=0; i<ARRAY_SIZE(Zones); i++) { + struct allocinfo_s *info; + hlist_for_each_entry(info, &Zones[i]->head, node) { + if (info->data == data) + return info; + } + } + return NULL; +} + +// Return the last sentinal node of a zone +static struct allocinfo_s * +findLast(struct zone_s *zone) +{ + struct allocinfo_s *info, *last = NULL; + hlist_for_each_entry(info, &zone->head, node) { + last = info; + } + return last; +} + + +/**************************************************************** + * ebda movement + ****************************************************************/ + +// Move ebda +static int +relocate_ebda(u32 newebda, u32 oldebda, u8 ebda_size) +{ + u32 lowram = GET_BDA(mem_size_kb) * 1024; + if (oldebda != lowram) + // EBDA isn't at end of ram - give up. + return -1; + + // Do copy + memmove((void*)newebda, (void*)oldebda, ebda_size * 1024); + + // Update indexes + dprintf(1, "ebda moved from %x to %x\n", oldebda, newebda); + SET_BDA(mem_size_kb, newebda / 1024); + SET_BDA(ebda_seg, FLATPTR_TO_SEG(newebda)); + return 0; +} + +// Support expanding the ZoneLow dynamically. +static void * +zonelow_expand(u32 size, u32 align, struct allocinfo_s *fill) +{ + // Make sure to not move ebda while an optionrom is running. + if (unlikely(wait_preempt())) { + void *data = allocSpace(&ZoneLow, size, align, fill); + if (data) + return data; + } + + struct allocinfo_s *info = findLast(&ZoneLow); + if (!info) + return NULL; + u32 oldpos = (u32)info->allocend; + u32 newpos = ALIGN_DOWN(oldpos - size, align); + u32 bottom = (u32)info->dataend; + if (newpos >= bottom && newpos <= oldpos) + // Space already present. + return allocSpace(&ZoneLow, size, align, fill); + u16 ebda_seg = get_ebda_seg(); + u32 ebda_pos = (u32)MAKE_FLATPTR(ebda_seg, 0); + u8 ebda_size = GET_EBDA(ebda_seg, size); + u32 ebda_end = ebda_pos + ebda_size * 1024; + if (ebda_end != bottom) + // Something else is after ebda - can't use any existing space. + newpos = ALIGN_DOWN(ebda_end - size, align); + u32 newbottom = ALIGN_DOWN(newpos, 1024); + u32 newebda = ALIGN_DOWN(newbottom - ebda_size * 1024, 1024); + if (newebda < BUILD_EBDA_MINIMUM) + // Not enough space. + return NULL; + + // Move ebda + int ret = relocate_ebda(newebda, ebda_pos, ebda_size); + if (ret) + return NULL; + + // Update zone + if (ebda_end == bottom) { + info->data = (void*)newbottom; + info->dataend = (void*)newbottom; + } else + addSpace(&ZoneLow, (void*)newbottom, (void*)ebda_end); + + return allocSpace(&ZoneLow, size, align, fill); +} + + +/**************************************************************** + * tracked memory allocations + ****************************************************************/ + +// Allocate memory from the given zone and track it as a PMM allocation +void * __malloc +_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align) +{ + ASSERT32FLAT(); + if (!size) + return NULL; + + // Find and reserve space for bookkeeping. + struct allocdetail_s *detail = allocSpace( + &ZoneTmpHigh, sizeof(*detail), MALLOC_MIN_ALIGN, NULL); + if (!detail) { + detail = allocSpace(&ZoneTmpLow, sizeof(*detail) + , MALLOC_MIN_ALIGN, NULL); + if (!detail) + return NULL; + } + + // Find and reserve space for main allocation + void *data = allocSpace(zone, size, align, &detail->datainfo); + if (!CONFIG_MALLOC_UPPERMEMORY && !data && zone == &ZoneLow) + data = zonelow_expand(size, align, &detail->datainfo); + if (!data) { + freeSpace(&detail->detailinfo); + return NULL; + } + + dprintf(8, "_malloc zone=%p handle=%x size=%d align=%x ret=%p (detail=%p)\n" + , zone, handle, size, align, data, detail); + detail->handle = handle; + + return data; +} + +// Free a data block allocated with _malloc +int +_free(void *data) +{ + ASSERT32FLAT(); + struct allocinfo_s *info = findAlloc(data); + if (!info || data == (void*)info || data == info->dataend) + return -1; + struct allocdetail_s *detail = container_of( + info, struct allocdetail_s, datainfo); + dprintf(8, "_free %p (detail=%p)\n", data, detail); + freeSpace(info); + freeSpace(&detail->detailinfo); + return 0; +} + +// Find the amount of free space in a given zone. +u32 +malloc_getspace(struct zone_s *zone) +{ + // XXX - doesn't account for ZoneLow being able to grow. + // XXX - results not reliable when CONFIG_THREAD_OPTIONROMS + u32 maxspace = 0; + struct allocinfo_s *info; + hlist_for_each_entry(info, &zone->head, node) { + u32 space = info->allocend - info->dataend; + if (space > maxspace) + maxspace = space; + } + + if (zone != &ZoneTmpHigh && zone != &ZoneTmpLow) + return maxspace; + // Account for space needed for PMM tracking. + u32 reserve = ALIGN(sizeof(struct allocdetail_s), MALLOC_MIN_ALIGN); + if (maxspace <= reserve) + return 0; + return maxspace - reserve; +} + +// Find the data block allocated with _malloc with a given handle. +void * +malloc_find(u32 handle) +{ + int i; + for (i=0; i<ARRAY_SIZE(Zones); i++) { + struct allocinfo_s *info; + hlist_for_each_entry(info, &Zones[i]->head, node) { + if (info->data != (void*)info) + continue; + struct allocdetail_s *detail = container_of( + info, struct allocdetail_s, detailinfo); + if (detail->handle == handle) + return detail->datainfo.data; + } + } + return NULL; +} + + +/**************************************************************** + * 0xc0000-0xf0000 management + ****************************************************************/ + +static u32 RomEnd = BUILD_ROM_START; +static struct allocinfo_s *RomBase; + +#define OPROM_HEADER_RESERVE 16 + +// Return the maximum memory position option roms may use. +u32 +rom_get_max(void) +{ + if (CONFIG_MALLOC_UPPERMEMORY) + return ALIGN_DOWN((u32)RomBase->allocend - OPROM_HEADER_RESERVE + , OPTION_ROM_ALIGN); + extern u8 code32init_end[]; + u32 end = (u32)code32init_end; + return end > BUILD_BIOS_ADDR ? BUILD_BIOS_ADDR : end; +} + +// Return the end of the last deployed option rom. +u32 +rom_get_last(void) +{ + return RomEnd; +} + +// Request space for an optionrom in 0xc0000-0xf0000 area. +struct rom_header * +rom_reserve(u32 size) +{ + u32 newend = ALIGN(RomEnd + size, OPTION_ROM_ALIGN); + if (newend > rom_get_max()) + return NULL; + if (CONFIG_MALLOC_UPPERMEMORY) { + if (newend < (u32)zonelow_base) + newend = (u32)zonelow_base; + RomBase->data = RomBase->dataend = (void*)newend + OPROM_HEADER_RESERVE; + } + return (void*)RomEnd; +} + +// Confirm space as in use by an optionrom. +int +rom_confirm(u32 size) +{ + void *new = rom_reserve(size); + if (!new) { + warn_noalloc(); + return -1; + } + RomEnd = ALIGN(RomEnd + size, OPTION_ROM_ALIGN); + return 0; +} + + +/**************************************************************** + * Setup + ****************************************************************/ + +void +malloc_preinit(void) +{ + ASSERT32FLAT(); + dprintf(3, "malloc preinit\n"); + + // Don't declare any memory between 0xa0000 and 0x100000 + add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE); + + // Mark known areas as reserved. + add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED); + + // Populate temp high ram + u32 highram = 0; + int i; + for (i=e820_count-1; i>=0; i--) { + struct e820entry *en = &e820_list[i]; + u64 end = en->start + en->size; + if (end < 1024*1024) + break; + if (en->type != E820_RAM || end > 0xffffffff) + continue; + u32 s = en->start, e = end; + if (!highram) { + u32 newe = ALIGN_DOWN(e - BUILD_MAX_HIGHTABLE, MALLOC_MIN_ALIGN); + if (newe <= e && newe >= s) { + highram = newe; + e = newe; + } + } + addSpace(&ZoneTmpHigh, (void*)s, (void*)e); + } + + // Populate regions + addSpace(&ZoneTmpLow, (void*)BUILD_STACK_ADDR, (void*)BUILD_EBDA_MINIMUM); + if (highram) { + addSpace(&ZoneHigh, (void*)highram + , (void*)highram + BUILD_MAX_HIGHTABLE); + add_e820(highram, BUILD_MAX_HIGHTABLE, E820_RESERVED); + } +} + +void +csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm, u32 hi_pmm_size) +{ + ASSERT32FLAT(); + + if (hi_pmm_size > BUILD_MAX_HIGHTABLE) { + void *hi_pmm_end = (void *)hi_pmm + hi_pmm_size; + addSpace(&ZoneTmpHigh, (void *)hi_pmm, hi_pmm_end - BUILD_MAX_HIGHTABLE); + addSpace(&ZoneHigh, hi_pmm_end - BUILD_MAX_HIGHTABLE, hi_pmm_end); + } else { + addSpace(&ZoneTmpHigh, (void *)hi_pmm, (void *)hi_pmm + hi_pmm_size); + } + addSpace(&ZoneTmpLow, (void *)low_pmm, (void *)low_pmm + low_pmm_size); +} + +u32 LegacyRamSize VARFSEG; + +// Calculate the maximum ramsize (less than 4gig) from e820 map. +static void +calcRamSize(void) +{ + u32 rs = 0; + int i; + for (i=e820_count-1; i>=0; i--) { + struct e820entry *en = &e820_list[i]; + u64 end = en->start + en->size; + u32 type = en->type; + if (end <= 0xffffffff && (type == E820_ACPI || type == E820_RAM)) { + rs = end; + break; + } + } + LegacyRamSize = rs >= 1024*1024 ? rs : 1024*1024; +} + +// Update pointers after code relocation. +void +malloc_init(void) +{ + ASSERT32FLAT(); + dprintf(3, "malloc init\n"); + + if (CONFIG_RELOCATE_INIT) { + // Fixup malloc pointers after relocation + int i; + for (i=0; i<ARRAY_SIZE(Zones); i++) { + struct zone_s *zone = Zones[i]; + if (zone->head.first) + zone->head.first->pprev = &zone->head.first; + } + } + + // Initialize low-memory region + extern u8 varlow_start[], varlow_end[], final_varlow_start[]; + memmove(final_varlow_start, varlow_start, varlow_end - varlow_start); + if (CONFIG_MALLOC_UPPERMEMORY) { + addSpace(&ZoneLow, zonelow_base + OPROM_HEADER_RESERVE + , final_varlow_start); + RomBase = findLast(&ZoneLow); + } else { + addSpace(&ZoneLow, (void*)ALIGN_DOWN((u32)final_varlow_start, 1024) + , final_varlow_start); + } + + // Add space available in f-segment to ZoneFSeg + extern u8 zonefseg_start[], zonefseg_end[]; + memset(zonefseg_start, 0, zonefseg_end - zonefseg_start); + addSpace(&ZoneFSeg, zonefseg_start, zonefseg_end); + + calcRamSize(); +} + +void +malloc_prepboot(void) +{ + ASSERT32FLAT(); + dprintf(3, "malloc finalize\n"); + + u32 base = rom_get_max(); + memset((void*)RomEnd, 0, base-RomEnd); + if (CONFIG_MALLOC_UPPERMEMORY) { + // Place an optionrom signature around used low mem area. + struct rom_header *dummyrom = (void*)base; + dummyrom->signature = OPTION_ROM_SIGNATURE; + int size = (BUILD_BIOS_ADDR - base) / 512; + dummyrom->size = (size > 255) ? 255 : size; + } + + // Reserve more low-mem if needed. + u32 endlow = GET_BDA(mem_size_kb)*1024; + add_e820(endlow, BUILD_LOWRAM_END-endlow, E820_RESERVED); + + // Clear unused f-seg ram. + struct allocinfo_s *info = findLast(&ZoneFSeg); + memset(info->dataend, 0, info->allocend - info->dataend); + dprintf(1, "Space available for UMB: %x-%x, %x-%x\n" + , RomEnd, base, (u32)info->dataend, (u32)info->allocend); + + // Give back unused high ram. + info = findLast(&ZoneHigh); + if (info) { + u32 giveback = ALIGN_DOWN(info->allocend - info->dataend, PAGE_SIZE); + add_e820((u32)info->dataend, giveback, E820_RAM); + dprintf(1, "Returned %d bytes of ZoneHigh\n", giveback); + } + + calcRamSize(); +} diff --git a/src/malloc.h b/src/malloc.h new file mode 100644 index 0000000..af8a21d --- /dev/null +++ b/src/malloc.h @@ -0,0 +1,70 @@ +#ifndef __MALLOC_H +#define __MALLOC_H + +#include "types.h" // u32 + +// malloc.c +extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh; +u32 rom_get_max(void); +u32 rom_get_last(void); +struct rom_header *rom_reserve(u32 size); +int rom_confirm(u32 size); +void csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm, + u32 hi_pmm_size); +void malloc_preinit(void); +extern u32 LegacyRamSize; +void malloc_init(void); +void malloc_prepboot(void); +void *_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align); +int _free(void *data); +u32 malloc_getspace(struct zone_s *zone); +void *malloc_find(u32 handle); + +#define MALLOC_DEFAULT_HANDLE 0xFFFFFFFF +// Minimum alignment of malloc'd memory +#define MALLOC_MIN_ALIGN 16 +// Helper functions for memory allocation. +static inline void *malloc_low(u32 size) { + return _malloc(&ZoneLow, MALLOC_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); +} +static inline void *malloc_high(u32 size) { + return _malloc(&ZoneHigh, MALLOC_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); +} +static inline void *malloc_fseg(u32 size) { + return _malloc(&ZoneFSeg, MALLOC_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); +} +static inline void *malloc_tmplow(u32 size) { + return _malloc(&ZoneTmpLow, MALLOC_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); +} +static inline void *malloc_tmphigh(u32 size) { + return _malloc(&ZoneTmpHigh, MALLOC_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); +} +static inline void *malloc_tmp(u32 size) { + void *ret = malloc_tmphigh(size); + if (ret) + return ret; + return malloc_tmplow(size); +} +static inline void *memalign_low(u32 align, u32 size) { + return _malloc(&ZoneLow, MALLOC_DEFAULT_HANDLE, size, align); +} +static inline void *memalign_high(u32 align, u32 size) { + return _malloc(&ZoneHigh, MALLOC_DEFAULT_HANDLE, size, align); +} +static inline void *memalign_tmplow(u32 align, u32 size) { + return _malloc(&ZoneTmpLow, MALLOC_DEFAULT_HANDLE, size, align); +} +static inline void *memalign_tmphigh(u32 align, u32 size) { + return _malloc(&ZoneTmpHigh, MALLOC_DEFAULT_HANDLE, size, align); +} +static inline void *memalign_tmp(u32 align, u32 size) { + void *ret = memalign_tmphigh(align, size); + if (ret) + return ret; + return memalign_tmplow(align, size); +} +static inline void free(void *data) { + _free(data); +} + +#endif // malloc.h diff --git a/src/optionroms.c b/src/optionroms.c index 5c79121..560df81 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -13,6 +13,7 @@ #include "hw/pci_regs.h" // PCI_ROM_ADDRESS #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "boot.h" // IPL +#include "malloc.h" // rom_confirm #include "optionroms.h" // struct rom_header #include "romfile.h" // romfile_loadint #include "stacks.h" // farcall16big diff --git a/src/output.c b/src/output.c index b5d7ae0..e69a09a 100644 --- a/src/output.c +++ b/src/output.c @@ -12,6 +12,7 @@ #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL #include "fw/paravirt.h" // PlatformRunningOn +#include "malloc.h" // malloc_tmp #include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/pmm.c b/src/pmm.c index cd6ee89..f6319a4 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -1,541 +1,17 @@ // Post memory manager (PMM) calls // -// Copyright (C) 2009 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.
+#include "biosvar.h" // FUNC16 +#include "config.h" // CONFIG_* +#include "farptr.h" // struct segoff_s +#include "malloc.h" // _malloc +#include "string.h" // checksum #include "util.h" // dprintf -#include "config.h" // BUILD_BIOS_ADDR -#include "memmap.h" // struct e820entry -#include "farptr.h" // GET_FARVAR -#include "biosvar.h" // GET_BDA -#include "optionroms.h" // OPTION_ROM_ALIGN -#include "list.h" // hlist_node -#include "stacks.h" // wait_preempt -#include "string.h" // memset #include "x86.h" // __ffs
-// Information on a reserved area. -struct allocinfo_s { - struct hlist_node node; - void *data, *dataend, *allocend; -}; - -// Information on a tracked memory allocation. -struct allocdetail_s { - struct allocinfo_s detailinfo; - struct allocinfo_s datainfo; - u32 handle; -}; - -// The various memory zones. -struct zone_s { - struct hlist_head head; -}; - -struct zone_s ZoneLow VARVERIFY32INIT, ZoneHigh VARVERIFY32INIT; -struct zone_s ZoneFSeg VARVERIFY32INIT; -struct zone_s ZoneTmpLow VARVERIFY32INIT, ZoneTmpHigh VARVERIFY32INIT; - -static struct zone_s *Zones[] VARVERIFY32INIT = { - &ZoneTmpLow, &ZoneLow, &ZoneFSeg, &ZoneTmpHigh, &ZoneHigh -}; - - -/**************************************************************** - * low-level memory reservations - ****************************************************************/ - -// Find and reserve space from a given zone -static void * -allocSpace(struct zone_s *zone, u32 size, u32 align, struct allocinfo_s *fill) -{ - struct allocinfo_s *info; - hlist_for_each_entry(info, &zone->head, node) { - void *dataend = info->dataend; - void *allocend = info->allocend; - void *newallocend = (void*)ALIGN_DOWN((u32)allocend - size, align); - if (newallocend >= dataend && newallocend <= allocend) { - // Found space - now reserve it. - if (!fill) - fill = newallocend; - fill->data = newallocend; - fill->dataend = newallocend + size; - fill->allocend = allocend; - - info->allocend = newallocend; - hlist_add_before(&fill->node, &info->node); - return newallocend; - } - } - return NULL; -} - -// Release space allocated with allocSpace() -static void -freeSpace(struct allocinfo_s *info) -{ - struct allocinfo_s *next = container_of_or_null( - info->node.next, struct allocinfo_s, node); - if (next && next->allocend == info->data) - next->allocend = info->allocend; - hlist_del(&info->node); -} - -// Add new memory to a zone -static void -addSpace(struct zone_s *zone, void *start, void *end) -{ - // Find position to add space - struct allocinfo_s *info; - struct hlist_node **pprev; - hlist_for_each_entry_pprev(info, pprev, &zone->head, node) { - if (info->data < start) - break; - } - - // Add space using temporary allocation info. - struct allocdetail_s tempdetail; - tempdetail.datainfo.data = tempdetail.datainfo.dataend = start; - tempdetail.datainfo.allocend = end; - hlist_add(&tempdetail.datainfo.node, pprev); - - // Allocate final allocation info. - struct allocdetail_s *detail = allocSpace( - &ZoneTmpHigh, sizeof(*detail), MALLOC_MIN_ALIGN, NULL); - if (!detail) { - detail = allocSpace(&ZoneTmpLow, sizeof(*detail) - , MALLOC_MIN_ALIGN, NULL); - if (!detail) { - hlist_del(&tempdetail.datainfo.node); - warn_noalloc(); - return; - } - } - - // Replace temp alloc space with final alloc space - pprev = tempdetail.datainfo.node.pprev; - hlist_del(&tempdetail.datainfo.node); - memcpy(&detail->datainfo, &tempdetail.datainfo, sizeof(detail->datainfo)); - detail->handle = PMM_DEFAULT_HANDLE; - hlist_add(&detail->datainfo.node, pprev); -} - -// Search all zones for an allocation obtained from allocSpace() -static struct allocinfo_s * -findAlloc(void *data) -{ - int i; - for (i=0; i<ARRAY_SIZE(Zones); i++) { - struct allocinfo_s *info; - hlist_for_each_entry(info, &Zones[i]->head, node) { - if (info->data == data) - return info; - } - } - return NULL; -} - -// Return the last sentinal node of a zone -static struct allocinfo_s * -findLast(struct zone_s *zone) -{ - struct allocinfo_s *info, *last = NULL; - hlist_for_each_entry(info, &zone->head, node) { - last = info; - } - return last; -} - - -/**************************************************************** - * ebda movement - ****************************************************************/ - -// Move ebda -static int -relocate_ebda(u32 newebda, u32 oldebda, u8 ebda_size) -{ - u32 lowram = GET_BDA(mem_size_kb) * 1024; - if (oldebda != lowram) - // EBDA isn't at end of ram - give up. - return -1; - - // Do copy - memmove((void*)newebda, (void*)oldebda, ebda_size * 1024); - - // Update indexes - dprintf(1, "ebda moved from %x to %x\n", oldebda, newebda); - SET_BDA(mem_size_kb, newebda / 1024); - SET_BDA(ebda_seg, FLATPTR_TO_SEG(newebda)); - return 0; -} - -// Support expanding the ZoneLow dynamically. -static void * -zonelow_expand(u32 size, u32 align, struct allocinfo_s *fill) -{ - // Make sure to not move ebda while an optionrom is running. - if (unlikely(wait_preempt())) { - void *data = allocSpace(&ZoneLow, size, align, fill); - if (data) - return data; - } - - struct allocinfo_s *info = findLast(&ZoneLow); - if (!info) - return NULL; - u32 oldpos = (u32)info->allocend; - u32 newpos = ALIGN_DOWN(oldpos - size, align); - u32 bottom = (u32)info->dataend; - if (newpos >= bottom && newpos <= oldpos) - // Space already present. - return allocSpace(&ZoneLow, size, align, fill); - u16 ebda_seg = get_ebda_seg(); - u32 ebda_pos = (u32)MAKE_FLATPTR(ebda_seg, 0); - u8 ebda_size = GET_EBDA(ebda_seg, size); - u32 ebda_end = ebda_pos + ebda_size * 1024; - if (ebda_end != bottom) - // Something else is after ebda - can't use any existing space. - newpos = ALIGN_DOWN(ebda_end - size, align); - u32 newbottom = ALIGN_DOWN(newpos, 1024); - u32 newebda = ALIGN_DOWN(newbottom - ebda_size * 1024, 1024); - if (newebda < BUILD_EBDA_MINIMUM) - // Not enough space. - return NULL; - - // Move ebda - int ret = relocate_ebda(newebda, ebda_pos, ebda_size); - if (ret) - return NULL; - - // Update zone - if (ebda_end == bottom) { - info->data = (void*)newbottom; - info->dataend = (void*)newbottom; - } else - addSpace(&ZoneLow, (void*)newbottom, (void*)ebda_end); - - return allocSpace(&ZoneLow, size, align, fill); -} - - -/**************************************************************** - * tracked memory allocations - ****************************************************************/ - -// Allocate memory from the given zone and track it as a PMM allocation -void * __malloc -pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align) -{ - ASSERT32FLAT(); - if (!size) - return NULL; - - // Find and reserve space for bookkeeping. - struct allocdetail_s *detail = allocSpace( - &ZoneTmpHigh, sizeof(*detail), MALLOC_MIN_ALIGN, NULL); - if (!detail) { - detail = allocSpace(&ZoneTmpLow, sizeof(*detail) - , MALLOC_MIN_ALIGN, NULL); - if (!detail) - return NULL; - } - - // Find and reserve space for main allocation - void *data = allocSpace(zone, size, align, &detail->datainfo); - if (!CONFIG_MALLOC_UPPERMEMORY && !data && zone == &ZoneLow) - data = zonelow_expand(size, align, &detail->datainfo); - if (!data) { - freeSpace(&detail->detailinfo); - return NULL; - } - - dprintf(8, "pmm_malloc zone=%p handle=%x size=%d align=%x" - " ret=%p (detail=%p)\n" - , zone, handle, size, align - , data, detail); - detail->handle = handle; - - return data; -} - -// Free a data block allocated with pmm_malloc -int -pmm_free(void *data) -{ - ASSERT32FLAT(); - struct allocinfo_s *info = findAlloc(data); - if (!info || data == (void*)info || data == info->dataend) - return -1; - struct allocdetail_s *detail = container_of( - info, struct allocdetail_s, datainfo); - dprintf(8, "pmm_free %p (detail=%p)\n", data, detail); - freeSpace(info); - freeSpace(&detail->detailinfo); - return 0; -} - -// Find the amount of free space in a given zone. -static u32 -pmm_getspace(struct zone_s *zone) -{ - // XXX - doesn't account for ZoneLow being able to grow. - // XXX - results not reliable when CONFIG_THREAD_OPTIONROMS - u32 maxspace = 0; - struct allocinfo_s *info; - hlist_for_each_entry(info, &zone->head, node) { - u32 space = info->allocend - info->dataend; - if (space > maxspace) - maxspace = space; - } - - if (zone != &ZoneTmpHigh && zone != &ZoneTmpLow) - return maxspace; - // Account for space needed for PMM tracking. - u32 reserve = ALIGN(sizeof(struct allocdetail_s), MALLOC_MIN_ALIGN); - if (maxspace <= reserve) - return 0; - return maxspace - reserve; -} - -// Find the data block allocated with pmm_malloc with a given handle. -static void * -pmm_find(u32 handle) -{ - int i; - for (i=0; i<ARRAY_SIZE(Zones); i++) { - struct allocinfo_s *info; - hlist_for_each_entry(info, &Zones[i]->head, node) { - if (info->data != (void*)info) - continue; - struct allocdetail_s *detail = container_of( - info, struct allocdetail_s, detailinfo); - if (detail->handle == handle) - return detail->datainfo.data; - } - } - return NULL; -} - - -/**************************************************************** - * 0xc0000-0xf0000 management - ****************************************************************/ - -static u32 RomEnd = BUILD_ROM_START; -static struct allocinfo_s *RomBase; - -#define OPROM_HEADER_RESERVE 16 - -// Return the maximum memory position option roms may use. -u32 -rom_get_max(void) -{ - if (CONFIG_MALLOC_UPPERMEMORY) - return ALIGN_DOWN((u32)RomBase->allocend - OPROM_HEADER_RESERVE - , OPTION_ROM_ALIGN); - extern u8 code32init_end[]; - u32 end = (u32)code32init_end; - return end > BUILD_BIOS_ADDR ? BUILD_BIOS_ADDR : end; -} - -// Return the end of the last deployed option rom. -u32 -rom_get_last(void) -{ - return RomEnd; -} - -// Request space for an optionrom in 0xc0000-0xf0000 area. -struct rom_header * -rom_reserve(u32 size) -{ - u32 newend = ALIGN(RomEnd + size, OPTION_ROM_ALIGN); - if (newend > rom_get_max()) - return NULL; - if (CONFIG_MALLOC_UPPERMEMORY) { - if (newend < (u32)zonelow_base) - newend = (u32)zonelow_base; - RomBase->data = RomBase->dataend = (void*)newend + OPROM_HEADER_RESERVE; - } - return (void*)RomEnd; -} - -// Confirm space as in use by an optionrom. -int -rom_confirm(u32 size) -{ - void *new = rom_reserve(size); - if (!new) { - warn_noalloc(); - return -1; - } - RomEnd = ALIGN(RomEnd + size, OPTION_ROM_ALIGN); - return 0; -} - - -/**************************************************************** - * Setup - ****************************************************************/ - -void -malloc_preinit(void) -{ - ASSERT32FLAT(); - dprintf(3, "malloc preinit\n"); - - // Don't declare any memory between 0xa0000 and 0x100000 - add_e820(BUILD_LOWRAM_END, BUILD_BIOS_ADDR-BUILD_LOWRAM_END, E820_HOLE); - - // Mark known areas as reserved. - add_e820(BUILD_BIOS_ADDR, BUILD_BIOS_SIZE, E820_RESERVED); - - // Populate temp high ram - u32 highram = 0; - int i; - for (i=e820_count-1; i>=0; i--) { - struct e820entry *en = &e820_list[i]; - u64 end = en->start + en->size; - if (end < 1024*1024) - break; - if (en->type != E820_RAM || end > 0xffffffff) - continue; - u32 s = en->start, e = end; - if (!highram) { - u32 newe = ALIGN_DOWN(e - BUILD_MAX_HIGHTABLE, MALLOC_MIN_ALIGN); - if (newe <= e && newe >= s) { - highram = newe; - e = newe; - } - } - addSpace(&ZoneTmpHigh, (void*)s, (void*)e); - } - - // Populate regions - addSpace(&ZoneTmpLow, (void*)BUILD_STACK_ADDR, (void*)BUILD_EBDA_MINIMUM); - if (highram) { - addSpace(&ZoneHigh, (void*)highram - , (void*)highram + BUILD_MAX_HIGHTABLE); - add_e820(highram, BUILD_MAX_HIGHTABLE, E820_RESERVED); - } -} - -void -csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm, u32 hi_pmm_size) -{ - ASSERT32FLAT(); - - if (hi_pmm_size > BUILD_MAX_HIGHTABLE) { - void *hi_pmm_end = (void *)hi_pmm + hi_pmm_size; - addSpace(&ZoneTmpHigh, (void *)hi_pmm, hi_pmm_end - BUILD_MAX_HIGHTABLE); - addSpace(&ZoneHigh, hi_pmm_end - BUILD_MAX_HIGHTABLE, hi_pmm_end); - } else { - addSpace(&ZoneTmpHigh, (void *)hi_pmm, (void *)hi_pmm + hi_pmm_size); - } - addSpace(&ZoneTmpLow, (void *)low_pmm, (void *)low_pmm + low_pmm_size); -} - -u32 LegacyRamSize VARFSEG; - -// Calculate the maximum ramsize (less than 4gig) from e820 map. -static void -calcRamSize(void) -{ - u32 rs = 0; - int i; - for (i=e820_count-1; i>=0; i--) { - struct e820entry *en = &e820_list[i]; - u64 end = en->start + en->size; - u32 type = en->type; - if (end <= 0xffffffff && (type == E820_ACPI || type == E820_RAM)) { - rs = end; - break; - } - } - LegacyRamSize = rs >= 1024*1024 ? rs : 1024*1024; -} - -// Update pointers after code relocation. -void -malloc_init(void) -{ - ASSERT32FLAT(); - dprintf(3, "malloc init\n"); - - if (CONFIG_RELOCATE_INIT) { - // Fixup malloc pointers after relocation - int i; - for (i=0; i<ARRAY_SIZE(Zones); i++) { - struct zone_s *zone = Zones[i]; - if (zone->head.first) - zone->head.first->pprev = &zone->head.first; - } - } - - // Initialize low-memory region - extern u8 varlow_start[], varlow_end[], final_varlow_start[]; - memmove(final_varlow_start, varlow_start, varlow_end - varlow_start); - if (CONFIG_MALLOC_UPPERMEMORY) { - addSpace(&ZoneLow, zonelow_base + OPROM_HEADER_RESERVE - , final_varlow_start); - RomBase = findLast(&ZoneLow); - } else { - addSpace(&ZoneLow, (void*)ALIGN_DOWN((u32)final_varlow_start, 1024) - , final_varlow_start); - } - - // Add space available in f-segment to ZoneFSeg - extern u8 zonefseg_start[], zonefseg_end[]; - memset(zonefseg_start, 0, zonefseg_end - zonefseg_start); - addSpace(&ZoneFSeg, zonefseg_start, zonefseg_end); - - calcRamSize(); -} - -void -malloc_prepboot(void) -{ - ASSERT32FLAT(); - dprintf(3, "malloc finalize\n"); - - u32 base = rom_get_max(); - memset((void*)RomEnd, 0, base-RomEnd); - if (CONFIG_MALLOC_UPPERMEMORY) { - // Place an optionrom signature around used low mem area. - struct rom_header *dummyrom = (void*)base; - dummyrom->signature = OPTION_ROM_SIGNATURE; - int size = (BUILD_BIOS_ADDR - base) / 512; - dummyrom->size = (size > 255) ? 255 : size; - } - - // Reserve more low-mem if needed. - u32 endlow = GET_BDA(mem_size_kb)*1024; - add_e820(endlow, BUILD_LOWRAM_END-endlow, E820_RESERVED); - - // Clear unused f-seg ram. - struct allocinfo_s *info = findLast(&ZoneFSeg); - memset(info->dataend, 0, info->allocend - info->dataend); - dprintf(1, "Space available for UMB: %x-%x, %x-%x\n" - , RomEnd, base, (u32)info->dataend, (u32)info->allocend); - - // Give back unused high ram. - info = findLast(&ZoneHigh); - if (info) { - u32 giveback = ALIGN_DOWN(info->allocend - info->dataend, PAGE_SIZE); - add_e820((u32)info->dataend, giveback, E820_RAM); - dprintf(1, "Returned %d bytes of ZoneHigh\n", giveback); - } - - calcRamSize(); -} - - -/**************************************************************** - * pmm interface - ****************************************************************/ - struct pmmheader { u32 signature; u8 version; @@ -580,12 +56,12 @@ handle_pmm00(u16 *args) case 0: return 0; case 1: - return pmm_getspace(lowzone); + return malloc_getspace(lowzone); case 2: - return pmm_getspace(highzone); + return malloc_getspace(highzone); case 3: { - u32 spacelow = pmm_getspace(lowzone); - u32 spacehigh = pmm_getspace(highzone); + u32 spacelow = malloc_getspace(lowzone); + u32 spacehigh = malloc_getspace(highzone); if (spacelow > spacehigh) return spacelow; return spacehigh; @@ -606,14 +82,14 @@ handle_pmm00(u16 *args) case 0: return 0; case 1: - return (u32)pmm_malloc(lowzone, handle, size, align); + return (u32)_malloc(lowzone, handle, size, align); case 2: - return (u32)pmm_malloc(highzone, handle, size, align); + return (u32)_malloc(highzone, handle, size, align); case 3: { - void *data = pmm_malloc(lowzone, handle, size, align); + void *data = _malloc(lowzone, handle, size, align); if (data) return (u32)data; - return (u32)pmm_malloc(highzone, handle, size, align); + return (u32)_malloc(highzone, handle, size, align); } } } @@ -624,9 +100,9 @@ handle_pmm01(u16 *args) { u32 handle = *(u32*)&args[1]; dprintf(3, "pmm01: handle=%x\n", handle); - if (handle == PMM_DEFAULT_HANDLE) + if (handle == MALLOC_DEFAULT_HANDLE) return 0; - return (u32)pmm_find(handle); + return (u32)malloc_find(handle); }
// PMM - deallocate @@ -635,7 +111,7 @@ handle_pmm02(u16 *args) { u32 buffer = *(u32*)&args[1]; dprintf(3, "pmm02: buffer=%x\n", buffer); - int ret = pmm_free((void*)buffer); + int ret = _free((void*)buffer); if (ret) // Error return 1; diff --git a/src/post.c b/src/post.c index f1cb8a8..701134f 100644 --- a/src/post.c +++ b/src/post.c @@ -25,6 +25,7 @@ #include "hw/lsi-scsi.h" // lsi_scsi_setup #include "hw/esp-scsi.h" // esp_scsi_setup #include "hw/megasas.h" // megasas_setup +#include "malloc.h" // malloc_init #include "post.h" // interface_init #include "string.h" // memset
diff --git a/src/romfile.c b/src/romfile.c index 94e1ed5..835ca99 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -6,6 +6,7 @@
#include "config.h" // CONFIG_* #include "util.h" // dprintf +#include "malloc.h" // free #include "romfile.h" // struct romfile_s #include "string.h" // memcmp
diff --git a/src/stacks.c b/src/stacks.c index b499872..19cd869 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -8,6 +8,7 @@ #include "util.h" // dprintf #include "bregs.h" // CR0_PE #include "list.h" // hlist_node +#include "malloc.h" // free #include "stacks.h" // struct mutex_s
diff --git a/src/system.c b/src/system.c index af31db7..bd53f7d 100644 --- a/src/system.c +++ b/src/system.c @@ -11,6 +11,7 @@ #include "memmap.h" // E820_RAM #include "hw/pic.h" // pic_reset #include "bregs.h" // struct bregs +#include "malloc.h" // LegacyRamSize #include "string.h" // memcpy_far
// Use PS2 System Control port A to set A20 enable diff --git a/src/util.h b/src/util.h index a1a10f4..dffc444 100644 --- a/src/util.h +++ b/src/util.h @@ -174,67 +174,8 @@ u16 get_pnp_offset(void); void pnp_init(void);
// pmm.c -extern struct zone_s ZoneLow, ZoneHigh, ZoneFSeg, ZoneTmpLow, ZoneTmpHigh; -u32 rom_get_max(void); -u32 rom_get_last(void); -struct rom_header *rom_reserve(u32 size); -int rom_confirm(u32 size); -void csm_malloc_preinit(u32 low_pmm, u32 low_pmm_size, u32 hi_pmm, - u32 hi_pmm_size); -void malloc_preinit(void); -extern u32 LegacyRamSize; -void malloc_init(void); -void malloc_prepboot(void); -void *pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align); -int pmm_free(void *data); void pmm_init(void); void pmm_prepboot(void); -#define PMM_DEFAULT_HANDLE 0xFFFFFFFF -// Minimum alignment of malloc'd memory -#define MALLOC_MIN_ALIGN 16 -// Helper functions for memory allocation. -static inline void *malloc_low(u32 size) { - return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); -} -static inline void *malloc_high(u32 size) { - return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); -} -static inline void *malloc_fseg(u32 size) { - return pmm_malloc(&ZoneFSeg, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); -} -static inline void *malloc_tmplow(u32 size) { - return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); -} -static inline void *malloc_tmphigh(u32 size) { - return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, MALLOC_MIN_ALIGN); -} -static inline void *malloc_tmp(u32 size) { - void *ret = malloc_tmphigh(size); - if (ret) - return ret; - return malloc_tmplow(size); -} -static inline void *memalign_low(u32 align, u32 size) { - return pmm_malloc(&ZoneLow, PMM_DEFAULT_HANDLE, size, align); -} -static inline void *memalign_high(u32 align, u32 size) { - return pmm_malloc(&ZoneHigh, PMM_DEFAULT_HANDLE, size, align); -} -static inline void *memalign_tmplow(u32 align, u32 size) { - return pmm_malloc(&ZoneTmpLow, PMM_DEFAULT_HANDLE, size, align); -} -static inline void *memalign_tmphigh(u32 align, u32 size) { - return pmm_malloc(&ZoneTmpHigh, PMM_DEFAULT_HANDLE, size, align); -} -static inline void *memalign_tmp(u32 align, u32 size) { - void *ret = memalign_tmphigh(align, size); - if (ret) - return ret; - return memalign_tmplow(align, size); -} -static inline void free(void *data) { - pmm_free(data); -}
// fw/mtrr.c void mtrr_setup(void);
Also, sort the order of include files in the c files.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/apm.c | 9 +++---- src/block.c | 8 +++---- src/boot.c | 11 +++++---- src/boot.h | 2 ++ src/bootsplash.c | 11 +++++---- src/cdrom.c | 6 ++--- src/clock.c | 6 ++--- src/disk.c | 10 ++++---- src/fw/acpi.c | 9 +++---- src/fw/biostables.c | 5 ++-- src/fw/coreboot.c | 15 ++++++------ src/fw/csm.c | 17 ++++++------- src/fw/mptable.c | 5 ++-- src/fw/mtrr.c | 3 ++- src/fw/paravirt.c | 19 ++++++++------- src/fw/pciinit.c | 13 +++++----- src/fw/pirtable.c | 4 ++-- src/fw/shadow.c | 9 +++---- src/fw/smbios.c | 7 +++--- src/fw/smm.c | 9 +++---- src/fw/smp.c | 3 ++- src/fw/xen.c | 12 +++++----- src/hw/ahci.c | 18 +++++++------- src/hw/ahci.h | 3 +++ src/hw/ata.c | 20 ++++++++-------- src/hw/blockcmd.c | 19 ++++++++------- src/hw/esp-scsi.c | 15 ++++++------ src/hw/floppy.c | 14 +++++------ src/hw/lsi-scsi.c | 15 ++++++------ src/hw/megasas.c | 13 +++++----- src/hw/pci.c | 9 +++---- src/hw/pic.c | 6 ++--- src/hw/ps2port.c | 7 +++--- src/hw/ramdisk.c | 8 +++---- src/hw/timer.c | 9 +++---- src/hw/usb-ehci.c | 15 ++++++------ src/hw/usb-hid.c | 9 +++---- src/hw/usb-hub.c | 7 +++--- src/hw/usb-msc.c | 10 ++++---- src/hw/usb-ohci.c | 13 +++++----- src/hw/usb-uas.c | 10 ++++---- src/hw/usb-uhci.c | 13 +++++----- src/hw/usb.c | 19 ++++++++------- src/hw/virtio-blk.c | 15 ++++++------ src/hw/virtio-pci.c | 6 ++--- src/hw/virtio-ring.c | 4 ++-- src/hw/virtio-scsi.c | 17 ++++++------- src/kbd.c | 5 ++-- src/malloc.c | 8 +++---- src/memmap.c | 4 ++-- src/misc.c | 4 ++-- src/mouse.c | 3 ++- src/optionroms.c | 9 +++---- src/output.c | 3 ++- src/output.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/pcibios.c | 8 +++---- src/pmm.c | 3 ++- src/pnpbios.c | 3 ++- src/post.c | 27 +++++++++++---------- src/resume.c | 11 +++++---- src/romfile.c | 2 +- src/serial.c | 3 ++- src/stacks.c | 3 ++- src/system.c | 9 +++---- src/util.h | 63 +----------------------------------------------- src/vgahooks.c | 9 +++---- vgasrc/bochsvga.c | 10 ++++---- vgasrc/clext.c | 8 +++---- vgasrc/geodevga.c | 10 ++++---- vgasrc/stdvgamodes.c | 4 ++-- vgasrc/vbe.c | 10 ++++---- vgasrc/vgabios.c | 17 ++++++------- vgasrc/vgafb.c | 4 ++-- 73 files changed, 425 insertions(+), 370 deletions(-) create mode 100644 src/output.h
diff --git a/src/apm.c b/src/apm.c index 32d1f4b..b4b9ed9 100644 --- a/src/apm.c +++ b/src/apm.c @@ -6,14 +6,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs -#include "ioport.h" // outb -#include "util.h" // dprintf #include "config.h" // CONFIG_* -#include "biosvar.h" // GET_GLOBAL -#include "fw/paravirt.h" // runningOnQEMU #include "fw/acpi.h" // acpi_pm_ctl +#include "fw/paravirt.h" // runningOnQEMU +#include "ioport.h" // outb +#include "output.h" // dprintf #include "stacks.h" // yield_toirq +#include "util.h" // apm_shutdown
static void out_str(const char *str_cs) diff --git a/src/block.c b/src/block.c index 5c8bf75..73d6068 100644 --- a/src/block.c +++ b/src/block.c @@ -5,15 +5,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "disk.h" // struct ata_s #include "biosvar.h" // GET_GLOBAL -#include "hw/cmos.h" // inb_cmos -#include "util.h" // dprintf +#include "disk.h" // struct ata_s #include "hw/ata.h" // process_ata_op #include "hw/ahci.h" // process_ahci_op -#include "hw/virtio-blk.h" // process_virtio_blk_op +#include "hw/cmos.h" // inb_cmos #include "hw/blockcmd.h" // cdb_* +#include "hw/virtio-blk.h" // process_virtio_blk_op #include "malloc.h" // malloc_low +#include "output.h" // dprintf #include "stacks.h" // stack_hop #include "string.h" // checksum
diff --git a/src/boot.c b/src/boot.c index cb85325..1cb49d4 100644 --- a/src/boot.c +++ b/src/boot.c @@ -5,20 +5,21 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf +#include "boot.h" // boot_init +#include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "disk.h" // cdrom_boot -#include "bregs.h" // struct bregs -#include "boot.h" // func defs -#include "hw/cmos.h" // inb_cmos +#include "fw/csm.h" // csm_bootprio_* #include "fw/paravirt.h" // qemu_cfg_show_boot_menu +#include "hw/cmos.h" // inb_cmos #include "hw/pci.h" // pci_bdf_to_* #include "hw/usb.h" // struct usbdevice_s -#include "fw/csm.h" // csm_bootprio_* #include "list.h" // hlist_node #include "malloc.h" // free +#include "output.h" // dprintf #include "romfile.h" // romfile_loadint #include "string.h" // memset +#include "util.h" // irqtimer_calc
/**************************************************************** diff --git a/src/boot.h b/src/boot.h index 4d4943b..e6b81bd 100644 --- a/src/boot.h +++ b/src/boot.h @@ -2,6 +2,8 @@ #ifndef __BOOT_H #define __BOOT_H
+#include "types.h" // u16 + // boot.c void boot_init(void); void boot_add_bev(u16 seg, u16 bev, u16 desc, int prio); diff --git a/src/bootsplash.c b/src/bootsplash.c index 1bea722..b7b3eb8 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -5,18 +5,19 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "bmp.h" // bmp_alloc #include "bregs.h" // struct bregs -#include "farptr.h" // FLATPTR_TO_SEG #include "config.h" // CONFIG_* -#include "util.h" // dprintf -#include "jpeg.h" // splash -#include "vbe.h" // struct vbe_info -#include "bmp.h" // bmp_alloc +#include "farptr.h" // FLATPTR_TO_SEG #include "fw/smbios.h" // display_uuid +#include "jpeg.h" // jpeg_alloc #include "malloc.h" // free +#include "output.h" // dprintf #include "romfile.h" // romfile_loadfile #include "stacks.h" // call16_int #include "string.h" // memset +#include "util.h" // enable_bootsplash +#include "vbe.h" // struct vbe_info
/**************************************************************** diff --git a/src/cdrom.c b/src/cdrom.c index a9ac9e4..c499cf9 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -5,13 +5,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "disk.h" // cdrom_13 -#include "util.h" // dprintf -#include "bregs.h" // struct bregs #include "biosvar.h" // GET_GLOBAL +#include "bregs.h" // struct bregs +#include "disk.h" // cdrom_13 #include "hw/ata.h" // ATA_CMD_REQUEST_SENSE #include "hw/blockcmd.h" // CDB_CMD_REQUEST_SENSE #include "malloc.h" // free +#include "output.h" // dprintf #include "string.h" // memset
// Locks for removable devices diff --git a/src/clock.c b/src/clock.c index 6b27aa9..d7de59e 100644 --- a/src/clock.c +++ b/src/clock.c @@ -6,16 +6,16 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // SET_BDA -#include "util.h" // debug_enter +#include "bregs.h" // struct bregs #include "disk.h" // floppy_tick #include "hw/cmos.h" // inb_cmos #include "hw/pic.h" // pic_eoi1 #include "hw/pit.h" // PM_SEL_TIMER0 -#include "bregs.h" // struct bregs -#include "biosvar.h" // GET_GLOBAL #include "hw/usb-hid.h" // usb_check_event +#include "output.h" // debug_enter #include "stacks.h" // yield #include "string.h" // memset +#include "util.h" // clock_setup
// RTC register flags #define RTC_A_UIP 0x80 diff --git a/src/disk.c b/src/disk.c index 2d335e6..b149b6d 100644 --- a/src/disk.c +++ b/src/disk.c @@ -5,14 +5,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "disk.h" // floppy_13 #include "biosvar.h" // SET_BDA -#include "config.h" // CONFIG_* -#include "util.h" // debug_enter -#include "hw/pic.h" // pic_eoi2 #include "bregs.h" // struct bregs -#include "hw/pci.h" // pci_bdf_to_bus +#include "config.h" // CONFIG_* +#include "disk.h" // floppy_13 #include "hw/ata.h" // ATA_CB_DC +#include "hw/pci.h" // pci_bdf_to_bus +#include "hw/pic.h" // pic_eoi2 +#include "output.h" // debug_enter #include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/fw/acpi.c b/src/fw/acpi.c index 8ad3673..cba3f68 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -6,18 +6,19 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "acpi.h" // struct rsdp_descriptor -#include "util.h" // dprintf #include "byteorder.h" // cpu_to_le16 +#include "config.h" // CONFIG_* +#include "dev-q35.h" #include "hw/pci.h" // pci_find_init_device #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_INTERRUPT_LINE #include "ioport.h" // inl -#include "config.h" // CONFIG_* -#include "paravirt.h" // RamSize -#include "dev-q35.h" #include "malloc.h" // free +#include "output.h" // dprintf +#include "paravirt.h" // RamSize #include "romfile.h" // romfile_loadint #include "string.h" // memset +#include "util.h" // MaxCountCPUs #include "x86.h" // readl
#include "src/fw/acpi-dsdt.hex" diff --git a/src/fw/biostables.c b/src/fw/biostables.c index 06cd864..8fa9fac 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -4,14 +4,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "acpi.h" // struct rsdp_descriptor #include "config.h" // CONFIG_* -#include "util.h" // dprintf #include "hw/pci.h" // struct pir_header -#include "acpi.h" // struct rsdp_descriptor #include "malloc.h" // malloc_fseg #include "mptable.h" // MPTABLE_SIGNATURE +#include "output.h" // dprintf #include "smbios.h" // struct smbios_entry_point #include "string.h" // memcpy +#include "util.h" // copy_table
static void copy_pir(void *pos) diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 9971f82..c82dd4e 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -4,21 +4,22 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "memmap.h" // add_e820 -#include "util.h" // dprintf -#include "byteorder.h" // be32_to_cpu -#include "lzmadecode.h" // LzmaDecode -#include "smbios.h" // smbios_init +#include "acpi.h" // find_acpi_features #include "boot.h" // boot_add_cbfs -#include "disk.h" // MAXDESCSIZE +#include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_* -#include "acpi.h" // find_acpi_features +#include "disk.h" // MAXDESCSIZE #include "hw/pci.h" // pci_probe_devices +#include "lzmadecode.h" // LzmaDecode #include "malloc.h" // free +#include "memmap.h" // add_e820 +#include "output.h" // dprintf #include "paravirt.h" // PlatformRunningOn #include "romfile.h" // romfile_findprefix +#include "smbios.h" // smbios_init #include "stacks.h" // yield #include "string.h" // memset +#include "util.h" // coreboot_preinit
/**************************************************************** diff --git a/src/fw/csm.c b/src/fw/csm.c index 9e73a40..7a926b1 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -4,21 +4,22 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "acpi.h" +#include "biosvar.h" +#include "boot.h" +#include "bregs.h" #include "config.h" // CONFIG_* #include "csm.h" -#include "util.h" // dprintf -#include "bregs.h" -#include "optionroms.h" #include "hw/pci.h" +#include "hw/pic.h" +#include "malloc.h" // csm_malloc_preinit #include "memmap.h" -#include "biosvar.h" +#include "optionroms.h" +#include "output.h" // dprintf #include "post.h" -#include "acpi.h" -#include "boot.h" #include "smbios.h" -#include "hw/pic.h" -#include "malloc.h" // csm_malloc_preinit #include "stacks.h" // wait_threads +#include "util.h" // copy_smbios
struct rsdp_descriptor csm_rsdp VARFSEG __aligned(16);
diff --git a/src/fw/mptable.c b/src/fw/mptable.c index 4562a46..9877bae 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -5,14 +5,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf #include "config.h" // CONFIG_* -#include "mptable.h" // MPTABLE_SIGNATURE #include "hw/pci.h" #include "hw/pci_regs.h" #include "malloc.h" // free +#include "mptable.h" // MPTABLE_SIGNATURE +#include "output.h" // dprintf #include "romfile.h" // romfile_loadint #include "string.h" // memset +#include "util.h" // MaxCountCPUs #include "x86.h" // cpuid
void diff --git a/src/fw/mtrr.c b/src/fw/mtrr.c index 855457a..913580e 100644 --- a/src/fw/mtrr.c +++ b/src/fw/mtrr.c @@ -4,10 +4,11 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf #include "config.h" // CONFIG_* #include "hw/pci.h" // pcimem_start +#include "output.h" // dprintf #include "paravirt.h" // RamSize +#include "util.h" // mtrr_setup #include "x86.h" // cpuid
#define MSR_MTRRcap 0x000000fe diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index ea2bbfb..b76c1db 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -8,22 +8,23 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "config.h" // CONFIG_QEMU -#include "util.h" // dprintf +#include "acpi.h" // acpi_setup #include "byteorder.h" // be32_to_cpu -#include "ioport.h" // outw -#include "paravirt.h" // qemu_cfg_preinit -#include "smbios.h" // smbios_setup -#include "memmap.h" // add_e820 +#include "config.h" // CONFIG_QEMU #include "hw/cmos.h" // CMOS_* -#include "acpi.h" // acpi_setup -#include "mptable.h" // mptable_setup #include "hw/pci.h" // create_pirtable -#include "xen.h" // xen_biostable_setup +#include "ioport.h" // outw #include "malloc.h" // malloc_tmp +#include "memmap.h" // add_e820 +#include "mptable.h" // mptable_setup +#include "output.h" // dprintf +#include "paravirt.h" // qemu_cfg_preinit #include "romfile.h" // romfile_loadint +#include "smbios.h" // smbios_setup #include "string.h" // memset +#include "util.h" // pci_setup #include "x86.h" // cpuid +#include "xen.h" // xen_biostable_setup
// Amount of continuous ram under 4Gig u32 RamSize; diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 549c940..834847b 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -5,19 +5,20 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf +#include "acpi.h" // acpi_pm1a_cnt +#include "config.h" // CONFIG_* +#include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR #include "hw/pci.h" // pci_config_readl #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_COMMAND #include "ioport.h" // PORT_ATA1_CMD_BASE -#include "config.h" // CONFIG_* -#include "memmap.h" // add_e820 -#include "paravirt.h" // RamSize -#include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR #include "list.h" // struct hlist_node -#include "acpi.h" // acpi_pm1a_cnt #include "malloc.h" // free +#include "memmap.h" // add_e820 +#include "output.h" // dprintf +#include "paravirt.h" // RamSize #include "string.h" // memset +#include "util.h" // pci_setup
#define PCI_DEVICE_MEM_MIN 0x1000 #define PCI_BRIDGE_IO_MIN 0x1000 diff --git a/src/fw/pirtable.c b/src/fw/pirtable.c index d66d21b..bd4a6aa 100644 --- a/src/fw/pirtable.c +++ b/src/fw/pirtable.c @@ -5,9 +5,9 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "hw/pci.h" // struct pir_header #include "config.h" // CONFIG_* -#include "util.h" // dprintf +#include "hw/pci.h" // struct pir_header +#include "output.h" // dprintf #include "string.h" // checksum
struct pir_header *PirAddr VARFSEG; diff --git a/src/fw/shadow.c b/src/fw/shadow.c index c470592..82d6753 100644 --- a/src/fw/shadow.c +++ b/src/fw/shadow.c @@ -5,15 +5,16 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "hw/pci.h" // pci_config_writeb #include "config.h" // CONFIG_* +#include "dev-q35.h" // PCI_VENDOR_ID_INTEL +#include "hw/pci.h" // pci_config_writeb #include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_VENDOR_ID -#include "paravirt.h" // runningOnXen -#include "dev-q35.h" // PCI_VENDOR_ID_INTEL #include "malloc.h" // rom_get_last +#include "output.h" // dprintf +#include "paravirt.h" // runningOnXen #include "string.h" // memset +#include "util.h" // make_bios_writable #include "x86.h" // wbinvd
// On the emulators, the bios at 0xf0000 is also at 0xffff0000 diff --git a/src/fw/smbios.c b/src/fw/smbios.c index beb3143..a8969da 100644 --- a/src/fw/smbios.c +++ b/src/fw/smbios.c @@ -5,13 +5,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf #include "config.h" // CONFIG_* -#include "paravirt.h" // RamSize -#include "smbios.h" // struct smbios_entry_point #include "malloc.h" // free +#include "output.h" // dprintf +#include "paravirt.h" // RamSize #include "romfile.h" // romfile_findprefix +#include "smbios.h" // struct smbios_entry_point #include "string.h" // memset +#include "util.h" // MaxCountCPUs #include "x86.h" // cpuid
struct smbios_entry_point *SMBiosAddr; diff --git a/src/fw/smm.c b/src/fw/smm.c index 8ca1e83..7142ac0 100644 --- a/src/fw/smm.c +++ b/src/fw/smm.c @@ -5,14 +5,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "config.h" // CONFIG_* +#include "dev-q35.h" #include "hw/pci.h" // pci_config_writel +#include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL #include "hw/pci_regs.h" // PCI_DEVICE_ID -#include "util.h" // dprintf -#include "config.h" // CONFIG_* #include "ioport.h" // outb -#include "hw/pci_ids.h" // PCI_VENDOR_ID_INTEL -#include "dev-q35.h" +#include "output.h" // dprintf #include "string.h" // memcpy +#include "util.h" // smm_setup #include "x86.h" // wbinvd
extern u8 smm_relocation_start, smm_relocation_end; diff --git a/src/fw/smp.c b/src/fw/smp.c index cc6fb80..b96bcfd 100644 --- a/src/fw/smp.c +++ b/src/fw/smp.c @@ -5,11 +5,12 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf #include "config.h" // CONFIG_* #include "hw/cmos.h" // CMOS_BIOS_SMP_COUNT +#include "output.h" // dprintf #include "romfile.h" // romfile_loadint #include "stacks.h" // yield +#include "util.h" // smp_setup #include "x86.h" // wrmsr
#define APIC_ICR_LOW ((u8*)BUILD_APIC_ADDR + 0x300) diff --git a/src/fw/xen.c b/src/fw/xen.c index 8412330..9252721 100644 --- a/src/fw/xen.c +++ b/src/fw/xen.c @@ -4,16 +4,16 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "config.h" -#include "xen.h" -#include "paravirt.h" // PlatformRunningOn -#include "memmap.h" // add_e820 -#include "types.h" // ASM32FLAT -#include "util.h" // copy_acpi_rsdp #include "acpi.h" // find_acpi_features +#include "config.h" #include "malloc.h" // memalign_high +#include "memmap.h" // add_e820 +#include "output.h" // dprintf +#include "paravirt.h" // PlatformRunningOn #include "string.h" // memcpy +#include "util.h" // copy_acpi_rsdp #include "x86.h" // cpuid +#include "xen.h"
#define INFO_PHYSICAL_ADDRESS 0x00001000
diff --git a/src/hw/ahci.c b/src/hw/ahci.c index b3530f9..bf70e23 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -4,21 +4,21 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "types.h" // u8 -#include "ioport.h" // inb -#include "util.h" // dprintf +#include "ahci.h" // CDB_CMD_READ_10 +#include "ata.h" // ATA_CB_STAT #include "biosvar.h" // GET_GLOBAL +#include "blockcmd.h" // CDB_CMD_READ_10 +#include "boot.h" // add_bcv_hd +#include "disk.h" // struct drive_s +#include "ioport.h" // inb +#include "malloc.h" // free +#include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE -#include "boot.h" // add_bcv_hd -#include "disk.h" // struct ata_s -#include "ata.h" // ATA_CB_STAT -#include "ahci.h" // CDB_CMD_READ_10 -#include "blockcmd.h" // CDB_CMD_READ_10 -#include "malloc.h" // free #include "stacks.h" // yield #include "string.h" // memset +#include "util.h" // timer_calc
#define AHCI_REQUEST_TIMEOUT 32000 // 32 seconds max for IDE ops #define AHCI_RESET_TIMEOUT 500 // 500 miliseconds diff --git a/src/hw/ahci.h b/src/hw/ahci.h index c3d3a70..c3d2402 100644 --- a/src/hw/ahci.h +++ b/src/hw/ahci.h @@ -1,6 +1,9 @@ #ifndef __AHCI_H #define __AHCI_H
+#include "types.h" // u32 +#include "disk.h" // struct drive_s + struct sata_cmd_fis { u8 reg; u8 pmp_type; diff --git a/src/hw/ata.c b/src/hw/ata.c index b58ecc3..7338ebf 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -5,23 +5,23 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "types.h" // u8 -#include "ioport.h" // inb -#include "util.h" // dprintf +#include "ata.h" // ATA_CB_STAT +#include "biosvar.h" // GET_GLOBAL +#include "blockcmd.h" // CDB_CMD_READ_10 +#include "boot.h" // boot_add_hd #include "byteorder.h" // be16_to_cpu #include "cmos.h" // inb_cmos -#include "pic.h" // enable_hwirq -#include "biosvar.h" // GET_GLOBAL +#include "disk.h" // struct ata_s +#include "ioport.h" // inb +#include "malloc.h" // malloc_fseg +#include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE -#include "boot.h" // boot_add_hd -#include "disk.h" // struct ata_s -#include "ata.h" // ATA_CB_STAT -#include "blockcmd.h" // CDB_CMD_READ_10 -#include "malloc.h" // malloc_fseg +#include "pic.h" // enable_hwirq #include "stacks.h" // yield #include "string.h" // memset +#include "util.h" // timer_calc
#define IDE_TIMEOUT 32000 //32 seconds max for IDE ops
diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 6f79cc5..59f5763 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -5,21 +5,22 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "ahci.h" // atapi_cmd_data +#include "ata.h" // atapi_cmd_data #include "biosvar.h" // GET_GLOBAL -#include "util.h" // dprintf +#include "blockcmd.h" // struct cdb_request_sense +#include "boot.h" // boot_add_hd #include "byteorder.h" // be32_to_cpu #include "disk.h" // struct disk_op_s -#include "blockcmd.h" // struct cdb_request_sense -#include "ata.h" // atapi_cmd_data -#include "ahci.h" // atapi_cmd_data -#include "usb-msc.h" // usb_cmd_data -#include "usb-uas.h" // usb_cmd_data -#include "virtio-scsi.h" // virtio_scsi_cmd_data -#include "lsi-scsi.h" // lsi_scsi_cmd_data #include "esp-scsi.h" // esp_scsi_cmd_data +#include "lsi-scsi.h" // lsi_scsi_cmd_data #include "megasas.h" // megasas_cmd_data -#include "boot.h" // boot_add_hd +#include "output.h" // dprintf #include "string.h" // memset +#include "usb-msc.h" // usb_cmd_data +#include "usb-uas.h" // usb_cmd_data +#include "util.h" // timer_calc +#include "virtio-scsi.h" // virtio_scsi_cmd_data
// Route command to low-level handler. static int diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 0f55bb9..65a67cd 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -10,18 +10,19 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // foreachpci -#include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL -#include "pci_ids.h" // PCI_DEVICE_ID -#include "pci_regs.h" // PCI_VENDOR_ID -#include "boot.h" // bootprio_find_scsi_device #include "blockcmd.h" // scsi_drive_setup -#include "fw/paravirt.h" // runningOnQEMU +#include "boot.h" // bootprio_find_scsi_device +#include "config.h" // CONFIG_* #include "disk.h" +#include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // foreachpci +#include "pci_ids.h" // PCI_DEVICE_ID +#include "pci_regs.h" // PCI_VENDOR_ID #include "string.h" // memset +#include "util.h" // usleep
#define ESP_TCLO 0x00 #define ESP_TCMID 0x04 diff --git a/src/hw/floppy.c b/src/hw/floppy.c index baae88b..e2db2f8 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -5,21 +5,21 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "types.h" // u8 -#include "disk.h" // DISK_RET_SUCCESS -#include "config.h" // CONFIG_FLOPPY #include "biosvar.h" // SET_BDA -#include "util.h" // dprintf -#include "cmos.h" // inb_cmos -#include "pic.h" // pic_eoi1 -#include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "bregs.h" // struct bregs +#include "cmos.h" // inb_cmos +#include "config.h" // CONFIG_FLOPPY +#include "disk.h" // DISK_RET_SUCCESS #include "malloc.h" // malloc_fseg +#include "output.h" // dprintf #include "pci.h" // pci_to_bdf #include "pci_ids.h" // PCI_CLASS_BRIDGE_ISA +#include "pic.h" // pic_eoi1 #include "romfile.h" // romfile_loadint #include "stacks.h" // yield #include "string.h" // memset +#include "util.h" // timer_calc
#define FLOPPY_SIZE_CODE 0x02 // 512 byte sectors #define FLOPPY_DATALEN 0xff // Not used - because size code is 0x02 diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 91ed198..87751aa 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -10,18 +10,19 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // foreachpci -#include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL -#include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK -#include "pci_regs.h" // PCI_VENDOR_ID -#include "boot.h" // bootprio_find_scsi_device #include "blockcmd.h" // scsi_drive_setup -#include "fw/paravirt.h" // runningOnQEMU +#include "boot.h" // bootprio_find_scsi_device +#include "config.h" // CONFIG_* #include "disk.h" +#include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // foreachpci +#include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK +#include "pci_regs.h" // PCI_VENDOR_ID #include "string.h" // memset +#include "util.h" // usleep
#define LSI_REG_DSTAT 0x0c #define LSI_REG_ISTAT0 0x14 diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 29143eb..4bba0e1 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -10,18 +10,19 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // foreachpci -#include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL -#include "pci_ids.h" // PCI_DEVICE_ID_XXX -#include "pci_regs.h" // PCI_VENDOR_ID -#include "boot.h" // bootprio_find_scsi_device #include "blockcmd.h" // scsi_drive_setup +#include "boot.h" // bootprio_find_scsi_device +#include "config.h" // CONFIG_* #include "disk.h" #include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // foreachpci +#include "pci_ids.h" // PCI_DEVICE_ID_XXX +#include "pci_regs.h" // PCI_VENDOR_ID #include "stacks.h" // yield #include "string.h" // memset +#include "util.h" // timer_calc
#define MFI_DB 0x0 // Doorbell #define MFI_OMSG0 0x18 // Outbound message 0 diff --git a/src/hw/pci.c b/src/hw/pci.c index 9c287ee..4295d01 100644 --- a/src/hw/pci.c +++ b/src/hw/pci.c @@ -6,16 +6,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "config.h" // CONFIG_* -#include "pci.h" // pci_config_writel -#include "ioport.h" // outl -#include "util.h" // dprintf #include "farptr.h" // MAKE_FLATPTR +#include "ioport.h" // outl #include "malloc.h" // malloc_tmp -#include "pci_regs.h" // PCI_VENDOR_ID +#include "output.h" // dprintf +#include "pci.h" // pci_config_writel #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA +#include "pci_regs.h" // PCI_VENDOR_ID #include "romfile.h" // romfile_loadint #include "stacks.h" // call32 #include "string.h" // memset +#include "util.h" // udelay #include "x86.h" // readl
void pci_config_writel(u16 bdf, u32 addr, u32 val) diff --git a/src/hw/pic.c b/src/hw/pic.c index 9a3ea0b..6ff6967 100644 --- a/src/hw/pic.c +++ b/src/hw/pic.c @@ -5,10 +5,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "pic.h" // pic_* -#include "util.h" // dprintf -#include "config.h" // CONFIG_* #include "biosvar.h" // SET_IVT +#include "config.h" // CONFIG_* +#include "output.h" // dprintf +#include "pic.h" // pic_*
u16 pic_irqmask_read(void) diff --git a/src/hw/ps2port.c b/src/hw/ps2port.c index 6da297f..936d152 100644 --- a/src/hw/ps2port.c +++ b/src/hw/ps2port.c @@ -5,13 +5,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "ioport.h" // inb -#include "util.h" // dprintf #include "biosvar.h" // GET_LOW -#include "ps2port.h" // ps2_kbd_command +#include "ioport.h" // inb +#include "output.h" // dprintf #include "pic.h" // pic_eoi1 +#include "ps2port.h" // ps2_kbd_command #include "romfile.h" // romfile_loadint #include "stacks.h" // yield +#include "util.h" // udelay
/**************************************************************** diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index a50e7c0..2599f9a 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -4,13 +4,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "disk.h" // process_ramdisk_op -#include "util.h" // dprintf -#include "memmap.h" // add_e820 #include "biosvar.h" // GET_GLOBAL -#include "bregs.h" // struct bregs #include "boot.h" // boot_add_floppy +#include "bregs.h" // struct bregs +#include "disk.h" // process_ramdisk_op #include "malloc.h" // malloc_fseg +#include "memmap.h" // add_e820 +#include "output.h" // dprintf #include "romfile.h" // romfile_findprefix #include "stacks.h" // call16_int #include "string.h" // memset diff --git a/src/hw/timer.c b/src/hw/timer.c index 56c4eca..6477313 100644 --- a/src/hw/timer.c +++ b/src/hw/timer.c @@ -4,12 +4,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pit.h" // PM_SEL_TIMER0 -#include "ioport.h" // PORT_PIT_MODE -#include "config.h" // CONFIG_* #include "biosvar.h" // GET_LOW +#include "config.h" // CONFIG_* +#include "ioport.h" // PORT_PIT_MODE +#include "output.h" // dprintf +#include "pit.h" // PM_SEL_TIMER0 #include "stacks.h" // yield +#include "util.h" // timer_setup #include "x86.h" // cpuid
// Bits for PORT_PS2_CTRLB diff --git a/src/hw/usb-ehci.c b/src/hw/usb-ehci.c index 6786fd3..626f308 100644 --- a/src/hw/usb-ehci.c +++ b/src/hw/usb-ehci.c @@ -4,19 +4,20 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // pci_bdf_to_bus +#include "biosvar.h" // GET_LOWFLAT #include "config.h" // CONFIG_* #include "ioport.h" // outw -#include "usb-ehci.h" // struct ehci_qh +#include "output.h" // dprintf +#include "malloc.h" // free +#include "pci.h" // pci_bdf_to_bus #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI #include "pci_regs.h" // PCI_BASE_ADDRESS_0 +#include "string.h" // memset #include "usb.h" // struct usb_s -#include "biosvar.h" // GET_LOWFLAT -#include "usb-uhci.h" // uhci_setup +#include "usb-ehci.h" // struct ehci_qh #include "usb-ohci.h" // ohci_setup -#include "malloc.h" // free -#include "string.h" // memset +#include "usb-uhci.h" // uhci_setup +#include "util.h" // msleep #include "x86.h" // readl
struct usb_ehci_s { diff --git a/src/hw/usb-hid.c b/src/hw/usb-hid.c index deb3ea5..e94aa16 100644 --- a/src/hw/usb-hid.c +++ b/src/hw/usb-hid.c @@ -4,12 +4,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "usb-hid.h" // usb_keyboard_setup -#include "config.h" // CONFIG_* -#include "usb.h" // usb_ctrlrequest #include "biosvar.h" // GET_GLOBAL +#include "config.h" // CONFIG_* +#include "output.h" // dprintf #include "ps2port.h" // ATKBD_CMD_GETID +#include "usb.h" // usb_ctrlrequest +#include "usb-hid.h" // usb_keyboard_setup +#include "util.h" // process_key
struct usb_pipe *keyboard_pipe VARFSEG; struct usb_pipe *mouse_pipe VARFSEG; diff --git a/src/hw/usb-hub.c b/src/hw/usb-hub.c index 5bef26f..477518b 100644 --- a/src/hw/usb-hub.c +++ b/src/hw/usb-hub.c @@ -4,11 +4,12 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf #include "config.h" // CONFIG_USB_HUB -#include "usb-hub.h" // struct usb_hub_descriptor -#include "usb.h" // struct usb_s +#include "output.h" // dprintf #include "string.h" // memset +#include "usb.h" // struct usb_s +#include "usb-hub.h" // struct usb_hub_descriptor +#include "util.h" // timer_calc
static int get_hub_desc(struct usb_pipe *pipe, struct usb_hub_descriptor *desc) diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index f592726..ee1fe20 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -4,16 +4,16 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "config.h" // CONFIG_USB_MSC -#include "usb-msc.h" // usb_msc_setup -#include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL #include "blockcmd.h" // cdb_read -#include "disk.h" // DTYPE_USB #include "boot.h" // bootprio_find_usb +#include "config.h" // CONFIG_USB_MSC +#include "disk.h" // DTYPE_USB #include "malloc.h" // free +#include "output.h" // dprintf #include "string.h" // memset +#include "usb.h" // struct usb_s +#include "usb-msc.h" // usb_msc_setup
struct usbdrive_s { struct drive_s drive; diff --git a/src/hw/usb-ohci.c b/src/hw/usb-ohci.c index c96c1d7..313e3fd 100644 --- a/src/hw/usb-ohci.c +++ b/src/hw/usb-ohci.c @@ -4,15 +4,16 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // pci_bdf_to_bus -#include "config.h" // CONFIG_* -#include "usb-ohci.h" // struct ohci_hcca -#include "pci_regs.h" // PCI_BASE_ADDRESS_0 -#include "usb.h" // struct usb_s #include "biosvar.h" // GET_LOWFLAT +#include "config.h" // CONFIG_* #include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // pci_bdf_to_bus +#include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset +#include "usb.h" // struct usb_s +#include "usb-ohci.h" // struct ohci_hcca +#include "util.h" // msleep #include "x86.h" // readl
#define FIT (1 << 31) diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index ab9a050..6925f33 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -14,16 +14,16 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "config.h" // CONFIG_USB_UAS -#include "usb.h" // struct usb_s #include "biosvar.h" // GET_GLOBAL #include "blockcmd.h" // cdb_read -#include "disk.h" // DTYPE_UAS #include "boot.h" // bootprio_find_usb -#include "usb-uas.h" // usb_uas_init +#include "config.h" // CONFIG_USB_UAS +#include "disk.h" // DTYPE_UAS #include "malloc.h" // free +#include "output.h" // dprintf #include "string.h" // memset +#include "usb.h" // struct usb_s +#include "usb-uas.h" // usb_uas_init
#define UAS_UI_COMMAND 0x01 #define UAS_UI_SENSE 0x03 diff --git a/src/hw/usb-uhci.c b/src/hw/usb-uhci.c index 2587a56..753e5dd 100644 --- a/src/hw/usb-uhci.c +++ b/src/hw/usb-uhci.c @@ -4,16 +4,17 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // pci_bdf_to_bus +#include "biosvar.h" // GET_LOWFLAT #include "config.h" // CONFIG_* #include "ioport.h" // outw -#include "usb-uhci.h" // USBLEGSUP -#include "pci_regs.h" // PCI_BASE_ADDRESS_4 -#include "usb.h" // struct usb_s -#include "biosvar.h" // GET_LOWFLAT #include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // pci_bdf_to_bus +#include "pci_regs.h" // PCI_BASE_ADDRESS_4 #include "string.h" // memset +#include "usb.h" // struct usb_s +#include "usb-uhci.h" // USBLEGSUP +#include "util.h" // msleep
struct usb_uhci_s { struct usb_s usb; diff --git a/src/hw/usb.c b/src/hw/usb.c index 5216cce..59d2a93 100644 --- a/src/hw/usb.c +++ b/src/hw/usb.c @@ -4,22 +4,23 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // foreachpci +#include "biosvar.h" // GET_GLOBAL #include "config.h" // CONFIG_* -#include "pci_regs.h" // PCI_CLASS_REVISION +#include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_SERIAL_USB_UHCI -#include "usb-uhci.h" // uhci_setup -#include "usb-ohci.h" // ohci_setup +#include "pci_regs.h" // PCI_CLASS_REVISION +#include "string.h" // memset +#include "usb.h" // struct usb_s #include "usb-ehci.h" // ehci_setup #include "usb-hid.h" // usb_keyboard_setup #include "usb-hub.h" // usb_hub_setup #include "usb-msc.h" // usb_msc_setup +#include "usb-ohci.h" // ohci_setup #include "usb-uas.h" // usb_uas_setup -#include "usb.h" // struct usb_s -#include "biosvar.h" // GET_GLOBAL -#include "malloc.h" // free -#include "string.h" // memset +#include "usb-uhci.h" // uhci_setup +#include "util.h" // msleep #include "x86.h" // __fls
diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 6b628f3..07f6e57 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -7,19 +7,20 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // foreachpci -#include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL +#include "boot.h" // boot_add_hd +#include "config.h" // CONFIG_* +#include "disk.h" +#include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID -#include "boot.h" // boot_add_hd +#include "string.h" // memset +#include "util.h" // usleep #include "virtio-pci.h" #include "virtio-ring.h" #include "virtio-blk.h" -#include "disk.h" -#include "malloc.h" // free -#include "string.h" // memset
struct virtiodrive_s { struct drive_s drive; diff --git a/src/hw/virtio-pci.c b/src/hw/virtio-pci.c index 07177ac..a382504 100644 --- a/src/hw/virtio-pci.c +++ b/src/hw/virtio-pci.c @@ -15,14 +15,14 @@ * See the COPYING file in the top-level directory. */
-#include "virtio-ring.h" -#include "virtio-pci.h" #include "config.h" // CONFIG_DEBUG_LEVEL -#include "util.h" // dprintf #include "malloc.h" // free +#include "output.h" // dprintf #include "pci.h" // pci_config_readl #include "pci_regs.h" // PCI_BASE_ADDRESS_0 #include "string.h" // memset +#include "virtio-pci.h" +#include "virtio-ring.h"
int vp_find_vq(unsigned int ioaddr, int queue_index, struct vring_virtqueue **p_vq) diff --git a/src/hw/virtio-ring.c b/src/hw/virtio-ring.c index bddb090..97e0b34 100644 --- a/src/hw/virtio-ring.c +++ b/src/hw/virtio-ring.c @@ -16,10 +16,10 @@ * */
+#include "biosvar.h" // GET_GLOBAL +#include "output.h" // panic #include "virtio-ring.h" #include "virtio-pci.h" -#include "biosvar.h" // GET_GLOBAL -#include "util.h" // dprintf
#define BUG() do { \ panic("BUG: failure at %d/%s()!\n", __LINE__, __func__); \ diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 8c9c670..1c3500c 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -7,20 +7,21 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "pci.h" // foreachpci -#include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL +#include "blockcmd.h" // scsi_drive_setup +#include "boot.h" // bootprio_find_scsi_device +#include "config.h" // CONFIG_* +#include "disk.h" +#include "malloc.h" // free +#include "output.h" // dprintf +#include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID -#include "boot.h" // bootprio_find_scsi_device -#include "blockcmd.h" // scsi_drive_setup +#include "string.h" // memset +#include "util.h" // usleep #include "virtio-pci.h" #include "virtio-ring.h" #include "virtio-scsi.h" -#include "disk.h" -#include "malloc.h" // free -#include "string.h" // memset
struct virtio_lun_s { struct drive_s drive; diff --git a/src/kbd.c b/src/kbd.c index 4302a05..33a95a3 100644 --- a/src/kbd.c +++ b/src/kbd.c @@ -6,13 +6,14 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_BDA -#include "util.h" // debug_enter -#include "config.h" // CONFIG_* #include "bregs.h" // struct bregs +#include "config.h" // CONFIG_* #include "hw/ps2port.h" // ps2_kbd_command #include "hw/usb-hid.h" // usb_kbd_command +#include "output.h" // debug_enter #include "stacks.h" // stack_hop #include "string.h" // memset +#include "util.h" // kbd_init
// Bit definitions for BDA kbd_flag[012] #define KF0_RSHIFT (1<<0) diff --git a/src/malloc.c b/src/malloc.c index f4783af..65a0bb1 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -4,13 +4,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "config.h" // BUILD_BIOS_ADDR -#include "memmap.h" // struct e820entry #include "biosvar.h" // GET_BDA -#include "optionroms.h" // OPTION_ROM_ALIGN +#include "config.h" // BUILD_BIOS_ADDR #include "list.h" // hlist_node #include "malloc.h" // _malloc +#include "memmap.h" // struct e820entry +#include "optionroms.h" // OPTION_ROM_ALIGN +#include "output.h" // dprintf #include "stacks.h" // wait_preempt #include "string.h" // memset
diff --git a/src/memmap.c b/src/memmap.c index ab1bcad..e03f8d0 100644 --- a/src/memmap.c +++ b/src/memmap.c @@ -4,9 +4,9 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "memmap.h" // struct e820entry #include "config.h" // BUILD_MAX_E820 -#include "util.h" // dprintf.h +#include "memmap.h" // struct e820entry +#include "output.h" // dprintf #include "string.h" // memmove
diff --git a/src/misc.c b/src/misc.c index 642bbb1..43dd16f 100644 --- a/src/misc.c +++ b/src/misc.c @@ -5,10 +5,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "bregs.h" // struct bregs #include "biosvar.h" // GET_BDA -#include "util.h" // debug_enter +#include "bregs.h" // struct bregs #include "hw/pic.h" // enable_hwirq +#include "output.h" // debug_enter #include "stacks.h" // call16_int #include "string.h" // memset
diff --git a/src/mouse.c b/src/mouse.c index 8e8374c..92ae921 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -6,11 +6,12 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_EBDA -#include "util.h" // dprintf #include "bregs.h" // struct bregs #include "hw/ps2port.h" // ps2_mouse_command #include "hw/usb-hid.h" // usb_mouse_command +#include "output.h" // dprintf #include "stacks.h" // stack_hop +#include "util.h" // mouse_init
void mouse_init(void) diff --git a/src/optionroms.c b/src/optionroms.c index 560df81..b38e44e 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -5,19 +5,20 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "boot.h" // IPL #include "bregs.h" // struct bregs -#include "farptr.h" // FLATPTR_TO_SEG #include "config.h" // CONFIG_* -#include "util.h" // dprintf +#include "farptr.h" // FLATPTR_TO_SEG #include "hw/pci.h" // foreachpci -#include "hw/pci_regs.h" // PCI_ROM_ADDRESS #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA -#include "boot.h" // IPL +#include "hw/pci_regs.h" // PCI_ROM_ADDRESS #include "malloc.h" // rom_confirm #include "optionroms.h" // struct rom_header +#include "output.h" // dprintf #include "romfile.h" // romfile_loadint #include "stacks.h" // farcall16big #include "string.h" // memset +#include "util.h" // get_pnp_offset
/**************************************************************** diff --git a/src/output.c b/src/output.c index e69a09a..c38c70c 100644 --- a/src/output.c +++ b/src/output.c @@ -7,14 +7,15 @@ #include <stdarg.h> // va_list
#include "farptr.h" // GET_VAR -#include "util.h" // printf #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "biosvar.h" // GET_GLOBAL #include "fw/paravirt.h" // PlatformRunningOn #include "malloc.h" // malloc_tmp +#include "output.h" // dprintf #include "stacks.h" // call16_int #include "string.h" // memset +#include "util.h" // ScreenAndDebug
struct putcinfo { void (*func)(struct putcinfo *info, char c); diff --git a/src/output.h b/src/output.h new file mode 100644 index 0000000..bdfdd63 --- /dev/null +++ b/src/output.h @@ -0,0 +1,68 @@ +#ifndef __OUTPUT_H +#define __OUTPUT_H + +#include "types.h" // u32 + +// output.c +extern u16 DebugOutputPort; +void debug_serial_preinit(void); +void panic(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))) __noreturn; +void printf(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); +int snprintf(char *str, size_t size, const char *fmt, ...) + __attribute__ ((format (printf, 3, 4))); +char * znprintf(size_t size, const char *fmt, ...) + __attribute__ ((format (printf, 2, 3))); +void __dprintf(const char *fmt, ...) + __attribute__ ((format (printf, 1, 2))); +struct bregs; +void __debug_enter(struct bregs *regs, const char *fname); +void __debug_isr(const char *fname); +void __debug_stub(struct bregs *regs, int lineno, const char *fname); +void __warn_invalid(struct bregs *regs, int lineno, const char *fname); +void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname); +void __warn_internalerror(int lineno, const char *fname); +void __warn_noalloc(int lineno, const char *fname); +void __warn_timeout(int lineno, const char *fname); +void __set_invalid(struct bregs *regs, int lineno, const char *fname); +void __set_unimplemented(struct bregs *regs, int lineno, const char *fname); +void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname); +void __set_code_unimplemented(struct bregs *regs, u32 linecode + , const char *fname); +void hexdump(const void *d, int len); + +#define dprintf(lvl, fmt, args...) do { \ + if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \ + __dprintf((fmt) , ##args ); \ + } while (0) +#define debug_enter(regs, lvl) do { \ + if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \ + __debug_enter((regs), __func__); \ + } while (0) +#define debug_isr(lvl) do { \ + if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \ + __debug_isr(__func__); \ + } while (0) +#define debug_stub(regs) \ + __debug_stub((regs), __LINE__, __func__) +#define warn_invalid(regs) \ + __warn_invalid((regs), __LINE__, __func__) +#define warn_unimplemented(regs) \ + __warn_unimplemented((regs), __LINE__, __func__) +#define warn_internalerror() \ + __warn_internalerror(__LINE__, __func__) +#define warn_noalloc() \ + __warn_noalloc(__LINE__, __func__) +#define warn_timeout() \ + __warn_timeout(__LINE__, __func__) +#define set_invalid(regs) \ + __set_invalid((regs), __LINE__, __func__) +#define set_code_invalid(regs, code) \ + __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__) +#define set_unimplemented(regs) \ + __set_unimplemented((regs), __LINE__, __func__) +#define set_code_unimplemented(regs, code) \ + __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__) + +#endif // output.h diff --git a/src/pcibios.c b/src/pcibios.c index 5b242c9..8e7e1f9 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -5,13 +5,13 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "types.h" // u32 -#include "util.h" // handle_1ab1 -#include "hw/pci.h" // pci_config_readl -#include "bregs.h" // struct bregs #include "biosvar.h" // GET_GLOBAL +#include "bregs.h" // struct bregs +#include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_VENDOR_ID +#include "output.h" // dprintf #include "string.h" // checksum +#include "util.h" // handle_1ab1
// romlayout.S extern void entry_bios32(void); diff --git a/src/pmm.c b/src/pmm.c index f6319a4..e87cfd1 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -8,8 +8,9 @@ #include "config.h" // CONFIG_* #include "farptr.h" // struct segoff_s #include "malloc.h" // _malloc +#include "output.h" // dprintf #include "string.h" // checksum -#include "util.h" // dprintf +#include "util.h" // pmm_init #include "x86.h" // __ffs
struct pmmheader { diff --git a/src/pnpbios.c b/src/pnpbios.c index e67425f..87eea9f 100644 --- a/src/pnpbios.c +++ b/src/pnpbios.c @@ -4,10 +4,11 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf #include "config.h" // BUILD_BIOS_ADDR #include "farptr.h" // SET_FARVAR +#include "output.h" // dprintf #include "string.h" // checksum +#include "util.h" // pnp_init
struct pnpheader { u32 signature; diff --git a/src/post.c b/src/post.c index 701134f..e84dcae 100644 --- a/src/post.c +++ b/src/post.c @@ -5,29 +5,30 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "config.h" // CONFIG_* -#include "hw/cmos.h" // CMOS_* -#include "util.h" // dprintf #include "biosvar.h" // struct bios_data_area_s -#include "disk.h" // floppy_setup -#include "hw/ata.h" // ata_setup -#include "hw/ahci.h" // ahci_setup -#include "memmap.h" // add_e820 -#include "hw/pic.h" // pic_setup -#include "bregs.h" // struct bregs #include "boot.h" // boot_init -#include "hw/usb.h" // usb_setup +#include "bregs.h" // struct bregs +#include "config.h" // CONFIG_* +#include "disk.h" // floppy_setup #include "fw/paravirt.h" // qemu_cfg_preinit #include "fw/xen.h" // xen_preinit +#include "hw/ahci.h" // ahci_setup +#include "hw/ata.h" // ata_setup +#include "hw/cmos.h" // CMOS_* +#include "hw/esp-scsi.h" // esp_scsi_setup +#include "hw/lsi-scsi.h" // lsi_scsi_setup +#include "hw/megasas.h" // megasas_setup +#include "hw/pic.h" // pic_setup #include "hw/ps2port.h" // ps2port_setup +#include "hw/usb.h" // usb_setup #include "hw/virtio-blk.h" // virtio_blk_setup #include "hw/virtio-scsi.h" // virtio_scsi_setup -#include "hw/lsi-scsi.h" // lsi_scsi_setup -#include "hw/esp-scsi.h" // esp_scsi_setup -#include "hw/megasas.h" // megasas_setup #include "malloc.h" // malloc_init +#include "memmap.h" // add_e820 +#include "output.h" // dprintf #include "post.h" // interface_init #include "string.h" // memset +#include "util.h" // kbd_init
/**************************************************************** diff --git a/src/resume.c b/src/resume.c index 892c76c..31643a7 100644 --- a/src/resume.c +++ b/src/resume.c @@ -4,17 +4,18 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // dprintf -#include "ioport.h" // outb -#include "hw/pic.h" // pic_eoi2 #include "biosvar.h" // struct bios_data_area_s #include "bregs.h" // struct bregs #include "fw/acpi.h" // find_resume_vector -#include "hw/ps2port.h" // i8042_reboot -#include "hw/pci.h" // pci_reboot #include "hw/cmos.h" // inb_cmos +#include "hw/pci.h" // pci_reboot +#include "hw/pic.h" // pic_eoi2 +#include "hw/ps2port.h" // i8042_reboot +#include "ioport.h" // outb +#include "output.h" // dprintf #include "stacks.h" // farcall16big #include "string.h" // memset +#include "util.h" // dma_setup
// Indicator if POST phase has been run. int HaveRunPost VARFSEG; diff --git a/src/romfile.c b/src/romfile.c index 835ca99..33b6223 100644 --- a/src/romfile.c +++ b/src/romfile.c @@ -5,8 +5,8 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "config.h" // CONFIG_* -#include "util.h" // dprintf #include "malloc.h" // free +#include "output.h" // dprintf #include "romfile.h" // struct romfile_s #include "string.h" // memcmp
diff --git a/src/serial.c b/src/serial.c index 8fd3067..02f30d6 100644 --- a/src/serial.c +++ b/src/serial.c @@ -6,9 +6,10 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // SET_BDA -#include "util.h" // debug_enter #include "bregs.h" // struct bregs +#include "output.h" // debug_enter #include "stacks.h" // yield +#include "util.h" // serial_setup
/**************************************************************** diff --git a/src/stacks.c b/src/stacks.c index 19cd869..cc597c6 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -5,11 +5,12 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL -#include "util.h" // dprintf #include "bregs.h" // CR0_PE #include "list.h" // hlist_node #include "malloc.h" // free +#include "output.h" // dprintf #include "stacks.h" // struct mutex_s +#include "util.h" // useRTC
/**************************************************************** diff --git a/src/system.c b/src/system.c index bd53f7d..4669e62 100644 --- a/src/system.c +++ b/src/system.c @@ -5,14 +5,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "util.h" // debug_enter #include "biosvar.h" // BIOS_CONFIG_TABLE -#include "ioport.h" // inb -#include "memmap.h" // E820_RAM -#include "hw/pic.h" // pic_reset #include "bregs.h" // struct bregs +#include "hw/pic.h" // pic_reset +#include "ioport.h" // inb #include "malloc.h" // LegacyRamSize +#include "memmap.h" // E820_RAM +#include "output.h" // debug_enter #include "string.h" // memcpy_far +#include "util.h" // handle_1553
// Use PS2 System Control port A to set A20 enable static inline u8 diff --git a/src/util.h b/src/util.h index dffc444..2712f46 100644 --- a/src/util.h +++ b/src/util.h @@ -4,70 +4,9 @@
#include "types.h" // u32
-// output.c -extern u16 DebugOutputPort; -void debug_serial_preinit(void); -void panic(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))) __noreturn; -void printf(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -int snprintf(char *str, size_t size, const char *fmt, ...) - __attribute__ ((format (printf, 3, 4))); -char * znprintf(size_t size, const char *fmt, ...) - __attribute__ ((format (printf, 2, 3))); -void __dprintf(const char *fmt, ...) - __attribute__ ((format (printf, 1, 2))); -struct bregs; -void __debug_enter(struct bregs *regs, const char *fname); -void __debug_isr(const char *fname); -void __debug_stub(struct bregs *regs, int lineno, const char *fname); -void __warn_invalid(struct bregs *regs, int lineno, const char *fname); -void __warn_unimplemented(struct bregs *regs, int lineno, const char *fname); -void __warn_internalerror(int lineno, const char *fname); -void __warn_noalloc(int lineno, const char *fname); -void __warn_timeout(int lineno, const char *fname); -void __set_invalid(struct bregs *regs, int lineno, const char *fname); -void __set_unimplemented(struct bregs *regs, int lineno, const char *fname); -void __set_code_invalid(struct bregs *regs, u32 linecode, const char *fname); -void __set_code_unimplemented(struct bregs *regs, u32 linecode - , const char *fname); -void hexdump(const void *d, int len); - -#define dprintf(lvl, fmt, args...) do { \ - if (CONFIG_DEBUG_LEVEL && (lvl) <= CONFIG_DEBUG_LEVEL) \ - __dprintf((fmt) , ##args ); \ - } while (0) -#define debug_enter(regs, lvl) do { \ - if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \ - __debug_enter((regs), __func__); \ - } while (0) -#define debug_isr(lvl) do { \ - if ((lvl) && (lvl) <= CONFIG_DEBUG_LEVEL) \ - __debug_isr(__func__); \ - } while (0) -#define debug_stub(regs) \ - __debug_stub((regs), __LINE__, __func__) -#define warn_invalid(regs) \ - __warn_invalid((regs), __LINE__, __func__) -#define warn_unimplemented(regs) \ - __warn_unimplemented((regs), __LINE__, __func__) -#define warn_internalerror() \ - __warn_internalerror(__LINE__, __func__) -#define warn_noalloc() \ - __warn_noalloc(__LINE__, __func__) -#define warn_timeout() \ - __warn_timeout(__LINE__, __func__) -#define set_invalid(regs) \ - __set_invalid((regs), __LINE__, __func__) -#define set_code_invalid(regs, code) \ - __set_code_invalid((regs), (code) | (__LINE__ << 8), __func__) -#define set_unimplemented(regs) \ - __set_unimplemented((regs), __LINE__, __func__) -#define set_code_unimplemented(regs, code) \ - __set_code_unimplemented((regs), (code) | (__LINE__ << 8), __func__) - // kbd.c void kbd_init(void); +struct bregs; void handle_15c2(struct bregs *regs); void process_key(u8 key);
diff --git a/src/vgahooks.c b/src/vgahooks.c index 9917014..dc3085e 100644 --- a/src/vgahooks.c +++ b/src/vgahooks.c @@ -4,14 +4,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "bregs.h" // set_code_invalid #include "biosvar.h" // GET_GLOBAL +#include "bregs.h" // set_code_invalid +#include "config.h" // CONFIG_* #include "hw/pci.h" // pci_find_device -#include "hw/pci_regs.h" // PCI_VENDOR_ID #include "hw/pci_ids.h" // PCI_VENDOR_ID_VIA -#include "util.h" // handle_155f -#include "config.h" // CONFIG_* +#include "hw/pci_regs.h" // PCI_VENDOR_ID +#include "output.h" // dprintf #include "string.h" // strcmp +#include "util.h" // handle_155f
#define VH_VIA 1 #define VH_INTEL 2 diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index 7ea49ff..e038c61 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -6,15 +6,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "vgabios.h" // struct vbe_modeinfo -#include "vbe.h" // VBE_CAPABILITY_8BIT_DAC +#include "biosvar.h" // GET_GLOBAL #include "bochsvga.h" // bochsvga_set_mode -#include "util.h" // dprintf #include "config.h" // CONFIG_* -#include "biosvar.h" // GET_GLOBAL -#include "stdvga.h" // VGAREG_SEQU_ADDRESS #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_BASE_ADDRESS_0 +#include "output.h" // dprintf +#include "stdvga.h" // VGAREG_SEQU_ADDRESS +#include "vbe.h" // VBE_CAPABILITY_8BIT_DAC +#include "vgabios.h" // struct vbe_modeinfo
/**************************************************************** diff --git a/vgasrc/clext.c b/vgasrc/clext.c index 6fc6337..93085cf 100644 --- a/vgasrc/clext.c +++ b/vgasrc/clext.c @@ -5,15 +5,15 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "clext.h" // clext_setup -#include "vgabios.h" // VBE_VENDOR_STRING #include "biosvar.h" // GET_GLOBAL -#include "util.h" // dprintf #include "bregs.h" // struct bregs -#include "stdvga.h" // VGAREG_SEQU_ADDRESS +#include "clext.h" // clext_setup #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_BASE_ADDRESS_0 +#include "output.h" // dprintf +#include "stdvga.h" // VGAREG_SEQU_ADDRESS #include "string.h" // memset16_far +#include "vgabios.h" // VBE_VENDOR_STRING
/**************************************************************** diff --git a/vgasrc/geodevga.c b/vgasrc/geodevga.c index 4a63068..f8f61c3 100644 --- a/vgasrc/geodevga.c +++ b/vgasrc/geodevga.c @@ -6,14 +6,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "geodevga.h" // geodevga_setup -#include "farptr.h" // SET_FARVAR #include "biosvar.h" // GET_BDA -#include "vgabios.h" // VGAREG_* -#include "util.h" // dprintf -#include "stdvga.h" // stdvga_crtc_write +#include "farptr.h" // SET_FARVAR +#include "geodevga.h" // geodevga_setup #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_BASE_ADDRESS_0 +#include "output.h" // dprintf +#include "stdvga.h" // stdvga_crtc_write +#include "vgabios.h" // VGAREG_*
/**************************************************************** diff --git a/vgasrc/stdvgamodes.c b/vgasrc/stdvgamodes.c index f22f82c..dda35db 100644 --- a/vgasrc/stdvgamodes.c +++ b/vgasrc/stdvgamodes.c @@ -5,11 +5,11 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "vgabios.h" // struct VideoParamTableEntry_s #include "biosvar.h" // GET_GLOBAL -#include "util.h" // warn_internalerror +#include "output.h" // warn_internalerror #include "stdvga.h" // stdvga_find_mode #include "string.h" // memcpy_far +#include "vgabios.h" // struct VideoParamTableEntry_s
/**************************************************************** diff --git a/vgasrc/vbe.c b/vgasrc/vbe.c index 8595e69..9026b77 100644 --- a/vgasrc/vbe.c +++ b/vgasrc/vbe.c @@ -6,14 +6,14 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "vgabios.h" // handle_104f -#include "config.h" // CONFIG_* +#include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs +#include "config.h" // CONFIG_* +#include "output.h" // dprintf +#include "string.h" // memset_far #include "vbe.h" // struct vbe_info -#include "util.h" // dprintf -#include "biosvar.h" // GET_GLOBAL +#include "vgabios.h" // handle_104f #include "vgahw.h" // vgahw_set_mode -#include "string.h" // memset_far
u32 VBE_total_memory VAR16 = 256 * 1024; u32 VBE_capabilities VAR16; diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 12cd782..5206da9 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -5,19 +5,20 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "bregs.h" // struct bregs #include "biosvar.h" // GET_BDA -#include "util.h" // dprintf -#include "vgabios.h" // calc_page_size -#include "optionroms.h" // struct pci_data -#include "config.h" // CONFIG_* -#include "stdvga.h" // stdvga_set_cursor_shape +#include "bregs.h" // struct bregs #include "clext.h" // clext_1012 -#include "vgahw.h" // vgahw_set_mode -#include "vbe.h" // VBE_RETURN_STATUS_FAILED +#include "config.h" // CONFIG_* #include "hw/pci.h" // pci_config_readw #include "hw/pci_regs.h" // PCI_VENDOR_ID +#include "optionroms.h" // struct pci_data +#include "output.h" // dprintf +#include "stdvga.h" // stdvga_set_cursor_shape #include "string.h" // memset_far +#include "util.h" // VERSION +#include "vbe.h" // VBE_RETURN_STATUS_FAILED +#include "vgabios.h" // calc_page_size +#include "vgahw.h" // vgahw_set_mode
// Standard Video Save Pointer Table struct VideoSavePointer_s { diff --git a/vgasrc/vgafb.c b/vgasrc/vgafb.c index 1fa11b5..815d54b 100644 --- a/vgasrc/vgafb.c +++ b/vgasrc/vgafb.c @@ -5,12 +5,12 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "vgabios.h" // vgafb_scroll #include "biosvar.h" // GET_BDA -#include "util.h" // dprintf #include "byteorder.h" // cpu_to_be16 +#include "output.h" // dprintf #include "stdvga.h" // stdvga_planar4_plane #include "string.h" // memset_far +#include "vgabios.h" // vgafb_scroll
/****************************************************************
The segoff_s definition is used by a number of header files that would not otherwise need farptr.h, so move it to a more central location.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/bregs.h | 1 - src/disk.h | 2 -- src/farptr.h | 10 ---------- src/hw/pic.h | 1 - src/pmm.c | 1 - src/types.h | 11 +++++++++++ src/vbe.h | 1 - 7 files changed, 11 insertions(+), 16 deletions(-)
diff --git a/src/bregs.h b/src/bregs.h index 009db99..3df7d9f 100644 --- a/src/bregs.h +++ b/src/bregs.h @@ -8,7 +8,6 @@ #define __BREGS_H
#include "types.h" // u16 -#include "farptr.h" // struct segoff_s #include "x86.h" // F_CF
diff --git a/src/disk.h b/src/disk.h index 8e49124..48496da 100644 --- a/src/disk.h +++ b/src/disk.h @@ -7,8 +7,6 @@ #define __DISK_H
#include "types.h" // u8 -#include "config.h" // CONFIG_* -#include "farptr.h" // struct segoff_s
#define DISK_RET_SUCCESS 0x00 #define DISK_RET_EPARAM 0x01 diff --git a/src/farptr.h b/src/farptr.h index 5b6c5c1..b64567e 100644 --- a/src/farptr.h +++ b/src/farptr.h @@ -196,16 +196,6 @@ static inline void outsl_fl(u16 port, void *ptr_fl, u16 count) {
#endif
-// Definition for common 16bit segment/offset pointers. -struct segoff_s { - union { - struct { - u16 offset; - u16 seg; - }; - u32 segoff; - }; -}; #define SEGOFF(s,o) ({struct segoff_s __so; __so.offset=(o); __so.seg=(s); __so;})
static inline struct segoff_s FLATPTR_TO_SEGOFF(void *p) { diff --git a/src/hw/pic.h b/src/hw/pic.h index 19aecba..2a89e3f 100644 --- a/src/hw/pic.h +++ b/src/hw/pic.h @@ -8,7 +8,6 @@ #define __PIC_H
#include "ioport.h" // PORT_PIC* -#include "farptr.h" // struct segoff_s
// PORT_PIC1 bitdefs #define PIC1_IRQ0 (1<<0) diff --git a/src/pmm.c b/src/pmm.c index e87cfd1..cce0f29 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -6,7 +6,6 @@
#include "biosvar.h" // FUNC16 #include "config.h" // CONFIG_* -#include "farptr.h" // struct segoff_s #include "malloc.h" // _malloc #include "output.h" // dprintf #include "string.h" // checksum diff --git a/src/types.h b/src/types.h index 9e22ab5..3466b3a 100644 --- a/src/types.h +++ b/src/types.h @@ -21,6 +21,17 @@ union u64_u32_u { u64 val; };
+// Definition for common 16bit segment/offset pointers. +struct segoff_s { + union { + struct { + u16 offset; + u16 seg; + }; + u32 segoff; + }; +}; + #ifdef MANUAL_NO_JUMP_TABLE # define default case 775324556: asm(""); default #endif diff --git a/src/vbe.h b/src/vbe.h index 386613c..94b4ad8 100644 --- a/src/vbe.h +++ b/src/vbe.h @@ -2,7 +2,6 @@ #define __VBE_H
#include "types.h" // u8 -#include "farptr.h" // struct segoff_s
#define VESA_SIGNATURE 0x41534556 // VESA #define VBE2_SIGNATURE 0x32454256 // VBE2
Make sure dependency file import works with new hw/ and fw/ sub-directories.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index fb1f81f..b846491 100644 --- a/Makefile +++ b/Makefile @@ -253,4 +253,4 @@ distclean: clean $(OUT) $(addprefix $(OUT), $(DIRS)): $(Q)mkdir $@
--include $(OUT)*.d +-include $(patsubst %,$(OUT)%/*.d,$(DIRS))
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/fw/biostables.c | 2 +- src/fw/pirtable.c | 2 +- src/hw/pci.h | 40 ---------------------------------------- src/pcibios.c | 1 + src/std/pirtable.h | 35 +++++++++++++++++++++++++++++++++++ src/util.h | 4 ++++ 6 files changed, 42 insertions(+), 42 deletions(-) create mode 100644 src/std/pirtable.h
diff --git a/src/fw/biostables.c b/src/fw/biostables.c index 8fa9fac..a51e8ee 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -6,11 +6,11 @@
#include "acpi.h" // struct rsdp_descriptor #include "config.h" // CONFIG_* -#include "hw/pci.h" // struct pir_header #include "malloc.h" // malloc_fseg #include "mptable.h" // MPTABLE_SIGNATURE #include "output.h" // dprintf #include "smbios.h" // struct smbios_entry_point +#include "std/pirtable.h" // struct pir_header #include "string.h" // memcpy #include "util.h" // copy_table
diff --git a/src/fw/pirtable.c b/src/fw/pirtable.c index bd4a6aa..ee2659d 100644 --- a/src/fw/pirtable.c +++ b/src/fw/pirtable.c @@ -6,8 +6,8 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "config.h" // CONFIG_* -#include "hw/pci.h" // struct pir_header #include "output.h" // dprintf +#include "std/pirtable.h" // struct pir_header #include "string.h" // checksum
struct pir_header *PirAddr VARFSEG; diff --git a/src/hw/pci.h b/src/hw/pci.h index 7760d21..8fccefc 100644 --- a/src/hw/pci.h +++ b/src/hw/pci.h @@ -118,44 +118,4 @@ void pci_reboot(void); u32 pci_readl(u32 addr); void pci_writel(u32 addr, u32 val);
-// pirtable.c -void pirtable_setup(void); - - -/**************************************************************** - * PIR table - ****************************************************************/ - -struct link_info { - u8 link; - u16 bitmap; -} PACKED; - -struct pir_slot { - u8 bus; - u8 dev; - struct link_info links[4]; - u8 slot_nr; - u8 reserved; -} PACKED; - -struct pir_header { - u32 signature; - u16 version; - u16 size; - u8 router_bus; - u8 router_devfunc; - u16 exclusive_irqs; - u32 compatible_devid; - u32 miniport_data; - u8 reserved[11]; - u8 checksum; - struct pir_slot slots[0]; -} PACKED; - -extern struct pir_header *PirAddr; - -#define PIR_SIGNATURE 0x52495024 // $PIR - - #endif diff --git a/src/pcibios.c b/src/pcibios.c index 8e7e1f9..7e5d972 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -10,6 +10,7 @@ #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "output.h" // dprintf +#include "std/pirtable.h" // struct pir_header #include "string.h" // checksum #include "util.h" // handle_1ab1
diff --git a/src/std/pirtable.h b/src/std/pirtable.h new file mode 100644 index 0000000..9de3a43 --- /dev/null +++ b/src/std/pirtable.h @@ -0,0 +1,35 @@ +#ifndef __PIRTABLE_H +#define __PIRTABLE_H + +#include "types.h" // u32 + +struct link_info { + u8 link; + u16 bitmap; +} PACKED; + +struct pir_slot { + u8 bus; + u8 dev; + struct link_info links[4]; + u8 slot_nr; + u8 reserved; +} PACKED; + +struct pir_header { + u32 signature; + u16 version; + u16 size; + u8 router_bus; + u8 router_devfunc; + u16 exclusive_irqs; + u32 compatible_devid; + u32 miniport_data; + u8 reserved[11]; + u8 checksum; + struct pir_slot slots[0]; +} PACKED; + +#define PIR_SIGNATURE 0x52495024 // $PIR + +#endif // pirtable.h diff --git a/src/util.h b/src/util.h index 2712f46..2c65494 100644 --- a/src/util.h +++ b/src/util.h @@ -60,6 +60,10 @@ void qemu_prep_reset(void); extern const u8 pci_irqs[4]; void pci_setup(void);
+// fw/pirtable.c +extern struct pir_header *PirAddr; +void pirtable_setup(void); + // fw/smm.c void smm_device_setup(void); void smm_setup(void);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/fw/csm.c | 2 +- src/malloc.c | 2 +- src/optionroms.c | 2 +- src/{optionroms.h => std/optionrom.h} | 3 --- src/util.h | 4 ++++ vgasrc/vgabios.c | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) rename src/{optionroms.h => std/optionrom.h} (95%)
diff --git a/src/fw/csm.c b/src/fw/csm.c index 7a926b1..b98dc96 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -14,11 +14,11 @@ #include "hw/pic.h" #include "malloc.h" // csm_malloc_preinit #include "memmap.h" -#include "optionroms.h" #include "output.h" // dprintf #include "post.h" #include "smbios.h" #include "stacks.h" // wait_threads +#include "std/optionrom.h" // struct rom_header #include "util.h" // copy_smbios
struct rsdp_descriptor csm_rsdp VARFSEG __aligned(16); diff --git a/src/malloc.c b/src/malloc.c index 65a0bb1..281f41e 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -9,9 +9,9 @@ #include "list.h" // hlist_node #include "malloc.h" // _malloc #include "memmap.h" // struct e820entry -#include "optionroms.h" // OPTION_ROM_ALIGN #include "output.h" // dprintf #include "stacks.h" // wait_preempt +#include "std/optionrom.h" // OPTION_ROM_ALIGN #include "string.h" // memset
// Information on a reserved area. diff --git a/src/optionroms.c b/src/optionroms.c index b38e44e..8f9bb31 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -13,10 +13,10 @@ #include "hw/pci_ids.h" // PCI_CLASS_DISPLAY_VGA #include "hw/pci_regs.h" // PCI_ROM_ADDRESS #include "malloc.h" // rom_confirm -#include "optionroms.h" // struct rom_header #include "output.h" // dprintf #include "romfile.h" // romfile_loadint #include "stacks.h" // farcall16big +#include "std/optionrom.h" // struct rom_header #include "string.h" // memset #include "util.h" // get_pnp_offset
diff --git a/src/optionroms.h b/src/std/optionrom.h similarity index 95% rename from src/optionroms.h rename to src/std/optionrom.h index c5ea4ba..94ca4ae 100644 --- a/src/optionroms.h +++ b/src/std/optionrom.h @@ -56,7 +56,4 @@ struct pnp_data { #define OPTION_ROM_INITVECTOR offsetof(struct rom_header, initVector[0]) #define PCIROM_CODETYPE_X86 0
-void -callrom(struct rom_header *rom, u16 bdf); - #endif diff --git a/src/util.h b/src/util.h index 2c65494..06483ba 100644 --- a/src/util.h +++ b/src/util.h @@ -47,6 +47,10 @@ int irqtimer_check(u32 end); void apm_shutdown(void); void handle_1553(struct bregs *regs);
+// optionroms.c +struct rom_header; +void callrom(struct rom_header *rom, u16 bdf); + // pcibios.c void handle_1ab1(struct bregs *regs); void bios32_init(void); diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 5206da9..a07fc91 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -11,8 +11,8 @@ #include "config.h" // CONFIG_* #include "hw/pci.h" // pci_config_readw #include "hw/pci_regs.h" // PCI_VENDOR_ID -#include "optionroms.h" // struct pci_data #include "output.h" // dprintf +#include "std/optionrom.h" // struct pci_data #include "stdvga.h" // stdvga_set_cursor_shape #include "string.h" // memset_far #include "util.h" // VERSION
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/bootsplash.c | 2 +- src/{ => std}/vbe.h | 0 vgasrc/bochsvga.c | 2 +- vgasrc/vbe.c | 2 +- vgasrc/vgabios.c | 2 +- 5 files changed, 4 insertions(+), 4 deletions(-) rename src/{ => std}/vbe.h (100%)
diff --git a/src/bootsplash.c b/src/bootsplash.c index b7b3eb8..3c08f5d 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -15,9 +15,9 @@ #include "output.h" // dprintf #include "romfile.h" // romfile_loadfile #include "stacks.h" // call16_int +#include "std/vbe.h" // struct vbe_info #include "string.h" // memset #include "util.h" // enable_bootsplash -#include "vbe.h" // struct vbe_info
/**************************************************************** diff --git a/src/vbe.h b/src/std/vbe.h similarity index 100% rename from src/vbe.h rename to src/std/vbe.h diff --git a/vgasrc/bochsvga.c b/vgasrc/bochsvga.c index e038c61..ed741dc 100644 --- a/vgasrc/bochsvga.c +++ b/vgasrc/bochsvga.c @@ -12,8 +12,8 @@ #include "hw/pci.h" // pci_config_readl #include "hw/pci_regs.h" // PCI_BASE_ADDRESS_0 #include "output.h" // dprintf +#include "std/vbe.h" // VBE_CAPABILITY_8BIT_DAC #include "stdvga.h" // VGAREG_SEQU_ADDRESS -#include "vbe.h" // VBE_CAPABILITY_8BIT_DAC #include "vgabios.h" // struct vbe_modeinfo
diff --git a/vgasrc/vbe.c b/vgasrc/vbe.c index 9026b77..f7e2203 100644 --- a/vgasrc/vbe.c +++ b/vgasrc/vbe.c @@ -10,8 +10,8 @@ #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "output.h" // dprintf +#include "std/vbe.h" // struct vbe_info #include "string.h" // memset_far -#include "vbe.h" // struct vbe_info #include "vgabios.h" // handle_104f #include "vgahw.h" // vgahw_set_mode
diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index a07fc91..0769330 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -13,10 +13,10 @@ #include "hw/pci_regs.h" // PCI_VENDOR_ID #include "output.h" // dprintf #include "std/optionrom.h" // struct pci_data +#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 "vbe.h" // VBE_RETURN_STATUS_FAILED #include "vgabios.h" // calc_page_size #include "vgahw.h" // vgahw_set_mode
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/boot.c | 1 - src/fw/csm.c | 6 +++++- src/fw/csm.h | 18 ------------------ src/{fw => std}/LegacyBios.h | 0 src/util.h | 7 ++++++- 5 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 src/fw/csm.h rename src/{fw => std}/LegacyBios.h (100%)
diff --git a/src/boot.c b/src/boot.c index 1cb49d4..fbfbf34 100644 --- a/src/boot.c +++ b/src/boot.c @@ -9,7 +9,6 @@ #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "disk.h" // cdrom_boot -#include "fw/csm.h" // csm_bootprio_* #include "fw/paravirt.h" // qemu_cfg_show_boot_menu #include "hw/cmos.h" // inb_cmos #include "hw/pci.h" // pci_bdf_to_* diff --git a/src/fw/csm.c b/src/fw/csm.c index b98dc96..7829c1e 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -9,7 +9,6 @@ #include "boot.h" #include "bregs.h" #include "config.h" // CONFIG_* -#include "csm.h" #include "hw/pci.h" #include "hw/pic.h" #include "malloc.h" // csm_malloc_preinit @@ -21,6 +20,11 @@ #include "std/optionrom.h" // struct rom_header #include "util.h" // copy_smbios
+#define UINT8 u8 +#define UINT16 u16 +#define UINT32 u32 +#include "std/LegacyBios.h" + struct rsdp_descriptor csm_rsdp VARFSEG __aligned(16);
EFI_COMPATIBILITY16_TABLE csm_compat_table VARFSEG __aligned(16) = { diff --git a/src/fw/csm.h b/src/fw/csm.h deleted file mode 100644 index 997e3f7..0000000 --- a/src/fw/csm.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef __CSM_H -#define __CSM_H - -#include "types.h" - -#define UINT8 u8 -#define UINT16 u16 -#define UINT32 u32 - -// csm.c -struct pci_device; -int csm_bootprio_fdc(struct pci_device *pci, int port, int fdid); -int csm_bootprio_ata(struct pci_device *pci, int chanid, int slave); -int csm_bootprio_pci(struct pci_device *pci); - -#include "LegacyBios.h" - -#endif // __CSM_H diff --git a/src/fw/LegacyBios.h b/src/std/LegacyBios.h similarity index 100% rename from src/fw/LegacyBios.h rename to src/std/LegacyBios.h diff --git a/src/util.h b/src/util.h index 06483ba..dfd6faf 100644 --- a/src/util.h +++ b/src/util.h @@ -55,6 +55,12 @@ void callrom(struct rom_header *rom, u16 bdf); void handle_1ab1(struct bregs *regs); void bios32_init(void);
+// fw/csm.c +struct pci_device; +int csm_bootprio_fdc(struct pci_device *pci, int port, int fdid); +int csm_bootprio_ata(struct pci_device *pci, int chanid, int slave); +int csm_bootprio_pci(struct pci_device *pci); + // fw/shadow.c void make_bios_writable(void); void make_bios_readonly(void); @@ -95,7 +101,6 @@ void copy_table(void *pos);
// vgahooks.c void handle_155f(struct bregs *regs); -struct pci_device; void vgahook_setup(struct pci_device *pci);
// optionroms.c
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/bootsplash.c | 1 - src/fw/biostables.c | 2 +- src/fw/coreboot.c | 1 - src/fw/csm.c | 1 - src/fw/paravirt.c | 1 - src/fw/smbios.c | 2 +- src/{fw => std}/smbios.h | 6 +----- src/util.h | 5 +++++ 8 files changed, 8 insertions(+), 11 deletions(-) rename src/{fw => std}/smbios.h (97%)
diff --git a/src/bootsplash.c b/src/bootsplash.c index 3c08f5d..aac7ebe 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -9,7 +9,6 @@ #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "farptr.h" // FLATPTR_TO_SEG -#include "fw/smbios.h" // display_uuid #include "jpeg.h" // jpeg_alloc #include "malloc.h" // free #include "output.h" // dprintf diff --git a/src/fw/biostables.c b/src/fw/biostables.c index a51e8ee..5200e65 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -9,8 +9,8 @@ #include "malloc.h" // malloc_fseg #include "mptable.h" // MPTABLE_SIGNATURE #include "output.h" // dprintf -#include "smbios.h" // struct smbios_entry_point #include "std/pirtable.h" // struct pir_header +#include "std/smbios.h" // struct smbios_entry_point #include "string.h" // memcpy #include "util.h" // copy_table
diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index c82dd4e..5daed86 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -16,7 +16,6 @@ #include "output.h" // dprintf #include "paravirt.h" // PlatformRunningOn #include "romfile.h" // romfile_findprefix -#include "smbios.h" // smbios_init #include "stacks.h" // yield #include "string.h" // memset #include "util.h" // coreboot_preinit diff --git a/src/fw/csm.c b/src/fw/csm.c index 7829c1e..eca97a7 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -15,7 +15,6 @@ #include "memmap.h" #include "output.h" // dprintf #include "post.h" -#include "smbios.h" #include "stacks.h" // wait_threads #include "std/optionrom.h" // struct rom_header #include "util.h" // copy_smbios diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index b76c1db..a49c80a 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -20,7 +20,6 @@ #include "output.h" // dprintf #include "paravirt.h" // qemu_cfg_preinit #include "romfile.h" // romfile_loadint -#include "smbios.h" // smbios_setup #include "string.h" // memset #include "util.h" // pci_setup #include "x86.h" // cpuid diff --git a/src/fw/smbios.c b/src/fw/smbios.c index a8969da..affb9be 100644 --- a/src/fw/smbios.c +++ b/src/fw/smbios.c @@ -10,7 +10,7 @@ #include "output.h" // dprintf #include "paravirt.h" // RamSize #include "romfile.h" // romfile_findprefix -#include "smbios.h" // struct smbios_entry_point +#include "std/smbios.h" // struct smbios_entry_point #include "string.h" // memset #include "util.h" // MaxCountCPUs #include "x86.h" // cpuid diff --git a/src/fw/smbios.h b/src/std/smbios.h similarity index 97% rename from src/fw/smbios.h rename to src/std/smbios.h index a4c1444..0513716 100644 --- a/src/fw/smbios.h +++ b/src/std/smbios.h @@ -1,8 +1,7 @@ #ifndef __SMBIOS_H #define __SMBIOS_H
-// smbios.c -void smbios_setup(void); +#include "types.h" // u32
/* SMBIOS entry point -- must be written to a 16-bit aligned address between 0xf0000 and 0xfffff. @@ -24,8 +23,6 @@ struct smbios_entry_point { u8 smbios_bcd_revision; } PACKED;
-extern struct smbios_entry_point *SMBiosAddr; - /* This goes at the beginning of every SMBIOS structure. */ struct smbios_structure_header { u8 type; @@ -165,5 +162,4 @@ struct smbios_type_127 { struct smbios_structure_header header; } PACKED;
-void display_uuid(void); #endif // smbios.h diff --git a/src/util.h b/src/util.h index dfd6faf..0b3a8e7 100644 --- a/src/util.h +++ b/src/util.h @@ -66,6 +66,11 @@ void make_bios_writable(void); void make_bios_readonly(void); void qemu_prep_reset(void);
+// fw/smbios.c +extern struct smbios_entry_point *SMBiosAddr; +void smbios_setup(void); +void display_uuid(void); + // fw/pciinit.c extern const u8 pci_irqs[4]; void pci_setup(void);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/fw/biostables.c | 2 +- src/fw/mptable.c | 2 +- src/fw/paravirt.c | 1 - src/{fw => std}/mptable.h | 3 --- src/util.h | 3 +++ 5 files changed, 5 insertions(+), 6 deletions(-) rename src/{fw => std}/mptable.h (96%)
diff --git a/src/fw/biostables.c b/src/fw/biostables.c index 5200e65..fea7511 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -7,8 +7,8 @@ #include "acpi.h" // struct rsdp_descriptor #include "config.h" // CONFIG_* #include "malloc.h" // malloc_fseg -#include "mptable.h" // MPTABLE_SIGNATURE #include "output.h" // dprintf +#include "std/mptable.h" // MPTABLE_SIGNATURE #include "std/pirtable.h" // struct pir_header #include "std/smbios.h" // struct smbios_entry_point #include "string.h" // memcpy diff --git a/src/fw/mptable.c b/src/fw/mptable.c index 9877bae..b453469 100644 --- a/src/fw/mptable.c +++ b/src/fw/mptable.c @@ -9,9 +9,9 @@ #include "hw/pci.h" #include "hw/pci_regs.h" #include "malloc.h" // free -#include "mptable.h" // MPTABLE_SIGNATURE #include "output.h" // dprintf #include "romfile.h" // romfile_loadint +#include "std/mptable.h" // MPTABLE_SIGNATURE #include "string.h" // memset #include "util.h" // MaxCountCPUs #include "x86.h" // cpuid diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index a49c80a..573511c 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -16,7 +16,6 @@ #include "ioport.h" // outw #include "malloc.h" // malloc_tmp #include "memmap.h" // add_e820 -#include "mptable.h" // mptable_setup #include "output.h" // dprintf #include "paravirt.h" // qemu_cfg_preinit #include "romfile.h" // romfile_loadint diff --git a/src/fw/mptable.h b/src/std/mptable.h similarity index 96% rename from src/fw/mptable.h rename to src/std/mptable.h index 6252854..fa6a229 100644 --- a/src/fw/mptable.h +++ b/src/std/mptable.h @@ -74,7 +74,4 @@ struct mpt_intsrc { u8 dstirq; } PACKED;
-// mptable.c -void mptable_setup(void); - #endif // mptable.h diff --git a/src/util.h b/src/util.h index 0b3a8e7..ab45ac6 100644 --- a/src/util.h +++ b/src/util.h @@ -61,6 +61,9 @@ int csm_bootprio_fdc(struct pci_device *pci, int port, int fdid); int csm_bootprio_ata(struct pci_device *pci, int chanid, int slave); int csm_bootprio_pci(struct pci_device *pci);
+// fw/mptable.c +void mptable_setup(void); + // fw/shadow.c void make_bios_writable(void); void make_bios_readonly(void);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/apm.c | 1 - src/byteorder.h | 2 ++ src/fw/acpi.c | 4 +++- src/fw/biostables.c | 2 +- src/fw/coreboot.c | 1 - src/fw/csm.c | 2 +- src/fw/paravirt.c | 1 - src/fw/pciinit.c | 1 - src/fw/xen.c | 1 - src/resume.c | 1 - src/{fw => std}/acpi.h | 10 ---------- src/util.h | 10 ++++++++++ 12 files changed, 17 insertions(+), 19 deletions(-) rename src/{fw => std}/acpi.h (96%)
diff --git a/src/apm.c b/src/apm.c index b4b9ed9..7f400fb 100644 --- a/src/apm.c +++ b/src/apm.c @@ -9,7 +9,6 @@ #include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "fw/acpi.h" // acpi_pm_ctl #include "fw/paravirt.h" // runningOnQEMU #include "ioport.h" // outb #include "output.h" // dprintf diff --git a/src/byteorder.h b/src/byteorder.h index 7362aeb..928c1b8 100644 --- a/src/byteorder.h +++ b/src/byteorder.h @@ -1,6 +1,8 @@ #ifndef __BYTEORDER_H #define __BYTEORDER_H
+#include "types.h" // u32 + static inline u16 __swab16_constant(u16 val) { return (val<<8) | (val>>8); } diff --git a/src/fw/acpi.c b/src/fw/acpi.c index cba3f68..8f99b34 100644 --- a/src/fw/acpi.c +++ b/src/fw/acpi.c @@ -5,7 +5,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" // struct rsdp_descriptor #include "byteorder.h" // cpu_to_le16 #include "config.h" // CONFIG_* #include "dev-q35.h" @@ -17,6 +16,7 @@ #include "output.h" // dprintf #include "paravirt.h" // RamSize #include "romfile.h" // romfile_loadint +#include "std/acpi.h" // struct rsdp_descriptor #include "string.h" // memset #include "util.h" // MaxCountCPUs #include "x86.h" // readl @@ -756,6 +756,8 @@ find_acpi_features(void) static struct acpi_20_generic_address acpi_reset_reg; static u8 acpi_reset_val;
+#define acpi_ga_to_bdf(addr) pci_to_bdf(0, (addr >> 32) & 0xffff, (addr >> 16) & 0xffff) + void acpi_reboot(void) { diff --git a/src/fw/biostables.c b/src/fw/biostables.c index fea7511..a3ee827 100644 --- a/src/fw/biostables.c +++ b/src/fw/biostables.c @@ -4,10 +4,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" // struct rsdp_descriptor #include "config.h" // CONFIG_* #include "malloc.h" // malloc_fseg #include "output.h" // dprintf +#include "std/acpi.h" // struct rsdp_descriptor #include "std/mptable.h" // MPTABLE_SIGNATURE #include "std/pirtable.h" // struct pir_header #include "std/smbios.h" // struct smbios_entry_point diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 5daed86..e9874e2 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -4,7 +4,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" // find_acpi_features #include "boot.h" // boot_add_cbfs #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_* diff --git a/src/fw/csm.c b/src/fw/csm.c index eca97a7..dda6af4 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -4,7 +4,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" #include "biosvar.h" #include "boot.h" #include "bregs.h" @@ -16,6 +15,7 @@ #include "output.h" // dprintf #include "post.h" #include "stacks.h" // wait_threads +#include "std/acpi.h" // RSDP_SIGNATURE #include "std/optionrom.h" // struct rom_header #include "util.h" // copy_smbios
diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c index 573511c..2524b7b 100644 --- a/src/fw/paravirt.c +++ b/src/fw/paravirt.c @@ -8,7 +8,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" // acpi_setup #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_QEMU #include "hw/cmos.h" // CMOS_* diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c index 834847b..b29db99 100644 --- a/src/fw/pciinit.c +++ b/src/fw/pciinit.c @@ -5,7 +5,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" // acpi_pm1a_cnt #include "config.h" // CONFIG_* #include "dev-q35.h" // Q35_HOST_BRIDGE_PCIEXBAR_ADDR #include "hw/pci.h" // pci_config_readl diff --git a/src/fw/xen.c b/src/fw/xen.c index 9252721..9b00030 100644 --- a/src/fw/xen.c +++ b/src/fw/xen.c @@ -4,7 +4,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "acpi.h" // find_acpi_features #include "config.h" #include "malloc.h" // memalign_high #include "memmap.h" // add_e820 diff --git a/src/resume.c b/src/resume.c index 31643a7..96c63d5 100644 --- a/src/resume.c +++ b/src/resume.c @@ -6,7 +6,6 @@
#include "biosvar.h" // struct bios_data_area_s #include "bregs.h" // struct bregs -#include "fw/acpi.h" // find_resume_vector #include "hw/cmos.h" // inb_cmos #include "hw/pci.h" // pci_reboot #include "hw/pic.h" // pic_eoi2 diff --git a/src/fw/acpi.h b/src/std/acpi.h similarity index 96% rename from src/fw/acpi.h rename to src/std/acpi.h index f0d24d4..fad6ac2 100644 --- a/src/fw/acpi.h +++ b/src/std/acpi.h @@ -13,13 +13,6 @@ struct acpi_20_generic_address { u8 reserved; u64 address; } PACKED; -#define acpi_ga_to_bdf(addr) pci_to_bdf(0, (addr >> 32) & 0xffff, (addr >> 16) & 0xffff) - -void acpi_setup(void); -u32 find_resume_vector(void); -void find_acpi_features(void); -void acpi_set_reset_reg(struct acpi_20_generic_address *reg, u8 val); -void acpi_reboot(void);
#define RSDP_SIGNATURE 0x2052545020445352LL // "RSD PTR "
@@ -35,9 +28,6 @@ struct rsdp_descriptor { /* Root System Descriptor Pointer */ u8 reserved [3]; /* Reserved field must be 0 */ };
-extern struct rsdp_descriptor *RsdpAddr; -extern u32 acpi_pm1a_cnt; - /* Table structure from Linux kernel (the ACPI tables are under the BSD license) */
diff --git a/src/util.h b/src/util.h index ab45ac6..95be57f 100644 --- a/src/util.h +++ b/src/util.h @@ -55,6 +55,16 @@ void callrom(struct rom_header *rom, u16 bdf); void handle_1ab1(struct bregs *regs); void bios32_init(void);
+// fw/acpi.c +extern struct rsdp_descriptor *RsdpAddr; +extern u32 acpi_pm1a_cnt; +void acpi_setup(void); +u32 find_resume_vector(void); +void find_acpi_features(void); +struct acpi_20_generic_address; +void acpi_set_reset_reg(struct acpi_20_generic_address *reg, u8 val); +void acpi_reboot(void); + // fw/csm.c struct pci_device; int csm_bootprio_fdc(struct pci_device *pci, int port, int fdid);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/optionroms.c | 1 + src/pnpbios.c | 19 +------------------ src/std/pnpbios.h | 24 ++++++++++++++++++++++++ src/util.h | 1 - 4 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 src/std/pnpbios.h
diff --git a/src/optionroms.c b/src/optionroms.c index 8f9bb31..04afb2c 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -17,6 +17,7 @@ #include "romfile.h" // romfile_loadint #include "stacks.h" // farcall16big #include "std/optionrom.h" // struct rom_header +#include "std/pnpbios.h" // PNP_SIGNATURE #include "string.h" // memset #include "util.h" // get_pnp_offset
diff --git a/src/pnpbios.c b/src/pnpbios.c index 87eea9f..95ce21f 100644 --- a/src/pnpbios.c +++ b/src/pnpbios.c @@ -7,25 +7,10 @@ #include "config.h" // BUILD_BIOS_ADDR #include "farptr.h" // SET_FARVAR #include "output.h" // dprintf +#include "std/pnpbios.h" // PNP_SIGNATURE #include "string.h" // checksum #include "util.h" // pnp_init
-struct pnpheader { - u32 signature; - u8 version; - u8 length; - u16 control; - u8 checksum; - u32 eventloc; - u16 real_ip; - u16 real_cs; - u16 prot_ip; - u32 prot_base; - u32 oemid; - u16 real_ds; - u32 prot_database; -} PACKED; - extern struct pnpheader PNPHEADER; extern char pnp_string[];
@@ -46,8 +31,6 @@ struct pnpheader PNPHEADER __aligned(16) VARFSEG = { char pnp_string[] __aligned(2) VARFSEG = " $PnP"; #endif
-#define FUNCTION_NOT_SUPPORTED 0x82 - // BBS - Get Version and Installation Check static u16 handle_pnp60(u16 *args) diff --git a/src/std/pnpbios.h b/src/std/pnpbios.h new file mode 100644 index 0000000..0871e3a --- /dev/null +++ b/src/std/pnpbios.h @@ -0,0 +1,24 @@ +#ifndef __PNPHEADER_H +#define __PNPHEADER_H + +#define PNP_SIGNATURE 0x506e5024 // $PnP + +struct pnpheader { + u32 signature; + u8 version; + u8 length; + u16 control; + u8 checksum; + u32 eventloc; + u16 real_ip; + u16 real_cs; + u16 prot_ip; + u32 prot_base; + u32 oemid; + u16 real_ds; + u32 prot_database; +} PACKED; + +#define FUNCTION_NOT_SUPPORTED 0x82 + +#endif // pnpheader.h diff --git a/src/util.h b/src/util.h index 95be57f..333d116 100644 --- a/src/util.h +++ b/src/util.h @@ -139,7 +139,6 @@ extern int HaveRunPost; void dma_setup(void);
// pnpbios.c -#define PNP_SIGNATURE 0x506e5024 // $PnP u16 get_pnp_offset(void); void pnp_init(void);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/pmm.c | 14 +------------- src/std/pmm.h | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 src/std/pmm.h
diff --git a/src/pmm.c b/src/pmm.c index cce0f29..be03bdb 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -8,23 +8,13 @@ #include "config.h" // CONFIG_* #include "malloc.h" // _malloc #include "output.h" // dprintf +#include "std/pmm.h" // PMM_SIGNATURE #include "string.h" // checksum #include "util.h" // pmm_init #include "x86.h" // __ffs
-struct pmmheader { - u32 signature; - u8 version; - u8 length; - u8 checksum; - struct segoff_s entry; - u8 reserved[5]; -} PACKED; - extern struct pmmheader PMMHEADER;
-#define PMM_SIGNATURE 0x4d4d5024 // $PMM - #if CONFIG_PMM struct pmmheader PMMHEADER __aligned(16) VARFSEG = { .signature = PMM_SIGNATURE, @@ -33,8 +23,6 @@ struct pmmheader PMMHEADER __aligned(16) VARFSEG = { }; #endif
-#define PMM_FUNCTION_NOT_SUPPORTED 0xffffffff - // PMM - allocate static u32 handle_pmm00(u16 *args) diff --git a/src/std/pmm.h b/src/std/pmm.h new file mode 100644 index 0000000..80027f3 --- /dev/null +++ b/src/std/pmm.h @@ -0,0 +1,19 @@ +#ifndef __PMM_H +#define __PMM_H + +#include "types.h" // u32 + +#define PMM_SIGNATURE 0x4d4d5024 // $PMM + +struct pmmheader { + u32 signature; + u8 version; + u8 length; + u8 checksum; + struct segoff_s entry; + u8 reserved[5]; +} PACKED; + +#define PMM_FUNCTION_NOT_SUPPORTED 0xffffffff + +#endif // pmm.h
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/block.c | 35 ++++++- src/block.h | 129 +++++++++++++++++++++++ src/boot.c | 3 +- src/cdrom.c | 19 +--- src/clock.c | 1 - src/disk.c | 28 +---- src/disk.h | 290 --------------------------------------------------- src/fw/coreboot.c | 2 +- src/hw/ahci.c | 2 +- src/hw/ahci.h | 2 +- src/hw/ata.c | 3 +- src/hw/ata.h | 4 +- src/hw/blockcmd.c | 3 +- src/hw/esp-scsi.c | 3 +- src/hw/floppy.c | 3 +- src/hw/lsi-scsi.c | 3 +- src/hw/megasas.c | 3 +- src/hw/ramdisk.c | 4 +- src/hw/usb-msc.c | 3 +- src/hw/usb-uas.c | 3 +- src/hw/virtio-blk.c | 3 +- src/hw/virtio-scsi.c | 3 +- src/post.c | 1 - src/std/disk.h | 161 ++++++++++++++++++++++++++++ src/util.h | 22 ++++ 25 files changed, 381 insertions(+), 352 deletions(-) create mode 100644 src/block.h delete mode 100644 src/disk.h create mode 100644 src/std/disk.h
diff --git a/src/block.c b/src/block.c index 73d6068..4560b24 100644 --- a/src/block.c +++ b/src/block.c @@ -6,7 +6,8 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL -#include "disk.h" // struct ata_s +#include "block.h" // process_op +#include "bregs.h" // struct bregs #include "hw/ata.h" // process_ata_op #include "hw/ahci.h" // process_ahci_op #include "hw/cmos.h" // inb_cmos @@ -15,7 +16,9 @@ #include "malloc.h" // malloc_low #include "output.h" // dprintf #include "stacks.h" // stack_hop +#include "std/disk.h" // struct dpte_s #include "string.h" // checksum +#include "util.h" // process_floppy_op
u8 FloppyCount VARFSEG; u8 CDCount; @@ -277,6 +280,36 @@ map_floppy_drive(struct drive_s *drive_g)
/**************************************************************** + * Return status functions + ****************************************************************/ + +void +__disk_ret(struct bregs *regs, u32 linecode, const char *fname) +{ + u8 code = linecode; + if (regs->dl < EXTSTART_HD) + SET_BDA(floppy_last_status, code); + else + SET_BDA(disk_last_status, code); + if (code) + __set_code_invalid(regs, linecode, fname); + else + set_code_success(regs); +} + +void +__disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname) +{ + u8 code = linecode; + if (regs->dl < EXTSTART_HD) + SET_BDA(floppy_last_status, code); + else + SET_BDA(disk_last_status, code); + __set_code_unimplemented(regs, linecode, fname); +} + + +/**************************************************************** * 16bit calling interface ****************************************************************/
diff --git a/src/block.h b/src/block.h new file mode 100644 index 0000000..3492806 --- /dev/null +++ b/src/block.h @@ -0,0 +1,129 @@ +#ifndef __BLOCK_H +#define __BLOCK_H + +#include "types.h" // u32 + + +/**************************************************************** + * Disk command request + ****************************************************************/ + +struct disk_op_s { + u64 lba; + void *buf_fl; + struct drive_s *drive_g; + u16 count; + u8 command; +}; + +#define CMD_RESET 0x00 +#define CMD_READ 0x02 +#define CMD_WRITE 0x03 +#define CMD_VERIFY 0x04 +#define CMD_FORMAT 0x05 +#define CMD_SEEK 0x07 +#define CMD_ISREADY 0x10 + + +/**************************************************************** + * Global storage + ****************************************************************/ + +struct chs_s { + u16 heads; // # heads + u16 cylinders; // # cylinders + u16 spt; // # sectors / track + u16 pad; +}; + +// ElTorito Device Emulation data +struct cdemu_s { + struct drive_s *emulated_drive_gf; + u32 ilba; + u16 buffer_segment; + u16 load_segment; + u16 sector_count; + u8 active; + u8 media; + u8 emulated_extdrive; + + // Virtual device + struct chs_s lchs; +}; + +struct drive_s { + u8 type; // Driver type (DTYPE_*) + u8 floppy_type; // Type of floppy (only for floppy drives). + struct chs_s lchs; // Logical CHS + u64 sectors; // Total sectors count + u32 cntl_id; // Unique id for a given driver type. + u8 removable; // Is media removable (currently unused) + + // Info for EDD calls + u8 translation; // type of translation + u16 blksize; // block size + struct chs_s pchs; // Physical CHS +}; + +#define DISK_SECTOR_SIZE 512 +#define CDROM_SECTOR_SIZE 2048 + +#define DTYPE_NONE 0x00 +#define DTYPE_FLOPPY 0x01 +#define DTYPE_ATA 0x02 +#define DTYPE_ATA_ATAPI 0x03 +#define DTYPE_RAMDISK 0x04 +#define DTYPE_CDEMU 0x05 +#define DTYPE_AHCI 0x06 +#define DTYPE_AHCI_ATAPI 0x07 +#define DTYPE_VIRTIO_SCSI 0x08 +#define DTYPE_VIRTIO_BLK 0x09 +#define DTYPE_USB 0x0a +#define DTYPE_UAS 0x0b +#define DTYPE_LSI_SCSI 0x0c +#define DTYPE_ESP_SCSI 0x0d +#define DTYPE_MEGASAS 0x0e + +#define MAXDESCSIZE 80 + +#define TRANSLATION_NONE 0 +#define TRANSLATION_LBA 1 +#define TRANSLATION_LARGE 2 +#define TRANSLATION_RECHS 3 + +#define EXTTYPE_FLOPPY 0 +#define EXTTYPE_HD 1 +#define EXTTYPE_CD 2 + +#define EXTSTART_HD 0x80 +#define EXTSTART_CD 0xE0 + + +/**************************************************************** + * Function defs + ****************************************************************/ + +// block.c +extern struct dpte_s DefaultDPTE; +extern u8 FloppyCount, CDCount; +extern u8 *bounce_buf_fl; +struct drive_s *getDrive(u8 exttype, u8 extdriveoffset); +int getDriveId(u8 exttype, struct drive_s *drive_g); +void map_floppy_drive(struct drive_s *drive_g); +void map_hd_drive(struct drive_s *drive_g); +void map_cd_drive(struct drive_s *drive_g); +struct bregs; +void __disk_ret(struct bregs *regs, u32 linecode, const char *fname); +void __disk_ret_unimplemented(struct bregs *regs, u32 linecode + , const char *fname); +int process_op(struct disk_op_s *op); +int send_disk_op(struct disk_op_s *op); +int create_bounce_buf(void); + +// Helper function for setting up a return code. +#define disk_ret(regs, code) \ + __disk_ret((regs), (code) | (__LINE__ << 8), __func__) +#define disk_ret_unimplemented(regs, code) \ + __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__) + +#endif // block.h diff --git a/src/boot.c b/src/boot.c index fbfbf34..70888e2 100644 --- a/src/boot.c +++ b/src/boot.c @@ -6,9 +6,9 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "boot.h" // boot_init +#include "block.h" // struct drive_s #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "disk.h" // cdrom_boot #include "fw/paravirt.h" // qemu_cfg_show_boot_menu #include "hw/cmos.h" // inb_cmos #include "hw/pci.h" // pci_bdf_to_* @@ -17,6 +17,7 @@ #include "malloc.h" // free #include "output.h" // dprintf #include "romfile.h" // romfile_loadint +#include "std/disk.h" // struct mbr_s #include "string.h" // memset #include "util.h" // irqtimer_calc
diff --git a/src/cdrom.c b/src/cdrom.c index c499cf9..827ffdb 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -6,13 +6,15 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "bregs.h" // struct bregs -#include "disk.h" // cdrom_13 #include "hw/ata.h" // ATA_CMD_REQUEST_SENSE #include "hw/blockcmd.h" // CDB_CMD_REQUEST_SENSE #include "malloc.h" // free #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset +#include "util.h" // cdrom_prepboot
// Locks for removable devices u8 CDRom_locks[BUILD_MAX_EXTDRIVE] VARLOW; @@ -131,21 +133,6 @@ cdrom_prepboot(void) drive_g->sectors = (u64)-1; }
-struct eltorito_s { - u8 size; - u8 media; - u8 emulated_drive; - u8 controller_index; - u32 ilba; - u16 device_spec; - u16 buffer_segment; - u16 load_segment; - u16 sector_count; - u8 cylinders; - u8 sectors; - u8 heads; -}; - #define SET_INT13ET(regs,var,val) \ SET_FARVAR((regs)->ds, ((struct eltorito_s*)((regs)->si+0))->var, (val))
diff --git a/src/clock.c b/src/clock.c index d7de59e..7e24626 100644 --- a/src/clock.c +++ b/src/clock.c @@ -7,7 +7,6 @@
#include "biosvar.h" // SET_BDA #include "bregs.h" // struct bregs -#include "disk.h" // floppy_tick #include "hw/cmos.h" // inb_cmos #include "hw/pic.h" // pic_eoi1 #include "hw/pit.h" // PM_SEL_TIMER0 diff --git a/src/disk.c b/src/disk.c index b149b6d..8a5ce0c 100644 --- a/src/disk.c +++ b/src/disk.c @@ -8,44 +8,20 @@ #include "biosvar.h" // SET_BDA #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "disk.h" // floppy_13 #include "hw/ata.h" // ATA_CB_DC #include "hw/pci.h" // pci_bdf_to_bus #include "hw/pic.h" // pic_eoi2 #include "output.h" // debug_enter #include "stacks.h" // call16_int +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset +#include "util.h" // CDRom_locks
/**************************************************************** * Helper functions ****************************************************************/
-void -__disk_ret(struct bregs *regs, u32 linecode, const char *fname) -{ - u8 code = linecode; - if (regs->dl < EXTSTART_HD) - SET_BDA(floppy_last_status, code); - else - SET_BDA(disk_last_status, code); - if (code) - __set_code_invalid(regs, linecode, fname); - else - set_code_success(regs); -} - -void -__disk_ret_unimplemented(struct bregs *regs, u32 linecode, const char *fname) -{ - u8 code = linecode; - if (regs->dl < EXTSTART_HD) - SET_BDA(floppy_last_status, code); - else - SET_BDA(disk_last_status, code); - __set_code_unimplemented(regs, linecode, fname); -} - static void __disk_stub(struct bregs *regs, int lineno, const char *fname) { diff --git a/src/disk.h b/src/disk.h deleted file mode 100644 index 48496da..0000000 --- a/src/disk.h +++ /dev/null @@ -1,290 +0,0 @@ -// Definitions for X86 bios disks. -// -// Copyright (C) 2008 Kevin O'Connor kevin@koconnor.net -// -// This file may be distributed under the terms of the GNU LGPLv3 license. -#ifndef __DISK_H -#define __DISK_H - -#include "types.h" // u8 - -#define DISK_RET_SUCCESS 0x00 -#define DISK_RET_EPARAM 0x01 -#define DISK_RET_EADDRNOTFOUND 0x02 -#define DISK_RET_EWRITEPROTECT 0x03 -#define DISK_RET_ECHANGED 0x06 -#define DISK_RET_EBOUNDARY 0x09 -#define DISK_RET_EBADTRACK 0x0c -#define DISK_RET_ECONTROLLER 0x20 -#define DISK_RET_ETIMEOUT 0x80 -#define DISK_RET_ENOTLOCKED 0xb0 -#define DISK_RET_ELOCKED 0xb1 -#define DISK_RET_ENOTREMOVABLE 0xb2 -#define DISK_RET_ETOOMANYLOCKS 0xb4 -#define DISK_RET_EMEDIA 0xC0 -#define DISK_RET_ENOTREADY 0xAA - - -/**************************************************************** - * Interface structs - ****************************************************************/ - -// Bios disk structures. -struct int13ext_s { - u8 size; - u8 reserved; - u16 count; - struct segoff_s data; - u64 lba; -} PACKED; - -// DPTE definition -struct dpte_s { - u16 iobase1; - u16 iobase2; - u8 prefix; - u8 unused; - u8 irq; - u8 blkcount; - u8 dma; - u8 pio; - u16 options; - u16 reserved; - u8 revision; - u8 checksum; -}; - -extern struct dpte_s DefaultDPTE; - -// Disk Physical Table definition -struct int13dpt_s { - u16 size; - u16 infos; - u32 cylinders; - u32 heads; - u32 spt; - u64 sector_count; - u16 blksize; - struct segoff_s dpte; - u16 key; - u8 dpi_length; - u8 reserved1; - u16 reserved2; - u8 host_bus[4]; - u8 iface_type[8]; - u64 iface_path; - union { - struct { - u64 device_path; - u8 reserved3; - u8 checksum; - } phoenix; - struct { - u64 device_path[2]; - u8 reserved3; - u8 checksum; - } t13; - }; -} PACKED; - -// Floppy "Disk Base Table" -struct floppy_dbt_s { - u8 specify1; - u8 specify2; - u8 shutoff_ticks; - u8 bps_code; - u8 sectors; - u8 interblock_len; - u8 data_len; - u8 gap_len; - u8 fill_byte; - u8 settle_time; - u8 startup_time; -} PACKED; - -struct floppy_ext_dbt_s { - struct floppy_dbt_s dbt; - // Extra fields - u8 max_track; - u8 data_rate; - u8 drive_type; -} PACKED; - -// Helper function for setting up a return code. -struct bregs; -void __disk_ret(struct bregs *regs, u32 linecode, const char *fname); -#define disk_ret(regs, code) \ - __disk_ret((regs), (code) | (__LINE__ << 8), __func__) -void __disk_ret_unimplemented(struct bregs *regs, u32 linecode - , const char *fname); -#define disk_ret_unimplemented(regs, code) \ - __disk_ret_unimplemented((regs), (code) | (__LINE__ << 8), __func__) - - -/**************************************************************** - * Master boot record - ****************************************************************/ - -struct packed_chs_s { - u8 heads; - u8 sptcyl; - u8 cyllow; -}; - -struct partition_s { - u8 status; - struct packed_chs_s first; - u8 type; - struct packed_chs_s last; - u32 lba; - u32 count; -} PACKED; - -struct mbr_s { - u8 code[440]; - // 0x01b8 - u32 diskseg; - // 0x01bc - u16 null; - // 0x01be - struct partition_s partitions[4]; - // 0x01fe - u16 signature; -} PACKED; - -#define MBR_SIGNATURE 0xaa55 - - -/**************************************************************** - * Disk command request - ****************************************************************/ - -struct disk_op_s { - u64 lba; - void *buf_fl; - struct drive_s *drive_g; - u16 count; - u8 command; -}; - -#define CMD_RESET 0x00 -#define CMD_READ 0x02 -#define CMD_WRITE 0x03 -#define CMD_VERIFY 0x04 -#define CMD_FORMAT 0x05 -#define CMD_SEEK 0x07 -#define CMD_ISREADY 0x10 - - -/**************************************************************** - * Global storage - ****************************************************************/ - -struct chs_s { - u16 heads; // # heads - u16 cylinders; // # cylinders - u16 spt; // # sectors / track - u16 pad; -}; - -// ElTorito Device Emulation data -struct cdemu_s { - struct drive_s *emulated_drive_gf; - u32 ilba; - u16 buffer_segment; - u16 load_segment; - u16 sector_count; - u8 active; - u8 media; - u8 emulated_extdrive; - - // Virtual device - struct chs_s lchs; -}; - -struct drive_s { - u8 type; // Driver type (DTYPE_*) - u8 floppy_type; // Type of floppy (only for floppy drives). - struct chs_s lchs; // Logical CHS - u64 sectors; // Total sectors count - u32 cntl_id; // Unique id for a given driver type. - u8 removable; // Is media removable (currently unused) - - // Info for EDD calls - u8 translation; // type of translation - u16 blksize; // block size - struct chs_s pchs; // Physical CHS -}; - -#define DISK_SECTOR_SIZE 512 -#define CDROM_SECTOR_SIZE 2048 - -#define DTYPE_NONE 0x00 -#define DTYPE_FLOPPY 0x01 -#define DTYPE_ATA 0x02 -#define DTYPE_ATA_ATAPI 0x03 -#define DTYPE_RAMDISK 0x04 -#define DTYPE_CDEMU 0x05 -#define DTYPE_AHCI 0x06 -#define DTYPE_AHCI_ATAPI 0x07 -#define DTYPE_VIRTIO_SCSI 0x08 -#define DTYPE_VIRTIO_BLK 0x09 -#define DTYPE_USB 0x0a -#define DTYPE_UAS 0x0b -#define DTYPE_LSI_SCSI 0x0c -#define DTYPE_ESP_SCSI 0x0d -#define DTYPE_MEGASAS 0x0e - -#define MAXDESCSIZE 80 - -#define TRANSLATION_NONE 0 -#define TRANSLATION_LBA 1 -#define TRANSLATION_LARGE 2 -#define TRANSLATION_RECHS 3 - -#define EXTTYPE_FLOPPY 0 -#define EXTTYPE_HD 1 -#define EXTTYPE_CD 2 - -#define EXTSTART_HD 0x80 -#define EXTSTART_CD 0xE0 - - -/**************************************************************** - * Function defs - ****************************************************************/ - -// block.c -extern u8 FloppyCount, CDCount; -extern u8 *bounce_buf_fl; -struct drive_s *getDrive(u8 exttype, u8 extdriveoffset); -int getDriveId(u8 exttype, struct drive_s *drive_g); -void map_floppy_drive(struct drive_s *drive_g); -void map_hd_drive(struct drive_s *drive_g); -void map_cd_drive(struct drive_s *drive_g); -int process_op(struct disk_op_s *op); -int send_disk_op(struct disk_op_s *op); -int create_bounce_buf(void); - -// floppy.c -extern struct floppy_ext_dbt_s diskette_param_table2; -void floppy_setup(void); -struct drive_s *init_floppy(int floppyid, int ftype); -int find_floppy_type(u32 size); -int process_floppy_op(struct disk_op_s *op); -void floppy_tick(void); - -// cdrom.c -extern u8 CDRom_locks[]; -extern struct cdemu_s CDEmu; -extern struct drive_s *cdemu_drive_gf; -int process_cdemu_op(struct disk_op_s *op); -void cdrom_prepboot(void); -void cdemu_134b(struct bregs *regs); -int cdrom_boot(struct drive_s *drive_g); - -// ramdisk.c -void ramdisk_setup(void); -int process_ramdisk_op(struct disk_op_s *op); - -#endif // disk.h diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index e9874e2..7d877eb 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -4,10 +4,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
+#include "block.h" // MAXDESCSIZE #include "boot.h" // boot_add_cbfs #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_* -#include "disk.h" // MAXDESCSIZE #include "hw/pci.h" // pci_probe_devices #include "lzmadecode.h" // LzmaDecode #include "malloc.h" // free diff --git a/src/hw/ahci.c b/src/hw/ahci.c index bf70e23..6bf0bf0 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -9,7 +9,6 @@ #include "biosvar.h" // GET_GLOBAL #include "blockcmd.h" // CDB_CMD_READ_10 #include "boot.h" // add_bcv_hd -#include "disk.h" // struct drive_s #include "ioport.h" // inb #include "malloc.h" // free #include "output.h" // dprintf @@ -17,6 +16,7 @@ #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/ahci.h b/src/hw/ahci.h index c3d2402..c8c755a 100644 --- a/src/hw/ahci.h +++ b/src/hw/ahci.h @@ -1,8 +1,8 @@ #ifndef __AHCI_H #define __AHCI_H
+#include "block.h" // struct drive_s #include "types.h" // u32 -#include "disk.h" // struct drive_s
struct sata_cmd_fis { u8 reg; diff --git a/src/hw/ata.c b/src/hw/ata.c index 7338ebf..4ea6cd1 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -7,11 +7,11 @@
#include "ata.h" // ATA_CB_STAT #include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // CDB_CMD_READ_10 #include "boot.h" // boot_add_hd #include "byteorder.h" // be16_to_cpu #include "cmos.h" // inb_cmos -#include "disk.h" // struct ata_s #include "ioport.h" // inb #include "malloc.h" // malloc_fseg #include "output.h" // dprintf @@ -20,6 +20,7 @@ #include "pci_regs.h" // PCI_INTERRUPT_LINE #include "pic.h" // enable_hwirq #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/ata.h b/src/hw/ata.h index 1f41233..a9f865e 100644 --- a/src/hw/ata.h +++ b/src/hw/ata.h @@ -1,9 +1,9 @@ #ifndef __ATA_H #define __ATA_H
-#include "types.h" // u8 +#include "block.h" // struct drive_s #include "config.h" // CONFIG_MAX_ATA_INTERFACES -#include "disk.h" // struct drive_s +#include "types.h" // u8
struct ata_channel_s { u16 iobase1; diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 59f5763..b9e61cd 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -8,14 +8,15 @@ #include "ahci.h" // atapi_cmd_data #include "ata.h" // atapi_cmd_data #include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense #include "boot.h" // boot_add_hd #include "byteorder.h" // be32_to_cpu -#include "disk.h" // struct disk_op_s #include "esp-scsi.h" // esp_scsi_cmd_data #include "lsi-scsi.h" // lsi_scsi_cmd_data #include "megasas.h" // megasas_cmd_data #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_EPARAM #include "string.h" // memset #include "usb-msc.h" // usb_cmd_data #include "usb-uas.h" // usb_cmd_data diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index 65a67cd..e6533af 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -11,16 +11,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep
diff --git a/src/hw/floppy.c b/src/hw/floppy.c index e2db2f8..05c518f 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -6,11 +6,11 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // SET_BDA +#include "block.h" // struct drive_s #include "boot.h" // boot_add_floppy #include "bregs.h" // struct bregs #include "cmos.h" // inb_cmos #include "config.h" // CONFIG_FLOPPY -#include "disk.h" // DISK_RET_SUCCESS #include "malloc.h" // malloc_fseg #include "output.h" // dprintf #include "pci.h" // pci_to_bdf @@ -18,6 +18,7 @@ #include "pic.h" // pic_eoi1 #include "romfile.h" // romfile_loadint #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index 87751aa..b7eb1f1 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -11,16 +11,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep
diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 4bba0e1..772fc75 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -11,16 +11,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_XXX #include "pci_regs.h" // PCI_VENDOR_ID #include "stacks.h" // yield +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // timer_calc
diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index 2599f9a..f57affd 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -5,15 +5,17 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "boot.h" // boot_add_floppy #include "bregs.h" // struct bregs -#include "disk.h" // process_ramdisk_op #include "malloc.h" // malloc_fseg #include "memmap.h" // add_e820 #include "output.h" // dprintf #include "romfile.h" // romfile_findprefix #include "stacks.h" // call16_int +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset +#include "util.h" // process_ramdisk_op
void ramdisk_setup(void) diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index ee1fe20..975ec7a 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -5,12 +5,13 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // DTYPE_USB #include "blockcmd.h" // cdb_read #include "boot.h" // bootprio_find_usb #include "config.h" // CONFIG_USB_MSC -#include "disk.h" // DTYPE_USB #include "malloc.h" // free #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "usb.h" // struct usb_s #include "usb-msc.h" // usb_msc_setup diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 6925f33..9f4b558 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -15,12 +15,13 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // DTYPE_USB #include "blockcmd.h" // cdb_read #include "boot.h" // bootprio_find_usb #include "config.h" // CONFIG_USB_UAS -#include "disk.h" // DTYPE_UAS #include "malloc.h" // free #include "output.h" // dprintf +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "usb.h" // struct usb_s #include "usb-uas.h" // usb_uas_init diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index 07f6e57..c48ea45 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -10,12 +10,13 @@ #include "biosvar.h" // GET_GLOBAL #include "boot.h" // boot_add_hd #include "config.h" // CONFIG_* -#include "disk.h" +#include "block.h" // struct drive_s #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep #include "virtio-pci.h" diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index 1c3500c..f50e335 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -8,15 +8,16 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL +#include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup #include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* -#include "disk.h" #include "malloc.h" // free #include "output.h" // dprintf #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_DEVICE_ID_VIRTIO_BLK #include "pci_regs.h" // PCI_VENDOR_ID +#include "std/disk.h" // DISK_RET_SUCCESS #include "string.h" // memset #include "util.h" // usleep #include "virtio-pci.h" diff --git a/src/post.c b/src/post.c index e84dcae..5514120 100644 --- a/src/post.c +++ b/src/post.c @@ -9,7 +9,6 @@ #include "boot.h" // boot_init #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* -#include "disk.h" // floppy_setup #include "fw/paravirt.h" // qemu_cfg_preinit #include "fw/xen.h" // xen_preinit #include "hw/ahci.h" // ahci_setup diff --git a/src/std/disk.h b/src/std/disk.h new file mode 100644 index 0000000..c111e07 --- /dev/null +++ b/src/std/disk.h @@ -0,0 +1,161 @@ +// Standard disk BIOS definitions. +#ifndef __DISK_H +#define __DISK_H + +#include "types.h" // u8 + +#define DISK_RET_SUCCESS 0x00 +#define DISK_RET_EPARAM 0x01 +#define DISK_RET_EADDRNOTFOUND 0x02 +#define DISK_RET_EWRITEPROTECT 0x03 +#define DISK_RET_ECHANGED 0x06 +#define DISK_RET_EBOUNDARY 0x09 +#define DISK_RET_EBADTRACK 0x0c +#define DISK_RET_ECONTROLLER 0x20 +#define DISK_RET_ETIMEOUT 0x80 +#define DISK_RET_ENOTLOCKED 0xb0 +#define DISK_RET_ELOCKED 0xb1 +#define DISK_RET_ENOTREMOVABLE 0xb2 +#define DISK_RET_ETOOMANYLOCKS 0xb4 +#define DISK_RET_EMEDIA 0xC0 +#define DISK_RET_ENOTREADY 0xAA + + +/**************************************************************** + * Interface structs + ****************************************************************/ + +// Bios disk structures. +struct int13ext_s { + u8 size; + u8 reserved; + u16 count; + struct segoff_s data; + u64 lba; +} PACKED; + +// DPTE definition +struct dpte_s { + u16 iobase1; + u16 iobase2; + u8 prefix; + u8 unused; + u8 irq; + u8 blkcount; + u8 dma; + u8 pio; + u16 options; + u16 reserved; + u8 revision; + u8 checksum; +}; + +// Disk Physical Table definition +struct int13dpt_s { + u16 size; + u16 infos; + u32 cylinders; + u32 heads; + u32 spt; + u64 sector_count; + u16 blksize; + struct segoff_s dpte; + u16 key; + u8 dpi_length; + u8 reserved1; + u16 reserved2; + u8 host_bus[4]; + u8 iface_type[8]; + u64 iface_path; + union { + struct { + u64 device_path; + u8 reserved3; + u8 checksum; + } phoenix; + struct { + u64 device_path[2]; + u8 reserved3; + u8 checksum; + } t13; + }; +} PACKED; + +// Floppy "Disk Base Table" +struct floppy_dbt_s { + u8 specify1; + u8 specify2; + u8 shutoff_ticks; + u8 bps_code; + u8 sectors; + u8 interblock_len; + u8 data_len; + u8 gap_len; + u8 fill_byte; + u8 settle_time; + u8 startup_time; +} PACKED; + +struct floppy_ext_dbt_s { + struct floppy_dbt_s dbt; + // Extra fields + u8 max_track; + u8 data_rate; + u8 drive_type; +} PACKED; + + +/**************************************************************** + * Master boot record + ****************************************************************/ + +struct packed_chs_s { + u8 heads; + u8 sptcyl; + u8 cyllow; +}; + +struct partition_s { + u8 status; + struct packed_chs_s first; + u8 type; + struct packed_chs_s last; + u32 lba; + u32 count; +} PACKED; + +struct mbr_s { + u8 code[440]; + // 0x01b8 + u32 diskseg; + // 0x01bc + u16 null; + // 0x01be + struct partition_s partitions[4]; + // 0x01fe + u16 signature; +} PACKED; + +#define MBR_SIGNATURE 0xaa55 + + +/**************************************************************** + * ElTorito CDROM interface + ****************************************************************/ + +struct eltorito_s { + u8 size; + u8 media; + u8 emulated_drive; + u8 controller_index; + u32 ilba; + u16 device_spec; + u16 buffer_segment; + u16 load_segment; + u16 sector_count; + u8 cylinders; + u8 sectors; + u8 heads; +}; + +#endif // disk.h diff --git a/src/util.h b/src/util.h index 333d116..6d8c0d2 100644 --- a/src/util.h +++ b/src/util.h @@ -18,6 +18,16 @@ void process_mouse(u8 data); void serial_setup(void); void lpt_setup(void);
+// cdrom.c +extern u8 CDRom_locks[]; +extern struct cdemu_s CDEmu; +extern struct drive_s *cdemu_drive_gf; +struct disk_op_s; +int process_cdemu_op(struct disk_op_s *op); +void cdrom_prepboot(void); +void cdemu_134b(struct bregs *regs); +int cdrom_boot(struct drive_s *drive_g); + // clock.c void clock_setup(void); void handle_1583(struct bregs *regs); @@ -25,6 +35,18 @@ void handle_1586(struct bregs *regs); void useRTC(void); void releaseRTC(void);
+// hw/floppy.c +extern struct floppy_ext_dbt_s diskette_param_table2; +void floppy_setup(void); +struct drive_s *init_floppy(int floppyid, int ftype); +int find_floppy_type(u32 size); +int process_floppy_op(struct disk_op_s *op); +void floppy_tick(void); + +// hw/ramdisk.c +void ramdisk_setup(void); +int process_ramdisk_op(struct disk_op_s *op); + // hw/timer.c void timer_setup(void); void pmtimer_setup(u16 ioport);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/biosvar.h | 161 ++------------------------------------------------------- src/fw/csm.c | 3 +- src/post.c | 2 +- src/resume.c | 4 +- src/std/bda.h | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/std/disk.h | 16 ++++++ src/system.c | 2 +- src/util.h | 3 +- 8 files changed, 188 insertions(+), 162 deletions(-) create mode 100644 src/std/bda.h
diff --git a/src/biosvar.h b/src/biosvar.h index e49a10a..051cd1e 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -1,24 +1,20 @@ -// Variable layouts of bios. +// Memory access to BIOS variables. // -// Copyright (C) 2008-2010 Kevin O'Connor kevin@koconnor.net +// Copyright (C) 2008-2013 Kevin O'Connor kevin@koconnor.net // // This file may be distributed under the terms of the GNU LGPLv3 license. #ifndef __BIOSVAR_H #define __BIOSVAR_H
-#include "types.h" // u8 -#include "farptr.h" // GET_FARVAR #include "config.h" // SEG_BDA +#include "farptr.h" // GET_FARVAR +#include "std/bda.h" // struct bios_data_area_s
/**************************************************************** * Interupt vector table ****************************************************************/
-struct rmode_IVT { - struct segoff_s ivec[256]; -}; - #define GET_IVT(vector) \ GET_FARVAR(SEG_IVT, ((struct rmode_IVT *)0)->ivec[vector]) #define SET_IVT(vector, segoff) \ @@ -35,106 +31,6 @@ struct rmode_IVT { * Bios Data Area (BDA) ****************************************************************/
-struct bios_data_area_s { - // 40:00 - u16 port_com[4]; - u16 port_lpt[3]; - u16 ebda_seg; - // 40:10 - u16 equipment_list_flags; - u8 pad1; - u16 mem_size_kb; - u8 pad2; - u8 ps2_ctrl_flag; - u8 kbd_flag0; - u8 kbd_flag1; - u8 alt_keypad; - u16 kbd_buf_head; - u16 kbd_buf_tail; - // 40:1e - u8 kbd_buf[32]; - u8 floppy_recalibration_status; - u8 floppy_motor_status; - // 40:40 - u8 floppy_motor_counter; - u8 floppy_last_status; - u8 floppy_return_status[7]; - u8 video_mode; - u16 video_cols; - u16 video_pagesize; - u16 video_pagestart; - // 40:50 - u16 cursor_pos[8]; - // 40:60 - u16 cursor_type; - u8 video_page; - u16 crtc_address; - u8 video_msr; - u8 video_pal; - struct segoff_s jump; - u8 other_6b; - u32 timer_counter; - // 40:70 - u8 timer_rollover; - u8 break_flag; - u16 soft_reset_flag; - u8 disk_last_status; - u8 hdcount; - u8 disk_control_byte; - u8 port_disk; - u8 lpt_timeout[4]; - u8 com_timeout[4]; - // 40:80 - u16 kbd_buf_start_offset; - u16 kbd_buf_end_offset; - u8 video_rows; - u16 char_height; - u8 video_ctl; - u8 video_switches; - u8 modeset_ctl; - u8 dcc_index; - u8 floppy_last_data_rate; - u8 disk_status_controller; - u8 disk_error_controller; - u8 disk_interrupt_flag; - u8 floppy_harddisk_info; - // 40:90 - u8 floppy_media_state[4]; - u8 floppy_track[2]; - u8 kbd_flag2; - u8 kbd_led; - struct segoff_s user_wait_complete_flag; - u32 user_wait_timeout; - // 40:A0 - u8 rtc_wait_flag; - u8 other_a1[7]; - struct segoff_s video_savetable; - u8 other_ac[4]; - // 40:B0 - u8 other_b0[9]; - u8 vbe_flag; - u16 vbe_mode; - u8 other_bc[4]; - // 40:C0 - u8 other_c0[4*16]; -} PACKED; - -// BDA floppy_recalibration_status bitdefs -#define FRS_IRQ (1<<7) - -// BDA rtc_wait_flag bitdefs -#define RWS_WAIT_PENDING (1<<0) -#define RWS_WAIT_ELAPSED (1<<7) - -// BDA floppy_media_state bitdefs -#define FMS_DRIVE_STATE_MASK (0x07) -#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4) -#define FMS_DOUBLE_STEPPING (1<<5) -#define FMS_DATA_RATE_MASK (0xc0) - -// Limit of BDA timer_counter field -#define TICKS_PER_DAY 1573040 - // Accessor functions #define GET_BDA(var) \ GET_FARVAR(SEG_BDA, ((struct bios_data_area_s *)0)->var) @@ -152,40 +48,6 @@ static inline void set_equipment_flags(u16 clear, u16 set) { * Extended Bios Data Area (EBDA) ****************************************************************/
-struct fdpt_s { - u16 cylinders; - u8 heads; - u8 a0h_signature; - u8 phys_sectors; - u16 precompensation; - u8 reserved; - u8 drive_control_byte; - u16 phys_cylinders; - u8 phys_heads; - u16 landing_zone; - u8 sectors; - u8 checksum; -} PACKED; - -struct extended_bios_data_area_s { - u8 size; - u8 reserved1[0x21]; - struct segoff_s far_call_pointer; - u8 mouse_flag1; - u8 mouse_flag2; - u8 mouse_data[0x08]; - // 0x30 - u8 other1[0x0d]; - - // 0x3d - struct fdpt_s fdpt[2]; - - // 0x5d - u8 other2[0xC4]; - - // 0x121 - Begin custom storage. -} PACKED; - // The initial size and location of EBDA #define EBDA_SIZE_START \ DIV_ROUND_UP(sizeof(struct extended_bios_data_area_s), 1024) @@ -269,19 +131,4 @@ extern u8 _zonelow_seg, zonelow_base[]; #define GET_LOWFLAT(var) GET_LOW(*LOWFLAT2LOW(&(var))) #define SET_LOWFLAT(var, val) SET_LOW(*LOWFLAT2LOW(&(var)), (val))
- -/**************************************************************** - * Bios Config Table - ****************************************************************/ - -struct bios_config_table_s { - u16 size; - u8 model; - u8 submodel; - u8 biosrev; - u8 feature1, feature2, feature3, feature4, feature5; -} PACKED; - -extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1); - #endif // __BIOSVAR_H diff --git a/src/fw/csm.c b/src/fw/csm.c index dda6af4..d241b17 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -4,10 +4,10 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" #include "boot.h" #include "bregs.h" #include "config.h" // CONFIG_* +#include "farptr.h" // MAKE_FLATPTR #include "hw/pci.h" #include "hw/pic.h" #include "malloc.h" // csm_malloc_preinit @@ -16,6 +16,7 @@ #include "post.h" #include "stacks.h" // wait_threads #include "std/acpi.h" // RSDP_SIGNATURE +#include "std/bda.h" // struct bios_data_area_s #include "std/optionrom.h" // struct rom_header #include "util.h" // copy_smbios
diff --git a/src/post.c b/src/post.c index 5514120..512c716 100644 --- a/src/post.c +++ b/src/post.c @@ -5,7 +5,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // struct bios_data_area_s +#include "biosvar.h" // SET_BDA #include "boot.h" // boot_init #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* diff --git a/src/resume.c b/src/resume.c index 96c63d5..af39a1d 100644 --- a/src/resume.c +++ b/src/resume.c @@ -4,8 +4,9 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // struct bios_data_area_s #include "bregs.h" // struct bregs +#include "config.h" // CONFIG_* +#include "farptr.h" // FLATPTR_TO_SEGOFF #include "hw/cmos.h" // inb_cmos #include "hw/pci.h" // pci_reboot #include "hw/pic.h" // pic_eoi2 @@ -13,6 +14,7 @@ #include "ioport.h" // outb #include "output.h" // dprintf #include "stacks.h" // farcall16big +#include "std/bda.h" // struct bios_data_area_s #include "string.h" // memset #include "util.h" // dma_setup
diff --git a/src/std/bda.h b/src/std/bda.h new file mode 100644 index 0000000..948bdbf --- /dev/null +++ b/src/std/bda.h @@ -0,0 +1,159 @@ +// BIOS Data Area (and similar) definitions +#ifndef __BDA_H +#define __BDA_H + +#include "disk.h" // struct fdpt_s +#include "types.h" // u8 + + +/**************************************************************** + * Interupt vector table + ****************************************************************/ + +struct rmode_IVT { + struct segoff_s ivec[256]; +}; + + +/**************************************************************** + * Bios Data Area (BDA) + ****************************************************************/ + +struct bios_data_area_s { + // 40:00 + u16 port_com[4]; + u16 port_lpt[3]; + u16 ebda_seg; + // 40:10 + u16 equipment_list_flags; + u8 pad1; + u16 mem_size_kb; + u8 pad2; + u8 ps2_ctrl_flag; + u8 kbd_flag0; + u8 kbd_flag1; + u8 alt_keypad; + u16 kbd_buf_head; + u16 kbd_buf_tail; + // 40:1e + u8 kbd_buf[32]; + u8 floppy_recalibration_status; + u8 floppy_motor_status; + // 40:40 + u8 floppy_motor_counter; + u8 floppy_last_status; + u8 floppy_return_status[7]; + u8 video_mode; + u16 video_cols; + u16 video_pagesize; + u16 video_pagestart; + // 40:50 + u16 cursor_pos[8]; + // 40:60 + u16 cursor_type; + u8 video_page; + u16 crtc_address; + u8 video_msr; + u8 video_pal; + struct segoff_s jump; + u8 other_6b; + u32 timer_counter; + // 40:70 + u8 timer_rollover; + u8 break_flag; + u16 soft_reset_flag; + u8 disk_last_status; + u8 hdcount; + u8 disk_control_byte; + u8 port_disk; + u8 lpt_timeout[4]; + u8 com_timeout[4]; + // 40:80 + u16 kbd_buf_start_offset; + u16 kbd_buf_end_offset; + u8 video_rows; + u16 char_height; + u8 video_ctl; + u8 video_switches; + u8 modeset_ctl; + u8 dcc_index; + u8 floppy_last_data_rate; + u8 disk_status_controller; + u8 disk_error_controller; + u8 disk_interrupt_flag; + u8 floppy_harddisk_info; + // 40:90 + u8 floppy_media_state[4]; + u8 floppy_track[2]; + u8 kbd_flag2; + u8 kbd_led; + struct segoff_s user_wait_complete_flag; + u32 user_wait_timeout; + // 40:A0 + u8 rtc_wait_flag; + u8 other_a1[7]; + struct segoff_s video_savetable; + u8 other_ac[4]; + // 40:B0 + u8 other_b0[9]; + u8 vbe_flag; + u16 vbe_mode; + u8 other_bc[4]; + // 40:C0 + u8 other_c0[4*16]; +} PACKED; + +// BDA floppy_recalibration_status bitdefs +#define FRS_IRQ (1<<7) + +// BDA rtc_wait_flag bitdefs +#define RWS_WAIT_PENDING (1<<0) +#define RWS_WAIT_ELAPSED (1<<7) + +// BDA floppy_media_state bitdefs +#define FMS_DRIVE_STATE_MASK (0x07) +#define FMS_MEDIA_DRIVE_ESTABLISHED (1<<4) +#define FMS_DOUBLE_STEPPING (1<<5) +#define FMS_DATA_RATE_MASK (0xc0) + +// Limit of BDA timer_counter field +#define TICKS_PER_DAY 1573040 + + +/**************************************************************** + * Extended Bios Data Area (EBDA) + ****************************************************************/ + +struct extended_bios_data_area_s { + u8 size; + u8 reserved1[0x21]; + struct segoff_s far_call_pointer; + u8 mouse_flag1; + u8 mouse_flag2; + u8 mouse_data[0x08]; + // 0x30 + u8 other1[0x0d]; + + // 0x3d + struct fdpt_s fdpt[2]; + + // 0x5d + u8 other2[0xC4]; + + // 0x121 - Begin custom storage. +} PACKED; + + +/**************************************************************** + * Bios Config Table + ****************************************************************/ + +struct bios_config_table_s { + u16 size; + u8 model; + u8 submodel; + u8 biosrev; + u8 feature1, feature2, feature3, feature4, feature5; +} PACKED; + +#endif // bda.h diff --git a/src/std/disk.h b/src/std/disk.h index c111e07..b2576d9 100644 --- a/src/std/disk.h +++ b/src/std/disk.h @@ -81,6 +81,22 @@ struct int13dpt_s { }; } PACKED;
+// Floppy info +struct fdpt_s { + u16 cylinders; + u8 heads; + u8 a0h_signature; + u8 phys_sectors; + u16 precompensation; + u8 reserved; + u8 drive_control_byte; + u16 phys_cylinders; + u8 phys_heads; + u16 landing_zone; + u8 sectors; + u8 checksum; +} PACKED; + // Floppy "Disk Base Table" struct floppy_dbt_s { u8 specify1; diff --git a/src/system.c b/src/system.c index 4669e62..aaca059 100644 --- a/src/system.c +++ b/src/system.c @@ -5,7 +5,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // BIOS_CONFIG_TABLE +#include "biosvar.h" // GET_GLOBAL #include "bregs.h" // struct bregs #include "hw/pic.h" // pic_reset #include "ioport.h" // inb diff --git a/src/util.h b/src/util.h index 6d8c0d2..32a4af4 100644 --- a/src/util.h +++ b/src/util.h @@ -175,8 +175,9 @@ void mtrr_setup(void); void reset_vector(void) __noreturn;
// misc.c -void mathcp_setup(void); +extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1); extern u8 BiosChecksum; +void mathcp_setup(void);
// version (auto generated file out/version.c) extern const char VERSION[];
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/bmp.c | 15 +++++++++++++-- src/bmp.h | 25 ------------------------- src/boot.c | 1 - src/boot.h | 28 ---------------------------- src/bootsplash.c | 2 -- src/fw/coreboot.c | 1 - src/fw/csm.c | 2 -- src/hw/ahci.c | 1 - src/hw/ata.c | 1 - src/hw/blockcmd.c | 1 - src/hw/esp-scsi.c | 1 - src/hw/floppy.c | 1 - src/hw/lsi-scsi.c | 1 - src/hw/megasas.c | 1 - src/hw/ramdisk.c | 1 - src/hw/usb-msc.c | 2 +- src/hw/usb-uas.c | 2 +- src/hw/virtio-blk.c | 1 - src/hw/virtio-scsi.c | 1 - src/jpeg.c | 2 +- src/jpeg.h | 11 ----------- src/optionroms.c | 1 - src/post.c | 2 -- src/post.h | 10 ---------- src/util.h | 42 +++++++++++++++++++++++++++++++++++++++++- 25 files changed, 57 insertions(+), 99 deletions(-) delete mode 100644 src/bmp.h delete mode 100644 src/boot.h delete mode 100644 src/jpeg.h delete mode 100644 src/post.h
diff --git a/src/bmp.c b/src/bmp.c index 68952f6..d8e76b7 100644 --- a/src/bmp.c +++ b/src/bmp.c @@ -6,9 +6,17 @@ * * This work is licensed under the terms of the GNU LGPLv3. */ -#include "bmp.h" // struct bmp_decdata #include "malloc.h" // malloc_tmphigh #include "string.h" // memcpy +#include "util.h" // struct bmp_decdata + +struct bmp_decdata { + struct tagRGBQUAD *quadp; + unsigned char *datap; + int width; + int height; + int bpp; +};
#define bmp_load4byte(addr) (*(u32 *)(addr)) #define bmp_load2byte(addr) (*(u16 *)(addr)) @@ -59,12 +67,14 @@ static void raw_data_format_adjust_24bpp(u8 *src, u8 *dest, int width, } }
+/* allocate decdata struct */ struct bmp_decdata *bmp_alloc(void) { struct bmp_decdata *bmp = malloc_tmphigh(sizeof(*bmp)); return bmp; }
+/* extract information from bmp file data */ int bmp_decode(struct bmp_decdata *bmp, unsigned char *data, int data_size) { if (data_size < 54) @@ -84,13 +94,14 @@ int bmp_decode(struct bmp_decdata *bmp, unsigned char *data, int data_size) return 0; }
+/* get bmp properties */ void bmp_get_size(struct bmp_decdata *bmp, int *width, int *height) { *width = bmp->width; *height = bmp->height; }
- +/* flush flat picture data to *pc */ int bmp_show(struct bmp_decdata *bmp, unsigned char *pic, int width , int height, int depth, int bytes_per_line_dest) { diff --git a/src/bmp.h b/src/bmp.h deleted file mode 100644 index 7ae8e87..0000000 --- a/src/bmp.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef BMP_H -#define BMP_H -#include "types.h" - -struct bmp_decdata { - struct tagRGBQUAD *quadp; - unsigned char *datap; - int width; - int height; - int bpp; -}; - -/* allocate decdata struct */ -struct bmp_decdata *bmp_alloc(void); - -/* extract information from bmp file data */ -int bmp_decode(struct bmp_decdata *bmp, unsigned char *data, int data_size); - -/* get bmp properties */ -void bmp_get_size(struct bmp_decdata *bmp, int *width, int *height); - -/* flush flat picture data to *pc */ -int bmp_show(struct bmp_decdata *bmp, unsigned char *pic, int width - , int height, int depth, int bytes_per_line_dest); -#endif diff --git a/src/boot.c b/src/boot.c index 70888e2..a2851b2 100644 --- a/src/boot.c +++ b/src/boot.c @@ -5,7 +5,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "boot.h" // boot_init #include "block.h" // struct drive_s #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* diff --git a/src/boot.h b/src/boot.h deleted file mode 100644 index e6b81bd..0000000 --- a/src/boot.h +++ /dev/null @@ -1,28 +0,0 @@ -// Storage for boot definitions. -#ifndef __BOOT_H -#define __BOOT_H - -#include "types.h" // u16 - -// boot.c -void boot_init(void); -void boot_add_bev(u16 seg, u16 bev, u16 desc, int prio); -void boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio); -struct drive_s; -void boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio); -void boot_add_hd(struct drive_s *drive_g, const char *desc, int prio); -void boot_add_cd(struct drive_s *drive_g, const char *desc, int prio); -void boot_add_cbfs(void *data, const char *desc, int prio); -void interactive_bootmenu(void); -void bcv_prepboot(void); -struct pci_device; -int bootprio_find_pci_device(struct pci_device *pci); -int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); -int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave); -int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid); -int bootprio_find_pci_rom(struct pci_device *pci, int instance); -int bootprio_find_named_rom(const char *name, int instance); -struct usbdevice_s; -int bootprio_find_usb(struct usbdevice_s *usbdev, int lun); - -#endif // __BOOT_H diff --git a/src/bootsplash.c b/src/bootsplash.c index aac7ebe..fb505ce 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -5,11 +5,9 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "bmp.h" // bmp_alloc #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "farptr.h" // FLATPTR_TO_SEG -#include "jpeg.h" // jpeg_alloc #include "malloc.h" // free #include "output.h" // dprintf #include "romfile.h" // romfile_loadfile diff --git a/src/fw/coreboot.c b/src/fw/coreboot.c index 7d877eb..a234e97 100644 --- a/src/fw/coreboot.c +++ b/src/fw/coreboot.c @@ -5,7 +5,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "block.h" // MAXDESCSIZE -#include "boot.h" // boot_add_cbfs #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_* #include "hw/pci.h" // pci_probe_devices diff --git a/src/fw/csm.c b/src/fw/csm.c index d241b17..cd16641 100644 --- a/src/fw/csm.c +++ b/src/fw/csm.c @@ -4,7 +4,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "boot.h" #include "bregs.h" #include "config.h" // CONFIG_* #include "farptr.h" // MAKE_FLATPTR @@ -13,7 +12,6 @@ #include "malloc.h" // csm_malloc_preinit #include "memmap.h" #include "output.h" // dprintf -#include "post.h" #include "stacks.h" // wait_threads #include "std/acpi.h" // RSDP_SIGNATURE #include "std/bda.h" // struct bios_data_area_s diff --git a/src/hw/ahci.c b/src/hw/ahci.c index 6bf0bf0..05474b1 100644 --- a/src/hw/ahci.c +++ b/src/hw/ahci.c @@ -8,7 +8,6 @@ #include "ata.h" // ATA_CB_STAT #include "biosvar.h" // GET_GLOBAL #include "blockcmd.h" // CDB_CMD_READ_10 -#include "boot.h" // add_bcv_hd #include "ioport.h" // inb #include "malloc.h" // free #include "output.h" // dprintf diff --git a/src/hw/ata.c b/src/hw/ata.c index 4ea6cd1..34ba119 100644 --- a/src/hw/ata.c +++ b/src/hw/ata.c @@ -9,7 +9,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // struct drive_s #include "blockcmd.h" // CDB_CMD_READ_10 -#include "boot.h" // boot_add_hd #include "byteorder.h" // be16_to_cpu #include "cmos.h" // inb_cmos #include "ioport.h" // inb diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index b9e61cd..7bdcf38 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -10,7 +10,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // struct disk_op_s #include "blockcmd.h" // struct cdb_request_sense -#include "boot.h" // boot_add_hd #include "byteorder.h" // be32_to_cpu #include "esp-scsi.h" // esp_scsi_cmd_data #include "lsi-scsi.h" // lsi_scsi_cmd_data diff --git a/src/hw/esp-scsi.c b/src/hw/esp-scsi.c index e6533af..118a1f5 100644 --- a/src/hw/esp-scsi.c +++ b/src/hw/esp-scsi.c @@ -13,7 +13,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup -#include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free diff --git a/src/hw/floppy.c b/src/hw/floppy.c index 05c518f..39efaad 100644 --- a/src/hw/floppy.c +++ b/src/hw/floppy.c @@ -7,7 +7,6 @@
#include "biosvar.h" // SET_BDA #include "block.h" // struct drive_s -#include "boot.h" // boot_add_floppy #include "bregs.h" // struct bregs #include "cmos.h" // inb_cmos #include "config.h" // CONFIG_FLOPPY diff --git a/src/hw/lsi-scsi.c b/src/hw/lsi-scsi.c index b7eb1f1..021aa61 100644 --- a/src/hw/lsi-scsi.c +++ b/src/hw/lsi-scsi.c @@ -13,7 +13,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup -#include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* #include "fw/paravirt.h" // runningOnQEMU #include "malloc.h" // free diff --git a/src/hw/megasas.c b/src/hw/megasas.c index 772fc75..ebc49f9 100644 --- a/src/hw/megasas.c +++ b/src/hw/megasas.c @@ -13,7 +13,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup -#include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* #include "malloc.h" // free #include "output.h" // dprintf diff --git a/src/hw/ramdisk.c b/src/hw/ramdisk.c index f57affd..eeddf25 100644 --- a/src/hw/ramdisk.c +++ b/src/hw/ramdisk.c @@ -6,7 +6,6 @@
#include "biosvar.h" // GET_GLOBAL #include "block.h" // struct drive_s -#include "boot.h" // boot_add_floppy #include "bregs.h" // struct bregs #include "malloc.h" // malloc_fseg #include "memmap.h" // add_e820 diff --git a/src/hw/usb-msc.c b/src/hw/usb-msc.c index 975ec7a..8ee448f 100644 --- a/src/hw/usb-msc.c +++ b/src/hw/usb-msc.c @@ -7,7 +7,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // DTYPE_USB #include "blockcmd.h" // cdb_read -#include "boot.h" // bootprio_find_usb #include "config.h" // CONFIG_USB_MSC #include "malloc.h" // free #include "output.h" // dprintf @@ -15,6 +14,7 @@ #include "string.h" // memset #include "usb.h" // struct usb_s #include "usb-msc.h" // usb_msc_setup +#include "util.h" // bootprio_find_usb
struct usbdrive_s { struct drive_s drive; diff --git a/src/hw/usb-uas.c b/src/hw/usb-uas.c index 9f4b558..1a9773a 100644 --- a/src/hw/usb-uas.c +++ b/src/hw/usb-uas.c @@ -17,7 +17,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // DTYPE_USB #include "blockcmd.h" // cdb_read -#include "boot.h" // bootprio_find_usb #include "config.h" // CONFIG_USB_UAS #include "malloc.h" // free #include "output.h" // dprintf @@ -25,6 +24,7 @@ #include "string.h" // memset #include "usb.h" // struct usb_s #include "usb-uas.h" // usb_uas_init +#include "util.h" // bootprio_find_usb
#define UAS_UI_COMMAND 0x01 #define UAS_UI_SENSE 0x03 diff --git a/src/hw/virtio-blk.c b/src/hw/virtio-blk.c index c48ea45..0de83b4 100644 --- a/src/hw/virtio-blk.c +++ b/src/hw/virtio-blk.c @@ -8,7 +8,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // GET_GLOBAL -#include "boot.h" // boot_add_hd #include "config.h" // CONFIG_* #include "block.h" // struct drive_s #include "malloc.h" // free diff --git a/src/hw/virtio-scsi.c b/src/hw/virtio-scsi.c index f50e335..7cde3bc 100644 --- a/src/hw/virtio-scsi.c +++ b/src/hw/virtio-scsi.c @@ -10,7 +10,6 @@ #include "biosvar.h" // GET_GLOBAL #include "block.h" // struct drive_s #include "blockcmd.h" // scsi_drive_setup -#include "boot.h" // bootprio_find_scsi_device #include "config.h" // CONFIG_* #include "malloc.h" // free #include "output.h" // dprintf diff --git a/src/jpeg.c b/src/jpeg.c index 925aa3d..c2138ed 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -41,8 +41,8 @@
#define __LITTLE_ENDIAN #include "malloc.h" -#include "jpeg.h" #include "string.h" +#include "util.h" #define ISHIFT 11
#define IFIX(a) ((int)((a) * (1 << ISHIFT) + .5)) diff --git a/src/jpeg.h b/src/jpeg.h deleted file mode 100644 index 2d08f45..0000000 --- a/src/jpeg.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __JPEG_H -#define __JPEG_H - -struct jpeg_decdata; -struct jpeg_decdata *jpeg_alloc(void); -int jpeg_decode(struct jpeg_decdata *jpeg, unsigned char *buf); -void jpeg_get_size(struct jpeg_decdata *jpeg, int *width, int *height); -int jpeg_show(struct jpeg_decdata *jpeg, unsigned char *pic, int width - , int height, int depth, int bytes_per_line_dest); - -#endif diff --git a/src/optionroms.c b/src/optionroms.c index 04afb2c..d7c8aef 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -5,7 +5,6 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "boot.h" // IPL #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "farptr.h" // FLATPTR_TO_SEG diff --git a/src/post.c b/src/post.c index 512c716..592176d 100644 --- a/src/post.c +++ b/src/post.c @@ -6,7 +6,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "biosvar.h" // SET_BDA -#include "boot.h" // boot_init #include "bregs.h" // struct bregs #include "config.h" // CONFIG_* #include "fw/paravirt.h" // qemu_cfg_preinit @@ -25,7 +24,6 @@ #include "malloc.h" // malloc_init #include "memmap.h" // add_e820 #include "output.h" // dprintf -#include "post.h" // interface_init #include "string.h" // memset #include "util.h" // kbd_init
diff --git a/src/post.h b/src/post.h deleted file mode 100644 index 5536eb9..0000000 --- a/src/post.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __POST_H -#define __POST_H - -void interface_init(void); -void device_hardware_setup(void); -void prepareboot(void); -void startBoot(void); -void reloc_preinit(void *f, void *arg); - -#endif // __POST_H diff --git a/src/util.h b/src/util.h index 32a4af4..79a2e7f 100644 --- a/src/util.h +++ b/src/util.h @@ -69,6 +69,40 @@ int irqtimer_check(u32 end); void apm_shutdown(void); void handle_1553(struct bregs *regs);
+// bmp.c +struct bmp_decdata *bmp_alloc(void); +int bmp_decode(struct bmp_decdata *bmp, unsigned char *data, int data_size); +void bmp_get_size(struct bmp_decdata *bmp, int *width, int *height); +int bmp_show(struct bmp_decdata *bmp, unsigned char *pic, int width + , int height, int depth, int bytes_per_line_dest); + +// boot.c +void boot_init(void); +void boot_add_bev(u16 seg, u16 bev, u16 desc, int prio); +void boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio); +void boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio); +void boot_add_hd(struct drive_s *drive_g, const char *desc, int prio); +void boot_add_cd(struct drive_s *drive_g, const char *desc, int prio); +void boot_add_cbfs(void *data, const char *desc, int prio); +void interactive_bootmenu(void); +void bcv_prepboot(void); +struct pci_device; +int bootprio_find_pci_device(struct pci_device *pci); +int bootprio_find_scsi_device(struct pci_device *pci, int target, int lun); +int bootprio_find_ata_device(struct pci_device *pci, int chanid, int slave); +int bootprio_find_fdc_device(struct pci_device *pci, int port, int fdid); +int bootprio_find_pci_rom(struct pci_device *pci, int instance); +int bootprio_find_named_rom(const char *name, int instance); +struct usbdevice_s; +int bootprio_find_usb(struct usbdevice_s *usbdev, int lun); + +// jpeg.c +struct jpeg_decdata *jpeg_alloc(void); +int jpeg_decode(struct jpeg_decdata *jpeg, unsigned char *buf); +void jpeg_get_size(struct jpeg_decdata *jpeg, int *width, int *height); +int jpeg_show(struct jpeg_decdata *jpeg, unsigned char *pic, int width + , int height, int depth, int bytes_per_line_dest); + // optionroms.c struct rom_header; void callrom(struct rom_header *rom, u16 bdf); @@ -77,6 +111,13 @@ void callrom(struct rom_header *rom, u16 bdf); void handle_1ab1(struct bregs *regs); void bios32_init(void);
+// post.c +void interface_init(void); +void device_hardware_setup(void); +void prepareboot(void); +void startBoot(void); +void reloc_preinit(void *f, void *arg); + // fw/acpi.c extern struct rsdp_descriptor *RsdpAddr; extern u32 acpi_pm1a_cnt; @@ -88,7 +129,6 @@ void acpi_set_reset_reg(struct acpi_20_generic_address *reg, u8 val); void acpi_reboot(void);
// fw/csm.c -struct pci_device; int csm_bootprio_fdc(struct pci_device *pci, int port, int fdid); int csm_bootprio_ata(struct pci_device *pci, int chanid, int slave); int csm_bootprio_pci(struct pci_device *pci);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/util.h | 238 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 119 insertions(+), 119 deletions(-)
diff --git a/src/util.h b/src/util.h index 79a2e7f..880c04a 100644 --- a/src/util.h +++ b/src/util.h @@ -4,69 +4,9 @@
#include "types.h" // u32
-// kbd.c -void kbd_init(void); -struct bregs; -void handle_15c2(struct bregs *regs); -void process_key(u8 key); - -// mouse.c -void mouse_init(void); -void process_mouse(u8 data); - -// serial.c -void serial_setup(void); -void lpt_setup(void); - -// cdrom.c -extern u8 CDRom_locks[]; -extern struct cdemu_s CDEmu; -extern struct drive_s *cdemu_drive_gf; -struct disk_op_s; -int process_cdemu_op(struct disk_op_s *op); -void cdrom_prepboot(void); -void cdemu_134b(struct bregs *regs); -int cdrom_boot(struct drive_s *drive_g); - -// clock.c -void clock_setup(void); -void handle_1583(struct bregs *regs); -void handle_1586(struct bregs *regs); -void useRTC(void); -void releaseRTC(void); - -// hw/floppy.c -extern struct floppy_ext_dbt_s diskette_param_table2; -void floppy_setup(void); -struct drive_s *init_floppy(int floppyid, int ftype); -int find_floppy_type(u32 size); -int process_floppy_op(struct disk_op_s *op); -void floppy_tick(void); - -// hw/ramdisk.c -void ramdisk_setup(void); -int process_ramdisk_op(struct disk_op_s *op); - -// hw/timer.c -void timer_setup(void); -void pmtimer_setup(u16 ioport); -u32 timer_calc(u32 msecs); -u32 timer_calc_usec(u32 usecs); -int timer_check(u32 end); -void ndelay(u32 count); -void udelay(u32 count); -void mdelay(u32 count); -void nsleep(u32 count); -void usleep(u32 count); -void msleep(u32 count); -u32 ticks_to_ms(u32 ticks); -u32 ticks_from_ms(u32 ms); -u32 irqtimer_calc_ticks(u32 count); -u32 irqtimer_calc(u32 msecs); -int irqtimer_check(u32 end); - // apm.c void apm_shutdown(void); +struct bregs; void handle_1553(struct bregs *regs);
// bmp.c @@ -80,6 +20,7 @@ int bmp_show(struct bmp_decdata *bmp, unsigned char *pic, int width void boot_init(void); void boot_add_bev(u16 seg, u16 bev, u16 desc, int prio); void boot_add_bcv(u16 seg, u16 ip, u16 desc, int prio); +struct drive_s; void boot_add_floppy(struct drive_s *drive_g, const char *desc, int prio); void boot_add_hd(struct drive_s *drive_g, const char *desc, int prio); void boot_add_cd(struct drive_s *drive_g, const char *desc, int prio); @@ -96,27 +37,27 @@ int bootprio_find_named_rom(const char *name, int instance); struct usbdevice_s; int bootprio_find_usb(struct usbdevice_s *usbdev, int lun);
-// jpeg.c -struct jpeg_decdata *jpeg_alloc(void); -int jpeg_decode(struct jpeg_decdata *jpeg, unsigned char *buf); -void jpeg_get_size(struct jpeg_decdata *jpeg, int *width, int *height); -int jpeg_show(struct jpeg_decdata *jpeg, unsigned char *pic, int width - , int height, int depth, int bytes_per_line_dest); - -// optionroms.c -struct rom_header; -void callrom(struct rom_header *rom, u16 bdf); +// bootsplash.c +void enable_vga_console(void); +void enable_bootsplash(void); +void disable_bootsplash(void);
-// pcibios.c -void handle_1ab1(struct bregs *regs); -void bios32_init(void); +// cdrom.c +extern u8 CDRom_locks[]; +extern struct cdemu_s CDEmu; +extern struct drive_s *cdemu_drive_gf; +struct disk_op_s; +int process_cdemu_op(struct disk_op_s *op); +void cdrom_prepboot(void); +void cdemu_134b(struct bregs *regs); +int cdrom_boot(struct drive_s *drive_g);
-// post.c -void interface_init(void); -void device_hardware_setup(void); -void prepareboot(void); -void startBoot(void); -void reloc_preinit(void *f, void *arg); +// clock.c +void clock_setup(void); +void handle_1583(struct bregs *regs); +void handle_1586(struct bregs *regs); +void useRTC(void); +void releaseRTC(void);
// fw/acpi.c extern struct rsdp_descriptor *RsdpAddr; @@ -128,6 +69,20 @@ struct acpi_20_generic_address; void acpi_set_reset_reg(struct acpi_20_generic_address *reg, u8 val); void acpi_reboot(void);
+// fw/biostable.c +void copy_smbios(void *pos); +void copy_table(void *pos); + +// fw/coreboot.c +extern const char *CBvendor, *CBpart; +struct cbfs_file; +void debug_cbmem(char c); +void cbfs_run_payload(struct cbfs_file *file); +void coreboot_platform_setup(void); +void cbfs_payload_setup(void); +void coreboot_preinit(void); +void coreboot_cbfs_init(void); + // fw/csm.c int csm_bootprio_fdc(struct pci_device *pci, int port, int fdid); int csm_bootprio_ata(struct pci_device *pci, int chanid, int slave); @@ -136,6 +91,17 @@ int csm_bootprio_pci(struct pci_device *pci); // fw/mptable.c void mptable_setup(void);
+// fw/mtrr.c +void mtrr_setup(void); + +// fw/pciinit.c +extern const u8 pci_irqs[4]; +void pci_setup(void); + +// fw/pirtable.c +extern struct pir_header *PirAddr; +void pirtable_setup(void); + // fw/shadow.c void make_bios_writable(void); void make_bios_readonly(void); @@ -146,14 +112,6 @@ extern struct smbios_entry_point *SMBiosAddr; void smbios_setup(void); void display_uuid(void);
-// fw/pciinit.c -extern const u8 pci_irqs[4]; -void pci_setup(void); - -// fw/pirtable.c -extern struct pir_header *PirAddr; -void pirtable_setup(void); - // fw/smm.c void smm_device_setup(void); void smm_setup(void); @@ -165,25 +123,60 @@ void wrmsr_smp(u32 index, u64 val); void smp_setup(void); int apic_id_is_present(u8 apic_id);
-// fw/coreboot.c -extern const char *CBvendor, *CBpart; -struct cbfs_file; -void debug_cbmem(char c); -void cbfs_run_payload(struct cbfs_file *file); -void coreboot_platform_setup(void); -void cbfs_payload_setup(void); -void coreboot_preinit(void); -void coreboot_cbfs_init(void); +// hw/floppy.c +extern struct floppy_ext_dbt_s diskette_param_table2; +void floppy_setup(void); +struct drive_s *init_floppy(int floppyid, int ftype); +int find_floppy_type(u32 size); +int process_floppy_op(struct disk_op_s *op); +void floppy_tick(void);
-// fw/biostable.c -void copy_smbios(void *pos); -void copy_table(void *pos); +// hw/ramdisk.c +void ramdisk_setup(void); +int process_ramdisk_op(struct disk_op_s *op);
-// vgahooks.c -void handle_155f(struct bregs *regs); -void vgahook_setup(struct pci_device *pci); +// hw/timer.c +void timer_setup(void); +void pmtimer_setup(u16 ioport); +u32 timer_calc(u32 msecs); +u32 timer_calc_usec(u32 usecs); +int timer_check(u32 end); +void ndelay(u32 count); +void udelay(u32 count); +void mdelay(u32 count); +void nsleep(u32 count); +void usleep(u32 count); +void msleep(u32 count); +u32 ticks_to_ms(u32 ticks); +u32 ticks_from_ms(u32 ms); +u32 irqtimer_calc_ticks(u32 count); +u32 irqtimer_calc(u32 msecs); +int irqtimer_check(u32 end); + +// jpeg.c +struct jpeg_decdata *jpeg_alloc(void); +int jpeg_decode(struct jpeg_decdata *jpeg, unsigned char *buf); +void jpeg_get_size(struct jpeg_decdata *jpeg, int *width, int *height); +int jpeg_show(struct jpeg_decdata *jpeg, unsigned char *pic, int width + , int height, int depth, int bytes_per_line_dest); + +// kbd.c +void kbd_init(void); +void handle_15c2(struct bregs *regs); +void process_key(u8 key); + +// misc.c +extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1); +extern u8 BiosChecksum; +void mathcp_setup(void); + +// mouse.c +void mouse_init(void); +void process_mouse(u8 data);
// optionroms.c +struct rom_header; +void callrom(struct rom_header *rom, u16 bdf); void call_bcv(u16 seg, u16 ip); int is_pci_vga(struct pci_device *pci); void optionrom_setup(void); @@ -191,33 +184,40 @@ void vgarom_setup(void); void s3_resume_vga(void); extern int ScreenAndDebug;
-// bootsplash.c -void enable_vga_console(void); -void enable_bootsplash(void); -void disable_bootsplash(void); +// pcibios.c +void handle_1ab1(struct bregs *regs); +void bios32_init(void);
-// resume.c -extern int HaveRunPost; -void dma_setup(void); +// pmm.c +void pmm_init(void); +void pmm_prepboot(void);
// pnpbios.c u16 get_pnp_offset(void); void pnp_init(void);
-// pmm.c -void pmm_init(void); -void pmm_prepboot(void); +// post.c +void interface_init(void); +void device_hardware_setup(void); +void prepareboot(void); +void startBoot(void); +void reloc_preinit(void *f, void *arg);
-// fw/mtrr.c -void mtrr_setup(void); +// resume.c +extern int HaveRunPost; +void dma_setup(void);
// romlayout.S void reset_vector(void) __noreturn;
-// misc.c -extern struct bios_config_table_s BIOS_CONFIG_TABLE __aligned(1); -extern u8 BiosChecksum; -void mathcp_setup(void); +// serial.c +void serial_setup(void); +void lpt_setup(void); + +// vgahooks.c +void handle_155f(struct bregs *regs); +void vgahook_setup(struct pci_device *pci); +
// version (auto generated file out/version.c) extern const char VERSION[];
On So, 2013-09-15 at 01:07 -0400, Kevin O'Connor wrote:
This patch series attempts to cleanup some of the include files within SeaBIOS. There are three main goals: split out the complex users of util.h into their own header files, introduce a new directory std/ for header files that just define standard bios interfaces, and make sure no header files (with the exception of util.h) have declarations for more than one c file.
At the end of this series util.h, only contains simple function and variable prototypes (ie, no macros, inline code, or struct definitions).
Nice cleanup.
cheers, Gerd
On Sun, Sep 15, 2013 at 01:07:15AM -0400, Kevin O'Connor wrote:
This patch series attempts to cleanup some of the include files within SeaBIOS. There are three main goals: split out the complex users of util.h into their own header files, introduce a new directory std/ for header files that just define standard bios interfaces, and make sure no header files (with the exception of util.h) have declarations for more than one c file.
At the end of this series util.h, only contains simple function and variable prototypes (ie, no macros, inline code, or struct definitions).
FYI - I committed this (slightly modified) series.
-Kevin