1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 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
25 #include "safe-ctype.h"
28 #include "opcode/ppc.h"
32 #include "dwarf2dbg.h"
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian;
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian = 0;
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
50 #define TARGET_REG_NAMES_P true
52 #define TARGET_REG_NAMES_P false
56 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
68 #define PPC_HA(v) ((((v) >> 16) + (((v) >> 15) & 1)) & 0xffff)
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 32) & 0xffff)
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) \
76 ((((v) >> 32) + (((v) & 0xffff8000) == 0xffff8000)) & 0xffff)
78 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
79 #define PPC_HIGHEST(v) (((v) >> 48) & 0xffff)
81 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
82 compensating for #lo being treated as a signed number.
83 Generate 0xffffffff8000 with arithmetic here, for portability. */
84 #define PPC_HIGHESTA(v) \
86 + (((v) & (((valueT) 1 << 48) - 0x8000)) == ((valueT) 1 << 48) - 0x8000)) \
89 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
91 static boolean reg_names_p = TARGET_REG_NAMES_P;
93 static boolean register_name PARAMS ((expressionS *));
94 static void ppc_set_cpu PARAMS ((void));
95 static unsigned long ppc_insert_operand
96 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
97 offsetT val, char *file, unsigned int line));
98 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
99 static void ppc_byte PARAMS ((int));
101 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
102 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
103 static void ppc_tc PARAMS ((int));
104 static void ppc_machine PARAMS ((int));
108 static void ppc_comm PARAMS ((int));
109 static void ppc_bb PARAMS ((int));
110 static void ppc_bc PARAMS ((int));
111 static void ppc_bf PARAMS ((int));
112 static void ppc_biei PARAMS ((int));
113 static void ppc_bs PARAMS ((int));
114 static void ppc_eb PARAMS ((int));
115 static void ppc_ec PARAMS ((int));
116 static void ppc_ef PARAMS ((int));
117 static void ppc_es PARAMS ((int));
118 static void ppc_csect PARAMS ((int));
119 static void ppc_change_csect PARAMS ((symbolS *));
120 static void ppc_function PARAMS ((int));
121 static void ppc_extern PARAMS ((int));
122 static void ppc_lglobl PARAMS ((int));
123 static void ppc_section PARAMS ((int));
124 static void ppc_named_section PARAMS ((int));
125 static void ppc_stabx PARAMS ((int));
126 static void ppc_rename PARAMS ((int));
127 static void ppc_toc PARAMS ((int));
128 static void ppc_xcoff_cons PARAMS ((int));
129 static void ppc_vbyte PARAMS ((int));
133 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
134 static void ppc_elf_cons PARAMS ((int));
135 static void ppc_elf_rdata PARAMS ((int));
136 static void ppc_elf_lcomm PARAMS ((int));
137 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
141 static void ppc_set_current_section PARAMS ((segT));
142 static void ppc_previous PARAMS ((int));
143 static void ppc_pdata PARAMS ((int));
144 static void ppc_ydata PARAMS ((int));
145 static void ppc_reldata PARAMS ((int));
146 static void ppc_rdata PARAMS ((int));
147 static void ppc_ualong PARAMS ((int));
148 static void ppc_znop PARAMS ((int));
149 static void ppc_pe_comm PARAMS ((int));
150 static void ppc_pe_section PARAMS ((int));
151 static void ppc_pe_function PARAMS ((int));
152 static void ppc_pe_tocd PARAMS ((int));
155 /* Generic assembler global variables which must be defined by all
159 /* This string holds the chars that always start a comment. If the
160 pre-processor is disabled, these aren't very useful. The macro
161 tc_comment_chars points to this. We use this, rather than the
162 usual comment_chars, so that we can switch for Solaris conventions. */
163 static const char ppc_solaris_comment_chars[] = "#!";
164 static const char ppc_eabi_comment_chars[] = "#";
166 #ifdef TARGET_SOLARIS_COMMENT
167 const char *ppc_comment_chars = ppc_solaris_comment_chars;
169 const char *ppc_comment_chars = ppc_eabi_comment_chars;
172 const char comment_chars[] = "#";
175 /* Characters which start a comment at the beginning of a line. */
176 const char line_comment_chars[] = "#";
178 /* Characters which may be used to separate multiple commands on a
180 const char line_separator_chars[] = ";";
182 /* Characters which are used to indicate an exponent in a floating
184 const char EXP_CHARS[] = "eE";
186 /* Characters which mean that a number is a floating point constant,
188 const char FLT_CHARS[] = "dD";
190 /* The target specific pseudo-ops which we support. */
192 const pseudo_typeS md_pseudo_table[] =
194 /* Pseudo-ops which must be overridden. */
195 { "byte", ppc_byte, 0 },
198 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
199 legitimately belong in the obj-*.c file. However, XCOFF is based
200 on COFF, and is only implemented for the RS/6000. We just use
201 obj-coff.c, and add what we need here. */
202 { "comm", ppc_comm, 0 },
203 { "lcomm", ppc_comm, 1 },
207 { "bi", ppc_biei, 0 },
209 { "csect", ppc_csect, 0 },
210 { "data", ppc_section, 'd' },
214 { "ei", ppc_biei, 1 },
216 { "extern", ppc_extern, 0 },
217 { "function", ppc_function, 0 },
218 { "lglobl", ppc_lglobl, 0 },
219 { "rename", ppc_rename, 0 },
220 { "section", ppc_named_section, 0 },
221 { "stabx", ppc_stabx, 0 },
222 { "text", ppc_section, 't' },
223 { "toc", ppc_toc, 0 },
224 { "long", ppc_xcoff_cons, 2 },
225 { "llong", ppc_xcoff_cons, 3 },
226 { "word", ppc_xcoff_cons, 1 },
227 { "short", ppc_xcoff_cons, 1 },
228 { "vbyte", ppc_vbyte, 0 },
232 { "llong", ppc_elf_cons, 8 },
233 { "quad", ppc_elf_cons, 8 },
234 { "long", ppc_elf_cons, 4 },
235 { "word", ppc_elf_cons, 2 },
236 { "short", ppc_elf_cons, 2 },
237 { "rdata", ppc_elf_rdata, 0 },
238 { "rodata", ppc_elf_rdata, 0 },
239 { "lcomm", ppc_elf_lcomm, 0 },
240 { "file", dwarf2_directive_file, 0 },
241 { "loc", dwarf2_directive_loc, 0 },
245 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
246 { "previous", ppc_previous, 0 },
247 { "pdata", ppc_pdata, 0 },
248 { "ydata", ppc_ydata, 0 },
249 { "reldata", ppc_reldata, 0 },
250 { "rdata", ppc_rdata, 0 },
251 { "ualong", ppc_ualong, 0 },
252 { "znop", ppc_znop, 0 },
253 { "comm", ppc_pe_comm, 0 },
254 { "lcomm", ppc_pe_comm, 1 },
255 { "section", ppc_pe_section, 0 },
256 { "function", ppc_pe_function,0 },
257 { "tocd", ppc_pe_tocd, 0 },
260 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
262 { "machine", ppc_machine, 0 },
269 /* Predefined register names if -mregnames (or default for Windows NT).
270 In general, there are lots of them, in an attempt to be compatible
271 with a number of other Windows NT assemblers. */
273 /* Structure to hold information about predefined registers. */
280 /* List of registers that are pre-defined:
282 Each general register has predefined names of the form:
283 1. r<reg_num> which has the value <reg_num>.
284 2. r.<reg_num> which has the value <reg_num>.
286 Each floating point register has predefined names of the form:
287 1. f<reg_num> which has the value <reg_num>.
288 2. f.<reg_num> which has the value <reg_num>.
290 Each vector unit register has predefined names of the form:
291 1. v<reg_num> which has the value <reg_num>.
292 2. v.<reg_num> which has the value <reg_num>.
294 Each condition register has predefined names of the form:
295 1. cr<reg_num> which has the value <reg_num>.
296 2. cr.<reg_num> which has the value <reg_num>.
298 There are individual registers as well:
299 sp or r.sp has the value 1
300 rtoc or r.toc has the value 2
301 fpscr has the value 0
307 dsisr has the value 18
309 sdr1 has the value 25
310 srr0 has the value 26
311 srr1 has the value 27
313 The table is sorted. Suitable for searching by a binary search. */
315 static const struct pd_reg pre_defined_registers[] =
317 { "cr.0", 0 }, /* Condition Registers */
337 { "dar", 19 }, /* Data Access Register */
338 { "dec", 22 }, /* Decrementer */
339 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
341 { "f.0", 0 }, /* Floating point registers */
409 { "lr", 8 }, /* Link Register */
413 { "r.0", 0 }, /* General Purpose Registers */
446 { "r.sp", 1 }, /* Stack Pointer */
448 { "r.toc", 2 }, /* Pointer to the table of contents */
450 { "r0", 0 }, /* More general purpose registers */
483 { "rtoc", 2 }, /* Table of contents */
485 { "sdr1", 25 }, /* Storage Description Register 1 */
489 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
490 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
492 { "v.0", 0 }, /* Vector registers */
562 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
564 /* Given NAME, find the register number associated with that name, return
565 the integer value associated with the given name or -1 on failure. */
567 static int reg_name_search
568 PARAMS ((const struct pd_reg *, int, const char * name));
571 reg_name_search (regs, regcount, name)
572 const struct pd_reg *regs;
576 int middle, low, high;
584 middle = (low + high) / 2;
585 cmp = strcasecmp (name, regs[middle].name);
591 return regs[middle].value;
599 * Summary of register_name.
601 * in: Input_line_pointer points to 1st char of operand.
603 * out: A expressionS.
604 * The operand may have been a register: in this case, X_op == O_register,
605 * X_add_number is set to the register number, and truth is returned.
606 * Input_line_pointer->(next non-blank) char after operand, or is in its
611 register_name (expressionP)
612 expressionS *expressionP;
619 /* Find the spelling of the operand. */
620 start = name = input_line_pointer;
621 if (name[0] == '%' && ISALPHA (name[1]))
622 name = ++input_line_pointer;
624 else if (!reg_names_p || !ISALPHA (name[0]))
627 c = get_symbol_end ();
628 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
630 /* Put back the delimiting char. */
631 *input_line_pointer = c;
633 /* Look to see if it's in the register table. */
636 expressionP->X_op = O_register;
637 expressionP->X_add_number = reg_number;
639 /* Make the rest nice. */
640 expressionP->X_add_symbol = NULL;
641 expressionP->X_op_symbol = NULL;
645 /* Reset the line as if we had not done anything. */
646 input_line_pointer = start;
650 /* This function is called for each symbol seen in an expression. It
651 handles the special parsing which PowerPC assemblers are supposed
652 to use for condition codes. */
654 /* Whether to do the special parsing. */
655 static boolean cr_operand;
657 /* Names to recognize in a condition code. This table is sorted. */
658 static const struct pd_reg cr_names[] =
675 /* Parsing function. This returns non-zero if it recognized an
679 ppc_parse_name (name, expr)
688 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
693 expr->X_op = O_constant;
694 expr->X_add_number = val;
699 /* Local variables. */
701 /* The type of processor we are assembling for. This is one or more
702 of the PPC_OPCODE flags defined in opcode/ppc.h. */
703 static int ppc_cpu = 0;
705 /* The size of the processor we are assembling for. This is either
706 PPC_OPCODE_32 or PPC_OPCODE_64. */
707 static unsigned long ppc_size = PPC_OPCODE_32;
709 /* Whether to target xcoff64. */
710 static int ppc_xcoff64 = 0;
712 /* Opcode hash table. */
713 static struct hash_control *ppc_hash;
715 /* Macro hash table. */
716 static struct hash_control *ppc_macro_hash;
719 /* What type of shared library support to use. */
720 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
722 /* Flags to set in the elf header. */
723 static flagword ppc_flags = 0;
725 /* Whether this is Solaris or not. */
726 #ifdef TARGET_SOLARIS_COMMENT
727 #define SOLARIS_P true
729 #define SOLARIS_P false
732 static boolean msolaris = SOLARIS_P;
737 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
738 using a bunch of different sections. These assembler sections,
739 however, are all encompassed within the .text or .data sections of
740 the final output file. We handle this by using different
741 subsegments within these main segments. */
743 /* Next subsegment to allocate within the .text segment. */
744 static subsegT ppc_text_subsegment = 2;
746 /* Linked list of csects in the text section. */
747 static symbolS *ppc_text_csects;
749 /* Next subsegment to allocate within the .data segment. */
750 static subsegT ppc_data_subsegment = 2;
752 /* Linked list of csects in the data section. */
753 static symbolS *ppc_data_csects;
755 /* The current csect. */
756 static symbolS *ppc_current_csect;
758 /* The RS/6000 assembler uses a TOC which holds addresses of functions
759 and variables. Symbols are put in the TOC with the .tc pseudo-op.
760 A special relocation is used when accessing TOC entries. We handle
761 the TOC as a subsegment within the .data segment. We set it up if
762 we see a .toc pseudo-op, and save the csect symbol here. */
763 static symbolS *ppc_toc_csect;
765 /* The first frag in the TOC subsegment. */
766 static fragS *ppc_toc_frag;
768 /* The first frag in the first subsegment after the TOC in the .data
769 segment. NULL if there are no subsegments after the TOC. */
770 static fragS *ppc_after_toc_frag;
772 /* The current static block. */
773 static symbolS *ppc_current_block;
775 /* The COFF debugging section; set by md_begin. This is not the
776 .debug section, but is instead the secret BFD section which will
777 cause BFD to set the section number of a symbol to N_DEBUG. */
778 static asection *ppc_coff_debug_section;
780 #endif /* OBJ_XCOFF */
784 /* Various sections that we need for PE coff support. */
785 static segT ydata_section;
786 static segT pdata_section;
787 static segT reldata_section;
788 static segT rdata_section;
789 static segT tocdata_section;
791 /* The current section and the previous section. See ppc_previous. */
792 static segT ppc_previous_section;
793 static segT ppc_current_section;
798 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
802 CONST char *md_shortopts = "b:l:usm:K:VQ:";
804 CONST char *md_shortopts = "um:";
806 struct option md_longopts[] = {
807 {NULL, no_argument, NULL, 0}
809 size_t md_longopts_size = sizeof (md_longopts);
812 md_parse_option (c, arg)
819 /* -u means that any undefined symbols should be treated as
820 external, which is the default for gas anyhow. */
825 /* Solaris as takes -le (presumably for little endian). For completeness
826 sake, recognize -be also. */
827 if (strcmp (arg, "e") == 0)
829 target_big_endian = 0;
830 set_target_endian = 1;
838 if (strcmp (arg, "e") == 0)
840 target_big_endian = 1;
841 set_target_endian = 1;
849 /* Recognize -K PIC. */
850 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
853 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
861 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
863 if (strcmp (arg, "64") == 0)
865 else if (strcmp (arg, "32") == 0)
872 /* Most CPU's are 32 bit. Exceptions are listed below. */
873 ppc_size = PPC_OPCODE_32;
875 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
877 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
878 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
879 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
880 else if (strcmp (arg, "pwr") == 0)
881 ppc_cpu = PPC_OPCODE_POWER;
882 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
883 instructions that are holdovers from the Power. */
884 else if (strcmp (arg, "601") == 0)
885 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
886 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
887 Motorola PowerPC 603/604. */
888 else if (strcmp (arg, "ppc") == 0
889 || strcmp (arg, "ppc32") == 0
890 || strcmp (arg, "603") == 0
891 || strcmp (arg, "604") == 0)
892 ppc_cpu = PPC_OPCODE_PPC;
893 /* -m403 and -m405 mean to assemble for the Motorola PowerPC 403/405. */
894 else if (strcmp (arg, "403") == 0
895 || strcmp (arg, "405") == 0)
896 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_403;
897 else if (strcmp (arg, "7400") == 0
898 || strcmp (arg, "7410") == 0
899 || strcmp (arg, "7450") == 0
900 || strcmp (arg, "7455") == 0)
901 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_ALTIVEC;
902 else if (strcmp (arg, "altivec") == 0)
903 ppc_cpu |= PPC_OPCODE_ALTIVEC;
904 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
906 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
908 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64;
909 ppc_size = PPC_OPCODE_64;
911 else if (strcmp (arg, "ppc64bridge") == 0)
913 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64_BRIDGE | PPC_OPCODE_64;
914 ppc_size = PPC_OPCODE_64;
916 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
917 else if (strcmp (arg, "booke") == 0 || strcmp (arg, "booke32") == 0)
918 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE;
919 /* -mbooke64 means enable 64-bit BookE support. */
920 else if (strcmp (arg, "booke64") == 0)
922 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE |
923 PPC_OPCODE_BOOKE64 | PPC_OPCODE_64;
924 ppc_size = PPC_OPCODE_64;
926 /* -mcom means assemble for the common intersection between Power
927 and PowerPC. At present, we just allow the union, rather
928 than the intersection. */
929 else if (strcmp (arg, "com") == 0)
930 ppc_cpu = PPC_OPCODE_COMMON;
931 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
932 else if (strcmp (arg, "any") == 0)
933 ppc_cpu = PPC_OPCODE_ANY;
935 else if (strcmp (arg, "regnames") == 0)
938 else if (strcmp (arg, "no-regnames") == 0)
942 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
943 that require relocation. */
944 else if (strcmp (arg, "relocatable") == 0)
946 shlib = SHLIB_MRELOCATABLE;
947 ppc_flags |= EF_PPC_RELOCATABLE;
950 else if (strcmp (arg, "relocatable-lib") == 0)
952 shlib = SHLIB_MRELOCATABLE;
953 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
956 /* -memb, set embedded bit. */
957 else if (strcmp (arg, "emb") == 0)
958 ppc_flags |= EF_PPC_EMB;
960 /* -mlittle/-mbig set the endianess. */
961 else if (strcmp (arg, "little") == 0
962 || strcmp (arg, "little-endian") == 0)
964 target_big_endian = 0;
965 set_target_endian = 1;
968 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
970 target_big_endian = 1;
971 set_target_endian = 1;
974 else if (strcmp (arg, "solaris") == 0)
977 ppc_comment_chars = ppc_solaris_comment_chars;
980 else if (strcmp (arg, "no-solaris") == 0)
983 ppc_comment_chars = ppc_eabi_comment_chars;
988 as_bad (_("invalid switch -m%s"), arg);
994 /* -V: SVR4 argument to print version ID. */
999 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1000 should be emitted or not. FIXME: Not implemented. */
1004 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1005 rather than .stabs.excl, which is ignored by the linker.
1006 FIXME: Not implemented. */
1022 md_show_usage (stream)
1025 fprintf (stream, _("\
1028 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
1029 -mpwr generate code for IBM POWER (RIOS1)\n\
1030 -m601 generate code for Motorola PowerPC 601\n\
1031 -mppc, -mppc32, -m603, -m604\n\
1032 generate code for Motorola PowerPC 603/604\n\
1033 -m403, -m405 generate code for Motorola PowerPC 403/405\n\
1034 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
1035 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1036 -mbooke64 generate code for 64-bit Motorola BookE\n\
1037 -mbooke, mbooke32 generate code for 32-bit Motorola BookE\n\
1038 -mcom generate code Power/PowerPC common instructions\n\
1039 -many generate code for any architecture (PWR/PWRX/PPC)\n\
1040 -mregnames Allow symbolic names for registers\n\
1041 -mno-regnames Do not allow symbolic names for registers\n"));
1043 fprintf (stream, _("\
1044 -mrelocatable support for GCC's -mrelocatble option\n\
1045 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1046 -memb set PPC_EMB bit in ELF flags\n\
1047 -mlittle, -mlittle-endian\n\
1048 generate code for a little endian machine\n\
1049 -mbig, -mbig-endian generate code for a big endian machine\n\
1050 -msolaris generate code for Solaris\n\
1051 -mno-solaris do not generate code for Solaris\n\
1052 -V print assembler version number\n\
1053 -Qy, -Qn ignored\n"));
1057 /* Set ppc_cpu if it is not already set. */
1062 const char *default_os = TARGET_OS;
1063 const char *default_cpu = TARGET_CPU;
1067 if (strncmp (default_os, "aix", 3) == 0
1068 && default_os[3] >= '4' && default_os[3] <= '9')
1069 ppc_cpu = PPC_OPCODE_COMMON;
1070 else if (strncmp (default_os, "aix3", 4) == 0)
1071 ppc_cpu = PPC_OPCODE_POWER;
1072 else if (strcmp (default_cpu, "rs6000") == 0)
1073 ppc_cpu = PPC_OPCODE_POWER;
1074 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1075 ppc_cpu = PPC_OPCODE_PPC;
1077 as_fatal (_("Unknown default cpu = %s, os = %s"),
1078 default_cpu, default_os);
1082 /* Figure out the BFD architecture to use. */
1084 enum bfd_architecture
1087 const char *default_cpu = TARGET_CPU;
1090 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1091 return bfd_arch_powerpc;
1092 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1093 return bfd_arch_rs6000;
1094 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1096 if (strcmp (default_cpu, "rs6000") == 0)
1097 return bfd_arch_rs6000;
1098 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1099 return bfd_arch_powerpc;
1102 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1103 return bfd_arch_unknown;
1109 return ppc_size == PPC_OPCODE_64 ? 620 : 0;
1116 return ppc_xcoff64 ? 3 : 2;
1121 ppc_target_format ()
1125 return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1127 return "xcoff-powermac";
1129 return ppc_xcoff64 ? "aixcoff64-rs6000" : "aixcoff-rs6000";
1133 return (target_big_endian
1134 ? (BFD_DEFAULT_TARGET_SIZE == 64 ? "elf64-powerpc" : "elf32-powerpc")
1135 : (BFD_DEFAULT_TARGET_SIZE == 64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1139 /* This function is called when the assembler starts up. It is called
1140 after the options have been parsed and the output file has been
1146 register const struct powerpc_opcode *op;
1147 const struct powerpc_opcode *op_end;
1148 const struct powerpc_macro *macro;
1149 const struct powerpc_macro *macro_end;
1150 boolean dup_insn = false;
1155 /* If we're going to generate a 64-bit ABI file, then we need
1156 the 64-bit capable instructions. */
1157 if (BFD_DEFAULT_TARGET_SIZE == 64)
1158 ppc_size = PPC_OPCODE_64;
1160 /* Set the ELF flags if desired. */
1161 if (ppc_flags && !msolaris)
1162 bfd_set_private_flags (stdoutput, ppc_flags);
1165 /* Insert the opcodes into a hash table. */
1166 ppc_hash = hash_new ();
1168 op_end = powerpc_opcodes + powerpc_num_opcodes;
1169 for (op = powerpc_opcodes; op < op_end; op++)
1171 know ((op->opcode & op->mask) == op->opcode);
1173 if ((op->flags & ppc_cpu) != 0
1174 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
1175 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size
1176 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0))
1180 retval = hash_insert (ppc_hash, op->name, (PTR) op);
1181 if (retval != (const char *) NULL)
1183 /* Ignore Power duplicates for -m601. */
1184 if ((ppc_cpu & PPC_OPCODE_601) != 0
1185 && (op->flags & PPC_OPCODE_POWER) != 0)
1188 as_bad (_("Internal assembler error for instruction %s"),
1195 /* Insert the macros into a hash table. */
1196 ppc_macro_hash = hash_new ();
1198 macro_end = powerpc_macros + powerpc_num_macros;
1199 for (macro = powerpc_macros; macro < macro_end; macro++)
1201 if ((macro->flags & ppc_cpu) != 0)
1205 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1206 if (retval != (const char *) NULL)
1208 as_bad (_("Internal assembler error for macro %s"), macro->name);
1217 /* Tell the main code what the endianness is if it is not overidden
1219 if (!set_target_endian)
1221 set_target_endian = 1;
1222 target_big_endian = PPC_BIG_ENDIAN;
1226 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1228 /* Create dummy symbols to serve as initial csects. This forces the
1229 text csects to precede the data csects. These symbols will not
1231 ppc_text_csects = symbol_make ("dummy\001");
1232 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1233 ppc_data_csects = symbol_make ("dummy\001");
1234 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1239 ppc_current_section = text_section;
1240 ppc_previous_section = 0;
1245 /* Insert an operand value into an instruction. */
1247 static unsigned long
1248 ppc_insert_operand (insn, operand, val, file, line)
1250 const struct powerpc_operand *operand;
1255 if (operand->bits != 32)
1260 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1262 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1263 max = (1 << operand->bits) - 1;
1265 max = (1 << (operand->bits - 1)) - 1;
1266 min = - (1 << (operand->bits - 1));
1268 if (ppc_size == PPC_OPCODE_32)
1270 /* Some people write 32 bit hex constants with the sign
1271 extension done by hand. This shouldn't really be
1272 valid, but, to permit this code to assemble on a 64
1273 bit host, we sign extend the 32 bit value. */
1275 && (val & (offsetT) 0x80000000) != 0
1276 && (val & (offsetT) 0xffffffff) == val)
1285 max = (1 << operand->bits) - 1;
1289 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1294 if (test < (offsetT) min || test > (offsetT) max)
1297 _("operand out of range (%s not between %ld and %ld)");
1300 sprint_value (buf, test);
1301 as_bad_where (file, line, err, buf, min, max);
1305 if (operand->insert)
1310 insn = (*operand->insert) (insn, (long) val, &errmsg);
1311 if (errmsg != (const char *) NULL)
1312 as_bad_where (file, line, errmsg);
1315 insn |= (((long) val & ((1 << operand->bits) - 1))
1323 /* Parse @got, etc. and return the desired relocation. */
1324 static bfd_reloc_code_real_type
1325 ppc_elf_suffix (str_p, exp_p)
1332 bfd_reloc_code_real_type reloc;
1340 struct map_bfd *ptr;
1342 #define MAP(str,reloc) { str, sizeof (str)-1, reloc }
1344 static struct map_bfd mapping[] = {
1345 MAP ("l", BFD_RELOC_LO16),
1346 MAP ("h", BFD_RELOC_HI16),
1347 MAP ("ha", BFD_RELOC_HI16_S),
1348 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1349 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1350 MAP ("got", BFD_RELOC_16_GOTOFF),
1351 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1352 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1353 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1354 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1355 MAP ("plt", BFD_RELOC_24_PLT_PCREL),
1356 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1357 MAP ("copy", BFD_RELOC_PPC_COPY),
1358 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1359 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1360 MAP ("local", BFD_RELOC_PPC_LOCAL24PC),
1361 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1362 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1363 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1364 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1365 MAP ("sdarel", BFD_RELOC_GPREL16),
1366 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1367 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1368 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1369 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1370 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1371 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1372 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1373 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1374 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1375 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1376 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1377 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1378 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1379 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1380 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1381 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1382 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1383 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1384 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1385 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1386 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1387 #if BFD_DEFAULT_TARGET_SIZE == 64
1388 MAP ("higher", BFD_RELOC_PPC64_HIGHER),
1389 MAP ("highera", BFD_RELOC_PPC64_HIGHER_S),
1390 MAP ("highest", BFD_RELOC_PPC64_HIGHEST),
1391 MAP ("highesta", BFD_RELOC_PPC64_HIGHEST_S),
1392 MAP ("tocbase", BFD_RELOC_PPC64_TOC),
1393 MAP ("toc", BFD_RELOC_PPC_TOC16),
1394 MAP ("toc@l", BFD_RELOC_PPC64_TOC16_LO),
1395 MAP ("toc@h", BFD_RELOC_PPC64_TOC16_HI),
1396 MAP ("toc@ha", BFD_RELOC_PPC64_TOC16_HA),
1398 { (char *) 0, 0, BFD_RELOC_UNUSED }
1402 return BFD_RELOC_UNUSED;
1404 for (ch = *str, str2 = ident;
1405 (str2 < ident + sizeof (ident) - 1
1406 && (ISALNUM (ch) || ch == '@'));
1409 *str2++ = TOLOWER (ch);
1416 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1417 if (ch == ptr->string[0]
1418 && len == ptr->length
1419 && memcmp (ident, ptr->string, ptr->length) == 0)
1421 if (exp_p->X_add_number != 0
1422 && (ptr->reloc == BFD_RELOC_16_GOTOFF
1423 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
1424 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
1425 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
1426 as_warn (_("identifier+constant@got means identifier@got+constant"));
1428 /* Now check for identifier@suffix+constant. */
1429 if (*str == '-' || *str == '+')
1431 char *orig_line = input_line_pointer;
1432 expressionS new_exp;
1434 input_line_pointer = str;
1435 expression (&new_exp);
1436 if (new_exp.X_op == O_constant)
1438 exp_p->X_add_number += new_exp.X_add_number;
1439 str = input_line_pointer;
1442 if (&input_line_pointer != str_p)
1443 input_line_pointer = orig_line;
1447 if (BFD_DEFAULT_TARGET_SIZE == 64
1448 && ptr->reloc == BFD_RELOC_PPC64_TOC
1449 && exp_p->X_op == O_symbol)
1451 /* This reloc type ignores the symbol. Change the symbol
1452 so that the dummy .TOC. symbol can be omitted from the
1454 exp_p->X_add_symbol = &abs_symbol;
1460 return BFD_RELOC_UNUSED;
1463 /* Like normal .long/.short/.word, except support @got, etc.
1464 Clobbers input_line_pointer, checks end-of-line. */
1466 ppc_elf_cons (nbytes)
1467 register int nbytes; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1470 bfd_reloc_code_real_type reloc;
1472 if (is_it_end_of_statement ())
1474 demand_empty_rest_of_line ();
1481 if (exp.X_op == O_symbol
1482 && *input_line_pointer == '@'
1483 && (reloc = ppc_elf_suffix (&input_line_pointer,
1484 &exp)) != BFD_RELOC_UNUSED)
1486 reloc_howto_type *reloc_howto;
1489 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1490 size = bfd_get_reloc_size (reloc_howto);
1494 as_bad (_("%s relocations do not fit in %d bytes\n"),
1495 reloc_howto->name, nbytes);
1502 p = frag_more (nbytes);
1504 if (target_big_endian)
1505 offset = nbytes - size;
1506 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1511 emit_expr (&exp, (unsigned int) nbytes);
1513 while (*input_line_pointer++ == ',');
1515 /* Put terminator back into stream. */
1516 input_line_pointer--;
1517 demand_empty_rest_of_line ();
1520 /* Solaris pseduo op to change to the .rodata section. */
1525 char *save_line = input_line_pointer;
1526 static char section[] = ".rodata\n";
1528 /* Just pretend this is .section .rodata */
1529 input_line_pointer = section;
1530 obj_elf_section (xxx);
1532 input_line_pointer = save_line;
1535 /* Pseudo op to make file scope bss items. */
1538 int xxx ATTRIBUTE_UNUSED;
1540 register char *name;
1544 register symbolS *symbolP;
1551 name = input_line_pointer;
1552 c = get_symbol_end ();
1554 /* just after name is now '\0'. */
1555 p = input_line_pointer;
1558 if (*input_line_pointer != ',')
1560 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1561 ignore_rest_of_line ();
1565 input_line_pointer++; /* skip ',' */
1566 if ((size = get_absolute_expression ()) < 0)
1568 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1569 ignore_rest_of_line ();
1573 /* The third argument to .lcomm is the alignment. */
1574 if (*input_line_pointer != ',')
1578 ++input_line_pointer;
1579 align = get_absolute_expression ();
1582 as_warn (_("ignoring bad alignment"));
1588 symbolP = symbol_find_or_make (name);
1591 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1593 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1594 S_GET_NAME (symbolP));
1595 ignore_rest_of_line ();
1599 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1601 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1602 S_GET_NAME (symbolP),
1603 (long) S_GET_VALUE (symbolP),
1606 ignore_rest_of_line ();
1612 old_subsec = now_subseg;
1615 /* Convert to a power of 2 alignment. */
1616 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1619 as_bad (_("Common alignment not a power of 2"));
1620 ignore_rest_of_line ();
1627 record_alignment (bss_section, align2);
1628 subseg_set (bss_section, 0);
1630 frag_align (align2, 0, 0);
1631 if (S_GET_SEGMENT (symbolP) == bss_section)
1632 symbol_get_frag (symbolP)->fr_symbol = 0;
1633 symbol_set_frag (symbolP, frag_now);
1634 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1637 S_SET_SIZE (symbolP, size);
1638 S_SET_SEGMENT (symbolP, bss_section);
1639 subseg_set (old_sec, old_subsec);
1640 demand_empty_rest_of_line ();
1643 /* Validate any relocations emitted for -mrelocatable, possibly adding
1644 fixups for word relocations in writable segments, so we can adjust
1647 ppc_elf_validate_fix (fixp, seg)
1651 if (fixp->fx_done || fixp->fx_pcrel)
1660 case SHLIB_MRELOCATABLE:
1661 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1662 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1663 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1664 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1665 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1666 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1667 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1668 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1669 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1670 && (seg->flags & SEC_LOAD) != 0
1671 && strcmp (segment_name (seg), ".got2") != 0
1672 && strcmp (segment_name (seg), ".dtors") != 0
1673 && strcmp (segment_name (seg), ".ctors") != 0
1674 && strcmp (segment_name (seg), ".fixup") != 0
1675 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1676 && strcmp (segment_name (seg), ".eh_frame") != 0
1677 && strcmp (segment_name (seg), ".ex_shared") != 0)
1679 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1680 || fixp->fx_r_type != BFD_RELOC_CTOR)
1682 as_bad_where (fixp->fx_file, fixp->fx_line,
1683 _("Relocation cannot be done when using -mrelocatable"));
1690 #if BFD_DEFAULT_TARGET_SIZE == 64
1691 /* Don't emit .TOC. symbol. */
1693 ppc_elf_frob_symbol (sym)
1698 name = S_GET_NAME (sym);
1699 if (name != NULL && strcmp (name, ".TOC.") == 0)
1701 S_CLEAR_EXTERNAL (sym);
1708 #endif /* OBJ_ELF */
1713 * Summary of parse_toc_entry.
1715 * in: Input_line_pointer points to the '[' in one of:
1717 * [toc] [tocv] [toc32] [toc64]
1719 * Anything else is an error of one kind or another.
1722 * return value: success or failure
1723 * toc_kind: kind of toc reference
1724 * input_line_pointer:
1725 * success: first char after the ']'
1726 * failure: unchanged
1730 * [toc] - rv == success, toc_kind = default_toc
1731 * [tocv] - rv == success, toc_kind = data_in_toc
1732 * [toc32] - rv == success, toc_kind = must_be_32
1733 * [toc64] - rv == success, toc_kind = must_be_64
1737 enum toc_size_qualifier
1739 default_toc, /* The toc cell constructed should be the system default size */
1740 data_in_toc, /* This is a direct reference to a toc cell */
1741 must_be_32, /* The toc cell constructed must be 32 bits wide */
1742 must_be_64 /* The toc cell constructed must be 64 bits wide */
1746 parse_toc_entry (toc_kind)
1747 enum toc_size_qualifier *toc_kind;
1752 enum toc_size_qualifier t;
1754 /* Save the input_line_pointer. */
1755 start = input_line_pointer;
1757 /* Skip over the '[' , and whitespace. */
1758 ++input_line_pointer;
1761 /* Find the spelling of the operand. */
1762 toc_spec = input_line_pointer;
1763 c = get_symbol_end ();
1765 if (strcmp (toc_spec, "toc") == 0)
1769 else if (strcmp (toc_spec, "tocv") == 0)
1773 else if (strcmp (toc_spec, "toc32") == 0)
1777 else if (strcmp (toc_spec, "toc64") == 0)
1783 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1784 *input_line_pointer = c;
1785 input_line_pointer = start;
1789 /* Now find the ']'. */
1790 *input_line_pointer = c;
1792 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1793 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1797 as_bad (_("syntax error: expected `]', found `%c'"), c);
1798 input_line_pointer = start;
1808 /* We need to keep a list of fixups. We can't simply generate them as
1809 we go, because that would require us to first create the frag, and
1810 that would screw up references to ``.''. */
1816 bfd_reloc_code_real_type reloc;
1819 #define MAX_INSN_FIXUPS (5)
1821 /* This routine is called for each instruction to be assembled. */
1828 const struct powerpc_opcode *opcode;
1830 const unsigned char *opindex_ptr;
1834 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1839 bfd_reloc_code_real_type reloc;
1842 /* Get the opcode. */
1843 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
1848 /* Look up the opcode in the hash table. */
1849 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1850 if (opcode == (const struct powerpc_opcode *) NULL)
1852 const struct powerpc_macro *macro;
1854 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1855 if (macro == (const struct powerpc_macro *) NULL)
1856 as_bad (_("Unrecognized opcode: `%s'"), str);
1858 ppc_macro (s, macro);
1863 insn = opcode->opcode;
1866 while (ISSPACE (*str))
1869 /* PowerPC operands are just expressions. The only real issue is
1870 that a few operand types are optional. All cases which might use
1871 an optional operand separate the operands only with commas (in
1872 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1873 cases never have optional operands). There is never more than
1874 one optional operand for an instruction. So, before we start
1875 seriously parsing the operands, we check to see if we have an
1876 optional operand, and, if we do, we count the number of commas to
1877 see whether the operand should be omitted. */
1879 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1881 const struct powerpc_operand *operand;
1883 operand = &powerpc_operands[*opindex_ptr];
1884 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1886 unsigned int opcount;
1888 /* There is an optional operand. Count the number of
1889 commas in the input line. */
1896 while ((s = strchr (s, ',')) != (char *) NULL)
1903 /* If there are fewer operands in the line then are called
1904 for by the instruction, we want to skip the optional
1906 if (opcount < strlen (opcode->operands))
1913 /* Gather the operands. */
1917 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1919 const struct powerpc_operand *operand;
1925 if (next_opindex == 0)
1926 operand = &powerpc_operands[*opindex_ptr];
1929 operand = &powerpc_operands[next_opindex];
1935 /* If this is a fake operand, then we do not expect anything
1937 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1939 insn = (*operand->insert) (insn, 0L, &errmsg);
1940 if (errmsg != (const char *) NULL)
1945 /* If this is an optional operand, and we are skipping it, just
1947 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1950 if (operand->insert)
1952 insn = (*operand->insert) (insn, 0L, &errmsg);
1953 if (errmsg != (const char *) NULL)
1956 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1957 next_opindex = *opindex_ptr + 1;
1961 /* Gather the operand. */
1962 hold = input_line_pointer;
1963 input_line_pointer = str;
1966 if (*input_line_pointer == '[')
1968 /* We are expecting something like the second argument here:
1970 * lwz r4,[toc].GS.0.static_int(rtoc)
1971 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1972 * The argument following the `]' must be a symbol name, and the
1973 * register must be the toc register: 'rtoc' or '2'
1975 * The effect is to 0 as the displacement field
1976 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1977 * the appropriate variation) reloc against it based on the symbol.
1978 * The linker will build the toc, and insert the resolved toc offset.
1981 * o The size of the toc entry is currently assumed to be
1982 * 32 bits. This should not be assumed to be a hard coded
1984 * o In an effort to cope with a change from 32 to 64 bits,
1985 * there are also toc entries that are specified to be
1986 * either 32 or 64 bits:
1987 * lwz r4,[toc32].GS.0.static_int(rtoc)
1988 * lwz r4,[toc64].GS.0.static_int(rtoc)
1989 * These demand toc entries of the specified size, and the
1990 * instruction probably requires it.
1994 enum toc_size_qualifier toc_kind;
1995 bfd_reloc_code_real_type toc_reloc;
1997 /* Go parse off the [tocXX] part. */
1998 valid_toc = parse_toc_entry (&toc_kind);
2002 /* Note: message has already been issued.
2003 FIXME: what sort of recovery should we do?
2004 demand_rest_of_line (); return; ? */
2007 /* Now get the symbol following the ']'. */
2013 /* In this case, we may not have seen the symbol yet,
2014 since it is allowed to appear on a .extern or .globl
2015 or just be a label in the .data section. */
2016 toc_reloc = BFD_RELOC_PPC_TOC16;
2019 /* 1. The symbol must be defined and either in the toc
2020 section, or a global.
2021 2. The reloc generated must have the TOCDEFN flag set
2022 in upper bit mess of the reloc type.
2023 FIXME: It's a little confusing what the tocv
2024 qualifier can be used for. At the very least, I've
2025 seen three uses, only one of which I'm sure I can
2027 if (ex.X_op == O_symbol)
2029 assert (ex.X_add_symbol != NULL);
2030 if (symbol_get_bfdsym (ex.X_add_symbol)->section
2033 as_bad (_("[tocv] symbol is not a toc symbol"));
2037 toc_reloc = BFD_RELOC_PPC_TOC16;
2040 /* FIXME: these next two specifically specify 32/64 bit
2041 toc entries. We don't support them today. Is this
2042 the right way to say that? */
2043 toc_reloc = BFD_RELOC_UNUSED;
2044 as_bad (_("Unimplemented toc32 expression modifier"));
2047 /* FIXME: see above. */
2048 toc_reloc = BFD_RELOC_UNUSED;
2049 as_bad (_("Unimplemented toc64 expression modifier"));
2053 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2059 /* We need to generate a fixup for this expression. */
2060 if (fc >= MAX_INSN_FIXUPS)
2061 as_fatal (_("too many fixups"));
2063 fixups[fc].reloc = toc_reloc;
2064 fixups[fc].exp = ex;
2065 fixups[fc].opindex = *opindex_ptr;
2068 /* Ok. We've set up the fixup for the instruction. Now make it
2069 look like the constant 0 was found here. */
2071 ex.X_op = O_constant;
2072 ex.X_add_number = 0;
2073 ex.X_add_symbol = NULL;
2074 ex.X_op_symbol = NULL;
2080 if (! register_name (&ex))
2082 if ((operand->flags & PPC_OPERAND_CR) != 0)
2089 str = input_line_pointer;
2090 input_line_pointer = hold;
2092 if (ex.X_op == O_illegal)
2093 as_bad (_("illegal operand"));
2094 else if (ex.X_op == O_absent)
2095 as_bad (_("missing operand"));
2096 else if (ex.X_op == O_register)
2098 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2101 else if (ex.X_op == O_constant)
2104 /* Allow @HA, @L, @H on constants. */
2105 char *orig_str = str;
2107 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2114 case BFD_RELOC_LO16:
2115 /* X_unsigned is the default, so if the user has done
2116 something which cleared it, we always produce a
2118 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2119 ex.X_add_number &= 0xffff;
2121 ex.X_add_number = SEX16 (ex.X_add_number);
2124 case BFD_RELOC_HI16:
2125 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2126 ex.X_add_number = PPC_HI (ex.X_add_number);
2128 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2131 case BFD_RELOC_HI16_S:
2132 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2133 ex.X_add_number = PPC_HA (ex.X_add_number);
2135 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2138 #if BFD_DEFAULT_TARGET_SIZE == 64
2139 case BFD_RELOC_PPC64_HIGHER:
2140 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2141 ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2143 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2146 case BFD_RELOC_PPC64_HIGHER_S:
2147 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2148 ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2150 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2153 case BFD_RELOC_PPC64_HIGHEST:
2154 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2155 ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2157 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2160 case BFD_RELOC_PPC64_HIGHEST_S:
2161 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2162 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2164 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2166 #endif /* BFD_DEFAULT_TARGET_SIZE == 64 */
2168 #endif /* OBJ_ELF */
2169 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2173 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2175 /* For the absolute forms of branches, convert the PC
2176 relative form back into the absolute. */
2177 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2181 case BFD_RELOC_PPC_B26:
2182 reloc = BFD_RELOC_PPC_BA26;
2184 case BFD_RELOC_PPC_B16:
2185 reloc = BFD_RELOC_PPC_BA16;
2187 case BFD_RELOC_PPC_B16_BRTAKEN:
2188 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2190 case BFD_RELOC_PPC_B16_BRNTAKEN:
2191 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2198 if (BFD_DEFAULT_TARGET_SIZE == 64
2199 && ppc_size == PPC_OPCODE_64
2200 && (operand->flags & PPC_OPERAND_DS) != 0)
2205 reloc = BFD_RELOC_PPC64_ADDR16_DS;
2207 case BFD_RELOC_LO16:
2208 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
2210 case BFD_RELOC_16_GOTOFF:
2211 reloc = BFD_RELOC_PPC64_GOT16_DS;
2213 case BFD_RELOC_LO16_GOTOFF:
2214 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
2216 case BFD_RELOC_LO16_PLTOFF:
2217 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
2219 case BFD_RELOC_32_BASEREL:
2220 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
2222 case BFD_RELOC_LO16_BASEREL:
2223 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
2225 case BFD_RELOC_PPC_TOC16:
2226 reloc = BFD_RELOC_PPC64_TOC16_DS;
2228 case BFD_RELOC_PPC64_TOC16_LO:
2229 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
2231 case BFD_RELOC_PPC64_PLTGOT16:
2232 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
2234 case BFD_RELOC_PPC64_PLTGOT16_LO:
2235 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
2238 as_bad (_("unsupported relocation for DS offset field"));
2243 /* We need to generate a fixup for this expression. */
2244 if (fc >= MAX_INSN_FIXUPS)
2245 as_fatal (_("too many fixups"));
2246 fixups[fc].exp = ex;
2247 fixups[fc].opindex = 0;
2248 fixups[fc].reloc = reloc;
2251 #endif /* OBJ_ELF */
2255 /* We need to generate a fixup for this expression. */
2256 if (fc >= MAX_INSN_FIXUPS)
2257 as_fatal (_("too many fixups"));
2258 fixups[fc].exp = ex;
2259 fixups[fc].opindex = *opindex_ptr;
2260 fixups[fc].reloc = BFD_RELOC_UNUSED;
2269 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2277 /* The call to expression should have advanced str past any
2280 && (endc != ',' || *str != '\0'))
2282 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
2290 while (ISSPACE (*str))
2294 as_bad (_("junk at end of line: `%s'"), str);
2296 /* Write out the instruction. */
2298 md_number_to_chars (f, insn, 4);
2301 dwarf2_emit_insn (4);
2304 /* Create any fixups. At this point we do not use a
2305 bfd_reloc_code_real_type, but instead just use the
2306 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2307 handle fixups for any operand type, although that is admittedly
2308 not a very exciting feature. We pick a BFD reloc type in
2310 for (i = 0; i < fc; i++)
2312 const struct powerpc_operand *operand;
2314 operand = &powerpc_operands[fixups[i].opindex];
2315 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2317 reloc_howto_type *reloc_howto;
2322 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2326 size = bfd_get_reloc_size (reloc_howto);
2327 offset = target_big_endian ? (4 - size) : 0;
2329 if (size < 1 || size > 4)
2332 fixP = fix_new_exp (frag_now,
2333 f - frag_now->fr_literal + offset,
2336 reloc_howto->pc_relative,
2339 /* Turn off complaints that the addend is too large for things like
2341 switch (fixups[i].reloc)
2343 case BFD_RELOC_16_GOTOFF:
2344 case BFD_RELOC_PPC_TOC16:
2345 case BFD_RELOC_LO16:
2346 case BFD_RELOC_HI16:
2347 case BFD_RELOC_HI16_S:
2349 #if BFD_DEFAULT_TARGET_SIZE == 64
2350 case BFD_RELOC_PPC64_HIGHER:
2351 case BFD_RELOC_PPC64_HIGHER_S:
2352 case BFD_RELOC_PPC64_HIGHEST:
2353 case BFD_RELOC_PPC64_HIGHEST_S:
2356 fixP->fx_no_overflow = 1;
2363 fix_new_exp (frag_now,
2364 f - frag_now->fr_literal,
2367 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2368 ((bfd_reloc_code_real_type)
2369 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2373 /* Handle a macro. Gather all the operands, transform them as
2374 described by the macro, and call md_assemble recursively. All the
2375 operands are separated by commas; we don't accept parentheses
2376 around operands here. */
2379 ppc_macro (str, macro)
2381 const struct powerpc_macro *macro;
2392 /* Gather the users operands into the operands array. */
2397 if (count >= sizeof operands / sizeof operands[0])
2399 operands[count++] = s;
2400 s = strchr (s, ',');
2401 if (s == (char *) NULL)
2406 if (count != macro->operands)
2408 as_bad (_("wrong number of operands"));
2412 /* Work out how large the string must be (the size is unbounded
2413 because it includes user input). */
2415 format = macro->format;
2416 while (*format != '\0')
2425 arg = strtol (format + 1, &send, 10);
2426 know (send != format && arg >= 0 && arg < count);
2427 len += strlen (operands[arg]);
2432 /* Put the string together. */
2433 complete = s = (char *) alloca (len + 1);
2434 format = macro->format;
2435 while (*format != '\0')
2441 arg = strtol (format + 1, &send, 10);
2442 strcpy (s, operands[arg]);
2449 /* Assemble the constructed instruction. */
2450 md_assemble (complete);
2454 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2457 ppc_section_letter (letter, ptr_msg)
2464 *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S in string");
2469 ppc_section_word (str, len)
2473 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2480 ppc_section_type (str, len)
2484 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2491 ppc_section_flags (flags, attr, type)
2496 if (type == SHT_ORDERED)
2497 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2499 if (attr & SHF_EXCLUDE)
2500 flags |= SEC_EXCLUDE;
2504 #endif /* OBJ_ELF */
2507 /* Pseudo-op handling. */
2509 /* The .byte pseudo-op. This is similar to the normal .byte
2510 pseudo-op, but it can also take a single ASCII string. */
2514 int ignore ATTRIBUTE_UNUSED;
2516 if (*input_line_pointer != '\"')
2522 /* Gather characters. A real double quote is doubled. Unusual
2523 characters are not permitted. */
2524 ++input_line_pointer;
2529 c = *input_line_pointer++;
2533 if (*input_line_pointer != '\"')
2535 ++input_line_pointer;
2538 FRAG_APPEND_1_CHAR (c);
2541 demand_empty_rest_of_line ();
2546 /* XCOFF specific pseudo-op handling. */
2548 /* This is set if we are creating a .stabx symbol, since we don't want
2549 to handle symbol suffixes for such symbols. */
2550 static boolean ppc_stab_symbol;
2552 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2553 symbols in the .bss segment as though they were local common
2554 symbols, and uses a different smclas. The native Aix 4.3.3 assember
2555 aligns .comm and .lcomm to 4 bytes. */
2561 asection *current_seg = now_seg;
2562 subsegT current_subseg = now_subseg;
2568 symbolS *lcomm_sym = NULL;
2572 name = input_line_pointer;
2573 endc = get_symbol_end ();
2574 end_name = input_line_pointer;
2577 if (*input_line_pointer != ',')
2579 as_bad (_("missing size"));
2580 ignore_rest_of_line ();
2583 ++input_line_pointer;
2585 size = get_absolute_expression ();
2588 as_bad (_("negative size"));
2589 ignore_rest_of_line ();
2595 /* The third argument to .comm is the alignment. */
2596 if (*input_line_pointer != ',')
2600 ++input_line_pointer;
2601 align = get_absolute_expression ();
2604 as_warn (_("ignoring bad alignment"));
2619 /* The third argument to .lcomm appears to be the real local
2620 common symbol to create. References to the symbol named in
2621 the first argument are turned into references to the third
2623 if (*input_line_pointer != ',')
2625 as_bad (_("missing real symbol name"));
2626 ignore_rest_of_line ();
2629 ++input_line_pointer;
2631 lcomm_name = input_line_pointer;
2632 lcomm_endc = get_symbol_end ();
2634 lcomm_sym = symbol_find_or_make (lcomm_name);
2636 *input_line_pointer = lcomm_endc;
2640 sym = symbol_find_or_make (name);
2643 if (S_IS_DEFINED (sym)
2644 || S_GET_VALUE (sym) != 0)
2646 as_bad (_("attempt to redefine symbol"));
2647 ignore_rest_of_line ();
2651 record_alignment (bss_section, align);
2654 || ! S_IS_DEFINED (lcomm_sym))
2663 S_SET_EXTERNAL (sym);
2667 symbol_get_tc (lcomm_sym)->output = 1;
2668 def_sym = lcomm_sym;
2672 subseg_set (bss_section, 1);
2673 frag_align (align, 0, 0);
2675 symbol_set_frag (def_sym, frag_now);
2676 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2677 def_size, (char *) NULL);
2679 S_SET_SEGMENT (def_sym, bss_section);
2680 symbol_get_tc (def_sym)->align = align;
2684 /* Align the size of lcomm_sym. */
2685 symbol_get_frag (lcomm_sym)->fr_offset =
2686 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
2687 &~ ((1 << align) - 1));
2688 if (align > symbol_get_tc (lcomm_sym)->align)
2689 symbol_get_tc (lcomm_sym)->align = align;
2694 /* Make sym an offset from lcomm_sym. */
2695 S_SET_SEGMENT (sym, bss_section);
2696 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
2697 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
2698 symbol_get_frag (lcomm_sym)->fr_offset += size;
2701 subseg_set (current_seg, current_subseg);
2703 demand_empty_rest_of_line ();
2706 /* The .csect pseudo-op. This switches us into a different
2707 subsegment. The first argument is a symbol whose value is the
2708 start of the .csect. In COFF, csect symbols get special aux
2709 entries defined by the x_csect field of union internal_auxent. The
2710 optional second argument is the alignment (the default is 2). */
2714 int ignore ATTRIBUTE_UNUSED;
2720 name = input_line_pointer;
2721 endc = get_symbol_end ();
2723 sym = symbol_find_or_make (name);
2725 *input_line_pointer = endc;
2727 if (S_GET_NAME (sym)[0] == '\0')
2729 /* An unnamed csect is assumed to be [PR]. */
2730 symbol_get_tc (sym)->class = XMC_PR;
2733 ppc_change_csect (sym);
2735 if (*input_line_pointer == ',')
2737 ++input_line_pointer;
2738 symbol_get_tc (sym)->align = get_absolute_expression ();
2741 demand_empty_rest_of_line ();
2744 /* Change to a different csect. */
2747 ppc_change_csect (sym)
2750 if (S_IS_DEFINED (sym))
2751 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
2759 /* This is a new csect. We need to look at the symbol class to
2760 figure out whether it should go in the text section or the
2763 switch (symbol_get_tc (sym)->class)
2773 S_SET_SEGMENT (sym, text_section);
2774 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
2775 ++ppc_text_subsegment;
2776 list_ptr = &ppc_text_csects;
2785 if (ppc_toc_csect != NULL
2786 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
2787 == ppc_data_subsegment))
2789 S_SET_SEGMENT (sym, data_section);
2790 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
2791 ++ppc_data_subsegment;
2792 list_ptr = &ppc_data_csects;
2798 /* We set the obstack chunk size to a small value before
2799 changing subsegments, so that we don't use a lot of memory
2800 space for what may be a small section. */
2801 hold_chunksize = chunksize;
2804 subseg_new (segment_name (S_GET_SEGMENT (sym)),
2805 symbol_get_tc (sym)->subseg);
2807 chunksize = hold_chunksize;
2810 ppc_after_toc_frag = frag_now;
2812 symbol_set_frag (sym, frag_now);
2813 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2815 symbol_get_tc (sym)->align = (ppc_xcoff64) ? 3 : 2;
2816 symbol_get_tc (sym)->output = 1;
2817 symbol_get_tc (sym)->within = sym;
2819 for (list = *list_ptr;
2820 symbol_get_tc (list)->next != (symbolS *) NULL;
2821 list = symbol_get_tc (list)->next)
2823 symbol_get_tc (list)->next = sym;
2825 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2826 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
2830 ppc_current_csect = sym;
2833 /* This function handles the .text and .data pseudo-ops. These
2834 pseudo-ops aren't really used by XCOFF; we implement them for the
2835 convenience of people who aren't used to XCOFF. */
2846 else if (type == 'd')
2851 sym = symbol_find_or_make (name);
2853 ppc_change_csect (sym);
2855 demand_empty_rest_of_line ();
2858 /* This function handles the .section pseudo-op. This is mostly to
2859 give an error, since XCOFF only supports .text, .data and .bss, but
2860 we do permit the user to name the text or data section. */
2863 ppc_named_section (ignore)
2864 int ignore ATTRIBUTE_UNUSED;
2867 const char *real_name;
2871 user_name = input_line_pointer;
2872 c = get_symbol_end ();
2874 if (strcmp (user_name, ".text") == 0)
2875 real_name = ".text[PR]";
2876 else if (strcmp (user_name, ".data") == 0)
2877 real_name = ".data[RW]";
2880 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2881 *input_line_pointer = c;
2882 ignore_rest_of_line ();
2886 *input_line_pointer = c;
2888 sym = symbol_find_or_make (real_name);
2890 ppc_change_csect (sym);
2892 demand_empty_rest_of_line ();
2895 /* The .extern pseudo-op. We create an undefined symbol. */
2899 int ignore ATTRIBUTE_UNUSED;
2904 name = input_line_pointer;
2905 endc = get_symbol_end ();
2907 (void) symbol_find_or_make (name);
2909 *input_line_pointer = endc;
2911 demand_empty_rest_of_line ();
2914 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2918 int ignore ATTRIBUTE_UNUSED;
2924 name = input_line_pointer;
2925 endc = get_symbol_end ();
2927 sym = symbol_find_or_make (name);
2929 *input_line_pointer = endc;
2931 symbol_get_tc (sym)->output = 1;
2933 demand_empty_rest_of_line ();
2936 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2937 although I don't know why it bothers. */
2941 int ignore ATTRIBUTE_UNUSED;
2948 name = input_line_pointer;
2949 endc = get_symbol_end ();
2951 sym = symbol_find_or_make (name);
2953 *input_line_pointer = endc;
2955 if (*input_line_pointer != ',')
2957 as_bad (_("missing rename string"));
2958 ignore_rest_of_line ();
2961 ++input_line_pointer;
2963 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
2965 demand_empty_rest_of_line ();
2968 /* The .stabx pseudo-op. This is similar to a normal .stabs
2969 pseudo-op, but slightly different. A sample is
2970 .stabx "main:F-1",.main,142,0
2971 The first argument is the symbol name to create. The second is the
2972 value, and the third is the storage class. The fourth seems to be
2973 always zero, and I am assuming it is the type. */
2977 int ignore ATTRIBUTE_UNUSED;
2984 name = demand_copy_C_string (&len);
2986 if (*input_line_pointer != ',')
2988 as_bad (_("missing value"));
2991 ++input_line_pointer;
2993 ppc_stab_symbol = true;
2994 sym = symbol_make (name);
2995 ppc_stab_symbol = false;
2997 symbol_get_tc (sym)->real_name = name;
2999 (void) expression (&exp);
3006 as_bad (_("illegal .stabx expression; zero assumed"));
3007 exp.X_add_number = 0;
3010 S_SET_VALUE (sym, (valueT) exp.X_add_number);
3011 symbol_set_frag (sym, &zero_address_frag);
3015 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
3016 symbol_set_value_expression (sym, &exp);
3020 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
3021 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
3026 /* The value is some complex expression. This will probably
3027 fail at some later point, but this is probably the right
3028 thing to do here. */
3029 symbol_set_value_expression (sym, &exp);
3033 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3034 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3036 if (*input_line_pointer != ',')
3038 as_bad (_("missing class"));
3041 ++input_line_pointer;
3043 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
3045 if (*input_line_pointer != ',')
3047 as_bad (_("missing type"));
3050 ++input_line_pointer;
3052 S_SET_DATA_TYPE (sym, get_absolute_expression ());
3054 symbol_get_tc (sym)->output = 1;
3056 if (S_GET_STORAGE_CLASS (sym) == C_STSYM) {
3058 symbol_get_tc (sym)->within = ppc_current_block;
3063 .stabx "z",arrays_,133,0
3066 .comm arrays_,13768,3
3068 resolve_symbol_value will copy the exp's "within" into sym's when the
3069 offset is 0. Since this seems to be corner case problem,
3070 only do the correction for storage class C_STSYM. A better solution
3071 would be to have the tc field updated in ppc_symbol_new_hook. */
3073 if (exp.X_op == O_symbol)
3075 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
3079 if (exp.X_op != O_symbol
3080 || ! S_IS_EXTERNAL (exp.X_add_symbol)
3081 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
3082 ppc_frob_label (sym);
3085 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3086 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
3087 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
3088 symbol_get_tc (ppc_current_csect)->within = sym;
3091 demand_empty_rest_of_line ();
3094 /* The .function pseudo-op. This takes several arguments. The first
3095 argument seems to be the external name of the symbol. The second
3096 argment seems to be the label for the start of the function. gcc
3097 uses the same name for both. I have no idea what the third and
3098 fourth arguments are meant to be. The optional fifth argument is
3099 an expression for the size of the function. In COFF this symbol
3100 gets an aux entry like that used for a csect. */
3103 ppc_function (ignore)
3104 int ignore ATTRIBUTE_UNUSED;
3112 name = input_line_pointer;
3113 endc = get_symbol_end ();
3115 /* Ignore any [PR] suffix. */
3116 name = ppc_canonicalize_symbol_name (name);
3117 s = strchr (name, '[');
3118 if (s != (char *) NULL
3119 && strcmp (s + 1, "PR]") == 0)
3122 ext_sym = symbol_find_or_make (name);
3124 *input_line_pointer = endc;
3126 if (*input_line_pointer != ',')
3128 as_bad (_("missing symbol name"));
3129 ignore_rest_of_line ();
3132 ++input_line_pointer;
3134 name = input_line_pointer;
3135 endc = get_symbol_end ();
3137 lab_sym = symbol_find_or_make (name);
3139 *input_line_pointer = endc;
3141 if (ext_sym != lab_sym)
3145 exp.X_op = O_symbol;
3146 exp.X_add_symbol = lab_sym;
3147 exp.X_op_symbol = NULL;
3148 exp.X_add_number = 0;
3150 symbol_set_value_expression (ext_sym, &exp);
3153 if (symbol_get_tc (ext_sym)->class == -1)
3154 symbol_get_tc (ext_sym)->class = XMC_PR;
3155 symbol_get_tc (ext_sym)->output = 1;
3157 if (*input_line_pointer == ',')
3161 /* Ignore the third argument. */
3162 ++input_line_pointer;
3163 expression (&ignore);
3164 if (*input_line_pointer == ',')
3166 /* Ignore the fourth argument. */
3167 ++input_line_pointer;
3168 expression (&ignore);
3169 if (*input_line_pointer == ',')
3171 /* The fifth argument is the function size. */
3172 ++input_line_pointer;
3173 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
3176 &zero_address_frag);
3177 pseudo_set (symbol_get_tc (ext_sym)->size);
3182 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3183 SF_SET_FUNCTION (ext_sym);
3184 SF_SET_PROCESS (ext_sym);
3185 coff_add_linesym (ext_sym);
3187 demand_empty_rest_of_line ();
3190 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3191 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3192 with the correct line number */
3194 static symbolS *saved_bi_sym = 0;
3198 int ignore ATTRIBUTE_UNUSED;
3202 sym = symbol_make (".bf");
3203 S_SET_SEGMENT (sym, text_section);
3204 symbol_set_frag (sym, frag_now);
3205 S_SET_VALUE (sym, frag_now_fix ());
3206 S_SET_STORAGE_CLASS (sym, C_FCN);
3208 coff_line_base = get_absolute_expression ();
3210 S_SET_NUMBER_AUXILIARY (sym, 1);
3211 SA_SET_SYM_LNNO (sym, coff_line_base);
3213 /* Line number for bi. */
3216 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
3221 symbol_get_tc (sym)->output = 1;
3223 ppc_frob_label (sym);
3225 demand_empty_rest_of_line ();
3228 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3229 ".ef", except that the line number is absolute, not relative to the
3230 most recent ".bf" symbol. */
3234 int ignore ATTRIBUTE_UNUSED;
3238 sym = symbol_make (".ef");
3239 S_SET_SEGMENT (sym, text_section);
3240 symbol_set_frag (sym, frag_now);
3241 S_SET_VALUE (sym, frag_now_fix ());
3242 S_SET_STORAGE_CLASS (sym, C_FCN);
3243 S_SET_NUMBER_AUXILIARY (sym, 1);
3244 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3245 symbol_get_tc (sym)->output = 1;
3247 ppc_frob_label (sym);
3249 demand_empty_rest_of_line ();
3252 /* The .bi and .ei pseudo-ops. These take a string argument and
3253 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3254 the symbol list. The value of .bi will be know when the next .bf
3261 static symbolS *last_biei;
3268 name = demand_copy_C_string (&len);
3270 /* The value of these symbols is actually file offset. Here we set
3271 the value to the index into the line number entries. In
3272 ppc_frob_symbols we set the fix_line field, which will cause BFD
3273 to do the right thing. */
3275 sym = symbol_make (name);
3276 /* obj-coff.c currently only handles line numbers correctly in the
3278 S_SET_SEGMENT (sym, text_section);
3279 S_SET_VALUE (sym, coff_n_line_nos);
3280 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3282 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
3283 symbol_get_tc (sym)->output = 1;
3291 for (look = last_biei ? last_biei : symbol_rootP;
3292 (look != (symbolS *) NULL
3293 && (S_GET_STORAGE_CLASS (look) == C_FILE
3294 || S_GET_STORAGE_CLASS (look) == C_BINCL
3295 || S_GET_STORAGE_CLASS (look) == C_EINCL));
3296 look = symbol_next (look))
3298 if (look != (symbolS *) NULL)
3300 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3301 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
3305 demand_empty_rest_of_line ();
3308 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3309 There is one argument, which is a csect symbol. The value of the
3310 .bs symbol is the index of this csect symbol. */
3314 int ignore ATTRIBUTE_UNUSED;
3321 if (ppc_current_block != NULL)
3322 as_bad (_("nested .bs blocks"));
3324 name = input_line_pointer;
3325 endc = get_symbol_end ();
3327 csect = symbol_find_or_make (name);
3329 *input_line_pointer = endc;
3331 sym = symbol_make (".bs");
3332 S_SET_SEGMENT (sym, now_seg);
3333 S_SET_STORAGE_CLASS (sym, C_BSTAT);
3334 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3335 symbol_get_tc (sym)->output = 1;
3337 symbol_get_tc (sym)->within = csect;
3339 ppc_frob_label (sym);
3341 ppc_current_block = sym;
3343 demand_empty_rest_of_line ();
3346 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3350 int ignore ATTRIBUTE_UNUSED;
3354 if (ppc_current_block == NULL)
3355 as_bad (_(".es without preceding .bs"));
3357 sym = symbol_make (".es");
3358 S_SET_SEGMENT (sym, now_seg);
3359 S_SET_STORAGE_CLASS (sym, C_ESTAT);
3360 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3361 symbol_get_tc (sym)->output = 1;
3363 ppc_frob_label (sym);
3365 ppc_current_block = NULL;
3367 demand_empty_rest_of_line ();
3370 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3375 int ignore ATTRIBUTE_UNUSED;
3379 sym = symbol_make (".bb");
3380 S_SET_SEGMENT (sym, text_section);
3381 symbol_set_frag (sym, frag_now);
3382 S_SET_VALUE (sym, frag_now_fix ());
3383 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3385 S_SET_NUMBER_AUXILIARY (sym, 1);
3386 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3388 symbol_get_tc (sym)->output = 1;
3390 SF_SET_PROCESS (sym);
3392 ppc_frob_label (sym);
3394 demand_empty_rest_of_line ();
3397 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3402 int ignore ATTRIBUTE_UNUSED;
3406 sym = symbol_make (".eb");
3407 S_SET_SEGMENT (sym, text_section);
3408 symbol_set_frag (sym, frag_now);
3409 S_SET_VALUE (sym, frag_now_fix ());
3410 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3411 S_SET_NUMBER_AUXILIARY (sym, 1);
3412 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3413 symbol_get_tc (sym)->output = 1;
3415 SF_SET_PROCESS (sym);
3417 ppc_frob_label (sym);
3419 demand_empty_rest_of_line ();
3422 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3427 int ignore ATTRIBUTE_UNUSED;
3433 name = demand_copy_C_string (&len);
3434 sym = symbol_make (name);
3435 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3436 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3437 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3438 S_SET_VALUE (sym, 0);
3439 symbol_get_tc (sym)->output = 1;
3441 ppc_frob_label (sym);
3443 demand_empty_rest_of_line ();
3446 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3450 int ignore ATTRIBUTE_UNUSED;
3454 sym = symbol_make (".ec");
3455 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3456 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3457 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3458 S_SET_VALUE (sym, 0);
3459 symbol_get_tc (sym)->output = 1;
3461 ppc_frob_label (sym);
3463 demand_empty_rest_of_line ();
3466 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3470 int ignore ATTRIBUTE_UNUSED;
3472 if (ppc_toc_csect != (symbolS *) NULL)
3473 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
3480 subseg = ppc_data_subsegment;
3481 ++ppc_data_subsegment;
3483 subseg_new (segment_name (data_section), subseg);
3484 ppc_toc_frag = frag_now;
3486 sym = symbol_find_or_make ("TOC[TC0]");
3487 symbol_set_frag (sym, frag_now);
3488 S_SET_SEGMENT (sym, data_section);
3489 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3490 symbol_get_tc (sym)->subseg = subseg;
3491 symbol_get_tc (sym)->output = 1;
3492 symbol_get_tc (sym)->within = sym;
3494 ppc_toc_csect = sym;
3496 for (list = ppc_data_csects;
3497 symbol_get_tc (list)->next != (symbolS *) NULL;
3498 list = symbol_get_tc (list)->next)
3500 symbol_get_tc (list)->next = sym;
3502 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3503 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3507 ppc_current_csect = ppc_toc_csect;
3509 demand_empty_rest_of_line ();
3512 /* The AIX assembler automatically aligns the operands of a .long or
3513 .short pseudo-op, and we want to be compatible. */
3516 ppc_xcoff_cons (log_size)
3519 frag_align (log_size, 0, 0);
3520 record_alignment (now_seg, log_size);
3521 cons (1 << log_size);
3526 int dummy ATTRIBUTE_UNUSED;
3531 (void) expression (&exp);
3533 if (exp.X_op != O_constant)
3535 as_bad (_("non-constant byte count"));
3539 byte_count = exp.X_add_number;
3541 if (*input_line_pointer != ',')
3543 as_bad (_("missing value"));
3547 ++input_line_pointer;
3551 #endif /* OBJ_XCOFF */
3552 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3554 /* The .tc pseudo-op. This is used when generating either XCOFF or
3555 ELF. This takes two or more arguments.
3557 When generating XCOFF output, the first argument is the name to
3558 give to this location in the toc; this will be a symbol with class
3559 TC. The rest of the arguments are N-byte values to actually put at
3560 this location in the TOC; often there is just one more argument, a
3561 relocateable symbol reference. The size of the value to store
3562 depends on target word size. A 32-bit target uses 4-byte values, a
3563 64-bit target uses 8-byte values.
3565 When not generating XCOFF output, the arguments are the same, but
3566 the first argument is simply ignored. */
3570 int ignore ATTRIBUTE_UNUSED;
3574 /* Define the TOC symbol name. */
3580 if (ppc_toc_csect == (symbolS *) NULL
3581 || ppc_toc_csect != ppc_current_csect)
3583 as_bad (_(".tc not in .toc section"));
3584 ignore_rest_of_line ();
3588 name = input_line_pointer;
3589 endc = get_symbol_end ();
3591 sym = symbol_find_or_make (name);
3593 *input_line_pointer = endc;
3595 if (S_IS_DEFINED (sym))
3599 label = symbol_get_tc (ppc_current_csect)->within;
3600 if (symbol_get_tc (label)->class != XMC_TC0)
3602 as_bad (_(".tc with no label"));
3603 ignore_rest_of_line ();
3607 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3608 symbol_set_frag (label, symbol_get_frag (sym));
3609 S_SET_VALUE (label, S_GET_VALUE (sym));
3611 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3612 ++input_line_pointer;
3617 S_SET_SEGMENT (sym, now_seg);
3618 symbol_set_frag (sym, frag_now);
3619 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3620 symbol_get_tc (sym)->class = XMC_TC;
3621 symbol_get_tc (sym)->output = 1;
3623 ppc_frob_label (sym);
3626 #endif /* OBJ_XCOFF */
3630 /* Skip the TOC symbol name. */
3631 while (is_part_of_name (*input_line_pointer)
3632 || *input_line_pointer == '['
3633 || *input_line_pointer == ']'
3634 || *input_line_pointer == '{'
3635 || *input_line_pointer == '}')
3636 ++input_line_pointer;
3638 /* Align to a four/eight byte boundary. */
3639 align = BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64 ? 3 : 2;
3640 frag_align (align, 0, 0);
3641 record_alignment (now_seg, align);
3642 #endif /* OBJ_ELF */
3644 if (*input_line_pointer != ',')
3645 demand_empty_rest_of_line ();
3648 ++input_line_pointer;
3649 cons ((ppc_size == PPC_OPCODE_64) ? 8 : 4);
3653 /* Pseudo-op .machine. */
3654 /* FIXME: `.machine' is a nop for the moment. */
3657 ppc_machine (ignore)
3658 int ignore ATTRIBUTE_UNUSED;
3660 discard_rest_of_line ();
3663 /* See whether a symbol is in the TOC section. */
3666 ppc_is_toc_sym (sym)
3670 return symbol_get_tc (sym)->class == XMC_TC;
3673 const char *sname = segment_name (S_GET_SEGMENT (sym));
3674 if (BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64)
3675 return strcmp (sname, ".toc") == 0;
3677 return strcmp (sname, ".got") == 0;
3680 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
3684 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
3686 /* Set the current section. */
3688 ppc_set_current_section (new)
3691 ppc_previous_section = ppc_current_section;
3692 ppc_current_section = new;
3695 /* pseudo-op: .previous
3696 behaviour: toggles the current section with the previous section.
3698 warnings: "No previous section" */
3701 ppc_previous (ignore)
3702 int ignore ATTRIBUTE_UNUSED;
3706 if (ppc_previous_section == NULL)
3708 as_warn (_("No previous section to return to. Directive ignored."));
3712 subseg_set (ppc_previous_section, 0);
3714 ppc_set_current_section (ppc_previous_section);
3717 /* pseudo-op: .pdata
3718 behaviour: predefined read only data section
3722 initial: .section .pdata "adr3"
3723 a - don't know -- maybe a misprint
3724 d - initialized data
3726 3 - double word aligned (that would be 4 byte boundary)
3729 Tag index tables (also known as the function table) for exception
3730 handling, debugging, etc. */
3734 int ignore ATTRIBUTE_UNUSED;
3736 if (pdata_section == 0)
3738 pdata_section = subseg_new (".pdata", 0);
3740 bfd_set_section_flags (stdoutput, pdata_section,
3741 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3742 | SEC_READONLY | SEC_DATA ));
3744 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3748 pdata_section = subseg_new (".pdata", 0);
3750 ppc_set_current_section (pdata_section);
3753 /* pseudo-op: .ydata
3754 behaviour: predefined read only data section
3758 initial: .section .ydata "drw3"
3759 a - don't know -- maybe a misprint
3760 d - initialized data
3762 3 - double word aligned (that would be 4 byte boundary)
3764 Tag tables (also known as the scope table) for exception handling,
3769 int ignore ATTRIBUTE_UNUSED;
3771 if (ydata_section == 0)
3773 ydata_section = subseg_new (".ydata", 0);
3774 bfd_set_section_flags (stdoutput, ydata_section,
3775 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3776 | SEC_READONLY | SEC_DATA ));
3778 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3782 ydata_section = subseg_new (".ydata", 0);
3784 ppc_set_current_section (ydata_section);
3787 /* pseudo-op: .reldata
3788 behaviour: predefined read write data section
3789 double word aligned (4-byte)
3790 FIXME: relocation is applied to it
3791 FIXME: what's the difference between this and .data?
3794 initial: .section .reldata "drw3"
3795 d - initialized data
3798 3 - double word aligned (that would be 8 byte boundary)
3801 Like .data, but intended to hold data subject to relocation, such as
3802 function descriptors, etc. */
3805 ppc_reldata (ignore)
3806 int ignore ATTRIBUTE_UNUSED;
3808 if (reldata_section == 0)
3810 reldata_section = subseg_new (".reldata", 0);
3812 bfd_set_section_flags (stdoutput, reldata_section,
3813 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3816 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3820 reldata_section = subseg_new (".reldata", 0);
3822 ppc_set_current_section (reldata_section);
3825 /* pseudo-op: .rdata
3826 behaviour: predefined read only data section
3830 initial: .section .rdata "dr3"
3831 d - initialized data
3833 3 - double word aligned (that would be 4 byte boundary) */
3837 int ignore ATTRIBUTE_UNUSED;
3839 if (rdata_section == 0)
3841 rdata_section = subseg_new (".rdata", 0);
3842 bfd_set_section_flags (stdoutput, rdata_section,
3843 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3844 | SEC_READONLY | SEC_DATA ));
3846 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3850 rdata_section = subseg_new (".rdata", 0);
3852 ppc_set_current_section (rdata_section);
3855 /* pseudo-op: .ualong
3856 behaviour: much like .int, with the exception that no alignment is
3858 FIXME: test the alignment statement
3864 int ignore ATTRIBUTE_UNUSED;
3870 /* pseudo-op: .znop <symbol name>
3871 behaviour: Issue a nop instruction
3872 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3873 the supplied symbol name.
3875 warnings: Missing symbol name */
3879 int ignore ATTRIBUTE_UNUSED;
3882 const struct powerpc_opcode *opcode;
3893 /* Strip out the symbol name. */
3894 symbol_name = input_line_pointer;
3895 c = get_symbol_end ();
3897 name = xmalloc (input_line_pointer - symbol_name + 1);
3898 strcpy (name, symbol_name);
3900 sym = symbol_find_or_make (name);
3902 *input_line_pointer = c;
3906 /* Look up the opcode in the hash table. */
3907 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3909 /* Stick in the nop. */
3910 insn = opcode->opcode;
3912 /* Write out the instruction. */
3914 md_number_to_chars (f, insn, 4);
3916 f - frag_now->fr_literal,
3921 BFD_RELOC_16_GOT_PCREL);
3934 register char *name;
3938 register symbolS *symbolP;
3941 name = input_line_pointer;
3942 c = get_symbol_end ();
3944 /* just after name is now '\0'. */
3945 p = input_line_pointer;
3948 if (*input_line_pointer != ',')
3950 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3951 ignore_rest_of_line ();
3955 input_line_pointer++; /* skip ',' */
3956 if ((temp = get_absolute_expression ()) < 0)
3958 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
3959 ignore_rest_of_line ();
3965 /* The third argument to .comm is the alignment. */
3966 if (*input_line_pointer != ',')
3970 ++input_line_pointer;
3971 align = get_absolute_expression ();
3974 as_warn (_("ignoring bad alignment"));
3981 symbolP = symbol_find_or_make (name);
3984 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
3986 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3987 S_GET_NAME (symbolP));
3988 ignore_rest_of_line ();
3992 if (S_GET_VALUE (symbolP))
3994 if (S_GET_VALUE (symbolP) != (valueT) temp)
3995 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3996 S_GET_NAME (symbolP),
3997 (long) S_GET_VALUE (symbolP),
4002 S_SET_VALUE (symbolP, (valueT) temp);
4003 S_SET_EXTERNAL (symbolP);
4006 demand_empty_rest_of_line ();
4010 * implement the .section pseudo op:
4011 * .section name {, "flags"}
4013 * | +--- optional flags: 'b' for bss
4015 * +-- section name 'l' for lib
4019 * 'd' (apparently m88k for data)
4021 * But if the argument is not a quoted string, treat it as a
4022 * subsegment number.
4024 * FIXME: this is a copy of the section processing from obj-coff.c, with
4025 * additions/changes for the moto-pas assembler support. There are three
4028 * FIXME: I just noticed this. This doesn't work at all really. It it
4029 * setting bits that bfd probably neither understands or uses. The
4030 * correct approach (?) will have to incorporate extra fields attached
4031 * to the section to hold the system specific stuff. (krk)
4034 * 'a' - unknown - referred to in documentation, but no definition supplied
4035 * 'c' - section has code
4036 * 'd' - section has initialized data
4037 * 'u' - section has uninitialized data
4038 * 'i' - section contains directives (info)
4039 * 'n' - section can be discarded
4040 * 'R' - remove section at link time
4042 * Section Protection:
4043 * 'r' - section is readable
4044 * 'w' - section is writeable
4045 * 'x' - section is executable
4046 * 's' - section is sharable
4048 * Section Alignment:
4049 * '0' - align to byte boundary
4050 * '1' - align to halfword undary
4051 * '2' - align to word boundary
4052 * '3' - align to doubleword boundary
4053 * '4' - align to quadword boundary
4054 * '5' - align to 32 byte boundary
4055 * '6' - align to 64 byte boundary
4060 ppc_pe_section (ignore)
4061 int ignore ATTRIBUTE_UNUSED;
4063 /* Strip out the section name. */
4072 section_name = input_line_pointer;
4073 c = get_symbol_end ();
4075 name = xmalloc (input_line_pointer - section_name + 1);
4076 strcpy (name, section_name);
4078 *input_line_pointer = c;
4083 flags = SEC_NO_FLAGS;
4085 if (strcmp (name, ".idata$2") == 0)
4089 else if (strcmp (name, ".idata$3") == 0)
4093 else if (strcmp (name, ".idata$4") == 0)
4097 else if (strcmp (name, ".idata$5") == 0)
4101 else if (strcmp (name, ".idata$6") == 0)
4106 /* Default alignment to 16 byte boundary. */
4109 if (*input_line_pointer == ',')
4111 ++input_line_pointer;
4113 if (*input_line_pointer != '"')
4114 exp = get_absolute_expression ();
4117 ++input_line_pointer;
4118 while (*input_line_pointer != '"'
4119 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4121 switch (*input_line_pointer)
4123 /* Section Contents */
4124 case 'a': /* unknown */
4125 as_bad (_("Unsupported section attribute -- 'a'"));
4127 case 'c': /* code section */
4130 case 'd': /* section has initialized data */
4133 case 'u': /* section has uninitialized data */
4134 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4138 case 'i': /* section contains directives (info) */
4139 /* FIXME: This is IMAGE_SCN_LNK_INFO
4141 flags |= SEC_HAS_CONTENTS;
4143 case 'n': /* section can be discarded */
4146 case 'R': /* Remove section at link time */
4147 flags |= SEC_NEVER_LOAD;
4150 /* Section Protection */
4151 case 'r': /* section is readable */
4152 flags |= IMAGE_SCN_MEM_READ;
4154 case 'w': /* section is writeable */
4155 flags |= IMAGE_SCN_MEM_WRITE;
4157 case 'x': /* section is executable */
4158 flags |= IMAGE_SCN_MEM_EXECUTE;
4160 case 's': /* section is sharable */
4161 flags |= IMAGE_SCN_MEM_SHARED;
4164 /* Section Alignment */
4165 case '0': /* align to byte boundary */
4166 flags |= IMAGE_SCN_ALIGN_1BYTES;
4169 case '1': /* align to halfword boundary */
4170 flags |= IMAGE_SCN_ALIGN_2BYTES;
4173 case '2': /* align to word boundary */
4174 flags |= IMAGE_SCN_ALIGN_4BYTES;
4177 case '3': /* align to doubleword boundary */
4178 flags |= IMAGE_SCN_ALIGN_8BYTES;
4181 case '4': /* align to quadword boundary */
4182 flags |= IMAGE_SCN_ALIGN_16BYTES;
4185 case '5': /* align to 32 byte boundary */
4186 flags |= IMAGE_SCN_ALIGN_32BYTES;
4189 case '6': /* align to 64 byte boundary */
4190 flags |= IMAGE_SCN_ALIGN_64BYTES;
4195 as_bad (_("unknown section attribute '%c'"),
4196 *input_line_pointer);
4199 ++input_line_pointer;
4201 if (*input_line_pointer == '"')
4202 ++input_line_pointer;
4206 sec = subseg_new (name, (subsegT) exp);
4208 ppc_set_current_section (sec);
4210 if (flags != SEC_NO_FLAGS)
4212 if (! bfd_set_section_flags (stdoutput, sec, flags))
4213 as_bad (_("error setting flags for \"%s\": %s"),
4214 bfd_section_name (stdoutput, sec),
4215 bfd_errmsg (bfd_get_error ()));
4218 bfd_set_section_alignment (stdoutput, sec, align);
4223 ppc_pe_function (ignore)
4224 int ignore ATTRIBUTE_UNUSED;
4230 name = input_line_pointer;
4231 endc = get_symbol_end ();
4233 ext_sym = symbol_find_or_make (name);
4235 *input_line_pointer = endc;
4237 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4238 SF_SET_FUNCTION (ext_sym);
4239 SF_SET_PROCESS (ext_sym);
4240 coff_add_linesym (ext_sym);
4242 demand_empty_rest_of_line ();
4246 ppc_pe_tocd (ignore)
4247 int ignore ATTRIBUTE_UNUSED;
4249 if (tocdata_section == 0)
4251 tocdata_section = subseg_new (".tocd", 0);
4252 /* FIXME: section flags won't work. */
4253 bfd_set_section_flags (stdoutput, tocdata_section,
4254 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4255 | SEC_READONLY | SEC_DATA));
4257 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
4261 rdata_section = subseg_new (".tocd", 0);
4264 ppc_set_current_section (tocdata_section);
4266 demand_empty_rest_of_line ();
4269 /* Don't adjust TOC relocs to use the section symbol. */
4272 ppc_pe_fix_adjustable (fix)
4275 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
4282 /* XCOFF specific symbol and file handling. */
4284 /* Canonicalize the symbol name. We use the to force the suffix, if
4285 any, to use square brackets, and to be in upper case. */
4288 ppc_canonicalize_symbol_name (name)
4293 if (ppc_stab_symbol)
4296 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
4310 for (s++; *s != '\0' && *s != brac; s++)
4313 if (*s == '\0' || s[1] != '\0')
4314 as_bad (_("bad symbol suffix"));
4322 /* Set the class of a symbol based on the suffix, if any. This is
4323 called whenever a new symbol is created. */
4326 ppc_symbol_new_hook (sym)
4329 struct ppc_tc_sy *tc;
4332 tc = symbol_get_tc (sym);
4336 tc->real_name = NULL;
4342 if (ppc_stab_symbol)
4345 s = strchr (S_GET_NAME (sym), '[');
4346 if (s == (const char *) NULL)
4348 /* There is no suffix. */
4357 if (strcmp (s, "BS]") == 0)
4361 if (strcmp (s, "DB]") == 0)
4363 else if (strcmp (s, "DS]") == 0)
4367 if (strcmp (s, "GL]") == 0)
4371 if (strcmp (s, "PR]") == 0)
4375 if (strcmp (s, "RO]") == 0)
4377 else if (strcmp (s, "RW]") == 0)
4381 if (strcmp (s, "SV]") == 0)
4385 if (strcmp (s, "TC]") == 0)
4387 else if (strcmp (s, "TI]") == 0)
4389 else if (strcmp (s, "TB]") == 0)
4391 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
4392 tc->class = XMC_TC0;
4395 if (strcmp (s, "UA]") == 0)
4397 else if (strcmp (s, "UC]") == 0)
4401 if (strcmp (s, "XO]") == 0)
4406 if (tc->class == -1)
4407 as_bad (_("Unrecognized symbol suffix"));
4410 /* Set the class of a label based on where it is defined. This
4411 handles symbols without suffixes. Also, move the symbol so that it
4412 follows the csect symbol. */
4415 ppc_frob_label (sym)
4418 if (ppc_current_csect != (symbolS *) NULL)
4420 if (symbol_get_tc (sym)->class == -1)
4421 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class;
4423 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4424 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
4425 &symbol_rootP, &symbol_lastP);
4426 symbol_get_tc (ppc_current_csect)->within = sym;
4430 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4431 seen. It tells ppc_adjust_symtab whether it needs to look through
4434 static boolean ppc_saw_abs;
4436 /* Change the name of a symbol just before writing it out. Set the
4437 real name if the .rename pseudo-op was used. Otherwise, remove any
4438 class suffix. Return 1 if the symbol should not be included in the
4442 ppc_frob_symbol (sym)
4445 static symbolS *ppc_last_function;
4446 static symbolS *set_end;
4448 /* Discard symbols that should not be included in the output symbol
4450 if (! symbol_used_in_reloc_p (sym)
4451 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
4452 || (! S_IS_EXTERNAL (sym)
4453 && ! symbol_get_tc (sym)->output
4454 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4457 if (symbol_get_tc (sym)->real_name != (char *) NULL)
4458 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
4464 name = S_GET_NAME (sym);
4465 s = strchr (name, '[');
4466 if (s != (char *) NULL)
4472 snew = xmalloc (len + 1);
4473 memcpy (snew, name, len);
4476 S_SET_NAME (sym, snew);
4480 if (set_end != (symbolS *) NULL)
4482 SA_SET_SYM_ENDNDX (set_end, sym);
4486 if (SF_GET_FUNCTION (sym))
4488 if (ppc_last_function != (symbolS *) NULL)
4489 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4490 ppc_last_function = sym;
4491 if (symbol_get_tc (sym)->size != (symbolS *) NULL)
4493 resolve_symbol_value (symbol_get_tc (sym)->size);
4494 SA_SET_SYM_FSIZE (sym,
4495 (long) S_GET_VALUE (symbol_get_tc (sym)->size));
4498 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4499 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4501 if (ppc_last_function == (symbolS *) NULL)
4502 as_bad (_(".ef with no preceding .function"));
4505 set_end = ppc_last_function;
4506 ppc_last_function = NULL;
4508 /* We don't have a C_EFCN symbol, but we need to force the
4509 COFF backend to believe that it has seen one. */
4510 coff_last_function = NULL;
4514 if (! S_IS_EXTERNAL (sym)
4515 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
4516 && S_GET_STORAGE_CLASS (sym) != C_FILE
4517 && S_GET_STORAGE_CLASS (sym) != C_FCN
4518 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4519 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4520 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4521 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4522 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4523 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4524 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4526 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4527 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4530 union internal_auxent *a;
4532 /* Create a csect aux. */
4533 i = S_GET_NUMBER_AUXILIARY (sym);
4534 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4535 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
4536 if (symbol_get_tc (sym)->class == XMC_TC0)
4538 /* This is the TOC table. */
4539 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4540 a->x_csect.x_scnlen.l = 0;
4541 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4543 else if (symbol_get_tc (sym)->subseg != 0)
4545 /* This is a csect symbol. x_scnlen is the size of the
4547 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
4548 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4549 S_GET_SEGMENT (sym))
4550 - S_GET_VALUE (sym));
4553 resolve_symbol_value (symbol_get_tc (sym)->next);
4554 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
4555 - S_GET_VALUE (sym));
4557 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
4559 else if (S_GET_SEGMENT (sym) == bss_section)
4561 /* This is a common symbol. */
4562 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
4563 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
4564 if (S_IS_EXTERNAL (sym))
4565 symbol_get_tc (sym)->class = XMC_RW;
4567 symbol_get_tc (sym)->class = XMC_BS;
4569 else if (S_GET_SEGMENT (sym) == absolute_section)
4571 /* This is an absolute symbol. The csect will be created by
4572 ppc_adjust_symtab. */
4574 a->x_csect.x_smtyp = XTY_LD;
4575 if (symbol_get_tc (sym)->class == -1)
4576 symbol_get_tc (sym)->class = XMC_XO;
4578 else if (! S_IS_DEFINED (sym))
4580 /* This is an external symbol. */
4581 a->x_csect.x_scnlen.l = 0;
4582 a->x_csect.x_smtyp = XTY_ER;
4584 else if (symbol_get_tc (sym)->class == XMC_TC)
4588 /* This is a TOC definition. x_scnlen is the size of the
4590 next = symbol_next (sym);
4591 while (symbol_get_tc (next)->class == XMC_TC0)
4592 next = symbol_next (next);
4593 if (next == (symbolS *) NULL
4594 || symbol_get_tc (next)->class != XMC_TC)
4596 if (ppc_after_toc_frag == (fragS *) NULL)
4597 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4599 - S_GET_VALUE (sym));
4601 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4602 - S_GET_VALUE (sym));
4606 resolve_symbol_value (next);
4607 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4608 - S_GET_VALUE (sym));
4610 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4616 /* This is a normal symbol definition. x_scnlen is the
4617 symbol index of the containing csect. */
4618 if (S_GET_SEGMENT (sym) == text_section)
4619 csect = ppc_text_csects;
4620 else if (S_GET_SEGMENT (sym) == data_section)
4621 csect = ppc_data_csects;
4625 /* Skip the initial dummy symbol. */
4626 csect = symbol_get_tc (csect)->next;
4628 if (csect == (symbolS *) NULL)
4630 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4631 a->x_csect.x_scnlen.l = 0;
4635 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
4637 resolve_symbol_value (symbol_get_tc (csect)->next);
4638 if (S_GET_VALUE (symbol_get_tc (csect)->next)
4639 > S_GET_VALUE (sym))
4641 csect = symbol_get_tc (csect)->next;
4644 a->x_csect.x_scnlen.p =
4645 coffsymbol (symbol_get_bfdsym (csect))->native;
4646 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
4649 a->x_csect.x_smtyp = XTY_LD;
4652 a->x_csect.x_parmhash = 0;
4653 a->x_csect.x_snhash = 0;
4654 if (symbol_get_tc (sym)->class == -1)
4655 a->x_csect.x_smclas = XMC_PR;
4657 a->x_csect.x_smclas = symbol_get_tc (sym)->class;
4658 a->x_csect.x_stab = 0;
4659 a->x_csect.x_snstab = 0;
4661 /* Don't let the COFF backend resort these symbols. */
4662 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
4664 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4666 /* We want the value to be the symbol index of the referenced
4667 csect symbol. BFD will do that for us if we set the right
4671 coffsymbol (symbol_get_bfdsym
4672 (symbol_get_tc (sym)->within))->native));
4673 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
4675 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4680 /* The value is the offset from the enclosing csect. */
4681 block = symbol_get_tc (sym)->within;
4682 csect = symbol_get_tc (block)->within;
4683 resolve_symbol_value (csect);
4684 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4686 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4687 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4689 /* We want the value to be a file offset into the line numbers.
4690 BFD will do that for us if we set the right flags. We have
4691 already set the value correctly. */
4692 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
4698 /* Adjust the symbol table. This creates csect symbols for all
4699 absolute symbols. */
4702 ppc_adjust_symtab ()
4709 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4713 union internal_auxent *a;
4715 if (S_GET_SEGMENT (sym) != absolute_section)
4718 csect = symbol_create (".abs[XO]", absolute_section,
4719 S_GET_VALUE (sym), &zero_address_frag);
4720 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
4721 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4722 i = S_GET_NUMBER_AUXILIARY (csect);
4723 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4724 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
4725 a->x_csect.x_scnlen.l = 0;
4726 a->x_csect.x_smtyp = XTY_SD;
4727 a->x_csect.x_parmhash = 0;
4728 a->x_csect.x_snhash = 0;
4729 a->x_csect.x_smclas = XMC_XO;
4730 a->x_csect.x_stab = 0;
4731 a->x_csect.x_snstab = 0;
4733 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4735 i = S_GET_NUMBER_AUXILIARY (sym);
4736 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
4737 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
4738 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
4741 ppc_saw_abs = false;
4744 /* Set the VMA for a section. This is called on all the sections in
4748 ppc_frob_section (sec)
4751 static bfd_size_type vma = 0;
4753 bfd_set_section_vma (stdoutput, sec, vma);
4754 vma += bfd_section_size (stdoutput, sec);
4757 #endif /* OBJ_XCOFF */
4759 /* Turn a string in input_line_pointer into a floating point constant
4760 of type TYPE, and store the appropriate bytes in *LITP. The number
4761 of LITTLENUMS emitted is stored in *SIZEP. An error message is
4762 returned, or NULL on OK. */
4765 md_atof (type, litp, sizep)
4771 LITTLENUM_TYPE words[4];
4787 return _("bad call to md_atof");
4790 t = atof_ieee (input_line_pointer, type, words);
4792 input_line_pointer = t;
4796 if (target_big_endian)
4798 for (i = 0; i < prec; i++)
4800 md_number_to_chars (litp, (valueT) words[i], 2);
4806 for (i = prec - 1; i >= 0; i--)
4808 md_number_to_chars (litp, (valueT) words[i], 2);
4816 /* Write a value out to the object file, using the appropriate
4820 md_number_to_chars (buf, val, n)
4825 if (target_big_endian)
4826 number_to_chars_bigendian (buf, val, n);
4828 number_to_chars_littleendian (buf, val, n);
4831 /* Align a section (I don't know why this is machine dependent). */
4834 md_section_align (seg, addr)
4838 int align = bfd_get_section_alignment (stdoutput, seg);
4840 return ((addr + (1 << align) - 1) & (-1 << align));
4843 /* We don't have any form of relaxing. */
4846 md_estimate_size_before_relax (fragp, seg)
4847 fragS *fragp ATTRIBUTE_UNUSED;
4848 asection *seg ATTRIBUTE_UNUSED;
4854 /* Convert a machine dependent frag. We never generate these. */
4857 md_convert_frag (abfd, sec, fragp)
4858 bfd *abfd ATTRIBUTE_UNUSED;
4859 asection *sec ATTRIBUTE_UNUSED;
4860 fragS *fragp ATTRIBUTE_UNUSED;
4865 /* We have no need to default values of symbols. */
4868 md_undefined_symbol (name)
4869 char *name ATTRIBUTE_UNUSED;
4874 /* Functions concerning relocs. */
4876 /* The location from which a PC relative jump should be calculated,
4877 given a PC relative reloc. */
4880 md_pcrel_from_section (fixp, sec)
4882 segT sec ATTRIBUTE_UNUSED;
4884 return fixp->fx_frag->fr_address + fixp->fx_where;
4889 /* This is called to see whether a fixup should be adjusted to use a
4890 section symbol. We take the opportunity to change a fixup against
4891 a symbol in the TOC subsegment into a reloc against the
4892 corresponding .tc symbol. */
4895 ppc_fix_adjustable (fix)
4900 resolve_symbol_value (fix->fx_addsy);
4901 val = S_GET_VALUE (fix->fx_addsy);
4902 if (ppc_toc_csect != (symbolS *) NULL
4903 && fix->fx_addsy != (symbolS *) NULL
4904 && fix->fx_addsy != ppc_toc_csect
4905 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4906 && val >= ppc_toc_frag->fr_address
4907 && (ppc_after_toc_frag == (fragS *) NULL
4908 || val < ppc_after_toc_frag->fr_address))
4912 for (sy = symbol_next (ppc_toc_csect);
4913 sy != (symbolS *) NULL;
4914 sy = symbol_next (sy))
4916 if (symbol_get_tc (sy)->class == XMC_TC0)
4918 if (symbol_get_tc (sy)->class != XMC_TC)
4920 resolve_symbol_value (sy);
4921 if (val == S_GET_VALUE (sy))
4924 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4929 as_bad_where (fix->fx_file, fix->fx_line,
4930 _("symbol in .toc does not match any .tc"));
4933 /* Possibly adjust the reloc to be against the csect. */
4934 if (fix->fx_addsy != (symbolS *) NULL
4935 && symbol_get_tc (fix->fx_addsy)->subseg == 0
4936 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC0
4937 && symbol_get_tc (fix->fx_addsy)->class != XMC_TC
4938 && S_GET_SEGMENT (fix->fx_addsy) != bss_section
4939 /* Don't adjust if this is a reloc in the toc section. */
4940 && (S_GET_SEGMENT (fix->fx_addsy) != data_section
4941 || ppc_toc_csect == NULL
4942 || val < ppc_toc_frag->fr_address
4943 || (ppc_after_toc_frag != NULL
4944 && val >= ppc_after_toc_frag->fr_address)))
4948 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4949 csect = ppc_text_csects;
4950 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4951 csect = ppc_data_csects;
4955 /* Skip the initial dummy symbol. */
4956 csect = symbol_get_tc (csect)->next;
4958 if (csect != (symbolS *) NULL)
4960 while (symbol_get_tc (csect)->next != (symbolS *) NULL
4961 && (symbol_get_frag (symbol_get_tc (csect)->next)->fr_address
4964 /* If the csect address equals the symbol value, then we
4965 have to look through the full symbol table to see
4966 whether this is the csect we want. Note that we will
4967 only get here if the csect has zero length. */
4968 if ((symbol_get_frag (csect)->fr_address == val)
4969 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4973 for (scan = symbol_next (csect);
4975 scan = symbol_next (scan))
4977 if (symbol_get_tc (scan)->subseg != 0)
4979 if (scan == fix->fx_addsy)
4983 /* If we found the symbol before the next csect
4984 symbol, then this is the csect we want. */
4985 if (scan == fix->fx_addsy)
4989 csect = symbol_get_tc (csect)->next;
4992 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4993 - symbol_get_frag (csect)->fr_address);
4994 fix->fx_addsy = csect;
4998 /* Adjust a reloc against a .lcomm symbol to be against the base
5000 if (fix->fx_addsy != (symbolS *) NULL
5001 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
5002 && ! S_IS_EXTERNAL (fix->fx_addsy))
5004 resolve_symbol_value (symbol_get_frag (fix->fx_addsy)->fr_symbol);
5006 (S_GET_VALUE (fix->fx_addsy)
5007 - S_GET_VALUE (symbol_get_frag (fix->fx_addsy)->fr_symbol));
5008 fix->fx_addsy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
5014 /* A reloc from one csect to another must be kept. The assembler
5015 will, of course, keep relocs between sections, and it will keep
5016 absolute relocs, but we need to force it to keep PC relative relocs
5017 between two csects in the same section. */
5020 ppc_force_relocation (fix)
5023 /* At this point fix->fx_addsy should already have been converted to
5024 a csect symbol. If the csect does not include the fragment, then
5025 we need to force the relocation. */
5027 && fix->fx_addsy != NULL
5028 && symbol_get_tc (fix->fx_addsy)->subseg != 0
5029 && ((symbol_get_frag (fix->fx_addsy)->fr_address
5030 > fix->fx_frag->fr_address)
5031 || (symbol_get_tc (fix->fx_addsy)->next != NULL
5032 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
5033 <= fix->fx_frag->fr_address))))
5039 #endif /* OBJ_XCOFF */
5043 ppc_fix_adjustable (fix)
5046 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
5047 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
5048 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
5049 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
5050 && fix->fx_r_type != BFD_RELOC_GPREL16
5051 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
5052 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
5053 && ! S_IS_EXTERNAL (fix->fx_addsy)
5054 && ! S_IS_WEAK (fix->fx_addsy)
5056 || (fix->fx_subsy != NULL
5057 && (S_GET_SEGMENT (fix->fx_subsy)
5058 == S_GET_SEGMENT (fix->fx_addsy)))
5059 || S_IS_LOCAL (fix->fx_addsy)));
5063 /* Apply a fixup to the object code. This is called for all the
5064 fixups we generated by the call to fix_new_exp, above. In the call
5065 above we used a reloc code which was the largest legal reloc code
5066 plus the operand index. Here we undo that to recover the operand
5067 index. At this point all symbol values should be fully resolved,
5068 and we attempt to completely resolve the reloc. If we can not do
5069 that, we determine the correct reloc code and put it back in the
5073 md_apply_fix3 (fixp, valuep, seg)
5076 segT seg ATTRIBUTE_UNUSED;
5082 if (fixp->fx_addsy != NULL)
5084 /* `*valuep' may contain the value of the symbol on which the reloc
5085 will be based; we have to remove it. */
5086 if (symbol_used_in_reloc_p (fixp->fx_addsy)
5087 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
5088 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
5089 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
5090 value -= S_GET_VALUE (fixp->fx_addsy);
5092 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
5093 supposed to be? I think this is related to various similar
5094 FIXMEs in tc-i386.c and tc-sparc.c. */
5096 value += fixp->fx_frag->fr_address + fixp->fx_where;
5103 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
5104 the symbol values. Since we are using BFD_ASSEMBLER, if we are
5105 doing this relocation the code in write.c is going to call
5106 bfd_install_relocation, which is also going to use the symbol
5107 value. That means that if the reloc is fully resolved we want to
5108 use *valuep since bfd_install_relocation is not being used.
5109 However, if the reloc is not fully resolved we do not want to use
5110 *valuep, and must use fx_offset instead. However, if the reloc
5111 is PC relative, we do want to use *valuep since it includes the
5112 result of md_pcrel_from. This is confusing. */
5113 if (fixp->fx_addsy == (symbolS *) NULL)
5118 else if (fixp->fx_pcrel)
5122 value = fixp->fx_offset;
5123 if (fixp->fx_subsy != (symbolS *) NULL)
5125 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
5126 value -= S_GET_VALUE (fixp->fx_subsy);
5129 /* We can't actually support subtracting a symbol. */
5130 as_bad_where (fixp->fx_file, fixp->fx_line,
5131 _("expression too complex"));
5137 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
5140 const struct powerpc_operand *operand;
5144 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
5146 operand = &powerpc_operands[opindex];
5149 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5150 does not generate a reloc. It uses the offset of `sym' within its
5151 csect. Other usages, such as `.long sym', generate relocs. This
5152 is the documented behaviour of non-TOC symbols. */
5153 if ((operand->flags & PPC_OPERAND_PARENS) != 0
5154 && operand->bits == 16
5155 && operand->shift == 0
5156 && operand->insert == NULL
5157 && fixp->fx_addsy != NULL
5158 && symbol_get_tc (fixp->fx_addsy)->subseg != 0
5159 && symbol_get_tc (fixp->fx_addsy)->class != XMC_TC
5160 && symbol_get_tc (fixp->fx_addsy)->class != XMC_TC0
5161 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
5163 value = fixp->fx_offset;
5168 /* Fetch the instruction, insert the fully resolved operand
5169 value, and stuff the instruction back again. */
5170 where = fixp->fx_frag->fr_literal + fixp->fx_where;
5171 if (target_big_endian)
5172 insn = bfd_getb32 ((unsigned char *) where);
5174 insn = bfd_getl32 ((unsigned char *) where);
5175 insn = ppc_insert_operand (insn, operand, (offsetT) value,
5176 fixp->fx_file, fixp->fx_line);
5177 if (target_big_endian)
5178 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5180 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5184 /* Nothing else to do here. */
5188 assert (fixp->fx_addsy != NULL);
5190 /* Determine a BFD reloc value based on the operand information.
5191 We are only prepared to turn a few of the operands into
5193 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5194 && operand->bits == 26
5195 && operand->shift == 0)
5196 fixp->fx_r_type = BFD_RELOC_PPC_B26;
5197 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5198 && operand->bits == 16
5199 && operand->shift == 0)
5200 fixp->fx_r_type = BFD_RELOC_PPC_B16;
5201 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5202 && operand->bits == 26
5203 && operand->shift == 0)
5204 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
5205 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5206 && operand->bits == 16
5207 && operand->shift == 0)
5208 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
5209 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5210 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
5211 && operand->bits == 16
5212 && operand->shift == 0
5213 && ppc_is_toc_sym (fixp->fx_addsy))
5215 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
5217 if (BFD_DEFAULT_TARGET_SIZE == 64
5218 && ppc_size == PPC_OPCODE_64
5219 && (operand->flags & PPC_OPERAND_DS) != 0)
5220 fixp->fx_r_type = BFD_RELOC_PPC64_TOC16_DS;
5223 if (target_big_endian)
5224 fixp->fx_where += 2;
5226 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5232 /* Use expr_symbol_where to see if this is an expression
5234 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
5235 as_bad_where (fixp->fx_file, fixp->fx_line,
5236 _("unresolved expression that must be resolved"));
5238 as_bad_where (fixp->fx_file, fixp->fx_line,
5239 _("unsupported relocation against %s"),
5240 S_GET_NAME (fixp->fx_addsy));
5248 ppc_elf_validate_fix (fixp, seg);
5250 switch (fixp->fx_r_type)
5252 case BFD_RELOC_CTOR:
5253 if (BFD_DEFAULT_TARGET_SIZE == 64 && ppc_size == PPC_OPCODE_64)
5259 fixp->fx_r_type = BFD_RELOC_32_PCREL;
5263 case BFD_RELOC_32_PCREL:
5264 case BFD_RELOC_32_BASEREL:
5265 case BFD_RELOC_PPC_EMB_NADDR32:
5266 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5273 fixp->fx_r_type = BFD_RELOC_64_PCREL;
5276 case BFD_RELOC_64_PCREL:
5277 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5281 case BFD_RELOC_LO16:
5283 case BFD_RELOC_GPREL16:
5284 case BFD_RELOC_16_GOT_PCREL:
5285 case BFD_RELOC_16_GOTOFF:
5286 case BFD_RELOC_LO16_GOTOFF:
5287 case BFD_RELOC_HI16_GOTOFF:
5288 case BFD_RELOC_HI16_S_GOTOFF:
5289 case BFD_RELOC_LO16_BASEREL:
5290 case BFD_RELOC_HI16_BASEREL:
5291 case BFD_RELOC_HI16_S_BASEREL:
5292 case BFD_RELOC_PPC_EMB_NADDR16:
5293 case BFD_RELOC_PPC_EMB_NADDR16_LO:
5294 case BFD_RELOC_PPC_EMB_NADDR16_HI:
5295 case BFD_RELOC_PPC_EMB_NADDR16_HA:
5296 case BFD_RELOC_PPC_EMB_SDAI16:
5297 case BFD_RELOC_PPC_EMB_SDA2REL:
5298 case BFD_RELOC_PPC_EMB_SDA2I16:
5299 case BFD_RELOC_PPC_EMB_RELSEC16:
5300 case BFD_RELOC_PPC_EMB_RELST_LO:
5301 case BFD_RELOC_PPC_EMB_RELST_HI:
5302 case BFD_RELOC_PPC_EMB_RELST_HA:
5303 case BFD_RELOC_PPC_EMB_RELSDA:
5304 case BFD_RELOC_PPC_TOC16:
5306 #if BFD_DEFAULT_TARGET_SIZE == 64
5307 case BFD_RELOC_PPC64_TOC16_LO:
5308 case BFD_RELOC_PPC64_TOC16_HI:
5309 case BFD_RELOC_PPC64_TOC16_HA:
5314 if (fixp->fx_addsy != NULL)
5315 as_bad_where (fixp->fx_file, fixp->fx_line,
5316 _("cannot emit PC relative %s relocation against %s"),
5317 bfd_get_reloc_code_name (fixp->fx_r_type),
5318 S_GET_NAME (fixp->fx_addsy));
5320 as_bad_where (fixp->fx_file, fixp->fx_line,
5321 _("cannot emit PC relative %s relocation"),
5322 bfd_get_reloc_code_name (fixp->fx_r_type));
5325 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5329 /* This case happens when you write, for example,
5331 where L1 and L2 are defined later. */
5332 case BFD_RELOC_HI16:
5335 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5339 case BFD_RELOC_HI16_S:
5342 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5347 #if BFD_DEFAULT_TARGET_SIZE == 64
5348 case BFD_RELOC_PPC64_HIGHER:
5351 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5352 PPC_HIGHER (value), 2);
5355 case BFD_RELOC_PPC64_HIGHER_S:
5358 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5359 PPC_HIGHERA (value), 2);
5362 case BFD_RELOC_PPC64_HIGHEST:
5365 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5366 PPC_HIGHEST (value), 2);
5369 case BFD_RELOC_PPC64_HIGHEST_S:
5372 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5373 PPC_HIGHESTA (value), 2);
5376 case BFD_RELOC_PPC64_ADDR16_DS:
5377 case BFD_RELOC_PPC64_ADDR16_LO_DS:
5378 case BFD_RELOC_PPC64_GOT16_DS:
5379 case BFD_RELOC_PPC64_GOT16_LO_DS:
5380 case BFD_RELOC_PPC64_PLT16_LO_DS:
5381 case BFD_RELOC_PPC64_SECTOFF_DS:
5382 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
5383 case BFD_RELOC_PPC64_TOC16_DS:
5384 case BFD_RELOC_PPC64_TOC16_LO_DS:
5385 case BFD_RELOC_PPC64_PLTGOT16_DS:
5386 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
5390 unsigned char *where = fixp->fx_frag->fr_literal + fixp->fx_where;
5393 if (target_big_endian)
5394 val = bfd_getb16 (where);
5396 val = bfd_getl16 (where);
5397 val |= (value & 0xfffc);
5398 if (target_big_endian)
5399 bfd_putb16 ((bfd_vma) val, where);
5401 bfd_putl16 ((bfd_vma) val, where);
5406 /* Because SDA21 modifies the register field, the size is set to 4
5407 bytes, rather than 2, so offset it here appropriately. */
5408 case BFD_RELOC_PPC_EMB_SDA21:
5412 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
5413 + ((target_big_endian) ? 2 : 0),
5421 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
5425 case BFD_RELOC_24_PLT_PCREL:
5426 case BFD_RELOC_PPC_LOCAL24PC:
5427 if (!fixp->fx_pcrel && !fixp->fx_done)
5435 /* Fetch the instruction, insert the fully resolved operand
5436 value, and stuff the instruction back again. */
5437 where = fixp->fx_frag->fr_literal + fixp->fx_where;
5438 if (target_big_endian)
5439 insn = bfd_getb32 ((unsigned char *) where);
5441 insn = bfd_getl32 ((unsigned char *) where);
5442 if ((value & 3) != 0)
5443 as_bad_where (fixp->fx_file, fixp->fx_line,
5444 _("must branch to an address a multiple of 4"));
5445 if ((offsetT) value < -0x40000000
5446 || (offsetT) value >= 0x40000000)
5447 as_bad_where (fixp->fx_file, fixp->fx_line,
5448 _("@local or @plt branch destination is too far away, %ld bytes"),
5450 insn = insn | (value & 0x03fffffc);
5451 if (target_big_endian)
5452 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5454 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5458 case BFD_RELOC_VTABLE_INHERIT:
5461 && !S_IS_DEFINED (fixp->fx_addsy)
5462 && !S_IS_WEAK (fixp->fx_addsy))
5463 S_SET_WEAK (fixp->fx_addsy);
5466 case BFD_RELOC_VTABLE_ENTRY:
5471 #if BFD_DEFAULT_TARGET_SIZE == 64
5472 /* Generated by reference to `sym@tocbase'. The sym is
5473 ignored by the linker. */
5474 case BFD_RELOC_PPC64_TOC:
5481 _("Gas failure, reloc value %d\n"), fixp->fx_r_type);
5488 fixp->fx_addnumber = value;
5490 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
5491 fixp->fx_addnumber = 0;
5495 fixp->fx_addnumber = 0;
5497 /* We want to use the offset within the data segment of the
5498 symbol, not the actual VMA of the symbol. */
5499 fixp->fx_addnumber =
5500 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
5508 /* Generate a reloc for a fixup. */
5511 tc_gen_reloc (seg, fixp)
5512 asection *seg ATTRIBUTE_UNUSED;
5517 reloc = (arelent *) xmalloc (sizeof (arelent));
5519 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
5520 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
5521 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5522 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5523 if (reloc->howto == (reloc_howto_type *) NULL)
5525 as_bad_where (fixp->fx_file, fixp->fx_line,
5526 _("reloc %d not supported by object file format"),
5527 (int) fixp->fx_r_type);
5530 reloc->addend = fixp->fx_addnumber;