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