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