From da13b94a4339b94b359076fb55d60303d43fdff8 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 25 Sep 2022 21:42:20 -0500 Subject: [PATCH] Properly evaluate non-constant expressions in EQU/GEQU records. Previously, the values of such expressions were essentially ignored, resulting in incorrect output. This affected code like the following example: test1 start lda >p rtl end D1 data p gequ val end val data dc i'123' end Note that the EQU/GEQU expression is evaluated within the context of the location that references it, not the location where it is defined. This affects the value of the location counter, as well as the symbol search behavior. The references for the OMF format do not clearly define which way this should be done, but the current behavior can cause problems with certain object files produced by ORCA/M. --- exp.asm | 1 + linker.notes | 3 +++ symbol.asm | 14 ++------------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/exp.asm b/exp.asm index a545482..73e4a6b 100644 --- a/exp.asm +++ b/exp.asm @@ -727,6 +727,7 @@ addr dc a'EndExp' $00 End * shiftFlag - 1 if the value is shifted, else 0 * shiftValue - expression result before shifting * shiftCount - shift counter +* symbolRelocatable - non-zero if sym is relocatable * returns the value of the expression * **************************************************************** diff --git a/linker.notes b/linker.notes index 9f2c539..dbd56c6 100644 --- a/linker.notes +++ b/linker.notes @@ -10,6 +10,9 @@ Updated 2022 2. A load segment is now flagged as position-independent only if all the constituent object segments have that attribute set. + 3. Fixed bug that caused EQU or GEQU expressions with non-constant + operands to be evaluated incorrectly. + 2.0.6 1. The linker could give a spurious error about the relative address calculation for a BRL instruction if it branched forward or backward more than 32 KB. Since the address diff --git a/symbol.asm b/symbol.asm index eccdb34..319f492 100644 --- a/symbol.asm +++ b/symbol.asm @@ -845,15 +845,10 @@ gb3 ldy #symPriv if sym^.symPriv then sv1 ldy #symExp if the value is an expression then lda [sym],Y jeq sv2 - ph2 copiedExpression save volitile variables + ph2 copiedExpression save volatile variables ph4 shiftCount ph2 shiftFlag ph4 shiftValue - ph2 symbolCount - ph2 symbolLength - ph2 symbolRelocatable - ph2 symbolType - ph4 symbolValue ldy #symVal+2 evaluate the expression lda [sym],Y pha @@ -875,12 +870,7 @@ sv1a lda symbolRelocatable if the symbol is relocatable then ldy #symSeg set the expression file lda [sym],Y sta expSegment -sv1c pl4 symbolValue restore volitile variables - pl2 symbolType - pl2 symbolRelocatable - pl2 symbolLength - pl2 symbolCount - pl4 shiftValue +sv1c pl4 shiftValue restore volatile variables pl2 shiftFlag pl4 shiftCount pl2 copiedExpression