mirror of
https://github.com/fachat/xa65.git
synced 2024-06-08 23:29:30 +00:00
finished work on aligned linking, added tests
This commit is contained in:
parent
5ff76efec2
commit
cc03ac80be
|
@ -418,7 +418,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
}
|
||||
if (maxalign) {
|
||||
printf("Info: file %s requires alignment at %d-boundaries\n", alignfname, maxalign + 1);
|
||||
printf("Info: Alignment at %d-boundaries required\n", maxalign + 1);
|
||||
}
|
||||
switch (maxalign) {
|
||||
case 0:
|
||||
|
@ -447,19 +447,22 @@ int main(int argc, char *argv[]) {
|
|||
// then check start addresses
|
||||
file = fp[0];
|
||||
if (file->align != 0) {
|
||||
int er = 1;
|
||||
int er = 0;
|
||||
if (tbase & file->align) {
|
||||
fprintf(stderr, "Error: text segment start address ($%04x) not aligned as required (at %d bytes)\n",
|
||||
fprintf(stderr, "Error: text segment start address ($%04x) "
|
||||
"not aligned as required by first file (at %d bytes)\n",
|
||||
tbase, file->align + 1);
|
||||
er = 1;
|
||||
}
|
||||
if (dbase & file->align) {
|
||||
fprintf(stderr, "Error: data segment start address ($%04x) not aligned as required (at %d bytes)\n",
|
||||
fprintf(stderr, "Error: data segment start address ($%04x) "
|
||||
"not aligned as required by first file (at %d bytes)\n",
|
||||
dbase, file->align + 1);
|
||||
er = 1;
|
||||
}
|
||||
if (bbase & file->align) {
|
||||
fprintf(stderr, "Error: bss segment start address ($%04x) not aligned as required (at %d bytes)\n",
|
||||
fprintf(stderr, "Error: bss segment start address ($%04x) "
|
||||
"not aligned as required (by first file at %d bytes)\n",
|
||||
bbase, file->align + 1);
|
||||
er = 1;
|
||||
}
|
||||
|
@ -473,14 +476,30 @@ int main(int argc, char *argv[]) {
|
|||
file = fp[i];
|
||||
|
||||
/* compute align fillers */
|
||||
file->talign = file->align - ((tbase + ttlen) & file->align);
|
||||
file->dalign = file->align - ((dbase + tdlen) & file->align);
|
||||
file->balign = file->align - ((bbase + tblen) & file->align);
|
||||
file->talign = 0;
|
||||
file->dalign = 0;
|
||||
file->balign = 0;
|
||||
// filler only needed if align not zero ...
|
||||
if (file->align) {
|
||||
// ... and respective segment not empty
|
||||
if (file->tlen) {
|
||||
//file->talign = file->align + 1 - ((tbase + ttlen) & file->align);
|
||||
file->talign = ( -((tbase + ttlen) & file->align) ) & file->align;
|
||||
}
|
||||
if (file->dlen) {
|
||||
//file->dalign = file->align + 1 - ((dbase + tdlen) & file->align);
|
||||
file->dalign = ( -((dbase + tdlen) & file->align) ) & file->align;
|
||||
}
|
||||
if (file->blen) {
|
||||
//file->balign = file->align + 1 - ((bbase + tblen) & file->align);
|
||||
file->balign = ( -((bbase + tblen) & file->align) ) & file->align;
|
||||
}
|
||||
}
|
||||
|
||||
/* insert align fillers */
|
||||
ttlen += file->talign;
|
||||
tdlen += file->talign;
|
||||
tblen += file->talign;
|
||||
tdlen += file->dalign;
|
||||
tblen += file->balign;
|
||||
|
||||
/* compute relocation differences */
|
||||
file->tdiff = ((tbase + ttlen) - file->tbase);
|
||||
|
@ -514,6 +533,31 @@ printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n
|
|||
tzlen += file->zlen;
|
||||
}
|
||||
|
||||
// validate various situations.
|
||||
if (maxalign != 0) {
|
||||
int er = 0;
|
||||
if (tbase & maxalign) {
|
||||
fprintf(stderr, "Error: text segment start address ($%04x) "
|
||||
"not aligned as first required by file %s (at %d bytes)\n",
|
||||
tbase, alignfname, maxalign + 1);
|
||||
er = 1;
|
||||
}
|
||||
if (dbase & maxalign) {
|
||||
fprintf(stderr, "Error: data segment start address ($%04x) "
|
||||
"not aligned as first required by file %s (at %d bytes)\n",
|
||||
dbase, alignfname, maxalign + 1);
|
||||
er = 1;
|
||||
}
|
||||
if (bbase & maxalign) {
|
||||
fprintf(stderr, "Error: bss segment start address ($%04x) "
|
||||
"not aligned as first required (by file %s (at %d bytes)\n",
|
||||
bbase, alignfname, maxalign + 1);
|
||||
er = 1;
|
||||
}
|
||||
if (er) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
// validate various situations.
|
||||
{
|
||||
int er = 0;
|
||||
|
@ -659,7 +703,7 @@ printf("zbase=%04x+len=%04x->%04x, file->zbase=%04x, f.zlen=%04x -> zdiff=%04x\n
|
|||
//
|
||||
|
||||
// prepare header
|
||||
hdr[ 6] = 0; hdr[ 7] = 0;
|
||||
hdr[ 6] = trgmode & 255; hdr[ 7] = (trgmode>>8)& 255;
|
||||
hdr[ 8] = tbase & 255; hdr[ 9] = (tbase>>8) & 255;
|
||||
hdr[10] = ttlen & 255; hdr[11] = (ttlen >>8)& 255;
|
||||
hdr[12] = dbase & 255; hdr[13] = (dbase>>8) & 255;
|
||||
|
|
|
@ -535,10 +535,6 @@ int main(int argc,char *argv[])
|
|||
sprintf(out,"Warning: bss segment ($%04x) start address doesn't align to %d!\n", bbase, align);
|
||||
logout(out);
|
||||
}
|
||||
if(zbase & (align-1)) {
|
||||
sprintf(out,"Warning: zero segment ($%04x) start address doesn't align to %d!\n", zbase, align);
|
||||
logout(out);
|
||||
}
|
||||
if (n65816>0)
|
||||
fmode |= 0x8000;
|
||||
switch(align) {
|
||||
|
|
40
xa/tests/mode/Makefile
Normal file
40
xa/tests/mode/Makefile
Normal file
|
@ -0,0 +1,40 @@
|
|||
|
||||
FILES=at1.o65 at2.o65 at4.o65 at256.o65 ad1.o65 ad2.o65 ad4.o65 ad256.o65 ab1.o65 ab2.o65 ab4.o65 ab256.o65
|
||||
|
||||
VERBOSE=
|
||||
#VERBOSE=-v
|
||||
|
||||
XA=../../xa
|
||||
LDO=../../ldo65
|
||||
|
||||
all: test1 test2 test3 test4
|
||||
|
||||
%.o65: %.a65
|
||||
${XA} -R -o $@ $<
|
||||
|
||||
# test with files in order of increasing align
|
||||
test1: ${FILES}
|
||||
${LDO} ${VERBOSE} -o $@.o65 $^
|
||||
cmp $@.o65 $@.ok
|
||||
|
||||
|
||||
# test with files in order of decreasing align
|
||||
test2: ${FILES}
|
||||
${LDO} ${VERBOSE} -o $@.o65 ab256.o65 ab4.o65 ab2.o65 ab1.o65 ad256.o65 ad4.o65 ad2.o65 ad1.o65 at256.o65 at4.o65 at2.o65 at1.o65
|
||||
cmp $@.o65 $@.ok
|
||||
|
||||
# test with files in order of increasing align, not starting at align=1
|
||||
test3: ${FILES}
|
||||
${LDO} ${VERBOSE} -o $@.o65 ab2.o65 at2.o65 ad2.o65 ab4.o65 at4.o65 ad4.o65 ad256.o65 at256.o65 ab256.o65
|
||||
cmp $@.o65 $@.ok
|
||||
|
||||
# test with files in order of increasing align, with non-aligned segment addresses
|
||||
test4: ${FILES}
|
||||
${LDO} ${VERBOSE} -bt 1025 -bd 1025 -o $@.o65 ab2.o65 at2.o65 ad2.o65 ab4.o65 at4.o65 ad4.o65 ad256.o65 at256.o65 ab256.o65 || exit 0 && exit 1
|
||||
${LDO} ${VERBOSE} -bt 1026 -bd 1026 -o $@.o65 ab2.o65 at2.o65 ad2.o65 ab4.o65 at4.o65 ad4.o65 ad256.o65 at256.o65 ab256.o65 || exit 0 && exit 1
|
||||
${LDO} ${VERBOSE} -bt 1027 -bd 1027 -o $@.o65 ab2.o65 at2.o65 ad2.o65 ab4.o65 at4.o65 ad4.o65 ad256.o65 at256.o65 ab256.o65 || exit 0 && exit 1
|
||||
${LDO} ${VERBOSE} -bt 1028 -bd 1028 -o $@.o65 ab2.o65 at2.o65 ad2.o65 ab4.o65 at4.o65 ad4.o65 ad256.o65 at256.o65 ab256.o65 || exit 0 && exit 1
|
||||
|
||||
clean:
|
||||
rm -f *.o65
|
||||
|
6
xa/tests/mode/ab1.a65
Normal file
6
xa/tests/mode/ab1.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 1
|
||||
|
||||
.bss
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ab2.a65
Normal file
6
xa/tests/mode/ab2.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 2
|
||||
|
||||
.bss
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ab256.a65
Normal file
6
xa/tests/mode/ab256.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 256
|
||||
|
||||
.bss
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ab4.a65
Normal file
6
xa/tests/mode/ab4.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 4
|
||||
|
||||
.bss
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ad1.a65
Normal file
6
xa/tests/mode/ad1.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 1
|
||||
|
||||
.data
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ad2.a65
Normal file
6
xa/tests/mode/ad2.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 2
|
||||
|
||||
.data
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ad256.a65
Normal file
6
xa/tests/mode/ad256.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 256
|
||||
|
||||
.data
|
||||
.byt 0
|
||||
|
6
xa/tests/mode/ad4.a65
Normal file
6
xa/tests/mode/ad4.a65
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
.align 4
|
||||
|
||||
.data
|
||||
.byt 0
|
||||
|
4
xa/tests/mode/at1.a65
Normal file
4
xa/tests/mode/at1.a65
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
.align 1
|
||||
iny
|
||||
|
4
xa/tests/mode/at2.a65
Normal file
4
xa/tests/mode/at2.a65
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
.align 2
|
||||
iny
|
||||
|
4
xa/tests/mode/at256.a65
Normal file
4
xa/tests/mode/at256.a65
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
.align 256
|
||||
iny
|
||||
|
4
xa/tests/mode/at4.a65
Normal file
4
xa/tests/mode/at4.a65
Normal file
|
@ -0,0 +1,4 @@
|
|||
|
||||
.align 4
|
||||
iny
|
||||
|
BIN
xa/tests/mode/test1.ok
Normal file
BIN
xa/tests/mode/test1.ok
Normal file
Binary file not shown.
BIN
xa/tests/mode/test2.ok
Normal file
BIN
xa/tests/mode/test2.ok
Normal file
Binary file not shown.
BIN
xa/tests/mode/test3.ok
Normal file
BIN
xa/tests/mode/test3.ok
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user