home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / gas / config / tc-ppc.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  115KB  |  4,640 lines

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