Fix comments.
[deliverable/binutils-gdb.git] / gas / config / tc-i370.c
1 /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set.
2 Loosely based on the ppc files by Linas Vepstas <linas@linas.org> 1998, 99
3 Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
5
6 This file is part of GAS, the GNU Assembler.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 /* This assembler implements a very hacked version of an elf-like thing
24 * that gcc emits (when gcc is suitably hacked). To make it behave more
25 * HLASM-like, try turning on the -M or --mri flag (as there are various
26 * similarities between HLASM and the MRI assemblers, such as section
27 * names, lack of leading . in pseudo-ops, DC and DS, etc ...
28 */
29
30 #include <stdio.h>
31 #include <ctype.h>
32 #include "as.h"
33 #include "subsegs.h"
34 #include "struc-symbol.h"
35
36 #include "opcode/i370.h"
37
38 #ifdef OBJ_ELF
39 #include "elf/i370.h"
40 #endif
41
42 /* This is the assembler for the System/390 Architecture */
43
44 /* Tell the main code what the endianness is. */
45 extern int target_big_endian;
46
47 \f
48 /* Generic assembler global variables which must be defined by all
49 targets. */
50
51 #ifdef OBJ_ELF
52 /* This string holds the chars that always start a comment. If the
53 pre-processor is disabled, these aren't very useful. The macro
54 tc_comment_chars points to this. We use this, rather than the
55 usual comment_chars, so that we can switch for Solaris conventions. */
56 static const char i370_eabi_comment_chars[] = "#";
57
58 const char *i370_comment_chars = i370_eabi_comment_chars;
59 #else
60 const char comment_chars[] = "#";
61 #endif
62
63 /* Characters which start a comment at the beginning of a line. */
64 const char line_comment_chars[] = "#*";
65
66 /* Characters which may be used to separate multiple commands on a
67 single line. */
68 const char line_separator_chars[] = ";";
69
70 /* Characters which are used to indicate an exponent in a floating
71 point number. */
72 const char EXP_CHARS[] = "eE";
73
74 /* Characters which mean that a number is a floating point constant,
75 as in 0d1.0. */
76 const char FLT_CHARS[] = "dD";
77
78
79 void
80 md_show_usage (stream)
81 FILE *stream;
82 {
83 fprintf(stream, "\
84 S/370 options: (these have not yet been tested and may not work) \n\
85 -u ignored\n\
86 -mregnames Allow symbolic names for registers\n\
87 -mno-regnames Do not allow symbolic names for registers\n");
88 #ifdef OBJ_ELF
89 fprintf(stream, "\
90 -mrelocatable support for GCC's -mrelocatble option\n\
91 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
92 -V print assembler version number\n");
93 #endif
94 }
95
96 \f
97 static void i370_byte PARAMS ((int));
98 static void i370_tc PARAMS ((int));
99 static void i370_ebcdic PARAMS ((int));
100
101 static void i370_dc PARAMS ((int));
102 static void i370_ds PARAMS ((int));
103 static void i370_rmode PARAMS ((int));
104 static void i370_csect PARAMS ((int));
105 static void i370_dsect PARAMS ((int));
106 static void i370_ltorg PARAMS ((int));
107 static void i370_using PARAMS ((int));
108 static void i370_drop PARAMS ((int));
109 static void i370_make_relative PARAMS ((expressionS *exp, expressionS *baseaddr));
110
111 #ifdef OBJ_ELF
112 static bfd_reloc_code_real_type i370_elf_suffix PARAMS ((char **, expressionS *));
113 static void i370_elf_cons PARAMS ((int));
114 static void i370_elf_rdata PARAMS ((int));
115 static void i370_elf_lcomm PARAMS ((int));
116 static void i370_elf_validate_fix PARAMS ((fixS *, segT));
117 #endif
118
119
120 \f
121 /* The target specific pseudo-ops which we support. */
122
123 const pseudo_typeS md_pseudo_table[] =
124 {
125 /* Pseudo-ops which must be overridden. */
126 { "byte", i370_byte, 0 },
127
128 { "dc", i370_dc, 0 },
129 { "ds", i370_ds, 0 },
130 { "rmode", i370_rmode, 0 },
131 { "csect", i370_csect, 0 },
132 { "dsect", i370_dsect, 0 },
133
134 /* enable ebcdic strings e.g. for 3270 support */
135 { "ebcdic", i370_ebcdic, 0 },
136
137 #ifdef OBJ_ELF
138 { "long", i370_elf_cons, 4 },
139 { "word", i370_elf_cons, 4 },
140 { "short", i370_elf_cons, 2 },
141 { "rdata", i370_elf_rdata, 0 },
142 { "rodata", i370_elf_rdata, 0 },
143 { "lcomm", i370_elf_lcomm, 0 },
144 #endif
145
146 /* This pseudo-op is used even when not generating XCOFF output. */
147 { "tc", i370_tc, 0 },
148
149 /* dump the literal pool */
150 { "ltorg", i370_ltorg, 0 },
151
152 /* support the hlasm-style USING directive */
153 { "using", i370_using, 0 },
154 { "drop", i370_drop, 0 },
155
156 { NULL, NULL, 0 }
157 };
158
159 /* ***************************************************************** */
160
161 /* Whether to use user friendly register names. */
162 #define TARGET_REG_NAMES_P true
163
164 static boolean reg_names_p = TARGET_REG_NAMES_P;
165
166 static boolean register_name PARAMS ((expressionS *));
167 static void i370_set_cpu PARAMS ((void));
168 static i370_insn_t i370_insert_operand
169 PARAMS ((i370_insn_t insn, const struct i370_operand *operand, offsetT val));
170 static void i370_macro PARAMS ((char *str, const struct i370_macro *macro));
171 \f
172 /* Predefined register names if -mregnames */
173 /* In general, there are lots of them, in an attempt to be compatible */
174 /* with a number of assemblers. */
175
176 /* Structure to hold information about predefined registers. */
177 struct pd_reg
178 {
179 char *name;
180 int value;
181 };
182
183 /* List of registers that are pre-defined:
184
185 Each general register has predefined names of the form:
186 1. r<reg_num> which has the value <reg_num>.
187 2. r.<reg_num> which has the value <reg_num>.
188
189
190 Each floating point register has predefined names of the form:
191 1. f<reg_num> which has the value <reg_num>.
192 2. f.<reg_num> which has the value <reg_num>.
193
194 There are only four floating point registers, and these are
195 commonly labelled 0,2,4 and 6. Thus, there is no f1, f3, etc.
196
197
198 There are individual registers as well:
199 rbase or r.base has the value 3 (base register)
200 rpgt or r.pgt has the value 4 (page origin table pointer)
201 rarg or r.arg has the value 11 (argument pointer)
202 rtca or r.tca has the value 12 (table of contents pointer)
203 rtoc or r.toc has the value 12 (table of contents pointer)
204 sp or r.sp has the value 13 (stack pointer)
205 dsa or r.dsa has the value 13 (stack pointer)
206 lr has the value 14 (link reg)
207
208 The table is sorted. Suitable for searching by a binary search. */
209
210 static const struct pd_reg pre_defined_registers[] =
211 {
212 { "arg", 11 }, /* Argument Pointer */
213 { "base", 3 }, /* Base Reg */
214
215 { "f.0", 0 }, /* Floating point registers */
216 { "f.2", 2 },
217 { "f.4", 4 },
218 { "f.6", 6 },
219
220 { "f0", 0 },
221 { "f2", 2 },
222 { "f4", 4 },
223 { "f6", 6 },
224
225
226 { "dsa",13 }, /* stack pointer */
227 { "lr", 14 }, /* Link Register */
228 { "pgt", 4 }, /* Page Origin Table Pointer */
229
230 { "r.0", 0 }, /* General Purpose Registers */
231 { "r.1", 1 },
232 { "r.10", 10 },
233 { "r.11", 11 },
234 { "r.12", 12 },
235 { "r.13", 13 },
236 { "r.14", 14 },
237 { "r.15", 15 },
238 { "r.2", 2 },
239 { "r.3", 3 },
240 { "r.4", 4 },
241 { "r.5", 5 },
242 { "r.6", 6 },
243 { "r.7", 7 },
244 { "r.8", 8 },
245 { "r.9", 9 },
246
247 { "r.arg", 11 }, /* Argument Pointer */
248 { "r.base", 3 }, /* Base Reg */
249 { "r.dsa", 13 }, /* Stack Pointer */
250 { "r.pgt", 4 }, /* Page Origin Table Pointer */
251 { "r.sp", 13 }, /* Stack Pointer */
252
253 { "r.tca", 12 }, /* Pointer to the table of contents */
254 { "r.toc", 12 }, /* Pointer to the table of contents */
255
256 { "r0", 0 }, /* More general purpose registers */
257 { "r1", 1 },
258 { "r10", 10 },
259 { "r11", 11 },
260 { "r12", 12 },
261 { "r13", 13 },
262 { "r14", 14 },
263 { "r15", 15 },
264 { "r2", 2 },
265 { "r3", 3 },
266 { "r4", 4 },
267 { "r5", 5 },
268 { "r6", 6 },
269 { "r7", 7 },
270 { "r8", 8 },
271 { "r9", 9 },
272
273 { "rbase", 3 }, /* Base Reg */
274
275 { "rtca", 12 }, /* Pointer to the table of contents */
276 { "rtoc", 12 }, /* Pointer to the table of contents */
277
278 { "sp", 13 }, /* Stack Pointer */
279
280 };
281
282 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
283
284 /* Given NAME, find the register number associated with that name, return
285 the integer value associated with the given name or -1 on failure. */
286
287 static int reg_name_search
288 PARAMS ((const struct pd_reg *, int, const char * name));
289
290 static int
291 reg_name_search (regs, regcount, name)
292 const struct pd_reg *regs;
293 int regcount;
294 const char *name;
295 {
296 int middle, low, high;
297 int cmp;
298
299 low = 0;
300 high = regcount - 1;
301
302 do
303 {
304 middle = (low + high) / 2;
305 cmp = strcasecmp (name, regs[middle].name);
306 if (cmp < 0)
307 high = middle - 1;
308 else if (cmp > 0)
309 low = middle + 1;
310 else
311 return regs[middle].value;
312 }
313 while (low <= high);
314
315 return -1;
316 }
317
318 /*
319 * Summary of register_name().
320 *
321 * in: Input_line_pointer points to 1st char of operand.
322 *
323 * out: A expressionS.
324 * The operand may have been a register: in this case, X_op == O_register,
325 * X_add_number is set to the register number, and truth is returned.
326 * Input_line_pointer->(next non-blank) char after operand, or is in its
327 * original state.
328 */
329
330 static boolean
331 register_name (expressionP)
332 expressionS *expressionP;
333 {
334 int reg_number;
335 char *name;
336 char *start;
337 char c;
338
339 /* Find the spelling of the operand */
340 start = name = input_line_pointer;
341 if (name[0] == '%' && isalpha (name[1]))
342 name = ++input_line_pointer;
343
344 else if (!reg_names_p)
345 return false;
346
347 while (' ' == *name)
348 name = ++input_line_pointer;
349
350 /* if its a number, treat it as a number */
351 /* if its alpha, look to see if it's in the register table */
352 if (!isalpha (name[0]))
353 {
354 reg_number = get_single_number();
355 c = get_symbol_end ();
356 }
357 else
358 {
359 c = get_symbol_end ();
360 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
361 }
362
363 /* if numeric, make sure its not out of bounds */
364 if ((0 <= reg_number) && (16 >= reg_number))
365 {
366 expressionP->X_op = O_register;
367 expressionP->X_add_number = reg_number;
368
369 /* make the rest nice */
370 expressionP->X_add_symbol = NULL;
371 expressionP->X_op_symbol = NULL;
372 *input_line_pointer = c; /* put back the delimiting char */
373 return true;
374 }
375
376 /* reset the line as if we had not done anything */
377 *input_line_pointer = c; /* put back the delimiting char */
378 input_line_pointer = start; /* reset input_line pointer */
379 return false;
380 }
381 \f
382 /* Local variables. */
383
384 /* The type of processor we are assembling for. This is one or more
385 of the I370_OPCODE flags defined in opcode/i370.h. */
386 static int i370_cpu = 0;
387
388 /* The base register to use for opcode with optional operands.
389 * We define two of these: "text" and "other". Normally, "text"
390 * would get used in the .text section for branches, while "other"
391 * gets used in the .data section for address constants.
392 *
393 * The idea of a second base register in a different section
394 * is foreign to the usual HLASM-style semantics; however, it
395 * allows us to provide support for dynamically loaded libraries,
396 * by allowing us to place address constants in a section other
397 * than the text section. The "other" section need not be the
398 * .data section, it can be any section that isn't the .text section.
399 *
400 * Note that HLASM defines a multiple, concurrent .using semantic
401 * that we do not: in calculating offsets, it uses either the most
402 * recent .using directive, or the one with the smallest displacement.
403 * This allows HLASM to support a quasi-block-scope-like behaviour.
404 * Handy for people writing assembly by hand ... but not supported
405 * by us.
406 */
407 static int i370_using_text_regno = -1;
408 static int i370_using_other_regno = -1;
409
410 /* The base address for address literals */
411 static expressionS i370_using_text_baseaddr;
412 static expressionS i370_using_other_baseaddr;
413
414 /* the "other" section, used only for syntax error detection */
415 static segT i370_other_section = undefined_section;
416
417 /* Opcode hash table. */
418 static struct hash_control *i370_hash;
419
420 /* Macro hash table. */
421 static struct hash_control *i370_macro_hash;
422
423 #ifdef OBJ_ELF
424 /* What type of shared library support to use */
425 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
426 #endif
427
428 /* Flags to set in the elf header */
429 static flagword i370_flags = 0;
430
431 #ifndef WORKING_DOT_WORD
432 const int md_short_jump_size = 4;
433 const int md_long_jump_size = 4;
434 #endif
435 \f
436 #ifdef OBJ_ELF
437 CONST char *md_shortopts = "l:um:K:VQ:";
438 #else
439 CONST char *md_shortopts = "um:";
440 #endif
441 struct option md_longopts[] =
442 {
443 {NULL, no_argument, NULL, 0}
444 };
445 size_t md_longopts_size = sizeof(md_longopts);
446
447 int
448 md_parse_option (c, arg)
449 int c;
450 char *arg;
451 {
452 switch (c)
453 {
454 case 'u':
455 /* -u means that any undefined symbols should be treated as
456 external, which is the default for gas anyhow. */
457 break;
458
459 #ifdef OBJ_ELF
460 case 'K':
461 /* Recognize -K PIC */
462 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
463 {
464 shlib = SHLIB_PIC;
465 i370_flags |= EF_I370_RELOCATABLE_LIB;
466 }
467 else
468 return 0;
469
470 break;
471 #endif
472
473 case 'm':
474
475 /* -m360 mean to assemble for the ancient 360 architecture */
476 if (strcmp (arg, "360") == 0 || strcmp (arg, "i360") == 0)
477 i370_cpu = I370_OPCODE_360;
478 /* -mxa means to assemble for the IBM 370 XA */
479 else if (strcmp (arg, "xa") == 0)
480 i370_cpu = I370_OPCODE_370_XA;
481 /* -many means to assemble for any architecture (370/XA). */
482 else if (strcmp (arg, "any") == 0)
483 i370_cpu = I370_OPCODE_370;
484
485 else if (strcmp (arg, "regnames") == 0)
486 reg_names_p = true;
487
488 else if (strcmp (arg, "no-regnames") == 0)
489 reg_names_p = false;
490
491 #ifdef OBJ_ELF
492 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
493 else if (strcmp (arg, "relocatable") == 0)
494 {
495 shlib = SHILB_MRELOCATABLE;
496 i370_flags |= EF_I370_RELOCATABLE;
497 }
498
499 else if (strcmp (arg, "relocatable-lib") == 0)
500 {
501 shlib = SHILB_MRELOCATABLE;
502 i370_flags |= EF_I370_RELOCATABLE_LIB;
503 }
504
505 #endif
506 else
507 {
508 as_bad ("invalid switch -m%s", arg);
509 return 0;
510 }
511 break;
512
513 #ifdef OBJ_ELF
514 /* -V: SVR4 argument to print version ID. */
515 case 'V':
516 print_version_id ();
517 break;
518
519 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
520 should be emitted or not. FIXME: Not implemented. */
521 case 'Q':
522 break;
523
524 #endif
525
526 default:
527 return 0;
528 }
529
530 return 1;
531 }
532
533 \f
534 /* Set i370_cpu if it is not already set.
535 Currently defaults to the reasonable superset;
536 but can be made more fine grained if desred. */
537
538 static void
539 i370_set_cpu ()
540 {
541 const char *default_os = TARGET_OS;
542 const char *default_cpu = TARGET_CPU;
543
544 /* override with the superset for the moment. */
545 i370_cpu = I370_OPCODE_ESA390_SUPERSET;
546 if (i370_cpu == 0)
547 {
548 if (strcmp (default_cpu, "i360") == 0)
549 i370_cpu = I370_OPCODE_360;
550 else if (strcmp (default_cpu, "i370") == 0)
551 i370_cpu = I370_OPCODE_370;
552 else if (strcmp (default_cpu, "XA") == 0)
553 i370_cpu = I370_OPCODE_370_XA;
554 else
555 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
556 }
557 }
558
559 /* Figure out the BFD architecture to use. */
560 // hack alert -- specify the different 370 architectures
561
562 enum bfd_architecture
563 i370_arch ()
564 {
565 return bfd_arch_i370;
566 }
567
568 /* This function is called when the assembler starts up. It is called
569 after the options have been parsed and the output file has been
570 opened. */
571
572 void
573 md_begin ()
574 {
575 register const struct i370_opcode *op;
576 const struct i370_opcode *op_end;
577 const struct i370_macro *macro;
578 const struct i370_macro *macro_end;
579 boolean dup_insn = false;
580
581 i370_set_cpu ();
582
583 #ifdef OBJ_ELF
584 /* Set the ELF flags if desired. */
585 if (i370_flags)
586 bfd_set_private_flags (stdoutput, i370_flags);
587 #endif
588
589 /* Insert the opcodes into a hash table. */
590 i370_hash = hash_new ();
591
592 op_end = i370_opcodes + i370_num_opcodes;
593 for (op = i370_opcodes; op < op_end; op++)
594 {
595 know ((op->opcode & op->mask) == op->opcode);
596
597 if ((op->flags & i370_cpu) != 0)
598 {
599 const char *retval;
600
601 retval = hash_insert (i370_hash, op->name, (PTR) op);
602 if (retval != (const char *) NULL)
603 {
604 as_bad ("Internal assembler error for instruction %s", op->name);
605 dup_insn = true;
606 }
607 }
608 }
609
610 /* Insert the macros into a hash table. */
611 i370_macro_hash = hash_new ();
612
613 macro_end = i370_macros + i370_num_macros;
614 for (macro = i370_macros; macro < macro_end; macro++)
615 {
616 if ((macro->flags & i370_cpu) != 0)
617 {
618 const char *retval;
619
620 retval = hash_insert (i370_macro_hash, macro->name, (PTR) macro);
621 if (retval != (const char *) NULL)
622 {
623 as_bad ("Internal assembler error for macro %s", macro->name);
624 dup_insn = true;
625 }
626 }
627 }
628
629 if (dup_insn)
630 abort ();
631 }
632
633 /* Insert an operand value into an instruction. */
634
635 static i370_insn_t
636 i370_insert_operand (insn, operand, val)
637 i370_insn_t insn;
638 const struct i370_operand *operand;
639 offsetT val;
640 {
641 if (operand->insert)
642 {
643 const char *errmsg;
644
645 /* used for 48-bit insn's */
646 errmsg = NULL;
647 insn = (*operand->insert) (insn, (long) val, &errmsg);
648 if (errmsg)
649 as_bad ("%s", errmsg);
650 }
651 else
652 {
653 /* this is used only for 16, 32 bit insn's */
654 insn.i[0] |= (((long) val & ((1 << operand->bits) - 1))
655 << operand->shift);
656 }
657
658 return insn;
659 }
660
661 \f
662 #ifdef OBJ_ELF
663 /* Parse @got, etc. and return the desired relocation.
664 * Currently, i370 does not support (don't really need to support) any
665 * of these fancier markups ... for example, no one is going to
666 * write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
667 * So basically, we could get away with this routine returning
668 * BFD_RELOC_UNUSED in all circumstances. However, I'll leave
669 * in for now in case someone ambitious finds a good use for this stuff ...
670 * this routine was pretty much just copied from the powerpc code ...
671 */
672 static bfd_reloc_code_real_type
673 i370_elf_suffix (str_p, exp_p)
674 char **str_p;
675 expressionS *exp_p;
676 {
677 struct map_bfd
678 {
679 char *string;
680 int length;
681 bfd_reloc_code_real_type reloc;
682 };
683
684 char ident[20];
685 char *str = *str_p;
686 char *str2;
687 int ch;
688 int len;
689 struct map_bfd *ptr;
690
691 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
692
693 static struct map_bfd mapping[] =
694 {
695 // MAP ("l", BFD_RELOC_LO16),
696 // MAP ("h", BFD_RELOC_HI16),
697 // MAP ("ha", BFD_RELOC_HI16_S),
698 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
699 { (char *)0, 0, BFD_RELOC_UNUSED }
700 };
701
702 if (*str++ != '@')
703 return BFD_RELOC_UNUSED;
704
705 for (ch = *str, str2 = ident;
706 (str2 < ident + sizeof (ident) - 1
707 && (isalnum (ch) || ch == '@'));
708 ch = *++str)
709 {
710 *str2++ = (islower (ch)) ? ch : tolower (ch);
711 }
712
713 *str2 = '\0';
714 len = str2 - ident;
715
716 ch = ident[0];
717 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
718 if (ch == ptr->string[0]
719 && len == ptr->length
720 && memcmp (ident, ptr->string, ptr->length) == 0)
721 {
722 if (exp_p->X_add_number != 0
723 && (ptr->reloc == BFD_RELOC_16_GOTOFF
724 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
725 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
726 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
727 as_warn ("identifier+constant@got means identifier@got+constant");
728
729 /* Now check for identifier@suffix+constant */
730 if (*str == '-' || *str == '+')
731 {
732 char *orig_line = input_line_pointer;
733 expressionS new_exp;
734
735 input_line_pointer = str;
736 expression (&new_exp);
737 if (new_exp.X_op == O_constant)
738 {
739 exp_p->X_add_number += new_exp.X_add_number;
740 str = input_line_pointer;
741 }
742
743 if (&input_line_pointer != str_p)
744 input_line_pointer = orig_line;
745 }
746
747 *str_p = str;
748 return ptr->reloc;
749 }
750
751 return BFD_RELOC_UNUSED;
752 }
753
754 /* Like normal .long/.short/.word, except support @got, etc. */
755 /* clobbers input_line_pointer, checks end-of-line. */
756 static void
757 i370_elf_cons (nbytes)
758 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
759 {
760 expressionS exp;
761 bfd_reloc_code_real_type reloc;
762
763 if (is_it_end_of_statement ())
764 {
765 demand_empty_rest_of_line ();
766 return;
767 }
768
769 do
770 {
771 expression (&exp);
772 if (exp.X_op == O_symbol
773 && *input_line_pointer == '@'
774 && (reloc = i370_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
775 {
776 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
777 int size = bfd_get_reloc_size (reloc_howto);
778
779 if (size > nbytes)
780 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
781
782 else
783 {
784 register char *p = frag_more ((int) nbytes);
785 int offset = nbytes - size;
786
787 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
788 }
789 }
790 else
791 emit_expr (&exp, (unsigned int) nbytes);
792 }
793 while (*input_line_pointer++ == ',');
794
795 input_line_pointer--; /* Put terminator back into stream. */
796 demand_empty_rest_of_line ();
797 }
798
799 \f
800 /* ASCII to EBCDIC conversion table. */
801 static unsigned char ascebc[256] =
802 {
803 /*00 NL SH SX EX ET NQ AK BL */
804 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
805 /*08 BS HT LF VT FF CR SO SI */
806 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
807 /*10 DL D1 D2 D3 D4 NK SN EB */
808 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
809 /*18 CN EM SB EC FS GS RS US */
810 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
811 /*20 SP ! " # $ % & ' */
812 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
813 /*28 ( ) * + , - . / */
814 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
815 /*30 0 1 2 3 4 5 6 7 */
816 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
817 /*38 8 9 : ; < = > ? */
818 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
819 /*40 @ A B C D E F G */
820 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
821 /*48 H I J K L M N O */
822 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
823 /*50 P Q R S T U V W */
824 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
825 /*58 X Y Z [ \ ] ^ _ */
826 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
827 /*60 ` a b c d e f g */
828 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
829 /*68 h i j k l m n o */
830 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
831 /*70 p q r s t u v w */
832 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
833 /*78 x y z { | } ~ DL */
834 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
835 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
836 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
837 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
838 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
839 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
840 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
841 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
842 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
843 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
844 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
845 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
846 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
847 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
848 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
849 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
850 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
851 };
852
853 /* EBCDIC to ASCII conversion table. */
854 unsigned char ebcasc[256] =
855 {
856 /*00 NU SH SX EX PF HT LC DL */
857 0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
858 /*08 SM VT FF CR SO SI */
859 0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
860 /*10 DE D1 D2 TM RS NL BS IL */
861 0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
862 /*18 CN EM CC C1 FS GS RS US */
863 0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
864 /*20 DS SS FS BP LF EB EC */
865 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
866 /*28 SM C2 EQ AK BL */
867 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
868 /*30 SY PN RS UC ET */
869 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
870 /*38 C3 D4 NK SU */
871 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
872 /*40 SP */
873 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
874 /*48 . < ( + | */
875 0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
876 /*50 & */
877 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
878 /*58 ! $ * ) ; ^ */
879 0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
880 /*60 - / */
881 0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
882 /*68 , % _ > ? */
883 0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
884 /*70 */
885 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
886 /*78 ` : # @ ' = " */
887 0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
888 /*80 a b c d e f g */
889 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
890 /*88 h i { */
891 0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
892 /*90 j k l m n o p */
893 0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
894 /*98 q r } */
895 0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
896 /*A0 ~ s t u v w x */
897 0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
898 /*A8 y z [ */
899 0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
900 /*B0 */
901 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
902 /*B8 ] */
903 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
904 /*C0 { A B C D E F G */
905 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
906 /*C8 H I */
907 0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
908 /*D0 } J K L M N O P */
909 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
910 /*D8 Q R */
911 0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
912 /*E0 \ S T U V W X */
913 0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
914 /*E8 Y Z */
915 0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
916 /*F0 0 1 2 3 4 5 6 7 */
917 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
918 /*F8 8 9 */
919 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
920 };
921
922 /* ebcdic translation tables needed for 3270 support */
923 static void
924 i370_ebcdic (unused)
925 int unused;
926 {
927 char *p, *end;
928 char delim = 0;
929 size_t nbytes;
930
931 nbytes = strlen (input_line_pointer);
932 end = input_line_pointer + nbytes;
933 while ('\r' == *end) end --;
934 while ('\n' == *end) end --;
935
936 delim = *input_line_pointer;
937 if (('\'' == delim) || ('\"' == delim)) {
938 input_line_pointer ++;
939 end = rindex (input_line_pointer, delim);
940 }
941
942 if (end > input_line_pointer)
943 {
944 nbytes = end - input_line_pointer +1;
945 p = frag_more (nbytes);
946 while (end > input_line_pointer)
947 {
948 *p = ascebc [(unsigned char)(*input_line_pointer)];
949 ++p; ++input_line_pointer;
950 }
951 *p = '\0';
952 }
953 if (delim == *input_line_pointer) ++input_line_pointer;
954 }
955
956 \f
957 /* stub out a couple of routines */
958 static void
959 i370_rmode (unused)
960 int unused;
961 {
962 as_tsktsk ("rmode ignored");
963 }
964
965 static void
966 i370_dsect (sect)
967 int sect;
968 {
969 char *save_line = input_line_pointer;
970 static char section[] = ".data\n";
971
972 /* Just pretend this is .section .data */
973 input_line_pointer = section;
974 obj_elf_section (sect);
975
976 input_line_pointer = save_line;
977 }
978
979 static void
980 i370_csect (unused)
981 int unused;
982 {
983 as_tsktsk ("csect not supported");
984 }
985
986 \f
987 /* DC Define Const is only partially supported.
988 * For samplecode on what to do, look at i370_elf_cons() above.
989 * This code handles pseudoops of the style
990 * DC D'3.141592653' # in sysv4, .double 3.14159265
991 * DC F'1' # in sysv4, .long 1
992 */
993 static void
994 i370_dc(unused)
995 int unused;
996 {
997 char * p, tmp[50];
998 int nbytes=0;
999 expressionS exp;
1000 char type=0;
1001
1002 if (is_it_end_of_statement ())
1003 {
1004 demand_empty_rest_of_line ();
1005 return;
1006 }
1007
1008 /* figure out the size */
1009 type = *input_line_pointer++;
1010 switch (type)
1011 {
1012 case 'H': /* 16-bit */
1013 nbytes = 2;
1014 break;
1015 case 'E': /* 32-bit */
1016 case 'F': /* 32-bit */
1017 nbytes = 4;
1018 break;
1019 case 'D': /* 64-bit */
1020 nbytes = 8;
1021 break;
1022 default:
1023 as_bad ("unsupported DC type");
1024 return;
1025 }
1026
1027 /* get rid of pesky quotes */
1028 if ('\'' == *input_line_pointer)
1029 {
1030 char * close;
1031 ++input_line_pointer;
1032 close = strchr (input_line_pointer, '\'');
1033 if (close)
1034 *close= ' ';
1035 else
1036 as_bad ("missing end-quote");
1037 }
1038 if ('\"' == *input_line_pointer)
1039 {
1040 char * close;
1041 ++input_line_pointer;
1042 close = strchr (input_line_pointer, '\"');
1043 if (close)
1044 *close= ' ';
1045 else
1046 as_bad ("missing end-quote");
1047 }
1048
1049 switch (type)
1050 {
1051 case 'H': /* 16-bit */
1052 case 'F': /* 32-bit */
1053 expression (&exp);
1054 emit_expr (&exp, nbytes);
1055 break;
1056 case 'E': /* 32-bit */
1057 case 'D': /* 64-bit */
1058 md_atof (type, tmp, &nbytes);
1059 p = frag_more (nbytes);
1060 memcpy (p, tmp, nbytes);
1061 break;
1062 default:
1063 as_bad ("unsupported DC type");
1064 return;
1065 }
1066
1067 demand_empty_rest_of_line ();
1068 }
1069
1070 \f
1071 /* provide minimal support for DS Define Storage */
1072 static void
1073 i370_ds (unused)
1074 int unused;
1075 {
1076 /* DS 0H or DS 0F or DS 0D */
1077 if ('0' == *input_line_pointer)
1078 {
1079 int alignment = 0; /* left shift 1<<align */
1080 input_line_pointer ++;
1081 switch (*input_line_pointer++)
1082 {
1083 case 'H': /* 16-bit */
1084 alignment = 1;
1085 break;
1086 case 'F': /* 32-bit */
1087 alignment = 2;
1088 break;
1089 case 'D': /* 64-bit */
1090 alignment = 3;
1091 break;
1092 default:
1093 as_bad ("unsupported alignment");
1094 return;
1095 }
1096 frag_align (alignment, 0, 0);
1097 record_alignment (now_seg, alignment);
1098 }
1099 else
1100 {
1101 as_bad ("this DS form not yet supported");
1102 }
1103 }
1104
1105 /* Solaris pseudo op to change to the .rodata section. */
1106 static void
1107 i370_elf_rdata (sect)
1108 int sect;
1109 {
1110 char *save_line = input_line_pointer;
1111 static char section[] = ".rodata\n";
1112
1113 /* Just pretend this is .section .rodata */
1114 input_line_pointer = section;
1115 obj_elf_section (sect);
1116
1117 input_line_pointer = save_line;
1118 }
1119
1120 /* Pseudo op to make file scope bss items */
1121 static void
1122 i370_elf_lcomm(unused)
1123 int unused;
1124 {
1125 register char *name;
1126 register char c;
1127 register char *p;
1128 offsetT size;
1129 register symbolS *symbolP;
1130 offsetT align;
1131 segT old_sec;
1132 int old_subsec;
1133 char *pfrag;
1134 int align2;
1135
1136 name = input_line_pointer;
1137 c = get_symbol_end ();
1138
1139 /* just after name is now '\0' */
1140 p = input_line_pointer;
1141 *p = c;
1142 SKIP_WHITESPACE ();
1143 if (*input_line_pointer != ',')
1144 {
1145 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1146 ignore_rest_of_line ();
1147 return;
1148 }
1149
1150 input_line_pointer++; /* skip ',' */
1151 if ((size = get_absolute_expression ()) < 0)
1152 {
1153 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size);
1154 ignore_rest_of_line ();
1155 return;
1156 }
1157
1158 /* The third argument to .lcomm is the alignment. */
1159 if (*input_line_pointer != ',')
1160 align = 8;
1161 else
1162 {
1163 ++input_line_pointer;
1164 align = get_absolute_expression ();
1165 if (align <= 0)
1166 {
1167 as_warn ("ignoring bad alignment");
1168 align = 8;
1169 }
1170 }
1171
1172 *p = 0;
1173 symbolP = symbol_find_or_make (name);
1174 *p = c;
1175
1176 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1177 {
1178 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1179 S_GET_NAME (symbolP));
1180 ignore_rest_of_line ();
1181 return;
1182 }
1183
1184 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1185 {
1186 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1187 S_GET_NAME (symbolP),
1188 (long) S_GET_VALUE (symbolP),
1189 (long) size);
1190
1191 ignore_rest_of_line ();
1192 return;
1193 }
1194
1195 /* allocate_bss: */
1196 old_sec = now_seg;
1197 old_subsec = now_subseg;
1198 if (align)
1199 {
1200 /* convert to a power of 2 alignment */
1201 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2)
1202 ;
1203 if (align != 1)
1204 {
1205 as_bad ("Common alignment not a power of 2");
1206 ignore_rest_of_line ();
1207 return;
1208 }
1209 }
1210 else
1211 align2 = 0;
1212
1213 record_alignment (bss_section, align2);
1214 subseg_set (bss_section, 0);
1215 if (align2)
1216 frag_align (align2, 0, 0);
1217 if (S_GET_SEGMENT (symbolP) == bss_section)
1218 symbol_get_frag (symbolP)->fr_symbol = 0;
1219 symbol_set_frag (symbolP, frag_now);
1220 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1221 (char *) 0);
1222 *pfrag = 0;
1223 S_SET_SIZE (symbolP, size);
1224 S_SET_SEGMENT (symbolP, bss_section);
1225 subseg_set (old_sec, old_subsec);
1226 demand_empty_rest_of_line ();
1227 }
1228
1229 /* Validate any relocations emitted for -mrelocatable, possibly adding
1230 fixups for word relocations in writable segments, so we can adjust
1231 them at runtime. */
1232 static void
1233 i370_elf_validate_fix (fixp, seg)
1234 fixS *fixp;
1235 segT seg;
1236 {
1237 if (fixp->fx_done || fixp->fx_pcrel)
1238 return;
1239
1240 switch (shlib)
1241 {
1242 case SHLIB_NONE:
1243 case SHLIB_PIC:
1244 return;
1245
1246 case SHILB_MRELOCATABLE:
1247 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1248 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1249 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1250 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1251 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1252 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1253 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1254 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1255 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1256 && strcmp (segment_name (seg), ".got2") != 0
1257 && strcmp (segment_name (seg), ".dtors") != 0
1258 && strcmp (segment_name (seg), ".ctors") != 0
1259 && strcmp (segment_name (seg), ".fixup") != 0
1260 && strcmp (segment_name (seg), ".stab") != 0
1261 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1262 && strcmp (segment_name (seg), ".ex_shared") != 0)
1263 {
1264 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1265 || fixp->fx_r_type != BFD_RELOC_CTOR)
1266 {
1267 as_bad_where (fixp->fx_file, fixp->fx_line,
1268 "Relocation cannot be done when using -mrelocatable");
1269 }
1270 }
1271 return;
1272 }
1273 }
1274 #endif /* OBJ_ELF */
1275
1276
1277 \f
1278 #define LITERAL_POOL_SUPPORT
1279 #ifdef LITERAL_POOL_SUPPORT
1280 /* Provide support for literal pools within the text section. */
1281 /* Loosely based on similar code from tc-arm.c */
1282 /*
1283 * We will use four symbols to locate four parts of the literal pool.
1284 * These four sections contain 64,32,16 and 8-bit constants; we use
1285 * four sections so that all memory access can be appropriately aligned.
1286 * That is, we want to avoid mixing these together so that we don't
1287 * waste space padding out to alignments. The four pointers
1288 * longlong_poolP, word_poolP, etc. point to a symbol labeling the
1289 * start of each pool part.
1290 *
1291 * lit_pool_num increments from zero to infinity and uniquely id's
1292 * -- its used to generate the *_poolP symbol name.
1293 */
1294
1295 #define MAX_LITERAL_POOL_SIZE 1024
1296
1297 typedef struct literalS
1298 {
1299 struct expressionS exp;
1300 char * sym_name;
1301 char size; /* 1,2,4 or 8 */
1302 short offset;
1303 } literalT;
1304
1305 literalT literals[MAX_LITERAL_POOL_SIZE];
1306 int next_literal_pool_place = 0; /* Next free entry in the pool */
1307
1308 static symbolS *longlong_poolP = NULL; /* 64-bit pool entries */
1309 static symbolS *word_poolP = NULL; /* 32-bit pool entries */
1310 static symbolS *short_poolP = NULL; /* 16-bit pool entries */
1311 static symbolS *byte_poolP = NULL; /* 8-bit pool entries */
1312
1313 static int lit_pool_num = 1;
1314
1315 /* create a new, empty symbol */
1316 static symbolS *
1317 symbol_make_empty (void)
1318 {
1319 return symbol_create (FAKE_LABEL_NAME, undefined_section,
1320 (valueT) 0, &zero_address_frag);
1321 }
1322
1323 /* add an expression to the literal pool */
1324 static void
1325 add_to_lit_pool (expressionS *exx, char *name, int sz)
1326 {
1327 int lit_count = 0;
1328 int offset_in_pool = 0;
1329
1330 /* start a new pool, if necessary */
1331 if (8 == sz && NULL == longlong_poolP)
1332 longlong_poolP = symbol_make_empty();
1333 else if (4 == sz && NULL == word_poolP)
1334 word_poolP = symbol_make_empty();
1335 else if (2 == sz && NULL == short_poolP)
1336 short_poolP = symbol_make_empty();
1337 else if (1 == sz && NULL == byte_poolP)
1338 byte_poolP = symbol_make_empty();
1339
1340 /* Check if this literal value is already in the pool: */
1341 /* hack alert -- we should probably be checking expressions
1342 * of type O_symbol as well ... */
1343 /* hack alert XXX this is probably(certainly?) broken for O_big,
1344 * which includes 64-bit long-longs ...
1345 */
1346 while (lit_count < next_literal_pool_place)
1347 {
1348 if (exx->X_op == O_constant
1349 && literals[lit_count].exp.X_op == exx->X_op
1350 && literals[lit_count].exp.X_add_number == exx->X_add_number
1351 && literals[lit_count].exp.X_unsigned == exx->X_unsigned
1352 && literals[lit_count].size == sz)
1353 break;
1354 else if (literals[lit_count].sym_name
1355 && name
1356 && !strcmp (name, literals[lit_count].sym_name))
1357 break;
1358 if (sz == literals[lit_count].size)
1359 offset_in_pool += sz;
1360 lit_count ++;
1361 }
1362
1363 if (lit_count == next_literal_pool_place) /* new entry */
1364 {
1365 if (next_literal_pool_place > MAX_LITERAL_POOL_SIZE)
1366 {
1367 as_bad("Literal Pool Overflow");
1368 }
1369
1370 literals[next_literal_pool_place].exp = *exx;
1371 literals[next_literal_pool_place].size = sz;
1372 literals[next_literal_pool_place].offset = offset_in_pool;
1373 if (name)
1374 {
1375 literals[next_literal_pool_place].sym_name = strdup (name);
1376 }
1377 else
1378 {
1379 literals[next_literal_pool_place].sym_name = NULL;
1380 }
1381 next_literal_pool_place++;
1382 }
1383
1384 /* ???_poolP points to the begining of the literal pool.
1385 * X_add_number is the offset from the begining of the
1386 * literal pool to this expr minus the location of the most
1387 * recent .using directive. Thus, the grand total value of the
1388 * expression is the distance from .using to the literal.
1389 */
1390 if (8 == sz)
1391 exx->X_add_symbol = longlong_poolP;
1392 else if (4 == sz)
1393 exx->X_add_symbol = word_poolP;
1394 else if (2 == sz)
1395 exx->X_add_symbol = short_poolP;
1396 else if (1 == sz)
1397 exx->X_add_symbol = byte_poolP;
1398 exx->X_add_number = offset_in_pool;
1399 exx->X_op_symbol = NULL;
1400
1401 /* If the user has set up a base reg in another section,
1402 * use that; otherwise use the text section. */
1403 if (0 < i370_using_other_regno)
1404 {
1405 i370_make_relative (exx, &i370_using_other_baseaddr);
1406 }
1407 else
1408 {
1409 i370_make_relative (exx, &i370_using_text_baseaddr);
1410 }
1411 }
1412
1413 /* The symbol setup for the literal pool is done in two steps. First,
1414 * a symbol that represents the start of the literal pool is created,
1415 * above, in the add_to_pool() routine. This sym ???_poolP.
1416 * However, we don't know what fragment its in until a bit later.
1417 * So we defer the frag_now thing, and the symbol name, until .ltorg time
1418 */
1419
1420 /* Can't use symbol_new here, so have to create a symbol and then at
1421 a later date assign it a value. Thats what these functions do */
1422 static void
1423 symbol_locate (symbolP, name, segment, valu, frag)
1424 symbolS *symbolP;
1425 CONST char *name; /* It is copied, the caller can modify */
1426 segT segment; /* Segment identifier (SEG_<something>) */
1427 valueT valu; /* Symbol value */
1428 fragS *frag; /* Associated fragment */
1429 {
1430 size_t name_length;
1431 char *preserved_copy_of_name;
1432
1433 name_length = strlen (name) + 1; /* +1 for \0 */
1434 obstack_grow (&notes, name, name_length);
1435 preserved_copy_of_name = obstack_finish (&notes);
1436
1437 S_SET_NAME (symbolP, preserved_copy_of_name);
1438
1439 S_SET_SEGMENT (symbolP, segment);
1440 S_SET_VALUE (symbolP, valu);
1441 symbol_clear_list_pointers(symbolP);
1442
1443 symbol_set_frag (symbolP, frag);
1444
1445 /*
1446 * Link to end of symbol chain.
1447 */
1448 {
1449 extern int symbol_table_frozen;
1450 if (symbol_table_frozen)
1451 abort ();
1452 }
1453
1454 symbol_append (symbolP, symbol_lastP, &symbol_rootP, &symbol_lastP);
1455
1456 obj_symbol_new_hook (symbolP);
1457
1458 #ifdef tc_symbol_new_hook
1459 tc_symbol_new_hook (symbolP);
1460 #endif
1461
1462 #define DEBUG_SYMS
1463 #ifdef DEBUG_SYMS
1464 verify_symbol_chain(symbol_rootP, symbol_lastP);
1465 #endif /* DEBUG_SYMS */
1466 }
1467
1468 /* i370_addr_offset() will convert operand expressions
1469 * that appear to be absolute into thier base-register
1470 * relative form. These expressions come in two types:
1471 *
1472 * (1) of the form "* + const" * where "*" means
1473 * relative offset since the last using
1474 * i.e. "*" means ".-using_baseaddr"
1475 *
1476 * (2) labels, which are never absolute, but are always
1477 * relative to the last "using". Anything with an alpha
1478 * character is considered to be a label (since symbols
1479 * can never be operands), and since we've already handled
1480 * register operands. For example, "BL .L33" branch low
1481 * to .L33 RX form insn frequently terminates for-loops,
1482 */
1483 static boolean
1484 i370_addr_offset (expressionS *exx)
1485 {
1486 char *dot, *lab;
1487 int islabel = 0;
1488 int all_digits = 0;
1489
1490 /* search for a label; anything with an alpha char will do */
1491 /* local labels consist of N digits followed by either b or f */
1492 lab = input_line_pointer;
1493 while (*lab && (',' != *lab) && ('(' != *lab))
1494 {
1495 if (isdigit(*lab))
1496 {
1497 all_digits = 1;
1498 }
1499 else if (isalpha(*lab))
1500 {
1501 if (!all_digits)
1502 {
1503 islabel = 1;
1504 break;
1505 }
1506 else if (('f' == *lab) || ('b' == *lab))
1507 {
1508 islabel = 1;
1509 break;
1510 }
1511 if (all_digits)
1512 break;
1513 }
1514 else if ('.' != *lab)
1515 break;
1516 ++lab;
1517 }
1518
1519 /* See if operand has a * in it */
1520 dot = strchr (input_line_pointer, '*');
1521
1522 if (!dot && !islabel)
1523 return false;
1524
1525 /* replace * with . and let expr munch on it. */
1526 if (dot)
1527 *dot = '.';
1528 expression (exx);
1529
1530 /* OK, now we have to subtract the "using" location */
1531 /* normally branches appear in the text section only... */
1532 if (0 == strncmp (now_seg->name, ".text", 5) || 0 > i370_using_other_regno)
1533 {
1534 i370_make_relative (exx, &i370_using_text_baseaddr);
1535 }
1536 else
1537 {
1538 i370_make_relative (exx, &i370_using_other_baseaddr);
1539 }
1540
1541 /* put the * back */
1542 if (dot)
1543 *dot = '*';
1544
1545 return true;
1546 }
1547
1548 /* handle address constants of various sorts */
1549 /* The currently supported types are
1550 * =A(some_symb)
1551 * =V(some_extern)
1552 * =X'deadbeef' hexadecimal
1553 * =F'1234' 32-bit const int
1554 * =H'1234' 16-bit const int
1555 */
1556 static boolean
1557 i370_addr_cons (expressionS *exp)
1558 {
1559 char *name;
1560 char *sym_name, delim;
1561 int name_len;
1562 int hex_len=0;
1563 int cons_len=0;
1564
1565 name = input_line_pointer;
1566 sym_name = input_line_pointer;
1567 /* Find the spelling of the operand */
1568 if (name[0] == '=' && isalpha (name[1]))
1569 {
1570 name = ++input_line_pointer;
1571 }
1572 else
1573 {
1574 return false;
1575 }
1576 switch (name[0])
1577 {
1578 case 'A':
1579 case 'V':
1580 /* A == address-of */
1581 /* V == extern */
1582 ++input_line_pointer;
1583 expression (exp);
1584
1585 /* we use a simple string name to collapse together
1586 * multiple refrences to the same address literal
1587 */
1588 name_len = strcspn (sym_name, ", ");
1589 delim = *(sym_name + name_len);
1590 *(sym_name + name_len) = 0x0;
1591 add_to_lit_pool (exp, sym_name, 4);
1592 *(sym_name + name_len) = delim;
1593
1594 break;
1595 case 'H':
1596 case 'F':
1597 case 'X':
1598 case 'E': /* single-precision float point */
1599 case 'D': /* double-precision float point */
1600
1601 /* H == 16-bit fixed-point const; expression must be const */
1602 /* F == fixed-point const; expression must be const */
1603 /* X == fixed-point const; expression must be const */
1604 if ('H' == name[0]) cons_len = 2;
1605 else if ('F' == name[0]) cons_len = 4;
1606 else if ('X' == name[0]) cons_len = -1;
1607 else if ('E' == name[0]) cons_len = 4;
1608 else if ('D' == name[0]) cons_len = 8;
1609
1610 /* extract length, if it is present; hack alert -- assume single-digit
1611 * length */
1612 if ('L' == name[1])
1613 {
1614 cons_len = name[2] - '0'; /* should work for ascii and ebcdic */
1615 input_line_pointer += 2;
1616 }
1617
1618 ++input_line_pointer;
1619
1620 /* get rid of pesky quotes */
1621 if ('\'' == *input_line_pointer)
1622 {
1623 char * close;
1624 ++input_line_pointer;
1625 close = strchr (input_line_pointer, '\'');
1626 if (close)
1627 *close= ' ';
1628 else
1629 as_bad ("missing end-quote");
1630 }
1631 if ('\"' == *input_line_pointer)
1632 {
1633 char * close;
1634 ++input_line_pointer;
1635 close = strchr (input_line_pointer, '\"');
1636 if (close)
1637 *close= ' ';
1638 else
1639 as_bad ("missing end-quote");
1640 }
1641 if (('X' == name[0]) || ('E' == name[0]) || ('D' == name[0]))
1642 {
1643 char tmp[50];
1644 char *save;
1645
1646 /* The length of hex constants is specified directly with L,
1647 * or implied through the number of hex digits. For example:
1648 * =X'AB' one byte
1649 * =X'abcd' two bytes
1650 * =X'000000AB' four bytes
1651 * =XL4'AB' four bytes, left-padded withn zero
1652 */
1653 if (('X' == name[0]) && (0 > cons_len))
1654 {
1655 save = input_line_pointer;
1656 while (*save)
1657 {
1658 if (isxdigit(*save))
1659 hex_len++;
1660 save++;
1661 }
1662 cons_len = (hex_len+1) /2;
1663 }
1664 /* I beleive this works even for =XL8'dada0000beeebaaa'
1665 * which should parse out to X_op == O_big
1666 * Note that floats and doubles get represented as
1667 * 0d3.14159265358979 or 0f 2.7
1668 */
1669 tmp[0] = '0';
1670 tmp[1] = name[0];
1671 tmp[2] = 0;
1672 strcat (tmp, input_line_pointer);
1673 save = input_line_pointer;
1674 input_line_pointer = tmp;
1675 expression (exp);
1676 input_line_pointer = save + (input_line_pointer-tmp-2);
1677
1678 /* fix up lengths for floats and doubles */
1679 if (O_big == exp->X_op)
1680 {
1681 exp->X_add_number = cons_len / CHARS_PER_LITTLENUM;
1682 }
1683 }
1684 else
1685 {
1686 expression (exp);
1687 }
1688 /* O_big occurs when more than 4 bytes worth gets parsed */
1689 if ((exp->X_op != O_constant) && (exp->X_op != O_big))
1690 {
1691 as_bad ("expression not a constant");
1692 return false;
1693 }
1694 add_to_lit_pool (exp, 0x0, cons_len);
1695 break;
1696
1697 default:
1698 as_bad ("Unknown/unsupported address literal type");
1699 return false;
1700 }
1701
1702 return true;
1703 }
1704
1705 \f
1706 /* Dump the contents of the literal pool that we've accumulated so far.
1707 * This aligns the pool to the size of the largest literal in the pool.
1708 */
1709
1710 static void
1711 i370_ltorg (ignore)
1712 int ignore;
1713 {
1714 int litsize;
1715 int lit_count = 0;
1716 int biggest_literal_size = 0;
1717 int biggest_align = 0;
1718 char pool_name[20];
1719
1720 if (strncmp (now_seg->name, ".text", 5))
1721 {
1722 if (i370_other_section == undefined_section)
1723 {
1724 as_bad (".ltorg without prior .using in section %s",
1725 now_seg->name);
1726 }
1727 if (i370_other_section != now_seg)
1728 {
1729 as_bad (".ltorg in section %s paired to .using in section %s",
1730 now_seg->name, i370_other_section->name);
1731 }
1732 }
1733 if (! longlong_poolP
1734 && ! word_poolP
1735 && ! short_poolP
1736 && ! byte_poolP)
1737 {
1738 /* Nothing to do */
1739 /* as_tsktsk ("Nothing to put in the pool\n"); */
1740 return;
1741 }
1742
1743 /* find largest literal .. 2 4 or 8 */
1744 lit_count = 0;
1745 while (lit_count < next_literal_pool_place)
1746 {
1747 if (biggest_literal_size < literals[lit_count].size)
1748 biggest_literal_size = literals[lit_count].size;
1749 lit_count ++;
1750 }
1751 if (1 == biggest_literal_size) biggest_align = 0;
1752 else if (2 == biggest_literal_size) biggest_align = 1;
1753 else if (4 == biggest_literal_size) biggest_align = 2;
1754 else if (8 == biggest_literal_size) biggest_align = 3;
1755 else as_bad ("bad alignment of %d bytes in literal pool", biggest_literal_size);
1756 if (0 == biggest_align) biggest_align = 1;
1757
1758
1759 /* Align pool for short, word, double word accesses */
1760 frag_align (biggest_align, 0, 0);
1761 record_alignment (now_seg, biggest_align);
1762
1763 /* Note that the gas listing will print only the first five
1764 * entries in the pool .... wonder how to make it print more ...
1765 */
1766 /* output largest literals first, then the smaller ones. */
1767 for (litsize=8; litsize; litsize /=2)
1768 {
1769 symbolS *current_poolP = NULL;
1770 switch (litsize)
1771 {
1772 case 8:
1773 current_poolP = longlong_poolP; break;
1774 case 4:
1775 current_poolP = word_poolP; break;
1776 case 2:
1777 current_poolP = short_poolP; break;
1778 case 1:
1779 current_poolP = byte_poolP; break;
1780 default:
1781 as_bad ("bad literal size\n");
1782 }
1783 if (NULL == current_poolP)
1784 continue;
1785 sprintf (pool_name, ".LITP%01d%06d", litsize, lit_pool_num);
1786 symbol_locate (current_poolP, pool_name, now_seg,
1787 (valueT) frag_now_fix (), frag_now);
1788 symbol_table_insert (current_poolP);
1789
1790 lit_count = 0;
1791 while (lit_count < next_literal_pool_place)
1792 {
1793 if (litsize == literals[lit_count].size)
1794 {
1795 #define EMIT_ADDR_CONS_SYMBOLS
1796 #ifdef EMIT_ADDR_CONS_SYMBOLS
1797 /* create a bogus symbol, add it to the pool ...
1798 * For the most part, I think this is a useless excercise,
1799 * except that having these symbol names in the objects
1800 * is vaguely useful for debugging ...
1801 */
1802 if (literals[lit_count].sym_name)
1803 {
1804 symbolS * symP = symbol_make_empty();
1805 symbol_locate (symP, literals[lit_count].sym_name, now_seg,
1806 (valueT) frag_now_fix (), frag_now);
1807 symbol_table_insert (symP);
1808 }
1809 #endif /* EMIT_ADDR_CONS_SYMBOLS */
1810
1811 emit_expr (&(literals[lit_count].exp), literals[lit_count].size);
1812 }
1813 lit_count ++;
1814 }
1815 }
1816
1817 next_literal_pool_place = 0;
1818 longlong_poolP = NULL;
1819 word_poolP = NULL;
1820 short_poolP = NULL;
1821 byte_poolP = NULL;
1822 lit_pool_num++;
1823 }
1824
1825 #endif /* LITERAL_POOL_SUPPORT */
1826
1827 \f
1828 /* add support for the HLASM-like USING directive to indicate
1829 * the base register to use ... we don't support the full
1830 * hlasm semantics for this ... we merely pluck a base address
1831 * and a register number out. We print a warning if using is
1832 * called multiple times. I suppose we should check to see
1833 * if the regno is valid ...
1834 */
1835 static void
1836 i370_using (ignore)
1837 int ignore;
1838 {
1839 expressionS ex, baseaddr;
1840 int iregno;
1841 char *star;
1842
1843 /* if "*" appears in a using, it means "." */
1844 /* replace it with "." so that expr doesn't get confused. */
1845 star = strchr (input_line_pointer, '*');
1846 if (star)
1847 *star = '.';
1848
1849 /* the first arg to using will usually be ".", but it can
1850 * be a more complex exprsssion too ... */
1851 expression (&baseaddr);
1852 if (star)
1853 *star = '*';
1854 if (O_constant != baseaddr.X_op
1855 && O_symbol != baseaddr.X_op
1856 && O_uminus != baseaddr.X_op)
1857 {
1858 as_bad (".using: base address expression illegal or too complex");
1859 }
1860
1861 if (*input_line_pointer != '\0') ++input_line_pointer;
1862
1863 /* the second arg to using had better be a register */
1864 register_name (&ex);
1865 demand_empty_rest_of_line ();
1866 iregno = ex.X_add_number;
1867
1868 if (0 == strncmp (now_seg->name, ".text", 5))
1869 {
1870 i370_using_text_baseaddr = baseaddr;
1871 i370_using_text_regno = iregno;
1872 }
1873 else
1874 {
1875 i370_using_other_baseaddr = baseaddr;
1876 i370_using_other_regno = iregno;
1877 i370_other_section = now_seg;
1878 }
1879 }
1880
1881 static void
1882 i370_drop (ignore)
1883 int ignore;
1884 {
1885 expressionS ex;
1886 int iregno;
1887
1888 register_name (&ex);
1889 demand_empty_rest_of_line ();
1890 iregno = ex.X_add_number;
1891
1892 if (0 == strncmp (now_seg->name, ".text", 5))
1893 {
1894 if (iregno != i370_using_text_regno)
1895 {
1896 as_bad ("droping register %d in section %s does not match using register %d",
1897 iregno, now_seg->name, i370_using_text_regno);
1898 }
1899 i370_using_text_regno = -1;
1900 i370_using_text_baseaddr.X_op = O_absent;
1901 }
1902 else
1903 {
1904 if (iregno != i370_using_other_regno)
1905 {
1906 as_bad ("droping register %d in section %s does not match using register %d",
1907 iregno, now_seg->name, i370_using_other_regno);
1908 }
1909 if (i370_other_section != now_seg)
1910 {
1911 as_bad ("droping register %d in section %s previously used in section %s",
1912 iregno, now_seg->name, i370_other_section->name);
1913 }
1914 i370_using_other_regno = -1;
1915 i370_using_other_baseaddr.X_op = O_absent;
1916 i370_other_section = undefined_section;
1917 }
1918 }
1919
1920 /* Make the first argument an address-relative expression
1921 * by subtracting the second argument.
1922 */
1923 static void
1924 i370_make_relative (expressionS *exx, expressionS *baseaddr)
1925 {
1926
1927 if (O_constant == baseaddr->X_op)
1928 {
1929 exx->X_op = O_symbol;
1930 exx->X_add_number -= baseaddr->X_add_number;
1931 }
1932 else if (O_symbol == baseaddr->X_op)
1933 {
1934 exx->X_op = O_subtract;
1935 exx->X_op_symbol = baseaddr->X_add_symbol;
1936 exx->X_add_number -= baseaddr->X_add_number;
1937 }
1938 else if (O_uminus == baseaddr->X_op)
1939 {
1940 exx->X_op = O_add;
1941 exx->X_op_symbol = baseaddr->X_add_symbol;
1942 exx->X_add_number += baseaddr->X_add_number;
1943 }
1944 else
1945 {
1946 as_bad ("Missing or bad .using directive");
1947 }
1948 }
1949 \f
1950 /* We need to keep a list of fixups. We can't simply generate them as
1951 we go, because that would require us to first create the frag, and
1952 that would screw up references to ``.''. */
1953
1954 struct i370_fixup
1955 {
1956 expressionS exp;
1957 int opindex;
1958 bfd_reloc_code_real_type reloc;
1959 };
1960
1961 #define MAX_INSN_FIXUPS (5)
1962
1963 /* This routine is called for each instruction to be assembled. */
1964
1965 void
1966 md_assemble (str)
1967 char *str;
1968 {
1969 char *s, *opcode_str;
1970 const struct i370_opcode *opcode;
1971 i370_insn_t insn;
1972 const unsigned char *opindex_ptr;
1973 int have_optional_index, have_optional_basereg, have_optional_reg;
1974 int skip_optional_index, skip_optional_basereg, skip_optional_reg;
1975 int use_text=0, use_other=0;
1976 int off_by_one;
1977 struct i370_fixup fixups[MAX_INSN_FIXUPS];
1978 int fc;
1979 char *f;
1980 int i;
1981 #ifdef OBJ_ELF
1982 bfd_reloc_code_real_type reloc;
1983 #endif
1984
1985 /* Get the opcode. */
1986 for (s = str; *s != '\0' && ! isspace (*s); s++)
1987 ;
1988 if (*s != '\0')
1989 *s++ = '\0';
1990 opcode_str = str;
1991
1992 /* Look up the opcode in the hash table. */
1993 opcode = (const struct i370_opcode *) hash_find (i370_hash, str);
1994 if (opcode == (const struct i370_opcode *) NULL)
1995 {
1996 const struct i370_macro *macro;
1997
1998 assert (i370_macro_hash);
1999 macro = (const struct i370_macro *) hash_find (i370_macro_hash, str);
2000 if (macro == (const struct i370_macro *) NULL)
2001 as_bad ("Unrecognized opcode: `%s'", str);
2002 else
2003 i370_macro (s, macro);
2004
2005 return;
2006 }
2007
2008 insn = opcode->opcode;
2009
2010 str = s;
2011 while (isspace (*str))
2012 ++str;
2013
2014 /* I370 operands are either expressions or address constants.
2015 Many operand types are optional. The optional operands
2016 are always surrounded by parens, and are used to denote the base
2017 register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
2018 the fully-formed "A R1, D2(X2,B2)". Note also the = sign,
2019 such as A R1,=A(i) where the address-of operator =A implies
2020 use of both a base register, and a missing index register.
2021
2022 So, before we start seriously parsing the operands, we check
2023 to see if we have an optional operand, and, if we do, we count
2024 the number of commas to see which operand should be omitted. */
2025
2026 have_optional_index = have_optional_basereg = have_optional_reg = 0;
2027 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2028 {
2029 const struct i370_operand *operand;
2030 operand = &i370_operands[*opindex_ptr];
2031 if ((operand->flags & I370_OPERAND_INDEX) != 0)
2032 have_optional_index = 1;
2033 if ((operand->flags & I370_OPERAND_BASE) != 0)
2034 have_optional_basereg = 1;
2035 if ((operand->flags & I370_OPERAND_OPTIONAL) != 0)
2036 have_optional_reg = 1;
2037 }
2038
2039 skip_optional_index = skip_optional_basereg = skip_optional_reg = 0;
2040 if (have_optional_index || have_optional_basereg)
2041 {
2042 unsigned int opcount, nwanted;
2043
2044 /* There is an optional operand. Count the number of
2045 commas and open-parens in the input line. */
2046 if (*str == '\0')
2047 opcount = 0;
2048 else
2049 {
2050 opcount = 1;
2051 s = str;
2052 while ((s = strpbrk (s, ",(=")) != (char *) NULL)
2053 {
2054 ++opcount;
2055 ++s;
2056 if (',' == *s) ++s; /* avoid counting things like (, */
2057 if ('=' == *s) { ++s; --opcount; }
2058 }
2059 }
2060
2061 /* If there are fewer operands in the line then are called
2062 for by the instruction, we want to skip the optional
2063 operand. */
2064 nwanted = strlen (opcode->operands);
2065 if (have_optional_index)
2066 {
2067 if (opcount < nwanted)
2068 skip_optional_index = 1;
2069 if (have_optional_basereg && ((opcount+1) < nwanted))
2070 skip_optional_basereg = 1;
2071 if (have_optional_reg && ((opcount+1) < nwanted))
2072 skip_optional_reg = 1;
2073 }
2074 else
2075 {
2076 if (have_optional_basereg && (opcount < nwanted))
2077 skip_optional_basereg = 1;
2078 if (have_optional_reg && (opcount < nwanted))
2079 skip_optional_reg = 1;
2080 }
2081 }
2082
2083 /* Perform some off-by-one hacks on the length field of certain instructions.
2084 * Its such a shame to have to do this, but the problem is that HLASM got
2085 * defined so that the lengths differ by one from the actual machine instructions.
2086 * this code should probably be moved to a special inster-operand routine.
2087 * Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
2088 * hack alert -- aren't *all* SS instructions affected ??
2089 */
2090 off_by_one = 0;
2091 if (0 == strcasecmp ("CLC", opcode->name)
2092 || 0 == strcasecmp ("ED", opcode->name)
2093 || 0 == strcasecmp ("EDMK", opcode->name)
2094 || 0 == strcasecmp ("MVC", opcode->name)
2095 || 0 == strcasecmp ("MVCIN", opcode->name)
2096 || 0 == strcasecmp ("MVN", opcode->name)
2097 || 0 == strcasecmp ("MVZ", opcode->name)
2098 || 0 == strcasecmp ("NC", opcode->name)
2099 || 0 == strcasecmp ("OC", opcode->name)
2100 || 0 == strcasecmp ("XC", opcode->name))
2101 off_by_one = 1;
2102
2103 /* Gather the operands. */
2104 fc = 0;
2105 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2106 {
2107 const struct i370_operand *operand;
2108 const char *errmsg;
2109 char *hold;
2110 expressionS ex;
2111
2112 operand = &i370_operands[*opindex_ptr];
2113 errmsg = NULL;
2114
2115 /* If this is an index operand, and we are skipping it,
2116 just insert a zero. */
2117 if (skip_optional_index &&
2118 ((operand->flags & I370_OPERAND_INDEX) != 0))
2119 {
2120 insn = i370_insert_operand (insn, operand, 0);
2121 continue;
2122 }
2123
2124 /* If this is the base operand, and we are skipping it,
2125 just insert the current using basreg. */
2126 if (skip_optional_basereg &&
2127 ((operand->flags & I370_OPERAND_BASE) != 0))
2128 {
2129 int basereg = -1;
2130 if (use_text)
2131 {
2132 if (0 == strncmp (now_seg->name, ".text", 5)
2133 || 0 > i370_using_other_regno)
2134 {
2135 basereg = i370_using_text_regno;
2136 }
2137 else
2138 {
2139 basereg = i370_using_other_regno;
2140 }
2141 }
2142 else if (use_other)
2143 {
2144 if (0 > i370_using_other_regno)
2145 {
2146 basereg = i370_using_text_regno;
2147 }
2148 else
2149 {
2150 basereg = i370_using_other_regno;
2151 }
2152 }
2153 if (0 > basereg)
2154 {
2155 as_bad ("not using any base register");
2156 }
2157 insn = i370_insert_operand (insn, operand, basereg);
2158 continue;
2159 }
2160
2161 /* If this is an optional operand, and we are skipping it,
2162 Use zero (since a non-zero value would denote a register) */
2163 if (skip_optional_reg
2164 && ((operand->flags & I370_OPERAND_OPTIONAL) != 0))
2165 {
2166 insn = i370_insert_operand (insn, operand, 0);
2167 continue;
2168 }
2169
2170 /* Gather the operand. */
2171 hold = input_line_pointer;
2172 input_line_pointer = str;
2173
2174 /* register names are only allowed where there are registers ... */
2175 if ((operand->flags & I370_OPERAND_GPR) != 0)
2176 {
2177 /* quickie hack to get past things like (,r13) */
2178 if (skip_optional_index && (',' == *input_line_pointer))
2179 {
2180 *input_line_pointer = ' ';
2181 input_line_pointer ++;
2182 }
2183 if (! register_name (&ex))
2184 {
2185 as_bad ("expecting a register for operand %d",
2186 opindex_ptr - opcode->operands + 1);
2187 }
2188 }
2189
2190 /* check for a address constant expression */
2191 /* We will put PSW-relative addresses in the text section,
2192 * and adress literals in the .data (or other) section. */
2193 else if (i370_addr_cons (&ex))
2194 use_other=1;
2195 else if (i370_addr_offset (&ex))
2196 use_text=1;
2197 else expression (&ex);
2198
2199 str = input_line_pointer;
2200 input_line_pointer = hold;
2201
2202 /* perform some off-by-one hacks on the length field of certain instructions.
2203 * Its such a shame to have to do this, but the problem is that HLASM got
2204 * defined so that the programmer specifies a length that is one greater
2205 * than what the machine instruction wants.
2206 * Sigh.
2207 */
2208 if (off_by_one && (0 == strcasecmp ("SS L", operand->name)))
2209 {
2210 ex.X_add_number --;
2211 }
2212
2213 if (ex.X_op == O_illegal)
2214 as_bad ("illegal operand");
2215 else if (ex.X_op == O_absent)
2216 as_bad ("missing operand");
2217 else if (ex.X_op == O_register)
2218 {
2219 insn = i370_insert_operand (insn, operand, ex.X_add_number);
2220 }
2221 else if (ex.X_op == O_constant)
2222 {
2223 #ifdef OBJ_ELF
2224 /* Allow @HA, @L, @H on constants.
2225 * Well actually, no we don't; there really don't make sense
2226 * (at least not to me) for the i370. However, this code is
2227 * left here for any dubious future expansion reasons ... */
2228 char *orig_str = str;
2229
2230 if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2231 switch (reloc)
2232 {
2233 default:
2234 str = orig_str;
2235 break;
2236
2237 case BFD_RELOC_LO16:
2238 /* X_unsigned is the default, so if the user has done
2239 something which cleared it, we always produce a
2240 signed value. */
2241 ex.X_add_number = (((ex.X_add_number & 0xffff)
2242 ^ 0x8000)
2243 - 0x8000);
2244 break;
2245
2246 case BFD_RELOC_HI16:
2247 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
2248 break;
2249
2250 case BFD_RELOC_HI16_S:
2251 ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
2252 + ((ex.X_add_number >> 15) & 1));
2253 break;
2254 }
2255 #endif
2256 insn = i370_insert_operand (insn, operand, ex.X_add_number);
2257 }
2258 #ifdef OBJ_ELF
2259 else if ((reloc = i370_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2260 {
2261 as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
2262
2263 /* We need to generate a fixup for this expression. */
2264 if (fc >= MAX_INSN_FIXUPS)
2265 as_fatal ("too many fixups");
2266 fixups[fc].exp = ex;
2267 fixups[fc].opindex = 0;
2268 fixups[fc].reloc = reloc;
2269 ++fc;
2270 }
2271 #endif /* OBJ_ELF */
2272
2273 else
2274 {
2275 /* We need to generate a fixup for this expression. */
2276 /* Typically, the expression will just be a symbol ...
2277 * printf ("insn %s needs fixup for %s \n",
2278 * opcode->name, ex.X_add_symbol->bsym->name);
2279 */
2280
2281 if (fc >= MAX_INSN_FIXUPS)
2282 as_fatal ("too many fixups");
2283 fixups[fc].exp = ex;
2284 fixups[fc].opindex = *opindex_ptr;
2285 fixups[fc].reloc = BFD_RELOC_UNUSED;
2286 ++fc;
2287 }
2288
2289 /* skip over delimiter (close paren, or comma) */
2290 if ((')' == *str) && (',' == *(str+1)))
2291 ++str;
2292 if (*str != '\0')
2293 ++str;
2294 }
2295
2296 while (isspace (*str))
2297 ++str;
2298
2299 if (*str != '\0')
2300 as_bad ("junk at end of line: `%s'", str);
2301
2302 /* Write out the instruction. */
2303 f = frag_more (opcode->len);
2304 if (4 >= opcode->len)
2305 {
2306 md_number_to_chars (f, insn.i[0], opcode->len);
2307 }
2308 else
2309 {
2310 md_number_to_chars (f, insn.i[0], 4);
2311 if (6 == opcode->len)
2312 {
2313 md_number_to_chars ((f+4), ((insn.i[1])>>16), 2);
2314 }
2315 else
2316 {
2317 /* not used --- don't have any 8 byte instructions */
2318 as_bad ("Internal Error: bad instruction length");
2319 md_number_to_chars ((f+4), insn.i[1], opcode->len -4);
2320 }
2321 }
2322
2323 /* Create any fixups. At this point we do not use a
2324 bfd_reloc_code_real_type, but instead just use the
2325 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2326 handle fixups for any operand type, although that is admittedly
2327 not a very exciting feature. We pick a BFD reloc type in
2328 md_apply_fix. */
2329 for (i = 0; i < fc; i++)
2330 {
2331 const struct i370_operand *operand;
2332
2333 operand = &i370_operands[fixups[i].opindex];
2334 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2335 {
2336 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2337 int size;
2338 fixS *fixP;
2339
2340 if (!reloc_howto)
2341 abort ();
2342
2343 size = bfd_get_reloc_size (reloc_howto);
2344
2345 if (size < 1 || size > 4)
2346 abort();
2347
2348 printf (" gwana doo fixup %d \n", i);
2349 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
2350 &fixups[i].exp, reloc_howto->pc_relative,
2351 fixups[i].reloc);
2352
2353 /* Turn off complaints that the addend is too large for things like
2354 foo+100000@ha. */
2355 switch (fixups[i].reloc)
2356 {
2357 case BFD_RELOC_16_GOTOFF:
2358 case BFD_RELOC_LO16:
2359 case BFD_RELOC_HI16:
2360 case BFD_RELOC_HI16_S:
2361 fixP->fx_no_overflow = 1;
2362 break;
2363 default:
2364 break;
2365 }
2366 }
2367 else
2368 {
2369 fix_new_exp (frag_now, f - frag_now->fr_literal, opcode->len,
2370 &fixups[i].exp,
2371 (operand->flags & I370_OPERAND_RELATIVE) != 0,
2372 ((bfd_reloc_code_real_type)
2373 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2374 }
2375 }
2376 }
2377
2378 /* Handle a macro. Gather all the operands, transform them as
2379 described by the macro, and call md_assemble recursively. All the
2380 operands are separated by commas; we don't accept parentheses
2381 around operands here. */
2382
2383 static void
2384 i370_macro (str, macro)
2385 char *str;
2386 const struct i370_macro *macro;
2387 {
2388 char *operands[10];
2389 unsigned int count;
2390 char *s;
2391 unsigned int len;
2392 const char *format;
2393 int arg;
2394 char *send;
2395 char *complete;
2396
2397 /* Gather the users operands into the operands array. */
2398 count = 0;
2399 s = str;
2400 while (1)
2401 {
2402 if (count >= sizeof operands / sizeof operands[0])
2403 break;
2404 operands[count++] = s;
2405 s = strchr (s, ',');
2406 if (s == (char *) NULL)
2407 break;
2408 *s++ = '\0';
2409 }
2410
2411 if (count != macro->operands)
2412 {
2413 as_bad ("wrong number of operands");
2414 return;
2415 }
2416
2417 /* Work out how large the string must be (the size is unbounded
2418 because it includes user input). */
2419 len = 0;
2420 format = macro->format;
2421 while (*format != '\0')
2422 {
2423 if (*format != '%')
2424 {
2425 ++len;
2426 ++format;
2427 }
2428 else
2429 {
2430 arg = strtol (format + 1, &send, 10);
2431 know (send != format && arg >= 0 && arg < count);
2432 len += strlen (operands[arg]);
2433 format = send;
2434 }
2435 }
2436
2437 /* Put the string together. */
2438 complete = s = (char *) alloca (len + 1);
2439 format = macro->format;
2440 while (*format != '\0')
2441 {
2442 if (*format != '%')
2443 *s++ = *format++;
2444 else
2445 {
2446 arg = strtol (format + 1, &send, 10);
2447 strcpy (s, operands[arg]);
2448 s += strlen (s);
2449 format = send;
2450 }
2451 }
2452 *s = '\0';
2453
2454 /* Assemble the constructed instruction. */
2455 md_assemble (complete);
2456 }
2457 \f
2458 #ifdef OBJ_ELF
2459 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2460
2461 int
2462 i370_section_letter (letter, ptr_msg)
2463 int letter;
2464 char **ptr_msg;
2465 {
2466 if (letter == 'e')
2467 return SHF_EXCLUDE;
2468
2469 *ptr_msg = "Bad .section directive: want a,w,x,e in string";
2470 return 0;
2471 }
2472
2473 int
2474 i370_section_word (str, len)
2475 char *str;
2476 size_t len;
2477 {
2478 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2479 return SHF_EXCLUDE;
2480
2481 return -1;
2482 }
2483
2484 int
2485 i370_section_type (str, len)
2486 char *str;
2487 size_t len;
2488 {
2489 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2490 return SHT_ORDERED;
2491
2492 return -1;
2493 }
2494
2495 int
2496 i370_section_flags (flags, attr, type)
2497 int flags;
2498 int attr;
2499 int type;
2500 {
2501 if (type == SHT_ORDERED)
2502 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2503
2504 if (attr & SHF_EXCLUDE)
2505 flags |= SEC_EXCLUDE;
2506
2507 return flags;
2508 }
2509 #endif /* OBJ_ELF */
2510
2511 \f
2512 /* Pseudo-op handling. */
2513
2514 /* The .byte pseudo-op. This is similar to the normal .byte
2515 pseudo-op, but it can also take a single ASCII string. */
2516
2517 static void
2518 i370_byte (ignore)
2519 int ignore;
2520 {
2521 if (*input_line_pointer != '\"')
2522 {
2523 cons (1);
2524 return;
2525 }
2526
2527 /* Gather characters. A real double quote is doubled. Unusual
2528 characters are not permitted. */
2529 ++input_line_pointer;
2530 while (1)
2531 {
2532 char c;
2533
2534 c = *input_line_pointer++;
2535
2536 if (c == '\"')
2537 {
2538 if (*input_line_pointer != '\"')
2539 break;
2540 ++input_line_pointer;
2541 }
2542
2543 FRAG_APPEND_1_CHAR (c);
2544 }
2545
2546 demand_empty_rest_of_line ();
2547 }
2548 \f
2549 /* The .tc pseudo-op. This is used when generating XCOFF and ELF.
2550 This takes two or more arguments.
2551
2552 When generating XCOFF output, the first argument is the name to
2553 give to this location in the toc; this will be a symbol with class
2554 TC. The rest of the arguments are 4 byte values to actually put at
2555 this location in the TOC; often there is just one more argument, a
2556 relocateable symbol reference.
2557
2558 When not generating XCOFF output, the arguments are the same, but
2559 the first argument is simply ignored. */
2560
2561 static void
2562 i370_tc (ignore)
2563 int ignore;
2564 {
2565
2566 /* Skip the TOC symbol name. */
2567 while (is_part_of_name (*input_line_pointer)
2568 || *input_line_pointer == '['
2569 || *input_line_pointer == ']'
2570 || *input_line_pointer == '{'
2571 || *input_line_pointer == '}')
2572 ++input_line_pointer;
2573
2574 /* Align to a four byte boundary. */
2575 frag_align (2, 0, 0);
2576 record_alignment (now_seg, 2);
2577
2578 if (*input_line_pointer != ',')
2579 demand_empty_rest_of_line ();
2580 else
2581 {
2582 ++input_line_pointer;
2583 cons (4);
2584 }
2585 }
2586 \f
2587 /* Turn a string in input_line_pointer into a floating point constant
2588 of type TYPE, and store the appropriate bytes in *LITP. The number
2589 of LITTLENUMS emitted is stored in *SIZEP. An error message is
2590 returned, or NULL on OK. */
2591
2592 char *
2593 md_atof (type, litp, sizep)
2594 int type;
2595 char *litp;
2596 int *sizep;
2597 {
2598 int prec;
2599 LITTLENUM_TYPE words[4];
2600 char *t;
2601 int i;
2602
2603 switch (type)
2604 {
2605 case 'f':
2606 case 'E':
2607 type = 'f';
2608 prec = 2;
2609 break;
2610
2611 case 'd':
2612 case 'D':
2613 type = 'd';
2614 prec = 4;
2615 break;
2616
2617 default:
2618 *sizep = 0;
2619 return "bad call to md_atof";
2620 }
2621
2622 /* 360/370/390 have two float formats: an old, funky 360 single-precision
2623 * format, and the ieee format. Support only the ieee format. */
2624 t = atof_ieee (input_line_pointer, type, words);
2625 if (t)
2626 input_line_pointer = t;
2627
2628 *sizep = prec * 2;
2629
2630 for (i = 0; i < prec; i++)
2631 {
2632 md_number_to_chars (litp, (valueT) words[i], 2);
2633 litp += 2;
2634 }
2635
2636 return NULL;
2637 }
2638
2639 /* Write a value out to the object file, using the appropriate
2640 endianness. */
2641
2642 void
2643 md_number_to_chars (buf, val, n)
2644 char *buf;
2645 valueT val;
2646 int n;
2647 {
2648 number_to_chars_bigendian (buf, val, n);
2649 }
2650
2651 /* Align a section (I don't know why this is machine dependent). */
2652
2653 valueT
2654 md_section_align (seg, addr)
2655 asection *seg;
2656 valueT addr;
2657 {
2658 int align = bfd_get_section_alignment (stdoutput, seg);
2659
2660 return (addr + (1 << align) - 1) & (-1 << align);
2661 }
2662
2663 /* We don't have any form of relaxing. */
2664
2665 int
2666 md_estimate_size_before_relax (fragp, seg)
2667 fragS *fragp;
2668 asection *seg;
2669 {
2670 abort ();
2671 return 0;
2672 }
2673
2674 /* Convert a machine dependent frag. We never generate these. */
2675
2676 void
2677 md_convert_frag (abfd, sec, fragp)
2678 bfd *abfd;
2679 asection *sec;
2680 fragS *fragp;
2681 {
2682 abort ();
2683 }
2684
2685 /* We have no need to default values of symbols. */
2686
2687 /*ARGSUSED*/
2688 symbolS *
2689 md_undefined_symbol (name)
2690 char *name;
2691 {
2692 return 0;
2693 }
2694 \f
2695 /* Functions concerning relocs. */
2696
2697 /* The location from which a PC relative jump should be calculated,
2698 given a PC relative reloc. */
2699
2700 long
2701 md_pcrel_from_section (fixp, sec)
2702 fixS *fixp;
2703 segT sec;
2704 {
2705 return fixp->fx_frag->fr_address + fixp->fx_where;
2706 }
2707
2708
2709 /* Apply a fixup to the object code. This is called for all the
2710 fixups we generated by the call to fix_new_exp, above. In the call
2711 above we used a reloc code which was the largest legal reloc code
2712 plus the operand index. Here we undo that to recover the operand
2713 index. At this point all symbol values should be fully resolved,
2714 and we attempt to completely resolve the reloc. If we can not do
2715 that, we determine the correct reloc code and put it back in the
2716 fixup.
2717
2718 See gas/cgen.c for more sample code and explanations of what's
2719 going on here ...
2720 */
2721
2722 int
2723 md_apply_fix3 (fixp, valuep, seg)
2724 fixS *fixp;
2725 valueT *valuep;
2726 segT seg;
2727 {
2728 valueT value;
2729
2730 value = *valuep;
2731 if (fixp->fx_addsy != NULL)
2732 {
2733 /* Notes:
2734 Branches to labels will come in here with fixp->fx_pcrel set to 1
2735 and fixp->fx_subsy not null, and holding the value of the base
2736 (i.e. the value of the .using). These we want to ignore.
2737
2738 'Strong' and 'weak' symbols will come in here with
2739 fixp->fx_pcrel==0, fixp->fx_addsy defined, and
2740 *valuep holding the value of the symbol.
2741
2742 'Strong' symbols will have S_GET_VALUE(fx_addsy) equal to zero,
2743 whereas 'weak' symbols will have S_GET_VALUE(fx_addsy) set to the
2744 symbol value (usually).
2745
2746 We want to subtract S_GET_VALUE(fx_addsy) if it set, and
2747 for all practical purposes, do a fixup with value zero. This
2748 is because the linker/loader, at a later time, will do this
2749 fixup with the correct value. If we fixup now with a value,
2750 it will get double-fixed, leading to garbage.
2751
2752 Note that subsy will also be set for strong/weak symbols
2753 when the user program was compiled with -g. In that case,
2754 subsy will hold the base address (i.e. the .using address).
2755 */
2756
2757 if (fixp->fx_addsy->sy_used_in_reloc
2758 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
2759 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
2760 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
2761 value -= S_GET_VALUE (fixp->fx_addsy);
2762
2763 #ifdef DEBUG
2764 printf ("\nmd_apply_fix3: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
2765 S_GET_NAME (fixp->fx_addsy),
2766 fixp->fx_frag->fr_address + fixp->fx_where,
2767 fixp->fx_file, fixp->fx_line,
2768 S_GET_VALUE (fixp->fx_addsy), value);
2769 #endif
2770 }
2771 else
2772 {
2773 fixp->fx_done = 1;
2774 return 1;
2775 }
2776
2777 /* Apply fixups to operands. Note that there should be no relocations
2778 for any operands, since no instruction ever takes an operand
2779 that requires reloc. */
2780 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
2781 {
2782 int opindex;
2783 const struct i370_operand *operand;
2784 char *where;
2785 i370_insn_t insn;
2786
2787 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
2788
2789 operand = &i370_operands[opindex];
2790
2791 #ifdef DEBUG
2792 printf ("\nmd_apply_fix3: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
2793 operand->name,
2794 fixp->fx_frag->fr_address + fixp->fx_where,
2795 fixp->fx_file, fixp->fx_line,
2796 value);
2797 #endif
2798 /* Fetch the instruction, insert the fully resolved operand
2799 value, and stuff the instruction back again.
2800 fisxp->fx_size is the length of the instruction. */
2801 where = fixp->fx_frag->fr_literal + fixp->fx_where;
2802 insn.i[0] = bfd_getb32 ((unsigned char *) where);
2803 if (6 <= fixp->fx_size)
2804 { /* deal with 48-bit insn's */
2805 insn.i[1] = bfd_getb32 (((unsigned char *) where)+4);
2806 }
2807 insn = i370_insert_operand (insn, operand, (offsetT) value);
2808 bfd_putb32 ((bfd_vma) insn.i[0], (unsigned char *) where);
2809 if (6 <= fixp->fx_size)
2810 { /* deal with 48-bit insn's */
2811 bfd_putb32 ((bfd_vma) insn.i[1], (((unsigned char *) where)+4));
2812 }
2813
2814 /* we are done, right? right !! */
2815 fixp->fx_done = 1;
2816 if (fixp->fx_done)
2817 {
2818 /* Nothing else to do here. */
2819 return 1;
2820 }
2821
2822 /* Determine a BFD reloc value based on the operand information.
2823 We are only prepared to turn a few of the operands into
2824 relocs. In fact, we support *zero* operand relocations ...
2825 Why? Because we are not expecting the compiler to generate
2826 any operands that need relocation. Due to the 12-bit naturew of
2827 i370 addressing, this would be unusual. */
2828 #if 0
2829 if ((operand->flags & I370_OPERAND_RELATIVE) != 0
2830 && operand->bits == 12
2831 && operand->shift == 0)
2832 fixp->fx_r_type = BFD_RELOC_I370_D12;
2833 else
2834 #endif
2835 {
2836 char *sfile;
2837 unsigned int sline;
2838
2839 /* Use expr_symbol_where to see if this is an expression
2840 symbol. */
2841 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
2842 as_bad_where (fixp->fx_file, fixp->fx_line,
2843 "unresolved expression that must be resolved");
2844 else
2845 as_bad_where (fixp->fx_file, fixp->fx_line,
2846 "unsupported relocation type");
2847 fixp->fx_done = 1;
2848 return 1;
2849 }
2850 }
2851 else
2852 {
2853 /* We branch to here if the fixup is not to a symbol that
2854 * appears in an instruction operand, but is rather some
2855 * declared storage.
2856 */
2857 #ifdef OBJ_ELF
2858 i370_elf_validate_fix (fixp, seg);
2859 #endif
2860 #ifdef DEBUG
2861 printf ("md_apply_fix3: reloc case %d in segment %s %s:%d\n",
2862 fixp->fx_r_type, segment_name (seg), fixp->fx_file, fixp->fx_line);
2863 printf ("\tcurrent fixup value is 0x%x \n", value);
2864 #endif
2865 switch (fixp->fx_r_type)
2866 {
2867 case BFD_RELOC_32:
2868 case BFD_RELOC_CTOR:
2869 if (fixp->fx_pcrel)
2870 fixp->fx_r_type = BFD_RELOC_32_PCREL;
2871 /* fall through */
2872
2873 case BFD_RELOC_RVA:
2874 case BFD_RELOC_32_PCREL:
2875 case BFD_RELOC_32_BASEREL:
2876 #ifdef DEBUG
2877 printf ("\t32 bit relocation at 0x%x\n",
2878 fixp->fx_frag->fr_address + fixp->fx_where);
2879 #endif
2880 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2881 value, 4);
2882 break;
2883
2884 case BFD_RELOC_LO16:
2885 case BFD_RELOC_16:
2886 if (fixp->fx_pcrel)
2887 as_bad_where (fixp->fx_file, fixp->fx_line,
2888 "cannot emit PC relative %s relocation%s%s",
2889 bfd_get_reloc_code_name (fixp->fx_r_type),
2890 fixp->fx_addsy != NULL ? " against " : "",
2891 (fixp->fx_addsy != NULL
2892 ? S_GET_NAME (fixp->fx_addsy)
2893 : ""));
2894
2895 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2896 value, 2);
2897 break;
2898
2899 /* This case happens when you write, for example,
2900 lis %r3,(L1-L2)@ha
2901 where L1 and L2 are defined later. */
2902 case BFD_RELOC_HI16:
2903 if (fixp->fx_pcrel)
2904 abort ();
2905 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2906 value >> 16, 2);
2907 break;
2908 case BFD_RELOC_HI16_S:
2909 if (fixp->fx_pcrel)
2910 abort ();
2911 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2912 (value + 0x8000) >> 16, 2);
2913 break;
2914
2915 case BFD_RELOC_8:
2916 if (fixp->fx_pcrel)
2917 abort ();
2918
2919 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
2920 value, 1);
2921 break;
2922
2923 default:
2924 fprintf(stderr,
2925 "Gas failure, reloc value %d\n", fixp->fx_r_type);
2926 fflush(stderr);
2927 abort ();
2928 }
2929 }
2930
2931 fixp->fx_addnumber = value;
2932
2933 return 1;
2934 }
2935
2936 /* Generate a reloc for a fixup. */
2937
2938 arelent *
2939 tc_gen_reloc (seg, fixp)
2940 asection *seg;
2941 fixS *fixp;
2942 {
2943 arelent *reloc;
2944
2945 reloc = (arelent *) xmalloc (sizeof (arelent));
2946
2947 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2948 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
2949 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
2950 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
2951 if (reloc->howto == (reloc_howto_type *) NULL)
2952 {
2953 as_bad_where (fixp->fx_file, fixp->fx_line,
2954 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
2955 return NULL;
2956 }
2957 reloc->addend = fixp->fx_addnumber;
2958
2959 #ifdef DEBUG
2960 printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
2961 fixp->fx_addsy->bsym->name,
2962 fixp->fx_file, fixp->fx_line,
2963 reloc->address, reloc->addend);
2964 #endif
2965
2966 return reloc;
2967 }
This page took 0.147565 seconds and 5 git commands to generate.