Eliminate separate BiosTableSpace[] space for f-segment allocations.
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@koconnor.net>
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 @@
* 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 @@
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 70370e4..6e1c588 100755
--- a/tools/layoutrom.py
+++ b/tools/layoutrom.py
@@ -59,6 +59,8 @@
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 @@
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 @@
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 @@
, 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 @@
code32flat_end = ABSOLUTE(.) ;
} :text
""" % (li.sec32init_align,
+ li.zonefseg_start,
+ li.zonefseg_end,
li.zonelow_base,
li.final_sec32low_start,
sec32all_start,