Commit | Line | Data |
---|---|---|
a85d7ed0 | 1 | /* tc-s390.c -- Assemble for the S390 |
5a49b8ac | 2 | Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 |
f17c130b | 3 | Free Software Foundation, Inc. |
a85d7ed0 NC |
4 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). |
5 | ||
6 | This file is part of GAS, the GNU Assembler. | |
7 | ||
8 | GAS is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 10 | the Free Software Foundation; either version 3, or (at your option) |
a85d7ed0 NC |
11 | any later version. |
12 | ||
13 | GAS is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with GAS; see the file COPYING. If not, write to the Free | |
4b4da160 NC |
20 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
21 | 02110-1301, USA. */ | |
a85d7ed0 | 22 | |
a85d7ed0 | 23 | #include "as.h" |
3882b010 | 24 | #include "safe-ctype.h" |
a85d7ed0 NC |
25 | #include "subsegs.h" |
26 | #include "struc-symbol.h" | |
a161fe53 | 27 | #include "dwarf2dbg.h" |
75e21f08 | 28 | #include "dw2gencfi.h" |
a85d7ed0 NC |
29 | |
30 | #include "opcode/s390.h" | |
31 | #include "elf/s390.h" | |
32 | ||
16a419ba | 33 | /* The default architecture. */ |
a85d7ed0 NC |
34 | #ifndef DEFAULT_ARCH |
35 | #define DEFAULT_ARCH "s390" | |
36 | #endif | |
37 | static char *default_arch = DEFAULT_ARCH; | |
38 | /* Either 32 or 64, selects file format. */ | |
37a58793 MS |
39 | static int s390_arch_size = 0; |
40 | ||
41 | static unsigned int current_mode_mask = 0; | |
42 | static unsigned int current_cpu = -1U; | |
a85d7ed0 | 43 | |
b34976b6 | 44 | /* Whether to use user friendly register names. Default is TRUE. */ |
a85d7ed0 | 45 | #ifndef TARGET_REG_NAMES_P |
b34976b6 | 46 | #define TARGET_REG_NAMES_P TRUE |
a85d7ed0 NC |
47 | #endif |
48 | ||
b34976b6 | 49 | static bfd_boolean reg_names_p = TARGET_REG_NAMES_P; |
a85d7ed0 | 50 | |
16a419ba | 51 | /* Set to TRUE if we want to warn about zero base/index registers. */ |
b34976b6 | 52 | static bfd_boolean warn_areg_zero = FALSE; |
16a419ba | 53 | |
a85d7ed0 NC |
54 | /* Generic assembler global variables which must be defined by all |
55 | targets. */ | |
56 | ||
57 | const char comment_chars[] = "#"; | |
58 | ||
59 | /* Characters which start a comment at the beginning of a line. */ | |
60 | const char line_comment_chars[] = "#"; | |
61 | ||
62 | /* Characters which may be used to separate multiple commands on a | |
63 | single line. */ | |
64 | const char line_separator_chars[] = ";"; | |
65 | ||
66 | /* Characters which are used to indicate an exponent in a floating | |
67 | point number. */ | |
68 | const char EXP_CHARS[] = "eE"; | |
69 | ||
70 | /* Characters which mean that a number is a floating point constant, | |
71 | as in 0d1.0. */ | |
72 | const char FLT_CHARS[] = "dD"; | |
73 | ||
75e21f08 JJ |
74 | /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */ |
75 | int s390_cie_data_alignment; | |
76 | ||
a85d7ed0 NC |
77 | /* The target specific pseudo-ops which we support. */ |
78 | ||
79 | /* Define the prototypes for the pseudo-ops */ | |
5a49b8ac AM |
80 | static void s390_byte (int); |
81 | static void s390_elf_cons (int); | |
82 | static void s390_bss (int); | |
83 | static void s390_insn (int); | |
84 | static void s390_literals (int); | |
a85d7ed0 NC |
85 | |
86 | const pseudo_typeS md_pseudo_table[] = | |
87 | { | |
88 | { "align", s_align_bytes, 0 }, | |
98d3f06f | 89 | /* Pseudo-ops which must be defined. */ |
198ce79b | 90 | { "bss", s390_bss, 0 }, |
a85d7ed0 NC |
91 | { "insn", s390_insn, 0 }, |
92 | /* Pseudo-ops which must be overridden. */ | |
93 | { "byte", s390_byte, 0 }, | |
94 | { "short", s390_elf_cons, 2 }, | |
95 | { "long", s390_elf_cons, 4 }, | |
96 | { "quad", s390_elf_cons, 8 }, | |
97 | { "ltorg", s390_literals, 0 }, | |
38a57ae7 | 98 | { "string", stringer, 8 + 1 }, |
a85d7ed0 NC |
99 | { NULL, NULL, 0 } |
100 | }; | |
101 | ||
102 | ||
103 | /* Structure to hold information about predefined registers. */ | |
104 | struct pd_reg | |
105 | { | |
106 | char *name; | |
107 | int value; | |
108 | }; | |
109 | ||
110 | /* List of registers that are pre-defined: | |
111 | ||
112 | Each access register has a predefined name of the form: | |
113 | a<reg_num> which has the value <reg_num>. | |
114 | ||
115 | Each control register has a predefined name of the form: | |
116 | c<reg_num> which has the value <reg_num>. | |
117 | ||
118 | Each general register has a predefined name of the form: | |
119 | r<reg_num> which has the value <reg_num>. | |
120 | ||
121 | Each floating point register a has predefined name of the form: | |
122 | f<reg_num> which has the value <reg_num>. | |
123 | ||
124 | There are individual registers as well: | |
125 | sp has the value 15 | |
126 | lit has the value 12 | |
127 | ||
98d3f06f | 128 | The table is sorted. Suitable for searching by a binary search. */ |
a85d7ed0 NC |
129 | |
130 | static const struct pd_reg pre_defined_registers[] = | |
131 | { | |
132 | { "a0", 0 }, /* Access registers */ | |
133 | { "a1", 1 }, | |
134 | { "a10", 10 }, | |
135 | { "a11", 11 }, | |
136 | { "a12", 12 }, | |
137 | { "a13", 13 }, | |
138 | { "a14", 14 }, | |
139 | { "a15", 15 }, | |
140 | { "a2", 2 }, | |
141 | { "a3", 3 }, | |
142 | { "a4", 4 }, | |
143 | { "a5", 5 }, | |
144 | { "a6", 6 }, | |
145 | { "a7", 7 }, | |
146 | { "a8", 8 }, | |
147 | { "a9", 9 }, | |
148 | ||
149 | { "c0", 0 }, /* Control registers */ | |
150 | { "c1", 1 }, | |
151 | { "c10", 10 }, | |
152 | { "c11", 11 }, | |
153 | { "c12", 12 }, | |
154 | { "c13", 13 }, | |
155 | { "c14", 14 }, | |
156 | { "c15", 15 }, | |
157 | { "c2", 2 }, | |
158 | { "c3", 3 }, | |
159 | { "c4", 4 }, | |
160 | { "c5", 5 }, | |
161 | { "c6", 6 }, | |
162 | { "c7", 7 }, | |
163 | { "c8", 8 }, | |
164 | { "c9", 9 }, | |
165 | ||
166 | { "f0", 0 }, /* Floating point registers */ | |
198ce79b AJ |
167 | { "f1", 1 }, |
168 | { "f10", 10 }, | |
169 | { "f11", 11 }, | |
170 | { "f12", 12 }, | |
171 | { "f13", 13 }, | |
172 | { "f14", 14 }, | |
173 | { "f15", 15 }, | |
174 | { "f2", 2 }, | |
175 | { "f3", 3 }, | |
176 | { "f4", 4 }, | |
177 | { "f5", 5 }, | |
178 | { "f6", 6 }, | |
179 | { "f7", 7 }, | |
180 | { "f8", 8 }, | |
181 | { "f9", 9 }, | |
a85d7ed0 NC |
182 | |
183 | { "lit", 13 }, /* Pointer to literal pool */ | |
184 | ||
185 | { "r0", 0 }, /* General purpose registers */ | |
186 | { "r1", 1 }, | |
187 | { "r10", 10 }, | |
188 | { "r11", 11 }, | |
189 | { "r12", 12 }, | |
190 | { "r13", 13 }, | |
191 | { "r14", 14 }, | |
192 | { "r15", 15 }, | |
193 | { "r2", 2 }, | |
194 | { "r3", 3 }, | |
195 | { "r4", 4 }, | |
196 | { "r5", 5 }, | |
197 | { "r6", 6 }, | |
198 | { "r7", 7 }, | |
199 | { "r8", 8 }, | |
200 | { "r9", 9 }, | |
201 | ||
202 | { "sp", 15 }, /* Stack pointer */ | |
203 | ||
204 | }; | |
205 | ||
07726851 | 206 | #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg)) |
a85d7ed0 NC |
207 | |
208 | /* Given NAME, find the register number associated with that name, return | |
209 | the integer value associated with the given name or -1 on failure. */ | |
210 | ||
211 | static int | |
5a49b8ac | 212 | reg_name_search (const struct pd_reg *regs, int regcount, const char *name) |
a85d7ed0 NC |
213 | { |
214 | int middle, low, high; | |
215 | int cmp; | |
216 | ||
217 | low = 0; | |
218 | high = regcount - 1; | |
219 | ||
220 | do | |
221 | { | |
222 | middle = (low + high) / 2; | |
223 | cmp = strcasecmp (name, regs[middle].name); | |
224 | if (cmp < 0) | |
225 | high = middle - 1; | |
226 | else if (cmp > 0) | |
227 | low = middle + 1; | |
228 | else | |
229 | return regs[middle].value; | |
230 | } | |
231 | while (low <= high); | |
232 | ||
233 | return -1; | |
234 | } | |
235 | ||
236 | ||
237 | /* | |
238 | * Summary of register_name(). | |
239 | * | |
240 | * in: Input_line_pointer points to 1st char of operand. | |
241 | * | |
242 | * out: A expressionS. | |
243 | * The operand may have been a register: in this case, X_op == O_register, | |
244 | * X_add_number is set to the register number, and truth is returned. | |
245 | * Input_line_pointer->(next non-blank) char after operand, or is in its | |
246 | * original state. | |
247 | */ | |
248 | ||
b34976b6 | 249 | static bfd_boolean |
5a49b8ac | 250 | register_name (expressionS *expressionP) |
a85d7ed0 NC |
251 | { |
252 | int reg_number; | |
253 | char *name; | |
254 | char *start; | |
255 | char c; | |
256 | ||
468cced8 | 257 | /* Find the spelling of the operand. */ |
a85d7ed0 | 258 | start = name = input_line_pointer; |
3882b010 | 259 | if (name[0] == '%' && ISALPHA (name[1])) |
a85d7ed0 NC |
260 | name = ++input_line_pointer; |
261 | else | |
b34976b6 | 262 | return FALSE; |
a85d7ed0 NC |
263 | |
264 | c = get_symbol_end (); | |
265 | reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name); | |
266 | ||
468cced8 AM |
267 | /* Put back the delimiting char. */ |
268 | *input_line_pointer = c; | |
269 | ||
270 | /* Look to see if it's in the register table. */ | |
198ce79b | 271 | if (reg_number >= 0) |
a85d7ed0 NC |
272 | { |
273 | expressionP->X_op = O_register; | |
274 | expressionP->X_add_number = reg_number; | |
198ce79b | 275 | |
468cced8 | 276 | /* Make the rest nice. */ |
a85d7ed0 NC |
277 | expressionP->X_add_symbol = NULL; |
278 | expressionP->X_op_symbol = NULL; | |
b34976b6 | 279 | return TRUE; |
a85d7ed0 | 280 | } |
468cced8 AM |
281 | |
282 | /* Reset the line as if we had not done anything. */ | |
283 | input_line_pointer = start; | |
b34976b6 | 284 | return FALSE; |
a85d7ed0 NC |
285 | } |
286 | ||
287 | /* Local variables. */ | |
288 | ||
289 | /* Opformat hash table. */ | |
290 | static struct hash_control *s390_opformat_hash; | |
291 | ||
292 | /* Opcode hash table. */ | |
293 | static struct hash_control *s390_opcode_hash; | |
294 | ||
295 | /* Flags to set in the elf header */ | |
296 | static flagword s390_flags = 0; | |
297 | ||
298 | symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ | |
299 | ||
300 | #ifndef WORKING_DOT_WORD | |
2b4f075a HPN |
301 | int md_short_jump_size = 4; |
302 | int md_long_jump_size = 4; | |
a85d7ed0 NC |
303 | #endif |
304 | ||
5a38dc70 | 305 | const char *md_shortopts = "A:m:kVQ:"; |
a85d7ed0 NC |
306 | struct option md_longopts[] = { |
307 | {NULL, no_argument, NULL, 0} | |
308 | }; | |
07726851 | 309 | size_t md_longopts_size = sizeof (md_longopts); |
a85d7ed0 NC |
310 | |
311 | /* Initialize the default opcode arch and word size from the default | |
37a58793 | 312 | architecture name if not specified by an option. */ |
a85d7ed0 | 313 | static void |
5a49b8ac | 314 | init_default_arch (void) |
a85d7ed0 | 315 | { |
07726851 | 316 | if (strcmp (default_arch, "s390") == 0) |
07855bec | 317 | { |
37a58793 MS |
318 | if (s390_arch_size == 0) |
319 | s390_arch_size = 32; | |
07855bec | 320 | } |
07726851 | 321 | else if (strcmp (default_arch, "s390x") == 0) |
07855bec | 322 | { |
37a58793 MS |
323 | if (s390_arch_size == 0) |
324 | s390_arch_size = 64; | |
07855bec NC |
325 | } |
326 | else | |
a85d7ed0 | 327 | as_fatal ("Invalid default architecture, broken assembler."); |
df9a398f MS |
328 | |
329 | if (current_mode_mask == 0) | |
330 | { | |
331 | if (s390_arch_size == 32) | |
332 | current_mode_mask = 1 << S390_OPCODE_ESA; | |
333 | else | |
334 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
335 | } | |
336 | if (current_cpu == -1U) | |
337 | { | |
338 | if (current_mode_mask == (1 << S390_OPCODE_ESA)) | |
339 | current_cpu = S390_OPCODE_G5; | |
340 | else | |
341 | current_cpu = S390_OPCODE_Z900; | |
342 | } | |
a85d7ed0 NC |
343 | } |
344 | ||
345 | /* Called by TARGET_FORMAT. */ | |
346 | const char * | |
5a49b8ac | 347 | s390_target_format (void) |
a85d7ed0 NC |
348 | { |
349 | /* We don't get a chance to initialize anything before we're called, | |
350 | so handle that now. */ | |
2ebb4b88 | 351 | init_default_arch (); |
a85d7ed0 NC |
352 | |
353 | return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390"; | |
354 | } | |
355 | ||
356 | int | |
5a49b8ac | 357 | md_parse_option (int c, char *arg) |
a85d7ed0 | 358 | { |
07855bec NC |
359 | switch (c) |
360 | { | |
361 | /* -k: Ignore for FreeBSD compatibility. */ | |
362 | case 'k': | |
363 | break; | |
364 | case 'm': | |
365 | if (arg != NULL && strcmp (arg, "regnames") == 0) | |
b34976b6 | 366 | reg_names_p = TRUE; |
198ce79b | 367 | |
07855bec | 368 | else if (arg != NULL && strcmp (arg, "no-regnames") == 0) |
b34976b6 | 369 | reg_names_p = FALSE; |
198ce79b | 370 | |
16a419ba NC |
371 | else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0) |
372 | warn_areg_zero = TRUE; | |
373 | ||
ff0fb565 | 374 | else if (arg != NULL && strcmp (arg, "31") == 0) |
75504fed | 375 | s390_arch_size = 32; |
ff0fb565 MS |
376 | |
377 | else if (arg != NULL && strcmp (arg, "64") == 0) | |
378 | s390_arch_size = 64; | |
379 | ||
37a58793 MS |
380 | else if (arg != NULL && strcmp (arg, "esa") == 0) |
381 | current_mode_mask = 1 << S390_OPCODE_ESA; | |
382 | ||
383 | else if (arg != NULL && strcmp (arg, "zarch") == 0) | |
384 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
385 | ||
386 | else if (arg != NULL && strncmp (arg, "arch=", 5) == 0) | |
387 | { | |
388 | if (strcmp (arg + 5, "g5") == 0) | |
389 | current_cpu = S390_OPCODE_G5; | |
390 | else if (strcmp (arg + 5, "g6") == 0) | |
391 | current_cpu = S390_OPCODE_G6; | |
392 | else if (strcmp (arg + 5, "z900") == 0) | |
393 | current_cpu = S390_OPCODE_Z900; | |
933fbc29 MS |
394 | else if (strcmp (arg + 5, "z990") == 0) |
395 | current_cpu = S390_OPCODE_Z990; | |
6c639ef9 MS |
396 | else if (strcmp (arg + 5, "z9-109") == 0) |
397 | current_cpu = S390_OPCODE_Z9_109; | |
b5639b37 MS |
398 | else if (strcmp (arg + 5, "z9-ec") == 0) |
399 | current_cpu = S390_OPCODE_Z9_EC; | |
5746fb46 AK |
400 | else if (strcmp (arg + 5, "z10") == 0) |
401 | current_cpu = S390_OPCODE_Z10; | |
37a58793 MS |
402 | else |
403 | { | |
404 | as_bad (_("invalid switch -m%s"), arg); | |
405 | return 0; | |
406 | } | |
407 | } | |
408 | ||
07855bec NC |
409 | else |
410 | { | |
411 | as_bad (_("invalid switch -m%s"), arg); | |
412 | return 0; | |
413 | } | |
414 | break; | |
198ce79b | 415 | |
07855bec | 416 | case 'A': |
67c1ffbe | 417 | /* Option -A is deprecated. Still available for compatibility. */ |
07855bec | 418 | if (arg != NULL && strcmp (arg, "esa") == 0) |
37a58793 | 419 | current_cpu = S390_OPCODE_G5; |
07855bec | 420 | else if (arg != NULL && strcmp (arg, "esame") == 0) |
37a58793 | 421 | current_cpu = S390_OPCODE_Z900; |
07855bec NC |
422 | else |
423 | as_bad ("invalid architecture -A%s", arg); | |
07855bec NC |
424 | break; |
425 | ||
426 | /* -V: SVR4 argument to print version ID. */ | |
427 | case 'V': | |
428 | print_version_id (); | |
429 | break; | |
198ce79b | 430 | |
07855bec NC |
431 | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section |
432 | should be emitted or not. FIXME: Not implemented. */ | |
433 | case 'Q': | |
434 | break; | |
198ce79b | 435 | |
07855bec NC |
436 | default: |
437 | return 0; | |
438 | } | |
198ce79b | 439 | |
a85d7ed0 NC |
440 | return 1; |
441 | } | |
442 | ||
443 | void | |
5a49b8ac | 444 | md_show_usage (FILE *stream) |
a85d7ed0 | 445 | { |
07855bec | 446 | fprintf (stream, _("\ |
16a419ba NC |
447 | S390 options:\n\ |
448 | -mregnames Allow symbolic names for registers\n\ | |
449 | -mwarn-areg-zero Warn about zero base/index registers\n\ | |
ff0fb565 MS |
450 | -mno-regnames Do not allow symbolic names for registers\n\ |
451 | -m31 Set file format to 31 bit format\n\ | |
452 | -m64 Set file format to 64 bit format\n")); | |
07855bec | 453 | fprintf (stream, _("\ |
16a419ba NC |
454 | -V print assembler version number\n\ |
455 | -Qy, -Qn ignored\n")); | |
a85d7ed0 NC |
456 | } |
457 | ||
458 | /* This function is called when the assembler starts up. It is called | |
459 | after the options have been parsed and the output file has been | |
16a419ba | 460 | opened. */ |
a85d7ed0 NC |
461 | |
462 | void | |
5a49b8ac | 463 | md_begin (void) |
a85d7ed0 NC |
464 | { |
465 | register const struct s390_opcode *op; | |
466 | const struct s390_opcode *op_end; | |
b34976b6 | 467 | bfd_boolean dup_insn = FALSE; |
a85d7ed0 NC |
468 | const char *retval; |
469 | ||
ff0fb565 | 470 | /* Give a warning if the combination -m64-bit and -Aesa is used. */ |
37a58793 | 471 | if (s390_arch_size == 64 && current_cpu < S390_OPCODE_Z900) |
ff0fb565 MS |
472 | as_warn ("The 64 bit file format is used without esame instructions."); |
473 | ||
75e21f08 JJ |
474 | s390_cie_data_alignment = -s390_arch_size / 8; |
475 | ||
16a419ba | 476 | /* Set the ELF flags if desired. */ |
a85d7ed0 NC |
477 | if (s390_flags) |
478 | bfd_set_private_flags (stdoutput, s390_flags); | |
479 | ||
480 | /* Insert the opcode formats into a hash table. */ | |
481 | s390_opformat_hash = hash_new (); | |
482 | ||
483 | op_end = s390_opformats + s390_num_opformats; | |
07855bec NC |
484 | for (op = s390_opformats; op < op_end; op++) |
485 | { | |
5a49b8ac | 486 | retval = hash_insert (s390_opformat_hash, op->name, (void *) op); |
07855bec NC |
487 | if (retval != (const char *) NULL) |
488 | { | |
489 | as_bad (_("Internal assembler error for instruction format %s"), | |
490 | op->name); | |
b34976b6 | 491 | dup_insn = TRUE; |
07855bec NC |
492 | } |
493 | } | |
a85d7ed0 NC |
494 | |
495 | /* Insert the opcodes into a hash table. */ | |
496 | s390_opcode_hash = hash_new (); | |
497 | ||
498 | op_end = s390_opcodes + s390_num_opcodes; | |
07855bec | 499 | for (op = s390_opcodes; op < op_end; op++) |
e6181b6a MS |
500 | { |
501 | while (op < op_end - 1 && strcmp(op->name, op[1].name) == 0) | |
502 | { | |
503 | if (op->min_cpu <= current_cpu && (op->modes & current_mode_mask)) | |
504 | break; | |
933fbc29 | 505 | op++; |
e6181b6a | 506 | } |
5a49b8ac | 507 | retval = hash_insert (s390_opcode_hash, op->name, (void *) op); |
e6181b6a MS |
508 | if (retval != (const char *) NULL) |
509 | { | |
510 | as_bad (_("Internal assembler error for instruction %s"), | |
511 | op->name); | |
512 | dup_insn = TRUE; | |
513 | } | |
514 | while (op < op_end - 1 && strcmp (op->name, op[1].name) == 0) | |
515 | op++; | |
933fbc29 | 516 | } |
07855bec | 517 | |
a85d7ed0 NC |
518 | if (dup_insn) |
519 | abort (); | |
520 | ||
521 | record_alignment (text_section, 2); | |
522 | record_alignment (data_section, 2); | |
523 | record_alignment (bss_section, 2); | |
524 | ||
525 | } | |
526 | ||
527 | /* Called after all assembly has been done. */ | |
528 | void | |
5a49b8ac | 529 | s390_md_end (void) |
a85d7ed0 | 530 | { |
07855bec | 531 | if (s390_arch_size == 64) |
ff0fb565 | 532 | bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_64); |
07855bec | 533 | else |
ff0fb565 | 534 | bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_31); |
a85d7ed0 NC |
535 | } |
536 | ||
a85d7ed0 NC |
537 | /* Insert an operand value into an instruction. */ |
538 | ||
539 | static void | |
5a49b8ac AM |
540 | s390_insert_operand (unsigned char *insn, |
541 | const struct s390_operand *operand, | |
542 | offsetT val, | |
543 | char *file, | |
544 | unsigned int line) | |
a85d7ed0 NC |
545 | { |
546 | addressT uval; | |
547 | int offset; | |
548 | ||
07855bec NC |
549 | if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL)) |
550 | { | |
551 | offsetT min, max; | |
552 | ||
553 | max = ((offsetT) 1 << (operand->bits - 1)) - 1; | |
554 | min = - ((offsetT) 1 << (operand->bits - 1)); | |
555 | /* Halve PCREL operands. */ | |
556 | if (operand->flags & S390_OPERAND_PCREL) | |
557 | val >>= 1; | |
558 | /* Check for underflow / overflow. */ | |
559 | if (val < min || val > max) | |
560 | { | |
561 | const char *err = | |
562 | "operand out of range (%s not between %ld and %ld)"; | |
563 | char buf[100]; | |
564 | ||
565 | if (operand->flags & S390_OPERAND_PCREL) | |
566 | { | |
567 | val <<= 1; | |
568 | min <<= 1; | |
569 | max <<= 1; | |
570 | } | |
571 | sprint_value (buf, val); | |
572 | if (file == (char *) NULL) | |
573 | as_bad (err, buf, (int) min, (int) max); | |
574 | else | |
575 | as_bad_where (file, line, err, buf, (int) min, (int) max); | |
576 | return; | |
577 | } | |
578 | /* val is ok, now restrict it to operand->bits bits. */ | |
579 | uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1); | |
933fbc29 MS |
580 | /* val is restrict, now check for special case. */ |
581 | if (operand->bits == 20 && operand->shift == 20) | |
582 | uval = (uval >> 12) | ((uval & 0xfff) << 8); | |
a85d7ed0 | 583 | } |
07855bec NC |
584 | else |
585 | { | |
586 | addressT min, max; | |
198ce79b | 587 | |
98d3f06f | 588 | max = (((addressT) 1 << (operand->bits - 1)) << 1) - 1; |
07855bec NC |
589 | min = (offsetT) 0; |
590 | uval = (addressT) val; | |
591 | /* Length x in an instructions has real length x+1. */ | |
592 | if (operand->flags & S390_OPERAND_LENGTH) | |
593 | uval--; | |
594 | /* Check for underflow / overflow. */ | |
595 | if (uval < min || uval > max) | |
596 | { | |
07855bec NC |
597 | if (operand->flags & S390_OPERAND_LENGTH) |
598 | { | |
599 | uval++; | |
600 | min++; | |
601 | max++; | |
602 | } | |
e5976317 NC |
603 | |
604 | as_bad_value_out_of_range (_("operand"), uval, (offsetT) min, (offsetT) max, file, line); | |
605 | ||
07855bec NC |
606 | return; |
607 | } | |
a85d7ed0 | 608 | } |
a85d7ed0 NC |
609 | |
610 | /* Insert fragments of the operand byte for byte. */ | |
611 | offset = operand->shift + operand->bits; | |
612 | uval <<= (-offset) & 7; | |
98d3f06f | 613 | insn += (offset - 1) / 8; |
07855bec NC |
614 | while (uval != 0) |
615 | { | |
616 | *insn-- |= uval; | |
617 | uval >>= 8; | |
618 | } | |
a85d7ed0 NC |
619 | } |
620 | ||
1971b29d MS |
621 | struct map_tls |
622 | { | |
623 | char *string; | |
624 | int length; | |
625 | bfd_reloc_code_real_type reloc; | |
626 | }; | |
627 | ||
1971b29d MS |
628 | /* Parse tls marker and return the desired relocation. */ |
629 | static bfd_reloc_code_real_type | |
5a49b8ac | 630 | s390_tls_suffix (char **str_p, expressionS *exp_p) |
1971b29d MS |
631 | { |
632 | static struct map_tls mapping[] = | |
633 | { | |
634 | { "tls_load", 8, BFD_RELOC_390_TLS_LOAD }, | |
635 | { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL }, | |
636 | { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL }, | |
637 | { NULL, 0, BFD_RELOC_UNUSED } | |
638 | }; | |
639 | struct map_tls *ptr; | |
640 | char *orig_line; | |
641 | char *str; | |
642 | char *ident; | |
643 | int len; | |
644 | ||
645 | str = *str_p; | |
646 | if (*str++ != ':') | |
647 | return BFD_RELOC_UNUSED; | |
648 | ||
649 | ident = str; | |
650 | while (ISIDNUM (*str)) | |
651 | str++; | |
652 | len = str - ident; | |
653 | if (*str++ != ':') | |
654 | return BFD_RELOC_UNUSED; | |
655 | ||
656 | orig_line = input_line_pointer; | |
657 | input_line_pointer = str; | |
658 | expression (exp_p); | |
659 | str = input_line_pointer; | |
660 | if (&input_line_pointer != str_p) | |
661 | input_line_pointer = orig_line; | |
662 | ||
663 | if (exp_p->X_op != O_symbol) | |
664 | return BFD_RELOC_UNUSED; | |
665 | ||
666 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
667 | if (len == ptr->length | |
668 | && strncasecmp (ident, ptr->string, ptr->length) == 0) | |
669 | { | |
670 | /* Found a matching tls suffix. */ | |
671 | *str_p = str; | |
672 | return ptr->reloc; | |
673 | } | |
674 | return BFD_RELOC_UNUSED; | |
675 | } | |
676 | ||
a85d7ed0 | 677 | /* Structure used to hold suffixes. */ |
07855bec NC |
678 | typedef enum |
679 | { | |
680 | ELF_SUFFIX_NONE = 0, | |
681 | ELF_SUFFIX_GOT, | |
682 | ELF_SUFFIX_PLT, | |
2a19f73f MS |
683 | ELF_SUFFIX_GOTENT, |
684 | ELF_SUFFIX_GOTOFF, | |
685 | ELF_SUFFIX_GOTPLT, | |
1971b29d MS |
686 | ELF_SUFFIX_PLTOFF, |
687 | ELF_SUFFIX_TLS_GD, | |
688 | ELF_SUFFIX_TLS_GOTIE, | |
689 | ELF_SUFFIX_TLS_IE, | |
690 | ELF_SUFFIX_TLS_LDM, | |
691 | ELF_SUFFIX_TLS_LDO, | |
692 | ELF_SUFFIX_TLS_LE | |
07855bec NC |
693 | } |
694 | elf_suffix_type; | |
695 | ||
696 | struct map_bfd | |
697 | { | |
698 | char *string; | |
699 | int length; | |
700 | elf_suffix_type suffix; | |
701 | }; | |
a85d7ed0 | 702 | |
9d654c1c | 703 | |
a85d7ed0 NC |
704 | /* Parse @got/@plt/@gotoff. and return the desired relocation. */ |
705 | static elf_suffix_type | |
5a49b8ac | 706 | s390_elf_suffix (char **str_p, expressionS *exp_p) |
a85d7ed0 | 707 | { |
07855bec NC |
708 | static struct map_bfd mapping[] = |
709 | { | |
a85d7ed0 NC |
710 | { "got", 3, ELF_SUFFIX_GOT }, |
711 | { "got12", 5, ELF_SUFFIX_GOT }, | |
712 | { "plt", 3, ELF_SUFFIX_PLT }, | |
713 | { "gotent", 6, ELF_SUFFIX_GOTENT }, | |
2a19f73f MS |
714 | { "gotoff", 6, ELF_SUFFIX_GOTOFF }, |
715 | { "gotplt", 6, ELF_SUFFIX_GOTPLT }, | |
716 | { "pltoff", 6, ELF_SUFFIX_PLTOFF }, | |
1971b29d MS |
717 | { "tlsgd", 5, ELF_SUFFIX_TLS_GD }, |
718 | { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE }, | |
719 | { "indntpoff", 9, ELF_SUFFIX_TLS_IE }, | |
720 | { "tlsldm", 6, ELF_SUFFIX_TLS_LDM }, | |
721 | { "dtpoff", 6, ELF_SUFFIX_TLS_LDO }, | |
722 | { "ntpoff", 6, ELF_SUFFIX_TLS_LE }, | |
a85d7ed0 NC |
723 | { NULL, 0, ELF_SUFFIX_NONE } |
724 | }; | |
725 | ||
726 | struct map_bfd *ptr; | |
727 | char *str = *str_p; | |
728 | char *ident; | |
729 | int len; | |
730 | ||
731 | if (*str++ != '@') | |
732 | return ELF_SUFFIX_NONE; | |
733 | ||
734 | ident = str; | |
3882b010 | 735 | while (ISALNUM (*str)) |
a85d7ed0 NC |
736 | str++; |
737 | len = str - ident; | |
738 | ||
739 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
16a419ba NC |
740 | if (len == ptr->length |
741 | && strncasecmp (ident, ptr->string, ptr->length) == 0) | |
07855bec NC |
742 | { |
743 | if (exp_p->X_add_number != 0) | |
744 | as_warn (_("identifier+constant@%s means identifier@%s+constant"), | |
745 | ptr->string, ptr->string); | |
746 | /* Now check for identifier@suffix+constant. */ | |
747 | if (*str == '-' || *str == '+') | |
748 | { | |
749 | char *orig_line = input_line_pointer; | |
750 | expressionS new_exp; | |
751 | ||
752 | input_line_pointer = str; | |
753 | expression (&new_exp); | |
754 | ||
755 | switch (new_exp.X_op) | |
756 | { | |
757 | case O_constant: /* X_add_number (a constant expression). */ | |
758 | exp_p->X_add_number += new_exp.X_add_number; | |
759 | str = input_line_pointer; | |
760 | break; | |
761 | case O_symbol: /* X_add_symbol + X_add_number. */ | |
762 | /* this case is used for e.g. xyz@PLT+.Label. */ | |
763 | exp_p->X_add_number += new_exp.X_add_number; | |
764 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
765 | exp_p->X_op = O_add; | |
766 | str = input_line_pointer; | |
767 | break; | |
768 | case O_uminus: /* (- X_add_symbol) + X_add_number. */ | |
769 | /* this case is used for e.g. xyz@PLT-.Label. */ | |
770 | exp_p->X_add_number += new_exp.X_add_number; | |
771 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
772 | exp_p->X_op = O_subtract; | |
773 | str = input_line_pointer; | |
774 | break; | |
775 | default: | |
776 | break; | |
777 | } | |
778 | ||
779 | /* If s390_elf_suffix has not been called with | |
780 | &input_line_pointer as first parameter, we have | |
781 | clobbered the input_line_pointer. We have to | |
782 | undo that. */ | |
783 | if (&input_line_pointer != str_p) | |
784 | input_line_pointer = orig_line; | |
a85d7ed0 | 785 | } |
07855bec NC |
786 | *str_p = str; |
787 | return ptr->suffix; | |
a85d7ed0 | 788 | } |
a85d7ed0 NC |
789 | |
790 | return BFD_RELOC_UNUSED; | |
791 | } | |
792 | ||
793 | /* Structure used to hold a literal pool entry. */ | |
07855bec NC |
794 | struct s390_lpe |
795 | { | |
796 | struct s390_lpe *next; | |
797 | expressionS ex; | |
798 | FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */ | |
799 | LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */ | |
800 | int nbytes; | |
801 | bfd_reloc_code_real_type reloc; | |
802 | symbolS *sym; | |
803 | }; | |
a85d7ed0 NC |
804 | |
805 | static struct s390_lpe *lpe_free_list = NULL; | |
806 | static struct s390_lpe *lpe_list = NULL; | |
807 | static struct s390_lpe *lpe_list_tail = NULL; | |
808 | static symbolS *lp_sym = NULL; | |
809 | static int lp_count = 0; | |
810 | static int lpe_count = 0; | |
811 | ||
812 | static int | |
5a49b8ac | 813 | s390_exp_compare (expressionS *exp1, expressionS *exp2) |
a85d7ed0 NC |
814 | { |
815 | if (exp1->X_op != exp2->X_op) | |
816 | return 0; | |
817 | ||
07855bec NC |
818 | switch (exp1->X_op) |
819 | { | |
820 | case O_constant: /* X_add_number must be equal. */ | |
821 | case O_register: | |
822 | return exp1->X_add_number == exp2->X_add_number; | |
823 | ||
824 | case O_big: | |
198ce79b | 825 | as_bad (_("Can't handle O_big in s390_exp_compare")); |
07855bec NC |
826 | |
827 | case O_symbol: /* X_add_symbol & X_add_number must be equal. */ | |
828 | case O_symbol_rva: | |
829 | case O_uminus: | |
830 | case O_bit_not: | |
831 | case O_logical_not: | |
16a419ba NC |
832 | return (exp1->X_add_symbol == exp2->X_add_symbol) |
833 | && (exp1->X_add_number == exp2->X_add_number); | |
07855bec NC |
834 | |
835 | case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */ | |
836 | case O_divide: | |
837 | case O_modulus: | |
838 | case O_left_shift: | |
839 | case O_right_shift: | |
840 | case O_bit_inclusive_or: | |
841 | case O_bit_or_not: | |
842 | case O_bit_exclusive_or: | |
843 | case O_bit_and: | |
844 | case O_add: | |
845 | case O_subtract: | |
846 | case O_eq: | |
847 | case O_ne: | |
848 | case O_lt: | |
849 | case O_le: | |
850 | case O_ge: | |
851 | case O_gt: | |
852 | case O_logical_and: | |
853 | case O_logical_or: | |
16a419ba NC |
854 | return (exp1->X_add_symbol == exp2->X_add_symbol) |
855 | && (exp1->X_op_symbol == exp2->X_op_symbol) | |
856 | && (exp1->X_add_number == exp2->X_add_number); | |
07855bec | 857 | default: |
98d3f06f KH |
858 | return 0; |
859 | } | |
a85d7ed0 NC |
860 | } |
861 | ||
862 | /* Test for @lit and if its present make an entry in the literal pool and | |
863 | modify the current expression to be an offset into the literal pool. */ | |
864 | static elf_suffix_type | |
5a49b8ac | 865 | s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix) |
a85d7ed0 NC |
866 | { |
867 | bfd_reloc_code_real_type reloc; | |
868 | char tmp_name[64]; | |
869 | char *str = *str_p; | |
870 | char *ident; | |
871 | struct s390_lpe *lpe; | |
872 | int nbytes, len; | |
873 | ||
874 | if (*str++ != ':') | |
875 | return suffix; /* No modification. */ | |
198ce79b | 876 | |
a85d7ed0 NC |
877 | /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */ |
878 | ident = str; | |
3882b010 | 879 | while (ISALNUM (*str)) |
a85d7ed0 NC |
880 | str++; |
881 | len = str - ident; | |
16a419ba NC |
882 | if (len != 4 || strncasecmp (ident, "lit", 3) != 0 |
883 | || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8')) | |
a85d7ed0 NC |
884 | return suffix; /* no modification */ |
885 | nbytes = ident[3] - '0'; | |
886 | ||
887 | reloc = BFD_RELOC_UNUSED; | |
07855bec NC |
888 | if (suffix == ELF_SUFFIX_GOT) |
889 | { | |
890 | if (nbytes == 2) | |
891 | reloc = BFD_RELOC_390_GOT16; | |
892 | else if (nbytes == 4) | |
893 | reloc = BFD_RELOC_32_GOT_PCREL; | |
894 | else if (nbytes == 8) | |
895 | reloc = BFD_RELOC_390_GOT64; | |
896 | } | |
897 | else if (suffix == ELF_SUFFIX_PLT) | |
898 | { | |
899 | if (nbytes == 4) | |
900 | reloc = BFD_RELOC_390_PLT32; | |
901 | else if (nbytes == 8) | |
902 | reloc = BFD_RELOC_390_PLT64; | |
903 | } | |
a85d7ed0 | 904 | |
07855bec | 905 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) |
a85d7ed0 | 906 | as_bad (_("Invalid suffix for literal pool entry")); |
a85d7ed0 NC |
907 | |
908 | /* Search the pool if the new entry is a duplicate. */ | |
07855bec NC |
909 | if (exp_p->X_op == O_big) |
910 | { | |
911 | /* Special processing for big numbers. */ | |
912 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
913 | { | |
914 | if (lpe->ex.X_op == O_big) | |
915 | { | |
916 | if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0) | |
917 | { | |
918 | if (memcmp (&generic_floating_point_number, &lpe->floatnum, | |
919 | sizeof (FLONUM_TYPE)) == 0) | |
920 | break; | |
921 | } | |
922 | else if (exp_p->X_add_number == lpe->ex.X_add_number) | |
923 | { | |
924 | if (memcmp (generic_bignum, lpe->bignum, | |
925 | sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0) | |
926 | break; | |
927 | } | |
928 | } | |
929 | } | |
a85d7ed0 | 930 | } |
07855bec NC |
931 | else |
932 | { | |
933 | /* Processing for 'normal' data types. */ | |
934 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
16a419ba | 935 | if (lpe->nbytes == nbytes && lpe->reloc == reloc |
98d3f06f | 936 | && s390_exp_compare (exp_p, &lpe->ex) != 0) |
07855bec | 937 | break; |
a85d7ed0 | 938 | } |
07855bec NC |
939 | |
940 | if (lpe == NULL) | |
941 | { | |
942 | /* A new literal. */ | |
943 | if (lpe_free_list != NULL) | |
944 | { | |
945 | lpe = lpe_free_list; | |
946 | lpe_free_list = lpe_free_list->next; | |
947 | } | |
a85d7ed0 | 948 | else |
07855bec | 949 | { |
98d3f06f | 950 | lpe = (struct s390_lpe *) xmalloc (sizeof (struct s390_lpe)); |
07855bec NC |
951 | } |
952 | ||
953 | lpe->ex = *exp_p; | |
954 | ||
955 | if (exp_p->X_op == O_big) | |
956 | { | |
957 | if (exp_p->X_add_number <= 0) | |
958 | lpe->floatnum = generic_floating_point_number; | |
959 | else if (exp_p->X_add_number <= 4) | |
960 | memcpy (lpe->bignum, generic_bignum, | |
98d3f06f | 961 | exp_p->X_add_number * sizeof (LITTLENUM_TYPE)); |
07855bec NC |
962 | else |
963 | as_bad (_("Big number is too big")); | |
964 | } | |
965 | ||
966 | lpe->nbytes = nbytes; | |
967 | lpe->reloc = reloc; | |
968 | /* Literal pool name defined ? */ | |
969 | if (lp_sym == NULL) | |
970 | { | |
07726851 | 971 | sprintf (tmp_name, ".L\001%i", lp_count); |
98d3f06f | 972 | lp_sym = symbol_make (tmp_name); |
07855bec | 973 | } |
a85d7ed0 | 974 | |
07855bec | 975 | /* Make name for literal pool entry. */ |
07726851 | 976 | sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count); |
07855bec | 977 | lpe_count++; |
98d3f06f | 978 | lpe->sym = symbol_make (tmp_name); |
07855bec NC |
979 | |
980 | /* Add to literal pool list. */ | |
981 | lpe->next = NULL; | |
982 | if (lpe_list_tail != NULL) | |
983 | { | |
984 | lpe_list_tail->next = lpe; | |
985 | lpe_list_tail = lpe; | |
986 | } | |
987 | else | |
988 | lpe_list = lpe_list_tail = lpe; | |
989 | } | |
198ce79b | 990 | |
a85d7ed0 NC |
991 | /* Now change exp_p to the offset into the literal pool. |
992 | Thats the expression: .L^Ax^By-.L^Ax */ | |
993 | exp_p->X_add_symbol = lpe->sym; | |
994 | exp_p->X_op_symbol = lp_sym; | |
995 | exp_p->X_op = O_subtract; | |
996 | exp_p->X_add_number = 0; | |
997 | ||
998 | *str_p = str; | |
999 | ||
1000 | /* We change the suffix type to ELF_SUFFIX_NONE, because | |
1001 | the difference of two local labels is just a number. */ | |
1002 | return ELF_SUFFIX_NONE; | |
1003 | } | |
1004 | ||
1005 | /* Like normal .long/.short/.word, except support @got, etc. | |
1006 | clobbers input_line_pointer, checks end-of-line. */ | |
1007 | static void | |
5a49b8ac | 1008 | s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */) |
a85d7ed0 NC |
1009 | { |
1010 | expressionS exp; | |
1011 | elf_suffix_type suffix; | |
1012 | ||
07855bec NC |
1013 | if (is_it_end_of_statement ()) |
1014 | { | |
1015 | demand_empty_rest_of_line (); | |
1016 | return; | |
1017 | } | |
a85d7ed0 | 1018 | |
07855bec NC |
1019 | do |
1020 | { | |
1021 | expression (&exp); | |
1022 | ||
1023 | if (exp.X_op == O_symbol | |
1024 | && *input_line_pointer == '@' | |
1025 | && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE) | |
1026 | { | |
1027 | bfd_reloc_code_real_type reloc; | |
1028 | reloc_howto_type *reloc_howto; | |
1029 | int size; | |
1030 | char *where; | |
1031 | ||
1971b29d MS |
1032 | if (nbytes == 2) |
1033 | { | |
1034 | static bfd_reloc_code_real_type tab2[] = | |
1035 | { | |
5cfbfc2b MS |
1036 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1037 | BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */ | |
1038 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */ | |
1039 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1040 | BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */ | |
1041 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */ | |
1042 | BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */ | |
1043 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */ | |
1044 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */ | |
1045 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */ | |
1046 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */ | |
1047 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */ | |
1048 | BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1049 | }; |
1050 | reloc = tab2[suffix]; | |
1051 | } | |
1052 | else if (nbytes == 4) | |
1053 | { | |
1054 | static bfd_reloc_code_real_type tab4[] = | |
1055 | { | |
5cfbfc2b MS |
1056 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1057 | BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */ | |
1058 | BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */ | |
1059 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1060 | BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */ | |
1061 | BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */ | |
1062 | BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */ | |
1063 | BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */ | |
1064 | BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */ | |
1065 | BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */ | |
1066 | BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */ | |
1067 | BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */ | |
1068 | BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1069 | }; |
1070 | reloc = tab4[suffix]; | |
1071 | } | |
1072 | else if (nbytes == 8) | |
1073 | { | |
1074 | static bfd_reloc_code_real_type tab8[] = | |
1075 | { | |
5cfbfc2b MS |
1076 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1077 | BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */ | |
1078 | BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */ | |
1079 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1080 | BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */ | |
1081 | BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */ | |
1082 | BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */ | |
1083 | BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */ | |
1084 | BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */ | |
1085 | BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */ | |
1086 | BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */ | |
1087 | BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */ | |
1088 | BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1089 | }; |
1090 | reloc = tab8[suffix]; | |
1091 | } | |
07855bec NC |
1092 | else |
1093 | reloc = BFD_RELOC_UNUSED; | |
1094 | ||
1971b29d MS |
1095 | if (reloc != BFD_RELOC_UNUSED |
1096 | && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc))) | |
07855bec | 1097 | { |
07855bec NC |
1098 | size = bfd_get_reloc_size (reloc_howto); |
1099 | if (size > nbytes) | |
1100 | as_bad (_("%s relocations do not fit in %d bytes"), | |
1101 | reloc_howto->name, nbytes); | |
07726851 | 1102 | where = frag_more (nbytes); |
07855bec | 1103 | md_number_to_chars (where, 0, size); |
198ce79b | 1104 | /* To make fixup_segment do the pc relative conversion the |
b34976b6 | 1105 | pcrel parameter on the fix_new_exp call needs to be FALSE. */ |
198ce79b | 1106 | fix_new_exp (frag_now, where - frag_now->fr_literal, |
b34976b6 | 1107 | size, &exp, FALSE, reloc); |
07855bec NC |
1108 | } |
1109 | else | |
1110 | as_bad (_("relocation not applicable")); | |
1111 | } | |
a85d7ed0 | 1112 | else |
07855bec NC |
1113 | emit_expr (&exp, (unsigned int) nbytes); |
1114 | } | |
1115 | while (*input_line_pointer++ == ','); | |
a85d7ed0 | 1116 | |
98d3f06f | 1117 | input_line_pointer--; /* Put terminator back into stream. */ |
a85d7ed0 NC |
1118 | demand_empty_rest_of_line (); |
1119 | } | |
1120 | ||
1121 | /* We need to keep a list of fixups. We can't simply generate them as | |
1122 | we go, because that would require us to first create the frag, and | |
1123 | that would screw up references to ``.''. */ | |
1124 | ||
1125 | struct s390_fixup | |
07855bec NC |
1126 | { |
1127 | expressionS exp; | |
1128 | int opindex; | |
1129 | bfd_reloc_code_real_type reloc; | |
1130 | }; | |
a85d7ed0 NC |
1131 | |
1132 | #define MAX_INSN_FIXUPS (4) | |
1133 | ||
1134 | /* This routine is called for each instruction to be assembled. */ | |
1135 | ||
9d654c1c | 1136 | static char * |
5a49b8ac AM |
1137 | md_gather_operands (char *str, |
1138 | unsigned char *insn, | |
1139 | const struct s390_opcode *opcode) | |
a85d7ed0 NC |
1140 | { |
1141 | struct s390_fixup fixups[MAX_INSN_FIXUPS]; | |
1142 | const struct s390_operand *operand; | |
1143 | const unsigned char *opindex_ptr; | |
1971b29d | 1144 | expressionS ex; |
a85d7ed0 NC |
1145 | elf_suffix_type suffix; |
1146 | bfd_reloc_code_real_type reloc; | |
1147 | int skip_optional; | |
1148 | int parentheses; | |
1149 | char *f; | |
1150 | int fc, i; | |
1151 | ||
98d3f06f KH |
1152 | while (ISSPACE (*str)) |
1153 | str++; | |
a85d7ed0 NC |
1154 | |
1155 | parentheses = 0; | |
1156 | skip_optional = 0; | |
1157 | ||
1158 | /* Gather the operands. */ | |
1159 | fc = 0; | |
07855bec NC |
1160 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) |
1161 | { | |
07855bec NC |
1162 | char *hold; |
1163 | ||
1164 | operand = s390_operands + *opindex_ptr; | |
198ce79b | 1165 | |
07855bec NC |
1166 | if (skip_optional && (operand->flags & S390_OPERAND_INDEX)) |
1167 | { | |
1168 | /* We do an early skip. For D(X,B) constructions the index | |
198ce79b | 1169 | register is skipped (X is optional). For D(L,B) the base |
07855bec NC |
1170 | register will be the skipped operand, because L is NOT |
1171 | optional. */ | |
1172 | skip_optional = 0; | |
1173 | continue; | |
1174 | } | |
198ce79b | 1175 | |
07855bec NC |
1176 | /* Gather the operand. */ |
1177 | hold = input_line_pointer; | |
1178 | input_line_pointer = str; | |
1179 | ||
98d3f06f KH |
1180 | /* Parse the operand. */ |
1181 | if (! register_name (&ex)) | |
07855bec | 1182 | expression (&ex); |
198ce79b | 1183 | |
07855bec NC |
1184 | str = input_line_pointer; |
1185 | input_line_pointer = hold; | |
198ce79b | 1186 | |
07855bec NC |
1187 | /* Write the operand to the insn. */ |
1188 | if (ex.X_op == O_illegal) | |
1189 | as_bad (_("illegal operand")); | |
1190 | else if (ex.X_op == O_absent) | |
1191 | as_bad (_("missing operand")); | |
1192 | else if (ex.X_op == O_register || ex.X_op == O_constant) | |
1193 | { | |
1194 | s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE); | |
1195 | ||
1196 | if (ex.X_op != O_register && ex.X_op != O_constant) | |
1197 | { | |
1198 | /* We need to generate a fixup for the | |
1199 | expression returned by s390_lit_suffix. */ | |
1200 | if (fc >= MAX_INSN_FIXUPS) | |
1201 | as_fatal (_("too many fixups")); | |
1202 | fixups[fc].exp = ex; | |
1203 | fixups[fc].opindex = *opindex_ptr; | |
1204 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
1205 | ++fc; | |
1206 | } | |
1207 | else | |
1208 | { | |
16a419ba NC |
1209 | if ((operand->flags & S390_OPERAND_INDEX) |
1210 | && ex.X_add_number == 0 | |
b34976b6 | 1211 | && warn_areg_zero) |
07726851 | 1212 | as_warn ("index register specified but zero"); |
16a419ba NC |
1213 | if ((operand->flags & S390_OPERAND_BASE) |
1214 | && ex.X_add_number == 0 | |
b34976b6 | 1215 | && warn_areg_zero) |
07726851 | 1216 | as_warn ("base register specified but zero"); |
07855bec NC |
1217 | s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0); |
1218 | } | |
1219 | } | |
1220 | else | |
1221 | { | |
1222 | suffix = s390_elf_suffix (&str, &ex); | |
1223 | suffix = s390_lit_suffix (&str, &ex, suffix); | |
1224 | reloc = BFD_RELOC_UNUSED; | |
1225 | ||
1226 | if (suffix == ELF_SUFFIX_GOT) | |
1227 | { | |
933fbc29 MS |
1228 | if ((operand->flags & S390_OPERAND_DISP) && |
1229 | (operand->bits == 12)) | |
07855bec | 1230 | reloc = BFD_RELOC_390_GOT12; |
933fbc29 MS |
1231 | else if ((operand->flags & S390_OPERAND_DISP) && |
1232 | (operand->bits == 20)) | |
1233 | reloc = BFD_RELOC_390_GOT20; | |
16a419ba NC |
1234 | else if ((operand->flags & S390_OPERAND_SIGNED) |
1235 | && (operand->bits == 16)) | |
07855bec | 1236 | reloc = BFD_RELOC_390_GOT16; |
16a419ba NC |
1237 | else if ((operand->flags & S390_OPERAND_PCREL) |
1238 | && (operand->bits == 32)) | |
07855bec NC |
1239 | reloc = BFD_RELOC_390_GOTENT; |
1240 | } | |
1241 | else if (suffix == ELF_SUFFIX_PLT) | |
1242 | { | |
16a419ba NC |
1243 | if ((operand->flags & S390_OPERAND_PCREL) |
1244 | && (operand->bits == 16)) | |
07855bec | 1245 | reloc = BFD_RELOC_390_PLT16DBL; |
16a419ba NC |
1246 | else if ((operand->flags & S390_OPERAND_PCREL) |
1247 | && (operand->bits == 32)) | |
07855bec NC |
1248 | reloc = BFD_RELOC_390_PLT32DBL; |
1249 | } | |
1250 | else if (suffix == ELF_SUFFIX_GOTENT) | |
1251 | { | |
16a419ba NC |
1252 | if ((operand->flags & S390_OPERAND_PCREL) |
1253 | && (operand->bits == 32)) | |
07855bec NC |
1254 | reloc = BFD_RELOC_390_GOTENT; |
1255 | } | |
2a19f73f MS |
1256 | else if (suffix == ELF_SUFFIX_GOTOFF) |
1257 | { | |
1258 | if ((operand->flags & S390_OPERAND_SIGNED) | |
1259 | && (operand->bits == 16)) | |
1260 | reloc = BFD_RELOC_16_GOTOFF; | |
1261 | } | |
1262 | else if (suffix == ELF_SUFFIX_PLTOFF) | |
1263 | { | |
1264 | if ((operand->flags & S390_OPERAND_SIGNED) | |
1265 | && (operand->bits == 16)) | |
1266 | reloc = BFD_RELOC_390_PLTOFF16; | |
1267 | } | |
1268 | else if (suffix == ELF_SUFFIX_GOTPLT) | |
1269 | { | |
1270 | if ((operand->flags & S390_OPERAND_DISP) | |
1271 | && (operand->bits == 12)) | |
1272 | reloc = BFD_RELOC_390_GOTPLT12; | |
1273 | else if ((operand->flags & S390_OPERAND_SIGNED) | |
1274 | && (operand->bits == 16)) | |
1275 | reloc = BFD_RELOC_390_GOTPLT16; | |
1276 | else if ((operand->flags & S390_OPERAND_PCREL) | |
1277 | && (operand->bits == 32)) | |
1278 | reloc = BFD_RELOC_390_GOTPLTENT; | |
1279 | } | |
1971b29d MS |
1280 | else if (suffix == ELF_SUFFIX_TLS_GOTIE) |
1281 | { | |
1282 | if ((operand->flags & S390_OPERAND_DISP) | |
1283 | && (operand->bits == 12)) | |
1284 | reloc = BFD_RELOC_390_TLS_GOTIE12; | |
933fbc29 MS |
1285 | else if ((operand->flags & S390_OPERAND_DISP) |
1286 | && (operand->bits == 20)) | |
1287 | reloc = BFD_RELOC_390_TLS_GOTIE20; | |
1971b29d MS |
1288 | } |
1289 | else if (suffix == ELF_SUFFIX_TLS_IE) | |
1290 | { | |
1291 | if ((operand->flags & S390_OPERAND_PCREL) | |
1292 | && (operand->bits == 32)) | |
1293 | reloc = BFD_RELOC_390_TLS_IEENT; | |
1294 | } | |
07855bec NC |
1295 | |
1296 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) | |
1297 | as_bad (_("invalid operand suffix")); | |
1298 | /* We need to generate a fixup of type 'reloc' for this | |
1299 | expression. */ | |
a85d7ed0 NC |
1300 | if (fc >= MAX_INSN_FIXUPS) |
1301 | as_fatal (_("too many fixups")); | |
1302 | fixups[fc].exp = ex; | |
1303 | fixups[fc].opindex = *opindex_ptr; | |
07855bec | 1304 | fixups[fc].reloc = reloc; |
a85d7ed0 | 1305 | ++fc; |
07855bec | 1306 | } |
198ce79b | 1307 | |
07855bec NC |
1308 | /* Check the next character. The call to expression has advanced |
1309 | str past any whitespace. */ | |
1310 | if (operand->flags & S390_OPERAND_DISP) | |
1311 | { | |
1312 | /* After a displacement a block in parentheses can start. */ | |
1313 | if (*str != '(') | |
1314 | { | |
67c1ffbe | 1315 | /* Check if parenthesized block can be skipped. If the next |
07855bec NC |
1316 | operand is neiter an optional operand nor a base register |
1317 | then we have a syntax error. */ | |
1318 | operand = s390_operands + *(++opindex_ptr); | |
1319 | if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE))) | |
1320 | as_bad (_("syntax error; missing '(' after displacement")); | |
1321 | ||
1322 | /* Ok, skip all operands until S390_OPERAND_BASE. */ | |
1323 | while (!(operand->flags & S390_OPERAND_BASE)) | |
1324 | operand = s390_operands + *(++opindex_ptr); | |
198ce79b | 1325 | |
67c1ffbe | 1326 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1327 | if (opindex_ptr[1] != '\0') |
1328 | { | |
6c639ef9 MS |
1329 | if (*str != ',') |
1330 | { | |
1331 | while (opindex_ptr[1] != '\0') | |
1332 | { | |
1333 | operand = s390_operands + *(++opindex_ptr); | |
1334 | if (operand->flags & S390_OPERAND_OPTIONAL) | |
1335 | continue; | |
1336 | as_bad (_("syntax error; expected ,")); | |
1337 | break; | |
1338 | } | |
1339 | } | |
1340 | else | |
1341 | str++; | |
07855bec NC |
1342 | } |
1343 | } | |
1344 | else | |
1345 | { | |
1346 | /* We found an opening parentheses. */ | |
1347 | str++; | |
1348 | for (f = str; *f != '\0'; f++) | |
1349 | if (*f == ',' || *f == ')') | |
1350 | break; | |
1351 | /* If there is no comma until the closing parentheses OR | |
1352 | there is a comma right after the opening parentheses, | |
1353 | we have to skip optional operands. */ | |
1354 | if (*f == ',' && f == str) | |
1355 | { | |
1356 | /* comma directly after '(' ? */ | |
1357 | skip_optional = 1; | |
1358 | str++; | |
1359 | } | |
1360 | else | |
1361 | skip_optional = (*f != ','); | |
1362 | } | |
1363 | } | |
1364 | else if (operand->flags & S390_OPERAND_BASE) | |
1365 | { | |
1366 | /* After the base register the parenthesed block ends. */ | |
1367 | if (*str++ != ')') | |
1368 | as_bad (_("syntax error; missing ')' after base register")); | |
1369 | skip_optional = 0; | |
67c1ffbe | 1370 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1371 | if (opindex_ptr[1] != '\0') |
1372 | { | |
6c639ef9 MS |
1373 | if (*str != ',') |
1374 | { | |
1375 | while (opindex_ptr[1] != '\0') | |
1376 | { | |
1377 | operand = s390_operands + *(++opindex_ptr); | |
1378 | if (operand->flags & S390_OPERAND_OPTIONAL) | |
1379 | continue; | |
1380 | as_bad (_("syntax error; expected ,")); | |
1381 | break; | |
1382 | } | |
1383 | } | |
1384 | else | |
1385 | str++; | |
07855bec NC |
1386 | } |
1387 | } | |
1388 | else | |
1389 | { | |
1390 | /* We can find an 'early' closing parentheses in e.g. D(L) instead | |
1391 | of D(L,B). In this case the base register has to be skipped. */ | |
1392 | if (*str == ')') | |
1393 | { | |
1394 | operand = s390_operands + *(++opindex_ptr); | |
1395 | ||
1396 | if (!(operand->flags & S390_OPERAND_BASE)) | |
1397 | as_bad (_("syntax error; ')' not allowed here")); | |
1398 | str++; | |
1399 | } | |
67c1ffbe | 1400 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1401 | if (opindex_ptr[1] != '\0') |
1402 | { | |
6c639ef9 MS |
1403 | if (*str != ',') |
1404 | { | |
1405 | while (opindex_ptr[1] != '\0') | |
1406 | { | |
1407 | operand = s390_operands + *(++opindex_ptr); | |
1408 | if (operand->flags & S390_OPERAND_OPTIONAL) | |
1409 | continue; | |
1410 | as_bad (_("syntax error; expected ,")); | |
1411 | break; | |
1412 | } | |
1413 | } | |
1414 | else | |
1415 | str++; | |
07855bec | 1416 | } |
a85d7ed0 | 1417 | } |
a85d7ed0 | 1418 | } |
a85d7ed0 | 1419 | |
3882b010 | 1420 | while (ISSPACE (*str)) |
a85d7ed0 NC |
1421 | ++str; |
1422 | ||
1971b29d MS |
1423 | /* Check for tls instruction marker. */ |
1424 | reloc = s390_tls_suffix (&str, &ex); | |
1425 | if (reloc != BFD_RELOC_UNUSED) | |
1426 | { | |
1427 | /* We need to generate a fixup of type 'reloc' for this | |
1428 | instruction. */ | |
1429 | if (fc >= MAX_INSN_FIXUPS) | |
1430 | as_fatal (_("too many fixups")); | |
1431 | fixups[fc].exp = ex; | |
1432 | fixups[fc].opindex = -1; | |
1433 | fixups[fc].reloc = reloc; | |
1434 | ++fc; | |
1435 | } | |
1436 | ||
07855bec NC |
1437 | if (*str != '\0') |
1438 | { | |
1439 | char *linefeed; | |
a85d7ed0 | 1440 | |
07726851 | 1441 | if ((linefeed = strchr (str, '\n')) != NULL) |
07855bec NC |
1442 | *linefeed = '\0'; |
1443 | as_bad (_("junk at end of line: `%s'"), str); | |
1444 | if (linefeed != NULL) | |
1445 | *linefeed = '\n'; | |
1446 | } | |
a85d7ed0 NC |
1447 | |
1448 | /* Write out the instruction. */ | |
1449 | f = frag_more (opcode->oplen); | |
07855bec | 1450 | memcpy (f, insn, opcode->oplen); |
8f5b2891 | 1451 | dwarf2_emit_insn (opcode->oplen); |
a85d7ed0 NC |
1452 | |
1453 | /* Create any fixups. At this point we do not use a | |
1454 | bfd_reloc_code_real_type, but instead just use the | |
1455 | BFD_RELOC_UNUSED plus the operand index. This lets us easily | |
1456 | handle fixups for any operand type, although that is admittedly | |
1457 | not a very exciting feature. We pick a BFD reloc type in | |
55cf6793 | 1458 | md_apply_fix. */ |
07855bec NC |
1459 | for (i = 0; i < fc; i++) |
1460 | { | |
1971b29d MS |
1461 | |
1462 | if (fixups[i].opindex < 0) | |
1463 | { | |
1464 | /* Create tls instruction marker relocation. */ | |
1465 | fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen, | |
1466 | &fixups[i].exp, 0, fixups[i].reloc); | |
1467 | continue; | |
1468 | } | |
1469 | ||
07855bec | 1470 | operand = s390_operands + fixups[i].opindex; |
a85d7ed0 | 1471 | |
07855bec NC |
1472 | if (fixups[i].reloc != BFD_RELOC_UNUSED) |
1473 | { | |
1474 | reloc_howto_type *reloc_howto; | |
1475 | fixS *fixP; | |
1476 | int size; | |
198ce79b | 1477 | |
07855bec NC |
1478 | reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); |
1479 | if (!reloc_howto) | |
1480 | abort (); | |
198ce79b | 1481 | |
07855bec NC |
1482 | size = bfd_get_reloc_size (reloc_howto); |
1483 | ||
1484 | if (size < 1 || size > 4) | |
1485 | abort (); | |
198ce79b AJ |
1486 | |
1487 | fixP = fix_new_exp (frag_now, | |
1488 | f - frag_now->fr_literal + (operand->shift/8), | |
07855bec NC |
1489 | size, &fixups[i].exp, reloc_howto->pc_relative, |
1490 | fixups[i].reloc); | |
1491 | /* Turn off overflow checking in fixup_segment. This is necessary | |
1492 | because fixup_segment will signal an overflow for large 4 byte | |
1493 | quantities for GOT12 relocations. */ | |
16a419ba | 1494 | if ( fixups[i].reloc == BFD_RELOC_390_GOT12 |
933fbc29 | 1495 | || fixups[i].reloc == BFD_RELOC_390_GOT20 |
16a419ba | 1496 | || fixups[i].reloc == BFD_RELOC_390_GOT16) |
07855bec NC |
1497 | fixP->fx_no_overflow = 1; |
1498 | } | |
1499 | else | |
1500 | fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp, | |
1501 | (operand->flags & S390_OPERAND_PCREL) != 0, | |
1502 | ((bfd_reloc_code_real_type) | |
1503 | (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); | |
1504 | } | |
a85d7ed0 NC |
1505 | return str; |
1506 | } | |
1507 | ||
1508 | /* This routine is called for each instruction to be assembled. */ | |
1509 | ||
1510 | void | |
5a49b8ac | 1511 | md_assemble (char *str) |
a85d7ed0 NC |
1512 | { |
1513 | const struct s390_opcode *opcode; | |
1514 | unsigned char insn[6]; | |
1515 | char *s; | |
1516 | ||
1517 | /* Get the opcode. */ | |
3882b010 | 1518 | for (s = str; *s != '\0' && ! ISSPACE (*s); s++) |
a85d7ed0 NC |
1519 | ; |
1520 | if (*s != '\0') | |
1521 | *s++ = '\0'; | |
1522 | ||
1523 | /* Look up the opcode in the hash table. */ | |
1524 | opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str); | |
07855bec NC |
1525 | if (opcode == (const struct s390_opcode *) NULL) |
1526 | { | |
1527 | as_bad (_("Unrecognized opcode: `%s'"), str); | |
1528 | return; | |
1529 | } | |
37a58793 MS |
1530 | else if (!(opcode->modes & current_mode_mask)) |
1531 | { | |
1532 | as_bad ("Opcode %s not available in this mode", str); | |
1533 | return; | |
1534 | } | |
07726851 | 1535 | memcpy (insn, opcode->opcode, sizeof (insn)); |
07855bec | 1536 | md_gather_operands (s, insn, opcode); |
a85d7ed0 NC |
1537 | } |
1538 | ||
1539 | #ifndef WORKING_DOT_WORD | |
1540 | /* Handle long and short jumps. We don't support these */ | |
1541 | void | |
1542 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1543 | char *ptr; | |
1544 | addressT from_addr, to_addr; | |
1545 | fragS *frag; | |
1546 | symbolS *to_symbol; | |
1547 | { | |
1548 | abort (); | |
1549 | } | |
1550 | ||
1551 | void | |
1552 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1553 | char *ptr; | |
1554 | addressT from_addr, to_addr; | |
1555 | fragS *frag; | |
1556 | symbolS *to_symbol; | |
1557 | { | |
1558 | abort (); | |
1559 | } | |
1560 | #endif | |
1561 | ||
1562 | void | |
5a49b8ac | 1563 | s390_bss (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1564 | { |
1565 | /* We don't support putting frags in the BSS segment, we fake it | |
1566 | by marking in_bss, then looking at s_skip for clues. */ | |
1567 | ||
1568 | subseg_set (bss_section, 0); | |
1569 | demand_empty_rest_of_line (); | |
1570 | } | |
1571 | ||
1572 | /* Pseudo-op handling. */ | |
1573 | ||
1574 | void | |
5a49b8ac | 1575 | s390_insn (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1576 | { |
1577 | expressionS exp; | |
1578 | const struct s390_opcode *opformat; | |
1579 | unsigned char insn[6]; | |
1580 | char *s; | |
1581 | ||
1582 | /* Get the opcode format. */ | |
1583 | s = input_line_pointer; | |
3882b010 | 1584 | while (*s != '\0' && *s != ',' && ! ISSPACE (*s)) |
a85d7ed0 NC |
1585 | s++; |
1586 | if (*s != ',') | |
1587 | as_bad (_("Invalid .insn format\n")); | |
1588 | *s++ = '\0'; | |
1589 | ||
1590 | /* Look up the opcode in the hash table. */ | |
1591 | opformat = (struct s390_opcode *) | |
1592 | hash_find (s390_opformat_hash, input_line_pointer); | |
07855bec NC |
1593 | if (opformat == (const struct s390_opcode *) NULL) |
1594 | { | |
1595 | as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer); | |
1596 | return; | |
1597 | } | |
a85d7ed0 NC |
1598 | input_line_pointer = s; |
1599 | expression (&exp); | |
07855bec NC |
1600 | if (exp.X_op == O_constant) |
1601 | { | |
1d6d62a4 | 1602 | if ( ( opformat->oplen == 6 |
1d6d62a4 MS |
1603 | && (addressT) exp.X_add_number < (1ULL << 48)) |
1604 | || ( opformat->oplen == 4 | |
1d6d62a4 MS |
1605 | && (addressT) exp.X_add_number < (1ULL << 32)) |
1606 | || ( opformat->oplen == 2 | |
1d6d62a4 | 1607 | && (addressT) exp.X_add_number < (1ULL << 16))) |
2132e3a3 | 1608 | md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen); |
07855bec | 1609 | else |
07726851 | 1610 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1611 | } |
1612 | else if (exp.X_op == O_big) | |
1613 | { | |
16a419ba NC |
1614 | if (exp.X_add_number > 0 |
1615 | && opformat->oplen == 6 | |
1616 | && generic_bignum[3] == 0) | |
07855bec | 1617 | { |
2132e3a3 AM |
1618 | md_number_to_chars ((char *) insn, generic_bignum[2], 2); |
1619 | md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2); | |
1620 | md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2); | |
07855bec NC |
1621 | } |
1622 | else | |
07726851 | 1623 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1624 | } |
1625 | else | |
a85d7ed0 | 1626 | as_bad (_("second operand of .insn not a constant\n")); |
a85d7ed0 | 1627 | |
b6849f55 NC |
1628 | if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',') |
1629 | as_bad (_("missing comma after insn constant\n")); | |
98d3f06f | 1630 | |
07726851 | 1631 | if ((s = strchr (input_line_pointer, '\n')) != NULL) |
a85d7ed0 | 1632 | *s = '\0'; |
b6849f55 NC |
1633 | input_line_pointer = md_gather_operands (input_line_pointer, insn, |
1634 | opformat); | |
a85d7ed0 NC |
1635 | if (s != NULL) |
1636 | *s = '\n'; | |
1637 | demand_empty_rest_of_line (); | |
1638 | } | |
1639 | ||
1640 | /* The .byte pseudo-op. This is similar to the normal .byte | |
1641 | pseudo-op, but it can also take a single ASCII string. */ | |
1642 | ||
1643 | static void | |
5a49b8ac | 1644 | s390_byte (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1645 | { |
1646 | if (*input_line_pointer != '\"') | |
1647 | { | |
1648 | cons (1); | |
1649 | return; | |
1650 | } | |
1651 | ||
1652 | /* Gather characters. A real double quote is doubled. Unusual | |
1653 | characters are not permitted. */ | |
1654 | ++input_line_pointer; | |
1655 | while (1) | |
1656 | { | |
1657 | char c; | |
1658 | ||
1659 | c = *input_line_pointer++; | |
1660 | ||
1661 | if (c == '\"') | |
1662 | { | |
1663 | if (*input_line_pointer != '\"') | |
1664 | break; | |
1665 | ++input_line_pointer; | |
1666 | } | |
1667 | ||
1668 | FRAG_APPEND_1_CHAR (c); | |
1669 | } | |
1670 | ||
1671 | demand_empty_rest_of_line (); | |
1672 | } | |
1673 | ||
1674 | /* The .ltorg pseudo-op.This emits all literals defined since the last | |
198ce79b | 1675 | .ltorg or the invocation of gas. Literals are defined with the |
a85d7ed0 NC |
1676 | @lit suffix. */ |
1677 | ||
1678 | static void | |
5a49b8ac | 1679 | s390_literals (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1680 | { |
1681 | struct s390_lpe *lpe; | |
1682 | ||
1683 | if (lp_sym == NULL || lpe_count == 0) | |
98d3f06f | 1684 | return; /* Nothing to be done. */ |
a85d7ed0 NC |
1685 | |
1686 | /* Emit symbol for start of literal pool. */ | |
1687 | S_SET_SEGMENT (lp_sym, now_seg); | |
1688 | S_SET_VALUE (lp_sym, (valueT) frag_now_fix ()); | |
1689 | lp_sym->sy_frag = frag_now; | |
1690 | ||
07855bec NC |
1691 | while (lpe_list) |
1692 | { | |
1693 | lpe = lpe_list; | |
1694 | lpe_list = lpe_list->next; | |
1695 | S_SET_SEGMENT (lpe->sym, now_seg); | |
1696 | S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ()); | |
1697 | lpe->sym->sy_frag = frag_now; | |
1698 | ||
1699 | /* Emit literal pool entry. */ | |
1700 | if (lpe->reloc != BFD_RELOC_UNUSED) | |
1701 | { | |
198ce79b | 1702 | reloc_howto_type *reloc_howto = |
07855bec NC |
1703 | bfd_reloc_type_lookup (stdoutput, lpe->reloc); |
1704 | int size = bfd_get_reloc_size (reloc_howto); | |
1705 | char *where; | |
1706 | ||
1707 | if (size > lpe->nbytes) | |
1708 | as_bad (_("%s relocations do not fit in %d bytes"), | |
1709 | reloc_howto->name, lpe->nbytes); | |
07726851 | 1710 | where = frag_more (lpe->nbytes); |
07855bec NC |
1711 | md_number_to_chars (where, 0, size); |
1712 | fix_new_exp (frag_now, where - frag_now->fr_literal, | |
1713 | size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc); | |
1714 | } | |
1715 | else | |
1716 | { | |
1717 | if (lpe->ex.X_op == O_big) | |
1718 | { | |
1719 | if (lpe->ex.X_add_number <= 0) | |
1720 | generic_floating_point_number = lpe->floatnum; | |
1721 | else | |
1722 | memcpy (generic_bignum, lpe->bignum, | |
98d3f06f | 1723 | lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE)); |
07855bec NC |
1724 | } |
1725 | emit_expr (&lpe->ex, lpe->nbytes); | |
1726 | } | |
a85d7ed0 | 1727 | |
07855bec NC |
1728 | lpe->next = lpe_free_list; |
1729 | lpe_free_list = lpe; | |
1730 | } | |
a85d7ed0 NC |
1731 | lpe_list_tail = NULL; |
1732 | lp_sym = NULL; | |
1733 | lp_count++; | |
1734 | lpe_count = 0; | |
1735 | } | |
1736 | ||
a85d7ed0 | 1737 | char * |
499ac353 | 1738 | md_atof (int type, char *litp, int *sizep) |
a85d7ed0 | 1739 | { |
499ac353 | 1740 | return ieee_md_atof (type, litp, sizep, TRUE); |
a85d7ed0 NC |
1741 | } |
1742 | ||
1743 | /* Align a section (I don't know why this is machine dependent). */ | |
1744 | ||
1745 | valueT | |
5a49b8ac | 1746 | md_section_align (asection *seg, valueT addr) |
a85d7ed0 NC |
1747 | { |
1748 | int align = bfd_get_section_alignment (stdoutput, seg); | |
1749 | ||
1750 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
1751 | } | |
1752 | ||
1753 | /* We don't have any form of relaxing. */ | |
1754 | ||
1755 | int | |
5a49b8ac AM |
1756 | md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED, |
1757 | asection *seg ATTRIBUTE_UNUSED) | |
a85d7ed0 NC |
1758 | { |
1759 | abort (); | |
1760 | return 0; | |
1761 | } | |
1762 | ||
1763 | /* Convert a machine dependent frag. We never generate these. */ | |
1764 | ||
1765 | void | |
5a49b8ac AM |
1766 | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, |
1767 | asection *sec ATTRIBUTE_UNUSED, | |
1768 | fragS *fragp ATTRIBUTE_UNUSED) | |
a85d7ed0 NC |
1769 | { |
1770 | abort (); | |
1771 | } | |
1772 | ||
1773 | symbolS * | |
5a49b8ac | 1774 | md_undefined_symbol (char *name) |
a85d7ed0 | 1775 | { |
98d3f06f | 1776 | if (*name == '_' && *(name + 1) == 'G' |
07726851 | 1777 | && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) |
98d3f06f KH |
1778 | { |
1779 | if (!GOT_symbol) | |
1780 | { | |
1781 | if (symbol_find (name)) | |
1782 | as_bad (_("GOT already in symbol table")); | |
1783 | GOT_symbol = symbol_new (name, undefined_section, | |
1784 | (valueT) 0, &zero_address_frag); | |
1785 | } | |
1786 | return GOT_symbol; | |
1787 | } | |
a85d7ed0 NC |
1788 | return 0; |
1789 | } | |
1790 | ||
1791 | /* Functions concerning relocs. */ | |
1792 | ||
1793 | /* The location from which a PC relative jump should be calculated, | |
1794 | given a PC relative reloc. */ | |
1795 | ||
1796 | long | |
5a49b8ac | 1797 | md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1798 | { |
1799 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
1800 | } | |
1801 | ||
1802 | /* Here we decide which fixups can be adjusted to make them relative to | |
1803 | the beginning of the section instead of the symbol. Basically we need | |
1804 | to make sure that the dynamic relocations are done correctly, so in | |
1805 | some cases we force the original symbol to be used. */ | |
1806 | int | |
5a49b8ac | 1807 | tc_s390_fix_adjustable (fixS *fixP) |
a85d7ed0 | 1808 | { |
0a00dd48 MS |
1809 | /* Don't adjust references to merge sections. */ |
1810 | if ((S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0) | |
1811 | return 0; | |
a85d7ed0 | 1812 | /* adjust_reloc_syms doesn't know about the GOT. */ |
2a19f73f MS |
1813 | if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF |
1814 | || fixP->fx_r_type == BFD_RELOC_32_GOTOFF | |
1815 | || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64 | |
1816 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16 | |
1817 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32 | |
1818 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64 | |
a85d7ed0 NC |
1819 | || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL |
1820 | || fixP->fx_r_type == BFD_RELOC_390_PLT32 | |
1821 | || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL | |
1822 | || fixP->fx_r_type == BFD_RELOC_390_PLT64 | |
1823 | || fixP->fx_r_type == BFD_RELOC_390_GOT12 | |
933fbc29 | 1824 | || fixP->fx_r_type == BFD_RELOC_390_GOT20 |
a85d7ed0 NC |
1825 | || fixP->fx_r_type == BFD_RELOC_390_GOT16 |
1826 | || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL | |
1827 | || fixP->fx_r_type == BFD_RELOC_390_GOT64 | |
07855bec | 1828 | || fixP->fx_r_type == BFD_RELOC_390_GOTENT |
2a19f73f MS |
1829 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12 |
1830 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16 | |
933fbc29 | 1831 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20 |
2a19f73f MS |
1832 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32 |
1833 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64 | |
1834 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT | |
1971b29d MS |
1835 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD |
1836 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL | |
1837 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL | |
1838 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32 | |
1839 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64 | |
1840 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12 | |
933fbc29 | 1841 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20 |
1971b29d MS |
1842 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32 |
1843 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64 | |
1844 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32 | |
1845 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64 | |
1846 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32 | |
1847 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64 | |
1848 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT | |
1849 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32 | |
1850 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64 | |
1851 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32 | |
1852 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64 | |
1853 | || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD | |
1854 | || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF | |
1855 | || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF | |
a85d7ed0 NC |
1856 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
1857 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
1858 | return 0; | |
1859 | return 1; | |
1860 | } | |
1861 | ||
b8edc45c | 1862 | /* Return true if we must always emit a reloc for a type and false if |
c03099e6 | 1863 | there is some hope of resolving it at assembly time. */ |
b8edc45c | 1864 | int |
5a49b8ac | 1865 | tc_s390_force_relocation (struct fix *fixp) |
b8edc45c MS |
1866 | { |
1867 | /* Ensure we emit a relocation for every reference to the global | |
1868 | offset table or to the procedure link table. */ | |
1869 | switch (fixp->fx_r_type) | |
1870 | { | |
1871 | case BFD_RELOC_390_GOT12: | |
933fbc29 | 1872 | case BFD_RELOC_390_GOT20: |
b8edc45c MS |
1873 | case BFD_RELOC_32_GOT_PCREL: |
1874 | case BFD_RELOC_32_GOTOFF: | |
2a19f73f MS |
1875 | case BFD_RELOC_390_GOTOFF64: |
1876 | case BFD_RELOC_390_PLTOFF16: | |
1877 | case BFD_RELOC_390_PLTOFF32: | |
1878 | case BFD_RELOC_390_PLTOFF64: | |
b8edc45c MS |
1879 | case BFD_RELOC_390_GOTPC: |
1880 | case BFD_RELOC_390_GOT16: | |
1881 | case BFD_RELOC_390_GOTPCDBL: | |
1882 | case BFD_RELOC_390_GOT64: | |
1883 | case BFD_RELOC_390_GOTENT: | |
1884 | case BFD_RELOC_390_PLT32: | |
1885 | case BFD_RELOC_390_PLT16DBL: | |
1886 | case BFD_RELOC_390_PLT32DBL: | |
1887 | case BFD_RELOC_390_PLT64: | |
2a19f73f MS |
1888 | case BFD_RELOC_390_GOTPLT12: |
1889 | case BFD_RELOC_390_GOTPLT16: | |
933fbc29 | 1890 | case BFD_RELOC_390_GOTPLT20: |
2a19f73f MS |
1891 | case BFD_RELOC_390_GOTPLT32: |
1892 | case BFD_RELOC_390_GOTPLT64: | |
1893 | case BFD_RELOC_390_GOTPLTENT: | |
b8edc45c MS |
1894 | return 1; |
1895 | default: | |
a161fe53 | 1896 | break;; |
b8edc45c | 1897 | } |
a161fe53 | 1898 | |
ae6063d4 | 1899 | return generic_force_reloc (fixp); |
b8edc45c MS |
1900 | } |
1901 | ||
a85d7ed0 NC |
1902 | /* Apply a fixup to the object code. This is called for all the |
1903 | fixups we generated by the call to fix_new_exp, above. In the call | |
1904 | above we used a reloc code which was the largest legal reloc code | |
1905 | plus the operand index. Here we undo that to recover the operand | |
1906 | index. At this point all symbol values should be fully resolved, | |
1907 | and we attempt to completely resolve the reloc. If we can not do | |
1908 | that, we determine the correct reloc code and put it back in the | |
1909 | fixup. */ | |
1910 | ||
94f592af | 1911 | void |
5a49b8ac | 1912 | md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1913 | { |
1914 | char *where; | |
98d3f06f | 1915 | valueT value = *valP; |
a85d7ed0 | 1916 | |
94f592af | 1917 | where = fixP->fx_frag->fr_literal + fixP->fx_where; |
a85d7ed0 | 1918 | |
98d3f06f | 1919 | if (fixP->fx_subsy != NULL) |
f1fc51da MS |
1920 | as_bad_where (fixP->fx_file, fixP->fx_line, |
1921 | "cannot emit relocation %s against subsy symbol %s", | |
1922 | bfd_get_reloc_code_name (fixP->fx_r_type), | |
1923 | S_GET_NAME (fixP->fx_subsy)); | |
98d3f06f KH |
1924 | |
1925 | if (fixP->fx_addsy != NULL) | |
07855bec | 1926 | { |
94f592af NC |
1927 | if (fixP->fx_pcrel) |
1928 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
07855bec NC |
1929 | } |
1930 | else | |
94f592af | 1931 | fixP->fx_done = 1; |
a85d7ed0 | 1932 | |
94f592af | 1933 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
07855bec NC |
1934 | { |
1935 | const struct s390_operand *operand; | |
1936 | int opindex; | |
198ce79b | 1937 | |
94f592af | 1938 | opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
07855bec | 1939 | operand = &s390_operands[opindex]; |
198ce79b | 1940 | |
94f592af | 1941 | if (fixP->fx_done) |
07855bec NC |
1942 | { |
1943 | /* Insert the fully resolved operand value. */ | |
2132e3a3 AM |
1944 | s390_insert_operand ((unsigned char *) where, operand, |
1945 | (offsetT) value, fixP->fx_file, fixP->fx_line); | |
94f592af | 1946 | return; |
07855bec | 1947 | } |
198ce79b | 1948 | |
07855bec NC |
1949 | /* Determine a BFD reloc value based on the operand information. |
1950 | We are only prepared to turn a few of the operands into | |
1951 | relocs. */ | |
94f592af | 1952 | fixP->fx_offset = value; |
07855bec NC |
1953 | if (operand->bits == 12 && operand->shift == 20) |
1954 | { | |
94f592af NC |
1955 | fixP->fx_size = 2; |
1956 | fixP->fx_where += 2; | |
1957 | fixP->fx_r_type = BFD_RELOC_390_12; | |
07855bec NC |
1958 | } |
1959 | else if (operand->bits == 12 && operand->shift == 36) | |
1960 | { | |
94f592af NC |
1961 | fixP->fx_size = 2; |
1962 | fixP->fx_where += 4; | |
1963 | fixP->fx_r_type = BFD_RELOC_390_12; | |
07855bec | 1964 | } |
933fbc29 MS |
1965 | else if (operand->bits == 20 && operand->shift == 20) |
1966 | { | |
1967 | fixP->fx_size = 2; | |
1968 | fixP->fx_where += 2; | |
1969 | fixP->fx_r_type = BFD_RELOC_390_20; | |
1970 | } | |
07855bec NC |
1971 | else if (operand->bits == 8 && operand->shift == 8) |
1972 | { | |
94f592af NC |
1973 | fixP->fx_size = 1; |
1974 | fixP->fx_where += 1; | |
1975 | fixP->fx_r_type = BFD_RELOC_8; | |
07855bec NC |
1976 | } |
1977 | else if (operand->bits == 16 && operand->shift == 16) | |
1978 | { | |
94f592af NC |
1979 | fixP->fx_size = 2; |
1980 | fixP->fx_where += 2; | |
07855bec NC |
1981 | if (operand->flags & S390_OPERAND_PCREL) |
1982 | { | |
94f592af NC |
1983 | fixP->fx_r_type = BFD_RELOC_390_PC16DBL; |
1984 | fixP->fx_offset += 2; | |
07855bec NC |
1985 | } |
1986 | else | |
94f592af | 1987 | fixP->fx_r_type = BFD_RELOC_16; |
07855bec | 1988 | } |
16a419ba NC |
1989 | else if (operand->bits == 32 && operand->shift == 16 |
1990 | && (operand->flags & S390_OPERAND_PCREL)) | |
07855bec | 1991 | { |
94f592af NC |
1992 | fixP->fx_size = 4; |
1993 | fixP->fx_where += 2; | |
1994 | fixP->fx_offset += 2; | |
1995 | fixP->fx_r_type = BFD_RELOC_390_PC32DBL; | |
07855bec | 1996 | } |
a85d7ed0 | 1997 | else |
07855bec NC |
1998 | { |
1999 | char *sfile; | |
2000 | unsigned int sline; | |
198ce79b | 2001 | |
07855bec NC |
2002 | /* Use expr_symbol_where to see if this is an expression |
2003 | symbol. */ | |
94f592af NC |
2004 | if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) |
2005 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
07855bec NC |
2006 | _("unresolved expression that must be resolved")); |
2007 | else | |
94f592af | 2008 | as_bad_where (fixP->fx_file, fixP->fx_line, |
07855bec | 2009 | _("unsupported relocation type")); |
94f592af NC |
2010 | fixP->fx_done = 1; |
2011 | return; | |
07855bec | 2012 | } |
a85d7ed0 | 2013 | } |
07855bec NC |
2014 | else |
2015 | { | |
94f592af | 2016 | switch (fixP->fx_r_type) |
07855bec NC |
2017 | { |
2018 | case BFD_RELOC_8: | |
94f592af | 2019 | if (fixP->fx_pcrel) |
07855bec | 2020 | abort (); |
94f592af | 2021 | if (fixP->fx_done) |
07855bec NC |
2022 | md_number_to_chars (where, value, 1); |
2023 | break; | |
2024 | case BFD_RELOC_390_12: | |
2025 | case BFD_RELOC_390_GOT12: | |
2a19f73f | 2026 | case BFD_RELOC_390_GOTPLT12: |
94f592af | 2027 | if (fixP->fx_done) |
07855bec NC |
2028 | { |
2029 | unsigned short mop; | |
2030 | ||
2031 | mop = bfd_getb16 ((unsigned char *) where); | |
2032 | mop |= (unsigned short) (value & 0xfff); | |
2033 | bfd_putb16 ((bfd_vma) mop, (unsigned char *) where); | |
198ce79b | 2034 | } |
07855bec | 2035 | break; |
198ce79b | 2036 | |
933fbc29 MS |
2037 | case BFD_RELOC_390_20: |
2038 | case BFD_RELOC_390_GOT20: | |
2039 | case BFD_RELOC_390_GOTPLT20: | |
2040 | if (fixP->fx_done) | |
2041 | { | |
2042 | unsigned int mop; | |
2043 | mop = bfd_getb32 ((unsigned char *) where); | |
2044 | mop |= (unsigned int) ((value & 0xfff) << 8 | | |
2045 | (value & 0xff000) >> 12); | |
2046 | bfd_putb32 ((bfd_vma) mop, (unsigned char *) where); | |
2047 | } | |
2048 | break; | |
2049 | ||
07855bec NC |
2050 | case BFD_RELOC_16: |
2051 | case BFD_RELOC_GPREL16: | |
2052 | case BFD_RELOC_16_GOT_PCREL: | |
2053 | case BFD_RELOC_16_GOTOFF: | |
94f592af NC |
2054 | if (fixP->fx_pcrel) |
2055 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
07855bec | 2056 | "cannot emit PC relative %s relocation%s%s", |
94f592af NC |
2057 | bfd_get_reloc_code_name (fixP->fx_r_type), |
2058 | fixP->fx_addsy != NULL ? " against " : "", | |
2059 | (fixP->fx_addsy != NULL | |
2060 | ? S_GET_NAME (fixP->fx_addsy) | |
07855bec | 2061 | : "")); |
94f592af | 2062 | if (fixP->fx_done) |
07855bec NC |
2063 | md_number_to_chars (where, value, 2); |
2064 | break; | |
2065 | case BFD_RELOC_390_GOT16: | |
2a19f73f MS |
2066 | case BFD_RELOC_390_PLTOFF16: |
2067 | case BFD_RELOC_390_GOTPLT16: | |
94f592af | 2068 | if (fixP->fx_done) |
07855bec NC |
2069 | md_number_to_chars (where, value, 2); |
2070 | break; | |
2071 | case BFD_RELOC_390_PC16DBL: | |
2072 | case BFD_RELOC_390_PLT16DBL: | |
2073 | value += 2; | |
94f592af | 2074 | if (fixP->fx_done) |
07855bec NC |
2075 | md_number_to_chars (where, (offsetT) value >> 1, 2); |
2076 | break; | |
2077 | ||
2078 | case BFD_RELOC_32: | |
94f592af NC |
2079 | if (fixP->fx_pcrel) |
2080 | fixP->fx_r_type = BFD_RELOC_32_PCREL; | |
07855bec | 2081 | else |
94f592af NC |
2082 | fixP->fx_r_type = BFD_RELOC_32; |
2083 | if (fixP->fx_done) | |
07855bec NC |
2084 | md_number_to_chars (where, value, 4); |
2085 | break; | |
2086 | case BFD_RELOC_32_PCREL: | |
2087 | case BFD_RELOC_32_BASEREL: | |
94f592af NC |
2088 | fixP->fx_r_type = BFD_RELOC_32_PCREL; |
2089 | if (fixP->fx_done) | |
07855bec NC |
2090 | md_number_to_chars (where, value, 4); |
2091 | break; | |
2092 | case BFD_RELOC_32_GOT_PCREL: | |
2a19f73f | 2093 | case BFD_RELOC_390_PLTOFF32: |
07855bec | 2094 | case BFD_RELOC_390_PLT32: |
2a19f73f | 2095 | case BFD_RELOC_390_GOTPLT32: |
94f592af | 2096 | if (fixP->fx_done) |
07855bec NC |
2097 | md_number_to_chars (where, value, 4); |
2098 | break; | |
2099 | case BFD_RELOC_390_PC32DBL: | |
2100 | case BFD_RELOC_390_PLT32DBL: | |
2101 | case BFD_RELOC_390_GOTPCDBL: | |
2102 | case BFD_RELOC_390_GOTENT: | |
2a19f73f | 2103 | case BFD_RELOC_390_GOTPLTENT: |
07855bec | 2104 | value += 2; |
94f592af | 2105 | if (fixP->fx_done) |
07855bec NC |
2106 | md_number_to_chars (where, (offsetT) value >> 1, 4); |
2107 | break; | |
2108 | ||
2109 | case BFD_RELOC_32_GOTOFF: | |
94f592af | 2110 | if (fixP->fx_done) |
07726851 | 2111 | md_number_to_chars (where, value, sizeof (int)); |
07855bec NC |
2112 | break; |
2113 | ||
2a19f73f MS |
2114 | case BFD_RELOC_390_GOTOFF64: |
2115 | if (fixP->fx_done) | |
2116 | md_number_to_chars (where, value, 8); | |
2117 | break; | |
2118 | ||
07855bec | 2119 | case BFD_RELOC_390_GOT64: |
2a19f73f | 2120 | case BFD_RELOC_390_PLTOFF64: |
07855bec | 2121 | case BFD_RELOC_390_PLT64: |
2a19f73f | 2122 | case BFD_RELOC_390_GOTPLT64: |
94f592af | 2123 | if (fixP->fx_done) |
07855bec NC |
2124 | md_number_to_chars (where, value, 8); |
2125 | break; | |
2126 | ||
2127 | case BFD_RELOC_64: | |
94f592af NC |
2128 | if (fixP->fx_pcrel) |
2129 | fixP->fx_r_type = BFD_RELOC_64_PCREL; | |
07855bec | 2130 | else |
94f592af NC |
2131 | fixP->fx_r_type = BFD_RELOC_64; |
2132 | if (fixP->fx_done) | |
07855bec NC |
2133 | md_number_to_chars (where, value, 8); |
2134 | break; | |
2135 | ||
2136 | case BFD_RELOC_64_PCREL: | |
94f592af NC |
2137 | fixP->fx_r_type = BFD_RELOC_64_PCREL; |
2138 | if (fixP->fx_done) | |
07855bec NC |
2139 | md_number_to_chars (where, value, 8); |
2140 | break; | |
2141 | ||
2142 | case BFD_RELOC_VTABLE_INHERIT: | |
2143 | case BFD_RELOC_VTABLE_ENTRY: | |
94f592af NC |
2144 | fixP->fx_done = 0; |
2145 | return; | |
07855bec | 2146 | |
1971b29d MS |
2147 | case BFD_RELOC_390_TLS_LOAD: |
2148 | case BFD_RELOC_390_TLS_GDCALL: | |
2149 | case BFD_RELOC_390_TLS_LDCALL: | |
2150 | case BFD_RELOC_390_TLS_GD32: | |
2151 | case BFD_RELOC_390_TLS_GD64: | |
2152 | case BFD_RELOC_390_TLS_GOTIE12: | |
933fbc29 | 2153 | case BFD_RELOC_390_TLS_GOTIE20: |
1971b29d MS |
2154 | case BFD_RELOC_390_TLS_GOTIE32: |
2155 | case BFD_RELOC_390_TLS_GOTIE64: | |
2156 | case BFD_RELOC_390_TLS_LDM32: | |
2157 | case BFD_RELOC_390_TLS_LDM64: | |
2158 | case BFD_RELOC_390_TLS_IE32: | |
2159 | case BFD_RELOC_390_TLS_IE64: | |
2160 | case BFD_RELOC_390_TLS_LE32: | |
2161 | case BFD_RELOC_390_TLS_LE64: | |
2162 | case BFD_RELOC_390_TLS_LDO32: | |
2163 | case BFD_RELOC_390_TLS_LDO64: | |
2164 | case BFD_RELOC_390_TLS_DTPMOD: | |
2165 | case BFD_RELOC_390_TLS_DTPOFF: | |
2166 | case BFD_RELOC_390_TLS_TPOFF: | |
7c1d0959 | 2167 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
1971b29d MS |
2168 | /* Fully resolved at link time. */ |
2169 | break; | |
2170 | case BFD_RELOC_390_TLS_IEENT: | |
2171 | /* Fully resolved at link time. */ | |
7c1d0959 | 2172 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
1971b29d MS |
2173 | value += 2; |
2174 | break; | |
2175 | ||
07855bec NC |
2176 | default: |
2177 | { | |
94f592af | 2178 | const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type); |
198ce79b | 2179 | |
07855bec NC |
2180 | if (reloc_name != NULL) |
2181 | fprintf (stderr, "Gas failure, reloc type %s\n", reloc_name); | |
2182 | else | |
94f592af | 2183 | fprintf (stderr, "Gas failure, reloc type #%i\n", fixP->fx_r_type); |
07855bec NC |
2184 | fflush (stderr); |
2185 | abort (); | |
2186 | } | |
2187 | } | |
a85d7ed0 | 2188 | |
94f592af | 2189 | fixP->fx_offset = value; |
07855bec | 2190 | } |
a85d7ed0 NC |
2191 | } |
2192 | ||
2193 | /* Generate a reloc for a fixup. */ | |
2194 | ||
2195 | arelent * | |
5a49b8ac | 2196 | tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) |
a85d7ed0 NC |
2197 | { |
2198 | bfd_reloc_code_real_type code; | |
2199 | arelent *reloc; | |
2200 | ||
2201 | code = fixp->fx_r_type; | |
07855bec NC |
2202 | if (GOT_symbol && fixp->fx_addsy == GOT_symbol) |
2203 | { | |
16a419ba NC |
2204 | if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL) |
2205 | || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL)) | |
07855bec NC |
2206 | code = BFD_RELOC_390_GOTPC; |
2207 | if (code == BFD_RELOC_390_PC32DBL) | |
2208 | code = BFD_RELOC_390_GOTPCDBL; | |
2209 | } | |
a85d7ed0 NC |
2210 | |
2211 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
2212 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
2213 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
2214 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
2215 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
2216 | if (reloc->howto == NULL) | |
2217 | { | |
2218 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
98d3f06f KH |
2219 | _("cannot represent relocation type %s"), |
2220 | bfd_get_reloc_code_name (code)); | |
a85d7ed0 NC |
2221 | /* Set howto to a garbage value so that we can keep going. */ |
2222 | reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); | |
2223 | assert (reloc->howto != NULL); | |
2224 | } | |
2225 | reloc->addend = fixp->fx_offset; | |
2226 | ||
2227 | return reloc; | |
2228 | } | |
75e21f08 JJ |
2229 | |
2230 | void | |
5a49b8ac | 2231 | s390_cfi_frame_initial_instructions (void) |
75e21f08 JJ |
2232 | { |
2233 | cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96); | |
2234 | } | |
2235 | ||
2236 | int | |
1df69f4f | 2237 | tc_s390_regname_to_dw2regnum (char *regname) |
75e21f08 JJ |
2238 | { |
2239 | int regnum = -1; | |
2240 | ||
2241 | if (regname[0] != 'c' && regname[0] != 'a') | |
2242 | { | |
2243 | regnum = reg_name_search (pre_defined_registers, REG_NAME_CNT, regname); | |
2244 | if (regname[0] == 'f' && regnum != -1) | |
2245 | regnum += 16; | |
2246 | } | |
2247 | else if (strcmp (regname, "ap") == 0) | |
2248 | regnum = 32; | |
2249 | else if (strcmp (regname, "cc") == 0) | |
2250 | regnum = 33; | |
2251 | return regnum; | |
2252 | } |