]>
Commit | Line | Data |
---|---|---|
a85d7ed0 | 1 | /* tc-s390.c -- Assemble for the S390 |
f7e42eb4 | 2 | Copyright 2000, 2001 Free Software Foundation, Inc. |
a85d7ed0 NC |
3 | Contributed by Martin Schwidefsky (schwidefsky@de.ibm.com). |
4 | ||
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GAS is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GAS; see the file COPYING. If not, write to the Free | |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
21 | ||
22 | #include <stdio.h> | |
a85d7ed0 | 23 | #include "as.h" |
3882b010 | 24 | #include "safe-ctype.h" |
a85d7ed0 NC |
25 | #include "subsegs.h" |
26 | #include "struc-symbol.h" | |
27 | ||
28 | #include "opcode/s390.h" | |
29 | #include "elf/s390.h" | |
30 | ||
31 | /* The default architecture */ | |
32 | #ifndef DEFAULT_ARCH | |
33 | #define DEFAULT_ARCH "s390" | |
34 | #endif | |
35 | static char *default_arch = DEFAULT_ARCH; | |
36 | /* Either 32 or 64, selects file format. */ | |
37 | static int s390_arch_size; | |
38 | /* Current architecture. Start with the smallest instruction set */ | |
39 | static enum s390_opcode_arch_val current_architecture = S390_OPCODE_ESA; | |
40 | static int current_arch_mask = 1 << S390_OPCODE_ESA; | |
41 | static int current_arch_requested = 0; | |
42 | ||
43 | /* Whether to use user friendly register names. Default is true. */ | |
44 | #ifndef TARGET_REG_NAMES_P | |
45 | #define TARGET_REG_NAMES_P true | |
46 | #endif | |
47 | ||
48 | static boolean reg_names_p = TARGET_REG_NAMES_P; | |
49 | ||
50 | /* Generic assembler global variables which must be defined by all | |
51 | targets. */ | |
52 | ||
53 | const char comment_chars[] = "#"; | |
54 | ||
55 | /* Characters which start a comment at the beginning of a line. */ | |
56 | const char line_comment_chars[] = "#"; | |
57 | ||
58 | /* Characters which may be used to separate multiple commands on a | |
59 | single line. */ | |
60 | const char line_separator_chars[] = ";"; | |
61 | ||
62 | /* Characters which are used to indicate an exponent in a floating | |
63 | point number. */ | |
64 | const char EXP_CHARS[] = "eE"; | |
65 | ||
66 | /* Characters which mean that a number is a floating point constant, | |
67 | as in 0d1.0. */ | |
68 | const char FLT_CHARS[] = "dD"; | |
69 | ||
70 | /* The target specific pseudo-ops which we support. */ | |
71 | ||
72 | /* Define the prototypes for the pseudo-ops */ | |
73 | static void s390_byte PARAMS ((int)); | |
74 | static void s390_elf_cons PARAMS ((int)); | |
75 | static void s390_bss PARAMS ((int)); | |
76 | static void s390_insn PARAMS ((int)); | |
77 | static void s390_literals PARAMS ((int)); | |
78 | ||
79 | const pseudo_typeS md_pseudo_table[] = | |
80 | { | |
81 | { "align", s_align_bytes, 0 }, | |
82 | /* Pseudo-ops which must be defined. */ | |
198ce79b | 83 | { "bss", s390_bss, 0 }, |
a85d7ed0 NC |
84 | { "insn", s390_insn, 0 }, |
85 | /* Pseudo-ops which must be overridden. */ | |
86 | { "byte", s390_byte, 0 }, | |
87 | { "short", s390_elf_cons, 2 }, | |
88 | { "long", s390_elf_cons, 4 }, | |
89 | { "quad", s390_elf_cons, 8 }, | |
90 | { "ltorg", s390_literals, 0 }, | |
91 | { "string", stringer, 2 }, | |
92 | { NULL, NULL, 0 } | |
93 | }; | |
94 | ||
95 | ||
96 | /* Structure to hold information about predefined registers. */ | |
97 | struct pd_reg | |
98 | { | |
99 | char *name; | |
100 | int value; | |
101 | }; | |
102 | ||
103 | /* List of registers that are pre-defined: | |
104 | ||
105 | Each access register has a predefined name of the form: | |
106 | a<reg_num> which has the value <reg_num>. | |
107 | ||
108 | Each control register has a predefined name of the form: | |
109 | c<reg_num> which has the value <reg_num>. | |
110 | ||
111 | Each general register has a predefined name of the form: | |
112 | r<reg_num> which has the value <reg_num>. | |
113 | ||
114 | Each floating point register a has predefined name of the form: | |
115 | f<reg_num> which has the value <reg_num>. | |
116 | ||
117 | There are individual registers as well: | |
118 | sp has the value 15 | |
119 | lit has the value 12 | |
120 | ||
121 | The table is sorted. Suitable for searching by a binary search. */ | |
122 | ||
123 | static const struct pd_reg pre_defined_registers[] = | |
124 | { | |
125 | { "a0", 0 }, /* Access registers */ | |
126 | { "a1", 1 }, | |
127 | { "a10", 10 }, | |
128 | { "a11", 11 }, | |
129 | { "a12", 12 }, | |
130 | { "a13", 13 }, | |
131 | { "a14", 14 }, | |
132 | { "a15", 15 }, | |
133 | { "a2", 2 }, | |
134 | { "a3", 3 }, | |
135 | { "a4", 4 }, | |
136 | { "a5", 5 }, | |
137 | { "a6", 6 }, | |
138 | { "a7", 7 }, | |
139 | { "a8", 8 }, | |
140 | { "a9", 9 }, | |
141 | ||
142 | { "c0", 0 }, /* Control registers */ | |
143 | { "c1", 1 }, | |
144 | { "c10", 10 }, | |
145 | { "c11", 11 }, | |
146 | { "c12", 12 }, | |
147 | { "c13", 13 }, | |
148 | { "c14", 14 }, | |
149 | { "c15", 15 }, | |
150 | { "c2", 2 }, | |
151 | { "c3", 3 }, | |
152 | { "c4", 4 }, | |
153 | { "c5", 5 }, | |
154 | { "c6", 6 }, | |
155 | { "c7", 7 }, | |
156 | { "c8", 8 }, | |
157 | { "c9", 9 }, | |
158 | ||
159 | { "f0", 0 }, /* Floating point registers */ | |
198ce79b AJ |
160 | { "f1", 1 }, |
161 | { "f10", 10 }, | |
162 | { "f11", 11 }, | |
163 | { "f12", 12 }, | |
164 | { "f13", 13 }, | |
165 | { "f14", 14 }, | |
166 | { "f15", 15 }, | |
167 | { "f2", 2 }, | |
168 | { "f3", 3 }, | |
169 | { "f4", 4 }, | |
170 | { "f5", 5 }, | |
171 | { "f6", 6 }, | |
172 | { "f7", 7 }, | |
173 | { "f8", 8 }, | |
174 | { "f9", 9 }, | |
a85d7ed0 NC |
175 | |
176 | { "lit", 13 }, /* Pointer to literal pool */ | |
177 | ||
178 | { "r0", 0 }, /* General purpose registers */ | |
179 | { "r1", 1 }, | |
180 | { "r10", 10 }, | |
181 | { "r11", 11 }, | |
182 | { "r12", 12 }, | |
183 | { "r13", 13 }, | |
184 | { "r14", 14 }, | |
185 | { "r15", 15 }, | |
186 | { "r2", 2 }, | |
187 | { "r3", 3 }, | |
188 | { "r4", 4 }, | |
189 | { "r5", 5 }, | |
190 | { "r6", 6 }, | |
191 | { "r7", 7 }, | |
192 | { "r8", 8 }, | |
193 | { "r9", 9 }, | |
194 | ||
195 | { "sp", 15 }, /* Stack pointer */ | |
196 | ||
197 | }; | |
198 | ||
07726851 | 199 | #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg)) |
a85d7ed0 | 200 | |
9d654c1c AJ |
201 | static int reg_name_search |
202 | PARAMS ((const struct pd_reg *, int, const char *)); | |
203 | static boolean register_name PARAMS ((expressionS *)); | |
204 | static void init_default_arch PARAMS ((void)); | |
205 | static void s390_insert_operand | |
206 | PARAMS ((unsigned char *, const struct s390_operand *, offsetT, char *, | |
207 | unsigned int)); | |
208 | static char *md_gather_operands | |
209 | PARAMS ((char *, unsigned char *, const struct s390_opcode *)); | |
210 | ||
a85d7ed0 NC |
211 | /* Given NAME, find the register number associated with that name, return |
212 | the integer value associated with the given name or -1 on failure. */ | |
213 | ||
214 | static int | |
215 | reg_name_search (regs, regcount, name) | |
216 | const struct pd_reg *regs; | |
217 | int regcount; | |
218 | const char *name; | |
219 | { | |
220 | int middle, low, high; | |
221 | int cmp; | |
222 | ||
223 | low = 0; | |
224 | high = regcount - 1; | |
225 | ||
226 | do | |
227 | { | |
228 | middle = (low + high) / 2; | |
229 | cmp = strcasecmp (name, regs[middle].name); | |
230 | if (cmp < 0) | |
231 | high = middle - 1; | |
232 | else if (cmp > 0) | |
233 | low = middle + 1; | |
234 | else | |
235 | return regs[middle].value; | |
236 | } | |
237 | while (low <= high); | |
238 | ||
239 | return -1; | |
240 | } | |
241 | ||
242 | ||
243 | /* | |
244 | * Summary of register_name(). | |
245 | * | |
246 | * in: Input_line_pointer points to 1st char of operand. | |
247 | * | |
248 | * out: A expressionS. | |
249 | * The operand may have been a register: in this case, X_op == O_register, | |
250 | * X_add_number is set to the register number, and truth is returned. | |
251 | * Input_line_pointer->(next non-blank) char after operand, or is in its | |
252 | * original state. | |
253 | */ | |
254 | ||
255 | static boolean | |
256 | register_name (expressionP) | |
257 | expressionS *expressionP; | |
258 | { | |
259 | int reg_number; | |
260 | char *name; | |
261 | char *start; | |
262 | char c; | |
263 | ||
468cced8 | 264 | /* Find the spelling of the operand. */ |
a85d7ed0 | 265 | start = name = input_line_pointer; |
3882b010 | 266 | if (name[0] == '%' && ISALPHA (name[1])) |
a85d7ed0 NC |
267 | name = ++input_line_pointer; |
268 | else | |
269 | return false; | |
270 | ||
271 | c = get_symbol_end (); | |
272 | reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name); | |
273 | ||
468cced8 AM |
274 | /* Put back the delimiting char. */ |
275 | *input_line_pointer = c; | |
276 | ||
277 | /* Look to see if it's in the register table. */ | |
198ce79b | 278 | if (reg_number >= 0) |
a85d7ed0 NC |
279 | { |
280 | expressionP->X_op = O_register; | |
281 | expressionP->X_add_number = reg_number; | |
198ce79b | 282 | |
468cced8 | 283 | /* Make the rest nice. */ |
a85d7ed0 NC |
284 | expressionP->X_add_symbol = NULL; |
285 | expressionP->X_op_symbol = NULL; | |
a85d7ed0 NC |
286 | return true; |
287 | } | |
468cced8 AM |
288 | |
289 | /* Reset the line as if we had not done anything. */ | |
290 | input_line_pointer = start; | |
291 | return false; | |
a85d7ed0 NC |
292 | } |
293 | ||
294 | /* Local variables. */ | |
295 | ||
296 | /* Opformat hash table. */ | |
297 | static struct hash_control *s390_opformat_hash; | |
298 | ||
299 | /* Opcode hash table. */ | |
300 | static struct hash_control *s390_opcode_hash; | |
301 | ||
302 | /* Flags to set in the elf header */ | |
303 | static flagword s390_flags = 0; | |
304 | ||
305 | symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */ | |
306 | ||
307 | #ifndef WORKING_DOT_WORD | |
308 | const int md_short_jump_size = 4; | |
309 | const int md_long_jump_size = 4; | |
310 | #endif | |
311 | ||
312 | CONST char *md_shortopts = "A:m:kVQ:"; | |
313 | struct option md_longopts[] = { | |
314 | {NULL, no_argument, NULL, 0} | |
315 | }; | |
07726851 | 316 | size_t md_longopts_size = sizeof (md_longopts); |
a85d7ed0 NC |
317 | |
318 | /* Initialize the default opcode arch and word size from the default | |
319 | architecture name. */ | |
320 | static void | |
321 | init_default_arch () | |
322 | { | |
323 | if (current_arch_requested) | |
324 | return; | |
07855bec | 325 | |
07726851 | 326 | if (strcmp (default_arch, "s390") == 0) |
07855bec NC |
327 | { |
328 | s390_arch_size = 32; | |
329 | current_architecture = S390_OPCODE_ESA; | |
330 | } | |
07726851 | 331 | else if (strcmp (default_arch, "s390x") == 0) |
07855bec NC |
332 | { |
333 | s390_arch_size = 64; | |
334 | current_architecture = S390_OPCODE_ESAME; | |
335 | } | |
336 | else | |
a85d7ed0 NC |
337 | as_fatal ("Invalid default architecture, broken assembler."); |
338 | current_arch_mask = 1 << current_architecture; | |
339 | } | |
340 | ||
341 | /* Called by TARGET_FORMAT. */ | |
342 | const char * | |
343 | s390_target_format () | |
344 | { | |
345 | /* We don't get a chance to initialize anything before we're called, | |
346 | so handle that now. */ | |
347 | if (! s390_arch_size) | |
348 | init_default_arch (); | |
349 | ||
350 | return s390_arch_size == 64 ? "elf64-s390" : "elf32-s390"; | |
351 | } | |
352 | ||
353 | int | |
354 | md_parse_option (c, arg) | |
355 | int c; | |
356 | char *arg; | |
357 | { | |
07855bec NC |
358 | switch (c) |
359 | { | |
360 | /* -k: Ignore for FreeBSD compatibility. */ | |
361 | case 'k': | |
362 | break; | |
363 | case 'm': | |
364 | if (arg != NULL && strcmp (arg, "regnames") == 0) | |
365 | reg_names_p = true; | |
198ce79b | 366 | |
07855bec NC |
367 | else if (arg != NULL && strcmp (arg, "no-regnames") == 0) |
368 | reg_names_p = false; | |
198ce79b | 369 | |
07855bec NC |
370 | else |
371 | { | |
372 | as_bad (_("invalid switch -m%s"), arg); | |
373 | return 0; | |
374 | } | |
375 | break; | |
198ce79b | 376 | |
07855bec NC |
377 | case 'A': |
378 | if (arg != NULL && strcmp (arg, "esa") == 0) | |
379 | { | |
380 | current_architecture = S390_OPCODE_ESA; | |
381 | s390_arch_size = 32; | |
382 | } | |
383 | else if (arg != NULL && strcmp (arg, "esame") == 0) | |
384 | { | |
385 | current_architecture = S390_OPCODE_ESAME; | |
386 | s390_arch_size = 64; | |
387 | } | |
388 | else | |
389 | as_bad ("invalid architecture -A%s", arg); | |
390 | current_arch_mask = 1 << current_architecture; | |
391 | current_arch_requested = 1; | |
392 | break; | |
393 | ||
394 | /* -V: SVR4 argument to print version ID. */ | |
395 | case 'V': | |
396 | print_version_id (); | |
397 | break; | |
198ce79b | 398 | |
07855bec NC |
399 | /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section |
400 | should be emitted or not. FIXME: Not implemented. */ | |
401 | case 'Q': | |
402 | break; | |
198ce79b | 403 | |
07855bec NC |
404 | default: |
405 | return 0; | |
406 | } | |
198ce79b | 407 | |
a85d7ed0 NC |
408 | return 1; |
409 | } | |
410 | ||
411 | void | |
412 | md_show_usage (stream) | |
413 | FILE *stream; | |
414 | { | |
07855bec | 415 | fprintf (stream, _("\ |
a85d7ed0 NC |
416 | S390 options:\n\ |
417 | -mregnames \tAllow symbolic names for registers\n\ | |
418 | -mno-regnames\tDo not allow symbolic names for registers\n")); | |
07855bec | 419 | fprintf (stream, _("\ |
a85d7ed0 NC |
420 | -V \tprint assembler version number\n\ |
421 | -Qy, -Qn \tignored\n")); | |
422 | } | |
423 | ||
424 | /* This function is called when the assembler starts up. It is called | |
425 | after the options have been parsed and the output file has been | |
426 | opened. */ | |
427 | ||
428 | void | |
429 | md_begin () | |
430 | { | |
431 | register const struct s390_opcode *op; | |
432 | const struct s390_opcode *op_end; | |
433 | boolean dup_insn = false; | |
434 | const char *retval; | |
435 | ||
436 | /* Set the ELF flags if desired. */ | |
437 | if (s390_flags) | |
438 | bfd_set_private_flags (stdoutput, s390_flags); | |
439 | ||
440 | /* Insert the opcode formats into a hash table. */ | |
441 | s390_opformat_hash = hash_new (); | |
442 | ||
443 | op_end = s390_opformats + s390_num_opformats; | |
07855bec NC |
444 | for (op = s390_opformats; op < op_end; op++) |
445 | { | |
446 | retval = hash_insert (s390_opformat_hash, op->name, (PTR) op); | |
447 | if (retval != (const char *) NULL) | |
448 | { | |
449 | as_bad (_("Internal assembler error for instruction format %s"), | |
450 | op->name); | |
451 | dup_insn = true; | |
452 | } | |
453 | } | |
a85d7ed0 NC |
454 | |
455 | /* Insert the opcodes into a hash table. */ | |
456 | s390_opcode_hash = hash_new (); | |
457 | ||
458 | op_end = s390_opcodes + s390_num_opcodes; | |
07855bec NC |
459 | for (op = s390_opcodes; op < op_end; op++) |
460 | { | |
461 | retval = hash_insert (s390_opcode_hash, op->name, (PTR) op); | |
462 | if (retval != (const char *) NULL) | |
463 | { | |
464 | as_bad (_("Internal assembler error for instruction %s"), op->name); | |
465 | dup_insn = true; | |
466 | } | |
467 | } | |
468 | ||
a85d7ed0 NC |
469 | if (dup_insn) |
470 | abort (); | |
471 | ||
472 | record_alignment (text_section, 2); | |
473 | record_alignment (data_section, 2); | |
474 | record_alignment (bss_section, 2); | |
475 | ||
476 | } | |
477 | ||
478 | /* Called after all assembly has been done. */ | |
479 | void | |
480 | s390_md_end () | |
481 | { | |
07855bec | 482 | if (s390_arch_size == 64) |
a85d7ed0 | 483 | bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_esame); |
07855bec | 484 | else |
a85d7ed0 | 485 | bfd_set_arch_mach (stdoutput, bfd_arch_s390, bfd_mach_s390_esa); |
a85d7ed0 NC |
486 | } |
487 | ||
488 | void | |
489 | s390_align_code (fragP, count) | |
490 | fragS *fragP; | |
491 | int count; | |
492 | { | |
493 | /* We use nop pattern 0x0707. */ | |
07855bec NC |
494 | if (count > 0) |
495 | { | |
07726851 | 496 | memset (fragP->fr_literal + fragP->fr_fix, 0x07, count); |
07855bec NC |
497 | fragP->fr_var = count; |
498 | } | |
a85d7ed0 NC |
499 | } |
500 | ||
501 | /* Insert an operand value into an instruction. */ | |
502 | ||
503 | static void | |
504 | s390_insert_operand (insn, operand, val, file, line) | |
505 | unsigned char *insn; | |
506 | const struct s390_operand *operand; | |
507 | offsetT val; | |
508 | char *file; | |
509 | unsigned int line; | |
510 | { | |
511 | addressT uval; | |
512 | int offset; | |
513 | ||
07855bec NC |
514 | if (operand->flags & (S390_OPERAND_SIGNED|S390_OPERAND_PCREL)) |
515 | { | |
516 | offsetT min, max; | |
517 | ||
518 | max = ((offsetT) 1 << (operand->bits - 1)) - 1; | |
519 | min = - ((offsetT) 1 << (operand->bits - 1)); | |
520 | /* Halve PCREL operands. */ | |
521 | if (operand->flags & S390_OPERAND_PCREL) | |
522 | val >>= 1; | |
523 | /* Check for underflow / overflow. */ | |
524 | if (val < min || val > max) | |
525 | { | |
526 | const char *err = | |
527 | "operand out of range (%s not between %ld and %ld)"; | |
528 | char buf[100]; | |
529 | ||
530 | if (operand->flags & S390_OPERAND_PCREL) | |
531 | { | |
532 | val <<= 1; | |
533 | min <<= 1; | |
534 | max <<= 1; | |
535 | } | |
536 | sprint_value (buf, val); | |
537 | if (file == (char *) NULL) | |
538 | as_bad (err, buf, (int) min, (int) max); | |
539 | else | |
540 | as_bad_where (file, line, err, buf, (int) min, (int) max); | |
541 | return; | |
542 | } | |
543 | /* val is ok, now restrict it to operand->bits bits. */ | |
544 | uval = (addressT) val & ((((addressT) 1 << (operand->bits-1)) << 1) - 1); | |
a85d7ed0 | 545 | } |
07855bec NC |
546 | else |
547 | { | |
548 | addressT min, max; | |
198ce79b | 549 | |
07855bec NC |
550 | max = (((addressT) 1 << (operand->bits - 1))<<1) - 1; |
551 | min = (offsetT) 0; | |
552 | uval = (addressT) val; | |
553 | /* Length x in an instructions has real length x+1. */ | |
554 | if (operand->flags & S390_OPERAND_LENGTH) | |
555 | uval--; | |
556 | /* Check for underflow / overflow. */ | |
557 | if (uval < min || uval > max) | |
558 | { | |
559 | const char *err = | |
560 | "operand out of range (%s not between %ld and %ld)"; | |
561 | char buf[100]; | |
198ce79b | 562 | |
07855bec NC |
563 | if (operand->flags & S390_OPERAND_LENGTH) |
564 | { | |
565 | uval++; | |
566 | min++; | |
567 | max++; | |
568 | } | |
569 | sprint_value (buf, uval); | |
570 | if (file == (char *) NULL) | |
571 | as_bad (err, buf, (int) min, (int) max); | |
572 | else | |
573 | as_bad_where (file, line, err, buf, (int) min, (int) max); | |
574 | return; | |
575 | } | |
a85d7ed0 | 576 | } |
a85d7ed0 NC |
577 | |
578 | /* Insert fragments of the operand byte for byte. */ | |
579 | offset = operand->shift + operand->bits; | |
580 | uval <<= (-offset) & 7; | |
581 | insn += (offset - 1)/8; | |
07855bec NC |
582 | while (uval != 0) |
583 | { | |
584 | *insn-- |= uval; | |
585 | uval >>= 8; | |
586 | } | |
a85d7ed0 NC |
587 | } |
588 | ||
589 | /* Structure used to hold suffixes. */ | |
07855bec NC |
590 | typedef enum |
591 | { | |
592 | ELF_SUFFIX_NONE = 0, | |
593 | ELF_SUFFIX_GOT, | |
594 | ELF_SUFFIX_PLT, | |
595 | ELF_SUFFIX_GOTENT | |
596 | } | |
597 | elf_suffix_type; | |
598 | ||
599 | struct map_bfd | |
600 | { | |
601 | char *string; | |
602 | int length; | |
603 | elf_suffix_type suffix; | |
604 | }; | |
a85d7ed0 | 605 | |
9d654c1c AJ |
606 | static elf_suffix_type s390_elf_suffix PARAMS ((char **, expressionS *)); |
607 | static int s390_exp_compare PARAMS ((expressionS *exp1, expressionS *exp2)); | |
608 | static elf_suffix_type s390_lit_suffix | |
609 | PARAMS ((char **, expressionS *, elf_suffix_type)); | |
610 | ||
611 | ||
a85d7ed0 NC |
612 | /* Parse @got/@plt/@gotoff. and return the desired relocation. */ |
613 | static elf_suffix_type | |
614 | s390_elf_suffix (str_p, exp_p) | |
615 | char **str_p; | |
616 | expressionS *exp_p; | |
617 | { | |
07855bec NC |
618 | static struct map_bfd mapping[] = |
619 | { | |
a85d7ed0 NC |
620 | { "got", 3, ELF_SUFFIX_GOT }, |
621 | { "got12", 5, ELF_SUFFIX_GOT }, | |
622 | { "plt", 3, ELF_SUFFIX_PLT }, | |
623 | { "gotent", 6, ELF_SUFFIX_GOTENT }, | |
624 | { NULL, 0, ELF_SUFFIX_NONE } | |
625 | }; | |
626 | ||
627 | struct map_bfd *ptr; | |
628 | char *str = *str_p; | |
629 | char *ident; | |
630 | int len; | |
631 | ||
632 | if (*str++ != '@') | |
633 | return ELF_SUFFIX_NONE; | |
634 | ||
635 | ident = str; | |
3882b010 | 636 | while (ISALNUM (*str)) |
a85d7ed0 NC |
637 | str++; |
638 | len = str - ident; | |
639 | ||
640 | for (ptr = &mapping[0]; ptr->length > 0; ptr++) | |
641 | if (len == ptr->length && | |
07726851 | 642 | strncasecmp (ident, ptr->string, ptr->length) == 0) |
07855bec NC |
643 | { |
644 | if (exp_p->X_add_number != 0) | |
645 | as_warn (_("identifier+constant@%s means identifier@%s+constant"), | |
646 | ptr->string, ptr->string); | |
647 | /* Now check for identifier@suffix+constant. */ | |
648 | if (*str == '-' || *str == '+') | |
649 | { | |
650 | char *orig_line = input_line_pointer; | |
651 | expressionS new_exp; | |
652 | ||
653 | input_line_pointer = str; | |
654 | expression (&new_exp); | |
655 | ||
656 | switch (new_exp.X_op) | |
657 | { | |
658 | case O_constant: /* X_add_number (a constant expression). */ | |
659 | exp_p->X_add_number += new_exp.X_add_number; | |
660 | str = input_line_pointer; | |
661 | break; | |
662 | case O_symbol: /* X_add_symbol + X_add_number. */ | |
663 | /* this case is used for e.g. xyz@PLT+.Label. */ | |
664 | exp_p->X_add_number += new_exp.X_add_number; | |
665 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
666 | exp_p->X_op = O_add; | |
667 | str = input_line_pointer; | |
668 | break; | |
669 | case O_uminus: /* (- X_add_symbol) + X_add_number. */ | |
670 | /* this case is used for e.g. xyz@PLT-.Label. */ | |
671 | exp_p->X_add_number += new_exp.X_add_number; | |
672 | exp_p->X_op_symbol = new_exp.X_add_symbol; | |
673 | exp_p->X_op = O_subtract; | |
674 | str = input_line_pointer; | |
675 | break; | |
676 | default: | |
677 | break; | |
678 | } | |
679 | ||
680 | /* If s390_elf_suffix has not been called with | |
681 | &input_line_pointer as first parameter, we have | |
682 | clobbered the input_line_pointer. We have to | |
683 | undo that. */ | |
684 | if (&input_line_pointer != str_p) | |
685 | input_line_pointer = orig_line; | |
a85d7ed0 | 686 | } |
07855bec NC |
687 | *str_p = str; |
688 | return ptr->suffix; | |
a85d7ed0 | 689 | } |
a85d7ed0 NC |
690 | |
691 | return BFD_RELOC_UNUSED; | |
692 | } | |
693 | ||
694 | /* Structure used to hold a literal pool entry. */ | |
07855bec NC |
695 | struct s390_lpe |
696 | { | |
697 | struct s390_lpe *next; | |
698 | expressionS ex; | |
699 | FLONUM_TYPE floatnum; /* used if X_op == O_big && X_add_number <= 0 */ | |
700 | LITTLENUM_TYPE bignum[4]; /* used if X_op == O_big && X_add_number > 0 */ | |
701 | int nbytes; | |
702 | bfd_reloc_code_real_type reloc; | |
703 | symbolS *sym; | |
704 | }; | |
a85d7ed0 NC |
705 | |
706 | static struct s390_lpe *lpe_free_list = NULL; | |
707 | static struct s390_lpe *lpe_list = NULL; | |
708 | static struct s390_lpe *lpe_list_tail = NULL; | |
709 | static symbolS *lp_sym = NULL; | |
710 | static int lp_count = 0; | |
711 | static int lpe_count = 0; | |
712 | ||
713 | static int | |
714 | s390_exp_compare(exp1, exp2) | |
715 | expressionS *exp1; | |
716 | expressionS *exp2; | |
717 | { | |
718 | if (exp1->X_op != exp2->X_op) | |
719 | return 0; | |
720 | ||
07855bec NC |
721 | switch (exp1->X_op) |
722 | { | |
723 | case O_constant: /* X_add_number must be equal. */ | |
724 | case O_register: | |
725 | return exp1->X_add_number == exp2->X_add_number; | |
726 | ||
727 | case O_big: | |
198ce79b | 728 | as_bad (_("Can't handle O_big in s390_exp_compare")); |
07855bec NC |
729 | |
730 | case O_symbol: /* X_add_symbol & X_add_number must be equal. */ | |
731 | case O_symbol_rva: | |
732 | case O_uminus: | |
733 | case O_bit_not: | |
734 | case O_logical_not: | |
735 | return (exp1->X_add_symbol == exp2->X_add_symbol) && | |
736 | (exp1->X_add_number == exp2->X_add_number); | |
737 | ||
738 | case O_multiply: /* X_add_symbol,X_op_symbol&X_add_number must be equal. */ | |
739 | case O_divide: | |
740 | case O_modulus: | |
741 | case O_left_shift: | |
742 | case O_right_shift: | |
743 | case O_bit_inclusive_or: | |
744 | case O_bit_or_not: | |
745 | case O_bit_exclusive_or: | |
746 | case O_bit_and: | |
747 | case O_add: | |
748 | case O_subtract: | |
749 | case O_eq: | |
750 | case O_ne: | |
751 | case O_lt: | |
752 | case O_le: | |
753 | case O_ge: | |
754 | case O_gt: | |
755 | case O_logical_and: | |
756 | case O_logical_or: | |
757 | return (exp1->X_add_symbol == exp2->X_add_symbol) && | |
758 | (exp1->X_op_symbol == exp2->X_op_symbol) && | |
759 | (exp1->X_add_number == exp2->X_add_number); | |
760 | default: | |
a85d7ed0 NC |
761 | return 0; |
762 | } | |
763 | } | |
764 | ||
765 | /* Test for @lit and if its present make an entry in the literal pool and | |
766 | modify the current expression to be an offset into the literal pool. */ | |
767 | static elf_suffix_type | |
768 | s390_lit_suffix (str_p, exp_p, suffix) | |
769 | char **str_p; | |
770 | expressionS *exp_p; | |
771 | elf_suffix_type suffix; | |
772 | { | |
773 | bfd_reloc_code_real_type reloc; | |
774 | char tmp_name[64]; | |
775 | char *str = *str_p; | |
776 | char *ident; | |
777 | struct s390_lpe *lpe; | |
778 | int nbytes, len; | |
779 | ||
780 | if (*str++ != ':') | |
781 | return suffix; /* No modification. */ | |
198ce79b | 782 | |
a85d7ed0 NC |
783 | /* We look for a suffix of the form "@lit1", "@lit2", "@lit4" or "@lit8". */ |
784 | ident = str; | |
3882b010 | 785 | while (ISALNUM (*str)) |
a85d7ed0 NC |
786 | str++; |
787 | len = str - ident; | |
07726851 | 788 | if (len != 4 || strncasecmp (ident, "lit", 3) != 0 || |
a85d7ed0 NC |
789 | (ident[3]!='1' && ident[3]!='2' && ident[3]!='4' && ident[3]!='8')) |
790 | return suffix; /* no modification */ | |
791 | nbytes = ident[3] - '0'; | |
792 | ||
793 | reloc = BFD_RELOC_UNUSED; | |
07855bec NC |
794 | if (suffix == ELF_SUFFIX_GOT) |
795 | { | |
796 | if (nbytes == 2) | |
797 | reloc = BFD_RELOC_390_GOT16; | |
798 | else if (nbytes == 4) | |
799 | reloc = BFD_RELOC_32_GOT_PCREL; | |
800 | else if (nbytes == 8) | |
801 | reloc = BFD_RELOC_390_GOT64; | |
802 | } | |
803 | else if (suffix == ELF_SUFFIX_PLT) | |
804 | { | |
805 | if (nbytes == 4) | |
806 | reloc = BFD_RELOC_390_PLT32; | |
807 | else if (nbytes == 8) | |
808 | reloc = BFD_RELOC_390_PLT64; | |
809 | } | |
a85d7ed0 | 810 | |
07855bec | 811 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) |
a85d7ed0 | 812 | as_bad (_("Invalid suffix for literal pool entry")); |
a85d7ed0 NC |
813 | |
814 | /* Search the pool if the new entry is a duplicate. */ | |
07855bec NC |
815 | if (exp_p->X_op == O_big) |
816 | { | |
817 | /* Special processing for big numbers. */ | |
818 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
819 | { | |
820 | if (lpe->ex.X_op == O_big) | |
821 | { | |
822 | if (exp_p->X_add_number <= 0 && lpe->ex.X_add_number <= 0) | |
823 | { | |
824 | if (memcmp (&generic_floating_point_number, &lpe->floatnum, | |
825 | sizeof (FLONUM_TYPE)) == 0) | |
826 | break; | |
827 | } | |
828 | else if (exp_p->X_add_number == lpe->ex.X_add_number) | |
829 | { | |
830 | if (memcmp (generic_bignum, lpe->bignum, | |
831 | sizeof (LITTLENUM_TYPE)*exp_p->X_add_number) == 0) | |
832 | break; | |
833 | } | |
834 | } | |
835 | } | |
a85d7ed0 | 836 | } |
07855bec NC |
837 | else |
838 | { | |
839 | /* Processing for 'normal' data types. */ | |
840 | for (lpe = lpe_list; lpe != NULL; lpe = lpe->next) | |
841 | if (lpe->nbytes == nbytes && lpe->reloc == reloc && | |
842 | s390_exp_compare(exp_p, &lpe->ex) != 0) | |
843 | break; | |
a85d7ed0 | 844 | } |
07855bec NC |
845 | |
846 | if (lpe == NULL) | |
847 | { | |
848 | /* A new literal. */ | |
849 | if (lpe_free_list != NULL) | |
850 | { | |
851 | lpe = lpe_free_list; | |
852 | lpe_free_list = lpe_free_list->next; | |
853 | } | |
a85d7ed0 | 854 | else |
07855bec | 855 | { |
07726851 | 856 | lpe = (struct s390_lpe *) xmalloc(sizeof (struct s390_lpe)); |
07855bec NC |
857 | } |
858 | ||
859 | lpe->ex = *exp_p; | |
860 | ||
861 | if (exp_p->X_op == O_big) | |
862 | { | |
863 | if (exp_p->X_add_number <= 0) | |
864 | lpe->floatnum = generic_floating_point_number; | |
865 | else if (exp_p->X_add_number <= 4) | |
866 | memcpy (lpe->bignum, generic_bignum, | |
07726851 | 867 | exp_p->X_add_number*sizeof (LITTLENUM_TYPE)); |
07855bec NC |
868 | else |
869 | as_bad (_("Big number is too big")); | |
870 | } | |
871 | ||
872 | lpe->nbytes = nbytes; | |
873 | lpe->reloc = reloc; | |
874 | /* Literal pool name defined ? */ | |
875 | if (lp_sym == NULL) | |
876 | { | |
07726851 | 877 | sprintf (tmp_name, ".L\001%i", lp_count); |
07855bec NC |
878 | lp_sym = symbol_make(tmp_name); |
879 | } | |
a85d7ed0 | 880 | |
07855bec | 881 | /* Make name for literal pool entry. */ |
07726851 | 882 | sprintf (tmp_name, ".L\001%i\002%i", lp_count, lpe_count); |
07855bec NC |
883 | lpe_count++; |
884 | lpe->sym = symbol_make(tmp_name); | |
885 | ||
886 | /* Add to literal pool list. */ | |
887 | lpe->next = NULL; | |
888 | if (lpe_list_tail != NULL) | |
889 | { | |
890 | lpe_list_tail->next = lpe; | |
891 | lpe_list_tail = lpe; | |
892 | } | |
893 | else | |
894 | lpe_list = lpe_list_tail = lpe; | |
895 | } | |
198ce79b | 896 | |
a85d7ed0 NC |
897 | /* Now change exp_p to the offset into the literal pool. |
898 | Thats the expression: .L^Ax^By-.L^Ax */ | |
899 | exp_p->X_add_symbol = lpe->sym; | |
900 | exp_p->X_op_symbol = lp_sym; | |
901 | exp_p->X_op = O_subtract; | |
902 | exp_p->X_add_number = 0; | |
903 | ||
904 | *str_p = str; | |
905 | ||
906 | /* We change the suffix type to ELF_SUFFIX_NONE, because | |
907 | the difference of two local labels is just a number. */ | |
908 | return ELF_SUFFIX_NONE; | |
909 | } | |
910 | ||
911 | /* Like normal .long/.short/.word, except support @got, etc. | |
912 | clobbers input_line_pointer, checks end-of-line. */ | |
913 | static void | |
914 | s390_elf_cons (nbytes) | |
915 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ | |
916 | { | |
917 | expressionS exp; | |
918 | elf_suffix_type suffix; | |
919 | ||
07855bec NC |
920 | if (is_it_end_of_statement ()) |
921 | { | |
922 | demand_empty_rest_of_line (); | |
923 | return; | |
924 | } | |
a85d7ed0 | 925 | |
07855bec NC |
926 | do |
927 | { | |
928 | expression (&exp); | |
929 | ||
930 | if (exp.X_op == O_symbol | |
931 | && *input_line_pointer == '@' | |
932 | && (suffix = s390_elf_suffix (&input_line_pointer, &exp)) != ELF_SUFFIX_NONE) | |
933 | { | |
934 | bfd_reloc_code_real_type reloc; | |
935 | reloc_howto_type *reloc_howto; | |
936 | int size; | |
937 | char *where; | |
938 | ||
939 | if (nbytes == 2 && suffix == ELF_SUFFIX_GOT) | |
940 | reloc = BFD_RELOC_390_GOT16; | |
941 | else if (nbytes == 4 && suffix == ELF_SUFFIX_GOT) | |
942 | reloc = BFD_RELOC_32_GOT_PCREL; | |
943 | else if (nbytes == 8 && suffix == ELF_SUFFIX_GOT) | |
944 | reloc = BFD_RELOC_390_GOT64; | |
945 | else if (nbytes == 4 && suffix == ELF_SUFFIX_PLT) | |
946 | reloc = BFD_RELOC_390_PLT32; | |
947 | else if (nbytes == 8 && suffix == ELF_SUFFIX_PLT) | |
948 | reloc = BFD_RELOC_390_PLT64; | |
949 | else | |
950 | reloc = BFD_RELOC_UNUSED; | |
951 | ||
952 | if (reloc != BFD_RELOC_UNUSED) | |
953 | { | |
954 | reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc); | |
955 | size = bfd_get_reloc_size (reloc_howto); | |
956 | if (size > nbytes) | |
957 | as_bad (_("%s relocations do not fit in %d bytes"), | |
958 | reloc_howto->name, nbytes); | |
07726851 | 959 | where = frag_more (nbytes); |
07855bec | 960 | md_number_to_chars (where, 0, size); |
198ce79b AJ |
961 | /* To make fixup_segment do the pc relative conversion the |
962 | pcrel parameter on the fix_new_exp call needs to be false. */ | |
963 | fix_new_exp (frag_now, where - frag_now->fr_literal, | |
964 | size, &exp, false, reloc); | |
07855bec NC |
965 | } |
966 | else | |
967 | as_bad (_("relocation not applicable")); | |
968 | } | |
a85d7ed0 | 969 | else |
07855bec NC |
970 | emit_expr (&exp, (unsigned int) nbytes); |
971 | } | |
972 | while (*input_line_pointer++ == ','); | |
a85d7ed0 NC |
973 | |
974 | input_line_pointer--; /* Put terminator back into stream. */ | |
975 | demand_empty_rest_of_line (); | |
976 | } | |
977 | ||
978 | /* We need to keep a list of fixups. We can't simply generate them as | |
979 | we go, because that would require us to first create the frag, and | |
980 | that would screw up references to ``.''. */ | |
981 | ||
982 | struct s390_fixup | |
07855bec NC |
983 | { |
984 | expressionS exp; | |
985 | int opindex; | |
986 | bfd_reloc_code_real_type reloc; | |
987 | }; | |
a85d7ed0 NC |
988 | |
989 | #define MAX_INSN_FIXUPS (4) | |
990 | ||
991 | /* This routine is called for each instruction to be assembled. */ | |
992 | ||
9d654c1c | 993 | static char * |
a85d7ed0 NC |
994 | md_gather_operands (str, insn, opcode) |
995 | char *str; | |
996 | unsigned char *insn; | |
997 | const struct s390_opcode *opcode; | |
998 | { | |
999 | struct s390_fixup fixups[MAX_INSN_FIXUPS]; | |
1000 | const struct s390_operand *operand; | |
1001 | const unsigned char *opindex_ptr; | |
1002 | elf_suffix_type suffix; | |
1003 | bfd_reloc_code_real_type reloc; | |
1004 | int skip_optional; | |
1005 | int parentheses; | |
1006 | char *f; | |
1007 | int fc, i; | |
1008 | ||
3882b010 | 1009 | while (ISSPACE (*str)) str++; |
a85d7ed0 NC |
1010 | |
1011 | parentheses = 0; | |
1012 | skip_optional = 0; | |
1013 | ||
1014 | /* Gather the operands. */ | |
1015 | fc = 0; | |
07855bec NC |
1016 | for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++) |
1017 | { | |
1018 | expressionS ex; | |
1019 | char *hold; | |
1020 | ||
1021 | operand = s390_operands + *opindex_ptr; | |
198ce79b | 1022 | |
07855bec NC |
1023 | if (skip_optional && (operand->flags & S390_OPERAND_INDEX)) |
1024 | { | |
1025 | /* We do an early skip. For D(X,B) constructions the index | |
198ce79b | 1026 | register is skipped (X is optional). For D(L,B) the base |
07855bec NC |
1027 | register will be the skipped operand, because L is NOT |
1028 | optional. */ | |
1029 | skip_optional = 0; | |
1030 | continue; | |
1031 | } | |
198ce79b | 1032 | |
07855bec NC |
1033 | /* Gather the operand. */ |
1034 | hold = input_line_pointer; | |
1035 | input_line_pointer = str; | |
1036 | ||
1037 | if (! register_name (&ex)) /* parse the operand */ | |
1038 | expression (&ex); | |
198ce79b | 1039 | |
07855bec NC |
1040 | str = input_line_pointer; |
1041 | input_line_pointer = hold; | |
198ce79b | 1042 | |
07855bec NC |
1043 | /* Write the operand to the insn. */ |
1044 | if (ex.X_op == O_illegal) | |
1045 | as_bad (_("illegal operand")); | |
1046 | else if (ex.X_op == O_absent) | |
1047 | as_bad (_("missing operand")); | |
1048 | else if (ex.X_op == O_register || ex.X_op == O_constant) | |
1049 | { | |
1050 | s390_lit_suffix (&str, &ex, ELF_SUFFIX_NONE); | |
1051 | ||
1052 | if (ex.X_op != O_register && ex.X_op != O_constant) | |
1053 | { | |
1054 | /* We need to generate a fixup for the | |
1055 | expression returned by s390_lit_suffix. */ | |
1056 | if (fc >= MAX_INSN_FIXUPS) | |
1057 | as_fatal (_("too many fixups")); | |
1058 | fixups[fc].exp = ex; | |
1059 | fixups[fc].opindex = *opindex_ptr; | |
1060 | fixups[fc].reloc = BFD_RELOC_UNUSED; | |
1061 | ++fc; | |
1062 | } | |
1063 | else | |
1064 | { | |
1065 | if ((operand->flags & S390_OPERAND_INDEX) && ex.X_add_number == 0) | |
07726851 | 1066 | as_warn ("index register specified but zero"); |
07855bec | 1067 | if ((operand->flags & S390_OPERAND_BASE) && ex.X_add_number == 0) |
07726851 | 1068 | as_warn ("base register specified but zero"); |
07855bec NC |
1069 | s390_insert_operand (insn, operand, ex.X_add_number, NULL, 0); |
1070 | } | |
1071 | } | |
1072 | else | |
1073 | { | |
1074 | suffix = s390_elf_suffix (&str, &ex); | |
1075 | suffix = s390_lit_suffix (&str, &ex, suffix); | |
1076 | reloc = BFD_RELOC_UNUSED; | |
1077 | ||
1078 | if (suffix == ELF_SUFFIX_GOT) | |
1079 | { | |
1080 | if (operand->flags & S390_OPERAND_DISP) | |
1081 | reloc = BFD_RELOC_390_GOT12; | |
1082 | else if ((operand->flags & S390_OPERAND_SIGNED) && | |
1083 | (operand->bits == 16)) | |
1084 | reloc = BFD_RELOC_390_GOT16; | |
1085 | else if ((operand->flags & S390_OPERAND_PCREL) && | |
1086 | (operand->bits == 32)) | |
1087 | reloc = BFD_RELOC_390_GOTENT; | |
1088 | } | |
1089 | else if (suffix == ELF_SUFFIX_PLT) | |
1090 | { | |
1091 | if ((operand->flags & S390_OPERAND_PCREL) && | |
1092 | (operand->bits == 16)) | |
1093 | reloc = BFD_RELOC_390_PLT16DBL; | |
1094 | else if ((operand->flags & S390_OPERAND_PCREL) && | |
1095 | (operand->bits == 32)) | |
1096 | reloc = BFD_RELOC_390_PLT32DBL; | |
1097 | } | |
1098 | else if (suffix == ELF_SUFFIX_GOTENT) | |
1099 | { | |
1100 | if ((operand->flags & S390_OPERAND_PCREL) && | |
1101 | (operand->bits == 32)) | |
1102 | reloc = BFD_RELOC_390_GOTENT; | |
1103 | } | |
1104 | ||
1105 | if (suffix != ELF_SUFFIX_NONE && reloc == BFD_RELOC_UNUSED) | |
1106 | as_bad (_("invalid operand suffix")); | |
1107 | /* We need to generate a fixup of type 'reloc' for this | |
1108 | expression. */ | |
a85d7ed0 NC |
1109 | if (fc >= MAX_INSN_FIXUPS) |
1110 | as_fatal (_("too many fixups")); | |
1111 | fixups[fc].exp = ex; | |
1112 | fixups[fc].opindex = *opindex_ptr; | |
07855bec | 1113 | fixups[fc].reloc = reloc; |
a85d7ed0 | 1114 | ++fc; |
07855bec | 1115 | } |
198ce79b | 1116 | |
07855bec NC |
1117 | /* Check the next character. The call to expression has advanced |
1118 | str past any whitespace. */ | |
1119 | if (operand->flags & S390_OPERAND_DISP) | |
1120 | { | |
1121 | /* After a displacement a block in parentheses can start. */ | |
1122 | if (*str != '(') | |
1123 | { | |
1124 | /* Check if parethesed block can be skipped. If the next | |
1125 | operand is neiter an optional operand nor a base register | |
1126 | then we have a syntax error. */ | |
1127 | operand = s390_operands + *(++opindex_ptr); | |
1128 | if (!(operand->flags & (S390_OPERAND_INDEX|S390_OPERAND_BASE))) | |
1129 | as_bad (_("syntax error; missing '(' after displacement")); | |
1130 | ||
1131 | /* Ok, skip all operands until S390_OPERAND_BASE. */ | |
1132 | while (!(operand->flags & S390_OPERAND_BASE)) | |
1133 | operand = s390_operands + *(++opindex_ptr); | |
198ce79b | 1134 | |
07855bec NC |
1135 | /* If there is a next operand it must be seperated by a comma. */ |
1136 | if (opindex_ptr[1] != '\0') | |
1137 | { | |
1138 | if (*str++ != ',') | |
07726851 | 1139 | as_bad (_("syntax error; expected ,")); |
07855bec NC |
1140 | } |
1141 | } | |
1142 | else | |
1143 | { | |
1144 | /* We found an opening parentheses. */ | |
1145 | str++; | |
1146 | for (f = str; *f != '\0'; f++) | |
1147 | if (*f == ',' || *f == ')') | |
1148 | break; | |
1149 | /* If there is no comma until the closing parentheses OR | |
1150 | there is a comma right after the opening parentheses, | |
1151 | we have to skip optional operands. */ | |
1152 | if (*f == ',' && f == str) | |
1153 | { | |
1154 | /* comma directly after '(' ? */ | |
1155 | skip_optional = 1; | |
1156 | str++; | |
1157 | } | |
1158 | else | |
1159 | skip_optional = (*f != ','); | |
1160 | } | |
1161 | } | |
1162 | else if (operand->flags & S390_OPERAND_BASE) | |
1163 | { | |
1164 | /* After the base register the parenthesed block ends. */ | |
1165 | if (*str++ != ')') | |
1166 | as_bad (_("syntax error; missing ')' after base register")); | |
1167 | skip_optional = 0; | |
1168 | /* If there is a next operand it must be seperated by a comma. */ | |
1169 | if (opindex_ptr[1] != '\0') | |
1170 | { | |
1171 | if (*str++ != ',') | |
1172 | as_bad (_("syntax error; expected ,")); | |
1173 | } | |
1174 | } | |
1175 | else | |
1176 | { | |
1177 | /* We can find an 'early' closing parentheses in e.g. D(L) instead | |
1178 | of D(L,B). In this case the base register has to be skipped. */ | |
1179 | if (*str == ')') | |
1180 | { | |
1181 | operand = s390_operands + *(++opindex_ptr); | |
1182 | ||
1183 | if (!(operand->flags & S390_OPERAND_BASE)) | |
1184 | as_bad (_("syntax error; ')' not allowed here")); | |
1185 | str++; | |
1186 | } | |
1187 | /* If there is a next operand it must be seperated by a comma. */ | |
1188 | if (opindex_ptr[1] != '\0') | |
1189 | { | |
1190 | if (*str++ != ',') | |
07726851 | 1191 | as_bad (_("syntax error; expected ,")); |
07855bec | 1192 | } |
a85d7ed0 | 1193 | } |
a85d7ed0 | 1194 | } |
a85d7ed0 | 1195 | |
3882b010 | 1196 | while (ISSPACE (*str)) |
a85d7ed0 NC |
1197 | ++str; |
1198 | ||
07855bec NC |
1199 | if (*str != '\0') |
1200 | { | |
1201 | char *linefeed; | |
a85d7ed0 | 1202 | |
07726851 | 1203 | if ((linefeed = strchr (str, '\n')) != NULL) |
07855bec NC |
1204 | *linefeed = '\0'; |
1205 | as_bad (_("junk at end of line: `%s'"), str); | |
1206 | if (linefeed != NULL) | |
1207 | *linefeed = '\n'; | |
1208 | } | |
a85d7ed0 NC |
1209 | |
1210 | /* Write out the instruction. */ | |
1211 | f = frag_more (opcode->oplen); | |
07855bec | 1212 | memcpy (f, insn, opcode->oplen); |
a85d7ed0 NC |
1213 | |
1214 | /* Create any fixups. At this point we do not use a | |
1215 | bfd_reloc_code_real_type, but instead just use the | |
1216 | BFD_RELOC_UNUSED plus the operand index. This lets us easily | |
1217 | handle fixups for any operand type, although that is admittedly | |
1218 | not a very exciting feature. We pick a BFD reloc type in | |
1219 | md_apply_fix3. */ | |
07855bec NC |
1220 | for (i = 0; i < fc; i++) |
1221 | { | |
1222 | operand = s390_operands + fixups[i].opindex; | |
a85d7ed0 | 1223 | |
07855bec NC |
1224 | if (fixups[i].reloc != BFD_RELOC_UNUSED) |
1225 | { | |
1226 | reloc_howto_type *reloc_howto; | |
1227 | fixS *fixP; | |
1228 | int size; | |
198ce79b | 1229 | |
07855bec NC |
1230 | reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc); |
1231 | if (!reloc_howto) | |
1232 | abort (); | |
198ce79b | 1233 | |
07855bec NC |
1234 | size = bfd_get_reloc_size (reloc_howto); |
1235 | ||
1236 | if (size < 1 || size > 4) | |
1237 | abort (); | |
198ce79b AJ |
1238 | |
1239 | fixP = fix_new_exp (frag_now, | |
1240 | f - frag_now->fr_literal + (operand->shift/8), | |
07855bec NC |
1241 | size, &fixups[i].exp, reloc_howto->pc_relative, |
1242 | fixups[i].reloc); | |
1243 | /* Turn off overflow checking in fixup_segment. This is necessary | |
1244 | because fixup_segment will signal an overflow for large 4 byte | |
1245 | quantities for GOT12 relocations. */ | |
1246 | if (fixups[i].reloc == BFD_RELOC_390_GOT12 || | |
1247 | fixups[i].reloc == BFD_RELOC_390_GOT16) | |
1248 | fixP->fx_no_overflow = 1; | |
1249 | } | |
1250 | else | |
1251 | fix_new_exp (frag_now, f - frag_now->fr_literal, 4, &fixups[i].exp, | |
1252 | (operand->flags & S390_OPERAND_PCREL) != 0, | |
1253 | ((bfd_reloc_code_real_type) | |
1254 | (fixups[i].opindex + (int) BFD_RELOC_UNUSED))); | |
1255 | } | |
a85d7ed0 NC |
1256 | return str; |
1257 | } | |
1258 | ||
1259 | /* This routine is called for each instruction to be assembled. */ | |
1260 | ||
1261 | void | |
1262 | md_assemble (str) | |
1263 | char *str; | |
1264 | { | |
1265 | const struct s390_opcode *opcode; | |
1266 | unsigned char insn[6]; | |
1267 | char *s; | |
1268 | ||
1269 | /* Get the opcode. */ | |
3882b010 | 1270 | for (s = str; *s != '\0' && ! ISSPACE (*s); s++) |
a85d7ed0 NC |
1271 | ; |
1272 | if (*s != '\0') | |
1273 | *s++ = '\0'; | |
1274 | ||
1275 | /* Look up the opcode in the hash table. */ | |
1276 | opcode = (struct s390_opcode *) hash_find (s390_opcode_hash, str); | |
07855bec NC |
1277 | if (opcode == (const struct s390_opcode *) NULL) |
1278 | { | |
1279 | as_bad (_("Unrecognized opcode: `%s'"), str); | |
1280 | return; | |
1281 | } | |
1282 | else if (!(opcode->architecture & current_arch_mask)) | |
1283 | { | |
07726851 | 1284 | as_bad ("Opcode %s not available in this architecture", str); |
07855bec NC |
1285 | return; |
1286 | } | |
a85d7ed0 | 1287 | |
07726851 | 1288 | memcpy (insn, opcode->opcode, sizeof (insn)); |
07855bec | 1289 | md_gather_operands (s, insn, opcode); |
a85d7ed0 NC |
1290 | } |
1291 | ||
1292 | #ifndef WORKING_DOT_WORD | |
1293 | /* Handle long and short jumps. We don't support these */ | |
1294 | void | |
1295 | md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1296 | char *ptr; | |
1297 | addressT from_addr, to_addr; | |
1298 | fragS *frag; | |
1299 | symbolS *to_symbol; | |
1300 | { | |
1301 | abort (); | |
1302 | } | |
1303 | ||
1304 | void | |
1305 | md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol) | |
1306 | char *ptr; | |
1307 | addressT from_addr, to_addr; | |
1308 | fragS *frag; | |
1309 | symbolS *to_symbol; | |
1310 | { | |
1311 | abort (); | |
1312 | } | |
1313 | #endif | |
1314 | ||
1315 | void | |
1316 | s390_bss (ignore) | |
1317 | int ignore ATTRIBUTE_UNUSED; | |
1318 | { | |
1319 | /* We don't support putting frags in the BSS segment, we fake it | |
1320 | by marking in_bss, then looking at s_skip for clues. */ | |
1321 | ||
1322 | subseg_set (bss_section, 0); | |
1323 | demand_empty_rest_of_line (); | |
1324 | } | |
1325 | ||
1326 | /* Pseudo-op handling. */ | |
1327 | ||
1328 | void | |
07726851 | 1329 | s390_insn (ignore) |
a85d7ed0 NC |
1330 | int ignore ATTRIBUTE_UNUSED; |
1331 | { | |
1332 | expressionS exp; | |
1333 | const struct s390_opcode *opformat; | |
1334 | unsigned char insn[6]; | |
1335 | char *s; | |
1336 | ||
1337 | /* Get the opcode format. */ | |
1338 | s = input_line_pointer; | |
3882b010 | 1339 | while (*s != '\0' && *s != ',' && ! ISSPACE (*s)) |
a85d7ed0 NC |
1340 | s++; |
1341 | if (*s != ',') | |
1342 | as_bad (_("Invalid .insn format\n")); | |
1343 | *s++ = '\0'; | |
1344 | ||
1345 | /* Look up the opcode in the hash table. */ | |
1346 | opformat = (struct s390_opcode *) | |
1347 | hash_find (s390_opformat_hash, input_line_pointer); | |
07855bec NC |
1348 | if (opformat == (const struct s390_opcode *) NULL) |
1349 | { | |
1350 | as_bad (_("Unrecognized opcode format: `%s'"), input_line_pointer); | |
1351 | return; | |
1352 | } | |
a85d7ed0 NC |
1353 | input_line_pointer = s; |
1354 | expression (&exp); | |
07855bec NC |
1355 | if (exp.X_op == O_constant) |
1356 | { | |
b6849f55 NC |
1357 | if ((opformat->oplen == 6 && exp.X_op > 0 && exp.X_op < (1ULL << 48)) || |
1358 | (opformat->oplen == 4 && exp.X_op > 0 && exp.X_op < (1ULL << 32)) || | |
1359 | (opformat->oplen == 2 && exp.X_op > 0 && exp.X_op < (1ULL << 16))) | |
07855bec NC |
1360 | md_number_to_chars (insn, exp.X_add_number, opformat->oplen); |
1361 | else | |
07726851 | 1362 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1363 | } |
1364 | else if (exp.X_op == O_big) | |
1365 | { | |
198ce79b | 1366 | if (exp.X_add_number > 0 && |
07855bec NC |
1367 | opformat->oplen == 6 && |
1368 | generic_bignum[3] == 0) | |
1369 | { | |
1370 | md_number_to_chars (insn, generic_bignum[2], 2); | |
1371 | md_number_to_chars (&insn[2], generic_bignum[1], 2); | |
1372 | md_number_to_chars (&insn[4], generic_bignum[0], 2); | |
1373 | } | |
1374 | else | |
07726851 | 1375 | as_bad (_("Invalid .insn format\n")); |
07855bec NC |
1376 | } |
1377 | else | |
a85d7ed0 | 1378 | as_bad (_("second operand of .insn not a constant\n")); |
a85d7ed0 | 1379 | |
b6849f55 NC |
1380 | if (strcmp (opformat->name, "e") != 0 && *input_line_pointer++ != ',') |
1381 | as_bad (_("missing comma after insn constant\n")); | |
1382 | ||
07726851 | 1383 | if ((s = strchr (input_line_pointer, '\n')) != NULL) |
a85d7ed0 | 1384 | *s = '\0'; |
b6849f55 NC |
1385 | input_line_pointer = md_gather_operands (input_line_pointer, insn, |
1386 | opformat); | |
a85d7ed0 NC |
1387 | if (s != NULL) |
1388 | *s = '\n'; | |
1389 | demand_empty_rest_of_line (); | |
1390 | } | |
1391 | ||
1392 | /* The .byte pseudo-op. This is similar to the normal .byte | |
1393 | pseudo-op, but it can also take a single ASCII string. */ | |
1394 | ||
1395 | static void | |
1396 | s390_byte (ignore) | |
1397 | int ignore ATTRIBUTE_UNUSED; | |
1398 | { | |
1399 | if (*input_line_pointer != '\"') | |
1400 | { | |
1401 | cons (1); | |
1402 | return; | |
1403 | } | |
1404 | ||
1405 | /* Gather characters. A real double quote is doubled. Unusual | |
1406 | characters are not permitted. */ | |
1407 | ++input_line_pointer; | |
1408 | while (1) | |
1409 | { | |
1410 | char c; | |
1411 | ||
1412 | c = *input_line_pointer++; | |
1413 | ||
1414 | if (c == '\"') | |
1415 | { | |
1416 | if (*input_line_pointer != '\"') | |
1417 | break; | |
1418 | ++input_line_pointer; | |
1419 | } | |
1420 | ||
1421 | FRAG_APPEND_1_CHAR (c); | |
1422 | } | |
1423 | ||
1424 | demand_empty_rest_of_line (); | |
1425 | } | |
1426 | ||
1427 | /* The .ltorg pseudo-op.This emits all literals defined since the last | |
198ce79b | 1428 | .ltorg or the invocation of gas. Literals are defined with the |
a85d7ed0 NC |
1429 | @lit suffix. */ |
1430 | ||
1431 | static void | |
1432 | s390_literals (ignore) | |
1433 | int ignore ATTRIBUTE_UNUSED; | |
1434 | { | |
1435 | struct s390_lpe *lpe; | |
1436 | ||
1437 | if (lp_sym == NULL || lpe_count == 0) | |
1438 | return; /* nothing to be done */ | |
1439 | ||
1440 | /* Emit symbol for start of literal pool. */ | |
1441 | S_SET_SEGMENT (lp_sym, now_seg); | |
1442 | S_SET_VALUE (lp_sym, (valueT) frag_now_fix ()); | |
1443 | lp_sym->sy_frag = frag_now; | |
1444 | ||
07855bec NC |
1445 | while (lpe_list) |
1446 | { | |
1447 | lpe = lpe_list; | |
1448 | lpe_list = lpe_list->next; | |
1449 | S_SET_SEGMENT (lpe->sym, now_seg); | |
1450 | S_SET_VALUE (lpe->sym, (valueT) frag_now_fix ()); | |
1451 | lpe->sym->sy_frag = frag_now; | |
1452 | ||
1453 | /* Emit literal pool entry. */ | |
1454 | if (lpe->reloc != BFD_RELOC_UNUSED) | |
1455 | { | |
198ce79b | 1456 | reloc_howto_type *reloc_howto = |
07855bec NC |
1457 | bfd_reloc_type_lookup (stdoutput, lpe->reloc); |
1458 | int size = bfd_get_reloc_size (reloc_howto); | |
1459 | char *where; | |
1460 | ||
1461 | if (size > lpe->nbytes) | |
1462 | as_bad (_("%s relocations do not fit in %d bytes"), | |
1463 | reloc_howto->name, lpe->nbytes); | |
07726851 | 1464 | where = frag_more (lpe->nbytes); |
07855bec NC |
1465 | md_number_to_chars (where, 0, size); |
1466 | fix_new_exp (frag_now, where - frag_now->fr_literal, | |
1467 | size, &lpe->ex, reloc_howto->pc_relative, lpe->reloc); | |
1468 | } | |
1469 | else | |
1470 | { | |
1471 | if (lpe->ex.X_op == O_big) | |
1472 | { | |
1473 | if (lpe->ex.X_add_number <= 0) | |
1474 | generic_floating_point_number = lpe->floatnum; | |
1475 | else | |
1476 | memcpy (generic_bignum, lpe->bignum, | |
07726851 | 1477 | lpe->ex.X_add_number*sizeof (LITTLENUM_TYPE)); |
07855bec NC |
1478 | } |
1479 | emit_expr (&lpe->ex, lpe->nbytes); | |
1480 | } | |
a85d7ed0 | 1481 | |
07855bec NC |
1482 | lpe->next = lpe_free_list; |
1483 | lpe_free_list = lpe; | |
1484 | } | |
a85d7ed0 NC |
1485 | lpe_list_tail = NULL; |
1486 | lp_sym = NULL; | |
1487 | lp_count++; | |
1488 | lpe_count = 0; | |
1489 | } | |
1490 | ||
1491 | /* Turn a string in input_line_pointer into a floating point constant | |
1492 | of type type, and store the appropriate bytes in *litp. The number | |
1493 | of LITTLENUMS emitted is stored in *sizep . An error message is | |
1494 | returned, or NULL on OK. */ | |
1495 | ||
1496 | char * | |
1497 | md_atof (type, litp, sizep) | |
1498 | int type; | |
1499 | char *litp; | |
1500 | int *sizep; | |
1501 | { | |
1502 | int prec; | |
1503 | LITTLENUM_TYPE words[4]; | |
1504 | char *t; | |
1505 | int i; | |
1506 | ||
1507 | switch (type) | |
1508 | { | |
1509 | case 'f': | |
1510 | prec = 2; | |
1511 | break; | |
1512 | ||
1513 | case 'd': | |
1514 | prec = 4; | |
1515 | break; | |
1516 | ||
1517 | default: | |
1518 | *sizep = 0; | |
1519 | return "bad call to md_atof"; | |
1520 | } | |
1521 | ||
1522 | t = atof_ieee (input_line_pointer, type, words); | |
1523 | if (t) | |
1524 | input_line_pointer = t; | |
1525 | ||
1526 | *sizep = prec * 2; | |
1527 | ||
1528 | for (i = 0; i < prec; i++) | |
1529 | { | |
1530 | md_number_to_chars (litp, (valueT) words[i], 2); | |
1531 | litp += 2; | |
1532 | } | |
198ce79b | 1533 | |
a85d7ed0 NC |
1534 | return NULL; |
1535 | } | |
1536 | ||
1537 | /* Align a section (I don't know why this is machine dependent). */ | |
1538 | ||
1539 | valueT | |
1540 | md_section_align (seg, addr) | |
1541 | asection *seg; | |
1542 | valueT addr; | |
1543 | { | |
1544 | int align = bfd_get_section_alignment (stdoutput, seg); | |
1545 | ||
1546 | return ((addr + (1 << align) - 1) & (-1 << align)); | |
1547 | } | |
1548 | ||
1549 | /* We don't have any form of relaxing. */ | |
1550 | ||
1551 | int | |
1552 | md_estimate_size_before_relax (fragp, seg) | |
1553 | fragS *fragp ATTRIBUTE_UNUSED; | |
1554 | asection *seg ATTRIBUTE_UNUSED; | |
1555 | { | |
1556 | abort (); | |
1557 | return 0; | |
1558 | } | |
1559 | ||
1560 | /* Convert a machine dependent frag. We never generate these. */ | |
1561 | ||
1562 | void | |
1563 | md_convert_frag (abfd, sec, fragp) | |
1564 | bfd *abfd ATTRIBUTE_UNUSED; | |
1565 | asection *sec ATTRIBUTE_UNUSED; | |
1566 | fragS *fragp ATTRIBUTE_UNUSED; | |
1567 | { | |
1568 | abort (); | |
1569 | } | |
1570 | ||
1571 | symbolS * | |
1572 | md_undefined_symbol (name) | |
1573 | char *name; | |
1574 | { | |
1575 | if (*name == '_' && *(name+1) == 'G' | |
07726851 | 1576 | && strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) |
a85d7ed0 | 1577 | { |
07726851 | 1578 | if (!GOT_symbol) |
a85d7ed0 | 1579 | { |
07726851 KH |
1580 | if (symbol_find (name)) |
1581 | as_bad (_("GOT already in symbol table")); | |
a85d7ed0 NC |
1582 | GOT_symbol = symbol_new (name, undefined_section, |
1583 | (valueT) 0, &zero_address_frag); | |
1584 | } | |
1585 | return GOT_symbol; | |
1586 | } | |
1587 | return 0; | |
1588 | } | |
1589 | ||
1590 | /* Functions concerning relocs. */ | |
1591 | ||
1592 | /* The location from which a PC relative jump should be calculated, | |
1593 | given a PC relative reloc. */ | |
1594 | ||
1595 | long | |
1596 | md_pcrel_from_section (fixp, sec) | |
1597 | fixS *fixp; | |
1598 | segT sec ATTRIBUTE_UNUSED; | |
1599 | { | |
1600 | return fixp->fx_frag->fr_address + fixp->fx_where; | |
1601 | } | |
1602 | ||
1603 | /* Here we decide which fixups can be adjusted to make them relative to | |
1604 | the beginning of the section instead of the symbol. Basically we need | |
1605 | to make sure that the dynamic relocations are done correctly, so in | |
1606 | some cases we force the original symbol to be used. */ | |
1607 | int | |
1608 | tc_s390_fix_adjustable(fixP) | |
1609 | fixS * fixP; | |
1610 | { | |
1611 | /* Prevent all adjustments to global symbols. */ | |
1612 | if (S_IS_EXTERN (fixP->fx_addsy)) | |
1613 | return 0; | |
1614 | if (S_IS_WEAK (fixP->fx_addsy)) | |
1615 | return 0; | |
1616 | /* adjust_reloc_syms doesn't know about the GOT. */ | |
1617 | if (fixP->fx_r_type == BFD_RELOC_32_GOTOFF | |
1618 | || fixP->fx_r_type == BFD_RELOC_390_PLT16DBL | |
1619 | || fixP->fx_r_type == BFD_RELOC_390_PLT32 | |
1620 | || fixP->fx_r_type == BFD_RELOC_390_PLT32DBL | |
1621 | || fixP->fx_r_type == BFD_RELOC_390_PLT64 | |
1622 | || fixP->fx_r_type == BFD_RELOC_390_GOT12 | |
1623 | || fixP->fx_r_type == BFD_RELOC_390_GOT16 | |
1624 | || fixP->fx_r_type == BFD_RELOC_32_GOT_PCREL | |
1625 | || fixP->fx_r_type == BFD_RELOC_390_GOT64 | |
07855bec | 1626 | || fixP->fx_r_type == BFD_RELOC_390_GOTENT |
a85d7ed0 NC |
1627 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT |
1628 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
1629 | return 0; | |
1630 | return 1; | |
1631 | } | |
1632 | ||
1633 | /* Apply a fixup to the object code. This is called for all the | |
1634 | fixups we generated by the call to fix_new_exp, above. In the call | |
1635 | above we used a reloc code which was the largest legal reloc code | |
1636 | plus the operand index. Here we undo that to recover the operand | |
1637 | index. At this point all symbol values should be fully resolved, | |
1638 | and we attempt to completely resolve the reloc. If we can not do | |
1639 | that, we determine the correct reloc code and put it back in the | |
1640 | fixup. */ | |
1641 | ||
1642 | int | |
1643 | md_apply_fix3 (fixp, valuep, seg) | |
1644 | fixS *fixp; | |
1645 | valueT *valuep; | |
1646 | segT seg ATTRIBUTE_UNUSED; | |
1647 | { | |
1648 | char *where; | |
1649 | valueT value; | |
1650 | ||
1651 | value = *valuep; | |
1652 | where = fixp->fx_frag->fr_literal + fixp->fx_where; | |
1653 | ||
07855bec NC |
1654 | if (fixp->fx_subsy != NULL) |
1655 | { | |
1656 | if (!S_IS_DEFINED (fixp->fx_subsy)) | |
a85d7ed0 | 1657 | as_bad_where (fixp->fx_file, fixp->fx_line, |
07855bec NC |
1658 | _("unresolved fx_subsy symbol that must be resolved")); |
1659 | value -= S_GET_VALUE(fixp->fx_subsy); | |
a85d7ed0 | 1660 | } |
a85d7ed0 | 1661 | |
07855bec NC |
1662 | if (fixp->fx_addsy != NULL) |
1663 | { | |
1664 | /* `*valuep' may contain the value of the symbol on which the reloc | |
1665 | will be based; we have to remove it. */ | |
1666 | if (fixp->fx_addsy->sy_used_in_reloc | |
1667 | && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section | |
1668 | && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section | |
1669 | && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy))) | |
1670 | value -= S_GET_VALUE (fixp->fx_addsy); | |
198ce79b | 1671 | |
a85d7ed0 | 1672 | if (fixp->fx_pcrel) |
07855bec NC |
1673 | value += fixp->fx_frag->fr_address + fixp->fx_where; |
1674 | } | |
1675 | else | |
1676 | fixp->fx_done = 1; | |
a85d7ed0 | 1677 | |
07855bec NC |
1678 | if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED) |
1679 | { | |
1680 | const struct s390_operand *operand; | |
1681 | int opindex; | |
198ce79b | 1682 | |
07855bec NC |
1683 | opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED; |
1684 | operand = &s390_operands[opindex]; | |
198ce79b | 1685 | |
a85d7ed0 | 1686 | if (fixp->fx_done) |
07855bec NC |
1687 | { |
1688 | /* Insert the fully resolved operand value. */ | |
1689 | s390_insert_operand (where, operand, (offsetT) value, | |
1690 | fixp->fx_file, fixp->fx_line); | |
a85d7ed0 | 1691 | |
07855bec NC |
1692 | return 1; |
1693 | } | |
198ce79b | 1694 | |
07855bec NC |
1695 | /* Determine a BFD reloc value based on the operand information. |
1696 | We are only prepared to turn a few of the operands into | |
1697 | relocs. */ | |
1698 | fixp->fx_offset = value; | |
1699 | if (operand->bits == 12 && operand->shift == 20) | |
1700 | { | |
1701 | fixp->fx_size = 2; | |
1702 | fixp->fx_where += 2; | |
1703 | fixp->fx_r_type = BFD_RELOC_390_12; | |
1704 | } | |
1705 | else if (operand->bits == 12 && operand->shift == 36) | |
1706 | { | |
1707 | fixp->fx_size = 2; | |
1708 | fixp->fx_where += 4; | |
1709 | fixp->fx_r_type = BFD_RELOC_390_12; | |
1710 | } | |
1711 | else if (operand->bits == 8 && operand->shift == 8) | |
1712 | { | |
1713 | fixp->fx_size = 1; | |
1714 | fixp->fx_where += 1; | |
1715 | fixp->fx_r_type = BFD_RELOC_8; | |
1716 | } | |
1717 | else if (operand->bits == 16 && operand->shift == 16) | |
1718 | { | |
1719 | fixp->fx_size = 2; | |
1720 | fixp->fx_where += 2; | |
1721 | if (operand->flags & S390_OPERAND_PCREL) | |
1722 | { | |
1723 | fixp->fx_r_type = BFD_RELOC_390_PC16DBL; | |
1724 | fixp->fx_offset += 2; | |
1725 | } | |
1726 | else | |
1727 | fixp->fx_r_type = BFD_RELOC_16; | |
1728 | } | |
1729 | else if (operand->bits == 32 && operand->shift == 16 && | |
1730 | (operand->flags & S390_OPERAND_PCREL)) | |
1731 | { | |
1732 | fixp->fx_size = 4; | |
1733 | fixp->fx_where += 2; | |
1734 | fixp->fx_offset += 2; | |
1735 | fixp->fx_r_type = BFD_RELOC_390_PC32DBL; | |
1736 | } | |
a85d7ed0 | 1737 | else |
07855bec NC |
1738 | { |
1739 | char *sfile; | |
1740 | unsigned int sline; | |
198ce79b | 1741 | |
07855bec NC |
1742 | /* Use expr_symbol_where to see if this is an expression |
1743 | symbol. */ | |
1744 | if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline)) | |
1745 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1746 | _("unresolved expression that must be resolved")); | |
1747 | else | |
1748 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1749 | _("unsupported relocation type")); | |
1750 | fixp->fx_done = 1; | |
1751 | return 1; | |
1752 | } | |
a85d7ed0 | 1753 | } |
07855bec NC |
1754 | else |
1755 | { | |
1756 | switch (fixp->fx_r_type) | |
1757 | { | |
1758 | case BFD_RELOC_8: | |
1759 | if (fixp->fx_pcrel) | |
1760 | abort (); | |
1761 | if (fixp->fx_done) | |
1762 | md_number_to_chars (where, value, 1); | |
1763 | break; | |
1764 | case BFD_RELOC_390_12: | |
1765 | case BFD_RELOC_390_GOT12: | |
1766 | if (fixp->fx_done) | |
1767 | { | |
1768 | unsigned short mop; | |
1769 | ||
1770 | mop = bfd_getb16 ((unsigned char *) where); | |
1771 | mop |= (unsigned short) (value & 0xfff); | |
1772 | bfd_putb16 ((bfd_vma) mop, (unsigned char *) where); | |
198ce79b | 1773 | } |
07855bec | 1774 | break; |
198ce79b | 1775 | |
07855bec NC |
1776 | case BFD_RELOC_16: |
1777 | case BFD_RELOC_GPREL16: | |
1778 | case BFD_RELOC_16_GOT_PCREL: | |
1779 | case BFD_RELOC_16_GOTOFF: | |
1780 | if (fixp->fx_pcrel) | |
1781 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1782 | "cannot emit PC relative %s relocation%s%s", | |
1783 | bfd_get_reloc_code_name (fixp->fx_r_type), | |
1784 | fixp->fx_addsy != NULL ? " against " : "", | |
1785 | (fixp->fx_addsy != NULL | |
1786 | ? S_GET_NAME (fixp->fx_addsy) | |
1787 | : "")); | |
1788 | if (fixp->fx_done) | |
1789 | md_number_to_chars (where, value, 2); | |
1790 | break; | |
1791 | case BFD_RELOC_390_GOT16: | |
1792 | if (fixp->fx_done) | |
1793 | md_number_to_chars (where, value, 2); | |
1794 | break; | |
1795 | case BFD_RELOC_390_PC16DBL: | |
1796 | case BFD_RELOC_390_PLT16DBL: | |
1797 | value += 2; | |
1798 | if (fixp->fx_done) | |
1799 | md_number_to_chars (where, (offsetT) value >> 1, 2); | |
1800 | break; | |
1801 | ||
1802 | case BFD_RELOC_32: | |
1803 | if (fixp->fx_pcrel) | |
1804 | fixp->fx_r_type = BFD_RELOC_32_PCREL; | |
1805 | else | |
1806 | fixp->fx_r_type = BFD_RELOC_32; | |
1807 | if (fixp->fx_done) | |
1808 | md_number_to_chars (where, value, 4); | |
1809 | break; | |
1810 | case BFD_RELOC_32_PCREL: | |
1811 | case BFD_RELOC_32_BASEREL: | |
1812 | fixp->fx_r_type = BFD_RELOC_32_PCREL; | |
1813 | if (fixp->fx_done) | |
1814 | md_number_to_chars (where, value, 4); | |
1815 | break; | |
1816 | case BFD_RELOC_32_GOT_PCREL: | |
1817 | case BFD_RELOC_390_PLT32: | |
1818 | if (fixp->fx_done) | |
1819 | md_number_to_chars (where, value, 4); | |
1820 | break; | |
1821 | case BFD_RELOC_390_PC32DBL: | |
1822 | case BFD_RELOC_390_PLT32DBL: | |
1823 | case BFD_RELOC_390_GOTPCDBL: | |
1824 | case BFD_RELOC_390_GOTENT: | |
1825 | value += 2; | |
1826 | if (fixp->fx_done) | |
1827 | md_number_to_chars (where, (offsetT) value >> 1, 4); | |
1828 | break; | |
1829 | ||
1830 | case BFD_RELOC_32_GOTOFF: | |
1831 | if (fixp->fx_done) | |
07726851 | 1832 | md_number_to_chars (where, value, sizeof (int)); |
07855bec NC |
1833 | break; |
1834 | ||
1835 | case BFD_RELOC_390_GOT64: | |
1836 | case BFD_RELOC_390_PLT64: | |
1837 | if (fixp->fx_done) | |
1838 | md_number_to_chars (where, value, 8); | |
1839 | break; | |
1840 | ||
1841 | case BFD_RELOC_64: | |
1842 | if (fixp->fx_pcrel) | |
1843 | fixp->fx_r_type = BFD_RELOC_64_PCREL; | |
1844 | else | |
1845 | fixp->fx_r_type = BFD_RELOC_64; | |
1846 | if (fixp->fx_done) | |
1847 | md_number_to_chars (where, value, 8); | |
1848 | break; | |
1849 | ||
1850 | case BFD_RELOC_64_PCREL: | |
1851 | fixp->fx_r_type = BFD_RELOC_64_PCREL; | |
1852 | if (fixp->fx_done) | |
1853 | md_number_to_chars (where, value, 8); | |
1854 | break; | |
1855 | ||
1856 | case BFD_RELOC_VTABLE_INHERIT: | |
1857 | case BFD_RELOC_VTABLE_ENTRY: | |
1858 | fixp->fx_done = 0; | |
1859 | return 1; | |
1860 | ||
1861 | default: | |
1862 | { | |
1863 | const char *reloc_name = bfd_get_reloc_code_name (fixp->fx_r_type); | |
198ce79b | 1864 | |
07855bec NC |
1865 | if (reloc_name != NULL) |
1866 | fprintf (stderr, "Gas failure, reloc type %s\n", reloc_name); | |
1867 | else | |
1868 | fprintf (stderr, "Gas failure, reloc type #%i\n", fixp->fx_r_type); | |
1869 | fflush (stderr); | |
1870 | abort (); | |
1871 | } | |
1872 | } | |
a85d7ed0 | 1873 | |
07855bec NC |
1874 | fixp->fx_offset = value; |
1875 | } | |
a85d7ed0 NC |
1876 | |
1877 | return 1; | |
1878 | } | |
1879 | ||
1880 | /* Generate a reloc for a fixup. */ | |
1881 | ||
1882 | arelent * | |
1883 | tc_gen_reloc (seg, fixp) | |
1884 | asection *seg ATTRIBUTE_UNUSED; | |
1885 | fixS *fixp; | |
1886 | { | |
1887 | bfd_reloc_code_real_type code; | |
1888 | arelent *reloc; | |
1889 | ||
1890 | code = fixp->fx_r_type; | |
07855bec NC |
1891 | if (GOT_symbol && fixp->fx_addsy == GOT_symbol) |
1892 | { | |
1893 | if ((s390_arch_size == 32 && code == BFD_RELOC_32_PCREL) || | |
1894 | (s390_arch_size == 64 && code == BFD_RELOC_64_PCREL)) | |
1895 | code = BFD_RELOC_390_GOTPC; | |
1896 | if (code == BFD_RELOC_390_PC32DBL) | |
1897 | code = BFD_RELOC_390_GOTPCDBL; | |
1898 | } | |
a85d7ed0 NC |
1899 | |
1900 | reloc = (arelent *) xmalloc (sizeof (arelent)); | |
1901 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
1902 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
1903 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
1904 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); | |
1905 | if (reloc->howto == NULL) | |
1906 | { | |
1907 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
1908 | _("cannot represent relocation type %s"), | |
1909 | bfd_get_reloc_code_name (code)); | |
1910 | /* Set howto to a garbage value so that we can keep going. */ | |
1911 | reloc->howto = bfd_reloc_type_lookup (stdoutput, BFD_RELOC_32); | |
1912 | assert (reloc->howto != NULL); | |
1913 | } | |
1914 | reloc->addend = fixp->fx_offset; | |
1915 | ||
1916 | return reloc; | |
1917 | } |