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