Commit | Line | Data |
---|---|---|
355afbcd | 1 | /* tc-vax.c - vax-specific - |
8e86815b | 2 | Copyright (C) 1987, 1991, 1992, 1994 Free Software Foundation, Inc. |
355afbcd | 3 | |
a39116f1 | 4 | This file is part of GAS, the GNU Assembler. |
355afbcd | 5 | |
a39116f1 RP |
6 | GAS is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
355afbcd | 10 | |
a39116f1 RP |
11 | GAS is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
355afbcd | 15 | |
a39116f1 RP |
16 | You should have received a copy of the GNU General Public License |
17 | along with GAS; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
fecd2382 | 19 | |
fecd2382 RP |
20 | #include "as.h" |
21 | ||
fecd2382 RP |
22 | #include "vax-inst.h" |
23 | #include "obstack.h" /* For FRAG_APPEND_1_CHAR macro in "frags.h" */ | |
fecd2382 RP |
24 | |
25 | /* These chars start a comment anywhere in a source file (except inside | |
26 | another comment */ | |
27 | const char comment_chars[] = "#"; | |
28 | ||
29 | /* These chars only start a comment at the beginning of a line. */ | |
30 | /* Note that for the VAX the are the same as comment_chars above. */ | |
31 | const char line_comment_chars[] = "#"; | |
32 | ||
355afbcd KR |
33 | const char line_separator_chars[] = ""; |
34 | ||
fecd2382 RP |
35 | /* Chars that can be used to separate mant from exp in floating point nums */ |
36 | const char EXP_CHARS[] = "eE"; | |
37 | ||
38 | /* Chars that mean this number is a floating point constant */ | |
39 | /* as in 0f123.456 */ | |
40 | /* or 0H1.234E-12 (see exp chars above) */ | |
41 | const char FLT_CHARS[] = "dDfFgGhH"; | |
42 | ||
43 | /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be | |
44 | changed in read.c . Ideally it shouldn't have to know about it at all, | |
f3d817d8 | 45 | but nothing is ideal around here. */ |
fecd2382 | 46 | |
f3d817d8 DM |
47 | /* Hold details of an operand expression */ |
48 | static expressionS exp_of_operand[VIT_MAX_OPERANDS]; | |
49 | static segT seg_of_operand[VIT_MAX_OPERANDS]; | |
fecd2382 | 50 | |
f3d817d8 DM |
51 | /* A vax instruction after decoding. */ |
52 | static struct vit v; | |
fecd2382 | 53 | |
a39116f1 | 54 | /* Hold details of big operands. */ |
f3d817d8 | 55 | LITTLENUM_TYPE big_operand_bits[VIT_MAX_OPERANDS][SIZE_OF_LARGE_NUMBER]; |
fecd2382 | 56 | FLONUM_TYPE float_operand[VIT_MAX_OPERANDS]; |
f3d817d8 | 57 | /* Above is made to point into big_operand_bits by md_begin(). */ |
def66e24 DM |
58 | |
59 | int flag_hash_long_names; /* -+ */ | |
60 | int flag_one; /* -1 */ | |
61 | int flag_show_after_trunc; /* -H */ | |
62 | int flag_no_hash_mixed_case; /* -h NUM */ | |
fecd2382 RP |
63 | \f |
64 | /* | |
65 | * For VAX, relative addresses of "just the right length" are easy. | |
66 | * The branch displacement is always the last operand, even in | |
67 | * synthetic instructions. | |
68 | * For VAX, we encode the relax_substateTs (in e.g. fr_substate) as: | |
69 | * | |
70 | * 4 3 2 1 0 bit number | |
71 | * ---/ /--+-------+-------+-------+-------+-------+ | |
72 | * | what state ? | how long ? | | |
73 | * ---/ /--+-------+-------+-------+-------+-------+ | |
74 | * | |
75 | * The "how long" bits are 00=byte, 01=word, 10=long. | |
76 | * This is a Un*x convention. | |
77 | * Not all lengths are legit for a given value of (what state). | |
78 | * The "how long" refers merely to the displacement length. | |
79 | * The address usually has some constant bytes in it as well. | |
80 | * | |
355afbcd | 81 | |
a39116f1 | 82 | groups for VAX address relaxing. |
355afbcd | 83 | |
a39116f1 RP |
84 | 1. "foo" pc-relative. |
85 | length of byte, word, long | |
355afbcd | 86 | |
a39116f1 RP |
87 | 2a. J<cond> where <cond> is a simple flag test. |
88 | length of byte, word, long. | |
89 | VAX opcodes are: (Hex) | |
90 | bneq/bnequ 12 | |
91 | beql/beqlu 13 | |
92 | bgtr 14 | |
93 | bleq 15 | |
94 | bgeq 18 | |
95 | blss 19 | |
96 | bgtru 1a | |
97 | blequ 1b | |
98 | bvc 1c | |
99 | bvs 1d | |
100 | bgequ/bcc 1e | |
101 | blssu/bcs 1f | |
102 | Always, you complement 0th bit to reverse condition. | |
103 | Always, 1-byte opcode, then 1-byte displacement. | |
355afbcd | 104 | |
a39116f1 RP |
105 | 2b. J<cond> where cond tests a memory bit. |
106 | length of byte, word, long. | |
107 | Vax opcodes are: (Hex) | |
108 | bbs e0 | |
109 | bbc e1 | |
110 | bbss e2 | |
111 | bbcs e3 | |
112 | bbsc e4 | |
113 | bbcc e5 | |
114 | bbssi e6 | |
115 | bbcci e7 | |
116 | Always, you complement 0th bit to reverse condition. | |
117 | Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement | |
355afbcd | 118 | |
a39116f1 RP |
119 | 2c. J<cond> where cond tests low-order memory bit |
120 | length of byte,word,long. | |
121 | Vax opcodes are: (Hex) | |
122 | blbs e8 | |
123 | blbc e9 | |
124 | Always, you complement 0th bit to reverse condition. | |
125 | Always, 1-byte opcode, longword-address, 1-byte displacement. | |
355afbcd | 126 | |
a39116f1 RP |
127 | 3. Jbs/Jbr. |
128 | length of byte,word,long. | |
129 | Vax opcodes are: (Hex) | |
130 | bsbb 10 | |
131 | brb 11 | |
132 | These are like (2) but there is no condition to reverse. | |
133 | Always, 1 byte opcode, then displacement/absolute. | |
355afbcd | 134 | |
a39116f1 RP |
135 | 4a. JacbX |
136 | length of word, long. | |
137 | Vax opcodes are: (Hex) | |
138 | acbw 3d | |
139 | acbf 4f | |
140 | acbd 6f | |
141 | abcb 9d | |
142 | acbl f1 | |
143 | acbg 4ffd | |
144 | acbh 6ffd | |
145 | Always, we cannot reverse the sense of the branch; we have a word | |
146 | displacement. | |
147 | The double-byte op-codes don't hurt: we never want to modify the | |
148 | opcode, so we don't care how many bytes are between the opcode and | |
149 | the operand. | |
355afbcd | 150 | |
a39116f1 RP |
151 | 4b. JXobXXX |
152 | length of long, long, byte. | |
153 | Vax opcodes are: (Hex) | |
154 | aoblss f2 | |
155 | aobleq f3 | |
156 | sobgeq f4 | |
157 | sobgtr f5 | |
158 | Always, we cannot reverse the sense of the branch; we have a byte | |
159 | displacement. | |
355afbcd | 160 | |
a39116f1 RP |
161 | The only time we need to modify the opcode is for class 2 instructions. |
162 | After relax() we may complement the lowest order bit of such instruction | |
163 | to reverse sense of branch. | |
355afbcd | 164 | |
a39116f1 RP |
165 | For class 2 instructions, we store context of "where is the opcode literal". |
166 | We can change an opcode's lowest order bit without breaking anything else. | |
355afbcd | 167 | |
a39116f1 RP |
168 | We sometimes store context in the operand literal. This way we can figure out |
169 | after relax() what the original addressing mode was. | |
170 | */ | |
fecd2382 | 171 | \f |
f3d817d8 DM |
172 | /* These displacements are relative to the start address of the |
173 | displacement. The first letter is Byte, Word. 2nd letter is | |
174 | Forward, Backward. */ | |
fecd2382 RP |
175 | #define BF (1+ 127) |
176 | #define BB (1+-128) | |
177 | #define WF (2+ 32767) | |
178 | #define WB (2+-32768) | |
f3d817d8 | 179 | /* Dont need LF, LB because they always reach. [They are coded as 0.] */ |
fecd2382 RP |
180 | |
181 | ||
182 | #define C(a,b) ENCODE_RELAX(a,b) | |
a39116f1 | 183 | /* This macro has no side-effects. */ |
fecd2382 RP |
184 | #define ENCODE_RELAX(what,length) (((what) << 2) + (length)) |
185 | ||
186 | const relax_typeS | |
355afbcd KR |
187 | md_relax_table[] = |
188 | { | |
189 | {1, 1, 0, 0}, /* error sentinel 0,0 */ | |
190 | {1, 1, 0, 0}, /* unused 0,1 */ | |
191 | {1, 1, 0, 0}, /* unused 0,2 */ | |
192 | {1, 1, 0, 0}, /* unused 0,3 */ | |
193 | {BF + 1, BB + 1, 2, C (1, 1)},/* B^"foo" 1,0 */ | |
194 | {WF + 1, WB + 1, 3, C (1, 2)},/* W^"foo" 1,1 */ | |
195 | {0, 0, 5, 0}, /* L^"foo" 1,2 */ | |
196 | {1, 1, 0, 0}, /* unused 1,3 */ | |
197 | {BF, BB, 1, C (2, 1)}, /* b<cond> B^"foo" 2,0 */ | |
198 | {WF + 2, WB + 2, 4, C (2, 2)},/* br.+? brw X 2,1 */ | |
199 | {0, 0, 7, 0}, /* br.+? jmp X 2,2 */ | |
200 | {1, 1, 0, 0}, /* unused 2,3 */ | |
201 | {BF, BB, 1, C (3, 1)}, /* brb B^foo 3,0 */ | |
202 | {WF, WB, 2, C (3, 2)}, /* brw W^foo 3,1 */ | |
203 | {0, 0, 5, 0}, /* Jmp L^foo 3,2 */ | |
204 | {1, 1, 0, 0}, /* unused 3,3 */ | |
205 | {1, 1, 0, 0}, /* unused 4,0 */ | |
206 | {WF, WB, 2, C (4, 2)}, /* acb_ ^Wfoo 4,1 */ | |
207 | {0, 0, 10, 0}, /* acb_,br,jmp L^foo4,2 */ | |
208 | {1, 1, 0, 0}, /* unused 4,3 */ | |
209 | {BF, BB, 1, C (5, 1)}, /* Xob___,,foo 5,0 */ | |
210 | {WF + 4, WB + 4, 6, C (5, 2)},/* Xob.+2,brb.+3,brw5,1 */ | |
211 | {0, 0, 9, 0}, /* Xob.+2,brb.+6,jmp5,2 */ | |
fecd2382 RP |
212 | }; |
213 | ||
214 | #undef C | |
215 | #undef BF | |
216 | #undef BB | |
217 | #undef WF | |
218 | #undef WB | |
219 | ||
220 | void float_cons (); | |
221 | ||
222 | const pseudo_typeS md_pseudo_table[] = | |
223 | { | |
355afbcd KR |
224 | {"dfloat", float_cons, 'd'}, |
225 | {"ffloat", float_cons, 'f'}, | |
226 | {"gfloat", float_cons, 'g'}, | |
227 | {"hfloat", float_cons, 'h'}, | |
228 | {0}, | |
fecd2382 RP |
229 | }; |
230 | ||
231 | #define STATE_PC_RELATIVE (1) | |
232 | #define STATE_CONDITIONAL_BRANCH (2) | |
233 | #define STATE_ALWAYS_BRANCH (3) /* includes BSB... */ | |
234 | #define STATE_COMPLEX_BRANCH (4) | |
235 | #define STATE_COMPLEX_HOP (5) | |
355afbcd | 236 | |
fecd2382 RP |
237 | #define STATE_BYTE (0) |
238 | #define STATE_WORD (1) | |
239 | #define STATE_LONG (2) | |
240 | #define STATE_UNDF (3) /* Symbol undefined in pass1 */ | |
355afbcd KR |
241 | |
242 | ||
fecd2382 | 243 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
355afbcd | 244 | |
f3d817d8 DM |
245 | int flonum_gen2vax PARAMS ((char format_letter, FLONUM_TYPE * f, |
246 | LITTLENUM_TYPE * words)); | |
247 | static const char *vip_begin PARAMS ((int, char *, char *, char *)); | |
248 | static void vip_op_defaults PARAMS ((char *immediate, char *indirect, | |
249 | char *displen)); | |
250 | static void vip_op PARAMS ((char *, struct vop *)); | |
251 | static void vip PARAMS ((struct vit *, char *)); | |
355afbcd KR |
252 | |
253 | void | |
254 | md_begin () | |
fecd2382 | 255 | { |
f3d817d8 | 256 | const char *errtxt; |
355afbcd KR |
257 | FLONUM_TYPE *fP; |
258 | int i; | |
259 | ||
8e86815b | 260 | if ((errtxt = vip_begin (1, "$", "*", "`")) != 0) |
fecd2382 | 261 | { |
355afbcd | 262 | as_fatal ("VIP_BEGIN error:%s", errtxt); |
fecd2382 | 263 | } |
355afbcd KR |
264 | |
265 | for (i = 0, fP = float_operand; | |
266 | fP < float_operand + VIT_MAX_OPERANDS; | |
267 | i++, fP++) | |
fecd2382 | 268 | { |
355afbcd KR |
269 | fP->low = &big_operand_bits[i][0]; |
270 | fP->high = &big_operand_bits[i][SIZE_OF_LARGE_NUMBER - 1]; | |
fecd2382 RP |
271 | } |
272 | } | |
fecd2382 | 273 | \f |
f3d817d8 | 274 | void |
355afbcd | 275 | md_number_to_chars (con, value, nbytes) |
f3d817d8 DM |
276 | char con[]; |
277 | valueT value; | |
278 | int nbytes; | |
fecd2382 | 279 | { |
f3d817d8 | 280 | number_to_chars_littleendian (con, value, nbytes); |
fecd2382 RP |
281 | } |
282 | ||
283 | /* Fix up some data or instructions after we find out the value of a symbol | |
284 | that they reference. */ | |
285 | ||
286 | void /* Knows about order of bytes in address. */ | |
355afbcd | 287 | md_apply_fix (fixP, value) |
f3d817d8 DM |
288 | fixS *fixP; |
289 | long value; | |
fecd2382 | 290 | { |
f3d817d8 DM |
291 | number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal, |
292 | (valueT) value, fixP->fx_size); | |
fecd2382 RP |
293 | } |
294 | ||
f3d817d8 | 295 | long |
355afbcd KR |
296 | md_chars_to_number (con, nbytes) |
297 | unsigned char con[]; /* Low order byte 1st. */ | |
298 | int nbytes; /* Number of bytes in the input. */ | |
fecd2382 | 299 | { |
355afbcd KR |
300 | long retval; |
301 | for (retval = 0, con += nbytes - 1; nbytes--; con--) | |
fecd2382 | 302 | { |
355afbcd KR |
303 | retval <<= BITS_PER_CHAR; |
304 | retval |= *con; | |
fecd2382 | 305 | } |
355afbcd | 306 | return retval; |
fecd2382 RP |
307 | } |
308 | \f | |
309 | /* vax:md_assemble() emit frags for 1 instruction */ | |
310 | ||
311 | void | |
355afbcd KR |
312 | md_assemble (instruction_string) |
313 | char *instruction_string; /* A string: assemble 1 instruction. */ | |
314 | { | |
f3d817d8 DM |
315 | /* Non-zero if operand expression's segment is not known yet. */ |
316 | int is_undefined; | |
355afbcd | 317 | |
f3d817d8 | 318 | int length_code; |
355afbcd | 319 | char *p; |
f3d817d8 DM |
320 | /* An operand. Scans all operands. */ |
321 | struct vop *operandP; | |
355afbcd | 322 | char *save_input_line_pointer; |
f3d817d8 DM |
323 | /* What used to live after an expression. */ |
324 | char c_save; | |
325 | /* 1: instruction_string bad for all passes. */ | |
326 | int goofed; | |
327 | /* Points to slot just after last operand. */ | |
328 | struct vop *end_operandP; | |
329 | /* Points to expression values for this operand. */ | |
330 | expressionS *expP; | |
331 | segT *segP; | |
355afbcd KR |
332 | |
333 | /* These refer to an instruction operand expression. */ | |
f3d817d8 DM |
334 | /* Target segment of the address. */ |
335 | segT to_seg; | |
336 | valueT this_add_number; | |
337 | /* Positive (minuend) symbol. */ | |
338 | struct symbol *this_add_symbol; | |
339 | /* As a number. */ | |
340 | long opcode_as_number; | |
341 | /* Least significant byte 1st. */ | |
342 | char *opcode_as_chars; | |
355afbcd | 343 | /* As an array of characters. */ |
f3d817d8 DM |
344 | /* Least significant byte 1st */ |
345 | char *opcode_low_byteP; | |
346 | /* length (bytes) meant by vop_short. */ | |
347 | int length; | |
348 | /* 0, or 1 if '@' is in addressing mode. */ | |
349 | int at; | |
350 | /* From vop_nbytes: vax_operand_width (in bytes) */ | |
351 | int nbytes; | |
355afbcd | 352 | FLONUM_TYPE *floatP; |
355afbcd KR |
353 | LITTLENUM_TYPE literal_float[8]; |
354 | /* Big enough for any floating point literal. */ | |
355 | ||
f3d817d8 DM |
356 | vip (&v, instruction_string); |
357 | ||
355afbcd | 358 | /* |
9a75dc1f ILT |
359 | * Now we try to find as many as_warn()s as we can. If we do any as_warn()s |
360 | * then goofed=1. Notice that we don't make any frags yet. | |
361 | * Should goofed be 1, then this instruction will wedge in any pass, | |
362 | * and we can safely flush it, without causing interpass symbol phase | |
363 | * errors. That is, without changing label values in different passes. | |
364 | */ | |
8e86815b | 365 | if ((goofed = (*v.vit_error)) != 0) |
fecd2382 | 366 | { |
355afbcd | 367 | as_warn ("Ignoring statement due to \"%s\"", v.vit_error); |
fecd2382 | 368 | } |
355afbcd | 369 | /* |
9a75dc1f ILT |
370 | * We need to use expression() and friends, which require us to diddle |
371 | * input_line_pointer. So we save it and restore it later. | |
372 | */ | |
355afbcd KR |
373 | save_input_line_pointer = input_line_pointer; |
374 | for (operandP = v.vit_operand, | |
375 | expP = exp_of_operand, | |
f3d817d8 | 376 | segP = seg_of_operand, |
355afbcd KR |
377 | floatP = float_operand, |
378 | end_operandP = v.vit_operand + v.vit_operands; | |
379 | ||
380 | operandP < end_operandP; | |
381 | ||
f3d817d8 | 382 | operandP++, expP++, segP++, floatP++) |
355afbcd | 383 | { /* for each operand */ |
f3d817d8 | 384 | if (operandP->vop_error) |
fecd2382 | 385 | { |
f3d817d8 | 386 | as_warn ("Ignoring statement because \"%s\"", operandP->vop_error); |
355afbcd | 387 | goofed = 1; |
fecd2382 | 388 | } |
355afbcd | 389 | else |
9a75dc1f ILT |
390 | { |
391 | /* statement has no syntax goofs: lets sniff the expression */ | |
355afbcd KR |
392 | int can_be_short = 0; /* 1 if a bignum can be reduced to a short literal. */ |
393 | ||
394 | input_line_pointer = operandP->vop_expr_begin; | |
395 | c_save = operandP->vop_expr_end[1]; | |
396 | operandP->vop_expr_end[1] = '\0'; | |
397 | /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1. */ | |
f3d817d8 DM |
398 | *segP = expression (expP); |
399 | switch (expP->X_op) | |
fecd2382 | 400 | { |
f3d817d8 | 401 | case O_absent: |
355afbcd | 402 | /* for BSD4.2 compatibility, missing expression is absolute 0 */ |
f3d817d8 | 403 | expP->X_op = O_constant; |
355afbcd | 404 | expP->X_add_number = 0; |
f3d817d8 | 405 | /* For SEG_ABSOLUTE, we shouldn't need to set X_op_symbol, |
9a75dc1f ILT |
406 | X_add_symbol to any particular value. But, we will program |
407 | defensively. Since this situation occurs rarely so it costs | |
408 | us little to do, and stops Dean worrying about the origin of | |
409 | random bits in expressionS's. */ | |
355afbcd | 410 | expP->X_add_symbol = NULL; |
f3d817d8 | 411 | expP->X_op_symbol = NULL; |
355afbcd KR |
412 | break; |
413 | ||
f3d817d8 DM |
414 | case O_symbol: |
415 | case O_constant: | |
416 | break; | |
417 | ||
418 | default: | |
355afbcd | 419 | /* |
9a75dc1f | 420 | * Major bug. We can't handle the case of a |
f3d817d8 | 421 | * SEG_OP expression in a VIT_OPCODE_SYNTHETIC |
9a75dc1f ILT |
422 | * variable-length instruction. |
423 | * We don't have a frag type that is smart enough to | |
f3d817d8 DM |
424 | * relax a SEG_OP, and so we just force all |
425 | * SEG_OPs to behave like SEG_PASS1s. | |
9a75dc1f ILT |
426 | * Clearly, if there is a demand we can invent a new or |
427 | * modified frag type and then coding up a frag for this | |
f3d817d8 | 428 | * case will be easy. SEG_OP was invented for the |
9a75dc1f ILT |
429 | * .words after a CASE opcode, and was never intended for |
430 | * instruction operands. | |
431 | */ | |
355afbcd KR |
432 | need_pass_2 = 1; |
433 | as_warn ("Can't relocate expression"); | |
434 | break; | |
435 | ||
f3d817d8 | 436 | case O_big: |
355afbcd KR |
437 | /* Preserve the bits. */ |
438 | if (expP->X_add_number > 0) | |
fecd2382 | 439 | { |
355afbcd KR |
440 | bignum_copy (generic_bignum, expP->X_add_number, |
441 | floatP->low, SIZE_OF_LARGE_NUMBER); | |
fecd2382 | 442 | } |
355afbcd | 443 | else |
fecd2382 | 444 | { |
355afbcd KR |
445 | know (expP->X_add_number < 0); |
446 | flonum_copy (&generic_floating_point_number, | |
447 | floatP); | |
448 | if (strchr ("s i", operandP->vop_short)) | |
f3d817d8 DM |
449 | { |
450 | /* Could possibly become S^# */ | |
355afbcd KR |
451 | flonum_gen2vax (-expP->X_add_number, floatP, literal_float); |
452 | switch (-expP->X_add_number) | |
fecd2382 RP |
453 | { |
454 | case 'f': | |
355afbcd KR |
455 | can_be_short = |
456 | (literal_float[0] & 0xFC0F) == 0x4000 | |
457 | && literal_float[1] == 0; | |
458 | break; | |
459 | ||
fecd2382 | 460 | case 'd': |
355afbcd KR |
461 | can_be_short = |
462 | (literal_float[0] & 0xFC0F) == 0x4000 | |
463 | && literal_float[1] == 0 | |
464 | && literal_float[2] == 0 | |
465 | && literal_float[3] == 0; | |
466 | break; | |
467 | ||
fecd2382 | 468 | case 'g': |
355afbcd KR |
469 | can_be_short = |
470 | (literal_float[0] & 0xFF81) == 0x4000 | |
471 | && literal_float[1] == 0 | |
472 | && literal_float[2] == 0 | |
473 | && literal_float[3] == 0; | |
474 | break; | |
475 | ||
fecd2382 | 476 | case 'h': |
355afbcd KR |
477 | can_be_short = ((literal_float[0] & 0xFFF8) == 0x4000 |
478 | && (literal_float[1] & 0xE000) == 0 | |
479 | && literal_float[2] == 0 | |
480 | && literal_float[3] == 0 | |
481 | && literal_float[4] == 0 | |
482 | && literal_float[5] == 0 | |
483 | && literal_float[6] == 0 | |
484 | && literal_float[7] == 0); | |
485 | break; | |
486 | ||
fecd2382 | 487 | default: |
355afbcd KR |
488 | BAD_CASE (-expP->X_add_number); |
489 | break; | |
fecd2382 RP |
490 | } /* switch (float type) */ |
491 | } /* if (could want to become S^#...) */ | |
492 | } /* bignum or flonum ? */ | |
355afbcd KR |
493 | |
494 | if (operandP->vop_short == 's' | |
495 | || operandP->vop_short == 'i' | |
496 | || (operandP->vop_short == ' ' | |
497 | && operandP->vop_reg == 0xF | |
498 | && (operandP->vop_mode & 0xE) == 0x8)) | |
fecd2382 | 499 | { |
355afbcd KR |
500 | /* Saw a '#'. */ |
501 | if (operandP->vop_short == ' ') | |
f3d817d8 DM |
502 | { |
503 | /* We must chose S^ or I^. */ | |
355afbcd | 504 | if (expP->X_add_number > 0) |
f3d817d8 DM |
505 | { |
506 | /* Bignum: Short literal impossible. */ | |
355afbcd KR |
507 | operandP->vop_short = 'i'; |
508 | operandP->vop_mode = 8; | |
509 | operandP->vop_reg = 0xF; /* VAX PC. */ | |
fecd2382 | 510 | } |
355afbcd | 511 | else |
f3d817d8 DM |
512 | { |
513 | /* Flonum: Try to do it. */ | |
355afbcd | 514 | if (can_be_short) |
fecd2382 | 515 | { |
355afbcd KR |
516 | operandP->vop_short = 's'; |
517 | operandP->vop_mode = 0; | |
518 | operandP->vop_ndx = -1; | |
519 | operandP->vop_reg = -1; | |
f3d817d8 | 520 | expP->X_op = O_constant; |
fecd2382 | 521 | } |
355afbcd | 522 | else |
fecd2382 | 523 | { |
355afbcd KR |
524 | operandP->vop_short = 'i'; |
525 | operandP->vop_mode = 8; | |
526 | operandP->vop_reg = 0xF; /* VAX PC */ | |
fecd2382 RP |
527 | } |
528 | } /* bignum or flonum ? */ | |
529 | } /* if #, but no S^ or I^ seen. */ | |
355afbcd KR |
530 | /* No more ' ' case: either 's' or 'i'. */ |
531 | if (operandP->vop_short == 's') | |
fecd2382 | 532 | { |
355afbcd KR |
533 | /* Wants to be a short literal. */ |
534 | if (expP->X_add_number > 0) | |
fecd2382 | 535 | { |
355afbcd KR |
536 | as_warn ("Bignum not permitted in short literal. Immediate mode assumed."); |
537 | operandP->vop_short = 'i'; | |
538 | operandP->vop_mode = 8; | |
539 | operandP->vop_reg = 0xF; /* VAX PC. */ | |
fecd2382 | 540 | } |
355afbcd | 541 | else |
fecd2382 | 542 | { |
355afbcd | 543 | if (!can_be_short) |
fecd2382 | 544 | { |
355afbcd KR |
545 | as_warn ("Can't do flonum short literal: immediate mode used."); |
546 | operandP->vop_short = 'i'; | |
547 | operandP->vop_mode = 8; | |
548 | operandP->vop_reg = 0xF; /* VAX PC. */ | |
fecd2382 | 549 | } |
355afbcd | 550 | else |
fecd2382 | 551 | { /* Encode short literal now. */ |
355afbcd KR |
552 | int temp = 0; |
553 | ||
554 | switch (-expP->X_add_number) | |
fecd2382 RP |
555 | { |
556 | case 'f': | |
557 | case 'd': | |
355afbcd KR |
558 | temp = literal_float[0] >> 4; |
559 | break; | |
560 | ||
fecd2382 | 561 | case 'g': |
355afbcd KR |
562 | temp = literal_float[0] >> 1; |
563 | break; | |
564 | ||
fecd2382 | 565 | case 'h': |
355afbcd KR |
566 | temp = ((literal_float[0] << 3) & 070) |
567 | | ((literal_float[1] >> 13) & 07); | |
568 | break; | |
569 | ||
fecd2382 | 570 | default: |
355afbcd KR |
571 | BAD_CASE (-expP->X_add_number); |
572 | break; | |
fecd2382 | 573 | } |
355afbcd KR |
574 | |
575 | floatP->low[0] = temp & 077; | |
576 | floatP->low[1] = 0; | |
fecd2382 RP |
577 | } /* if can be short literal float */ |
578 | } /* flonum or bignum ? */ | |
579 | } | |
355afbcd | 580 | else |
fecd2382 | 581 | { /* I^# seen: set it up if float. */ |
355afbcd | 582 | if (expP->X_add_number < 0) |
fecd2382 | 583 | { |
355afbcd | 584 | memcpy (floatP->low, literal_float, sizeof (literal_float)); |
fecd2382 RP |
585 | } |
586 | } /* if S^# seen. */ | |
587 | } | |
355afbcd | 588 | else |
fecd2382 | 589 | { |
8e86815b KR |
590 | as_warn ("A bignum/flonum may not be a displacement: 0x%lx used", |
591 | (expP->X_add_number = 0x80000000L)); | |
355afbcd | 592 | /* Chosen so luser gets the most offset bits to patch later. */ |
fecd2382 | 593 | } |
355afbcd KR |
594 | expP->X_add_number = floatP->low[0] |
595 | | ((LITTLENUM_MASK & (floatP->low[1])) << LITTLENUM_NUMBER_OF_BITS); | |
596 | /* | |
460531da | 597 | * For the O_big case we have: |
f3d817d8 DM |
598 | * If vop_short == 's' then a short floating literal is in the |
599 | * lowest 6 bits of floatP -> low [0], which is | |
600 | * big_operand_bits [---] [0]. | |
601 | * If vop_short == 'i' then the appropriate number of elements | |
602 | * of big_operand_bits [---] [...] are set up with the correct | |
603 | * bits. | |
604 | * Also, just in case width is byte word or long, we copy the lowest | |
605 | * 32 bits of the number to X_add_number. | |
606 | */ | |
355afbcd | 607 | break; |
fecd2382 | 608 | } |
355afbcd | 609 | if (input_line_pointer != operandP->vop_expr_end + 1) |
fecd2382 | 610 | { |
355afbcd KR |
611 | as_warn ("Junk at end of expression \"%s\"", input_line_pointer); |
612 | goofed = 1; | |
fecd2382 | 613 | } |
355afbcd | 614 | operandP->vop_expr_end[1] = c_save; |
fecd2382 RP |
615 | } |
616 | } /* for(each operand) */ | |
355afbcd KR |
617 | |
618 | input_line_pointer = save_input_line_pointer; | |
619 | ||
620 | if (need_pass_2 || goofed) | |
fecd2382 | 621 | { |
355afbcd KR |
622 | return; |
623 | } | |
624 | ||
625 | ||
626 | /* Emit op-code. */ | |
627 | /* Remember where it is, in case we want to modify the op-code later. */ | |
628 | opcode_low_byteP = frag_more (v.vit_opcode_nbytes); | |
629 | memcpy (opcode_low_byteP, v.vit_opcode, v.vit_opcode_nbytes); | |
630 | opcode_as_number = md_chars_to_number (opcode_as_chars = v.vit_opcode, 4); | |
631 | for (operandP = v.vit_operand, | |
632 | expP = exp_of_operand, | |
f3d817d8 | 633 | segP = seg_of_operand, |
355afbcd KR |
634 | floatP = float_operand, |
635 | end_operandP = v.vit_operand + v.vit_operands; | |
636 | ||
637 | operandP < end_operandP; | |
638 | ||
639 | operandP++, | |
640 | floatP++, | |
f3d817d8 | 641 | segP++, |
355afbcd | 642 | expP++) |
f3d817d8 | 643 | { |
355afbcd | 644 | if (operandP->vop_ndx >= 0) |
fecd2382 | 645 | { |
355afbcd KR |
646 | /* indexed addressing byte */ |
647 | /* Legality of indexed mode already checked: it is OK */ | |
648 | FRAG_APPEND_1_CHAR (0x40 + operandP->vop_ndx); | |
649 | } /* if(vop_ndx>=0) */ | |
650 | ||
651 | /* Here to make main operand frag(s). */ | |
652 | this_add_number = expP->X_add_number; | |
653 | this_add_symbol = expP->X_add_symbol; | |
f3d817d8 | 654 | to_seg = *segP; |
355afbcd | 655 | is_undefined = (to_seg == SEG_UNKNOWN); |
355afbcd KR |
656 | at = operandP->vop_mode & 1; |
657 | length = (operandP->vop_short == 'b' | |
658 | ? 1 : (operandP->vop_short == 'w' | |
659 | ? 2 : (operandP->vop_short == 'l' | |
660 | ? 4 : 0))); | |
661 | nbytes = operandP->vop_nbytes; | |
662 | if (operandP->vop_access == 'b') | |
663 | { | |
664 | if (to_seg == now_seg || is_undefined) | |
fecd2382 | 665 | { |
355afbcd KR |
666 | /* If is_undefined, then it might BECOME now_seg. */ |
667 | if (nbytes) | |
668 | { | |
669 | p = frag_more (nbytes); | |
670 | fix_new (frag_now, p - frag_now->fr_literal, nbytes, | |
f3d817d8 | 671 | this_add_symbol, this_add_number, 1, NO_RELOC); |
355afbcd KR |
672 | } |
673 | else | |
674 | { /* to_seg==now_seg || to_seg == SEG_UNKNOWN */ | |
675 | /* nbytes==0 */ | |
676 | length_code = is_undefined ? STATE_UNDF : STATE_BYTE; | |
677 | if (opcode_as_number & VIT_OPCODE_SPECIAL) | |
fecd2382 | 678 | { |
355afbcd | 679 | if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP) |
fecd2382 | 680 | { |
355afbcd KR |
681 | /* br or jsb */ |
682 | frag_var (rs_machine_dependent, 5, 1, | |
683 | ENCODE_RELAX (STATE_ALWAYS_BRANCH, length_code), | |
684 | this_add_symbol, this_add_number, | |
685 | opcode_low_byteP); | |
686 | } | |
687 | else | |
688 | { | |
689 | if (operandP->vop_width == VAX_WIDTH_WORD_JUMP) | |
fecd2382 | 690 | { |
355afbcd KR |
691 | length_code = STATE_WORD; |
692 | /* JF: There is no state_byte for this one! */ | |
693 | frag_var (rs_machine_dependent, 10, 2, | |
694 | ENCODE_RELAX (STATE_COMPLEX_BRANCH, length_code), | |
695 | this_add_symbol, this_add_number, | |
696 | opcode_low_byteP); | |
fecd2382 | 697 | } |
355afbcd | 698 | else |
fecd2382 | 699 | { |
355afbcd KR |
700 | know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP); |
701 | frag_var (rs_machine_dependent, 9, 1, | |
702 | ENCODE_RELAX (STATE_COMPLEX_HOP, length_code), | |
703 | this_add_symbol, this_add_number, | |
704 | opcode_low_byteP); | |
fecd2382 RP |
705 | } |
706 | } | |
355afbcd KR |
707 | } |
708 | else | |
709 | { | |
710 | know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP); | |
711 | frag_var (rs_machine_dependent, 7, 1, | |
712 | ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, length_code), | |
713 | this_add_symbol, this_add_number, | |
714 | opcode_low_byteP); | |
fecd2382 RP |
715 | } |
716 | } | |
355afbcd KR |
717 | } |
718 | else | |
f3d817d8 DM |
719 | { |
720 | /* to_seg != now_seg && to_seg != SEG_UNKNOWN */ | |
355afbcd | 721 | /* |
f3d817d8 DM |
722 | * --- SEG FLOAT MAY APPEAR HERE ---- |
723 | */ | |
355afbcd KR |
724 | if (to_seg == SEG_ABSOLUTE) |
725 | { | |
726 | if (nbytes) | |
fecd2382 | 727 | { |
355afbcd KR |
728 | know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC)); |
729 | p = frag_more (nbytes); | |
730 | /* Conventional relocation. */ | |
731 | fix_new (frag_now, p - frag_now->fr_literal, | |
f3d817d8 DM |
732 | nbytes, &abs_symbol, this_add_number, |
733 | 1, NO_RELOC); | |
355afbcd KR |
734 | } |
735 | else | |
736 | { | |
737 | know (opcode_as_number & VIT_OPCODE_SYNTHETIC); | |
738 | if (opcode_as_number & VIT_OPCODE_SPECIAL) | |
fecd2382 | 739 | { |
355afbcd KR |
740 | if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP) |
741 | { | |
742 | /* br or jsb */ | |
743 | *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG; | |
744 | know (opcode_as_chars[1] == 0); | |
745 | p = frag_more (5); | |
746 | p[0] = VAX_ABSOLUTE_MODE; /* @#... */ | |
747 | md_number_to_chars (p + 1, this_add_number, 4); | |
748 | /* Now (eg) JMP @#foo or JSB @#foo. */ | |
749 | } | |
750 | else | |
fecd2382 | 751 | { |
355afbcd | 752 | if (operandP->vop_width == VAX_WIDTH_WORD_JUMP) |
fecd2382 | 753 | { |
355afbcd KR |
754 | p = frag_more (10); |
755 | p[0] = 2; | |
756 | p[1] = 0; | |
757 | p[2] = VAX_BRB; | |
758 | p[3] = 6; | |
759 | p[4] = VAX_JMP; | |
760 | p[5] = VAX_ABSOLUTE_MODE; /* @#... */ | |
761 | md_number_to_chars (p + 6, this_add_number, 4); | |
762 | /* | |
f3d817d8 DM |
763 | * Now (eg) ACBx 1f |
764 | * BRB 2f | |
765 | * 1: JMP @#foo | |
766 | * 2: | |
767 | */ | |
fecd2382 | 768 | } |
355afbcd | 769 | else |
fecd2382 | 770 | { |
355afbcd KR |
771 | know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP); |
772 | p = frag_more (9); | |
773 | p[0] = 2; | |
774 | p[1] = VAX_BRB; | |
775 | p[2] = 6; | |
776 | p[3] = VAX_JMP; | |
777 | p[4] = VAX_PC_RELATIVE_MODE + 1; /* @#... */ | |
778 | md_number_to_chars (p + 5, this_add_number, 4); | |
779 | /* | |
f3d817d8 DM |
780 | * Now (eg) xOBxxx 1f |
781 | * BRB 2f | |
782 | * 1: JMP @#foo | |
783 | * 2: | |
784 | */ | |
fecd2382 RP |
785 | } |
786 | } | |
fecd2382 | 787 | } |
355afbcd | 788 | else |
fecd2382 | 789 | { |
355afbcd KR |
790 | /* b<cond> */ |
791 | *opcode_low_byteP ^= 1; | |
f3d817d8 DM |
792 | /* To reverse the condition in a VAX branch, |
793 | complement the lowest order bit. */ | |
355afbcd KR |
794 | p = frag_more (7); |
795 | p[0] = 6; | |
796 | p[1] = VAX_JMP; | |
797 | p[2] = VAX_ABSOLUTE_MODE; /* @#... */ | |
798 | md_number_to_chars (p + 3, this_add_number, 4); | |
799 | /* | |
f3d817d8 DM |
800 | * Now (eg) BLEQ 1f |
801 | * JMP @#foo | |
802 | * 1: | |
803 | */ | |
fecd2382 | 804 | } |
355afbcd KR |
805 | } |
806 | } | |
807 | else | |
f3d817d8 DM |
808 | { |
809 | /* to_seg != now_seg && to_seg != SEG_UNKNOWN && to_Seg != SEG_ABSOLUTE */ | |
355afbcd KR |
810 | if (nbytes > 0) |
811 | { | |
812 | /* Pc-relative. Conventional relocation. */ | |
813 | know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC)); | |
814 | p = frag_more (nbytes); | |
815 | fix_new (frag_now, p - frag_now->fr_literal, | |
f3d817d8 DM |
816 | nbytes, &abs_symbol, this_add_number, |
817 | 1, NO_RELOC); | |
355afbcd KR |
818 | } |
819 | else | |
820 | { | |
821 | know (opcode_as_number & VIT_OPCODE_SYNTHETIC); | |
822 | if (opcode_as_number & VIT_OPCODE_SPECIAL) | |
fecd2382 | 823 | { |
355afbcd KR |
824 | if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP) |
825 | { | |
826 | /* br or jsb */ | |
827 | know (opcode_as_chars[1] == 0); | |
828 | *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG; | |
829 | p = frag_more (5); | |
830 | p[0] = VAX_PC_RELATIVE_MODE; | |
831 | fix_new (frag_now, | |
832 | p + 1 - frag_now->fr_literal, 4, | |
f3d817d8 | 833 | this_add_symbol, |
355afbcd KR |
834 | this_add_number, 1, NO_RELOC); |
835 | /* Now eg JMP foo or JSB foo. */ | |
836 | } | |
837 | else | |
fecd2382 | 838 | { |
355afbcd | 839 | if (operandP->vop_width == VAX_WIDTH_WORD_JUMP) |
fecd2382 | 840 | { |
355afbcd KR |
841 | p = frag_more (10); |
842 | p[0] = 0; | |
843 | p[1] = 2; | |
844 | p[2] = VAX_BRB; | |
845 | p[3] = 6; | |
846 | p[4] = VAX_JMP; | |
847 | p[5] = VAX_PC_RELATIVE_MODE; | |
848 | fix_new (frag_now, | |
849 | p + 6 - frag_now->fr_literal, 4, | |
f3d817d8 | 850 | this_add_symbol, |
355afbcd KR |
851 | this_add_number, 1, NO_RELOC); |
852 | /* | |
f3d817d8 DM |
853 | * Now (eg) ACBx 1f |
854 | * BRB 2f | |
855 | * 1: JMP foo | |
856 | * 2: | |
857 | */ | |
fecd2382 | 858 | } |
355afbcd | 859 | else |
fecd2382 | 860 | { |
355afbcd KR |
861 | know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP); |
862 | p = frag_more (10); | |
863 | p[0] = 2; | |
864 | p[1] = VAX_BRB; | |
865 | p[2] = 6; | |
866 | p[3] = VAX_JMP; | |
867 | p[4] = VAX_PC_RELATIVE_MODE; | |
868 | fix_new (frag_now, | |
869 | p + 5 - frag_now->fr_literal, | |
f3d817d8 | 870 | 4, this_add_symbol, |
355afbcd KR |
871 | this_add_number, 1, NO_RELOC); |
872 | /* | |
f3d817d8 DM |
873 | * Now (eg) xOBxxx 1f |
874 | * BRB 2f | |
875 | * 1: JMP foo | |
876 | * 2: | |
877 | */ | |
fecd2382 RP |
878 | } |
879 | } | |
355afbcd KR |
880 | } |
881 | else | |
882 | { | |
883 | know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP); | |
884 | *opcode_low_byteP ^= 1; /* Reverse branch condition. */ | |
885 | p = frag_more (7); | |
886 | p[0] = 6; | |
887 | p[1] = VAX_JMP; | |
888 | p[2] = VAX_PC_RELATIVE_MODE; | |
889 | fix_new (frag_now, p + 3 - frag_now->fr_literal, | |
f3d817d8 | 890 | 4, this_add_symbol, |
355afbcd | 891 | this_add_number, 1, NO_RELOC); |
fecd2382 RP |
892 | } |
893 | } | |
894 | } | |
895 | } | |
355afbcd KR |
896 | } |
897 | else | |
898 | { | |
899 | know (operandP->vop_access != 'b'); /* So it is ordinary operand. */ | |
900 | know (operandP->vop_access != ' '); /* ' ' target-independent: elsewhere. */ | |
901 | know (operandP->vop_access == 'a' | |
902 | || operandP->vop_access == 'm' | |
903 | || operandP->vop_access == 'r' | |
904 | || operandP->vop_access == 'v' | |
905 | || operandP->vop_access == 'w'); | |
906 | if (operandP->vop_short == 's') | |
fecd2382 | 907 | { |
355afbcd | 908 | if (to_seg == SEG_ABSOLUTE) |
fecd2382 | 909 | { |
355afbcd | 910 | if (this_add_number < 0 || this_add_number >= 64) |
fecd2382 | 911 | { |
8e86815b KR |
912 | as_warn ("Short literal overflow(%ld.), immediate mode assumed.", |
913 | (long) this_add_number); | |
355afbcd KR |
914 | operandP->vop_short = 'i'; |
915 | operandP->vop_mode = 8; | |
916 | operandP->vop_reg = 0xF; | |
fecd2382 RP |
917 | } |
918 | } | |
355afbcd KR |
919 | else |
920 | { | |
921 | as_warn ("Forced short literal to immediate mode. now_seg=%s to_seg=%s", | |
922 | segment_name (now_seg), segment_name (to_seg)); | |
923 | operandP->vop_short = 'i'; | |
924 | operandP->vop_mode = 8; | |
925 | operandP->vop_reg = 0xF; | |
fecd2382 | 926 | } |
355afbcd KR |
927 | } |
928 | if (operandP->vop_reg >= 0 && (operandP->vop_mode < 8 | |
929 | || (operandP->vop_reg != 0xF && operandP->vop_mode < 10))) | |
930 | { | |
931 | /* One byte operand. */ | |
932 | know (operandP->vop_mode > 3); | |
933 | FRAG_APPEND_1_CHAR (operandP->vop_mode << 4 | operandP->vop_reg); | |
934 | /* All 1-bytes except S^# happen here. */ | |
935 | } | |
936 | else | |
f3d817d8 DM |
937 | { |
938 | /* {@}{q^}foo{(Rn)} or S^#foo */ | |
355afbcd KR |
939 | if (operandP->vop_reg == -1 && operandP->vop_short != 's') |
940 | { | |
941 | /* "{@}{q^}foo" */ | |
942 | if (to_seg == now_seg) | |
943 | { | |
944 | if (length == 0) | |
fecd2382 | 945 | { |
355afbcd KR |
946 | know (operandP->vop_short == ' '); |
947 | p = frag_var (rs_machine_dependent, 10, 2, | |
948 | ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE), | |
949 | this_add_symbol, this_add_number, | |
950 | opcode_low_byteP); | |
951 | know (operandP->vop_mode == 10 + at); | |
952 | *p = at << 4; | |
f3d817d8 DM |
953 | /* At is the only context we need to carry |
954 | to other side of relax() process. Must | |
955 | be in the correct bit position of VAX | |
956 | operand spec. byte. */ | |
355afbcd KR |
957 | } |
958 | else | |
959 | { | |
960 | know (length); | |
961 | know (operandP->vop_short != ' '); | |
962 | p = frag_more (length + 1); | |
355afbcd KR |
963 | p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4); |
964 | fix_new (frag_now, p + 1 - frag_now->fr_literal, | |
f3d817d8 | 965 | length, this_add_symbol, |
355afbcd KR |
966 | this_add_number, 1, NO_RELOC); |
967 | } | |
968 | } | |
969 | else | |
970 | { /* to_seg != now_seg */ | |
971 | if (this_add_symbol == NULL) | |
972 | { | |
973 | know (to_seg == SEG_ABSOLUTE); | |
974 | /* Do @#foo: simpler relocation than foo-.(pc) anyway. */ | |
975 | p = frag_more (5); | |
976 | p[0] = VAX_ABSOLUTE_MODE; /* @#... */ | |
977 | md_number_to_chars (p + 1, this_add_number, 4); | |
978 | if (length && length != 4) | |
fecd2382 | 979 | { |
355afbcd | 980 | as_warn ("Length specification ignored. Address mode 9F used"); |
fecd2382 RP |
981 | } |
982 | } | |
355afbcd KR |
983 | else |
984 | { | |
985 | /* {@}{q^}other_seg */ | |
986 | know ((length == 0 && operandP->vop_short == ' ') | |
987 | || (length > 0 && operandP->vop_short != ' ')); | |
988 | if (is_undefined) | |
fecd2382 | 989 | { |
355afbcd | 990 | /* |
f3d817d8 DM |
991 | * We have a SEG_UNKNOWN symbol. It might |
992 | * turn out to be in the same segment as | |
993 | * the instruction, permitting relaxation. | |
994 | */ | |
355afbcd KR |
995 | p = frag_var (rs_machine_dependent, 5, 2, |
996 | ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF), | |
997 | this_add_symbol, this_add_number, | |
998 | 0); | |
999 | p[0] = at << 4; | |
fecd2382 | 1000 | } |
355afbcd | 1001 | else |
fecd2382 | 1002 | { |
355afbcd | 1003 | if (length == 0) |
fecd2382 | 1004 | { |
355afbcd KR |
1005 | know (operandP->vop_short == ' '); |
1006 | length = 4; /* Longest possible. */ | |
fecd2382 | 1007 | } |
355afbcd KR |
1008 | p = frag_more (length + 1); |
1009 | p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4); | |
1010 | md_number_to_chars (p + 1, this_add_number, length); | |
1011 | fix_new (frag_now, | |
1012 | p + 1 - frag_now->fr_literal, | |
f3d817d8 | 1013 | length, this_add_symbol, |
355afbcd | 1014 | this_add_number, 1, NO_RELOC); |
fecd2382 RP |
1015 | } |
1016 | } | |
1017 | } | |
355afbcd KR |
1018 | } |
1019 | else | |
f3d817d8 DM |
1020 | { |
1021 | /* {@}{q^}foo(Rn) or S^# or I^# or # */ | |
355afbcd | 1022 | if (operandP->vop_mode < 0xA) |
f3d817d8 DM |
1023 | { |
1024 | /* # or S^# or I^# */ | |
355afbcd | 1025 | if (length == 0 |
8e86815b | 1026 | && to_seg == SEG_ABSOLUTE && (expP->X_op != O_big) |
355afbcd KR |
1027 | && operandP->vop_mode == 8 /* No '@'. */ |
1028 | && this_add_number < 64 | |
1029 | && this_add_number >= 0) | |
1030 | { | |
1031 | operandP->vop_short = 's'; | |
1032 | } | |
1033 | if (operandP->vop_short == 's') | |
1034 | { | |
1035 | FRAG_APPEND_1_CHAR (this_add_number); | |
1036 | } | |
1037 | else | |
f3d817d8 DM |
1038 | { |
1039 | /* I^#... */ | |
355afbcd KR |
1040 | know (nbytes); |
1041 | p = frag_more (nbytes + 1); | |
1042 | know (operandP->vop_reg == 0xF); | |
1043 | p[0] = (operandP->vop_mode << 4) | 0xF; | |
8e86815b | 1044 | if ((to_seg == SEG_ABSOLUTE) && (expP->X_op != O_big)) |
fecd2382 | 1045 | { |
355afbcd | 1046 | /* |
f3d817d8 DM |
1047 | * If nbytes > 4, then we are scrod. We |
1048 | * don't know if the high order bytes | |
1049 | * are to be 0xFF or 0x00. BSD4.2 & RMS | |
1050 | * say use 0x00. OK --- but this | |
1051 | * assembler needs ANOTHER rewrite to | |
1052 | * cope properly with this bug. */ | |
355afbcd KR |
1053 | md_number_to_chars (p + 1, this_add_number, min (4, nbytes)); |
1054 | if (nbytes > 4) | |
1055 | { | |
1056 | memset (p + 5, '\0', nbytes - 4); | |
1057 | } | |
fecd2382 | 1058 | } |
355afbcd | 1059 | else |
fecd2382 | 1060 | { |
f3d817d8 | 1061 | if (expP->X_op == O_big) |
fecd2382 | 1062 | { |
355afbcd | 1063 | /* |
f3d817d8 DM |
1064 | * Problem here is to get the bytes |
1065 | * in the right order. We stored | |
1066 | * our constant as LITTLENUMs, not | |
1067 | * bytes. */ | |
355afbcd KR |
1068 | LITTLENUM_TYPE *lP; |
1069 | ||
1070 | lP = floatP->low; | |
1071 | if (nbytes & 1) | |
fecd2382 | 1072 | { |
355afbcd KR |
1073 | know (nbytes == 1); |
1074 | p[1] = *lP; | |
fecd2382 | 1075 | } |
355afbcd | 1076 | else |
fecd2382 | 1077 | { |
355afbcd | 1078 | for (p++; nbytes; nbytes -= 2, p += 2, lP++) |
fecd2382 | 1079 | { |
355afbcd | 1080 | md_number_to_chars (p, *lP, 2); |
fecd2382 RP |
1081 | } |
1082 | } | |
fecd2382 | 1083 | } |
355afbcd | 1084 | else |
fecd2382 | 1085 | { |
355afbcd | 1086 | fix_new (frag_now, p + 1 - frag_now->fr_literal, |
f3d817d8 | 1087 | nbytes, this_add_symbol, |
355afbcd | 1088 | this_add_number, 0, NO_RELOC); |
fecd2382 RP |
1089 | } |
1090 | } | |
355afbcd KR |
1091 | } |
1092 | } | |
1093 | else | |
1094 | { /* {@}{q^}foo(Rn) */ | |
1095 | know ((length == 0 && operandP->vop_short == ' ') | |
1096 | || (length > 0 && operandP->vop_short != ' ')); | |
1097 | if (length == 0) | |
1098 | { | |
1099 | if (to_seg == SEG_ABSOLUTE) | |
fecd2382 | 1100 | { |
f3d817d8 | 1101 | long test; |
355afbcd KR |
1102 | |
1103 | test = this_add_number; | |
1104 | ||
1105 | if (test < 0) | |
1106 | test = ~test; | |
1107 | ||
1108 | length = test & 0xffff8000 ? 4 | |
1109 | : test & 0xffffff80 ? 2 | |
1110 | : 1; | |
fecd2382 | 1111 | } |
355afbcd | 1112 | else |
fecd2382 | 1113 | { |
355afbcd | 1114 | length = 4; |
fecd2382 RP |
1115 | } |
1116 | } | |
355afbcd KR |
1117 | p = frag_more (1 + length); |
1118 | know (operandP->vop_reg >= 0); | |
1119 | p[0] = operandP->vop_reg | |
1120 | | ((at | "?\12\14?\16"[length]) << 4); | |
1121 | if (to_seg == SEG_ABSOLUTE) | |
1122 | { | |
1123 | md_number_to_chars (p + 1, this_add_number, length); | |
1124 | } | |
1125 | else | |
1126 | { | |
1127 | fix_new (frag_now, p + 1 - frag_now->fr_literal, | |
f3d817d8 | 1128 | length, this_add_symbol, |
355afbcd KR |
1129 | this_add_number, 0, NO_RELOC); |
1130 | } | |
fecd2382 | 1131 | } |
355afbcd KR |
1132 | } |
1133 | } /* if(single-byte-operand) */ | |
1134 | } | |
1135 | } /* for(operandP) */ | |
fecd2382 RP |
1136 | } /* vax_assemble() */ |
1137 | \f | |
1138 | /* | |
1139 | * md_estimate_size_before_relax() | |
1140 | * | |
1141 | * Called just before relax(). | |
1142 | * Any symbol that is now undefined will not become defined. | |
1143 | * Return the correct fr_subtype in the frag. | |
1144 | * Return the initial "guess for fr_var" to caller. | |
1145 | * The guess for fr_var is ACTUALLY the growth beyond fr_fix. | |
1146 | * Whatever we do to grow fr_fix or fr_var contributes to our returned value. | |
1147 | * Although it may not be explicit in the frag, pretend fr_var starts with a | |
1148 | * 0 value. | |
1149 | */ | |
1150 | int | |
355afbcd | 1151 | md_estimate_size_before_relax (fragP, segment) |
f3d817d8 DM |
1152 | fragS *fragP; |
1153 | segT segment; | |
fecd2382 | 1154 | { |
f3d817d8 DM |
1155 | char *p; |
1156 | int old_fr_fix; | |
355afbcd KR |
1157 | |
1158 | old_fr_fix = fragP->fr_fix; | |
1159 | switch (fragP->fr_subtype) | |
fecd2382 RP |
1160 | { |
1161 | case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF): | |
355afbcd | 1162 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment) |
fecd2382 | 1163 | { /* A relaxable case. */ |
355afbcd | 1164 | fragP->fr_subtype = ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE); |
fecd2382 | 1165 | } |
355afbcd | 1166 | else |
fecd2382 | 1167 | { |
355afbcd KR |
1168 | p = fragP->fr_literal + old_fr_fix; |
1169 | p[0] |= VAX_PC_RELATIVE_MODE; /* Preserve @ bit. */ | |
1170 | fragP->fr_fix += 1 + 4; | |
f3d817d8 | 1171 | fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol, |
355afbcd KR |
1172 | fragP->fr_offset, 1, NO_RELOC); |
1173 | frag_wane (fragP); | |
fecd2382 | 1174 | } |
355afbcd KR |
1175 | break; |
1176 | ||
fecd2382 | 1177 | case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_UNDF): |
355afbcd | 1178 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment) |
fecd2382 | 1179 | { |
355afbcd | 1180 | fragP->fr_subtype = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE); |
fecd2382 | 1181 | } |
355afbcd | 1182 | else |
fecd2382 | 1183 | { |
355afbcd KR |
1184 | p = fragP->fr_literal + old_fr_fix; |
1185 | *fragP->fr_opcode ^= 1; /* Reverse sense of branch. */ | |
1186 | p[0] = 6; | |
1187 | p[1] = VAX_JMP; | |
1188 | p[2] = VAX_PC_RELATIVE_MODE; /* ...(PC) */ | |
1189 | fragP->fr_fix += 1 + 1 + 1 + 4; | |
f3d817d8 | 1190 | fix_new (fragP, old_fr_fix + 3, 4, fragP->fr_symbol, |
355afbcd KR |
1191 | fragP->fr_offset, 1, NO_RELOC); |
1192 | frag_wane (fragP); | |
fecd2382 | 1193 | } |
355afbcd KR |
1194 | break; |
1195 | ||
fecd2382 | 1196 | case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_UNDF): |
355afbcd | 1197 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment) |
fecd2382 | 1198 | { |
355afbcd | 1199 | fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD); |
fecd2382 | 1200 | } |
355afbcd | 1201 | else |
fecd2382 | 1202 | { |
355afbcd KR |
1203 | p = fragP->fr_literal + old_fr_fix; |
1204 | p[0] = 2; | |
1205 | p[1] = 0; | |
1206 | p[2] = VAX_BRB; | |
1207 | p[3] = 6; | |
1208 | p[4] = VAX_JMP; | |
1209 | p[5] = VAX_PC_RELATIVE_MODE; /* ...(pc) */ | |
1210 | fragP->fr_fix += 2 + 2 + 1 + 1 + 4; | |
f3d817d8 | 1211 | fix_new (fragP, old_fr_fix + 6, 4, fragP->fr_symbol, |
355afbcd KR |
1212 | fragP->fr_offset, 1, NO_RELOC); |
1213 | frag_wane (fragP); | |
fecd2382 | 1214 | } |
355afbcd KR |
1215 | break; |
1216 | ||
fecd2382 | 1217 | case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_UNDF): |
355afbcd | 1218 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment) |
fecd2382 | 1219 | { |
355afbcd | 1220 | fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE); |
fecd2382 | 1221 | } |
355afbcd | 1222 | else |
fecd2382 | 1223 | { |
355afbcd KR |
1224 | p = fragP->fr_literal + old_fr_fix; |
1225 | p[0] = 2; | |
1226 | p[1] = VAX_BRB; | |
1227 | p[2] = 6; | |
1228 | p[3] = VAX_JMP; | |
1229 | p[4] = VAX_PC_RELATIVE_MODE; /* ...(pc) */ | |
1230 | fragP->fr_fix += 1 + 2 + 1 + 1 + 4; | |
f3d817d8 | 1231 | fix_new (fragP, old_fr_fix + 5, 4, fragP->fr_symbol, |
355afbcd KR |
1232 | fragP->fr_offset, 1, NO_RELOC); |
1233 | frag_wane (fragP); | |
fecd2382 | 1234 | } |
355afbcd KR |
1235 | break; |
1236 | ||
fecd2382 | 1237 | case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_UNDF): |
355afbcd | 1238 | if (S_GET_SEGMENT (fragP->fr_symbol) == segment) |
fecd2382 | 1239 | { |
355afbcd | 1240 | fragP->fr_subtype = ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE); |
fecd2382 | 1241 | } |
355afbcd | 1242 | else |
fecd2382 | 1243 | { |
355afbcd KR |
1244 | p = fragP->fr_literal + old_fr_fix; |
1245 | *fragP->fr_opcode += VAX_WIDEN_LONG; | |
1246 | p[0] = VAX_PC_RELATIVE_MODE; /* ...(PC) */ | |
1247 | fragP->fr_fix += 1 + 4; | |
f3d817d8 | 1248 | fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol, |
355afbcd KR |
1249 | fragP->fr_offset, 1, NO_RELOC); |
1250 | frag_wane (fragP); | |
fecd2382 | 1251 | } |
355afbcd KR |
1252 | break; |
1253 | ||
fecd2382 | 1254 | default: |
355afbcd | 1255 | break; |
fecd2382 | 1256 | } |
355afbcd | 1257 | return (fragP->fr_var + fragP->fr_fix - old_fr_fix); |
fecd2382 RP |
1258 | } /* md_estimate_size_before_relax() */ |
1259 | \f | |
1260 | /* | |
1261 | * md_convert_frag(); | |
1262 | * | |
1263 | * Called after relax() is finished. | |
1264 | * In: Address of frag. | |
1265 | * fr_type == rs_machine_dependent. | |
1266 | * fr_subtype is what the address relaxed to. | |
1267 | * | |
1268 | * Out: Any fixSs and constants are set up. | |
1269 | * Caller will turn frag into a ".space 0". | |
1270 | */ | |
1271 | void | |
355afbcd KR |
1272 | md_convert_frag (headers, fragP) |
1273 | object_headers *headers; | |
f3d817d8 | 1274 | fragS *fragP; |
355afbcd KR |
1275 | { |
1276 | char *addressP; /* -> _var to change. */ | |
1277 | char *opcodeP; /* -> opcode char(s) to change. */ | |
1278 | short int length_code; /* 2=long 1=word 0=byte */ | |
1279 | short int extension = 0; /* Size of relaxed address. */ | |
1280 | /* Added to fr_fix: incl. ALL var chars. */ | |
1281 | symbolS *symbolP; | |
1282 | long where; | |
1283 | long address_of_var; | |
1284 | /* Where, in file space, is _var of *fragP? */ | |
1285 | long target_address = 0; | |
1286 | /* Where, in file space, does addr point? */ | |
1287 | ||
1288 | know (fragP->fr_type == rs_machine_dependent); | |
1289 | length_code = fragP->fr_subtype & 3; /* depends on ENCODE_RELAX() */ | |
1290 | know (length_code >= 0 && length_code < 3); | |
1291 | where = fragP->fr_fix; | |
1292 | addressP = fragP->fr_literal + where; | |
1293 | opcodeP = fragP->fr_opcode; | |
1294 | symbolP = fragP->fr_symbol; | |
1295 | know (symbolP); | |
1296 | target_address = S_GET_VALUE (symbolP) + fragP->fr_offset; | |
1297 | address_of_var = fragP->fr_address + where; | |
1298 | ||
1299 | switch (fragP->fr_subtype) | |
fecd2382 | 1300 | { |
355afbcd | 1301 | |
fecd2382 | 1302 | case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE): |
355afbcd KR |
1303 | know (*addressP == 0 || *addressP == 0x10); /* '@' bit. */ |
1304 | addressP[0] |= 0xAF; /* Byte displacement. */ | |
1305 | addressP[1] = target_address - (address_of_var + 2); | |
1306 | extension = 2; | |
1307 | break; | |
1308 | ||
fecd2382 | 1309 | case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_WORD): |
355afbcd KR |
1310 | know (*addressP == 0 || *addressP == 0x10); /* '@' bit. */ |
1311 | addressP[0] |= 0xCF; /* Word displacement. */ | |
1312 | md_number_to_chars (addressP + 1, target_address - (address_of_var + 3), 2); | |
1313 | extension = 3; | |
1314 | break; | |
1315 | ||
fecd2382 | 1316 | case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_LONG): |
355afbcd KR |
1317 | know (*addressP == 0 || *addressP == 0x10); /* '@' bit. */ |
1318 | addressP[0] |= 0xEF; /* Long word displacement. */ | |
1319 | md_number_to_chars (addressP + 1, target_address - (address_of_var + 5), 4); | |
1320 | extension = 5; | |
1321 | break; | |
1322 | ||
fecd2382 | 1323 | case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE): |
355afbcd KR |
1324 | addressP[0] = target_address - (address_of_var + 1); |
1325 | extension = 1; | |
1326 | break; | |
1327 | ||
fecd2382 | 1328 | case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD): |
355afbcd KR |
1329 | opcodeP[0] ^= 1; /* Reverse sense of test. */ |
1330 | addressP[0] = 3; | |
1331 | addressP[1] = VAX_BRB + VAX_WIDEN_WORD; | |
1332 | md_number_to_chars (addressP + 2, target_address - (address_of_var + 4), 2); | |
1333 | extension = 4; | |
1334 | break; | |
1335 | ||
fecd2382 | 1336 | case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_LONG): |
355afbcd KR |
1337 | opcodeP[0] ^= 1; /* Reverse sense of test. */ |
1338 | addressP[0] = 6; | |
1339 | addressP[1] = VAX_JMP; | |
1340 | addressP[2] = VAX_PC_RELATIVE_MODE; | |
1341 | md_number_to_chars (addressP + 3, target_address, 4); | |
1342 | extension = 7; | |
1343 | break; | |
1344 | ||
fecd2382 | 1345 | case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE): |
355afbcd KR |
1346 | addressP[0] = target_address - (address_of_var + 1); |
1347 | extension = 1; | |
1348 | break; | |
1349 | ||
fecd2382 | 1350 | case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_WORD): |
355afbcd KR |
1351 | opcodeP[0] += VAX_WIDEN_WORD; /* brb -> brw, bsbb -> bsbw */ |
1352 | md_number_to_chars (addressP, target_address - (address_of_var + 2), 2); | |
1353 | extension = 2; | |
1354 | break; | |
1355 | ||
fecd2382 | 1356 | case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_LONG): |
355afbcd KR |
1357 | opcodeP[0] += VAX_WIDEN_LONG; /* brb -> jmp, bsbb -> jsb */ |
1358 | addressP[0] = VAX_PC_RELATIVE_MODE; | |
1359 | md_number_to_chars (addressP + 1, target_address - (address_of_var + 5), 4); | |
1360 | extension = 5; | |
1361 | break; | |
1362 | ||
fecd2382 | 1363 | case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD): |
355afbcd KR |
1364 | md_number_to_chars (addressP, target_address - (address_of_var + 2), 2); |
1365 | extension = 2; | |
1366 | break; | |
1367 | ||
fecd2382 | 1368 | case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_LONG): |
355afbcd KR |
1369 | addressP[0] = 2; |
1370 | addressP[1] = 0; | |
1371 | addressP[2] = VAX_BRB; | |
1372 | addressP[3] = 6; | |
1373 | addressP[4] = VAX_JMP; | |
1374 | addressP[5] = VAX_PC_RELATIVE_MODE; | |
1375 | md_number_to_chars (addressP + 6, target_address, 4); | |
1376 | extension = 10; | |
1377 | break; | |
1378 | ||
fecd2382 | 1379 | case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE): |
355afbcd KR |
1380 | addressP[0] = target_address - (address_of_var + 1); |
1381 | extension = 1; | |
1382 | break; | |
1383 | ||
fecd2382 | 1384 | case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_WORD): |
355afbcd KR |
1385 | addressP[0] = 2; |
1386 | addressP[1] = VAX_BRB; | |
1387 | addressP[2] = 3; | |
1388 | addressP[3] = VAX_BRW; | |
1389 | md_number_to_chars (addressP + 4, target_address - (address_of_var + 6), 2); | |
1390 | extension = 6; | |
1391 | break; | |
1392 | ||
fecd2382 | 1393 | case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_LONG): |
355afbcd KR |
1394 | addressP[0] = 2; |
1395 | addressP[1] = VAX_BRB; | |
1396 | addressP[2] = 6; | |
1397 | addressP[3] = VAX_JMP; | |
1398 | addressP[4] = VAX_PC_RELATIVE_MODE; | |
1399 | md_number_to_chars (addressP + 5, target_address, 4); | |
1400 | extension = 9; | |
1401 | break; | |
1402 | ||
fecd2382 | 1403 | default: |
355afbcd KR |
1404 | BAD_CASE (fragP->fr_subtype); |
1405 | break; | |
fecd2382 | 1406 | } |
355afbcd KR |
1407 | fragP->fr_fix += extension; |
1408 | } /* md_convert_frag() */ | |
fecd2382 RP |
1409 | |
1410 | /* Translate internal format of relocation info into target format. | |
355afbcd | 1411 | |
fecd2382 RP |
1412 | On vax: first 4 bytes are normal unsigned long, next three bytes |
1413 | are symbolnum, least sig. byte first. Last byte is broken up with | |
1414 | the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and | |
1415 | bit 0 as pcrel. */ | |
355afbcd KR |
1416 | #ifdef comment |
1417 | void | |
1418 | md_ri_to_chars (the_bytes, ri) | |
1419 | char *the_bytes; | |
1420 | struct reloc_info_generic ri; | |
1421 | { | |
1422 | /* this is easy */ | |
1423 | md_number_to_chars (the_bytes, ri.r_address, sizeof (ri.r_address)); | |
1424 | /* now the fun stuff */ | |
1425 | the_bytes[6] = (ri.r_symbolnum >> 16) & 0x0ff; | |
1426 | the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff; | |
1427 | the_bytes[4] = ri.r_symbolnum & 0x0ff; | |
1428 | the_bytes[7] = (((ri.r_extern << 3) & 0x08) | ((ri.r_length << 1) & 0x06) | | |
1429 | ((ri.r_pcrel << 0) & 0x01)) & 0x0F; | |
fecd2382 | 1430 | } |
355afbcd KR |
1431 | |
1432 | #endif /* comment */ | |
1433 | ||
1434 | void | |
1435 | tc_aout_fix_to_chars (where, fixP, segment_address_in_file) | |
1436 | char *where; | |
1437 | fixS *fixP; | |
1438 | relax_addressT segment_address_in_file; | |
1439 | { | |
1440 | /* | |
f3d817d8 DM |
1441 | * In: length of relocation (or of address) in chars: 1, 2 or 4. |
1442 | * Out: GNU LD relocation length code: 0, 1, or 2. | |
1443 | */ | |
355afbcd | 1444 | |
f3d817d8 | 1445 | static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2}; |
355afbcd KR |
1446 | long r_symbolnum; |
1447 | ||
1448 | know (fixP->fx_addsy != NULL); | |
1449 | ||
1450 | md_number_to_chars (where, | |
1451 | fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file, | |
1452 | 4); | |
1453 | ||
1454 | r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy) | |
1455 | ? S_GET_TYPE (fixP->fx_addsy) | |
1456 | : fixP->fx_addsy->sy_number); | |
1457 | ||
1458 | where[6] = (r_symbolnum >> 16) & 0x0ff; | |
1459 | where[5] = (r_symbolnum >> 8) & 0x0ff; | |
1460 | where[4] = r_symbolnum & 0x0ff; | |
1461 | where[7] = ((((!S_IS_DEFINED (fixP->fx_addsy)) << 3) & 0x08) | |
1462 | | ((nbytes_r_length[fixP->fx_size] << 1) & 0x06) | |
1463 | | (((fixP->fx_pcrel << 0) & 0x01) & 0x0f)); | |
f3d817d8 | 1464 | } |
355afbcd | 1465 | |
fecd2382 RP |
1466 | /* |
1467 | * BUGS, GRIPES, APOLOGIA, etc. | |
1468 | * | |
1469 | * The opcode table 'votstrs' needs to be sorted on opcode frequency. | |
1470 | * That is, AFTER we hash it with hash_...(), we want most-used opcodes | |
1471 | * to come out of the hash table faster. | |
1472 | * | |
f3d817d8 DM |
1473 | * I am sorry to inflict yet another VAX assembler on the world, but |
1474 | * RMS says we must do everything from scratch, to prevent pin-heads | |
1475 | * restricting this software. | |
fecd2382 RP |
1476 | */ |
1477 | ||
1478 | /* | |
1479 | * This is a vaguely modular set of routines in C to parse VAX | |
1480 | * assembly code using DEC mnemonics. It is NOT un*x specific. | |
1481 | * | |
1482 | * The idea here is that the assembler has taken care of all: | |
1483 | * labels | |
1484 | * macros | |
1485 | * listing | |
1486 | * pseudo-ops | |
1487 | * line continuation | |
1488 | * comments | |
1489 | * condensing any whitespace down to exactly one space | |
1490 | * and all we have to do is parse 1 line into a vax instruction | |
1491 | * partially formed. We will accept a line, and deliver: | |
1492 | * an error message (hopefully empty) | |
1493 | * a skeleton VAX instruction (tree structure) | |
1494 | * textual pointers to all the operand expressions | |
1495 | * a warning message that notes a silly operand (hopefully empty) | |
1496 | */ | |
1497 | \f | |
1498 | /* | |
1499 | * E D I T H I S T O R Y | |
1500 | * | |
1501 | * 17may86 Dean Elsner. Bug if line ends immediately after opcode. | |
1502 | * 30apr86 Dean Elsner. New vip_op() uses arg block so change call. | |
1503 | * 6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults(). | |
1504 | * 2jan86 Dean Elsner. Invent synthetic opcodes. | |
1505 | * Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC, | |
1506 | * which means this is not a real opcode, it is like a macro; it will | |
1507 | * be relax()ed into 1 or more instructions. | |
1508 | * Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised | |
1509 | * like a regular branch instruction. Option added to vip_begin(): | |
1510 | * exclude synthetic opcodes. Invent synthetic_votstrs[]. | |
1511 | * 31dec85 Dean Elsner. Invent vit_opcode_nbytes. | |
1512 | * Also make vit_opcode into a char[]. We now have n-byte vax opcodes, | |
1513 | * so caller's don't have to know the difference between a 1-byte & a | |
1514 | * 2-byte op-code. Still need vax_opcodeT concept, so we know how | |
1515 | * big an object must be to hold an op.code. | |
1516 | * 30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h" | |
1517 | * because vax opcodes may be 16 bits. Our crufty C compiler was | |
1518 | * happily initialising 8-bit vot_codes with 16-bit numbers! | |
1519 | * (Wouldn't the 'phone company like to compress data so easily!) | |
1520 | * 29dec85 Dean Elsner. New static table vax_operand_width_size[]. | |
1521 | * Invented so we know hw many bytes a "I^#42" needs in its immediate | |
1522 | * operand. Revised struct vop in "vax-inst.h": explicitly include | |
1523 | * byte length of each operand, and it's letter-code datum type. | |
1524 | * 17nov85 Dean Elsner. Name Change. | |
1525 | * Due to ar(1) truncating names, we learned the hard way that | |
1526 | * "vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off | |
1527 | * the archived object name. SO... we shortened the name of this | |
1528 | * source file, and changed the makefile. | |
1529 | */ | |
1530 | ||
f3d817d8 DM |
1531 | /* handle of the OPCODE hash table */ |
1532 | static struct hash_control *op_hash; | |
fecd2382 RP |
1533 | |
1534 | /* | |
1535 | * In: 1 character, from "bdfghloqpw" being the data-type of an operand | |
1536 | * of a vax instruction. | |
1537 | * | |
1538 | * Out: the length of an operand of that type, in bytes. | |
1539 | * Special branch operands types "-?!" have length 0. | |
1540 | */ | |
1541 | ||
1542 | static const short int vax_operand_width_size[256] = | |
1543 | { | |
355afbcd | 1544 | |
fecd2382 | 1545 | #define _ 0 |
355afbcd KR |
1546 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, |
1547 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1548 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1549 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1550 | _, _, 1, _, 8, _, 4, 8, 16, _, _, _, 4, _, _, 16, /* ..b.d.fgh...l..o */ | |
1551 | _, 8, _, _, _, _, _, 2, _, _, _, _, _, _, _, _, /* .q.....w........ */ | |
1552 | _, _, 1, _, 8, _, 4, 8, 16, _, _, _, 4, _, _, 16, /* ..b.d.fgh...l..o */ | |
1553 | _, 8, _, _, _, _, _, 2, _, _, _, _, _, _, _, _, /* .q.....w........ */ | |
1554 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1555 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1556 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1557 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1558 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1559 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1560 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, | |
1561 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _}; | |
fecd2382 RP |
1562 | #undef _ |
1563 | \f | |
1564 | /* | |
1565 | * This perversion encodes all the vax opcodes as a bunch of strings. | |
1566 | * RMS says we should build our hash-table at run-time. Hmm. | |
1567 | * Please would someone arrange these in decreasing frequency of opcode? | |
1568 | * Because of the way hash_...() works, the most frequently used opcode | |
1569 | * should be textually first and so on. | |
1570 | * | |
1571 | * Input for this table was 'vax.opcodes', awk(1)ed by 'vax.opcodes.c.awk' . | |
1572 | * So change 'vax.opcodes', then re-generate this table. | |
1573 | */ | |
1574 | ||
a39116f1 | 1575 | #include "opcode/vax.h" |
fecd2382 RP |
1576 | \f |
1577 | /* | |
1578 | * This is a table of optional op-codes. All of them represent | |
1579 | * 'synthetic' instructions that seem popular. | |
1580 | * | |
1581 | * Here we make some pseudo op-codes. Every code has a bit set to say | |
1582 | * it is synthetic. This lets you catch them if you want to | |
1583 | * ban these opcodes. They are mnemonics for "elastic" instructions | |
1584 | * that are supposed to assemble into the fewest bytes needed to do a | |
1585 | * branch, or to do a conditional branch, or whatever. | |
1586 | * | |
1587 | * The opcode is in the usual place [low-order n*8 bits]. This means | |
1588 | * that if you mask off the bucky bits, the usual rules apply about | |
1589 | * how long the opcode is. | |
1590 | * | |
1591 | * All VAX branch displacements come at the end of the instruction. | |
1592 | * For simple branches (1-byte opcode + 1-byte displacement) the last | |
1593 | * operand is coded 'b?' where the "data type" '?' is a clue that we | |
1594 | * may reverse the sense of the branch (complement lowest order bit) | |
1595 | * and branch around a jump. This is by far the most common case. | |
1596 | * That is why the VIT_OPCODE_SYNTHETIC bit is set: it says this is | |
1597 | * a 0-byte op-code followed by 2 or more bytes of operand address. | |
1598 | * | |
1599 | * If the op-code has VIT_OPCODE_SPECIAL set, then we have a more unusual | |
1600 | * case. | |
1601 | * | |
1602 | * For JBSB & JBR the treatment is the similar, except (1) we have a 'bw' | |
1603 | * option before (2) we can directly JSB/JMP because there is no condition. | |
1604 | * These operands have 'b-' as their access/data type. | |
1605 | * | |
1606 | * That leaves a bunch of random opcodes: JACBx, JxOBxxx. In these | |
1607 | * cases, we do the same idea. JACBxxx are all marked with a 'b!' | |
1608 | * JAOBxxx & JSOBxxx are marked with a 'b:'. | |
1609 | * | |
1610 | */ | |
1611 | #if (VIT_OPCODE_SYNTHETIC != 0x80000000) | |
1612 | You have just broken the encoding below, which assumes the sign bit | |
355afbcd | 1613 | means 'I am an imaginary instruction'. |
fecd2382 | 1614 | #endif |
355afbcd | 1615 | |
fecd2382 | 1616 | #if (VIT_OPCODE_SPECIAL != 0x40000000) |
355afbcd KR |
1617 | You have just broken the encoding below, which assumes the 0x40 M bit means |
1618 | 'I am not to be "optimised" the way normal branches are'. | |
fecd2382 | 1619 | #endif |
355afbcd KR |
1620 | |
1621 | static const struct vot | |
1622 | synthetic_votstrs[] = | |
1623 | { | |
1624 | {"jbsb", {"b-", 0xC0000010}}, /* BSD 4.2 */ | |
1625 | /* jsb used already */ | |
1626 | {"jbr", {"b-", 0xC0000011}}, /* BSD 4.2 */ | |
1627 | {"jr", {"b-", 0xC0000011}}, /* consistent */ | |
1628 | {"jneq", {"b?", 0x80000012}}, | |
1629 | {"jnequ", {"b?", 0x80000012}}, | |
1630 | {"jeql", {"b?", 0x80000013}}, | |
1631 | {"jeqlu", {"b?", 0x80000013}}, | |
1632 | {"jgtr", {"b?", 0x80000014}}, | |
1633 | {"jleq", {"b?", 0x80000015}}, | |
1634 | /* un-used opcodes here */ | |
1635 | {"jgeq", {"b?", 0x80000018}}, | |
1636 | {"jlss", {"b?", 0x80000019}}, | |
1637 | {"jgtru", {"b?", 0x8000001a}}, | |
1638 | {"jlequ", {"b?", 0x8000001b}}, | |
1639 | {"jvc", {"b?", 0x8000001c}}, | |
1640 | {"jvs", {"b?", 0x8000001d}}, | |
1641 | {"jgequ", {"b?", 0x8000001e}}, | |
1642 | {"jcc", {"b?", 0x8000001e}}, | |
1643 | {"jlssu", {"b?", 0x8000001f}}, | |
1644 | {"jcs", {"b?", 0x8000001f}}, | |
1645 | ||
1646 | {"jacbw", {"rwrwmwb!", 0xC000003d}}, | |
1647 | {"jacbf", {"rfrfmfb!", 0xC000004f}}, | |
1648 | {"jacbd", {"rdrdmdb!", 0xC000006f}}, | |
1649 | {"jacbb", {"rbrbmbb!", 0xC000009d}}, | |
1650 | {"jacbl", {"rlrlmlb!", 0xC00000f1}}, | |
1651 | {"jacbg", {"rgrgmgb!", 0xC0004ffd}}, | |
1652 | {"jacbh", {"rhrhmhb!", 0xC0006ffd}}, | |
1653 | ||
1654 | {"jbs", {"rlvbb?", 0x800000e0}}, | |
1655 | {"jbc", {"rlvbb?", 0x800000e1}}, | |
1656 | {"jbss", {"rlvbb?", 0x800000e2}}, | |
1657 | {"jbcs", {"rlvbb?", 0x800000e3}}, | |
1658 | {"jbsc", {"rlvbb?", 0x800000e4}}, | |
1659 | {"jbcc", {"rlvbb?", 0x800000e5}}, | |
1660 | {"jbssi", {"rlvbb?", 0x800000e6}}, | |
1661 | {"jbcci", {"rlvbb?", 0x800000e7}}, | |
f3d817d8 DM |
1662 | {"jlbs", {"rlb?", 0x800000e8}}, |
1663 | {"jlbc", {"rlb?", 0x800000e9}}, | |
355afbcd KR |
1664 | |
1665 | {"jaoblss", {"rlmlb:", 0xC00000f2}}, | |
1666 | {"jaobleq", {"rlmlb:", 0xC00000f3}}, | |
f3d817d8 DM |
1667 | {"jsobgeq", {"mlb:", 0xC00000f4}}, |
1668 | {"jsobgtr", {"mlb:", 0xC00000f5}}, | |
355afbcd KR |
1669 | |
1670 | /* CASEx has no branch addresses in our conception of it. */ | |
1671 | /* You should use ".word ..." statements after the "case ...". */ | |
1672 | ||
8e86815b | 1673 | {"", {"", 0}} /* empty is end sentinel */ |
fecd2382 RP |
1674 | |
1675 | }; /* synthetic_votstrs */ | |
1676 | \f | |
1677 | /* | |
1678 | * v i p _ b e g i n ( ) | |
1679 | * | |
1680 | * Call me once before you decode any lines. | |
1681 | * I decode votstrs into a hash table at op_hash (which I create). | |
f3d817d8 | 1682 | * I return an error text or null. |
fecd2382 RP |
1683 | * If you want, I will include the 'synthetic' jXXX instructions in the |
1684 | * instruction table. | |
1685 | * You must nominate metacharacters for eg DEC's "#", "@", "^". | |
1686 | */ | |
1687 | ||
f3d817d8 | 1688 | static const char * |
355afbcd KR |
1689 | vip_begin (synthetic_too, immediate, indirect, displen) |
1690 | int synthetic_too; /* 1 means include jXXX op-codes. */ | |
1691 | char *immediate, *indirect, *displen; | |
fecd2382 | 1692 | { |
355afbcd | 1693 | const struct vot *vP; /* scan votstrs */ |
f3d817d8 DM |
1694 | const char *retval = 0; /* error text */ |
1695 | ||
1696 | op_hash = hash_new (); | |
1697 | ||
1698 | for (vP = votstrs; *vP->vot_name && !retval; vP++) | |
1699 | retval = hash_insert (op_hash, vP->vot_name, (PTR) &vP->vot_detail); | |
1700 | ||
1701 | if (synthetic_too) | |
1702 | for (vP = synthetic_votstrs; *vP->vot_name && !retval; vP++) | |
1703 | retval = hash_insert (op_hash, vP->vot_name, (PTR) &vP->vot_detail); | |
355afbcd | 1704 | |
fecd2382 | 1705 | #ifndef CONST_TABLE |
355afbcd | 1706 | vip_op_defaults (immediate, indirect, displen); |
fecd2382 | 1707 | #endif |
355afbcd | 1708 | |
f3d817d8 | 1709 | return retval; |
fecd2382 RP |
1710 | } |
1711 | ||
1712 | ||
fecd2382 RP |
1713 | /* |
1714 | * v i p ( ) | |
1715 | * | |
1716 | * This converts a string into a vax instruction. | |
1717 | * The string must be a bare single instruction in dec-vax (with BSD4 frobs) | |
1718 | * format. | |
1719 | * It provides some error messages: at most one fatal error message (which | |
1720 | * stops the scan) and at most one warning message for each operand. | |
1721 | * The vax instruction is returned in exploded form, since we have no | |
1722 | * knowledge of how you parse (or evaluate) your expressions. | |
1723 | * We do however strip off and decode addressing modes and operation | |
1724 | * mnemonic. | |
1725 | * | |
1726 | * The exploded instruction is returned to a struct vit of your choice. | |
1727 | * #include "vax-inst.h" to know what a struct vit is. | |
1728 | * | |
1729 | * This function's value is a string. If it is not "" then an internal | |
1730 | * logic error was found: read this code to assign meaning to the string. | |
1731 | * No argument string should generate such an error string: | |
1732 | * it means a bug in our code, not in the user's text. | |
1733 | * | |
f3d817d8 | 1734 | * You MUST have called vip_begin() once before using this function. |
fecd2382 RP |
1735 | */ |
1736 | ||
f3d817d8 | 1737 | static void |
355afbcd KR |
1738 | vip (vitP, instring) |
1739 | struct vit *vitP; /* We build an exploded instruction here. */ | |
1740 | char *instring; /* Text of a vax instruction: we modify. */ | |
1741 | { | |
f3d817d8 DM |
1742 | /* How to bit-encode this opcode. */ |
1743 | struct vot_wot *vwP; | |
1744 | /* 1/skip whitespace.2/scan vot_how */ | |
1745 | char *p; | |
1746 | char *q; | |
1747 | /* counts number of operands seen */ | |
1748 | unsigned char count; | |
1749 | /* scan operands in struct vit */ | |
1750 | struct vop *operandp; | |
1751 | /* error over all operands */ | |
1752 | char *alloperr; | |
1753 | /* Remember char, (we clobber it with '\0' temporarily). */ | |
1754 | char c; | |
1755 | /* Op-code of this instruction. */ | |
1756 | vax_opcodeT oc; | |
1757 | ||
355afbcd KR |
1758 | if (*instring == ' ') |
1759 | ++instring; /* Skip leading whitespace. */ | |
1760 | for (p = instring; *p && *p != ' '; p++);; /* MUST end in end-of-string or exactly 1 space. */ | |
1761 | /* Scanned up to end of operation-code. */ | |
1762 | /* Operation-code is ended with whitespace. */ | |
1763 | if (p - instring == 0) | |
fecd2382 | 1764 | { |
355afbcd KR |
1765 | vitP->vit_error = "No operator"; |
1766 | count = 0; | |
1767 | memset (vitP->vit_opcode, '\0', sizeof (vitP->vit_opcode)); | |
fecd2382 | 1768 | } |
355afbcd | 1769 | else |
fecd2382 | 1770 | { |
355afbcd KR |
1771 | c = *p; |
1772 | *p = '\0'; | |
1773 | /* | |
9a75dc1f ILT |
1774 | * Here with instring pointing to what better be an op-name, and p |
1775 | * pointing to character just past that. | |
1776 | * We trust instring points to an op-name, with no whitespace. | |
1777 | */ | |
355afbcd KR |
1778 | vwP = (struct vot_wot *) hash_find (op_hash, instring); |
1779 | *p = c; /* Restore char after op-code. */ | |
1780 | if (vwP == 0) | |
fecd2382 | 1781 | { |
355afbcd KR |
1782 | vitP->vit_error = "Unknown operator"; |
1783 | count = 0; | |
1784 | memset (vitP->vit_opcode, '\0', sizeof (vitP->vit_opcode)); | |
fecd2382 | 1785 | } |
355afbcd | 1786 | else |
fecd2382 | 1787 | { |
355afbcd | 1788 | /* |
9a75dc1f ILT |
1789 | * We found a match! So lets pick up as many operands as the |
1790 | * instruction wants, and even gripe if there are too many. | |
1791 | * We expect comma to seperate each operand. | |
1792 | * We let instring track the text, while p tracks a part of the | |
1793 | * struct vot. | |
1794 | */ | |
355afbcd | 1795 | /* |
9a75dc1f ILT |
1796 | * The lines below know about 2-byte opcodes starting FD,FE or FF. |
1797 | * They also understand synthetic opcodes. Note: | |
1798 | * we return 32 bits of opcode, including bucky bits, BUT | |
1799 | * an opcode length is either 8 or 16 bits for vit_opcode_nbytes. | |
1800 | */ | |
355afbcd KR |
1801 | oc = vwP->vot_code; /* The op-code. */ |
1802 | vitP->vit_opcode_nbytes = (oc & 0xFF) >= 0xFD ? 2 : 1; | |
1803 | md_number_to_chars (vitP->vit_opcode, oc, 4); | |
1804 | count = 0; /* no operands seen yet */ | |
1805 | instring = p; /* point just past operation code */ | |
1806 | alloperr = ""; | |
1807 | for (p = vwP->vot_how, operandp = vitP->vit_operand; | |
f3d817d8 DM |
1808 | !(alloperr && *alloperr) && *p; |
1809 | operandp++, p += 2) | |
fecd2382 | 1810 | { |
355afbcd | 1811 | /* |
9a75dc1f ILT |
1812 | * Here to parse one operand. Leave instring pointing just |
1813 | * past any one ',' that marks the end of this operand. | |
1814 | */ | |
355afbcd | 1815 | if (!p[1]) |
f3d817d8 | 1816 | as_fatal ("odd number of bytes in operand description"); |
355afbcd | 1817 | else if (*instring) |
fecd2382 | 1818 | { |
355afbcd KR |
1819 | for (q = instring; (c = *q) && c != ','; q++) |
1820 | ; | |
1821 | /* | |
9a75dc1f ILT |
1822 | * Q points to ',' or '\0' that ends argument. C is that |
1823 | * character. | |
1824 | */ | |
355afbcd KR |
1825 | *q = 0; |
1826 | operandp->vop_width = p[1]; | |
8e86815b | 1827 | operandp->vop_nbytes = vax_operand_width_size[(unsigned) p[1]]; |
355afbcd | 1828 | operandp->vop_access = p[0]; |
f3d817d8 | 1829 | vip_op (instring, operandp); |
355afbcd | 1830 | *q = c; /* Restore input text. */ |
f3d817d8 | 1831 | if (operandp->vop_error) |
355afbcd KR |
1832 | alloperr = "Bad operand"; |
1833 | instring = q + (c ? 1 : 0); /* next operand (if any) */ | |
1834 | count++; /* won another argument, may have an operr */ | |
fecd2382 | 1835 | } |
355afbcd KR |
1836 | else |
1837 | alloperr = "Not enough operands"; | |
fecd2382 | 1838 | } |
355afbcd | 1839 | if (!*alloperr) |
fecd2382 | 1840 | { |
355afbcd KR |
1841 | if (*instring == ' ') |
1842 | instring++; /* Skip whitespace. */ | |
1843 | if (*instring) | |
1844 | alloperr = "Too many operands"; | |
fecd2382 | 1845 | } |
355afbcd | 1846 | vitP->vit_error = alloperr; |
fecd2382 RP |
1847 | } |
1848 | } | |
355afbcd | 1849 | vitP->vit_operands = count; |
fecd2382 RP |
1850 | } |
1851 | \f | |
1852 | #ifdef test | |
1853 | ||
1854 | /* | |
1855 | * Test program for above. | |
1856 | */ | |
1857 | ||
1858 | struct vit myvit; /* build an exploded vax instruction here */ | |
1859 | char answer[100]; /* human types a line of vax assembler here */ | |
1860 | char *mybug; /* "" or an internal logic diagnostic */ | |
1861 | int mycount; /* number of operands */ | |
1862 | struct vop *myvop; /* scan operands from myvit */ | |
355afbcd | 1863 | int mysynth; /* 1 means want synthetic opcodes. */ |
fecd2382 RP |
1864 | char my_immediate[200]; |
1865 | char my_indirect[200]; | |
1866 | char my_displen[200]; | |
1867 | ||
fecd2382 RP |
1868 | main () |
1869 | { | |
355afbcd | 1870 | char *p; |
355afbcd KR |
1871 | |
1872 | printf ("0 means no synthetic instructions. "); | |
1873 | printf ("Value for vip_begin? "); | |
1874 | gets (answer); | |
1875 | sscanf (answer, "%d", &mysynth); | |
1876 | printf ("Synthetic opcodes %s be included.\n", mysynth ? "will" : "will not"); | |
1877 | printf ("enter immediate symbols eg enter # "); | |
1878 | gets (my_immediate); | |
1879 | printf ("enter indirect symbols eg enter @ "); | |
1880 | gets (my_indirect); | |
1881 | printf ("enter displen symbols eg enter ^ "); | |
1882 | gets (my_displen); | |
f3d817d8 | 1883 | if (p = vip_begin (mysynth, my_immediate, my_indirect, my_displen)) |
fecd2382 | 1884 | { |
355afbcd | 1885 | error ("vip_begin=%s", p); |
fecd2382 | 1886 | } |
355afbcd KR |
1887 | printf ("An empty input line will quit you from the vax instruction parser\n"); |
1888 | for (;;) | |
fecd2382 | 1889 | { |
355afbcd KR |
1890 | printf ("vax instruction: "); |
1891 | fflush (stdout); | |
1892 | gets (answer); | |
1893 | if (!*answer) | |
fecd2382 | 1894 | { |
355afbcd | 1895 | break; /* out of for each input text loop */ |
fecd2382 | 1896 | } |
f3d817d8 | 1897 | vip (&myvit, answer); |
355afbcd | 1898 | if (*myvit.vit_error) |
fecd2382 | 1899 | { |
355afbcd | 1900 | printf ("ERR:\"%s\"\n", myvit.vit_error); |
fecd2382 | 1901 | } |
355afbcd KR |
1902 | printf ("opcode="); |
1903 | for (mycount = myvit.vit_opcode_nbytes, p = myvit.vit_opcode; | |
1904 | mycount; | |
1905 | mycount--, p++ | |
1906 | ) | |
fecd2382 | 1907 | { |
355afbcd | 1908 | printf ("%02x ", *p & 0xFF); |
fecd2382 | 1909 | } |
355afbcd KR |
1910 | printf (" operand count=%d.\n", mycount = myvit.vit_operands); |
1911 | for (myvop = myvit.vit_operand; mycount; mycount--, myvop++) | |
fecd2382 | 1912 | { |
355afbcd KR |
1913 | printf ("mode=%xx reg=%xx ndx=%xx len='%c'=%c%c%d. expr=\"", |
1914 | myvop->vop_mode, myvop->vop_reg, myvop->vop_ndx, | |
1915 | myvop->vop_short, myvop->vop_access, myvop->vop_width, | |
1916 | myvop->vop_nbytes); | |
1917 | for (p = myvop->vop_expr_begin; p <= myvop->vop_expr_end; p++) | |
fecd2382 | 1918 | { |
355afbcd | 1919 | putchar (*p); |
fecd2382 | 1920 | } |
355afbcd | 1921 | printf ("\"\n"); |
f3d817d8 | 1922 | if (myvop->vop_error) |
fecd2382 | 1923 | { |
355afbcd | 1924 | printf (" err:\"%s\"\n", myvop->vop_error); |
fecd2382 | 1925 | } |
f3d817d8 | 1926 | if (myvop->vop_warn) |
fecd2382 | 1927 | { |
355afbcd | 1928 | printf (" wrn:\"%s\"\n", myvop->vop_warn); |
fecd2382 RP |
1929 | } |
1930 | } | |
1931 | } | |
355afbcd | 1932 | vip_end (); |
460531da | 1933 | exit (EXIT_SUCCESS); |
fecd2382 RP |
1934 | } |
1935 | ||
1936 | #endif /* #ifdef test */ | |
1937 | ||
1938 | /* end of vax_ins_parse.c */ | |
1939 | ||
fecd2382 RP |
1940 | /* vax_reg_parse.c - convert a VAX register name to a number */ |
1941 | ||
1942 | /* Copyright (C) 1987 Free Software Foundation, Inc. A part of GNU. */ | |
1943 | ||
1944 | /* | |
1945 | * v a x _ r e g _ p a r s e ( ) | |
1946 | * | |
1947 | * Take 3 char.s, the last of which may be `\0` (non-existent) | |
1948 | * and return the VAX register number that they represent. | |
1949 | * | |
1950 | * Return -1 if they don't form a register name. Good names return | |
1951 | * a number from 0:15 inclusive. | |
1952 | * | |
1953 | * Case is not important in a name. | |
1954 | * | |
1955 | * Register names understood are: | |
1956 | * | |
1957 | * R0 | |
1958 | * R1 | |
1959 | * R2 | |
1960 | * R3 | |
1961 | * R4 | |
1962 | * R5 | |
1963 | * R6 | |
1964 | * R7 | |
1965 | * R8 | |
1966 | * R9 | |
1967 | * R10 | |
1968 | * R11 | |
1969 | * R12 AP | |
1970 | * R13 FP | |
1971 | * R14 SP | |
1972 | * R15 PC | |
1973 | * | |
1974 | */ | |
1975 | ||
1976 | #include <ctype.h> | |
1977 | #define AP (12) | |
1978 | #define FP (13) | |
1979 | #define SP (14) | |
1980 | #define PC (15) | |
1981 | \f | |
1982 | int /* return -1 or 0:15 */ | |
355afbcd KR |
1983 | vax_reg_parse (c1, c2, c3) /* 3 chars of register name */ |
1984 | char c1, c2, c3; /* c3 == 0 if 2-character reg name */ | |
fecd2382 | 1985 | { |
f3d817d8 | 1986 | int retval; /* return -1:15 */ |
355afbcd KR |
1987 | |
1988 | retval = -1; | |
1989 | ||
1990 | if (isupper (c1)) | |
1991 | c1 = tolower (c1); | |
1992 | if (isupper (c2)) | |
1993 | c2 = tolower (c2); | |
1994 | if (isdigit (c2) && c1 == 'r') | |
fecd2382 | 1995 | { |
355afbcd KR |
1996 | retval = c2 - '0'; |
1997 | if (isdigit (c3)) | |
fecd2382 | 1998 | { |
355afbcd KR |
1999 | retval = retval * 10 + c3 - '0'; |
2000 | retval = (retval > 15) ? -1 : retval; | |
2001 | /* clamp the register value to 1 hex digit */ | |
fecd2382 | 2002 | } |
355afbcd KR |
2003 | else if (c3) |
2004 | retval = -1; /* c3 must be '\0' or a digit */ | |
fecd2382 | 2005 | } |
355afbcd KR |
2006 | else if (c3) /* There are no three letter regs */ |
2007 | retval = -1; | |
2008 | else if (c2 == 'p') | |
fecd2382 | 2009 | { |
355afbcd | 2010 | switch (c1) |
fecd2382 RP |
2011 | { |
2012 | case 's': | |
355afbcd KR |
2013 | retval = SP; |
2014 | break; | |
fecd2382 | 2015 | case 'f': |
355afbcd KR |
2016 | retval = FP; |
2017 | break; | |
fecd2382 | 2018 | case 'a': |
355afbcd KR |
2019 | retval = AP; |
2020 | break; | |
fecd2382 | 2021 | default: |
355afbcd | 2022 | retval = -1; |
fecd2382 RP |
2023 | } |
2024 | } | |
355afbcd KR |
2025 | else if (c1 == 'p' && c2 == 'c') |
2026 | retval = PC; | |
2027 | else | |
2028 | retval = -1; | |
2029 | return (retval); | |
fecd2382 RP |
2030 | } |
2031 | ||
2032 | /* | |
2033 | * v i p _ o p ( ) | |
2034 | * | |
2035 | * Parse a vax operand in DEC assembler notation. | |
2036 | * For speed, expect a string of whitespace to be reduced to a single ' '. | |
2037 | * This is the case for GNU AS, and is easy for other DEC-compatible | |
2038 | * assemblers. | |
2039 | * | |
2040 | * Knowledge about DEC VAX assembler operand notation lives here. | |
2041 | * This doesn't even know what a register name is, except it believes | |
2042 | * all register names are 2 or 3 characters, and lets vax_reg_parse() say | |
2043 | * what number each name represents. | |
2044 | * It does, however, know that PC, SP etc are special registers so it can | |
2045 | * detect addressing modes that are silly for those registers. | |
2046 | * | |
2047 | * Where possible, it delivers 1 fatal or 1 warning message if the operand | |
2048 | * is suspect. Exactly what we test for is still evolving. | |
2049 | */ | |
2050 | ||
2051 | /* | |
2052 | * B u g s | |
2053 | * | |
2054 | * Arg block. | |
2055 | * | |
2056 | * There were a number of 'mismatched argument type' bugs to vip_op. | |
2057 | * The most general solution is to typedef each (of many) arguments. | |
2058 | * We used instead a typedef'd argument block. This is less modular | |
2059 | * than using seperate return pointers for each result, but runs faster | |
2060 | * on most engines, and seems to keep programmers happy. It will have | |
2061 | * to be done properly if we ever want to use vip_op as a general-purpose | |
2062 | * module (it was designed to be). | |
2063 | * | |
2064 | * G^ | |
2065 | * | |
2066 | * Doesn't support DEC "G^" format operands. These always take 5 bytes | |
2067 | * to express, and code as modes 8F or 9F. Reason: "G^" deprives you of | |
2068 | * optimising to (say) a "B^" if you are lucky in the way you link. | |
2069 | * When someone builds a linker smart enough to convert "G^" to "B^", "W^" | |
2070 | * whenever possible, then we should implement it. | |
2071 | * If there is some other use for "G^", feel free to code it in! | |
2072 | * | |
2073 | * | |
2074 | * speed | |
2075 | * | |
2076 | * If I nested if()s more, I could avoid testing (*err) which would save | |
2077 | * time, space and page faults. I didn't nest all those if()s for clarity | |
2078 | * and because I think the mode testing can be re-arranged 1st to test the | |
2079 | * commoner constructs 1st. Does anybody have statistics on this? | |
2080 | * | |
2081 | * | |
2082 | * | |
2083 | * error messages | |
2084 | * | |
2085 | * In future, we should be able to 'compose' error messages in a scratch area | |
2086 | * and give the user MUCH more informative error messages. Although this takes | |
2087 | * a little more code at run-time, it will make this module much more self- | |
2088 | * documenting. As an example of what sucks now: most error messages have | |
2089 | * hardwired into them the DEC VAX metacharacters "#^@" which are nothing like | |
2090 | * the Un*x characters "$`*", that most users will expect from this AS. | |
2091 | */ | |
2092 | \f | |
2093 | /* | |
2094 | * The input is a string, ending with '\0'. | |
2095 | * | |
2096 | * We also require a 'hint' of what kind of operand is expected: so | |
2097 | * we can remind caller not to write into literals for instance. | |
2098 | * | |
2099 | * The output is a skeletal instruction. | |
2100 | * | |
2101 | * The algorithm has two parts. | |
2102 | * 1. extract the syntactic features (parse off all the @^#-()+[] mode crud); | |
2103 | * 2. express the @^#-()+[] as some parameters suited to further analysis. | |
2104 | * | |
2105 | * 2nd step is where we detect the googles of possible invalid combinations | |
2106 | * a human (or compiler) might write. Note that if we do a half-way | |
2107 | * decent assembler, we don't know how long to make (eg) displacement | |
2108 | * fields when we first meet them (because they may not have defined values). | |
2109 | * So we must wait until we know how many bits are needed for each address, | |
2110 | * then we can know both length and opcodes of instructions. | |
2111 | * For reason(s) above, we will pass to our caller a 'broken' instruction | |
2112 | * of these major components, from which our caller can generate instructions: | |
2113 | * - displacement length I^ S^ L^ B^ W^ unspecified | |
2114 | * - mode (many) | |
2115 | * - register R0-R15 or absent | |
2116 | * - index register R0-R15 or absent | |
2117 | * - expression text what we don't parse | |
2118 | * - error text(s) why we couldn't understand the operand | |
2119 | */ | |
2120 | ||
2121 | /* | |
2122 | * To decode output of this, test errtxt. If errtxt[0] == '\0', then | |
2123 | * we had no errors that prevented parsing. Also, if we ever report | |
2124 | * an internal bug, errtxt[0] is set non-zero. So one test tells you | |
2125 | * if the other outputs are to be taken seriously. | |
2126 | */ | |
2127 | ||
2128 | ||
fecd2382 RP |
2129 | /* |
2130 | * Because this module is useful for both VMS and UN*X style assemblers | |
2131 | * and because of the variety of UN*X assemblers we must recognise | |
2132 | * the different conventions for assembler operand notation. For example | |
2133 | * VMS says "#42" for immediate mode, while most UN*X say "$42". | |
2134 | * We permit arbitrary sets of (single) characters to represent the | |
2135 | * 3 concepts that DEC writes '#', '@', '^'. | |
2136 | */ | |
2137 | ||
a39116f1 | 2138 | /* character tests */ |
355afbcd KR |
2139 | #define VIP_IMMEDIATE 01 /* Character is like DEC # */ |
2140 | #define VIP_INDIRECT 02 /* Char is like DEC @ */ | |
2141 | #define VIP_DISPLEN 04 /* Char is like DEC ^ */ | |
fecd2382 RP |
2142 | |
2143 | #define IMMEDIATEP(c) (vip_metacharacters [(c)&0xff]&VIP_IMMEDIATE) | |
2144 | #define INDIRECTP(c) (vip_metacharacters [(c)&0xff]&VIP_INDIRECT) | |
2145 | #define DISPLENP(c) (vip_metacharacters [(c)&0xff]&VIP_DISPLEN) | |
2146 | ||
2147 | /* We assume 8 bits per byte. Use vip_op_defaults() to set these up BEFORE we | |
2148 | * are ever called. | |
2149 | */ | |
2150 | ||
2151 | #if defined(CONST_TABLE) | |
2152 | #define _ 0, | |
2153 | #define I VIP_IMMEDIATE, | |
2154 | #define S VIP_INDIRECT, | |
2155 | #define D VIP_DISPLEN, | |
2156 | static const char | |
f3d817d8 | 2157 | vip_metacharacters[256] = |
355afbcd KR |
2158 | { |
2159 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /* ^@ ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O*/ | |
2160 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /* ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */ | |
2161 | _ _ _ _ I _ _ _ _ _ S _ _ _ _ _ /* sp ! " # $ % & ' ( ) * + , - . / */ | |
2162 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /*0 1 2 3 4 5 6 7 8 9 : ; < = > ?*/ | |
2163 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /*@ A B C D E F G H I J K L M N O*/ | |
2164 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /*P Q R S T U V W X Y Z [ \ ] ^ _*/ | |
2165 | D _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /*` a b c d e f g h i j k l m n o*/ | |
2166 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ /*p q r s t u v w x y z { | } ~ ^?*/ | |
2167 | ||
2168 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2169 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2170 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2171 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2172 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2173 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2174 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2175 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ | |
2176 | }; | |
fecd2382 RP |
2177 | #undef _ |
2178 | #undef I | |
2179 | #undef S | |
2180 | #undef D | |
2181 | #else | |
2182 | static char vip_metacharacters[256]; | |
2183 | ||
355afbcd KR |
2184 | static void |
2185 | vip_op_1 (bit, syms) | |
2186 | int bit; | |
2187 | char *syms; | |
fecd2382 | 2188 | { |
355afbcd KR |
2189 | unsigned char t; |
2190 | ||
8e86815b | 2191 | while ((t = *syms++) != 0) |
355afbcd | 2192 | vip_metacharacters[t] |= bit; |
fecd2382 | 2193 | } |
355afbcd | 2194 | |
f3d817d8 | 2195 | /* Can be called any time. More arguments may appear in future. */ |
355afbcd | 2196 | static void |
f3d817d8 DM |
2197 | vip_op_defaults (immediate, indirect, displen) |
2198 | char *immediate; | |
355afbcd | 2199 | char *indirect; |
f3d817d8 | 2200 | char *displen; |
fecd2382 | 2201 | { |
355afbcd KR |
2202 | vip_op_1 (VIP_IMMEDIATE, immediate); |
2203 | vip_op_1 (VIP_INDIRECT, indirect); | |
2204 | vip_op_1 (VIP_DISPLEN, displen); | |
fecd2382 | 2205 | } |
fecd2382 | 2206 | |
355afbcd | 2207 | #endif |
fecd2382 | 2208 | \f |
355afbcd | 2209 | |
fecd2382 RP |
2210 | /* |
2211 | * Dec defines the semantics of address modes (and values) | |
2212 | * by a two-letter code, explained here. | |
2213 | * | |
2214 | * letter 1: access type | |
2215 | * | |
2216 | * a address calculation - no data access, registers forbidden | |
2217 | * b branch displacement | |
2218 | * m read - let go of bus - write back "modify" | |
2219 | * r read | |
2220 | * v bit field address: like 'a' but registers are OK | |
2221 | * w write | |
2222 | * space no operator (eg ".long foo") [our convention] | |
2223 | * | |
2224 | * letter 2: data type (i.e. width, alignment) | |
2225 | * | |
2226 | * b byte | |
2227 | * d double precision floating point (D format) | |
2228 | * f single precision floating point (F format) | |
2229 | * g G format floating | |
2230 | * h H format floating | |
2231 | * l longword | |
2232 | * o octaword | |
2233 | * q quadword | |
2234 | * w word | |
2235 | * ? simple synthetic branch operand | |
2236 | * - unconditional synthetic JSB/JSR operand | |
2237 | * ! complex synthetic branch operand | |
2238 | * | |
2239 | * The '-?!' letter 2's are not for external consumption. They are used | |
2240 | * for various assemblers. Generally, all unknown widths are assumed 0. | |
2241 | * We don't limit your choice of width character. | |
2242 | * | |
2243 | * DEC operands are hard work to parse. For example, '@' as the first | |
2244 | * character means indirect (deferred) mode but elswhere it is a shift | |
2245 | * operator. | |
2246 | * The long-winded explanation of how this is supposed to work is | |
2247 | * cancelled. Read a DEC vax manual. | |
2248 | * We try hard not to parse anything that MIGHT be part of the expression | |
2249 | * buried in that syntax. For example if we see @...(Rn) we don't check | |
2250 | * for '-' before the '(' because mode @-(Rn) does not exist. | |
2251 | * | |
2252 | * After parsing we have: | |
2253 | * | |
355afbcd | 2254 | * at 1 if leading '@' (or Un*x '*') |
fecd2382 | 2255 | * len takes one value from " bilsw". eg B^ -> 'b'. |
355afbcd | 2256 | * hash 1 if leading '#' (or Un*x '$') |
fecd2382 RP |
2257 | * expr_begin, expr_end the expression we did not parse |
2258 | * even though we don't interpret it, we make use | |
2259 | * of its presence or absence. | |
2260 | * sign -1: -(Rn) 0: absent +1: (Rn)+ | |
355afbcd | 2261 | * paren 1 if () are around register |
fecd2382 RP |
2262 | * reg major register number 0:15 -1 means absent |
2263 | * ndx index register number 0:15 -1 means absent | |
2264 | * | |
2265 | * Again, I dare not explain it: just trace ALL the code! | |
2266 | */ | |
2267 | \f | |
f3d817d8 | 2268 | static void |
355afbcd | 2269 | vip_op (optext, vopP) |
9a75dc1f ILT |
2270 | /* user's input string e.g.: "@B^foo@bar(AP)[FP]:" */ |
2271 | char *optext; | |
2272 | /* Input fields: vop_access, vop_width. | |
2273 | Output fields: _ndx, _reg, _mode, _short, _warn, | |
2274 | _error _expr_begin, _expr_end, _nbytes. | |
2275 | vop_nbytes : number of bytes in a datum. */ | |
2276 | struct vop *vopP; | |
355afbcd | 2277 | { |
f3d817d8 DM |
2278 | /* track operand text forward */ |
2279 | char *p; | |
2280 | /* track operand text backward */ | |
2281 | char *q; | |
2282 | /* 1 if leading '@' ('*') seen */ | |
2283 | int at; | |
2284 | /* one of " bilsw" */ | |
2285 | char len; | |
2286 | /* 1 if leading '#' ('$') seen */ | |
2287 | int hash; | |
2288 | /* -1, 0 or +1 */ | |
2289 | int sign = 0; | |
2290 | /* 1 if () surround register */ | |
2291 | int paren = 0; | |
2292 | /* register number, -1:absent */ | |
2293 | int reg = 0; | |
2294 | /* index register number -1:absent */ | |
2295 | int ndx = 0; | |
2296 | /* report illegal operand, ""==OK */ | |
355afbcd KR |
2297 | /* " " is a FAKE error: means we won */ |
2298 | /* ANY err that begins with ' ' is a fake. */ | |
2299 | /* " " is converted to "" before return */ | |
f3d817d8 DM |
2300 | char *err; |
2301 | /* warn about weird modes pf address */ | |
2302 | char *wrn; | |
2303 | /* preserve q in case we backup */ | |
2304 | char *oldq = NULL; | |
2305 | /* build up 4-bit operand mode here */ | |
355afbcd KR |
2306 | /* note: index mode is in ndx, this is */ |
2307 | /* the major mode of operand address */ | |
f3d817d8 | 2308 | int mode = 0; |
355afbcd | 2309 | /* |
f3d817d8 DM |
2310 | * Notice how we move wrong-arg-type bugs INSIDE this module: if we |
2311 | * get the types wrong below, we lose at compile time rather than at | |
2312 | * lint or run time. | |
2313 | */ | |
355afbcd KR |
2314 | char access; /* vop_access. */ |
2315 | char width; /* vop_width. */ | |
2316 | ||
355afbcd KR |
2317 | access = vopP->vop_access; |
2318 | width = vopP->vop_width; | |
f3d817d8 DM |
2319 | /* None of our code bugs (yet), no user text errors, no warnings |
2320 | even. */ | |
2321 | err = wrn = 0; | |
355afbcd KR |
2322 | |
2323 | p = optext; | |
2324 | ||
2325 | if (*p == ' ') /* Expect all whitespace reduced to ' '. */ | |
2326 | p++; /* skip over whitespace */ | |
2327 | ||
8e86815b | 2328 | if ((at = INDIRECTP (*p)) != 0) |
355afbcd KR |
2329 | { /* 1 if *p=='@'(or '*' for Un*x) */ |
2330 | p++; /* at is determined */ | |
2331 | if (*p == ' ') /* Expect all whitespace reduced to ' '. */ | |
fecd2382 RP |
2332 | p++; /* skip over whitespace */ |
2333 | } | |
355afbcd KR |
2334 | |
2335 | /* | |
f3d817d8 DM |
2336 | * This code is subtle. It tries to detect all legal (letter)'^' |
2337 | * but it doesn't waste time explicitly testing for premature '\0' because | |
2338 | * this case is rejected as a mismatch against either (letter) or '^'. | |
2339 | */ | |
355afbcd | 2340 | { |
f3d817d8 | 2341 | char c; |
355afbcd | 2342 | |
fecd2382 RP |
2343 | c = *p; |
2344 | if (isupper (c)) | |
355afbcd | 2345 | c = tolower (c); |
fecd2382 | 2346 | if (DISPLENP (p[1]) && strchr ("bilws", len = c)) |
355afbcd | 2347 | p += 2; /* skip (letter) '^' */ |
fecd2382 | 2348 | else /* no (letter) '^' seen */ |
355afbcd KR |
2349 | len = ' '; /* len is determined */ |
2350 | } | |
fecd2382 | 2351 | |
355afbcd | 2352 | if (*p == ' ') /* Expect all whitespace reduced to ' '. */ |
fecd2382 | 2353 | p++; /* skip over whitespace */ |
355afbcd | 2354 | |
8e86815b | 2355 | if ((hash = IMMEDIATEP (*p)) != 0) /* 1 if *p=='#' ('$' for Un*x) */ |
fecd2382 | 2356 | p++; /* hash is determined */ |
355afbcd KR |
2357 | |
2358 | /* | |
f3d817d8 DM |
2359 | * p points to what may be the beginning of an expression. |
2360 | * We have peeled off the front all that is peelable. | |
2361 | * We know at, len, hash. | |
2362 | * | |
2363 | * Lets point q at the end of the text and parse that (backwards). | |
2364 | */ | |
355afbcd KR |
2365 | |
2366 | for (q = p; *q; q++) | |
fecd2382 | 2367 | ; |
355afbcd KR |
2368 | q--; /* now q points at last char of text */ |
2369 | \f | |
2370 | if (*q == ' ' && q >= p) /* Expect all whitespace reduced to ' '. */ | |
fecd2382 | 2371 | q--; |
355afbcd KR |
2372 | /* reverse over whitespace, but don't */ |
2373 | /* run back over *p */ | |
2374 | ||
2375 | /* | |
f3d817d8 DM |
2376 | * As a matter of policy here, we look for [Rn], although both Rn and S^# |
2377 | * forbid [Rn]. This is because it is easy, and because only a sick | |
2378 | * cyborg would have [...] trailing an expression in a VAX-like assembler. | |
2379 | * A meticulous parser would first check for Rn followed by '(' or '[' | |
2380 | * and not parse a trailing ']' if it found another. We just ban expressions | |
2381 | * ending in ']'. | |
2382 | */ | |
355afbcd KR |
2383 | if (*q == ']') |
2384 | { | |
2385 | while (q >= p && *q != '[') | |
fecd2382 | 2386 | q--; |
355afbcd KR |
2387 | /* either q<p or we got matching '[' */ |
2388 | if (q < p) | |
fecd2382 | 2389 | err = "no '[' to match ']'"; |
355afbcd KR |
2390 | else |
2391 | { | |
2392 | /* | |
9a75dc1f ILT |
2393 | * Confusers like "[]" will eventually lose with a bad register |
2394 | * name error. So again we don't need to check for early '\0'. | |
2395 | */ | |
355afbcd | 2396 | if (q[3] == ']') |
fecd2382 | 2397 | ndx = vax_reg_parse (q[1], q[2], 0); |
355afbcd | 2398 | else if (q[4] == ']') |
fecd2382 | 2399 | ndx = vax_reg_parse (q[1], q[2], q[3]); |
355afbcd | 2400 | else |
fecd2382 | 2401 | ndx = -1; |
355afbcd | 2402 | /* |
f3d817d8 DM |
2403 | * Since we saw a ']' we will demand a register name in the []. |
2404 | * If luser hasn't given us one: be rude. | |
2405 | */ | |
355afbcd | 2406 | if (ndx < 0) |
fecd2382 | 2407 | err = "bad register in []"; |
355afbcd | 2408 | else if (ndx == PC) |
fecd2382 | 2409 | err = "[PC] index banned"; |
355afbcd | 2410 | else |
fecd2382 | 2411 | q--; /* point q just before "[...]" */ |
355afbcd | 2412 | } |
fecd2382 | 2413 | } |
355afbcd | 2414 | else |
fecd2382 RP |
2415 | ndx = -1; /* no ']', so no iNDeX register */ |
2416 | ||
355afbcd | 2417 | /* |
f3d817d8 DM |
2418 | * If err = "..." then we lost: run away. |
2419 | * Otherwise ndx == -1 if there was no "[...]". | |
2420 | * Otherwise, ndx is index register number, and q points before "[...]". | |
2421 | */ | |
fecd2382 | 2422 | \f |
355afbcd | 2423 | if (*q == ' ' && q >= p) /* Expect all whitespace reduced to ' '. */ |
fecd2382 | 2424 | q--; |
355afbcd KR |
2425 | /* reverse over whitespace, but don't */ |
2426 | /* run back over *p */ | |
f3d817d8 | 2427 | if (!err || !*err) |
fecd2382 | 2428 | { |
355afbcd KR |
2429 | sign = 0; /* no ()+ or -() seen yet */ |
2430 | ||
2431 | if (q > p + 3 && *q == '+' && q[-1] == ')') | |
2432 | { | |
2433 | sign = 1; /* we saw a ")+" */ | |
2434 | q--; /* q points to ')' */ | |
2435 | } | |
2436 | ||
2437 | if (*q == ')' && q > p + 2) | |
2438 | { | |
2439 | paren = 1; /* assume we have "(...)" */ | |
2440 | while (q >= p && *q != '(') | |
fecd2382 | 2441 | q--; |
355afbcd KR |
2442 | /* either q<p or we got matching '(' */ |
2443 | if (q < p) | |
fecd2382 | 2444 | err = "no '(' to match ')'"; |
355afbcd KR |
2445 | else |
2446 | { | |
2447 | /* | |
9a75dc1f ILT |
2448 | * Confusers like "()" will eventually lose with a bad register |
2449 | * name error. So again we don't need to check for early '\0'. | |
2450 | */ | |
355afbcd | 2451 | if (q[3] == ')') |
fecd2382 | 2452 | reg = vax_reg_parse (q[1], q[2], 0); |
355afbcd | 2453 | else if (q[4] == ')') |
fecd2382 | 2454 | reg = vax_reg_parse (q[1], q[2], q[3]); |
355afbcd | 2455 | else |
fecd2382 | 2456 | reg = -1; |
355afbcd | 2457 | /* |
9a75dc1f ILT |
2458 | * Since we saw a ')' we will demand a register name in the ')'. |
2459 | * This is nasty: why can't our hypothetical assembler permit | |
2460 | * parenthesised expressions? BECAUSE I AM LAZY! That is why. | |
2461 | * Abuse luser if we didn't spy a register name. | |
2462 | */ | |
355afbcd KR |
2463 | if (reg < 0) |
2464 | { | |
2465 | /* JF allow parenthasized expressions. I hope this works */ | |
2466 | paren = 0; | |
2467 | while (*q != ')') | |
fecd2382 | 2468 | q++; |
355afbcd KR |
2469 | /* err = "unknown register in ()"; */ |
2470 | } | |
2471 | else | |
a39116f1 | 2472 | q--; /* point just before '(' of "(...)" */ |
355afbcd | 2473 | /* |
9a75dc1f ILT |
2474 | * If err == "..." then we lost. Run away. |
2475 | * Otherwise if reg >= 0 then we saw (Rn). | |
2476 | */ | |
355afbcd KR |
2477 | } |
2478 | /* | |
9a75dc1f ILT |
2479 | * If err == "..." then we lost. |
2480 | * Otherwise paren==1 and reg = register in "()". | |
2481 | */ | |
fecd2382 | 2482 | } |
355afbcd KR |
2483 | else |
2484 | paren = 0; | |
2485 | /* | |
9a75dc1f ILT |
2486 | * If err == "..." then we lost. |
2487 | * Otherwise, q points just before "(Rn)", if any. | |
2488 | * If there was a "(...)" then paren==1, and reg is the register. | |
2489 | */ | |
355afbcd KR |
2490 | \f |
2491 | /* | |
9a75dc1f ILT |
2492 | * We should only seek '-' of "-(...)" if: |
2493 | * we saw "(...)" paren == 1 | |
2494 | * we have no errors so far ! *err | |
2495 | * we did not see '+' of "(...)+" sign < 1 | |
2496 | * We don't check len. We want a specific error message later if | |
2497 | * user tries "x^...-(Rn)". This is a feature not a bug. | |
2498 | */ | |
f3d817d8 | 2499 | if (!err || !*err) |
fecd2382 | 2500 | { |
355afbcd | 2501 | if (paren && sign < 1)/* !sign is adequate test */ |
fecd2382 | 2502 | { |
355afbcd KR |
2503 | if (*q == '-') |
2504 | { | |
2505 | sign = -1; | |
2506 | q--; | |
2507 | } | |
fecd2382 | 2508 | } |
355afbcd | 2509 | /* |
9a75dc1f ILT |
2510 | * We have back-tracked over most |
2511 | * of the crud at the end of an operand. | |
2512 | * Unless err, we know: sign, paren. If paren, we know reg. | |
2513 | * The last case is of an expression "Rn". | |
2514 | * This is worth hunting for if !err, !paren. | |
2515 | * We wouldn't be here if err. | |
2516 | * We remember to save q, in case we didn't want "Rn" anyway. | |
2517 | */ | |
355afbcd KR |
2518 | if (!paren) |
2519 | { | |
2520 | if (*q == ' ' && q >= p) /* Expect all whitespace reduced to ' '. */ | |
fecd2382 | 2521 | q--; |
355afbcd KR |
2522 | /* reverse over whitespace, but don't */ |
2523 | /* run back over *p */ | |
2524 | if (q > p && q < p + 3) /* room for Rn or Rnn exactly? */ | |
fecd2382 | 2525 | reg = vax_reg_parse (p[0], p[1], q < p + 2 ? 0 : p[2]); |
355afbcd | 2526 | else |
fecd2382 | 2527 | reg = -1; /* always comes here if no register at all */ |
355afbcd | 2528 | /* |
9a75dc1f ILT |
2529 | * Here with a definitive reg value. |
2530 | */ | |
355afbcd KR |
2531 | if (reg >= 0) |
2532 | { | |
2533 | oldq = q; | |
2534 | q = p - 1; | |
2535 | } | |
fecd2382 RP |
2536 | } |
2537 | } | |
2538 | } | |
355afbcd | 2539 | /* |
9a75dc1f ILT |
2540 | * have reg. -1:absent; else 0:15 |
2541 | */ | |
fecd2382 | 2542 | |
355afbcd | 2543 | /* |
9a75dc1f ILT |
2544 | * We have: err, at, len, hash, ndx, sign, paren, reg. |
2545 | * Also, any remaining expression is from *p through *q inclusive. | |
2546 | * Should there be no expression, q==p-1. So expression length = q-p+1. | |
2547 | * This completes the first part: parsing the operand text. | |
2548 | */ | |
fecd2382 | 2549 | \f |
355afbcd | 2550 | /* |
9a75dc1f ILT |
2551 | * We now want to boil the data down, checking consistency on the way. |
2552 | * We want: len, mode, reg, ndx, err, p, q, wrn, bug. | |
2553 | * We will deliver a 4-bit reg, and a 4-bit mode. | |
2554 | */ | |
fecd2382 | 2555 | |
355afbcd | 2556 | /* |
9a75dc1f ILT |
2557 | * Case of branch operand. Different. No L^B^W^I^S^ allowed for instance. |
2558 | * | |
2559 | * in: at ? | |
2560 | * len ? | |
2561 | * hash ? | |
2562 | * p:q ? | |
2563 | * sign ? | |
2564 | * paren ? | |
2565 | * reg ? | |
2566 | * ndx ? | |
2567 | * | |
2568 | * out: mode 0 | |
2569 | * reg -1 | |
2570 | * len ' ' | |
2571 | * p:q whatever was input | |
2572 | * ndx -1 | |
2573 | * err " " or error message, and other outputs trashed | |
2574 | */ | |
355afbcd | 2575 | /* branch operands have restricted forms */ |
f3d817d8 | 2576 | if ((!err || !*err) && access == 'b') |
355afbcd KR |
2577 | { |
2578 | if (at || hash || sign || paren || ndx >= 0 || reg >= 0 || len != ' ') | |
fecd2382 | 2579 | err = "invalid branch operand"; |
355afbcd | 2580 | else |
fecd2382 | 2581 | err = " "; |
355afbcd | 2582 | } |
fecd2382 | 2583 | \f |
355afbcd | 2584 | /* Since nobody seems to use it: comment this 'feature'(?) out for now. */ |
fecd2382 | 2585 | #ifdef NEVER |
355afbcd | 2586 | /* |
9a75dc1f ILT |
2587 | * Case of stand-alone operand. e.g. ".long foo" |
2588 | * | |
2589 | * in: at ? | |
2590 | * len ? | |
2591 | * hash ? | |
2592 | * p:q ? | |
2593 | * sign ? | |
2594 | * paren ? | |
2595 | * reg ? | |
2596 | * ndx ? | |
2597 | * | |
2598 | * out: mode 0 | |
2599 | * reg -1 | |
2600 | * len ' ' | |
2601 | * p:q whatever was input | |
2602 | * ndx -1 | |
2603 | * err " " or error message, and other outputs trashed | |
2604 | */ | |
f3d817d8 | 2605 | if ((!err || !*err) && access == ' ') |
355afbcd | 2606 | { |
f3d817d8 DM |
2607 | if (at) |
2608 | err = "address prohibits @"; | |
2609 | else if (hash) | |
2610 | err = "address prohibits #"; | |
2611 | else if (sign) | |
2612 | { | |
2613 | if (sign < 0) | |
2614 | err = "address prohibits -()"; | |
355afbcd | 2615 | else |
f3d817d8 DM |
2616 | err = "address prohibits ()+"; |
2617 | } | |
2618 | else if (paren) | |
2619 | err = "address prohibits ()"; | |
2620 | else if (ndx >= 0) | |
2621 | err = "address prohibits []"; | |
2622 | else if (reg >= 0) | |
2623 | err = "address prohibits register"; | |
2624 | else if (len != ' ') | |
2625 | err = "address prohibits displacement length specifier"; | |
2626 | else | |
2627 | { | |
2628 | err = " "; /* succeed */ | |
2629 | mode = 0; | |
fecd2382 RP |
2630 | } |
2631 | } | |
2632 | #endif /*#Ifdef NEVER*/ | |
2633 | \f | |
355afbcd | 2634 | /* |
9a75dc1f ILT |
2635 | * Case of S^#. |
2636 | * | |
2637 | * in: at 0 | |
2638 | * len 's' definition | |
2639 | * hash 1 demand | |
2640 | * p:q demand not empty | |
2641 | * sign 0 by paren==0 | |
2642 | * paren 0 by "()" scan logic because "S^" seen | |
2643 | * reg -1 or nn by mistake | |
2644 | * ndx -1 | |
2645 | * | |
2646 | * out: mode 0 | |
2647 | * reg -1 | |
2648 | * len 's' | |
2649 | * exp | |
2650 | * ndx -1 | |
2651 | */ | |
f3d817d8 | 2652 | if ((!err || !*err) && len == 's') |
a39116f1 | 2653 | { |
355afbcd KR |
2654 | if (!hash || paren || at || ndx >= 0) |
2655 | err = "invalid operand of S^#"; | |
2656 | else | |
fecd2382 | 2657 | { |
355afbcd KR |
2658 | if (reg >= 0) |
2659 | { | |
2660 | /* | |
2661 | * SHIT! we saw S^#Rnn ! put the Rnn back in | |
2662 | * expression. KLUDGE! Use oldq so we don't | |
2663 | * need to know exact length of reg name. | |
2664 | */ | |
2665 | q = oldq; | |
2666 | reg = 0; | |
2667 | } | |
2668 | /* | |
f3d817d8 DM |
2669 | * We have all the expression we will ever get. |
2670 | */ | |
355afbcd | 2671 | if (p > q) |
fecd2382 | 2672 | err = "S^# needs expression"; |
355afbcd KR |
2673 | else if (access == 'r') |
2674 | { | |
2675 | err = " "; /* WIN! */ | |
2676 | mode = 0; | |
2677 | } | |
2678 | else | |
a39116f1 | 2679 | err = "S^# may only read-access"; |
355afbcd | 2680 | } |
fecd2382 RP |
2681 | } |
2682 | \f | |
355afbcd | 2683 | /* |
9a75dc1f ILT |
2684 | * Case of -(Rn), which is weird case. |
2685 | * | |
2686 | * in: at 0 | |
2687 | * len ' | |
2688 | * hash 0 | |
2689 | * p:q q<p | |
2690 | * sign -1 by definition | |
2691 | * paren 1 by definition | |
2692 | * reg present by definition | |
2693 | * ndx optional | |
2694 | * | |
2695 | * out: mode 7 | |
2696 | * reg present | |
2697 | * len ' ' | |
2698 | * exp "" enforce empty expression | |
2699 | * ndx optional warn if same as reg | |
2700 | */ | |
f3d817d8 | 2701 | if ((!err || !*err) && sign < 0) |
a39116f1 | 2702 | { |
355afbcd KR |
2703 | if (len != ' ' || hash || at || p <= q) |
2704 | err = "invalid operand of -()"; | |
2705 | else | |
2706 | { | |
2707 | err = " "; /* win */ | |
2708 | mode = 7; | |
2709 | if (reg == PC) | |
fecd2382 | 2710 | wrn = "-(PC) unpredictable"; |
355afbcd | 2711 | else if (reg == ndx) |
fecd2382 | 2712 | wrn = "[]index same as -()register: unpredictable"; |
355afbcd | 2713 | } |
fecd2382 RP |
2714 | } |
2715 | \f | |
355afbcd | 2716 | /* |
9a75dc1f ILT |
2717 | * We convert "(Rn)" to "@Rn" for our convenience. |
2718 | * (I hope this is convenient: has someone got a better way to parse this?) | |
2719 | * A side-effect of this is that "@Rn" is a valid operand. | |
2720 | */ | |
355afbcd KR |
2721 | if (paren && !sign && !hash && !at && len == ' ' && p > q) |
2722 | { | |
2723 | at = 1; | |
2724 | paren = 0; | |
2725 | } | |
fecd2382 | 2726 | |
355afbcd | 2727 | /* |
9a75dc1f ILT |
2728 | * Case of (Rn)+, which is slightly different. |
2729 | * | |
2730 | * in: at | |
2731 | * len ' ' | |
2732 | * hash 0 | |
2733 | * p:q q<p | |
2734 | * sign +1 by definition | |
2735 | * paren 1 by definition | |
2736 | * reg present by definition | |
2737 | * ndx optional | |
2738 | * | |
2739 | * out: mode 8+@ | |
2740 | * reg present | |
2741 | * len ' ' | |
2742 | * exp "" enforce empty expression | |
2743 | * ndx optional warn if same as reg | |
2744 | */ | |
f3d817d8 | 2745 | if ((!err || !*err) && sign > 0) |
a39116f1 | 2746 | { |
355afbcd KR |
2747 | if (len != ' ' || hash || p <= q) |
2748 | err = "invalid operand of ()+"; | |
2749 | else | |
2750 | { | |
2751 | err = " "; /* win */ | |
2752 | mode = 8 + (at ? 1 : 0); | |
2753 | if (reg == PC) | |
fecd2382 | 2754 | wrn = "(PC)+ unpredictable"; |
355afbcd | 2755 | else if (reg == ndx) |
fecd2382 | 2756 | wrn = "[]index same as ()+register: unpredictable"; |
355afbcd | 2757 | } |
fecd2382 RP |
2758 | } |
2759 | \f | |
355afbcd | 2760 | /* |
9a75dc1f ILT |
2761 | * Case of #, without S^. |
2762 | * | |
2763 | * in: at | |
2764 | * len ' ' or 'i' | |
2765 | * hash 1 by definition | |
2766 | * p:q | |
2767 | * sign 0 | |
2768 | * paren 0 | |
2769 | * reg absent | |
2770 | * ndx optional | |
2771 | * | |
2772 | * out: mode 8+@ | |
2773 | * reg PC | |
2774 | * len ' ' or 'i' | |
2775 | * exp | |
2776 | * ndx optional | |
2777 | */ | |
f3d817d8 | 2778 | if ((!err || !*err) && hash) |
355afbcd KR |
2779 | { |
2780 | if (len != 'i' && len != ' ') | |
fecd2382 | 2781 | err = "# conflicts length"; |
355afbcd | 2782 | else if (paren) |
fecd2382 | 2783 | err = "# bars register"; |
355afbcd | 2784 | else |
fecd2382 | 2785 | { |
355afbcd KR |
2786 | if (reg >= 0) |
2787 | { | |
2788 | /* | |
9a75dc1f ILT |
2789 | * SHIT! we saw #Rnn! Put the Rnn back into the expression. |
2790 | * By using oldq, we don't need to know how long Rnn was. | |
2791 | * KLUDGE! | |
2792 | */ | |
355afbcd KR |
2793 | q = oldq; |
2794 | reg = -1; /* no register any more */ | |
2795 | } | |
2796 | err = " "; /* win */ | |
2797 | ||
2798 | /* JF a bugfix, I think! */ | |
2799 | if (at && access == 'a') | |
2800 | vopP->vop_nbytes = 4; | |
2801 | ||
2802 | mode = (at ? 9 : 8); | |
2803 | reg = PC; | |
2804 | if ((access == 'm' || access == 'w') && !at) | |
fecd2382 | 2805 | wrn = "writing or modifying # is unpredictable"; |
355afbcd | 2806 | } |
fecd2382 | 2807 | } |
355afbcd | 2808 | /* |
9a75dc1f ILT |
2809 | * If !*err, then sign == 0 |
2810 | * hash == 0 | |
2811 | */ | |
fecd2382 | 2812 | \f |
355afbcd | 2813 | /* |
9a75dc1f ILT |
2814 | * Case of Rn. We seperate this one because it has a few special |
2815 | * errors the remaining modes lack. | |
2816 | * | |
2817 | * in: at optional | |
2818 | * len ' ' | |
2819 | * hash 0 by program logic | |
2820 | * p:q empty | |
2821 | * sign 0 by program logic | |
2822 | * paren 0 by definition | |
2823 | * reg present by definition | |
2824 | * ndx optional | |
2825 | * | |
2826 | * out: mode 5+@ | |
2827 | * reg present | |
2828 | * len ' ' enforce no length | |
2829 | * exp "" enforce empty expression | |
2830 | * ndx optional warn if same as reg | |
2831 | */ | |
f3d817d8 | 2832 | if ((!err || !*err) && !paren && reg >= 0) |
a39116f1 | 2833 | { |
355afbcd KR |
2834 | if (len != ' ') |
2835 | err = "length not needed"; | |
2836 | else if (at) | |
2837 | { | |
2838 | err = " "; /* win */ | |
2839 | mode = 6; /* @Rn */ | |
2840 | } | |
2841 | else if (ndx >= 0) | |
fecd2382 | 2842 | err = "can't []index a register, because it has no address"; |
355afbcd | 2843 | else if (access == 'a') |
fecd2382 | 2844 | err = "a register has no address"; |
355afbcd KR |
2845 | else |
2846 | { | |
2847 | /* | |
9a75dc1f ILT |
2848 | * Idea here is to detect from length of datum |
2849 | * and from register number if we will touch PC. | |
2850 | * Warn if we do. | |
2851 | * vop_nbytes is number of bytes in operand. | |
2852 | * Compute highest byte affected, compare to PC0. | |
2853 | */ | |
355afbcd | 2854 | if ((vopP->vop_nbytes + reg * 4) > 60) |
fecd2382 | 2855 | wrn = "PC part of operand unpredictable"; |
355afbcd KR |
2856 | err = " "; /* win */ |
2857 | mode = 5; /* Rn */ | |
2858 | } | |
fecd2382 | 2859 | } |
355afbcd | 2860 | /* |
f3d817d8 DM |
2861 | * If !*err, sign == 0 |
2862 | * hash == 0 | |
2863 | * paren == 1 OR reg==-1 | |
2864 | */ | |
fecd2382 | 2865 | \f |
355afbcd | 2866 | /* |
f3d817d8 DM |
2867 | * Rest of cases fit into one bunch. |
2868 | * | |
2869 | * in: at optional | |
2870 | * len ' ' or 'b' or 'w' or 'l' | |
2871 | * hash 0 by program logic | |
2872 | * p:q expected (empty is not an error) | |
2873 | * sign 0 by program logic | |
2874 | * paren optional | |
2875 | * reg optional | |
2876 | * ndx optional | |
2877 | * | |
2878 | * out: mode 10 + @ + len | |
2879 | * reg optional | |
2880 | * len ' ' or 'b' or 'w' or 'l' | |
2881 | * exp maybe empty | |
2882 | * ndx optional warn if same as reg | |
2883 | */ | |
2884 | if (!err || !*err) | |
fecd2382 | 2885 | { |
355afbcd KR |
2886 | err = " "; /* win (always) */ |
2887 | mode = 10 + (at ? 1 : 0); | |
2888 | switch (len) | |
2889 | { | |
2890 | case 'l': | |
2891 | mode += 2; | |
2892 | case 'w': | |
2893 | mode += 2; | |
2894 | case ' ': /* assumed B^ until our caller changes it */ | |
2895 | case 'b': | |
2896 | break; | |
2897 | } | |
fecd2382 RP |
2898 | } |
2899 | ||
355afbcd | 2900 | /* |
9a75dc1f ILT |
2901 | * here with completely specified mode |
2902 | * len | |
2903 | * reg | |
2904 | * expression p,q | |
2905 | * ndx | |
2906 | */ | |
fecd2382 | 2907 | |
355afbcd | 2908 | if (*err == ' ') |
f3d817d8 | 2909 | err = 0; /* " " is no longer an error */ |
355afbcd KR |
2910 | |
2911 | vopP->vop_mode = mode; | |
2912 | vopP->vop_reg = reg; | |
2913 | vopP->vop_short = len; | |
2914 | vopP->vop_expr_begin = p; | |
2915 | vopP->vop_expr_end = q; | |
2916 | vopP->vop_ndx = ndx; | |
2917 | vopP->vop_error = err; | |
2918 | vopP->vop_warn = wrn; | |
f3d817d8 | 2919 | } |
fecd2382 RP |
2920 | \f |
2921 | /* | |
355afbcd | 2922 | |
a39116f1 | 2923 | Summary of vip_op outputs. |
355afbcd | 2924 | |
a39116f1 RP |
2925 | mode reg len ndx |
2926 | (Rn) => @Rn | |
2927 | {@}Rn 5+@ n ' ' optional | |
2928 | branch operand 0 -1 ' ' -1 | |
2929 | S^#foo 0 -1 's' -1 | |
2930 | -(Rn) 7 n ' ' optional | |
2931 | {@}(Rn)+ 8+@ n ' ' optional | |
2932 | {@}#foo, no S^ 8+@ PC " i" optional | |
2933 | {@}{q^}{(Rn)} 10+@+q option " bwl" optional | |
355afbcd | 2934 | |
a39116f1 | 2935 | */ |
fecd2382 RP |
2936 | \f |
2937 | #ifdef TEST /* #Define to use this testbed. */ | |
2938 | ||
2939 | /* | |
2940 | * Follows a test program for this function. | |
2941 | * We declare arrays non-local in case some of our tiny-minded machines | |
2942 | * default to small stacks. Also, helps with some debuggers. | |
2943 | */ | |
2944 | ||
2945 | #include <stdio.h> | |
2946 | ||
2947 | char answer[100]; /* human types into here */ | |
2948 | char *p; /* */ | |
2949 | char *myerr; | |
2950 | char *mywrn; | |
2951 | char *mybug; | |
2952 | char myaccess; | |
2953 | char mywidth; | |
2954 | char mymode; | |
2955 | char myreg; | |
2956 | char mylen; | |
2957 | char *myleft; | |
2958 | char *myright; | |
2959 | char myndx; | |
2960 | int my_operand_length; | |
2961 | char my_immediate[200]; | |
2962 | char my_indirect[200]; | |
2963 | char my_displen[200]; | |
2964 | ||
2965 | main () | |
2966 | { | |
355afbcd KR |
2967 | printf ("enter immediate symbols eg enter # "); |
2968 | gets (my_immediate); | |
2969 | printf ("enter indirect symbols eg enter @ "); | |
2970 | gets (my_indirect); | |
2971 | printf ("enter displen symbols eg enter ^ "); | |
2972 | gets (my_displen); | |
2973 | vip_op_defaults (my_immediate, my_indirect, my_displen); | |
2974 | for (;;) | |
fecd2382 | 2975 | { |
355afbcd KR |
2976 | printf ("access,width (eg 'ab' or 'wh') [empty line to quit] : "); |
2977 | fflush (stdout); | |
2978 | gets (answer); | |
2979 | if (!answer[0]) | |
460531da | 2980 | exit (EXIT_SUCCESS); |
355afbcd KR |
2981 | myaccess = answer[0]; |
2982 | mywidth = answer[1]; | |
2983 | switch (mywidth) | |
fecd2382 RP |
2984 | { |
2985 | case 'b': | |
355afbcd KR |
2986 | my_operand_length = 1; |
2987 | break; | |
fecd2382 | 2988 | case 'd': |
355afbcd KR |
2989 | my_operand_length = 8; |
2990 | break; | |
fecd2382 | 2991 | case 'f': |
355afbcd KR |
2992 | my_operand_length = 4; |
2993 | break; | |
fecd2382 | 2994 | case 'g': |
355afbcd KR |
2995 | my_operand_length = 16; |
2996 | break; | |
fecd2382 | 2997 | case 'h': |
355afbcd KR |
2998 | my_operand_length = 32; |
2999 | break; | |
fecd2382 | 3000 | case 'l': |
355afbcd KR |
3001 | my_operand_length = 4; |
3002 | break; | |
fecd2382 | 3003 | case 'o': |
355afbcd KR |
3004 | my_operand_length = 16; |
3005 | break; | |
fecd2382 | 3006 | case 'q': |
355afbcd KR |
3007 | my_operand_length = 8; |
3008 | break; | |
fecd2382 | 3009 | case 'w': |
355afbcd KR |
3010 | my_operand_length = 2; |
3011 | break; | |
fecd2382 RP |
3012 | case '!': |
3013 | case '?': | |
3014 | case '-': | |
355afbcd KR |
3015 | my_operand_length = 0; |
3016 | break; | |
3017 | ||
fecd2382 | 3018 | default: |
355afbcd KR |
3019 | my_operand_length = 2; |
3020 | printf ("I dn't understand access width %c\n", mywidth); | |
3021 | break; | |
fecd2382 | 3022 | } |
355afbcd KR |
3023 | printf ("VAX assembler instruction operand: "); |
3024 | fflush (stdout); | |
3025 | gets (answer); | |
3026 | mybug = vip_op (answer, myaccess, mywidth, my_operand_length, | |
3027 | &mymode, &myreg, &mylen, &myleft, &myright, &myndx, | |
3028 | &myerr, &mywrn); | |
3029 | if (*myerr) | |
fecd2382 | 3030 | { |
355afbcd KR |
3031 | printf ("error: \"%s\"\n", myerr); |
3032 | if (*mybug) | |
3033 | printf (" bug: \"%s\"\n", mybug); | |
fecd2382 | 3034 | } |
355afbcd | 3035 | else |
fecd2382 | 3036 | { |
355afbcd KR |
3037 | if (*mywrn) |
3038 | printf ("warning: \"%s\"\n", mywrn); | |
3039 | mumble ("mode", mymode); | |
3040 | mumble ("register", myreg); | |
3041 | mumble ("index", myndx); | |
3042 | printf ("width:'%c' ", mylen); | |
3043 | printf ("expression: \""); | |
3044 | while (myleft <= myright) | |
3045 | putchar (*myleft++); | |
3046 | printf ("\"\n"); | |
fecd2382 RP |
3047 | } |
3048 | } | |
3049 | } | |
3050 | ||
3051 | mumble (text, value) | |
355afbcd KR |
3052 | char *text; |
3053 | int value; | |
3054 | { | |
3055 | printf ("%s:", text); | |
3056 | if (value >= 0) | |
3057 | printf ("%xx", value); | |
3058 | else | |
3059 | printf ("ABSENT"); | |
3060 | printf (" "); | |
fecd2382 RP |
3061 | } |
3062 | ||
3063 | #endif /* ifdef TEST */ | |
3064 | ||
3065 | /* end: vip_op.c */ | |
3066 | ||
3067 | const int md_short_jump_size = 3; | |
3068 | const int md_long_jump_size = 6; | |
355afbcd | 3069 | const int md_reloc_size = 8; /* Size of relocation record */ |
fecd2382 RP |
3070 | |
3071 | void | |
355afbcd KR |
3072 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) |
3073 | char *ptr; | |
025b0302 | 3074 | addressT from_addr, to_addr; |
355afbcd KR |
3075 | fragS *frag; |
3076 | symbolS *to_symbol; | |
fecd2382 | 3077 | { |
025b0302 | 3078 | valueT offset; |
355afbcd KR |
3079 | |
3080 | offset = to_addr - (from_addr + 1); | |
3081 | *ptr++ = 0x31; | |
3082 | md_number_to_chars (ptr, offset, 2); | |
fecd2382 RP |
3083 | } |
3084 | ||
3085 | void | |
355afbcd KR |
3086 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) |
3087 | char *ptr; | |
025b0302 | 3088 | addressT from_addr, to_addr; |
355afbcd KR |
3089 | fragS *frag; |
3090 | symbolS *to_symbol; | |
3091 | { | |
025b0302 | 3092 | valueT offset; |
355afbcd KR |
3093 | |
3094 | offset = to_addr - S_GET_VALUE (to_symbol); | |
3095 | *ptr++ = 0x17; | |
3096 | *ptr++ = 0x9F; | |
3097 | md_number_to_chars (ptr, offset, 4); | |
f3d817d8 | 3098 | fix_new (frag, ptr - frag->fr_literal, 4, to_symbol, (long) 0, 0, NO_RELOC); |
fecd2382 | 3099 | } |
f3d817d8 DM |
3100 | \f |
3101 | #ifdef OBJ_VMS | |
8e86815b | 3102 | CONST char *md_shortopts = "d:STt:V+1h:Hv::"; |
f3d817d8 DM |
3103 | #else |
3104 | CONST char *md_shortopts = "d:STt:V"; | |
3105 | #endif | |
3106 | struct option md_longopts[] = { | |
3107 | {NULL, no_argument, NULL, 0} | |
3108 | }; | |
3109 | size_t md_longopts_size = sizeof(md_longopts); | |
fecd2382 RP |
3110 | |
3111 | int | |
f3d817d8 DM |
3112 | md_parse_option (c, arg) |
3113 | int c; | |
3114 | char *arg; | |
fecd2382 | 3115 | { |
f3d817d8 | 3116 | switch (c) |
fecd2382 | 3117 | { |
fecd2382 | 3118 | case 'S': |
355afbcd | 3119 | as_warn ("SYMBOL TABLE not implemented"); |
f3d817d8 | 3120 | break; |
355afbcd | 3121 | |
fecd2382 | 3122 | case 'T': |
355afbcd | 3123 | as_warn ("TOKEN TRACE not implemented"); |
f3d817d8 | 3124 | break; |
355afbcd | 3125 | |
fecd2382 | 3126 | case 'd': |
f3d817d8 DM |
3127 | as_warn ("Displacement length %s ignored!", arg); |
3128 | break; | |
355afbcd | 3129 | |
f3d817d8 DM |
3130 | case 't': |
3131 | as_warn ("I don't need or use temp. file \"%s\".", arg); | |
355afbcd KR |
3132 | break; |
3133 | ||
fecd2382 | 3134 | case 'V': |
355afbcd KR |
3135 | as_warn ("I don't use an interpass file! -V ignored"); |
3136 | break; | |
3137 | ||
025b0302 | 3138 | #ifdef OBJ_VMS |
def66e24 DM |
3139 | case '+': /* For g++. Hash any name > 31 chars long. */ |
3140 | flag_hash_long_names = 1; | |
3141 | break; | |
3142 | ||
3143 | case '1': /* For backward compatibility */ | |
3144 | flag_one = 1; | |
3145 | break; | |
3146 | ||
3147 | case 'H': /* Show new symbol after hash truncation */ | |
3148 | flag_show_after_trunc = 1; | |
355afbcd KR |
3149 | break; |
3150 | ||
3151 | case 'h': /* No hashing of mixed-case names */ | |
f3d817d8 DM |
3152 | { |
3153 | extern char vms_name_mapping; | |
3154 | vms_name_mapping = atoi (arg); | |
def66e24 | 3155 | flag_no_hash_mixed_case = 1; |
f3d817d8 | 3156 | } |
355afbcd KR |
3157 | break; |
3158 | ||
def66e24 DM |
3159 | case 'v': |
3160 | { | |
3161 | extern char *compiler_version_string; | |
8e86815b KR |
3162 | if (!arg || !*arg || access (arg, 0) == 0) |
3163 | return 0; /* have caller show the assembler version */ | |
def66e24 DM |
3164 | compiler_version_string = arg; |
3165 | } | |
355afbcd | 3166 | break; |
fecd2382 | 3167 | #endif |
355afbcd | 3168 | |
fecd2382 | 3169 | default: |
355afbcd | 3170 | return 0; |
fecd2382 | 3171 | } |
f3d817d8 | 3172 | |
355afbcd | 3173 | return 1; |
fecd2382 RP |
3174 | } |
3175 | ||
f3d817d8 DM |
3176 | void |
3177 | md_show_usage (stream) | |
3178 | FILE *stream; | |
3179 | { | |
3180 | fprintf(stream, "\ | |
3181 | VAX options:\n\ | |
3182 | -d LENGTH ignored\n\ | |
3183 | -J ignored\n\ | |
3184 | -S ignored\n\ | |
3185 | -t FILE ignored\n\ | |
3186 | -T ignored\n\ | |
3187 | -V ignored\n"); | |
def66e24 DM |
3188 | #ifdef OBJ_VMS |
3189 | fprintf (stream, "\ | |
8e86815b KR |
3190 | VMS options:\n\ |
3191 | -+ hash encode names longer than 31 characters\n\ | |
3192 | -1 `const' handling compatible with gcc 1.x\n\ | |
def66e24 | 3193 | -H show new symbol after hash truncation\n\ |
dbc0fdd7 DM |
3194 | -h NUM don't hash mixed-case names, and adjust case:\n\ |
3195 | 0 = upper, 2 = lower, 3 = preserve case\n\ | |
8e86815b | 3196 | -v\"VERSION\" code being assembled was produced by compiler \"VERSION\"\n"); |
def66e24 | 3197 | #endif |
f3d817d8 DM |
3198 | } |
3199 | \f | |
fecd2382 RP |
3200 | /* We have no need to default values of symbols. */ |
3201 | ||
3202 | /* ARGSUSED */ | |
3203 | symbolS * | |
355afbcd KR |
3204 | md_undefined_symbol (name) |
3205 | char *name; | |
fecd2382 | 3206 | { |
355afbcd | 3207 | return 0; |
fecd2382 RP |
3208 | } |
3209 | ||
355afbcd | 3210 | /* Parse an operand that is machine-specific. |
fecd2382 RP |
3211 | We just return without modifying the expression if we have nothing |
3212 | to do. */ | |
3213 | ||
3214 | /* ARGSUSED */ | |
3215 | void | |
355afbcd KR |
3216 | md_operand (expressionP) |
3217 | expressionS *expressionP; | |
fecd2382 RP |
3218 | { |
3219 | } | |
3220 | ||
3221 | /* Round up a section size to the appropriate boundary. */ | |
025b0302 | 3222 | valueT |
355afbcd KR |
3223 | md_section_align (segment, size) |
3224 | segT segment; | |
025b0302 | 3225 | valueT size; |
fecd2382 | 3226 | { |
355afbcd | 3227 | return size; /* Byte alignment is fine */ |
fecd2382 RP |
3228 | } |
3229 | ||
3230 | /* Exactly what point is a PC-relative offset relative TO? | |
3231 | On the vax, they're relative to the address of the offset, plus | |
3232 | its size. (??? Is this right? FIXME-SOON) */ | |
3233 | long | |
355afbcd KR |
3234 | md_pcrel_from (fixP) |
3235 | fixS *fixP; | |
fecd2382 | 3236 | { |
355afbcd | 3237 | return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address; |
fecd2382 | 3238 | } |
8b228fe9 RP |
3239 | |
3240 | /* end of tc-vax.c */ |