Commit | Line | Data |
---|---|---|
a85d7ed0 | 1 | /* tc-s390.c -- Assemble for the S390 |
250d07de | 2 | Copyright (C) 2000-2021 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. */ | |
51 | static bfd_boolean set_highgprs_p = FALSE; | |
52 | ||
b34976b6 | 53 | /* Whether to use user friendly register names. Default is TRUE. */ |
a85d7ed0 | 54 | #ifndef TARGET_REG_NAMES_P |
b34976b6 | 55 | #define TARGET_REG_NAMES_P TRUE |
a85d7ed0 NC |
56 | #endif |
57 | ||
b34976b6 | 58 | static bfd_boolean reg_names_p = TARGET_REG_NAMES_P; |
a85d7ed0 | 59 | |
16a419ba | 60 | /* Set to TRUE if we want to warn about zero base/index registers. */ |
b34976b6 | 61 | static bfd_boolean 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 | ||
b34976b6 | 159 | static bfd_boolean |
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 | |
b34976b6 | 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; | |
b34976b6 | 189 | return TRUE; |
a85d7ed0 | 190 | } |
468cced8 AM |
191 | |
192 | /* Reset the line as if we had not done anything. */ | |
193 | input_line_pointer = start; | |
b34976b6 | 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 | |
17b9d67d | 267 | s390_parse_cpu (const char * arg, |
7ecc513a DV |
268 | unsigned int * ret_flags, |
269 | bfd_boolean 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 AK |
295 | S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX }, |
296 | { STRING_COMMA_LEN (""), STRING_COMMA_LEN ("arch14"), | |
2253c8f0 | 297 | S390_INSTR_FLAG_HTM | S390_INSTR_FLAG_VX } |
7ecc513a DV |
298 | }; |
299 | static struct | |
300 | { | |
301 | const char * name; | |
302 | unsigned int mask; | |
303 | bfd_boolean on; | |
304 | } cpu_flags[] = | |
305 | { | |
306 | { "htm", S390_INSTR_FLAG_HTM, TRUE }, | |
307 | { "nohtm", S390_INSTR_FLAG_HTM, FALSE }, | |
308 | { "vx", S390_INSTR_FLAG_VX, TRUE }, | |
2253c8f0 | 309 | { "novx", S390_INSTR_FLAG_VX, FALSE } |
7ecc513a DV |
310 | }; |
311 | unsigned int icpu; | |
312 | char *ilp_bak; | |
313 | ||
314 | icpu = S390_OPCODE_MAXCPU; | |
315 | if (strncmp (arg, "all", 3) == 0 && (arg[3] == 0 || arg[3] == '+')) | |
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) | |
b34976b6 | 406 | reg_names_p = TRUE; |
198ce79b | 407 | |
07855bec | 408 | else if (arg != NULL && strcmp (arg, "no-regnames") == 0) |
b34976b6 | 409 | reg_names_p = FALSE; |
198ce79b | 410 | |
16a419ba NC |
411 | else if (arg != NULL && strcmp (arg, "warn-areg-zero") == 0) |
412 | warn_areg_zero = TRUE; | |
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) | |
426 | set_highgprs_p = TRUE; | |
427 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
428 | } | |
37a58793 MS |
429 | |
430 | else if (arg != NULL && strncmp (arg, "arch=", 5) == 0) | |
431 | { | |
7ecc513a DV |
432 | current_cpu = s390_parse_cpu (arg + 5, ¤t_flags, FALSE); |
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; |
b34976b6 | 498 | bfd_boolean 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); | |
539 | dup_insn = TRUE; | |
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 | |
5a49b8ac | 587 | s390_md_end (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 = | |
20203fb9 | 620 | _("operand out of range (%s not between %ld and %ld)"); |
07855bec NC |
621 | char buf[100]; |
622 | ||
623 | if (operand->flags & S390_OPERAND_PCREL) | |
624 | { | |
625 | val <<= 1; | |
626 | min <<= 1; | |
627 | max <<= 1; | |
628 | } | |
629 | sprint_value (buf, val); | |
630 | if (file == (char *) NULL) | |
631 | as_bad (err, buf, (int) min, (int) max); | |
632 | else | |
633 | as_bad_where (file, line, err, buf, (int) min, (int) max); | |
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 | ||
702 | /* Duplicate the operand at bit pos 12 to 16. */ | |
703 | if (operand->flags & S390_OPERAND_CP16) | |
704 | { | |
705 | /* Copy VR operand at bit pos 12 to bit pos 16. */ | |
706 | insn[2] |= uval << 4; | |
707 | /* Copy the flag in the RXB field. */ | |
708 | insn[4] |= (insn[4] & 4) >> 1; | |
709 | } | |
710 | ||
a85d7ed0 NC |
711 | /* Insert fragments of the operand byte for byte. */ |
712 | offset = operand->shift + operand->bits; | |
713 | uval <<= (-offset) & 7; | |
98d3f06f | 714 | insn += (offset - 1) / 8; |
07855bec NC |
715 | while (uval != 0) |
716 | { | |
717 | *insn-- |= uval; | |
718 | uval >>= 8; | |
719 | } | |
a85d7ed0 NC |
720 | } |
721 | ||
1971b29d MS |
722 | struct map_tls |
723 | { | |
f86f5863 | 724 | const char *string; |
1971b29d MS |
725 | int length; |
726 | bfd_reloc_code_real_type reloc; | |
727 | }; | |
728 | ||
1971b29d MS |
729 | /* Parse tls marker and return the desired relocation. */ |
730 | static bfd_reloc_code_real_type | |
5a49b8ac | 731 | s390_tls_suffix (char **str_p, expressionS *exp_p) |
1971b29d MS |
732 | { |
733 | static struct map_tls mapping[] = | |
734 | { | |
735 | { "tls_load", 8, BFD_RELOC_390_TLS_LOAD }, | |
736 | { "tls_gdcall", 10, BFD_RELOC_390_TLS_GDCALL }, | |
737 | { "tls_ldcall", 10, BFD_RELOC_390_TLS_LDCALL }, | |
738 | { NULL, 0, BFD_RELOC_UNUSED } | |
739 | }; | |
740 | struct map_tls *ptr; | |
741 | char *orig_line; | |
742 | char *str; | |
743 | char *ident; | |
744 | int len; | |
745 | ||
746 | str = *str_p; | |
747 | if (*str++ != ':') | |
748 | return BFD_RELOC_UNUSED; | |
749 | ||
750 | ident = str; | |
751 | while (ISIDNUM (*str)) | |
752 | str++; | |
753 | len = str - ident; | |
754 | if (*str++ != ':') | |
755 | return BFD_RELOC_UNUSED; | |
756 | ||
757 | orig_line = input_line_pointer; | |
758 | input_line_pointer = str; | |
759 | expression (exp_p); | |
760 | str = input_line_pointer; | |
761 | if (&input_line_pointer != str_p) | |
762 | input_line_pointer = orig_line; | |
763 | ||
764 | if (exp_p->X_op != O_symbol) | |
765 | return BFD_RELOC_UNUSED; | |
766 | ||
767 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
768 | if (len == ptr->length | |
769 | && strncasecmp (ident, ptr->string, ptr->length) == 0) | |
770 | { | |
771 | /* Found a matching tls suffix. */ | |
772 | *str_p = str; | |
773 | return ptr->reloc; | |
774 | } | |
775 | return BFD_RELOC_UNUSED; | |
776 | } | |
777 | ||
a85d7ed0 | 778 | /* Structure used to hold suffixes. */ |
07855bec NC |
779 | typedef enum |
780 | { | |
781 | ELF_SUFFIX_NONE = 0, | |
782 | ELF_SUFFIX_GOT, | |
783 | ELF_SUFFIX_PLT, | |
2a19f73f MS |
784 | ELF_SUFFIX_GOTENT, |
785 | ELF_SUFFIX_GOTOFF, | |
786 | ELF_SUFFIX_GOTPLT, | |
1971b29d MS |
787 | ELF_SUFFIX_PLTOFF, |
788 | ELF_SUFFIX_TLS_GD, | |
789 | ELF_SUFFIX_TLS_GOTIE, | |
790 | ELF_SUFFIX_TLS_IE, | |
791 | ELF_SUFFIX_TLS_LDM, | |
792 | ELF_SUFFIX_TLS_LDO, | |
793 | ELF_SUFFIX_TLS_LE | |
07855bec NC |
794 | } |
795 | elf_suffix_type; | |
796 | ||
797 | struct map_bfd | |
798 | { | |
f86f5863 | 799 | const char *string; |
07855bec NC |
800 | int length; |
801 | elf_suffix_type suffix; | |
802 | }; | |
a85d7ed0 | 803 | |
9d654c1c | 804 | |
a85d7ed0 NC |
805 | /* Parse @got/@plt/@gotoff. and return the desired relocation. */ |
806 | static elf_suffix_type | |
5a49b8ac | 807 | s390_elf_suffix (char **str_p, expressionS *exp_p) |
a85d7ed0 | 808 | { |
07855bec NC |
809 | static struct map_bfd mapping[] = |
810 | { | |
a85d7ed0 NC |
811 | { "got", 3, ELF_SUFFIX_GOT }, |
812 | { "got12", 5, ELF_SUFFIX_GOT }, | |
813 | { "plt", 3, ELF_SUFFIX_PLT }, | |
814 | { "gotent", 6, ELF_SUFFIX_GOTENT }, | |
2a19f73f MS |
815 | { "gotoff", 6, ELF_SUFFIX_GOTOFF }, |
816 | { "gotplt", 6, ELF_SUFFIX_GOTPLT }, | |
817 | { "pltoff", 6, ELF_SUFFIX_PLTOFF }, | |
1971b29d MS |
818 | { "tlsgd", 5, ELF_SUFFIX_TLS_GD }, |
819 | { "gotntpoff", 9, ELF_SUFFIX_TLS_GOTIE }, | |
820 | { "indntpoff", 9, ELF_SUFFIX_TLS_IE }, | |
821 | { "tlsldm", 6, ELF_SUFFIX_TLS_LDM }, | |
822 | { "dtpoff", 6, ELF_SUFFIX_TLS_LDO }, | |
823 | { "ntpoff", 6, ELF_SUFFIX_TLS_LE }, | |
a85d7ed0 NC |
824 | { NULL, 0, ELF_SUFFIX_NONE } |
825 | }; | |
826 | ||
827 | struct map_bfd *ptr; | |
828 | char *str = *str_p; | |
829 | char *ident; | |
830 | int len; | |
831 | ||
832 | if (*str++ != '@') | |
833 | return ELF_SUFFIX_NONE; | |
834 | ||
835 | ident = str; | |
3882b010 | 836 | while (ISALNUM (*str)) |
a85d7ed0 NC |
837 | str++; |
838 | len = str - ident; | |
839 | ||
840 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
16a419ba NC |
841 | if (len == ptr->length |
842 | && strncasecmp (ident, ptr->string, ptr->length) == 0) | |
07855bec NC |
843 | { |
844 | if (exp_p->X_add_number != 0) | |
845 | as_warn (_("identifier+constant@%s means identifier@%s+constant"), | |
846 | ptr->string, ptr->string); | |
847 | /* Now check for identifier@suffix+constant. */ | |
848 | if (*str == '-' || *str == '+') | |
849 | { | |
850 | char *orig_line = input_line_pointer; | |
851 | expressionS new_exp; | |
852 | ||
853 | input_line_pointer = str; | |
854 | expression (&new_exp); | |
855 | ||
856 | switch (new_exp.X_op) | |
857 | { | |
858 | case O_constant: /* X_add_number (a constant expression). */ | |
859 | exp_p->X_add_number += new_exp.X_add_number; | |
860 | str = input_line_pointer; | |
861 | break; | |
862 | case O_symbol: /* X_add_symbol + X_add_number. */ | |
863 | /* this case is used for e.g. xyz@PLT+.Label. */ | |
864 | exp_p->X_add_number += new_exp.X_add_number; | |
865 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
866 | exp_p->X_op = O_add; | |
867 | str = input_line_pointer; | |
868 | break; | |
869 | case O_uminus: /* (- X_add_symbol) + X_add_number. */ | |
870 | /* this case is used for e.g. xyz@PLT-.Label. */ | |
871 | exp_p->X_add_number += new_exp.X_add_number; | |
872 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
873 | exp_p->X_op = O_subtract; | |
874 | str = input_line_pointer; | |
875 | break; | |
876 | default: | |
877 | break; | |
878 | } | |
879 | ||
880 | /* If s390_elf_suffix has not been called with | |
881 | &input_line_pointer as first parameter, we have | |
882 | clobbered the input_line_pointer. We have to | |
883 | undo that. */ | |
884 | if (&input_line_pointer != str_p) | |
885 | input_line_pointer = orig_line; | |
a85d7ed0 | 886 | } |
07855bec NC |
887 | *str_p = str; |
888 | return ptr->suffix; | |
a85d7ed0 | 889 | } |
a85d7ed0 | 890 | |
d26cc8a9 | 891 | return ELF_SUFFIX_NONE; |
a85d7ed0 NC |
892 | } |
893 | ||
894 | /* Structure used to hold a literal pool entry. */ | |
07855bec NC |
895 | struct s390_lpe |
896 | { | |
897 | struct s390_lpe *next; | |
898 | expressionS ex; | |
899 | FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */ | |
900 | LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */ | |
901 | int nbytes; | |
902 | bfd_reloc_code_real_type reloc; | |
903 | symbolS *sym; | |
904 | }; | |
a85d7ed0 NC |
905 | |
906 | static struct s390_lpe *lpe_free_list = NULL; | |
907 | static struct s390_lpe *lpe_list = NULL; | |
908 | static struct s390_lpe *lpe_list_tail = NULL; | |
909 | static symbolS *lp_sym = NULL; | |
910 | static int lp_count = 0; | |
911 | static int lpe_count = 0; | |
912 | ||
913 | static int | |
5a49b8ac | 914 | s390_exp_compare (expressionS *exp1, expressionS *exp2) |
a85d7ed0 NC |
915 | { |
916 | if (exp1->X_op != exp2->X_op) | |
917 | return 0; | |
918 | ||
07855bec NC |
919 | switch (exp1->X_op) |
920 | { | |
921 | case O_constant: /* X_add_number must be equal. */ | |
922 | case O_register: | |
923 | return exp1->X_add_number == exp2->X_add_number; | |
924 | ||
925 | case O_big: | |
198ce79b | 926 | as_bad (_("Can't handle O_big in s390_exp_compare")); |
2b804145 | 927 | return 0; |
07855bec NC |
928 | |
929 | case O_symbol: /* X_add_symbol & X_add_number must be equal. */ | |
930 | case O_symbol_rva: | |
931 | case O_uminus: | |
932 | case O_bit_not: | |
933 | case O_logical_not: | |
16a419ba NC |
934 | return (exp1->X_add_symbol == exp2->X_add_symbol) |
935 | && (exp1->X_add_number == exp2->X_add_number); | |
07855bec NC |
936 | |
937 | case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */ | |
938 | case O_divide: | |
939 | case O_modulus: | |
940 | case O_left_shift: | |
941 | case O_right_shift: | |
942 | case O_bit_inclusive_or: | |
943 | case O_bit_or_not: | |
944 | case O_bit_exclusive_or: | |
945 | case O_bit_and: | |
946 | case O_add: | |
947 | case O_subtract: | |
948 | case O_eq: | |
949 | case O_ne: | |
950 | case O_lt: | |
951 | case O_le: | |
952 | case O_ge: | |
953 | case O_gt: | |
954 | case O_logical_and: | |
955 | case O_logical_or: | |
16a419ba NC |
956 | return (exp1->X_add_symbol == exp2->X_add_symbol) |
957 | && (exp1->X_op_symbol == exp2->X_op_symbol) | |
958 | && (exp1->X_add_number == exp2->X_add_number); | |
07855bec | 959 | default: |
98d3f06f KH |
960 | return 0; |
961 | } | |
a85d7ed0 NC |
962 | } |
963 | ||
33eaf5de | 964 | /* Test for @lit and if it's present make an entry in the literal pool and |
a85d7ed0 NC |
965 | modify the current expression to be an offset into the literal pool. */ |
966 | static elf_suffix_type | |
5a49b8ac | 967 | s390_lit_suffix (char **str_p, expressionS *exp_p, elf_suffix_type suffix) |
a85d7ed0 NC |
968 | { |
969 | bfd_reloc_code_real_type reloc; | |
970 | char tmp_name[64]; | |
971 | char *str = *str_p; | |
972 | char *ident; | |
973 | struct s390_lpe *lpe; | |
974 | int nbytes, len; | |
975 | ||
976 | if (*str++ != ':') | |
977 | return suffix; /* No modification. */ | |
198ce79b | 978 | |
a85d7ed0 NC |
979 | /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */ |
980 | ident = str; | |
3882b010 | 981 | while (ISALNUM (*str)) |
a85d7ed0 NC |
982 | str++; |
983 | len = str - ident; | |
16a419ba NC |
984 | if (len != 4 || strncasecmp (ident, "lit", 3) != 0 |
985 | || (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8')) | |
a85d7ed0 NC |
986 | return suffix; /* no modification */ |
987 | nbytes = ident[3] - '0'; | |
988 | ||
989 | reloc = BFD_RELOC_UNUSED; | |
07855bec NC |
990 | if (suffix == ELF_SUFFIX_GOT) |
991 | { | |
992 | if (nbytes == 2) | |
993 | reloc = BFD_RELOC_390_GOT16; | |
994 | else if (nbytes == 4) | |
995 | reloc = BFD_RELOC_32_GOT_PCREL; | |
996 | else if (nbytes == 8) | |
997 | reloc = BFD_RELOC_390_GOT64; | |
998 | } | |
999 | else if (suffix == ELF_SUFFIX_PLT) | |
1000 | { | |
1001 | if (nbytes == 4) | |
1002 | reloc = BFD_RELOC_390_PLT32; | |
1003 | else if (nbytes == 8) | |
1004 | reloc = BFD_RELOC_390_PLT64; | |
1005 | } | |
a85d7ed0 | 1006 | |
07855bec | 1007 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) |
a85d7ed0 | 1008 | as_bad (_("Invalid suffix for literal pool entry")); |
a85d7ed0 NC |
1009 | |
1010 | /* Search the pool if the new entry is a duplicate. */ | |
07855bec NC |
1011 | if (exp_p->X_op == O_big) |
1012 | { | |
1013 | /* Special processing for big numbers. */ | |
1014 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
1015 | { | |
1016 | if (lpe->ex.X_op == O_big) | |
1017 | { | |
1018 | if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0) | |
1019 | { | |
1020 | if (memcmp (&generic_floating_point_number, &lpe->floatnum, | |
1021 | sizeof (FLONUM_TYPE)) == 0) | |
1022 | break; | |
1023 | } | |
1024 | else if (exp_p->X_add_number == lpe->ex.X_add_number) | |
1025 | { | |
1026 | if (memcmp (generic_bignum, lpe->bignum, | |
1027 | sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0) | |
1028 | break; | |
1029 | } | |
1030 | } | |
1031 | } | |
a85d7ed0 | 1032 | } |
07855bec NC |
1033 | else |
1034 | { | |
1035 | /* Processing for 'normal' data types. */ | |
1036 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
16a419ba | 1037 | if (lpe->nbytes == nbytes && lpe->reloc == reloc |
98d3f06f | 1038 | && s390_exp_compare (exp_p, &lpe->ex) != 0) |
07855bec | 1039 | break; |
a85d7ed0 | 1040 | } |
07855bec NC |
1041 | |
1042 | if (lpe == NULL) | |
1043 | { | |
1044 | /* A new literal. */ | |
1045 | if (lpe_free_list != NULL) | |
1046 | { | |
1047 | lpe = lpe_free_list; | |
1048 | lpe_free_list = lpe_free_list->next; | |
1049 | } | |
a85d7ed0 | 1050 | else |
07855bec | 1051 | { |
325801bd | 1052 | lpe = XNEW (struct s390_lpe); |
07855bec NC |
1053 | } |
1054 | ||
1055 | lpe->ex = *exp_p; | |
1056 | ||
1057 | if (exp_p->X_op == O_big) | |
1058 | { | |
1059 | if (exp_p->X_add_number <= 0) | |
1060 | lpe->floatnum = generic_floating_point_number; | |
1061 | else if (exp_p->X_add_number <= 4) | |
1062 | memcpy (lpe->bignum, generic_bignum, | |
98d3f06f | 1063 | exp_p->X_add_number * sizeof (LITTLENUM_TYPE)); |
07855bec NC |
1064 | else |
1065 | as_bad (_("Big number is too big")); | |
1066 | } | |
1067 | ||
1068 | lpe->nbytes = nbytes; | |
1069 | lpe->reloc = reloc; | |
1070 | /* Literal pool name defined ? */ | |
1071 | if (lp_sym == NULL) | |
1072 | { | |
07726851 | 1073 | sprintf (tmp_name, ".L\001%i", lp_count); |
98d3f06f | 1074 | lp_sym = symbol_make (tmp_name); |
07855bec | 1075 | } |
a85d7ed0 | 1076 | |
07855bec | 1077 | /* Make name for literal pool entry. */ |
07726851 | 1078 | sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count); |
07855bec | 1079 | lpe_count++; |
98d3f06f | 1080 | lpe->sym = symbol_make (tmp_name); |
07855bec NC |
1081 | |
1082 | /* Add to literal pool list. */ | |
1083 | lpe->next = NULL; | |
1084 | if (lpe_list_tail != NULL) | |
1085 | { | |
1086 | lpe_list_tail->next = lpe; | |
1087 | lpe_list_tail = lpe; | |
1088 | } | |
1089 | else | |
1090 | lpe_list = lpe_list_tail = lpe; | |
1091 | } | |
198ce79b | 1092 | |
a85d7ed0 | 1093 | /* Now change exp_p to the offset into the literal pool. |
33eaf5de | 1094 | That's the expression: .L^Ax^By-.L^Ax */ |
a85d7ed0 NC |
1095 | exp_p->X_add_symbol = lpe->sym; |
1096 | exp_p->X_op_symbol = lp_sym; | |
1097 | exp_p->X_op = O_subtract; | |
1098 | exp_p->X_add_number = 0; | |
1099 | ||
1100 | *str_p = str; | |
1101 | ||
1102 | /* We change the suffix type to ELF_SUFFIX_NONE, because | |
1103 | the difference of two local labels is just a number. */ | |
1104 | return ELF_SUFFIX_NONE; | |
1105 | } | |
1106 | ||
1107 | /* Like normal .long/.short/.word, except support @got, etc. | |
1108 | clobbers input_line_pointer, checks end-of-line. */ | |
1109 | static void | |
5a49b8ac | 1110 | s390_elf_cons (int nbytes /* 1=.byte, 2=.word, 4=.long */) |
a85d7ed0 NC |
1111 | { |
1112 | expressionS exp; | |
1113 | elf_suffix_type suffix; | |
1114 | ||
07855bec NC |
1115 | if (is_it_end_of_statement ()) |
1116 | { | |
1117 | demand_empty_rest_of_line (); | |
1118 | return; | |
1119 | } | |
a85d7ed0 | 1120 | |
07855bec NC |
1121 | do |
1122 | { | |
1123 | expression (&exp); | |
1124 | ||
1125 | if (exp.X_op == O_symbol | |
1126 | && *input_line_pointer == '@' | |
1127 | && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE) | |
1128 | { | |
1129 | bfd_reloc_code_real_type reloc; | |
1130 | reloc_howto_type *reloc_howto; | |
1131 | int size; | |
1132 | char *where; | |
1133 | ||
1971b29d MS |
1134 | if (nbytes == 2) |
1135 | { | |
1136 | static bfd_reloc_code_real_type tab2[] = | |
1137 | { | |
5cfbfc2b MS |
1138 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1139 | BFD_RELOC_390_GOT16, /* ELF_SUFFIX_GOT */ | |
1140 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_PLT */ | |
1141 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1142 | BFD_RELOC_16_GOTOFF, /* ELF_SUFFIX_GOTOFF */ | |
1143 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTPLT */ | |
1144 | BFD_RELOC_390_PLTOFF16, /* ELF_SUFFIX_PLTOFF */ | |
1145 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GD */ | |
1146 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_GOTIE */ | |
1147 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_IE */ | |
1148 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDM */ | |
1149 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_TLS_LDO */ | |
1150 | BFD_RELOC_UNUSED /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1151 | }; |
1152 | reloc = tab2[suffix]; | |
1153 | } | |
1154 | else if (nbytes == 4) | |
1155 | { | |
1156 | static bfd_reloc_code_real_type tab4[] = | |
1157 | { | |
5cfbfc2b MS |
1158 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1159 | BFD_RELOC_32_GOT_PCREL, /* ELF_SUFFIX_GOT */ | |
1160 | BFD_RELOC_390_PLT32, /* ELF_SUFFIX_PLT */ | |
1161 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1162 | BFD_RELOC_32_GOTOFF, /* ELF_SUFFIX_GOTOFF */ | |
1163 | BFD_RELOC_390_GOTPLT32, /* ELF_SUFFIX_GOTPLT */ | |
1164 | BFD_RELOC_390_PLTOFF32, /* ELF_SUFFIX_PLTOFF */ | |
1165 | BFD_RELOC_390_TLS_GD32, /* ELF_SUFFIX_TLS_GD */ | |
1166 | BFD_RELOC_390_TLS_GOTIE32, /* ELF_SUFFIX_TLS_GOTIE */ | |
1167 | BFD_RELOC_390_TLS_IE32, /* ELF_SUFFIX_TLS_IE */ | |
1168 | BFD_RELOC_390_TLS_LDM32, /* ELF_SUFFIX_TLS_LDM */ | |
1169 | BFD_RELOC_390_TLS_LDO32, /* ELF_SUFFIX_TLS_LDO */ | |
1170 | BFD_RELOC_390_TLS_LE32 /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1171 | }; |
1172 | reloc = tab4[suffix]; | |
1173 | } | |
1174 | else if (nbytes == 8) | |
1175 | { | |
1176 | static bfd_reloc_code_real_type tab8[] = | |
1177 | { | |
5cfbfc2b MS |
1178 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_NONE */ |
1179 | BFD_RELOC_390_GOT64, /* ELF_SUFFIX_GOT */ | |
1180 | BFD_RELOC_390_PLT64, /* ELF_SUFFIX_PLT */ | |
1181 | BFD_RELOC_UNUSED, /* ELF_SUFFIX_GOTENT */ | |
1182 | BFD_RELOC_390_GOTOFF64, /* ELF_SUFFIX_GOTOFF */ | |
1183 | BFD_RELOC_390_GOTPLT64, /* ELF_SUFFIX_GOTPLT */ | |
1184 | BFD_RELOC_390_PLTOFF64, /* ELF_SUFFIX_PLTOFF */ | |
1185 | BFD_RELOC_390_TLS_GD64, /* ELF_SUFFIX_TLS_GD */ | |
1186 | BFD_RELOC_390_TLS_GOTIE64, /* ELF_SUFFIX_TLS_GOTIE */ | |
1187 | BFD_RELOC_390_TLS_IE64, /* ELF_SUFFIX_TLS_IE */ | |
1188 | BFD_RELOC_390_TLS_LDM64, /* ELF_SUFFIX_TLS_LDM */ | |
1189 | BFD_RELOC_390_TLS_LDO64, /* ELF_SUFFIX_TLS_LDO */ | |
1190 | BFD_RELOC_390_TLS_LE64 /* ELF_SUFFIX_TLS_LE */ | |
1971b29d MS |
1191 | }; |
1192 | reloc = tab8[suffix]; | |
1193 | } | |
07855bec NC |
1194 | else |
1195 | reloc = BFD_RELOC_UNUSED; | |
1196 | ||
1971b29d MS |
1197 | if (reloc != BFD_RELOC_UNUSED |
1198 | && (reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc))) | |
07855bec | 1199 | { |
07855bec NC |
1200 | size = bfd_get_reloc_size (reloc_howto); |
1201 | if (size > nbytes) | |
992a06ee AM |
1202 | as_bad (ngettext ("%s relocations do not fit in %d byte", |
1203 | "%s relocations do not fit in %d bytes", | |
1204 | nbytes), | |
07855bec | 1205 | reloc_howto->name, nbytes); |
07726851 | 1206 | where = frag_more (nbytes); |
07855bec | 1207 | md_number_to_chars (where, 0, size); |
198ce79b | 1208 | /* To make fixup_segment do the pc relative conversion the |
b34976b6 | 1209 | pcrel parameter on the fix_new_exp call needs to be FALSE. */ |
198ce79b | 1210 | fix_new_exp (frag_now, where - frag_now->fr_literal, |
b34976b6 | 1211 | size, &exp, FALSE, reloc); |
07855bec NC |
1212 | } |
1213 | else | |
1214 | as_bad (_("relocation not applicable")); | |
1215 | } | |
a85d7ed0 | 1216 | else |
07855bec NC |
1217 | emit_expr (&exp, (unsigned int) nbytes); |
1218 | } | |
1219 | while (*input_line_pointer++ == ','); | |
a85d7ed0 | 1220 | |
98d3f06f | 1221 | input_line_pointer--; /* Put terminator back into stream. */ |
a85d7ed0 NC |
1222 | demand_empty_rest_of_line (); |
1223 | } | |
1224 | ||
13daa8e4 AK |
1225 | /* Return true if all remaining operands in the opcode with |
1226 | OPCODE_FLAGS can be skipped. */ | |
1227 | static bfd_boolean | |
1228 | skip_optargs_p (unsigned int opcode_flags, const unsigned char *opindex_ptr) | |
1229 | { | |
1230 | if ((opcode_flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2)) | |
1231 | && opindex_ptr[0] != '\0' | |
1232 | && opindex_ptr[1] == '\0') | |
1233 | return TRUE; | |
1234 | ||
1235 | if ((opcode_flags & S390_INSTR_FLAG_OPTPARM2) | |
1236 | && opindex_ptr[0] != '\0' | |
1237 | && opindex_ptr[1] != '\0' | |
1238 | && opindex_ptr[2] == '\0') | |
1239 | return TRUE; | |
1240 | return FALSE; | |
1241 | } | |
1242 | ||
a85d7ed0 NC |
1243 | /* We need to keep a list of fixups. We can't simply generate them as |
1244 | we go, because that would require us to first create the frag, and | |
1245 | that would screw up references to ``.''. */ | |
1246 | ||
1247 | struct s390_fixup | |
07855bec NC |
1248 | { |
1249 | expressionS exp; | |
1250 | int opindex; | |
1251 | bfd_reloc_code_real_type reloc; | |
1252 | }; | |
a85d7ed0 NC |
1253 | |
1254 | #define MAX_INSN_FIXUPS (4) | |
1255 | ||
1256 | /* This routine is called for each instruction to be assembled. */ | |
1257 | ||
9d654c1c | 1258 | static char * |
5a49b8ac AM |
1259 | md_gather_operands (char *str, |
1260 | unsigned char *insn, | |
1261 | const struct s390_opcode *opcode) | |
a85d7ed0 NC |
1262 | { |
1263 | struct s390_fixup fixups[MAX_INSN_FIXUPS]; | |
1264 | const struct s390_operand *operand; | |
1265 | const unsigned char *opindex_ptr; | |
1971b29d | 1266 | expressionS ex; |
a85d7ed0 NC |
1267 | elf_suffix_type suffix; |
1268 | bfd_reloc_code_real_type reloc; | |
1269 | int skip_optional; | |
a85d7ed0 NC |
1270 | char *f; |
1271 | int fc, i; | |
1272 | ||
98d3f06f KH |
1273 | while (ISSPACE (*str)) |
1274 | str++; | |
a85d7ed0 | 1275 | |
a85d7ed0 NC |
1276 | skip_optional = 0; |
1277 | ||
1278 | /* Gather the operands. */ | |
1279 | fc = 0; | |
07855bec NC |
1280 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) |
1281 | { | |
07855bec NC |
1282 | char *hold; |
1283 | ||
1284 | operand = s390_operands + *opindex_ptr; | |
198ce79b | 1285 | |
a09f2586 AK |
1286 | if ((opcode->flags & (S390_INSTR_FLAG_OPTPARM | S390_INSTR_FLAG_OPTPARM2)) |
1287 | && *str == '\0') | |
1e2e8c52 AK |
1288 | { |
1289 | /* Optional parameters might need to be ORed with a | |
1290 | value so calling s390_insert_operand is needed. */ | |
1291 | s390_insert_operand (insn, operand, 0, NULL, 0); | |
1292 | break; | |
1293 | } | |
1294 | ||
07855bec NC |
1295 | if (skip_optional && (operand->flags & S390_OPERAND_INDEX)) |
1296 | { | |
1297 | /* We do an early skip. For D(X,B) constructions the index | |
198ce79b | 1298 | register is skipped (X is optional). For D(L,B) the base |
07855bec NC |
1299 | register will be the skipped operand, because L is NOT |
1300 | optional. */ | |
1301 | skip_optional = 0; | |
1302 | continue; | |
1303 | } | |
198ce79b | 1304 | |
07855bec NC |
1305 | /* Gather the operand. */ |
1306 | hold = input_line_pointer; | |
1307 | input_line_pointer = str; | |
1308 | ||
98d3f06f KH |
1309 | /* Parse the operand. */ |
1310 | if (! register_name (&ex)) | |
07855bec | 1311 | expression (&ex); |
198ce79b | 1312 | |
07855bec NC |
1313 | str = input_line_pointer; |
1314 | input_line_pointer = hold; | |
198ce79b | 1315 | |
07855bec NC |
1316 | /* Write the operand to the insn. */ |
1317 | if (ex.X_op == O_illegal) | |
1318 | as_bad (_("illegal operand")); | |
1319 | else if (ex.X_op == O_absent) | |
5e7c27a6 | 1320 | { |
5e7c27a6 MS |
1321 | if (opindex_ptr[0] == '\0') |
1322 | break; | |
1323 | as_bad (_("missing operand")); | |
1324 | } | |
07855bec NC |
1325 | else if (ex.X_op == O_register || ex.X_op == O_constant) |
1326 | { | |
1327 | s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE); | |
1328 | ||
1329 | if (ex.X_op != O_register && ex.X_op != O_constant) | |
1330 | { | |
1331 | /* We need to generate a fixup for the | |
1332 | expression returned by s390_lit_suffix. */ | |
1333 | if (fc >= MAX_INSN_FIXUPS) | |
1334 | as_fatal (_("too many fixups")); | |
1335 | fixups[fc].exp = ex; | |
1336 | fixups[fc].opindex = *opindex_ptr; | |
1337 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
1338 | ++fc; | |
1339 | } | |
1340 | else | |
1341 | { | |
c6837265 AK |
1342 | if ((operand->flags & S390_OPERAND_LENGTH) |
1343 | && ex.X_op != O_constant) | |
1344 | as_fatal (_("invalid length field specified")); | |
16a419ba NC |
1345 | if ((operand->flags & S390_OPERAND_INDEX) |
1346 | && ex.X_add_number == 0 | |
b34976b6 | 1347 | && warn_areg_zero) |
20203fb9 | 1348 | as_warn (_("index register specified but zero")); |
16a419ba NC |
1349 | if ((operand->flags & S390_OPERAND_BASE) |
1350 | && ex.X_add_number == 0 | |
b34976b6 | 1351 | && warn_areg_zero) |
20203fb9 | 1352 | as_warn (_("base register specified but zero")); |
c8fa16ed AK |
1353 | if ((operand->flags & S390_OPERAND_GPR) |
1354 | && (operand->flags & S390_OPERAND_REG_PAIR) | |
5e4b319c | 1355 | && (ex.X_add_number & 1)) |
c8fa16ed AK |
1356 | as_fatal (_("odd numbered general purpose register specified as " |
1357 | "register pair")); | |
1358 | if ((operand->flags & S390_OPERAND_FPR) | |
1359 | && (operand->flags & S390_OPERAND_REG_PAIR) | |
1360 | && ex.X_add_number != 0 && ex.X_add_number != 1 | |
1361 | && ex.X_add_number != 4 && ex.X_add_number != 5 | |
1362 | && ex.X_add_number != 8 && ex.X_add_number != 9 | |
1363 | && ex.X_add_number != 12 && ex.X_add_number != 13) | |
1364 | as_fatal (_("invalid floating point register pair. Valid fp " | |
1365 | "register pair operands are 0, 1, 4, 5, 8, 9, " | |
1366 | "12 or 13.")); | |
07855bec NC |
1367 | s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0); |
1368 | } | |
1369 | } | |
1370 | else | |
1371 | { | |
1372 | suffix = s390_elf_suffix (&str, &ex); | |
1373 | suffix = s390_lit_suffix (&str, &ex, suffix); | |
1374 | reloc = BFD_RELOC_UNUSED; | |
1375 | ||
1376 | if (suffix == ELF_SUFFIX_GOT) | |
1377 | { | |
933fbc29 MS |
1378 | if ((operand->flags & S390_OPERAND_DISP) && |
1379 | (operand->bits == 12)) | |
07855bec | 1380 | reloc = BFD_RELOC_390_GOT12; |
933fbc29 MS |
1381 | else if ((operand->flags & S390_OPERAND_DISP) && |
1382 | (operand->bits == 20)) | |
1383 | reloc = BFD_RELOC_390_GOT20; | |
16a419ba NC |
1384 | else if ((operand->flags & S390_OPERAND_SIGNED) |
1385 | && (operand->bits == 16)) | |
07855bec | 1386 | reloc = BFD_RELOC_390_GOT16; |
16a419ba NC |
1387 | else if ((operand->flags & S390_OPERAND_PCREL) |
1388 | && (operand->bits == 32)) | |
07855bec NC |
1389 | reloc = BFD_RELOC_390_GOTENT; |
1390 | } | |
1391 | else if (suffix == ELF_SUFFIX_PLT) | |
1392 | { | |
16a419ba | 1393 | if ((operand->flags & S390_OPERAND_PCREL) |
fb798c50 AK |
1394 | && (operand->bits == 12)) |
1395 | reloc = BFD_RELOC_390_PLT12DBL; | |
1396 | else if ((operand->flags & S390_OPERAND_PCREL) | |
1397 | && (operand->bits == 16)) | |
07855bec | 1398 | reloc = BFD_RELOC_390_PLT16DBL; |
fb798c50 AK |
1399 | else if ((operand->flags & S390_OPERAND_PCREL) |
1400 | && (operand->bits == 24)) | |
1401 | reloc = BFD_RELOC_390_PLT24DBL; | |
16a419ba NC |
1402 | else if ((operand->flags & S390_OPERAND_PCREL) |
1403 | && (operand->bits == 32)) | |
07855bec NC |
1404 | reloc = BFD_RELOC_390_PLT32DBL; |
1405 | } | |
1406 | else if (suffix == ELF_SUFFIX_GOTENT) | |
1407 | { | |
16a419ba NC |
1408 | if ((operand->flags & S390_OPERAND_PCREL) |
1409 | && (operand->bits == 32)) | |
07855bec NC |
1410 | reloc = BFD_RELOC_390_GOTENT; |
1411 | } | |
2a19f73f MS |
1412 | else if (suffix == ELF_SUFFIX_GOTOFF) |
1413 | { | |
1414 | if ((operand->flags & S390_OPERAND_SIGNED) | |
1415 | && (operand->bits == 16)) | |
1416 | reloc = BFD_RELOC_16_GOTOFF; | |
1417 | } | |
1418 | else if (suffix == ELF_SUFFIX_PLTOFF) | |
1419 | { | |
1420 | if ((operand->flags & S390_OPERAND_SIGNED) | |
1421 | && (operand->bits == 16)) | |
1422 | reloc = BFD_RELOC_390_PLTOFF16; | |
1423 | } | |
1424 | else if (suffix == ELF_SUFFIX_GOTPLT) | |
1425 | { | |
1426 | if ((operand->flags & S390_OPERAND_DISP) | |
1427 | && (operand->bits == 12)) | |
1428 | reloc = BFD_RELOC_390_GOTPLT12; | |
1429 | else if ((operand->flags & S390_OPERAND_SIGNED) | |
1430 | && (operand->bits == 16)) | |
1431 | reloc = BFD_RELOC_390_GOTPLT16; | |
1432 | else if ((operand->flags & S390_OPERAND_PCREL) | |
1433 | && (operand->bits == 32)) | |
1434 | reloc = BFD_RELOC_390_GOTPLTENT; | |
1435 | } | |
1971b29d MS |
1436 | else if (suffix == ELF_SUFFIX_TLS_GOTIE) |
1437 | { | |
1438 | if ((operand->flags & S390_OPERAND_DISP) | |
1439 | && (operand->bits == 12)) | |
1440 | reloc = BFD_RELOC_390_TLS_GOTIE12; | |
933fbc29 MS |
1441 | else if ((operand->flags & S390_OPERAND_DISP) |
1442 | && (operand->bits == 20)) | |
1443 | reloc = BFD_RELOC_390_TLS_GOTIE20; | |
1971b29d MS |
1444 | } |
1445 | else if (suffix == ELF_SUFFIX_TLS_IE) | |
1446 | { | |
1447 | if ((operand->flags & S390_OPERAND_PCREL) | |
1448 | && (operand->bits == 32)) | |
1449 | reloc = BFD_RELOC_390_TLS_IEENT; | |
1450 | } | |
07855bec NC |
1451 | |
1452 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) | |
1453 | as_bad (_("invalid operand suffix")); | |
1454 | /* We need to generate a fixup of type 'reloc' for this | |
1455 | expression. */ | |
a85d7ed0 NC |
1456 | if (fc >= MAX_INSN_FIXUPS) |
1457 | as_fatal (_("too many fixups")); | |
1458 | fixups[fc].exp = ex; | |
1459 | fixups[fc].opindex = *opindex_ptr; | |
07855bec | 1460 | fixups[fc].reloc = reloc; |
a85d7ed0 | 1461 | ++fc; |
07855bec | 1462 | } |
198ce79b | 1463 | |
07855bec NC |
1464 | /* Check the next character. The call to expression has advanced |
1465 | str past any whitespace. */ | |
1466 | if (operand->flags & S390_OPERAND_DISP) | |
1467 | { | |
1468 | /* After a displacement a block in parentheses can start. */ | |
1469 | if (*str != '(') | |
1470 | { | |
67c1ffbe | 1471 | /* Check if parenthesized block can be skipped. If the next |
33eaf5de | 1472 | operand is neither an optional operand nor a base register |
07855bec NC |
1473 | then we have a syntax error. */ |
1474 | operand = s390_operands + *(++opindex_ptr); | |
1475 | if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE))) | |
1476 | as_bad (_("syntax error; missing '(' after displacement")); | |
1477 | ||
1478 | /* Ok, skip all operands until S390_OPERAND_BASE. */ | |
1479 | while (!(operand->flags & S390_OPERAND_BASE)) | |
1480 | operand = s390_operands + *(++opindex_ptr); | |
198ce79b | 1481 | |
13daa8e4 AK |
1482 | if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) |
1483 | continue; | |
1484 | ||
67c1ffbe | 1485 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1486 | if (opindex_ptr[1] != '\0') |
1487 | { | |
6c639ef9 MS |
1488 | if (*str != ',') |
1489 | { | |
1490 | while (opindex_ptr[1] != '\0') | |
1491 | { | |
1492 | operand = s390_operands + *(++opindex_ptr); | |
33eaf5de | 1493 | as_bad (_("syntax error; expected ','")); |
6c639ef9 MS |
1494 | break; |
1495 | } | |
1496 | } | |
1497 | else | |
1498 | str++; | |
07855bec NC |
1499 | } |
1500 | } | |
1501 | else | |
1502 | { | |
1503 | /* We found an opening parentheses. */ | |
1504 | str++; | |
1505 | for (f = str; *f != '\0'; f++) | |
1506 | if (*f == ',' || *f == ')') | |
1507 | break; | |
1508 | /* If there is no comma until the closing parentheses OR | |
1509 | there is a comma right after the opening parentheses, | |
1510 | we have to skip optional operands. */ | |
1511 | if (*f == ',' && f == str) | |
1512 | { | |
1513 | /* comma directly after '(' ? */ | |
1514 | skip_optional = 1; | |
1515 | str++; | |
1516 | } | |
1517 | else | |
1518 | skip_optional = (*f != ','); | |
1519 | } | |
1520 | } | |
1521 | else if (operand->flags & S390_OPERAND_BASE) | |
1522 | { | |
33eaf5de | 1523 | /* After the base register the parenthesised block ends. */ |
07855bec NC |
1524 | if (*str++ != ')') |
1525 | as_bad (_("syntax error; missing ')' after base register")); | |
1526 | skip_optional = 0; | |
f47998d6 | 1527 | |
13daa8e4 | 1528 | if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) |
f47998d6 AK |
1529 | continue; |
1530 | ||
67c1ffbe | 1531 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1532 | if (opindex_ptr[1] != '\0') |
1533 | { | |
6c639ef9 MS |
1534 | if (*str != ',') |
1535 | { | |
1536 | while (opindex_ptr[1] != '\0') | |
1537 | { | |
1538 | operand = s390_operands + *(++opindex_ptr); | |
33eaf5de | 1539 | as_bad (_("syntax error; expected ','")); |
6c639ef9 MS |
1540 | break; |
1541 | } | |
1542 | } | |
1543 | else | |
1544 | str++; | |
07855bec NC |
1545 | } |
1546 | } | |
1547 | else | |
1548 | { | |
1549 | /* We can find an 'early' closing parentheses in e.g. D(L) instead | |
1550 | of D(L,B). In this case the base register has to be skipped. */ | |
1551 | if (*str == ')') | |
1552 | { | |
1553 | operand = s390_operands + *(++opindex_ptr); | |
1554 | ||
1555 | if (!(operand->flags & S390_OPERAND_BASE)) | |
1556 | as_bad (_("syntax error; ')' not allowed here")); | |
1557 | str++; | |
1558 | } | |
1e2e8c52 | 1559 | |
13daa8e4 | 1560 | if (*str == '\0' && skip_optargs_p (opcode->flags, &opindex_ptr[1])) |
1e2e8c52 AK |
1561 | continue; |
1562 | ||
67c1ffbe | 1563 | /* If there is a next operand it must be separated by a comma. */ |
07855bec NC |
1564 | if (opindex_ptr[1] != '\0') |
1565 | { | |
6c639ef9 MS |
1566 | if (*str != ',') |
1567 | { | |
1568 | while (opindex_ptr[1] != '\0') | |
1569 | { | |
1570 | operand = s390_operands + *(++opindex_ptr); | |
33eaf5de | 1571 | as_bad (_("syntax error; expected ','")); |
6c639ef9 MS |
1572 | break; |
1573 | } | |
1574 | } | |
1575 | else | |
1576 | str++; | |
07855bec | 1577 | } |
a85d7ed0 | 1578 | } |
a85d7ed0 | 1579 | } |
a85d7ed0 | 1580 | |
3882b010 | 1581 | while (ISSPACE (*str)) |
a85d7ed0 NC |
1582 | ++str; |
1583 | ||
1971b29d MS |
1584 | /* Check for tls instruction marker. */ |
1585 | reloc = s390_tls_suffix (&str, &ex); | |
1586 | if (reloc != BFD_RELOC_UNUSED) | |
1587 | { | |
1588 | /* We need to generate a fixup of type 'reloc' for this | |
1589 | instruction. */ | |
1590 | if (fc >= MAX_INSN_FIXUPS) | |
1591 | as_fatal (_("too many fixups")); | |
1592 | fixups[fc].exp = ex; | |
1593 | fixups[fc].opindex = -1; | |
1594 | fixups[fc].reloc = reloc; | |
1595 | ++fc; | |
1596 | } | |
1597 | ||
07855bec NC |
1598 | if (*str != '\0') |
1599 | { | |
1600 | char *linefeed; | |
a85d7ed0 | 1601 | |
07726851 | 1602 | if ((linefeed = strchr (str, '\n')) != NULL) |
07855bec NC |
1603 | *linefeed = '\0'; |
1604 | as_bad (_("junk at end of line: `%s'"), str); | |
1605 | if (linefeed != NULL) | |
1606 | *linefeed = '\n'; | |
1607 | } | |
a85d7ed0 NC |
1608 | |
1609 | /* Write out the instruction. */ | |
1610 | f = frag_more (opcode->oplen); | |
07855bec | 1611 | memcpy (f, insn, opcode->oplen); |
8f5b2891 | 1612 | dwarf2_emit_insn (opcode->oplen); |
a85d7ed0 NC |
1613 | |
1614 | /* Create any fixups. At this point we do not use a | |
1615 | bfd_reloc_code_real_type, but instead just use the | |
1616 | BFD_RELOC_UNUSED plus the operand index. This lets us easily | |
1617 | handle fixups for any operand type, although that is admittedly | |
1618 | not a very exciting feature. We pick a BFD reloc type in | |
55cf6793 | 1619 | md_apply_fix. */ |
07855bec NC |
1620 | for (i = 0; i < fc; i++) |
1621 | { | |
1971b29d MS |
1622 | |
1623 | if (fixups[i].opindex < 0) | |
1624 | { | |
1625 | /* Create tls instruction marker relocation. */ | |
1626 | fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->oplen, | |
1627 | &fixups[i].exp, 0, fixups[i].reloc); | |
1628 | continue; | |
1629 | } | |
1630 | ||
07855bec | 1631 | operand = s390_operands + fixups[i].opindex; |
a85d7ed0 | 1632 | |
07855bec NC |
1633 | if (fixups[i].reloc != BFD_RELOC_UNUSED) |
1634 | { | |
1635 | reloc_howto_type *reloc_howto; | |
1636 | fixS *fixP; | |
1637 | int size; | |
198ce79b | 1638 | |
07855bec NC |
1639 | reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); |
1640 | if (!reloc_howto) | |
1641 | abort (); | |
198ce79b | 1642 | |
fb798c50 | 1643 | size = ((reloc_howto->bitsize - 1) / 8) + 1; |
07855bec NC |
1644 | |
1645 | if (size < 1 || size > 4) | |
1646 | abort (); | |
198ce79b AJ |
1647 | |
1648 | fixP = fix_new_exp (frag_now, | |
1649 | f - frag_now->fr_literal + (operand->shift/8), | |
07855bec NC |
1650 | size, &fixups[i].exp, reloc_howto->pc_relative, |
1651 | fixups[i].reloc); | |
1652 | /* Turn off overflow checking in fixup_segment. This is necessary | |
1653 | because fixup_segment will signal an overflow for large 4 byte | |
1654 | quantities for GOT12 relocations. */ | |
16a419ba | 1655 | if ( fixups[i].reloc == BFD_RELOC_390_GOT12 |
933fbc29 | 1656 | || fixups[i].reloc == BFD_RELOC_390_GOT20 |
16a419ba | 1657 | || fixups[i].reloc == BFD_RELOC_390_GOT16) |
07855bec | 1658 | fixP->fx_no_overflow = 1; |
feb4bea7 AK |
1659 | |
1660 | if (operand->flags & S390_OPERAND_PCREL) | |
1661 | fixP->fx_pcrel_adjust = operand->shift / 8; | |
07855bec NC |
1662 | } |
1663 | else | |
1664 | fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp, | |
1665 | (operand->flags & S390_OPERAND_PCREL) != 0, | |
1666 | ((bfd_reloc_code_real_type) | |
1667 | (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); | |
1668 | } | |
a85d7ed0 NC |
1669 | return str; |
1670 | } | |
1671 | ||
1672 | /* This routine is called for each instruction to be assembled. */ | |
1673 | ||
1674 | void | |
5a49b8ac | 1675 | md_assemble (char *str) |
a85d7ed0 NC |
1676 | { |
1677 | const struct s390_opcode *opcode; | |
1678 | unsigned char insn[6]; | |
1679 | char *s; | |
1680 | ||
1681 | /* Get the opcode. */ | |
3882b010 | 1682 | for (s = str; *s != '\0' && ! ISSPACE (*s); s++) |
a85d7ed0 NC |
1683 | ; |
1684 | if (*s != '\0') | |
1685 | *s++ = '\0'; | |
1686 | ||
1687 | /* Look up the opcode in the hash table. */ | |
629310ab | 1688 | opcode = (struct s390_opcode *) str_hash_find (s390_opcode_hash, str); |
07855bec NC |
1689 | if (opcode == (const struct s390_opcode *) NULL) |
1690 | { | |
1691 | as_bad (_("Unrecognized opcode: `%s'"), str); | |
1692 | return; | |
1693 | } | |
37a58793 MS |
1694 | else if (!(opcode->modes & current_mode_mask)) |
1695 | { | |
20203fb9 | 1696 | as_bad (_("Opcode %s not available in this mode"), str); |
37a58793 MS |
1697 | return; |
1698 | } | |
07726851 | 1699 | memcpy (insn, opcode->opcode, sizeof (insn)); |
07855bec | 1700 | md_gather_operands (s, insn, opcode); |
a85d7ed0 NC |
1701 | } |
1702 | ||
1703 | #ifndef WORKING_DOT_WORD | |
1704 | /* Handle long and short jumps. We don't support these */ | |
1705 | void | |
1706 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1707 | char *ptr; | |
1708 | addressT from_addr, to_addr; | |
1709 | fragS *frag; | |
1710 | symbolS *to_symbol; | |
1711 | { | |
1712 | abort (); | |
1713 | } | |
1714 | ||
1715 | void | |
1716 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1717 | char *ptr; | |
1718 | addressT from_addr, to_addr; | |
1719 | fragS *frag; | |
1720 | symbolS *to_symbol; | |
1721 | { | |
1722 | abort (); | |
1723 | } | |
1724 | #endif | |
1725 | ||
1726 | void | |
5a49b8ac | 1727 | s390_bss (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1728 | { |
1729 | /* We don't support putting frags in the BSS segment, we fake it | |
1730 | by marking in_bss, then looking at s_skip for clues. */ | |
1731 | ||
1732 | subseg_set (bss_section, 0); | |
1733 | demand_empty_rest_of_line (); | |
1734 | } | |
1735 | ||
1736 | /* Pseudo-op handling. */ | |
1737 | ||
1738 | void | |
5a49b8ac | 1739 | s390_insn (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1740 | { |
1741 | expressionS exp; | |
1742 | const struct s390_opcode *opformat; | |
1743 | unsigned char insn[6]; | |
1744 | char *s; | |
1745 | ||
1746 | /* Get the opcode format. */ | |
1747 | s = input_line_pointer; | |
3882b010 | 1748 | while (*s != '\0' && *s != ',' && ! ISSPACE (*s)) |
a85d7ed0 NC |
1749 | s++; |
1750 | if (*s != ',') | |
1751 | as_bad (_("Invalid .insn format\n")); | |
1752 | *s++ = '\0'; | |
1753 | ||
1754 | /* Look up the opcode in the hash table. */ | |
1755 | opformat = (struct s390_opcode *) | |
629310ab | 1756 | str_hash_find (s390_opformat_hash, input_line_pointer); |
07855bec NC |
1757 | if (opformat == (const struct s390_opcode *) NULL) |
1758 | { | |
1759 | as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer); | |
1760 | return; | |
1761 | } | |
a85d7ed0 NC |
1762 | input_line_pointer = s; |
1763 | expression (&exp); | |
07855bec NC |
1764 | if (exp.X_op == O_constant) |
1765 | { | |
1d6d62a4 | 1766 | if ( ( opformat->oplen == 6 |
1d6d62a4 MS |
1767 | && (addressT) exp.X_add_number < (1ULL << 48)) |
1768 | || ( opformat->oplen == 4 | |
1d6d62a4 MS |
1769 | && (addressT) exp.X_add_number < (1ULL << 32)) |
1770 | || ( opformat->oplen == 2 | |
1d6d62a4 | 1771 | && (addressT) exp.X_add_number < (1ULL << 16))) |
2132e3a3 | 1772 | md_number_to_chars ((char *) insn, exp.X_add_number, opformat->oplen); |
07855bec | 1773 | else |
07726851 | 1774 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1775 | } |
1776 | else if (exp.X_op == O_big) | |
1777 | { | |
16a419ba NC |
1778 | if (exp.X_add_number > 0 |
1779 | && opformat->oplen == 6 | |
1780 | && generic_bignum[3] == 0) | |
07855bec | 1781 | { |
2132e3a3 AM |
1782 | md_number_to_chars ((char *) insn, generic_bignum[2], 2); |
1783 | md_number_to_chars ((char *) &insn[2], generic_bignum[1], 2); | |
1784 | md_number_to_chars ((char *) &insn[4], generic_bignum[0], 2); | |
07855bec NC |
1785 | } |
1786 | else | |
07726851 | 1787 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1788 | } |
1789 | else | |
a85d7ed0 | 1790 | as_bad (_("second operand of .insn not a constant\n")); |
a85d7ed0 | 1791 | |
b6849f55 NC |
1792 | if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',') |
1793 | as_bad (_("missing comma after insn constant\n")); | |
98d3f06f | 1794 | |
07726851 | 1795 | if ((s = strchr (input_line_pointer, '\n')) != NULL) |
a85d7ed0 | 1796 | *s = '\0'; |
b6849f55 NC |
1797 | input_line_pointer = md_gather_operands (input_line_pointer, insn, |
1798 | opformat); | |
a85d7ed0 NC |
1799 | if (s != NULL) |
1800 | *s = '\n'; | |
1801 | demand_empty_rest_of_line (); | |
1802 | } | |
1803 | ||
1804 | /* The .byte pseudo-op. This is similar to the normal .byte | |
1805 | pseudo-op, but it can also take a single ASCII string. */ | |
1806 | ||
1807 | static void | |
5a49b8ac | 1808 | s390_byte (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1809 | { |
1810 | if (*input_line_pointer != '\"') | |
1811 | { | |
1812 | cons (1); | |
1813 | return; | |
1814 | } | |
1815 | ||
1816 | /* Gather characters. A real double quote is doubled. Unusual | |
1817 | characters are not permitted. */ | |
1818 | ++input_line_pointer; | |
1819 | while (1) | |
1820 | { | |
1821 | char c; | |
1822 | ||
1823 | c = *input_line_pointer++; | |
1824 | ||
1825 | if (c == '\"') | |
1826 | { | |
1827 | if (*input_line_pointer != '\"') | |
1828 | break; | |
1829 | ++input_line_pointer; | |
1830 | } | |
1831 | ||
1832 | FRAG_APPEND_1_CHAR (c); | |
1833 | } | |
1834 | ||
1835 | demand_empty_rest_of_line (); | |
1836 | } | |
1837 | ||
1838 | /* The .ltorg pseudo-op.This emits all literals defined since the last | |
198ce79b | 1839 | .ltorg or the invocation of gas. Literals are defined with the |
a85d7ed0 NC |
1840 | @lit suffix. */ |
1841 | ||
1842 | static void | |
5a49b8ac | 1843 | s390_literals (int ignore ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
1844 | { |
1845 | struct s390_lpe *lpe; | |
1846 | ||
1847 | if (lp_sym == NULL || lpe_count == 0) | |
98d3f06f | 1848 | return; /* Nothing to be done. */ |
a85d7ed0 NC |
1849 | |
1850 | /* Emit symbol for start of literal pool. */ | |
1851 | S_SET_SEGMENT (lp_sym, now_seg); | |
1852 | S_SET_VALUE (lp_sym, (valueT) frag_now_fix ()); | |
8d1015a8 | 1853 | symbol_set_frag (lp_sym, frag_now); |
a85d7ed0 | 1854 | |
07855bec NC |
1855 | while (lpe_list) |
1856 | { | |
1857 | lpe = lpe_list; | |
1858 | lpe_list = lpe_list->next; | |
1859 | S_SET_SEGMENT (lpe->sym, now_seg); | |
1860 | S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ()); | |
8d1015a8 | 1861 | symbol_set_frag (lpe->sym, frag_now); |
07855bec NC |
1862 | |
1863 | /* Emit literal pool entry. */ | |
1864 | if (lpe->reloc != BFD_RELOC_UNUSED) | |
1865 | { | |
198ce79b | 1866 | reloc_howto_type *reloc_howto = |
07855bec NC |
1867 | bfd_reloc_type_lookup (stdoutput, lpe->reloc); |
1868 | int size = bfd_get_reloc_size (reloc_howto); | |
1869 | char *where; | |
1870 | ||
1871 | if (size > lpe->nbytes) | |
992a06ee AM |
1872 | as_bad (ngettext ("%s relocations do not fit in %d byte", |
1873 | "%s relocations do not fit in %d bytes", | |
1874 | lpe->nbytes), | |
07855bec | 1875 | reloc_howto->name, lpe->nbytes); |
07726851 | 1876 | where = frag_more (lpe->nbytes); |
07855bec NC |
1877 | md_number_to_chars (where, 0, size); |
1878 | fix_new_exp (frag_now, where - frag_now->fr_literal, | |
1879 | size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc); | |
1880 | } | |
1881 | else | |
1882 | { | |
1883 | if (lpe->ex.X_op == O_big) | |
1884 | { | |
1885 | if (lpe->ex.X_add_number <= 0) | |
1886 | generic_floating_point_number = lpe->floatnum; | |
1887 | else | |
1888 | memcpy (generic_bignum, lpe->bignum, | |
98d3f06f | 1889 | lpe->ex.X_add_number * sizeof (LITTLENUM_TYPE)); |
07855bec NC |
1890 | } |
1891 | emit_expr (&lpe->ex, lpe->nbytes); | |
1892 | } | |
a85d7ed0 | 1893 | |
07855bec NC |
1894 | lpe->next = lpe_free_list; |
1895 | lpe_free_list = lpe; | |
1896 | } | |
a85d7ed0 NC |
1897 | lpe_list_tail = NULL; |
1898 | lp_sym = NULL; | |
1899 | lp_count++; | |
1900 | lpe_count = 0; | |
1901 | } | |
1902 | ||
7ecc513a DV |
1903 | #define MAX_HISTORY 100 |
1904 | ||
f9a6a8f0 | 1905 | /* The .machine pseudo op allows one to switch to a different CPU level in |
902cc293 | 1906 | the asm listing. The current CPU setting can be stored on a stack |
1dd53816 | 1907 | with .machine push and restored with .machine pop. */ |
902cc293 AK |
1908 | |
1909 | static void | |
1910 | s390_machine (int ignore ATTRIBUTE_UNUSED) | |
1911 | { | |
1912 | char *cpu_string; | |
325801bd | 1913 | static struct cpu_history |
7ecc513a DV |
1914 | { |
1915 | unsigned int cpu; | |
1916 | unsigned int flags; | |
1917 | } *cpu_history; | |
902cc293 AK |
1918 | static int curr_hist; |
1919 | ||
1920 | SKIP_WHITESPACE (); | |
1921 | ||
1922 | if (*input_line_pointer == '"') | |
1923 | { | |
1924 | int len; | |
1925 | cpu_string = demand_copy_C_string (&len); | |
1926 | } | |
1927 | else | |
1928 | { | |
1929 | char c; | |
7ecc513a DV |
1930 | |
1931 | cpu_string = input_line_pointer; | |
1932 | do | |
1933 | { | |
1934 | char * str; | |
1935 | ||
1936 | c = get_symbol_name (&str); | |
1937 | c = restore_line_pointer (c); | |
1938 | if (c == '+') | |
1939 | ++ input_line_pointer; | |
1940 | } | |
1941 | while (c == '+'); | |
1942 | ||
1943 | c = *input_line_pointer; | |
1944 | *input_line_pointer = 0; | |
902cc293 | 1945 | cpu_string = xstrdup (cpu_string); |
d02603dc | 1946 | (void) restore_line_pointer (c); |
902cc293 AK |
1947 | } |
1948 | ||
1949 | if (cpu_string != NULL) | |
1950 | { | |
7ecc513a DV |
1951 | unsigned int new_cpu = current_cpu; |
1952 | unsigned int new_flags = current_flags; | |
902cc293 AK |
1953 | |
1954 | if (strcmp (cpu_string, "push") == 0) | |
1955 | { | |
1956 | if (cpu_history == NULL) | |
325801bd | 1957 | cpu_history = XNEWVEC (struct cpu_history, MAX_HISTORY); |
902cc293 AK |
1958 | |
1959 | if (curr_hist >= MAX_HISTORY) | |
1960 | as_bad (_(".machine stack overflow")); | |
1961 | else | |
7ecc513a DV |
1962 | { |
1963 | cpu_history[curr_hist].cpu = current_cpu; | |
1964 | cpu_history[curr_hist].flags = current_flags; | |
1965 | curr_hist++; | |
1966 | } | |
902cc293 AK |
1967 | } |
1968 | else if (strcmp (cpu_string, "pop") == 0) | |
1969 | { | |
1970 | if (curr_hist <= 0) | |
1971 | as_bad (_(".machine stack underflow")); | |
1972 | else | |
7ecc513a DV |
1973 | { |
1974 | curr_hist--; | |
1975 | new_cpu = cpu_history[curr_hist].cpu; | |
1976 | new_flags = cpu_history[curr_hist].flags; | |
1977 | } | |
902cc293 | 1978 | } |
902cc293 | 1979 | else |
7ecc513a DV |
1980 | new_cpu = s390_parse_cpu (cpu_string, &new_flags, TRUE); |
1981 | ||
1982 | if (new_cpu == S390_OPCODE_MAXCPU) | |
902cc293 AK |
1983 | as_bad (_("invalid machine `%s'"), cpu_string); |
1984 | ||
7ecc513a DV |
1985 | if (new_cpu != current_cpu || new_flags != current_flags) |
1986 | { | |
1987 | current_cpu = new_cpu; | |
1988 | current_flags = new_flags; | |
1989 | s390_setup_opcodes (); | |
1990 | } | |
902cc293 AK |
1991 | } |
1992 | ||
1993 | demand_empty_rest_of_line (); | |
1994 | } | |
1995 | ||
f9a6a8f0 | 1996 | /* The .machinemode pseudo op allows one to switch to a different |
1dd53816 AK |
1997 | architecture mode in the asm listing. The current architecture |
1998 | mode setting can be stored on a stack with .machinemode push and | |
1999 | restored with .machinemode pop. */ | |
2000 | ||
2001 | static void | |
2002 | s390_machinemode (int ignore ATTRIBUTE_UNUSED) | |
2003 | { | |
2004 | char *mode_string; | |
1dd53816 AK |
2005 | static unsigned int *mode_history; |
2006 | static int curr_hist; | |
2007 | ||
2008 | SKIP_WHITESPACE (); | |
2009 | ||
d02603dc NC |
2010 | { |
2011 | char c; | |
2012 | ||
2013 | c = get_symbol_name (&mode_string); | |
2014 | mode_string = xstrdup (mode_string); | |
2015 | (void) restore_line_pointer (c); | |
2016 | } | |
1dd53816 AK |
2017 | |
2018 | if (mode_string != NULL) | |
2019 | { | |
2020 | unsigned int old_mode_mask = current_mode_mask; | |
2021 | char *p; | |
2022 | ||
2023 | for (p = mode_string; *p != 0; p++) | |
2024 | *p = TOLOWER (*p); | |
2025 | ||
2026 | if (strcmp (mode_string, "push") == 0) | |
2027 | { | |
2028 | if (mode_history == NULL) | |
325801bd | 2029 | mode_history = XNEWVEC (unsigned int, MAX_HISTORY); |
1dd53816 AK |
2030 | |
2031 | if (curr_hist >= MAX_HISTORY) | |
2032 | as_bad (_(".machinemode stack overflow")); | |
2033 | else | |
2034 | mode_history[curr_hist++] = current_mode_mask; | |
2035 | } | |
2036 | else if (strcmp (mode_string, "pop") == 0) | |
2037 | { | |
2038 | if (curr_hist <= 0) | |
2039 | as_bad (_(".machinemode stack underflow")); | |
2040 | else | |
2041 | current_mode_mask = mode_history[--curr_hist]; | |
2042 | } | |
2043 | else | |
2044 | { | |
2045 | if (strcmp (mode_string, "esa") == 0) | |
2046 | current_mode_mask = 1 << S390_OPCODE_ESA; | |
2047 | else if (strcmp (mode_string, "zarch") == 0) | |
2048 | { | |
2049 | if (s390_arch_size == 32) | |
2050 | set_highgprs_p = TRUE; | |
2051 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
2052 | } | |
2053 | else if (strcmp (mode_string, "zarch_nohighgprs") == 0) | |
2054 | current_mode_mask = 1 << S390_OPCODE_ZARCH; | |
2055 | else | |
7ecc513a | 2056 | as_bad (_("invalid machine mode `%s'"), mode_string); |
1dd53816 AK |
2057 | } |
2058 | ||
2059 | if (current_mode_mask != old_mode_mask) | |
2060 | s390_setup_opcodes (); | |
2061 | } | |
2062 | ||
2063 | demand_empty_rest_of_line (); | |
2064 | } | |
2065 | ||
7ecc513a DV |
2066 | #undef MAX_HISTORY |
2067 | ||
6d4af3c2 | 2068 | const char * |
499ac353 | 2069 | md_atof (int type, char *litp, int *sizep) |
a85d7ed0 | 2070 | { |
499ac353 | 2071 | return ieee_md_atof (type, litp, sizep, TRUE); |
a85d7ed0 NC |
2072 | } |
2073 | ||
2074 | /* Align a section (I don't know why this is machine dependent). */ | |
2075 | ||
2076 | valueT | |
5a49b8ac | 2077 | md_section_align (asection *seg, valueT addr) |
a85d7ed0 | 2078 | { |
fd361982 | 2079 | int align = bfd_section_alignment (seg); |
a85d7ed0 | 2080 | |
8d3842cd | 2081 | return ((addr + (1 << align) - 1) & -(1 << align)); |
a85d7ed0 NC |
2082 | } |
2083 | ||
2084 | /* We don't have any form of relaxing. */ | |
2085 | ||
2086 | int | |
5a49b8ac AM |
2087 | md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED, |
2088 | asection *seg ATTRIBUTE_UNUSED) | |
a85d7ed0 NC |
2089 | { |
2090 | abort (); | |
2091 | return 0; | |
2092 | } | |
2093 | ||
2094 | /* Convert a machine dependent frag. We never generate these. */ | |
2095 | ||
2096 | void | |
5a49b8ac AM |
2097 | md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, |
2098 | asection *sec ATTRIBUTE_UNUSED, | |
2099 | fragS *fragp ATTRIBUTE_UNUSED) | |
a85d7ed0 NC |
2100 | { |
2101 | abort (); | |
2102 | } | |
2103 | ||
2104 | symbolS * | |
5a49b8ac | 2105 | md_undefined_symbol (char *name) |
a85d7ed0 | 2106 | { |
98d3f06f | 2107 | if (*name == '_' && *(name + 1) == 'G' |
07726851 | 2108 | && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) |
98d3f06f KH |
2109 | { |
2110 | if (!GOT_symbol) | |
2111 | { | |
2112 | if (symbol_find (name)) | |
2113 | as_bad (_("GOT already in symbol table")); | |
2114 | GOT_symbol = symbol_new (name, undefined_section, | |
e01e1cee | 2115 | &zero_address_frag, 0); |
98d3f06f KH |
2116 | } |
2117 | return GOT_symbol; | |
2118 | } | |
a85d7ed0 NC |
2119 | return 0; |
2120 | } | |
2121 | ||
2122 | /* Functions concerning relocs. */ | |
2123 | ||
2124 | /* The location from which a PC relative jump should be calculated, | |
2125 | given a PC relative reloc. */ | |
2126 | ||
2127 | long | |
5a49b8ac | 2128 | md_pcrel_from_section (fixS *fixp, segT sec ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
2129 | { |
2130 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
2131 | } | |
2132 | ||
2133 | /* Here we decide which fixups can be adjusted to make them relative to | |
2134 | the beginning of the section instead of the symbol. Basically we need | |
2135 | to make sure that the dynamic relocations are done correctly, so in | |
2136 | some cases we force the original symbol to be used. */ | |
2137 | int | |
5a49b8ac | 2138 | tc_s390_fix_adjustable (fixS *fixP) |
a85d7ed0 | 2139 | { |
dc1e4d6d NC |
2140 | /* Don't adjust pc-relative references to merge sections. */ |
2141 | if (fixP->fx_pcrel | |
2142 | && (S_GET_SEGMENT (fixP->fx_addsy)->flags & SEC_MERGE) != 0) | |
0a00dd48 | 2143 | return 0; |
dc1e4d6d | 2144 | |
a85d7ed0 | 2145 | /* adjust_reloc_syms doesn't know about the GOT. */ |
2a19f73f MS |
2146 | if ( fixP->fx_r_type == BFD_RELOC_16_GOTOFF |
2147 | || fixP->fx_r_type == BFD_RELOC_32_GOTOFF | |
2148 | || fixP->fx_r_type == BFD_RELOC_390_GOTOFF64 | |
2149 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF16 | |
2150 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF32 | |
2151 | || fixP->fx_r_type == BFD_RELOC_390_PLTOFF64 | |
fb798c50 | 2152 | || fixP->fx_r_type == BFD_RELOC_390_PLT12DBL |
a85d7ed0 | 2153 | || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL |
fb798c50 | 2154 | || fixP->fx_r_type == BFD_RELOC_390_PLT24DBL |
a85d7ed0 NC |
2155 | || fixP->fx_r_type == BFD_RELOC_390_PLT32 |
2156 | || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL | |
2157 | || fixP->fx_r_type == BFD_RELOC_390_PLT64 | |
2158 | || fixP->fx_r_type == BFD_RELOC_390_GOT12 | |
933fbc29 | 2159 | || fixP->fx_r_type == BFD_RELOC_390_GOT20 |
a85d7ed0 NC |
2160 | || fixP->fx_r_type == BFD_RELOC_390_GOT16 |
2161 | || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL | |
2162 | || fixP->fx_r_type == BFD_RELOC_390_GOT64 | |
07855bec | 2163 | || fixP->fx_r_type == BFD_RELOC_390_GOTENT |
2a19f73f MS |
2164 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT12 |
2165 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT16 | |
933fbc29 | 2166 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT20 |
2a19f73f MS |
2167 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT32 |
2168 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLT64 | |
2169 | || fixP->fx_r_type == BFD_RELOC_390_GOTPLTENT | |
1971b29d MS |
2170 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LOAD |
2171 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GDCALL | |
2172 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDCALL | |
2173 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GD32 | |
2174 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GD64 | |
2175 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE12 | |
933fbc29 | 2176 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE20 |
1971b29d MS |
2177 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE32 |
2178 | || fixP->fx_r_type == BFD_RELOC_390_TLS_GOTIE64 | |
2179 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM32 | |
2180 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDM64 | |
2181 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IE32 | |
2182 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IE64 | |
2183 | || fixP->fx_r_type == BFD_RELOC_390_TLS_IEENT | |
2184 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LE32 | |
2185 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LE64 | |
2186 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO32 | |
2187 | || fixP->fx_r_type == BFD_RELOC_390_TLS_LDO64 | |
2188 | || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPMOD | |
2189 | || fixP->fx_r_type == BFD_RELOC_390_TLS_DTPOFF | |
2190 | || fixP->fx_r_type == BFD_RELOC_390_TLS_TPOFF | |
a85d7ed0 NC |
2191 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
2192 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
2193 | return 0; | |
2194 | return 1; | |
2195 | } | |
2196 | ||
b8edc45c | 2197 | /* Return true if we must always emit a reloc for a type and false if |
c03099e6 | 2198 | there is some hope of resolving it at assembly time. */ |
b8edc45c | 2199 | int |
5a49b8ac | 2200 | tc_s390_force_relocation (struct fix *fixp) |
b8edc45c MS |
2201 | { |
2202 | /* Ensure we emit a relocation for every reference to the global | |
2203 | offset table or to the procedure link table. */ | |
2204 | switch (fixp->fx_r_type) | |
2205 | { | |
2206 | case BFD_RELOC_390_GOT12: | |
933fbc29 | 2207 | case BFD_RELOC_390_GOT20: |
b8edc45c MS |
2208 | case BFD_RELOC_32_GOT_PCREL: |
2209 | case BFD_RELOC_32_GOTOFF: | |
2a19f73f MS |
2210 | case BFD_RELOC_390_GOTOFF64: |
2211 | case BFD_RELOC_390_PLTOFF16: | |
2212 | case BFD_RELOC_390_PLTOFF32: | |
2213 | case BFD_RELOC_390_PLTOFF64: | |
b8edc45c MS |
2214 | case BFD_RELOC_390_GOTPC: |
2215 | case BFD_RELOC_390_GOT16: | |
2216 | case BFD_RELOC_390_GOTPCDBL: | |
2217 | case BFD_RELOC_390_GOT64: | |
2218 | case BFD_RELOC_390_GOTENT: | |
2219 | case BFD_RELOC_390_PLT32: | |
fb798c50 | 2220 | case BFD_RELOC_390_PLT12DBL: |
b8edc45c | 2221 | case BFD_RELOC_390_PLT16DBL: |
fb798c50 | 2222 | case BFD_RELOC_390_PLT24DBL: |
b8edc45c MS |
2223 | case BFD_RELOC_390_PLT32DBL: |
2224 | case BFD_RELOC_390_PLT64: | |
2a19f73f MS |
2225 | case BFD_RELOC_390_GOTPLT12: |
2226 | case BFD_RELOC_390_GOTPLT16: | |
933fbc29 | 2227 | case BFD_RELOC_390_GOTPLT20: |
2a19f73f MS |
2228 | case BFD_RELOC_390_GOTPLT32: |
2229 | case BFD_RELOC_390_GOTPLT64: | |
2230 | case BFD_RELOC_390_GOTPLTENT: | |
b8edc45c MS |
2231 | return 1; |
2232 | default: | |
5bb3703f | 2233 | break; |
b8edc45c | 2234 | } |
a161fe53 | 2235 | |
ae6063d4 | 2236 | return generic_force_reloc (fixp); |
b8edc45c MS |
2237 | } |
2238 | ||
a85d7ed0 NC |
2239 | /* Apply a fixup to the object code. This is called for all the |
2240 | fixups we generated by the call to fix_new_exp, above. In the call | |
2241 | above we used a reloc code which was the largest legal reloc code | |
2242 | plus the operand index. Here we undo that to recover the operand | |
2243 | index. At this point all symbol values should be fully resolved, | |
2244 | and we attempt to completely resolve the reloc. If we can not do | |
2245 | that, we determine the correct reloc code and put it back in the | |
2246 | fixup. */ | |
2247 | ||
94f592af | 2248 | void |
5a49b8ac | 2249 | md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
a85d7ed0 NC |
2250 | { |
2251 | char *where; | |
98d3f06f | 2252 | valueT value = *valP; |
a85d7ed0 | 2253 | |
94f592af | 2254 | where = fixP->fx_frag->fr_literal + fixP->fx_where; |
a85d7ed0 | 2255 | |
98d3f06f | 2256 | if (fixP->fx_subsy != NULL) |
f1fc51da | 2257 | as_bad_where (fixP->fx_file, fixP->fx_line, |
20203fb9 | 2258 | _("cannot emit relocation %s against subsy symbol %s"), |
f1fc51da MS |
2259 | bfd_get_reloc_code_name (fixP->fx_r_type), |
2260 | S_GET_NAME (fixP->fx_subsy)); | |
98d3f06f KH |
2261 | |
2262 | if (fixP->fx_addsy != NULL) | |
07855bec | 2263 | { |
94f592af NC |
2264 | if (fixP->fx_pcrel) |
2265 | value += fixP->fx_frag->fr_address + fixP->fx_where; | |
07855bec NC |
2266 | } |
2267 | else | |
94f592af | 2268 | fixP->fx_done = 1; |
a85d7ed0 | 2269 | |
94f592af | 2270 | if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED) |
07855bec NC |
2271 | { |
2272 | const struct s390_operand *operand; | |
2273 | int opindex; | |
198ce79b | 2274 | |
94f592af | 2275 | opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED; |
07855bec | 2276 | operand = &s390_operands[opindex]; |
198ce79b | 2277 | |
94f592af | 2278 | if (fixP->fx_done) |
07855bec NC |
2279 | { |
2280 | /* Insert the fully resolved operand value. */ | |
2132e3a3 AM |
2281 | s390_insert_operand ((unsigned char *) where, operand, |
2282 | (offsetT) value, fixP->fx_file, fixP->fx_line); | |
94f592af | 2283 | return; |
07855bec | 2284 | } |
198ce79b | 2285 | |
07855bec NC |
2286 | /* Determine a BFD reloc value based on the operand information. |
2287 | We are only prepared to turn a few of the operands into | |
2288 | relocs. */ | |
94f592af | 2289 | fixP->fx_offset = value; |
07855bec NC |
2290 | if (operand->bits == 12 && operand->shift == 20) |
2291 | { | |
94f592af NC |
2292 | fixP->fx_size = 2; |
2293 | fixP->fx_where += 2; | |
2294 | fixP->fx_r_type = BFD_RELOC_390_12; | |
07855bec NC |
2295 | } |
2296 | else if (operand->bits == 12 && operand->shift == 36) | |
2297 | { | |
94f592af NC |
2298 | fixP->fx_size = 2; |
2299 | fixP->fx_where += 4; | |
2300 | fixP->fx_r_type = BFD_RELOC_390_12; | |
07855bec | 2301 | } |
933fbc29 MS |
2302 | else if (operand->bits == 20 && operand->shift == 20) |
2303 | { | |
3d6e0c01 | 2304 | fixP->fx_size = 4; |
933fbc29 MS |
2305 | fixP->fx_where += 2; |
2306 | fixP->fx_r_type = BFD_RELOC_390_20; | |
2307 | } | |
07855bec NC |
2308 | else if (operand->bits == 8 && operand->shift == 8) |
2309 | { | |
94f592af NC |
2310 | fixP->fx_size = 1; |
2311 | fixP->fx_where += 1; | |
2312 | fixP->fx_r_type = BFD_RELOC_8; | |
07855bec | 2313 | } |
fb798c50 AK |
2314 | else if (operand->bits == 12 && operand->shift == 12 |
2315 | && (operand->flags & S390_OPERAND_PCREL)) | |
2316 | { | |
2317 | fixP->fx_size = 2; | |
2318 | fixP->fx_where += 1; | |
2319 | fixP->fx_offset += 1; | |
feb4bea7 | 2320 | fixP->fx_pcrel_adjust = 1; |
fb798c50 AK |
2321 | fixP->fx_r_type = BFD_RELOC_390_PC12DBL; |
2322 | } | |
07855bec NC |
2323 | else if (operand->bits == 16 && operand->shift == 16) |
2324 | { | |
94f592af NC |
2325 | fixP->fx_size = 2; |
2326 | fixP->fx_where += 2; | |
07855bec NC |
2327 | if (operand->flags & S390_OPERAND_PCREL) |
2328 | { | |
94f592af NC |
2329 | fixP->fx_r_type = BFD_RELOC_390_PC16DBL; |
2330 | fixP->fx_offset += 2; | |
feb4bea7 | 2331 | fixP->fx_pcrel_adjust = 2; |
07855bec NC |
2332 | } |
2333 | else | |
94f592af | 2334 | fixP->fx_r_type = BFD_RELOC_16; |
07855bec | 2335 | } |
feb4bea7 AK |
2336 | else if (operand->bits == 16 && operand->shift == 32 |
2337 | && (operand->flags & S390_OPERAND_PCREL)) | |
2338 | { | |
2339 | fixP->fx_size = 2; | |
2340 | fixP->fx_where += 4; | |
2341 | fixP->fx_offset += 4; | |
2342 | fixP->fx_pcrel_adjust = 4; | |
2343 | fixP->fx_r_type = BFD_RELOC_390_PC16DBL; | |
2344 | } | |
fb798c50 AK |
2345 | else if (operand->bits == 24 && operand->shift == 24 |
2346 | && (operand->flags & S390_OPERAND_PCREL)) | |
2347 | { | |
2348 | fixP->fx_size = 3; | |
2349 | fixP->fx_where += 3; | |
2350 | fixP->fx_offset += 3; | |
feb4bea7 | 2351 | fixP->fx_pcrel_adjust = 3; |
fb798c50 AK |
2352 | fixP->fx_r_type = BFD_RELOC_390_PC24DBL; |
2353 | } | |
16a419ba NC |
2354 | else if (operand->bits == 32 && operand->shift == 16 |
2355 | && (operand->flags & S390_OPERAND_PCREL)) | |
07855bec | 2356 | { |
94f592af NC |
2357 | fixP->fx_size = 4; |
2358 | fixP->fx_where += 2; | |
2359 | fixP->fx_offset += 2; | |
feb4bea7 | 2360 | fixP->fx_pcrel_adjust = 2; |
94f592af | 2361 | fixP->fx_r_type = BFD_RELOC_390_PC32DBL; |
07855bec | 2362 | } |
a85d7ed0 | 2363 | else |
07855bec | 2364 | { |
3b4dbbbf | 2365 | const char *sfile; |
07855bec | 2366 | unsigned int sline; |
198ce79b | 2367 | |
07855bec NC |
2368 | /* Use expr_symbol_where to see if this is an expression |
2369 | symbol. */ | |
94f592af NC |
2370 | if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline)) |
2371 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
07855bec NC |
2372 | _("unresolved expression that must be resolved")); |
2373 | else | |
94f592af | 2374 | as_bad_where (fixP->fx_file, fixP->fx_line, |
07855bec | 2375 | _("unsupported relocation type")); |
94f592af NC |
2376 | fixP->fx_done = 1; |
2377 | return; | |
07855bec | 2378 | } |
a85d7ed0 | 2379 | } |
07855bec NC |
2380 | else |
2381 | { | |
94f592af | 2382 | switch (fixP->fx_r_type) |
07855bec NC |
2383 | { |
2384 | case BFD_RELOC_8: | |
94f592af | 2385 | if (fixP->fx_pcrel) |
07855bec | 2386 | abort (); |
94f592af | 2387 | if (fixP->fx_done) |
07855bec NC |
2388 | md_number_to_chars (where, value, 1); |
2389 | break; | |
2390 | case BFD_RELOC_390_12: | |
2391 | case BFD_RELOC_390_GOT12: | |
2a19f73f | 2392 | case BFD_RELOC_390_GOTPLT12: |
fb798c50 AK |
2393 | case BFD_RELOC_390_PC12DBL: |
2394 | case BFD_RELOC_390_PLT12DBL: | |
2395 | if (fixP->fx_pcrel) | |
feb4bea7 | 2396 | value += fixP->fx_pcrel_adjust; |
fb798c50 | 2397 | |
94f592af | 2398 | if (fixP->fx_done) |
07855bec NC |
2399 | { |
2400 | unsigned short mop; | |
2401 | ||
fb798c50 AK |
2402 | if (fixP->fx_pcrel) |
2403 | value >>= 1; | |
2404 | ||
07855bec NC |
2405 | mop = bfd_getb16 ((unsigned char *) where); |
2406 | mop |= (unsigned short) (value & 0xfff); | |
2407 | bfd_putb16 ((bfd_vma) mop, (unsigned char *) where); | |
198ce79b | 2408 | } |
07855bec | 2409 | break; |
198ce79b | 2410 | |
933fbc29 MS |
2411 | case BFD_RELOC_390_20: |
2412 | case BFD_RELOC_390_GOT20: | |
2413 | case BFD_RELOC_390_GOTPLT20: | |
2414 | if (fixP->fx_done) | |
2415 | { | |
2416 | unsigned int mop; | |
2417 | mop = bfd_getb32 ((unsigned char *) where); | |
2418 | mop |= (unsigned int) ((value & 0xfff) << 8 | | |
2419 | (value & 0xff000) >> 12); | |
2420 | bfd_putb32 ((bfd_vma) mop, (unsigned char *) where); | |
3739860c | 2421 | } |
933fbc29 MS |
2422 | break; |
2423 | ||
07855bec NC |
2424 | case BFD_RELOC_16: |
2425 | case BFD_RELOC_GPREL16: | |
2426 | case BFD_RELOC_16_GOT_PCREL: | |
2427 | case BFD_RELOC_16_GOTOFF: | |
94f592af NC |
2428 | if (fixP->fx_pcrel) |
2429 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
20203fb9 | 2430 | _("cannot emit PC relative %s relocation%s%s"), |
94f592af NC |
2431 | bfd_get_reloc_code_name (fixP->fx_r_type), |
2432 | fixP->fx_addsy != NULL ? " against " : "", | |
2433 | (fixP->fx_addsy != NULL | |
2434 | ? S_GET_NAME (fixP->fx_addsy) | |
07855bec | 2435 | : "")); |
94f592af | 2436 | if (fixP->fx_done) |
07855bec NC |
2437 | md_number_to_chars (where, value, 2); |
2438 | break; | |
2439 | case BFD_RELOC_390_GOT16: | |
2a19f73f MS |
2440 | case BFD_RELOC_390_PLTOFF16: |
2441 | case BFD_RELOC_390_GOTPLT16: | |
94f592af | 2442 | if (fixP->fx_done) |
07855bec NC |
2443 | md_number_to_chars (where, value, 2); |
2444 | break; | |
2445 | case BFD_RELOC_390_PC16DBL: | |
2446 | case BFD_RELOC_390_PLT16DBL: | |
feb4bea7 | 2447 | value += fixP->fx_pcrel_adjust; |
94f592af | 2448 | if (fixP->fx_done) |
07855bec NC |
2449 | md_number_to_chars (where, (offsetT) value >> 1, 2); |
2450 | break; | |
2451 | ||
fb798c50 AK |
2452 | case BFD_RELOC_390_PC24DBL: |
2453 | case BFD_RELOC_390_PLT24DBL: | |
feb4bea7 | 2454 | value += fixP->fx_pcrel_adjust; |
fb798c50 AK |
2455 | if (fixP->fx_done) |
2456 | { | |
2457 | unsigned int mop; | |
2458 | value >>= 1; | |
2459 | ||
2460 | mop = bfd_getb32 ((unsigned char *) where - 1); | |
2461 | mop |= (unsigned int) (value & 0xffffff); | |
2462 | bfd_putb32 ((bfd_vma) mop, (unsigned char *) where - 1); | |
2463 | } | |
2464 | break; | |
2465 | ||
07855bec | 2466 | case BFD_RELOC_32: |
94f592af NC |
2467 | if (fixP->fx_pcrel) |
2468 | fixP->fx_r_type = BFD_RELOC_32_PCREL; | |
07855bec | 2469 | else |
94f592af NC |
2470 | fixP->fx_r_type = BFD_RELOC_32; |
2471 | if (fixP->fx_done) | |
07855bec NC |
2472 | md_number_to_chars (where, value, 4); |
2473 | break; | |
2474 | case BFD_RELOC_32_PCREL: | |
2475 | case BFD_RELOC_32_BASEREL: | |
94f592af NC |
2476 | fixP->fx_r_type = BFD_RELOC_32_PCREL; |
2477 | if (fixP->fx_done) | |
07855bec NC |
2478 | md_number_to_chars (where, value, 4); |
2479 | break; | |
2480 | case BFD_RELOC_32_GOT_PCREL: | |
2a19f73f | 2481 | case BFD_RELOC_390_PLTOFF32: |
07855bec | 2482 | case BFD_RELOC_390_PLT32: |
2a19f73f | 2483 | case BFD_RELOC_390_GOTPLT32: |
94f592af | 2484 | if (fixP->fx_done) |
07855bec NC |
2485 | md_number_to_chars (where, value, 4); |
2486 | break; | |
2487 | case BFD_RELOC_390_PC32DBL: | |
2488 | case BFD_RELOC_390_PLT32DBL: | |
2489 | case BFD_RELOC_390_GOTPCDBL: | |
2490 | case BFD_RELOC_390_GOTENT: | |
2a19f73f | 2491 | case BFD_RELOC_390_GOTPLTENT: |
feb4bea7 | 2492 | value += fixP->fx_pcrel_adjust; |
94f592af | 2493 | if (fixP->fx_done) |
07855bec NC |
2494 | md_number_to_chars (where, (offsetT) value >> 1, 4); |
2495 | break; | |
2496 | ||
2497 | case BFD_RELOC_32_GOTOFF: | |
94f592af | 2498 | if (fixP->fx_done) |
07726851 | 2499 | md_number_to_chars (where, value, sizeof (int)); |
07855bec NC |
2500 | break; |
2501 | ||
2a19f73f MS |
2502 | case BFD_RELOC_390_GOTOFF64: |
2503 | if (fixP->fx_done) | |
2504 | md_number_to_chars (where, value, 8); | |
2505 | break; | |
2506 | ||
07855bec | 2507 | case BFD_RELOC_390_GOT64: |
2a19f73f | 2508 | case BFD_RELOC_390_PLTOFF64: |
07855bec | 2509 | case BFD_RELOC_390_PLT64: |
2a19f73f | 2510 | case BFD_RELOC_390_GOTPLT64: |
94f592af | 2511 | if (fixP->fx_done) |
07855bec NC |
2512 | md_number_to_chars (where, value, 8); |
2513 | break; | |
2514 | ||
2515 | case BFD_RELOC_64: | |
94f592af NC |
2516 | if (fixP->fx_pcrel) |
2517 | fixP->fx_r_type = BFD_RELOC_64_PCREL; | |
07855bec | 2518 | else |
94f592af NC |
2519 | fixP->fx_r_type = BFD_RELOC_64; |
2520 | if (fixP->fx_done) | |
07855bec NC |
2521 | md_number_to_chars (where, value, 8); |
2522 | break; | |
2523 | ||
2524 | case BFD_RELOC_64_PCREL: | |
94f592af NC |
2525 | fixP->fx_r_type = BFD_RELOC_64_PCREL; |
2526 | if (fixP->fx_done) | |
07855bec NC |
2527 | md_number_to_chars (where, value, 8); |
2528 | break; | |
2529 | ||
2530 | case BFD_RELOC_VTABLE_INHERIT: | |
2531 | case BFD_RELOC_VTABLE_ENTRY: | |
94f592af NC |
2532 | fixP->fx_done = 0; |
2533 | return; | |
07855bec | 2534 | |
1971b29d MS |
2535 | case BFD_RELOC_390_TLS_LOAD: |
2536 | case BFD_RELOC_390_TLS_GDCALL: | |
2537 | case BFD_RELOC_390_TLS_LDCALL: | |
2538 | case BFD_RELOC_390_TLS_GD32: | |
2539 | case BFD_RELOC_390_TLS_GD64: | |
2540 | case BFD_RELOC_390_TLS_GOTIE12: | |
933fbc29 | 2541 | case BFD_RELOC_390_TLS_GOTIE20: |
1971b29d MS |
2542 | case BFD_RELOC_390_TLS_GOTIE32: |
2543 | case BFD_RELOC_390_TLS_GOTIE64: | |
2544 | case BFD_RELOC_390_TLS_LDM32: | |
2545 | case BFD_RELOC_390_TLS_LDM64: | |
2546 | case BFD_RELOC_390_TLS_IE32: | |
2547 | case BFD_RELOC_390_TLS_IE64: | |
2548 | case BFD_RELOC_390_TLS_LE32: | |
2549 | case BFD_RELOC_390_TLS_LE64: | |
2550 | case BFD_RELOC_390_TLS_LDO32: | |
2551 | case BFD_RELOC_390_TLS_LDO64: | |
2552 | case BFD_RELOC_390_TLS_DTPMOD: | |
2553 | case BFD_RELOC_390_TLS_DTPOFF: | |
2554 | case BFD_RELOC_390_TLS_TPOFF: | |
7c1d0959 | 2555 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
1971b29d MS |
2556 | /* Fully resolved at link time. */ |
2557 | break; | |
2558 | case BFD_RELOC_390_TLS_IEENT: | |
2559 | /* Fully resolved at link time. */ | |
7c1d0959 | 2560 | S_SET_THREAD_LOCAL (fixP->fx_addsy); |
1971b29d MS |
2561 | value += 2; |
2562 | break; | |
2563 | ||
07855bec NC |
2564 | default: |
2565 | { | |
94f592af | 2566 | const char *reloc_name = bfd_get_reloc_code_name (fixP->fx_r_type); |
198ce79b | 2567 | |
07855bec | 2568 | if (reloc_name != NULL) |
20203fb9 | 2569 | as_fatal (_("Gas failure, reloc type %s\n"), reloc_name); |
07855bec | 2570 | else |
20203fb9 | 2571 | as_fatal (_("Gas failure, reloc type #%i\n"), fixP->fx_r_type); |
07855bec NC |
2572 | } |
2573 | } | |
a85d7ed0 | 2574 | |
94f592af | 2575 | fixP->fx_offset = value; |
07855bec | 2576 | } |
a85d7ed0 NC |
2577 | } |
2578 | ||
2579 | /* Generate a reloc for a fixup. */ | |
2580 | ||
2581 | arelent * | |
5a49b8ac | 2582 | tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) |
a85d7ed0 NC |
2583 | { |
2584 | bfd_reloc_code_real_type code; | |
2585 | arelent *reloc; | |
2586 | ||
2587 | code = fixp->fx_r_type; | |
07855bec NC |
2588 | if (GOT_symbol && fixp->fx_addsy == GOT_symbol) |
2589 | { | |
16a419ba NC |
2590 | if ( (s390_arch_size == 32 && code == BFD_RELOC_32_PCREL) |
2591 | || (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL)) | |
07855bec NC |
2592 | code = BFD_RELOC_390_GOTPC; |
2593 | if (code == BFD_RELOC_390_PC32DBL) | |
2594 | code = BFD_RELOC_390_GOTPCDBL; | |
2595 | } | |
a85d7ed0 | 2596 | |
325801bd TS |
2597 | reloc = XNEW (arelent); |
2598 | reloc->sym_ptr_ptr = XNEW (asymbol *); | |
a85d7ed0 NC |
2599 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
2600 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
2601 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
2602 | if (reloc->howto == NULL) | |
2603 | { | |
2604 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
98d3f06f KH |
2605 | _("cannot represent relocation type %s"), |
2606 | bfd_get_reloc_code_name (code)); | |
a85d7ed0 NC |
2607 | /* Set howto to a garbage value so that we can keep going. */ |
2608 | reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); | |
9c2799c2 | 2609 | gas_assert (reloc->howto != NULL); |
a85d7ed0 NC |
2610 | } |
2611 | reloc->addend = fixp->fx_offset; | |
2612 | ||
2613 | return reloc; | |
2614 | } | |
75e21f08 JJ |
2615 | |
2616 | void | |
5a49b8ac | 2617 | s390_cfi_frame_initial_instructions (void) |
75e21f08 JJ |
2618 | { |
2619 | cfi_add_CFA_def_cfa (15, s390_arch_size == 64 ? 160 : 96); | |
2620 | } | |
2621 | ||
2622 | int | |
1df69f4f | 2623 | tc_s390_regname_to_dw2regnum (char *regname) |
75e21f08 JJ |
2624 | { |
2625 | int regnum = -1; | |
2626 | ||
2627 | if (regname[0] != 'c' && regname[0] != 'a') | |
2628 | { | |
1e2e8c52 | 2629 | regnum = reg_name_search (regname); |
75e21f08 JJ |
2630 | if (regname[0] == 'f' && regnum != -1) |
2631 | regnum += 16; | |
2632 | } | |
2633 | else if (strcmp (regname, "ap") == 0) | |
2634 | regnum = 32; | |
2635 | else if (strcmp (regname, "cc") == 0) | |
2636 | regnum = 33; | |
2637 | return regnum; | |
2638 | } | |
55786da2 AK |
2639 | |
2640 | void | |
2641 | s390_elf_final_processing (void) | |
2642 | { | |
1dd53816 | 2643 | if (set_highgprs_p) |
55786da2 AK |
2644 | elf_elfheader (stdoutput)->e_flags |= EF_S390_HIGH_GPRS; |
2645 | } |