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-2017 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
6 This file is part of GAS, the GNU Assembler.
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 3, or (at your option)
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.
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, 51 Franklin Street - Fifth Floor, Boston, MA
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. */
30 #include "safe-ctype.h"
32 #include "struc-symbol.h"
34 #include "opcode/i370.h"
40 /* This is the assembler for the System/390 Architecture. */
42 /* Tell the main code what the endianness is. */
43 extern int target_big_endian
;
46 /* Generic assembler global variables which must be defined by all
50 /* This string holds the chars that always start a comment. If the
51 pre-processor is disabled, these aren't very useful. The macro
52 tc_comment_chars points to this. We use this, rather than the
53 usual comment_chars, so that we can switch for Solaris conventions. */
54 static const char i370_eabi_comment_chars
[] = "#";
56 const char *i370_comment_chars
= i370_eabi_comment_chars
;
58 const char comment_chars
[] = "#";
61 /* Characters which start a comment at the beginning of a line. */
62 const char line_comment_chars
[] = "#*";
64 /* Characters which may be used to separate multiple commands on a
66 const char line_separator_chars
[] = ";";
68 /* Characters which are used to indicate an exponent in a floating
70 const char EXP_CHARS
[] = "eE";
72 /* Characters which mean that a number is a floating point constant,
74 const char FLT_CHARS
[] = "dD";
77 md_show_usage (FILE *stream
)
80 S/370 options: (these have not yet been tested and may not work) \n\
82 -mregnames Allow symbolic names for registers\n\
83 -mno-regnames Do not allow symbolic names for registers\n");
86 -mrelocatable support for GCC's -mrelocatble option\n\
87 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
88 -V print assembler version number\n");
92 /* Whether to use user friendly register names. */
93 #define TARGET_REG_NAMES_P TRUE
95 static bfd_boolean reg_names_p
= TARGET_REG_NAMES_P
;
98 /* Predefined register names if -mregnames
99 In general, there are lots of them, in an attempt to be compatible
100 with a number of assemblers. */
102 /* Structure to hold information about predefined registers. */
109 /* List of registers that are pre-defined:
111 Each general register has predefined names of the form:
112 1. r<reg_num> which has the value <reg_num>.
113 2. r.<reg_num> which has the value <reg_num>.
115 Each floating point register has predefined names of the form:
116 1. f<reg_num> which has the value <reg_num>.
117 2. f.<reg_num> which has the value <reg_num>.
119 There are only four floating point registers, and these are
120 commonly labelled 0,2,4 and 6. Thus, there is no f1, f3, etc.
122 There are individual registers as well:
123 rbase or r.base has the value 3 (base register)
124 rpgt or r.pgt has the value 4 (page origin table pointer)
125 rarg or r.arg has the value 11 (argument pointer)
126 rtca or r.tca has the value 12 (table of contents pointer)
127 rtoc or r.toc has the value 12 (table of contents pointer)
128 sp or r.sp has the value 13 (stack pointer)
129 dsa or r.dsa has the value 13 (stack pointer)
130 lr has the value 14 (link reg)
132 The table is sorted. Suitable for searching by a binary search. */
134 static const struct pd_reg pre_defined_registers
[] =
136 { "arg", 11 }, /* Argument Pointer. */
137 { "base", 3 }, /* Base Reg. */
139 { "f.0", 0 }, /* Floating point registers. */
149 { "dsa",13 }, /* Stack pointer. */
150 { "lr", 14 }, /* Link Register. */
151 { "pgt", 4 }, /* Page Origin Table Pointer. */
153 { "r.0", 0 }, /* General Purpose Registers. */
170 { "r.arg", 11 }, /* Argument Pointer. */
171 { "r.base", 3 }, /* Base Reg. */
172 { "r.dsa", 13 }, /* Stack Pointer. */
173 { "r.pgt", 4 }, /* Page Origin Table Pointer. */
174 { "r.sp", 13 }, /* Stack Pointer. */
176 { "r.tca", 12 }, /* Pointer to the table of contents. */
177 { "r.toc", 12 }, /* Pointer to the table of contents. */
179 { "r0", 0 }, /* More general purpose registers. */
196 { "rbase", 3 }, /* Base Reg. */
198 { "rtca", 12 }, /* Pointer to the table of contents. */
199 { "rtoc", 12 }, /* Pointer to the table of contents. */
201 { "sp", 13 }, /* Stack Pointer. */
205 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
207 /* Given NAME, find the register number associated with that name, return
208 the integer value associated with the given name or -1 on failure. */
211 reg_name_search (const struct pd_reg
*regs
,
215 int middle
, low
, high
;
223 middle
= (low
+ high
) / 2;
224 cmp
= strcasecmp (name
, regs
[middle
].name
);
230 return regs
[middle
].value
;
237 /* Summary of register_name().
239 in: Input_line_pointer points to 1st char of operand.
242 The operand may have been a register: in this case, X_op == O_register,
243 X_add_number is set to the register number, and truth is returned.
244 Input_line_pointer->(next non-blank) char after operand, or is in its
248 register_name (expressionS
*expressionP
)
255 /* Find the spelling of the operand. */
256 start
= name
= input_line_pointer
;
257 if (name
[0] == '%' && ISALPHA (name
[1]))
258 name
= ++input_line_pointer
;
260 else if (!reg_names_p
)
264 name
= ++input_line_pointer
;
266 /* If it's a number, treat it as a number. If it's alpha, look to
267 see if it's in the register table. */
268 if (!ISALPHA (name
[0]))
269 reg_number
= get_single_number ();
272 c
= get_symbol_name (&name
);
273 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
275 /* Put back the delimiting char. */
276 (void) restore_line_pointer (c
);
279 /* If numeric, make sure it's not out of bounds. */
280 if ((0 <= reg_number
) && (16 >= reg_number
))
282 expressionP
->X_op
= O_register
;
283 expressionP
->X_add_number
= reg_number
;
285 /* Make the rest nice. */
286 expressionP
->X_add_symbol
= NULL
;
287 expressionP
->X_op_symbol
= NULL
;
291 /* Reset the line as if we had not done anything. */
292 input_line_pointer
= start
;
296 /* Local variables. */
298 /* The type of processor we are assembling for. This is one or more
299 of the I370_OPCODE flags defined in opcode/i370.h. */
300 static int i370_cpu
= 0;
302 /* The base register to use for opcode with optional operands.
303 We define two of these: "text" and "other". Normally, "text"
304 would get used in the .text section for branches, while "other"
305 gets used in the .data section for address constants.
307 The idea of a second base register in a different section
308 is foreign to the usual HLASM-style semantics; however, it
309 allows us to provide support for dynamically loaded libraries,
310 by allowing us to place address constants in a section other
311 than the text section. The "other" section need not be the
312 .data section, it can be any section that isn't the .text section.
314 Note that HLASM defines a multiple, concurrent .using semantic
315 that we do not: in calculating offsets, it uses either the most
316 recent .using directive, or the one with the smallest displacement.
317 This allows HLASM to support a quasi-block-scope-like behaviour.
318 Handy for people writing assembly by hand ... but not supported
320 static int i370_using_text_regno
= -1;
321 static int i370_using_other_regno
= -1;
323 /* The base address for address literals. */
324 static expressionS i370_using_text_baseaddr
;
325 static expressionS i370_using_other_baseaddr
;
327 /* the "other" section, used only for syntax error detection. */
328 static segT i370_other_section
= undefined_section
;
330 /* Opcode hash table. */
331 static struct hash_control
*i370_hash
;
333 /* Macro hash table. */
334 static struct hash_control
*i370_macro_hash
;
337 /* What type of shared library support to use. */
338 static enum { SHLIB_NONE
, SHLIB_PIC
, SHILB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
341 /* Flags to set in the elf header. */
342 static flagword i370_flags
= 0;
344 #ifndef WORKING_DOT_WORD
345 int md_short_jump_size
= 4;
346 int md_long_jump_size
= 4;
350 const char *md_shortopts
= "l:um:K:VQ:";
352 const char *md_shortopts
= "um:";
354 struct option md_longopts
[] =
356 {NULL
, no_argument
, NULL
, 0}
358 size_t md_longopts_size
= sizeof (md_longopts
);
361 md_parse_option (int c
, const char *arg
)
366 /* -u means that any undefined symbols should be treated as
367 external, which is the default for gas anyhow. */
372 /* Recognize -K PIC */
373 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
376 i370_flags
|= EF_I370_RELOCATABLE_LIB
;
386 /* -m360 mean to assemble for the ancient 360 architecture. */
387 if (strcmp (arg
, "360") == 0 || strcmp (arg
, "i360") == 0)
388 i370_cpu
= I370_OPCODE_360
;
389 /* -mxa means to assemble for the IBM 370 XA. */
390 else if (strcmp (arg
, "xa") == 0)
391 i370_cpu
= I370_OPCODE_370_XA
;
392 /* -many means to assemble for any architecture (370/XA). */
393 else if (strcmp (arg
, "any") == 0)
394 i370_cpu
= I370_OPCODE_370
;
396 else if (strcmp (arg
, "regnames") == 0)
399 else if (strcmp (arg
, "no-regnames") == 0)
403 /* -mrelocatable/-mrelocatable-lib -- warn about
404 initializations that require relocation. */
405 else if (strcmp (arg
, "relocatable") == 0)
407 shlib
= SHILB_MRELOCATABLE
;
408 i370_flags
|= EF_I370_RELOCATABLE
;
410 else if (strcmp (arg
, "relocatable-lib") == 0)
412 shlib
= SHILB_MRELOCATABLE
;
413 i370_flags
|= EF_I370_RELOCATABLE_LIB
;
418 as_bad (_("invalid switch -m%s"), arg
);
424 /* -V: SVR4 argument to print version ID. */
429 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
430 should be emitted or not. FIXME: Not implemented. */
444 /* Set i370_cpu if it is not already set.
445 Currently defaults to the reasonable superset;
446 but can be made more fine grained if desired. */
451 const char *default_os
= TARGET_OS
;
452 const char *default_cpu
= TARGET_CPU
;
454 /* Override with the superset for the moment. */
455 i370_cpu
= I370_OPCODE_ESA390_SUPERSET
;
458 if (strcmp (default_cpu
, "i360") == 0)
459 i370_cpu
= I370_OPCODE_360
;
460 else if (strcmp (default_cpu
, "i370") == 0)
461 i370_cpu
= I370_OPCODE_370
;
462 else if (strcmp (default_cpu
, "XA") == 0)
463 i370_cpu
= I370_OPCODE_370_XA
;
465 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
469 /* Figure out the BFD architecture to use.
470 FIXME: specify the different 370 architectures. */
472 enum bfd_architecture
475 return bfd_arch_i370
;
478 /* This function is called when the assembler starts up. It is called
479 after the options have been parsed and the output file has been
485 const struct i370_opcode
*op
;
486 const struct i370_opcode
*op_end
;
487 const struct i370_macro
*macro
;
488 const struct i370_macro
*macro_end
;
489 bfd_boolean dup_insn
= FALSE
;
494 /* Set the ELF flags if desired. */
496 bfd_set_private_flags (stdoutput
, i370_flags
);
499 /* Insert the opcodes into a hash table. */
500 i370_hash
= hash_new ();
502 op_end
= i370_opcodes
+ i370_num_opcodes
;
503 for (op
= i370_opcodes
; op
< op_end
; op
++)
505 know ((op
->opcode
.i
[0] & op
->mask
.i
[0]) == op
->opcode
.i
[0]
506 && (op
->opcode
.i
[1] & op
->mask
.i
[1]) == op
->opcode
.i
[1]);
508 if ((op
->flags
& i370_cpu
) != 0)
512 retval
= hash_insert (i370_hash
, op
->name
, (void *) op
);
513 if (retval
!= (const char *) NULL
)
515 as_bad (_("Internal assembler error for instruction %s"), op
->name
);
521 /* Insert the macros into a hash table. */
522 i370_macro_hash
= hash_new ();
524 macro_end
= i370_macros
+ i370_num_macros
;
525 for (macro
= i370_macros
; macro
< macro_end
; macro
++)
527 if ((macro
->flags
& i370_cpu
) != 0)
531 retval
= hash_insert (i370_macro_hash
, macro
->name
, (void *) macro
);
532 if (retval
!= (const char *) NULL
)
534 as_bad (_("Internal assembler error for macro %s"), macro
->name
);
544 /* Insert an operand value into an instruction. */
547 i370_insert_operand (i370_insn_t insn
,
548 const struct i370_operand
*operand
,
555 /* Used for 48-bit insn's. */
557 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
559 as_bad ("%s", errmsg
);
562 /* This is used only for 16, 32 bit insn's. */
563 insn
.i
[0] |= (((long) val
& ((1 << operand
->bits
) - 1))
571 /* Parse @got, etc. and return the desired relocation.
572 Currently, i370 does not support (don't really need to support) any
573 of these fancier markups ... for example, no one is going to
574 write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
575 So basically, we could get away with this routine returning
576 BFD_RELOC_UNUSED in all circumstances. However, I'll leave
577 in for now in case someone ambitious finds a good use for this stuff ...
578 this routine was pretty much just copied from the powerpc code ... */
580 static bfd_reloc_code_real_type
581 i370_elf_suffix (char **str_p
, expressionS
*exp_p
)
587 bfd_reloc_code_real_type reloc
;
597 #define MAP(str,reloc) { str, sizeof (str) - 1, reloc }
599 static struct map_bfd mapping
[] =
601 /* warnings with -mrelocatable. */
602 MAP ("fixup", BFD_RELOC_CTOR
),
603 { (char *)0, 0, BFD_RELOC_UNUSED
}
607 return BFD_RELOC_UNUSED
;
609 for (ch
= *str
, str2
= ident
;
610 (str2
< ident
+ sizeof (ident
) - 1
611 && (ISALNUM (ch
) || ch
== '@'));
613 *str2
++ = TOLOWER (ch
);
619 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
620 if (ch
== ptr
->string
[0]
621 && len
== ptr
->length
622 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
624 if (exp_p
->X_add_number
!= 0
625 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
626 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
627 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
628 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
629 as_warn (_("identifier+constant@got means identifier@got+constant"));
631 /* Now check for identifier@suffix+constant */
632 if (*str
== '-' || *str
== '+')
634 char *orig_line
= input_line_pointer
;
637 input_line_pointer
= str
;
638 expression (&new_exp
);
639 if (new_exp
.X_op
== O_constant
)
641 exp_p
->X_add_number
+= new_exp
.X_add_number
;
642 str
= input_line_pointer
;
645 if (&input_line_pointer
!= str_p
)
646 input_line_pointer
= orig_line
;
653 return BFD_RELOC_UNUSED
;
656 /* Like normal .long/.short/.word, except support @got, etc.
657 Clobbers input_line_pointer, checks end-of-line. */
660 i370_elf_cons (int nbytes
) /* 1=.byte, 2=.word, 4=.long. */
663 bfd_reloc_code_real_type reloc
;
665 if (is_it_end_of_statement ())
667 demand_empty_rest_of_line ();
675 if (exp
.X_op
== O_symbol
676 && *input_line_pointer
== '@'
677 && (reloc
= i370_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
679 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
680 int size
= bfd_get_reloc_size (reloc_howto
);
683 as_bad (ngettext ("%s relocations do not fit in %u byte",
684 "%s relocations do not fit in %u bytes",
686 reloc_howto
->name
, nbytes
);
689 char *p
= frag_more ((int) nbytes
);
690 int offset
= nbytes
- size
;
692 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
696 emit_expr (&exp
, (unsigned int) nbytes
);
698 while (*input_line_pointer
++ == ',');
700 input_line_pointer
--; /* Put terminator back into stream. */
701 demand_empty_rest_of_line ();
705 /* ASCII to EBCDIC conversion table. */
706 static unsigned char ascebc
[256] =
708 /*00 NL SH SX EX ET NQ AK BL */
709 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
710 /*08 BS HT LF VT FF CR SO SI */
711 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
712 /*10 DL D1 D2 D3 D4 NK SN EB */
713 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
714 /*18 CN EM SB EC FS GS RS US */
715 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
716 /*20 SP ! " # $ % & ' */
717 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
718 /*28 ( ) * + , - . / */
719 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
720 /*30 0 1 2 3 4 5 6 7 */
721 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
722 /*38 8 9 : ; < = > ? */
723 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
724 /*40 @ A B C D E F G */
725 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
726 /*48 H I J K L M N O */
727 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
728 /*50 P Q R S T U V W */
729 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
730 /*58 X Y Z [ \ ] ^ _ */
731 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
732 /*60 ` a b c d e f g */
733 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
734 /*68 h i j k l m n o */
735 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
736 /*70 p q r s t u v w */
737 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
738 /*78 x y z { | } ~ DL */
739 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
740 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
741 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
742 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
743 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
744 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
745 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
746 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
747 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
748 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
749 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
750 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
751 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
752 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
753 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
754 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
755 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
758 /* EBCDIC to ASCII conversion table. */
759 unsigned char ebcasc
[256] =
761 /*00 NU SH SX EX PF HT LC DL */
762 0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
763 /*08 SM VT FF CR SO SI */
764 0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
765 /*10 DE D1 D2 TM RS NL BS IL */
766 0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
767 /*18 CN EM CC C1 FS GS RS US */
768 0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
769 /*20 DS SS FS BP LF EB EC */
770 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
771 /*28 SM C2 EQ AK BL */
772 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
773 /*30 SY PN RS UC ET */
774 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
776 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
778 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
780 0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
782 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
784 0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
786 0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
788 0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
790 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
791 /*78 ` : # @ ' = " */
792 0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
793 /*80 a b c d e f g */
794 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
796 0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
797 /*90 j k l m n o p */
798 0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
800 0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
801 /*A0 ~ s t u v w x */
802 0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
804 0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
806 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
808 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
809 /*C0 { A B C D E F G */
810 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
812 0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
813 /*D0 } J K L M N O P */
814 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
816 0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
817 /*E0 \ S T U V W X */
818 0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
820 0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
821 /*F0 0 1 2 3 4 5 6 7 */
822 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
824 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
827 /* EBCDIC translation tables needed for 3270 support. */
830 i370_ebcdic (int unused ATTRIBUTE_UNUSED
)
836 nbytes
= strlen (input_line_pointer
);
837 end
= input_line_pointer
+ nbytes
;
838 while ('\r' == *end
) end
--;
839 while ('\n' == *end
) end
--;
841 delim
= *input_line_pointer
;
842 if (('\'' == delim
) || ('\"' == delim
))
844 input_line_pointer
++;
845 end
= rindex (input_line_pointer
, delim
);
848 if (end
> input_line_pointer
)
850 nbytes
= end
- input_line_pointer
+1;
851 p
= frag_more (nbytes
);
852 while (end
> input_line_pointer
)
854 *p
= ascebc
[(unsigned char) (*input_line_pointer
)];
855 ++p
; ++input_line_pointer
;
859 if (delim
== *input_line_pointer
) ++input_line_pointer
;
863 /* Stub out a couple of routines. */
866 i370_rmode (int unused ATTRIBUTE_UNUSED
)
868 as_tsktsk ("rmode ignored");
872 i370_dsect (int sect
)
874 char *save_line
= input_line_pointer
;
875 static char section
[] = ".data\n";
877 /* Just pretend this is .section .data. */
878 input_line_pointer
= section
;
879 obj_elf_section (sect
);
881 input_line_pointer
= save_line
;
885 i370_csect (int unused ATTRIBUTE_UNUSED
)
887 as_tsktsk ("csect not supported");
891 /* DC Define Const is only partially supported.
892 For sample code on what to do, look at i370_elf_cons() above.
893 This code handles pseudoops of the style
894 DC D'3.141592653' # in sysv4, .double 3.14159265
895 DC F'1' # in sysv4, .long 1. */
898 i370_dc (int unused ATTRIBUTE_UNUSED
)
906 if (is_it_end_of_statement ())
908 demand_empty_rest_of_line ();
912 /* Figure out the size. */
913 type
= *input_line_pointer
++;
916 case 'H': /* 16-bit */
919 case 'E': /* 32-bit */
920 case 'F': /* 32-bit */
923 case 'D': /* 64-bit */
927 as_bad (_("unsupported DC type"));
931 /* Get rid of pesky quotes. */
932 if ('\'' == *input_line_pointer
)
934 ++input_line_pointer
;
935 clse
= strchr (input_line_pointer
, '\'');
939 as_bad (_("missing end-quote"));
942 if ('\"' == *input_line_pointer
)
944 ++input_line_pointer
;
945 clse
= strchr (input_line_pointer
, '\"');
949 as_bad (_("missing end-quote"));
954 case 'H': /* 16-bit */
955 case 'F': /* 32-bit */
957 emit_expr (&exp
, nbytes
);
959 case 'E': /* 32-bit */
962 case 'D': /* 64-bit */
963 md_atof (type
, tmp
, &nbytes
);
964 p
= frag_more (nbytes
);
965 memcpy (p
, tmp
, nbytes
);
968 as_bad (_("unsupported DC type"));
972 demand_empty_rest_of_line ();
976 /* Provide minimal support for DS Define Storage. */
979 i370_ds (int unused ATTRIBUTE_UNUSED
)
981 /* DS 0H or DS 0F or DS 0D. */
982 if ('0' == *input_line_pointer
)
984 int alignment
= 0; /* Left shift 1 << align. */
985 input_line_pointer
++;
986 switch (*input_line_pointer
++)
988 case 'H': /* 16-bit */
991 case 'F': /* 32-bit */
994 case 'D': /* 64-bit */
998 as_bad (_("unsupported alignment"));
1001 frag_align (alignment
, 0, 0);
1002 record_alignment (now_seg
, alignment
);
1005 as_bad (_("this DS form not yet supported"));
1008 /* Solaris pseudo op to change to the .rodata section. */
1011 i370_elf_rdata (int sect
)
1013 char *save_line
= input_line_pointer
;
1014 static char section
[] = ".rodata\n";
1016 /* Just pretend this is .section .rodata. */
1017 input_line_pointer
= section
;
1018 obj_elf_section (sect
);
1020 input_line_pointer
= save_line
;
1023 /* Pseudo op to make file scope bss items. */
1026 i370_elf_lcomm (int unused ATTRIBUTE_UNUSED
)
1039 c
= get_symbol_name (&name
);
1041 /* Just after name is now '\0'. */
1042 p
= input_line_pointer
;
1043 (void) restore_line_pointer (c
);
1045 if (*input_line_pointer
!= ',')
1047 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1048 ignore_rest_of_line ();
1053 input_line_pointer
++;
1054 if ((size
= get_absolute_expression ()) < 0)
1056 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size
);
1057 ignore_rest_of_line ();
1061 /* The third argument to .lcomm is the alignment. */
1062 if (*input_line_pointer
!= ',')
1066 ++input_line_pointer
;
1067 align
= get_absolute_expression ();
1070 as_warn (_("ignoring bad alignment"));
1076 symbolP
= symbol_find_or_make (name
);
1079 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1081 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1082 S_GET_NAME (symbolP
));
1083 ignore_rest_of_line ();
1087 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1089 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1090 S_GET_NAME (symbolP
),
1091 (long) S_GET_VALUE (symbolP
),
1094 ignore_rest_of_line ();
1100 old_subsec
= now_subseg
;
1103 /* Convert to a power of 2 alignment. */
1104 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
)
1108 as_bad (_("Common alignment not a power of 2"));
1109 ignore_rest_of_line ();
1116 record_alignment (bss_section
, align2
);
1117 subseg_set (bss_section
, 0);
1119 frag_align (align2
, 0, 0);
1120 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1121 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1122 symbol_set_frag (symbolP
, frag_now
);
1123 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1126 S_SET_SIZE (symbolP
, size
);
1127 S_SET_SEGMENT (symbolP
, bss_section
);
1128 subseg_set (old_sec
, old_subsec
);
1129 demand_empty_rest_of_line ();
1132 /* Validate any relocations emitted for -mrelocatable, possibly adding
1133 fixups for word relocations in writable segments, so we can adjust
1137 i370_elf_validate_fix (fixS
*fixp
, segT seg
)
1139 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1148 case SHILB_MRELOCATABLE
:
1149 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1150 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1151 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1152 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1153 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1154 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1155 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1156 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1157 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1158 && strcmp (segment_name (seg
), ".got2") != 0
1159 && strcmp (segment_name (seg
), ".dtors") != 0
1160 && strcmp (segment_name (seg
), ".ctors") != 0
1161 && strcmp (segment_name (seg
), ".fixup") != 0
1162 && strcmp (segment_name (seg
), ".stab") != 0
1163 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1164 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1166 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1167 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1168 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1169 "Relocation cannot be done when using -mrelocatable");
1176 #endif /* OBJ_ELF */
1179 #define LITERAL_POOL_SUPPORT
1180 #ifdef LITERAL_POOL_SUPPORT
1181 /* Provide support for literal pools within the text section.
1182 Loosely based on similar code from tc-arm.c.
1183 We will use four symbols to locate four parts of the literal pool.
1184 These four sections contain 64,32,16 and 8-bit constants; we use
1185 four sections so that all memory access can be appropriately aligned.
1186 That is, we want to avoid mixing these together so that we don't
1187 waste space padding out to alignments. The four pointers
1188 longlong_poolP, word_poolP, etc. point to a symbol labeling the
1189 start of each pool part.
1191 lit_pool_num increments from zero to infinity and uniquely id's
1192 -- it's used to generate the *_poolP symbol name. */
1194 #define MAX_LITERAL_POOL_SIZE 1024
1196 typedef struct literalS
1198 struct expressionS exp
;
1200 char size
; /* 1,2,4 or 8 */
1204 literalT literals
[MAX_LITERAL_POOL_SIZE
];
1205 int next_literal_pool_place
= 0; /* Next free entry in the pool. */
1207 static symbolS
*longlong_poolP
= NULL
; /* 64-bit pool entries. */
1208 static symbolS
*word_poolP
= NULL
; /* 32-bit pool entries. */
1209 static symbolS
*short_poolP
= NULL
; /* 16-bit pool entries. */
1210 static symbolS
*byte_poolP
= NULL
; /* 8-bit pool entries. */
1212 static int lit_pool_num
= 1;
1214 /* Create a new, empty symbol. */
1216 symbol_make_empty (void)
1218 return symbol_create (FAKE_LABEL_NAME
, undefined_section
,
1219 (valueT
) 0, &zero_address_frag
);
1222 /* Make the first argument an address-relative expression
1223 by subtracting the second argument. */
1226 i370_make_relative (expressionS
*exx
, expressionS
*baseaddr
)
1228 if (O_constant
== baseaddr
->X_op
)
1230 exx
->X_op
= O_symbol
;
1231 exx
->X_add_number
-= baseaddr
->X_add_number
;
1233 else if (O_symbol
== baseaddr
->X_op
)
1235 exx
->X_op
= O_subtract
;
1236 exx
->X_op_symbol
= baseaddr
->X_add_symbol
;
1237 exx
->X_add_number
-= baseaddr
->X_add_number
;
1239 else if (O_uminus
== baseaddr
->X_op
)
1242 exx
->X_op_symbol
= baseaddr
->X_add_symbol
;
1243 exx
->X_add_number
+= baseaddr
->X_add_number
;
1246 as_bad (_("Missing or bad .using directive"));
1248 /* Add an expression to the literal pool. */
1251 add_to_lit_pool (expressionS
*exx
, char *name
, int sz
)
1254 int offset_in_pool
= 0;
1256 /* Start a new pool, if necessary. */
1257 if (8 == sz
&& NULL
== longlong_poolP
)
1258 longlong_poolP
= symbol_make_empty ();
1259 else if (4 == sz
&& NULL
== word_poolP
)
1260 word_poolP
= symbol_make_empty ();
1261 else if (2 == sz
&& NULL
== short_poolP
)
1262 short_poolP
= symbol_make_empty ();
1263 else if (1 == sz
&& NULL
== byte_poolP
)
1264 byte_poolP
= symbol_make_empty ();
1266 /* Check if this literal value is already in the pool.
1267 FIXME: We should probably be checking expressions
1268 of type O_symbol as well.
1269 FIXME: This is probably(certainly?) broken for O_big,
1270 which includes 64-bit long-longs. */
1271 while (lit_count
< next_literal_pool_place
)
1273 if (exx
->X_op
== O_constant
1274 && literals
[lit_count
].exp
.X_op
== exx
->X_op
1275 && literals
[lit_count
].exp
.X_add_number
== exx
->X_add_number
1276 && literals
[lit_count
].exp
.X_unsigned
== exx
->X_unsigned
1277 && literals
[lit_count
].size
== sz
)
1279 else if (literals
[lit_count
].sym_name
1281 && !strcmp (name
, literals
[lit_count
].sym_name
))
1283 if (sz
== literals
[lit_count
].size
)
1284 offset_in_pool
+= sz
;
1288 if (lit_count
== next_literal_pool_place
) /* new entry */
1290 if (next_literal_pool_place
> MAX_LITERAL_POOL_SIZE
)
1291 as_bad (_("Literal Pool Overflow"));
1293 literals
[next_literal_pool_place
].exp
= *exx
;
1294 literals
[next_literal_pool_place
].size
= sz
;
1295 literals
[next_literal_pool_place
].offset
= offset_in_pool
;
1297 literals
[next_literal_pool_place
].sym_name
= strdup (name
);
1299 literals
[next_literal_pool_place
].sym_name
= NULL
;
1300 next_literal_pool_place
++;
1303 /* ???_poolP points to the beginning of the literal pool.
1304 X_add_number is the offset from the beginning of the
1305 literal pool to this expr minus the location of the most
1306 recent .using directive. Thus, the grand total value of the
1307 expression is the distance from .using to the literal. */
1309 exx
->X_add_symbol
= longlong_poolP
;
1311 exx
->X_add_symbol
= word_poolP
;
1313 exx
->X_add_symbol
= short_poolP
;
1315 exx
->X_add_symbol
= byte_poolP
;
1316 exx
->X_add_number
= offset_in_pool
;
1317 exx
->X_op_symbol
= NULL
;
1319 /* If the user has set up a base reg in another section,
1320 use that; otherwise use the text section. */
1321 if (0 < i370_using_other_regno
)
1322 i370_make_relative (exx
, &i370_using_other_baseaddr
);
1324 i370_make_relative (exx
, &i370_using_text_baseaddr
);
1327 /* The symbol setup for the literal pool is done in two steps. First,
1328 a symbol that represents the start of the literal pool is created,
1329 above, in the add_to_pool() routine. This sym ???_poolP.
1330 However, we don't know what fragment it's in until a bit later.
1331 So we defer the frag_now thing, and the symbol name, until .ltorg time. */
1333 /* Can't use symbol_new here, so have to create a symbol and then at
1334 a later date assign it a value. That's what these functions do. */
1337 symbol_locate (symbolS
*symbolP
,
1338 const char *name
, /* It is copied, the caller can modify. */
1339 segT segment
, /* Segment identifier (SEG_<something>). */
1340 valueT valu
, /* Symbol value. */
1341 fragS
*frag
) /* Associated fragment. */
1344 char *preserved_copy_of_name
;
1346 name_length
= strlen (name
) + 1; /* +1 for \0 */
1347 obstack_grow (¬es
, name
, name_length
);
1348 preserved_copy_of_name
= obstack_finish (¬es
);
1350 S_SET_NAME (symbolP
, preserved_copy_of_name
);
1352 S_SET_SEGMENT (symbolP
, segment
);
1353 S_SET_VALUE (symbolP
, valu
);
1354 symbol_clear_list_pointers (symbolP
);
1356 symbol_set_frag (symbolP
, frag
);
1358 /* Link to end of symbol chain. */
1360 extern int symbol_table_frozen
;
1362 if (symbol_table_frozen
)
1366 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1368 obj_symbol_new_hook (symbolP
);
1370 #ifdef tc_symbol_new_hook
1371 tc_symbol_new_hook (symbolP
);
1376 verify_symbol_chain(symbol_rootP
, symbol_lastP
);
1377 #endif /* DEBUG_SYMS */
1380 /* i370_addr_offset() will convert operand expressions
1381 that appear to be absolute into their base-register
1382 relative form. These expressions come in two types:
1384 (1) of the form "* + const" * where "*" means
1385 relative offset since the last using
1386 i.e. "*" means ".-using_baseaddr"
1388 (2) labels, which are never absolute, but are always
1389 relative to the last "using". Anything with an alpha
1390 character is considered to be a label (since symbols
1391 can never be operands), and since we've already handled
1392 register operands. For example, "BL .L33" branch low
1393 to .L33 RX form insn frequently terminates for-loops. */
1396 i370_addr_offset (expressionS
*exx
)
1402 /* Search for a label; anything with an alpha char will do.
1403 Local labels consist of N digits followed by either b or f. */
1404 lab
= input_line_pointer
;
1405 while (*lab
&& (',' != *lab
) && ('(' != *lab
))
1409 else if (ISALPHA (*lab
))
1416 else if (('f' == *lab
) || ('b' == *lab
))
1424 else if ('.' != *lab
)
1429 /* See if operand has a * in it. */
1430 dot
= strchr (input_line_pointer
, '*');
1432 if (!dot
&& !islabel
)
1435 /* Replace * with . and let expr munch on it. */
1440 /* OK, now we have to subtract the "using" location.
1441 Normally branches appear in the text section only. */
1442 if (0 == strncmp (now_seg
->name
, ".text", 5) || 0 > i370_using_other_regno
)
1443 i370_make_relative (exx
, &i370_using_text_baseaddr
);
1445 i370_make_relative (exx
, &i370_using_other_baseaddr
);
1447 /* Put the * back. */
1454 /* Handle address constants of various sorts. */
1455 /* The currently supported types are
1458 =X'deadbeef' hexadecimal
1459 =F'1234' 32-bit const int
1460 =H'1234' 16-bit const int. */
1463 i370_addr_cons (expressionS
*exp
)
1466 char *sym_name
, delim
;
1471 name
= input_line_pointer
;
1472 sym_name
= input_line_pointer
;
1473 /* Find the spelling of the operand. */
1474 if (name
[0] == '=' && ISALPHA (name
[1]))
1475 name
= ++input_line_pointer
;
1481 case 'A': /* A == address-of. */
1482 case 'V': /* V == extern. */
1483 ++input_line_pointer
;
1486 /* We use a simple string name to collapse together
1487 multiple references to the same address literal. */
1488 name_len
= strcspn (sym_name
, ", ");
1489 delim
= *(sym_name
+ name_len
);
1490 *(sym_name
+ name_len
) = 0x0;
1491 add_to_lit_pool (exp
, sym_name
, 4);
1492 *(sym_name
+ name_len
) = delim
;
1498 case 'E': /* Single-precision float point. */
1499 case 'D': /* Double-precision float point. */
1501 /* H == 16-bit fixed-point const; expression must be const. */
1502 /* F == fixed-point const; expression must be const. */
1503 /* X == fixed-point const; expression must be const. */
1504 if ('H' == name
[0]) cons_len
= 2;
1505 else if ('F' == name
[0]) cons_len
= 4;
1506 else if ('X' == name
[0]) cons_len
= -1;
1507 else if ('E' == name
[0]) cons_len
= 4;
1508 else if ('D' == name
[0]) cons_len
= 8;
1510 /* Extract length, if it is present;
1511 FIXME: assume single-digit length. */
1514 /* Should work for ASCII and EBCDIC. */
1515 cons_len
= name
[2] - '0';
1516 input_line_pointer
+= 2;
1519 ++input_line_pointer
;
1521 /* Get rid of pesky quotes. */
1522 if ('\'' == *input_line_pointer
)
1526 ++input_line_pointer
;
1527 clse
= strchr (input_line_pointer
, '\'');
1531 as_bad (_("missing end-quote"));
1533 if ('\"' == *input_line_pointer
)
1537 ++input_line_pointer
;
1538 clse
= strchr (input_line_pointer
, '\"');
1542 as_bad (_("missing end-quote"));
1544 if (('X' == name
[0]) || ('E' == name
[0]) || ('D' == name
[0]))
1549 /* The length of hex constants is specified directly with L,
1550 or implied through the number of hex digits. For example:
1553 =X'000000AB' four bytes
1554 =XL4'AB' four bytes, left-padded with zero. */
1555 if (('X' == name
[0]) && (0 > cons_len
))
1557 save
= input_line_pointer
;
1560 if (ISXDIGIT (*save
))
1564 cons_len
= (hex_len
+1) /2;
1566 /* I believe this works even for =XL8'dada0000beeebaaa'
1567 which should parse out to X_op == O_big
1568 Note that floats and doubles get represented as
1569 0d3.14159265358979 or 0f 2.7. */
1573 strcat (tmp
, input_line_pointer
);
1574 save
= input_line_pointer
;
1575 input_line_pointer
= tmp
;
1577 input_line_pointer
= save
+ (input_line_pointer
-tmp
-2);
1579 /* Fix up lengths for floats and doubles. */
1580 if (O_big
== exp
->X_op
)
1581 exp
->X_add_number
= cons_len
/ CHARS_PER_LITTLENUM
;
1586 /* O_big occurs when more than 4 bytes worth gets parsed. */
1587 if ((exp
->X_op
!= O_constant
) && (exp
->X_op
!= O_big
))
1589 as_bad (_("expression not a constant"));
1592 add_to_lit_pool (exp
, 0x0, cons_len
);
1596 as_bad (_("Unknown/unsupported address literal type"));
1604 /* Dump the contents of the literal pool that we've accumulated so far.
1605 This aligns the pool to the size of the largest literal in the pool. */
1608 i370_ltorg (int ignore ATTRIBUTE_UNUSED
)
1612 int biggest_literal_size
= 0;
1613 int biggest_align
= 0;
1616 if (strncmp (now_seg
->name
, ".text", 5))
1618 if (i370_other_section
== undefined_section
)
1619 as_bad (_(".ltorg without prior .using in section %s"),
1622 if (i370_other_section
!= now_seg
)
1623 as_bad (_(".ltorg in section %s paired to .using in section %s"),
1624 now_seg
->name
, i370_other_section
->name
);
1627 if (! longlong_poolP
1631 /* Nothing to do. */
1634 /* Find largest literal .. 2 4 or 8. */
1636 while (lit_count
< next_literal_pool_place
)
1638 if (biggest_literal_size
< literals
[lit_count
].size
)
1639 biggest_literal_size
= literals
[lit_count
].size
;
1642 if (1 == biggest_literal_size
) biggest_align
= 0;
1643 else if (2 == biggest_literal_size
) biggest_align
= 1;
1644 else if (4 == biggest_literal_size
) biggest_align
= 2;
1645 else if (8 == biggest_literal_size
) biggest_align
= 3;
1646 else as_bad (_("bad alignment of %d bytes in literal pool"), biggest_literal_size
);
1647 if (0 == biggest_align
) biggest_align
= 1;
1649 /* Align pool for short, word, double word accesses. */
1650 frag_align (biggest_align
, 0, 0);
1651 record_alignment (now_seg
, biggest_align
);
1653 /* Note that the gas listing will print only the first five
1654 entries in the pool .... wonder how to make it print more. */
1655 /* Output largest literals first, then the smaller ones. */
1656 for (litsize
=8; litsize
; litsize
/=2)
1658 symbolS
*current_poolP
= NULL
;
1662 current_poolP
= longlong_poolP
; break;
1664 current_poolP
= word_poolP
; break;
1666 current_poolP
= short_poolP
; break;
1668 current_poolP
= byte_poolP
; break;
1670 as_bad (_("bad literal size\n"));
1672 if (NULL
== current_poolP
)
1674 sprintf (pool_name
, ".LITP%01d%06d", litsize
, lit_pool_num
);
1675 symbol_locate (current_poolP
, pool_name
, now_seg
,
1676 (valueT
) frag_now_fix (), frag_now
);
1677 symbol_table_insert (current_poolP
);
1680 while (lit_count
< next_literal_pool_place
)
1682 if (litsize
== literals
[lit_count
].size
)
1684 #define EMIT_ADDR_CONS_SYMBOLS
1685 #ifdef EMIT_ADDR_CONS_SYMBOLS
1686 /* Create a bogus symbol, add it to the pool ...
1687 For the most part, I think this is a useless exercise,
1688 except that having these symbol names in the objects
1689 is vaguely useful for debugging. */
1690 if (literals
[lit_count
].sym_name
)
1692 symbolS
* symP
= symbol_make_empty ();
1693 symbol_locate (symP
, literals
[lit_count
].sym_name
, now_seg
,
1694 (valueT
) frag_now_fix (), frag_now
);
1695 symbol_table_insert (symP
);
1697 #endif /* EMIT_ADDR_CONS_SYMBOLS */
1699 emit_expr (&(literals
[lit_count
].exp
), literals
[lit_count
].size
);
1705 next_literal_pool_place
= 0;
1706 longlong_poolP
= NULL
;
1713 #endif /* LITERAL_POOL_SUPPORT */
1716 /* Add support for the HLASM-like USING directive to indicate
1717 the base register to use ... we don't support the full
1718 hlasm semantics for this ... we merely pluck a base address
1719 and a register number out. We print a warning if using is
1720 called multiple times. I suppose we should check to see
1721 if the regno is valid. */
1724 i370_using (int ignore ATTRIBUTE_UNUSED
)
1726 expressionS ex
, baseaddr
;
1730 /* If "*" appears in a using, it means "."
1731 replace it with "." so that expr doesn't get confused. */
1732 star
= strchr (input_line_pointer
, '*');
1736 /* The first arg to using will usually be ".", but it can
1737 be a more complex expression too. */
1738 expression (&baseaddr
);
1741 if (O_constant
!= baseaddr
.X_op
1742 && O_symbol
!= baseaddr
.X_op
1743 && O_uminus
!= baseaddr
.X_op
)
1744 as_bad (_(".using: base address expression illegal or too complex"));
1746 if (*input_line_pointer
!= '\0') ++input_line_pointer
;
1748 /* The second arg to using had better be a register. */
1749 register_name (&ex
);
1750 demand_empty_rest_of_line ();
1751 iregno
= ex
.X_add_number
;
1753 if (0 == strncmp (now_seg
->name
, ".text", 5))
1755 i370_using_text_baseaddr
= baseaddr
;
1756 i370_using_text_regno
= iregno
;
1760 i370_using_other_baseaddr
= baseaddr
;
1761 i370_using_other_regno
= iregno
;
1762 i370_other_section
= now_seg
;
1767 i370_drop (int ignore ATTRIBUTE_UNUSED
)
1772 register_name (&ex
);
1773 demand_empty_rest_of_line ();
1774 iregno
= ex
.X_add_number
;
1776 if (0 == strncmp (now_seg
->name
, ".text", 5))
1778 if (iregno
!= i370_using_text_regno
)
1779 as_bad (_("dropping register %d in section %s does not match using register %d"),
1780 iregno
, now_seg
->name
, i370_using_text_regno
);
1782 i370_using_text_regno
= -1;
1783 i370_using_text_baseaddr
.X_op
= O_absent
;
1787 if (iregno
!= i370_using_other_regno
)
1788 as_bad (_("dropping register %d in section %s does not match using register %d"),
1789 iregno
, now_seg
->name
, i370_using_other_regno
);
1791 if (i370_other_section
!= now_seg
)
1792 as_bad (_("dropping register %d in section %s previously used in section %s"),
1793 iregno
, now_seg
->name
, i370_other_section
->name
);
1795 i370_using_other_regno
= -1;
1796 i370_using_other_baseaddr
.X_op
= O_absent
;
1797 i370_other_section
= undefined_section
;
1802 /* We need to keep a list of fixups. We can't simply generate them as
1803 we go, because that would require us to first create the frag, and
1804 that would screw up references to ``.''. */
1810 bfd_reloc_code_real_type reloc
;
1813 #define MAX_INSN_FIXUPS 5
1815 /* Handle a macro. Gather all the operands, transform them as
1816 described by the macro, and call md_assemble recursively. All the
1817 operands are separated by commas; we don't accept parentheses
1818 around operands here. */
1821 i370_macro (char *str
, const struct i370_macro
*macro
)
1832 /* Gather the users operands into the operands array. */
1837 if (count
>= sizeof operands
/ sizeof operands
[0])
1839 operands
[count
++] = s
;
1840 s
= strchr (s
, ',');
1841 if (s
== (char *) NULL
)
1846 if (count
!= macro
->operands
)
1848 as_bad (_("wrong number of operands"));
1852 /* Work out how large the string must be (the size is unbounded
1853 because it includes user input). */
1855 format
= macro
->format
;
1856 while (*format
!= '\0')
1865 arg
= strtol (format
+ 1, &send
, 10);
1866 know (send
!= format
&& arg
>= 0 && (unsigned) arg
< count
);
1867 len
+= strlen (operands
[arg
]);
1872 /* Put the string together. */
1873 complete
= s
= XNEWVEC (char, len
+ 1);
1874 format
= macro
->format
;
1875 while (*format
!= '\0')
1881 arg
= strtol (format
+ 1, &send
, 10);
1882 strcpy (s
, operands
[arg
]);
1889 /* Assemble the constructed instruction. */
1890 md_assemble (complete
);
1894 /* This routine is called for each instruction to be assembled. */
1897 md_assemble (char *str
)
1900 const struct i370_opcode
*opcode
;
1902 const unsigned char *opindex_ptr
;
1903 int have_optional_index
, have_optional_basereg
, have_optional_reg
;
1904 int skip_optional_index
, skip_optional_basereg
, skip_optional_reg
;
1905 int use_text
=0, use_other
=0;
1907 struct i370_fixup fixups
[MAX_INSN_FIXUPS
];
1912 bfd_reloc_code_real_type reloc
;
1915 /* Get the opcode. */
1916 for (s
= str
; *s
!= '\0' && ! ISSPACE (*s
); s
++)
1921 /* Look up the opcode in the hash table. */
1922 opcode
= (const struct i370_opcode
*) hash_find (i370_hash
, str
);
1923 if (opcode
== (const struct i370_opcode
*) NULL
)
1925 const struct i370_macro
*macro
;
1927 gas_assert (i370_macro_hash
);
1928 macro
= (const struct i370_macro
*) hash_find (i370_macro_hash
, str
);
1929 if (macro
== (const struct i370_macro
*) NULL
)
1930 as_bad (_("Unrecognized opcode: `%s'"), str
);
1932 i370_macro (s
, macro
);
1937 insn
= opcode
->opcode
;
1940 while (ISSPACE (*str
))
1943 /* I370 operands are either expressions or address constants.
1944 Many operand types are optional. The optional operands
1945 are always surrounded by parens, and are used to denote the base
1946 register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
1947 the fully-formed "A R1, D2(X2,B2)". Note also the = sign,
1948 such as A R1,=A(i) where the address-of operator =A implies
1949 use of both a base register, and a missing index register.
1951 So, before we start seriously parsing the operands, we check
1952 to see if we have an optional operand, and, if we do, we count
1953 the number of commas to see which operand should be omitted. */
1955 have_optional_index
= have_optional_basereg
= have_optional_reg
= 0;
1956 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
1958 const struct i370_operand
*operand
;
1960 operand
= &i370_operands
[*opindex_ptr
];
1961 if ((operand
->flags
& I370_OPERAND_INDEX
) != 0)
1962 have_optional_index
= 1;
1963 if ((operand
->flags
& I370_OPERAND_BASE
) != 0)
1964 have_optional_basereg
= 1;
1965 if ((operand
->flags
& I370_OPERAND_OPTIONAL
) != 0)
1966 have_optional_reg
= 1;
1969 skip_optional_index
= skip_optional_basereg
= skip_optional_reg
= 0;
1970 if (have_optional_index
|| have_optional_basereg
)
1972 unsigned int opcount
, nwanted
;
1974 /* There is an optional operand. Count the number of
1975 commas and open-parens in the input line. */
1982 while ((s
= strpbrk (s
, ",(=")) != (char *) NULL
)
1986 if (',' == *s
) ++s
; /* avoid counting things like (, */
1987 if ('=' == *s
) { ++s
; --opcount
; }
1991 /* If there are fewer operands in the line then are called
1992 for by the instruction, we want to skip the optional
1994 nwanted
= strlen ((char *) opcode
->operands
);
1995 if (have_optional_index
)
1997 if (opcount
< nwanted
)
1998 skip_optional_index
= 1;
1999 if (have_optional_basereg
&& ((opcount
+1) < nwanted
))
2000 skip_optional_basereg
= 1;
2001 if (have_optional_reg
&& ((opcount
+1) < nwanted
))
2002 skip_optional_reg
= 1;
2006 if (have_optional_basereg
&& (opcount
< nwanted
))
2007 skip_optional_basereg
= 1;
2008 if (have_optional_reg
&& (opcount
< nwanted
))
2009 skip_optional_reg
= 1;
2013 /* Perform some off-by-one hacks on the length field of certain instructions.
2014 It's such a shame to have to do this, but the problem is that HLASM got
2015 defined so that the lengths differ by one from the actual machine instructions.
2016 this code should probably be moved to a special inter-operand routine.
2017 Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
2018 hack alert -- aren't *all* SS instructions affected ?? */
2020 if (0 == strcasecmp ("CLC", opcode
->name
)
2021 || 0 == strcasecmp ("ED", opcode
->name
)
2022 || 0 == strcasecmp ("EDMK", opcode
->name
)
2023 || 0 == strcasecmp ("MVC", opcode
->name
)
2024 || 0 == strcasecmp ("MVCIN", opcode
->name
)
2025 || 0 == strcasecmp ("MVN", opcode
->name
)
2026 || 0 == strcasecmp ("MVZ", opcode
->name
)
2027 || 0 == strcasecmp ("NC", opcode
->name
)
2028 || 0 == strcasecmp ("OC", opcode
->name
)
2029 || 0 == strcasecmp ("XC", opcode
->name
))
2032 /* Gather the operands. */
2034 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2036 const struct i370_operand
*operand
;
2040 operand
= &i370_operands
[*opindex_ptr
];
2042 /* If this is an index operand, and we are skipping it,
2043 just insert a zero. */
2044 if (skip_optional_index
&&
2045 ((operand
->flags
& I370_OPERAND_INDEX
) != 0))
2047 insn
= i370_insert_operand (insn
, operand
, 0);
2051 /* If this is the base operand, and we are skipping it,
2052 just insert the current using basreg. */
2053 if (skip_optional_basereg
&&
2054 ((operand
->flags
& I370_OPERAND_BASE
) != 0))
2059 if (0 == strncmp (now_seg
->name
, ".text", 5)
2060 || 0 > i370_using_other_regno
)
2061 basereg
= i370_using_text_regno
;
2063 basereg
= i370_using_other_regno
;
2067 if (0 > i370_using_other_regno
)
2068 basereg
= i370_using_text_regno
;
2070 basereg
= i370_using_other_regno
;
2073 as_bad (_("not using any base register"));
2075 insn
= i370_insert_operand (insn
, operand
, basereg
);
2079 /* If this is an optional operand, and we are skipping it,
2080 Use zero (since a non-zero value would denote a register) */
2081 if (skip_optional_reg
2082 && ((operand
->flags
& I370_OPERAND_OPTIONAL
) != 0))
2084 insn
= i370_insert_operand (insn
, operand
, 0);
2088 /* Gather the operand. */
2089 hold
= input_line_pointer
;
2090 input_line_pointer
= str
;
2092 /* Register names are only allowed where there are registers. */
2093 if ((operand
->flags
& I370_OPERAND_GPR
) != 0)
2095 /* Quickie hack to get past things like (,r13). */
2096 if (skip_optional_index
&& (',' == *input_line_pointer
))
2098 *input_line_pointer
= ' ';
2099 input_line_pointer
++;
2102 if (! register_name (&ex
))
2103 as_bad (_("expecting a register for operand %d"),
2104 (int) (opindex_ptr
- opcode
->operands
+ 1));
2107 /* Check for an address constant expression. */
2108 /* We will put PSW-relative addresses in the text section,
2109 and address literals in the .data (or other) section. */
2110 else if (i370_addr_cons (&ex
))
2112 else if (i370_addr_offset (&ex
))
2114 else expression (&ex
);
2116 str
= input_line_pointer
;
2117 input_line_pointer
= hold
;
2119 /* Perform some off-by-one hacks on the length field of certain instructions.
2120 It's such a shame to have to do this, but the problem is that HLASM got
2121 defined so that the programmer specifies a length that is one greater
2122 than what the machine instruction wants. Sigh. */
2123 if (off_by_one
&& (0 == strcasecmp ("SS L", operand
->name
)))
2126 if (ex
.X_op
== O_illegal
)
2127 as_bad (_("illegal operand"));
2128 else if (ex
.X_op
== O_absent
)
2129 as_bad (_("missing operand"));
2130 else if (ex
.X_op
== O_register
)
2131 insn
= i370_insert_operand (insn
, operand
, ex
.X_add_number
);
2132 else if (ex
.X_op
== O_constant
)
2135 /* Allow @HA, @L, @H on constants.
2136 Well actually, no we don't; there really don't make sense
2137 (at least not to me) for the i370. However, this code is
2138 left here for any dubious future expansion reasons. */
2139 char *orig_str
= str
;
2141 if ((reloc
= i370_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2148 case BFD_RELOC_LO16
:
2149 /* X_unsigned is the default, so if the user has done
2150 something which cleared it, we always produce a
2152 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
2157 case BFD_RELOC_HI16
:
2158 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
2161 case BFD_RELOC_HI16_S
:
2162 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
2163 + ((ex
.X_add_number
>> 15) & 1));
2167 insn
= i370_insert_operand (insn
, operand
, ex
.X_add_number
);
2170 else if ((reloc
= i370_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2172 as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
2174 /* We need to generate a fixup for this expression. */
2175 if (fc
>= MAX_INSN_FIXUPS
)
2176 as_fatal ("too many fixups");
2177 fixups
[fc
].exp
= ex
;
2178 fixups
[fc
].opindex
= 0;
2179 fixups
[fc
].reloc
= reloc
;
2182 #endif /* OBJ_ELF */
2185 /* We need to generate a fixup for this expression. */
2186 /* Typically, the expression will just be a symbol ...
2187 printf ("insn %s needs fixup for %s \n",
2188 opcode->name, ex.X_add_symbol->bsym->name); */
2190 if (fc
>= MAX_INSN_FIXUPS
)
2191 as_fatal ("too many fixups");
2192 fixups
[fc
].exp
= ex
;
2193 fixups
[fc
].opindex
= *opindex_ptr
;
2194 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2198 /* Skip over delimiter (close paren, or comma). */
2199 if ((')' == *str
) && (',' == *(str
+1)))
2205 while (ISSPACE (*str
))
2209 as_bad (_("junk at end of line: `%s'"), str
);
2211 /* Write out the instruction. */
2212 f
= frag_more (opcode
->len
);
2213 if (4 >= opcode
->len
)
2214 md_number_to_chars (f
, insn
.i
[0], opcode
->len
);
2217 md_number_to_chars (f
, insn
.i
[0], 4);
2219 if (6 == opcode
->len
)
2220 md_number_to_chars ((f
+ 4), ((insn
.i
[1])>>16), 2);
2223 /* Not used --- don't have any 8 byte instructions. */
2224 as_bad (_("Internal Error: bad instruction length"));
2225 md_number_to_chars ((f
+ 4), insn
.i
[1], opcode
->len
-4);
2229 /* Create any fixups. At this point we do not use a
2230 bfd_reloc_code_real_type, but instead just use the
2231 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2232 handle fixups for any operand type, although that is admittedly
2233 not a very exciting feature. We pick a BFD reloc type in
2235 for (i
= 0; i
< fc
; i
++)
2237 const struct i370_operand
*operand
;
2239 operand
= &i370_operands
[fixups
[i
].opindex
];
2240 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2242 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2249 size
= bfd_get_reloc_size (reloc_howto
);
2251 if (size
< 1 || size
> 4)
2254 printf (" gwana do fixup %d \n", i
);
2255 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, size
,
2256 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
2259 /* Turn off complaints that the addend is too large for things like
2261 switch (fixups
[i
].reloc
)
2263 case BFD_RELOC_16_GOTOFF
:
2264 case BFD_RELOC_LO16
:
2265 case BFD_RELOC_HI16
:
2266 case BFD_RELOC_HI16_S
:
2267 fixP
->fx_no_overflow
= 1;
2275 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->len
,
2277 (operand
->flags
& I370_OPERAND_RELATIVE
) != 0,
2278 ((bfd_reloc_code_real_type
)
2279 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2285 /* Pseudo-op handling. */
2287 /* The .byte pseudo-op. This is similar to the normal .byte
2288 pseudo-op, but it can also take a single ASCII string. */
2291 i370_byte (int ignore ATTRIBUTE_UNUSED
)
2293 if (*input_line_pointer
!= '\"')
2299 /* Gather characters. A real double quote is doubled. Unusual
2300 characters are not permitted. */
2301 ++input_line_pointer
;
2306 c
= *input_line_pointer
++;
2310 if (*input_line_pointer
!= '\"')
2312 ++input_line_pointer
;
2315 FRAG_APPEND_1_CHAR (c
);
2318 demand_empty_rest_of_line ();
2321 /* The .tc pseudo-op. This is used when generating XCOFF and ELF.
2322 This takes two or more arguments.
2324 When generating XCOFF output, the first argument is the name to
2325 give to this location in the toc; this will be a symbol with class
2326 TC. The rest of the arguments are 4 byte values to actually put at
2327 this location in the TOC; often there is just one more argument, a
2328 relocatable symbol reference.
2330 When not generating XCOFF output, the arguments are the same, but
2331 the first argument is simply ignored. */
2334 i370_tc (int ignore ATTRIBUTE_UNUSED
)
2337 /* Skip the TOC symbol name. */
2338 while (is_part_of_name (*input_line_pointer
)
2339 || *input_line_pointer
== '['
2340 || *input_line_pointer
== ']'
2341 || *input_line_pointer
== '{'
2342 || *input_line_pointer
== '}')
2343 ++input_line_pointer
;
2345 /* Align to a four byte boundary. */
2346 frag_align (2, 0, 0);
2347 record_alignment (now_seg
, 2);
2349 if (*input_line_pointer
!= ',')
2350 demand_empty_rest_of_line ();
2353 ++input_line_pointer
;
2359 md_atof (int type
, char *litp
, int *sizep
)
2361 /* 360/370/390 have two float formats: an old, funky 360 single-precision
2362 format, and the ieee format. Support only the ieee format. */
2363 return ieee_md_atof (type
, litp
, sizep
, TRUE
);
2366 /* Write a value out to the object file, using the appropriate
2370 md_number_to_chars (char *buf
, valueT val
, int n
)
2372 number_to_chars_bigendian (buf
, val
, n
);
2375 /* Align a section (I don't know why this is machine dependent). */
2378 md_section_align (asection
*seg
, valueT addr
)
2380 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2382 return (addr
+ (1 << align
) - 1) & -(1 << align
);
2385 /* We don't have any form of relaxing. */
2388 md_estimate_size_before_relax (fragS
*fragp ATTRIBUTE_UNUSED
,
2389 asection
*seg ATTRIBUTE_UNUSED
)
2395 /* Convert a machine dependent frag. We never generate these. */
2398 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
,
2399 asection
*sec ATTRIBUTE_UNUSED
,
2400 fragS
*fragp ATTRIBUTE_UNUSED
)
2405 /* We have no need to default values of symbols. */
2408 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2413 /* Functions concerning relocs. */
2415 /* The location from which a PC relative jump should be calculated,
2416 given a PC relative reloc. */
2419 md_pcrel_from_section (fixS
*fixp
, segT sec ATTRIBUTE_UNUSED
)
2421 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2424 /* Apply a fixup to the object code. This is called for all the
2425 fixups we generated by the call to fix_new_exp, above. In the call
2426 above we used a reloc code which was the largest legal reloc code
2427 plus the operand index. Here we undo that to recover the operand
2428 index. At this point all symbol values should be fully resolved,
2429 and we attempt to completely resolve the reloc. If we can not do
2430 that, we determine the correct reloc code and put it back in the
2433 See gas/cgen.c for more sample code and explanations of what's
2437 md_apply_fix (fixS
*fixP
, valueT
* valP
, segT seg
)
2439 valueT value
= * valP
;
2441 if (fixP
->fx_addsy
!= NULL
)
2444 printf ("\nmd_apply_fix: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
2445 S_GET_NAME (fixP
->fx_addsy
),
2446 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
,
2447 fixP
->fx_file
, fixP
->fx_line
,
2448 S_GET_VALUE (fixP
->fx_addsy
), value
);
2454 /* Apply fixups to operands. Note that there should be no relocations
2455 for any operands, since no instruction ever takes an operand
2456 that requires reloc. */
2457 if ((int) fixP
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2460 const struct i370_operand
*operand
;
2464 opindex
= (int) fixP
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2466 operand
= &i370_operands
[opindex
];
2469 printf ("\nmd_apply_fix: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
2471 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
,
2472 fixP
->fx_file
, fixP
->fx_line
,
2475 /* Fetch the instruction, insert the fully resolved operand
2476 value, and stuff the instruction back again.
2477 fisxp->fx_size is the length of the instruction. */
2478 where
= fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
;
2479 insn
.i
[0] = bfd_getb32 ((unsigned char *) where
);
2481 if (6 <= fixP
->fx_size
)
2482 /* Deal with 48-bit insn's. */
2483 insn
.i
[1] = bfd_getb32 (((unsigned char *) where
)+4);
2485 insn
= i370_insert_operand (insn
, operand
, (offsetT
) value
);
2486 bfd_putb32 ((bfd_vma
) insn
.i
[0], (unsigned char *) where
);
2488 if (6 <= fixP
->fx_size
)
2489 /* Deal with 48-bit insn's. */
2490 bfd_putb32 ((bfd_vma
) insn
.i
[1], (((unsigned char *) where
)+4));
2492 /* We are done, right? right !! */
2495 /* Nothing else to do here. */
2498 /* Determine a BFD reloc value based on the operand information.
2499 We are only prepared to turn a few of the operands into
2500 relocs. In fact, we support *zero* operand relocations ...
2501 Why? Because we are not expecting the compiler to generate
2502 any operands that need relocation. Due to the 12-bit nature of
2503 i370 addressing, this would be unusual. */
2508 /* Use expr_symbol_where to see if this is an expression
2510 if (expr_symbol_where (fixP
->fx_addsy
, &sfile
, &sline
))
2511 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2512 "unresolved expression that must be resolved");
2514 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2515 "unsupported relocation type");
2522 /* We branch to here if the fixup is not to a symbol that
2523 appears in an instruction operand, but is rather some
2524 declared storage. */
2526 i370_elf_validate_fix (fixP
, seg
);
2529 printf ("md_apply_fix: reloc case %d in segment %s %s:%d\n",
2530 fixP
->fx_r_type
, segment_name (seg
), fixP
->fx_file
, fixP
->fx_line
);
2531 printf ("\tcurrent fixup value is 0x%x \n", value
);
2533 switch (fixP
->fx_r_type
)
2536 case BFD_RELOC_CTOR
:
2538 fixP
->fx_r_type
= BFD_RELOC_32_PCREL
;
2542 case BFD_RELOC_32_PCREL
:
2543 case BFD_RELOC_32_BASEREL
:
2545 printf ("\t32 bit relocation at 0x%x\n",
2546 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
2548 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
2552 case BFD_RELOC_LO16
:
2555 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2556 "cannot emit PC relative %s relocation%s%s",
2557 bfd_get_reloc_code_name (fixP
->fx_r_type
),
2558 fixP
->fx_addsy
!= NULL
? " against " : "",
2559 (fixP
->fx_addsy
!= NULL
2560 ? S_GET_NAME (fixP
->fx_addsy
)
2563 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
2567 /* This case happens when you write, for example,
2569 where L1 and L2 are defined later. */
2570 case BFD_RELOC_HI16
:
2573 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
2576 case BFD_RELOC_HI16_S
:
2579 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
2580 (value
+ 0x8000) >> 16, 2);
2587 md_number_to_chars (fixP
->fx_frag
->fr_literal
+ fixP
->fx_where
,
2593 "Gas failure, reloc value %d\n", fixP
->fx_r_type
);
2599 fixP
->fx_addnumber
= value
;
2602 /* Generate a reloc for a fixup. */
2605 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
2609 reloc
= XNEW (arelent
);
2611 reloc
->sym_ptr_ptr
= XNEW (asymbol
*);
2612 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2613 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2614 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2615 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2617 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2618 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
2621 reloc
->addend
= fixp
->fx_addnumber
;
2624 printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
2625 fixp
->fx_addsy
->bsym
->name
,
2626 fixp
->fx_file
, fixp
->fx_line
,
2627 reloc
->address
, reloc
->addend
);
2633 /* The target specific pseudo-ops which we support. */
2635 const pseudo_typeS md_pseudo_table
[] =
2637 /* Pseudo-ops which must be overridden. */
2638 { "byte", i370_byte
, 0 },
2640 { "dc", i370_dc
, 0 },
2641 { "ds", i370_ds
, 0 },
2642 { "rmode", i370_rmode
, 0 },
2643 { "csect", i370_csect
, 0 },
2644 { "dsect", i370_dsect
, 0 },
2646 /* enable ebcdic strings e.g. for 3270 support */
2647 { "ebcdic", i370_ebcdic
, 0 },
2650 { "long", i370_elf_cons
, 4 },
2651 { "word", i370_elf_cons
, 4 },
2652 { "short", i370_elf_cons
, 2 },
2653 { "rdata", i370_elf_rdata
, 0 },
2654 { "rodata", i370_elf_rdata
, 0 },
2655 { "lcomm", i370_elf_lcomm
, 0 },
2658 /* This pseudo-op is used even when not generating XCOFF output. */
2659 { "tc", i370_tc
, 0 },
2661 /* dump the literal pool */
2662 { "ltorg", i370_ltorg
, 0 },
2664 /* support the hlasm-style USING directive */
2665 { "using", i370_using
, 0 },
2666 { "drop", i370_drop
, 0 },