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