source: trunk/binutils/gas/config/tc-i370.c@ 2562

Last change on this file since 2562 was 610, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r609,
which included commits to RCS files with non-trunk default branches.

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