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