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