Allow specifying offset in addition to alignment

This commit is contained in:
ISSOtm
2020-04-08 00:40:41 +02:00
parent e82ad21704
commit b0ec8468e6
16 changed files with 154 additions and 44 deletions

View File

@@ -132,7 +132,8 @@ static bool isLocationSuitable(struct Section const *section,
if (section->isAddressFixed && section->org != location->address)
return false;
if (section->isAlignFixed && location->address & section->alignMask)
if (section->isAlignFixed
&& ((location->address - section->alignOfs) & section->alignMask))
return false;
if (location->address < freeSpace->address)
@@ -183,8 +184,13 @@ static struct FreeSpace *getPlacement(struct Section const *section,
space = NULL;
} else if (section->isAlignFixed) {
/* Move to next aligned location */
/* Move back to alignment boundary */
location->address -= section->alignOfs;
/* Ensure we're there (e.g. on first check) */
location->address &= ~section->alignMask;
location->address += section->alignMask + 1;
/* Go to next align boundary and add offset */
location->address += section->alignMask + 1
+ section->alignOfs;
} else {
/* Any location is fine, so, next free block */
space = space->next;
@@ -309,8 +315,8 @@ static void placeSection(struct Section *section)
if (section->isAddressFixed)
snprintf(where, 64, "at address $%04x", section->org);
else if (section->isAlignFixed)
snprintf(where, 64, "with align mask %x",
~section->alignMask);
snprintf(where, 64, "with align mask %x and offset %u",
~section->alignMask, section->alignOfs);
else
strcpy(where, "anywhere");
}