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