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