include/opcode/
[deliverable/binutils-gdb.git] / gas / config / tc-ppc.c
1 /* tc-ppc.c -- Assemble for the PowerPC or POWER (RS/6000)
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor, Cygnus Support.
5
6 This file is part of GAS, the GNU Assembler.
7
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 02110-1301, USA. */
22
23 #include <stdio.h>
24 #include "as.h"
25 #include "safe-ctype.h"
26 #include "subsegs.h"
27 #include "dw2gencfi.h"
28 #include "opcode/ppc.h"
29
30 #ifdef OBJ_ELF
31 #include "elf/ppc.h"
32 #include "dwarf2dbg.h"
33 #endif
34
35 #ifdef TE_PE
36 #include "coff/pe.h"
37 #endif
38
39 /* This is the assembler for the PowerPC or POWER (RS/6000) chips. */
40
41 /* Tell the main code what the endianness is. */
42 extern int target_big_endian;
43
44 /* Whether or not, we've set target_big_endian. */
45 static int set_target_endian = 0;
46
47 /* Whether to use user friendly register names. */
48 #ifndef TARGET_REG_NAMES_P
49 #ifdef TE_PE
50 #define TARGET_REG_NAMES_P TRUE
51 #else
52 #define TARGET_REG_NAMES_P FALSE
53 #endif
54 #endif
55
56 /* Macros for calculating LO, HI, HA, HIGHER, HIGHERA, HIGHEST,
57 HIGHESTA. */
58
59 /* #lo(value) denotes the least significant 16 bits of the indicated. */
60 #define PPC_LO(v) ((v) & 0xffff)
61
62 /* #hi(value) denotes bits 16 through 31 of the indicated value. */
63 #define PPC_HI(v) (((v) >> 16) & 0xffff)
64
65 /* #ha(value) denotes the high adjusted value: bits 16 through 31 of
66 the indicated value, compensating for #lo() being treated as a
67 signed number. */
68 #define PPC_HA(v) PPC_HI ((v) + 0x8000)
69
70 /* #higher(value) denotes bits 32 through 47 of the indicated value. */
71 #define PPC_HIGHER(v) (((v) >> 16 >> 16) & 0xffff)
72
73 /* #highera(value) denotes bits 32 through 47 of the indicated value,
74 compensating for #lo() being treated as a signed number. */
75 #define PPC_HIGHERA(v) PPC_HIGHER ((v) + 0x8000)
76
77 /* #highest(value) denotes bits 48 through 63 of the indicated value. */
78 #define PPC_HIGHEST(v) (((v) >> 24 >> 24) & 0xffff)
79
80 /* #highesta(value) denotes bits 48 through 63 of the indicated value,
81 compensating for #lo being treated as a signed number. */
82 #define PPC_HIGHESTA(v) PPC_HIGHEST ((v) + 0x8000)
83
84 #define SEX16(val) ((((val) & 0xffff) ^ 0x8000) - 0x8000)
85
86 static bfd_boolean reg_names_p = TARGET_REG_NAMES_P;
87
88 static bfd_boolean register_name PARAMS ((expressionS *));
89 static void ppc_set_cpu PARAMS ((void));
90 static unsigned long ppc_insert_operand
91 PARAMS ((unsigned long insn, const struct powerpc_operand *operand,
92 offsetT val, char *file, unsigned int line));
93 static void ppc_macro PARAMS ((char *str, const struct powerpc_macro *macro));
94 static void ppc_byte PARAMS ((int));
95
96 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
97 static int ppc_is_toc_sym PARAMS ((symbolS *sym));
98 static void ppc_tc PARAMS ((int));
99 static void ppc_machine PARAMS ((int));
100 #endif
101
102 #ifdef OBJ_XCOFF
103 static void ppc_comm PARAMS ((int));
104 static void ppc_bb PARAMS ((int));
105 static void ppc_bc PARAMS ((int));
106 static void ppc_bf PARAMS ((int));
107 static void ppc_biei PARAMS ((int));
108 static void ppc_bs PARAMS ((int));
109 static void ppc_eb PARAMS ((int));
110 static void ppc_ec PARAMS ((int));
111 static void ppc_ef PARAMS ((int));
112 static void ppc_es PARAMS ((int));
113 static void ppc_csect PARAMS ((int));
114 static void ppc_change_csect PARAMS ((symbolS *, offsetT));
115 static void ppc_function PARAMS ((int));
116 static void ppc_extern PARAMS ((int));
117 static void ppc_lglobl PARAMS ((int));
118 static void ppc_section PARAMS ((int));
119 static void ppc_named_section PARAMS ((int));
120 static void ppc_stabx PARAMS ((int));
121 static void ppc_rename PARAMS ((int));
122 static void ppc_toc PARAMS ((int));
123 static void ppc_xcoff_cons PARAMS ((int));
124 static void ppc_vbyte PARAMS ((int));
125 #endif
126
127 #ifdef OBJ_ELF
128 static bfd_reloc_code_real_type ppc_elf_suffix PARAMS ((char **, expressionS *));
129 static void ppc_elf_cons PARAMS ((int));
130 static void ppc_elf_rdata PARAMS ((int));
131 static void ppc_elf_lcomm PARAMS ((int));
132 static void ppc_elf_validate_fix PARAMS ((fixS *, segT));
133 static void ppc_apuinfo_section_add PARAMS ((unsigned int apu, unsigned int version));
134 #endif
135
136 #ifdef TE_PE
137 static void ppc_set_current_section PARAMS ((segT));
138 static void ppc_previous PARAMS ((int));
139 static void ppc_pdata PARAMS ((int));
140 static void ppc_ydata PARAMS ((int));
141 static void ppc_reldata PARAMS ((int));
142 static void ppc_rdata PARAMS ((int));
143 static void ppc_ualong PARAMS ((int));
144 static void ppc_znop PARAMS ((int));
145 static void ppc_pe_comm PARAMS ((int));
146 static void ppc_pe_section PARAMS ((int));
147 static void ppc_pe_function PARAMS ((int));
148 static void ppc_pe_tocd PARAMS ((int));
149 #endif
150 \f
151 /* Generic assembler global variables which must be defined by all
152 targets. */
153
154 #ifdef OBJ_ELF
155 /* This string holds the chars that always start a comment. If the
156 pre-processor is disabled, these aren't very useful. The macro
157 tc_comment_chars points to this. We use this, rather than the
158 usual comment_chars, so that we can switch for Solaris conventions. */
159 static const char ppc_solaris_comment_chars[] = "#!";
160 static const char ppc_eabi_comment_chars[] = "#";
161
162 #ifdef TARGET_SOLARIS_COMMENT
163 const char *ppc_comment_chars = ppc_solaris_comment_chars;
164 #else
165 const char *ppc_comment_chars = ppc_eabi_comment_chars;
166 #endif
167 #else
168 const char comment_chars[] = "#";
169 #endif
170
171 /* Characters which start a comment at the beginning of a line. */
172 const char line_comment_chars[] = "#";
173
174 /* Characters which may be used to separate multiple commands on a
175 single line. */
176 const char line_separator_chars[] = ";";
177
178 /* Characters which are used to indicate an exponent in a floating
179 point number. */
180 const char EXP_CHARS[] = "eE";
181
182 /* Characters which mean that a number is a floating point constant,
183 as in 0d1.0. */
184 const char FLT_CHARS[] = "dD";
185
186 /* '+' and '-' can be used as postfix predicate predictors for conditional
187 branches. So they need to be accepted as symbol characters.
188 Also, anything that can start an operand needs to be mentioned here,
189 to stop the input scrubber eating whitespace. */
190 const char ppc_symbol_chars[] = "+-%[";
191
192 /* The dwarf2 data alignment, adjusted for 32 or 64 bit. */
193 int ppc_cie_data_alignment;
194 \f
195 /* The target specific pseudo-ops which we support. */
196
197 const pseudo_typeS md_pseudo_table[] =
198 {
199 /* Pseudo-ops which must be overridden. */
200 { "byte", ppc_byte, 0 },
201
202 #ifdef OBJ_XCOFF
203 /* Pseudo-ops specific to the RS/6000 XCOFF format. Some of these
204 legitimately belong in the obj-*.c file. However, XCOFF is based
205 on COFF, and is only implemented for the RS/6000. We just use
206 obj-coff.c, and add what we need here. */
207 { "comm", ppc_comm, 0 },
208 { "lcomm", ppc_comm, 1 },
209 { "bb", ppc_bb, 0 },
210 { "bc", ppc_bc, 0 },
211 { "bf", ppc_bf, 0 },
212 { "bi", ppc_biei, 0 },
213 { "bs", ppc_bs, 0 },
214 { "csect", ppc_csect, 0 },
215 { "data", ppc_section, 'd' },
216 { "eb", ppc_eb, 0 },
217 { "ec", ppc_ec, 0 },
218 { "ef", ppc_ef, 0 },
219 { "ei", ppc_biei, 1 },
220 { "es", ppc_es, 0 },
221 { "extern", ppc_extern, 0 },
222 { "function", ppc_function, 0 },
223 { "lglobl", ppc_lglobl, 0 },
224 { "rename", ppc_rename, 0 },
225 { "section", ppc_named_section, 0 },
226 { "stabx", ppc_stabx, 0 },
227 { "text", ppc_section, 't' },
228 { "toc", ppc_toc, 0 },
229 { "long", ppc_xcoff_cons, 2 },
230 { "llong", ppc_xcoff_cons, 3 },
231 { "word", ppc_xcoff_cons, 1 },
232 { "short", ppc_xcoff_cons, 1 },
233 { "vbyte", ppc_vbyte, 0 },
234 #endif
235
236 #ifdef OBJ_ELF
237 { "llong", ppc_elf_cons, 8 },
238 { "quad", ppc_elf_cons, 8 },
239 { "long", ppc_elf_cons, 4 },
240 { "word", ppc_elf_cons, 2 },
241 { "short", ppc_elf_cons, 2 },
242 { "rdata", ppc_elf_rdata, 0 },
243 { "rodata", ppc_elf_rdata, 0 },
244 { "lcomm", ppc_elf_lcomm, 0 },
245 #endif
246
247 #ifdef TE_PE
248 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
249 { "previous", ppc_previous, 0 },
250 { "pdata", ppc_pdata, 0 },
251 { "ydata", ppc_ydata, 0 },
252 { "reldata", ppc_reldata, 0 },
253 { "rdata", ppc_rdata, 0 },
254 { "ualong", ppc_ualong, 0 },
255 { "znop", ppc_znop, 0 },
256 { "comm", ppc_pe_comm, 0 },
257 { "lcomm", ppc_pe_comm, 1 },
258 { "section", ppc_pe_section, 0 },
259 { "function", ppc_pe_function,0 },
260 { "tocd", ppc_pe_tocd, 0 },
261 #endif
262
263 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
264 { "tc", ppc_tc, 0 },
265 { "machine", ppc_machine, 0 },
266 #endif
267
268 { NULL, NULL, 0 }
269 };
270
271 \f
272 /* Predefined register names if -mregnames (or default for Windows NT).
273 In general, there are lots of them, in an attempt to be compatible
274 with a number of other Windows NT assemblers. */
275
276 /* Structure to hold information about predefined registers. */
277 struct pd_reg
278 {
279 char *name;
280 int value;
281 };
282
283 /* List of registers that are pre-defined:
284
285 Each general register has predefined names of the form:
286 1. r<reg_num> which has the value <reg_num>.
287 2. r.<reg_num> which has the value <reg_num>.
288
289 Each floating point register has predefined names of the form:
290 1. f<reg_num> which has the value <reg_num>.
291 2. f.<reg_num> which has the value <reg_num>.
292
293 Each vector unit register has predefined names of the form:
294 1. v<reg_num> which has the value <reg_num>.
295 2. v.<reg_num> which has the value <reg_num>.
296
297 Each condition register has predefined names of the form:
298 1. cr<reg_num> which has the value <reg_num>.
299 2. cr.<reg_num> which has the value <reg_num>.
300
301 There are individual registers as well:
302 sp or r.sp has the value 1
303 rtoc or r.toc has the value 2
304 fpscr has the value 0
305 xer has the value 1
306 lr has the value 8
307 ctr has the value 9
308 pmr has the value 0
309 dar has the value 19
310 dsisr has the value 18
311 dec has the value 22
312 sdr1 has the value 25
313 srr0 has the value 26
314 srr1 has the value 27
315
316 The table is sorted. Suitable for searching by a binary search. */
317
318 static const struct pd_reg pre_defined_registers[] =
319 {
320 { "cr.0", 0 }, /* Condition Registers */
321 { "cr.1", 1 },
322 { "cr.2", 2 },
323 { "cr.3", 3 },
324 { "cr.4", 4 },
325 { "cr.5", 5 },
326 { "cr.6", 6 },
327 { "cr.7", 7 },
328
329 { "cr0", 0 },
330 { "cr1", 1 },
331 { "cr2", 2 },
332 { "cr3", 3 },
333 { "cr4", 4 },
334 { "cr5", 5 },
335 { "cr6", 6 },
336 { "cr7", 7 },
337
338 { "ctr", 9 },
339
340 { "dar", 19 }, /* Data Access Register */
341 { "dec", 22 }, /* Decrementer */
342 { "dsisr", 18 }, /* Data Storage Interrupt Status Register */
343
344 { "f.0", 0 }, /* Floating point registers */
345 { "f.1", 1 },
346 { "f.10", 10 },
347 { "f.11", 11 },
348 { "f.12", 12 },
349 { "f.13", 13 },
350 { "f.14", 14 },
351 { "f.15", 15 },
352 { "f.16", 16 },
353 { "f.17", 17 },
354 { "f.18", 18 },
355 { "f.19", 19 },
356 { "f.2", 2 },
357 { "f.20", 20 },
358 { "f.21", 21 },
359 { "f.22", 22 },
360 { "f.23", 23 },
361 { "f.24", 24 },
362 { "f.25", 25 },
363 { "f.26", 26 },
364 { "f.27", 27 },
365 { "f.28", 28 },
366 { "f.29", 29 },
367 { "f.3", 3 },
368 { "f.30", 30 },
369 { "f.31", 31 },
370 { "f.4", 4 },
371 { "f.5", 5 },
372 { "f.6", 6 },
373 { "f.7", 7 },
374 { "f.8", 8 },
375 { "f.9", 9 },
376
377 { "f0", 0 },
378 { "f1", 1 },
379 { "f10", 10 },
380 { "f11", 11 },
381 { "f12", 12 },
382 { "f13", 13 },
383 { "f14", 14 },
384 { "f15", 15 },
385 { "f16", 16 },
386 { "f17", 17 },
387 { "f18", 18 },
388 { "f19", 19 },
389 { "f2", 2 },
390 { "f20", 20 },
391 { "f21", 21 },
392 { "f22", 22 },
393 { "f23", 23 },
394 { "f24", 24 },
395 { "f25", 25 },
396 { "f26", 26 },
397 { "f27", 27 },
398 { "f28", 28 },
399 { "f29", 29 },
400 { "f3", 3 },
401 { "f30", 30 },
402 { "f31", 31 },
403 { "f4", 4 },
404 { "f5", 5 },
405 { "f6", 6 },
406 { "f7", 7 },
407 { "f8", 8 },
408 { "f9", 9 },
409
410 { "fpscr", 0 },
411
412 { "lr", 8 }, /* Link Register */
413
414 { "pmr", 0 },
415
416 { "r.0", 0 }, /* General Purpose Registers */
417 { "r.1", 1 },
418 { "r.10", 10 },
419 { "r.11", 11 },
420 { "r.12", 12 },
421 { "r.13", 13 },
422 { "r.14", 14 },
423 { "r.15", 15 },
424 { "r.16", 16 },
425 { "r.17", 17 },
426 { "r.18", 18 },
427 { "r.19", 19 },
428 { "r.2", 2 },
429 { "r.20", 20 },
430 { "r.21", 21 },
431 { "r.22", 22 },
432 { "r.23", 23 },
433 { "r.24", 24 },
434 { "r.25", 25 },
435 { "r.26", 26 },
436 { "r.27", 27 },
437 { "r.28", 28 },
438 { "r.29", 29 },
439 { "r.3", 3 },
440 { "r.30", 30 },
441 { "r.31", 31 },
442 { "r.4", 4 },
443 { "r.5", 5 },
444 { "r.6", 6 },
445 { "r.7", 7 },
446 { "r.8", 8 },
447 { "r.9", 9 },
448
449 { "r.sp", 1 }, /* Stack Pointer */
450
451 { "r.toc", 2 }, /* Pointer to the table of contents */
452
453 { "r0", 0 }, /* More general purpose registers */
454 { "r1", 1 },
455 { "r10", 10 },
456 { "r11", 11 },
457 { "r12", 12 },
458 { "r13", 13 },
459 { "r14", 14 },
460 { "r15", 15 },
461 { "r16", 16 },
462 { "r17", 17 },
463 { "r18", 18 },
464 { "r19", 19 },
465 { "r2", 2 },
466 { "r20", 20 },
467 { "r21", 21 },
468 { "r22", 22 },
469 { "r23", 23 },
470 { "r24", 24 },
471 { "r25", 25 },
472 { "r26", 26 },
473 { "r27", 27 },
474 { "r28", 28 },
475 { "r29", 29 },
476 { "r3", 3 },
477 { "r30", 30 },
478 { "r31", 31 },
479 { "r4", 4 },
480 { "r5", 5 },
481 { "r6", 6 },
482 { "r7", 7 },
483 { "r8", 8 },
484 { "r9", 9 },
485
486 { "rtoc", 2 }, /* Table of contents */
487
488 { "sdr1", 25 }, /* Storage Description Register 1 */
489
490 { "sp", 1 },
491
492 { "srr0", 26 }, /* Machine Status Save/Restore Register 0 */
493 { "srr1", 27 }, /* Machine Status Save/Restore Register 1 */
494
495 { "v.0", 0 }, /* Vector registers */
496 { "v.1", 1 },
497 { "v.10", 10 },
498 { "v.11", 11 },
499 { "v.12", 12 },
500 { "v.13", 13 },
501 { "v.14", 14 },
502 { "v.15", 15 },
503 { "v.16", 16 },
504 { "v.17", 17 },
505 { "v.18", 18 },
506 { "v.19", 19 },
507 { "v.2", 2 },
508 { "v.20", 20 },
509 { "v.21", 21 },
510 { "v.22", 22 },
511 { "v.23", 23 },
512 { "v.24", 24 },
513 { "v.25", 25 },
514 { "v.26", 26 },
515 { "v.27", 27 },
516 { "v.28", 28 },
517 { "v.29", 29 },
518 { "v.3", 3 },
519 { "v.30", 30 },
520 { "v.31", 31 },
521 { "v.4", 4 },
522 { "v.5", 5 },
523 { "v.6", 6 },
524 { "v.7", 7 },
525 { "v.8", 8 },
526 { "v.9", 9 },
527
528 { "v0", 0 },
529 { "v1", 1 },
530 { "v10", 10 },
531 { "v11", 11 },
532 { "v12", 12 },
533 { "v13", 13 },
534 { "v14", 14 },
535 { "v15", 15 },
536 { "v16", 16 },
537 { "v17", 17 },
538 { "v18", 18 },
539 { "v19", 19 },
540 { "v2", 2 },
541 { "v20", 20 },
542 { "v21", 21 },
543 { "v22", 22 },
544 { "v23", 23 },
545 { "v24", 24 },
546 { "v25", 25 },
547 { "v26", 26 },
548 { "v27", 27 },
549 { "v28", 28 },
550 { "v29", 29 },
551 { "v3", 3 },
552 { "v30", 30 },
553 { "v31", 31 },
554 { "v4", 4 },
555 { "v5", 5 },
556 { "v6", 6 },
557 { "v7", 7 },
558 { "v8", 8 },
559 { "v9", 9 },
560
561 { "xer", 1 },
562
563 };
564
565 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
566
567 /* Given NAME, find the register number associated with that name, return
568 the integer value associated with the given name or -1 on failure. */
569
570 static int reg_name_search
571 PARAMS ((const struct pd_reg *, int, const char * name));
572
573 static int
574 reg_name_search (regs, regcount, name)
575 const struct pd_reg *regs;
576 int regcount;
577 const char *name;
578 {
579 int middle, low, high;
580 int cmp;
581
582 low = 0;
583 high = regcount - 1;
584
585 do
586 {
587 middle = (low + high) / 2;
588 cmp = strcasecmp (name, regs[middle].name);
589 if (cmp < 0)
590 high = middle - 1;
591 else if (cmp > 0)
592 low = middle + 1;
593 else
594 return regs[middle].value;
595 }
596 while (low <= high);
597
598 return -1;
599 }
600
601 /*
602 * Summary of register_name.
603 *
604 * in: Input_line_pointer points to 1st char of operand.
605 *
606 * out: A expressionS.
607 * The operand may have been a register: in this case, X_op == O_register,
608 * X_add_number is set to the register number, and truth is returned.
609 * Input_line_pointer->(next non-blank) char after operand, or is in its
610 * original state.
611 */
612
613 static bfd_boolean
614 register_name (expressionP)
615 expressionS *expressionP;
616 {
617 int reg_number;
618 char *name;
619 char *start;
620 char c;
621
622 /* Find the spelling of the operand. */
623 start = name = input_line_pointer;
624 if (name[0] == '%' && ISALPHA (name[1]))
625 name = ++input_line_pointer;
626
627 else if (!reg_names_p || !ISALPHA (name[0]))
628 return FALSE;
629
630 c = get_symbol_end ();
631 reg_number = reg_name_search (pre_defined_registers, REG_NAME_CNT, name);
632
633 /* Put back the delimiting char. */
634 *input_line_pointer = c;
635
636 /* Look to see if it's in the register table. */
637 if (reg_number >= 0)
638 {
639 expressionP->X_op = O_register;
640 expressionP->X_add_number = reg_number;
641
642 /* Make the rest nice. */
643 expressionP->X_add_symbol = NULL;
644 expressionP->X_op_symbol = NULL;
645 return TRUE;
646 }
647
648 /* Reset the line as if we had not done anything. */
649 input_line_pointer = start;
650 return FALSE;
651 }
652 \f
653 /* This function is called for each symbol seen in an expression. It
654 handles the special parsing which PowerPC assemblers are supposed
655 to use for condition codes. */
656
657 /* Whether to do the special parsing. */
658 static bfd_boolean cr_operand;
659
660 /* Names to recognize in a condition code. This table is sorted. */
661 static const struct pd_reg cr_names[] =
662 {
663 { "cr0", 0 },
664 { "cr1", 1 },
665 { "cr2", 2 },
666 { "cr3", 3 },
667 { "cr4", 4 },
668 { "cr5", 5 },
669 { "cr6", 6 },
670 { "cr7", 7 },
671 { "eq", 2 },
672 { "gt", 1 },
673 { "lt", 0 },
674 { "so", 3 },
675 { "un", 3 }
676 };
677
678 /* Parsing function. This returns non-zero if it recognized an
679 expression. */
680
681 int
682 ppc_parse_name (name, expr)
683 const char *name;
684 expressionS *expr;
685 {
686 int val;
687
688 if (! cr_operand)
689 return 0;
690
691 val = reg_name_search (cr_names, sizeof cr_names / sizeof cr_names[0],
692 name);
693 if (val < 0)
694 return 0;
695
696 expr->X_op = O_constant;
697 expr->X_add_number = val;
698
699 return 1;
700 }
701 \f
702 /* Local variables. */
703
704 /* The type of processor we are assembling for. This is one or more
705 of the PPC_OPCODE flags defined in opcode/ppc.h. */
706 static unsigned long ppc_cpu = 0;
707
708 /* Whether to target xcoff64/elf64. */
709 static unsigned int ppc_obj64 = BFD_DEFAULT_TARGET_SIZE == 64;
710
711 /* Opcode hash table. */
712 static struct hash_control *ppc_hash;
713
714 /* Macro hash table. */
715 static struct hash_control *ppc_macro_hash;
716
717 #ifdef OBJ_ELF
718 /* What type of shared library support to use. */
719 static enum { SHLIB_NONE, SHLIB_PIC, SHLIB_MRELOCATABLE } shlib = SHLIB_NONE;
720
721 /* Flags to set in the elf header. */
722 static flagword ppc_flags = 0;
723
724 /* Whether this is Solaris or not. */
725 #ifdef TARGET_SOLARIS_COMMENT
726 #define SOLARIS_P TRUE
727 #else
728 #define SOLARIS_P FALSE
729 #endif
730
731 static bfd_boolean msolaris = SOLARIS_P;
732 #endif
733
734 #ifdef OBJ_XCOFF
735
736 /* The RS/6000 assembler uses the .csect pseudo-op to generate code
737 using a bunch of different sections. These assembler sections,
738 however, are all encompassed within the .text or .data sections of
739 the final output file. We handle this by using different
740 subsegments within these main segments. */
741
742 /* Next subsegment to allocate within the .text segment. */
743 static subsegT ppc_text_subsegment = 2;
744
745 /* Linked list of csects in the text section. */
746 static symbolS *ppc_text_csects;
747
748 /* Next subsegment to allocate within the .data segment. */
749 static subsegT ppc_data_subsegment = 2;
750
751 /* Linked list of csects in the data section. */
752 static symbolS *ppc_data_csects;
753
754 /* The current csect. */
755 static symbolS *ppc_current_csect;
756
757 /* The RS/6000 assembler uses a TOC which holds addresses of functions
758 and variables. Symbols are put in the TOC with the .tc pseudo-op.
759 A special relocation is used when accessing TOC entries. We handle
760 the TOC as a subsegment within the .data segment. We set it up if
761 we see a .toc pseudo-op, and save the csect symbol here. */
762 static symbolS *ppc_toc_csect;
763
764 /* The first frag in the TOC subsegment. */
765 static fragS *ppc_toc_frag;
766
767 /* The first frag in the first subsegment after the TOC in the .data
768 segment. NULL if there are no subsegments after the TOC. */
769 static fragS *ppc_after_toc_frag;
770
771 /* The current static block. */
772 static symbolS *ppc_current_block;
773
774 /* The COFF debugging section; set by md_begin. This is not the
775 .debug section, but is instead the secret BFD section which will
776 cause BFD to set the section number of a symbol to N_DEBUG. */
777 static asection *ppc_coff_debug_section;
778
779 #endif /* OBJ_XCOFF */
780
781 #ifdef TE_PE
782
783 /* Various sections that we need for PE coff support. */
784 static segT ydata_section;
785 static segT pdata_section;
786 static segT reldata_section;
787 static segT rdata_section;
788 static segT tocdata_section;
789
790 /* The current section and the previous section. See ppc_previous. */
791 static segT ppc_previous_section;
792 static segT ppc_current_section;
793
794 #endif /* TE_PE */
795
796 #ifdef OBJ_ELF
797 symbolS *GOT_symbol; /* Pre-defined "_GLOBAL_OFFSET_TABLE" */
798 #define PPC_APUINFO_ISEL 0x40
799 #define PPC_APUINFO_PMR 0x41
800 #define PPC_APUINFO_RFMCI 0x42
801 #define PPC_APUINFO_CACHELCK 0x43
802 #define PPC_APUINFO_SPE 0x100
803 #define PPC_APUINFO_EFS 0x101
804 #define PPC_APUINFO_BRLOCK 0x102
805
806 /*
807 * We keep a list of APUinfo
808 */
809 unsigned long *ppc_apuinfo_list;
810 unsigned int ppc_apuinfo_num;
811 unsigned int ppc_apuinfo_num_alloc;
812 #endif /* OBJ_ELF */
813 \f
814 #ifdef OBJ_ELF
815 const char *const md_shortopts = "b:l:usm:K:VQ:";
816 #else
817 const char *const md_shortopts = "um:";
818 #endif
819 const struct option md_longopts[] = {
820 {NULL, no_argument, NULL, 0}
821 };
822 const size_t md_longopts_size = sizeof (md_longopts);
823
824
825 /* Handle -m options that set cpu type, and .machine arg. */
826
827 static int
828 parse_cpu (const char *arg)
829 {
830 /* -mpwrx and -mpwr2 mean to assemble for the IBM POWER/2
831 (RIOS2). */
832 if (strcmp (arg, "pwrx") == 0 || strcmp (arg, "pwr2") == 0)
833 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_POWER2 | PPC_OPCODE_32;
834 /* -mpwr means to assemble for the IBM POWER (RIOS1). */
835 else if (strcmp (arg, "pwr") == 0)
836 ppc_cpu = PPC_OPCODE_POWER | PPC_OPCODE_32;
837 /* -m601 means to assemble for the PowerPC 601, which includes
838 instructions that are holdovers from the Power. */
839 else if (strcmp (arg, "601") == 0)
840 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
841 | PPC_OPCODE_601 | PPC_OPCODE_32);
842 /* -mppc, -mppc32, -m603, and -m604 mean to assemble for the
843 PowerPC 603/604. */
844 else if (strcmp (arg, "ppc") == 0
845 || strcmp (arg, "ppc32") == 0
846 || strcmp (arg, "603") == 0
847 || strcmp (arg, "604") == 0)
848 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32;
849 /* -m403 and -m405 mean to assemble for the PowerPC 403/405. */
850 else if (strcmp (arg, "403") == 0
851 || strcmp (arg, "405") == 0)
852 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
853 | PPC_OPCODE_403 | PPC_OPCODE_32);
854 else if (strcmp (arg, "440") == 0)
855 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_32
856 | PPC_OPCODE_440 | PPC_OPCODE_ISEL | PPC_OPCODE_RFMCI);
857 else if (strcmp (arg, "7400") == 0
858 || strcmp (arg, "7410") == 0
859 || strcmp (arg, "7450") == 0
860 || strcmp (arg, "7455") == 0)
861 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
862 | PPC_OPCODE_ALTIVEC | PPC_OPCODE_32);
863 else if (strcmp (arg, "e300") == 0)
864 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32
865 | PPC_OPCODE_E300);
866 else if (strcmp (arg, "altivec") == 0)
867 {
868 if (ppc_cpu == 0)
869 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_ALTIVEC;
870 else
871 ppc_cpu |= PPC_OPCODE_ALTIVEC;
872 }
873 else if (strcmp (arg, "e500") == 0 || strcmp (arg, "e500x2") == 0)
874 {
875 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_SPE
876 | PPC_OPCODE_ISEL | PPC_OPCODE_EFS | PPC_OPCODE_BRLOCK
877 | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK
878 | PPC_OPCODE_RFMCI);
879 }
880 else if (strcmp (arg, "spe") == 0)
881 {
882 if (ppc_cpu == 0)
883 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_SPE | PPC_OPCODE_EFS;
884 else
885 ppc_cpu |= PPC_OPCODE_SPE;
886 }
887 /* -mppc64 and -m620 mean to assemble for the 64-bit PowerPC
888 620. */
889 else if (strcmp (arg, "ppc64") == 0 || strcmp (arg, "620") == 0)
890 {
891 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64;
892 }
893 else if (strcmp (arg, "ppc64bridge") == 0)
894 {
895 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
896 | PPC_OPCODE_64_BRIDGE | PPC_OPCODE_64);
897 }
898 /* -mbooke/-mbooke32 mean enable 32-bit BookE support. */
899 else if (strcmp (arg, "booke") == 0 || strcmp (arg, "booke32") == 0)
900 {
901 ppc_cpu = PPC_OPCODE_PPC | PPC_OPCODE_BOOKE | PPC_OPCODE_32;
902 }
903 /* -mbooke64 means enable 64-bit BookE support. */
904 else if (strcmp (arg, "booke64") == 0)
905 {
906 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_BOOKE
907 | PPC_OPCODE_BOOKE64 | PPC_OPCODE_64);
908 }
909 else if (strcmp (arg, "power4") == 0)
910 {
911 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
912 | PPC_OPCODE_64 | PPC_OPCODE_POWER4);
913 }
914 else if (strcmp (arg, "power5") == 0)
915 {
916 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
917 | PPC_OPCODE_64 | PPC_OPCODE_POWER4
918 | PPC_OPCODE_POWER5);
919 }
920 else if (strcmp (arg, "power6") == 0)
921 {
922 ppc_cpu = (PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC
923 | PPC_OPCODE_64 | PPC_OPCODE_POWER4
924 | PPC_OPCODE_POWER5 | PPC_OPCODE_POWER6);
925 }
926 /* -mcom means assemble for the common intersection between Power
927 and PowerPC. At present, we just allow the union, rather
928 than the intersection. */
929 else if (strcmp (arg, "com") == 0)
930 ppc_cpu = PPC_OPCODE_COMMON | PPC_OPCODE_32;
931 /* -many means to assemble for any architecture (PWR/PWRX/PPC). */
932 else if (strcmp (arg, "any") == 0)
933 ppc_cpu |= PPC_OPCODE_ANY;
934 else
935 return 0;
936
937 return 1;
938 }
939
940 int
941 md_parse_option (c, arg)
942 int c;
943 char *arg;
944 {
945 switch (c)
946 {
947 case 'u':
948 /* -u means that any undefined symbols should be treated as
949 external, which is the default for gas anyhow. */
950 break;
951
952 #ifdef OBJ_ELF
953 case 'l':
954 /* Solaris as takes -le (presumably for little endian). For completeness
955 sake, recognize -be also. */
956 if (strcmp (arg, "e") == 0)
957 {
958 target_big_endian = 0;
959 set_target_endian = 1;
960 }
961 else
962 return 0;
963
964 break;
965
966 case 'b':
967 if (strcmp (arg, "e") == 0)
968 {
969 target_big_endian = 1;
970 set_target_endian = 1;
971 }
972 else
973 return 0;
974
975 break;
976
977 case 'K':
978 /* Recognize -K PIC. */
979 if (strcmp (arg, "PIC") == 0 || strcmp (arg, "pic") == 0)
980 {
981 shlib = SHLIB_PIC;
982 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
983 }
984 else
985 return 0;
986
987 break;
988 #endif
989
990 /* a64 and a32 determine whether to use XCOFF64 or XCOFF32. */
991 case 'a':
992 if (strcmp (arg, "64") == 0)
993 {
994 #ifdef BFD64
995 ppc_obj64 = 1;
996 #else
997 as_fatal (_("%s unsupported"), "-a64");
998 #endif
999 }
1000 else if (strcmp (arg, "32") == 0)
1001 ppc_obj64 = 0;
1002 else
1003 return 0;
1004 break;
1005
1006 case 'm':
1007 if (parse_cpu (arg))
1008 ;
1009
1010 else if (strcmp (arg, "regnames") == 0)
1011 reg_names_p = TRUE;
1012
1013 else if (strcmp (arg, "no-regnames") == 0)
1014 reg_names_p = FALSE;
1015
1016 #ifdef OBJ_ELF
1017 /* -mrelocatable/-mrelocatable-lib -- warn about initializations
1018 that require relocation. */
1019 else if (strcmp (arg, "relocatable") == 0)
1020 {
1021 shlib = SHLIB_MRELOCATABLE;
1022 ppc_flags |= EF_PPC_RELOCATABLE;
1023 }
1024
1025 else if (strcmp (arg, "relocatable-lib") == 0)
1026 {
1027 shlib = SHLIB_MRELOCATABLE;
1028 ppc_flags |= EF_PPC_RELOCATABLE_LIB;
1029 }
1030
1031 /* -memb, set embedded bit. */
1032 else if (strcmp (arg, "emb") == 0)
1033 ppc_flags |= EF_PPC_EMB;
1034
1035 /* -mlittle/-mbig set the endianess. */
1036 else if (strcmp (arg, "little") == 0
1037 || strcmp (arg, "little-endian") == 0)
1038 {
1039 target_big_endian = 0;
1040 set_target_endian = 1;
1041 }
1042
1043 else if (strcmp (arg, "big") == 0 || strcmp (arg, "big-endian") == 0)
1044 {
1045 target_big_endian = 1;
1046 set_target_endian = 1;
1047 }
1048
1049 else if (strcmp (arg, "solaris") == 0)
1050 {
1051 msolaris = TRUE;
1052 ppc_comment_chars = ppc_solaris_comment_chars;
1053 }
1054
1055 else if (strcmp (arg, "no-solaris") == 0)
1056 {
1057 msolaris = FALSE;
1058 ppc_comment_chars = ppc_eabi_comment_chars;
1059 }
1060 #endif
1061 else
1062 {
1063 as_bad (_("invalid switch -m%s"), arg);
1064 return 0;
1065 }
1066 break;
1067
1068 #ifdef OBJ_ELF
1069 /* -V: SVR4 argument to print version ID. */
1070 case 'V':
1071 print_version_id ();
1072 break;
1073
1074 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment section
1075 should be emitted or not. FIXME: Not implemented. */
1076 case 'Q':
1077 break;
1078
1079 /* Solaris takes -s to specify that .stabs go in a .stabs section,
1080 rather than .stabs.excl, which is ignored by the linker.
1081 FIXME: Not implemented. */
1082 case 's':
1083 if (arg)
1084 return 0;
1085
1086 break;
1087 #endif
1088
1089 default:
1090 return 0;
1091 }
1092
1093 return 1;
1094 }
1095
1096 void
1097 md_show_usage (stream)
1098 FILE *stream;
1099 {
1100 fprintf (stream, _("\
1101 PowerPC options:\n\
1102 -a32 generate ELF32/XCOFF32\n\
1103 -a64 generate ELF64/XCOFF64\n\
1104 -u ignored\n\
1105 -mpwrx, -mpwr2 generate code for POWER/2 (RIOS2)\n\
1106 -mpwr generate code for POWER (RIOS1)\n\
1107 -m601 generate code for PowerPC 601\n\
1108 -mppc, -mppc32, -m603, -m604\n\
1109 generate code for PowerPC 603/604\n\
1110 -m403, -m405 generate code for PowerPC 403/405\n\
1111 -m440 generate code for PowerPC 440\n\
1112 -m7400, -m7410, -m7450, -m7455\n\
1113 generate code For PowerPC 7400/7410/7450/7455\n"));
1114 fprintf (stream, _("\
1115 -mppc64, -m620 generate code for PowerPC 620/625/630\n\
1116 -mppc64bridge generate code for PowerPC 64, including bridge insns\n\
1117 -mbooke64 generate code for 64-bit PowerPC BookE\n\
1118 -mbooke, mbooke32 generate code for 32-bit PowerPC BookE\n\
1119 -mpower4 generate code for Power4 architecture\n\
1120 -mpower5 generate code for Power5 architecture\n\
1121 -mpower6 generate code for Power6 architecture\n\
1122 -mcom generate code Power/PowerPC common instructions\n\
1123 -many generate code for any architecture (PWR/PWRX/PPC)\n"));
1124 fprintf (stream, _("\
1125 -maltivec generate code for AltiVec\n\
1126 -me300 generate code for PowerPC e300 family\n\
1127 -me500, -me500x2 generate code for Motorola e500 core complex\n\
1128 -mspe generate code for Motorola SPE instructions\n\
1129 -mregnames Allow symbolic names for registers\n\
1130 -mno-regnames Do not allow symbolic names for registers\n"));
1131 #ifdef OBJ_ELF
1132 fprintf (stream, _("\
1133 -mrelocatable support for GCC's -mrelocatble option\n\
1134 -mrelocatable-lib support for GCC's -mrelocatble-lib option\n\
1135 -memb set PPC_EMB bit in ELF flags\n\
1136 -mlittle, -mlittle-endian, -l, -le\n\
1137 generate code for a little endian machine\n\
1138 -mbig, -mbig-endian, -b, -be\n\
1139 generate code for a big endian machine\n\
1140 -msolaris generate code for Solaris\n\
1141 -mno-solaris do not generate code for Solaris\n\
1142 -V print assembler version number\n\
1143 -Qy, -Qn ignored\n"));
1144 #endif
1145 }
1146 \f
1147 /* Set ppc_cpu if it is not already set. */
1148
1149 static void
1150 ppc_set_cpu ()
1151 {
1152 const char *default_os = TARGET_OS;
1153 const char *default_cpu = TARGET_CPU;
1154
1155 if ((ppc_cpu & ~PPC_OPCODE_ANY) == 0)
1156 {
1157 if (ppc_obj64)
1158 ppc_cpu |= PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_64;
1159 else if (strncmp (default_os, "aix", 3) == 0
1160 && default_os[3] >= '4' && default_os[3] <= '9')
1161 ppc_cpu |= PPC_OPCODE_COMMON | PPC_OPCODE_32;
1162 else if (strncmp (default_os, "aix3", 4) == 0)
1163 ppc_cpu |= PPC_OPCODE_POWER | PPC_OPCODE_32;
1164 else if (strcmp (default_cpu, "rs6000") == 0)
1165 ppc_cpu |= PPC_OPCODE_POWER | PPC_OPCODE_32;
1166 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1167 ppc_cpu |= PPC_OPCODE_PPC | PPC_OPCODE_CLASSIC | PPC_OPCODE_32;
1168 else
1169 as_fatal (_("Unknown default cpu = %s, os = %s"),
1170 default_cpu, default_os);
1171 }
1172 }
1173
1174 /* Figure out the BFD architecture to use. This function and ppc_mach
1175 are called well before md_begin, when the output file is opened. */
1176
1177 enum bfd_architecture
1178 ppc_arch ()
1179 {
1180 const char *default_cpu = TARGET_CPU;
1181 ppc_set_cpu ();
1182
1183 if ((ppc_cpu & PPC_OPCODE_PPC) != 0)
1184 return bfd_arch_powerpc;
1185 else if ((ppc_cpu & PPC_OPCODE_POWER) != 0)
1186 return bfd_arch_rs6000;
1187 else if ((ppc_cpu & (PPC_OPCODE_COMMON | PPC_OPCODE_ANY)) != 0)
1188 {
1189 if (strcmp (default_cpu, "rs6000") == 0)
1190 return bfd_arch_rs6000;
1191 else if (strncmp (default_cpu, "powerpc", 7) == 0)
1192 return bfd_arch_powerpc;
1193 }
1194
1195 as_fatal (_("Neither Power nor PowerPC opcodes were selected."));
1196 return bfd_arch_unknown;
1197 }
1198
1199 unsigned long
1200 ppc_mach ()
1201 {
1202 if (ppc_obj64)
1203 return bfd_mach_ppc64;
1204 else if (ppc_arch () == bfd_arch_rs6000)
1205 return bfd_mach_rs6k;
1206 else
1207 return bfd_mach_ppc;
1208 }
1209
1210 extern char*
1211 ppc_target_format ()
1212 {
1213 #ifdef OBJ_COFF
1214 #ifdef TE_PE
1215 return target_big_endian ? "pe-powerpc" : "pe-powerpcle";
1216 #elif TE_POWERMAC
1217 return "xcoff-powermac";
1218 #else
1219 # ifdef TE_AIX5
1220 return (ppc_obj64 ? "aix5coff64-rs6000" : "aixcoff-rs6000");
1221 # else
1222 return (ppc_obj64 ? "aixcoff64-rs6000" : "aixcoff-rs6000");
1223 # endif
1224 #endif
1225 #endif
1226 #ifdef OBJ_ELF
1227 # ifdef TE_VXWORKS
1228 return "elf32-powerpc-vxworks";
1229 # else
1230 return (target_big_endian
1231 ? (ppc_obj64 ? "elf64-powerpc" : "elf32-powerpc")
1232 : (ppc_obj64 ? "elf64-powerpcle" : "elf32-powerpcle"));
1233 # endif
1234 #endif
1235 }
1236
1237 /* Insert opcodes and macros into hash tables. Called at startup and
1238 for .cpu pseudo. */
1239
1240 static void
1241 ppc_setup_opcodes (void)
1242 {
1243 register const struct powerpc_opcode *op;
1244 const struct powerpc_opcode *op_end;
1245 const struct powerpc_macro *macro;
1246 const struct powerpc_macro *macro_end;
1247 bfd_boolean dup_insn = FALSE;
1248
1249 if (ppc_hash != NULL)
1250 hash_die (ppc_hash);
1251 if (ppc_macro_hash != NULL)
1252 hash_die (ppc_macro_hash);
1253
1254 /* Insert the opcodes into a hash table. */
1255 ppc_hash = hash_new ();
1256
1257 op_end = powerpc_opcodes + powerpc_num_opcodes;
1258 for (op = powerpc_opcodes; op < op_end; op++)
1259 {
1260 know ((op->opcode & op->mask) == op->opcode);
1261
1262 if ((op->flags & ppc_cpu & ~(PPC_OPCODE_32 | PPC_OPCODE_64)) != 0
1263 && ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64)) == 0
1264 || ((op->flags & (PPC_OPCODE_32 | PPC_OPCODE_64))
1265 == (ppc_cpu & (PPC_OPCODE_32 | PPC_OPCODE_64)))
1266 || (ppc_cpu & PPC_OPCODE_64_BRIDGE) != 0)
1267 /* Certain instructions (eg: extsw) do not exist in the
1268 32-bit BookE instruction set, but they do exist in the
1269 64-bit BookE instruction set, and other PPC instruction
1270 sets. Check to see if the opcode has the BOOKE64 flag set.
1271 If it does make sure that the target CPU is not the BookE32. */
1272 && ((op->flags & PPC_OPCODE_BOOKE64) == 0
1273 || (ppc_cpu & PPC_OPCODE_BOOKE64) == PPC_OPCODE_BOOKE64
1274 || (ppc_cpu & PPC_OPCODE_BOOKE) == 0)
1275 && ((op->flags & (PPC_OPCODE_POWER4 | PPC_OPCODE_NOPOWER4)) == 0
1276 || ((op->flags & PPC_OPCODE_POWER4)
1277 == (ppc_cpu & PPC_OPCODE_POWER4)))
1278 && ((op->flags & PPC_OPCODE_POWER5) == 0
1279 || ((op->flags & PPC_OPCODE_POWER5)
1280 == (ppc_cpu & PPC_OPCODE_POWER5)))
1281 && ((op->flags & PPC_OPCODE_POWER6) == 0
1282 || ((op->flags & PPC_OPCODE_POWER6)
1283 == (ppc_cpu & PPC_OPCODE_POWER6))))
1284 {
1285 const char *retval;
1286
1287 retval = hash_insert (ppc_hash, op->name, (PTR) op);
1288 if (retval != NULL)
1289 {
1290 /* Ignore Power duplicates for -m601. */
1291 if ((ppc_cpu & PPC_OPCODE_601) != 0
1292 && (op->flags & PPC_OPCODE_POWER) != 0)
1293 continue;
1294
1295 as_bad (_("Internal assembler error for instruction %s"),
1296 op->name);
1297 dup_insn = TRUE;
1298 }
1299 }
1300 }
1301
1302 if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
1303 for (op = powerpc_opcodes; op < op_end; op++)
1304 hash_insert (ppc_hash, op->name, (PTR) op);
1305
1306 /* Insert the macros into a hash table. */
1307 ppc_macro_hash = hash_new ();
1308
1309 macro_end = powerpc_macros + powerpc_num_macros;
1310 for (macro = powerpc_macros; macro < macro_end; macro++)
1311 {
1312 if ((macro->flags & ppc_cpu) != 0)
1313 {
1314 const char *retval;
1315
1316 retval = hash_insert (ppc_macro_hash, macro->name, (PTR) macro);
1317 if (retval != (const char *) NULL)
1318 {
1319 as_bad (_("Internal assembler error for macro %s"), macro->name);
1320 dup_insn = TRUE;
1321 }
1322 }
1323 }
1324
1325 if (dup_insn)
1326 abort ();
1327 }
1328
1329 /* This function is called when the assembler starts up. It is called
1330 after the options have been parsed and the output file has been
1331 opened. */
1332
1333 void
1334 md_begin ()
1335 {
1336 ppc_set_cpu ();
1337
1338 ppc_cie_data_alignment = ppc_obj64 ? -8 : -4;
1339
1340 #ifdef OBJ_ELF
1341 /* Set the ELF flags if desired. */
1342 if (ppc_flags && !msolaris)
1343 bfd_set_private_flags (stdoutput, ppc_flags);
1344 #endif
1345
1346 ppc_setup_opcodes ();
1347
1348 /* Tell the main code what the endianness is if it is not overridden
1349 by the user. */
1350 if (!set_target_endian)
1351 {
1352 set_target_endian = 1;
1353 target_big_endian = PPC_BIG_ENDIAN;
1354 }
1355
1356 #ifdef OBJ_XCOFF
1357 ppc_coff_debug_section = coff_section_from_bfd_index (stdoutput, N_DEBUG);
1358
1359 /* Create dummy symbols to serve as initial csects. This forces the
1360 text csects to precede the data csects. These symbols will not
1361 be output. */
1362 ppc_text_csects = symbol_make ("dummy\001");
1363 symbol_get_tc (ppc_text_csects)->within = ppc_text_csects;
1364 ppc_data_csects = symbol_make ("dummy\001");
1365 symbol_get_tc (ppc_data_csects)->within = ppc_data_csects;
1366 #endif
1367
1368 #ifdef TE_PE
1369
1370 ppc_current_section = text_section;
1371 ppc_previous_section = 0;
1372
1373 #endif
1374 }
1375
1376 void
1377 ppc_cleanup ()
1378 {
1379 #ifdef OBJ_ELF
1380 if (ppc_apuinfo_list == NULL)
1381 return;
1382
1383 /* Ok, so write the section info out. We have this layout:
1384
1385 byte data what
1386 ---- ---- ----
1387 0 8 length of "APUinfo\0"
1388 4 (n*4) number of APU's (4 bytes each)
1389 8 2 note type 2
1390 12 "APUinfo\0" name
1391 20 APU#1 first APU's info
1392 24 APU#2 second APU's info
1393 ... ...
1394 */
1395 {
1396 char *p;
1397 asection *seg = now_seg;
1398 subsegT subseg = now_subseg;
1399 asection *apuinfo_secp = (asection *) NULL;
1400 unsigned int i;
1401
1402 /* Create the .PPC.EMB.apuinfo section. */
1403 apuinfo_secp = subseg_new (".PPC.EMB.apuinfo", 0);
1404 bfd_set_section_flags (stdoutput,
1405 apuinfo_secp,
1406 SEC_HAS_CONTENTS | SEC_READONLY);
1407
1408 p = frag_more (4);
1409 md_number_to_chars (p, (valueT) 8, 4);
1410
1411 p = frag_more (4);
1412 md_number_to_chars (p, (valueT) ppc_apuinfo_num * 4, 4);
1413
1414 p = frag_more (4);
1415 md_number_to_chars (p, (valueT) 2, 4);
1416
1417 p = frag_more (8);
1418 strcpy (p, "APUinfo");
1419
1420 for (i = 0; i < ppc_apuinfo_num; i++)
1421 {
1422 p = frag_more (4);
1423 md_number_to_chars (p, (valueT) ppc_apuinfo_list[i], 4);
1424 }
1425
1426 frag_align (2, 0, 0);
1427
1428 /* We probably can't restore the current segment, for there likely
1429 isn't one yet... */
1430 if (seg && subseg)
1431 subseg_set (seg, subseg);
1432 }
1433 #endif
1434 }
1435
1436 /* Insert an operand value into an instruction. */
1437
1438 static unsigned long
1439 ppc_insert_operand (insn, operand, val, file, line)
1440 unsigned long insn;
1441 const struct powerpc_operand *operand;
1442 offsetT val;
1443 char *file;
1444 unsigned int line;
1445 {
1446 if (operand->bits != 32)
1447 {
1448 long min, max;
1449 offsetT test;
1450
1451 if ((operand->flags & PPC_OPERAND_SIGNED) != 0)
1452 {
1453 if ((operand->flags & PPC_OPERAND_SIGNOPT) != 0)
1454 max = (1 << operand->bits) - 1;
1455 else
1456 max = (1 << (operand->bits - 1)) - 1;
1457 min = - (1 << (operand->bits - 1));
1458
1459 if (!ppc_obj64)
1460 {
1461 /* Some people write 32 bit hex constants with the sign
1462 extension done by hand. This shouldn't really be
1463 valid, but, to permit this code to assemble on a 64
1464 bit host, we sign extend the 32 bit value. */
1465 if (val > 0
1466 && (val & (offsetT) 0x80000000) != 0
1467 && (val & (offsetT) 0xffffffff) == val)
1468 {
1469 val -= 0x80000000;
1470 val -= 0x80000000;
1471 }
1472 }
1473 }
1474 else
1475 {
1476 max = (1 << operand->bits) - 1;
1477 min = 0;
1478 }
1479
1480 if ((operand->flags & PPC_OPERAND_NEGATIVE) != 0)
1481 test = - val;
1482 else
1483 test = val;
1484
1485 if (test < (offsetT) min || test > (offsetT) max)
1486 as_bad_value_out_of_range (_("operand"), test, (offsetT) min, (offsetT) max, file, line);
1487 }
1488
1489 if (operand->insert)
1490 {
1491 const char *errmsg;
1492
1493 errmsg = NULL;
1494 insn = (*operand->insert) (insn, (long) val, ppc_cpu, &errmsg);
1495 if (errmsg != (const char *) NULL)
1496 as_bad_where (file, line, errmsg);
1497 }
1498 else
1499 insn |= (((long) val & ((1 << operand->bits) - 1))
1500 << operand->shift);
1501
1502 return insn;
1503 }
1504
1505 \f
1506 #ifdef OBJ_ELF
1507 /* Parse @got, etc. and return the desired relocation. */
1508 static bfd_reloc_code_real_type
1509 ppc_elf_suffix (str_p, exp_p)
1510 char **str_p;
1511 expressionS *exp_p;
1512 {
1513 struct map_bfd {
1514 char *string;
1515 unsigned int length : 8;
1516 unsigned int valid32 : 1;
1517 unsigned int valid64 : 1;
1518 unsigned int reloc;
1519 };
1520
1521 char ident[20];
1522 char *str = *str_p;
1523 char *str2;
1524 int ch;
1525 int len;
1526 const struct map_bfd *ptr;
1527
1528 #define MAP(str, reloc) { str, sizeof (str) - 1, 1, 1, reloc }
1529 #define MAP32(str, reloc) { str, sizeof (str) - 1, 1, 0, reloc }
1530 #define MAP64(str, reloc) { str, sizeof (str) - 1, 0, 1, reloc }
1531
1532 static const struct map_bfd mapping[] = {
1533 MAP ("l", BFD_RELOC_LO16),
1534 MAP ("h", BFD_RELOC_HI16),
1535 MAP ("ha", BFD_RELOC_HI16_S),
1536 MAP ("brtaken", BFD_RELOC_PPC_B16_BRTAKEN),
1537 MAP ("brntaken", BFD_RELOC_PPC_B16_BRNTAKEN),
1538 MAP ("got", BFD_RELOC_16_GOTOFF),
1539 MAP ("got@l", BFD_RELOC_LO16_GOTOFF),
1540 MAP ("got@h", BFD_RELOC_HI16_GOTOFF),
1541 MAP ("got@ha", BFD_RELOC_HI16_S_GOTOFF),
1542 MAP ("plt@l", BFD_RELOC_LO16_PLTOFF),
1543 MAP ("plt@h", BFD_RELOC_HI16_PLTOFF),
1544 MAP ("plt@ha", BFD_RELOC_HI16_S_PLTOFF),
1545 MAP ("copy", BFD_RELOC_PPC_COPY),
1546 MAP ("globdat", BFD_RELOC_PPC_GLOB_DAT),
1547 MAP ("sectoff", BFD_RELOC_16_BASEREL),
1548 MAP ("sectoff@l", BFD_RELOC_LO16_BASEREL),
1549 MAP ("sectoff@h", BFD_RELOC_HI16_BASEREL),
1550 MAP ("sectoff@ha", BFD_RELOC_HI16_S_BASEREL),
1551 MAP ("tls", BFD_RELOC_PPC_TLS),
1552 MAP ("dtpmod", BFD_RELOC_PPC_DTPMOD),
1553 MAP ("dtprel", BFD_RELOC_PPC_DTPREL),
1554 MAP ("dtprel@l", BFD_RELOC_PPC_DTPREL16_LO),
1555 MAP ("dtprel@h", BFD_RELOC_PPC_DTPREL16_HI),
1556 MAP ("dtprel@ha", BFD_RELOC_PPC_DTPREL16_HA),
1557 MAP ("tprel", BFD_RELOC_PPC_TPREL),
1558 MAP ("tprel@l", BFD_RELOC_PPC_TPREL16_LO),
1559 MAP ("tprel@h", BFD_RELOC_PPC_TPREL16_HI),
1560 MAP ("tprel@ha", BFD_RELOC_PPC_TPREL16_HA),
1561 MAP ("got@tlsgd", BFD_RELOC_PPC_GOT_TLSGD16),
1562 MAP ("got@tlsgd@l", BFD_RELOC_PPC_GOT_TLSGD16_LO),
1563 MAP ("got@tlsgd@h", BFD_RELOC_PPC_GOT_TLSGD16_HI),
1564 MAP ("got@tlsgd@ha", BFD_RELOC_PPC_GOT_TLSGD16_HA),
1565 MAP ("got@tlsld", BFD_RELOC_PPC_GOT_TLSLD16),
1566 MAP ("got@tlsld@l", BFD_RELOC_PPC_GOT_TLSLD16_LO),
1567 MAP ("got@tlsld@h", BFD_RELOC_PPC_GOT_TLSLD16_HI),
1568 MAP ("got@tlsld@ha", BFD_RELOC_PPC_GOT_TLSLD16_HA),
1569 MAP ("got@dtprel", BFD_RELOC_PPC_GOT_DTPREL16),
1570 MAP ("got@dtprel@l", BFD_RELOC_PPC_GOT_DTPREL16_LO),
1571 MAP ("got@dtprel@h", BFD_RELOC_PPC_GOT_DTPREL16_HI),
1572 MAP ("got@dtprel@ha", BFD_RELOC_PPC_GOT_DTPREL16_HA),
1573 MAP ("got@tprel", BFD_RELOC_PPC_GOT_TPREL16),
1574 MAP ("got@tprel@l", BFD_RELOC_PPC_GOT_TPREL16_LO),
1575 MAP ("got@tprel@h", BFD_RELOC_PPC_GOT_TPREL16_HI),
1576 MAP ("got@tprel@ha", BFD_RELOC_PPC_GOT_TPREL16_HA),
1577 MAP32 ("fixup", BFD_RELOC_CTOR),
1578 MAP32 ("plt", BFD_RELOC_24_PLT_PCREL),
1579 MAP32 ("pltrel24", BFD_RELOC_24_PLT_PCREL),
1580 MAP32 ("local24pc", BFD_RELOC_PPC_LOCAL24PC),
1581 MAP32 ("local", BFD_RELOC_PPC_LOCAL24PC),
1582 MAP32 ("pltrel", BFD_RELOC_32_PLT_PCREL),
1583 MAP32 ("sdarel", BFD_RELOC_GPREL16),
1584 MAP32 ("naddr", BFD_RELOC_PPC_EMB_NADDR32),
1585 MAP32 ("naddr16", BFD_RELOC_PPC_EMB_NADDR16),
1586 MAP32 ("naddr@l", BFD_RELOC_PPC_EMB_NADDR16_LO),
1587 MAP32 ("naddr@h", BFD_RELOC_PPC_EMB_NADDR16_HI),
1588 MAP32 ("naddr@ha", BFD_RELOC_PPC_EMB_NADDR16_HA),
1589 MAP32 ("sdai16", BFD_RELOC_PPC_EMB_SDAI16),
1590 MAP32 ("sda2rel", BFD_RELOC_PPC_EMB_SDA2REL),
1591 MAP32 ("sda2i16", BFD_RELOC_PPC_EMB_SDA2I16),
1592 MAP32 ("sda21", BFD_RELOC_PPC_EMB_SDA21),
1593 MAP32 ("mrkref", BFD_RELOC_PPC_EMB_MRKREF),
1594 MAP32 ("relsect", BFD_RELOC_PPC_EMB_RELSEC16),
1595 MAP32 ("relsect@l", BFD_RELOC_PPC_EMB_RELST_LO),
1596 MAP32 ("relsect@h", BFD_RELOC_PPC_EMB_RELST_HI),
1597 MAP32 ("relsect@ha", BFD_RELOC_PPC_EMB_RELST_HA),
1598 MAP32 ("bitfld", BFD_RELOC_PPC_EMB_BIT_FLD),
1599 MAP32 ("relsda", BFD_RELOC_PPC_EMB_RELSDA),
1600 MAP32 ("xgot", BFD_RELOC_PPC_TOC16),
1601 MAP64 ("higher", BFD_RELOC_PPC64_HIGHER),
1602 MAP64 ("highera", BFD_RELOC_PPC64_HIGHER_S),
1603 MAP64 ("highest", BFD_RELOC_PPC64_HIGHEST),
1604 MAP64 ("highesta", BFD_RELOC_PPC64_HIGHEST_S),
1605 MAP64 ("tocbase", BFD_RELOC_PPC64_TOC),
1606 MAP64 ("toc", BFD_RELOC_PPC_TOC16),
1607 MAP64 ("toc@l", BFD_RELOC_PPC64_TOC16_LO),
1608 MAP64 ("toc@h", BFD_RELOC_PPC64_TOC16_HI),
1609 MAP64 ("toc@ha", BFD_RELOC_PPC64_TOC16_HA),
1610 MAP64 ("dtprel@higher", BFD_RELOC_PPC64_DTPREL16_HIGHER),
1611 MAP64 ("dtprel@highera", BFD_RELOC_PPC64_DTPREL16_HIGHERA),
1612 MAP64 ("dtprel@highest", BFD_RELOC_PPC64_DTPREL16_HIGHEST),
1613 MAP64 ("dtprel@highesta", BFD_RELOC_PPC64_DTPREL16_HIGHESTA),
1614 MAP64 ("tprel@higher", BFD_RELOC_PPC64_TPREL16_HIGHER),
1615 MAP64 ("tprel@highera", BFD_RELOC_PPC64_TPREL16_HIGHERA),
1616 MAP64 ("tprel@highest", BFD_RELOC_PPC64_TPREL16_HIGHEST),
1617 MAP64 ("tprel@highesta", BFD_RELOC_PPC64_TPREL16_HIGHESTA),
1618 { (char *) 0, 0, 0, 0, BFD_RELOC_UNUSED }
1619 };
1620
1621 if (*str++ != '@')
1622 return BFD_RELOC_UNUSED;
1623
1624 for (ch = *str, str2 = ident;
1625 (str2 < ident + sizeof (ident) - 1
1626 && (ISALNUM (ch) || ch == '@'));
1627 ch = *++str)
1628 {
1629 *str2++ = TOLOWER (ch);
1630 }
1631
1632 *str2 = '\0';
1633 len = str2 - ident;
1634
1635 ch = ident[0];
1636 for (ptr = &mapping[0]; ptr->length > 0; ptr++)
1637 if (ch == ptr->string[0]
1638 && len == ptr->length
1639 && memcmp (ident, ptr->string, ptr->length) == 0
1640 && (ppc_obj64 ? ptr->valid64 : ptr->valid32))
1641 {
1642 int reloc = ptr->reloc;
1643
1644 if (!ppc_obj64)
1645 if (exp_p->X_add_number != 0
1646 && (reloc == (int) BFD_RELOC_16_GOTOFF
1647 || reloc == (int) BFD_RELOC_LO16_GOTOFF
1648 || reloc == (int) BFD_RELOC_HI16_GOTOFF
1649 || reloc == (int) BFD_RELOC_HI16_S_GOTOFF))
1650 as_warn (_("identifier+constant@got means identifier@got+constant"));
1651
1652 /* Now check for identifier@suffix+constant. */
1653 if (*str == '-' || *str == '+')
1654 {
1655 char *orig_line = input_line_pointer;
1656 expressionS new_exp;
1657
1658 input_line_pointer = str;
1659 expression (&new_exp);
1660 if (new_exp.X_op == O_constant)
1661 {
1662 exp_p->X_add_number += new_exp.X_add_number;
1663 str = input_line_pointer;
1664 }
1665
1666 if (&input_line_pointer != str_p)
1667 input_line_pointer = orig_line;
1668 }
1669 *str_p = str;
1670
1671 if (reloc == (int) BFD_RELOC_PPC64_TOC
1672 && exp_p->X_op == O_symbol
1673 && strcmp (S_GET_NAME (exp_p->X_add_symbol), ".TOC.") == 0)
1674 {
1675 /* Change the symbol so that the dummy .TOC. symbol can be
1676 omitted from the object file. */
1677 exp_p->X_add_symbol = &abs_symbol;
1678 }
1679
1680 return (bfd_reloc_code_real_type) reloc;
1681 }
1682
1683 return BFD_RELOC_UNUSED;
1684 }
1685
1686 /* Like normal .long/.short/.word, except support @got, etc.
1687 Clobbers input_line_pointer, checks end-of-line. */
1688 static void
1689 ppc_elf_cons (nbytes)
1690 register int nbytes; /* 1=.byte, 2=.word, 4=.long, 8=.llong. */
1691 {
1692 expressionS exp;
1693 bfd_reloc_code_real_type reloc;
1694
1695 if (is_it_end_of_statement ())
1696 {
1697 demand_empty_rest_of_line ();
1698 return;
1699 }
1700
1701 do
1702 {
1703 expression (&exp);
1704 if (exp.X_op == O_symbol
1705 && *input_line_pointer == '@'
1706 && (reloc = ppc_elf_suffix (&input_line_pointer,
1707 &exp)) != BFD_RELOC_UNUSED)
1708 {
1709 reloc_howto_type *reloc_howto;
1710 int size;
1711
1712 reloc_howto = bfd_reloc_type_lookup (stdoutput, reloc);
1713 size = bfd_get_reloc_size (reloc_howto);
1714
1715 if (size > nbytes)
1716 {
1717 as_bad (_("%s relocations do not fit in %d bytes\n"),
1718 reloc_howto->name, nbytes);
1719 }
1720 else
1721 {
1722 char *p;
1723 int offset;
1724
1725 p = frag_more (nbytes);
1726 offset = 0;
1727 if (target_big_endian)
1728 offset = nbytes - size;
1729 fix_new_exp (frag_now, p - frag_now->fr_literal + offset, size,
1730 &exp, 0, reloc);
1731 }
1732 }
1733 else
1734 emit_expr (&exp, (unsigned int) nbytes);
1735 }
1736 while (*input_line_pointer++ == ',');
1737
1738 /* Put terminator back into stream. */
1739 input_line_pointer--;
1740 demand_empty_rest_of_line ();
1741 }
1742
1743 /* Solaris pseduo op to change to the .rodata section. */
1744 static void
1745 ppc_elf_rdata (xxx)
1746 int xxx;
1747 {
1748 char *save_line = input_line_pointer;
1749 static char section[] = ".rodata\n";
1750
1751 /* Just pretend this is .section .rodata */
1752 input_line_pointer = section;
1753 obj_elf_section (xxx);
1754
1755 input_line_pointer = save_line;
1756 }
1757
1758 /* Pseudo op to make file scope bss items. */
1759 static void
1760 ppc_elf_lcomm (xxx)
1761 int xxx ATTRIBUTE_UNUSED;
1762 {
1763 register char *name;
1764 register char c;
1765 register char *p;
1766 offsetT size;
1767 register symbolS *symbolP;
1768 offsetT align;
1769 segT old_sec;
1770 int old_subsec;
1771 char *pfrag;
1772 int align2;
1773
1774 name = input_line_pointer;
1775 c = get_symbol_end ();
1776
1777 /* just after name is now '\0'. */
1778 p = input_line_pointer;
1779 *p = c;
1780 SKIP_WHITESPACE ();
1781 if (*input_line_pointer != ',')
1782 {
1783 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
1784 ignore_rest_of_line ();
1785 return;
1786 }
1787
1788 input_line_pointer++; /* skip ',' */
1789 if ((size = get_absolute_expression ()) < 0)
1790 {
1791 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) size);
1792 ignore_rest_of_line ();
1793 return;
1794 }
1795
1796 /* The third argument to .lcomm is the alignment. */
1797 if (*input_line_pointer != ',')
1798 align = 8;
1799 else
1800 {
1801 ++input_line_pointer;
1802 align = get_absolute_expression ();
1803 if (align <= 0)
1804 {
1805 as_warn (_("ignoring bad alignment"));
1806 align = 8;
1807 }
1808 }
1809
1810 *p = 0;
1811 symbolP = symbol_find_or_make (name);
1812 *p = c;
1813
1814 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
1815 {
1816 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
1817 S_GET_NAME (symbolP));
1818 ignore_rest_of_line ();
1819 return;
1820 }
1821
1822 if (S_GET_VALUE (symbolP) && S_GET_VALUE (symbolP) != (valueT) size)
1823 {
1824 as_bad (_("Length of .lcomm \"%s\" is already %ld. Not changed to %ld."),
1825 S_GET_NAME (symbolP),
1826 (long) S_GET_VALUE (symbolP),
1827 (long) size);
1828
1829 ignore_rest_of_line ();
1830 return;
1831 }
1832
1833 /* Allocate_bss. */
1834 old_sec = now_seg;
1835 old_subsec = now_subseg;
1836 if (align)
1837 {
1838 /* Convert to a power of 2 alignment. */
1839 for (align2 = 0; (align & 1) == 0; align >>= 1, ++align2);
1840 if (align != 1)
1841 {
1842 as_bad (_("Common alignment not a power of 2"));
1843 ignore_rest_of_line ();
1844 return;
1845 }
1846 }
1847 else
1848 align2 = 0;
1849
1850 record_alignment (bss_section, align2);
1851 subseg_set (bss_section, 0);
1852 if (align2)
1853 frag_align (align2, 0, 0);
1854 if (S_GET_SEGMENT (symbolP) == bss_section)
1855 symbol_get_frag (symbolP)->fr_symbol = 0;
1856 symbol_set_frag (symbolP, frag_now);
1857 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP, size,
1858 (char *) 0);
1859 *pfrag = 0;
1860 S_SET_SIZE (symbolP, size);
1861 S_SET_SEGMENT (symbolP, bss_section);
1862 subseg_set (old_sec, old_subsec);
1863 demand_empty_rest_of_line ();
1864 }
1865
1866 /* Validate any relocations emitted for -mrelocatable, possibly adding
1867 fixups for word relocations in writable segments, so we can adjust
1868 them at runtime. */
1869 static void
1870 ppc_elf_validate_fix (fixp, seg)
1871 fixS *fixp;
1872 segT seg;
1873 {
1874 if (fixp->fx_done || fixp->fx_pcrel)
1875 return;
1876
1877 switch (shlib)
1878 {
1879 case SHLIB_NONE:
1880 case SHLIB_PIC:
1881 return;
1882
1883 case SHLIB_MRELOCATABLE:
1884 if (fixp->fx_r_type <= BFD_RELOC_UNUSED
1885 && fixp->fx_r_type != BFD_RELOC_16_GOTOFF
1886 && fixp->fx_r_type != BFD_RELOC_HI16_GOTOFF
1887 && fixp->fx_r_type != BFD_RELOC_LO16_GOTOFF
1888 && fixp->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
1889 && fixp->fx_r_type != BFD_RELOC_16_BASEREL
1890 && fixp->fx_r_type != BFD_RELOC_LO16_BASEREL
1891 && fixp->fx_r_type != BFD_RELOC_HI16_BASEREL
1892 && fixp->fx_r_type != BFD_RELOC_HI16_S_BASEREL
1893 && (seg->flags & SEC_LOAD) != 0
1894 && strcmp (segment_name (seg), ".got2") != 0
1895 && strcmp (segment_name (seg), ".dtors") != 0
1896 && strcmp (segment_name (seg), ".ctors") != 0
1897 && strcmp (segment_name (seg), ".fixup") != 0
1898 && strcmp (segment_name (seg), ".gcc_except_table") != 0
1899 && strcmp (segment_name (seg), ".eh_frame") != 0
1900 && strcmp (segment_name (seg), ".ex_shared") != 0)
1901 {
1902 if ((seg->flags & (SEC_READONLY | SEC_CODE)) != 0
1903 || fixp->fx_r_type != BFD_RELOC_CTOR)
1904 {
1905 as_bad_where (fixp->fx_file, fixp->fx_line,
1906 _("Relocation cannot be done when using -mrelocatable"));
1907 }
1908 }
1909 return;
1910 }
1911 }
1912
1913 /* Prevent elf_frob_file_before_adjust removing a weak undefined
1914 function descriptor sym if the corresponding code sym is used. */
1915
1916 void
1917 ppc_frob_file_before_adjust ()
1918 {
1919 symbolS *symp;
1920 asection *toc;
1921
1922 if (!ppc_obj64)
1923 return;
1924
1925 for (symp = symbol_rootP; symp; symp = symbol_next (symp))
1926 {
1927 const char *name;
1928 char *dotname;
1929 symbolS *dotsym;
1930 size_t len;
1931
1932 name = S_GET_NAME (symp);
1933 if (name[0] == '.')
1934 continue;
1935
1936 if (! S_IS_WEAK (symp)
1937 || S_IS_DEFINED (symp))
1938 continue;
1939
1940 len = strlen (name) + 1;
1941 dotname = xmalloc (len + 1);
1942 dotname[0] = '.';
1943 memcpy (dotname + 1, name, len);
1944 dotsym = symbol_find_noref (dotname, 1);
1945 free (dotname);
1946 if (dotsym != NULL && (symbol_used_p (dotsym)
1947 || symbol_used_in_reloc_p (dotsym)))
1948 symbol_mark_used (symp);
1949
1950 }
1951
1952 toc = bfd_get_section_by_name (stdoutput, ".toc");
1953 if (toc != NULL
1954 && bfd_section_size (stdoutput, toc) > 0x10000)
1955 as_warn (_("TOC section size exceeds 64k"));
1956
1957 /* Don't emit .TOC. symbol. */
1958 symp = symbol_find (".TOC.");
1959 if (symp != NULL)
1960 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
1961 }
1962 #endif /* OBJ_ELF */
1963 \f
1964 #ifdef TE_PE
1965
1966 /*
1967 * Summary of parse_toc_entry.
1968 *
1969 * in: Input_line_pointer points to the '[' in one of:
1970 *
1971 * [toc] [tocv] [toc32] [toc64]
1972 *
1973 * Anything else is an error of one kind or another.
1974 *
1975 * out:
1976 * return value: success or failure
1977 * toc_kind: kind of toc reference
1978 * input_line_pointer:
1979 * success: first char after the ']'
1980 * failure: unchanged
1981 *
1982 * settings:
1983 *
1984 * [toc] - rv == success, toc_kind = default_toc
1985 * [tocv] - rv == success, toc_kind = data_in_toc
1986 * [toc32] - rv == success, toc_kind = must_be_32
1987 * [toc64] - rv == success, toc_kind = must_be_64
1988 *
1989 */
1990
1991 enum toc_size_qualifier
1992 {
1993 default_toc, /* The toc cell constructed should be the system default size */
1994 data_in_toc, /* This is a direct reference to a toc cell */
1995 must_be_32, /* The toc cell constructed must be 32 bits wide */
1996 must_be_64 /* The toc cell constructed must be 64 bits wide */
1997 };
1998
1999 static int
2000 parse_toc_entry (toc_kind)
2001 enum toc_size_qualifier *toc_kind;
2002 {
2003 char *start;
2004 char *toc_spec;
2005 char c;
2006 enum toc_size_qualifier t;
2007
2008 /* Save the input_line_pointer. */
2009 start = input_line_pointer;
2010
2011 /* Skip over the '[' , and whitespace. */
2012 ++input_line_pointer;
2013 SKIP_WHITESPACE ();
2014
2015 /* Find the spelling of the operand. */
2016 toc_spec = input_line_pointer;
2017 c = get_symbol_end ();
2018
2019 if (strcmp (toc_spec, "toc") == 0)
2020 {
2021 t = default_toc;
2022 }
2023 else if (strcmp (toc_spec, "tocv") == 0)
2024 {
2025 t = data_in_toc;
2026 }
2027 else if (strcmp (toc_spec, "toc32") == 0)
2028 {
2029 t = must_be_32;
2030 }
2031 else if (strcmp (toc_spec, "toc64") == 0)
2032 {
2033 t = must_be_64;
2034 }
2035 else
2036 {
2037 as_bad (_("syntax error: invalid toc specifier `%s'"), toc_spec);
2038 *input_line_pointer = c;
2039 input_line_pointer = start;
2040 return 0;
2041 }
2042
2043 /* Now find the ']'. */
2044 *input_line_pointer = c;
2045
2046 SKIP_WHITESPACE (); /* leading whitespace could be there. */
2047 c = *input_line_pointer++; /* input_line_pointer->past char in c. */
2048
2049 if (c != ']')
2050 {
2051 as_bad (_("syntax error: expected `]', found `%c'"), c);
2052 input_line_pointer = start;
2053 return 0;
2054 }
2055
2056 *toc_kind = t;
2057 return 1;
2058 }
2059 #endif
2060 \f
2061
2062 #ifdef OBJ_ELF
2063 #define APUID(a,v) ((((a) & 0xffff) << 16) | ((v) & 0xffff))
2064 static void
2065 ppc_apuinfo_section_add (apu, version)
2066 unsigned int apu, version;
2067 {
2068 unsigned int i;
2069
2070 /* Check we don't already exist. */
2071 for (i = 0; i < ppc_apuinfo_num; i++)
2072 if (ppc_apuinfo_list[i] == APUID (apu, version))
2073 return;
2074
2075 if (ppc_apuinfo_num == ppc_apuinfo_num_alloc)
2076 {
2077 if (ppc_apuinfo_num_alloc == 0)
2078 {
2079 ppc_apuinfo_num_alloc = 4;
2080 ppc_apuinfo_list = (unsigned long *)
2081 xmalloc (sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2082 }
2083 else
2084 {
2085 ppc_apuinfo_num_alloc += 4;
2086 ppc_apuinfo_list = (unsigned long *) xrealloc (ppc_apuinfo_list,
2087 sizeof (unsigned long) * ppc_apuinfo_num_alloc);
2088 }
2089 }
2090 ppc_apuinfo_list[ppc_apuinfo_num++] = APUID (apu, version);
2091 }
2092 #undef APUID
2093 #endif
2094 \f
2095
2096 /* We need to keep a list of fixups. We can't simply generate them as
2097 we go, because that would require us to first create the frag, and
2098 that would screw up references to ``.''. */
2099
2100 struct ppc_fixup
2101 {
2102 expressionS exp;
2103 int opindex;
2104 bfd_reloc_code_real_type reloc;
2105 };
2106
2107 #define MAX_INSN_FIXUPS (5)
2108
2109 /* This routine is called for each instruction to be assembled. */
2110
2111 void
2112 md_assemble (str)
2113 char *str;
2114 {
2115 char *s;
2116 const struct powerpc_opcode *opcode;
2117 unsigned long insn;
2118 const unsigned char *opindex_ptr;
2119 int skip_optional;
2120 int need_paren;
2121 int next_opindex;
2122 struct ppc_fixup fixups[MAX_INSN_FIXUPS];
2123 int fc;
2124 char *f;
2125 int addr_mod;
2126 int i;
2127 #ifdef OBJ_ELF
2128 bfd_reloc_code_real_type reloc;
2129 #endif
2130
2131 /* Get the opcode. */
2132 for (s = str; *s != '\0' && ! ISSPACE (*s); s++)
2133 ;
2134 if (*s != '\0')
2135 *s++ = '\0';
2136
2137 /* Look up the opcode in the hash table. */
2138 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, str);
2139 if (opcode == (const struct powerpc_opcode *) NULL)
2140 {
2141 const struct powerpc_macro *macro;
2142
2143 macro = (const struct powerpc_macro *) hash_find (ppc_macro_hash, str);
2144 if (macro == (const struct powerpc_macro *) NULL)
2145 as_bad (_("Unrecognized opcode: `%s'"), str);
2146 else
2147 ppc_macro (s, macro);
2148
2149 return;
2150 }
2151
2152 insn = opcode->opcode;
2153
2154 str = s;
2155 while (ISSPACE (*str))
2156 ++str;
2157
2158 /* PowerPC operands are just expressions. The only real issue is
2159 that a few operand types are optional. All cases which might use
2160 an optional operand separate the operands only with commas (in some
2161 cases parentheses are used, as in ``lwz 1,0(1)'' but such cases never
2162 have optional operands). Most instructions with optional operands
2163 have only one. Those that have more than one optional operand can
2164 take either all their operands or none. So, before we start seriously
2165 parsing the operands, we check to see if we have optional operands,
2166 and if we do, we count the number of commas to see which operands
2167 have been omitted. */
2168 skip_optional = 0;
2169 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2170 {
2171 const struct powerpc_operand *operand;
2172
2173 operand = &powerpc_operands[*opindex_ptr];
2174 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0)
2175 {
2176 unsigned int opcount;
2177 unsigned int num_operands_expected;
2178 unsigned int i;
2179
2180 /* There is an optional operand. Count the number of
2181 commas in the input line. */
2182 if (*str == '\0')
2183 opcount = 0;
2184 else
2185 {
2186 opcount = 1;
2187 s = str;
2188 while ((s = strchr (s, ',')) != (char *) NULL)
2189 {
2190 ++opcount;
2191 ++s;
2192 }
2193 }
2194
2195 /* Compute the number of expected operands.
2196 Do not count fake operands. */
2197 for (num_operands_expected = 0, i = 0; opcode->operands[i]; i ++)
2198 if ((powerpc_operands [opcode->operands[i]].flags & PPC_OPERAND_FAKE) == 0)
2199 ++ num_operands_expected;
2200
2201 /* If there are fewer operands in the line then are called
2202 for by the instruction, we want to skip the optional
2203 operands. */
2204 if (opcount < num_operands_expected)
2205 skip_optional = 1;
2206
2207 break;
2208 }
2209 }
2210
2211 /* Gather the operands. */
2212 need_paren = 0;
2213 next_opindex = 0;
2214 fc = 0;
2215 for (opindex_ptr = opcode->operands; *opindex_ptr != 0; opindex_ptr++)
2216 {
2217 const struct powerpc_operand *operand;
2218 const char *errmsg;
2219 char *hold;
2220 expressionS ex;
2221 char endc;
2222
2223 if (next_opindex == 0)
2224 operand = &powerpc_operands[*opindex_ptr];
2225 else
2226 {
2227 operand = &powerpc_operands[next_opindex];
2228 next_opindex = 0;
2229 }
2230 errmsg = NULL;
2231
2232 /* If this is a fake operand, then we do not expect anything
2233 from the input. */
2234 if ((operand->flags & PPC_OPERAND_FAKE) != 0)
2235 {
2236 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2237 if (errmsg != (const char *) NULL)
2238 as_bad (errmsg);
2239 continue;
2240 }
2241
2242 /* If this is an optional operand, and we are skipping it, just
2243 insert a zero. */
2244 if ((operand->flags & PPC_OPERAND_OPTIONAL) != 0
2245 && skip_optional)
2246 {
2247 if (operand->insert)
2248 {
2249 insn = (*operand->insert) (insn, 0L, ppc_cpu, &errmsg);
2250 if (errmsg != (const char *) NULL)
2251 as_bad (errmsg);
2252 }
2253 if ((operand->flags & PPC_OPERAND_NEXT) != 0)
2254 next_opindex = *opindex_ptr + 1;
2255 continue;
2256 }
2257
2258 /* Gather the operand. */
2259 hold = input_line_pointer;
2260 input_line_pointer = str;
2261
2262 #ifdef TE_PE
2263 if (*input_line_pointer == '[')
2264 {
2265 /* We are expecting something like the second argument here:
2266 *
2267 * lwz r4,[toc].GS.0.static_int(rtoc)
2268 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2269 * The argument following the `]' must be a symbol name, and the
2270 * register must be the toc register: 'rtoc' or '2'
2271 *
2272 * The effect is to 0 as the displacement field
2273 * in the instruction, and issue an IMAGE_REL_PPC_TOCREL16 (or
2274 * the appropriate variation) reloc against it based on the symbol.
2275 * The linker will build the toc, and insert the resolved toc offset.
2276 *
2277 * Note:
2278 * o The size of the toc entry is currently assumed to be
2279 * 32 bits. This should not be assumed to be a hard coded
2280 * number.
2281 * o In an effort to cope with a change from 32 to 64 bits,
2282 * there are also toc entries that are specified to be
2283 * either 32 or 64 bits:
2284 * lwz r4,[toc32].GS.0.static_int(rtoc)
2285 * lwz r4,[toc64].GS.0.static_int(rtoc)
2286 * These demand toc entries of the specified size, and the
2287 * instruction probably requires it.
2288 */
2289
2290 int valid_toc;
2291 enum toc_size_qualifier toc_kind;
2292 bfd_reloc_code_real_type toc_reloc;
2293
2294 /* Go parse off the [tocXX] part. */
2295 valid_toc = parse_toc_entry (&toc_kind);
2296
2297 if (!valid_toc)
2298 {
2299 /* Note: message has already been issued.
2300 FIXME: what sort of recovery should we do?
2301 demand_rest_of_line (); return; ? */
2302 }
2303
2304 /* Now get the symbol following the ']'. */
2305 expression (&ex);
2306
2307 switch (toc_kind)
2308 {
2309 case default_toc:
2310 /* In this case, we may not have seen the symbol yet,
2311 since it is allowed to appear on a .extern or .globl
2312 or just be a label in the .data section. */
2313 toc_reloc = BFD_RELOC_PPC_TOC16;
2314 break;
2315 case data_in_toc:
2316 /* 1. The symbol must be defined and either in the toc
2317 section, or a global.
2318 2. The reloc generated must have the TOCDEFN flag set
2319 in upper bit mess of the reloc type.
2320 FIXME: It's a little confusing what the tocv
2321 qualifier can be used for. At the very least, I've
2322 seen three uses, only one of which I'm sure I can
2323 explain. */
2324 if (ex.X_op == O_symbol)
2325 {
2326 assert (ex.X_add_symbol != NULL);
2327 if (symbol_get_bfdsym (ex.X_add_symbol)->section
2328 != tocdata_section)
2329 {
2330 as_bad (_("[tocv] symbol is not a toc symbol"));
2331 }
2332 }
2333
2334 toc_reloc = BFD_RELOC_PPC_TOC16;
2335 break;
2336 case must_be_32:
2337 /* FIXME: these next two specifically specify 32/64 bit
2338 toc entries. We don't support them today. Is this
2339 the right way to say that? */
2340 toc_reloc = BFD_RELOC_UNUSED;
2341 as_bad (_("Unimplemented toc32 expression modifier"));
2342 break;
2343 case must_be_64:
2344 /* FIXME: see above. */
2345 toc_reloc = BFD_RELOC_UNUSED;
2346 as_bad (_("Unimplemented toc64 expression modifier"));
2347 break;
2348 default:
2349 fprintf (stderr,
2350 _("Unexpected return value [%d] from parse_toc_entry!\n"),
2351 toc_kind);
2352 abort ();
2353 break;
2354 }
2355
2356 /* We need to generate a fixup for this expression. */
2357 if (fc >= MAX_INSN_FIXUPS)
2358 as_fatal (_("too many fixups"));
2359
2360 fixups[fc].reloc = toc_reloc;
2361 fixups[fc].exp = ex;
2362 fixups[fc].opindex = *opindex_ptr;
2363 ++fc;
2364
2365 /* Ok. We've set up the fixup for the instruction. Now make it
2366 look like the constant 0 was found here. */
2367 ex.X_unsigned = 1;
2368 ex.X_op = O_constant;
2369 ex.X_add_number = 0;
2370 ex.X_add_symbol = NULL;
2371 ex.X_op_symbol = NULL;
2372 }
2373
2374 else
2375 #endif /* TE_PE */
2376 {
2377 if (! register_name (&ex))
2378 {
2379 if ((operand->flags & PPC_OPERAND_CR) != 0)
2380 cr_operand = TRUE;
2381 expression (&ex);
2382 cr_operand = FALSE;
2383 }
2384 }
2385
2386 str = input_line_pointer;
2387 input_line_pointer = hold;
2388
2389 if (ex.X_op == O_illegal)
2390 as_bad (_("illegal operand"));
2391 else if (ex.X_op == O_absent)
2392 as_bad (_("missing operand"));
2393 else if (ex.X_op == O_register)
2394 {
2395 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2396 (char *) NULL, 0);
2397 }
2398 else if (ex.X_op == O_constant)
2399 {
2400 #ifdef OBJ_ELF
2401 /* Allow @HA, @L, @H on constants. */
2402 char *orig_str = str;
2403
2404 if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2405 switch (reloc)
2406 {
2407 default:
2408 str = orig_str;
2409 break;
2410
2411 case BFD_RELOC_LO16:
2412 /* X_unsigned is the default, so if the user has done
2413 something which cleared it, we always produce a
2414 signed value. */
2415 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2416 ex.X_add_number &= 0xffff;
2417 else
2418 ex.X_add_number = SEX16 (ex.X_add_number);
2419 break;
2420
2421 case BFD_RELOC_HI16:
2422 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2423 ex.X_add_number = PPC_HI (ex.X_add_number);
2424 else
2425 ex.X_add_number = SEX16 (PPC_HI (ex.X_add_number));
2426 break;
2427
2428 case BFD_RELOC_HI16_S:
2429 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2430 ex.X_add_number = PPC_HA (ex.X_add_number);
2431 else
2432 ex.X_add_number = SEX16 (PPC_HA (ex.X_add_number));
2433 break;
2434
2435 case BFD_RELOC_PPC64_HIGHER:
2436 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2437 ex.X_add_number = PPC_HIGHER (ex.X_add_number);
2438 else
2439 ex.X_add_number = SEX16 (PPC_HIGHER (ex.X_add_number));
2440 break;
2441
2442 case BFD_RELOC_PPC64_HIGHER_S:
2443 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2444 ex.X_add_number = PPC_HIGHERA (ex.X_add_number);
2445 else
2446 ex.X_add_number = SEX16 (PPC_HIGHERA (ex.X_add_number));
2447 break;
2448
2449 case BFD_RELOC_PPC64_HIGHEST:
2450 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2451 ex.X_add_number = PPC_HIGHEST (ex.X_add_number);
2452 else
2453 ex.X_add_number = SEX16 (PPC_HIGHEST (ex.X_add_number));
2454 break;
2455
2456 case BFD_RELOC_PPC64_HIGHEST_S:
2457 if (ex.X_unsigned && ! (operand->flags & PPC_OPERAND_SIGNED))
2458 ex.X_add_number = PPC_HIGHESTA (ex.X_add_number);
2459 else
2460 ex.X_add_number = SEX16 (PPC_HIGHESTA (ex.X_add_number));
2461 break;
2462 }
2463 #endif /* OBJ_ELF */
2464 insn = ppc_insert_operand (insn, operand, ex.X_add_number,
2465 (char *) NULL, 0);
2466 }
2467 #ifdef OBJ_ELF
2468 else if ((reloc = ppc_elf_suffix (&str, &ex)) != BFD_RELOC_UNUSED)
2469 {
2470 /* Some TLS tweaks. */
2471 switch (reloc)
2472 {
2473 default:
2474 break;
2475 case BFD_RELOC_PPC_TLS:
2476 insn = ppc_insert_operand (insn, operand, ppc_obj64 ? 13 : 2,
2477 (char *) NULL, 0);
2478 break;
2479 /* We'll only use the 32 (or 64) bit form of these relocations
2480 in constants. Instructions get the 16 bit form. */
2481 case BFD_RELOC_PPC_DTPREL:
2482 reloc = BFD_RELOC_PPC_DTPREL16;
2483 break;
2484 case BFD_RELOC_PPC_TPREL:
2485 reloc = BFD_RELOC_PPC_TPREL16;
2486 break;
2487 }
2488
2489 /* For the absolute forms of branches, convert the PC
2490 relative form back into the absolute. */
2491 if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0)
2492 {
2493 switch (reloc)
2494 {
2495 case BFD_RELOC_PPC_B26:
2496 reloc = BFD_RELOC_PPC_BA26;
2497 break;
2498 case BFD_RELOC_PPC_B16:
2499 reloc = BFD_RELOC_PPC_BA16;
2500 break;
2501 case BFD_RELOC_PPC_B16_BRTAKEN:
2502 reloc = BFD_RELOC_PPC_BA16_BRTAKEN;
2503 break;
2504 case BFD_RELOC_PPC_B16_BRNTAKEN:
2505 reloc = BFD_RELOC_PPC_BA16_BRNTAKEN;
2506 break;
2507 default:
2508 break;
2509 }
2510 }
2511
2512 if (ppc_obj64
2513 && (operand->flags & (PPC_OPERAND_DS | PPC_OPERAND_DQ)) != 0)
2514 {
2515 switch (reloc)
2516 {
2517 case BFD_RELOC_16:
2518 reloc = BFD_RELOC_PPC64_ADDR16_DS;
2519 break;
2520 case BFD_RELOC_LO16:
2521 reloc = BFD_RELOC_PPC64_ADDR16_LO_DS;
2522 break;
2523 case BFD_RELOC_16_GOTOFF:
2524 reloc = BFD_RELOC_PPC64_GOT16_DS;
2525 break;
2526 case BFD_RELOC_LO16_GOTOFF:
2527 reloc = BFD_RELOC_PPC64_GOT16_LO_DS;
2528 break;
2529 case BFD_RELOC_LO16_PLTOFF:
2530 reloc = BFD_RELOC_PPC64_PLT16_LO_DS;
2531 break;
2532 case BFD_RELOC_16_BASEREL:
2533 reloc = BFD_RELOC_PPC64_SECTOFF_DS;
2534 break;
2535 case BFD_RELOC_LO16_BASEREL:
2536 reloc = BFD_RELOC_PPC64_SECTOFF_LO_DS;
2537 break;
2538 case BFD_RELOC_PPC_TOC16:
2539 reloc = BFD_RELOC_PPC64_TOC16_DS;
2540 break;
2541 case BFD_RELOC_PPC64_TOC16_LO:
2542 reloc = BFD_RELOC_PPC64_TOC16_LO_DS;
2543 break;
2544 case BFD_RELOC_PPC64_PLTGOT16:
2545 reloc = BFD_RELOC_PPC64_PLTGOT16_DS;
2546 break;
2547 case BFD_RELOC_PPC64_PLTGOT16_LO:
2548 reloc = BFD_RELOC_PPC64_PLTGOT16_LO_DS;
2549 break;
2550 case BFD_RELOC_PPC_DTPREL16:
2551 reloc = BFD_RELOC_PPC64_DTPREL16_DS;
2552 break;
2553 case BFD_RELOC_PPC_DTPREL16_LO:
2554 reloc = BFD_RELOC_PPC64_DTPREL16_LO_DS;
2555 break;
2556 case BFD_RELOC_PPC_TPREL16:
2557 reloc = BFD_RELOC_PPC64_TPREL16_DS;
2558 break;
2559 case BFD_RELOC_PPC_TPREL16_LO:
2560 reloc = BFD_RELOC_PPC64_TPREL16_LO_DS;
2561 break;
2562 case BFD_RELOC_PPC_GOT_DTPREL16:
2563 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
2564 case BFD_RELOC_PPC_GOT_TPREL16:
2565 case BFD_RELOC_PPC_GOT_TPREL16_LO:
2566 break;
2567 default:
2568 as_bad (_("unsupported relocation for DS offset field"));
2569 break;
2570 }
2571 }
2572
2573 /* We need to generate a fixup for this expression. */
2574 if (fc >= MAX_INSN_FIXUPS)
2575 as_fatal (_("too many fixups"));
2576 fixups[fc].exp = ex;
2577 fixups[fc].opindex = 0;
2578 fixups[fc].reloc = reloc;
2579 ++fc;
2580 }
2581 #endif /* OBJ_ELF */
2582
2583 else
2584 {
2585 /* We need to generate a fixup for this expression. */
2586 if (fc >= MAX_INSN_FIXUPS)
2587 as_fatal (_("too many fixups"));
2588 fixups[fc].exp = ex;
2589 fixups[fc].opindex = *opindex_ptr;
2590 fixups[fc].reloc = BFD_RELOC_UNUSED;
2591 ++fc;
2592 }
2593
2594 if (need_paren)
2595 {
2596 endc = ')';
2597 need_paren = 0;
2598 }
2599 else if ((operand->flags & PPC_OPERAND_PARENS) != 0)
2600 {
2601 endc = '(';
2602 need_paren = 1;
2603 }
2604 else
2605 endc = ',';
2606
2607 /* The call to expression should have advanced str past any
2608 whitespace. */
2609 if (*str != endc
2610 && (endc != ',' || *str != '\0'))
2611 {
2612 as_bad (_("syntax error; found `%c' but expected `%c'"), *str, endc);
2613 break;
2614 }
2615
2616 if (*str != '\0')
2617 ++str;
2618 }
2619
2620 while (ISSPACE (*str))
2621 ++str;
2622
2623 if (*str != '\0')
2624 as_bad (_("junk at end of line: `%s'"), str);
2625
2626 #ifdef OBJ_ELF
2627 /* Do we need/want a APUinfo section? */
2628 if (ppc_cpu & (PPC_OPCODE_SPE
2629 | PPC_OPCODE_ISEL | PPC_OPCODE_EFS
2630 | PPC_OPCODE_BRLOCK | PPC_OPCODE_PMR | PPC_OPCODE_CACHELCK
2631 | PPC_OPCODE_RFMCI))
2632 {
2633 /* These are all version "1". */
2634 if (opcode->flags & PPC_OPCODE_SPE)
2635 ppc_apuinfo_section_add (PPC_APUINFO_SPE, 1);
2636 if (opcode->flags & PPC_OPCODE_ISEL)
2637 ppc_apuinfo_section_add (PPC_APUINFO_ISEL, 1);
2638 if (opcode->flags & PPC_OPCODE_EFS)
2639 ppc_apuinfo_section_add (PPC_APUINFO_EFS, 1);
2640 if (opcode->flags & PPC_OPCODE_BRLOCK)
2641 ppc_apuinfo_section_add (PPC_APUINFO_BRLOCK, 1);
2642 if (opcode->flags & PPC_OPCODE_PMR)
2643 ppc_apuinfo_section_add (PPC_APUINFO_PMR, 1);
2644 if (opcode->flags & PPC_OPCODE_CACHELCK)
2645 ppc_apuinfo_section_add (PPC_APUINFO_CACHELCK, 1);
2646 if (opcode->flags & PPC_OPCODE_RFMCI)
2647 ppc_apuinfo_section_add (PPC_APUINFO_RFMCI, 1);
2648 }
2649 #endif
2650
2651 /* Write out the instruction. */
2652 f = frag_more (4);
2653 addr_mod = frag_now_fix () & 3;
2654 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
2655 as_bad (_("instruction address is not a multiple of 4"));
2656 frag_now->insn_addr = addr_mod;
2657 frag_now->has_code = 1;
2658 md_number_to_chars (f, insn, 4);
2659
2660 #ifdef OBJ_ELF
2661 dwarf2_emit_insn (4);
2662 #endif
2663
2664 /* Create any fixups. At this point we do not use a
2665 bfd_reloc_code_real_type, but instead just use the
2666 BFD_RELOC_UNUSED plus the operand index. This lets us easily
2667 handle fixups for any operand type, although that is admittedly
2668 not a very exciting feature. We pick a BFD reloc type in
2669 md_apply_fix. */
2670 for (i = 0; i < fc; i++)
2671 {
2672 const struct powerpc_operand *operand;
2673
2674 operand = &powerpc_operands[fixups[i].opindex];
2675 if (fixups[i].reloc != BFD_RELOC_UNUSED)
2676 {
2677 reloc_howto_type *reloc_howto;
2678 int size;
2679 int offset;
2680 fixS *fixP;
2681
2682 reloc_howto = bfd_reloc_type_lookup (stdoutput, fixups[i].reloc);
2683 if (!reloc_howto)
2684 abort ();
2685
2686 size = bfd_get_reloc_size (reloc_howto);
2687 offset = target_big_endian ? (4 - size) : 0;
2688
2689 if (size < 1 || size > 4)
2690 abort ();
2691
2692 fixP = fix_new_exp (frag_now,
2693 f - frag_now->fr_literal + offset,
2694 size,
2695 &fixups[i].exp,
2696 reloc_howto->pc_relative,
2697 fixups[i].reloc);
2698
2699 /* Turn off complaints that the addend is too large for things like
2700 foo+100000@ha. */
2701 switch (fixups[i].reloc)
2702 {
2703 case BFD_RELOC_16_GOTOFF:
2704 case BFD_RELOC_PPC_TOC16:
2705 case BFD_RELOC_LO16:
2706 case BFD_RELOC_HI16:
2707 case BFD_RELOC_HI16_S:
2708 #ifdef OBJ_ELF
2709 case BFD_RELOC_PPC64_HIGHER:
2710 case BFD_RELOC_PPC64_HIGHER_S:
2711 case BFD_RELOC_PPC64_HIGHEST:
2712 case BFD_RELOC_PPC64_HIGHEST_S:
2713 #endif
2714 fixP->fx_no_overflow = 1;
2715 break;
2716 default:
2717 break;
2718 }
2719 }
2720 else
2721 fix_new_exp (frag_now,
2722 f - frag_now->fr_literal,
2723 4,
2724 &fixups[i].exp,
2725 (operand->flags & PPC_OPERAND_RELATIVE) != 0,
2726 ((bfd_reloc_code_real_type)
2727 (fixups[i].opindex + (int) BFD_RELOC_UNUSED)));
2728 }
2729 }
2730
2731 /* Handle a macro. Gather all the operands, transform them as
2732 described by the macro, and call md_assemble recursively. All the
2733 operands are separated by commas; we don't accept parentheses
2734 around operands here. */
2735
2736 static void
2737 ppc_macro (str, macro)
2738 char *str;
2739 const struct powerpc_macro *macro;
2740 {
2741 char *operands[10];
2742 unsigned int count;
2743 char *s;
2744 unsigned int len;
2745 const char *format;
2746 int arg;
2747 char *send;
2748 char *complete;
2749
2750 /* Gather the users operands into the operands array. */
2751 count = 0;
2752 s = str;
2753 while (1)
2754 {
2755 if (count >= sizeof operands / sizeof operands[0])
2756 break;
2757 operands[count++] = s;
2758 s = strchr (s, ',');
2759 if (s == (char *) NULL)
2760 break;
2761 *s++ = '\0';
2762 }
2763
2764 if (count != macro->operands)
2765 {
2766 as_bad (_("wrong number of operands"));
2767 return;
2768 }
2769
2770 /* Work out how large the string must be (the size is unbounded
2771 because it includes user input). */
2772 len = 0;
2773 format = macro->format;
2774 while (*format != '\0')
2775 {
2776 if (*format != '%')
2777 {
2778 ++len;
2779 ++format;
2780 }
2781 else
2782 {
2783 arg = strtol (format + 1, &send, 10);
2784 know (send != format && arg >= 0 && arg < count);
2785 len += strlen (operands[arg]);
2786 format = send;
2787 }
2788 }
2789
2790 /* Put the string together. */
2791 complete = s = (char *) alloca (len + 1);
2792 format = macro->format;
2793 while (*format != '\0')
2794 {
2795 if (*format != '%')
2796 *s++ = *format++;
2797 else
2798 {
2799 arg = strtol (format + 1, &send, 10);
2800 strcpy (s, operands[arg]);
2801 s += strlen (s);
2802 format = send;
2803 }
2804 }
2805 *s = '\0';
2806
2807 /* Assemble the constructed instruction. */
2808 md_assemble (complete);
2809 }
2810 \f
2811 #ifdef OBJ_ELF
2812 /* For ELF, add support for SHF_EXCLUDE and SHT_ORDERED. */
2813
2814 int
2815 ppc_section_letter (letter, ptr_msg)
2816 int letter;
2817 char **ptr_msg;
2818 {
2819 if (letter == 'e')
2820 return SHF_EXCLUDE;
2821
2822 *ptr_msg = _("Bad .section directive: want a,e,w,x,M,S,G,T in string");
2823 return -1;
2824 }
2825
2826 int
2827 ppc_section_word (str, len)
2828 char *str;
2829 size_t len;
2830 {
2831 if (len == 7 && strncmp (str, "exclude", 7) == 0)
2832 return SHF_EXCLUDE;
2833
2834 return -1;
2835 }
2836
2837 int
2838 ppc_section_type (str, len)
2839 char *str;
2840 size_t len;
2841 {
2842 if (len == 7 && strncmp (str, "ordered", 7) == 0)
2843 return SHT_ORDERED;
2844
2845 return -1;
2846 }
2847
2848 int
2849 ppc_section_flags (flags, attr, type)
2850 int flags;
2851 int attr;
2852 int type;
2853 {
2854 if (type == SHT_ORDERED)
2855 flags |= SEC_ALLOC | SEC_LOAD | SEC_SORT_ENTRIES;
2856
2857 if (attr & SHF_EXCLUDE)
2858 flags |= SEC_EXCLUDE;
2859
2860 return flags;
2861 }
2862 #endif /* OBJ_ELF */
2863
2864 \f
2865 /* Pseudo-op handling. */
2866
2867 /* The .byte pseudo-op. This is similar to the normal .byte
2868 pseudo-op, but it can also take a single ASCII string. */
2869
2870 static void
2871 ppc_byte (ignore)
2872 int ignore ATTRIBUTE_UNUSED;
2873 {
2874 if (*input_line_pointer != '\"')
2875 {
2876 cons (1);
2877 return;
2878 }
2879
2880 /* Gather characters. A real double quote is doubled. Unusual
2881 characters are not permitted. */
2882 ++input_line_pointer;
2883 while (1)
2884 {
2885 char c;
2886
2887 c = *input_line_pointer++;
2888
2889 if (c == '\"')
2890 {
2891 if (*input_line_pointer != '\"')
2892 break;
2893 ++input_line_pointer;
2894 }
2895
2896 FRAG_APPEND_1_CHAR (c);
2897 }
2898
2899 demand_empty_rest_of_line ();
2900 }
2901 \f
2902 #ifdef OBJ_XCOFF
2903
2904 /* XCOFF specific pseudo-op handling. */
2905
2906 /* This is set if we are creating a .stabx symbol, since we don't want
2907 to handle symbol suffixes for such symbols. */
2908 static bfd_boolean ppc_stab_symbol;
2909
2910 /* The .comm and .lcomm pseudo-ops for XCOFF. XCOFF puts common
2911 symbols in the .bss segment as though they were local common
2912 symbols, and uses a different smclas. The native Aix 4.3.3 assembler
2913 aligns .comm and .lcomm to 4 bytes. */
2914
2915 static void
2916 ppc_comm (lcomm)
2917 int lcomm;
2918 {
2919 asection *current_seg = now_seg;
2920 subsegT current_subseg = now_subseg;
2921 char *name;
2922 char endc;
2923 char *end_name;
2924 offsetT size;
2925 offsetT align;
2926 symbolS *lcomm_sym = NULL;
2927 symbolS *sym;
2928 char *pfrag;
2929
2930 name = input_line_pointer;
2931 endc = get_symbol_end ();
2932 end_name = input_line_pointer;
2933 *end_name = endc;
2934
2935 if (*input_line_pointer != ',')
2936 {
2937 as_bad (_("missing size"));
2938 ignore_rest_of_line ();
2939 return;
2940 }
2941 ++input_line_pointer;
2942
2943 size = get_absolute_expression ();
2944 if (size < 0)
2945 {
2946 as_bad (_("negative size"));
2947 ignore_rest_of_line ();
2948 return;
2949 }
2950
2951 if (! lcomm)
2952 {
2953 /* The third argument to .comm is the alignment. */
2954 if (*input_line_pointer != ',')
2955 align = 2;
2956 else
2957 {
2958 ++input_line_pointer;
2959 align = get_absolute_expression ();
2960 if (align <= 0)
2961 {
2962 as_warn (_("ignoring bad alignment"));
2963 align = 2;
2964 }
2965 }
2966 }
2967 else
2968 {
2969 char *lcomm_name;
2970 char lcomm_endc;
2971
2972 if (size <= 4)
2973 align = 2;
2974 else
2975 align = 3;
2976
2977 /* The third argument to .lcomm appears to be the real local
2978 common symbol to create. References to the symbol named in
2979 the first argument are turned into references to the third
2980 argument. */
2981 if (*input_line_pointer != ',')
2982 {
2983 as_bad (_("missing real symbol name"));
2984 ignore_rest_of_line ();
2985 return;
2986 }
2987 ++input_line_pointer;
2988
2989 lcomm_name = input_line_pointer;
2990 lcomm_endc = get_symbol_end ();
2991
2992 lcomm_sym = symbol_find_or_make (lcomm_name);
2993
2994 *input_line_pointer = lcomm_endc;
2995 }
2996
2997 *end_name = '\0';
2998 sym = symbol_find_or_make (name);
2999 *end_name = endc;
3000
3001 if (S_IS_DEFINED (sym)
3002 || S_GET_VALUE (sym) != 0)
3003 {
3004 as_bad (_("attempt to redefine symbol"));
3005 ignore_rest_of_line ();
3006 return;
3007 }
3008
3009 record_alignment (bss_section, align);
3010
3011 if (! lcomm
3012 || ! S_IS_DEFINED (lcomm_sym))
3013 {
3014 symbolS *def_sym;
3015 offsetT def_size;
3016
3017 if (! lcomm)
3018 {
3019 def_sym = sym;
3020 def_size = size;
3021 S_SET_EXTERNAL (sym);
3022 }
3023 else
3024 {
3025 symbol_get_tc (lcomm_sym)->output = 1;
3026 def_sym = lcomm_sym;
3027 def_size = 0;
3028 }
3029
3030 subseg_set (bss_section, 1);
3031 frag_align (align, 0, 0);
3032
3033 symbol_set_frag (def_sym, frag_now);
3034 pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, def_sym,
3035 def_size, (char *) NULL);
3036 *pfrag = 0;
3037 S_SET_SEGMENT (def_sym, bss_section);
3038 symbol_get_tc (def_sym)->align = align;
3039 }
3040 else if (lcomm)
3041 {
3042 /* Align the size of lcomm_sym. */
3043 symbol_get_frag (lcomm_sym)->fr_offset =
3044 ((symbol_get_frag (lcomm_sym)->fr_offset + (1 << align) - 1)
3045 &~ ((1 << align) - 1));
3046 if (align > symbol_get_tc (lcomm_sym)->align)
3047 symbol_get_tc (lcomm_sym)->align = align;
3048 }
3049
3050 if (lcomm)
3051 {
3052 /* Make sym an offset from lcomm_sym. */
3053 S_SET_SEGMENT (sym, bss_section);
3054 symbol_set_frag (sym, symbol_get_frag (lcomm_sym));
3055 S_SET_VALUE (sym, symbol_get_frag (lcomm_sym)->fr_offset);
3056 symbol_get_frag (lcomm_sym)->fr_offset += size;
3057 }
3058
3059 subseg_set (current_seg, current_subseg);
3060
3061 demand_empty_rest_of_line ();
3062 }
3063
3064 /* The .csect pseudo-op. This switches us into a different
3065 subsegment. The first argument is a symbol whose value is the
3066 start of the .csect. In COFF, csect symbols get special aux
3067 entries defined by the x_csect field of union internal_auxent. The
3068 optional second argument is the alignment (the default is 2). */
3069
3070 static void
3071 ppc_csect (ignore)
3072 int ignore ATTRIBUTE_UNUSED;
3073 {
3074 char *name;
3075 char endc;
3076 symbolS *sym;
3077 offsetT align;
3078
3079 name = input_line_pointer;
3080 endc = get_symbol_end ();
3081
3082 sym = symbol_find_or_make (name);
3083
3084 *input_line_pointer = endc;
3085
3086 if (S_GET_NAME (sym)[0] == '\0')
3087 {
3088 /* An unnamed csect is assumed to be [PR]. */
3089 symbol_get_tc (sym)->class = XMC_PR;
3090 }
3091
3092 align = 2;
3093 if (*input_line_pointer == ',')
3094 {
3095 ++input_line_pointer;
3096 align = get_absolute_expression ();
3097 }
3098
3099 ppc_change_csect (sym, align);
3100
3101 demand_empty_rest_of_line ();
3102 }
3103
3104 /* Change to a different csect. */
3105
3106 static void
3107 ppc_change_csect (sym, align)
3108 symbolS *sym;
3109 offsetT align;
3110 {
3111 if (S_IS_DEFINED (sym))
3112 subseg_set (S_GET_SEGMENT (sym), symbol_get_tc (sym)->subseg);
3113 else
3114 {
3115 symbolS **list_ptr;
3116 int after_toc;
3117 int hold_chunksize;
3118 symbolS *list;
3119 int is_code;
3120 segT sec;
3121
3122 /* This is a new csect. We need to look at the symbol class to
3123 figure out whether it should go in the text section or the
3124 data section. */
3125 after_toc = 0;
3126 is_code = 0;
3127 switch (symbol_get_tc (sym)->class)
3128 {
3129 case XMC_PR:
3130 case XMC_RO:
3131 case XMC_DB:
3132 case XMC_GL:
3133 case XMC_XO:
3134 case XMC_SV:
3135 case XMC_TI:
3136 case XMC_TB:
3137 S_SET_SEGMENT (sym, text_section);
3138 symbol_get_tc (sym)->subseg = ppc_text_subsegment;
3139 ++ppc_text_subsegment;
3140 list_ptr = &ppc_text_csects;
3141 is_code = 1;
3142 break;
3143 case XMC_RW:
3144 case XMC_TC0:
3145 case XMC_TC:
3146 case XMC_DS:
3147 case XMC_UA:
3148 case XMC_BS:
3149 case XMC_UC:
3150 if (ppc_toc_csect != NULL
3151 && (symbol_get_tc (ppc_toc_csect)->subseg + 1
3152 == ppc_data_subsegment))
3153 after_toc = 1;
3154 S_SET_SEGMENT (sym, data_section);
3155 symbol_get_tc (sym)->subseg = ppc_data_subsegment;
3156 ++ppc_data_subsegment;
3157 list_ptr = &ppc_data_csects;
3158 break;
3159 default:
3160 abort ();
3161 }
3162
3163 /* We set the obstack chunk size to a small value before
3164 changing subsegments, so that we don't use a lot of memory
3165 space for what may be a small section. */
3166 hold_chunksize = chunksize;
3167 chunksize = 64;
3168
3169 sec = subseg_new (segment_name (S_GET_SEGMENT (sym)),
3170 symbol_get_tc (sym)->subseg);
3171
3172 chunksize = hold_chunksize;
3173
3174 if (after_toc)
3175 ppc_after_toc_frag = frag_now;
3176
3177 record_alignment (sec, align);
3178 if (is_code)
3179 frag_align_code (align, 0);
3180 else
3181 frag_align (align, 0, 0);
3182
3183 symbol_set_frag (sym, frag_now);
3184 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3185
3186 symbol_get_tc (sym)->align = align;
3187 symbol_get_tc (sym)->output = 1;
3188 symbol_get_tc (sym)->within = sym;
3189
3190 for (list = *list_ptr;
3191 symbol_get_tc (list)->next != (symbolS *) NULL;
3192 list = symbol_get_tc (list)->next)
3193 ;
3194 symbol_get_tc (list)->next = sym;
3195
3196 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3197 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3198 &symbol_lastP);
3199 }
3200
3201 ppc_current_csect = sym;
3202 }
3203
3204 /* This function handles the .text and .data pseudo-ops. These
3205 pseudo-ops aren't really used by XCOFF; we implement them for the
3206 convenience of people who aren't used to XCOFF. */
3207
3208 static void
3209 ppc_section (type)
3210 int type;
3211 {
3212 const char *name;
3213 symbolS *sym;
3214
3215 if (type == 't')
3216 name = ".text[PR]";
3217 else if (type == 'd')
3218 name = ".data[RW]";
3219 else
3220 abort ();
3221
3222 sym = symbol_find_or_make (name);
3223
3224 ppc_change_csect (sym, 2);
3225
3226 demand_empty_rest_of_line ();
3227 }
3228
3229 /* This function handles the .section pseudo-op. This is mostly to
3230 give an error, since XCOFF only supports .text, .data and .bss, but
3231 we do permit the user to name the text or data section. */
3232
3233 static void
3234 ppc_named_section (ignore)
3235 int ignore ATTRIBUTE_UNUSED;
3236 {
3237 char *user_name;
3238 const char *real_name;
3239 char c;
3240 symbolS *sym;
3241
3242 user_name = input_line_pointer;
3243 c = get_symbol_end ();
3244
3245 if (strcmp (user_name, ".text") == 0)
3246 real_name = ".text[PR]";
3247 else if (strcmp (user_name, ".data") == 0)
3248 real_name = ".data[RW]";
3249 else
3250 {
3251 as_bad (_("The XCOFF file format does not support arbitrary sections"));
3252 *input_line_pointer = c;
3253 ignore_rest_of_line ();
3254 return;
3255 }
3256
3257 *input_line_pointer = c;
3258
3259 sym = symbol_find_or_make (real_name);
3260
3261 ppc_change_csect (sym, 2);
3262
3263 demand_empty_rest_of_line ();
3264 }
3265
3266 /* The .extern pseudo-op. We create an undefined symbol. */
3267
3268 static void
3269 ppc_extern (ignore)
3270 int ignore ATTRIBUTE_UNUSED;
3271 {
3272 char *name;
3273 char endc;
3274
3275 name = input_line_pointer;
3276 endc = get_symbol_end ();
3277
3278 (void) symbol_find_or_make (name);
3279
3280 *input_line_pointer = endc;
3281
3282 demand_empty_rest_of_line ();
3283 }
3284
3285 /* The .lglobl pseudo-op. Keep the symbol in the symbol table. */
3286
3287 static void
3288 ppc_lglobl (ignore)
3289 int ignore ATTRIBUTE_UNUSED;
3290 {
3291 char *name;
3292 char endc;
3293 symbolS *sym;
3294
3295 name = input_line_pointer;
3296 endc = get_symbol_end ();
3297
3298 sym = symbol_find_or_make (name);
3299
3300 *input_line_pointer = endc;
3301
3302 symbol_get_tc (sym)->output = 1;
3303
3304 demand_empty_rest_of_line ();
3305 }
3306
3307 /* The .rename pseudo-op. The RS/6000 assembler can rename symbols,
3308 although I don't know why it bothers. */
3309
3310 static void
3311 ppc_rename (ignore)
3312 int ignore ATTRIBUTE_UNUSED;
3313 {
3314 char *name;
3315 char endc;
3316 symbolS *sym;
3317 int len;
3318
3319 name = input_line_pointer;
3320 endc = get_symbol_end ();
3321
3322 sym = symbol_find_or_make (name);
3323
3324 *input_line_pointer = endc;
3325
3326 if (*input_line_pointer != ',')
3327 {
3328 as_bad (_("missing rename string"));
3329 ignore_rest_of_line ();
3330 return;
3331 }
3332 ++input_line_pointer;
3333
3334 symbol_get_tc (sym)->real_name = demand_copy_C_string (&len);
3335
3336 demand_empty_rest_of_line ();
3337 }
3338
3339 /* The .stabx pseudo-op. This is similar to a normal .stabs
3340 pseudo-op, but slightly different. A sample is
3341 .stabx "main:F-1",.main,142,0
3342 The first argument is the symbol name to create. The second is the
3343 value, and the third is the storage class. The fourth seems to be
3344 always zero, and I am assuming it is the type. */
3345
3346 static void
3347 ppc_stabx (ignore)
3348 int ignore ATTRIBUTE_UNUSED;
3349 {
3350 char *name;
3351 int len;
3352 symbolS *sym;
3353 expressionS exp;
3354
3355 name = demand_copy_C_string (&len);
3356
3357 if (*input_line_pointer != ',')
3358 {
3359 as_bad (_("missing value"));
3360 return;
3361 }
3362 ++input_line_pointer;
3363
3364 ppc_stab_symbol = TRUE;
3365 sym = symbol_make (name);
3366 ppc_stab_symbol = FALSE;
3367
3368 symbol_get_tc (sym)->real_name = name;
3369
3370 (void) expression (&exp);
3371
3372 switch (exp.X_op)
3373 {
3374 case O_illegal:
3375 case O_absent:
3376 case O_big:
3377 as_bad (_("illegal .stabx expression; zero assumed"));
3378 exp.X_add_number = 0;
3379 /* Fall through. */
3380 case O_constant:
3381 S_SET_VALUE (sym, (valueT) exp.X_add_number);
3382 symbol_set_frag (sym, &zero_address_frag);
3383 break;
3384
3385 case O_symbol:
3386 if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section)
3387 symbol_set_value_expression (sym, &exp);
3388 else
3389 {
3390 S_SET_VALUE (sym,
3391 exp.X_add_number + S_GET_VALUE (exp.X_add_symbol));
3392 symbol_set_frag (sym, symbol_get_frag (exp.X_add_symbol));
3393 }
3394 break;
3395
3396 default:
3397 /* The value is some complex expression. This will probably
3398 fail at some later point, but this is probably the right
3399 thing to do here. */
3400 symbol_set_value_expression (sym, &exp);
3401 break;
3402 }
3403
3404 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3405 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3406
3407 if (*input_line_pointer != ',')
3408 {
3409 as_bad (_("missing class"));
3410 return;
3411 }
3412 ++input_line_pointer;
3413
3414 S_SET_STORAGE_CLASS (sym, get_absolute_expression ());
3415
3416 if (*input_line_pointer != ',')
3417 {
3418 as_bad (_("missing type"));
3419 return;
3420 }
3421 ++input_line_pointer;
3422
3423 S_SET_DATA_TYPE (sym, get_absolute_expression ());
3424
3425 symbol_get_tc (sym)->output = 1;
3426
3427 if (S_GET_STORAGE_CLASS (sym) == C_STSYM) {
3428
3429 symbol_get_tc (sym)->within = ppc_current_block;
3430
3431 /* In this case :
3432
3433 .bs name
3434 .stabx "z",arrays_,133,0
3435 .es
3436
3437 .comm arrays_,13768,3
3438
3439 resolve_symbol_value will copy the exp's "within" into sym's when the
3440 offset is 0. Since this seems to be corner case problem,
3441 only do the correction for storage class C_STSYM. A better solution
3442 would be to have the tc field updated in ppc_symbol_new_hook. */
3443
3444 if (exp.X_op == O_symbol)
3445 {
3446 symbol_get_tc (exp.X_add_symbol)->within = ppc_current_block;
3447 }
3448 }
3449
3450 if (exp.X_op != O_symbol
3451 || ! S_IS_EXTERNAL (exp.X_add_symbol)
3452 || S_GET_SEGMENT (exp.X_add_symbol) != bss_section)
3453 ppc_frob_label (sym);
3454 else
3455 {
3456 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3457 symbol_append (sym, exp.X_add_symbol, &symbol_rootP, &symbol_lastP);
3458 if (symbol_get_tc (ppc_current_csect)->within == exp.X_add_symbol)
3459 symbol_get_tc (ppc_current_csect)->within = sym;
3460 }
3461
3462 demand_empty_rest_of_line ();
3463 }
3464
3465 /* The .function pseudo-op. This takes several arguments. The first
3466 argument seems to be the external name of the symbol. The second
3467 argument seems to be the label for the start of the function. gcc
3468 uses the same name for both. I have no idea what the third and
3469 fourth arguments are meant to be. The optional fifth argument is
3470 an expression for the size of the function. In COFF this symbol
3471 gets an aux entry like that used for a csect. */
3472
3473 static void
3474 ppc_function (ignore)
3475 int ignore ATTRIBUTE_UNUSED;
3476 {
3477 char *name;
3478 char endc;
3479 char *s;
3480 symbolS *ext_sym;
3481 symbolS *lab_sym;
3482
3483 name = input_line_pointer;
3484 endc = get_symbol_end ();
3485
3486 /* Ignore any [PR] suffix. */
3487 name = ppc_canonicalize_symbol_name (name);
3488 s = strchr (name, '[');
3489 if (s != (char *) NULL
3490 && strcmp (s + 1, "PR]") == 0)
3491 *s = '\0';
3492
3493 ext_sym = symbol_find_or_make (name);
3494
3495 *input_line_pointer = endc;
3496
3497 if (*input_line_pointer != ',')
3498 {
3499 as_bad (_("missing symbol name"));
3500 ignore_rest_of_line ();
3501 return;
3502 }
3503 ++input_line_pointer;
3504
3505 name = input_line_pointer;
3506 endc = get_symbol_end ();
3507
3508 lab_sym = symbol_find_or_make (name);
3509
3510 *input_line_pointer = endc;
3511
3512 if (ext_sym != lab_sym)
3513 {
3514 expressionS exp;
3515
3516 exp.X_op = O_symbol;
3517 exp.X_add_symbol = lab_sym;
3518 exp.X_op_symbol = NULL;
3519 exp.X_add_number = 0;
3520 exp.X_unsigned = 0;
3521 symbol_set_value_expression (ext_sym, &exp);
3522 }
3523
3524 if (symbol_get_tc (ext_sym)->class == -1)
3525 symbol_get_tc (ext_sym)->class = XMC_PR;
3526 symbol_get_tc (ext_sym)->output = 1;
3527
3528 if (*input_line_pointer == ',')
3529 {
3530 expressionS ignore;
3531
3532 /* Ignore the third argument. */
3533 ++input_line_pointer;
3534 expression (&ignore);
3535 if (*input_line_pointer == ',')
3536 {
3537 /* Ignore the fourth argument. */
3538 ++input_line_pointer;
3539 expression (&ignore);
3540 if (*input_line_pointer == ',')
3541 {
3542 /* The fifth argument is the function size. */
3543 ++input_line_pointer;
3544 symbol_get_tc (ext_sym)->size = symbol_new ("L0\001",
3545 absolute_section,
3546 (valueT) 0,
3547 &zero_address_frag);
3548 pseudo_set (symbol_get_tc (ext_sym)->size);
3549 }
3550 }
3551 }
3552
3553 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
3554 SF_SET_FUNCTION (ext_sym);
3555 SF_SET_PROCESS (ext_sym);
3556 coff_add_linesym (ext_sym);
3557
3558 demand_empty_rest_of_line ();
3559 }
3560
3561 /* The .bf pseudo-op. This is just like a COFF C_FCN symbol named
3562 ".bf". If the pseudo op .bi was seen before .bf, patch the .bi sym
3563 with the correct line number */
3564
3565 static symbolS *saved_bi_sym = 0;
3566
3567 static void
3568 ppc_bf (ignore)
3569 int ignore ATTRIBUTE_UNUSED;
3570 {
3571 symbolS *sym;
3572
3573 sym = symbol_make (".bf");
3574 S_SET_SEGMENT (sym, text_section);
3575 symbol_set_frag (sym, frag_now);
3576 S_SET_VALUE (sym, frag_now_fix ());
3577 S_SET_STORAGE_CLASS (sym, C_FCN);
3578
3579 coff_line_base = get_absolute_expression ();
3580
3581 S_SET_NUMBER_AUXILIARY (sym, 1);
3582 SA_SET_SYM_LNNO (sym, coff_line_base);
3583
3584 /* Line number for bi. */
3585 if (saved_bi_sym)
3586 {
3587 S_SET_VALUE (saved_bi_sym, coff_n_line_nos);
3588 saved_bi_sym = 0;
3589 }
3590
3591
3592 symbol_get_tc (sym)->output = 1;
3593
3594 ppc_frob_label (sym);
3595
3596 demand_empty_rest_of_line ();
3597 }
3598
3599 /* The .ef pseudo-op. This is just like a COFF C_FCN symbol named
3600 ".ef", except that the line number is absolute, not relative to the
3601 most recent ".bf" symbol. */
3602
3603 static void
3604 ppc_ef (ignore)
3605 int ignore ATTRIBUTE_UNUSED;
3606 {
3607 symbolS *sym;
3608
3609 sym = symbol_make (".ef");
3610 S_SET_SEGMENT (sym, text_section);
3611 symbol_set_frag (sym, frag_now);
3612 S_SET_VALUE (sym, frag_now_fix ());
3613 S_SET_STORAGE_CLASS (sym, C_FCN);
3614 S_SET_NUMBER_AUXILIARY (sym, 1);
3615 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3616 symbol_get_tc (sym)->output = 1;
3617
3618 ppc_frob_label (sym);
3619
3620 demand_empty_rest_of_line ();
3621 }
3622
3623 /* The .bi and .ei pseudo-ops. These take a string argument and
3624 generates a C_BINCL or C_EINCL symbol, which goes at the start of
3625 the symbol list. The value of .bi will be know when the next .bf
3626 is encountered. */
3627
3628 static void
3629 ppc_biei (ei)
3630 int ei;
3631 {
3632 static symbolS *last_biei;
3633
3634 char *name;
3635 int len;
3636 symbolS *sym;
3637 symbolS *look;
3638
3639 name = demand_copy_C_string (&len);
3640
3641 /* The value of these symbols is actually file offset. Here we set
3642 the value to the index into the line number entries. In
3643 ppc_frob_symbols we set the fix_line field, which will cause BFD
3644 to do the right thing. */
3645
3646 sym = symbol_make (name);
3647 /* obj-coff.c currently only handles line numbers correctly in the
3648 .text section. */
3649 S_SET_SEGMENT (sym, text_section);
3650 S_SET_VALUE (sym, coff_n_line_nos);
3651 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3652
3653 S_SET_STORAGE_CLASS (sym, ei ? C_EINCL : C_BINCL);
3654 symbol_get_tc (sym)->output = 1;
3655
3656 /* Save bi. */
3657 if (ei)
3658 saved_bi_sym = 0;
3659 else
3660 saved_bi_sym = sym;
3661
3662 for (look = last_biei ? last_biei : symbol_rootP;
3663 (look != (symbolS *) NULL
3664 && (S_GET_STORAGE_CLASS (look) == C_FILE
3665 || S_GET_STORAGE_CLASS (look) == C_BINCL
3666 || S_GET_STORAGE_CLASS (look) == C_EINCL));
3667 look = symbol_next (look))
3668 ;
3669 if (look != (symbolS *) NULL)
3670 {
3671 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3672 symbol_insert (sym, look, &symbol_rootP, &symbol_lastP);
3673 last_biei = sym;
3674 }
3675
3676 demand_empty_rest_of_line ();
3677 }
3678
3679 /* The .bs pseudo-op. This generates a C_BSTAT symbol named ".bs".
3680 There is one argument, which is a csect symbol. The value of the
3681 .bs symbol is the index of this csect symbol. */
3682
3683 static void
3684 ppc_bs (ignore)
3685 int ignore ATTRIBUTE_UNUSED;
3686 {
3687 char *name;
3688 char endc;
3689 symbolS *csect;
3690 symbolS *sym;
3691
3692 if (ppc_current_block != NULL)
3693 as_bad (_("nested .bs blocks"));
3694
3695 name = input_line_pointer;
3696 endc = get_symbol_end ();
3697
3698 csect = symbol_find_or_make (name);
3699
3700 *input_line_pointer = endc;
3701
3702 sym = symbol_make (".bs");
3703 S_SET_SEGMENT (sym, now_seg);
3704 S_SET_STORAGE_CLASS (sym, C_BSTAT);
3705 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3706 symbol_get_tc (sym)->output = 1;
3707
3708 symbol_get_tc (sym)->within = csect;
3709
3710 ppc_frob_label (sym);
3711
3712 ppc_current_block = sym;
3713
3714 demand_empty_rest_of_line ();
3715 }
3716
3717 /* The .es pseudo-op. Generate a C_ESTART symbol named .es. */
3718
3719 static void
3720 ppc_es (ignore)
3721 int ignore ATTRIBUTE_UNUSED;
3722 {
3723 symbolS *sym;
3724
3725 if (ppc_current_block == NULL)
3726 as_bad (_(".es without preceding .bs"));
3727
3728 sym = symbol_make (".es");
3729 S_SET_SEGMENT (sym, now_seg);
3730 S_SET_STORAGE_CLASS (sym, C_ESTAT);
3731 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3732 symbol_get_tc (sym)->output = 1;
3733
3734 ppc_frob_label (sym);
3735
3736 ppc_current_block = NULL;
3737
3738 demand_empty_rest_of_line ();
3739 }
3740
3741 /* The .bb pseudo-op. Generate a C_BLOCK symbol named .bb, with a
3742 line number. */
3743
3744 static void
3745 ppc_bb (ignore)
3746 int ignore ATTRIBUTE_UNUSED;
3747 {
3748 symbolS *sym;
3749
3750 sym = symbol_make (".bb");
3751 S_SET_SEGMENT (sym, text_section);
3752 symbol_set_frag (sym, frag_now);
3753 S_SET_VALUE (sym, frag_now_fix ());
3754 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3755
3756 S_SET_NUMBER_AUXILIARY (sym, 1);
3757 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3758
3759 symbol_get_tc (sym)->output = 1;
3760
3761 SF_SET_PROCESS (sym);
3762
3763 ppc_frob_label (sym);
3764
3765 demand_empty_rest_of_line ();
3766 }
3767
3768 /* The .eb pseudo-op. Generate a C_BLOCK symbol named .eb, with a
3769 line number. */
3770
3771 static void
3772 ppc_eb (ignore)
3773 int ignore ATTRIBUTE_UNUSED;
3774 {
3775 symbolS *sym;
3776
3777 sym = symbol_make (".eb");
3778 S_SET_SEGMENT (sym, text_section);
3779 symbol_set_frag (sym, frag_now);
3780 S_SET_VALUE (sym, frag_now_fix ());
3781 S_SET_STORAGE_CLASS (sym, C_BLOCK);
3782 S_SET_NUMBER_AUXILIARY (sym, 1);
3783 SA_SET_SYM_LNNO (sym, get_absolute_expression ());
3784 symbol_get_tc (sym)->output = 1;
3785
3786 SF_SET_PROCESS (sym);
3787
3788 ppc_frob_label (sym);
3789
3790 demand_empty_rest_of_line ();
3791 }
3792
3793 /* The .bc pseudo-op. This just creates a C_BCOMM symbol with a
3794 specified name. */
3795
3796 static void
3797 ppc_bc (ignore)
3798 int ignore ATTRIBUTE_UNUSED;
3799 {
3800 char *name;
3801 int len;
3802 symbolS *sym;
3803
3804 name = demand_copy_C_string (&len);
3805 sym = symbol_make (name);
3806 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3807 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3808 S_SET_STORAGE_CLASS (sym, C_BCOMM);
3809 S_SET_VALUE (sym, 0);
3810 symbol_get_tc (sym)->output = 1;
3811
3812 ppc_frob_label (sym);
3813
3814 demand_empty_rest_of_line ();
3815 }
3816
3817 /* The .ec pseudo-op. This just creates a C_ECOMM symbol. */
3818
3819 static void
3820 ppc_ec (ignore)
3821 int ignore ATTRIBUTE_UNUSED;
3822 {
3823 symbolS *sym;
3824
3825 sym = symbol_make (".ec");
3826 S_SET_SEGMENT (sym, ppc_coff_debug_section);
3827 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING;
3828 S_SET_STORAGE_CLASS (sym, C_ECOMM);
3829 S_SET_VALUE (sym, 0);
3830 symbol_get_tc (sym)->output = 1;
3831
3832 ppc_frob_label (sym);
3833
3834 demand_empty_rest_of_line ();
3835 }
3836
3837 /* The .toc pseudo-op. Switch to the .toc subsegment. */
3838
3839 static void
3840 ppc_toc (ignore)
3841 int ignore ATTRIBUTE_UNUSED;
3842 {
3843 if (ppc_toc_csect != (symbolS *) NULL)
3844 subseg_set (data_section, symbol_get_tc (ppc_toc_csect)->subseg);
3845 else
3846 {
3847 subsegT subseg;
3848 symbolS *sym;
3849 symbolS *list;
3850
3851 subseg = ppc_data_subsegment;
3852 ++ppc_data_subsegment;
3853
3854 subseg_new (segment_name (data_section), subseg);
3855 ppc_toc_frag = frag_now;
3856
3857 sym = symbol_find_or_make ("TOC[TC0]");
3858 symbol_set_frag (sym, frag_now);
3859 S_SET_SEGMENT (sym, data_section);
3860 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3861 symbol_get_tc (sym)->subseg = subseg;
3862 symbol_get_tc (sym)->output = 1;
3863 symbol_get_tc (sym)->within = sym;
3864
3865 ppc_toc_csect = sym;
3866
3867 for (list = ppc_data_csects;
3868 symbol_get_tc (list)->next != (symbolS *) NULL;
3869 list = symbol_get_tc (list)->next)
3870 ;
3871 symbol_get_tc (list)->next = sym;
3872
3873 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3874 symbol_append (sym, symbol_get_tc (list)->within, &symbol_rootP,
3875 &symbol_lastP);
3876 }
3877
3878 ppc_current_csect = ppc_toc_csect;
3879
3880 demand_empty_rest_of_line ();
3881 }
3882
3883 /* The AIX assembler automatically aligns the operands of a .long or
3884 .short pseudo-op, and we want to be compatible. */
3885
3886 static void
3887 ppc_xcoff_cons (log_size)
3888 int log_size;
3889 {
3890 frag_align (log_size, 0, 0);
3891 record_alignment (now_seg, log_size);
3892 cons (1 << log_size);
3893 }
3894
3895 static void
3896 ppc_vbyte (dummy)
3897 int dummy ATTRIBUTE_UNUSED;
3898 {
3899 expressionS exp;
3900 int byte_count;
3901
3902 (void) expression (&exp);
3903
3904 if (exp.X_op != O_constant)
3905 {
3906 as_bad (_("non-constant byte count"));
3907 return;
3908 }
3909
3910 byte_count = exp.X_add_number;
3911
3912 if (*input_line_pointer != ',')
3913 {
3914 as_bad (_("missing value"));
3915 return;
3916 }
3917
3918 ++input_line_pointer;
3919 cons (byte_count);
3920 }
3921
3922 #endif /* OBJ_XCOFF */
3923 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
3924 \f
3925 /* The .tc pseudo-op. This is used when generating either XCOFF or
3926 ELF. This takes two or more arguments.
3927
3928 When generating XCOFF output, the first argument is the name to
3929 give to this location in the toc; this will be a symbol with class
3930 TC. The rest of the arguments are N-byte values to actually put at
3931 this location in the TOC; often there is just one more argument, a
3932 relocatable symbol reference. The size of the value to store
3933 depends on target word size. A 32-bit target uses 4-byte values, a
3934 64-bit target uses 8-byte values.
3935
3936 When not generating XCOFF output, the arguments are the same, but
3937 the first argument is simply ignored. */
3938
3939 static void
3940 ppc_tc (ignore)
3941 int ignore ATTRIBUTE_UNUSED;
3942 {
3943 #ifdef OBJ_XCOFF
3944
3945 /* Define the TOC symbol name. */
3946 {
3947 char *name;
3948 char endc;
3949 symbolS *sym;
3950
3951 if (ppc_toc_csect == (symbolS *) NULL
3952 || ppc_toc_csect != ppc_current_csect)
3953 {
3954 as_bad (_(".tc not in .toc section"));
3955 ignore_rest_of_line ();
3956 return;
3957 }
3958
3959 name = input_line_pointer;
3960 endc = get_symbol_end ();
3961
3962 sym = symbol_find_or_make (name);
3963
3964 *input_line_pointer = endc;
3965
3966 if (S_IS_DEFINED (sym))
3967 {
3968 symbolS *label;
3969
3970 label = symbol_get_tc (ppc_current_csect)->within;
3971 if (symbol_get_tc (label)->class != XMC_TC0)
3972 {
3973 as_bad (_(".tc with no label"));
3974 ignore_rest_of_line ();
3975 return;
3976 }
3977
3978 S_SET_SEGMENT (label, S_GET_SEGMENT (sym));
3979 symbol_set_frag (label, symbol_get_frag (sym));
3980 S_SET_VALUE (label, S_GET_VALUE (sym));
3981
3982 while (! is_end_of_line[(unsigned char) *input_line_pointer])
3983 ++input_line_pointer;
3984
3985 return;
3986 }
3987
3988 S_SET_SEGMENT (sym, now_seg);
3989 symbol_set_frag (sym, frag_now);
3990 S_SET_VALUE (sym, (valueT) frag_now_fix ());
3991 symbol_get_tc (sym)->class = XMC_TC;
3992 symbol_get_tc (sym)->output = 1;
3993
3994 ppc_frob_label (sym);
3995 }
3996
3997 #endif /* OBJ_XCOFF */
3998 #ifdef OBJ_ELF
3999 int align;
4000
4001 /* Skip the TOC symbol name. */
4002 while (is_part_of_name (*input_line_pointer)
4003 || *input_line_pointer == '['
4004 || *input_line_pointer == ']'
4005 || *input_line_pointer == '{'
4006 || *input_line_pointer == '}')
4007 ++input_line_pointer;
4008
4009 /* Align to a four/eight byte boundary. */
4010 align = ppc_obj64 ? 3 : 2;
4011 frag_align (align, 0, 0);
4012 record_alignment (now_seg, align);
4013 #endif /* OBJ_ELF */
4014
4015 if (*input_line_pointer != ',')
4016 demand_empty_rest_of_line ();
4017 else
4018 {
4019 ++input_line_pointer;
4020 cons (ppc_obj64 ? 8 : 4);
4021 }
4022 }
4023
4024 /* Pseudo-op .machine. */
4025
4026 static void
4027 ppc_machine (ignore)
4028 int ignore ATTRIBUTE_UNUSED;
4029 {
4030 char *cpu_string;
4031 #define MAX_HISTORY 100
4032 static unsigned long *cpu_history;
4033 static int curr_hist;
4034
4035 SKIP_WHITESPACE ();
4036
4037 if (*input_line_pointer == '"')
4038 {
4039 int len;
4040 cpu_string = demand_copy_C_string (&len);
4041 }
4042 else
4043 {
4044 char c;
4045 cpu_string = input_line_pointer;
4046 c = get_symbol_end ();
4047 cpu_string = xstrdup (cpu_string);
4048 *input_line_pointer = c;
4049 }
4050
4051 if (cpu_string != NULL)
4052 {
4053 unsigned long old_cpu = ppc_cpu;
4054 char *p;
4055
4056 for (p = cpu_string; *p != 0; p++)
4057 *p = TOLOWER (*p);
4058
4059 if (strcmp (cpu_string, "push") == 0)
4060 {
4061 if (cpu_history == NULL)
4062 cpu_history = xmalloc (MAX_HISTORY * sizeof (*cpu_history));
4063
4064 if (curr_hist >= MAX_HISTORY)
4065 as_bad (_(".machine stack overflow"));
4066 else
4067 cpu_history[curr_hist++] = ppc_cpu;
4068 }
4069 else if (strcmp (cpu_string, "pop") == 0)
4070 {
4071 if (curr_hist <= 0)
4072 as_bad (_(".machine stack underflow"));
4073 else
4074 ppc_cpu = cpu_history[--curr_hist];
4075 }
4076 else if (parse_cpu (cpu_string))
4077 ;
4078 else
4079 as_bad (_("invalid machine `%s'"), cpu_string);
4080
4081 if (ppc_cpu != old_cpu)
4082 ppc_setup_opcodes ();
4083 }
4084
4085 demand_empty_rest_of_line ();
4086 }
4087
4088 /* See whether a symbol is in the TOC section. */
4089
4090 static int
4091 ppc_is_toc_sym (sym)
4092 symbolS *sym;
4093 {
4094 #ifdef OBJ_XCOFF
4095 return symbol_get_tc (sym)->class == XMC_TC;
4096 #endif
4097 #ifdef OBJ_ELF
4098 const char *sname = segment_name (S_GET_SEGMENT (sym));
4099 if (ppc_obj64)
4100 return strcmp (sname, ".toc") == 0;
4101 else
4102 return strcmp (sname, ".got") == 0;
4103 #endif
4104 }
4105 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
4106 \f
4107 #ifdef TE_PE
4108
4109 /* Pseudo-ops specific to the Windows NT PowerPC PE (coff) format. */
4110
4111 /* Set the current section. */
4112 static void
4113 ppc_set_current_section (new)
4114 segT new;
4115 {
4116 ppc_previous_section = ppc_current_section;
4117 ppc_current_section = new;
4118 }
4119
4120 /* pseudo-op: .previous
4121 behaviour: toggles the current section with the previous section.
4122 errors: None
4123 warnings: "No previous section" */
4124
4125 static void
4126 ppc_previous (ignore)
4127 int ignore ATTRIBUTE_UNUSED;
4128 {
4129 symbolS *tmp;
4130
4131 if (ppc_previous_section == NULL)
4132 {
4133 as_warn (_("No previous section to return to. Directive ignored."));
4134 return;
4135 }
4136
4137 subseg_set (ppc_previous_section, 0);
4138
4139 ppc_set_current_section (ppc_previous_section);
4140 }
4141
4142 /* pseudo-op: .pdata
4143 behaviour: predefined read only data section
4144 double word aligned
4145 errors: None
4146 warnings: None
4147 initial: .section .pdata "adr3"
4148 a - don't know -- maybe a misprint
4149 d - initialized data
4150 r - readable
4151 3 - double word aligned (that would be 4 byte boundary)
4152
4153 commentary:
4154 Tag index tables (also known as the function table) for exception
4155 handling, debugging, etc. */
4156
4157 static void
4158 ppc_pdata (ignore)
4159 int ignore ATTRIBUTE_UNUSED;
4160 {
4161 if (pdata_section == 0)
4162 {
4163 pdata_section = subseg_new (".pdata", 0);
4164
4165 bfd_set_section_flags (stdoutput, pdata_section,
4166 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4167 | SEC_READONLY | SEC_DATA ));
4168
4169 bfd_set_section_alignment (stdoutput, pdata_section, 2);
4170 }
4171 else
4172 {
4173 pdata_section = subseg_new (".pdata", 0);
4174 }
4175 ppc_set_current_section (pdata_section);
4176 }
4177
4178 /* pseudo-op: .ydata
4179 behaviour: predefined read only data section
4180 double word aligned
4181 errors: None
4182 warnings: None
4183 initial: .section .ydata "drw3"
4184 a - don't know -- maybe a misprint
4185 d - initialized data
4186 r - readable
4187 3 - double word aligned (that would be 4 byte boundary)
4188 commentary:
4189 Tag tables (also known as the scope table) for exception handling,
4190 debugging, etc. */
4191
4192 static void
4193 ppc_ydata (ignore)
4194 int ignore ATTRIBUTE_UNUSED;
4195 {
4196 if (ydata_section == 0)
4197 {
4198 ydata_section = subseg_new (".ydata", 0);
4199 bfd_set_section_flags (stdoutput, ydata_section,
4200 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4201 | SEC_READONLY | SEC_DATA ));
4202
4203 bfd_set_section_alignment (stdoutput, ydata_section, 3);
4204 }
4205 else
4206 {
4207 ydata_section = subseg_new (".ydata", 0);
4208 }
4209 ppc_set_current_section (ydata_section);
4210 }
4211
4212 /* pseudo-op: .reldata
4213 behaviour: predefined read write data section
4214 double word aligned (4-byte)
4215 FIXME: relocation is applied to it
4216 FIXME: what's the difference between this and .data?
4217 errors: None
4218 warnings: None
4219 initial: .section .reldata "drw3"
4220 d - initialized data
4221 r - readable
4222 w - writeable
4223 3 - double word aligned (that would be 8 byte boundary)
4224
4225 commentary:
4226 Like .data, but intended to hold data subject to relocation, such as
4227 function descriptors, etc. */
4228
4229 static void
4230 ppc_reldata (ignore)
4231 int ignore ATTRIBUTE_UNUSED;
4232 {
4233 if (reldata_section == 0)
4234 {
4235 reldata_section = subseg_new (".reldata", 0);
4236
4237 bfd_set_section_flags (stdoutput, reldata_section,
4238 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4239 | SEC_DATA));
4240
4241 bfd_set_section_alignment (stdoutput, reldata_section, 2);
4242 }
4243 else
4244 {
4245 reldata_section = subseg_new (".reldata", 0);
4246 }
4247 ppc_set_current_section (reldata_section);
4248 }
4249
4250 /* pseudo-op: .rdata
4251 behaviour: predefined read only data section
4252 double word aligned
4253 errors: None
4254 warnings: None
4255 initial: .section .rdata "dr3"
4256 d - initialized data
4257 r - readable
4258 3 - double word aligned (that would be 4 byte boundary) */
4259
4260 static void
4261 ppc_rdata (ignore)
4262 int ignore ATTRIBUTE_UNUSED;
4263 {
4264 if (rdata_section == 0)
4265 {
4266 rdata_section = subseg_new (".rdata", 0);
4267 bfd_set_section_flags (stdoutput, rdata_section,
4268 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4269 | SEC_READONLY | SEC_DATA ));
4270
4271 bfd_set_section_alignment (stdoutput, rdata_section, 2);
4272 }
4273 else
4274 {
4275 rdata_section = subseg_new (".rdata", 0);
4276 }
4277 ppc_set_current_section (rdata_section);
4278 }
4279
4280 /* pseudo-op: .ualong
4281 behaviour: much like .int, with the exception that no alignment is
4282 performed.
4283 FIXME: test the alignment statement
4284 errors: None
4285 warnings: None */
4286
4287 static void
4288 ppc_ualong (ignore)
4289 int ignore ATTRIBUTE_UNUSED;
4290 {
4291 /* Try for long. */
4292 cons (4);
4293 }
4294
4295 /* pseudo-op: .znop <symbol name>
4296 behaviour: Issue a nop instruction
4297 Issue a IMAGE_REL_PPC_IFGLUE relocation against it, using
4298 the supplied symbol name.
4299 errors: None
4300 warnings: Missing symbol name */
4301
4302 static void
4303 ppc_znop (ignore)
4304 int ignore ATTRIBUTE_UNUSED;
4305 {
4306 unsigned long insn;
4307 const struct powerpc_opcode *opcode;
4308 expressionS ex;
4309 char *f;
4310 symbolS *sym;
4311 char *symbol_name;
4312 char c;
4313 char *name;
4314 unsigned int exp;
4315 flagword flags;
4316 asection *sec;
4317
4318 /* Strip out the symbol name. */
4319 symbol_name = input_line_pointer;
4320 c = get_symbol_end ();
4321
4322 name = xmalloc (input_line_pointer - symbol_name + 1);
4323 strcpy (name, symbol_name);
4324
4325 sym = symbol_find_or_make (name);
4326
4327 *input_line_pointer = c;
4328
4329 SKIP_WHITESPACE ();
4330
4331 /* Look up the opcode in the hash table. */
4332 opcode = (const struct powerpc_opcode *) hash_find (ppc_hash, "nop");
4333
4334 /* Stick in the nop. */
4335 insn = opcode->opcode;
4336
4337 /* Write out the instruction. */
4338 f = frag_more (4);
4339 md_number_to_chars (f, insn, 4);
4340 fix_new (frag_now,
4341 f - frag_now->fr_literal,
4342 4,
4343 sym,
4344 0,
4345 0,
4346 BFD_RELOC_16_GOT_PCREL);
4347
4348 }
4349
4350 /* pseudo-op:
4351 behaviour:
4352 errors:
4353 warnings: */
4354
4355 static void
4356 ppc_pe_comm (lcomm)
4357 int lcomm;
4358 {
4359 register char *name;
4360 register char c;
4361 register char *p;
4362 offsetT temp;
4363 register symbolS *symbolP;
4364 offsetT align;
4365
4366 name = input_line_pointer;
4367 c = get_symbol_end ();
4368
4369 /* just after name is now '\0'. */
4370 p = input_line_pointer;
4371 *p = c;
4372 SKIP_WHITESPACE ();
4373 if (*input_line_pointer != ',')
4374 {
4375 as_bad (_("Expected comma after symbol-name: rest of line ignored."));
4376 ignore_rest_of_line ();
4377 return;
4378 }
4379
4380 input_line_pointer++; /* skip ',' */
4381 if ((temp = get_absolute_expression ()) < 0)
4382 {
4383 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
4384 ignore_rest_of_line ();
4385 return;
4386 }
4387
4388 if (! lcomm)
4389 {
4390 /* The third argument to .comm is the alignment. */
4391 if (*input_line_pointer != ',')
4392 align = 3;
4393 else
4394 {
4395 ++input_line_pointer;
4396 align = get_absolute_expression ();
4397 if (align <= 0)
4398 {
4399 as_warn (_("ignoring bad alignment"));
4400 align = 3;
4401 }
4402 }
4403 }
4404
4405 *p = 0;
4406 symbolP = symbol_find_or_make (name);
4407
4408 *p = c;
4409 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4410 {
4411 as_bad (_("Ignoring attempt to re-define symbol `%s'."),
4412 S_GET_NAME (symbolP));
4413 ignore_rest_of_line ();
4414 return;
4415 }
4416
4417 if (S_GET_VALUE (symbolP))
4418 {
4419 if (S_GET_VALUE (symbolP) != (valueT) temp)
4420 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4421 S_GET_NAME (symbolP),
4422 (long) S_GET_VALUE (symbolP),
4423 (long) temp);
4424 }
4425 else
4426 {
4427 S_SET_VALUE (symbolP, (valueT) temp);
4428 S_SET_EXTERNAL (symbolP);
4429 S_SET_SEGMENT (symbolP, bfd_com_section_ptr);
4430 }
4431
4432 demand_empty_rest_of_line ();
4433 }
4434
4435 /*
4436 * implement the .section pseudo op:
4437 * .section name {, "flags"}
4438 * ^ ^
4439 * | +--- optional flags: 'b' for bss
4440 * | 'i' for info
4441 * +-- section name 'l' for lib
4442 * 'n' for noload
4443 * 'o' for over
4444 * 'w' for data
4445 * 'd' (apparently m88k for data)
4446 * 'x' for text
4447 * But if the argument is not a quoted string, treat it as a
4448 * subsegment number.
4449 *
4450 * FIXME: this is a copy of the section processing from obj-coff.c, with
4451 * additions/changes for the moto-pas assembler support. There are three
4452 * categories:
4453 *
4454 * FIXME: I just noticed this. This doesn't work at all really. It it
4455 * setting bits that bfd probably neither understands or uses. The
4456 * correct approach (?) will have to incorporate extra fields attached
4457 * to the section to hold the system specific stuff. (krk)
4458 *
4459 * Section Contents:
4460 * 'a' - unknown - referred to in documentation, but no definition supplied
4461 * 'c' - section has code
4462 * 'd' - section has initialized data
4463 * 'u' - section has uninitialized data
4464 * 'i' - section contains directives (info)
4465 * 'n' - section can be discarded
4466 * 'R' - remove section at link time
4467 *
4468 * Section Protection:
4469 * 'r' - section is readable
4470 * 'w' - section is writeable
4471 * 'x' - section is executable
4472 * 's' - section is sharable
4473 *
4474 * Section Alignment:
4475 * '0' - align to byte boundary
4476 * '1' - align to halfword undary
4477 * '2' - align to word boundary
4478 * '3' - align to doubleword boundary
4479 * '4' - align to quadword boundary
4480 * '5' - align to 32 byte boundary
4481 * '6' - align to 64 byte boundary
4482 *
4483 */
4484
4485 void
4486 ppc_pe_section (ignore)
4487 int ignore ATTRIBUTE_UNUSED;
4488 {
4489 /* Strip out the section name. */
4490 char *section_name;
4491 char c;
4492 char *name;
4493 unsigned int exp;
4494 flagword flags;
4495 segT sec;
4496 int align;
4497
4498 section_name = input_line_pointer;
4499 c = get_symbol_end ();
4500
4501 name = xmalloc (input_line_pointer - section_name + 1);
4502 strcpy (name, section_name);
4503
4504 *input_line_pointer = c;
4505
4506 SKIP_WHITESPACE ();
4507
4508 exp = 0;
4509 flags = SEC_NO_FLAGS;
4510
4511 if (strcmp (name, ".idata$2") == 0)
4512 {
4513 align = 0;
4514 }
4515 else if (strcmp (name, ".idata$3") == 0)
4516 {
4517 align = 0;
4518 }
4519 else if (strcmp (name, ".idata$4") == 0)
4520 {
4521 align = 2;
4522 }
4523 else if (strcmp (name, ".idata$5") == 0)
4524 {
4525 align = 2;
4526 }
4527 else if (strcmp (name, ".idata$6") == 0)
4528 {
4529 align = 1;
4530 }
4531 else
4532 /* Default alignment to 16 byte boundary. */
4533 align = 4;
4534
4535 if (*input_line_pointer == ',')
4536 {
4537 ++input_line_pointer;
4538 SKIP_WHITESPACE ();
4539 if (*input_line_pointer != '"')
4540 exp = get_absolute_expression ();
4541 else
4542 {
4543 ++input_line_pointer;
4544 while (*input_line_pointer != '"'
4545 && ! is_end_of_line[(unsigned char) *input_line_pointer])
4546 {
4547 switch (*input_line_pointer)
4548 {
4549 /* Section Contents */
4550 case 'a': /* unknown */
4551 as_bad (_("Unsupported section attribute -- 'a'"));
4552 break;
4553 case 'c': /* code section */
4554 flags |= SEC_CODE;
4555 break;
4556 case 'd': /* section has initialized data */
4557 flags |= SEC_DATA;
4558 break;
4559 case 'u': /* section has uninitialized data */
4560 /* FIXME: This is IMAGE_SCN_CNT_UNINITIALIZED_DATA
4561 in winnt.h */
4562 flags |= SEC_ROM;
4563 break;
4564 case 'i': /* section contains directives (info) */
4565 /* FIXME: This is IMAGE_SCN_LNK_INFO
4566 in winnt.h */
4567 flags |= SEC_HAS_CONTENTS;
4568 break;
4569 case 'n': /* section can be discarded */
4570 flags &=~ SEC_LOAD;
4571 break;
4572 case 'R': /* Remove section at link time */
4573 flags |= SEC_NEVER_LOAD;
4574 break;
4575
4576 /* Section Protection */
4577 case 'r': /* section is readable */
4578 flags |= IMAGE_SCN_MEM_READ;
4579 break;
4580 case 'w': /* section is writeable */
4581 flags |= IMAGE_SCN_MEM_WRITE;
4582 break;
4583 case 'x': /* section is executable */
4584 flags |= IMAGE_SCN_MEM_EXECUTE;
4585 break;
4586 case 's': /* section is sharable */
4587 flags |= IMAGE_SCN_MEM_SHARED;
4588 break;
4589
4590 /* Section Alignment */
4591 case '0': /* align to byte boundary */
4592 flags |= IMAGE_SCN_ALIGN_1BYTES;
4593 align = 0;
4594 break;
4595 case '1': /* align to halfword boundary */
4596 flags |= IMAGE_SCN_ALIGN_2BYTES;
4597 align = 1;
4598 break;
4599 case '2': /* align to word boundary */
4600 flags |= IMAGE_SCN_ALIGN_4BYTES;
4601 align = 2;
4602 break;
4603 case '3': /* align to doubleword boundary */
4604 flags |= IMAGE_SCN_ALIGN_8BYTES;
4605 align = 3;
4606 break;
4607 case '4': /* align to quadword boundary */
4608 flags |= IMAGE_SCN_ALIGN_16BYTES;
4609 align = 4;
4610 break;
4611 case '5': /* align to 32 byte boundary */
4612 flags |= IMAGE_SCN_ALIGN_32BYTES;
4613 align = 5;
4614 break;
4615 case '6': /* align to 64 byte boundary */
4616 flags |= IMAGE_SCN_ALIGN_64BYTES;
4617 align = 6;
4618 break;
4619
4620 default:
4621 as_bad (_("unknown section attribute '%c'"),
4622 *input_line_pointer);
4623 break;
4624 }
4625 ++input_line_pointer;
4626 }
4627 if (*input_line_pointer == '"')
4628 ++input_line_pointer;
4629 }
4630 }
4631
4632 sec = subseg_new (name, (subsegT) exp);
4633
4634 ppc_set_current_section (sec);
4635
4636 if (flags != SEC_NO_FLAGS)
4637 {
4638 if (! bfd_set_section_flags (stdoutput, sec, flags))
4639 as_bad (_("error setting flags for \"%s\": %s"),
4640 bfd_section_name (stdoutput, sec),
4641 bfd_errmsg (bfd_get_error ()));
4642 }
4643
4644 bfd_set_section_alignment (stdoutput, sec, align);
4645
4646 }
4647
4648 static void
4649 ppc_pe_function (ignore)
4650 int ignore ATTRIBUTE_UNUSED;
4651 {
4652 char *name;
4653 char endc;
4654 symbolS *ext_sym;
4655
4656 name = input_line_pointer;
4657 endc = get_symbol_end ();
4658
4659 ext_sym = symbol_find_or_make (name);
4660
4661 *input_line_pointer = endc;
4662
4663 S_SET_DATA_TYPE (ext_sym, DT_FCN << N_BTSHFT);
4664 SF_SET_FUNCTION (ext_sym);
4665 SF_SET_PROCESS (ext_sym);
4666 coff_add_linesym (ext_sym);
4667
4668 demand_empty_rest_of_line ();
4669 }
4670
4671 static void
4672 ppc_pe_tocd (ignore)
4673 int ignore ATTRIBUTE_UNUSED;
4674 {
4675 if (tocdata_section == 0)
4676 {
4677 tocdata_section = subseg_new (".tocd", 0);
4678 /* FIXME: section flags won't work. */
4679 bfd_set_section_flags (stdoutput, tocdata_section,
4680 (SEC_ALLOC | SEC_LOAD | SEC_RELOC
4681 | SEC_READONLY | SEC_DATA));
4682
4683 bfd_set_section_alignment (stdoutput, tocdata_section, 2);
4684 }
4685 else
4686 {
4687 rdata_section = subseg_new (".tocd", 0);
4688 }
4689
4690 ppc_set_current_section (tocdata_section);
4691
4692 demand_empty_rest_of_line ();
4693 }
4694
4695 /* Don't adjust TOC relocs to use the section symbol. */
4696
4697 int
4698 ppc_pe_fix_adjustable (fix)
4699 fixS *fix;
4700 {
4701 return fix->fx_r_type != BFD_RELOC_PPC_TOC16;
4702 }
4703
4704 #endif
4705 \f
4706 #ifdef OBJ_XCOFF
4707
4708 /* XCOFF specific symbol and file handling. */
4709
4710 /* Canonicalize the symbol name. We use the to force the suffix, if
4711 any, to use square brackets, and to be in upper case. */
4712
4713 char *
4714 ppc_canonicalize_symbol_name (name)
4715 char *name;
4716 {
4717 char *s;
4718
4719 if (ppc_stab_symbol)
4720 return name;
4721
4722 for (s = name; *s != '\0' && *s != '{' && *s != '['; s++)
4723 ;
4724 if (*s != '\0')
4725 {
4726 char brac;
4727
4728 if (*s == '[')
4729 brac = ']';
4730 else
4731 {
4732 *s = '[';
4733 brac = '}';
4734 }
4735
4736 for (s++; *s != '\0' && *s != brac; s++)
4737 *s = TOUPPER (*s);
4738
4739 if (*s == '\0' || s[1] != '\0')
4740 as_bad (_("bad symbol suffix"));
4741
4742 *s = ']';
4743 }
4744
4745 return name;
4746 }
4747
4748 /* Set the class of a symbol based on the suffix, if any. This is
4749 called whenever a new symbol is created. */
4750
4751 void
4752 ppc_symbol_new_hook (sym)
4753 symbolS *sym;
4754 {
4755 struct ppc_tc_sy *tc;
4756 const char *s;
4757
4758 tc = symbol_get_tc (sym);
4759 tc->next = NULL;
4760 tc->output = 0;
4761 tc->class = -1;
4762 tc->real_name = NULL;
4763 tc->subseg = 0;
4764 tc->align = 0;
4765 tc->size = NULL;
4766 tc->within = NULL;
4767
4768 if (ppc_stab_symbol)
4769 return;
4770
4771 s = strchr (S_GET_NAME (sym), '[');
4772 if (s == (const char *) NULL)
4773 {
4774 /* There is no suffix. */
4775 return;
4776 }
4777
4778 ++s;
4779
4780 switch (s[0])
4781 {
4782 case 'B':
4783 if (strcmp (s, "BS]") == 0)
4784 tc->class = XMC_BS;
4785 break;
4786 case 'D':
4787 if (strcmp (s, "DB]") == 0)
4788 tc->class = XMC_DB;
4789 else if (strcmp (s, "DS]") == 0)
4790 tc->class = XMC_DS;
4791 break;
4792 case 'G':
4793 if (strcmp (s, "GL]") == 0)
4794 tc->class = XMC_GL;
4795 break;
4796 case 'P':
4797 if (strcmp (s, "PR]") == 0)
4798 tc->class = XMC_PR;
4799 break;
4800 case 'R':
4801 if (strcmp (s, "RO]") == 0)
4802 tc->class = XMC_RO;
4803 else if (strcmp (s, "RW]") == 0)
4804 tc->class = XMC_RW;
4805 break;
4806 case 'S':
4807 if (strcmp (s, "SV]") == 0)
4808 tc->class = XMC_SV;
4809 break;
4810 case 'T':
4811 if (strcmp (s, "TC]") == 0)
4812 tc->class = XMC_TC;
4813 else if (strcmp (s, "TI]") == 0)
4814 tc->class = XMC_TI;
4815 else if (strcmp (s, "TB]") == 0)
4816 tc->class = XMC_TB;
4817 else if (strcmp (s, "TC0]") == 0 || strcmp (s, "T0]") == 0)
4818 tc->class = XMC_TC0;
4819 break;
4820 case 'U':
4821 if (strcmp (s, "UA]") == 0)
4822 tc->class = XMC_UA;
4823 else if (strcmp (s, "UC]") == 0)
4824 tc->class = XMC_UC;
4825 break;
4826 case 'X':
4827 if (strcmp (s, "XO]") == 0)
4828 tc->class = XMC_XO;
4829 break;
4830 }
4831
4832 if (tc->class == -1)
4833 as_bad (_("Unrecognized symbol suffix"));
4834 }
4835
4836 /* Set the class of a label based on where it is defined. This
4837 handles symbols without suffixes. Also, move the symbol so that it
4838 follows the csect symbol. */
4839
4840 void
4841 ppc_frob_label (sym)
4842 symbolS *sym;
4843 {
4844 if (ppc_current_csect != (symbolS *) NULL)
4845 {
4846 if (symbol_get_tc (sym)->class == -1)
4847 symbol_get_tc (sym)->class = symbol_get_tc (ppc_current_csect)->class;
4848
4849 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
4850 symbol_append (sym, symbol_get_tc (ppc_current_csect)->within,
4851 &symbol_rootP, &symbol_lastP);
4852 symbol_get_tc (ppc_current_csect)->within = sym;
4853 }
4854
4855 #ifdef OBJ_ELF
4856 dwarf2_emit_label (sym);
4857 #endif
4858 }
4859
4860 /* This variable is set by ppc_frob_symbol if any absolute symbols are
4861 seen. It tells ppc_adjust_symtab whether it needs to look through
4862 the symbols. */
4863
4864 static bfd_boolean ppc_saw_abs;
4865
4866 /* Change the name of a symbol just before writing it out. Set the
4867 real name if the .rename pseudo-op was used. Otherwise, remove any
4868 class suffix. Return 1 if the symbol should not be included in the
4869 symbol table. */
4870
4871 int
4872 ppc_frob_symbol (sym)
4873 symbolS *sym;
4874 {
4875 static symbolS *ppc_last_function;
4876 static symbolS *set_end;
4877
4878 /* Discard symbols that should not be included in the output symbol
4879 table. */
4880 if (! symbol_used_in_reloc_p (sym)
4881 && ((symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) != 0
4882 || (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
4883 && ! symbol_get_tc (sym)->output
4884 && S_GET_STORAGE_CLASS (sym) != C_FILE)))
4885 return 1;
4886
4887 /* This one will disappear anyway. Don't make a csect sym for it. */
4888 if (sym == abs_section_sym)
4889 return 1;
4890
4891 if (symbol_get_tc (sym)->real_name != (char *) NULL)
4892 S_SET_NAME (sym, symbol_get_tc (sym)->real_name);
4893 else
4894 {
4895 const char *name;
4896 const char *s;
4897
4898 name = S_GET_NAME (sym);
4899 s = strchr (name, '[');
4900 if (s != (char *) NULL)
4901 {
4902 unsigned int len;
4903 char *snew;
4904
4905 len = s - name;
4906 snew = xmalloc (len + 1);
4907 memcpy (snew, name, len);
4908 snew[len] = '\0';
4909
4910 S_SET_NAME (sym, snew);
4911 }
4912 }
4913
4914 if (set_end != (symbolS *) NULL)
4915 {
4916 SA_SET_SYM_ENDNDX (set_end, sym);
4917 set_end = NULL;
4918 }
4919
4920 if (SF_GET_FUNCTION (sym))
4921 {
4922 if (ppc_last_function != (symbolS *) NULL)
4923 as_bad (_("two .function pseudo-ops with no intervening .ef"));
4924 ppc_last_function = sym;
4925 if (symbol_get_tc (sym)->size != (symbolS *) NULL)
4926 {
4927 resolve_symbol_value (symbol_get_tc (sym)->size);
4928 SA_SET_SYM_FSIZE (sym,
4929 (long) S_GET_VALUE (symbol_get_tc (sym)->size));
4930 }
4931 }
4932 else if (S_GET_STORAGE_CLASS (sym) == C_FCN
4933 && strcmp (S_GET_NAME (sym), ".ef") == 0)
4934 {
4935 if (ppc_last_function == (symbolS *) NULL)
4936 as_bad (_(".ef with no preceding .function"));
4937 else
4938 {
4939 set_end = ppc_last_function;
4940 ppc_last_function = NULL;
4941
4942 /* We don't have a C_EFCN symbol, but we need to force the
4943 COFF backend to believe that it has seen one. */
4944 coff_last_function = NULL;
4945 }
4946 }
4947
4948 if (! (S_IS_EXTERNAL (sym) || S_IS_WEAK (sym))
4949 && (symbol_get_bfdsym (sym)->flags & BSF_SECTION_SYM) == 0
4950 && S_GET_STORAGE_CLASS (sym) != C_FILE
4951 && S_GET_STORAGE_CLASS (sym) != C_FCN
4952 && S_GET_STORAGE_CLASS (sym) != C_BLOCK
4953 && S_GET_STORAGE_CLASS (sym) != C_BSTAT
4954 && S_GET_STORAGE_CLASS (sym) != C_ESTAT
4955 && S_GET_STORAGE_CLASS (sym) != C_BINCL
4956 && S_GET_STORAGE_CLASS (sym) != C_EINCL
4957 && S_GET_SEGMENT (sym) != ppc_coff_debug_section)
4958 S_SET_STORAGE_CLASS (sym, C_HIDEXT);
4959
4960 if (S_GET_STORAGE_CLASS (sym) == C_EXT
4961 || S_GET_STORAGE_CLASS (sym) == C_HIDEXT)
4962 {
4963 int i;
4964 union internal_auxent *a;
4965
4966 /* Create a csect aux. */
4967 i = S_GET_NUMBER_AUXILIARY (sym);
4968 S_SET_NUMBER_AUXILIARY (sym, i + 1);
4969 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].u.auxent;
4970 if (symbol_get_tc (sym)->class == XMC_TC0)
4971 {
4972 /* This is the TOC table. */
4973 know (strcmp (S_GET_NAME (sym), "TOC") == 0);
4974 a->x_csect.x_scnlen.l = 0;
4975 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
4976 }
4977 else if (symbol_get_tc (sym)->subseg != 0)
4978 {
4979 /* This is a csect symbol. x_scnlen is the size of the
4980 csect. */
4981 if (symbol_get_tc (sym)->next == (symbolS *) NULL)
4982 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
4983 S_GET_SEGMENT (sym))
4984 - S_GET_VALUE (sym));
4985 else
4986 {
4987 resolve_symbol_value (symbol_get_tc (sym)->next);
4988 a->x_csect.x_scnlen.l = (S_GET_VALUE (symbol_get_tc (sym)->next)
4989 - S_GET_VALUE (sym));
4990 }
4991 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_SD;
4992 }
4993 else if (S_GET_SEGMENT (sym) == bss_section)
4994 {
4995 /* This is a common symbol. */
4996 a->x_csect.x_scnlen.l = symbol_get_frag (sym)->fr_offset;
4997 a->x_csect.x_smtyp = (symbol_get_tc (sym)->align << 3) | XTY_CM;
4998 if (S_IS_EXTERNAL (sym))
4999 symbol_get_tc (sym)->class = XMC_RW;
5000 else
5001 symbol_get_tc (sym)->class = XMC_BS;
5002 }
5003 else if (S_GET_SEGMENT (sym) == absolute_section)
5004 {
5005 /* This is an absolute symbol. The csect will be created by
5006 ppc_adjust_symtab. */
5007 ppc_saw_abs = TRUE;
5008 a->x_csect.x_smtyp = XTY_LD;
5009 if (symbol_get_tc (sym)->class == -1)
5010 symbol_get_tc (sym)->class = XMC_XO;
5011 }
5012 else if (! S_IS_DEFINED (sym))
5013 {
5014 /* This is an external symbol. */
5015 a->x_csect.x_scnlen.l = 0;
5016 a->x_csect.x_smtyp = XTY_ER;
5017 }
5018 else if (symbol_get_tc (sym)->class == XMC_TC)
5019 {
5020 symbolS *next;
5021
5022 /* This is a TOC definition. x_scnlen is the size of the
5023 TOC entry. */
5024 next = symbol_next (sym);
5025 while (symbol_get_tc (next)->class == XMC_TC0)
5026 next = symbol_next (next);
5027 if (next == (symbolS *) NULL
5028 || symbol_get_tc (next)->class != XMC_TC)
5029 {
5030 if (ppc_after_toc_frag == (fragS *) NULL)
5031 a->x_csect.x_scnlen.l = (bfd_section_size (stdoutput,
5032 data_section)
5033 - S_GET_VALUE (sym));
5034 else
5035 a->x_csect.x_scnlen.l = (ppc_after_toc_frag->fr_address
5036 - S_GET_VALUE (sym));
5037 }
5038 else
5039 {
5040 resolve_symbol_value (next);
5041 a->x_csect.x_scnlen.l = (S_GET_VALUE (next)
5042 - S_GET_VALUE (sym));
5043 }
5044 a->x_csect.x_smtyp = (2 << 3) | XTY_SD;
5045 }
5046 else
5047 {
5048 symbolS *csect;
5049
5050 /* This is a normal symbol definition. x_scnlen is the
5051 symbol index of the containing csect. */
5052 if (S_GET_SEGMENT (sym) == text_section)
5053 csect = ppc_text_csects;
5054 else if (S_GET_SEGMENT (sym) == data_section)
5055 csect = ppc_data_csects;
5056 else
5057 abort ();
5058
5059 /* Skip the initial dummy symbol. */
5060 csect = symbol_get_tc (csect)->next;
5061
5062 if (csect == (symbolS *) NULL)
5063 {
5064 as_warn (_("warning: symbol %s has no csect"), S_GET_NAME (sym));
5065 a->x_csect.x_scnlen.l = 0;
5066 }
5067 else
5068 {
5069 while (symbol_get_tc (csect)->next != (symbolS *) NULL)
5070 {
5071 resolve_symbol_value (symbol_get_tc (csect)->next);
5072 if (S_GET_VALUE (symbol_get_tc (csect)->next)
5073 > S_GET_VALUE (sym))
5074 break;
5075 csect = symbol_get_tc (csect)->next;
5076 }
5077
5078 a->x_csect.x_scnlen.p =
5079 coffsymbol (symbol_get_bfdsym (csect))->native;
5080 coffsymbol (symbol_get_bfdsym (sym))->native[i + 1].fix_scnlen =
5081 1;
5082 }
5083 a->x_csect.x_smtyp = XTY_LD;
5084 }
5085
5086 a->x_csect.x_parmhash = 0;
5087 a->x_csect.x_snhash = 0;
5088 if (symbol_get_tc (sym)->class == -1)
5089 a->x_csect.x_smclas = XMC_PR;
5090 else
5091 a->x_csect.x_smclas = symbol_get_tc (sym)->class;
5092 a->x_csect.x_stab = 0;
5093 a->x_csect.x_snstab = 0;
5094
5095 /* Don't let the COFF backend resort these symbols. */
5096 symbol_get_bfdsym (sym)->flags |= BSF_NOT_AT_END;
5097 }
5098 else if (S_GET_STORAGE_CLASS (sym) == C_BSTAT)
5099 {
5100 /* We want the value to be the symbol index of the referenced
5101 csect symbol. BFD will do that for us if we set the right
5102 flags. */
5103 asymbol *bsym = symbol_get_bfdsym (symbol_get_tc (sym)->within);
5104 combined_entry_type *c = coffsymbol (bsym)->native;
5105
5106 S_SET_VALUE (sym, (valueT) (size_t) c);
5107 coffsymbol (symbol_get_bfdsym (sym))->native->fix_value = 1;
5108 }
5109 else if (S_GET_STORAGE_CLASS (sym) == C_STSYM)
5110 {
5111 symbolS *block;
5112 symbolS *csect;
5113
5114 /* The value is the offset from the enclosing csect. */
5115 block = symbol_get_tc (sym)->within;
5116 csect = symbol_get_tc (block)->within;
5117 resolve_symbol_value (csect);
5118 S_SET_VALUE (sym, S_GET_VALUE (sym) - S_GET_VALUE (csect));
5119 }
5120 else if (S_GET_STORAGE_CLASS (sym) == C_BINCL
5121 || S_GET_STORAGE_CLASS (sym) == C_EINCL)
5122 {
5123 /* We want the value to be a file offset into the line numbers.
5124 BFD will do that for us if we set the right flags. We have
5125 already set the value correctly. */
5126 coffsymbol (symbol_get_bfdsym (sym))->native->fix_line = 1;
5127 }
5128
5129 return 0;
5130 }
5131
5132 /* Adjust the symbol table. This creates csect symbols for all
5133 absolute symbols. */
5134
5135 void
5136 ppc_adjust_symtab ()
5137 {
5138 symbolS *sym;
5139
5140 if (! ppc_saw_abs)
5141 return;
5142
5143 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
5144 {
5145 symbolS *csect;
5146 int i;
5147 union internal_auxent *a;
5148
5149 if (S_GET_SEGMENT (sym) != absolute_section)
5150 continue;
5151
5152 csect = symbol_create (".abs[XO]", absolute_section,
5153 S_GET_VALUE (sym), &zero_address_frag);
5154 symbol_get_bfdsym (csect)->value = S_GET_VALUE (sym);
5155 S_SET_STORAGE_CLASS (csect, C_HIDEXT);
5156 i = S_GET_NUMBER_AUXILIARY (csect);
5157 S_SET_NUMBER_AUXILIARY (csect, i + 1);
5158 a = &coffsymbol (symbol_get_bfdsym (csect))->native[i + 1].u.auxent;
5159 a->x_csect.x_scnlen.l = 0;
5160 a->x_csect.x_smtyp = XTY_SD;
5161 a->x_csect.x_parmhash = 0;
5162 a->x_csect.x_snhash = 0;
5163 a->x_csect.x_smclas = XMC_XO;
5164 a->x_csect.x_stab = 0;
5165 a->x_csect.x_snstab = 0;
5166
5167 symbol_insert (csect, sym, &symbol_rootP, &symbol_lastP);
5168
5169 i = S_GET_NUMBER_AUXILIARY (sym);
5170 a = &coffsymbol (symbol_get_bfdsym (sym))->native[i].u.auxent;
5171 a->x_csect.x_scnlen.p = coffsymbol (symbol_get_bfdsym (csect))->native;
5172 coffsymbol (symbol_get_bfdsym (sym))->native[i].fix_scnlen = 1;
5173 }
5174
5175 ppc_saw_abs = FALSE;
5176 }
5177
5178 /* Set the VMA for a section. This is called on all the sections in
5179 turn. */
5180
5181 void
5182 ppc_frob_section (sec)
5183 asection *sec;
5184 {
5185 static bfd_vma vma = 0;
5186
5187 vma = md_section_align (sec, vma);
5188 bfd_set_section_vma (stdoutput, sec, vma);
5189 vma += bfd_section_size (stdoutput, sec);
5190 }
5191
5192 #endif /* OBJ_XCOFF */
5193 \f
5194 /* Turn a string in input_line_pointer into a floating point constant
5195 of type TYPE, and store the appropriate bytes in *LITP. The number
5196 of LITTLENUMS emitted is stored in *SIZEP. An error message is
5197 returned, or NULL on OK. */
5198
5199 char *
5200 md_atof (type, litp, sizep)
5201 int type;
5202 char *litp;
5203 int *sizep;
5204 {
5205 int prec;
5206 LITTLENUM_TYPE words[4];
5207 char *t;
5208 int i;
5209
5210 switch (type)
5211 {
5212 case 'f':
5213 prec = 2;
5214 break;
5215
5216 case 'd':
5217 prec = 4;
5218 break;
5219
5220 default:
5221 *sizep = 0;
5222 return _("bad call to md_atof");
5223 }
5224
5225 t = atof_ieee (input_line_pointer, type, words);
5226 if (t)
5227 input_line_pointer = t;
5228
5229 *sizep = prec * 2;
5230
5231 if (target_big_endian)
5232 {
5233 for (i = 0; i < prec; i++)
5234 {
5235 md_number_to_chars (litp, (valueT) words[i], 2);
5236 litp += 2;
5237 }
5238 }
5239 else
5240 {
5241 for (i = prec - 1; i >= 0; i--)
5242 {
5243 md_number_to_chars (litp, (valueT) words[i], 2);
5244 litp += 2;
5245 }
5246 }
5247
5248 return NULL;
5249 }
5250
5251 /* Write a value out to the object file, using the appropriate
5252 endianness. */
5253
5254 void
5255 md_number_to_chars (buf, val, n)
5256 char *buf;
5257 valueT val;
5258 int n;
5259 {
5260 if (target_big_endian)
5261 number_to_chars_bigendian (buf, val, n);
5262 else
5263 number_to_chars_littleendian (buf, val, n);
5264 }
5265
5266 /* Align a section (I don't know why this is machine dependent). */
5267
5268 valueT
5269 md_section_align (seg, addr)
5270 asection *seg;
5271 valueT addr;
5272 {
5273 int align = bfd_get_section_alignment (stdoutput, seg);
5274
5275 return ((addr + (1 << align) - 1) & (-1 << align));
5276 }
5277
5278 /* We don't have any form of relaxing. */
5279
5280 int
5281 md_estimate_size_before_relax (fragp, seg)
5282 fragS *fragp ATTRIBUTE_UNUSED;
5283 asection *seg ATTRIBUTE_UNUSED;
5284 {
5285 abort ();
5286 return 0;
5287 }
5288
5289 /* Convert a machine dependent frag. We never generate these. */
5290
5291 void
5292 md_convert_frag (abfd, sec, fragp)
5293 bfd *abfd ATTRIBUTE_UNUSED;
5294 asection *sec ATTRIBUTE_UNUSED;
5295 fragS *fragp ATTRIBUTE_UNUSED;
5296 {
5297 abort ();
5298 }
5299
5300 /* We have no need to default values of symbols. */
5301
5302 symbolS *
5303 md_undefined_symbol (name)
5304 char *name ATTRIBUTE_UNUSED;
5305 {
5306 return 0;
5307 }
5308 \f
5309 /* Functions concerning relocs. */
5310
5311 /* The location from which a PC relative jump should be calculated,
5312 given a PC relative reloc. */
5313
5314 long
5315 md_pcrel_from_section (fixp, sec)
5316 fixS *fixp;
5317 segT sec ATTRIBUTE_UNUSED;
5318 {
5319 return fixp->fx_frag->fr_address + fixp->fx_where;
5320 }
5321
5322 #ifdef OBJ_XCOFF
5323
5324 /* This is called to see whether a fixup should be adjusted to use a
5325 section symbol. We take the opportunity to change a fixup against
5326 a symbol in the TOC subsegment into a reloc against the
5327 corresponding .tc symbol. */
5328
5329 int
5330 ppc_fix_adjustable (fix)
5331 fixS *fix;
5332 {
5333 valueT val = resolve_symbol_value (fix->fx_addsy);
5334 segT symseg = S_GET_SEGMENT (fix->fx_addsy);
5335 TC_SYMFIELD_TYPE *tc;
5336
5337 if (symseg == absolute_section)
5338 return 0;
5339
5340 if (ppc_toc_csect != (symbolS *) NULL
5341 && fix->fx_addsy != ppc_toc_csect
5342 && symseg == data_section
5343 && val >= ppc_toc_frag->fr_address
5344 && (ppc_after_toc_frag == (fragS *) NULL
5345 || val < ppc_after_toc_frag->fr_address))
5346 {
5347 symbolS *sy;
5348
5349 for (sy = symbol_next (ppc_toc_csect);
5350 sy != (symbolS *) NULL;
5351 sy = symbol_next (sy))
5352 {
5353 TC_SYMFIELD_TYPE *sy_tc = symbol_get_tc (sy);
5354
5355 if (sy_tc->class == XMC_TC0)
5356 continue;
5357 if (sy_tc->class != XMC_TC)
5358 break;
5359 if (val == resolve_symbol_value (sy))
5360 {
5361 fix->fx_addsy = sy;
5362 fix->fx_addnumber = val - ppc_toc_frag->fr_address;
5363 return 0;
5364 }
5365 }
5366
5367 as_bad_where (fix->fx_file, fix->fx_line,
5368 _("symbol in .toc does not match any .tc"));
5369 }
5370
5371 /* Possibly adjust the reloc to be against the csect. */
5372 tc = symbol_get_tc (fix->fx_addsy);
5373 if (tc->subseg == 0
5374 && tc->class != XMC_TC0
5375 && tc->class != XMC_TC
5376 && symseg != bss_section
5377 /* Don't adjust if this is a reloc in the toc section. */
5378 && (symseg != data_section
5379 || ppc_toc_csect == NULL
5380 || val < ppc_toc_frag->fr_address
5381 || (ppc_after_toc_frag != NULL
5382 && val >= ppc_after_toc_frag->fr_address)))
5383 {
5384 symbolS *csect;
5385 symbolS *next_csect;
5386
5387 if (symseg == text_section)
5388 csect = ppc_text_csects;
5389 else if (symseg == data_section)
5390 csect = ppc_data_csects;
5391 else
5392 abort ();
5393
5394 /* Skip the initial dummy symbol. */
5395 csect = symbol_get_tc (csect)->next;
5396
5397 if (csect != (symbolS *) NULL)
5398 {
5399 while ((next_csect = symbol_get_tc (csect)->next) != (symbolS *) NULL
5400 && (symbol_get_frag (next_csect)->fr_address <= val))
5401 {
5402 /* If the csect address equals the symbol value, then we
5403 have to look through the full symbol table to see
5404 whether this is the csect we want. Note that we will
5405 only get here if the csect has zero length. */
5406 if (symbol_get_frag (csect)->fr_address == val
5407 && S_GET_VALUE (csect) == val)
5408 {
5409 symbolS *scan;
5410
5411 for (scan = symbol_next (csect);
5412 scan != NULL;
5413 scan = symbol_next (scan))
5414 {
5415 if (symbol_get_tc (scan)->subseg != 0)
5416 break;
5417 if (scan == fix->fx_addsy)
5418 break;
5419 }
5420
5421 /* If we found the symbol before the next csect
5422 symbol, then this is the csect we want. */
5423 if (scan == fix->fx_addsy)
5424 break;
5425 }
5426
5427 csect = next_csect;
5428 }
5429
5430 fix->fx_offset += val - symbol_get_frag (csect)->fr_address;
5431 fix->fx_addsy = csect;
5432 }
5433 return 0;
5434 }
5435
5436 /* Adjust a reloc against a .lcomm symbol to be against the base
5437 .lcomm. */
5438 if (symseg == bss_section
5439 && ! S_IS_EXTERNAL (fix->fx_addsy))
5440 {
5441 symbolS *sy = symbol_get_frag (fix->fx_addsy)->fr_symbol;
5442
5443 fix->fx_offset += val - resolve_symbol_value (sy);
5444 fix->fx_addsy = sy;
5445 }
5446
5447 return 0;
5448 }
5449
5450 /* A reloc from one csect to another must be kept. The assembler
5451 will, of course, keep relocs between sections, and it will keep
5452 absolute relocs, but we need to force it to keep PC relative relocs
5453 between two csects in the same section. */
5454
5455 int
5456 ppc_force_relocation (fix)
5457 fixS *fix;
5458 {
5459 /* At this point fix->fx_addsy should already have been converted to
5460 a csect symbol. If the csect does not include the fragment, then
5461 we need to force the relocation. */
5462 if (fix->fx_pcrel
5463 && fix->fx_addsy != NULL
5464 && symbol_get_tc (fix->fx_addsy)->subseg != 0
5465 && ((symbol_get_frag (fix->fx_addsy)->fr_address
5466 > fix->fx_frag->fr_address)
5467 || (symbol_get_tc (fix->fx_addsy)->next != NULL
5468 && (symbol_get_frag (symbol_get_tc (fix->fx_addsy)->next)->fr_address
5469 <= fix->fx_frag->fr_address))))
5470 return 1;
5471
5472 return generic_force_reloc (fix);
5473 }
5474
5475 #endif /* OBJ_XCOFF */
5476
5477 #ifdef OBJ_ELF
5478 /* If this function returns non-zero, it guarantees that a relocation
5479 will be emitted for a fixup. */
5480
5481 int
5482 ppc_force_relocation (fix)
5483 fixS *fix;
5484 {
5485 /* Branch prediction relocations must force a relocation, as must
5486 the vtable description relocs. */
5487 switch (fix->fx_r_type)
5488 {
5489 case BFD_RELOC_PPC_B16_BRTAKEN:
5490 case BFD_RELOC_PPC_B16_BRNTAKEN:
5491 case BFD_RELOC_PPC_BA16_BRTAKEN:
5492 case BFD_RELOC_PPC_BA16_BRNTAKEN:
5493 case BFD_RELOC_24_PLT_PCREL:
5494 case BFD_RELOC_PPC64_TOC:
5495 return 1;
5496 default:
5497 break;
5498 }
5499
5500 if (fix->fx_r_type >= BFD_RELOC_PPC_TLS
5501 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA)
5502 return 1;
5503
5504 return generic_force_reloc (fix);
5505 }
5506
5507 int
5508 ppc_fix_adjustable (fix)
5509 fixS *fix;
5510 {
5511 return (fix->fx_r_type != BFD_RELOC_16_GOTOFF
5512 && fix->fx_r_type != BFD_RELOC_LO16_GOTOFF
5513 && fix->fx_r_type != BFD_RELOC_HI16_GOTOFF
5514 && fix->fx_r_type != BFD_RELOC_HI16_S_GOTOFF
5515 && fix->fx_r_type != BFD_RELOC_GPREL16
5516 && fix->fx_r_type != BFD_RELOC_VTABLE_INHERIT
5517 && fix->fx_r_type != BFD_RELOC_VTABLE_ENTRY
5518 && !(fix->fx_r_type >= BFD_RELOC_PPC_TLS
5519 && fix->fx_r_type <= BFD_RELOC_PPC64_DTPREL16_HIGHESTA));
5520 }
5521 #endif
5522
5523 /* Apply a fixup to the object code. This is called for all the
5524 fixups we generated by the call to fix_new_exp, above. In the call
5525 above we used a reloc code which was the largest legal reloc code
5526 plus the operand index. Here we undo that to recover the operand
5527 index. At this point all symbol values should be fully resolved,
5528 and we attempt to completely resolve the reloc. If we can not do
5529 that, we determine the correct reloc code and put it back in the
5530 fixup. */
5531
5532 void
5533 md_apply_fix (fixP, valP, seg)
5534 fixS *fixP;
5535 valueT * valP;
5536 segT seg ATTRIBUTE_UNUSED;
5537 {
5538 valueT value = * valP;
5539
5540 #ifdef OBJ_ELF
5541 if (fixP->fx_addsy != NULL)
5542 {
5543 /* Hack around bfd_install_relocation brain damage. */
5544 if (fixP->fx_pcrel)
5545 value += fixP->fx_frag->fr_address + fixP->fx_where;
5546 }
5547 else
5548 fixP->fx_done = 1;
5549 #else
5550 /* FIXME FIXME FIXME: The value we are passed in *valP includes
5551 the symbol values. If we are doing this relocation the code in
5552 write.c is going to call bfd_install_relocation, which is also
5553 going to use the symbol value. That means that if the reloc is
5554 fully resolved we want to use *valP since bfd_install_relocation is
5555 not being used.
5556 However, if the reloc is not fully resolved we do not want to use
5557 *valP, and must use fx_offset instead. However, if the reloc
5558 is PC relative, we do want to use *valP since it includes the
5559 result of md_pcrel_from. This is confusing. */
5560 if (fixP->fx_addsy == (symbolS *) NULL)
5561 fixP->fx_done = 1;
5562
5563 else if (fixP->fx_pcrel)
5564 ;
5565
5566 else
5567 value = fixP->fx_offset;
5568 #endif
5569
5570 if (fixP->fx_subsy != (symbolS *) NULL)
5571 {
5572 /* We can't actually support subtracting a symbol. */
5573 as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
5574 }
5575
5576 if ((int) fixP->fx_r_type >= (int) BFD_RELOC_UNUSED)
5577 {
5578 int opindex;
5579 const struct powerpc_operand *operand;
5580 char *where;
5581 unsigned long insn;
5582
5583 opindex = (int) fixP->fx_r_type - (int) BFD_RELOC_UNUSED;
5584
5585 operand = &powerpc_operands[opindex];
5586
5587 #ifdef OBJ_XCOFF
5588 /* An instruction like `lwz 9,sym(30)' when `sym' is not a TOC symbol
5589 does not generate a reloc. It uses the offset of `sym' within its
5590 csect. Other usages, such as `.long sym', generate relocs. This
5591 is the documented behaviour of non-TOC symbols. */
5592 if ((operand->flags & PPC_OPERAND_PARENS) != 0
5593 && operand->bits == 16
5594 && operand->shift == 0
5595 && (operand->insert == NULL || ppc_obj64)
5596 && fixP->fx_addsy != NULL
5597 && symbol_get_tc (fixP->fx_addsy)->subseg != 0
5598 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC
5599 && symbol_get_tc (fixP->fx_addsy)->class != XMC_TC0
5600 && S_GET_SEGMENT (fixP->fx_addsy) != bss_section)
5601 {
5602 value = fixP->fx_offset;
5603 fixP->fx_done = 1;
5604 }
5605 #endif
5606
5607 /* Fetch the instruction, insert the fully resolved operand
5608 value, and stuff the instruction back again. */
5609 where = fixP->fx_frag->fr_literal + fixP->fx_where;
5610 if (target_big_endian)
5611 insn = bfd_getb32 ((unsigned char *) where);
5612 else
5613 insn = bfd_getl32 ((unsigned char *) where);
5614 insn = ppc_insert_operand (insn, operand, (offsetT) value,
5615 fixP->fx_file, fixP->fx_line);
5616 if (target_big_endian)
5617 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5618 else
5619 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
5620
5621 if (fixP->fx_done)
5622 /* Nothing else to do here. */
5623 return;
5624
5625 assert (fixP->fx_addsy != NULL);
5626
5627 /* Determine a BFD reloc value based on the operand information.
5628 We are only prepared to turn a few of the operands into
5629 relocs. */
5630 if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5631 && operand->bits == 26
5632 && operand->shift == 0)
5633 fixP->fx_r_type = BFD_RELOC_PPC_B26;
5634 else if ((operand->flags & PPC_OPERAND_RELATIVE) != 0
5635 && operand->bits == 16
5636 && operand->shift == 0)
5637 {
5638 fixP->fx_r_type = BFD_RELOC_PPC_B16;
5639 #ifdef OBJ_XCOFF
5640 fixP->fx_size = 2;
5641 if (target_big_endian)
5642 fixP->fx_where += 2;
5643 #endif
5644 }
5645 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5646 && operand->bits == 26
5647 && operand->shift == 0)
5648 fixP->fx_r_type = BFD_RELOC_PPC_BA26;
5649 else if ((operand->flags & PPC_OPERAND_ABSOLUTE) != 0
5650 && operand->bits == 16
5651 && operand->shift == 0)
5652 {
5653 fixP->fx_r_type = BFD_RELOC_PPC_BA16;
5654 #ifdef OBJ_XCOFF
5655 fixP->fx_size = 2;
5656 if (target_big_endian)
5657 fixP->fx_where += 2;
5658 #endif
5659 }
5660 #if defined (OBJ_XCOFF) || defined (OBJ_ELF)
5661 else if ((operand->flags & PPC_OPERAND_PARENS) != 0
5662 && operand->bits == 16
5663 && operand->shift == 0)
5664 {
5665 if (ppc_is_toc_sym (fixP->fx_addsy))
5666 {
5667 fixP->fx_r_type = BFD_RELOC_PPC_TOC16;
5668 #ifdef OBJ_ELF
5669 if (ppc_obj64
5670 && (operand->flags & PPC_OPERAND_DS) != 0)
5671 fixP->fx_r_type = BFD_RELOC_PPC64_TOC16_DS;
5672 #endif
5673 }
5674 else
5675 {
5676 fixP->fx_r_type = BFD_RELOC_16;
5677 #ifdef OBJ_ELF
5678 if (ppc_obj64
5679 && (operand->flags & PPC_OPERAND_DS) != 0)
5680 fixP->fx_r_type = BFD_RELOC_PPC64_ADDR16_DS;
5681 #endif
5682 }
5683 fixP->fx_size = 2;
5684 if (target_big_endian)
5685 fixP->fx_where += 2;
5686 }
5687 #endif /* defined (OBJ_XCOFF) || defined (OBJ_ELF) */
5688 else
5689 {
5690 char *sfile;
5691 unsigned int sline;
5692
5693 /* Use expr_symbol_where to see if this is an expression
5694 symbol. */
5695 if (expr_symbol_where (fixP->fx_addsy, &sfile, &sline))
5696 as_bad_where (fixP->fx_file, fixP->fx_line,
5697 _("unresolved expression that must be resolved"));
5698 else
5699 as_bad_where (fixP->fx_file, fixP->fx_line,
5700 _("unsupported relocation against %s"),
5701 S_GET_NAME (fixP->fx_addsy));
5702 fixP->fx_done = 1;
5703 return;
5704 }
5705 }
5706 else
5707 {
5708 #ifdef OBJ_ELF
5709 ppc_elf_validate_fix (fixP, seg);
5710 #endif
5711 switch (fixP->fx_r_type)
5712 {
5713 case BFD_RELOC_CTOR:
5714 if (ppc_obj64)
5715 goto ctor64;
5716 /* fall through */
5717
5718 case BFD_RELOC_32:
5719 if (fixP->fx_pcrel)
5720 fixP->fx_r_type = BFD_RELOC_32_PCREL;
5721 /* fall through */
5722
5723 case BFD_RELOC_RVA:
5724 case BFD_RELOC_32_PCREL:
5725 case BFD_RELOC_PPC_EMB_NADDR32:
5726 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5727 value, 4);
5728 break;
5729
5730 case BFD_RELOC_64:
5731 ctor64:
5732 if (fixP->fx_pcrel)
5733 fixP->fx_r_type = BFD_RELOC_64_PCREL;
5734 /* fall through */
5735
5736 case BFD_RELOC_64_PCREL:
5737 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5738 value, 8);
5739 break;
5740
5741 case BFD_RELOC_GPREL16:
5742 case BFD_RELOC_16_GOT_PCREL:
5743 case BFD_RELOC_16_GOTOFF:
5744 case BFD_RELOC_LO16_GOTOFF:
5745 case BFD_RELOC_HI16_GOTOFF:
5746 case BFD_RELOC_HI16_S_GOTOFF:
5747 case BFD_RELOC_16_BASEREL:
5748 case BFD_RELOC_LO16_BASEREL:
5749 case BFD_RELOC_HI16_BASEREL:
5750 case BFD_RELOC_HI16_S_BASEREL:
5751 case BFD_RELOC_PPC_EMB_NADDR16:
5752 case BFD_RELOC_PPC_EMB_NADDR16_LO:
5753 case BFD_RELOC_PPC_EMB_NADDR16_HI:
5754 case BFD_RELOC_PPC_EMB_NADDR16_HA:
5755 case BFD_RELOC_PPC_EMB_SDAI16:
5756 case BFD_RELOC_PPC_EMB_SDA2REL:
5757 case BFD_RELOC_PPC_EMB_SDA2I16:
5758 case BFD_RELOC_PPC_EMB_RELSEC16:
5759 case BFD_RELOC_PPC_EMB_RELST_LO:
5760 case BFD_RELOC_PPC_EMB_RELST_HI:
5761 case BFD_RELOC_PPC_EMB_RELST_HA:
5762 case BFD_RELOC_PPC_EMB_RELSDA:
5763 case BFD_RELOC_PPC_TOC16:
5764 #ifdef OBJ_ELF
5765 case BFD_RELOC_PPC64_TOC16_LO:
5766 case BFD_RELOC_PPC64_TOC16_HI:
5767 case BFD_RELOC_PPC64_TOC16_HA:
5768 #endif
5769 if (fixP->fx_pcrel)
5770 {
5771 if (fixP->fx_addsy != NULL)
5772 as_bad_where (fixP->fx_file, fixP->fx_line,
5773 _("cannot emit PC relative %s relocation against %s"),
5774 bfd_get_reloc_code_name (fixP->fx_r_type),
5775 S_GET_NAME (fixP->fx_addsy));
5776 else
5777 as_bad_where (fixP->fx_file, fixP->fx_line,
5778 _("cannot emit PC relative %s relocation"),
5779 bfd_get_reloc_code_name (fixP->fx_r_type));
5780 }
5781
5782 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5783 value, 2);
5784 break;
5785
5786 case BFD_RELOC_16:
5787 if (fixP->fx_pcrel)
5788 fixP->fx_r_type = BFD_RELOC_16_PCREL;
5789 /* fall through */
5790
5791 case BFD_RELOC_16_PCREL:
5792 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5793 value, 2);
5794 break;
5795
5796 case BFD_RELOC_LO16:
5797 if (fixP->fx_pcrel)
5798 fixP->fx_r_type = BFD_RELOC_LO16_PCREL;
5799 /* fall through */
5800
5801 case BFD_RELOC_LO16_PCREL:
5802 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5803 value, 2);
5804 break;
5805
5806 /* This case happens when you write, for example,
5807 lis %r3,(L1-L2)@ha
5808 where L1 and L2 are defined later. */
5809 case BFD_RELOC_HI16:
5810 if (fixP->fx_pcrel)
5811 fixP->fx_r_type = BFD_RELOC_HI16_PCREL;
5812 /* fall through */
5813
5814 case BFD_RELOC_HI16_PCREL:
5815 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5816 PPC_HI (value), 2);
5817 break;
5818
5819 case BFD_RELOC_HI16_S:
5820 if (fixP->fx_pcrel)
5821 fixP->fx_r_type = BFD_RELOC_HI16_S_PCREL;
5822 /* fall through */
5823
5824 case BFD_RELOC_HI16_S_PCREL:
5825 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5826 PPC_HA (value), 2);
5827 break;
5828
5829 #ifdef OBJ_ELF
5830 case BFD_RELOC_PPC64_HIGHER:
5831 if (fixP->fx_pcrel)
5832 abort ();
5833 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5834 PPC_HIGHER (value), 2);
5835 break;
5836
5837 case BFD_RELOC_PPC64_HIGHER_S:
5838 if (fixP->fx_pcrel)
5839 abort ();
5840 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5841 PPC_HIGHERA (value), 2);
5842 break;
5843
5844 case BFD_RELOC_PPC64_HIGHEST:
5845 if (fixP->fx_pcrel)
5846 abort ();
5847 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5848 PPC_HIGHEST (value), 2);
5849 break;
5850
5851 case BFD_RELOC_PPC64_HIGHEST_S:
5852 if (fixP->fx_pcrel)
5853 abort ();
5854 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5855 PPC_HIGHESTA (value), 2);
5856 break;
5857
5858 case BFD_RELOC_PPC64_ADDR16_DS:
5859 case BFD_RELOC_PPC64_ADDR16_LO_DS:
5860 case BFD_RELOC_PPC64_GOT16_DS:
5861 case BFD_RELOC_PPC64_GOT16_LO_DS:
5862 case BFD_RELOC_PPC64_PLT16_LO_DS:
5863 case BFD_RELOC_PPC64_SECTOFF_DS:
5864 case BFD_RELOC_PPC64_SECTOFF_LO_DS:
5865 case BFD_RELOC_PPC64_TOC16_DS:
5866 case BFD_RELOC_PPC64_TOC16_LO_DS:
5867 case BFD_RELOC_PPC64_PLTGOT16_DS:
5868 case BFD_RELOC_PPC64_PLTGOT16_LO_DS:
5869 if (fixP->fx_pcrel)
5870 abort ();
5871 {
5872 char *where = fixP->fx_frag->fr_literal + fixP->fx_where;
5873 unsigned long val, mask;
5874
5875 if (target_big_endian)
5876 val = bfd_getb32 (where - 2);
5877 else
5878 val = bfd_getl32 (where);
5879 mask = 0xfffc;
5880 /* lq insns reserve the four lsbs. */
5881 if ((ppc_cpu & PPC_OPCODE_POWER4) != 0
5882 && (val & (0x3f << 26)) == (56u << 26))
5883 mask = 0xfff0;
5884 val |= value & mask;
5885 if (target_big_endian)
5886 bfd_putb16 ((bfd_vma) val, where);
5887 else
5888 bfd_putl16 ((bfd_vma) val, where);
5889 }
5890 break;
5891
5892 case BFD_RELOC_PPC_B16_BRTAKEN:
5893 case BFD_RELOC_PPC_B16_BRNTAKEN:
5894 case BFD_RELOC_PPC_BA16_BRTAKEN:
5895 case BFD_RELOC_PPC_BA16_BRNTAKEN:
5896 break;
5897
5898 case BFD_RELOC_PPC_TLS:
5899 break;
5900
5901 case BFD_RELOC_PPC_DTPMOD:
5902 case BFD_RELOC_PPC_TPREL16:
5903 case BFD_RELOC_PPC_TPREL16_LO:
5904 case BFD_RELOC_PPC_TPREL16_HI:
5905 case BFD_RELOC_PPC_TPREL16_HA:
5906 case BFD_RELOC_PPC_TPREL:
5907 case BFD_RELOC_PPC_DTPREL16:
5908 case BFD_RELOC_PPC_DTPREL16_LO:
5909 case BFD_RELOC_PPC_DTPREL16_HI:
5910 case BFD_RELOC_PPC_DTPREL16_HA:
5911 case BFD_RELOC_PPC_DTPREL:
5912 case BFD_RELOC_PPC_GOT_TLSGD16:
5913 case BFD_RELOC_PPC_GOT_TLSGD16_LO:
5914 case BFD_RELOC_PPC_GOT_TLSGD16_HI:
5915 case BFD_RELOC_PPC_GOT_TLSGD16_HA:
5916 case BFD_RELOC_PPC_GOT_TLSLD16:
5917 case BFD_RELOC_PPC_GOT_TLSLD16_LO:
5918 case BFD_RELOC_PPC_GOT_TLSLD16_HI:
5919 case BFD_RELOC_PPC_GOT_TLSLD16_HA:
5920 case BFD_RELOC_PPC_GOT_TPREL16:
5921 case BFD_RELOC_PPC_GOT_TPREL16_LO:
5922 case BFD_RELOC_PPC_GOT_TPREL16_HI:
5923 case BFD_RELOC_PPC_GOT_TPREL16_HA:
5924 case BFD_RELOC_PPC_GOT_DTPREL16:
5925 case BFD_RELOC_PPC_GOT_DTPREL16_LO:
5926 case BFD_RELOC_PPC_GOT_DTPREL16_HI:
5927 case BFD_RELOC_PPC_GOT_DTPREL16_HA:
5928 case BFD_RELOC_PPC64_TPREL16_DS:
5929 case BFD_RELOC_PPC64_TPREL16_LO_DS:
5930 case BFD_RELOC_PPC64_TPREL16_HIGHER:
5931 case BFD_RELOC_PPC64_TPREL16_HIGHERA:
5932 case BFD_RELOC_PPC64_TPREL16_HIGHEST:
5933 case BFD_RELOC_PPC64_TPREL16_HIGHESTA:
5934 case BFD_RELOC_PPC64_DTPREL16_DS:
5935 case BFD_RELOC_PPC64_DTPREL16_LO_DS:
5936 case BFD_RELOC_PPC64_DTPREL16_HIGHER:
5937 case BFD_RELOC_PPC64_DTPREL16_HIGHERA:
5938 case BFD_RELOC_PPC64_DTPREL16_HIGHEST:
5939 case BFD_RELOC_PPC64_DTPREL16_HIGHESTA:
5940 S_SET_THREAD_LOCAL (fixP->fx_addsy);
5941 break;
5942 #endif
5943 /* Because SDA21 modifies the register field, the size is set to 4
5944 bytes, rather than 2, so offset it here appropriately. */
5945 case BFD_RELOC_PPC_EMB_SDA21:
5946 if (fixP->fx_pcrel)
5947 abort ();
5948
5949 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where
5950 + ((target_big_endian) ? 2 : 0),
5951 value, 2);
5952 break;
5953
5954 case BFD_RELOC_8:
5955 if (fixP->fx_pcrel)
5956 {
5957 /* This can occur if there is a bug in the input assembler, eg:
5958 ".byte <undefined_symbol> - ." */
5959 if (fixP->fx_addsy)
5960 as_bad (_("Unable to handle reference to symbol %s"),
5961 S_GET_NAME (fixP->fx_addsy));
5962 else
5963 as_bad (_("Unable to resolve expression"));
5964 fixP->fx_done = 1;
5965 }
5966 else
5967 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
5968 value, 1);
5969 break;
5970
5971 case BFD_RELOC_24_PLT_PCREL:
5972 case BFD_RELOC_PPC_LOCAL24PC:
5973 if (!fixP->fx_pcrel && !fixP->fx_done)
5974 abort ();
5975
5976 if (fixP->fx_done)
5977 {
5978 char *where;
5979 unsigned long insn;
5980
5981 /* Fetch the instruction, insert the fully resolved operand
5982 value, and stuff the instruction back again. */
5983 where = fixP->fx_frag->fr_literal + fixP->fx_where;
5984 if (target_big_endian)
5985 insn = bfd_getb32 ((unsigned char *) where);
5986 else
5987 insn = bfd_getl32 ((unsigned char *) where);
5988 if ((value & 3) != 0)
5989 as_bad_where (fixP->fx_file, fixP->fx_line,
5990 _("must branch to an address a multiple of 4"));
5991 if ((offsetT) value < -0x40000000
5992 || (offsetT) value >= 0x40000000)
5993 as_bad_where (fixP->fx_file, fixP->fx_line,
5994 _("@local or @plt branch destination is too far away, %ld bytes"),
5995 (long) value);
5996 insn = insn | (value & 0x03fffffc);
5997 if (target_big_endian)
5998 bfd_putb32 ((bfd_vma) insn, (unsigned char *) where);
5999 else
6000 bfd_putl32 ((bfd_vma) insn, (unsigned char *) where);
6001 }
6002 break;
6003
6004 case BFD_RELOC_VTABLE_INHERIT:
6005 fixP->fx_done = 0;
6006 if (fixP->fx_addsy
6007 && !S_IS_DEFINED (fixP->fx_addsy)
6008 && !S_IS_WEAK (fixP->fx_addsy))
6009 S_SET_WEAK (fixP->fx_addsy);
6010 break;
6011
6012 case BFD_RELOC_VTABLE_ENTRY:
6013 fixP->fx_done = 0;
6014 break;
6015
6016 #ifdef OBJ_ELF
6017 /* Generated by reference to `sym@tocbase'. The sym is
6018 ignored by the linker. */
6019 case BFD_RELOC_PPC64_TOC:
6020 fixP->fx_done = 0;
6021 break;
6022 #endif
6023 default:
6024 fprintf (stderr,
6025 _("Gas failure, reloc value %d\n"), fixP->fx_r_type);
6026 fflush (stderr);
6027 abort ();
6028 }
6029 }
6030
6031 #ifdef OBJ_ELF
6032 fixP->fx_addnumber = value;
6033
6034 /* PowerPC uses RELA relocs, ie. the reloc addend is stored separately
6035 from the section contents. If we are going to be emitting a reloc
6036 then the section contents are immaterial, so don't warn if they
6037 happen to overflow. Leave such warnings to ld. */
6038 if (!fixP->fx_done)
6039 fixP->fx_no_overflow = 1;
6040 #else
6041 if (fixP->fx_r_type != BFD_RELOC_PPC_TOC16)
6042 fixP->fx_addnumber = 0;
6043 else
6044 {
6045 #ifdef TE_PE
6046 fixP->fx_addnumber = 0;
6047 #else
6048 /* We want to use the offset within the data segment of the
6049 symbol, not the actual VMA of the symbol. */
6050 fixP->fx_addnumber =
6051 - bfd_get_section_vma (stdoutput, S_GET_SEGMENT (fixP->fx_addsy));
6052 #endif
6053 }
6054 #endif
6055 }
6056
6057 /* Generate a reloc for a fixup. */
6058
6059 arelent *
6060 tc_gen_reloc (seg, fixp)
6061 asection *seg ATTRIBUTE_UNUSED;
6062 fixS *fixp;
6063 {
6064 arelent *reloc;
6065
6066 reloc = (arelent *) xmalloc (sizeof (arelent));
6067
6068 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
6069 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
6070 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
6071 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
6072 if (reloc->howto == (reloc_howto_type *) NULL)
6073 {
6074 as_bad_where (fixp->fx_file, fixp->fx_line,
6075 _("reloc %d not supported by object file format"),
6076 (int) fixp->fx_r_type);
6077 return NULL;
6078 }
6079 reloc->addend = fixp->fx_addnumber;
6080
6081 return reloc;
6082 }
6083
6084 void
6085 ppc_cfi_frame_initial_instructions ()
6086 {
6087 cfi_add_CFA_def_cfa (1, 0);
6088 }
6089
6090 int
6091 tc_ppc_regname_to_dw2regnum (char *regname)
6092 {
6093 unsigned int regnum = -1;
6094 unsigned int i;
6095 const char *p;
6096 char *q;
6097 static struct { char *name; int dw2regnum; } regnames[] =
6098 {
6099 { "sp", 1 }, { "r.sp", 1 }, { "rtoc", 2 }, { "r.toc", 2 },
6100 { "mq", 64 }, { "lr", 65 }, { "ctr", 66 }, { "ap", 67 },
6101 { "cr", 70 }, { "xer", 76 }, { "vrsave", 109 }, { "vscr", 110 },
6102 { "spe_acc", 111 }, { "spefscr", 112 }
6103 };
6104
6105 for (i = 0; i < ARRAY_SIZE (regnames); ++i)
6106 if (strcmp (regnames[i].name, regname) == 0)
6107 return regnames[i].dw2regnum;
6108
6109 if (regname[0] == 'r' || regname[0] == 'f' || regname[0] == 'v')
6110 {
6111 p = regname + 1 + (regname[1] == '.');
6112 regnum = strtoul (p, &q, 10);
6113 if (p == q || *q || regnum >= 32)
6114 return -1;
6115 if (regname[0] == 'f')
6116 regnum += 32;
6117 else if (regname[0] == 'v')
6118 regnum += 77;
6119 }
6120 else if (regname[0] == 'c' && regname[1] == 'r')
6121 {
6122 p = regname + 2 + (regname[2] == '.');
6123 if (p[0] < '0' || p[0] > '7' || p[1])
6124 return -1;
6125 regnum = p[0] - '0' + 68;
6126 }
6127 return regnum;
6128 }
This page took 0.154415 seconds and 4 git commands to generate.