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