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