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