From 850952d612ad708d7952bc30b9a6c674fdc90f58 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 26 Sep 2022 21:28:12 -0500 Subject: [PATCH] Treat ORG records as giving a signed offset from the current location. This is the way they are defined in the GS/OS Reference, as well as the way they seem to be used by all assemblers and all other linkers that I could check (ORCA/M, MPW AsmIIGS, Apple LinkIIGS, old ORCA/APW LINKED, 8-bit ORCA linker). Previously, this linker treated ORG records as giving an absolute address to ORG to (but with a bug in the address computation). The OMF spec in appendix B of the ORCA/M manual defines them this way, but this is inconsistent with the spec in the GS/OS Reference and with the way ORG records are generated by ORCA/M itself (for an ORG *+expression directive). Therefore, I think this is just an error and the specification in the GS/OS Reference should be regarded as correct. We still do not support going backward (using a negative ORG operand). Trying to do so will just give an error. --- linker.notes | 9 ++++++++- pass1.asm | 9 ++++----- pass2.asm | 7 +++---- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/linker.notes b/linker.notes index dbd56c6..8ff8c4f 100644 --- a/linker.notes +++ b/linker.notes @@ -13,6 +13,11 @@ Updated 2022 3. Fixed bug that caused EQU or GEQU expressions with non-constant operands to be evaluated incorrectly. + 4. The numeric value in an ORG record is now treated as a signed + offset from the current location, consistent with its + definition in the GS/OS Reference. However, negative offset + values are not supported and will produce an error. + 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 @@ -69,7 +74,9 @@ Updated 2022 -- Documentation Update ----------------------------------------------------- -No changes. +ORCA/M Manual, p. 492 + +The operand in an ORG record is a signed offset from the current location, not an absolute address. (This is consistent with the definition in the GS/OS Reference, and with the behavior of ORCA/M and other assemblers and linkers.) -- Changes introduced in ORCA/Linker 2.1.0 ---------------------------------- diff --git a/pass1.asm b/pass1.asm index b18a290..24a5a34 100644 --- a/pass1.asm +++ b/pass1.asm @@ -137,13 +137,12 @@ DoOrg private sta r0 ldy #3 lda [sp],Y - sta r2+2 + sta r2 add4 sp,#5 - sub4 r0,loadOrg get the disp from the segment start - cmpl pc,r0 - bge lb1 if the disp is greater than the pc then - move4 r0,pc update the pc + lda r2 + bmi lb1 if the disp is positive + add4 pc,r0 update the pc lb1 anop rts end diff --git a/pass2.asm b/pass2.asm index 07ad2ff..bae0513 100644 --- a/pass2.asm +++ b/pass2.asm @@ -643,13 +643,12 @@ DoOrg private ldy #1 get the value lda [sp],Y - sta r4 + sta r0 ldy #3 lda [sp],Y - sta r6 + sta r2 add4 sp,#5 skip the op code & operand - sub4 pc,r4,r0 calculate the space to insert - lda r2 if space < 0 then + lda r2 if disp < 0 then bpl lb1 ph4 #0 Error(NULL,3) ph2 #3