| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <stdio.h> |
| 23 |
#include "as.h" |
| 24 |
#include "safe-ctype.h" |
| 25 |
#include "subsegs.h" |
| 26 |
#include "symcat.h" |
| 27 |
#include "opcodes/m32r-desc.h" |
| 28 |
#include "opcodes/m32r-opc.h" |
| 29 |
#include "cgen.h" |
| 30 |
#include "elf/m32r.h" |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
typedef struct sym_link |
| 35 |
{ |
| 36 |
struct sym_link *next; |
| 37 |
symbolS *symbol; |
| 38 |
} sym_linkS; |
| 39 |
|
| 40 |
static sym_linkS *debug_sym_link = (sym_linkS *) 0; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
typedef struct |
| 45 |
{ |
| 46 |
const CGEN_INSN *insn; |
| 47 |
const CGEN_INSN *orig_insn; |
| 48 |
CGEN_FIELDS fields; |
| 49 |
#if CGEN_INT_INSN_P |
| 50 |
CGEN_INSN_INT buffer[1]; |
| 51 |
#define INSN_VALUE(buf) (*(buf)) |
| 52 |
#else |
| 53 |
unsigned char buffer[CGEN_MAX_INSN_SIZE]; |
| 54 |
#define INSN_VALUE(buf) (buf) |
| 55 |
#endif |
| 56 |
char *addr; |
| 57 |
fragS *frag; |
| 58 |
int num_fixups; |
| 59 |
fixS *fixups[GAS_CGEN_MAX_FIXUPS]; |
| 60 |
int indices[MAX_OPERAND_INSTANCES]; |
| 61 |
sym_linkS *debug_sym_link; |
| 62 |
} |
| 63 |
m32r_insn; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static m32r_insn prev_insn; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
static int seen_relaxable_p = 0; |
| 72 |
|
| 73 |
|
| 74 |
int pic_code; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
static int m32r_relax; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
static int warn_unmatched_high = 0; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
static int enable_m32rx = 0; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
static int enable_special = 0; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
static int enable_special_m32r = 1; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
static int enable_special_float = 0; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
static int warn_explicit_parallel_conflicts = 1; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
static int ignore_parallel_conflicts = 0; |
| 121 |
|
| 122 |
|
| 123 |
static int use_parallel = 0; |
| 124 |
|
| 125 |
|
| 126 |
static int optimize; |
| 127 |
|
| 128 |
|
| 129 |
static int m32r_flags = 0; |
| 130 |
|
| 131 |
|
| 132 |
static segT sbss_section; |
| 133 |
static asection scom_section; |
| 134 |
static asymbol scom_symbol; |
| 135 |
|
| 136 |
const char comment_chars[] = ";"; |
| 137 |
const char line_comment_chars[] = "#"; |
| 138 |
const char line_separator_chars[] = "!"; |
| 139 |
const char EXP_CHARS[] = "eE"; |
| 140 |
const char FLT_CHARS[] = "dD"; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
struct m32r_hi_fixup |
| 154 |
{ |
| 155 |
|
| 156 |
struct m32r_hi_fixup *next; |
| 157 |
|
| 158 |
|
| 159 |
fixS *fixp; |
| 160 |
|
| 161 |
|
| 162 |
segT seg; |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
static struct m32r_hi_fixup *m32r_hi_fixup_list; |
| 168 |
|
| 169 |
struct { |
| 170 |
enum bfd_architecture bfd_mach; |
| 171 |
int mach_flags; |
| 172 |
} mach_table[] = |
| 173 |
{ |
| 174 |
{ bfd_mach_m32r, (1<<MACH_M32R) }, |
| 175 |
{ bfd_mach_m32rx, (1<<MACH_M32RX) }, |
| 176 |
{ bfd_mach_m32r2, (1<<MACH_M32R2) } |
| 177 |
}; |
| 178 |
|
| 179 |
static void allow_m32rx (int); |
| 180 |
|
| 181 |
static void |
| 182 |
allow_m32rx (int on) |
| 183 |
{ |
| 184 |
enable_m32rx = on; |
| 185 |
|
| 186 |
if (stdoutput != NULL) |
| 187 |
bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach_table[on].bfd_mach); |
| 188 |
|
| 189 |
if (gas_cgen_cpu_desc != NULL) |
| 190 |
gas_cgen_cpu_desc->machs = mach_table[on].mach_flags; |
| 191 |
} |
| 192 |
|
| 193 |
#define M32R_SHORTOPTS "O::K:" |
| 194 |
|
| 195 |
const char *md_shortopts = M32R_SHORTOPTS; |
| 196 |
|
| 197 |
struct option md_longopts[] = |
| 198 |
{ |
| 199 |
#define OPTION_M32R (OPTION_MD_BASE) |
| 200 |
#define OPTION_M32RX (OPTION_M32R + 1) |
| 201 |
#define OPTION_M32R2 (OPTION_M32RX + 1) |
| 202 |
#define OPTION_BIG (OPTION_M32R2 + 1) |
| 203 |
#define OPTION_LITTLE (OPTION_BIG + 1) |
| 204 |
#define OPTION_PARALLEL (OPTION_LITTLE + 1) |
| 205 |
#define OPTION_NO_PARALLEL (OPTION_PARALLEL + 1) |
| 206 |
#define OPTION_WARN_PARALLEL (OPTION_NO_PARALLEL + 1) |
| 207 |
#define OPTION_NO_WARN_PARALLEL (OPTION_WARN_PARALLEL + 1) |
| 208 |
#define OPTION_IGNORE_PARALLEL (OPTION_NO_WARN_PARALLEL + 1) |
| 209 |
#define OPTION_NO_IGNORE_PARALLEL (OPTION_IGNORE_PARALLEL + 1) |
| 210 |
#define OPTION_SPECIAL (OPTION_NO_IGNORE_PARALLEL + 1) |
| 211 |
#define OPTION_SPECIAL_M32R (OPTION_SPECIAL + 1) |
| 212 |
#define OPTION_NO_SPECIAL_M32R (OPTION_SPECIAL_M32R + 1) |
| 213 |
#define OPTION_SPECIAL_FLOAT (OPTION_NO_SPECIAL_M32R + 1) |
| 214 |
#define OPTION_WARN_UNMATCHED (OPTION_SPECIAL_FLOAT + 1) |
| 215 |
#define OPTION_NO_WARN_UNMATCHED (OPTION_WARN_UNMATCHED + 1) |
| 216 |
{"m32r", no_argument, NULL, OPTION_M32R}, |
| 217 |
{"m32rx", no_argument, NULL, OPTION_M32RX}, |
| 218 |
{"m32r2", no_argument, NULL, OPTION_M32R2}, |
| 219 |
{"big", no_argument, NULL, OPTION_BIG}, |
| 220 |
{"little", no_argument, NULL, OPTION_LITTLE}, |
| 221 |
{"EB", no_argument, NULL, OPTION_BIG}, |
| 222 |
{"EL", no_argument, NULL, OPTION_LITTLE}, |
| 223 |
{"parallel", no_argument, NULL, OPTION_PARALLEL}, |
| 224 |
{"no-parallel", no_argument, NULL, OPTION_NO_PARALLEL}, |
| 225 |
{"warn-explicit-parallel-conflicts", no_argument, NULL, OPTION_WARN_PARALLEL}, |
| 226 |
{"Wp", no_argument, NULL, OPTION_WARN_PARALLEL}, |
| 227 |
{"no-warn-explicit-parallel-conflicts", no_argument, NULL, OPTION_NO_WARN_PARALLEL}, |
| 228 |
{"Wnp", no_argument, NULL, OPTION_NO_WARN_PARALLEL}, |
| 229 |
{"ignore-parallel-conflicts", no_argument, NULL, OPTION_IGNORE_PARALLEL}, |
| 230 |
{"Ip", no_argument, NULL, OPTION_IGNORE_PARALLEL}, |
| 231 |
{"no-ignore-parallel-conflicts", no_argument, NULL, OPTION_NO_IGNORE_PARALLEL}, |
| 232 |
{"nIp", no_argument, NULL, OPTION_NO_IGNORE_PARALLEL}, |
| 233 |
{"hidden", no_argument, NULL, OPTION_SPECIAL}, |
| 234 |
{"bitinst", no_argument, NULL, OPTION_SPECIAL_M32R}, |
| 235 |
{"no-bitinst", no_argument, NULL, OPTION_NO_SPECIAL_M32R}, |
| 236 |
{"float", no_argument, NULL, OPTION_SPECIAL_FLOAT}, |
| 237 |
|
| 238 |
{"warn-unmatched-high", no_argument, NULL, OPTION_WARN_UNMATCHED}, |
| 239 |
{"Wuh", no_argument, NULL, OPTION_WARN_UNMATCHED}, |
| 240 |
{"no-warn-unmatched-high", no_argument, NULL, OPTION_NO_WARN_UNMATCHED}, |
| 241 |
{"Wnuh", no_argument, NULL, OPTION_NO_WARN_UNMATCHED}, |
| 242 |
{NULL, no_argument, NULL, 0} |
| 243 |
}; |
| 244 |
|
| 245 |
size_t md_longopts_size = sizeof (md_longopts); |
| 246 |
|
| 247 |
static void little (int); |
| 248 |
static int parallel (void); |
| 249 |
|
| 250 |
static void |
| 251 |
little (int on) |
| 252 |
{ |
| 253 |
target_big_endian = ! on; |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
static int |
| 259 |
parallel (void) |
| 260 |
{ |
| 261 |
if (! enable_m32rx) |
| 262 |
return 0; |
| 263 |
|
| 264 |
if (use_parallel == 1) |
| 265 |
return 1; |
| 266 |
|
| 267 |
return 0; |
| 268 |
} |
| 269 |
|
| 270 |
int |
| 271 |
md_parse_option (c, arg) |
| 272 |
int c; |
| 273 |
char *arg ATTRIBUTE_UNUSED; |
| 274 |
{ |
| 275 |
switch (c) |
| 276 |
{ |
| 277 |
case 'O': |
| 278 |
optimize = 1; |
| 279 |
use_parallel = 1; |
| 280 |
break; |
| 281 |
|
| 282 |
case OPTION_M32R: |
| 283 |
allow_m32rx (0); |
| 284 |
break; |
| 285 |
|
| 286 |
case OPTION_M32RX: |
| 287 |
allow_m32rx (1); |
| 288 |
break; |
| 289 |
|
| 290 |
case OPTION_M32R2: |
| 291 |
allow_m32rx (2); |
| 292 |
enable_special = 1; |
| 293 |
enable_special_m32r = 1; |
| 294 |
break; |
| 295 |
|
| 296 |
case OPTION_BIG: |
| 297 |
target_big_endian = 1; |
| 298 |
break; |
| 299 |
|
| 300 |
case OPTION_LITTLE: |
| 301 |
target_big_endian = 0; |
| 302 |
break; |
| 303 |
|
| 304 |
case OPTION_PARALLEL: |
| 305 |
use_parallel = 1; |
| 306 |
break; |
| 307 |
|
| 308 |
case OPTION_NO_PARALLEL: |
| 309 |
use_parallel = 0; |
| 310 |
break; |
| 311 |
|
| 312 |
case OPTION_WARN_PARALLEL: |
| 313 |
warn_explicit_parallel_conflicts = 1; |
| 314 |
break; |
| 315 |
|
| 316 |
case OPTION_NO_WARN_PARALLEL: |
| 317 |
warn_explicit_parallel_conflicts = 0; |
| 318 |
break; |
| 319 |
|
| 320 |
case OPTION_IGNORE_PARALLEL: |
| 321 |
ignore_parallel_conflicts = 1; |
| 322 |
break; |
| 323 |
|
| 324 |
case OPTION_NO_IGNORE_PARALLEL: |
| 325 |
ignore_parallel_conflicts = 0; |
| 326 |
break; |
| 327 |
|
| 328 |
case OPTION_SPECIAL: |
| 329 |
if (enable_m32rx) |
| 330 |
enable_special = 1; |
| 331 |
else |
| 332 |
{ |
| 333 |
|
| 334 |
as_bad (_("Unrecognised option: -hidden")); |
| 335 |
return 0; |
| 336 |
} |
| 337 |
break; |
| 338 |
|
| 339 |
case OPTION_SPECIAL_M32R: |
| 340 |
enable_special_m32r = 1; |
| 341 |
break; |
| 342 |
|
| 343 |
case OPTION_NO_SPECIAL_M32R: |
| 344 |
enable_special_m32r = 0; |
| 345 |
break; |
| 346 |
|
| 347 |
case OPTION_SPECIAL_FLOAT: |
| 348 |
enable_special_float = 1; |
| 349 |
break; |
| 350 |
|
| 351 |
case OPTION_WARN_UNMATCHED: |
| 352 |
warn_unmatched_high = 1; |
| 353 |
break; |
| 354 |
|
| 355 |
case OPTION_NO_WARN_UNMATCHED: |
| 356 |
warn_unmatched_high = 0; |
| 357 |
break; |
| 358 |
|
| 359 |
case 'K': |
| 360 |
if (strcmp (arg, "PIC") != 0) |
| 361 |
as_warn (_("Unrecognized option following -K")); |
| 362 |
else |
| 363 |
pic_code = 1; |
| 364 |
break; |
| 365 |
|
| 366 |
default: |
| 367 |
return 0; |
| 368 |
} |
| 369 |
|
| 370 |
return 1; |
| 371 |
} |
| 372 |
|
| 373 |
void |
| 374 |
md_show_usage (stream) |
| 375 |
FILE *stream; |
| 376 |
{ |
| 377 |
fprintf (stream, _(" M32R specific command line options:\n")); |
| 378 |
|
| 379 |
fprintf (stream, _("\ |
| 380 |
-m32r disable support for the m32rx instruction set\n")); |
| 381 |
fprintf (stream, _("\ |
| 382 |
-m32rx support the extended m32rx instruction set\n")); |
| 383 |
fprintf (stream, _("\ |
| 384 |
-m32r2 support the extended m32r2 instruction set\n")); |
| 385 |
fprintf (stream, _("\ |
| 386 |
-EL,-little produce little endian code and data\n")); |
| 387 |
fprintf (stream, _("\ |
| 388 |
-EB,-big produce big endian code and data\n")); |
| 389 |
fprintf (stream, _("\ |
| 390 |
-parallel try to combine instructions in parallel\n")); |
| 391 |
fprintf (stream, _("\ |
| 392 |
-no-parallel disable -parallel\n")); |
| 393 |
fprintf (stream, _("\ |
| 394 |
-no-bitinst disallow the M32R2's extended bit-field instructions\n")); |
| 395 |
fprintf (stream, _("\ |
| 396 |
-O try to optimize code. Implies -parallel\n")); |
| 397 |
|
| 398 |
fprintf (stream, _("\ |
| 399 |
-warn-explicit-parallel-conflicts warn when parallel instructions\n")); |
| 400 |
fprintf (stream, _("\ |
| 401 |
might violate contraints\n")); |
| 402 |
fprintf (stream, _("\ |
| 403 |
-no-warn-explicit-parallel-conflicts do not warn when parallel\n")); |
| 404 |
fprintf (stream, _("\ |
| 405 |
instructions might violate contraints\n")); |
| 406 |
fprintf (stream, _("\ |
| 407 |
-Wp synonym for -warn-explicit-parallel-conflicts\n")); |
| 408 |
fprintf (stream, _("\ |
| 409 |
-Wnp synonym for -no-warn-explicit-parallel-conflicts\n")); |
| 410 |
fprintf (stream, _("\ |
| 411 |
-ignore-parallel-conflicts do not check parallel instructions\n")); |
| 412 |
fprintf (stream, _("\ |
| 413 |
fo contraint violations\n")); |
| 414 |
fprintf (stream, _("\ |
| 415 |
-no-ignore-parallel-conflicts check parallel instructions for\n")); |
| 416 |
fprintf (stream, _("\ |
| 417 |
contraint violations\n")); |
| 418 |
fprintf (stream, _("\ |
| 419 |
-Ip synonym for -ignore-parallel-conflicts\n")); |
| 420 |
fprintf (stream, _("\ |
| 421 |
-nIp synonym for -no-ignore-parallel-conflicts\n")); |
| 422 |
|
| 423 |
fprintf (stream, _("\ |
| 424 |
-warn-unmatched-high warn when an (s)high reloc has no matching low reloc\n")); |
| 425 |
fprintf (stream, _("\ |
| 426 |
-no-warn-unmatched-high do not warn about missing low relocs\n")); |
| 427 |
fprintf (stream, _("\ |
| 428 |
-Wuh synonym for -warn-unmatched-high\n")); |
| 429 |
fprintf (stream, _("\ |
| 430 |
-Wnuh synonym for -no-warn-unmatched-high\n")); |
| 431 |
|
| 432 |
fprintf (stream, _("\ |
| 433 |
-KPIC generate PIC\n")); |
| 434 |
} |
| 435 |
|
| 436 |
static void fill_insn PARAMS ((int)); |
| 437 |
static void m32r_scomm PARAMS ((int)); |
| 438 |
static void debug_sym PARAMS ((int)); |
| 439 |
static void expand_debug_syms PARAMS ((sym_linkS *, int)); |
| 440 |
|
| 441 |
|
| 442 |
static subsegT prev_subseg; |
| 443 |
static segT prev_seg; |
| 444 |
|
| 445 |
|
| 446 |
const pseudo_typeS md_pseudo_table[] = |
| 447 |
{ |
| 448 |
{ "word", cons, 4 }, |
| 449 |
{ "fillinsn", fill_insn, 0 }, |
| 450 |
{ "scomm", m32r_scomm, 0 }, |
| 451 |
{ "debugsym", debug_sym, 0 }, |
| 452 |
{ "m32r", allow_m32rx, 0 }, |
| 453 |
{ "m32rx", allow_m32rx, 1 }, |
| 454 |
{ "m32r2", allow_m32rx, 2 }, |
| 455 |
{ "little", little, 1 }, |
| 456 |
{ "big", little, 0 }, |
| 457 |
{ NULL, NULL, 0 } |
| 458 |
}; |
| 459 |
|
| 460 |
#define GOT_NAME "_GLOBAL_OFFSET_TABLE_" |
| 461 |
symbolS * GOT_symbol; |
| 462 |
|
| 463 |
static inline int |
| 464 |
m32r_PIC_related_p (symbolS *sym) |
| 465 |
{ |
| 466 |
expressionS *exp; |
| 467 |
|
| 468 |
if (! sym) |
| 469 |
return 0; |
| 470 |
|
| 471 |
if (sym == GOT_symbol) |
| 472 |
return 1; |
| 473 |
|
| 474 |
exp = symbol_get_value_expression (sym); |
| 475 |
|
| 476 |
return (exp->X_op == O_PIC_reloc |
| 477 |
|| exp->X_md == BFD_RELOC_M32R_26_PLTREL |
| 478 |
|| m32r_PIC_related_p (exp->X_add_symbol) |
| 479 |
|| m32r_PIC_related_p (exp->X_op_symbol)); |
| 480 |
} |
| 481 |
|
| 482 |
static inline int |
| 483 |
m32r_check_fixup (expressionS *main_exp, bfd_reloc_code_real_type *r_type_p) |
| 484 |
{ |
| 485 |
expressionS *exp = main_exp; |
| 486 |
|
| 487 |
if (exp->X_op == O_add && m32r_PIC_related_p (exp->X_op_symbol)) |
| 488 |
return 1; |
| 489 |
|
| 490 |
if (exp->X_op == O_symbol && exp->X_add_symbol) |
| 491 |
{ |
| 492 |
if (exp->X_add_symbol == GOT_symbol) |
| 493 |
{ |
| 494 |
*r_type_p = BFD_RELOC_M32R_GOTPC24; |
| 495 |
return 0; |
| 496 |
} |
| 497 |
} |
| 498 |
else if (exp->X_op == O_add) |
| 499 |
{ |
| 500 |
exp = symbol_get_value_expression (exp->X_add_symbol); |
| 501 |
if (! exp) |
| 502 |
return 0; |
| 503 |
} |
| 504 |
|
| 505 |
if (exp->X_op == O_PIC_reloc || exp->X_md != BFD_RELOC_UNUSED) |
| 506 |
{ |
| 507 |
*r_type_p = exp->X_md; |
| 508 |
if (exp == main_exp) |
| 509 |
exp->X_op = O_symbol; |
| 510 |
else |
| 511 |
{ |
| 512 |
main_exp->X_add_symbol = exp->X_add_symbol; |
| 513 |
main_exp->X_add_number += exp->X_add_number; |
| 514 |
} |
| 515 |
} |
| 516 |
else |
| 517 |
return (m32r_PIC_related_p (exp->X_add_symbol) |
| 518 |
|| m32r_PIC_related_p (exp->X_op_symbol)); |
| 519 |
|
| 520 |
return 0; |
| 521 |
} |
| 522 |
|
| 523 |
|
| 524 |
#define NOP_INSN 0x7000 |
| 525 |
#define PAR_NOP_INSN 0xf000 |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
void |
| 531 |
m32r_handle_align (fragp) |
| 532 |
fragS *fragp; |
| 533 |
{ |
| 534 |
static const unsigned char nop_pattern[] = { 0xf0, 0x00 }; |
| 535 |
static const unsigned char multi_nop_pattern[] = { 0x70, 0x00, 0xf0, 0x00 }; |
| 536 |
|
| 537 |
int bytes, fix; |
| 538 |
char *p; |
| 539 |
|
| 540 |
if (fragp->fr_type != rs_align_code) |
| 541 |
return; |
| 542 |
|
| 543 |
bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
| 544 |
p = fragp->fr_literal + fragp->fr_fix; |
| 545 |
fix = 0; |
| 546 |
|
| 547 |
if (bytes & 1) |
| 548 |
{ |
| 549 |
fix = 1; |
| 550 |
*p++ = 0; |
| 551 |
bytes--; |
| 552 |
} |
| 553 |
|
| 554 |
if (bytes & 2) |
| 555 |
{ |
| 556 |
memcpy (p, nop_pattern, 2); |
| 557 |
p += 2; |
| 558 |
bytes -= 2; |
| 559 |
fix += 2; |
| 560 |
} |
| 561 |
|
| 562 |
memcpy (p, multi_nop_pattern, 4); |
| 563 |
|
| 564 |
fragp->fr_fix += fix; |
| 565 |
fragp->fr_var = 4; |
| 566 |
} |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
static void |
| 578 |
fill_insn (ignore) |
| 579 |
int ignore ATTRIBUTE_UNUSED; |
| 580 |
{ |
| 581 |
frag_align_code (2, 0); |
| 582 |
prev_insn.insn = NULL; |
| 583 |
seen_relaxable_p = 0; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
static void |
| 593 |
debug_sym (ignore) |
| 594 |
int ignore ATTRIBUTE_UNUSED; |
| 595 |
{ |
| 596 |
register char *name; |
| 597 |
register char delim; |
| 598 |
register char *end_name; |
| 599 |
register symbolS *symbolP; |
| 600 |
register sym_linkS *link; |
| 601 |
|
| 602 |
name = input_line_pointer; |
| 603 |
delim = get_symbol_end (); |
| 604 |
end_name = input_line_pointer; |
| 605 |
|
| 606 |
if ((symbolP = symbol_find (name)) == NULL |
| 607 |
&& (symbolP = md_undefined_symbol (name)) == NULL) |
| 608 |
{ |
| 609 |
symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); |
| 610 |
} |
| 611 |
|
| 612 |
symbol_table_insert (symbolP); |
| 613 |
if (S_IS_DEFINED (symbolP) && (S_GET_SEGMENT (symbolP) != reg_section |
| 614 |
|| S_IS_EXTERNAL (symbolP) |
| 615 |
|| S_IS_WEAK (symbolP))) |
| 616 |
|
| 617 |
as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP)); |
| 618 |
|
| 619 |
else |
| 620 |
{ |
| 621 |
link = (sym_linkS *) xmalloc (sizeof (sym_linkS)); |
| 622 |
link->symbol = symbolP; |
| 623 |
link->next = debug_sym_link; |
| 624 |
debug_sym_link = link; |
| 625 |
symbol_get_obj (symbolP)->local = 1; |
| 626 |
} |
| 627 |
|
| 628 |
*end_name = delim; |
| 629 |
demand_empty_rest_of_line (); |
| 630 |
} |
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
static void |
| 636 |
expand_debug_syms (syms, align) |
| 637 |
sym_linkS *syms; |
| 638 |
int align; |
| 639 |
{ |
| 640 |
char *save_input_line = input_line_pointer; |
| 641 |
sym_linkS *next_syms; |
| 642 |
|
| 643 |
if (!syms) |
| 644 |
return; |
| 645 |
|
| 646 |
(void) frag_align_code (align, 0); |
| 647 |
for (; syms != (sym_linkS *) 0; syms = next_syms) |
| 648 |
{ |
| 649 |
symbolS *symbolP = syms->symbol; |
| 650 |
next_syms = syms->next; |
| 651 |
input_line_pointer = ".\n"; |
| 652 |
pseudo_set (symbolP); |
| 653 |
free ((char *) syms); |
| 654 |
} |
| 655 |
|
| 656 |
input_line_pointer = save_input_line; |
| 657 |
} |
| 658 |
|
| 659 |
void |
| 660 |
m32r_flush_pending_output() |
| 661 |
{ |
| 662 |
if (debug_sym_link) |
| 663 |
{ |
| 664 |
expand_debug_syms (debug_sym_link, 1); |
| 665 |
debug_sym_link = (sym_linkS *) 0; |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
int |
| 674 |
m32r_fill_insn (done) |
| 675 |
int done; |
| 676 |
{ |
| 677 |
if (prev_seg != NULL) |
| 678 |
{ |
| 679 |
segT seg = now_seg; |
| 680 |
subsegT subseg = now_subseg; |
| 681 |
|
| 682 |
subseg_set (prev_seg, prev_subseg); |
| 683 |
|
| 684 |
fill_insn (0); |
| 685 |
|
| 686 |
subseg_set (seg, subseg); |
| 687 |
} |
| 688 |
|
| 689 |
if (done && debug_sym_link) |
| 690 |
{ |
| 691 |
expand_debug_syms (debug_sym_link, 1); |
| 692 |
debug_sym_link = (sym_linkS *) 0; |
| 693 |
} |
| 694 |
|
| 695 |
return 1; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
const char * |
| 701 |
m32r_target_format () |
| 702 |
{ |
| 703 |
#ifdef TE_LINUX |
| 704 |
if (target_big_endian) |
| 705 |
return "elf32-m32r-linux"; |
| 706 |
else |
| 707 |
return "elf32-m32rle-linux"; |
| 708 |
#else |
| 709 |
if (target_big_endian) |
| 710 |
return "elf32-m32r"; |
| 711 |
else |
| 712 |
return "elf32-m32rle"; |
| 713 |
#endif |
| 714 |
} |
| 715 |
|
| 716 |
void |
| 717 |
md_begin () |
| 718 |
{ |
| 719 |
flagword applicable; |
| 720 |
segT seg; |
| 721 |
subsegT subseg; |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
gas_cgen_cpu_desc = m32r_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0, |
| 727 |
CGEN_CPU_OPEN_ENDIAN, |
| 728 |
(target_big_endian ? |
| 729 |
CGEN_ENDIAN_BIG : CGEN_ENDIAN_LITTLE), |
| 730 |
CGEN_CPU_OPEN_END); |
| 731 |
m32r_cgen_init_asm (gas_cgen_cpu_desc); |
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
m32r_cgen_init_opinst_table (gas_cgen_cpu_desc); |
| 737 |
|
| 738 |
|
| 739 |
cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand); |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
seg = now_seg; |
| 744 |
subseg = now_subseg; |
| 745 |
|
| 746 |
|
| 747 |
sbss_section = subseg_new (".sbss", 0); |
| 748 |
|
| 749 |
|
| 750 |
applicable = bfd_applicable_section_flags (stdoutput); |
| 751 |
bfd_set_section_flags (stdoutput, sbss_section, applicable & SEC_ALLOC); |
| 752 |
|
| 753 |
subseg_set (seg, subseg); |
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
scom_section = bfd_com_section; |
| 758 |
scom_section.name = ".scommon"; |
| 759 |
scom_section.output_section = &scom_section; |
| 760 |
scom_section.symbol = &scom_symbol; |
| 761 |
scom_section.symbol_ptr_ptr = &scom_section.symbol; |
| 762 |
scom_symbol = *bfd_com_section.symbol; |
| 763 |
scom_symbol.name = ".scommon"; |
| 764 |
scom_symbol.section = &scom_section; |
| 765 |
|
| 766 |
allow_m32rx (enable_m32rx); |
| 767 |
|
| 768 |
gas_cgen_initialize_saved_fixups_array (); |
| 769 |
} |
| 770 |
|
| 771 |
#define OPERAND_IS_COND_BIT(operand, indices, index) \ |
| 772 |
((operand)->hw_type == HW_H_COND \ |
| 773 |
|| ((operand)->hw_type == HW_H_PSW) \ |
| 774 |
|| ((operand)->hw_type == HW_H_CR \ |
| 775 |
&& (indices [index] == 0 || indices [index] == 1))) |
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
static int first_writes_to_seconds_operands |
| 782 |
PARAMS ((m32r_insn *, m32r_insn *, const int)); |
| 783 |
|
| 784 |
static int |
| 785 |
first_writes_to_seconds_operands (a, b, check_outputs) |
| 786 |
m32r_insn *a; |
| 787 |
m32r_insn *b; |
| 788 |
const int check_outputs; |
| 789 |
{ |
| 790 |
const CGEN_OPINST *a_operands = CGEN_INSN_OPERANDS (a->insn); |
| 791 |
const CGEN_OPINST *b_ops = CGEN_INSN_OPERANDS (b->insn); |
| 792 |
int a_index; |
| 793 |
|
| 794 |
if (ignore_parallel_conflicts) |
| 795 |
return 0; |
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
if (a_operands == NULL || b_ops == NULL) |
| 801 |
return 0; |
| 802 |
|
| 803 |
|
| 804 |
for (a_index = 0; |
| 805 |
a_operands->type != CGEN_OPINST_END; |
| 806 |
a_index ++, a_operands ++) |
| 807 |
{ |
| 808 |
if (a_operands->type == CGEN_OPINST_OUTPUT) |
| 809 |
{ |
| 810 |
int b_index; |
| 811 |
const CGEN_OPINST *b_operands = b_ops; |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
if (OPERAND_IS_COND_BIT (a_operands, a->indices, a_index)) |
| 820 |
{ |
| 821 |
|
| 822 |
|
| 823 |
for (b_index = 0; |
| 824 |
b_operands->type != CGEN_OPINST_END; |
| 825 |
b_index++, b_operands++) |
| 826 |
{ |
| 827 |
if ((b_operands->type |
| 828 |
== (check_outputs |
| 829 |
? CGEN_OPINST_OUTPUT |
| 830 |
: CGEN_OPINST_INPUT)) |
| 831 |
&& OPERAND_IS_COND_BIT (b_operands, b->indices, b_index)) |
| 832 |
return 1; |
| 833 |
} |
| 834 |
} |
| 835 |
else |
| 836 |
{ |
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
for (b_index = 0; |
| 841 |
b_operands->type != CGEN_OPINST_END; |
| 842 |
b_index++, b_operands++) |
| 843 |
{ |
| 844 |
if ((b_operands->type |
| 845 |
== (check_outputs |
| 846 |
? CGEN_OPINST_OUTPUT |
| 847 |
: CGEN_OPINST_INPUT)) |
| 848 |
&& (b_operands->hw_type == a_operands->hw_type) |
| 849 |
&& (a->indices[a_index] == b->indices[b_index])) |
| 850 |
return 1; |
| 851 |
} |
| 852 |
} |
| 853 |
} |
| 854 |
} |
| 855 |
|
| 856 |
return 0; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
static int writes_to_pc PARAMS ((m32r_insn *)); |
| 862 |
|
| 863 |
static int |
| 864 |
writes_to_pc (a) |
| 865 |
m32r_insn *a; |
| 866 |
{ |
| 867 |
if (CGEN_INSN_ATTR_VALUE (a->insn, CGEN_INSN_UNCOND_CTI) |
| 868 |
|| CGEN_INSN_ATTR_VALUE (a->insn, CGEN_INSN_COND_CTI)) |
| 869 |
return 1; |
| 870 |
return 0; |
| 871 |
} |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
static const char *can_make_parallel PARAMS ((m32r_insn *, m32r_insn *)); |
| 877 |
|
| 878 |
static const char * |
| 879 |
can_make_parallel (a, b) |
| 880 |
m32r_insn *a; |
| 881 |
m32r_insn *b; |
| 882 |
{ |
| 883 |
PIPE_ATTR a_pipe; |
| 884 |
PIPE_ATTR b_pipe; |
| 885 |
|
| 886 |
|
| 887 |
if (CGEN_FIELDS_BITSIZE (&a->fields) != 16 |
| 888 |
|| CGEN_FIELDS_BITSIZE (&b->fields) != 16) |
| 889 |
abort (); |
| 890 |
|
| 891 |
if (first_writes_to_seconds_operands (a, b, TRUE)) |
| 892 |
return _("instructions write to the same destination register."); |
| 893 |
|
| 894 |
a_pipe = CGEN_INSN_ATTR_VALUE (a->insn, CGEN_INSN_PIPE); |
| 895 |
b_pipe = CGEN_INSN_ATTR_VALUE (b->insn, CGEN_INSN_PIPE); |
| 896 |
|
| 897 |
|
| 898 |
if (a_pipe == PIPE_NONE |
| 899 |
|| b_pipe == PIPE_NONE) |
| 900 |
return _("Instructions do not use parallel execution pipelines."); |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
if (a_pipe == PIPE_S |
| 906 |
|| b_pipe == PIPE_O |
| 907 |
|| (b_pipe == PIPE_O_OS && (enable_m32rx != 2))) |
| 908 |
return _("Instructions share the same execution pipeline"); |
| 909 |
|
| 910 |
return NULL; |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
static void make_parallel PARAMS ((CGEN_INSN_BYTES_PTR)); |
| 916 |
|
| 917 |
static void |
| 918 |
make_parallel (buffer) |
| 919 |
CGEN_INSN_BYTES_PTR buffer; |
| 920 |
{ |
| 921 |
#if CGEN_INT_INSN_P |
| 922 |
*buffer |= 0x8000; |
| 923 |
#else |
| 924 |
buffer[CGEN_CPU_ENDIAN (gas_cgen_cpu_desc) == CGEN_ENDIAN_BIG ? 0 : 1] |
| 925 |
|= 0x80; |
| 926 |
#endif |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
static void target_make_parallel PARAMS ((char *)); |
| 932 |
|
| 933 |
static void |
| 934 |
target_make_parallel (buffer) |
| 935 |
char *buffer; |
| 936 |
{ |
| 937 |
buffer[CGEN_CPU_ENDIAN (gas_cgen_cpu_desc) == CGEN_ENDIAN_BIG ? 0 : 1] |
| 938 |
|= 0x80; |
| 939 |
} |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
static void assemble_two_insns PARAMS ((char *, char *, int)); |
| 945 |
|
| 946 |
static void |
| 947 |
assemble_two_insns (str, str2, parallel_p) |
| 948 |
char *str; |
| 949 |
char *str2; |
| 950 |
int parallel_p; |
| 951 |
{ |
| 952 |
char *str3; |
| 953 |
m32r_insn first; |
| 954 |
m32r_insn second; |
| 955 |
char *errmsg; |
| 956 |
char save_str2 = *str2; |
| 957 |
|
| 958 |
|
| 959 |
*str2 = 0; |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
fill_insn (0); |
| 968 |
|
| 969 |
first.debug_sym_link = debug_sym_link; |
| 970 |
debug_sym_link = (sym_linkS *) 0; |
| 971 |
|
| 972 |
|
| 973 |
if (! (first.insn = m32r_cgen_assemble_insn |
| 974 |
(gas_cgen_cpu_desc, str, & first.fields, first.buffer, & errmsg))) |
| 975 |
{ |
| 976 |
as_bad (errmsg); |
| 977 |
return; |
| 978 |
} |
| 979 |
|
| 980 |
|
| 981 |
if (CGEN_FIELDS_BITSIZE (&first.fields) != 16) |
| 982 |
{ |
| 983 |
|
| 984 |
as_bad (_("not a 16 bit instruction '%s'"), str); |
| 985 |
return; |
| 986 |
} |
| 987 |
#ifdef E_M32R2_ARCH |
| 988 |
else if ((enable_m32rx == 1) |
| 989 |
|
| 990 |
&& ((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH) |
| 991 |
& (1 << MACH_M32R2)) |
| 992 |
&& !((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH) |
| 993 |
& (1 << MACH_M32RX))))) |
| 994 |
{ |
| 995 |
|
| 996 |
as_bad (_("instruction '%s' is for the M32R2 only"), str); |
| 997 |
return; |
| 998 |
} |
| 999 |
else if ((! enable_special |
| 1000 |
&& CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL)) |
| 1001 |
|| (! enable_special_m32r |
| 1002 |
&& CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL_M32R))) |
| 1003 |
#else |
| 1004 |
else if (! enable_special |
| 1005 |
&& CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL)) |
| 1006 |
#endif |
| 1007 |
{ |
| 1008 |
|
| 1009 |
as_bad (_("unknown instruction '%s'"), str); |
| 1010 |
return; |
| 1011 |
} |
| 1012 |
else if (! enable_m32rx |
| 1013 |
|
| 1014 |
&& (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH) |
| 1015 |
== (1 << MACH_M32RX))) |
| 1016 |
{ |
| 1017 |
|
| 1018 |
as_bad (_("instruction '%s' is for the M32RX only"), str); |
| 1019 |
return; |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
if (parallel_p |
| 1024 |
&& CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_PIPE) == PIPE_NONE) |
| 1025 |
{ |
| 1026 |
|
| 1027 |
as_bad (_("instruction '%s' cannot be executed in parallel."), str); |
| 1028 |
return; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
*str2 = save_str2; |
| 1033 |
|
| 1034 |
|
| 1035 |
str3 = str; |
| 1036 |
|
| 1037 |
|
| 1038 |
str = str2 + 2; |
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
str2 = str3; |
| 1043 |
|
| 1044 |
|
| 1045 |
{ |
| 1046 |
char *s2 = str; |
| 1047 |
|
| 1048 |
while (ISSPACE (*s2++)) |
| 1049 |
continue; |
| 1050 |
|
| 1051 |
--s2; |
| 1052 |
|
| 1053 |
while (ISALNUM (*s2)) |
| 1054 |
{ |
| 1055 |
*s2 = TOLOWER (*s2); |
| 1056 |
s2++; |
| 1057 |
} |
| 1058 |
} |
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
gas_cgen_save_fixups (0); |
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
first.orig_insn = first.insn; |
| 1074 |
{ |
| 1075 |
CGEN_FIELDS tmp_fields; |
| 1076 |
first.insn = cgen_lookup_get_insn_operands |
| 1077 |
(gas_cgen_cpu_desc, NULL, INSN_VALUE (first.buffer), NULL, 16, |
| 1078 |
first.indices, &tmp_fields); |
| 1079 |
} |
| 1080 |
|
| 1081 |
if (first.insn == NULL) |
| 1082 |
as_fatal (_("internal error: lookup/get operands failed")); |
| 1083 |
|
| 1084 |
second.debug_sym_link = NULL; |
| 1085 |
|
| 1086 |
|
| 1087 |
if (! (second.insn = m32r_cgen_assemble_insn |
| 1088 |
(gas_cgen_cpu_desc, str, & second.fields, second.buffer, & errmsg))) |
| 1089 |
{ |
| 1090 |
as_bad (errmsg); |
| 1091 |
return; |
| 1092 |
} |
| 1093 |
|
| 1094 |
|
| 1095 |
if (CGEN_FIELDS_BITSIZE (&second.fields) != 16) |
| 1096 |
{ |
| 1097 |
|
| 1098 |
as_bad (_("not a 16 bit instruction '%s'"), str); |
| 1099 |
return; |
| 1100 |
} |
| 1101 |
#ifdef E_M32R2_ARCH |
| 1102 |
else if ((enable_m32rx == 1) |
| 1103 |
|
| 1104 |
&& ((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH) |
| 1105 |
& (1 << MACH_M32R2)) |
| 1106 |
&& !((CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_MACH) |
| 1107 |
& (1 << MACH_M32RX))))) |
| 1108 |
{ |
| 1109 |
|
| 1110 |
as_bad (_("instruction '%s' is for the M32R2 only"), str); |
| 1111 |
return; |
| 1112 |
} |
| 1113 |
else if ((! enable_special |
| 1114 |
&& CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL)) |
| 1115 |
|| (! enable_special_m32r |
| 1116 |
&& CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL_M32R))) |
| 1117 |
#else |
| 1118 |
else if (! enable_special |
| 1119 |
&& CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL)) |
| 1120 |
#endif |
| 1121 |
{ |
| 1122 |
|
| 1123 |
as_bad (_("unknown instruction '%s'"), str); |
| 1124 |
return; |
| 1125 |
} |
| 1126 |
else if (! enable_m32rx |
| 1127 |
&& CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_MACH) == (1 << MACH_M32RX)) |
| 1128 |
{ |
| 1129 |
|
| 1130 |
as_bad (_("instruction '%s' is for the M32RX only"), str); |
| 1131 |
return; |
| 1132 |
} |
| 1133 |
|
| 1134 |
|
| 1135 |
if (parallel_p |
| 1136 |
&& CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_PIPE) == PIPE_NONE) |
| 1137 |
{ |
| 1138 |
|
| 1139 |
as_bad (_("instruction '%s' cannot be executed in parallel."), str); |
| 1140 |
return; |
| 1141 |
} |
| 1142 |
|
| 1143 |
if (parallel_p && ! enable_m32rx) |
| 1144 |
{ |
| 1145 |
if (CGEN_INSN_NUM (first.insn) != M32R_INSN_NOP |
| 1146 |
&& CGEN_INSN_NUM (second.insn) != M32R_INSN_NOP) |
| 1147 |
{ |
| 1148 |
|
| 1149 |
as_bad (_("'%s': only the NOP instruction can be issued in parallel on the m32r"), str2); |
| 1150 |
return; |
| 1151 |
} |
| 1152 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
second.orig_insn = second.insn; |
| 1156 |
{ |
| 1157 |
CGEN_FIELDS tmp_fields; |
| 1158 |
second.insn = cgen_lookup_get_insn_operands |
| 1159 |
(gas_cgen_cpu_desc, NULL, INSN_VALUE (second.buffer), NULL, 16, |
| 1160 |
second.indices, &tmp_fields); |
| 1161 |
} |
| 1162 |
|
| 1163 |
if (second.insn == NULL) |
| 1164 |
as_fatal (_("internal error: lookup/get operands failed")); |
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
if (parallel_p && warn_explicit_parallel_conflicts) |
| 1175 |
{ |
| 1176 |
if (first_writes_to_seconds_operands (&first, &second, FALSE)) |
| 1177 |
|
| 1178 |
as_warn (_("%s: output of 1st instruction is the same as an input to 2nd instruction - is this intentional ?"), str2); |
| 1179 |
|
| 1180 |
if (first_writes_to_seconds_operands (&second, &first, FALSE)) |
| 1181 |
|
| 1182 |
as_warn (_("%s: output of 2nd instruction is the same as an input to 1st instruction - is this intentional ?"), str2); |
| 1183 |
} |
| 1184 |
|
| 1185 |
if (!parallel_p |
| 1186 |
|| (errmsg = (char *) can_make_parallel (&first, &second)) == NULL) |
| 1187 |
{ |
| 1188 |
|
| 1189 |
gas_cgen_swap_fixups (0); |
| 1190 |
|
| 1191 |
|
| 1192 |
expand_debug_syms (first.debug_sym_link, 1); |
| 1193 |
gas_cgen_finish_insn (first.orig_insn, first.buffer, |
| 1194 |
CGEN_FIELDS_BITSIZE (&first.fields), 0, NULL); |
| 1195 |
|
| 1196 |
|
| 1197 |
if (parallel_p) |
| 1198 |
make_parallel (second.buffer); |
| 1199 |
|
| 1200 |
|
| 1201 |
gas_cgen_restore_fixups (0); |
| 1202 |
|
| 1203 |
|
| 1204 |
expand_debug_syms (second.debug_sym_link, 1); |
| 1205 |
gas_cgen_finish_insn (second.orig_insn, second.buffer, |
| 1206 |
CGEN_FIELDS_BITSIZE (&second.fields), 0, NULL); |
| 1207 |
} |
| 1208 |
|
| 1209 |
else if (can_make_parallel (&second, &first) == NULL) |
| 1210 |
{ |
| 1211 |
|
| 1212 |
expand_debug_syms (second.debug_sym_link, 1); |
| 1213 |
gas_cgen_finish_insn (second.orig_insn, second.buffer, |
| 1214 |
CGEN_FIELDS_BITSIZE (&second.fields), 0, NULL); |
| 1215 |
|
| 1216 |
|
| 1217 |
make_parallel (first.buffer); |
| 1218 |
|
| 1219 |
|
| 1220 |
gas_cgen_restore_fixups (0); |
| 1221 |
|
| 1222 |
|
| 1223 |
expand_debug_syms (first.debug_sym_link, 1); |
| 1224 |
gas_cgen_finish_insn (first.orig_insn, first.buffer, |
| 1225 |
CGEN_FIELDS_BITSIZE (&first.fields), 0, NULL); |
| 1226 |
} |
| 1227 |
else |
| 1228 |
{ |
| 1229 |
as_bad ("'%s': %s", str2, errmsg); |
| 1230 |
return; |
| 1231 |
} |
| 1232 |
|
| 1233 |
if (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL) |
| 1234 |
|| CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL)) |
| 1235 |
m32r_flags |= E_M32R_HAS_HIDDEN_INST; |
| 1236 |
if (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL_M32R) |
| 1237 |
|| CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL_M32R)) |
| 1238 |
m32r_flags |= E_M32R_HAS_BIT_INST; |
| 1239 |
if (CGEN_INSN_ATTR_VALUE (first.insn, CGEN_INSN_SPECIAL_FLOAT) |
| 1240 |
|| CGEN_INSN_ATTR_VALUE (second.insn, CGEN_INSN_SPECIAL_FLOAT)) |
| 1241 |
m32r_flags |= E_M32R_HAS_FLOAT_INST; |
| 1242 |
|
| 1243 |
|
| 1244 |
prev_seg = now_seg; |
| 1245 |
prev_subseg = now_subseg; |
| 1246 |
} |
| 1247 |
|
| 1248 |
void |
| 1249 |
md_assemble (str) |
| 1250 |
char *str; |
| 1251 |
{ |
| 1252 |
m32r_insn insn; |
| 1253 |
char *errmsg; |
| 1254 |
char *str2 = NULL; |
| 1255 |
|
| 1256 |
|
| 1257 |
gas_cgen_init_parse (); |
| 1258 |
|
| 1259 |
|
| 1260 |
if ((str2 = strstr (str, "||")) != NULL) |
| 1261 |
{ |
| 1262 |
assemble_two_insns (str, str2, 1); |
| 1263 |
m32r_flags |= E_M32R_HAS_PARALLEL; |
| 1264 |
return; |
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
if ((str2 = strstr (str, "->")) != NULL) |
| 1269 |
{ |
| 1270 |
assemble_two_insns (str, str2, 0); |
| 1271 |
return; |
| 1272 |
} |
| 1273 |
|
| 1274 |
insn.debug_sym_link = debug_sym_link; |
| 1275 |
debug_sym_link = (sym_linkS *) 0; |
| 1276 |
|
| 1277 |
insn.insn = m32r_cgen_assemble_insn |
| 1278 |
(gas_cgen_cpu_desc, str, &insn.fields, insn.buffer, & errmsg); |
| 1279 |
|
| 1280 |
if (!insn.insn) |
| 1281 |
{ |
| 1282 |
as_bad (errmsg); |
| 1283 |
return; |
| 1284 |
} |
| 1285 |
|
| 1286 |
#ifdef E_M32R2_ARCH |
| 1287 |
if ((enable_m32rx == 1) |
| 1288 |
|
| 1289 |
&& ((CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_MACH) |
| 1290 |
& (1 << MACH_M32R2)) |
| 1291 |
&& !((CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_MACH) |
| 1292 |
& (1 << MACH_M32RX))))) |
| 1293 |
{ |
| 1294 |
|
| 1295 |
as_bad (_("instruction '%s' is for the M32R2 only"), str); |
| 1296 |
return; |
| 1297 |
} |
| 1298 |
else if ((! enable_special |
| 1299 |
&& CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL)) |
| 1300 |
|| (! enable_special_m32r |
| 1301 |
&& CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL_M32R))) |
| 1302 |
#else |
| 1303 |
if (! enable_special |
| 1304 |
&& CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL)) |
| 1305 |
#endif |
| 1306 |
{ |
| 1307 |
|
| 1308 |
as_bad (_("unknown instruction '%s'"), str); |
| 1309 |
return; |
| 1310 |
} |
| 1311 |
else if (! enable_m32rx |
| 1312 |
&& CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_MACH) == (1 << MACH_M32RX)) |
| 1313 |
{ |
| 1314 |
|
| 1315 |
as_bad (_("instruction '%s' is for the M32RX only"), str); |
| 1316 |
return; |
| 1317 |
} |
| 1318 |
|
| 1319 |
if (CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL)) |
| 1320 |
m32r_flags |= E_M32R_HAS_HIDDEN_INST; |
| 1321 |
if (CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL_M32R)) |
| 1322 |
m32r_flags |= E_M32R_HAS_BIT_INST; |
| 1323 |
if (CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_SPECIAL_FLOAT)) |
| 1324 |
m32r_flags |= E_M32R_HAS_FLOAT_INST; |
| 1325 |
|
| 1326 |
if (CGEN_INSN_BITSIZE (insn.insn) == 32) |
| 1327 |
{ |
| 1328 |
|
| 1329 |
if (prev_insn.insn || seen_relaxable_p) |
| 1330 |
{ |
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
fill_insn (0); |
| 1335 |
} |
| 1336 |
|
| 1337 |
expand_debug_syms (insn.debug_sym_link, 2); |
| 1338 |
|
| 1339 |
|
| 1340 |
gas_cgen_finish_insn (insn.insn, insn.buffer, |
| 1341 |
CGEN_FIELDS_BITSIZE (&insn.fields), 1, NULL); |
| 1342 |
} |
| 1343 |
else |
| 1344 |
{ |
| 1345 |
int on_32bit_boundary_p; |
| 1346 |
int swap = FALSE; |
| 1347 |
|
| 1348 |
if (CGEN_INSN_BITSIZE (insn.insn) != 16) |
| 1349 |
abort (); |
| 1350 |
|
| 1351 |
insn.orig_insn = insn.insn; |
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
if (prev_insn.insn && seen_relaxable_p && optimize) |
| 1358 |
fill_insn (0); |
| 1359 |
|
| 1360 |
if (enable_m32rx) |
| 1361 |
{ |
| 1362 |
|
| 1363 |
|
| 1364 |
{ |
| 1365 |
CGEN_FIELDS tmp_fields; |
| 1366 |
insn.insn = cgen_lookup_get_insn_operands |
| 1367 |
(gas_cgen_cpu_desc, NULL, INSN_VALUE (insn.buffer), NULL, |
| 1368 |
16, insn.indices, &tmp_fields); |
| 1369 |
} |
| 1370 |
|
| 1371 |
if (insn.insn == NULL) |
| 1372 |
as_fatal (_("internal error: lookup/get operands failed")); |
| 1373 |
} |
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
on_32bit_boundary_p = prev_insn.insn == NULL; |
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
if (parallel() && on_32bit_boundary_p) |
| 1382 |
{ |
| 1383 |
frag_wane (frag_now); |
| 1384 |
frag_new (0); |
| 1385 |
} |
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
if (! on_32bit_boundary_p |
| 1398 |
&& parallel () |
| 1399 |
&& CGEN_INSN_ATTR_VALUE (insn.orig_insn, CGEN_INSN_RELAXABLE) == 0 |
| 1400 |
&& ! writes_to_pc (&prev_insn) |
| 1401 |
&& ! first_writes_to_seconds_operands (&prev_insn, &insn, FALSE)) |
| 1402 |
{ |
| 1403 |
if (can_make_parallel (&prev_insn, &insn) == NULL) |
| 1404 |
make_parallel (insn.buffer); |
| 1405 |
else if (can_make_parallel (&insn, &prev_insn) == NULL) |
| 1406 |
swap = TRUE; |
| 1407 |
} |
| 1408 |
|
| 1409 |
expand_debug_syms (insn.debug_sym_link, 1); |
| 1410 |
|
| 1411 |
{ |
| 1412 |
int i; |
| 1413 |
finished_insnS fi; |
| 1414 |
|
| 1415 |
|
| 1416 |
frag_grow (4); |
| 1417 |
|
| 1418 |
gas_cgen_finish_insn (insn.orig_insn, insn.buffer, |
| 1419 |
CGEN_FIELDS_BITSIZE (&insn.fields), |
| 1420 |
1 , &fi); |
| 1421 |
insn.addr = fi.addr; |
| 1422 |
insn.frag = fi.frag; |
| 1423 |
insn.num_fixups = fi.num_fixups; |
| 1424 |
for (i = 0; i < fi.num_fixups; ++i) |
| 1425 |
insn.fixups[i] = fi.fixups[i]; |
| 1426 |
} |
| 1427 |
|
| 1428 |
if (swap) |
| 1429 |
{ |
| 1430 |
int i, tmp; |
| 1431 |
|
| 1432 |
#define SWAP_BYTES(a,b) tmp = a; a = b; b = tmp |
| 1433 |
|
| 1434 |
|
| 1435 |
SWAP_BYTES (prev_insn.addr[0], insn.addr[0]); |
| 1436 |
SWAP_BYTES (prev_insn.addr[1], insn.addr[1]); |
| 1437 |
|
| 1438 |
target_make_parallel (insn.addr); |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
if (prev_insn.frag->fr_opcode == prev_insn.addr) |
| 1443 |
prev_insn.frag->fr_opcode = insn.addr; |
| 1444 |
else if (insn.frag->fr_opcode == insn.addr) |
| 1445 |
insn.frag->fr_opcode = prev_insn.addr; |
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
if (prev_insn.frag != insn.frag) |
| 1450 |
{ |
| 1451 |
for (i = 0; i < prev_insn.num_fixups; ++i) |
| 1452 |
prev_insn.fixups[i]->fx_frag = insn.frag; |
| 1453 |
for (i = 0; i < insn.num_fixups; ++i) |
| 1454 |
insn.fixups[i]->fx_frag = prev_insn.frag; |
| 1455 |
} |
| 1456 |
else |
| 1457 |
{ |
| 1458 |
|
| 1459 |
|
| 1460 |
|
| 1461 |
for (i = 0; i < prev_insn.num_fixups; ++i) |
| 1462 |
prev_insn.fixups[i]->fx_where += 2; |
| 1463 |
for (i = 0; i < insn.num_fixups; ++i) |
| 1464 |
insn.fixups[i]->fx_where -= 2; |
| 1465 |
} |
| 1466 |
} |
| 1467 |
|
| 1468 |
|
| 1469 |
|
| 1470 |
if (on_32bit_boundary_p) |
| 1471 |
prev_insn = insn; |
| 1472 |
else |
| 1473 |
prev_insn.insn = NULL; |
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
if (on_32bit_boundary_p |
| 1478 |
&& CGEN_INSN_ATTR_VALUE (insn.orig_insn, CGEN_INSN_FILL_SLOT) != 0) |
| 1479 |
fill_insn (0); |
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
if (CGEN_INSN_ATTR_VALUE (insn.orig_insn, CGEN_INSN_RELAXABLE) != 0) |
| 1485 |
seen_relaxable_p = 1; |
| 1486 |
} |
| 1487 |
|
| 1488 |
|
| 1489 |
prev_seg = now_seg; |
| 1490 |
prev_subseg = now_subseg; |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
void |
| 1497 |
md_operand (expressionP) |
| 1498 |
expressionS *expressionP; |
| 1499 |
{ |
| 1500 |
if (*input_line_pointer == '#') |
| 1501 |
{ |
| 1502 |
input_line_pointer++; |
| 1503 |
expression (expressionP); |
| 1504 |
} |
| 1505 |
} |
| 1506 |
|
| 1507 |
valueT |
| 1508 |
md_section_align (segment, size) |
| 1509 |
segT segment; |
| 1510 |
valueT size; |
| 1511 |
{ |
| 1512 |
int align = bfd_get_section_alignment (stdoutput, segment); |
| 1513 |
return ((size + (1 << align) - 1) & (-1 << align)); |
| 1514 |
} |
| 1515 |
|
| 1516 |
symbolS * |
| 1517 |
md_undefined_symbol (name) |
| 1518 |
char *name ATTRIBUTE_UNUSED; |
| 1519 |
{ |
| 1520 |
return 0; |
| 1521 |
} |
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
static void |
| 1531 |
m32r_scomm (ignore) |
| 1532 |
int ignore ATTRIBUTE_UNUSED; |
| 1533 |
{ |
| 1534 |
register char *name; |
| 1535 |
register char c; |
| 1536 |
register char *p; |
| 1537 |
offsetT size; |
| 1538 |
register symbolS *symbolP; |
| 1539 |
offsetT align; |
| 1540 |
int align2; |
| 1541 |
|
| 1542 |
name = input_line_pointer; |
| 1543 |
c = get_symbol_end (); |
| 1544 |
|
| 1545 |
|
| 1546 |
p = input_line_pointer; |
| 1547 |
*p = c; |
| 1548 |
SKIP_WHITESPACE (); |
| 1549 |
if (*input_line_pointer != ',') |
| 1550 |
{ |
| 1551 |
as_bad (_("Expected comma after symbol-name: rest of line ignored.")); |
| 1552 |
ignore_rest_of_line (); |
| 1553 |
return; |
| 1554 |
} |
| 1555 |
|
| 1556 |
|
| 1557 |
input_line_pointer++; |
| 1558 |
if ((size = get_absolute_expression ()) < 0) |
| 1559 |
{ |
| 1560 |
|
| 1561 |
as_warn (_(".SCOMMon length (%ld.) <0! Ignored."), (long) size); |
| 1562 |
ignore_rest_of_line (); |
| 1563 |
return; |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
if (*input_line_pointer != ',') |
| 1568 |
align = 8; |
| 1569 |
else |
| 1570 |
{ |
| 1571 |
++input_line_pointer; |
| 1572 |
align = get_absolute_expression (); |
| 1573 |
if (align <= 0) |
| 1574 |
{ |
| 1575 |
as_warn (_("ignoring bad alignment")); |
| 1576 |
align = 8; |
| 1577 |
} |
| 1578 |
} |
| 1579 |
|
| 1580 |
|
| 1581 |
if (align) |
| 1582 |
{ |
| 1583 |
for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2) |
| 1584 |
continue; |
| 1585 |
if (align != 1) |
| 1586 |
{ |
| 1587 |
as_bad (_("Common alignment not a power of 2")); |
| 1588 |
ignore_rest_of_line (); |
| 1589 |
return; |
| 1590 |
} |
| 1591 |
} |
| 1592 |
else |
| 1593 |
align2 = 0; |
| 1594 |
|
| 1595 |
*p = 0; |
| 1596 |
symbolP = symbol_find_or_make (name); |
| 1597 |
*p = c; |
| 1598 |
|
| 1599 |
if (S_IS_DEFINED (symbolP)) |
| 1600 |
{ |
| 1601 |
|
| 1602 |
as_bad (_("Ignoring attempt to re-define symbol `%s'."), |
| 1603 |
S_GET_NAME (symbolP)); |
| 1604 |
ignore_rest_of_line (); |
| 1605 |
return; |
| 1606 |
} |
| 1607 |
|
| 1608 |
if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size) |
| 1609 |
{ |
| 1610 |
|
| 1611 |
as_bad (_("Length of .scomm \"%s\" is already %ld. Not changed to %ld."), |
| 1612 |
S_GET_NAME (symbolP), |
| 1613 |
(long) S_GET_VALUE (symbolP), |
| 1614 |
(long) size); |
| 1615 |
|
| 1616 |
ignore_rest_of_line (); |
| 1617 |
return; |
| 1618 |
} |
| 1619 |
|
| 1620 |
if (symbol_get_obj (symbolP)->local) |
| 1621 |
{ |
| 1622 |
segT old_sec = now_seg; |
| 1623 |
int old_subsec = now_subseg; |
| 1624 |
char *pfrag; |
| 1625 |
|
| 1626 |
record_alignment (sbss_section, align2); |
| 1627 |
subseg_set (sbss_section, 0); |
| 1628 |
|
| 1629 |
if (align2) |
| 1630 |
frag_align (align2, 0, 0); |
| 1631 |
|
| 1632 |
if (S_GET_SEGMENT (symbolP) == sbss_section) |
| 1633 |
symbol_get_frag (symbolP)->fr_symbol = 0; |
| 1634 |
|
| 1635 |
symbol_set_frag (symbolP, frag_now); |
| 1636 |
|
| 1637 |
pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size, |
| 1638 |
(char *) 0); |
| 1639 |
*pfrag = 0; |
| 1640 |
S_SET_SIZE (symbolP, size); |
| 1641 |
S_SET_SEGMENT (symbolP, sbss_section); |
| 1642 |
S_CLEAR_EXTERNAL (symbolP); |
| 1643 |
subseg_set (old_sec, old_subsec); |
| 1644 |
} |
| 1645 |
else |
| 1646 |
{ |
| 1647 |
S_SET_VALUE (symbolP, (valueT) size); |
| 1648 |
S_SET_ALIGN (symbolP, align2); |
| 1649 |
S_SET_EXTERNAL (symbolP); |
| 1650 |
S_SET_SEGMENT (symbolP, &scom_section); |
| 1651 |
} |
| 1652 |
|
| 1653 |
demand_empty_rest_of_line (); |
| 1654 |
} |
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
const relax_typeS md_relax_table[] = |
| 1661 |
{ |
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
{1, 1, 0, 0}, |
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
{511 - 2 - 2, -512 - 2 + 2, 0, 2 }, |
| 1680 |
|
| 1681 |
{0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 }, |
| 1682 |
|
| 1683 |
{0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 } |
| 1684 |
}; |
| 1685 |
|
| 1686 |
long |
| 1687 |
m32r_relax_frag (segment, fragP, stretch) |
| 1688 |
segT segment; |
| 1689 |
fragS *fragP; |
| 1690 |
long stretch; |
| 1691 |
{ |
| 1692 |
|
| 1693 |
long address = fragP->fr_address + fragP->fr_fix - 2; |
| 1694 |
long growth = 0; |
| 1695 |
|
| 1696 |
|
| 1697 |
if (fragP->fr_subtype == 2) |
| 1698 |
{ |
| 1699 |
if ((address & 3) != 0) |
| 1700 |
{ |
| 1701 |
fragP->fr_subtype = 3; |
| 1702 |
growth = 2; |
| 1703 |
} |
| 1704 |
} |
| 1705 |
else if (fragP->fr_subtype == 3) |
| 1706 |
{ |
| 1707 |
if ((address & 3) == 0) |
| 1708 |
{ |
| 1709 |
fragP->fr_subtype = 2; |
| 1710 |
growth = -2; |
| 1711 |
} |
| 1712 |
} |
| 1713 |
else |
| 1714 |
{ |
| 1715 |
growth = relax_frag (segment, fragP, stretch); |
| 1716 |
|
| 1717 |
|
| 1718 |
if (fragP->fr_subtype == 2 && (address & 3) != 0) |
| 1719 |
{ |
| 1720 |
fragP->fr_subtype = 3; |
| 1721 |
growth += 2; |
| 1722 |
} |
| 1723 |
} |
| 1724 |
|
| 1725 |
return growth; |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
|
| 1735 |
|
| 1736 |
|
| 1737 |
|
| 1738 |
|
| 1739 |
int |
| 1740 |
md_estimate_size_before_relax (fragP, segment) |
| 1741 |
fragS *fragP; |
| 1742 |
segT segment; |
| 1743 |
{ |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
if (S_GET_SEGMENT (fragP->fr_symbol) != segment |
| 1751 |
|| S_IS_EXTERNAL (fragP->fr_symbol) |
| 1752 |
|| S_IS_WEAK (fragP->fr_symbol)) |
| 1753 |
{ |
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
fragP->fr_subtype = 2; |
| 1758 |
|
| 1759 |
{ |
| 1760 |
const CGEN_INSN *insn; |
| 1761 |
int i; |
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
for (i = 0, insn = fragP->fr_cgen.insn; i < 4; i++, insn++) |
| 1768 |
{ |
| 1769 |
if ((strcmp (CGEN_INSN_MNEMONIC (insn), |
| 1770 |
CGEN_INSN_MNEMONIC (fragP->fr_cgen.insn)) |
| 1771 |
== 0) |
| 1772 |
&& CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED)) |
| 1773 |
break; |
| 1774 |
} |
| 1775 |
if (i == 4) |
| 1776 |
abort (); |
| 1777 |
|
| 1778 |
fragP->fr_cgen.insn = insn; |
| 1779 |
return 2; |
| 1780 |
} |
| 1781 |
} |
| 1782 |
|
| 1783 |
return md_relax_table[fragP->fr_subtype].rlx_length; |
| 1784 |
} |
| 1785 |
|
| 1786 |
|
| 1787 |
|
| 1788 |
|
| 1789 |
|
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
void |
| 1794 |
md_convert_frag (abfd, sec, fragP) |
| 1795 |
bfd *abfd ATTRIBUTE_UNUSED; |
| 1796 |
segT sec; |
| 1797 |
fragS *fragP; |
| 1798 |
{ |
| 1799 |
char *opcode; |
| 1800 |
char *displacement; |
| 1801 |
int target_address; |
| 1802 |
int opcode_address; |
| 1803 |
int extension; |
| 1804 |
int addend; |
| 1805 |
|
| 1806 |
opcode = fragP->fr_opcode; |
| 1807 |
|
| 1808 |
|
| 1809 |
opcode_address = fragP->fr_address + fragP->fr_fix - 2; |
| 1810 |
|
| 1811 |
switch (fragP->fr_subtype) |
| 1812 |
{ |
| 1813 |
case 1: |
| 1814 |
extension = 0; |
| 1815 |
displacement = &opcode[1]; |
| 1816 |
break; |
| 1817 |
case 2: |
| 1818 |
opcode[0] |= 0x80; |
| 1819 |
extension = 2; |
| 1820 |
displacement = &opcode[1]; |
| 1821 |
break; |
| 1822 |
case 3: |
| 1823 |
opcode[2] = opcode[0] | 0x80; |
| 1824 |
md_number_to_chars (opcode, PAR_NOP_INSN, 2); |
| 1825 |
opcode_address += 2; |
| 1826 |
extension = 4; |
| 1827 |
displacement = &opcode[3]; |
| 1828 |
break; |
| 1829 |
default: |
| 1830 |
abort (); |
| 1831 |
} |
| 1832 |
|
| 1833 |
if (S_GET_SEGMENT (fragP->fr_symbol) != sec |
| 1834 |
|| S_IS_EXTERNAL (fragP->fr_symbol) |
| 1835 |
|| S_IS_WEAK (fragP->fr_symbol)) |
| 1836 |
{ |
| 1837 |
|
| 1838 |
if (fragP->fr_offset & 3) |
| 1839 |
as_warn (_("Addend to unresolved symbol not on word boundary.")); |
| 1840 |
#ifdef USE_M32R_OLD_RELOC |
| 1841 |
addend = fragP->fr_offset >> 2; |
| 1842 |
#else |
| 1843 |
addend = 0; |
| 1844 |
#endif |
| 1845 |
} |
| 1846 |
else |
| 1847 |
{ |
| 1848 |
|
| 1849 |
target_address = S_GET_VALUE (fragP->fr_symbol) + fragP->fr_offset; |
| 1850 |
addend = (target_address - (opcode_address & -4)) >> 2; |
| 1851 |
} |
| 1852 |
|
| 1853 |
|
| 1854 |
|
| 1855 |
|
| 1856 |
if (S_GET_SEGMENT (fragP->fr_symbol) != sec |
| 1857 |
|| S_IS_EXTERNAL (fragP->fr_symbol) |
| 1858 |
|| S_IS_WEAK (fragP->fr_symbol)) |
| 1859 |
{ |
| 1860 |
fixS *fixP; |
| 1861 |
|
| 1862 |
assert (fragP->fr_subtype != 1); |
| 1863 |
assert (fragP->fr_cgen.insn != 0); |
| 1864 |
|
| 1865 |
fixP = gas_cgen_record_fixup (fragP, |
| 1866 |
|
| 1867 |
fragP->fr_fix + extension - 4, |
| 1868 |
fragP->fr_cgen.insn, |
| 1869 |
4 , |
| 1870 |
|
| 1871 |
cgen_operand_lookup_by_num (gas_cgen_cpu_desc, |
| 1872 |
M32R_OPERAND_DISP24), |
| 1873 |
fragP->fr_cgen.opinfo, |
| 1874 |
fragP->fr_symbol, fragP->fr_offset); |
| 1875 |
if (fragP->fr_cgen.opinfo) |
| 1876 |
fixP->fx_r_type = fragP->fr_cgen.opinfo; |
| 1877 |
} |
| 1878 |
|
| 1879 |
#define SIZE_FROM_RELAX_STATE(n) ((n) == 1 ? 1 : 3) |
| 1880 |
|
| 1881 |
md_number_to_chars (displacement, (valueT) addend, |
| 1882 |
SIZE_FROM_RELAX_STATE (fragP->fr_subtype)); |
| 1883 |
|
| 1884 |
fragP->fr_fix += extension; |
| 1885 |
} |
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
long |
| 1893 |
md_pcrel_from_section (fixP, sec) |
| 1894 |
fixS *fixP; |
| 1895 |
segT sec; |
| 1896 |
{ |
| 1897 |
if (fixP->fx_addsy != (symbolS *) NULL |
| 1898 |
&& (! S_IS_DEFINED (fixP->fx_addsy) |
| 1899 |
|| S_GET_SEGMENT (fixP->fx_addsy) != sec |
| 1900 |
|| S_IS_EXTERNAL (fixP->fx_addsy) |
| 1901 |
|| S_IS_WEAK (fixP->fx_addsy))) |
| 1902 |
{ |
| 1903 |
if (S_GET_SEGMENT (fixP->fx_addsy) != sec |
| 1904 |
&& S_IS_DEFINED (fixP->fx_addsy) |
| 1905 |
&& ! S_IS_EXTERNAL (fixP->fx_addsy) |
| 1906 |
&& ! S_IS_WEAK (fixP->fx_addsy)) |
| 1907 |
return fixP->fx_offset; |
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
return 0; |
| 1912 |
} |
| 1913 |
|
| 1914 |
return (fixP->fx_frag->fr_address + fixP->fx_where) & -4L; |
| 1915 |
} |
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
bfd_reloc_code_real_type |
| 1922 |
md_cgen_lookup_reloc (insn, operand, fixP) |
| 1923 |
const CGEN_INSN *insn ATTRIBUTE_UNUSED; |
| 1924 |
const CGEN_OPERAND *operand; |
| 1925 |
fixS *fixP; |
| 1926 |
{ |
| 1927 |
switch (operand->type) |
| 1928 |
{ |
| 1929 |
case M32R_OPERAND_DISP8: return BFD_RELOC_M32R_10_PCREL; |
| 1930 |
case M32R_OPERAND_DISP16: return BFD_RELOC_M32R_18_PCREL; |
| 1931 |
case M32R_OPERAND_DISP24: return BFD_RELOC_M32R_26_PCREL; |
| 1932 |
case M32R_OPERAND_UIMM24: return BFD_RELOC_M32R_24; |
| 1933 |
case M32R_OPERAND_HI16: |
| 1934 |
case M32R_OPERAND_SLO16: |
| 1935 |
case M32R_OPERAND_ULO16: |
| 1936 |
|
| 1937 |
if (fixP->fx_cgen.opinfo != 0) |
| 1938 |
return fixP->fx_cgen.opinfo; |
| 1939 |
break; |
| 1940 |
default: |
| 1941 |
|
| 1942 |
break; |
| 1943 |
} |
| 1944 |
return BFD_RELOC_NONE; |
| 1945 |
} |
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
static void m32r_record_hi16 PARAMS ((int, fixS *, segT)); |
| 1950 |
|
| 1951 |
static void |
| 1952 |
m32r_record_hi16 (reloc_type, fixP, seg) |
| 1953 |
int reloc_type; |
| 1954 |
fixS *fixP; |
| 1955 |
segT seg ATTRIBUTE_UNUSED; |
| 1956 |
{ |
| 1957 |
struct m32r_hi_fixup *hi_fixup; |
| 1958 |
|
| 1959 |
assert (reloc_type == BFD_RELOC_M32R_HI16_SLO |
| 1960 |
|| reloc_type == BFD_RELOC_M32R_HI16_ULO); |
| 1961 |
|
| 1962 |
hi_fixup = ((struct m32r_hi_fixup *) |
| 1963 |
xmalloc (sizeof (struct m32r_hi_fixup))); |
| 1964 |
hi_fixup->fixp = fixP; |
| 1965 |
hi_fixup->seg = now_seg; |
| 1966 |
hi_fixup->next = m32r_hi_fixup_list; |
| 1967 |
|
| 1968 |
m32r_hi_fixup_list = hi_fixup; |
| 1969 |
} |
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
fixS * |
| 1975 |
m32r_cgen_record_fixup_exp (frag, where, insn, length, operand, opinfo, exp) |
| 1976 |
fragS *frag; |
| 1977 |
int where; |
| 1978 |
const CGEN_INSN *insn; |
| 1979 |
int length; |
| 1980 |
const CGEN_OPERAND *operand; |
| 1981 |
int opinfo; |
| 1982 |
expressionS *exp; |
| 1983 |
{ |
| 1984 |
fixS *fixP; |
| 1985 |
bfd_reloc_code_real_type r_type = BFD_RELOC_UNUSED; |
| 1986 |
|
| 1987 |
if (m32r_check_fixup (exp, &r_type)) |
| 1988 |
as_bad (_("Invalid PIC expression.")); |
| 1989 |
|
| 1990 |
fixP = gas_cgen_record_fixup_exp (frag, where, insn, length, |
| 1991 |
operand, opinfo, exp); |
| 1992 |
|
| 1993 |
switch (operand->type) |
| 1994 |
{ |
| 1995 |
case M32R_OPERAND_HI16: |
| 1996 |
|
| 1997 |
if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO |
| 1998 |
|| fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO) |
| 1999 |
m32r_record_hi16 (fixP->fx_cgen.opinfo, fixP, now_seg); |
| 2000 |
break; |
| 2001 |
|
| 2002 |
default: |
| 2003 |
|
| 2004 |
break; |
| 2005 |
} |
| 2006 |
|
| 2007 |
switch (r_type) |
| 2008 |
{ |
| 2009 |
case BFD_RELOC_UNUSED: |
| 2010 |
default: |
| 2011 |
return fixP; |
| 2012 |
|
| 2013 |
case BFD_RELOC_M32R_GOTPC24: |
| 2014 |
if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO) |
| 2015 |
r_type = BFD_RELOC_M32R_GOTPC_HI_SLO; |
| 2016 |
else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO) |
| 2017 |
r_type = BFD_RELOC_M32R_GOTPC_HI_ULO; |
| 2018 |
else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_LO16) |
| 2019 |
r_type = BFD_RELOC_M32R_GOTPC_LO; |
| 2020 |
break; |
| 2021 |
case BFD_RELOC_M32R_GOT24: |
| 2022 |
if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO) |
| 2023 |
r_type = BFD_RELOC_M32R_GOT16_HI_SLO; |
| 2024 |
else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO) |
| 2025 |
r_type = BFD_RELOC_M32R_GOT16_HI_ULO; |
| 2026 |
else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_LO16) |
| 2027 |
r_type = BFD_RELOC_M32R_GOT16_LO; |
| 2028 |
break; |
| 2029 |
case BFD_RELOC_M32R_GOTOFF: |
| 2030 |
if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_SLO) |
| 2031 |
r_type = BFD_RELOC_M32R_GOTOFF_HI_SLO; |
| 2032 |
else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_HI16_ULO) |
| 2033 |
r_type = BFD_RELOC_M32R_GOTOFF_HI_ULO; |
| 2034 |
else if (fixP->fx_cgen.opinfo == BFD_RELOC_M32R_LO16) |
| 2035 |
r_type = BFD_RELOC_M32R_GOTOFF_LO; |
| 2036 |
break; |
| 2037 |
case BFD_RELOC_M32R_26_PLTREL: |
| 2038 |
as_bad (_("Invalid PIC expression.")); |
| 2039 |
break; |
| 2040 |
} |
| 2041 |
|
| 2042 |
fixP->fx_r_type = r_type; |
| 2043 |
|
| 2044 |
return fixP; |
| 2045 |
} |
| 2046 |
|
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
#define FX_OPINFO_R_TYPE(f) ((f)->fx_cgen.opinfo) |
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
void |
| 2057 |
m32r_frob_file () |
| 2058 |
{ |
| 2059 |
struct m32r_hi_fixup *l; |
| 2060 |
|
| 2061 |
for (l = m32r_hi_fixup_list; l != NULL; l = l->next) |
| 2062 |
{ |
| 2063 |
segment_info_type *seginfo; |
| 2064 |
int pass; |
| 2065 |
|
| 2066 |
assert (FX_OPINFO_R_TYPE (l->fixp) == BFD_RELOC_M32R_HI16_SLO |
| 2067 |
|| FX_OPINFO_R_TYPE (l->fixp) == BFD_RELOC_M32R_HI16_ULO); |
| 2068 |
|
| 2069 |
|
| 2070 |
if (l->fixp->fx_next != NULL |
| 2071 |
&& FX_OPINFO_R_TYPE (l->fixp->fx_next) == BFD_RELOC_M32R_LO16 |
| 2072 |
&& l->fixp->fx_addsy == l->fixp->fx_next->fx_addsy |
| 2073 |
&& l->fixp->fx_offset == l->fixp->fx_next->fx_offset) |
| 2074 |
continue; |
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
seginfo = seg_info (l->seg); |
| 2082 |
for (pass = 0; pass < 2; pass++) |
| 2083 |
{ |
| 2084 |
fixS *f; |
| 2085 |
fixS *prev; |
| 2086 |
|
| 2087 |
prev = NULL; |
| 2088 |
for (f = seginfo->fix_root; f != NULL; f = f->fx_next) |
| 2089 |
{ |
| 2090 |
|
| 2091 |
if (FX_OPINFO_R_TYPE (f) == BFD_RELOC_M32R_LO16 |
| 2092 |
&& f->fx_addsy == l->fixp->fx_addsy |
| 2093 |
&& f->fx_offset == l->fixp->fx_offset |
| 2094 |
&& (pass == 1 |
| 2095 |
|| prev == NULL |
| 2096 |
|| (FX_OPINFO_R_TYPE (prev) != BFD_RELOC_M32R_HI16_SLO |
| 2097 |
&& FX_OPINFO_R_TYPE (prev) != BFD_RELOC_M32R_HI16_ULO) |
| 2098 |
|| prev->fx_addsy != f->fx_addsy |
| 2099 |
|| prev->fx_offset != f->fx_offset)) |
| 2100 |
{ |
| 2101 |
fixS **pf; |
| 2102 |
|
| 2103 |
|
| 2104 |
for (pf = &seginfo->fix_root; |
| 2105 |
*pf != l->fixp; |
| 2106 |
pf = & (*pf)->fx_next) |
| 2107 |
assert (*pf != NULL); |
| 2108 |
|
| 2109 |
*pf = l->fixp->fx_next; |
| 2110 |
|
| 2111 |
l->fixp->fx_next = f; |
| 2112 |
if (prev == NULL) |
| 2113 |
seginfo->fix_root = l->fixp; |
| 2114 |
else |
| 2115 |
prev->fx_next = l->fixp; |
| 2116 |
|
| 2117 |
break; |
| 2118 |
} |
| 2119 |
|
| 2120 |
prev = f; |
| 2121 |
} |
| 2122 |
|
| 2123 |
if (f != NULL) |
| 2124 |
break; |
| 2125 |
|
| 2126 |
if (pass == 1 |
| 2127 |
&& warn_unmatched_high) |
| 2128 |
as_warn_where (l->fixp->fx_file, l->fixp->fx_line, |
| 2129 |
_("Unmatched high/shigh reloc")); |
| 2130 |
} |
| 2131 |
} |
| 2132 |
} |
| 2133 |
|
| 2134 |
|
| 2135 |
|
| 2136 |
|
| 2137 |
|
| 2138 |
int |
| 2139 |
m32r_force_relocation (fix) |
| 2140 |
fixS *fix; |
| 2141 |
{ |
| 2142 |
if (generic_force_reloc (fix)) |
| 2143 |
return 1; |
| 2144 |
|
| 2145 |
if (! m32r_relax) |
| 2146 |
return 0; |
| 2147 |
|
| 2148 |
return fix->fx_pcrel; |
| 2149 |
} |
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
void |
| 2154 |
md_number_to_chars (buf, val, n) |
| 2155 |
char *buf; |
| 2156 |
valueT val; |
| 2157 |
int n; |
| 2158 |
{ |
| 2159 |
if (target_big_endian) |
| 2160 |
number_to_chars_bigendian (buf, val, n); |
| 2161 |
else |
| 2162 |
number_to_chars_littleendian (buf, val, n); |
| 2163 |
} |
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
#define MAX_LITTLENUMS 6 |
| 2172 |
|
| 2173 |
char * |
| 2174 |
md_atof (type, litP, sizeP) |
| 2175 |
char type; |
| 2176 |
char *litP; |
| 2177 |
int *sizeP; |
| 2178 |
{ |
| 2179 |
int i; |
| 2180 |
int prec; |
| 2181 |
LITTLENUM_TYPE words[MAX_LITTLENUMS]; |
| 2182 |
char *t; |
| 2183 |
|
| 2184 |
switch (type) |
| 2185 |
{ |
| 2186 |
case 'f': |
| 2187 |
case 'F': |
| 2188 |
case 's': |
| 2189 |
case 'S': |
| 2190 |
prec = 2; |
| 2191 |
break; |
| 2192 |
|
| 2193 |
case 'd': |
| 2194 |
case 'D': |
| 2195 |
case 'r': |
| 2196 |
case 'R': |
| 2197 |
prec = 4; |
| 2198 |
break; |
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
default: |
| 2204 |
*sizeP = 0; |
| 2205 |
return _("Bad call to md_atof()"); |
| 2206 |
} |
| 2207 |
|
| 2208 |
t = atof_ieee (input_line_pointer, type, words); |
| 2209 |
if (t) |
| 2210 |
input_line_pointer = t; |
| 2211 |
*sizeP = prec * sizeof (LITTLENUM_TYPE); |
| 2212 |
|
| 2213 |
if (target_big_endian) |
| 2214 |
{ |
| 2215 |
for (i = 0; i < prec; i++) |
| 2216 |
{ |
| 2217 |
md_number_to_chars (litP, (valueT) words[i], |
| 2218 |
sizeof (LITTLENUM_TYPE)); |
| 2219 |
litP += sizeof (LITTLENUM_TYPE); |
| 2220 |
} |
| 2221 |
} |
| 2222 |
else |
| 2223 |
{ |
| 2224 |
for (i = prec - 1; i >= 0; i--) |
| 2225 |
{ |
| 2226 |
md_number_to_chars (litP, (valueT) words[i], |
| 2227 |
sizeof (LITTLENUM_TYPE)); |
| 2228 |
litP += sizeof (LITTLENUM_TYPE); |
| 2229 |
} |
| 2230 |
} |
| 2231 |
|
| 2232 |
return 0; |
| 2233 |
} |
| 2234 |
|
| 2235 |
void |
| 2236 |
m32r_elf_section_change_hook () |
| 2237 |
{ |
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
if (prev_insn.insn || seen_relaxable_p) |
| 2243 |
(void) m32r_fill_insn (0); |
| 2244 |
} |
| 2245 |
|
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
bfd_boolean |
| 2250 |
m32r_fix_adjustable (fixP) |
| 2251 |
fixS *fixP; |
| 2252 |
{ |
| 2253 |
bfd_reloc_code_real_type reloc_type; |
| 2254 |
|
| 2255 |
if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
| 2256 |
{ |
| 2257 |
const CGEN_INSN *insn = NULL; |
| 2258 |
int opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
| 2259 |
const CGEN_OPERAND *operand = |
| 2260 |
cgen_operand_lookup_by_num(gas_cgen_cpu_desc, opindex); |
| 2261 |
reloc_type = md_cgen_lookup_reloc (insn, operand, fixP); |
| 2262 |
} |
| 2263 |
else |
| 2264 |
reloc_type = fixP->fx_r_type; |
| 2265 |
|
| 2266 |
if (fixP->fx_addsy == NULL) |
| 2267 |
return 1; |
| 2268 |
|
| 2269 |
|
| 2270 |
if (S_IS_EXTERN (fixP->fx_addsy)) |
| 2271 |
return 0; |
| 2272 |
if (S_IS_WEAK (fixP->fx_addsy)) |
| 2273 |
return 0; |
| 2274 |
|
| 2275 |
if (pic_code |
| 2276 |
&& (reloc_type == BFD_RELOC_M32R_24 |
| 2277 |
|| reloc_type == BFD_RELOC_M32R_26_PCREL |
| 2278 |
|| reloc_type == BFD_RELOC_M32R_HI16_SLO |
| 2279 |
|| reloc_type == BFD_RELOC_M32R_HI16_ULO |
| 2280 |
|| reloc_type == BFD_RELOC_M32R_LO16)) |
| 2281 |
return 0; |
| 2282 |
|
| 2283 |
if (reloc_type == BFD_RELOC_M32R_GOT24 |
| 2284 |
|| reloc_type == BFD_RELOC_M32R_26_PLTREL |
| 2285 |
|| reloc_type == BFD_RELOC_M32R_GOTPC_HI_SLO |
| 2286 |
|| reloc_type == BFD_RELOC_M32R_GOTPC_HI_ULO |
| 2287 |
|| reloc_type == BFD_RELOC_M32R_GOTPC_LO |
| 2288 |
|| reloc_type == BFD_RELOC_M32R_GOT16_HI_SLO |
| 2289 |
|| reloc_type == BFD_RELOC_M32R_GOT16_HI_ULO |
| 2290 |
|| reloc_type == BFD_RELOC_M32R_GOT16_LO) |
| 2291 |
return 0; |
| 2292 |
|
| 2293 |
|
| 2294 |
if (reloc_type == BFD_RELOC_VTABLE_INHERIT |
| 2295 |
|| reloc_type == BFD_RELOC_VTABLE_ENTRY) |
| 2296 |
return 0; |
| 2297 |
|
| 2298 |
return 1; |
| 2299 |
} |
| 2300 |
|
| 2301 |
void |
| 2302 |
m32r_elf_final_processing (void) |
| 2303 |
{ |
| 2304 |
if (use_parallel) |
| 2305 |
m32r_flags |= E_M32R_HAS_PARALLEL; |
| 2306 |
elf_elfheader (stdoutput)->e_flags |= m32r_flags; |
| 2307 |
} |
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
arelent * |
| 2313 |
tc_gen_reloc (section, fixP) |
| 2314 |
asection * section; |
| 2315 |
fixS * fixP; |
| 2316 |
{ |
| 2317 |
arelent * reloc; |
| 2318 |
bfd_reloc_code_real_type code; |
| 2319 |
|
| 2320 |
reloc = (arelent *) xmalloc (sizeof (arelent)); |
| 2321 |
|
| 2322 |
reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
| 2323 |
*reloc->sym_ptr_ptr = symbol_get_bfdsym (fixP->fx_addsy); |
| 2324 |
reloc->address = fixP->fx_frag->fr_address + fixP->fx_where; |
| 2325 |
|
| 2326 |
code = fixP->fx_r_type; |
| 2327 |
if (pic_code) |
| 2328 |
{ |
| 2329 |
#ifdef DEBUG_PIC |
| 2330 |
printf("%s",bfd_get_reloc_code_name(code)); |
| 2331 |
#endif |
| 2332 |
switch (code) |
| 2333 |
{ |
| 2334 |
case BFD_RELOC_M32R_26_PCREL: |
| 2335 |
code = BFD_RELOC_M32R_26_PLTREL; |
| 2336 |
break; |
| 2337 |
case BFD_RELOC_M32R_24: |
| 2338 |
if (fixP->fx_addsy != NULL |
| 2339 |
&& strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0) |
| 2340 |
code = BFD_RELOC_M32R_GOTPC24; |
| 2341 |
else |
| 2342 |
code = BFD_RELOC_M32R_GOT24; |
| 2343 |
break; |
| 2344 |
case BFD_RELOC_M32R_HI16_ULO: |
| 2345 |
if (fixP->fx_addsy != NULL |
| 2346 |
&& strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0) |
| 2347 |
code = BFD_RELOC_M32R_GOTPC_HI_ULO; |
| 2348 |
else |
| 2349 |
code = BFD_RELOC_M32R_GOT16_HI_ULO; |
| 2350 |
break; |
| 2351 |
case BFD_RELOC_M32R_HI16_SLO: |
| 2352 |
if (fixP->fx_addsy != NULL |
| 2353 |
&& strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0) |
| 2354 |
code = BFD_RELOC_M32R_GOTPC_HI_SLO; |
| 2355 |
else |
| 2356 |
code = BFD_RELOC_M32R_GOT16_HI_SLO; |
| 2357 |
break; |
| 2358 |
case BFD_RELOC_M32R_LO16: |
| 2359 |
if (fixP->fx_addsy != NULL |
| 2360 |
&& strcmp (S_GET_NAME (fixP->fx_addsy), GOT_NAME) == 0) |
| 2361 |
code = BFD_RELOC_M32R_GOTPC_LO; |
| 2362 |
else |
| 2363 |
code = BFD_RELOC_M32R_GOT16_LO; |
| 2364 |
break; |
| 2365 |
default: |
| 2366 |
break; |
| 2367 |
} |
| 2368 |
#ifdef DEBUG_PIC |
| 2369 |
printf(" => %s",bfd_get_reloc_code_name(code)); |
| 2370 |
#endif |
| 2371 |
} |
| 2372 |
|
| 2373 |
reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
| 2374 |
#ifdef DEBUG_PIC |
| 2375 |
printf(" => %s\n",reloc->howto->name); |
| 2376 |
#endif |
| 2377 |
if (reloc->howto == (reloc_howto_type *) NULL) |
| 2378 |
{ |
| 2379 |
as_bad_where (fixP->fx_file, fixP->fx_line, |
| 2380 |
_("internal error: can't export reloc type %d (`%s')"), |
| 2381 |
fixP->fx_r_type, bfd_get_reloc_code_name (code)); |
| 2382 |
return NULL; |
| 2383 |
} |
| 2384 |
|
| 2385 |
|
| 2386 |
if ( fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY |
| 2387 |
|| fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT) |
| 2388 |
reloc->addend = fixP->fx_offset; |
| 2389 |
else if ((!pic_code |
| 2390 |
&& code != BFD_RELOC_M32R_26_PLTREL) |
| 2391 |
&& fixP->fx_pcrel |
| 2392 |
&& fixP->fx_addsy != NULL |
| 2393 |
&& (S_GET_SEGMENT(fixP->fx_addsy) != section) |
| 2394 |
&& S_IS_DEFINED (fixP->fx_addsy) |
| 2395 |
&& ! S_IS_EXTERNAL(fixP->fx_addsy) |
| 2396 |
&& ! S_IS_WEAK(fixP->fx_addsy)) |
| 2397 |
|
| 2398 |
reloc->addend = fixP->fx_offset; |
| 2399 |
else |
| 2400 |
reloc->addend = fixP->fx_addnumber; |
| 2401 |
|
| 2402 |
return reloc; |
| 2403 |
} |
| 2404 |
|
| 2405 |
inline static char * |
| 2406 |
m32r_end_of_match (char *cont, char *what) |
| 2407 |
{ |
| 2408 |
int len = strlen (what); |
| 2409 |
|
| 2410 |
if (strncasecmp (cont, what, strlen (what)) == 0 |
| 2411 |
&& ! is_part_of_name (cont[len])) |
| 2412 |
return cont + len; |
| 2413 |
|
| 2414 |
return NULL; |
| 2415 |
} |
| 2416 |
|
| 2417 |
int |
| 2418 |
m32r_parse_name (char const *name, expressionS *exprP, char *nextcharP) |
| 2419 |
{ |
| 2420 |
char *next = input_line_pointer; |
| 2421 |
char *next_end; |
| 2422 |
int reloc_type; |
| 2423 |
operatorT op_type; |
| 2424 |
segT segment; |
| 2425 |
|
| 2426 |
exprP->X_op_symbol = NULL; |
| 2427 |
exprP->X_md = BFD_RELOC_UNUSED; |
| 2428 |
|
| 2429 |
if (strcmp (name, GOT_NAME) == 0) |
| 2430 |
{ |
| 2431 |
if (! GOT_symbol) |
| 2432 |
GOT_symbol = symbol_find_or_make (name); |
| 2433 |
|
| 2434 |
exprP->X_add_symbol = GOT_symbol; |
| 2435 |
no_suffix: |
| 2436 |
|
| 2437 |
|
| 2438 |
segment = S_GET_SEGMENT (exprP->X_add_symbol); |
| 2439 |
if (segment == absolute_section) |
| 2440 |
{ |
| 2441 |
exprP->X_op = O_constant; |
| 2442 |
exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol); |
| 2443 |
exprP->X_add_symbol = NULL; |
| 2444 |
} |
| 2445 |
else if (segment == reg_section) |
| 2446 |
{ |
| 2447 |
exprP->X_op = O_register; |
| 2448 |
exprP->X_add_number = S_GET_VALUE (exprP->X_add_symbol); |
| 2449 |
exprP->X_add_symbol = NULL; |
| 2450 |
} |
| 2451 |
else |
| 2452 |
{ |
| 2453 |
exprP->X_op = O_symbol; |
| 2454 |
exprP->X_add_number = 0; |
| 2455 |
} |
| 2456 |
|
| 2457 |
return 1; |
| 2458 |
} |
| 2459 |
|
| 2460 |
exprP->X_add_symbol = symbol_find_or_make (name); |
| 2461 |
|
| 2462 |
if (*nextcharP != '@') |
| 2463 |
goto no_suffix; |
| 2464 |
else if ((next_end = m32r_end_of_match (next + 1, "GOTOFF"))) |
| 2465 |
{ |
| 2466 |
reloc_type = BFD_RELOC_M32R_GOTOFF; |
| 2467 |
op_type = O_PIC_reloc; |
| 2468 |
} |
| 2469 |
else if ((next_end = m32r_end_of_match (next + 1, "GOT"))) |
| 2470 |
{ |
| 2471 |
reloc_type = BFD_RELOC_M32R_GOT24; |
| 2472 |
op_type = O_PIC_reloc; |
| 2473 |
} |
| 2474 |
else if ((next_end = m32r_end_of_match (next + 1, "PLT"))) |
| 2475 |
{ |
| 2476 |
reloc_type = BFD_RELOC_M32R_26_PLTREL; |
| 2477 |
op_type = O_PIC_reloc; |
| 2478 |
} |
| 2479 |
else |
| 2480 |
goto no_suffix; |
| 2481 |
|
| 2482 |
*input_line_pointer = *nextcharP; |
| 2483 |
input_line_pointer = next_end; |
| 2484 |
*nextcharP = *input_line_pointer; |
| 2485 |
*input_line_pointer = '\0'; |
| 2486 |
|
| 2487 |
exprP->X_op = op_type; |
| 2488 |
exprP->X_add_number = 0; |
| 2489 |
exprP->X_md = reloc_type; |
| 2490 |
|
| 2491 |
return 1; |
| 2492 |
} |
| 2493 |
|
| 2494 |
int |
| 2495 |
m32r_cgen_parse_fix_exp(int opinfo, expressionS *exp) |
| 2496 |
{ |
| 2497 |
if (exp->X_op == O_PIC_reloc |
| 2498 |
&& exp->X_md == BFD_RELOC_M32R_26_PLTREL) |
| 2499 |
{ |
| 2500 |
exp->X_op = O_symbol; |
| 2501 |
opinfo = exp->X_md; |
| 2502 |
} |
| 2503 |
|
| 2504 |
return opinfo; |
| 2505 |
} |