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