diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2012-05-13 12:10:30 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2012-05-20 18:10:38 -0400 |
commit | 46b82624c95b951e8825fab117d9352faeae0ec8 (patch) | |
tree | 02e6dfd8ab8dcacd86ef7b6b08bd2a67d45d6410 /src | |
parent | 9c98517c938d20c38f537d516c71b30bb60c3ea0 (diff) | |
download | seabios-46b82624c95b951e8825fab117d9352faeae0ec8.tar.gz |
Add mechanism to declare variables as "low mem" and use for extra stack.
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.
This also reworks tools/layoutrom.py a bit.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/asm-offsets.c | 8 | ||||
-rw-r--r-- | src/ata.c | 7 | ||||
-rw-r--r-- | src/biosvar.h | 24 | ||||
-rw-r--r-- | src/block.c | 4 | ||||
-rw-r--r-- | src/config.h | 1 | ||||
-rw-r--r-- | src/post.c | 50 | ||||
-rw-r--r-- | src/romlayout.S | 8 | ||||
-rw-r--r-- | src/stacks.c | 15 | ||||
-rw-r--r-- | src/types.h | 4 | ||||
-rw-r--r-- | src/util.h | 1 |
10 files changed, 75 insertions, 47 deletions
diff --git a/src/asm-offsets.c b/src/asm-offsets.c index 5035cef8..b98f3b5a 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); } @@ -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 @@ -379,6 +379,7 @@ struct sff_dma_prd { static int ata_try_dma(struct disk_op_s *op, int iswrite, int blocksize) { + ASSERT16(); if (! CONFIG_ATA_DMA) return -1; u32 dest = (u32)op->buf_fl; @@ -396,9 +397,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 = MAKE_FLATPTR(SEG_LOW, ExtraStack); struct sff_dma_prd *origdma = dma; while (bytes) { if (dma >= &origdma[16]) diff --git a/src/biosvar.h b/src/biosvar.h index b6f7174c..99c2565b 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 @@ -321,6 +313,22 @@ static inline u16 get_global_seg(void) { /**************************************************************** + * "Low" memory variables + ****************************************************************/ + +extern u8 _datalow_seg, _datalow_base[]; +#define SEG_LOW ((u32)&_datalow_seg) + +#if MODESEGMENT +#define GET_LOW(var) GET_FARVAR(SEG_LOW, (var)) +#define SET_LOW(var, val) SET_FARVAR(SEG_LOW, (var), (val)) +#else +#define GET_LOW(var) (var) +#define SET_LOW(var, val) do { (var) = (val); } while (0) +#endif + + +/**************************************************************** * Bios Config Table ****************************************************************/ diff --git a/src/block.c b/src/block.c index a80199c6..194d6f26 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) { @@ -349,7 +349,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/config.h b/src/config.h index 521469b2..23591b97 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 @@ -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) @@ -306,32 +318,42 @@ reloc_init(void) } // Symbols populated by the build. extern u8 code32flat_start[]; - extern u8 _reloc_min_align[]; + extern u8 _reloc_min_align; extern u32 _reloc_abs_start[], _reloc_abs_end[]; 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 c4b2ef11..399f596b 100644 --- a/src/romlayout.S +++ b/src/romlayout.S @@ -232,13 +232,11 @@ 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 $_datalow_seg, %eax movw %ax, %ds movw %ax, %ss - movl $EBDA_OFFSET_TOP_STACK, %esp + movl $ExtraStack + BUILD_EXTRA_STACK_SIZE, %esp // Call handler. jmp handle_resume diff --git a/src/stacks.c b/src/stacks.c index 17f1a4a8..0371330a 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,21 +149,24 @@ wait_irq(void) /**************************************************************** - * Stack in EBDA + * Extra 16bit stack ****************************************************************/ -// Switch to the extra stack in ebda and call a function. +// Space for a stack for 16bit code. +u8 ExtraStack[BUILD_EXTRA_STACK_SIZE+1] VARLOW __aligned(8); + +// Switch to the extra stack 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 = SEG_LOW, bkup_ss; u32 bkup_esp; asm volatile( // 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" @@ -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" (&ExtraStack[BUILD_EXTRA_STACK_SIZE]), "r" (stack_seg) : "cc", "memory"); return eax; } diff --git a/src/types.h b/src/types.h index c0c6d26c..0f83697e 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() @@ -230,6 +230,7 @@ int get_keystroke(int msec); // stacks.c u32 call32(void *func, u32 eax, u32 errret); +extern u8 ExtraStack[]; inline u32 stack_hop(u32 eax, u32 edx, void *func); extern struct thread_info MainThread; extern int CanPreempt; |