Update copyright years
[deliverable/binutils-gdb.git] / gas / config / tc-hppa.c
1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989-2014 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to the Free
18 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
19 02110-1301, USA. */
20
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
23
24 #include "as.h"
25 #include "safe-ctype.h"
26 #include "subsegs.h"
27 #include "dw2gencfi.h"
28
29 #include "bfd/libhppa.h"
30
31 /* Be careful, this file includes data *declarations*. */
32 #include "opcode/hppa.h"
33
34 #if defined (OBJ_ELF) && defined (OBJ_SOM)
35 error only one of OBJ_ELF and OBJ_SOM can be defined
36 #endif
37
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"
43
44 /* A "convenient" place to put object file dependencies which do
45 not need to be seen outside of tc-hppa.c. */
46
47 /* Object file formats specify relocation types. */
48 typedef enum elf_hppa_reloc_type reloc_type;
49
50 /* Object file formats specify BFD symbol types. */
51 typedef elf_symbol_type obj_symbol_type;
52 #define symbol_arg_reloc_info(sym)\
53 (((obj_symbol_type *) symbol_get_bfdsym (sym))->tc_data.hppa_arg_reloc)
54
55 #if TARGET_ARCH_SIZE == 64
56 /* How to generate a relocation. */
57 #define hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type
58 #define elf_hppa_reloc_final_type elf64_hppa_reloc_final_type
59 #else
60 #define hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type
61 #define elf_hppa_reloc_final_type elf32_hppa_reloc_final_type
62 #endif
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
68
69 #define UNWIND_SECTION_NAME ".PARISC.unwind"
70 #endif /* OBJ_ELF */
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. */
80 typedef 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
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. */
90 typedef som_symbol_type obj_symbol_type;
91 #define symbol_arg_reloc_info(sym)\
92 (((obj_symbol_type *) symbol_get_bfdsym (sym))->tc_data.ap.hppa_arg_reloc)
93
94 /* This apparently isn't in older versions of hpux reloc.h. */
95 #ifndef R_DLT_REL
96 #define R_DLT_REL 0x78
97 #endif
98
99 #ifndef R_N0SEL
100 #define R_N0SEL 0xd8
101 #endif
102
103 #ifndef R_N1SEL
104 #define R_N1SEL 0xd9
105 #endif
106 #endif /* OBJ_SOM */
107
108 #if TARGET_ARCH_SIZE == 64
109 #define DEFAULT_LEVEL 25
110 #else
111 #define DEFAULT_LEVEL 10
112 #endif
113
114 /* Various structures and types used internally in tc-hppa.c. */
115
116 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
117
118 struct 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
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
167 struct 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
186 struct 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). */
204 typedef enum
205 {
206 SGL, DBL, ILLEGAL_FMT, QUAD, W, UW, DW, UDW, QW, UQW
207 }
208 fp_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). */
213 typedef 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 }
225 pa_symbol_type;
226
227 /* This structure contains information needed to assemble
228 individual instructions. */
229 struct 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
244 /* Whether or not we saw a truncation request on an fcnv insn. */
245 int trunc;
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). */
253 unsigned int arg_reloc;
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
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 |
280 +--------------+--------------+ */
281
282 /* Additional information needed to build argument relocation stubs. */
283 struct 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
292 #ifdef OBJ_SOM
293 /* This structure defines an entry in the subspace dictionary
294 chain. */
295
296 struct 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
312 typedef struct subspace_dictionary_chain ssd_chain_struct;
313
314 /* This structure defines an entry in the subspace dictionary
315 chain. */
316
317 struct 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
345 typedef struct space_dictionary_chain sd_chain_struct;
346
347 /* This structure defines attributes of the default subspace
348 dictionary entries. */
349
350 struct 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
364 /* Nonzero if this is a comdat subspace. */
365 char comdat;
366
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
396 /* Subsegment associated with this subspace. */
397 subsegT subsegment;
398 };
399
400 /* This structure defines attributes of the default space
401 dictionary entries. */
402
403 struct 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;
426 };
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. */
432 typedef 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 }
443 label_symbol_struct;
444
445 /* Extra information needed to perform fixups (relocations) on the PA. */
446 struct 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. */
458 unsigned int fx_arg_reloc;
459
460 /* The segment this fixup appears in. */
461 segT segment;
462 };
463
464 /* Structure to hold information about predefined registers. */
465
466 struct 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. */
474 struct 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. */
482 struct selector_entry
483 {
484 char *prefix;
485 int field_selector;
486 };
487
488 /* Prototypes for functions local to tc-hppa.c. */
489
490 #ifdef OBJ_SOM
491 static void pa_check_current_space_and_subspace (void);
492 #endif
493
494 #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
495 static void pa_text (int);
496 static void pa_data (int);
497 static void pa_comm (int);
498 #endif
499 #ifdef OBJ_SOM
500 static int exact_log2 (int);
501 static void pa_compiler (int);
502 static void pa_align (int);
503 static void pa_space (int);
504 static void pa_spnum (int);
505 static void pa_subspace (int);
506 static sd_chain_struct *create_new_space (char *, int, int,
507 int, int, int,
508 asection *, int);
509 static ssd_chain_struct *create_new_subspace (sd_chain_struct *,
510 char *, int, int,
511 int, int, int, int,
512 int, int, int, int,
513 int, asection *);
514 static ssd_chain_struct *update_subspace (sd_chain_struct *,
515 char *, int, int, int,
516 int, int, int, int,
517 int, int, int, int,
518 asection *);
519 static sd_chain_struct *is_defined_space (char *);
520 static ssd_chain_struct *is_defined_subspace (char *);
521 static sd_chain_struct *pa_segment_to_space (asection *);
522 static ssd_chain_struct *pa_subsegment_to_subspace (asection *,
523 subsegT);
524 static sd_chain_struct *pa_find_space_by_number (int);
525 static unsigned int pa_subspace_start (sd_chain_struct *, int);
526 static sd_chain_struct *pa_parse_space_stmt (char *, int);
527 #endif
528
529 /* File and globally scoped variable declarations. */
530
531 #ifdef OBJ_SOM
532 /* Root and final entry in the space chain. */
533 static sd_chain_struct *space_dict_root;
534 static sd_chain_struct *space_dict_last;
535
536 /* The current space and subspace. */
537 static sd_chain_struct *current_space;
538 static ssd_chain_struct *current_subspace;
539 #endif
540
541 /* Root of the call_info chain. */
542 static 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. */
547 static struct call_info *last_call_info;
548
549 /* The last call description (for actual calls). */
550 static struct call_desc last_call_desc;
551
552 /* handle of the OPCODE hash table */
553 static struct hash_control *op_hash = NULL;
554
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. */
558 const char hppa_symbol_chars[] = "*?=<>";
559
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
568 Also note that C style comments will always work. */
569 const char line_comment_chars[] = "#";
570
571 /* This array holds the chars that always start a comment. If the
572 pre-processor is disabled, these aren't very useful. */
573 const char comment_chars[] = ";";
574
575 /* This array holds the characters which act as line separators. */
576 const char line_separator_chars[] = "!";
577
578 /* Chars that can be used to separate mant from exp in floating point nums. */
579 const 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
585 changed in read.c. Ideally it shouldn't have to know about it
586 at all, but nothing is ideal around here. */
587 const char FLT_CHARS[] = "rRsSfFdDxXpP";
588
589 static struct pa_it the_insn;
590
591 /* Points to the end of an expression just parsed by get_expression
592 and friends. FIXME. This shouldn't be handled with a file-global
593 variable. */
594 static char *expr_end;
595
596 /* Nonzero if a .callinfo appeared within the current procedure. */
597 static int callinfo_found;
598
599 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
600 static int within_entry_exit;
601
602 /* Nonzero if the assembler is currently within a procedure definition. */
603 static int within_procedure;
604
605 /* Handle on structure which keep track of the last symbol
606 seen in each subspace. */
607 static label_symbol_struct *label_symbols_rootp = NULL;
608
609 /* Holds the last field selector. */
610 static int hppa_field_selector;
611
612 /* Nonzero when strict matching is enabled. Zero otherwise.
613
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. */
620 static int strict;
621
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
629 static int pa_number;
630
631 #ifdef OBJ_SOM
632 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
633 static symbolS *dummy_symbol;
634 #endif
635
636 /* Nonzero if errors are to be printed. */
637 static 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
656 %fr4 - %fr7 have %farg0 - %farg3 as synonyms
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
664 The table is sorted. Suitable for searching by a binary search. */
665
666 static const struct pd_reg pre_defined_registers[] =
667 {
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},
700 {"%farg0", 4 + FP_REG_BASE},
701 {"%farg1", 5 + FP_REG_BASE},
702 {"%farg2", 6 + FP_REG_BASE},
703 {"%farg3", 7 + FP_REG_BASE},
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},
800 {"%fret", 4},
801 {"%hta", 25},
802 {"%iir", 19},
803 {"%ior", 21},
804 {"%ipsw", 22},
805 {"%isr", 20},
806 {"%itmr", 16},
807 {"%iva", 14},
808 #if TARGET_ARCH_SIZE == 64
809 {"%mrp", 2},
810 #else
811 {"%mrp", 31},
812 #endif
813 {"%pcoq", 18},
814 {"%pcsq", 17},
815 {"%pidr1", 8},
816 {"%pidr2", 9},
817 {"%pidr3", 12},
818 {"%pidr4", 13},
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},
866 {"%t1", 22},
867 {"%t2", 21},
868 {"%t3", 20},
869 {"%t4", 19},
870 {"%tf1", 11},
871 {"%tf2", 10},
872 {"%tf3", 9},
873 {"%tf4", 8},
874 {"%tr0", 24},
875 {"%tr1", 25},
876 {"%tr2", 26},
877 {"%tr3", 27},
878 {"%tr4", 28},
879 {"%tr5", 29},
880 {"%tr6", 30},
881 {"%tr7", 31}
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. */
887 static 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
923 static 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},
932 {"ltp", e_ltpsel},
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},
943 {"rtp", e_rtpsel},
944 {"t", e_tsel},
945 };
946
947 #ifdef OBJ_SOM
948 /* default space and subspace dictionaries */
949
950 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
951 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
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
963 static struct default_subspace_dict pa_def_subspaces[] =
964 {
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}
971 };
972
973 static struct default_space_dict pa_def_spaces[] =
974 {
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}
978 };
979
980 /* Misc local definitions used by the assembler. */
981
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
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')
996
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
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
1019 /* Simple range checking for FIELD against HIGH and LOW bounds.
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) \
1027 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1028 (int) (FIELD));\
1029 break; \
1030 } \
1031 }
1032
1033 /* Variant of CHECK_FIELD for use in md_apply_fix and other places where
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 { \
1040 as_bad_where ((FILENAME), (LINE), \
1041 _("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1042 (int) (FIELD));\
1043 break; \
1044 } \
1045 }
1046
1047 /* Simple alignment checking for FIELD against ALIGN (a power of two).
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) \
1055 as_bad (_("Field not properly aligned [%d] (%d)."), (ALIGN), \
1056 (int) (FIELD));\
1057 break; \
1058 } \
1059 }
1060
1061 #define is_DP_relative(exp) \
1062 ((exp).X_op == O_subtract \
1063 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
1064
1065 #define is_SB_relative(exp) \
1066 ((exp).X_op == O_subtract \
1067 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$segrel$") == 0)
1068
1069 #define is_PC_relative(exp) \
1070 ((exp).X_op == O_subtract \
1071 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
1072
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
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
1104 void
1105 pa_check_eof (void)
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
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
1117 static label_symbol_struct *
1118 pa_get_label (void)
1119 {
1120 label_symbol_struct *label_chain;
1121
1122 for (label_chain = label_symbols_rootp;
1123 label_chain;
1124 label_chain = label_chain->lss_next)
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)
1132 return label_chain;
1133 #endif
1134 }
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
1142 void
1143 pa_define_label (symbolS *symbol)
1144 {
1145 label_symbol_struct *label_chain = pa_get_label ();
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. */
1152 label_chain = xmalloc (sizeof (label_symbol_struct));
1153 label_chain->lss_label = symbol;
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
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 }
1167
1168 #ifdef OBJ_ELF
1169 dwarf2_emit_label (symbol);
1170 #endif
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
1176 static void
1177 pa_undefine_label (void)
1178 {
1179 label_symbol_struct *label_chain;
1180 label_symbol_struct *prev_label_chain = NULL;
1181
1182 for (label_chain = label_symbols_rootp;
1183 label_chain;
1184 label_chain = label_chain->lss_next)
1185 {
1186 if (1
1187 #ifdef OBJ_SOM
1188 && current_space == label_chain->lss_space && label_chain->lss_label
1189 #endif
1190 #ifdef OBJ_ELF
1191 && now_seg == label_chain->lss_segment && label_chain->lss_label
1192 #endif
1193 )
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
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
1215 static void
1216 fix_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)
1228 {
1229 fixS *new_fix;
1230 struct hppa_fix_struct *hppa_fix = obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
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)
1244 new_fix->fx_offset = unwind_bits;
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
1249 it now so as not to confuse write.c. Ditto for $PIC_pcrel$0. */
1250 if (new_fix->fx_subsy
1251 && (strcmp (S_GET_NAME (new_fix->fx_subsy), "$global$") == 0
1252 || strcmp (S_GET_NAME (new_fix->fx_subsy), "$segrel$") == 0
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))
1259 new_fix->fx_subsy = NULL;
1260 }
1261
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
1265 void
1266 cons_fix_new_hppa (fragS *frag, int where, int size, expressionS *exp)
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;
1273 else if (is_PC_relative (*exp))
1274 rel_type = R_HPPA_PCREL_CALL;
1275 #ifdef OBJ_ELF
1276 else if (is_SB_relative (*exp))
1277 rel_type = R_PARISC_SEGREL32;
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
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)
1295 {
1296 as_warn (_("Invalid field selector. Assuming F%%."));
1297 hppa_field_selector = e_fsel;
1298 }
1299
1300 fix_new_hppa (frag, where, size,
1301 (symbolS *) NULL, (offsetT) 0, exp, 0, rel_type,
1302 hppa_field_selector, size * 8, 0, 0);
1303
1304 /* Reset field selector to its default state. */
1305 hppa_field_selector = 0;
1306 }
1307
1308 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
1309
1310 static void
1311 get_expression (char *str)
1312 {
1313 char *save_in;
1314 asection *seg;
1315
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)))
1322 {
1323 as_warn (_("Bad segment in expression."));
1324 expr_end = input_line_pointer;
1325 input_line_pointer = save_in;
1326 return;
1327 }
1328 expr_end = input_line_pointer;
1329 input_line_pointer = save_in;
1330 }
1331
1332 /* Parse a PA nullification completer (,n). Return nonzero if the
1333 completer was found; return zero if no completer was found. */
1334
1335 static int
1336 pa_parse_nullif (char **s)
1337 {
1338 int nullif;
1339
1340 nullif = 0;
1341 if (**s == ',')
1342 {
1343 *s = *s + 1;
1344 if (strncasecmp (*s, "n", 1) == 0)
1345 nullif = 1;
1346 else
1347 {
1348 as_bad (_("Invalid Nullification: (%c)"), **s);
1349 nullif = 0;
1350 }
1351 *s = *s + 1;
1352 }
1353
1354 return nullif;
1355 }
1356
1357 char *
1358 md_atof (int type, char *litP, int *sizeP)
1359 {
1360 return ieee_md_atof (type, litP, sizeP, TRUE);
1361 }
1362
1363 /* Write out big-endian. */
1364
1365 void
1366 md_number_to_chars (char *buf, valueT val, int n)
1367 {
1368 number_to_chars_bigendian (buf, val, n);
1369 }
1370
1371 /* Translate internal representation of relocation info to BFD target
1372 format. */
1373
1374 arelent **
1375 tc_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;
1385
1386 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
1387 if (fixp->fx_addsy == 0)
1388 return &no_relocs;
1389
1390 gas_assert (hppa_fixp != 0);
1391 gas_assert (section != 0);
1392
1393 reloc = xmalloc (sizeof (arelent));
1394
1395 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
1396 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
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. */
1403 if (fixp->fx_r_type == (bfd_reloc_code_real_type) R_HPPA_COMPLEX
1404 && fixp->fx_pcrel)
1405 {
1406 fixp->fx_r_type = R_HPPA_PCREL_CALL;
1407 fixp->fx_offset += 8;
1408 }
1409
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));
1416
1417 if (codes == NULL)
1418 {
1419 as_bad_where (fixp->fx_file, fixp->fx_line, _("Cannot handle fixup"));
1420 abort ();
1421 }
1422
1423 for (n_relocs = 0; codes[n_relocs]; n_relocs++)
1424 ;
1425
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];
1430
1431 relocs[n_relocs] = NULL;
1432
1433 #ifdef OBJ_ELF
1434 switch (fixp->fx_r_type)
1435 {
1436 default:
1437 gas_assert (n_relocs == 1);
1438
1439 code = *codes[0];
1440
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.
1454
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;
1460
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
1473
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 */
1479
1480 default:
1481 reloc->addend = fixp->fx_offset;
1482 break;
1483 }
1484
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;
1490
1491 gas_assert (reloc->howto && (unsigned int) code == reloc->howto->type);
1492 break;
1493 }
1494 #else /* OBJ_SOM */
1495
1496 /* Walk over reach relocation returned by the BFD backend. */
1497 for (i = 0; i < n_relocs; i++)
1498 {
1499 code = *codes[i];
1500
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;
1507
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. */
1514 gas_assert (i == 1);
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;
1555
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).
1562
1563 FIXME: We always assume no static link!
1564
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;
1570
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;
1588
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;
1597
1598 default:
1599 relocs[i]->addend = fixp->fx_offset;
1600 }
1601 }
1602
1603 done:
1604 #endif
1605
1606 return relocs;
1607 }
1608
1609 /* Process any machine dependent frag types. */
1610
1611 void
1612 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
1613 asection *sec ATTRIBUTE_UNUSED,
1614 fragS *fragP)
1615 {
1616 unsigned int address;
1617
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 }
1640
1641 /* Round up a section size to the appropriate boundary. */
1642
1643 valueT
1644 md_section_align (asection *segment, valueT size)
1645 {
1646 int align = bfd_get_section_alignment (stdoutput, segment);
1647 int align2 = (1 << align) - 1;
1648
1649 return (size + align2) & ~align2;
1650 }
1651
1652 /* Return the approximate size of a frag before relaxation has occurred. */
1653
1654 int
1655 md_estimate_size_before_relax (fragS *fragP, asection *segment ATTRIBUTE_UNUSED)
1656 {
1657 int size;
1658
1659 size = 0;
1660
1661 while ((fragP->fr_fix + size) % fragP->fr_offset)
1662 size++;
1663
1664 return size;
1665 }
1666 \f
1667 #ifdef OBJ_ELF
1668 # ifdef WARN_COMMENTS
1669 const char *md_shortopts = "Vc";
1670 # else
1671 const char *md_shortopts = "V";
1672 # endif
1673 #else
1674 # ifdef WARN_COMMENTS
1675 const char *md_shortopts = "c";
1676 # else
1677 const char *md_shortopts = "";
1678 # endif
1679 #endif
1680
1681 struct option md_longopts[] =
1682 {
1683 #ifdef WARN_COMMENTS
1684 {"warn-comment", no_argument, NULL, 'c'},
1685 #endif
1686 {NULL, no_argument, NULL, 0}
1687 };
1688 size_t md_longopts_size = sizeof (md_longopts);
1689
1690 int
1691 md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
1692 {
1693 switch (c)
1694 {
1695 default:
1696 return 0;
1697
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 }
1709
1710 return 1;
1711 }
1712
1713 void
1714 md_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. */
1727
1728 symbolS *
1729 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
1730 {
1731 return NULL;
1732 }
1733
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
1742
1743 /* Apply a fixup to an instruction. */
1744
1745 void
1746 md_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;
1752
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;
1763
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
1778
1779 if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1780 fixP->fx_done = 1;
1781
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 }
1791
1792 fixpos = fixP->fx_frag->fr_literal + fixP->fx_where;
1793
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 }
1800
1801 insn = bfd_get_32 (stdoutput, fixpos);
1802 fmt = bfd_hppa_insn2fmt (stdoutput, insn);
1803
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);
1827
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 }
1851
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;
1858
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;
1866
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;
1875
1876 insn = ((insn & ~ 0x3fff) | low_sign_unext (val, 14));
1877 break;
1878
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;
1884
1885 insn = (insn & ~ 0x1fffff) | re_assemble_21 (val);
1886 break;
1887
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;
1893
1894 insn = (insn & ~ 0x7ff) | low_sign_unext (val, 11);
1895 break;
1896
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;
1902
1903 insn = (insn & ~ 0x1ffd) | re_assemble_12 (val >> 2);
1904 break;
1905
1906 /* Handle some of the opcodes with the 'W' operand type. */
1907 case 17:
1908 {
1909 offsetT distance = * valP;
1910
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);
1917
1918 CHECK_FIELD_WHERE (new_val - 8, 262143, -262144,
1919 fixP->fx_file, fixP->fx_line);
1920 val = new_val - 8;
1921
1922 insn = (insn & ~ 0x1f1ffd) | re_assemble_17 (val >> 2);
1923 break;
1924 }
1925
1926 case 22:
1927 {
1928 offsetT distance = * valP;
1929
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);
1936
1937 CHECK_FIELD_WHERE (new_val - 8, 8388607, -8388608,
1938 fixP->fx_file, fixP->fx_line);
1939 val = new_val - 8;
1940
1941 insn = (insn & ~ 0x3ff1ffd) | re_assemble_22 (val >> 2);
1942 break;
1943 }
1944
1945 case -10:
1946 val = new_val;
1947 insn = (insn & ~ 0xfff1) | re_assemble_16 (val & -8);
1948 break;
1949
1950 case -16:
1951 val = new_val;
1952 insn = (insn & ~ 0xfff9) | re_assemble_16 (val & -4);
1953 break;
1954
1955 case 16:
1956 val = new_val;
1957 insn = (insn & ~ 0xffff) | re_assemble_16 (val);
1958 break;
1959
1960 case 32:
1961 insn = new_val;
1962 break;
1963
1964 default:
1965 as_bad_where (fixP->fx_file, fixP->fx_line,
1966 _("Unknown relocation encountered in md_apply_fix."));
1967 return;
1968 }
1969
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:
1981 if (fixP->fx_addsy)
1982 S_SET_THREAD_LOCAL (fixP->fx_addsy);
1983 break;
1984 default:
1985 break;
1986 }
1987 #endif
1988
1989 /* Insert the relocation. */
1990 bfd_put_32 (stdoutput, insn, fixpos);
1991 }
1992
1993 /* Exactly what point is a PC-relative offset relative TO?
1994 On the PA, they're relative to the address of the offset. */
1995
1996 long
1997 md_pcrel_from (fixS *fixP)
1998 {
1999 return fixP->fx_where + fixP->fx_frag->fr_address;
2000 }
2001
2002 /* Return nonzero if the input line pointer is at the end of
2003 a statement. */
2004
2005 static int
2006 is_end_of_statement (void)
2007 {
2008 return ((*input_line_pointer == '\n')
2009 || (*input_line_pointer == ';')
2010 || (*input_line_pointer == '!'));
2011 }
2012
2013 #define REG_NAME_CNT (sizeof (pre_defined_registers) / sizeof (struct pd_reg))
2014
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. */
2017
2018 static int
2019 reg_name_search (char *name)
2020 {
2021 int middle, low, high;
2022 int cmp;
2023
2024 low = 0;
2025 high = REG_NAME_CNT - 1;
2026
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);
2039
2040 return -1;
2041 }
2042
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.
2046
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'.
2050
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.
2054
2055 pa_parse_number can not handle negative constants and will fail
2056 horribly if it is passed such a constant. */
2057
2058 static int
2059 pa_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;
2068
2069 /* Skip whitespace before the number. */
2070 while (*p == ' ' || *p == '\t')
2071 p = p + 1;
2072
2073 pa_number = -1;
2074 have_prefix = 0;
2075 num = 0;
2076 if (!strict && ISDIGIT (*p))
2077 {
2078 /* Looks like a number. */
2079
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 }
2105
2106 pa_number = num;
2107
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
2134 code makes a binary search with case translation, and is VERY
2135 slow. */
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 }
2184
2185 pa_number = num;
2186 }
2187 else
2188 {
2189 /* And finally, it could be a symbol in the absolute section which
2190 is effectively a constant, or a register alias symbol. */
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 }
2208 else if (S_GET_SEGMENT (sym) == bfd_abs_section_ptr)
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;
2233
2234 pa_number = num;
2235 }
2236
2237 if (!strict || have_prefix)
2238 {
2239 *s = p;
2240 return 1;
2241 }
2242 return 0;
2243 }
2244
2245 /* Return nonzero if the given INSN and L/R information will require
2246 a new PA-1.1 opcode. */
2247
2248 static int
2249 need_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 }
2266
2267 /* Parse a condition for a fcmp instruction. Return the numerical
2268 code associated with the condition. */
2269
2270 static int
2271 pa_parse_fp_cmp_cond (char **s)
2272 {
2273 int cond, i;
2274
2275 cond = 0;
2276
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 }
2296
2297 as_bad (_("Invalid FP Compare Condition: %s"), *s);
2298
2299 /* Advance over the bogus completer. */
2300 while (**s != ',' && **s != ' ' && **s != '\t')
2301 *s += 1;
2302
2303 return 0;
2304 }
2305
2306 /* Parse a graphics test complete for ftest. */
2307
2308 static int
2309 pa_parse_ftest_gfx_completer (char **s)
2310 {
2311 int value;
2312
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 }
2354
2355 return value;
2356 }
2357
2358 /* Parse an FP operand format completer returning the completer
2359 type. */
2360
2361 static fp_operand_format
2362 pa_parse_fp_cnv_format (char **s)
2363 {
2364 int format;
2365
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 }
2421
2422 return format;
2423 }
2424
2425 /* Parse an FP operand format completer returning the completer
2426 type. */
2427
2428 static fp_operand_format
2429 pa_parse_fp_format (char **s)
2430 {
2431 int format;
2432
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 }
2458
2459 return format;
2460 }
2461
2462 /* Convert from a selector string into a selector type. */
2463
2464 static int
2465 pa_chk_field_selector (char **str)
2466 {
2467 int middle, low, high;
2468 int cmp;
2469 char name[4];
2470
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;
2475
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;
2490
2491 low = 0;
2492 high = sizeof (selector_table) / sizeof (struct selector_entry) - 1;
2493
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);
2513
2514 return e_fsel;
2515 }
2516
2517 /* Parse a .byte, .word, .long expression for the HPPA. Called by
2518 cons via the TC_PARSE_CONS_EXPRESSION macro. */
2519
2520 void
2521 parse_cons_expression_hppa (expressionS *exp)
2522 {
2523 hppa_field_selector = pa_chk_field_selector (&input_line_pointer);
2524 expression (exp);
2525 }
2526
2527 /* Evaluate an absolute expression EXP which may be modified by
2528 the selector FIELD_SELECTOR. Return the value of the expression. */
2529 static int
2530 evaluate_absolute (struct pa_it *insn)
2531 {
2532 offsetT value;
2533 expressionS exp;
2534 int field_selector = insn->field_selector;
2535
2536 exp = insn->exp;
2537 value = exp.X_add_number;
2538
2539 return hppa_field_adjust (0, value, field_selector);
2540 }
2541
2542 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
2543
2544 static int
2545 pa_get_absolute_expression (struct pa_it *insn, char **strp)
2546 {
2547 char *save_in;
2548
2549 insn->field_selector = pa_chk_field_selector (strp);
2550 save_in = input_line_pointer;
2551 input_line_pointer = *strp;
2552 expression (&insn->exp);
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
2568 static int
2569 pa_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;
2577
2578 /* The PA assembly syntax is ambiguous in a variety of ways. Consider
2579 this string "4 %r5" Is that the number 4 followed by the register
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.
2584
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. */
2588
2589 s = *strp;
2590 while (*s != ',' && *s != ' ' && *s != '\t')
2591 s++;
2592
2593 c = *s;
2594 *s = 0;
2595
2596 result = pa_get_absolute_expression (insn, strp);
2597
2598 input_line_pointer = save_in;
2599 *s = c;
2600 return result;
2601 }
2602
2603 /* Given an argument location specification return the associated
2604 argument location number. */
2605
2606 static unsigned int
2607 pa_build_arg_reloc (char *type_name)
2608 {
2609
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);
2620
2621 return 0;
2622 }
2623
2624 /* Encode and return an argument relocation specification for
2625 the given register in the location specified by arg_reloc. */
2626
2627 static unsigned int
2628 pa_align_arg_reloc (unsigned int reg, unsigned int arg_reloc)
2629 {
2630 unsigned int new_reloc;
2631
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 }
2650
2651 return new_reloc;
2652 }
2653
2654 /* Parse a non-negated compare/subtract completer returning the
2655 number (for encoding in instructions) of the given completer. */
2656
2657 static int
2658 pa_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;
2665
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;
2674
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
2704 completer. */
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 }
2716
2717 /* Reset pointers if this was really a ,n for a branch instruction. */
2718 if (nullify)
2719 *s = save_s;
2720
2721 return cmpltr;
2722 }
2723
2724 /* Parse a negated compare/subtract completer returning the
2725 number (for encoding in instructions) of the given completer. */
2726
2727 static int
2728 pa_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;
2735
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;
2744
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
2778 completer. */
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 }
2790
2791 /* Reset pointers if this was really a ,n for a branch instruction. */
2792 if (nullify)
2793 *s = save_s;
2794
2795 return cmpltr;
2796 }
2797
2798 /* Parse a 64 bit compare and branch completer returning the number (for
2799 encoding in instructions) of the given completer.
2800
2801 Nonnegated comparisons are returned as 0-7, negated comparisons are
2802 returned as 8-15. */
2803
2804 static int
2805 pa_parse_cmpb_64_cmpltr (char **s)
2806 {
2807 int cmpltr;
2808 char *name = *s + 1;
2809 char c;
2810
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;
2819
2820 if (strcmp (name, "*") == 0)
2821 {
2822 cmpltr = 0;
2823 }
2824 else if (strcmp (name, "*=") == 0)
2825 {
2826 cmpltr = 1;
2827 }
2828 else if (strcmp (name, "*<") == 0)
2829 {
2830 cmpltr = 2;
2831 }
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;
2889 }
2890
2891 return cmpltr;
2892 }
2893
2894 /* Parse a 64 bit compare immediate and branch completer returning the number
2895 (for encoding in instructions) of the given completer. */
2896
2897 static int
2898 pa_parse_cmpib_64_cmpltr (char **s)
2899 {
2900 int cmpltr;
2901 char *name = *s + 1;
2902 char c;
2903
2904 cmpltr = -1;
2905 if (**s == ',')
2906 {
2907 *s += 1;
2908 while (**s != ',' && **s != ' ' && **s != '\t')
2909 *s += 1;
2910 c = **s;
2911 **s = 0x00;
2912
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 }
2951
2952 return cmpltr;
2953 }
2954
2955 /* Parse a non-negated addition completer returning the number
2956 (for encoding in instructions) of the given completer. */
2957
2958 static int
2959 pa_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;
2966
2967 cmpltr = 0;
2968 if (**s == ',')
2969 {
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
3004 completer. */
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;
3015 }
3016
3017 /* Reset pointers if this was really a ,n for a branch instruction. */
3018 if (nullify)
3019 *s = save_s;
3020
3021 return cmpltr;
3022 }
3023
3024 /* Parse a negated addition completer returning the number
3025 (for encoding in instructions) of the given completer. */
3026
3027 static int
3028 pa_parse_neg_add_cmpltr (char **s)
3029 {
3030 int cmpltr;
3031 char *name = *s + 1;
3032 char c;
3033 char *save_s = *s;
3034 int nullify = 0;
3035
3036 cmpltr = 0;
3037 if (**s == ',')
3038 {
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
3077 completer. */
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;
3088 }
3089
3090 /* Reset pointers if this was really a ,n for a branch instruction. */
3091 if (nullify)
3092 *s = save_s;
3093
3094 return cmpltr;
3095 }
3096
3097 /* Parse a 64 bit wide mode add and branch completer returning the number (for
3098 encoding in instructions) of the given completer. */
3099
3100 static int
3101 pa_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;
3108
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
3178 completer. */
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 }
3190
3191 /* Reset pointers if this was really a ,n for a branch instruction. */
3192 if (nullify)
3193 *s = save_s;
3194
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
3201 static void
3202 pa_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;
3209 int cmpltr, nullif, flag, cond, need_cond, num;
3210 int immediate_check = 0, pos = -1, len = -1;
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 ();
3217 #endif
3218
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);
3223
3224 /* Skip to something interesting. */
3225 for (s = str;
3226 ISUPPER (*s) || ISLOWER (*s) || (*s >= '0' && *s <= '3');
3227 ++s)
3228 ;
3229
3230 switch (*s)
3231 {
3232
3233 case '\0':
3234 break;
3235
3236 case ',':
3237 comma = 1;
3238
3239 /*FALLTHROUGH */
3240
3241 case ' ':
3242 *s++ = '\0';
3243 break;
3244
3245 default:
3246 as_bad (_("Unknown opcode: `%s'"), str);
3247 return;
3248 }
3249
3250 /* Look up the opcode in the hash table. */
3251 if ((insn = (struct pa_opcode *) hash_find (op_hash, str)) == NULL)
3252 {
3253 as_bad (_("Unknown opcode: `%s'"), str);
3254 return;
3255 }
3256
3257 if (comma)
3258 *--s = ',';
3259
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));
3269 need_cond = 1;
3270
3271 the_insn.reloc = R_HPPA_NONE;
3272
3273 if (insn->arch >= pa20
3274 && bfd_get_mach (stdoutput) < insn->arch)
3275 goto failed;
3276
3277 /* Build the opcode, checking as we go to make
3278 sure that the operands match. */
3279 for (args = insn->args;; ++args)
3280 {
3281 /* Absorb white space in instruction. */
3282 while (*s == ' ' || *s == '\t')
3283 s++;
3284
3285 switch (*args)
3286 {
3287 /* End of arguments. */
3288 case '\0':
3289 if (*s == '\0')
3290 match = TRUE;
3291 break;
3292
3293 case '+':
3294 if (*s == '+')
3295 {
3296 ++s;
3297 continue;
3298 }
3299 if (*s == '-')
3300 continue;
3301 break;
3302
3303 /* These must match exactly. */
3304 case '(':
3305 case ')':
3306 case ',':
3307 case ' ':
3308 if (*s++ == *args)
3309 continue;
3310 break;
3311
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);
3320
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;
3327
3328 if (!strncasecmp (s, "%sar", 4))
3329 {
3330 s += 4;
3331 continue;
3332 }
3333 else if (!strncasecmp (s, "%cr11", 5))
3334 {
3335 s += 5;
3336 continue;
3337 }
3338 break;
3339
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);
3347
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);
3355
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);
3364
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);
3372 SAVE_IMMEDIATE(num);
3373 INSERT_FIELD_AND_CONTINUE (opcode, 32 - num, 0);
3374
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);
3386
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);
3398
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);
3407
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);
3416
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);
3425
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);
3433
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;
3442
3443 /* Handle all completers. */
3444 case 'c':
3445 switch (*++args)
3446 {
3447
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 }
3486
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;
3524
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 {
3539 /* M bit is explicit in the major opcode. */
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 }
3551
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 }
3585
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);
3595
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);
3610
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);
3620
3621 /* Handle load ordering completer. */
3622 case 'o':
3623 if (strncmp (s, ",o", 2) != 0)
3624 break;
3625 s += 2;
3626 continue;
3627
3628 /* Handle a branch gate completer. */
3629 case 'g':
3630 if (strncasecmp (s, ",gate", 5) != 0)
3631 break;
3632 s += 5;
3633 continue;
3634
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;
3641
3642 /* Handle a branch link completer. */
3643 case 'l':
3644 if (strncasecmp (s, ",l", 2) != 0)
3645 break;
3646 s += 2;
3647 continue;
3648
3649 /* Handle a branch pop completer. */
3650 case 'P':
3651 if (strncasecmp (s, ",pop", 4) != 0)
3652 break;
3653 s += 4;
3654 continue;
3655
3656 /* Handle a local processor completer. */
3657 case 'L':
3658 if (strncasecmp (s, ",l", 2) != 0)
3659 break;
3660 s += 2;
3661 continue;
3662
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 }
3676
3677 INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
3678
3679 /* Handle MFCTL wide completer. */
3680 case 'W':
3681 if (strncasecmp (s, ",w", 2) != 0)
3682 break;
3683 s += 2;
3684 continue;
3685
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 }
3694
3695 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
3696
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;
3706
3707 INSERT_FIELD_AND_CONTINUE (opcode, flag, 5);
3708
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 }
3717
3718 INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
3719
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 }
3728
3729 INSERT_FIELD_AND_CONTINUE (opcode, flag, 10);
3730
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 }
3744
3745 INSERT_FIELD_AND_CONTINUE (opcode, flag, 10);
3746
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;
3763
3764 /* Condition is not required with "dc". */
3765 need_cond = 0;
3766 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3767
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;
3784
3785 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3786
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 }
3795
3796 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3797
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;
3814
3815 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3816
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;
3833
3834 /* Condition is not required with "db". */
3835 need_cond = 0;
3836 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3837
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;
3854
3855 INSERT_FIELD_AND_CONTINUE (opcode, flag, 11);
3856
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 }
3865
3866 INSERT_FIELD_AND_CONTINUE (opcode, flag, 6);
3867
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 }
3882
3883 INSERT_FIELD_AND_CONTINUE (opcode, sign, 10);
3884 }
3885
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"));
3897
3898 s++;
3899 INSERT_FIELD_AND_CONTINUE (opcode, lr, 13);
3900 }
3901 else
3902 as_bad (_("Invalid left/right combination completer"));
3903 break;
3904
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 }
3919
3920 INSERT_FIELD_AND_CONTINUE (opcode, sat, 6);
3921 }
3922
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++)
3935 {
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;
3960
3961 default:
3962 abort ();
3963 }
3964 break;
3965
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);
3976
3977 /* Handle an add condition. */
3978 case 'A':
3979 case 'a':
3980 cmpltr = 0;
3981 flag = 0;
3982 if (*s == ',')
3983 {
3984 s++;
3985
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;
3996
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 }
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
4066 opcode |= cmpltr << 13;
4067 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
4068
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);
4078
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);
4093
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);
4115
4116 /* Handle branch on bit conditions. */
4117 case 'B':
4118 case 'b':
4119 cmpltr = 0;
4120 if (*s == ',')
4121 {
4122 s++;
4123
4124 if (*args == 'B')
4125 {
4126 if (*s == '*')
4127 s++;
4128 else
4129 break;
4130 }
4131 else if (*s == '*')
4132 break;
4133
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
4145 as_bad (_("Invalid Branch On Bit Condition: %c"), *s);
4146 }
4147 else
4148 as_bad (_("Missing Branch On Bit Condition"));
4149
4150 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 15);
4151
4152 /* Handle a compare/subtract condition. */
4153 case 'S':
4154 case 's':
4155 cmpltr = 0;
4156 flag = 0;
4157 if (*s == ',')
4158 {
4159 s++;
4160
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;
4171
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 }
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
4242 opcode |= cmpltr << 13;
4243 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
4244
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);
4254
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 }
4274
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;
4288
4289 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr & 7, 13);
4290
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;
4297
4298 INSERT_FIELD_AND_CONTINUE (opcode, cmpltr, 13);
4299
4300 /* Handle a logical instruction condition. */
4301 case 'L':
4302 case 'l':
4303 cmpltr = 0;
4304 flag = 0;
4305 if (*s == ',')
4306 {
4307 s++;
4308
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;
4319
4320 name = s;
4321 while (*s != ',' && *s != ' ' && *s != '\t')
4322 s += 1;
4323 c = *s;
4324 *s = 0x00;
4325
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 }
4364 /* 32-bit is default for no condition. */
4365 else if (*args == 'L')
4366 break;
4367
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;
4376 /* Check immediate values in shift/extract/deposit
4377 * instructions if they will give undefined behaviour. */
4378 immediate_check = 1;
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 }
4426
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 {
4436 int uxor;
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
4450 /* The uxor instruction only supports unit conditions
4451 not involving carries. */
4452 uxor = (opcode & 0xfc000fc0) == 0x08000380;
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 }
4463 else if (!uxor && strncasecmp (s, "sdc", 3) == 0)
4464 {
4465 cmpltr = 4;
4466 s += 3;
4467 }
4468 else if (!uxor && strncasecmp (s, "sbc", 3) == 0)
4469 {
4470 cmpltr = 6;
4471 s += 3;
4472 }
4473 else if (!uxor && strncasecmp (s, "shc", 3) == 0)
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 }
4496 else if (!uxor && strncasecmp (s, "ndc", 3) == 0)
4497 {
4498 cmpltr = 4;
4499 flag = 1;
4500 s += 3;
4501 }
4502 else if (!uxor && strncasecmp (s, "nbc", 3) == 0)
4503 {
4504 cmpltr = 6;
4505 flag = 1;
4506 s += 3;
4507 }
4508 else if (!uxor && strncasecmp (s, "nhc", 3) == 0)
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 }
4520 else if (!uxor && strncasecmp (s, "swc", 3) == 0)
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 }
4532 else if (!uxor && strncasecmp (s, "nwc", 3) == 0)
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 }
4542 /* 32-bit is default for no condition. */
4543 else if (*args == 'U')
4544 break;
4545
4546 opcode |= cmpltr << 13;
4547 INSERT_FIELD_AND_CONTINUE (opcode, flag, 12);
4548
4549 default:
4550 abort ();
4551 }
4552 break;
4553 }
4554
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);
4559
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);
4564
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;
4574
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;
4589
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;
4604
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 }
4611
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;
4641 #endif
4642 else
4643 the_insn.reloc = R_HPPA;
4644 the_insn.format = 11;
4645 continue;
4646 }
4647
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;
4656
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;
4671
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;
4693
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;
4702
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;
4713
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;
4722
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;
4735
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;
4779
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 }
4820
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 }
4856
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 }
4892
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 }
4967
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 }
5005
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 }
5037
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 }
5068
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 }
5098
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 }
5129
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
5139 break;
5140
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;
5147
5148 /* Handle immediate value of 0 for ordered load/store instructions. */
5149 case '@':
5150 if (*s != '0')
5151 break;
5152 s++;
5153 continue;
5154
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);
5163
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);
5180 SAVE_IMMEDIATE(num);
5181 INSERT_FIELD_AND_CONTINUE (opcode, 31 - num, 5);
5182
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);
5190 SAVE_IMMEDIATE(num);
5191 num = 63 - num;
5192 opcode |= (num & 0x20) << 6;
5193 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
5194
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);
5203 SAVE_IMMEDIATE(num);
5204 num--;
5205 opcode |= (num & 0x20) << 3;
5206 num = 31 - (num & 0x1f);
5207 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
5208
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);
5216 SAVE_IMMEDIATE(num);
5217 num--;
5218 opcode |= (num & 0x20) << 7;
5219 num = 31 - (num & 0x1f);
5220 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
5221
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);
5229 SAVE_IMMEDIATE(num);
5230 INSERT_FIELD_AND_CONTINUE (opcode, num, 5);
5231
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);
5239 SAVE_IMMEDIATE(num);
5240 opcode |= (num & 0x20) << 6;
5241 INSERT_FIELD_AND_CONTINUE (opcode, num & 0x1f, 5);
5242
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);
5256
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);
5265
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);
5274
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);
5283
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);
5292
5293 /* Handle a 3 bit SFU identifier at 25. */
5294 case 'v':
5295 if (*s++ != ',')
5296 as_bad (_("Invalid SFU identifier"));
5297 num = pa_get_number (&the_insn, &s);
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);
5303
5304 /* Handle a 20 bit SOP field for spop0. */
5305 case 'O':
5306 num = pa_get_number (&the_insn, &s);
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);
5313
5314 /* Handle a 15bit SOP field for spop1. */
5315 case 'o':
5316 num = pa_get_number (&the_insn, &s);
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);
5322
5323 /* Handle a 10bit SOP field for spop3. */
5324 case '0':
5325 num = pa_get_number (&the_insn, &s);
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':
5335 num = pa_get_number (&the_insn, &s);
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"));
5347 num = pa_get_number (&the_insn, &s);
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);
5353
5354 /* Handle a 22bit SOP field for copr. */
5355 case '2':
5356 num = pa_get_number (&the_insn, &s);
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);
5363
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);
5382
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);
5439
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);
5445
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);
5453
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);
5459
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;
5471
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)
5482 {
5483 /* Float target register. */
5484 case 't':
5485 if (!pa_parse_number (&s, 3))
5486 break;
5487 /* RSEL should not be set. */
5488 if (pa_number & FP_REG_RSEL)
5489 break;
5490 num = pa_number - FP_REG_BASE;
5491 CHECK_FIELD (num, 31, 0, 0);
5492 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
5493
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;
5502
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;
5509
5510 opcode |= (pa_number & FP_REG_RSEL ? 1 << 6 : 0);
5511 continue;
5512 }
5513
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 }
5529
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 }
5542
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 }
5558
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 }
5570
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 }
5583
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 {
5613 if (num < 16)
5614 {
5615 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
5616 break;
5617 }
5618 num &= 0xF;
5619 num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
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 {
5633 if (num < 16)
5634 {
5635 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
5636 break;
5637 }
5638 num &= 0xF;
5639 num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
5640 }
5641 INSERT_FIELD_AND_CONTINUE (opcode, num, 0);
5642 }
5643
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 {
5653 if (num < 16)
5654 {
5655 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
5656 break;
5657 }
5658 num &= 0xF;
5659 num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
5660 }
5661 INSERT_FIELD_AND_CONTINUE (opcode, num, 6);
5662 }
5663
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 {
5673 if (num < 16)
5674 {
5675 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
5676 break;
5677 }
5678 num &= 0xF;
5679 num |= (pa_number & FP_REG_RSEL ? 1 << 4 : 0);
5680 }
5681 INSERT_FIELD_AND_CONTINUE (opcode, num, 11);
5682 }
5683
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 }
5699
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);
5707
5708 default:
5709 abort ();
5710 }
5711 break;
5712
5713 default:
5714 abort ();
5715 }
5716 break;
5717 }
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))
5725 {
5726 as_warn (_("could not update architecture and machine"));
5727 match = FALSE;
5728 }
5729
5730 failed:
5731 /* Check if the args matched. */
5732 if (!match)
5733 {
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 }
5746 }
5747 break;
5748 }
5749
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
5757 the_insn.opcode = opcode;
5758 }
5759
5760 /* Assemble a single instruction storing it into a frag. */
5761
5762 void
5763 md_assemble (char *str)
5764 {
5765 char *to;
5766
5767 /* The had better be something to assemble. */
5768 gas_assert (str);
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)
5782 {
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)"));
5806 }
5807 else
5808 as_bad (_("Missing function name for .PROC"));
5809 }
5810
5811 /* Assemble the instruction. Results are saved into "the_insn". */
5812 pa_ip (str);
5813
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
5830 }
5831
5832 #ifdef OBJ_SOM
5833 /* Handle an alignment directive. Special so that we can update the
5834 alignment of the subspace if necessary. */
5835 static void
5836 pa_align (int bytes)
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. */
5846 if (exact_log2 (bytes) != -1)
5847 record_alignment (current_subspace->ssd_seg, exact_log2 (bytes));
5848 }
5849 #endif
5850
5851 /* Handle a .BLOCK type pseudo-op. */
5852
5853 static void
5854 pa_block (int z ATTRIBUTE_UNUSED)
5855 {
5856 unsigned int temp_size;
5857
5858 #ifdef OBJ_SOM
5859 /* We must have a valid space and subspace. */
5860 pa_check_current_space_and_subspace ();
5861 #endif
5862
5863 temp_size = get_absolute_expression ();
5864
5865 if (temp_size > 0x3FFFFFFF)
5866 {
5867 as_bad (_("Argument to .BLOCK/.BLOCKZ must be between 0 and 0x3fffffff"));
5868 temp_size = 0;
5869 }
5870 else
5871 {
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;
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
5883 static void
5884 pa_brtab (int begin ATTRIBUTE_UNUSED)
5885 {
5886
5887 #ifdef OBJ_SOM
5888 /* The BRTAB relocations are only available in SOM (to denote
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,
5895 e_fsel, 0, 0, 0);
5896 #endif
5897
5898 demand_empty_rest_of_line ();
5899 }
5900
5901 /* Handle a .begin_try and .end_try pseudo-op. */
5902
5903 static void
5904 pa_try (int begin ATTRIBUTE_UNUSED)
5905 {
5906 #ifdef OBJ_SOM
5907 expressionS exp;
5908 char *where = frag_more (0);
5909
5910 if (! begin)
5911 expression (&exp);
5912
5913 /* The TRY relocations are only available in SOM (to denote
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,
5919 e_fsel, 0, 0, 0);
5920 #endif
5921
5922 demand_empty_rest_of_line ();
5923 }
5924
5925 /* Do the dirty work of building a call descriptor which describes
5926 where the caller placed arguments to a function call. */
5927
5928 static void
5929 pa_call_args (struct call_desc *call_desc)
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
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
5976 static void
5977 pa_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
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
5994 static void
5995 pa_build_unwind_subspace (struct call_info *call_info)
5996 {
5997 asection *seg, *save_seg;
5998 subsegT save_subseg;
5999 unsigned int unwind;
6000 int reloc;
6001 char *name, *p;
6002 symbolS *symbolP;
6003
6004 if ((bfd_get_section_flags (stdoutput, now_seg)
6005 & (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
6006 != (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
6007 return;
6008
6009 if (call_info->start_symbol == NULL)
6010 /* This can happen if there were errors earlier on in the assembly. */
6011 return;
6012
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
6040 reloc = R_PARISC_SEGREL32;
6041 save_seg = now_seg;
6042 save_subseg = now_subseg;
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. */
6046 seg = bfd_get_section_by_name (stdoutput, UNWIND_SECTION_NAME);
6047 if (seg == ASEC_NULL)
6048 {
6049 seg = subseg_new (UNWIND_SECTION_NAME, 0);
6050 bfd_set_section_flags (stdoutput, seg,
6051 SEC_READONLY | SEC_HAS_CONTENTS
6052 | SEC_LOAD | SEC_RELOC | SEC_ALLOC | SEC_DATA);
6053 bfd_set_section_alignment (stdoutput, seg, 2);
6054 }
6055
6056 subseg_set (seg, 0);
6057
6058 /* Get some space to hold relocation information for the unwind
6059 descriptor. */
6060 p = frag_more (16);
6061
6062 /* Relocation info. for start offset of the function. */
6063 md_number_to_chars (p, 0, 4);
6064 fix_new_hppa (frag_now, p - frag_now->fr_literal, 4,
6065 symbolP, (offsetT) 0,
6066 (expressionS *) NULL, 0, reloc,
6067 e_fsel, 32, 0, 0);
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. */
6076 md_number_to_chars (p + 4, 0, 4);
6077 fix_new_hppa (frag_now, p + 4 - frag_now->fr_literal, 4,
6078 call_info->end_symbol, (offsetT) 0,
6079 (expressionS *) NULL, 0, reloc,
6080 e_fsel, 32, 0, 0);
6081
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);
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
6098 static void
6099 pa_callinfo (int unused ATTRIBUTE_UNUSED)
6100 {
6101 char *name, c, *p;
6102 int temp;
6103
6104 #ifdef OBJ_SOM
6105 /* We must have a valid space and subspace. */
6106 pa_check_current_space_and_subspace ();
6107 #endif
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
6201 in the unwind descriptor. */
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
6209 unwind descriptor. */
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
6238 #if !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD)))
6239 /* Switch to the text space. Like s_text, but delete our
6240 label when finished. */
6241
6242 static void
6243 pa_text (int unused ATTRIBUTE_UNUSED)
6244 {
6245 #ifdef OBJ_SOM
6246 current_space = is_defined_space ("$TEXT$");
6247 current_subspace
6248 = pa_subsegment_to_subspace (current_space->sd_seg, 0);
6249 #endif
6250
6251 s_text (0);
6252 pa_undefine_label ();
6253 }
6254
6255 /* Switch to the data space. As usual delete our label. */
6256
6257 static void
6258 pa_data (int unused ATTRIBUTE_UNUSED)
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
6269 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
6270 the .comm pseudo-op has the following syntax:
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
6289 static void
6290 pa_comm (int unused ATTRIBUTE_UNUSED)
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 {
6306 symbol_get_bfdsym (symbol)->flags |= BSF_OBJECT;
6307 S_SET_VALUE (symbol, size);
6308 S_SET_SEGMENT (symbol, bfd_com_section_ptr);
6309 S_SET_EXTERNAL (symbol);
6310
6311 /* colon() has already set the frag to the current location in the
6312 current subspace; we need to reset the fragment to the zero address
6313 fragment. We also need to reset the segment pointer. */
6314 symbol_set_frag (symbol, &zero_address_frag);
6315 }
6316 demand_empty_rest_of_line ();
6317 }
6318 #endif /* !(defined (OBJ_ELF) && (defined (TE_LINUX) || defined (TE_NetBSD))) */
6319
6320 /* Process a .END pseudo-op. */
6321
6322 static void
6323 pa_end (int unused ATTRIBUTE_UNUSED)
6324 {
6325 demand_empty_rest_of_line ();
6326 }
6327
6328 /* Process a .ENTER pseudo-op. This is not supported. */
6329
6330 static void
6331 pa_enter (int unused ATTRIBUTE_UNUSED)
6332 {
6333 #ifdef OBJ_SOM
6334 /* We must have a valid space and subspace. */
6335 pa_check_current_space_and_subspace ();
6336 #endif
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
6343 procedure. */
6344
6345 static void
6346 pa_entry (int unused ATTRIBUTE_UNUSED)
6347 {
6348 #ifdef OBJ_SOM
6349 /* We must have a valid space and subspace. */
6350 pa_check_current_space_and_subspace ();
6351 #endif
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 {
6375 char *where;
6376 unsigned int u;
6377
6378 where = frag_more (0);
6379 u = UNWIND_LOW32 (&last_call_info->ci_unwind.descriptor);
6380 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
6381 NULL, (offsetT) 0, NULL,
6382 0, R_HPPA_ENTRY, e_fsel, 0, 0, u);
6383 }
6384 #endif
6385 }
6386
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. */
6390 static int fudge_reg_expressions;
6391
6392 int
6393 hppa_force_reg_syms_absolute (expressionS *resultP,
6394 operatorT op ATTRIBUTE_UNUSED,
6395 expressionS *rightP)
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
6407 /* Handle a .EQU pseudo-op. */
6408
6409 static void
6410 pa_equ (int reg)
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)
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 }
6426 else
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 }
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
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
6462 static void
6463 hppa_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
6505 gas_assert (symbolP);
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
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
6525 static void
6526 process_exit (void)
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. */
6536 (void) where;
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,
6552 UNWIND_HIGH32 (&last_call_info->ci_unwind.descriptor));
6553 #endif
6554 }
6555
6556 /* Process a .EXIT pseudo-op. */
6557
6558 static void
6559 pa_exit (int unused ATTRIBUTE_UNUSED)
6560 {
6561 #ifdef OBJ_SOM
6562 /* We must have a valid space and subspace. */
6563 pa_check_current_space_and_subspace ();
6564 #endif
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
6586 /* Helper function to process arguments to a .EXPORT pseudo-op. */
6587
6588 static void
6589 pa_type_args (symbolS *symbolP, int is_export)
6590 {
6591 char *name, c, *p;
6592 unsigned int temp, arg_reloc;
6593 pa_symbol_type type = SYMBOL_TYPE_UNKNOWN;
6594 asymbol *bfdsym = symbol_get_bfdsym (symbolP);
6595
6596 if (strncasecmp (input_line_pointer, "absolute", 8) == 0)
6597 {
6598 input_line_pointer += 8;
6599 bfdsym->flags &= ~BSF_FUNCTION;
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,
6607 instead one should be IMPORTing/EXPORTing ENTRY types.
6608
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. */
6612 if (S_IS_FUNCTION (symbolP))
6613 {
6614 if (is_export)
6615 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
6616 S_GET_NAME (symbolP));
6617
6618 bfdsym->flags |= BSF_FUNCTION;
6619 type = SYMBOL_TYPE_ENTRY;
6620 }
6621 else
6622 {
6623 bfdsym->flags &= ~BSF_FUNCTION;
6624 type = SYMBOL_TYPE_CODE;
6625 }
6626 }
6627 else if (strncasecmp (input_line_pointer, "data", 4) == 0)
6628 {
6629 input_line_pointer += 4;
6630 bfdsym->flags &= ~BSF_FUNCTION;
6631 bfdsym->flags |= BSF_OBJECT;
6632 type = SYMBOL_TYPE_DATA;
6633 }
6634 else if ((strncasecmp (input_line_pointer, "entry", 5) == 0))
6635 {
6636 input_line_pointer += 5;
6637 bfdsym->flags |= BSF_FUNCTION;
6638 type = SYMBOL_TYPE_ENTRY;
6639 }
6640 else if (strncasecmp (input_line_pointer, "millicode", 9) == 0)
6641 {
6642 input_line_pointer += 9;
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
6652 type = SYMBOL_TYPE_MILLICODE;
6653 }
6654 else if (strncasecmp (input_line_pointer, "plabel", 6) == 0)
6655 {
6656 input_line_pointer += 6;
6657 bfdsym->flags &= ~BSF_FUNCTION;
6658 type = SYMBOL_TYPE_PLABEL;
6659 }
6660 else if (strncasecmp (input_line_pointer, "pri_prog", 8) == 0)
6661 {
6662 input_line_pointer += 8;
6663 bfdsym->flags |= BSF_FUNCTION;
6664 type = SYMBOL_TYPE_PRI_PROG;
6665 }
6666 else if (strncasecmp (input_line_pointer, "sec_prog", 8) == 0)
6667 {
6668 input_line_pointer += 8;
6669 bfdsym->flags |= BSF_FUNCTION;
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
6677 obj_set_symbol_type (bfdsym, (int) type);
6678 #else
6679 (void) type;
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));
6700 #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
6701 symbol_arg_reloc_info (symbolP) |= arg_reloc;
6702 #else
6703 (void) arg_reloc;
6704 #endif
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);
6716 #if defined (OBJ_SOM) || defined (ELF_ARG_RELOC)
6717 symbol_arg_reloc_info (symbolP) |= arg_reloc;
6718 #else
6719 (void) arg_reloc;
6720 #endif
6721 *input_line_pointer = c;
6722 }
6723 /* Privilege level. */
6724 else if ((strncasecmp (name, "priv_lev", 8)) == 0)
6725 {
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
6751 static void
6752 pa_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.
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. */
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 {
6780 input_line_pointer++;
6781 pa_type_args (symbol, 1);
6782 }
6783 }
6784
6785 demand_empty_rest_of_line ();
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
6792 static void
6793 pa_import (int unused ATTRIBUTE_UNUSED)
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 {
6818 /* Sigh. To be compatible with the HP assembler and to help
6819 poorly written assembly code, we assign a type based on
6820 the current segment. Note only BSF_FUNCTION really
6821 matters, we do not need to set the full SYMBOL_TYPE_* info. */
6822 if (now_seg == text_section)
6823 symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
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
6843 static void
6844 pa_label (int unused ATTRIBUTE_UNUSED)
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
6872 static void
6873 pa_leave (int unused ATTRIBUTE_UNUSED)
6874 {
6875 #ifdef OBJ_SOM
6876 /* We must have a valid space and subspace. */
6877 pa_check_current_space_and_subspace ();
6878 #endif
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
6886 static void
6887 pa_level (int unused ATTRIBUTE_UNUSED)
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 }
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 }
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
6926 static void
6927 pa_origin (int unused ATTRIBUTE_UNUSED)
6928 {
6929 #ifdef OBJ_SOM
6930 /* We must have a valid space and subspace. */
6931 pa_check_current_space_and_subspace ();
6932 #endif
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
6941 static void
6942 pa_param (int unused ATTRIBUTE_UNUSED)
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
6973 of a procedure from a syntactical point of view. */
6974
6975 static void
6976 pa_proc (int unused ATTRIBUTE_UNUSED)
6977 {
6978 struct call_info *call_info;
6979
6980 #ifdef OBJ_SOM
6981 /* We must have a valid space and subspace. */
6982 pa_check_current_space_and_subspace ();
6983 #endif
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. */
6993 call_info = xmalloc (sizeof (struct call_info));
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;
7029 symbol_get_bfdsym (label_symbol->lss_label)->flags |= BSF_FUNCTION;
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
7041 /* Process the syntactical end of a procedure. Make sure all the
7042 appropriate pseudo-ops were found within the procedure. */
7043
7044 static void
7045 pa_procend (int unused ATTRIBUTE_UNUSED)
7046 {
7047 #ifdef OBJ_SOM
7048 /* We must have a valid space and subspace. */
7049 pa_check_current_space_and_subspace ();
7050 #endif
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;
7068 symbol_get_bfdsym (label_symbol->lss_label)->flags
7069 |= BSF_FUNCTION;
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 {
7075 char *where;
7076 unsigned int u;
7077
7078 where = frag_more (0);
7079 u = UNWIND_LOW32 (&last_call_info->ci_unwind.descriptor);
7080 fix_new_hppa (frag_now, where - frag_now->fr_literal, 0,
7081 NULL, (offsetT) 0, NULL,
7082 0, R_HPPA_ENTRY, e_fsel, 0, 0, u);
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
7113 #ifdef OBJ_SOM
7114 /* If VALUE is an exact power of two between zero and 2^31, then
7115 return log2 (VALUE). Else return -1. */
7116
7117 static int
7118 exact_log2 (int value)
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
7131 /* Check to make sure we have a valid space and subspace. */
7132
7133 static void
7134 pa_check_current_space_and_subspace (void)
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
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
7147 static sd_chain_struct *
7148 pa_parse_space_stmt (char *space_name, int create_flag)
7149 {
7150 char *name, *ptemp, c;
7151 char loadable, defined, private, sort;
7152 int spnum;
7153 asection *seg = NULL;
7154 sd_chain_struct *space;
7155
7156 /* Load default values. */
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
7184 as a name. According to the PA assembly manual the rest of
7185 the line should be ignored. */
7186 strict = 0;
7187 pa_parse_number (&ptemp, 0);
7188 if (pa_number >= 0)
7189 {
7190 spnum = pa_number;
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
7245 the first occurrence of a built-in space. */
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
7267 static void
7268 pa_space (int unused ATTRIBUTE_UNUSED)
7269 {
7270 char *name, c, *space_name, *save_s;
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
7281 below is repeated several times, can we extract the common parts
7282 and place them into a subroutine or something similar? */
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;
7348 strict = 0;
7349 pa_parse_number (&input_line_pointer, 0);
7350 if (pa_number >= 0)
7351 {
7352 if ((sd_chain = pa_find_space_by_number (pa_number)))
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
7386 static void
7387 pa_spnum (int unused ATTRIBUTE_UNUSED)
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
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
7415 static void
7416 pa_subspace (int create_new)
7417 {
7418 char *name, *ss_name, c;
7419 char loadable, code_only, comdat, common, dup_common, zero, sort;
7420 int i, access_ctr, space_index, alignment, quadrant, applicable, flags;
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;
7443 access_ctr = 0x7f;
7444 loadable = 1;
7445 comdat = 0;
7446 common = 0;
7447 dup_common = 0;
7448 code_only = 0;
7449 zero = 0;
7450 space_index = ~0;
7451 alignment = 1;
7452 quadrant = 0;
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
7460 only allow the attributes to be changed once! */
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;
7480 comdat = pa_def_subspaces[i].comdat;
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;
7488 access_ctr = pa_def_subspaces[i].access;
7489 sort = pa_def_subspaces[i].sort;
7490 break;
7491 }
7492 i++;
7493 }
7494 }
7495
7496 /* We should be working with a new subspace now. Fill in
7497 any information as specified by the user. */
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 ();
7516 if (exact_log2 (alignment) == -1)
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++;
7526 access_ctr = get_absolute_expression ();
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 }
7544 else if ((strncasecmp (name, "comdat", 6) == 0))
7545 {
7546 *input_line_pointer = c;
7547 comdat = 1;
7548 }
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
7574 in the .subspace directive. */
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;
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;
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
7602 segment already associated with the subspace.
7603
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. */
7608 if (create_new)
7609 section = subseg_force_new (ss_name, 0);
7610 else if (ssd)
7611 section = ssd->ssd_seg;
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. */
7622 record_alignment (section, exact_log2 (alignment));
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,
7629 or create a new one. */
7630 if (ssd)
7631
7632 current_subspace = update_subspace (space, ss_name, loadable,
7633 code_only, comdat, common,
7634 dup_common, sort, zero, access_ctr,
7635 space_index, alignment, quadrant,
7636 section);
7637 else
7638 current_subspace = create_new_subspace (space, ss_name, loadable,
7639 code_only, comdat, common,
7640 dup_common, zero, sort,
7641 access_ctr, space_index,
7642 alignment, quadrant, section);
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
7651 /* Create default space and subspace dictionaries. */
7652
7653 static void
7654 pa_spaces_begin (void)
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. */
7667 name = pa_def_spaces[i].name;
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
7686 subsegment number. */
7687 name = pa_def_subspaces[i].name;
7688 subsegment = 0;
7689
7690 /* Create the new section. */
7691 segment = subseg_new (name, subsegment);
7692
7693 /* For SOM we want to replace the standard .text, .data, and .bss
7694 sections with our own. We also want to set BFD flags for
7695 all the built-in subspaces. */
7696 if (!strcmp (pa_def_subspaces[i].name, "$CODE$"))
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 }
7706 else if (!strcmp (pa_def_subspaces[i].name, "$DATA$"))
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
7715 }
7716 else if (!strcmp (pa_def_subspaces[i].name, "$BSS$"))
7717 {
7718 bss_section = segment;
7719 applicable = bfd_applicable_section_flags (stdoutput);
7720 bfd_set_section_flags (stdoutput, segment,
7721 applicable & SEC_ALLOC);
7722 }
7723 else if (!strcmp (pa_def_subspaces[i].name, "$LIT$"))
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 }
7732 else if (!strcmp (pa_def_subspaces[i].name, "$MILLICODE$"))
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 }
7741 else if (!strcmp (pa_def_subspaces[i].name, "$UNWIND$"))
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,
7763 pa_def_subspaces[i].comdat,
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
7777 /* Create a new space NAME, with the appropriate flags as defined
7778 by the given parameters. */
7779
7780 static sd_chain_struct *
7781 create_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)
7789 {
7790 sd_chain_struct *chain_entry;
7791
7792 chain_entry = xmalloc (sizeof (sd_chain_struct));
7793 if (!chain_entry)
7794 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
7795 name);
7796
7797 SPACE_NAME (chain_entry) = xmalloc (strlen (name) + 1);
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
7829 entry. So add it and update the linked lists as appropriate. */
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
7862 static ssd_chain_struct *
7863 create_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,
7872 int access_ctr,
7873 int space_index ATTRIBUTE_UNUSED,
7874 int alignment ATTRIBUTE_UNUSED,
7875 int quadrant,
7876 asection *seg)
7877 {
7878 ssd_chain_struct *chain_entry;
7879
7880 chain_entry = xmalloc (sizeof (ssd_chain_struct));
7881 if (!chain_entry)
7882 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name);
7883
7884 SUBSPACE_NAME (chain_entry) = xmalloc (strlen (name) + 1);
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
7891 chain_entry->ssd_subseg = 0;
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
7913 the links. */
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
7927 obj_set_subsection_attributes (seg, space->sd_seg, access_ctr, sort,
7928 quadrant, comdat, common, dup_common);
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
7937 static ssd_chain_struct *
7938 update_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,
7947 int access_ctr,
7948 int space_index ATTRIBUTE_UNUSED,
7949 int alignment ATTRIBUTE_UNUSED,
7950 int quadrant,
7951 asection *section)
7952 {
7953 ssd_chain_struct *chain_entry;
7954
7955 chain_entry = is_defined_subspace (name);
7956
7957 #ifdef obj_set_subsection_attributes
7958 obj_set_subsection_attributes (section, space->sd_seg, access_ctr, sort,
7959 quadrant, comdat, common, dup_common);
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
7968 static sd_chain_struct *
7969 is_defined_space (char *name)
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)
7976 if (strcmp (SPACE_NAME (chain_pointer), name) == 0)
7977 return chain_pointer;
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
7989 static sd_chain_struct *
7990 pa_segment_to_space (asection *seg)
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)
7998 if (space_chain->sd_seg == seg)
7999 return space_chain;
8000
8001 /* Mapping was not found. Return NULL. */
8002 return NULL;
8003 }
8004
8005 /* Return the first space chain entry for the subspace with the name
8006 NAME or NULL if no such subspace exists.
8007
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.
8012
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
8017 static ssd_chain_struct *
8018 is_defined_subspace (char *name)
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
8047 static ssd_chain_struct *
8048 pa_subsegment_to_subspace (asection *seg, subsegT subseg)
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
8079 static sd_chain_struct *
8080 pa_find_space_by_number (int number)
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
8099 static unsigned int
8100 pa_subspace_start (sd_chain_struct *space, int quadrant)
8101 {
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;
8110 return 0;
8111 }
8112 #endif
8113
8114 /* Helper function for pa_stringer. Used to find the end of
8115 a string. */
8116
8117 static unsigned int
8118 pa_stringer_aux (char *s)
8119 {
8120 unsigned int c = *s & CHAR_MASK;
8121
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
8135 static void
8136 pa_stringer (int append_zero)
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.
8143 For example, \xDD where DD is a hexadecimal number should be
8144 changed to \OOO where OOO is an octal number. */
8145
8146 #ifdef OBJ_SOM
8147 /* We must have a valid space and subspace. */
8148 pa_check_current_space_and_subspace ();
8149 #endif
8150
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
8169 /* Get past the 'x'. */
8170 s++;
8171 for (num_digit = 0, number = 0, dg = *s;
8172 num_digit < 2
8173 && (ISDIGIT (dg) || (dg >= 'a' && dg <= 'f')
8174 || (dg >= 'A' && dg <= 'F'));
8175 num_digit++)
8176 {
8177 if (ISDIGIT (dg))
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 }
8210 stringer (8 + append_zero);
8211 pa_undefine_label ();
8212 }
8213
8214 /* Handle a .VERSION pseudo-op. */
8215
8216 static void
8217 pa_version (int unused ATTRIBUTE_UNUSED)
8218 {
8219 obj_version (0);
8220 pa_undefine_label ();
8221 }
8222
8223 #ifdef OBJ_SOM
8224
8225 /* Handle a .COMPILER pseudo-op. */
8226
8227 static void
8228 pa_compiler (int unused ATTRIBUTE_UNUSED)
8229 {
8230 obj_som_compiler (0);
8231 pa_undefine_label ();
8232 }
8233
8234 #endif
8235
8236 /* Handle a .COPYRIGHT pseudo-op. */
8237
8238 static void
8239 pa_copyright (int unused ATTRIBUTE_UNUSED)
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
8248 static void
8249 pa_cons (int nbytes)
8250 {
8251 cons (nbytes);
8252 pa_undefine_label ();
8253 }
8254
8255 /* Like float_cons, but we need to undefine our label. */
8256
8257 static void
8258 pa_float_cons (int float_type)
8259 {
8260 float_cons (float_type);
8261 pa_undefine_label ();
8262 }
8263
8264 /* Like s_fill, but delete our label when finished. */
8265
8266 static void
8267 pa_fill (int unused ATTRIBUTE_UNUSED)
8268 {
8269 #ifdef OBJ_SOM
8270 /* We must have a valid space and subspace. */
8271 pa_check_current_space_and_subspace ();
8272 #endif
8273
8274 s_fill (0);
8275 pa_undefine_label ();
8276 }
8277
8278 /* Like lcomm, but delete our label when finished. */
8279
8280 static void
8281 pa_lcomm (int needs_align)
8282 {
8283 #ifdef OBJ_SOM
8284 /* We must have a valid space and subspace. */
8285 pa_check_current_space_and_subspace ();
8286 #endif
8287
8288 s_lcomm (needs_align);
8289 pa_undefine_label ();
8290 }
8291
8292 /* Like lsym, but delete our label when finished. */
8293
8294 static void
8295 pa_lsym (int unused ATTRIBUTE_UNUSED)
8296 {
8297 #ifdef OBJ_SOM
8298 /* We must have a valid space and subspace. */
8299 pa_check_current_space_and_subspace ();
8300 #endif
8301
8302 s_lsym (0);
8303 pa_undefine_label ();
8304 }
8305
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
8309 void
8310 md_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. */
8375 symbol_get_bfdsym (dummy_symbol)->flags |= BSF_KEEP;
8376 #endif
8377 }
8378
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
8397 ??? Reject reductions involving symbols with external scope; such
8398 reductions make life a living hell for object file editors. */
8399
8400 int
8401 hppa_fix_adjustable (fixS *fixp)
8402 {
8403 #ifdef OBJ_ELF
8404 reloc_type code;
8405 #endif
8406 struct hppa_fix_struct *hppa_fix;
8407
8408 hppa_fix = (struct hppa_fix_struct *) fixp->tc_fix_data;
8409
8410 #ifdef OBJ_ELF
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:
8422 case R_PARISC_DLTREL21L:
8423 case R_PARISC_DPREL21L:
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:
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:
8437 case R_PARISC_PLTOFF14R:
8438 case R_PARISC_PLTOFF14DR:
8439 case R_PARISC_PLTOFF14WR:
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 }
8448 #endif
8449
8450 /* Reject reductions of symbols in sym1-sym2 expressions when
8451 the fixup will occur in a CODE subspace.
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))
8459 return 0;
8460
8461 /* We can't adjust any relocs that use LR% and RR% field selectors.
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
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
8483 multiples takes us up to 8192 with an offset of -4096.
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
8489 above where the LR% expression is offset from the RR% one. */
8490
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;
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
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. */
8511 if (fixp->fx_addsy != 0 && S_IS_FUNCTION (fixp->fx_addsy))
8512 return 0;
8513
8514 return 1;
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
8521 int
8522 hppa_force_relocation (struct fix *fixp)
8523 {
8524 struct hppa_fix_struct *hppa_fixp;
8525
8526 hppa_fixp = (struct hppa_fix_struct *) fixp->tc_fix_data;
8527 #ifdef OBJ_SOM
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
8534 || (fixp->fx_addsy != NULL && fixp->fx_subsy != NULL
8535 && (hppa_fixp->segment->flags & SEC_CODE) != 0))
8536 return 1;
8537 #endif
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;
8542 #endif
8543
8544 gas_assert (fixp->fx_addsy != NULL);
8545
8546 /* Ensure we emit a relocation for global symbols so that dynamic
8547 linking works. */
8548 if (S_FORCE_RELOC (fixp->fx_addsy, 1))
8549 return 1;
8550
8551 /* It is necessary to force PC-relative calls/jumps to have a relocation
8552 entry if they're going to need either an argument relocation or long
8553 call stub. */
8554 if (fixp->fx_pcrel
8555 && arg_reloc_stub_needed (symbol_arg_reloc_info (fixp->fx_addsy),
8556 hppa_fixp->fx_arg_reloc))
8557 return 1;
8558
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 {
8562 long pc = md_pcrel_from (fixp);
8563 valueT distance, min_stub_distance;
8564
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);
8573 #endif
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)
8583 )
8584 return 1;
8585 }
8586
8587 if (fixp->fx_r_type == (int) R_HPPA_ABS_CALL)
8588 return 1;
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
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
8601 void
8602 elf_hppa_final_processing (void)
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
8611 = ((elf_symbol_type *)
8612 symbol_get_bfdsym (call_info_pointer->start_symbol));
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 }
8618
8619 static void
8620 pa_vtable_entry (int ignore ATTRIBUTE_UNUSED)
8621 {
8622 struct fix *new_fix;
8623
8624 new_fix = obj_elf_vtable_entry (0);
8625
8626 if (new_fix)
8627 {
8628 struct hppa_fix_struct * hppa_fix = obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
8629
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
8640 static void
8641 pa_vtable_inherit (int ignore ATTRIBUTE_UNUSED)
8642 {
8643 struct fix *new_fix;
8644
8645 new_fix = obj_elf_vtable_inherit (0);
8646
8647 if (new_fix)
8648 {
8649 struct hppa_fix_struct * hppa_fix = obstack_alloc (&notes, sizeof (struct hppa_fix_struct));
8650
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 }
8660 #endif
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? */
8665 const 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 };
8751
8752 #ifdef OBJ_ELF
8753 void
8754 hppa_cfi_frame_initial_instructions (void)
8755 {
8756 cfi_add_CFA_def_cfa (30, 0);
8757 }
8758
8759 int
8760 hppa_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);
8786 #if TARGET_ARCH_SIZE == 64
8787 if (p == q || *q || regnum <= 4 || regnum >= 32)
8788 return -1;
8789 regnum += 32 - 4;
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
8799 }
8800 return regnum;
8801 }
8802 #endif
This page took 0.224442 seconds and 5 git commands to generate.