[SeaBIOS] [PATCH] Eliminate separate BiosTableSpace[] space for f-segment allocations.

Kevin O'Connor kevin at koconnor.net
Wed Feb 20 03:46:06 CET 2013


The BiosTableSpace variable was used to ensure there was sufficient
space in the f-segment for malloc_fseg() calls.  However, it added 2K
to the final image size to reserve that space.

Update the build to determine where to put the f-segment allocations.
In most cases (when code relocation is enabled) allocations can be
done in the space free'd from the "init" sections and no additional
space needs to be reserved in the final image.  This also has the
benefit of not fragmenting the f-segment allocation space.

Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---

This patch, along with the other pending patches from my local tree,
is available for testing at:
https://github.com/KevinOConnor/seabios/tree/test-20130218

---
 src/config.h       |  2 --
 src/pmm.c          | 12 +++---------
 tools/layoutrom.py | 16 ++++++++++++++++
 3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/src/config.h b/src/config.h
index 71c0b7e..f391877 100644
--- a/src/config.h
+++ b/src/config.h
@@ -16,8 +16,6 @@
 
 // Maximum number of map entries in the e820 map
 #define CONFIG_MAX_E820 32
-// Space to reserve in f-segment for dynamic allocations
-#define CONFIG_MAX_BIOSTABLE 2048
 // Space to reserve in high-memory for tables
 #define CONFIG_MAX_HIGHTABLE (64*1024)
 // Largest supported externaly facing drive id
diff --git a/src/pmm.c b/src/pmm.c
index 9fca8dc..dbe34a1 100644
--- a/src/pmm.c
+++ b/src/pmm.c
@@ -216,9 +216,6 @@ 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)
 {
@@ -320,12 +317,9 @@ malloc_init(void)
     RomBase = findLast(&ZoneLow);
 
     // Add space available in f-segment to ZoneFSeg
-    addSpace(&ZoneFSeg, BiosTableSpace, &BiosTableSpace[CONFIG_MAX_BIOSTABLE]);
-    extern u8 code32init_end[];
-    if ((u32)code32init_end > BUILD_BIOS_ADDR) {
-        memset((void*)BUILD_BIOS_ADDR, 0, (u32)code32init_end - BUILD_BIOS_ADDR);
-        addSpace(&ZoneFSeg, (void*)BUILD_BIOS_ADDR, code32init_end);
-    }
+    extern u8 zonefseg_start[], zonefseg_end[];
+    memset(zonefseg_start, 0, zonefseg_end - zonefseg_start);
+    addSpace(&ZoneFSeg, zonefseg_start, zonefseg_end);
 
     calcRamSize();
 }
diff --git a/tools/layoutrom.py b/tools/layoutrom.py
index 2d45317..d90f326 100755
--- a/tools/layoutrom.py
+++ b/tools/layoutrom.py
@@ -59,6 +59,8 @@ def setSectionsStart(sections, endaddr, minalign=1, segoffset=0):
 BUILD_BIOS_ADDR = 0xf0000
 BUILD_BIOS_SIZE = 0x10000
 BUILD_ROM_START = 0xc0000
+# Space to reserve in f-segment for dynamic allocations
+BUILD_MIN_BIOSTABLE = 2048
 
 # Layout the 16bit code.  This ensures sections with fixed offset
 # requirements are placed in the correct location.  It also places the
@@ -159,6 +161,7 @@ class LayoutInfo:
     sections32init = sec32init_start = sec32init_align = None
     sections32low = sec32low_start = sec32low_align = None
     sections32fseg = sec32fseg_start = sec32fseg_align = None
+    zonefseg_start = zonefseg_end = None
     zonelow_base = final_sec32low_start = None
     exportsyms = varlowsyms = None
 
@@ -211,6 +214,15 @@ def doLayout(sections):
     li.sec32flat_start, li.sec32flat_align = setSectionsStart(
         textsections + rodatasections + datasections + bsssections
         , li.sec32fseg_start, 16)
+    li.zonefseg_end = li.sec32flat_start
+    li.zonefseg_start = BUILD_BIOS_ADDR
+    if li.zonefseg_start + BUILD_MIN_BIOSTABLE > li.zonefseg_end:
+        # Not enough ZoneFSeg space - force a minimum space.
+        li.zonefseg_end = li.sec32fseg_start
+        li.zonefseg_start = li.zonefseg_end - BUILD_MIN_BIOSTABLE
+        li.sec32flat_start, li.sec32flat_align = setSectionsStart(
+            textsections + rodatasections + datasections + bsssections
+            , li.zonefseg_start, 16)
 
     # Determine 32flat init positions
     li.sections32init = getSectionsCategory(sections, '32init')
@@ -369,6 +381,8 @@ def writeLinkerScripts(li, out16, out32seg, out32flat):
                    , forcedelta=li.final_sec32low_start-li.sec32low_start)
     out += outXRefs(sections32all, exportsyms=li.exportsyms) + """
     _reloc_min_align = 0x%x ;
+    zonefseg_start = 0x%x ;
+    zonefseg_end = 0x%x ;
     zonelow_base = 0x%x ;
     final_varlow_start = 0x%x ;
 
@@ -390,6 +404,8 @@ def writeLinkerScripts(li, out16, out32seg, out32flat):
         code32flat_end = ABSOLUTE(.) ;
     } :text
 """ % (li.sec32init_align,
+       li.zonefseg_start,
+       li.zonefseg_end,
        li.zonelow_base,
        li.final_sec32low_start,
        sec32all_start,
-- 
1.7.11.7




More information about the SeaBIOS mailing list