This patch series updates the SeaBIOS' low-memory allocation scheme so that it no longer uses the EBDA or the 9-segment for internal low memory allocations. Instead, the e-segment is used where SeaBIOS requires read/writable "low" memory.
There is now plenty of space in the e-segment (there has been ever since SeaBIOS was updated to relocate its initialization code), while using 9-segment space can reserve the memory from OS use (in particular on older operating systems). Also, using the 9-segment (and indirectly the EBDA) is more fragile as it requires handling of a relocatable EBDA.
As a result of this change, SeaBIOS will be able to allocate larger amounts of low-memory. Indeed, the size of the "extra stack" for 16bit code is increased from 512 bytes to 2K in this series.
-Kevin
Kevin O'Connor (8): Use the e-segment instead of the 9-segment for bios "low mem". Add mechanism to declare variables as "low mem" and use for extra stack. Convert timer code EBDA variables to VARLOW variables. Convert boot code EBDA variables to VARLOW variables. Convert ps2 code EBDA variables to VARLOW variables. Convert USB keyboard code EBDA variables to VARLOW variables. Convert disk code EBDA variables to VARLOW variables. EBDA cleanups.
src/acpi.c | 2 +- src/ahci.c | 2 +- src/asm-offsets.c | 8 ---- src/ata.c | 6 +-- src/biosvar.h | 80 +---------------------------------- src/block.c | 5 +- src/blockcmd.h | 2 + src/boot.c | 19 ++++----- src/bootsplash.c | 1 - src/cdrom.c | 80 ++++++++++++++++++------------------ src/clock.c | 32 ++++++++------- src/config.h | 2 + src/coreboot.c | 3 +- src/disk.c | 73 ++++++++++++++------------------ src/disk.h | 38 ++++++++++++++++- src/memmap.c | 2 +- src/mouse.c | 31 +++++++------- src/mtrr.c | 2 +- src/optionroms.c | 14 +----- src/pcibios.c | 2 +- src/pciinit.c | 3 +- src/pirtable.c | 2 +- src/pmm.c | 116 ++++++++++++---------------------------------------- src/post.c | 50 ++++++++++++++++------ src/ps2port.c | 18 ++++---- src/romlayout.S | 9 ++-- src/shadow.c | 4 +- src/smbios.c | 1 - src/stacks.c | 15 ++++--- src/types.h | 4 ++ src/usb-hid.c | 17 ++++++- src/util.h | 3 +- src/xen.h | 3 +- tools/layoutrom.py | 81 ++++++++++++++++++++++++------------ 34 files changed, 337 insertions(+), 393 deletions(-)
Use the e-segment for ZoneLow allocations. There is plenty of e-segment space (there has been since SeaBIOS supported code relocation), while using the 9-segment space can impact old real-mode applications.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/config.h | 1 + src/optionroms.c | 14 +----- src/pmm.c | 116 ++++++++++++----------------------------------------- src/shadow.c | 4 +- src/util.h | 2 +- 5 files changed, 34 insertions(+), 103 deletions(-)
diff --git a/src/config.h b/src/config.h index bbacae7..521469b 100644 --- a/src/config.h +++ b/src/config.h @@ -38,6 +38,7 @@ #define BUILD_ROM_START 0xc0000 #define BUILD_BIOS_ADDR 0xf0000 #define BUILD_BIOS_SIZE 0x10000 +#define BUILD_LOWMEM_SIZE 0x8000 // 32KB for shadow ram copying (works around emulator deficiencies) #define BUILD_BIOS_TMP_ADDR 0x30000 #define BUILD_SMM_INIT_ADDR 0x38000 diff --git a/src/optionroms.c b/src/optionroms.c index 06db1c1..5ce8af8 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -16,12 +16,10 @@ #include "paravirt.h" // qemu_cfg_* #include "optionroms.h" // struct rom_header
-/**************************************************************** - * Definitions - ****************************************************************/ - // The end of the last deployed rom. u32 RomEnd = BUILD_ROM_START; +// The maximum memory location a rom may extend to. +u32 RomTop;
/**************************************************************** @@ -120,15 +118,9 @@ get_pci_rom(struct rom_header *rom) return pd; }
-// Return start of code in 0xc0000-0xf0000 space. -static inline u32 _max_rom(void) { - extern u8 code32flat_start[], code32init_end[]; - return CONFIG_RELOCATE_INIT ? (u32)code32init_end : (u32)code32flat_start; -} // Return the memory position up to which roms may be located. static inline u32 max_rom(void) { - u32 end = _max_rom(); - return end > BUILD_BIOS_ADDR ? BUILD_BIOS_ADDR : end; + return RomTop; }
// Copy a rom to its permanent location below 1MiB diff --git a/src/pmm.c b/src/pmm.c index c649fd8..1648bf2 100644 --- a/src/pmm.c +++ b/src/pmm.c @@ -9,6 +9,7 @@ #include "memmap.h" // struct e820entry #include "farptr.h" // GET_FARVAR #include "biosvar.h" // GET_BDA +#include "optionroms.h" // OPTION_ROM_ALIGN
// Information on a reserved area. struct allocinfo_s { @@ -164,6 +165,15 @@ findLast(struct zone_s *zone) * Setup ****************************************************************/
+// Return start of code in 0xc0000-0xf0000 space. +static inline u32 lowmemend(void) { + extern u8 code32flat_start[], code32init_end[]; + u32 end = CONFIG_RELOCATE_INIT ? (u32)code32init_end : (u32)code32flat_start; + return end > BUILD_BIOS_ADDR ? BUILD_BIOS_ADDR : end; +} + +#define OPROM_HEADER_RESERVE 16 + void malloc_setup(void) { @@ -194,7 +204,9 @@ malloc_setup(void) // Populate other regions addSpace(&ZoneTmpLow, (void*)BUILD_STACK_ADDR, (void*)BUILD_EBDA_MINIMUM); addSpace(&ZoneFSeg, BiosTableSpace, &BiosTableSpace[CONFIG_MAX_BIOSTABLE]); - addSpace(&ZoneLow, (void*)BUILD_LOWRAM_END, (void*)BUILD_LOWRAM_END); + u32 lowend = lowmemend(); + RomTop = ALIGN_DOWN(lowend-BUILD_LOWMEM_SIZE, OPTION_ROM_ALIGN); + addSpace(&ZoneLow, (void*)RomTop + OPROM_HEADER_RESERVE, (void*)lowend); if (highram) { addSpace(&ZoneHigh, (void*)highram , (void*)highram + CONFIG_MAX_HIGHTABLE); @@ -232,12 +244,21 @@ malloc_finalize(void) ASSERT32FLAT(); dprintf(3, "malloc finalize\n");
- // Reserve more low-mem if needed. - u32 endlow = GET_BDA(mem_size_kb)*1024; - add_e820(endlow, BUILD_LOWRAM_END-endlow, E820_RESERVED); + // Place an optionrom signature around used low mem area. + struct allocinfo_s *info = findLast(&ZoneLow); + u32 base = BUILD_BIOS_ADDR; + if (info && info->allocend < (void*)BUILD_BIOS_ADDR) { + base = ALIGN_DOWN((u32)info->allocend - OPROM_HEADER_RESERVE + , OPTION_ROM_ALIGN); + struct rom_header *dummyrom = (void*)base; + dummyrom->signature = OPTION_ROM_SIGNATURE; + dummyrom->size = (BUILD_BIOS_ADDR - base) / 512; + } + memset((void*)RomEnd, 0, base-RomEnd); + dprintf(1, "Space available for UMB: %08x-%08x\n", RomEnd, base);
// Give back unused high ram. - struct allocinfo_s *info = findLast(&ZoneHigh); + info = findLast(&ZoneHigh); if (info) { u32 giveback = ALIGN_DOWN(info->allocend - info->dataend, PAGE_SIZE); add_e820((u32)info->dataend, giveback, E820_RAM); @@ -247,89 +268,6 @@ malloc_finalize(void)
/**************************************************************** - * 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 *info = findLast(&ZoneLow); - if (!info) - return; - 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; - u16 ebda_seg = get_ebda_seg(); - u32 ebda_pos = (u32)MAKE_FLATPTR(ebda_seg, 0); - u8 ebda_size = GET_EBDA2(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; - - // Move ebda - int ret = relocate_ebda(newebda, ebda_pos, ebda_size); - if (ret) - return; - - // Update zone - if (ebda_end == bottom) { - info->data = (void*)newbottom; - info->dataend = (void*)newbottom; - } else - addSpace(&ZoneLow, (void*)newbottom, (void*)ebda_end); -} - -// Check if can expand the given zone to fulfill an allocation -static void * -allocExpandSpace(struct zone_s *zone, u32 size, u32 align - , struct allocinfo_s *fill) -{ - void *data = allocSpace(zone, size, align, fill); - if (data || zone != &ZoneLow) - return data; - - // Make sure to not move ebda while an optionrom is running. - if (unlikely(wait_preempt())) { - data = allocSpace(zone, size, align, fill); - if (data) - return data; - } - - zonelow_expand(size, align); - return allocSpace(zone, size, align, fill); -} - - -/**************************************************************** * tracked memory allocations ****************************************************************/
@@ -352,7 +290,7 @@ pmm_malloc(struct zone_s *zone, u32 handle, u32 size, u32 align) }
// Find and reserve space for main allocation - void *data = allocExpandSpace(zone, size, align, &detail->datainfo); + void *data = allocSpace(zone, size, align, &detail->datainfo); if (!data) { freeSpace(&detail->detailinfo); return NULL; diff --git a/src/shadow.c b/src/shadow.c index c0c8cc2..70f04c5 100644 --- a/src/shadow.c +++ b/src/shadow.c @@ -83,8 +83,8 @@ make_bios_readonly_intel(u16 bdf, u32 pam0) for (i=0; i<6; i++) { u32 mem = BUILD_ROM_START + i * 32*1024; u32 pam = pam0 + 1 + i; - if (RomEnd <= mem + 16*1024) { - if (RomEnd > mem) + if (RomEnd <= mem + 16*1024 || RomTop <= mem + 32*1024) { + if (RomEnd > mem && RomTop > mem + 16*1024) pci_config_writeb(bdf, pam, 0x31); break; } diff --git a/src/util.h b/src/util.h index 70d3c4c..04de66b 100644 --- a/src/util.h +++ b/src/util.h @@ -400,7 +400,7 @@ void call_bcv(u16 seg, u16 ip); void optionrom_setup(void); void vga_setup(void); void s3_resume_vga_init(void); -extern u32 RomEnd; +extern u32 RomEnd, RomTop; extern int ScreenAndDebug;
// bootsplash.c
Add a mechanism (VARLOW declaration) to make a variable reside in the low memory (e-segment) area. This is useful for runtime variables that need to be accessed from 16bit code and need to be modifiable during runtime.
Move the 16bit "extra stack" from the EBDA to the low memory area using this declaration mechanism. Also increase the size of this stack from 512 bytes to 2048 bytes.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/asm-offsets.c | 8 ----- src/ata.c | 4 +-- src/biosvar.h | 8 ----- src/block.c | 2 +- src/config.h | 1 + src/post.c | 48 ++++++++++++++++++++++-------- src/romlayout.S | 9 ++--- src/stacks.c | 7 +++- src/types.h | 4 ++ src/util.h | 1 + tools/layoutrom.py | 81 ++++++++++++++++++++++++++++++++++----------------- 11 files changed, 106 insertions(+), 67 deletions(-)
diff --git a/src/asm-offsets.c b/src/asm-offsets.c index 5035cef..b98f3b5 100644 --- a/src/asm-offsets.c +++ b/src/asm-offsets.c @@ -2,7 +2,6 @@
#include "gen-defs.h" // OFFSET #include "bregs.h" // struct bregs -#include "biosvar.h" // struct bios_data_area_s
/* workaround for a warning with -Wmissing-prototypes */ void foo(void) VISIBLE16; @@ -21,11 +20,4 @@ void foo(void) OFFSET(BREGS_edi, bregs, edi); OFFSET(BREGS_flags, bregs, flags); OFFSET(BREGS_code, bregs, code); - - COMMENT("BDA"); - OFFSET(BDA_ebda_seg, bios_data_area_s, ebda_seg); - - COMMENT("EBDA"); - DEFINE(EBDA_OFFSET_TOP_STACK, EBDA_OFFSET_TOP_STACK); - DEFINE(EBDA_SEGMENT_START, EBDA_SEGMENT_START); } diff --git a/src/ata.c b/src/ata.c index c37691a..b8b0cb3 100644 --- a/src/ata.c +++ b/src/ata.c @@ -396,9 +396,7 @@ ata_try_dma(struct disk_op_s *op, int iswrite, int blocksize) return -1;
// Build PRD dma structure. - struct sff_dma_prd *dma = MAKE_FLATPTR( - get_ebda_seg() - , (void*)offsetof(struct extended_bios_data_area_s, extra_stack)); + struct sff_dma_prd *dma = (void*)ExtraStack; struct sff_dma_prd *origdma = dma; while (bytes) { if (dma >= &origdma[16]) diff --git a/src/biosvar.h b/src/biosvar.h index b6f7174..0674df6 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -242,9 +242,6 @@ struct extended_bios_data_area_s { /* TSC emulation timekeepers */ u64 tsc_8254; int last_tsc_8254; - - // Stack space available for code that needs it. - u8 extra_stack[512] __aligned(8); } PACKED;
// The initial size and location of EBDA @@ -272,11 +269,6 @@ get_ebda_ptr(void) #define SET_EBDA(var, val) \ SET_EBDA2(get_ebda_seg(), var, (val))
-#define EBDA_OFFSET_TOP_STACK \ - offsetof(struct extended_bios_data_area_s, extra_stack[ \ - FIELD_SIZEOF(struct extended_bios_data_area_s \ - , extra_stack)]) -
/**************************************************************** * Global variables diff --git a/src/block.c b/src/block.c index a80199c..263fa30 100644 --- a/src/block.c +++ b/src/block.c @@ -328,7 +328,7 @@ process_op(struct disk_op_s *op) } }
-// Execute a "disk_op_s" request - this runs on a stack in the ebda. +// Execute a "disk_op_s" request - this runs on the extra stack. static int __send_disk_op(struct disk_op_s *op_far, u16 op_seg) { diff --git a/src/config.h b/src/config.h index 521469b..23591b9 100644 --- a/src/config.h +++ b/src/config.h @@ -39,6 +39,7 @@ #define BUILD_BIOS_ADDR 0xf0000 #define BUILD_BIOS_SIZE 0x10000 #define BUILD_LOWMEM_SIZE 0x8000 +#define BUILD_EXTRA_STACK_SIZE 0x800 // 32KB for shadow ram copying (works around emulator deficiencies) #define BUILD_BIOS_TMP_ADDR 0x30000 #define BUILD_SMM_INIT_ADDR 0x38000 diff --git a/src/post.c b/src/post.c index 8383b79..3561c0d 100644 --- a/src/post.c +++ b/src/post.c @@ -211,9 +211,6 @@ startBoot(void) static void maininit(void) { - // Running at new code address - do code relocation fixups - malloc_fixupreloc(); - // Setup ivt/bda/ebda init_ivt(); init_bda(); @@ -287,6 +284,21 @@ maininit(void) * POST entry and code relocation ****************************************************************/
+// Relocation fixup code that runs at new address after relocation complete. +static void +afterReloc(void *datalow) +{ + // Running at new code address - do code relocation fixups + malloc_fixupreloc(); + + // Move low-memory initial variable content to new location. + extern u8 datalow_start[], datalow_end[]; + memmove(datalow, datalow_start, datalow_end - datalow_start); + + // Run main code + maininit(); +} + // Update given relocs for the code at 'dest' with a given 'delta' static void updateRelocs(void *dest, u32 *rstart, u32 *rend, u32 delta) @@ -311,27 +323,37 @@ reloc_init(void) extern u32 _reloc_rel_start[], _reloc_rel_end[]; extern u32 _reloc_init_start[], _reloc_init_end[]; extern u8 code32init_start[], code32init_end[]; + extern u32 _reloc_datalow_start[], _reloc_datalow_end[]; + extern u8 _datalow_min_align[]; + extern u8 datalow_start[], datalow_end[];
// Allocate space for init code. u32 initsize = code32init_end - code32init_start; - u32 align = (u32)&_reloc_min_align; - void *dest = memalign_tmp(align, initsize); - if (!dest) + u32 codealign = (u32)&_reloc_min_align; + void *codedest = memalign_tmp(codealign, initsize); + u32 datalowsize = datalow_end - datalow_start; + u32 datalowalign = (u32)&_datalow_min_align; + void *datalow = memalign_low(datalowalign, datalowsize); + if (!codedest || !datalow) panic("No space for init relocation.\n");
// Copy code and update relocs (init absolute, init relative, and runtime) + dprintf(1, "Relocating low data from %p to %p (size %d)\n" + , datalow_start, datalow, datalowsize); + updateRelocs(code32flat_start, _reloc_datalow_start, _reloc_datalow_end + , datalow - (void*)datalow_start); dprintf(1, "Relocating init from %p to %p (size %d)\n" - , code32init_start, dest, initsize); - s32 delta = dest - (void*)code32init_start; - memcpy(dest, code32init_start, initsize); - updateRelocs(dest, _reloc_abs_start, _reloc_abs_end, delta); - updateRelocs(dest, _reloc_rel_start, _reloc_rel_end, -delta); + , code32init_start, codedest, initsize); + s32 delta = codedest - (void*)code32init_start; + memcpy(codedest, code32init_start, initsize); + updateRelocs(codedest, _reloc_abs_start, _reloc_abs_end, delta); + updateRelocs(codedest, _reloc_rel_start, _reloc_rel_end, -delta); updateRelocs(code32flat_start, _reloc_init_start, _reloc_init_end, delta);
// Call maininit() in relocated code. - void (*func)(void) = (void*)maininit + delta; + void (*func)(void*) = (void*)afterReloc + delta; barrier(); - func(); + func(datalow); }
// Setup for code relocation and then call reloc_init diff --git a/src/romlayout.S b/src/romlayout.S index c4b2ef1..917a6fe 100644 --- a/src/romlayout.S +++ b/src/romlayout.S @@ -232,13 +232,12 @@ entry_resume: // Disable interrupts cli cld - // Use a stack in EBDA - movw $SEG_BDA, %ax - movw %ax, %ds - movw BDA_ebda_seg, %ax + // Use the ExtraStack in low mem. + movl $ExtraStack, %eax + shrl $4, %eax movw %ax, %ds movw %ax, %ss - movl $EBDA_OFFSET_TOP_STACK, %esp + movl $BUILD_EXTRA_STACK_SIZE, %esp // Call handler. jmp handle_resume
diff --git a/src/stacks.c b/src/stacks.c index 17f1a4a..659e5bf 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -152,12 +152,15 @@ wait_irq(void) * Stack in EBDA ****************************************************************/
+// Space for a stack for 16bit code. +char ExtraStack[BUILD_EXTRA_STACK_SIZE] VARLOW __aligned(16); + // Switch to the extra stack in ebda and call a function. inline u32 stack_hop(u32 eax, u32 edx, void *func) { ASSERT16(); - u16 ebda_seg = get_ebda_seg(), bkup_ss; + u16 stack_seg = FLATPTR_TO_SEG(ExtraStack), bkup_ss; u32 bkup_esp; asm volatile( // Backup current %ss/%esp values. @@ -174,7 +177,7 @@ stack_hop(u32 eax, u32 edx, void *func) "movw %w3, %%ss\n" "movl %4, %%esp" : "+a" (eax), "+d" (edx), "+c" (func), "=&r" (bkup_ss), "=&r" (bkup_esp) - : "i" (EBDA_OFFSET_TOP_STACK), "r" (ebda_seg) + : "i" (BUILD_EXTRA_STACK_SIZE), "r" (stack_seg) : "cc", "memory"); return eax; } diff --git a/src/types.h b/src/types.h index c0c6d26..0f83697 100644 --- a/src/types.h +++ b/src/types.h @@ -61,6 +61,8 @@ extern void __force_link_error__only_in_16bit(void) __noreturn; # 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 top-level assembler as 16bit only. # define ASM16(code) __ASM(code) // Designate top-level assembler as 32bit flat only. @@ -80,6 +82,7 @@ extern void __force_link_error__only_in_16bit(void) __noreturn; # define VAR16FIXED(addr) VAR16VISIBLE # define VAR32SEG __section(".data32seg." UNIQSEC) # define VAR32FLATVISIBLE __section(".discard.var32flat." UNIQSEC) __VISIBLE __weak +# define VARLOW __section(".discard.varlow." UNIQSEC) __VISIBLE __weak # define ASM16(code) # define ASM32FLAT(code) # define ASSERT16() __force_link_error__only_in_16bit() @@ -96,6 +99,7 @@ extern void __force_link_error__only_in_16bit(void) __noreturn; # define VAR16FIXED(addr) VAR16VISIBLE # define VAR32SEG __section(".discard.var32seg." UNIQSEC) # define VAR32FLATVISIBLE __section(".data.runtime." UNIQSEC) __VISIBLE +# define VARLOW __section(".datalow." UNIQSEC) __VISIBLE # define ASM16(code) # define ASM32FLAT(code) __ASM(code) # define ASSERT16() __force_link_error__only_in_16bit() diff --git a/src/util.h b/src/util.h index 04de66b..0c731fe 100644 --- a/src/util.h +++ b/src/util.h @@ -230,6 +230,7 @@ int get_keystroke(int msec);
// stacks.c u32 call32(void *func, u32 eax, u32 errret); +extern char ExtraStack[]; inline u32 stack_hop(u32 eax, u32 edx, void *func); extern struct thread_info MainThread; extern int CanPreempt; diff --git a/tools/layoutrom.py b/tools/layoutrom.py index 86e1f33..bf4a9c4 100755 --- a/tools/layoutrom.py +++ b/tools/layoutrom.py @@ -144,7 +144,7 @@ def getSectionsPrefix(sections, category, prefix): return [section for section in sections if section.category == category and section.name.startswith(prefix)]
-def doLayout(sections): +def doLayout(sections, genreloc): # Determine 16bit positions textsections = getSectionsPrefix(sections, '16', '.text.') rodatasections = ( @@ -190,15 +190,25 @@ def doLayout(sections): textsections + rodatasections + datasections + bsssections , code32flat_start, 16)
+ datalowsections = getSectionsPrefix(sections, '32flat', '.datalow.') + for section in datalowsections: + section.category = '32low' + datalowtop = code32init_start + if genreloc: + datalowtop = min(datalowtop, BUILD_BIOS_ADDR) + datalow_start = setSectionsStart(datalowsections, datalowtop, 16) + # Print statistics size16 = BUILD_BIOS_SIZE - code16_start size32seg = code16_start - code32seg_start size32flat = code32seg_start + BUILD_BIOS_ADDR - code32flat_start size32init = code32flat_start - code32init_start + sizelow = code32init_start - datalow_start print "16bit size: %d" % size16 print "32bit segmented size: %d" % size32seg print "32bit flat size: %d" % size32flat print "32bit flat init size: %d" % size32init + print "lowmem size: %d" % sizelow
###################################################################### @@ -235,6 +245,7 @@ def outRelSections(sections, startsym): out += "*(%s)\n" % (section.name,) return out
+# Return the sections with the given fileid (ie, one input object file). def getSectionsFile(sections, fileid, defaddr=0): sections = [(section.finalloc, section) for section in sections if section.fileid == fileid] @@ -279,24 +290,31 @@ def writeLinkerScripts(sections, entrysym, genreloc, out16, out32seg, out32flat) # Write 32flat linker script sections32flat, code32flat_start = getSectionsFile( sections, '32flat', code32seg_start) - relocstr = "" - relocminalign = 0 + relocstr = relocdefstr = "" if genreloc: # Generate relocations - relocstr, size, relocminalign = genRelocs(sections) + relocstr, size, relocdefstr = genRelocs(sections) code32flat_start -= size output = open(out32flat, 'wb') output.write(COMMONHEADER + outXRefs(sections32flat) + """ %s = 0x%x ; - _reloc_min_align = 0x%x ; +%s code32flat_start = 0x%x ; .text code32flat_start : { """ % (entrysym.name, entrysym.section.finalloc + entrysym.offset + BUILD_BIOS_ADDR, - relocminalign, code32flat_start) + relocdefstr, code32flat_start) + relocstr + """ + datalow_start = ABSOLUTE(.) ; +""" + + outRelSections(getSectionsPrefix(sections32flat, '32low', '') + , 'code32flat_start') + + """ + datalow_end = ABSOLUTE(.) ; +""" + + """ code32init_start = ABSOLUTE(.) ; """ + outRelSections(getSectionsPrefix(sections32flat, '32init', '') @@ -329,20 +347,31 @@ PHDRS # Detection of init code ######################################################################
+def strRelocs(outname, outrel, relocs): + return (" %s_start = ABSOLUTE(.) ;\n" % (outname,) + + "".join(["LONG(0x%x - %s)\n" % (pos, outrel) + for pos in relocs]) + + " %s_end = ABSOLUTE(.) ;\n" % (outname,)) + # Determine init section relocations def genRelocs(sections): absrelocs = [] relrelocs = [] initrelocs = [] - minalign = 16 + datalowrelocs = [] + mincodealign = mindatalowalign = 16 for section in sections: - if section.category == '32init' and section.align > minalign: - minalign = section.align + if section.category == '32init' and section.align > mincodealign: + mincodealign = section.align + elif section.category == '32low' and section.align > mindatalowalign: + mindatalowalign = section.align for reloc in section.relocs: symbol = reloc.symbol if symbol.section is None: continue relocpos = section.finalloc + reloc.offset + if section.fileid in ('16', '32seg'): + relocpos += BUILD_BIOS_ADDR if (reloc.type == 'R_386_32' and section.category == '32init' and symbol.section.category == '32init'): # Absolute relocation @@ -354,25 +383,22 @@ def genRelocs(sections): elif (section.category != '32init' and symbol.section.category == '32init'): # Relocation to the init section - if section.fileid in ('16', '32seg'): - relocpos += BUILD_BIOS_ADDR initrelocs.append(relocpos) + if symbol.section.category == '32low': + # Relocation to the low memory section + datalowrelocs.append(relocpos) absrelocs.sort() relrelocs.sort() initrelocs.sort() - out = (" _reloc_abs_start = ABSOLUTE(.) ;\n" - + "".join(["LONG(0x%x - code32init_start)\n" % (pos,) - for pos in absrelocs]) - + " _reloc_abs_end = ABSOLUTE(.) ;\n" - + " _reloc_rel_start = ABSOLUTE(.) ;\n" - + "".join(["LONG(0x%x - code32init_start)\n" % (pos,) - for pos in relrelocs]) - + " _reloc_rel_end = ABSOLUTE(.) ;\n" - + " _reloc_init_start = ABSOLUTE(.) ;\n" - + "".join(["LONG(0x%x - code32flat_start)\n" % (pos,) - for pos in initrelocs]) - + " _reloc_init_end = ABSOLUTE(.) ;\n") - return out, len(absrelocs + relrelocs + initrelocs) * 4, minalign + datalowrelocs.sort() + relocstr = (strRelocs("_reloc_abs", "code32init_start", absrelocs) + + strRelocs("_reloc_rel", "code32init_start", relrelocs) + + strRelocs("_reloc_init", "code32flat_start", initrelocs) + + strRelocs("_reloc_datalow", "code32flat_start", datalowrelocs)) + relocdefstr = (" _reloc_min_align = 0x%x ;\n" % (mincodealign,) + + " _datalow_min_align = 0x%x ;\n" % (mindatalowalign,)) + numrelocs = len(absrelocs + relrelocs + initrelocs + datalowrelocs) + return relocstr, numrelocs * 4, relocdefstr
def markRuntime(section, sections): if (section is None or not section.keep or section.category is not None @@ -386,7 +412,8 @@ def markRuntime(section, sections): def findInit(sections): # Recursively find and mark all "runtime" sections. for section in sections: - if '.runtime.' in section.name or '.export.' in section.name: + if ('.datalow.' in section.name or '.runtime.' in section.name + or '.export.' in section.name): markRuntime(section, sections) for section in sections: if section.category is not None: @@ -572,11 +599,11 @@ def main(): findInit(sections)
# Determine the final memory locations of each kept section. - doLayout(sections) + genreloc = '_reloc_abs_start' in info32flat[1] + doLayout(sections, genreloc)
# Write out linker script files. entrysym = info16[1]['entry_elf'] - genreloc = '_reloc_abs_start' in info32flat[1] writeLinkerScripts(sections, entrysym, genreloc, out16, out32seg, out32flat)
if __name__ == '__main__':
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/biosvar.h | 6 ------ src/clock.c | 32 +++++++++++++++++--------------- 2 files changed, 17 insertions(+), 21 deletions(-)
diff --git a/src/biosvar.h b/src/biosvar.h index 0674df6..5a77f7d 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -226,8 +226,6 @@ struct extended_bios_data_area_s { u8 ps2ctr; struct usbkeyinfo usbkey_last;
- int RTCusers; - // El Torito Emulation data struct cdemu_s cdemu;
@@ -238,10 +236,6 @@ struct extended_bios_data_area_s { u8 cdrom_locks[CONFIG_MAX_EXTDRIVE];
u16 boot_sequence; - - /* TSC emulation timekeepers */ - u64 tsc_8254; - int last_tsc_8254; } PACKED;
// The initial size and location of EBDA diff --git a/src/clock.c b/src/clock.c index e8a48a1..5767996 100644 --- a/src/clock.c +++ b/src/clock.c @@ -108,22 +108,24 @@ calibrate_tsc(void) dprintf(1, "CPU Mhz=%u\n", hz / 1000000); }
+/* TSC emulation timekeepers */ +u64 TSC_8254 VARLOW; +int Last_TSC_8254 VARLOW; + static u64 emulate_tsc(void) { - int cnt, d; - u16 ebda_seg = get_ebda_seg(); - u64 ret; /* read timer 0 current count */ - ret = GET_EBDA2(ebda_seg, tsc_8254); - /* readback mode has slightly shifted registers, works on all 8254, readback PIT0 latch */ + u64 ret = GET_FLATPTR(TSC_8254); + /* readback mode has slightly shifted registers, works on all + * 8254, readback PIT0 latch */ outb(PM_SEL_READBACK | PM_READ_VALUE | PM_READ_COUNTER0, PORT_PIT_MODE); - cnt = (inb(PORT_PIT_COUNTER0) | (inb(PORT_PIT_COUNTER0) << 8)); - d = GET_EBDA2(ebda_seg, last_tsc_8254) - cnt; + int cnt = (inb(PORT_PIT_COUNTER0) | (inb(PORT_PIT_COUNTER0) << 8)); + int d = GET_FLATPTR(Last_TSC_8254) - cnt; /* Determine the ticks count from last invocation of this function */ ret += (d > 0) ? d : (PIT_TICK_INTERVAL + d); - SET_EBDA2(ebda_seg, last_tsc_8254, cnt); - SET_EBDA2(ebda_seg, tsc_8254, ret); + SET_FLATPTR(Last_TSC_8254, cnt); + SET_FLATPTR(TSC_8254, ret); return ret; }
@@ -545,12 +547,13 @@ handle_08(void) * Periodic timer ****************************************************************/
+int RTCusers VARLOW; + void useRTC(void) { - u16 ebda_seg = get_ebda_seg(); - int count = GET_EBDA2(ebda_seg, RTCusers); - SET_EBDA2(ebda_seg, RTCusers, count+1); + int count = GET_FLATPTR(RTCusers); + SET_FLATPTR(RTCusers, count+1); if (count) return; // Turn on the Periodic Interrupt timer @@ -561,9 +564,8 @@ useRTC(void) void releaseRTC(void) { - u16 ebda_seg = get_ebda_seg(); - int count = GET_EBDA2(ebda_seg, RTCusers); - SET_EBDA2(ebda_seg, RTCusers, count-1); + int count = GET_FLATPTR(RTCusers); + SET_FLATPTR(RTCusers, count-1); if (count != 1) return; // Clear the Periodic Interrupt.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/biosvar.h | 2 -- src/boot.c | 13 ++++++------- 2 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/src/biosvar.h b/src/biosvar.h index 5a77f7d..6758f1a 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -234,8 +234,6 @@ struct extended_bios_data_area_s {
// Locks for removable devices u8 cdrom_locks[CONFIG_MAX_EXTDRIVE]; - - u16 boot_sequence; } PACKED;
// The initial size and location of EBDA diff --git a/src/boot.c b/src/boot.c index 4447b9a..d160b95 100644 --- a/src/boot.c +++ b/src/boot.c @@ -238,8 +238,6 @@ boot_setup(void) if (! CONFIG_BOOT) return;
- SET_EBDA(boot_sequence, 0xffff); - if (!CONFIG_COREBOOT) { // On emulators, get boot order from nvram. if (inb_cmos(CMOS_BIOS_BOOTFLAG1) & 1) @@ -642,7 +640,7 @@ boot_fail(void)
// Determine next boot method and attempt a boot using it. static void -do_boot(u16 seq_nr) +do_boot(int seq_nr) { if (! CONFIG_BOOT) panic("Boot support not compiled in.\n"); @@ -679,15 +677,16 @@ do_boot(u16 seq_nr) call16_int(0x18, &br); }
+int BootSequence VARLOW = -1; + // Boot Failure recovery: try the next device. void VISIBLE32FLAT handle_18(void) { debug_serial_setup(); debug_enter(NULL, DEBUG_HDL_18); - u16 ebda_seg = get_ebda_seg(); - u16 seq = GET_EBDA2(ebda_seg, boot_sequence) + 1; - SET_EBDA2(ebda_seg, boot_sequence, seq); + u16 seq = GET_FLATPTR(BootSequence) + 1; + SET_FLATPTR(BootSequence, seq); do_boot(seq); }
@@ -697,6 +696,6 @@ handle_19(void) { debug_serial_setup(); debug_enter(NULL, DEBUG_HDL_19); - SET_EBDA(boot_sequence, 0); + SET_FLATPTR(BootSequence, 0); do_boot(0); }
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/biosvar.h | 1 - src/ps2port.c | 18 +++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/src/biosvar.h b/src/biosvar.h index 6758f1a..cf601ee 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -223,7 +223,6 @@ struct extended_bios_data_area_s { u8 other2[0xC4];
// 0x121 - Begin custom storage. - u8 ps2ctr; struct usbkeyinfo usbkey_last;
// El Torito Emulation data diff --git a/src/ps2port.c b/src/ps2port.c index 4b27b7a..a63a28c 100644 --- a/src/ps2port.c +++ b/src/ps2port.c @@ -8,7 +8,6 @@ #include "ioport.h" // inb #include "util.h" // dprintf #include "paravirt.h" // romfile_loadint -#include "biosvar.h" // GET_EBDA #include "ps2port.h" // ps2_kbd_command #include "pic.h" // eoi_pic1
@@ -208,6 +207,8 @@ ps2_sendbyte(int aux, u8 command, int timeout) return 0; }
+u8 Ps2ctr VARLOW; + static int __ps2_command(int aux, int command, u8 *param) { @@ -216,7 +217,7 @@ __ps2_command(int aux, int command, u8 *param) int send = (command >> 12) & 0xf;
// Disable interrupts and keyboard/mouse. - u8 ps2ctr = GET_EBDA(ps2ctr); + u8 ps2ctr = GET_FLATPTR(Ps2ctr); u8 newctr = ((ps2ctr | I8042_CTR_AUXDIS | I8042_CTR_KBDDIS) & ~(I8042_CTR_KBDINT|I8042_CTR_AUXINT)); dprintf(6, "i8042 ctr old=%x new=%x\n", ps2ctr, newctr); @@ -337,13 +338,12 @@ ps2_mouse_command(int command, u8 *param)
// Update ps2ctr for mouse enable/disable. if (command == PSMOUSE_CMD_ENABLE || command == PSMOUSE_CMD_DISABLE) { - u16 ebda_seg = get_ebda_seg(); - u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr); + u8 ps2ctr = GET_FLATPTR(Ps2ctr); if (command == PSMOUSE_CMD_ENABLE) ps2ctr = (ps2ctr | I8042_CTR_AUXINT) & ~I8042_CTR_AUXDIS; else ps2ctr = (ps2ctr | I8042_CTR_AUXDIS) & ~I8042_CTR_AUXINT; - SET_EBDA2(ebda_seg, ps2ctr, ps2ctr); + SET_FLATPTR(Ps2ctr, ps2ctr); }
return ps2_command(1, command, param); @@ -371,7 +371,7 @@ handle_74(void) } v = inb(PORT_PS2_DATA);
- if (!(GET_EBDA(ps2ctr) & I8042_CTR_AUXINT)) + if (!(GET_FLATPTR(Ps2ctr) & I8042_CTR_AUXINT)) // Interrupts not enabled. goto done;
@@ -398,7 +398,7 @@ handle_09(void) } v = inb(PORT_PS2_DATA);
- if (!(GET_EBDA(ps2ctr) & I8042_CTR_KBDINT)) + if (!(GET_FLATPTR(Ps2ctr) & I8042_CTR_KBDINT)) // Interrupts not enabled. goto done;
@@ -444,7 +444,7 @@ keyboard_init(void *data) }
// Disable keyboard and mouse events. - SET_EBDA(ps2ctr, I8042_CTR_KBDDIS | I8042_CTR_AUXDIS); + SET_FLATPTR(Ps2ctr, I8042_CTR_KBDDIS | I8042_CTR_AUXDIS);
/* ------------------- keyboard side ------------------------*/ @@ -479,7 +479,7 @@ keyboard_init(void *data) return;
// Keyboard Mode: disable mouse, scan code convert, enable kbd IRQ - SET_EBDA(ps2ctr, I8042_CTR_AUXDIS | I8042_CTR_XLATE | I8042_CTR_KBDINT); + SET_FLATPTR(Ps2ctr, I8042_CTR_AUXDIS | I8042_CTR_XLATE | I8042_CTR_KBDINT);
/* Enable keyboard */ ret = ps2_kbd_command(ATKBD_CMD_ENABLE, NULL);
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/biosvar.h | 12 ------------ src/usb-hid.c | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/src/biosvar.h b/src/biosvar.h index cf601ee..b7df42b 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -195,17 +195,6 @@ struct fdpt_s { u8 checksum; } PACKED;
-struct usbkeyinfo { - union { - struct { - u8 modifiers; - u8 repeatcount; - u8 keys[6]; - }; - u64 data; - }; -}; - struct extended_bios_data_area_s { u8 size; u8 reserved1[0x21]; @@ -223,7 +212,6 @@ struct extended_bios_data_area_s { u8 other2[0xC4];
// 0x121 - Begin custom storage. - struct usbkeyinfo usbkey_last;
// El Torito Emulation data struct cdemu_s cdemu; diff --git a/src/usb-hid.c b/src/usb-hid.c index 6e8ec4e..90e860c 100644 --- a/src/usb-hid.c +++ b/src/usb-hid.c @@ -211,6 +211,18 @@ procmodkey(u8 mods, u8 flags) } }
+struct usbkeyinfo { + union { + struct { + u8 modifiers; + u8 repeatcount; + u8 keys[6]; + }; + u64 data; + }; +}; +struct usbkeyinfo LastUSBkey VARLOW; + // Process USB keyboard data. static void noinline handle_key(struct keyevent *data) @@ -218,9 +230,8 @@ handle_key(struct keyevent *data) dprintf(9, "Got key %x %x\n", data->modifiers, data->keys[0]);
// Load old keys. - u16 ebda_seg = get_ebda_seg(); struct usbkeyinfo old; - old.data = GET_EBDA2(ebda_seg, usbkey_last.data); + old.data = GET_FLATPTR(LastUSBkey.data);
// Check for keys no longer pressed. int addpos = 0; @@ -273,7 +284,7 @@ handle_key(struct keyevent *data) }
// Update old keys - SET_EBDA2(ebda_seg, usbkey_last.data, old.data); + SET_FLATPTR(LastUSBkey.data, old.data); }
// Check if a USB keyboard event is pending and process it if so.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/biosvar.h | 40 ---------------------------- src/block.c | 1 + src/boot.c | 6 +--- src/cdrom.c | 80 ++++++++++++++++++++++++++++---------------------------- src/disk.c | 71 ++++++++++++++++++++++---------------------------- src/disk.h | 38 +++++++++++++++++++++++++- 6 files changed, 110 insertions(+), 126 deletions(-)
diff --git a/src/biosvar.h b/src/biosvar.h index b7df42b..5993718 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -149,37 +149,6 @@ struct bios_data_area_s { * Extended Bios Data Area (EBDA) ****************************************************************/
-// 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; -}; - -// 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 fdpt_s { u16 cylinders; u8 heads; @@ -212,15 +181,6 @@ struct extended_bios_data_area_s { u8 other2[0xC4];
// 0x121 - Begin custom storage. - - // El Torito Emulation data - struct cdemu_s cdemu; - - // Buffer for disk DPTE table - struct dpte_s dpte; - - // Locks for removable devices - u8 cdrom_locks[CONFIG_MAX_EXTDRIVE]; } PACKED;
// The initial size and location of EBDA diff --git a/src/block.c b/src/block.c index 263fa30..1ea2b60 100644 --- a/src/block.c +++ b/src/block.c @@ -18,6 +18,7 @@ u8 FloppyCount VAR16VISIBLE; u8 CDCount; struct drive_s *IDMap[3][CONFIG_MAX_EXTDRIVE] VAR16VISIBLE; u8 *bounce_buf_fl VAR16VISIBLE; +struct dpte_s DefaultDPTE VARLOW;
struct drive_s * getDrive(u8 exttype, u8 extdriveoffset) diff --git a/src/boot.c b/src/boot.c index d160b95..e30f221 100644 --- a/src/boot.c +++ b/src/boot.c @@ -6,7 +6,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "util.h" // dprintf -#include "biosvar.h" // GET_EBDA #include "config.h" // CONFIG_* #include "disk.h" // cdrom_boot #include "bregs.h" // struct bregs @@ -585,9 +584,8 @@ boot_cdrom(struct drive_s *drive_g) return; }
- u16 ebda_seg = get_ebda_seg(); - u8 bootdrv = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive); - u16 bootseg = GET_EBDA2(ebda_seg, cdemu.load_segment); + u8 bootdrv = GET_FLATPTR(CDEmu.emulated_extdrive); + u16 bootseg = GET_FLATPTR(CDEmu.load_segment); /* Canonicalize bootseg:bootip */ u16 bootip = (bootseg & 0x0fff) << 4; bootseg &= 0xf000; diff --git a/src/cdrom.c b/src/cdrom.c index 170ffc4..2414746 100644 --- a/src/cdrom.c +++ b/src/cdrom.c @@ -8,27 +8,30 @@ #include "disk.h" // cdrom_13 #include "util.h" // memset #include "bregs.h" // struct bregs -#include "biosvar.h" // GET_EBDA +#include "biosvar.h" // GET_GLOBAL #include "ata.h" // ATA_CMD_REQUEST_SENSE #include "blockcmd.h" // CDB_CMD_REQUEST_SENSE
+// Locks for removable devices +u8 CDRom_locks[CONFIG_MAX_EXTDRIVE] VARLOW; +
/**************************************************************** * CD emulation ****************************************************************/
+struct cdemu_s CDEmu VARLOW; struct drive_s *cdemu_drive_gf VAR16VISIBLE;
static int cdemu_read(struct disk_op_s *op) { - u16 ebda_seg = get_ebda_seg(); struct drive_s *drive_g; - drive_g = GLOBALFLAT2GLOBAL(GET_EBDA2(ebda_seg, cdemu.emulated_drive_gf)); + drive_g = GLOBALFLAT2GLOBAL(GET_FLATPTR(CDEmu.emulated_drive_gf)); struct disk_op_s dop; dop.drive_g = drive_g; dop.command = op->command; - dop.lba = GET_EBDA2(ebda_seg, cdemu.ilba) + op->lba / 4; + dop.lba = GET_FLATPTR(CDEmu.ilba) + op->lba / 4;
int count = op->count; op->count = 0; @@ -149,29 +152,27 @@ void cdemu_134b(struct bregs *regs) { // FIXME ElTorito Hardcoded - u16 ebda_seg = get_ebda_seg(); SET_INT13ET(regs, size, 0x13); - SET_INT13ET(regs, media, GET_EBDA2(ebda_seg, cdemu.media)); - SET_INT13ET(regs, emulated_drive - , GET_EBDA2(ebda_seg, cdemu.emulated_extdrive)); - struct drive_s *drive_gf = GET_EBDA2(ebda_seg, cdemu.emulated_drive_gf); + SET_INT13ET(regs, media, GET_FLATPTR(CDEmu.media)); + SET_INT13ET(regs, emulated_drive, GET_FLATPTR(CDEmu.emulated_extdrive)); + struct drive_s *drive_gf = GET_FLATPTR(CDEmu.emulated_drive_gf); u8 cntl_id = 0; if (drive_gf) cntl_id = GET_GLOBALFLAT(drive_gf->cntl_id); SET_INT13ET(regs, controller_index, cntl_id / 2); SET_INT13ET(regs, device_spec, cntl_id % 2); - SET_INT13ET(regs, ilba, GET_EBDA2(ebda_seg, cdemu.ilba)); - SET_INT13ET(regs, buffer_segment, GET_EBDA2(ebda_seg, cdemu.buffer_segment)); - SET_INT13ET(regs, load_segment, GET_EBDA2(ebda_seg, cdemu.load_segment)); - SET_INT13ET(regs, sector_count, GET_EBDA2(ebda_seg, cdemu.sector_count)); - SET_INT13ET(regs, cylinders, GET_EBDA2(ebda_seg, cdemu.lchs.cylinders)); - SET_INT13ET(regs, sectors, GET_EBDA2(ebda_seg, cdemu.lchs.spt)); - SET_INT13ET(regs, heads, GET_EBDA2(ebda_seg, cdemu.lchs.heads)); + SET_INT13ET(regs, ilba, GET_FLATPTR(CDEmu.ilba)); + SET_INT13ET(regs, buffer_segment, GET_FLATPTR(CDEmu.buffer_segment)); + SET_INT13ET(regs, load_segment, GET_FLATPTR(CDEmu.load_segment)); + SET_INT13ET(regs, sector_count, GET_FLATPTR(CDEmu.sector_count)); + SET_INT13ET(regs, cylinders, GET_FLATPTR(CDEmu.lchs.cylinders)); + SET_INT13ET(regs, sectors, GET_FLATPTR(CDEmu.lchs.spt)); + SET_INT13ET(regs, heads, GET_FLATPTR(CDEmu.lchs.heads));
// If we have to terminate emulation if (regs->al == 0x00) { // FIXME ElTorito Various. Should be handled accordingly to spec - SET_EBDA2(ebda_seg, cdemu.active, 0x00); // bye bye + SET_FLATPTR(CDEmu.active, 0x00); // bye bye
// XXX - update floppy/hd count. } @@ -237,23 +238,22 @@ cdrom_boot(struct drive_s *drive_g) if (buffer[0x20] != 0x88) return 11; // Bootable
- u16 ebda_seg = get_ebda_seg(); u8 media = buffer[0x21]; - SET_EBDA2(ebda_seg, cdemu.media, media); + SET_FLATPTR(CDEmu.media, media);
- SET_EBDA2(ebda_seg, cdemu.emulated_drive_gf, dop.drive_g); + SET_FLATPTR(CDEmu.emulated_drive_gf, dop.drive_g);
u16 boot_segment = *(u16*)&buffer[0x22]; if (!boot_segment) boot_segment = 0x07C0; - SET_EBDA2(ebda_seg, cdemu.load_segment, boot_segment); - SET_EBDA2(ebda_seg, cdemu.buffer_segment, 0x0000); + SET_FLATPTR(CDEmu.load_segment, boot_segment); + SET_FLATPTR(CDEmu.buffer_segment, 0x0000);
u16 nbsectors = *(u16*)&buffer[0x26]; - SET_EBDA2(ebda_seg, cdemu.sector_count, nbsectors); + SET_FLATPTR(CDEmu.sector_count, nbsectors);
lba = *(u32*)&buffer[0x28]; - SET_EBDA2(ebda_seg, cdemu.ilba, lba); + SET_FLATPTR(CDEmu.ilba, lba);
// And we read the image in memory dop.lba = lba; @@ -265,7 +265,7 @@ cdrom_boot(struct drive_s *drive_g)
if (media == 0) { // No emulation requested - return success. - SET_EBDA2(ebda_seg, cdemu.emulated_extdrive, EXTSTART_CD + cdid); + SET_FLATPTR(CDEmu.emulated_extdrive, EXTSTART_CD + cdid); return 0; }
@@ -277,30 +277,30 @@ cdrom_boot(struct drive_s *drive_g) // number of devices if (media < 4) { // Floppy emulation - SET_EBDA2(ebda_seg, cdemu.emulated_extdrive, 0x00); + SET_FLATPTR(CDEmu.emulated_extdrive, 0x00); // XXX - get and set actual floppy count. SETBITS_BDA(equipment_list_flags, 0x41);
switch (media) { case 0x01: // 1.2M floppy - SET_EBDA2(ebda_seg, cdemu.lchs.spt, 15); - SET_EBDA2(ebda_seg, cdemu.lchs.cylinders, 80); - SET_EBDA2(ebda_seg, cdemu.lchs.heads, 2); + SET_FLATPTR(CDEmu.lchs.spt, 15); + SET_FLATPTR(CDEmu.lchs.cylinders, 80); + SET_FLATPTR(CDEmu.lchs.heads, 2); break; case 0x02: // 1.44M floppy - SET_EBDA2(ebda_seg, cdemu.lchs.spt, 18); - SET_EBDA2(ebda_seg, cdemu.lchs.cylinders, 80); - SET_EBDA2(ebda_seg, cdemu.lchs.heads, 2); + SET_FLATPTR(CDEmu.lchs.spt, 18); + SET_FLATPTR(CDEmu.lchs.cylinders, 80); + SET_FLATPTR(CDEmu.lchs.heads, 2); break; case 0x03: // 2.88M floppy - SET_EBDA2(ebda_seg, cdemu.lchs.spt, 36); - SET_EBDA2(ebda_seg, cdemu.lchs.cylinders, 80); - SET_EBDA2(ebda_seg, cdemu.lchs.heads, 2); + SET_FLATPTR(CDEmu.lchs.spt, 36); + SET_FLATPTR(CDEmu.lchs.cylinders, 80); + SET_FLATPTR(CDEmu.lchs.heads, 2); break; } } else { // Harddrive emulation - SET_EBDA2(ebda_seg, cdemu.emulated_extdrive, 0x80); + SET_FLATPTR(CDEmu.emulated_extdrive, 0x80); SET_BDA(hdcount, GET_BDA(hdcount) + 1);
// Peak at partition table to get chs. @@ -309,14 +309,14 @@ cdrom_boot(struct drive_s *drive_g) u8 cyllow = GET_FARVAR(boot_segment, mbr->partitions[0].last.cyllow); u8 heads = GET_FARVAR(boot_segment, mbr->partitions[0].last.heads);
- SET_EBDA2(ebda_seg, cdemu.lchs.spt, sptcyl & 0x3f); - SET_EBDA2(ebda_seg, cdemu.lchs.cylinders + SET_FLATPTR(CDEmu.lchs.spt, sptcyl & 0x3f); + SET_FLATPTR(CDEmu.lchs.cylinders , ((sptcyl<<2)&0x300) + cyllow + 1); - SET_EBDA2(ebda_seg, cdemu.lchs.heads, heads + 1); + SET_FLATPTR(CDEmu.lchs.heads, heads + 1); }
// everything is ok, so from now on, the emulation is active - SET_EBDA2(ebda_seg, cdemu.active, 0x01); + SET_FLATPTR(CDEmu.active, 0x01); dprintf(6, "cdemu media=%d\n", media);
return 0; diff --git a/src/disk.c b/src/disk.c index 706b9f4..a0f0dc3 100644 --- a/src/disk.c +++ b/src/disk.c @@ -64,10 +64,9 @@ fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt) // populate the geometry directly in the driveid because the // geometry is only known after the bios segment is made // read-only). - u16 ebda_seg = get_ebda_seg(); - *nlc = GET_EBDA2(ebda_seg, cdemu.lchs.cylinders); - *nlh = GET_EBDA2(ebda_seg, cdemu.lchs.heads); - *nlspt = GET_EBDA2(ebda_seg, cdemu.lchs.spt); + *nlc = GET_FLATPTR(CDEmu.lchs.cylinders); + *nlh = GET_FLATPTR(CDEmu.lchs.heads); + *nlspt = GET_FLATPTR(CDEmu.lchs.spt); return; } *nlc = GET_GLOBAL(drive_g->lchs.cylinders); @@ -231,7 +230,6 @@ disk_1305(struct bregs *regs, struct drive_s *drive_g) static void noinline disk_1308(struct bregs *regs, struct drive_s *drive_g) { - u16 ebda_seg = get_ebda_seg(); // Get logical geometry from table u16 nlc, nlh, nlspt; fillLCHS(drive_g, &nlc, &nlh, &nlspt); @@ -244,7 +242,7 @@ disk_1308(struct bregs *regs, struct drive_s *drive_g)
if (CONFIG_CDROM_EMU && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf))) - regs->bx = GET_EBDA2(ebda_seg, cdemu.media) * 2; + regs->bx = GET_FLATPTR(CDEmu.media) * 2; else regs->bx = GET_GLOBAL(drive_g->floppy_type);
@@ -261,8 +259,8 @@ disk_1308(struct bregs *regs, struct drive_s *drive_g) return; }
- if (CONFIG_CDROM_EMU && GET_EBDA2(ebda_seg, cdemu.active)) { - u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive); + if (CONFIG_CDROM_EMU && GET_FLATPTR(CDEmu.active)) { + u8 emudrive = GET_FLATPTR(CDEmu.emulated_extdrive); if (((emudrive ^ regs->dl) & 0x80) == 0) // Note extra drive due to emulation. count++; @@ -397,15 +395,14 @@ disk_1344(struct bregs *regs, struct drive_s *drive_g) static void disk_134500(struct bregs *regs, struct drive_s *drive_g) { - u16 ebda_seg = get_ebda_seg(); int cdid = regs->dl - EXTSTART_CD; - u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]); + u8 locks = GET_FLATPTR(CDRom_locks[cdid]); if (locks == 0xff) { regs->al = 1; disk_ret(regs, DISK_RET_ETOOMANYLOCKS); return; } - SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks + 1); + SET_FLATPTR(CDRom_locks[cdid], locks + 1); regs->al = 1; disk_ret(regs, DISK_RET_SUCCESS); } @@ -414,16 +411,15 @@ disk_134500(struct bregs *regs, struct drive_s *drive_g) static void disk_134501(struct bregs *regs, struct drive_s *drive_g) { - u16 ebda_seg = get_ebda_seg(); int cdid = regs->dl - EXTSTART_CD; - u8 locks = GET_EBDA2(ebda_seg, cdrom_locks[cdid]); + u8 locks = GET_FLATPTR(CDRom_locks[cdid]); if (locks == 0x00) { regs->al = 0; disk_ret(regs, DISK_RET_ENOTLOCKED); return; } locks--; - SET_EBDA2(ebda_seg, cdrom_locks[cdid], locks); + SET_FLATPTR(CDRom_locks[cdid], locks); regs->al = (locks ? 1 : 0); disk_ret(regs, DISK_RET_SUCCESS); } @@ -433,7 +429,7 @@ static void disk_134502(struct bregs *regs, struct drive_s *drive_g) { int cdid = regs->dl - EXTSTART_CD; - u8 locks = GET_EBDA(cdrom_locks[cdid]); + u8 locks = GET_FLATPTR(CDRom_locks[cdid]); regs->al = (locks ? 1 : 0); disk_ret(regs, DISK_RET_SUCCESS); } @@ -473,7 +469,7 @@ disk_1346(struct bregs *regs, struct drive_s *drive_g) }
int cdid = regs->dl - EXTSTART_CD; - u8 locks = GET_EBDA(cdrom_locks[cdid]); + u8 locks = GET_FLATPTR(CDRom_locks[cdid]); if (locks != 0) { disk_ret(regs, DISK_RET_ELOCKED); return; @@ -565,11 +561,7 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g) u8 channel = 0; SET_INT13DPT(regs, size, 30); if (type == DTYPE_ATA || type == DTYPE_ATAPI) { - u16 ebda_seg = get_ebda_seg(); - - SET_INT13DPT(regs, dpte_segment, ebda_seg); - SET_INT13DPT(regs, dpte_offset - , offsetof(struct extended_bios_data_area_s, dpte)); + SET_INT13DPT(regs, dpte, FLATPTR_TO_SEGOFF(&DefaultDPTE));
// Fill in dpte struct atadrive_s *adrive_g = container_of( @@ -602,25 +594,25 @@ disk_1348(struct bregs *regs, struct drive_s *drive_g) if (CONFIG_ATA_PIO32) options |= 1<<7;
- SET_EBDA2(ebda_seg, dpte.iobase1, iobase1); - SET_EBDA2(ebda_seg, dpte.iobase2, iobase2 + ATA_CB_DC); - SET_EBDA2(ebda_seg, dpte.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0) - | ATA_CB_DH_LBA)); - SET_EBDA2(ebda_seg, dpte.unused, 0xcb); - SET_EBDA2(ebda_seg, dpte.irq, irq); - SET_EBDA2(ebda_seg, dpte.blkcount, 1); - SET_EBDA2(ebda_seg, dpte.dma, 0); - SET_EBDA2(ebda_seg, dpte.pio, 0); - SET_EBDA2(ebda_seg, dpte.options, options); - SET_EBDA2(ebda_seg, dpte.reserved, 0); - SET_EBDA2(ebda_seg, dpte.revision, 0x11); + SET_FLATPTR(DefaultDPTE.iobase1, iobase1); + SET_FLATPTR(DefaultDPTE.iobase2, iobase2 + ATA_CB_DC); + SET_FLATPTR(DefaultDPTE.prefix, ((slave ? ATA_CB_DH_DEV1 : ATA_CB_DH_DEV0) + | ATA_CB_DH_LBA)); + SET_FLATPTR(DefaultDPTE.unused, 0xcb); + SET_FLATPTR(DefaultDPTE.irq, irq); + SET_FLATPTR(DefaultDPTE.blkcount, 1); + SET_FLATPTR(DefaultDPTE.dma, 0); + SET_FLATPTR(DefaultDPTE.pio, 0); + SET_FLATPTR(DefaultDPTE.options, options); + SET_FLATPTR(DefaultDPTE.reserved, 0); + SET_FLATPTR(DefaultDPTE.revision, 0x11);
u8 sum = checksum_far( - ebda_seg, (void*)offsetof(struct extended_bios_data_area_s, dpte), 15); - SET_EBDA2(ebda_seg, dpte.checksum, -sum); + FLATPTR_TO_SEG(&DefaultDPTE), (void*)FLATPTR_TO_OFFSET(&DefaultDPTE) + , 15); + SET_FLATPTR(DefaultDPTE.checksum, -sum); } else { - SET_INT13DPT(regs, dpte_segment, 0); - SET_INT13DPT(regs, dpte_offset, 0); + SET_INT13DPT(regs, dpte.segoff, 0); bdf = GET_GLOBAL(drive_g->cntl_id); }
@@ -866,9 +858,8 @@ handle_13(struct bregs *regs) cdemu_134b(regs); return; } - u16 ebda_seg = get_ebda_seg(); - if (GET_EBDA2(ebda_seg, cdemu.active)) { - u8 emudrive = GET_EBDA2(ebda_seg, cdemu.emulated_extdrive); + if (GET_FLATPTR(CDEmu.active)) { + u8 emudrive = GET_FLATPTR(CDEmu.emulated_extdrive); if (extdrive == emudrive) { // Access to an emulated drive. struct drive_s *cdemu_g; diff --git a/src/disk.h b/src/disk.h index a675aeb..6c7d8fe 100644 --- a/src/disk.h +++ b/src/disk.h @@ -45,6 +45,24 @@ struct int13ext_s { #define SET_INT13EXT(regs,var,val) \ SET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var, (val))
+// 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; @@ -54,8 +72,7 @@ struct int13dpt_s { u32 spt; u64 sector_count; u16 blksize; - u16 dpte_offset; - u16 dpte_segment; + struct segoff_s dpte; u16 key; u8 dpi_length; u8 reserved1; @@ -181,6 +198,21 @@ struct chs_s { u16 spt; // # sectors / track };
+// 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). @@ -249,6 +281,8 @@ 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 cdemu_setup(void);
Clean up includes of biosvar.h.
Rename GET/SET_EBDA2 to GET/SET_EBDA - nearly all users use the extended form now anyway.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/acpi.c | 2 +- src/ahci.c | 2 +- src/ata.c | 2 +- src/biosvar.h | 11 +++-------- src/block.c | 2 +- src/blockcmd.h | 2 ++ src/bootsplash.c | 1 - src/coreboot.c | 3 ++- src/disk.c | 2 +- src/memmap.c | 2 +- src/mouse.c | 31 ++++++++++++++++--------------- src/mtrr.c | 2 +- src/pcibios.c | 2 +- src/pciinit.c | 3 ++- src/pirtable.c | 2 +- src/post.c | 2 +- src/smbios.c | 1 - src/stacks.c | 8 ++++---- src/xen.h | 3 ++- 19 files changed, 41 insertions(+), 42 deletions(-)
diff --git a/src/acpi.c b/src/acpi.c index 30888b9..5387183 100644 --- a/src/acpi.c +++ b/src/acpi.c @@ -8,9 +8,9 @@ #include "acpi.h" // struct rsdp_descriptor #include "util.h" // memcpy #include "pci.h" // pci_find_init_device -#include "biosvar.h" // GET_EBDA #include "pci_ids.h" // PCI_VENDOR_ID_INTEL #include "pci_regs.h" // PCI_INTERRUPT_LINE +#include "ioport.h" // inl #include "paravirt.h"
/****************************************************/ diff --git a/src/ahci.c b/src/ahci.c index 4abfec5..1176dcc 100644 --- a/src/ahci.c +++ b/src/ahci.c @@ -7,7 +7,7 @@ #include "types.h" // u8 #include "ioport.h" // inb #include "util.h" // dprintf -#include "biosvar.h" // GET_EBDA +#include "biosvar.h" // GET_GLOBAL #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE diff --git a/src/ata.c b/src/ata.c index b8b0cb3..8e3089a 100644 --- a/src/ata.c +++ b/src/ata.c @@ -10,7 +10,7 @@ #include "util.h" // dprintf #include "cmos.h" // inb_cmos #include "pic.h" // enable_hwirq -#include "biosvar.h" // GET_EBDA +#include "biosvar.h" // GET_GLOBAL #include "pci.h" // foreachpci #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER #include "pci_regs.h" // PCI_INTERRUPT_LINE diff --git a/src/biosvar.h b/src/biosvar.h index 5993718..0716877 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -8,8 +8,7 @@
#include "types.h" // u8 #include "farptr.h" // GET_FARVAR -#include "config.h" // CONFIG_* -#include "disk.h" // struct chs_s +#include "config.h" // SEG_BDA
/**************************************************************** @@ -199,14 +198,10 @@ get_ebda_ptr(void) ASSERT32FLAT(); return MAKE_FLATPTR(get_ebda_seg(), 0); } -#define GET_EBDA2(eseg, var) \ +#define GET_EBDA(eseg, var) \ GET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var) -#define SET_EBDA2(eseg, var, val) \ +#define SET_EBDA(eseg, var, val) \ SET_FARVAR(eseg, ((struct extended_bios_data_area_s *)0)->var, (val)) -#define GET_EBDA(var) \ - GET_EBDA2(get_ebda_seg(), var) -#define SET_EBDA(var, val) \ - SET_EBDA2(get_ebda_seg(), var, (val))
/**************************************************************** diff --git a/src/block.c b/src/block.c index 1ea2b60..44ba9bd 100644 --- a/src/block.c +++ b/src/block.c @@ -350,7 +350,7 @@ __send_disk_op(struct disk_op_s *op_far, u16 op_seg) return status; }
-// Execute a "disk_op_s" request by jumping to a stack in the ebda. +// Execute a "disk_op_s" request by jumping to the extra 16bit stack. int send_disk_op(struct disk_op_s *op) { diff --git a/src/blockcmd.h b/src/blockcmd.h index 8459d3e..b45bbb7 100644 --- a/src/blockcmd.h +++ b/src/blockcmd.h @@ -101,6 +101,7 @@ struct cdbres_mode_sense_geom {
// blockcmd.c int cdb_is_read(u8 *cdbcmd, u16 blocksize); +struct disk_op_s; int cdb_get_inquiry(struct disk_op_s *op, struct cdbres_inquiry *data); int cdb_get_sense(struct disk_op_s *op, struct cdbres_request_sense *data); int cdb_test_unit_ready(struct disk_op_s *op); @@ -111,6 +112,7 @@ int cdb_read(struct disk_op_s *op); int cdb_write(struct disk_op_s *op);
int scsi_is_ready(struct disk_op_s *op); +struct drive_s; int scsi_init_drive(struct drive_s *drive, const char *s, int prio);
#endif // blockcmd.h diff --git a/src/bootsplash.c b/src/bootsplash.c index 76b72c1..f85f734 100644 --- a/src/bootsplash.c +++ b/src/bootsplash.c @@ -10,7 +10,6 @@ #include "config.h" // CONFIG_* #include "util.h" // dprintf #include "jpeg.h" // splash -#include "biosvar.h" // SET_EBDA #include "paravirt.h" // romfile_find #include "vbe.h" // struct vbe_info #include "bmp.h" diff --git a/src/coreboot.c b/src/coreboot.c index 4ae44e5..e116a14 100644 --- a/src/coreboot.c +++ b/src/coreboot.c @@ -6,10 +6,11 @@
#include "memmap.h" // add_e820 #include "util.h" // dprintf -#include "biosvar.h" // GET_EBDA #include "lzmadecode.h" // LzmaDecode #include "smbios.h" // smbios_init #include "boot.h" // boot_add_cbfs +#include "disk.h" // MAXDESCSIZE +#include "config.h" // CONFIG_*
/**************************************************************** diff --git a/src/disk.c b/src/disk.c index a0f0dc3..8095581 100644 --- a/src/disk.c +++ b/src/disk.c @@ -60,7 +60,7 @@ fillLCHS(struct drive_s *drive_g, u16 *nlc, u16 *nlh, u16 *nlspt) { if (CONFIG_CDROM_EMU && drive_g == GLOBALFLAT2GLOBAL(GET_GLOBAL(cdemu_drive_gf))) { - // Emulated drive - get info from ebda. (It's not possible to + // Emulated drive - get info from CDEmu. (It's not possible to // populate the geometry directly in the driveid because the // geometry is only known after the bios segment is made // read-only). diff --git a/src/memmap.c b/src/memmap.c index 56865b4..3783518 100644 --- a/src/memmap.c +++ b/src/memmap.c @@ -5,8 +5,8 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "memmap.h" // struct e820entry +#include "config.h" // CONFIG_* #include "util.h" // dprintf.h -#include "biosvar.h" // SET_EBDA
/**************************************************************** diff --git a/src/mouse.c b/src/mouse.c index e26cf69..237c8ff 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -52,7 +52,8 @@ mouse_15c20000(struct bregs *regs) static void mouse_15c20001(struct bregs *regs) { - u8 mouse_flags_2 = GET_EBDA(mouse_flag2); + u16 ebda_seg = get_ebda_seg(); + u8 mouse_flags_2 = GET_EBDA(ebda_seg, mouse_flag2); if ((mouse_flags_2 & 0x80) == 0) { set_code_invalid(regs, RET_ENOHANDLER); return; @@ -158,8 +159,8 @@ mouse_15c205(struct bregs *regs) return; } u16 ebda_seg = get_ebda_seg(); - SET_EBDA2(ebda_seg, mouse_flag1, 0x00); - SET_EBDA2(ebda_seg, mouse_flag2, regs->bh); + SET_EBDA(ebda_seg, mouse_flag1, 0x00); + SET_EBDA(ebda_seg, mouse_flag2, regs->bh);
// Reset Mouse mouse_15c201(regs); @@ -227,7 +228,7 @@ mouse_15c207(struct bregs *regs) { struct segoff_s farptr = SEGOFF(regs->es, regs->bx); u16 ebda_seg = get_ebda_seg(); - u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2); + u8 mouse_flags_2 = GET_EBDA(ebda_seg, mouse_flag2); if (! farptr.segoff) { /* remove handler */ if ((mouse_flags_2 & 0x80) != 0) { @@ -238,8 +239,8 @@ mouse_15c207(struct bregs *regs) /* install handler */ mouse_flags_2 |= 0x80; } - SET_EBDA2(ebda_seg, mouse_flag2, mouse_flags_2); - SET_EBDA2(ebda_seg, far_call_pointer, farptr); + SET_EBDA(ebda_seg, mouse_flag2, mouse_flags_2); + SET_EBDA(ebda_seg, far_call_pointer, farptr); set_code_success(regs); }
@@ -279,8 +280,8 @@ process_mouse(u8 data) return;
u16 ebda_seg = get_ebda_seg(); - u8 mouse_flags_1 = GET_EBDA2(ebda_seg, mouse_flag1); - u8 mouse_flags_2 = GET_EBDA2(ebda_seg, mouse_flag2); + u8 mouse_flags_1 = GET_EBDA(ebda_seg, mouse_flag1); + u8 mouse_flags_2 = GET_EBDA(ebda_seg, mouse_flag2);
if (! (mouse_flags_2 & 0x80)) // far call handler not installed @@ -288,20 +289,20 @@ process_mouse(u8 data)
u8 package_count = mouse_flags_2 & 0x07; u8 index = mouse_flags_1 & 0x07; - SET_EBDA2(ebda_seg, mouse_data[index], data); + SET_EBDA(ebda_seg, mouse_data[index], data);
if ((index+1) < package_count) { mouse_flags_1++; - SET_EBDA2(ebda_seg, mouse_flag1, mouse_flags_1); + SET_EBDA(ebda_seg, mouse_flag1, mouse_flags_1); return; }
- u16 status = GET_EBDA2(ebda_seg, mouse_data[0]); - u16 X = GET_EBDA2(ebda_seg, mouse_data[1]); - u16 Y = GET_EBDA2(ebda_seg, mouse_data[2]); - SET_EBDA2(ebda_seg, mouse_flag1, 0); + u16 status = GET_EBDA(ebda_seg, mouse_data[0]); + u16 X = GET_EBDA(ebda_seg, mouse_data[1]); + u16 Y = GET_EBDA(ebda_seg, mouse_data[2]); + SET_EBDA(ebda_seg, mouse_flag1, 0);
- struct segoff_s func = GET_EBDA2(ebda_seg, far_call_pointer); + struct segoff_s func = GET_EBDA(ebda_seg, far_call_pointer); dprintf(16, "mouse farcall s=%04x x=%04x y=%04x func=%04x:%04x\n" , status, X, Y, func.seg, func.offset);
diff --git a/src/mtrr.c b/src/mtrr.c index ec3be4f..0957834 100644 --- a/src/mtrr.c +++ b/src/mtrr.c @@ -5,7 +5,7 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "util.h" // dprintf -#include "biosvar.h" // GET_EBDA +#include "config.h" // CONFIG_* #include "xen.h" // usingXen
#define MSR_MTRRcap 0x000000fe diff --git a/src/pcibios.c b/src/pcibios.c index 8b792fb..d10cdfd 100644 --- a/src/pcibios.c +++ b/src/pcibios.c @@ -9,7 +9,7 @@ #include "util.h" // handle_1ab1 #include "pci.h" // pci_config_readl #include "bregs.h" // struct bregs -#include "biosvar.h" // GET_EBDA +#include "biosvar.h" // GET_GLOBAL #include "pci_regs.h" // PCI_VENDOR_ID
// romlayout.S diff --git a/src/pciinit.c b/src/pciinit.c index f265662..613a9c0 100644 --- a/src/pciinit.c +++ b/src/pciinit.c @@ -7,9 +7,10 @@
#include "util.h" // dprintf #include "pci.h" // pci_config_readl -#include "biosvar.h" // GET_EBDA #include "pci_ids.h" // PCI_VENDOR_ID_INTEL #include "pci_regs.h" // PCI_COMMAND +#include "ioport.h" // PORT_ATA1_CMD_BASE +#include "config.h" // CONFIG_* #include "xen.h" // usingXen
#define PCI_DEVICE_MEM_MIN 0x1000 diff --git a/src/pirtable.c b/src/pirtable.c index 4c3f1ff..2c328d8 100644 --- a/src/pirtable.c +++ b/src/pirtable.c @@ -6,8 +6,8 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "pci.h" // struct pir_header +#include "config.h" // CONFIG_* #include "util.h" // checksum -#include "biosvar.h" // SET_EBDA
u16 PirOffset VAR16VISIBLE;
diff --git a/src/post.c b/src/post.c index 3561c0d..695f43f 100644 --- a/src/post.c +++ b/src/post.c @@ -93,7 +93,7 @@ init_bda(void) memset(ebda, 0, sizeof(*ebda)); ebda->size = esize;
- add_e820((u32)MAKE_FLATPTR(ebda_seg, 0), GET_EBDA2(ebda_seg, size) * 1024 + add_e820((u32)MAKE_FLATPTR(ebda_seg, 0), GET_EBDA(ebda_seg, size) * 1024 , E820_RESERVED); }
diff --git a/src/smbios.c b/src/smbios.c index fe1e183..20d2d47 100644 --- a/src/smbios.c +++ b/src/smbios.c @@ -6,7 +6,6 @@ // This file may be distributed under the terms of the GNU LGPLv3 license.
#include "util.h" // dprintf -#include "biosvar.h" // GET_EBDA #include "paravirt.h" // qemu_cfg_smbios_load_field #include "smbios.h" // struct smbios_entry_point
diff --git a/src/stacks.c b/src/stacks.c index 659e5bf..9c84d1f 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -4,7 +4,7 @@ // // This file may be distributed under the terms of the GNU LGPLv3 license.
-#include "biosvar.h" // get_ebda_seg +#include "biosvar.h" // GET_GLOBAL #include "util.h" // dprintf #include "bregs.h" // CR0_PE
@@ -149,13 +149,13 @@ wait_irq(void)
/**************************************************************** - * Stack in EBDA + * Extra 16bit stack ****************************************************************/
// Space for a stack for 16bit code. char ExtraStack[BUILD_EXTRA_STACK_SIZE] VARLOW __aligned(16);
-// Switch to the extra stack in ebda and call a function. +// Switch to the extra stack and call a function. inline u32 stack_hop(u32 eax, u32 edx, void *func) { @@ -166,7 +166,7 @@ stack_hop(u32 eax, u32 edx, void *func) // Backup current %ss/%esp values. "movw %%ss, %w3\n" "movl %%esp, %4\n" - // Copy ebda seg to %ds/%ss and set %esp + // Copy stack seg to %ds/%ss and set %esp "movw %w6, %%ds\n" "movw %w6, %%ss\n" "movl %5, %%esp\n" diff --git a/src/xen.h b/src/xen.h index dbd4a37..cc506a6 100644 --- a/src/xen.h +++ b/src/xen.h @@ -1,7 +1,8 @@ #ifndef __XEN_H #define __XEN_H
-#include "util.h" +#include "config.h" // CONFIG_* +#include "types.h" // u32
extern u32 xen_cpuid_base;