Make @ relative to the start of a ds even at link time

Fix #737
This commit is contained in:
Rangi
2021-02-14 20:53:44 -05:00
committed by Eldred Habert
parent 2bc12447e2
commit ee20d9010e
13 changed files with 74 additions and 72 deletions

View File

@@ -421,10 +421,6 @@ static int32_t computeRPNExpr(struct Patch const *patch,
isError = true;
} else {
value = patch->pcOffset + patch->pcSection->org;
// If the patch is an operand, PC is not at the patch's
// location, but at the (opcode) byte right before it
if (patch->isOperand)
value--;
}
} else {
symbol = getSymbol(fileSymbols, value);
@@ -520,9 +516,10 @@ static void applyFilePatches(struct Section *section, struct Section *dataSectio
/* `jr` is quite unlike the others... */
if (patch->type == PATCHTYPE_JR) {
/* Target is relative to the byte *after* the operand */
// Offset is relative to the byte *after* the operand
// PC as operand to `jr` is lower than reference PC by 2
uint16_t address = patch->pcSection->org
+ patch->pcOffset + 1;
+ patch->pcOffset + 2;
int16_t jumpOffset = value - address;
if (!isError && (jumpOffset < -128 || jumpOffset > 127))