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