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-hppa.c < prev    next >
C/C++ Source or Header  |  1996-09-28  |  168KB  |  6,552 lines

  1. /* tc-hppa.c -- Assemble for the PA
  2.    Copyright (C) 1989, 1996 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 1, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
  19.  
  20.  
  21. /* HP PA-RISC support was contributed by the Center for Software Science
  22.    at the University of Utah.  */
  23.  
  24. #include <stdio.h>
  25. #include <ctype.h>
  26.  
  27. #include "as.h"
  28. #include "subsegs.h"
  29.  
  30. #include "bfd/libhppa.h"
  31. #include "bfd/libbfd.h"
  32.  
  33. /* Be careful, this file includes data *declarations*.  */
  34. #include "opcode/hppa.h"
  35.  
  36. /* A "convient" place to put object file dependencies which do
  37.    not need to be seen outside of tc-hppa.c.  */
  38. #ifdef OBJ_ELF
  39. /* Names of various debugging spaces/subspaces.  */
  40. #define GDB_DEBUG_SPACE_NAME ".stab"
  41. #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
  42. #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
  43. #define UNWIND_SECTION_NAME ".PARISC.unwind"
  44. /* Nonzero if CODE is a fixup code needing further processing.  */
  45.  
  46. /* Object file formats specify relocation types.  */
  47. typedef elf32_hppa_reloc_type reloc_type;
  48.  
  49. /* Object file formats specify BFD symbol types.  */
  50. typedef elf_symbol_type obj_symbol_type;
  51.  
  52. /* How to generate a relocation.  */
  53. #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
  54.  
  55. /* ELF objects can have versions, but apparently do not have anywhere
  56.    to store a copyright string.  */
  57. #define obj_version obj_elf_version
  58. #define obj_copyright obj_elf_version
  59.  
  60. /* Use space aliases.  */
  61. #define USE_ALIASES 1
  62. #endif
  63.  
  64. #ifdef OBJ_SOM
  65. /* Names of various debugging spaces/subspaces.  */
  66. #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
  67. #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
  68. #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
  69. #define UNWIND_SECTION_NAME "$UNWIND$"
  70.  
  71. /* Object file formats specify relocation types.  */
  72. typedef int reloc_type;
  73.  
  74. /* SOM objects can have both a version string and a copyright string.  */
  75. #define obj_version obj_som_version
  76. #define obj_copyright obj_som_copyright
  77.  
  78. /* Do not use space aliases.  */
  79. #define USE_ALIASES 0
  80.  
  81. /* How to generate a relocation.  */
  82. #define hppa_gen_reloc_type hppa_som_gen_reloc_type
  83.  
  84. /* Object file formats specify BFD symbol types.  */
  85. typedef som_symbol_type obj_symbol_type;
  86.  
  87. /* This apparently isn't in older versions of hpux reloc.h.  */
  88. #ifndef R_DLT_REL
  89. #define R_DLT_REL 0x78
  90. #endif
  91. #endif
  92.  
  93. #ifndef R_N0SEL
  94. #define R_N0SEL 0xd8
  95. #endif
  96.  
  97. #ifndef R_N1SEL
  98. #define R_N1SEL 0xd9
  99. #endif
  100.  
  101. /* Various structures and types used internally in tc-hppa.c.  */
  102.  
  103. /* Unwind table and descriptor.  FIXME: Sync this with GDB version.  */
  104.  
  105. struct unwind_desc
  106.   {
  107.     unsigned int cannot_unwind:1;
  108.     unsigned int millicode:1;
  109.     unsigned int millicode_save_rest:1;
  110.     unsigned int region_desc:2;
  111.     unsigned int save_sr:2;
  112.     unsigned int entry_fr:4;
  113.     unsigned int entry_gr:5;
  114.     unsigned int args_stored:1;
  115.     unsigned int call_fr:5;
  116.     unsigned int call_gr:5;
  117.     unsigned int save_sp:1;
  118.     unsigned int save_rp:1;
  119.     unsigned int save_rp_in_frame:1;
  120.     unsigned int extn_ptr_defined:1;
  121.     unsigned int cleanup_defined:1;
  122.  
  123.     unsigned int hpe_interrupt_marker:1;
  124.     unsigned int hpux_interrupt_marker:1;
  125.     unsigned int reserved:3;
  126.     unsigned int frame_size:27;
  127.   };
  128.  
  129. struct unwind_table
  130.   {
  131.     /* Starting and ending offsets of the region described by
  132.        descriptor.  */
  133.     unsigned int start_offset;
  134.     unsigned int end_offset;
  135.     struct unwind_desc descriptor;
  136.   };
  137.  
  138. /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
  139.    control the entry and exit code they generate. It is also used in
  140.    creation of the correct stack unwind descriptors.
  141.  
  142.    NOTE:  GAS does not support .enter and .leave for the generation of
  143.    prologues and epilogues.  FIXME.
  144.  
  145.    The fields in structure roughly correspond to the arguments available on the
  146.    .callinfo pseudo-op.  */
  147.  
  148. struct call_info
  149.   {
  150.     /* The unwind descriptor being built.  */
  151.     struct unwind_table ci_unwind;
  152.  
  153.     /* Name of this function.  */
  154.     symbolS *start_symbol;
  155.  
  156.     /* (temporary) symbol used to mark the end of this function.  */
  157.     symbolS *end_symbol;
  158.  
  159.     /* Next entry in the chain.  */
  160.     struct call_info *ci_next;
  161.   };
  162.  
  163. /* Operand formats for FP instructions.   Note not all FP instructions
  164.    allow all four formats to be used (for example fmpysub only allows
  165.    SGL and DBL).  */
  166. typedef enum
  167.   {
  168.     SGL, DBL, ILLEGAL_FMT, QUAD
  169.   }
  170. fp_operand_format;
  171.  
  172. /* This fully describes the symbol types which may be attached to
  173.    an EXPORT or IMPORT directive.  Only SOM uses this formation
  174.    (ELF has no need for it).  */
  175. typedef enum
  176.   {
  177.     SYMBOL_TYPE_UNKNOWN,
  178.     SYMBOL_TYPE_ABSOLUTE,
  179.     SYMBOL_TYPE_CODE,
  180.     SYMBOL_TYPE_DATA,
  181.     SYMBOL_TYPE_ENTRY,
  182.     SYMBOL_TYPE_MILLICODE,
  183.     SYMBOL_TYPE_PLABEL,
  184.     SYMBOL_TYPE_PRI_PROG,
  185.     SYMBOL_TYPE_SEC_PROG,
  186.   }
  187. pa_symbol_type;
  188.  
  189. /* This structure contains information needed to assemble
  190.    individual instructions.  */
  191. struct pa_it
  192.   {
  193.     /* Holds the opcode after parsing by pa_ip.  */
  194.     unsigned long opcode;
  195.  
  196.     /* Holds an expression associated with the current instruction.  */
  197.     expressionS exp;
  198.  
  199.     /* Does this instruction use PC-relative addressing.  */
  200.     int pcrel;
  201.  
  202.     /* Floating point formats for operand1 and operand2.  */
  203.     fp_operand_format fpof1;
  204.     fp_operand_format fpof2;
  205.  
  206.     /* Holds the field selector for this instruction
  207.        (for example L%, LR%, etc).  */
  208.     long field_selector;
  209.  
  210.     /* Holds any argument relocation bits associated with this
  211.        instruction.  (instruction should be some sort of call).  */
  212.     long arg_reloc;
  213.  
  214.     /* The format specification for this instruction.  */
  215.     int format;
  216.  
  217.     /* The relocation (if any) associated with this instruction.  */
  218.     reloc_type reloc;
  219.   };
  220.  
  221. /* PA-89 floating point registers are arranged like this:
  222.  
  223.  
  224.    +--------------+--------------+
  225.    |   0 or 16L   |  16 or 16R   |
  226.    +--------------+--------------+
  227.    |   1 or 17L   |  17 or 17R   |
  228.    +--------------+--------------+
  229.    |              |              |
  230.  
  231.    .              .              .
  232.    .              .              .
  233.    .              .              .
  234.  
  235.    |              |              |
  236.    +--------------+--------------+
  237.    |  14 or 30L   |  30 or 30R   |
  238.    +--------------+--------------+
  239.    |  15 or 31L   |  31 or 31R   |
  240.    +--------------+--------------+
  241.  
  242.  
  243.    The following is a version of pa_parse_number that
  244.    handles the L/R notation and returns the correct
  245.    value to put into the instruction register field.
  246.    The correct value to put into the instruction is
  247.    encoded in the structure 'pa_11_fp_reg_struct'.  */
  248.  
  249. struct pa_11_fp_reg_struct
  250.   {
  251.     /* The register number.  */
  252.     char number_part;
  253.  
  254.     /* L/R selector.  */
  255.     char l_r_select;
  256.   };
  257.  
  258. /* Additional information needed to build argument relocation stubs.  */
  259. struct call_desc
  260.   {
  261.     /* The argument relocation specification.  */
  262.     unsigned int arg_reloc;
  263.  
  264.     /* Number of arguments.  */
  265.     unsigned int arg_count;
  266.   };
  267.  
  268. /* This structure defines an entry in the subspace dictionary
  269.    chain.  */
  270.  
  271. struct subspace_dictionary_chain
  272.   {
  273.     /* Nonzero if this space has been defined by the user code.  */
  274.     unsigned int ssd_defined;
  275.  
  276.     /* Name of this subspace.  */
  277.     char *ssd_name;
  278.  
  279.     /* GAS segment and subsegment associated with this subspace.  */
  280.     asection *ssd_seg;
  281.     int ssd_subseg;
  282.  
  283.     /* Next space in the subspace dictionary chain.  */
  284.     struct subspace_dictionary_chain *ssd_next;
  285.   };
  286.  
  287. typedef struct subspace_dictionary_chain ssd_chain_struct;
  288.  
  289. /* This structure defines an entry in the subspace dictionary
  290.    chain.  */
  291.  
  292. struct space_dictionary_chain
  293.   {
  294.     /* Nonzero if this space has been defined by the user code or
  295.        as a default space.  */
  296.     unsigned int sd_defined;
  297.  
  298.     /* Nonzero if this spaces has been defined by the user code.  */
  299.     unsigned int sd_user_defined;
  300.  
  301.     /* The space number (or index).  */
  302.     unsigned int sd_spnum;
  303.  
  304.     /* The name of this subspace.  */
  305.     char *sd_name;
  306.  
  307.     /* GAS segment to which this subspace corresponds.  */
  308.     asection *sd_seg;
  309.  
  310.     /* Current subsegment number being used.  */
  311.     int sd_last_subseg;
  312.  
  313.     /* The chain of subspaces contained within this space.  */
  314.     ssd_chain_struct *sd_subspaces;
  315.  
  316.     /* The next entry in the space dictionary chain.  */
  317.     struct space_dictionary_chain *sd_next;
  318.   };
  319.  
  320. typedef struct space_dictionary_chain sd_chain_struct;
  321.  
  322. /* Structure for previous label tracking.  Needed so that alignments,
  323.    callinfo declarations, etc can be easily attached to a particular
  324.    label.  */
  325. typedef struct label_symbol_struct
  326.   {
  327.     struct symbol *lss_label;
  328.     sd_chain_struct *lss_space;
  329.     struct label_symbol_struct *lss_next;
  330.   }
  331. label_symbol_struct;
  332.  
  333. /* This structure defines attributes of the default subspace
  334.    dictionary entries.  */
  335.  
  336. struct default_subspace_dict
  337.   {
  338.     /* Name of the subspace.  */
  339.     char *name;
  340.  
  341.     /* FIXME.  Is this still needed?  */
  342.     char defined;
  343.  
  344.     /* Nonzero if this subspace is loadable.  */
  345.     char loadable;
  346.  
  347.     /* Nonzero if this subspace contains only code.  */
  348.     char code_only;
  349.  
  350.     /* Nonzero if this is a common subspace.  */
  351.     char common;
  352.  
  353.     /* Nonzero if this is a common subspace which allows symbols
  354.        to be multiply defined.  */
  355.     char dup_common;
  356.  
  357.     /* Nonzero if this subspace should be zero filled.  */
  358.     char zero;
  359.  
  360.     /* Sort key for this subspace.  */
  361.     unsigned char sort;
  362.  
  363.     /* Access control bits for this subspace.  Can represent RWX access
  364.        as well as privilege level changes for gateways.  */
  365.     int access;
  366.  
  367.     /* Index of containing space.  */
  368.     int space_index;
  369.  
  370.     /* Alignment (in bytes) of this subspace.  */
  371.     int alignment;
  372.  
  373.     /* Quadrant within space where this subspace should be loaded.  */
  374.     int quadrant;
  375.  
  376.     /* An index into the default spaces array.  */
  377.     int def_space_index;
  378.  
  379.     /* An alias for this section (or NULL if no alias exists).  */
  380.     char *alias;
  381.  
  382.     /* Subsegment associated with this subspace.  */
  383.     subsegT subsegment;
  384.   };
  385.  
  386. /* This structure defines attributes of the default space
  387.    dictionary entries.  */
  388.  
  389. struct default_space_dict
  390.   {
  391.     /* Name of the space.  */
  392.     char *name;
  393.  
  394.     /* Space number.  It is possible to identify spaces within
  395.        assembly code numerically!  */
  396.     int spnum;
  397.  
  398.     /* Nonzero if this space is loadable.  */
  399.     char loadable;
  400.  
  401.     /* Nonzero if this space is "defined".  FIXME is still needed */
  402.     char defined;
  403.  
  404.     /* Nonzero if this space can not be shared.  */
  405.     char private;
  406.  
  407.     /* Sort key for this space.  */
  408.     unsigned char sort;
  409.  
  410.     /* Segment associated with this space.  */
  411.     asection *segment;
  412.  
  413.     /* An alias for this section (or NULL if no alias exists).  */
  414.     char *alias;
  415.   };
  416.  
  417. /* Extra information needed to perform fixups (relocations) on the PA.  */
  418. struct hppa_fix_struct
  419.   {
  420.     /* The field selector.  */
  421.     enum hppa_reloc_field_selector_type fx_r_field;
  422.  
  423.     /* Type of fixup.  */
  424.     int fx_r_type;
  425.  
  426.     /* Format of fixup.  */
  427.     int fx_r_format;
  428.  
  429.     /* Argument relocation bits.  */
  430.     long fx_arg_reloc;
  431.  
  432.     /* The segment this fixup appears in.  */
  433.     segT segment;
  434.   };
  435.  
  436. /* Structure to hold information about predefined registers.  */
  437.  
  438. struct pd_reg
  439.   {
  440.     char *name;
  441.     int value;
  442.   };
  443.  
  444. /* This structure defines the mapping from a FP condition string
  445.    to a condition number which can be recorded in an instruction.  */
  446. struct fp_cond_map
  447.   {
  448.     char *string;
  449.     int cond;
  450.   };
  451.  
  452. /* This structure defines a mapping from a field selector
  453.    string to a field selector type.  */
  454. struct selector_entry
  455.   {
  456.     char *prefix;
  457.     int field_selector;
  458.   };
  459.  
  460. /* Prototypes for functions local to tc-hppa.c.  */
  461.  
  462. static void pa_check_current_space_and_subspace PARAMS ((void));
  463. static fp_operand_format pa_parse_fp_format PARAMS ((char **s));
  464. static void pa_cons PARAMS ((int));
  465. static void pa_data PARAMS ((int));
  466. static void pa_float_cons PARAMS ((int));
  467. static void pa_fill PARAMS ((int));
  468. static void pa_lcomm PARAMS ((int));
  469. static void pa_lsym PARAMS ((int));
  470. static void pa_stringer PARAMS ((int));
  471. static void pa_text PARAMS ((int));
  472. static void pa_version PARAMS ((int));
  473. static int pa_parse_fp_cmp_cond PARAMS ((char **));
  474. static int get_expression PARAMS ((char *));
  475. static int pa_get_absolute_expression PARAMS ((struct pa_it *, char **));
  476. static int evaluate_absolute PARAMS ((struct pa_it *));
  477. static unsigned int pa_build_arg_reloc PARAMS ((char *));
  478. static unsigned int pa_align_arg_reloc PARAMS ((unsigned int, unsigned int));
  479. static int pa_parse_nullif PARAMS ((char **));
  480. static int pa_parse_nonneg_cmpsub_cmpltr PARAMS ((char **, int));
  481. static int pa_parse_neg_cmpsub_cmpltr PARAMS ((char **, int));
  482. static int pa_parse_neg_add_cmpltr PARAMS ((char **, int));
  483. static int pa_parse_nonneg_add_cmpltr PARAMS ((char **, int));
  484. static void pa_align PARAMS ((int));
  485. static void pa_block PARAMS ((int));
  486. static void pa_brtab PARAMS ((int));
  487. static void pa_try PARAMS ((int));
  488. static void pa_call PARAMS ((int));
  489. static void pa_call_args PARAMS ((struct call_desc *));
  490. static void pa_callinfo PARAMS ((int));
  491. static void pa_code PARAMS ((int));
  492. static void pa_comm PARAMS ((int));
  493. static void pa_copyright PARAMS ((int));
  494. static void pa_end PARAMS ((int));
  495. static void pa_enter PARAMS ((int));
  496. static void pa_entry PARAMS ((int));
  497. static void pa_equ PARAMS ((int));
  498. static void pa_exit PARAMS ((int));
  499. static void pa_export PARAMS ((int));
  500. static void pa_type_args PARAMS ((symbolS *, int));
  501. static void pa_import PARAMS ((int));
  502. static void pa_label PARAMS ((int));
  503. static void pa_leave PARAMS ((int));
  504. static void pa_level PARAMS ((int));
  505. static void pa_origin PARAMS ((int));
  506. static void pa_proc PARAMS ((int));
  507. static void pa_procend PARAMS ((int));
  508. static void pa_space PARAMS ((int));
  509. static void pa_spnum PARAMS ((int));
  510. static void pa_subspace PARAMS ((int));
  511. static void pa_param PARAMS ((int));
  512. static void pa_undefine_label PARAMS ((void));
  513. static int need_pa11_opcode PARAMS ((struct pa_it *,
  514.                      struct pa_11_fp_reg_struct *));
  515. static int pa_parse_number PARAMS ((char **, struct pa_11_fp_reg_struct *));
  516. static label_symbol_struct *pa_get_label PARAMS ((void));
  517. static sd_chain_struct *create_new_space PARAMS ((char *, int, int,
  518.                           int, int, int,
  519.                           asection *, int));
  520. static ssd_chain_struct *create_new_subspace PARAMS ((sd_chain_struct *,
  521.                               char *, int, int,
  522.                               int, int, int,
  523.                               int, int, int, int,
  524.                               int, asection *));
  525. static ssd_chain_struct *update_subspace PARAMS ((sd_chain_struct *,
  526.                           char *, int, int, int,
  527.                           int, int, int, int,
  528.                           int, int, int,
  529.                           asection *));
  530. static sd_chain_struct *is_defined_space PARAMS ((char *));
  531. static ssd_chain_struct *is_defined_subspace PARAMS ((char *));
  532. static sd_chain_struct *pa_segment_to_space PARAMS ((asection *));
  533. static ssd_chain_struct *pa_subsegment_to_subspace PARAMS ((asection *,
  534.                                 subsegT));
  535. static sd_chain_struct *pa_find_space_by_number PARAMS ((int));
  536. static unsigned int pa_subspace_start PARAMS ((sd_chain_struct *, int));
  537. static void pa_ip PARAMS ((char *));
  538. static void fix_new_hppa PARAMS ((fragS *, int, int, symbolS *,
  539.                   long, expressionS *, int,
  540.                   bfd_reloc_code_real_type,
  541.                   enum hppa_reloc_field_selector_type,
  542.                   int, long, int *));
  543. static int is_end_of_statement PARAMS ((void));
  544. static int reg_name_search PARAMS ((char *));
  545. static int pa_chk_field_selector PARAMS ((char **));
  546. static int is_same_frag PARAMS ((fragS *, fragS *));
  547. static void pa_build_unwind_subspace PARAMS ((struct call_info *));
  548. static void process_exit PARAMS ((void));
  549. static sd_chain_struct *pa_parse_space_stmt PARAMS ((char *, int));
  550. static int log2 PARAMS ((int));
  551. static int pa_next_subseg PARAMS ((sd_chain_struct *));
  552. static unsigned int pa_stringer_aux PARAMS ((char *));
  553. static void pa_spaces_begin PARAMS ((void));
  554. static void hppa_elf_mark_end_of_function PARAMS ((void));
  555.  
  556. /* File and gloally scoped variable declarations.  */
  557.  
  558. /* Root and final entry in the space chain.  */
  559. static sd_chain_struct *space_dict_root;
  560. static sd_chain_struct *space_dict_last;
  561.  
  562. /* The current space and subspace.  */
  563. static sd_chain_struct *current_space;
  564. static ssd_chain_struct *current_subspace;
  565.  
  566. /* Root of the call_info chain.  */
  567. static struct call_info *call_info_root;
  568.  
  569. /* The last call_info (for functions) structure
  570.    seen so it can be associated with fixups and
  571.    function labels.  */
  572. static struct call_info *last_call_info;
  573.  
  574. /* The last call description (for actual calls).  */
  575. static struct call_desc last_call_desc;
  576.  
  577. /* Jumps are always the same size -- one instruction.  */
  578. int md_short_jump_size = 4;
  579. int md_long_jump_size = 4;
  580.  
  581. /* handle of the OPCODE hash table */
  582. static struct hash_control *op_hash = NULL;
  583.  
  584. /* This array holds the chars that always start a comment.  If the
  585.    pre-processor is disabled, these aren't very useful.  */
  586. const char comment_chars[] = ";";
  587.  
  588. /* Table of pseudo ops for the PA.  FIXME -- how many of these
  589.    are now redundant with the overall GAS and the object file
  590.    dependent tables?  */
  591. const pseudo_typeS md_pseudo_table[] =
  592. {
  593.   /* align pseudo-ops on the PA specify the actual alignment requested,
  594.      not the log2 of the requested alignment.  */
  595.   {"align", pa_align, 8},
  596.   {"begin_brtab", pa_brtab, 1},
  597.   {"begin_try", pa_try, 1},
  598.   {"block", pa_block, 1},
  599.   {"blockz", pa_block, 0},
  600.   {"byte", pa_cons, 1},
  601.   {"call", pa_call, 0},
  602.   {"callinfo", pa_callinfo, 0},
  603.   {"code", pa_code, 0},
  604.   {"comm", pa_comm, 0},
  605.   {"copyright", pa_copyright, 0},
  606.   {"data", pa_data, 0},
  607.   {"double", pa_float_cons, 'd'},
  608.   {"end", pa_end, 0},
  609.   {"end_brtab", pa_brtab, 0},
  610.   {"end_try", pa_try, 0},
  611.   {"enter", pa_enter, 0},
  612.   {"entry", pa_entry, 0},
  613.   {"equ", pa_equ, 0},
  614.   {"exit", pa_exit, 0},
  615.   {"export", pa_export, 0},
  616.   {"fill", pa_fill, 0},
  617.   {"float", pa_float_cons, 'f'},
  618.   {"half", pa_cons, 2},
  619.   {"import", pa_import, 0},
  620.   {"int", pa_cons, 4},
  621.   {"label", pa_label, 0},
  622.   {"lcomm", pa_lcomm, 0},
  623.   {"leave", pa_leave, 0},
  624.   {"level", pa_level, 0},
  625.   {"long", pa_cons, 4},
  626.   {"lsym", pa_lsym, 0},
  627.   {"nsubspa", pa_subspace, 1},
  628.   {"octa", pa_cons, 16},
  629.   {"org", pa_origin, 0},
  630.   {"origin", pa_origin, 0},
  631.   {"param", pa_param, 0},
  632.   {"proc", pa_proc, 0},
  633.   {"procend", pa_procend, 0},
  634.   {"quad", pa_cons, 8},
  635.   {"reg", pa_equ, 1},
  636.   {"short", pa_cons, 2},
  637.   {"single", pa_float_cons, 'f'},
  638.   {"space", pa_space, 0},
  639.   {"spnum", pa_spnum, 0},
  640.   {"string", pa_stringer, 0},
  641.   {"stringz", pa_stringer, 1},
  642.   {"subspa", pa_subspace, 0},
  643.   {"text", pa_text, 0},
  644.   {"version", pa_version, 0},
  645.   {"word", pa_cons, 4},
  646.   {NULL, 0, 0}
  647. };
  648.  
  649. /* This array holds the chars that only start a comment at the beginning of
  650.    a line.  If the line seems to have the form '# 123 filename'
  651.    .line and .file directives will appear in the pre-processed output.
  652.  
  653.    Note that input_file.c hand checks for '#' at the beginning of the
  654.    first line of the input file.  This is because the compiler outputs
  655.    #NO_APP at the beginning of its output.
  656.  
  657.    Also note that C style comments will always work. */
  658. const char line_comment_chars[] = "#";
  659.  
  660. /* This array holds the characters which act as line separators.  */
  661. const char line_separator_chars[] = "!";
  662.  
  663. /* Chars that can be used to separate mant from exp in floating point nums.  */
  664. const char EXP_CHARS[] = "eE";
  665.  
  666. /* Chars that mean this number is a floating point constant.
  667.    As in 0f12.456 or 0d1.2345e12.
  668.  
  669.    Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
  670.    changed in read.c.  Ideally it shouldn't hae to know abou it at
  671.    all, but nothing is ideal around here.  */
  672. const char FLT_CHARS[] = "rRsSfFdDxXpP";
  673.  
  674. static struct pa_it the_insn;
  675.  
  676. /* Points to the end of an expression just parsed by get_expressoin
  677.    and friends.  FIXME.  This shouldn't be handled with a file-global
  678.    variable.  */
  679. static char *expr_end;
  680.  
  681. /* Nonzero if a .callinfo appeared within the current procedure.  */
  682. static int callinfo_found;
  683.  
  684. /* Nonzero if the assembler is currently within a .entry/.exit pair.  */
  685. static int within_entry_exit;
  686.  
  687. /* Nonzero if the assembler is currently within a procedure definition.  */
  688. static int within_procedure;
  689.  
  690. /* Handle on strucutre which keep track of the last symbol
  691.    seen in each subspace.  */
  692. static label_symbol_struct *label_symbols_rootp = NULL;
  693.  
  694. /* Holds the last field selector.  */
  695. static int hppa_field_selector;
  696.  
  697. /* A dummy bfd symbol so that all relocations have symbols of some kind.  */
  698. static symbolS *dummy_symbol;
  699.  
  700. /* Nonzero if errors are to be printed.  */
  701. static int print_errors = 1;
  702.  
  703. /* List of registers that are pre-defined:
  704.  
  705.    Each general register has one predefined name of the form
  706.    %r<REGNUM> which has the value <REGNUM>.
  707.  
  708.    Space and control registers are handled in a similar manner,
  709.    but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
  710.  
  711.    Likewise for the floating point registers, but of the form
  712.    %fr<REGNUM>.  Floating point registers have additional predefined
  713.    names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
  714.    again have the value <REGNUM>.
  715.  
  716.    Many registers also have synonyms:
  717.  
  718.    %r26 - %r23 have %arg0 - %arg3 as synonyms
  719.    %r28 - %r29 have %ret0 - %ret1 as synonyms
  720.    %r30 has %sp as a synonym
  721.    %r27 has %dp as a synonym
  722.    %r2  has %rp as a synonym
  723.  
  724.    Almost every control register has a synonym; they are not listed
  725.    here for brevity.
  726.  
  727.    The table is sorted. Suitable for searching by a binary search. */
  728.  
  729. static const struct pd_reg pre_defined_registers[] =
  730. {
  731.   {"%arg0", 26},
  732.   {"%arg1", 25},
  733.   {"%arg2", 24},
  734.   {"%arg3", 23},
  735.   {"%cr0", 0},
  736.   {"%cr10", 10},
  737.   {"%cr11", 11},
  738.   {"%cr12", 12},
  739.   {"%cr13", 13},
  740.   {"%cr14", 14},
  741.   {"%cr15", 15},
  742.   {"%cr16", 16},
  743.   {"%cr17", 17},
  744.   {"%cr18", 18},
  745.   {"%cr19", 19},
  746.   {"%cr20", 20},
  747.   {"%cr21", 21},
  748.   {"%cr22", 22},
  749.   {"%cr23", 23},
  750.   {"%cr24", 24},
  751.   {"%cr25", 25},
  752.   {"%cr26", 26},
  753.   {"%cr27", 27},
  754.   {"%cr28", 28},
  755.   {"%cr29", 29},
  756.   {"%cr30", 30},
  757.   {"%cr31", 31},
  758.   {"%cr8", 8},
  759.   {"%cr9", 9},
  760.   {"%dp", 27},
  761.   {"%eiem", 15},
  762.   {"%eirr", 23},
  763.   {"%fr0", 0},
  764.   {"%fr0l", 0},
  765.   {"%fr0r", 0},
  766.   {"%fr1", 1},
  767.   {"%fr10", 10},
  768.   {"%fr10l", 10},
  769.   {"%fr10r", 10},
  770.   {"%fr11", 11},
  771.   {"%fr11l", 11},
  772.   {"%fr11r", 11},
  773.   {"%fr12", 12},
  774.   {"%fr12l", 12},
  775.   {"%fr12r", 12},
  776.   {"%fr13", 13},
  777.   {"%fr13l", 13},
  778.   {"%fr13r", 13},
  779.   {"%fr14", 14},
  780.   {"%fr14l", 14},
  781.   {"%fr14r", 14},
  782.   {"%fr15", 15},
  783.   {"%fr15l", 15},
  784.   {"%fr15r", 15},
  785.   {"%fr16", 16},
  786.   {"%fr16l", 16},
  787.   {"%fr16r", 16},
  788.   {"%fr17", 17},
  789.   {"%fr17l", 17},
  790.   {"%fr17r", 17},
  791.   {"%fr18", 18},
  792.   {"%fr18l", 18},
  793.   {"%fr18r", 18},
  794.   {"%fr19", 19},
  795.   {"%fr19l", 19},
  796.   {"%fr19r", 19},
  797.   {"%fr1l", 1},
  798.   {"%fr1r", 1},
  799.   {"%fr2", 2},
  800.   {"%fr20", 20},
  801.   {"%fr20l", 20},
  802.   {"%fr20r", 20},
  803.   {"%fr21", 21},
  804.   {"%fr21l", 21},
  805.   {"%fr21r", 21},
  806.   {"%fr22", 22},
  807.   {"%fr22l", 22},
  808.   {"%fr22r", 22},
  809.   {"%fr23", 23},
  810.   {"%fr23l", 23},
  811.   {"%fr23r", 23},
  812.   {"%fr24", 24},
  813.   {"%fr24l", 24},
  814.   {"%fr24r", 24},
  815.   {"%fr25", 25},
  816.   {"%fr25l", 25},
  817.   {"%fr25r", 25},
  818.   {"%fr26", 26},
  819.   {"%fr26l", 26},
  820.   {"%fr26r", 26},
  821.   {"%fr27", 27},
  822.   {"%fr27l", 27},
  823.   {"%fr27r", 27},
  824.   {"%fr28", 28},
  825.   {"%fr28l", 28},
  826.   {"%fr28r", 28},
  827.   {"%fr29", 29},
  828.   {"%fr29l", 29},
  829.   {"%fr29r", 29},
  830.   {"%fr2l", 2},
  831.   {"%fr2r", 2},
  832.   {"%fr3", 3},
  833.   {"%fr30", 30},
  834.   {"%fr30l", 30},
  835.   {"%fr30r", 30},
  836.   {"%fr31", 31},
  837.   {"%fr31l", 31},
  838.   {"%fr31r", 31},
  839.   {"%fr3l", 3},
  840.   {"%fr3r", 3},
  841.   {"%fr4", 4},
  842.   {"%fr4l", 4},
  843.   {"%fr4r", 4},
  844.   {"%fr5", 5},
  845.   {"%fr5l", 5},
  846.   {"%fr5r", 5},
  847.   {"%fr6", 6},
  848.   {"%fr6l", 6},
  849.   {"%fr6r", 6},
  850.   {"%fr7", 7},
  851.   {"%fr7l", 7},
  852.   {"%fr7r", 7},
  853.   {"%fr8", 8},
  854.   {"%fr8l", 8},
  855.   {"%fr8r", 8},
  856.   {"%fr9", 9},
  857.   {"%fr9l", 9},
  858.   {"%fr9r", 9},
  859.   {"%hta", 25},
  860.   {"%iir", 19},
  861.   {"%ior", 21},
  862.   {"%ipsw", 22},
  863.   {"%isr", 20},
  864.   {"%itmr", 16},
  865.   {"%iva", 14},
  866.   {"%pcoq", 18},
  867.   {"%pcsq", 17},
  868.   {"%pidr1", 8},
  869.   {"%pidr2", 9},
  870.   {"%pidr3", 12},
  871.   {"%pidr4", 13},
  872.   {"%ppda", 24},
  873.   {"%r0", 0},
  874.   {"%r1", 1},
  875.   {"%r10", 10},
  876.   {"%r11", 11},
  877.   {"%r12", 12},
  878.   {"%r13", 13},
  879.   {"%r14", 14},
  880.   {"%r15", 15},
  881.   {"%r16", 16},
  882.   {"%r17", 17},
  883.   {"%r18", 18},
  884.   {"%r19", 19},
  885.   {"%r2", 2},
  886.   {"%r20", 20},
  887.   {"%r21", 21},
  888.   {"%r22", 22},
  889.   {"%r23", 23},
  890.   {"%r24", 24},
  891.   {"%r25", 25},
  892.   {"%r26", 26},
  893.   {"%r27", 27},
  894.   {"%r28", 28},
  895.   {"%r29", 29},
  896.   {"%r3", 3},
  897.   {"%r30", 30},
  898.   {"%r31", 31},
  899.   {"%r4", 4},
  900.   {"%r5", 5},
  901.   {"%r6", 6},
  902.   {"%r7", 7},
  903.   {"%r8", 8},
  904.   {"%r9", 9},
  905.   {"%rctr", 0},
  906.   {"%ret0", 28},
  907.   {"%ret1", 29},
  908.   {"%rp", 2},
  909.   {"%sar", 11},
  910.   {"%sp", 30},
  911.   {"%sr0", 0},
  912.   {"%sr1", 1},
  913.   {"%sr2", 2},
  914.   {"%sr3", 3},
  915.   {"%sr4", 4},
  916.   {"%sr5", 5},
  917.   {"%sr6", 6},
  918.   {"%sr7", 7},
  919.   {"%tr0", 24},
  920.   {"%tr1", 25},
  921.   {"%tr2", 26},
  922.   {"%tr3", 27},
  923.   {"%tr4", 28},
  924.   {"%tr5", 29},
  925.   {"%tr6", 30},
  926.   {"%tr7", 31}
  927. };
  928.  
  929. /* This table is sorted by order of the length of the string. This is
  930.    so we check for <> before we check for <. If we had a <> and checked
  931.    for < first, we would get a false match.  */
  932. static const struct fp_cond_map fp_cond_map[] =
  933. {
  934.   {"false?", 0},
  935.   {"false", 1},
  936.   {"true?", 30},
  937.   {"true", 31},
  938.   {"!<=>", 3},
  939.   {"!?>=", 8},
  940.   {"!?<=", 16},
  941.   {"!<>", 7},
  942.   {"!>=", 11},
  943.   {"!?>", 12},
  944.   {"?<=", 14},
  945.   {"!<=", 19},
  946.   {"!?<", 20},
  947.   {"?>=", 22},
  948.   {"!?=", 24},
  949.   {"!=t", 27},
  950.   {"<=>", 29},
  951.   {"=t", 5},
  952.   {"?=", 6},
  953.   {"?<", 10},
  954.   {"<=", 13},
  955.   {"!>", 15},
  956.   {"?>", 18},
  957.   {">=", 21},
  958.   {"!<", 23},
  959.   {"<>", 25},
  960.   {"!=", 26},
  961.   {"!?", 28},
  962.   {"?", 2},
  963.   {"=", 4},
  964.   {"<", 9},
  965.   {">", 17}
  966. };
  967.  
  968. static const struct selector_entry selector_table[] =
  969. {
  970.   {"f", e_fsel},
  971.   {"l", e_lsel},
  972.   {"ld", e_ldsel},
  973.   {"lp", e_lpsel},
  974.   {"lr", e_lrsel},
  975.   {"ls", e_lssel},
  976.   {"lt", e_ltsel},
  977.   {"n", e_nsel},
  978.   {"nl", e_nlsel},
  979.   {"nlr", e_nlrsel},
  980.   {"p", e_psel},
  981.   {"r", e_rsel},
  982.   {"rd", e_rdsel},
  983.   {"rp", e_rpsel},
  984.   {"rr", e_rrsel},
  985.   {"rs", e_rssel},
  986.   {"rt", e_rtsel},
  987.   {"t", e_tsel},
  988. };
  989.  
  990. /* default space and subspace dictionaries */
  991.  
  992. #define GDB_SYMBOLS          GDB_SYMBOLS_SUBSPACE_NAME
  993. #define GDB_STRINGS          GDB_STRINGS_SUBSPACE_NAME
  994.  
  995. /* pre-defined subsegments (subspaces) for the HPPA.  */
  996. #define SUBSEG_CODE   0
  997. #define SUBSEG_LIT    1
  998. #define SUBSEG_MILLI  2
  999. #define SUBSEG_DATA   0
  1000. #define SUBSEG_BSS    2
  1001. #define SUBSEG_UNWIND 3
  1002. #define SUBSEG_GDB_STRINGS 0
  1003. #define SUBSEG_GDB_SYMBOLS 1
  1004.  
  1005. static struct default_subspace_dict pa_def_subspaces[] =
  1006. {
  1007.   {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE},
  1008.   {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA},
  1009.   {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT},
  1010.   {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_MILLI},
  1011.   {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS},
  1012. #ifdef OBJ_ELF
  1013.   {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".PARISC.unwind", SUBSEG_UNWIND},
  1014. #endif
  1015.   {NULL, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
  1016. };
  1017.  
  1018. static struct default_space_dict pa_def_spaces[] =
  1019. {
  1020.   {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL, ".text"},
  1021.   {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL, ".data"},
  1022.   {NULL, 0, 0, 0, 0, 0, ASEC_NULL, NULL}
  1023. };
  1024.  
  1025. /* Misc local definitions used by the assembler.  */
  1026.  
  1027. /* Return nonzero if the string pointed to by S potentially represents
  1028.    a right or left half of a FP register  */
  1029. #define IS_R_SELECT(S)   (*(S) == 'R' || *(S) == 'r')
  1030. #define IS_L_SELECT(S)   (*(S) == 'L' || *(S) == 'l')
  1031.  
  1032. /* These macros are used to maintain spaces/subspaces.  */
  1033. #define SPACE_DEFINED(space_chain)    (space_chain)->sd_defined
  1034. #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
  1035. #define SPACE_SPNUM(space_chain)    (space_chain)->sd_spnum
  1036. #define SPACE_NAME(space_chain)        (space_chain)->sd_name
  1037.  
  1038. #define SUBSPACE_DEFINED(ss_chain)    (ss_chain)->ssd_defined
  1039. #define SUBSPACE_NAME(ss_chain)        (ss_chain)->ssd_name
  1040.  
  1041. /* Insert FIELD into OPCODE starting at bit START.  Continue pa_ip
  1042.    main loop after insertion.  */
  1043.  
  1044. #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
  1045.   { \
  1046.     ((OPCODE) |= (FIELD) << (START)); \
  1047.     continue; \
  1048.   }
  1049.  
  1050. /* Simple range checking for FIELD againt HIGH and LOW bounds.
  1051.    IGNORE is used to suppress the error message.  */
  1052.  
  1053. #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
  1054.   { \
  1055.     if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
  1056.       { \
  1057.     if (! IGNORE) \
  1058.           as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
  1059.           (int) (FIELD));\
  1060.         break; \
  1061.       } \
  1062.   }
  1063.  
  1064. #define is_DP_relative(exp)            \
  1065.   ((exp).X_op == O_subtract            \
  1066.    && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
  1067.  
  1068. #define is_PC_relative(exp)            \
  1069.   ((exp).X_op == O_subtract            \
  1070.    && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
  1071.  
  1072. /* We need some complex handling for stabs (sym1 - sym2).  Luckily, we'll
  1073.    always be able to reduce the expression to a constant, so we don't
  1074.    need real complex handling yet.  */
  1075. #define is_complex(exp)                \
  1076.   ((exp).X_op != O_constant && (exp).X_op != O_symbol)
  1077.  
  1078. /* Actual functions to implement the PA specific code for the assembler.  */
  1079.  
  1080. /* Called before writing the object file.  Make sure entry/exit and
  1081.    proc/procend pairs match.  */
  1082.  
  1083. void
  1084. pa_check_eof ()
  1085. {
  1086.   if (within_entry_exit)
  1087.     as_fatal ("Missing .exit\n");
  1088.  
  1089.   if (within_procedure)
  1090.     as_fatal ("Missing .procend\n");
  1091. }
  1092.  
  1093. /* Check to make sure we have a valid space and subspace.  */
  1094.  
  1095. static void
  1096. pa_check_current_space_and_subspace ()
  1097. {
  1098.   if (current_space == NULL)
  1099.     as_fatal ("Not in a space.\n");
  1100.  
  1101.   if (current_subspace == NULL)
  1102.     as_fatal ("Not in a subspace.\n");
  1103. }
  1104.  
  1105. /* Returns a pointer to the label_symbol_struct for the current space.
  1106.    or NULL if no label_symbol_struct exists for the current space.  */
  1107.  
  1108. static label_symbol_struct *
  1109. pa_get_label ()
  1110. {
  1111.   label_symbol_struct *label_chain;
  1112.   sd_chain_struct *space_chain = current_space;
  1113.  
  1114.   for (label_chain = label_symbols_rootp;
  1115.        label_chain;
  1116.        label_chain = label_chain->lss_next)
  1117.     if (space_chain == label_chain->lss_space && label_chain->lss_label)
  1118.       return label_chain;
  1119.  
  1120.   return NULL;
  1121. }
  1122.  
  1123. /* Defines a label for the current space.  If one is already defined,
  1124.    this function will replace it with the new label.  */
  1125.  
  1126. void
  1127. pa_define_label (symbol)
  1128.      symbolS *symbol;
  1129. {
  1130.   label_symbol_struct *label_chain = pa_get_label ();
  1131.   sd_chain_struct *space_chain = current_space;
  1132.  
  1133.   if (label_chain)
  1134.     label_chain->lss_label = symbol;
  1135.   else
  1136.     {
  1137.       /* Create a new label entry and add it to the head of the chain.  */
  1138.       label_chain
  1139.     = (label_symbol_struct *) xmalloc (sizeof (label_symbol_struct));
  1140.       label_chain->lss_label = symbol;
  1141.       label_chain->lss_space = space_chain;
  1142.       label_chain->lss_next = NULL;
  1143.  
  1144.       if (label_symbols_rootp)
  1145.     label_chain->lss_next = label_symbols_rootp;
  1146.  
  1147.       label_symbols_rootp = label_chain;
  1148.     }
  1149. }
  1150.  
  1151. /* Removes a label definition for the current space.
  1152.    If there is no label_symbol_struct entry, then no action is taken.  */
  1153.  
  1154. static void
  1155. pa_undefine_label ()
  1156. {
  1157.   label_symbol_struct *label_chain;
  1158.   label_symbol_struct *prev_label_chain = NULL;
  1159.   sd_chain_struct *space_chain = current_space;
  1160.  
  1161.   for (label_chain = label_symbols_rootp;
  1162.        label_chain;
  1163.        label_chain = label_chain->lss_next)
  1164.     {
  1165.       if (space_chain == label_chain->lss_space && label_chain->lss_label)
  1166.     {
  1167.       /* Remove the label from the chain and free its memory.  */
  1168.       if (prev_label_chain)
  1169.         prev_label_chain->lss_next = label_chain->lss_next;
  1170.       else
  1171.         label_symbols_rootp = label_chain->lss_next;
  1172.  
  1173.       free (label_chain);
  1174.       break;
  1175.     }
  1176.       prev_label_chain = label_chain;
  1177.     }
  1178. }
  1179.  
  1180.  
  1181. /* An HPPA-specific version of fix_new.  This is required because the HPPA
  1182.    code needs to keep track of some extra stuff.  Each call to fix_new_hppa
  1183.    results in the creation of an instance of an hppa_fix_struct.  An
  1184.    hppa_fix_struct stores the extra information along with a pointer to the
  1185.    original fixS.  This is attached to the original fixup via the
  1186.    tc_fix_data field.  */
  1187.  
  1188. static void
  1189. fix_new_hppa (frag, where, size, add_symbol, offset, exp, pcrel,
  1190.           r_type, r_field, r_format, arg_reloc, unwind_bits)
  1191.      fragS *frag;
  1192.      int where;
  1193.      int size;
  1194.      symbolS *add_symbol;
  1195.      long offset;
  1196.      expressionS *exp;
  1197.      int pcrel;
  1198.      bfd_reloc_code_real_type r_type;
  1199.      enum hppa_reloc_field_selector_type r_field;
  1200.      int r_format;
  1201.      long arg_reloc;
  1202.      int* unwind_bits;
  1203. {
  1204.   fixS *new_fix;
  1205.  
  1206.   struct hppa_fix_struct *hppa_fix = (struct hppa_fix_struct *)
  1207.   obstack_alloc (¬es, sizeof (struct hppa_fix_struct));
  1208.  
  1209.   if (exp != NULL)
  1210.     new_fix = fix_new_exp (frag, where, size, exp, pcrel, r_type);
  1211.   else
  1212.     new_fix = fix_new (frag, where, size, add_symbol, offset, pcrel, r_type);
  1213.   new_fix->tc_fix_data = (void *) hppa_fix;
  1214.   hppa_fix->fx_r_type = r_type;
  1215.   hppa_fix->fx_r_field = r_field;
  1216.   hppa_fix->fx_r_format = r_format;
  1217.   hppa_fix->fx_arg_reloc = arg_reloc;
  1218.   hppa_fix->segment = now_seg;
  1219. #ifdef OBJ_SOM
  1220.   if (r_type == R_ENTRY || r_type == R_EXIT)
  1221.     new_fix->fx_offset = *unwind_bits;
  1222. #endif
  1223.  
  1224.   /* foo-$global$ is used to access non-automatic storage.  $global$
  1225.      is really just a marker and has served its purpose, so eliminate
  1226.      it now so as not to confuse write.c.  */
  1227.   if (new_fix->fx_subsy
  1228.       && !strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$"))
  1229.     new_fix->fx_subsy = NULL;
  1230. }
  1231.  
  1232. /* Parse a .byte, .word, .long expression for the HPPA.  Called by
  1233.    cons via the TC_PARSE_CONS_EXPRESSION macro.  */
  1234.  
  1235. void
  1236. parse_cons_expression_hppa (exp)
  1237.      expressionS *exp;
  1238. {
  1239.   hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
  1240.   expression (exp);
  1241. }
  1242.  
  1243. /* This fix_new is called by cons via TC_CONS_FIX_NEW.
  1244.    hppa_field_selector is set by the parse_cons_expression_hppa.  */
  1245.  
  1246. void
  1247. cons_fix_new_hppa (frag, where, size, exp)
  1248.      fragS *frag;
  1249.      int where;
  1250.      int size;
  1251.      expressionS *exp;
  1252. {
  1253.   unsigned int rel_type;
  1254.  
  1255.   /* Get a base relocation type.  */
  1256.   if (is_DP_relative (*exp))
  1257.     rel_type = R_HPPA_GOTOFF;
  1258.   else if (is_complex (*exp))
  1259.     rel_type = R_HPPA_COMPLEX;
  1260.   else
  1261.     rel_type = R_HPPA;
  1262.  
  1263.   if (hppa_field_selector != e_psel && hppa_field_selector != e_fsel)
  1264.     as_warn ("Invalid field selector.  Assuming F%%.");
  1265.  
  1266.   fix_new_hppa (frag, where, size,
  1267.         (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
  1268.         hppa_field_selector, 32, 0, NULL);
  1269.  
  1270.   /* Reset field selector to its default state.  */
  1271.   hppa_field_selector = 0;
  1272. }
  1273.  
  1274. /* This function is called once, at assembler startup time.  It should
  1275.    set up all the tables, etc. that the MD part of the assembler will need.  */
  1276.  
  1277. void
  1278. md_begin ()
  1279. {
  1280.   const char *retval = NULL;
  1281.   int lose = 0;
  1282.   unsigned int i = 0;
  1283.  
  1284.   last_call_info = NULL;
  1285.   call_info_root = NULL;
  1286.  
  1287.   /* Set the default machine type.  */
  1288.   if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
  1289.     as_warn ("could not set architecture and machine");
  1290.  
  1291.   /* Folding of text and data segments fails miserably on the PA.
  1292.      Warn user and disable "-R" option.  */
  1293.   if (flag_readonly_data_in_text)
  1294.     {
  1295.       as_warn ("-R option not supported on this target.");
  1296.       flag_readonly_data_in_text = 0;
  1297.     }
  1298.  
  1299.   pa_spaces_begin ();
  1300.  
  1301.   op_hash = hash_new ();
  1302.  
  1303.   while (i < NUMOPCODES)
  1304.     {
  1305.       const char *name = pa_opcodes[i].name;
  1306.       retval = hash_insert (op_hash, name, (struct pa_opcode *) &pa_opcodes[i]);
  1307.       if (retval != NULL && *retval != '\0')
  1308.     {
  1309.       as_fatal ("Internal error: can't hash `%s': %s\n", name, retval);
  1310.       lose = 1;
  1311.     }
  1312.       do
  1313.     {
  1314.       if ((pa_opcodes[i].match & pa_opcodes[i].mask)
  1315.           != pa_opcodes[i].match)
  1316.         {
  1317.           fprintf (stderr, "internal error: losing opcode: `%s' \"%s\"\n",
  1318.                pa_opcodes[i].name, pa_opcodes[i].args);
  1319.           lose = 1;
  1320.         }
  1321.       ++i;
  1322.     }
  1323.       while (i < NUMOPCODES && !strcmp (pa_opcodes[i].name, name));
  1324.     }
  1325.  
  1326.   if (lose)
  1327.     as_fatal ("Broken assembler.  No assembly attempted.");
  1328.  
  1329.   /* SOM will change text_section.  To make sure we never put
  1330.      anything into the old one switch to the new one now.  */
  1331.   subseg_set (text_section, 0);
  1332.  
  1333.   dummy_symbol = symbol_find_or_make ("L$dummy");
  1334.   S_SET_SEGMENT (dummy_symbol, text_section);
  1335. }
  1336.  
  1337. /* Assemble a single instruction storing it into a frag.  */
  1338. void
  1339. md_assemble (str)
  1340.      char *str;
  1341. {
  1342.   char *to;
  1343.  
  1344.   /* The had better be something to assemble.  */
  1345.   assert (str);
  1346.  
  1347.   /* If we are within a procedure definition, make sure we've
  1348.      defined a label for the procedure; handle case where the
  1349.      label was defined after the .PROC directive.
  1350.  
  1351.      Note there's not need to diddle with the segment or fragment
  1352.      for the label symbol in this case.  We have already switched
  1353.      into the new $CODE$ subspace at this point.  */
  1354.   if (within_procedure && last_call_info->start_symbol == NULL)
  1355.     {
  1356.       label_symbol_struct *label_symbol = pa_get_label ();
  1357.  
  1358.       if (label_symbol)
  1359.     {
  1360.       if (label_symbol->lss_label)
  1361.         {
  1362.           last_call_info->start_symbol = label_symbol->lss_label;
  1363.           label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
  1364. #ifdef OBJ_SOM
  1365.           /* Also handle allocation of a fixup to hold the unwind
  1366.          information when the label appears after the proc/procend.  */
  1367.           if (within_entry_exit)
  1368.         {
  1369.           char *where = frag_more (0);
  1370.  
  1371.           fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  1372.                 NULL, (offsetT) 0, NULL,
  1373.                 0, R_HPPA_ENTRY, e_fsel, 0, 0,
  1374.                 (int *)&last_call_info->ci_unwind.descriptor);
  1375.         }
  1376. #endif
  1377.         }
  1378.       else
  1379.         as_bad ("Missing function name for .PROC (corrupted label chain)");
  1380.     }
  1381.       else
  1382.     as_bad ("Missing function name for .PROC");
  1383.     }
  1384.  
  1385.   /* Assemble the instruction.  Results are saved into "the_insn".  */
  1386.   pa_ip (str);
  1387.  
  1388.   /* Get somewhere to put the assembled instrution.  */
  1389.   to = frag_more (4);
  1390.  
  1391.   /* Output the opcode. */
  1392.   md_number_to_chars (to, the_insn.opcode, 4);
  1393.  
  1394.   /* If necessary output more stuff.  */
  1395.   if (the_insn.reloc != R_HPPA_NONE)
  1396.     fix_new_hppa (frag_now, (to - frag_now->fr_literal), 4, NULL,
  1397.           (offsetT) 0, &the_insn.exp, the_insn.pcrel,
  1398.           the_insn.reloc, the_insn.field_selector,
  1399.           the_insn.format, the_insn.arg_reloc, NULL);
  1400. }
  1401.  
  1402. /* Do the real work for assembling a single instruction.  Store results
  1403.    into the global "the_insn" variable.  */
  1404.  
  1405. static void
  1406. pa_ip (str)
  1407.      char *str;
  1408. {
  1409.   char *error_message = "";
  1410.   char *s, c, *argstart, *name, *save_s;
  1411.   const char *args;
  1412.   int match = FALSE;
  1413.   int comma = 0;
  1414.   int cmpltr, nullif, flag, cond, num;
  1415.   unsigned long opcode;
  1416.   struct pa_opcode *insn;
  1417.  
  1418.   /* We must have a valid space and subspace.  */
  1419.   pa_check_current_space_and_subspace ();
  1420.  
  1421.   /* Skip to something interesting.  */
  1422.   for (s = str; isupper (*s) || islower (*s) || (*s >= '0' && *s <= '3'); ++s)
  1423.     ;
  1424.  
  1425.   switch (*s)
  1426.     {
  1427.  
  1428.     case '\0':
  1429.       break;
  1430.  
  1431.     case ',':
  1432.       comma = 1;
  1433.  
  1434.       /*FALLTHROUGH */
  1435.  
  1436.     case ' ':
  1437.       *s++ = '\0';
  1438.       break;
  1439.  
  1440.     default:
  1441.       as_fatal ("Unknown opcode: `%s'", str);
  1442.     }
  1443.  
  1444.   save_s = str;
  1445.  
  1446.   /* Convert everything into lower case.  */
  1447.   while (*save_s)
  1448.     {
  1449.       if (isupper (*save_s))
  1450.     *save_s = tolower (*save_s);
  1451.       save_s++;
  1452.     }
  1453.  
  1454.   /* Look up the opcode in the has table.  */
  1455.   if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
  1456.     {
  1457.       as_bad ("Unknown opcode: `%s'", str);
  1458.       return;
  1459.     }
  1460.  
  1461.   if (comma)
  1462.     {
  1463.       *--s = ',';
  1464.     }
  1465.  
  1466.   /* Mark the location where arguments for the instruction start, then
  1467.      start processing them.  */
  1468.   argstart = s;
  1469.   for (;;)
  1470.     {
  1471.       /* Do some initialization.  */
  1472.       opcode = insn->match;
  1473.       bzero (&the_insn, sizeof (the_insn));
  1474.  
  1475.       the_insn.reloc = R_HPPA_NONE;
  1476.  
  1477.       /* If this instruction is specific to a particular architecture,
  1478.      then set a new architecture.  */
  1479.       if (bfd_get_mach (stdoutput) < insn->arch)
  1480.     {
  1481.       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, insn->arch))
  1482.         as_warn ("could not update architecture and machine");
  1483.     }
  1484.  
  1485.       /* Build the opcode, checking as we go to make
  1486.          sure that the operands match.  */
  1487.       for (args = insn->args;; ++args)
  1488.     {
  1489.       switch (*args)
  1490.         {
  1491.  
  1492.         /* End of arguments.  */
  1493.         case '\0':
  1494.           if (*s == '\0')
  1495.         match = TRUE;
  1496.           break;
  1497.  
  1498.         case '+':
  1499.           if (*s == '+')
  1500.         {
  1501.           ++s;
  1502.           continue;
  1503.         }
  1504.           if (*s == '-')
  1505.         continue;
  1506.           break;
  1507.  
  1508.         /* These must match exactly.  */
  1509.         case '(':
  1510.         case ')':
  1511.         case ',':
  1512.         case ' ':
  1513.           if (*s++ == *args)
  1514.         continue;
  1515.           break;
  1516.  
  1517.         /* Handle a 5 bit register or control register field at 10.  */
  1518.         case 'b':
  1519.         case '^':
  1520.           num = pa_parse_number (&s, 0);
  1521.           CHECK_FIELD (num, 31, 0, 0);
  1522.           INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  1523.  
  1524.         /* Handle a 5 bit register field at 15.  */
  1525.         case 'x':
  1526.           num = pa_parse_number (&s, 0);
  1527.           CHECK_FIELD (num, 31, 0, 0);
  1528.           INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  1529.  
  1530.         /* Handle a 5 bit register field at 31.  */
  1531.         case 'y':
  1532.         case 't':
  1533.           num = pa_parse_number (&s, 0);
  1534.           CHECK_FIELD (num, 31, 0, 0);
  1535.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1536.  
  1537.         /* Handle a 5 bit field length at 31.  */
  1538.         case 'T':
  1539.           num = pa_get_absolute_expression (&the_insn, &s);
  1540.           s = expr_end;
  1541.           CHECK_FIELD (num, 32, 1, 0);
  1542.           INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
  1543.  
  1544.         /* Handle a 5 bit immediate at 15.  */
  1545.         case '5':
  1546.           num = pa_get_absolute_expression (&the_insn, &s);
  1547.           s = expr_end;
  1548.           CHECK_FIELD (num, 15, -16, 0);
  1549.           low_sign_unext (num, 5, &num);
  1550.           INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  1551.  
  1552.         /* Handle a 5 bit immediate at 31.  */
  1553.         case 'V':
  1554.           num = pa_get_absolute_expression (&the_insn, &s);
  1555.           s = expr_end;
  1556.           CHECK_FIELD (num, 15, -16, 0)
  1557.         low_sign_unext (num, 5, &num);
  1558.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1559.  
  1560.         /* Handle an unsigned 5 bit immediate at 31.  */
  1561.         case 'r':
  1562.           num = pa_get_absolute_expression (&the_insn, &s);
  1563.           s = expr_end;
  1564.           CHECK_FIELD (num, 31, 0, 0);
  1565.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  1566.  
  1567.         /* Handle an unsigned 5 bit immediate at 15.  */
  1568.         case 'R':
  1569.           num = pa_get_absolute_expression (&the_insn, &s);
  1570.           s = expr_end;
  1571.           CHECK_FIELD (num, 31, 0, 0);
  1572.           INSERT_FIELD_AND_CONTINUE (opcode, num, 16);
  1573.  
  1574.         /* Handle a 2 bit space identifier at 17.  */
  1575.         case 's':
  1576.           num = pa_parse_number (&s, 0);
  1577.           CHECK_FIELD (num, 3, 0, 1);
  1578.           INSERT_FIELD_AND_CONTINUE (opcode, num, 14);
  1579.  
  1580.         /* Handle a 3 bit space identifier at 18.  */
  1581.         case 'S':
  1582.           num = pa_parse_number (&s, 0);
  1583.           CHECK_FIELD (num, 7, 0, 1);
  1584.           dis_assemble_3 (num, &num);
  1585.           INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  1586.  
  1587.         /* Handle a completer for an indexing load or store.  */
  1588.         case 'c':
  1589.           {
  1590.         int uu = 0;
  1591.         int m = 0;
  1592.         int i = 0;
  1593.         while (*s == ',' && i < 2)
  1594.           {
  1595.             s++;
  1596.             if (strncasecmp (s, "sm", 2) == 0)
  1597.               {
  1598.             uu = 1;
  1599.             m = 1;
  1600.             s++;
  1601.             i++;
  1602.               }
  1603.             else if (strncasecmp (s, "m", 1) == 0)
  1604.               m = 1;
  1605.             else if (strncasecmp (s, "s", 1) == 0)
  1606.               uu = 1;
  1607.             else
  1608.               as_bad ("Invalid Indexed Load Completer.");
  1609.             s++;
  1610.             i++;
  1611.           }
  1612.         if (i > 2)
  1613.           as_bad ("Invalid Indexed Load Completer Syntax.");
  1614.         opcode |= m << 5;
  1615.         INSERT_FIELD_AND_CONTINUE (opcode, uu, 13);
  1616.           }
  1617.  
  1618.         /* Handle a short load/store completer.  */
  1619.         case 'C':
  1620.           {
  1621.         int a = 0;
  1622.         int m = 0;
  1623.         if (*s == ',')
  1624.           {
  1625.             s++;
  1626.             if (strncasecmp (s, "ma", 2) == 0)
  1627.               {
  1628.             a = 0;
  1629.             m = 1;
  1630.               }
  1631.             else if (strncasecmp (s, "mb", 2) == 0)
  1632.               {
  1633.             a = 1;
  1634.             m = 1;
  1635.               }
  1636.             else
  1637.               as_bad ("Invalid Short Load/Store Completer.");
  1638.             s += 2;
  1639.           }
  1640.         opcode |= m << 5;
  1641.         INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
  1642.           }
  1643.  
  1644.         /* Handle a stbys completer.  */
  1645.         case 'Y':
  1646.           {
  1647.         int a = 0;
  1648.         int m = 0;
  1649.         int i = 0;
  1650.         while (*s == ',' && i < 2)
  1651.           {
  1652.             s++;
  1653.             if (strncasecmp (s, "m", 1) == 0)
  1654.               m = 1;
  1655.             else if (strncasecmp (s, "b", 1) == 0)
  1656.               a = 0;
  1657.             else if (strncasecmp (s, "e", 1) == 0)
  1658.               a = 1;
  1659.             else
  1660.               as_bad ("Invalid Store Bytes Short Completer");
  1661.             s++;
  1662.             i++;
  1663.           }
  1664.         if (i > 2)
  1665.           as_bad ("Invalid Store Bytes Short Completer");
  1666.         opcode |= m << 5;
  1667.         INSERT_FIELD_AND_CONTINUE (opcode, a, 13);
  1668.           }
  1669.  
  1670.         /* Handle a non-negated compare/stubtract condition.  */
  1671.         case '<':
  1672.           cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
  1673.           if (cmpltr < 0)
  1674.         {
  1675.           as_bad ("Invalid Compare/Subtract Condition: %c", *s);
  1676.           cmpltr = 0;
  1677.         }
  1678.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1679.  
  1680.         /* Handle a negated or non-negated compare/subtract condition.  */
  1681.         case '?':
  1682.           save_s = s;
  1683.           cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 1);
  1684.           if (cmpltr < 0)
  1685.         {
  1686.           s = save_s;
  1687.           cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 1);
  1688.           if (cmpltr < 0)
  1689.             {
  1690.               as_bad ("Invalid Compare/Subtract Condition.");
  1691.               cmpltr = 0;
  1692.             }
  1693.           else
  1694.             {
  1695.               /* Negated condition requires an opcode change.  */
  1696.               opcode |= 1 << 27;
  1697.             }
  1698.         }
  1699.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1700.  
  1701.         /* Handle non-negated add condition.  */
  1702.         case '!':
  1703.           cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
  1704.           if (cmpltr < 0)
  1705.         {
  1706.           as_bad ("Invalid Compare/Subtract Condition: %c", *s);
  1707.           cmpltr = 0;
  1708.         }
  1709.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1710.  
  1711.         /* Handle a negated or non-negated add condition.  */
  1712.         case '@':
  1713.           save_s = s;
  1714.           cmpltr = pa_parse_nonneg_add_cmpltr (&s, 1);
  1715.           if (cmpltr < 0)
  1716.         {
  1717.           s = save_s;
  1718.           cmpltr = pa_parse_neg_add_cmpltr (&s, 1);
  1719.           if (cmpltr < 0)
  1720.             {
  1721.               as_bad ("Invalid Compare/Subtract Condition");
  1722.               cmpltr = 0;
  1723.             }
  1724.           else
  1725.             {
  1726.               /* Negated condition requires an opcode change.  */
  1727.               opcode |= 1 << 27;
  1728.             }
  1729.         }
  1730.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1731.  
  1732.         /* Handle a compare/subtract condition.  */
  1733.         case 'a':
  1734.           cmpltr = 0;
  1735.           flag = 0;
  1736.           save_s = s;
  1737.           if (*s == ',')
  1738.         {
  1739.           cmpltr = pa_parse_nonneg_cmpsub_cmpltr (&s, 0);
  1740.           if (cmpltr < 0)
  1741.             {
  1742.               flag = 1;
  1743.               s = save_s;
  1744.               cmpltr = pa_parse_neg_cmpsub_cmpltr (&s, 0);
  1745.               if (cmpltr < 0)
  1746.             {
  1747.               as_bad ("Invalid Compare/Subtract Condition");
  1748.             }
  1749.             }
  1750.         }
  1751.           opcode |= cmpltr << 13;
  1752.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1753.  
  1754.         /* Handle a non-negated add condition.  */
  1755.         case 'd':
  1756.           cmpltr = 0;
  1757.           nullif = 0;
  1758.           flag = 0;
  1759.           if (*s == ',')
  1760.         {
  1761.           s++;
  1762.           name = s;
  1763.           while (*s != ',' && *s != ' ' && *s != '\t')
  1764.             s += 1;
  1765.           c = *s;
  1766.           *s = 0x00;
  1767.           if (strcmp (name, "=") == 0)
  1768.             cmpltr = 1;
  1769.           else if (strcmp (name, "<") == 0)
  1770.             cmpltr = 2;
  1771.           else if (strcmp (name, "<=") == 0)
  1772.             cmpltr = 3;
  1773.           else if (strcasecmp (name, "nuv") == 0)
  1774.             cmpltr = 4;
  1775.           else if (strcasecmp (name, "znv") == 0)
  1776.             cmpltr = 5;
  1777.           else if (strcasecmp (name, "sv") == 0)
  1778.             cmpltr = 6;
  1779.           else if (strcasecmp (name, "od") == 0)
  1780.             cmpltr = 7;
  1781.           else if (strcasecmp (name, "n") == 0)
  1782.             nullif = 1;
  1783.           else if (strcasecmp (name, "tr") == 0)
  1784.             {
  1785.               cmpltr = 0;
  1786.               flag = 1;
  1787.             }
  1788.           else if (strcmp (name, "<>") == 0)
  1789.             {
  1790.               cmpltr = 1;
  1791.               flag = 1;
  1792.             }
  1793.           else if (strcmp (name, ">=") == 0)
  1794.             {
  1795.               cmpltr = 2;
  1796.               flag = 1;
  1797.             }
  1798.           else if (strcmp (name, ">") == 0)
  1799.             {
  1800.               cmpltr = 3;
  1801.               flag = 1;
  1802.             }
  1803.           else if (strcasecmp (name, "uv") == 0)
  1804.             {
  1805.               cmpltr = 4;
  1806.               flag = 1;
  1807.             }
  1808.           else if (strcasecmp (name, "vnz") == 0)
  1809.             {
  1810.               cmpltr = 5;
  1811.               flag = 1;
  1812.             }
  1813.           else if (strcasecmp (name, "nsv") == 0)
  1814.             {
  1815.               cmpltr = 6;
  1816.               flag = 1;
  1817.             }
  1818.           else if (strcasecmp (name, "ev") == 0)
  1819.             {
  1820.               cmpltr = 7;
  1821.               flag = 1;
  1822.             }
  1823.           else
  1824.             as_bad ("Invalid Add Condition: %s", name);
  1825.           *s = c;
  1826.         }
  1827.           nullif = pa_parse_nullif (&s);
  1828.           opcode |= nullif << 1;
  1829.           opcode |= cmpltr << 13;
  1830.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1831.  
  1832.         /* HANDLE a logical instruction condition.  */
  1833.         case '&':
  1834.           cmpltr = 0;
  1835.           flag = 0;
  1836.           if (*s == ',')
  1837.         {
  1838.           s++;
  1839.           name = s;
  1840.           while (*s != ',' && *s != ' ' && *s != '\t')
  1841.             s += 1;
  1842.           c = *s;
  1843.           *s = 0x00;
  1844.           if (strcmp (name, "=") == 0)
  1845.             cmpltr = 1;
  1846.           else if (strcmp (name, "<") == 0)
  1847.             cmpltr = 2;
  1848.           else if (strcmp (name, "<=") == 0)
  1849.             cmpltr = 3;
  1850.           else if (strcasecmp (name, "od") == 0)
  1851.             cmpltr = 7;
  1852.           else if (strcasecmp (name, "tr") == 0)
  1853.             {
  1854.               cmpltr = 0;
  1855.               flag = 1;
  1856.             }
  1857.           else if (strcmp (name, "<>") == 0)
  1858.             {
  1859.               cmpltr = 1;
  1860.               flag = 1;
  1861.             }
  1862.           else if (strcmp (name, ">=") == 0)
  1863.             {
  1864.               cmpltr = 2;
  1865.               flag = 1;
  1866.             }
  1867.           else if (strcmp (name, ">") == 0)
  1868.             {
  1869.               cmpltr = 3;
  1870.               flag = 1;
  1871.             }
  1872.           else if (strcasecmp (name, "ev") == 0)
  1873.             {
  1874.               cmpltr = 7;
  1875.               flag = 1;
  1876.             }
  1877.           else
  1878.             as_bad ("Invalid Logical Instruction Condition.");
  1879.           *s = c;
  1880.         }
  1881.           opcode |= cmpltr << 13;
  1882.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1883.  
  1884.         /* Handle a unit instruction condition.  */
  1885.         case 'U':
  1886.           cmpltr = 0;
  1887.           flag = 0;
  1888.           if (*s == ',')
  1889.         {
  1890.           s++;
  1891.           if (strncasecmp (s, "sbz", 3) == 0)
  1892.             {
  1893.               cmpltr = 2;
  1894.               s += 3;
  1895.             }
  1896.           else if (strncasecmp (s, "shz", 3) == 0)
  1897.             {
  1898.               cmpltr = 3;
  1899.               s += 3;
  1900.             }
  1901.           else if (strncasecmp (s, "sdc", 3) == 0)
  1902.             {
  1903.               cmpltr = 4;
  1904.               s += 3;
  1905.             }
  1906.           else if (strncasecmp (s, "sbc", 3) == 0)
  1907.             {
  1908.               cmpltr = 6;
  1909.               s += 3;
  1910.             }
  1911.           else if (strncasecmp (s, "shc", 3) == 0)
  1912.             {
  1913.               cmpltr = 7;
  1914.               s += 3;
  1915.             }
  1916.           else if (strncasecmp (s, "tr", 2) == 0)
  1917.             {
  1918.               cmpltr = 0;
  1919.               flag = 1;
  1920.               s += 2;
  1921.             }
  1922.           else if (strncasecmp (s, "nbz", 3) == 0)
  1923.             {
  1924.               cmpltr = 2;
  1925.               flag = 1;
  1926.               s += 3;
  1927.             }
  1928.           else if (strncasecmp (s, "nhz", 3) == 0)
  1929.             {
  1930.               cmpltr = 3;
  1931.               flag = 1;
  1932.               s += 3;
  1933.             }
  1934.           else if (strncasecmp (s, "ndc", 3) == 0)
  1935.             {
  1936.               cmpltr = 4;
  1937.               flag = 1;
  1938.               s += 3;
  1939.             }
  1940.           else if (strncasecmp (s, "nbc", 3) == 0)
  1941.             {
  1942.               cmpltr = 6;
  1943.               flag = 1;
  1944.               s += 3;
  1945.             }
  1946.           else if (strncasecmp (s, "nhc", 3) == 0)
  1947.             {
  1948.               cmpltr = 7;
  1949.               flag = 1;
  1950.               s += 3;
  1951.             }
  1952.           else
  1953.             as_bad ("Invalid Logical Instruction Condition.");
  1954.         }
  1955.           opcode |= cmpltr << 13;
  1956.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
  1957.  
  1958.         /* Handle a shift/extract/deposit condition.  */
  1959.         case '|':
  1960.         case '>':
  1961.           cmpltr = 0;
  1962.           if (*s == ',')
  1963.         {
  1964.           save_s = s++;
  1965.           name = s;
  1966.           while (*s != ',' && *s != ' ' && *s != '\t')
  1967.             s += 1;
  1968.           c = *s;
  1969.           *s = 0x00;
  1970.           if (strcmp (name, "=") == 0)
  1971.             cmpltr = 1;
  1972.           else if (strcmp (name, "<") == 0)
  1973.             cmpltr = 2;
  1974.           else if (strcasecmp (name, "od") == 0)
  1975.             cmpltr = 3;
  1976.           else if (strcasecmp (name, "tr") == 0)
  1977.             cmpltr = 4;
  1978.           else if (strcmp (name, "<>") == 0)
  1979.             cmpltr = 5;
  1980.           else if (strcmp (name, ">=") == 0)
  1981.             cmpltr = 6;
  1982.           else if (strcasecmp (name, "ev") == 0)
  1983.             cmpltr = 7;
  1984.           /* Handle movb,n.  Put things back the way they were.
  1985.              This includes moving s back to where it started.  */
  1986.           else if (strcasecmp (name, "n") == 0 && *args == '|')
  1987.             {
  1988.               *s = c;
  1989.               s = save_s;
  1990.               continue;
  1991.             }
  1992.           else
  1993.             as_bad ("Invalid Shift/Extract/Deposit Condition.");
  1994.           *s = c;
  1995.         }
  1996.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  1997.  
  1998.         /* Handle bvb and bb conditions.  */
  1999.         case '~':
  2000.           cmpltr = 0;
  2001.           if (*s == ',')
  2002.         {
  2003.           s++;
  2004.           if (strncmp (s, "<", 1) == 0)
  2005.             {
  2006.               cmpltr = 2;
  2007.               s++;
  2008.             }
  2009.           else if (strncmp (s, ">=", 2) == 0)
  2010.             {
  2011.               cmpltr = 6;
  2012.               s += 2;
  2013.             }
  2014.           else
  2015.             as_bad ("Invalid Bit Branch Condition: %c", *s);
  2016.         }
  2017.           INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
  2018.  
  2019.         /* Handle a system control completer.  */
  2020.         case 'Z':
  2021.           if (*s == ',' && (*(s + 1) == 'm' || *(s + 1) == 'M'))
  2022.         {
  2023.           flag = 1;
  2024.           s += 2;
  2025.         }
  2026.           else
  2027.         flag = 0;
  2028.  
  2029.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
  2030.  
  2031.         /* Handle a nullification completer for branch instructions.  */
  2032.         case 'n':
  2033.           nullif = pa_parse_nullif (&s);
  2034.           INSERT_FIELD_AND_CONTINUE (opcode, nullif, 1);
  2035.  
  2036.         /* Handle a nullification completer for copr and spop insns.  */
  2037.         case 'N':
  2038.           nullif = pa_parse_nullif (&s);
  2039.           INSERT_FIELD_AND_CONTINUE (opcode, nullif, 5);
  2040.  
  2041.         /* Handle a 11 bit immediate at 31.  */
  2042.         case 'i':
  2043.           the_insn.field_selector = pa_chk_field_selector (&s);
  2044.           get_expression (s);
  2045.           s = expr_end;
  2046.           if (the_insn.exp.X_op == O_constant)
  2047.         {
  2048.           num = evaluate_absolute (&the_insn);
  2049.           CHECK_FIELD (num, 1023, -1024, 0);
  2050.           low_sign_unext (num, 11, &num);
  2051.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2052.         }
  2053.           else
  2054.         {
  2055.           if (is_DP_relative (the_insn.exp))
  2056.             the_insn.reloc = R_HPPA_GOTOFF;
  2057.           else if (is_PC_relative (the_insn.exp))
  2058.             the_insn.reloc = R_HPPA_PCREL_CALL;
  2059.           else
  2060.             the_insn.reloc = R_HPPA;
  2061.           the_insn.format = 11;
  2062.           continue;
  2063.         }
  2064.  
  2065.         /* Handle a 14 bit immediate at 31.  */
  2066.         case 'j':
  2067.           the_insn.field_selector = pa_chk_field_selector (&s);
  2068.           get_expression (s);
  2069.           s = expr_end;
  2070.           if (the_insn.exp.X_op == O_constant)
  2071.         {
  2072.           num = evaluate_absolute (&the_insn);
  2073.           CHECK_FIELD (num, 8191, -8192, 0);
  2074.           low_sign_unext (num, 14, &num);
  2075.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2076.         }
  2077.           else
  2078.         {
  2079.           if (is_DP_relative (the_insn.exp))
  2080.             the_insn.reloc = R_HPPA_GOTOFF;
  2081.           else if (is_PC_relative (the_insn.exp))
  2082.             the_insn.reloc = R_HPPA_PCREL_CALL;
  2083.           else
  2084.             the_insn.reloc = R_HPPA;
  2085.           the_insn.format = 14;
  2086.           continue;
  2087.         }
  2088.  
  2089.         /* Handle a 21 bit immediate at 31.  */
  2090.         case 'k':
  2091.           the_insn.field_selector = pa_chk_field_selector (&s);
  2092.           get_expression (s);
  2093.           s = expr_end;
  2094.           if (the_insn.exp.X_op == O_constant)
  2095.         {
  2096.           num = evaluate_absolute (&the_insn);
  2097.           CHECK_FIELD (num >> 11, 1048575, -1048576, 0);
  2098.           dis_assemble_21 (num, &num);
  2099.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2100.         }
  2101.           else
  2102.         {
  2103.           if (is_DP_relative (the_insn.exp))
  2104.             the_insn.reloc = R_HPPA_GOTOFF;
  2105.           else if (is_PC_relative (the_insn.exp))
  2106.             the_insn.reloc = R_HPPA_PCREL_CALL;
  2107.           else
  2108.             the_insn.reloc = R_HPPA;
  2109.           the_insn.format = 21;
  2110.           continue;
  2111.         }
  2112.  
  2113.         /* Handle a 12 bit branch displacement.  */
  2114.         case 'w':
  2115.           the_insn.field_selector = pa_chk_field_selector (&s);
  2116.           get_expression (s);
  2117.           s = expr_end;
  2118.           the_insn.pcrel = 1;
  2119.           if (!strcmp (S_GET_NAME (the_insn.exp.X_add_symbol), "L$0\001"))
  2120.         {
  2121.           unsigned int w1, w, result;
  2122.  
  2123.           num = evaluate_absolute (&the_insn);
  2124.           if (num % 4)
  2125.             {
  2126.               as_bad ("Branch to unaligned address");
  2127.               break;
  2128.             }
  2129.           CHECK_FIELD (num, 8199, -8184, 0);
  2130.           sign_unext ((num - 8) >> 2, 12, &result);
  2131.           dis_assemble_12 (result, &w1, &w);
  2132.           INSERT_FIELD_AND_CONTINUE (opcode, ((w1 << 2) | w), 0);
  2133.         }
  2134.           else
  2135.         {
  2136.           the_insn.reloc = R_HPPA_PCREL_CALL;
  2137.           the_insn.format = 12;
  2138.           the_insn.arg_reloc = last_call_desc.arg_reloc;
  2139.           bzero (&last_call_desc, sizeof (struct call_desc));
  2140.           s = expr_end;
  2141.           continue;
  2142.         }
  2143.  
  2144.         /* Handle a 17 bit branch displacement.  */
  2145.         case 'W':
  2146.           the_insn.field_selector = pa_chk_field_selector (&s);
  2147.           get_expression (s);
  2148.           s = expr_end;
  2149.           the_insn.pcrel = 1;
  2150.           if (!the_insn.exp.X_add_symbol
  2151.           || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  2152.                   "L$0\001"))
  2153.         {
  2154.           unsigned int w2, w1, w, result;
  2155.  
  2156.           num = evaluate_absolute (&the_insn);
  2157.           if (num % 4)
  2158.             {
  2159.               as_bad ("Branch to unaligned address");
  2160.               break;
  2161.             }
  2162.           CHECK_FIELD (num, 262143, -262144, 0);
  2163.  
  2164.           if (the_insn.exp.X_add_symbol)
  2165.             num -= 8;
  2166.  
  2167.           sign_unext (num >> 2, 17, &result);
  2168.           dis_assemble_17 (result, &w1, &w2, &w);
  2169.           INSERT_FIELD_AND_CONTINUE (opcode,
  2170.                        ((w2 << 2) | (w1 << 16) | w), 0);
  2171.         }
  2172.           else
  2173.         {
  2174.           the_insn.reloc = R_HPPA_PCREL_CALL;
  2175.           the_insn.format = 17;
  2176.           the_insn.arg_reloc = last_call_desc.arg_reloc;
  2177.           bzero (&last_call_desc, sizeof (struct call_desc));
  2178.           continue;
  2179.         }
  2180.  
  2181.         /* Handle an absolute 17 bit branch target.  */
  2182.         case 'z':
  2183.           the_insn.field_selector = pa_chk_field_selector (&s);
  2184.           get_expression (s);
  2185.           s = expr_end;
  2186.           the_insn.pcrel = 0;
  2187.           if (!the_insn.exp.X_add_symbol
  2188.           || !strcmp (S_GET_NAME (the_insn.exp.X_add_symbol),
  2189.                   "L$0\001"))
  2190.         {
  2191.           unsigned int w2, w1, w, result;
  2192.  
  2193.           num = evaluate_absolute (&the_insn);
  2194.           if (num % 4)
  2195.             {
  2196.               as_bad ("Branch to unaligned address");
  2197.               break;
  2198.             }
  2199.           CHECK_FIELD (num, 262143, -262144, 0);
  2200.  
  2201.           if (the_insn.exp.X_add_symbol)
  2202.             num -= 8;
  2203.  
  2204.           sign_unext (num >> 2, 17, &result);
  2205.           dis_assemble_17 (result, &w1, &w2, &w);
  2206.           INSERT_FIELD_AND_CONTINUE (opcode,
  2207.                        ((w2 << 2) | (w1 << 16) | w), 0);
  2208.         }
  2209.           else
  2210.         {
  2211.           the_insn.reloc = R_HPPA_ABS_CALL;
  2212.           the_insn.format = 17;
  2213.           the_insn.arg_reloc = last_call_desc.arg_reloc;
  2214.           bzero (&last_call_desc, sizeof (struct call_desc));
  2215.           continue;
  2216.         }
  2217.  
  2218.         /* Handle a 5 bit shift count at 26.  */
  2219.         case 'p':
  2220.           num = pa_get_absolute_expression (&the_insn, &s);
  2221.           s = expr_end;
  2222.           CHECK_FIELD (num, 31, 0, 0);
  2223.           INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
  2224.  
  2225.         /* Handle a 5 bit bit position at 26.  */
  2226.         case 'P':
  2227.           num = pa_get_absolute_expression (&the_insn, &s);
  2228.           s = expr_end;
  2229.           CHECK_FIELD (num, 31, 0, 0);
  2230.           INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
  2231.  
  2232.         /* Handle a 5 bit immediate at 10.  */
  2233.         case 'Q':
  2234.           num = pa_get_absolute_expression (&the_insn, &s);
  2235.           s = expr_end;
  2236.           CHECK_FIELD (num, 31, 0, 0);
  2237.           INSERT_FIELD_AND_CONTINUE (opcode, num, 21);
  2238.  
  2239.         /* Handle a 13 bit immediate at 18.  */
  2240.         case 'A':
  2241.           num = pa_get_absolute_expression (&the_insn, &s);
  2242.           s = expr_end;
  2243.           CHECK_FIELD (num, 8191, 0, 0);
  2244.           INSERT_FIELD_AND_CONTINUE (opcode, num, 13);
  2245.  
  2246.         /* Handle a 26 bit immediate at 31.  */
  2247.         case 'D':
  2248.           num = pa_get_absolute_expression (&the_insn, &s);
  2249.           s = expr_end;
  2250.           CHECK_FIELD (num, 671108864, 0, 0);
  2251.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2252.  
  2253.         /* Handle a 3 bit SFU identifier at 25.  */
  2254.         case 'f':
  2255.           if (*s++ != ',')
  2256.         as_bad ("Invalid SFU identifier");
  2257.           num = pa_get_absolute_expression (&the_insn, &s);
  2258.           s = expr_end;
  2259.           CHECK_FIELD (num, 7, 0, 0);
  2260.           INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  2261.  
  2262.         /* Handle a 20 bit SOP field for spop0.  */
  2263.         case 'O':
  2264.           num = pa_get_absolute_expression (&the_insn, &s);
  2265.           s = expr_end;
  2266.           CHECK_FIELD (num, 1048575, 0, 0);
  2267.           num = (num & 0x1f) | ((num & 0x000fffe0) << 6);
  2268.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2269.  
  2270.         /* Handle a 15bit SOP field for spop1.  */
  2271.         case 'o':
  2272.           num = pa_get_absolute_expression (&the_insn, &s);
  2273.           s = expr_end;
  2274.           CHECK_FIELD (num, 32767, 0, 0);
  2275.           INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
  2276.  
  2277.         /* Handle a 10bit SOP field for spop3.  */
  2278.         case '0':
  2279.           num = pa_get_absolute_expression (&the_insn, &s);
  2280.           s = expr_end;
  2281.           CHECK_FIELD (num, 1023, 0, 0);
  2282.           num = (num & 0x1f) | ((num & 0x000003e0) << 6);
  2283.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2284.  
  2285.         /* Handle a 15 bit SOP field for spop2.  */
  2286.         case '1':
  2287.           num = pa_get_absolute_expression (&the_insn, &s);
  2288.           s = expr_end;
  2289.           CHECK_FIELD (num, 32767, 0, 0);
  2290.           num = (num & 0x1f) | ((num & 0x00007fe0) << 6);
  2291.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2292.  
  2293.         /* Handle a 3-bit co-processor ID field.  */
  2294.         case 'u':
  2295.           if (*s++ != ',')
  2296.         as_bad ("Invalid COPR identifier");
  2297.           num = pa_get_absolute_expression (&the_insn, &s);
  2298.           s = expr_end;
  2299.           CHECK_FIELD (num, 7, 0, 0);
  2300.           INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
  2301.  
  2302.         /* Handle a 22bit SOP field for copr.  */
  2303.         case '2':
  2304.           num = pa_get_absolute_expression (&the_insn, &s);
  2305.           s = expr_end;
  2306.           CHECK_FIELD (num, 4194303, 0, 0);
  2307.           num = (num & 0x1f) | ((num & 0x003fffe0) << 4);
  2308.           INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
  2309.  
  2310.         /* Handle a source FP operand format completer.  */
  2311.         case 'F':
  2312.           flag = pa_parse_fp_format (&s);
  2313.           the_insn.fpof1 = flag;
  2314.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
  2315.  
  2316.         /* Handle a destination FP operand format completer.  */
  2317.         case 'G':
  2318.           /* pa_parse_format needs the ',' prefix.  */
  2319.           s--;
  2320.           flag = pa_parse_fp_format (&s);
  2321.           the_insn.fpof2 = flag;
  2322.           INSERT_FIELD_AND_CONTINUE (opcode, flag, 13);
  2323.  
  2324.         /* Handle FP compare conditions.  */
  2325.         case 'M':
  2326.           cond = pa_parse_fp_cmp_cond (&s);
  2327.           INSERT_FIELD_AND_CONTINUE (opcode, cond, 0);
  2328.  
  2329.         /* Handle L/R register halves like 't'.  */
  2330.         case 'v':
  2331.           {
  2332.         struct pa_11_fp_reg_struct result;
  2333.  
  2334.         pa_parse_number (&s, &result);
  2335.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2336.         opcode |= result.number_part;
  2337.  
  2338.         /* 0x30 opcodes are FP arithmetic operation opcodes
  2339.            and need to be turned into 0x38 opcodes.  This
  2340.            is not necessary for loads/stores.  */
  2341.         if (need_pa11_opcode (&the_insn, &result)
  2342.             && ((opcode & 0xfc000000) == 0x30000000))
  2343.           opcode |= 1 << 27;
  2344.  
  2345.         INSERT_FIELD_AND_CONTINUE (opcode, result.l_r_select & 1, 6);
  2346.           }
  2347.  
  2348.         /* Handle L/R register halves like 'b'.  */
  2349.         case 'E':
  2350.           {
  2351.         struct pa_11_fp_reg_struct result;
  2352.  
  2353.         pa_parse_number (&s, &result);
  2354.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2355.         opcode |= result.number_part << 21;
  2356.         if (need_pa11_opcode (&the_insn, &result))
  2357.           {
  2358.             opcode |= (result.l_r_select & 1) << 7;
  2359.             opcode |= 1 << 27;
  2360.           }
  2361.         continue;
  2362.           }
  2363.  
  2364.         /* Handle L/R register halves like 'x'.  */
  2365.         case 'X':
  2366.           {
  2367.         struct pa_11_fp_reg_struct result;
  2368.  
  2369.         pa_parse_number (&s, &result);
  2370.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2371.         opcode |= (result.number_part & 0x1f) << 16;
  2372.         if (need_pa11_opcode (&the_insn, &result))
  2373.           {
  2374.             opcode |= (result.l_r_select & 1) << 12;
  2375.             opcode |= 1 << 27;
  2376.           }
  2377.         continue;
  2378.           }
  2379.  
  2380.         /* Handle a 5 bit register field at 10.  */
  2381.         case '4':
  2382.           {
  2383.         struct pa_11_fp_reg_struct result;
  2384.  
  2385.         pa_parse_number (&s, &result);
  2386.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2387.         if (the_insn.fpof1 == SGL)
  2388.           {
  2389.             if (result.number_part < 16)
  2390.               {
  2391.             as_bad  ("Invalid register for single precision fmpyadd or fmpysub");
  2392.             break;
  2393.               }
  2394.  
  2395.             result.number_part &= 0xF;
  2396.             result.number_part |= (result.l_r_select & 1) << 4;
  2397.           }
  2398.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 21);
  2399.           }
  2400.  
  2401.         /* Handle a 5 bit register field at 15.  */
  2402.         case '6':
  2403.           {
  2404.         struct pa_11_fp_reg_struct result;
  2405.  
  2406.         pa_parse_number (&s, &result);
  2407.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2408.         if (the_insn.fpof1 == SGL)
  2409.           {
  2410.             if (result.number_part < 16)
  2411.               {
  2412.             as_bad  ("Invalid register for single precision fmpyadd or fmpysub");
  2413.             break;
  2414.               }
  2415.             result.number_part &= 0xF;
  2416.             result.number_part |= (result.l_r_select & 1) << 4;
  2417.           }
  2418.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 16);
  2419.           }
  2420.  
  2421.         /* Handle a 5 bit register field at 31.  */
  2422.         case '7':
  2423.           {
  2424.         struct pa_11_fp_reg_struct result;
  2425.  
  2426.         pa_parse_number (&s, &result);
  2427.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2428.         if (the_insn.fpof1 == SGL)
  2429.           {
  2430.             if (result.number_part < 16)
  2431.               {
  2432.             as_bad  ("Invalid register for single precision fmpyadd or fmpysub");
  2433.             break;
  2434.               }
  2435.             result.number_part &= 0xF;
  2436.             result.number_part |= (result.l_r_select & 1) << 4;
  2437.           }
  2438.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 0);
  2439.           }
  2440.  
  2441.         /* Handle a 5 bit register field at 20.  */
  2442.         case '8':
  2443.           {
  2444.         struct pa_11_fp_reg_struct result;
  2445.  
  2446.         pa_parse_number (&s, &result);
  2447.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2448.         if (the_insn.fpof1 == SGL)
  2449.           {
  2450.             if (result.number_part < 16)
  2451.               {
  2452.             as_bad  ("Invalid register for single precision fmpyadd or fmpysub");
  2453.             break;
  2454.               }
  2455.             result.number_part &= 0xF;
  2456.             result.number_part |= (result.l_r_select & 1) << 4;
  2457.           }
  2458.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 11);
  2459.           }
  2460.  
  2461.         /* Handle a 5 bit register field at 25.  */
  2462.         case '9':
  2463.           {
  2464.         struct pa_11_fp_reg_struct result;
  2465.  
  2466.         pa_parse_number (&s, &result);
  2467.         CHECK_FIELD (result.number_part, 31, 0, 0);
  2468.         if (the_insn.fpof1 == SGL)
  2469.           {
  2470.             if (result.number_part < 16)
  2471.               {
  2472.             as_bad  ("Invalid register for single precision fmpyadd or fmpysub");
  2473.             break;
  2474.               }
  2475.             result.number_part &= 0xF;
  2476.             result.number_part |= (result.l_r_select & 1) << 4;
  2477.           }
  2478.         INSERT_FIELD_AND_CONTINUE (opcode, result.number_part, 6);
  2479.           }
  2480.  
  2481.         /* Handle a floating point operand format at 26.
  2482.            Only allows single and double precision.  */
  2483.         case 'H':
  2484.           flag = pa_parse_fp_format (&s);
  2485.           switch (flag)
  2486.         {
  2487.         case SGL:
  2488.           opcode |= 0x20;
  2489.         case DBL:
  2490.           the_insn.fpof1 = flag;
  2491.           continue;
  2492.  
  2493.         case QUAD:
  2494.         case ILLEGAL_FMT:
  2495.         default:
  2496.           as_bad ("Invalid Floating Point Operand Format.");
  2497.         }
  2498.           break;
  2499.  
  2500.         default:
  2501.           abort ();
  2502.         }
  2503.       break;
  2504.     }
  2505.  
  2506.       /* Check if the args matched.  */
  2507.       if (match == FALSE)
  2508.     {
  2509.       if (&insn[1] - pa_opcodes < NUMOPCODES
  2510.           && !strcmp (insn->name, insn[1].name))
  2511.         {
  2512.           ++insn;
  2513.           s = argstart;
  2514.           continue;
  2515.         }
  2516.       else
  2517.         {
  2518.           as_bad ("Invalid operands %s", error_message);
  2519.           return;
  2520.         }
  2521.     }
  2522.       break;
  2523.     }
  2524.  
  2525.   the_insn.opcode = opcode;
  2526. }
  2527.  
  2528. /* Turn a string in input_line_pointer into a floating point constant of type
  2529.    type, and store the appropriate bytes in *litP.  The number of LITTLENUMS
  2530.    emitted is stored in *sizeP .  An error message or NULL is returned.  */
  2531.  
  2532. #define MAX_LITTLENUMS 6
  2533.  
  2534. char *
  2535. md_atof (type, litP, sizeP)
  2536.      char type;
  2537.      char *litP;
  2538.      int *sizeP;
  2539. {
  2540.   int prec;
  2541.   LITTLENUM_TYPE words[MAX_LITTLENUMS];
  2542.   LITTLENUM_TYPE *wordP;
  2543.   char *t;
  2544.  
  2545.   switch (type)
  2546.     {
  2547.  
  2548.     case 'f':
  2549.     case 'F':
  2550.     case 's':
  2551.     case 'S':
  2552.       prec = 2;
  2553.       break;
  2554.  
  2555.     case 'd':
  2556.     case 'D':
  2557.     case 'r':
  2558.     case 'R':
  2559.       prec = 4;
  2560.       break;
  2561.  
  2562.     case 'x':
  2563.     case 'X':
  2564.       prec = 6;
  2565.       break;
  2566.  
  2567.     case 'p':
  2568.     case 'P':
  2569.       prec = 6;
  2570.       break;
  2571.  
  2572.     default:
  2573.       *sizeP = 0;
  2574.       return "Bad call to MD_ATOF()";
  2575.     }
  2576.   t = atof_ieee (input_line_pointer, type, words);
  2577.   if (t)
  2578.     input_line_pointer = t;
  2579.   *sizeP = prec * sizeof (LITTLENUM_TYPE);
  2580.   for (wordP = words; prec--;)
  2581.     {
  2582.       md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
  2583.       litP += sizeof (LITTLENUM_TYPE);
  2584.     }
  2585.   return NULL;
  2586. }
  2587.  
  2588. /* Write out big-endian.  */
  2589.  
  2590. void
  2591. md_number_to_chars (buf, val, n)
  2592.      char *buf;
  2593.      valueT val;
  2594.      int n;
  2595. {
  2596.   number_to_chars_bigendian (buf, val, n);
  2597. }
  2598.  
  2599. /* Translate internal representation of relocation info to BFD target
  2600.    format.  */
  2601.  
  2602. arelent **
  2603. tc_gen_reloc (section, fixp)
  2604.      asection *section;
  2605.      fixS *fixp;
  2606. {
  2607.   arelent *reloc;
  2608.   struct hppa_fix_struct *hppa_fixp;
  2609.   bfd_reloc_code_real_type code;
  2610.   static arelent *no_relocs = NULL;
  2611.   arelent **relocs;
  2612.   bfd_reloc_code_real_type **codes;
  2613.   int n_relocs;
  2614.   int i;
  2615.  
  2616.   hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
  2617.   if (fixp->fx_addsy == 0)
  2618.     return &no_relocs;
  2619.   assert (hppa_fixp != 0);
  2620.   assert (section != 0);
  2621.  
  2622.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
  2623.   assert (reloc != 0);
  2624.  
  2625.   reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2626.   codes = (bfd_reloc_code_real_type **) hppa_gen_reloc_type (stdoutput,
  2627.                    fixp->fx_r_type,
  2628.                    hppa_fixp->fx_r_format,
  2629.                    hppa_fixp->fx_r_field,
  2630.                    fixp->fx_subsy != NULL);
  2631.  
  2632.   for (n_relocs = 0; codes[n_relocs]; n_relocs++)
  2633.     ;
  2634.  
  2635.   relocs = (arelent **)
  2636.     bfd_alloc_by_size_t (stdoutput, sizeof (arelent *) * n_relocs + 1);
  2637.   assert (relocs != 0);
  2638.  
  2639.   reloc = (arelent *) bfd_alloc_by_size_t (stdoutput,
  2640.                        sizeof (arelent) * n_relocs);
  2641.   if (n_relocs > 0)
  2642.     assert (reloc != 0);
  2643.  
  2644.   for (i = 0; i < n_relocs; i++)
  2645.     relocs[i] = &reloc[i];
  2646.  
  2647.   relocs[n_relocs] = NULL;
  2648.  
  2649. #ifdef OBJ_ELF
  2650.   switch (fixp->fx_r_type)
  2651.     {
  2652.     default:
  2653.       assert (n_relocs == 1);
  2654.  
  2655.       code = *codes[0];
  2656.  
  2657.       reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2658.       reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
  2659.       reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2660.       reloc->addend = 0;    /* default */
  2661.  
  2662.       assert (reloc->howto && code == reloc->howto->type);
  2663.  
  2664.       /* Now, do any processing that is dependent on the relocation type.  */
  2665.       switch (code)
  2666.     {
  2667.     case R_PARISC_DLTREL21L:
  2668.     case R_PARISC_DLTREL14R:
  2669.     case R_PARISC_DLTREL14F:
  2670.     case R_PARISC_PLABEL32:
  2671.     case R_PARISC_PLABEL21L:
  2672.     case R_PARISC_PLABEL14R:
  2673.       /* For plabel relocations, the addend of the
  2674.          relocation should be either 0 (no static link) or 2
  2675.          (static link required).
  2676.  
  2677.          FIXME: We always assume no static link!
  2678.  
  2679.          We also slam a zero addend into the DLT relative relocs;
  2680.          it doesn't make a lot of sense to use any addend since
  2681.          it gets you a different (eg unknown) DLT entry.  */
  2682.       reloc->addend = 0;
  2683.       break;
  2684.  
  2685.     case R_PARISC_PCREL21L:
  2686.     case R_PARISC_PCREL17R:
  2687.     case R_PARISC_PCREL17F:
  2688.     case R_PARISC_PCREL17C:
  2689.     case R_PARISC_PCREL14R:
  2690.     case R_PARISC_PCREL14F:
  2691.       /* The constant is stored in the instruction.  */
  2692.       reloc->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
  2693.       break;
  2694.     default:
  2695.       reloc->addend = fixp->fx_offset;
  2696.       break;
  2697.     }
  2698.       break;
  2699.     }
  2700. #else /* OBJ_SOM */
  2701.  
  2702.   /* Walk over reach relocation returned by the BFD backend.  */
  2703.   for (i = 0; i < n_relocs; i++)
  2704.     {
  2705.       code = *codes[i];
  2706.  
  2707.       relocs[i]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2708.       relocs[i]->howto = bfd_reloc_type_lookup (stdoutput, code);
  2709.       relocs[i]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2710.  
  2711.       switch (code)
  2712.     {
  2713.     case R_COMP2:
  2714.       /* The only time we ever use a R_COMP2 fixup is for the difference
  2715.          of two symbols.  With that in mind we fill in all four
  2716.          relocs now and break out of the loop.  */
  2717.       assert (i == 1);
  2718.       relocs[0]->sym_ptr_ptr = &bfd_abs_symbol;
  2719.       relocs[0]->howto = bfd_reloc_type_lookup (stdoutput, *codes[0]);
  2720.       relocs[0]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2721.       relocs[0]->addend = 0;
  2722.       relocs[1]->sym_ptr_ptr = &fixp->fx_addsy->bsym;
  2723.       relocs[1]->howto = bfd_reloc_type_lookup (stdoutput, *codes[1]);
  2724.       relocs[1]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2725.       relocs[1]->addend = 0;
  2726.       relocs[2]->sym_ptr_ptr = &fixp->fx_subsy->bsym;
  2727.       relocs[2]->howto = bfd_reloc_type_lookup (stdoutput, *codes[2]);
  2728.       relocs[2]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2729.       relocs[2]->addend = 0;
  2730.       relocs[3]->sym_ptr_ptr = &bfd_abs_symbol;
  2731.       relocs[3]->howto = bfd_reloc_type_lookup (stdoutput, *codes[3]);
  2732.       relocs[3]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2733.       relocs[3]->addend = 0;
  2734.       relocs[4]->sym_ptr_ptr = &bfd_abs_symbol;
  2735.       relocs[4]->howto = bfd_reloc_type_lookup (stdoutput, *codes[4]);
  2736.       relocs[4]->address = fixp->fx_frag->fr_address + fixp->fx_where;
  2737.       relocs[4]->addend = 0;
  2738.       goto done;
  2739.     case R_PCREL_CALL:
  2740.     case R_ABS_CALL:
  2741.       relocs[i]->addend = HPPA_R_ADDEND (hppa_fixp->fx_arg_reloc, 0);
  2742.       break;
  2743.  
  2744.     case R_DLT_REL:
  2745.     case R_DATA_PLABEL:
  2746.     case R_CODE_PLABEL:
  2747.       /* For plabel relocations, the addend of the
  2748.          relocation should be either 0 (no static link) or 2
  2749.          (static link required).
  2750.  
  2751.          FIXME: We always assume no static link!
  2752.  
  2753.          We also slam a zero addend into the DLT relative relocs;
  2754.          it doesn't make a lot of sense to use any addend since
  2755.          it gets you a different (eg unknown) DLT entry.  */
  2756.       relocs[i]->addend = 0;
  2757.       break;
  2758.  
  2759.     case R_N_MODE:
  2760.     case R_S_MODE:
  2761.     case R_D_MODE:
  2762.     case R_R_MODE:
  2763.     case R_FSEL:
  2764.     case R_LSEL:
  2765.     case R_RSEL:
  2766.     case R_BEGIN_BRTAB:
  2767.     case R_END_BRTAB:
  2768.     case R_BEGIN_TRY:
  2769.     case R_N0SEL:
  2770.     case R_N1SEL:
  2771.       /* There is no symbol or addend associated with these fixups.  */
  2772.       relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
  2773.       relocs[i]->addend = 0;
  2774.       break;
  2775.  
  2776.     case R_END_TRY:
  2777.     case R_ENTRY:
  2778.     case R_EXIT:
  2779.       /* There is no symbol associated with these fixups.  */
  2780.       relocs[i]->sym_ptr_ptr = &dummy_symbol->bsym;
  2781.       relocs[i]->addend = fixp->fx_offset;
  2782.       break;
  2783.  
  2784.     default:
  2785.       relocs[i]->addend = fixp->fx_offset;
  2786.     }
  2787.     }
  2788.  
  2789.  done:
  2790. #endif
  2791.  
  2792.   return relocs;
  2793. }
  2794.  
  2795. /* Process any machine dependent frag types.  */
  2796.  
  2797. void
  2798. md_convert_frag (abfd, sec, fragP)
  2799.      register bfd *abfd;
  2800.      register asection *sec;
  2801.      register fragS *fragP;
  2802. {
  2803.   unsigned int address;
  2804.  
  2805.   if (fragP->fr_type == rs_machine_dependent)
  2806.     {
  2807.       switch ((int) fragP->fr_subtype)
  2808.     {
  2809.     case 0:
  2810.       fragP->fr_type = rs_fill;
  2811.       know (fragP->fr_var == 1);
  2812.       know (fragP->fr_next);
  2813.       address = fragP->fr_address + fragP->fr_fix;
  2814.       if (address % fragP->fr_offset)
  2815.         {
  2816.           fragP->fr_offset =
  2817.         fragP->fr_next->fr_address
  2818.         - fragP->fr_address
  2819.         - fragP->fr_fix;
  2820.         }
  2821.       else
  2822.         fragP->fr_offset = 0;
  2823.       break;
  2824.     }
  2825.     }
  2826. }
  2827.  
  2828. /* Round up a section size to the appropriate boundary. */
  2829.  
  2830. valueT
  2831. md_section_align (segment, size)
  2832.      asection *segment;
  2833.      valueT size;
  2834. {
  2835.   int align = bfd_get_section_alignment (stdoutput, segment);
  2836.   int align2 = (1 << align) - 1;
  2837.  
  2838.   return (size + align2) & ~align2;
  2839. }
  2840.  
  2841. /* Create a short jump from FROM_ADDR to TO_ADDR.  Not used on the PA.  */
  2842. void
  2843. md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
  2844.      char *ptr;
  2845.      addressT from_addr, to_addr;
  2846.      fragS *frag;
  2847.      symbolS *to_symbol;
  2848. {
  2849.   fprintf (stderr, "pa_create_short_jmp\n");
  2850.   abort ();
  2851. }
  2852.  
  2853. /* Create a long jump from FROM_ADDR to TO_ADDR.  Not used on the PA.  */
  2854. void
  2855. md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
  2856.      char *ptr;
  2857.      addressT from_addr, to_addr;
  2858.      fragS *frag;
  2859.      symbolS *to_symbol;
  2860. {
  2861.   fprintf (stderr, "pa_create_long_jump\n");
  2862.   abort ();
  2863. }
  2864.  
  2865. /* Return the approximate size of a frag before relaxation has occurred.  */
  2866. int
  2867. md_estimate_size_before_relax (fragP, segment)
  2868.      register fragS *fragP;
  2869.      asection *segment;
  2870. {
  2871.   int size;
  2872.  
  2873.   size = 0;
  2874.  
  2875.   while ((fragP->fr_fix + size) % fragP->fr_offset)
  2876.     size++;
  2877.  
  2878.   return size;
  2879. }
  2880.  
  2881. CONST char *md_shortopts = "";
  2882. struct option md_longopts[] = {
  2883.   {NULL, no_argument, NULL, 0}
  2884. };
  2885. size_t md_longopts_size = sizeof(md_longopts);
  2886.  
  2887. int
  2888. md_parse_option (c, arg)
  2889.      int c;
  2890.      char *arg;
  2891. {
  2892.   return 0;
  2893. }
  2894.  
  2895. void
  2896. md_show_usage (stream)
  2897.      FILE *stream;
  2898. {
  2899. }
  2900.  
  2901. /* We have no need to default values of symbols.  */
  2902.  
  2903. symbolS *
  2904. md_undefined_symbol (name)
  2905.      char *name;
  2906. {
  2907.   return 0;
  2908. }
  2909.  
  2910. /* Apply a fixup to an instruction.  */
  2911.  
  2912. int
  2913. md_apply_fix (fixP, valp)
  2914.      fixS *fixP;
  2915.      valueT *valp;
  2916. {
  2917.   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
  2918.   struct hppa_fix_struct *hppa_fixP;
  2919.   long new_val, result;
  2920.   unsigned int w1, w2, w, resulti;
  2921.  
  2922.   hppa_fixP = (struct hppa_fix_struct *) fixP->tc_fix_data;
  2923.   /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
  2924.      never be "applied" (they are just markers).  Likewise for
  2925.      R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB.  */
  2926. #ifdef OBJ_SOM
  2927.   if (fixP->fx_r_type == R_HPPA_ENTRY
  2928.       || fixP->fx_r_type == R_HPPA_EXIT
  2929.       || fixP->fx_r_type == R_HPPA_BEGIN_BRTAB
  2930.       || fixP->fx_r_type == R_HPPA_END_BRTAB
  2931.       || fixP->fx_r_type == R_HPPA_BEGIN_TRY)
  2932.     return 1;
  2933.  
  2934.   /* Disgusting.  We must set fx_offset ourselves -- R_HPPA_END_TRY
  2935.      fixups are considered not adjustable, which in turn causes
  2936.      adjust_reloc_syms to not set fx_offset.  Ugh.  */
  2937.   if (fixP->fx_r_type == R_HPPA_END_TRY)
  2938.     {
  2939.       fixP->fx_offset = *valp;
  2940.       return 1;
  2941.     }
  2942. #endif
  2943.  
  2944.   /* There should have been an HPPA specific fixup associated
  2945.      with the GAS fixup.  */
  2946.   if (hppa_fixP)
  2947.     {
  2948.       unsigned long buf_wd = bfd_get_32 (stdoutput, buf);
  2949.       unsigned char fmt = bfd_hppa_insn2fmt (buf_wd);
  2950.  
  2951.       /* If there is a symbol associated with this fixup, then it's something
  2952.      which will need a SOM relocation (except for some PC-relative relocs).
  2953.      In such cases we should treat the "val" or "addend" as zero since it
  2954.      will be added in as needed from fx_offset in tc_gen_reloc.  */
  2955.       if ((fixP->fx_addsy != NULL
  2956.        || fixP->fx_r_type == R_HPPA_NONE)
  2957. #ifdef OBJ_SOM
  2958.       && fmt != 32
  2959.       || hppa_fixP->fx_r_field == e_psel
  2960.       || hppa_fixP->fx_r_field == e_rpsel
  2961.       || hppa_fixP->fx_r_field == e_lpsel
  2962.       || hppa_fixP->fx_r_field == e_tsel
  2963.       || hppa_fixP->fx_r_field == e_rtsel
  2964.       || hppa_fixP->fx_r_field == e_ltsel
  2965. #endif
  2966.       )
  2967.     new_val = ((fmt == 12 || fmt == 17) ? 8 : 0);
  2968. #ifdef OBJ_SOM
  2969.       /* This is truely disgusting.  The machine independent code blindly
  2970.      adds in the value of the symbol being relocated against.  Damn!  */
  2971.       else if (fmt == 32
  2972.            && fixP->fx_addsy != NULL
  2973.            && S_GET_SEGMENT (fixP->fx_addsy) != bfd_com_section_ptr)
  2974.     new_val = hppa_field_adjust (*valp - S_GET_VALUE (fixP->fx_addsy),
  2975.                      0, hppa_fixP->fx_r_field);
  2976. #endif
  2977.       else
  2978.     new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
  2979.  
  2980.       /* Handle pc-relative exceptions from above.  */
  2981. #define arg_reloc_stub_needed(CALLER, CALLEE) \
  2982.   ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
  2983.       if ((fmt == 12 || fmt == 17)
  2984.       && fixP->fx_addsy
  2985.       && fixP->fx_pcrel
  2986.       && !arg_reloc_stub_needed (((obj_symbol_type *)
  2987.                 fixP->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
  2988.                     hppa_fixP->fx_arg_reloc)
  2989.       && ((int)(*valp) > -262144 && (int)(*valp) < 262143)
  2990.       && S_GET_SEGMENT (fixP->fx_addsy) == hppa_fixP->segment
  2991.       && !(fixP->fx_subsy
  2992.            && S_GET_SEGMENT (fixP->fx_subsy) != hppa_fixP->segment))
  2993.           
  2994.     new_val = hppa_field_adjust (*valp, 0, hppa_fixP->fx_r_field);
  2995. #undef arg_reloc_stub_needed
  2996.     
  2997.       switch (fmt)
  2998.     {
  2999.     /* Handle all opcodes with the 'j' operand type.  */
  3000.     case 14:
  3001.       CHECK_FIELD (new_val, 8191, -8192, 0);
  3002.  
  3003.       /* Mask off 14 bits to be changed.  */
  3004.       bfd_put_32 (stdoutput,
  3005.               bfd_get_32 (stdoutput, buf) & 0xffffc000,
  3006.               buf);
  3007.       low_sign_unext (new_val, 14, &resulti);
  3008.       result = resulti;
  3009.       break;
  3010.  
  3011.     /* Handle all opcodes with the 'k' operand type.  */
  3012.     case 21:
  3013.       CHECK_FIELD (new_val, 2097152, 0, 0);
  3014.  
  3015.       /* Mask off 21 bits to be changed.  */
  3016.       bfd_put_32 (stdoutput,
  3017.               bfd_get_32 (stdoutput, buf) & 0xffe00000,
  3018.               buf);
  3019.       dis_assemble_21 (new_val, &resulti);
  3020.       result = resulti;
  3021.       break;
  3022.  
  3023.     /* Handle all the opcodes with the 'i' operand type.  */
  3024.     case 11:
  3025.       CHECK_FIELD (new_val, 1023, -1023, 0);
  3026.  
  3027.       /* Mask off 11 bits to be changed.  */
  3028.       bfd_put_32 (stdoutput,
  3029.               bfd_get_32 (stdoutput, buf) & 0xffff800,
  3030.               buf);
  3031.       low_sign_unext (new_val, 11, &resulti);
  3032.       result = resulti;
  3033.       break;
  3034.  
  3035.     /* Handle all the opcodes with the 'w' operand type.  */
  3036.     case 12:
  3037.       CHECK_FIELD (new_val, 8199, -8184, 0);
  3038.  
  3039.       /* Mask off 11 bits to be changed.  */
  3040.       sign_unext ((new_val - 8) >> 2, 12, &resulti);
  3041.       bfd_put_32 (stdoutput,
  3042.               bfd_get_32 (stdoutput, buf) & 0xffffe002,
  3043.               buf);
  3044.  
  3045.       dis_assemble_12 (resulti, &w1, &w);
  3046.       result = ((w1 << 2) | w);
  3047.       break;
  3048.  
  3049.     /* Handle some of the opcodes with the 'W' operand type.  */
  3050.     case 17:
  3051.       CHECK_FIELD (new_val, 262143, -262144, 0);
  3052.  
  3053.       /* Mask off 17 bits to be changed.  */
  3054.       bfd_put_32 (stdoutput,
  3055.               bfd_get_32 (stdoutput, buf) & 0xffe0e002,
  3056.               buf);
  3057.       sign_unext ((new_val - 8) >> 2, 17, &resulti);
  3058.       dis_assemble_17 (resulti, &w1, &w2, &w);
  3059.       result = ((w2 << 2) | (w1 << 16) | w);
  3060.       break;
  3061.  
  3062.     case 32:
  3063.       result = 0;
  3064.       bfd_put_32 (stdoutput, new_val, buf);
  3065.       break;
  3066.  
  3067.     default:
  3068.       as_bad ("Unknown relocation encountered in md_apply_fix.");
  3069.       return 0;
  3070.     }
  3071.  
  3072.       /* Insert the relocation.  */
  3073.       bfd_put_32 (stdoutput, bfd_get_32 (stdoutput, buf) | result, buf);
  3074.       return 1;
  3075.     }
  3076.   else
  3077.     {
  3078.       printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
  3079.           (unsigned int) fixP, fixP->fx_r_type);
  3080.       return 0;
  3081.     }
  3082. }
  3083.  
  3084. /* Exactly what point is a PC-relative offset relative TO?
  3085.    On the PA, they're relative to the address of the offset.  */
  3086.  
  3087. long
  3088. md_pcrel_from (fixP)
  3089.      fixS *fixP;
  3090. {
  3091.   return fixP->fx_where + fixP->fx_frag->fr_address;
  3092. }
  3093.  
  3094. /* Return nonzero if the input line pointer is at the end of
  3095.    a statement.  */
  3096.  
  3097. static int
  3098. is_end_of_statement ()
  3099. {
  3100.   return ((*input_line_pointer == '\n')
  3101.       || (*input_line_pointer == ';')
  3102.       || (*input_line_pointer == '!'));
  3103. }
  3104.  
  3105. /* Read a number from S.  The number might come in one of many forms,
  3106.    the most common will be a hex or decimal constant, but it could be
  3107.    a pre-defined register (Yuk!), or an absolute symbol.
  3108.  
  3109.    Return a number or -1 for failure.
  3110.  
  3111.    When parsing PA-89 FP register numbers RESULT will be
  3112.    the address of a structure to return information about
  3113.    L/R half of FP registers, store results there as appropriate.
  3114.  
  3115.    pa_parse_number can not handle negative constants and will fail
  3116.    horribly if it is passed such a constant.  */
  3117.  
  3118. static int
  3119. pa_parse_number (s, result)
  3120.      char **s;
  3121.      struct pa_11_fp_reg_struct *result;
  3122. {
  3123.   int num;
  3124.   char *name;
  3125.   char c;
  3126.   symbolS *sym;
  3127.   int status;
  3128.   char *p = *s;
  3129.  
  3130.   /* Skip whitespace before the number.  */
  3131.   while (*p == ' ' || *p == '\t')
  3132.     p = p + 1;
  3133.  
  3134.   /* Store info in RESULT if requested by caller.  */
  3135.   if (result)
  3136.     {
  3137.       result->number_part = -1;
  3138.       result->l_r_select = -1;
  3139.     }
  3140.   num = -1;
  3141.  
  3142.   if (isdigit (*p))
  3143.     {
  3144.       /* Looks like a number.  */
  3145.       num = 0;
  3146.  
  3147.       if (*p == '0' && (*(p + 1) == 'x' || *(p + 1) == 'X'))
  3148.     {
  3149.       /* The number is specified in hex.  */
  3150.       p += 2;
  3151.       while (isdigit (*p) || ((*p >= 'a') && (*p <= 'f'))
  3152.          || ((*p >= 'A') && (*p <= 'F')))
  3153.         {
  3154.           if (isdigit (*p))
  3155.         num = num * 16 + *p - '0';
  3156.           else if (*p >= 'a' && *p <= 'f')
  3157.         num = num * 16 + *p - 'a' + 10;
  3158.           else
  3159.         num = num * 16 + *p - 'A' + 10;
  3160.           ++p;
  3161.         }
  3162.     }
  3163.       else
  3164.     {
  3165.       /* The number is specified in decimal.  */
  3166.       while (isdigit (*p))
  3167.         {
  3168.           num = num * 10 + *p - '0';
  3169.           ++p;
  3170.         }
  3171.     }
  3172.  
  3173.       /* Store info in RESULT if requested by the caller.  */
  3174.       if (result)
  3175.     {
  3176.       result->number_part = num;
  3177.  
  3178.       if (IS_R_SELECT (p))
  3179.         {
  3180.           result->l_r_select = 1;
  3181.           ++p;
  3182.         }
  3183.       else if (IS_L_SELECT (p))
  3184.         {
  3185.           result->l_r_select = 0;
  3186.           ++p;
  3187.         }
  3188.       else
  3189.         result->l_r_select = 0;
  3190.     }
  3191.     }
  3192.   else if (*p == '%')
  3193.     {
  3194.       /* The number might be a predefined register.  */
  3195.       num = 0;
  3196.       name = p;
  3197.       p++;
  3198.       c = *p;
  3199.       /* Tege hack: Special case for general registers as the general
  3200.          code makes a binary search with case translation, and is VERY
  3201.          slow. */
  3202.       if (c == 'r')
  3203.     {
  3204.       p++;
  3205.       if (*p == 'e' && *(p + 1) == 't'
  3206.           && (*(p + 2) == '0' || *(p + 2) == '1'))
  3207.         {
  3208.           p += 2;
  3209.           num = *p - '0' + 28;
  3210.           p++;
  3211.         }
  3212.       else if (*p == 'p')
  3213.         {
  3214.           num = 2;
  3215.           p++;
  3216.         }
  3217.       else if (!isdigit (*p))
  3218.         {
  3219.           if (print_errors)
  3220.         as_bad ("Undefined register: '%s'.", name);
  3221.           num = -1;
  3222.         }
  3223.       else
  3224.         {
  3225.           do
  3226.         num = num * 10 + *p++ - '0';
  3227.           while (isdigit (*p));
  3228.         }
  3229.     }
  3230.       else
  3231.     {
  3232.       /* Do a normal register search.  */
  3233.       while (is_part_of_name (c))
  3234.         {
  3235.           p = p + 1;
  3236.           c = *p;
  3237.         }
  3238.       *p = 0;
  3239.       status = reg_name_search (name);
  3240.       if (status >= 0)
  3241.         num = status;
  3242.       else
  3243.         {
  3244.           if (print_errors)
  3245.         as_bad ("Undefined register: '%s'.", name);
  3246.           num = -1;
  3247.         }
  3248.       *p = c;
  3249.     }
  3250.  
  3251.       /* Store info in RESULT if requested by caller.  */
  3252.       if (result)
  3253.     {
  3254.       result->number_part = num;
  3255.       if (IS_R_SELECT (p - 1))
  3256.         result->l_r_select = 1;
  3257.       else if (IS_L_SELECT (p - 1))
  3258.         result->l_r_select = 0;
  3259.       else
  3260.         result->l_r_select = 0;
  3261.     }
  3262.     }
  3263.   else
  3264.     {
  3265.       /* And finally, it could be a symbol in the absolute section which
  3266.          is effectively a constant.  */
  3267.       num = 0;
  3268.       name = p;
  3269.       c = *p;
  3270.       while (is_part_of_name (c))
  3271.     {
  3272.       p = p + 1;
  3273.       c = *p;
  3274.     }
  3275.       *p = 0;
  3276.       if ((sym = symbol_find (name)) != NULL)
  3277.     {
  3278.       if (S_GET_SEGMENT (sym) == &bfd_abs_section)
  3279.         num = S_GET_VALUE (sym);
  3280.       else
  3281.         {
  3282.           if (print_errors)
  3283.         as_bad ("Non-absolute symbol: '%s'.", name);
  3284.           num = -1;
  3285.         }
  3286.     }
  3287.       else
  3288.     {
  3289.       /* There is where we'd come for an undefined symbol
  3290.          or for an empty string.  For an empty string we
  3291.          will return zero.  That's a concession made for
  3292.          compatability with the braindamaged HP assemblers.  */
  3293.       if (*name == 0)
  3294.         num = 0;
  3295.       else
  3296.         {
  3297.           if (print_errors)
  3298.         as_bad ("Undefined absolute constant: '%s'.", name);
  3299.           num = -1;
  3300.         }
  3301.     }
  3302.       *p = c;
  3303.  
  3304.       /* Store info in RESULT if requested by caller.  */
  3305.       if (result)
  3306.     {
  3307.       result->number_part = num;
  3308.       if (IS_R_SELECT (p - 1))
  3309.         result->l_r_select = 1;
  3310.       else if (IS_L_SELECT (p - 1))
  3311.         result->l_r_select = 0;
  3312.       else
  3313.         result->l_r_select = 0;
  3314.     }
  3315.     }
  3316.  
  3317.   *s = p;
  3318.   return num;
  3319. }
  3320.  
  3321. #define REG_NAME_CNT    (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
  3322.  
  3323. /* Given NAME, find the register number associated with that name, return
  3324.    the integer value associated with the given name or -1 on failure.  */
  3325.  
  3326. static int
  3327. reg_name_search (name)
  3328.      char *name;
  3329. {
  3330.   int middle, low, high;
  3331.   int cmp;
  3332.  
  3333.   low = 0;
  3334.   high = REG_NAME_CNT - 1;
  3335.  
  3336.   do
  3337.     {
  3338.       middle = (low + high) / 2;
  3339.       cmp = strcasecmp (name, pre_defined_registers[middle].name);
  3340.       if (cmp < 0)
  3341.     high = middle - 1;
  3342.       else if (cmp > 0)
  3343.     low = middle + 1;
  3344.       else
  3345.     return pre_defined_registers[middle].value;
  3346.     }
  3347.   while (low <= high);
  3348.  
  3349.   return -1;
  3350. }
  3351.  
  3352.  
  3353. /* Return nonzero if the given INSN and L/R information will require
  3354.    a new PA-1.1 opcode.  */
  3355.  
  3356. static int
  3357. need_pa11_opcode (insn, result)
  3358.      struct pa_it *insn;
  3359.      struct pa_11_fp_reg_struct *result;
  3360. {
  3361.   if (result->l_r_select == 1 && !(insn->fpof1 == DBL && insn->fpof2 == DBL))
  3362.     {
  3363.       /* If this instruction is specific to a particular architecture,
  3364.      then set a new architecture.  */
  3365.       if (bfd_get_mach (stdoutput) < pa11)
  3366.     {
  3367.       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, pa11))
  3368.         as_warn ("could not update architecture and machine");
  3369.     }
  3370.       return TRUE;
  3371.     }
  3372.   else
  3373.     return FALSE;
  3374. }
  3375.  
  3376. /* Parse a condition for a fcmp instruction.  Return the numerical
  3377.    code associated with the condition.  */
  3378.  
  3379. static int
  3380. pa_parse_fp_cmp_cond (s)
  3381.      char **s;
  3382. {
  3383.   int cond, i;
  3384.  
  3385.   cond = 0;
  3386.  
  3387.   for (i = 0; i < 32; i++)
  3388.     {
  3389.       if (strncasecmp (*s, fp_cond_map[i].string,
  3390.                strlen (fp_cond_map[i].string)) == 0)
  3391.     {
  3392.       cond = fp_cond_map[i].cond;
  3393.       *s += strlen (fp_cond_map[i].string);
  3394.       /* If not a complete match, back up the input string and
  3395.          report an error.  */
  3396.       if (**s != ' ' && **s != '\t')
  3397.         {
  3398.           *s -= strlen (fp_cond_map[i].string);
  3399.           break;
  3400.         }
  3401.       while (**s == ' ' || **s == '\t')
  3402.         *s = *s + 1;
  3403.       return cond;
  3404.     }
  3405.     }
  3406.  
  3407.   as_bad ("Invalid FP Compare Condition: %s", *s);
  3408.  
  3409.   /* Advance over the bogus completer.  */
  3410.   while (**s != ',' && **s != ' ' && **s != '\t')
  3411.     *s += 1;
  3412.  
  3413.   return 0;
  3414. }
  3415.  
  3416. /* Parse an FP operand format completer returning the completer
  3417.    type.  */
  3418.  
  3419. static fp_operand_format
  3420. pa_parse_fp_format (s)
  3421.      char **s;
  3422. {
  3423.   int format;
  3424.  
  3425.   format = SGL;
  3426.   if (**s == ',')
  3427.     {
  3428.       *s += 1;
  3429.       if (strncasecmp (*s, "sgl", 3) == 0)
  3430.     {
  3431.       format = SGL;
  3432.       *s += 4;
  3433.     }
  3434.       else if (strncasecmp (*s, "dbl", 3) == 0)
  3435.     {
  3436.       format = DBL;
  3437.       *s += 4;
  3438.     }
  3439.       else if (strncasecmp (*s, "quad", 4) == 0)
  3440.     {
  3441.       format = QUAD;
  3442.       *s += 5;
  3443.     }
  3444.       else
  3445.     {
  3446.       format = ILLEGAL_FMT;
  3447.       as_bad ("Invalid FP Operand Format: %3s", *s);
  3448.     }
  3449.     }
  3450.  
  3451.   return format;
  3452. }
  3453.  
  3454. /* Convert from a selector string into a selector type.  */
  3455.  
  3456. static int
  3457. pa_chk_field_selector (str)
  3458.      char **str;
  3459. {
  3460.   int middle, low, high;
  3461.   int cmp;
  3462.   char name[4];
  3463.  
  3464.   /* Read past any whitespace.  */
  3465.   /* FIXME: should we read past newlines and formfeeds??? */
  3466.   while (**str == ' ' || **str == '\t' || **str == '\n' || **str == '\f')
  3467.     *str = *str + 1;
  3468.  
  3469.   if ((*str)[1] == '\'' || (*str)[1] == '%')
  3470.     name[0] = tolower ((*str)[0]),
  3471.     name[1] = 0;
  3472.   else if ((*str)[2] == '\'' || (*str)[2] == '%')
  3473.     name[0] = tolower ((*str)[0]),
  3474.     name[1] = tolower ((*str)[1]),
  3475.     name[2] = 0;
  3476. #ifdef OBJ_SOM
  3477.   else if ((*str)[3] == '\'' || (*str)[3] == '%')
  3478.     name[0] = tolower ((*str)[0]),
  3479.     name[1] = tolower ((*str)[1]),
  3480.     name[2] = tolower ((*str)[2]),
  3481.     name[3] = 0;
  3482. #endif
  3483.   else
  3484.     return e_fsel;
  3485.  
  3486.   low = 0;
  3487.   high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
  3488.  
  3489.   do
  3490.     {
  3491.       middle = (low + high) / 2;
  3492.       cmp = strcmp (name, selector_table[middle].prefix);
  3493.       if (cmp < 0)
  3494.     high = middle - 1;
  3495.       else if (cmp > 0)
  3496.     low = middle + 1;
  3497.       else
  3498.     {
  3499.       *str += strlen (name) + 1;
  3500. #ifndef OBJ_SOM
  3501.       if (selector_table[middle].field_selector == e_nsel)
  3502.         return e_fsel;
  3503. #endif
  3504.       return selector_table[middle].field_selector;
  3505.     }
  3506.     }
  3507.   while (low <= high);
  3508.  
  3509.   return e_fsel;
  3510. }
  3511.  
  3512. /* Mark (via expr_end) the end of an expression (I think).  FIXME.  */
  3513.  
  3514. static int
  3515. get_expression (str)
  3516.      char *str;
  3517. {
  3518.   char *save_in;
  3519.   asection *seg;
  3520.  
  3521.   save_in = input_line_pointer;
  3522.   input_line_pointer = str;
  3523.   seg = expression (&the_insn.exp);
  3524.   if (!(seg == absolute_section
  3525.     || seg == undefined_section
  3526.     || SEG_NORMAL (seg)))
  3527.     {
  3528.       as_warn ("Bad segment in expression.");
  3529.       expr_end = input_line_pointer;
  3530.       input_line_pointer = save_in;
  3531.       return 1;
  3532.     }
  3533.   expr_end = input_line_pointer;
  3534.   input_line_pointer = save_in;
  3535.   return 0;
  3536. }
  3537.  
  3538. /* Mark (via expr_end) the end of an absolute expression.  FIXME. */
  3539. static int
  3540. pa_get_absolute_expression (insn, strp)
  3541.      struct pa_it *insn;
  3542.      char **strp;
  3543. {
  3544.   char *save_in;
  3545.  
  3546.   insn->field_selector = pa_chk_field_selector (strp);
  3547.   save_in = input_line_pointer;
  3548.   input_line_pointer = *strp;
  3549.   expression (&insn->exp);
  3550.   if (insn->exp.X_op != O_constant)
  3551.     {
  3552.       as_bad ("Bad segment (should be absolute).");
  3553.       expr_end = input_line_pointer;
  3554.       input_line_pointer = save_in;
  3555.       return 0;
  3556.     }
  3557.   expr_end = input_line_pointer;
  3558.   input_line_pointer = save_in;
  3559.   return evaluate_absolute (insn);
  3560. }
  3561.  
  3562. /* Evaluate an absolute expression EXP which may be modified by
  3563.    the selector FIELD_SELECTOR.  Return the value of the expression.  */
  3564. static int
  3565. evaluate_absolute (insn)
  3566.      struct pa_it *insn;
  3567. {
  3568.   int value;
  3569.   expressionS exp;
  3570.   int field_selector = insn->field_selector;
  3571.  
  3572.   exp = insn->exp;
  3573.   value = exp.X_add_number;
  3574.  
  3575.   switch (field_selector)
  3576.     {
  3577.     /* No change.  */
  3578.     case e_fsel:
  3579.       break;
  3580.  
  3581.     /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits.  */
  3582.     case e_lssel:
  3583.       if (value & 0x00000400)
  3584.     value += 0x800;
  3585.       value = (value & 0xfffff800) >> 11;
  3586.       break;
  3587.  
  3588.     /* Sign extend from bit 21.  */
  3589.     case e_rssel:
  3590.       if (value & 0x00000400)
  3591.     value |= 0xfffff800;
  3592.       else
  3593.     value &= 0x7ff;
  3594.       break;
  3595.  
  3596.     /* Arithmetic shift right 11 bits.  */
  3597.     case e_lsel:
  3598.       value = (value & 0xfffff800) >> 11;
  3599.       break;
  3600.  
  3601.     /* Set bits 0-20 to zero.  */
  3602.     case e_rsel:
  3603.       value = value & 0x7ff;
  3604.       break;
  3605.  
  3606.     /* Add 0x800 and arithmetic shift right 11 bits.  */
  3607.     case e_ldsel:
  3608.       value += 0x800;
  3609.       value = (value & 0xfffff800) >> 11;
  3610.       break;
  3611.  
  3612.     /* Set bitgs 0-21 to one.  */
  3613.     case e_rdsel:
  3614.       value |= 0xfffff800;
  3615.       break;
  3616.  
  3617. #define RSEL_ROUND(c)  (((c) + 0x1000) & ~0x1fff)
  3618.     case e_rrsel:
  3619.       value = (RSEL_ROUND (value) & 0x7ff) + (value - RSEL_ROUND (value));
  3620.       break;
  3621.  
  3622.     case e_lrsel:
  3623.       value = (RSEL_ROUND (value) >> 11) & 0x1fffff;
  3624.       break;
  3625. #undef RSEL_ROUND
  3626.  
  3627.     default:
  3628.       BAD_CASE (field_selector);
  3629.       break;
  3630.     }
  3631.   return value;
  3632. }
  3633.  
  3634. /* Given an argument location specification return the associated
  3635.    argument location number.  */
  3636.  
  3637. static unsigned int
  3638. pa_build_arg_reloc (type_name)
  3639.      char *type_name;
  3640. {
  3641.  
  3642.   if (strncasecmp (type_name, "no", 2) == 0)
  3643.     return 0;
  3644.   if (strncasecmp (type_name, "gr", 2) == 0)
  3645.     return 1;
  3646.   else if (strncasecmp (type_name, "fr", 2) == 0)
  3647.     return 2;
  3648.   else if (strncasecmp (type_name, "fu", 2) == 0)
  3649.     return 3;
  3650.   else
  3651.     as_bad ("Invalid argument location: %s\n", type_name);
  3652.  
  3653.   return 0;
  3654. }
  3655.  
  3656. /* Encode and return an argument relocation specification for
  3657.    the given register in the location specified by arg_reloc.  */
  3658.  
  3659. static unsigned int
  3660. pa_align_arg_reloc (reg, arg_reloc)
  3661.      unsigned int reg;
  3662.      unsigned int arg_reloc;
  3663. {
  3664.   unsigned int new_reloc;
  3665.  
  3666.   new_reloc = arg_reloc;
  3667.   switch (reg)
  3668.     {
  3669.     case 0:
  3670.       new_reloc <<= 8;
  3671.       break;
  3672.     case 1:
  3673.       new_reloc <<= 6;
  3674.       break;
  3675.     case 2:
  3676.       new_reloc <<= 4;
  3677.       break;
  3678.     case 3:
  3679.       new_reloc <<= 2;
  3680.       break;
  3681.     default:
  3682.       as_bad ("Invalid argument description: %d", reg);
  3683.     }
  3684.  
  3685.   return new_reloc;
  3686. }
  3687.  
  3688. /* Parse a PA nullification completer (,n).  Return nonzero if the
  3689.    completer was found; return zero if no completer was found.  */
  3690.  
  3691. static int
  3692. pa_parse_nullif (s)
  3693.      char **s;
  3694. {
  3695.   int nullif;
  3696.  
  3697.   nullif = 0;
  3698.   if (**s == ',')
  3699.     {
  3700.       *s = *s + 1;
  3701.       if (strncasecmp (*s, "n", 1) == 0)
  3702.     nullif = 1;
  3703.       else
  3704.     {
  3705.       as_bad ("Invalid Nullification: (%c)", **s);
  3706.       nullif = 0;
  3707.     }
  3708.       *s = *s + 1;
  3709.     }
  3710.  
  3711.   return nullif;
  3712. }
  3713.  
  3714. /* Parse a non-negated compare/subtract completer returning the
  3715.    number (for encoding in instrutions) of the given completer.
  3716.  
  3717.    ISBRANCH specifies whether or not this is parsing a condition
  3718.    completer for a branch (vs a nullification completer for a
  3719.    computational instruction.  */
  3720.  
  3721. static int
  3722. pa_parse_nonneg_cmpsub_cmpltr (s, isbranch)
  3723.      char **s;
  3724.      int isbranch;
  3725. {
  3726.   int cmpltr;
  3727.   char *name = *s + 1;
  3728.   char c;
  3729.   char *save_s = *s;
  3730.  
  3731.   cmpltr = 0;
  3732.   if (**s == ',')
  3733.     {
  3734.       *s += 1;
  3735.       while (**s != ',' && **s != ' ' && **s != '\t')
  3736.     *s += 1;
  3737.       c = **s;
  3738.       **s = 0x00;
  3739.       if (strcmp (name, "=") == 0)
  3740.     {
  3741.       cmpltr = 1;
  3742.     }
  3743.       else if (strcmp (name, "<") == 0)
  3744.     {
  3745.       cmpltr = 2;
  3746.     }
  3747.       else if (strcmp (name, "<=") == 0)
  3748.     {
  3749.       cmpltr = 3;
  3750.     }
  3751.       else if (strcmp (name, "<<") == 0)
  3752.     {
  3753.       cmpltr = 4;
  3754.     }
  3755.       else if (strcmp (name, "<<=") == 0)
  3756.     {
  3757.       cmpltr = 5;
  3758.     }
  3759.       else if (strcasecmp (name, "sv") == 0)
  3760.     {
  3761.       cmpltr = 6;
  3762.     }
  3763.       else if (strcasecmp (name, "od") == 0)
  3764.     {
  3765.       cmpltr = 7;
  3766.     }
  3767.       /* If we have something like addb,n then there is no condition
  3768.          completer.  */
  3769.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3770.     {
  3771.       cmpltr = 0;
  3772.     }
  3773.       else
  3774.     {
  3775.       cmpltr = -1;
  3776.     }
  3777.       **s = c;
  3778.     }
  3779.  
  3780.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3781.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3782.     *s = save_s;
  3783.  
  3784.   return cmpltr;
  3785. }
  3786.  
  3787. /* Parse a negated compare/subtract completer returning the
  3788.    number (for encoding in instrutions) of the given completer.
  3789.  
  3790.    ISBRANCH specifies whether or not this is parsing a condition
  3791.    completer for a branch (vs a nullification completer for a
  3792.    computational instruction.  */
  3793.  
  3794. static int
  3795. pa_parse_neg_cmpsub_cmpltr (s, isbranch)
  3796.      char **s;
  3797.      int isbranch;
  3798. {
  3799.   int cmpltr;
  3800.   char *name = *s + 1;
  3801.   char c;
  3802.   char *save_s = *s;
  3803.  
  3804.   cmpltr = 0;
  3805.   if (**s == ',')
  3806.     {
  3807.       *s += 1;
  3808.       while (**s != ',' && **s != ' ' && **s != '\t')
  3809.     *s += 1;
  3810.       c = **s;
  3811.       **s = 0x00;
  3812.       if (strcasecmp (name, "tr") == 0)
  3813.     {
  3814.       cmpltr = 0;
  3815.     }
  3816.       else if (strcmp (name, "<>") == 0)
  3817.     {
  3818.       cmpltr = 1;
  3819.     }
  3820.       else if (strcmp (name, ">=") == 0)
  3821.     {
  3822.       cmpltr = 2;
  3823.     }
  3824.       else if (strcmp (name, ">") == 0)
  3825.     {
  3826.       cmpltr = 3;
  3827.     }
  3828.       else if (strcmp (name, ">>=") == 0)
  3829.     {
  3830.       cmpltr = 4;
  3831.     }
  3832.       else if (strcmp (name, ">>") == 0)
  3833.     {
  3834.       cmpltr = 5;
  3835.     }
  3836.       else if (strcasecmp (name, "nsv") == 0)
  3837.     {
  3838.       cmpltr = 6;
  3839.     }
  3840.       else if (strcasecmp (name, "ev") == 0)
  3841.     {
  3842.       cmpltr = 7;
  3843.     }
  3844.       /* If we have something like addb,n then there is no condition
  3845.          completer.  */
  3846.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3847.     {
  3848.       cmpltr = 0;
  3849.     }
  3850.       else
  3851.     {
  3852.       cmpltr = -1;
  3853.     }
  3854.       **s = c;
  3855.     }
  3856.  
  3857.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3858.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3859.     *s = save_s;
  3860.  
  3861.   return cmpltr;
  3862. }
  3863.  
  3864. /* Parse a non-negated addition completer returning the number
  3865.    (for encoding in instrutions) of the given completer.
  3866.  
  3867.    ISBRANCH specifies whether or not this is parsing a condition
  3868.    completer for a branch (vs a nullification completer for a
  3869.    computational instruction.  */
  3870.  
  3871. static int
  3872. pa_parse_nonneg_add_cmpltr (s, isbranch)
  3873.      char **s;
  3874.      int isbranch;
  3875. {
  3876.   int cmpltr;
  3877.   char *name = *s + 1;
  3878.   char c;
  3879.   char *save_s = *s;
  3880.  
  3881.   cmpltr = 0;
  3882.   if (**s == ',')
  3883.     {
  3884.       *s += 1;
  3885.       while (**s != ',' && **s != ' ' && **s != '\t')
  3886.     *s += 1;
  3887.       c = **s;
  3888.       **s = 0x00;
  3889.       if (strcmp (name, "=") == 0)
  3890.     {
  3891.       cmpltr = 1;
  3892.     }
  3893.       else if (strcmp (name, "<") == 0)
  3894.     {
  3895.       cmpltr = 2;
  3896.     }
  3897.       else if (strcmp (name, "<=") == 0)
  3898.     {
  3899.       cmpltr = 3;
  3900.     }
  3901.       else if (strcasecmp (name, "nuv") == 0)
  3902.     {
  3903.       cmpltr = 4;
  3904.     }
  3905.       else if (strcasecmp (name, "znv") == 0)
  3906.     {
  3907.       cmpltr = 5;
  3908.     }
  3909.       else if (strcasecmp (name, "sv") == 0)
  3910.     {
  3911.       cmpltr = 6;
  3912.     }
  3913.       else if (strcasecmp (name, "od") == 0)
  3914.     {
  3915.       cmpltr = 7;
  3916.     }
  3917.       /* If we have something like addb,n then there is no condition
  3918.          completer.  */
  3919.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3920.     {
  3921.       cmpltr = 0;
  3922.     }
  3923.       else
  3924.     {
  3925.       cmpltr = -1;
  3926.     }
  3927.       **s = c;
  3928.     }
  3929.  
  3930.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  3931.   if (cmpltr == 0 && *name == 'n' && isbranch)
  3932.     *s = save_s;
  3933.  
  3934.   return cmpltr;
  3935. }
  3936.  
  3937. /* Parse a negated addition completer returning the number
  3938.    (for encoding in instrutions) of the given completer.
  3939.  
  3940.    ISBRANCH specifies whether or not this is parsing a condition
  3941.    completer for a branch (vs a nullification completer for a
  3942.    computational instruction).  */
  3943.  
  3944. static int
  3945. pa_parse_neg_add_cmpltr (s, isbranch)
  3946.      char **s;
  3947.      int isbranch;
  3948. {
  3949.   int cmpltr;
  3950.   char *name = *s + 1;
  3951.   char c;
  3952.   char *save_s = *s;
  3953.  
  3954.   cmpltr = 0;
  3955.   if (**s == ',')
  3956.     {
  3957.       *s += 1;
  3958.       while (**s != ',' && **s != ' ' && **s != '\t')
  3959.     *s += 1;
  3960.       c = **s;
  3961.       **s = 0x00;
  3962.       if (strcasecmp (name, "tr") == 0)
  3963.     {
  3964.       cmpltr = 0;
  3965.     }
  3966.       else if (strcmp (name, "<>") == 0)
  3967.     {
  3968.       cmpltr = 1;
  3969.     }
  3970.       else if (strcmp (name, ">=") == 0)
  3971.     {
  3972.       cmpltr = 2;
  3973.     }
  3974.       else if (strcmp (name, ">") == 0)
  3975.     {
  3976.       cmpltr = 3;
  3977.     }
  3978.       else if (strcasecmp (name, "uv") == 0)
  3979.     {
  3980.       cmpltr = 4;
  3981.     }
  3982.       else if (strcasecmp (name, "vnz") == 0)
  3983.     {
  3984.       cmpltr = 5;
  3985.     }
  3986.       else if (strcasecmp (name, "nsv") == 0)
  3987.     {
  3988.       cmpltr = 6;
  3989.     }
  3990.       else if (strcasecmp (name, "ev") == 0)
  3991.     {
  3992.       cmpltr = 7;
  3993.     }
  3994.       /* If we have something like addb,n then there is no condition
  3995.          completer.  */
  3996.       else if (strcasecmp (name, "n") == 0 && isbranch)
  3997.     {
  3998.       cmpltr = 0;
  3999.     }
  4000.       else
  4001.     {
  4002.       cmpltr = -1;
  4003.     }
  4004.       **s = c;
  4005.     }
  4006.  
  4007.   /* Reset pointers if this was really a ,n for a branch instruction.  */
  4008.   if (cmpltr == 0 && *name == 'n' && isbranch)
  4009.     *s = save_s;
  4010.  
  4011.   return cmpltr;
  4012. }
  4013.  
  4014. /* Handle an alignment directive.  Special so that we can update the
  4015.    alignment of the subspace if necessary.  */
  4016. static void
  4017. pa_align (bytes)
  4018. {
  4019.   /* We must have a valid space and subspace.  */
  4020.   pa_check_current_space_and_subspace ();
  4021.  
  4022.   /* Let the generic gas code do most of the work.  */
  4023.   s_align_bytes (bytes);
  4024.  
  4025.   /* If bytes is a power of 2, then update the current subspace's
  4026.      alignment if necessary.  */
  4027.   if (log2 (bytes) != -1)
  4028.     record_alignment (current_subspace->ssd_seg, log2 (bytes));
  4029. }
  4030.  
  4031. /* Handle a .BLOCK type pseudo-op.  */
  4032.  
  4033. static void
  4034. pa_block (z)
  4035.      int z;
  4036. {
  4037.   char *p;
  4038.   long int temp_fill;
  4039.   unsigned int temp_size;
  4040.   int i;
  4041.  
  4042.   /* We must have a valid space and subspace.  */
  4043.   pa_check_current_space_and_subspace ();
  4044.  
  4045.   temp_size = get_absolute_expression ();
  4046.  
  4047.   /* Always fill with zeros, that's what the HP assembler does.  */
  4048.   temp_fill = 0;
  4049.  
  4050.   p = frag_var (rs_fill, (int) temp_size, (int) temp_size,
  4051.         (relax_substateT) 0, (symbolS *) 0, 1, NULL);
  4052.   bzero (p, temp_size);
  4053.  
  4054.   /* Convert 2 bytes at a time.  */
  4055.  
  4056.   for (i = 0; i < temp_size; i += 2)
  4057.     {
  4058.       md_number_to_chars (p + i,
  4059.               (valueT) temp_fill,
  4060.               (int) ((temp_size - i) > 2 ? 2 : (temp_size - i)));
  4061.     }
  4062.  
  4063.   pa_undefine_label ();
  4064.   demand_empty_rest_of_line ();
  4065. }
  4066.  
  4067. /* Handle a .begin_brtab and .end_brtab pseudo-op.  */
  4068.  
  4069. static void
  4070. pa_brtab (begin)
  4071.      int begin;
  4072. {
  4073.  
  4074. #ifdef OBJ_SOM
  4075.   /* The BRTAB relocations are only availble in SOM (to denote
  4076.      the beginning and end of branch tables).  */
  4077.   char *where = frag_more (0);
  4078.  
  4079.   fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4080.         NULL, (offsetT) 0, NULL,
  4081.         0, begin ? R_HPPA_BEGIN_BRTAB : R_HPPA_END_BRTAB,
  4082.         e_fsel, 0, 0, NULL);
  4083. #endif
  4084.  
  4085.   demand_empty_rest_of_line ();
  4086. }
  4087.  
  4088. /* Handle a .begin_try and .end_try pseudo-op.  */
  4089.  
  4090. static void
  4091. pa_try (begin)
  4092.      int begin;
  4093. {
  4094. #ifdef OBJ_SOM
  4095.   expressionS exp;
  4096.   char *where = frag_more (0);
  4097.  
  4098.   if (! begin)
  4099.     expression (&exp);
  4100.  
  4101.   /* The TRY relocations are only availble in SOM (to denote
  4102.      the beginning and end of exception handling regions).  */
  4103.  
  4104.   fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4105.         NULL, (offsetT) 0, begin ? NULL : &exp,
  4106.         0, begin ? R_HPPA_BEGIN_TRY : R_HPPA_END_TRY,
  4107.         e_fsel, 0, 0, NULL);
  4108. #endif
  4109.  
  4110.   demand_empty_rest_of_line ();
  4111. }
  4112.  
  4113. /* Handle a .CALL pseudo-op.  This involves storing away information
  4114.    about where arguments are to be found so the linker can detect
  4115.    (and correct) argument location mismatches between caller and callee.  */
  4116.  
  4117. static void
  4118. pa_call (unused)
  4119.      int unused;
  4120. {
  4121.   /* We must have a valid space and subspace.  */
  4122.   pa_check_current_space_and_subspace ();
  4123.  
  4124.   pa_call_args (&last_call_desc);
  4125.   demand_empty_rest_of_line ();
  4126. }
  4127.  
  4128. /* Do the dirty work of building a call descriptor which describes
  4129.    where the caller placed arguments to a function call.  */
  4130.  
  4131. static void
  4132. pa_call_args (call_desc)
  4133.      struct call_desc *call_desc;
  4134. {
  4135.   char *name, c, *p;
  4136.   unsigned int temp, arg_reloc;
  4137.  
  4138.   while (!is_end_of_statement ())
  4139.     {
  4140.       name = input_line_pointer;
  4141.       c = get_symbol_end ();
  4142.       /* Process a source argument.  */
  4143.       if ((strncasecmp (name, "argw", 4) == 0))
  4144.     {
  4145.       temp = atoi (name + 4);
  4146.       p = input_line_pointer;
  4147.       *p = c;
  4148.       input_line_pointer++;
  4149.       name = input_line_pointer;
  4150.       c = get_symbol_end ();
  4151.       arg_reloc = pa_build_arg_reloc (name);
  4152.       call_desc->arg_reloc |= pa_align_arg_reloc (temp, arg_reloc);
  4153.     }
  4154.       /* Process a return value.  */
  4155.       else if ((strncasecmp (name, "rtnval", 6) == 0))
  4156.     {
  4157.       p = input_line_pointer;
  4158.       *p = c;
  4159.       input_line_pointer++;
  4160.       name = input_line_pointer;
  4161.       c = get_symbol_end ();
  4162.       arg_reloc = pa_build_arg_reloc (name);
  4163.       call_desc->arg_reloc |= (arg_reloc & 0x3);
  4164.     }
  4165.       else
  4166.     {
  4167.       as_bad ("Invalid .CALL argument: %s", name);
  4168.     }
  4169.       p = input_line_pointer;
  4170.       *p = c;
  4171.       if (!is_end_of_statement ())
  4172.     input_line_pointer++;
  4173.     }
  4174. }
  4175.  
  4176. /* Return TRUE if FRAG1 and FRAG2 are the same.  */
  4177.  
  4178. static int
  4179. is_same_frag (frag1, frag2)
  4180.      fragS *frag1;
  4181.      fragS *frag2;
  4182. {
  4183.  
  4184.   if (frag1 == NULL)
  4185.     return (FALSE);
  4186.   else if (frag2 == NULL)
  4187.     return (FALSE);
  4188.   else if (frag1 == frag2)
  4189.     return (TRUE);
  4190.   else if (frag2->fr_type == rs_fill && frag2->fr_fix == 0)
  4191.     return (is_same_frag (frag1, frag2->fr_next));
  4192.   else
  4193.     return (FALSE);
  4194. }
  4195.  
  4196. #ifdef OBJ_ELF
  4197. /* Build an entry in the UNWIND subspace from the given function
  4198.    attributes in CALL_INFO.  This is not needed for SOM as using
  4199.    R_ENTRY and R_EXIT relocations allow the linker to handle building
  4200.    of the unwind spaces.  */
  4201.  
  4202. static void
  4203. pa_build_unwind_subspace (call_info)
  4204.      struct call_info *call_info;
  4205. {
  4206.   char *unwind;
  4207.   asection *seg, *save_seg;
  4208.   subsegT subseg, save_subseg;
  4209.   int i;
  4210.   char c, *p;
  4211.  
  4212.   /* Get into the right seg/subseg.  This may involve creating
  4213.      the seg the first time through.  Make sure to have the
  4214.      old seg/subseg so that we can reset things when we are done.  */
  4215.   subseg = SUBSEG_UNWIND;
  4216.   seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
  4217.   if (seg == ASEC_NULL)
  4218.     {
  4219.       seg = bfd_make_section_old_way (stdoutput, UNWIND_SECTION_NAME);
  4220.       bfd_set_section_flags (stdoutput, seg,
  4221.                  SEC_READONLY | SEC_HAS_CONTENTS
  4222.                  | SEC_LOAD | SEC_RELOC);
  4223.     }
  4224.  
  4225.   save_seg = now_seg;
  4226.   save_subseg = now_subseg;
  4227.   subseg_set (seg, subseg);
  4228.  
  4229.  
  4230.   /* Get some space to hold relocation information for the unwind
  4231.      descriptor.  */
  4232.   p = frag_more (4);
  4233.   md_number_to_chars (p, 0, 4);
  4234.  
  4235.   /* Relocation info. for start offset of the function.  */
  4236.   fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
  4237.         call_info->start_symbol, (offsetT) 0,
  4238.         (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
  4239.  
  4240.   p = frag_more (4);
  4241.   md_number_to_chars (p, 0, 4);
  4242.  
  4243.   /* Relocation info. for end offset of the function.
  4244.  
  4245.      Because we allow reductions of 32bit relocations for ELF, this will be
  4246.      reduced to section_sym + offset which avoids putting the temporary
  4247.      symbol into the symbol table.  It (should) end up giving the same
  4248.      value as call_info->start_symbol + function size once the linker is
  4249.      finished with its work.  */
  4250.  
  4251.   fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
  4252.         call_info->end_symbol, (offsetT) 0,
  4253.         (expressionS *) NULL, 0, R_PARISC_DIR32, e_fsel, 32, 0, NULL);
  4254.  
  4255.   /* Dump it. */
  4256.   unwind = (char *) &call_info->ci_unwind;
  4257.   for (i = 8; i < sizeof (struct unwind_table); i++)
  4258.     {
  4259.       c = *(unwind + i);
  4260.       {
  4261.     FRAG_APPEND_1_CHAR (c);
  4262.       }
  4263.     }
  4264.  
  4265.   /* Return back to the original segment/subsegment.  */
  4266.   subseg_set (save_seg, save_subseg);
  4267. }
  4268. #endif
  4269.  
  4270. /* Process a .CALLINFO pseudo-op.  This information is used later
  4271.    to build unwind descriptors and maybe one day to support
  4272.    .ENTER and .LEAVE.  */
  4273.  
  4274. static void
  4275. pa_callinfo (unused)
  4276.      int unused;
  4277. {
  4278.   char *name, c, *p;
  4279.   int temp;
  4280.  
  4281.   /* We must have a valid space and subspace.  */
  4282.   pa_check_current_space_and_subspace ();
  4283.  
  4284.   /* .CALLINFO must appear within a procedure definition.  */
  4285.   if (!within_procedure)
  4286.     as_bad (".callinfo is not within a procedure definition");
  4287.  
  4288.   /* Mark the fact that we found the .CALLINFO for the
  4289.      current procedure.  */
  4290.   callinfo_found = TRUE;
  4291.  
  4292.   /* Iterate over the .CALLINFO arguments.  */
  4293.   while (!is_end_of_statement ())
  4294.     {
  4295.       name = input_line_pointer;
  4296.       c = get_symbol_end ();
  4297.       /* Frame size specification.  */
  4298.       if ((strncasecmp (name, "frame", 5) == 0))
  4299.     {
  4300.       p = input_line_pointer;
  4301.       *p = c;
  4302.       input_line_pointer++;
  4303.       temp = get_absolute_expression ();
  4304.       if ((temp & 0x3) != 0)
  4305.         {
  4306.           as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp);
  4307.           temp = 0;
  4308.         }
  4309.  
  4310.       /* callinfo is in bytes and unwind_desc is in 8 byte units.  */
  4311.       last_call_info->ci_unwind.descriptor.frame_size = temp / 8;
  4312.  
  4313.     }
  4314.       /* Entry register (GR, GR and SR) specifications.  */
  4315.       else if ((strncasecmp (name, "entry_gr", 8) == 0))
  4316.     {
  4317.       p = input_line_pointer;
  4318.       *p = c;
  4319.       input_line_pointer++;
  4320.       temp = get_absolute_expression ();
  4321.       /* The HP assembler accepts 19 as the high bound for ENTRY_GR
  4322.          even though %r19 is caller saved.  I think this is a bug in
  4323.          the HP assembler, and we are not going to emulate it.  */
  4324.       if (temp < 3 || temp > 18)
  4325.         as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
  4326.       last_call_info->ci_unwind.descriptor.entry_gr = temp - 2;
  4327.     }
  4328.       else if ((strncasecmp (name, "entry_fr", 8) == 0))
  4329.     {
  4330.       p = input_line_pointer;
  4331.       *p = c;
  4332.       input_line_pointer++;
  4333.       temp = get_absolute_expression ();
  4334.       /* Similarly the HP assembler takes 31 as the high bound even
  4335.          though %fr21 is the last callee saved floating point register.  */
  4336.       if (temp < 12 || temp > 21)
  4337.         as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
  4338.       last_call_info->ci_unwind.descriptor.entry_fr = temp - 11;
  4339.     }
  4340.       else if ((strncasecmp (name, "entry_sr", 8) == 0))
  4341.     {
  4342.       p = input_line_pointer;
  4343.       *p = c;
  4344.       input_line_pointer++;
  4345.       temp = get_absolute_expression ();
  4346.       if (temp != 3)
  4347.         as_bad ("Value for ENTRY_SR must be 3\n");
  4348.     }
  4349.       /* Note whether or not this function performs any calls.  */
  4350.       else if ((strncasecmp (name, "calls", 5) == 0) ||
  4351.            (strncasecmp (name, "caller", 6) == 0))
  4352.     {
  4353.       p = input_line_pointer;
  4354.       *p = c;
  4355.     }
  4356.       else if ((strncasecmp (name, "no_calls", 8) == 0))
  4357.     {
  4358.       p = input_line_pointer;
  4359.       *p = c;
  4360.     }
  4361.       /* Should RP be saved into the stack.  */
  4362.       else if ((strncasecmp (name, "save_rp", 7) == 0))
  4363.     {
  4364.       p = input_line_pointer;
  4365.       *p = c;
  4366.       last_call_info->ci_unwind.descriptor.save_rp = 1;
  4367.     }
  4368.       /* Likewise for SP.  */
  4369.       else if ((strncasecmp (name, "save_sp", 7) == 0))
  4370.     {
  4371.       p = input_line_pointer;
  4372.       *p = c;
  4373.       last_call_info->ci_unwind.descriptor.save_sp = 1;
  4374.     }
  4375.       /* Is this an unwindable procedure.  If so mark it so
  4376.          in the unwind descriptor.  */
  4377.       else if ((strncasecmp (name, "no_unwind", 9) == 0))
  4378.     {
  4379.       p = input_line_pointer;
  4380.       *p = c;
  4381.       last_call_info->ci_unwind.descriptor.cannot_unwind = 1;
  4382.     }
  4383.       /* Is this an interrupt routine.  If so mark it in the
  4384.          unwind descriptor.  */
  4385.       else if ((strncasecmp (name, "hpux_int", 7) == 0))
  4386.     {
  4387.       p = input_line_pointer;
  4388.       *p = c;
  4389.       last_call_info->ci_unwind.descriptor.hpux_interrupt_marker = 1;
  4390.     }
  4391.       /* Is this a millicode routine.  "millicode" isn't in my
  4392.      assembler manual, but my copy is old.  The HP assembler
  4393.      accepts it, and there's a place in the unwind descriptor
  4394.      to drop the information, so we'll accept it too.  */
  4395.       else if ((strncasecmp (name, "millicode", 9) == 0))
  4396.     {
  4397.       p = input_line_pointer;
  4398.       *p = c;
  4399.       last_call_info->ci_unwind.descriptor.millicode = 1;
  4400.     }
  4401.       else
  4402.     {
  4403.       as_bad ("Invalid .CALLINFO argument: %s", name);
  4404.       *input_line_pointer = c;
  4405.     }
  4406.       if (!is_end_of_statement ())
  4407.     input_line_pointer++;
  4408.     }
  4409.  
  4410.   demand_empty_rest_of_line ();
  4411. }
  4412.  
  4413. /* Switch into the code subspace.  */
  4414.  
  4415. static void
  4416. pa_code (unused)
  4417.      int unused;
  4418. {
  4419.   current_space = is_defined_space ("$TEXT$");
  4420.   current_subspace
  4421.     = pa_subsegment_to_subspace (current_space->sd_seg, 0);
  4422.   s_text (0);
  4423.   pa_undefine_label ();
  4424. }
  4425.  
  4426. /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
  4427.    the .comm pseudo-op has the following symtax:
  4428.  
  4429.    <label> .comm <length>
  4430.  
  4431.    where <label> is optional and is a symbol whose address will be the start of
  4432.    a block of memory <length> bytes long. <length> must be an absolute
  4433.    expression.  <length> bytes will be allocated in the current space
  4434.    and subspace.
  4435.  
  4436.    Also note the label may not even be on the same line as the .comm.
  4437.  
  4438.    This difference in syntax means the colon function will be called
  4439.    on the symbol before we arrive in pa_comm.  colon will set a number
  4440.    of attributes of the symbol that need to be fixed here.  In particular
  4441.    the value, section pointer, fragment pointer, flags, etc.  What
  4442.    a pain.
  4443.  
  4444.    This also makes error detection all but impossible.  */
  4445.  
  4446. static void
  4447. pa_comm (unused)
  4448.      int unused;
  4449. {
  4450.   unsigned int size;
  4451.   symbolS *symbol;
  4452.   label_symbol_struct *label_symbol = pa_get_label ();
  4453.  
  4454.   if (label_symbol)
  4455.     symbol = label_symbol->lss_label;
  4456.   else
  4457.     symbol = NULL;
  4458.  
  4459.   SKIP_WHITESPACE ();
  4460.   size = get_absolute_expression ();
  4461.  
  4462.   if (symbol)
  4463.     {
  4464.       S_SET_VALUE (symbol, size);
  4465.       S_SET_SEGMENT (symbol, bfd_und_section_ptr);
  4466.       S_SET_EXTERNAL (symbol);
  4467.  
  4468.       /* colon() has already set the frag to the current location in the
  4469.          current subspace; we need to reset the fragment to the zero address
  4470.          fragment.  We also need to reset the segment pointer.  */
  4471.       symbol->sy_frag = &zero_address_frag;
  4472.     }
  4473.   demand_empty_rest_of_line ();
  4474. }
  4475.  
  4476. /* Process a .END pseudo-op.  */
  4477.  
  4478. static void
  4479. pa_end (unused)
  4480.      int unused;
  4481. {
  4482.   demand_empty_rest_of_line ();
  4483. }
  4484.  
  4485. /* Process a .ENTER pseudo-op.  This is not supported.  */
  4486. static void
  4487. pa_enter (unused)
  4488.      int unused;
  4489. {
  4490.   /* We must have a valid space and subspace.  */
  4491.   pa_check_current_space_and_subspace ();
  4492.  
  4493.   abort ();
  4494. }
  4495.  
  4496. /* Process a .ENTRY pseudo-op.  .ENTRY marks the beginning of the
  4497.    procesure.  */
  4498. static void
  4499. pa_entry (unused)
  4500.      int unused;
  4501. {
  4502.   /* We must have a valid space and subspace.  */
  4503.   pa_check_current_space_and_subspace ();
  4504.  
  4505.   if (!within_procedure)
  4506.     as_bad ("Misplaced .entry. Ignored.");
  4507.   else
  4508.     {
  4509.       if (!callinfo_found)
  4510.     as_bad ("Missing .callinfo.");
  4511.     }
  4512.   demand_empty_rest_of_line ();
  4513.   within_entry_exit = TRUE;
  4514.  
  4515. #ifdef OBJ_SOM
  4516.   /* SOM defers building of unwind descriptors until the link phase.
  4517.      The assembler is responsible for creating an R_ENTRY relocation
  4518.      to mark the beginning of a region and hold the unwind bits, and
  4519.      for creating an R_EXIT relocation to mark the end of the region.
  4520.  
  4521.      FIXME.  ELF should be using the same conventions!  The problem
  4522.      is an unwind requires too much relocation space.  Hmmm.  Maybe
  4523.      if we split the unwind bits up between the relocations which
  4524.      denote the entry and exit points.  */
  4525.   if (last_call_info->start_symbol != NULL)
  4526.     {
  4527.       char *where = frag_more (0);
  4528.  
  4529.       fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4530.             NULL, (offsetT) 0, NULL,
  4531.             0, R_HPPA_ENTRY, e_fsel, 0, 0,
  4532.             (int *) &last_call_info->ci_unwind.descriptor);
  4533.     }
  4534. #endif
  4535. }
  4536.  
  4537. /* Handle a .EQU pseudo-op.  */
  4538.  
  4539. static void
  4540. pa_equ (reg)
  4541.      int reg;
  4542. {
  4543.   label_symbol_struct *label_symbol = pa_get_label ();
  4544.   symbolS *symbol;
  4545.  
  4546.   if (label_symbol)
  4547.     {
  4548.       symbol = label_symbol->lss_label;
  4549.       if (reg)
  4550.     S_SET_VALUE (symbol, pa_parse_number (&input_line_pointer, 0));
  4551.       else
  4552.     S_SET_VALUE (symbol, (unsigned int) get_absolute_expression ());
  4553.       S_SET_SEGMENT (symbol, bfd_abs_section_ptr);
  4554.     }
  4555.   else
  4556.     {
  4557.       if (reg)
  4558.     as_bad (".REG must use a label");
  4559.       else
  4560.     as_bad (".EQU must use a label");
  4561.     }
  4562.  
  4563.   pa_undefine_label ();
  4564.   demand_empty_rest_of_line ();
  4565. }
  4566.  
  4567. /* Helper function.  Does processing for the end of a function.  This
  4568.    usually involves creating some relocations or building special
  4569.    symbols to mark the end of the function.  */
  4570.  
  4571. static void
  4572. process_exit ()
  4573. {
  4574.   char *where;
  4575.  
  4576.   where = frag_more (0);
  4577.  
  4578. #ifdef OBJ_ELF
  4579.   /* Mark the end of the function, stuff away the location of the frag
  4580.      for the end of the function, and finally call pa_build_unwind_subspace
  4581.      to add an entry in the unwind table.  */
  4582.   hppa_elf_mark_end_of_function ();
  4583.   pa_build_unwind_subspace (last_call_info);
  4584. #else
  4585.   /* SOM defers building of unwind descriptors until the link phase.
  4586.      The assembler is responsible for creating an R_ENTRY relocation
  4587.      to mark the beginning of a region and hold the unwind bits, and
  4588.      for creating an R_EXIT relocation to mark the end of the region.
  4589.  
  4590.      FIXME.  ELF should be using the same conventions!  The problem
  4591.      is an unwind requires too much relocation space.  Hmmm.  Maybe
  4592.      if we split the unwind bits up between the relocations which
  4593.      denote the entry and exit points.  */
  4594.   fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  4595.         NULL, (offsetT) 0,
  4596.         NULL, 0, R_HPPA_EXIT, e_fsel, 0, 0,
  4597.         (int *) &last_call_info->ci_unwind.descriptor + 1);
  4598. #endif
  4599. }
  4600.  
  4601. /* Process a .EXIT pseudo-op.  */
  4602.  
  4603. static void
  4604. pa_exit (unused)
  4605.      int unused;
  4606. {
  4607.   /* We must have a valid space and subspace.  */
  4608.   pa_check_current_space_and_subspace ();
  4609.  
  4610.   if (!within_procedure)
  4611.     as_bad (".EXIT must appear within a procedure");
  4612.   else
  4613.     {
  4614.       if (!callinfo_found)
  4615.     as_bad ("Missing .callinfo");
  4616.       else
  4617.     {
  4618.       if (!within_entry_exit)
  4619.         as_bad ("No .ENTRY for this .EXIT");
  4620.       else
  4621.         {
  4622.           within_entry_exit = FALSE;
  4623.           process_exit ();
  4624.         }
  4625.     }
  4626.     }
  4627.   demand_empty_rest_of_line ();
  4628. }
  4629.  
  4630. /* Process a .EXPORT directive.  This makes functions external
  4631.    and provides information such as argument relocation entries
  4632.    to callers.  */
  4633.  
  4634. static void
  4635. pa_export (unused)
  4636.      int unused;
  4637. {
  4638.   char *name, c, *p;
  4639.   symbolS *symbol;
  4640.  
  4641.   name = input_line_pointer;
  4642.   c = get_symbol_end ();
  4643.   /* Make sure the given symbol exists.  */
  4644.   if ((symbol = symbol_find_or_make (name)) == NULL)
  4645.     {
  4646.       as_bad ("Cannot define export symbol: %s\n", name);
  4647.       p = input_line_pointer;
  4648.       *p = c;
  4649.       input_line_pointer++;
  4650.     }
  4651.   else
  4652.     {
  4653.       /* OK.  Set the external bits and process argument relocations.  */
  4654.       S_SET_EXTERNAL (symbol);
  4655.       p = input_line_pointer;
  4656.       *p = c;
  4657.       if (!is_end_of_statement ())
  4658.     {
  4659.       input_line_pointer++;
  4660.       pa_type_args (symbol, 1);
  4661.     }
  4662.     }
  4663.  
  4664.   demand_empty_rest_of_line ();
  4665. }
  4666.  
  4667. /* Helper function to process arguments to a .EXPORT pseudo-op.  */
  4668.  
  4669. static void
  4670. pa_type_args (symbolP, is_export)
  4671.      symbolS *symbolP;
  4672.      int is_export;
  4673. {
  4674.   char *name, c, *p;
  4675.   unsigned int temp, arg_reloc;
  4676.   pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
  4677.   obj_symbol_type *symbol = (obj_symbol_type *) symbolP->bsym;
  4678.  
  4679.   if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
  4680.  
  4681.     {
  4682.       input_line_pointer += 8;
  4683.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4684.       S_SET_SEGMENT (symbolP, bfd_abs_section_ptr);
  4685.       type = SYMBOL_TYPE_ABSOLUTE;
  4686.     }
  4687.   else if (strncasecmp (input_line_pointer, "code", 4) == 0)
  4688.     {
  4689.       input_line_pointer += 4;
  4690.       /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
  4691.          instead one should be IMPORTing/EXPORTing ENTRY types.
  4692.  
  4693.          Complain if one tries to EXPORT a CODE type since that's never
  4694.          done.  Both GCC and HP C still try to IMPORT CODE types, so
  4695.          silently fix them to be ENTRY types.  */
  4696.       if (symbolP->bsym->flags & BSF_FUNCTION)
  4697.     {
  4698.       if (is_export)
  4699.         as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP->bsym->name);
  4700.  
  4701.       symbolP->bsym->flags |= BSF_FUNCTION;
  4702.       type = SYMBOL_TYPE_ENTRY;
  4703.     }
  4704.       else
  4705.     {
  4706.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4707.       type = SYMBOL_TYPE_CODE;
  4708.     }
  4709.     }
  4710.   else if (strncasecmp (input_line_pointer, "data", 4) == 0)
  4711.     {
  4712.       input_line_pointer += 4;
  4713.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4714.       type = SYMBOL_TYPE_DATA;
  4715.     }
  4716.   else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
  4717.     {
  4718.       input_line_pointer += 5;
  4719.       symbolP->bsym->flags |= BSF_FUNCTION;
  4720.       type = SYMBOL_TYPE_ENTRY;
  4721.     }
  4722.   else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
  4723.     {
  4724.       input_line_pointer += 9;
  4725.       symbolP->bsym->flags |= BSF_FUNCTION;
  4726.       type = SYMBOL_TYPE_MILLICODE;
  4727.     }
  4728.   else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
  4729.     {
  4730.       input_line_pointer += 6;
  4731.       symbolP->bsym->flags &= ~BSF_FUNCTION;
  4732.       type = SYMBOL_TYPE_PLABEL;
  4733.     }
  4734.   else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
  4735.     {
  4736.       input_line_pointer += 8;
  4737.       symbolP->bsym->flags |= BSF_FUNCTION;
  4738.       type = SYMBOL_TYPE_PRI_PROG;
  4739.     }
  4740.   else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
  4741.     {
  4742.       input_line_pointer += 8;
  4743.       symbolP->bsym->flags |= BSF_FUNCTION;
  4744.       type = SYMBOL_TYPE_SEC_PROG;
  4745.     }
  4746.  
  4747.   /* SOM requires much more information about symbol types
  4748.      than BFD understands.  This is how we get this information
  4749.      to the SOM BFD backend.  */
  4750. #ifdef obj_set_symbol_type
  4751.   obj_set_symbol_type (symbolP->bsym, (int) type);
  4752. #endif
  4753.  
  4754.   /* Now that the type of the exported symbol has been handled,
  4755.      handle any argument relocation information.  */
  4756.   while (!is_end_of_statement ())
  4757.     {
  4758.       if (*input_line_pointer == ',')
  4759.     input_line_pointer++;
  4760.       name = input_line_pointer;
  4761.       c = get_symbol_end ();
  4762.       /* Argument sources.  */
  4763.       if ((strncasecmp (name, "argw", 4) == 0))
  4764.     {
  4765.       p = input_line_pointer;
  4766.       *p = c;
  4767.       input_line_pointer++;
  4768.       temp = atoi (name + 4);
  4769.       name = input_line_pointer;
  4770.       c = get_symbol_end ();
  4771.       arg_reloc = pa_align_arg_reloc (temp, pa_build_arg_reloc (name));
  4772.       symbol->tc_data.hppa_arg_reloc |= arg_reloc;
  4773.       *input_line_pointer = c;
  4774.     }
  4775.       /* The return value.  */
  4776.       else if ((strncasecmp (name, "rtnval", 6)) == 0)
  4777.     {
  4778.       p = input_line_pointer;
  4779.       *p = c;
  4780.       input_line_pointer++;
  4781.       name = input_line_pointer;
  4782.       c = get_symbol_end ();
  4783.       arg_reloc = pa_build_arg_reloc (name);
  4784.       symbol->tc_data.hppa_arg_reloc |= arg_reloc;
  4785.       *input_line_pointer = c;
  4786.     }
  4787.       /* Privelege level.  */
  4788.       else if ((strncasecmp (name, "priv_lev", 8)) == 0)
  4789.     {
  4790.       p = input_line_pointer;
  4791.       *p = c;
  4792.       input_line_pointer++;
  4793.       temp = atoi (input_line_pointer);
  4794.       c = get_symbol_end ();
  4795.       *input_line_pointer = c;
  4796.     }
  4797.       else
  4798.     {
  4799.       as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name);
  4800.       p = input_line_pointer;
  4801.       *p = c;
  4802.     }
  4803.       if (!is_end_of_statement ())
  4804.     input_line_pointer++;
  4805.     }
  4806. }
  4807.  
  4808. /* Handle an .IMPORT pseudo-op.  Any symbol referenced in a given
  4809.    assembly file must either be defined in the assembly file, or
  4810.    explicitly IMPORTED from another.  */
  4811.  
  4812. static void
  4813. pa_import (unused)
  4814.      int unused;
  4815. {
  4816.   char *name, c, *p;
  4817.   symbolS *symbol;
  4818.  
  4819.   name = input_line_pointer;
  4820.   c = get_symbol_end ();
  4821.  
  4822.   symbol = symbol_find (name);
  4823.   /* Ugh.  We might be importing a symbol defined earlier in the file,
  4824.      in which case all the code below will really screw things up
  4825.      (set the wrong segment, symbol flags & type, etc).  */
  4826.   if (symbol == NULL || !S_IS_DEFINED (symbol))
  4827.     {
  4828.       symbol = symbol_find_or_make (name);
  4829.       p = input_line_pointer;
  4830.       *p = c;
  4831.  
  4832.       if (!is_end_of_statement ())
  4833.     {
  4834.       input_line_pointer++;
  4835.       pa_type_args (symbol, 0);
  4836.     }
  4837.       else
  4838.     {
  4839.       /* Sigh.  To be compatable with the HP assembler and to help
  4840.          poorly written assembly code, we assign a type based on
  4841.          the the current segment.  Note only BSF_FUNCTION really
  4842.          matters, we do not need to set the full SYMBOL_TYPE_* info.  */
  4843.       if (now_seg == text_section)
  4844.         symbol->bsym->flags |= BSF_FUNCTION;
  4845.  
  4846.       /* If the section is undefined, then the symbol is undefined
  4847.          Since this is an import, leave the section undefined.  */
  4848.       S_SET_SEGMENT (symbol, bfd_und_section_ptr);
  4849.     }
  4850.     }
  4851.   else
  4852.     {
  4853.       /* The symbol was already defined.  Just eat everything up to
  4854.      the end of the current statement.  */
  4855.       while (!is_end_of_statement ())
  4856.     input_line_pointer++;
  4857.     }
  4858.  
  4859.   demand_empty_rest_of_line ();
  4860. }
  4861.  
  4862. /* Handle a .LABEL pseudo-op.  */
  4863.  
  4864. static void
  4865. pa_label (unused)
  4866.      int unused;
  4867. {
  4868.   char *name, c, *p;
  4869.  
  4870.   name = input_line_pointer;
  4871.   c = get_symbol_end ();
  4872.  
  4873.   if (strlen (name) > 0)
  4874.     {
  4875.       colon (name);
  4876.       p = input_line_pointer;
  4877.       *p = c;
  4878.     }
  4879.   else
  4880.     {
  4881.       as_warn ("Missing label name on .LABEL");
  4882.     }
  4883.  
  4884.   if (!is_end_of_statement ())
  4885.     {
  4886.       as_warn ("extra .LABEL arguments ignored.");
  4887.       ignore_rest_of_line ();
  4888.     }
  4889.   demand_empty_rest_of_line ();
  4890. }
  4891.  
  4892. /* Handle a .LEAVE pseudo-op.  This is not supported yet.  */
  4893.  
  4894. static void
  4895. pa_leave (unused)
  4896.      int unused;
  4897. {
  4898.   /* We must have a valid space and subspace.  */
  4899.   pa_check_current_space_and_subspace ();
  4900.  
  4901.   abort ();
  4902. }
  4903.  
  4904. /* Handle a .LEVEL pseudo-op.  */
  4905.  
  4906. static void
  4907. pa_level (unused)
  4908.      int unused;
  4909. {
  4910.   char *level;
  4911.  
  4912.   level = input_line_pointer;
  4913.   if (strncmp (level, "1.0", 3) == 0)
  4914.     {
  4915.       input_line_pointer += 3;
  4916.       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 10))
  4917.     as_warn ("could not set architecture and machine");
  4918.     }
  4919.   else if (strncmp (level, "1.1", 3) == 0)
  4920.     {
  4921.       input_line_pointer += 3;
  4922.       if (!bfd_set_arch_mach (stdoutput, bfd_arch_hppa, 11))
  4923.     as_warn ("could not set architecture and machine");
  4924.     }
  4925.   else
  4926.     {
  4927.       as_bad ("Unrecognized .LEVEL argument\n");
  4928.       ignore_rest_of_line ();
  4929.     }
  4930.   demand_empty_rest_of_line ();
  4931. }
  4932.  
  4933. /* Handle a .ORIGIN pseudo-op.  */
  4934.  
  4935. static void
  4936. pa_origin (unused)
  4937.      int unused;
  4938. {
  4939.   /* We must have a valid space and subspace.  */
  4940.   pa_check_current_space_and_subspace ();
  4941.  
  4942.   s_org (0);
  4943.   pa_undefine_label ();
  4944. }
  4945.  
  4946. /* Handle a .PARAM pseudo-op.  This is much like a .EXPORT, except it
  4947.    is for static functions.  FIXME.  Should share more code with .EXPORT.  */
  4948.  
  4949. static void
  4950. pa_param (unused)
  4951.      int unused;
  4952. {
  4953.   char *name, c, *p;
  4954.   symbolS *symbol;
  4955.  
  4956.   name = input_line_pointer;
  4957.   c = get_symbol_end ();
  4958.  
  4959.   if ((symbol = symbol_find_or_make (name)) == NULL)
  4960.     {
  4961.       as_bad ("Cannot define static symbol: %s\n", name);
  4962.       p = input_line_pointer;
  4963.       *p = c;
  4964.       input_line_pointer++;
  4965.     }
  4966.   else
  4967.     {
  4968.       S_CLEAR_EXTERNAL (symbol);
  4969.       p = input_line_pointer;
  4970.       *p = c;
  4971.       if (!is_end_of_statement ())
  4972.     {
  4973.       input_line_pointer++;
  4974.       pa_type_args (symbol, 0);
  4975.     }
  4976.     }
  4977.  
  4978.   demand_empty_rest_of_line ();
  4979. }
  4980.  
  4981. /* Handle a .PROC pseudo-op.  It is used to mark the beginning
  4982.    of a procedure from a syntatical point of view.  */
  4983.  
  4984. static void
  4985. pa_proc (unused)
  4986.      int unused;
  4987. {
  4988.   struct call_info *call_info;
  4989.  
  4990.   /* We must have a valid space and subspace.  */
  4991.   pa_check_current_space_and_subspace ();
  4992.  
  4993.   if (within_procedure)
  4994.     as_fatal ("Nested procedures");
  4995.  
  4996.   /* Reset global variables for new procedure.  */
  4997.   callinfo_found = FALSE;
  4998.   within_procedure = TRUE;
  4999.  
  5000.   /* Create another call_info structure.  */
  5001.   call_info = (struct call_info *) xmalloc (sizeof (struct call_info));
  5002.  
  5003.   if (!call_info)
  5004.     as_fatal ("Cannot allocate unwind descriptor\n");
  5005.  
  5006.   bzero (call_info, sizeof (struct call_info));
  5007.  
  5008.   call_info->ci_next = NULL;
  5009.  
  5010.   if (call_info_root == NULL)
  5011.     {
  5012.       call_info_root = call_info;
  5013.       last_call_info = call_info;
  5014.     }
  5015.   else
  5016.     {
  5017.       last_call_info->ci_next = call_info;
  5018.       last_call_info = call_info;
  5019.     }
  5020.  
  5021.   /* set up defaults on call_info structure */
  5022.  
  5023.   call_info->ci_unwind.descriptor.cannot_unwind = 0;
  5024.   call_info->ci_unwind.descriptor.region_desc = 1;
  5025.   call_info->ci_unwind.descriptor.hpux_interrupt_marker = 0;
  5026.  
  5027.   /* If we got a .PROC pseudo-op, we know that the function is defined
  5028.      locally.  Make sure it gets into the symbol table.  */
  5029.   {
  5030.     label_symbol_struct *label_symbol = pa_get_label ();
  5031.  
  5032.     if (label_symbol)
  5033.       {
  5034.     if (label_symbol->lss_label)
  5035.       {
  5036.         last_call_info->start_symbol = label_symbol->lss_label;
  5037.         label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
  5038.       }
  5039.     else
  5040.       as_bad ("Missing function name for .PROC (corrupted label chain)");
  5041.       }
  5042.     else
  5043.       last_call_info->start_symbol = NULL;
  5044.   }
  5045.  
  5046.   demand_empty_rest_of_line ();
  5047. }
  5048.  
  5049. /* Process the syntatical end of a procedure.  Make sure all the
  5050.    appropriate pseudo-ops were found within the procedure.  */
  5051.  
  5052. static void
  5053. pa_procend (unused)
  5054.      int unused;
  5055. {
  5056.  
  5057.   /* We must have a valid space and subspace.  */
  5058.   pa_check_current_space_and_subspace ();
  5059.  
  5060.   /* If we are within a procedure definition, make sure we've
  5061.      defined a label for the procedure; handle case where the
  5062.      label was defined after the .PROC directive.
  5063.  
  5064.      Note there's not need to diddle with the segment or fragment
  5065.      for the label symbol in this case.  We have already switched
  5066.      into the new $CODE$ subspace at this point.  */
  5067.   if (within_procedure && last_call_info->start_symbol == NULL)
  5068.     {
  5069.       label_symbol_struct *label_symbol = pa_get_label ();
  5070.  
  5071.       if (label_symbol)
  5072.     {
  5073.       if (label_symbol->lss_label)
  5074.         {
  5075.           last_call_info->start_symbol = label_symbol->lss_label;
  5076.           label_symbol->lss_label->bsym->flags |= BSF_FUNCTION;
  5077. #ifdef OBJ_SOM
  5078.           /* Also handle allocation of a fixup to hold the unwind
  5079.          information when the label appears after the proc/procend.  */
  5080.           if (within_entry_exit)
  5081.         {
  5082.           char *where = frag_more (0);
  5083.  
  5084.           fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
  5085.                 NULL, (offsetT) 0, NULL,
  5086.                 0, R_HPPA_ENTRY, e_fsel, 0, 0,
  5087.                 (int *) &last_call_info->ci_unwind.descriptor);
  5088.         }
  5089. #endif
  5090.         }
  5091.       else
  5092.         as_bad ("Missing function name for .PROC (corrupted label chain)");
  5093.     }
  5094.       else
  5095.     as_bad ("Missing function name for .PROC");
  5096.     }
  5097.  
  5098.   if (!within_procedure)
  5099.     as_bad ("misplaced .procend");
  5100.  
  5101.   if (!callinfo_found)
  5102.     as_bad ("Missing .callinfo for this procedure");
  5103.  
  5104.   if (within_entry_exit)
  5105.     as_bad ("Missing .EXIT for a .ENTRY");
  5106.  
  5107. #ifdef OBJ_ELF
  5108.   /* ELF needs to mark the end of each function so that it can compute
  5109.      the size of the function (apparently its needed in the symbol table).  */
  5110.   hppa_elf_mark_end_of_function ();
  5111. #endif
  5112.  
  5113.   within_procedure = FALSE;
  5114.   demand_empty_rest_of_line ();
  5115.   pa_undefine_label ();
  5116. }
  5117.  
  5118. /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
  5119.    then create a new space entry to hold the information specified
  5120.    by the parameters to the .SPACE directive.  */
  5121.  
  5122. static sd_chain_struct *
  5123. pa_parse_space_stmt (space_name, create_flag)
  5124.      char *space_name;
  5125.      int create_flag;
  5126. {
  5127.   char *name, *ptemp, c;
  5128.   char loadable, defined, private, sort;
  5129.   int spnum, temp;
  5130.   asection *seg = NULL;
  5131.   sd_chain_struct *space;
  5132.  
  5133.   /* load default values */
  5134.   spnum = 0;
  5135.   sort = 0;
  5136.   loadable = TRUE;
  5137.   defined = TRUE;
  5138.   private = FALSE;
  5139.   if (strcmp (space_name, "$TEXT$") == 0)
  5140.     {
  5141.       seg = pa_def_spaces[0].segment;
  5142.       defined = pa_def_spaces[0].defined;
  5143.       private = pa_def_spaces[0].private;
  5144.       sort = pa_def_spaces[0].sort;
  5145.       spnum = pa_def_spaces[0].spnum;
  5146.     }
  5147.   else if (strcmp (space_name, "$PRIVATE$") == 0)
  5148.     {
  5149.       seg = pa_def_spaces[1].segment;
  5150.       defined = pa_def_spaces[1].defined;
  5151.       private = pa_def_spaces[1].private;
  5152.       sort = pa_def_spaces[1].sort;
  5153.       spnum = pa_def_spaces[1].spnum;
  5154.     }
  5155.  
  5156.   if (!is_end_of_statement ())
  5157.     {
  5158.       print_errors = FALSE;
  5159.       ptemp = input_line_pointer + 1;
  5160.       /* First see if the space was specified as a number rather than
  5161.          as a name.  According to the PA assembly manual the rest of
  5162.          the line should be ignored.  */
  5163.       temp = pa_parse_number (&ptemp, 0);
  5164.       if (temp >= 0)
  5165.     {
  5166.       spnum = temp;
  5167.       input_line_pointer = ptemp;
  5168.     }
  5169.       else
  5170.     {
  5171.       while (!is_end_of_statement ())
  5172.         {
  5173.           input_line_pointer++;
  5174.           name = input_line_pointer;
  5175.           c = get_symbol_end ();
  5176.           if ((strncasecmp (name, "spnum", 5) == 0))
  5177.         {
  5178.           *input_line_pointer = c;
  5179.           input_line_pointer++;
  5180.           spnum = get_absolute_expression ();
  5181.         }
  5182.           else if ((strncasecmp (name, "sort", 4) == 0))
  5183.         {
  5184.           *input_line_pointer = c;
  5185.           input_line_pointer++;
  5186.           sort = get_absolute_expression ();
  5187.         }
  5188.           else if ((strncasecmp (name, "unloadable", 10) == 0))
  5189.         {
  5190.           *input_line_pointer = c;
  5191.           loadable = FALSE;
  5192.         }
  5193.           else if ((strncasecmp (name, "notdefined", 10) == 0))
  5194.         {
  5195.           *input_line_pointer = c;
  5196.           defined = FALSE;
  5197.         }
  5198.           else if ((strncasecmp (name, "private", 7) == 0))
  5199.         {
  5200.           *input_line_pointer = c;
  5201.           private = TRUE;
  5202.         }
  5203.           else
  5204.         {
  5205.           as_bad ("Invalid .SPACE argument");
  5206.           *input_line_pointer = c;
  5207.           if (!is_end_of_statement ())
  5208.             input_line_pointer++;
  5209.         }
  5210.         }
  5211.     }
  5212.       print_errors = TRUE;
  5213.     }
  5214.  
  5215.   if (create_flag && seg == NULL)
  5216.     seg = subseg_new (space_name, 0);
  5217.  
  5218.   /* If create_flag is nonzero, then create the new space with
  5219.      the attributes computed above.  Else set the values in
  5220.      an already existing space -- this can only happen for
  5221.      the first occurence of a built-in space.  */
  5222.   if (create_flag)
  5223.     space = create_new_space (space_name, spnum, loadable, defined,
  5224.                   private, sort, seg, 1);
  5225.   else
  5226.     {
  5227.       space = is_defined_space (space_name);
  5228.       SPACE_SPNUM (space) = spnum;
  5229.       SPACE_DEFINED (space) = defined & 1;
  5230.       SPACE_USER_DEFINED (space) = 1;
  5231.     }
  5232.  
  5233. #ifdef obj_set_section_attributes
  5234.   obj_set_section_attributes (seg, defined, private, sort, spnum);
  5235. #endif
  5236.  
  5237.   return space;
  5238. }
  5239.  
  5240. /* Handle a .SPACE pseudo-op; this switches the current space to the
  5241.    given space, creating the new space if necessary.  */
  5242.  
  5243. static void
  5244. pa_space (unused)
  5245.      int unused;
  5246. {
  5247.   char *name, c, *space_name, *save_s;
  5248.   int temp;
  5249.   sd_chain_struct *sd_chain;
  5250.  
  5251.   if (within_procedure)
  5252.     {
  5253.       as_bad ("Can\'t change spaces within a procedure definition. Ignored");
  5254.       ignore_rest_of_line ();
  5255.     }
  5256.   else
  5257.     {
  5258.       /* Check for some of the predefined spaces.   FIXME: most of the code
  5259.          below is repeated several times, can we extract the common parts
  5260.          and place them into a subroutine or something similar?  */
  5261.       /* FIXME Is this (and the next IF stmt) really right?
  5262.      What if INPUT_LINE_POINTER points to "$TEXT$FOO"?  */
  5263.       if (strncmp (input_line_pointer, "$TEXT$", 6) == 0)
  5264.     {
  5265.       input_line_pointer += 6;
  5266.       sd_chain = is_defined_space ("$TEXT$");
  5267.       if (sd_chain == NULL)
  5268.         sd_chain = pa_parse_space_stmt ("$TEXT$", 1);
  5269.       else if (SPACE_USER_DEFINED (sd_chain) == 0)
  5270.         sd_chain = pa_parse_space_stmt ("$TEXT$", 0);
  5271.  
  5272.       current_space = sd_chain;
  5273.       subseg_set (text_section, sd_chain->sd_last_subseg);
  5274.       current_subspace
  5275.         = pa_subsegment_to_subspace (text_section,
  5276.                      sd_chain->sd_last_subseg);
  5277.       demand_empty_rest_of_line ();
  5278.       return;
  5279.     }
  5280.       if (strncmp (input_line_pointer, "$PRIVATE$", 9) == 0)
  5281.     {
  5282.       input_line_pointer += 9;
  5283.       sd_chain = is_defined_space ("$PRIVATE$");
  5284.       if (sd_chain == NULL)
  5285.         sd_chain = pa_parse_space_stmt ("$PRIVATE$", 1);
  5286.       else if (SPACE_USER_DEFINED (sd_chain) == 0)
  5287.         sd_chain = pa_parse_space_stmt ("$PRIVATE$", 0);
  5288.  
  5289.       current_space = sd_chain;
  5290.       subseg_set (data_section, sd_chain->sd_last_subseg);
  5291.       current_subspace
  5292.         = pa_subsegment_to_subspace (data_section,
  5293.                      sd_chain->sd_last_subseg);
  5294.       demand_empty_rest_of_line ();
  5295.       return;
  5296.     }
  5297.       if (!strncasecmp (input_line_pointer,
  5298.             GDB_DEBUG_SPACE_NAME,
  5299.             strlen (GDB_DEBUG_SPACE_NAME)))
  5300.     {
  5301.       input_line_pointer += strlen (GDB_DEBUG_SPACE_NAME);
  5302.       sd_chain = is_defined_space (GDB_DEBUG_SPACE_NAME);
  5303.       if (sd_chain == NULL)
  5304.         sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 1);
  5305.       else if (SPACE_USER_DEFINED (sd_chain) == 0)
  5306.         sd_chain = pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME, 0);
  5307.  
  5308.       current_space = sd_chain;
  5309.  
  5310.       {
  5311.         asection *gdb_section
  5312.         = bfd_make_section_old_way (stdoutput, GDB_DEBUG_SPACE_NAME);
  5313.  
  5314.         subseg_set (gdb_section, sd_chain->sd_last_subseg);
  5315.         current_subspace
  5316.           = pa_subsegment_to_subspace (gdb_section,
  5317.                        sd_chain->sd_last_subseg);
  5318.       }
  5319.       demand_empty_rest_of_line ();
  5320.       return;
  5321.     }
  5322.  
  5323.       /* It could be a space specified by number.  */
  5324.       print_errors = 0;
  5325.       save_s = input_line_pointer;
  5326.       if ((temp = pa_parse_number (&input_line_pointer, 0)) >= 0)
  5327.     {
  5328.       if ((sd_chain = pa_find_space_by_number (temp)))
  5329.         {
  5330.           current_space = sd_chain;
  5331.  
  5332.           subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
  5333.           current_subspace
  5334.         = pa_subsegment_to_subspace (sd_chain->sd_seg,
  5335.                          sd_chain->sd_last_subseg);
  5336.           demand_empty_rest_of_line ();
  5337.           return;
  5338.         }
  5339.     }
  5340.  
  5341.       /* Not a number, attempt to create a new space.  */
  5342.       print_errors = 1;
  5343.       input_line_pointer = save_s;
  5344.       name = input_line_pointer;
  5345.       c = get_symbol_end ();
  5346.       space_name = xmalloc (strlen (name) + 1);
  5347.       strcpy (space_name, name);
  5348.       *input_line_pointer = c;
  5349.  
  5350.       sd_chain = pa_parse_space_stmt (space_name, 1);
  5351.       current_space = sd_chain;
  5352.  
  5353.       subseg_set (sd_chain->sd_seg, sd_chain->sd_last_subseg);
  5354.       current_subspace = pa_subsegment_to_subspace (sd_chain->sd_seg,
  5355.                           sd_chain->sd_last_subseg);
  5356.       demand_empty_rest_of_line ();
  5357.     }
  5358. }
  5359.  
  5360. /* Switch to a new space.  (I think).  FIXME.  */
  5361.  
  5362. static void
  5363. pa_spnum (unused)
  5364.      int unused;
  5365. {
  5366.   char *name;
  5367.   char c;
  5368.   char *p;
  5369.   sd_chain_struct *space;
  5370.  
  5371.   name = input_line_pointer;
  5372.   c = get_symbol_end ();
  5373.   space = is_defined_space (name);
  5374.   if (space)
  5375.     {
  5376.       p = frag_more (4);
  5377.       md_number_to_chars (p, SPACE_SPNUM (space), 4);
  5378.     }
  5379.   else
  5380.     as_warn ("Undefined space: '%s' Assuming space number = 0.", name);
  5381.  
  5382.   *input_line_pointer = c;
  5383.   demand_empty_rest_of_line ();
  5384. }
  5385.  
  5386. /* If VALUE is an exact power of two between zero and 2^31, then
  5387.    return log2 (VALUE).  Else return -1.  */
  5388.  
  5389. static int
  5390. log2 (value)
  5391.      int value;
  5392. {
  5393.   int shift = 0;
  5394.  
  5395.   while ((1 << shift) != value && shift < 32)
  5396.     shift++;
  5397.  
  5398.   if (shift >= 32)
  5399.     return -1;
  5400.   else
  5401.     return shift;
  5402. }
  5403.  
  5404. /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
  5405.    given subspace, creating the new subspace if necessary.
  5406.  
  5407.    FIXME.  Should mirror pa_space more closely, in particular how
  5408.    they're broken up into subroutines.  */
  5409.  
  5410. static void
  5411. pa_subspace (create_new)
  5412.      int create_new;
  5413. {
  5414.   char *name, *ss_name, *alias, c;
  5415.   char loadable, code_only, common, dup_common, zero, sort;
  5416.   int i, access, space_index, alignment, quadrant, applicable, flags;
  5417.   sd_chain_struct *space;
  5418.   ssd_chain_struct *ssd;
  5419.   asection *section;
  5420.  
  5421.   if (current_space == NULL)
  5422.     as_fatal ("Must be in a space before changing or declaring subspaces.\n");
  5423.  
  5424.   if (within_procedure)
  5425.     {
  5426.       as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
  5427.       ignore_rest_of_line ();
  5428.     }
  5429.   else
  5430.     {
  5431.       name = input_line_pointer;
  5432.       c = get_symbol_end ();
  5433.       ss_name = xmalloc (strlen (name) + 1);
  5434.       strcpy (ss_name, name);
  5435.       *input_line_pointer = c;
  5436.  
  5437.       /* Load default values.  */
  5438.       sort = 0;
  5439.       access = 0x7f;
  5440.       loadable = 1;
  5441.       common = 0;
  5442.       dup_common = 0;
  5443.       code_only = 0;
  5444.       zero = 0;
  5445.       space_index = ~0;
  5446.       alignment = 1;
  5447.       quadrant = 0;
  5448.       alias = NULL;
  5449.  
  5450.       space = current_space;
  5451.       if (create_new)
  5452.     ssd = NULL;
  5453.       else
  5454.     ssd = is_defined_subspace (ss_name);
  5455.       /* Allow user to override the builtin attributes of subspaces.  But
  5456.          only allow the attributes to be changed once!  */
  5457.       if (ssd && SUBSPACE_DEFINED (ssd))
  5458.     {
  5459.       subseg_set (ssd->ssd_seg, ssd->ssd_subseg);
  5460.       current_subspace = ssd;
  5461.       if (!is_end_of_statement ())
  5462.         as_warn ("Parameters of an existing subspace can\'t be modified");
  5463.       demand_empty_rest_of_line ();
  5464.       return;
  5465.     }
  5466.       else
  5467.     {
  5468.       /* A new subspace.  Load default values if it matches one of
  5469.          the builtin subspaces.  */
  5470.       i = 0;
  5471.       while (pa_def_subspaces[i].name)
  5472.         {
  5473.           if (strcasecmp (pa_def_subspaces[i].name, ss_name) == 0)
  5474.         {
  5475.           loadable = pa_def_subspaces[i].loadable;
  5476.           common = pa_def_subspaces[i].common;
  5477.           dup_common = pa_def_subspaces[i].dup_common;
  5478.           code_only = pa_def_subspaces[i].code_only;
  5479.           zero = pa_def_subspaces[i].zero;
  5480.           space_index = pa_def_subspaces[i].space_index;
  5481.           alignment = pa_def_subspaces[i].alignment;
  5482.           quadrant = pa_def_subspaces[i].quadrant;
  5483.           access = pa_def_subspaces[i].access;
  5484.           sort = pa_def_subspaces[i].sort;
  5485.           if (USE_ALIASES && pa_def_subspaces[i].alias)
  5486.             alias = pa_def_subspaces[i].alias;
  5487.           break;
  5488.         }
  5489.           i++;
  5490.         }
  5491.     }
  5492.  
  5493.       /* We should be working with a new subspace now.  Fill in
  5494.          any information as specified by the user.  */
  5495.       if (!is_end_of_statement ())
  5496.     {
  5497.       input_line_pointer++;
  5498.       while (!is_end_of_statement ())
  5499.         {
  5500.           name = input_line_pointer;
  5501.           c = get_symbol_end ();
  5502.           if ((strncasecmp (name, "quad", 4) == 0))
  5503.         {
  5504.           *input_line_pointer = c;
  5505.           input_line_pointer++;
  5506.           quadrant = get_absolute_expression ();
  5507.         }
  5508.           else if ((strncasecmp (name, "align", 5) == 0))
  5509.         {
  5510.           *input_line_pointer = c;
  5511.           input_line_pointer++;
  5512.           alignment = get_absolute_expression ();
  5513.           if (log2 (alignment) == -1)
  5514.             {
  5515.               as_bad ("Alignment must be a power of 2");
  5516.               alignment = 1;
  5517.             }
  5518.         }
  5519.           else if ((strncasecmp (name, "access", 6) == 0))
  5520.         {
  5521.           *input_line_pointer = c;
  5522.           input_line_pointer++;
  5523.           access = get_absolute_expression ();
  5524.         }
  5525.           else if ((strncasecmp (name, "sort", 4) == 0))
  5526.         {
  5527.           *input_line_pointer = c;
  5528.           input_line_pointer++;
  5529.           sort = get_absolute_expression ();
  5530.         }
  5531.           else if ((strncasecmp (name, "code_only", 9) == 0))
  5532.         {
  5533.           *input_line_pointer = c;
  5534.           code_only = 1;
  5535.         }
  5536.           else if ((strncasecmp (name, "unloadable", 10) == 0))
  5537.         {
  5538.           *input_line_pointer = c;
  5539.           loadable = 0;
  5540.         }
  5541.           else if ((strncasecmp (name, "common", 6) == 0))
  5542.         {
  5543.           *input_line_pointer = c;
  5544.           common = 1;
  5545.         }
  5546.           else if ((strncasecmp (name, "dup_comm", 8) == 0))
  5547.         {
  5548.           *input_line_pointer = c;
  5549.           dup_common = 1;
  5550.         }
  5551.           else if ((strncasecmp (name, "zero", 4) == 0))
  5552.         {
  5553.           *input_line_pointer = c;
  5554.           zero = 1;
  5555.         }
  5556.           else if ((strncasecmp (name, "first", 5) == 0))
  5557.         as_bad ("FIRST not supported as a .SUBSPACE argument");
  5558.           else
  5559.         as_bad ("Invalid .SUBSPACE argument");
  5560.           if (!is_end_of_statement ())
  5561.         input_line_pointer++;
  5562.         }
  5563.     }
  5564.  
  5565.       /* Compute a reasonable set of BFD flags based on the information
  5566.          in the .subspace directive.  */
  5567.       applicable = bfd_applicable_section_flags (stdoutput);
  5568.       flags = 0;
  5569.       if (loadable)
  5570.     flags |= (SEC_ALLOC | SEC_LOAD);
  5571.       if (code_only)
  5572.     flags |= SEC_CODE;
  5573.       if (common || dup_common)
  5574.     flags |= SEC_IS_COMMON;
  5575.  
  5576.       flags |= SEC_RELOC | SEC_HAS_CONTENTS;
  5577.  
  5578.       /* This is a zero-filled subspace (eg BSS).  */
  5579.       if (zero)
  5580.     flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
  5581.  
  5582.       applicable &= flags;
  5583.  
  5584.       /* If this is an existing subspace, then we want to use the
  5585.          segment already associated with the subspace.
  5586.  
  5587.          FIXME NOW!  ELF BFD doesn't appear to be ready to deal with
  5588.          lots of sections.  It might be a problem in the PA ELF
  5589.          code, I do not know yet.  For now avoid creating anything
  5590.          but the "standard" sections for ELF.  */
  5591.       if (create_new)
  5592.     section = subseg_force_new (ss_name, 0);
  5593.       else if (ssd)
  5594.     section = ssd->ssd_seg;
  5595.       else if (alias)
  5596.     section = subseg_new (alias, 0);
  5597.       else if (!alias && USE_ALIASES)
  5598.     {
  5599.       as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
  5600.       demand_empty_rest_of_line ();
  5601.       return;
  5602.     }
  5603.       else
  5604.     section = subseg_new (ss_name, 0);
  5605.  
  5606.       if (zero)
  5607.     seg_info (section)->bss = 1;
  5608.  
  5609.       /* Now set the flags.  */
  5610.       bfd_set_section_flags (stdoutput, section, applicable);
  5611.  
  5612.       /* Record any alignment request for this section.  */
  5613.       record_alignment (section, log2 (alignment));
  5614.  
  5615.       /* Set the starting offset for this section.  */
  5616.       bfd_set_section_vma (stdoutput, section,
  5617.                pa_subspace_start (space, quadrant));
  5618.  
  5619.       /* Now that all the flags are set, update an existing subspace,
  5620.          or create a new one.  */
  5621.       if (ssd)
  5622.  
  5623.     current_subspace = update_subspace (space, ss_name, loadable,
  5624.                         code_only, common, dup_common,
  5625.                         sort, zero, access, space_index,
  5626.                         alignment, quadrant,
  5627.                         section);
  5628.       else
  5629.     current_subspace = create_new_subspace (space, ss_name, loadable,
  5630.                         code_only, common,
  5631.                         dup_common, zero, sort,
  5632.                         access, space_index,
  5633.                           alignment, quadrant, section);
  5634.  
  5635.       demand_empty_rest_of_line ();
  5636.       current_subspace->ssd_seg = section;
  5637.       subseg_set (current_subspace->ssd_seg, current_subspace->ssd_subseg);
  5638.     }
  5639.   SUBSPACE_DEFINED (current_subspace) = 1;
  5640. }
  5641.  
  5642.  
  5643. /* Create default space and subspace dictionaries.  */
  5644.  
  5645. static void
  5646. pa_spaces_begin ()
  5647. {
  5648.   int i;
  5649.  
  5650.   space_dict_root = NULL;
  5651.   space_dict_last = NULL;
  5652.  
  5653.   i = 0;
  5654.   while (pa_def_spaces[i].name)
  5655.     {
  5656.       char *name;
  5657.  
  5658.       /* Pick the right name to use for the new section.  */
  5659.       if (pa_def_spaces[i].alias && USE_ALIASES)
  5660.     name = pa_def_spaces[i].alias;
  5661.       else
  5662.     name = pa_def_spaces[i].name;
  5663.  
  5664.       pa_def_spaces[i].segment = subseg_new (name, 0);
  5665.       create_new_space (pa_def_spaces[i].name, pa_def_spaces[i].spnum,
  5666.             pa_def_spaces[i].loadable, pa_def_spaces[i].defined,
  5667.             pa_def_spaces[i].private, pa_def_spaces[i].sort,
  5668.             pa_def_spaces[i].segment, 0);
  5669.       i++;
  5670.     }
  5671.  
  5672.   i = 0;
  5673.   while (pa_def_subspaces[i].name)
  5674.     {
  5675.       char *name;
  5676.       int applicable, subsegment;
  5677.       asection *segment = NULL;
  5678.       sd_chain_struct *space;
  5679.  
  5680.       /* Pick the right name for the new section and pick the right
  5681.          subsegment number.  */
  5682.       if (pa_def_subspaces[i].alias && USE_ALIASES)
  5683.     {
  5684.       name = pa_def_subspaces[i].alias;
  5685.       subsegment = pa_def_subspaces[i].subsegment;
  5686.     }
  5687.       else
  5688.     {
  5689.       name = pa_def_subspaces[i].name;
  5690.       subsegment = 0;
  5691.     }
  5692.  
  5693.       /* Create the new section.  */
  5694.       segment = subseg_new (name, subsegment);
  5695.  
  5696.  
  5697.       /* For SOM we want to replace the standard .text, .data, and .bss
  5698.          sections with our own.   We also want to set BFD flags for
  5699.      all the built-in subspaces.  */
  5700.       if (!strcmp (pa_def_subspaces[i].name, "$CODE$") && !USE_ALIASES)
  5701.     {
  5702.       text_section = segment;
  5703.       applicable = bfd_applicable_section_flags (stdoutput);
  5704.       bfd_set_section_flags (stdoutput, segment,
  5705.                  applicable & (SEC_ALLOC | SEC_LOAD
  5706.                            | SEC_RELOC | SEC_CODE
  5707.                            | SEC_READONLY
  5708.                            | SEC_HAS_CONTENTS));
  5709.     }
  5710.       else if (!strcmp (pa_def_subspaces[i].name, "$DATA$") && !USE_ALIASES)
  5711.     {
  5712.       data_section = segment;
  5713.       applicable = bfd_applicable_section_flags (stdoutput);
  5714.       bfd_set_section_flags (stdoutput, segment,
  5715.                  applicable & (SEC_ALLOC | SEC_LOAD
  5716.                            | SEC_RELOC
  5717.                            | SEC_HAS_CONTENTS));
  5718.  
  5719.  
  5720.     }
  5721.       else if (!strcmp (pa_def_subspaces[i].name, "$BSS$") && !USE_ALIASES)
  5722.     {
  5723.       bss_section = segment;
  5724.       applicable = bfd_applicable_section_flags (stdoutput);
  5725.       bfd_set_section_flags (stdoutput, segment,
  5726.                  applicable & SEC_ALLOC);
  5727.     }
  5728.       else if (!strcmp (pa_def_subspaces[i].name, "$LIT$") && !USE_ALIASES)
  5729.     {
  5730.       applicable = bfd_applicable_section_flags (stdoutput);
  5731.       bfd_set_section_flags (stdoutput, segment,
  5732.                  applicable & (SEC_ALLOC | SEC_LOAD
  5733.                            | SEC_RELOC
  5734.                            | SEC_READONLY
  5735.                            | SEC_HAS_CONTENTS));
  5736.     }
  5737.       else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$")
  5738.            && !USE_ALIASES)
  5739.     {
  5740.       applicable = bfd_applicable_section_flags (stdoutput);
  5741.       bfd_set_section_flags (stdoutput, segment,
  5742.                  applicable & (SEC_ALLOC | SEC_LOAD
  5743.                            | SEC_RELOC
  5744.                            | SEC_READONLY
  5745.                            | SEC_HAS_CONTENTS));
  5746.     }
  5747.       else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$") && !USE_ALIASES)
  5748.     {
  5749.       applicable = bfd_applicable_section_flags (stdoutput);
  5750.       bfd_set_section_flags (stdoutput, segment,
  5751.                  applicable & (SEC_ALLOC | SEC_LOAD
  5752.                            | SEC_RELOC
  5753.                            | SEC_READONLY
  5754.                            | SEC_HAS_CONTENTS));
  5755.     }
  5756.  
  5757.       /* Find the space associated with this subspace.  */
  5758.       space = pa_segment_to_space (pa_def_spaces[pa_def_subspaces[i].
  5759.                          def_space_index].segment);
  5760.       if (space == NULL)
  5761.     {
  5762.       as_fatal ("Internal error: Unable to find containing space for %s.",
  5763.             pa_def_subspaces[i].name);
  5764.     }
  5765.  
  5766.       create_new_subspace (space, name,
  5767.                pa_def_subspaces[i].loadable,
  5768.                pa_def_subspaces[i].code_only,
  5769.                pa_def_subspaces[i].common,
  5770.                pa_def_subspaces[i].dup_common,
  5771.                pa_def_subspaces[i].zero,
  5772.                pa_def_subspaces[i].sort,
  5773.                pa_def_subspaces[i].access,
  5774.                pa_def_subspaces[i].space_index,
  5775.                pa_def_subspaces[i].alignment,
  5776.                pa_def_subspaces[i].quadrant,
  5777.                segment);
  5778.       i++;
  5779.     }
  5780. }
  5781.  
  5782.  
  5783.  
  5784. /* Create a new space NAME, with the appropriate flags as defined
  5785.    by the given parameters.  */
  5786.  
  5787. static sd_chain_struct *
  5788. create_new_space (name, spnum, loadable, defined, private,
  5789.           sort, seg, user_defined)
  5790.      char *name;
  5791.      int spnum;
  5792.      int loadable;
  5793.      int defined;
  5794.      int private;
  5795.      int sort;
  5796.      asection *seg;
  5797.      int user_defined;
  5798. {
  5799.   sd_chain_struct *chain_entry;
  5800.  
  5801.   chain_entry = (sd_chain_struct *) xmalloc (sizeof (sd_chain_struct));
  5802.   if (!chain_entry)
  5803.     as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
  5804.           name);
  5805.  
  5806.   SPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
  5807.   strcpy (SPACE_NAME (chain_entry), name);
  5808.   SPACE_DEFINED (chain_entry) = defined;
  5809.   SPACE_USER_DEFINED (chain_entry) = user_defined;
  5810.   SPACE_SPNUM (chain_entry) = spnum;
  5811.  
  5812.   chain_entry->sd_seg = seg;
  5813.   chain_entry->sd_last_subseg = -1;
  5814.   chain_entry->sd_subspaces = NULL;
  5815.   chain_entry->sd_next = NULL;
  5816.  
  5817.   /* Find spot for the new space based on its sort key.  */
  5818.   if (!space_dict_last)
  5819.     space_dict_last = chain_entry;
  5820.  
  5821.   if (space_dict_root == NULL)
  5822.     space_dict_root = chain_entry;
  5823.   else
  5824.     {
  5825.       sd_chain_struct *chain_pointer;
  5826.       sd_chain_struct *prev_chain_pointer;
  5827.  
  5828.       chain_pointer = space_dict_root;
  5829.       prev_chain_pointer = NULL;
  5830.  
  5831.       while (chain_pointer)
  5832.     {
  5833.       prev_chain_pointer = chain_pointer;
  5834.       chain_pointer = chain_pointer->sd_next;
  5835.     }
  5836.  
  5837.       /* At this point we've found the correct place to add the new
  5838.          entry.  So add it and update the linked lists as appropriate.  */
  5839.       if (prev_chain_pointer)
  5840.     {
  5841.       chain_entry->sd_next = chain_pointer;
  5842.       prev_chain_pointer->sd_next = chain_entry;
  5843.     }
  5844.       else
  5845.     {
  5846.       space_dict_root = chain_entry;
  5847.       chain_entry->sd_next = chain_pointer;
  5848.     }
  5849.  
  5850.       if (chain_entry->sd_next == NULL)
  5851.     space_dict_last = chain_entry;
  5852.     }
  5853.  
  5854.   /* This is here to catch predefined spaces which do not get
  5855.      modified by the user's input.  Another call is found at
  5856.      the bottom of pa_parse_space_stmt to handle cases where
  5857.      the user modifies a predefined space.  */
  5858. #ifdef obj_set_section_attributes
  5859.   obj_set_section_attributes (seg, defined, private, sort, spnum);
  5860. #endif
  5861.  
  5862.   return chain_entry;
  5863. }
  5864.  
  5865. /* Create a new subspace NAME, with the appropriate flags as defined
  5866.    by the given parameters.
  5867.  
  5868.    Add the new subspace to the subspace dictionary chain in numerical
  5869.    order as defined by the SORT entries.  */
  5870.  
  5871. static ssd_chain_struct *
  5872. create_new_subspace (space, name, loadable, code_only, common,
  5873.              dup_common, is_zero, sort, access, space_index,
  5874.              alignment, quadrant, seg)
  5875.      sd_chain_struct *space;
  5876.      char *name;
  5877.      int loadable, code_only, common, dup_common, is_zero;
  5878.      int sort;
  5879.      int access;
  5880.      int space_index;
  5881.      int alignment;
  5882.      int quadrant;
  5883.      asection *seg;
  5884. {
  5885.   ssd_chain_struct *chain_entry;
  5886.  
  5887.   chain_entry = (ssd_chain_struct *) xmalloc (sizeof (ssd_chain_struct));
  5888.   if (!chain_entry)
  5889.     as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name);
  5890.  
  5891.   SUBSPACE_NAME (chain_entry) = (char *) xmalloc (strlen (name) + 1);
  5892.   strcpy (SUBSPACE_NAME (chain_entry), name);
  5893.  
  5894.   /* Initialize subspace_defined.  When we hit a .subspace directive
  5895.      we'll set it to 1 which "locks-in" the subspace attributes.  */
  5896.   SUBSPACE_DEFINED (chain_entry) = 0;
  5897.  
  5898.   chain_entry->ssd_subseg = USE_ALIASES ? pa_next_subseg (space) : 0;
  5899.   chain_entry->ssd_seg = seg;
  5900.   chain_entry->ssd_next = NULL;
  5901.  
  5902.   /* Find spot for the new subspace based on its sort key.  */
  5903.   if (space->sd_subspaces == NULL)
  5904.     space->sd_subspaces = chain_entry;
  5905.   else
  5906.     {
  5907.       ssd_chain_struct *chain_pointer;
  5908.       ssd_chain_struct *prev_chain_pointer;
  5909.  
  5910.       chain_pointer = space->sd_subspaces;
  5911.       prev_chain_pointer = NULL;
  5912.  
  5913.       while (chain_pointer)
  5914.     {
  5915.       prev_chain_pointer = chain_pointer;
  5916.       chain_pointer = chain_pointer->ssd_next;
  5917.     }
  5918.  
  5919.       /* Now we have somewhere to put the new entry.  Insert it and update
  5920.          the links.  */
  5921.       if (prev_chain_pointer)
  5922.     {
  5923.       chain_entry->ssd_next = chain_pointer;
  5924.       prev_chain_pointer->ssd_next = chain_entry;
  5925.     }
  5926.       else
  5927.     {
  5928.       space->sd_subspaces = chain_entry;
  5929.       chain_entry->ssd_next = chain_pointer;
  5930.     }
  5931.     }
  5932.  
  5933. #ifdef obj_set_subsection_attributes
  5934.   obj_set_subsection_attributes (seg, space->sd_seg, access,
  5935.                  sort, quadrant);
  5936. #endif
  5937.  
  5938.   return chain_entry;
  5939. }
  5940.  
  5941. /* Update the information for the given subspace based upon the
  5942.    various arguments.   Return the modified subspace chain entry.  */
  5943.  
  5944. static ssd_chain_struct *
  5945. update_subspace (space, name, loadable, code_only, common, dup_common, sort,
  5946.          zero, access, space_index, alignment, quadrant, section)
  5947.      sd_chain_struct *space;
  5948.      char *name;
  5949.      int loadable;
  5950.      int code_only;
  5951.      int common;
  5952.      int dup_common;
  5953.      int zero;
  5954.      int sort;
  5955.      int access;
  5956.      int space_index;
  5957.      int alignment;
  5958.      int quadrant;
  5959.      asection *section;
  5960. {
  5961.   ssd_chain_struct *chain_entry;
  5962.  
  5963.   chain_entry = is_defined_subspace (name);
  5964.  
  5965. #ifdef obj_set_subsection_attributes
  5966.   obj_set_subsection_attributes (section, space->sd_seg, access,
  5967.                  sort, quadrant);
  5968. #endif
  5969.  
  5970.   return chain_entry;
  5971. }
  5972.  
  5973. /* Return the space chain entry for the space with the name NAME or
  5974.    NULL if no such space exists.  */
  5975.  
  5976. static sd_chain_struct *
  5977. is_defined_space (name)
  5978.      char *name;
  5979. {
  5980.   sd_chain_struct *chain_pointer;
  5981.  
  5982.   for (chain_pointer = space_dict_root;
  5983.        chain_pointer;
  5984.        chain_pointer = chain_pointer->sd_next)
  5985.     {
  5986.       if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
  5987.     return chain_pointer;
  5988.     }
  5989.  
  5990.   /* No mapping from segment to space was found.  Return NULL.  */
  5991.   return NULL;
  5992. }
  5993.  
  5994. /* Find and return the space associated with the given seg.  If no mapping
  5995.    from the given seg to a space is found, then return NULL.
  5996.  
  5997.    Unlike subspaces, the number of spaces is not expected to grow much,
  5998.    so a linear exhaustive search is OK here.  */
  5999.  
  6000. static sd_chain_struct *
  6001. pa_segment_to_space (seg)
  6002.      asection *seg;
  6003. {
  6004.   sd_chain_struct *space_chain;
  6005.  
  6006.   /* Walk through each space looking for the correct mapping.  */
  6007.   for (space_chain = space_dict_root;
  6008.        space_chain;
  6009.        space_chain = space_chain->sd_next)
  6010.     {
  6011.       if (space_chain->sd_seg == seg)
  6012.     return space_chain;
  6013.     }
  6014.  
  6015.   /* Mapping was not found.  Return NULL.  */
  6016.   return NULL;
  6017. }
  6018.  
  6019. /* Return the space chain entry for the subspace with the name NAME or
  6020.    NULL if no such subspace exists.
  6021.  
  6022.    Uses a linear search through all the spaces and subspaces, this may
  6023.    not be appropriate if we ever being placing each function in its
  6024.    own subspace.  */
  6025.  
  6026. static ssd_chain_struct *
  6027. is_defined_subspace (name)
  6028.      char *name;
  6029. {
  6030.   sd_chain_struct *space_chain;
  6031.   ssd_chain_struct *subspace_chain;
  6032.  
  6033.   /* Walk through each space.  */
  6034.   for (space_chain = space_dict_root;
  6035.        space_chain;
  6036.        space_chain = space_chain->sd_next)
  6037.     {
  6038.       /* Walk through each subspace looking for a name which matches.  */
  6039.       for (subspace_chain = space_chain->sd_subspaces;
  6040.        subspace_chain;
  6041.        subspace_chain = subspace_chain->ssd_next)
  6042.     if (strcmp (SUBSPACE_NAME (subspace_chain), name) == 0)
  6043.       return subspace_chain;
  6044.     }
  6045.  
  6046.   /* Subspace wasn't found.  Return NULL.  */
  6047.   return NULL;
  6048. }
  6049.  
  6050. /* Find and return the subspace associated with the given seg.  If no
  6051.    mapping from the given seg to a subspace is found, then return NULL.
  6052.  
  6053.    If we ever put each procedure/function within its own subspace
  6054.    (to make life easier on the compiler and linker), then this will have
  6055.    to become more efficient.  */
  6056.  
  6057. static ssd_chain_struct *
  6058. pa_subsegment_to_subspace (seg, subseg)
  6059.      asection *seg;
  6060.      subsegT subseg;
  6061. {
  6062.   sd_chain_struct *space_chain;
  6063.   ssd_chain_struct *subspace_chain;
  6064.  
  6065.   /* Walk through each space.  */
  6066.   for (space_chain = space_dict_root;
  6067.        space_chain;
  6068.        space_chain = space_chain->sd_next)
  6069.     {
  6070.       if (space_chain->sd_seg == seg)
  6071.     {
  6072.       /* Walk through each subspace within each space looking for
  6073.          the correct mapping.  */
  6074.       for (subspace_chain = space_chain->sd_subspaces;
  6075.            subspace_chain;
  6076.            subspace_chain = subspace_chain->ssd_next)
  6077.         if (subspace_chain->ssd_subseg == (int) subseg)
  6078.           return subspace_chain;
  6079.     }
  6080.     }
  6081.  
  6082.   /* No mapping from subsegment to subspace found.  Return NULL.  */
  6083.   return NULL;
  6084. }
  6085.  
  6086. /* Given a number, try and find a space with the name number.
  6087.  
  6088.    Return a pointer to a space dictionary chain entry for the space
  6089.    that was found or NULL on failure.  */
  6090.  
  6091. static sd_chain_struct *
  6092. pa_find_space_by_number (number)
  6093.      int number;
  6094. {
  6095.   sd_chain_struct *space_chain;
  6096.  
  6097.   for (space_chain = space_dict_root;
  6098.        space_chain;
  6099.        space_chain = space_chain->sd_next)
  6100.     {
  6101.       if (SPACE_SPNUM (space_chain) == number)
  6102.     return space_chain;
  6103.     }
  6104.  
  6105.   /* No appropriate space found.  Return NULL.  */
  6106.   return NULL;
  6107. }
  6108.  
  6109. /* Return the starting address for the given subspace.  If the starting
  6110.    address is unknown then return zero.  */
  6111.  
  6112. static unsigned int
  6113. pa_subspace_start (space, quadrant)
  6114.      sd_chain_struct *space;
  6115.      int quadrant;
  6116. {
  6117.   /* FIXME.  Assumes everyone puts read/write data at 0x4000000, this
  6118.      is not correct for the PA OSF1 port.  */
  6119.   if ((strcmp (SPACE_NAME (space), "$PRIVATE$") == 0) && quadrant == 1)
  6120.     return 0x40000000;
  6121.   else if (space->sd_seg == data_section && quadrant == 1)
  6122.     return 0x40000000;
  6123.   else
  6124.     return 0;
  6125. }
  6126.  
  6127. /* FIXME.  Needs documentation.  */
  6128. static int
  6129. pa_next_subseg (space)
  6130.      sd_chain_struct *space;
  6131. {
  6132.  
  6133.   space->sd_last_subseg++;
  6134.   return space->sd_last_subseg;
  6135. }
  6136.  
  6137. /* Helper function for pa_stringer.  Used to find the end of
  6138.    a string.  */
  6139.  
  6140. static unsigned int
  6141. pa_stringer_aux (s)
  6142.      char *s;
  6143. {
  6144.   unsigned int c = *s & CHAR_MASK;
  6145.  
  6146.   /* We must have a valid space and subspace.  */
  6147.   pa_check_current_space_and_subspace ();
  6148.  
  6149.   switch (c)
  6150.     {
  6151.     case '\"':
  6152.       c = NOT_A_CHAR;
  6153.       break;
  6154.     default:
  6155.       break;
  6156.     }
  6157.   return c;
  6158. }
  6159.  
  6160. /* Handle a .STRING type pseudo-op.  */
  6161.  
  6162. static void
  6163. pa_stringer (append_zero)
  6164.      int append_zero;
  6165. {
  6166.   char *s, num_buf[4];
  6167.   unsigned int c;
  6168.   int i;
  6169.  
  6170.   /* Preprocess the string to handle PA-specific escape sequences.
  6171.      For example, \xDD where DD is a hexidecimal number should be
  6172.      changed to \OOO where OOO is an octal number.  */
  6173.  
  6174.   /* Skip the opening quote.  */
  6175.   s = input_line_pointer + 1;
  6176.  
  6177.   while (is_a_char (c = pa_stringer_aux (s++)))
  6178.     {
  6179.       if (c == '\\')
  6180.     {
  6181.       c = *s;
  6182.       switch (c)
  6183.         {
  6184.           /* Handle \x<num>.  */
  6185.         case 'x':
  6186.           {
  6187.         unsigned int number;
  6188.         int num_digit;
  6189.         char dg;
  6190.         char *s_start = s;
  6191.  
  6192.         /* Get pas the 'x'.  */
  6193.         s++;
  6194.         for (num_digit = 0, number = 0, dg = *s;
  6195.              num_digit < 2
  6196.              && (isdigit (dg) || (dg >= 'a' && dg <= 'f')
  6197.              || (dg >= 'A' && dg <= 'F'));
  6198.              num_digit++)
  6199.           {
  6200.             if (isdigit (dg))
  6201.               number = number * 16 + dg - '0';
  6202.             else if (dg >= 'a' && dg <= 'f')
  6203.               number = number * 16 + dg - 'a' + 10;
  6204.             else
  6205.               number = number * 16 + dg - 'A' + 10;
  6206.  
  6207.             s++;
  6208.             dg = *s;
  6209.           }
  6210.         if (num_digit > 0)
  6211.           {
  6212.             switch (num_digit)
  6213.               {
  6214.               case 1:
  6215.             sprintf (num_buf, "%02o", number);
  6216.             break;
  6217.               case 2:
  6218.             sprintf (num_buf, "%03o", number);
  6219.             break;
  6220.               }
  6221.             for (i = 0; i <= num_digit; i++)
  6222.               s_start[i] = num_buf[i];
  6223.           }
  6224.         break;
  6225.           }
  6226.         /* This might be a "\"", skip over the escaped char.  */
  6227.         default:
  6228.           s++;
  6229.           break;
  6230.         }
  6231.     }
  6232.     }
  6233.   stringer (append_zero);
  6234.   pa_undefine_label ();
  6235. }
  6236.  
  6237. /* Handle a .VERSION pseudo-op.  */
  6238.  
  6239. static void
  6240. pa_version (unused)
  6241.      int unused;
  6242. {
  6243.   obj_version (0);
  6244.   pa_undefine_label ();
  6245. }
  6246.  
  6247. /* Handle a .COPYRIGHT pseudo-op.  */
  6248.  
  6249. static void
  6250. pa_copyright (unused)
  6251.      int unused;
  6252. {
  6253.   obj_copyright (0);
  6254.   pa_undefine_label ();
  6255. }
  6256.  
  6257. /* Just like a normal cons, but when finished we have to undefine
  6258.    the latest space label.  */
  6259.  
  6260. static void
  6261. pa_cons (nbytes)
  6262.      int nbytes;
  6263. {
  6264.   cons (nbytes);
  6265.   pa_undefine_label ();
  6266. }
  6267.  
  6268. /* Switch to the data space.  As usual delete our label.  */
  6269.  
  6270. static void
  6271. pa_data (unused)
  6272.      int unused;
  6273. {
  6274.   current_space = is_defined_space ("$PRIVATE$");
  6275.   current_subspace
  6276.     = pa_subsegment_to_subspace (current_space->sd_seg, 0);
  6277.   s_data (0);
  6278.   pa_undefine_label ();
  6279. }
  6280.  
  6281. /* Like float_cons, but we need to undefine our label.  */
  6282.  
  6283. static void
  6284. pa_float_cons (float_type)
  6285.      int float_type;
  6286. {
  6287.   float_cons (float_type);
  6288.   pa_undefine_label ();
  6289. }
  6290.  
  6291. /* Like s_fill, but delete our label when finished.  */
  6292.  
  6293. static void
  6294. pa_fill (unused)
  6295.      int unused;
  6296. {
  6297.   /* We must have a valid space and subspace.  */
  6298.   pa_check_current_space_and_subspace ();
  6299.  
  6300.   s_fill (0);
  6301.   pa_undefine_label ();
  6302. }
  6303.  
  6304. /* Like lcomm, but delete our label when finished.  */
  6305.  
  6306. static void
  6307. pa_lcomm (needs_align)
  6308.      int needs_align;
  6309. {
  6310.   /* We must have a valid space and subspace.  */
  6311.   pa_check_current_space_and_subspace ();
  6312.  
  6313.   s_lcomm (needs_align);
  6314.   pa_undefine_label ();
  6315. }
  6316.  
  6317. /* Like lsym, but delete our label when finished.  */
  6318.  
  6319. static void
  6320. pa_lsym (unused)
  6321.      int unused;
  6322. {
  6323.   /* We must have a valid space and subspace.  */
  6324.   pa_check_current_space_and_subspace ();
  6325.  
  6326.   s_lsym (0);
  6327.   pa_undefine_label ();
  6328. }
  6329.  
  6330. /* Switch to the text space.  Like s_text, but delete our
  6331.    label when finished.  */
  6332. static void
  6333. pa_text (unused)
  6334.      int unused;
  6335. {
  6336.   current_space = is_defined_space ("$TEXT$");
  6337.   current_subspace
  6338.     = pa_subsegment_to_subspace (current_space->sd_seg, 0);
  6339.  
  6340.   s_text (0);
  6341.   pa_undefine_label ();
  6342. }
  6343.  
  6344. /* On the PA relocations which involve function symbols must not be
  6345.    adjusted.  This so that the linker can know when/how to create argument
  6346.    relocation stubs for indirect calls and calls to static functions.
  6347.  
  6348.    "T" field selectors create DLT relative fixups for accessing
  6349.    globals and statics in PIC code; each DLT relative fixup creates
  6350.    an entry in the DLT table.  The entries contain the address of
  6351.    the final target (eg accessing "foo" would create a DLT entry
  6352.    with the address of "foo").
  6353.  
  6354.    Unfortunately, the HP linker doesn't take into account any addend
  6355.    when generating the DLT; so accessing $LIT$+8 puts the address of
  6356.    $LIT$ into the DLT rather than the address of $LIT$+8.
  6357.  
  6358.    The end result is we can't perform relocation symbol reductions for
  6359.    any fixup which creates entries in the DLT (eg they use "T" field
  6360.    selectors).
  6361.  
  6362.    Reject reductions involving symbols with external scope; such
  6363.    reductions make life a living hell for object file editors. 
  6364.  
  6365.    FIXME.  Also reject R_HPPA relocations which are 32bits wide in
  6366.    the code space.  The SOM BFD backend doesn't know how to pull the
  6367.    right bits out of an instruction.  */
  6368.  
  6369. int
  6370. hppa_fix_adjustable (fixp)
  6371.      fixS *fixp;
  6372. {
  6373.   struct hppa_fix_struct *hppa_fix;
  6374.  
  6375.   hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
  6376.  
  6377. #ifdef OBJ_SOM
  6378.   /* Reject reductions of symbols in 32bit relocs.  */
  6379.   if (fixp->fx_r_type == R_HPPA && hppa_fix->fx_r_format == 32)
  6380.     return 0;
  6381.  
  6382.   /* Reject reductions of symbols in sym1-sym2 expressions when
  6383.      the fixup will occur in a CODE subspace. 
  6384.  
  6385.      XXX FIXME: Long term we probably want to reject all of these;
  6386.      for example reducing in the debug section would lose if we ever
  6387.      supported using the optimizing hp linker.  */
  6388.   if (fixp->fx_addsy
  6389.       && fixp->fx_subsy
  6390.       && (hppa_fix->segment->flags & SEC_CODE))
  6391.     {
  6392.       /* Apparently sy_used_in_reloc never gets set for sub symbols.  */
  6393.       fixp->fx_subsy->sy_used_in_reloc = 1;
  6394.       return 0;
  6395.     }
  6396.  
  6397.   /* We can't adjust any relocs that use LR% and RR% field selectors.
  6398.      That confuses the HP linker.  */
  6399.   if (hppa_fix->fx_r_field == e_lrsel
  6400.       || hppa_fix->fx_r_field == e_rrsel
  6401.       || hppa_fix->fx_r_field == e_nlrsel)
  6402.     return 0;
  6403. #endif
  6404.  
  6405.   /* Reject reductions of symbols in DLT relative relocs,
  6406.      relocations with plabels.  */
  6407.   if (hppa_fix->fx_r_field == e_tsel
  6408.       || hppa_fix->fx_r_field == e_ltsel
  6409.       || hppa_fix->fx_r_field == e_rtsel
  6410.       || hppa_fix->fx_r_field == e_psel
  6411.       || hppa_fix->fx_r_field == e_rpsel
  6412.       || hppa_fix->fx_r_field == e_lpsel)
  6413.     return 0;
  6414.  
  6415.   if (fixp->fx_addsy && fixp->fx_addsy->bsym->flags & BSF_GLOBAL)
  6416.     return 0;
  6417.  
  6418.   /* Reject reductions of function symbols.  */
  6419.   if (fixp->fx_addsy == 0
  6420.       || (fixp->fx_addsy->bsym->flags & BSF_FUNCTION) == 0)
  6421.     return 1;
  6422.  
  6423.   return 0;
  6424. }
  6425.  
  6426. /* Return nonzero if the fixup in FIXP will require a relocation,
  6427.    even it if appears that the fixup could be completely handled
  6428.    within GAS.  */
  6429.  
  6430. int
  6431. hppa_force_relocation (fixp)
  6432.      fixS *fixp;
  6433. {
  6434.   struct hppa_fix_struct *hppa_fixp;
  6435.   int distance;
  6436.  
  6437.   hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
  6438. #ifdef OBJ_SOM
  6439.   if (fixp->fx_r_type == R_HPPA_ENTRY || fixp->fx_r_type == R_HPPA_EXIT
  6440.       || fixp->fx_r_type == R_HPPA_BEGIN_BRTAB
  6441.       || fixp->fx_r_type == R_HPPA_END_BRTAB
  6442.       || fixp->fx_r_type == R_HPPA_BEGIN_TRY
  6443.       || fixp->fx_r_type == R_HPPA_END_TRY
  6444.       || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
  6445.       && (hppa_fixp->segment->flags & SEC_CODE) != 0))
  6446.     return 1;
  6447. #endif
  6448.  
  6449. #define arg_reloc_stub_needed(CALLER, CALLEE) \
  6450.   ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
  6451.  
  6452.   /* It is necessary to force PC-relative calls/jumps to have a relocation
  6453.      entry if they're going to need either a argument relocation or long
  6454.      call stub.  FIXME.  Can't we need the same for absolute calls?  */
  6455.   if (fixp->fx_pcrel && fixp->fx_addsy
  6456.       && (arg_reloc_stub_needed (((obj_symbol_type *)
  6457.                   fixp->fx_addsy->bsym)->tc_data.hppa_arg_reloc,
  6458.  
  6459.                  hppa_fixp->fx_arg_reloc)))
  6460.     return 1;
  6461.   distance = (fixp->fx_offset + S_GET_VALUE (fixp->fx_addsy)
  6462.           - md_pcrel_from (fixp));
  6463.   /* Now check and see if we're going to need a long-branch stub.  */
  6464.   if (fixp->fx_r_type == R_HPPA_PCREL_CALL
  6465.       && (distance > 262143 || distance < -262144))
  6466.     return 1;
  6467.  
  6468. #undef arg_reloc_stub_needed
  6469.  
  6470.   /* No need (yet) to force another relocations to be emitted.  */
  6471.   return 0;
  6472. }
  6473.  
  6474. /* Now for some ELF specific code.  FIXME.  */
  6475. #ifdef OBJ_ELF
  6476. /* Mark the end of a function so that it's possible to compute
  6477.    the size of the function in hppa_elf_final_processing.  */
  6478.  
  6479. static void
  6480. hppa_elf_mark_end_of_function ()
  6481. {
  6482.   /* ELF does not have EXIT relocations.  All we do is create a
  6483.      temporary symbol marking the end of the function.  */
  6484.   char *name = (char *)
  6485.     xmalloc (strlen ("L$\001end_") +
  6486.          strlen (S_GET_NAME (last_call_info->start_symbol)) + 1);
  6487.  
  6488.   if (name)
  6489.     {
  6490.       symbolS *symbolP;
  6491.  
  6492.       strcpy (name, "L$\001end_");
  6493.       strcat (name, S_GET_NAME (last_call_info->start_symbol));
  6494.  
  6495.       /* If we have a .exit followed by a .procend, then the
  6496.      symbol will have already been defined.  */
  6497.       symbolP = symbol_find (name);
  6498.       if (symbolP)
  6499.     {
  6500.       /* The symbol has already been defined!  This can
  6501.          happen if we have a .exit followed by a .procend.
  6502.  
  6503.          This is *not* an error.  All we want to do is free
  6504.          the memory we just allocated for the name and continue.  */
  6505.       xfree (name);
  6506.     }
  6507.       else
  6508.     {
  6509.       /* symbol value should be the offset of the
  6510.          last instruction of the function */
  6511.       symbolP = symbol_new (name, now_seg, (valueT) (frag_now_fix () - 4),
  6512.                 frag_now);
  6513.  
  6514.       assert (symbolP);
  6515.       symbolP->bsym->flags = BSF_LOCAL;
  6516.       symbol_table_insert (symbolP);
  6517.     }
  6518.  
  6519.       if (symbolP)
  6520.     last_call_info->end_symbol = symbolP;
  6521.       else
  6522.     as_bad ("Symbol '%s' could not be created.", name);
  6523.  
  6524.     }
  6525.   else
  6526.     as_bad ("No memory for symbol name.");
  6527.  
  6528. }
  6529.  
  6530. /* For ELF, this function serves one purpose:  to setup the st_size
  6531.    field of STT_FUNC symbols.  To do this, we need to scan the
  6532.    call_info structure list, determining st_size in by taking the
  6533.    difference in the address of the beginning/end marker symbols.  */
  6534.  
  6535. void
  6536. elf_hppa_final_processing ()
  6537. {
  6538.   struct call_info *call_info_pointer;
  6539.  
  6540.   for (call_info_pointer = call_info_root;
  6541.        call_info_pointer;
  6542.        call_info_pointer = call_info_pointer->ci_next)
  6543.     {
  6544.       elf_symbol_type *esym
  6545.       = (elf_symbol_type *) call_info_pointer->start_symbol->bsym;
  6546.       esym->internal_elf_sym.st_size =
  6547.     S_GET_VALUE (call_info_pointer->end_symbol)
  6548.     - S_GET_VALUE (call_info_pointer->start_symbol) + 4;
  6549.     }
  6550. }
  6551. #endif
  6552.