Convert all users of the alternative variable exports to VARFSEG. There isn't a significant distinction between the existing types of exports, so it's simpler to just use one type going forward.
The new VARFSEG declaration is only emitting when in 32bit mode, so update and move some variables as needed.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- Makefile | 8 ++++---- src/block.c | 6 +++--- src/cdrom.c | 2 +- src/clock.c | 6 +++--- src/csm.c | 4 ++-- src/floppy.c | 4 ++-- src/memmap.c | 4 ++++ src/memmap.h | 5 +---- src/misc.c | 20 ++++++++------------ src/output.c | 2 +- src/paravirt.c | 3 +++ src/paravirt.h | 1 - src/pci.c | 2 +- src/pcibios.c | 2 +- src/pirtable.c | 4 ++-- src/pmm.c | 5 ++++- src/pnpbios.c | 4 ++-- src/resume.c | 2 +- src/smp.c | 10 +++++----- src/stacks.c | 4 ++-- src/system.c | 4 ---- src/types.h | 16 ++-------------- src/usb-hid.c | 4 ++-- src/vgahooks.c | 6 +++--- vgasrc/vgabios.c | 2 +- 25 files changed, 58 insertions(+), 72 deletions(-)
diff --git a/Makefile b/Makefile index ab9ca0e..1ce2f79 100644 --- a/Makefile +++ b/Makefile @@ -8,15 +8,15 @@ OUT=out/
# Source files -SRCBOTH=misc.c stacks.c pmm.c output.c util.c block.c floppy.c ata.c mouse.c \ +SRCBOTH=misc.c stacks.c output.c util.c block.c floppy.c ata.c mouse.c \ kbd.c pci.c serial.c clock.c pic.c cdrom.c ps2port.c smp.c resume.c \ - pnpbios.c pirtable.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \ + pnpbios.c vgahooks.c ramdisk.c pcibios.c blockcmd.c \ usb.c usb-uhci.c usb-ohci.c usb-ehci.c usb-hid.c usb-msc.c \ virtio-ring.c virtio-pci.c virtio-blk.c virtio-scsi.c apm.c ahci.c \ usb-uas.c lsi-scsi.c esp-scsi.c megasas.c SRC16=$(SRCBOTH) system.c disk.c font.c -SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c coreboot.c boot.c \ - acpi.c smm.c mptable.c smbios.c pciinit.c optionroms.c mtrr.c \ +SRC32FLAT=$(SRCBOTH) post.c shadow.c memmap.c pmm.c coreboot.c boot.c \ + acpi.c smm.c mptable.c pirtable.c smbios.c pciinit.c optionroms.c mtrr.c \ lzmadecode.c bootsplash.c jpeg.c usb-hub.c paravirt.c \ biostables.c xen.c bmp.c romfile.c csm.c SRC32SEG=util.c output.c pci.c pcibios.c apm.c stacks.c diff --git a/src/block.c b/src/block.c index c202f5a..9ea4ca7 100644 --- a/src/block.c +++ b/src/block.c @@ -14,10 +14,10 @@ #include "virtio-blk.h" // process_virtio_blk_op #include "blockcmd.h" // cdb_*
-u8 FloppyCount VAR16VISIBLE; +u8 FloppyCount VARFSEG; u8 CDCount; -struct drive_s *IDMap[3][CONFIG_MAX_EXTDRIVE] VAR16VISIBLE; -u8 *bounce_buf_fl VAR16VISIBLE; +struct drive_s *IDMap[3][CONFIG_MAX_EXTDRIVE] VARFSEG; +u8 *bounce_buf_fl VARFSEG; struct dpte_s DefaultDPTE VARLOW;
struct drive_s * diff --git a/src/cdrom.c b/src/cdrom.c index 81b97f7..01eb87a 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -21,7 +21,7 @@ u8 CDRom_locks[CONFIG_MAX_EXTDRIVE] VARLOW; ****************************************************************/
struct cdemu_s CDEmu VARLOW; -struct drive_s *cdemu_drive_gf VAR16VISIBLE; +struct drive_s *cdemu_drive_gf VARFSEG;
static int cdemu_read(struct disk_op_s *op) diff --git a/src/clock.c b/src/clock.c index 708d413..79b18f9 100644 --- a/src/clock.c +++ b/src/clock.c @@ -62,10 +62,10 @@
#define CALIBRATE_COUNT 0x800 // Approx 1.7ms
-u32 cpu_khz VAR16VISIBLE; -u8 no_tsc VAR16VISIBLE; +u32 cpu_khz VARFSEG; +u8 no_tsc VARFSEG;
-u16 pmtimer_ioport VAR16VISIBLE; +u16 pmtimer_ioport VARFSEG; u32 pmtimer_wraps VARLOW; u32 pmtimer_last VARLOW;
diff --git a/src/csm.c b/src/csm.c index b5d8b54..8882ee5 100644 --- a/src/csm.c +++ b/src/csm.c @@ -18,9 +18,9 @@ #include "smbios.h" #include "pic.h"
-struct rsdp_descriptor VAR32FLATVISIBLE __aligned(16) csm_rsdp; +struct rsdp_descriptor csm_rsdp VARFSEG __aligned(16);
-EFI_COMPATIBILITY16_TABLE csm_compat_table VAR32FLATVISIBLE __aligned(16) = { +EFI_COMPATIBILITY16_TABLE csm_compat_table VARFSEG __aligned(16) = { .Signature = 0x24454649, .TableChecksum = 0 /* Filled in by checkrom.py */, .TableLength = sizeof(csm_compat_table), diff --git a/src/floppy.c b/src/floppy.c index 2887e78..d73e4ae 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -28,7 +28,7 @@ // Since no provisions are made for multiple drive types, most // values in this table are ignored. I set parameters for 1.44M // floppy here -struct floppy_ext_dbt_s diskette_param_table2 VAR16VISIBLE = { +struct floppy_ext_dbt_s diskette_param_table2 VARFSEG = { .dbt = { .specify1 = 0xAF, // step rate 12ms, head unload 240ms .specify2 = 0x02, // head load time 4ms, DMA used @@ -55,7 +55,7 @@ struct floppyinfo_s { u8 media_state; };
-struct floppyinfo_s FloppyInfo[] VAR16VISIBLE = { +struct floppyinfo_s FloppyInfo[] VARFSEG = { // Unknown { {0, 0, 0}, 0x00, 0x00}, // 1 - 360KB, 5.25" - 2 heads, 40 tracks, 9 sectors diff --git a/src/memmap.c b/src/memmap.c index 29ca644..f029ce2 100644 --- a/src/memmap.c +++ b/src/memmap.c @@ -13,6 +13,10 @@ * e820 memory map ****************************************************************/
+// Info on e820 map location and size. +struct e820entry e820_list[CONFIG_MAX_E820] VARFSEG; +int e820_count VARFSEG; + // Remove an entry from the e820_list. static void remove_e820(int i) diff --git a/src/memmap.h b/src/memmap.h index 783a042..7bda56e 100644 --- a/src/memmap.h +++ b/src/memmap.h @@ -22,11 +22,8 @@ void memmap_prepboot(void); // A typical OS page size #define PAGE_SIZE 4096
-// e820 map storage (defined in system.c) +// e820 map storage extern struct e820entry e820_list[]; extern int e820_count;
-// Space for exported bios tables (defined in misc.c) -extern char BiosTableSpace[]; - #endif // e820map.h diff --git a/src/misc.c b/src/misc.c index 05d0cf5..fb7aad4 100644 --- a/src/misc.c +++ b/src/misc.c @@ -11,13 +11,9 @@ #include "pic.h" // enable_hwirq
// Amount of continuous ram under 4Gig -u32 RamSize VAR16VISIBLE; +u32 RamSize VARFSEG; // Amount of continuous ram >4Gig u64 RamSizeOver4G; -// Space for bios tables built an run-time. -char BiosTableSpace[CONFIG_MAX_BIOSTABLE] __aligned(MALLOC_MIN_ALIGN) VAR16VISIBLE; -// Type of emulator platform. -int PlatformRunningOn VAR16VISIBLE;
/**************************************************************** @@ -133,23 +129,23 @@ struct bios_config_table_s BIOS_CONFIG_TABLE VAR16FIXED(0xe6f5) = { ****************************************************************/
// Real mode IDT descriptor -struct descloc_s rmode_IDT_info VAR16VISIBLE = { +struct descloc_s rmode_IDT_info VARFSEG = { .length = sizeof(struct rmode_IVT) - 1, .addr = (u32)MAKE_FLATPTR(SEG_IVT, 0), };
// Dummy IDT that forces a machine shutdown if an irq happens in // protected mode. -u8 dummy_IDT VAR16VISIBLE; +u8 dummy_IDT VARFSEG;
// Protected mode IDT descriptor -struct descloc_s pmode_IDT_info VAR16VISIBLE = { +struct descloc_s pmode_IDT_info VARFSEG = { .length = sizeof(dummy_IDT) - 1, - .addr = (u32)MAKE_FLATPTR(SEG_BIOS, &dummy_IDT), + .addr = (u32)&dummy_IDT, };
// GDT -u64 rombios32_gdt[] VAR16VISIBLE __aligned(8) = { +u64 rombios32_gdt[] VARFSEG __aligned(8) = { // First entry can't be used. 0x0000000000000000LL, // 32 bit flat code segment (SEG32_MODE32_CS) @@ -167,9 +163,9 @@ u64 rombios32_gdt[] VAR16VISIBLE __aligned(8) = { };
// GDT descriptor -struct descloc_s rombios32_gdt_48 VAR16VISIBLE = { +struct descloc_s rombios32_gdt_48 VARFSEG = { .length = sizeof(rombios32_gdt) - 1, - .addr = (u32)MAKE_FLATPTR(SEG_BIOS, rombios32_gdt), + .addr = (u32)rombios32_gdt, };
diff --git a/src/output.c b/src/output.c index e623d37..79c3ada 100644 --- a/src/output.c +++ b/src/output.c @@ -23,7 +23,7 @@ struct putcinfo {
#define DEBUG_TIMEOUT 100000
-u16 DebugOutputPort VAR16VISIBLE = 0x402; +u16 DebugOutputPort VARFSEG = 0x402;
void debug_serial_preinit(void) diff --git a/src/paravirt.c b/src/paravirt.c index f76b47f..9ea3dd5 100644 --- a/src/paravirt.c +++ b/src/paravirt.c @@ -21,6 +21,9 @@ #include "pci.h" // create_pirtable #include "xen.h" // xen_biostable_setup
+// Type of emulator platform. +int PlatformRunningOn VARFSEG; + /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It * should be used to determine that a VM is running under KVM. */ diff --git a/src/paravirt.h b/src/paravirt.h index 96b35ba..7237731 100644 --- a/src/paravirt.h +++ b/src/paravirt.h @@ -9,7 +9,6 @@ #define PF_XEN (1<<1) #define PF_KVM (1<<2)
-// misc.c extern int PlatformRunningOn;
static inline int runningOnQEMU(void) { diff --git a/src/pci.c b/src/pci.c index 071c302..4f6a6fa 100644 --- a/src/pci.c +++ b/src/pci.c @@ -86,7 +86,7 @@ pci_next(int bdf, int bus) }
struct pci_device *PCIDevices; -int MaxPCIBus VAR16VISIBLE; +int MaxPCIBus VARFSEG;
// Check if PCI is available at all int diff --git a/src/pcibios.c b/src/pcibios.c index f084fa1..0f3ec5b 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -223,7 +223,7 @@ struct bios32_s { u8 reserved[5]; } PACKED;
-struct bios32_s BIOS32HEADER __aligned(16) VAR16EXPORT = { +struct bios32_s BIOS32HEADER __aligned(16) VARFSEG = { .signature = 0x5f32335f, // _32_ .length = sizeof(BIOS32HEADER) / 16, }; diff --git a/src/pirtable.c b/src/pirtable.c index 8b79791..02e2a67 100644 --- a/src/pirtable.c +++ b/src/pirtable.c @@ -9,7 +9,7 @@ #include "config.h" // CONFIG_* #include "util.h" // checksum
-struct pir_header *PirAddr VAR16VISIBLE; +struct pir_header *PirAddr VARFSEG;
struct pir_table { struct pir_header pir; @@ -18,7 +18,7 @@ struct pir_table {
extern struct pir_table PIR_TABLE; #if CONFIG_PIRTABLE -struct pir_table PIR_TABLE __aligned(16) VAR16EXPORT = { +struct pir_table PIR_TABLE __aligned(16) VARFSEG = { .pir = { .version = 0x0100, .size = sizeof(struct pir_table), diff --git a/src/pmm.c b/src/pmm.c index 790177e..8944bae 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -216,6 +216,9 @@ rom_confirm(u32 size) * Setup ****************************************************************/
+// Space for bios tables built an run-time. +char BiosTableSpace[CONFIG_MAX_BIOSTABLE] __aligned(MALLOC_MIN_ALIGN) VARFSEG; + void malloc_preinit(void) { @@ -457,7 +460,7 @@ extern struct pmmheader PMMHEADER; #define PMM_SIGNATURE 0x4d4d5024 // $PMM
#if CONFIG_PMM -struct pmmheader PMMHEADER __aligned(16) VAR16EXPORT = { +struct pmmheader PMMHEADER __aligned(16) VARFSEG = { .signature = PMM_SIGNATURE, .version = 0x01, .length = sizeof(PMMHEADER), diff --git a/src/pnpbios.c b/src/pnpbios.c index c8bc8f4..fddcc81 100644 --- a/src/pnpbios.c +++ b/src/pnpbios.c @@ -28,7 +28,7 @@ extern struct pnpheader PNPHEADER; extern char pnp_string[];
#if CONFIG_PNPBIOS -struct pnpheader PNPHEADER __aligned(16) VAR16EXPORT = { +struct pnpheader PNPHEADER __aligned(16) VARFSEG = { .signature = PNP_SIGNATURE, .version = 0x10, .length = sizeof(PNPHEADER), @@ -41,7 +41,7 @@ struct pnpheader PNPHEADER __aligned(16) VAR16EXPORT = { // We need a copy of this string in the 0xf000 segment, but we are not // actually a PnP BIOS, so make sure it is *not* aligned, so OSes will // not see it if they scan. -char pnp_string[] __aligned(2) VAR16VISIBLE = " $PnP"; +char pnp_string[] __aligned(2) VARFSEG = " $PnP"; #endif
#define FUNCTION_NOT_SUPPORTED 0x82 diff --git a/src/resume.c b/src/resume.c index adc3594..b30d62e 100644 --- a/src/resume.c +++ b/src/resume.c @@ -15,7 +15,7 @@ #include "cmos.h" // inb_cmos
// Indicator if POST phase has been run. -int HaveRunPost VAR16VISIBLE; +int HaveRunPost VARFSEG;
// Reset DMA controller void diff --git a/src/smp.c b/src/smp.c index f971647..0dfec29 100644 --- a/src/smp.c +++ b/src/smp.c @@ -16,8 +16,8 @@
#define APIC_ENABLED 0x0100
-struct { u32 ecx, eax, edx; } smp_mtrr[32] VAR16VISIBLE; -u32 smp_mtrr_count VAR16VISIBLE; +struct { u32 ecx, eax, edx; } smp_mtrr[32] VARFSEG; +u32 smp_mtrr_count VARFSEG;
void wrmsr_smp(u32 index, u64 val) @@ -33,10 +33,10 @@ wrmsr_smp(u32 index, u64 val) smp_mtrr_count++; }
-u32 CountCPUs VAR16VISIBLE; -u32 MaxCountCPUs VAR16VISIBLE; +u32 CountCPUs VARFSEG; +u32 MaxCountCPUs VARFSEG; // 256 bits for the found APIC IDs -u32 FoundAPICIDs[256/32] VAR16VISIBLE; +u32 FoundAPICIDs[256/32] VARFSEG; extern void smp_ap_boot_code(void); ASM16( " .global smp_ap_boot_code\n" diff --git a/src/stacks.c b/src/stacks.c index 93da7b5..7423939 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -243,7 +243,7 @@ struct thread_info { void *stackpos; struct thread_info **pprev; }; -struct thread_info VAR32FLATVISIBLE MainThread = { +struct thread_info MainThread VARFSEG = { &MainThread, NULL, &MainThread.next }; #define THREADSTACKSIZE 4096 @@ -424,7 +424,7 @@ mutex_unlock(struct mutex_s *mutex) * Thread preemption ****************************************************************/
-int VAR16VISIBLE CanPreempt; +int CanPreempt VARFSEG; static u32 PreemptCount;
// Turn on RTC irqs and arrange for them to check the 32bit threads. diff --git a/src/system.c b/src/system.c index 6658e22..dc1dd7d 100644 --- a/src/system.c +++ b/src/system.c @@ -290,10 +290,6 @@ handle_15e801(struct bregs *regs) set_success(regs); }
-// Info on e820 map location and size. -struct e820entry e820_list[CONFIG_MAX_E820] VAR16VISIBLE; -int e820_count VAR16VISIBLE; - static void handle_15e820(struct bregs *regs) { diff --git a/src/types.h b/src/types.h index ce0f081..4df1476 100644 --- a/src/types.h +++ b/src/types.h @@ -51,16 +51,10 @@ extern void __force_link_error__only_in_16bit(void) __noreturn; # define VISIBLE32SEG // Designate a variable as (only) visible to 16bit code. # define VAR16 __section(".data16." UNIQSEC) -// Designate a variable as visible to 16bit, 32bit, and assembler code. -# define VAR16VISIBLE VAR16 __VISIBLE -// Designate a variable as externally visible (in addition to all internal code). -# define VAR16EXPORT __section(".data16.export." UNIQSEC) __VISIBLE // Designate a variable at a specific 16bit address # define VAR16FIXED(addr) __aligned(1) __VISIBLE __section(".fixedaddr." __stringify(addr)) // Designate a variable as (only) visible to 32bit segmented code. # define VAR32SEG __section(".discard.var32seg." UNIQSEC) -// Designate a 32bit variable also available in 16bit "big real" mode. -# define VAR32FLATVISIBLE __section(".discard.var32flat." UNIQSEC) __VISIBLE __weak // Designate a variable as visible and located in the e-segment. # define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak // Designate a variable as visible and located in the f-segment. @@ -79,11 +73,8 @@ extern void __force_link_error__only_in_16bit(void) __noreturn; # define VISIBLE32INIT # define VISIBLE32SEG __VISIBLE # define VAR16 __section(".discard.var16." UNIQSEC) -# define VAR16VISIBLE VAR16 __VISIBLE __weak -# define VAR16EXPORT VAR16VISIBLE -# define VAR16FIXED(addr) VAR16VISIBLE +# define VAR16FIXED(addr) VAR16 __VISIBLE __weak # define VAR32SEG __section(".data32seg." UNIQSEC) -# define VAR32FLATVISIBLE __section(".discard.var32flat." UNIQSEC) __VISIBLE __weak # define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak # define VARFSEG __section(".discard.varfseg." UNIQSEC) __VISIBLE __weak # define ASM16(code) @@ -97,11 +88,8 @@ extern void __force_link_error__only_in_16bit(void) __noreturn; # define VISIBLE32INIT __section(".text.init." UNIQSEC) __VISIBLE # define VISIBLE32SEG # define VAR16 __section(".discard.var16." UNIQSEC) -# define VAR16VISIBLE VAR16 __VISIBLE __weak -# define VAR16EXPORT VAR16VISIBLE -# define VAR16FIXED(addr) VAR16VISIBLE +# define VAR16FIXED(addr) VAR16 __VISIBLE __weak # define VAR32SEG __section(".discard.var32seg." UNIQSEC) -# define VAR32FLATVISIBLE __section(".data.runtime." UNIQSEC) __VISIBLE # define VARLOW __section(".data.varlow." UNIQSEC) __VISIBLE # define VARFSEG __section(".data.varfseg." UNIQSEC) __VISIBLE # define ASM16(code) diff --git a/src/usb-hid.c b/src/usb-hid.c index 0d5f371..deb3ea5 100644 --- a/src/usb-hid.c +++ b/src/usb-hid.c @@ -11,8 +11,8 @@ #include "biosvar.h" // GET_GLOBAL #include "ps2port.h" // ATKBD_CMD_GETID
-struct usb_pipe *keyboard_pipe VAR16VISIBLE; -struct usb_pipe *mouse_pipe VAR16VISIBLE; +struct usb_pipe *keyboard_pipe VARFSEG; +struct usb_pipe *mouse_pipe VARFSEG;
/**************************************************************** diff --git a/src/vgahooks.c b/src/vgahooks.c index 20a2e2e..c9a4448 100644 --- a/src/vgahooks.c +++ b/src/vgahooks.c @@ -15,7 +15,7 @@ #define VH_VIA 1 #define VH_INTEL 2
-int VGAHookHandlerType VAR16VISIBLE; +int VGAHookHandlerType VARFSEG;
static void handle_155fXX(struct bregs *regs) @@ -28,7 +28,7 @@ handle_155fXX(struct bregs *regs) * Via hooks ****************************************************************/
-int ViaFBsize VAR16VISIBLE, ViaRamSpeed VAR16VISIBLE; +int ViaFBsize VARFSEG, ViaRamSpeed VARFSEG;
static void via_155f01(struct bregs *regs) @@ -167,7 +167,7 @@ via_setup(struct pci_device *pci) * Intel VGA hooks ****************************************************************/
-u8 IntelDisplayType VAR16VISIBLE, IntelDisplayId VAR16VISIBLE; +u8 IntelDisplayType VARFSEG, IntelDisplayId VARFSEG;
static void intel_155f35(struct bregs *regs) diff --git a/vgasrc/vgabios.c b/vgasrc/vgabios.c index 3e26e32..6abe639 100644 --- a/vgasrc/vgabios.c +++ b/vgasrc/vgabios.c @@ -37,7 +37,7 @@ struct VideoParam_s video_param_table[29] VAR16; * PCI Data ****************************************************************/
-struct pci_data rom_pci_data VAR16VISIBLE = { +struct pci_data rom_pci_data VAR16 VISIBLE16 = { .signature = PCI_ROM_SIGNATURE, .vendor = CONFIG_VGA_VID, .device = CONFIG_VGA_DID,