read.c revision 38889
1/* read.c - read a source file - 2 Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 97, 1998 3 Free Software Foundation, Inc. 4 5This file is part of GAS, the GNU Assembler. 6 7GAS is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2, or (at your option) 10any later version. 11 12GAS is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with GAS; see the file COPYING. If not, write to the Free 19Software Foundation, 59 Temple Place - Suite 330, Boston, MA 2002111-1307, USA. */ 21 22#if 0 23#define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will 24 change this a bit. But then, GNU isn't 25 spozed to run on your machine anyway. 26 (RMS is so shortsighted sometimes.) 27 */ 28#else 29#define MASK_CHAR ((int)(unsigned char)-1) 30#endif 31 32 33/* This is the largest known floating point format (for now). It will 34 grow when we do 4361 style flonums. */ 35 36#define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16) 37 38/* Routines that read assembler source text to build spagetti in memory. 39 Another group of these functions is in the expr.c module. */ 40 41/* for isdigit() */ 42#include <ctype.h> 43 44#include "as.h" 45#include "subsegs.h" 46#include "sb.h" 47#include "macro.h" 48#include "obstack.h" 49#include "listing.h" 50#include "ecoff.h" 51 52#ifndef TC_START_LABEL 53#define TC_START_LABEL(x,y) (x==':') 54#endif 55 56/* The NOP_OPCODE is for the alignment fill value. 57 * fill it a nop instruction so that the disassembler does not choke 58 * on it 59 */ 60#ifndef NOP_OPCODE 61#define NOP_OPCODE 0x00 62#endif 63 64char *input_line_pointer; /*->next char of source file to parse. */ 65 66#if BITS_PER_CHAR != 8 67/* The following table is indexed by[(char)] and will break if 68 a char does not have exactly 256 states (hopefully 0:255!)! */ 69die horribly; 70#endif 71 72#ifndef LEX_AT 73/* The m88k unfortunately uses @ as a label beginner. */ 74#define LEX_AT 0 75#endif 76 77#ifndef LEX_BR 78/* The RS/6000 assembler uses {,},[,] as parts of symbol names. */ 79#define LEX_BR 0 80#endif 81 82#ifndef LEX_PCT 83/* The Delta 68k assembler permits % inside label names. */ 84#define LEX_PCT 0 85#endif 86 87#ifndef LEX_QM 88/* The PowerPC Windows NT assemblers permits ? inside label names. */ 89#define LEX_QM 0 90#endif 91 92#ifndef LEX_DOLLAR 93/* The a29k assembler does not permits labels to start with $. */ 94#define LEX_DOLLAR 3 95#endif 96 97#ifndef LEX_TILDE 98/* The Delta 68k assembler permits ~ at start of label names. */ 99#define LEX_TILDE 0 100#endif 101 102/* used by is_... macros. our ctype[] */ 103char lex_type[256] = 104{ 105 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */ 106 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */ 107 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */ 108 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */ 109 LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */ 110 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */ 111 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */ 112 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */ 113 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 114 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 115 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 116 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 118 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 119 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120}; 121 122 123/* 124 * In: a character. 125 * Out: 1 if this character ends a line. 126 */ 127#define _ (0) 128char is_end_of_line[256] = 129{ 130#ifdef CR_EOL 131 99, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */ 132#else 133 99, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */ 134#endif 135 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 136#ifdef TC_HPPA 137 _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */ 138 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */ 139#else 140 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 141 _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */ 142#endif 143 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 144 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 145 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 146 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 147 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 148 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 149 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 150 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 151 _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ 152}; 153#undef _ 154 155/* Functions private to this file. */ 156 157static char *buffer; /* 1st char of each buffer of lines is here. */ 158static char *buffer_limit; /*->1 + last char in buffer. */ 159 160/* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the 161 tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */ 162int target_big_endian = TARGET_BYTES_BIG_ENDIAN; 163 164static char *old_buffer; /* JF a hack */ 165static char *old_input; 166static char *old_limit; 167 168/* Variables for handling include file directory table. */ 169 170char **include_dirs; /* Table of pointers to directories to 171 search for .include's */ 172int include_dir_count; /* How many are in the table */ 173int include_dir_maxlen = 1;/* Length of longest in table */ 174 175#ifndef WORKING_DOT_WORD 176struct broken_word *broken_words; 177int new_broken_words; 178#endif 179 180/* The current offset into the absolute section. We don't try to 181 build frags in the absolute section, since no data can be stored 182 there. We just keep track of the current offset. */ 183addressT abs_section_offset; 184 185/* If this line had an MRI style label, it is stored in this variable. 186 This is used by some of the MRI pseudo-ops. */ 187symbolS *line_label; 188 189/* This global variable is used to support MRI common sections. We 190 translate such sections into a common symbol. This variable is 191 non-NULL when we are in an MRI common section. */ 192symbolS *mri_common_symbol; 193 194/* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we 195 need to align to an even byte boundary unless the next pseudo-op is 196 dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment 197 may be needed. */ 198static int mri_pending_align; 199 200#ifndef NO_LISTING 201#ifdef OBJ_ELF 202/* This variable is set to be non-zero if the next string we see might 203 be the name of the source file in DWARF debugging information. See 204 the comment in emit_expr for the format we look for. */ 205static int dwarf_file_string; 206#endif 207#endif 208 209static void cons_worker PARAMS ((int, int)); 210static int scrub_from_string PARAMS ((char **)); 211static void do_align PARAMS ((int, char *, int, int)); 212static void s_align PARAMS ((int, int)); 213static int hex_float PARAMS ((int, char *)); 214static void do_org PARAMS ((segT, expressionS *, int)); 215char *demand_copy_string PARAMS ((int *lenP)); 216static segT get_segmented_expression PARAMS ((expressionS *expP)); 217static segT get_known_segmented_expression PARAMS ((expressionS * expP)); 218static void pobegin PARAMS ((void)); 219static int get_line_sb PARAMS ((sb *)); 220 221 222void 223read_begin () 224{ 225 const char *p; 226 227 pobegin (); 228 obj_read_begin_hook (); 229 230 /* Something close -- but not too close -- to a multiple of 1024. 231 The debugging malloc I'm using has 24 bytes of overhead. */ 232 obstack_begin (¬es, chunksize); 233 obstack_begin (&cond_obstack, chunksize); 234 235 /* Use machine dependent syntax */ 236 for (p = line_separator_chars; *p; p++) 237 is_end_of_line[(unsigned char) *p] = 1; 238 /* Use more. FIXME-SOMEDAY. */ 239 240 if (flag_mri) 241 lex_type['?'] = 3; 242} 243 244/* set up pseudo-op tables */ 245 246static struct hash_control *po_hash; 247 248static const pseudo_typeS potable[] = 249{ 250 {"abort", s_abort, 0}, 251 {"align", s_align_ptwo, 0}, 252 {"ascii", stringer, 0}, 253 {"asciz", stringer, 1}, 254 {"balign", s_align_bytes, 0}, 255 {"balignw", s_align_bytes, -2}, 256 {"balignl", s_align_bytes, -4}, 257/* block */ 258 {"byte", cons, 1}, 259 {"comm", s_comm, 0}, 260 {"common", s_mri_common, 0}, 261 {"common.s", s_mri_common, 1}, 262 {"data", s_data, 0}, 263 {"dc", cons, 2}, 264 {"dc.b", cons, 1}, 265 {"dc.d", float_cons, 'd'}, 266 {"dc.l", cons, 4}, 267 {"dc.s", float_cons, 'f'}, 268 {"dc.w", cons, 2}, 269 {"dc.x", float_cons, 'x'}, 270 {"dcb", s_space, 2}, 271 {"dcb.b", s_space, 1}, 272 {"dcb.d", s_float_space, 'd'}, 273 {"dcb.l", s_space, 4}, 274 {"dcb.s", s_float_space, 'f'}, 275 {"dcb.w", s_space, 2}, 276 {"dcb.x", s_float_space, 'x'}, 277 {"ds", s_space, 2}, 278 {"ds.b", s_space, 1}, 279 {"ds.d", s_space, 8}, 280 {"ds.l", s_space, 4}, 281 {"ds.p", s_space, 12}, 282 {"ds.s", s_space, 4}, 283 {"ds.w", s_space, 2}, 284 {"ds.x", s_space, 12}, 285 {"debug", s_ignore, 0}, 286#ifdef S_SET_DESC 287 {"desc", s_desc, 0}, 288#endif 289/* dim */ 290 {"double", float_cons, 'd'}, 291/* dsect */ 292 {"eject", listing_eject, 0}, /* Formfeed listing */ 293 {"else", s_else, 0}, 294 {"elsec", s_else, 0}, 295 {"end", s_end, 0}, 296 {"endc", s_endif, 0}, 297 {"endif", s_endif, 0}, 298/* endef */ 299 {"equ", s_set, 0}, 300 {"equiv", s_set, 1}, 301 {"err", s_err, 0}, 302 {"exitm", s_mexit, 0}, 303/* extend */ 304 {"extern", s_ignore, 0}, /* We treat all undef as ext */ 305 {"appfile", s_app_file, 1}, 306 {"appline", s_app_line, 0}, 307 {"fail", s_fail, 0}, 308 {"file", s_app_file, 0}, 309 {"fill", s_fill, 0}, 310 {"float", float_cons, 'f'}, 311 {"format", s_ignore, 0}, 312 {"global", s_globl, 0}, 313 {"globl", s_globl, 0}, 314 {"hword", cons, 2}, 315 {"if", s_if, (int) O_ne}, 316 {"ifc", s_ifc, 0}, 317 {"ifdef", s_ifdef, 0}, 318 {"ifeq", s_if, (int) O_eq}, 319 {"ifeqs", s_ifeqs, 0}, 320 {"ifge", s_if, (int) O_ge}, 321 {"ifgt", s_if, (int) O_gt}, 322 {"ifle", s_if, (int) O_le}, 323 {"iflt", s_if, (int) O_lt}, 324 {"ifnc", s_ifc, 1}, 325 {"ifndef", s_ifdef, 1}, 326 {"ifne", s_if, (int) O_ne}, 327 {"ifnes", s_ifeqs, 1}, 328 {"ifnotdef", s_ifdef, 1}, 329 {"include", s_include, 0}, 330 {"int", cons, 4}, 331 {"irp", s_irp, 0}, 332 {"irep", s_irp, 0}, 333 {"irpc", s_irp, 1}, 334 {"irepc", s_irp, 1}, 335 {"lcomm", s_lcomm, 0}, 336 {"lflags", listing_flags, 0}, /* Listing flags */ 337 {"linkonce", s_linkonce, 0}, 338 {"list", listing_list, 1}, /* Turn listing on */ 339 {"llen", listing_psize, 1}, 340 {"long", cons, 4}, 341 {"lsym", s_lsym, 0}, 342 {"macro", s_macro, 0}, 343 {"mexit", s_mexit, 0}, 344 {"mri", s_mri, 0}, 345 {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */ 346 {"name", s_ignore, 0}, 347 {"noformat", s_ignore, 0}, 348 {"nolist", listing_list, 0}, /* Turn listing off */ 349 {"nopage", listing_nopage, 0}, 350 {"octa", cons, 16}, 351 {"offset", s_struct, 0}, 352 {"org", s_org, 0}, 353 {"p2align", s_align_ptwo, 0}, 354 {"p2alignw", s_align_ptwo, -2}, 355 {"p2alignl", s_align_ptwo, -4}, 356 {"page", listing_eject, 0}, 357 {"plen", listing_psize, 0}, 358 {"print", s_print, 0}, 359 {"psize", listing_psize, 0}, /* set paper size */ 360 {"purgem", s_purgem, 0}, 361 {"quad", cons, 8}, 362 {"rep", s_rept, 0}, 363 {"rept", s_rept, 0}, 364 {"rva", s_rva, 4}, 365 {"sbttl", listing_title, 1}, /* Subtitle of listing */ 366/* scl */ 367/* sect */ 368 {"set", s_set, 0}, 369 {"short", cons, 2}, 370 {"single", float_cons, 'f'}, 371/* size */ 372 {"space", s_space, 0}, 373 {"skip", s_space, 0}, 374 {"sleb128", s_leb128, 1}, 375 {"spc", s_ignore, 0}, 376 {"stabd", s_stab, 'd'}, 377 {"stabn", s_stab, 'n'}, 378 {"stabs", s_stab, 's'}, 379 {"string", stringer, 1}, 380 {"struct", s_struct, 0}, 381/* tag */ 382 {"text", s_text, 0}, 383 384 /* This is for gcc to use. It's only just been added (2/94), so gcc 385 won't be able to use it for a while -- probably a year or more. 386 But once this has been released, check with gcc maintainers 387 before deleting it or even changing the spelling. */ 388 {"this_GCC_requires_the_GNU_assembler", s_ignore, 0}, 389 /* If we're folding case -- done for some targets, not necessarily 390 all -- the above string in an input file will be converted to 391 this one. Match it either way... */ 392 {"this_gcc_requires_the_gnu_assembler", s_ignore, 0}, 393 394 {"title", listing_title, 0}, /* Listing title */ 395 {"ttl", listing_title, 0}, 396/* type */ 397 {"uleb128", s_leb128, 0}, 398/* use */ 399/* val */ 400 {"xcom", s_comm, 0}, 401 {"xdef", s_globl, 0}, 402 {"xref", s_ignore, 0}, 403 {"xstabs", s_xstab, 's'}, 404 {"word", cons, 2}, 405 {"zero", s_space, 0}, 406 {NULL} /* end sentinel */ 407}; 408 409static int pop_override_ok = 0; 410static const char *pop_table_name; 411 412void 413pop_insert (table) 414 const pseudo_typeS *table; 415{ 416 const char *errtxt; 417 const pseudo_typeS *pop; 418 for (pop = table; pop->poc_name; pop++) 419 { 420 errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); 421 if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists"))) 422 as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name, 423 errtxt); 424 } 425} 426 427#ifndef md_pop_insert 428#define md_pop_insert() pop_insert(md_pseudo_table) 429#endif 430 431#ifndef obj_pop_insert 432#define obj_pop_insert() pop_insert(obj_pseudo_table) 433#endif 434 435static void 436pobegin () 437{ 438 po_hash = hash_new (); 439 440 /* Do the target-specific pseudo ops. */ 441 pop_table_name = "md"; 442 md_pop_insert (); 443 444 /* Now object specific. Skip any that were in the target table. */ 445 pop_table_name = "obj"; 446 pop_override_ok = 1; 447 obj_pop_insert (); 448 449 /* Now portable ones. Skip any that we've seen already. */ 450 pop_table_name = "standard"; 451 pop_insert (potable); 452} 453 454#define HANDLE_CONDITIONAL_ASSEMBLY() \ 455 if (ignore_input ()) \ 456 { \ 457 while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \ 458 if (input_line_pointer == buffer_limit) \ 459 break; \ 460 continue; \ 461 } 462 463 464/* This function is used when scrubbing the characters between #APP 465 and #NO_APP. */ 466 467static char *scrub_string; 468static char *scrub_string_end; 469 470static int 471scrub_from_string (from) 472 char **from; 473{ 474 int size; 475 476 *from = scrub_string; 477 size = scrub_string_end - scrub_string; 478 scrub_string = scrub_string_end; 479 return size; 480} 481 482/* read_a_source_file() 483 * 484 * We read the file, putting things into a web that 485 * represents what we have been reading. 486 */ 487void 488read_a_source_file (name) 489 char *name; 490{ 491 register char c; 492 register char *s; /* string of symbol, '\0' appended */ 493 register int temp; 494 pseudo_typeS *pop; 495 496 buffer = input_scrub_new_file (name); 497 498 listing_file (name); 499 listing_newline (NULL); 500 register_dependency (name); 501 502 while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0) 503 { /* We have another line to parse. */ 504 know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */ 505 contin: /* JF this goto is my fault I admit it. 506 Someone brave please re-write the whole 507 input section here? Pleeze??? */ 508 while (input_line_pointer < buffer_limit) 509 { 510 /* We have more of this buffer to parse. */ 511 512 /* 513 * We now have input_line_pointer->1st char of next line. 514 * If input_line_pointer [-1] == '\n' then we just 515 * scanned another line: so bump line counters. 516 */ 517 if (is_end_of_line[(unsigned char) input_line_pointer[-1]]) 518 { 519#ifdef md_start_line_hook 520 md_start_line_hook (); 521#endif 522 523 if (input_line_pointer[-1] == '\n') 524 bump_line_counters (); 525 526 line_label = NULL; 527 528 if (flag_m68k_mri 529#ifdef LABELS_WITHOUT_COLONS 530 || 1 531#endif 532 ) 533 { 534 /* Text at the start of a line must be a label, we 535 run down and stick a colon in. */ 536 if (is_name_beginner (*input_line_pointer)) 537 { 538 char *line_start = input_line_pointer; 539 char c; 540 int mri_line_macro; 541 542 LISTING_NEWLINE (); 543 HANDLE_CONDITIONAL_ASSEMBLY (); 544 545 c = get_symbol_end (); 546 547 /* In MRI mode, the EQU and MACRO pseudoops must 548 be handled specially. */ 549 mri_line_macro = 0; 550 if (flag_m68k_mri) 551 { 552 char *rest = input_line_pointer + 1; 553 554 if (*rest == ':') 555 ++rest; 556 if (*rest == ' ' || *rest == '\t') 557 ++rest; 558 if ((strncasecmp (rest, "EQU", 3) == 0 559 || strncasecmp (rest, "SET", 3) == 0) 560 && (rest[3] == ' ' || rest[3] == '\t')) 561 { 562 input_line_pointer = rest + 3; 563 equals (line_start, 564 strncasecmp (rest, "SET", 3) == 0); 565 continue; 566 } 567 if (strncasecmp (rest, "MACRO", 5) == 0 568 && (rest[5] == ' ' 569 || rest[5] == '\t' 570 || is_end_of_line[(unsigned char) rest[5]])) 571 mri_line_macro = 1; 572 } 573 574 /* In MRI mode, we need to handle the MACRO 575 pseudo-op specially: we don't want to put the 576 symbol in the symbol table. */ 577 if (! mri_line_macro) 578 line_label = colon (line_start); 579 else 580 line_label = symbol_create (line_start, 581 absolute_section, 582 (valueT) 0, 583 &zero_address_frag); 584 585 *input_line_pointer = c; 586 if (c == ':') 587 input_line_pointer++; 588 } 589 } 590 } 591 592 /* 593 * We are at the begining of a line, or similar place. 594 * We expect a well-formed assembler statement. 595 * A "symbol-name:" is a statement. 596 * 597 * Depending on what compiler is used, the order of these tests 598 * may vary to catch most common case 1st. 599 * Each test is independent of all other tests at the (top) level. 600 * PLEASE make a compiler that doesn't use this assembler. 601 * It is crufty to waste a compiler's time encoding things for this 602 * assembler, which then wastes more time decoding it. 603 * (And communicating via (linear) files is silly! 604 * If you must pass stuff, please pass a tree!) 605 */ 606 if ((c = *input_line_pointer++) == '\t' 607 || c == ' ' 608 || c == '\f' 609 || c == 0) 610 { 611 c = *input_line_pointer++; 612 } 613 know (c != ' '); /* No further leading whitespace. */ 614 615#ifndef NO_LISTING 616 /* If listing is on, and we are expanding a macro, then give 617 the listing code the contents of the expanded line. */ 618 if (listing) 619 { 620 if ((listing & LISTING_MACEXP) && macro_nest > 0) 621 { 622 char *copy; 623 int len; 624 625 /* Find the end of the current expanded macro line. */ 626 for (s = input_line_pointer-1; *s ; ++s) 627 if (is_end_of_line[(unsigned char) *s]) 628 break; 629 630 /* Copy it for safe keeping. Also give an indication of 631 how much macro nesting is involved at this point. */ 632 len = s - (input_line_pointer-1); 633 copy = (char *) xmalloc (len + macro_nest + 2); 634 memset (copy, '>', macro_nest); 635 copy[macro_nest] = ' '; 636 memcpy (copy + macro_nest + 1, input_line_pointer-1, len); 637 copy[macro_nest+1+len] = '\0'; 638 639 /* Install the line with the listing facility. */ 640 listing_newline (copy); 641 } 642 else 643 listing_newline (NULL); 644 } 645#endif 646 647 /* 648 * C is the 1st significant character. 649 * Input_line_pointer points after that character. 650 */ 651 if (is_name_beginner (c)) 652 { 653 /* want user-defined label or pseudo/opcode */ 654 HANDLE_CONDITIONAL_ASSEMBLY (); 655 656 s = --input_line_pointer; 657 c = get_symbol_end (); /* name's delimiter */ 658 /* 659 * C is character after symbol. 660 * That character's place in the input line is now '\0'. 661 * S points to the beginning of the symbol. 662 * [In case of pseudo-op, s->'.'.] 663 * Input_line_pointer->'\0' where c was. 664 */ 665 if (TC_START_LABEL(c, input_line_pointer)) 666 { 667 if (flag_m68k_mri) 668 { 669 char *rest = input_line_pointer + 1; 670 671 /* In MRI mode, \tsym: set 0 is permitted. */ 672 673 if (*rest == ':') 674 ++rest; 675 if (*rest == ' ' || *rest == '\t') 676 ++rest; 677 if ((strncasecmp (rest, "EQU", 3) == 0 678 || strncasecmp (rest, "SET", 3) == 0) 679 && (rest[3] == ' ' || rest[3] == '\t')) 680 { 681 input_line_pointer = rest + 3; 682 equals (s, 1); 683 continue; 684 } 685 } 686 687 line_label = colon (s); /* user-defined label */ 688 *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */ 689 /* Input_line_pointer->after ':'. */ 690 SKIP_WHITESPACE (); 691 692 693 } 694 else if (c == '=' 695 || ((c == ' ' || c == '\t') 696 && input_line_pointer[1] == '=' 697#ifdef TC_EQUAL_IN_INSN 698 && ! TC_EQUAL_IN_INSN (c, input_line_pointer) 699#endif 700 )) 701 { 702 equals (s, 1); 703 demand_empty_rest_of_line (); 704 } 705 else 706 { /* expect pseudo-op or machine instruction */ 707 pop = NULL; 708 709#define IGNORE_OPCODE_CASE 710#ifdef IGNORE_OPCODE_CASE 711 { 712 char *s2 = s; 713 while (*s2) 714 { 715 if (isupper ((unsigned char) *s2)) 716 *s2 = tolower (*s2); 717 s2++; 718 } 719 } 720#endif 721 722 if (flag_m68k_mri 723#ifdef NO_PSEUDO_DOT 724 || 1 725#endif 726 ) 727 { 728 /* The MRI assembler and the m88k use pseudo-ops 729 without a period. */ 730 pop = (pseudo_typeS *) hash_find (po_hash, s); 731 if (pop != NULL && pop->poc_handler == NULL) 732 pop = NULL; 733 } 734 735 if (pop != NULL 736 || (! flag_m68k_mri && *s == '.')) 737 { 738 /* 739 * PSEUDO - OP. 740 * 741 * WARNING: c has next char, which may be end-of-line. 742 * We lookup the pseudo-op table with s+1 because we 743 * already know that the pseudo-op begins with a '.'. 744 */ 745 746 if (pop == NULL) 747 pop = (pseudo_typeS *) hash_find (po_hash, s + 1); 748 749 /* In MRI mode, we may need to insert an 750 automatic alignment directive. What a hack 751 this is. */ 752 if (mri_pending_align 753 && (pop == NULL 754 || ! ((pop->poc_handler == cons 755 && pop->poc_val == 1) 756 || (pop->poc_handler == s_space 757 && pop->poc_val == 1) 758#ifdef tc_conditional_pseudoop 759 || tc_conditional_pseudoop (pop) 760#endif 761 || pop->poc_handler == s_if 762 || pop->poc_handler == s_ifdef 763 || pop->poc_handler == s_ifc 764 || pop->poc_handler == s_ifeqs 765 || pop->poc_handler == s_else 766 || pop->poc_handler == s_endif 767 || pop->poc_handler == s_globl 768 || pop->poc_handler == s_ignore))) 769 { 770 do_align (1, (char *) NULL, 0, 0); 771 mri_pending_align = 0; 772 if (line_label != NULL) 773 { 774 line_label->sy_frag = frag_now; 775 S_SET_VALUE (line_label, frag_now_fix ()); 776 } 777 } 778 779 /* Print the error msg now, while we still can */ 780 if (pop == NULL) 781 { 782 as_bad ("Unknown pseudo-op: `%s'", s); 783 *input_line_pointer = c; 784 s_ignore (0); 785 continue; 786 } 787 788 /* Put it back for error messages etc. */ 789 *input_line_pointer = c; 790 /* The following skip of whitespace is compulsory. 791 A well shaped space is sometimes all that separates 792 keyword from operands. */ 793 if (c == ' ' || c == '\t') 794 input_line_pointer++; 795 /* 796 * Input_line is restored. 797 * Input_line_pointer->1st non-blank char 798 * after pseudo-operation. 799 */ 800 (*pop->poc_handler) (pop->poc_val); 801 802 /* If that was .end, just get out now. */ 803 if (pop->poc_handler == s_end) 804 goto quit; 805 } 806 else 807 { 808 int inquote = 0; 809 810 /* WARNING: c has char, which may be end-of-line. */ 811 /* Also: input_line_pointer->`\0` where c was. */ 812 *input_line_pointer = c; 813 while (!is_end_of_line[(unsigned char) *input_line_pointer] 814 || inquote 815#ifdef TC_EOL_IN_INSN 816 || TC_EOL_IN_INSN (input_line_pointer) 817#endif 818 ) 819 { 820 if (flag_m68k_mri && *input_line_pointer == '\'') 821 inquote = ! inquote; 822 input_line_pointer++; 823 } 824 825 c = *input_line_pointer; 826 *input_line_pointer = '\0'; 827 828 if (debug_type == DEBUG_STABS) 829 stabs_generate_asm_lineno (); 830 831#ifdef OBJ_GENERATE_ASM_LINENO 832#ifdef ECOFF_DEBUGGING 833 /* ECOFF assemblers automatically generate 834 debugging information. FIXME: This should 835 probably be handled elsewhere. */ 836 if (debug_type == DEBUG_NONE) 837 { 838 if (ecoff_no_current_file ()) 839 debug_type = DEBUG_ECOFF; 840 } 841 842 if (debug_type == DEBUG_ECOFF) 843 { 844 unsigned int lineno; 845 char *s; 846 847 as_where (&s, &lineno); 848 OBJ_GENERATE_ASM_LINENO (s, lineno); 849 } 850#endif 851#endif 852 853 if (macro_defined) 854 { 855 sb out; 856 const char *err; 857 858 if (check_macro (s, &out, '\0', &err)) 859 { 860 if (err != NULL) 861 as_bad (err); 862 *input_line_pointer++ = c; 863 input_scrub_include_sb (&out, 864 input_line_pointer); 865 sb_kill (&out); 866 buffer_limit = 867 input_scrub_next_buffer (&input_line_pointer); 868 continue; 869 } 870 } 871 872 if (mri_pending_align) 873 { 874 do_align (1, (char *) NULL, 0, 0); 875 mri_pending_align = 0; 876 if (line_label != NULL) 877 { 878 line_label->sy_frag = frag_now; 879 S_SET_VALUE (line_label, frag_now_fix ()); 880 } 881 } 882 883 md_assemble (s); /* Assemble 1 instruction. */ 884 885 *input_line_pointer++ = c; 886 887 /* We resume loop AFTER the end-of-line from 888 this instruction. */ 889 } /* if (*s=='.') */ 890 } /* if c==':' */ 891 continue; 892 } /* if (is_name_beginner(c) */ 893 894 895 /* Empty statement? */ 896 if (is_end_of_line[(unsigned char) c]) 897 continue; 898 899 if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) 900 && isdigit ((unsigned char) c)) 901 { 902 /* local label ("4:") */ 903 char *backup = input_line_pointer; 904 905 HANDLE_CONDITIONAL_ASSEMBLY (); 906 907 temp = c - '0'; 908 909 while (isdigit ((unsigned char) *input_line_pointer)) 910 { 911 temp = (temp * 10) + *input_line_pointer - '0'; 912 ++input_line_pointer; 913 } /* read the whole number */ 914 915 if (LOCAL_LABELS_DOLLAR 916 && *input_line_pointer == '$' 917 && *(input_line_pointer + 1) == ':') 918 { 919 input_line_pointer += 2; 920 921 if (dollar_label_defined (temp)) 922 { 923 as_fatal ("label \"%d$\" redefined", temp); 924 } 925 926 define_dollar_label (temp); 927 colon (dollar_label_name (temp, 0)); 928 continue; 929 } 930 931 if (LOCAL_LABELS_FB 932 && *input_line_pointer++ == ':') 933 { 934 fb_label_instance_inc (temp); 935 colon (fb_label_name (temp, 0)); 936 continue; 937 } 938 939 input_line_pointer = backup; 940 } /* local label ("4:") */ 941 942 if (c && strchr (line_comment_chars, c)) 943 { /* Its a comment. Better say APP or NO_APP */ 944 char *ends; 945 char *new_buf; 946 char *new_tmp; 947 unsigned int new_length; 948 char *tmp_buf = 0; 949 950 bump_line_counters (); 951 s = input_line_pointer; 952 if (strncmp (s, "APP\n", 4)) 953 continue; /* We ignore it */ 954 s += 4; 955 956 ends = strstr (s, "#NO_APP\n"); 957 958 if (!ends) 959 { 960 unsigned int tmp_len; 961 unsigned int num; 962 963 /* The end of the #APP wasn't in this buffer. We 964 keep reading in buffers until we find the #NO_APP 965 that goes with this #APP There is one. The specs 966 guarentee it. . . */ 967 tmp_len = buffer_limit - s; 968 tmp_buf = xmalloc (tmp_len + 1); 969 memcpy (tmp_buf, s, tmp_len); 970 do 971 { 972 new_tmp = input_scrub_next_buffer (&buffer); 973 if (!new_tmp) 974 break; 975 else 976 buffer_limit = new_tmp; 977 input_line_pointer = buffer; 978 ends = strstr (buffer, "#NO_APP\n"); 979 if (ends) 980 num = ends - buffer; 981 else 982 num = buffer_limit - buffer; 983 984 tmp_buf = xrealloc (tmp_buf, tmp_len + num); 985 memcpy (tmp_buf + tmp_len, buffer, num); 986 tmp_len += num; 987 } 988 while (!ends); 989 990 input_line_pointer = ends ? ends + 8 : NULL; 991 992 s = tmp_buf; 993 ends = s + tmp_len; 994 995 } 996 else 997 { 998 input_line_pointer = ends + 8; 999 } 1000 1001 scrub_string = s; 1002 scrub_string_end = ends; 1003 1004 new_length = ends - s; 1005 new_buf = (char *) xmalloc (new_length); 1006 new_tmp = new_buf; 1007 for (;;) 1008 { 1009 int space; 1010 int size; 1011 1012 space = (new_buf + new_length) - new_tmp; 1013 size = do_scrub_chars (scrub_from_string, new_tmp, space); 1014 1015 if (size < space) 1016 { 1017 new_tmp += size; 1018 break; 1019 } 1020 1021 new_buf = xrealloc (new_buf, new_length + 100); 1022 new_tmp = new_buf + new_length; 1023 new_length += 100; 1024 } 1025 1026 if (tmp_buf) 1027 free (tmp_buf); 1028 old_buffer = buffer; 1029 old_input = input_line_pointer; 1030 old_limit = buffer_limit; 1031 buffer = new_buf; 1032 input_line_pointer = new_buf; 1033 buffer_limit = new_tmp; 1034 continue; 1035 } 1036 1037 HANDLE_CONDITIONAL_ASSEMBLY (); 1038 1039#ifdef tc_unrecognized_line 1040 if (tc_unrecognized_line (c)) 1041 continue; 1042#endif 1043 1044 /* as_warn("Junk character %d.",c); Now done by ignore_rest */ 1045 input_line_pointer--; /* Report unknown char as ignored. */ 1046 ignore_rest_of_line (); 1047 } /* while (input_line_pointer<buffer_limit) */ 1048 1049#ifdef md_after_pass_hook 1050 md_after_pass_hook (); 1051#endif 1052 1053 if (old_buffer) 1054 { 1055 free (buffer); 1056 bump_line_counters (); 1057 if (old_input != 0) 1058 { 1059 buffer = old_buffer; 1060 input_line_pointer = old_input; 1061 buffer_limit = old_limit; 1062 old_buffer = 0; 1063 goto contin; 1064 } 1065 } 1066 } /* while (more buffers to scan) */ 1067 1068 quit: 1069 1070#ifdef md_cleanup 1071 md_cleanup(); 1072#endif 1073 input_scrub_close (); /* Close the input file */ 1074} 1075 1076/* For most MRI pseudo-ops, the line actually ends at the first 1077 nonquoted space. This function looks for that point, stuffs a null 1078 in, and sets *STOPCP to the character that used to be there, and 1079 returns the location. 1080 1081 Until I hear otherwise, I am going to assume that this is only true 1082 for the m68k MRI assembler. */ 1083 1084char * 1085mri_comment_field (stopcp) 1086 char *stopcp; 1087{ 1088#ifdef TC_M68K 1089 1090 char *s; 1091 int inquote = 0; 1092 1093 know (flag_m68k_mri); 1094 1095 for (s = input_line_pointer; 1096 ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t') 1097 || inquote); 1098 s++) 1099 { 1100 if (*s == '\'') 1101 inquote = ! inquote; 1102 } 1103 *stopcp = *s; 1104 *s = '\0'; 1105 return s; 1106 1107#else 1108 1109 char *s; 1110 1111 for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++) 1112 ; 1113 *stopcp = *s; 1114 *s = '\0'; 1115 return s; 1116 1117#endif 1118 1119} 1120 1121/* Skip to the end of an MRI comment field. */ 1122 1123void 1124mri_comment_end (stop, stopc) 1125 char *stop; 1126 int stopc; 1127{ 1128 know (flag_mri); 1129 1130 input_line_pointer = stop; 1131 *stop = stopc; 1132 while (! is_end_of_line[(unsigned char) *input_line_pointer]) 1133 ++input_line_pointer; 1134} 1135 1136void 1137s_abort (ignore) 1138 int ignore; 1139{ 1140 as_fatal (".abort detected. Abandoning ship."); 1141} 1142 1143/* Guts of .align directive. N is the power of two to which to align. 1144 FILL may be NULL, or it may point to the bytes of the fill pattern. 1145 LEN is the length of whatever FILL points to, if anything. MAX is 1146 the maximum number of characters to skip when doing the alignment, 1147 or 0 if there is no maximum. */ 1148 1149static void 1150do_align (n, fill, len, max) 1151 int n; 1152 char *fill; 1153 int len; 1154 int max; 1155{ 1156 char default_fill; 1157 1158#ifdef md_do_align 1159 md_do_align (n, fill, len, max, just_record_alignment); 1160#endif 1161 1162 if (fill == NULL) 1163 { 1164 int maybe_text; 1165 1166#ifdef BFD_ASSEMBLER 1167 if ((bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0) 1168 maybe_text = 1; 1169 else 1170 maybe_text = 0; 1171#else 1172 if (now_seg != data_section && now_seg != bss_section) 1173 maybe_text = 1; 1174 else 1175 maybe_text = 0; 1176#endif 1177 1178 if (maybe_text) 1179 default_fill = NOP_OPCODE; 1180 else 1181 default_fill = 0; 1182 fill = &default_fill; 1183 len = 1; 1184 } 1185 1186 /* Only make a frag if we HAVE to. . . */ 1187 if (n != 0 && !need_pass_2) 1188 { 1189 if (len <= 1) 1190 frag_align (n, *fill, max); 1191 else 1192 frag_align_pattern (n, fill, len, max); 1193 } 1194 1195#ifdef md_do_align 1196 just_record_alignment: 1197#endif 1198 1199 record_alignment (now_seg, n); 1200} 1201 1202/* Handle the .align pseudo-op. A positive ARG is a default alignment 1203 (in bytes). A negative ARG is the negative of the length of the 1204 fill pattern. BYTES_P is non-zero if the alignment value should be 1205 interpreted as the byte boundary, rather than the power of 2. */ 1206 1207static void 1208s_align (arg, bytes_p) 1209 int arg; 1210 int bytes_p; 1211{ 1212 register unsigned int align; 1213 char *stop = NULL; 1214 char stopc; 1215 offsetT fill = 0; 1216 int max; 1217 int fill_p; 1218 1219 if (flag_mri) 1220 stop = mri_comment_field (&stopc); 1221 1222 if (is_end_of_line[(unsigned char) *input_line_pointer]) 1223 { 1224 if (arg < 0) 1225 align = 0; 1226 else 1227 align = arg; /* Default value from pseudo-op table */ 1228 } 1229 else 1230 { 1231 align = get_absolute_expression (); 1232 SKIP_WHITESPACE (); 1233 } 1234 1235 if (bytes_p) 1236 { 1237 /* Convert to a power of 2. */ 1238 if (align != 0) 1239 { 1240 unsigned int i; 1241 1242 for (i = 0; (align & 1) == 0; align >>= 1, ++i) 1243 ; 1244 if (align != 1) 1245 as_bad ("Alignment not a power of 2"); 1246 align = i; 1247 } 1248 } 1249 1250 if (align > 15) 1251 { 1252 align = 15; 1253 as_bad ("Alignment too large: %u assumed", align); 1254 } 1255 1256 if (*input_line_pointer != ',') 1257 { 1258 fill_p = 0; 1259 max = 0; 1260 } 1261 else 1262 { 1263 ++input_line_pointer; 1264 if (*input_line_pointer == ',') 1265 fill_p = 0; 1266 else 1267 { 1268 fill = get_absolute_expression (); 1269 SKIP_WHITESPACE (); 1270 fill_p = 1; 1271 } 1272 1273 if (*input_line_pointer != ',') 1274 max = 0; 1275 else 1276 { 1277 ++input_line_pointer; 1278 max = get_absolute_expression (); 1279 } 1280 } 1281 1282 if (! fill_p) 1283 { 1284 if (arg < 0) 1285 as_warn ("expected fill pattern missing"); 1286 do_align (align, (char *) NULL, 0, max); 1287 } 1288 else 1289 { 1290 int fill_len; 1291 1292 if (arg >= 0) 1293 fill_len = 1; 1294 else 1295 fill_len = - arg; 1296 if (fill_len <= 1) 1297 { 1298 char fill_char; 1299 1300 fill_char = fill; 1301 do_align (align, &fill_char, fill_len, max); 1302 } 1303 else 1304 { 1305 char ab[16]; 1306 1307 if ((size_t) fill_len > sizeof ab) 1308 abort (); 1309 md_number_to_chars (ab, fill, fill_len); 1310 do_align (align, ab, fill_len, max); 1311 } 1312 } 1313 1314 if (flag_mri) 1315 mri_comment_end (stop, stopc); 1316 1317 demand_empty_rest_of_line (); 1318} 1319 1320/* Handle the .align pseudo-op on machines where ".align 4" means 1321 align to a 4 byte boundary. */ 1322 1323void 1324s_align_bytes (arg) 1325 int arg; 1326{ 1327 s_align (arg, 1); 1328} 1329 1330/* Handle the .align pseudo-op on machines where ".align 4" means align 1331 to a 2**4 boundary. */ 1332 1333void 1334s_align_ptwo (arg) 1335 int arg; 1336{ 1337 s_align (arg, 0); 1338} 1339 1340void 1341s_comm (ignore) 1342 int ignore; 1343{ 1344 register char *name; 1345 register char c; 1346 register char *p; 1347 offsetT temp; 1348 register symbolS *symbolP; 1349 char *stop = NULL; 1350 char stopc; 1351 1352 if (flag_mri) 1353 stop = mri_comment_field (&stopc); 1354 1355 name = input_line_pointer; 1356 c = get_symbol_end (); 1357 /* just after name is now '\0' */ 1358 p = input_line_pointer; 1359 *p = c; 1360 SKIP_WHITESPACE (); 1361 if (*input_line_pointer != ',') 1362 { 1363 as_bad ("Expected comma after symbol-name: rest of line ignored."); 1364 if (flag_mri) 1365 mri_comment_end (stop, stopc); 1366 ignore_rest_of_line (); 1367 return; 1368 } 1369 input_line_pointer++; /* skip ',' */ 1370 if ((temp = get_absolute_expression ()) < 0) 1371 { 1372 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp); 1373 if (flag_mri) 1374 mri_comment_end (stop, stopc); 1375 ignore_rest_of_line (); 1376 return; 1377 } 1378 *p = 0; 1379 symbolP = symbol_find_or_make (name); 1380 *p = c; 1381 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) 1382 { 1383 as_bad ("Ignoring attempt to re-define symbol `%s'.", 1384 S_GET_NAME (symbolP)); 1385 if (flag_mri) 1386 mri_comment_end (stop, stopc); 1387 ignore_rest_of_line (); 1388 return; 1389 } 1390 if (S_GET_VALUE (symbolP)) 1391 { 1392 if (S_GET_VALUE (symbolP) != (valueT) temp) 1393 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.", 1394 S_GET_NAME (symbolP), 1395 (long) S_GET_VALUE (symbolP), 1396 (long) temp); 1397 } 1398 else 1399 { 1400 S_SET_VALUE (symbolP, (valueT) temp); 1401 S_SET_EXTERNAL (symbolP); 1402 } 1403#ifdef OBJ_VMS 1404 { 1405 extern int flag_one; 1406 if ( (!temp) || !flag_one) 1407 S_GET_OTHER(symbolP) = const_flag; 1408 } 1409#endif /* not OBJ_VMS */ 1410 know (symbolP->sy_frag == &zero_address_frag); 1411 1412 if (flag_mri) 1413 mri_comment_end (stop, stopc); 1414 1415 demand_empty_rest_of_line (); 1416} /* s_comm() */ 1417 1418/* The MRI COMMON pseudo-op. We handle this by creating a common 1419 symbol with the appropriate name. We make s_space do the right 1420 thing by increasing the size. */ 1421 1422void 1423s_mri_common (small) 1424 int small; 1425{ 1426 char *name; 1427 char c; 1428 char *alc = NULL; 1429 symbolS *sym; 1430 offsetT align; 1431 char *stop = NULL; 1432 char stopc; 1433 1434 if (! flag_mri) 1435 { 1436 s_comm (0); 1437 return; 1438 } 1439 1440 stop = mri_comment_field (&stopc); 1441 1442 SKIP_WHITESPACE (); 1443 1444 name = input_line_pointer; 1445 if (! isdigit ((unsigned char) *name)) 1446 c = get_symbol_end (); 1447 else 1448 { 1449 do 1450 { 1451 ++input_line_pointer; 1452 } 1453 while (isdigit ((unsigned char) *input_line_pointer)); 1454 c = *input_line_pointer; 1455 *input_line_pointer = '\0'; 1456 1457 if (line_label != NULL) 1458 { 1459 alc = (char *) xmalloc (strlen (S_GET_NAME (line_label)) 1460 + (input_line_pointer - name) 1461 + 1); 1462 sprintf (alc, "%s%s", name, S_GET_NAME (line_label)); 1463 name = alc; 1464 } 1465 } 1466 1467 sym = symbol_find_or_make (name); 1468 *input_line_pointer = c; 1469 if (alc != NULL) 1470 free (alc); 1471 1472 if (*input_line_pointer != ',') 1473 align = 0; 1474 else 1475 { 1476 ++input_line_pointer; 1477 align = get_absolute_expression (); 1478 } 1479 1480 if (S_IS_DEFINED (sym) && ! S_IS_COMMON (sym)) 1481 { 1482 as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym)); 1483 mri_comment_end (stop, stopc); 1484 ignore_rest_of_line (); 1485 return; 1486 } 1487 1488 S_SET_EXTERNAL (sym); 1489 mri_common_symbol = sym; 1490 1491#ifdef S_SET_ALIGN 1492 if (align != 0) 1493 S_SET_ALIGN (sym, align); 1494#endif 1495 1496 if (line_label != NULL) 1497 { 1498 line_label->sy_value.X_op = O_symbol; 1499 line_label->sy_value.X_add_symbol = sym; 1500 line_label->sy_value.X_add_number = S_GET_VALUE (sym); 1501 line_label->sy_frag = &zero_address_frag; 1502 S_SET_SEGMENT (line_label, expr_section); 1503 } 1504 1505 /* FIXME: We just ignore the small argument, which distinguishes 1506 COMMON and COMMON.S. I don't know what we can do about it. */ 1507 1508 /* Ignore the type and hptype. */ 1509 if (*input_line_pointer == ',') 1510 input_line_pointer += 2; 1511 if (*input_line_pointer == ',') 1512 input_line_pointer += 2; 1513 1514 mri_comment_end (stop, stopc); 1515 1516 demand_empty_rest_of_line (); 1517} 1518 1519void 1520s_data (ignore) 1521 int ignore; 1522{ 1523 segT section; 1524 register int temp; 1525 1526 temp = get_absolute_expression (); 1527 if (flag_readonly_data_in_text) 1528 { 1529 section = text_section; 1530 temp += 1000; 1531 } 1532 else 1533 section = data_section; 1534 1535 subseg_set (section, (subsegT) temp); 1536 1537#ifdef OBJ_VMS 1538 const_flag = 0; 1539#endif 1540 demand_empty_rest_of_line (); 1541} 1542 1543/* Handle the .appfile pseudo-op. This is automatically generated by 1544 do_scrub_chars when a preprocessor # line comment is seen with a 1545 file name. This default definition may be overridden by the object 1546 or CPU specific pseudo-ops. This function is also the default 1547 definition for .file; the APPFILE argument is 1 for .appfile, 0 for 1548 .file. */ 1549 1550void 1551s_app_file (appfile) 1552 int appfile; 1553{ 1554 register char *s; 1555 int length; 1556 1557 /* Some assemblers tolerate immediately following '"' */ 1558 if ((s = demand_copy_string (&length)) != 0) 1559 { 1560 /* If this is a fake .appfile, a fake newline was inserted into 1561 the buffer. Passing -2 to new_logical_line tells it to 1562 account for it. */ 1563 int may_omit 1564 = (! new_logical_line (s, appfile ? -2 : -1) && appfile); 1565 1566 /* In MRI mode, the preprocessor may have inserted an extraneous 1567 backquote. */ 1568 if (flag_m68k_mri 1569 && *input_line_pointer == '\'' 1570 && is_end_of_line[(unsigned char) input_line_pointer[1]]) 1571 ++input_line_pointer; 1572 1573 demand_empty_rest_of_line (); 1574 if (! may_omit) 1575 { 1576#ifdef LISTING 1577 if (listing) 1578 listing_source_file (s); 1579#endif 1580 register_dependency (s); 1581#ifdef obj_app_file 1582 obj_app_file (s); 1583#endif 1584 } 1585 } 1586} 1587 1588/* Handle the .appline pseudo-op. This is automatically generated by 1589 do_scrub_chars when a preprocessor # line comment is seen. This 1590 default definition may be overridden by the object or CPU specific 1591 pseudo-ops. */ 1592 1593void 1594s_app_line (ignore) 1595 int ignore; 1596{ 1597 int l; 1598 1599 /* The given number is that of the next line. */ 1600 l = get_absolute_expression () - 1; 1601 if (l < 0) 1602 /* Some of the back ends can't deal with non-positive line numbers. 1603 Besides, it's silly. */ 1604 as_warn ("Line numbers must be positive; line number %d rejected.", l+1); 1605 else 1606 { 1607 new_logical_line ((char *) NULL, l); 1608#ifdef LISTING 1609 if (listing) 1610 listing_source_line (l); 1611#endif 1612 } 1613 demand_empty_rest_of_line (); 1614} 1615 1616/* Handle the .end pseudo-op. Actually, the real work is done in 1617 read_a_source_file. */ 1618 1619void 1620s_end (ignore) 1621 int ignore; 1622{ 1623 if (flag_mri) 1624 { 1625 /* The MRI assembler permits the start symbol to follow .end, 1626 but we don't support that. */ 1627 SKIP_WHITESPACE (); 1628 if (! is_end_of_line[(unsigned char) *input_line_pointer] 1629 && *input_line_pointer != '*' 1630 && *input_line_pointer != '!') 1631 as_warn ("start address not supported"); 1632 } 1633} 1634 1635/* Handle the .err pseudo-op. */ 1636 1637void 1638s_err (ignore) 1639 int ignore; 1640{ 1641 as_bad (".err encountered"); 1642 demand_empty_rest_of_line (); 1643} 1644 1645/* Handle the MRI fail pseudo-op. */ 1646 1647void 1648s_fail (ignore) 1649 int ignore; 1650{ 1651 offsetT temp; 1652 char *stop = NULL; 1653 char stopc; 1654 1655 if (flag_mri) 1656 stop = mri_comment_field (&stopc); 1657 1658 temp = get_absolute_expression (); 1659 if (temp >= 500) 1660 as_warn (".fail %ld encountered", (long) temp); 1661 else 1662 as_bad (".fail %ld encountered", (long) temp); 1663 1664 if (flag_mri) 1665 mri_comment_end (stop, stopc); 1666 1667 demand_empty_rest_of_line (); 1668} 1669 1670void 1671s_fill (ignore) 1672 int ignore; 1673{ 1674 expressionS rep_exp; 1675 long size = 1; 1676 register long fill = 0; 1677 char *p; 1678 1679#ifdef md_flush_pending_output 1680 md_flush_pending_output (); 1681#endif 1682 1683 get_known_segmented_expression (&rep_exp); 1684 if (*input_line_pointer == ',') 1685 { 1686 input_line_pointer++; 1687 size = get_absolute_expression (); 1688 if (*input_line_pointer == ',') 1689 { 1690 input_line_pointer++; 1691 fill = get_absolute_expression (); 1692 } 1693 } 1694 1695 /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */ 1696#define BSD_FILL_SIZE_CROCK_8 (8) 1697 if (size > BSD_FILL_SIZE_CROCK_8) 1698 { 1699 as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8); 1700 size = BSD_FILL_SIZE_CROCK_8; 1701 } 1702 if (size < 0) 1703 { 1704 as_warn ("Size negative: .fill ignored."); 1705 size = 0; 1706 } 1707 else if (rep_exp.X_op == O_constant && rep_exp.X_add_number <= 0) 1708 { 1709 if (rep_exp.X_add_number < 0) 1710 as_warn ("Repeat < 0, .fill ignored"); 1711 size = 0; 1712 } 1713 1714 if (size && !need_pass_2) 1715 { 1716 if (rep_exp.X_op == O_constant) 1717 { 1718 p = frag_var (rs_fill, (int) size, (int) size, 1719 (relax_substateT) 0, (symbolS *) 0, 1720 (offsetT) rep_exp.X_add_number, 1721 (char *) 0); 1722 } 1723 else 1724 { 1725 /* We don't have a constant repeat count, so we can't use 1726 rs_fill. We can get the same results out of rs_space, 1727 but its argument is in bytes, so we must multiply the 1728 repeat count by size. */ 1729 1730 symbolS *rep_sym; 1731 rep_sym = make_expr_symbol (&rep_exp); 1732 if (size != 1) 1733 { 1734 expressionS size_exp; 1735 size_exp.X_op = O_constant; 1736 size_exp.X_add_number = size; 1737 1738 rep_exp.X_op = O_multiply; 1739 rep_exp.X_add_symbol = rep_sym; 1740 rep_exp.X_op_symbol = make_expr_symbol (&size_exp); 1741 rep_exp.X_add_number = 0; 1742 rep_sym = make_expr_symbol (&rep_exp); 1743 } 1744 1745 p = frag_var (rs_space, (int) size, (int) size, 1746 (relax_substateT) 0, rep_sym, (offsetT) 0, (char *) 0); 1747 } 1748 memset (p, 0, (unsigned int) size); 1749 /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX 1750 * flavoured AS. The following bizzare behaviour is to be 1751 * compatible with above. I guess they tried to take up to 8 1752 * bytes from a 4-byte expression and they forgot to sign 1753 * extend. Un*x Sux. */ 1754#define BSD_FILL_SIZE_CROCK_4 (4) 1755 md_number_to_chars (p, (valueT) fill, 1756 (size > BSD_FILL_SIZE_CROCK_4 1757 ? BSD_FILL_SIZE_CROCK_4 1758 : (int) size)); 1759 /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes) 1760 * but emits no error message because it seems a legal thing to do. 1761 * It is a degenerate case of .fill but could be emitted by a compiler. 1762 */ 1763 } 1764 demand_empty_rest_of_line (); 1765} 1766 1767void 1768s_globl (ignore) 1769 int ignore; 1770{ 1771 char *name; 1772 int c; 1773 symbolS *symbolP; 1774 char *stop = NULL; 1775 char stopc; 1776 1777 if (flag_mri) 1778 stop = mri_comment_field (&stopc); 1779 1780 do 1781 { 1782 name = input_line_pointer; 1783 c = get_symbol_end (); 1784 symbolP = symbol_find_or_make (name); 1785 *input_line_pointer = c; 1786 SKIP_WHITESPACE (); 1787 S_SET_EXTERNAL (symbolP); 1788 if (c == ',') 1789 { 1790 input_line_pointer++; 1791 SKIP_WHITESPACE (); 1792 if (*input_line_pointer == '\n') 1793 c = '\n'; 1794 } 1795 } 1796 while (c == ','); 1797 1798 if (flag_mri) 1799 mri_comment_end (stop, stopc); 1800 1801 demand_empty_rest_of_line (); 1802} 1803 1804/* Handle the MRI IRP and IRPC pseudo-ops. */ 1805 1806void 1807s_irp (irpc) 1808 int irpc; 1809{ 1810 char *file; 1811 unsigned int line; 1812 sb s; 1813 const char *err; 1814 sb out; 1815 1816 as_where (&file, &line); 1817 1818 sb_new (&s); 1819 while (! is_end_of_line[(unsigned char) *input_line_pointer]) 1820 sb_add_char (&s, *input_line_pointer++); 1821 1822 sb_new (&out); 1823 1824 err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0'); 1825 if (err != NULL) 1826 as_bad_where (file, line, "%s", err); 1827 1828 sb_kill (&s); 1829 1830 input_scrub_include_sb (&out, input_line_pointer); 1831 sb_kill (&out); 1832 buffer_limit = input_scrub_next_buffer (&input_line_pointer); 1833} 1834 1835/* Handle the .linkonce pseudo-op. This tells the assembler to mark 1836 the section to only be linked once. However, this is not supported 1837 by most object file formats. This takes an optional argument, 1838 which is what to do about duplicates. */ 1839 1840void 1841s_linkonce (ignore) 1842 int ignore; 1843{ 1844 enum linkonce_type type; 1845 1846 SKIP_WHITESPACE (); 1847 1848 type = LINKONCE_DISCARD; 1849 1850 if (! is_end_of_line[(unsigned char) *input_line_pointer]) 1851 { 1852 char *s; 1853 char c; 1854 1855 s = input_line_pointer; 1856 c = get_symbol_end (); 1857 if (strcasecmp (s, "discard") == 0) 1858 type = LINKONCE_DISCARD; 1859 else if (strcasecmp (s, "one_only") == 0) 1860 type = LINKONCE_ONE_ONLY; 1861 else if (strcasecmp (s, "same_size") == 0) 1862 type = LINKONCE_SAME_SIZE; 1863 else if (strcasecmp (s, "same_contents") == 0) 1864 type = LINKONCE_SAME_CONTENTS; 1865 else 1866 as_warn ("unrecognized .linkonce type `%s'", s); 1867 1868 *input_line_pointer = c; 1869 } 1870 1871#ifdef obj_handle_link_once 1872 obj_handle_link_once (type); 1873#else /* ! defined (obj_handle_link_once) */ 1874#ifdef BFD_ASSEMBLER 1875 { 1876 flagword flags; 1877 1878 if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0) 1879 as_warn (".linkonce is not supported for this object file format"); 1880 1881 flags = bfd_get_section_flags (stdoutput, now_seg); 1882 flags |= SEC_LINK_ONCE; 1883 switch (type) 1884 { 1885 default: 1886 abort (); 1887 case LINKONCE_DISCARD: 1888 flags |= SEC_LINK_DUPLICATES_DISCARD; 1889 break; 1890 case LINKONCE_ONE_ONLY: 1891 flags |= SEC_LINK_DUPLICATES_ONE_ONLY; 1892 break; 1893 case LINKONCE_SAME_SIZE: 1894 flags |= SEC_LINK_DUPLICATES_SAME_SIZE; 1895 break; 1896 case LINKONCE_SAME_CONTENTS: 1897 flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS; 1898 break; 1899 } 1900 if (! bfd_set_section_flags (stdoutput, now_seg, flags)) 1901 as_bad ("bfd_set_section_flags: %s", 1902 bfd_errmsg (bfd_get_error ())); 1903 } 1904#else /* ! defined (BFD_ASSEMBLER) */ 1905 as_warn (".linkonce is not supported for this object file format"); 1906#endif /* ! defined (BFD_ASSEMBLER) */ 1907#endif /* ! defined (obj_handle_link_once) */ 1908 1909 demand_empty_rest_of_line (); 1910} 1911 1912static void 1913s_lcomm_internal (needs_align, bytes_p) 1914 /* 1 if this was a ".bss" directive, which may require a 3rd argument 1915 (alignment); 0 if it was an ".lcomm" (2 args only) */ 1916 int needs_align; 1917 /* 1 if the alignment value should be interpreted as the byte boundary, 1918 rather than the power of 2. */ 1919 int bytes_p; 1920{ 1921 register char *name; 1922 register char c; 1923 register char *p; 1924 register int temp; 1925 register symbolS *symbolP; 1926 segT current_seg = now_seg; 1927 subsegT current_subseg = now_subseg; 1928 const int max_alignment = 15; 1929 int align = 0; 1930 segT bss_seg = bss_section; 1931 1932 name = input_line_pointer; 1933 c = get_symbol_end (); 1934 p = input_line_pointer; 1935 *p = c; 1936 SKIP_WHITESPACE (); 1937 1938 /* Accept an optional comma after the name. The comma used to be 1939 required, but Irix 5 cc does not generate it. */ 1940 if (*input_line_pointer == ',') 1941 { 1942 ++input_line_pointer; 1943 SKIP_WHITESPACE (); 1944 } 1945 1946 if (*input_line_pointer == '\n') 1947 { 1948 as_bad ("Missing size expression"); 1949 return; 1950 } 1951 1952 if ((temp = get_absolute_expression ()) < 0) 1953 { 1954 as_warn ("BSS length (%d.) <0! Ignored.", temp); 1955 ignore_rest_of_line (); 1956 return; 1957 } 1958 1959#if defined (TC_MIPS) || defined (TC_ALPHA) 1960 if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour 1961 || OUTPUT_FLAVOR == bfd_target_elf_flavour) 1962 { 1963 /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */ 1964 if (temp <= bfd_get_gp_size (stdoutput)) 1965 { 1966 bss_seg = subseg_new (".sbss", 1); 1967 seg_info (bss_seg)->bss = 1; 1968#ifdef BFD_ASSEMBLER 1969 if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC)) 1970 as_warn ("error setting flags for \".sbss\": %s", 1971 bfd_errmsg (bfd_get_error ())); 1972#endif 1973 } 1974 } 1975#endif 1976 if (!needs_align) 1977 { 1978 /* FIXME. This needs to be machine independent. */ 1979 if (temp >= 8) 1980 align = 3; 1981 else if (temp >= 4) 1982 align = 2; 1983 else if (temp >= 2) 1984 align = 1; 1985 else 1986 align = 0; 1987 1988#ifdef OBJ_EVAX 1989 /* FIXME: This needs to be done in a more general fashion. */ 1990 align = 3; 1991#endif 1992 1993 record_alignment(bss_seg, align); 1994 } 1995 1996 if (needs_align) 1997 { 1998 align = 0; 1999 SKIP_WHITESPACE (); 2000 if (*input_line_pointer != ',') 2001 { 2002 as_bad ("Expected comma after size"); 2003 ignore_rest_of_line (); 2004 return; 2005 } 2006 input_line_pointer++; 2007 SKIP_WHITESPACE (); 2008 if (*input_line_pointer == '\n') 2009 { 2010 as_bad ("Missing alignment"); 2011 return; 2012 } 2013 align = get_absolute_expression (); 2014 if (bytes_p) 2015 { 2016 /* Convert to a power of 2. */ 2017 if (align != 0) 2018 { 2019 unsigned int i; 2020 2021 for (i = 0; (align & 1) == 0; align >>= 1, ++i) 2022 ; 2023 if (align != 1) 2024 as_bad ("Alignment not a power of 2"); 2025 align = i; 2026 } 2027 } 2028 if (align > max_alignment) 2029 { 2030 align = max_alignment; 2031 as_warn ("Alignment too large: %d. assumed.", align); 2032 } 2033 else if (align < 0) 2034 { 2035 align = 0; 2036 as_warn ("Alignment negative. 0 assumed."); 2037 } 2038 record_alignment (bss_seg, align); 2039 } /* if needs align */ 2040 else 2041 { 2042 /* Assume some objects may require alignment on some systems. */ 2043#if defined (TC_ALPHA) && ! defined (VMS) 2044 if (temp > 1) 2045 { 2046 align = ffs (temp) - 1; 2047 if (temp % (1 << align)) 2048 abort (); 2049 } 2050#endif 2051 } 2052 2053 *p = 0; 2054 symbolP = symbol_find_or_make (name); 2055 *p = c; 2056 2057 if ( 2058#if defined(OBJ_AOUT) | defined(OBJ_BOUT) 2059 S_GET_OTHER (symbolP) == 0 && 2060 S_GET_DESC (symbolP) == 0 && 2061#endif /* OBJ_AOUT or OBJ_BOUT */ 2062 (S_GET_SEGMENT (symbolP) == bss_seg 2063 || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0))) 2064 { 2065 char *pfrag; 2066 2067 subseg_set (bss_seg, 1); 2068 2069 if (align) 2070 frag_align (align, 0, 0); 2071 /* detach from old frag */ 2072 if (S_GET_SEGMENT (symbolP) == bss_seg) 2073 symbolP->sy_frag->fr_symbol = NULL; 2074 2075 symbolP->sy_frag = frag_now; 2076 pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, 2077 (offsetT) temp, (char *) 0); 2078 *pfrag = 0; 2079 2080 S_SET_SEGMENT (symbolP, bss_seg); 2081 2082#ifdef OBJ_COFF 2083 /* The symbol may already have been created with a preceding 2084 ".globl" directive -- be careful not to step on storage class 2085 in that case. Otherwise, set it to static. */ 2086 if (S_GET_STORAGE_CLASS (symbolP) != C_EXT) 2087 { 2088 S_SET_STORAGE_CLASS (symbolP, C_STAT); 2089 } 2090#endif /* OBJ_COFF */ 2091 2092#ifdef S_SET_SIZE 2093 S_SET_SIZE (symbolP, temp); 2094#endif 2095 } 2096 else 2097 as_bad ("Ignoring attempt to re-define symbol `%s'.", 2098 S_GET_NAME (symbolP)); 2099 2100 subseg_set (current_seg, current_subseg); 2101 2102 demand_empty_rest_of_line (); 2103} /* s_lcomm_internal() */ 2104 2105void 2106s_lcomm (needs_align) 2107 int needs_align; 2108{ 2109 s_lcomm_internal (needs_align, 0); 2110} 2111 2112void s_lcomm_bytes (needs_align) 2113 int needs_align; 2114{ 2115 s_lcomm_internal (needs_align, 1); 2116} 2117 2118void 2119s_lsym (ignore) 2120 int ignore; 2121{ 2122 register char *name; 2123 register char c; 2124 register char *p; 2125 expressionS exp; 2126 register symbolS *symbolP; 2127 2128 /* we permit ANY defined expression: BSD4.2 demands constants */ 2129 name = input_line_pointer; 2130 c = get_symbol_end (); 2131 p = input_line_pointer; 2132 *p = c; 2133 SKIP_WHITESPACE (); 2134 if (*input_line_pointer != ',') 2135 { 2136 *p = 0; 2137 as_bad ("Expected comma after name \"%s\"", name); 2138 *p = c; 2139 ignore_rest_of_line (); 2140 return; 2141 } 2142 input_line_pointer++; 2143 expression (&exp); 2144 if (exp.X_op != O_constant 2145 && exp.X_op != O_register) 2146 { 2147 as_bad ("bad expression"); 2148 ignore_rest_of_line (); 2149 return; 2150 } 2151 *p = 0; 2152 symbolP = symbol_find_or_make (name); 2153 2154 /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 && 2155 symbolP->sy_desc == 0) out of this test because coff doesn't have 2156 those fields, and I can't see when they'd ever be tripped. I 2157 don't think I understand why they were here so I may have 2158 introduced a bug. As recently as 1.37 didn't have this test 2159 anyway. xoxorich. */ 2160 2161 if (S_GET_SEGMENT (symbolP) == undefined_section 2162 && S_GET_VALUE (symbolP) == 0) 2163 { 2164 /* The name might be an undefined .global symbol; be sure to 2165 keep the "external" bit. */ 2166 S_SET_SEGMENT (symbolP, 2167 (exp.X_op == O_constant 2168 ? absolute_section 2169 : reg_section)); 2170 S_SET_VALUE (symbolP, (valueT) exp.X_add_number); 2171 } 2172 else 2173 { 2174 as_bad ("Symbol %s already defined", name); 2175 } 2176 *p = c; 2177 demand_empty_rest_of_line (); 2178} /* s_lsym() */ 2179 2180/* Read a line into an sb. */ 2181 2182static int 2183get_line_sb (line) 2184 sb *line; 2185{ 2186 char quote1, quote2, inquote; 2187 2188 if (input_line_pointer[-1] == '\n') 2189 bump_line_counters (); 2190 2191 if (input_line_pointer >= buffer_limit) 2192 { 2193 buffer_limit = input_scrub_next_buffer (&input_line_pointer); 2194 if (buffer_limit == 0) 2195 return 0; 2196 } 2197 2198 /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this 2199 code needs to be changed. */ 2200 if (! flag_m68k_mri) 2201 quote1 = '"'; 2202 else 2203 quote1 = '\0'; 2204 2205 quote2 = '\0'; 2206 if (flag_m68k_mri) 2207 quote2 = '\''; 2208#ifdef LEX_IS_STRINGQUOTE 2209 quote2 = '\''; 2210#endif 2211 2212 inquote = '\0'; 2213 while (! is_end_of_line[(unsigned char) *input_line_pointer] 2214 || (inquote != '\0' && *input_line_pointer != '\n')) 2215 { 2216 if (inquote == *input_line_pointer) 2217 inquote = '\0'; 2218 else if (inquote == '\0') 2219 { 2220 if (*input_line_pointer == quote1) 2221 inquote = quote1; 2222 else if (*input_line_pointer == quote2) 2223 inquote = quote2; 2224 } 2225 sb_add_char (line, *input_line_pointer++); 2226 } 2227 while (input_line_pointer < buffer_limit 2228 && is_end_of_line[(unsigned char) *input_line_pointer]) 2229 { 2230 if (input_line_pointer[-1] == '\n') 2231 bump_line_counters (); 2232 ++input_line_pointer; 2233 } 2234 return 1; 2235} 2236 2237/* Define a macro. This is an interface to macro.c, which is shared 2238 between gas and gasp. */ 2239 2240void 2241s_macro (ignore) 2242 int ignore; 2243{ 2244 char *file; 2245 unsigned int line; 2246 sb s; 2247 sb label; 2248 const char *err; 2249 const char *name; 2250 2251 as_where (&file, &line); 2252 2253 sb_new (&s); 2254 while (! is_end_of_line[(unsigned char) *input_line_pointer]) 2255 sb_add_char (&s, *input_line_pointer++); 2256 2257 sb_new (&label); 2258 if (line_label != NULL) 2259 sb_add_string (&label, S_GET_NAME (line_label)); 2260 2261 err = define_macro (0, &s, &label, get_line_sb, &name); 2262 if (err != NULL) 2263 as_bad_where (file, line, "%s", err); 2264 else 2265 { 2266 if (line_label != NULL) 2267 { 2268 S_SET_SEGMENT (line_label, undefined_section); 2269 S_SET_VALUE (line_label, 0); 2270 line_label->sy_frag = &zero_address_frag; 2271 } 2272 2273 if (((flag_m68k_mri 2274#ifdef NO_PSEUDO_DOT 2275 || 1 2276#endif 2277 ) 2278 && hash_find (po_hash, name) != NULL) 2279 || (! flag_m68k_mri 2280 && *name == '.' 2281 && hash_find (po_hash, name + 1) != NULL)) 2282 as_warn ("attempt to redefine pseudo-op `%s' ignored", 2283 name); 2284 } 2285 2286 sb_kill (&s); 2287} 2288 2289/* Handle the .mexit pseudo-op, which immediately exits a macro 2290 expansion. */ 2291 2292void 2293s_mexit (ignore) 2294 int ignore; 2295{ 2296 cond_exit_macro (macro_nest); 2297 buffer_limit = input_scrub_next_buffer (&input_line_pointer); 2298} 2299 2300/* Switch in and out of MRI mode. */ 2301 2302void 2303s_mri (ignore) 2304 int ignore; 2305{ 2306 int on, old_flag; 2307 2308 on = get_absolute_expression (); 2309 old_flag = flag_mri; 2310 if (on != 0) 2311 { 2312 flag_mri = 1; 2313#ifdef TC_M68K 2314 flag_m68k_mri = 1; 2315#endif 2316 } 2317 else 2318 { 2319 flag_mri = 0; 2320 flag_m68k_mri = 0; 2321 } 2322 2323#ifdef MRI_MODE_CHANGE 2324 if (on != old_flag) 2325 MRI_MODE_CHANGE (on); 2326#endif 2327 2328 demand_empty_rest_of_line (); 2329} 2330 2331/* Handle changing the location counter. */ 2332 2333static void 2334do_org (segment, exp, fill) 2335 segT segment; 2336 expressionS *exp; 2337 int fill; 2338{ 2339 if (segment != now_seg && segment != absolute_section) 2340 as_bad ("invalid segment \"%s\"; segment \"%s\" assumed", 2341 segment_name (segment), segment_name (now_seg)); 2342 2343 if (now_seg == absolute_section) 2344 { 2345 if (fill != 0) 2346 as_warn ("ignoring fill value in absolute section"); 2347 if (exp->X_op != O_constant) 2348 { 2349 as_bad ("only constant offsets supported in absolute section"); 2350 exp->X_add_number = 0; 2351 } 2352 abs_section_offset = exp->X_add_number; 2353 } 2354 else 2355 { 2356 char *p; 2357 2358 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol, 2359 exp->X_add_number, (char *) NULL); 2360 *p = fill; 2361 } 2362} 2363 2364void 2365s_org (ignore) 2366 int ignore; 2367{ 2368 register segT segment; 2369 expressionS exp; 2370 register long temp_fill; 2371 2372 /* The m68k MRI assembler has a different meaning for .org. It 2373 means to create an absolute section at a given address. We can't 2374 support that--use a linker script instead. */ 2375 if (flag_m68k_mri) 2376 { 2377 as_bad ("MRI style ORG pseudo-op not supported"); 2378 ignore_rest_of_line (); 2379 return; 2380 } 2381 2382 /* Don't believe the documentation of BSD 4.2 AS. There is no such 2383 thing as a sub-segment-relative origin. Any absolute origin is 2384 given a warning, then assumed to be segment-relative. Any 2385 segmented origin expression ("foo+42") had better be in the right 2386 segment or the .org is ignored. 2387 2388 BSD 4.2 AS warns if you try to .org backwards. We cannot because 2389 we never know sub-segment sizes when we are reading code. BSD 2390 will crash trying to emit negative numbers of filler bytes in 2391 certain .orgs. We don't crash, but see as-write for that code. 2392 2393 Don't make frag if need_pass_2==1. */ 2394 segment = get_known_segmented_expression (&exp); 2395 if (*input_line_pointer == ',') 2396 { 2397 input_line_pointer++; 2398 temp_fill = get_absolute_expression (); 2399 } 2400 else 2401 temp_fill = 0; 2402 2403 if (!need_pass_2) 2404 do_org (segment, &exp, temp_fill); 2405 2406 demand_empty_rest_of_line (); 2407} /* s_org() */ 2408 2409/* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be 2410 called by the obj-format routine which handles section changing 2411 when in MRI mode. It will create a new section, and return it. It 2412 will set *TYPE to the section type: one of 'C' (code), 'D' (data), 2413 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the 2414 flags will be set in the section. */ 2415 2416void 2417s_mri_sect (type) 2418 char *type; 2419{ 2420#ifdef TC_M68K 2421 2422 char *name; 2423 char c; 2424 segT seg; 2425 2426 SKIP_WHITESPACE (); 2427 2428 name = input_line_pointer; 2429 if (! isdigit ((unsigned char) *name)) 2430 c = get_symbol_end (); 2431 else 2432 { 2433 do 2434 { 2435 ++input_line_pointer; 2436 } 2437 while (isdigit ((unsigned char) *input_line_pointer)); 2438 c = *input_line_pointer; 2439 *input_line_pointer = '\0'; 2440 } 2441 2442 name = xstrdup (name); 2443 2444 *input_line_pointer = c; 2445 2446 seg = subseg_new (name, 0); 2447 2448 if (*input_line_pointer == ',') 2449 { 2450 int align; 2451 2452 ++input_line_pointer; 2453 align = get_absolute_expression (); 2454 record_alignment (seg, align); 2455 } 2456 2457 *type = 'C'; 2458 if (*input_line_pointer == ',') 2459 { 2460 c = *++input_line_pointer; 2461 c = toupper ((unsigned char) c); 2462 if (c == 'C' || c == 'D' || c == 'M' || c == 'R') 2463 *type = c; 2464 else 2465 as_bad ("unrecognized section type"); 2466 ++input_line_pointer; 2467 2468#ifdef BFD_ASSEMBLER 2469 { 2470 flagword flags; 2471 2472 flags = SEC_NO_FLAGS; 2473 if (*type == 'C') 2474 flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE; 2475 else if (*type == 'D' || *type == 'M') 2476 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA; 2477 else if (*type == 'R') 2478 flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM; 2479 if (flags != SEC_NO_FLAGS) 2480 { 2481 if (! bfd_set_section_flags (stdoutput, seg, flags)) 2482 as_warn ("error setting flags for \"%s\": %s", 2483 bfd_section_name (stdoutput, seg), 2484 bfd_errmsg (bfd_get_error ())); 2485 } 2486 } 2487#endif 2488 } 2489 2490 /* Ignore the HP type. */ 2491 if (*input_line_pointer == ',') 2492 input_line_pointer += 2; 2493 2494 demand_empty_rest_of_line (); 2495 2496#else /* ! TC_M68K */ 2497#ifdef TC_I960 2498 2499 char *name; 2500 char c; 2501 segT seg; 2502 2503 SKIP_WHITESPACE (); 2504 2505 name = input_line_pointer; 2506 c = get_symbol_end (); 2507 2508 name = xstrdup (name); 2509 2510 *input_line_pointer = c; 2511 2512 seg = subseg_new (name, 0); 2513 2514 if (*input_line_pointer != ',') 2515 *type = 'C'; 2516 else 2517 { 2518 char *sectype; 2519 2520 ++input_line_pointer; 2521 SKIP_WHITESPACE (); 2522 sectype = input_line_pointer; 2523 c = get_symbol_end (); 2524 if (*sectype == '\0') 2525 *type = 'C'; 2526 else if (strcasecmp (sectype, "text") == 0) 2527 *type = 'C'; 2528 else if (strcasecmp (sectype, "data") == 0) 2529 *type = 'D'; 2530 else if (strcasecmp (sectype, "romdata") == 0) 2531 *type = 'R'; 2532 else 2533 as_warn ("unrecognized section type `%s'", sectype); 2534 *input_line_pointer = c; 2535 } 2536 2537 if (*input_line_pointer == ',') 2538 { 2539 char *seccmd; 2540 2541 ++input_line_pointer; 2542 SKIP_WHITESPACE (); 2543 seccmd = input_line_pointer; 2544 c = get_symbol_end (); 2545 if (strcasecmp (seccmd, "absolute") == 0) 2546 { 2547 as_bad ("absolute sections are not supported"); 2548 *input_line_pointer = c; 2549 ignore_rest_of_line (); 2550 return; 2551 } 2552 else if (strcasecmp (seccmd, "align") == 0) 2553 { 2554 int align; 2555 2556 *input_line_pointer = c; 2557 align = get_absolute_expression (); 2558 record_alignment (seg, align); 2559 } 2560 else 2561 { 2562 as_warn ("unrecognized section command `%s'", seccmd); 2563 *input_line_pointer = c; 2564 } 2565 } 2566 2567 demand_empty_rest_of_line (); 2568 2569#else /* ! TC_I960 */ 2570 /* The MRI assembler seems to use different forms of .sect for 2571 different targets. */ 2572 abort (); 2573#endif /* ! TC_I960 */ 2574#endif /* ! TC_M68K */ 2575} 2576 2577/* Handle the .print pseudo-op. */ 2578 2579void 2580s_print (ignore) 2581 int ignore; 2582{ 2583 char *s; 2584 int len; 2585 2586 s = demand_copy_C_string (&len); 2587 printf ("%s\n", s); 2588 demand_empty_rest_of_line (); 2589} 2590 2591/* Handle the .purgem pseudo-op. */ 2592 2593void 2594s_purgem (ignore) 2595 int ignore; 2596{ 2597 if (is_it_end_of_statement ()) 2598 { 2599 demand_empty_rest_of_line (); 2600 return; 2601 } 2602 2603 do 2604 { 2605 char *name; 2606 char c; 2607 2608 SKIP_WHITESPACE (); 2609 name = input_line_pointer; 2610 c = get_symbol_end (); 2611 delete_macro (name); 2612 *input_line_pointer = c; 2613 SKIP_WHITESPACE (); 2614 } 2615 while (*input_line_pointer++ == ','); 2616 2617 --input_line_pointer; 2618 demand_empty_rest_of_line (); 2619} 2620 2621/* Handle the .rept pseudo-op. */ 2622 2623void 2624s_rept (ignore) 2625 int ignore; 2626{ 2627 int count; 2628 sb one; 2629 sb many; 2630 2631 count = get_absolute_expression (); 2632 2633 sb_new (&one); 2634 if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb)) 2635 { 2636 as_bad ("rept without endr"); 2637 return; 2638 } 2639 2640 sb_new (&many); 2641 while (count-- > 0) 2642 sb_add_sb (&many, &one); 2643 2644 sb_kill (&one); 2645 2646 input_scrub_include_sb (&many, input_line_pointer); 2647 sb_kill (&many); 2648 buffer_limit = input_scrub_next_buffer (&input_line_pointer); 2649} 2650 2651/* Handle the .equ, .equiv and .set directives. If EQUIV is 1, then 2652 this is .equiv, and it is an error if the symbol is already 2653 defined. */ 2654 2655void 2656s_set (equiv) 2657 int equiv; 2658{ 2659 register char *name; 2660 register char delim; 2661 register char *end_name; 2662 register symbolS *symbolP; 2663 2664 /* 2665 * Especial apologies for the random logic: 2666 * this just grew, and could be parsed much more simply! 2667 * Dean in haste. 2668 */ 2669 name = input_line_pointer; 2670 delim = get_symbol_end (); 2671 end_name = input_line_pointer; 2672 *end_name = delim; 2673 SKIP_WHITESPACE (); 2674 2675 if (*input_line_pointer != ',') 2676 { 2677 *end_name = 0; 2678 as_bad ("Expected comma after name \"%s\"", name); 2679 *end_name = delim; 2680 ignore_rest_of_line (); 2681 return; 2682 } 2683 2684 input_line_pointer++; 2685 *end_name = 0; 2686 2687 if (name[0] == '.' && name[1] == '\0') 2688 { 2689 /* Turn '. = mumble' into a .org mumble */ 2690 register segT segment; 2691 expressionS exp; 2692 2693 segment = get_known_segmented_expression (&exp); 2694 2695 if (!need_pass_2) 2696 do_org (segment, &exp, 0); 2697 2698 *end_name = delim; 2699 return; 2700 } 2701 2702 if ((symbolP = symbol_find (name)) == NULL 2703 && (symbolP = md_undefined_symbol (name)) == NULL) 2704 { 2705#ifndef NO_LISTING 2706 /* When doing symbol listings, play games with dummy fragments living 2707 outside the normal fragment chain to record the file and line info 2708 for this symbol. */ 2709 if (listing & LISTING_SYMBOLS) 2710 { 2711 extern struct list_info_struct *listing_tail; 2712 fragS *dummy_frag = (fragS *) xmalloc (sizeof(fragS)); 2713 memset (dummy_frag, 0, sizeof(fragS)); 2714 dummy_frag->fr_type = rs_fill; 2715 dummy_frag->line = listing_tail; 2716 symbolP = symbol_new (name, undefined_section, 0, dummy_frag); 2717 dummy_frag->fr_symbol = symbolP; 2718 } 2719 else 2720#endif 2721 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); 2722 2723#ifdef OBJ_COFF 2724 /* "set" symbols are local unless otherwise specified. */ 2725 SF_SET_LOCAL (symbolP); 2726#endif /* OBJ_COFF */ 2727 2728 } /* make a new symbol */ 2729 2730 symbol_table_insert (symbolP); 2731 2732 *end_name = delim; 2733 2734 if (equiv 2735 && S_IS_DEFINED (symbolP) 2736 && S_GET_SEGMENT (symbolP) != reg_section) 2737 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP)); 2738 2739 pseudo_set (symbolP); 2740 demand_empty_rest_of_line (); 2741} /* s_set() */ 2742 2743void 2744s_space (mult) 2745 int mult; 2746{ 2747 expressionS exp; 2748 expressionS val; 2749 char *p = 0; 2750 char *stop = NULL; 2751 char stopc; 2752 int bytes; 2753 2754#ifdef md_flush_pending_output 2755 md_flush_pending_output (); 2756#endif 2757 2758 if (flag_mri) 2759 stop = mri_comment_field (&stopc); 2760 2761 /* In m68k MRI mode, we need to align to a word boundary, unless 2762 this is ds.b. */ 2763 if (flag_m68k_mri && mult > 1) 2764 { 2765 if (now_seg == absolute_section) 2766 { 2767 abs_section_offset += abs_section_offset & 1; 2768 if (line_label != NULL) 2769 S_SET_VALUE (line_label, abs_section_offset); 2770 } 2771 else if (mri_common_symbol != NULL) 2772 { 2773 valueT val; 2774 2775 val = S_GET_VALUE (mri_common_symbol); 2776 if ((val & 1) != 0) 2777 { 2778 S_SET_VALUE (mri_common_symbol, val + 1); 2779 if (line_label != NULL) 2780 { 2781 know (line_label->sy_value.X_op == O_symbol); 2782 know (line_label->sy_value.X_add_symbol == mri_common_symbol); 2783 line_label->sy_value.X_add_number += 1; 2784 } 2785 } 2786 } 2787 else 2788 { 2789 do_align (1, (char *) NULL, 0, 0); 2790 if (line_label != NULL) 2791 { 2792 line_label->sy_frag = frag_now; 2793 S_SET_VALUE (line_label, frag_now_fix ()); 2794 } 2795 } 2796 } 2797 2798 bytes = mult; 2799 2800 expression (&exp); 2801 2802 SKIP_WHITESPACE (); 2803 if (*input_line_pointer == ',') 2804 { 2805 ++input_line_pointer; 2806 expression (&val); 2807 } 2808 else 2809 { 2810 val.X_op = O_constant; 2811 val.X_add_number = 0; 2812 } 2813 2814 if (val.X_op != O_constant 2815 || val.X_add_number < - 0x80 2816 || val.X_add_number > 0xff 2817 || (mult != 0 && mult != 1 && val.X_add_number != 0)) 2818 { 2819 if (exp.X_op != O_constant) 2820 as_bad ("Unsupported variable size or fill value"); 2821 else 2822 { 2823 offsetT i; 2824 2825 if (mult == 0) 2826 mult = 1; 2827 bytes = mult * exp.X_add_number; 2828 for (i = 0; i < exp.X_add_number; i++) 2829 emit_expr (&val, mult); 2830 } 2831 } 2832 else 2833 { 2834 if (exp.X_op == O_constant) 2835 { 2836 long repeat; 2837 2838 repeat = exp.X_add_number; 2839 if (mult) 2840 repeat *= mult; 2841 bytes = repeat; 2842 if (repeat <= 0) 2843 { 2844 if (! flag_mri || repeat < 0) 2845 as_warn (".space repeat count is %s, ignored", 2846 repeat ? "negative" : "zero"); 2847 goto getout; 2848 } 2849 2850 /* If we are in the absolute section, just bump the offset. */ 2851 if (now_seg == absolute_section) 2852 { 2853 abs_section_offset += repeat; 2854 goto getout; 2855 } 2856 2857 /* If we are secretly in an MRI common section, then 2858 creating space just increases the size of the common 2859 symbol. */ 2860 if (mri_common_symbol != NULL) 2861 { 2862 S_SET_VALUE (mri_common_symbol, 2863 S_GET_VALUE (mri_common_symbol) + repeat); 2864 goto getout; 2865 } 2866 2867 if (!need_pass_2) 2868 p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, 2869 (offsetT) repeat, (char *) 0); 2870 } 2871 else 2872 { 2873 if (now_seg == absolute_section) 2874 { 2875 as_bad ("space allocation too complex in absolute section"); 2876 subseg_set (text_section, 0); 2877 } 2878 if (mri_common_symbol != NULL) 2879 { 2880 as_bad ("space allocation too complex in common section"); 2881 mri_common_symbol = NULL; 2882 } 2883 if (!need_pass_2) 2884 p = frag_var (rs_space, 1, 1, (relax_substateT) 0, 2885 make_expr_symbol (&exp), (offsetT) 0, (char *) 0); 2886 } 2887 2888 if (p) 2889 *p = val.X_add_number; 2890 } 2891 2892 getout: 2893 2894 /* In MRI mode, after an odd number of bytes, we must align to an 2895 even word boundary, unless the next instruction is a dc.b, ds.b 2896 or dcb.b. */ 2897 if (flag_mri && (bytes & 1) != 0) 2898 mri_pending_align = 1; 2899 2900 if (flag_mri) 2901 mri_comment_end (stop, stopc); 2902 2903 demand_empty_rest_of_line (); 2904} 2905 2906/* This is like s_space, but the value is a floating point number with 2907 the given precision. This is for the MRI dcb.s pseudo-op and 2908 friends. */ 2909 2910void 2911s_float_space (float_type) 2912 int float_type; 2913{ 2914 offsetT count; 2915 int flen; 2916 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; 2917 char *stop = NULL; 2918 char stopc; 2919 2920 if (flag_mri) 2921 stop = mri_comment_field (&stopc); 2922 2923 count = get_absolute_expression (); 2924 2925 SKIP_WHITESPACE (); 2926 if (*input_line_pointer != ',') 2927 { 2928 as_bad ("missing value"); 2929 if (flag_mri) 2930 mri_comment_end (stop, stopc); 2931 ignore_rest_of_line (); 2932 return; 2933 } 2934 2935 ++input_line_pointer; 2936 2937 SKIP_WHITESPACE (); 2938 2939 /* Skip any 0{letter} that may be present. Don't even check if the 2940 * letter is legal. */ 2941 if (input_line_pointer[0] == '0' 2942 && isalpha ((unsigned char) input_line_pointer[1])) 2943 input_line_pointer += 2; 2944 2945 /* Accept :xxxx, where the x's are hex digits, for a floating point 2946 with the exact digits specified. */ 2947 if (input_line_pointer[0] == ':') 2948 { 2949 flen = hex_float (float_type, temp); 2950 if (flen < 0) 2951 { 2952 if (flag_mri) 2953 mri_comment_end (stop, stopc); 2954 ignore_rest_of_line (); 2955 return; 2956 } 2957 } 2958 else 2959 { 2960 char *err; 2961 2962 err = md_atof (float_type, temp, &flen); 2963 know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); 2964 know (flen > 0); 2965 if (err) 2966 { 2967 as_bad ("Bad floating literal: %s", err); 2968 if (flag_mri) 2969 mri_comment_end (stop, stopc); 2970 ignore_rest_of_line (); 2971 return; 2972 } 2973 } 2974 2975 while (--count >= 0) 2976 { 2977 char *p; 2978 2979 p = frag_more (flen); 2980 memcpy (p, temp, (unsigned int) flen); 2981 } 2982 2983 if (flag_mri) 2984 mri_comment_end (stop, stopc); 2985 2986 demand_empty_rest_of_line (); 2987} 2988 2989/* Handle the .struct pseudo-op, as found in MIPS assemblers. */ 2990 2991void 2992s_struct (ignore) 2993 int ignore; 2994{ 2995 char *stop = NULL; 2996 char stopc; 2997 2998 if (flag_mri) 2999 stop = mri_comment_field (&stopc); 3000 abs_section_offset = get_absolute_expression (); 3001 subseg_set (absolute_section, 0); 3002 if (flag_mri) 3003 mri_comment_end (stop, stopc); 3004 demand_empty_rest_of_line (); 3005} 3006 3007void 3008s_text (ignore) 3009 int ignore; 3010{ 3011 register int temp; 3012 3013 temp = get_absolute_expression (); 3014 subseg_set (text_section, (subsegT) temp); 3015 demand_empty_rest_of_line (); 3016#ifdef OBJ_VMS 3017 const_flag &= ~IN_DEFAULT_SECTION; 3018#endif 3019} /* s_text() */ 3020 3021 3022void 3023demand_empty_rest_of_line () 3024{ 3025 SKIP_WHITESPACE (); 3026 if (is_end_of_line[(unsigned char) *input_line_pointer]) 3027 { 3028 input_line_pointer++; 3029 } 3030 else 3031 { 3032 ignore_rest_of_line (); 3033 } 3034 /* Return having already swallowed end-of-line. */ 3035} /* Return pointing just after end-of-line. */ 3036 3037void 3038ignore_rest_of_line () /* For suspect lines: gives warning. */ 3039{ 3040 if (!is_end_of_line[(unsigned char) *input_line_pointer]) 3041 { 3042 if (isprint ((unsigned char) *input_line_pointer)) 3043 as_bad ("Rest of line ignored. First ignored character is `%c'.", 3044 *input_line_pointer); 3045 else 3046 as_bad ("Rest of line ignored. First ignored character valued 0x%x.", 3047 *input_line_pointer); 3048 while (input_line_pointer < buffer_limit 3049 && !is_end_of_line[(unsigned char) *input_line_pointer]) 3050 { 3051 input_line_pointer++; 3052 } 3053 } 3054 input_line_pointer++; /* Return pointing just after end-of-line. */ 3055 know (is_end_of_line[(unsigned char) input_line_pointer[-1]]); 3056} 3057 3058/* 3059 * pseudo_set() 3060 * 3061 * In: Pointer to a symbol. 3062 * Input_line_pointer->expression. 3063 * 3064 * Out: Input_line_pointer->just after any whitespace after expression. 3065 * Tried to set symbol to value of expression. 3066 * Will change symbols type, value, and frag; 3067 */ 3068void 3069pseudo_set (symbolP) 3070 symbolS *symbolP; 3071{ 3072 expressionS exp; 3073#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) 3074 int ext; 3075#endif /* OBJ_AOUT or OBJ_BOUT */ 3076 3077 know (symbolP); /* NULL pointer is logic error. */ 3078#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) 3079 ext = S_IS_EXTERNAL (symbolP); 3080#endif /* OBJ_AOUT or OBJ_BOUT */ 3081 3082 (void) expression (&exp); 3083 3084 if (exp.X_op == O_illegal) 3085 as_bad ("illegal expression; zero assumed"); 3086 else if (exp.X_op == O_absent) 3087 as_bad ("missing expression; zero assumed"); 3088 else if (exp.X_op == O_big) 3089 as_bad ("%s number invalid; zero assumed", 3090 exp.X_add_number > 0 ? "bignum" : "floating point"); 3091 else if (exp.X_op == O_subtract 3092 && (S_GET_SEGMENT (exp.X_add_symbol) 3093 == S_GET_SEGMENT (exp.X_op_symbol)) 3094 && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol)) 3095 && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag) 3096 { 3097 exp.X_op = O_constant; 3098 exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol) 3099 - S_GET_VALUE (exp.X_op_symbol)); 3100 } 3101 3102 switch (exp.X_op) 3103 { 3104 case O_illegal: 3105 case O_absent: 3106 case O_big: 3107 exp.X_add_number = 0; 3108 /* Fall through. */ 3109 case O_constant: 3110 S_SET_SEGMENT (symbolP, absolute_section); 3111#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) 3112 if (ext) 3113 S_SET_EXTERNAL (symbolP); 3114 else 3115 S_CLEAR_EXTERNAL (symbolP); 3116#endif /* OBJ_AOUT or OBJ_BOUT */ 3117 S_SET_VALUE (symbolP, (valueT) exp.X_add_number); 3118 if (exp.X_op != O_constant) 3119 symbolP->sy_frag = &zero_address_frag; 3120 break; 3121 3122 case O_register: 3123 S_SET_SEGMENT (symbolP, reg_section); 3124 S_SET_VALUE (symbolP, (valueT) exp.X_add_number); 3125 symbolP->sy_frag = &zero_address_frag; 3126 break; 3127 3128 case O_symbol: 3129 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section 3130 || exp.X_add_number != 0) 3131 symbolP->sy_value = exp; 3132 else 3133 { 3134 symbolS *s = exp.X_add_symbol; 3135 3136 S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s)); 3137#if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) 3138 if (ext) 3139 S_SET_EXTERNAL (symbolP); 3140 else 3141 S_CLEAR_EXTERNAL (symbolP); 3142#endif /* OBJ_AOUT or OBJ_BOUT */ 3143 S_SET_VALUE (symbolP, 3144 exp.X_add_number + S_GET_VALUE (s)); 3145 symbolP->sy_frag = s->sy_frag; 3146 copy_symbol_attributes (symbolP, s); 3147 } 3148 break; 3149 3150 default: 3151 /* The value is some complex expression. 3152 FIXME: Should we set the segment to anything? */ 3153 symbolP->sy_value = exp; 3154 break; 3155 } 3156} 3157 3158/* 3159 * cons() 3160 * 3161 * CONStruct more frag of .bytes, or .words etc. 3162 * Should need_pass_2 be 1 then emit no frag(s). 3163 * This understands EXPRESSIONS. 3164 * 3165 * Bug (?) 3166 * 3167 * This has a split personality. We use expression() to read the 3168 * value. We can detect if the value won't fit in a byte or word. 3169 * But we can't detect if expression() discarded significant digits 3170 * in the case of a long. Not worth the crocks required to fix it. 3171 */ 3172 3173/* Select a parser for cons expressions. */ 3174 3175/* Some targets need to parse the expression in various fancy ways. 3176 You can define TC_PARSE_CONS_EXPRESSION to do whatever you like 3177 (for example, the HPPA does this). Otherwise, you can define 3178 BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or 3179 REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these 3180 are defined, which is the normal case, then only simple expressions 3181 are permitted. */ 3182 3183static void 3184parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes)); 3185 3186#ifndef TC_PARSE_CONS_EXPRESSION 3187#ifdef BITFIELD_CONS_EXPRESSIONS 3188#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES) 3189static void 3190parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes)); 3191#endif 3192#ifdef REPEAT_CONS_EXPRESSIONS 3193#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES) 3194static void 3195parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes)); 3196#endif 3197 3198/* If we haven't gotten one yet, just call expression. */ 3199#ifndef TC_PARSE_CONS_EXPRESSION 3200#define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP) 3201#endif 3202#endif 3203 3204/* worker to do .byte etc statements */ 3205/* clobbers input_line_pointer, checks */ 3206/* end-of-line. */ 3207static void 3208cons_worker (nbytes, rva) 3209 register int nbytes; /* 1=.byte, 2=.word, 4=.long */ 3210 int rva; 3211{ 3212 int c; 3213 expressionS exp; 3214 char *stop = NULL; 3215 char stopc; 3216 3217#ifdef md_flush_pending_output 3218 md_flush_pending_output (); 3219#endif 3220 3221 if (flag_mri) 3222 stop = mri_comment_field (&stopc); 3223 3224 if (is_it_end_of_statement ()) 3225 { 3226 if (flag_mri) 3227 mri_comment_end (stop, stopc); 3228 demand_empty_rest_of_line (); 3229 return; 3230 } 3231 3232#ifdef md_cons_align 3233 md_cons_align (nbytes); 3234#endif 3235 3236 c = 0; 3237 do 3238 { 3239 if (flag_m68k_mri) 3240 parse_mri_cons (&exp, (unsigned int) nbytes); 3241 else 3242 TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes); 3243 3244 if (rva) 3245 { 3246 if (exp.X_op == O_symbol) 3247 exp.X_op = O_symbol_rva; 3248 else 3249 as_fatal ("rva without symbol"); 3250 } 3251 emit_expr (&exp, (unsigned int) nbytes); 3252 ++c; 3253 } 3254 while (*input_line_pointer++ == ','); 3255 3256 /* In MRI mode, after an odd number of bytes, we must align to an 3257 even word boundary, unless the next instruction is a dc.b, ds.b 3258 or dcb.b. */ 3259 if (flag_mri && nbytes == 1 && (c & 1) != 0) 3260 mri_pending_align = 1; 3261 3262 input_line_pointer--; /* Put terminator back into stream. */ 3263 3264 if (flag_mri) 3265 mri_comment_end (stop, stopc); 3266 3267 demand_empty_rest_of_line (); 3268} 3269 3270 3271void 3272cons (size) 3273 int size; 3274{ 3275 cons_worker (size, 0); 3276} 3277 3278void 3279s_rva (size) 3280 int size; 3281{ 3282 cons_worker (size, 1); 3283} 3284 3285/* Put the contents of expression EXP into the object file using 3286 NBYTES bytes. If need_pass_2 is 1, this does nothing. */ 3287 3288void 3289emit_expr (exp, nbytes) 3290 expressionS *exp; 3291 unsigned int nbytes; 3292{ 3293 operatorT op; 3294 register char *p; 3295 valueT extra_digit = 0; 3296 3297 /* Don't do anything if we are going to make another pass. */ 3298 if (need_pass_2) 3299 return; 3300 3301#ifndef NO_LISTING 3302#ifdef OBJ_ELF 3303 /* When gcc emits DWARF 1 debugging pseudo-ops, a line number will 3304 appear as a four byte positive constant in the .line section, 3305 followed by a 2 byte 0xffff. Look for that case here. */ 3306 { 3307 static int dwarf_line = -1; 3308 3309 if (strcmp (segment_name (now_seg), ".line") != 0) 3310 dwarf_line = -1; 3311 else if (dwarf_line >= 0 3312 && nbytes == 2 3313 && exp->X_op == O_constant 3314 && (exp->X_add_number == -1 || exp->X_add_number == 0xffff)) 3315 listing_source_line ((unsigned int) dwarf_line); 3316 else if (nbytes == 4 3317 && exp->X_op == O_constant 3318 && exp->X_add_number >= 0) 3319 dwarf_line = exp->X_add_number; 3320 else 3321 dwarf_line = -1; 3322 } 3323 3324 /* When gcc emits DWARF 1 debugging pseudo-ops, a file name will 3325 appear as a 2 byte TAG_compile_unit (0x11) followed by a 2 byte 3326 AT_sibling (0x12) followed by a four byte address of the sibling 3327 followed by a 2 byte AT_name (0x38) followed by the name of the 3328 file. We look for that case here. */ 3329 { 3330 static int dwarf_file = 0; 3331 3332 if (strcmp (segment_name (now_seg), ".debug") != 0) 3333 dwarf_file = 0; 3334 else if (dwarf_file == 0 3335 && nbytes == 2 3336 && exp->X_op == O_constant 3337 && exp->X_add_number == 0x11) 3338 dwarf_file = 1; 3339 else if (dwarf_file == 1 3340 && nbytes == 2 3341 && exp->X_op == O_constant 3342 && exp->X_add_number == 0x12) 3343 dwarf_file = 2; 3344 else if (dwarf_file == 2 3345 && nbytes == 4) 3346 dwarf_file = 3; 3347 else if (dwarf_file == 3 3348 && nbytes == 2 3349 && exp->X_op == O_constant 3350 && exp->X_add_number == 0x38) 3351 dwarf_file = 4; 3352 else 3353 dwarf_file = 0; 3354 3355 /* The variable dwarf_file_string tells stringer that the string 3356 may be the name of the source file. */ 3357 if (dwarf_file == 4) 3358 dwarf_file_string = 1; 3359 else 3360 dwarf_file_string = 0; 3361 } 3362#endif 3363#endif 3364 3365 if (check_eh_frame (exp, &nbytes)) 3366 return; 3367 3368 op = exp->X_op; 3369 3370 /* Allow `.word 0' in the absolute section. */ 3371 if (now_seg == absolute_section) 3372 { 3373 if (op != O_constant || exp->X_add_number != 0) 3374 as_bad ("attempt to store value in absolute section"); 3375 abs_section_offset += nbytes; 3376 return; 3377 } 3378 3379 /* Handle a negative bignum. */ 3380 if (op == O_uminus 3381 && exp->X_add_number == 0 3382 && exp->X_add_symbol->sy_value.X_op == O_big 3383 && exp->X_add_symbol->sy_value.X_add_number > 0) 3384 { 3385 int i; 3386 unsigned long carry; 3387 3388 exp = &exp->X_add_symbol->sy_value; 3389 3390 /* Negate the bignum: one's complement each digit and add 1. */ 3391 carry = 1; 3392 for (i = 0; i < exp->X_add_number; i++) 3393 { 3394 unsigned long next; 3395 3396 next = (((~ (generic_bignum[i] & LITTLENUM_MASK)) 3397 & LITTLENUM_MASK) 3398 + carry); 3399 generic_bignum[i] = next & LITTLENUM_MASK; 3400 carry = next >> LITTLENUM_NUMBER_OF_BITS; 3401 } 3402 3403 /* We can ignore any carry out, because it will be handled by 3404 extra_digit if it is needed. */ 3405 3406 extra_digit = (valueT) -1; 3407 op = O_big; 3408 } 3409 3410 if (op == O_absent || op == O_illegal) 3411 { 3412 as_warn ("zero assumed for missing expression"); 3413 exp->X_add_number = 0; 3414 op = O_constant; 3415 } 3416 else if (op == O_big && exp->X_add_number <= 0) 3417 { 3418 as_bad ("floating point number invalid; zero assumed"); 3419 exp->X_add_number = 0; 3420 op = O_constant; 3421 } 3422 else if (op == O_register) 3423 { 3424 as_warn ("register value used as expression"); 3425 op = O_constant; 3426 } 3427 3428 p = frag_more ((int) nbytes); 3429 3430#ifndef WORKING_DOT_WORD 3431 /* If we have the difference of two symbols in a word, save it on 3432 the broken_words list. See the code in write.c. */ 3433 if (op == O_subtract && nbytes == 2) 3434 { 3435 struct broken_word *x; 3436 3437 x = (struct broken_word *) xmalloc (sizeof (struct broken_word)); 3438 x->next_broken_word = broken_words; 3439 broken_words = x; 3440 x->frag = frag_now; 3441 x->word_goes_here = p; 3442 x->dispfrag = 0; 3443 x->add = exp->X_add_symbol; 3444 x->sub = exp->X_op_symbol; 3445 x->addnum = exp->X_add_number; 3446 x->added = 0; 3447 new_broken_words++; 3448 return; 3449 } 3450#endif 3451 3452 /* If we have an integer, but the number of bytes is too large to 3453 pass to md_number_to_chars, handle it as a bignum. */ 3454 if (op == O_constant && nbytes > sizeof (valueT)) 3455 { 3456 valueT val; 3457 int gencnt; 3458 3459 if (! exp->X_unsigned && exp->X_add_number < 0) 3460 extra_digit = (valueT) -1; 3461 val = (valueT) exp->X_add_number; 3462 gencnt = 0; 3463 do 3464 { 3465 generic_bignum[gencnt] = val & LITTLENUM_MASK; 3466 val >>= LITTLENUM_NUMBER_OF_BITS; 3467 ++gencnt; 3468 } 3469 while (val != 0); 3470 op = exp->X_op = O_big; 3471 exp->X_add_number = gencnt; 3472 } 3473 3474 if (op == O_constant) 3475 { 3476 register valueT get; 3477 register valueT use; 3478 register valueT mask; 3479 valueT hibit; 3480 register valueT unmask; 3481 3482 /* JF << of >= number of bits in the object is undefined. In 3483 particular SPARC (Sun 4) has problems */ 3484 if (nbytes >= sizeof (valueT)) 3485 { 3486 mask = 0; 3487 if (nbytes > sizeof (valueT)) 3488 hibit = 0; 3489 else 3490 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); 3491 } 3492 else 3493 { 3494 /* Don't store these bits. */ 3495 mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); 3496 hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); 3497 } 3498 3499 unmask = ~mask; /* Do store these bits. */ 3500 3501#ifdef NEVER 3502 "Do this mod if you want every overflow check to assume SIGNED 2's complement data."; 3503 mask = ~(unmask >> 1); /* Includes sign bit now. */ 3504#endif 3505 3506 get = exp->X_add_number; 3507 use = get & unmask; 3508 if ((get & mask) != 0 3509 && ((get & mask) != mask 3510 || (get & hibit) == 0)) 3511 { /* Leading bits contain both 0s & 1s. */ 3512 as_warn ("Value 0x%lx truncated to 0x%lx.", 3513 (unsigned long) get, (unsigned long) use); 3514 } 3515 /* put bytes in right order. */ 3516 md_number_to_chars (p, use, (int) nbytes); 3517 } 3518 else if (op == O_big) 3519 { 3520 unsigned int size; 3521 LITTLENUM_TYPE *nums; 3522 3523 know (nbytes % CHARS_PER_LITTLENUM == 0); 3524 3525 size = exp->X_add_number * CHARS_PER_LITTLENUM; 3526 if (nbytes < size) 3527 { 3528 as_warn ("Bignum truncated to %d bytes", nbytes); 3529 size = nbytes; 3530 } 3531 3532 if (target_big_endian) 3533 { 3534 while (nbytes > size) 3535 { 3536 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); 3537 nbytes -= CHARS_PER_LITTLENUM; 3538 p += CHARS_PER_LITTLENUM; 3539 } 3540 3541 nums = generic_bignum + size / CHARS_PER_LITTLENUM; 3542 while (size > 0) 3543 { 3544 --nums; 3545 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); 3546 size -= CHARS_PER_LITTLENUM; 3547 p += CHARS_PER_LITTLENUM; 3548 } 3549 } 3550 else 3551 { 3552 nums = generic_bignum; 3553 while (size > 0) 3554 { 3555 md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); 3556 ++nums; 3557 size -= CHARS_PER_LITTLENUM; 3558 p += CHARS_PER_LITTLENUM; 3559 nbytes -= CHARS_PER_LITTLENUM; 3560 } 3561 3562 while (nbytes > 0) 3563 { 3564 md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); 3565 nbytes -= CHARS_PER_LITTLENUM; 3566 p += CHARS_PER_LITTLENUM; 3567 } 3568 } 3569 } 3570 else 3571 { 3572 memset (p, 0, nbytes); 3573 3574 /* Now we need to generate a fixS to record the symbol value. 3575 This is easy for BFD. For other targets it can be more 3576 complex. For very complex cases (currently, the HPPA and 3577 NS32K), you can define TC_CONS_FIX_NEW to do whatever you 3578 want. For simpler cases, you can define TC_CONS_RELOC to be 3579 the name of the reloc code that should be stored in the fixS. 3580 If neither is defined, the code uses NO_RELOC if it is 3581 defined, and otherwise uses 0. */ 3582 3583#ifdef BFD_ASSEMBLER 3584#ifdef TC_CONS_FIX_NEW 3585 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); 3586#else 3587 { 3588 bfd_reloc_code_real_type r; 3589 3590 switch (nbytes) 3591 { 3592 case 1: 3593 r = BFD_RELOC_8; 3594 break; 3595 case 2: 3596 r = BFD_RELOC_16; 3597 break; 3598 case 4: 3599 r = BFD_RELOC_32; 3600 break; 3601 case 8: 3602 r = BFD_RELOC_64; 3603 break; 3604 default: 3605 as_bad ("unsupported BFD relocation size %u", nbytes); 3606 r = BFD_RELOC_32; 3607 break; 3608 } 3609 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 3610 0, r); 3611 } 3612#endif 3613#else 3614#ifdef TC_CONS_FIX_NEW 3615 TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); 3616#else 3617 /* Figure out which reloc number to use. Use TC_CONS_RELOC if 3618 it is defined, otherwise use NO_RELOC if it is defined, 3619 otherwise use 0. */ 3620#ifndef TC_CONS_RELOC 3621#ifdef NO_RELOC 3622#define TC_CONS_RELOC NO_RELOC 3623#else 3624#define TC_CONS_RELOC 0 3625#endif 3626#endif 3627 fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, 3628 TC_CONS_RELOC); 3629#endif /* TC_CONS_FIX_NEW */ 3630#endif /* BFD_ASSEMBLER */ 3631 } 3632} 3633 3634#ifdef BITFIELD_CONS_EXPRESSIONS 3635 3636/* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as 3637 w:x,y:z, where w and y are bitwidths and x and y are values. They 3638 then pack them all together. We do a little better in that we allow 3639 them in words, longs, etc. and we'll pack them in target byte order 3640 for you. 3641 3642 The rules are: pack least significat bit first, if a field doesn't 3643 entirely fit, put it in the next unit. Overflowing the bitfield is 3644 explicitly *not* even a warning. The bitwidth should be considered 3645 a "mask". 3646 3647 To use this function the tc-XXX.h file should define 3648 BITFIELD_CONS_EXPRESSIONS. */ 3649 3650static void 3651parse_bitfield_cons (exp, nbytes) 3652 expressionS *exp; 3653 unsigned int nbytes; 3654{ 3655 unsigned int bits_available = BITS_PER_CHAR * nbytes; 3656 char *hold = input_line_pointer; 3657 3658 (void) expression (exp); 3659 3660 if (*input_line_pointer == ':') 3661 { /* bitfields */ 3662 long value = 0; 3663 3664 for (;;) 3665 { 3666 unsigned long width; 3667 3668 if (*input_line_pointer != ':') 3669 { 3670 input_line_pointer = hold; 3671 break; 3672 } /* next piece is not a bitfield */ 3673 3674 /* In the general case, we can't allow 3675 full expressions with symbol 3676 differences and such. The relocation 3677 entries for symbols not defined in this 3678 assembly would require arbitrary field 3679 widths, positions, and masks which most 3680 of our current object formats don't 3681 support. 3682 3683 In the specific case where a symbol 3684 *is* defined in this assembly, we 3685 *could* build fixups and track it, but 3686 this could lead to confusion for the 3687 backends. I'm lazy. I'll take any 3688 SEG_ABSOLUTE. I think that means that 3689 you can use a previous .set or 3690 .equ type symbol. xoxorich. */ 3691 3692 if (exp->X_op == O_absent) 3693 { 3694 as_warn ("using a bit field width of zero"); 3695 exp->X_add_number = 0; 3696 exp->X_op = O_constant; 3697 } /* implied zero width bitfield */ 3698 3699 if (exp->X_op != O_constant) 3700 { 3701 *input_line_pointer = '\0'; 3702 as_bad ("field width \"%s\" too complex for a bitfield", hold); 3703 *input_line_pointer = ':'; 3704 demand_empty_rest_of_line (); 3705 return; 3706 } /* too complex */ 3707 3708 if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes)) 3709 { 3710 as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits", 3711 width, nbytes, (BITS_PER_CHAR * nbytes)); 3712 width = BITS_PER_CHAR * nbytes; 3713 } /* too big */ 3714 3715 if (width > bits_available) 3716 { 3717 /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */ 3718 input_line_pointer = hold; 3719 exp->X_add_number = value; 3720 break; 3721 } /* won't fit */ 3722 3723 hold = ++input_line_pointer; /* skip ':' */ 3724 3725 (void) expression (exp); 3726 if (exp->X_op != O_constant) 3727 { 3728 char cache = *input_line_pointer; 3729 3730 *input_line_pointer = '\0'; 3731 as_bad ("field value \"%s\" too complex for a bitfield", hold); 3732 *input_line_pointer = cache; 3733 demand_empty_rest_of_line (); 3734 return; 3735 } /* too complex */ 3736 3737 value |= ((~(-1 << width) & exp->X_add_number) 3738 << ((BITS_PER_CHAR * nbytes) - bits_available)); 3739 3740 if ((bits_available -= width) == 0 3741 || is_it_end_of_statement () 3742 || *input_line_pointer != ',') 3743 { 3744 break; 3745 } /* all the bitfields we're gonna get */ 3746 3747 hold = ++input_line_pointer; 3748 (void) expression (exp); 3749 } /* forever loop */ 3750 3751 exp->X_add_number = value; 3752 exp->X_op = O_constant; 3753 exp->X_unsigned = 1; 3754 } /* if looks like a bitfield */ 3755} /* parse_bitfield_cons() */ 3756 3757#endif /* BITFIELD_CONS_EXPRESSIONS */ 3758 3759/* Handle an MRI style string expression. */ 3760 3761static void 3762parse_mri_cons (exp, nbytes) 3763 expressionS *exp; 3764 unsigned int nbytes; 3765{ 3766 if (*input_line_pointer != '\'' 3767 && (input_line_pointer[1] != '\'' 3768 || (*input_line_pointer != 'A' 3769 && *input_line_pointer != 'E'))) 3770 TC_PARSE_CONS_EXPRESSION (exp, nbytes); 3771 else 3772 { 3773 unsigned int scan; 3774 unsigned int result = 0; 3775 3776 /* An MRI style string. Cut into as many bytes as will fit into 3777 a nbyte chunk, left justify if necessary, and separate with 3778 commas so we can try again later. */ 3779 if (*input_line_pointer == 'A') 3780 ++input_line_pointer; 3781 else if (*input_line_pointer == 'E') 3782 { 3783 as_bad ("EBCDIC constants are not supported"); 3784 ++input_line_pointer; 3785 } 3786 3787 input_line_pointer++; 3788 for (scan = 0; scan < nbytes; scan++) 3789 { 3790 if (*input_line_pointer == '\'') 3791 { 3792 if (input_line_pointer[1] == '\'') 3793 { 3794 input_line_pointer++; 3795 } 3796 else 3797 break; 3798 } 3799 result = (result << 8) | (*input_line_pointer++); 3800 } 3801 3802 /* Left justify */ 3803 while (scan < nbytes) 3804 { 3805 result <<= 8; 3806 scan++; 3807 } 3808 /* Create correct expression */ 3809 exp->X_op = O_constant; 3810 exp->X_add_number = result; 3811 /* Fake it so that we can read the next char too */ 3812 if (input_line_pointer[0] != '\'' || 3813 (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\'')) 3814 { 3815 input_line_pointer -= 2; 3816 input_line_pointer[0] = ','; 3817 input_line_pointer[1] = '\''; 3818 } 3819 else 3820 input_line_pointer++; 3821 } 3822} 3823 3824#ifdef REPEAT_CONS_EXPRESSIONS 3825 3826/* Parse a repeat expression for cons. This is used by the MIPS 3827 assembler. The format is NUMBER:COUNT; NUMBER appears in the 3828 object file COUNT times. 3829 3830 To use this for a target, define REPEAT_CONS_EXPRESSIONS. */ 3831 3832static void 3833parse_repeat_cons (exp, nbytes) 3834 expressionS *exp; 3835 unsigned int nbytes; 3836{ 3837 expressionS count; 3838 register int i; 3839 3840 expression (exp); 3841 3842 if (*input_line_pointer != ':') 3843 { 3844 /* No repeat count. */ 3845 return; 3846 } 3847 3848 ++input_line_pointer; 3849 expression (&count); 3850 if (count.X_op != O_constant 3851 || count.X_add_number <= 0) 3852 { 3853 as_warn ("Unresolvable or nonpositive repeat count; using 1"); 3854 return; 3855 } 3856 3857 /* The cons function is going to output this expression once. So we 3858 output it count - 1 times. */ 3859 for (i = count.X_add_number - 1; i > 0; i--) 3860 emit_expr (exp, nbytes); 3861} 3862 3863#endif /* REPEAT_CONS_EXPRESSIONS */ 3864 3865/* Parse a floating point number represented as a hex constant. This 3866 permits users to specify the exact bits they want in the floating 3867 point number. */ 3868 3869static int 3870hex_float (float_type, bytes) 3871 int float_type; 3872 char *bytes; 3873{ 3874 int length; 3875 int i; 3876 3877 switch (float_type) 3878 { 3879 case 'f': 3880 case 'F': 3881 case 's': 3882 case 'S': 3883 length = 4; 3884 break; 3885 3886 case 'd': 3887 case 'D': 3888 case 'r': 3889 case 'R': 3890 length = 8; 3891 break; 3892 3893 case 'x': 3894 case 'X': 3895 length = 12; 3896 break; 3897 3898 case 'p': 3899 case 'P': 3900 length = 12; 3901 break; 3902 3903 default: 3904 as_bad ("Unknown floating type type '%c'", float_type); 3905 return -1; 3906 } 3907 3908 /* It would be nice if we could go through expression to parse the 3909 hex constant, but if we get a bignum it's a pain to sort it into 3910 the buffer correctly. */ 3911 i = 0; 3912 while (hex_p (*input_line_pointer) || *input_line_pointer == '_') 3913 { 3914 int d; 3915 3916 /* The MRI assembler accepts arbitrary underscores strewn about 3917 through the hex constant, so we ignore them as well. */ 3918 if (*input_line_pointer == '_') 3919 { 3920 ++input_line_pointer; 3921 continue; 3922 } 3923 3924 if (i >= length) 3925 { 3926 as_warn ("Floating point constant too large"); 3927 return -1; 3928 } 3929 d = hex_value (*input_line_pointer) << 4; 3930 ++input_line_pointer; 3931 while (*input_line_pointer == '_') 3932 ++input_line_pointer; 3933 if (hex_p (*input_line_pointer)) 3934 { 3935 d += hex_value (*input_line_pointer); 3936 ++input_line_pointer; 3937 } 3938 if (target_big_endian) 3939 bytes[i] = d; 3940 else 3941 bytes[length - i - 1] = d; 3942 ++i; 3943 } 3944 3945 if (i < length) 3946 { 3947 if (target_big_endian) 3948 memset (bytes + i, 0, length - i); 3949 else 3950 memset (bytes, 0, length - i); 3951 } 3952 3953 return length; 3954} 3955 3956/* 3957 * float_cons() 3958 * 3959 * CONStruct some more frag chars of .floats .ffloats etc. 3960 * Makes 0 or more new frags. 3961 * If need_pass_2 == 1, no frags are emitted. 3962 * This understands only floating literals, not expressions. Sorry. 3963 * 3964 * A floating constant is defined by atof_generic(), except it is preceded 3965 * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its 3966 * reading, I decided to be incompatible. This always tries to give you 3967 * rounded bits to the precision of the pseudo-op. Former AS did premature 3968 * truncatation, restored noisy bits instead of trailing 0s AND gave you 3969 * a choice of 2 flavours of noise according to which of 2 floating-point 3970 * scanners you directed AS to use. 3971 * 3972 * In: input_line_pointer->whitespace before, or '0' of flonum. 3973 * 3974 */ 3975 3976void 3977float_cons (float_type) 3978 /* Clobbers input_line-pointer, checks end-of-line. */ 3979 register int float_type; /* 'f':.ffloat ... 'F':.float ... */ 3980{ 3981 register char *p; 3982 int length; /* Number of chars in an object. */ 3983 register char *err; /* Error from scanning floating literal. */ 3984 char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; 3985 3986 if (is_it_end_of_statement ()) 3987 { 3988 demand_empty_rest_of_line (); 3989 return; 3990 } 3991 3992#ifdef md_flush_pending_output 3993 md_flush_pending_output (); 3994#endif 3995 3996 do 3997 { 3998 /* input_line_pointer->1st char of a flonum (we hope!). */ 3999 SKIP_WHITESPACE (); 4000 4001 /* Skip any 0{letter} that may be present. Don't even check if the 4002 * letter is legal. Someone may invent a "z" format and this routine 4003 * has no use for such information. Lusers beware: you get 4004 * diagnostics if your input is ill-conditioned. 4005 */ 4006 if (input_line_pointer[0] == '0' 4007 && isalpha ((unsigned char) input_line_pointer[1])) 4008 input_line_pointer += 2; 4009 4010 /* Accept :xxxx, where the x's are hex digits, for a floating 4011 point with the exact digits specified. */ 4012 if (input_line_pointer[0] == ':') 4013 { 4014 ++input_line_pointer; 4015 length = hex_float (float_type, temp); 4016 if (length < 0) 4017 { 4018 ignore_rest_of_line (); 4019 return; 4020 } 4021 } 4022 else 4023 { 4024 err = md_atof (float_type, temp, &length); 4025 know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); 4026 know (length > 0); 4027 if (err) 4028 { 4029 as_bad ("Bad floating literal: %s", err); 4030 ignore_rest_of_line (); 4031 return; 4032 } 4033 } 4034 4035 if (!need_pass_2) 4036 { 4037 int count; 4038 4039 count = 1; 4040 4041#ifdef REPEAT_CONS_EXPRESSIONS 4042 if (*input_line_pointer == ':') 4043 { 4044 expressionS count_exp; 4045 4046 ++input_line_pointer; 4047 expression (&count_exp); 4048 if (count_exp.X_op != O_constant 4049 || count_exp.X_add_number <= 0) 4050 { 4051 as_warn ("unresolvable or nonpositive repeat count; using 1"); 4052 } 4053 else 4054 count = count_exp.X_add_number; 4055 } 4056#endif 4057 4058 while (--count >= 0) 4059 { 4060 p = frag_more (length); 4061 memcpy (p, temp, (unsigned int) length); 4062 } 4063 } 4064 SKIP_WHITESPACE (); 4065 } 4066 while (*input_line_pointer++ == ','); 4067 4068 --input_line_pointer; /* Put terminator back into stream. */ 4069 demand_empty_rest_of_line (); 4070} /* float_cons() */ 4071 4072/* Return the size of a LEB128 value */ 4073 4074static inline int 4075sizeof_sleb128 (value) 4076 offsetT value; 4077{ 4078 register int size = 0; 4079 register unsigned byte; 4080 4081 do 4082 { 4083 byte = (value & 0x7f); 4084 /* Sadly, we cannot rely on typical arithmetic right shift behaviour. 4085 Fortunately, we can structure things so that the extra work reduces 4086 to a noop on systems that do things "properly". */ 4087 value = (value >> 7) | ~(-(offsetT)1 >> 7); 4088 size += 1; 4089 } 4090 while (!(((value == 0) && ((byte & 0x40) == 0)) 4091 || ((value == -1) && ((byte & 0x40) != 0)))); 4092 4093 return size; 4094} 4095 4096static inline int 4097sizeof_uleb128 (value) 4098 valueT value; 4099{ 4100 register int size = 0; 4101 register unsigned byte; 4102 4103 do 4104 { 4105 byte = (value & 0x7f); 4106 value >>= 7; 4107 size += 1; 4108 } 4109 while (value != 0); 4110 4111 return size; 4112} 4113 4114inline int 4115sizeof_leb128 (value, sign) 4116 valueT value; 4117 int sign; 4118{ 4119 if (sign) 4120 return sizeof_sleb128 ((offsetT) value); 4121 else 4122 return sizeof_uleb128 (value); 4123} 4124 4125/* Output a LEB128 value. */ 4126 4127static inline int 4128output_sleb128 (p, value) 4129 char *p; 4130 offsetT value; 4131{ 4132 register char *orig = p; 4133 register int more; 4134 4135 do 4136 { 4137 unsigned byte = (value & 0x7f); 4138 4139 /* Sadly, we cannot rely on typical arithmetic right shift behaviour. 4140 Fortunately, we can structure things so that the extra work reduces 4141 to a noop on systems that do things "properly". */ 4142 value = (value >> 7) | ~(-(offsetT)1 >> 7); 4143 4144 more = !((((value == 0) && ((byte & 0x40) == 0)) 4145 || ((value == -1) && ((byte & 0x40) != 0)))); 4146 if (more) 4147 byte |= 0x80; 4148 4149 *p++ = byte; 4150 } 4151 while (more); 4152 4153 return p - orig; 4154} 4155 4156static inline int 4157output_uleb128 (p, value) 4158 char *p; 4159 valueT value; 4160{ 4161 char *orig = p; 4162 4163 do 4164 { 4165 unsigned byte = (value & 0x7f); 4166 value >>= 7; 4167 if (value != 0) 4168 /* More bytes to follow. */ 4169 byte |= 0x80; 4170 4171 *p++ = byte; 4172 } 4173 while (value != 0); 4174 4175 return p - orig; 4176} 4177 4178inline int 4179output_leb128 (p, value, sign) 4180 char *p; 4181 valueT value; 4182 int sign; 4183{ 4184 if (sign) 4185 return output_sleb128 (p, (offsetT) value); 4186 else 4187 return output_uleb128 (p, value); 4188} 4189 4190/* Do the same for bignums. We combine sizeof with output here in that 4191 we don't output for NULL values of P. It isn't really as critical as 4192 for "normal" values that this be streamlined. */ 4193 4194static int 4195output_big_sleb128 (p, bignum, size) 4196 char *p; 4197 LITTLENUM_TYPE *bignum; 4198 int size; 4199{ 4200 char *orig = p; 4201 valueT val = 0; 4202 int loaded = 0; 4203 unsigned byte; 4204 4205 /* Strip leading sign extensions off the bignum. */ 4206 while (size > 0 && bignum[size-1] == (LITTLENUM_TYPE)-1) 4207 size--; 4208 4209 do 4210 { 4211 if (loaded < 7 && size > 0) 4212 { 4213 val |= (*bignum << loaded); 4214 loaded += 8 * CHARS_PER_LITTLENUM; 4215 size--; 4216 bignum++; 4217 } 4218 4219 byte = val & 0x7f; 4220 loaded -= 7; 4221 val >>= 7; 4222 4223 if (size == 0) 4224 { 4225 if ((val == 0 && (byte & 0x40) == 0) 4226 || (~(val | ~(((valueT)1 << loaded) - 1)) == 0 4227 && (byte & 0x40) != 0)) 4228 byte |= 0x80; 4229 } 4230 4231 if (orig) 4232 *p = byte; 4233 p++; 4234 } 4235 while (byte & 0x80); 4236 4237 return p - orig; 4238} 4239 4240static int 4241output_big_uleb128 (p, bignum, size) 4242 char *p; 4243 LITTLENUM_TYPE *bignum; 4244 int size; 4245{ 4246 char *orig = p; 4247 valueT val = 0; 4248 int loaded = 0; 4249 unsigned byte; 4250 4251 /* Strip leading zeros off the bignum. */ 4252 /* XXX: Is this needed? */ 4253 while (size > 0 && bignum[size-1] == 0) 4254 size--; 4255 4256 do 4257 { 4258 if (loaded < 7 && size > 0) 4259 { 4260 val |= (*bignum << loaded); 4261 loaded += 8 * CHARS_PER_LITTLENUM; 4262 size--; 4263 bignum++; 4264 } 4265 4266 byte = val & 0x7f; 4267 loaded -= 7; 4268 val >>= 7; 4269 4270 if (size > 0 || val) 4271 byte |= 0x80; 4272 4273 if (orig) 4274 *p = byte; 4275 p++; 4276 } 4277 while (byte & 0x80); 4278 4279 return p - orig; 4280} 4281 4282static inline int 4283output_big_leb128 (p, bignum, size, sign) 4284 char *p; 4285 LITTLENUM_TYPE *bignum; 4286 int size, sign; 4287{ 4288 if (sign) 4289 return output_big_sleb128 (p, bignum, size); 4290 else 4291 return output_big_uleb128 (p, bignum, size); 4292} 4293 4294/* Generate the appropriate fragments for a given expression to emit a 4295 leb128 value. */ 4296 4297void 4298emit_leb128_expr(exp, sign) 4299 expressionS *exp; 4300 int sign; 4301{ 4302 operatorT op = exp->X_op; 4303 4304 if (op == O_absent || op == O_illegal) 4305 { 4306 as_warn ("zero assumed for missing expression"); 4307 exp->X_add_number = 0; 4308 op = O_constant; 4309 } 4310 else if (op == O_big && exp->X_add_number <= 0) 4311 { 4312 as_bad ("floating point number invalid; zero assumed"); 4313 exp->X_add_number = 0; 4314 op = O_constant; 4315 } 4316 else if (op == O_register) 4317 { 4318 as_warn ("register value used as expression"); 4319 op = O_constant; 4320 } 4321 4322 if (op == O_constant) 4323 { 4324 /* If we've got a constant, emit the thing directly right now. */ 4325 4326 valueT value = exp->X_add_number; 4327 int size; 4328 char *p; 4329 4330 size = sizeof_leb128 (value, sign); 4331 p = frag_more (size); 4332 output_leb128 (p, value, sign); 4333 } 4334 else if (op == O_big) 4335 { 4336 /* O_big is a different sort of constant. */ 4337 4338 int size; 4339 char *p; 4340 4341 size = output_big_leb128 (NULL, generic_bignum, exp->X_add_number, sign); 4342 p = frag_more (size); 4343 output_big_leb128 (p, generic_bignum, exp->X_add_number, sign); 4344 } 4345 else 4346 { 4347 /* Otherwise, we have to create a variable sized fragment and 4348 resolve things later. */ 4349 4350 frag_var (rs_leb128, sizeof_uleb128 (~(valueT)0), 0, sign, 4351 make_expr_symbol (exp), 0, (char *) NULL); 4352 } 4353} 4354 4355/* Parse the .sleb128 and .uleb128 pseudos. */ 4356 4357void 4358s_leb128 (sign) 4359 int sign; 4360{ 4361 expressionS exp; 4362 4363 do { 4364 expression (&exp); 4365 emit_leb128_expr (&exp, sign); 4366 } while (*input_line_pointer++ == ','); 4367 4368 input_line_pointer--; 4369 demand_empty_rest_of_line (); 4370} 4371 4372/* 4373 * stringer() 4374 * 4375 * We read 0 or more ',' seperated, double-quoted strings. 4376 * 4377 * Caller should have checked need_pass_2 is FALSE because we don't check it. 4378 */ 4379 4380 4381void 4382stringer (append_zero) /* Worker to do .ascii etc statements. */ 4383 /* Checks end-of-line. */ 4384 register int append_zero; /* 0: don't append '\0', else 1 */ 4385{ 4386 register unsigned int c; 4387 char *start; 4388 4389#ifdef md_flush_pending_output 4390 md_flush_pending_output (); 4391#endif 4392 4393 /* 4394 * The following awkward logic is to parse ZERO or more strings, 4395 * comma seperated. Recall a string expression includes spaces 4396 * before the opening '\"' and spaces after the closing '\"'. 4397 * We fake a leading ',' if there is (supposed to be) 4398 * a 1st, expression. We keep demanding expressions for each 4399 * ','. 4400 */ 4401 if (is_it_end_of_statement ()) 4402 { 4403 c = 0; /* Skip loop. */ 4404 ++input_line_pointer; /* Compensate for end of loop. */ 4405 } 4406 else 4407 { 4408 c = ','; /* Do loop. */ 4409 } 4410 while (c == ',' || c == '<' || c == '"') 4411 { 4412 SKIP_WHITESPACE (); 4413 switch (*input_line_pointer) 4414 { 4415 case '\"': 4416 ++input_line_pointer; /*->1st char of string. */ 4417 start = input_line_pointer; 4418 while (is_a_char (c = next_char_of_string ())) 4419 { 4420 FRAG_APPEND_1_CHAR (c); 4421 } 4422 if (append_zero) 4423 { 4424 FRAG_APPEND_1_CHAR (0); 4425 } 4426 know (input_line_pointer[-1] == '\"'); 4427 4428#ifndef NO_LISTING 4429#ifdef OBJ_ELF 4430 /* In ELF, when gcc is emitting DWARF 1 debugging output, it 4431 will emit .string with a filename in the .debug section 4432 after a sequence of constants. See the comment in 4433 emit_expr for the sequence. emit_expr will set 4434 dwarf_file_string to non-zero if this string might be a 4435 source file name. */ 4436 if (strcmp (segment_name (now_seg), ".debug") != 0) 4437 dwarf_file_string = 0; 4438 else if (dwarf_file_string) 4439 { 4440 c = input_line_pointer[-1]; 4441 input_line_pointer[-1] = '\0'; 4442 listing_source_file (start); 4443 input_line_pointer[-1] = c; 4444 } 4445#endif 4446#endif 4447 4448 break; 4449 case '<': 4450 input_line_pointer++; 4451 c = get_single_number (); 4452 FRAG_APPEND_1_CHAR (c); 4453 if (*input_line_pointer != '>') 4454 { 4455 as_bad ("Expected <nn>"); 4456 } 4457 input_line_pointer++; 4458 break; 4459 case ',': 4460 input_line_pointer++; 4461 break; 4462 } 4463 SKIP_WHITESPACE (); 4464 c = *input_line_pointer; 4465 } 4466 4467 demand_empty_rest_of_line (); 4468} /* stringer() */ 4469 4470/* FIXME-SOMEDAY: I had trouble here on characters with the 4471 high bits set. We'll probably also have trouble with 4472 multibyte chars, wide chars, etc. Also be careful about 4473 returning values bigger than 1 byte. xoxorich. */ 4474 4475unsigned int 4476next_char_of_string () 4477{ 4478 register unsigned int c; 4479 4480 c = *input_line_pointer++ & CHAR_MASK; 4481 switch (c) 4482 { 4483 case '\"': 4484 c = NOT_A_CHAR; 4485 break; 4486 4487 case '\n': 4488 as_warn ("Unterminated string: Newline inserted."); 4489 bump_line_counters (); 4490 break; 4491 4492#ifndef NO_STRING_ESCAPES 4493 case '\\': 4494 switch (c = *input_line_pointer++) 4495 { 4496 case 'b': 4497 c = '\b'; 4498 break; 4499 4500 case 'f': 4501 c = '\f'; 4502 break; 4503 4504 case 'n': 4505 c = '\n'; 4506 break; 4507 4508 case 'r': 4509 c = '\r'; 4510 break; 4511 4512 case 't': 4513 c = '\t'; 4514 break; 4515 4516 case 'v': 4517 c = '\013'; 4518 break; 4519 4520 case '\\': 4521 case '"': 4522 break; /* As itself. */ 4523 4524 case '0': 4525 case '1': 4526 case '2': 4527 case '3': 4528 case '4': 4529 case '5': 4530 case '6': 4531 case '7': 4532 case '8': 4533 case '9': 4534 { 4535 long number; 4536 int i; 4537 4538 for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++) 4539 { 4540 number = number * 8 + c - '0'; 4541 } 4542 c = number & 0xff; 4543 } 4544 --input_line_pointer; 4545 break; 4546 4547 case 'x': 4548 case 'X': 4549 { 4550 long number; 4551 4552 number = 0; 4553 c = *input_line_pointer++; 4554 while (isxdigit (c)) 4555 { 4556 if (isdigit (c)) 4557 number = number * 16 + c - '0'; 4558 else if (isupper (c)) 4559 number = number * 16 + c - 'A' + 10; 4560 else 4561 number = number * 16 + c - 'a' + 10; 4562 c = *input_line_pointer++; 4563 } 4564 c = number & 0xff; 4565 --input_line_pointer; 4566 } 4567 break; 4568 4569 case '\n': 4570 /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */ 4571 as_warn ("Unterminated string: Newline inserted."); 4572 c = '\n'; 4573 bump_line_counters (); 4574 break; 4575 4576 default: 4577 4578#ifdef ONLY_STANDARD_ESCAPES 4579 as_bad ("Bad escaped character in string, '?' assumed"); 4580 c = '?'; 4581#endif /* ONLY_STANDARD_ESCAPES */ 4582 4583 break; 4584 } /* switch on escaped char */ 4585 break; 4586#endif /* ! defined (NO_STRING_ESCAPES) */ 4587 4588 default: 4589 break; 4590 } /* switch on char */ 4591 return (c); 4592} /* next_char_of_string() */ 4593 4594static segT 4595get_segmented_expression (expP) 4596 register expressionS *expP; 4597{ 4598 register segT retval; 4599 4600 retval = expression (expP); 4601 if (expP->X_op == O_illegal 4602 || expP->X_op == O_absent 4603 || expP->X_op == O_big) 4604 { 4605 as_bad ("expected address expression; zero assumed"); 4606 expP->X_op = O_constant; 4607 expP->X_add_number = 0; 4608 retval = absolute_section; 4609 } 4610 return retval; 4611} 4612 4613static segT 4614get_known_segmented_expression (expP) 4615 register expressionS *expP; 4616{ 4617 register segT retval; 4618 4619 if ((retval = get_segmented_expression (expP)) == undefined_section) 4620 { 4621 /* There is no easy way to extract the undefined symbol from the 4622 expression. */ 4623 if (expP->X_add_symbol != NULL 4624 && S_GET_SEGMENT (expP->X_add_symbol) != expr_section) 4625 as_warn ("symbol \"%s\" undefined; zero assumed", 4626 S_GET_NAME (expP->X_add_symbol)); 4627 else 4628 as_warn ("some symbol undefined; zero assumed"); 4629 retval = absolute_section; 4630 expP->X_op = O_constant; 4631 expP->X_add_number = 0; 4632 } 4633 know (retval == absolute_section || SEG_NORMAL (retval)); 4634 return (retval); 4635} /* get_known_segmented_expression() */ 4636 4637offsetT 4638get_absolute_expression () 4639{ 4640 expressionS exp; 4641 4642 expression (&exp); 4643 if (exp.X_op != O_constant) 4644 { 4645 if (exp.X_op != O_absent) 4646 as_bad ("bad or irreducible absolute expression; zero assumed"); 4647 exp.X_add_number = 0; 4648 } 4649 return exp.X_add_number; 4650} 4651 4652char /* return terminator */ 4653get_absolute_expression_and_terminator (val_pointer) 4654 long *val_pointer; /* return value of expression */ 4655{ 4656 /* FIXME: val_pointer should probably be offsetT *. */ 4657 *val_pointer = (long) get_absolute_expression (); 4658 return (*input_line_pointer++); 4659} 4660 4661/* 4662 * demand_copy_C_string() 4663 * 4664 * Like demand_copy_string, but return NULL if the string contains any '\0's. 4665 * Give a warning if that happens. 4666 */ 4667char * 4668demand_copy_C_string (len_pointer) 4669 int *len_pointer; 4670{ 4671 register char *s; 4672 4673 if ((s = demand_copy_string (len_pointer)) != 0) 4674 { 4675 register int len; 4676 4677 for (len = *len_pointer; len > 0; len--) 4678 { 4679 if (*s == 0) 4680 { 4681 s = 0; 4682 len = 1; 4683 *len_pointer = 0; 4684 as_bad ("This string may not contain \'\\0\'"); 4685 } 4686 } 4687 } 4688 return s; 4689} 4690 4691/* 4692 * demand_copy_string() 4693 * 4694 * Demand string, but return a safe (=private) copy of the string. 4695 * Return NULL if we can't read a string here. 4696 */ 4697char * 4698demand_copy_string (lenP) 4699 int *lenP; 4700{ 4701 register unsigned int c; 4702 register int len; 4703 char *retval; 4704 4705 len = 0; 4706 SKIP_WHITESPACE (); 4707 if (*input_line_pointer == '\"') 4708 { 4709 input_line_pointer++; /* Skip opening quote. */ 4710 4711 while (is_a_char (c = next_char_of_string ())) 4712 { 4713 obstack_1grow (¬es, c); 4714 len++; 4715 } 4716 /* JF this next line is so demand_copy_C_string will return a 4717 null terminated string. */ 4718 obstack_1grow (¬es, '\0'); 4719 retval = obstack_finish (¬es); 4720 } 4721 else 4722 { 4723 as_warn ("Missing string"); 4724 retval = NULL; 4725 ignore_rest_of_line (); 4726 } 4727 *lenP = len; 4728 return (retval); 4729} /* demand_copy_string() */ 4730 4731/* 4732 * is_it_end_of_statement() 4733 * 4734 * In: Input_line_pointer->next character. 4735 * 4736 * Do: Skip input_line_pointer over all whitespace. 4737 * 4738 * Out: 1 if input_line_pointer->end-of-line. 4739*/ 4740int 4741is_it_end_of_statement () 4742{ 4743 SKIP_WHITESPACE (); 4744 return (is_end_of_line[(unsigned char) *input_line_pointer]); 4745} /* is_it_end_of_statement() */ 4746 4747void 4748equals (sym_name, reassign) 4749 char *sym_name; 4750 int reassign; 4751{ 4752 register symbolS *symbolP; /* symbol we are working with */ 4753 char *stop = NULL; 4754 char stopc; 4755 4756 input_line_pointer++; 4757 if (*input_line_pointer == '=') 4758 input_line_pointer++; 4759 4760 while (*input_line_pointer == ' ' || *input_line_pointer == '\t') 4761 input_line_pointer++; 4762 4763 if (flag_mri) 4764 stop = mri_comment_field (&stopc); 4765 4766 if (sym_name[0] == '.' && sym_name[1] == '\0') 4767 { 4768 /* Turn '. = mumble' into a .org mumble */ 4769 register segT segment; 4770 expressionS exp; 4771 4772 segment = get_known_segmented_expression (&exp); 4773 if (!need_pass_2) 4774 do_org (segment, &exp, 0); 4775 } 4776 else 4777 { 4778 symbolP = symbol_find_or_make (sym_name); 4779 /* Permit register names to be redefined. */ 4780 if (! reassign 4781 && S_IS_DEFINED (symbolP) 4782 && S_GET_SEGMENT (symbolP) != reg_section) 4783 as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP)); 4784 pseudo_set (symbolP); 4785 } 4786 4787 if (flag_mri) 4788 mri_comment_end (stop, stopc); 4789} /* equals() */ 4790 4791/* .include -- include a file at this point. */ 4792 4793/* ARGSUSED */ 4794void 4795s_include (arg) 4796 int arg; 4797{ 4798 char *newbuf; 4799 char *filename; 4800 int i; 4801 FILE *try; 4802 char *path; 4803 4804 if (! flag_m68k_mri) 4805 { 4806 filename = demand_copy_string (&i); 4807 if (filename == NULL) 4808 { 4809 /* demand_copy_string has already printed an error and 4810 called ignore_rest_of_line. */ 4811 return; 4812 } 4813 } 4814 else 4815 { 4816 SKIP_WHITESPACE (); 4817 i = 0; 4818 while (! is_end_of_line[(unsigned char) *input_line_pointer] 4819 && *input_line_pointer != ' ' 4820 && *input_line_pointer != '\t') 4821 { 4822 obstack_1grow (¬es, *input_line_pointer); 4823 ++input_line_pointer; 4824 ++i; 4825 } 4826 obstack_1grow (¬es, '\0'); 4827 filename = obstack_finish (¬es); 4828 while (! is_end_of_line[(unsigned char) *input_line_pointer]) 4829 ++input_line_pointer; 4830 } 4831 demand_empty_rest_of_line (); 4832 path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ ); 4833 for (i = 0; i < include_dir_count; i++) 4834 { 4835 strcpy (path, include_dirs[i]); 4836 strcat (path, "/"); 4837 strcat (path, filename); 4838 if (0 != (try = fopen (path, "r"))) 4839 { 4840 fclose (try); 4841 goto gotit; 4842 } 4843 } 4844 free (path); 4845 path = filename; 4846gotit: 4847 /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */ 4848 register_dependency (path); 4849 newbuf = input_scrub_include_file (path, input_line_pointer); 4850 buffer_limit = input_scrub_next_buffer (&input_line_pointer); 4851} /* s_include() */ 4852 4853void 4854add_include_dir (path) 4855 char *path; 4856{ 4857 int i; 4858 4859 if (include_dir_count == 0) 4860 { 4861 include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs)); 4862 include_dirs[0] = "."; /* Current dir */ 4863 include_dir_count = 2; 4864 } 4865 else 4866 { 4867 include_dir_count++; 4868 include_dirs = (char **) realloc (include_dirs, 4869 include_dir_count * sizeof (*include_dirs)); 4870 } 4871 4872 include_dirs[include_dir_count - 1] = path; /* New one */ 4873 4874 i = strlen (path); 4875 if (i > include_dir_maxlen) 4876 include_dir_maxlen = i; 4877} /* add_include_dir() */ 4878 4879void 4880s_ignore (arg) 4881 int arg; 4882{ 4883 while (!is_end_of_line[(unsigned char) *input_line_pointer]) 4884 { 4885 ++input_line_pointer; 4886 } 4887 ++input_line_pointer; 4888} 4889 4890 4891void 4892read_print_statistics (file) 4893 FILE *file; 4894{ 4895 hash_print_statistics (file, "pseudo-op table", po_hash); 4896} 4897 4898/* end of read.c */ 4899