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