| 1 | /* tc-mn10300.c -- Assembler code for the Matsushita 10300
|
|---|
| 2 | Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
|
|---|
| 3 | Free Software Foundation, Inc.
|
|---|
| 4 |
|
|---|
| 5 | This file is part of GAS, the GNU Assembler.
|
|---|
| 6 |
|
|---|
| 7 | GAS is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 10 | any later version.
|
|---|
| 11 |
|
|---|
| 12 | GAS is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with GAS; see the file COPYING. If not, write to
|
|---|
| 19 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 20 | Boston, MA 02111-1307, USA. */
|
|---|
| 21 |
|
|---|
| 22 | #include <stdio.h>
|
|---|
| 23 | #include "as.h"
|
|---|
| 24 | #include "safe-ctype.h"
|
|---|
| 25 | #include "subsegs.h"
|
|---|
| 26 | #include "opcode/mn10300.h"
|
|---|
| 27 | #include "dwarf2dbg.h"
|
|---|
| 28 | |
|---|
| 29 |
|
|---|
| 30 | /* Structure to hold information about predefined registers. */
|
|---|
| 31 | struct reg_name
|
|---|
| 32 | {
|
|---|
| 33 | const char *name;
|
|---|
| 34 | int value;
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | /* Generic assembler global variables which must be defined by all
|
|---|
| 38 | targets. */
|
|---|
| 39 |
|
|---|
| 40 | /* Characters which always start a comment. */
|
|---|
| 41 | const char comment_chars[] = "#";
|
|---|
| 42 |
|
|---|
| 43 | /* Characters which start a comment at the beginning of a line. */
|
|---|
| 44 | const char line_comment_chars[] = ";#";
|
|---|
| 45 |
|
|---|
| 46 | /* Characters which may be used to separate multiple commands on a
|
|---|
| 47 | single line. */
|
|---|
| 48 | const char line_separator_chars[] = ";";
|
|---|
| 49 |
|
|---|
| 50 | /* Characters which are used to indicate an exponent in a floating
|
|---|
| 51 | point number. */
|
|---|
| 52 | const char EXP_CHARS[] = "eE";
|
|---|
| 53 |
|
|---|
| 54 | /* Characters which mean that a number is a floating point constant,
|
|---|
| 55 | as in 0d1.0. */
|
|---|
| 56 | const char FLT_CHARS[] = "dD";
|
|---|
| 57 | |
|---|
| 58 |
|
|---|
| 59 | const relax_typeS md_relax_table[] = {
|
|---|
| 60 | /* bCC relaxing */
|
|---|
| 61 | {0x7f, -0x80, 2, 1},
|
|---|
| 62 | {0x7fff, -0x8000, 5, 2},
|
|---|
| 63 | {0x7fffffff, -0x80000000, 7, 0},
|
|---|
| 64 |
|
|---|
| 65 | /* bCC relaxing (uncommon cases) */
|
|---|
| 66 | {0x7f, -0x80, 3, 4},
|
|---|
| 67 | {0x7fff, -0x8000, 6, 5},
|
|---|
| 68 | {0x7fffffff, -0x80000000, 8, 0},
|
|---|
| 69 |
|
|---|
| 70 | /* call relaxing */
|
|---|
| 71 | {0x7fff, -0x8000, 5, 7},
|
|---|
| 72 | {0x7fffffff, -0x80000000, 7, 0},
|
|---|
| 73 |
|
|---|
| 74 | /* calls relaxing */
|
|---|
| 75 | {0x7fff, -0x8000, 4, 9},
|
|---|
| 76 | {0x7fffffff, -0x80000000, 6, 0},
|
|---|
| 77 |
|
|---|
| 78 | /* jmp relaxing */
|
|---|
| 79 | {0x7f, -0x80, 2, 11},
|
|---|
| 80 | {0x7fff, -0x8000, 3, 12},
|
|---|
| 81 | {0x7fffffff, -0x80000000, 5, 0},
|
|---|
| 82 |
|
|---|
| 83 | };
|
|---|
| 84 |
|
|---|
| 85 | /* Local functions. */
|
|---|
| 86 | static void mn10300_insert_operand PARAMS ((unsigned long *, unsigned long *,
|
|---|
| 87 | const struct mn10300_operand *,
|
|---|
| 88 | offsetT, char *, unsigned,
|
|---|
| 89 | unsigned));
|
|---|
| 90 | static unsigned long check_operand PARAMS ((unsigned long,
|
|---|
| 91 | const struct mn10300_operand *,
|
|---|
| 92 | offsetT));
|
|---|
| 93 | static int reg_name_search PARAMS ((const struct reg_name *, int, const char *));
|
|---|
| 94 | static bfd_boolean data_register_name PARAMS ((expressionS *expressionP));
|
|---|
| 95 | static bfd_boolean address_register_name PARAMS ((expressionS *expressionP));
|
|---|
| 96 | static bfd_boolean other_register_name PARAMS ((expressionS *expressionP));
|
|---|
| 97 | static bfd_boolean r_register_name PARAMS ((expressionS *expressionP));
|
|---|
| 98 | static bfd_boolean xr_register_name PARAMS ((expressionS *expressionP));
|
|---|
| 99 | static void set_arch_mach PARAMS ((int));
|
|---|
| 100 |
|
|---|
| 101 | /* Set linkrelax here to avoid fixups in most sections. */
|
|---|
| 102 | int linkrelax = 1;
|
|---|
| 103 |
|
|---|
| 104 | static int current_machine;
|
|---|
| 105 |
|
|---|
| 106 | /* Fixups. */
|
|---|
| 107 | #define MAX_INSN_FIXUPS (5)
|
|---|
| 108 | struct mn10300_fixup
|
|---|
| 109 | {
|
|---|
| 110 | expressionS exp;
|
|---|
| 111 | int opindex;
|
|---|
| 112 | bfd_reloc_code_real_type reloc;
|
|---|
| 113 | };
|
|---|
| 114 | struct mn10300_fixup fixups[MAX_INSN_FIXUPS];
|
|---|
| 115 | static int fc;
|
|---|
| 116 |
|
|---|
| 117 | /* We must store the value of each register operand so that we can
|
|---|
| 118 | verify that certain registers do not match. */
|
|---|
| 119 | int mn10300_reg_operands[MN10300_MAX_OPERANDS];
|
|---|
| 120 | |
|---|
| 121 |
|
|---|
| 122 | const char *md_shortopts = "";
|
|---|
| 123 | struct option md_longopts[] = {
|
|---|
| 124 | {NULL, no_argument, NULL, 0}
|
|---|
| 125 | };
|
|---|
| 126 | size_t md_longopts_size = sizeof (md_longopts);
|
|---|
| 127 |
|
|---|
| 128 | /* The target specific pseudo-ops which we support. */
|
|---|
| 129 | const pseudo_typeS md_pseudo_table[] =
|
|---|
| 130 | {
|
|---|
| 131 | { "file", (void (*) PARAMS ((int))) dwarf2_directive_file, 0 },
|
|---|
| 132 | { "loc", dwarf2_directive_loc, 0 },
|
|---|
| 133 | { "am30", set_arch_mach, AM30 },
|
|---|
| 134 | { "am33", set_arch_mach, AM33 },
|
|---|
| 135 | { "mn10300", set_arch_mach, MN103 },
|
|---|
| 136 | {NULL, 0, 0}
|
|---|
| 137 | };
|
|---|
| 138 |
|
|---|
| 139 | #define HAVE_AM33 (current_machine == AM33)
|
|---|
| 140 | #define HAVE_AM30 (current_machine == AM30)
|
|---|
| 141 |
|
|---|
| 142 | /* Opcode hash table. */
|
|---|
| 143 | static struct hash_control *mn10300_hash;
|
|---|
| 144 |
|
|---|
| 145 | /* This table is sorted. Suitable for searching by a binary search. */
|
|---|
| 146 | static const struct reg_name data_registers[] =
|
|---|
| 147 | {
|
|---|
| 148 | { "d0", 0 },
|
|---|
| 149 | { "d1", 1 },
|
|---|
| 150 | { "d2", 2 },
|
|---|
| 151 | { "d3", 3 },
|
|---|
| 152 | };
|
|---|
| 153 | #define DATA_REG_NAME_CNT \
|
|---|
| 154 | (sizeof (data_registers) / sizeof (struct reg_name))
|
|---|
| 155 |
|
|---|
| 156 | static const struct reg_name address_registers[] =
|
|---|
| 157 | {
|
|---|
| 158 | { "a0", 0 },
|
|---|
| 159 | { "a1", 1 },
|
|---|
| 160 | { "a2", 2 },
|
|---|
| 161 | { "a3", 3 },
|
|---|
| 162 | };
|
|---|
| 163 |
|
|---|
| 164 | #define ADDRESS_REG_NAME_CNT \
|
|---|
| 165 | (sizeof (address_registers) / sizeof (struct reg_name))
|
|---|
| 166 |
|
|---|
| 167 | static const struct reg_name r_registers[] =
|
|---|
| 168 | {
|
|---|
| 169 | { "a0", 8 },
|
|---|
| 170 | { "a1", 9 },
|
|---|
| 171 | { "a2", 10 },
|
|---|
| 172 | { "a3", 11 },
|
|---|
| 173 | { "d0", 12 },
|
|---|
| 174 | { "d1", 13 },
|
|---|
| 175 | { "d2", 14 },
|
|---|
| 176 | { "d3", 15 },
|
|---|
| 177 | { "e0", 0 },
|
|---|
| 178 | { "e1", 1 },
|
|---|
| 179 | { "e10", 10 },
|
|---|
| 180 | { "e11", 11 },
|
|---|
| 181 | { "e12", 12 },
|
|---|
| 182 | { "e13", 13 },
|
|---|
| 183 | { "e14", 14 },
|
|---|
| 184 | { "e15", 15 },
|
|---|
| 185 | { "e2", 2 },
|
|---|
| 186 | { "e3", 3 },
|
|---|
| 187 | { "e4", 4 },
|
|---|
| 188 | { "e5", 5 },
|
|---|
| 189 | { "e6", 6 },
|
|---|
| 190 | { "e7", 7 },
|
|---|
| 191 | { "e8", 8 },
|
|---|
| 192 | { "e9", 9 },
|
|---|
| 193 | { "r0", 0 },
|
|---|
| 194 | { "r1", 1 },
|
|---|
| 195 | { "r10", 10 },
|
|---|
| 196 | { "r11", 11 },
|
|---|
| 197 | { "r12", 12 },
|
|---|
| 198 | { "r13", 13 },
|
|---|
| 199 | { "r14", 14 },
|
|---|
| 200 | { "r15", 15 },
|
|---|
| 201 | { "r2", 2 },
|
|---|
| 202 | { "r3", 3 },
|
|---|
| 203 | { "r4", 4 },
|
|---|
| 204 | { "r5", 5 },
|
|---|
| 205 | { "r6", 6 },
|
|---|
| 206 | { "r7", 7 },
|
|---|
| 207 | { "r8", 8 },
|
|---|
| 208 | { "r9", 9 },
|
|---|
| 209 | };
|
|---|
| 210 |
|
|---|
| 211 | #define R_REG_NAME_CNT \
|
|---|
| 212 | (sizeof (r_registers) / sizeof (struct reg_name))
|
|---|
| 213 |
|
|---|
| 214 | static const struct reg_name xr_registers[] =
|
|---|
| 215 | {
|
|---|
| 216 | { "mcrh", 2 },
|
|---|
| 217 | { "mcrl", 3 },
|
|---|
| 218 | { "mcvf", 4 },
|
|---|
| 219 | { "mdrq", 1 },
|
|---|
| 220 | { "sp", 0 },
|
|---|
| 221 | { "xr0", 0 },
|
|---|
| 222 | { "xr1", 1 },
|
|---|
| 223 | { "xr10", 10 },
|
|---|
| 224 | { "xr11", 11 },
|
|---|
| 225 | { "xr12", 12 },
|
|---|
| 226 | { "xr13", 13 },
|
|---|
| 227 | { "xr14", 14 },
|
|---|
| 228 | { "xr15", 15 },
|
|---|
| 229 | { "xr2", 2 },
|
|---|
| 230 | { "xr3", 3 },
|
|---|
| 231 | { "xr4", 4 },
|
|---|
| 232 | { "xr5", 5 },
|
|---|
| 233 | { "xr6", 6 },
|
|---|
| 234 | { "xr7", 7 },
|
|---|
| 235 | { "xr8", 8 },
|
|---|
| 236 | { "xr9", 9 },
|
|---|
| 237 | };
|
|---|
| 238 |
|
|---|
| 239 | #define XR_REG_NAME_CNT \
|
|---|
| 240 | (sizeof (xr_registers) / sizeof (struct reg_name))
|
|---|
| 241 |
|
|---|
| 242 | /* We abuse the `value' field, that would be otherwise unused, to
|
|---|
| 243 | encode the architecture on which (access to) the register was
|
|---|
| 244 | introduced. FIXME: we should probably warn when we encounter a
|
|---|
| 245 | register name when assembling for an architecture that doesn't
|
|---|
| 246 | support it, before parsing it as a symbol name. */
|
|---|
| 247 | static const struct reg_name other_registers[] =
|
|---|
| 248 | {
|
|---|
| 249 | { "epsw", AM33 },
|
|---|
| 250 | { "mdr", 0 },
|
|---|
| 251 | { "pc", AM33 },
|
|---|
| 252 | { "psw", 0 },
|
|---|
| 253 | { "sp", 0 },
|
|---|
| 254 | };
|
|---|
| 255 |
|
|---|
| 256 | #define OTHER_REG_NAME_CNT \
|
|---|
| 257 | (sizeof (other_registers) / sizeof (struct reg_name))
|
|---|
| 258 |
|
|---|
| 259 | /* reg_name_search does a binary search of the given register table
|
|---|
| 260 | to see if "name" is a valid regiter name. Returns the register
|
|---|
| 261 | number from the array on success, or -1 on failure. */
|
|---|
| 262 |
|
|---|
| 263 | static int
|
|---|
| 264 | reg_name_search (regs, regcount, name)
|
|---|
| 265 | const struct reg_name *regs;
|
|---|
| 266 | int regcount;
|
|---|
| 267 | const char *name;
|
|---|
| 268 | {
|
|---|
| 269 | int middle, low, high;
|
|---|
| 270 | int cmp;
|
|---|
| 271 |
|
|---|
| 272 | low = 0;
|
|---|
| 273 | high = regcount - 1;
|
|---|
| 274 |
|
|---|
| 275 | do
|
|---|
| 276 | {
|
|---|
| 277 | middle = (low + high) / 2;
|
|---|
| 278 | cmp = strcasecmp (name, regs[middle].name);
|
|---|
| 279 | if (cmp < 0)
|
|---|
| 280 | high = middle - 1;
|
|---|
| 281 | else if (cmp > 0)
|
|---|
| 282 | low = middle + 1;
|
|---|
| 283 | else
|
|---|
| 284 | return regs[middle].value;
|
|---|
| 285 | }
|
|---|
| 286 | while (low <= high);
|
|---|
| 287 | return -1;
|
|---|
| 288 | }
|
|---|
| 289 |
|
|---|
| 290 | /* Summary of register_name().
|
|---|
| 291 | *
|
|---|
| 292 | * in: Input_line_pointer points to 1st char of operand.
|
|---|
| 293 | *
|
|---|
| 294 | * out: An expressionS.
|
|---|
| 295 | * The operand may have been a register: in this case, X_op == O_register,
|
|---|
| 296 | * X_add_number is set to the register number, and truth is returned.
|
|---|
| 297 | * Input_line_pointer->(next non-blank) char after operand, or is in
|
|---|
| 298 | * its original state.
|
|---|
| 299 | */
|
|---|
| 300 |
|
|---|
| 301 | static bfd_boolean
|
|---|
| 302 | r_register_name (expressionP)
|
|---|
| 303 | expressionS *expressionP;
|
|---|
| 304 | {
|
|---|
| 305 | int reg_number;
|
|---|
| 306 | char *name;
|
|---|
| 307 | char *start;
|
|---|
| 308 | char c;
|
|---|
| 309 |
|
|---|
| 310 | /* Find the spelling of the operand. */
|
|---|
| 311 | start = name = input_line_pointer;
|
|---|
| 312 |
|
|---|
| 313 | c = get_symbol_end ();
|
|---|
| 314 | reg_number = reg_name_search (r_registers, R_REG_NAME_CNT, name);
|
|---|
| 315 |
|
|---|
| 316 | /* Put back the delimiting char. */
|
|---|
| 317 | *input_line_pointer = c;
|
|---|
| 318 |
|
|---|
| 319 | /* Look to see if it's in the register table. */
|
|---|
| 320 | if (reg_number >= 0)
|
|---|
| 321 | {
|
|---|
| 322 | expressionP->X_op = O_register;
|
|---|
| 323 | expressionP->X_add_number = reg_number;
|
|---|
| 324 |
|
|---|
| 325 | /* Make the rest nice. */
|
|---|
| 326 | expressionP->X_add_symbol = NULL;
|
|---|
| 327 | expressionP->X_op_symbol = NULL;
|
|---|
| 328 |
|
|---|
| 329 | return TRUE;
|
|---|
| 330 | }
|
|---|
| 331 |
|
|---|
| 332 | /* Reset the line as if we had not done anything. */
|
|---|
| 333 | input_line_pointer = start;
|
|---|
| 334 | return FALSE;
|
|---|
| 335 | }
|
|---|
| 336 |
|
|---|
| 337 | /* Summary of register_name().
|
|---|
| 338 | *
|
|---|
| 339 | * in: Input_line_pointer points to 1st char of operand.
|
|---|
| 340 | *
|
|---|
| 341 | * out: An expressionS.
|
|---|
| 342 | * The operand may have been a register: in this case, X_op == O_register,
|
|---|
| 343 | * X_add_number is set to the register number, and truth is returned.
|
|---|
| 344 | * Input_line_pointer->(next non-blank) char after operand, or is in
|
|---|
| 345 | * its original state.
|
|---|
| 346 | */
|
|---|
| 347 |
|
|---|
| 348 | static bfd_boolean
|
|---|
| 349 | xr_register_name (expressionP)
|
|---|
| 350 | expressionS *expressionP;
|
|---|
| 351 | {
|
|---|
| 352 | int reg_number;
|
|---|
| 353 | char *name;
|
|---|
| 354 | char *start;
|
|---|
| 355 | char c;
|
|---|
| 356 |
|
|---|
| 357 | /* Find the spelling of the operand. */
|
|---|
| 358 | start = name = input_line_pointer;
|
|---|
| 359 |
|
|---|
| 360 | c = get_symbol_end ();
|
|---|
| 361 | reg_number = reg_name_search (xr_registers, XR_REG_NAME_CNT, name);
|
|---|
| 362 |
|
|---|
| 363 | /* Put back the delimiting char. */
|
|---|
| 364 | *input_line_pointer = c;
|
|---|
| 365 |
|
|---|
| 366 | /* Look to see if it's in the register table. */
|
|---|
| 367 | if (reg_number >= 0)
|
|---|
| 368 | {
|
|---|
| 369 | expressionP->X_op = O_register;
|
|---|
| 370 | expressionP->X_add_number = reg_number;
|
|---|
| 371 |
|
|---|
| 372 | /* Make the rest nice. */
|
|---|
| 373 | expressionP->X_add_symbol = NULL;
|
|---|
| 374 | expressionP->X_op_symbol = NULL;
|
|---|
| 375 |
|
|---|
| 376 | return TRUE;
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | /* Reset the line as if we had not done anything. */
|
|---|
| 380 | input_line_pointer = start;
|
|---|
| 381 | return FALSE;
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | /* Summary of register_name().
|
|---|
| 385 | *
|
|---|
| 386 | * in: Input_line_pointer points to 1st char of operand.
|
|---|
| 387 | *
|
|---|
| 388 | * out: An expressionS.
|
|---|
| 389 | * The operand may have been a register: in this case, X_op == O_register,
|
|---|
| 390 | * X_add_number is set to the register number, and truth is returned.
|
|---|
| 391 | * Input_line_pointer->(next non-blank) char after operand, or is in
|
|---|
| 392 | * its original state.
|
|---|
| 393 | */
|
|---|
| 394 |
|
|---|
| 395 | static bfd_boolean
|
|---|
| 396 | data_register_name (expressionP)
|
|---|
| 397 | expressionS *expressionP;
|
|---|
| 398 | {
|
|---|
| 399 | int reg_number;
|
|---|
| 400 | char *name;
|
|---|
| 401 | char *start;
|
|---|
| 402 | char c;
|
|---|
| 403 |
|
|---|
| 404 | /* Find the spelling of the operand. */
|
|---|
| 405 | start = name = input_line_pointer;
|
|---|
| 406 |
|
|---|
| 407 | c = get_symbol_end ();
|
|---|
| 408 | reg_number = reg_name_search (data_registers, DATA_REG_NAME_CNT, name);
|
|---|
| 409 |
|
|---|
| 410 | /* Put back the delimiting char. */
|
|---|
| 411 | *input_line_pointer = c;
|
|---|
| 412 |
|
|---|
| 413 | /* Look to see if it's in the register table. */
|
|---|
| 414 | if (reg_number >= 0)
|
|---|
| 415 | {
|
|---|
| 416 | expressionP->X_op = O_register;
|
|---|
| 417 | expressionP->X_add_number = reg_number;
|
|---|
| 418 |
|
|---|
| 419 | /* Make the rest nice. */
|
|---|
| 420 | expressionP->X_add_symbol = NULL;
|
|---|
| 421 | expressionP->X_op_symbol = NULL;
|
|---|
| 422 |
|
|---|
| 423 | return TRUE;
|
|---|
| 424 | }
|
|---|
| 425 |
|
|---|
| 426 | /* Reset the line as if we had not done anything. */
|
|---|
| 427 | input_line_pointer = start;
|
|---|
| 428 | return FALSE;
|
|---|
| 429 | }
|
|---|
| 430 |
|
|---|
| 431 | /* Summary of register_name().
|
|---|
| 432 | *
|
|---|
| 433 | * in: Input_line_pointer points to 1st char of operand.
|
|---|
| 434 | *
|
|---|
| 435 | * out: An expressionS.
|
|---|
| 436 | * The operand may have been a register: in this case, X_op == O_register,
|
|---|
| 437 | * X_add_number is set to the register number, and truth is returned.
|
|---|
| 438 | * Input_line_pointer->(next non-blank) char after operand, or is in
|
|---|
| 439 | * its original state.
|
|---|
| 440 | */
|
|---|
| 441 |
|
|---|
| 442 | static bfd_boolean
|
|---|
| 443 | address_register_name (expressionP)
|
|---|
| 444 | expressionS *expressionP;
|
|---|
| 445 | {
|
|---|
| 446 | int reg_number;
|
|---|
| 447 | char *name;
|
|---|
| 448 | char *start;
|
|---|
| 449 | char c;
|
|---|
| 450 |
|
|---|
| 451 | /* Find the spelling of the operand. */
|
|---|
| 452 | start = name = input_line_pointer;
|
|---|
| 453 |
|
|---|
| 454 | c = get_symbol_end ();
|
|---|
| 455 | reg_number = reg_name_search (address_registers, ADDRESS_REG_NAME_CNT, name);
|
|---|
| 456 |
|
|---|
| 457 | /* Put back the delimiting char. */
|
|---|
| 458 | *input_line_pointer = c;
|
|---|
| 459 |
|
|---|
| 460 | /* Look to see if it's in the register table. */
|
|---|
| 461 | if (reg_number >= 0)
|
|---|
| 462 | {
|
|---|
| 463 | expressionP->X_op = O_register;
|
|---|
| 464 | expressionP->X_add_number = reg_number;
|
|---|
| 465 |
|
|---|
| 466 | /* Make the rest nice. */
|
|---|
| 467 | expressionP->X_add_symbol = NULL;
|
|---|
| 468 | expressionP->X_op_symbol = NULL;
|
|---|
| 469 |
|
|---|
| 470 | return TRUE;
|
|---|
| 471 | }
|
|---|
| 472 |
|
|---|
| 473 | /* Reset the line as if we had not done anything. */
|
|---|
| 474 | input_line_pointer = start;
|
|---|
| 475 | return FALSE;
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | /* Summary of register_name().
|
|---|
| 479 | *
|
|---|
| 480 | * in: Input_line_pointer points to 1st char of operand.
|
|---|
| 481 | *
|
|---|
| 482 | * out: An expressionS.
|
|---|
| 483 | * The operand may have been a register: in this case, X_op == O_register,
|
|---|
| 484 | * X_add_number is set to the register number, and truth is returned.
|
|---|
| 485 | * Input_line_pointer->(next non-blank) char after operand, or is in
|
|---|
| 486 | * its original state.
|
|---|
| 487 | */
|
|---|
| 488 |
|
|---|
| 489 | static bfd_boolean
|
|---|
| 490 | other_register_name (expressionP)
|
|---|
| 491 | expressionS *expressionP;
|
|---|
| 492 | {
|
|---|
| 493 | int reg_number;
|
|---|
| 494 | char *name;
|
|---|
| 495 | char *start;
|
|---|
| 496 | char c;
|
|---|
| 497 |
|
|---|
| 498 | /* Find the spelling of the operand. */
|
|---|
| 499 | start = name = input_line_pointer;
|
|---|
| 500 |
|
|---|
| 501 | c = get_symbol_end ();
|
|---|
| 502 | reg_number = reg_name_search (other_registers, OTHER_REG_NAME_CNT, name);
|
|---|
| 503 |
|
|---|
| 504 | /* Put back the delimiting char. */
|
|---|
| 505 | *input_line_pointer = c;
|
|---|
| 506 |
|
|---|
| 507 | /* Look to see if it's in the register table. */
|
|---|
| 508 | if (reg_number == 0
|
|---|
| 509 | || (reg_number == AM33 && HAVE_AM33))
|
|---|
| 510 | {
|
|---|
| 511 | expressionP->X_op = O_register;
|
|---|
| 512 | expressionP->X_add_number = 0;
|
|---|
| 513 |
|
|---|
| 514 | /* Make the rest nice. */
|
|---|
| 515 | expressionP->X_add_symbol = NULL;
|
|---|
| 516 | expressionP->X_op_symbol = NULL;
|
|---|
| 517 |
|
|---|
| 518 | return TRUE;
|
|---|
| 519 | }
|
|---|
| 520 |
|
|---|
| 521 | /* Reset the line as if we had not done anything. */
|
|---|
| 522 | input_line_pointer = start;
|
|---|
| 523 | return FALSE;
|
|---|
| 524 | }
|
|---|
| 525 |
|
|---|
| 526 | void
|
|---|
| 527 | md_show_usage (stream)
|
|---|
| 528 | FILE *stream;
|
|---|
| 529 | {
|
|---|
| 530 | fprintf (stream, _("MN10300 options:\n\
|
|---|
| 531 | none yet\n"));
|
|---|
| 532 | }
|
|---|
| 533 |
|
|---|
| 534 | int
|
|---|
| 535 | md_parse_option (c, arg)
|
|---|
| 536 | int c ATTRIBUTE_UNUSED;
|
|---|
| 537 | char *arg ATTRIBUTE_UNUSED;
|
|---|
| 538 | {
|
|---|
| 539 | return 0;
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | symbolS *
|
|---|
| 543 | md_undefined_symbol (name)
|
|---|
| 544 | char *name ATTRIBUTE_UNUSED;
|
|---|
| 545 | {
|
|---|
| 546 | return 0;
|
|---|
| 547 | }
|
|---|
| 548 |
|
|---|
| 549 | char *
|
|---|
| 550 | md_atof (type, litp, sizep)
|
|---|
| 551 | int type;
|
|---|
| 552 | char *litp;
|
|---|
| 553 | int *sizep;
|
|---|
| 554 | {
|
|---|
| 555 | int prec;
|
|---|
| 556 | LITTLENUM_TYPE words[4];
|
|---|
| 557 | char *t;
|
|---|
| 558 | int i;
|
|---|
| 559 |
|
|---|
| 560 | switch (type)
|
|---|
| 561 | {
|
|---|
| 562 | case 'f':
|
|---|
| 563 | prec = 2;
|
|---|
| 564 | break;
|
|---|
| 565 |
|
|---|
| 566 | case 'd':
|
|---|
| 567 | prec = 4;
|
|---|
| 568 | break;
|
|---|
| 569 |
|
|---|
| 570 | default:
|
|---|
| 571 | *sizep = 0;
|
|---|
| 572 | return "bad call to md_atof";
|
|---|
| 573 | }
|
|---|
| 574 |
|
|---|
| 575 | t = atof_ieee (input_line_pointer, type, words);
|
|---|
| 576 | if (t)
|
|---|
| 577 | input_line_pointer = t;
|
|---|
| 578 |
|
|---|
| 579 | *sizep = prec * 2;
|
|---|
| 580 |
|
|---|
| 581 | for (i = prec - 1; i >= 0; i--)
|
|---|
| 582 | {
|
|---|
| 583 | md_number_to_chars (litp, (valueT) words[i], 2);
|
|---|
| 584 | litp += 2;
|
|---|
| 585 | }
|
|---|
| 586 |
|
|---|
| 587 | return NULL;
|
|---|
| 588 | }
|
|---|
| 589 |
|
|---|
| 590 | void
|
|---|
| 591 | md_convert_frag (abfd, sec, fragP)
|
|---|
| 592 | bfd *abfd ATTRIBUTE_UNUSED;
|
|---|
| 593 | asection *sec;
|
|---|
| 594 | fragS *fragP;
|
|---|
| 595 | {
|
|---|
| 596 | static unsigned long label_count = 0;
|
|---|
| 597 | char buf[40];
|
|---|
| 598 |
|
|---|
| 599 | subseg_change (sec, 0);
|
|---|
| 600 | if (fragP->fr_subtype == 0)
|
|---|
| 601 | {
|
|---|
| 602 | fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
|
|---|
| 603 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
|
|---|
| 604 | fragP->fr_var = 0;
|
|---|
| 605 | fragP->fr_fix += 2;
|
|---|
| 606 | }
|
|---|
| 607 | else if (fragP->fr_subtype == 1)
|
|---|
| 608 | {
|
|---|
| 609 | /* Reverse the condition of the first branch. */
|
|---|
| 610 | int offset = fragP->fr_fix;
|
|---|
| 611 | int opcode = fragP->fr_literal[offset] & 0xff;
|
|---|
| 612 |
|
|---|
| 613 | switch (opcode)
|
|---|
| 614 | {
|
|---|
| 615 | case 0xc8:
|
|---|
| 616 | opcode = 0xc9;
|
|---|
| 617 | break;
|
|---|
| 618 | case 0xc9:
|
|---|
| 619 | opcode = 0xc8;
|
|---|
| 620 | break;
|
|---|
| 621 | case 0xc0:
|
|---|
| 622 | opcode = 0xc2;
|
|---|
| 623 | break;
|
|---|
| 624 | case 0xc2:
|
|---|
| 625 | opcode = 0xc0;
|
|---|
| 626 | break;
|
|---|
| 627 | case 0xc3:
|
|---|
| 628 | opcode = 0xc1;
|
|---|
| 629 | break;
|
|---|
| 630 | case 0xc1:
|
|---|
| 631 | opcode = 0xc3;
|
|---|
| 632 | break;
|
|---|
| 633 | case 0xc4:
|
|---|
| 634 | opcode = 0xc6;
|
|---|
| 635 | break;
|
|---|
| 636 | case 0xc6:
|
|---|
| 637 | opcode = 0xc4;
|
|---|
| 638 | break;
|
|---|
| 639 | case 0xc7:
|
|---|
| 640 | opcode = 0xc5;
|
|---|
| 641 | break;
|
|---|
| 642 | case 0xc5:
|
|---|
| 643 | opcode = 0xc7;
|
|---|
| 644 | break;
|
|---|
| 645 | default:
|
|---|
| 646 | abort ();
|
|---|
| 647 | }
|
|---|
| 648 | fragP->fr_literal[offset] = opcode;
|
|---|
| 649 |
|
|---|
| 650 | /* Create a fixup for the reversed conditional branch. */
|
|---|
| 651 | sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
|
|---|
| 652 | fix_new (fragP, fragP->fr_fix + 1, 1,
|
|---|
| 653 | symbol_new (buf, sec, 0, fragP->fr_next),
|
|---|
| 654 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
|
|---|
| 655 |
|
|---|
| 656 | /* Now create the unconditional branch + fixup to the
|
|---|
| 657 | final target. */
|
|---|
| 658 | fragP->fr_literal[offset + 2] = 0xcc;
|
|---|
| 659 | fix_new (fragP, fragP->fr_fix + 3, 2, fragP->fr_symbol,
|
|---|
| 660 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
|
|---|
| 661 | fragP->fr_var = 0;
|
|---|
| 662 | fragP->fr_fix += 5;
|
|---|
| 663 | }
|
|---|
| 664 | else if (fragP->fr_subtype == 2)
|
|---|
| 665 | {
|
|---|
| 666 | /* Reverse the condition of the first branch. */
|
|---|
| 667 | int offset = fragP->fr_fix;
|
|---|
| 668 | int opcode = fragP->fr_literal[offset] & 0xff;
|
|---|
| 669 |
|
|---|
| 670 | switch (opcode)
|
|---|
| 671 | {
|
|---|
| 672 | case 0xc8:
|
|---|
| 673 | opcode = 0xc9;
|
|---|
| 674 | break;
|
|---|
| 675 | case 0xc9:
|
|---|
| 676 | opcode = 0xc8;
|
|---|
| 677 | break;
|
|---|
| 678 | case 0xc0:
|
|---|
| 679 | opcode = 0xc2;
|
|---|
| 680 | break;
|
|---|
| 681 | case 0xc2:
|
|---|
| 682 | opcode = 0xc0;
|
|---|
| 683 | break;
|
|---|
| 684 | case 0xc3:
|
|---|
| 685 | opcode = 0xc1;
|
|---|
| 686 | break;
|
|---|
| 687 | case 0xc1:
|
|---|
| 688 | opcode = 0xc3;
|
|---|
| 689 | break;
|
|---|
| 690 | case 0xc4:
|
|---|
| 691 | opcode = 0xc6;
|
|---|
| 692 | break;
|
|---|
| 693 | case 0xc6:
|
|---|
| 694 | opcode = 0xc4;
|
|---|
| 695 | break;
|
|---|
| 696 | case 0xc7:
|
|---|
| 697 | opcode = 0xc5;
|
|---|
| 698 | break;
|
|---|
| 699 | case 0xc5:
|
|---|
| 700 | opcode = 0xc7;
|
|---|
| 701 | break;
|
|---|
| 702 | default:
|
|---|
| 703 | abort ();
|
|---|
| 704 | }
|
|---|
| 705 | fragP->fr_literal[offset] = opcode;
|
|---|
| 706 |
|
|---|
| 707 | /* Create a fixup for the reversed conditional branch. */
|
|---|
| 708 | sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
|
|---|
| 709 | fix_new (fragP, fragP->fr_fix + 1, 1,
|
|---|
| 710 | symbol_new (buf, sec, 0, fragP->fr_next),
|
|---|
| 711 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
|
|---|
| 712 |
|
|---|
| 713 | /* Now create the unconditional branch + fixup to the
|
|---|
| 714 | final target. */
|
|---|
| 715 | fragP->fr_literal[offset + 2] = 0xdc;
|
|---|
| 716 | fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
|
|---|
| 717 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
|
|---|
| 718 | fragP->fr_var = 0;
|
|---|
| 719 | fragP->fr_fix += 7;
|
|---|
| 720 | }
|
|---|
| 721 | else if (fragP->fr_subtype == 3)
|
|---|
| 722 | {
|
|---|
| 723 | fix_new (fragP, fragP->fr_fix + 2, 1, fragP->fr_symbol,
|
|---|
| 724 | fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
|
|---|
| 725 | fragP->fr_var = 0;
|
|---|
| 726 | fragP->fr_fix += 3;
|
|---|
| 727 | }
|
|---|
| 728 | else if (fragP->fr_subtype == 4)
|
|---|
| 729 | {
|
|---|
| 730 | /* Reverse the condition of the first branch. */
|
|---|
| 731 | int offset = fragP->fr_fix;
|
|---|
| 732 | int opcode = fragP->fr_literal[offset + 1] & 0xff;
|
|---|
| 733 |
|
|---|
| 734 | switch (opcode)
|
|---|
| 735 | {
|
|---|
| 736 | case 0xe8:
|
|---|
| 737 | opcode = 0xe9;
|
|---|
| 738 | break;
|
|---|
| 739 | case 0xe9:
|
|---|
| 740 | opcode = 0xe8;
|
|---|
| 741 | break;
|
|---|
| 742 | case 0xea:
|
|---|
| 743 | opcode = 0xeb;
|
|---|
| 744 | break;
|
|---|
| 745 | case 0xeb:
|
|---|
| 746 | opcode = 0xea;
|
|---|
| 747 | break;
|
|---|
| 748 | default:
|
|---|
| 749 | abort ();
|
|---|
| 750 | }
|
|---|
| 751 | fragP->fr_literal[offset + 1] = opcode;
|
|---|
| 752 |
|
|---|
| 753 | /* Create a fixup for the reversed conditional branch. */
|
|---|
| 754 | sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
|
|---|
| 755 | fix_new (fragP, fragP->fr_fix + 2, 1,
|
|---|
| 756 | symbol_new (buf, sec, 0, fragP->fr_next),
|
|---|
| 757 | fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
|
|---|
| 758 |
|
|---|
| 759 | /* Now create the unconditional branch + fixup to the
|
|---|
| 760 | final target. */
|
|---|
| 761 | fragP->fr_literal[offset + 3] = 0xcc;
|
|---|
| 762 | fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
|
|---|
| 763 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
|
|---|
| 764 | fragP->fr_var = 0;
|
|---|
| 765 | fragP->fr_fix += 6;
|
|---|
| 766 | }
|
|---|
| 767 | else if (fragP->fr_subtype == 5)
|
|---|
| 768 | {
|
|---|
| 769 | /* Reverse the condition of the first branch. */
|
|---|
| 770 | int offset = fragP->fr_fix;
|
|---|
| 771 | int opcode = fragP->fr_literal[offset + 1] & 0xff;
|
|---|
| 772 |
|
|---|
| 773 | switch (opcode)
|
|---|
| 774 | {
|
|---|
| 775 | case 0xe8:
|
|---|
| 776 | opcode = 0xe9;
|
|---|
| 777 | break;
|
|---|
| 778 | case 0xea:
|
|---|
| 779 | opcode = 0xeb;
|
|---|
| 780 | break;
|
|---|
| 781 | case 0xeb:
|
|---|
| 782 | opcode = 0xea;
|
|---|
| 783 | break;
|
|---|
| 784 | default:
|
|---|
| 785 | abort ();
|
|---|
| 786 | }
|
|---|
| 787 | fragP->fr_literal[offset + 1] = opcode;
|
|---|
| 788 |
|
|---|
| 789 | /* Create a fixup for the reversed conditional branch. */
|
|---|
| 790 | sprintf (buf, ".%s_%ld", FAKE_LABEL_NAME, label_count++);
|
|---|
| 791 | fix_new (fragP, fragP->fr_fix + 2, 1,
|
|---|
| 792 | symbol_new (buf, sec, 0, fragP->fr_next),
|
|---|
| 793 | fragP->fr_offset + 2, 1, BFD_RELOC_8_PCREL);
|
|---|
| 794 |
|
|---|
| 795 | /* Now create the unconditional branch + fixup to the
|
|---|
| 796 | final target. */
|
|---|
| 797 | fragP->fr_literal[offset + 3] = 0xdc;
|
|---|
| 798 | fix_new (fragP, fragP->fr_fix + 4, 4, fragP->fr_symbol,
|
|---|
| 799 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
|
|---|
| 800 | fragP->fr_var = 0;
|
|---|
| 801 | fragP->fr_fix += 8;
|
|---|
| 802 | }
|
|---|
| 803 | else if (fragP->fr_subtype == 6)
|
|---|
| 804 | {
|
|---|
| 805 | int offset = fragP->fr_fix;
|
|---|
| 806 | fragP->fr_literal[offset] = 0xcd;
|
|---|
| 807 | fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
|
|---|
| 808 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
|
|---|
| 809 | fragP->fr_var = 0;
|
|---|
| 810 | fragP->fr_fix += 5;
|
|---|
| 811 | }
|
|---|
| 812 | else if (fragP->fr_subtype == 7)
|
|---|
| 813 | {
|
|---|
| 814 | int offset = fragP->fr_fix;
|
|---|
| 815 | fragP->fr_literal[offset] = 0xdd;
|
|---|
| 816 | fragP->fr_literal[offset + 5] = fragP->fr_literal[offset + 3];
|
|---|
| 817 | fragP->fr_literal[offset + 6] = fragP->fr_literal[offset + 4];
|
|---|
| 818 |
|
|---|
| 819 | fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
|
|---|
| 820 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
|
|---|
| 821 | fragP->fr_var = 0;
|
|---|
| 822 | fragP->fr_fix += 7;
|
|---|
| 823 | }
|
|---|
| 824 | else if (fragP->fr_subtype == 8)
|
|---|
| 825 | {
|
|---|
| 826 | int offset = fragP->fr_fix;
|
|---|
| 827 | fragP->fr_literal[offset] = 0xfa;
|
|---|
| 828 | fragP->fr_literal[offset + 1] = 0xff;
|
|---|
| 829 | fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
|
|---|
| 830 | fragP->fr_offset + 2, 1, BFD_RELOC_16_PCREL);
|
|---|
| 831 | fragP->fr_var = 0;
|
|---|
| 832 | fragP->fr_fix += 4;
|
|---|
| 833 | }
|
|---|
| 834 | else if (fragP->fr_subtype == 9)
|
|---|
| 835 | {
|
|---|
| 836 | int offset = fragP->fr_fix;
|
|---|
| 837 | fragP->fr_literal[offset] = 0xfc;
|
|---|
| 838 | fragP->fr_literal[offset + 1] = 0xff;
|
|---|
| 839 |
|
|---|
| 840 | fix_new (fragP, fragP->fr_fix + 2, 4, fragP->fr_symbol,
|
|---|
| 841 | fragP->fr_offset + 2, 1, BFD_RELOC_32_PCREL);
|
|---|
| 842 | fragP->fr_var = 0;
|
|---|
| 843 | fragP->fr_fix += 6;
|
|---|
| 844 | }
|
|---|
| 845 | else if (fragP->fr_subtype == 10)
|
|---|
| 846 | {
|
|---|
| 847 | fragP->fr_literal[fragP->fr_fix] = 0xca;
|
|---|
| 848 | fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
|
|---|
| 849 | fragP->fr_offset + 1, 1, BFD_RELOC_8_PCREL);
|
|---|
| 850 | fragP->fr_var = 0;
|
|---|
| 851 | fragP->fr_fix += 2;
|
|---|
| 852 | }
|
|---|
| 853 | else if (fragP->fr_subtype == 11)
|
|---|
| 854 | {
|
|---|
| 855 | int offset = fragP->fr_fix;
|
|---|
| 856 | fragP->fr_literal[offset] = 0xcc;
|
|---|
| 857 |
|
|---|
| 858 | fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
|
|---|
| 859 | fragP->fr_offset + 1, 1, BFD_RELOC_16_PCREL);
|
|---|
| 860 | fragP->fr_var = 0;
|
|---|
| 861 | fragP->fr_fix += 3;
|
|---|
| 862 | }
|
|---|
| 863 | else if (fragP->fr_subtype == 12)
|
|---|
| 864 | {
|
|---|
| 865 | int offset = fragP->fr_fix;
|
|---|
| 866 | fragP->fr_literal[offset] = 0xdc;
|
|---|
| 867 |
|
|---|
| 868 | fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
|
|---|
| 869 | fragP->fr_offset + 1, 1, BFD_RELOC_32_PCREL);
|
|---|
| 870 | fragP->fr_var = 0;
|
|---|
| 871 | fragP->fr_fix += 5;
|
|---|
| 872 | }
|
|---|
| 873 | else
|
|---|
| 874 | abort ();
|
|---|
| 875 | }
|
|---|
| 876 |
|
|---|
| 877 | valueT
|
|---|
| 878 | md_section_align (seg, addr)
|
|---|
| 879 | asection *seg;
|
|---|
| 880 | valueT addr;
|
|---|
| 881 | {
|
|---|
| 882 | int align = bfd_get_section_alignment (stdoutput, seg);
|
|---|
| 883 | return ((addr + (1 << align) - 1) & (-1 << align));
|
|---|
| 884 | }
|
|---|
| 885 |
|
|---|
| 886 | void
|
|---|
| 887 | md_begin ()
|
|---|
| 888 | {
|
|---|
| 889 | char *prev_name = "";
|
|---|
| 890 | register const struct mn10300_opcode *op;
|
|---|
| 891 |
|
|---|
| 892 | mn10300_hash = hash_new ();
|
|---|
| 893 |
|
|---|
| 894 | /* Insert unique names into hash table. The MN10300 instruction set
|
|---|
| 895 | has many identical opcode names that have different opcodes based
|
|---|
| 896 | on the operands. This hash table then provides a quick index to
|
|---|
| 897 | the first opcode with a particular name in the opcode table. */
|
|---|
| 898 |
|
|---|
| 899 | op = mn10300_opcodes;
|
|---|
| 900 | while (op->name)
|
|---|
| 901 | {
|
|---|
| 902 | if (strcmp (prev_name, op->name))
|
|---|
| 903 | {
|
|---|
| 904 | prev_name = (char *) op->name;
|
|---|
| 905 | hash_insert (mn10300_hash, op->name, (char *) op);
|
|---|
| 906 | }
|
|---|
| 907 | op++;
|
|---|
| 908 | }
|
|---|
| 909 |
|
|---|
| 910 | /* Set the default machine type. */
|
|---|
| 911 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, MN103))
|
|---|
| 912 | as_warn (_("could not set architecture and machine"));
|
|---|
| 913 |
|
|---|
| 914 | current_machine = MN103;
|
|---|
| 915 | }
|
|---|
| 916 |
|
|---|
| 917 | void
|
|---|
| 918 | md_assemble (str)
|
|---|
| 919 | char *str;
|
|---|
| 920 | {
|
|---|
| 921 | char *s;
|
|---|
| 922 | struct mn10300_opcode *opcode;
|
|---|
| 923 | struct mn10300_opcode *next_opcode;
|
|---|
| 924 | const unsigned char *opindex_ptr;
|
|---|
| 925 | int next_opindex, relaxable;
|
|---|
| 926 | unsigned long insn, extension, size = 0;
|
|---|
| 927 | char *f;
|
|---|
| 928 | int i;
|
|---|
| 929 | int match;
|
|---|
| 930 |
|
|---|
| 931 | /* Get the opcode. */
|
|---|
| 932 | for (s = str; *s != '\0' && !ISSPACE (*s); s++)
|
|---|
| 933 | ;
|
|---|
| 934 | if (*s != '\0')
|
|---|
| 935 | *s++ = '\0';
|
|---|
| 936 |
|
|---|
| 937 | /* Find the first opcode with the proper name. */
|
|---|
| 938 | opcode = (struct mn10300_opcode *) hash_find (mn10300_hash, str);
|
|---|
| 939 | if (opcode == NULL)
|
|---|
| 940 | {
|
|---|
| 941 | as_bad (_("Unrecognized opcode: `%s'"), str);
|
|---|
| 942 | return;
|
|---|
| 943 | }
|
|---|
| 944 |
|
|---|
| 945 | str = s;
|
|---|
| 946 | while (ISSPACE (*str))
|
|---|
| 947 | ++str;
|
|---|
| 948 |
|
|---|
| 949 | input_line_pointer = str;
|
|---|
| 950 |
|
|---|
| 951 | for (;;)
|
|---|
| 952 | {
|
|---|
| 953 | const char *errmsg;
|
|---|
| 954 | int op_idx;
|
|---|
| 955 | char *hold;
|
|---|
| 956 | int extra_shift = 0;
|
|---|
| 957 |
|
|---|
| 958 | errmsg = _("Invalid opcode/operands");
|
|---|
| 959 |
|
|---|
| 960 | /* Reset the array of register operands. */
|
|---|
| 961 | memset (mn10300_reg_operands, -1, sizeof (mn10300_reg_operands));
|
|---|
| 962 |
|
|---|
| 963 | relaxable = 0;
|
|---|
| 964 | fc = 0;
|
|---|
| 965 | match = 0;
|
|---|
| 966 | next_opindex = 0;
|
|---|
| 967 | insn = opcode->opcode;
|
|---|
| 968 | extension = 0;
|
|---|
| 969 |
|
|---|
| 970 | /* If the instruction is not available on the current machine
|
|---|
| 971 | then it can not possibly match. */
|
|---|
| 972 | if (opcode->machine
|
|---|
| 973 | && !(opcode->machine == AM33 && HAVE_AM33)
|
|---|
| 974 | && !(opcode->machine == AM30 && HAVE_AM30))
|
|---|
| 975 | goto error;
|
|---|
| 976 |
|
|---|
| 977 | for (op_idx = 1, opindex_ptr = opcode->operands;
|
|---|
| 978 | *opindex_ptr != 0;
|
|---|
| 979 | opindex_ptr++, op_idx++)
|
|---|
| 980 | {
|
|---|
| 981 | const struct mn10300_operand *operand;
|
|---|
| 982 | expressionS ex;
|
|---|
| 983 |
|
|---|
| 984 | if (next_opindex == 0)
|
|---|
| 985 | {
|
|---|
| 986 | operand = &mn10300_operands[*opindex_ptr];
|
|---|
| 987 | }
|
|---|
| 988 | else
|
|---|
| 989 | {
|
|---|
| 990 | operand = &mn10300_operands[next_opindex];
|
|---|
| 991 | next_opindex = 0;
|
|---|
| 992 | }
|
|---|
| 993 |
|
|---|
| 994 | while (*str == ' ' || *str == ',')
|
|---|
| 995 | ++str;
|
|---|
| 996 |
|
|---|
| 997 | if (operand->flags & MN10300_OPERAND_RELAX)
|
|---|
| 998 | relaxable = 1;
|
|---|
| 999 |
|
|---|
| 1000 | /* Gather the operand. */
|
|---|
| 1001 | hold = input_line_pointer;
|
|---|
| 1002 | input_line_pointer = str;
|
|---|
| 1003 |
|
|---|
| 1004 | if (operand->flags & MN10300_OPERAND_PAREN)
|
|---|
| 1005 | {
|
|---|
| 1006 | if (*input_line_pointer != ')' && *input_line_pointer != '(')
|
|---|
| 1007 | {
|
|---|
| 1008 | input_line_pointer = hold;
|
|---|
| 1009 | str = hold;
|
|---|
| 1010 | goto error;
|
|---|
| 1011 | }
|
|---|
| 1012 | input_line_pointer++;
|
|---|
| 1013 | goto keep_going;
|
|---|
| 1014 | }
|
|---|
| 1015 | /* See if we can match the operands. */
|
|---|
| 1016 | else if (operand->flags & MN10300_OPERAND_DREG)
|
|---|
| 1017 | {
|
|---|
| 1018 | if (!data_register_name (&ex))
|
|---|
| 1019 | {
|
|---|
| 1020 | input_line_pointer = hold;
|
|---|
| 1021 | str = hold;
|
|---|
| 1022 | goto error;
|
|---|
| 1023 | }
|
|---|
| 1024 | }
|
|---|
| 1025 | else if (operand->flags & MN10300_OPERAND_AREG)
|
|---|
| 1026 | {
|
|---|
| 1027 | if (!address_register_name (&ex))
|
|---|
| 1028 | {
|
|---|
| 1029 | input_line_pointer = hold;
|
|---|
| 1030 | str = hold;
|
|---|
| 1031 | goto error;
|
|---|
| 1032 | }
|
|---|
| 1033 | }
|
|---|
| 1034 | else if (operand->flags & MN10300_OPERAND_SP)
|
|---|
| 1035 | {
|
|---|
| 1036 | char *start = input_line_pointer;
|
|---|
| 1037 | char c = get_symbol_end ();
|
|---|
| 1038 |
|
|---|
| 1039 | if (strcasecmp (start, "sp") != 0)
|
|---|
| 1040 | {
|
|---|
| 1041 | *input_line_pointer = c;
|
|---|
| 1042 | input_line_pointer = hold;
|
|---|
| 1043 | str = hold;
|
|---|
| 1044 | goto error;
|
|---|
| 1045 | }
|
|---|
| 1046 | *input_line_pointer = c;
|
|---|
| 1047 | goto keep_going;
|
|---|
| 1048 | }
|
|---|
| 1049 | else if (operand->flags & MN10300_OPERAND_RREG)
|
|---|
| 1050 | {
|
|---|
| 1051 | if (!r_register_name (&ex))
|
|---|
| 1052 | {
|
|---|
| 1053 | input_line_pointer = hold;
|
|---|
| 1054 | str = hold;
|
|---|
| 1055 | goto error;
|
|---|
| 1056 | }
|
|---|
| 1057 | }
|
|---|
| 1058 | else if (operand->flags & MN10300_OPERAND_XRREG)
|
|---|
| 1059 | {
|
|---|
| 1060 | if (!xr_register_name (&ex))
|
|---|
| 1061 | {
|
|---|
| 1062 | input_line_pointer = hold;
|
|---|
| 1063 | str = hold;
|
|---|
| 1064 | goto error;
|
|---|
| 1065 | }
|
|---|
| 1066 | }
|
|---|
| 1067 | else if (operand->flags & MN10300_OPERAND_USP)
|
|---|
| 1068 | {
|
|---|
| 1069 | char *start = input_line_pointer;
|
|---|
| 1070 | char c = get_symbol_end ();
|
|---|
| 1071 |
|
|---|
| 1072 | if (strcasecmp (start, "usp") != 0)
|
|---|
| 1073 | {
|
|---|
| 1074 | *input_line_pointer = c;
|
|---|
| 1075 | input_line_pointer = hold;
|
|---|
| 1076 | str = hold;
|
|---|
| 1077 | goto error;
|
|---|
| 1078 | }
|
|---|
| 1079 | *input_line_pointer = c;
|
|---|
| 1080 | goto keep_going;
|
|---|
| 1081 | }
|
|---|
| 1082 | else if (operand->flags & MN10300_OPERAND_SSP)
|
|---|
| 1083 | {
|
|---|
| 1084 | char *start = input_line_pointer;
|
|---|
| 1085 | char c = get_symbol_end ();
|
|---|
| 1086 |
|
|---|
| 1087 | if (strcasecmp (start, "ssp") != 0)
|
|---|
| 1088 | {
|
|---|
| 1089 | *input_line_pointer = c;
|
|---|
| 1090 | input_line_pointer = hold;
|
|---|
| 1091 | str = hold;
|
|---|
| 1092 | goto error;
|
|---|
| 1093 | }
|
|---|
| 1094 | *input_line_pointer = c;
|
|---|
| 1095 | goto keep_going;
|
|---|
| 1096 | }
|
|---|
| 1097 | else if (operand->flags & MN10300_OPERAND_MSP)
|
|---|
| 1098 | {
|
|---|
| 1099 | char *start = input_line_pointer;
|
|---|
| 1100 | char c = get_symbol_end ();
|
|---|
| 1101 |
|
|---|
| 1102 | if (strcasecmp (start, "msp") != 0)
|
|---|
| 1103 | {
|
|---|
| 1104 | *input_line_pointer = c;
|
|---|
| 1105 | input_line_pointer = hold;
|
|---|
| 1106 | str = hold;
|
|---|
| 1107 | goto error;
|
|---|
| 1108 | }
|
|---|
| 1109 | *input_line_pointer = c;
|
|---|
| 1110 | goto keep_going;
|
|---|
| 1111 | }
|
|---|
| 1112 | else if (operand->flags & MN10300_OPERAND_PC)
|
|---|
| 1113 | {
|
|---|
| 1114 | char *start = input_line_pointer;
|
|---|
| 1115 | char c = get_symbol_end ();
|
|---|
| 1116 |
|
|---|
| 1117 | if (strcasecmp (start, "pc") != 0)
|
|---|
| 1118 | {
|
|---|
| 1119 | *input_line_pointer = c;
|
|---|
| 1120 | input_line_pointer = hold;
|
|---|
| 1121 | str = hold;
|
|---|
| 1122 | goto error;
|
|---|
| 1123 | }
|
|---|
| 1124 | *input_line_pointer = c;
|
|---|
| 1125 | goto keep_going;
|
|---|
| 1126 | }
|
|---|
| 1127 | else if (operand->flags & MN10300_OPERAND_EPSW)
|
|---|
| 1128 | {
|
|---|
| 1129 | char *start = input_line_pointer;
|
|---|
| 1130 | char c = get_symbol_end ();
|
|---|
| 1131 |
|
|---|
| 1132 | if (strcasecmp (start, "epsw") != 0)
|
|---|
| 1133 | {
|
|---|
| 1134 | *input_line_pointer = c;
|
|---|
| 1135 | input_line_pointer = hold;
|
|---|
| 1136 | str = hold;
|
|---|
| 1137 | goto error;
|
|---|
| 1138 | }
|
|---|
| 1139 | *input_line_pointer = c;
|
|---|
| 1140 | goto keep_going;
|
|---|
| 1141 | }
|
|---|
| 1142 | else if (operand->flags & MN10300_OPERAND_PLUS)
|
|---|
| 1143 | {
|
|---|
| 1144 | if (*input_line_pointer != '+')
|
|---|
| 1145 | {
|
|---|
| 1146 | input_line_pointer = hold;
|
|---|
| 1147 | str = hold;
|
|---|
| 1148 | goto error;
|
|---|
| 1149 | }
|
|---|
| 1150 | input_line_pointer++;
|
|---|
| 1151 | goto keep_going;
|
|---|
| 1152 | }
|
|---|
| 1153 | else if (operand->flags & MN10300_OPERAND_PSW)
|
|---|
| 1154 | {
|
|---|
| 1155 | char *start = input_line_pointer;
|
|---|
| 1156 | char c = get_symbol_end ();
|
|---|
| 1157 |
|
|---|
| 1158 | if (strcasecmp (start, "psw") != 0)
|
|---|
| 1159 | {
|
|---|
| 1160 | *input_line_pointer = c;
|
|---|
| 1161 | input_line_pointer = hold;
|
|---|
| 1162 | str = hold;
|
|---|
| 1163 | goto error;
|
|---|
| 1164 | }
|
|---|
| 1165 | *input_line_pointer = c;
|
|---|
| 1166 | goto keep_going;
|
|---|
| 1167 | }
|
|---|
| 1168 | else if (operand->flags & MN10300_OPERAND_MDR)
|
|---|
| 1169 | {
|
|---|
| 1170 | char *start = input_line_pointer;
|
|---|
| 1171 | char c = get_symbol_end ();
|
|---|
| 1172 |
|
|---|
| 1173 | if (strcasecmp (start, "mdr") != 0)
|
|---|
| 1174 | {
|
|---|
| 1175 | *input_line_pointer = c;
|
|---|
| 1176 | input_line_pointer = hold;
|
|---|
| 1177 | str = hold;
|
|---|
| 1178 | goto error;
|
|---|
| 1179 | }
|
|---|
| 1180 | *input_line_pointer = c;
|
|---|
| 1181 | goto keep_going;
|
|---|
| 1182 | }
|
|---|
| 1183 | else if (operand->flags & MN10300_OPERAND_REG_LIST)
|
|---|
| 1184 | {
|
|---|
| 1185 | unsigned int value = 0;
|
|---|
| 1186 | if (*input_line_pointer != '[')
|
|---|
| 1187 | {
|
|---|
| 1188 | input_line_pointer = hold;
|
|---|
| 1189 | str = hold;
|
|---|
| 1190 | goto error;
|
|---|
| 1191 | }
|
|---|
| 1192 |
|
|---|
| 1193 | /* Eat the '['. */
|
|---|
| 1194 | input_line_pointer++;
|
|---|
| 1195 |
|
|---|
| 1196 | /* We used to reject a null register list here; however,
|
|---|
| 1197 | we accept it now so the compiler can emit "call"
|
|---|
| 1198 | instructions for all calls to named functions.
|
|---|
| 1199 |
|
|---|
| 1200 | The linker can then fill in the appropriate bits for the
|
|---|
| 1201 | register list and stack size or change the instruction
|
|---|
| 1202 | into a "calls" if using "call" is not profitable. */
|
|---|
| 1203 | while (*input_line_pointer != ']')
|
|---|
| 1204 | {
|
|---|
| 1205 | char *start;
|
|---|
| 1206 | char c;
|
|---|
| 1207 |
|
|---|
| 1208 | if (*input_line_pointer == ',')
|
|---|
| 1209 | input_line_pointer++;
|
|---|
| 1210 |
|
|---|
| 1211 | start = input_line_pointer;
|
|---|
| 1212 | c = get_symbol_end ();
|
|---|
| 1213 |
|
|---|
| 1214 | if (strcasecmp (start, "d2") == 0)
|
|---|
| 1215 | {
|
|---|
| 1216 | value |= 0x80;
|
|---|
| 1217 | *input_line_pointer = c;
|
|---|
| 1218 | }
|
|---|
| 1219 | else if (strcasecmp (start, "d3") == 0)
|
|---|
| 1220 | {
|
|---|
| 1221 | value |= 0x40;
|
|---|
| 1222 | *input_line_pointer = c;
|
|---|
| 1223 | }
|
|---|
| 1224 | else if (strcasecmp (start, "a2") == 0)
|
|---|
| 1225 | {
|
|---|
| 1226 | value |= 0x20;
|
|---|
| 1227 | *input_line_pointer = c;
|
|---|
| 1228 | }
|
|---|
| 1229 | else if (strcasecmp (start, "a3") == 0)
|
|---|
| 1230 | {
|
|---|
| 1231 | value |= 0x10;
|
|---|
| 1232 | *input_line_pointer = c;
|
|---|
| 1233 | }
|
|---|
| 1234 | else if (strcasecmp (start, "other") == 0)
|
|---|
| 1235 | {
|
|---|
| 1236 | value |= 0x08;
|
|---|
| 1237 | *input_line_pointer = c;
|
|---|
| 1238 | }
|
|---|
| 1239 | else if (HAVE_AM33
|
|---|
| 1240 | && strcasecmp (start, "exreg0") == 0)
|
|---|
| 1241 | {
|
|---|
| 1242 | value |= 0x04;
|
|---|
| 1243 | *input_line_pointer = c;
|
|---|
| 1244 | }
|
|---|
| 1245 | else if (HAVE_AM33
|
|---|
| 1246 | && strcasecmp (start, "exreg1") == 0)
|
|---|
| 1247 | {
|
|---|
| 1248 | value |= 0x02;
|
|---|
| 1249 | *input_line_pointer = c;
|
|---|
| 1250 | }
|
|---|
| 1251 | else if (HAVE_AM33
|
|---|
| 1252 | && strcasecmp (start, "exother") == 0)
|
|---|
| 1253 | {
|
|---|
| 1254 | value |= 0x01;
|
|---|
| 1255 | *input_line_pointer = c;
|
|---|
| 1256 | }
|
|---|
| 1257 | else if (HAVE_AM33
|
|---|
| 1258 | && strcasecmp (start, "all") == 0)
|
|---|
| 1259 | {
|
|---|
| 1260 | value |= 0xff;
|
|---|
| 1261 | *input_line_pointer = c;
|
|---|
| 1262 | }
|
|---|
| 1263 | else
|
|---|
| 1264 | {
|
|---|
| 1265 | input_line_pointer = hold;
|
|---|
| 1266 | str = hold;
|
|---|
| 1267 | goto error;
|
|---|
| 1268 | }
|
|---|
| 1269 | }
|
|---|
| 1270 | input_line_pointer++;
|
|---|
| 1271 | mn10300_insert_operand (&insn, &extension, operand,
|
|---|
| 1272 | value, (char *) NULL, 0, 0);
|
|---|
| 1273 | goto keep_going;
|
|---|
| 1274 |
|
|---|
| 1275 | }
|
|---|
| 1276 | else if (data_register_name (&ex))
|
|---|
| 1277 | {
|
|---|
| 1278 | input_line_pointer = hold;
|
|---|
| 1279 | str = hold;
|
|---|
| 1280 | goto error;
|
|---|
| 1281 | }
|
|---|
| 1282 | else if (address_register_name (&ex))
|
|---|
| 1283 | {
|
|---|
| 1284 | input_line_pointer = hold;
|
|---|
| 1285 | str = hold;
|
|---|
| 1286 | goto error;
|
|---|
| 1287 | }
|
|---|
| 1288 | else if (other_register_name (&ex))
|
|---|
| 1289 | {
|
|---|
| 1290 | input_line_pointer = hold;
|
|---|
| 1291 | str = hold;
|
|---|
| 1292 | goto error;
|
|---|
| 1293 | }
|
|---|
| 1294 | else if (HAVE_AM33 && r_register_name (&ex))
|
|---|
| 1295 | {
|
|---|
| 1296 | input_line_pointer = hold;
|
|---|
| 1297 | str = hold;
|
|---|
| 1298 | goto error;
|
|---|
| 1299 | }
|
|---|
| 1300 | else if (HAVE_AM33 && xr_register_name (&ex))
|
|---|
| 1301 | {
|
|---|
| 1302 | input_line_pointer = hold;
|
|---|
| 1303 | str = hold;
|
|---|
| 1304 | goto error;
|
|---|
| 1305 | }
|
|---|
| 1306 | else if (*str == ')' || *str == '(')
|
|---|
| 1307 | {
|
|---|
| 1308 | input_line_pointer = hold;
|
|---|
| 1309 | str = hold;
|
|---|
| 1310 | goto error;
|
|---|
| 1311 | }
|
|---|
| 1312 | else
|
|---|
| 1313 | {
|
|---|
| 1314 | expression (&ex);
|
|---|
| 1315 | }
|
|---|
| 1316 |
|
|---|
| 1317 | switch (ex.X_op)
|
|---|
| 1318 | {
|
|---|
| 1319 | case O_illegal:
|
|---|
| 1320 | errmsg = _("illegal operand");
|
|---|
| 1321 | goto error;
|
|---|
| 1322 | case O_absent:
|
|---|
| 1323 | errmsg = _("missing operand");
|
|---|
| 1324 | goto error;
|
|---|
| 1325 | case O_register:
|
|---|
| 1326 | {
|
|---|
| 1327 | int mask;
|
|---|
| 1328 |
|
|---|
| 1329 | mask = MN10300_OPERAND_DREG | MN10300_OPERAND_AREG;
|
|---|
| 1330 | if (HAVE_AM33)
|
|---|
| 1331 | mask |= MN10300_OPERAND_RREG | MN10300_OPERAND_XRREG;
|
|---|
| 1332 | if ((operand->flags & mask) == 0)
|
|---|
| 1333 | {
|
|---|
| 1334 | input_line_pointer = hold;
|
|---|
| 1335 | str = hold;
|
|---|
| 1336 | goto error;
|
|---|
| 1337 | }
|
|---|
| 1338 |
|
|---|
| 1339 | if (opcode->format == FMT_D1 || opcode->format == FMT_S1)
|
|---|
| 1340 | extra_shift = 8;
|
|---|
| 1341 | else if (opcode->format == FMT_D2
|
|---|
| 1342 | || opcode->format == FMT_D4
|
|---|
| 1343 | || opcode->format == FMT_S2
|
|---|
| 1344 | || opcode->format == FMT_S4
|
|---|
| 1345 | || opcode->format == FMT_S6
|
|---|
| 1346 | || opcode->format == FMT_D5)
|
|---|
| 1347 | extra_shift = 16;
|
|---|
| 1348 | else if (opcode->format == FMT_D7)
|
|---|
| 1349 | extra_shift = 8;
|
|---|
| 1350 | else if (opcode->format == FMT_D8 || opcode->format == FMT_D9)
|
|---|
| 1351 | extra_shift = 8;
|
|---|
| 1352 | else
|
|---|
| 1353 | extra_shift = 0;
|
|---|
| 1354 |
|
|---|
| 1355 | mn10300_insert_operand (&insn, &extension, operand,
|
|---|
| 1356 | ex.X_add_number, (char *) NULL,
|
|---|
| 1357 | 0, extra_shift);
|
|---|
| 1358 |
|
|---|
| 1359 | /* And note the register number in the register array. */
|
|---|
| 1360 | mn10300_reg_operands[op_idx - 1] = ex.X_add_number;
|
|---|
| 1361 | break;
|
|---|
| 1362 | }
|
|---|
| 1363 |
|
|---|
| 1364 | case O_constant:
|
|---|
| 1365 | /* If this operand can be promoted, and it doesn't
|
|---|
| 1366 | fit into the allocated bitfield for this insn,
|
|---|
| 1367 | then promote it (ie this opcode does not match). */
|
|---|
| 1368 | if (operand->flags
|
|---|
| 1369 | & (MN10300_OPERAND_PROMOTE | MN10300_OPERAND_RELAX)
|
|---|
| 1370 | && !check_operand (insn, operand, ex.X_add_number))
|
|---|
| 1371 | {
|
|---|
| 1372 | input_line_pointer = hold;
|
|---|
| 1373 | str = hold;
|
|---|
| 1374 | goto error;
|
|---|
| 1375 | }
|
|---|
| 1376 |
|
|---|
| 1377 | mn10300_insert_operand (&insn, &extension, operand,
|
|---|
| 1378 | ex.X_add_number, (char *) NULL,
|
|---|
| 1379 | 0, 0);
|
|---|
| 1380 | break;
|
|---|
| 1381 |
|
|---|
| 1382 | default:
|
|---|
| 1383 | /* If this operand can be promoted, then this opcode didn't
|
|---|
| 1384 | match since we can't know if it needed promotion! */
|
|---|
| 1385 | if (operand->flags & MN10300_OPERAND_PROMOTE)
|
|---|
| 1386 | {
|
|---|
| 1387 | input_line_pointer = hold;
|
|---|
| 1388 | str = hold;
|
|---|
| 1389 | goto error;
|
|---|
| 1390 | }
|
|---|
| 1391 |
|
|---|
| 1392 | /* We need to generate a fixup for this expression. */
|
|---|
| 1393 | if (fc >= MAX_INSN_FIXUPS)
|
|---|
| 1394 | as_fatal (_("too many fixups"));
|
|---|
| 1395 | fixups[fc].exp = ex;
|
|---|
| 1396 | fixups[fc].opindex = *opindex_ptr;
|
|---|
| 1397 | fixups[fc].reloc = BFD_RELOC_UNUSED;
|
|---|
| 1398 | ++fc;
|
|---|
| 1399 | break;
|
|---|
| 1400 | }
|
|---|
| 1401 |
|
|---|
| 1402 | keep_going:
|
|---|
| 1403 | str = input_line_pointer;
|
|---|
| 1404 | input_line_pointer = hold;
|
|---|
| 1405 |
|
|---|
| 1406 | while (*str == ' ' || *str == ',')
|
|---|
| 1407 | ++str;
|
|---|
| 1408 |
|
|---|
| 1409 | }
|
|---|
| 1410 |
|
|---|
| 1411 | /* Make sure we used all the operands! */
|
|---|
| 1412 | if (*str != ',')
|
|---|
| 1413 | match = 1;
|
|---|
| 1414 |
|
|---|
| 1415 | /* If this instruction has registers that must not match, verify
|
|---|
| 1416 | that they do indeed not match. */
|
|---|
| 1417 | if (opcode->no_match_operands)
|
|---|
| 1418 | {
|
|---|
| 1419 | int i;
|
|---|
| 1420 |
|
|---|
| 1421 | /* Look at each operand to see if it's marked. */
|
|---|
| 1422 | for (i = 0; i < MN10300_MAX_OPERANDS; i++)
|
|---|
| 1423 | {
|
|---|
| 1424 | if ((1 << i) & opcode->no_match_operands)
|
|---|
| 1425 | {
|
|---|
| 1426 | int j;
|
|---|
| 1427 |
|
|---|
| 1428 | /* operand I is marked. Check that it does not match any
|
|---|
| 1429 | operands > I which are marked. */
|
|---|
| 1430 | for (j = i + 1; j < MN10300_MAX_OPERANDS; j++)
|
|---|
| 1431 | {
|
|---|
| 1432 | if (((1 << j) & opcode->no_match_operands)
|
|---|
| 1433 | && mn10300_reg_operands[i] == mn10300_reg_operands[j])
|
|---|
| 1434 | {
|
|---|
| 1435 | errmsg = _("Invalid register specification.");
|
|---|
| 1436 | match = 0;
|
|---|
| 1437 | goto error;
|
|---|
| 1438 | }
|
|---|
| 1439 | }
|
|---|
| 1440 | }
|
|---|
| 1441 | }
|
|---|
| 1442 | }
|
|---|
| 1443 |
|
|---|
| 1444 | error:
|
|---|
| 1445 | if (match == 0)
|
|---|
| 1446 | {
|
|---|
| 1447 | next_opcode = opcode + 1;
|
|---|
| 1448 | if (!strcmp (next_opcode->name, opcode->name))
|
|---|
| 1449 | {
|
|---|
| 1450 | opcode = next_opcode;
|
|---|
| 1451 | continue;
|
|---|
| 1452 | }
|
|---|
| 1453 |
|
|---|
| 1454 | as_bad ("%s", errmsg);
|
|---|
| 1455 | return;
|
|---|
| 1456 | }
|
|---|
| 1457 | break;
|
|---|
| 1458 | }
|
|---|
| 1459 |
|
|---|
| 1460 | while (ISSPACE (*str))
|
|---|
| 1461 | ++str;
|
|---|
| 1462 |
|
|---|
| 1463 | if (*str != '\0')
|
|---|
| 1464 | as_bad (_("junk at end of line: `%s'"), str);
|
|---|
| 1465 |
|
|---|
| 1466 | input_line_pointer = str;
|
|---|
| 1467 |
|
|---|
| 1468 | /* Determine the size of the instruction. */
|
|---|
| 1469 | if (opcode->format == FMT_S0)
|
|---|
| 1470 | size = 1;
|
|---|
| 1471 |
|
|---|
| 1472 | if (opcode->format == FMT_S1 || opcode->format == FMT_D0)
|
|---|
| 1473 | size = 2;
|
|---|
| 1474 |
|
|---|
| 1475 | if (opcode->format == FMT_S2 || opcode->format == FMT_D1)
|
|---|
| 1476 | size = 3;
|
|---|
| 1477 |
|
|---|
| 1478 | if (opcode->format == FMT_D6)
|
|---|
| 1479 | size = 3;
|
|---|
| 1480 |
|
|---|
| 1481 | if (opcode->format == FMT_D7 || opcode->format == FMT_D10)
|
|---|
| 1482 | size = 4;
|
|---|
| 1483 |
|
|---|
| 1484 | if (opcode->format == FMT_D8)
|
|---|
| 1485 | size = 6;
|
|---|
| 1486 |
|
|---|
| 1487 | if (opcode->format == FMT_D9)
|
|---|
| 1488 | size = 7;
|
|---|
| 1489 |
|
|---|
| 1490 | if (opcode->format == FMT_S4)
|
|---|
| 1491 | size = 5;
|
|---|
| 1492 |
|
|---|
| 1493 | if (opcode->format == FMT_S6 || opcode->format == FMT_D5)
|
|---|
| 1494 | size = 7;
|
|---|
| 1495 |
|
|---|
| 1496 | if (opcode->format == FMT_D2)
|
|---|
| 1497 | size = 4;
|
|---|
| 1498 |
|
|---|
| 1499 | if (opcode->format == FMT_D4)
|
|---|
| 1500 | size = 6;
|
|---|
| 1501 |
|
|---|
| 1502 | if (relaxable && fc > 0)
|
|---|
| 1503 | {
|
|---|
| 1504 | int type;
|
|---|
| 1505 |
|
|---|
| 1506 | /* We want to anchor the line info to the previous frag (if
|
|---|
| 1507 | there isn't one, create it), so that, when the insn is
|
|---|
| 1508 | resized, we still get the right address for the beginning of
|
|---|
| 1509 | the region. */
|
|---|
| 1510 | f = frag_more (0);
|
|---|
| 1511 | dwarf2_emit_insn (0);
|
|---|
| 1512 |
|
|---|
| 1513 | /* bCC */
|
|---|
| 1514 | if (size == 2)
|
|---|
| 1515 | {
|
|---|
| 1516 | /* Handle bra specially. Basically treat it like jmp so
|
|---|
| 1517 | that we automatically handle 8, 16 and 32 bit offsets
|
|---|
| 1518 | correctly as well as jumps to an undefined address.
|
|---|
| 1519 |
|
|---|
| 1520 | It is also important to not treat it like other bCC
|
|---|
| 1521 | instructions since the long forms of bra is different
|
|---|
| 1522 | from other bCC instructions. */
|
|---|
| 1523 | if (opcode->opcode == 0xca00)
|
|---|
| 1524 | type = 10;
|
|---|
| 1525 | else
|
|---|
| 1526 | type = 0;
|
|---|
| 1527 | }
|
|---|
| 1528 | /* call */
|
|---|
| 1529 | else if (size == 5)
|
|---|
| 1530 | type = 6;
|
|---|
| 1531 | /* calls */
|
|---|
| 1532 | else if (size == 4)
|
|---|
| 1533 | type = 8;
|
|---|
| 1534 | /* jmp */
|
|---|
| 1535 | else if (size == 3 && opcode->opcode == 0xcc0000)
|
|---|
| 1536 | type = 10;
|
|---|
| 1537 | /* bCC (uncommon cases) */
|
|---|
| 1538 | else
|
|---|
| 1539 | type = 3;
|
|---|
| 1540 |
|
|---|
| 1541 | f = frag_var (rs_machine_dependent, 8, 8 - size, type,
|
|---|
| 1542 | fixups[0].exp.X_add_symbol,
|
|---|
| 1543 | fixups[0].exp.X_add_number,
|
|---|
| 1544 | (char *)fixups[0].opindex);
|
|---|
| 1545 |
|
|---|
| 1546 | /* This is pretty hokey. We basically just care about the
|
|---|
| 1547 | opcode, so we have to write out the first word big endian.
|
|---|
| 1548 |
|
|---|
| 1549 | The exception is "call", which has two operands that we
|
|---|
| 1550 | care about.
|
|---|
| 1551 |
|
|---|
| 1552 | The first operand (the register list) happens to be in the
|
|---|
| 1553 | first instruction word, and will be in the right place if
|
|---|
| 1554 | we output the first word in big endian mode.
|
|---|
| 1555 |
|
|---|
| 1556 | The second operand (stack size) is in the extension word,
|
|---|
| 1557 | and we want it to appear as the first character in the extension
|
|---|
| 1558 | word (as it appears in memory). Luckily, writing the extension
|
|---|
| 1559 | word in big endian format will do what we want. */
|
|---|
| 1560 | number_to_chars_bigendian (f, insn, size > 4 ? 4 : size);
|
|---|
| 1561 | if (size > 8)
|
|---|
| 1562 | {
|
|---|
| 1563 | number_to_chars_bigendian (f + 4, extension, 4);
|
|---|
| 1564 | number_to_chars_bigendian (f + 8, 0, size - 8);
|
|---|
| 1565 | }
|
|---|
| 1566 | else if (size > 4)
|
|---|
| 1567 | number_to_chars_bigendian (f + 4, extension, size - 4);
|
|---|
| 1568 | }
|
|---|
| 1569 | else
|
|---|
| 1570 | {
|
|---|
| 1571 | /* Allocate space for the instruction. */
|
|---|
| 1572 | f = frag_more (size);
|
|---|
| 1573 |
|
|---|
| 1574 | /* Fill in bytes for the instruction. Note that opcode fields
|
|---|
| 1575 | are written big-endian, 16 & 32bit immediates are written
|
|---|
| 1576 | little endian. Egad. */
|
|---|
| 1577 | if (opcode->format == FMT_S0
|
|---|
| 1578 | || opcode->format == FMT_S1
|
|---|
| 1579 | || opcode->format == FMT_D0
|
|---|
| 1580 | || opcode->format == FMT_D6
|
|---|
| 1581 | || opcode->format == FMT_D7
|
|---|
| 1582 | || opcode->format == FMT_D10
|
|---|
| 1583 | || opcode->format == FMT_D1)
|
|---|
| 1584 | {
|
|---|
| 1585 | number_to_chars_bigendian (f, insn, size);
|
|---|
| 1586 | }
|
|---|
| 1587 | else if (opcode->format == FMT_S2
|
|---|
| 1588 | && opcode->opcode != 0xdf0000
|
|---|
| 1589 | && opcode->opcode != 0xde0000)
|
|---|
| 1590 | {
|
|---|
| 1591 | /* A format S2 instruction that is _not_ "ret" and "retf". */
|
|---|
| 1592 | number_to_chars_bigendian (f, (insn >> 16) & 0xff, 1);
|
|---|
| 1593 | number_to_chars_littleendian (f + 1, insn & 0xffff, 2);
|
|---|
| 1594 | }
|
|---|
| 1595 | else if (opcode->format == FMT_S2)
|
|---|
| 1596 | {
|
|---|
| 1597 | /* This must be a ret or retf, which is written entirely in
|
|---|
| 1598 | big-endian format. */
|
|---|
| 1599 | number_to_chars_bigendian (f, insn, 3);
|
|---|
| 1600 | }
|
|---|
| 1601 | else if (opcode->format == FMT_S4
|
|---|
| 1602 | && opcode->opcode != 0xdc000000)
|
|---|
| 1603 | {
|
|---|
| 1604 | /* This must be a format S4 "call" instruction. What a pain. */
|
|---|
| 1605 | unsigned long temp = (insn >> 8) & 0xffff;
|
|---|
| 1606 | number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
|
|---|
| 1607 | number_to_chars_littleendian (f + 1, temp, 2);
|
|---|
| 1608 | number_to_chars_bigendian (f + 3, insn & 0xff, 1);
|
|---|
| 1609 | number_to_chars_bigendian (f + 4, extension & 0xff, 1);
|
|---|
| 1610 | }
|
|---|
| 1611 | else if (opcode->format == FMT_S4)
|
|---|
| 1612 | {
|
|---|
| 1613 | /* This must be a format S4 "jmp" instruction. */
|
|---|
| 1614 | unsigned long temp = ((insn & 0xffffff) << 8) | (extension & 0xff);
|
|---|
| 1615 | number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
|
|---|
| 1616 | number_to_chars_littleendian (f + 1, temp, 4);
|
|---|
| 1617 | }
|
|---|
| 1618 | else if (opcode->format == FMT_S6)
|
|---|
| 1619 | {
|
|---|
| 1620 | unsigned long temp = ((insn & 0xffffff) << 8)
|
|---|
| 1621 | | ((extension >> 16) & 0xff);
|
|---|
| 1622 | number_to_chars_bigendian (f, (insn >> 24) & 0xff, 1);
|
|---|
| 1623 | number_to_chars_littleendian (f + 1, temp, 4);
|
|---|
| 1624 | number_to_chars_bigendian (f + 5, (extension >> 8) & 0xff, 1);
|
|---|
| 1625 | number_to_chars_bigendian (f + 6, extension & 0xff, 1);
|
|---|
| 1626 | }
|
|---|
| 1627 | else if (opcode->format == FMT_D2
|
|---|
| 1628 | && opcode->opcode != 0xfaf80000
|
|---|
| 1629 | && opcode->opcode != 0xfaf00000
|
|---|
| 1630 | && opcode->opcode != 0xfaf40000)
|
|---|
| 1631 | {
|
|---|
| 1632 | /* A format D2 instruction where the 16bit immediate is
|
|---|
| 1633 | really a single 16bit value, not two 8bit values. */
|
|---|
| 1634 | number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
|
|---|
| 1635 | number_to_chars_littleendian (f + 2, insn & 0xffff, 2);
|
|---|
| 1636 | }
|
|---|
| 1637 | else if (opcode->format == FMT_D2)
|
|---|
| 1638 | {
|
|---|
| 1639 | /* A format D2 instruction where the 16bit immediate
|
|---|
| 1640 | is really two 8bit immediates. */
|
|---|
| 1641 | number_to_chars_bigendian (f, insn, 4);
|
|---|
| 1642 | }
|
|---|
| 1643 | else if (opcode->format == FMT_D4)
|
|---|
| 1644 | {
|
|---|
| 1645 | unsigned long temp = ((insn & 0xffff) << 16) | (extension & 0xffff);
|
|---|
| 1646 |
|
|---|
| 1647 | number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
|
|---|
| 1648 | number_to_chars_littleendian (f + 2, temp, 4);
|
|---|
| 1649 | }
|
|---|
| 1650 | else if (opcode->format == FMT_D5)
|
|---|
| 1651 | {
|
|---|
| 1652 | unsigned long temp = (((insn & 0xffff) << 16)
|
|---|
| 1653 | | ((extension >> 8) & 0xffff));
|
|---|
| 1654 |
|
|---|
| 1655 | number_to_chars_bigendian (f, (insn >> 16) & 0xffff, 2);
|
|---|
| 1656 | number_to_chars_littleendian (f + 2, temp, 4);
|
|---|
| 1657 | number_to_chars_bigendian (f + 6, extension & 0xff, 1);
|
|---|
| 1658 | }
|
|---|
| 1659 | else if (opcode->format == FMT_D8)
|
|---|
| 1660 | {
|
|---|
| 1661 | unsigned long temp = ((insn & 0xff) << 16) | (extension & 0xffff);
|
|---|
| 1662 |
|
|---|
| 1663 | number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
|
|---|
| 1664 | number_to_chars_bigendian (f + 3, (temp & 0xff), 1);
|
|---|
| 1665 | number_to_chars_littleendian (f + 4, temp >> 8, 2);
|
|---|
| 1666 | }
|
|---|
| 1667 | else if (opcode->format == FMT_D9)
|
|---|
| 1668 | {
|
|---|
| 1669 | unsigned long temp = ((insn & 0xff) << 24) | (extension & 0xffffff);
|
|---|
| 1670 |
|
|---|
| 1671 | number_to_chars_bigendian (f, (insn >> 8) & 0xffffff, 3);
|
|---|
| 1672 | number_to_chars_littleendian (f + 3, temp, 4);
|
|---|
| 1673 | }
|
|---|
| 1674 |
|
|---|
| 1675 | /* Create any fixups. */
|
|---|
| 1676 | for (i = 0; i < fc; i++)
|
|---|
| 1677 | {
|
|---|
| 1678 | const struct mn10300_operand *operand;
|
|---|
| 1679 |
|
|---|
| 1680 | operand = &mn10300_operands[fixups[i].opindex];
|
|---|
| 1681 | if (fixups[i].reloc != BFD_RELOC_UNUSED)
|
|---|
| 1682 | {
|
|---|
| 1683 | reloc_howto_type *reloc_howto;
|
|---|
| 1684 | int size;
|
|---|
| 1685 | int offset;
|
|---|
| 1686 | fixS *fixP;
|
|---|
| 1687 |
|
|---|
| 1688 | reloc_howto = bfd_reloc_type_lookup (stdoutput,
|
|---|
| 1689 | fixups[i].reloc);
|
|---|
| 1690 |
|
|---|
| 1691 | if (!reloc_howto)
|
|---|
| 1692 | abort ();
|
|---|
| 1693 |
|
|---|
| 1694 | size = bfd_get_reloc_size (reloc_howto);
|
|---|
| 1695 |
|
|---|
| 1696 | if (size < 1 || size > 4)
|
|---|
| 1697 | abort ();
|
|---|
| 1698 |
|
|---|
| 1699 | offset = 4 - size;
|
|---|
| 1700 | fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
|
|---|
| 1701 | size, &fixups[i].exp,
|
|---|
| 1702 | reloc_howto->pc_relative,
|
|---|
| 1703 | fixups[i].reloc);
|
|---|
| 1704 | }
|
|---|
| 1705 | else
|
|---|
| 1706 | {
|
|---|
| 1707 | int reloc, pcrel, reloc_size, offset;
|
|---|
| 1708 | fixS *fixP;
|
|---|
| 1709 |
|
|---|
| 1710 | reloc = BFD_RELOC_NONE;
|
|---|
| 1711 | /* How big is the reloc? Remember SPLIT relocs are
|
|---|
| 1712 | implicitly 32bits. */
|
|---|
| 1713 | if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
|
|---|
| 1714 | reloc_size = 32;
|
|---|
| 1715 | else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
|
|---|
| 1716 | reloc_size = 24;
|
|---|
| 1717 | else
|
|---|
| 1718 | reloc_size = operand->bits;
|
|---|
| 1719 |
|
|---|
| 1720 | /* Is the reloc pc-relative? */
|
|---|
| 1721 | pcrel = (operand->flags & MN10300_OPERAND_PCREL) != 0;
|
|---|
| 1722 |
|
|---|
| 1723 | offset = size - (reloc_size + operand->shift) / 8;
|
|---|
| 1724 |
|
|---|
| 1725 | /* Choose a proper BFD relocation type. */
|
|---|
| 1726 | if (pcrel)
|
|---|
| 1727 | {
|
|---|
| 1728 | if (reloc_size == 32)
|
|---|
| 1729 | reloc = BFD_RELOC_32_PCREL;
|
|---|
| 1730 | else if (reloc_size == 16)
|
|---|
| 1731 | reloc = BFD_RELOC_16_PCREL;
|
|---|
| 1732 | else if (reloc_size == 8)
|
|---|
| 1733 | reloc = BFD_RELOC_8_PCREL;
|
|---|
| 1734 | else
|
|---|
| 1735 | abort ();
|
|---|
| 1736 | }
|
|---|
| 1737 | else
|
|---|
| 1738 | {
|
|---|
| 1739 | if (reloc_size == 32)
|
|---|
| 1740 | reloc = BFD_RELOC_32;
|
|---|
| 1741 | else if (reloc_size == 16)
|
|---|
| 1742 | reloc = BFD_RELOC_16;
|
|---|
| 1743 | else if (reloc_size == 8)
|
|---|
| 1744 | reloc = BFD_RELOC_8;
|
|---|
| 1745 | else
|
|---|
| 1746 | abort ();
|
|---|
| 1747 | }
|
|---|
| 1748 |
|
|---|
| 1749 | /* Convert the size of the reloc into what fix_new_exp wants. */
|
|---|
| 1750 | reloc_size = reloc_size / 8;
|
|---|
| 1751 | if (reloc_size == 8)
|
|---|
| 1752 | reloc_size = 0;
|
|---|
| 1753 | else if (reloc_size == 16)
|
|---|
| 1754 | reloc_size = 1;
|
|---|
| 1755 | else if (reloc_size == 32)
|
|---|
| 1756 | reloc_size = 2;
|
|---|
| 1757 |
|
|---|
| 1758 | fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset,
|
|---|
| 1759 | reloc_size, &fixups[i].exp, pcrel,
|
|---|
| 1760 | ((bfd_reloc_code_real_type) reloc));
|
|---|
| 1761 |
|
|---|
| 1762 | if (pcrel)
|
|---|
| 1763 | fixP->fx_offset += offset;
|
|---|
| 1764 | }
|
|---|
| 1765 | }
|
|---|
| 1766 |
|
|---|
| 1767 | dwarf2_emit_insn (size);
|
|---|
| 1768 | }
|
|---|
| 1769 | }
|
|---|
| 1770 |
|
|---|
| 1771 | /* If while processing a fixup, a reloc really needs to be created
|
|---|
| 1772 | then it is done here. */
|
|---|
| 1773 |
|
|---|
| 1774 | arelent *
|
|---|
| 1775 | tc_gen_reloc (seg, fixp)
|
|---|
| 1776 | asection *seg ATTRIBUTE_UNUSED;
|
|---|
| 1777 | fixS *fixp;
|
|---|
| 1778 | {
|
|---|
| 1779 | arelent *reloc;
|
|---|
| 1780 | reloc = (arelent *) xmalloc (sizeof (arelent));
|
|---|
| 1781 |
|
|---|
| 1782 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
|
|---|
| 1783 | if (reloc->howto == (reloc_howto_type *) NULL)
|
|---|
| 1784 | {
|
|---|
| 1785 | as_bad_where (fixp->fx_file, fixp->fx_line,
|
|---|
| 1786 | _("reloc %d not supported by object file format"),
|
|---|
| 1787 | (int) fixp->fx_r_type);
|
|---|
| 1788 | return NULL;
|
|---|
| 1789 | }
|
|---|
| 1790 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
|
|---|
| 1791 |
|
|---|
| 1792 | if (fixp->fx_addsy && fixp->fx_subsy)
|
|---|
| 1793 | {
|
|---|
| 1794 | reloc->sym_ptr_ptr = NULL;
|
|---|
| 1795 |
|
|---|
| 1796 | /* If we got a difference between two symbols, and the
|
|---|
| 1797 | subtracted symbol is in the current section, use a
|
|---|
| 1798 | PC-relative relocation. If both symbols are in the same
|
|---|
| 1799 | section, the difference would have already been simplified
|
|---|
| 1800 | to a constant. */
|
|---|
| 1801 | if (S_GET_SEGMENT (fixp->fx_subsy) == seg)
|
|---|
| 1802 | {
|
|---|
| 1803 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
|
|---|
| 1804 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
|
|---|
| 1805 | reloc->addend = (reloc->address - S_GET_VALUE (fixp->fx_subsy)
|
|---|
| 1806 | + fixp->fx_offset);
|
|---|
| 1807 |
|
|---|
| 1808 | switch (fixp->fx_r_type)
|
|---|
| 1809 | {
|
|---|
| 1810 | case BFD_RELOC_8:
|
|---|
| 1811 | reloc->howto = bfd_reloc_type_lookup (stdoutput,
|
|---|
| 1812 | BFD_RELOC_8_PCREL);
|
|---|
| 1813 | return reloc;
|
|---|
| 1814 |
|
|---|
| 1815 | case BFD_RELOC_16:
|
|---|
| 1816 | reloc->howto = bfd_reloc_type_lookup (stdoutput,
|
|---|
| 1817 | BFD_RELOC_16_PCREL);
|
|---|
| 1818 | return reloc;
|
|---|
| 1819 |
|
|---|
| 1820 | case BFD_RELOC_24:
|
|---|
| 1821 | reloc->howto = bfd_reloc_type_lookup (stdoutput,
|
|---|
| 1822 | BFD_RELOC_24_PCREL);
|
|---|
| 1823 | return reloc;
|
|---|
| 1824 |
|
|---|
| 1825 | case BFD_RELOC_32:
|
|---|
| 1826 | reloc->howto = bfd_reloc_type_lookup (stdoutput,
|
|---|
| 1827 | BFD_RELOC_32_PCREL);
|
|---|
| 1828 | return reloc;
|
|---|
| 1829 |
|
|---|
| 1830 | default:
|
|---|
| 1831 | /* Try to compute the absolute value below. */
|
|---|
| 1832 | break;
|
|---|
| 1833 | }
|
|---|
| 1834 | }
|
|---|
| 1835 |
|
|---|
| 1836 | if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
|
|---|
| 1837 | || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
|
|---|
| 1838 | {
|
|---|
| 1839 | as_bad_where (fixp->fx_file, fixp->fx_line,
|
|---|
| 1840 | "Difference of symbols in different sections is not supported");
|
|---|
| 1841 | }
|
|---|
| 1842 | else
|
|---|
| 1843 | {
|
|---|
| 1844 | char *fixpos = fixp->fx_where + fixp->fx_frag->fr_literal;
|
|---|
| 1845 |
|
|---|
| 1846 | reloc->addend = (S_GET_VALUE (fixp->fx_addsy)
|
|---|
| 1847 | - S_GET_VALUE (fixp->fx_subsy) + fixp->fx_offset);
|
|---|
| 1848 |
|
|---|
| 1849 | switch (fixp->fx_r_type)
|
|---|
| 1850 | {
|
|---|
| 1851 | case BFD_RELOC_8:
|
|---|
| 1852 | md_number_to_chars (fixpos, reloc->addend, 1);
|
|---|
| 1853 | break;
|
|---|
| 1854 |
|
|---|
| 1855 | case BFD_RELOC_16:
|
|---|
| 1856 | md_number_to_chars (fixpos, reloc->addend, 2);
|
|---|
| 1857 | break;
|
|---|
| 1858 |
|
|---|
| 1859 | case BFD_RELOC_24:
|
|---|
| 1860 | md_number_to_chars (fixpos, reloc->addend, 3);
|
|---|
| 1861 | break;
|
|---|
| 1862 |
|
|---|
| 1863 | case BFD_RELOC_32:
|
|---|
| 1864 | md_number_to_chars (fixpos, reloc->addend, 4);
|
|---|
| 1865 | break;
|
|---|
| 1866 |
|
|---|
| 1867 | default:
|
|---|
| 1868 | reloc->sym_ptr_ptr = (asymbol **) &bfd_abs_symbol;
|
|---|
| 1869 | return reloc;
|
|---|
| 1870 | }
|
|---|
| 1871 | }
|
|---|
| 1872 |
|
|---|
| 1873 | if (reloc->sym_ptr_ptr)
|
|---|
| 1874 | free (reloc->sym_ptr_ptr);
|
|---|
| 1875 | free (reloc);
|
|---|
| 1876 | return NULL;
|
|---|
| 1877 | }
|
|---|
| 1878 | else
|
|---|
| 1879 | {
|
|---|
| 1880 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
|
|---|
| 1881 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
|
|---|
| 1882 | reloc->addend = fixp->fx_offset;
|
|---|
| 1883 | }
|
|---|
| 1884 | return reloc;
|
|---|
| 1885 | }
|
|---|
| 1886 |
|
|---|
| 1887 | int
|
|---|
| 1888 | md_estimate_size_before_relax (fragp, seg)
|
|---|
| 1889 | fragS *fragp;
|
|---|
| 1890 | asection *seg;
|
|---|
| 1891 | {
|
|---|
| 1892 | if (fragp->fr_subtype == 6
|
|---|
| 1893 | && (!S_IS_DEFINED (fragp->fr_symbol)
|
|---|
| 1894 | || seg != S_GET_SEGMENT (fragp->fr_symbol)))
|
|---|
| 1895 | fragp->fr_subtype = 7;
|
|---|
| 1896 | else if (fragp->fr_subtype == 8
|
|---|
| 1897 | && (!S_IS_DEFINED (fragp->fr_symbol)
|
|---|
| 1898 | || seg != S_GET_SEGMENT (fragp->fr_symbol)))
|
|---|
| 1899 | fragp->fr_subtype = 9;
|
|---|
| 1900 | else if (fragp->fr_subtype == 10
|
|---|
| 1901 | && (!S_IS_DEFINED (fragp->fr_symbol)
|
|---|
| 1902 | || seg != S_GET_SEGMENT (fragp->fr_symbol)))
|
|---|
| 1903 | fragp->fr_subtype = 12;
|
|---|
| 1904 |
|
|---|
| 1905 | if (fragp->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
|
|---|
| 1906 | abort ();
|
|---|
| 1907 |
|
|---|
| 1908 | return md_relax_table[fragp->fr_subtype].rlx_length;
|
|---|
| 1909 | }
|
|---|
| 1910 |
|
|---|
| 1911 | long
|
|---|
| 1912 | md_pcrel_from (fixp)
|
|---|
| 1913 | fixS *fixp;
|
|---|
| 1914 | {
|
|---|
| 1915 | if (fixp->fx_addsy != (symbolS *) NULL && !S_IS_DEFINED (fixp->fx_addsy))
|
|---|
| 1916 | {
|
|---|
| 1917 | /* The symbol is undefined. Let the linker figure it out. */
|
|---|
| 1918 | return 0;
|
|---|
| 1919 | }
|
|---|
| 1920 | return fixp->fx_frag->fr_address + fixp->fx_where;
|
|---|
| 1921 | }
|
|---|
| 1922 |
|
|---|
| 1923 | void
|
|---|
| 1924 | md_apply_fix3 (fixP, valP, seg)
|
|---|
| 1925 | fixS * fixP;
|
|---|
| 1926 | valueT * valP;
|
|---|
| 1927 | segT seg;
|
|---|
| 1928 | {
|
|---|
| 1929 | char * fixpos = fixP->fx_where + fixP->fx_frag->fr_literal;
|
|---|
| 1930 | int size = 0;
|
|---|
| 1931 | int value = (int) * valP;
|
|---|
| 1932 |
|
|---|
| 1933 | assert (fixP->fx_r_type < BFD_RELOC_UNUSED);
|
|---|
| 1934 |
|
|---|
| 1935 | /* This should never happen. */
|
|---|
| 1936 | if (seg->flags & SEC_ALLOC)
|
|---|
| 1937 | abort ();
|
|---|
| 1938 |
|
|---|
| 1939 | /* The value we are passed in *valuep includes the symbol values.
|
|---|
| 1940 | Since we are using BFD_ASSEMBLER, if we are doing this relocation
|
|---|
| 1941 | the code in write.c is going to call bfd_install_relocation, which
|
|---|
| 1942 | is also going to use the symbol value. That means that if the
|
|---|
| 1943 | reloc is fully resolved we want to use *valuep since
|
|---|
| 1944 | bfd_install_relocation is not being used.
|
|---|
| 1945 |
|
|---|
| 1946 | However, if the reloc is not fully resolved we do not want to use
|
|---|
| 1947 | *valuep, and must use fx_offset instead. However, if the reloc
|
|---|
| 1948 | is PC relative, we do want to use *valuep since it includes the
|
|---|
| 1949 | result of md_pcrel_from. */
|
|---|
| 1950 | if (fixP->fx_addsy != (symbolS *) NULL && ! fixP->fx_pcrel)
|
|---|
| 1951 | value = fixP->fx_offset;
|
|---|
| 1952 |
|
|---|
| 1953 | /* If the fix is relative to a symbol which is not defined, or not
|
|---|
| 1954 | in the same segment as the fix, we cannot resolve it here. */
|
|---|
| 1955 | if (fixP->fx_addsy != NULL
|
|---|
| 1956 | && (! S_IS_DEFINED (fixP->fx_addsy)
|
|---|
| 1957 | || (S_GET_SEGMENT (fixP->fx_addsy) != seg)))
|
|---|
| 1958 | {
|
|---|
| 1959 | fixP->fx_done = 0;
|
|---|
| 1960 | return;
|
|---|
| 1961 | }
|
|---|
| 1962 |
|
|---|
| 1963 | switch (fixP->fx_r_type)
|
|---|
| 1964 | {
|
|---|
| 1965 | case BFD_RELOC_8:
|
|---|
| 1966 | case BFD_RELOC_8_PCREL:
|
|---|
| 1967 | size = 1;
|
|---|
| 1968 | break;
|
|---|
| 1969 |
|
|---|
| 1970 | case BFD_RELOC_16:
|
|---|
| 1971 | case BFD_RELOC_16_PCREL:
|
|---|
| 1972 | size = 2;
|
|---|
| 1973 | break;
|
|---|
| 1974 |
|
|---|
| 1975 | case BFD_RELOC_32:
|
|---|
| 1976 | case BFD_RELOC_32_PCREL:
|
|---|
| 1977 | size = 4;
|
|---|
| 1978 | break;
|
|---|
| 1979 |
|
|---|
| 1980 | case BFD_RELOC_VTABLE_INHERIT:
|
|---|
| 1981 | case BFD_RELOC_VTABLE_ENTRY:
|
|---|
| 1982 | fixP->fx_done = 0;
|
|---|
| 1983 | return;
|
|---|
| 1984 |
|
|---|
| 1985 | case BFD_RELOC_NONE:
|
|---|
| 1986 | default:
|
|---|
| 1987 | as_bad_where (fixP->fx_file, fixP->fx_line,
|
|---|
| 1988 | _("Bad relocation fixup type (%d)"), fixP->fx_r_type);
|
|---|
| 1989 | }
|
|---|
| 1990 |
|
|---|
| 1991 | md_number_to_chars (fixpos, value, size);
|
|---|
| 1992 |
|
|---|
| 1993 | /* If a symbol remains, pass the fixup, as a reloc, onto the linker. */
|
|---|
| 1994 | if (fixP->fx_addsy == NULL)
|
|---|
| 1995 | fixP->fx_done = 1;
|
|---|
| 1996 | }
|
|---|
| 1997 |
|
|---|
| 1998 | /* Return zero if the fixup in fixp should be left alone and not
|
|---|
| 1999 | adjusted. */
|
|---|
| 2000 |
|
|---|
| 2001 | bfd_boolean
|
|---|
| 2002 | mn10300_fix_adjustable (fixp)
|
|---|
| 2003 | struct fix *fixp;
|
|---|
| 2004 | {
|
|---|
| 2005 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
|
|---|
| 2006 | || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
|
|---|
| 2007 | return 0;
|
|---|
| 2008 |
|
|---|
| 2009 | /* Do not adjust relocations involving symbols in code sections,
|
|---|
| 2010 | because it breaks linker relaxations. This could be fixed in the
|
|---|
| 2011 | linker, but this fix is simpler, and it pretty much only affects
|
|---|
| 2012 | object size a little bit. */
|
|---|
| 2013 | if (S_GET_SEGMENT (fixp->fx_addsy)->flags & SEC_CODE)
|
|---|
| 2014 | return 0;
|
|---|
| 2015 |
|
|---|
| 2016 | return 1;
|
|---|
| 2017 | }
|
|---|
| 2018 |
|
|---|
| 2019 | /* Insert an operand value into an instruction. */
|
|---|
| 2020 |
|
|---|
| 2021 | static void
|
|---|
| 2022 | mn10300_insert_operand (insnp, extensionp, operand, val, file, line, shift)
|
|---|
| 2023 | unsigned long *insnp;
|
|---|
| 2024 | unsigned long *extensionp;
|
|---|
| 2025 | const struct mn10300_operand *operand;
|
|---|
| 2026 | offsetT val;
|
|---|
| 2027 | char *file;
|
|---|
| 2028 | unsigned int line;
|
|---|
| 2029 | unsigned int shift;
|
|---|
| 2030 | {
|
|---|
| 2031 | /* No need to check 32bit operands for a bit. Note that
|
|---|
| 2032 | MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
|
|---|
| 2033 | if (operand->bits != 32
|
|---|
| 2034 | && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
|
|---|
| 2035 | {
|
|---|
| 2036 | long min, max;
|
|---|
| 2037 | offsetT test;
|
|---|
| 2038 | int bits;
|
|---|
| 2039 |
|
|---|
| 2040 | bits = operand->bits;
|
|---|
| 2041 | if (operand->flags & MN10300_OPERAND_24BIT)
|
|---|
| 2042 | bits = 24;
|
|---|
| 2043 |
|
|---|
| 2044 | if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
|
|---|
| 2045 | {
|
|---|
| 2046 | max = (1 << (bits - 1)) - 1;
|
|---|
| 2047 | min = - (1 << (bits - 1));
|
|---|
| 2048 | }
|
|---|
| 2049 | else
|
|---|
| 2050 | {
|
|---|
| 2051 | max = (1 << bits) - 1;
|
|---|
| 2052 | min = 0;
|
|---|
| 2053 | }
|
|---|
| 2054 |
|
|---|
| 2055 | test = val;
|
|---|
| 2056 |
|
|---|
| 2057 | if (test < (offsetT) min || test > (offsetT) max)
|
|---|
| 2058 | {
|
|---|
| 2059 | const char *err =
|
|---|
| 2060 | _("operand out of range (%s not between %ld and %ld)");
|
|---|
| 2061 | char buf[100];
|
|---|
| 2062 |
|
|---|
| 2063 | sprint_value (buf, test);
|
|---|
| 2064 | if (file == (char *) NULL)
|
|---|
| 2065 | as_warn (err, buf, min, max);
|
|---|
| 2066 | else
|
|---|
| 2067 | as_warn_where (file, line, err, buf, min, max);
|
|---|
| 2068 | }
|
|---|
| 2069 | }
|
|---|
| 2070 |
|
|---|
| 2071 | if ((operand->flags & MN10300_OPERAND_SPLIT) != 0)
|
|---|
| 2072 | {
|
|---|
| 2073 | *insnp |= (val >> (32 - operand->bits)) & ((1 << operand->bits) - 1);
|
|---|
| 2074 | *extensionp |= ((val & ((1 << (32 - operand->bits)) - 1))
|
|---|
| 2075 | << operand->shift);
|
|---|
| 2076 | }
|
|---|
| 2077 | else if ((operand->flags & MN10300_OPERAND_24BIT) != 0)
|
|---|
| 2078 | {
|
|---|
| 2079 | *insnp |= (val >> (24 - operand->bits)) & ((1 << operand->bits) - 1);
|
|---|
| 2080 | *extensionp |= ((val & ((1 << (24 - operand->bits)) - 1))
|
|---|
| 2081 | << operand->shift);
|
|---|
| 2082 | }
|
|---|
| 2083 | else if ((operand->flags & MN10300_OPERAND_EXTENDED) == 0)
|
|---|
| 2084 | {
|
|---|
| 2085 | *insnp |= (((long) val & ((1 << operand->bits) - 1))
|
|---|
| 2086 | << (operand->shift + shift));
|
|---|
| 2087 |
|
|---|
| 2088 | if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
|
|---|
| 2089 | *insnp |= (((long) val & ((1 << operand->bits) - 1))
|
|---|
| 2090 | << (operand->shift + shift + operand->bits));
|
|---|
| 2091 | }
|
|---|
| 2092 | else
|
|---|
| 2093 | {
|
|---|
| 2094 | *extensionp |= (((long) val & ((1 << operand->bits) - 1))
|
|---|
| 2095 | << (operand->shift + shift));
|
|---|
| 2096 |
|
|---|
| 2097 | if ((operand->flags & MN10300_OPERAND_REPEATED) != 0)
|
|---|
| 2098 | *extensionp |= (((long) val & ((1 << operand->bits) - 1))
|
|---|
| 2099 | << (operand->shift + shift + operand->bits));
|
|---|
| 2100 | }
|
|---|
| 2101 | }
|
|---|
| 2102 |
|
|---|
| 2103 | static unsigned long
|
|---|
| 2104 | check_operand (insn, operand, val)
|
|---|
| 2105 | unsigned long insn ATTRIBUTE_UNUSED;
|
|---|
| 2106 | const struct mn10300_operand *operand;
|
|---|
| 2107 | offsetT val;
|
|---|
| 2108 | {
|
|---|
| 2109 | /* No need to check 32bit operands for a bit. Note that
|
|---|
| 2110 | MN10300_OPERAND_SPLIT is an implicit 32bit operand. */
|
|---|
| 2111 | if (operand->bits != 32
|
|---|
| 2112 | && (operand->flags & MN10300_OPERAND_SPLIT) == 0)
|
|---|
| 2113 | {
|
|---|
| 2114 | long min, max;
|
|---|
| 2115 | offsetT test;
|
|---|
| 2116 | int bits;
|
|---|
| 2117 |
|
|---|
| 2118 | bits = operand->bits;
|
|---|
| 2119 | if (operand->flags & MN10300_OPERAND_24BIT)
|
|---|
| 2120 | bits = 24;
|
|---|
| 2121 |
|
|---|
| 2122 | if ((operand->flags & MN10300_OPERAND_SIGNED) != 0)
|
|---|
| 2123 | {
|
|---|
| 2124 | max = (1 << (bits - 1)) - 1;
|
|---|
| 2125 | min = - (1 << (bits - 1));
|
|---|
| 2126 | }
|
|---|
| 2127 | else
|
|---|
| 2128 | {
|
|---|
| 2129 | max = (1 << bits) - 1;
|
|---|
| 2130 | min = 0;
|
|---|
| 2131 | }
|
|---|
| 2132 |
|
|---|
| 2133 | test = val;
|
|---|
| 2134 |
|
|---|
| 2135 | if (test < (offsetT) min || test > (offsetT) max)
|
|---|
| 2136 | return 0;
|
|---|
| 2137 | else
|
|---|
| 2138 | return 1;
|
|---|
| 2139 | }
|
|---|
| 2140 | return 1;
|
|---|
| 2141 | }
|
|---|
| 2142 |
|
|---|
| 2143 | static void
|
|---|
| 2144 | set_arch_mach (mach)
|
|---|
| 2145 | int mach;
|
|---|
| 2146 | {
|
|---|
| 2147 | if (!bfd_set_arch_mach (stdoutput, bfd_arch_mn10300, mach))
|
|---|
| 2148 | as_warn (_("could not set architecture and machine"));
|
|---|
| 2149 |
|
|---|
| 2150 | current_machine = mach;
|
|---|
| 2151 | }
|
|---|