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