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