Add check for odd branch target.

Apart from the fact that instruction addresses must be even, this can't
even be expressed since the branch offset is expressed in words.
This commit is contained in:
Olaf Seibert 2021-03-14 20:27:56 +01:00
parent 0e373a8570
commit b100021ffd
3 changed files with 155 additions and 148 deletions

View File

@ -693,6 +693,10 @@ int check_branch(
{
int s_offset;
if (offset & 1) {
report(stack->top, "Bad branch target (odd address)\n");
}
/* Sign-extend */
if (offset & 0100000)
s_offset = offset | ~0177777;

View File

@ -71,181 +71,183 @@ test-operands.mac:50: ***ERROR Branch target out of range (distance=-402)
53 000056 000577 br .+2+254.
test-operands.mac:54: ***ERROR Branch target out of range (distance=400)
54 000060 000400 br .+2+256. ; bad
55
56 ; OC_SOB
57
58 000062 077001 sob r0,.
59 000064 077001 sob 0,. ; yes MACRO11 accepts this
test-operands.mac:60: ***ERROR Junk at end of line (',3 ; bad
test-operands.mac:55: ***ERROR Bad branch target (odd address)
55 000062 000400 br .+2+1 ; bad (odd)
56
57 ; OC_SOB
58
59 000064 077001 sob r0,.
60 000066 077001 sob 0,. ; yes MACRO11 accepts this
test-operands.mac:61: ***ERROR Junk at end of line (',3 ; bad
')
60 000066 077001 sob r0,.,3 ; bad
test-operands.mac:61: ***ERROR Invalid addressing mode (register expected)
61 sob ; bad
test-operands.mac:62: ***ERROR Invalid syntax (comma expected)
62 sob r0 ; bad
61 000070 077001 sob r0,.,3 ; bad
test-operands.mac:62: ***ERROR Invalid addressing mode (register expected)
62 sob ; bad
test-operands.mac:63: ***ERROR Invalid syntax (comma expected)
63 sob r0 . ; bad
test-operands.mac:64: ***ERROR Invalid addressing mode (register expected)
64 sob 10,. ; bad
65
66 ; OC_ASH
67
68 000070 072027 000003 ash #3,r0
69 000074 072027 000003 ash #3,0 ; yes MACRO11 accepts this
test-operands.mac:70: ***ERROR Junk at end of line (',r1 ; bad
63 sob r0 ; bad
test-operands.mac:64: ***ERROR Invalid syntax (comma expected)
64 sob r0 . ; bad
test-operands.mac:65: ***ERROR Invalid addressing mode (register expected)
65 sob 10,. ; bad
66
67 ; OC_ASH
68
69 000072 072027 000003 ash #3,r0
70 000076 072027 000003 ash #3,0 ; yes MACRO11 accepts this
test-operands.mac:71: ***ERROR Junk at end of line (',r1 ; bad
')
70 000100 072027 000003 ash #3,r0,r1 ; bad
test-operands.mac:71: ***ERROR Invalid addressing mode (1st operand)
71 ash ; bad
test-operands.mac:72: ***ERROR Invalid syntax (comma expected)
72 ash #3 ; bad
71 000102 072027 000003 ash #3,r0,r1 ; bad
test-operands.mac:72: ***ERROR Invalid addressing mode (1st operand)
72 ash ; bad
test-operands.mac:73: ***ERROR Invalid syntax (comma expected)
73 ash #3 r0 ; bad
test-operands.mac:74: ***ERROR Invalid addressing mode (2nd operand: register expected)
74 ash #3,#0 ; bad
75
76 ; OC_JSR tested in test-jmp.mac
77
78 ; OC_FPPGENAC
79
80 000001 ac1 = %1
81 000005 ac5 = %5
82
83 000104 171111 mulf (r1),ac1
84 000106 171111 mulf (r1),1
test-operands.mac:85: ***ERROR Junk at end of line (',ac1 ; bad
73 ash #3 ; bad
test-operands.mac:74: ***ERROR Invalid syntax (comma expected)
74 ash #3 r0 ; bad
test-operands.mac:75: ***ERROR Invalid addressing mode (2nd operand: register expected)
75 ash #3,#0 ; bad
76
77 ; OC_JSR tested in test-jmp.mac
78
79 ; OC_FPPGENAC
80
81 000001 ac1 = %1
82 000005 ac5 = %5
83
84 000106 171111 mulf (r1),ac1
85 000110 171111 mulf (r1),1
test-operands.mac:86: ***ERROR Junk at end of line (',ac1 ; bad
')
85 000110 171111 mulf (r1),ac1,ac1 ; bad
test-operands.mac:86: ***ERROR Invalid addressing mode (1st operand)
86 mulf ; bad
86 000112 171111 mulf (r1),ac1,ac1 ; bad
test-operands.mac:87: ***ERROR Invalid addressing mode (1st operand)
87 mulf ( ; bad
test-operands.mac:88: ***ERROR Invalid syntax (comma expected)
88 mulf (r1) ; bad
87 mulf ; bad
test-operands.mac:88: ***ERROR Invalid addressing mode (1st operand)
88 mulf ( ; bad
test-operands.mac:89: ***ERROR Invalid syntax (comma expected)
89 mulf (r1) ac1 ; bad
test-operands.mac:90: ***ERROR Invalid destination fp register
90 000112 171011 mulf (r1),ac5 ; bad
91
92 ; OC_FPPACGEN
93
94 000114 174115 stf ac1,(r5)
95 000116 174115 stf 1,(r5)
test-operands.mac:96: ***ERROR Invalid source fp register
test-operands.mac:96: ***ERROR Invalid syntax (comma expected)
96 stf ; bad
89 mulf (r1) ; bad
test-operands.mac:90: ***ERROR Invalid syntax (comma expected)
90 mulf (r1) ac1 ; bad
test-operands.mac:91: ***ERROR Invalid destination fp register
91 000114 171011 mulf (r1),ac5 ; bad
92
93 ; OC_FPPACGEN
94
95 000116 174115 stf ac1,(r5)
96 000120 174115 stf 1,(r5)
test-operands.mac:97: ***ERROR Invalid source fp register
test-operands.mac:97: ***ERROR Invalid syntax (comma expected)
97 stf ac1 ; bad
97 stf ; bad
test-operands.mac:98: ***ERROR Invalid syntax (comma expected)
98 stf ac1 (r5) ; bad
test-operands.mac:99: ***ERROR Invalid source fp register
99 000120 174015 stf ac5,(r5) ; bad
100
101 ; OC_CIS2 operands are optional and an extension
102
103 000122 076152 cmpni
104 000124 076152 000001 000002 cmpni 1,2
test-operands.mac:105: ***ERROR Junk at end of line (',3 ; bad
98 stf ac1 ; bad
test-operands.mac:99: ***ERROR Invalid syntax (comma expected)
99 stf ac1 (r5) ; bad
test-operands.mac:100: ***ERROR Invalid source fp register
100 000122 174015 stf ac5,(r5) ; bad
101
102 ; OC_CIS2 operands are optional and an extension
103
104 000124 076152 cmpni
105 000126 076152 000001 000002 cmpni 1,2
test-operands.mac:106: ***ERROR Junk at end of line (',3 ; bad
')
105 000132 076152 000001 000002 cmpni 1,2,3 ; bad
test-operands.mac:106: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:106: ***ERROR Invalid expression (operand 2)
test-operands.mac:106: ***ERROR Invalid expression
106 000140 076152 000003 000000 cmpni 3 ; bad
106 000134 076152 000001 000002 cmpni 1,2,3 ; bad
test-operands.mac:107: ***ERROR Invalid syntax (operand 2: comma expected)
107 000146 076152 000004 000005 cmpni 4 5 ; bad
test-operands.mac:108: ***ERROR Invalid expression (operand 1)
test-operands.mac:108: ***ERROR Invalid expression (operand 2)
test-operands.mac:108: ***ERROR Invalid expression
test-operands.mac:108: ***ERROR Invalid expression
108 000154 076152 000000 000000 cmpni <>,<> ; bad
109
110 ; OC_CIS3 operands are optional and an extension
111
112 000162 076150 addni
113 000164 076150 000001 000002 addni 1,2,3
000172 000003
114 000174 076150 000001 000002 addni 1,2,3,4 ; bad
test-operands.mac:114: ***ERROR Junk at end of line (',4 ; bad
test-operands.mac:107: ***ERROR Invalid expression (operand 2)
test-operands.mac:107: ***ERROR Invalid expression
107 000142 076152 000003 000000 cmpni 3 ; bad
test-operands.mac:108: ***ERROR Invalid syntax (operand 2: comma expected)
108 000150 076152 000004 000005 cmpni 4 5 ; bad
test-operands.mac:109: ***ERROR Invalid expression (operand 1)
test-operands.mac:109: ***ERROR Invalid expression (operand 2)
test-operands.mac:109: ***ERROR Invalid expression
test-operands.mac:109: ***ERROR Invalid expression
109 000156 076152 000000 000000 cmpni <>,<> ; bad
110
111 ; OC_CIS3 operands are optional and an extension
112
113 000164 076150 addni
114 000166 076150 000001 000002 addni 1,2,3
000174 000003
115 000176 076150 000001 000002 addni 1,2,3,4 ; bad
test-operands.mac:115: ***ERROR Junk at end of line (',4 ; bad
')
000202 000003
test-operands.mac:115: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:115: ***ERROR Invalid expression (operand 2)
test-operands.mac:115: ***ERROR Invalid syntax (operand 3: comma expected)
test-operands.mac:115: ***ERROR Invalid expression (operand 3)
test-operands.mac:115: ***ERROR Invalid expression
test-operands.mac:115: ***ERROR Invalid expression
115 000204 076150 000001 000000 addni 1 ; bad
000212 000000
000204 000003
test-operands.mac:116: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:116: ***ERROR Invalid expression (operand 2)
test-operands.mac:116: ***ERROR Invalid syntax (operand 3: comma expected)
test-operands.mac:116: ***ERROR Invalid expression (operand 3)
test-operands.mac:116: ***ERROR Invalid expression
116 000214 076150 000001 000002 addni 1,2 ; bad
000222 000000
test-operands.mac:117: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:116: ***ERROR Invalid expression
116 000206 076150 000001 000000 addni 1 ; bad
000214 000000
test-operands.mac:117: ***ERROR Invalid syntax (operand 3: comma expected)
117 000224 076150 000001 000002 addni 1 2 3 ; bad
000232 000003
test-operands.mac:118: ***ERROR Invalid expression (operand 1)
test-operands.mac:118: ***ERROR Invalid expression (operand 2)
test-operands.mac:118: ***ERROR Invalid expression (operand 3)
test-operands.mac:118: ***ERROR Invalid expression
test-operands.mac:118: ***ERROR Invalid expression
test-operands.mac:118: ***ERROR Invalid expression
118 000234 076150 000000 000000 addni <>,<>,<> ; bad
000242 000000
119
120 ; OC_CIS4 operands are optional and an extension
121
122 000244 076132 movtci
123 000246 076132 000001 000002 movtci 1,2,3,4
000254 000003 000004
124 000260 076132 000001 000002 movtci 1,2,3,4,5
test-operands.mac:124: ***ERROR Junk at end of line (',5
test-operands.mac:117: ***ERROR Invalid expression (operand 3)
test-operands.mac:117: ***ERROR Invalid expression
117 000216 076150 000001 000002 addni 1,2 ; bad
000224 000000
test-operands.mac:118: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:118: ***ERROR Invalid syntax (operand 3: comma expected)
118 000226 076150 000001 000002 addni 1 2 3 ; bad
000234 000003
test-operands.mac:119: ***ERROR Invalid expression (operand 1)
test-operands.mac:119: ***ERROR Invalid expression (operand 2)
test-operands.mac:119: ***ERROR Invalid expression (operand 3)
test-operands.mac:119: ***ERROR Invalid expression
test-operands.mac:119: ***ERROR Invalid expression
test-operands.mac:119: ***ERROR Invalid expression
119 000236 076150 000000 000000 addni <>,<>,<> ; bad
000244 000000
120
121 ; OC_CIS4 operands are optional and an extension
122
123 000246 076132 movtci
124 000250 076132 000001 000002 movtci 1,2,3,4
000256 000003 000004
125 000262 076132 000001 000002 movtci 1,2,3,4,5
test-operands.mac:125: ***ERROR Junk at end of line (',5
')
000266 000003 000004
test-operands.mac:125: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:125: ***ERROR Invalid expression (operand 2)
test-operands.mac:125: ***ERROR Invalid syntax (operand 3: comma expected)
test-operands.mac:125: ***ERROR Invalid expression (operand 3)
test-operands.mac:125: ***ERROR Invalid syntax (operand 4: comma expected)
test-operands.mac:125: ***ERROR Invalid expression (operand 4)
test-operands.mac:125: ***ERROR Invalid expression
test-operands.mac:125: ***ERROR Invalid expression
125 000272 076132 000001 000000 movtci 1 ; bad
test-operands.mac:125: ***ERROR Invalid expression
000300 000000 000000
000270 000003 000004
test-operands.mac:126: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:126: ***ERROR Invalid expression (operand 2)
test-operands.mac:126: ***ERROR Invalid syntax (operand 3: comma expected)
test-operands.mac:126: ***ERROR Invalid expression (operand 3)
test-operands.mac:126: ***ERROR Invalid syntax (operand 4: comma expected)
test-operands.mac:126: ***ERROR Invalid expression (operand 4)
test-operands.mac:126: ***ERROR Invalid expression
126 000304 076132 000001 000002 movtci 1,2 ; bad
test-operands.mac:126: ***ERROR Invalid expression
000312 000000 000000
126 000274 076132 000001 000000 movtci 1 ; bad
test-operands.mac:126: ***ERROR Invalid expression
000302 000000 000000
test-operands.mac:127: ***ERROR Invalid syntax (operand 3: comma expected)
test-operands.mac:127: ***ERROR Invalid expression (operand 3)
test-operands.mac:127: ***ERROR Invalid syntax (operand 4: comma expected)
test-operands.mac:127: ***ERROR Invalid expression (operand 4)
127 000316 076132 000001 000002 movtci 1,2,3 ; bad
test-operands.mac:127: ***ERROR Invalid expression
000324 000003 000000
test-operands.mac:128: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:128: ***ERROR Invalid syntax (operand 3: comma expected)
127 000306 076132 000001 000002 movtci 1,2 ; bad
test-operands.mac:127: ***ERROR Invalid expression
000314 000000 000000
test-operands.mac:128: ***ERROR Invalid syntax (operand 4: comma expected)
128 000330 076132 000001 000002 movtci 1 2 3 4 ; bad
000336 000003 000004
test-operands.mac:129: ***ERROR Invalid expression (operand 1)
test-operands.mac:129: ***ERROR Invalid expression (operand 2)
test-operands.mac:129: ***ERROR Invalid expression (operand 3)
test-operands.mac:129: ***ERROR Invalid expression (operand 4)
test-operands.mac:129: ***ERROR Invalid expression
test-operands.mac:129: ***ERROR Invalid expression
test-operands.mac:129: ***ERROR Invalid expression
129 000342 076132 000000 000000 movtci <>,<>,<>,<> ; bad
test-operands.mac:129: ***ERROR Invalid expression
000350 000000 000000
130
131 .end
test-operands.mac:128: ***ERROR Invalid expression (operand 4)
128 000320 076132 000001 000002 movtci 1,2,3 ; bad
test-operands.mac:128: ***ERROR Invalid expression
000326 000003 000000
test-operands.mac:129: ***ERROR Invalid syntax (operand 2: comma expected)
test-operands.mac:129: ***ERROR Invalid syntax (operand 3: comma expected)
test-operands.mac:129: ***ERROR Invalid syntax (operand 4: comma expected)
129 000332 076132 000001 000002 movtci 1 2 3 4 ; bad
000340 000003 000004
test-operands.mac:130: ***ERROR Invalid expression (operand 1)
test-operands.mac:130: ***ERROR Invalid expression (operand 2)
test-operands.mac:130: ***ERROR Invalid expression (operand 3)
test-operands.mac:130: ***ERROR Invalid expression (operand 4)
test-operands.mac:130: ***ERROR Invalid expression
test-operands.mac:130: ***ERROR Invalid expression
test-operands.mac:130: ***ERROR Invalid expression
130 000344 076132 000000 000000 movtci <>,<>,<>,<> ; bad
test-operands.mac:130: ***ERROR Invalid expression
000352 000000 000000
131
132 .end
132
Symbol table
@ -256,4 +258,4 @@ Symbol table
Program sections:
. ABS. 000000 000 (RW,I,GBL,ABS,OVR,NOSAV)
000354 001 (RW,I,LCL,REL,CON,NOSAV)
000356 001 (RW,I,LCL,REL,CON,NOSAV)

View File

@ -52,6 +52,7 @@
br .+2
br .+2+254.
br .+2+256. ; bad
br .+2+1 ; bad (odd)
; OC_SOB