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