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