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, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "opcode/ppc.h"
28 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
30 /* FIXME: This should be handled in a different way. */
31 extern int target_big_endian
;
33 static void ppc_set_cpu
PARAMS ((void));
34 static unsigned long ppc_insert_operand
35 PARAMS ((unsigned long insn
, const struct powerpc_operand
*operand
,
36 offsetT val
, char *file
, unsigned int line
));
37 static void ppc_macro
PARAMS ((char *str
, const struct powerpc_macro
*macro
));
38 static void ppc_byte
PARAMS ((int));
39 static int ppc_is_toc_sym
PARAMS ((symbolS
*sym
));
40 static void ppc_tc
PARAMS ((int));
42 static void ppc_comm
PARAMS ((int));
43 static void ppc_bb
PARAMS ((int));
44 static void ppc_bf
PARAMS ((int));
45 static void ppc_biei
PARAMS ((int));
46 static void ppc_bs
PARAMS ((int));
47 static void ppc_eb
PARAMS ((int));
48 static void ppc_ef
PARAMS ((int));
49 static void ppc_es
PARAMS ((int));
50 static void ppc_csect
PARAMS ((int));
51 static void ppc_function
PARAMS ((int));
52 static void ppc_extern
PARAMS ((int));
53 static void ppc_lglobl
PARAMS ((int));
54 static void ppc_stabx
PARAMS ((int));
55 static void ppc_rename
PARAMS ((int));
56 static void ppc_toc
PARAMS ((int));
59 /* Generic assembler global variables which must be defined by all
62 /* Characters which always start a comment. */
63 const char comment_chars
[] = "#";
65 /* Characters which start a comment at the beginning of a line. */
66 const char line_comment_chars
[] = "#";
68 /* Characters which may be used to separate multiple commands on a
70 const char line_separator_chars
[] = ";";
72 /* Characters which are used to indicate an exponent in a floating
74 const char EXP_CHARS
[] = "eE";
76 /* Characters which mean that a number is a floating point constant,
78 const char FLT_CHARS
[] = "dD";
80 /* The target specific pseudo-ops which we support. */
82 const pseudo_typeS md_pseudo_table
[] =
84 /* Pseudo-ops which must be overridden. */
85 { "byte", ppc_byte
, 0 },
88 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
89 legitimately belong in the obj-*.c file. However, XCOFF is based
90 on COFF, and is only implemented for the RS/6000. We just use
91 obj-coff.c, and add what we need here. */
92 { "comm", ppc_comm
, 0 },
93 { "lcomm", ppc_comm
, 1 },
96 { "bi", ppc_biei
, 0 },
98 { "csect", ppc_csect
, 0 },
101 { "ei", ppc_biei
, 1 },
103 { "extern", ppc_extern
, 0 },
104 { "function", ppc_function
, 0 },
105 { "lglobl", ppc_lglobl
, 0 },
106 { "rename", ppc_rename
, 0 },
107 { "stabx", ppc_stabx
, 0 },
108 { "toc", ppc_toc
, 0 },
111 /* This pseudo-op is used even when not generating XCOFF output. */
117 /* Local variables. */
119 /* The type of processor we are assembling for. This is one or more
120 of the PPC_OPCODE flags defined in opcode/ppc.h. */
121 static int ppc_cpu
= 0;
123 /* The size of the processor we are assembling for. This is either
124 PPC_OPCODE_32 or PPC_OPCODE_64. */
125 static int ppc_size
= PPC_OPCODE_32
;
127 /* The endianness we are using. */
128 static int ppc_big_endian
= PPC_BIG_ENDIAN
;
130 /* Opcode hash table. */
131 static struct hash_control
*ppc_hash
;
133 /* Macro hash table. */
134 static struct hash_control
*ppc_macro_hash
;
138 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
139 using a bunch of different sections. These assembler sections,
140 however, are all encompassed within the .text or .data sections of
141 the final output file. We handle this by using different
142 subsegments within these main segments. */
144 /* Next subsegment to allocate within the .text segment. */
145 static subsegT ppc_text_subsegment
= 2;
147 /* Linked list of csects in the text section. */
148 static symbolS
*ppc_text_csects
;
150 /* Next subsegment to allocate within the .data segment. */
151 static subsegT ppc_data_subsegment
= 2;
153 /* Linked list of csects in the data section. */
154 static symbolS
*ppc_data_csects
;
156 /* The current csect. */
157 static symbolS
*ppc_current_csect
;
159 /* The RS/6000 assembler uses a TOC which holds addresses of functions
160 and variables. Symbols are put in the TOC with the .tc pseudo-op.
161 A special relocation is used when accessing TOC entries. We handle
162 the TOC as a subsegment within the .data segment. We set it up if
163 we see a .toc pseudo-op, and save the csect symbol here. */
164 static symbolS
*ppc_toc_csect
;
166 /* The first frag in the TOC subsegment. */
167 static fragS
*ppc_toc_frag
;
169 /* The first frag in the first subsegment after the TOC in the .data
170 segment. NULL if there are no subsegments after the TOC. */
171 static fragS
*ppc_after_toc_frag
;
173 /* The current static block. */
174 static symbolS
*ppc_current_block
;
176 /* The COFF debugging section; set by md_begin. This is not the
177 .debug section, but is instead the secret BFD section which will
178 cause BFD to set the section number of a symbol to N_DEBUG. */
179 static asection
*ppc_coff_debug_section
;
181 /* The size of the .debug section. */
182 static bfd_size_type ppc_debug_name_section_size
;
184 #endif /* OBJ_COFF */
187 CONST
char *md_shortopts
= "um:VQ:";
189 CONST
char *md_shortopts
= "um:";
191 struct option md_longopts
[] = {
192 {NULL
, no_argument
, NULL
, 0}
194 size_t md_longopts_size
= sizeof(md_longopts
);
197 md_parse_option (c
, arg
)
204 /* -u means that any undefined symbols should be treated as
205 external, which is the default for gas anyhow. */
209 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
211 if (strcmp (arg
, "pwrx") == 0 || strcmp (arg
, "pwr2") == 0)
212 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
213 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
214 else if (strcmp (arg
, "pwr") == 0)
215 ppc_cpu
= PPC_OPCODE_POWER
;
216 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
217 ignore the option for now, but we should really use it to permit
218 instructions defined on the 601 that are not part of the standard
219 PowerPC architecture (mostly holdovers from the POWER). */
220 else if (strcmp (arg
, "601") == 0)
221 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
222 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
223 Motorola PowerPC 603/604. */
224 else if (strcmp (arg
, "ppc") == 0
225 || strcmp (arg
, "ppc32") == 0
226 || strcmp (arg
, "603") == 0
227 || strcmp (arg
, "604") == 0)
228 ppc_cpu
= PPC_OPCODE_PPC
;
229 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
231 else if (strcmp (arg
, "ppc64") == 0 || strcmp (arg
, "620") == 0)
233 ppc_cpu
= PPC_OPCODE_PPC
;
234 ppc_size
= PPC_OPCODE_64
;
236 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
237 else if (strcmp (arg
, "any") == 0)
238 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
241 as_bad ("invalid architecture -m%s", arg
);
247 /* -V: SVR4 argument to print version ID. */
252 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
253 should be emitted or not. FIXME: Not implemented. */
266 md_show_usage (stream
)
272 -mpwrx generate code for IBM POWER/2 (RIOS2)\n\
273 -mpwr generate code for IBM POWER (RIOS1)\n\
274 -m601 generate code for Motorola PowerPC 601\n\
275 -mppc generate code for Motorola PowerPC 603/604\n\
276 -many generate code for any architecture (PWR/PWRX/PPC)\n");
279 -V print assembler version number\n\
280 -Qy, -Qn ignored\n");
284 /* Set ppc_cpu if it is not already set. */
289 const char *default_cpu
= TARGET_CPU
;
293 if (strcmp (default_cpu
, "rs6000") == 0)
294 ppc_cpu
= PPC_OPCODE_POWER
;
295 else if (strcmp (default_cpu
, "powerpc") == 0)
296 ppc_cpu
= PPC_OPCODE_PPC
;
302 /* Figure out the BFD architecture to use. */
304 enum bfd_architecture
309 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
310 return bfd_arch_powerpc
;
311 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
312 return bfd_arch_rs6000
;
317 /* This function is called when the assembler starts up. It is called
318 after the options have been parsed and the output file has been
324 register const struct powerpc_opcode
*op
;
325 const struct powerpc_opcode
*op_end
;
326 const struct powerpc_macro
*macro
;
327 const struct powerpc_macro
*macro_end
;
331 /* Insert the opcodes into a hash table. */
332 ppc_hash
= hash_new ();
334 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
335 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
337 know ((op
->opcode
& op
->mask
) == op
->opcode
);
339 if ((op
->flags
& ppc_cpu
) != 0
340 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
341 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
345 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
346 if (retval
!= (const char *) NULL
)
348 /* When using -many, the comparison instructions are a
349 harmless special case. */
350 if (ppc_cpu
!= (PPC_OPCODE_POWER
353 || (strcmp (op
->name
, "cmpli") != 0
354 && strcmp (op
->name
, "cmpi") != 0
355 && strcmp (op
->name
, "cmp") != 0
356 && strcmp (op
->name
, "cmpl") != 0))
362 /* Insert the macros into a hash table. */
363 ppc_macro_hash
= hash_new ();
365 macro_end
= powerpc_macros
+ powerpc_num_macros
;
366 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
368 if ((macro
->flags
& ppc_cpu
) != 0)
372 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
373 if (retval
!= (const char *) NULL
)
378 /* Tell the main code what the endianness is. */
379 target_big_endian
= ppc_big_endian
;
382 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
384 /* Create dummy symbols to serve as initial csects. This forces the
385 text csects to precede the data csects. These symbols will not
387 ppc_text_csects
= symbol_make ("dummy\001");
388 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
389 ppc_data_csects
= symbol_make ("dummy\001");
390 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
394 /* Insert an operand value into an instruction. */
397 ppc_insert_operand (insn
, operand
, val
, file
, line
)
399 const struct powerpc_operand
*operand
;
404 if (operand
->bits
!= 32)
409 if ((operand
->flags
& PPC_OPERAND_SIGNED
) != 0)
411 if ((operand
->flags
& PPC_OPERAND_SIGNOPT
) != 0
412 && ppc_size
== PPC_OPCODE_32
)
413 max
= (1 << operand
->bits
) - 1;
415 max
= (1 << (operand
->bits
- 1)) - 1;
416 min
= - (1 << (operand
->bits
- 1));
420 max
= (1 << operand
->bits
) - 1;
424 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
429 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
432 "operand out of range (%s not between %ld and %ld)";
435 sprint_value (buf
, test
);
436 if (file
== (char *) NULL
)
437 as_warn (err
, buf
, min
, max
);
439 as_warn_where (file
, line
, err
, buf
, min
, max
);
448 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
449 if (errmsg
!= (const char *) NULL
)
453 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
459 /* We need to keep a list of fixups. We can't simply generate them as
460 we go, because that would require us to first create the frag, and
461 that would screw up references to ``.''. */
469 #define MAX_INSN_FIXUPS (5)
471 /* This routine is called for each instruction to be assembled. */
478 const struct powerpc_opcode
*opcode
;
480 const unsigned char *opindex_ptr
;
484 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
489 /* Get the opcode. */
490 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
495 /* Look up the opcode in the hash table. */
496 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
497 if (opcode
== (const struct powerpc_opcode
*) NULL
)
499 const struct powerpc_macro
*macro
;
501 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
502 if (macro
== (const struct powerpc_macro
*) NULL
)
503 as_bad ("Unrecognized opcode: `%s'", str
);
505 ppc_macro (s
, macro
);
510 insn
= opcode
->opcode
;
513 while (isspace (*str
))
516 /* PowerPC operands are just expressions. The only real issue is
517 that a few operand types are optional. All cases which might use
518 an optional operand separate the operands only with commas (in
519 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
520 cases never have optional operands). There is never more than
521 one optional operand for an instruction. So, before we start
522 seriously parsing the operands, we check to see if we have an
523 optional operand, and, if we do, we count the number of commas to
524 see whether the operand should be omitted. */
526 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
528 const struct powerpc_operand
*operand
;
530 operand
= &powerpc_operands
[*opindex_ptr
];
531 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
533 unsigned int opcount
;
535 /* There is an optional operand. Count the number of
536 commas in the input line. */
543 while ((s
= strchr (s
, ',')) != (char *) NULL
)
550 /* If there are fewer operands in the line then are called
551 for by the instruction, we want to skip the optional
553 if (opcount
< strlen (opcode
->operands
))
560 /* Gather the operands. */
564 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
566 const struct powerpc_operand
*operand
;
572 if (next_opindex
== 0)
573 operand
= &powerpc_operands
[*opindex_ptr
];
576 operand
= &powerpc_operands
[next_opindex
];
582 /* If this is a fake operand, then we do not expect anything
584 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
586 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
587 if (errmsg
!= (const char *) NULL
)
592 /* If this is an optional operand, and we are skipping it, just
594 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
599 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
600 if (errmsg
!= (const char *) NULL
)
603 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
604 next_opindex
= *opindex_ptr
+ 1;
608 /* Gather the operand. */
609 hold
= input_line_pointer
;
610 input_line_pointer
= str
;
612 str
= input_line_pointer
;
613 input_line_pointer
= hold
;
615 if (ex
.X_op
== O_illegal
)
616 as_bad ("illegal operand");
617 else if (ex
.X_op
== O_absent
)
618 as_bad ("missing operand");
619 else if (ex
.X_op
== O_constant
)
620 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
624 /* We need to generate a fixup for this expression. */
625 if (fc
>= MAX_INSN_FIXUPS
)
626 as_fatal ("too many fixups");
628 fixups
[fc
].opindex
= *opindex_ptr
;
637 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
645 /* The call to expression should have advanced str past any
648 && (endc
!= ',' || *str
!= '\0'))
650 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
658 while (isspace (*str
))
662 as_bad ("junk at end of line: `%s'", str
);
664 /* Write out the instruction. */
666 md_number_to_chars (f
, insn
, 4);
668 /* Create any fixups. At this point we do not use a
669 bfd_reloc_code_real_type, but instead just use the operand index.
670 This lets us easily handle fixups for any operand type, although
671 that is admittedly not a very exciting feature. We pick a BFD
672 reloc type in md_apply_fix. */
673 for (i
= 0; i
< fc
; i
++)
675 const struct powerpc_operand
*operand
;
677 operand
= &powerpc_operands
[fixups
[i
].opindex
];
678 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
680 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
681 ((bfd_reloc_code_real_type
)
682 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
686 /* Handle a macro. Gather all the operands, transform them as
687 described by the macro, and call md_assemble recursively. All the
688 operands are separated by commas; we don't accept parentheses
689 around operands here. */
692 ppc_macro (str
, macro
)
694 const struct powerpc_macro
*macro
;
705 /* Gather the users operands into the operands array. */
710 if (count
>= sizeof operands
/ sizeof operands
[0])
712 operands
[count
++] = s
;
714 if (s
== (char *) NULL
)
719 if (count
!= macro
->operands
)
721 as_bad ("wrong number of operands");
725 /* Work out how large the string must be (the size is unbounded
726 because it includes user input). */
728 format
= macro
->format
;
729 while (*format
!= '\0')
738 arg
= strtol (format
+ 1, &send
, 10);
739 know (send
!= format
&& arg
>= 0 && arg
< count
);
740 len
+= strlen (operands
[arg
]);
745 /* Put the string together. */
746 complete
= s
= (char *) alloca (len
+ 1);
747 format
= macro
->format
;
748 while (*format
!= '\0')
754 arg
= strtol (format
+ 1, &send
, 10);
755 strcpy (s
, operands
[arg
]);
762 /* Assemble the constructed instruction. */
763 md_assemble (complete
);
766 /* Pseudo-op handling. */
768 /* The .byte pseudo-op. This is similar to the normal .byte
769 pseudo-op, but it can also take a single ASCII string. */
775 if (*input_line_pointer
!= '\"')
781 /* Gather characters. A real double quote is doubled. Unusual
782 characters are not permitted. */
783 ++input_line_pointer
;
788 c
= *input_line_pointer
++;
792 if (*input_line_pointer
!= '\"')
794 ++input_line_pointer
;
797 FRAG_APPEND_1_CHAR (c
);
800 demand_empty_rest_of_line ();
805 /* XCOFF specific pseudo-op handling. */
807 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
808 symbols in the .bss segment as though they were local common
809 symbols, and uses a different smclas. */
815 asection
*current_seg
= now_seg
;
816 subsegT current_subseg
= now_subseg
;
822 symbolS
*lcomm_sym
= NULL
;
826 name
= input_line_pointer
;
827 endc
= get_symbol_end ();
828 end_name
= input_line_pointer
;
831 if (*input_line_pointer
!= ',')
833 as_bad ("missing size");
834 ignore_rest_of_line ();
837 ++input_line_pointer
;
839 size
= get_absolute_expression ();
842 as_bad ("negative size");
843 ignore_rest_of_line ();
849 /* The third argument to .comm is the alignment. */
850 if (*input_line_pointer
!= ',')
854 ++input_line_pointer
;
855 align
= get_absolute_expression ();
858 as_warn ("ignoring bad alignment");
877 /* The third argument to .lcomm appears to be the real local
878 common symbol to create. References to the symbol named in
879 the first argument are turned into references to the third
881 if (*input_line_pointer
!= ',')
883 as_bad ("missing real symbol name");
884 ignore_rest_of_line ();
887 ++input_line_pointer
;
889 lcomm_name
= input_line_pointer
;
890 lcomm_endc
= get_symbol_end ();
892 lcomm_sym
= symbol_find_or_make (lcomm_name
);
894 *input_line_pointer
= lcomm_endc
;
898 sym
= symbol_find_or_make (name
);
901 if (S_IS_DEFINED (sym
)
902 || S_GET_VALUE (sym
) != 0)
904 as_bad ("attempt to redefine symbol");
905 ignore_rest_of_line ();
909 record_alignment (bss_section
, align
);
912 || ! S_IS_DEFINED (lcomm_sym
))
921 S_SET_EXTERNAL (sym
);
925 lcomm_sym
->sy_tc
.output
= 1;
930 subseg_set (bss_section
, 1);
931 frag_align (align
, 0);
933 def_sym
->sy_frag
= frag_now
;
934 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
935 def_size
, (char *) NULL
);
937 S_SET_SEGMENT (def_sym
, bss_section
);
938 def_sym
->sy_tc
.align
= align
;
942 /* Align the size of lcomm_sym. */
943 lcomm_sym
->sy_frag
->fr_offset
=
944 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
945 &~ ((1 << align
) - 1));
946 if (align
> lcomm_sym
->sy_tc
.align
)
947 lcomm_sym
->sy_tc
.align
= align
;
952 /* Make sym an offset from lcomm_sym. */
953 S_SET_SEGMENT (sym
, bss_section
);
954 sym
->sy_frag
= lcomm_sym
->sy_frag
;
955 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
956 lcomm_sym
->sy_frag
->fr_offset
+= size
;
959 subseg_set (current_seg
, current_subseg
);
961 demand_empty_rest_of_line ();
964 /* The .csect pseudo-op. This switches us into a different
965 subsegment. The first argument is a symbol whose value is the
966 start of the .csect. In COFF, csect symbols get special aux
967 entries defined by the x_csect field of union internal_auxent. The
968 optional second argument is the alignment (the default is 2). */
978 name
= input_line_pointer
;
979 endc
= get_symbol_end ();
981 sym
= symbol_find_or_make (name
);
983 *input_line_pointer
= endc
;
985 if (S_IS_DEFINED (sym
))
986 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
993 /* This is a new csect. We need to look at the symbol class to
994 figure out whether it should go in the text section or the
997 switch (sym
->sy_tc
.class)
1007 S_SET_SEGMENT (sym
, text_section
);
1008 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
1009 ++ppc_text_subsegment
;
1010 list_ptr
= &ppc_text_csects
;
1019 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
1021 S_SET_SEGMENT (sym
, data_section
);
1022 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
1023 ++ppc_data_subsegment
;
1024 list_ptr
= &ppc_data_csects
;
1030 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1032 ppc_after_toc_frag
= frag_now
;
1034 sym
->sy_frag
= frag_now
;
1035 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1037 sym
->sy_tc
.align
= 2;
1038 sym
->sy_tc
.output
= 1;
1039 sym
->sy_tc
.within
= sym
;
1041 for (list
= *list_ptr
;
1042 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1043 list
= list
->sy_tc
.next
)
1045 list
->sy_tc
.next
= sym
;
1047 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1048 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1051 if (*input_line_pointer
== ',')
1053 ++input_line_pointer
;
1054 sym
->sy_tc
.align
= get_absolute_expression ();
1057 ppc_current_csect
= sym
;
1059 demand_empty_rest_of_line ();
1062 /* The .extern pseudo-op. We create an undefined symbol. */
1071 name
= input_line_pointer
;
1072 endc
= get_symbol_end ();
1074 (void) symbol_find_or_make (name
);
1076 *input_line_pointer
= endc
;
1078 demand_empty_rest_of_line ();
1081 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1082 this because it can't handle undefined symbols. I think we can
1092 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1093 although I don't know why it bothers. */
1104 name
= input_line_pointer
;
1105 endc
= get_symbol_end ();
1107 sym
= symbol_find_or_make (name
);
1109 *input_line_pointer
= endc
;
1111 if (*input_line_pointer
!= ',')
1113 as_bad ("missing rename string");
1114 ignore_rest_of_line ();
1117 ++input_line_pointer
;
1119 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1121 demand_empty_rest_of_line ();
1124 /* The .stabx pseudo-op. This is similar to a normal .stabs
1125 pseudo-op, but slightly different. A sample is
1126 .stabx "main:F-1",.main,142,0
1127 The first argument is the symbol name to create. The second is the
1128 value, and the third is the storage class. The fourth seems to be
1129 always zero, and I am assuming it is the type. */
1140 name
= demand_copy_C_string (&len
);
1142 if (*input_line_pointer
!= ',')
1144 as_bad ("missing value");
1147 ++input_line_pointer
;
1149 sym
= symbol_make (name
);
1151 (void) expression (&exp
);
1158 as_bad ("illegal .stabx expression; zero assumed");
1159 exp
.X_add_number
= 0;
1162 S_SET_VALUE (sym
, (valueT
) exp
.X_add_number
);
1163 sym
->sy_frag
= &zero_address_frag
;
1167 if (S_GET_SEGMENT (exp
.X_add_symbol
) == undefined_section
)
1168 sym
->sy_value
= exp
;
1172 exp
.X_add_number
+ S_GET_VALUE (exp
.X_add_symbol
));
1173 sym
->sy_frag
= exp
.X_add_symbol
->sy_frag
;
1178 /* The value is some complex expression. This will probably
1179 fail at some later point, but this is probably the right
1180 thing to do here. */
1181 sym
->sy_value
= exp
;
1185 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1186 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1188 if (*input_line_pointer
!= ',')
1190 as_bad ("missing class");
1193 ++input_line_pointer
;
1195 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1197 if (*input_line_pointer
!= ',')
1199 as_bad ("missing type");
1202 ++input_line_pointer
;
1204 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1206 sym
->sy_tc
.output
= 1;
1208 if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
1209 sym
->sy_tc
.within
= ppc_current_block
;
1211 if (exp
.X_op
!= O_symbol
1212 || ! S_IS_EXTERNAL (exp
.X_add_symbol
)
1213 || S_GET_SEGMENT (exp
.X_add_symbol
) != bss_section
)
1214 ppc_frob_label (sym
);
1217 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1218 symbol_append (sym
, exp
.X_add_symbol
, &symbol_rootP
, &symbol_lastP
);
1219 if (ppc_current_csect
->sy_tc
.within
== exp
.X_add_symbol
)
1220 ppc_current_csect
->sy_tc
.within
= sym
;
1223 if (strlen (name
) > SYMNMLEN
)
1225 /* For some reason, each name is preceded by a two byte length
1226 and followed by a null byte. */
1227 ppc_debug_name_section_size
+= strlen (name
) + 3;
1230 demand_empty_rest_of_line ();
1233 /* The .function pseudo-op. This takes several arguments. The first
1234 argument seems to be the external name of the symbol. The second
1235 argment seems to be the label for the start of the function. gcc
1236 uses the same name for both. I have no idea what the third and
1237 fourth arguments are meant to be. The optional fifth argument is
1238 an expression for the size of the function. In COFF this symbol
1239 gets an aux entry like that used for a csect. */
1242 ppc_function (ignore
)
1251 name
= input_line_pointer
;
1252 endc
= get_symbol_end ();
1254 /* Ignore any [PR] suffix. */
1255 name
= ppc_canonicalize_symbol_name (name
);
1256 s
= strchr (name
, '[');
1257 if (s
!= (char *) NULL
1258 && strcmp (s
+ 1, "PR]") == 0)
1261 ext_sym
= symbol_find_or_make (name
);
1263 *input_line_pointer
= endc
;
1265 if (*input_line_pointer
!= ',')
1267 as_bad ("missing symbol name");
1268 ignore_rest_of_line ();
1271 ++input_line_pointer
;
1273 name
= input_line_pointer
;
1274 endc
= get_symbol_end ();
1276 lab_sym
= symbol_find_or_make (name
);
1278 *input_line_pointer
= endc
;
1280 if (ext_sym
!= lab_sym
)
1282 ext_sym
->sy_value
.X_op
= O_symbol
;
1283 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1284 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1285 ext_sym
->sy_value
.X_add_number
= 0;
1288 if (ext_sym
->sy_tc
.class == -1)
1289 ext_sym
->sy_tc
.class = XMC_PR
;
1290 ext_sym
->sy_tc
.output
= 1;
1292 if (*input_line_pointer
== ',')
1296 /* Ignore the third argument. */
1297 ++input_line_pointer
;
1298 expression (&ignore
);
1299 if (*input_line_pointer
== ',')
1301 /* Ignore the fourth argument. */
1302 ++input_line_pointer
;
1303 expression (&ignore
);
1304 if (*input_line_pointer
== ',')
1306 /* The fifth argument is the function size. */
1307 ++input_line_pointer
;
1308 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
1311 &zero_address_frag
);
1312 pseudo_set (ext_sym
->sy_tc
.size
);
1317 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
1318 SF_SET_FUNCTION (ext_sym
);
1319 SF_SET_PROCESS (ext_sym
);
1320 coff_add_linesym (ext_sym
);
1322 demand_empty_rest_of_line ();
1325 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
1334 sym
= symbol_make (".bf");
1335 S_SET_SEGMENT (sym
, text_section
);
1336 sym
->sy_frag
= frag_now
;
1337 S_SET_VALUE (sym
, frag_now_fix ());
1338 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1340 coff_line_base
= get_absolute_expression ();
1342 S_SET_NUMBER_AUXILIARY (sym
, 1);
1343 SA_SET_SYM_LNNO (sym
, coff_line_base
);
1345 sym
->sy_tc
.output
= 1;
1347 ppc_frob_label (sym
);
1349 demand_empty_rest_of_line ();
1352 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
1353 ".ef", except that the line number is absolute, not relative to the
1354 most recent ".bf" symbol. */
1362 sym
= symbol_make (".ef");
1363 S_SET_SEGMENT (sym
, text_section
);
1364 sym
->sy_frag
= frag_now
;
1365 S_SET_VALUE (sym
, frag_now_fix ());
1366 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1367 S_SET_NUMBER_AUXILIARY (sym
, 1);
1368 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1369 sym
->sy_tc
.output
= 1;
1371 ppc_frob_label (sym
);
1373 demand_empty_rest_of_line ();
1376 /* The .bi and .ei pseudo-ops. These take a string argument and
1377 generates a C_BINCL or C_EINCL symbol, which goes at the start of
1389 name
= demand_copy_C_string (&len
);
1391 sym
= symbol_make (name
);
1392 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1393 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1395 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
1396 offset in the file to the line number entry to use. That is
1397 quite difficult to implement using BFD, so I'm just not doing it.
1398 Sorry. Please add it if you can figure out how. Note that this
1399 approach is the only way to support multiple files in COFF, since
1400 line numbers are associated with function symbols. Note further
1401 that it still doesn't work, since the line numbers are stored as
1402 offsets from a base line number. */
1404 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
1405 sym
->sy_tc
.output
= 1;
1407 for (look
= symbol_rootP
;
1408 (look
!= (symbolS
*) NULL
1409 && (S_GET_STORAGE_CLASS (look
) == C_FILE
1410 || S_GET_STORAGE_CLASS (look
) == C_BINCL
1411 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
1412 look
= symbol_next (look
))
1414 if (look
!= (symbolS
*) NULL
)
1416 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1417 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
1420 demand_empty_rest_of_line ();
1423 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
1424 There is one argument, which is a csect symbol. The value of the
1425 .bs symbol is the index of this csect symbol. */
1436 if (ppc_current_block
!= NULL
)
1437 as_bad ("nested .bs blocks");
1439 name
= input_line_pointer
;
1440 endc
= get_symbol_end ();
1442 csect
= symbol_find_or_make (name
);
1444 *input_line_pointer
= endc
;
1446 sym
= symbol_make (".bs");
1447 S_SET_SEGMENT (sym
, now_seg
);
1448 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
1449 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1450 sym
->sy_tc
.output
= 1;
1452 sym
->sy_tc
.within
= csect
;
1454 ppc_frob_label (sym
);
1456 ppc_current_block
= sym
;
1458 demand_empty_rest_of_line ();
1461 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
1469 if (ppc_current_block
== NULL
)
1470 as_bad (".es without preceding .bs");
1472 sym
= symbol_make (".es");
1473 S_SET_SEGMENT (sym
, now_seg
);
1474 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
1475 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1476 sym
->sy_tc
.output
= 1;
1478 ppc_frob_label (sym
);
1480 ppc_current_block
= NULL
;
1482 demand_empty_rest_of_line ();
1485 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
1494 sym
= symbol_make (".bb");
1495 S_SET_SEGMENT (sym
, text_section
);
1496 sym
->sy_frag
= frag_now
;
1497 S_SET_VALUE (sym
, frag_now_fix ());
1498 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
1500 S_SET_NUMBER_AUXILIARY (sym
, 1);
1501 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1503 sym
->sy_tc
.output
= 1;
1505 ppc_frob_label (sym
);
1507 demand_empty_rest_of_line ();
1510 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
1519 sym
= symbol_make (".eb");
1520 S_SET_SEGMENT (sym
, text_section
);
1521 sym
->sy_frag
= frag_now
;
1522 S_SET_VALUE (sym
, frag_now_fix ());
1523 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1524 S_SET_NUMBER_AUXILIARY (sym
, 1);
1525 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1526 sym
->sy_tc
.output
= 1;
1528 ppc_frob_label (sym
);
1530 demand_empty_rest_of_line ();
1533 /* The .toc pseudo-op. Switch to the .toc subsegment. */
1539 if (ppc_toc_csect
!= (symbolS
*) NULL
)
1540 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
1547 subseg
= ppc_data_subsegment
;
1548 ++ppc_data_subsegment
;
1550 subseg_new (segment_name (data_section
), subseg
);
1551 ppc_toc_frag
= frag_now
;
1553 sym
= symbol_find_or_make ("TOC[TC0]");
1554 sym
->sy_frag
= frag_now
;
1555 S_SET_SEGMENT (sym
, data_section
);
1556 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1557 sym
->sy_tc
.subseg
= subseg
;
1558 sym
->sy_tc
.output
= 1;
1559 sym
->sy_tc
.within
= sym
;
1561 ppc_toc_csect
= sym
;
1563 for (list
= ppc_data_csects
;
1564 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1565 list
= list
->sy_tc
.next
)
1567 list
->sy_tc
.next
= sym
;
1569 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1570 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1573 ppc_current_csect
= ppc_toc_csect
;
1575 demand_empty_rest_of_line ();
1578 #endif /* OBJ_COFF */
1580 /* The .tc pseudo-op. This is used when generating either XCOFF or
1581 ELF. This takes two or more arguments.
1583 When generating XCOFF output, the first argument is the name to
1584 give to this location in the toc; this will be a symbol with class
1585 TC. The rest of the arguments are 4 byte values to actually put at
1586 this location in the TOC; often there is just one more argument, a
1587 relocateable symbol reference.
1589 When not generating XCOFF output, the arguments are the same, but
1590 the first argument is simply ignored. */
1598 /* Define the TOC symbol name. */
1604 if (ppc_toc_csect
== (symbolS
*) NULL
1605 || ppc_toc_csect
!= ppc_current_csect
)
1607 as_bad (".tc not in .toc section");
1608 ignore_rest_of_line ();
1612 name
= input_line_pointer
;
1613 endc
= get_symbol_end ();
1615 sym
= symbol_find_or_make (name
);
1617 *input_line_pointer
= endc
;
1619 if (S_IS_DEFINED (sym
))
1623 label
= ppc_current_csect
->sy_tc
.within
;
1624 if (label
->sy_tc
.class != XMC_TC0
)
1626 as_warn (".tc with no label");
1627 ignore_rest_of_line ();
1631 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
1632 label
->sy_frag
= sym
->sy_frag
;
1633 S_SET_VALUE (label
, S_GET_VALUE (sym
));
1635 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1636 ++input_line_pointer
;
1641 S_SET_SEGMENT (sym
, now_seg
);
1642 sym
->sy_frag
= frag_now
;
1643 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1644 sym
->sy_tc
.class = XMC_TC
;
1645 sym
->sy_tc
.output
= 1;
1647 ppc_frob_label (sym
);
1650 #else /* ! defined (OBJ_COFF) */
1652 /* Skip the TOC symbol name. */
1653 while (is_part_of_name (*input_line_pointer
)
1654 || *input_line_pointer
== '['
1655 || *input_line_pointer
== ']'
1656 || *input_line_pointer
== '{'
1657 || *input_line_pointer
== '}')
1658 ++input_line_pointer
;
1660 /* Align to a four byte boundary. */
1662 record_alignment (now_seg
, 2);
1664 #endif /* ! defined (OBJ_COFF) */
1666 if (*input_line_pointer
!= ',')
1667 demand_empty_rest_of_line ();
1670 ++input_line_pointer
;
1677 /* XCOFF specific symbol and file handling. */
1679 /* Canonicalize the symbol name. We use the to force the suffix, if
1680 any, to use square brackets, and to be in upper case. */
1683 ppc_canonicalize_symbol_name (name
)
1688 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
1702 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
1706 if (*s
== '\0' || s
[1] != '\0')
1707 as_bad ("bad symbol suffix");
1715 /* Set the class of a symbol based on the suffix, if any. This is
1716 called whenever a new symbol is created. */
1719 ppc_symbol_new_hook (sym
)
1724 sym
->sy_tc
.next
= NULL
;
1725 sym
->sy_tc
.output
= 0;
1726 sym
->sy_tc
.class = -1;
1727 sym
->sy_tc
.real_name
= NULL
;
1728 sym
->sy_tc
.subseg
= 0;
1729 sym
->sy_tc
.align
= 0;
1730 sym
->sy_tc
.size
= NULL
;
1731 sym
->sy_tc
.within
= NULL
;
1733 s
= strchr (S_GET_NAME (sym
), '[');
1734 if (s
== (const char *) NULL
)
1736 /* There is no suffix. */
1745 if (strcmp (s
, "BS]") == 0)
1746 sym
->sy_tc
.class = XMC_BS
;
1749 if (strcmp (s
, "DB]") == 0)
1750 sym
->sy_tc
.class = XMC_DB
;
1751 else if (strcmp (s
, "DS]") == 0)
1752 sym
->sy_tc
.class = XMC_DS
;
1755 if (strcmp (s
, "GL]") == 0)
1756 sym
->sy_tc
.class = XMC_GL
;
1759 if (strcmp (s
, "PR]") == 0)
1760 sym
->sy_tc
.class = XMC_PR
;
1763 if (strcmp (s
, "RO]") == 0)
1764 sym
->sy_tc
.class = XMC_RO
;
1765 else if (strcmp (s
, "RW]") == 0)
1766 sym
->sy_tc
.class = XMC_RW
;
1769 if (strcmp (s
, "SV]") == 0)
1770 sym
->sy_tc
.class = XMC_SV
;
1773 if (strcmp (s
, "TC]") == 0)
1774 sym
->sy_tc
.class = XMC_TC
;
1775 else if (strcmp (s
, "TI]") == 0)
1776 sym
->sy_tc
.class = XMC_TI
;
1777 else if (strcmp (s
, "TB]") == 0)
1778 sym
->sy_tc
.class = XMC_TB
;
1779 else if (strcmp (s
, "TC0]") == 0 || strcm (s
, "T0]") == 0)
1780 sym
->sy_tc
.class = XMC_TC0
;
1783 if (strcmp (s
, "UA]") == 0)
1784 sym
->sy_tc
.class = XMC_UA
;
1785 else if (strcmp (s
, "UC]") == 0)
1786 sym
->sy_tc
.class = XMC_UC
;
1789 if (strcmp (s
, "XO]") == 0)
1790 sym
->sy_tc
.class = XMC_XO
;
1794 if (sym
->sy_tc
.class == -1)
1795 as_bad ("Unrecognized symbol suffix");
1798 /* Set the class of a label based on where it is defined. This
1799 handles symbols without suffixes. Also, move the symbol so that it
1800 follows the csect symbol. */
1803 ppc_frob_label (sym
)
1806 if (ppc_current_csect
!= (symbolS
*) NULL
)
1808 if (sym
->sy_tc
.class == -1)
1809 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
1811 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1812 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
1814 ppc_current_csect
->sy_tc
.within
= sym
;
1818 /* Change the name of a symbol just before writing it out. Set the
1819 real name if the .rename pseudo-op was used. Otherwise, remove any
1820 class suffix. Return 1 if the symbol should not be included in the
1824 ppc_frob_symbol (sym
)
1827 static symbolS
*ppc_last_function
;
1828 static symbolS
*set_end
;
1830 /* Discard symbols that should not be included in the output symbol
1832 if (! sym
->sy_used_in_reloc
1833 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1834 || (! S_IS_EXTERNAL (sym
)
1835 && ! sym
->sy_tc
.output
1836 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
1839 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
1840 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
1846 name
= S_GET_NAME (sym
);
1847 s
= strchr (name
, '[');
1848 if (s
!= (char *) NULL
)
1854 snew
= xmalloc (len
+ 1);
1855 memcpy (snew
, name
, len
);
1858 S_SET_NAME (sym
, snew
);
1862 if (set_end
!= (symbolS
*) NULL
)
1864 SA_SET_SYM_ENDNDX (set_end
, sym
);
1868 if (SF_GET_FUNCTION (sym
))
1870 if (ppc_last_function
!= (symbolS
*) NULL
)
1871 as_warn ("two .function pseudo-ops with no intervening .ef");
1872 ppc_last_function
= sym
;
1873 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
1875 resolve_symbol_value (sym
->sy_tc
.size
);
1876 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
1879 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
1880 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
1882 if (ppc_last_function
== (symbolS
*) NULL
)
1883 as_warn (".ef with no preceding .function");
1886 set_end
= ppc_last_function
;
1887 ppc_last_function
= NULL
;
1889 /* We don't have a C_EFCN symbol, but we need to force the
1890 COFF backend to believe that it has seen one. */
1891 coff_last_function
= NULL
;
1895 if (! S_IS_EXTERNAL (sym
)
1896 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
1897 && S_GET_STORAGE_CLASS (sym
) != C_FILE
1898 && S_GET_STORAGE_CLASS (sym
) != C_FCN
1899 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
1900 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
1901 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
1902 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
1904 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
1905 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
1908 union internal_auxent
*a
;
1910 /* Create a csect aux. */
1911 i
= S_GET_NUMBER_AUXILIARY (sym
);
1912 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
1913 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
1914 if (sym
->sy_tc
.class == XMC_TC0
)
1916 /* This is the TOC table. */
1917 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
1918 a
->x_csect
.x_scnlen
.l
= 0;
1919 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
1921 else if (sym
->sy_tc
.subseg
!= 0)
1923 /* This is a csect symbol. x_scnlen is the size of the
1925 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
1926 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
1927 S_GET_SEGMENT (sym
))
1928 - S_GET_VALUE (sym
));
1931 resolve_symbol_value (sym
->sy_tc
.next
);
1932 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
1933 - S_GET_VALUE (sym
));
1935 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
1937 else if (S_GET_SEGMENT (sym
) == bss_section
)
1939 /* This is a common symbol. */
1940 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
1941 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
1942 if (S_IS_EXTERNAL (sym
))
1943 sym
->sy_tc
.class = XMC_RW
;
1945 sym
->sy_tc
.class = XMC_BS
;
1947 else if (! S_IS_DEFINED (sym
))
1949 /* This is an external symbol. */
1950 a
->x_csect
.x_scnlen
.l
= 0;
1951 a
->x_csect
.x_smtyp
= XTY_ER
;
1953 else if (sym
->sy_tc
.class == XMC_TC
)
1957 /* This is a TOC definition. x_scnlen is the size of the
1959 next
= symbol_next (sym
);
1960 while (next
->sy_tc
.class == XMC_TC0
)
1961 next
= symbol_next (next
);
1962 if (next
== (symbolS
*) NULL
1963 || next
->sy_tc
.class != XMC_TC
)
1965 if (ppc_after_toc_frag
== (fragS
*) NULL
)
1966 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
1968 - S_GET_VALUE (sym
));
1970 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
1971 - S_GET_VALUE (sym
));
1975 resolve_symbol_value (next
);
1976 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
1977 - S_GET_VALUE (sym
));
1979 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
1985 /* This is a normal symbol definition. x_scnlen is the
1986 symbol index of the containing csect. */
1987 if (S_GET_SEGMENT (sym
) == text_section
)
1988 csect
= ppc_text_csects
;
1989 else if (S_GET_SEGMENT (sym
) == data_section
)
1990 csect
= ppc_data_csects
;
1994 /* Skip the initial dummy symbol. */
1995 csect
= csect
->sy_tc
.next
;
1997 if (csect
== (symbolS
*) NULL
)
1998 a
->x_csect
.x_scnlen
.l
= 0;
2001 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
2003 resolve_symbol_value (csect
->sy_tc
.next
);
2004 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
2006 csect
= csect
->sy_tc
.next
;
2009 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
2010 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
2012 a
->x_csect
.x_smtyp
= XTY_LD
;
2015 a
->x_csect
.x_parmhash
= 0;
2016 a
->x_csect
.x_snhash
= 0;
2017 if (sym
->sy_tc
.class == -1)
2018 a
->x_csect
.x_smclas
= XMC_PR
;
2020 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
2021 a
->x_csect
.x_stab
= 0;
2022 a
->x_csect
.x_snstab
= 0;
2024 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
2026 /* We want the value to be the symbol index of the referenced
2027 csect symbol. BFD will do that for us if we set the right
2030 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
2031 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
2033 else if (S_GET_STORAGE_CLASS (sym
) == C_STSYM
)
2038 /* The value is the offset from the enclosing csect. */
2039 block
= sym
->sy_tc
.within
;
2040 csect
= block
->sy_tc
.within
;
2041 resolve_symbol_value (csect
);
2042 S_SET_VALUE (sym
, S_GET_VALUE (sym
) - S_GET_VALUE (csect
));
2048 /* Set the VMA for a section. This is called on all the sections in
2052 ppc_frob_section (sec
)
2055 static bfd_size_type vma
= 0;
2057 bfd_set_section_vma (stdoutput
, sec
, vma
);
2058 vma
+= bfd_section_size (stdoutput
, sec
);
2061 /* Adjust the file by adding a .debug section if needed. */
2066 if (ppc_debug_name_section_size
> 0)
2070 sec
= bfd_make_section (stdoutput
, ".debug");
2071 if (sec
== (asection
*) NULL
2072 || ! bfd_set_section_size (stdoutput
, sec
,
2073 ppc_debug_name_section_size
)
2074 || ! bfd_set_section_flags (stdoutput
, sec
,
2075 SEC_HAS_CONTENTS
| SEC_LOAD
))
2076 as_fatal ("can't make .debug section");
2080 #endif /* OBJ_COFF */
2082 /* Turn a string in input_line_pointer into a floating point constant
2083 of type type, and store the appropriate bytes in *litp. The number
2084 of LITTLENUMS emitted is stored in *sizep . An error message is
2085 returned, or NULL on OK. */
2088 md_atof (type
, litp
, sizep
)
2094 LITTLENUM_TYPE words
[4];
2110 return "bad call to md_atof";
2113 t
= atof_ieee (input_line_pointer
, type
, words
);
2115 input_line_pointer
= t
;
2121 for (i
= 0; i
< prec
; i
++)
2123 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2129 for (i
= prec
- 1; i
>= 0; i
--)
2131 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2139 /* Write a value out to the object file, using the appropriate
2143 md_number_to_chars (buf
, val
, n
)
2149 number_to_chars_bigendian (buf
, val
, n
);
2151 number_to_chars_littleendian (buf
, val
, n
);
2154 /* Align a section (I don't know why this is machine dependent). */
2157 md_section_align (seg
, addr
)
2161 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2163 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
2166 /* We don't have any form of relaxing. */
2169 md_estimate_size_before_relax (fragp
, seg
)
2176 const relax_typeS md_relax_table
[] =
2181 /* Convert a machine dependent frag. We never generate these. */
2184 md_convert_frag (abfd
, sec
, fragp
)
2192 /* Parse an operand that is machine-specific. We just return without
2193 modifying the expression if we have nothing to do. */
2197 md_operand (expressionP
)
2198 expressionS
*expressionP
;
2202 /* We have no need to default values of symbols. */
2206 md_undefined_symbol (name
)
2212 /* Functions concerning relocs. */
2214 /* The location from which a PC relative jump should be calculated,
2215 given a PC relative reloc. */
2218 md_pcrel_from (fixp
)
2222 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2223 && ! S_IS_DEFINED (fixp
->fx_addsy
))
2227 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2232 /* This is called to see whether a fixup should be adjusted to use a
2233 section symbol. We take the opportunity to change a fixup against
2234 a symbol in the TOC subsegment into a reloc against the
2235 corresponding .tc symbol. */
2238 ppc_fix_adjustable (fix
)
2243 resolve_symbol_value (fix
->fx_addsy
);
2244 val
= S_GET_VALUE (fix
->fx_addsy
);
2245 if (ppc_toc_csect
!= (symbolS
*) NULL
2246 && fix
->fx_addsy
!= (symbolS
*) NULL
2247 && fix
->fx_addsy
!= ppc_toc_csect
2248 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
2249 && val
>= ppc_toc_frag
->fr_address
2250 && (ppc_after_toc_frag
== (fragS
*) NULL
2251 || val
< ppc_after_toc_frag
->fr_address
))
2255 for (sy
= symbol_next (ppc_toc_csect
);
2256 sy
!= (symbolS
*) NULL
;
2257 sy
= symbol_next (sy
))
2259 if (sy
->sy_tc
.class == XMC_TC0
)
2261 if (sy
->sy_tc
.class != XMC_TC
)
2263 resolve_symbol_value (sy
);
2264 if (val
== S_GET_VALUE (sy
))
2267 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
2272 as_bad_where (fix
->fx_file
, fix
->fx_line
,
2273 "symbol in .toc does not match any .tc");
2276 /* Possibly adjust the reloc to be against the csect. */
2277 if (fix
->fx_addsy
!= (symbolS
*) NULL
2278 && fix
->fx_addsy
->sy_tc
.subseg
== 0
2279 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
2280 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
2281 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
2285 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
2286 csect
= ppc_text_csects
;
2287 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
2288 csect
= ppc_data_csects
;
2292 /* Skip the initial dummy symbol. */
2293 csect
= csect
->sy_tc
.next
;
2295 if (csect
!= (symbolS
*) NULL
)
2297 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
2298 && (csect
->sy_tc
.next
->sy_frag
->fr_address
2299 <= fix
->fx_addsy
->sy_frag
->fr_address
))
2300 csect
= csect
->sy_tc
.next
;
2302 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2303 - csect
->sy_frag
->fr_address
);
2304 fix
->fx_addsy
= csect
;
2308 /* Adjust a reloc against a .lcomm symbol to be against the base
2310 if (fix
->fx_addsy
!= (symbolS
*) NULL
2311 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
2312 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
2314 resolve_symbol_value (fix
->fx_addsy
->sy_frag
->fr_symbol
);
2315 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2316 - S_GET_VALUE (fix
->fx_addsy
->sy_frag
->fr_symbol
));
2317 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
2325 /* See whether a symbol is in the TOC section. */
2328 ppc_is_toc_sym (sym
)
2332 return sym
->sy_tc
.class == XMC_TC
;
2334 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
2338 /* Apply a fixup to the object code. This is called for all the
2339 fixups we generated by the call to fix_new_exp, above. In the call
2340 above we used a reloc code which was the largest legal reloc code
2341 plus the operand index. Here we undo that to recover the operand
2342 index. At this point all symbol values should be fully resolved,
2343 and we attempt to completely resolve the reloc. If we can not do
2344 that, we determine the correct reloc code and put it back in the
2348 md_apply_fix (fixp
, valuep
)
2354 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
2355 the symbol values. Since we are using BFD_ASSEMBLER, if we are
2356 doing this relocation the code in write.c is going to call
2357 bfd_perform_relocation, which is also going to use the symbol
2358 value. That means that if the reloc is fully resolved we want to
2359 use *valuep since bfd_perform_relocation is not being used.
2360 However, if the reloc is not fully resolved we do not want to use
2361 *valuep, and must use fx_offset instead. However, if the reloc
2362 is PC relative, we do want to use *valuep since it includes the
2363 result of md_pcrel_from. This is confusing. */
2365 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2370 else if (fixp
->fx_pcrel
)
2374 value
= fixp
->fx_offset
;
2375 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2377 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2378 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2381 /* We can't actually support subtracting a symbol. */
2382 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2383 "expression too complex");
2388 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2391 const struct powerpc_operand
*operand
;
2395 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2397 operand
= &powerpc_operands
[opindex
];
2400 /* It appears that an instruction like
2402 when LC..1 is not a TOC symbol does not generate a reloc. It
2403 uses the offset of LC..1 within its csect. However, .long
2404 LC..1 will generate a reloc. I can't find any documentation
2405 on how these cases are to be distinguished, so this is a wild
2406 guess. These cases are generated by gcc -mminimal-toc. */
2407 if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2408 && operand
->bits
== 16
2409 && operand
->shift
== 0
2410 && operand
->insert
== NULL
2411 && fixp
->fx_addsy
!= NULL
2412 && fixp
->fx_addsy
->sy_tc
.subseg
!= 0
2413 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC
2414 && fixp
->fx_addsy
->sy_tc
.class != XMC_TC0
2415 && S_GET_SEGMENT (fixp
->fx_addsy
) != bss_section
)
2417 value
= fixp
->fx_offset
;
2422 /* Fetch the instruction, insert the fully resolved operand
2423 value, and stuff the instruction back again. */
2424 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2426 insn
= bfd_getb32 ((unsigned char *) where
);
2428 insn
= bfd_getl32 ((unsigned char *) where
);
2429 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
2430 fixp
->fx_file
, fixp
->fx_line
);
2432 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2434 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2438 /* Nothing else to do here. */
2442 /* Determine a BFD reloc value based on the operand information.
2443 We are only prepared to turn a few of the operands into
2445 FIXME: We need to handle the DS field at the very least.
2446 FIXME: Handling 16 bit branches would also be reasonable.
2447 FIXME: Selecting the reloc type is a bit haphazard; perhaps
2448 there should be a new field in the operand table. */
2449 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
2450 && operand
->bits
== 26
2451 && operand
->shift
== 0)
2452 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
2453 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
2454 && operand
->bits
== 26
2455 && operand
->shift
== 0)
2456 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
2457 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2458 && operand
->bits
== 16
2459 && operand
->shift
== 0
2460 && operand
->insert
== NULL
2461 && fixp
->fx_addsy
!= NULL
2462 && ppc_is_toc_sym (fixp
->fx_addsy
))
2466 fixp
->fx_where
+= 2;
2467 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
2471 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2472 "unresolved expression that must be resolved");
2479 switch (fixp
->fx_r_type
)
2482 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2486 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2490 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2499 fixp
->fx_addnumber
= value
;
2501 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
2502 fixp
->fx_addnumber
= 0;
2505 /* We want to use the offset within the data segment of the
2506 symbol, not the actual VMA of the symbol. */
2507 fixp
->fx_addnumber
=
2508 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
2515 /* Generate a reloc for a fixup. */
2518 tc_gen_reloc (seg
, fixp
)
2524 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2526 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2527 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2528 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2529 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2531 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2532 "reloc not supported by object file format");
2535 reloc
->addend
= fixp
->fx_addnumber
;