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