1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994 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
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "opcode/ppc.h"
32 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
34 /* FIXME: This should be handled in a different way. */
35 extern int target_big_endian
;
37 static void ppc_set_cpu
PARAMS ((void));
38 static unsigned long ppc_insert_operand
39 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
40 offsetT val
, char *file
, unsigned int line
));
41 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
42 static void ppc_byte
PARAMS ((int));
43 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
44 static void ppc_tc
PARAMS ((int));
46 static void ppc_comm
PARAMS ((int));
47 static void ppc_bb
PARAMS ((int));
48 static void ppc_bf
PARAMS ((int));
49 static void ppc_biei
PARAMS ((int));
50 static void ppc_bs
PARAMS ((int));
51 static void ppc_eb
PARAMS ((int));
52 static void ppc_ef
PARAMS ((int));
53 static void ppc_es
PARAMS ((int));
54 static void ppc_csect
PARAMS ((int));
55 static void ppc_function
PARAMS ((int));
56 static void ppc_extern
PARAMS ((int));
57 static void ppc_lglobl
PARAMS ((int));
58 static void ppc_stabx
PARAMS ((int));
59 static void ppc_rename
PARAMS ((int));
60 static void ppc_toc
PARAMS ((int));
63 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
64 static void ppc_elf_cons
PARAMS ((int));
65 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
68 /* Generic assembler global variables which must be defined by all
71 /* Characters which always start a comment. */
72 const char comment_chars
[] = "#";
74 /* Characters which start a comment at the beginning of a line. */
75 const char line_comment_chars
[] = "#";
77 /* Characters which may be used to separate multiple commands on a
79 const char line_separator_chars
[] = ";";
81 /* Characters which are used to indicate an exponent in a floating
83 const char EXP_CHARS
[] = "eE";
85 /* Characters which mean that a number is a floating point constant,
87 const char FLT_CHARS
[] = "dD";
89 /* The target specific pseudo-ops which we support. */
91 const pseudo_typeS md_pseudo_table
[] =
93 /* Pseudo-ops which must be overridden. */
94 { "byte", ppc_byte
, 0 },
97 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
98 legitimately belong in the obj-*.c file. However, XCOFF is based
99 on COFF, and is only implemented for the RS/6000. We just use
100 obj-coff.c, and add what we need here. */
101 { "comm", ppc_comm
, 0 },
102 { "lcomm", ppc_comm
, 1 },
105 { "bi", ppc_biei
, 0 },
107 { "csect", ppc_csect
, 0 },
110 { "ei", ppc_biei
, 1 },
112 { "extern", ppc_extern
, 0 },
113 { "function", ppc_function
, 0 },
114 { "lglobl", ppc_lglobl
, 0 },
115 { "rename", ppc_rename
, 0 },
116 { "stabx", ppc_stabx
, 0 },
117 { "toc", ppc_toc
, 0 },
120 { "long", ppc_elf_cons
, 4 },
121 { "word", ppc_elf_cons
, 2 },
122 { "short", ppc_elf_cons
, 2 },
125 /* This pseudo-op is used even when not generating XCOFF output. */
131 /* Local variables. */
133 /* The type of processor we are assembling for. This is one or more
134 of the PPC_OPCODE flags defined in opcode/ppc.h. */
135 static int ppc_cpu
= 0;
137 /* The size of the processor we are assembling for. This is either
138 PPC_OPCODE_32 or PPC_OPCODE_64. */
139 static int ppc_size
= PPC_OPCODE_32
;
141 /* Opcode hash table. */
142 static struct hash_control
*ppc_hash
;
144 /* Macro hash table. */
145 static struct hash_control
*ppc_macro_hash
;
148 /* Whether to warn about non PC relative relocations that aren't
149 in the .got2 section. */
150 static boolean mrelocatable
= false;
155 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
156 using a bunch of different sections. These assembler sections,
157 however, are all encompassed within the .text or .data sections of
158 the final output file. We handle this by using different
159 subsegments within these main segments. */
161 /* Next subsegment to allocate within the .text segment. */
162 static subsegT ppc_text_subsegment
= 2;
164 /* Linked list of csects in the text section. */
165 static symbolS
*ppc_text_csects
;
167 /* Next subsegment to allocate within the .data segment. */
168 static subsegT ppc_data_subsegment
= 2;
170 /* Linked list of csects in the data section. */
171 static symbolS
*ppc_data_csects
;
173 /* The current csect. */
174 static symbolS
*ppc_current_csect
;
176 /* The RS/6000 assembler uses a TOC which holds addresses of functions
177 and variables. Symbols are put in the TOC with the .tc pseudo-op.
178 A special relocation is used when accessing TOC entries. We handle
179 the TOC as a subsegment within the .data segment. We set it up if
180 we see a .toc pseudo-op, and save the csect symbol here. */
181 static symbolS
*ppc_toc_csect
;
183 /* The first frag in the TOC subsegment. */
184 static fragS
*ppc_toc_frag
;
186 /* The first frag in the first subsegment after the TOC in the .data
187 segment. NULL if there are no subsegments after the TOC. */
188 static fragS
*ppc_after_toc_frag
;
190 /* The current static block. */
191 static symbolS
*ppc_current_block
;
193 /* The COFF debugging section; set by md_begin. This is not the
194 .debug section, but is instead the secret BFD section which will
195 cause BFD to set the section number of a symbol to N_DEBUG. */
196 static asection
*ppc_coff_debug_section
;
198 /* The size of the .debug section. */
199 static bfd_size_type ppc_debug_name_section_size
;
201 #endif /* OBJ_COFF */
204 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
207 #ifndef WORKING_DOT_WORD
208 const int md_short_jump_size
= 4;
209 const int md_long_jump_size
= 4;
213 CONST
char *md_shortopts
= "um:VQ:";
215 CONST
char *md_shortopts
= "um:";
217 struct option md_longopts
[] = {
218 {NULL
, no_argument
, NULL
, 0}
220 size_t md_longopts_size
= sizeof(md_longopts
);
223 md_parse_option (c
, arg
)
230 /* -u means that any undefined symbols should be treated as
231 external, which is the default for gas anyhow. */
235 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
237 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
238 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
239 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
240 else if (strcmp (arg
, "pwr") == 0)
241 ppc_cpu
= PPC_OPCODE_POWER
;
242 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
243 ignore the option for now, but we should really use it to permit
244 instructions defined on the 601 that are not part of the standard
245 PowerPC architecture (mostly holdovers from the POWER). */
246 else if (strcmp (arg
, "601") == 0)
247 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
248 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
249 Motorola PowerPC 603/604. */
250 else if (strcmp (arg
, "ppc") == 0
251 || strcmp (arg
, "ppc32") == 0
252 || strcmp (arg
, "403") == 0
253 || strcmp (arg
, "603") == 0
254 || strcmp (arg
, "604") == 0)
255 ppc_cpu
= PPC_OPCODE_PPC
;
256 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
258 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
260 ppc_cpu
= PPC_OPCODE_PPC
;
261 ppc_size
= PPC_OPCODE_64
;
263 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
264 else if (strcmp (arg
, "any") == 0)
265 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
268 /* -mrelocatable -- warn about initializations that require relocation */
269 else if (strcmp (arg
, "relocatable") == 0)
272 /* -mlittle/-mbig set the endianess */
273 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
274 target_big_endian
= 0;
276 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
277 target_big_endian
= 1;
281 as_bad ("invalid switch -m%s", arg
);
287 /* -V: SVR4 argument to print version ID. */
292 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
293 should be emitted or not. FIXME: Not implemented. */
306 md_show_usage (stream
)
312 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
313 -mpwr generate code for IBM POWER (RIOS1)\n\
314 -m601 generate code for Motorola PowerPC 601\n\
315 -mppc, -mppc32, -m403, -m603, -m604\n\
316 generate code for Motorola PowerPC 603/604\n\
317 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
318 -many generate code for any architecture (PWR/PWRX/PPC)\n");
321 -mrelocatable support for GCC's -mrelocatble option\n\
322 -mlittle, -mlittle-endian\n\
323 generate code for a little endian machine\n\
324 -mbig, -mbig-endian generate code for a big endian machine\n\
325 -V print assembler version number\n\
326 -Qy, -Qn ignored\n");
330 /* Set ppc_cpu if it is not already set. */
335 const char *default_cpu
= TARGET_CPU
;
339 if (strcmp (default_cpu
, "rs6000") == 0)
340 ppc_cpu
= PPC_OPCODE_POWER
;
341 else if (strcmp (default_cpu
, "powerpc") == 0
342 || strcmp (default_cpu
, "powerpcle") == 0)
343 ppc_cpu
= PPC_OPCODE_PPC
;
345 as_fatal ("Unknown default cpu = %s", default_cpu
);
349 /* Figure out the BFD architecture to use. */
351 enum bfd_architecture
356 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
357 return bfd_arch_powerpc
;
358 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
359 return bfd_arch_rs6000
;
361 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
364 /* This function is called when the assembler starts up. It is called
365 after the options have been parsed and the output file has been
371 register const struct powerpc_opcode
*op
;
372 const struct powerpc_opcode
*op_end
;
373 const struct powerpc_macro
*macro
;
374 const struct powerpc_macro
*macro_end
;
379 /* Set the -mrelocatable flag bit */
381 bfd_set_private_flags (stdoutput
, EF_PPC_RELOCATABLE
);
384 /* Insert the opcodes into a hash table. */
385 ppc_hash
= hash_new ();
387 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
388 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
390 know ((op
->opcode
& op
->mask
) == op
->opcode
);
392 if ((op
->flags
& ppc_cpu
) != 0
393 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
394 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
398 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
399 if (retval
!= (const char *) NULL
)
401 /* We permit a duplication of the mfdec instruction on
402 the 601, because it seems to have one value on the
403 601 and a different value on other PowerPC
404 processors. It's easier to permit a duplication than
405 to define a new instruction type flag. When using
406 -many, the comparison instructions are a harmless
408 if (strcmp (retval
, "exists") != 0
409 || (((ppc_cpu
& PPC_OPCODE_601
) == 0
410 || strcmp (op
->name
, "mfdec") != 0)
411 && (ppc_cpu
!= (PPC_OPCODE_POWER
414 || (strcmp (op
->name
, "cmpli") != 0
415 && strcmp (op
->name
, "cmpi") != 0
416 && strcmp (op
->name
, "cmp") != 0
417 && strcmp (op
->name
, "cmpl") != 0))))
423 /* Insert the macros into a hash table. */
424 ppc_macro_hash
= hash_new ();
426 macro_end
= powerpc_macros
+ powerpc_num_macros
;
427 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
429 if ((macro
->flags
& ppc_cpu
) != 0)
433 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
434 if (retval
!= (const char *) NULL
)
439 /* Tell the main code what the endianness is. */
440 target_big_endian
= PPC_BIG_ENDIAN
;
443 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
445 /* Create dummy symbols to serve as initial csects. This forces the
446 text csects to precede the data csects. These symbols will not
448 ppc_text_csects
= symbol_make ("dummy\001");
449 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
450 ppc_data_csects
= symbol_make ("dummy\001");
451 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
455 /* Insert an operand value into an instruction. */
458 ppc_insert_operand (insn
, operand
, val
, file
, line
)
460 const struct powerpc_operand
*operand
;
465 if (operand
->bits
!= 32)
470 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
472 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
473 && ppc_size
== PPC_OPCODE_32
)
474 max
= (1 << operand
->bits
) - 1;
476 max
= (1 << (operand
->bits
- 1)) - 1;
477 min
= - (1 << (operand
->bits
- 1));
481 max
= (1 << operand
->bits
) - 1;
485 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
490 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
493 "operand out of range (%s not between %ld and %ld)";
496 sprint_value (buf
, test
);
497 if (file
== (char *) NULL
)
498 as_warn (err
, buf
, min
, max
);
500 as_warn_where (file
, line
, err
, buf
, min
, max
);
509 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
510 if (errmsg
!= (const char *) NULL
)
514 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
521 /* Parse @got, etc. and return the desired relocation. */
522 static bfd_reloc_code_real_type
523 ppc_elf_suffix (str_p
)
529 return BFD_RELOC_UNUSED
;
531 if (strncmp (str
, "@GOT", 4) == 0 || strncmp (str
, "@got", 4) == 0)
534 return BFD_RELOC_PPC_TOC16
;
536 else if (strncmp (str
, "@L", 2) == 0 || strncmp (str
, "@l", 2) == 0)
539 return BFD_RELOC_LO16
;
541 else if (strncmp (str
, "@HA", 3) == 0 || strncmp (str
, "@ha", 3) == 0)
544 return BFD_RELOC_HI16_S
;
546 else if (strncmp (str
, "@H", 2) == 0 || strncmp (str
, "@h", 2) == 0)
549 return BFD_RELOC_HI16
;
551 else if (strncmp (str
, "@sdarel", 7) == 0 || strncmp (str
, "@sdarel", 7) == 0)
554 return BFD_RELOC_GPREL16
;
556 else if (strncmp (str
, "@FIXUP", 6) == 0 || strncmp (str
, "@fixup", 6) == 0)
559 return BFD_RELOC_CTOR
; /* synonym for BFD_RELOC_32 that doesn't get */
560 } /* warnings with -mrelocatable */
562 return BFD_RELOC_UNUSED
;
565 /* Like normal .long/.short/.word, except support @got, etc. */
566 /* clobbers input_line_pointer, checks */
569 ppc_elf_cons (nbytes
)
570 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
573 bfd_reloc_code_real_type reloc
;
575 if (is_it_end_of_statement ())
577 demand_empty_rest_of_line ();
585 && exp
.X_op
== O_symbol
586 && *input_line_pointer
== '@'
587 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
589 register char *p
= frag_more ((int) nbytes
);
590 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
591 int offset
= (!reloc_howto
) ? 0 : (nbytes
- bfd_get_reloc_size (reloc_howto
));
596 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, (int) nbytes
- offset
, &exp
, 0, reloc
);
599 emit_expr (&exp
, (unsigned int) nbytes
);
601 while (*input_line_pointer
++ == ',');
603 input_line_pointer
--; /* Put terminator back into stream. */
604 demand_empty_rest_of_line ();
607 /* Validate any relocations emitted for -mrelocatable, possibly adding
608 fixups for word relocations in writable segments, so we can adjust
611 ppc_elf_validate_fix (fixp
, seg
)
618 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
619 && strcmp (segment_name (seg
), ".got2") != 0
620 && strcmp (segment_name (seg
), ".dtors") != 0
621 && strcmp (segment_name (seg
), ".ctors") != 0
622 && strcmp (segment_name (seg
), ".fixup") != 0
623 && strcmp (segment_name (seg
), ".stab") != 0)
625 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
626 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
628 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
629 "Relocation cannot be done when using -mrelocatable");
636 /* We need to keep a list of fixups. We can't simply generate them as
637 we go, because that would require us to first create the frag, and
638 that would screw up references to ``.''. */
644 bfd_reloc_code_real_type reloc
;
647 #define MAX_INSN_FIXUPS (5)
649 /* This routine is called for each instruction to be assembled. */
656 const struct powerpc_opcode
*opcode
;
658 const unsigned char *opindex_ptr
;
662 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
666 bfd_reloc_code_real_type reloc
;
668 /* Get the opcode. */
669 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
674 /* Look up the opcode in the hash table. */
675 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
676 if (opcode
== (const struct powerpc_opcode
*) NULL
)
678 const struct powerpc_macro
*macro
;
680 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
681 if (macro
== (const struct powerpc_macro
*) NULL
)
682 as_bad ("Unrecognized opcode: `%s'", str
);
684 ppc_macro (s
, macro
);
689 insn
= opcode
->opcode
;
692 while (isspace (*str
))
695 /* PowerPC operands are just expressions. The only real issue is
696 that a few operand types are optional. All cases which might use
697 an optional operand separate the operands only with commas (in
698 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
699 cases never have optional operands). There is never more than
700 one optional operand for an instruction. So, before we start
701 seriously parsing the operands, we check to see if we have an
702 optional operand, and, if we do, we count the number of commas to
703 see whether the operand should be omitted. */
705 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
707 const struct powerpc_operand
*operand
;
709 operand
= &powerpc_operands
[*opindex_ptr
];
710 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
712 unsigned int opcount
;
714 /* There is an optional operand. Count the number of
715 commas in the input line. */
722 while ((s
= strchr (s
, ',')) != (char *) NULL
)
729 /* If there are fewer operands in the line then are called
730 for by the instruction, we want to skip the optional
732 if (opcount
< strlen (opcode
->operands
))
739 /* Gather the operands. */
743 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
745 const struct powerpc_operand
*operand
;
751 if (next_opindex
== 0)
752 operand
= &powerpc_operands
[*opindex_ptr
];
755 operand
= &powerpc_operands
[next_opindex
];
761 /* If this is a fake operand, then we do not expect anything
763 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
765 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
766 if (errmsg
!= (const char *) NULL
)
771 /* If this is an optional operand, and we are skipping it, just
773 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
778 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
779 if (errmsg
!= (const char *) NULL
)
782 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
783 next_opindex
= *opindex_ptr
+ 1;
787 /* Gather the operand. */
788 hold
= input_line_pointer
;
789 input_line_pointer
= str
;
791 str
= input_line_pointer
;
792 input_line_pointer
= hold
;
794 if (ex
.X_op
== O_illegal
)
795 as_bad ("illegal operand");
796 else if (ex
.X_op
== O_absent
)
797 as_bad ("missing operand");
798 else if (ex
.X_op
== O_constant
)
801 /* Allow @HA, @L, @H on constants. */
802 char *orig_str
= str
;
803 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
811 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
815 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
818 case BFD_RELOC_HI16_S
:
819 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
820 + ((ex
.X_add_number
>> 15) & 1);
824 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
829 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
831 /* We need to generate a fixup for this expression. */
832 if (fc
>= MAX_INSN_FIXUPS
)
833 as_fatal ("too many fixups");
835 fixups
[fc
].opindex
= 0;
836 fixups
[fc
].reloc
= reloc
;
843 /* We need to generate a fixup for this expression. */
844 if (fc
>= MAX_INSN_FIXUPS
)
845 as_fatal ("too many fixups");
847 fixups
[fc
].opindex
= *opindex_ptr
;
848 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
857 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
865 /* The call to expression should have advanced str past any
868 && (endc
!= ',' || *str
!= '\0'))
870 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
878 while (isspace (*str
))
882 as_bad ("junk at end of line: `%s'", str
);
884 /* Write out the instruction. */
886 md_number_to_chars (f
, insn
, 4);
888 /* Create any fixups. At this point we do not use a
889 bfd_reloc_code_real_type, but instead just use the
890 BFD_RELOC_UNUSED plus the operand index. This lets us easily
891 handle fixups for any operand type, although that is admittedly
892 not a very exciting feature. We pick a BFD reloc type in
894 for (i
= 0; i
< fc
; i
++)
896 const struct powerpc_operand
*operand
;
898 operand
= &powerpc_operands
[fixups
[i
].opindex
];
899 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
901 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
902 int size
= (!reloc_howto
) ? 0 : bfd_get_reloc_size (reloc_howto
);
903 int offset
= target_big_endian
? (4 - size
) : 0;
909 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
910 &fixups
[i
].exp
, (reloc_howto
&& reloc_howto
->pc_relative
),
913 /* Turn off complaints that the addend is too large for things like
915 switch (fixups
[i
].reloc
)
919 case BFD_RELOC_HI16_S
:
920 fixP
->fx_no_overflow
= 1;
925 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
927 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
928 ((bfd_reloc_code_real_type
)
929 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
933 #ifndef WORKING_DOT_WORD
934 /* Handle long and short jumps */
936 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
938 addressT from_addr
, to_addr
;
946 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
948 addressT from_addr
, to_addr
;
956 /* Handle a macro. Gather all the operands, transform them as
957 described by the macro, and call md_assemble recursively. All the
958 operands are separated by commas; we don't accept parentheses
959 around operands here. */
962 ppc_macro (str
, macro
)
964 const struct powerpc_macro
*macro
;
975 /* Gather the users operands into the operands array. */
980 if (count
>= sizeof operands
/ sizeof operands
[0])
982 operands
[count
++] = s
;
984 if (s
== (char *) NULL
)
989 if (count
!= macro
->operands
)
991 as_bad ("wrong number of operands");
995 /* Work out how large the string must be (the size is unbounded
996 because it includes user input). */
998 format
= macro
->format
;
999 while (*format
!= '\0')
1008 arg
= strtol (format
+ 1, &send
, 10);
1009 know (send
!= format
&& arg
>= 0 && arg
< count
);
1010 len
+= strlen (operands
[arg
]);
1015 /* Put the string together. */
1016 complete
= s
= (char *) alloca (len
+ 1);
1017 format
= macro
->format
;
1018 while (*format
!= '\0')
1024 arg
= strtol (format
+ 1, &send
, 10);
1025 strcpy (s
, operands
[arg
]);
1032 /* Assemble the constructed instruction. */
1033 md_assemble (complete
);
1036 /* Pseudo-op handling. */
1038 /* The .byte pseudo-op. This is similar to the normal .byte
1039 pseudo-op, but it can also take a single ASCII string. */
1045 if (*input_line_pointer
!= '\"')
1051 /* Gather characters. A real double quote is doubled. Unusual
1052 characters are not permitted. */
1053 ++input_line_pointer
;
1058 c
= *input_line_pointer
++;
1062 if (*input_line_pointer
!= '\"')
1064 ++input_line_pointer
;
1067 FRAG_APPEND_1_CHAR (c
);
1070 demand_empty_rest_of_line ();
1075 /* XCOFF specific pseudo-op handling. */
1077 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1078 symbols in the .bss segment as though they were local common
1079 symbols, and uses a different smclas. */
1085 asection
*current_seg
= now_seg
;
1086 subsegT current_subseg
= now_subseg
;
1092 symbolS
*lcomm_sym
= NULL
;
1096 name
= input_line_pointer
;
1097 endc
= get_symbol_end ();
1098 end_name
= input_line_pointer
;
1101 if (*input_line_pointer
!= ',')
1103 as_bad ("missing size");
1104 ignore_rest_of_line ();
1107 ++input_line_pointer
;
1109 size
= get_absolute_expression ();
1112 as_bad ("negative size");
1113 ignore_rest_of_line ();
1119 /* The third argument to .comm is the alignment. */
1120 if (*input_line_pointer
!= ',')
1124 ++input_line_pointer
;
1125 align
= get_absolute_expression ();
1128 as_warn ("ignoring bad alignment");
1147 /* The third argument to .lcomm appears to be the real local
1148 common symbol to create. References to the symbol named in
1149 the first argument are turned into references to the third
1151 if (*input_line_pointer
!= ',')
1153 as_bad ("missing real symbol name");
1154 ignore_rest_of_line ();
1157 ++input_line_pointer
;
1159 lcomm_name
= input_line_pointer
;
1160 lcomm_endc
= get_symbol_end ();
1162 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1164 *input_line_pointer
= lcomm_endc
;
1168 sym
= symbol_find_or_make (name
);
1171 if (S_IS_DEFINED (sym
)
1172 || S_GET_VALUE (sym
) != 0)
1174 as_bad ("attempt to redefine symbol");
1175 ignore_rest_of_line ();
1179 record_alignment (bss_section
, align
);
1182 || ! S_IS_DEFINED (lcomm_sym
))
1191 S_SET_EXTERNAL (sym
);
1195 lcomm_sym
->sy_tc
.output
= 1;
1196 def_sym
= lcomm_sym
;
1200 subseg_set (bss_section
, 1);
1201 frag_align (align
, 0);
1203 def_sym
->sy_frag
= frag_now
;
1204 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1205 def_size
, (char *) NULL
);
1207 S_SET_SEGMENT (def_sym
, bss_section
);
1208 def_sym
->sy_tc
.align
= align
;
1212 /* Align the size of lcomm_sym. */
1213 lcomm_sym
->sy_frag
->fr_offset
=
1214 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1215 &~ ((1 << align
) - 1));
1216 if (align
> lcomm_sym
->sy_tc
.align
)
1217 lcomm_sym
->sy_tc
.align
= align
;
1222 /* Make sym an offset from lcomm_sym. */
1223 S_SET_SEGMENT (sym
, bss_section
);
1224 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1225 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1226 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1229 subseg_set (current_seg
, current_subseg
);
1231 demand_empty_rest_of_line ();
1234 /* The .csect pseudo-op. This switches us into a different
1235 subsegment. The first argument is a symbol whose value is the
1236 start of the .csect. In COFF, csect symbols get special aux
1237 entries defined by the x_csect field of union internal_auxent. The
1238 optional second argument is the alignment (the default is 2). */
1248 name
= input_line_pointer
;
1249 endc
= get_symbol_end ();
1251 sym
= symbol_find_or_make (name
);
1253 *input_line_pointer
= endc
;
1255 if (S_IS_DEFINED (sym
))
1256 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1263 /* This is a new csect. We need to look at the symbol class to
1264 figure out whether it should go in the text section or the
1267 switch (sym
->sy_tc
.class)
1277 S_SET_SEGMENT (sym
, text_section
);
1278 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1279 ++ppc_text_subsegment
;
1280 list_ptr
= &ppc_text_csects
;
1289 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1291 S_SET_SEGMENT (sym
, data_section
);
1292 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1293 ++ppc_data_subsegment
;
1294 list_ptr
= &ppc_data_csects
;
1300 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1302 ppc_after_toc_frag
= frag_now
;
1304 sym
->sy_frag
= frag_now
;
1305 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1307 sym
->sy_tc
.align
= 2;
1308 sym
->sy_tc
.output
= 1;
1309 sym
->sy_tc
.within
= sym
;
1311 for (list
= *list_ptr
;
1312 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1313 list
= list
->sy_tc
.next
)
1315 list
->sy_tc
.next
= sym
;
1317 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1318 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1321 if (*input_line_pointer
== ',')
1323 ++input_line_pointer
;
1324 sym
->sy_tc
.align
= get_absolute_expression ();
1327 ppc_current_csect
= sym
;
1329 demand_empty_rest_of_line ();
1332 /* The .extern pseudo-op. We create an undefined symbol. */
1341 name
= input_line_pointer
;
1342 endc
= get_symbol_end ();
1344 (void) symbol_find_or_make (name
);
1346 *input_line_pointer
= endc
;
1348 demand_empty_rest_of_line ();
1351 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1352 this because it can't handle undefined symbols. I think we can
1362 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1363 although I don't know why it bothers. */
1374 name
= input_line_pointer
;
1375 endc
= get_symbol_end ();
1377 sym
= symbol_find_or_make (name
);
1379 *input_line_pointer
= endc
;
1381 if (*input_line_pointer
!= ',')
1383 as_bad ("missing rename string");
1384 ignore_rest_of_line ();
1387 ++input_line_pointer
;
1389 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1391 demand_empty_rest_of_line ();
1394 /* The .stabx pseudo-op. This is similar to a normal .stabs
1395 pseudo-op, but slightly different. A sample is
1396 .stabx "main:F-1",.main,142,0
1397 The first argument is the symbol name to create. The second is the
1398 value, and the third is the storage class. The fourth seems to be
1399 always zero, and I am assuming it is the type. */
1410 name
= demand_copy_C_string (&len
);
1412 if (*input_line_pointer
!= ',')
1414 as_bad ("missing value");
1417 ++input_line_pointer
;
1419 sym
= symbol_make (name
);
1421 (void) expression (&exp
);
1428 as_bad ("illegal .stabx expression; zero assumed");
1429 exp
.X_add_number
= 0;
1432 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
1433 sym
->sy_frag
= &zero_address_frag
;
1437 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1438 sym
->sy_value
= exp
;
1442 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1443 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1448 /* The value is some complex expression. This will probably
1449 fail at some later point, but this is probably the right
1450 thing to do here. */
1451 sym
->sy_value
= exp
;
1455 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1456 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1458 if (*input_line_pointer
!= ',')
1460 as_bad ("missing class");
1463 ++input_line_pointer
;
1465 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1467 if (*input_line_pointer
!= ',')
1469 as_bad ("missing type");
1472 ++input_line_pointer
;
1474 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1476 sym
->sy_tc
.output
= 1;
1478 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
1479 sym
->sy_tc
.within
= ppc_current_block
;
1481 if (exp
.X_op
!= O_symbol
1482 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
1483 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
1484 ppc_frob_label (sym
);
1487 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1488 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
1489 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
1490 ppc_current_csect
->sy_tc
.within
= sym
;
1493 if (strlen (name
) > SYMNMLEN
)
1495 /* For some reason, each name is preceded by a two byte length
1496 and followed by a null byte. */
1497 ppc_debug_name_section_size
+= strlen (name
) + 3;
1500 demand_empty_rest_of_line ();
1503 /* The .function pseudo-op. This takes several arguments. The first
1504 argument seems to be the external name of the symbol. The second
1505 argment seems to be the label for the start of the function. gcc
1506 uses the same name for both. I have no idea what the third and
1507 fourth arguments are meant to be. The optional fifth argument is
1508 an expression for the size of the function. In COFF this symbol
1509 gets an aux entry like that used for a csect. */
1512 ppc_function (ignore
)
1521 name
= input_line_pointer
;
1522 endc
= get_symbol_end ();
1524 /* Ignore any [PR] suffix. */
1525 name
= ppc_canonicalize_symbol_name (name
);
1526 s
= strchr (name
, '[');
1527 if (s
!= (char *) NULL
1528 && strcmp (s
+ 1, "PR]") == 0)
1531 ext_sym
= symbol_find_or_make (name
);
1533 *input_line_pointer
= endc
;
1535 if (*input_line_pointer
!= ',')
1537 as_bad ("missing symbol name");
1538 ignore_rest_of_line ();
1541 ++input_line_pointer
;
1543 name
= input_line_pointer
;
1544 endc
= get_symbol_end ();
1546 lab_sym
= symbol_find_or_make (name
);
1548 *input_line_pointer
= endc
;
1550 if (ext_sym
!= lab_sym
)
1552 ext_sym
->sy_value
.X_op
= O_symbol
;
1553 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1554 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1555 ext_sym
->sy_value
.X_add_number
= 0;
1558 if (ext_sym
->sy_tc
.class == -1)
1559 ext_sym
->sy_tc
.class = XMC_PR
;
1560 ext_sym
->sy_tc
.output
= 1;
1562 if (*input_line_pointer
== ',')
1566 /* Ignore the third argument. */
1567 ++input_line_pointer
;
1568 expression (&ignore
);
1569 if (*input_line_pointer
== ',')
1571 /* Ignore the fourth argument. */
1572 ++input_line_pointer
;
1573 expression (&ignore
);
1574 if (*input_line_pointer
== ',')
1576 /* The fifth argument is the function size. */
1577 ++input_line_pointer
;
1578 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
1581 &zero_address_frag
);
1582 pseudo_set (ext_sym
->sy_tc
.size
);
1587 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
1588 SF_SET_FUNCTION (ext_sym
);
1589 SF_SET_PROCESS (ext_sym
);
1590 coff_add_linesym (ext_sym
);
1592 demand_empty_rest_of_line ();
1595 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
1604 sym
= symbol_make (".bf");
1605 S_SET_SEGMENT (sym
, text_section
);
1606 sym
->sy_frag
= frag_now
;
1607 S_SET_VALUE (sym
, frag_now_fix ());
1608 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1610 coff_line_base
= get_absolute_expression ();
1612 S_SET_NUMBER_AUXILIARY (sym
, 1);
1613 SA_SET_SYM_LNNO (sym
, coff_line_base
);
1615 sym
->sy_tc
.output
= 1;
1617 ppc_frob_label (sym
);
1619 demand_empty_rest_of_line ();
1622 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
1623 ".ef", except that the line number is absolute, not relative to the
1624 most recent ".bf" symbol. */
1632 sym
= symbol_make (".ef");
1633 S_SET_SEGMENT (sym
, text_section
);
1634 sym
->sy_frag
= frag_now
;
1635 S_SET_VALUE (sym
, frag_now_fix ());
1636 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1637 S_SET_NUMBER_AUXILIARY (sym
, 1);
1638 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1639 sym
->sy_tc
.output
= 1;
1641 ppc_frob_label (sym
);
1643 demand_empty_rest_of_line ();
1646 /* The .bi and .ei pseudo-ops. These take a string argument and
1647 generates a C_BINCL or C_EINCL symbol, which goes at the start of
1659 name
= demand_copy_C_string (&len
);
1661 sym
= symbol_make (name
);
1662 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1663 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1665 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
1666 offset in the file to the line number entry to use. That is
1667 quite difficult to implement using BFD, so I'm just not doing it.
1668 Sorry. Please add it if you can figure out how. Note that this
1669 approach is the only way to support multiple files in COFF, since
1670 line numbers are associated with function symbols. Note further
1671 that it still doesn't work, since the line numbers are stored as
1672 offsets from a base line number. */
1674 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
1675 sym
->sy_tc
.output
= 1;
1677 for (look
= symbol_rootP
;
1678 (look
!= (symbolS
*) NULL
1679 && (S_GET_STORAGE_CLASS (look
) == C_FILE
1680 || S_GET_STORAGE_CLASS (look
) == C_BINCL
1681 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
1682 look
= symbol_next (look
))
1684 if (look
!= (symbolS
*) NULL
)
1686 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1687 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
1690 demand_empty_rest_of_line ();
1693 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
1694 There is one argument, which is a csect symbol. The value of the
1695 .bs symbol is the index of this csect symbol. */
1706 if (ppc_current_block
!= NULL
)
1707 as_bad ("nested .bs blocks");
1709 name
= input_line_pointer
;
1710 endc
= get_symbol_end ();
1712 csect
= symbol_find_or_make (name
);
1714 *input_line_pointer
= endc
;
1716 sym
= symbol_make (".bs");
1717 S_SET_SEGMENT (sym
, now_seg
);
1718 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
1719 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1720 sym
->sy_tc
.output
= 1;
1722 sym
->sy_tc
.within
= csect
;
1724 ppc_frob_label (sym
);
1726 ppc_current_block
= sym
;
1728 demand_empty_rest_of_line ();
1731 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
1739 if (ppc_current_block
== NULL
)
1740 as_bad (".es without preceding .bs");
1742 sym
= symbol_make (".es");
1743 S_SET_SEGMENT (sym
, now_seg
);
1744 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
1745 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1746 sym
->sy_tc
.output
= 1;
1748 ppc_frob_label (sym
);
1750 ppc_current_block
= NULL
;
1752 demand_empty_rest_of_line ();
1755 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
1764 sym
= symbol_make (".bb");
1765 S_SET_SEGMENT (sym
, text_section
);
1766 sym
->sy_frag
= frag_now
;
1767 S_SET_VALUE (sym
, frag_now_fix ());
1768 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
1770 S_SET_NUMBER_AUXILIARY (sym
, 1);
1771 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1773 sym
->sy_tc
.output
= 1;
1775 ppc_frob_label (sym
);
1777 demand_empty_rest_of_line ();
1780 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
1789 sym
= symbol_make (".eb");
1790 S_SET_SEGMENT (sym
, text_section
);
1791 sym
->sy_frag
= frag_now
;
1792 S_SET_VALUE (sym
, frag_now_fix ());
1793 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1794 S_SET_NUMBER_AUXILIARY (sym
, 1);
1795 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1796 sym
->sy_tc
.output
= 1;
1798 ppc_frob_label (sym
);
1800 demand_empty_rest_of_line ();
1803 /* The .toc pseudo-op. Switch to the .toc subsegment. */
1809 if (ppc_toc_csect
!= (symbolS
*) NULL
)
1810 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
1817 subseg
= ppc_data_subsegment
;
1818 ++ppc_data_subsegment
;
1820 subseg_new (segment_name (data_section
), subseg
);
1821 ppc_toc_frag
= frag_now
;
1823 sym
= symbol_find_or_make ("TOC[TC0]");
1824 sym
->sy_frag
= frag_now
;
1825 S_SET_SEGMENT (sym
, data_section
);
1826 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1827 sym
->sy_tc
.subseg
= subseg
;
1828 sym
->sy_tc
.output
= 1;
1829 sym
->sy_tc
.within
= sym
;
1831 ppc_toc_csect
= sym
;
1833 for (list
= ppc_data_csects
;
1834 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1835 list
= list
->sy_tc
.next
)
1837 list
->sy_tc
.next
= sym
;
1839 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1840 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1843 ppc_current_csect
= ppc_toc_csect
;
1845 demand_empty_rest_of_line ();
1848 #endif /* OBJ_COFF */
1850 /* The .tc pseudo-op. This is used when generating either XCOFF or
1851 ELF. This takes two or more arguments.
1853 When generating XCOFF output, the first argument is the name to
1854 give to this location in the toc; this will be a symbol with class
1855 TC. The rest of the arguments are 4 byte values to actually put at
1856 this location in the TOC; often there is just one more argument, a
1857 relocateable symbol reference.
1859 When not generating XCOFF output, the arguments are the same, but
1860 the first argument is simply ignored. */
1868 /* Define the TOC symbol name. */
1874 if (ppc_toc_csect
== (symbolS
*) NULL
1875 || ppc_toc_csect
!= ppc_current_csect
)
1877 as_bad (".tc not in .toc section");
1878 ignore_rest_of_line ();
1882 name
= input_line_pointer
;
1883 endc
= get_symbol_end ();
1885 sym
= symbol_find_or_make (name
);
1887 *input_line_pointer
= endc
;
1889 if (S_IS_DEFINED (sym
))
1893 label
= ppc_current_csect
->sy_tc
.within
;
1894 if (label
->sy_tc
.class != XMC_TC0
)
1896 as_warn (".tc with no label");
1897 ignore_rest_of_line ();
1901 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
1902 label
->sy_frag
= sym
->sy_frag
;
1903 S_SET_VALUE (label
, S_GET_VALUE (sym
));
1905 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1906 ++input_line_pointer
;
1911 S_SET_SEGMENT (sym
, now_seg
);
1912 sym
->sy_frag
= frag_now
;
1913 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1914 sym
->sy_tc
.class = XMC_TC
;
1915 sym
->sy_tc
.output
= 1;
1917 ppc_frob_label (sym
);
1920 #else /* ! defined (OBJ_COFF) */
1922 /* Skip the TOC symbol name. */
1923 while (is_part_of_name (*input_line_pointer
)
1924 || *input_line_pointer
== '['
1925 || *input_line_pointer
== ']'
1926 || *input_line_pointer
== '{'
1927 || *input_line_pointer
== '}')
1928 ++input_line_pointer
;
1930 /* Align to a four byte boundary. */
1932 record_alignment (now_seg
, 2);
1934 #endif /* ! defined (OBJ_COFF) */
1936 if (*input_line_pointer
!= ',')
1937 demand_empty_rest_of_line ();
1940 ++input_line_pointer
;
1947 /* XCOFF specific symbol and file handling. */
1949 /* Canonicalize the symbol name. We use the to force the suffix, if
1950 any, to use square brackets, and to be in upper case. */
1953 ppc_canonicalize_symbol_name (name
)
1958 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
1972 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
1976 if (*s
== '\0' || s
[1] != '\0')
1977 as_bad ("bad symbol suffix");
1985 /* Set the class of a symbol based on the suffix, if any. This is
1986 called whenever a new symbol is created. */
1989 ppc_symbol_new_hook (sym
)
1994 sym
->sy_tc
.next
= NULL
;
1995 sym
->sy_tc
.output
= 0;
1996 sym
->sy_tc
.class = -1;
1997 sym
->sy_tc
.real_name
= NULL
;
1998 sym
->sy_tc
.subseg
= 0;
1999 sym
->sy_tc
.align
= 0;
2000 sym
->sy_tc
.size
= NULL
;
2001 sym
->sy_tc
.within
= NULL
;
2003 s
= strchr (S_GET_NAME (sym
), '[');
2004 if (s
== (const char *) NULL
)
2006 /* There is no suffix. */
2015 if (strcmp (s
, "BS]") == 0)
2016 sym
->sy_tc
.class = XMC_BS
;
2019 if (strcmp (s
, "DB]") == 0)
2020 sym
->sy_tc
.class = XMC_DB
;
2021 else if (strcmp (s
, "DS]") == 0)
2022 sym
->sy_tc
.class = XMC_DS
;
2025 if (strcmp (s
, "GL]") == 0)
2026 sym
->sy_tc
.class = XMC_GL
;
2029 if (strcmp (s
, "PR]") == 0)
2030 sym
->sy_tc
.class = XMC_PR
;
2033 if (strcmp (s
, "RO]") == 0)
2034 sym
->sy_tc
.class = XMC_RO
;
2035 else if (strcmp (s
, "RW]") == 0)
2036 sym
->sy_tc
.class = XMC_RW
;
2039 if (strcmp (s
, "SV]") == 0)
2040 sym
->sy_tc
.class = XMC_SV
;
2043 if (strcmp (s
, "TC]") == 0)
2044 sym
->sy_tc
.class = XMC_TC
;
2045 else if (strcmp (s
, "TI]") == 0)
2046 sym
->sy_tc
.class = XMC_TI
;
2047 else if (strcmp (s
, "TB]") == 0)
2048 sym
->sy_tc
.class = XMC_TB
;
2049 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
2050 sym
->sy_tc
.class = XMC_TC0
;
2053 if (strcmp (s
, "UA]") == 0)
2054 sym
->sy_tc
.class = XMC_UA
;
2055 else if (strcmp (s
, "UC]") == 0)
2056 sym
->sy_tc
.class = XMC_UC
;
2059 if (strcmp (s
, "XO]") == 0)
2060 sym
->sy_tc
.class = XMC_XO
;
2064 if (sym
->sy_tc
.class == -1)
2065 as_bad ("Unrecognized symbol suffix");
2068 /* Set the class of a label based on where it is defined. This
2069 handles symbols without suffixes. Also, move the symbol so that it
2070 follows the csect symbol. */
2073 ppc_frob_label (sym
)
2076 if (ppc_current_csect
!= (symbolS
*) NULL
)
2078 if (sym
->sy_tc
.class == -1)
2079 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
2081 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2082 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
2084 ppc_current_csect
->sy_tc
.within
= sym
;
2088 /* Change the name of a symbol just before writing it out. Set the
2089 real name if the .rename pseudo-op was used. Otherwise, remove any
2090 class suffix. Return 1 if the symbol should not be included in the
2094 ppc_frob_symbol (sym
)
2097 static symbolS
*ppc_last_function
;
2098 static symbolS
*set_end
;
2100 /* Discard symbols that should not be included in the output symbol
2102 if (! sym
->sy_used_in_reloc
2103 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
2104 || (! S_IS_EXTERNAL (sym
)
2105 && ! sym
->sy_tc
.output
2106 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
2109 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
2110 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
2116 name
= S_GET_NAME (sym
);
2117 s
= strchr (name
, '[');
2118 if (s
!= (char *) NULL
)
2124 snew
= xmalloc (len
+ 1);
2125 memcpy (snew
, name
, len
);
2128 S_SET_NAME (sym
, snew
);
2132 if (set_end
!= (symbolS
*) NULL
)
2134 SA_SET_SYM_ENDNDX (set_end
, sym
);
2138 if (SF_GET_FUNCTION (sym
))
2140 if (ppc_last_function
!= (symbolS
*) NULL
)
2141 as_warn ("two .function pseudo-ops with no intervening .ef");
2142 ppc_last_function
= sym
;
2143 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
2145 resolve_symbol_value (sym
->sy_tc
.size
);
2146 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
2149 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
2150 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
2152 if (ppc_last_function
== (symbolS
*) NULL
)
2153 as_warn (".ef with no preceding .function");
2156 set_end
= ppc_last_function
;
2157 ppc_last_function
= NULL
;
2159 /* We don't have a C_EFCN symbol, but we need to force the
2160 COFF backend to believe that it has seen one. */
2161 coff_last_function
= NULL
;
2165 if (! S_IS_EXTERNAL (sym
)
2166 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
2167 && S_GET_STORAGE_CLASS (sym
) != C_FILE
2168 && S_GET_STORAGE_CLASS (sym
) != C_FCN
2169 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
2170 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
2171 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
2172 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
2174 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
2175 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
2178 union internal_auxent
*a
;
2180 /* Create a csect aux. */
2181 i
= S_GET_NUMBER_AUXILIARY (sym
);
2182 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
2183 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
2184 if (sym
->sy_tc
.class == XMC_TC0
)
2186 /* This is the TOC table. */
2187 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
2188 a
->x_csect
.x_scnlen
.l
= 0;
2189 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
2191 else if (sym
->sy_tc
.subseg
!= 0)
2193 /* This is a csect symbol. x_scnlen is the size of the
2195 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
2196 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
2197 S_GET_SEGMENT (sym
))
2198 - S_GET_VALUE (sym
));
2201 resolve_symbol_value (sym
->sy_tc
.next
);
2202 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
2203 - S_GET_VALUE (sym
));
2205 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
2207 else if (S_GET_SEGMENT (sym
) == bss_section
)
2209 /* This is a common symbol. */
2210 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
2211 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
2212 if (S_IS_EXTERNAL (sym
))
2213 sym
->sy_tc
.class = XMC_RW
;
2215 sym
->sy_tc
.class = XMC_BS
;
2217 else if (! S_IS_DEFINED (sym
))
2219 /* This is an external symbol. */
2220 a
->x_csect
.x_scnlen
.l
= 0;
2221 a
->x_csect
.x_smtyp
= XTY_ER
;
2223 else if (sym
->sy_tc
.class == XMC_TC
)
2227 /* This is a TOC definition. x_scnlen is the size of the
2229 next
= symbol_next (sym
);
2230 while (next
->sy_tc
.class == XMC_TC0
)
2231 next
= symbol_next (next
);
2232 if (next
== (symbolS
*) NULL
2233 || next
->sy_tc
.class != XMC_TC
)
2235 if (ppc_after_toc_frag
== (fragS
*) NULL
)
2236 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
2238 - S_GET_VALUE (sym
));
2240 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
2241 - S_GET_VALUE (sym
));
2245 resolve_symbol_value (next
);
2246 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
2247 - S_GET_VALUE (sym
));
2249 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
2255 /* This is a normal symbol definition. x_scnlen is the
2256 symbol index of the containing csect. */
2257 if (S_GET_SEGMENT (sym
) == text_section
)
2258 csect
= ppc_text_csects
;
2259 else if (S_GET_SEGMENT (sym
) == data_section
)
2260 csect
= ppc_data_csects
;
2264 /* Skip the initial dummy symbol. */
2265 csect
= csect
->sy_tc
.next
;
2267 if (csect
== (symbolS
*) NULL
)
2268 a
->x_csect
.x_scnlen
.l
= 0;
2271 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
2273 resolve_symbol_value (csect
->sy_tc
.next
);
2274 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
2276 csect
= csect
->sy_tc
.next
;
2279 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
2280 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
2282 a
->x_csect
.x_smtyp
= XTY_LD
;
2285 a
->x_csect
.x_parmhash
= 0;
2286 a
->x_csect
.x_snhash
= 0;
2287 if (sym
->sy_tc
.class == -1)
2288 a
->x_csect
.x_smclas
= XMC_PR
;
2290 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
2291 a
->x_csect
.x_stab
= 0;
2292 a
->x_csect
.x_snstab
= 0;
2294 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
2296 /* We want the value to be the symbol index of the referenced
2297 csect symbol. BFD will do that for us if we set the right
2300 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
2301 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
2303 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2308 /* The value is the offset from the enclosing csect. */
2309 block
= sym
->sy_tc
.within
;
2310 csect
= block
->sy_tc
.within
;
2311 resolve_symbol_value (csect
);
2312 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
2318 /* Set the VMA for a section. This is called on all the sections in
2322 ppc_frob_section (sec
)
2325 static bfd_size_type vma
= 0;
2327 bfd_set_section_vma (stdoutput
, sec
, vma
);
2328 vma
+= bfd_section_size (stdoutput
, sec
);
2331 /* Adjust the file by adding a .debug section if needed. */
2336 if (ppc_debug_name_section_size
> 0)
2340 sec
= bfd_make_section (stdoutput
, ".debug");
2341 if (sec
== (asection
*) NULL
2342 || ! bfd_set_section_size (stdoutput
, sec
,
2343 ppc_debug_name_section_size
)
2344 || ! bfd_set_section_flags (stdoutput
, sec
,
2345 SEC_HAS_CONTENTS
| SEC_LOAD
))
2346 as_fatal ("can't make .debug section");
2350 #endif /* OBJ_COFF */
2352 /* Turn a string in input_line_pointer into a floating point constant
2353 of type type, and store the appropriate bytes in *litp. The number
2354 of LITTLENUMS emitted is stored in *sizep . An error message is
2355 returned, or NULL on OK. */
2358 md_atof (type
, litp
, sizep
)
2364 LITTLENUM_TYPE words
[4];
2380 return "bad call to md_atof";
2383 t
= atof_ieee (input_line_pointer
, type
, words
);
2385 input_line_pointer
= t
;
2389 if (target_big_endian
)
2391 for (i
= 0; i
< prec
; i
++)
2393 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2399 for (i
= prec
- 1; i
>= 0; i
--)
2401 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2409 /* Write a value out to the object file, using the appropriate
2413 md_number_to_chars (buf
, val
, n
)
2418 if (target_big_endian
)
2419 number_to_chars_bigendian (buf
, val
, n
);
2421 number_to_chars_littleendian (buf
, val
, n
);
2424 /* Align a section (I don't know why this is machine dependent). */
2427 md_section_align (seg
, addr
)
2431 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2433 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
2436 /* We don't have any form of relaxing. */
2439 md_estimate_size_before_relax (fragp
, seg
)
2446 /* Convert a machine dependent frag. We never generate these. */
2449 md_convert_frag (abfd
, sec
, fragp
)
2457 /* We have no need to default values of symbols. */
2461 md_undefined_symbol (name
)
2467 /* Functions concerning relocs. */
2469 /* The location from which a PC relative jump should be calculated,
2470 given a PC relative reloc. */
2473 md_pcrel_from (fixp
)
2477 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2478 && ! S_IS_DEFINED (fixp
->fx_addsy
))
2482 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2487 /* This is called to see whether a fixup should be adjusted to use a
2488 section symbol. We take the opportunity to change a fixup against
2489 a symbol in the TOC subsegment into a reloc against the
2490 corresponding .tc symbol. */
2493 ppc_fix_adjustable (fix
)
2498 resolve_symbol_value (fix
->fx_addsy
);
2499 val
= S_GET_VALUE (fix
->fx_addsy
);
2500 if (ppc_toc_csect
!= (symbolS
*) NULL
2501 && fix
->fx_addsy
!= (symbolS
*) NULL
2502 && fix
->fx_addsy
!= ppc_toc_csect
2503 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
2504 && val
>= ppc_toc_frag
->fr_address
2505 && (ppc_after_toc_frag
== (fragS
*) NULL
2506 || val
< ppc_after_toc_frag
->fr_address
))
2510 for (sy
= symbol_next (ppc_toc_csect
);
2511 sy
!= (symbolS
*) NULL
;
2512 sy
= symbol_next (sy
))
2514 if (sy
->sy_tc
.class == XMC_TC0
)
2516 if (sy
->sy_tc
.class != XMC_TC
)
2518 resolve_symbol_value (sy
);
2519 if (val
== S_GET_VALUE (sy
))
2522 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
2527 as_bad_where (fix
->fx_file
, fix
->fx_line
,
2528 "symbol in .toc does not match any .tc");
2531 /* Possibly adjust the reloc to be against the csect. */
2532 if (fix
->fx_addsy
!= (symbolS
*) NULL
2533 && fix
->fx_addsy
->sy_tc
.subseg
== 0
2534 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
2535 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
2536 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
2540 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
2541 csect
= ppc_text_csects
;
2542 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
2543 csect
= ppc_data_csects
;
2547 /* Skip the initial dummy symbol. */
2548 csect
= csect
->sy_tc
.next
;
2550 if (csect
!= (symbolS
*) NULL
)
2552 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
2553 && (csect
->sy_tc
.next
->sy_frag
->fr_address
2554 <= fix
->fx_addsy
->sy_frag
->fr_address
))
2555 csect
= csect
->sy_tc
.next
;
2557 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2558 - csect
->sy_frag
->fr_address
);
2559 fix
->fx_addsy
= csect
;
2563 /* Adjust a reloc against a .lcomm symbol to be against the base
2565 if (fix
->fx_addsy
!= (symbolS
*) NULL
2566 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
2567 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
2569 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
2570 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2571 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
2572 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
2580 /* See whether a symbol is in the TOC section. */
2583 ppc_is_toc_sym (sym
)
2587 return sym
->sy_tc
.class == XMC_TC
;
2589 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
2593 /* Apply a fixup to the object code. This is called for all the
2594 fixups we generated by the call to fix_new_exp, above. In the call
2595 above we used a reloc code which was the largest legal reloc code
2596 plus the operand index. Here we undo that to recover the operand
2597 index. At this point all symbol values should be fully resolved,
2598 and we attempt to completely resolve the reloc. If we can not do
2599 that, we determine the correct reloc code and put it back in the
2603 md_apply_fix3 (fixp
, valuep
, seg
)
2610 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
2611 the symbol values. Since we are using BFD_ASSEMBLER, if we are
2612 doing this relocation the code in write.c is going to call
2613 bfd_perform_relocation, which is also going to use the symbol
2614 value. That means that if the reloc is fully resolved we want to
2615 use *valuep since bfd_perform_relocation is not being used.
2616 However, if the reloc is not fully resolved we do not want to use
2617 *valuep, and must use fx_offset instead. However, if the reloc
2618 is PC relative, we do want to use *valuep since it includes the
2619 result of md_pcrel_from. This is confusing. */
2621 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2626 else if (fixp
->fx_pcrel
)
2630 value
= fixp
->fx_offset
;
2631 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2633 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2634 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2637 /* We can't actually support subtracting a symbol. */
2638 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2639 "expression too complex");
2644 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2647 const struct powerpc_operand
*operand
;
2651 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2653 operand
= &powerpc_operands
[opindex
];
2656 /* It appears that an instruction like
2658 when LC..1 is not a TOC symbol does not generate a reloc. It
2659 uses the offset of LC..1 within its csect. However, .long
2660 LC..1 will generate a reloc. I can't find any documentation
2661 on how these cases are to be distinguished, so this is a wild
2662 guess. These cases are generated by gcc -mminimal-toc. */
2663 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2664 && operand
->bits
== 16
2665 && operand
->shift
== 0
2666 && operand
->insert
== NULL
2667 && fixp
->fx_addsy
!= NULL
2668 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
2669 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
2670 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
2671 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
2673 value
= fixp
->fx_offset
;
2678 /* Fetch the instruction, insert the fully resolved operand
2679 value, and stuff the instruction back again. */
2680 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2681 if (target_big_endian
)
2682 insn
= bfd_getb32 ((unsigned char *) where
);
2684 insn
= bfd_getl32 ((unsigned char *) where
);
2685 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
2686 fixp
->fx_file
, fixp
->fx_line
);
2687 if (target_big_endian
)
2688 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2690 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2694 /* Nothing else to do here. */
2698 /* Determine a BFD reloc value based on the operand information.
2699 We are only prepared to turn a few of the operands into
2701 FIXME: We need to handle the DS field at the very least.
2702 FIXME: Handling 16 bit branches would also be reasonable.
2703 FIXME: Selecting the reloc type is a bit haphazard; perhaps
2704 there should be a new field in the operand table. */
2705 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
2706 && operand
->bits
== 26
2707 && operand
->shift
== 0)
2708 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
2709 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
2710 && operand
->bits
== 26
2711 && operand
->shift
== 0)
2712 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
2713 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2714 && operand
->bits
== 16
2715 && operand
->shift
== 0
2716 && operand
->insert
== NULL
2717 && fixp
->fx_addsy
!= NULL
2718 && ppc_is_toc_sym (fixp
->fx_addsy
))
2721 if (target_big_endian
)
2722 fixp
->fx_where
+= 2;
2723 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
2727 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2728 "unresolved expression that must be resolved");
2736 ppc_elf_validate_fix (fixp
, seg
);
2738 switch (fixp
->fx_r_type
)
2741 case BFD_RELOC_CTOR
:
2744 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
2745 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2746 } /* fall through */
2748 case BFD_RELOC_32_PCREL
:
2749 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2753 case BFD_RELOC_LO16
:
2754 case BFD_RELOC_HI16
:
2755 case BFD_RELOC_HI16_S
:
2756 case BFD_RELOC_PPC_TOC16
:
2758 case BFD_RELOC_GPREL16
:
2762 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2770 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2780 fixp
->fx_addnumber
= value
;
2782 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
2783 fixp
->fx_addnumber
= 0;
2786 /* We want to use the offset within the data segment of the
2787 symbol, not the actual VMA of the symbol. */
2788 fixp
->fx_addnumber
=
2789 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
2796 /* Generate a reloc for a fixup. */
2799 tc_gen_reloc (seg
, fixp
)
2805 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2807 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2808 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2809 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2810 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2812 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2813 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
2816 reloc
->addend
= fixp
->fx_addnumber
;