Fix bug in assembler: incorrect reordering of branch instruction.

Increase cpp buffer size.
This commit is contained in:
Serge Vakulenko
2015-08-20 20:55:55 -07:00
parent c2a86d50bb
commit c8939dc646
4 changed files with 42 additions and 8 deletions

View File

@@ -1721,6 +1721,14 @@ done:
((type & FRT2) && rt == reorder_clobber))
reorder_flush();
}
if (reorder_full && (type & (FOFF18 | FAOFF18)) &&
relinfo.flags == RABS && (opcode & 0x8000)) {
/* Branch instruction with negative offset is being displaced
* by one word. Need to update the offset field. */
offset = opcode + 1;
opcode &= ~0xffff;
opcode |= (offset & 0xffff);
}
fputword (opcode, sfile[segm]);
fputrel (&relinfo, rfile[segm]);
if (reorder_full) {

View File

@@ -2,14 +2,14 @@ TOPSRC = $(shell cd ../../../..; pwd)
include $(TOPSRC)/target.mk
CFLAGS += -Wall -Os
TESTS = test1 test2 test3 test4
TESTS = test1 test2 test3 test4 test5
all: ../as ../aout
all: ../../../../lib/as ../../../../lib/aout
for i in $(TESTS); do \
$(AS) $$i.s -o $$i.o; \
$(OBJDUMP) -D $$i.o > $$i.gcc-dis; \
../as $$i.s -o $$i.o; \
../aout -r $$i.o > $$i.dis; \
../../../../lib/as $$i.s -o $$i.o; \
../../../../lib/aout -r $$i.o > $$i.dis; \
done
clean:

26
src/cmd/as/tests/test5.s Normal file
View File

@@ -0,0 +1,26 @@
.set reorder
x:
add $2, $16, $31
b x
sub $31, $11, $26
add $2, $16, $31
beqz $3, x
sub $31, $11, $26
add $2, $16, $31
j x
sub $31, $11, $26
and $31, $3, $18
b y
or $31, $8, $23
and $31, $3, $18
beqz $2, y
or $31, $8, $23
and $31, $3, $18
j y
or $31, $8, $23
y:

View File

@@ -48,7 +48,7 @@ extern int ofd;
#define ENTER 1
/* buffer used internally */
#define CPPBUF 512
#define CPPBUF 640
#ifndef CPPBUF
#if defined(__pdp11__)
#define CPPBUF BUFSIZ
@@ -86,7 +86,7 @@ extern int bidx;
#define C_SPEC 001
#define C_EP 002
#define C_ID 004
#define C_I (C_SPEC|C_ID)
#define C_I (C_SPEC|C_ID)
#define C_2 010 /* for yylex() tokenizing */
#define C_WSNL 020 /* ' ','\t','\r','\n' */
#define iswsnl(x) (spechr[x] & C_WSNL)
@@ -116,8 +116,8 @@ extern struct includ *ifiles;
/* Symbol table entry */
struct symtab {
const usch *namep;
const usch *value;
const usch *namep;
const usch *value;
const usch *file;
int line;
};