From 08dc1fcb4e66167bdc2d5fc8d6b7e8d1aedf3e25 Mon Sep 17 00:00:00 2001 From: Andre Fachat Date: Fri, 27 Oct 2023 21:57:03 +0200 Subject: [PATCH] reloc fix --- xa/misc/ldo65.c | 46 +++++++++++++++++++++++++++++++------ xa/tests/ldoreloc/60.s | 13 +++++++++++ xa/tests/ldoreloc/61.s | 15 ++++++++++++ xa/tests/ldoreloc/Makefile | 27 +++++++++++++++++++--- xa/tests/ldoreloc/t60.ok | Bin 0 -> 113 bytes xa/tests/ldoreloc/t61.ok | Bin 0 -> 113 bytes 6 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 xa/tests/ldoreloc/60.s create mode 100644 xa/tests/ldoreloc/61.s create mode 100644 xa/tests/ldoreloc/t60.ok create mode 100644 xa/tests/ldoreloc/t61.ok diff --git a/xa/misc/ldo65.c b/xa/misc/ldo65.c index f22ab06..21009a0 100644 --- a/xa/misc/ldo65.c +++ b/xa/misc/ldo65.c @@ -288,9 +288,13 @@ int main(int argc, char *argv[]) { file->ddiff = ((dbase + tdlen) - file->dbase); file->bdiff = ((bbase + tblen) - file->bbase); file->zdiff = ((zbase + tzlen) - file->zbase); -/*printf("tbase=%04x, file->tbase=%04x, ttlen=%04x -> tdiff=%04x\n", - tbase, file->tbase, ttlen, file->tdiff);*/ +/* +printf("tbase=%04x+len=%04x->%04x, file->tbase=%04x, f.tlen=%04x -> tdiff=%04x\n", + tbase, ttlen, (tbase + ttlen), file->tbase, file->tlen, file->tdiff); +printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n", + zbase, tzlen, (zbase + tzlen), file->zbase, file->zlen, file->zdiff); +*/ /* update globals (for result file) */ ttlen += file->tlen; tdlen += file->dlen; @@ -298,6 +302,38 @@ int main(int argc, char *argv[]) { tzlen += file->zlen; } + // validate various situations. + { + int er = 0; + if (tbase + ttlen > 0x10000) { + fprintf(stderr, + "Overflow in text segment: end at %06x behind 64k limit\n", + tbase + ttlen); + er = 1; + } + if (dbase + tdlen > 0x10000) { + fprintf(stderr, + "Overflow in data segment: end at %06x behind 64k limit\n", + dbase + tdlen); + er = 1; + } + if (bbase + tblen > 0x10000) { + fprintf(stderr, + "Overflow in bss segment: end at %06x behind 64k limit\n", + bbase + tblen); + er = 1; + } + if (zbase + tzlen > 0x100) { + fprintf(stderr, + "Overflow in zero segment: end at %04x behind 256 byte limit\n", + zbase + tzlen); + er = 1; + } + if (er) { + exit (1); + } + } + // ------------------------------------------------------------------------- // step 3 - merge globals from all files into single table // @@ -710,7 +746,7 @@ file65 *load_file(char *fname) { file->bbase = file->buf[17]*256+file->buf[16]; file->blen = file->buf[19]*256+file->buf[18]; file->zbase = file->buf[21]*256+file->buf[20]; - file->zlen = file->buf[23]*256+file->buf[21]; + file->zlen = file->buf[23]*256+file->buf[22]; file->tpos = hlen; file->dpos = hlen + file->tlen; @@ -1056,10 +1092,6 @@ printf("found undef'd label %s, resolved=%d, newidx=%d, (ri=%d, ro=%d)\n", u->na ri += 4;// account for position, segment byte, label number in reloc table } new = old + diff; - if (((diff & 0xff) + (old & 0xff)) > 0xff) { - fprintf(stderr,"Warning: overflow in byte relocation at %04x in file %s\n", - pos, fp->fname); - } buf[addr-base+pos] = new & 255; break; } diff --git a/xa/tests/ldoreloc/60.s b/xa/tests/ldoreloc/60.s new file mode 100644 index 0000000..70e5a40 --- /dev/null +++ b/xa/tests/ldoreloc/60.s @@ -0,0 +1,13 @@ + + .zero +ptr .word 0 + .text + +foo =$1234 + + lda ptr2 +loop: jmp loop + + .data +bar .word bla + diff --git a/xa/tests/ldoreloc/61.s b/xa/tests/ldoreloc/61.s new file mode 100644 index 0000000..bc3f771 --- /dev/null +++ b/xa/tests/ldoreloc/61.s @@ -0,0 +1,15 @@ + jsr loop +bla: lda ptr + lda #ptr + + .zero +ptr2 .byt 0 + + .data + + .word foo + .word bar + .byte foo + + diff --git a/xa/tests/ldoreloc/Makefile b/xa/tests/ldoreloc/Makefile index 9dd62af..5922ca4 100644 --- a/xa/tests/ldoreloc/Makefile +++ b/xa/tests/ldoreloc/Makefile @@ -1,6 +1,6 @@ default: all -all: t1 t2 t10 t11 t20 t21 t30 t31 t40 t41 t50 t51 +all: t1 t2 t10 t11 t20 t21 t30 t31 t40 t41 t50 t51 t60 t61 t62 %.o65: %.s ../../xa -R -c -o $@ $< @@ -47,6 +47,15 @@ linked50.o65: 50.o65 51.o65 linked51.o65: 50.o65 51.o65 ../../ldo65 -o $@ 51.o65 50.o65 +linked60.o65: 60.o65 61.o65 + ../../ldo65 -o $@ 60.o65 61.o65 + +linked61.o65: 60.o65 61.o65 + ../../ldo65 -o $@ 61.o65 60.o65 + +linked62.o65: 60.o65 61.o65 + ../../ldo65 -bd 65529 -bt 65523 -bz 255 -o $@ 61.o65 60.o65 && exit 1 || exit 0 + t1: linked.o65 ../../reloc65 -bt 32768 -xt -o $@ $< ../hextool $@ > $@.hex @@ -110,6 +119,18 @@ t51: linked51.o65 ../hextool $@ > $@.hex ../hextool -cmp=$@ < t51.ok -clean: - rm -f *.o65 *.hex t1 t2 t10 t11 t20 t21 t30 t31 t40 t41 t50 t51 +t60: linked60.o65 + ../../reloc65 -bt 32768 -bd 40960 -o $@ $< + ../hextool $@ > $@.hex + ../hextool -cmp=$@ < t60.ok + +t61: linked61.o65 + ../../reloc65 -bt 32768 -bd 40960 -o $@ $< + ../hextool $@ > $@.hex + ../hextool -cmp=$@ < t61.ok + +t62: linked62.o65 + +clean: + rm -f *.o65 *.hex t1 t2 t10 t11 t20 t21 t30 t31 t40 t41 t50 t51 t60 t61 diff --git a/xa/tests/ldoreloc/t60.ok b/xa/tests/ldoreloc/t60.ok new file mode 100644 index 0000000000000000000000000000000000000000..82db7b17b06ea76574d65234db55aca1b0ded281 GIT binary patch literal 113 zcmWlRu?>Sz5JTU;`$VKk!2~o}AOh+PkR_l(opz=?=Gew%_FbFt;-$#%kqo{-<5 z)bIpB|K!ZP)LZpa_{!D0h7v&z-NT38NqhcqVcAwH;cZ6hn%QhY)TeQcqcY7Sv5wAz GD)R#+?-e8f literal 0 HcmV?d00001 diff --git a/xa/tests/ldoreloc/t61.ok b/xa/tests/ldoreloc/t61.ok new file mode 100644 index 0000000000000000000000000000000000000000..33d02fca0de21c032e93f7ca9c476e7bd615333a GIT binary patch literal 113 zcmWlOu?@m76a_E;kqF5Wg(sk40c5BdfF+WGDw3m!0lti~hg*v5h`HvZyN-On(eM-0 zBRs&+znp{b;;Y?w22XLQDazX}+H|o^1$_>MfoUEw`SM<`^hPtic;!r&;+*q>1)s(h G4fO{eo)tU* literal 0 HcmV?d00001