On Tue, Jun 05, 2012 at 12:09:18PM -0400, Jason Baron wrote:
I've been creating 256kb rom images with larger acpi tables for second level buses. After a recent re-base, my rom images no longer built. Bisected to:
commit 46b82624c95b951e8825fab117d9352faeae0ec8 Author: Kevin O'Connor kevin@koconnor.net Date: Sun May 13 12:10:30 2012 -0400
Add mechanism to declare variables as "low mem" and use for extra stack.
Where sec32low_top is greater than datalow_base. Currently, datalow_base is calculated by subtracting a 64kb offset. Updating it to 128kb, resolved this issue for me, while still continuing to create smaller rom images as expected.
Thanks. The problem causing the build to fail is that negative numbers aren't encoded properly. That's easy to fix, but it quickly uncovers a problem with relocations. Some of the 16bit code has 16bit relocations and those wont be handled right if the integer wraps. I put together a fix (see below) but it's a bit ugly.
--- a/tools/layoutrom.py +++ b/tools/layoutrom.py @@ -219,10 +219,10 @@ def doLayout(sections, genreloc): li.sections32low = getSectionsCategory(sections, '32low') if genreloc: sec32low_top = li.sec32init_start
datalow_base = min(BUILD_BIOS_ADDR, li.sec32flat_start) - 64*1024
datalow_base = min(BUILD_BIOS_ADDR, li.sec32flat_start) - 128*1024
Unfortunately this will just break other areas. The datalow_base can only be 64K in size because a real-mode segment can only see 64K.
-Kevin
diff --git a/src/biosvar.h b/src/biosvar.h index fd2f1bf..0da5a27 100644 --- a/src/biosvar.h +++ b/src/biosvar.h @@ -254,8 +254,8 @@ 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)) +#define GET_LOW(var) __GET_FARVAR("addr32 ", SEG_LOW, (var)) +#define SET_LOW(var, val) __SET_FARVAR("addr32 ", SEG_LOW, (var), (val)) #define LOWFLAT2LOW(var) ((typeof(var))((void*)(var) - (u32)_datalow_base)) #else #define GET_LOW(var) (var) diff --git a/src/farptr.h b/src/farptr.h index 3a85c6b..3a6130b 100644 --- a/src/farptr.h +++ b/src/farptr.h @@ -106,13 +106,13 @@ DECL_SEGFUNCS(SS) // Macros for accessing a variable in another segment. (They // automatically update the %es segment and then make the appropriate // access.) -#define __GET_FARVAR(seg, var) ({ \ +#define __GET_FARVAR(prefix, seg, var) ({ \ SET_SEG(ES, (seg)); \ - GET_VAR(ES, (var)); }) -#define __SET_FARVAR(seg, var, val) do { \ - typeof(var) __sfv_val = (val); \ - SET_SEG(ES, (seg)); \ - SET_VAR(ES, (var), __sfv_val); \ + __GET_VAR(prefix, ES, (var)); }) +#define __SET_FARVAR(prefix, seg, var, val) do { \ + typeof(var) __sfv_val = (val); \ + SET_SEG(ES, (seg)); \ + __SET_VAR(prefix, ES, (var), __sfv_val); \ } while (0)
// Macros for accesssing a 32bit flat mode pointer from 16bit real @@ -139,8 +139,8 @@ DECL_SEGFUNCS(SS) #if MODESEGMENT == 1
// Definitions when using segmented mode. -#define GET_FARVAR(seg, var) __GET_FARVAR((seg), (var)) -#define SET_FARVAR(seg, var, val) __SET_FARVAR((seg), (var), (val)) +#define GET_FARVAR(seg, var) __GET_FARVAR("", (seg), (var)) +#define SET_FARVAR(seg, var, val) __SET_FARVAR("", (seg), (var), (val)) #define GET_VAR(seg, var) __GET_VAR("", seg, (var)) #define SET_VAR(seg, var, val) __SET_VAR("", seg, (var), (val)) #define SET_SEG(SEG, value) __SET_SEG(SEG, (value)) diff --git a/src/romlayout.S b/src/romlayout.S index 8125277..67b0cc2 100644 --- a/src/romlayout.S +++ b/src/romlayout.S @@ -398,7 +398,7 @@ irqentry_extrastack: pushl %eax movl $_datalow_seg, %eax movl %eax, %ds - movl StackPos, %eax + addr32 movl StackPos, %eax subl $24, %eax popl 0(%eax) // Backup %eax, %ds, %es, %ecx, %edx popw 4(%eax) diff --git a/src/stacks.c b/src/stacks.c index 9381729..890fb58 100644 --- a/src/stacks.c +++ b/src/stacks.c @@ -40,7 +40,7 @@ stack_hop(u32 eax, u32 edx, void *func) // Copy stack seg to %ds/%ss and set %esp "movw %w6, %%ds\n" "movw %w6, %%ss\n" - "movl %5, %%esp\n" + "addr32 movl %5, %%esp\n" "pushl %3\n" "pushl %4\n" // Call func @@ -68,9 +68,9 @@ stack_hop_back(u32 eax, u32 edx, void *func) u32 bkup_stack_pos, temp; asm volatile( // Backup stack_pos and current %ss/%esp - "movl %6, %4\n" + "addr32 movl %6, %4\n" "movw %%ss, %w3\n" - "movl %%esp, %6\n" + "addr32 movl %%esp, %6\n" // Restore original callers' %ss/%esp "movl -4(%4), %5\n" "movl %5, %%ss\n" @@ -81,8 +81,8 @@ stack_hop_back(u32 eax, u32 edx, void *func) // Restore %ss/%esp and stack_pos "movw %w3, %%ds\n" "movw %w3, %%ss\n" - "movl %6, %%esp\n" - "movl %4, %6" + "addr32 movl %6, %%esp\n" + "addr32 movl %4, %6" : "+a" (eax), "+d" (edx), "+c" (func), "=&r" (bkup_ss) , "=&r" (bkup_stack_pos), "=&r" (temp), "+m" (StackPos) : diff --git a/tools/layoutrom.py b/tools/layoutrom.py index 74b410f..c6025ae 100755 --- a/tools/layoutrom.py +++ b/tools/layoutrom.py @@ -48,8 +48,6 @@ def setSectionsStart(sections, endaddr, minalign=1, segoffset=0): totspace = alignpos(totspace, section.align) + section.size startaddr = (endaddr - totspace) / minalign * minalign curaddr = startaddr - # out = [(addr, sectioninfo), ...] - out = [] for section in sections: curaddr = alignpos(curaddr, section.align) section.finalloc = curaddr @@ -261,7 +259,8 @@ def outXRefs(sections, useseg=0): loc = symbol.section.finalloc if useseg: loc = symbol.section.finalsegloc - out += "%s = 0x%x ;\n" % (reloc.symbolname, loc + symbol.offset) + out += "%s = 0x%x ;\n" % ( + reloc.symbolname, (loc + symbol.offset) & 0xffffffff) return out
# Write LD script includes for the given sections using relative offsets