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 /* Tell the main code what the endianness is. */
35 extern int target_big_endian
;
37 /* Whether or not, we've set target_big_endian. */
38 static int set_target_endian
= 0;
40 static void ppc_set_cpu
PARAMS ((void));
41 static unsigned long ppc_insert_operand
42 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
43 offsetT val
, char *file
, unsigned int line
));
44 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
45 static void ppc_byte
PARAMS ((int));
46 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
47 static void ppc_tc
PARAMS ((int));
49 static void ppc_comm
PARAMS ((int));
50 static void ppc_bb
PARAMS ((int));
51 static void ppc_bf
PARAMS ((int));
52 static void ppc_biei
PARAMS ((int));
53 static void ppc_bs
PARAMS ((int));
54 static void ppc_eb
PARAMS ((int));
55 static void ppc_ef
PARAMS ((int));
56 static void ppc_es
PARAMS ((int));
57 static void ppc_csect
PARAMS ((int));
58 static void ppc_function
PARAMS ((int));
59 static void ppc_extern
PARAMS ((int));
60 static void ppc_lglobl
PARAMS ((int));
61 static void ppc_stabx
PARAMS ((int));
62 static void ppc_rename
PARAMS ((int));
63 static void ppc_toc
PARAMS ((int));
66 static bfd_reloc_code_real_type ppc_elf_suffix
PARAMS ((char **));
67 static void ppc_elf_cons
PARAMS ((int));
68 static void ppc_elf_validate_fix
PARAMS ((fixS
*, segT
));
71 /* Generic assembler global variables which must be defined by all
74 /* Characters which always start a comment. */
75 const char comment_chars
[] = "#";
77 /* Characters which start a comment at the beginning of a line. */
78 const char line_comment_chars
[] = "#";
80 /* Characters which may be used to separate multiple commands on a
82 const char line_separator_chars
[] = ";";
84 /* Characters which are used to indicate an exponent in a floating
86 const char EXP_CHARS
[] = "eE";
88 /* Characters which mean that a number is a floating point constant,
90 const char FLT_CHARS
[] = "dD";
92 /* The target specific pseudo-ops which we support. */
94 const pseudo_typeS md_pseudo_table
[] =
96 /* Pseudo-ops which must be overridden. */
97 { "byte", ppc_byte
, 0 },
100 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
101 legitimately belong in the obj-*.c file. However, XCOFF is based
102 on COFF, and is only implemented for the RS/6000. We just use
103 obj-coff.c, and add what we need here. */
104 { "comm", ppc_comm
, 0 },
105 { "lcomm", ppc_comm
, 1 },
108 { "bi", ppc_biei
, 0 },
110 { "csect", ppc_csect
, 0 },
113 { "ei", ppc_biei
, 1 },
115 { "extern", ppc_extern
, 0 },
116 { "function", ppc_function
, 0 },
117 { "lglobl", ppc_lglobl
, 0 },
118 { "rename", ppc_rename
, 0 },
119 { "stabx", ppc_stabx
, 0 },
120 { "toc", ppc_toc
, 0 },
123 { "long", ppc_elf_cons
, 4 },
124 { "word", ppc_elf_cons
, 2 },
125 { "short", ppc_elf_cons
, 2 },
128 /* This pseudo-op is used even when not generating XCOFF output. */
134 /* Local variables. */
136 /* The type of processor we are assembling for. This is one or more
137 of the PPC_OPCODE flags defined in opcode/ppc.h. */
138 static int ppc_cpu
= 0;
140 /* The size of the processor we are assembling for. This is either
141 PPC_OPCODE_32 or PPC_OPCODE_64. */
142 static int ppc_size
= PPC_OPCODE_32
;
144 /* Opcode hash table. */
145 static struct hash_control
*ppc_hash
;
147 /* Macro hash table. */
148 static struct hash_control
*ppc_macro_hash
;
151 /* Whether to warn about non PC relative relocations that aren't
152 in the .got2 section. */
153 static boolean mrelocatable
= false;
155 /* Flags to set in the elf header */
156 static flagword ppc_flags
= 0;
161 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
162 using a bunch of different sections. These assembler sections,
163 however, are all encompassed within the .text or .data sections of
164 the final output file. We handle this by using different
165 subsegments within these main segments. */
167 /* Next subsegment to allocate within the .text segment. */
168 static subsegT ppc_text_subsegment
= 2;
170 /* Linked list of csects in the text section. */
171 static symbolS
*ppc_text_csects
;
173 /* Next subsegment to allocate within the .data segment. */
174 static subsegT ppc_data_subsegment
= 2;
176 /* Linked list of csects in the data section. */
177 static symbolS
*ppc_data_csects
;
179 /* The current csect. */
180 static symbolS
*ppc_current_csect
;
182 /* The RS/6000 assembler uses a TOC which holds addresses of functions
183 and variables. Symbols are put in the TOC with the .tc pseudo-op.
184 A special relocation is used when accessing TOC entries. We handle
185 the TOC as a subsegment within the .data segment. We set it up if
186 we see a .toc pseudo-op, and save the csect symbol here. */
187 static symbolS
*ppc_toc_csect
;
189 /* The first frag in the TOC subsegment. */
190 static fragS
*ppc_toc_frag
;
192 /* The first frag in the first subsegment after the TOC in the .data
193 segment. NULL if there are no subsegments after the TOC. */
194 static fragS
*ppc_after_toc_frag
;
196 /* The current static block. */
197 static symbolS
*ppc_current_block
;
199 /* The COFF debugging section; set by md_begin. This is not the
200 .debug section, but is instead the secret BFD section which will
201 cause BFD to set the section number of a symbol to N_DEBUG. */
202 static asection
*ppc_coff_debug_section
;
204 /* The size of the .debug section. */
205 static bfd_size_type ppc_debug_name_section_size
;
207 #endif /* OBJ_COFF */
210 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
213 #ifndef WORKING_DOT_WORD
214 const int md_short_jump_size
= 4;
215 const int md_long_jump_size
= 4;
219 CONST
char *md_shortopts
= "um:VQ:";
221 CONST
char *md_shortopts
= "um:";
223 struct option md_longopts
[] = {
224 {NULL
, no_argument
, NULL
, 0}
226 size_t md_longopts_size
= sizeof(md_longopts
);
229 md_parse_option (c
, arg
)
236 /* -u means that any undefined symbols should be treated as
237 external, which is the default for gas anyhow. */
241 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
243 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
244 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
245 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
246 else if (strcmp (arg
, "pwr") == 0)
247 ppc_cpu
= PPC_OPCODE_POWER
;
248 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
249 ignore the option for now, but we should really use it to permit
250 instructions defined on the 601 that are not part of the standard
251 PowerPC architecture (mostly holdovers from the POWER). */
252 else if (strcmp (arg
, "601") == 0)
253 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
254 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
255 Motorola PowerPC 603/604. */
256 else if (strcmp (arg
, "ppc") == 0
257 || strcmp (arg
, "ppc32") == 0
258 || strcmp (arg
, "403") == 0
259 || strcmp (arg
, "603") == 0
260 || strcmp (arg
, "604") == 0)
261 ppc_cpu
= PPC_OPCODE_PPC
;
262 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
264 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
266 ppc_cpu
= PPC_OPCODE_PPC
;
267 ppc_size
= PPC_OPCODE_64
;
269 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
270 else if (strcmp (arg
, "any") == 0)
271 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
274 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
275 else if (strcmp (arg
, "relocatable") == 0)
278 ppc_flags
|= EF_PPC_RELOCATABLE
;
281 else if (strcmp (arg
, "relocatable-lib") == 0)
284 ppc_flags
|= EF_PPC_RELOCATABLE_LIB
;
287 /* -memb, set embedded bit */
288 else if (strcmp (arg
, "emb") == 0)
289 ppc_flags
|= EF_PPC_EMB
;
291 /* -mlittle/-mbig set the endianess */
292 else if (strcmp (arg
, "little") == 0 || strcmp (arg
, "little-endian") == 0)
294 target_big_endian
= 0;
295 set_target_endian
= 1;
298 else if (strcmp (arg
, "big") == 0 || strcmp (arg
, "big-endian") == 0)
300 target_big_endian
= 1;
301 set_target_endian
= 1;
306 as_bad ("invalid switch -m%s", arg
);
312 /* -V: SVR4 argument to print version ID. */
317 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
318 should be emitted or not. FIXME: Not implemented. */
331 md_show_usage (stream
)
337 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
338 -mpwr generate code for IBM POWER (RIOS1)\n\
339 -m601 generate code for Motorola PowerPC 601\n\
340 -mppc, -mppc32, -m403, -m603, -m604\n\
341 generate code for Motorola PowerPC 603/604\n\
342 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
343 -many generate code for any architecture (PWR/PWRX/PPC)\n");
346 -mrelocatable support for GCC's -mrelocatble option\n\
347 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
348 -memb set PPC_EMB bit in ELF flags\n\
349 -mlittle, -mlittle-endian\n\
350 generate code for a little endian machine\n\
351 -mbig, -mbig-endian generate code for a big endian machine\n\
352 -V print assembler version number\n\
353 -Qy, -Qn ignored\n");
357 /* Set ppc_cpu if it is not already set. */
362 const char *default_cpu
= TARGET_CPU
;
366 if (strcmp (default_cpu
, "rs6000") == 0)
367 ppc_cpu
= PPC_OPCODE_POWER
;
368 else if (strcmp (default_cpu
, "powerpc") == 0
369 || strcmp (default_cpu
, "powerpcle") == 0)
370 ppc_cpu
= PPC_OPCODE_PPC
;
372 as_fatal ("Unknown default cpu = %s", default_cpu
);
376 /* Figure out the BFD architecture to use. */
378 enum bfd_architecture
383 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
384 return bfd_arch_powerpc
;
385 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
386 return bfd_arch_rs6000
;
388 as_fatal ("Neither Power nor PowerPC opcodes were selected.");
391 /* This function is called when the assembler starts up. It is called
392 after the options have been parsed and the output file has been
398 register const struct powerpc_opcode
*op
;
399 const struct powerpc_opcode
*op_end
;
400 const struct powerpc_macro
*macro
;
401 const struct powerpc_macro
*macro_end
;
406 /* Set the ELF flags if desired. */
408 bfd_set_private_flags (stdoutput
, ppc_flags
);
411 /* Insert the opcodes into a hash table. */
412 ppc_hash
= hash_new ();
414 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
415 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
417 know ((op
->opcode
& op
->mask
) == op
->opcode
);
419 if ((op
->flags
& ppc_cpu
) != 0
420 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
421 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
425 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
426 if (retval
!= (const char *) NULL
)
428 /* We permit a duplication of the mfdec instruction on
429 the 601, because it seems to have one value on the
430 601 and a different value on other PowerPC
431 processors. It's easier to permit a duplication than
432 to define a new instruction type flag. When using
433 -many, the comparison instructions are a harmless
435 if (strcmp (retval
, "exists") != 0
436 || (((ppc_cpu
& PPC_OPCODE_601
) == 0
437 || strcmp (op
->name
, "mfdec") != 0)
438 && (ppc_cpu
!= (PPC_OPCODE_POWER
441 || (strcmp (op
->name
, "cmpli") != 0
442 && strcmp (op
->name
, "cmpi") != 0
443 && strcmp (op
->name
, "cmp") != 0
444 && strcmp (op
->name
, "cmpl") != 0))))
450 /* Insert the macros into a hash table. */
451 ppc_macro_hash
= hash_new ();
453 macro_end
= powerpc_macros
+ powerpc_num_macros
;
454 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
456 if ((macro
->flags
& ppc_cpu
) != 0)
460 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
461 if (retval
!= (const char *) NULL
)
466 /* Tell the main code what the endianness is if it is not overidden by the user. */
467 if (!set_target_endian
)
469 set_target_endian
= 1;
470 target_big_endian
= PPC_BIG_ENDIAN
;
474 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
476 /* Create dummy symbols to serve as initial csects. This forces the
477 text csects to precede the data csects. These symbols will not
479 ppc_text_csects
= symbol_make ("dummy\001");
480 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
481 ppc_data_csects
= symbol_make ("dummy\001");
482 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
486 /* Insert an operand value into an instruction. */
489 ppc_insert_operand (insn
, operand
, val
, file
, line
)
491 const struct powerpc_operand
*operand
;
496 if (operand
->bits
!= 32)
501 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
503 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
504 && ppc_size
== PPC_OPCODE_32
)
505 max
= (1 << operand
->bits
) - 1;
507 max
= (1 << (operand
->bits
- 1)) - 1;
508 min
= - (1 << (operand
->bits
- 1));
512 max
= (1 << operand
->bits
) - 1;
516 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
521 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
524 "operand out of range (%s not between %ld and %ld)";
527 sprint_value (buf
, test
);
528 if (file
== (char *) NULL
)
529 as_warn (err
, buf
, min
, max
);
531 as_warn_where (file
, line
, err
, buf
, min
, max
);
540 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
541 if (errmsg
!= (const char *) NULL
)
545 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
552 /* Parse @got, etc. and return the desired relocation. */
553 static bfd_reloc_code_real_type
554 ppc_elf_suffix (str_p
)
560 bfd_reloc_code_real_type reloc
;
567 static struct map_bfd mapping
[] = {
568 { "GOT", 3, BFD_RELOC_PPC_TOC16
},
569 { "got", 3, BFD_RELOC_PPC_TOC16
},
570 { "L", 1, BFD_RELOC_LO16
},
571 { "l", 1, BFD_RELOC_LO16
},
572 { "HA", 2, BFD_RELOC_HI16_S
},
573 { "ha", 2, BFD_RELOC_HI16_S
},
574 { "H", 1, BFD_RELOC_HI16
},
575 { "h", 1, BFD_RELOC_HI16
},
576 { "SDAREL", 6, BFD_RELOC_GPREL16
},
577 { "sdarel", 6, BFD_RELOC_GPREL16
},
578 { "FIXUP", 5, BFD_RELOC_CTOR
}, /* synonym for BFD_RELOC_32 that doesn't get */
579 { "fixup", 5, BFD_RELOC_CTOR
}, /* warnings with -mrelocatable */
580 { "BRTAKEN", 7, BFD_RELOC_PPC_B16_BRTAKEN
},
581 { "brtaken", 7, BFD_RELOC_PPC_B16_BRTAKEN
},
582 { "BRNTAKEN", 8, BFD_RELOC_PPC_B16_BRNTAKEN
},
583 { "brntaken", 8, BFD_RELOC_PPC_B16_BRNTAKEN
},
584 { (char *)0, 0, BFD_RELOC_UNUSED
}
588 return BFD_RELOC_UNUSED
;
591 for (ptr
= &mapping
[0]; ptr
->length
> 0; ptr
++)
592 if (ch
== ptr
->string
[0] && strncmp (str
, ptr
->string
, ptr
->length
) == 0)
594 *str_p
= str
+ ptr
->length
;
598 return BFD_RELOC_UNUSED
;
601 /* Like normal .long/.short/.word, except support @got, etc. */
602 /* clobbers input_line_pointer, checks */
605 ppc_elf_cons (nbytes
)
606 register int nbytes
; /* 1=.byte, 2=.word, 4=.long */
609 bfd_reloc_code_real_type reloc
;
611 if (is_it_end_of_statement ())
613 demand_empty_rest_of_line ();
621 && exp
.X_op
== O_symbol
622 && *input_line_pointer
== '@'
623 && (reloc
= ppc_elf_suffix (&input_line_pointer
)) != BFD_RELOC_UNUSED
)
625 register char *p
= frag_more ((int) nbytes
);
626 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, reloc
);
627 int offset
= (!reloc_howto
) ? 0 : (nbytes
- bfd_get_reloc_size (reloc_howto
));
632 fix_new_exp (frag_now
, p
- frag_now
->fr_literal
+ offset
, (int) nbytes
- offset
, &exp
, 0, reloc
);
635 emit_expr (&exp
, (unsigned int) nbytes
);
637 while (*input_line_pointer
++ == ',');
639 input_line_pointer
--; /* Put terminator back into stream. */
640 demand_empty_rest_of_line ();
643 /* Validate any relocations emitted for -mrelocatable, possibly adding
644 fixups for word relocations in writable segments, so we can adjust
647 ppc_elf_validate_fix (fixp
, seg
)
654 && fixp
->fx_r_type
<= BFD_RELOC_UNUSED
655 && strcmp (segment_name (seg
), ".got2") != 0
656 && strcmp (segment_name (seg
), ".dtors") != 0
657 && strcmp (segment_name (seg
), ".ctors") != 0
658 && strcmp (segment_name (seg
), ".fixup") != 0
659 && strcmp (segment_name (seg
), ".stab") != 0)
661 if ((seg
->flags
& (SEC_READONLY
| SEC_CODE
)) != 0
662 || fixp
->fx_r_type
!= BFD_RELOC_CTOR
)
664 as_warn_where (fixp
->fx_file
, fixp
->fx_line
,
665 "Relocation cannot be done when using -mrelocatable");
672 /* We need to keep a list of fixups. We can't simply generate them as
673 we go, because that would require us to first create the frag, and
674 that would screw up references to ``.''. */
680 bfd_reloc_code_real_type reloc
;
683 #define MAX_INSN_FIXUPS (5)
685 /* This routine is called for each instruction to be assembled. */
692 const struct powerpc_opcode
*opcode
;
694 const unsigned char *opindex_ptr
;
698 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
702 bfd_reloc_code_real_type reloc
;
704 /* Get the opcode. */
705 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
710 /* Look up the opcode in the hash table. */
711 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
712 if (opcode
== (const struct powerpc_opcode
*) NULL
)
714 const struct powerpc_macro
*macro
;
716 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
717 if (macro
== (const struct powerpc_macro
*) NULL
)
718 as_bad ("Unrecognized opcode: `%s'", str
);
720 ppc_macro (s
, macro
);
725 insn
= opcode
->opcode
;
728 while (isspace (*str
))
731 /* PowerPC operands are just expressions. The only real issue is
732 that a few operand types are optional. All cases which might use
733 an optional operand separate the operands only with commas (in
734 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
735 cases never have optional operands). There is never more than
736 one optional operand for an instruction. So, before we start
737 seriously parsing the operands, we check to see if we have an
738 optional operand, and, if we do, we count the number of commas to
739 see whether the operand should be omitted. */
741 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
743 const struct powerpc_operand
*operand
;
745 operand
= &powerpc_operands
[*opindex_ptr
];
746 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
748 unsigned int opcount
;
750 /* There is an optional operand. Count the number of
751 commas in the input line. */
758 while ((s
= strchr (s
, ',')) != (char *) NULL
)
765 /* If there are fewer operands in the line then are called
766 for by the instruction, we want to skip the optional
768 if (opcount
< strlen (opcode
->operands
))
775 /* Gather the operands. */
779 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
781 const struct powerpc_operand
*operand
;
787 if (next_opindex
== 0)
788 operand
= &powerpc_operands
[*opindex_ptr
];
791 operand
= &powerpc_operands
[next_opindex
];
797 /* If this is a fake operand, then we do not expect anything
799 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
801 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
802 if (errmsg
!= (const char *) NULL
)
807 /* If this is an optional operand, and we are skipping it, just
809 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
814 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
815 if (errmsg
!= (const char *) NULL
)
818 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
819 next_opindex
= *opindex_ptr
+ 1;
823 /* Gather the operand. */
824 hold
= input_line_pointer
;
825 input_line_pointer
= str
;
827 str
= input_line_pointer
;
828 input_line_pointer
= hold
;
830 if (ex
.X_op
== O_illegal
)
831 as_bad ("illegal operand");
832 else if (ex
.X_op
== O_absent
)
833 as_bad ("missing operand");
834 else if (ex
.X_op
== O_constant
)
837 /* Allow @HA, @L, @H on constants. */
838 char *orig_str
= str
;
839 if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
847 ex
.X_add_number
= ((ex
.X_add_number
& 0xffff) ^ 0x8000) - 0x8000;
851 ex
.X_add_number
= (ex
.X_add_number
>> 16) & 0xffff;
854 case BFD_RELOC_HI16_S
:
855 ex
.X_add_number
= ((ex
.X_add_number
>> 16) & 0xffff)
856 + ((ex
.X_add_number
>> 15) & 1);
860 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
865 else if ((reloc
= ppc_elf_suffix (&str
)) != BFD_RELOC_UNUSED
)
867 /* We need to generate a fixup for this expression. */
868 if (fc
>= MAX_INSN_FIXUPS
)
869 as_fatal ("too many fixups");
871 fixups
[fc
].opindex
= 0;
872 fixups
[fc
].reloc
= reloc
;
879 /* We need to generate a fixup for this expression. */
880 if (fc
>= MAX_INSN_FIXUPS
)
881 as_fatal ("too many fixups");
883 fixups
[fc
].opindex
= *opindex_ptr
;
884 fixups
[fc
].reloc
= BFD_RELOC_UNUSED
;
893 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
901 /* The call to expression should have advanced str past any
904 && (endc
!= ',' || *str
!= '\0'))
906 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
914 while (isspace (*str
))
918 as_bad ("junk at end of line: `%s'", str
);
920 /* Write out the instruction. */
922 md_number_to_chars (f
, insn
, 4);
924 /* Create any fixups. At this point we do not use a
925 bfd_reloc_code_real_type, but instead just use the
926 BFD_RELOC_UNUSED plus the operand index. This lets us easily
927 handle fixups for any operand type, although that is admittedly
928 not a very exciting feature. We pick a BFD reloc type in
930 for (i
= 0; i
< fc
; i
++)
932 const struct powerpc_operand
*operand
;
934 operand
= &powerpc_operands
[fixups
[i
].opindex
];
935 if (fixups
[i
].reloc
!= BFD_RELOC_UNUSED
)
937 reloc_howto_type
*reloc_howto
= bfd_reloc_type_lookup (stdoutput
, fixups
[i
].reloc
);
938 int size
= (!reloc_howto
) ? 0 : bfd_get_reloc_size (reloc_howto
);
939 int offset
= target_big_endian
? (4 - size
) : 0;
945 fixP
= fix_new_exp (frag_now
, f
- frag_now
->fr_literal
+ offset
, size
,
946 &fixups
[i
].exp
, (reloc_howto
&& reloc_howto
->pc_relative
),
949 /* Turn off complaints that the addend is too large for things like
951 switch (fixups
[i
].reloc
)
955 case BFD_RELOC_HI16_S
:
956 fixP
->fx_no_overflow
= 1;
961 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
963 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
964 ((bfd_reloc_code_real_type
)
965 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
969 #ifndef WORKING_DOT_WORD
970 /* Handle long and short jumps */
972 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
974 addressT from_addr
, to_addr
;
982 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
984 addressT from_addr
, to_addr
;
992 /* Handle a macro. Gather all the operands, transform them as
993 described by the macro, and call md_assemble recursively. All the
994 operands are separated by commas; we don't accept parentheses
995 around operands here. */
998 ppc_macro (str
, macro
)
1000 const struct powerpc_macro
*macro
;
1011 /* Gather the users operands into the operands array. */
1016 if (count
>= sizeof operands
/ sizeof operands
[0])
1018 operands
[count
++] = s
;
1019 s
= strchr (s
, ',');
1020 if (s
== (char *) NULL
)
1025 if (count
!= macro
->operands
)
1027 as_bad ("wrong number of operands");
1031 /* Work out how large the string must be (the size is unbounded
1032 because it includes user input). */
1034 format
= macro
->format
;
1035 while (*format
!= '\0')
1044 arg
= strtol (format
+ 1, &send
, 10);
1045 know (send
!= format
&& arg
>= 0 && arg
< count
);
1046 len
+= strlen (operands
[arg
]);
1051 /* Put the string together. */
1052 complete
= s
= (char *) alloca (len
+ 1);
1053 format
= macro
->format
;
1054 while (*format
!= '\0')
1060 arg
= strtol (format
+ 1, &send
, 10);
1061 strcpy (s
, operands
[arg
]);
1068 /* Assemble the constructed instruction. */
1069 md_assemble (complete
);
1072 /* Pseudo-op handling. */
1074 /* The .byte pseudo-op. This is similar to the normal .byte
1075 pseudo-op, but it can also take a single ASCII string. */
1081 if (*input_line_pointer
!= '\"')
1087 /* Gather characters. A real double quote is doubled. Unusual
1088 characters are not permitted. */
1089 ++input_line_pointer
;
1094 c
= *input_line_pointer
++;
1098 if (*input_line_pointer
!= '\"')
1100 ++input_line_pointer
;
1103 FRAG_APPEND_1_CHAR (c
);
1106 demand_empty_rest_of_line ();
1111 /* XCOFF specific pseudo-op handling. */
1113 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
1114 symbols in the .bss segment as though they were local common
1115 symbols, and uses a different smclas. */
1121 asection
*current_seg
= now_seg
;
1122 subsegT current_subseg
= now_subseg
;
1128 symbolS
*lcomm_sym
= NULL
;
1132 name
= input_line_pointer
;
1133 endc
= get_symbol_end ();
1134 end_name
= input_line_pointer
;
1137 if (*input_line_pointer
!= ',')
1139 as_bad ("missing size");
1140 ignore_rest_of_line ();
1143 ++input_line_pointer
;
1145 size
= get_absolute_expression ();
1148 as_bad ("negative size");
1149 ignore_rest_of_line ();
1155 /* The third argument to .comm is the alignment. */
1156 if (*input_line_pointer
!= ',')
1160 ++input_line_pointer
;
1161 align
= get_absolute_expression ();
1164 as_warn ("ignoring bad alignment");
1183 /* The third argument to .lcomm appears to be the real local
1184 common symbol to create. References to the symbol named in
1185 the first argument are turned into references to the third
1187 if (*input_line_pointer
!= ',')
1189 as_bad ("missing real symbol name");
1190 ignore_rest_of_line ();
1193 ++input_line_pointer
;
1195 lcomm_name
= input_line_pointer
;
1196 lcomm_endc
= get_symbol_end ();
1198 lcomm_sym
= symbol_find_or_make (lcomm_name
);
1200 *input_line_pointer
= lcomm_endc
;
1204 sym
= symbol_find_or_make (name
);
1207 if (S_IS_DEFINED (sym
)
1208 || S_GET_VALUE (sym
) != 0)
1210 as_bad ("attempt to redefine symbol");
1211 ignore_rest_of_line ();
1215 record_alignment (bss_section
, align
);
1218 || ! S_IS_DEFINED (lcomm_sym
))
1227 S_SET_EXTERNAL (sym
);
1231 lcomm_sym
->sy_tc
.output
= 1;
1232 def_sym
= lcomm_sym
;
1236 subseg_set (bss_section
, 1);
1237 frag_align (align
, 0);
1239 def_sym
->sy_frag
= frag_now
;
1240 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
1241 def_size
, (char *) NULL
);
1243 S_SET_SEGMENT (def_sym
, bss_section
);
1244 def_sym
->sy_tc
.align
= align
;
1248 /* Align the size of lcomm_sym. */
1249 lcomm_sym
->sy_frag
->fr_offset
=
1250 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
1251 &~ ((1 << align
) - 1));
1252 if (align
> lcomm_sym
->sy_tc
.align
)
1253 lcomm_sym
->sy_tc
.align
= align
;
1258 /* Make sym an offset from lcomm_sym. */
1259 S_SET_SEGMENT (sym
, bss_section
);
1260 sym
->sy_frag
= lcomm_sym
->sy_frag
;
1261 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
1262 lcomm_sym
->sy_frag
->fr_offset
+= size
;
1265 subseg_set (current_seg
, current_subseg
);
1267 demand_empty_rest_of_line ();
1270 /* The .csect pseudo-op. This switches us into a different
1271 subsegment. The first argument is a symbol whose value is the
1272 start of the .csect. In COFF, csect symbols get special aux
1273 entries defined by the x_csect field of union internal_auxent. The
1274 optional second argument is the alignment (the default is 2). */
1284 name
= input_line_pointer
;
1285 endc
= get_symbol_end ();
1287 sym
= symbol_find_or_make (name
);
1289 *input_line_pointer
= endc
;
1291 if (S_IS_DEFINED (sym
))
1292 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
1299 /* This is a new csect. We need to look at the symbol class to
1300 figure out whether it should go in the text section or the
1303 switch (sym
->sy_tc
.class)
1313 S_SET_SEGMENT (sym
, text_section
);
1314 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1315 ++ppc_text_subsegment
;
1316 list_ptr
= &ppc_text_csects
;
1325 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1327 S_SET_SEGMENT (sym
, data_section
);
1328 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1329 ++ppc_data_subsegment
;
1330 list_ptr
= &ppc_data_csects
;
1336 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1338 ppc_after_toc_frag
= frag_now
;
1340 sym
->sy_frag
= frag_now
;
1341 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1343 sym
->sy_tc
.align
= 2;
1344 sym
->sy_tc
.output
= 1;
1345 sym
->sy_tc
.within
= sym
;
1347 for (list
= *list_ptr
;
1348 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1349 list
= list
->sy_tc
.next
)
1351 list
->sy_tc
.next
= sym
;
1353 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1354 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1357 if (*input_line_pointer
== ',')
1359 ++input_line_pointer
;
1360 sym
->sy_tc
.align
= get_absolute_expression ();
1363 ppc_current_csect
= sym
;
1365 demand_empty_rest_of_line ();
1368 /* The .extern pseudo-op. We create an undefined symbol. */
1377 name
= input_line_pointer
;
1378 endc
= get_symbol_end ();
1380 (void) symbol_find_or_make (name
);
1382 *input_line_pointer
= endc
;
1384 demand_empty_rest_of_line ();
1387 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1388 this because it can't handle undefined symbols. I think we can
1398 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1399 although I don't know why it bothers. */
1410 name
= input_line_pointer
;
1411 endc
= get_symbol_end ();
1413 sym
= symbol_find_or_make (name
);
1415 *input_line_pointer
= endc
;
1417 if (*input_line_pointer
!= ',')
1419 as_bad ("missing rename string");
1420 ignore_rest_of_line ();
1423 ++input_line_pointer
;
1425 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1427 demand_empty_rest_of_line ();
1430 /* The .stabx pseudo-op. This is similar to a normal .stabs
1431 pseudo-op, but slightly different. A sample is
1432 .stabx "main:F-1",.main,142,0
1433 The first argument is the symbol name to create. The second is the
1434 value, and the third is the storage class. The fourth seems to be
1435 always zero, and I am assuming it is the type. */
1446 name
= demand_copy_C_string (&len
);
1448 if (*input_line_pointer
!= ',')
1450 as_bad ("missing value");
1453 ++input_line_pointer
;
1455 sym
= symbol_make (name
);
1457 (void) expression (&exp
);
1464 as_bad ("illegal .stabx expression; zero assumed");
1465 exp
.X_add_number
= 0;
1468 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
1469 sym
->sy_frag
= &zero_address_frag
;
1473 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1474 sym
->sy_value
= exp
;
1478 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1479 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1484 /* The value is some complex expression. This will probably
1485 fail at some later point, but this is probably the right
1486 thing to do here. */
1487 sym
->sy_value
= exp
;
1491 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1492 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1494 if (*input_line_pointer
!= ',')
1496 as_bad ("missing class");
1499 ++input_line_pointer
;
1501 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1503 if (*input_line_pointer
!= ',')
1505 as_bad ("missing type");
1508 ++input_line_pointer
;
1510 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1512 sym
->sy_tc
.output
= 1;
1514 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
1515 sym
->sy_tc
.within
= ppc_current_block
;
1517 if (exp
.X_op
!= O_symbol
1518 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
1519 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
1520 ppc_frob_label (sym
);
1523 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1524 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
1525 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
1526 ppc_current_csect
->sy_tc
.within
= sym
;
1529 if (strlen (name
) > SYMNMLEN
)
1531 /* For some reason, each name is preceded by a two byte length
1532 and followed by a null byte. */
1533 ppc_debug_name_section_size
+= strlen (name
) + 3;
1536 demand_empty_rest_of_line ();
1539 /* The .function pseudo-op. This takes several arguments. The first
1540 argument seems to be the external name of the symbol. The second
1541 argment seems to be the label for the start of the function. gcc
1542 uses the same name for both. I have no idea what the third and
1543 fourth arguments are meant to be. The optional fifth argument is
1544 an expression for the size of the function. In COFF this symbol
1545 gets an aux entry like that used for a csect. */
1548 ppc_function (ignore
)
1557 name
= input_line_pointer
;
1558 endc
= get_symbol_end ();
1560 /* Ignore any [PR] suffix. */
1561 name
= ppc_canonicalize_symbol_name (name
);
1562 s
= strchr (name
, '[');
1563 if (s
!= (char *) NULL
1564 && strcmp (s
+ 1, "PR]") == 0)
1567 ext_sym
= symbol_find_or_make (name
);
1569 *input_line_pointer
= endc
;
1571 if (*input_line_pointer
!= ',')
1573 as_bad ("missing symbol name");
1574 ignore_rest_of_line ();
1577 ++input_line_pointer
;
1579 name
= input_line_pointer
;
1580 endc
= get_symbol_end ();
1582 lab_sym
= symbol_find_or_make (name
);
1584 *input_line_pointer
= endc
;
1586 if (ext_sym
!= lab_sym
)
1588 ext_sym
->sy_value
.X_op
= O_symbol
;
1589 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1590 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1591 ext_sym
->sy_value
.X_add_number
= 0;
1594 if (ext_sym
->sy_tc
.class == -1)
1595 ext_sym
->sy_tc
.class = XMC_PR
;
1596 ext_sym
->sy_tc
.output
= 1;
1598 if (*input_line_pointer
== ',')
1602 /* Ignore the third argument. */
1603 ++input_line_pointer
;
1604 expression (&ignore
);
1605 if (*input_line_pointer
== ',')
1607 /* Ignore the fourth argument. */
1608 ++input_line_pointer
;
1609 expression (&ignore
);
1610 if (*input_line_pointer
== ',')
1612 /* The fifth argument is the function size. */
1613 ++input_line_pointer
;
1614 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
1617 &zero_address_frag
);
1618 pseudo_set (ext_sym
->sy_tc
.size
);
1623 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
1624 SF_SET_FUNCTION (ext_sym
);
1625 SF_SET_PROCESS (ext_sym
);
1626 coff_add_linesym (ext_sym
);
1628 demand_empty_rest_of_line ();
1631 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
1640 sym
= symbol_make (".bf");
1641 S_SET_SEGMENT (sym
, text_section
);
1642 sym
->sy_frag
= frag_now
;
1643 S_SET_VALUE (sym
, frag_now_fix ());
1644 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1646 coff_line_base
= get_absolute_expression ();
1648 S_SET_NUMBER_AUXILIARY (sym
, 1);
1649 SA_SET_SYM_LNNO (sym
, coff_line_base
);
1651 sym
->sy_tc
.output
= 1;
1653 ppc_frob_label (sym
);
1655 demand_empty_rest_of_line ();
1658 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
1659 ".ef", except that the line number is absolute, not relative to the
1660 most recent ".bf" symbol. */
1668 sym
= symbol_make (".ef");
1669 S_SET_SEGMENT (sym
, text_section
);
1670 sym
->sy_frag
= frag_now
;
1671 S_SET_VALUE (sym
, frag_now_fix ());
1672 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1673 S_SET_NUMBER_AUXILIARY (sym
, 1);
1674 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1675 sym
->sy_tc
.output
= 1;
1677 ppc_frob_label (sym
);
1679 demand_empty_rest_of_line ();
1682 /* The .bi and .ei pseudo-ops. These take a string argument and
1683 generates a C_BINCL or C_EINCL symbol, which goes at the start of
1695 name
= demand_copy_C_string (&len
);
1697 sym
= symbol_make (name
);
1698 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1699 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1701 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
1702 offset in the file to the line number entry to use. That is
1703 quite difficult to implement using BFD, so I'm just not doing it.
1704 Sorry. Please add it if you can figure out how. Note that this
1705 approach is the only way to support multiple files in COFF, since
1706 line numbers are associated with function symbols. Note further
1707 that it still doesn't work, since the line numbers are stored as
1708 offsets from a base line number. */
1710 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
1711 sym
->sy_tc
.output
= 1;
1713 for (look
= symbol_rootP
;
1714 (look
!= (symbolS
*) NULL
1715 && (S_GET_STORAGE_CLASS (look
) == C_FILE
1716 || S_GET_STORAGE_CLASS (look
) == C_BINCL
1717 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
1718 look
= symbol_next (look
))
1720 if (look
!= (symbolS
*) NULL
)
1722 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1723 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
1726 demand_empty_rest_of_line ();
1729 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
1730 There is one argument, which is a csect symbol. The value of the
1731 .bs symbol is the index of this csect symbol. */
1742 if (ppc_current_block
!= NULL
)
1743 as_bad ("nested .bs blocks");
1745 name
= input_line_pointer
;
1746 endc
= get_symbol_end ();
1748 csect
= symbol_find_or_make (name
);
1750 *input_line_pointer
= endc
;
1752 sym
= symbol_make (".bs");
1753 S_SET_SEGMENT (sym
, now_seg
);
1754 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
1755 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1756 sym
->sy_tc
.output
= 1;
1758 sym
->sy_tc
.within
= csect
;
1760 ppc_frob_label (sym
);
1762 ppc_current_block
= sym
;
1764 demand_empty_rest_of_line ();
1767 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
1775 if (ppc_current_block
== NULL
)
1776 as_bad (".es without preceding .bs");
1778 sym
= symbol_make (".es");
1779 S_SET_SEGMENT (sym
, now_seg
);
1780 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
1781 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1782 sym
->sy_tc
.output
= 1;
1784 ppc_frob_label (sym
);
1786 ppc_current_block
= NULL
;
1788 demand_empty_rest_of_line ();
1791 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
1800 sym
= symbol_make (".bb");
1801 S_SET_SEGMENT (sym
, text_section
);
1802 sym
->sy_frag
= frag_now
;
1803 S_SET_VALUE (sym
, frag_now_fix ());
1804 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
1806 S_SET_NUMBER_AUXILIARY (sym
, 1);
1807 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1809 sym
->sy_tc
.output
= 1;
1811 ppc_frob_label (sym
);
1813 demand_empty_rest_of_line ();
1816 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
1825 sym
= symbol_make (".eb");
1826 S_SET_SEGMENT (sym
, text_section
);
1827 sym
->sy_frag
= frag_now
;
1828 S_SET_VALUE (sym
, frag_now_fix ());
1829 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1830 S_SET_NUMBER_AUXILIARY (sym
, 1);
1831 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1832 sym
->sy_tc
.output
= 1;
1834 ppc_frob_label (sym
);
1836 demand_empty_rest_of_line ();
1839 /* The .toc pseudo-op. Switch to the .toc subsegment. */
1845 if (ppc_toc_csect
!= (symbolS
*) NULL
)
1846 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
1853 subseg
= ppc_data_subsegment
;
1854 ++ppc_data_subsegment
;
1856 subseg_new (segment_name (data_section
), subseg
);
1857 ppc_toc_frag
= frag_now
;
1859 sym
= symbol_find_or_make ("TOC[TC0]");
1860 sym
->sy_frag
= frag_now
;
1861 S_SET_SEGMENT (sym
, data_section
);
1862 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1863 sym
->sy_tc
.subseg
= subseg
;
1864 sym
->sy_tc
.output
= 1;
1865 sym
->sy_tc
.within
= sym
;
1867 ppc_toc_csect
= sym
;
1869 for (list
= ppc_data_csects
;
1870 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1871 list
= list
->sy_tc
.next
)
1873 list
->sy_tc
.next
= sym
;
1875 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1876 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1879 ppc_current_csect
= ppc_toc_csect
;
1881 demand_empty_rest_of_line ();
1884 #endif /* OBJ_COFF */
1886 /* The .tc pseudo-op. This is used when generating either XCOFF or
1887 ELF. This takes two or more arguments.
1889 When generating XCOFF output, the first argument is the name to
1890 give to this location in the toc; this will be a symbol with class
1891 TC. The rest of the arguments are 4 byte values to actually put at
1892 this location in the TOC; often there is just one more argument, a
1893 relocateable symbol reference.
1895 When not generating XCOFF output, the arguments are the same, but
1896 the first argument is simply ignored. */
1904 /* Define the TOC symbol name. */
1910 if (ppc_toc_csect
== (symbolS
*) NULL
1911 || ppc_toc_csect
!= ppc_current_csect
)
1913 as_bad (".tc not in .toc section");
1914 ignore_rest_of_line ();
1918 name
= input_line_pointer
;
1919 endc
= get_symbol_end ();
1921 sym
= symbol_find_or_make (name
);
1923 *input_line_pointer
= endc
;
1925 if (S_IS_DEFINED (sym
))
1929 label
= ppc_current_csect
->sy_tc
.within
;
1930 if (label
->sy_tc
.class != XMC_TC0
)
1932 as_warn (".tc with no label");
1933 ignore_rest_of_line ();
1937 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
1938 label
->sy_frag
= sym
->sy_frag
;
1939 S_SET_VALUE (label
, S_GET_VALUE (sym
));
1941 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1942 ++input_line_pointer
;
1947 S_SET_SEGMENT (sym
, now_seg
);
1948 sym
->sy_frag
= frag_now
;
1949 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1950 sym
->sy_tc
.class = XMC_TC
;
1951 sym
->sy_tc
.output
= 1;
1953 ppc_frob_label (sym
);
1956 #else /* ! defined (OBJ_COFF) */
1958 /* Skip the TOC symbol name. */
1959 while (is_part_of_name (*input_line_pointer
)
1960 || *input_line_pointer
== '['
1961 || *input_line_pointer
== ']'
1962 || *input_line_pointer
== '{'
1963 || *input_line_pointer
== '}')
1964 ++input_line_pointer
;
1966 /* Align to a four byte boundary. */
1968 record_alignment (now_seg
, 2);
1970 #endif /* ! defined (OBJ_COFF) */
1972 if (*input_line_pointer
!= ',')
1973 demand_empty_rest_of_line ();
1976 ++input_line_pointer
;
1983 /* XCOFF specific symbol and file handling. */
1985 /* Canonicalize the symbol name. We use the to force the suffix, if
1986 any, to use square brackets, and to be in upper case. */
1989 ppc_canonicalize_symbol_name (name
)
1994 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
2008 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
2012 if (*s
== '\0' || s
[1] != '\0')
2013 as_bad ("bad symbol suffix");
2021 /* Set the class of a symbol based on the suffix, if any. This is
2022 called whenever a new symbol is created. */
2025 ppc_symbol_new_hook (sym
)
2030 sym
->sy_tc
.next
= NULL
;
2031 sym
->sy_tc
.output
= 0;
2032 sym
->sy_tc
.class = -1;
2033 sym
->sy_tc
.real_name
= NULL
;
2034 sym
->sy_tc
.subseg
= 0;
2035 sym
->sy_tc
.align
= 0;
2036 sym
->sy_tc
.size
= NULL
;
2037 sym
->sy_tc
.within
= NULL
;
2039 s
= strchr (S_GET_NAME (sym
), '[');
2040 if (s
== (const char *) NULL
)
2042 /* There is no suffix. */
2051 if (strcmp (s
, "BS]") == 0)
2052 sym
->sy_tc
.class = XMC_BS
;
2055 if (strcmp (s
, "DB]") == 0)
2056 sym
->sy_tc
.class = XMC_DB
;
2057 else if (strcmp (s
, "DS]") == 0)
2058 sym
->sy_tc
.class = XMC_DS
;
2061 if (strcmp (s
, "GL]") == 0)
2062 sym
->sy_tc
.class = XMC_GL
;
2065 if (strcmp (s
, "PR]") == 0)
2066 sym
->sy_tc
.class = XMC_PR
;
2069 if (strcmp (s
, "RO]") == 0)
2070 sym
->sy_tc
.class = XMC_RO
;
2071 else if (strcmp (s
, "RW]") == 0)
2072 sym
->sy_tc
.class = XMC_RW
;
2075 if (strcmp (s
, "SV]") == 0)
2076 sym
->sy_tc
.class = XMC_SV
;
2079 if (strcmp (s
, "TC]") == 0)
2080 sym
->sy_tc
.class = XMC_TC
;
2081 else if (strcmp (s
, "TI]") == 0)
2082 sym
->sy_tc
.class = XMC_TI
;
2083 else if (strcmp (s
, "TB]") == 0)
2084 sym
->sy_tc
.class = XMC_TB
;
2085 else if (strcmp (s
, "TC0]") == 0 || strcmp (s
, "T0]") == 0)
2086 sym
->sy_tc
.class = XMC_TC0
;
2089 if (strcmp (s
, "UA]") == 0)
2090 sym
->sy_tc
.class = XMC_UA
;
2091 else if (strcmp (s
, "UC]") == 0)
2092 sym
->sy_tc
.class = XMC_UC
;
2095 if (strcmp (s
, "XO]") == 0)
2096 sym
->sy_tc
.class = XMC_XO
;
2100 if (sym
->sy_tc
.class == -1)
2101 as_bad ("Unrecognized symbol suffix");
2104 /* Set the class of a label based on where it is defined. This
2105 handles symbols without suffixes. Also, move the symbol so that it
2106 follows the csect symbol. */
2109 ppc_frob_label (sym
)
2112 if (ppc_current_csect
!= (symbolS
*) NULL
)
2114 if (sym
->sy_tc
.class == -1)
2115 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
2117 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
2118 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
2120 ppc_current_csect
->sy_tc
.within
= sym
;
2124 /* Change the name of a symbol just before writing it out. Set the
2125 real name if the .rename pseudo-op was used. Otherwise, remove any
2126 class suffix. Return 1 if the symbol should not be included in the
2130 ppc_frob_symbol (sym
)
2133 static symbolS
*ppc_last_function
;
2134 static symbolS
*set_end
;
2136 /* Discard symbols that should not be included in the output symbol
2138 if (! sym
->sy_used_in_reloc
2139 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
2140 || (! S_IS_EXTERNAL (sym
)
2141 && ! sym
->sy_tc
.output
2142 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
2145 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
2146 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
2152 name
= S_GET_NAME (sym
);
2153 s
= strchr (name
, '[');
2154 if (s
!= (char *) NULL
)
2160 snew
= xmalloc (len
+ 1);
2161 memcpy (snew
, name
, len
);
2164 S_SET_NAME (sym
, snew
);
2168 if (set_end
!= (symbolS
*) NULL
)
2170 SA_SET_SYM_ENDNDX (set_end
, sym
);
2174 if (SF_GET_FUNCTION (sym
))
2176 if (ppc_last_function
!= (symbolS
*) NULL
)
2177 as_warn ("two .function pseudo-ops with no intervening .ef");
2178 ppc_last_function
= sym
;
2179 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
2181 resolve_symbol_value (sym
->sy_tc
.size
);
2182 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
2185 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
2186 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
2188 if (ppc_last_function
== (symbolS
*) NULL
)
2189 as_warn (".ef with no preceding .function");
2192 set_end
= ppc_last_function
;
2193 ppc_last_function
= NULL
;
2195 /* We don't have a C_EFCN symbol, but we need to force the
2196 COFF backend to believe that it has seen one. */
2197 coff_last_function
= NULL
;
2201 if (! S_IS_EXTERNAL (sym
)
2202 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
2203 && S_GET_STORAGE_CLASS (sym
) != C_FILE
2204 && S_GET_STORAGE_CLASS (sym
) != C_FCN
2205 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
2206 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
2207 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
2208 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
2210 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
2211 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
2214 union internal_auxent
*a
;
2216 /* Create a csect aux. */
2217 i
= S_GET_NUMBER_AUXILIARY (sym
);
2218 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
2219 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
2220 if (sym
->sy_tc
.class == XMC_TC0
)
2222 /* This is the TOC table. */
2223 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
2224 a
->x_csect
.x_scnlen
.l
= 0;
2225 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
2227 else if (sym
->sy_tc
.subseg
!= 0)
2229 /* This is a csect symbol. x_scnlen is the size of the
2231 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
2232 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
2233 S_GET_SEGMENT (sym
))
2234 - S_GET_VALUE (sym
));
2237 resolve_symbol_value (sym
->sy_tc
.next
);
2238 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
2239 - S_GET_VALUE (sym
));
2241 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
2243 else if (S_GET_SEGMENT (sym
) == bss_section
)
2245 /* This is a common symbol. */
2246 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
2247 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
2248 if (S_IS_EXTERNAL (sym
))
2249 sym
->sy_tc
.class = XMC_RW
;
2251 sym
->sy_tc
.class = XMC_BS
;
2253 else if (! S_IS_DEFINED (sym
))
2255 /* This is an external symbol. */
2256 a
->x_csect
.x_scnlen
.l
= 0;
2257 a
->x_csect
.x_smtyp
= XTY_ER
;
2259 else if (sym
->sy_tc
.class == XMC_TC
)
2263 /* This is a TOC definition. x_scnlen is the size of the
2265 next
= symbol_next (sym
);
2266 while (next
->sy_tc
.class == XMC_TC0
)
2267 next
= symbol_next (next
);
2268 if (next
== (symbolS
*) NULL
2269 || next
->sy_tc
.class != XMC_TC
)
2271 if (ppc_after_toc_frag
== (fragS
*) NULL
)
2272 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
2274 - S_GET_VALUE (sym
));
2276 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
2277 - S_GET_VALUE (sym
));
2281 resolve_symbol_value (next
);
2282 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
2283 - S_GET_VALUE (sym
));
2285 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
2291 /* This is a normal symbol definition. x_scnlen is the
2292 symbol index of the containing csect. */
2293 if (S_GET_SEGMENT (sym
) == text_section
)
2294 csect
= ppc_text_csects
;
2295 else if (S_GET_SEGMENT (sym
) == data_section
)
2296 csect
= ppc_data_csects
;
2300 /* Skip the initial dummy symbol. */
2301 csect
= csect
->sy_tc
.next
;
2303 if (csect
== (symbolS
*) NULL
)
2304 a
->x_csect
.x_scnlen
.l
= 0;
2307 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
2309 resolve_symbol_value (csect
->sy_tc
.next
);
2310 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
2312 csect
= csect
->sy_tc
.next
;
2315 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
2316 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
2318 a
->x_csect
.x_smtyp
= XTY_LD
;
2321 a
->x_csect
.x_parmhash
= 0;
2322 a
->x_csect
.x_snhash
= 0;
2323 if (sym
->sy_tc
.class == -1)
2324 a
->x_csect
.x_smclas
= XMC_PR
;
2326 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
2327 a
->x_csect
.x_stab
= 0;
2328 a
->x_csect
.x_snstab
= 0;
2330 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
2332 /* We want the value to be the symbol index of the referenced
2333 csect symbol. BFD will do that for us if we set the right
2336 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
2337 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
2339 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2344 /* The value is the offset from the enclosing csect. */
2345 block
= sym
->sy_tc
.within
;
2346 csect
= block
->sy_tc
.within
;
2347 resolve_symbol_value (csect
);
2348 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
2354 /* Set the VMA for a section. This is called on all the sections in
2358 ppc_frob_section (sec
)
2361 static bfd_size_type vma
= 0;
2363 bfd_set_section_vma (stdoutput
, sec
, vma
);
2364 vma
+= bfd_section_size (stdoutput
, sec
);
2367 /* Adjust the file by adding a .debug section if needed. */
2372 if (ppc_debug_name_section_size
> 0)
2376 sec
= bfd_make_section (stdoutput
, ".debug");
2377 if (sec
== (asection
*) NULL
2378 || ! bfd_set_section_size (stdoutput
, sec
,
2379 ppc_debug_name_section_size
)
2380 || ! bfd_set_section_flags (stdoutput
, sec
,
2381 SEC_HAS_CONTENTS
| SEC_LOAD
))
2382 as_fatal ("can't make .debug section");
2386 #endif /* OBJ_COFF */
2388 /* Turn a string in input_line_pointer into a floating point constant
2389 of type type, and store the appropriate bytes in *litp. The number
2390 of LITTLENUMS emitted is stored in *sizep . An error message is
2391 returned, or NULL on OK. */
2394 md_atof (type
, litp
, sizep
)
2400 LITTLENUM_TYPE words
[4];
2416 return "bad call to md_atof";
2419 t
= atof_ieee (input_line_pointer
, type
, words
);
2421 input_line_pointer
= t
;
2425 if (target_big_endian
)
2427 for (i
= 0; i
< prec
; i
++)
2429 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2435 for (i
= prec
- 1; i
>= 0; i
--)
2437 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2445 /* Write a value out to the object file, using the appropriate
2449 md_number_to_chars (buf
, val
, n
)
2454 if (target_big_endian
)
2455 number_to_chars_bigendian (buf
, val
, n
);
2457 number_to_chars_littleendian (buf
, val
, n
);
2460 /* Align a section (I don't know why this is machine dependent). */
2463 md_section_align (seg
, addr
)
2467 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2469 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
2472 /* We don't have any form of relaxing. */
2475 md_estimate_size_before_relax (fragp
, seg
)
2482 /* Convert a machine dependent frag. We never generate these. */
2485 md_convert_frag (abfd
, sec
, fragp
)
2493 /* We have no need to default values of symbols. */
2497 md_undefined_symbol (name
)
2503 /* Functions concerning relocs. */
2505 /* The location from which a PC relative jump should be calculated,
2506 given a PC relative reloc. */
2509 md_pcrel_from (fixp
)
2513 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2514 && ! S_IS_DEFINED (fixp
->fx_addsy
))
2518 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2523 /* This is called to see whether a fixup should be adjusted to use a
2524 section symbol. We take the opportunity to change a fixup against
2525 a symbol in the TOC subsegment into a reloc against the
2526 corresponding .tc symbol. */
2529 ppc_fix_adjustable (fix
)
2534 resolve_symbol_value (fix
->fx_addsy
);
2535 val
= S_GET_VALUE (fix
->fx_addsy
);
2536 if (ppc_toc_csect
!= (symbolS
*) NULL
2537 && fix
->fx_addsy
!= (symbolS
*) NULL
2538 && fix
->fx_addsy
!= ppc_toc_csect
2539 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
2540 && val
>= ppc_toc_frag
->fr_address
2541 && (ppc_after_toc_frag
== (fragS
*) NULL
2542 || val
< ppc_after_toc_frag
->fr_address
))
2546 for (sy
= symbol_next (ppc_toc_csect
);
2547 sy
!= (symbolS
*) NULL
;
2548 sy
= symbol_next (sy
))
2550 if (sy
->sy_tc
.class == XMC_TC0
)
2552 if (sy
->sy_tc
.class != XMC_TC
)
2554 resolve_symbol_value (sy
);
2555 if (val
== S_GET_VALUE (sy
))
2558 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
2563 as_bad_where (fix
->fx_file
, fix
->fx_line
,
2564 "symbol in .toc does not match any .tc");
2567 /* Possibly adjust the reloc to be against the csect. */
2568 if (fix
->fx_addsy
!= (symbolS
*) NULL
2569 && fix
->fx_addsy
->sy_tc
.subseg
== 0
2570 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
2571 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
2572 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
2576 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
2577 csect
= ppc_text_csects
;
2578 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
2579 csect
= ppc_data_csects
;
2583 /* Skip the initial dummy symbol. */
2584 csect
= csect
->sy_tc
.next
;
2586 if (csect
!= (symbolS
*) NULL
)
2588 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
2589 && (csect
->sy_tc
.next
->sy_frag
->fr_address
2590 <= fix
->fx_addsy
->sy_frag
->fr_address
))
2591 csect
= csect
->sy_tc
.next
;
2593 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2594 - csect
->sy_frag
->fr_address
);
2595 fix
->fx_addsy
= csect
;
2599 /* Adjust a reloc against a .lcomm symbol to be against the base
2601 if (fix
->fx_addsy
!= (symbolS
*) NULL
2602 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
2603 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
2605 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
2606 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2607 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
2608 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
2616 /* See whether a symbol is in the TOC section. */
2619 ppc_is_toc_sym (sym
)
2623 return sym
->sy_tc
.class == XMC_TC
;
2625 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
2629 /* Apply a fixup to the object code. This is called for all the
2630 fixups we generated by the call to fix_new_exp, above. In the call
2631 above we used a reloc code which was the largest legal reloc code
2632 plus the operand index. Here we undo that to recover the operand
2633 index. At this point all symbol values should be fully resolved,
2634 and we attempt to completely resolve the reloc. If we can not do
2635 that, we determine the correct reloc code and put it back in the
2639 md_apply_fix3 (fixp
, valuep
, seg
)
2646 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
2647 the symbol values. Since we are using BFD_ASSEMBLER, if we are
2648 doing this relocation the code in write.c is going to call
2649 bfd_perform_relocation, which is also going to use the symbol
2650 value. That means that if the reloc is fully resolved we want to
2651 use *valuep since bfd_perform_relocation is not being used.
2652 However, if the reloc is not fully resolved we do not want to use
2653 *valuep, and must use fx_offset instead. However, if the reloc
2654 is PC relative, we do want to use *valuep since it includes the
2655 result of md_pcrel_from. This is confusing. */
2657 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2662 else if (fixp
->fx_pcrel
)
2666 value
= fixp
->fx_offset
;
2667 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2669 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2670 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2673 /* We can't actually support subtracting a symbol. */
2674 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2675 "expression too complex");
2680 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2683 const struct powerpc_operand
*operand
;
2687 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2689 operand
= &powerpc_operands
[opindex
];
2692 /* It appears that an instruction like
2694 when LC..1 is not a TOC symbol does not generate a reloc. It
2695 uses the offset of LC..1 within its csect. However, .long
2696 LC..1 will generate a reloc. I can't find any documentation
2697 on how these cases are to be distinguished, so this is a wild
2698 guess. These cases are generated by gcc -mminimal-toc. */
2699 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2700 && operand
->bits
== 16
2701 && operand
->shift
== 0
2702 && operand
->insert
== NULL
2703 && fixp
->fx_addsy
!= NULL
2704 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
2705 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
2706 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
2707 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
2709 value
= fixp
->fx_offset
;
2714 /* Fetch the instruction, insert the fully resolved operand
2715 value, and stuff the instruction back again. */
2716 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2717 if (target_big_endian
)
2718 insn
= bfd_getb32 ((unsigned char *) where
);
2720 insn
= bfd_getl32 ((unsigned char *) where
);
2721 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
2722 fixp
->fx_file
, fixp
->fx_line
);
2723 if (target_big_endian
)
2724 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2726 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2730 /* Nothing else to do here. */
2734 /* Determine a BFD reloc value based on the operand information.
2735 We are only prepared to turn a few of the operands into
2737 FIXME: We need to handle the DS field at the very least.
2738 FIXME: Handling 16 bit branches would also be reasonable.
2739 FIXME: Selecting the reloc type is a bit haphazard; perhaps
2740 there should be a new field in the operand table. */
2741 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
2742 && operand
->bits
== 26
2743 && operand
->shift
== 0)
2744 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
2745 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
2746 && operand
->bits
== 26
2747 && operand
->shift
== 0)
2748 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
2749 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2750 && operand
->bits
== 16
2751 && operand
->shift
== 0
2752 && operand
->insert
== NULL
2753 && fixp
->fx_addsy
!= NULL
2754 && ppc_is_toc_sym (fixp
->fx_addsy
))
2757 if (target_big_endian
)
2758 fixp
->fx_where
+= 2;
2759 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
2763 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2764 "unresolved expression that must be resolved");
2772 ppc_elf_validate_fix (fixp
, seg
);
2774 switch (fixp
->fx_r_type
)
2777 case BFD_RELOC_CTOR
:
2780 fixp
->fx_r_type
= BFD_RELOC_32_PCREL
;
2781 value
+= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2782 } /* fall through */
2784 case BFD_RELOC_32_PCREL
:
2785 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2789 case BFD_RELOC_LO16
:
2790 case BFD_RELOC_HI16
:
2791 case BFD_RELOC_HI16_S
:
2792 case BFD_RELOC_PPC_TOC16
:
2794 case BFD_RELOC_GPREL16
:
2798 case BFD_RELOC_PPC_B16_BRTAKEN
:
2799 case BFD_RELOC_PPC_B16_BRNTAKEN
:
2801 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2809 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2819 fixp
->fx_addnumber
= value
;
2821 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
2822 fixp
->fx_addnumber
= 0;
2825 /* We want to use the offset within the data segment of the
2826 symbol, not the actual VMA of the symbol. */
2827 fixp
->fx_addnumber
=
2828 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
2835 /* Generate a reloc for a fixup. */
2838 tc_gen_reloc (seg
, fixp
)
2844 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2846 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2847 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2848 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2849 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2851 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2852 "reloc %d not supported by object file format", (int)fixp
->fx_r_type
);
2855 reloc
->addend
= fixp
->fx_addnumber
;