Add support for storing local symbols in a small structure to save
[binutils.git] / gas / config / tc-ppc.c
bloba028e0bae12006e5d1bf3d6e97e56b1abf61437f
1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright (C) 1994, 95, 96, 97, 98, 1999 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)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include <stdio.h>
23 #include <ctype.h>
24 #include "as.h"
25 #include "subsegs.h"
27 #include "opcode/ppc.h"
29 #ifdef OBJ_ELF
30 #include "elf/ppc.h"
31 #endif
33 #ifdef TE_PE
34 #include "coff/pe.h"
35 #endif
37 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
39 /* Tell the main code what the endianness is. */
40 extern int target_big_endian;
42 /* Whether or not, we've set target_big_endian. */
43 static int set_target_endian = 0;
45 /* Whether to use user friendly register names. */
46 #ifndef TARGET_REG_NAMES_P
47 #ifdef TE_PE
48 #define TARGET_REG_NAMES_P true
49 #else
50 #define TARGET_REG_NAMES_P false
51 #endif
52 #endif
54 static boolean reg_names_p = TARGET_REG_NAMES_P;
56 static boolean register_name PARAMS ((expressionS *));
57 static void ppc_set_cpu PARAMS ((void));
58 static unsigned long ppc_insert_operand
59 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
60 offsetT val, char *file, unsigned int line));
61 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
62 static void ppc_byte PARAMS ((int));
63 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
64 static void ppc_tc PARAMS ((int));
66 #ifdef OBJ_XCOFF
67 static void ppc_comm PARAMS ((int));
68 static void ppc_bb PARAMS ((int));
69 static void ppc_bc PARAMS ((int));
70 static void ppc_bf PARAMS ((int));
71 static void ppc_biei PARAMS ((int));
72 static void ppc_bs PARAMS ((int));
73 static void ppc_eb PARAMS ((int));
74 static void ppc_ec PARAMS ((int));
75 static void ppc_ef PARAMS ((int));
76 static void ppc_es PARAMS ((int));
77 static void ppc_csect PARAMS ((int));
78 static void ppc_change_csect PARAMS ((symbolS *));
79 static void ppc_function PARAMS ((int));
80 static void ppc_extern PARAMS ((int));
81 static void ppc_lglobl PARAMS ((int));
82 static void ppc_section PARAMS ((int));
83 static void ppc_named_section PARAMS ((int));
84 static void ppc_stabx PARAMS ((int));
85 static void ppc_rename PARAMS ((int));
86 static void ppc_toc PARAMS ((int));
87 static void ppc_xcoff_cons PARAMS ((int));
88 static void ppc_vbyte PARAMS ((int));
89 #endif
91 #ifdef OBJ_ELF
92 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
93 static void ppc_elf_cons PARAMS ((int));
94 static void ppc_elf_rdata PARAMS ((int));
95 static void ppc_elf_lcomm PARAMS ((int));
96 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
97 #endif
99 #ifdef TE_PE
100 static void ppc_set_current_section PARAMS ((segT));
101 static void ppc_previous PARAMS ((int));
102 static void ppc_pdata PARAMS ((int));
103 static void ppc_ydata PARAMS ((int));
104 static void ppc_reldata PARAMS ((int));
105 static void ppc_rdata PARAMS ((int));
106 static void ppc_ualong PARAMS ((int));
107 static void ppc_znop PARAMS ((int));
108 static void ppc_pe_comm PARAMS ((int));
109 static void ppc_pe_section PARAMS ((int));
110 static void ppc_pe_function PARAMS ((int));
111 static void ppc_pe_tocd PARAMS ((int));
112 #endif
114 /* Generic assembler global variables which must be defined by all
115 targets. */
117 #ifdef OBJ_ELF
118 /* This string holds the chars that always start a comment. If the
119 pre-processor is disabled, these aren't very useful. The macro
120 tc_comment_chars points to this. We use this, rather than the
121 usual comment_chars, so that we can switch for Solaris conventions. */
122 static const char ppc_solaris_comment_chars[] = "#!";
123 static const char ppc_eabi_comment_chars[] = "#";
125 #ifdef TARGET_SOLARIS_COMMENT
126 const char *ppc_comment_chars = ppc_solaris_comment_chars;
127 #else
128 const char *ppc_comment_chars = ppc_eabi_comment_chars;
129 #endif
130 #else
131 const char comment_chars[] = "#";
132 #endif
134 /* Characters which start a comment at the beginning of a line. */
135 const char line_comment_chars[] = "#";
137 /* Characters which may be used to separate multiple commands on a
138 single line. */
139 const char line_separator_chars[] = ";";
141 /* Characters which are used to indicate an exponent in a floating
142 point number. */
143 const char EXP_CHARS[] = "eE";
145 /* Characters which mean that a number is a floating point constant,
146 as in 0d1.0. */
147 const char FLT_CHARS[] = "dD";
149 /* The target specific pseudo-ops which we support. */
151 const pseudo_typeS md_pseudo_table[] =
153 /* Pseudo-ops which must be overridden. */
154 { "byte", ppc_byte, 0 },
156 #ifdef OBJ_XCOFF
157 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
158 legitimately belong in the obj-*.c file. However, XCOFF is based
159 on COFF, and is only implemented for the RS/6000. We just use
160 obj-coff.c, and add what we need here. */
161 { "comm", ppc_comm, 0 },
162 { "lcomm", ppc_comm, 1 },
163 { "bb", ppc_bb, 0 },
164 { "bc", ppc_bc, 0 },
165 { "bf", ppc_bf, 0 },
166 { "bi", ppc_biei, 0 },
167 { "bs", ppc_bs, 0 },
168 { "csect", ppc_csect, 0 },
169 { "data", ppc_section, 'd' },
170 { "eb", ppc_eb, 0 },
171 { "ec", ppc_ec, 0 },
172 { "ef", ppc_ef, 0 },
173 { "ei", ppc_biei, 1 },
174 { "es", ppc_es, 0 },
175 { "extern", ppc_extern, 0 },
176 { "function", ppc_function, 0 },
177 { "lglobl", ppc_lglobl, 0 },
178 { "rename", ppc_rename, 0 },
179 { "section", ppc_named_section, 0 },
180 { "stabx", ppc_stabx, 0 },
181 { "text", ppc_section, 't' },
182 { "toc", ppc_toc, 0 },
183 { "long", ppc_xcoff_cons, 2 },
184 { "word", ppc_xcoff_cons, 1 },
185 { "short", ppc_xcoff_cons, 1 },
186 { "vbyte", ppc_vbyte, 0 },
187 #endif
189 #ifdef OBJ_ELF
190 { "long", ppc_elf_cons, 4 },
191 { "word", ppc_elf_cons, 2 },
192 { "short", ppc_elf_cons, 2 },
193 { "rdata", ppc_elf_rdata, 0 },
194 { "rodata", ppc_elf_rdata, 0 },
195 { "lcomm", ppc_elf_lcomm, 0 },
196 #endif
198 #ifdef TE_PE
199 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
200 { "previous", ppc_previous, 0 },
201 { "pdata", ppc_pdata, 0 },
202 { "ydata", ppc_ydata, 0 },
203 { "reldata", ppc_reldata, 0 },
204 { "rdata", ppc_rdata, 0 },
205 { "ualong", ppc_ualong, 0 },
206 { "znop", ppc_znop, 0 },
207 { "comm", ppc_pe_comm, 0 },
208 { "lcomm", ppc_pe_comm, 1 },
209 { "section", ppc_pe_section, 0 },
210 { "function", ppc_pe_function,0 },
211 { "tocd", ppc_pe_tocd, 0 },
212 #endif
214 /* This pseudo-op is used even when not generating XCOFF output. */
215 { "tc", ppc_tc, 0 },
217 { NULL, NULL, 0 }
221 /* Predefined register names if -mregnames (or default for Windows NT). */
222 /* In general, there are lots of them, in an attempt to be compatible */
223 /* with a number of other Windows NT assemblers. */
225 /* Structure to hold information about predefined registers. */
226 struct pd_reg
228 char *name;
229 int value;
232 /* List of registers that are pre-defined:
234 Each general register has predefined names of the form:
235 1. r<reg_num> which has the value <reg_num>.
236 2. r.<reg_num> which has the value <reg_num>.
239 Each floating point register has predefined names of the form:
240 1. f<reg_num> which has the value <reg_num>.
241 2. f.<reg_num> which has the value <reg_num>.
243 Each condition register has predefined names of the form:
244 1. cr<reg_num> which has the value <reg_num>.
245 2. cr.<reg_num> which has the value <reg_num>.
247 There are individual registers as well:
248 sp or r.sp has the value 1
249 rtoc or r.toc has the value 2
250 fpscr has the value 0
251 xer has the value 1
252 lr has the value 8
253 ctr has the value 9
254 pmr has the value 0
255 dar has the value 19
256 dsisr has the value 18
257 dec has the value 22
258 sdr1 has the value 25
259 srr0 has the value 26
260 srr1 has the value 27
262 The table is sorted. Suitable for searching by a binary search. */
264 static const struct pd_reg pre_defined_registers[] =
266 { "cr.0", 0 }, /* Condition Registers */
267 { "cr.1", 1 },
268 { "cr.2", 2 },
269 { "cr.3", 3 },
270 { "cr.4", 4 },
271 { "cr.5", 5 },
272 { "cr.6", 6 },
273 { "cr.7", 7 },
275 { "cr0", 0 },
276 { "cr1", 1 },
277 { "cr2", 2 },
278 { "cr3", 3 },
279 { "cr4", 4 },
280 { "cr5", 5 },
281 { "cr6", 6 },
282 { "cr7", 7 },
284 { "ctr", 9 },
286 { "dar", 19 }, /* Data Access Register */
287 { "dec", 22 }, /* Decrementer */
288 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
290 { "f.0", 0 }, /* Floating point registers */
291 { "f.1", 1 },
292 { "f.10", 10 },
293 { "f.11", 11 },
294 { "f.12", 12 },
295 { "f.13", 13 },
296 { "f.14", 14 },
297 { "f.15", 15 },
298 { "f.16", 16 },
299 { "f.17", 17 },
300 { "f.18", 18 },
301 { "f.19", 19 },
302 { "f.2", 2 },
303 { "f.20", 20 },
304 { "f.21", 21 },
305 { "f.22", 22 },
306 { "f.23", 23 },
307 { "f.24", 24 },
308 { "f.25", 25 },
309 { "f.26", 26 },
310 { "f.27", 27 },
311 { "f.28", 28 },
312 { "f.29", 29 },
313 { "f.3", 3 },
314 { "f.30", 30 },
315 { "f.31", 31 },
316 { "f.4", 4 },
317 { "f.5", 5 },
318 { "f.6", 6 },
319 { "f.7", 7 },
320 { "f.8", 8 },
321 { "f.9", 9 },
323 { "f0", 0 },
324 { "f1", 1 },
325 { "f10", 10 },
326 { "f11", 11 },
327 { "f12", 12 },
328 { "f13", 13 },
329 { "f14", 14 },
330 { "f15", 15 },
331 { "f16", 16 },
332 { "f17", 17 },
333 { "f18", 18 },
334 { "f19", 19 },
335 { "f2", 2 },
336 { "f20", 20 },
337 { "f21", 21 },
338 { "f22", 22 },
339 { "f23", 23 },
340 { "f24", 24 },
341 { "f25", 25 },
342 { "f26", 26 },
343 { "f27", 27 },
344 { "f28", 28 },
345 { "f29", 29 },
346 { "f3", 3 },
347 { "f30", 30 },
348 { "f31", 31 },
349 { "f4", 4 },
350 { "f5", 5 },
351 { "f6", 6 },
352 { "f7", 7 },
353 { "f8", 8 },
354 { "f9", 9 },
356 { "fpscr", 0 },
358 { "lr", 8 }, /* Link Register */
360 { "pmr", 0 },
362 { "r.0", 0 }, /* General Purpose Registers */
363 { "r.1", 1 },
364 { "r.10", 10 },
365 { "r.11", 11 },
366 { "r.12", 12 },
367 { "r.13", 13 },
368 { "r.14", 14 },
369 { "r.15", 15 },
370 { "r.16", 16 },
371 { "r.17", 17 },
372 { "r.18", 18 },
373 { "r.19", 19 },
374 { "r.2", 2 },
375 { "r.20", 20 },
376 { "r.21", 21 },
377 { "r.22", 22 },
378 { "r.23", 23 },
379 { "r.24", 24 },
380 { "r.25", 25 },
381 { "r.26", 26 },
382 { "r.27", 27 },
383 { "r.28", 28 },
384 { "r.29", 29 },
385 { "r.3", 3 },
386 { "r.30", 30 },
387 { "r.31", 31 },
388 { "r.4", 4 },
389 { "r.5", 5 },
390 { "r.6", 6 },
391 { "r.7", 7 },
392 { "r.8", 8 },
393 { "r.9", 9 },
395 { "r.sp", 1 }, /* Stack Pointer */
397 { "r.toc", 2 }, /* Pointer to the table of contents */
399 { "r0", 0 }, /* More general purpose registers */
400 { "r1", 1 },
401 { "r10", 10 },
402 { "r11", 11 },
403 { "r12", 12 },
404 { "r13", 13 },
405 { "r14", 14 },
406 { "r15", 15 },
407 { "r16", 16 },
408 { "r17", 17 },
409 { "r18", 18 },
410 { "r19", 19 },
411 { "r2", 2 },
412 { "r20", 20 },
413 { "r21", 21 },
414 { "r22", 22 },
415 { "r23", 23 },
416 { "r24", 24 },
417 { "r25", 25 },
418 { "r26", 26 },
419 { "r27", 27 },
420 { "r28", 28 },
421 { "r29", 29 },
422 { "r3", 3 },
423 { "r30", 30 },
424 { "r31", 31 },
425 { "r4", 4 },
426 { "r5", 5 },
427 { "r6", 6 },
428 { "r7", 7 },
429 { "r8", 8 },
430 { "r9", 9 },
432 { "rtoc", 2 }, /* Table of contents */
434 { "sdr1", 25 }, /* Storage Description Register 1 */
436 { "sp", 1 },
438 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
439 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
441 { "xer", 1 },
445 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
447 /* Given NAME, find the register number associated with that name, return
448 the integer value associated with the given name or -1 on failure. */
450 static int reg_name_search
451 PARAMS ((const struct pd_reg *, int, const char * name));
453 static int
454 reg_name_search (regs, regcount, name)
455 const struct pd_reg *regs;
456 int regcount;
457 const char *name;
459 int middle, low, high;
460 int cmp;
462 low = 0;
463 high = regcount - 1;
467 middle = (low + high) / 2;
468 cmp = strcasecmp (name, regs[middle].name);
469 if (cmp < 0)
470 high = middle - 1;
471 else if (cmp > 0)
472 low = middle + 1;
473 else
474 return regs[middle].value;
476 while (low <= high);
478 return -1;
482 * Summary of register_name().
484 * in: Input_line_pointer points to 1st char of operand.
486 * out: A expressionS.
487 * The operand may have been a register: in this case, X_op == O_register,
488 * X_add_number is set to the register number, and truth is returned.
489 * Input_line_pointer->(next non-blank) char after operand, or is in its
490 * original state.
493 static boolean
494 register_name (expressionP)
495 expressionS *expressionP;
497 int reg_number;
498 char *name;
499 char *start;
500 char c;
502 /* Find the spelling of the operand */
503 start = name = input_line_pointer;
504 if (name[0] == '%' && isalpha (name[1]))
505 name = ++input_line_pointer;
507 else if (!reg_names_p || !isalpha (name[0]))
508 return false;
510 c = get_symbol_end ();
511 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
513 /* look to see if it's in the register table */
514 if (reg_number >= 0)
516 expressionP->X_op = O_register;
517 expressionP->X_add_number = reg_number;
519 /* make the rest nice */
520 expressionP->X_add_symbol = NULL;
521 expressionP->X_op_symbol = NULL;
522 *input_line_pointer = c; /* put back the delimiting char */
523 return true;
525 else
527 /* reset the line as if we had not done anything */
528 *input_line_pointer = c; /* put back the delimiting char */
529 input_line_pointer = start; /* reset input_line pointer */
530 return false;
534 /* This function is called for each symbol seen in an expression. It
535 handles the special parsing which PowerPC assemblers are supposed
536 to use for condition codes. */
538 /* Whether to do the special parsing. */
539 static boolean cr_operand;
541 /* Names to recognize in a condition code. This table is sorted. */
542 static const struct pd_reg cr_names[] =
544 { "cr0", 0 },
545 { "cr1", 1 },
546 { "cr2", 2 },
547 { "cr3", 3 },
548 { "cr4", 4 },
549 { "cr5", 5 },
550 { "cr6", 6 },
551 { "cr7", 7 },
552 { "eq", 2 },
553 { "gt", 1 },
554 { "lt", 0 },
555 { "so", 3 },
556 { "un", 3 }
559 /* Parsing function. This returns non-zero if it recognized an
560 expression. */
563 ppc_parse_name (name, expr)
564 const char *name;
565 expressionS *expr;
567 int val;
569 if (! cr_operand)
570 return 0;
572 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
573 name);
574 if (val < 0)
575 return 0;
577 expr->X_op = O_constant;
578 expr->X_add_number = val;
580 return 1;
583 /* Local variables. */
585 /* The type of processor we are assembling for. This is one or more
586 of the PPC_OPCODE flags defined in opcode/ppc.h. */
587 static int ppc_cpu = 0;
589 /* The size of the processor we are assembling for. This is either
590 PPC_OPCODE_32 or PPC_OPCODE_64. */
591 static int ppc_size = PPC_OPCODE_32;
593 /* Opcode hash table. */
594 static struct hash_control *ppc_hash;
596 /* Macro hash table. */
597 static struct hash_control *ppc_macro_hash;
599 #ifdef OBJ_ELF
600 /* What type of shared library support to use */
601 static enum { SHLIB_NONE, SHLIB_PIC, SHILB_MRELOCATABLE } shlib = SHLIB_NONE;
603 /* Flags to set in the elf header */
604 static flagword ppc_flags = 0;
606 /* Whether this is Solaris or not. */
607 #ifdef TARGET_SOLARIS_COMMENT
608 #define SOLARIS_P true
609 #else
610 #define SOLARIS_P false
611 #endif
613 static boolean msolaris = SOLARIS_P;
614 #endif
616 #ifdef OBJ_XCOFF
618 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
619 using a bunch of different sections. These assembler sections,
620 however, are all encompassed within the .text or .data sections of
621 the final output file. We handle this by using different
622 subsegments within these main segments. */
624 /* Next subsegment to allocate within the .text segment. */
625 static subsegT ppc_text_subsegment = 2;
627 /* Linked list of csects in the text section. */
628 static symbolS *ppc_text_csects;
630 /* Next subsegment to allocate within the .data segment. */
631 static subsegT ppc_data_subsegment = 2;
633 /* Linked list of csects in the data section. */
634 static symbolS *ppc_data_csects;
636 /* The current csect. */
637 static symbolS *ppc_current_csect;
639 /* The RS/6000 assembler uses a TOC which holds addresses of functions
640 and variables. Symbols are put in the TOC with the .tc pseudo-op.
641 A special relocation is used when accessing TOC entries. We handle
642 the TOC as a subsegment within the .data segment. We set it up if
643 we see a .toc pseudo-op, and save the csect symbol here. */
644 static symbolS *ppc_toc_csect;
646 /* The first frag in the TOC subsegment. */
647 static fragS *ppc_toc_frag;
649 /* The first frag in the first subsegment after the TOC in the .data
650 segment. NULL if there are no subsegments after the TOC. */
651 static fragS *ppc_after_toc_frag;
653 /* The current static block. */
654 static symbolS *ppc_current_block;
656 /* The COFF debugging section; set by md_begin. This is not the
657 .debug section, but is instead the secret BFD section which will
658 cause BFD to set the section number of a symbol to N_DEBUG. */
659 static asection *ppc_coff_debug_section;
661 #endif /* OBJ_XCOFF */
663 #ifdef TE_PE
665 /* Various sections that we need for PE coff support. */
666 static segT ydata_section;
667 static segT pdata_section;
668 static segT reldata_section;
669 static segT rdata_section;
670 static segT tocdata_section;
672 /* The current section and the previous section. See ppc_previous. */
673 static segT ppc_previous_section;
674 static segT ppc_current_section;
676 #endif /* TE_PE */
678 #ifdef OBJ_ELF
679 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
680 #endif /* OBJ_ELF */
682 #ifdef OBJ_ELF
683 CONST char *md_shortopts = "b:l:usm:K:VQ:";
684 #else
685 CONST char *md_shortopts = "um:";
686 #endif
687 struct option md_longopts[] = {
688 {NULL, no_argument, NULL, 0}
690 size_t md_longopts_size = sizeof(md_longopts);
693 md_parse_option (c, arg)
694 int c;
695 char *arg;
697 switch (c)
699 case 'u':
700 /* -u means that any undefined symbols should be treated as
701 external, which is the default for gas anyhow. */
702 break;
704 #ifdef OBJ_ELF
705 case 'l':
706 /* Solaris as takes -le (presumably for little endian). For completeness
707 sake, recognize -be also. */
708 if (strcmp (arg, "e") == 0)
710 target_big_endian = 0;
711 set_target_endian = 1;
713 else
714 return 0;
716 break;
718 case 'b':
719 if (strcmp (arg, "e") == 0)
721 target_big_endian = 1;
722 set_target_endian = 1;
724 else
725 return 0;
727 break;
729 case 'K':
730 /* Recognize -K PIC */
731 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
733 shlib = SHLIB_PIC;
734 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
736 else
737 return 0;
739 break;
740 #endif
742 case 'm':
743 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
744 (RIOS2). */
745 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
746 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2;
747 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
748 else if (strcmp (arg, "pwr") == 0)
749 ppc_cpu = PPC_OPCODE_POWER;
750 /* -m601 means to assemble for the Motorola PowerPC 601, which includes
751 instructions that are holdovers from the Power. */
752 else if (strcmp (arg, "601") == 0)
753 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_601;
754 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
755 Motorola PowerPC 603/604. */
756 else if (strcmp (arg, "ppc") == 0
757 || strcmp (arg, "ppc32") == 0
758 || strcmp (arg, "403") == 0
759 || strcmp (arg, "603") == 0
760 || strcmp (arg, "604") == 0)
761 ppc_cpu = PPC_OPCODE_PPC;
762 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
763 620. */
764 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
766 ppc_cpu = PPC_OPCODE_PPC;
767 ppc_size = PPC_OPCODE_64;
769 else if (strcmp (arg, "ppc64bridge") == 0)
771 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_64_BRIDGE;
772 ppc_size = PPC_OPCODE_64;
774 /* -mcom means assemble for the common intersection between Power
775 and PowerPC. At present, we just allow the union, rather
776 than the intersection. */
777 else if (strcmp (arg, "com") == 0)
778 ppc_cpu = PPC_OPCODE_COMMON;
779 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
780 else if (strcmp (arg, "any") == 0)
781 ppc_cpu = PPC_OPCODE_ANY;
783 else if (strcmp (arg, "regnames") == 0)
784 reg_names_p = true;
786 else if (strcmp (arg, "no-regnames") == 0)
787 reg_names_p = false;
789 #ifdef OBJ_ELF
790 /* -mrelocatable/-mrelocatable-lib -- warn about initializations that require relocation */
791 else if (strcmp (arg, "relocatable") == 0)
793 shlib = SHILB_MRELOCATABLE;
794 ppc_flags |= EF_PPC_RELOCATABLE;
797 else if (strcmp (arg, "relocatable-lib") == 0)
799 shlib = SHILB_MRELOCATABLE;
800 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
803 /* -memb, set embedded bit */
804 else if (strcmp (arg, "emb") == 0)
805 ppc_flags |= EF_PPC_EMB;
807 /* -mlittle/-mbig set the endianess */
808 else if (strcmp (arg, "little") == 0 || strcmp (arg, "little-endian") == 0)
810 target_big_endian = 0;
811 set_target_endian = 1;
814 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
816 target_big_endian = 1;
817 set_target_endian = 1;
820 else if (strcmp (arg, "solaris") == 0)
822 msolaris = true;
823 ppc_comment_chars = ppc_solaris_comment_chars;
826 else if (strcmp (arg, "no-solaris") == 0)
828 msolaris = false;
829 ppc_comment_chars = ppc_eabi_comment_chars;
831 #endif
832 else
834 as_bad (_("invalid switch -m%s"), arg);
835 return 0;
837 break;
839 #ifdef OBJ_ELF
840 /* -V: SVR4 argument to print version ID. */
841 case 'V':
842 print_version_id ();
843 break;
845 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
846 should be emitted or not. FIXME: Not implemented. */
847 case 'Q':
848 break;
850 /* Solaris takes -s to specify that .stabs go in a .stabs section,
851 rather than .stabs.excl, which is ignored by the linker.
852 FIXME: Not implemented. */
853 case 's':
854 if (arg)
855 return 0;
857 break;
858 #endif
860 default:
861 return 0;
864 return 1;
867 void
868 md_show_usage (stream)
869 FILE *stream;
871 fprintf(stream, _("\
872 PowerPC options:\n\
873 -u ignored\n\
874 -mpwrx, -mpwr2 generate code for IBM POWER/2 (RIOS2)\n\
875 -mpwr generate code for IBM POWER (RIOS1)\n\
876 -m601 generate code for Motorola PowerPC 601\n\
877 -mppc, -mppc32, -m403, -m603, -m604\n\
878 generate code for Motorola PowerPC 603/604\n\
879 -mppc64, -m620 generate code for Motorola PowerPC 620\n\
880 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
881 -mcom generate code Power/PowerPC common instructions\n\
882 -many generate code for any architecture (PWR/PWRX/PPC)\n\
883 -mregnames Allow symbolic names for registers\n\
884 -mno-regnames Do not allow symbolic names for registers\n"));
885 #ifdef OBJ_ELF
886 fprintf(stream, _("\
887 -mrelocatable support for GCC's -mrelocatble option\n\
888 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
889 -memb set PPC_EMB bit in ELF flags\n\
890 -mlittle, -mlittle-endian\n\
891 generate code for a little endian machine\n\
892 -mbig, -mbig-endian generate code for a big endian machine\n\
893 -msolaris generate code for Solaris\n\
894 -mno-solaris do not generate code for Solaris\n\
895 -V print assembler version number\n\
896 -Qy, -Qn ignored\n"));
897 #endif
900 /* Set ppc_cpu if it is not already set. */
902 static void
903 ppc_set_cpu ()
905 const char *default_os = TARGET_OS;
906 const char *default_cpu = TARGET_CPU;
908 if (ppc_cpu == 0)
910 if (strncmp (default_os, "aix", 3) == 0
911 && default_os[3] >= '4' && default_os[3] <= '9')
912 ppc_cpu = PPC_OPCODE_COMMON;
913 else if (strncmp (default_os, "aix3", 4) == 0)
914 ppc_cpu = PPC_OPCODE_POWER;
915 else if (strcmp (default_cpu, "rs6000") == 0)
916 ppc_cpu = PPC_OPCODE_POWER;
917 else if (strcmp (default_cpu, "powerpc") == 0
918 || strcmp (default_cpu, "powerpcle") == 0)
919 ppc_cpu = PPC_OPCODE_PPC;
920 else
921 as_fatal (_("Unknown default cpu = %s, os = %s"), default_cpu, default_os);
925 /* Figure out the BFD architecture to use. */
927 enum bfd_architecture
928 ppc_arch ()
930 const char *default_cpu = TARGET_CPU;
931 ppc_set_cpu ();
933 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
934 return bfd_arch_powerpc;
935 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
936 return bfd_arch_rs6000;
937 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
939 if (strcmp (default_cpu, "rs6000") == 0)
940 return bfd_arch_rs6000;
941 else if (strcmp (default_cpu, "powerpc") == 0
942 || strcmp (default_cpu, "powerpcle") == 0)
943 return bfd_arch_powerpc;
946 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
947 return bfd_arch_unknown;
950 /* This function is called when the assembler starts up. It is called
951 after the options have been parsed and the output file has been
952 opened. */
954 void
955 md_begin ()
957 register const struct powerpc_opcode *op;
958 const struct powerpc_opcode *op_end;
959 const struct powerpc_macro *macro;
960 const struct powerpc_macro *macro_end;
961 boolean dup_insn = false;
963 ppc_set_cpu ();
965 #ifdef OBJ_ELF
966 /* Set the ELF flags if desired. */
967 if (ppc_flags && !msolaris)
968 bfd_set_private_flags (stdoutput, ppc_flags);
969 #endif
971 /* Insert the opcodes into a hash table. */
972 ppc_hash = hash_new ();
974 op_end = powerpc_opcodes + powerpc_num_opcodes;
975 for (op = powerpc_opcodes; op < op_end; op++)
977 know ((op->opcode & op->mask) == op->opcode);
979 if ((op->flags & ppc_cpu) != 0
980 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
981 || (op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == ppc_size
982 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0))
984 const char *retval;
986 retval = hash_insert (ppc_hash, op->name, (PTR) op);
987 if (retval != (const char *) NULL)
989 /* Ignore Power duplicates for -m601 */
990 if ((ppc_cpu & PPC_OPCODE_601) != 0
991 && (op->flags & PPC_OPCODE_POWER) != 0)
992 continue;
994 as_bad (_("Internal assembler error for instruction %s"), op->name);
995 dup_insn = true;
1000 /* Insert the macros into a hash table. */
1001 ppc_macro_hash = hash_new ();
1003 macro_end = powerpc_macros + powerpc_num_macros;
1004 for (macro = powerpc_macros; macro < macro_end; macro++)
1006 if ((macro->flags & ppc_cpu) != 0)
1008 const char *retval;
1010 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1011 if (retval != (const char *) NULL)
1013 as_bad (_("Internal assembler error for macro %s"), macro->name);
1014 dup_insn = true;
1019 if (dup_insn)
1020 abort ();
1022 /* Tell the main code what the endianness is if it is not overidden by the user. */
1023 if (!set_target_endian)
1025 set_target_endian = 1;
1026 target_big_endian = PPC_BIG_ENDIAN;
1029 #ifdef OBJ_XCOFF
1030 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1032 /* Create dummy symbols to serve as initial csects. This forces the
1033 text csects to precede the data csects. These symbols will not
1034 be output. */
1035 ppc_text_csects = symbol_make ("dummy\001");
1036 ppc_text_csects->sy_tc.within = ppc_text_csects;
1037 ppc_data_csects = symbol_make ("dummy\001");
1038 ppc_data_csects->sy_tc.within = ppc_data_csects;
1039 #endif
1041 #ifdef TE_PE
1043 ppc_current_section = text_section;
1044 ppc_previous_section = 0;
1046 #endif
1049 /* Insert an operand value into an instruction. */
1051 static unsigned long
1052 ppc_insert_operand (insn, operand, val, file, line)
1053 unsigned long insn;
1054 const struct powerpc_operand *operand;
1055 offsetT val;
1056 char *file;
1057 unsigned int line;
1059 if (operand->bits != 32)
1061 long min, max;
1062 offsetT test;
1064 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1066 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1067 max = (1 << operand->bits) - 1;
1068 else
1069 max = (1 << (operand->bits - 1)) - 1;
1070 min = - (1 << (operand->bits - 1));
1072 if (ppc_size == PPC_OPCODE_32)
1074 /* Some people write 32 bit hex constants with the sign
1075 extension done by hand. This shouldn't really be
1076 valid, but, to permit this code to assemble on a 64
1077 bit host, we sign extend the 32 bit value. */
1078 if (val > 0
1079 && (val & 0x80000000) != 0
1080 && (val & 0xffffffff) == val)
1082 val -= 0x80000000;
1083 val -= 0x80000000;
1087 else
1089 max = (1 << operand->bits) - 1;
1090 min = 0;
1093 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1094 test = - val;
1095 else
1096 test = val;
1098 if (test < (offsetT) min || test > (offsetT) max)
1100 const char *err =
1101 _("operand out of range (%s not between %ld and %ld)");
1102 char buf[100];
1104 sprint_value (buf, test);
1105 if (file == (char *) NULL)
1106 as_bad (err, buf, min, max);
1107 else
1108 as_bad_where (file, line, err, buf, min, max);
1112 if (operand->insert)
1114 const char *errmsg;
1116 errmsg = NULL;
1117 insn = (*operand->insert) (insn, (long) val, &errmsg);
1118 if (errmsg != (const char *) NULL)
1119 as_bad (errmsg);
1121 else
1122 insn |= (((long) val & ((1 << operand->bits) - 1))
1123 << operand->shift);
1125 return insn;
1129 #ifdef OBJ_ELF
1130 /* Parse @got, etc. and return the desired relocation. */
1131 static bfd_reloc_code_real_type
1132 ppc_elf_suffix (str_p, exp_p)
1133 char **str_p;
1134 expressionS *exp_p;
1136 struct map_bfd {
1137 char *string;
1138 int length;
1139 bfd_reloc_code_real_type reloc;
1142 char ident[20];
1143 char *str = *str_p;
1144 char *str2;
1145 int ch;
1146 int len;
1147 struct map_bfd *ptr;
1149 #define MAP(str,reloc) { str, sizeof(str)-1, reloc }
1151 static struct map_bfd mapping[] = {
1152 MAP ("l", BFD_RELOC_LO16),
1153 MAP ("h", BFD_RELOC_HI16),
1154 MAP ("ha", BFD_RELOC_HI16_S),
1155 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1156 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1157 MAP ("got", BFD_RELOC_16_GOTOFF),
1158 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1159 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1160 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1161 MAP ("fixup", BFD_RELOC_CTOR), /* warnings with -mrelocatable */
1162 MAP ("plt", BFD_RELOC_24_PLT_PCREL),
1163 MAP ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1164 MAP ("copy", BFD_RELOC_PPC_COPY),
1165 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1166 MAP ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1167 MAP ("local", BFD_RELOC_PPC_LOCAL24PC),
1168 MAP ("pltrel", BFD_RELOC_32_PLT_PCREL),
1169 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1170 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1171 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1172 MAP ("sdarel", BFD_RELOC_GPREL16),
1173 MAP ("sectoff", BFD_RELOC_32_BASEREL),
1174 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1175 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1176 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1177 MAP ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1178 MAP ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1179 MAP ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1180 MAP ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1181 MAP ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1182 MAP ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1183 MAP ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1184 MAP ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1185 MAP ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1186 MAP ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1187 MAP ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1188 MAP ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1189 MAP ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1190 MAP ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1191 MAP ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1192 MAP ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1193 MAP ("xgot", BFD_RELOC_PPC_TOC16),
1195 { (char *)0, 0, BFD_RELOC_UNUSED }
1198 if (*str++ != '@')
1199 return BFD_RELOC_UNUSED;
1201 for (ch = *str, str2 = ident;
1202 (str2 < ident + sizeof (ident) - 1
1203 && (isalnum (ch) || ch == '@'));
1204 ch = *++str)
1206 *str2++ = (islower (ch)) ? ch : tolower (ch);
1209 *str2 = '\0';
1210 len = str2 - ident;
1212 ch = ident[0];
1213 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1214 if (ch == ptr->string[0]
1215 && len == ptr->length
1216 && memcmp (ident, ptr->string, ptr->length) == 0)
1218 if (exp_p->X_add_number != 0
1219 && (ptr->reloc == BFD_RELOC_16_GOTOFF
1220 || ptr->reloc == BFD_RELOC_LO16_GOTOFF
1221 || ptr->reloc == BFD_RELOC_HI16_GOTOFF
1222 || ptr->reloc == BFD_RELOC_HI16_S_GOTOFF))
1223 as_warn (_("identifier+constant@got means identifier@got+constant"));
1225 /* Now check for identifier@suffix+constant */
1226 if (*str == '-' || *str == '+')
1228 char *orig_line = input_line_pointer;
1229 expressionS new_exp;
1231 input_line_pointer = str;
1232 expression (&new_exp);
1233 if (new_exp.X_op == O_constant)
1235 exp_p->X_add_number += new_exp.X_add_number;
1236 str = input_line_pointer;
1239 if (&input_line_pointer != str_p)
1240 input_line_pointer = orig_line;
1243 *str_p = str;
1244 return ptr->reloc;
1247 return BFD_RELOC_UNUSED;
1250 /* Like normal .long/.short/.word, except support @got, etc. */
1251 /* clobbers input_line_pointer, checks */
1252 /* end-of-line. */
1253 static void
1254 ppc_elf_cons (nbytes)
1255 register int nbytes; /* 1=.byte, 2=.word, 4=.long */
1257 expressionS exp;
1258 bfd_reloc_code_real_type reloc;
1260 if (is_it_end_of_statement ())
1262 demand_empty_rest_of_line ();
1263 return;
1268 expression (&exp);
1269 if (exp.X_op == O_symbol
1270 && *input_line_pointer == '@'
1271 && (reloc = ppc_elf_suffix (&input_line_pointer, &exp)) != BFD_RELOC_UNUSED)
1273 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1274 int size = bfd_get_reloc_size (reloc_howto);
1276 if (size > nbytes)
1277 as_bad (_("%s relocations do not fit in %d bytes\n"), reloc_howto->name, nbytes);
1279 else
1281 register char *p = frag_more ((int) nbytes);
1282 int offset = nbytes - size;
1284 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size, &exp, 0, reloc);
1287 else
1288 emit_expr (&exp, (unsigned int) nbytes);
1290 while (*input_line_pointer++ == ',');
1292 input_line_pointer--; /* Put terminator back into stream. */
1293 demand_empty_rest_of_line ();
1296 /* Solaris pseduo op to change to the .rodata section. */
1297 static void
1298 ppc_elf_rdata (xxx)
1299 int xxx;
1301 char *save_line = input_line_pointer;
1302 static char section[] = ".rodata\n";
1304 /* Just pretend this is .section .rodata */
1305 input_line_pointer = section;
1306 obj_elf_section (xxx);
1308 input_line_pointer = save_line;
1311 /* Pseudo op to make file scope bss items */
1312 static void
1313 ppc_elf_lcomm(xxx)
1314 int xxx;
1316 register char *name;
1317 register char c;
1318 register char *p;
1319 offsetT size;
1320 register symbolS *symbolP;
1321 offsetT align;
1322 segT old_sec;
1323 int old_subsec;
1324 char *pfrag;
1325 int align2;
1327 name = input_line_pointer;
1328 c = get_symbol_end ();
1330 /* just after name is now '\0' */
1331 p = input_line_pointer;
1332 *p = c;
1333 SKIP_WHITESPACE ();
1334 if (*input_line_pointer != ',')
1336 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1337 ignore_rest_of_line ();
1338 return;
1341 input_line_pointer++; /* skip ',' */
1342 if ((size = get_absolute_expression ()) < 0)
1344 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1345 ignore_rest_of_line ();
1346 return;
1349 /* The third argument to .lcomm is the alignment. */
1350 if (*input_line_pointer != ',')
1351 align = 8;
1352 else
1354 ++input_line_pointer;
1355 align = get_absolute_expression ();
1356 if (align <= 0)
1358 as_warn (_("ignoring bad alignment"));
1359 align = 8;
1363 *p = 0;
1364 symbolP = symbol_find_or_make (name);
1365 *p = c;
1367 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1369 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1370 S_GET_NAME (symbolP));
1371 ignore_rest_of_line ();
1372 return;
1375 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1377 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1378 S_GET_NAME (symbolP),
1379 (long) S_GET_VALUE (symbolP),
1380 (long) size);
1382 ignore_rest_of_line ();
1383 return;
1386 /* allocate_bss: */
1387 old_sec = now_seg;
1388 old_subsec = now_subseg;
1389 if (align)
1391 /* convert to a power of 2 alignment */
1392 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1393 if (align != 1)
1395 as_bad (_("Common alignment not a power of 2"));
1396 ignore_rest_of_line ();
1397 return;
1400 else
1401 align2 = 0;
1403 record_alignment (bss_section, align2);
1404 subseg_set (bss_section, 0);
1405 if (align2)
1406 frag_align (align2, 0, 0);
1407 if (S_GET_SEGMENT (symbolP) == bss_section)
1408 symbol_get_frag (symbolP)->fr_symbol = 0;
1409 symbol_set_frag (symbolP, frag_now);
1410 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1411 (char *) 0);
1412 *pfrag = 0;
1413 S_SET_SIZE (symbolP, size);
1414 S_SET_SEGMENT (symbolP, bss_section);
1415 subseg_set (old_sec, old_subsec);
1416 demand_empty_rest_of_line ();
1419 /* Validate any relocations emitted for -mrelocatable, possibly adding
1420 fixups for word relocations in writable segments, so we can adjust
1421 them at runtime. */
1422 static void
1423 ppc_elf_validate_fix (fixp, seg)
1424 fixS *fixp;
1425 segT seg;
1427 if (fixp->fx_done || fixp->fx_pcrel)
1428 return;
1430 switch (shlib)
1432 case SHLIB_NONE:
1433 case SHLIB_PIC:
1434 return;
1436 case SHILB_MRELOCATABLE:
1437 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1438 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1439 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1440 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1441 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1442 && fixp->fx_r_type != BFD_RELOC_32_BASEREL
1443 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1444 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1445 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1446 && strcmp (segment_name (seg), ".got2") != 0
1447 && strcmp (segment_name (seg), ".dtors") != 0
1448 && strcmp (segment_name (seg), ".ctors") != 0
1449 && strcmp (segment_name (seg), ".fixup") != 0
1450 && strcmp (segment_name (seg), ".stab") != 0
1451 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1452 && strcmp (segment_name (seg), ".eh_frame") != 0
1453 && strcmp (segment_name (seg), ".ex_shared") != 0)
1455 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1456 || fixp->fx_r_type != BFD_RELOC_CTOR)
1458 as_bad_where (fixp->fx_file, fixp->fx_line,
1459 _("Relocation cannot be done when using -mrelocatable"));
1462 return;
1465 #endif /* OBJ_ELF */
1467 #ifdef TE_PE
1470 * Summary of parse_toc_entry().
1472 * in: Input_line_pointer points to the '[' in one of:
1474 * [toc] [tocv] [toc32] [toc64]
1476 * Anything else is an error of one kind or another.
1478 * out:
1479 * return value: success or failure
1480 * toc_kind: kind of toc reference
1481 * input_line_pointer:
1482 * success: first char after the ']'
1483 * failure: unchanged
1485 * settings:
1487 * [toc] - rv == success, toc_kind = default_toc
1488 * [tocv] - rv == success, toc_kind = data_in_toc
1489 * [toc32] - rv == success, toc_kind = must_be_32
1490 * [toc64] - rv == success, toc_kind = must_be_64
1494 enum toc_size_qualifier
1496 default_toc, /* The toc cell constructed should be the system default size */
1497 data_in_toc, /* This is a direct reference to a toc cell */
1498 must_be_32, /* The toc cell constructed must be 32 bits wide */
1499 must_be_64 /* The toc cell constructed must be 64 bits wide */
1502 static int
1503 parse_toc_entry(toc_kind)
1504 enum toc_size_qualifier *toc_kind;
1506 char *start;
1507 char *toc_spec;
1508 char c;
1509 enum toc_size_qualifier t;
1511 /* save the input_line_pointer */
1512 start = input_line_pointer;
1514 /* skip over the '[' , and whitespace */
1515 ++input_line_pointer;
1516 SKIP_WHITESPACE ();
1518 /* find the spelling of the operand */
1519 toc_spec = input_line_pointer;
1520 c = get_symbol_end ();
1522 if (strcmp(toc_spec, "toc") == 0)
1524 t = default_toc;
1526 else if (strcmp(toc_spec, "tocv") == 0)
1528 t = data_in_toc;
1530 else if (strcmp(toc_spec, "toc32") == 0)
1532 t = must_be_32;
1534 else if (strcmp(toc_spec, "toc64") == 0)
1536 t = must_be_64;
1538 else
1540 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
1541 *input_line_pointer = c; /* put back the delimiting char */
1542 input_line_pointer = start; /* reset input_line pointer */
1543 return 0;
1546 /* now find the ']' */
1547 *input_line_pointer = c; /* put back the delimiting char */
1549 SKIP_WHITESPACE (); /* leading whitespace could be there. */
1550 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
1552 if (c != ']')
1554 as_bad (_("syntax error: expected `]', found `%c'"), c);
1555 input_line_pointer = start; /* reset input_line pointer */
1556 return 0;
1559 *toc_kind = t; /* set return value */
1560 return 1;
1562 #endif
1565 /* We need to keep a list of fixups. We can't simply generate them as
1566 we go, because that would require us to first create the frag, and
1567 that would screw up references to ``.''. */
1569 struct ppc_fixup
1571 expressionS exp;
1572 int opindex;
1573 bfd_reloc_code_real_type reloc;
1576 #define MAX_INSN_FIXUPS (5)
1578 /* This routine is called for each instruction to be assembled. */
1580 void
1581 md_assemble (str)
1582 char *str;
1584 char *s;
1585 const struct powerpc_opcode *opcode;
1586 unsigned long insn;
1587 const unsigned char *opindex_ptr;
1588 int skip_optional;
1589 int need_paren;
1590 int next_opindex;
1591 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
1592 int fc;
1593 char *f;
1594 int i;
1595 #ifdef OBJ_ELF
1596 bfd_reloc_code_real_type reloc;
1597 #endif
1599 /* Get the opcode. */
1600 for (s = str; *s != '\0' && ! isspace (*s); s++)
1602 if (*s != '\0')
1603 *s++ = '\0';
1605 /* Look up the opcode in the hash table. */
1606 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
1607 if (opcode == (const struct powerpc_opcode *) NULL)
1609 const struct powerpc_macro *macro;
1611 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
1612 if (macro == (const struct powerpc_macro *) NULL)
1613 as_bad (_("Unrecognized opcode: `%s'"), str);
1614 else
1615 ppc_macro (s, macro);
1617 return;
1620 insn = opcode->opcode;
1622 str = s;
1623 while (isspace (*str))
1624 ++str;
1626 /* PowerPC operands are just expressions. The only real issue is
1627 that a few operand types are optional. All cases which might use
1628 an optional operand separate the operands only with commas (in
1629 some cases parentheses are used, as in ``lwz 1,0(1)'' but such
1630 cases never have optional operands). There is never more than
1631 one optional operand for an instruction. So, before we start
1632 seriously parsing the operands, we check to see if we have an
1633 optional operand, and, if we do, we count the number of commas to
1634 see whether the operand should be omitted. */
1635 skip_optional = 0;
1636 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1638 const struct powerpc_operand *operand;
1640 operand = &powerpc_operands[*opindex_ptr];
1641 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
1643 unsigned int opcount;
1645 /* There is an optional operand. Count the number of
1646 commas in the input line. */
1647 if (*str == '\0')
1648 opcount = 0;
1649 else
1651 opcount = 1;
1652 s = str;
1653 while ((s = strchr (s, ',')) != (char *) NULL)
1655 ++opcount;
1656 ++s;
1660 /* If there are fewer operands in the line then are called
1661 for by the instruction, we want to skip the optional
1662 operand. */
1663 if (opcount < strlen (opcode->operands))
1664 skip_optional = 1;
1666 break;
1670 /* Gather the operands. */
1671 need_paren = 0;
1672 next_opindex = 0;
1673 fc = 0;
1674 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
1676 const struct powerpc_operand *operand;
1677 const char *errmsg;
1678 char *hold;
1679 expressionS ex;
1680 char endc;
1682 if (next_opindex == 0)
1683 operand = &powerpc_operands[*opindex_ptr];
1684 else
1686 operand = &powerpc_operands[next_opindex];
1687 next_opindex = 0;
1690 errmsg = NULL;
1692 /* If this is a fake operand, then we do not expect anything
1693 from the input. */
1694 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
1696 insn = (*operand->insert) (insn, 0L, &errmsg);
1697 if (errmsg != (const char *) NULL)
1698 as_bad (errmsg);
1699 continue;
1702 /* If this is an optional operand, and we are skipping it, just
1703 insert a zero. */
1704 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
1705 && skip_optional)
1707 if (operand->insert)
1709 insn = (*operand->insert) (insn, 0L, &errmsg);
1710 if (errmsg != (const char *) NULL)
1711 as_bad (errmsg);
1713 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
1714 next_opindex = *opindex_ptr + 1;
1715 continue;
1718 /* Gather the operand. */
1719 hold = input_line_pointer;
1720 input_line_pointer = str;
1722 #ifdef TE_PE
1723 if (*input_line_pointer == '[')
1725 /* We are expecting something like the second argument here:
1727 lwz r4,[toc].GS.0.static_int(rtoc)
1728 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
1729 The argument following the `]' must be a symbol name, and the
1730 register must be the toc register: 'rtoc' or '2'
1732 The effect is to 0 as the displacement field
1733 in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
1734 the appropriate variation) reloc against it based on the symbol.
1735 The linker will build the toc, and insert the resolved toc offset.
1737 Note:
1738 o The size of the toc entry is currently assumed to be
1739 32 bits. This should not be assumed to be a hard coded
1740 number.
1741 o In an effort to cope with a change from 32 to 64 bits,
1742 there are also toc entries that are specified to be
1743 either 32 or 64 bits:
1744 lwz r4,[toc32].GS.0.static_int(rtoc)
1745 lwz r4,[toc64].GS.0.static_int(rtoc)
1746 These demand toc entries of the specified size, and the
1747 instruction probably requires it.
1750 int valid_toc;
1751 enum toc_size_qualifier toc_kind;
1752 bfd_reloc_code_real_type toc_reloc;
1754 /* go parse off the [tocXX] part */
1755 valid_toc = parse_toc_entry(&toc_kind);
1757 if (!valid_toc)
1759 /* Note: message has already been issued. */
1760 /* FIXME: what sort of recovery should we do? */
1761 /* demand_rest_of_line(); return; ? */
1764 /* Now get the symbol following the ']' */
1765 expression(&ex);
1767 switch (toc_kind)
1769 case default_toc:
1770 /* In this case, we may not have seen the symbol yet, since */
1771 /* it is allowed to appear on a .extern or .globl or just be */
1772 /* a label in the .data section. */
1773 toc_reloc = BFD_RELOC_PPC_TOC16;
1774 break;
1775 case data_in_toc:
1776 /* 1. The symbol must be defined and either in the toc */
1777 /* section, or a global. */
1778 /* 2. The reloc generated must have the TOCDEFN flag set in */
1779 /* upper bit mess of the reloc type. */
1780 /* FIXME: It's a little confusing what the tocv qualifier can */
1781 /* be used for. At the very least, I've seen three */
1782 /* uses, only one of which I'm sure I can explain. */
1783 if (ex.X_op == O_symbol)
1785 assert (ex.X_add_symbol != NULL);
1786 if (ex.X_add_symbol->bsym->section != tocdata_section)
1788 as_bad(_("[tocv] symbol is not a toc symbol"));
1792 toc_reloc = BFD_RELOC_PPC_TOC16;
1793 break;
1794 case must_be_32:
1795 /* FIXME: these next two specifically specify 32/64 bit toc */
1796 /* entries. We don't support them today. Is this the */
1797 /* right way to say that? */
1798 toc_reloc = BFD_RELOC_UNUSED;
1799 as_bad (_("Unimplemented toc32 expression modifier"));
1800 break;
1801 case must_be_64:
1802 /* FIXME: see above */
1803 toc_reloc = BFD_RELOC_UNUSED;
1804 as_bad (_("Unimplemented toc64 expression modifier"));
1805 break;
1806 default:
1807 fprintf(stderr,
1808 _("Unexpected return value [%d] from parse_toc_entry!\n"),
1809 toc_kind);
1810 abort();
1811 break;
1814 /* We need to generate a fixup for this expression. */
1815 if (fc >= MAX_INSN_FIXUPS)
1816 as_fatal (_("too many fixups"));
1818 fixups[fc].reloc = toc_reloc;
1819 fixups[fc].exp = ex;
1820 fixups[fc].opindex = *opindex_ptr;
1821 ++fc;
1823 /* Ok. We've set up the fixup for the instruction. Now make it
1824 look like the constant 0 was found here */
1825 ex.X_unsigned = 1;
1826 ex.X_op = O_constant;
1827 ex.X_add_number = 0;
1828 ex.X_add_symbol = NULL;
1829 ex.X_op_symbol = NULL;
1832 else
1833 #endif /* TE_PE */
1835 if (! register_name (&ex))
1837 if ((operand->flags & PPC_OPERAND_CR) != 0)
1838 cr_operand = true;
1839 expression (&ex);
1840 cr_operand = false;
1844 str = input_line_pointer;
1845 input_line_pointer = hold;
1847 if (ex.X_op == O_illegal)
1848 as_bad (_("illegal operand"));
1849 else if (ex.X_op == O_absent)
1850 as_bad (_("missing operand"));
1851 else if (ex.X_op == O_register)
1853 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1854 (char *) NULL, 0);
1856 else if (ex.X_op == O_constant)
1858 #ifdef OBJ_ELF
1859 /* Allow @HA, @L, @H on constants. */
1860 char *orig_str = str;
1862 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1863 switch (reloc)
1865 default:
1866 str = orig_str;
1867 break;
1869 case BFD_RELOC_LO16:
1870 /* X_unsigned is the default, so if the user has done
1871 something which cleared it, we always produce a
1872 signed value. */
1873 if (ex.X_unsigned
1874 && (operand->flags & PPC_OPERAND_SIGNED) == 0)
1875 ex.X_add_number &= 0xffff;
1876 else
1877 ex.X_add_number = (((ex.X_add_number & 0xffff)
1878 ^ 0x8000)
1879 - 0x8000);
1880 break;
1882 case BFD_RELOC_HI16:
1883 ex.X_add_number = (ex.X_add_number >> 16) & 0xffff;
1884 break;
1886 case BFD_RELOC_HI16_S:
1887 ex.X_add_number = (((ex.X_add_number >> 16) & 0xffff)
1888 + ((ex.X_add_number >> 15) & 1));
1889 break;
1891 #endif
1892 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
1893 (char *) NULL, 0);
1895 #ifdef OBJ_ELF
1896 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
1898 /* For the absoulte forms of branchs, convert the PC relative form back into
1899 the absolute. */
1900 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
1902 switch (reloc)
1904 case BFD_RELOC_PPC_B26:
1905 reloc = BFD_RELOC_PPC_BA26;
1906 break;
1907 case BFD_RELOC_PPC_B16:
1908 reloc = BFD_RELOC_PPC_BA16;
1909 break;
1910 case BFD_RELOC_PPC_B16_BRTAKEN:
1911 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
1912 break;
1913 case BFD_RELOC_PPC_B16_BRNTAKEN:
1914 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
1915 break;
1916 default:
1917 break;
1921 /* We need to generate a fixup for this expression. */
1922 if (fc >= MAX_INSN_FIXUPS)
1923 as_fatal (_("too many fixups"));
1924 fixups[fc].exp = ex;
1925 fixups[fc].opindex = 0;
1926 fixups[fc].reloc = reloc;
1927 ++fc;
1929 #endif /* OBJ_ELF */
1931 else
1933 /* We need to generate a fixup for this expression. */
1934 if (fc >= MAX_INSN_FIXUPS)
1935 as_fatal (_("too many fixups"));
1936 fixups[fc].exp = ex;
1937 fixups[fc].opindex = *opindex_ptr;
1938 fixups[fc].reloc = BFD_RELOC_UNUSED;
1939 ++fc;
1942 if (need_paren)
1944 endc = ')';
1945 need_paren = 0;
1947 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
1949 endc = '(';
1950 need_paren = 1;
1952 else
1953 endc = ',';
1955 /* The call to expression should have advanced str past any
1956 whitespace. */
1957 if (*str != endc
1958 && (endc != ',' || *str != '\0'))
1960 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
1961 break;
1964 if (*str != '\0')
1965 ++str;
1968 while (isspace (*str))
1969 ++str;
1971 if (*str != '\0')
1972 as_bad (_("junk at end of line: `%s'"), str);
1974 /* Write out the instruction. */
1975 f = frag_more (4);
1976 md_number_to_chars (f, insn, 4);
1978 /* Create any fixups. At this point we do not use a
1979 bfd_reloc_code_real_type, but instead just use the
1980 BFD_RELOC_UNUSED plus the operand index. This lets us easily
1981 handle fixups for any operand type, although that is admittedly
1982 not a very exciting feature. We pick a BFD reloc type in
1983 md_apply_fix. */
1984 for (i = 0; i < fc; i++)
1986 const struct powerpc_operand *operand;
1988 operand = &powerpc_operands[fixups[i].opindex];
1989 if (fixups[i].reloc != BFD_RELOC_UNUSED)
1991 reloc_howto_type *reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
1992 int size;
1993 int offset;
1994 fixS *fixP;
1996 if (!reloc_howto)
1997 abort ();
1999 size = bfd_get_reloc_size (reloc_howto);
2000 offset = target_big_endian ? (4 - size) : 0;
2002 if (size < 1 || size > 4)
2003 abort();
2005 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal + offset, size,
2006 &fixups[i].exp, reloc_howto->pc_relative,
2007 fixups[i].reloc);
2009 /* Turn off complaints that the addend is too large for things like
2010 foo+100000@ha. */
2011 switch (fixups[i].reloc)
2013 case BFD_RELOC_16_GOTOFF:
2014 case BFD_RELOC_PPC_TOC16:
2015 case BFD_RELOC_LO16:
2016 case BFD_RELOC_HI16:
2017 case BFD_RELOC_HI16_S:
2018 fixP->fx_no_overflow = 1;
2019 break;
2020 default:
2021 break;
2024 else
2025 fix_new_exp (frag_now, f - frag_now->fr_literal, 4,
2026 &fixups[i].exp,
2027 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2028 ((bfd_reloc_code_real_type)
2029 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2033 /* Handle a macro. Gather all the operands, transform them as
2034 described by the macro, and call md_assemble recursively. All the
2035 operands are separated by commas; we don't accept parentheses
2036 around operands here. */
2038 static void
2039 ppc_macro (str, macro)
2040 char *str;
2041 const struct powerpc_macro *macro;
2043 char *operands[10];
2044 unsigned int count;
2045 char *s;
2046 unsigned int len;
2047 const char *format;
2048 int arg;
2049 char *send;
2050 char *complete;
2052 /* Gather the users operands into the operands array. */
2053 count = 0;
2054 s = str;
2055 while (1)
2057 if (count >= sizeof operands / sizeof operands[0])
2058 break;
2059 operands[count++] = s;
2060 s = strchr (s, ',');
2061 if (s == (char *) NULL)
2062 break;
2063 *s++ = '\0';
2066 if (count != macro->operands)
2068 as_bad (_("wrong number of operands"));
2069 return;
2072 /* Work out how large the string must be (the size is unbounded
2073 because it includes user input). */
2074 len = 0;
2075 format = macro->format;
2076 while (*format != '\0')
2078 if (*format != '%')
2080 ++len;
2081 ++format;
2083 else
2085 arg = strtol (format + 1, &send, 10);
2086 know (send != format && arg >= 0 && arg < count);
2087 len += strlen (operands[arg]);
2088 format = send;
2092 /* Put the string together. */
2093 complete = s = (char *) alloca (len + 1);
2094 format = macro->format;
2095 while (*format != '\0')
2097 if (*format != '%')
2098 *s++ = *format++;
2099 else
2101 arg = strtol (format + 1, &send, 10);
2102 strcpy (s, operands[arg]);
2103 s += strlen (s);
2104 format = send;
2107 *s = '\0';
2109 /* Assemble the constructed instruction. */
2110 md_assemble (complete);
2113 #ifdef OBJ_ELF
2114 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED */
2117 ppc_section_letter (letter, ptr_msg)
2118 int letter;
2119 char **ptr_msg;
2121 if (letter == 'e')
2122 return SHF_EXCLUDE;
2124 *ptr_msg = _("Bad .section directive: want a,w,x,e in string");
2125 return 0;
2129 ppc_section_word (ptr_str)
2130 char **ptr_str;
2132 if (strncmp (*ptr_str, "exclude", sizeof ("exclude")-1) == 0)
2134 *ptr_str += sizeof ("exclude")-1;
2135 return SHF_EXCLUDE;
2138 return 0;
2142 ppc_section_type (ptr_str)
2143 char **ptr_str;
2145 if (strncmp (*ptr_str, "ordered", sizeof ("ordered")-1) == 0)
2147 *ptr_str += sizeof ("ordered")-1;
2148 return SHT_ORDERED;
2151 return 0;
2155 ppc_section_flags (flags, attr, type)
2156 int flags;
2157 int attr;
2158 int type;
2160 if (type == SHT_ORDERED)
2161 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2163 if (attr & SHF_EXCLUDE)
2164 flags |= SEC_EXCLUDE;
2166 return flags;
2168 #endif /* OBJ_ELF */
2171 /* Pseudo-op handling. */
2173 /* The .byte pseudo-op. This is similar to the normal .byte
2174 pseudo-op, but it can also take a single ASCII string. */
2176 static void
2177 ppc_byte (ignore)
2178 int ignore;
2180 if (*input_line_pointer != '\"')
2182 cons (1);
2183 return;
2186 /* Gather characters. A real double quote is doubled. Unusual
2187 characters are not permitted. */
2188 ++input_line_pointer;
2189 while (1)
2191 char c;
2193 c = *input_line_pointer++;
2195 if (c == '\"')
2197 if (*input_line_pointer != '\"')
2198 break;
2199 ++input_line_pointer;
2202 FRAG_APPEND_1_CHAR (c);
2205 demand_empty_rest_of_line ();
2208 #ifdef OBJ_XCOFF
2210 /* XCOFF specific pseudo-op handling. */
2212 /* This is set if we are creating a .stabx symbol, since we don't want
2213 to handle symbol suffixes for such symbols. */
2214 static boolean ppc_stab_symbol;
2216 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2217 symbols in the .bss segment as though they were local common
2218 symbols, and uses a different smclas. */
2220 static void
2221 ppc_comm (lcomm)
2222 int lcomm;
2224 asection *current_seg = now_seg;
2225 subsegT current_subseg = now_subseg;
2226 char *name;
2227 char endc;
2228 char *end_name;
2229 offsetT size;
2230 offsetT align;
2231 symbolS *lcomm_sym = NULL;
2232 symbolS *sym;
2233 char *pfrag;
2235 name = input_line_pointer;
2236 endc = get_symbol_end ();
2237 end_name = input_line_pointer;
2238 *end_name = endc;
2240 if (*input_line_pointer != ',')
2242 as_bad (_("missing size"));
2243 ignore_rest_of_line ();
2244 return;
2246 ++input_line_pointer;
2248 size = get_absolute_expression ();
2249 if (size < 0)
2251 as_bad (_("negative size"));
2252 ignore_rest_of_line ();
2253 return;
2256 if (! lcomm)
2258 /* The third argument to .comm is the alignment. */
2259 if (*input_line_pointer != ',')
2260 align = 3;
2261 else
2263 ++input_line_pointer;
2264 align = get_absolute_expression ();
2265 if (align <= 0)
2267 as_warn (_("ignoring bad alignment"));
2268 align = 3;
2272 else
2274 char *lcomm_name;
2275 char lcomm_endc;
2277 if (size <= 1)
2278 align = 0;
2279 else if (size <= 2)
2280 align = 1;
2281 else if (size <= 4)
2282 align = 2;
2283 else
2284 align = 3;
2286 /* The third argument to .lcomm appears to be the real local
2287 common symbol to create. References to the symbol named in
2288 the first argument are turned into references to the third
2289 argument. */
2290 if (*input_line_pointer != ',')
2292 as_bad (_("missing real symbol name"));
2293 ignore_rest_of_line ();
2294 return;
2296 ++input_line_pointer;
2298 lcomm_name = input_line_pointer;
2299 lcomm_endc = get_symbol_end ();
2301 lcomm_sym = symbol_find_or_make (lcomm_name);
2303 *input_line_pointer = lcomm_endc;
2306 *end_name = '\0';
2307 sym = symbol_find_or_make (name);
2308 *end_name = endc;
2310 if (S_IS_DEFINED (sym)
2311 || S_GET_VALUE (sym) != 0)
2313 as_bad (_("attempt to redefine symbol"));
2314 ignore_rest_of_line ();
2315 return;
2318 record_alignment (bss_section, align);
2320 if (! lcomm
2321 || ! S_IS_DEFINED (lcomm_sym))
2323 symbolS *def_sym;
2324 offsetT def_size;
2326 if (! lcomm)
2328 def_sym = sym;
2329 def_size = size;
2330 S_SET_EXTERNAL (sym);
2332 else
2334 lcomm_sym->sy_tc.output = 1;
2335 def_sym = lcomm_sym;
2336 def_size = 0;
2339 subseg_set (bss_section, 1);
2340 frag_align (align, 0, 0);
2342 def_sym->sy_frag = frag_now;
2343 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
2344 def_size, (char *) NULL);
2345 *pfrag = 0;
2346 S_SET_SEGMENT (def_sym, bss_section);
2347 def_sym->sy_tc.align = align;
2349 else if (lcomm)
2351 /* Align the size of lcomm_sym. */
2352 lcomm_sym->sy_frag->fr_offset =
2353 ((lcomm_sym->sy_frag->fr_offset + (1 << align) - 1)
2354 &~ ((1 << align) - 1));
2355 if (align > lcomm_sym->sy_tc.align)
2356 lcomm_sym->sy_tc.align = align;
2359 if (lcomm)
2361 /* Make sym an offset from lcomm_sym. */
2362 S_SET_SEGMENT (sym, bss_section);
2363 sym->sy_frag = lcomm_sym->sy_frag;
2364 S_SET_VALUE (sym, lcomm_sym->sy_frag->fr_offset);
2365 lcomm_sym->sy_frag->fr_offset += size;
2368 subseg_set (current_seg, current_subseg);
2370 demand_empty_rest_of_line ();
2373 /* The .csect pseudo-op. This switches us into a different
2374 subsegment. The first argument is a symbol whose value is the
2375 start of the .csect. In COFF, csect symbols get special aux
2376 entries defined by the x_csect field of union internal_auxent. The
2377 optional second argument is the alignment (the default is 2). */
2379 static void
2380 ppc_csect (ignore)
2381 int ignore;
2383 char *name;
2384 char endc;
2385 symbolS *sym;
2387 name = input_line_pointer;
2388 endc = get_symbol_end ();
2390 sym = symbol_find_or_make (name);
2392 *input_line_pointer = endc;
2394 if (S_GET_NAME (sym)[0] == '\0')
2396 /* An unnamed csect is assumed to be [PR]. */
2397 sym->sy_tc.class = XMC_PR;
2400 ppc_change_csect (sym);
2402 if (*input_line_pointer == ',')
2404 ++input_line_pointer;
2405 sym->sy_tc.align = get_absolute_expression ();
2408 demand_empty_rest_of_line ();
2411 /* Change to a different csect. */
2413 static void
2414 ppc_change_csect (sym)
2415 symbolS *sym;
2417 if (S_IS_DEFINED (sym))
2418 subseg_set (S_GET_SEGMENT (sym), sym->sy_tc.subseg);
2419 else
2421 symbolS **list_ptr;
2422 int after_toc;
2423 int hold_chunksize;
2424 symbolS *list;
2426 /* This is a new csect. We need to look at the symbol class to
2427 figure out whether it should go in the text section or the
2428 data section. */
2429 after_toc = 0;
2430 switch (sym->sy_tc.class)
2432 case XMC_PR:
2433 case XMC_RO:
2434 case XMC_DB:
2435 case XMC_GL:
2436 case XMC_XO:
2437 case XMC_SV:
2438 case XMC_TI:
2439 case XMC_TB:
2440 S_SET_SEGMENT (sym, text_section);
2441 sym->sy_tc.subseg = ppc_text_subsegment;
2442 ++ppc_text_subsegment;
2443 list_ptr = &ppc_text_csects;
2444 break;
2445 case XMC_RW:
2446 case XMC_TC0:
2447 case XMC_TC:
2448 case XMC_DS:
2449 case XMC_UA:
2450 case XMC_BS:
2451 case XMC_UC:
2452 if (ppc_toc_csect != NULL
2453 && ppc_toc_csect->sy_tc.subseg + 1 == ppc_data_subsegment)
2454 after_toc = 1;
2455 S_SET_SEGMENT (sym, data_section);
2456 sym->sy_tc.subseg = ppc_data_subsegment;
2457 ++ppc_data_subsegment;
2458 list_ptr = &ppc_data_csects;
2459 break;
2460 default:
2461 abort ();
2464 /* We set the obstack chunk size to a small value before
2465 changing subsegments, so that we don't use a lot of memory
2466 space for what may be a small section. */
2467 hold_chunksize = chunksize;
2468 chunksize = 64;
2470 subseg_new (segment_name (S_GET_SEGMENT (sym)), sym->sy_tc.subseg);
2472 chunksize = hold_chunksize;
2474 if (after_toc)
2475 ppc_after_toc_frag = frag_now;
2477 sym->sy_frag = frag_now;
2478 S_SET_VALUE (sym, (valueT) frag_now_fix ());
2480 sym->sy_tc.align = 2;
2481 sym->sy_tc.output = 1;
2482 sym->sy_tc.within = sym;
2484 for (list = *list_ptr;
2485 list->sy_tc.next != (symbolS *) NULL;
2486 list = list->sy_tc.next)
2488 list->sy_tc.next = sym;
2490 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2491 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
2494 ppc_current_csect = sym;
2497 /* This function handles the .text and .data pseudo-ops. These
2498 pseudo-ops aren't really used by XCOFF; we implement them for the
2499 convenience of people who aren't used to XCOFF. */
2501 static void
2502 ppc_section (type)
2503 int type;
2505 const char *name;
2506 symbolS *sym;
2508 if (type == 't')
2509 name = ".text[PR]";
2510 else if (type == 'd')
2511 name = ".data[RW]";
2512 else
2513 abort ();
2515 sym = symbol_find_or_make (name);
2517 ppc_change_csect (sym);
2519 demand_empty_rest_of_line ();
2522 /* This function handles the .section pseudo-op. This is mostly to
2523 give an error, since XCOFF only supports .text, .data and .bss, but
2524 we do permit the user to name the text or data section. */
2526 static void
2527 ppc_named_section (ignore)
2528 int ignore;
2530 char *user_name;
2531 const char *real_name;
2532 char c;
2533 symbolS *sym;
2535 user_name = input_line_pointer;
2536 c = get_symbol_end ();
2538 if (strcmp (user_name, ".text") == 0)
2539 real_name = ".text[PR]";
2540 else if (strcmp (user_name, ".data") == 0)
2541 real_name = ".data[RW]";
2542 else
2544 as_bad (_("The XCOFF file format does not support arbitrary sections"));
2545 *input_line_pointer = c;
2546 ignore_rest_of_line ();
2547 return;
2550 *input_line_pointer = c;
2552 sym = symbol_find_or_make (real_name);
2554 ppc_change_csect (sym);
2556 demand_empty_rest_of_line ();
2559 /* The .extern pseudo-op. We create an undefined symbol. */
2561 static void
2562 ppc_extern (ignore)
2563 int ignore;
2565 char *name;
2566 char endc;
2568 name = input_line_pointer;
2569 endc = get_symbol_end ();
2571 (void) symbol_find_or_make (name);
2573 *input_line_pointer = endc;
2575 demand_empty_rest_of_line ();
2578 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
2580 static void
2581 ppc_lglobl (ignore)
2582 int ignore;
2584 char *name;
2585 char endc;
2586 symbolS *sym;
2588 name = input_line_pointer;
2589 endc = get_symbol_end ();
2591 sym = symbol_find_or_make (name);
2593 *input_line_pointer = endc;
2595 sym->sy_tc.output = 1;
2597 demand_empty_rest_of_line ();
2600 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
2601 although I don't know why it bothers. */
2603 static void
2604 ppc_rename (ignore)
2605 int ignore;
2607 char *name;
2608 char endc;
2609 symbolS *sym;
2610 int len;
2612 name = input_line_pointer;
2613 endc = get_symbol_end ();
2615 sym = symbol_find_or_make (name);
2617 *input_line_pointer = endc;
2619 if (*input_line_pointer != ',')
2621 as_bad (_("missing rename string"));
2622 ignore_rest_of_line ();
2623 return;
2625 ++input_line_pointer;
2627 sym->sy_tc.real_name = demand_copy_C_string (&len);
2629 demand_empty_rest_of_line ();
2632 /* The .stabx pseudo-op. This is similar to a normal .stabs
2633 pseudo-op, but slightly different. A sample is
2634 .stabx "main:F-1",.main,142,0
2635 The first argument is the symbol name to create. The second is the
2636 value, and the third is the storage class. The fourth seems to be
2637 always zero, and I am assuming it is the type. */
2639 static void
2640 ppc_stabx (ignore)
2641 int ignore;
2643 char *name;
2644 int len;
2645 symbolS *sym;
2646 expressionS exp;
2648 name = demand_copy_C_string (&len);
2650 if (*input_line_pointer != ',')
2652 as_bad (_("missing value"));
2653 return;
2655 ++input_line_pointer;
2657 ppc_stab_symbol = true;
2658 sym = symbol_make (name);
2659 ppc_stab_symbol = false;
2661 sym->sy_tc.real_name = name;
2663 (void) expression (&exp);
2665 switch (exp.X_op)
2667 case O_illegal:
2668 case O_absent:
2669 case O_big:
2670 as_bad (_("illegal .stabx expression; zero assumed"));
2671 exp.X_add_number = 0;
2672 /* Fall through. */
2673 case O_constant:
2674 S_SET_VALUE (sym, (valueT) exp.X_add_number);
2675 sym->sy_frag = &zero_address_frag;
2676 break;
2678 case O_symbol:
2679 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
2680 sym->sy_value = exp;
2681 else
2683 S_SET_VALUE (sym,
2684 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
2685 sym->sy_frag = exp.X_add_symbol->sy_frag;
2687 break;
2689 default:
2690 /* The value is some complex expression. This will probably
2691 fail at some later point, but this is probably the right
2692 thing to do here. */
2693 sym->sy_value = exp;
2694 break;
2697 S_SET_SEGMENT (sym, ppc_coff_debug_section);
2698 sym->bsym->flags |= BSF_DEBUGGING;
2700 if (*input_line_pointer != ',')
2702 as_bad (_("missing class"));
2703 return;
2705 ++input_line_pointer;
2707 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
2709 if (*input_line_pointer != ',')
2711 as_bad (_("missing type"));
2712 return;
2714 ++input_line_pointer;
2716 S_SET_DATA_TYPE (sym, get_absolute_expression ());
2718 sym->sy_tc.output = 1;
2720 if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
2721 sym->sy_tc.within = ppc_current_block;
2723 if (exp.X_op != O_symbol
2724 || ! S_IS_EXTERNAL (exp.X_add_symbol)
2725 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
2726 ppc_frob_label (sym);
2727 else
2729 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2730 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
2731 if (ppc_current_csect->sy_tc.within == exp.X_add_symbol)
2732 ppc_current_csect->sy_tc.within = sym;
2735 demand_empty_rest_of_line ();
2738 /* The .function pseudo-op. This takes several arguments. The first
2739 argument seems to be the external name of the symbol. The second
2740 argment seems to be the label for the start of the function. gcc
2741 uses the same name for both. I have no idea what the third and
2742 fourth arguments are meant to be. The optional fifth argument is
2743 an expression for the size of the function. In COFF this symbol
2744 gets an aux entry like that used for a csect. */
2746 static void
2747 ppc_function (ignore)
2748 int ignore;
2750 char *name;
2751 char endc;
2752 char *s;
2753 symbolS *ext_sym;
2754 symbolS *lab_sym;
2756 name = input_line_pointer;
2757 endc = get_symbol_end ();
2759 /* Ignore any [PR] suffix. */
2760 name = ppc_canonicalize_symbol_name (name);
2761 s = strchr (name, '[');
2762 if (s != (char *) NULL
2763 && strcmp (s + 1, "PR]") == 0)
2764 *s = '\0';
2766 ext_sym = symbol_find_or_make (name);
2768 *input_line_pointer = endc;
2770 if (*input_line_pointer != ',')
2772 as_bad (_("missing symbol name"));
2773 ignore_rest_of_line ();
2774 return;
2776 ++input_line_pointer;
2778 name = input_line_pointer;
2779 endc = get_symbol_end ();
2781 lab_sym = symbol_find_or_make (name);
2783 *input_line_pointer = endc;
2785 if (ext_sym != lab_sym)
2787 ext_sym->sy_value.X_op = O_symbol;
2788 ext_sym->sy_value.X_add_symbol = lab_sym;
2789 ext_sym->sy_value.X_op_symbol = NULL;
2790 ext_sym->sy_value.X_add_number = 0;
2793 if (ext_sym->sy_tc.class == -1)
2794 ext_sym->sy_tc.class = XMC_PR;
2795 ext_sym->sy_tc.output = 1;
2797 if (*input_line_pointer == ',')
2799 expressionS ignore;
2801 /* Ignore the third argument. */
2802 ++input_line_pointer;
2803 expression (&ignore);
2804 if (*input_line_pointer == ',')
2806 /* Ignore the fourth argument. */
2807 ++input_line_pointer;
2808 expression (&ignore);
2809 if (*input_line_pointer == ',')
2811 /* The fifth argument is the function size. */
2812 ++input_line_pointer;
2813 ext_sym->sy_tc.size = symbol_new ("L0\001",
2814 absolute_section,
2815 (valueT) 0,
2816 &zero_address_frag);
2817 pseudo_set (ext_sym->sy_tc.size);
2822 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
2823 SF_SET_FUNCTION (ext_sym);
2824 SF_SET_PROCESS (ext_sym);
2825 coff_add_linesym (ext_sym);
2827 demand_empty_rest_of_line ();
2830 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
2831 ".bf". */
2833 static void
2834 ppc_bf (ignore)
2835 int ignore;
2837 symbolS *sym;
2839 sym = symbol_make (".bf");
2840 S_SET_SEGMENT (sym, text_section);
2841 sym->sy_frag = frag_now;
2842 S_SET_VALUE (sym, frag_now_fix ());
2843 S_SET_STORAGE_CLASS (sym, C_FCN);
2845 coff_line_base = get_absolute_expression ();
2847 S_SET_NUMBER_AUXILIARY (sym, 1);
2848 SA_SET_SYM_LNNO (sym, coff_line_base);
2850 sym->sy_tc.output = 1;
2852 ppc_frob_label (sym);
2854 demand_empty_rest_of_line ();
2857 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
2858 ".ef", except that the line number is absolute, not relative to the
2859 most recent ".bf" symbol. */
2861 static void
2862 ppc_ef (ignore)
2863 int ignore;
2865 symbolS *sym;
2867 sym = symbol_make (".ef");
2868 S_SET_SEGMENT (sym, text_section);
2869 sym->sy_frag = frag_now;
2870 S_SET_VALUE (sym, frag_now_fix ());
2871 S_SET_STORAGE_CLASS (sym, C_FCN);
2872 S_SET_NUMBER_AUXILIARY (sym, 1);
2873 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
2874 sym->sy_tc.output = 1;
2876 ppc_frob_label (sym);
2878 demand_empty_rest_of_line ();
2881 /* The .bi and .ei pseudo-ops. These take a string argument and
2882 generates a C_BINCL or C_EINCL symbol, which goes at the start of
2883 the symbol list. */
2885 static void
2886 ppc_biei (ei)
2887 int ei;
2889 static symbolS *last_biei;
2891 char *name;
2892 int len;
2893 symbolS *sym;
2894 symbolS *look;
2896 name = demand_copy_C_string (&len);
2898 /* The value of these symbols is actually file offset. Here we set
2899 the value to the index into the line number entries. In
2900 ppc_frob_symbols we set the fix_line field, which will cause BFD
2901 to do the right thing. */
2903 sym = symbol_make (name);
2904 /* obj-coff.c currently only handles line numbers correctly in the
2905 .text section. */
2906 S_SET_SEGMENT (sym, text_section);
2907 S_SET_VALUE (sym, coff_n_line_nos);
2908 sym->bsym->flags |= BSF_DEBUGGING;
2910 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
2911 sym->sy_tc.output = 1;
2913 for (look = last_biei ? last_biei : symbol_rootP;
2914 (look != (symbolS *) NULL
2915 && (S_GET_STORAGE_CLASS (look) == C_FILE
2916 || S_GET_STORAGE_CLASS (look) == C_BINCL
2917 || S_GET_STORAGE_CLASS (look) == C_EINCL));
2918 look = symbol_next (look))
2920 if (look != (symbolS *) NULL)
2922 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
2923 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
2924 last_biei = sym;
2927 demand_empty_rest_of_line ();
2930 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
2931 There is one argument, which is a csect symbol. The value of the
2932 .bs symbol is the index of this csect symbol. */
2934 static void
2935 ppc_bs (ignore)
2936 int ignore;
2938 char *name;
2939 char endc;
2940 symbolS *csect;
2941 symbolS *sym;
2943 if (ppc_current_block != NULL)
2944 as_bad (_("nested .bs blocks"));
2946 name = input_line_pointer;
2947 endc = get_symbol_end ();
2949 csect = symbol_find_or_make (name);
2951 *input_line_pointer = endc;
2953 sym = symbol_make (".bs");
2954 S_SET_SEGMENT (sym, now_seg);
2955 S_SET_STORAGE_CLASS (sym, C_BSTAT);
2956 sym->bsym->flags |= BSF_DEBUGGING;
2957 sym->sy_tc.output = 1;
2959 sym->sy_tc.within = csect;
2961 ppc_frob_label (sym);
2963 ppc_current_block = sym;
2965 demand_empty_rest_of_line ();
2968 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
2970 static void
2971 ppc_es (ignore)
2972 int ignore;
2974 symbolS *sym;
2976 if (ppc_current_block == NULL)
2977 as_bad (_(".es without preceding .bs"));
2979 sym = symbol_make (".es");
2980 S_SET_SEGMENT (sym, now_seg);
2981 S_SET_STORAGE_CLASS (sym, C_ESTAT);
2982 sym->bsym->flags |= BSF_DEBUGGING;
2983 sym->sy_tc.output = 1;
2985 ppc_frob_label (sym);
2987 ppc_current_block = NULL;
2989 demand_empty_rest_of_line ();
2992 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
2993 line number. */
2995 static void
2996 ppc_bb (ignore)
2997 int ignore;
2999 symbolS *sym;
3001 sym = symbol_make (".bb");
3002 S_SET_SEGMENT (sym, text_section);
3003 sym->sy_frag = frag_now;
3004 S_SET_VALUE (sym, frag_now_fix ());
3005 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3007 S_SET_NUMBER_AUXILIARY (sym, 1);
3008 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3010 sym->sy_tc.output = 1;
3012 SF_SET_PROCESS (sym);
3014 ppc_frob_label (sym);
3016 demand_empty_rest_of_line ();
3019 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3020 line number. */
3022 static void
3023 ppc_eb (ignore)
3024 int ignore;
3026 symbolS *sym;
3028 sym = symbol_make (".eb");
3029 S_SET_SEGMENT (sym, text_section);
3030 sym->sy_frag = frag_now;
3031 S_SET_VALUE (sym, frag_now_fix ());
3032 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3033 S_SET_NUMBER_AUXILIARY (sym, 1);
3034 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3035 sym->sy_tc.output = 1;
3037 SF_SET_PROCESS (sym);
3039 ppc_frob_label (sym);
3041 demand_empty_rest_of_line ();
3044 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3045 specified name. */
3047 static void
3048 ppc_bc (ignore)
3049 int ignore;
3051 char *name;
3052 int len;
3053 symbolS *sym;
3055 name = demand_copy_C_string (&len);
3056 sym = symbol_make (name);
3057 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3058 sym->bsym->flags |= BSF_DEBUGGING;
3059 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3060 S_SET_VALUE (sym, 0);
3061 sym->sy_tc.output = 1;
3063 ppc_frob_label (sym);
3065 demand_empty_rest_of_line ();
3068 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3070 static void
3071 ppc_ec (ignore)
3072 int ignore;
3074 symbolS *sym;
3076 sym = symbol_make (".ec");
3077 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3078 sym->bsym->flags |= BSF_DEBUGGING;
3079 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3080 S_SET_VALUE (sym, 0);
3081 sym->sy_tc.output = 1;
3083 ppc_frob_label (sym);
3085 demand_empty_rest_of_line ();
3088 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3090 static void
3091 ppc_toc (ignore)
3092 int ignore;
3094 if (ppc_toc_csect != (symbolS *) NULL)
3095 subseg_set (data_section, ppc_toc_csect->sy_tc.subseg);
3096 else
3098 subsegT subseg;
3099 symbolS *sym;
3100 symbolS *list;
3102 subseg = ppc_data_subsegment;
3103 ++ppc_data_subsegment;
3105 subseg_new (segment_name (data_section), subseg);
3106 ppc_toc_frag = frag_now;
3108 sym = symbol_find_or_make ("TOC[TC0]");
3109 sym->sy_frag = frag_now;
3110 S_SET_SEGMENT (sym, data_section);
3111 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3112 sym->sy_tc.subseg = subseg;
3113 sym->sy_tc.output = 1;
3114 sym->sy_tc.within = sym;
3116 ppc_toc_csect = sym;
3118 for (list = ppc_data_csects;
3119 list->sy_tc.next != (symbolS *) NULL;
3120 list = list->sy_tc.next)
3122 list->sy_tc.next = sym;
3124 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3125 symbol_append (sym, list->sy_tc.within, &symbol_rootP, &symbol_lastP);
3128 ppc_current_csect = ppc_toc_csect;
3130 demand_empty_rest_of_line ();
3133 /* The AIX assembler automatically aligns the operands of a .long or
3134 .short pseudo-op, and we want to be compatible. */
3136 static void
3137 ppc_xcoff_cons (log_size)
3138 int log_size;
3140 frag_align (log_size, 0, 0);
3141 record_alignment (now_seg, log_size);
3142 cons (1 << log_size);
3145 static void
3146 ppc_vbyte (dummy)
3147 int dummy;
3149 expressionS exp;
3150 int byte_count;
3152 (void) expression (&exp);
3154 if (exp.X_op != O_constant)
3156 as_bad (_("non-constant byte count"));
3157 return;
3160 byte_count = exp.X_add_number;
3162 if (*input_line_pointer != ',')
3164 as_bad (_("missing value"));
3165 return;
3168 ++input_line_pointer;
3169 cons (byte_count);
3172 #endif /* OBJ_XCOFF */
3174 /* The .tc pseudo-op. This is used when generating either XCOFF or
3175 ELF. This takes two or more arguments.
3177 When generating XCOFF output, the first argument is the name to
3178 give to this location in the toc; this will be a symbol with class
3179 TC. The rest of the arguments are 4 byte values to actually put at
3180 this location in the TOC; often there is just one more argument, a
3181 relocateable symbol reference.
3183 When not generating XCOFF output, the arguments are the same, but
3184 the first argument is simply ignored. */
3186 static void
3187 ppc_tc (ignore)
3188 int ignore;
3190 #ifdef OBJ_XCOFF
3192 /* Define the TOC symbol name. */
3194 char *name;
3195 char endc;
3196 symbolS *sym;
3198 if (ppc_toc_csect == (symbolS *) NULL
3199 || ppc_toc_csect != ppc_current_csect)
3201 as_bad (_(".tc not in .toc section"));
3202 ignore_rest_of_line ();
3203 return;
3206 name = input_line_pointer;
3207 endc = get_symbol_end ();
3209 sym = symbol_find_or_make (name);
3211 *input_line_pointer = endc;
3213 if (S_IS_DEFINED (sym))
3215 symbolS *label;
3217 label = ppc_current_csect->sy_tc.within;
3218 if (label->sy_tc.class != XMC_TC0)
3220 as_bad (_(".tc with no label"));
3221 ignore_rest_of_line ();
3222 return;
3225 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3226 label->sy_frag = sym->sy_frag;
3227 S_SET_VALUE (label, S_GET_VALUE (sym));
3229 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3230 ++input_line_pointer;
3232 return;
3235 S_SET_SEGMENT (sym, now_seg);
3236 sym->sy_frag = frag_now;
3237 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3238 sym->sy_tc.class = XMC_TC;
3239 sym->sy_tc.output = 1;
3241 ppc_frob_label (sym);
3244 #else /* ! defined (OBJ_XCOFF) */
3246 /* Skip the TOC symbol name. */
3247 while (is_part_of_name (*input_line_pointer)
3248 || *input_line_pointer == '['
3249 || *input_line_pointer == ']'
3250 || *input_line_pointer == '{'
3251 || *input_line_pointer == '}')
3252 ++input_line_pointer;
3254 /* Align to a four byte boundary. */
3255 frag_align (2, 0, 0);
3256 record_alignment (now_seg, 2);
3258 #endif /* ! defined (OBJ_XCOFF) */
3260 if (*input_line_pointer != ',')
3261 demand_empty_rest_of_line ();
3262 else
3264 ++input_line_pointer;
3265 cons (4);
3269 #ifdef TE_PE
3271 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format */
3273 /* Set the current section. */
3274 static void
3275 ppc_set_current_section (new)
3276 segT new;
3278 ppc_previous_section = ppc_current_section;
3279 ppc_current_section = new;
3282 /* pseudo-op: .previous
3283 behaviour: toggles the current section with the previous section.
3284 errors: None
3285 warnings: "No previous section"
3287 static void
3288 ppc_previous(ignore)
3289 int ignore;
3291 symbolS *tmp;
3293 if (ppc_previous_section == NULL)
3295 as_warn(_("No previous section to return to. Directive ignored."));
3296 return;
3299 subseg_set(ppc_previous_section, 0);
3301 ppc_set_current_section(ppc_previous_section);
3304 /* pseudo-op: .pdata
3305 behaviour: predefined read only data section
3306 double word aligned
3307 errors: None
3308 warnings: None
3309 initial: .section .pdata "adr3"
3310 a - don't know -- maybe a misprint
3311 d - initialized data
3312 r - readable
3313 3 - double word aligned (that would be 4 byte boundary)
3315 commentary:
3316 Tag index tables (also known as the function table) for exception
3317 handling, debugging, etc.
3320 static void
3321 ppc_pdata(ignore)
3322 int ignore;
3324 if (pdata_section == 0)
3326 pdata_section = subseg_new (".pdata", 0);
3328 bfd_set_section_flags (stdoutput, pdata_section,
3329 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3330 | SEC_READONLY | SEC_DATA ));
3332 bfd_set_section_alignment (stdoutput, pdata_section, 2);
3334 else
3336 pdata_section = subseg_new(".pdata", 0);
3338 ppc_set_current_section(pdata_section);
3341 /* pseudo-op: .ydata
3342 behaviour: predefined read only data section
3343 double word aligned
3344 errors: None
3345 warnings: None
3346 initial: .section .ydata "drw3"
3347 a - don't know -- maybe a misprint
3348 d - initialized data
3349 r - readable
3350 3 - double word aligned (that would be 4 byte boundary)
3351 commentary:
3352 Tag tables (also known as the scope table) for exception handling,
3353 debugging, etc.
3355 static void
3356 ppc_ydata(ignore)
3357 int ignore;
3359 if (ydata_section == 0)
3361 ydata_section = subseg_new (".ydata", 0);
3362 bfd_set_section_flags (stdoutput, ydata_section,
3363 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3364 | SEC_READONLY | SEC_DATA ));
3366 bfd_set_section_alignment (stdoutput, ydata_section, 3);
3368 else
3370 ydata_section = subseg_new (".ydata", 0);
3372 ppc_set_current_section(ydata_section);
3375 /* pseudo-op: .reldata
3376 behaviour: predefined read write data section
3377 double word aligned (4-byte)
3378 FIXME: relocation is applied to it
3379 FIXME: what's the difference between this and .data?
3380 errors: None
3381 warnings: None
3382 initial: .section .reldata "drw3"
3383 d - initialized data
3384 r - readable
3385 w - writeable
3386 3 - double word aligned (that would be 8 byte boundary)
3388 commentary:
3389 Like .data, but intended to hold data subject to relocation, such as
3390 function descriptors, etc.
3392 static void
3393 ppc_reldata(ignore)
3394 int ignore;
3396 if (reldata_section == 0)
3398 reldata_section = subseg_new (".reldata", 0);
3400 bfd_set_section_flags (stdoutput, reldata_section,
3401 ( SEC_ALLOC | SEC_LOAD | SEC_RELOC
3402 | SEC_DATA ));
3404 bfd_set_section_alignment (stdoutput, reldata_section, 2);
3406 else
3408 reldata_section = subseg_new (".reldata", 0);
3410 ppc_set_current_section(reldata_section);
3413 /* pseudo-op: .rdata
3414 behaviour: predefined read only data section
3415 double word aligned
3416 errors: None
3417 warnings: None
3418 initial: .section .rdata "dr3"
3419 d - initialized data
3420 r - readable
3421 3 - double word aligned (that would be 4 byte boundary)
3423 static void
3424 ppc_rdata(ignore)
3425 int ignore;
3427 if (rdata_section == 0)
3429 rdata_section = subseg_new (".rdata", 0);
3430 bfd_set_section_flags (stdoutput, rdata_section,
3431 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3432 | SEC_READONLY | SEC_DATA ));
3434 bfd_set_section_alignment (stdoutput, rdata_section, 2);
3436 else
3438 rdata_section = subseg_new (".rdata", 0);
3440 ppc_set_current_section(rdata_section);
3443 /* pseudo-op: .ualong
3444 behaviour: much like .int, with the exception that no alignment is
3445 performed.
3446 FIXME: test the alignment statement
3447 errors: None
3448 warnings: None
3450 static void
3451 ppc_ualong(ignore)
3452 int ignore;
3454 /* try for long */
3455 cons ( 4 );
3458 /* pseudo-op: .znop <symbol name>
3459 behaviour: Issue a nop instruction
3460 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
3461 the supplied symbol name.
3462 errors: None
3463 warnings: Missing symbol name
3465 static void
3466 ppc_znop(ignore)
3467 int ignore;
3469 unsigned long insn;
3470 const struct powerpc_opcode *opcode;
3471 expressionS ex;
3472 char *f;
3474 symbolS *sym;
3476 /* Strip out the symbol name */
3477 char *symbol_name;
3478 char c;
3479 char *name;
3480 unsigned int exp;
3481 flagword flags;
3482 asection *sec;
3484 symbol_name = input_line_pointer;
3485 c = get_symbol_end ();
3487 name = xmalloc (input_line_pointer - symbol_name + 1);
3488 strcpy (name, symbol_name);
3490 sym = symbol_find_or_make (name);
3492 *input_line_pointer = c;
3494 SKIP_WHITESPACE ();
3496 /* Look up the opcode in the hash table. */
3497 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
3499 /* stick in the nop */
3500 insn = opcode->opcode;
3502 /* Write out the instruction. */
3503 f = frag_more (4);
3504 md_number_to_chars (f, insn, 4);
3505 fix_new (frag_now,
3506 f - frag_now->fr_literal,
3508 sym,
3511 BFD_RELOC_16_GOT_PCREL);
3515 /* pseudo-op:
3516 behaviour:
3517 errors:
3518 warnings:
3520 static void
3521 ppc_pe_comm(lcomm)
3522 int lcomm;
3524 register char *name;
3525 register char c;
3526 register char *p;
3527 offsetT temp;
3528 register symbolS *symbolP;
3529 offsetT align;
3531 name = input_line_pointer;
3532 c = get_symbol_end ();
3534 /* just after name is now '\0' */
3535 p = input_line_pointer;
3536 *p = c;
3537 SKIP_WHITESPACE ();
3538 if (*input_line_pointer != ',')
3540 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
3541 ignore_rest_of_line ();
3542 return;
3545 input_line_pointer++; /* skip ',' */
3546 if ((temp = get_absolute_expression ()) < 0)
3548 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
3549 ignore_rest_of_line ();
3550 return;
3553 if (! lcomm)
3555 /* The third argument to .comm is the alignment. */
3556 if (*input_line_pointer != ',')
3557 align = 3;
3558 else
3560 ++input_line_pointer;
3561 align = get_absolute_expression ();
3562 if (align <= 0)
3564 as_warn (_("ignoring bad alignment"));
3565 align = 3;
3570 *p = 0;
3571 symbolP = symbol_find_or_make (name);
3573 *p = c;
3574 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
3576 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
3577 S_GET_NAME (symbolP));
3578 ignore_rest_of_line ();
3579 return;
3582 if (S_GET_VALUE (symbolP))
3584 if (S_GET_VALUE (symbolP) != (valueT) temp)
3585 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
3586 S_GET_NAME (symbolP),
3587 (long) S_GET_VALUE (symbolP),
3588 (long) temp);
3590 else
3592 S_SET_VALUE (symbolP, (valueT) temp);
3593 S_SET_EXTERNAL (symbolP);
3596 demand_empty_rest_of_line ();
3600 * implement the .section pseudo op:
3601 * .section name {, "flags"}
3602 * ^ ^
3603 * | +--- optional flags: 'b' for bss
3604 * | 'i' for info
3605 * +-- section name 'l' for lib
3606 * 'n' for noload
3607 * 'o' for over
3608 * 'w' for data
3609 * 'd' (apparently m88k for data)
3610 * 'x' for text
3611 * But if the argument is not a quoted string, treat it as a
3612 * subsegment number.
3614 * FIXME: this is a copy of the section processing from obj-coff.c, with
3615 * additions/changes for the moto-pas assembler support. There are three
3616 * categories:
3618 * FIXME: I just noticed this. This doesn't work at all really. It it
3619 * setting bits that bfd probably neither understands or uses. The
3620 * correct approach (?) will have to incorporate extra fields attached
3621 * to the section to hold the system specific stuff. (krk)
3623 * Section Contents:
3624 * 'a' - unknown - referred to in documentation, but no definition supplied
3625 * 'c' - section has code
3626 * 'd' - section has initialized data
3627 * 'u' - section has uninitialized data
3628 * 'i' - section contains directives (info)
3629 * 'n' - section can be discarded
3630 * 'R' - remove section at link time
3632 * Section Protection:
3633 * 'r' - section is readable
3634 * 'w' - section is writeable
3635 * 'x' - section is executable
3636 * 's' - section is sharable
3638 * Section Alignment:
3639 * '0' - align to byte boundary
3640 * '1' - align to halfword undary
3641 * '2' - align to word boundary
3642 * '3' - align to doubleword boundary
3643 * '4' - align to quadword boundary
3644 * '5' - align to 32 byte boundary
3645 * '6' - align to 64 byte boundary
3649 void
3650 ppc_pe_section (ignore)
3651 int ignore;
3653 /* Strip out the section name */
3654 char *section_name;
3655 char c;
3656 char *name;
3657 unsigned int exp;
3658 flagword flags;
3659 segT sec;
3660 int align;
3662 section_name = input_line_pointer;
3663 c = get_symbol_end ();
3665 name = xmalloc (input_line_pointer - section_name + 1);
3666 strcpy (name, section_name);
3668 *input_line_pointer = c;
3670 SKIP_WHITESPACE ();
3672 exp = 0;
3673 flags = SEC_NO_FLAGS;
3675 if (strcmp (name, ".idata$2") == 0)
3677 align = 0;
3679 else if (strcmp (name, ".idata$3") == 0)
3681 align = 0;
3683 else if (strcmp (name, ".idata$4") == 0)
3685 align = 2;
3687 else if (strcmp (name, ".idata$5") == 0)
3689 align = 2;
3691 else if (strcmp (name, ".idata$6") == 0)
3693 align = 1;
3695 else
3696 align = 4; /* default alignment to 16 byte boundary */
3698 if (*input_line_pointer == ',')
3700 ++input_line_pointer;
3701 SKIP_WHITESPACE ();
3702 if (*input_line_pointer != '"')
3703 exp = get_absolute_expression ();
3704 else
3706 ++input_line_pointer;
3707 while (*input_line_pointer != '"'
3708 && ! is_end_of_line[(unsigned char) *input_line_pointer])
3710 switch (*input_line_pointer)
3712 /* Section Contents */
3713 case 'a': /* unknown */
3714 as_bad (_("Unsupported section attribute -- 'a'"));
3715 break;
3716 case 'c': /* code section */
3717 flags |= SEC_CODE;
3718 break;
3719 case 'd': /* section has initialized data */
3720 flags |= SEC_DATA;
3721 break;
3722 case 'u': /* section has uninitialized data */
3723 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
3724 in winnt.h */
3725 flags |= SEC_ROM;
3726 break;
3727 case 'i': /* section contains directives (info) */
3728 /* FIXME: This is IMAGE_SCN_LNK_INFO
3729 in winnt.h */
3730 flags |= SEC_HAS_CONTENTS;
3731 break;
3732 case 'n': /* section can be discarded */
3733 flags &=~ SEC_LOAD;
3734 break;
3735 case 'R': /* Remove section at link time */
3736 flags |= SEC_NEVER_LOAD;
3737 break;
3739 /* Section Protection */
3740 case 'r': /* section is readable */
3741 flags |= IMAGE_SCN_MEM_READ;
3742 break;
3743 case 'w': /* section is writeable */
3744 flags |= IMAGE_SCN_MEM_WRITE;
3745 break;
3746 case 'x': /* section is executable */
3747 flags |= IMAGE_SCN_MEM_EXECUTE;
3748 break;
3749 case 's': /* section is sharable */
3750 flags |= IMAGE_SCN_MEM_SHARED;
3751 break;
3753 /* Section Alignment */
3754 case '0': /* align to byte boundary */
3755 flags |= IMAGE_SCN_ALIGN_1BYTES;
3756 align = 0;
3757 break;
3758 case '1': /* align to halfword boundary */
3759 flags |= IMAGE_SCN_ALIGN_2BYTES;
3760 align = 1;
3761 break;
3762 case '2': /* align to word boundary */
3763 flags |= IMAGE_SCN_ALIGN_4BYTES;
3764 align = 2;
3765 break;
3766 case '3': /* align to doubleword boundary */
3767 flags |= IMAGE_SCN_ALIGN_8BYTES;
3768 align = 3;
3769 break;
3770 case '4': /* align to quadword boundary */
3771 flags |= IMAGE_SCN_ALIGN_16BYTES;
3772 align = 4;
3773 break;
3774 case '5': /* align to 32 byte boundary */
3775 flags |= IMAGE_SCN_ALIGN_32BYTES;
3776 align = 5;
3777 break;
3778 case '6': /* align to 64 byte boundary */
3779 flags |= IMAGE_SCN_ALIGN_64BYTES;
3780 align = 6;
3781 break;
3783 default:
3784 as_bad(_("unknown section attribute '%c'"),
3785 *input_line_pointer);
3786 break;
3788 ++input_line_pointer;
3790 if (*input_line_pointer == '"')
3791 ++input_line_pointer;
3795 sec = subseg_new (name, (subsegT) exp);
3797 ppc_set_current_section(sec);
3799 if (flags != SEC_NO_FLAGS)
3801 if (! bfd_set_section_flags (stdoutput, sec, flags))
3802 as_bad (_("error setting flags for \"%s\": %s"),
3803 bfd_section_name (stdoutput, sec),
3804 bfd_errmsg (bfd_get_error ()));
3807 bfd_set_section_alignment(stdoutput, sec, align);
3811 static void
3812 ppc_pe_function (ignore)
3813 int ignore;
3815 char *name;
3816 char endc;
3817 symbolS *ext_sym;
3819 name = input_line_pointer;
3820 endc = get_symbol_end ();
3822 ext_sym = symbol_find_or_make (name);
3824 *input_line_pointer = endc;
3826 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3827 SF_SET_FUNCTION (ext_sym);
3828 SF_SET_PROCESS (ext_sym);
3829 coff_add_linesym (ext_sym);
3831 demand_empty_rest_of_line ();
3834 static void
3835 ppc_pe_tocd (ignore)
3836 int ignore;
3838 if (tocdata_section == 0)
3840 tocdata_section = subseg_new (".tocd", 0);
3841 /* FIXME: section flags won't work */
3842 bfd_set_section_flags (stdoutput, tocdata_section,
3843 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
3844 | SEC_READONLY | SEC_DATA ));
3846 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
3848 else
3850 rdata_section = subseg_new (".tocd", 0);
3853 ppc_set_current_section(tocdata_section);
3855 demand_empty_rest_of_line ();
3858 /* Don't adjust TOC relocs to use the section symbol. */
3861 ppc_pe_fix_adjustable (fix)
3862 fixS *fix;
3864 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
3867 #endif
3869 #ifdef OBJ_XCOFF
3871 /* XCOFF specific symbol and file handling. */
3873 /* Canonicalize the symbol name. We use the to force the suffix, if
3874 any, to use square brackets, and to be in upper case. */
3876 char *
3877 ppc_canonicalize_symbol_name (name)
3878 char *name;
3880 char *s;
3882 if (ppc_stab_symbol)
3883 return name;
3885 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
3887 if (*s != '\0')
3889 char brac;
3891 if (*s == '[')
3892 brac = ']';
3893 else
3895 *s = '[';
3896 brac = '}';
3899 for (s++; *s != '\0' && *s != brac; s++)
3900 if (islower (*s))
3901 *s = toupper (*s);
3903 if (*s == '\0' || s[1] != '\0')
3904 as_bad (_("bad symbol suffix"));
3906 *s = ']';
3909 return name;
3912 /* Set the class of a symbol based on the suffix, if any. This is
3913 called whenever a new symbol is created. */
3915 void
3916 ppc_symbol_new_hook (sym)
3917 symbolS *sym;
3919 const char *s;
3921 sym->sy_tc.next = NULL;
3922 sym->sy_tc.output = 0;
3923 sym->sy_tc.class = -1;
3924 sym->sy_tc.real_name = NULL;
3925 sym->sy_tc.subseg = 0;
3926 sym->sy_tc.align = 0;
3927 sym->sy_tc.size = NULL;
3928 sym->sy_tc.within = NULL;
3930 if (ppc_stab_symbol)
3931 return;
3933 s = strchr (S_GET_NAME (sym), '[');
3934 if (s == (const char *) NULL)
3936 /* There is no suffix. */
3937 return;
3940 ++s;
3942 switch (s[0])
3944 case 'B':
3945 if (strcmp (s, "BS]") == 0)
3946 sym->sy_tc.class = XMC_BS;
3947 break;
3948 case 'D':
3949 if (strcmp (s, "DB]") == 0)
3950 sym->sy_tc.class = XMC_DB;
3951 else if (strcmp (s, "DS]") == 0)
3952 sym->sy_tc.class = XMC_DS;
3953 break;
3954 case 'G':
3955 if (strcmp (s, "GL]") == 0)
3956 sym->sy_tc.class = XMC_GL;
3957 break;
3958 case 'P':
3959 if (strcmp (s, "PR]") == 0)
3960 sym->sy_tc.class = XMC_PR;
3961 break;
3962 case 'R':
3963 if (strcmp (s, "RO]") == 0)
3964 sym->sy_tc.class = XMC_RO;
3965 else if (strcmp (s, "RW]") == 0)
3966 sym->sy_tc.class = XMC_RW;
3967 break;
3968 case 'S':
3969 if (strcmp (s, "SV]") == 0)
3970 sym->sy_tc.class = XMC_SV;
3971 break;
3972 case 'T':
3973 if (strcmp (s, "TC]") == 0)
3974 sym->sy_tc.class = XMC_TC;
3975 else if (strcmp (s, "TI]") == 0)
3976 sym->sy_tc.class = XMC_TI;
3977 else if (strcmp (s, "TB]") == 0)
3978 sym->sy_tc.class = XMC_TB;
3979 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
3980 sym->sy_tc.class = XMC_TC0;
3981 break;
3982 case 'U':
3983 if (strcmp (s, "UA]") == 0)
3984 sym->sy_tc.class = XMC_UA;
3985 else if (strcmp (s, "UC]") == 0)
3986 sym->sy_tc.class = XMC_UC;
3987 break;
3988 case 'X':
3989 if (strcmp (s, "XO]") == 0)
3990 sym->sy_tc.class = XMC_XO;
3991 break;
3994 if (sym->sy_tc.class == -1)
3995 as_bad (_("Unrecognized symbol suffix"));
3998 /* Set the class of a label based on where it is defined. This
3999 handles symbols without suffixes. Also, move the symbol so that it
4000 follows the csect symbol. */
4002 void
4003 ppc_frob_label (sym)
4004 symbolS *sym;
4006 if (ppc_current_csect != (symbolS *) NULL)
4008 if (sym->sy_tc.class == -1)
4009 sym->sy_tc.class = ppc_current_csect->sy_tc.class;
4011 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4012 symbol_append (sym, ppc_current_csect->sy_tc.within, &symbol_rootP,
4013 &symbol_lastP);
4014 ppc_current_csect->sy_tc.within = sym;
4018 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4019 seen. It tells ppc_adjust_symtab whether it needs to look through
4020 the symbols. */
4022 static boolean ppc_saw_abs;
4024 /* Change the name of a symbol just before writing it out. Set the
4025 real name if the .rename pseudo-op was used. Otherwise, remove any
4026 class suffix. Return 1 if the symbol should not be included in the
4027 symbol table. */
4030 ppc_frob_symbol (sym)
4031 symbolS *sym;
4033 static symbolS *ppc_last_function;
4034 static symbolS *set_end;
4036 /* Discard symbols that should not be included in the output symbol
4037 table. */
4038 if (! sym->sy_used_in_reloc
4039 && ((sym->bsym->flags & BSF_SECTION_SYM) != 0
4040 || (! S_IS_EXTERNAL (sym)
4041 && ! sym->sy_tc.output
4042 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4043 return 1;
4045 if (sym->sy_tc.real_name != (char *) NULL)
4046 S_SET_NAME (sym, sym->sy_tc.real_name);
4047 else
4049 const char *name;
4050 const char *s;
4052 name = S_GET_NAME (sym);
4053 s = strchr (name, '[');
4054 if (s != (char *) NULL)
4056 unsigned int len;
4057 char *snew;
4059 len = s - name;
4060 snew = xmalloc (len + 1);
4061 memcpy (snew, name, len);
4062 snew[len] = '\0';
4064 S_SET_NAME (sym, snew);
4068 if (set_end != (symbolS *) NULL)
4070 SA_SET_SYM_ENDNDX (set_end, sym);
4071 set_end = NULL;
4074 if (SF_GET_FUNCTION (sym))
4076 if (ppc_last_function != (symbolS *) NULL)
4077 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4078 ppc_last_function = sym;
4079 if (sym->sy_tc.size != (symbolS *) NULL)
4081 resolve_symbol_value (sym->sy_tc.size, 1);
4082 SA_SET_SYM_FSIZE (sym, (long) S_GET_VALUE (sym->sy_tc.size));
4085 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4086 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4088 if (ppc_last_function == (symbolS *) NULL)
4089 as_bad (_(".ef with no preceding .function"));
4090 else
4092 set_end = ppc_last_function;
4093 ppc_last_function = NULL;
4095 /* We don't have a C_EFCN symbol, but we need to force the
4096 COFF backend to believe that it has seen one. */
4097 coff_last_function = NULL;
4101 if (! S_IS_EXTERNAL (sym)
4102 && (sym->bsym->flags & BSF_SECTION_SYM) == 0
4103 && S_GET_STORAGE_CLASS (sym) != C_FILE
4104 && S_GET_STORAGE_CLASS (sym) != C_FCN
4105 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4106 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4107 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4108 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4109 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4110 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4111 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4113 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4114 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4116 int i;
4117 union internal_auxent *a;
4119 /* Create a csect aux. */
4120 i = S_GET_NUMBER_AUXILIARY (sym);
4121 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4122 a = &coffsymbol (sym->bsym)->native[i + 1].u.auxent;
4123 if (sym->sy_tc.class == XMC_TC0)
4125 /* This is the TOC table. */
4126 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4127 a->x_csect.x_scnlen.l = 0;
4128 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4130 else if (sym->sy_tc.subseg != 0)
4132 /* This is a csect symbol. x_scnlen is the size of the
4133 csect. */
4134 if (sym->sy_tc.next == (symbolS *) NULL)
4135 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4136 S_GET_SEGMENT (sym))
4137 - S_GET_VALUE (sym));
4138 else
4140 resolve_symbol_value (sym->sy_tc.next, 1);
4141 a->x_csect.x_scnlen.l = (S_GET_VALUE (sym->sy_tc.next)
4142 - S_GET_VALUE (sym));
4144 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_SD;
4146 else if (S_GET_SEGMENT (sym) == bss_section)
4148 /* This is a common symbol. */
4149 a->x_csect.x_scnlen.l = sym->sy_frag->fr_offset;
4150 a->x_csect.x_smtyp = (sym->sy_tc.align << 3) | XTY_CM;
4151 if (S_IS_EXTERNAL (sym))
4152 sym->sy_tc.class = XMC_RW;
4153 else
4154 sym->sy_tc.class = XMC_BS;
4156 else if (S_GET_SEGMENT (sym) == absolute_section)
4158 /* This is an absolute symbol. The csect will be created by
4159 ppc_adjust_symtab. */
4160 ppc_saw_abs = true;
4161 a->x_csect.x_smtyp = XTY_LD;
4162 if (sym->sy_tc.class == -1)
4163 sym->sy_tc.class = XMC_XO;
4165 else if (! S_IS_DEFINED (sym))
4167 /* This is an external symbol. */
4168 a->x_csect.x_scnlen.l = 0;
4169 a->x_csect.x_smtyp = XTY_ER;
4171 else if (sym->sy_tc.class == XMC_TC)
4173 symbolS *next;
4175 /* This is a TOC definition. x_scnlen is the size of the
4176 TOC entry. */
4177 next = symbol_next (sym);
4178 while (next->sy_tc.class == XMC_TC0)
4179 next = symbol_next (next);
4180 if (next == (symbolS *) NULL
4181 || next->sy_tc.class != XMC_TC)
4183 if (ppc_after_toc_frag == (fragS *) NULL)
4184 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4185 data_section)
4186 - S_GET_VALUE (sym));
4187 else
4188 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
4189 - S_GET_VALUE (sym));
4191 else
4193 resolve_symbol_value (next, 1);
4194 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
4195 - S_GET_VALUE (sym));
4197 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4199 else
4201 symbolS *csect;
4203 /* This is a normal symbol definition. x_scnlen is the
4204 symbol index of the containing csect. */
4205 if (S_GET_SEGMENT (sym) == text_section)
4206 csect = ppc_text_csects;
4207 else if (S_GET_SEGMENT (sym) == data_section)
4208 csect = ppc_data_csects;
4209 else
4210 abort ();
4212 /* Skip the initial dummy symbol. */
4213 csect = csect->sy_tc.next;
4215 if (csect == (symbolS *) NULL)
4217 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
4218 a->x_csect.x_scnlen.l = 0;
4220 else
4222 while (csect->sy_tc.next != (symbolS *) NULL)
4224 resolve_symbol_value (csect->sy_tc.next, 1);
4225 if (S_GET_VALUE (csect->sy_tc.next) > S_GET_VALUE (sym))
4226 break;
4227 csect = csect->sy_tc.next;
4230 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4231 coffsymbol (sym->bsym)->native[i + 1].fix_scnlen = 1;
4233 a->x_csect.x_smtyp = XTY_LD;
4236 a->x_csect.x_parmhash = 0;
4237 a->x_csect.x_snhash = 0;
4238 if (sym->sy_tc.class == -1)
4239 a->x_csect.x_smclas = XMC_PR;
4240 else
4241 a->x_csect.x_smclas = sym->sy_tc.class;
4242 a->x_csect.x_stab = 0;
4243 a->x_csect.x_snstab = 0;
4245 /* Don't let the COFF backend resort these symbols. */
4246 sym->bsym->flags |= BSF_NOT_AT_END;
4248 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
4250 /* We want the value to be the symbol index of the referenced
4251 csect symbol. BFD will do that for us if we set the right
4252 flags. */
4253 S_SET_VALUE (sym,
4254 (valueT) coffsymbol (sym->sy_tc.within->bsym)->native);
4255 coffsymbol (sym->bsym)->native->fix_value = 1;
4257 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
4259 symbolS *block;
4260 symbolS *csect;
4262 /* The value is the offset from the enclosing csect. */
4263 block = sym->sy_tc.within;
4264 csect = block->sy_tc.within;
4265 resolve_symbol_value (csect, 1);
4266 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
4268 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
4269 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
4271 /* We want the value to be a file offset into the line numbers.
4272 BFD will do that for us if we set the right flags. We have
4273 already set the value correctly. */
4274 coffsymbol (sym->bsym)->native->fix_line = 1;
4277 return 0;
4280 /* Adjust the symbol table. This creates csect symbols for all
4281 absolute symbols. */
4283 void
4284 ppc_adjust_symtab ()
4286 symbolS *sym;
4288 if (! ppc_saw_abs)
4289 return;
4291 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
4293 symbolS *csect;
4294 int i;
4295 union internal_auxent *a;
4297 if (S_GET_SEGMENT (sym) != absolute_section)
4298 continue;
4300 csect = symbol_create (".abs[XO]", absolute_section,
4301 S_GET_VALUE (sym), &zero_address_frag);
4302 csect->bsym->value = S_GET_VALUE (sym);
4303 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
4304 i = S_GET_NUMBER_AUXILIARY (csect);
4305 S_SET_NUMBER_AUXILIARY (csect, i + 1);
4306 a = &coffsymbol (csect->bsym)->native[i + 1].u.auxent;
4307 a->x_csect.x_scnlen.l = 0;
4308 a->x_csect.x_smtyp = XTY_SD;
4309 a->x_csect.x_parmhash = 0;
4310 a->x_csect.x_snhash = 0;
4311 a->x_csect.x_smclas = XMC_XO;
4312 a->x_csect.x_stab = 0;
4313 a->x_csect.x_snstab = 0;
4315 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
4317 i = S_GET_NUMBER_AUXILIARY (sym);
4318 a = &coffsymbol (sym->bsym)->native[i].u.auxent;
4319 a->x_csect.x_scnlen.p = coffsymbol (csect->bsym)->native;
4320 coffsymbol (sym->bsym)->native[i].fix_scnlen = 1;
4323 ppc_saw_abs = false;
4326 /* Set the VMA for a section. This is called on all the sections in
4327 turn. */
4329 void
4330 ppc_frob_section (sec)
4331 asection *sec;
4333 static bfd_size_type vma = 0;
4335 bfd_set_section_vma (stdoutput, sec, vma);
4336 vma += bfd_section_size (stdoutput, sec);
4339 #endif /* OBJ_XCOFF */
4341 /* Turn a string in input_line_pointer into a floating point constant
4342 of type type, and store the appropriate bytes in *litp. The number
4343 of LITTLENUMS emitted is stored in *sizep . An error message is
4344 returned, or NULL on OK. */
4346 char *
4347 md_atof (type, litp, sizep)
4348 int type;
4349 char *litp;
4350 int *sizep;
4352 int prec;
4353 LITTLENUM_TYPE words[4];
4354 char *t;
4355 int i;
4357 switch (type)
4359 case 'f':
4360 prec = 2;
4361 break;
4363 case 'd':
4364 prec = 4;
4365 break;
4367 default:
4368 *sizep = 0;
4369 return _("bad call to md_atof");
4372 t = atof_ieee (input_line_pointer, type, words);
4373 if (t)
4374 input_line_pointer = t;
4376 *sizep = prec * 2;
4378 if (target_big_endian)
4380 for (i = 0; i < prec; i++)
4382 md_number_to_chars (litp, (valueT) words[i], 2);
4383 litp += 2;
4386 else
4388 for (i = prec - 1; i >= 0; i--)
4390 md_number_to_chars (litp, (valueT) words[i], 2);
4391 litp += 2;
4395 return NULL;
4398 /* Write a value out to the object file, using the appropriate
4399 endianness. */
4401 void
4402 md_number_to_chars (buf, val, n)
4403 char *buf;
4404 valueT val;
4405 int n;
4407 if (target_big_endian)
4408 number_to_chars_bigendian (buf, val, n);
4409 else
4410 number_to_chars_littleendian (buf, val, n);
4413 /* Align a section (I don't know why this is machine dependent). */
4415 valueT
4416 md_section_align (seg, addr)
4417 asection *seg;
4418 valueT addr;
4420 int align = bfd_get_section_alignment (stdoutput, seg);
4422 return ((addr + (1 << align) - 1) & (-1 << align));
4425 /* We don't have any form of relaxing. */
4428 md_estimate_size_before_relax (fragp, seg)
4429 fragS *fragp;
4430 asection *seg;
4432 abort ();
4433 return 0;
4436 /* Convert a machine dependent frag. We never generate these. */
4438 void
4439 md_convert_frag (abfd, sec, fragp)
4440 bfd *abfd;
4441 asection *sec;
4442 fragS *fragp;
4444 abort ();
4447 /* We have no need to default values of symbols. */
4449 /*ARGSUSED*/
4450 symbolS *
4451 md_undefined_symbol (name)
4452 char *name;
4454 return 0;
4457 /* Functions concerning relocs. */
4459 /* The location from which a PC relative jump should be calculated,
4460 given a PC relative reloc. */
4462 long
4463 md_pcrel_from_section (fixp, sec)
4464 fixS *fixp;
4465 segT sec;
4467 return fixp->fx_frag->fr_address + fixp->fx_where;
4470 #ifdef OBJ_XCOFF
4472 /* This is called to see whether a fixup should be adjusted to use a
4473 section symbol. We take the opportunity to change a fixup against
4474 a symbol in the TOC subsegment into a reloc against the
4475 corresponding .tc symbol. */
4478 ppc_fix_adjustable (fix)
4479 fixS *fix;
4481 valueT val;
4483 resolve_symbol_value (fix->fx_addsy, 1);
4484 val = S_GET_VALUE (fix->fx_addsy);
4485 if (ppc_toc_csect != (symbolS *) NULL
4486 && fix->fx_addsy != (symbolS *) NULL
4487 && fix->fx_addsy != ppc_toc_csect
4488 && S_GET_SEGMENT (fix->fx_addsy) == data_section
4489 && val >= ppc_toc_frag->fr_address
4490 && (ppc_after_toc_frag == (fragS *) NULL
4491 || val < ppc_after_toc_frag->fr_address))
4493 symbolS *sy;
4495 for (sy = symbol_next (ppc_toc_csect);
4496 sy != (symbolS *) NULL;
4497 sy = symbol_next (sy))
4499 if (sy->sy_tc.class == XMC_TC0)
4500 continue;
4501 if (sy->sy_tc.class != XMC_TC)
4502 break;
4503 resolve_symbol_value (sy, 1);
4504 if (val == S_GET_VALUE (sy))
4506 fix->fx_addsy = sy;
4507 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
4508 return 0;
4512 as_bad_where (fix->fx_file, fix->fx_line,
4513 _("symbol in .toc does not match any .tc"));
4516 /* Possibly adjust the reloc to be against the csect. */
4517 if (fix->fx_addsy != (symbolS *) NULL
4518 && fix->fx_addsy->sy_tc.subseg == 0
4519 && fix->fx_addsy->sy_tc.class != XMC_TC0
4520 && fix->fx_addsy->sy_tc.class != XMC_TC
4521 && S_GET_SEGMENT (fix->fx_addsy) != bss_section
4522 /* Don't adjust if this is a reloc in the toc section. */
4523 && (S_GET_SEGMENT (fix->fx_addsy) != data_section
4524 || ppc_toc_csect == NULL
4525 || val < ppc_toc_frag->fr_address
4526 || (ppc_after_toc_frag != NULL
4527 && val >= ppc_after_toc_frag->fr_address)))
4529 symbolS *csect;
4531 if (S_GET_SEGMENT (fix->fx_addsy) == text_section)
4532 csect = ppc_text_csects;
4533 else if (S_GET_SEGMENT (fix->fx_addsy) == data_section)
4534 csect = ppc_data_csects;
4535 else
4536 abort ();
4538 /* Skip the initial dummy symbol. */
4539 csect = csect->sy_tc.next;
4541 if (csect != (symbolS *) NULL)
4543 while (csect->sy_tc.next != (symbolS *) NULL
4544 && (csect->sy_tc.next->sy_frag->fr_address
4545 <= fix->fx_addsy->sy_frag->fr_address))
4547 /* If the csect address equals the symbol value, then we
4548 have to look through the full symbol table to see
4549 whether this is the csect we want. Note that we will
4550 only get here if the csect has zero length. */
4551 if ((csect->sy_frag->fr_address
4552 == fix->fx_addsy->sy_frag->fr_address)
4553 && S_GET_VALUE (csect) == S_GET_VALUE (fix->fx_addsy))
4555 symbolS *scan;
4557 for (scan = csect->sy_next;
4558 scan != NULL;
4559 scan = scan->sy_next)
4561 if (scan->sy_tc.subseg != 0)
4562 break;
4563 if (scan == fix->fx_addsy)
4564 break;
4567 /* If we found the symbol before the next csect
4568 symbol, then this is the csect we want. */
4569 if (scan == fix->fx_addsy)
4570 break;
4573 csect = csect->sy_tc.next;
4576 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4577 - csect->sy_frag->fr_address);
4578 fix->fx_addsy = csect;
4582 /* Adjust a reloc against a .lcomm symbol to be against the base
4583 .lcomm. */
4584 if (fix->fx_addsy != (symbolS *) NULL
4585 && S_GET_SEGMENT (fix->fx_addsy) == bss_section
4586 && ! S_IS_EXTERNAL (fix->fx_addsy))
4588 resolve_symbol_value (fix->fx_addsy->sy_frag->fr_symbol, 1);
4589 fix->fx_offset += (S_GET_VALUE (fix->fx_addsy)
4590 - S_GET_VALUE (fix->fx_addsy->sy_frag->fr_symbol));
4591 fix->fx_addsy = fix->fx_addsy->sy_frag->fr_symbol;
4594 return 0;
4597 /* A reloc from one csect to another must be kept. The assembler
4598 will, of course, keep relocs between sections, and it will keep
4599 absolute relocs, but we need to force it to keep PC relative relocs
4600 between two csects in the same section. */
4603 ppc_force_relocation (fix)
4604 fixS *fix;
4606 /* At this point fix->fx_addsy should already have been converted to
4607 a csect symbol. If the csect does not include the fragment, then
4608 we need to force the relocation. */
4609 if (fix->fx_pcrel
4610 && fix->fx_addsy != NULL
4611 && fix->fx_addsy->sy_tc.subseg != 0
4612 && (fix->fx_addsy->sy_frag->fr_address > fix->fx_frag->fr_address
4613 || (fix->fx_addsy->sy_tc.next != NULL
4614 && (fix->fx_addsy->sy_tc.next->sy_frag->fr_address
4615 <= fix->fx_frag->fr_address))))
4616 return 1;
4618 return 0;
4621 #endif /* OBJ_XCOFF */
4623 /* See whether a symbol is in the TOC section. */
4625 static int
4626 ppc_is_toc_sym (sym)
4627 symbolS *sym;
4629 #ifdef OBJ_XCOFF
4630 return sym->sy_tc.class == XMC_TC;
4631 #else
4632 return strcmp (segment_name (S_GET_SEGMENT (sym)), ".got") == 0;
4633 #endif
4636 /* Apply a fixup to the object code. This is called for all the
4637 fixups we generated by the call to fix_new_exp, above. In the call
4638 above we used a reloc code which was the largest legal reloc code
4639 plus the operand index. Here we undo that to recover the operand
4640 index. At this point all symbol values should be fully resolved,
4641 and we attempt to completely resolve the reloc. If we can not do
4642 that, we determine the correct reloc code and put it back in the
4643 fixup. */
4646 md_apply_fix3 (fixp, valuep, seg)
4647 fixS *fixp;
4648 valueT *valuep;
4649 segT seg;
4651 valueT value;
4653 #ifdef OBJ_ELF
4654 value = *valuep;
4655 if (fixp->fx_addsy != NULL)
4657 /* `*valuep' may contain the value of the symbol on which the reloc
4658 will be based; we have to remove it. */
4659 if (symbol_used_in_reloc_p (fixp->fx_addsy)
4660 && S_GET_SEGMENT (fixp->fx_addsy) != absolute_section
4661 && S_GET_SEGMENT (fixp->fx_addsy) != undefined_section
4662 && ! bfd_is_com_section (S_GET_SEGMENT (fixp->fx_addsy)))
4663 value -= S_GET_VALUE (fixp->fx_addsy);
4665 /* FIXME: Why '+'? Better yet, what exactly is '*valuep'
4666 supposed to be? I think this is related to various similar
4667 FIXMEs in tc-i386.c and tc-sparc.c. */
4668 if (fixp->fx_pcrel)
4669 value += fixp->fx_frag->fr_address + fixp->fx_where;
4671 else
4673 fixp->fx_done = 1;
4675 #else
4676 /* FIXME FIXME FIXME: The value we are passed in *valuep includes
4677 the symbol values. Since we are using BFD_ASSEMBLER, if we are
4678 doing this relocation the code in write.c is going to call
4679 bfd_install_relocation, which is also going to use the symbol
4680 value. That means that if the reloc is fully resolved we want to
4681 use *valuep since bfd_install_relocation is not being used.
4682 However, if the reloc is not fully resolved we do not want to use
4683 *valuep, and must use fx_offset instead. However, if the reloc
4684 is PC relative, we do want to use *valuep since it includes the
4685 result of md_pcrel_from. This is confusing. */
4686 if (fixp->fx_addsy == (symbolS *) NULL)
4688 value = *valuep;
4689 fixp->fx_done = 1;
4691 else if (fixp->fx_pcrel)
4692 value = *valuep;
4693 else
4695 value = fixp->fx_offset;
4696 if (fixp->fx_subsy != (symbolS *) NULL)
4698 if (S_GET_SEGMENT (fixp->fx_subsy) == absolute_section)
4699 value -= S_GET_VALUE (fixp->fx_subsy);
4700 else
4702 /* We can't actually support subtracting a symbol. */
4703 as_bad_where (fixp->fx_file, fixp->fx_line,
4704 _("expression too complex"));
4708 #endif
4710 if ((int) fixp->fx_r_type >= (int) BFD_RELOC_UNUSED)
4712 int opindex;
4713 const struct powerpc_operand *operand;
4714 char *where;
4715 unsigned long insn;
4717 opindex = (int) fixp->fx_r_type - (int) BFD_RELOC_UNUSED;
4719 operand = &powerpc_operands[opindex];
4721 #ifdef OBJ_XCOFF
4722 /* It appears that an instruction like
4723 l 9,LC..1(30)
4724 when LC..1 is not a TOC symbol does not generate a reloc. It
4725 uses the offset of LC..1 within its csect. However, .long
4726 LC..1 will generate a reloc. I can't find any documentation
4727 on how these cases are to be distinguished, so this is a wild
4728 guess. These cases are generated by gcc -mminimal-toc. */
4729 if ((operand->flags & PPC_OPERAND_PARENS) != 0
4730 && operand->bits == 16
4731 && operand->shift == 0
4732 && operand->insert == NULL
4733 && fixp->fx_addsy != NULL
4734 && fixp->fx_addsy->sy_tc.subseg != 0
4735 && fixp->fx_addsy->sy_tc.class != XMC_TC
4736 && fixp->fx_addsy->sy_tc.class != XMC_TC0
4737 && S_GET_SEGMENT (fixp->fx_addsy) != bss_section)
4739 value = fixp->fx_offset;
4740 fixp->fx_done = 1;
4742 #endif
4744 /* Fetch the instruction, insert the fully resolved operand
4745 value, and stuff the instruction back again. */
4746 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4747 if (target_big_endian)
4748 insn = bfd_getb32 ((unsigned char *) where);
4749 else
4750 insn = bfd_getl32 ((unsigned char *) where);
4751 insn = ppc_insert_operand (insn, operand, (offsetT) value,
4752 fixp->fx_file, fixp->fx_line);
4753 if (target_big_endian)
4754 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4755 else
4756 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4758 if (fixp->fx_done)
4760 /* Nothing else to do here. */
4761 return 1;
4764 /* Determine a BFD reloc value based on the operand information.
4765 We are only prepared to turn a few of the operands into
4766 relocs.
4767 FIXME: We need to handle the DS field at the very least.
4768 FIXME: Selecting the reloc type is a bit haphazard; perhaps
4769 there should be a new field in the operand table. */
4770 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4771 && operand->bits == 26
4772 && operand->shift == 0)
4773 fixp->fx_r_type = BFD_RELOC_PPC_B26;
4774 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
4775 && operand->bits == 16
4776 && operand->shift == 0)
4777 fixp->fx_r_type = BFD_RELOC_PPC_B16;
4778 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4779 && operand->bits == 26
4780 && operand->shift == 0)
4781 fixp->fx_r_type = BFD_RELOC_PPC_BA26;
4782 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
4783 && operand->bits == 16
4784 && operand->shift == 0)
4785 fixp->fx_r_type = BFD_RELOC_PPC_BA16;
4786 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
4787 && operand->bits == 16
4788 && operand->shift == 0
4789 && operand->insert == NULL
4790 && fixp->fx_addsy != NULL
4791 && ppc_is_toc_sym (fixp->fx_addsy))
4793 fixp->fx_size = 2;
4794 if (target_big_endian)
4795 fixp->fx_where += 2;
4796 fixp->fx_r_type = BFD_RELOC_PPC_TOC16;
4798 else
4800 char *sfile;
4801 unsigned int sline;
4803 /* Use expr_symbol_where to see if this is an expression
4804 symbol. */
4805 if (expr_symbol_where (fixp->fx_addsy, &sfile, &sline))
4806 as_bad_where (fixp->fx_file, fixp->fx_line,
4807 _("unresolved expression that must be resolved"));
4808 else
4809 as_bad_where (fixp->fx_file, fixp->fx_line,
4810 _("unsupported relocation type"));
4811 fixp->fx_done = 1;
4812 return 1;
4815 else
4817 #ifdef OBJ_ELF
4818 ppc_elf_validate_fix (fixp, seg);
4819 #endif
4820 switch (fixp->fx_r_type)
4822 case BFD_RELOC_32:
4823 case BFD_RELOC_CTOR:
4824 if (fixp->fx_pcrel)
4825 fixp->fx_r_type = BFD_RELOC_32_PCREL;
4826 /* fall through */
4828 case BFD_RELOC_RVA:
4829 case BFD_RELOC_32_PCREL:
4830 case BFD_RELOC_32_BASEREL:
4831 case BFD_RELOC_PPC_EMB_NADDR32:
4832 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4833 value, 4);
4834 break;
4836 case BFD_RELOC_LO16:
4837 case BFD_RELOC_16:
4838 case BFD_RELOC_GPREL16:
4839 case BFD_RELOC_16_GOT_PCREL:
4840 case BFD_RELOC_16_GOTOFF:
4841 case BFD_RELOC_LO16_GOTOFF:
4842 case BFD_RELOC_HI16_GOTOFF:
4843 case BFD_RELOC_HI16_S_GOTOFF:
4844 case BFD_RELOC_LO16_BASEREL:
4845 case BFD_RELOC_HI16_BASEREL:
4846 case BFD_RELOC_HI16_S_BASEREL:
4847 case BFD_RELOC_PPC_EMB_NADDR16:
4848 case BFD_RELOC_PPC_EMB_NADDR16_LO:
4849 case BFD_RELOC_PPC_EMB_NADDR16_HI:
4850 case BFD_RELOC_PPC_EMB_NADDR16_HA:
4851 case BFD_RELOC_PPC_EMB_SDAI16:
4852 case BFD_RELOC_PPC_EMB_SDA2REL:
4853 case BFD_RELOC_PPC_EMB_SDA2I16:
4854 case BFD_RELOC_PPC_EMB_RELSEC16:
4855 case BFD_RELOC_PPC_EMB_RELST_LO:
4856 case BFD_RELOC_PPC_EMB_RELST_HI:
4857 case BFD_RELOC_PPC_EMB_RELST_HA:
4858 case BFD_RELOC_PPC_EMB_RELSDA:
4859 case BFD_RELOC_PPC_TOC16:
4860 if (fixp->fx_pcrel)
4862 if (fixp->fx_addsy != NULL)
4863 as_bad_where (fixp->fx_file, fixp->fx_line,
4864 _("cannot emit PC relative %s relocation against %s"),
4865 bfd_get_reloc_code_name (fixp->fx_r_type),
4866 S_GET_NAME (fixp->fx_addsy));
4867 else
4868 as_bad_where (fixp->fx_file, fixp->fx_line,
4869 _("cannot emit PC relative %s relocation"),
4870 bfd_get_reloc_code_name (fixp->fx_r_type));
4873 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4874 value, 2);
4875 break;
4877 /* This case happens when you write, for example,
4878 lis %r3,(L1-L2)@ha
4879 where L1 and L2 are defined later. */
4880 case BFD_RELOC_HI16:
4881 if (fixp->fx_pcrel)
4882 abort ();
4883 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4884 value >> 16, 2);
4885 break;
4886 case BFD_RELOC_HI16_S:
4887 if (fixp->fx_pcrel)
4888 abort ();
4889 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4890 (value + 0x8000) >> 16, 2);
4891 break;
4893 /* Because SDA21 modifies the register field, the size is set to 4
4894 bytes, rather than 2, so offset it here appropriately */
4895 case BFD_RELOC_PPC_EMB_SDA21:
4896 if (fixp->fx_pcrel)
4897 abort ();
4899 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where
4900 + ((target_big_endian) ? 2 : 0),
4901 value, 2);
4902 break;
4904 case BFD_RELOC_8:
4905 if (fixp->fx_pcrel)
4906 abort ();
4908 md_number_to_chars (fixp->fx_frag->fr_literal + fixp->fx_where,
4909 value, 1);
4910 break;
4912 case BFD_RELOC_24_PLT_PCREL:
4913 case BFD_RELOC_PPC_LOCAL24PC:
4914 if (!fixp->fx_pcrel && !fixp->fx_done)
4915 abort ();
4917 if (fixp->fx_done)
4919 char *where;
4920 unsigned long insn;
4922 /* Fetch the instruction, insert the fully resolved operand
4923 value, and stuff the instruction back again. */
4924 where = fixp->fx_frag->fr_literal + fixp->fx_where;
4925 if (target_big_endian)
4926 insn = bfd_getb32 ((unsigned char *) where);
4927 else
4928 insn = bfd_getl32 ((unsigned char *) where);
4929 if ((value & 3) != 0)
4930 as_bad_where (fixp->fx_file, fixp->fx_line,
4931 _("must branch to an address a multiple of 4"));
4932 if ((offsetT) value < -0x40000000
4933 || (offsetT) value >= 0x40000000)
4934 as_bad_where (fixp->fx_file, fixp->fx_line,
4935 _("@local or @plt branch destination is too far away, %ld bytes"),
4936 value);
4937 insn = insn | (value & 0x03fffffc);
4938 if (target_big_endian)
4939 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
4940 else
4941 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
4943 break;
4945 case BFD_RELOC_VTABLE_INHERIT:
4946 fixp->fx_done = 0;
4947 if (fixp->fx_addsy
4948 && !S_IS_DEFINED (fixp->fx_addsy)
4949 && !S_IS_WEAK (fixp->fx_addsy))
4950 S_SET_WEAK (fixp->fx_addsy);
4951 break;
4953 case BFD_RELOC_VTABLE_ENTRY:
4954 fixp->fx_done = 0;
4955 break;
4957 default:
4958 fprintf(stderr,
4959 _("Gas failure, reloc value %d\n"), fixp->fx_r_type);
4960 fflush(stderr);
4961 abort ();
4965 #ifdef OBJ_ELF
4966 fixp->fx_addnumber = value;
4967 #else
4968 if (fixp->fx_r_type != BFD_RELOC_PPC_TOC16)
4969 fixp->fx_addnumber = 0;
4970 else
4972 #ifdef TE_PE
4973 fixp->fx_addnumber = 0;
4974 #else
4975 /* We want to use the offset within the data segment of the
4976 symbol, not the actual VMA of the symbol. */
4977 fixp->fx_addnumber =
4978 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixp->fx_addsy));
4979 #endif
4981 #endif
4983 return 1;
4986 /* Generate a reloc for a fixup. */
4988 arelent *
4989 tc_gen_reloc (seg, fixp)
4990 asection *seg;
4991 fixS *fixp;
4993 arelent *reloc;
4995 reloc = (arelent *) xmalloc (sizeof (arelent));
4997 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
4998 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
4999 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
5000 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
5001 if (reloc->howto == (reloc_howto_type *) NULL)
5003 as_bad_where (fixp->fx_file, fixp->fx_line,
5004 _("reloc %d not supported by object file format"), (int)fixp->fx_r_type);
5005 return NULL;
5007 reloc->addend = fixp->fx_addnumber;
5009 return reloc;