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