1 /* tc-i370.c -- Assembler for the IBM 360/370/390 instruction set.
2 Loosely based on the ppc files by Linas Vepstas <linas@linas.org> 1998, 99
3 Copyright (C) 1994, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
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 2, 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, 59 Temple Place - Suite 330, 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 ...
34 #include "struc-symbol.h"
36 #include "opcode/i370.h"
42 /* This is the assembler for the System/390 Architecture */
44 /* Tell the main code what the endianness is. */
45 extern int target_big_endian
;
48 /* Generic assembler global variables which must be defined by all
52 /* This string holds the chars that always start a comment. If the
53 pre-processor is disabled, these aren't very useful. The macro
54 tc_comment_chars points to this. We use this, rather than the
55 usual comment_chars, so that we can switch for Solaris conventions. */
56 static const char i370_eabi_comment_chars
[] = "#";
58 const char *i370_comment_chars
= i370_eabi_comment_chars
;
60 const char comment_chars
[] = "#";
63 /* Characters which start a comment at the beginning of a line. */
64 const char line_comment_chars
[] = "#*";
66 /* Characters which may be used to separate multiple commands on a
68 const char line_separator_chars
[] = ";";
70 /* Characters which are used to indicate an exponent in a floating
72 const char EXP_CHARS
[] = "eE";
74 /* Characters which mean that a number is a floating point constant,
76 const char FLT_CHARS
[] = "dD";
80 md_show_usage (stream
)
84 S/370 options: (these have not yet been tested and may not work) \n\
86 -mregnames Allow symbolic names for registers\n\
87 -mno-regnames Do not allow symbolic names for registers\n");
90 -mrelocatable support for GCC's -mrelocatble option\n\
91 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
92 -V print assembler version number\n");
97 static void i370_byte
PARAMS ((int));
98 static void i370_tc
PARAMS ((int));
99 static void i370_ebcdic
PARAMS ((int));
101 static void i370_dc
PARAMS ((int));
102 static void i370_ds
PARAMS ((int));
103 static void i370_rmode
PARAMS ((int));
104 static void i370_csect
PARAMS ((int));
105 static void i370_dsect
PARAMS ((int));
106 static void i370_ltorg
PARAMS ((int));
107 static void i370_using
PARAMS ((int));
108 static void i370_drop
PARAMS ((int));
109 static void i370_make_relative
PARAMS ((expressionS
*exp
, expressionS
*baseaddr
));
112 static bfd_reloc_code_real_type i370_elf_suffix
PARAMS ((char **, expressionS
*));
113 static void i370_elf_cons
PARAMS ((int));
114 static void i370_elf_rdata
PARAMS ((int));
115 static void i370_elf_lcomm
PARAMS ((int));
116 static void i370_elf_validate_fix
PARAMS ((fixS
*, segT
));
121 /* The target specific pseudo-ops which we support. */
123 const pseudo_typeS md_pseudo_table
[] =
125 /* Pseudo-ops which must be overridden. */
126 { "byte", i370_byte
, 0 },
128 { "dc", i370_dc
, 0 },
129 { "ds", i370_ds
, 0 },
130 { "rmode", i370_rmode
, 0 },
131 { "csect", i370_csect
, 0 },
132 { "dsect", i370_dsect
, 0 },
134 /* enable ebcdic strings e.g. for 3270 support */
135 { "ebcdic", i370_ebcdic
, 0 },
138 { "long", i370_elf_cons
, 4 },
139 { "word", i370_elf_cons
, 4 },
140 { "short", i370_elf_cons
, 2 },
141 { "rdata", i370_elf_rdata
, 0 },
142 { "rodata", i370_elf_rdata
, 0 },
143 { "lcomm", i370_elf_lcomm
, 0 },
146 /* This pseudo-op is used even when not generating XCOFF output. */
147 { "tc", i370_tc
, 0 },
149 /* dump the literal pool */
150 { "ltorg", i370_ltorg
, 0 },
152 /* support the hlasm-style USING directive */
153 { "using", i370_using
, 0 },
154 { "drop", i370_drop
, 0 },
159 /* ***************************************************************** */
161 /* Whether to use user friendly register names. */
162 #define TARGET_REG_NAMES_P true
164 static boolean reg_names_p
= TARGET_REG_NAMES_P
;
166 static boolean register_name
PARAMS ((expressionS
*));
167 static void i370_set_cpu
PARAMS ((void));
168 static i370_insn_t i370_insert_operand
169 PARAMS ((i370_insn_t insn
, const struct i370_operand
*operand
, offsetT val
));
170 static void i370_macro
PARAMS ((char *str
, const struct i370_macro
*macro
));
172 /* Predefined register names if -mregnames */
173 /* In general, there are lots of them, in an attempt to be compatible */
174 /* with a number of assemblers. */
176 /* Structure to hold information about predefined registers. */
183 /* List of registers that are pre-defined:
185 Each general register has predefined names of the form:
186 1. r<reg_num> which has the value <reg_num>.
187 2. r.<reg_num> which has the value <reg_num>.
190 Each floating point register has predefined names of the form:
191 1. f<reg_num> which has the value <reg_num>.
192 2. f.<reg_num> which has the value <reg_num>.
194 There are only four floating point registers, and these are
195 commonly labelled 0,2,4 and 6. Thus, there is no f1, f3, etc.
198 There are individual registers as well:
199 rbase or r.base has the value 3 (base register)
200 rpgt or r.pgt has the value 4 (page origin table pointer)
201 rarg or r.arg has the value 11 (argument pointer)
202 rtca or r.tca has the value 12 (table of contents pointer)
203 rtoc or r.toc has the value 12 (table of contents pointer)
204 sp or r.sp has the value 13 (stack pointer)
205 dsa or r.dsa has the value 13 (stack pointer)
206 lr has the value 14 (link reg)
208 The table is sorted. Suitable for searching by a binary search. */
210 static const struct pd_reg pre_defined_registers
[] =
212 { "arg", 11 }, /* Argument Pointer */
213 { "base", 3 }, /* Base Reg */
215 { "f.0", 0 }, /* Floating point registers */
226 { "dsa",13 }, /* stack pointer */
227 { "lr", 14 }, /* Link Register */
228 { "pgt", 4 }, /* Page Origin Table Pointer */
230 { "r.0", 0 }, /* General Purpose Registers */
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 */
253 { "r.tca", 12 }, /* Pointer to the table of contents */
254 { "r.toc", 12 }, /* Pointer to the table of contents */
256 { "r0", 0 }, /* More general purpose registers */
273 { "rbase", 3 }, /* Base Reg */
275 { "rtca", 12 }, /* Pointer to the table of contents */
276 { "rtoc", 12 }, /* Pointer to the table of contents */
278 { "sp", 13 }, /* Stack Pointer */
282 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
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. */
287 static int reg_name_search
288 PARAMS ((const struct pd_reg
*, int, const char * name
));
291 reg_name_search (regs
, regcount
, name
)
292 const struct pd_reg
*regs
;
296 int middle
, low
, high
;
304 middle
= (low
+ high
) / 2;
305 cmp
= strcasecmp (name
, regs
[middle
].name
);
311 return regs
[middle
].value
;
319 * Summary of register_name().
321 * in: Input_line_pointer points to 1st char of operand.
323 * out: A expressionS.
324 * The operand may have been a register: in this case, X_op == O_register,
325 * X_add_number is set to the register number, and truth is returned.
326 * Input_line_pointer->(next non-blank) char after operand, or is in its
331 register_name (expressionP
)
332 expressionS
*expressionP
;
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
;
344 else if (!reg_names_p
)
348 name
= ++input_line_pointer
;
350 /* if its a number, treat it as a number */
351 /* if its alpha, look to see if it's in the register table */
352 if (!isalpha (name
[0]))
354 reg_number
= get_single_number();
355 c
= get_symbol_end ();
359 c
= get_symbol_end ();
360 reg_number
= reg_name_search (pre_defined_registers
, REG_NAME_CNT
, name
);
363 /* if numeric, make sure its not out of bounds */
364 if ((0 <= reg_number
) && (16 >= reg_number
))
366 expressionP
->X_op
= O_register
;
367 expressionP
->X_add_number
= reg_number
;
369 /* make the rest nice */
370 expressionP
->X_add_symbol
= NULL
;
371 expressionP
->X_op_symbol
= NULL
;
372 *input_line_pointer
= c
; /* put back the delimiting char */
376 /* reset the line as if we had not done anything */
377 *input_line_pointer
= c
; /* put back the delimiting char */
378 input_line_pointer
= start
; /* reset input_line pointer */
382 /* Local variables. */
384 /* The type of processor we are assembling for. This is one or more
385 of the I370_OPCODE flags defined in opcode/i370.h. */
386 static int i370_cpu
= 0;
388 /* The base register to use for opcode with optional operands.
389 * We define two of these: "text" and "other". Normally, "text"
390 * would get used in the .text section for branches, while "other"
391 * gets used in the .data section for address constants.
393 * The idea of a second base register in a different section
394 * is foreign to the usual HLASM-style semantics; however, it
395 * allows us to provide support for dynamically loaded libraries,
396 * by allowing us to place address constants in a section other
397 * than the text section. The "other" section need not be the
398 * .data section, it can be any section that isn't the .text section.
400 * Note that HLASM defines a multiple, concurrent .using semantic
401 * that we do not: in calculating offsets, it uses either the most
402 * recent .using directive, or the one with the smallest displacement.
403 * This allows HLASM to support a quasi-block-scope-like behaviour.
404 * Handy for people writing assembly by hand ... but not supported
407 static int i370_using_text_regno
= -1;
408 static int i370_using_other_regno
= -1;
410 /* The base address for address literals */
411 static expressionS i370_using_text_baseaddr
;
412 static expressionS i370_using_other_baseaddr
;
414 /* the "other" section, used only for syntax error detection */
415 static segT i370_other_section
= undefined_section
;
417 /* Opcode hash table. */
418 static struct hash_control
*i370_hash
;
420 /* Macro hash table. */
421 static struct hash_control
*i370_macro_hash
;
424 /* What type of shared library support to use */
425 static enum { SHLIB_NONE
, SHLIB_PIC
, SHILB_MRELOCATABLE
} shlib
= SHLIB_NONE
;
428 /* Flags to set in the elf header */
429 static flagword i370_flags
= 0;
431 #ifndef WORKING_DOT_WORD
432 const int md_short_jump_size
= 4;
433 const int md_long_jump_size
= 4;
437 CONST
char *md_shortopts
= "l:um:K:VQ:";
439 CONST
char *md_shortopts
= "um:";
441 struct option md_longopts
[] =
443 {NULL
, no_argument
, NULL
, 0}
445 size_t md_longopts_size
= sizeof(md_longopts
);
448 md_parse_option (c
, arg
)
455 /* -u means that any undefined symbols should be treated as
456 external, which is the default for gas anyhow. */
461 /* Recognize -K PIC */
462 if (strcmp (arg
, "PIC") == 0 || strcmp (arg
, "pic") == 0)
465 i370_flags
|= EF_I370_RELOCATABLE_LIB
;
475 /* -m360 mean to assemble for the ancient 360 architecture */
476 if (strcmp (arg
, "360") == 0 || strcmp (arg
, "i360") == 0)
477 i370_cpu
= I370_OPCODE_360
;
478 /* -mxa means to assemble for the IBM 370 XA */
479 else if (strcmp (arg
, "xa") == 0)
480 i370_cpu
= I370_OPCODE_370_XA
;
481 /* -many means to assemble for any architecture (370/XA). */
482 else if (strcmp (arg
, "any") == 0)
483 i370_cpu
= I370_OPCODE_370
;
485 else if (strcmp (arg
, "regnames") == 0)
488 else if (strcmp (arg
, "no-regnames") == 0)
492 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
493 else if (strcmp (arg
, "relocatable") == 0)
495 shlib
= SHILB_MRELOCATABLE
;
496 i370_flags
|= EF_I370_RELOCATABLE
;
499 else if (strcmp (arg
, "relocatable-lib") == 0)
501 shlib
= SHILB_MRELOCATABLE
;
502 i370_flags
|= EF_I370_RELOCATABLE_LIB
;
508 as_bad ("invalid switch -m%s", arg
);
514 /* -V: SVR4 argument to print version ID. */
519 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
520 should be emitted or not. FIXME: Not implemented. */
534 /* Set i370_cpu if it is not already set.
535 Currently defaults to the reasonable superset;
536 but can be made more fine grained if desred. */
541 const char *default_os
= TARGET_OS
;
542 const char *default_cpu
= TARGET_CPU
;
544 /* override with the superset for the moment. */
545 i370_cpu
= I370_OPCODE_ESA390_SUPERSET
;
548 if (strcmp (default_cpu
, "i360") == 0)
549 i370_cpu
= I370_OPCODE_360
;
550 else if (strcmp (default_cpu
, "i370") == 0)
551 i370_cpu
= I370_OPCODE_370
;
552 else if (strcmp (default_cpu
, "XA") == 0)
553 i370_cpu
= I370_OPCODE_370_XA
;
555 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu
, default_os
);
559 /* Figure out the BFD architecture to use. */
560 // hack alert -- specify the different 370 architectures
562 enum bfd_architecture
565 return bfd_arch_i370
;
568 /* This function is called when the assembler starts up. It is called
569 after the options have been parsed and the output file has been
575 register const struct i370_opcode
*op
;
576 const struct i370_opcode
*op_end
;
577 const struct i370_macro
*macro
;
578 const struct i370_macro
*macro_end
;
579 boolean dup_insn
= false;
584 /* Set the ELF flags if desired. */
586 bfd_set_private_flags (stdoutput
, i370_flags
);
589 /* Insert the opcodes into a hash table. */
590 i370_hash
= hash_new ();
592 op_end
= i370_opcodes
+ i370_num_opcodes
;
593 for (op
= i370_opcodes
; op
< op_end
; op
++)
595 know ((op
->opcode
& op
->mask
) == op
->opcode
);
597 if ((op
->flags
& i370_cpu
) != 0)
601 retval
= hash_insert (i370_hash
, op
->name
, (PTR
) op
);
602 if (retval
!= (const char *) NULL
)
604 as_bad ("Internal assembler error for instruction %s", op
->name
);
610 /* Insert the macros into a hash table. */
611 i370_macro_hash
= hash_new ();
613 macro_end
= i370_macros
+ i370_num_macros
;
614 for (macro
= i370_macros
; macro
< macro_end
; macro
++)
616 if ((macro
->flags
& i370_cpu
) != 0)
620 retval
= hash_insert (i370_macro_hash
, macro
->name
, (PTR
) macro
);
621 if (retval
!= (const char *) NULL
)
623 as_bad ("Internal assembler error for macro %s", macro
->name
);
633 /* Insert an operand value into an instruction. */
636 i370_insert_operand (insn
, operand
, val
)
638 const struct i370_operand
*operand
;
645 /* used for 48-bit insn's */
647 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
649 as_bad ("%s", errmsg
);
653 /* this is used only for 16, 32 bit insn's */
654 insn
.i
[0] |= (((long) val
& ((1 << operand
->bits
) - 1))
663 /* Parse @got, etc. and return the desired relocation.
664 * Currently, i370 does not support (don't really need to support) any
665 * of these fancier markups ... for example, no one is going to
666 * write 'L 6,=V(bogus)@got' it just doesn't make sense (at least to me).
667 * So basically, we could get away with this routine returning
668 * BFD_RELOC_UNUSED in all circumstances. However, I'll leave
669 * in for now in case someone ambitious finds a good use for this stuff ...
670 * this routine was pretty much just copied from the powerpc code ...
672 static bfd_reloc_code_real_type
673 i370_elf_suffix (str_p
, exp_p
)
681 bfd_reloc_code_real_type reloc
;
691 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
693 static struct map_bfd mapping
[] =
695 // MAP ("l", BFD_RELOC_LO16),
696 // MAP ("h", BFD_RELOC_HI16),
697 // MAP ("ha", BFD_RELOC_HI16_S),
698 MAP ("fixup", BFD_RELOC_CTOR
), /* warnings with -mrelocatable */
699 { (char *)0, 0, BFD_RELOC_UNUSED
}
703 return BFD_RELOC_UNUSED
;
705 for (ch
= *str
, str2
= ident
;
706 (str2
< ident
+ sizeof (ident
) - 1
707 && (isalnum (ch
) || ch
== '@'));
710 *str2
++ = (islower (ch
)) ? ch
: tolower (ch
);
717 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
718 if (ch
== ptr
->string
[0]
719 && len
== ptr
->length
720 && memcmp (ident
, ptr
->string
, ptr
->length
) == 0)
722 if (exp_p
->X_add_number
!= 0
723 && (ptr
->reloc
== BFD_RELOC_16_GOTOFF
724 || ptr
->reloc
== BFD_RELOC_LO16_GOTOFF
725 || ptr
->reloc
== BFD_RELOC_HI16_GOTOFF
726 || ptr
->reloc
== BFD_RELOC_HI16_S_GOTOFF
))
727 as_warn ("identifier+constant@got means identifier@got+constant");
729 /* Now check for identifier@suffix+constant */
730 if (*str
== '-' || *str
== '+')
732 char *orig_line
= input_line_pointer
;
735 input_line_pointer
= str
;
736 expression (&new_exp
);
737 if (new_exp
.X_op
== O_constant
)
739 exp_p
->X_add_number
+= new_exp
.X_add_number
;
740 str
= input_line_pointer
;
743 if (&input_line_pointer
!= str_p
)
744 input_line_pointer
= orig_line
;
751 return BFD_RELOC_UNUSED
;
754 /* Like normal .long/.short/.word, except support @got, etc. */
755 /* clobbers input_line_pointer, checks end-of-line. */
757 i370_elf_cons (nbytes
)
758 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
761 bfd_reloc_code_real_type reloc
;
763 if (is_it_end_of_statement ())
765 demand_empty_rest_of_line ();
772 if (exp
.X_op
== O_symbol
773 && *input_line_pointer
== '@'
774 && (reloc
= i370_elf_suffix (&input_line_pointer
, &exp
)) != BFD_RELOC_UNUSED
)
776 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
777 int size
= bfd_get_reloc_size (reloc_howto
);
780 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto
->name
, nbytes
);
784 register char *p
= frag_more ((int) nbytes
);
785 int offset
= nbytes
- size
;
787 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, size
, &exp
, 0, reloc
);
791 emit_expr (&exp
, (unsigned int) nbytes
);
793 while (*input_line_pointer
++ == ',');
795 input_line_pointer
--; /* Put terminator back into stream. */
796 demand_empty_rest_of_line ();
800 /* ASCII to EBCDIC conversion table. */
801 static unsigned char ascebc
[256] =
803 /*00 NL SH SX EX ET NQ AK BL */
804 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F,
805 /*08 BS HT LF VT FF CR SO SI */
806 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
807 /*10 DL D1 D2 D3 D4 NK SN EB */
808 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26,
809 /*18 CN EM SB EC FS GS RS US */
810 0x18, 0x19, 0x3F, 0x27, 0x1C, 0x1D, 0x1E, 0x1F,
811 /*20 SP ! " # $ % & ' */
812 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D,
813 /*28 ( ) * + , - . / */
814 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
815 /*30 0 1 2 3 4 5 6 7 */
816 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
817 /*38 8 9 : ; < = > ? */
818 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
819 /*40 @ A B C D E F G */
820 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
821 /*48 H I J K L M N O */
822 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
823 /*50 P Q R S T U V W */
824 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
825 /*58 X Y Z [ \ ] ^ _ */
826 0xE7, 0xE8, 0xE9, 0xAD, 0xE0, 0xBD, 0x5F, 0x6D,
827 /*60 ` a b c d e f g */
828 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
829 /*68 h i j k l m n o */
830 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
831 /*70 p q r s t u v w */
832 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
833 /*78 x y z { | } ~ DL */
834 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07,
835 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
836 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
837 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
838 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
839 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
840 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
841 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
842 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
843 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
844 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
845 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
846 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
847 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
848 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
849 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
850 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0xFF
853 /* EBCDIC to ASCII conversion table. */
854 unsigned char ebcasc
[256] =
856 /*00 NU SH SX EX PF HT LC DL */
857 0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
858 /*08 SM VT FF CR SO SI */
859 0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
860 /*10 DE D1 D2 TM RS NL BS IL */
861 0x10, 0x11, 0x12, 0x13, 0x14, 0x0A, 0x08, 0x00,
862 /*18 CN EM CC C1 FS GS RS US */
863 0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
864 /*20 DS SS FS BP LF EB EC */
865 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
866 /*28 SM C2 EQ AK BL */
867 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07, 0x00,
868 /*30 SY PN RS UC ET */
869 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
871 0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
873 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
875 0x00, 0x00, 0x00, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
877 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
879 0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
881 0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
883 0x00, 0x00, 0x00, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
885 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
886 /*78 ` : # @ ' = " */
887 0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
888 /*80 a b c d e f g */
889 0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
891 0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
892 /*90 j k l m n o p */
893 0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
895 0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
896 /*A0 ~ s t u v w x */
897 0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
899 0x79, 0x7A, 0x00, 0x00, 0x00, 0x5B, 0x00, 0x00,
901 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
903 0x00, 0x00, 0x00, 0x00, 0x00, 0x5D, 0x00, 0x00,
904 /*C0 { A B C D E F G */
905 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
907 0x48, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
908 /*D0 } J K L M N O P */
909 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
911 0x51, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
912 /*E0 \ S T U V W X */
913 0x5C, 0x00, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
915 0x59, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
916 /*F0 0 1 2 3 4 5 6 7 */
917 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
919 0x38, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
922 /* ebcdic translation tables needed for 3270 support */
931 nbytes
= strlen (input_line_pointer
);
932 end
= input_line_pointer
+ nbytes
;
933 while ('\r' == *end
) end
--;
934 while ('\n' == *end
) end
--;
936 delim
= *input_line_pointer
;
937 if (('\'' == delim
) || ('\"' == delim
)) {
938 input_line_pointer
++;
939 end
= rindex (input_line_pointer
, delim
);
942 if (end
> input_line_pointer
)
944 nbytes
= end
- input_line_pointer
+1;
945 p
= frag_more (nbytes
);
946 while (end
> input_line_pointer
)
948 *p
= ascebc
[(unsigned char)(*input_line_pointer
)];
949 ++p
; ++input_line_pointer
;
953 if (delim
== *input_line_pointer
) ++input_line_pointer
;
957 /* stub out a couple of routines */
962 as_tsktsk ("rmode ignored");
969 char *save_line
= input_line_pointer
;
970 static char section
[] = ".data\n";
972 /* Just pretend this is .section .data */
973 input_line_pointer
= section
;
974 obj_elf_section (sect
);
976 input_line_pointer
= save_line
;
983 as_tsktsk ("csect not supported");
987 /* DC Define Const is only partially supported.
988 * For samplecode on what to do, look at i370_elf_cons() above.
989 * This code handles pseudoops of the style
990 * DC D'3.141592653' # in sysv4, .double 3.14159265
991 * DC F'1' # in sysv4, .long 1
1002 if (is_it_end_of_statement ())
1004 demand_empty_rest_of_line ();
1008 /* figure out the size */
1009 type
= *input_line_pointer
++;
1012 case 'H': /* 16-bit */
1015 case 'E': /* 32-bit */
1016 case 'F': /* 32-bit */
1019 case 'D': /* 64-bit */
1023 as_bad ("unsupported DC type");
1027 /* get rid of pesky quotes */
1028 if ('\'' == *input_line_pointer
)
1031 ++input_line_pointer
;
1032 close
= strchr (input_line_pointer
, '\'');
1036 as_bad ("missing end-quote");
1038 if ('\"' == *input_line_pointer
)
1041 ++input_line_pointer
;
1042 close
= strchr (input_line_pointer
, '\"');
1046 as_bad ("missing end-quote");
1051 case 'H': /* 16-bit */
1052 case 'F': /* 32-bit */
1054 emit_expr (&exp
, nbytes
);
1056 case 'E': /* 32-bit */
1057 case 'D': /* 64-bit */
1058 md_atof (type
, tmp
, &nbytes
);
1059 p
= frag_more (nbytes
);
1060 memcpy (p
, tmp
, nbytes
);
1063 as_bad ("unsupported DC type");
1067 demand_empty_rest_of_line ();
1071 /* provide minimal support for DS Define Storage */
1076 /* DS 0H or DS 0F or DS 0D */
1077 if ('0' == *input_line_pointer
)
1079 int alignment
= 0; /* left shift 1<<align */
1080 input_line_pointer
++;
1081 switch (*input_line_pointer
++)
1083 case 'H': /* 16-bit */
1086 case 'F': /* 32-bit */
1089 case 'D': /* 64-bit */
1093 as_bad ("unsupported alignment");
1096 frag_align (alignment
, 0, 0);
1097 record_alignment (now_seg
, alignment
);
1101 as_bad ("this DS form not yet supported");
1105 /* Solaris pseudo op to change to the .rodata section. */
1107 i370_elf_rdata (sect
)
1110 char *save_line
= input_line_pointer
;
1111 static char section
[] = ".rodata\n";
1113 /* Just pretend this is .section .rodata */
1114 input_line_pointer
= section
;
1115 obj_elf_section (sect
);
1117 input_line_pointer
= save_line
;
1120 /* Pseudo op to make file scope bss items */
1122 i370_elf_lcomm(unused
)
1125 register char *name
;
1129 register symbolS
*symbolP
;
1136 name
= input_line_pointer
;
1137 c
= get_symbol_end ();
1139 /* just after name is now '\0' */
1140 p
= input_line_pointer
;
1143 if (*input_line_pointer
!= ',')
1145 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1146 ignore_rest_of_line ();
1150 input_line_pointer
++; /* skip ',' */
1151 if ((size
= get_absolute_expression ()) < 0)
1153 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size
);
1154 ignore_rest_of_line ();
1158 /* The third argument to .lcomm is the alignment. */
1159 if (*input_line_pointer
!= ',')
1163 ++input_line_pointer
;
1164 align
= get_absolute_expression ();
1167 as_warn ("ignoring bad alignment");
1173 symbolP
= symbol_find_or_make (name
);
1176 if (S_IS_DEFINED (symbolP
) && ! S_IS_COMMON (symbolP
))
1178 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1179 S_GET_NAME (symbolP
));
1180 ignore_rest_of_line ();
1184 if (S_GET_VALUE (symbolP
) && S_GET_VALUE (symbolP
) != (valueT
) size
)
1186 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1187 S_GET_NAME (symbolP
),
1188 (long) S_GET_VALUE (symbolP
),
1191 ignore_rest_of_line ();
1197 old_subsec
= now_subseg
;
1200 /* convert to a power of 2 alignment */
1201 for (align2
= 0; (align
& 1) == 0; align
>>= 1, ++align2
)
1205 as_bad ("Common alignment not a power of 2");
1206 ignore_rest_of_line ();
1213 record_alignment (bss_section
, align2
);
1214 subseg_set (bss_section
, 0);
1216 frag_align (align2
, 0, 0);
1217 if (S_GET_SEGMENT (symbolP
) == bss_section
)
1218 symbol_get_frag (symbolP
)->fr_symbol
= 0;
1219 symbol_set_frag (symbolP
, frag_now
);
1220 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, symbolP
, size
,
1223 S_SET_SIZE (symbolP
, size
);
1224 S_SET_SEGMENT (symbolP
, bss_section
);
1225 subseg_set (old_sec
, old_subsec
);
1226 demand_empty_rest_of_line ();
1229 /* Validate any relocations emitted for -mrelocatable, possibly adding
1230 fixups for word relocations in writable segments, so we can adjust
1233 i370_elf_validate_fix (fixp
, seg
)
1237 if (fixp
->fx_done
|| fixp
->fx_pcrel
)
1246 case SHILB_MRELOCATABLE
:
1247 if (fixp
->fx_r_type
<= BFD_RELOC_UNUSED
1248 && fixp
->fx_r_type
!= BFD_RELOC_16_GOTOFF
1249 && fixp
->fx_r_type
!= BFD_RELOC_HI16_GOTOFF
1250 && fixp
->fx_r_type
!= BFD_RELOC_LO16_GOTOFF
1251 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_GOTOFF
1252 && fixp
->fx_r_type
!= BFD_RELOC_32_BASEREL
1253 && fixp
->fx_r_type
!= BFD_RELOC_LO16_BASEREL
1254 && fixp
->fx_r_type
!= BFD_RELOC_HI16_BASEREL
1255 && fixp
->fx_r_type
!= BFD_RELOC_HI16_S_BASEREL
1256 && strcmp (segment_name (seg
), ".got2") != 0
1257 && strcmp (segment_name (seg
), ".dtors") != 0
1258 && strcmp (segment_name (seg
), ".ctors") != 0
1259 && strcmp (segment_name (seg
), ".fixup") != 0
1260 && strcmp (segment_name (seg
), ".stab") != 0
1261 && strcmp (segment_name (seg
), ".gcc_except_table") != 0
1262 && strcmp (segment_name (seg
), ".ex_shared") != 0)
1264 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
1265 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
1267 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1268 "Relocation cannot be done when using -mrelocatable");
1274 #endif /* OBJ_ELF */
1278 #define LITERAL_POOL_SUPPORT
1279 #ifdef LITERAL_POOL_SUPPORT
1280 /* Provide support for literal pools within the text section. */
1281 /* Loosely based on similar code from tc-arm.c */
1283 * We will use four symbols to locate four parts of the literal pool.
1284 * These four sections contain 64,32,16 and 8-bit constants; we use
1285 * four sections so that all memory access can be appropriately aligned.
1286 * That is, we want to avoid mixing these together so that we don't
1287 * waste space padding out to alignments. The four pointers
1288 * longlong_poolP, word_poolP, etc. point to a symbol labeling the
1289 * start of each pool part.
1291 * lit_pool_num increments from zero to infinity and uniquely id's
1292 * -- its used to generate the *_poolP symbol name.
1295 #define MAX_LITERAL_POOL_SIZE 1024
1297 typedef struct literalS
1299 struct expressionS exp
;
1301 char size
; /* 1,2,4 or 8 */
1305 literalT literals
[MAX_LITERAL_POOL_SIZE
];
1306 int next_literal_pool_place
= 0; /* Next free entry in the pool */
1308 static symbolS
*longlong_poolP
= NULL
; /* 64-bit pool entries */
1309 static symbolS
*word_poolP
= NULL
; /* 32-bit pool entries */
1310 static symbolS
*short_poolP
= NULL
; /* 16-bit pool entries */
1311 static symbolS
*byte_poolP
= NULL
; /* 8-bit pool entries */
1313 static int lit_pool_num
= 1;
1315 /* create a new, empty symbol */
1317 symbol_make_empty (void)
1319 return symbol_create (FAKE_LABEL_NAME
, undefined_section
,
1320 (valueT
) 0, &zero_address_frag
);
1323 /* add an expression to the literal pool */
1325 add_to_lit_pool (expressionS
*exx
, char *name
, int sz
)
1328 int offset_in_pool
= 0;
1330 /* start a new pool, if necessary */
1331 if (8 == sz
&& NULL
== longlong_poolP
)
1332 longlong_poolP
= symbol_make_empty();
1333 else if (4 == sz
&& NULL
== word_poolP
)
1334 word_poolP
= symbol_make_empty();
1335 else if (2 == sz
&& NULL
== short_poolP
)
1336 short_poolP
= symbol_make_empty();
1337 else if (1 == sz
&& NULL
== byte_poolP
)
1338 byte_poolP
= symbol_make_empty();
1340 /* Check if this literal value is already in the pool: */
1341 /* hack alert -- we should probably be checking expressions
1342 * of type O_symbol as well ... */
1343 /* hack alert XXX this is probably(certainly?) broken for O_big,
1344 * which includes 64-bit long-longs ...
1346 while (lit_count
< next_literal_pool_place
)
1348 if (exx
->X_op
== O_constant
1349 && literals
[lit_count
].exp
.X_op
== exx
->X_op
1350 && literals
[lit_count
].exp
.X_add_number
== exx
->X_add_number
1351 && literals
[lit_count
].exp
.X_unsigned
== exx
->X_unsigned
1352 && literals
[lit_count
].size
== sz
)
1354 else if (literals
[lit_count
].sym_name
1356 && !strcmp (name
, literals
[lit_count
].sym_name
))
1358 if (sz
== literals
[lit_count
].size
)
1359 offset_in_pool
+= sz
;
1363 if (lit_count
== next_literal_pool_place
) /* new entry */
1365 if (next_literal_pool_place
> MAX_LITERAL_POOL_SIZE
)
1367 as_bad("Literal Pool Overflow");
1370 literals
[next_literal_pool_place
].exp
= *exx
;
1371 literals
[next_literal_pool_place
].size
= sz
;
1372 literals
[next_literal_pool_place
].offset
= offset_in_pool
;
1375 literals
[next_literal_pool_place
].sym_name
= strdup (name
);
1379 literals
[next_literal_pool_place
].sym_name
= NULL
;
1381 next_literal_pool_place
++;
1384 /* ???_poolP points to the begining of the literal pool.
1385 * X_add_number is the offset from the begining of the
1386 * literal pool to this expr minus the location of the most
1387 * recent .using directive. Thus, the grand total value of the
1388 * expression is the distance from .using to the literal.
1391 exx
->X_add_symbol
= longlong_poolP
;
1393 exx
->X_add_symbol
= word_poolP
;
1395 exx
->X_add_symbol
= short_poolP
;
1397 exx
->X_add_symbol
= byte_poolP
;
1398 exx
->X_add_number
= offset_in_pool
;
1399 exx
->X_op_symbol
= NULL
;
1401 /* If the user has set up a base reg in another section,
1402 * use that; otherwise use the text section. */
1403 if (0 < i370_using_other_regno
)
1405 i370_make_relative (exx
, &i370_using_other_baseaddr
);
1409 i370_make_relative (exx
, &i370_using_text_baseaddr
);
1413 /* The symbol setup for the literal pool is done in two steps. First,
1414 * a symbol that represents the start of the literal pool is created,
1415 * above, in the add_to_pool() routine. This sym ???_poolP.
1416 * However, we don't know what fragment its in until a bit later.
1417 * So we defer the frag_now thing, and the symbol name, until .ltorg time
1420 /* Can't use symbol_new here, so have to create a symbol and then at
1421 a later date assign it a value. Thats what these functions do */
1423 symbol_locate (symbolP
, name
, segment
, valu
, frag
)
1425 CONST
char *name
; /* It is copied, the caller can modify */
1426 segT segment
; /* Segment identifier (SEG_<something>) */
1427 valueT valu
; /* Symbol value */
1428 fragS
*frag
; /* Associated fragment */
1431 char *preserved_copy_of_name
;
1433 name_length
= strlen (name
) + 1; /* +1 for \0 */
1434 obstack_grow (¬es
, name
, name_length
);
1435 preserved_copy_of_name
= obstack_finish (¬es
);
1437 S_SET_NAME (symbolP
, preserved_copy_of_name
);
1439 S_SET_SEGMENT (symbolP
, segment
);
1440 S_SET_VALUE (symbolP
, valu
);
1441 symbol_clear_list_pointers(symbolP
);
1443 symbol_set_frag (symbolP
, frag
);
1446 * Link to end of symbol chain.
1449 extern int symbol_table_frozen
;
1450 if (symbol_table_frozen
)
1454 symbol_append (symbolP
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1456 obj_symbol_new_hook (symbolP
);
1458 #ifdef tc_symbol_new_hook
1459 tc_symbol_new_hook (symbolP
);
1464 verify_symbol_chain(symbol_rootP
, symbol_lastP
);
1465 #endif /* DEBUG_SYMS */
1468 /* i370_addr_offset() will convert operand expressions
1469 * that appear to be absolute into thier base-register
1470 * relative form. These expressions come in two types:
1472 * (1) of the form "* + const" * where "*" means
1473 * relative offset since the last using
1474 * i.e. "*" means ".-using_baseaddr"
1476 * (2) labels, which are never absolute, but are always
1477 * relative to the last "using". Anything with an alpha
1478 * character is considered to be a label (since symbols
1479 * can never be operands), and since we've already handled
1480 * register operands. For example, "BL .L33" branch low
1481 * to .L33 RX form insn frequently terminates for-loops,
1484 i370_addr_offset (expressionS
*exx
)
1490 /* search for a label; anything with an alpha char will do */
1491 /* local labels consist of N digits followed by either b or f */
1492 lab
= input_line_pointer
;
1493 while (*lab
&& (',' != *lab
) && ('(' != *lab
))
1499 else if (isalpha(*lab
))
1506 else if (('f' == *lab
) || ('b' == *lab
))
1514 else if ('.' != *lab
)
1519 /* See if operand has a * in it */
1520 dot
= strchr (input_line_pointer
, '*');
1522 if (!dot
&& !islabel
)
1525 /* replace * with . and let expr munch on it. */
1530 /* OK, now we have to subtract the "using" location */
1531 /* normally branches appear in the text section only... */
1532 if (0 == strncmp (now_seg
->name
, ".text", 5) || 0 > i370_using_other_regno
)
1534 i370_make_relative (exx
, &i370_using_text_baseaddr
);
1538 i370_make_relative (exx
, &i370_using_other_baseaddr
);
1541 /* put the * back */
1548 /* handle address constants of various sorts */
1549 /* The currently supported types are
1552 * =X'deadbeef' hexadecimal
1553 * =F'1234' 32-bit const int
1554 * =H'1234' 16-bit const int
1557 i370_addr_cons (expressionS
*exp
)
1560 char *sym_name
, delim
;
1565 name
= input_line_pointer
;
1566 sym_name
= input_line_pointer
;
1567 /* Find the spelling of the operand */
1568 if (name
[0] == '=' && isalpha (name
[1]))
1570 name
= ++input_line_pointer
;
1580 /* A == address-of */
1582 ++input_line_pointer
;
1585 /* we use a simple string name to collapse together
1586 * multiple refrences to the same address literal
1588 name_len
= strcspn (sym_name
, ", ");
1589 delim
= *(sym_name
+ name_len
);
1590 *(sym_name
+ name_len
) = 0x0;
1591 add_to_lit_pool (exp
, sym_name
, 4);
1592 *(sym_name
+ name_len
) = delim
;
1598 case 'E': /* single-precision float point */
1599 case 'D': /* double-precision float point */
1601 /* H == 16-bit fixed-point const; expression must be const */
1602 /* F == fixed-point const; expression must be const */
1603 /* X == fixed-point const; expression must be const */
1604 if ('H' == name
[0]) cons_len
= 2;
1605 else if ('F' == name
[0]) cons_len
= 4;
1606 else if ('X' == name
[0]) cons_len
= -1;
1607 else if ('E' == name
[0]) cons_len
= 4;
1608 else if ('D' == name
[0]) cons_len
= 8;
1610 /* extract length, if it is present; hack alert -- assume single-digit
1614 cons_len
= name
[2] - '0'; /* should work for ascii and ebcdic */
1615 input_line_pointer
+= 2;
1618 ++input_line_pointer
;
1620 /* get rid of pesky quotes */
1621 if ('\'' == *input_line_pointer
)
1624 ++input_line_pointer
;
1625 close
= strchr (input_line_pointer
, '\'');
1629 as_bad ("missing end-quote");
1631 if ('\"' == *input_line_pointer
)
1634 ++input_line_pointer
;
1635 close
= strchr (input_line_pointer
, '\"');
1639 as_bad ("missing end-quote");
1641 if (('X' == name
[0]) || ('E' == name
[0]) || ('D' == name
[0]))
1646 /* The length of hex constants is specified directly with L,
1647 * or implied through the number of hex digits. For example:
1649 * =X'abcd' two bytes
1650 * =X'000000AB' four bytes
1651 * =XL4'AB' four bytes, left-padded withn zero
1653 if (('X' == name
[0]) && (0 > cons_len
))
1655 save
= input_line_pointer
;
1658 if (isxdigit(*save
))
1662 cons_len
= (hex_len
+1) /2;
1664 /* I beleive this works even for =XL8'dada0000beeebaaa'
1665 * which should parse out to X_op == O_big
1666 * Note that floats and doubles get represented as
1667 * 0d3.14159265358979 or 0f 2.7
1672 strcat (tmp
, input_line_pointer
);
1673 save
= input_line_pointer
;
1674 input_line_pointer
= tmp
;
1676 input_line_pointer
= save
+ (input_line_pointer
-tmp
-2);
1678 /* fix up lengths for floats and doubles */
1679 if (O_big
== exp
->X_op
)
1681 exp
->X_add_number
= cons_len
/ CHARS_PER_LITTLENUM
;
1688 /* O_big occurs when more than 4 bytes worth gets parsed */
1689 if ((exp
->X_op
!= O_constant
) && (exp
->X_op
!= O_big
))
1691 as_bad ("expression not a constant");
1694 add_to_lit_pool (exp
, 0x0, cons_len
);
1698 as_bad ("Unknown/unsupported address literal type");
1706 /* Dump the contents of the literal pool that we've accumulated so far.
1707 * This aligns the pool to the size of the largest literal in the pool.
1716 int biggest_literal_size
= 0;
1717 int biggest_align
= 0;
1720 if (strncmp (now_seg
->name
, ".text", 5))
1722 if (i370_other_section
== undefined_section
)
1724 as_bad (".ltorg without prior .using in section %s",
1727 if (i370_other_section
!= now_seg
)
1729 as_bad (".ltorg in section %s paired to .using in section %s",
1730 now_seg
->name
, i370_other_section
->name
);
1733 if (! longlong_poolP
1739 /* as_tsktsk ("Nothing to put in the pool\n"); */
1743 /* find largest literal .. 2 4 or 8 */
1745 while (lit_count
< next_literal_pool_place
)
1747 if (biggest_literal_size
< literals
[lit_count
].size
)
1748 biggest_literal_size
= literals
[lit_count
].size
;
1751 if (1 == biggest_literal_size
) biggest_align
= 0;
1752 else if (2 == biggest_literal_size
) biggest_align
= 1;
1753 else if (4 == biggest_literal_size
) biggest_align
= 2;
1754 else if (8 == biggest_literal_size
) biggest_align
= 3;
1755 else as_bad ("bad alignment of %d bytes in literal pool", biggest_literal_size
);
1756 if (0 == biggest_align
) biggest_align
= 1;
1759 /* Align pool for short, word, double word accesses */
1760 frag_align (biggest_align
, 0, 0);
1761 record_alignment (now_seg
, biggest_align
);
1763 /* Note that the gas listing will print only the first five
1764 * entries in the pool .... wonder how to make it print more ...
1766 /* output largest literals first, then the smaller ones. */
1767 for (litsize
=8; litsize
; litsize
/=2)
1769 symbolS
*current_poolP
= NULL
;
1773 current_poolP
= longlong_poolP
; break;
1775 current_poolP
= word_poolP
; break;
1777 current_poolP
= short_poolP
; break;
1779 current_poolP
= byte_poolP
; break;
1781 as_bad ("bad literal size\n");
1783 if (NULL
== current_poolP
)
1785 sprintf (pool_name
, ".LITP%01d%06d", litsize
, lit_pool_num
);
1786 symbol_locate (current_poolP
, pool_name
, now_seg
,
1787 (valueT
) frag_now_fix (), frag_now
);
1788 symbol_table_insert (current_poolP
);
1791 while (lit_count
< next_literal_pool_place
)
1793 if (litsize
== literals
[lit_count
].size
)
1795 #define EMIT_ADDR_CONS_SYMBOLS
1796 #ifdef EMIT_ADDR_CONS_SYMBOLS
1797 /* create a bogus symbol, add it to the pool ...
1798 * For the most part, I think this is a useless excercise,
1799 * except that having these symbol names in the objects
1800 * is vaguely useful for debugging ...
1802 if (literals
[lit_count
].sym_name
)
1804 symbolS
* symP
= symbol_make_empty();
1805 symbol_locate (symP
, literals
[lit_count
].sym_name
, now_seg
,
1806 (valueT
) frag_now_fix (), frag_now
);
1807 symbol_table_insert (symP
);
1809 #endif /* EMIT_ADDR_CONS_SYMBOLS */
1811 emit_expr (&(literals
[lit_count
].exp
), literals
[lit_count
].size
);
1817 next_literal_pool_place
= 0;
1818 longlong_poolP
= NULL
;
1825 #endif /* LITERAL_POOL_SUPPORT */
1828 /* add support for the HLASM-like USING directive to indicate
1829 * the base register to use ... we don't support the full
1830 * hlasm semantics for this ... we merely pluck a base address
1831 * and a register number out. We print a warning if using is
1832 * called multiple times. I suppose we should check to see
1833 * if the regno is valid ...
1839 expressionS ex
, baseaddr
;
1843 /* if "*" appears in a using, it means "." */
1844 /* replace it with "." so that expr doesn't get confused. */
1845 star
= strchr (input_line_pointer
, '*');
1849 /* the first arg to using will usually be ".", but it can
1850 * be a more complex exprsssion too ... */
1851 expression (&baseaddr
);
1854 if (O_constant
!= baseaddr
.X_op
1855 && O_symbol
!= baseaddr
.X_op
1856 && O_uminus
!= baseaddr
.X_op
)
1858 as_bad (".using: base address expression illegal or too complex");
1861 if (*input_line_pointer
!= '\0') ++input_line_pointer
;
1863 /* the second arg to using had better be a register */
1864 register_name (&ex
);
1865 demand_empty_rest_of_line ();
1866 iregno
= ex
.X_add_number
;
1868 if (0 == strncmp (now_seg
->name
, ".text", 5))
1870 i370_using_text_baseaddr
= baseaddr
;
1871 i370_using_text_regno
= iregno
;
1875 i370_using_other_baseaddr
= baseaddr
;
1876 i370_using_other_regno
= iregno
;
1877 i370_other_section
= now_seg
;
1888 register_name (&ex
);
1889 demand_empty_rest_of_line ();
1890 iregno
= ex
.X_add_number
;
1892 if (0 == strncmp (now_seg
->name
, ".text", 5))
1894 if (iregno
!= i370_using_text_regno
)
1896 as_bad ("droping register %d in section %s does not match using register %d",
1897 iregno
, now_seg
->name
, i370_using_text_regno
);
1899 i370_using_text_regno
= -1;
1900 i370_using_text_baseaddr
.X_op
= O_absent
;
1904 if (iregno
!= i370_using_other_regno
)
1906 as_bad ("droping register %d in section %s does not match using register %d",
1907 iregno
, now_seg
->name
, i370_using_other_regno
);
1909 if (i370_other_section
!= now_seg
)
1911 as_bad ("droping register %d in section %s previously used in section %s",
1912 iregno
, now_seg
->name
, i370_other_section
->name
);
1914 i370_using_other_regno
= -1;
1915 i370_using_other_baseaddr
.X_op
= O_absent
;
1916 i370_other_section
= undefined_section
;
1920 /* Make the first argument an address-relative expression
1921 * by subtracting the second argument.
1924 i370_make_relative (expressionS
*exx
, expressionS
*baseaddr
)
1927 if (O_constant
== baseaddr
->X_op
)
1929 exx
->X_op
= O_symbol
;
1930 exx
->X_add_number
-= baseaddr
->X_add_number
;
1932 else if (O_symbol
== baseaddr
->X_op
)
1934 exx
->X_op
= O_subtract
;
1935 exx
->X_op_symbol
= baseaddr
->X_add_symbol
;
1936 exx
->X_add_number
-= baseaddr
->X_add_number
;
1938 else if (O_uminus
== baseaddr
->X_op
)
1941 exx
->X_op_symbol
= baseaddr
->X_add_symbol
;
1942 exx
->X_add_number
+= baseaddr
->X_add_number
;
1946 as_bad ("Missing or bad .using directive");
1950 /* We need to keep a list of fixups. We can't simply generate them as
1951 we go, because that would require us to first create the frag, and
1952 that would screw up references to ``.''. */
1958 bfd_reloc_code_real_type reloc
;
1961 #define MAX_INSN_FIXUPS (5)
1963 /* This routine is called for each instruction to be assembled. */
1969 char *s
, *opcode_str
;
1970 const struct i370_opcode
*opcode
;
1972 const unsigned char *opindex_ptr
;
1973 int have_optional_index
, have_optional_basereg
, have_optional_reg
;
1974 int skip_optional_index
, skip_optional_basereg
, skip_optional_reg
;
1975 int use_text
=0, use_other
=0;
1977 struct i370_fixup fixups
[MAX_INSN_FIXUPS
];
1982 bfd_reloc_code_real_type reloc
;
1985 /* Get the opcode. */
1986 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
1992 /* Look up the opcode in the hash table. */
1993 opcode
= (const struct i370_opcode
*) hash_find (i370_hash
, str
);
1994 if (opcode
== (const struct i370_opcode
*) NULL
)
1996 const struct i370_macro
*macro
;
1998 assert (i370_macro_hash
);
1999 macro
= (const struct i370_macro
*) hash_find (i370_macro_hash
, str
);
2000 if (macro
== (const struct i370_macro
*) NULL
)
2001 as_bad ("Unrecognized opcode: `%s'", str
);
2003 i370_macro (s
, macro
);
2008 insn
= opcode
->opcode
;
2011 while (isspace (*str
))
2014 /* I370 operands are either expressions or address constants.
2015 Many operand types are optional. The optional operands
2016 are always surrounded by parens, and are used to denote the base
2017 register ... e.g. "A R1, D2" or "A R1, D2(,B2) as opposed to
2018 the fully-formed "A R1, D2(X2,B2)". Note also the = sign,
2019 such as A R1,=A(i) where the address-of operator =A implies
2020 use of both a base register, and a missing index register.
2022 So, before we start seriously parsing the operands, we check
2023 to see if we have an optional operand, and, if we do, we count
2024 the number of commas to see which operand should be omitted. */
2026 have_optional_index
= have_optional_basereg
= have_optional_reg
= 0;
2027 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2029 const struct i370_operand
*operand
;
2030 operand
= &i370_operands
[*opindex_ptr
];
2031 if ((operand
->flags
& I370_OPERAND_INDEX
) != 0)
2032 have_optional_index
= 1;
2033 if ((operand
->flags
& I370_OPERAND_BASE
) != 0)
2034 have_optional_basereg
= 1;
2035 if ((operand
->flags
& I370_OPERAND_OPTIONAL
) != 0)
2036 have_optional_reg
= 1;
2039 skip_optional_index
= skip_optional_basereg
= skip_optional_reg
= 0;
2040 if (have_optional_index
|| have_optional_basereg
)
2042 unsigned int opcount
, nwanted
;
2044 /* There is an optional operand. Count the number of
2045 commas and open-parens in the input line. */
2052 while ((s
= strpbrk (s
, ",(=")) != (char *) NULL
)
2056 if (',' == *s
) ++s
; /* avoid counting things like (, */
2057 if ('=' == *s
) { ++s
; --opcount
; }
2061 /* If there are fewer operands in the line then are called
2062 for by the instruction, we want to skip the optional
2064 nwanted
= strlen (opcode
->operands
);
2065 if (have_optional_index
)
2067 if (opcount
< nwanted
)
2068 skip_optional_index
= 1;
2069 if (have_optional_basereg
&& ((opcount
+1) < nwanted
))
2070 skip_optional_basereg
= 1;
2071 if (have_optional_reg
&& ((opcount
+1) < nwanted
))
2072 skip_optional_reg
= 1;
2076 if (have_optional_basereg
&& (opcount
< nwanted
))
2077 skip_optional_basereg
= 1;
2078 if (have_optional_reg
&& (opcount
< nwanted
))
2079 skip_optional_reg
= 1;
2083 /* Perform some off-by-one hacks on the length field of certain instructions.
2084 * Its such a shame to have to do this, but the problem is that HLASM got
2085 * defined so that the lengths differ by one from the actual machine instructions.
2086 * this code should probably be moved to a special inster-operand routine.
2087 * Sigh. Affected instructions are Compare Logical, Move and Exclusive OR
2088 * hack alert -- aren't *all* SS instructions affected ??
2091 if (0 == strcasecmp ("CLC", opcode
->name
)
2092 || 0 == strcasecmp ("ED", opcode
->name
)
2093 || 0 == strcasecmp ("EDMK", opcode
->name
)
2094 || 0 == strcasecmp ("MVC", opcode
->name
)
2095 || 0 == strcasecmp ("MVCIN", opcode
->name
)
2096 || 0 == strcasecmp ("MVN", opcode
->name
)
2097 || 0 == strcasecmp ("MVZ", opcode
->name
)
2098 || 0 == strcasecmp ("NC", opcode
->name
)
2099 || 0 == strcasecmp ("OC", opcode
->name
)
2100 || 0 == strcasecmp ("XC", opcode
->name
))
2103 /* Gather the operands. */
2105 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
2107 const struct i370_operand
*operand
;
2112 operand
= &i370_operands
[*opindex_ptr
];
2115 /* If this is an index operand, and we are skipping it,
2116 just insert a zero. */
2117 if (skip_optional_index
&&
2118 ((operand
->flags
& I370_OPERAND_INDEX
) != 0))
2120 insn
= i370_insert_operand (insn
, operand
, 0);
2124 /* If this is the base operand, and we are skipping it,
2125 just insert the current using basreg. */
2126 if (skip_optional_basereg
&&
2127 ((operand
->flags
& I370_OPERAND_BASE
) != 0))
2132 if (0 == strncmp (now_seg
->name
, ".text", 5)
2133 || 0 > i370_using_other_regno
)
2135 basereg
= i370_using_text_regno
;
2139 basereg
= i370_using_other_regno
;
2144 if (0 > i370_using_other_regno
)
2146 basereg
= i370_using_text_regno
;
2150 basereg
= i370_using_other_regno
;
2155 as_bad ("not using any base register");
2157 insn
= i370_insert_operand (insn
, operand
, basereg
);
2161 /* If this is an optional operand, and we are skipping it,
2162 Use zero (since a non-zero value would denote a register) */
2163 if (skip_optional_reg
2164 && ((operand
->flags
& I370_OPERAND_OPTIONAL
) != 0))
2166 insn
= i370_insert_operand (insn
, operand
, 0);
2170 /* Gather the operand. */
2171 hold
= input_line_pointer
;
2172 input_line_pointer
= str
;
2174 /* register names are only allowed where there are registers ... */
2175 if ((operand
->flags
& I370_OPERAND_GPR
) != 0)
2177 /* quickie hack to get past things like (,r13) */
2178 if (skip_optional_index
&& (',' == *input_line_pointer
))
2180 *input_line_pointer
= ' ';
2181 input_line_pointer
++;
2183 if (! register_name (&ex
))
2185 as_bad ("expecting a register for operand %d",
2186 opindex_ptr
- opcode
->operands
+ 1);
2190 /* check for a address constant expression */
2191 /* We will put PSW-relative addresses in the text section,
2192 * and adress literals in the .data (or other) section. */
2193 else if (i370_addr_cons (&ex
))
2195 else if (i370_addr_offset (&ex
))
2197 else expression (&ex
);
2199 str
= input_line_pointer
;
2200 input_line_pointer
= hold
;
2202 /* perform some off-by-one hacks on the length field of certain instructions.
2203 * Its such a shame to have to do this, but the problem is that HLASM got
2204 * defined so that the programmer specifies a length that is one greater
2205 * than what the machine instruction wants.
2208 if (off_by_one
&& (0 == strcasecmp ("SS L", operand
->name
)))
2213 if (ex
.X_op
== O_illegal
)
2214 as_bad ("illegal operand");
2215 else if (ex
.X_op
== O_absent
)
2216 as_bad ("missing operand");
2217 else if (ex
.X_op
== O_register
)
2219 insn
= i370_insert_operand (insn
, operand
, ex
.X_add_number
);
2221 else if (ex
.X_op
== O_constant
)
2224 /* Allow @HA, @L, @H on constants.
2225 * Well actually, no we don't; there really don't make sense
2226 * (at least not to me) for the i370. However, this code is
2227 * left here for any dubious future expansion reasons ... */
2228 char *orig_str
= str
;
2230 if ((reloc
= i370_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2237 case BFD_RELOC_LO16
:
2238 /* X_unsigned is the default, so if the user has done
2239 something which cleared it, we always produce a
2241 ex
.X_add_number
= (((ex
.X_add_number
& 0xffff)
2246 case BFD_RELOC_HI16
:
2247 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
2250 case BFD_RELOC_HI16_S
:
2251 ex
.X_add_number
= (((ex
.X_add_number
>> 16) & 0xffff)
2252 + ((ex
.X_add_number
>> 15) & 1));
2256 insn
= i370_insert_operand (insn
, operand
, ex
.X_add_number
);
2259 else if ((reloc
= i370_elf_suffix (&str
, &ex
)) != BFD_RELOC_UNUSED
)
2261 as_tsktsk ("md_assemble(): suffixed relocations not supported\n");
2263 /* We need to generate a fixup for this expression. */
2264 if (fc
>= MAX_INSN_FIXUPS
)
2265 as_fatal ("too many fixups");
2266 fixups
[fc
].exp
= ex
;
2267 fixups
[fc
].opindex
= 0;
2268 fixups
[fc
].reloc
= reloc
;
2271 #endif /* OBJ_ELF */
2275 /* We need to generate a fixup for this expression. */
2276 /* Typically, the expression will just be a symbol ...
2277 * printf ("insn %s needs fixup for %s \n",
2278 * opcode->name, ex.X_add_symbol->bsym->name);
2281 if (fc
>= MAX_INSN_FIXUPS
)
2282 as_fatal ("too many fixups");
2283 fixups
[fc
].exp
= ex
;
2284 fixups
[fc
].opindex
= *opindex_ptr
;
2285 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
2289 /* skip over delimiter (close paren, or comma) */
2290 if ((')' == *str
) && (',' == *(str
+1)))
2296 while (isspace (*str
))
2300 as_bad ("junk at end of line: `%s'", str
);
2302 /* Write out the instruction. */
2303 f
= frag_more (opcode
->len
);
2304 if (4 >= opcode
->len
)
2306 md_number_to_chars (f
, insn
.i
[0], opcode
->len
);
2310 md_number_to_chars (f
, insn
.i
[0], 4);
2311 if (6 == opcode
->len
)
2313 md_number_to_chars ((f
+4), ((insn
.i
[1])>>16), 2);
2317 /* not used --- don't have any 8 byte instructions */
2318 as_bad ("Internal Error: bad instruction length");
2319 md_number_to_chars ((f
+4), insn
.i
[1], opcode
->len
-4);
2323 /* Create any fixups. At this point we do not use a
2324 bfd_reloc_code_real_type, but instead just use the
2325 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2326 handle fixups for any operand type, although that is admittedly
2327 not a very exciting feature. We pick a BFD reloc type in
2329 for (i
= 0; i
< fc
; i
++)
2331 const struct i370_operand
*operand
;
2333 operand
= &i370_operands
[fixups
[i
].opindex
];
2334 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
2336 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
2343 size
= bfd_get_reloc_size (reloc_howto
);
2345 if (size
< 1 || size
> 4)
2348 printf (" gwana doo fixup %d \n", i
);
2349 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, size
,
2350 &fixups
[i
].exp
, reloc_howto
->pc_relative
,
2353 /* Turn off complaints that the addend is too large for things like
2355 switch (fixups
[i
].reloc
)
2357 case BFD_RELOC_16_GOTOFF
:
2358 case BFD_RELOC_LO16
:
2359 case BFD_RELOC_HI16
:
2360 case BFD_RELOC_HI16_S
:
2361 fixP
->fx_no_overflow
= 1;
2369 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, opcode
->len
,
2371 (operand
->flags
& I370_OPERAND_RELATIVE
) != 0,
2372 ((bfd_reloc_code_real_type
)
2373 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
2378 /* Handle a macro. Gather all the operands, transform them as
2379 described by the macro, and call md_assemble recursively. All the
2380 operands are separated by commas; we don't accept parentheses
2381 around operands here. */
2384 i370_macro (str
, macro
)
2386 const struct i370_macro
*macro
;
2397 /* Gather the users operands into the operands array. */
2402 if (count
>= sizeof operands
/ sizeof operands
[0])
2404 operands
[count
++] = s
;
2405 s
= strchr (s
, ',');
2406 if (s
== (char *) NULL
)
2411 if (count
!= macro
->operands
)
2413 as_bad ("wrong number of operands");
2417 /* Work out how large the string must be (the size is unbounded
2418 because it includes user input). */
2420 format
= macro
->format
;
2421 while (*format
!= '\0')
2430 arg
= strtol (format
+ 1, &send
, 10);
2431 know (send
!= format
&& arg
>= 0 && arg
< count
);
2432 len
+= strlen (operands
[arg
]);
2437 /* Put the string together. */
2438 complete
= s
= (char *) alloca (len
+ 1);
2439 format
= macro
->format
;
2440 while (*format
!= '\0')
2446 arg
= strtol (format
+ 1, &send
, 10);
2447 strcpy (s
, operands
[arg
]);
2454 /* Assemble the constructed instruction. */
2455 md_assemble (complete
);
2459 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2462 i370_section_letter (letter
, ptr_msg
)
2469 *ptr_msg
= "Bad .section directive: want a,w,x,e in string";
2474 i370_section_word (str
, len
)
2478 if (len
== 7 && strncmp (str
, "exclude", 7) == 0)
2485 i370_section_type (str
, len
)
2489 if (len
== 7 && strncmp (str
, "ordered", 7) == 0)
2496 i370_section_flags (flags
, attr
, type
)
2501 if (type
== SHT_ORDERED
)
2502 flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_SORT_ENTRIES
;
2504 if (attr
& SHF_EXCLUDE
)
2505 flags
|= SEC_EXCLUDE
;
2509 #endif /* OBJ_ELF */
2512 /* Pseudo-op handling. */
2514 /* The .byte pseudo-op. This is similar to the normal .byte
2515 pseudo-op, but it can also take a single ASCII string. */
2521 if (*input_line_pointer
!= '\"')
2527 /* Gather characters. A real double quote is doubled. Unusual
2528 characters are not permitted. */
2529 ++input_line_pointer
;
2534 c
= *input_line_pointer
++;
2538 if (*input_line_pointer
!= '\"')
2540 ++input_line_pointer
;
2543 FRAG_APPEND_1_CHAR (c
);
2546 demand_empty_rest_of_line ();
2549 /* The .tc pseudo-op. This is used when generating XCOFF and ELF.
2550 This takes two or more arguments.
2552 When generating XCOFF output, the first argument is the name to
2553 give to this location in the toc; this will be a symbol with class
2554 TC. The rest of the arguments are 4 byte values to actually put at
2555 this location in the TOC; often there is just one more argument, a
2556 relocateable symbol reference.
2558 When not generating XCOFF output, the arguments are the same, but
2559 the first argument is simply ignored. */
2566 /* Skip the TOC symbol name. */
2567 while (is_part_of_name (*input_line_pointer
)
2568 || *input_line_pointer
== '['
2569 || *input_line_pointer
== ']'
2570 || *input_line_pointer
== '{'
2571 || *input_line_pointer
== '}')
2572 ++input_line_pointer
;
2574 /* Align to a four byte boundary. */
2575 frag_align (2, 0, 0);
2576 record_alignment (now_seg
, 2);
2578 if (*input_line_pointer
!= ',')
2579 demand_empty_rest_of_line ();
2582 ++input_line_pointer
;
2587 /* Turn a string in input_line_pointer into a floating point constant
2588 of type type, and store the appropriate bytes in *litp. The number
2589 of LITTLENUMS emitted is stored in *sizep . An error message is
2590 returned, or NULL on OK. */
2593 md_atof (type
, litp
, sizep
)
2599 LITTLENUM_TYPE words
[4];
2619 return "bad call to md_atof";
2622 /* 360/370/390 have two float formats: an old, funky 360 single-precision
2623 * format, and the ieee format. Support only the ieee format. */
2624 t
= atof_ieee (input_line_pointer
, type
, words
);
2626 input_line_pointer
= t
;
2630 for (i
= 0; i
< prec
; i
++)
2632 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2639 /* Write a value out to the object file, using the appropriate
2643 md_number_to_chars (buf
, val
, n
)
2648 number_to_chars_bigendian (buf
, val
, n
);
2651 /* Align a section (I don't know why this is machine dependent). */
2654 md_section_align (seg
, addr
)
2658 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2660 return (addr
+ (1 << align
) - 1) & (-1 << align
);
2663 /* We don't have any form of relaxing. */
2666 md_estimate_size_before_relax (fragp
, seg
)
2674 /* Convert a machine dependent frag. We never generate these. */
2677 md_convert_frag (abfd
, sec
, fragp
)
2685 /* We have no need to default values of symbols. */
2689 md_undefined_symbol (name
)
2695 /* Functions concerning relocs. */
2697 /* The location from which a PC relative jump should be calculated,
2698 given a PC relative reloc. */
2701 md_pcrel_from_section (fixp
, sec
)
2705 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2709 /* Apply a fixup to the object code. This is called for all the
2710 fixups we generated by the call to fix_new_exp, above. In the call
2711 above we used a reloc code which was the largest legal reloc code
2712 plus the operand index. Here we undo that to recover the operand
2713 index. At this point all symbol values should be fully resolved,
2714 and we attempt to completely resolve the reloc. If we can not do
2715 that, we determine the correct reloc code and put it back in the
2718 See gas/cgen.c for more sample code and explanations of what's
2723 md_apply_fix3 (fixp
, valuep
, seg
)
2731 if (fixp
->fx_addsy
!= NULL
)
2734 Branches to labels will come in here with fixp->fx_pcrel set to 1
2735 and fixp->fx_subsy not null, and holding the value of the base
2736 (i.e. the value of the .using). These we want to ignore.
2738 'Strong' and 'weak' symbols will come in here with
2739 fixp->fx_pcrel==0, fixp->fx_addsy defined, and
2740 *valuep holding the value of the symbol.
2742 'Strong' symbols will have S_GET_VALUE(fx_addsy) equal to zero,
2743 whereas 'weak' symbols will have S_GET_VALUE(fx_addsy) set to the
2744 symbol value (usually).
2746 We want to subtract S_GET_VALUE(fx_addsy) if it set, and
2747 for all practical purposes, do a fixup with value zero. This
2748 is because the linker/loader, at a later time, will do this
2749 fixup with the correct value. If we fixup now with a value,
2750 it will get double-fixed, leading to garbage.
2752 Note that subsy will also be set for strong/weak symbols
2753 when the user program was compiled with -g. In that case,
2754 subsy will hold the base address (i.e. the .using address).
2757 if (fixp
->fx_addsy
->sy_used_in_reloc
2758 && S_GET_SEGMENT (fixp
->fx_addsy
) != absolute_section
2759 && S_GET_SEGMENT (fixp
->fx_addsy
) != undefined_section
2760 && ! bfd_is_com_section (S_GET_SEGMENT (fixp
->fx_addsy
)))
2761 value
-= S_GET_VALUE (fixp
->fx_addsy
);
2764 printf ("\nmd_apply_fix3: symbol %s at 0x%x (%s:%d) val=0x%x addend=0x%x\n",
2765 S_GET_NAME (fixp
->fx_addsy
),
2766 fixp
->fx_frag
->fr_address
+ fixp
->fx_where
,
2767 fixp
->fx_file
, fixp
->fx_line
,
2768 S_GET_VALUE (fixp
->fx_addsy
), value
);
2777 /* Apply fixups to operands. Note that there should be no relocations
2778 for any operands, since no instruction ever takes an operand
2779 that requires reloc. */
2780 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2783 const struct i370_operand
*operand
;
2787 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2789 operand
= &i370_operands
[opindex
];
2792 printf ("\nmd_apply_fix3: fixup operand %s at 0x%x in %s:%d addend=0x%x\n",
2794 fixp
->fx_frag
->fr_address
+ fixp
->fx_where
,
2795 fixp
->fx_file
, fixp
->fx_line
,
2798 /* Fetch the instruction, insert the fully resolved operand
2799 value, and stuff the instruction back again.
2800 fisxp->fx_size is the length of the instruction. */
2801 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2802 insn
.i
[0] = bfd_getb32 ((unsigned char *) where
);
2803 if (6 <= fixp
->fx_size
)
2804 { /* deal with 48-bit insn's */
2805 insn
.i
[1] = bfd_getb32 (((unsigned char *) where
)+4);
2807 insn
= i370_insert_operand (insn
, operand
, (offsetT
) value
);
2808 bfd_putb32 ((bfd_vma
) insn
.i
[0], (unsigned char *) where
);
2809 if (6 <= fixp
->fx_size
)
2810 { /* deal with 48-bit insn's */
2811 bfd_putb32 ((bfd_vma
) insn
.i
[1], (((unsigned char *) where
)+4));
2814 /* we are done, right? right !! */
2818 /* Nothing else to do here. */
2822 /* Determine a BFD reloc value based on the operand information.
2823 We are only prepared to turn a few of the operands into
2824 relocs. In fact, we support *zero* operand relocations ...
2825 Why? Because we are not expecting the compiler to generate
2826 any operands that need relocation. Due to the 12-bit naturew of
2827 i370 addressing, this would be unusual. */
2829 if ((operand
->flags
& I370_OPERAND_RELATIVE
) != 0
2830 && operand
->bits
== 12
2831 && operand
->shift
== 0)
2832 fixp
->fx_r_type
= BFD_RELOC_I370_D12
;
2839 /* Use expr_symbol_where to see if this is an expression
2841 if (expr_symbol_where (fixp
->fx_addsy
, &sfile
, &sline
))
2842 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2843 "unresolved expression that must be resolved");
2845 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2846 "unsupported relocation type");
2853 /* We branch to here if the fixup is not to a symbol that
2854 * appears in an instruction operand, but is rather some
2858 i370_elf_validate_fix (fixp
, seg
);
2861 printf ("md_apply_fix3: reloc case %d in segment %s %s:%d\n",
2862 fixp
->fx_r_type
, segment_name (seg
), fixp
->fx_file
, fixp
->fx_line
);
2863 printf ("\tcurrent fixup value is 0x%x \n", value
);
2865 switch (fixp
->fx_r_type
)
2868 case BFD_RELOC_CTOR
:
2870 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
2874 case BFD_RELOC_32_PCREL
:
2875 case BFD_RELOC_32_BASEREL
:
2877 printf ("\t32 bit relocation at 0x%x\n",
2878 fixp
->fx_frag
->fr_address
+ fixp
->fx_where
);
2880 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2884 case BFD_RELOC_LO16
:
2887 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2888 "cannot emit PC relative %s relocation%s%s",
2889 bfd_get_reloc_code_name (fixp
->fx_r_type
),
2890 fixp
->fx_addsy
!= NULL
? " against " : "",
2891 (fixp
->fx_addsy
!= NULL
2892 ? S_GET_NAME (fixp
->fx_addsy
)
2895 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2899 /* This case happens when you write, for example,
2901 where L1 and L2 are defined later. */
2902 case BFD_RELOC_HI16
:
2905 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2908 case BFD_RELOC_HI16_S
:
2911 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2912 (value
+ 0x8000) >> 16, 2);
2919 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2925 "Gas failure, reloc value %d\n", fixp
->fx_r_type
);
2931 fixp
->fx_addnumber
= value
;
2936 /* Generate a reloc for a fixup. */
2939 tc_gen_reloc (seg
, fixp
)
2945 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
2947 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2948 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2949 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2950 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2951 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2953 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2954 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
2957 reloc
->addend
= fixp
->fx_addnumber
;
2960 printf ("\ngen_reloc(): sym %s (%s:%d) at addr 0x%x addend=0x%x\n",
2961 fixp
->fx_addsy
->bsym
->name
,
2962 fixp
->fx_file
, fixp
->fx_line
,
2963 reloc
->address
, reloc
->addend
);