| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
#include <stdio.h> |
| 30 |
#include <limits.h> |
| 31 |
#include "as.h" |
| 32 |
#include "subsegs.h" |
| 33 |
#include "bfd.h" |
| 34 |
#include "elf/mmix.h" |
| 35 |
#include "opcode/mmix.h" |
| 36 |
#include "safe-ctype.h" |
| 37 |
#include "dwarf2dbg.h" |
| 38 |
#include "obstack.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
enum mmix_fixup_action |
| 44 |
{ |
| 45 |
mmix_fixup_byte, |
| 46 |
mmix_fixup_register, |
| 47 |
mmix_fixup_register_or_adjust_for_byte |
| 48 |
}; |
| 49 |
|
| 50 |
static int get_spec_regno PARAMS ((char *)); |
| 51 |
static int get_operands PARAMS ((int, char *, expressionS[])); |
| 52 |
static int get_putget_operands |
| 53 |
PARAMS ((struct mmix_opcode *, char *, expressionS[])); |
| 54 |
static void s_prefix PARAMS ((int)); |
| 55 |
static void s_greg PARAMS ((int)); |
| 56 |
static void s_loc PARAMS ((int)); |
| 57 |
static void s_bspec PARAMS ((int)); |
| 58 |
static void s_espec PARAMS ((int)); |
| 59 |
static void mmix_s_local PARAMS ((int)); |
| 60 |
static void mmix_greg_internal PARAMS ((char *)); |
| 61 |
static void mmix_set_geta_branch_offset PARAMS ((char *, offsetT value)); |
| 62 |
static void mmix_set_jmp_offset PARAMS ((char *, offsetT)); |
| 63 |
static void mmix_fill_nops PARAMS ((char *, int)); |
| 64 |
static int cmp_greg_symbol_fixes PARAMS ((const PTR, const PTR)); |
| 65 |
static int cmp_greg_val_greg_symbol_fixes |
| 66 |
PARAMS ((const PTR p1, const PTR p2)); |
| 67 |
static void mmix_handle_rest_of_empty_line PARAMS ((void)); |
| 68 |
static void mmix_discard_rest_of_line PARAMS ((void)); |
| 69 |
static void mmix_byte PARAMS ((void)); |
| 70 |
static void mmix_cons PARAMS ((int)); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
#define MAGIC_FB_BACKWARD_CHAR '\003' |
| 76 |
#define MAGIC_FB_FORWARD_CHAR '\004' |
| 77 |
|
| 78 |
|
| 79 |
#define COPY_FR_WHERE_TO_FX(FRAG, FIX) \ |
| 80 |
do \ |
| 81 |
{ \ |
| 82 |
(FIX)->fx_file = (FRAG)->fr_file; \ |
| 83 |
(FIX)->fx_line = (FRAG)->fr_line; \ |
| 84 |
} \ |
| 85 |
while (0) |
| 86 |
|
| 87 |
const char *md_shortopts = "x"; |
| 88 |
static int current_fb_label = -1; |
| 89 |
static char *pending_label = NULL; |
| 90 |
|
| 91 |
static bfd_vma lowest_text_loc = (bfd_vma) -1; |
| 92 |
static int text_has_contents = 0; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
static int last_alignment = 0; |
| 97 |
static int want_unaligned = 0; |
| 98 |
|
| 99 |
static bfd_vma lowest_data_loc = (bfd_vma) -1; |
| 100 |
static int data_has_contents = 0; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
fragS *mmix_opcode_frag = NULL; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
static int n_of_raw_gregs = 0; |
| 109 |
static struct |
| 110 |
{ |
| 111 |
char *label; |
| 112 |
expressionS exp; |
| 113 |
} mmix_raw_gregs[MAX_GREGS]; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
static fixS *mmix_gregs[MAX_GREGS]; |
| 121 |
static int n_of_cooked_gregs = 0; |
| 122 |
|
| 123 |
|
| 124 |
static asection *real_reg_section; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
struct mmix_symbol_gregs |
| 131 |
{ |
| 132 |
int n_gregs; |
| 133 |
struct mmix_symbol_greg_fixes |
| 134 |
{ |
| 135 |
fixS *fix; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
offsetT offs; |
| 140 |
} greg_fixes[MAX_GREGS]; |
| 141 |
}; |
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
static int label_without_colon_this_line = 1; |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
static int expand_op = 1; |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
static int warn_on_expansion = 1; |
| 154 |
|
| 155 |
|
| 156 |
static int merge_gregs = 1; |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
static int allocate_undefined_gregs_in_linker = 0; |
| 161 |
|
| 162 |
|
| 163 |
static int predefined_syms = 1; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
static int equated_spec_regs = 1; |
| 168 |
|
| 169 |
|
| 170 |
int mmix_gnu_syntax = 0; |
| 171 |
|
| 172 |
|
| 173 |
int mmix_globalize_symbols = 0; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
int pushj_stubs = 1; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
int mmix_next_semicolon_is_eoln = 1; |
| 182 |
|
| 183 |
|
| 184 |
static int doing_bspec = 0; |
| 185 |
static char *bspec_file; |
| 186 |
static unsigned int bspec_line; |
| 187 |
|
| 188 |
struct option md_longopts[] = |
| 189 |
{ |
| 190 |
#define OPTION_RELAX (OPTION_MD_BASE) |
| 191 |
#define OPTION_NOEXPAND (OPTION_RELAX + 1) |
| 192 |
#define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1) |
| 193 |
#define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1) |
| 194 |
#define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1) |
| 195 |
#define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1) |
| 196 |
#define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1) |
| 197 |
#define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1) |
| 198 |
#define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1) |
| 199 |
{"linkrelax", no_argument, NULL, OPTION_RELAX}, |
| 200 |
{"no-expand", no_argument, NULL, OPTION_NOEXPAND}, |
| 201 |
{"no-merge-gregs", no_argument, NULL, OPTION_NOMERGEGREG}, |
| 202 |
{"no-predefined-syms", no_argument, NULL, OPTION_NOSYMS}, |
| 203 |
{"gnu-syntax", no_argument, NULL, OPTION_GNU_SYNTAX}, |
| 204 |
{"globalize-symbols", no_argument, NULL, OPTION_GLOBALIZE_SYMBOLS}, |
| 205 |
{"fixed-special-register-names", no_argument, NULL, |
| 206 |
OPTION_FIXED_SPEC_REGS}, |
| 207 |
{"linker-allocated-gregs", no_argument, NULL, |
| 208 |
OPTION_LINKER_ALLOCATED_GREGS}, |
| 209 |
{"no-pushj-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS}, |
| 210 |
{"no-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS}, |
| 211 |
{NULL, no_argument, NULL, 0} |
| 212 |
}; |
| 213 |
|
| 214 |
size_t md_longopts_size = sizeof (md_longopts); |
| 215 |
|
| 216 |
static struct hash_control *mmix_opcode_hash; |
| 217 |
|
| 218 |
|
| 219 |
char *mmix_current_prefix; |
| 220 |
struct obstack mmix_sym_obstack; |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
#define STATE_GETA (1) |
| 255 |
#define STATE_BCC (2) |
| 256 |
#define STATE_PUSHJ (3) |
| 257 |
#define STATE_JMP (4) |
| 258 |
#define STATE_GREG (5) |
| 259 |
#define STATE_PUSHJSTUB (6) |
| 260 |
|
| 261 |
|
| 262 |
#define STATE_LENGTH_MASK (1) |
| 263 |
|
| 264 |
#define STATE_ZERO (0) |
| 265 |
#define STATE_MAX (1) |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
#define STATE_UNDF STATE_MAX |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
#define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO) |
| 276 |
#define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX) |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
#define GETA_0F (65536 * 4 - 8) |
| 283 |
#define GETA_0B (-65536 * 4 - 4) |
| 284 |
|
| 285 |
#define GETA_MAX_LEN 4 * 4 |
| 286 |
#define GETA_3F 0 |
| 287 |
#define GETA_3B 0 |
| 288 |
|
| 289 |
#define BCC_0F GETA_0F |
| 290 |
#define BCC_0B GETA_0B |
| 291 |
|
| 292 |
#define BCC_MAX_LEN 6 * 4 |
| 293 |
#define BCC_5F GETA_3F |
| 294 |
#define BCC_5B GETA_3B |
| 295 |
|
| 296 |
#define PUSHJ_0F GETA_0F |
| 297 |
#define PUSHJ_0B GETA_0B |
| 298 |
|
| 299 |
#define PUSHJ_MAX_LEN 5 * 4 |
| 300 |
#define PUSHJ_4F GETA_3F |
| 301 |
#define PUSHJ_4B GETA_3B |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
#define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1)) |
| 306 |
#define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1) |
| 307 |
|
| 308 |
#define JMP_0F (65536 * 256 * 4 - 8) |
| 309 |
#define JMP_0B (-65536 * 256 * 4 - 4) |
| 310 |
|
| 311 |
#define JMP_MAX_LEN 5 * 4 |
| 312 |
#define JMP_4F 0 |
| 313 |
#define JMP_4B 0 |
| 314 |
|
| 315 |
#define RELAX_ENCODE_SHIFT 1 |
| 316 |
#define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length)) |
| 317 |
|
| 318 |
const relax_typeS mmix_relax_table[] = |
| 319 |
{ |
| 320 |
|
| 321 |
{1, 1, 0, 0}, |
| 322 |
|
| 323 |
|
| 324 |
{1, 1, 0, 0}, |
| 325 |
|
| 326 |
|
| 327 |
{GETA_0F, GETA_0B, 0, ENCODE_RELAX (STATE_GETA, STATE_MAX)}, |
| 328 |
|
| 329 |
|
| 330 |
{GETA_3F, GETA_3B, |
| 331 |
GETA_MAX_LEN - 4, 0}, |
| 332 |
|
| 333 |
|
| 334 |
{BCC_0F, BCC_0B, 0, ENCODE_RELAX (STATE_BCC, STATE_MAX)}, |
| 335 |
|
| 336 |
|
| 337 |
{BCC_5F, BCC_5B, |
| 338 |
BCC_MAX_LEN - 4, 0}, |
| 339 |
|
| 340 |
|
| 341 |
{PUSHJ_0F, PUSHJ_0B, 0, ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO)}, |
| 342 |
|
| 343 |
|
| 344 |
{PUSHJ_4F, PUSHJ_4B, |
| 345 |
PUSHJ_MAX_LEN - 4, 0}, |
| 346 |
|
| 347 |
|
| 348 |
{JMP_0F, JMP_0B, 0, ENCODE_RELAX (STATE_JMP, STATE_MAX)}, |
| 349 |
|
| 350 |
|
| 351 |
{JMP_4F, JMP_4B, |
| 352 |
JMP_MAX_LEN - 4, 0}, |
| 353 |
|
| 354 |
|
| 355 |
{0, 0, 0, 0}, {0, 0, 0, 0}, |
| 356 |
|
| 357 |
|
| 358 |
{PUSHJSTUB_MAX, PUSHJSTUB_MIN, |
| 359 |
0, ENCODE_RELAX (STATE_PUSHJ, STATE_MAX)}, |
| 360 |
|
| 361 |
{0, 0, PUSHJ_MAX_LEN, 0} |
| 362 |
}; |
| 363 |
|
| 364 |
const pseudo_typeS md_pseudo_table[] = |
| 365 |
{ |
| 366 |
|
| 367 |
{"greg", s_greg, 0}, |
| 368 |
|
| 369 |
|
| 370 |
{"bspec", s_bspec, 1}, |
| 371 |
|
| 372 |
|
| 373 |
{"espec", s_espec, 1}, |
| 374 |
|
| 375 |
|
| 376 |
{"local", mmix_s_local, 1}, |
| 377 |
|
| 378 |
{NULL, 0, 0} |
| 379 |
}; |
| 380 |
|
| 381 |
const char mmix_comment_chars[] = "%!"; |
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
const char mmix_symbol_chars[] = ":@"; |
| 389 |
|
| 390 |
const char line_comment_chars[] = "*#"; |
| 391 |
|
| 392 |
const char line_separator_chars[] = ";"; |
| 393 |
|
| 394 |
const char mmix_exp_chars[] = "eE"; |
| 395 |
|
| 396 |
const char mmix_flt_chars[] = "rf"; |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
static void |
| 402 |
mmix_set_geta_branch_offset (opcodep, value) |
| 403 |
char *opcodep; |
| 404 |
offsetT value; |
| 405 |
{ |
| 406 |
if (value < 0) |
| 407 |
{ |
| 408 |
value += 65536 * 4; |
| 409 |
opcodep[0] |= 1; |
| 410 |
} |
| 411 |
|
| 412 |
value /= 4; |
| 413 |
md_number_to_chars (opcodep + 2, value, 2); |
| 414 |
} |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
static void |
| 419 |
mmix_set_jmp_offset (opcodep, value) |
| 420 |
char *opcodep; |
| 421 |
offsetT value; |
| 422 |
{ |
| 423 |
if (value < 0) |
| 424 |
{ |
| 425 |
value += 65536 * 256 * 4; |
| 426 |
opcodep[0] |= 1; |
| 427 |
} |
| 428 |
|
| 429 |
value /= 4; |
| 430 |
md_number_to_chars (opcodep + 1, value, 3); |
| 431 |
} |
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
static void |
| 436 |
mmix_fill_nops (opcodep, n) |
| 437 |
char *opcodep; |
| 438 |
int n; |
| 439 |
{ |
| 440 |
int i; |
| 441 |
|
| 442 |
for (i = 0; i < n; i++) |
| 443 |
md_number_to_chars (opcodep + i * 4, SWYM_INSN_BYTE << 24, 4); |
| 444 |
} |
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
int |
| 449 |
mmix_current_location (fn, exp) |
| 450 |
void (*fn) PARAMS ((expressionS *)); |
| 451 |
expressionS *exp; |
| 452 |
{ |
| 453 |
(*fn) (exp); |
| 454 |
|
| 455 |
return 1; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
static int |
| 462 |
get_operands (max_operands, s, exp) |
| 463 |
int max_operands; |
| 464 |
char *s; |
| 465 |
expressionS exp[]; |
| 466 |
{ |
| 467 |
char *p = s; |
| 468 |
int numexp = 0; |
| 469 |
int nextchar = ','; |
| 470 |
|
| 471 |
while (nextchar == ',') |
| 472 |
{ |
| 473 |
|
| 474 |
while (*p == ' ' || *p == '\t') |
| 475 |
p++; |
| 476 |
|
| 477 |
|
| 478 |
if (*p == 0 || *p == '\n' || *p == '\r') |
| 479 |
{ |
| 480 |
break; |
| 481 |
} |
| 482 |
else if (numexp == max_operands) |
| 483 |
{ |
| 484 |
|
| 485 |
|
| 486 |
as_bad (_("invalid operands")); |
| 487 |
mmix_discard_rest_of_line (); |
| 488 |
return 0; |
| 489 |
} |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
input_line_pointer = p; |
| 494 |
expression (&exp[numexp]); |
| 495 |
|
| 496 |
if (exp[numexp].X_op == O_illegal) |
| 497 |
{ |
| 498 |
as_bad (_("invalid operands")); |
| 499 |
} |
| 500 |
else if (exp[numexp].X_op == O_absent) |
| 501 |
{ |
| 502 |
as_bad (_("missing operand")); |
| 503 |
} |
| 504 |
|
| 505 |
numexp++; |
| 506 |
p = input_line_pointer; |
| 507 |
|
| 508 |
|
| 509 |
while (*p == ' ' || *p == '\t') |
| 510 |
p++; |
| 511 |
nextchar = *p++; |
| 512 |
} |
| 513 |
|
| 514 |
|
| 515 |
if (nextchar != ',') |
| 516 |
{ |
| 517 |
mmix_handle_rest_of_empty_line (); |
| 518 |
input_line_pointer--; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
exp[numexp].X_op = O_illegal; |
| 523 |
|
| 524 |
return (numexp); |
| 525 |
} |
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
static int |
| 531 |
get_spec_regno (name) |
| 532 |
char *name; |
| 533 |
{ |
| 534 |
int i; |
| 535 |
|
| 536 |
if (name == NULL) |
| 537 |
return -1; |
| 538 |
|
| 539 |
if (*name == ':') |
| 540 |
name++; |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
for (i = 0; mmix_spec_regs[i].name != NULL; i++) |
| 545 |
if (strcmp (name, mmix_spec_regs[i].name) == 0) |
| 546 |
return mmix_spec_regs[i].number; |
| 547 |
|
| 548 |
return -1; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
static int |
| 554 |
get_putget_operands (insn, operands, exp) |
| 555 |
struct mmix_opcode *insn; |
| 556 |
char *operands; |
| 557 |
expressionS exp[]; |
| 558 |
{ |
| 559 |
expressionS *expp_reg; |
| 560 |
expressionS *expp_sreg; |
| 561 |
char *sregp = NULL; |
| 562 |
char *sregend = operands; |
| 563 |
char *p = operands; |
| 564 |
char c = *sregend; |
| 565 |
int regno; |
| 566 |
|
| 567 |
|
| 568 |
while (*p == ' ' || *p == '\t') |
| 569 |
p++; |
| 570 |
|
| 571 |
input_line_pointer = p; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
exp[0].X_op = O_illegal; |
| 576 |
exp[1].X_op = O_illegal; |
| 577 |
|
| 578 |
if (insn->operands == mmix_operands_get) |
| 579 |
{ |
| 580 |
expp_reg = &exp[0]; |
| 581 |
expp_sreg = &exp[1]; |
| 582 |
|
| 583 |
expression (expp_reg); |
| 584 |
|
| 585 |
p = input_line_pointer; |
| 586 |
|
| 587 |
|
| 588 |
while (*p == ' ' || *p == '\t') |
| 589 |
p++; |
| 590 |
|
| 591 |
if (*p == ',') |
| 592 |
{ |
| 593 |
p++; |
| 594 |
|
| 595 |
|
| 596 |
while (*p == ' ' || *p == '\t') |
| 597 |
p++; |
| 598 |
sregp = p; |
| 599 |
input_line_pointer = sregp; |
| 600 |
c = get_symbol_end (); |
| 601 |
sregend = input_line_pointer; |
| 602 |
} |
| 603 |
} |
| 604 |
else |
| 605 |
{ |
| 606 |
expp_sreg = &exp[0]; |
| 607 |
expp_reg = &exp[1]; |
| 608 |
|
| 609 |
sregp = p; |
| 610 |
c = get_symbol_end (); |
| 611 |
sregend = p = input_line_pointer; |
| 612 |
*p = c; |
| 613 |
|
| 614 |
|
| 615 |
while (*p == ' ' || *p == '\t') |
| 616 |
p++; |
| 617 |
|
| 618 |
if (*p == ',') |
| 619 |
{ |
| 620 |
p++; |
| 621 |
|
| 622 |
|
| 623 |
while (*p == ' ' || *p == '\t') |
| 624 |
p++; |
| 625 |
|
| 626 |
input_line_pointer = p; |
| 627 |
expression (expp_reg); |
| 628 |
} |
| 629 |
*sregend = 0; |
| 630 |
} |
| 631 |
|
| 632 |
regno = get_spec_regno (sregp); |
| 633 |
*sregend = c; |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
if (expp_reg->X_op != O_illegal |
| 638 |
&& expp_reg->X_op != O_absent |
| 639 |
&& regno != -1) |
| 640 |
{ |
| 641 |
expp_sreg->X_op = O_register; |
| 642 |
expp_sreg->X_add_number = regno + 256; |
| 643 |
} |
| 644 |
|
| 645 |
return 2; |
| 646 |
} |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
int |
| 651 |
md_parse_option (c, arg) |
| 652 |
int c; |
| 653 |
char *arg ATTRIBUTE_UNUSED; |
| 654 |
{ |
| 655 |
switch (c) |
| 656 |
{ |
| 657 |
case 'x': |
| 658 |
warn_on_expansion = 0; |
| 659 |
allocate_undefined_gregs_in_linker = 1; |
| 660 |
break; |
| 661 |
|
| 662 |
case OPTION_RELAX: |
| 663 |
linkrelax = 1; |
| 664 |
break; |
| 665 |
|
| 666 |
case OPTION_NOEXPAND: |
| 667 |
expand_op = 0; |
| 668 |
break; |
| 669 |
|
| 670 |
case OPTION_NOMERGEGREG: |
| 671 |
merge_gregs = 0; |
| 672 |
break; |
| 673 |
|
| 674 |
case OPTION_NOSYMS: |
| 675 |
predefined_syms = 0; |
| 676 |
equated_spec_regs = 0; |
| 677 |
break; |
| 678 |
|
| 679 |
case OPTION_GNU_SYNTAX: |
| 680 |
mmix_gnu_syntax = 1; |
| 681 |
label_without_colon_this_line = 0; |
| 682 |
break; |
| 683 |
|
| 684 |
case OPTION_GLOBALIZE_SYMBOLS: |
| 685 |
mmix_globalize_symbols = 1; |
| 686 |
break; |
| 687 |
|
| 688 |
case OPTION_FIXED_SPEC_REGS: |
| 689 |
equated_spec_regs = 0; |
| 690 |
break; |
| 691 |
|
| 692 |
case OPTION_LINKER_ALLOCATED_GREGS: |
| 693 |
allocate_undefined_gregs_in_linker = 1; |
| 694 |
break; |
| 695 |
|
| 696 |
case OPTION_NOPUSHJSTUBS: |
| 697 |
pushj_stubs = 0; |
| 698 |
break; |
| 699 |
|
| 700 |
default: |
| 701 |
return 0; |
| 702 |
} |
| 703 |
|
| 704 |
return 1; |
| 705 |
} |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
void |
| 710 |
md_show_usage (stream) |
| 711 |
FILE * stream; |
| 712 |
{ |
| 713 |
fprintf (stream, _(" MMIX-specific command line options:\n")); |
| 714 |
fprintf (stream, _("\ |
| 715 |
-fixed-special-register-names\n\ |
| 716 |
Allow only the original special register names.\n")); |
| 717 |
fprintf (stream, _("\ |
| 718 |
-globalize-symbols Make all symbols global.\n")); |
| 719 |
fprintf (stream, _("\ |
| 720 |
-gnu-syntax Turn off mmixal syntax compatibility.\n")); |
| 721 |
fprintf (stream, _("\ |
| 722 |
-relax Create linker relaxable code.\n")); |
| 723 |
fprintf (stream, _("\ |
| 724 |
-no-predefined-syms Do not provide mmixal built-in constants.\n\ |
| 725 |
Implies -fixed-special-register-names.\n")); |
| 726 |
fprintf (stream, _("\ |
| 727 |
-no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\ |
| 728 |
into multiple instructions.\n")); |
| 729 |
fprintf (stream, _("\ |
| 730 |
-no-merge-gregs Do not merge GREG definitions with nearby values.\n")); |
| 731 |
fprintf (stream, _("\ |
| 732 |
-linker-allocated-gregs If there's no suitable GREG definition for the\ |
| 733 |
operands of an instruction, let the linker resolve.\n")); |
| 734 |
fprintf (stream, _("\ |
| 735 |
-x Do not warn when an operand to GETA, a branch,\n\ |
| 736 |
PUSHJ or JUMP is not known to be within range.\n\ |
| 737 |
The linker will catch any errors. Implies\n\ |
| 738 |
-linker-allocated-gregs.")); |
| 739 |
} |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
static void |
| 744 |
mmix_discard_rest_of_line () |
| 745 |
{ |
| 746 |
while (*input_line_pointer |
| 747 |
&& (! is_end_of_line[(unsigned char) *input_line_pointer] |
| 748 |
|| TC_EOL_IN_INSN (input_line_pointer))) |
| 749 |
input_line_pointer++; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
static void |
| 757 |
mmix_handle_rest_of_empty_line () |
| 758 |
{ |
| 759 |
if (mmix_gnu_syntax) |
| 760 |
demand_empty_rest_of_line (); |
| 761 |
else |
| 762 |
{ |
| 763 |
mmix_discard_rest_of_line (); |
| 764 |
input_line_pointer++; |
| 765 |
} |
| 766 |
} |
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
void |
| 771 |
mmix_md_begin () |
| 772 |
{ |
| 773 |
int i; |
| 774 |
const struct mmix_opcode *opcode; |
| 775 |
|
| 776 |
|
| 777 |
obstack_begin (&mmix_sym_obstack, 0); |
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
lex_type[':'] = (LEX_NAME | LEX_BEGIN_NAME); |
| 782 |
|
| 783 |
mmix_opcode_hash = hash_new (); |
| 784 |
|
| 785 |
real_reg_section |
| 786 |
= bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME); |
| 787 |
|
| 788 |
for (opcode = mmix_opcodes; opcode->name; opcode++) |
| 789 |
hash_insert (mmix_opcode_hash, opcode->name, (char *) opcode); |
| 790 |
|
| 791 |
|
| 792 |
for (i = 0; i < 256; i++) |
| 793 |
{ |
| 794 |
char buf[5]; |
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
sprintf (buf, "$%d", i); |
| 799 |
symbol_table_insert (symbol_new (buf, reg_section, i, |
| 800 |
&zero_address_frag)); |
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
if (predefined_syms) |
| 805 |
{ |
| 806 |
for (i = 0; mmix_spec_regs[i].name != NULL; i++) |
| 807 |
symbol_table_insert (symbol_new (mmix_spec_regs[i].name, |
| 808 |
reg_section, |
| 809 |
mmix_spec_regs[i].number + 256, |
| 810 |
&zero_address_frag)); |
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section, 512, |
| 815 |
&zero_address_frag)); |
| 816 |
symbol_table_insert (symbol_new ("ROUND_OFF", reg_section, 512 + 1, |
| 817 |
&zero_address_frag)); |
| 818 |
symbol_table_insert (symbol_new ("ROUND_UP", reg_section, 512 + 2, |
| 819 |
&zero_address_frag)); |
| 820 |
symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section, 512 + 3, |
| 821 |
&zero_address_frag)); |
| 822 |
symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section, 512 + 4, |
| 823 |
&zero_address_frag)); |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
void |
| 830 |
md_assemble (str) |
| 831 |
char *str; |
| 832 |
{ |
| 833 |
char *operands = str; |
| 834 |
char modified_char = 0; |
| 835 |
struct mmix_opcode *instruction; |
| 836 |
fragS *opc_fragP = NULL; |
| 837 |
int max_operands = 3; |
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
char *opcodep = NULL; |
| 842 |
|
| 843 |
expressionS exp[4]; |
| 844 |
int n_operands = 0; |
| 845 |
|
| 846 |
|
| 847 |
for (operands = str; |
| 848 |
is_part_of_name (*operands); |
| 849 |
++operands) |
| 850 |
; |
| 851 |
|
| 852 |
if (ISSPACE (*operands)) |
| 853 |
{ |
| 854 |
modified_char = *operands; |
| 855 |
*operands++ = '\0'; |
| 856 |
} |
| 857 |
|
| 858 |
instruction = (struct mmix_opcode *) hash_find (mmix_opcode_hash, str); |
| 859 |
if (instruction == NULL) |
| 860 |
{ |
| 861 |
as_bad (_("unknown opcode: `%s'"), str); |
| 862 |
|
| 863 |
|
| 864 |
pending_label = NULL; |
| 865 |
return; |
| 866 |
} |
| 867 |
|
| 868 |
|
| 869 |
if (modified_char != 0) |
| 870 |
operands[-1] = modified_char; |
| 871 |
|
| 872 |
input_line_pointer = operands; |
| 873 |
|
| 874 |
|
| 875 |
if (instruction->type == mmix_type_pseudo) |
| 876 |
{ |
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
switch (instruction->operands) |
| 883 |
{ |
| 884 |
case mmix_operands_loc: |
| 885 |
case mmix_operands_byte: |
| 886 |
case mmix_operands_prefix: |
| 887 |
case mmix_operands_local: |
| 888 |
case mmix_operands_bspec: |
| 889 |
case mmix_operands_espec: |
| 890 |
if (current_fb_label >= 0) |
| 891 |
colon (fb_label_name (current_fb_label, 1)); |
| 892 |
else if (pending_label != NULL) |
| 893 |
{ |
| 894 |
colon (pending_label); |
| 895 |
pending_label = NULL; |
| 896 |
} |
| 897 |
break; |
| 898 |
|
| 899 |
default: |
| 900 |
break; |
| 901 |
} |
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
switch (instruction->operands) |
| 906 |
{ |
| 907 |
case mmix_operands_loc: |
| 908 |
|
| 909 |
s_loc (0); |
| 910 |
break; |
| 911 |
|
| 912 |
case mmix_operands_byte: |
| 913 |
|
| 914 |
mmix_byte (); |
| 915 |
break; |
| 916 |
|
| 917 |
case mmix_operands_wyde: |
| 918 |
|
| 919 |
mmix_cons (2); |
| 920 |
break; |
| 921 |
|
| 922 |
case mmix_operands_tetra: |
| 923 |
|
| 924 |
mmix_cons (4); |
| 925 |
break; |
| 926 |
|
| 927 |
case mmix_operands_octa: |
| 928 |
|
| 929 |
mmix_cons (8); |
| 930 |
break; |
| 931 |
|
| 932 |
case mmix_operands_prefix: |
| 933 |
|
| 934 |
s_prefix (0); |
| 935 |
break; |
| 936 |
|
| 937 |
case mmix_operands_local: |
| 938 |
|
| 939 |
mmix_s_local (0); |
| 940 |
break; |
| 941 |
|
| 942 |
case mmix_operands_bspec: |
| 943 |
|
| 944 |
s_bspec (0); |
| 945 |
break; |
| 946 |
|
| 947 |
case mmix_operands_espec: |
| 948 |
|
| 949 |
s_espec (0); |
| 950 |
break; |
| 951 |
|
| 952 |
default: |
| 953 |
BAD_CASE (instruction->operands); |
| 954 |
} |
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
input_line_pointer--; |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
if (current_fb_label >= 0) |
| 964 |
{ |
| 965 |
fb_label_instance_inc (current_fb_label); |
| 966 |
current_fb_label = -1; |
| 967 |
} |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
if (instruction->operands != mmix_operands_loc) |
| 972 |
want_unaligned = 0; |
| 973 |
|
| 974 |
return; |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
if (now_seg == data_section) |
| 979 |
{ |
| 980 |
if (lowest_data_loc != (bfd_vma) -1 && (lowest_data_loc & 3) != 0) |
| 981 |
{ |
| 982 |
if (data_has_contents) |
| 983 |
as_bad (_("specified location wasn't TETRA-aligned")); |
| 984 |
else if (want_unaligned) |
| 985 |
as_bad (_("unaligned data at an absolute location is not supported")); |
| 986 |
|
| 987 |
lowest_data_loc &= ~(bfd_vma) 3; |
| 988 |
lowest_data_loc += 4; |
| 989 |
} |
| 990 |
|
| 991 |
data_has_contents = 1; |
| 992 |
} |
| 993 |
else if (now_seg == text_section) |
| 994 |
{ |
| 995 |
if (lowest_text_loc != (bfd_vma) -1 && (lowest_text_loc & 3) != 0) |
| 996 |
{ |
| 997 |
if (text_has_contents) |
| 998 |
as_bad (_("specified location wasn't TETRA-aligned")); |
| 999 |
else if (want_unaligned) |
| 1000 |
as_bad (_("unaligned data at an absolute location is not supported")); |
| 1001 |
|
| 1002 |
lowest_text_loc &= ~(bfd_vma) 3; |
| 1003 |
lowest_text_loc += 4; |
| 1004 |
} |
| 1005 |
|
| 1006 |
text_has_contents = 1; |
| 1007 |
} |
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
if (last_alignment < 2 && ! want_unaligned) |
| 1013 |
{ |
| 1014 |
frag_align (2, 0, 0); |
| 1015 |
record_alignment (now_seg, 2); |
| 1016 |
last_alignment = 2; |
| 1017 |
} |
| 1018 |
else |
| 1019 |
|
| 1020 |
want_unaligned = 0; |
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
if (pending_label != NULL) |
| 1026 |
{ |
| 1027 |
colon (pending_label); |
| 1028 |
pending_label = NULL; |
| 1029 |
} |
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
switch (instruction->operands) |
| 1038 |
{ |
| 1039 |
case mmix_operands_reg_yz: |
| 1040 |
case mmix_operands_pop: |
| 1041 |
case mmix_operands_regaddr: |
| 1042 |
case mmix_operands_pushj: |
| 1043 |
case mmix_operands_get: |
| 1044 |
case mmix_operands_put: |
| 1045 |
case mmix_operands_set: |
| 1046 |
case mmix_operands_save: |
| 1047 |
case mmix_operands_unsave: |
| 1048 |
max_operands = 2; |
| 1049 |
break; |
| 1050 |
|
| 1051 |
case mmix_operands_sync: |
| 1052 |
case mmix_operands_jmp: |
| 1053 |
case mmix_operands_resume: |
| 1054 |
max_operands = 1; |
| 1055 |
break; |
| 1056 |
|
| 1057 |
|
| 1058 |
default: |
| 1059 |
break; |
| 1060 |
} |
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
if (! equated_spec_regs |
| 1066 |
&& (instruction->operands == mmix_operands_get |
| 1067 |
|| instruction->operands == mmix_operands_put)) |
| 1068 |
n_operands = get_putget_operands (instruction, operands, exp); |
| 1069 |
else |
| 1070 |
n_operands = get_operands (max_operands, operands, exp); |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
if (current_fb_label >= 0) |
| 1076 |
{ |
| 1077 |
fb_label_instance_inc (current_fb_label); |
| 1078 |
colon (fb_label_name (current_fb_label, 0)); |
| 1079 |
current_fb_label = -1; |
| 1080 |
} |
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
opcodep = frag_more (4); |
| 1088 |
mmix_opcode_frag = opc_fragP = frag_now; |
| 1089 |
frag_now->fr_opcode = opcodep; |
| 1090 |
|
| 1091 |
|
| 1092 |
if (OUTPUT_FLAVOR == bfd_target_elf_flavour) |
| 1093 |
dwarf2_emit_insn (4); |
| 1094 |
|
| 1095 |
md_number_to_chars (opcodep, instruction->match, 4); |
| 1096 |
|
| 1097 |
switch (instruction->operands) |
| 1098 |
{ |
| 1099 |
case mmix_operands_jmp: |
| 1100 |
if (n_operands == 0 && ! mmix_gnu_syntax) |
| 1101 |
|
| 1102 |
|
| 1103 |
break; |
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
if (n_operands != 1 || exp[0].X_op == O_register) |
| 1109 |
{ |
| 1110 |
as_bad (_("invalid operand to opcode %s: `%s'"), |
| 1111 |
instruction->name, operands); |
| 1112 |
return; |
| 1113 |
} |
| 1114 |
|
| 1115 |
if (expand_op) |
| 1116 |
frag_var (rs_machine_dependent, 4 * 4, 0, |
| 1117 |
ENCODE_RELAX (STATE_JMP, STATE_UNDF), |
| 1118 |
exp[0].X_add_symbol, |
| 1119 |
exp[0].X_add_number, |
| 1120 |
opcodep); |
| 1121 |
else |
| 1122 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4, |
| 1123 |
exp + 0, 1, BFD_RELOC_MMIX_ADDR27); |
| 1124 |
break; |
| 1125 |
|
| 1126 |
case mmix_operands_pushj: |
| 1127 |
|
| 1128 |
if (n_operands != 2 |
| 1129 |
|| ((exp[0].X_op == O_constant || exp[0].X_op == O_register) |
| 1130 |
&& (exp[0].X_add_number > 255 || exp[0].X_add_number < 0))) |
| 1131 |
{ |
| 1132 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1133 |
instruction->name, operands); |
| 1134 |
return; |
| 1135 |
} |
| 1136 |
|
| 1137 |
if (exp[0].X_op == O_register || exp[0].X_op == O_constant) |
| 1138 |
opcodep[1] = exp[0].X_add_number; |
| 1139 |
else |
| 1140 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1141 |
1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1142 |
|
| 1143 |
if (expand_op) |
| 1144 |
frag_var (rs_machine_dependent, PUSHJ_MAX_LEN - 4, 0, |
| 1145 |
ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF), |
| 1146 |
exp[1].X_add_symbol, |
| 1147 |
exp[1].X_add_number, |
| 1148 |
opcodep); |
| 1149 |
else |
| 1150 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4, |
| 1151 |
exp + 1, 1, BFD_RELOC_MMIX_ADDR19); |
| 1152 |
break; |
| 1153 |
|
| 1154 |
case mmix_operands_regaddr: |
| 1155 |
|
| 1156 |
|
| 1157 |
if (n_operands != 2 || exp[1].X_op == O_register) |
| 1158 |
{ |
| 1159 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1160 |
instruction->name, operands); |
| 1161 |
return; |
| 1162 |
} |
| 1163 |
|
| 1164 |
if (! expand_op) |
| 1165 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4, |
| 1166 |
exp + 1, 1, BFD_RELOC_MMIX_ADDR19); |
| 1167 |
else if (instruction->type == mmix_type_condbranch) |
| 1168 |
frag_var (rs_machine_dependent, BCC_MAX_LEN - 4, 0, |
| 1169 |
ENCODE_RELAX (STATE_BCC, STATE_UNDF), |
| 1170 |
exp[1].X_add_symbol, |
| 1171 |
exp[1].X_add_number, |
| 1172 |
opcodep); |
| 1173 |
else |
| 1174 |
frag_var (rs_machine_dependent, GETA_MAX_LEN - 4, 0, |
| 1175 |
ENCODE_RELAX (STATE_GETA, STATE_UNDF), |
| 1176 |
exp[1].X_add_symbol, |
| 1177 |
exp[1].X_add_number, |
| 1178 |
opcodep); |
| 1179 |
break; |
| 1180 |
|
| 1181 |
default: |
| 1182 |
break; |
| 1183 |
} |
| 1184 |
|
| 1185 |
switch (instruction->operands) |
| 1186 |
{ |
| 1187 |
case mmix_operands_regs: |
| 1188 |
|
| 1189 |
|
| 1190 |
if (n_operands != 3 || exp[2].X_op == O_constant) |
| 1191 |
{ |
| 1192 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1193 |
instruction->name, operands); |
| 1194 |
return; |
| 1195 |
} |
| 1196 |
|
| 1197 |
case mmix_operands_regs_z: |
| 1198 |
if (n_operands != 3) |
| 1199 |
{ |
| 1200 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1201 |
instruction->name, operands); |
| 1202 |
return; |
| 1203 |
} |
| 1204 |
|
| 1205 |
case mmix_operands_reg_yz: |
| 1206 |
case mmix_operands_roundregs_z: |
| 1207 |
case mmix_operands_roundregs: |
| 1208 |
case mmix_operands_regs_z_opt: |
| 1209 |
case mmix_operands_neg: |
| 1210 |
case mmix_operands_regaddr: |
| 1211 |
case mmix_operands_get: |
| 1212 |
case mmix_operands_set: |
| 1213 |
case mmix_operands_save: |
| 1214 |
if (n_operands < 1 |
| 1215 |
|| (exp[0].X_op == O_register && exp[0].X_add_number > 255)) |
| 1216 |
{ |
| 1217 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1218 |
instruction->name, operands); |
| 1219 |
return; |
| 1220 |
} |
| 1221 |
|
| 1222 |
if (exp[0].X_op == O_register) |
| 1223 |
opcodep[1] = exp[0].X_add_number; |
| 1224 |
else |
| 1225 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1226 |
1, exp + 0, 0, BFD_RELOC_MMIX_REG); |
| 1227 |
break; |
| 1228 |
|
| 1229 |
default: |
| 1230 |
; |
| 1231 |
} |
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
switch (instruction->operands) |
| 1236 |
{ |
| 1237 |
case mmix_operands_pushgo: |
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
if (n_operands < 2 |
| 1242 |
|| ((exp[0].X_op == O_constant || exp[0].X_op == O_register) |
| 1243 |
&& (exp[0].X_add_number > 255 || exp[0].X_add_number < 0))) |
| 1244 |
{ |
| 1245 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1246 |
instruction->name, operands); |
| 1247 |
return; |
| 1248 |
} |
| 1249 |
else if (exp[0].X_op == O_constant || exp[0].X_op == O_register) |
| 1250 |
opcodep[1] = exp[0].X_add_number; |
| 1251 |
else |
| 1252 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1253 |
1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1254 |
break; |
| 1255 |
|
| 1256 |
case mmix_operands_pop: |
| 1257 |
if ((n_operands == 0 || n_operands == 1) && ! mmix_gnu_syntax) |
| 1258 |
break; |
| 1259 |
|
| 1260 |
case mmix_operands_x_regs_z: |
| 1261 |
if (n_operands < 1 |
| 1262 |
|| (exp[0].X_op == O_constant |
| 1263 |
&& (exp[0].X_add_number > 255 |
| 1264 |
|| exp[0].X_add_number < 0))) |
| 1265 |
{ |
| 1266 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1267 |
instruction->name, operands); |
| 1268 |
return; |
| 1269 |
} |
| 1270 |
|
| 1271 |
if (exp[0].X_op == O_constant) |
| 1272 |
opcodep[1] = exp[0].X_add_number; |
| 1273 |
else |
| 1274 |
|
| 1275 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1276 |
1, exp + 0, 0, BFD_RELOC_8); |
| 1277 |
default: |
| 1278 |
; |
| 1279 |
} |
| 1280 |
|
| 1281 |
|
| 1282 |
switch (instruction->operands) |
| 1283 |
{ |
| 1284 |
case mmix_operands_set: |
| 1285 |
|
| 1286 |
|
| 1287 |
if (n_operands != 2 |
| 1288 |
|| (exp[1].X_op == O_constant |
| 1289 |
&& (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0))) |
| 1290 |
{ |
| 1291 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1292 |
instruction->name, operands); |
| 1293 |
return; |
| 1294 |
} |
| 1295 |
|
| 1296 |
if (exp[1].X_op == O_constant) |
| 1297 |
{ |
| 1298 |
|
| 1299 |
|
| 1300 |
|
| 1301 |
|
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
md_number_to_chars (opcodep, SETL_INSN_BYTE, 1); |
| 1306 |
|
| 1307 |
opcodep[2] = (exp[1].X_add_number >> 8) & 255; |
| 1308 |
opcodep[3] = exp[1].X_add_number & 255; |
| 1309 |
break; |
| 1310 |
} |
| 1311 |
|
| 1312 |
case mmix_operands_x_regs_z: |
| 1313 |
|
| 1314 |
|
| 1315 |
case mmix_operands_regs: |
| 1316 |
|
| 1317 |
|
| 1318 |
case mmix_operands_regs_z: |
| 1319 |
|
| 1320 |
|
| 1321 |
case mmix_operands_pushgo: |
| 1322 |
|
| 1323 |
|
| 1324 |
case mmix_operands_regs_z_opt: |
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
if ((n_operands != 2 && n_operands != 3) |
| 1330 |
|| (exp[1].X_op == O_register && exp[1].X_add_number > 255) |
| 1331 |
|| (n_operands == 3 |
| 1332 |
&& ((exp[2].X_op == O_register |
| 1333 |
&& exp[2].X_add_number > 255 |
| 1334 |
&& mmix_gnu_syntax) |
| 1335 |
|| (exp[2].X_op == O_constant |
| 1336 |
&& (exp[2].X_add_number > 255 |
| 1337 |
|| exp[2].X_add_number < 0))))) |
| 1338 |
{ |
| 1339 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1340 |
instruction->name, operands); |
| 1341 |
return; |
| 1342 |
} |
| 1343 |
|
| 1344 |
if (n_operands == 2) |
| 1345 |
{ |
| 1346 |
symbolS *sym; |
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
opcodep[0] |= IMM_OFFSET_BIT; |
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
if (exp[1].X_op == O_register && exp[1].X_add_number <= 255) |
| 1359 |
{ |
| 1360 |
|
| 1361 |
opcodep[2] = exp[1].X_add_number; |
| 1362 |
break; |
| 1363 |
} |
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
if ((instruction->operands != mmix_operands_regs_z_opt |
| 1368 |
&& instruction->operands != mmix_operands_x_regs_z |
| 1369 |
&& instruction->operands != mmix_operands_pushgo) |
| 1370 |
|| (instruction->type != mmix_type_memaccess_octa |
| 1371 |
&& instruction->type != mmix_type_memaccess_tetra |
| 1372 |
&& instruction->type != mmix_type_memaccess_wyde |
| 1373 |
&& instruction->type != mmix_type_memaccess_byte |
| 1374 |
&& instruction->type != mmix_type_memaccess_block |
| 1375 |
&& instruction->type != mmix_type_jsr |
| 1376 |
&& instruction->type != mmix_type_branch)) |
| 1377 |
{ |
| 1378 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1379 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG); |
| 1380 |
break; |
| 1381 |
} |
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
sym = make_expr_symbol (exp + 1); |
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
fix_new (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1393 |
8, sym, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET); |
| 1394 |
break; |
| 1395 |
} |
| 1396 |
|
| 1397 |
if (exp[1].X_op == O_register) |
| 1398 |
opcodep[2] = exp[1].X_add_number; |
| 1399 |
else |
| 1400 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1401 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG); |
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
if (exp[2].X_op == O_register && exp[2].X_add_number <= 255) |
| 1408 |
opcodep[3] = exp[2].X_add_number; |
| 1409 |
else if (exp[2].X_op == O_constant |
| 1410 |
|| (exp[2].X_op == O_register && exp[2].X_add_number > 255)) |
| 1411 |
{ |
| 1412 |
opcodep[3] = exp[2].X_add_number; |
| 1413 |
opcodep[0] |= IMM_OFFSET_BIT; |
| 1414 |
} |
| 1415 |
else |
| 1416 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1417 |
1, exp + 2, 0, |
| 1418 |
(instruction->operands == mmix_operands_set |
| 1419 |
|| instruction->operands == mmix_operands_regs) |
| 1420 |
? BFD_RELOC_MMIX_REG : BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1421 |
break; |
| 1422 |
|
| 1423 |
case mmix_operands_pop: |
| 1424 |
|
| 1425 |
if (n_operands == 0 && ! mmix_gnu_syntax) |
| 1426 |
break; |
| 1427 |
if (n_operands == 1 && ! mmix_gnu_syntax) |
| 1428 |
goto a_single_24_bit_number_operand; |
| 1429 |
|
| 1430 |
case mmix_operands_reg_yz: |
| 1431 |
|
| 1432 |
if (n_operands != 2 |
| 1433 |
|| exp[1].X_op == O_register |
| 1434 |
|| (exp[1].X_op == O_constant |
| 1435 |
&& (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0))) |
| 1436 |
{ |
| 1437 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1438 |
instruction->name, operands); |
| 1439 |
return; |
| 1440 |
} |
| 1441 |
|
| 1442 |
if (exp[1].X_op == O_constant) |
| 1443 |
{ |
| 1444 |
opcodep[2] = (exp[1].X_add_number >> 8) & 255; |
| 1445 |
opcodep[3] = exp[1].X_add_number & 255; |
| 1446 |
} |
| 1447 |
else |
| 1448 |
|
| 1449 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1450 |
2, exp + 1, 0, BFD_RELOC_16); |
| 1451 |
break; |
| 1452 |
|
| 1453 |
case mmix_operands_jmp: |
| 1454 |
|
| 1455 |
break; |
| 1456 |
|
| 1457 |
case mmix_operands_roundregs: |
| 1458 |
|
| 1459 |
if ((n_operands == 3 && exp[2].X_op == O_constant) |
| 1460 |
|| (n_operands == 2 && exp[1].X_op == O_constant)) |
| 1461 |
{ |
| 1462 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1463 |
instruction->name, operands); |
| 1464 |
return; |
| 1465 |
} |
| 1466 |
|
| 1467 |
case mmix_operands_roundregs_z: |
| 1468 |
|
| 1469 |
|
| 1470 |
{ |
| 1471 |
|
| 1472 |
|
| 1473 |
int op2no = n_operands - 1; |
| 1474 |
|
| 1475 |
if ((n_operands != 2 && n_operands != 3) |
| 1476 |
|| ((exp[op2no].X_op == O_register |
| 1477 |
&& exp[op2no].X_add_number > 255) |
| 1478 |
|| (exp[op2no].X_op == O_constant |
| 1479 |
&& (exp[op2no].X_add_number > 255 |
| 1480 |
|| exp[op2no].X_add_number < 0))) |
| 1481 |
|| (n_operands == 3 |
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
&& ((exp[1].X_op == O_register |
| 1487 |
&& exp[1].X_add_number < 512) |
| 1488 |
|| (exp[1].X_op == O_constant |
| 1489 |
&& exp[1].X_add_number < 0 |
| 1490 |
&& exp[1].X_add_number > 4) |
| 1491 |
|| (exp[1].X_op != O_register |
| 1492 |
&& exp[1].X_op != O_constant)))) |
| 1493 |
{ |
| 1494 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1495 |
instruction->name, operands); |
| 1496 |
return; |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
if (n_operands == 3) |
| 1501 |
opcodep[2] = exp[1].X_add_number & 255; |
| 1502 |
|
| 1503 |
if (exp[op2no].X_op == O_register) |
| 1504 |
opcodep[3] = exp[op2no].X_add_number; |
| 1505 |
else if (exp[op2no].X_op == O_constant) |
| 1506 |
{ |
| 1507 |
opcodep[3] = exp[op2no].X_add_number; |
| 1508 |
opcodep[0] |= IMM_OFFSET_BIT; |
| 1509 |
} |
| 1510 |
else |
| 1511 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1512 |
1, exp + op2no, 0, |
| 1513 |
instruction->operands == mmix_operands_roundregs |
| 1514 |
? BFD_RELOC_MMIX_REG |
| 1515 |
: BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1516 |
break; |
| 1517 |
} |
| 1518 |
|
| 1519 |
case mmix_operands_sync: |
| 1520 |
a_single_24_bit_number_operand: |
| 1521 |
if (n_operands != 1 |
| 1522 |
|| exp[0].X_op == O_register |
| 1523 |
|| (exp[0].X_op == O_constant |
| 1524 |
&& (exp[0].X_add_number > 0xffffff || exp[0].X_add_number < 0))) |
| 1525 |
{ |
| 1526 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1527 |
instruction->name, operands); |
| 1528 |
return; |
| 1529 |
} |
| 1530 |
|
| 1531 |
if (exp[0].X_op == O_constant) |
| 1532 |
{ |
| 1533 |
opcodep[1] = (exp[0].X_add_number >> 16) & 255; |
| 1534 |
opcodep[2] = (exp[0].X_add_number >> 8) & 255; |
| 1535 |
opcodep[3] = exp[0].X_add_number & 255; |
| 1536 |
} |
| 1537 |
else |
| 1538 |
|
| 1539 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1540 |
3, exp + 0, 0, BFD_RELOC_24); |
| 1541 |
break; |
| 1542 |
|
| 1543 |
case mmix_operands_neg: |
| 1544 |
|
| 1545 |
|
| 1546 |
if ((n_operands != 3 && n_operands != 2) |
| 1547 |
|| (n_operands == 3 && exp[1].X_op == O_register) |
| 1548 |
|| ((exp[1].X_op == O_constant || exp[1].X_op == O_register) |
| 1549 |
&& (exp[1].X_add_number > 255 || exp[1].X_add_number < 0)) |
| 1550 |
|| (n_operands == 3 |
| 1551 |
&& ((exp[2].X_op == O_register && exp[2].X_add_number > 255) |
| 1552 |
|| (exp[2].X_op == O_constant |
| 1553 |
&& (exp[2].X_add_number > 255 |
| 1554 |
|| exp[2].X_add_number < 0))))) |
| 1555 |
{ |
| 1556 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1557 |
instruction->name, operands); |
| 1558 |
return; |
| 1559 |
} |
| 1560 |
|
| 1561 |
if (n_operands == 2) |
| 1562 |
{ |
| 1563 |
if (exp[1].X_op == O_register) |
| 1564 |
opcodep[3] = exp[1].X_add_number; |
| 1565 |
else if (exp[1].X_op == O_constant) |
| 1566 |
{ |
| 1567 |
opcodep[3] = exp[1].X_add_number; |
| 1568 |
opcodep[0] |= IMM_OFFSET_BIT; |
| 1569 |
} |
| 1570 |
else |
| 1571 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1572 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1573 |
break; |
| 1574 |
} |
| 1575 |
|
| 1576 |
if (exp[1].X_op == O_constant) |
| 1577 |
opcodep[2] = exp[1].X_add_number; |
| 1578 |
else |
| 1579 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1580 |
1, exp + 1, 0, BFD_RELOC_8); |
| 1581 |
|
| 1582 |
if (exp[2].X_op == O_register) |
| 1583 |
opcodep[3] = exp[2].X_add_number; |
| 1584 |
else if (exp[2].X_op == O_constant) |
| 1585 |
{ |
| 1586 |
opcodep[3] = exp[2].X_add_number; |
| 1587 |
opcodep[0] |= IMM_OFFSET_BIT; |
| 1588 |
} |
| 1589 |
else |
| 1590 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1591 |
1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1592 |
break; |
| 1593 |
|
| 1594 |
case mmix_operands_regaddr: |
| 1595 |
|
| 1596 |
break; |
| 1597 |
|
| 1598 |
case mmix_operands_get: |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
if (n_operands != 2 |
| 1603 |
|| (exp[1].X_op == O_register |
| 1604 |
&& (exp[1].X_add_number < 256 || exp[1].X_add_number >= 512)) |
| 1605 |
|| (exp[1].X_op == O_constant |
| 1606 |
&& (exp[1].X_add_number < 0 || exp[1].X_add_number > 256)) |
| 1607 |
|| (exp[1].X_op != O_constant && exp[1].X_op != O_register)) |
| 1608 |
{ |
| 1609 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1610 |
instruction->name, operands); |
| 1611 |
return; |
| 1612 |
} |
| 1613 |
|
| 1614 |
opcodep[3] = exp[1].X_add_number - 256; |
| 1615 |
break; |
| 1616 |
|
| 1617 |
case mmix_operands_put: |
| 1618 |
|
| 1619 |
if (n_operands != 2 |
| 1620 |
|| (exp[0].X_op == O_register |
| 1621 |
&& (exp[0].X_add_number < 256 || exp[0].X_add_number >= 512)) |
| 1622 |
|| (exp[0].X_op == O_constant |
| 1623 |
&& (exp[0].X_add_number < 0 || exp[0].X_add_number > 256)) |
| 1624 |
|| (exp[0].X_op != O_constant && exp[0].X_op != O_register)) |
| 1625 |
{ |
| 1626 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1627 |
instruction->name, operands); |
| 1628 |
return; |
| 1629 |
} |
| 1630 |
|
| 1631 |
opcodep[1] = exp[0].X_add_number - 256; |
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
if (exp[1].X_op == O_register) |
| 1636 |
opcodep[3] = exp[1].X_add_number; |
| 1637 |
else if (exp[1].X_op == O_constant) |
| 1638 |
{ |
| 1639 |
opcodep[3] = exp[1].X_add_number; |
| 1640 |
opcodep[0] |= IMM_OFFSET_BIT; |
| 1641 |
} |
| 1642 |
else |
| 1643 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1644 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1645 |
break; |
| 1646 |
|
| 1647 |
case mmix_operands_save: |
| 1648 |
|
| 1649 |
if (n_operands != 2 |
| 1650 |
|| exp[1].X_op != O_constant |
| 1651 |
|| exp[1].X_add_number != 0) |
| 1652 |
{ |
| 1653 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1654 |
instruction->name, operands); |
| 1655 |
return; |
| 1656 |
} |
| 1657 |
break; |
| 1658 |
|
| 1659 |
case mmix_operands_unsave: |
| 1660 |
if (n_operands < 2 && ! mmix_gnu_syntax) |
| 1661 |
{ |
| 1662 |
if (n_operands == 1) |
| 1663 |
{ |
| 1664 |
if (exp[0].X_op == O_register) |
| 1665 |
opcodep[3] = exp[0].X_add_number; |
| 1666 |
else |
| 1667 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1668 |
1, exp, 0, BFD_RELOC_MMIX_REG); |
| 1669 |
} |
| 1670 |
break; |
| 1671 |
} |
| 1672 |
|
| 1673 |
|
| 1674 |
if (n_operands != 2 |
| 1675 |
|| exp[0].X_op != O_constant |
| 1676 |
|| exp[0].X_add_number != 0 |
| 1677 |
|| exp[1].X_op == O_constant |
| 1678 |
|| (exp[1].X_op == O_register |
| 1679 |
&& exp[1].X_add_number > 255)) |
| 1680 |
{ |
| 1681 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1682 |
instruction->name, operands); |
| 1683 |
return; |
| 1684 |
} |
| 1685 |
|
| 1686 |
if (exp[1].X_op == O_register) |
| 1687 |
opcodep[3] = exp[1].X_add_number; |
| 1688 |
else |
| 1689 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1690 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG); |
| 1691 |
break; |
| 1692 |
|
| 1693 |
case mmix_operands_xyz_opt: |
| 1694 |
|
| 1695 |
if (n_operands == 0 && ! mmix_gnu_syntax) |
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
; |
| 1701 |
else if (n_operands == 1 && exp[0].X_op != O_register) |
| 1702 |
{ |
| 1703 |
if (exp[0].X_op == O_constant) |
| 1704 |
{ |
| 1705 |
if (exp[0].X_add_number > 255*255*255 |
| 1706 |
|| exp[0].X_add_number < 0) |
| 1707 |
{ |
| 1708 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1709 |
instruction->name, operands); |
| 1710 |
return; |
| 1711 |
} |
| 1712 |
else |
| 1713 |
{ |
| 1714 |
opcodep[1] = (exp[0].X_add_number >> 16) & 255; |
| 1715 |
opcodep[2] = (exp[0].X_add_number >> 8) & 255; |
| 1716 |
opcodep[3] = exp[0].X_add_number & 255; |
| 1717 |
} |
| 1718 |
} |
| 1719 |
else |
| 1720 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1721 |
3, exp, 0, BFD_RELOC_24); |
| 1722 |
} |
| 1723 |
else if (n_operands == 2 |
| 1724 |
&& exp[0].X_op != O_register |
| 1725 |
&& exp[1].X_op != O_register) |
| 1726 |
{ |
| 1727 |
|
| 1728 |
|
| 1729 |
if (exp[0].X_op == O_constant) |
| 1730 |
{ |
| 1731 |
if (exp[0].X_add_number > 255 |
| 1732 |
|| exp[0].X_add_number < 0) |
| 1733 |
{ |
| 1734 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1735 |
instruction->name, operands); |
| 1736 |
return; |
| 1737 |
} |
| 1738 |
else |
| 1739 |
opcodep[1] = exp[0].X_add_number & 255; |
| 1740 |
} |
| 1741 |
else |
| 1742 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1743 |
1, exp, 0, BFD_RELOC_8); |
| 1744 |
|
| 1745 |
if (exp[1].X_op == O_constant) |
| 1746 |
{ |
| 1747 |
if (exp[1].X_add_number > 255*255 |
| 1748 |
|| exp[1].X_add_number < 0) |
| 1749 |
{ |
| 1750 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1751 |
instruction->name, operands); |
| 1752 |
return; |
| 1753 |
} |
| 1754 |
else |
| 1755 |
{ |
| 1756 |
opcodep[2] = (exp[1].X_add_number >> 8) & 255; |
| 1757 |
opcodep[3] = exp[1].X_add_number & 255; |
| 1758 |
} |
| 1759 |
} |
| 1760 |
else |
| 1761 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1762 |
2, exp + 1, 0, BFD_RELOC_16); |
| 1763 |
} |
| 1764 |
else if (n_operands == 3 |
| 1765 |
&& exp[0].X_op != O_register |
| 1766 |
&& exp[1].X_op != O_register |
| 1767 |
&& exp[2].X_op != O_register) |
| 1768 |
{ |
| 1769 |
|
| 1770 |
|
| 1771 |
if (exp[0].X_op == O_constant) |
| 1772 |
{ |
| 1773 |
if (exp[0].X_add_number > 255 |
| 1774 |
|| exp[0].X_add_number < 0) |
| 1775 |
{ |
| 1776 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1777 |
instruction->name, operands); |
| 1778 |
return; |
| 1779 |
} |
| 1780 |
else |
| 1781 |
opcodep[1] = exp[0].X_add_number & 255; |
| 1782 |
} |
| 1783 |
else |
| 1784 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1785 |
1, exp, 0, BFD_RELOC_8); |
| 1786 |
|
| 1787 |
if (exp[1].X_op == O_constant) |
| 1788 |
{ |
| 1789 |
if (exp[1].X_add_number > 255 |
| 1790 |
|| exp[1].X_add_number < 0) |
| 1791 |
{ |
| 1792 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1793 |
instruction->name, operands); |
| 1794 |
return; |
| 1795 |
} |
| 1796 |
else |
| 1797 |
opcodep[2] = exp[1].X_add_number & 255; |
| 1798 |
} |
| 1799 |
else |
| 1800 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1801 |
1, exp + 1, 0, BFD_RELOC_8); |
| 1802 |
|
| 1803 |
if (exp[2].X_op == O_constant) |
| 1804 |
{ |
| 1805 |
if (exp[2].X_add_number > 255 |
| 1806 |
|| exp[2].X_add_number < 0) |
| 1807 |
{ |
| 1808 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1809 |
instruction->name, operands); |
| 1810 |
return; |
| 1811 |
} |
| 1812 |
else |
| 1813 |
opcodep[3] = exp[2].X_add_number & 255; |
| 1814 |
} |
| 1815 |
else |
| 1816 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1817 |
1, exp + 2, 0, BFD_RELOC_8); |
| 1818 |
} |
| 1819 |
else if (n_operands <= 3 |
| 1820 |
&& (strcmp (instruction->name, "trip") == 0 |
| 1821 |
|| strcmp (instruction->name, "trap") == 0)) |
| 1822 |
{ |
| 1823 |
|
| 1824 |
|
| 1825 |
if (n_operands == 3) |
| 1826 |
{ |
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
if (exp[0].X_op == O_register) |
| 1834 |
opcodep[1] = exp[0].X_add_number; |
| 1835 |
else |
| 1836 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, |
| 1837 |
1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1838 |
if (exp[1].X_op == O_register) |
| 1839 |
opcodep[2] = exp[1].X_add_number; |
| 1840 |
else |
| 1841 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1842 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1843 |
if (exp[2].X_op == O_register) |
| 1844 |
opcodep[3] = exp[2].X_add_number; |
| 1845 |
else |
| 1846 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1847 |
1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1848 |
} |
| 1849 |
else if (n_operands == 2) |
| 1850 |
{ |
| 1851 |
if (exp[0].X_op == O_register) |
| 1852 |
opcodep[2] = exp[0].X_add_number; |
| 1853 |
else |
| 1854 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, |
| 1855 |
1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1856 |
if (exp[1].X_op == O_register) |
| 1857 |
opcodep[3] = exp[1].X_add_number; |
| 1858 |
else |
| 1859 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1860 |
1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); |
| 1861 |
} |
| 1862 |
else |
| 1863 |
{ |
| 1864 |
as_bad (_("unsupported operands to %s: `%s'"), |
| 1865 |
instruction->name, operands); |
| 1866 |
return; |
| 1867 |
} |
| 1868 |
} |
| 1869 |
else |
| 1870 |
{ |
| 1871 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1872 |
instruction->name, operands); |
| 1873 |
return; |
| 1874 |
} |
| 1875 |
break; |
| 1876 |
|
| 1877 |
case mmix_operands_resume: |
| 1878 |
if (n_operands == 0 && ! mmix_gnu_syntax) |
| 1879 |
break; |
| 1880 |
|
| 1881 |
if (n_operands != 1 |
| 1882 |
|| exp[0].X_op == O_register |
| 1883 |
|| (exp[0].X_op == O_constant |
| 1884 |
&& (exp[0].X_add_number < 0 |
| 1885 |
|| exp[0].X_add_number > 255))) |
| 1886 |
{ |
| 1887 |
as_bad (_("invalid operands to opcode %s: `%s'"), |
| 1888 |
instruction->name, operands); |
| 1889 |
return; |
| 1890 |
} |
| 1891 |
|
| 1892 |
if (exp[0].X_op == O_constant) |
| 1893 |
opcodep[3] = exp[0].X_add_number; |
| 1894 |
else |
| 1895 |
fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, |
| 1896 |
1, exp + 0, 0, BFD_RELOC_8); |
| 1897 |
break; |
| 1898 |
|
| 1899 |
case mmix_operands_pushj: |
| 1900 |
|
| 1901 |
break; |
| 1902 |
|
| 1903 |
default: |
| 1904 |
BAD_CASE (instruction->operands); |
| 1905 |
} |
| 1906 |
} |
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
int |
| 1912 |
mmix_assemble_return_nonzero (str) |
| 1913 |
char *str; |
| 1914 |
{ |
| 1915 |
int last_error_count = had_errors (); |
| 1916 |
char *s2 = str; |
| 1917 |
char c; |
| 1918 |
|
| 1919 |
|
| 1920 |
while (ISALNUM (*s2)) |
| 1921 |
{ |
| 1922 |
if (ISUPPER ((unsigned char) *s2)) |
| 1923 |
*s2 = TOLOWER (*s2); |
| 1924 |
s2++; |
| 1925 |
} |
| 1926 |
|
| 1927 |
|
| 1928 |
for (s2 = str; *s2 && *s2 != '\n'; s2++) |
| 1929 |
; |
| 1930 |
|
| 1931 |
c = *s2; |
| 1932 |
*s2 = 0; |
| 1933 |
md_assemble (str); |
| 1934 |
*s2 = c; |
| 1935 |
|
| 1936 |
return had_errors () == last_error_count; |
| 1937 |
} |
| 1938 |
|
| 1939 |
|
| 1940 |
|
| 1941 |
static void |
| 1942 |
s_prefix (unused) |
| 1943 |
int unused ATTRIBUTE_UNUSED; |
| 1944 |
{ |
| 1945 |
char *p; |
| 1946 |
int c; |
| 1947 |
|
| 1948 |
SKIP_WHITESPACE (); |
| 1949 |
|
| 1950 |
p = input_line_pointer; |
| 1951 |
|
| 1952 |
c = get_symbol_end (); |
| 1953 |
|
| 1954 |
|
| 1955 |
if (*p == ':' && p[1] == 0) |
| 1956 |
mmix_current_prefix = NULL; |
| 1957 |
else |
| 1958 |
{ |
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1); |
| 1963 |
p = obstack_finish (&mmix_sym_obstack); |
| 1964 |
|
| 1965 |
|
| 1966 |
if (mmix_current_prefix != NULL || *p == ':') |
| 1967 |
p = mmix_prefix_name (p); |
| 1968 |
|
| 1969 |
mmix_current_prefix = p; |
| 1970 |
} |
| 1971 |
|
| 1972 |
*input_line_pointer = c; |
| 1973 |
|
| 1974 |
mmix_handle_rest_of_empty_line (); |
| 1975 |
} |
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
char * |
| 1985 |
mmix_prefix_name (shortname) |
| 1986 |
char *shortname; |
| 1987 |
{ |
| 1988 |
if (*shortname == ':') |
| 1989 |
return shortname + 1; |
| 1990 |
|
| 1991 |
if (mmix_current_prefix == NULL) |
| 1992 |
as_fatal (_("internal: mmix_prefix_name but empty prefix")); |
| 1993 |
|
| 1994 |
if (*shortname == '$') |
| 1995 |
return shortname; |
| 1996 |
|
| 1997 |
obstack_grow (&mmix_sym_obstack, mmix_current_prefix, |
| 1998 |
strlen (mmix_current_prefix)); |
| 1999 |
obstack_grow (&mmix_sym_obstack, shortname, strlen (shortname) + 1); |
| 2000 |
return obstack_finish (&mmix_sym_obstack); |
| 2001 |
} |
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
static void |
| 2010 |
mmix_greg_internal (label) |
| 2011 |
char *label; |
| 2012 |
{ |
| 2013 |
expressionS *expP = &mmix_raw_gregs[n_of_raw_gregs].exp; |
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
expression (expP); |
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
if (expP->X_op == O_absent) |
| 2022 |
{ |
| 2023 |
|
| 2024 |
expP->X_op = O_constant; |
| 2025 |
expP->X_add_number = 0; |
| 2026 |
expP->X_unsigned = 0; |
| 2027 |
expP->X_add_symbol = NULL; |
| 2028 |
expP->X_op_symbol = NULL; |
| 2029 |
} |
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
mmix_raw_gregs[n_of_raw_gregs].label |
| 2034 |
= mmix_current_prefix == NULL ? label : mmix_prefix_name (label); |
| 2035 |
|
| 2036 |
if (n_of_raw_gregs == MAX_GREGS - 1) |
| 2037 |
as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS); |
| 2038 |
else |
| 2039 |
n_of_raw_gregs++; |
| 2040 |
|
| 2041 |
mmix_handle_rest_of_empty_line (); |
| 2042 |
} |
| 2043 |
|
| 2044 |
|
| 2045 |
|
| 2046 |
static void |
| 2047 |
s_greg (unused) |
| 2048 |
int unused ATTRIBUTE_UNUSED; |
| 2049 |
{ |
| 2050 |
char *p; |
| 2051 |
char c; |
| 2052 |
p = input_line_pointer; |
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
c = get_symbol_end (); |
| 2059 |
|
| 2060 |
if (! is_end_of_line[(unsigned char) c]) |
| 2061 |
input_line_pointer++; |
| 2062 |
|
| 2063 |
if (*p) |
| 2064 |
{ |
| 2065 |
|
| 2066 |
|
| 2067 |
obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1); |
| 2068 |
mmix_greg_internal (obstack_finish (&mmix_sym_obstack)); |
| 2069 |
} |
| 2070 |
else |
| 2071 |
mmix_greg_internal (NULL); |
| 2072 |
} |
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
static void |
| 2077 |
s_bspec (unused) |
| 2078 |
int unused ATTRIBUTE_UNUSED; |
| 2079 |
{ |
| 2080 |
asection *expsec; |
| 2081 |
asection *sec; |
| 2082 |
char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20] |
| 2083 |
= MMIX_OTHER_SPEC_SECTION_PREFIX; |
| 2084 |
expressionS exp; |
| 2085 |
int n; |
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
expsec = expression (&exp); |
| 2092 |
mmix_handle_rest_of_empty_line (); |
| 2093 |
|
| 2094 |
|
| 2095 |
if (doing_bspec) |
| 2096 |
{ |
| 2097 |
as_bad (_("BSPEC already active. Nesting is not supported.")); |
| 2098 |
return; |
| 2099 |
} |
| 2100 |
|
| 2101 |
if (exp.X_op != O_constant |
| 2102 |
|| expsec != absolute_section |
| 2103 |
|| exp.X_add_number < 0 |
| 2104 |
|| exp.X_add_number > 65535) |
| 2105 |
{ |
| 2106 |
as_bad (_("invalid BSPEC expression")); |
| 2107 |
exp.X_add_number = 0; |
| 2108 |
} |
| 2109 |
|
| 2110 |
n = (int) exp.X_add_number; |
| 2111 |
|
| 2112 |
sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX), "%d", n); |
| 2113 |
sec = bfd_get_section_by_name (stdoutput, secname); |
| 2114 |
if (sec == NULL) |
| 2115 |
{ |
| 2116 |
|
| 2117 |
|
| 2118 |
char *newsecname = xstrdup (secname); |
| 2119 |
sec = bfd_make_section (stdoutput, newsecname); |
| 2120 |
|
| 2121 |
if (sec == NULL) |
| 2122 |
as_fatal (_("can't create section %s"), newsecname); |
| 2123 |
|
| 2124 |
if (!bfd_set_section_flags (stdoutput, sec, |
| 2125 |
bfd_get_section_flags (stdoutput, sec) |
| 2126 |
| SEC_READONLY)) |
| 2127 |
as_fatal (_("can't set section flags for section %s"), newsecname); |
| 2128 |
} |
| 2129 |
|
| 2130 |
|
| 2131 |
obj_elf_section_change_hook (); |
| 2132 |
subseg_set (sec, 0); |
| 2133 |
|
| 2134 |
|
| 2135 |
as_where (&bspec_file, &bspec_line); |
| 2136 |
|
| 2137 |
doing_bspec = 1; |
| 2138 |
} |
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
static void |
| 2143 |
s_espec (unused) |
| 2144 |
int unused ATTRIBUTE_UNUSED; |
| 2145 |
{ |
| 2146 |
|
| 2147 |
if (! doing_bspec) |
| 2148 |
{ |
| 2149 |
as_bad (_("ESPEC without preceding BSPEC")); |
| 2150 |
return; |
| 2151 |
} |
| 2152 |
|
| 2153 |
mmix_handle_rest_of_empty_line (); |
| 2154 |
doing_bspec = 0; |
| 2155 |
|
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
obj_elf_previous (0); |
| 2160 |
} |
| 2161 |
|
| 2162 |
|
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
static void |
| 2167 |
mmix_s_local (unused) |
| 2168 |
int unused ATTRIBUTE_UNUSED; |
| 2169 |
{ |
| 2170 |
expressionS exp; |
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
expression (&exp); |
| 2176 |
|
| 2177 |
if (exp.X_op == O_absent) |
| 2178 |
{ |
| 2179 |
as_bad (_("missing local expression")); |
| 2180 |
return; |
| 2181 |
} |
| 2182 |
else if (exp.X_op == O_register) |
| 2183 |
{ |
| 2184 |
|
| 2185 |
|
| 2186 |
exp.X_op = O_constant; |
| 2187 |
} |
| 2188 |
|
| 2189 |
fix_new_exp (frag_now, 0, 0, &exp, 0, BFD_RELOC_MMIX_LOCAL); |
| 2190 |
mmix_handle_rest_of_empty_line (); |
| 2191 |
} |
| 2192 |
|
| 2193 |
|
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
int |
| 2198 |
md_estimate_size_before_relax (fragP, segment) |
| 2199 |
fragS *fragP; |
| 2200 |
segT segment; |
| 2201 |
{ |
| 2202 |
int length; |
| 2203 |
|
| 2204 |
#define HANDLE_RELAXABLE(state) \ |
| 2205 |
case ENCODE_RELAX (state, STATE_UNDF): \ |
| 2206 |
if (fragP->fr_symbol != NULL \ |
| 2207 |
&& S_GET_SEGMENT (fragP->fr_symbol) == segment \ |
| 2208 |
&& !S_IS_WEAK (fragP->fr_symbol)) \ |
| 2209 |
{ \ |
| 2210 |
\ |
| 2211 |
fragP->fr_subtype \ |
| 2212 |
= ENCODE_RELAX (state, STATE_ZERO); \ |
| 2213 |
} \ |
| 2214 |
break; |
| 2215 |
|
| 2216 |
switch (fragP->fr_subtype) |
| 2217 |
{ |
| 2218 |
HANDLE_RELAXABLE (STATE_GETA); |
| 2219 |
HANDLE_RELAXABLE (STATE_BCC); |
| 2220 |
HANDLE_RELAXABLE (STATE_JMP); |
| 2221 |
|
| 2222 |
case ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF): |
| 2223 |
if (fragP->fr_symbol != NULL |
| 2224 |
&& S_GET_SEGMENT (fragP->fr_symbol) == segment |
| 2225 |
&& !S_IS_WEAK (fragP->fr_symbol)) |
| 2226 |
|
| 2227 |
fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO); |
| 2228 |
else if (pushj_stubs) |
| 2229 |
|
| 2230 |
|
| 2231 |
fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO); |
| 2232 |
|
| 2233 |
case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO): |
| 2234 |
case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO): |
| 2235 |
|
| 2236 |
seg_info (segment)->tc_segment_info_data.last_stubfrag = fragP; |
| 2237 |
break; |
| 2238 |
|
| 2239 |
case ENCODE_RELAX (STATE_GETA, STATE_ZERO): |
| 2240 |
case ENCODE_RELAX (STATE_BCC, STATE_ZERO): |
| 2241 |
case ENCODE_RELAX (STATE_JMP, STATE_ZERO): |
| 2242 |
|
| 2243 |
|
| 2244 |
break; |
| 2245 |
|
| 2246 |
case STATE_GREG_DEF: |
| 2247 |
length = fragP->tc_frag_data != NULL ? 0 : 8; |
| 2248 |
fragP->fr_var = length; |
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
return length; |
| 2253 |
break; |
| 2254 |
|
| 2255 |
default: |
| 2256 |
BAD_CASE (fragP->fr_subtype); |
| 2257 |
} |
| 2258 |
|
| 2259 |
length = mmix_relax_table[fragP->fr_subtype].rlx_length; |
| 2260 |
fragP->fr_var = length; |
| 2261 |
|
| 2262 |
return length; |
| 2263 |
} |
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
char * |
| 2271 |
md_atof (type, litP, sizeP) |
| 2272 |
int type; |
| 2273 |
char *litP; |
| 2274 |
int *sizeP; |
| 2275 |
{ |
| 2276 |
int prec; |
| 2277 |
LITTLENUM_TYPE words[4]; |
| 2278 |
char *t; |
| 2279 |
int i; |
| 2280 |
|
| 2281 |
switch (type) |
| 2282 |
{ |
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
case 'f': |
| 2289 |
case 'r': |
| 2290 |
prec = 2; |
| 2291 |
break; |
| 2292 |
case 'd': |
| 2293 |
prec = 4; |
| 2294 |
break; |
| 2295 |
default: |
| 2296 |
*sizeP = 0; |
| 2297 |
return _("bad call to md_atof"); |
| 2298 |
} |
| 2299 |
|
| 2300 |
t = atof_ieee (input_line_pointer, type, words); |
| 2301 |
if (t) |
| 2302 |
input_line_pointer = t; |
| 2303 |
|
| 2304 |
*sizeP = prec * 2; |
| 2305 |
|
| 2306 |
for (i = 0; i < prec; i++) |
| 2307 |
{ |
| 2308 |
md_number_to_chars (litP, (valueT) words[i], 2); |
| 2309 |
litP += 2; |
| 2310 |
} |
| 2311 |
return NULL; |
| 2312 |
} |
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
void |
| 2317 |
md_convert_frag (abfd, sec, fragP) |
| 2318 |
bfd *abfd ATTRIBUTE_UNUSED; |
| 2319 |
segT sec ATTRIBUTE_UNUSED; |
| 2320 |
fragS *fragP; |
| 2321 |
{ |
| 2322 |
|
| 2323 |
char *var_partp; |
| 2324 |
|
| 2325 |
|
| 2326 |
char *opcodep; |
| 2327 |
|
| 2328 |
|
| 2329 |
int var_part_size = 0; |
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
symbolS *symbolP; |
| 2334 |
unsigned long var_part_offset; |
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
fragS *opc_fragP = fragP->tc_frag_data; |
| 2339 |
fixS *tmpfixP; |
| 2340 |
|
| 2341 |
|
| 2342 |
bfd_vma target_address; |
| 2343 |
bfd_vma opcode_address; |
| 2344 |
|
| 2345 |
know (fragP->fr_type == rs_machine_dependent); |
| 2346 |
|
| 2347 |
var_part_offset = fragP->fr_fix; |
| 2348 |
var_partp = fragP->fr_literal + var_part_offset; |
| 2349 |
opcodep = fragP->fr_opcode; |
| 2350 |
|
| 2351 |
symbolP = fragP->fr_symbol; |
| 2352 |
|
| 2353 |
target_address |
| 2354 |
= ((symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset); |
| 2355 |
|
| 2356 |
|
| 2357 |
opcode_address = fragP->fr_address + fragP->fr_fix - 4; |
| 2358 |
|
| 2359 |
switch (fragP->fr_subtype) |
| 2360 |
{ |
| 2361 |
case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO): |
| 2362 |
|
| 2363 |
mmix_set_geta_branch_offset (opcodep, 0); |
| 2364 |
tmpfixP = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 8, |
| 2365 |
fragP->fr_symbol, fragP->fr_offset, 1, |
| 2366 |
BFD_RELOC_MMIX_PUSHJ_STUBBABLE); |
| 2367 |
COPY_FR_WHERE_TO_FX (fragP, tmpfixP); |
| 2368 |
var_part_size = 0; |
| 2369 |
break; |
| 2370 |
|
| 2371 |
case ENCODE_RELAX (STATE_GETA, STATE_ZERO): |
| 2372 |
case ENCODE_RELAX (STATE_BCC, STATE_ZERO): |
| 2373 |
case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO): |
| 2374 |
mmix_set_geta_branch_offset (opcodep, target_address - opcode_address); |
| 2375 |
if (linkrelax) |
| 2376 |
{ |
| 2377 |
tmpfixP |
| 2378 |
= fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4, |
| 2379 |
fragP->fr_symbol, fragP->fr_offset, 1, |
| 2380 |
BFD_RELOC_MMIX_ADDR19); |
| 2381 |
COPY_FR_WHERE_TO_FX (fragP, tmpfixP); |
| 2382 |
} |
| 2383 |
var_part_size = 0; |
| 2384 |
break; |
| 2385 |
|
| 2386 |
case ENCODE_RELAX (STATE_JMP, STATE_ZERO): |
| 2387 |
mmix_set_jmp_offset (opcodep, target_address - opcode_address); |
| 2388 |
if (linkrelax) |
| 2389 |
{ |
| 2390 |
tmpfixP |
| 2391 |
= fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4, |
| 2392 |
fragP->fr_symbol, fragP->fr_offset, 1, |
| 2393 |
BFD_RELOC_MMIX_ADDR27); |
| 2394 |
COPY_FR_WHERE_TO_FX (fragP, tmpfixP); |
| 2395 |
} |
| 2396 |
var_part_size = 0; |
| 2397 |
break; |
| 2398 |
|
| 2399 |
case STATE_GREG_DEF: |
| 2400 |
if (fragP->tc_frag_data == NULL) |
| 2401 |
{ |
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
md_number_to_chars (var_partp, 0, 8); |
| 2406 |
tmpfixP |
| 2407 |
= fix_new (fragP, var_partp - fragP->fr_literal, 8, |
| 2408 |
fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_64); |
| 2409 |
COPY_FR_WHERE_TO_FX (fragP, tmpfixP); |
| 2410 |
mmix_gregs[n_of_cooked_gregs++] = tmpfixP; |
| 2411 |
var_part_size = 8; |
| 2412 |
} |
| 2413 |
else |
| 2414 |
var_part_size = 0; |
| 2415 |
break; |
| 2416 |
|
| 2417 |
#define HANDLE_MAX_RELOC(state, reloc) \ |
| 2418 |
case ENCODE_RELAX (state, STATE_MAX): \ |
| 2419 |
var_part_size \ |
| 2420 |
= mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \ |
| 2421 |
mmix_fill_nops (var_partp, var_part_size / 4); \ |
| 2422 |
if (warn_on_expansion) \ |
| 2423 |
as_warn_where (fragP->fr_file, fragP->fr_line, \ |
| 2424 |
_("operand out of range, instruction expanded")); \ |
| 2425 |
tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \ |
| 2426 |
fragP->fr_symbol, fragP->fr_offset, 1, reloc); \ |
| 2427 |
COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \ |
| 2428 |
break |
| 2429 |
|
| 2430 |
HANDLE_MAX_RELOC (STATE_GETA, BFD_RELOC_MMIX_GETA); |
| 2431 |
HANDLE_MAX_RELOC (STATE_BCC, BFD_RELOC_MMIX_CBRANCH); |
| 2432 |
HANDLE_MAX_RELOC (STATE_PUSHJ, BFD_RELOC_MMIX_PUSHJ); |
| 2433 |
HANDLE_MAX_RELOC (STATE_JMP, BFD_RELOC_MMIX_JMP); |
| 2434 |
|
| 2435 |
default: |
| 2436 |
BAD_CASE (fragP->fr_subtype); |
| 2437 |
break; |
| 2438 |
} |
| 2439 |
|
| 2440 |
fragP->fr_fix += var_part_size; |
| 2441 |
fragP->fr_var = 0; |
| 2442 |
} |
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
|
| 2448 |
|
| 2449 |
|
| 2450 |
void |
| 2451 |
md_apply_fix3 (fixP, valP, segment) |
| 2452 |
fixS * fixP; |
| 2453 |
valueT * valP; |
| 2454 |
segT segment; |
| 2455 |
{ |
| 2456 |
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 2457 |
|
| 2458 |
offsetT val = (offsetT) * valP; |
| 2459 |
segT symsec |
| 2460 |
= (fixP->fx_addsy == NULL |
| 2461 |
? absolute_section : S_GET_SEGMENT (fixP->fx_addsy)); |
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
if (fixP->fx_addsy != NULL |
| 2467 |
&& (! S_IS_DEFINED (fixP->fx_addsy) |
| 2468 |
|| S_IS_WEAK (fixP->fx_addsy) |
| 2469 |
|| (fixP->fx_pcrel && symsec != segment) |
| 2470 |
|| (! fixP->fx_pcrel |
| 2471 |
&& symsec != absolute_section |
| 2472 |
&& ((fixP->fx_r_type != BFD_RELOC_MMIX_REG |
| 2473 |
&& fixP->fx_r_type != BFD_RELOC_MMIX_REG_OR_BYTE) |
| 2474 |
|| symsec != reg_section)))) |
| 2475 |
{ |
| 2476 |
fixP->fx_done = 0; |
| 2477 |
return; |
| 2478 |
} |
| 2479 |
else if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL |
| 2480 |
|| fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
| 2481 |
|| fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
| 2482 |
{ |
| 2483 |
|
| 2484 |
fixP->fx_done = 0; |
| 2485 |
return; |
| 2486 |
} |
| 2487 |
else |
| 2488 |
|
| 2489 |
fixP->fx_done = 1; |
| 2490 |
|
| 2491 |
switch (fixP->fx_r_type) |
| 2492 |
{ |
| 2493 |
case BFD_RELOC_64: |
| 2494 |
case BFD_RELOC_32: |
| 2495 |
case BFD_RELOC_24: |
| 2496 |
case BFD_RELOC_16: |
| 2497 |
case BFD_RELOC_8: |
| 2498 |
case BFD_RELOC_64_PCREL: |
| 2499 |
case BFD_RELOC_32_PCREL: |
| 2500 |
case BFD_RELOC_24_PCREL: |
| 2501 |
case BFD_RELOC_16_PCREL: |
| 2502 |
case BFD_RELOC_8_PCREL: |
| 2503 |
md_number_to_chars (buf, val, fixP->fx_size); |
| 2504 |
break; |
| 2505 |
|
| 2506 |
case BFD_RELOC_MMIX_ADDR19: |
| 2507 |
if (expand_op) |
| 2508 |
{ |
| 2509 |
|
| 2510 |
BAD_CASE (fixP->fx_r_type); |
| 2511 |
break; |
| 2512 |
} |
| 2513 |
|
| 2514 |
case BFD_RELOC_MMIX_GETA: |
| 2515 |
case BFD_RELOC_MMIX_CBRANCH: |
| 2516 |
case BFD_RELOC_MMIX_PUSHJ: |
| 2517 |
case BFD_RELOC_MMIX_PUSHJ_STUBBABLE: |
| 2518 |
|
| 2519 |
|
| 2520 |
if (val < -(((offsetT) 1 << 19)/2) |
| 2521 |
|| val >= ((offsetT) 1 << 19)/2 - 1 |
| 2522 |
|| (val & 3) != 0) |
| 2523 |
{ |
| 2524 |
if (warn_on_expansion) |
| 2525 |
as_warn_where (fixP->fx_file, fixP->fx_line, |
| 2526 |
_("operand out of range")); |
| 2527 |
fixP->fx_done = 0; |
| 2528 |
val = 0; |
| 2529 |
} |
| 2530 |
mmix_set_geta_branch_offset (buf, val); |
| 2531 |
break; |
| 2532 |
|
| 2533 |
case BFD_RELOC_MMIX_ADDR27: |
| 2534 |
if (expand_op) |
| 2535 |
{ |
| 2536 |
|
| 2537 |
BAD_CASE (fixP->fx_r_type); |
| 2538 |
break; |
| 2539 |
} |
| 2540 |
|
| 2541 |
case BFD_RELOC_MMIX_JMP: |
| 2542 |
|
| 2543 |
|
| 2544 |
if (val < -(((offsetT) 1 << 27)/2) |
| 2545 |
|| val >= ((offsetT) 1 << 27)/2 - 1 |
| 2546 |
|| (val & 3) != 0) |
| 2547 |
{ |
| 2548 |
if (warn_on_expansion) |
| 2549 |
as_warn_where (fixP->fx_file, fixP->fx_line, |
| 2550 |
_("operand out of range")); |
| 2551 |
fixP->fx_done = 0; |
| 2552 |
val = 0; |
| 2553 |
} |
| 2554 |
mmix_set_jmp_offset (buf, val); |
| 2555 |
break; |
| 2556 |
|
| 2557 |
case BFD_RELOC_MMIX_REG_OR_BYTE: |
| 2558 |
if (fixP->fx_addsy != NULL |
| 2559 |
&& (S_GET_SEGMENT (fixP->fx_addsy) != reg_section |
| 2560 |
|| S_GET_VALUE (fixP->fx_addsy) > 255) |
| 2561 |
&& S_GET_SEGMENT (fixP->fx_addsy) != absolute_section) |
| 2562 |
{ |
| 2563 |
as_bad_where (fixP->fx_file, fixP->fx_line, |
| 2564 |
_("invalid operands")); |
| 2565 |
|
| 2566 |
|
| 2567 |
fixP->fx_done = 1; |
| 2568 |
} |
| 2569 |
|
| 2570 |
buf[0] = val; |
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
if ((fixP->fx_where & 3) == 3 |
| 2577 |
&& (fixP->fx_addsy == NULL |
| 2578 |
|| S_GET_SEGMENT (fixP->fx_addsy) == absolute_section)) |
| 2579 |
buf[-3] |= IMM_OFFSET_BIT; |
| 2580 |
break; |
| 2581 |
|
| 2582 |
case BFD_RELOC_MMIX_REG: |
| 2583 |
if (fixP->fx_addsy == NULL |
| 2584 |
|| S_GET_SEGMENT (fixP->fx_addsy) != reg_section |
| 2585 |
|| S_GET_VALUE (fixP->fx_addsy) > 255) |
| 2586 |
{ |
| 2587 |
as_bad_where (fixP->fx_file, fixP->fx_line, |
| 2588 |
_("invalid operands")); |
| 2589 |
fixP->fx_done = 1; |
| 2590 |
} |
| 2591 |
|
| 2592 |
*buf = val; |
| 2593 |
break; |
| 2594 |
|
| 2595 |
case BFD_RELOC_MMIX_BASE_PLUS_OFFSET: |
| 2596 |
|
| 2597 |
fixP->fx_done = 0; |
| 2598 |
return; |
| 2599 |
|
| 2600 |
case BFD_RELOC_MMIX_PUSHJ_1: |
| 2601 |
case BFD_RELOC_MMIX_PUSHJ_2: |
| 2602 |
case BFD_RELOC_MMIX_PUSHJ_3: |
| 2603 |
case BFD_RELOC_MMIX_CBRANCH_J: |
| 2604 |
case BFD_RELOC_MMIX_CBRANCH_1: |
| 2605 |
case BFD_RELOC_MMIX_CBRANCH_2: |
| 2606 |
case BFD_RELOC_MMIX_CBRANCH_3: |
| 2607 |
case BFD_RELOC_MMIX_GETA_1: |
| 2608 |
case BFD_RELOC_MMIX_GETA_2: |
| 2609 |
case BFD_RELOC_MMIX_GETA_3: |
| 2610 |
case BFD_RELOC_MMIX_JMP_1: |
| 2611 |
case BFD_RELOC_MMIX_JMP_2: |
| 2612 |
case BFD_RELOC_MMIX_JMP_3: |
| 2613 |
default: |
| 2614 |
BAD_CASE (fixP->fx_r_type); |
| 2615 |
break; |
| 2616 |
} |
| 2617 |
|
| 2618 |
if (fixP->fx_done) |
| 2619 |
|
| 2620 |
|
| 2621 |
fixP->fx_offset = val; |
| 2622 |
} |
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
static int |
| 2628 |
cmp_greg_val_greg_symbol_fixes (p1, p2) |
| 2629 |
const PTR p1; |
| 2630 |
const PTR p2; |
| 2631 |
{ |
| 2632 |
offsetT val1 = *(offsetT *) p1; |
| 2633 |
offsetT val2 = ((struct mmix_symbol_greg_fixes *) p2)->offs; |
| 2634 |
|
| 2635 |
if (val1 >= val2 && val1 < val2 + 255) |
| 2636 |
return 0; |
| 2637 |
|
| 2638 |
if (val1 > val2) |
| 2639 |
return 1; |
| 2640 |
|
| 2641 |
return -1; |
| 2642 |
} |
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
arelent * |
| 2647 |
tc_gen_reloc (section, fixP) |
| 2648 |
asection *section ATTRIBUTE_UNUSED; |
| 2649 |
fixS *fixP; |
| 2650 |
{ |
| 2651 |
bfd_signed_vma val |
| 2652 |
= fixP->fx_offset |
| 2653 |
+ (fixP->fx_addsy != NULL |
| 2654 |
&& !S_IS_WEAK (fixP->fx_addsy) |
| 2655 |
&& !S_IS_COMMON (fixP->fx_addsy) |
| 2656 |
? S_GET_VALUE (fixP->fx_addsy) : 0); |
| 2657 |
arelent *relP; |
| 2658 |
bfd_reloc_code_real_type code = BFD_RELOC_NONE; |
| 2659 |
char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 2660 |
symbolS *addsy = fixP->fx_addsy; |
| 2661 |
asection *addsec = addsy == NULL ? NULL : S_GET_SEGMENT (addsy); |
| 2662 |
asymbol *baddsy = addsy != NULL ? symbol_get_bfdsym (addsy) : NULL; |
| 2663 |
bfd_vma addend |
| 2664 |
= val - (baddsy == NULL || S_IS_COMMON (addsy) || S_IS_WEAK (addsy) |
| 2665 |
? 0 : bfd_asymbol_value (baddsy)); |
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
if (bfd_section_size (section->owner, section) == 0) |
| 2677 |
as_bad_where |
| 2678 |
(fixP->fx_file, fixP->fx_line, |
| 2679 |
fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL |
| 2680 |
|
| 2681 |
|
| 2682 |
? _("directive LOCAL must be placed in code or data") |
| 2683 |
: _("internal confusion: relocation in a section without contents")); |
| 2684 |
|
| 2685 |
|
| 2686 |
switch (fixP->fx_r_type) |
| 2687 |
{ |
| 2688 |
case BFD_RELOC_64: |
| 2689 |
case BFD_RELOC_32: |
| 2690 |
case BFD_RELOC_24: |
| 2691 |
case BFD_RELOC_16: |
| 2692 |
case BFD_RELOC_8: |
| 2693 |
code = fixP->fx_r_type; |
| 2694 |
|
| 2695 |
if (addsy == NULL || bfd_is_abs_section (addsec)) |
| 2696 |
{ |
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
md_number_to_chars (buf, val, fixP->fx_size); |
| 2705 |
return NULL; |
| 2706 |
} |
| 2707 |
break; |
| 2708 |
|
| 2709 |
case BFD_RELOC_64_PCREL: |
| 2710 |
case BFD_RELOC_32_PCREL: |
| 2711 |
case BFD_RELOC_24_PCREL: |
| 2712 |
case BFD_RELOC_16_PCREL: |
| 2713 |
case BFD_RELOC_8_PCREL: |
| 2714 |
case BFD_RELOC_MMIX_LOCAL: |
| 2715 |
case BFD_RELOC_VTABLE_INHERIT: |
| 2716 |
case BFD_RELOC_VTABLE_ENTRY: |
| 2717 |
case BFD_RELOC_MMIX_GETA: |
| 2718 |
case BFD_RELOC_MMIX_GETA_1: |
| 2719 |
case BFD_RELOC_MMIX_GETA_2: |
| 2720 |
case BFD_RELOC_MMIX_GETA_3: |
| 2721 |
case BFD_RELOC_MMIX_CBRANCH: |
| 2722 |
case BFD_RELOC_MMIX_CBRANCH_J: |
| 2723 |
case BFD_RELOC_MMIX_CBRANCH_1: |
| 2724 |
case BFD_RELOC_MMIX_CBRANCH_2: |
| 2725 |
case BFD_RELOC_MMIX_CBRANCH_3: |
| 2726 |
case BFD_RELOC_MMIX_PUSHJ: |
| 2727 |
case BFD_RELOC_MMIX_PUSHJ_1: |
| 2728 |
case BFD_RELOC_MMIX_PUSHJ_2: |
| 2729 |
case BFD_RELOC_MMIX_PUSHJ_3: |
| 2730 |
case BFD_RELOC_MMIX_PUSHJ_STUBBABLE: |
| 2731 |
case BFD_RELOC_MMIX_JMP: |
| 2732 |
case BFD_RELOC_MMIX_JMP_1: |
| 2733 |
case BFD_RELOC_MMIX_JMP_2: |
| 2734 |
case BFD_RELOC_MMIX_JMP_3: |
| 2735 |
case BFD_RELOC_MMIX_ADDR19: |
| 2736 |
case BFD_RELOC_MMIX_ADDR27: |
| 2737 |
code = fixP->fx_r_type; |
| 2738 |
break; |
| 2739 |
|
| 2740 |
case BFD_RELOC_MMIX_REG_OR_BYTE: |
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
if (addsy != NULL |
| 2745 |
&& (bfd_is_und_section (addsec) |
| 2746 |
|| strcmp (bfd_get_section_name (addsec->owner, addsec), |
| 2747 |
MMIX_REG_CONTENTS_SECTION_NAME) == 0)) |
| 2748 |
{ |
| 2749 |
code = fixP->fx_r_type; |
| 2750 |
break; |
| 2751 |
} |
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
if (addsy != NULL |
| 2756 |
&& (S_GET_SEGMENT (addsy) != real_reg_section |
| 2757 |
|| val > 255 |
| 2758 |
|| val < 0) |
| 2759 |
&& ! bfd_is_abs_section (addsec)) |
| 2760 |
goto badop; |
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
if ((fixP->fx_where & 3) == 3 |
| 2765 |
&& (addsy == NULL || bfd_is_abs_section (addsec))) |
| 2766 |
buf[-3] |= IMM_OFFSET_BIT; |
| 2767 |
|
| 2768 |
buf[0] = val; |
| 2769 |
return NULL; |
| 2770 |
|
| 2771 |
case BFD_RELOC_MMIX_BASE_PLUS_OFFSET: |
| 2772 |
if (addsy != NULL |
| 2773 |
&& strcmp (bfd_get_section_name (addsec->owner, addsec), |
| 2774 |
MMIX_REG_CONTENTS_SECTION_NAME) == 0) |
| 2775 |
{ |
| 2776 |
|
| 2777 |
|
| 2778 |
code = BFD_RELOC_MMIX_REG; |
| 2779 |
break; |
| 2780 |
} |
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
if (addsy == NULL || addsec != real_reg_section) |
| 2788 |
{ |
| 2789 |
struct mmix_symbol_gregs *gregs; |
| 2790 |
struct mmix_symbol_greg_fixes *fix; |
| 2791 |
|
| 2792 |
if (S_IS_DEFINED (addsy) |
| 2793 |
&& !bfd_is_com_section (addsec) |
| 2794 |
&& !S_IS_WEAK (addsy)) |
| 2795 |
{ |
| 2796 |
if (! symbol_section_p (addsy) && ! bfd_is_abs_section (addsec)) |
| 2797 |
as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section")); |
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
if (lowest_data_loc != (bfd_vma) -1 |
| 2805 |
&& (bfd_vma) val + 256 > lowest_data_loc |
| 2806 |
&& bfd_is_abs_section (addsec)) |
| 2807 |
{ |
| 2808 |
val -= (offsetT) lowest_data_loc; |
| 2809 |
addsy = section_symbol (data_section); |
| 2810 |
} |
| 2811 |
|
| 2812 |
else if (lowest_text_loc != (bfd_vma) -1 |
| 2813 |
&& (bfd_vma) val + 256 > lowest_text_loc |
| 2814 |
&& bfd_is_abs_section (addsec)) |
| 2815 |
{ |
| 2816 |
val -= (offsetT) lowest_text_loc; |
| 2817 |
addsy = section_symbol (text_section); |
| 2818 |
} |
| 2819 |
} |
| 2820 |
|
| 2821 |
gregs = *symbol_get_tc (addsy); |
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
if (gregs == NULL |
| 2826 |
|| (fix = bsearch (&val, gregs->greg_fixes, gregs->n_gregs, |
| 2827 |
sizeof (gregs->greg_fixes[0]), |
| 2828 |
cmp_greg_val_greg_symbol_fixes)) == NULL |
| 2829 |
|
| 2830 |
|| fix->offs > val |
| 2831 |
|
| 2832 |
|
| 2833 |
|| fix->offs + 255 < val) |
| 2834 |
{ |
| 2835 |
|
| 2836 |
|
| 2837 |
if (allocate_undefined_gregs_in_linker) |
| 2838 |
{ |
| 2839 |
|
| 2840 |
code = fixP->fx_r_type; |
| 2841 |
break; |
| 2842 |
} |
| 2843 |
else |
| 2844 |
as_bad_where (fixP->fx_file, fixP->fx_line, |
| 2845 |
_("no suitable GREG definition for operands")); |
| 2846 |
return NULL; |
| 2847 |
} |
| 2848 |
else |
| 2849 |
{ |
| 2850 |
|
| 2851 |
|
| 2852 |
|
| 2853 |
buf[1] = val - fix->offs; |
| 2854 |
code = BFD_RELOC_MMIX_REG; |
| 2855 |
baddsy |
| 2856 |
= (bfd_get_section_by_name (stdoutput, |
| 2857 |
MMIX_REG_CONTENTS_SECTION_NAME) |
| 2858 |
->symbol); |
| 2859 |
|
| 2860 |
addend = fix->fix->fx_frag->fr_address + fix->fix->fx_where; |
| 2861 |
} |
| 2862 |
} |
| 2863 |
else if (S_GET_VALUE (addsy) > 255) |
| 2864 |
as_bad_where (fixP->fx_file, fixP->fx_line, |
| 2865 |
_("invalid operands")); |
| 2866 |
else |
| 2867 |
{ |
| 2868 |
*buf = val; |
| 2869 |
return NULL; |
| 2870 |
} |
| 2871 |
break; |
| 2872 |
|
| 2873 |
case BFD_RELOC_MMIX_REG: |
| 2874 |
if (addsy != NULL |
| 2875 |
&& (bfd_is_und_section (addsec) |
| 2876 |
|| strcmp (bfd_get_section_name (addsec->owner, addsec), |
| 2877 |
MMIX_REG_CONTENTS_SECTION_NAME) == 0)) |
| 2878 |
{ |
| 2879 |
code = fixP->fx_r_type; |
| 2880 |
break; |
| 2881 |
} |
| 2882 |
|
| 2883 |
if (addsy != NULL |
| 2884 |
&& (addsec != real_reg_section |
| 2885 |
|| val > 255 |
| 2886 |
|| val < 0) |
| 2887 |
&& ! bfd_is_und_section (addsec)) |
| 2888 |
|
| 2889 |
; |
| 2890 |
else |
| 2891 |
{ |
| 2892 |
buf[0] = val; |
| 2893 |
return NULL; |
| 2894 |
} |
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
|
| 2900 |
badop: |
| 2901 |
default: |
| 2902 |
as_bad_where |
| 2903 |
(fixP->fx_file, fixP->fx_line, |
| 2904 |
_("operands were not reducible at assembly-time")); |
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
fixP->fx_addsy = NULL; |
| 2909 |
return NULL; |
| 2910 |
} |
| 2911 |
|
| 2912 |
relP = (arelent *) xmalloc (sizeof (arelent)); |
| 2913 |
assert (relP != 0); |
| 2914 |
relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); |
| 2915 |
*relP->sym_ptr_ptr = baddsy; |
| 2916 |
relP->address = fixP->fx_frag->fr_address + fixP->fx_where; |
| 2917 |
|
| 2918 |
relP->addend = addend; |
| 2919 |
|
| 2920 |
|
| 2921 |
|
| 2922 |
|
| 2923 |
relP->howto = bfd_reloc_type_lookup (stdoutput, code); |
| 2924 |
if (! relP->howto) |
| 2925 |
{ |
| 2926 |
const char *name; |
| 2927 |
|
| 2928 |
name = S_GET_NAME (addsy); |
| 2929 |
if (name == NULL) |
| 2930 |
name = _("<unknown>"); |
| 2931 |
as_fatal (_("cannot generate relocation type for symbol %s, code %s"), |
| 2932 |
name, bfd_get_reloc_code_name (code)); |
| 2933 |
} |
| 2934 |
|
| 2935 |
return relP; |
| 2936 |
} |
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
void |
| 2943 |
mmix_handle_mmixal () |
| 2944 |
{ |
| 2945 |
char *s0 = input_line_pointer; |
| 2946 |
char *s; |
| 2947 |
char *label = NULL; |
| 2948 |
char c; |
| 2949 |
|
| 2950 |
if (pending_label != NULL) |
| 2951 |
as_fatal (_("internal: unhandled label %s"), pending_label); |
| 2952 |
|
| 2953 |
if (mmix_gnu_syntax) |
| 2954 |
return; |
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
if (input_line_pointer[0] == '.') |
| 2960 |
{ |
| 2961 |
label_without_colon_this_line = 0; |
| 2962 |
return; |
| 2963 |
} |
| 2964 |
|
| 2965 |
|
| 2966 |
while (1) |
| 2967 |
{ |
| 2968 |
if (*s0 == 0 || is_end_of_line[(unsigned int) *s0]) |
| 2969 |
return; |
| 2970 |
|
| 2971 |
if (! ISSPACE (*s0)) |
| 2972 |
break; |
| 2973 |
|
| 2974 |
s0++; |
| 2975 |
} |
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
if (ISDIGIT (input_line_pointer[0]) |
| 2981 |
&& input_line_pointer[1] == 'H' |
| 2982 |
&& ISSPACE (input_line_pointer[2])) |
| 2983 |
{ |
| 2984 |
char *s; |
| 2985 |
current_fb_label = input_line_pointer[0] - '0'; |
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
input_line_pointer[1] = input_line_pointer[-1]; |
| 2991 |
input_line_pointer += 2; |
| 2992 |
|
| 2993 |
s = input_line_pointer; |
| 2994 |
while (*s && ISSPACE (*s) && ! is_end_of_line[(unsigned int) *s]) |
| 2995 |
s++; |
| 2996 |
|
| 2997 |
|
| 2998 |
|
| 2999 |
if (is_end_of_line[(unsigned int) *s]) |
| 3000 |
{ |
| 3001 |
char *name; |
| 3002 |
unsigned int line; |
| 3003 |
as_where (&name, &line); |
| 3004 |
as_bad_where (name, line + 1, |
| 3005 |
_("[0-9]H labels may not appear alone on a line")); |
| 3006 |
current_fb_label = -1; |
| 3007 |
} |
| 3008 |
if (*s == '.') |
| 3009 |
{ |
| 3010 |
char *name; |
| 3011 |
unsigned int line; |
| 3012 |
as_where (&name, &line); |
| 3013 |
as_bad_where (name, line + 1, |
| 3014 |
_("[0-9]H labels do not mix with dot-pseudos")); |
| 3015 |
current_fb_label = -1; |
| 3016 |
} |
| 3017 |
} |
| 3018 |
else |
| 3019 |
{ |
| 3020 |
current_fb_label = -1; |
| 3021 |
if (is_name_beginner (input_line_pointer[0])) |
| 3022 |
label = input_line_pointer; |
| 3023 |
} |
| 3024 |
|
| 3025 |
s0 = input_line_pointer; |
| 3026 |
|
| 3027 |
while (*s0 && is_part_of_name (*s0)) |
| 3028 |
s0++; |
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
if (s0 != input_line_pointer && s0[-1] == ':' |
| 3033 |
&& (s0 - 2 != input_line_pointer |
| 3034 |
|| ! ISDIGIT (s0[-2]))) |
| 3035 |
s0[-1] = ' '; |
| 3036 |
else if (label != NULL) |
| 3037 |
{ |
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
int len_0 = s0 - label + 1; |
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
obstack_grow (&mmix_sym_obstack, label, len_0); |
| 3048 |
pending_label = obstack_finish (&mmix_sym_obstack); |
| 3049 |
pending_label[len_0 - 1] = 0; |
| 3050 |
} |
| 3051 |
|
| 3052 |
while (*s0 && ISSPACE (*s0) && ! is_end_of_line[(unsigned int) *s0]) |
| 3053 |
s0++; |
| 3054 |
|
| 3055 |
if (pending_label != NULL && is_end_of_line[(unsigned int) *s0]) |
| 3056 |
|
| 3057 |
|
| 3058 |
|
| 3059 |
pending_label = NULL; |
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
s = s0; |
| 3072 |
while (*s) |
| 3073 |
{ |
| 3074 |
c = *s++; |
| 3075 |
if (is_end_of_line[(unsigned int) c]) |
| 3076 |
break; |
| 3077 |
if (c == MAGIC_FB_BACKWARD_CHAR || c == MAGIC_FB_FORWARD_CHAR) |
| 3078 |
as_bad (_("invalid characters in input")); |
| 3079 |
} |
| 3080 |
|
| 3081 |
|
| 3082 |
s = s0; |
| 3083 |
|
| 3084 |
|
| 3085 |
while (*s |
| 3086 |
&& ! ISSPACE (*s) |
| 3087 |
&& *s != ';' |
| 3088 |
&& ! is_end_of_line[(unsigned int) *s]) |
| 3089 |
s++; |
| 3090 |
|
| 3091 |
|
| 3092 |
while (*s |
| 3093 |
&& ISSPACE (*s) |
| 3094 |
&& *s != ';' |
| 3095 |
&& ! is_end_of_line[(unsigned int) *s]) |
| 3096 |
s++; |
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
while ((c = *s) != 0 |
| 3101 |
&& ! ISSPACE (c) |
| 3102 |
&& c != ';' |
| 3103 |
&& ! is_end_of_line[(unsigned int) c]) |
| 3104 |
{ |
| 3105 |
if (c == '"') |
| 3106 |
{ |
| 3107 |
s++; |
| 3108 |
|
| 3109 |
|
| 3110 |
while (*s |
| 3111 |
&& *s != '"' |
| 3112 |
&& (! is_end_of_line[(unsigned int) *s] || *s == ';')) |
| 3113 |
s++; |
| 3114 |
|
| 3115 |
if (*s == '"') |
| 3116 |
s++; |
| 3117 |
} |
| 3118 |
else if (ISDIGIT (c)) |
| 3119 |
{ |
| 3120 |
if ((s[1] != 'B' && s[1] != 'F') |
| 3121 |
|| is_part_of_name (s[-1]) |
| 3122 |
|| is_part_of_name (s[2])) |
| 3123 |
s++; |
| 3124 |
else |
| 3125 |
{ |
| 3126 |
s[0] = (s[1] == 'B' |
| 3127 |
? MAGIC_FB_BACKWARD_CHAR : MAGIC_FB_FORWARD_CHAR); |
| 3128 |
s[1] = c; |
| 3129 |
} |
| 3130 |
} |
| 3131 |
else |
| 3132 |
s++; |
| 3133 |
} |
| 3134 |
|
| 3135 |
|
| 3136 |
while (*s |
| 3137 |
&& ISSPACE (*s) |
| 3138 |
&& *s != ';' |
| 3139 |
&& !is_end_of_line[(unsigned int) *s]) |
| 3140 |
s++; |
| 3141 |
|
| 3142 |
|
| 3143 |
|
| 3144 |
mmix_next_semicolon_is_eoln = (*s == ';'); |
| 3145 |
|
| 3146 |
|
| 3147 |
|
| 3148 |
s = s0; |
| 3149 |
if (s[0] == 'I' && s[1] == 'S' && ISSPACE (s[2])) |
| 3150 |
{ |
| 3151 |
*s = '='; |
| 3152 |
s[1] = ' '; |
| 3153 |
|
| 3154 |
|
| 3155 |
|
| 3156 |
input_line_pointer = s; |
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
bump_line_counters (); |
| 3163 |
|
| 3164 |
|
| 3165 |
if (current_fb_label >= 0) |
| 3166 |
{ |
| 3167 |
char *fb_name; |
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
fb_name = fb_label_name (current_fb_label, 1); |
| 3174 |
obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1); |
| 3175 |
equals (obstack_finish (&mmix_sym_obstack), 0); |
| 3176 |
fb_label_instance_inc (current_fb_label); |
| 3177 |
current_fb_label = -1; |
| 3178 |
} |
| 3179 |
else |
| 3180 |
{ |
| 3181 |
if (pending_label == NULL) |
| 3182 |
as_bad (_("empty label field for IS")); |
| 3183 |
else |
| 3184 |
equals (pending_label, 0); |
| 3185 |
pending_label = NULL; |
| 3186 |
} |
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
mmix_handle_rest_of_empty_line (); |
| 3191 |
input_line_pointer--; |
| 3192 |
|
| 3193 |
input_line_pointer[-1] = ' '; |
| 3194 |
} |
| 3195 |
else if (s[0] == 'G' |
| 3196 |
&& s[1] == 'R' |
| 3197 |
&& strncmp (s, "GREG", 4) == 0 |
| 3198 |
&& (ISSPACE (s[4]) || is_end_of_line[(unsigned char) s[4]])) |
| 3199 |
{ |
| 3200 |
input_line_pointer = s + 4; |
| 3201 |
|
| 3202 |
|
| 3203 |
|
| 3204 |
|
| 3205 |
|
| 3206 |
bump_line_counters (); |
| 3207 |
|
| 3208 |
|
| 3209 |
if (current_fb_label >= 0) |
| 3210 |
{ |
| 3211 |
char *fb_name; |
| 3212 |
|
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
fb_name = fb_label_name (current_fb_label, 1); |
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
obstack_1grow (&mmix_sym_obstack, ':'); |
| 3222 |
obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1); |
| 3223 |
mmix_greg_internal (obstack_finish (&mmix_sym_obstack)); |
| 3224 |
fb_label_instance_inc (current_fb_label); |
| 3225 |
current_fb_label = -1; |
| 3226 |
} |
| 3227 |
else |
| 3228 |
mmix_greg_internal (pending_label); |
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
input_line_pointer--; |
| 3233 |
input_line_pointer[-1] = ' '; |
| 3234 |
|
| 3235 |
pending_label = NULL; |
| 3236 |
} |
| 3237 |
else if (pending_label != NULL) |
| 3238 |
{ |
| 3239 |
input_line_pointer += strlen (pending_label); |
| 3240 |
|
| 3241 |
|
| 3242 |
input_line_pointer[-1] = '\n'; |
| 3243 |
} |
| 3244 |
} |
| 3245 |
|
| 3246 |
|
| 3247 |
|
| 3248 |
|
| 3249 |
|
| 3250 |
|
| 3251 |
|
| 3252 |
|
| 3253 |
void |
| 3254 |
mmix_fb_label (expP) |
| 3255 |
expressionS *expP; |
| 3256 |
{ |
| 3257 |
symbolS *sym; |
| 3258 |
char *fb_internal_name; |
| 3259 |
|
| 3260 |
|
| 3261 |
if (mmix_gnu_syntax |
| 3262 |
|| (input_line_pointer[0] != MAGIC_FB_BACKWARD_CHAR |
| 3263 |
&& input_line_pointer[0] != MAGIC_FB_FORWARD_CHAR)) |
| 3264 |
return; |
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
|
| 3271 |
|
| 3272 |
fb_internal_name |
| 3273 |
= fb_label_name (input_line_pointer[1] - '0', |
| 3274 |
(input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR ? 1 : 0) |
| 3275 |
+ ((input_line_pointer[1] - '0' == current_fb_label |
| 3276 |
&& input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR) |
| 3277 |
? 1 : 0)); |
| 3278 |
|
| 3279 |
input_line_pointer += 2; |
| 3280 |
sym = symbol_find_or_make (fb_internal_name); |
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
if (S_GET_SEGMENT (sym) == absolute_section) |
| 3287 |
{ |
| 3288 |
expP->X_op = O_constant; |
| 3289 |
expP->X_add_number = S_GET_VALUE (sym); |
| 3290 |
} |
| 3291 |
else |
| 3292 |
{ |
| 3293 |
expP->X_op = O_symbol; |
| 3294 |
expP->X_add_symbol = sym; |
| 3295 |
expP->X_add_number = 0; |
| 3296 |
} |
| 3297 |
} |
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
int |
| 3304 |
mmix_force_relocation (fixP) |
| 3305 |
fixS *fixP; |
| 3306 |
{ |
| 3307 |
if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL |
| 3308 |
|| fixP->fx_r_type == BFD_RELOC_MMIX_BASE_PLUS_OFFSET) |
| 3309 |
return 1; |
| 3310 |
|
| 3311 |
if (linkrelax) |
| 3312 |
return 1; |
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
if (fixP->fx_pcrel) |
| 3319 |
return 1; |
| 3320 |
|
| 3321 |
return generic_force_reloc (fixP); |
| 3322 |
} |
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
long |
| 3328 |
md_pcrel_from_section (fixP, sec) |
| 3329 |
fixS * fixP; |
| 3330 |
segT sec; |
| 3331 |
{ |
| 3332 |
if (fixP->fx_addsy != (symbolS *) NULL |
| 3333 |
&& (! S_IS_DEFINED (fixP->fx_addsy) |
| 3334 |
|| S_GET_SEGMENT (fixP->fx_addsy) != sec)) |
| 3335 |
{ |
| 3336 |
|
| 3337 |
|
| 3338 |
return 0; |
| 3339 |
} |
| 3340 |
|
| 3341 |
return (fixP->fx_frag->fr_address + fixP->fx_where); |
| 3342 |
} |
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
void |
| 3348 |
mmix_adjust_symtab () |
| 3349 |
{ |
| 3350 |
symbolS *sym; |
| 3351 |
symbolS *regsec = section_symbol (reg_section); |
| 3352 |
|
| 3353 |
for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
| 3354 |
if (S_GET_SEGMENT (sym) == reg_section) |
| 3355 |
{ |
| 3356 |
if (sym == regsec) |
| 3357 |
{ |
| 3358 |
if (S_IS_EXTERN (sym) || symbol_used_in_reloc_p (sym)) |
| 3359 |
abort (); |
| 3360 |
symbol_remove (sym, &symbol_rootP, &symbol_lastP); |
| 3361 |
} |
| 3362 |
else |
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
S_SET_SEGMENT (sym, real_reg_section); |
| 3368 |
} |
| 3369 |
} |
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
int |
| 3378 |
mmix_label_without_colon_this_line () |
| 3379 |
{ |
| 3380 |
int retval = label_without_colon_this_line; |
| 3381 |
|
| 3382 |
if (! mmix_gnu_syntax) |
| 3383 |
label_without_colon_this_line = 1; |
| 3384 |
|
| 3385 |
return retval; |
| 3386 |
} |
| 3387 |
|
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
long |
| 3394 |
mmix_md_relax_frag (seg, fragP, stretch) |
| 3395 |
segT seg; |
| 3396 |
fragS *fragP; |
| 3397 |
long stretch; |
| 3398 |
{ |
| 3399 |
switch (fragP->fr_subtype) |
| 3400 |
{ |
| 3401 |
|
| 3402 |
|
| 3403 |
case STATE_GREG_DEF: |
| 3404 |
return 0; |
| 3405 |
|
| 3406 |
case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO): |
| 3407 |
{ |
| 3408 |
|
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
offsetT aim; |
| 3414 |
addressT target; |
| 3415 |
addressT address; |
| 3416 |
symbolS *symbolP; |
| 3417 |
target = fragP->fr_offset; |
| 3418 |
address = fragP->fr_address; |
| 3419 |
symbolP = fragP->fr_symbol; |
| 3420 |
|
| 3421 |
if (symbolP) |
| 3422 |
{ |
| 3423 |
fragS *sym_frag; |
| 3424 |
|
| 3425 |
sym_frag = symbol_get_frag (symbolP); |
| 3426 |
know (S_GET_SEGMENT (symbolP) != absolute_section |
| 3427 |
|| sym_frag == &zero_address_frag); |
| 3428 |
target += S_GET_VALUE (symbolP); |
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
if (stretch != 0 |
| 3436 |
&& sym_frag->relax_marker != fragP->relax_marker |
| 3437 |
&& S_GET_SEGMENT (symbolP) == seg) |
| 3438 |
target += stretch; |
| 3439 |
} |
| 3440 |
|
| 3441 |
aim = target - address - fragP->fr_fix; |
| 3442 |
if (aim >= PUSHJ_0B && aim <= PUSHJ_0F) |
| 3443 |
{ |
| 3444 |
|
| 3445 |
segment_info_type *seginfo = seg_info (seg); |
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
if (fragP == seginfo->tc_segment_info_data.last_stubfrag) |
| 3450 |
seginfo->tc_segment_info_data.nstubs = 0; |
| 3451 |
return 0; |
| 3452 |
} |
| 3453 |
|
| 3454 |
|
| 3455 |
fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO); |
| 3456 |
} |
| 3457 |
|
| 3458 |
|
| 3459 |
|
| 3460 |
case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO): |
| 3461 |
{ |
| 3462 |
segment_info_type *seginfo = seg_info (seg); |
| 3463 |
fragS *lastfrag = seginfo->frchainP->frch_last; |
| 3464 |
relax_substateT prev_type = fragP->fr_subtype; |
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
know (lastfrag->fr_type == rs_fill |
| 3469 |
&& lastfrag->fr_fix == 0 |
| 3470 |
&& lastfrag->fr_var == 0); |
| 3471 |
|
| 3472 |
|
| 3473 |
|
| 3474 |
|
| 3475 |
if ((lastfrag->fr_address |
| 3476 |
+ stretch |
| 3477 |
+ PUSHJ_MAX_LEN * seginfo->tc_segment_info_data.nstubs) |
| 3478 |
- (fragP->fr_address + fragP->fr_fix) |
| 3479 |
> GETA_0F |
| 3480 |
|| !pushj_stubs) |
| 3481 |
fragP->fr_subtype = mmix_relax_table[prev_type].rlx_more; |
| 3482 |
else |
| 3483 |
seginfo->tc_segment_info_data.nstubs++; |
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
if (fragP == seginfo->tc_segment_info_data.last_stubfrag) |
| 3488 |
seginfo->tc_segment_info_data.nstubs = 0; |
| 3489 |
|
| 3490 |
return |
| 3491 |
(mmix_relax_table[fragP->fr_subtype].rlx_length |
| 3492 |
- mmix_relax_table[prev_type].rlx_length); |
| 3493 |
} |
| 3494 |
|
| 3495 |
case ENCODE_RELAX (STATE_PUSHJ, STATE_MAX): |
| 3496 |
{ |
| 3497 |
segment_info_type *seginfo = seg_info (seg); |
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
if (fragP == seginfo->tc_segment_info_data.last_stubfrag) |
| 3503 |
seginfo->tc_segment_info_data.nstubs = 0; |
| 3504 |
|
| 3505 |
return 0; |
| 3506 |
} |
| 3507 |
|
| 3508 |
default: |
| 3509 |
return relax_frag (seg, fragP, stretch); |
| 3510 |
|
| 3511 |
case STATE_GREG_UNDF: |
| 3512 |
BAD_CASE (fragP->fr_subtype); |
| 3513 |
} |
| 3514 |
|
| 3515 |
as_fatal (_("internal: unexpected relax type %d:%d"), |
| 3516 |
fragP->fr_type, fragP->fr_subtype); |
| 3517 |
return 0; |
| 3518 |
} |
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
void |
| 3523 |
mmix_md_end () |
| 3524 |
{ |
| 3525 |
fragS *fragP; |
| 3526 |
symbolS *mainsym; |
| 3527 |
int i; |
| 3528 |
|
| 3529 |
|
| 3530 |
fragS *mmix_reg_contents_frags = NULL; |
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
mmix_current_prefix = NULL; |
| 3535 |
|
| 3536 |
if (doing_bspec) |
| 3537 |
as_bad_where (bspec_file, bspec_line, _("BSPEC without ESPEC.")); |
| 3538 |
|
| 3539 |
|
| 3540 |
if (text_has_contents && lowest_text_loc != (bfd_vma) -1) |
| 3541 |
{ |
| 3542 |
symbolS *symbolP; |
| 3543 |
char locsymbol[sizeof (":") - 1 |
| 3544 |
+ sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1 |
| 3545 |
+ sizeof (".text")]; |
| 3546 |
|
| 3547 |
|
| 3548 |
sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX, |
| 3549 |
".text"); |
| 3550 |
symbolP |
| 3551 |
= symbol_new (locsymbol, absolute_section, lowest_text_loc, |
| 3552 |
&zero_address_frag); |
| 3553 |
S_SET_EXTERNAL (symbolP); |
| 3554 |
} |
| 3555 |
|
| 3556 |
|
| 3557 |
if (data_has_contents && lowest_data_loc != (bfd_vma) -1) |
| 3558 |
{ |
| 3559 |
symbolS *symbolP; |
| 3560 |
char locsymbol[sizeof (":") - 1 |
| 3561 |
+ sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1 |
| 3562 |
+ sizeof (".data")]; |
| 3563 |
|
| 3564 |
sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX, |
| 3565 |
".data"); |
| 3566 |
symbolP |
| 3567 |
= symbol_new (locsymbol, absolute_section, lowest_data_loc, |
| 3568 |
&zero_address_frag); |
| 3569 |
S_SET_EXTERNAL (symbolP); |
| 3570 |
} |
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
mainsym = symbol_find (MMIX_START_SYMBOL_NAME); |
| 3578 |
if (mainsym != NULL && ! mmix_gnu_syntax) |
| 3579 |
{ |
| 3580 |
symbol_get_bfdsym (mainsym)->flags |= BSF_FUNCTION; |
| 3581 |
S_SET_EXTERNAL (mainsym); |
| 3582 |
} |
| 3583 |
|
| 3584 |
if (n_of_raw_gregs != 0) |
| 3585 |
{ |
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
segT this_segment = now_seg; |
| 3590 |
subsegT this_subsegment = now_subseg; |
| 3591 |
asection *regsec |
| 3592 |
= bfd_make_section_old_way (stdoutput, |
| 3593 |
MMIX_REG_CONTENTS_SECTION_NAME); |
| 3594 |
subseg_set (regsec, 0); |
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
mmix_opcode_frag = NULL; |
| 3601 |
|
| 3602 |
frag_grow (0); |
| 3603 |
mmix_reg_contents_frags = frag_now; |
| 3604 |
|
| 3605 |
for (i = n_of_raw_gregs - 1; i >= 0; i--) |
| 3606 |
{ |
| 3607 |
if (mmix_raw_gregs[i].label != NULL) |
| 3608 |
|
| 3609 |
|
| 3610 |
|
| 3611 |
colon (mmix_raw_gregs[i].label); |
| 3612 |
|
| 3613 |
frag_var (rs_machine_dependent, 8, 0, STATE_GREG_UNDF, |
| 3614 |
make_expr_symbol (&mmix_raw_gregs[i].exp), 0, NULL); |
| 3615 |
} |
| 3616 |
|
| 3617 |
subseg_set (this_segment, this_subsegment); |
| 3618 |
} |
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
for (fragP = mmix_reg_contents_frags; fragP != NULL; fragP = fragP->fr_next) |
| 3626 |
{ |
| 3627 |
fragS **fpp; |
| 3628 |
fragS *fp = NULL; |
| 3629 |
fragS *osymfrag; |
| 3630 |
offsetT osymval; |
| 3631 |
expressionS *oexpP; |
| 3632 |
symbolS *symbolP = fragP->fr_symbol; |
| 3633 |
|
| 3634 |
if (fragP->fr_type != rs_machine_dependent |
| 3635 |
|| fragP->fr_subtype != STATE_GREG_UNDF) |
| 3636 |
continue; |
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
fragP->fr_subtype = STATE_GREG_DEF; |
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
if (! merge_gregs) |
| 3646 |
continue; |
| 3647 |
|
| 3648 |
osymval = (offsetT) S_GET_VALUE (symbolP); |
| 3649 |
osymfrag = symbol_get_frag (symbolP); |
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
if (! S_IS_DEFINED (symbolP)) |
| 3655 |
continue; |
| 3656 |
|
| 3657 |
oexpP = symbol_get_value_expression (fragP->fr_symbol); |
| 3658 |
|
| 3659 |
|
| 3660 |
if (oexpP->X_op == O_constant && osymval == 0) |
| 3661 |
continue; |
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
for (fpp = &fragP->fr_next; *fpp != NULL; fpp = &fpp[0]->fr_next) |
| 3667 |
{ |
| 3668 |
fp = *fpp; |
| 3669 |
|
| 3670 |
if (fp->fr_type != rs_machine_dependent |
| 3671 |
|| fp->fr_subtype != STATE_GREG_UNDF) |
| 3672 |
continue; |
| 3673 |
|
| 3674 |
|
| 3675 |
|
| 3676 |
if ((offsetT) S_GET_VALUE (fp->fr_symbol) == osymval |
| 3677 |
&& symbol_get_frag (fp->fr_symbol) == osymfrag) |
| 3678 |
{ |
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
|
| 3683 |
*fpp = fp->fr_next; |
| 3684 |
fp->fr_next = fragP->fr_next; |
| 3685 |
fragP->fr_next = fp; |
| 3686 |
break; |
| 3687 |
} |
| 3688 |
} |
| 3689 |
|
| 3690 |
if (*fpp != NULL) |
| 3691 |
fragP->tc_frag_data = fp; |
| 3692 |
} |
| 3693 |
} |
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
static int |
| 3698 |
cmp_greg_symbol_fixes (parg, qarg) |
| 3699 |
const PTR parg; |
| 3700 |
const PTR qarg; |
| 3701 |
{ |
| 3702 |
const struct mmix_symbol_greg_fixes *p |
| 3703 |
= (const struct mmix_symbol_greg_fixes *) parg; |
| 3704 |
const struct mmix_symbol_greg_fixes *q |
| 3705 |
= (const struct mmix_symbol_greg_fixes *) qarg; |
| 3706 |
|
| 3707 |
return p->offs > q->offs ? 1 : p->offs < q->offs ? -1 : 0; |
| 3708 |
} |
| 3709 |
|
| 3710 |
|
| 3711 |
|
| 3712 |
|
| 3713 |
|
| 3714 |
|
| 3715 |
|
| 3716 |
void |
| 3717 |
mmix_frob_file () |
| 3718 |
{ |
| 3719 |
int i; |
| 3720 |
struct mmix_symbol_gregs *all_greg_symbols[MAX_GREGS]; |
| 3721 |
int n_greg_symbols = 0; |
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
for (i = 0; i < n_of_cooked_gregs; i++) |
| 3726 |
{ |
| 3727 |
offsetT offs; |
| 3728 |
symbolS *sym; |
| 3729 |
struct mmix_symbol_gregs *gregs; |
| 3730 |
fixS *fixP; |
| 3731 |
|
| 3732 |
fixP = mmix_gregs[i]; |
| 3733 |
know (fixP->fx_r_type == BFD_RELOC_64); |
| 3734 |
|
| 3735 |
|
| 3736 |
if (fixP->fx_subsy != NULL) |
| 3737 |
{ |
| 3738 |
as_bad_where (fixP->fx_file, fixP->fx_line, |
| 3739 |
_("GREG expression too complicated")); |
| 3740 |
continue; |
| 3741 |
} |
| 3742 |
|
| 3743 |
sym = fixP->fx_addsy; |
| 3744 |
offs = (offsetT) fixP->fx_offset; |
| 3745 |
|
| 3746 |
|
| 3747 |
|
| 3748 |
if (S_IS_DEFINED (sym) |
| 3749 |
&& !bfd_is_com_section (S_GET_SEGMENT (sym)) |
| 3750 |
&& !S_IS_WEAK (sym)) |
| 3751 |
{ |
| 3752 |
if (! symbol_section_p (sym) |
| 3753 |
&& ! bfd_is_abs_section (S_GET_SEGMENT (sym))) |
| 3754 |
as_fatal (_("internal: GREG expression not resolved to section")); |
| 3755 |
|
| 3756 |
offs += S_GET_VALUE (sym); |
| 3757 |
} |
| 3758 |
|
| 3759 |
|
| 3760 |
|
| 3761 |
|
| 3762 |
|
| 3763 |
if (lowest_data_loc != (bfd_vma) -1 |
| 3764 |
&& (bfd_vma) offs + 256 > lowest_data_loc |
| 3765 |
&& bfd_is_abs_section (S_GET_SEGMENT (sym))) |
| 3766 |
{ |
| 3767 |
offs -= (offsetT) lowest_data_loc; |
| 3768 |
sym = section_symbol (data_section); |
| 3769 |
} |
| 3770 |
|
| 3771 |
else if (lowest_text_loc != (bfd_vma) -1 |
| 3772 |
&& (bfd_vma) offs + 256 > lowest_text_loc |
| 3773 |
&& bfd_is_abs_section (S_GET_SEGMENT (sym))) |
| 3774 |
{ |
| 3775 |
offs -= (offsetT) lowest_text_loc; |
| 3776 |
sym = section_symbol (text_section); |
| 3777 |
} |
| 3778 |
|
| 3779 |
gregs = *symbol_get_tc (sym); |
| 3780 |
|
| 3781 |
if (gregs == NULL) |
| 3782 |
{ |
| 3783 |
gregs = xmalloc (sizeof (*gregs)); |
| 3784 |
gregs->n_gregs = 0; |
| 3785 |
symbol_set_tc (sym, &gregs); |
| 3786 |
all_greg_symbols[n_greg_symbols++] = gregs; |
| 3787 |
} |
| 3788 |
|
| 3789 |
gregs->greg_fixes[gregs->n_gregs].fix = fixP; |
| 3790 |
gregs->greg_fixes[gregs->n_gregs++].offs = offs; |
| 3791 |
} |
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
for (i = 0; i < n_greg_symbols; i++) |
| 3796 |
qsort (all_greg_symbols[i]->greg_fixes, all_greg_symbols[i]->n_gregs, |
| 3797 |
sizeof (all_greg_symbols[i]->greg_fixes[0]), cmp_greg_symbol_fixes); |
| 3798 |
|
| 3799 |
if (real_reg_section != NULL) |
| 3800 |
{ |
| 3801 |
asection **secpp; |
| 3802 |
|
| 3803 |
|
| 3804 |
if (bfd_get_section_flags (stdoutput, real_reg_section) & SEC_HAS_CONTENTS) |
| 3805 |
as_fatal (_("register section has contents\n")); |
| 3806 |
|
| 3807 |
|
| 3808 |
for (secpp = &stdoutput->sections; |
| 3809 |
*secpp != real_reg_section; |
| 3810 |
secpp = &(*secpp)->next) |
| 3811 |
; |
| 3812 |
bfd_section_list_remove (stdoutput, secpp); |
| 3813 |
--stdoutput->section_count; |
| 3814 |
} |
| 3815 |
|
| 3816 |
} |
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
int |
| 3825 |
mmix_parse_predefined_name (name, expP) |
| 3826 |
char *name; |
| 3827 |
expressionS *expP; |
| 3828 |
{ |
| 3829 |
char *canon_name; |
| 3830 |
char *handler_charp; |
| 3831 |
const char handler_chars[] = "DVWIOUZX"; |
| 3832 |
symbolS *symp; |
| 3833 |
|
| 3834 |
if (! predefined_syms) |
| 3835 |
return 0; |
| 3836 |
|
| 3837 |
canon_name = tc_canonicalize_symbol_name (name); |
| 3838 |
|
| 3839 |
if (canon_name[1] == '_' |
| 3840 |
&& strcmp (canon_name + 2, "Handler") == 0 |
| 3841 |
&& (handler_charp = strchr (handler_chars, *canon_name)) != NULL) |
| 3842 |
{ |
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
symp = symbol_find (name); |
| 3849 |
if (symp == NULL) |
| 3850 |
symp = symbol_new (name, text_section, |
| 3851 |
0x10 * (handler_charp + 1 - handler_chars), |
| 3852 |
&zero_address_frag); |
| 3853 |
} |
| 3854 |
else |
| 3855 |
{ |
| 3856 |
|
| 3857 |
|
| 3858 |
unsigned int i; |
| 3859 |
|
| 3860 |
static const struct |
| 3861 |
{ |
| 3862 |
const char *name; |
| 3863 |
valueT val; |
| 3864 |
} predefined_abs_syms[] = |
| 3865 |
{ |
| 3866 |
{"Data_Segment", (valueT) 0x20 << 56}, |
| 3867 |
{"Pool_Segment", (valueT) 0x40 << 56}, |
| 3868 |
{"Stack_Segment", (valueT) 0x60 << 56}, |
| 3869 |
{"StdIn", 0}, |
| 3870 |
{"StdOut", 1}, |
| 3871 |
{"StdErr", 2}, |
| 3872 |
{"TextRead", 0}, |
| 3873 |
{"TextWrite", 1}, |
| 3874 |
{"BinaryRead", 2}, |
| 3875 |
{"BinaryWrite", 3}, |
| 3876 |
{"BinaryReadWrite", 4}, |
| 3877 |
{"Halt", 0}, |
| 3878 |
{"Fopen", 1}, |
| 3879 |
{"Fclose", 2}, |
| 3880 |
{"Fread", 3}, |
| 3881 |
{"Fgets", 4}, |
| 3882 |
{"Fgetws", 5}, |
| 3883 |
{"Fwrite", 6}, |
| 3884 |
{"Fputs", 7}, |
| 3885 |
{"Fputws", 8}, |
| 3886 |
{"Fseek", 9}, |
| 3887 |
{"Ftell", 10}, |
| 3888 |
{"D_BIT", 0x80}, |
| 3889 |
{"V_BIT", 0x40}, |
| 3890 |
{"W_BIT", 0x20}, |
| 3891 |
{"I_BIT", 0x10}, |
| 3892 |
{"O_BIT", 0x08}, |
| 3893 |
{"U_BIT", 0x04}, |
| 3894 |
{"Z_BIT", 0x02}, |
| 3895 |
{"X_BIT", 0x01}, |
| 3896 |
{"Inf", 0x7ff00000} |
| 3897 |
}; |
| 3898 |
|
| 3899 |
|
| 3900 |
symp = symbol_find (name); |
| 3901 |
if (symp != NULL) |
| 3902 |
return 0; |
| 3903 |
|
| 3904 |
for (i = 0; |
| 3905 |
i < sizeof (predefined_abs_syms) / sizeof (predefined_abs_syms[0]); |
| 3906 |
i++) |
| 3907 |
if (strcmp (canon_name, predefined_abs_syms[i].name) == 0) |
| 3908 |
{ |
| 3909 |
symbol_table_insert (symbol_new (predefined_abs_syms[i].name, |
| 3910 |
absolute_section, |
| 3911 |
predefined_abs_syms[i].val, |
| 3912 |
&zero_address_frag)); |
| 3913 |
|
| 3914 |
|
| 3915 |
|
| 3916 |
return 0; |
| 3917 |
} |
| 3918 |
|
| 3919 |
|
| 3920 |
return 0; |
| 3921 |
} |
| 3922 |
|
| 3923 |
expP->X_op = O_symbol; |
| 3924 |
expP->X_add_number = 0; |
| 3925 |
expP->X_add_symbol = symp; |
| 3926 |
expP->X_op_symbol = NULL; |
| 3927 |
|
| 3928 |
return 1; |
| 3929 |
} |
| 3930 |
|
| 3931 |
|
| 3932 |
|
| 3933 |
|
| 3934 |
|
| 3935 |
void |
| 3936 |
mmix_md_elf_section_change_hook () |
| 3937 |
{ |
| 3938 |
if (doing_bspec) |
| 3939 |
as_bad (_("section change from within a BSPEC/ESPEC pair is not supported")); |
| 3940 |
|
| 3941 |
last_alignment = bfd_get_section_alignment (now_seg->owner, now_seg); |
| 3942 |
want_unaligned = 0; |
| 3943 |
} |
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
static void |
| 3949 |
s_loc (ignore) |
| 3950 |
int ignore ATTRIBUTE_UNUSED; |
| 3951 |
{ |
| 3952 |
segT section; |
| 3953 |
expressionS exp; |
| 3954 |
char *p; |
| 3955 |
symbolS *sym; |
| 3956 |
offsetT off; |
| 3957 |
|
| 3958 |
|
| 3959 |
if (doing_bspec) |
| 3960 |
{ |
| 3961 |
as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported")); |
| 3962 |
return; |
| 3963 |
} |
| 3964 |
|
| 3965 |
section = expression (&exp); |
| 3966 |
|
| 3967 |
if (exp.X_op == O_illegal |
| 3968 |
|| exp.X_op == O_absent |
| 3969 |
|| exp.X_op == O_big |
| 3970 |
|| section == undefined_section) |
| 3971 |
{ |
| 3972 |
as_bad (_("invalid LOC expression")); |
| 3973 |
return; |
| 3974 |
} |
| 3975 |
|
| 3976 |
if (section == absolute_section) |
| 3977 |
{ |
| 3978 |
|
| 3979 |
|
| 3980 |
if (exp.X_add_number < ((offsetT) 0x20 << 56)) |
| 3981 |
{ |
| 3982 |
|
| 3983 |
section = text_section; |
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
if (exp.X_add_number < 0 |
| 3995 |
|| exp.X_add_number < (offsetT) lowest_text_loc) |
| 3996 |
{ |
| 3997 |
as_bad (_("LOC expression stepping backwards is not supported")); |
| 3998 |
exp.X_op = O_absent; |
| 3999 |
} |
| 4000 |
else |
| 4001 |
{ |
| 4002 |
if (text_has_contents && lowest_text_loc == (bfd_vma) -1) |
| 4003 |
lowest_text_loc = 0; |
| 4004 |
|
| 4005 |
if (lowest_text_loc == (bfd_vma) -1) |
| 4006 |
{ |
| 4007 |
lowest_text_loc = exp.X_add_number; |
| 4008 |
|
| 4009 |
|
| 4010 |
exp.X_op = O_absent; |
| 4011 |
} |
| 4012 |
else |
| 4013 |
exp.X_add_number -= lowest_text_loc; |
| 4014 |
} |
| 4015 |
} |
| 4016 |
else |
| 4017 |
{ |
| 4018 |
|
| 4019 |
section = data_section; |
| 4020 |
|
| 4021 |
if (exp.X_add_number < (offsetT) lowest_data_loc) |
| 4022 |
{ |
| 4023 |
as_bad (_("LOC expression stepping backwards is not supported")); |
| 4024 |
exp.X_op = O_absent; |
| 4025 |
} |
| 4026 |
else |
| 4027 |
{ |
| 4028 |
if (data_has_contents && lowest_data_loc == (bfd_vma) -1) |
| 4029 |
lowest_data_loc = (bfd_vma) 0x20 << 56; |
| 4030 |
|
| 4031 |
if (lowest_data_loc == (bfd_vma) -1) |
| 4032 |
{ |
| 4033 |
lowest_data_loc = exp.X_add_number; |
| 4034 |
|
| 4035 |
|
| 4036 |
exp.X_op = O_absent; |
| 4037 |
} |
| 4038 |
else |
| 4039 |
exp.X_add_number -= lowest_data_loc; |
| 4040 |
} |
| 4041 |
} |
| 4042 |
} |
| 4043 |
|
| 4044 |
if (section != now_seg) |
| 4045 |
{ |
| 4046 |
obj_elf_section_change_hook (); |
| 4047 |
subseg_set (section, 0); |
| 4048 |
|
| 4049 |
|
| 4050 |
md_elf_section_change_hook (); |
| 4051 |
} |
| 4052 |
|
| 4053 |
if (exp.X_op != O_absent) |
| 4054 |
{ |
| 4055 |
if (exp.X_op != O_constant && exp.X_op != O_symbol) |
| 4056 |
{ |
| 4057 |
|
| 4058 |
sym = make_expr_symbol (&exp); |
| 4059 |
off = 0; |
| 4060 |
} |
| 4061 |
else |
| 4062 |
{ |
| 4063 |
sym = exp.X_add_symbol; |
| 4064 |
off = exp.X_add_number; |
| 4065 |
} |
| 4066 |
|
| 4067 |
p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0); |
| 4068 |
*p = 0; |
| 4069 |
} |
| 4070 |
|
| 4071 |
mmix_handle_rest_of_empty_line (); |
| 4072 |
} |
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
static void |
| 4079 |
mmix_byte () |
| 4080 |
{ |
| 4081 |
unsigned int c; |
| 4082 |
char *start; |
| 4083 |
|
| 4084 |
if (now_seg == text_section) |
| 4085 |
text_has_contents = 1; |
| 4086 |
else if (now_seg == data_section) |
| 4087 |
data_has_contents = 1; |
| 4088 |
|
| 4089 |
do |
| 4090 |
{ |
| 4091 |
SKIP_WHITESPACE (); |
| 4092 |
switch (*input_line_pointer) |
| 4093 |
{ |
| 4094 |
case '\"': |
| 4095 |
++input_line_pointer; |
| 4096 |
start = input_line_pointer; |
| 4097 |
while (is_a_char (c = next_char_of_string ())) |
| 4098 |
{ |
| 4099 |
FRAG_APPEND_1_CHAR (c); |
| 4100 |
} |
| 4101 |
|
| 4102 |
if (input_line_pointer[-1] != '\"') |
| 4103 |
{ |
| 4104 |
|
| 4105 |
|
| 4106 |
|
| 4107 |
as_bad (_("unterminated string")); |
| 4108 |
mmix_discard_rest_of_line (); |
| 4109 |
return; |
| 4110 |
} |
| 4111 |
break; |
| 4112 |
|
| 4113 |
default: |
| 4114 |
{ |
| 4115 |
expressionS exp; |
| 4116 |
segT expseg = expression (&exp); |
| 4117 |
|
| 4118 |
|
| 4119 |
if ((expseg != absolute_section && expseg != reg_section) |
| 4120 |
|| (exp.X_op != O_constant |
| 4121 |
&& (exp.X_op != O_register |
| 4122 |
|| exp.X_add_number <= 255))) |
| 4123 |
{ |
| 4124 |
as_bad (_("BYTE expression not a pure number")); |
| 4125 |
mmix_discard_rest_of_line (); |
| 4126 |
return; |
| 4127 |
} |
| 4128 |
else if ((exp.X_add_number > 255 && exp.X_op != O_register) |
| 4129 |
|| exp.X_add_number < 0) |
| 4130 |
{ |
| 4131 |
|
| 4132 |
|
| 4133 |
as_bad (_("BYTE expression not in the range 0..255")); |
| 4134 |
mmix_discard_rest_of_line (); |
| 4135 |
return; |
| 4136 |
} |
| 4137 |
|
| 4138 |
FRAG_APPEND_1_CHAR (exp.X_add_number); |
| 4139 |
} |
| 4140 |
break; |
| 4141 |
} |
| 4142 |
|
| 4143 |
SKIP_WHITESPACE (); |
| 4144 |
c = *input_line_pointer++; |
| 4145 |
} |
| 4146 |
while (c == ','); |
| 4147 |
|
| 4148 |
input_line_pointer--; |
| 4149 |
|
| 4150 |
if (mmix_gnu_syntax) |
| 4151 |
demand_empty_rest_of_line (); |
| 4152 |
else |
| 4153 |
{ |
| 4154 |
mmix_discard_rest_of_line (); |
| 4155 |
|
| 4156 |
|
| 4157 |
input_line_pointer++; |
| 4158 |
} |
| 4159 |
|
| 4160 |
|
| 4161 |
last_alignment = 0; |
| 4162 |
} |
| 4163 |
|
| 4164 |
|
| 4165 |
|
| 4166 |
|
| 4167 |
|
| 4168 |
static void |
| 4169 |
mmix_cons (nbytes) |
| 4170 |
int nbytes; |
| 4171 |
{ |
| 4172 |
expressionS exp; |
| 4173 |
char *start; |
| 4174 |
|
| 4175 |
|
| 4176 |
|
| 4177 |
|
| 4178 |
if (now_seg == text_section) |
| 4179 |
{ |
| 4180 |
if (lowest_text_loc != (bfd_vma) -1 |
| 4181 |
&& (lowest_text_loc & (nbytes - 1)) != 0) |
| 4182 |
{ |
| 4183 |
if (text_has_contents) |
| 4184 |
as_bad (_("data item with alignment larger than location")); |
| 4185 |
else if (want_unaligned) |
| 4186 |
as_bad (_("unaligned data at an absolute location is not supported")); |
| 4187 |
|
| 4188 |
lowest_text_loc &= ~((bfd_vma) nbytes - 1); |
| 4189 |
lowest_text_loc += (bfd_vma) nbytes; |
| 4190 |
} |
| 4191 |
|
| 4192 |
text_has_contents = 1; |
| 4193 |
} |
| 4194 |
else if (now_seg == data_section) |
| 4195 |
{ |
| 4196 |
if (lowest_data_loc != (bfd_vma) -1 |
| 4197 |
&& (lowest_data_loc & (nbytes - 1)) != 0) |
| 4198 |
{ |
| 4199 |
if (data_has_contents) |
| 4200 |
as_bad (_("data item with alignment larger than location")); |
| 4201 |
else if (want_unaligned) |
| 4202 |
as_bad (_("unaligned data at an absolute location is not supported")); |
| 4203 |
|
| 4204 |
lowest_data_loc &= ~((bfd_vma) nbytes - 1); |
| 4205 |
lowest_data_loc += (bfd_vma) nbytes; |
| 4206 |
} |
| 4207 |
|
| 4208 |
data_has_contents = 1; |
| 4209 |
} |
| 4210 |
|
| 4211 |
|
| 4212 |
if (! want_unaligned) |
| 4213 |
{ |
| 4214 |
last_alignment = nbytes == 2 ? 1 : (nbytes == 4 ? 2 : 3); |
| 4215 |
frag_align (last_alignment, 0, 0); |
| 4216 |
record_alignment (now_seg, last_alignment); |
| 4217 |
} |
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
if (current_fb_label >= 0) |
| 4223 |
colon (fb_label_name (current_fb_label, 1)); |
| 4224 |
else if (pending_label != NULL) |
| 4225 |
{ |
| 4226 |
colon (pending_label); |
| 4227 |
pending_label = NULL; |
| 4228 |
} |
| 4229 |
|
| 4230 |
SKIP_WHITESPACE (); |
| 4231 |
|
| 4232 |
if (is_end_of_line[(unsigned int) *input_line_pointer]) |
| 4233 |
{ |
| 4234 |
|
| 4235 |
|
| 4236 |
exp.X_op = O_constant; |
| 4237 |
exp.X_add_number = 0; |
| 4238 |
exp.X_unsigned = 0; |
| 4239 |
exp.X_add_symbol = NULL; |
| 4240 |
exp.X_op_symbol = NULL; |
| 4241 |
emit_expr (&exp, (unsigned int) nbytes); |
| 4242 |
} |
| 4243 |
else |
| 4244 |
do |
| 4245 |
{ |
| 4246 |
unsigned int c; |
| 4247 |
|
| 4248 |
switch (*input_line_pointer) |
| 4249 |
{ |
| 4250 |
|
| 4251 |
|
| 4252 |
case '\"': |
| 4253 |
++input_line_pointer; |
| 4254 |
start = input_line_pointer; |
| 4255 |
while (is_a_char (c = next_char_of_string ())) |
| 4256 |
{ |
| 4257 |
exp.X_op = O_constant; |
| 4258 |
exp.X_add_number = c; |
| 4259 |
exp.X_unsigned = 1; |
| 4260 |
emit_expr (&exp, (unsigned int) nbytes); |
| 4261 |
} |
| 4262 |
|
| 4263 |
if (input_line_pointer[-1] != '\"') |
| 4264 |
{ |
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
as_bad (_("unterminated string")); |
| 4269 |
mmix_discard_rest_of_line (); |
| 4270 |
return; |
| 4271 |
} |
| 4272 |
break; |
| 4273 |
|
| 4274 |
default: |
| 4275 |
{ |
| 4276 |
expression (&exp); |
| 4277 |
emit_expr (&exp, (unsigned int) nbytes); |
| 4278 |
SKIP_WHITESPACE (); |
| 4279 |
} |
| 4280 |
break; |
| 4281 |
} |
| 4282 |
} |
| 4283 |
while (*input_line_pointer++ == ','); |
| 4284 |
|
| 4285 |
input_line_pointer--; |
| 4286 |
|
| 4287 |
mmix_handle_rest_of_empty_line (); |
| 4288 |
|
| 4289 |
|
| 4290 |
|
| 4291 |
} |
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
void |
| 4299 |
mmix_md_do_align (n, fill, len, max) |
| 4300 |
int n; |
| 4301 |
char *fill ATTRIBUTE_UNUSED; |
| 4302 |
int len ATTRIBUTE_UNUSED; |
| 4303 |
int max ATTRIBUTE_UNUSED; |
| 4304 |
{ |
| 4305 |
last_alignment = n; |
| 4306 |
want_unaligned = n == 0; |
| 4307 |
} |