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