mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-25 12:32:07 +00:00
Use inttypes for stdint types
This should help make RGBDS portable to systems with 16-bit integers, like DOS. For kicks, use the macros for 16-bit and 8-bit integers. Fix other miscellaneous things, like #include ordering and other printf-format related things. Reduce repitition in math.c while I'm there.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -51,7 +52,7 @@ static void initFreeSpace(void)
|
||||
memory[type][bank].next =
|
||||
malloc(sizeof(*memory[type][0].next));
|
||||
if (!memory[type][bank].next)
|
||||
err(1, "Failed to init free space for region %d bank %u",
|
||||
err(1, "Failed to init free space for region %d bank %" PRIu32,
|
||||
type, bank);
|
||||
memory[type][bank].next->address = startaddr[type];
|
||||
memory[type][bank].next->size = maxsize[type];
|
||||
@@ -304,19 +305,22 @@ static void placeSection(struct Section *section)
|
||||
|
||||
if (section->isBankFixed && nbbanks(section->type) != 1) {
|
||||
if (section->isAddressFixed)
|
||||
snprintf(where, 64, "at $%02x:%04x",
|
||||
snprintf(where, 64, "at $%02" PRIx32 ":%04" PRIx16,
|
||||
section->bank, section->org);
|
||||
else if (section->isAlignFixed)
|
||||
snprintf(where, 64, "in bank $%02x with align mask %x",
|
||||
section->bank, ~section->alignMask);
|
||||
snprintf(where, 64, "in bank $%02" PRIx32 " with align mask %" PRIx16,
|
||||
section->bank, (uint16_t)~section->alignMask);
|
||||
else
|
||||
snprintf(where, 64, "in bank $%02x", section->bank);
|
||||
snprintf(where, 64, "in bank $%02" PRIx32,
|
||||
section->bank);
|
||||
} else {
|
||||
if (section->isAddressFixed)
|
||||
snprintf(where, 64, "at address $%04x", section->org);
|
||||
snprintf(where, 64, "at address $%04" PRIx16,
|
||||
section->org);
|
||||
else if (section->isAlignFixed)
|
||||
snprintf(where, 64, "with align mask %x and offset %u",
|
||||
~section->alignMask, section->alignOfs);
|
||||
snprintf(where, 64, "with align mask %" PRIx16 " and offset %" PRIx16,
|
||||
(uint16_t)~section->alignMask,
|
||||
section->alignOfs);
|
||||
else
|
||||
strcpy(where, "anywhere");
|
||||
}
|
||||
@@ -327,7 +331,7 @@ static void placeSection(struct Section *section)
|
||||
section->name, typeNames[section->type], where);
|
||||
/* If the section just can't fit the bank, report that */
|
||||
else if (section->org + section->size > endaddr(section->type) + 1)
|
||||
errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > $%04x)",
|
||||
errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04" PRIx16 " > $%04" PRIx16 ")",
|
||||
section->name, typeNames[section->type], where,
|
||||
section->org + section->size, endaddr(section->type) + 1);
|
||||
/* Otherwise there is overlap with another section */
|
||||
@@ -418,7 +422,7 @@ void assign_AssignSections(void)
|
||||
/* Overlaying requires only fully-constrained sections */
|
||||
verbosePrint("Assigning other sections...\n");
|
||||
if (overlayFileName)
|
||||
errx(1, "All sections must be fixed when using an overlay file; %lu %sn't",
|
||||
errx(1, "All sections must be fixed when using an overlay file; %" PRIu64 " %sn't",
|
||||
nbSectionsToAssign, nbSectionsToAssign == 1 ? "is" : "are");
|
||||
|
||||
/* Assign all remaining sections by decreasing constraint order */
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "link/object.h"
|
||||
#include "link/symbol.h"
|
||||
@@ -65,7 +66,7 @@ noreturn_ void fatal(char const *fmt, ...)
|
||||
if (nbErrors != UINT32_MAX)
|
||||
nbErrors++;
|
||||
|
||||
fprintf(stderr, "Linking aborted after %u error%s\n", nbErrors,
|
||||
fprintf(stderr, "Linking aborted after %" PRIu32 " error%s\n", nbErrors,
|
||||
nbErrors != 1 ? "s" : "");
|
||||
exit(1);
|
||||
}
|
||||
@@ -245,8 +246,8 @@ int main(int argc, char *argv[])
|
||||
/* and finally output the result. */
|
||||
patch_ApplyPatches();
|
||||
if (nbErrors) {
|
||||
fprintf(stderr, "Linking failed with %u error%s\n", nbErrors,
|
||||
nbErrors != 1 ? "s" : "");
|
||||
fprintf(stderr, "Linking failed with %" PRIu32 " error%s\n",
|
||||
nbErrors, nbErrors != 1 ? "s" : "");
|
||||
exit(1);
|
||||
}
|
||||
out_WriteFiles();
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "link/assign.h"
|
||||
#include "link/main.h"
|
||||
@@ -212,25 +213,25 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName,
|
||||
struct Section *fileSections[])
|
||||
{
|
||||
tryReadstr(patch->fileName, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%u's name: %s",
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s name: %s",
|
||||
fileName, sectName, i);
|
||||
tryReadlong(patch->offset, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%u's offset: %s",
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s offset: %s",
|
||||
fileName, sectName, i);
|
||||
tryReadlong(patch->pcSectionID, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%u's PC offset: %s",
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s PC offset: %s",
|
||||
fileName, sectName, i);
|
||||
patch->pcSection = patch->pcSectionID == -1
|
||||
? NULL
|
||||
: fileSections[patch->pcSectionID];
|
||||
tryReadlong(patch->pcOffset, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%u's PC offset: %s",
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s PC offset: %s",
|
||||
fileName, sectName, i);
|
||||
tryGetc(patch->type, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%u's type: %s",
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s type: %s",
|
||||
fileName, sectName, i);
|
||||
tryReadlong(patch->rpnSize, file,
|
||||
"%s: Unable to read \"%s\"'s patch #%u's RPN size: %s",
|
||||
"%s: Unable to read \"%s\"'s patch #%" PRIu32 "'s RPN size: %s",
|
||||
fileName, sectName, i);
|
||||
|
||||
uint8_t *rpnExpression =
|
||||
@@ -239,7 +240,7 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName,
|
||||
patch->rpnSize, file);
|
||||
|
||||
if (nbElementsRead != patch->rpnSize)
|
||||
errx(1, "%s: Cannot read \"%s\"'s patch #%u's RPN expression: %s",
|
||||
errx(1, "%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||
fileName, sectName, i,
|
||||
feof(file) ? "Unexpected end of file" : strerror(errno));
|
||||
patch->rpnExpression = rpnExpression;
|
||||
@@ -262,8 +263,8 @@ static void readSection(FILE *file, struct Section *section,
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s",
|
||||
fileName, section->name);
|
||||
if (tmp < 0 || tmp > UINT16_MAX)
|
||||
errx(1, "\"%s\"'s section size (%d) is invalid", section->name,
|
||||
tmp);
|
||||
errx(1, "\"%s\"'s section size (%" PRId32 ") is invalid",
|
||||
section->name, tmp);
|
||||
section->size = tmp;
|
||||
tryGetc(byte, file, "%s: Cannot read \"%s\"'s type: %s",
|
||||
fileName, section->name);
|
||||
@@ -273,7 +274,8 @@ static void readSection(FILE *file, struct Section *section,
|
||||
fileName, section->name);
|
||||
section->isAddressFixed = tmp >= 0;
|
||||
if (tmp > UINT16_MAX) {
|
||||
error("\"%s\"'s org is too large (%d)", section->name, tmp);
|
||||
error("\"%s\"'s org is too large (%" PRId32 ")",
|
||||
section->name, tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
section->org = tmp;
|
||||
@@ -288,7 +290,7 @@ static void readSection(FILE *file, struct Section *section,
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s alignment offset: %s",
|
||||
fileName, section->name);
|
||||
if (tmp > UINT16_MAX) {
|
||||
error("\"%s\"'s alignment offset is too large (%d)",
|
||||
error("\"%s\"'s alignment offset is too large (%" PRId32 ")",
|
||||
section->name, tmp);
|
||||
tmp = UINT16_MAX;
|
||||
}
|
||||
@@ -371,7 +373,7 @@ static void readAssertion(FILE *file, struct Assertion *assert,
|
||||
{
|
||||
char assertName[sizeof("Assertion #" EXPAND_AND_STR(UINT32_MAX))];
|
||||
|
||||
snprintf(assertName, sizeof(assertName), "Assertion #%u", i);
|
||||
snprintf(assertName, sizeof(assertName), "Assertion #%" PRIu32, i);
|
||||
|
||||
readPatch(file, &assert->patch, fileName, assertName, 0, fileSections);
|
||||
tryReadstr(assert->message, file, "%s: Cannot read assertion's message: %s",
|
||||
@@ -417,7 +419,7 @@ void obj_ReadFile(char const *fileName)
|
||||
tryReadlong(revNum, file, "%s: Cannot read revision number: %s",
|
||||
fileName);
|
||||
if (revNum != RGBDS_OBJECT_REV)
|
||||
errx(1, "%s is a revision 0x%04x object file, only 0x%04x is supported",
|
||||
errx(1, "%s is a revision 0x%04" PRIx32 " object file; only 0x%04x is supported",
|
||||
fileName, revNum, RGBDS_OBJECT_REV);
|
||||
|
||||
uint32_t nbSymbols;
|
||||
@@ -450,7 +452,7 @@ void obj_ReadFile(char const *fileName)
|
||||
|
||||
memset(nbSymPerSect, 0, sizeof(nbSymPerSect));
|
||||
|
||||
verbosePrint("Reading %u symbols...\n", nbSymbols);
|
||||
verbosePrint("Reading %" PRIu32 " symbols...\n", nbSymbols);
|
||||
for (uint32_t i = 0; i < nbSymbols; i++) {
|
||||
/* Read symbol */
|
||||
struct Symbol *symbol = malloc(sizeof(*symbol));
|
||||
@@ -469,7 +471,7 @@ void obj_ReadFile(char const *fileName)
|
||||
/* This file's sections, stored in a table to link symbols to them */
|
||||
struct Section *fileSections[nbSections ? nbSections : 1];
|
||||
|
||||
verbosePrint("Reading %u sections...\n", nbSections);
|
||||
verbosePrint("Reading %" PRIu32 " sections...\n", nbSections);
|
||||
for (uint32_t i = 0; i < nbSections; i++) {
|
||||
/* Read section */
|
||||
fileSections[i] = malloc(sizeof(*fileSections[i]));
|
||||
@@ -511,7 +513,7 @@ void obj_ReadFile(char const *fileName)
|
||||
|
||||
tryReadlong(nbAsserts, file, "%s: Cannot read number of assertions: %s",
|
||||
fileName);
|
||||
verbosePrint("Reading %u assertions...\n", nbAsserts);
|
||||
verbosePrint("Reading %" PRIu32 " assertions...\n", nbAsserts);
|
||||
for (uint32_t i = 0; i < nbAsserts; i++) {
|
||||
struct Assertion *assertion = malloc(sizeof(*assertion));
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "link/output.h"
|
||||
#include "link/main.h"
|
||||
@@ -51,7 +52,7 @@ void out_AddSection(struct Section const *section)
|
||||
uint32_t minNbBanks = targetBank + 1;
|
||||
|
||||
if (minNbBanks > maxNbBanks[section->type])
|
||||
errx(1, "Section \"%s\" has invalid bank range (%u > %u)",
|
||||
errx(1, "Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
||||
section->name, section->bank,
|
||||
maxNbBanks[section->type] - 1);
|
||||
|
||||
@@ -283,7 +284,7 @@ static void writeSymBank(struct SortedSections const *bankSections)
|
||||
|
||||
minSectList = &zlSectList;
|
||||
}
|
||||
fprintf(symFile, "%02x:%04x %s\n",
|
||||
fprintf(symFile, "%02" PRIx32 ":%04" PRIx16 " %s\n",
|
||||
minSectList->sect->bank, minSectList->addr,
|
||||
minSectList->sym->name);
|
||||
minSectList->i++;
|
||||
@@ -304,7 +305,7 @@ static void writeMapBank(struct SortedSections const *sectList,
|
||||
struct SortedSection const *section = sectList->sections;
|
||||
struct SortedSection const *zeroLenSection = sectList->zeroLenSections;
|
||||
|
||||
fprintf(mapFile, "%s bank #%u:\n", typeNames[type],
|
||||
fprintf(mapFile, "%s bank #%" PRIu32 ":\n", typeNames[type],
|
||||
bank + bankranges[type][0]);
|
||||
|
||||
uint16_t slack = maxsize[type];
|
||||
@@ -317,16 +318,16 @@ static void writeMapBank(struct SortedSections const *sectList,
|
||||
slack -= sect->size;
|
||||
|
||||
if (sect->size != 0)
|
||||
fprintf(mapFile, " SECTION: $%04x-$%04x ($%04x byte%s) [\"%s\"]\n",
|
||||
fprintf(mapFile, " SECTION: $%04" PRIx16 "-$%04" PRIx16 " ($%04" PRIx16 " byte%s) [\"%s\"]\n",
|
||||
sect->org, sect->org + sect->size - 1,
|
||||
sect->size, sect->size == 1 ? "" : "s",
|
||||
sect->name);
|
||||
else
|
||||
fprintf(mapFile, " SECTION: $%04x (0 bytes) [\"%s\"]\n",
|
||||
fprintf(mapFile, " SECTION: $%04" PRIx16 " (0 bytes) [\"%s\"]\n",
|
||||
sect->org, sect->name);
|
||||
|
||||
for (size_t i = 0; i < sect->nbSymbols; i++)
|
||||
fprintf(mapFile, " $%04x = %s\n",
|
||||
fprintf(mapFile, " $%04" PRIx32 " = %s\n",
|
||||
sect->symbols[i]->offset + sect->org,
|
||||
sect->symbols[i]->name);
|
||||
|
||||
@@ -336,7 +337,7 @@ static void writeMapBank(struct SortedSections const *sectList,
|
||||
if (slack == maxsize[type])
|
||||
fputs(" EMPTY\n\n", mapFile);
|
||||
else
|
||||
fprintf(mapFile, " SLACK: $%04x byte%s\n\n", slack,
|
||||
fprintf(mapFile, " SLACK: $%04" PRIx16 " byte%s\n\n", slack,
|
||||
slack == 1 ? "" : "s");
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "link/patch.h"
|
||||
@@ -316,7 +317,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
||||
if (value < 0
|
||||
|| (value > 0xFF && value < 0xFF00)
|
||||
|| value > 0xFFFF)
|
||||
error("%s: Value %d is not in HRAM range",
|
||||
error("%s: Value %" PRId32 " is not in HRAM range",
|
||||
patch->fileName, value);
|
||||
value &= 0xFF;
|
||||
break;
|
||||
@@ -327,7 +328,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
||||
* They can be easily checked with a bitmask
|
||||
*/
|
||||
if (value & ~0x38)
|
||||
error("%s: Value %d is not a RST vector",
|
||||
error("%s: Value %" PRId32 " is not a RST vector",
|
||||
patch->fileName, value);
|
||||
value |= 0xC7;
|
||||
break;
|
||||
@@ -370,7 +371,7 @@ static int32_t computeRPNExpr(struct Patch const *patch,
|
||||
}
|
||||
|
||||
if (stack.size > 1)
|
||||
error("%s: RPN stack has %lu entries on exit, not 1",
|
||||
error("%s: RPN stack has %zu entries on exit, not 1",
|
||||
patch->fileName, stack.size);
|
||||
|
||||
return popRPN();
|
||||
@@ -440,7 +441,7 @@ static void applyFilePatches(struct Section *section)
|
||||
int16_t offset = value - address;
|
||||
|
||||
if (offset < -128 || offset > 127)
|
||||
error("%s: jr target out of reach (expected -129 < %d < 128)",
|
||||
error("%s: jr target out of reach (expected -129 < %" PRId16 " < 128)",
|
||||
patch->fileName, offset);
|
||||
section->data[patch->offset] = offset & 0xFF;
|
||||
} else {
|
||||
@@ -457,10 +458,10 @@ static void applyFilePatches(struct Section *section)
|
||||
|
||||
if (value < types[patch->type].min
|
||||
|| value > types[patch->type].max)
|
||||
error("%s: Value %#x%s is not %u-bit",
|
||||
error("%s: Value %#" PRIx32 "%s is not %u-bit",
|
||||
patch->fileName, value,
|
||||
value < 0 ? " (maybe negative?)" : "",
|
||||
types[patch->type].size * 8);
|
||||
types[patch->type].size * 8U);
|
||||
for (uint8_t i = 0; i < types[patch->type].size; i++) {
|
||||
section->data[patch->offset + i] = value & 0xFF;
|
||||
value >>= 8;
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "link/main.h"
|
||||
#include "link/script.h"
|
||||
@@ -35,7 +36,7 @@ static uint32_t fileStackIndex;
|
||||
static void pushFile(char *newFileName)
|
||||
{
|
||||
if (fileStackIndex == UINT32_MAX)
|
||||
errx(1, "%s(%u): INCLUDE recursion limit reached",
|
||||
errx(1, "%s(%" PRIu32 "): INCLUDE recursion limit reached",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
if (fileStackIndex == fileStackSize) {
|
||||
@@ -45,7 +46,7 @@ static void pushFile(char *newFileName)
|
||||
fileStack = realloc(fileStack,
|
||||
sizeof(*fileStack) * fileStackSize);
|
||||
if (!fileStack)
|
||||
err(1, "%s(%u): Internal INCLUDE error",
|
||||
err(1, "%s(%" PRIu32 "): Internal INCLUDE error",
|
||||
linkerScriptName, lineNo);
|
||||
}
|
||||
|
||||
@@ -56,7 +57,7 @@ static void pushFile(char *newFileName)
|
||||
|
||||
linkerScript = fopen(newFileName, "r");
|
||||
if (!linkerScript)
|
||||
err(1, "%s(%u): Could not open \"%s\"",
|
||||
err(1, "%s(%" PRIu32 "): Could not open \"%s\"",
|
||||
linkerScriptName, lineNo, newFileName);
|
||||
lineNo = 1;
|
||||
linkerScriptName = newFileName;
|
||||
@@ -177,8 +178,8 @@ static int readChar(FILE *file)
|
||||
int curchar = getc(file);
|
||||
|
||||
if (curchar == EOF && ferror(file))
|
||||
err(1, "%s(%u): Unexpected error in %s", linkerScriptName,
|
||||
lineNo, __func__);
|
||||
err(1, "%s(%" PRIu32 "): Unexpected error in %s",
|
||||
linkerScriptName, lineNo, __func__);
|
||||
return curchar;
|
||||
}
|
||||
|
||||
@@ -223,7 +224,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
do {
|
||||
curchar = readChar(linkerScript);
|
||||
if (curchar == EOF || isNewline(curchar))
|
||||
errx(1, "%s(%u): Unterminated string",
|
||||
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
||||
linkerScriptName, lineNo);
|
||||
else if (curchar == '"')
|
||||
/* Quotes force a string termination */
|
||||
@@ -302,7 +303,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
if (tryParseNumber(str, &token.attr.number))
|
||||
token.type = TOKEN_NUMBER;
|
||||
else
|
||||
errx(1, "%s(%u): Unknown token \"%s\"",
|
||||
errx(1, "%s(%" PRIu32 "): Unknown token \"%s\"",
|
||||
linkerScriptName, lineNo, str);
|
||||
}
|
||||
|
||||
@@ -330,7 +331,7 @@ static void processCommand(enum LinkerScriptCommand command, uint16_t arg,
|
||||
}
|
||||
|
||||
if (arg < *pc)
|
||||
errx(1, "%s(%u): `%s` cannot be used to go backwards",
|
||||
errx(1, "%s(%" PRIu32 "): `%s` cannot be used to go backwards",
|
||||
linkerScriptName, lineNo, commands[command]);
|
||||
*pc = arg;
|
||||
}
|
||||
@@ -379,11 +380,11 @@ struct SectionPlacement *script_NextSection(void)
|
||||
|
||||
if (type != SECTTYPE_INVALID) {
|
||||
if (curaddr[type][bankID] > endaddr(type) + 1)
|
||||
errx(1, "%s(%u): Sections would extend past the end of %s ($%04hx > $%04hx)",
|
||||
errx(1, "%s(%" PRIu32 "): Sections would extend past the end of %s ($%04" PRIx16 " > $%04" PRIx16 ")",
|
||||
linkerScriptName, lineNo, typeNames[type],
|
||||
curaddr[type][bankID], endaddr(type));
|
||||
if (curaddr[type][bankID] < startaddr[type])
|
||||
errx(1, "%s(%u): PC underflowed ($%04hx < $%04hx)",
|
||||
errx(1, "%s(%" PRIu32 "): PC underflowed ($%04" PRIx16 " < $%04" PRIx16 ")",
|
||||
linkerScriptName, lineNo,
|
||||
curaddr[type][bankID], startaddr[type]);
|
||||
}
|
||||
@@ -404,7 +405,7 @@ struct SectionPlacement *script_NextSection(void)
|
||||
break;
|
||||
|
||||
case TOKEN_NUMBER:
|
||||
errx(1, "%s(%u): stray number \"%u\"",
|
||||
errx(1, "%s(%" PRIu32 "): stray number \"%" PRIu32 "\"",
|
||||
linkerScriptName, lineNo,
|
||||
token->attr.number);
|
||||
|
||||
@@ -417,13 +418,13 @@ struct SectionPlacement *script_NextSection(void)
|
||||
parserState = PARSER_LINEEND;
|
||||
|
||||
if (type == SECTTYPE_INVALID)
|
||||
errx(1, "%s(%u): Didn't specify a location before the section",
|
||||
errx(1, "%s(%" PRIu32 "): Didn't specify a location before the section",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
section.section =
|
||||
sect_GetSection(token->attr.string);
|
||||
if (!section.section)
|
||||
errx(1, "%s(%u): Unknown section \"%s\"",
|
||||
errx(1, "%s(%" PRIu32 "): Unknown section \"%s\"",
|
||||
linkerScriptName, lineNo,
|
||||
token->attr.string);
|
||||
section.org = curaddr[type][bankID];
|
||||
@@ -452,10 +453,10 @@ struct SectionPlacement *script_NextSection(void)
|
||||
|
||||
if (tokType == TOKEN_COMMAND) {
|
||||
if (type == SECTTYPE_INVALID)
|
||||
errx(1, "%s(%u): Didn't specify a location before the command",
|
||||
errx(1, "%s(%" PRIu32 "): Didn't specify a location before the command",
|
||||
linkerScriptName, lineNo);
|
||||
if (!hasArg)
|
||||
errx(1, "%s(%u): Command specified without an argument",
|
||||
errx(1, "%s(%" PRIu32 "): Command specified without an argument",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
processCommand(attr.command, arg,
|
||||
@@ -467,16 +468,16 @@ struct SectionPlacement *script_NextSection(void)
|
||||
* specifying the number is optional.
|
||||
*/
|
||||
if (!hasArg && nbbanks(type) != 1)
|
||||
errx(1, "%s(%u): Didn't specify a bank number",
|
||||
errx(1, "%s(%" PRIu32 "): Didn't specify a bank number",
|
||||
linkerScriptName, lineNo);
|
||||
else if (!hasArg)
|
||||
arg = bankranges[type][0];
|
||||
else if (arg < bankranges[type][0])
|
||||
errx(1, "%s(%u): specified bank number is too low (%u < %u)",
|
||||
errx(1, "%s(%" PRIu32 "): specified bank number is too low (%" PRIu32 " < %" PRIu32 ")",
|
||||
linkerScriptName, lineNo,
|
||||
arg, bankranges[type][0]);
|
||||
else if (arg > bankranges[type][1])
|
||||
errx(1, "%s(%u): specified bank number is too high (%u > %u)",
|
||||
errx(1, "%s(%" PRIu32 "): specified bank number is too high (%" PRIu32 " > %" PRIu32 ")",
|
||||
linkerScriptName, lineNo,
|
||||
arg, bankranges[type][1]);
|
||||
bank = arg;
|
||||
@@ -496,7 +497,7 @@ struct SectionPlacement *script_NextSection(void)
|
||||
|
||||
case PARSER_INCLUDE:
|
||||
if (token->type != TOKEN_STRING)
|
||||
errx(1, "%s(%u): Expected a file name after INCLUDE",
|
||||
errx(1, "%s(%" PRIu32 "): Expected a file name after INCLUDE",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
/* Switch to that file */
|
||||
@@ -516,7 +517,7 @@ lineend:
|
||||
return NULL;
|
||||
parserState = PARSER_LINEEND;
|
||||
} else if (token->type != TOKEN_NEWLINE)
|
||||
errx(1, "%s(%u): Unexpected %s at the end of the line",
|
||||
errx(1, "%s(%" PRIu32 "): Unexpected %s at the end of the line",
|
||||
linkerScriptName, lineNo,
|
||||
tokenTypes[token->type]);
|
||||
break;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "link/main.h"
|
||||
@@ -45,11 +46,11 @@ static void mergeSections(struct Section *target, struct Section *other)
|
||||
if (other->isAddressFixed) {
|
||||
if (target->isAddressFixed) {
|
||||
if (target->org != other->org)
|
||||
errx(1, "Section \"%s\" is defined with conflicting addresses $%x and $%x",
|
||||
errx(1, "Section \"%s\" is defined with conflicting addresses $%" PRIx16 " and $%" PRIx16,
|
||||
other->name, target->org, other->org);
|
||||
} else if (target->isAlignFixed) {
|
||||
if ((other->org - target->alignOfs) & target->alignMask)
|
||||
errx(1, "Section \"%s\" is defined with conflicting %u-byte alignment (offset %u) and address $%x",
|
||||
errx(1, "Section \"%s\" is defined with conflicting %" PRIu16 "-byte alignment (offset %" PRIu16 ") and address $%" PRIx16,
|
||||
other->name, target->alignMask + 1,
|
||||
target->alignOfs, other->org);
|
||||
}
|
||||
@@ -58,13 +59,13 @@ static void mergeSections(struct Section *target, struct Section *other)
|
||||
} else if (other->isAlignFixed) {
|
||||
if (target->isAddressFixed) {
|
||||
if ((target->org - other->alignOfs) & other->alignMask)
|
||||
errx(1, "Section \"%s\" is defined with conflicting address $%x and %u-byte alignment (offset %u)",
|
||||
errx(1, "Section \"%s\" is defined with conflicting address $%" PRIx16 " and %" PRIu16 "-byte alignment (offset %" PRIu16 ")",
|
||||
other->name, target->org,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
} else if (target->isAlignFixed
|
||||
&& (other->alignMask & target->alignOfs)
|
||||
!= (target->alignMask & other->alignOfs)) {
|
||||
errx(1, "Section \"%s\" is defined with conflicting %u-byte alignment (offset %u) and %u-byte alignment (offset %u)",
|
||||
errx(1, "Section \"%s\" is defined with conflicting %" PRIu16 "-byte alignment (offset %" PRIu16 ") and %" PRIu16 "-byte alignment (offset %" PRIu16 ")",
|
||||
other->name, target->alignMask + 1,
|
||||
target->alignOfs, other->alignMask + 1,
|
||||
other->alignOfs);
|
||||
@@ -80,7 +81,7 @@ static void mergeSections(struct Section *target, struct Section *other)
|
||||
target->isBankFixed = true;
|
||||
target->bank = other->bank;
|
||||
} else if (target->bank != other->bank) {
|
||||
errx(1, "Section \"%s\" is defined with conflicting banks %u and %u",
|
||||
errx(1, "Section \"%s\" is defined with conflicting banks %" PRIu32 " and %" PRIu32,
|
||||
other->name, target->bank, other->bank);
|
||||
}
|
||||
}
|
||||
@@ -171,7 +172,7 @@ static void doSanityChecks(struct Section *section, void *ptr)
|
||||
/* Too large an alignment may not be satisfiable */
|
||||
if (section->isAlignFixed
|
||||
&& (section->alignMask & startaddr[section->type]))
|
||||
fail("%s: %s sections cannot be aligned to $%x bytes",
|
||||
fail("%s: %s sections cannot be aligned to $%" PRIx16 " bytes",
|
||||
section->name, typeNames[section->type],
|
||||
section->alignMask + 1);
|
||||
|
||||
@@ -181,13 +182,13 @@ static void doSanityChecks(struct Section *section, void *ptr)
|
||||
if (section->isBankFixed && section->bank < minbank
|
||||
&& section->bank > maxbank)
|
||||
fail(minbank == maxbank
|
||||
? "Cannot place section \"%s\" in bank %d, it must be %d"
|
||||
: "Cannot place section \"%s\" in bank %d, it must be between %d and %d",
|
||||
? "Cannot place section \"%s\" in bank %" PRIu32 ", it must be %" PRIu32
|
||||
: "Cannot place section \"%s\" in bank %" PRIu32 ", it must be between %" PRIu32 " and %" PRIu32,
|
||||
section->name, section->bank, minbank, maxbank);
|
||||
|
||||
/* Check if section has a chance to be placed */
|
||||
if (section->size > maxsize[section->type])
|
||||
fail("Section \"%s\" is bigger than the max size for that type: %#x > %#x",
|
||||
fail("Section \"%s\" is bigger than the max size for that type: %#" PRIx16 " > %#" PRIx16,
|
||||
section->name, section->size, maxsize[section->type]);
|
||||
|
||||
/* Translate loose constraints to strong ones when they're equivalent */
|
||||
@@ -218,12 +219,12 @@ static void doSanityChecks(struct Section *section, void *ptr)
|
||||
/* Ensure the target address is valid */
|
||||
if (section->org < startaddr[section->type]
|
||||
|| section->org > endaddr(section->type))
|
||||
fail("Section \"%s\"'s fixed address %#x is outside of range [%#x; %#x]",
|
||||
fail("Section \"%s\"'s fixed address %#" PRIx16 " is outside of range [%#" PRIx16 "; %#" PRIx16 "]",
|
||||
section->name, section->org,
|
||||
startaddr[section->type], endaddr(section->type));
|
||||
|
||||
if (section->org + section->size > endaddr(section->type) + 1)
|
||||
fail("Section \"%s\"'s end address %#x is greater than last address %#x",
|
||||
fail("Section \"%s\"'s end address %#" PRIx16 " is greater than last address %#" PRIx16,
|
||||
section->name, section->org + section->size,
|
||||
endaddr(section->type) + 1);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "link/symbol.h"
|
||||
@@ -40,7 +41,7 @@ void sym_AddSymbol(struct Symbol *symbol)
|
||||
struct Symbol *other = hash_GetElement(symbols, symbol->name);
|
||||
|
||||
if (other)
|
||||
errx(1, "\"%s\" both in %s from %s(%d) and in %s from %s(%d)",
|
||||
errx(1, "\"%s\" both in %s from %s(%" PRId32 ") and in %s from %s(%" PRId32 ")",
|
||||
symbol->name,
|
||||
symbol->objFileName, symbol->fileName, symbol->lineNo,
|
||||
other->objFileName, other->fileName, other->lineNo);
|
||||
|
||||
Reference in New Issue
Block a user