From c1a97f6541b6a1b0e5144e0bfa4c37ecaf0f7e85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Ni=C3=B1o=20D=C3=ADaz?= Date: Wed, 28 Mar 2018 22:28:18 +0100 Subject: [PATCH] Allow to JR to numeric constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, JR was only allowed to labels (in the same section, or different sections). When trying to JR to an address specified as a numeric value, rgbasm would fail to calculate the JR offset (as it doesn't know the final address of the JR so it can't calculate the difference). This patch makes rgblink calculate the offset whenever there is a JR. Signed-off-by: Antonio Niño Díaz --- src/asm/globlex.c | 2 +- src/asm/output.c | 24 ++++++++---------------- src/link/patch.c | 2 +- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/asm/globlex.c b/src/asm/globlex.c index ca654280..79a8583d 100644 --- a/src/asm/globlex.c +++ b/src/asm/globlex.c @@ -579,7 +579,7 @@ void setup_lexer(void) lex_FloatAddRange(id, '@', '@'); lex_FloatAddRange(id, '#', '#'); - //@ID + // "@" id = lex_FloatAlloc(&tIDToken); lex_FloatAddFirstRange(id, '@', '@'); diff --git a/src/asm/output.c b/src/asm/output.c index db85c0d7..0059fe60 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -882,24 +882,16 @@ void out_PCRelByte(struct Expression *expr) { checkcodesection(); checksectionoverflow(1); - if (rpn_isReloc(expr)) { - if (nPass == 2) { - pCurrentSection->tData[nPC] = 0; - createpatch(PATCH_BYTE_JR, expr); - } - pCurrentSection->nPC += 1; - nPC += 1; - pPCSymbol->nValue += 1; - } else { - int32_t b = expr->nVal; - b = (int16_t)((b & 0xFFFF) - (nPC + 1)); - - if (nPass == 2 && ((b < -128) || (b > 127))) - yyerror("PC-relative value must be 8-bit"); - - out_AbsByte(b & 0xFF); + /* Always let the linker calculate the offset. */ + if (nPass == 2) { + pCurrentSection->tData[nPC] = 0; + createpatch(PATCH_BYTE_JR, expr); } + pCurrentSection->nPC += 1; + nPC += 1; + pPCSymbol->nValue += 1; + rpn_Reset(expr); } diff --git a/src/link/patch.c b/src/link/patch.c index 3c600a91..9d704264 100644 --- a/src/link/patch.c +++ b/src/link/patch.c @@ -314,7 +314,7 @@ void Patch(void) /* t contains the destination of the jump */ t = (int16_t)((t & 0xFFFF) - (nPatchOrg + 1)); - if (t >= -128 && t <= 255) { + if (t >= -128 && t <= 127) { t &= 0xFF; pSect->pData[pPatch->nOffset] = (uint8_t)t;