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