From 3edd289dfb6e36392b46b0b71f28996ccd768087 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Sat, 6 Apr 2024 16:57:15 +0200 Subject: [PATCH 1/3] Add linker test for M records of length 3 --- tests/linker/LinkerTest.java | 18 ++++++++++++++++++ tests/linker/mod3/mod3.asm | 5 +++++ tests/linker/mod3/mod3.obj | 5 +++++ 3 files changed, 28 insertions(+) create mode 100644 tests/linker/mod3/mod3.asm create mode 100644 tests/linker/mod3/mod3.obj diff --git a/tests/linker/LinkerTest.java b/tests/linker/LinkerTest.java index d4bde5d..8a6fab3 100644 --- a/tests/linker/LinkerTest.java +++ b/tests/linker/LinkerTest.java @@ -605,6 +605,24 @@ public void testAbsolute() { } } + @Test + public void testModification3() { + System.out.println("running testModification3"); + List inputs = new ArrayList<>(); + inputs.add("tests/linker/mod3/mod3.obj"); + Options options = new Options(); + options.setOutputName("out.obj"); + options.setOutputPath("tests/linker/mod3/out.obj"); + + Linker test = new Linker(inputs, options); + try { + Section out = test.link(); + + } catch (LinkerError le) { + Assert.fail("LinkerError: " + le.getMessage()); + } + } + // private functions for testing // ----------------------------------------------------------------- diff --git a/tests/linker/mod3/mod3.asm b/tests/linker/mod3/mod3.asm new file mode 100644 index 0000000..8d32c9a --- /dev/null +++ b/tests/linker/mod3/mod3.asm @@ -0,0 +1,5 @@ +mod3 START 0 +main LDA x + ORG 4000 +x WORD 0x12345 + END mod3 diff --git a/tests/linker/mod3/mod3.obj b/tests/linker/mod3/mod3.obj new file mode 100644 index 0000000..9f767b3 --- /dev/null +++ b/tests/linker/mod3/mod3.obj @@ -0,0 +1,5 @@ +Hmod3 000000000FA3 +T00000003030FA0 +T000FA003012345 +M00000103 +E000000 From f5b34feee53ac820f0ca2314d8c15791c14d96ad Mon Sep 17 00:00:00 2001 From: Kljunas2 Date: Wed, 22 Feb 2023 16:58:02 +0100 Subject: [PATCH 2/3] fix linking M records with length 3 Previously, fix would be moved by one byte, which would overflow into the next command. --- src/sic/link/visitors/SecondPassVisitor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sic/link/visitors/SecondPassVisitor.java b/src/sic/link/visitors/SecondPassVisitor.java index 2784acd..da3b7d7 100644 --- a/src/sic/link/visitors/SecondPassVisitor.java +++ b/src/sic/link/visitors/SecondPassVisitor.java @@ -85,7 +85,7 @@ public void visit(MRecord mRecord) throws LinkerError { // each byte is 2 chars int start = (int)(fixAddressStart - fixRecord.getStartAddr()) * 2; // start of the addressed word - start = start + 6 - mRecord.getLength(); // last mRecord.getLength() halfbytes of the adressed word + start++; int end = start + mRecord.getLength(); String text = fixRecord.getText(); From aefbeced15041c29e0de606afea2951344e12f2f Mon Sep 17 00:00:00 2001 From: Kljunas2 Date: Wed, 22 Feb 2023 16:55:30 +0100 Subject: [PATCH 3/3] reformat tabs to spaces --- src/sic/link/visitors/SecondPassVisitor.java | 32 ++++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/sic/link/visitors/SecondPassVisitor.java b/src/sic/link/visitors/SecondPassVisitor.java index da3b7d7..e98ff43 100644 --- a/src/sic/link/visitors/SecondPassVisitor.java +++ b/src/sic/link/visitors/SecondPassVisitor.java @@ -58,22 +58,22 @@ public void visit(MRecord mRecord) throws LinkerError { // find the Trecord that has to be fixed TRecord fixRecord = null; - TRecord fixRecordEnd = null; - int found = 0; + TRecord fixRecordEnd = null; + int found = 0; if (currSection.getTRecords() != null) { for (TRecord tRecord : currSection.getTRecords()) { if (tRecord.contains(fixAddressStart)) { - found++; + found++; fixRecord = tRecord; - if (tRecord.contains(fixAddressEnd) || found == 2) - break; + if (tRecord.contains(fixAddressEnd) || found == 2) + break; } if (tRecord.contains(fixAddressEnd)) { - found++; + found++; fixRecordEnd = tRecord; - if (found == 2) - break; + if (found == 2) + break; } } } @@ -89,10 +89,10 @@ public void visit(MRecord mRecord) throws LinkerError { int end = start + mRecord.getLength(); String text = fixRecord.getText(); - int recordLength = text.length(); - if (fixRecordEnd != null && fixRecord != fixRecordEnd) { - text += fixRecordEnd.getText(); - } + int recordLength = text.length(); + if (fixRecordEnd != null && fixRecord != fixRecordEnd) { + text += fixRecordEnd.getText(); + } String fixBytes = text.substring(start, end); @@ -109,10 +109,10 @@ public void visit(MRecord mRecord) throws LinkerError { text = text.substring(0,start) + correctedString + text.substring(end); fixRecord.setText(text.substring(0,recordLength)); - if (fixRecordEnd != null && fixRecord != fixRecordEnd) { - text = text.substring(recordLength); - fixRecordEnd.setText(text); - } + if (fixRecordEnd != null && fixRecord != fixRecordEnd) { + text = text.substring(recordLength); + fixRecordEnd.setText(text); + } if (options.isVerbose()) System.out.println("fixing " + mRecord.getLength() + " half-bytes from " + fixBytes + " to " + correctedString + " symbol=" + symbol.getName());