Commit | Line | Data |
---|---|---|
5b93d8bb AM |
1 | /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set. |
2 | Loosely based on the ppc files by Linas Vepstas <linas@linas.org> 1998, 99 | |
4b95cf5c | 3 | Copyright (C) 1994-2014 Free Software Foundation, Inc. |
5b93d8bb AM |
4 | Written by Ian Lance Taylor, Cygnus Support. |
5 | ||
6 | This file is part of GAS, the GNU Assembler. | |
7 | ||
8 | GAS is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 10 | the Free Software Foundation; either version 3, or (at your option) |
5b93d8bb AM |
11 | any later version. |
12 | ||
13 | GAS is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
20 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
21 | 02110-1301, USA. */ | |
5b93d8bb AM |
22 | |
23 | /* This assembler implements a very hacked version of an elf-like thing | |
ea1562b3 NC |
24 | that gcc emits (when gcc is suitably hacked). To make it behave more |
25 | HLASM-like, try turning on the -M or --mri flag (as there are various | |
26 | similarities between HLASM and the MRI assemblers, such as section | |
27 | names, lack of leading . in pseudo-ops, DC and DS, etc. */ | |
5b93d8bb | 28 | |
5b93d8bb | 29 | #include "as.h" |
44addf7f | 30 | #include "safe-ctype.h" |
5b93d8bb AM |
31 | #include "subsegs.h" |
32 | #include "struc-symbol.h" | |
33 | ||
34 | #include "opcode/i370.h" | |
35 | ||
36 | #ifdef OBJ_ELF | |
37 | #include "elf/i370.h" | |
38 | #endif | |
39 | ||
ea1562b3 | 40 | /* This is the assembler for the System/390 Architecture. */ |
5b93d8bb AM |
41 | |
42 | /* Tell the main code what the endianness is. */ | |
43 | extern int target_big_endian; | |
44 | ||
45 | \f | |
46 | /* Generic assembler global variables which must be defined by all | |
47 | targets. */ | |
48 | ||
49 | #ifdef OBJ_ELF | |
50 | /* This string holds the chars that always start a comment. If the | |
51 | pre-processor is disabled, these aren't very useful. The macro | |
52 | tc_comment_chars points to this. We use this, rather than the | |
53 | usual comment_chars, so that we can switch for Solaris conventions. */ | |
54 | static const char i370_eabi_comment_chars[] = "#"; | |
55 | ||
56 | const char *i370_comment_chars = i370_eabi_comment_chars; | |
57 | #else | |
58 | const char comment_chars[] = "#"; | |
59 | #endif | |
60 | ||
61 | /* Characters which start a comment at the beginning of a line. */ | |
62 | const char line_comment_chars[] = "#*"; | |
63 | ||
64 | /* Characters which may be used to separate multiple commands on a | |
65 | single line. */ | |
66 | const char line_separator_chars[] = ";"; | |
67 | ||
68 | /* Characters which are used to indicate an exponent in a floating | |
69 | point number. */ | |
70 | const char EXP_CHARS[] = "eE"; | |
71 | ||
72 | /* Characters which mean that a number is a floating point constant, | |
73 | as in 0d1.0. */ | |
74 | const char FLT_CHARS[] = "dD"; | |
75 | ||
5b93d8bb | 76 | void |
ea1562b3 | 77 | md_show_usage (FILE *stream) |
5b93d8bb | 78 | { |
bc805888 | 79 | fprintf (stream, "\ |
5b93d8bb AM |
80 | S/370 options: (these have not yet been tested and may not work) \n\ |
81 | -u ignored\n\ | |
82 | -mregnames Allow symbolic names for registers\n\ | |
83 | -mno-regnames Do not allow symbolic names for registers\n"); | |
84 | #ifdef OBJ_ELF | |
bc805888 | 85 | fprintf (stream, "\ |
5b93d8bb AM |
86 | -mrelocatable support for GCC's -mrelocatble option\n\ |
87 | -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\ | |
88 | -V print assembler version number\n"); | |
89 | #endif | |
90 | } | |
91 | ||
5b93d8bb | 92 | /* Whether to use user friendly register names. */ |
b34976b6 | 93 | #define TARGET_REG_NAMES_P TRUE |
5b93d8bb | 94 | |
b34976b6 | 95 | static bfd_boolean reg_names_p = TARGET_REG_NAMES_P; |
5b93d8bb | 96 | |
5b93d8bb | 97 | \f |
ea1562b3 NC |
98 | /* Predefined register names if -mregnames |
99 | In general, there are lots of them, in an attempt to be compatible | |
100 | with a number of assemblers. */ | |
5b93d8bb AM |
101 | |
102 | /* Structure to hold information about predefined registers. */ | |
103 | struct pd_reg | |
104 | { | |
105 | char *name; | |
106 | int value; | |
107 | }; | |
108 | ||
109 | /* List of registers that are pre-defined: | |
110 | ||
111 | Each general register has predefined names of the form: | |
112 | 1. r<reg_num> which has the value <reg_num>. | |
113 | 2. r.<reg_num> which has the value <reg_num>. | |
114 | ||
5b93d8bb AM |
115 | Each floating point register has predefined names of the form: |
116 | 1. f<reg_num> which has the value <reg_num>. | |
117 | 2. f.<reg_num> which has the value <reg_num>. | |
118 | ||
119 | There are only four floating point registers, and these are | |
120 | commonly labelled 0,2,4 and 6. Thus, there is no f1, f3, etc. | |
121 | ||
5b93d8bb AM |
122 | There are individual registers as well: |
123 | rbase or r.base has the value 3 (base register) | |
124 | rpgt or r.pgt has the value 4 (page origin table pointer) | |
125 | rarg or r.arg has the value 11 (argument pointer) | |
126 | rtca or r.tca has the value 12 (table of contents pointer) | |
127 | rtoc or r.toc has the value 12 (table of contents pointer) | |
128 | sp or r.sp has the value 13 (stack pointer) | |
129 | dsa or r.dsa has the value 13 (stack pointer) | |
130 | lr has the value 14 (link reg) | |
131 | ||
92774660 | 132 | The table is sorted. Suitable for searching by a binary search. */ |
5b93d8bb AM |
133 | |
134 | static const struct pd_reg pre_defined_registers[] = | |
135 | { | |
ea1562b3 NC |
136 | { "arg", 11 }, /* Argument Pointer. */ |
137 | { "base", 3 }, /* Base Reg. */ | |
5b93d8bb | 138 | |
ea1562b3 | 139 | { "f.0", 0 }, /* Floating point registers. */ |
5b93d8bb AM |
140 | { "f.2", 2 }, |
141 | { "f.4", 4 }, | |
142 | { "f.6", 6 }, | |
143 | ||
144 | { "f0", 0 }, | |
145 | { "f2", 2 }, | |
146 | { "f4", 4 }, | |
147 | { "f6", 6 }, | |
148 | ||
ea1562b3 NC |
149 | { "dsa",13 }, /* Stack pointer. */ |
150 | { "lr", 14 }, /* Link Register. */ | |
151 | { "pgt", 4 }, /* Page Origin Table Pointer. */ | |
5b93d8bb | 152 | |
ea1562b3 | 153 | { "r.0", 0 }, /* General Purpose Registers. */ |
5b93d8bb AM |
154 | { "r.1", 1 }, |
155 | { "r.10", 10 }, | |
156 | { "r.11", 11 }, | |
157 | { "r.12", 12 }, | |
158 | { "r.13", 13 }, | |
159 | { "r.14", 14 }, | |
160 | { "r.15", 15 }, | |
161 | { "r.2", 2 }, | |
162 | { "r.3", 3 }, | |
163 | { "r.4", 4 }, | |
164 | { "r.5", 5 }, | |
165 | { "r.6", 6 }, | |
166 | { "r.7", 7 }, | |
167 | { "r.8", 8 }, | |
168 | { "r.9", 9 }, | |
169 | ||
ea1562b3 NC |
170 | { "r.arg", 11 }, /* Argument Pointer. */ |
171 | { "r.base", 3 }, /* Base Reg. */ | |
172 | { "r.dsa", 13 }, /* Stack Pointer. */ | |
173 | { "r.pgt", 4 }, /* Page Origin Table Pointer. */ | |
174 | { "r.sp", 13 }, /* Stack Pointer. */ | |
5b93d8bb | 175 | |
ea1562b3 NC |
176 | { "r.tca", 12 }, /* Pointer to the table of contents. */ |
177 | { "r.toc", 12 }, /* Pointer to the table of contents. */ | |
5b93d8bb | 178 | |
ea1562b3 | 179 | { "r0", 0 }, /* More general purpose registers. */ |
5b93d8bb AM |
180 | { "r1", 1 }, |
181 | { "r10", 10 }, | |
182 | { "r11", 11 }, | |
183 | { "r12", 12 }, | |
184 | { "r13", 13 }, | |
185 | { "r14", 14 }, | |
186 | { "r15", 15 }, | |
187 | { "r2", 2 }, | |
188 | { "r3", 3 }, | |
189 | { "r4", 4 }, | |
190 | { "r5", 5 }, | |
191 | { "r6", 6 }, | |
192 | { "r7", 7 }, | |
193 | { "r8", 8 }, | |
194 | { "r9", 9 }, | |
195 | ||
ea1562b3 | 196 | { "rbase", 3 }, /* Base Reg. */ |
5b93d8bb | 197 | |
ea1562b3 NC |
198 | { "rtca", 12 }, /* Pointer to the table of contents. */ |
199 | { "rtoc", 12 }, /* Pointer to the table of contents. */ | |
5b93d8bb | 200 | |
ea1562b3 | 201 | { "sp", 13 }, /* Stack Pointer. */ |
5b93d8bb AM |
202 | |
203 | }; | |
204 | ||
bc805888 | 205 | #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg)) |
5b93d8bb AM |
206 | |
207 | /* Given NAME, find the register number associated with that name, return | |
208 | the integer value associated with the given name or -1 on failure. */ | |
209 | ||
5b93d8bb | 210 | static int |
ea1562b3 NC |
211 | reg_name_search (const struct pd_reg *regs, |
212 | int regcount, | |
213 | const char *name) | |
5b93d8bb AM |
214 | { |
215 | int middle, low, high; | |
216 | int cmp; | |
217 | ||
218 | low = 0; | |
219 | high = regcount - 1; | |
220 | ||
221 | do | |
222 | { | |
223 | middle = (low + high) / 2; | |
224 | cmp = strcasecmp (name, regs[middle].name); | |
225 | if (cmp < 0) | |
226 | high = middle - 1; | |
227 | else if (cmp > 0) | |
228 | low = middle + 1; | |
229 | else | |
230 | return regs[middle].value; | |
231 | } | |
232 | while (low <= high); | |
233 | ||
234 | return -1; | |
235 | } | |
236 | ||
ea1562b3 NC |
237 | /* Summary of register_name(). |
238 | ||
239 | in: Input_line_pointer points to 1st char of operand. | |
240 | ||
241 | out: An expressionS. | |
242 | The operand may have been a register: in this case, X_op == O_register, | |
243 | X_add_number is set to the register number, and truth is returned. | |
244 | Input_line_pointer->(next non-blank) char after operand, or is in its | |
245 | original state. */ | |
5b93d8bb | 246 | |
b34976b6 | 247 | static bfd_boolean |
ea1562b3 | 248 | register_name (expressionS *expressionP) |
5b93d8bb AM |
249 | { |
250 | int reg_number; | |
251 | char *name; | |
252 | char *start; | |
253 | char c; | |
254 | ||
468cced8 | 255 | /* Find the spelling of the operand. */ |
5b93d8bb | 256 | start = name = input_line_pointer; |
3882b010 | 257 | if (name[0] == '%' && ISALPHA (name[1])) |
5b93d8bb AM |
258 | name = ++input_line_pointer; |
259 | ||
260 | else if (!reg_names_p) | |
b34976b6 | 261 | return FALSE; |
5b93d8bb AM |
262 | |
263 | while (' ' == *name) | |
264 | name = ++input_line_pointer; | |
265 | ||
468cced8 AM |
266 | /* If it's a number, treat it as a number. If it's alpha, look to |
267 | see if it's in the register table. */ | |
3882b010 | 268 | if (!ISALPHA (name[0])) |
ea1562b3 | 269 | reg_number = get_single_number (); |
5b93d8bb AM |
270 | else |
271 | { | |
272 | c = get_symbol_end (); | |
273 | reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name); | |
468cced8 AM |
274 | |
275 | /* Put back the delimiting char. */ | |
276 | *input_line_pointer = c; | |
5b93d8bb AM |
277 | } |
278 | ||
468cced8 | 279 | /* If numeric, make sure its not out of bounds. */ |
5b93d8bb AM |
280 | if ((0 <= reg_number) && (16 >= reg_number)) |
281 | { | |
282 | expressionP->X_op = O_register; | |
283 | expressionP->X_add_number = reg_number; | |
284 | ||
468cced8 | 285 | /* Make the rest nice. */ |
5b93d8bb AM |
286 | expressionP->X_add_symbol = NULL; |
287 | expressionP->X_op_symbol = NULL; | |
b34976b6 | 288 | return TRUE; |
5b93d8bb AM |
289 | } |
290 | ||
468cced8 AM |
291 | /* Reset the line as if we had not done anything. */ |
292 | input_line_pointer = start; | |
b34976b6 | 293 | return FALSE; |
5b93d8bb AM |
294 | } |
295 | \f | |
296 | /* Local variables. */ | |
297 | ||
298 | /* The type of processor we are assembling for. This is one or more | |
299 | of the I370_OPCODE flags defined in opcode/i370.h. */ | |
300 | static int i370_cpu = 0; | |
301 | ||
302 | /* The base register to use for opcode with optional operands. | |
ea1562b3 NC |
303 | We define two of these: "text" and "other". Normally, "text" |
304 | would get used in the .text section for branches, while "other" | |
305 | gets used in the .data section for address constants. | |
306 | ||
307 | The idea of a second base register in a different section | |
308 | is foreign to the usual HLASM-style semantics; however, it | |
309 | allows us to provide support for dynamically loaded libraries, | |
310 | by allowing us to place address constants in a section other | |
311 | than the text section. The "other" section need not be the | |
312 | .data section, it can be any section that isn't the .text section. | |
313 | ||
314 | Note that HLASM defines a multiple, concurrent .using semantic | |
315 | that we do not: in calculating offsets, it uses either the most | |
316 | recent .using directive, or the one with the smallest displacement. | |
317 | This allows HLASM to support a quasi-block-scope-like behaviour. | |
318 | Handy for people writing assembly by hand ... but not supported | |
319 | by us. */ | |
5b93d8bb AM |
320 | static int i370_using_text_regno = -1; |
321 | static int i370_using_other_regno = -1; | |
322 | ||
ea1562b3 | 323 | /* The base address for address literals. */ |
5b93d8bb AM |
324 | static expressionS i370_using_text_baseaddr; |
325 | static expressionS i370_using_other_baseaddr; | |
326 | ||
ea1562b3 | 327 | /* the "other" section, used only for syntax error detection. */ |
5b93d8bb AM |
328 | static segT i370_other_section = undefined_section; |
329 | ||
330 | /* Opcode hash table. */ | |
331 | static struct hash_control *i370_hash; | |
332 | ||
333 | /* Macro hash table. */ | |
334 | static struct hash_control *i370_macro_hash; | |
335 | ||
336 | #ifdef OBJ_ELF | |
ea1562b3 | 337 | /* What type of shared library support to use. */ |
5b93d8bb AM |
338 | static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE; |
339 | #endif | |
340 | ||
ea1562b3 | 341 | /* Flags to set in the elf header. */ |
5b93d8bb AM |
342 | static flagword i370_flags = 0; |
343 | ||
344 | #ifndef WORKING_DOT_WORD | |
2b4f075a HPN |
345 | int md_short_jump_size = 4; |
346 | int md_long_jump_size = 4; | |
5b93d8bb AM |
347 | #endif |
348 | \f | |
349 | #ifdef OBJ_ELF | |
5a38dc70 | 350 | const char *md_shortopts = "l:um:K:VQ:"; |
5b93d8bb | 351 | #else |
5a38dc70 | 352 | const char *md_shortopts = "um:"; |
5b93d8bb AM |
353 | #endif |
354 | struct option md_longopts[] = | |
355 | { | |
356 | {NULL, no_argument, NULL, 0} | |
357 | }; | |
bc805888 | 358 | size_t md_longopts_size = sizeof (md_longopts); |
5b93d8bb AM |
359 | |
360 | int | |
ea1562b3 | 361 | md_parse_option (int c, char *arg) |
5b93d8bb AM |
362 | { |
363 | switch (c) | |
364 | { | |
365 | case 'u': | |
366 | /* -u means that any undefined symbols should be treated as | |
367 | external, which is the default for gas anyhow. */ | |
368 | break; | |
369 | ||
370 | #ifdef OBJ_ELF | |
371 | case 'K': | |
372 | /* Recognize -K PIC */ | |
373 | if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0) | |
374 | { | |
375 | shlib = SHLIB_PIC; | |
376 | i370_flags |= EF_I370_RELOCATABLE_LIB; | |
377 | } | |
378 | else | |
379 | return 0; | |
380 | ||
381 | break; | |
382 | #endif | |
383 | ||
384 | case 'm': | |
385 | ||
ea1562b3 | 386 | /* -m360 mean to assemble for the ancient 360 architecture. */ |
5b93d8bb AM |
387 | if (strcmp (arg, "360") == 0 || strcmp (arg, "i360") == 0) |
388 | i370_cpu = I370_OPCODE_360; | |
ea1562b3 | 389 | /* -mxa means to assemble for the IBM 370 XA. */ |
5b93d8bb AM |
390 | else if (strcmp (arg, "xa") == 0) |
391 | i370_cpu = I370_OPCODE_370_XA; | |
392 | /* -many means to assemble for any architecture (370/XA). */ | |
393 | else if (strcmp (arg, "any") == 0) | |
394 | i370_cpu = I370_OPCODE_370; | |
395 | ||
396 | else if (strcmp (arg, "regnames") == 0) | |
b34976b6 | 397 | reg_names_p = TRUE; |
5b93d8bb AM |
398 | |
399 | else if (strcmp (arg, "no-regnames") == 0) | |
b34976b6 | 400 | reg_names_p = FALSE; |
5b93d8bb AM |
401 | |
402 | #ifdef OBJ_ELF | |
ea1562b3 NC |
403 | /* -mrelocatable/-mrelocatable-lib -- warn about |
404 | initializations that require relocation. */ | |
5b93d8bb AM |
405 | else if (strcmp (arg, "relocatable") == 0) |
406 | { | |
407 | shlib = SHILB_MRELOCATABLE; | |
408 | i370_flags |= EF_I370_RELOCATABLE; | |
409 | } | |
5b93d8bb AM |
410 | else if (strcmp (arg, "relocatable-lib") == 0) |
411 | { | |
412 | shlib = SHILB_MRELOCATABLE; | |
413 | i370_flags |= EF_I370_RELOCATABLE_LIB; | |
414 | } | |
5b93d8bb AM |
415 | #endif |
416 | else | |
417 | { | |
20203fb9 | 418 | as_bad (_("invalid switch -m%s"), arg); |
5b93d8bb AM |
419 | return 0; |
420 | } | |
421 | break; | |
422 | ||
423 | #ifdef OBJ_ELF | |
424 | /* -V: SVR4 argument to print version ID. */ | |
425 | case 'V': | |
426 | print_version_id (); | |
427 | break; | |
428 | ||
429 | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section | |
430 | should be emitted or not. FIXME: Not implemented. */ | |
431 | case 'Q': | |
432 | break; | |
433 | ||
434 | #endif | |
435 | ||
436 | default: | |
437 | return 0; | |
438 | } | |
439 | ||
440 | return 1; | |
441 | } | |
442 | ||
443 | \f | |
444 | /* Set i370_cpu if it is not already set. | |
445 | Currently defaults to the reasonable superset; | |
92774660 | 446 | but can be made more fine grained if desred. */ |
5b93d8bb AM |
447 | |
448 | static void | |
ea1562b3 | 449 | i370_set_cpu (void) |
5b93d8bb AM |
450 | { |
451 | const char *default_os = TARGET_OS; | |
452 | const char *default_cpu = TARGET_CPU; | |
453 | ||
ea1562b3 | 454 | /* Override with the superset for the moment. */ |
5b93d8bb AM |
455 | i370_cpu = I370_OPCODE_ESA390_SUPERSET; |
456 | if (i370_cpu == 0) | |
457 | { | |
458 | if (strcmp (default_cpu, "i360") == 0) | |
459 | i370_cpu = I370_OPCODE_360; | |
460 | else if (strcmp (default_cpu, "i370") == 0) | |
461 | i370_cpu = I370_OPCODE_370; | |
462 | else if (strcmp (default_cpu, "XA") == 0) | |
463 | i370_cpu = I370_OPCODE_370_XA; | |
464 | else | |
465 | as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os); | |
466 | } | |
467 | } | |
468 | ||
ea1562b3 NC |
469 | /* Figure out the BFD architecture to use. |
470 | FIXME: specify the different 370 architectures. */ | |
5b93d8bb AM |
471 | |
472 | enum bfd_architecture | |
ea1562b3 | 473 | i370_arch (void) |
5b93d8bb AM |
474 | { |
475 | return bfd_arch_i370; | |
476 | } | |
477 | ||
478 | /* This function is called when the assembler starts up. It is called | |
479 | after the options have been parsed and the output file has been | |
480 | opened. */ | |
481 | ||
482 | void | |
ea1562b3 | 483 | md_begin (void) |
5b93d8bb | 484 | { |
ea1562b3 | 485 | const struct i370_opcode *op; |
5b93d8bb AM |
486 | const struct i370_opcode *op_end; |
487 | const struct i370_macro *macro; | |
488 | const struct i370_macro *macro_end; | |
b34976b6 | 489 | bfd_boolean dup_insn = FALSE; |
5b93d8bb AM |
490 | |
491 | i370_set_cpu (); | |
492 | ||
493 | #ifdef OBJ_ELF | |
92774660 | 494 | /* Set the ELF flags if desired. */ |
5b93d8bb AM |
495 | if (i370_flags) |
496 | bfd_set_private_flags (stdoutput, i370_flags); | |
497 | #endif | |
498 | ||
499 | /* Insert the opcodes into a hash table. */ | |
500 | i370_hash = hash_new (); | |
501 | ||
502 | op_end = i370_opcodes + i370_num_opcodes; | |
503 | for (op = i370_opcodes; op < op_end; op++) | |
504 | { | |
c9dea48b AM |
505 | know ((op->opcode.i[0] & op->mask.i[0]) == op->opcode.i[0] |
506 | && (op->opcode.i[1] & op->mask.i[1]) == op->opcode.i[1]); | |
5b93d8bb AM |
507 | |
508 | if ((op->flags & i370_cpu) != 0) | |
509 | { | |
510 | const char *retval; | |
511 | ||
ea1562b3 | 512 | retval = hash_insert (i370_hash, op->name, (void *) op); |
5b93d8bb AM |
513 | if (retval != (const char *) NULL) |
514 | { | |
20203fb9 | 515 | as_bad (_("Internal assembler error for instruction %s"), op->name); |
b34976b6 | 516 | dup_insn = TRUE; |
5b93d8bb AM |
517 | } |
518 | } | |
519 | } | |
520 | ||
521 | /* Insert the macros into a hash table. */ | |
522 | i370_macro_hash = hash_new (); | |
523 | ||
524 | macro_end = i370_macros + i370_num_macros; | |
525 | for (macro = i370_macros; macro < macro_end; macro++) | |
526 | { | |
527 | if ((macro->flags & i370_cpu) != 0) | |
528 | { | |
529 | const char *retval; | |
530 | ||
ea1562b3 | 531 | retval = hash_insert (i370_macro_hash, macro->name, (void *) macro); |
5b93d8bb AM |
532 | if (retval != (const char *) NULL) |
533 | { | |
20203fb9 | 534 | as_bad (_("Internal assembler error for macro %s"), macro->name); |
b34976b6 | 535 | dup_insn = TRUE; |
5b93d8bb AM |
536 | } |
537 | } | |
538 | } | |
539 | ||
540 | if (dup_insn) | |
541 | abort (); | |
542 | } | |
543 | ||
544 | /* Insert an operand value into an instruction. */ | |
545 | ||
546 | static i370_insn_t | |
ea1562b3 NC |
547 | i370_insert_operand (i370_insn_t insn, |
548 | const struct i370_operand *operand, | |
549 | offsetT val) | |
5b93d8bb AM |
550 | { |
551 | if (operand->insert) | |
552 | { | |
553 | const char *errmsg; | |
554 | ||
ea1562b3 | 555 | /* Used for 48-bit insn's. */ |
5b93d8bb AM |
556 | errmsg = NULL; |
557 | insn = (*operand->insert) (insn, (long) val, &errmsg); | |
558 | if (errmsg) | |
559 | as_bad ("%s", errmsg); | |
560 | } | |
561 | else | |
ea1562b3 NC |
562 | /* This is used only for 16, 32 bit insn's. */ |
563 | insn.i[0] |= (((long) val & ((1 << operand->bits) - 1)) | |
564 | << operand->shift); | |
5b93d8bb AM |
565 | |
566 | return insn; | |
567 | } | |
568 | ||
569 | \f | |
570 | #ifdef OBJ_ELF | |
571 | /* Parse @got, etc. and return the desired relocation. | |
56d27c17 AM |
572 | Currently, i370 does not support (don't really need to support) any |
573 | of these fancier markups ... for example, no one is going to | |
574 | write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me). | |
575 | So basically, we could get away with this routine returning | |
576 | BFD_RELOC_UNUSED in all circumstances. However, I'll leave | |
577 | in for now in case someone ambitious finds a good use for this stuff ... | |
578 | this routine was pretty much just copied from the powerpc code ... */ | |
ea1562b3 | 579 | |
5b93d8bb | 580 | static bfd_reloc_code_real_type |
ea1562b3 | 581 | i370_elf_suffix (char **str_p, expressionS *exp_p) |
5b93d8bb AM |
582 | { |
583 | struct map_bfd | |
584 | { | |
585 | char *string; | |
586 | int length; | |
587 | bfd_reloc_code_real_type reloc; | |
588 | }; | |
589 | ||
590 | char ident[20]; | |
591 | char *str = *str_p; | |
592 | char *str2; | |
593 | int ch; | |
594 | int len; | |
595 | struct map_bfd *ptr; | |
596 | ||
ea1562b3 | 597 | #define MAP(str,reloc) { str, sizeof (str) - 1, reloc } |
5b93d8bb AM |
598 | |
599 | static struct map_bfd mapping[] = | |
600 | { | |
56d27c17 AM |
601 | /* warnings with -mrelocatable. */ |
602 | MAP ("fixup", BFD_RELOC_CTOR), | |
603 | { (char *)0, 0, BFD_RELOC_UNUSED } | |
5b93d8bb AM |
604 | }; |
605 | ||
606 | if (*str++ != '@') | |
607 | return BFD_RELOC_UNUSED; | |
608 | ||
609 | for (ch = *str, str2 = ident; | |
610 | (str2 < ident + sizeof (ident) - 1 | |
3882b010 | 611 | && (ISALNUM (ch) || ch == '@')); |
5b93d8bb | 612 | ch = *++str) |
ea1562b3 | 613 | *str2++ = TOLOWER (ch); |
5b93d8bb AM |
614 | |
615 | *str2 = '\0'; | |
616 | len = str2 - ident; | |
617 | ||
618 | ch = ident[0]; | |
619 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
620 | if (ch == ptr->string[0] | |
621 | && len == ptr->length | |
622 | && memcmp (ident, ptr->string, ptr->length) == 0) | |
623 | { | |
624 | if (exp_p->X_add_number != 0 | |
625 | && (ptr->reloc == BFD_RELOC_16_GOTOFF | |
626 | || ptr->reloc == BFD_RELOC_LO16_GOTOFF | |
627 | || ptr->reloc == BFD_RELOC_HI16_GOTOFF | |
628 | || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF)) | |
20203fb9 | 629 | as_warn (_("identifier+constant@got means identifier@got+constant")); |
5b93d8bb AM |
630 | |
631 | /* Now check for identifier@suffix+constant */ | |
632 | if (*str == '-' || *str == '+') | |
633 | { | |
634 | char *orig_line = input_line_pointer; | |
635 | expressionS new_exp; | |
636 | ||
637 | input_line_pointer = str; | |
638 | expression (&new_exp); | |
639 | if (new_exp.X_op == O_constant) | |
640 | { | |
641 | exp_p->X_add_number += new_exp.X_add_number; | |
642 | str = input_line_pointer; | |
643 | } | |
644 | ||
645 | if (&input_line_pointer != str_p) | |
646 | input_line_pointer = orig_line; | |
647 | } | |
648 | ||
649 | *str_p = str; | |
650 | return ptr->reloc; | |
651 | } | |
652 | ||
653 | return BFD_RELOC_UNUSED; | |
654 | } | |
655 | ||
ea1562b3 NC |
656 | /* Like normal .long/.short/.word, except support @got, etc. |
657 | Clobbers input_line_pointer, checks end-of-line. */ | |
658 | ||
5b93d8bb | 659 | static void |
ea1562b3 | 660 | i370_elf_cons (int nbytes) /* 1=.byte, 2=.word, 4=.long. */ |
5b93d8bb AM |
661 | { |
662 | expressionS exp; | |
663 | bfd_reloc_code_real_type reloc; | |
664 | ||
665 | if (is_it_end_of_statement ()) | |
666 | { | |
667 | demand_empty_rest_of_line (); | |
668 | return; | |
669 | } | |
670 | ||
671 | do | |
672 | { | |
673 | expression (&exp); | |
ea1562b3 | 674 | |
5b93d8bb AM |
675 | if (exp.X_op == O_symbol |
676 | && *input_line_pointer == '@' | |
677 | && (reloc = i370_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED) | |
678 | { | |
679 | reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
680 | int size = bfd_get_reloc_size (reloc_howto); | |
681 | ||
682 | if (size > nbytes) | |
20203fb9 NC |
683 | as_bad (_("%s relocations do not fit in %d bytes\n"), |
684 | reloc_howto->name, nbytes); | |
5b93d8bb AM |
685 | else |
686 | { | |
ea1562b3 | 687 | char *p = frag_more ((int) nbytes); |
5b93d8bb AM |
688 | int offset = nbytes - size; |
689 | ||
690 | fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc); | |
691 | } | |
692 | } | |
693 | else | |
694 | emit_expr (&exp, (unsigned int) nbytes); | |
695 | } | |
696 | while (*input_line_pointer++ == ','); | |
697 | ||
92774660 | 698 | input_line_pointer--; /* Put terminator back into stream. */ |
5b93d8bb AM |
699 | demand_empty_rest_of_line (); |
700 | } | |
701 | ||
702 | \f | |
703 | /* ASCII to EBCDIC conversion table. */ | |
704 | static unsigned char ascebc[256] = | |
705 | { | |
706 | /*00 NL SH SX EX ET NQ AK BL */ | |
707 | 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F, | |
708 | /*08 BS HT LF VT FF CR SO SI */ | |
709 | 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | |
710 | /*10 DL D1 D2 D3 D4 NK SN EB */ | |
711 | 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26, | |
712 | /*18 CN EM SB EC FS GS RS US */ | |
713 | 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F, | |
714 | /*20 SP ! " # $ % & ' */ | |
715 | 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D, | |
716 | /*28 ( ) * + , - . / */ | |
717 | 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61, | |
718 | /*30 0 1 2 3 4 5 6 7 */ | |
719 | 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, | |
720 | /*38 8 9 : ; < = > ? */ | |
721 | 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F, | |
722 | /*40 @ A B C D E F G */ | |
723 | 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, | |
724 | /*48 H I J K L M N O */ | |
725 | 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, | |
726 | /*50 P Q R S T U V W */ | |
727 | 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, | |
728 | /*58 X Y Z [ \ ] ^ _ */ | |
729 | 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D, | |
730 | /*60 ` a b c d e f g */ | |
731 | 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, | |
732 | /*68 h i j k l m n o */ | |
733 | 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, | |
734 | /*70 p q r s t u v w */ | |
735 | 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, | |
736 | /*78 x y z { | } ~ DL */ | |
737 | 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07, | |
738 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
739 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
740 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
741 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
742 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
743 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
744 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
745 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
746 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
747 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
748 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
749 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
750 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
751 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
752 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, | |
753 | 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF | |
754 | }; | |
755 | ||
756 | /* EBCDIC to ASCII conversion table. */ | |
757 | unsigned char ebcasc[256] = | |
758 | { | |
759 | /*00 NU SH SX EX PF HT LC DL */ | |
760 | 0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F, | |
761 | /*08 SM VT FF CR SO SI */ | |
762 | 0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | |
763 | /*10 DE D1 D2 TM RS NL BS IL */ | |
764 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00, | |
765 | /*18 CN EM CC C1 FS GS RS US */ | |
766 | 0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F, | |
767 | /*20 DS SS FS BP LF EB EC */ | |
768 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B, | |
769 | /*28 SM C2 EQ AK BL */ | |
770 | 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00, | |
771 | /*30 SY PN RS UC ET */ | |
772 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, | |
773 | /*38 C3 D4 NK SU */ | |
774 | 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A, | |
775 | /*40 SP */ | |
776 | 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
777 | /*48 . < ( + | */ | |
778 | 0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C, | |
779 | /*50 & */ | |
780 | 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
781 | /*58 ! $ * ) ; ^ */ | |
782 | 0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E, | |
783 | /*60 - / */ | |
784 | 0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
785 | /*68 , % _ > ? */ | |
786 | 0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, | |
787 | /*70 */ | |
788 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
789 | /*78 ` : # @ ' = " */ | |
790 | 0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, | |
791 | /*80 a b c d e f g */ | |
792 | 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, | |
793 | /*88 h i { */ | |
794 | 0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00, | |
795 | /*90 j k l m n o p */ | |
796 | 0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, | |
797 | /*98 q r } */ | |
798 | 0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00, | |
799 | /*A0 ~ s t u v w x */ | |
800 | 0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, | |
801 | /*A8 y z [ */ | |
802 | 0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00, | |
803 | /*B0 */ | |
804 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
805 | /*B8 ] */ | |
806 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00, | |
807 | /*C0 { A B C D E F G */ | |
808 | 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | |
809 | /*C8 H I */ | |
810 | 0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
811 | /*D0 } J K L M N O P */ | |
812 | 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, | |
813 | /*D8 Q R */ | |
814 | 0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
815 | /*E0 \ S T U V W X */ | |
816 | 0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, | |
817 | /*E8 Y Z */ | |
818 | 0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | |
819 | /*F0 0 1 2 3 4 5 6 7 */ | |
820 | 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, | |
821 | /*F8 8 9 */ | |
822 | 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF | |
823 | }; | |
824 | ||
ea1562b3 NC |
825 | /* EBCDIC translation tables needed for 3270 support. */ |
826 | ||
5b93d8bb | 827 | static void |
ea1562b3 | 828 | i370_ebcdic (int unused ATTRIBUTE_UNUSED) |
5b93d8bb AM |
829 | { |
830 | char *p, *end; | |
831 | char delim = 0; | |
832 | size_t nbytes; | |
833 | ||
834 | nbytes = strlen (input_line_pointer); | |
835 | end = input_line_pointer + nbytes; | |
836 | while ('\r' == *end) end --; | |
837 | while ('\n' == *end) end --; | |
838 | ||
839 | delim = *input_line_pointer; | |
ea1562b3 NC |
840 | if (('\'' == delim) || ('\"' == delim)) |
841 | { | |
842 | input_line_pointer ++; | |
843 | end = rindex (input_line_pointer, delim); | |
844 | } | |
5b93d8bb AM |
845 | |
846 | if (end > input_line_pointer) | |
847 | { | |
848 | nbytes = end - input_line_pointer +1; | |
849 | p = frag_more (nbytes); | |
850 | while (end > input_line_pointer) | |
851 | { | |
bc805888 | 852 | *p = ascebc [(unsigned char) (*input_line_pointer)]; |
5b93d8bb AM |
853 | ++p; ++input_line_pointer; |
854 | } | |
855 | *p = '\0'; | |
856 | } | |
857 | if (delim == *input_line_pointer) ++input_line_pointer; | |
858 | } | |
859 | ||
860 | \f | |
ea1562b3 NC |
861 | /* Stub out a couple of routines. */ |
862 | ||
5b93d8bb | 863 | static void |
ea1562b3 | 864 | i370_rmode (int unused ATTRIBUTE_UNUSED) |
5b93d8bb AM |
865 | { |
866 | as_tsktsk ("rmode ignored"); | |
867 | } | |
868 | ||
869 | static void | |
ea1562b3 | 870 | i370_dsect (int sect) |
5b93d8bb AM |
871 | { |
872 | char *save_line = input_line_pointer; | |
873 | static char section[] = ".data\n"; | |
874 | ||
ea1562b3 | 875 | /* Just pretend this is .section .data. */ |
5b93d8bb AM |
876 | input_line_pointer = section; |
877 | obj_elf_section (sect); | |
878 | ||
879 | input_line_pointer = save_line; | |
880 | } | |
881 | ||
882 | static void | |
ea1562b3 | 883 | i370_csect (int unused ATTRIBUTE_UNUSED) |
5b93d8bb AM |
884 | { |
885 | as_tsktsk ("csect not supported"); | |
886 | } | |
887 | ||
888 | \f | |
889 | /* DC Define Const is only partially supported. | |
ea1562b3 NC |
890 | For samplecode on what to do, look at i370_elf_cons() above. |
891 | This code handles pseudoops of the style | |
892 | DC D'3.141592653' # in sysv4, .double 3.14159265 | |
893 | DC F'1' # in sysv4, .long 1. */ | |
894 | ||
5b93d8bb | 895 | static void |
ea1562b3 | 896 | i370_dc (int unused ATTRIBUTE_UNUSED) |
5b93d8bb AM |
897 | { |
898 | char * p, tmp[50]; | |
899 | int nbytes=0; | |
900 | expressionS exp; | |
901 | char type=0; | |
91d6fa6a | 902 | char * clse; |
5b93d8bb AM |
903 | |
904 | if (is_it_end_of_statement ()) | |
905 | { | |
906 | demand_empty_rest_of_line (); | |
907 | return; | |
908 | } | |
909 | ||
ea1562b3 | 910 | /* Figure out the size. */ |
5b93d8bb AM |
911 | type = *input_line_pointer++; |
912 | switch (type) | |
913 | { | |
914 | case 'H': /* 16-bit */ | |
915 | nbytes = 2; | |
916 | break; | |
917 | case 'E': /* 32-bit */ | |
918 | case 'F': /* 32-bit */ | |
919 | nbytes = 4; | |
920 | break; | |
921 | case 'D': /* 64-bit */ | |
922 | nbytes = 8; | |
923 | break; | |
924 | default: | |
20203fb9 | 925 | as_bad (_("unsupported DC type")); |
5b93d8bb AM |
926 | return; |
927 | } | |
928 | ||
ea1562b3 | 929 | /* Get rid of pesky quotes. */ |
5b93d8bb AM |
930 | if ('\'' == *input_line_pointer) |
931 | { | |
5b93d8bb | 932 | ++input_line_pointer; |
91d6fa6a NC |
933 | clse = strchr (input_line_pointer, '\''); |
934 | if (clse) | |
935 | *clse= ' '; | |
5b93d8bb | 936 | else |
20203fb9 | 937 | as_bad (_("missing end-quote")); |
5b93d8bb | 938 | } |
ea1562b3 | 939 | |
5b93d8bb AM |
940 | if ('\"' == *input_line_pointer) |
941 | { | |
5b93d8bb | 942 | ++input_line_pointer; |
91d6fa6a NC |
943 | clse = strchr (input_line_pointer, '\"'); |
944 | if (clse) | |
945 | *clse= ' '; | |
5b93d8bb | 946 | else |
20203fb9 | 947 | as_bad (_("missing end-quote")); |
5b93d8bb AM |
948 | } |
949 | ||
950 | switch (type) | |
951 | { | |
952 | case 'H': /* 16-bit */ | |
953 | case 'F': /* 32-bit */ | |
954 | expression (&exp); | |
955 | emit_expr (&exp, nbytes); | |
956 | break; | |
957 | case 'E': /* 32-bit */ | |
499ac353 | 958 | type = 'f'; |
5b93d8bb AM |
959 | case 'D': /* 64-bit */ |
960 | md_atof (type, tmp, &nbytes); | |
961 | p = frag_more (nbytes); | |
962 | memcpy (p, tmp, nbytes); | |
963 | break; | |
964 | default: | |
20203fb9 | 965 | as_bad (_("unsupported DC type")); |
5b93d8bb AM |
966 | return; |
967 | } | |
968 | ||
969 | demand_empty_rest_of_line (); | |
970 | } | |
971 | ||
972 | \f | |
ea1562b3 NC |
973 | /* Provide minimal support for DS Define Storage. */ |
974 | ||
5b93d8bb | 975 | static void |
ea1562b3 | 976 | i370_ds (int unused ATTRIBUTE_UNUSED) |
5b93d8bb | 977 | { |
ea1562b3 | 978 | /* DS 0H or DS 0F or DS 0D. */ |
5b93d8bb AM |
979 | if ('0' == *input_line_pointer) |
980 | { | |
ea1562b3 | 981 | int alignment = 0; /* Left shift 1 << align. */ |
5b93d8bb AM |
982 | input_line_pointer ++; |
983 | switch (*input_line_pointer++) | |
984 | { | |
985 | case 'H': /* 16-bit */ | |
986 | alignment = 1; | |
987 | break; | |
988 | case 'F': /* 32-bit */ | |
989 | alignment = 2; | |
990 | break; | |
991 | case 'D': /* 64-bit */ | |
992 | alignment = 3; | |
993 | break; | |
994 | default: | |
20203fb9 | 995 | as_bad (_("unsupported alignment")); |
5b93d8bb AM |
996 | return; |
997 | } | |
998 | frag_align (alignment, 0, 0); | |
999 | record_alignment (now_seg, alignment); | |
1000 | } | |
1001 | else | |
20203fb9 | 1002 | as_bad (_("this DS form not yet supported")); |
5b93d8bb AM |
1003 | } |
1004 | ||
1005 | /* Solaris pseudo op to change to the .rodata section. */ | |
ea1562b3 | 1006 | |
5b93d8bb | 1007 | static void |
ea1562b3 | 1008 | i370_elf_rdata (int sect) |
5b93d8bb AM |
1009 | { |
1010 | char *save_line = input_line_pointer; | |
1011 | static char section[] = ".rodata\n"; | |
1012 | ||
ea1562b3 | 1013 | /* Just pretend this is .section .rodata. */ |
5b93d8bb AM |
1014 | input_line_pointer = section; |
1015 | obj_elf_section (sect); | |
1016 | ||
1017 | input_line_pointer = save_line; | |
1018 | } | |
1019 | ||
ea1562b3 NC |
1020 | /* Pseudo op to make file scope bss items. */ |
1021 | ||
5b93d8bb | 1022 | static void |
ea1562b3 | 1023 | i370_elf_lcomm (int unused ATTRIBUTE_UNUSED) |
5b93d8bb | 1024 | { |
ea1562b3 NC |
1025 | char *name; |
1026 | char c; | |
1027 | char *p; | |
5b93d8bb | 1028 | offsetT size; |
ea1562b3 | 1029 | symbolS *symbolP; |
5b93d8bb AM |
1030 | offsetT align; |
1031 | segT old_sec; | |
1032 | int old_subsec; | |
1033 | char *pfrag; | |
1034 | int align2; | |
1035 | ||
1036 | name = input_line_pointer; | |
1037 | c = get_symbol_end (); | |
1038 | ||
ea1562b3 | 1039 | /* Just after name is now '\0'. */ |
5b93d8bb AM |
1040 | p = input_line_pointer; |
1041 | *p = c; | |
1042 | SKIP_WHITESPACE (); | |
1043 | if (*input_line_pointer != ',') | |
1044 | { | |
20203fb9 | 1045 | as_bad (_("Expected comma after symbol-name: rest of line ignored.")); |
5b93d8bb AM |
1046 | ignore_rest_of_line (); |
1047 | return; | |
1048 | } | |
1049 | ||
ea1562b3 NC |
1050 | /* Skip ','. */ |
1051 | input_line_pointer++; | |
5b93d8bb AM |
1052 | if ((size = get_absolute_expression ()) < 0) |
1053 | { | |
20203fb9 | 1054 | as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size); |
5b93d8bb AM |
1055 | ignore_rest_of_line (); |
1056 | return; | |
1057 | } | |
1058 | ||
1059 | /* The third argument to .lcomm is the alignment. */ | |
1060 | if (*input_line_pointer != ',') | |
1061 | align = 8; | |
1062 | else | |
1063 | { | |
1064 | ++input_line_pointer; | |
1065 | align = get_absolute_expression (); | |
1066 | if (align <= 0) | |
1067 | { | |
20203fb9 | 1068 | as_warn (_("ignoring bad alignment")); |
5b93d8bb AM |
1069 | align = 8; |
1070 | } | |
1071 | } | |
1072 | ||
1073 | *p = 0; | |
1074 | symbolP = symbol_find_or_make (name); | |
1075 | *p = c; | |
1076 | ||
1077 | if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP)) | |
1078 | { | |
20203fb9 | 1079 | as_bad (_("Ignoring attempt to re-define symbol `%s'."), |
5b93d8bb AM |
1080 | S_GET_NAME (symbolP)); |
1081 | ignore_rest_of_line (); | |
1082 | return; | |
1083 | } | |
1084 | ||
1085 | if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size) | |
1086 | { | |
20203fb9 | 1087 | as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."), |
5b93d8bb AM |
1088 | S_GET_NAME (symbolP), |
1089 | (long) S_GET_VALUE (symbolP), | |
1090 | (long) size); | |
1091 | ||
1092 | ignore_rest_of_line (); | |
1093 | return; | |
1094 | } | |
1095 | ||
ea1562b3 | 1096 | /* Allocate_bss: */ |
5b93d8bb AM |
1097 | old_sec = now_seg; |
1098 | old_subsec = now_subseg; | |
1099 | if (align) | |
1100 | { | |
ea1562b3 | 1101 | /* Convert to a power of 2 alignment. */ |
5b93d8bb AM |
1102 | for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2) |
1103 | ; | |
1104 | if (align != 1) | |
1105 | { | |
20203fb9 | 1106 | as_bad (_("Common alignment not a power of 2")); |
5b93d8bb AM |
1107 | ignore_rest_of_line (); |
1108 | return; | |
1109 | } | |
1110 | } | |
1111 | else | |
1112 | align2 = 0; | |
1113 | ||
1114 | record_alignment (bss_section, align2); | |
1115 | subseg_set (bss_section, 0); | |
1116 | if (align2) | |
1117 | frag_align (align2, 0, 0); | |
1118 | if (S_GET_SEGMENT (symbolP) == bss_section) | |
1119 | symbol_get_frag (symbolP)->fr_symbol = 0; | |
1120 | symbol_set_frag (symbolP, frag_now); | |
1121 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size, | |
1122 | (char *) 0); | |
1123 | *pfrag = 0; | |
1124 | S_SET_SIZE (symbolP, size); | |
1125 | S_SET_SEGMENT (symbolP, bss_section); | |
1126 | subseg_set (old_sec, old_subsec); | |
1127 | demand_empty_rest_of_line (); | |
1128 | } | |
1129 | ||
1130 | /* Validate any relocations emitted for -mrelocatable, possibly adding | |
1131 | fixups for word relocations in writable segments, so we can adjust | |
1132 | them at runtime. */ | |
ea1562b3 | 1133 | |
5b93d8bb | 1134 | static void |
ea1562b3 | 1135 | i370_elf_validate_fix (fixS *fixp, segT seg) |
5b93d8bb AM |
1136 | { |
1137 | if (fixp->fx_done || fixp->fx_pcrel) | |
1138 | return; | |
1139 | ||
1140 | switch (shlib) | |
1141 | { | |
1142 | case SHLIB_NONE: | |
1143 | case SHLIB_PIC: | |
1144 | return; | |
1145 | ||
1146 | case SHILB_MRELOCATABLE: | |
1147 | if (fixp->fx_r_type <= BFD_RELOC_UNUSED | |
1148 | && fixp->fx_r_type != BFD_RELOC_16_GOTOFF | |
1149 | && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF | |
1150 | && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF | |
1151 | && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF | |
1152 | && fixp->fx_r_type != BFD_RELOC_32_BASEREL | |
1153 | && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL | |
1154 | && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL | |
1155 | && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL | |
1156 | && strcmp (segment_name (seg), ".got2") != 0 | |
1157 | && strcmp (segment_name (seg), ".dtors") != 0 | |
1158 | && strcmp (segment_name (seg), ".ctors") != 0 | |
1159 | && strcmp (segment_name (seg), ".fixup") != 0 | |
1160 | && strcmp (segment_name (seg), ".stab") != 0 | |
1161 | && strcmp (segment_name (seg), ".gcc_except_table") != 0 | |
1162 | && strcmp (segment_name (seg), ".ex_shared") != 0) | |
1163 | { | |
1164 | if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0 | |
1165 | || fixp->fx_r_type != BFD_RELOC_CTOR) | |
ea1562b3 NC |
1166 | as_bad_where (fixp->fx_file, fixp->fx_line, |
1167 | "Relocation cannot be done when using -mrelocatable"); | |
5b93d8bb AM |
1168 | } |
1169 | return; | |
ea1562b3 NC |
1170 | default: |
1171 | break; | |
5b93d8bb AM |
1172 | } |
1173 | } | |
1174 | #endif /* OBJ_ELF */ | |
1175 | ||
5b93d8bb AM |
1176 | \f |
1177 | #define LITERAL_POOL_SUPPORT | |
1178 | #ifdef LITERAL_POOL_SUPPORT | |
ea1562b3 NC |
1179 | /* Provide support for literal pools within the text section. |
1180 | Loosely based on similar code from tc-arm.c. | |
1181 | We will use four symbols to locate four parts of the literal pool. | |
1182 | These four sections contain 64,32,16 and 8-bit constants; we use | |
1183 | four sections so that all memory access can be appropriately aligned. | |
1184 | That is, we want to avoid mixing these together so that we don't | |
1185 | waste space padding out to alignments. The four pointers | |
1186 | longlong_poolP, word_poolP, etc. point to a symbol labeling the | |
1187 | start of each pool part. | |
1188 | ||
1189 | lit_pool_num increments from zero to infinity and uniquely id's | |
1190 | -- its used to generate the *_poolP symbol name. */ | |
5b93d8bb AM |
1191 | |
1192 | #define MAX_LITERAL_POOL_SIZE 1024 | |
1193 | ||
1194 | typedef struct literalS | |
1195 | { | |
1196 | struct expressionS exp; | |
1197 | char * sym_name; | |
1198 | char size; /* 1,2,4 or 8 */ | |
1199 | short offset; | |
1200 | } literalT; | |
1201 | ||
1202 | literalT literals[MAX_LITERAL_POOL_SIZE]; | |
ea1562b3 | 1203 | int next_literal_pool_place = 0; /* Next free entry in the pool. */ |
5b93d8bb | 1204 | |
ea1562b3 NC |
1205 | static symbolS *longlong_poolP = NULL; /* 64-bit pool entries. */ |
1206 | static symbolS *word_poolP = NULL; /* 32-bit pool entries. */ | |
1207 | static symbolS *short_poolP = NULL; /* 16-bit pool entries. */ | |
1208 | static symbolS *byte_poolP = NULL; /* 8-bit pool entries. */ | |
5b93d8bb AM |
1209 | |
1210 | static int lit_pool_num = 1; | |
1211 | ||
ea1562b3 | 1212 | /* Create a new, empty symbol. */ |
5b93d8bb AM |
1213 | static symbolS * |
1214 | symbol_make_empty (void) | |
1215 | { | |
1216 | return symbol_create (FAKE_LABEL_NAME, undefined_section, | |
1217 | (valueT) 0, &zero_address_frag); | |
1218 | } | |
1219 | ||
ea1562b3 NC |
1220 | /* Make the first argument an address-relative expression |
1221 | by subtracting the second argument. */ | |
1222 | ||
1223 | static void | |
1224 | i370_make_relative (expressionS *exx, expressionS *baseaddr) | |
1225 | { | |
1226 | if (O_constant == baseaddr->X_op) | |
1227 | { | |
1228 | exx->X_op = O_symbol; | |
1229 | exx->X_add_number -= baseaddr->X_add_number; | |
1230 | } | |
1231 | else if (O_symbol == baseaddr->X_op) | |
1232 | { | |
1233 | exx->X_op = O_subtract; | |
1234 | exx->X_op_symbol = baseaddr->X_add_symbol; | |
1235 | exx->X_add_number -= baseaddr->X_add_number; | |
1236 | } | |
1237 | else if (O_uminus == baseaddr->X_op) | |
1238 | { | |
1239 | exx->X_op = O_add; | |
1240 | exx->X_op_symbol = baseaddr->X_add_symbol; | |
1241 | exx->X_add_number += baseaddr->X_add_number; | |
1242 | } | |
1243 | else | |
20203fb9 | 1244 | as_bad (_("Missing or bad .using directive")); |
ea1562b3 NC |
1245 | } |
1246 | /* Add an expression to the literal pool. */ | |
1247 | ||
5b93d8bb AM |
1248 | static void |
1249 | add_to_lit_pool (expressionS *exx, char *name, int sz) | |
1250 | { | |
1251 | int lit_count = 0; | |
1252 | int offset_in_pool = 0; | |
1253 | ||
ea1562b3 | 1254 | /* Start a new pool, if necessary. */ |
5b93d8bb | 1255 | if (8 == sz && NULL == longlong_poolP) |
07726851 | 1256 | longlong_poolP = symbol_make_empty (); |
5b93d8bb | 1257 | else if (4 == sz && NULL == word_poolP) |
07726851 | 1258 | word_poolP = symbol_make_empty (); |
5b93d8bb | 1259 | else if (2 == sz && NULL == short_poolP) |
07726851 | 1260 | short_poolP = symbol_make_empty (); |
5b93d8bb | 1261 | else if (1 == sz && NULL == byte_poolP) |
07726851 | 1262 | byte_poolP = symbol_make_empty (); |
5b93d8bb | 1263 | |
ea1562b3 NC |
1264 | /* Check if this literal value is already in the pool. |
1265 | FIXME: We should probably be checking expressions | |
1266 | of type O_symbol as well. | |
1267 | FIXME: This is probably(certainly?) broken for O_big, | |
1268 | which includes 64-bit long-longs. */ | |
5b93d8bb AM |
1269 | while (lit_count < next_literal_pool_place) |
1270 | { | |
1271 | if (exx->X_op == O_constant | |
1272 | && literals[lit_count].exp.X_op == exx->X_op | |
1273 | && literals[lit_count].exp.X_add_number == exx->X_add_number | |
1274 | && literals[lit_count].exp.X_unsigned == exx->X_unsigned | |
1275 | && literals[lit_count].size == sz) | |
1276 | break; | |
1277 | else if (literals[lit_count].sym_name | |
1278 | && name | |
1279 | && !strcmp (name, literals[lit_count].sym_name)) | |
1280 | break; | |
1281 | if (sz == literals[lit_count].size) | |
1282 | offset_in_pool += sz; | |
1283 | lit_count ++; | |
1284 | } | |
1285 | ||
1286 | if (lit_count == next_literal_pool_place) /* new entry */ | |
1287 | { | |
1288 | if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE) | |
20203fb9 | 1289 | as_bad (_("Literal Pool Overflow")); |
5b93d8bb AM |
1290 | |
1291 | literals[next_literal_pool_place].exp = *exx; | |
1292 | literals[next_literal_pool_place].size = sz; | |
1293 | literals[next_literal_pool_place].offset = offset_in_pool; | |
1294 | if (name) | |
ea1562b3 | 1295 | literals[next_literal_pool_place].sym_name = strdup (name); |
5b93d8bb | 1296 | else |
ea1562b3 | 1297 | literals[next_literal_pool_place].sym_name = NULL; |
5b93d8bb AM |
1298 | next_literal_pool_place++; |
1299 | } | |
1300 | ||
0234cb7c | 1301 | /* ???_poolP points to the beginning of the literal pool. |
ea1562b3 NC |
1302 | X_add_number is the offset from the beginning of the |
1303 | literal pool to this expr minus the location of the most | |
1304 | recent .using directive. Thus, the grand total value of the | |
1305 | expression is the distance from .using to the literal. */ | |
5b93d8bb AM |
1306 | if (8 == sz) |
1307 | exx->X_add_symbol = longlong_poolP; | |
1308 | else if (4 == sz) | |
1309 | exx->X_add_symbol = word_poolP; | |
1310 | else if (2 == sz) | |
1311 | exx->X_add_symbol = short_poolP; | |
1312 | else if (1 == sz) | |
1313 | exx->X_add_symbol = byte_poolP; | |
1314 | exx->X_add_number = offset_in_pool; | |
1315 | exx->X_op_symbol = NULL; | |
1316 | ||
1317 | /* If the user has set up a base reg in another section, | |
ea1562b3 | 1318 | use that; otherwise use the text section. */ |
5b93d8bb | 1319 | if (0 < i370_using_other_regno) |
ea1562b3 | 1320 | i370_make_relative (exx, &i370_using_other_baseaddr); |
5b93d8bb | 1321 | else |
ea1562b3 | 1322 | i370_make_relative (exx, &i370_using_text_baseaddr); |
5b93d8bb AM |
1323 | } |
1324 | ||
1325 | /* The symbol setup for the literal pool is done in two steps. First, | |
ea1562b3 NC |
1326 | a symbol that represents the start of the literal pool is created, |
1327 | above, in the add_to_pool() routine. This sym ???_poolP. | |
1328 | However, we don't know what fragment its in until a bit later. | |
1329 | So we defer the frag_now thing, and the symbol name, until .ltorg time. */ | |
5b93d8bb AM |
1330 | |
1331 | /* Can't use symbol_new here, so have to create a symbol and then at | |
ea1562b3 | 1332 | a later date assign it a value. Thats what these functions do. */ |
650f02e9 | 1333 | |
5b93d8bb | 1334 | static void |
ea1562b3 NC |
1335 | symbol_locate (symbolS *symbolP, |
1336 | const char *name, /* It is copied, the caller can modify. */ | |
1337 | segT segment, /* Segment identifier (SEG_<something>). */ | |
1338 | valueT valu, /* Symbol value. */ | |
1339 | fragS *frag) /* Associated fragment. */ | |
5b93d8bb AM |
1340 | { |
1341 | size_t name_length; | |
1342 | char *preserved_copy_of_name; | |
1343 | ||
1344 | name_length = strlen (name) + 1; /* +1 for \0 */ | |
1345 | obstack_grow (¬es, name, name_length); | |
1346 | preserved_copy_of_name = obstack_finish (¬es); | |
1347 | ||
1348 | S_SET_NAME (symbolP, preserved_copy_of_name); | |
1349 | ||
1350 | S_SET_SEGMENT (symbolP, segment); | |
1351 | S_SET_VALUE (symbolP, valu); | |
07726851 | 1352 | symbol_clear_list_pointers (symbolP); |
5b93d8bb AM |
1353 | |
1354 | symbol_set_frag (symbolP, frag); | |
1355 | ||
ea1562b3 | 1356 | /* Link to end of symbol chain. */ |
5b93d8bb AM |
1357 | { |
1358 | extern int symbol_table_frozen; | |
ea1562b3 | 1359 | |
5b93d8bb AM |
1360 | if (symbol_table_frozen) |
1361 | abort (); | |
1362 | } | |
1363 | ||
1364 | symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP); | |
1365 | ||
1366 | obj_symbol_new_hook (symbolP); | |
1367 | ||
1368 | #ifdef tc_symbol_new_hook | |
1369 | tc_symbol_new_hook (symbolP); | |
1370 | #endif | |
1371 | ||
1372 | #define DEBUG_SYMS | |
1373 | #ifdef DEBUG_SYMS | |
1374 | verify_symbol_chain(symbol_rootP, symbol_lastP); | |
1375 | #endif /* DEBUG_SYMS */ | |
1376 | } | |
1377 | ||
1378 | /* i370_addr_offset() will convert operand expressions | |
ea1562b3 NC |
1379 | that appear to be absolute into thier base-register |
1380 | relative form. These expressions come in two types: | |
1381 | ||
1382 | (1) of the form "* + const" * where "*" means | |
1383 | relative offset since the last using | |
1384 | i.e. "*" means ".-using_baseaddr" | |
1385 | ||
1386 | (2) labels, which are never absolute, but are always | |
1387 | relative to the last "using". Anything with an alpha | |
1388 | character is considered to be a label (since symbols | |
1389 | can never be operands), and since we've already handled | |
1390 | register operands. For example, "BL .L33" branch low | |
1391 | to .L33 RX form insn frequently terminates for-loops. */ | |
1392 | ||
b34976b6 | 1393 | static bfd_boolean |
5b93d8bb AM |
1394 | i370_addr_offset (expressionS *exx) |
1395 | { | |
1396 | char *dot, *lab; | |
1397 | int islabel = 0; | |
1398 | int all_digits = 0; | |
1399 | ||
ea1562b3 NC |
1400 | /* Search for a label; anything with an alpha char will do. |
1401 | Local labels consist of N digits followed by either b or f. */ | |
5b93d8bb AM |
1402 | lab = input_line_pointer; |
1403 | while (*lab && (',' != *lab) && ('(' != *lab)) | |
1404 | { | |
3882b010 | 1405 | if (ISDIGIT (*lab)) |
ea1562b3 | 1406 | all_digits = 1; |
3882b010 | 1407 | else if (ISALPHA (*lab)) |
5b93d8bb AM |
1408 | { |
1409 | if (!all_digits) | |
1410 | { | |
1411 | islabel = 1; | |
1412 | break; | |
1413 | } | |
1414 | else if (('f' == *lab) || ('b' == *lab)) | |
1415 | { | |
1416 | islabel = 1; | |
1417 | break; | |
1418 | } | |
1419 | if (all_digits) | |
1420 | break; | |
1421 | } | |
1422 | else if ('.' != *lab) | |
1423 | break; | |
1424 | ++lab; | |
1425 | } | |
1426 | ||
ea1562b3 | 1427 | /* See if operand has a * in it. */ |
5b93d8bb AM |
1428 | dot = strchr (input_line_pointer, '*'); |
1429 | ||
1430 | if (!dot && !islabel) | |
b34976b6 | 1431 | return FALSE; |
5b93d8bb | 1432 | |
ea1562b3 | 1433 | /* Replace * with . and let expr munch on it. */ |
5b93d8bb AM |
1434 | if (dot) |
1435 | *dot = '.'; | |
1436 | expression (exx); | |
1437 | ||
ea1562b3 NC |
1438 | /* OK, now we have to subtract the "using" location. |
1439 | Normally branches appear in the text section only. */ | |
5b93d8bb | 1440 | if (0 == strncmp (now_seg->name, ".text", 5) || 0 > i370_using_other_regno) |
ea1562b3 | 1441 | i370_make_relative (exx, &i370_using_text_baseaddr); |
5b93d8bb | 1442 | else |
ea1562b3 | 1443 | i370_make_relative (exx, &i370_using_other_baseaddr); |
5b93d8bb | 1444 | |
ea1562b3 | 1445 | /* Put the * back. */ |
5b93d8bb AM |
1446 | if (dot) |
1447 | *dot = '*'; | |
1448 | ||
b34976b6 | 1449 | return TRUE; |
5b93d8bb AM |
1450 | } |
1451 | ||
ea1562b3 | 1452 | /* Handle address constants of various sorts. */ |
5b93d8bb | 1453 | /* The currently supported types are |
ea1562b3 NC |
1454 | =A(some_symb) |
1455 | =V(some_extern) | |
1456 | =X'deadbeef' hexadecimal | |
1457 | =F'1234' 32-bit const int | |
1458 | =H'1234' 16-bit const int. */ | |
1459 | ||
b34976b6 | 1460 | static bfd_boolean |
5b93d8bb AM |
1461 | i370_addr_cons (expressionS *exp) |
1462 | { | |
1463 | char *name; | |
1464 | char *sym_name, delim; | |
1465 | int name_len; | |
ea1562b3 NC |
1466 | int hex_len = 0; |
1467 | int cons_len = 0; | |
5b93d8bb AM |
1468 | |
1469 | name = input_line_pointer; | |
1470 | sym_name = input_line_pointer; | |
ea1562b3 | 1471 | /* Find the spelling of the operand. */ |
3882b010 | 1472 | if (name[0] == '=' && ISALPHA (name[1])) |
ea1562b3 | 1473 | name = ++input_line_pointer; |
5b93d8bb | 1474 | else |
ea1562b3 NC |
1475 | return FALSE; |
1476 | ||
5b93d8bb AM |
1477 | switch (name[0]) |
1478 | { | |
ea1562b3 NC |
1479 | case 'A': /* A == address-of. */ |
1480 | case 'V': /* V == extern. */ | |
5b93d8bb AM |
1481 | ++input_line_pointer; |
1482 | expression (exp); | |
1483 | ||
ea1562b3 NC |
1484 | /* We use a simple string name to collapse together |
1485 | multiple refrences to the same address literal. */ | |
5b93d8bb AM |
1486 | name_len = strcspn (sym_name, ", "); |
1487 | delim = *(sym_name + name_len); | |
1488 | *(sym_name + name_len) = 0x0; | |
1489 | add_to_lit_pool (exp, sym_name, 4); | |
1490 | *(sym_name + name_len) = delim; | |
1491 | ||
1492 | break; | |
1493 | case 'H': | |
1494 | case 'F': | |
1495 | case 'X': | |
ea1562b3 NC |
1496 | case 'E': /* Single-precision float point. */ |
1497 | case 'D': /* Double-precision float point. */ | |
5b93d8bb | 1498 | |
ea1562b3 NC |
1499 | /* H == 16-bit fixed-point const; expression must be const. */ |
1500 | /* F == fixed-point const; expression must be const. */ | |
1501 | /* X == fixed-point const; expression must be const. */ | |
5b93d8bb AM |
1502 | if ('H' == name[0]) cons_len = 2; |
1503 | else if ('F' == name[0]) cons_len = 4; | |
1504 | else if ('X' == name[0]) cons_len = -1; | |
1505 | else if ('E' == name[0]) cons_len = 4; | |
1506 | else if ('D' == name[0]) cons_len = 8; | |
1507 | ||
ea1562b3 NC |
1508 | /* Extract length, if it is present; |
1509 | FIXME: assume single-digit length. */ | |
5b93d8bb AM |
1510 | if ('L' == name[1]) |
1511 | { | |
ea1562b3 NC |
1512 | /* Should work for ASCII and EBCDIC. */ |
1513 | cons_len = name[2] - '0'; | |
5b93d8bb AM |
1514 | input_line_pointer += 2; |
1515 | } | |
1516 | ||
1517 | ++input_line_pointer; | |
1518 | ||
ea1562b3 | 1519 | /* Get rid of pesky quotes. */ |
5b93d8bb AM |
1520 | if ('\'' == *input_line_pointer) |
1521 | { | |
91d6fa6a NC |
1522 | char * clse; |
1523 | ||
5b93d8bb | 1524 | ++input_line_pointer; |
91d6fa6a NC |
1525 | clse = strchr (input_line_pointer, '\''); |
1526 | if (clse) | |
1527 | *clse= ' '; | |
5b93d8bb | 1528 | else |
20203fb9 | 1529 | as_bad (_("missing end-quote")); |
5b93d8bb AM |
1530 | } |
1531 | if ('\"' == *input_line_pointer) | |
1532 | { | |
91d6fa6a NC |
1533 | char * clse; |
1534 | ||
5b93d8bb | 1535 | ++input_line_pointer; |
91d6fa6a NC |
1536 | clse = strchr (input_line_pointer, '\"'); |
1537 | if (clse) | |
1538 | *clse= ' '; | |
5b93d8bb | 1539 | else |
20203fb9 | 1540 | as_bad (_("missing end-quote")); |
5b93d8bb AM |
1541 | } |
1542 | if (('X' == name[0]) || ('E' == name[0]) || ('D' == name[0])) | |
1543 | { | |
1544 | char tmp[50]; | |
1545 | char *save; | |
1546 | ||
1547 | /* The length of hex constants is specified directly with L, | |
ea1562b3 NC |
1548 | or implied through the number of hex digits. For example: |
1549 | =X'AB' one byte | |
1550 | =X'abcd' two bytes | |
1551 | =X'000000AB' four bytes | |
1552 | =XL4'AB' four bytes, left-padded withn zero. */ | |
5b93d8bb AM |
1553 | if (('X' == name[0]) && (0 > cons_len)) |
1554 | { | |
1555 | save = input_line_pointer; | |
1556 | while (*save) | |
1557 | { | |
3882b010 | 1558 | if (ISXDIGIT (*save)) |
5b93d8bb AM |
1559 | hex_len++; |
1560 | save++; | |
1561 | } | |
1562 | cons_len = (hex_len+1) /2; | |
1563 | } | |
0234cb7c | 1564 | /* I believe this works even for =XL8'dada0000beeebaaa' |
ea1562b3 NC |
1565 | which should parse out to X_op == O_big |
1566 | Note that floats and doubles get represented as | |
1567 | 0d3.14159265358979 or 0f 2.7. */ | |
5b93d8bb AM |
1568 | tmp[0] = '0'; |
1569 | tmp[1] = name[0]; | |
1570 | tmp[2] = 0; | |
1571 | strcat (tmp, input_line_pointer); | |
1572 | save = input_line_pointer; | |
1573 | input_line_pointer = tmp; | |
1574 | expression (exp); | |
1575 | input_line_pointer = save + (input_line_pointer-tmp-2); | |
1576 | ||
ea1562b3 | 1577 | /* Fix up lengths for floats and doubles. */ |
5b93d8bb | 1578 | if (O_big == exp->X_op) |
ea1562b3 | 1579 | exp->X_add_number = cons_len / CHARS_PER_LITTLENUM; |
5b93d8bb AM |
1580 | } |
1581 | else | |
ea1562b3 NC |
1582 | expression (exp); |
1583 | ||
1584 | /* O_big occurs when more than 4 bytes worth gets parsed. */ | |
5b93d8bb AM |
1585 | if ((exp->X_op != O_constant) && (exp->X_op != O_big)) |
1586 | { | |
20203fb9 | 1587 | as_bad (_("expression not a constant")); |
b34976b6 | 1588 | return FALSE; |
5b93d8bb AM |
1589 | } |
1590 | add_to_lit_pool (exp, 0x0, cons_len); | |
1591 | break; | |
1592 | ||
1593 | default: | |
20203fb9 | 1594 | as_bad (_("Unknown/unsupported address literal type")); |
b34976b6 | 1595 | return FALSE; |
5b93d8bb AM |
1596 | } |
1597 | ||
b34976b6 | 1598 | return TRUE; |
5b93d8bb AM |
1599 | } |
1600 | ||
1601 | \f | |
1602 | /* Dump the contents of the literal pool that we've accumulated so far. | |
ea1562b3 | 1603 | This aligns the pool to the size of the largest literal in the pool. */ |
5b93d8bb AM |
1604 | |
1605 | static void | |
ea1562b3 | 1606 | i370_ltorg (int ignore ATTRIBUTE_UNUSED) |
5b93d8bb AM |
1607 | { |
1608 | int litsize; | |
1609 | int lit_count = 0; | |
1610 | int biggest_literal_size = 0; | |
1611 | int biggest_align = 0; | |
1612 | char pool_name[20]; | |
1613 | ||
1614 | if (strncmp (now_seg->name, ".text", 5)) | |
1615 | { | |
1616 | if (i370_other_section == undefined_section) | |
20203fb9 | 1617 | as_bad (_(".ltorg without prior .using in section %s"), |
ea1562b3 NC |
1618 | now_seg->name); |
1619 | ||
5b93d8bb | 1620 | if (i370_other_section != now_seg) |
20203fb9 | 1621 | as_bad (_(".ltorg in section %s paired to .using in section %s"), |
ea1562b3 | 1622 | now_seg->name, i370_other_section->name); |
5b93d8bb | 1623 | } |
ea1562b3 | 1624 | |
5b93d8bb AM |
1625 | if (! longlong_poolP |
1626 | && ! word_poolP | |
1627 | && ! short_poolP | |
1628 | && ! byte_poolP) | |
ea1562b3 NC |
1629 | /* Nothing to do. */ |
1630 | return; | |
5b93d8bb | 1631 | |
ea1562b3 | 1632 | /* Find largest literal .. 2 4 or 8. */ |
5b93d8bb AM |
1633 | lit_count = 0; |
1634 | while (lit_count < next_literal_pool_place) | |
1635 | { | |
1636 | if (biggest_literal_size < literals[lit_count].size) | |
1637 | biggest_literal_size = literals[lit_count].size; | |
1638 | lit_count ++; | |
1639 | } | |
1640 | if (1 == biggest_literal_size) biggest_align = 0; | |
1641 | else if (2 == biggest_literal_size) biggest_align = 1; | |
1642 | else if (4 == biggest_literal_size) biggest_align = 2; | |
1643 | else if (8 == biggest_literal_size) biggest_align = 3; | |
20203fb9 | 1644 | else as_bad (_("bad alignment of %d bytes in literal pool"), biggest_literal_size); |
5b93d8bb AM |
1645 | if (0 == biggest_align) biggest_align = 1; |
1646 | ||
ea1562b3 | 1647 | /* Align pool for short, word, double word accesses. */ |
5b93d8bb AM |
1648 | frag_align (biggest_align, 0, 0); |
1649 | record_alignment (now_seg, biggest_align); | |
1650 | ||
1651 | /* Note that the gas listing will print only the first five | |
ea1562b3 NC |
1652 | entries in the pool .... wonder how to make it print more. */ |
1653 | /* Output largest literals first, then the smaller ones. */ | |
5b93d8bb AM |
1654 | for (litsize=8; litsize; litsize /=2) |
1655 | { | |
1656 | symbolS *current_poolP = NULL; | |
1657 | switch (litsize) | |
1658 | { | |
1659 | case 8: | |
1660 | current_poolP = longlong_poolP; break; | |
1661 | case 4: | |
1662 | current_poolP = word_poolP; break; | |
1663 | case 2: | |
1664 | current_poolP = short_poolP; break; | |
1665 | case 1: | |
1666 | current_poolP = byte_poolP; break; | |
1667 | default: | |
20203fb9 | 1668 | as_bad (_("bad literal size\n")); |
5b93d8bb AM |
1669 | } |
1670 | if (NULL == current_poolP) | |
1671 | continue; | |
1672 | sprintf (pool_name, ".LITP%01d%06d", litsize, lit_pool_num); | |
1673 | symbol_locate (current_poolP, pool_name, now_seg, | |
1674 | (valueT) frag_now_fix (), frag_now); | |
1675 | symbol_table_insert (current_poolP); | |
1676 | ||
1677 | lit_count = 0; | |
1678 | while (lit_count < next_literal_pool_place) | |
1679 | { | |
1680 | if (litsize == literals[lit_count].size) | |
1681 | { | |
1682 | #define EMIT_ADDR_CONS_SYMBOLS | |
1683 | #ifdef EMIT_ADDR_CONS_SYMBOLS | |
ea1562b3 NC |
1684 | /* Create a bogus symbol, add it to the pool ... |
1685 | For the most part, I think this is a useless exercise, | |
1686 | except that having these symbol names in the objects | |
1687 | is vaguely useful for debugging. */ | |
5b93d8bb AM |
1688 | if (literals[lit_count].sym_name) |
1689 | { | |
07726851 | 1690 | symbolS * symP = symbol_make_empty (); |
5b93d8bb AM |
1691 | symbol_locate (symP, literals[lit_count].sym_name, now_seg, |
1692 | (valueT) frag_now_fix (), frag_now); | |
1693 | symbol_table_insert (symP); | |
1694 | } | |
1695 | #endif /* EMIT_ADDR_CONS_SYMBOLS */ | |
1696 | ||
1697 | emit_expr (&(literals[lit_count].exp), literals[lit_count].size); | |
1698 | } | |
1699 | lit_count ++; | |
1700 | } | |
1701 | } | |
1702 | ||
1703 | next_literal_pool_place = 0; | |
1704 | longlong_poolP = NULL; | |
1705 | word_poolP = NULL; | |
1706 | short_poolP = NULL; | |
1707 | byte_poolP = NULL; | |
1708 | lit_pool_num++; | |
1709 | } | |
1710 | ||
1711 | #endif /* LITERAL_POOL_SUPPORT */ | |
1712 | ||
1713 | \f | |
ea1562b3 NC |
1714 | /* Add support for the HLASM-like USING directive to indicate |
1715 | the base register to use ... we don't support the full | |
1716 | hlasm semantics for this ... we merely pluck a base address | |
1717 | and a register number out. We print a warning if using is | |
1718 | called multiple times. I suppose we should check to see | |
1719 | if the regno is valid. */ | |
1720 | ||
5b93d8bb | 1721 | static void |
ea1562b3 | 1722 | i370_using (int ignore ATTRIBUTE_UNUSED) |
5b93d8bb AM |
1723 | { |
1724 | expressionS ex, baseaddr; | |
1725 | int iregno; | |
1726 | char *star; | |
1727 | ||
ea1562b3 NC |
1728 | /* If "*" appears in a using, it means "." |
1729 | replace it with "." so that expr doesn't get confused. */ | |
5b93d8bb AM |
1730 | star = strchr (input_line_pointer, '*'); |
1731 | if (star) | |
1732 | *star = '.'; | |
1733 | ||
ea1562b3 NC |
1734 | /* The first arg to using will usually be ".", but it can |
1735 | be a more complex expression too. */ | |
5b93d8bb AM |
1736 | expression (&baseaddr); |
1737 | if (star) | |
1738 | *star = '*'; | |
1739 | if (O_constant != baseaddr.X_op | |
1740 | && O_symbol != baseaddr.X_op | |
1741 | && O_uminus != baseaddr.X_op) | |
20203fb9 | 1742 | as_bad (_(".using: base address expression illegal or too complex")); |
5b93d8bb AM |
1743 | |
1744 | if (*input_line_pointer != '\0') ++input_line_pointer; | |
1745 | ||
ea1562b3 | 1746 | /* The second arg to using had better be a register. */ |
5b93d8bb AM |
1747 | register_name (&ex); |
1748 | demand_empty_rest_of_line (); | |
1749 | iregno = ex.X_add_number; | |
1750 | ||
1751 | if (0 == strncmp (now_seg->name, ".text", 5)) | |
1752 | { | |
1753 | i370_using_text_baseaddr = baseaddr; | |
1754 | i370_using_text_regno = iregno; | |
1755 | } | |
1756 | else | |
1757 | { | |
1758 | i370_using_other_baseaddr = baseaddr; | |
1759 | i370_using_other_regno = iregno; | |
1760 | i370_other_section = now_seg; | |
1761 | } | |
1762 | } | |
1763 | ||
1764 | static void | |
ea1562b3 | 1765 | i370_drop (int ignore ATTRIBUTE_UNUSED) |
5b93d8bb AM |
1766 | { |
1767 | expressionS ex; | |
1768 | int iregno; | |
1769 | ||
1770 | register_name (&ex); | |
1771 | demand_empty_rest_of_line (); | |
1772 | iregno = ex.X_add_number; | |
1773 | ||
1774 | if (0 == strncmp (now_seg->name, ".text", 5)) | |
1775 | { | |
1776 | if (iregno != i370_using_text_regno) | |
20203fb9 | 1777 | as_bad (_("droping register %d in section %s does not match using register %d"), |
ea1562b3 NC |
1778 | iregno, now_seg->name, i370_using_text_regno); |
1779 | ||
5b93d8bb AM |
1780 | i370_using_text_regno = -1; |
1781 | i370_using_text_baseaddr.X_op = O_absent; | |
1782 | } | |
1783 | else | |
1784 | { | |
1785 | if (iregno != i370_using_other_regno) | |
20203fb9 | 1786 | as_bad (_("droping register %d in section %s does not match using register %d"), |
ea1562b3 NC |
1787 | iregno, now_seg->name, i370_using_other_regno); |
1788 | ||
5b93d8bb | 1789 | if (i370_other_section != now_seg) |
20203fb9 | 1790 | as_bad (_("droping register %d in section %s previously used in section %s"), |
ea1562b3 NC |
1791 | iregno, now_seg->name, i370_other_section->name); |
1792 | ||
5b93d8bb AM |
1793 | i370_using_other_regno = -1; |
1794 | i370_using_other_baseaddr.X_op = O_absent; | |
1795 | i370_other_section = undefined_section; | |
1796 | } | |
1797 | } | |
1798 | ||
5b93d8bb AM |
1799 | \f |
1800 | /* We need to keep a list of fixups. We can't simply generate them as | |
1801 | we go, because that would require us to first create the frag, and | |
1802 | that would screw up references to ``.''. */ | |
1803 | ||
1804 | struct i370_fixup | |
1805 | { | |
1806 | expressionS exp; | |
1807 | int opindex; | |
1808 | bfd_reloc_code_real_type reloc; | |
1809 | }; | |
1810 | ||
ea1562b3 NC |
1811 | #define MAX_INSN_FIXUPS 5 |
1812 | ||
1813 | /* Handle a macro. Gather all the operands, transform them as | |
1814 | described by the macro, and call md_assemble recursively. All the | |
1815 | operands are separated by commas; we don't accept parentheses | |
1816 | around operands here. */ | |
1817 | ||
1818 | static void | |
1819 | i370_macro (char *str, const struct i370_macro *macro) | |
1820 | { | |
1821 | char *operands[10]; | |
1822 | unsigned int count; | |
1823 | char *s; | |
1824 | unsigned int len; | |
1825 | const char *format; | |
1826 | int arg; | |
1827 | char *send; | |
1828 | char *complete; | |
1829 | ||
1830 | /* Gather the users operands into the operands array. */ | |
1831 | count = 0; | |
1832 | s = str; | |
1833 | while (1) | |
1834 | { | |
1835 | if (count >= sizeof operands / sizeof operands[0]) | |
1836 | break; | |
1837 | operands[count++] = s; | |
1838 | s = strchr (s, ','); | |
1839 | if (s == (char *) NULL) | |
1840 | break; | |
1841 | *s++ = '\0'; | |
1842 | } | |
1843 | ||
1844 | if (count != macro->operands) | |
1845 | { | |
20203fb9 | 1846 | as_bad (_("wrong number of operands")); |
ea1562b3 NC |
1847 | return; |
1848 | } | |
1849 | ||
1850 | /* Work out how large the string must be (the size is unbounded | |
1851 | because it includes user input). */ | |
1852 | len = 0; | |
1853 | format = macro->format; | |
1854 | while (*format != '\0') | |
1855 | { | |
1856 | if (*format != '%') | |
1857 | { | |
1858 | ++len; | |
1859 | ++format; | |
1860 | } | |
1861 | else | |
1862 | { | |
1863 | arg = strtol (format + 1, &send, 10); | |
1864 | know (send != format && arg >= 0 && (unsigned) arg < count); | |
1865 | len += strlen (operands[arg]); | |
1866 | format = send; | |
1867 | } | |
1868 | } | |
1869 | ||
1870 | /* Put the string together. */ | |
1871 | complete = s = alloca (len + 1); | |
1872 | format = macro->format; | |
1873 | while (*format != '\0') | |
1874 | { | |
1875 | if (*format != '%') | |
1876 | *s++ = *format++; | |
1877 | else | |
1878 | { | |
1879 | arg = strtol (format + 1, &send, 10); | |
1880 | strcpy (s, operands[arg]); | |
1881 | s += strlen (s); | |
1882 | format = send; | |
1883 | } | |
1884 | } | |
1885 | *s = '\0'; | |
1886 | ||
1887 | /* Assemble the constructed instruction. */ | |
1888 | md_assemble (complete); | |
1889 | } | |
5b93d8bb AM |
1890 | |
1891 | /* This routine is called for each instruction to be assembled. */ | |
1892 | ||
1893 | void | |
ea1562b3 | 1894 | md_assemble (char *str) |
5b93d8bb | 1895 | { |
87975d2a | 1896 | char *s; |
5b93d8bb AM |
1897 | const struct i370_opcode *opcode; |
1898 | i370_insn_t insn; | |
1899 | const unsigned char *opindex_ptr; | |
1900 | int have_optional_index, have_optional_basereg, have_optional_reg; | |
1901 | int skip_optional_index, skip_optional_basereg, skip_optional_reg; | |
1902 | int use_text=0, use_other=0; | |
1903 | int off_by_one; | |
1904 | struct i370_fixup fixups[MAX_INSN_FIXUPS]; | |
1905 | int fc; | |
1906 | char *f; | |
1907 | int i; | |
1908 | #ifdef OBJ_ELF | |
1909 | bfd_reloc_code_real_type reloc; | |
1910 | #endif | |
1911 | ||
1912 | /* Get the opcode. */ | |
3882b010 | 1913 | for (s = str; *s != '\0' && ! ISSPACE (*s); s++) |
5b93d8bb AM |
1914 | ; |
1915 | if (*s != '\0') | |
1916 | *s++ = '\0'; | |
5b93d8bb AM |
1917 | |
1918 | /* Look up the opcode in the hash table. */ | |
1919 | opcode = (const struct i370_opcode *) hash_find (i370_hash, str); | |
1920 | if (opcode == (const struct i370_opcode *) NULL) | |
1921 | { | |
1922 | const struct i370_macro *macro; | |
1923 | ||
9c2799c2 | 1924 | gas_assert (i370_macro_hash); |
5b93d8bb AM |
1925 | macro = (const struct i370_macro *) hash_find (i370_macro_hash, str); |
1926 | if (macro == (const struct i370_macro *) NULL) | |
20203fb9 | 1927 | as_bad (_("Unrecognized opcode: `%s'"), str); |
5b93d8bb AM |
1928 | else |
1929 | i370_macro (s, macro); | |
1930 | ||
1931 | return; | |
1932 | } | |
1933 | ||
1934 | insn = opcode->opcode; | |
1935 | ||
1936 | str = s; | |
3882b010 | 1937 | while (ISSPACE (*str)) |
5b93d8bb AM |
1938 | ++str; |
1939 | ||
1940 | /* I370 operands are either expressions or address constants. | |
1941 | Many operand types are optional. The optional operands | |
1942 | are always surrounded by parens, and are used to denote the base | |
1943 | register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to | |
1944 | the fully-formed "A R1, D2(X2,B2)". Note also the = sign, | |
1945 | such as A R1,=A(i) where the address-of operator =A implies | |
1946 | use of both a base register, and a missing index register. | |
1947 | ||
1948 | So, before we start seriously parsing the operands, we check | |
1949 | to see if we have an optional operand, and, if we do, we count | |
1950 | the number of commas to see which operand should be omitted. */ | |
1951 | ||
1952 | have_optional_index = have_optional_basereg = have_optional_reg = 0; | |
1953 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) | |
1954 | { | |
1955 | const struct i370_operand *operand; | |
ea1562b3 | 1956 | |
5b93d8bb AM |
1957 | operand = &i370_operands[*opindex_ptr]; |
1958 | if ((operand->flags & I370_OPERAND_INDEX) != 0) | |
1959 | have_optional_index = 1; | |
1960 | if ((operand->flags & I370_OPERAND_BASE) != 0) | |
1961 | have_optional_basereg = 1; | |
1962 | if ((operand->flags & I370_OPERAND_OPTIONAL) != 0) | |
1963 | have_optional_reg = 1; | |
1964 | } | |
1965 | ||
1966 | skip_optional_index = skip_optional_basereg = skip_optional_reg = 0; | |
1967 | if (have_optional_index || have_optional_basereg) | |
1968 | { | |
1969 | unsigned int opcount, nwanted; | |
1970 | ||
1971 | /* There is an optional operand. Count the number of | |
1972 | commas and open-parens in the input line. */ | |
1973 | if (*str == '\0') | |
1974 | opcount = 0; | |
1975 | else | |
1976 | { | |
1977 | opcount = 1; | |
1978 | s = str; | |
1979 | while ((s = strpbrk (s, ",(=")) != (char *) NULL) | |
1980 | { | |
1981 | ++opcount; | |
1982 | ++s; | |
1983 | if (',' == *s) ++s; /* avoid counting things like (, */ | |
1984 | if ('=' == *s) { ++s; --opcount; } | |
1985 | } | |
1986 | } | |
1987 | ||
1988 | /* If there are fewer operands in the line then are called | |
1989 | for by the instruction, we want to skip the optional | |
1990 | operand. */ | |
2132e3a3 | 1991 | nwanted = strlen ((char *) opcode->operands); |
5b93d8bb AM |
1992 | if (have_optional_index) |
1993 | { | |
1994 | if (opcount < nwanted) | |
1995 | skip_optional_index = 1; | |
1996 | if (have_optional_basereg && ((opcount+1) < nwanted)) | |
1997 | skip_optional_basereg = 1; | |
1998 | if (have_optional_reg && ((opcount+1) < nwanted)) | |
1999 | skip_optional_reg = 1; | |
2000 | } | |
2001 | else | |
2002 | { | |
2003 | if (have_optional_basereg && (opcount < nwanted)) | |
2004 | skip_optional_basereg = 1; | |
2005 | if (have_optional_reg && (opcount < nwanted)) | |
2006 | skip_optional_reg = 1; | |
2007 | } | |
2008 | } | |
2009 | ||
2010 | /* Perform some off-by-one hacks on the length field of certain instructions. | |
ea1562b3 NC |
2011 | Its such a shame to have to do this, but the problem is that HLASM got |
2012 | defined so that the lengths differ by one from the actual machine instructions. | |
2013 | this code should probably be moved to a special inster-operand routine. | |
2014 | Sigh. Affected instructions are Compare Logical, Move and Exclusive OR | |
2015 | hack alert -- aren't *all* SS instructions affected ?? */ | |
5b93d8bb AM |
2016 | off_by_one = 0; |
2017 | if (0 == strcasecmp ("CLC", opcode->name) | |
2018 | || 0 == strcasecmp ("ED", opcode->name) | |
2019 | || 0 == strcasecmp ("EDMK", opcode->name) | |
2020 | || 0 == strcasecmp ("MVC", opcode->name) | |
2021 | || 0 == strcasecmp ("MVCIN", opcode->name) | |
2022 | || 0 == strcasecmp ("MVN", opcode->name) | |
2023 | || 0 == strcasecmp ("MVZ", opcode->name) | |
2024 | || 0 == strcasecmp ("NC", opcode->name) | |
2025 | || 0 == strcasecmp ("OC", opcode->name) | |
2026 | || 0 == strcasecmp ("XC", opcode->name)) | |
2027 | off_by_one = 1; | |
2028 | ||
2029 | /* Gather the operands. */ | |
2030 | fc = 0; | |
2031 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) | |
2032 | { | |
2033 | const struct i370_operand *operand; | |
5b93d8bb AM |
2034 | char *hold; |
2035 | expressionS ex; | |
2036 | ||
2037 | operand = &i370_operands[*opindex_ptr]; | |
5b93d8bb AM |
2038 | |
2039 | /* If this is an index operand, and we are skipping it, | |
2040 | just insert a zero. */ | |
2041 | if (skip_optional_index && | |
2042 | ((operand->flags & I370_OPERAND_INDEX) != 0)) | |
2043 | { | |
2044 | insn = i370_insert_operand (insn, operand, 0); | |
2045 | continue; | |
2046 | } | |
2047 | ||
2048 | /* If this is the base operand, and we are skipping it, | |
2049 | just insert the current using basreg. */ | |
2050 | if (skip_optional_basereg && | |
2051 | ((operand->flags & I370_OPERAND_BASE) != 0)) | |
2052 | { | |
2053 | int basereg = -1; | |
2054 | if (use_text) | |
2055 | { | |
2056 | if (0 == strncmp (now_seg->name, ".text", 5) | |
2057 | || 0 > i370_using_other_regno) | |
ea1562b3 | 2058 | basereg = i370_using_text_regno; |
5b93d8bb | 2059 | else |
ea1562b3 | 2060 | basereg = i370_using_other_regno; |
5b93d8bb AM |
2061 | } |
2062 | else if (use_other) | |
2063 | { | |
2064 | if (0 > i370_using_other_regno) | |
ea1562b3 | 2065 | basereg = i370_using_text_regno; |
5b93d8bb | 2066 | else |
ea1562b3 | 2067 | basereg = i370_using_other_regno; |
5b93d8bb AM |
2068 | } |
2069 | if (0 > basereg) | |
20203fb9 | 2070 | as_bad (_("not using any base register")); |
ea1562b3 | 2071 | |
5b93d8bb AM |
2072 | insn = i370_insert_operand (insn, operand, basereg); |
2073 | continue; | |
2074 | } | |
2075 | ||
2076 | /* If this is an optional operand, and we are skipping it, | |
2077 | Use zero (since a non-zero value would denote a register) */ | |
2078 | if (skip_optional_reg | |
2079 | && ((operand->flags & I370_OPERAND_OPTIONAL) != 0)) | |
2080 | { | |
2081 | insn = i370_insert_operand (insn, operand, 0); | |
2082 | continue; | |
2083 | } | |
2084 | ||
2085 | /* Gather the operand. */ | |
2086 | hold = input_line_pointer; | |
2087 | input_line_pointer = str; | |
2088 | ||
ea1562b3 | 2089 | /* Register names are only allowed where there are registers. */ |
5b93d8bb AM |
2090 | if ((operand->flags & I370_OPERAND_GPR) != 0) |
2091 | { | |
ea1562b3 | 2092 | /* Quickie hack to get past things like (,r13). */ |
5b93d8bb AM |
2093 | if (skip_optional_index && (',' == *input_line_pointer)) |
2094 | { | |
2095 | *input_line_pointer = ' '; | |
2096 | input_line_pointer ++; | |
2097 | } | |
ea1562b3 | 2098 | |
5b93d8bb | 2099 | if (! register_name (&ex)) |
20203fb9 | 2100 | as_bad (_("expecting a register for operand %d"), |
8ad7c533 | 2101 | (int) (opindex_ptr - opcode->operands + 1)); |
5b93d8bb AM |
2102 | } |
2103 | ||
b6ff326e | 2104 | /* Check for an address constant expression. */ |
5b93d8bb | 2105 | /* We will put PSW-relative addresses in the text section, |
ea1562b3 | 2106 | and address literals in the .data (or other) section. */ |
5b93d8bb | 2107 | else if (i370_addr_cons (&ex)) |
ea1562b3 | 2108 | use_other = 1; |
5b93d8bb | 2109 | else if (i370_addr_offset (&ex)) |
ea1562b3 | 2110 | use_text = 1; |
5b93d8bb AM |
2111 | else expression (&ex); |
2112 | ||
2113 | str = input_line_pointer; | |
2114 | input_line_pointer = hold; | |
2115 | ||
ea1562b3 NC |
2116 | /* Perform some off-by-one hacks on the length field of certain instructions. |
2117 | Its such a shame to have to do this, but the problem is that HLASM got | |
2118 | defined so that the programmer specifies a length that is one greater | |
2119 | than what the machine instruction wants. Sigh. */ | |
5b93d8bb | 2120 | if (off_by_one && (0 == strcasecmp ("SS L", operand->name))) |
ea1562b3 | 2121 | ex.X_add_number --; |
5b93d8bb AM |
2122 | |
2123 | if (ex.X_op == O_illegal) | |
20203fb9 | 2124 | as_bad (_("illegal operand")); |
5b93d8bb | 2125 | else if (ex.X_op == O_absent) |
20203fb9 | 2126 | as_bad (_("missing operand")); |
5b93d8bb | 2127 | else if (ex.X_op == O_register) |
ea1562b3 | 2128 | insn = i370_insert_operand (insn, operand, ex.X_add_number); |
5b93d8bb AM |
2129 | else if (ex.X_op == O_constant) |
2130 | { | |
2131 | #ifdef OBJ_ELF | |
2132 | /* Allow @HA, @L, @H on constants. | |
ea1562b3 NC |
2133 | Well actually, no we don't; there really don't make sense |
2134 | (at least not to me) for the i370. However, this code is | |
2135 | left here for any dubious future expansion reasons. */ | |
5b93d8bb AM |
2136 | char *orig_str = str; |
2137 | ||
2138 | if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED) | |
2139 | switch (reloc) | |
2140 | { | |
2141 | default: | |
2142 | str = orig_str; | |
2143 | break; | |
2144 | ||
2145 | case BFD_RELOC_LO16: | |
2146 | /* X_unsigned is the default, so if the user has done | |
2147 | something which cleared it, we always produce a | |
2148 | signed value. */ | |
2149 | ex.X_add_number = (((ex.X_add_number & 0xffff) | |
2150 | ^ 0x8000) | |
2151 | - 0x8000); | |
2152 | break; | |
2153 | ||
2154 | case BFD_RELOC_HI16: | |
2155 | ex.X_add_number = (ex.X_add_number >> 16) & 0xffff; | |
2156 | break; | |
2157 | ||
2158 | case BFD_RELOC_HI16_S: | |
2159 | ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff) | |
2160 | + ((ex.X_add_number >> 15) & 1)); | |
2161 | break; | |
2162 | } | |
2163 | #endif | |
2164 | insn = i370_insert_operand (insn, operand, ex.X_add_number); | |
2165 | } | |
2166 | #ifdef OBJ_ELF | |
2167 | else if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED) | |
2168 | { | |
2169 | as_tsktsk ("md_assemble(): suffixed relocations not supported\n"); | |
2170 | ||
2171 | /* We need to generate a fixup for this expression. */ | |
2172 | if (fc >= MAX_INSN_FIXUPS) | |
2173 | as_fatal ("too many fixups"); | |
2174 | fixups[fc].exp = ex; | |
2175 | fixups[fc].opindex = 0; | |
2176 | fixups[fc].reloc = reloc; | |
2177 | ++fc; | |
2178 | } | |
2179 | #endif /* OBJ_ELF */ | |
5b93d8bb AM |
2180 | else |
2181 | { | |
2182 | /* We need to generate a fixup for this expression. */ | |
2183 | /* Typically, the expression will just be a symbol ... | |
ea1562b3 NC |
2184 | printf ("insn %s needs fixup for %s \n", |
2185 | opcode->name, ex.X_add_symbol->bsym->name); */ | |
5b93d8bb AM |
2186 | |
2187 | if (fc >= MAX_INSN_FIXUPS) | |
2188 | as_fatal ("too many fixups"); | |
2189 | fixups[fc].exp = ex; | |
2190 | fixups[fc].opindex = *opindex_ptr; | |
2191 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
2192 | ++fc; | |
2193 | } | |
2194 | ||
ea1562b3 | 2195 | /* Skip over delimiter (close paren, or comma). */ |
5b93d8bb AM |
2196 | if ((')' == *str) && (',' == *(str+1))) |
2197 | ++str; | |
2198 | if (*str != '\0') | |
2199 | ++str; | |
2200 | } | |
2201 | ||
3882b010 | 2202 | while (ISSPACE (*str)) |
5b93d8bb AM |
2203 | ++str; |
2204 | ||
2205 | if (*str != '\0') | |
20203fb9 | 2206 | as_bad (_("junk at end of line: `%s'"), str); |
5b93d8bb AM |
2207 | |
2208 | /* Write out the instruction. */ | |
2209 | f = frag_more (opcode->len); | |
2210 | if (4 >= opcode->len) | |
ea1562b3 | 2211 | md_number_to_chars (f, insn.i[0], opcode->len); |
5b93d8bb AM |
2212 | else |
2213 | { | |
2214 | md_number_to_chars (f, insn.i[0], 4); | |
ea1562b3 | 2215 | |
5b93d8bb | 2216 | if (6 == opcode->len) |
ea1562b3 | 2217 | md_number_to_chars ((f + 4), ((insn.i[1])>>16), 2); |
5b93d8bb AM |
2218 | else |
2219 | { | |
ea1562b3 | 2220 | /* Not used --- don't have any 8 byte instructions. */ |
20203fb9 | 2221 | as_bad (_("Internal Error: bad instruction length")); |
ea1562b3 | 2222 | md_number_to_chars ((f + 4), insn.i[1], opcode->len -4); |
5b93d8bb AM |
2223 | } |
2224 | } | |
2225 | ||
2226 | /* Create any fixups. At this point we do not use a | |
2227 | bfd_reloc_code_real_type, but instead just use the | |
2228 | BFD_RELOC_UNUSED plus the operand index. This lets us easily | |
2229 | handle fixups for any operand type, although that is admittedly | |
2230 | not a very exciting feature. We pick a BFD reloc type in | |
55cf6793 | 2231 | md_apply_fix. */ |
5b93d8bb AM |
2232 | for (i = 0; i < fc; i++) |
2233 | { | |
2234 | const struct i370_operand *operand; | |
2235 | ||
2236 | operand = &i370_operands[fixups[i].opindex]; | |
2237 | if (fixups[i].reloc != BFD_RELOC_UNUSED) | |
2238 | { | |
2239 | reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); | |
2240 | int size; | |
2241 | fixS *fixP; | |
2242 | ||
2243 | if (!reloc_howto) | |
2244 | abort (); | |
2245 | ||
2246 | size = bfd_get_reloc_size (reloc_howto); | |
2247 | ||
2248 | if (size < 1 || size > 4) | |
bc805888 | 2249 | abort (); |
5b93d8bb AM |
2250 | |
2251 | printf (" gwana doo fixup %d \n", i); | |
2252 | fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size, | |
2253 | &fixups[i].exp, reloc_howto->pc_relative, | |
2254 | fixups[i].reloc); | |
2255 | ||
2256 | /* Turn off complaints that the addend is too large for things like | |
2257 | foo+100000@ha. */ | |
2258 | switch (fixups[i].reloc) | |
2259 | { | |
2260 | case BFD_RELOC_16_GOTOFF: | |
2261 | case BFD_RELOC_LO16: | |
2262 | case BFD_RELOC_HI16: | |
2263 | case BFD_RELOC_HI16_S: | |
2264 | fixP->fx_no_overflow = 1; | |
2265 | break; | |
2266 | default: | |
2267 | break; | |
2268 | } | |
2269 | } | |
2270 | else | |
2271 | { | |
2272 | fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->len, | |
2273 | &fixups[i].exp, | |
2274 | (operand->flags & I370_OPERAND_RELATIVE) != 0, | |
2275 | ((bfd_reloc_code_real_type) | |
2276 | (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); | |
2277 | } | |
2278 | } | |
2279 | } | |
2280 | ||
5b93d8bb AM |
2281 | \f |
2282 | /* Pseudo-op handling. */ | |
2283 | ||
2284 | /* The .byte pseudo-op. This is similar to the normal .byte | |
2285 | pseudo-op, but it can also take a single ASCII string. */ | |
2286 | ||
2287 | static void | |
ea1562b3 | 2288 | i370_byte (int ignore ATTRIBUTE_UNUSED) |
5b93d8bb AM |
2289 | { |
2290 | if (*input_line_pointer != '\"') | |
2291 | { | |
2292 | cons (1); | |
2293 | return; | |
2294 | } | |
2295 | ||
2296 | /* Gather characters. A real double quote is doubled. Unusual | |
2297 | characters are not permitted. */ | |
2298 | ++input_line_pointer; | |
2299 | while (1) | |
2300 | { | |
2301 | char c; | |
2302 | ||
2303 | c = *input_line_pointer++; | |
2304 | ||
2305 | if (c == '\"') | |
2306 | { | |
2307 | if (*input_line_pointer != '\"') | |
2308 | break; | |
2309 | ++input_line_pointer; | |
2310 | } | |
2311 | ||
2312 | FRAG_APPEND_1_CHAR (c); | |
2313 | } | |
2314 | ||
2315 | demand_empty_rest_of_line (); | |
2316 | } | |
2317 | \f | |
2318 | /* The .tc pseudo-op. This is used when generating XCOFF and ELF. | |
2319 | This takes two or more arguments. | |
2320 | ||
2321 | When generating XCOFF output, the first argument is the name to | |
2322 | give to this location in the toc; this will be a symbol with class | |
2323 | TC. The rest of the arguments are 4 byte values to actually put at | |
2324 | this location in the TOC; often there is just one more argument, a | |
1049f94e | 2325 | relocatable symbol reference. |
5b93d8bb AM |
2326 | |
2327 | When not generating XCOFF output, the arguments are the same, but | |
2328 | the first argument is simply ignored. */ | |
2329 | ||
2330 | static void | |
ea1562b3 | 2331 | i370_tc (int ignore ATTRIBUTE_UNUSED) |
5b93d8bb AM |
2332 | { |
2333 | ||
2334 | /* Skip the TOC symbol name. */ | |
2335 | while (is_part_of_name (*input_line_pointer) | |
2336 | || *input_line_pointer == '[' | |
2337 | || *input_line_pointer == ']' | |
2338 | || *input_line_pointer == '{' | |
2339 | || *input_line_pointer == '}') | |
2340 | ++input_line_pointer; | |
2341 | ||
2342 | /* Align to a four byte boundary. */ | |
2343 | frag_align (2, 0, 0); | |
2344 | record_alignment (now_seg, 2); | |
2345 | ||
2346 | if (*input_line_pointer != ',') | |
2347 | demand_empty_rest_of_line (); | |
2348 | else | |
2349 | { | |
2350 | ++input_line_pointer; | |
2351 | cons (4); | |
2352 | } | |
2353 | } | |
2354 | \f | |
5b93d8bb | 2355 | char * |
ea1562b3 | 2356 | md_atof (int type, char *litp, int *sizep) |
5b93d8bb | 2357 | { |
5b93d8bb | 2358 | /* 360/370/390 have two float formats: an old, funky 360 single-precision |
499ac353 NC |
2359 | format, and the ieee format. Support only the ieee format. */ |
2360 | return ieee_md_atof (type, litp, sizep, TRUE); | |
5b93d8bb AM |
2361 | } |
2362 | ||
2363 | /* Write a value out to the object file, using the appropriate | |
2364 | endianness. */ | |
2365 | ||
2366 | void | |
ea1562b3 | 2367 | md_number_to_chars (char *buf, valueT val, int n) |
5b93d8bb | 2368 | { |
ea1562b3 | 2369 | number_to_chars_bigendian (buf, val, n); |
5b93d8bb AM |
2370 | } |
2371 | ||
2372 | /* Align a section (I don't know why this is machine dependent). */ | |
2373 | ||
2374 | valueT | |
ea1562b3 | 2375 | md_section_align (asection *seg, valueT addr) |
5b93d8bb AM |
2376 | { |
2377 | int align = bfd_get_section_alignment (stdoutput, seg); | |
2378 | ||
2379 | return (addr + (1 << align) - 1) & (-1 << align); | |
2380 | } | |
2381 | ||
2382 | /* We don't have any form of relaxing. */ | |
2383 | ||
2384 | int | |
ea1562b3 NC |
2385 | md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED, |
2386 | asection *seg ATTRIBUTE_UNUSED) | |
5b93d8bb AM |
2387 | { |
2388 | abort (); | |
2389 | return 0; | |
2390 | } | |
2391 | ||
2392 | /* Convert a machine dependent frag. We never generate these. */ | |
2393 | ||
2394 | void | |
ea1562b3 NC |
2395 | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, |
2396 | asection *sec ATTRIBUTE_UNUSED, | |
2397 | fragS *fragp ATTRIBUTE_UNUSED) | |
5b93d8bb AM |
2398 | { |
2399 | abort (); | |
2400 | } | |
2401 | ||
2402 | /* We have no need to default values of symbols. */ | |
2403 | ||
5b93d8bb | 2404 | symbolS * |
ea1562b3 | 2405 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
5b93d8bb AM |
2406 | { |
2407 | return 0; | |
2408 | } | |
2409 | \f | |
2410 | /* Functions concerning relocs. */ | |
2411 | ||
2412 | /* The location from which a PC relative jump should be calculated, | |
2413 | given a PC relative reloc. */ | |
2414 | ||
2415 | long | |
ea1562b3 | 2416 | md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED) |
5b93d8bb AM |
2417 | { |
2418 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
2419 | } | |
2420 | ||
5b93d8bb AM |
2421 | /* Apply a fixup to the object code. This is called for all the |
2422 | fixups we generated by the call to fix_new_exp, above. In the call | |
2423 | above we used a reloc code which was the largest legal reloc code | |
2424 | plus the operand index. Here we undo that to recover the operand | |
2425 | index. At this point all symbol values should be fully resolved, | |
2426 | and we attempt to completely resolve the reloc. If we can not do | |
2427 | that, we determine the correct reloc code and put it back in the | |
2428 | fixup. | |
2429 | ||
2430 | See gas/cgen.c for more sample code and explanations of what's | |
ea1562b3 | 2431 | going on here. */ |
5b93d8bb | 2432 | |
94f592af | 2433 | void |
55cf6793 | 2434 | md_apply_fix (fixS *fixP, valueT * valP, segT seg) |
5b93d8bb | 2435 | { |
94f592af | 2436 | valueT value = * valP; |
5b93d8bb | 2437 | |
94f592af | 2438 | if (fixP->fx_addsy != NULL) |
5b93d8bb | 2439 | { |
5b93d8bb | 2440 | #ifdef DEBUG |
55cf6793 | 2441 | printf ("\nmd_apply_fix: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n", |
94f592af NC |
2442 | S_GET_NAME (fixP->fx_addsy), |
2443 | fixP->fx_frag->fr_address + fixP->fx_where, | |
2444 | fixP->fx_file, fixP->fx_line, | |
2445 | S_GET_VALUE (fixP->fx_addsy), value); | |
5b93d8bb AM |
2446 | #endif |
2447 | } | |
2448 | else | |
a161fe53 | 2449 | fixP->fx_done = 1; |
5b93d8bb AM |
2450 | |
2451 | /* Apply fixups to operands. Note that there should be no relocations | |
2452 | for any operands, since no instruction ever takes an operand | |
2453 | that requires reloc. */ | |
94f592af | 2454 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
5b93d8bb AM |
2455 | { |
2456 | int opindex; | |
2457 | const struct i370_operand *operand; | |
2458 | char *where; | |
2459 | i370_insn_t insn; | |
2460 | ||
94f592af | 2461 | opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
5b93d8bb AM |
2462 | |
2463 | operand = &i370_operands[opindex]; | |
2464 | ||
2465 | #ifdef DEBUG | |
55cf6793 | 2466 | printf ("\nmd_apply_fix: fixup operand %s at 0x%x in %s:%d addend=0x%x\n", |
5b93d8bb | 2467 | operand->name, |
94f592af NC |
2468 | fixP->fx_frag->fr_address + fixP->fx_where, |
2469 | fixP->fx_file, fixP->fx_line, | |
5b93d8bb AM |
2470 | value); |
2471 | #endif | |
2472 | /* Fetch the instruction, insert the fully resolved operand | |
2473 | value, and stuff the instruction back again. | |
92774660 | 2474 | fisxp->fx_size is the length of the instruction. */ |
94f592af | 2475 | where = fixP->fx_frag->fr_literal + fixP->fx_where; |
5b93d8bb | 2476 | insn.i[0] = bfd_getb32 ((unsigned char *) where); |
94f592af NC |
2477 | |
2478 | if (6 <= fixP->fx_size) | |
2479 | /* Deal with 48-bit insn's. */ | |
2480 | insn.i[1] = bfd_getb32 (((unsigned char *) where)+4); | |
2481 | ||
5b93d8bb AM |
2482 | insn = i370_insert_operand (insn, operand, (offsetT) value); |
2483 | bfd_putb32 ((bfd_vma) insn.i[0], (unsigned char *) where); | |
5b93d8bb | 2484 | |
94f592af NC |
2485 | if (6 <= fixP->fx_size) |
2486 | /* Deal with 48-bit insn's. */ | |
2487 | bfd_putb32 ((bfd_vma) insn.i[1], (((unsigned char *) where)+4)); | |
2488 | ||
2489 | /* We are done, right? right !! */ | |
2490 | fixP->fx_done = 1; | |
2491 | if (fixP->fx_done) | |
2492 | /* Nothing else to do here. */ | |
2493 | return; | |
5b93d8bb AM |
2494 | |
2495 | /* Determine a BFD reloc value based on the operand information. | |
2496 | We are only prepared to turn a few of the operands into | |
2497 | relocs. In fact, we support *zero* operand relocations ... | |
2498 | Why? Because we are not expecting the compiler to generate | |
2499 | any operands that need relocation. Due to the 12-bit naturew of | |
92774660 | 2500 | i370 addressing, this would be unusual. */ |
5b93d8bb AM |
2501 | { |
2502 | char *sfile; | |
2503 | unsigned int sline; | |
2504 | ||
2505 | /* Use expr_symbol_where to see if this is an expression | |
2506 | symbol. */ | |
94f592af NC |
2507 | if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) |
2508 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
5b93d8bb AM |
2509 | "unresolved expression that must be resolved"); |
2510 | else | |
94f592af | 2511 | as_bad_where (fixP->fx_file, fixP->fx_line, |
5b93d8bb | 2512 | "unsupported relocation type"); |
94f592af NC |
2513 | fixP->fx_done = 1; |
2514 | return; | |
5b93d8bb AM |
2515 | } |
2516 | } | |
2517 | else | |
2518 | { | |
2519 | /* We branch to here if the fixup is not to a symbol that | |
94f592af NC |
2520 | appears in an instruction operand, but is rather some |
2521 | declared storage. */ | |
5b93d8bb | 2522 | #ifdef OBJ_ELF |
94f592af | 2523 | i370_elf_validate_fix (fixP, seg); |
5b93d8bb AM |
2524 | #endif |
2525 | #ifdef DEBUG | |
55cf6793 | 2526 | printf ("md_apply_fix: reloc case %d in segment %s %s:%d\n", |
94f592af | 2527 | fixP->fx_r_type, segment_name (seg), fixP->fx_file, fixP->fx_line); |
5b93d8bb AM |
2528 | printf ("\tcurrent fixup value is 0x%x \n", value); |
2529 | #endif | |
94f592af | 2530 | switch (fixP->fx_r_type) |
5b93d8bb AM |
2531 | { |
2532 | case BFD_RELOC_32: | |
2533 | case BFD_RELOC_CTOR: | |
94f592af NC |
2534 | if (fixP->fx_pcrel) |
2535 | fixP->fx_r_type = BFD_RELOC_32_PCREL; | |
2536 | /* Fall through. */ | |
5b93d8bb AM |
2537 | |
2538 | case BFD_RELOC_RVA: | |
2539 | case BFD_RELOC_32_PCREL: | |
2540 | case BFD_RELOC_32_BASEREL: | |
2541 | #ifdef DEBUG | |
2542 | printf ("\t32 bit relocation at 0x%x\n", | |
94f592af | 2543 | fixP->fx_frag->fr_address + fixP->fx_where); |
5b93d8bb | 2544 | #endif |
94f592af | 2545 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
5b93d8bb AM |
2546 | value, 4); |
2547 | break; | |
2548 | ||
2549 | case BFD_RELOC_LO16: | |
2550 | case BFD_RELOC_16: | |
94f592af NC |
2551 | if (fixP->fx_pcrel) |
2552 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
5b93d8bb | 2553 | "cannot emit PC relative %s relocation%s%s", |
94f592af NC |
2554 | bfd_get_reloc_code_name (fixP->fx_r_type), |
2555 | fixP->fx_addsy != NULL ? " against " : "", | |
2556 | (fixP->fx_addsy != NULL | |
2557 | ? S_GET_NAME (fixP->fx_addsy) | |
5b93d8bb AM |
2558 | : "")); |
2559 | ||
94f592af | 2560 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
5b93d8bb AM |
2561 | value, 2); |
2562 | break; | |
2563 | ||
2564 | /* This case happens when you write, for example, | |
2565 | lis %r3,(L1-L2)@ha | |
2566 | where L1 and L2 are defined later. */ | |
2567 | case BFD_RELOC_HI16: | |
94f592af | 2568 | if (fixP->fx_pcrel) |
5b93d8bb | 2569 | abort (); |
94f592af | 2570 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
5b93d8bb AM |
2571 | value >> 16, 2); |
2572 | break; | |
2573 | case BFD_RELOC_HI16_S: | |
94f592af | 2574 | if (fixP->fx_pcrel) |
5b93d8bb | 2575 | abort (); |
94f592af | 2576 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
5b93d8bb AM |
2577 | (value + 0x8000) >> 16, 2); |
2578 | break; | |
2579 | ||
2580 | case BFD_RELOC_8: | |
94f592af | 2581 | if (fixP->fx_pcrel) |
5b93d8bb AM |
2582 | abort (); |
2583 | ||
94f592af | 2584 | md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where, |
5b93d8bb AM |
2585 | value, 1); |
2586 | break; | |
2587 | ||
2588 | default: | |
bc805888 | 2589 | fprintf (stderr, |
94f592af | 2590 | "Gas failure, reloc value %d\n", fixP->fx_r_type); |
07726851 | 2591 | fflush (stderr); |
5b93d8bb AM |
2592 | abort (); |
2593 | } | |
2594 | } | |
2595 | ||
94f592af | 2596 | fixP->fx_addnumber = value; |
5b93d8bb AM |
2597 | } |
2598 | ||
2599 | /* Generate a reloc for a fixup. */ | |
2600 | ||
2601 | arelent * | |
ea1562b3 | 2602 | tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) |
5b93d8bb AM |
2603 | { |
2604 | arelent *reloc; | |
2605 | ||
ea1562b3 | 2606 | reloc = xmalloc (sizeof (arelent)); |
5b93d8bb | 2607 | |
ea1562b3 | 2608 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
5b93d8bb AM |
2609 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
2610 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
2611 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
2612 | if (reloc->howto == (reloc_howto_type *) NULL) | |
2613 | { | |
2614 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
2615 | "reloc %d not supported by object file format", (int)fixp->fx_r_type); | |
2616 | return NULL; | |
2617 | } | |
2618 | reloc->addend = fixp->fx_addnumber; | |
2619 | ||
2620 | #ifdef DEBUG | |
2621 | printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n", | |
2622 | fixp->fx_addsy->bsym->name, | |
2623 | fixp->fx_file, fixp->fx_line, | |
2624 | reloc->address, reloc->addend); | |
2625 | #endif | |
2626 | ||
2627 | return reloc; | |
2628 | } | |
ea1562b3 NC |
2629 | |
2630 | /* The target specific pseudo-ops which we support. */ | |
2631 | ||
2632 | const pseudo_typeS md_pseudo_table[] = | |
2633 | { | |
2634 | /* Pseudo-ops which must be overridden. */ | |
2635 | { "byte", i370_byte, 0 }, | |
2636 | ||
2637 | { "dc", i370_dc, 0 }, | |
2638 | { "ds", i370_ds, 0 }, | |
2639 | { "rmode", i370_rmode, 0 }, | |
2640 | { "csect", i370_csect, 0 }, | |
2641 | { "dsect", i370_dsect, 0 }, | |
2642 | ||
2643 | /* enable ebcdic strings e.g. for 3270 support */ | |
2644 | { "ebcdic", i370_ebcdic, 0 }, | |
2645 | ||
2646 | #ifdef OBJ_ELF | |
2647 | { "long", i370_elf_cons, 4 }, | |
2648 | { "word", i370_elf_cons, 4 }, | |
2649 | { "short", i370_elf_cons, 2 }, | |
2650 | { "rdata", i370_elf_rdata, 0 }, | |
2651 | { "rodata", i370_elf_rdata, 0 }, | |
2652 | { "lcomm", i370_elf_lcomm, 0 }, | |
2653 | #endif | |
2654 | ||
2655 | /* This pseudo-op is used even when not generating XCOFF output. */ | |
2656 | { "tc", i370_tc, 0 }, | |
2657 | ||
2658 | /* dump the literal pool */ | |
2659 | { "ltorg", i370_ltorg, 0 }, | |
2660 | ||
2661 | /* support the hlasm-style USING directive */ | |
2662 | { "using", i370_using, 0 }, | |
2663 | { "drop", i370_drop, 0 }, | |
2664 | ||
2665 | { NULL, NULL, 0 } | |
2666 | }; |