From 602cc72d96f8f628f6102a35e92636373dd7ef81 Mon Sep 17 00:00:00 2001 From: Andre Fachat Date: Thu, 31 Oct 2019 22:08:50 +0100 Subject: [PATCH] Proper reset of segment between p1 and p2; err out when using segment pseudo-ops in abs mode --- xa/src/xa.c | 14 +++++++------- xa/src/xat.c | 23 ++++++++++------------- xa/tests/relocmode/Makefile | 9 +++++++++ xa/tests/relocmode/ok | Bin 0 -> 46 bytes xa/tests/relocmode/test1.s | 7 +++++++ xa/tests/reset_segment/Makefile | 8 ++++++++ xa/tests/reset_segment/ok | Bin 0 -> 42 bytes xa/tests/reset_segment/test1.s | 12 ++++++++++++ 8 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 xa/tests/relocmode/Makefile create mode 100644 xa/tests/relocmode/ok create mode 100644 xa/tests/relocmode/test1.s create mode 100644 xa/tests/reset_segment/Makefile create mode 100644 xa/tests/reset_segment/ok create mode 100644 xa/tests/reset_segment/test1.s diff --git a/xa/src/xa.c b/xa/src/xa.c index dea8eb0..0460b54 100644 --- a/xa/src/xa.c +++ b/xa/src/xa.c @@ -393,7 +393,7 @@ int main(int argc,char *argv[]) segment = SEG_TEXT; } else { /* prime old_segment in r_mode with SEG_TEXT */ - segment = SEG_TEXT; + segment = SEG_ABS; r_mode(RMODE_ABS); } @@ -462,13 +462,13 @@ int main(int argc,char *argv[]) seg_pass2(); - if(!relmode) { - /* prime old_segment in r_mode with SEG_TEXT */ - segment = SEG_TEXT; - r_mode(RMODE_ABS); + if(relmode) { + r_mode(RMODE_RELOC); + segment = SEG_TEXT; } else { - r_mode(RMODE_RELOC); - segment = SEG_TEXT; + /* prime old_segment in r_mode with SEG_TEXT */ + segment = SEG_ABS; + r_mode(RMODE_ABS); } er=pass2(); } diff --git a/xa/src/xat.c b/xa/src/xat.c index 681570c..21e0862 100644 --- a/xa/src/xat.c +++ b/xa/src/xat.c @@ -479,48 +479,44 @@ printf(" wrote %02x %02x %02x %02x %02x %02x\n", dsb_len = 0; } else if(n==Ktext) { -/* if(segment!=SEG_ABS) { */ segment = relmode ? SEG_TEXT : SEG_ABS; t[0]=Ksegment; t[1]=segment; *ll=2; er=E_OKDEF; -/* } else { - er=E_ILLSEGMENT; - } */ } else if(n==Kdata) { -/* if(segment!=SEG_ABS) { */ + if(relmode) { segment = SEG_DATA; t[0]=Ksegment; t[1]=SEG_DATA; *ll=2; er=E_OKDEF; -/* } else { + } else { er=E_ILLSEGMENT; - } */ + } } else if(n==Kbss) { -/* if(segment!=SEG_ABS) { */ + if(relmode) { segment = SEG_BSS; t[0]=Ksegment; t[1]=SEG_BSS; *ll=2; er=E_OKDEF; -/* } else { + } else { er=E_ILLSEGMENT; - } */ + } } else if(n==Kzero) { -/* if(segment!=SEG_ABS) { */ + if(relmode) { segment = SEG_ZERO; t[0]=Ksegment; t[1]=SEG_ZERO; *ll=2; er=E_OKDEF; -/* } else { + } else { er=E_ILLSEGMENT; - } */ + } } else if (n==Kbin) { int j; @@ -1512,6 +1508,7 @@ fprintf(stderr, "address mode: %i address: %i\n", am, vv[0]); } } else if(am==11 || am==16) { + /* relative, relative long */ if((segment!=SEG_ABS) && (!rlt[0])) { er=E_ILLPOINTER; } else { diff --git a/xa/tests/relocmode/Makefile b/xa/tests/relocmode/Makefile new file mode 100644 index 0000000..fef14f5 --- /dev/null +++ b/xa/tests/relocmode/Makefile @@ -0,0 +1,9 @@ +default: test1 + +test1: + ../../xa test1.s -o test1.o || exit 0 && exit 1 + ../../xa -R test1.s -o test1.o + ../hextool -cmp=ok < test1.o + +clean: + rm -f *.o diff --git a/xa/tests/relocmode/ok b/xa/tests/relocmode/ok new file mode 100644 index 0000000000000000000000000000000000000000..828bf9574eb56a101b69dd73ad96fc3bdfc61179 GIT binary patch literal 46 wcmZQ%$Tu@(00IGK1_l;J1_lQp1>!R>tYu(X#lXPS%)r3Nkd~j%z|6n`09D!qWB>pF literal 0 HcmV?d00001 diff --git a/xa/tests/relocmode/test1.s b/xa/tests/relocmode/test1.s new file mode 100644 index 0000000..5cd10d2 --- /dev/null +++ b/xa/tests/relocmode/test1.s @@ -0,0 +1,7 @@ + + lda foo + + .data + +foo .byt $aa + diff --git a/xa/tests/reset_segment/Makefile b/xa/tests/reset_segment/Makefile new file mode 100644 index 0000000..768ff2b --- /dev/null +++ b/xa/tests/reset_segment/Makefile @@ -0,0 +1,8 @@ +default: test1 + +test1: + ../../xa -R -LLIB6502 test1.s -o test1.o + ../hextool -cmp=ok < test1.o + +clean: + rm -f *.o diff --git a/xa/tests/reset_segment/ok b/xa/tests/reset_segment/ok new file mode 100644 index 0000000000000000000000000000000000000000..195159e65dfa7ebb2a6275566e6c0cb3e0038737 GIT binary patch literal 42 ncmZQ%$Tu@(00IFf1_l-&?Es;GtP4QQz`)3mmY>hS#3TR!KLP_^ literal 0 HcmV?d00001 diff --git a/xa/tests/reset_segment/test1.s b/xa/tests/reset_segment/test1.s new file mode 100644 index 0000000..4c634a4 --- /dev/null +++ b/xa/tests/reset_segment/test1.s @@ -0,0 +1,12 @@ + + ; forward reference + ; results in illegal ptr arithmetic when segment + ; is not reset between pass1 and pass2 + + bne foo +foo + + .data + + +