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