1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, Cygnus Support.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 #include "opcode/ppc.h"
37 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
39 /* Tell the main code what the endianness is. */
40 extern int target_big_endian;
42 /* Whether or not, we've set target_big_endian. */
43 static int set_target_endian = 0;
45 /* Whether to use user friendly register names. */
46 #ifndef TARGET_REG_NAMES_P
48 #define TARGET_REG_NAMES_P true
50 #define TARGET_REG_NAMES_P false
54 static boolean reg_names_p = TARGET_REG_NAMES_P;
56 static boolean register_name PARAMS ((expressionS *));
57 static void ppc_set_cpu PARAMS ((void));
58 static unsigned long ppc_insert_operand
59 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
60 offsetT val, char *file, unsigned int line));
61 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
62 static void ppc_byte PARAMS ((int));
63 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
64 static void ppc_tc PARAMS ((int));
67 static void ppc_comm PARAMS ((int));
68 static void ppc_bb PARAMS ((int));
69 static void ppc_bc PARAMS ((int));
70 static void ppc_bf PARAMS ((int));
71 static void ppc_biei PARAMS ((int));
72 static void ppc_bs PARAMS ((int));
73 static void ppc_eb PARAMS ((int));
74 static void ppc_ec PARAMS ((int));
75 static void ppc_ef PARAMS ((int));
76 static void ppc_es PARAMS ((int));
77 static void ppc_csect PARAMS ((int));
78 static void ppc_change_csect PARAMS ((symbolS *));
79 static void ppc_function PARAMS ((int));
80 static void ppc_extern PARAMS ((int));
81 static void ppc_lglobl PARAMS ((int));
82 static void ppc_section PARAMS ((int));
83 static void ppc_stabx PARAMS ((int));
84 static void ppc_rename PARAMS ((int));
85 static void ppc_toc PARAMS ((int));
86 static void ppc_xcoff_cons PARAMS ((int));
90 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
91 static void ppc_elf_cons PARAMS ((int));
92 static void ppc_elf_rdata PARAMS ((int));
93 static void ppc_elf_lcomm PARAMS ((int));
94 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
98 static void ppc_set_current_section PARAMS ((segT));
99 static void ppc_previous PARAMS ((int));
100 static void ppc_pdata PARAMS ((int));
101 static void ppc_ydata PARAMS ((int));
102 static void ppc_reldata PARAMS ((int));
103 static void ppc_rdata PARAMS ((int));
104 static void ppc_ualong PARAMS ((int));
105 static void ppc_znop PARAMS ((int));
106 static void ppc_pe_comm PARAMS ((int));
107 static void ppc_pe_section PARAMS ((int));
108 static void ppc_pe_function PARAMS ((int));
109 static void ppc_pe_tocd PARAMS ((int));
112 /* Generic assembler global variables which must be defined by all
116 /* This string holds the chars that always start a comment. If the
117 pre-processor is disabled, these aren't very useful. The macro
118 tc_comment_chars points to this. We use this, rather than the
119 usual comment_chars, so that we can switch for Solaris conventions. */
120 static const char ppc_solaris_comment_chars[] = "#!";
121 static const char ppc_eabi_comment_chars[] = "#";
123 #ifdef TARGET_SOLARIS_COMMENT
124 const char *ppc_comment_chars = ppc_solaris_comment_chars;
126 const char *ppc_comment_chars = ppc_eabi_comment_chars;
129 const char comment_chars[] = "#";
132 /* Characters which start a comment at the beginning of a line. */
133 const char line_comment_chars[] = "#";
135 /* Characters which may be used to separate multiple commands on a
137 const char line_separator_chars[] = ";";
139 /* Characters which are used to indicate an exponent in a floating
141 const char EXP_CHARS[] = "eE";
143 /* Characters which mean that a number is a floating point constant,
145 const char FLT_CHARS[] = "dD";
147 /* The target specific pseudo-ops which we support. */
149 const pseudo_typeS md_pseudo_table[] =
151 /* Pseudo-ops which must be overridden. */
152 { "byte", ppc_byte, 0 },
155 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
156 legitimately belong in the obj-*.c file. However, XCOFF is based
157 on COFF, and is only implemented for the RS/6000. We just use
158 obj-coff.c, and add what we need here. */
159 { "comm", ppc_comm, 0 },
160 { "lcomm", ppc_comm, 1 },
164 { "bi", ppc_biei, 0 },
166 { "csect", ppc_csect, 0 },
167 { "data", ppc_section, 'd' },
171 { "ei", ppc_biei, 1 },
173 { "extern", ppc_extern, 0 },
174 { "function", ppc_function, 0 },
175 { "lglobl", ppc_lglobl, 0 },
176 { "rename", ppc_rename, 0 },
177 { "stabx", ppc_stabx, 0 },
178 { "text", ppc_section, 't' },
179 { "toc", ppc_toc, 0 },
180 { "long", ppc_xcoff_cons, 2 },
181 { "word", ppc_xcoff_cons, 1 },
182 { "short", ppc_xcoff_cons, 1 },
186 { "long", ppc_elf_cons, 4 },
187 { "word", ppc_elf_cons, 2 },
188 { "short", ppc_elf_cons, 2 },
189 { "rdata", ppc_elf_rdata, 0 },
190 { "rodata", ppc_elf_rdata, 0 },
191 { "lcomm", ppc_elf_lcomm, 0 },
195 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
196 { "previous", ppc_previous, 0 },
197 { "pdata", ppc_pdata, 0 },
198 { "ydata", ppc_ydata, 0 },
199 { "reldata", ppc_reldata, 0 },
200 { "rdata", ppc_rdata, 0 },
201 { "ualong", ppc_ualong, 0 },
202 { "znop", ppc_znop, 0 },
203 { "comm", ppc_pe_comm, 0 },
204 { "lcomm", ppc_pe_comm, 1 },
205 { "section", ppc_pe_section, 0 },
206 { "function", ppc_pe_function,0 },
207 { "tocd", ppc_pe_tocd, 0 },
210 /* This pseudo-op is used even when not generating XCOFF output. */
217 /* Predefined register names if -mregnames (or default for Windows NT). */
218 /* In general, there are lots of them, in an attempt to be compatible */
219 /* with a number of other Windows NT assemblers. */
221 /* Structure to hold information about predefined registers. */
228 /* List of registers that are pre-defined:
230 Each general register has predefined names of the form:
231 1. r<reg_num> which has the value <reg_num>.
232 2. r.<reg_num> which has the value <reg_num>.
235 Each floating point register has predefined names of the form:
236 1. f<reg_num> which has the value <reg_num>.
237 2. f.<reg_num> which has the value <reg_num>.
239 Each condition register has predefined names of the form:
240 1. cr<reg_num> which has the value <reg_num>.
241 2. cr.<reg_num> which has the value <reg_num>.
243 There are individual registers as well:
244 sp or r.sp has the value 1
245 rtoc or r.toc has the value 2
246 fpscr has the value 0
252 dsisr has the value 18
254 sdr1 has the value 25
255 srr0 has the value 26
256 srr1 has the value 27
258 The table is sorted. Suitable for searching by a binary search. */
260 static const struct pd_reg pre_defined_registers[] =
262 { "cr.0", 0 }, /* Condition Registers */
282 { "dar", 19 }, /* Data Access Register */
283 { "dec", 22 }, /* Decrementer */
284 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
286 { "f.0", 0 }, /* Floating point registers */
354 { "lr", 8 }, /* Link Register */
358 { "r.0", 0 }, /* General Purpose Registers */
391 { "r.sp", 1 }, /* Stack Pointer */
393 { "r.toc", 2 }, /* Pointer to the table of contents */
395 { "r0", 0 }, /* More general purpose registers */
428 { "rtoc", 2 }, /* Table of contents */
430 { "sdr1", 25 }, /* Storage Description Register 1 */
434 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
435 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
441 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
443 /* Given NAME, find the register number associated with that name, return
444 the integer value associated with the given name or -1 on failure. */
446 static int reg_name_search
447 PARAMS ((const struct pd_reg *, int, const char * name));
450 reg_name_search (regs, regcount, name)
451 const struct pd_reg *regs;
455 int middle, low, high;
463 middle = (low + high) / 2;
464 cmp = strcasecmp (name, regs[middle].name);
470 return regs[middle].value;
478 * Summary of register_name().
480 * in: Input_line_pointer points to 1st char of operand.
482 * out: A expressionS.
483 * The operand may have been a register: in this case, X_op == O_register,
484 * X_add_number is set to the register number, and truth is returned.
485 * Input_line_pointer->(next non-blank) char after operand, or is in its
490 register_name (expressionP)
491 expressionS *expressionP;
498 /* Find the spelling of the operand */
499 start = name = input_line_pointer;
500 if (name[0] == '%' && isalpha (name[1]))
501 name = ++input_line_pointer;
503 else if (!reg_names_p || !isalpha (name[0]))
506 c = get_symbol_end ();
507 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
509 /* look to see if it's in the register table */
512 expressionP->X_op = O_register;
513 expressionP->X_add_number = reg_number;
515 /* make the rest nice */
516 expressionP->X_add_symbol = NULL;
517 expressionP->X_op_symbol = NULL;
518 *input_line_pointer = c; /* put back the delimiting char */
523 /* reset the line as if we had not done anything */
524 *input_line_pointer = c; /* put back the delimiting char */
525 input_line_pointer = start; /* reset input_line pointer */
530 /* This function is called for each symbol seen in an expression. It
531 handles the special parsing which PowerPC assemblers are supposed
532 to use for condition codes. */
534 /* Whether to do the special parsing. */
535 static boolean cr_operand;
537 /* Names to recognize in a condition code. This table is sorted. */
538 static const struct pd_reg cr_names[] =
555 /* Parsing function. This returns non-zero if it recognized an
559 ppc_parse_name (name, expr)
568 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
573 expr->X_op = O_constant;
574 expr->X_add_number = val;
579 /* Local variables. */
581 /* The type of processor we are assembling for. This is one or more
582 of the PPC_OPCODE flags defined in opcode/ppc.h. */
583 static int ppc_cpu = 0;
585 /* The size of the processor we are assembling for. This is either
586 PPC_OPCODE_32 or PPC_OPCODE_64. */
587 static int ppc_size = PPC_OPCODE_32;
589 /* Opcode hash table. */
590 static struct hash_control *ppc_hash;
592 /* Macro hash table. */
593 static struct hash_control *ppc_macro_hash;
596 /* What type of shared library support to use */
597 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
599 /* Flags to set in the elf header */
600 static flagword ppc_flags = 0;
602 /* Whether this is Solaris or not. */
603 #ifdef TARGET_SOLARIS_COMMENT
604 #define SOLARIS_P true
606 #define SOLARIS_P false
609 static boolean msolaris = SOLARIS_P;
614 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
615 using a bunch of different sections. These assembler sections,
616 however, are all encompassed within the .text or .data sections of
617 the final output file. We handle this by using different
618 subsegments within these main segments. */
620 /* Next subsegment to allocate within the .text segment. */
621 static subsegT ppc_text_subsegment = 2;
623 /* Linked list of csects in the text section. */
624 static symbolS *ppc_text_csects;
626 /* Next subsegment to allocate within the .data segment. */
627 static subsegT ppc_data_subsegment = 2;
629 /* Linked list of csects in the data section. */
630 static symbolS *ppc_data_csects;
632 /* The current csect. */
633 static symbolS *ppc_current_csect;
635 /* The RS/6000 assembler uses a TOC which holds addresses of functions
636 and variables. Symbols are put in the TOC with the .tc pseudo-op.
637 A special relocation is used when accessing TOC entries. We handle
638 the TOC as a subsegment within the .data segment. We set it up if
639 we see a .toc pseudo-op, and save the csect symbol here. */
640 static symbolS *ppc_toc_csect;
642 /* The first frag in the TOC subsegment. */
643 static fragS *ppc_toc_frag;
645 /* The first frag in the first subsegment after the TOC in the .data
646 segment. NULL if there are no subsegments after the TOC. */
647 static fragS *ppc_after_toc_frag;
649 /* The current static block. */
650 static symbolS *ppc_current_block;
652 /* The COFF debugging section; set by md_begin. This is not the
653 .debug section, but is instead the secret BFD section which will
654 cause BFD to set the section number of a symbol to N_DEBUG. */
655 static asection *ppc_coff_debug_section;
657 #endif /* OBJ_XCOFF */
661 /* Various sections that we need for PE coff support. */
662 static segT ydata_section;
663 static segT pdata_section;
664 static segT reldata_section;
665 static segT rdata_section;
666 static segT tocdata_section;
668 /* The current section and the previous section. See ppc_previous. */
669 static segT ppc_previous_section;
670 static segT ppc_current_section;
675 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
678 #ifndef WORKING_DOT_WORD
679 const int md_short_jump_size = 4;
680 const int md_long_jump_size = 4;
684 CONST char *md_shortopts = "b:l:usm:K:VQ:";
686 CONST char *md_shortopts = "um:";
688 struct option md_longopts[] = {
689 {NULL, no_argument, NULL, 0}
691 size_t md_longopts_size = sizeof(md_longopts);
694 md_parse_option (c, arg)
701 /* -u means that any undefined symbols should be treated as
702 external, which is the default for gas anyhow. */
707 /* Solaris as takes -le (presumably for little endian). For completeness
708 sake, recognize -be also. */
709 if (strcmp (arg, "e") == 0)
711 target_big_endian = 0;
712 set_target_endian = 1;
720 if (strcmp (arg, "e") == 0)
722 target_big_endian = 1;
723 set_target_endian = 1;
731 /* Recognize -K PIC */
732 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
735 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
744 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
746 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
747 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
748 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
749 else if (strcmp (arg, "pwr") == 0)
750 ppc_cpu = PPC_OPCODE_POWER;
751 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
752 instructions that are holdovers from the Power. */
753 else if (strcmp (arg, "601") == 0)
754 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
755 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
756 Motorola PowerPC 603/604. */
757 else if (strcmp (arg, "ppc") == 0
758 || strcmp (arg, "ppc32") == 0
759 || strcmp (arg, "403") == 0
760 || strcmp (arg, "603") == 0
761 || strcmp (arg, "604") == 0)
762 ppc_cpu = PPC_OPCODE_PPC;
763 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
765 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
767 ppc_cpu = PPC_OPCODE_PPC;
768 ppc_size = PPC_OPCODE_64;
770 /* -mcom means assemble for the common intersection between Power
771 and PowerPC. At present, we just allow the union, rather
772 than the intersection. */
773 else if (strcmp (arg, "com") == 0)
774 ppc_cpu = PPC_OPCODE_COMMON;
775 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
776 else if (strcmp (arg, "any") == 0)
777 ppc_cpu = PPC_OPCODE_ANY;
779 else if (strcmp (arg, "regnames") == 0)
782 else if (strcmp (arg, "no-regnames") == 0)
786 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
787 else if (strcmp (arg, "relocatable") == 0)
789 shlib = SHILB_MRELOCATABLE;
790 ppc_flags |= EF_PPC_RELOCATABLE;
793 else if (strcmp (arg, "relocatable-lib") == 0)
795 shlib = SHILB_MRELOCATABLE;
796 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
799 /* -memb, set embedded bit */
800 else if (strcmp (arg, "emb") == 0)
801 ppc_flags |= EF_PPC_EMB;
803 /* -mlittle/-mbig set the endianess */
804 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
806 target_big_endian = 0;
807 set_target_endian = 1;
810 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
812 target_big_endian = 1;
813 set_target_endian = 1;
816 else if (strcmp (arg, "solaris") == 0)
819 ppc_comment_chars = ppc_solaris_comment_chars;
822 else if (strcmp (arg, "no-solaris") == 0)
825 ppc_comment_chars = ppc_eabi_comment_chars;
830 as_bad ("invalid switch -m%s", arg);
836 /* -V: SVR4 argument to print version ID. */
841 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
842 should be emitted or not. FIXME: Not implemented. */
846 /* Solaris takes -s to specify that .stabs go in a .stabs section,
847 rather than .stabs.excl, which is ignored by the linker.
848 FIXME: Not implemented. */
864 md_show_usage (stream)
870 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
871 -mpwr generate code for IBM POWER (RIOS1)\n\
872 -m601 generate code for Motorola PowerPC 601\n\
873 -mppc, -mppc32, -m403, -m603, -m604\n\
874 generate code for Motorola PowerPC 603/604\n\
875 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
876 -mcom generate code Power/PowerPC common instructions\n\
877 -many generate code for any architecture (PWR/PWRX/PPC)\n\
878 -mregnames Allow symbolic names for registers\n\
879 -mno-regnames Do not allow symbolic names for registers\n");
882 -mrelocatable support for GCC's -mrelocatble option\n\
883 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
884 -memb set PPC_EMB bit in ELF flags\n\
885 -mlittle, -mlittle-endian\n\
886 generate code for a little endian machine\n\
887 -mbig, -mbig-endian generate code for a big endian machine\n\
888 -msolaris generate code for Solaris\n\
889 -mno-solaris do not generate code for Solaris\n\
890 -V print assembler version number\n\
891 -Qy, -Qn ignored\n");
895 /* Set ppc_cpu if it is not already set. */
900 const char *default_os = TARGET_OS;
901 const char *default_cpu = TARGET_CPU;
905 if (strncmp (default_os, "aix", 3) == 0
906 && default_os[3] >= '4' && default_os[3] <= '9')
907 ppc_cpu = PPC_OPCODE_COMMON;
908 else if (strncmp (default_os, "aix3", 4) == 0)
909 ppc_cpu = PPC_OPCODE_POWER;
910 else if (strcmp (default_cpu, "rs6000") == 0)
911 ppc_cpu = PPC_OPCODE_POWER;
912 else if (strcmp (default_cpu, "powerpc") == 0
913 || strcmp (default_cpu, "powerpcle") == 0)
914 ppc_cpu = PPC_OPCODE_PPC;
916 as_fatal ("Unknown default cpu = %s, os = %s", default_cpu, default_os);
920 /* Figure out the BFD architecture to use. */
922 enum bfd_architecture
925 const char *default_cpu = TARGET_CPU;
928 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
929 return bfd_arch_powerpc;
930 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
931 return bfd_arch_rs6000;
932 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
934 if (strcmp (default_cpu, "rs6000") == 0)
935 return bfd_arch_rs6000;
936 else if (strcmp (default_cpu, "powerpc") == 0
937 || strcmp (default_cpu, "powerpcle") == 0)
938 return bfd_arch_powerpc;
941 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
942 return bfd_arch_unknown;
945 /* This function is called when the assembler starts up. It is called
946 after the options have been parsed and the output file has been
952 register const struct powerpc_opcode *op;
953 const struct powerpc_opcode *op_end;
954 const struct powerpc_macro *macro;
955 const struct powerpc_macro *macro_end;
956 boolean dup_insn = false;
961 /* Set the ELF flags if desired. */
962 if (ppc_flags && !msolaris)
963 bfd_set_private_flags (stdoutput, ppc_flags);
966 /* Insert the opcodes into a hash table. */
967 ppc_hash = hash_new ();
969 op_end = powerpc_opcodes + powerpc_num_opcodes;
970 for (op = powerpc_opcodes; op < op_end; op++)
972 know ((op->opcode & op->mask) == op->opcode);
974 if ((op->flags & ppc_cpu) != 0
975 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
976 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size))
980 retval = hash_insert (ppc_hash, op->name, (PTR) op);
981 if (retval != (const char *) NULL)
983 /* Ignore Power duplicates for -m601 */
984 if ((ppc_cpu & PPC_OPCODE_601) != 0
985 && (op->flags & PPC_OPCODE_POWER) != 0)
988 as_bad ("Internal assembler error for instruction %s", op->name);
994 /* Insert the macros into a hash table. */
995 ppc_macro_hash = hash_new ();
997 macro_end = powerpc_macros + powerpc_num_macros;
998 for (macro = powerpc_macros; macro < macro_end; macro++)
1000 if ((macro->flags & ppc_cpu) != 0)
1004 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1005 if (retval != (const char *) NULL)
1007 as_bad ("Internal assembler error for macro %s", macro->name);
1016 /* Tell the main code what the endianness is if it is not overidden by the user. */
1017 if (!set_target_endian)
1019 set_target_endian = 1;
1020 target_big_endian = PPC_BIG_ENDIAN;
1024 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1026 /* Create dummy symbols to serve as initial csects. This forces the
1027 text csects to precede the data csects. These symbols will not
1029 ppc_text_csects = symbol_make ("dummy\001");
1030 ppc_text_csects->sy_tc.within = ppc_text_csects;
1031 ppc_data_csects = symbol_make ("dummy\001");
1032 ppc_data_csects->sy_tc.within = ppc_data_csects;
1037 ppc_current_section = text_section;
1038 ppc_previous_section = 0;
1043 /* Insert an operand value into an instruction. */
1045 static unsigned long
1046 ppc_insert_operand (insn, operand, val, file, line)
1048 const struct powerpc_operand *operand;
1053 if (operand->bits != 32)
1058 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1060 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0
1061 && ppc_size == PPC_OPCODE_32)
1062 max = (1 << operand->bits) - 1;
1064 max = (1 << (operand->bits - 1)) - 1;
1065 min = - (1 << (operand->bits - 1));
1067 if (ppc_size == PPC_OPCODE_32)
1069 /* Some people write 32 bit hex constants with the sign
1070 extension done by hand. This shouldn't really be
1071 valid, but, to permit this code to assemble on a 64
1072 bit host, we sign extend the 32 bit value. */
1074 && (val & 0x80000000) != 0
1075 && (val & 0xffffffff) == val)
1084 max = (1 << operand->bits) - 1;
1088 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1093 if (test < (offsetT) min || test > (offsetT) max)
1096 "operand out of range (%s not between %ld and %ld)";
1099 sprint_value (buf, test);
1100 if (file == (char *) NULL)
1101 as_bad (err, buf, min, max);
1103 as_bad_where (file, line, err, buf, min, max);
1107 if (operand->insert)
1112 insn = (*operand->insert) (insn, (long) val, &errmsg);
1113 if (errmsg != (const char *) NULL)
1117 insn |= (((long) val & ((1 << operand->bits) - 1))
1125 /* Parse @got, etc. and return the desired relocation. */
1126 static bfd_reloc_code_real_type
1127 ppc_elf_suffix (str_p, exp_p)
1134 bfd_reloc_code_real_type reloc;
1142 struct map_bfd *ptr;
1144 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1146 static struct map_bfd mapping[] = {
1147 MAP ("l", BFD_RELOC_LO16),
1148 MAP ("h", BFD_RELOC_HI16),
1149 MAP ("ha", BFD_RELOC_HI16_S),
1150 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1151 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1152 MAP ("got", BFD_RELOC_16_GOTOFF),
1153 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1154 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1155 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1156 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1157 MAP ("plt", BFD_RELOC_24_PLT_PCREL),
1158 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1159 MAP ("copy", BFD_RELOC_PPC_COPY),
1160 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1161 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1162 MAP ("local", BFD_RELOC_PPC_LOCAL24PC),
1163 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1164 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1165 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1166 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1167 MAP ("sdarel", BFD_RELOC_GPREL16),
1168 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1169 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1170 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1171 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1172 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1173 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1174 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1175 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1176 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1177 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1178 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1179 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1180 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1181 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1182 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1183 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1184 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1185 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1186 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1187 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1188 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1190 { (char *)0, 0, BFD_RELOC_UNUSED }
1194 return BFD_RELOC_UNUSED;
1196 for (ch = *str, str2 = ident;
1197 (str2 < ident + sizeof (ident) - 1
1198 && (isalnum (ch) || ch == '@'));
1201 *str2++ = (islower (ch)) ? ch : tolower (ch);
1208 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1209 if (ch == ptr->string[0] && len == ptr->length && memcmp (ident, ptr->string, ptr->length) == 0)
1211 /* Now check for identifier@suffix+constant */
1212 if (*str == '-' || *str == '+')
1214 char *orig_line = input_line_pointer;
1215 expressionS new_exp;
1217 input_line_pointer = str;
1218 expression (&new_exp);
1219 if (new_exp.X_op == O_constant)
1221 exp_p->X_add_number += new_exp.X_add_number;
1222 str = input_line_pointer;
1225 if (&input_line_pointer != str_p)
1226 input_line_pointer = orig_line;
1233 return BFD_RELOC_UNUSED;
1236 /* Like normal .long/.short/.word, except support @got, etc. */
1237 /* clobbers input_line_pointer, checks */
1240 ppc_elf_cons (nbytes)
1241 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1244 bfd_reloc_code_real_type reloc;
1246 if (is_it_end_of_statement ())
1248 demand_empty_rest_of_line ();
1255 if (exp.X_op == O_symbol
1256 && *input_line_pointer == '@'
1257 && (reloc = ppc_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
1259 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1260 int size = bfd_get_reloc_size (reloc_howto);
1263 as_bad ("%s relocations do not fit in %d bytes\n", reloc_howto->name, nbytes);
1267 register char *p = frag_more ((int) nbytes);
1268 int offset = nbytes - size;
1270 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1274 emit_expr (&exp, (unsigned int) nbytes);
1276 while (*input_line_pointer++ == ',');
1278 input_line_pointer--; /* Put terminator back into stream. */
1279 demand_empty_rest_of_line ();
1282 /* Solaris pseduo op to change to the .rodata section. */
1287 char *save_line = input_line_pointer;
1288 static char section[] = ".rodata\n";
1290 /* Just pretend this is .section .rodata */
1291 input_line_pointer = section;
1292 obj_elf_section (xxx);
1294 input_line_pointer = save_line;
1297 /* Pseudo op to make file scope bss items */
1302 register char *name;
1306 register symbolS *symbolP;
1313 name = input_line_pointer;
1314 c = get_symbol_end ();
1316 /* just after name is now '\0' */
1317 p = input_line_pointer;
1320 if (*input_line_pointer != ',')
1322 as_bad ("Expected comma after symbol-name: rest of line ignored.");
1323 ignore_rest_of_line ();
1327 input_line_pointer++; /* skip ',' */
1328 if ((size = get_absolute_expression ()) < 0)
1330 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) size);
1331 ignore_rest_of_line ();
1335 /* The third argument to .lcomm is the alignment. */
1336 if (*input_line_pointer != ',')
1340 ++input_line_pointer;
1341 align = get_absolute_expression ();
1344 as_warn ("ignoring bad alignment");
1350 symbolP = symbol_find_or_make (name);
1353 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1355 as_bad ("Ignoring attempt to re-define symbol `%s'.",
1356 S_GET_NAME (symbolP));
1357 ignore_rest_of_line ();
1361 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1363 as_bad ("Length of .lcomm \"%s\" is already %ld. Not changed to %ld.",
1364 S_GET_NAME (symbolP),
1365 (long) S_GET_VALUE (symbolP),
1368 ignore_rest_of_line ();
1374 old_subsec = now_subseg;
1377 /* convert to a power of 2 alignment */
1378 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1381 as_bad ("Common alignment not a power of 2");
1382 ignore_rest_of_line ();
1389 record_alignment (bss_section, align2);
1390 subseg_set (bss_section, 0);
1392 frag_align (align2, 0, 0);
1393 if (S_GET_SEGMENT (symbolP) == bss_section)
1394 symbolP->sy_frag->fr_symbol = 0;
1395 symbolP->sy_frag = frag_now;
1396 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1399 S_SET_SIZE (symbolP, size);
1400 S_SET_SEGMENT (symbolP, bss_section);
1401 subseg_set (old_sec, old_subsec);
1402 demand_empty_rest_of_line ();
1405 /* Validate any relocations emitted for -mrelocatable, possibly adding
1406 fixups for word relocations in writable segments, so we can adjust
1409 ppc_elf_validate_fix (fixp, seg)
1413 if (fixp->fx_done || fixp->fx_pcrel)
1422 case SHILB_MRELOCATABLE:
1423 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1424 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1425 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1426 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1427 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1428 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1429 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1430 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1431 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1432 && strcmp (segment_name (seg), ".got2") != 0
1433 && strcmp (segment_name (seg), ".dtors") != 0
1434 && strcmp (segment_name (seg), ".ctors") != 0
1435 && strcmp (segment_name (seg), ".fixup") != 0
1436 && strcmp (segment_name (seg), ".stab") != 0
1437 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1438 && strcmp (segment_name (seg), ".ex_shared") != 0)
1440 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1441 || fixp->fx_r_type != BFD_RELOC_CTOR)
1443 as_bad_where (fixp->fx_file, fixp->fx_line,
1444 "Relocation cannot be done when using -mrelocatable");
1450 #endif /* OBJ_ELF */
1455 * Summary of parse_toc_entry().
1457 * in: Input_line_pointer points to the '[' in one of:
1459 * [toc] [tocv] [toc32] [toc64]
1461 * Anything else is an error of one kind or another.
1464 * return value: success or failure
1465 * toc_kind: kind of toc reference
1466 * input_line_pointer:
1467 * success: first char after the ']'
1468 * failure: unchanged
1472 * [toc] - rv == success, toc_kind = default_toc
1473 * [tocv] - rv == success, toc_kind = data_in_toc
1474 * [toc32] - rv == success, toc_kind = must_be_32
1475 * [toc64] - rv == success, toc_kind = must_be_64
1479 enum toc_size_qualifier
1481 default_toc, /* The toc cell constructed should be the system default size */
1482 data_in_toc, /* This is a direct reference to a toc cell */
1483 must_be_32, /* The toc cell constructed must be 32 bits wide */
1484 must_be_64 /* The toc cell constructed must be 64 bits wide */
1488 parse_toc_entry(toc_kind)
1489 enum toc_size_qualifier *toc_kind;
1494 enum toc_size_qualifier t;
1496 /* save the input_line_pointer */
1497 start = input_line_pointer;
1499 /* skip over the '[' , and whitespace */
1500 ++input_line_pointer;
1503 /* find the spelling of the operand */
1504 toc_spec = input_line_pointer;
1505 c = get_symbol_end ();
1507 if (strcmp(toc_spec, "toc") == 0)
1511 else if (strcmp(toc_spec, "tocv") == 0)
1515 else if (strcmp(toc_spec, "toc32") == 0)
1519 else if (strcmp(toc_spec, "toc64") == 0)
1525 as_bad ("syntax error: invalid toc specifier `%s'", toc_spec);
1526 *input_line_pointer = c; /* put back the delimiting char */
1527 input_line_pointer = start; /* reset input_line pointer */
1531 /* now find the ']' */
1532 *input_line_pointer = c; /* put back the delimiting char */
1534 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1535 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1539 as_bad ("syntax error: expected `]', found `%c'", c);
1540 input_line_pointer = start; /* reset input_line pointer */
1544 *toc_kind = t; /* set return value */
1550 /* We need to keep a list of fixups. We can't simply generate them as
1551 we go, because that would require us to first create the frag, and
1552 that would screw up references to ``.''. */
1558 bfd_reloc_code_real_type reloc;
1561 #define MAX_INSN_FIXUPS (5)
1563 /* This routine is called for each instruction to be assembled. */
1570 const struct powerpc_opcode *opcode;
1572 const unsigned char *opindex_ptr;
1576 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1581 bfd_reloc_code_real_type reloc;
1584 /* Get the opcode. */
1585 for (s = str; *s != '\0' && ! isspace (*s); s++)
1590 /* Look up the opcode in the hash table. */
1591 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1592 if (opcode == (const struct powerpc_opcode *) NULL)
1594 const struct powerpc_macro *macro;
1596 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1597 if (macro == (const struct powerpc_macro *) NULL)
1598 as_bad ("Unrecognized opcode: `%s'", str);
1600 ppc_macro (s, macro);
1605 insn = opcode->opcode;
1608 while (isspace (*str))
1611 /* PowerPC operands are just expressions. The only real issue is
1612 that a few operand types are optional. All cases which might use
1613 an optional operand separate the operands only with commas (in
1614 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1615 cases never have optional operands). There is never more than
1616 one optional operand for an instruction. So, before we start
1617 seriously parsing the operands, we check to see if we have an
1618 optional operand, and, if we do, we count the number of commas to
1619 see whether the operand should be omitted. */
1621 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1623 const struct powerpc_operand *operand;
1625 operand = &powerpc_operands[*opindex_ptr];
1626 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1628 unsigned int opcount;
1630 /* There is an optional operand. Count the number of
1631 commas in the input line. */
1638 while ((s = strchr (s, ',')) != (char *) NULL)
1645 /* If there are fewer operands in the line then are called
1646 for by the instruction, we want to skip the optional
1648 if (opcount < strlen (opcode->operands))
1655 /* Gather the operands. */
1659 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1661 const struct powerpc_operand *operand;
1667 if (next_opindex == 0)
1668 operand = &powerpc_operands[*opindex_ptr];
1671 operand = &powerpc_operands[next_opindex];
1677 /* If this is a fake operand, then we do not expect anything
1679 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1681 insn = (*operand->insert) (insn, 0L, &errmsg);
1682 if (errmsg != (const char *) NULL)
1687 /* If this is an optional operand, and we are skipping it, just
1689 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1692 if (operand->insert)
1694 insn = (*operand->insert) (insn, 0L, &errmsg);
1695 if (errmsg != (const char *) NULL)
1698 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1699 next_opindex = *opindex_ptr + 1;
1703 /* Gather the operand. */
1704 hold = input_line_pointer;
1705 input_line_pointer = str;
1708 if (*input_line_pointer == '[')
1710 /* We are expecting something like the second argument here:
1712 lwz r4,[toc].GS.0.static_int(rtoc)
1713 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1714 The argument following the `]' must be a symbol name, and the
1715 register must be the toc register: 'rtoc' or '2'
1717 The effect is to 0 as the displacement field
1718 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1719 the appropriate variation) reloc against it based on the symbol.
1720 The linker will build the toc, and insert the resolved toc offset.
1723 o The size of the toc entry is currently assumed to be
1724 32 bits. This should not be assumed to be a hard coded
1726 o In an effort to cope with a change from 32 to 64 bits,
1727 there are also toc entries that are specified to be
1728 either 32 or 64 bits:
1729 lwz r4,[toc32].GS.0.static_int(rtoc)
1730 lwz r4,[toc64].GS.0.static_int(rtoc)
1731 These demand toc entries of the specified size, and the
1732 instruction probably requires it.
1736 enum toc_size_qualifier toc_kind;
1737 bfd_reloc_code_real_type toc_reloc;
1739 /* go parse off the [tocXX] part */
1740 valid_toc = parse_toc_entry(&toc_kind);
1744 /* Note: message has already been issued. */
1745 /* FIXME: what sort of recovery should we do? */
1746 /* demand_rest_of_line(); return; ? */
1749 /* Now get the symbol following the ']' */
1755 /* In this case, we may not have seen the symbol yet, since */
1756 /* it is allowed to appear on a .extern or .globl or just be */
1757 /* a label in the .data section. */
1758 toc_reloc = BFD_RELOC_PPC_TOC16;
1761 /* 1. The symbol must be defined and either in the toc */
1762 /* section, or a global. */
1763 /* 2. The reloc generated must have the TOCDEFN flag set in */
1764 /* upper bit mess of the reloc type. */
1765 /* FIXME: It's a little confusing what the tocv qualifier can */
1766 /* be used for. At the very least, I've seen three */
1767 /* uses, only one of which I'm sure I can explain. */
1768 if (ex.X_op == O_symbol)
1770 assert (ex.X_add_symbol != NULL);
1771 if (ex.X_add_symbol->bsym->section != tocdata_section)
1773 as_bad("[tocv] symbol is not a toc symbol");
1777 toc_reloc = BFD_RELOC_PPC_TOC16;
1780 /* FIXME: these next two specifically specify 32/64 bit toc */
1781 /* entries. We don't support them today. Is this the */
1782 /* right way to say that? */
1783 toc_reloc = BFD_RELOC_UNUSED;
1784 as_bad ("Unimplemented toc32 expression modifier");
1787 /* FIXME: see above */
1788 toc_reloc = BFD_RELOC_UNUSED;
1789 as_bad ("Unimplemented toc64 expression modifier");
1793 "Unexpected return value [%d] from parse_toc_entry!\n",
1799 /* We need to generate a fixup for this expression. */
1800 if (fc >= MAX_INSN_FIXUPS)
1801 as_fatal ("too many fixups");
1803 fixups[fc].reloc = toc_reloc;
1804 fixups[fc].exp = ex;
1805 fixups[fc].opindex = *opindex_ptr;
1808 /* Ok. We've set up the fixup for the instruction. Now make it
1809 look like the constant 0 was found here */
1811 ex.X_op = O_constant;
1812 ex.X_add_number = 0;
1813 ex.X_add_symbol = NULL;
1814 ex.X_op_symbol = NULL;
1820 if (! register_name (&ex))
1822 if ((operand->flags & PPC_OPERAND_CR) != 0)
1829 str = input_line_pointer;
1830 input_line_pointer = hold;
1832 if (ex.X_op == O_illegal)
1833 as_bad ("illegal operand");
1834 else if (ex.X_op == O_absent)
1835 as_bad ("missing operand");
1836 else if (ex.X_op == O_register)
1838 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1841 else if (ex.X_op == O_constant)
1844 /* Allow @HA, @L, @H on constants. */
1845 char *orig_str = str;
1847 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1854 case BFD_RELOC_LO16:
1856 ex.X_add_number &= 0xffff;
1858 ex.X_add_number = (((ex.X_add_number & 0xffff)
1863 case BFD_RELOC_HI16:
1864 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1867 case BFD_RELOC_HI16_S:
1868 ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
1869 + ((ex.X_add_number >> 15) & 1));
1873 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1877 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1879 /* For the absoulte forms of branchs, convert the PC relative form back into
1881 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1885 case BFD_RELOC_PPC_B26:
1886 reloc = BFD_RELOC_PPC_BA26;
1888 case BFD_RELOC_PPC_B16:
1889 reloc = BFD_RELOC_PPC_BA16;
1891 case BFD_RELOC_PPC_B16_BRTAKEN:
1892 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
1894 case BFD_RELOC_PPC_B16_BRNTAKEN:
1895 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
1902 /* We need to generate a fixup for this expression. */
1903 if (fc >= MAX_INSN_FIXUPS)
1904 as_fatal ("too many fixups");
1905 fixups[fc].exp = ex;
1906 fixups[fc].opindex = 0;
1907 fixups[fc].reloc = reloc;
1910 #endif /* OBJ_ELF */
1914 /* We need to generate a fixup for this expression. */
1915 if (fc >= MAX_INSN_FIXUPS)
1916 as_fatal ("too many fixups");
1917 fixups[fc].exp = ex;
1918 fixups[fc].opindex = *opindex_ptr;
1919 fixups[fc].reloc = BFD_RELOC_UNUSED;
1928 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1936 /* The call to expression should have advanced str past any
1939 && (endc != ',' || *str != '\0'))
1941 as_bad ("syntax error; found `%c' but expected `%c'", *str, endc);
1949 while (isspace (*str))
1953 as_bad ("junk at end of line: `%s'", str);
1955 /* Write out the instruction. */
1957 md_number_to_chars (f, insn, 4);
1959 /* Create any fixups. At this point we do not use a
1960 bfd_reloc_code_real_type, but instead just use the
1961 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1962 handle fixups for any operand type, although that is admittedly
1963 not a very exciting feature. We pick a BFD reloc type in
1965 for (i = 0; i < fc; i++)
1967 const struct powerpc_operand *operand;
1969 operand = &powerpc_operands[fixups[i].opindex];
1970 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1972 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1980 size = bfd_get_reloc_size (reloc_howto);
1981 offset = target_big_endian ? (4 - size) : 0;
1983 if (size < 1 || size > 4)
1986 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
1987 &fixups[i].exp, reloc_howto->pc_relative,
1990 /* Turn off complaints that the addend is too large for things like
1992 switch (fixups[i].reloc)
1994 case BFD_RELOC_16_GOTOFF:
1995 case BFD_RELOC_PPC_TOC16:
1996 case BFD_RELOC_LO16:
1997 case BFD_RELOC_HI16:
1998 case BFD_RELOC_HI16_S:
1999 fixP->fx_no_overflow = 1;
2006 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2008 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2009 ((bfd_reloc_code_real_type)
2010 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2014 #ifndef WORKING_DOT_WORD
2015 /* Handle long and short jumps */
2017 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
2019 addressT from_addr, to_addr;
2027 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
2029 addressT from_addr, to_addr;
2037 /* Handle a macro. Gather all the operands, transform them as
2038 described by the macro, and call md_assemble recursively. All the
2039 operands are separated by commas; we don't accept parentheses
2040 around operands here. */
2043 ppc_macro (str, macro)
2045 const struct powerpc_macro *macro;
2056 /* Gather the users operands into the operands array. */
2061 if (count >= sizeof operands / sizeof operands[0])
2063 operands[count++] = s;
2064 s = strchr (s, ',');
2065 if (s == (char *) NULL)
2070 if (count != macro->operands)
2072 as_bad ("wrong number of operands");
2076 /* Work out how large the string must be (the size is unbounded
2077 because it includes user input). */
2079 format = macro->format;
2080 while (*format != '\0')
2089 arg = strtol (format + 1, &send, 10);
2090 know (send != format && arg >= 0 && arg < count);
2091 len += strlen (operands[arg]);
2096 /* Put the string together. */
2097 complete = s = (char *) alloca (len + 1);
2098 format = macro->format;
2099 while (*format != '\0')
2105 arg = strtol (format + 1, &send, 10);
2106 strcpy (s, operands[arg]);
2113 /* Assemble the constructed instruction. */
2114 md_assemble (complete);
2118 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2121 ppc_section_letter (letter, ptr_msg)
2128 *ptr_msg = "Bad .section directive: want a,w,x,e in string";
2133 ppc_section_word (ptr_str)
2136 if (strncmp (*ptr_str, "exclude", sizeof ("exclude")-1) == 0)
2138 *ptr_str += sizeof ("exclude")-1;
2146 ppc_section_type (ptr_str)
2149 if (strncmp (*ptr_str, "ordered", sizeof ("ordered")-1) == 0)
2151 *ptr_str += sizeof ("ordered")-1;
2159 ppc_section_flags (flags, attr, type)
2164 if (type == SHT_ORDERED)
2165 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2167 if (attr & SHF_EXCLUDE)
2168 flags |= SEC_EXCLUDE;
2172 #endif /* OBJ_ELF */
2175 /* Pseudo-op handling. */
2177 /* The .byte pseudo-op. This is similar to the normal .byte
2178 pseudo-op, but it can also take a single ASCII string. */
2184 if (*input_line_pointer != '\"')
2190 /* Gather characters. A real double quote is doubled. Unusual
2191 characters are not permitted. */
2192 ++input_line_pointer;
2197 c = *input_line_pointer++;
2201 if (*input_line_pointer != '\"')
2203 ++input_line_pointer;
2206 FRAG_APPEND_1_CHAR (c);
2209 demand_empty_rest_of_line ();
2214 /* XCOFF specific pseudo-op handling. */
2216 /* This is set if we are creating a .stabx symbol, since we don't want
2217 to handle symbol suffixes for such symbols. */
2218 static boolean ppc_stab_symbol;
2220 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2221 symbols in the .bss segment as though they were local common
2222 symbols, and uses a different smclas. */
2228 asection *current_seg = now_seg;
2229 subsegT current_subseg = now_subseg;
2235 symbolS *lcomm_sym = NULL;
2239 name = input_line_pointer;
2240 endc = get_symbol_end ();
2241 end_name = input_line_pointer;
2244 if (*input_line_pointer != ',')
2246 as_bad ("missing size");
2247 ignore_rest_of_line ();
2250 ++input_line_pointer;
2252 size = get_absolute_expression ();
2255 as_bad ("negative size");
2256 ignore_rest_of_line ();
2262 /* The third argument to .comm is the alignment. */
2263 if (*input_line_pointer != ',')
2267 ++input_line_pointer;
2268 align = get_absolute_expression ();
2271 as_warn ("ignoring bad alignment");
2290 /* The third argument to .lcomm appears to be the real local
2291 common symbol to create. References to the symbol named in
2292 the first argument are turned into references to the third
2294 if (*input_line_pointer != ',')
2296 as_bad ("missing real symbol name");
2297 ignore_rest_of_line ();
2300 ++input_line_pointer;
2302 lcomm_name = input_line_pointer;
2303 lcomm_endc = get_symbol_end ();
2305 lcomm_sym = symbol_find_or_make (lcomm_name);
2307 *input_line_pointer = lcomm_endc;
2311 sym = symbol_find_or_make (name);
2314 if (S_IS_DEFINED (sym)
2315 || S_GET_VALUE (sym) != 0)
2317 as_bad ("attempt to redefine symbol");
2318 ignore_rest_of_line ();
2322 record_alignment (bss_section, align);
2325 || ! S_IS_DEFINED (lcomm_sym))
2334 S_SET_EXTERNAL (sym);
2338 lcomm_sym->sy_tc.output = 1;
2339 def_sym = lcomm_sym;
2343 subseg_set (bss_section, 1);
2344 frag_align (align, 0, 0);
2346 def_sym->sy_frag = frag_now;
2347 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2348 def_size, (char *) NULL);
2350 S_SET_SEGMENT (def_sym, bss_section);
2351 def_sym->sy_tc.align = align;
2355 /* Align the size of lcomm_sym. */
2356 lcomm_sym->sy_frag->fr_offset =
2357 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
2358 &~ ((1 << align) - 1));
2359 if (align > lcomm_sym->sy_tc.align)
2360 lcomm_sym->sy_tc.align = align;
2365 /* Make sym an offset from lcomm_sym. */
2366 S_SET_SEGMENT (sym, bss_section);
2367 sym->sy_frag = lcomm_sym->sy_frag;
2368 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
2369 lcomm_sym->sy_frag->fr_offset += size;
2372 subseg_set (current_seg, current_subseg);
2374 demand_empty_rest_of_line ();
2377 /* The .csect pseudo-op. This switches us into a different
2378 subsegment. The first argument is a symbol whose value is the
2379 start of the .csect. In COFF, csect symbols get special aux
2380 entries defined by the x_csect field of union internal_auxent. The
2381 optional second argument is the alignment (the default is 2). */
2391 name = input_line_pointer;
2392 endc = get_symbol_end ();
2394 sym = symbol_find_or_make (name);
2396 *input_line_pointer = endc;
2398 if (S_GET_NAME (sym)[0] == '\0')
2400 /* An unnamed csect is assumed to be [PR]. */
2401 sym->sy_tc.class = XMC_PR;
2404 ppc_change_csect (sym);
2406 if (*input_line_pointer == ',')
2408 ++input_line_pointer;
2409 sym->sy_tc.align = get_absolute_expression ();
2412 demand_empty_rest_of_line ();
2415 /* Change to a different csect. */
2418 ppc_change_csect (sym)
2421 if (S_IS_DEFINED (sym))
2422 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
2429 /* This is a new csect. We need to look at the symbol class to
2430 figure out whether it should go in the text section or the
2433 switch (sym->sy_tc.class)
2443 S_SET_SEGMENT (sym, text_section);
2444 sym->sy_tc.subseg = ppc_text_subsegment;
2445 ++ppc_text_subsegment;
2446 list_ptr = &ppc_text_csects;
2455 if (ppc_toc_csect != NULL
2456 && ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
2458 S_SET_SEGMENT (sym, data_section);
2459 sym->sy_tc.subseg = ppc_data_subsegment;
2460 ++ppc_data_subsegment;
2461 list_ptr = &ppc_data_csects;
2467 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
2469 ppc_after_toc_frag = frag_now;
2471 sym->sy_frag = frag_now;
2472 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2474 sym->sy_tc.align = 2;
2475 sym->sy_tc.output = 1;
2476 sym->sy_tc.within = sym;
2478 for (list = *list_ptr;
2479 list->sy_tc.next != (symbolS *) NULL;
2480 list = list->sy_tc.next)
2482 list->sy_tc.next = sym;
2484 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2485 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2488 ppc_current_csect = sym;
2491 /* This function handles the .text and .data pseudo-ops. These
2492 pseudo-ops aren't really used by XCOFF; we implement them for the
2493 convenience of people who aren't used to XCOFF. */
2504 else if (type == 'd')
2509 sym = symbol_find_or_make (name);
2511 ppc_change_csect (sym);
2513 demand_empty_rest_of_line ();
2516 /* The .extern pseudo-op. We create an undefined symbol. */
2525 name = input_line_pointer;
2526 endc = get_symbol_end ();
2528 (void) symbol_find_or_make (name);
2530 *input_line_pointer = endc;
2532 demand_empty_rest_of_line ();
2535 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2545 name = input_line_pointer;
2546 endc = get_symbol_end ();
2548 sym = symbol_find_or_make (name);
2550 *input_line_pointer = endc;
2552 sym->sy_tc.output = 1;
2554 demand_empty_rest_of_line ();
2557 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2558 although I don't know why it bothers. */
2569 name = input_line_pointer;
2570 endc = get_symbol_end ();
2572 sym = symbol_find_or_make (name);
2574 *input_line_pointer = endc;
2576 if (*input_line_pointer != ',')
2578 as_bad ("missing rename string");
2579 ignore_rest_of_line ();
2582 ++input_line_pointer;
2584 sym->sy_tc.real_name = demand_copy_C_string (&len);
2586 demand_empty_rest_of_line ();
2589 /* The .stabx pseudo-op. This is similar to a normal .stabs
2590 pseudo-op, but slightly different. A sample is
2591 .stabx "main:F-1",.main,142,0
2592 The first argument is the symbol name to create. The second is the
2593 value, and the third is the storage class. The fourth seems to be
2594 always zero, and I am assuming it is the type. */
2605 name = demand_copy_C_string (&len);
2607 if (*input_line_pointer != ',')
2609 as_bad ("missing value");
2612 ++input_line_pointer;
2614 ppc_stab_symbol = true;
2615 sym = symbol_make (name);
2616 ppc_stab_symbol = false;
2618 sym->sy_tc.real_name = name;
2620 (void) expression (&exp);
2627 as_bad ("illegal .stabx expression; zero assumed");
2628 exp.X_add_number = 0;
2631 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2632 sym->sy_frag = &zero_address_frag;
2636 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2637 sym->sy_value = exp;
2641 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2642 sym->sy_frag = exp.X_add_symbol->sy_frag;
2647 /* The value is some complex expression. This will probably
2648 fail at some later point, but this is probably the right
2649 thing to do here. */
2650 sym->sy_value = exp;
2654 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2655 sym->bsym->flags |= BSF_DEBUGGING;
2657 if (*input_line_pointer != ',')
2659 as_bad ("missing class");
2662 ++input_line_pointer;
2664 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2666 if (*input_line_pointer != ',')
2668 as_bad ("missing type");
2671 ++input_line_pointer;
2673 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2675 sym->sy_tc.output = 1;
2677 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2678 sym->sy_tc.within = ppc_current_block;
2680 if (exp.X_op != O_symbol
2681 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2682 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2683 ppc_frob_label (sym);
2686 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2687 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2688 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2689 ppc_current_csect->sy_tc.within = sym;
2692 demand_empty_rest_of_line ();
2695 /* The .function pseudo-op. This takes several arguments. The first
2696 argument seems to be the external name of the symbol. The second
2697 argment seems to be the label for the start of the function. gcc
2698 uses the same name for both. I have no idea what the third and
2699 fourth arguments are meant to be. The optional fifth argument is
2700 an expression for the size of the function. In COFF this symbol
2701 gets an aux entry like that used for a csect. */
2704 ppc_function (ignore)
2713 name = input_line_pointer;
2714 endc = get_symbol_end ();
2716 /* Ignore any [PR] suffix. */
2717 name = ppc_canonicalize_symbol_name (name);
2718 s = strchr (name, '[');
2719 if (s != (char *) NULL
2720 && strcmp (s + 1, "PR]") == 0)
2723 ext_sym = symbol_find_or_make (name);
2725 *input_line_pointer = endc;
2727 if (*input_line_pointer != ',')
2729 as_bad ("missing symbol name");
2730 ignore_rest_of_line ();
2733 ++input_line_pointer;
2735 name = input_line_pointer;
2736 endc = get_symbol_end ();
2738 lab_sym = symbol_find_or_make (name);
2740 *input_line_pointer = endc;
2742 if (ext_sym != lab_sym)
2744 ext_sym->sy_value.X_op = O_symbol;
2745 ext_sym->sy_value.X_add_symbol = lab_sym;
2746 ext_sym->sy_value.X_op_symbol = NULL;
2747 ext_sym->sy_value.X_add_number = 0;
2750 if (ext_sym->sy_tc.class == -1)
2751 ext_sym->sy_tc.class = XMC_PR;
2752 ext_sym->sy_tc.output = 1;
2754 if (*input_line_pointer == ',')
2758 /* Ignore the third argument. */
2759 ++input_line_pointer;
2760 expression (&ignore);
2761 if (*input_line_pointer == ',')
2763 /* Ignore the fourth argument. */
2764 ++input_line_pointer;
2765 expression (&ignore);
2766 if (*input_line_pointer == ',')
2768 /* The fifth argument is the function size. */
2769 ++input_line_pointer;
2770 ext_sym->sy_tc.size = symbol_new ("L0\001",
2773 &zero_address_frag);
2774 pseudo_set (ext_sym->sy_tc.size);
2779 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2780 SF_SET_FUNCTION (ext_sym);
2781 SF_SET_PROCESS (ext_sym);
2782 coff_add_linesym (ext_sym);
2784 demand_empty_rest_of_line ();
2787 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2796 sym = symbol_make (".bf");
2797 S_SET_SEGMENT (sym, text_section);
2798 sym->sy_frag = frag_now;
2799 S_SET_VALUE (sym, frag_now_fix ());
2800 S_SET_STORAGE_CLASS (sym, C_FCN);
2802 coff_line_base = get_absolute_expression ();
2804 S_SET_NUMBER_AUXILIARY (sym, 1);
2805 SA_SET_SYM_LNNO (sym, coff_line_base);
2807 sym->sy_tc.output = 1;
2809 ppc_frob_label (sym);
2811 demand_empty_rest_of_line ();
2814 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2815 ".ef", except that the line number is absolute, not relative to the
2816 most recent ".bf" symbol. */
2824 sym = symbol_make (".ef");
2825 S_SET_SEGMENT (sym, text_section);
2826 sym->sy_frag = frag_now;
2827 S_SET_VALUE (sym, frag_now_fix ());
2828 S_SET_STORAGE_CLASS (sym, C_FCN);
2829 S_SET_NUMBER_AUXILIARY (sym, 1);
2830 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2831 sym->sy_tc.output = 1;
2833 ppc_frob_label (sym);
2835 demand_empty_rest_of_line ();
2838 /* The .bi and .ei pseudo-ops. These take a string argument and
2839 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2851 name = demand_copy_C_string (&len);
2853 /* The value of these symbols is actually file offset. Here we set
2854 the value to the index into the line number entries. In
2855 ppc_frob_symbols we set the fix_line field, which will cause BFD
2856 to do the right thing. */
2858 sym = symbol_make (name);
2859 /* obj-coff.c currently only handles line numbers correctly in the
2861 S_SET_SEGMENT (sym, text_section);
2862 S_SET_VALUE (sym, coff_n_line_nos);
2863 sym->bsym->flags |= BSF_DEBUGGING;
2865 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2866 sym->sy_tc.output = 1;
2868 for (look = symbol_rootP;
2869 (look != (symbolS *) NULL
2870 && (S_GET_STORAGE_CLASS (look) == C_FILE
2871 || S_GET_STORAGE_CLASS (look) == C_BINCL
2872 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2873 look = symbol_next (look))
2875 if (look != (symbolS *) NULL)
2877 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2878 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2881 demand_empty_rest_of_line ();
2884 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2885 There is one argument, which is a csect symbol. The value of the
2886 .bs symbol is the index of this csect symbol. */
2897 if (ppc_current_block != NULL)
2898 as_bad ("nested .bs blocks");
2900 name = input_line_pointer;
2901 endc = get_symbol_end ();
2903 csect = symbol_find_or_make (name);
2905 *input_line_pointer = endc;
2907 sym = symbol_make (".bs");
2908 S_SET_SEGMENT (sym, now_seg);
2909 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2910 sym->bsym->flags |= BSF_DEBUGGING;
2911 sym->sy_tc.output = 1;
2913 sym->sy_tc.within = csect;
2915 ppc_frob_label (sym);
2917 ppc_current_block = sym;
2919 demand_empty_rest_of_line ();
2922 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2930 if (ppc_current_block == NULL)
2931 as_bad (".es without preceding .bs");
2933 sym = symbol_make (".es");
2934 S_SET_SEGMENT (sym, now_seg);
2935 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2936 sym->bsym->flags |= BSF_DEBUGGING;
2937 sym->sy_tc.output = 1;
2939 ppc_frob_label (sym);
2941 ppc_current_block = NULL;
2943 demand_empty_rest_of_line ();
2946 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2955 sym = symbol_make (".bb");
2956 S_SET_SEGMENT (sym, text_section);
2957 sym->sy_frag = frag_now;
2958 S_SET_VALUE (sym, frag_now_fix ());
2959 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2961 S_SET_NUMBER_AUXILIARY (sym, 1);
2962 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2964 sym->sy_tc.output = 1;
2966 SF_SET_PROCESS (sym);
2968 ppc_frob_label (sym);
2970 demand_empty_rest_of_line ();
2973 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
2982 sym = symbol_make (".eb");
2983 S_SET_SEGMENT (sym, text_section);
2984 sym->sy_frag = frag_now;
2985 S_SET_VALUE (sym, frag_now_fix ());
2986 S_SET_STORAGE_CLASS (sym, C_BLOCK);
2987 S_SET_NUMBER_AUXILIARY (sym, 1);
2988 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2989 sym->sy_tc.output = 1;
2991 SF_SET_PROCESS (sym);
2993 ppc_frob_label (sym);
2995 demand_empty_rest_of_line ();
2998 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3009 name = demand_copy_C_string (&len);
3010 sym = symbol_make (name);
3011 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3012 sym->bsym->flags |= BSF_DEBUGGING;
3013 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3014 S_SET_VALUE (sym, 0);
3015 sym->sy_tc.output = 1;
3017 ppc_frob_label (sym);
3019 demand_empty_rest_of_line ();
3022 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3030 sym = symbol_make (".ec");
3031 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3032 sym->bsym->flags |= BSF_DEBUGGING;
3033 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3034 S_SET_VALUE (sym, 0);
3035 sym->sy_tc.output = 1;
3037 ppc_frob_label (sym);
3039 demand_empty_rest_of_line ();
3042 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3048 if (ppc_toc_csect != (symbolS *) NULL)
3049 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
3056 subseg = ppc_data_subsegment;
3057 ++ppc_data_subsegment;
3059 subseg_new (segment_name (data_section), subseg);
3060 ppc_toc_frag = frag_now;
3062 sym = symbol_find_or_make ("TOC[TC0]");
3063 sym->sy_frag = frag_now;
3064 S_SET_SEGMENT (sym, data_section);
3065 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3066 sym->sy_tc.subseg = subseg;
3067 sym->sy_tc.output = 1;
3068 sym->sy_tc.within = sym;
3070 ppc_toc_csect = sym;
3072 for (list = ppc_data_csects;
3073 list->sy_tc.next != (symbolS *) NULL;
3074 list = list->sy_tc.next)
3076 list->sy_tc.next = sym;
3078 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3079 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
3082 ppc_current_csect = ppc_toc_csect;
3084 demand_empty_rest_of_line ();
3087 /* The AIX assembler automatically aligns the operands of a .long or
3088 .short pseudo-op, and we want to be compatible. */
3091 ppc_xcoff_cons (log_size)
3094 frag_align (log_size, 0, 0);
3095 record_alignment (now_seg, log_size);
3096 cons (1 << log_size);
3099 #endif /* OBJ_XCOFF */
3101 /* The .tc pseudo-op. This is used when generating either XCOFF or
3102 ELF. This takes two or more arguments.
3104 When generating XCOFF output, the first argument is the name to
3105 give to this location in the toc; this will be a symbol with class
3106 TC. The rest of the arguments are 4 byte values to actually put at
3107 this location in the TOC; often there is just one more argument, a
3108 relocateable symbol reference.
3110 When not generating XCOFF output, the arguments are the same, but
3111 the first argument is simply ignored. */
3119 /* Define the TOC symbol name. */
3125 if (ppc_toc_csect == (symbolS *) NULL
3126 || ppc_toc_csect != ppc_current_csect)
3128 as_bad (".tc not in .toc section");
3129 ignore_rest_of_line ();
3133 name = input_line_pointer;
3134 endc = get_symbol_end ();
3136 sym = symbol_find_or_make (name);
3138 *input_line_pointer = endc;
3140 if (S_IS_DEFINED (sym))
3144 label = ppc_current_csect->sy_tc.within;
3145 if (label->sy_tc.class != XMC_TC0)
3147 as_bad (".tc with no label");
3148 ignore_rest_of_line ();
3152 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3153 label->sy_frag = sym->sy_frag;
3154 S_SET_VALUE (label, S_GET_VALUE (sym));
3156 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3157 ++input_line_pointer;
3162 S_SET_SEGMENT (sym, now_seg);
3163 sym->sy_frag = frag_now;
3164 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3165 sym->sy_tc.class = XMC_TC;
3166 sym->sy_tc.output = 1;
3168 ppc_frob_label (sym);
3171 #else /* ! defined (OBJ_XCOFF) */
3173 /* Skip the TOC symbol name. */
3174 while (is_part_of_name (*input_line_pointer)
3175 || *input_line_pointer == '['
3176 || *input_line_pointer == ']'
3177 || *input_line_pointer == '{'
3178 || *input_line_pointer == '}')
3179 ++input_line_pointer;
3181 /* Align to a four byte boundary. */
3182 frag_align (2, 0, 0);
3183 record_alignment (now_seg, 2);
3185 #endif /* ! defined (OBJ_XCOFF) */
3187 if (*input_line_pointer != ',')
3188 demand_empty_rest_of_line ();
3191 ++input_line_pointer;
3198 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3200 /* Set the current section. */
3202 ppc_set_current_section (new)
3205 ppc_previous_section = ppc_current_section;
3206 ppc_current_section = new;
3209 /* pseudo-op: .previous
3210 behaviour: toggles the current section with the previous section.
3212 warnings: "No previous section"
3215 ppc_previous(ignore)
3220 if (ppc_previous_section == NULL)
3222 as_warn("No previous section to return to. Directive ignored.");
3226 subseg_set(ppc_previous_section, 0);
3228 ppc_set_current_section(ppc_previous_section);
3231 /* pseudo-op: .pdata
3232 behaviour: predefined read only data section
3236 initial: .section .pdata "adr3"
3237 a - don't know -- maybe a misprint
3238 d - initialized data
3240 3 - double word aligned (that would be 4 byte boundary)
3243 Tag index tables (also known as the function table) for exception
3244 handling, debugging, etc.
3251 if (pdata_section == 0)
3253 pdata_section = subseg_new (".pdata", 0);
3255 bfd_set_section_flags (stdoutput, pdata_section,
3256 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3257 | SEC_READONLY | SEC_DATA ));
3259 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3263 pdata_section = subseg_new(".pdata", 0);
3265 ppc_set_current_section(pdata_section);
3268 /* pseudo-op: .ydata
3269 behaviour: predefined read only data section
3273 initial: .section .ydata "drw3"
3274 a - don't know -- maybe a misprint
3275 d - initialized data
3277 3 - double word aligned (that would be 4 byte boundary)
3279 Tag tables (also known as the scope table) for exception handling,
3286 if (ydata_section == 0)
3288 ydata_section = subseg_new (".ydata", 0);
3289 bfd_set_section_flags (stdoutput, ydata_section,
3290 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3291 | SEC_READONLY | SEC_DATA ));
3293 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3297 ydata_section = subseg_new (".ydata", 0);
3299 ppc_set_current_section(ydata_section);
3302 /* pseudo-op: .reldata
3303 behaviour: predefined read write data section
3304 double word aligned (4-byte)
3305 FIXME: relocation is applied to it
3306 FIXME: what's the difference between this and .data?
3309 initial: .section .reldata "drw3"
3310 d - initialized data
3313 3 - double word aligned (that would be 8 byte boundary)
3316 Like .data, but intended to hold data subject to relocation, such as
3317 function descriptors, etc.
3323 if (reldata_section == 0)
3325 reldata_section = subseg_new (".reldata", 0);
3327 bfd_set_section_flags (stdoutput, reldata_section,
3328 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
3331 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3335 reldata_section = subseg_new (".reldata", 0);
3337 ppc_set_current_section(reldata_section);
3340 /* pseudo-op: .rdata
3341 behaviour: predefined read only data section
3345 initial: .section .rdata "dr3"
3346 d - initialized data
3348 3 - double word aligned (that would be 4 byte boundary)
3354 if (rdata_section == 0)
3356 rdata_section = subseg_new (".rdata", 0);
3357 bfd_set_section_flags (stdoutput, rdata_section,
3358 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3359 | SEC_READONLY | SEC_DATA ));
3361 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3365 rdata_section = subseg_new (".rdata", 0);
3367 ppc_set_current_section(rdata_section);
3370 /* pseudo-op: .ualong
3371 behaviour: much like .int, with the exception that no alignment is
3373 FIXME: test the alignment statement
3385 /* pseudo-op: .znop <symbol name>
3386 behaviour: Issue a nop instruction
3387 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3388 the supplied symbol name.
3390 warnings: Missing symbol name
3397 const struct powerpc_opcode *opcode;
3403 /* Strip out the symbol name */
3411 symbol_name = input_line_pointer;
3412 c = get_symbol_end ();
3414 name = xmalloc (input_line_pointer - symbol_name + 1);
3415 strcpy (name, symbol_name);
3417 sym = symbol_find_or_make (name);
3419 *input_line_pointer = c;
3423 /* Look up the opcode in the hash table. */
3424 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3426 /* stick in the nop */
3427 insn = opcode->opcode;
3429 /* Write out the instruction. */
3431 md_number_to_chars (f, insn, 4);
3433 f - frag_now->fr_literal,
3438 BFD_RELOC_16_GOT_PCREL);
3451 register char *name;
3455 register symbolS *symbolP;
3458 name = input_line_pointer;
3459 c = get_symbol_end ();
3461 /* just after name is now '\0' */
3462 p = input_line_pointer;
3465 if (*input_line_pointer != ',')
3467 as_bad ("Expected comma after symbol-name: rest of line ignored.");
3468 ignore_rest_of_line ();
3472 input_line_pointer++; /* skip ',' */
3473 if ((temp = get_absolute_expression ()) < 0)
3475 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
3476 ignore_rest_of_line ();
3482 /* The third argument to .comm is the alignment. */
3483 if (*input_line_pointer != ',')
3487 ++input_line_pointer;
3488 align = get_absolute_expression ();
3491 as_warn ("ignoring bad alignment");
3498 symbolP = symbol_find_or_make (name);
3501 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
3503 as_bad ("Ignoring attempt to re-define symbol `%s'.",
3504 S_GET_NAME (symbolP));
3505 ignore_rest_of_line ();
3509 if (S_GET_VALUE (symbolP))
3511 if (S_GET_VALUE (symbolP) != (valueT) temp)
3512 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
3513 S_GET_NAME (symbolP),
3514 (long) S_GET_VALUE (symbolP),
3519 S_SET_VALUE (symbolP, (valueT) temp);
3520 S_SET_EXTERNAL (symbolP);
3523 demand_empty_rest_of_line ();
3527 * implement the .section pseudo op:
3528 * .section name {, "flags"}
3530 * | +--- optional flags: 'b' for bss
3532 * +-- section name 'l' for lib
3536 * 'd' (apparently m88k for data)
3538 * But if the argument is not a quoted string, treat it as a
3539 * subsegment number.
3541 * FIXME: this is a copy of the section processing from obj-coff.c, with
3542 * additions/changes for the moto-pas assembler support. There are three
3545 * FIXME: I just noticed this. This doesn't work at all really. It it
3546 * setting bits that bfd probably neither understands or uses. The
3547 * correct approach (?) will have to incorporate extra fields attached
3548 * to the section to hold the system specific stuff. (krk)
3551 * 'a' - unknown - referred to in documentation, but no definition supplied
3552 * 'c' - section has code
3553 * 'd' - section has initialized data
3554 * 'u' - section has uninitialized data
3555 * 'i' - section contains directives (info)
3556 * 'n' - section can be discarded
3557 * 'R' - remove section at link time
3559 * Section Protection:
3560 * 'r' - section is readable
3561 * 'w' - section is writeable
3562 * 'x' - section is executable
3563 * 's' - section is sharable
3565 * Section Alignment:
3566 * '0' - align to byte boundary
3567 * '1' - align to halfword undary
3568 * '2' - align to word boundary
3569 * '3' - align to doubleword boundary
3570 * '4' - align to quadword boundary
3571 * '5' - align to 32 byte boundary
3572 * '6' - align to 64 byte boundary
3577 ppc_pe_section (ignore)
3580 /* Strip out the section name */
3589 section_name = input_line_pointer;
3590 c = get_symbol_end ();
3592 name = xmalloc (input_line_pointer - section_name + 1);
3593 strcpy (name, section_name);
3595 *input_line_pointer = c;
3600 flags = SEC_NO_FLAGS;
3602 if (strcmp (name, ".idata$2") == 0)
3606 else if (strcmp (name, ".idata$3") == 0)
3610 else if (strcmp (name, ".idata$4") == 0)
3614 else if (strcmp (name, ".idata$5") == 0)
3618 else if (strcmp (name, ".idata$6") == 0)
3623 align = 4; /* default alignment to 16 byte boundary */
3625 if (*input_line_pointer == ',')
3627 ++input_line_pointer;
3629 if (*input_line_pointer != '"')
3630 exp = get_absolute_expression ();
3633 ++input_line_pointer;
3634 while (*input_line_pointer != '"'
3635 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3637 switch (*input_line_pointer)
3639 /* Section Contents */
3640 case 'a': /* unknown */
3641 as_bad ("Unsupported section attribute -- 'a'");
3643 case 'c': /* code section */
3646 case 'd': /* section has initialized data */
3649 case 'u': /* section has uninitialized data */
3650 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3654 case 'i': /* section contains directives (info) */
3655 /* FIXME: This is IMAGE_SCN_LNK_INFO
3657 flags |= SEC_HAS_CONTENTS;
3659 case 'n': /* section can be discarded */
3662 case 'R': /* Remove section at link time */
3663 flags |= SEC_NEVER_LOAD;
3666 /* Section Protection */
3667 case 'r': /* section is readable */
3668 flags |= IMAGE_SCN_MEM_READ;
3670 case 'w': /* section is writeable */
3671 flags |= IMAGE_SCN_MEM_WRITE;
3673 case 'x': /* section is executable */
3674 flags |= IMAGE_SCN_MEM_EXECUTE;
3676 case 's': /* section is sharable */
3677 flags |= IMAGE_SCN_MEM_SHARED;
3680 /* Section Alignment */
3681 case '0': /* align to byte boundary */
3682 flags |= IMAGE_SCN_ALIGN_1BYTES;
3685 case '1': /* align to halfword boundary */
3686 flags |= IMAGE_SCN_ALIGN_2BYTES;
3689 case '2': /* align to word boundary */
3690 flags |= IMAGE_SCN_ALIGN_4BYTES;
3693 case '3': /* align to doubleword boundary */
3694 flags |= IMAGE_SCN_ALIGN_8BYTES;
3697 case '4': /* align to quadword boundary */
3698 flags |= IMAGE_SCN_ALIGN_16BYTES;
3701 case '5': /* align to 32 byte boundary */
3702 flags |= IMAGE_SCN_ALIGN_32BYTES;
3705 case '6': /* align to 64 byte boundary */
3706 flags |= IMAGE_SCN_ALIGN_64BYTES;
3711 as_bad("unknown section attribute '%c'",
3712 *input_line_pointer);
3715 ++input_line_pointer;
3717 if (*input_line_pointer == '"')
3718 ++input_line_pointer;
3722 sec = subseg_new (name, (subsegT) exp);
3724 ppc_set_current_section(sec);
3726 if (flags != SEC_NO_FLAGS)
3728 if (! bfd_set_section_flags (stdoutput, sec, flags))
3729 as_bad ("error setting flags for \"%s\": %s",
3730 bfd_section_name (stdoutput, sec),
3731 bfd_errmsg (bfd_get_error ()));
3734 bfd_set_section_alignment(stdoutput, sec, align);
3739 ppc_pe_function (ignore)
3746 name = input_line_pointer;
3747 endc = get_symbol_end ();
3749 ext_sym = symbol_find_or_make (name);
3751 *input_line_pointer = endc;
3753 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3754 SF_SET_FUNCTION (ext_sym);
3755 SF_SET_PROCESS (ext_sym);
3756 coff_add_linesym (ext_sym);
3758 demand_empty_rest_of_line ();
3762 ppc_pe_tocd (ignore)
3765 if (tocdata_section == 0)
3767 tocdata_section = subseg_new (".tocd", 0);
3768 /* FIXME: section flags won't work */
3769 bfd_set_section_flags (stdoutput, tocdata_section,
3770 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3771 | SEC_READONLY | SEC_DATA ));
3773 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3777 rdata_section = subseg_new (".tocd", 0);
3780 ppc_set_current_section(tocdata_section);
3782 demand_empty_rest_of_line ();
3785 /* Don't adjust TOC relocs to use the section symbol. */
3788 ppc_pe_fix_adjustable (fix)
3791 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3798 /* XCOFF specific symbol and file handling. */
3800 /* Canonicalize the symbol name. We use the to force the suffix, if
3801 any, to use square brackets, and to be in upper case. */
3804 ppc_canonicalize_symbol_name (name)
3809 if (ppc_stab_symbol)
3812 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3826 for (s++; *s != '\0' && *s != brac; s++)
3830 if (*s == '\0' || s[1] != '\0')
3831 as_bad ("bad symbol suffix");
3839 /* Set the class of a symbol based on the suffix, if any. This is
3840 called whenever a new symbol is created. */
3843 ppc_symbol_new_hook (sym)
3848 sym->sy_tc.next = NULL;
3849 sym->sy_tc.output = 0;
3850 sym->sy_tc.class = -1;
3851 sym->sy_tc.real_name = NULL;
3852 sym->sy_tc.subseg = 0;
3853 sym->sy_tc.align = 0;
3854 sym->sy_tc.size = NULL;
3855 sym->sy_tc.within = NULL;
3857 if (ppc_stab_symbol)
3860 s = strchr (S_GET_NAME (sym), '[');
3861 if (s == (const char *) NULL)
3863 /* There is no suffix. */
3872 if (strcmp (s, "BS]") == 0)
3873 sym->sy_tc.class = XMC_BS;
3876 if (strcmp (s, "DB]") == 0)
3877 sym->sy_tc.class = XMC_DB;
3878 else if (strcmp (s, "DS]") == 0)
3879 sym->sy_tc.class = XMC_DS;
3882 if (strcmp (s, "GL]") == 0)
3883 sym->sy_tc.class = XMC_GL;
3886 if (strcmp (s, "PR]") == 0)
3887 sym->sy_tc.class = XMC_PR;
3890 if (strcmp (s, "RO]") == 0)
3891 sym->sy_tc.class = XMC_RO;
3892 else if (strcmp (s, "RW]") == 0)
3893 sym->sy_tc.class = XMC_RW;
3896 if (strcmp (s, "SV]") == 0)
3897 sym->sy_tc.class = XMC_SV;
3900 if (strcmp (s, "TC]") == 0)
3901 sym->sy_tc.class = XMC_TC;
3902 else if (strcmp (s, "TI]") == 0)
3903 sym->sy_tc.class = XMC_TI;
3904 else if (strcmp (s, "TB]") == 0)
3905 sym->sy_tc.class = XMC_TB;
3906 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3907 sym->sy_tc.class = XMC_TC0;
3910 if (strcmp (s, "UA]") == 0)
3911 sym->sy_tc.class = XMC_UA;
3912 else if (strcmp (s, "UC]") == 0)
3913 sym->sy_tc.class = XMC_UC;
3916 if (strcmp (s, "XO]") == 0)
3917 sym->sy_tc.class = XMC_XO;
3921 if (sym->sy_tc.class == -1)
3922 as_bad ("Unrecognized symbol suffix");
3925 /* Set the class of a label based on where it is defined. This
3926 handles symbols without suffixes. Also, move the symbol so that it
3927 follows the csect symbol. */
3930 ppc_frob_label (sym)
3933 if (ppc_current_csect != (symbolS *) NULL)
3935 if (sym->sy_tc.class == -1)
3936 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
3938 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3939 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
3941 ppc_current_csect->sy_tc.within = sym;
3945 /* This variable is set by ppc_frob_symbol if any absolute symbols are
3946 seen. It tells ppc_adjust_symtab whether it needs to look through
3949 static boolean ppc_saw_abs;
3951 /* Change the name of a symbol just before writing it out. Set the
3952 real name if the .rename pseudo-op was used. Otherwise, remove any
3953 class suffix. Return 1 if the symbol should not be included in the
3957 ppc_frob_symbol (sym)
3960 static symbolS *ppc_last_function;
3961 static symbolS *set_end;
3963 /* Discard symbols that should not be included in the output symbol
3965 if (! sym->sy_used_in_reloc
3966 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
3967 || (! S_IS_EXTERNAL (sym)
3968 && ! sym->sy_tc.output
3969 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
3972 if (sym->sy_tc.real_name != (char *) NULL)
3973 S_SET_NAME (sym, sym->sy_tc.real_name);
3979 name = S_GET_NAME (sym);
3980 s = strchr (name, '[');
3981 if (s != (char *) NULL)
3987 snew = xmalloc (len + 1);
3988 memcpy (snew, name, len);
3991 S_SET_NAME (sym, snew);
3995 if (set_end != (symbolS *) NULL)
3997 SA_SET_SYM_ENDNDX (set_end, sym);
4001 if (SF_GET_FUNCTION (sym))
4003 if (ppc_last_function != (symbolS *) NULL)
4004 as_bad ("two .function pseudo-ops with no intervening .ef");
4005 ppc_last_function = sym;
4006 if (sym->sy_tc.size != (symbolS *) NULL)
4008 resolve_symbol_value (sym->sy_tc.size);
4009 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
4012 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4013 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4015 if (ppc_last_function == (symbolS *) NULL)
4016 as_bad (".ef with no preceding .function");
4019 set_end = ppc_last_function;
4020 ppc_last_function = NULL;
4022 /* We don't have a C_EFCN symbol, but we need to force the
4023 COFF backend to believe that it has seen one. */
4024 coff_last_function = NULL;
4028 if (! S_IS_EXTERNAL (sym)
4029 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
4030 && S_GET_STORAGE_CLASS (sym) != C_FILE
4031 && S_GET_STORAGE_CLASS (sym) != C_FCN
4032 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4033 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4034 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4035 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4036 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4037 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4038 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4040 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4041 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4044 union internal_auxent *a;
4046 /* Create a csect aux. */
4047 i = S_GET_NUMBER_AUXILIARY (sym);
4048 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4049 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
4050 if (sym->sy_tc.class == XMC_TC0)
4052 /* This is the TOC table. */
4053 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4054 a->x_csect.x_scnlen.l = 0;
4055 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4057 else if (sym->sy_tc.subseg != 0)
4059 /* This is a csect symbol. x_scnlen is the size of the
4061 if (sym->sy_tc.next == (symbolS *) NULL)
4062 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4063 S_GET_SEGMENT (sym))
4064 - S_GET_VALUE (sym));
4067 resolve_symbol_value (sym->sy_tc.next);
4068 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
4069 - S_GET_VALUE (sym));
4071 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
4073 else if (S_GET_SEGMENT (sym) == bss_section)
4075 /* This is a common symbol. */
4076 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
4077 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
4078 if (S_IS_EXTERNAL (sym))
4079 sym->sy_tc.class = XMC_RW;
4081 sym->sy_tc.class = XMC_BS;
4083 else if (S_GET_SEGMENT (sym) == absolute_section)
4085 /* This is an absolute symbol. The csect will be created by
4086 ppc_adjust_symtab. */
4088 a->x_csect.x_smtyp = XTY_LD;
4089 if (sym->sy_tc.class == -1)
4090 sym->sy_tc.class = XMC_XO;
4092 else if (! S_IS_DEFINED (sym))
4094 /* This is an external symbol. */
4095 a->x_csect.x_scnlen.l = 0;
4096 a->x_csect.x_smtyp = XTY_ER;
4098 else if (sym->sy_tc.class == XMC_TC)
4102 /* This is a TOC definition. x_scnlen is the size of the
4104 next = symbol_next (sym);
4105 while (next->sy_tc.class == XMC_TC0)
4106 next = symbol_next (next);
4107 if (next == (symbolS *) NULL
4108 || next->sy_tc.class != XMC_TC)
4110 if (ppc_after_toc_frag == (fragS *) NULL)
4111 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4113 - S_GET_VALUE (sym));
4115 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4116 - S_GET_VALUE (sym));
4120 resolve_symbol_value (next);
4121 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4122 - S_GET_VALUE (sym));
4124 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4130 /* This is a normal symbol definition. x_scnlen is the
4131 symbol index of the containing csect. */
4132 if (S_GET_SEGMENT (sym) == text_section)
4133 csect = ppc_text_csects;
4134 else if (S_GET_SEGMENT (sym) == data_section)
4135 csect = ppc_data_csects;
4139 /* Skip the initial dummy symbol. */
4140 csect = csect->sy_tc.next;
4142 if (csect == (symbolS *) NULL)
4144 as_warn ("warning: symbol %s has no csect", S_GET_NAME (sym));
4145 a->x_csect.x_scnlen.l = 0;
4149 while (csect->sy_tc.next != (symbolS *) NULL)
4151 resolve_symbol_value (csect->sy_tc.next);
4152 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
4154 csect = csect->sy_tc.next;
4157 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4158 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
4160 a->x_csect.x_smtyp = XTY_LD;
4163 a->x_csect.x_parmhash = 0;
4164 a->x_csect.x_snhash = 0;
4165 if (sym->sy_tc.class == -1)
4166 a->x_csect.x_smclas = XMC_PR;
4168 a->x_csect.x_smclas = sym->sy_tc.class;
4169 a->x_csect.x_stab = 0;
4170 a->x_csect.x_snstab = 0;
4172 /* Don't let the COFF backend resort these symbols. */
4173 sym->bsym->flags |= BSF_NOT_AT_END;
4175 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4177 /* We want the value to be the symbol index of the referenced
4178 csect symbol. BFD will do that for us if we set the right
4181 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
4182 coffsymbol (sym->bsym)->native->fix_value = 1;
4184 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4189 /* The value is the offset from the enclosing csect. */
4190 block = sym->sy_tc.within;
4191 csect = block->sy_tc.within;
4192 resolve_symbol_value (csect);
4193 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4195 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4196 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4198 /* We want the value to be a file offset into the line numbers.
4199 BFD will do that for us if we set the right flags. We have
4200 already set the value correctly. */
4201 coffsymbol (sym->bsym)->native->fix_line = 1;
4207 /* Adjust the symbol table. This creates csect symbols for all
4208 absolute symbols. */
4211 ppc_adjust_symtab ()
4218 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4222 union internal_auxent *a;
4224 if (S_GET_SEGMENT (sym) != absolute_section)
4227 csect = symbol_create (".abs[XO]", absolute_section,
4228 S_GET_VALUE (sym), &zero_address_frag);
4229 csect->bsym->value = S_GET_VALUE (sym);
4230 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4231 i = S_GET_NUMBER_AUXILIARY (csect);
4232 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4233 a = &coffsymbol (csect->bsym)->native[i + 1].u.auxent;
4234 a->x_csect.x_scnlen.l = 0;
4235 a->x_csect.x_smtyp = XTY_SD;
4236 a->x_csect.x_parmhash = 0;
4237 a->x_csect.x_snhash = 0;
4238 a->x_csect.x_smclas = XMC_XO;
4239 a->x_csect.x_stab = 0;
4240 a->x_csect.x_snstab = 0;
4242 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4244 i = S_GET_NUMBER_AUXILIARY (sym);
4245 a = &coffsymbol (sym->bsym)->native[i].u.auxent;
4246 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4247 coffsymbol (sym->bsym)->native[i].fix_scnlen = 1;
4250 ppc_saw_abs = false;
4253 /* Set the VMA for a section. This is called on all the sections in
4257 ppc_frob_section (sec)
4260 static bfd_size_type vma = 0;
4262 bfd_set_section_vma (stdoutput, sec, vma);
4263 vma += bfd_section_size (stdoutput, sec);
4266 #endif /* OBJ_XCOFF */
4268 /* Turn a string in input_line_pointer into a floating point constant
4269 of type type, and store the appropriate bytes in *litp. The number
4270 of LITTLENUMS emitted is stored in *sizep . An error message is
4271 returned, or NULL on OK. */
4274 md_atof (type, litp, sizep)
4280 LITTLENUM_TYPE words[4];
4296 return "bad call to md_atof";
4299 t = atof_ieee (input_line_pointer, type, words);
4301 input_line_pointer = t;
4305 if (target_big_endian)
4307 for (i = 0; i < prec; i++)
4309 md_number_to_chars (litp, (valueT) words[i], 2);
4315 for (i = prec - 1; i >= 0; i--)
4317 md_number_to_chars (litp, (valueT) words[i], 2);
4325 /* Write a value out to the object file, using the appropriate
4329 md_number_to_chars (buf, val, n)
4334 if (target_big_endian)
4335 number_to_chars_bigendian (buf, val, n);
4337 number_to_chars_littleendian (buf, val, n);
4340 /* Align a section (I don't know why this is machine dependent). */
4343 md_section_align (seg, addr)
4347 int align = bfd_get_section_alignment (stdoutput, seg);
4349 return ((addr + (1 << align) - 1) & (-1 << align));
4352 /* We don't have any form of relaxing. */
4355 md_estimate_size_before_relax (fragp, seg)
4363 /* Convert a machine dependent frag. We never generate these. */
4366 md_convert_frag (abfd, sec, fragp)
4374 /* We have no need to default values of symbols. */
4378 md_undefined_symbol (name)
4384 /* Functions concerning relocs. */
4386 /* The location from which a PC relative jump should be calculated,
4387 given a PC relative reloc. */
4390 md_pcrel_from_section (fixp, sec)
4395 if (fixp->fx_addsy != (symbolS *) NULL
4396 && (! S_IS_DEFINED (fixp->fx_addsy)
4397 || TC_FORCE_RELOCATION_SECTION (fixp, sec)))
4401 return fixp->fx_frag->fr_address + fixp->fx_where;
4406 /* This is called to see whether a fixup should be adjusted to use a
4407 section symbol. We take the opportunity to change a fixup against
4408 a symbol in the TOC subsegment into a reloc against the
4409 corresponding .tc symbol. */
4412 ppc_fix_adjustable (fix)
4417 resolve_symbol_value (fix->fx_addsy);
4418 val = S_GET_VALUE (fix->fx_addsy);
4419 if (ppc_toc_csect != (symbolS *) NULL
4420 && fix->fx_addsy != (symbolS *) NULL
4421 && fix->fx_addsy != ppc_toc_csect
4422 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4423 && val >= ppc_toc_frag->fr_address
4424 && (ppc_after_toc_frag == (fragS *) NULL
4425 || val < ppc_after_toc_frag->fr_address))
4429 for (sy = symbol_next (ppc_toc_csect);
4430 sy != (symbolS *) NULL;
4431 sy = symbol_next (sy))
4433 if (sy->sy_tc.class == XMC_TC0)
4435 if (sy->sy_tc.class != XMC_TC)
4437 resolve_symbol_value (sy);
4438 if (val == S_GET_VALUE (sy))
4441 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4446 as_bad_where (fix->fx_file, fix->fx_line,
4447 "symbol in .toc does not match any .tc");
4450 /* Possibly adjust the reloc to be against the csect. */
4451 if (fix->fx_addsy != (symbolS *) NULL
4452 && fix->fx_addsy->sy_tc.subseg == 0
4453 && fix->fx_addsy->sy_tc.class != XMC_TC0
4454 && fix->fx_addsy->sy_tc.class != XMC_TC
4455 && S_GET_SEGMENT (fix->fx_addsy) != bss_section)
4459 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4460 csect = ppc_text_csects;
4461 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4462 csect = ppc_data_csects;
4466 /* Skip the initial dummy symbol. */
4467 csect = csect->sy_tc.next;
4469 if (csect != (symbolS *) NULL)
4471 while (csect->sy_tc.next != (symbolS *) NULL
4472 && (csect->sy_tc.next->sy_frag->fr_address
4473 <= fix->fx_addsy->sy_frag->fr_address))
4475 /* If the csect address equals the symbol value, then we
4476 have to look through the full symbol table to see
4477 whether this is the csect we want. Note that we will
4478 only get here if the csect has zero length. */
4479 if ((csect->sy_frag->fr_address
4480 == fix->fx_addsy->sy_frag->fr_address)
4481 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4485 for (scan = csect->sy_next;
4487 scan = scan->sy_next)
4489 if (scan->sy_tc.subseg != 0)
4491 if (scan == fix->fx_addsy)
4495 /* If we found the symbol before the next csect
4496 symbol, then this is the csect we want. */
4497 if (scan == fix->fx_addsy)
4501 csect = csect->sy_tc.next;
4504 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4505 - csect->sy_frag->fr_address);
4506 fix->fx_addsy = csect;
4510 /* Adjust a reloc against a .lcomm symbol to be against the base
4512 if (fix->fx_addsy != (symbolS *) NULL
4513 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4514 && ! S_IS_EXTERNAL (fix->fx_addsy))
4516 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol);
4517 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4518 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
4519 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
4525 /* A reloc from one csect to another must be kept. The assembler
4526 will, of course, keep relocs between sections, and it will keep
4527 absolute relocs, but we need to force it to keep PC relative relocs
4528 between two csects in the same section. */
4531 ppc_force_relocation (fix)
4534 /* At this point fix->fx_addsy should already have been converted to
4535 a csect symbol. If the csect does not include the fragment, then
4536 we need to force the relocation. */
4538 && fix->fx_addsy != NULL
4539 && fix->fx_addsy->sy_tc.subseg != 0
4540 && (fix->fx_addsy->sy_frag->fr_address > fix->fx_frag->fr_address
4541 || (fix->fx_addsy->sy_tc.next != NULL
4542 && (fix->fx_addsy->sy_tc.next->sy_frag->fr_address
4543 <= fix->fx_frag->fr_address))))
4549 #endif /* OBJ_XCOFF */
4551 /* See whether a symbol is in the TOC section. */
4554 ppc_is_toc_sym (sym)
4558 return sym->sy_tc.class == XMC_TC;
4560 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4564 /* Apply a fixup to the object code. This is called for all the
4565 fixups we generated by the call to fix_new_exp, above. In the call
4566 above we used a reloc code which was the largest legal reloc code
4567 plus the operand index. Here we undo that to recover the operand
4568 index. At this point all symbol values should be fully resolved,
4569 and we attempt to completely resolve the reloc. If we can not do
4570 that, we determine the correct reloc code and put it back in the
4574 md_apply_fix3 (fixp, valuep, seg)
4581 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4582 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4583 doing this relocation the code in write.c is going to call
4584 bfd_install_relocation, which is also going to use the symbol
4585 value. That means that if the reloc is fully resolved we want to
4586 use *valuep since bfd_install_relocation is not being used.
4587 However, if the reloc is not fully resolved we do not want to use
4588 *valuep, and must use fx_offset instead. However, if the reloc
4589 is PC relative, we do want to use *valuep since it includes the
4590 result of md_pcrel_from. This is confusing. */
4592 if (fixp->fx_addsy == (symbolS *) NULL)
4597 else if (fixp->fx_pcrel)
4601 value = fixp->fx_offset;
4602 if (fixp->fx_subsy != (symbolS *) NULL)
4604 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4605 value -= S_GET_VALUE (fixp->fx_subsy);
4608 /* We can't actually support subtracting a symbol. */
4609 as_bad_where (fixp->fx_file, fixp->fx_line,
4610 "expression too complex");
4615 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4618 const struct powerpc_operand *operand;
4622 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4624 operand = &powerpc_operands[opindex];
4627 /* It appears that an instruction like
4629 when LC..1 is not a TOC symbol does not generate a reloc. It
4630 uses the offset of LC..1 within its csect. However, .long
4631 LC..1 will generate a reloc. I can't find any documentation
4632 on how these cases are to be distinguished, so this is a wild
4633 guess. These cases are generated by gcc -mminimal-toc. */
4634 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4635 && operand->bits == 16
4636 && operand->shift == 0
4637 && operand->insert == NULL
4638 && fixp->fx_addsy != NULL
4639 && fixp->fx_addsy->sy_tc.subseg != 0
4640 && fixp->fx_addsy->sy_tc.class != XMC_TC
4641 && fixp->fx_addsy->sy_tc.class != XMC_TC0
4642 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4644 value = fixp->fx_offset;
4649 /* Fetch the instruction, insert the fully resolved operand
4650 value, and stuff the instruction back again. */
4651 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4652 if (target_big_endian)
4653 insn = bfd_getb32 ((unsigned char *) where);
4655 insn = bfd_getl32 ((unsigned char *) where);
4656 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4657 fixp->fx_file, fixp->fx_line);
4658 if (target_big_endian)
4659 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4661 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4665 /* Nothing else to do here. */
4669 /* Determine a BFD reloc value based on the operand information.
4670 We are only prepared to turn a few of the operands into
4672 FIXME: We need to handle the DS field at the very least.
4673 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4674 there should be a new field in the operand table. */
4675 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4676 && operand->bits == 26
4677 && operand->shift == 0)
4678 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4679 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4680 && operand->bits == 16
4681 && operand->shift == 0)
4682 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4683 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4684 && operand->bits == 26
4685 && operand->shift == 0)
4686 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4687 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4688 && operand->bits == 16
4689 && operand->shift == 0)
4690 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4691 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4692 && operand->bits == 16
4693 && operand->shift == 0
4694 && operand->insert == NULL
4695 && fixp->fx_addsy != NULL
4696 && ppc_is_toc_sym (fixp->fx_addsy))
4699 if (target_big_endian)
4700 fixp->fx_where += 2;
4701 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4708 /* Use expr_symbol_where to see if this is an expression
4710 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
4711 as_bad_where (fixp->fx_file, fixp->fx_line,
4712 "unresolved expression that must be resolved");
4714 as_bad_where (fixp->fx_file, fixp->fx_line,
4715 "unsupported relocation type");
4723 ppc_elf_validate_fix (fixp, seg);
4725 switch (fixp->fx_r_type)
4728 case BFD_RELOC_CTOR:
4730 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4734 case BFD_RELOC_32_PCREL:
4735 case BFD_RELOC_32_BASEREL:
4736 case BFD_RELOC_PPC_EMB_NADDR32:
4737 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4741 case BFD_RELOC_LO16:
4742 case BFD_RELOC_HI16:
4743 case BFD_RELOC_HI16_S:
4745 case BFD_RELOC_GPREL16:
4746 case BFD_RELOC_16_GOT_PCREL:
4747 case BFD_RELOC_16_GOTOFF:
4748 case BFD_RELOC_LO16_GOTOFF:
4749 case BFD_RELOC_HI16_GOTOFF:
4750 case BFD_RELOC_HI16_S_GOTOFF:
4751 case BFD_RELOC_LO16_BASEREL:
4752 case BFD_RELOC_HI16_BASEREL:
4753 case BFD_RELOC_HI16_S_BASEREL:
4754 case BFD_RELOC_PPC_EMB_NADDR16:
4755 case BFD_RELOC_PPC_EMB_NADDR16_LO:
4756 case BFD_RELOC_PPC_EMB_NADDR16_HI:
4757 case BFD_RELOC_PPC_EMB_NADDR16_HA:
4758 case BFD_RELOC_PPC_EMB_SDAI16:
4759 case BFD_RELOC_PPC_EMB_SDA2REL:
4760 case BFD_RELOC_PPC_EMB_SDA2I16:
4761 case BFD_RELOC_PPC_EMB_RELSEC16:
4762 case BFD_RELOC_PPC_EMB_RELST_LO:
4763 case BFD_RELOC_PPC_EMB_RELST_HI:
4764 case BFD_RELOC_PPC_EMB_RELST_HA:
4765 case BFD_RELOC_PPC_EMB_RELSDA:
4766 case BFD_RELOC_PPC_TOC16:
4768 as_bad_where (fixp->fx_file, fixp->fx_line,
4769 "cannot emit PC relative %s relocation%s%s",
4770 bfd_get_reloc_code_name (fixp->fx_r_type),
4771 fixp->fx_addsy != NULL ? " against " : "",
4772 (fixp->fx_addsy != NULL
4773 ? S_GET_NAME (fixp->fx_addsy)
4776 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4780 /* Because SDA21 modifies the register field, the size is set to 4
4781 bytes, rather than 2, so offset it here appropriately */
4782 case BFD_RELOC_PPC_EMB_SDA21:
4786 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
4787 + ((target_big_endian) ? 2 : 0),
4795 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4799 case BFD_RELOC_24_PLT_PCREL:
4800 case BFD_RELOC_PPC_LOCAL24PC:
4801 if (!fixp->fx_pcrel)
4808 "Gas failure, reloc value %d\n", fixp->fx_r_type);
4815 fixp->fx_addnumber = value;
4817 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4818 fixp->fx_addnumber = 0;
4822 fixp->fx_addnumber = 0;
4824 /* We want to use the offset within the data segment of the
4825 symbol, not the actual VMA of the symbol. */
4826 fixp->fx_addnumber =
4827 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4835 /* Generate a reloc for a fixup. */
4838 tc_gen_reloc (seg, fixp)
4844 reloc = (arelent *) xmalloc (sizeof (arelent));
4846 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
4847 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
4848 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
4849 if (reloc->howto == (reloc_howto_type *) NULL)
4851 as_bad_where (fixp->fx_file, fixp->fx_line,
4852 "reloc %d not supported by object file format", (int)fixp->fx_r_type);
4855 reloc->addend = fixp->fx_addnumber;