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 COFF debugging section; set by md_begin. This is not the
174 .debug section, but is instead the secret BFD section which will
175 cause BFD to set the section number of a symbol to N_DEBUG. */
176 static asection
*ppc_coff_debug_section
;
178 /* The size of the .debug section. */
179 static bfd_size_type ppc_debug_name_section_size
;
181 #endif /* OBJ_COFF */
183 /* This function is called when an option is found that is not
184 recognized by the driver code. It should return 1 if the option is
185 recognized here, 0 otherwise. */
188 md_parse_option (arg_ptr
, argc_ptr
, argv_ptr
)
193 /* -u means that any undefined symbols should be treated as
194 external, which is the default for gas anyhow. */
195 if (strcmp (*arg_ptr
, "u") == 0)
201 /* -mpwrx mean to assemble for the IBM POWER/2 (RIOS2). */
202 if (strcmp (*arg_ptr
, "mpwrx") == 0)
204 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
;
209 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
210 if (strcmp (*arg_ptr
, "mpwr") == 0)
212 ppc_cpu
= PPC_OPCODE_POWER
;
217 /* -m601 means to assemble for the Motorola PowerPC 601. FIXME: We
218 ignore the option for now, but we should really use it to permit
219 instructions defined on the 601 that are not part of the standard
220 PowerPC architecture (mostly holdovers from the POWER). */
221 if (strcmp (*arg_ptr
, "m601") == 0)
223 ppc_cpu
= PPC_OPCODE_PPC
| PPC_OPCODE_601
;
228 /* -mppc means to assemble for the Motorola PowerPC 603/604. */
229 if (strcmp (*arg_ptr
, "mppc") == 0)
231 ppc_cpu
= PPC_OPCODE_PPC
;
236 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
237 if (strcmp (*arg_ptr
, "many") == 0)
239 ppc_cpu
= PPC_OPCODE_POWER
| PPC_OPCODE_POWER2
| PPC_OPCODE_PPC
;
245 /* -V: SVR4 argument to print version ID. */
246 if (strcmp (*arg_ptr
, "V") == 0)
253 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
254 should be emitted or not. FIXME: Not implemented. */
255 if (strcmp (*arg_ptr
, "Qy") == 0
256 || strcmp (*arg_ptr
, "Qn") == 0)
266 /* Set ppc_cpu if it is not already set. */
271 const char *default_cpu
= TARGET_CPU
;
275 if (strcmp (default_cpu
, "rs6000") == 0)
276 ppc_cpu
= PPC_OPCODE_POWER
;
277 else if (strcmp (default_cpu
, "powerpc") == 0)
278 ppc_cpu
= PPC_OPCODE_PPC
;
284 /* Figure out the BFD architecture to use. */
286 enum bfd_architecture
291 if ((ppc_cpu
& PPC_OPCODE_PPC
) != 0)
292 return bfd_arch_powerpc
;
293 else if ((ppc_cpu
& PPC_OPCODE_POWER
) != 0)
294 return bfd_arch_rs6000
;
299 /* This function is called when the assembler starts up. It is called
300 after the options have been parsed and the output file has been
306 register const struct powerpc_opcode
*op
;
307 const struct powerpc_opcode
*op_end
;
308 const struct powerpc_macro
*macro
;
309 const struct powerpc_macro
*macro_end
;
313 /* Insert the opcodes into a hash table. */
314 ppc_hash
= hash_new ();
316 op_end
= powerpc_opcodes
+ powerpc_num_opcodes
;
317 for (op
= powerpc_opcodes
; op
< op_end
; op
++)
319 know ((op
->opcode
& op
->mask
) == op
->opcode
);
321 if ((op
->flags
& ppc_cpu
) != 0
322 && ((op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == 0
323 || (op
->flags
& (PPC_OPCODE_32
| PPC_OPCODE_64
)) == ppc_size
))
327 retval
= hash_insert (ppc_hash
, op
->name
, (PTR
) op
);
328 if (retval
!= (const char *) NULL
)
333 /* Insert the macros into a hash table. */
334 ppc_macro_hash
= hash_new ();
336 macro_end
= powerpc_macros
+ powerpc_num_macros
;
337 for (macro
= powerpc_macros
; macro
< macro_end
; macro
++)
339 if ((macro
->flags
& ppc_cpu
) != 0)
343 retval
= hash_insert (ppc_macro_hash
, macro
->name
, (PTR
) macro
);
344 if (retval
!= (const char *) NULL
)
349 /* Tell the main code what the endianness is. */
350 target_big_endian
= ppc_big_endian
;
353 ppc_coff_debug_section
= coff_section_from_bfd_index (stdoutput
, N_DEBUG
);
355 /* Create dummy symbols to serve as initial csects. This forces the
356 text csects to precede the data csects. These symbols will not
358 ppc_text_csects
= symbol_make ("dummy\001");
359 ppc_text_csects
->sy_tc
.within
= ppc_text_csects
;
360 ppc_data_csects
= symbol_make ("dummy\001");
361 ppc_data_csects
->sy_tc
.within
= ppc_data_csects
;
365 /* Insert an operand value into an instruction. */
368 ppc_insert_operand (insn
, operand
, val
, file
, line
)
370 const struct powerpc_operand
*operand
;
375 if (operand
->bits
!= 32)
380 if (operand
->signedp
)
383 max = (1 << (operand->bits - 1)) - 1;
384 Unfortunately, IBM has decided that all positive values
385 are permitted even for a signed field, so we lose some
387 max
= (1 << operand
->bits
) - 1;
388 min
= - (1 << (operand
->bits
- 1));
392 max
= (1 << operand
->bits
) - 1;
396 if ((operand
->flags
& PPC_OPERAND_NEGATIVE
) != 0)
401 if (test
< (offsetT
) min
|| test
> (offsetT
) max
)
404 "operand out of range (%s not between %ld and %ld)";
407 sprint_value (buf
, test
);
408 if (file
== (char *) NULL
)
409 as_warn (err
, buf
, min
, max
);
411 as_warn_where (file
, line
, err
, buf
, min
, max
);
420 insn
= (*operand
->insert
) (insn
, (long) val
, &errmsg
);
421 if (errmsg
!= (const char *) NULL
)
425 insn
|= (((long) val
& ((1 << operand
->bits
) - 1))
431 /* We need to keep a list of fixups. We can't simply generate them as
432 we go, because that would require us to first create the frag, and
433 that would screw up references to ``.''. */
441 #define MAX_INSN_FIXUPS (5)
443 /* This routine is called for each instruction to be assembled. */
450 const struct powerpc_opcode
*opcode
;
452 const unsigned char *opindex_ptr
;
456 struct ppc_fixup fixups
[MAX_INSN_FIXUPS
];
461 /* Get the opcode. */
462 for (s
= str
; *s
!= '\0' && ! isspace (*s
); s
++)
467 /* Look up the opcode in the hash table. */
468 opcode
= (const struct powerpc_opcode
*) hash_find (ppc_hash
, str
);
469 if (opcode
== (const struct powerpc_opcode
*) NULL
)
471 const struct powerpc_macro
*macro
;
473 macro
= (const struct powerpc_macro
*) hash_find (ppc_macro_hash
, str
);
474 if (macro
== (const struct powerpc_macro
*) NULL
)
475 as_bad ("Unrecognized opcode: `%s'", str
);
477 ppc_macro (s
, macro
);
482 insn
= opcode
->opcode
;
485 while (isspace (*str
))
488 /* PowerPC operands are just expressions. The only real issue is
489 that a few operand types are optional. All cases which might use
490 an optional operand separate the operands only with commas (in
491 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
492 cases never have optional operands). There is never more than
493 one optional operand for an instruction. So, before we start
494 seriously parsing the operands, we check to see if we have an
495 optional operand, and, if we do, we count the number of commas to
496 see whether the operand should be omitted. */
498 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
500 const struct powerpc_operand
*operand
;
502 operand
= &powerpc_operands
[*opindex_ptr
];
503 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0)
505 unsigned int opcount
;
507 /* There is an optional operand. Count the number of
508 commas in the input line. */
515 while ((s
= strchr (s
, ',')) != (char *) NULL
)
522 /* If there are fewer operands in the line then are called
523 for by the instruction, we want to skip the optional
525 if (opcount
< strlen (opcode
->operands
))
532 /* Gather the operands. */
536 for (opindex_ptr
= opcode
->operands
; *opindex_ptr
!= 0; opindex_ptr
++)
538 const struct powerpc_operand
*operand
;
544 if (next_opindex
== 0)
545 operand
= &powerpc_operands
[*opindex_ptr
];
548 operand
= &powerpc_operands
[next_opindex
];
554 /* If this is a fake operand, then we do not expect anything
556 if ((operand
->flags
& PPC_OPERAND_FAKE
) != 0)
558 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
559 if (errmsg
!= (const char *) NULL
)
564 /* If this is an optional operand, and we are skipping it, just
566 if ((operand
->flags
& PPC_OPERAND_OPTIONAL
) != 0
571 insn
= (*operand
->insert
) (insn
, 0L, &errmsg
);
572 if (errmsg
!= (const char *) NULL
)
575 if ((operand
->flags
& PPC_OPERAND_NEXT
) != 0)
576 next_opindex
= *opindex_ptr
+ 1;
580 /* Gather the operand. */
581 hold
= input_line_pointer
;
582 input_line_pointer
= str
;
584 str
= input_line_pointer
;
585 input_line_pointer
= hold
;
587 if (ex
.X_op
== O_illegal
)
588 as_bad ("illegal operand");
589 else if (ex
.X_op
== O_absent
)
590 as_bad ("missing operand");
591 else if (ex
.X_op
== O_constant
)
592 insn
= ppc_insert_operand (insn
, operand
, ex
.X_add_number
,
596 /* We need to generate a fixup for this expression. */
597 if (fc
>= MAX_INSN_FIXUPS
)
598 as_fatal ("too many fixups");
600 fixups
[fc
].opindex
= *opindex_ptr
;
609 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0)
617 /* The call to expression should have advanced str past any
620 && (endc
!= ',' || *str
!= '\0'))
622 as_bad ("syntax error; found `%c' but expected `%c'", *str
, endc
);
630 while (isspace (*str
))
634 as_bad ("junk at end of line: `%s'", str
);
636 /* Write out the instruction. */
638 md_number_to_chars (f
, insn
, 4);
640 /* Create any fixups. At this point we do not use a
641 bfd_reloc_code_real_type, but instead just use the operand index.
642 This lets us easily handle fixups for any operand type, although
643 that is admittedly not a very exciting feature. We pick a BFD
644 reloc type in md_apply_fix. */
645 for (i
= 0; i
< fc
; i
++)
647 const struct powerpc_operand
*operand
;
649 operand
= &powerpc_operands
[fixups
[i
].opindex
];
650 fix_new_exp (frag_now
, f
- frag_now
->fr_literal
, 4,
652 (operand
->flags
& PPC_OPERAND_RELATIVE
) != 0,
653 ((bfd_reloc_code_real_type
)
654 (fixups
[i
].opindex
+ (int) BFD_RELOC_UNUSED
)));
658 /* Handle a macro. Gather all the operands, transform them as
659 described by the macro, and call md_assemble recursively. All the
660 operands are separated by commas; we don't accept parentheses
661 around operands here. */
664 ppc_macro (str
, macro
)
666 const struct powerpc_macro
*macro
;
677 /* Gather the users operands into the operands array. */
682 if (count
>= sizeof operands
/ sizeof operands
[0])
684 operands
[count
++] = s
;
686 if (s
== (char *) NULL
)
691 if (count
!= macro
->operands
)
693 as_bad ("wrong number of operands");
697 /* Work out how large the string must be (the size is unbounded
698 because it includes user input). */
700 format
= macro
->format
;
701 while (*format
!= '\0')
710 arg
= strtol (format
+ 1, &send
, 10);
711 know (send
!= format
&& arg
>= 0 && arg
< count
);
712 len
+= strlen (operands
[arg
]);
717 /* Put the string together. */
718 complete
= s
= (char *) alloca (len
+ 1);
719 format
= macro
->format
;
720 while (*format
!= '\0')
726 arg
= strtol (format
+ 1, &send
, 10);
727 strcpy (s
, operands
[arg
]);
734 /* Assemble the constructed instruction. */
735 md_assemble (complete
);
738 /* Pseudo-op handling. */
740 /* The .byte pseudo-op. This is similar to the normal .byte
741 pseudo-op, but it can also take a single ASCII string. */
747 if (*input_line_pointer
!= '\"')
753 /* Gather characters. A real double quote is doubled. Unusual
754 characters are not permitted. */
755 ++input_line_pointer
;
760 c
= *input_line_pointer
++;
764 if (*input_line_pointer
!= '\"')
766 ++input_line_pointer
;
769 FRAG_APPEND_1_CHAR (c
);
772 demand_empty_rest_of_line ();
777 /* XCOFF specific pseudo-op handling. */
779 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
780 symbols in the .bss segment as though they were local common
781 symbols, and uses a different smclas. */
787 asection
*current_seg
= now_seg
;
788 subsegT current_subseg
= now_subseg
;
794 symbolS
*lcomm_sym
= NULL
;
798 name
= input_line_pointer
;
799 endc
= get_symbol_end ();
800 end_name
= input_line_pointer
;
803 if (*input_line_pointer
!= ',')
805 as_bad ("missing size");
806 ignore_rest_of_line ();
809 ++input_line_pointer
;
811 size
= get_absolute_expression ();
814 as_bad ("negative size");
815 ignore_rest_of_line ();
821 /* The third argument to .comm is the alignment. */
822 if (*input_line_pointer
!= ',')
826 ++input_line_pointer
;
827 align
= get_absolute_expression ();
830 as_warn ("ignoring bad alignment");
849 /* The third argument to .lcomm appears to be the real local
850 common symbol to create. References to the symbol named in
851 the first argument are turned into references to the third
853 if (*input_line_pointer
!= ',')
855 as_bad ("missing real symbol name");
856 ignore_rest_of_line ();
859 ++input_line_pointer
;
861 lcomm_name
= input_line_pointer
;
862 lcomm_endc
= get_symbol_end ();
864 lcomm_sym
= symbol_find_or_make (lcomm_name
);
866 *input_line_pointer
= lcomm_endc
;
870 sym
= symbol_find_or_make (name
);
873 if (S_IS_DEFINED (sym
)
874 || S_GET_VALUE (sym
) != 0)
876 as_bad ("attempt to redefine symbol");
877 ignore_rest_of_line ();
881 record_alignment (bss_section
, align
);
884 || ! S_IS_DEFINED (lcomm_sym
))
893 S_SET_EXTERNAL (sym
);
897 lcomm_sym
->sy_tc
.output
= 1;
902 subseg_set (bss_section
, 1);
903 frag_align (align
, 0);
905 def_sym
->sy_frag
= frag_now
;
906 pfrag
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, def_sym
,
907 def_size
, (char *) NULL
);
909 S_SET_SEGMENT (def_sym
, bss_section
);
910 def_sym
->sy_tc
.align
= align
;
914 /* Align the size of lcomm_sym. */
915 lcomm_sym
->sy_frag
->fr_offset
=
916 ((lcomm_sym
->sy_frag
->fr_offset
+ (1 << align
) - 1)
917 &~ ((1 << align
) - 1));
918 if (align
> lcomm_sym
->sy_tc
.align
)
919 lcomm_sym
->sy_tc
.align
= align
;
924 /* Make sym an offset from lcomm_sym. */
925 S_SET_SEGMENT (sym
, bss_section
);
926 sym
->sy_frag
= lcomm_sym
->sy_frag
;
927 S_SET_VALUE (sym
, lcomm_sym
->sy_frag
->fr_offset
);
928 lcomm_sym
->sy_frag
->fr_offset
+= size
;
931 subseg_set (current_seg
, current_subseg
);
933 demand_empty_rest_of_line ();
936 /* The .csect pseudo-op. This switches us into a different
937 subsegment. The first argument is a symbol whose value is the
938 start of the .csect. In COFF, csect symbols get special aux
939 entries defined by the x_csect field of union internal_auxent. The
940 optional second argument is the alignment (the default is 2). */
950 name
= input_line_pointer
;
951 endc
= get_symbol_end ();
953 sym
= symbol_find_or_make (name
);
955 *input_line_pointer
= endc
;
957 if (S_IS_DEFINED (sym
))
958 subseg_set (S_GET_SEGMENT (sym
), sym
->sy_tc
.subseg
);
965 /* This is a new csect. We need to look at the symbol class to
966 figure out whether it should go in the text section or the
969 switch (sym
->sy_tc
.class)
979 S_SET_SEGMENT (sym
, text_section
);
980 sym
->sy_tc
.subseg
= ppc_text_subsegment
;
981 ++ppc_text_subsegment
;
982 list_ptr
= &ppc_text_csects
;
991 if (ppc_toc_csect
->sy_tc
.subseg
+ 1 == ppc_data_subsegment
)
993 S_SET_SEGMENT (sym
, data_section
);
994 sym
->sy_tc
.subseg
= ppc_data_subsegment
;
995 ++ppc_data_subsegment
;
996 list_ptr
= &ppc_data_csects
;
1002 subseg_new (segment_name (S_GET_SEGMENT (sym
)), sym
->sy_tc
.subseg
);
1004 ppc_after_toc_frag
= frag_now
;
1006 sym
->sy_frag
= frag_now
;
1007 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1009 sym
->sy_tc
.align
= 2;
1010 sym
->sy_tc
.output
= 1;
1011 sym
->sy_tc
.within
= sym
;
1013 for (list
= *list_ptr
;
1014 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1015 list
= list
->sy_tc
.next
)
1017 list
->sy_tc
.next
= sym
;
1019 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1020 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1023 if (*input_line_pointer
== ',')
1025 ++input_line_pointer
;
1026 sym
->sy_tc
.align
= get_absolute_expression ();
1029 ppc_current_csect
= sym
;
1031 demand_empty_rest_of_line ();
1034 /* The .extern pseudo-op. We create an undefined symbol. */
1043 name
= input_line_pointer
;
1044 endc
= get_symbol_end ();
1046 (void) symbol_find_or_make (name
);
1048 *input_line_pointer
= endc
;
1050 demand_empty_rest_of_line ();
1053 /* The .lglobl pseudo-op. I think the RS/6000 assembler only needs
1054 this because it can't handle undefined symbols. I think we can
1064 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
1065 although I don't know why it bothers. */
1076 name
= input_line_pointer
;
1077 endc
= get_symbol_end ();
1079 sym
= symbol_find_or_make (name
);
1081 *input_line_pointer
= endc
;
1083 if (*input_line_pointer
!= ',')
1085 as_bad ("missing rename string");
1086 ignore_rest_of_line ();
1089 ++input_line_pointer
;
1091 sym
->sy_tc
.real_name
= demand_copy_C_string (&len
);
1093 demand_empty_rest_of_line ();
1096 /* The .stabx pseudo-op. This is similar to a normal .stabs
1097 pseudo-op, but slightly different. A sample is
1098 .stabx "main:F-1",.main,142,0
1099 The first argument is the symbol name to create. The second is the
1100 value, and the third is the storage class. The fourth seems to be
1101 always zero, and I am assuming it is the type. */
1111 name
= demand_copy_C_string (&len
);
1113 if (*input_line_pointer
!= ',')
1115 as_bad ("missing value");
1118 ++input_line_pointer
;
1120 sym
= symbol_make (name
);
1123 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1124 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1126 if (*input_line_pointer
!= ',')
1128 as_bad ("missing class");
1131 ++input_line_pointer
;
1133 S_SET_STORAGE_CLASS (sym
, get_absolute_expression ());
1135 if (*input_line_pointer
!= ',')
1137 as_bad ("missing type");
1140 ++input_line_pointer
;
1142 S_SET_DATA_TYPE (sym
, get_absolute_expression ());
1144 sym
->sy_tc
.output
= 1;
1145 ppc_frob_label (sym
);
1147 if (strlen (name
) > SYMNMLEN
)
1149 /* For some reason, each name is preceded by a two byte length
1150 and followed by a null byte. */
1151 ppc_debug_name_section_size
+= strlen (name
) + 3;
1154 demand_empty_rest_of_line ();
1157 /* The .function pseudo-op. This takes several arguments. The first
1158 argument seems to be the external name of the symbol. The second
1159 argment seems to be the label for the start of the function. gcc
1160 uses the same name for both. I have no idea what the third and
1161 fourth arguments are meant to be. The optional fifth argument is
1162 an expression for the size of the function. In COFF this symbol
1163 gets an aux entry like that used for a csect. */
1166 ppc_function (ignore
)
1175 name
= input_line_pointer
;
1176 endc
= get_symbol_end ();
1178 /* Ignore any [PR] suffix. */
1179 name
= ppc_canonicalize_symbol_name (name
);
1180 s
= strchr (name
, '[');
1181 if (s
!= (char *) NULL
1182 && strcmp (s
+ 1, "PR]") == 0)
1185 ext_sym
= symbol_find_or_make (name
);
1187 *input_line_pointer
= endc
;
1189 if (*input_line_pointer
!= ',')
1191 as_bad ("missing symbol name");
1192 ignore_rest_of_line ();
1195 ++input_line_pointer
;
1197 name
= input_line_pointer
;
1198 endc
= get_symbol_end ();
1200 lab_sym
= symbol_find_or_make (name
);
1202 *input_line_pointer
= endc
;
1204 if (ext_sym
!= lab_sym
)
1206 ext_sym
->sy_value
.X_op
= O_symbol
;
1207 ext_sym
->sy_value
.X_add_symbol
= lab_sym
;
1208 ext_sym
->sy_value
.X_op_symbol
= NULL
;
1209 ext_sym
->sy_value
.X_add_number
= 0;
1212 if (ext_sym
->sy_tc
.class == -1)
1213 ext_sym
->sy_tc
.class = XMC_PR
;
1214 ext_sym
->sy_tc
.output
= 1;
1216 if (*input_line_pointer
== ',')
1220 /* Ignore the third argument. */
1221 ++input_line_pointer
;
1222 expression (&ignore
);
1223 if (*input_line_pointer
== ',')
1225 /* Ignore the fourth argument. */
1226 ++input_line_pointer
;
1227 expression (&ignore
);
1228 if (*input_line_pointer
== ',')
1230 /* The fifth argument is the function size. */
1231 ++input_line_pointer
;
1232 ext_sym
->sy_tc
.size
= symbol_new ("L0\001",
1235 &zero_address_frag
);
1236 pseudo_set (ext_sym
->sy_tc
.size
);
1241 S_SET_DATA_TYPE (ext_sym
, DT_FCN
<< N_BTSHFT
);
1242 SF_SET_FUNCTION (ext_sym
);
1243 SF_SET_PROCESS (ext_sym
);
1244 coff_add_linesym (ext_sym
);
1246 demand_empty_rest_of_line ();
1249 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
1259 sym
= symbol_make (".bf");
1260 S_SET_SEGMENT (sym
, text_section
);
1261 sym
->sy_frag
= frag_now
;
1262 S_SET_VALUE (sym
, frag_now_fix ());
1263 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1265 base
= get_absolute_expression ();
1266 if (base
> coff_line_base
)
1267 coff_line_base
= base
;
1269 S_SET_NUMBER_AUXILIARY (sym
, 1);
1270 SA_SET_SYM_LNNO (sym
, coff_line_base
);
1272 sym
->sy_tc
.output
= 1;
1274 ppc_frob_label (sym
);
1276 demand_empty_rest_of_line ();
1279 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
1280 ".ef", except that the line number is absolute, not relative to the
1281 most recent ".bf" symbol. */
1289 sym
= symbol_make (".ef");
1290 S_SET_SEGMENT (sym
, text_section
);
1291 sym
->sy_frag
= frag_now
;
1292 S_SET_VALUE (sym
, frag_now_fix ());
1293 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1294 S_SET_NUMBER_AUXILIARY (sym
, 1);
1295 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1296 sym
->sy_tc
.output
= 1;
1298 ppc_frob_label (sym
);
1300 demand_empty_rest_of_line ();
1303 /* The .bi and .ei pseudo-ops. These take a string argument and
1304 generates a C_BINCL or C_EINCL symbol, which goes at the start of
1316 name
= demand_copy_C_string (&len
);
1318 sym
= symbol_make (name
);
1319 S_SET_SEGMENT (sym
, ppc_coff_debug_section
);
1320 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1322 /* FIXME: The value of the .bi or .ei symbol is supposed to be the
1323 offset in the file to the line number entry to use. That is
1324 quite difficult to implement using BFD, so I'm just not doing it.
1325 Sorry. Please add it if you can figure out how. Note that this
1326 approach is the only way to support multiple files in COFF, since
1327 line numbers are associated with function symbols. Note further
1328 that it still doesn't work, since the line numbers are stored as
1329 offsets from a base line number. */
1331 S_SET_STORAGE_CLASS (sym
, ei
? C_EINCL
: C_BINCL
);
1332 sym
->sy_tc
.output
= 1;
1334 for (look
= symbol_rootP
;
1335 (look
!= (symbolS
*) NULL
1336 && (S_GET_STORAGE_CLASS (look
) == C_FILE
1337 || S_GET_STORAGE_CLASS (look
) == C_BINCL
1338 || S_GET_STORAGE_CLASS (look
) == C_EINCL
));
1339 look
= symbol_next (look
))
1341 if (look
!= (symbolS
*) NULL
)
1343 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1344 symbol_insert (sym
, look
, &symbol_rootP
, &symbol_lastP
);
1347 demand_empty_rest_of_line ();
1350 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
1351 There is one argument, which is a csect symbol. The value of the
1352 .bs symbol is the index of this csect symbol. */
1363 name
= input_line_pointer
;
1364 endc
= get_symbol_end ();
1366 csect
= symbol_find_or_make (name
);
1368 *input_line_pointer
= endc
;
1370 sym
= symbol_make (".bs");
1371 S_SET_SEGMENT (sym
, now_seg
);
1372 S_SET_STORAGE_CLASS (sym
, C_BSTAT
);
1373 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1374 sym
->sy_tc
.output
= 1;
1376 sym
->sy_tc
.within
= csect
;
1378 ppc_frob_label (sym
);
1380 demand_empty_rest_of_line ();
1383 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
1391 sym
= symbol_make (".es");
1392 S_SET_SEGMENT (sym
, now_seg
);
1393 S_SET_STORAGE_CLASS (sym
, C_ESTAT
);
1394 sym
->bsym
->flags
|= BSF_DEBUGGING
;
1395 sym
->sy_tc
.output
= 1;
1397 ppc_frob_label (sym
);
1399 demand_empty_rest_of_line ();
1402 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
1411 sym
= symbol_make (".bb");
1412 S_SET_SEGMENT (sym
, text_section
);
1413 sym
->sy_frag
= frag_now
;
1414 S_SET_VALUE (sym
, frag_now_fix ());
1415 S_SET_STORAGE_CLASS (sym
, C_BLOCK
);
1417 S_SET_NUMBER_AUXILIARY (sym
, 1);
1418 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1420 sym
->sy_tc
.output
= 1;
1422 ppc_frob_label (sym
);
1424 demand_empty_rest_of_line ();
1427 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
1436 sym
= symbol_make (".eb");
1437 S_SET_SEGMENT (sym
, text_section
);
1438 sym
->sy_frag
= frag_now
;
1439 S_SET_VALUE (sym
, frag_now_fix ());
1440 S_SET_STORAGE_CLASS (sym
, C_FCN
);
1441 S_SET_NUMBER_AUXILIARY (sym
, 1);
1442 SA_SET_SYM_LNNO (sym
, get_absolute_expression ());
1443 sym
->sy_tc
.output
= 1;
1445 ppc_frob_label (sym
);
1447 demand_empty_rest_of_line ();
1450 /* The .toc pseudo-op. Switch to the .toc subsegment. */
1456 if (ppc_toc_csect
!= (symbolS
*) NULL
)
1457 subseg_set (data_section
, ppc_toc_csect
->sy_tc
.subseg
);
1464 subseg
= ppc_data_subsegment
;
1465 ++ppc_data_subsegment
;
1467 subseg_new (segment_name (data_section
), subseg
);
1468 ppc_toc_frag
= frag_now
;
1470 sym
= symbol_find_or_make ("TOC[TC0]");
1471 sym
->sy_frag
= frag_now
;
1472 S_SET_SEGMENT (sym
, data_section
);
1473 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1474 sym
->sy_tc
.subseg
= subseg
;
1475 sym
->sy_tc
.output
= 1;
1476 sym
->sy_tc
.within
= sym
;
1478 ppc_toc_csect
= sym
;
1480 for (list
= ppc_data_csects
;
1481 list
->sy_tc
.next
!= (symbolS
*) NULL
;
1482 list
= list
->sy_tc
.next
)
1484 list
->sy_tc
.next
= sym
;
1486 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1487 symbol_append (sym
, list
->sy_tc
.within
, &symbol_rootP
, &symbol_lastP
);
1490 ppc_current_csect
= ppc_toc_csect
;
1492 demand_empty_rest_of_line ();
1495 #endif /* OBJ_COFF */
1497 /* The .tc pseudo-op. This is used when generating either XCOFF or
1498 ELF. This takes two or more arguments.
1500 When generating XCOFF output, the first argument is the name to
1501 give to this location in the toc; this will be a symbol with class
1502 TC. The rest of the arguments are 4 byte values to actually put at
1503 this location in the TOC; often there is just one more argument, a
1504 relocateable symbol reference.
1506 When not generating XCOFF output, the arguments are the same, but
1507 the first argument is simply ignored. */
1515 /* Define the TOC symbol name. */
1521 if (ppc_toc_csect
== (symbolS
*) NULL
1522 || ppc_toc_csect
!= ppc_current_csect
)
1524 as_bad (".tc not in .toc section");
1525 ignore_rest_of_line ();
1529 name
= input_line_pointer
;
1530 endc
= get_symbol_end ();
1532 sym
= symbol_find_or_make (name
);
1534 *input_line_pointer
= endc
;
1536 if (S_IS_DEFINED (sym
))
1540 label
= ppc_current_csect
->sy_tc
.within
;
1541 if (label
->sy_tc
.class != XMC_TC0
)
1543 as_warn (".tc with no label");
1544 ignore_rest_of_line ();
1548 S_SET_SEGMENT (label
, S_GET_SEGMENT (sym
));
1549 label
->sy_frag
= sym
->sy_frag
;
1550 S_SET_VALUE (label
, S_GET_VALUE (sym
));
1552 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
1553 ++input_line_pointer
;
1558 S_SET_SEGMENT (sym
, now_seg
);
1559 sym
->sy_frag
= frag_now
;
1560 S_SET_VALUE (sym
, (valueT
) frag_now_fix ());
1561 sym
->sy_tc
.class = XMC_TC
;
1562 sym
->sy_tc
.output
= 1;
1564 ppc_frob_label (sym
);
1567 #else /* ! defined (OBJ_COFF) */
1569 /* Skip the TOC symbol name. */
1570 while (is_part_of_name (*input_line_pointer
)
1571 || *input_line_pointer
== '['
1572 || *input_line_pointer
== ']'
1573 || *input_line_pointer
== '{'
1574 || *input_line_pointer
== '}')
1575 ++input_line_pointer
;
1577 #endif /* ! defined (OBJ_COFF) */
1579 if (*input_line_pointer
!= ',')
1580 demand_empty_rest_of_line ();
1583 ++input_line_pointer
;
1590 /* XCOFF specific symbol and file handling. */
1592 /* Canonicalize the symbol name. We use the to force the suffix, if
1593 any, to use square brackets, and to be in upper case. */
1596 ppc_canonicalize_symbol_name (name
)
1601 for (s
= name
; *s
!= '\0' && *s
!= '{' && *s
!= '['; s
++)
1615 for (s
++; *s
!= '\0' && *s
!= brac
; s
++)
1619 if (*s
== '\0' || s
[1] != '\0')
1620 as_bad ("bad symbol suffix");
1628 /* Set the class of a symbol based on the suffix, if any. This is
1629 called whenever a new symbol is created. */
1632 ppc_symbol_new_hook (sym
)
1637 sym
->sy_tc
.next
= NULL
;
1638 sym
->sy_tc
.output
= 0;
1639 sym
->sy_tc
.class = -1;
1640 sym
->sy_tc
.real_name
= NULL
;
1641 sym
->sy_tc
.subseg
= 0;
1642 sym
->sy_tc
.align
= 0;
1643 sym
->sy_tc
.size
= NULL
;
1644 sym
->sy_tc
.within
= NULL
;
1646 s
= strchr (S_GET_NAME (sym
), '[');
1647 if (s
== (const char *) NULL
)
1649 /* There is no suffix. */
1658 if (strcmp (s
, "BS]") == 0)
1659 sym
->sy_tc
.class = XMC_BS
;
1662 if (strcmp (s
, "DB]") == 0)
1663 sym
->sy_tc
.class = XMC_DB
;
1664 else if (strcmp (s
, "DS]") == 0)
1665 sym
->sy_tc
.class = XMC_DS
;
1668 if (strcmp (s
, "GL]") == 0)
1669 sym
->sy_tc
.class = XMC_GL
;
1672 if (strcmp (s
, "PR]") == 0)
1673 sym
->sy_tc
.class = XMC_PR
;
1676 if (strcmp (s
, "RO]") == 0)
1677 sym
->sy_tc
.class = XMC_RO
;
1678 else if (strcmp (s
, "RW]") == 0)
1679 sym
->sy_tc
.class = XMC_RW
;
1682 if (strcmp (s
, "SV]") == 0)
1683 sym
->sy_tc
.class = XMC_SV
;
1686 if (strcmp (s
, "TC]") == 0)
1687 sym
->sy_tc
.class = XMC_TC
;
1688 else if (strcmp (s
, "TI]") == 0)
1689 sym
->sy_tc
.class = XMC_TI
;
1690 else if (strcmp (s
, "TB]") == 0)
1691 sym
->sy_tc
.class = XMC_TB
;
1692 else if (strcmp (s
, "TC0]") == 0)
1693 sym
->sy_tc
.class = XMC_TC0
;
1696 if (strcmp (s
, "UA]") == 0)
1697 sym
->sy_tc
.class = XMC_UA
;
1698 else if (strcmp (s
, "UC]") == 0)
1699 sym
->sy_tc
.class = XMC_UC
;
1702 if (strcmp (s
, "XO]") == 0)
1703 sym
->sy_tc
.class = XMC_XO
;
1707 if (sym
->sy_tc
.class == -1)
1708 as_bad ("Unrecognized symbol suffix");
1711 /* Set the class of a label based on where it is defined. This
1712 handles symbols without suffixes. Also, move the symbol so that it
1713 follows the csect symbol. */
1716 ppc_frob_label (sym
)
1719 if (ppc_current_csect
!= (symbolS
*) NULL
)
1721 if (sym
->sy_tc
.class == -1)
1722 sym
->sy_tc
.class = ppc_current_csect
->sy_tc
.class;
1724 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
1725 symbol_append (sym
, ppc_current_csect
->sy_tc
.within
, &symbol_rootP
,
1727 ppc_current_csect
->sy_tc
.within
= sym
;
1731 /* Change the name of a symbol just before writing it out. Set the
1732 real name if the .rename pseudo-op was used. Otherwise, remove any
1733 class suffix. Return 1 if the symbol should not be included in the
1737 ppc_frob_symbol (sym
)
1740 static symbolS
*ppc_last_function
;
1741 static symbolS
*set_end
;
1743 /* Discard symbols that should not be included in the output symbol
1745 if (! sym
->sy_used_in_reloc
1746 && ((sym
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1747 || (! S_IS_EXTERNAL (sym
)
1748 && ! sym
->sy_tc
.output
1749 && S_GET_STORAGE_CLASS (sym
) != C_FILE
)))
1752 if (sym
->sy_tc
.real_name
!= (char *) NULL
)
1753 S_SET_NAME (sym
, sym
->sy_tc
.real_name
);
1759 name
= S_GET_NAME (sym
);
1760 s
= strchr (name
, '[');
1761 if (s
!= (char *) NULL
)
1767 snew
= xmalloc (len
+ 1);
1768 memcpy (snew
, name
, len
);
1771 S_SET_NAME (sym
, snew
);
1775 if (set_end
!= (symbolS
*) NULL
)
1777 SA_SET_SYM_ENDNDX (set_end
, sym
);
1781 if (SF_GET_FUNCTION (sym
))
1783 if (ppc_last_function
!= (symbolS
*) NULL
)
1784 as_warn ("two .function pseudo-ops with no intervening .ef");
1785 ppc_last_function
= sym
;
1786 if (sym
->sy_tc
.size
!= (symbolS
*) NULL
)
1788 resolve_symbol_value (sym
->sy_tc
.size
);
1789 SA_SET_SYM_FSIZE (sym
, (long) S_GET_VALUE (sym
->sy_tc
.size
));
1792 else if (S_GET_STORAGE_CLASS (sym
) == C_FCN
1793 && strcmp (S_GET_NAME (sym
), ".ef") == 0)
1795 if (ppc_last_function
== (symbolS
*) NULL
)
1796 as_warn (".ef with no preceding .function");
1799 set_end
= ppc_last_function
;
1800 ppc_last_function
= NULL
;
1802 /* We don't have a C_EFCN symbol, but we need to force the
1803 COFF backend to believe that it has seen one. */
1804 coff_last_function
= NULL
;
1808 if (! S_IS_EXTERNAL (sym
)
1809 && (sym
->bsym
->flags
& BSF_SECTION_SYM
) == 0
1810 && S_GET_STORAGE_CLASS (sym
) != C_FILE
1811 && S_GET_STORAGE_CLASS (sym
) != C_FCN
1812 && S_GET_STORAGE_CLASS (sym
) != C_BSTAT
1813 && S_GET_STORAGE_CLASS (sym
) != C_ESTAT
1814 && S_GET_SEGMENT (sym
) != ppc_coff_debug_section
)
1815 S_SET_STORAGE_CLASS (sym
, C_HIDEXT
);
1817 if (S_GET_STORAGE_CLASS (sym
) == C_EXT
1818 || S_GET_STORAGE_CLASS (sym
) == C_HIDEXT
)
1821 union internal_auxent
*a
;
1823 /* Create a csect aux. */
1824 i
= S_GET_NUMBER_AUXILIARY (sym
);
1825 S_SET_NUMBER_AUXILIARY (sym
, i
+ 1);
1826 a
= &coffsymbol (sym
->bsym
)->native
[i
+ 1].u
.auxent
;
1827 if (sym
->sy_tc
.class == XMC_TC0
)
1829 /* This is the TOC table. */
1830 know (strcmp (S_GET_NAME (sym
), "TOC") == 0);
1831 a
->x_csect
.x_scnlen
.l
= 0;
1832 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
1834 else if (sym
->sy_tc
.subseg
!= 0)
1836 /* This is a csect symbol. x_scnlen is the size of the
1838 if (sym
->sy_tc
.next
== (symbolS
*) NULL
)
1839 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
1840 S_GET_SEGMENT (sym
))
1841 - S_GET_VALUE (sym
));
1844 resolve_symbol_value (sym
->sy_tc
.next
);
1845 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (sym
->sy_tc
.next
)
1846 - S_GET_VALUE (sym
));
1848 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_SD
;
1850 else if (S_GET_SEGMENT (sym
) == bss_section
)
1852 /* This is a common symbol. */
1853 a
->x_csect
.x_scnlen
.l
= sym
->sy_frag
->fr_offset
;
1854 a
->x_csect
.x_smtyp
= (sym
->sy_tc
.align
<< 3) | XTY_CM
;
1855 if (S_IS_EXTERNAL (sym
))
1856 sym
->sy_tc
.class = XMC_RW
;
1858 sym
->sy_tc
.class = XMC_BS
;
1860 else if (! S_IS_DEFINED (sym
))
1862 /* This is an external symbol. */
1863 a
->x_csect
.x_scnlen
.l
= 0;
1864 a
->x_csect
.x_smtyp
= XTY_ER
;
1866 else if (sym
->sy_tc
.class == XMC_TC
)
1870 /* This is a TOC definition. x_scnlen is the size of the
1872 next
= symbol_next (sym
);
1873 while (next
->sy_tc
.class == XMC_TC0
)
1874 next
= symbol_next (next
);
1875 if (next
== (symbolS
*) NULL
1876 || next
->sy_tc
.class != XMC_TC
)
1878 if (ppc_after_toc_frag
== (fragS
*) NULL
)
1879 a
->x_csect
.x_scnlen
.l
= (bfd_section_size (stdoutput
,
1881 - S_GET_VALUE (sym
));
1883 a
->x_csect
.x_scnlen
.l
= (ppc_after_toc_frag
->fr_address
1884 - S_GET_VALUE (sym
));
1888 resolve_symbol_value (next
);
1889 a
->x_csect
.x_scnlen
.l
= (S_GET_VALUE (next
)
1890 - S_GET_VALUE (sym
));
1892 a
->x_csect
.x_smtyp
= (2 << 3) | XTY_SD
;
1898 /* This is a normal symbol definition. x_scnlen is the
1899 symbol index of the containing csect. */
1900 if (S_GET_SEGMENT (sym
) == text_section
)
1901 csect
= ppc_text_csects
;
1902 else if (S_GET_SEGMENT (sym
) == data_section
)
1903 csect
= ppc_data_csects
;
1907 /* Skip the initial dummy symbol. */
1908 csect
= csect
->sy_tc
.next
;
1910 if (csect
== (symbolS
*) NULL
)
1911 a
->x_csect
.x_scnlen
.l
= 0;
1914 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
)
1916 resolve_symbol_value (csect
->sy_tc
.next
);
1917 if (S_GET_VALUE (csect
->sy_tc
.next
) > S_GET_VALUE (sym
))
1919 csect
= csect
->sy_tc
.next
;
1922 a
->x_csect
.x_scnlen
.p
= coffsymbol (csect
->bsym
)->native
;
1923 coffsymbol (sym
->bsym
)->native
[i
+ 1].fix_scnlen
= 1;
1925 a
->x_csect
.x_smtyp
= XTY_LD
;
1928 a
->x_csect
.x_parmhash
= 0;
1929 a
->x_csect
.x_snhash
= 0;
1930 if (sym
->sy_tc
.class == -1)
1931 a
->x_csect
.x_smclas
= XMC_PR
;
1933 a
->x_csect
.x_smclas
= sym
->sy_tc
.class;
1934 a
->x_csect
.x_stab
= 0;
1935 a
->x_csect
.x_snstab
= 0;
1937 else if (S_GET_STORAGE_CLASS (sym
) == C_BSTAT
)
1939 /* We want the value to be the symbol index of the referenced
1940 csect symbol. BFD will do that for us if we set the right
1943 (valueT
) coffsymbol (sym
->sy_tc
.within
->bsym
)->native
);
1944 coffsymbol (sym
->bsym
)->native
->fix_value
= 1;
1950 /* Set the VMA for a section. This is called on all the sections in
1954 ppc_frob_section (sec
)
1957 static bfd_size_type vma
= 0;
1959 bfd_set_section_vma (stdoutput
, sec
, vma
);
1960 vma
+= bfd_section_size (stdoutput
, sec
);
1963 /* Adjust the file by adding a .debug section if needed. */
1968 if (ppc_debug_name_section_size
> 0)
1972 sec
= bfd_make_section (stdoutput
, ".debug");
1973 if (sec
== (asection
*) NULL
1974 || ! bfd_set_section_size (stdoutput
, sec
,
1975 ppc_debug_name_section_size
)
1976 || ! bfd_set_section_flags (stdoutput
, sec
,
1977 SEC_HAS_CONTENTS
| SEC_LOAD
))
1978 as_fatal ("can't make .debug section");
1982 #endif /* OBJ_COFF */
1984 /* Turn a string in input_line_pointer into a floating point constant
1985 of type type, and store the appropriate bytes in *litp. The number
1986 of LITTLENUMS emitted is stored in *sizep . An error message is
1987 returned, or NULL on OK. */
1990 md_atof (type
, litp
, sizep
)
1996 LITTLENUM_TYPE words
[4];
2012 return "bad call to md_atof";
2015 t
= atof_ieee (input_line_pointer
, type
, words
);
2017 input_line_pointer
= t
;
2023 for (i
= 0; i
< prec
; i
++)
2025 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2031 for (i
= prec
- 1; i
>= 0; i
--)
2033 md_number_to_chars (litp
, (valueT
) words
[i
], 2);
2041 /* Write a value out to the object file, using the appropriate
2045 md_number_to_chars (buf
, val
, n
)
2051 number_to_chars_bigendian (buf
, val
, n
);
2053 number_to_chars_littleendian (buf
, val
, n
);
2056 /* Align a section (I don't know why this is machine dependent). */
2059 md_section_align (seg
, addr
)
2063 int align
= bfd_get_section_alignment (stdoutput
, seg
);
2065 return ((addr
+ (1 << align
) - 1) & (-1 << align
));
2068 /* We don't have any form of relaxing. */
2071 md_estimate_size_before_relax (fragp
, seg
)
2078 const relax_typeS md_relax_table
[] =
2083 /* Convert a machine dependent frag. We never generate these. */
2086 md_convert_frag (abfd
, sec
, fragp
)
2094 /* Parse an operand that is machine-specific. We just return without
2095 modifying the expression if we have nothing to do. */
2099 md_operand (expressionP
)
2100 expressionS
*expressionP
;
2104 /* We have no need to default values of symbols. */
2108 md_undefined_symbol (name
)
2114 /* Functions concerning relocs. */
2116 /* The location from which a PC relative jump should be calculated,
2117 given a PC relative reloc. */
2120 md_pcrel_from (fixp
)
2124 if (fixp
->fx_addsy
!= (symbolS
*) NULL
2125 && ! S_IS_DEFINED (fixp
->fx_addsy
))
2129 return fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2134 /* This is called to see whether a fixup should be adjusted to use a
2135 section symbol. We take the opportunity to change a fixup against
2136 a symbol in the TOC subsegment into a reloc against the
2137 corresponding .tc symbol. Note that this is called before the
2138 symbol values are finalized, but after the frag addresses are set,
2139 so we must add the frag address to the symbol values. */
2142 ppc_fix_adjustable (fix
)
2147 val
= S_GET_VALUE (fix
->fx_addsy
) + fix
->fx_addsy
->sy_frag
->fr_address
;
2148 if (ppc_toc_csect
!= (symbolS
*) NULL
2149 && fix
->fx_addsy
!= (symbolS
*) NULL
2150 && fix
->fx_addsy
!= ppc_toc_csect
2151 && S_GET_SEGMENT (fix
->fx_addsy
) == data_section
2152 && val
>= ppc_toc_frag
->fr_address
2153 && (ppc_after_toc_frag
== (fragS
*) NULL
2154 || val
< ppc_after_toc_frag
->fr_address
))
2158 for (sy
= symbol_next (ppc_toc_csect
);
2159 sy
!= (symbolS
*) NULL
;
2160 sy
= symbol_next (sy
))
2162 if (sy
->sy_tc
.class == XMC_TC0
)
2164 if (sy
->sy_tc
.class != XMC_TC
)
2166 if (val
== S_GET_VALUE (sy
) + sy
->sy_frag
->fr_address
)
2169 fix
->fx_addnumber
= val
- ppc_toc_frag
->fr_address
;
2174 as_bad_where (fix
->fx_file
, fix
->fx_line
,
2175 "symbol in .toc does not match any .tc");
2178 /* Possibly adjust the reloc to be against the csect. */
2179 if (fix
->fx_addsy
!= (symbolS
*) NULL
2180 && fix
->fx_addsy
->sy_tc
.subseg
== 0
2181 && fix
->fx_addsy
->sy_tc
.class != XMC_TC0
2182 && fix
->fx_addsy
->sy_tc
.class != XMC_TC
2183 && S_GET_SEGMENT (fix
->fx_addsy
) != bss_section
)
2187 if (S_GET_SEGMENT (fix
->fx_addsy
) == text_section
)
2188 csect
= ppc_text_csects
;
2189 else if (S_GET_SEGMENT (fix
->fx_addsy
) == data_section
)
2190 csect
= ppc_data_csects
;
2194 /* Skip the initial dummy symbol. */
2195 csect
= csect
->sy_tc
.next
;
2197 if (csect
!= (symbolS
*) NULL
)
2199 while (csect
->sy_tc
.next
!= (symbolS
*) NULL
2200 && (csect
->sy_tc
.next
->sy_frag
->fr_address
2201 <= fix
->fx_addsy
->sy_frag
->fr_address
))
2202 csect
= csect
->sy_tc
.next
;
2204 fix
->fx_offset
+= (S_GET_VALUE (fix
->fx_addsy
)
2205 + (fix
->fx_addsy
->sy_frag
->fr_address
2206 - csect
->sy_frag
->fr_address
));
2207 fix
->fx_addsy
= csect
;
2211 /* Adjust a reloc against a .lcomm symbol to be against the base
2213 if (fix
->fx_addsy
!= (symbolS
*) NULL
2214 && S_GET_SEGMENT (fix
->fx_addsy
) == bss_section
2215 && ! S_IS_EXTERNAL (fix
->fx_addsy
))
2217 fix
->fx_offset
+= S_GET_VALUE (fix
->fx_addsy
);
2218 fix
->fx_addsy
= fix
->fx_addsy
->sy_frag
->fr_symbol
;
2226 /* See whether a symbol is in the TOC section. */
2229 ppc_is_toc_sym (sym
)
2233 return sym
->sy_tc
.class == XMC_TC
;
2235 return strcmp (segment_name (S_GET_SEGMENT (sym
)), ".got") == 0;
2239 /* Apply a fixup to the object code. This is called for all the
2240 fixups we generated by the call to fix_new_exp, above. In the call
2241 above we used a reloc code which was the largest legal reloc code
2242 plus the operand index. Here we undo that to recover the operand
2243 index. At this point all symbol values should be fully resolved,
2244 and we attempt to completely resolve the reloc. If we can not do
2245 that, we determine the correct reloc code and put it back in the
2249 md_apply_fix (fixp
, valuep
)
2255 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
2256 the symbol values. Since we are using BFD_ASSEMBLER, if we are
2257 doing this relocation the code in write.c is going to call
2258 bfd_perform_relocation, which is also going to use the symbol
2259 value. That means that if the reloc is fully resolved we want to
2260 use *valuep since bfd_perform_relocation is not being used.
2261 However, if the reloc is not fully resolved we do not want to use
2262 *valuep, and must use fx_offset instead. However, if the reloc
2263 is PC relative, we do want to use *valuep since it includes the
2264 result of md_pcrel_from. This is confusing. */
2266 if (fixp
->fx_addsy
== (symbolS
*) NULL
)
2271 else if (fixp
->fx_pcrel
)
2275 value
= fixp
->fx_offset
;
2276 if (fixp
->fx_subsy
!= (symbolS
*) NULL
)
2278 if (S_GET_SEGMENT (fixp
->fx_subsy
) == absolute_section
)
2279 value
-= S_GET_VALUE (fixp
->fx_subsy
);
2282 /* We can't actually support subtracting a symbol. */
2283 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2284 "expression too complex");
2289 if ((int) fixp
->fx_r_type
>= (int) BFD_RELOC_UNUSED
)
2292 const struct powerpc_operand
*operand
;
2296 opindex
= (int) fixp
->fx_r_type
- (int) BFD_RELOC_UNUSED
;
2298 operand
= &powerpc_operands
[opindex
];
2300 /* Fetch the instruction, insert the fully resolved operand
2301 value, and stuff the instruction back again. */
2302 where
= fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
;
2304 insn
= bfd_getb32 ((unsigned char *) where
);
2306 insn
= bfd_getl32 ((unsigned char *) where
);
2307 insn
= ppc_insert_operand (insn
, operand
, (offsetT
) value
,
2308 fixp
->fx_file
, fixp
->fx_line
);
2310 bfd_putb32 ((bfd_vma
) insn
, (unsigned char *) where
);
2312 bfd_putl32 ((bfd_vma
) insn
, (unsigned char *) where
);
2316 /* Nothing else to do here. */
2320 /* Determine a BFD reloc value based on the operand information.
2321 We are only prepared to turn a few of the operands into
2323 FIXME: We need to handle the DS field at the very least.
2324 FIXME: Handling 16 bit branches would also be reasonable.
2325 FIXME: Selecting the reloc type is a bit haphazard; perhaps
2326 there should be a new field in the operand table. */
2327 if ((operand
->flags
& PPC_OPERAND_RELATIVE
) != 0
2328 && operand
->bits
== 26
2329 && operand
->shift
== 0)
2330 fixp
->fx_r_type
= BFD_RELOC_PPC_B26
;
2331 else if ((operand
->flags
& PPC_OPERAND_ABSOLUTE
) != 0
2332 && operand
->bits
== 26
2333 && operand
->shift
== 0)
2334 fixp
->fx_r_type
= BFD_RELOC_PPC_BA26
;
2335 else if ((operand
->flags
& PPC_OPERAND_PARENS
) != 0
2336 && operand
->bits
== 16
2337 && operand
->shift
== 0
2338 && operand
->insert
== NULL
2339 && fixp
->fx_addsy
!= NULL
2340 && ppc_is_toc_sym (fixp
->fx_addsy
))
2344 fixp
->fx_where
+= 2;
2345 fixp
->fx_r_type
= BFD_RELOC_PPC_TOC16
;
2349 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2350 "unresolved expression that must be resolved");
2357 switch (fixp
->fx_r_type
)
2360 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2364 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2368 md_number_to_chars (fixp
->fx_frag
->fr_literal
+ fixp
->fx_where
,
2377 fixp
->fx_addnumber
= value
;
2379 if (fixp
->fx_r_type
!= BFD_RELOC_PPC_TOC16
)
2380 fixp
->fx_addnumber
= 0;
2383 /* We want to use the offset within the data segment of the
2384 symbol, not the actual VMA of the symbol. */
2385 fixp
->fx_addnumber
=
2386 - bfd_get_section_vma (stdoutput
, S_GET_SEGMENT (fixp
->fx_addsy
));
2393 /* Generate a reloc for a fixup. */
2396 tc_gen_reloc (seg
, fixp
)
2402 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2404 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2405 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2406 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
2407 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
2409 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2410 "reloc not supported by object file format");
2413 reloc
->addend
= fixp
->fx_addnumber
;
2416 /* Don't ask. I hate this stuff. */
2417 if (reloc
->howto
->pc_relative
)
2418 reloc
->addend
-= reloc
->address
;