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