1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
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)
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.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 /* HP PA-RISC support was contributed by the Center for Software Science
24 at the University of Utah. */
32 #include "bfd/libhppa.h"
33 #include "bfd/libbfd.h"
35 /* Be careful, this file includes data *declarations*. */
36 #include "opcode/hppa.h"
38 #if defined (OBJ_ELF) && defined (OBJ_SOM)
39 error only one of OBJ_ELF
and OBJ_SOM can be defined
42 /* If we are using ELF, then we probably can support dwarf2 debug
43 records. Furthermore, if we are supporting dwarf2 debug records,
44 then we want to use the assembler support for compact line numbers. */
46 #include "dwarf2dbg.h"
47 struct dwarf2_line_info debug_line
;
50 /* A "convient" place to put object file dependencies which do
51 not need to be seen outside of tc-hppa.c. */
53 /* Object file formats specify relocation types. */
54 typedef elf_hppa_reloc_type reloc_type
;
56 /* Object file formats specify BFD symbol types. */
57 typedef elf_symbol_type obj_symbol_type
;
60 /* How to generate a relocation. */
61 #define hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type
63 #define hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type
66 /* ELF objects can have versions, but apparently do not have anywhere
67 to store a copyright string. */
68 #define obj_version obj_elf_version
69 #define obj_copyright obj_elf_version
71 #define UNWIND_SECTION_NAME ".PARISC.unwind"
75 /* Names of various debugging spaces/subspaces. */
76 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
77 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
78 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
79 #define UNWIND_SECTION_NAME "$UNWIND$"
81 /* Object file formats specify relocation types. */
82 typedef int reloc_type
;
84 /* SOM objects can have both a version string and a copyright string. */
85 #define obj_version obj_som_version
86 #define obj_copyright obj_som_copyright
88 /* How to generate a relocation. */
89 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
91 /* Object file formats specify BFD symbol types. */
92 typedef som_symbol_type obj_symbol_type
;
94 /* This apparently isn't in older versions of hpux reloc.h. */
96 #define R_DLT_REL 0x78
108 /* Various structures and types used internally in tc-hppa.c. */
110 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
114 unsigned int cannot_unwind
:1;
115 unsigned int millicode
:1;
116 unsigned int millicode_save_rest
:1;
117 unsigned int region_desc
:2;
118 unsigned int save_sr
:2;
119 unsigned int entry_fr
:4;
120 unsigned int entry_gr
:5;
121 unsigned int args_stored
:1;
122 unsigned int call_fr
:5;
123 unsigned int call_gr
:5;
124 unsigned int save_sp
:1;
125 unsigned int save_rp
:1;
126 unsigned int save_rp_in_frame
:1;
127 unsigned int extn_ptr_defined
:1;
128 unsigned int cleanup_defined
:1;
130 unsigned int hpe_interrupt_marker
:1;
131 unsigned int hpux_interrupt_marker
:1;
132 unsigned int reserved
:3;
133 unsigned int frame_size
:27;
138 /* Starting and ending offsets of the region described by
140 unsigned int start_offset
;
141 unsigned int end_offset
;
142 struct unwind_desc descriptor
;
145 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
146 control the entry and exit code they generate. It is also used in
147 creation of the correct stack unwind descriptors.
149 NOTE: GAS does not support .enter and .leave for the generation of
150 prologues and epilogues. FIXME.
152 The fields in structure roughly correspond to the arguments available on the
153 .callinfo pseudo-op. */
157 /* The unwind descriptor being built. */
158 struct unwind_table ci_unwind
;
160 /* Name of this function. */
161 symbolS
*start_symbol
;
163 /* (temporary) symbol used to mark the end of this function. */
166 /* Next entry in the chain. */
167 struct call_info
*ci_next
;
170 /* Operand formats for FP instructions. Note not all FP instructions
171 allow all four formats to be used (for example fmpysub only allows
175 SGL
, DBL
, ILLEGAL_FMT
, QUAD
, W
, UW
, DW
, UDW
, QW
, UQW
179 /* This fully describes the symbol types which may be attached to
180 an EXPORT or IMPORT directive. Only SOM uses this formation
181 (ELF has no need for it). */
185 SYMBOL_TYPE_ABSOLUTE
,
189 SYMBOL_TYPE_MILLICODE
,
191 SYMBOL_TYPE_PRI_PROG
,
192 SYMBOL_TYPE_SEC_PROG
,
196 /* This structure contains information needed to assemble
197 individual instructions. */
200 /* Holds the opcode after parsing by pa_ip. */
201 unsigned long opcode
;
203 /* Holds an expression associated with the current instruction. */
206 /* Does this instruction use PC-relative addressing. */
209 /* Floating point formats for operand1 and operand2. */
210 fp_operand_format fpof1
;
211 fp_operand_format fpof2
;
214 /* Holds the field selector for this instruction
215 (for example L%, LR%, etc). */
218 /* Holds any argument relocation bits associated with this
219 instruction. (instruction should be some sort of call). */
222 /* The format specification for this instruction. */
225 /* The relocation (if any) associated with this instruction. */
229 /* PA-89 floating point registers are arranged like this:
232 +--------------+--------------+
233 | 0 or 16L | 16 or 16R |
234 +--------------+--------------+
235 | 1 or 17L | 17 or 17R |
236 +--------------+--------------+
244 +--------------+--------------+
245 | 14 or 30L | 30 or 30R |
246 +--------------+--------------+
247 | 15 or 31L | 31 or 31R |
248 +--------------+--------------+
251 The following is a version of pa_parse_number that
252 handles the L/R notation and returns the correct
253 value to put into the instruction register field.
254 The correct value to put into the instruction is
255 encoded in the structure 'pa_11_fp_reg_struct'. */
257 struct pa_11_fp_reg_struct
259 /* The register number. */
266 /* Additional information needed to build argument relocation stubs. */
269 /* The argument relocation specification. */
270 unsigned int arg_reloc
;
272 /* Number of arguments. */
273 unsigned int arg_count
;
277 /* This structure defines an entry in the subspace dictionary
280 struct subspace_dictionary_chain
282 /* Nonzero if this space has been defined by the user code. */
283 unsigned int ssd_defined
;
285 /* Name of this subspace. */
288 /* GAS segment and subsegment associated with this subspace. */
292 /* Next space in the subspace dictionary chain. */
293 struct subspace_dictionary_chain
*ssd_next
;
296 typedef struct subspace_dictionary_chain ssd_chain_struct
;
298 /* This structure defines an entry in the subspace dictionary
301 struct space_dictionary_chain
303 /* Nonzero if this space has been defined by the user code or
304 as a default space. */
305 unsigned int sd_defined
;
307 /* Nonzero if this spaces has been defined by the user code. */
308 unsigned int sd_user_defined
;
310 /* The space number (or index). */
311 unsigned int sd_spnum
;
313 /* The name of this subspace. */
316 /* GAS segment to which this subspace corresponds. */
319 /* Current subsegment number being used. */
322 /* The chain of subspaces contained within this space. */
323 ssd_chain_struct
*sd_subspaces
;
325 /* The next entry in the space dictionary chain. */
326 struct space_dictionary_chain
*sd_next
;
329 typedef struct space_dictionary_chain sd_chain_struct
;
331 /* This structure defines attributes of the default subspace
332 dictionary entries. */
334 struct default_subspace_dict
336 /* Name of the subspace. */
339 /* FIXME. Is this still needed? */
342 /* Nonzero if this subspace is loadable. */
345 /* Nonzero if this subspace contains only code. */
348 /* Nonzero if this is a common subspace. */
351 /* Nonzero if this is a common subspace which allows symbols
352 to be multiply defined. */
355 /* Nonzero if this subspace should be zero filled. */
358 /* Sort key for this subspace. */
361 /* Access control bits for this subspace. Can represent RWX access
362 as well as privilege level changes for gateways. */
365 /* Index of containing space. */
368 /* Alignment (in bytes) of this subspace. */
371 /* Quadrant within space where this subspace should be loaded. */
374 /* An index into the default spaces array. */
377 /* Subsegment associated with this subspace. */
381 /* This structure defines attributes of the default space
382 dictionary entries. */
384 struct default_space_dict
386 /* Name of the space. */
389 /* Space number. It is possible to identify spaces within
390 assembly code numerically! */
393 /* Nonzero if this space is loadable. */
396 /* Nonzero if this space is "defined". FIXME is still needed */
399 /* Nonzero if this space can not be shared. */
402 /* Sort key for this space. */
405 /* Segment associated with this space. */
410 /* Structure for previous label tracking. Needed so that alignments,
411 callinfo declarations, etc can be easily attached to a particular
413 typedef struct label_symbol_struct
415 struct symbol
*lss_label
;
417 sd_chain_struct
*lss_space
;
422 struct label_symbol_struct
*lss_next
;
426 /* Extra information needed to perform fixups (relocations) on the PA. */
427 struct hppa_fix_struct
429 /* The field selector. */
430 enum hppa_reloc_field_selector_type_alt fx_r_field
;
435 /* Format of fixup. */
438 /* Argument relocation bits. */
441 /* The segment this fixup appears in. */
445 /* Structure to hold information about predefined registers. */
453 /* This structure defines the mapping from a FP condition string
454 to a condition number which can be recorded in an instruction. */
461 /* This structure defines a mapping from a field selector
462 string to a field selector type. */
463 struct selector_entry
469 /* Prototypes for functions local to tc-hppa.c. */
472 static void pa_check_current_space_and_subspace
PARAMS ((void));
475 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
476 static void pa_cons
PARAMS ((int));
477 static void pa_data
PARAMS ((int));
478 static void pa_float_cons
PARAMS ((int));
479 static void pa_fill
PARAMS ((int));
480 static void pa_lcomm
PARAMS ((int));
481 static void pa_lsym
PARAMS ((int));
482 static void pa_stringer
PARAMS ((int));
483 static void pa_text
PARAMS ((int));
484 static void pa_version
PARAMS ((int));
485 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
486 static int get_expression
PARAMS ((char *));
487 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
488 static int evaluate_absolute
PARAMS ((struct pa_it
*));
489 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
490 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
491 static int pa_parse_nullif
PARAMS ((char **));
492 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
493 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
494 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
495 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
496 static void pa_block
PARAMS ((int));
497 static void pa_brtab
PARAMS ((int));
498 static void pa_try
PARAMS ((int));
499 static void pa_call
PARAMS ((int));
500 static void pa_call_args
PARAMS ((struct call_desc
*));
501 static void pa_callinfo
PARAMS ((int));
502 static void pa_code
PARAMS ((int));
503 static void pa_comm
PARAMS ((int));
504 static void pa_copyright
PARAMS ((int));
505 static void pa_end
PARAMS ((int));
506 static void pa_enter
PARAMS ((int));
507 static void pa_entry
PARAMS ((int));
508 static void pa_equ
PARAMS ((int));
509 static void pa_exit
PARAMS ((int));
510 static void pa_export
PARAMS ((int));
511 static void pa_type_args
PARAMS ((symbolS
*, int));
512 static void pa_import
PARAMS ((int));
513 static void pa_label
PARAMS ((int));
514 static void pa_leave
PARAMS ((int));
515 static void pa_level
PARAMS ((int));
516 static void pa_origin
PARAMS ((int));
517 static void pa_proc
PARAMS ((int));
518 static void pa_procend
PARAMS ((int));
519 static void pa_param
PARAMS ((int));
520 static void pa_undefine_label
PARAMS ((void));
521 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
522 struct pa_11_fp_reg_struct
*));
523 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
524 static label_symbol_struct
*pa_get_label
PARAMS ((void));
526 static void pa_compiler
PARAMS ((int));
527 static void pa_align
PARAMS ((int));
528 static void pa_space
PARAMS ((int));
529 static void pa_spnum
PARAMS ((int));
530 static void pa_subspace
PARAMS ((int));
531 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
534 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
539 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
540 char *, int, int, int,
544 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
545 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
546 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
547 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
549 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
550 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
551 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
552 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
553 static void pa_spaces_begin
PARAMS ((void));
555 static void pa_ip
PARAMS ((char *));
556 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
557 long, expressionS
*, int,
558 bfd_reloc_code_real_type
,
559 enum hppa_reloc_field_selector_type_alt
,
561 static int is_end_of_statement
PARAMS ((void));
562 static int reg_name_search
PARAMS ((char *));
563 static int pa_chk_field_selector
PARAMS ((char **));
564 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
565 static void process_exit
PARAMS ((void));
566 static int log2
PARAMS ((int));
567 static unsigned int pa_stringer_aux
PARAMS ((char *));
570 static void hppa_elf_mark_end_of_function
PARAMS ((void));
571 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
574 /* File and gloally scoped variable declarations. */
577 /* Root and final entry in the space chain. */
578 static sd_chain_struct
*space_dict_root
;
579 static sd_chain_struct
*space_dict_last
;
581 /* The current space and subspace. */
582 static sd_chain_struct
*current_space
;
583 static ssd_chain_struct
*current_subspace
;
586 /* Root of the call_info chain. */
587 static struct call_info
*call_info_root
;
589 /* The last call_info (for functions) structure
590 seen so it can be associated with fixups and
592 static struct call_info
*last_call_info
;
594 /* The last call description (for actual calls). */
595 static struct call_desc last_call_desc
;
597 /* handle of the OPCODE hash table */
598 static struct hash_control
*op_hash
= NULL
;
600 /* This array holds the chars that always start a comment. If the
601 pre-processor is disabled, these aren't very useful. */
602 const char comment_chars
[] = ";";
604 /* Table of pseudo ops for the PA. FIXME -- how many of these
605 are now redundant with the overall GAS and the object file
607 const pseudo_typeS md_pseudo_table
[] =
609 /* align pseudo-ops on the PA specify the actual alignment requested,
610 not the log2 of the requested alignment. */
612 {"align", pa_align
, 8},
615 {"align", s_align_bytes
, 8},
617 {"begin_brtab", pa_brtab
, 1},
618 {"begin_try", pa_try
, 1},
619 {"block", pa_block
, 1},
620 {"blockz", pa_block
, 0},
621 {"byte", pa_cons
, 1},
622 {"call", pa_call
, 0},
623 {"callinfo", pa_callinfo
, 0},
624 {"code", pa_code
, 0},
625 {"comm", pa_comm
, 0},
627 {"compiler", pa_compiler
, 0},
629 {"copyright", pa_copyright
, 0},
630 {"data", pa_data
, 0},
631 {"double", pa_float_cons
, 'd'},
632 {"dword", pa_cons
, 8},
634 {"end_brtab", pa_brtab
, 0},
635 {"end_try", pa_try
, 0},
636 {"enter", pa_enter
, 0},
637 {"entry", pa_entry
, 0},
639 {"exit", pa_exit
, 0},
640 {"export", pa_export
, 0},
642 { "file", dwarf2_directive_file
},
644 {"fill", pa_fill
, 0},
645 {"float", pa_float_cons
, 'f'},
646 {"half", pa_cons
, 2},
647 {"import", pa_import
, 0},
649 {"label", pa_label
, 0},
650 {"lcomm", pa_lcomm
, 0},
651 {"leave", pa_leave
, 0},
652 {"level", pa_level
, 0},
654 { "loc", dwarf2_directive_loc
},
656 {"long", pa_cons
, 4},
657 {"lsym", pa_lsym
, 0},
659 {"nsubspa", pa_subspace
, 1},
661 {"octa", pa_cons
, 16},
662 {"org", pa_origin
, 0},
663 {"origin", pa_origin
, 0},
664 {"param", pa_param
, 0},
665 {"proc", pa_proc
, 0},
666 {"procend", pa_procend
, 0},
667 {"quad", pa_cons
, 8},
669 {"short", pa_cons
, 2},
670 {"single", pa_float_cons
, 'f'},
672 {"space", pa_space
, 0},
673 {"spnum", pa_spnum
, 0},
675 {"string", pa_stringer
, 0},
676 {"stringz", pa_stringer
, 1},
678 {"subspa", pa_subspace
, 0},
680 {"text", pa_text
, 0},
681 {"version", pa_version
, 0},
682 {"word", pa_cons
, 4},
686 /* This array holds the chars that only start a comment at the beginning of
687 a line. If the line seems to have the form '# 123 filename'
688 .line and .file directives will appear in the pre-processed output.
690 Note that input_file.c hand checks for '#' at the beginning of the
691 first line of the input file. This is because the compiler outputs
692 #NO_APP at the beginning of its output.
694 Also note that C style comments will always work. */
695 const char line_comment_chars
[] = "#";
697 /* This array holds the characters which act as line separators. */
698 const char line_separator_chars
[] = "!";
700 /* Chars that can be used to separate mant from exp in floating point nums. */
701 const char EXP_CHARS
[] = "eE";
703 /* Chars that mean this number is a floating point constant.
704 As in 0f12.456 or 0d1.2345e12.
706 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
707 changed in read.c. Ideally it shouldn't hae to know abou it at
708 all, but nothing is ideal around here. */
709 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
711 static struct pa_it the_insn
;
713 /* Points to the end of an expression just parsed by get_expressoin
714 and friends. FIXME. This shouldn't be handled with a file-global
716 static char *expr_end
;
718 /* Nonzero if a .callinfo appeared within the current procedure. */
719 static int callinfo_found
;
721 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
722 static int within_entry_exit
;
724 /* Nonzero if the assembler is currently within a procedure definition. */
725 static int within_procedure
;
727 /* Handle on strucutre which keep track of the last symbol
728 seen in each subspace. */
729 static label_symbol_struct
*label_symbols_rootp
= NULL
;
731 /* Holds the last field selector. */
732 static int hppa_field_selector
;
734 /* Nonzero when strict syntax checking is enabled. Zero otherwise.
736 Each opcode in the table has a flag which indicates whether or not
737 strict syntax checking should be enabled for that instruction. */
738 static int strict
= 0;
741 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
742 static symbolS
*dummy_symbol
;
745 /* Nonzero if errors are to be printed. */
746 static int print_errors
= 1;
748 /* List of registers that are pre-defined:
750 Each general register has one predefined name of the form
751 %r<REGNUM> which has the value <REGNUM>.
753 Space and control registers are handled in a similar manner,
754 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
756 Likewise for the floating point registers, but of the form
757 %fr<REGNUM>. Floating point registers have additional predefined
758 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
759 again have the value <REGNUM>.
761 Many registers also have synonyms:
763 %r26 - %r23 have %arg0 - %arg3 as synonyms
764 %r28 - %r29 have %ret0 - %ret1 as synonyms
765 %r30 has %sp as a synonym
766 %r27 has %dp as a synonym
767 %r2 has %rp as a synonym
769 Almost every control register has a synonym; they are not listed
772 The table is sorted. Suitable for searching by a binary search. */
774 static const struct pd_reg pre_defined_registers
[] =
974 /* This table is sorted by order of the length of the string. This is
975 so we check for <> before we check for <. If we had a <> and checked
976 for < first, we would get a false match. */
977 static const struct fp_cond_map fp_cond_map
[] =
1013 static const struct selector_entry selector_table
[] =
1038 /* default space and subspace dictionaries */
1040 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1041 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1043 /* pre-defined subsegments (subspaces) for the HPPA. */
1044 #define SUBSEG_CODE 0
1045 #define SUBSEG_LIT 1
1046 #define SUBSEG_MILLI 2
1047 #define SUBSEG_DATA 0
1048 #define SUBSEG_BSS 2
1049 #define SUBSEG_UNWIND 3
1050 #define SUBSEG_GDB_STRINGS 0
1051 #define SUBSEG_GDB_SYMBOLS 1
1053 static struct default_subspace_dict pa_def_subspaces
[] =
1055 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, SUBSEG_CODE
},
1056 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, SUBSEG_DATA
},
1057 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, SUBSEG_LIT
},
1058 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, SUBSEG_MILLI
},
1059 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, SUBSEG_BSS
},
1060 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1063 static struct default_space_dict pa_def_spaces
[] =
1065 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
},
1066 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
},
1067 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
}
1070 /* Misc local definitions used by the assembler. */
1072 /* These macros are used to maintain spaces/subspaces. */
1073 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1074 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1075 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1076 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1078 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1079 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1082 /* Return nonzero if the string pointed to by S potentially represents
1083 a right or left half of a FP register */
1084 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1085 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1087 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1088 main loop after insertion. */
1090 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1092 ((OPCODE) |= (FIELD) << (START)); \
1096 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1097 IGNORE is used to suppress the error message. */
1099 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1101 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1104 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1110 #define is_DP_relative(exp) \
1111 ((exp).X_op == O_subtract \
1112 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
1114 #define is_PC_relative(exp) \
1115 ((exp).X_op == O_subtract \
1116 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
1118 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1119 always be able to reduce the expression to a constant, so we don't
1120 need real complex handling yet. */
1121 #define is_complex(exp) \
1122 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1124 /* Actual functions to implement the PA specific code for the assembler. */
1126 /* Called before writing the object file. Make sure entry/exit and
1127 proc/procend pairs match. */
1132 if (within_entry_exit
)
1133 as_fatal (_("Missing .exit\n"));
1135 if (within_procedure
)
1136 as_fatal (_("Missing .procend\n"));
1139 /* Returns a pointer to the label_symbol_struct for the current space.
1140 or NULL if no label_symbol_struct exists for the current space. */
1142 static label_symbol_struct
*
1145 label_symbol_struct
*label_chain
;
1147 for (label_chain
= label_symbols_rootp
;
1149 label_chain
= label_chain
->lss_next
)
1152 if (current_space
== label_chain
->lss_space
&& label_chain
->lss_label
)
1156 if (now_seg
== label_chain
->lss_segment
&& label_chain
->lss_label
)
1164 /* Defines a label for the current space. If one is already defined,
1165 this function will replace it with the new label. */
1168 pa_define_label (symbol
)
1171 label_symbol_struct
*label_chain
= pa_get_label ();
1174 label_chain
->lss_label
= symbol
;
1177 /* Create a new label entry and add it to the head of the chain. */
1179 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1180 label_chain
->lss_label
= symbol
;
1182 label_chain
->lss_space
= current_space
;
1185 label_chain
->lss_segment
= now_seg
;
1187 label_chain
->lss_next
= NULL
;
1189 if (label_symbols_rootp
)
1190 label_chain
->lss_next
= label_symbols_rootp
;
1192 label_symbols_rootp
= label_chain
;
1196 /* Removes a label definition for the current space.
1197 If there is no label_symbol_struct entry, then no action is taken. */
1200 pa_undefine_label ()
1202 label_symbol_struct
*label_chain
;
1203 label_symbol_struct
*prev_label_chain
= NULL
;
1205 for (label_chain
= label_symbols_rootp
;
1207 label_chain
= label_chain
->lss_next
)
1211 && current_space
== label_chain
->lss_space
&& label_chain
->lss_label
1214 && now_seg
== label_chain
->lss_segment
&& label_chain
->lss_label
1218 /* Remove the label from the chain and free its memory. */
1219 if (prev_label_chain
)
1220 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1222 label_symbols_rootp
= label_chain
->lss_next
;
1227 prev_label_chain
= label_chain
;
1232 /* An HPPA-specific version of fix_new. This is required because the HPPA
1233 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1234 results in the creation of an instance of an hppa_fix_struct. An
1235 hppa_fix_struct stores the extra information along with a pointer to the
1236 original fixS. This is attached to the original fixup via the
1237 tc_fix_data field. */
1240 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1241 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1245 symbolS
*add_symbol
;
1249 bfd_reloc_code_real_type r_type
;
1250 enum hppa_reloc_field_selector_type_alt r_field
;
1257 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1258 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1261 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1263 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1264 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1265 hppa_fix
->fx_r_type
= r_type
;
1266 hppa_fix
->fx_r_field
= r_field
;
1267 hppa_fix
->fx_r_format
= r_format
;
1268 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1269 hppa_fix
->segment
= now_seg
;
1271 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1272 new_fix
->fx_offset
= *unwind_bits
;
1275 /* foo-$global$ is used to access non-automatic storage. $global$
1276 is really just a marker and has served its purpose, so eliminate
1277 it now so as not to confuse write.c. */
1278 if (new_fix
->fx_subsy
1279 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1280 new_fix
->fx_subsy
= NULL
;
1283 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1284 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1287 parse_cons_expression_hppa (exp
)
1290 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1294 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1295 hppa_field_selector is set by the parse_cons_expression_hppa. */
1298 cons_fix_new_hppa (frag
, where
, size
, exp
)
1304 unsigned int rel_type
;
1306 /* Get a base relocation type. */
1307 if (is_DP_relative (*exp
))
1308 rel_type
= R_HPPA_GOTOFF
;
1309 else if (is_complex (*exp
))
1310 rel_type
= R_HPPA_COMPLEX
;
1314 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1315 as_warn (_("Invalid field selector. Assuming F%%."));
1317 fix_new_hppa (frag
, where
, size
,
1318 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1319 hppa_field_selector
, size
* 8, 0, NULL
);
1321 /* Reset field selector to its default state. */
1322 hppa_field_selector
= 0;
1325 /* This function is called once, at assembler startup time. It should
1326 set up all the tables, etc. that the MD part of the assembler will need. */
1331 const char *retval
= NULL
;
1335 last_call_info
= NULL
;
1336 call_info_root
= NULL
;
1338 /* Set the default machine type. */
1339 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1340 as_warn (_("could not set architecture and machine"));
1342 /* Folding of text and data segments fails miserably on the PA.
1343 Warn user and disable "-R" option. */
1344 if (flag_readonly_data_in_text
)
1346 as_warn (_("-R option not supported on this target."));
1347 flag_readonly_data_in_text
= 0;
1354 op_hash
= hash_new ();
1356 while (i
< NUMOPCODES
)
1358 const char *name
= pa_opcodes
[i
].name
;
1359 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1360 if (retval
!= NULL
&& *retval
!= '\0')
1362 as_fatal (_("Internal error: can't hash `%s': %s\n"), name
, retval
);
1367 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1368 != pa_opcodes
[i
].match
)
1370 fprintf (stderr
, _("internal error: losing opcode: `%s' \"%s\"\n"),
1371 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1376 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1380 as_fatal (_("Broken assembler. No assembly attempted."));
1383 /* SOM will change text_section. To make sure we never put
1384 anything into the old one switch to the new one now. */
1385 subseg_set (text_section
, 0);
1389 dummy_symbol
= symbol_find_or_make ("L$dummy");
1390 S_SET_SEGMENT (dummy_symbol
, text_section
);
1391 /* Force the symbol to be converted to a real symbol. */
1392 (void) symbol_get_bfdsym (dummy_symbol
);
1396 /* Assemble a single instruction storing it into a frag. */
1403 /* The had better be something to assemble. */
1406 /* If we are within a procedure definition, make sure we've
1407 defined a label for the procedure; handle case where the
1408 label was defined after the .PROC directive.
1410 Note there's not need to diddle with the segment or fragment
1411 for the label symbol in this case. We have already switched
1412 into the new $CODE$ subspace at this point. */
1413 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1415 label_symbol_struct
*label_symbol
= pa_get_label ();
1419 if (label_symbol
->lss_label
)
1421 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1422 symbol_get_bfdsym (label_symbol
->lss_label
)->flags
1425 /* Also handle allocation of a fixup to hold the unwind
1426 information when the label appears after the proc/procend. */
1427 if (within_entry_exit
)
1429 char *where
= frag_more (0);
1431 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1432 NULL
, (offsetT
) 0, NULL
,
1433 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1434 (int *)&last_call_info
->ci_unwind
.descriptor
);
1439 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
1442 as_bad (_("Missing function name for .PROC"));
1445 /* Assemble the instruction. Results are saved into "the_insn". */
1448 /* Get somewhere to put the assembled instrution. */
1451 /* Output the opcode. */
1452 md_number_to_chars (to
, the_insn
.opcode
, 4);
1454 /* If necessary output more stuff. */
1455 if (the_insn
.reloc
!= R_HPPA_NONE
)
1456 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1457 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1458 the_insn
.reloc
, the_insn
.field_selector
,
1459 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1462 if (debug_type
== DEBUG_DWARF2
)
1466 /* First update the notion of the current source line. */
1467 dwarf2_where (&debug_line
);
1469 /* We want the offset of the start of this instruction within the
1470 the current frag. */
1471 addr
= frag_now
->fr_address
+ frag_now_fix () - 4;
1473 /* And record the information. */
1474 dwarf2_gen_line_info (addr
, &debug_line
);
1479 /* Do the real work for assembling a single instruction. Store results
1480 into the global "the_insn" variable. */
1486 char *error_message
= "";
1487 char *s
, c
, *argstart
, *name
, *save_s
;
1491 int cmpltr
, nullif
, flag
, cond
, num
;
1492 unsigned long opcode
;
1493 struct pa_opcode
*insn
;
1496 /* We must have a valid space and subspace. */
1497 pa_check_current_space_and_subspace ();
1500 /* Convert everything up to the first whitespace character into lower
1502 for (s
= str
; *s
!= ' ' && *s
!= '\t' && *s
!= '\n' && *s
!= '\0'; s
++)
1506 /* Skip to something interesting. */
1507 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1526 as_fatal (_("Unknown opcode: `%s'"), str
);
1531 /* Look up the opcode in the has table. */
1532 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1534 as_bad ("Unknown opcode: `%s'", str
);
1543 /* Mark the location where arguments for the instruction start, then
1544 start processing them. */
1548 /* Do some initialization. */
1549 opcode
= insn
->match
;
1550 strict
= (insn
->flags
& FLAG_STRICT
);
1551 memset (&the_insn
, 0, sizeof (the_insn
));
1553 the_insn
.reloc
= R_HPPA_NONE
;
1555 /* If this instruction is specific to a particular architecture,
1556 then set a new architecture. */
1557 /* But do not automatically promote to pa2.0. The automatic promotion
1558 crud is for compatability with HP's old assemblers only. */
1560 && bfd_get_mach (stdoutput
) < insn
->arch
)
1562 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1563 as_warn (_("could not update architecture and machine"));
1565 else if (bfd_get_mach (stdoutput
) < insn
->arch
)
1571 /* Build the opcode, checking as we go to make
1572 sure that the operands match. */
1573 for (args
= insn
->args
;; ++args
)
1575 /* Absorb white space in instruction. */
1576 while (*s
== ' ' || *s
== '\t')
1582 /* End of arguments. */
1598 /* These must match exactly. */
1607 /* Handle a 5 bit register or control register field at 10. */
1610 /* This should be more strict. Small steps. */
1611 if (strict
&& *s
!= '%')
1613 num
= pa_parse_number (&s
, 0);
1614 CHECK_FIELD (num
, 31, 0, 0);
1615 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1617 /* Handle %sar or %cr11. No bits get set, we just verify that it
1620 /* Skip whitespace before register. */
1621 while (*s
== ' ' || *s
== '\t')
1624 if (!strncasecmp(s
, "%sar", 4))
1629 else if (!strncasecmp(s
, "%cr11", 5))
1636 /* Handle a 5 bit register field at 15. */
1638 /* This should be more strict. Small steps. */
1639 if (strict
&& *s
!= '%')
1641 num
= pa_parse_number (&s
, 0);
1642 CHECK_FIELD (num
, 31, 0, 0);
1643 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1645 /* Handle a 5 bit register field at 31. */
1647 /* This should be more strict. Small steps. */
1648 if (strict
&& *s
!= '%')
1650 num
= pa_parse_number (&s
, 0);
1651 CHECK_FIELD (num
, 31, 0, 0);
1652 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1654 /* Handle a 5 bit register field at 10 and 15. */
1656 /* This should be more strict. Small steps. */
1657 if (strict
&& *s
!= '%')
1659 num
= pa_parse_number (&s
, 0);
1660 CHECK_FIELD (num
, 31, 0, 0);
1661 opcode
|= num
<< 16;
1662 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1664 /* Handle a 5 bit field length at 31. */
1666 num
= pa_get_absolute_expression (&the_insn
, &s
);
1667 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1670 CHECK_FIELD (num
, 32, 1, 0);
1671 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1673 /* Handle a 5 bit immediate at 15. */
1675 num
= pa_get_absolute_expression (&the_insn
, &s
);
1676 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1679 /* When in strict mode, we want to just reject this
1680 match instead of giving an out of range error. */
1681 CHECK_FIELD (num
, 15, -16, strict
);
1682 low_sign_unext (num
, 5, &num
);
1683 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1685 /* Handle a 5 bit immediate at 31. */
1687 num
= pa_get_absolute_expression (&the_insn
, &s
);
1688 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1691 /* When in strict mode, we want to just reject this
1692 match instead of giving an out of range error. */
1693 CHECK_FIELD (num
, 15, -16, strict
)
1694 low_sign_unext (num
, 5, &num
);
1695 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1697 /* Handle an unsigned 5 bit immediate at 31. */
1699 num
= pa_get_absolute_expression (&the_insn
, &s
);
1700 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1703 CHECK_FIELD (num
, 31, 0, 0);
1704 INSERT_FIELD_AND_CONTINUE (opcode
, num
, strict
);
1706 /* Handle an unsigned 5 bit immediate at 15. */
1708 num
= pa_get_absolute_expression (&the_insn
, &s
);
1709 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1712 CHECK_FIELD (num
, 31, 0, strict
);
1713 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1715 /* Handle an unsigned 10 bit immediate at 15. */
1717 num
= pa_get_absolute_expression (&the_insn
, &s
);
1718 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1721 CHECK_FIELD (num
, 1023, 0, strict
);
1722 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1724 /* Handle a 2 bit space identifier at 17. */
1726 /* This should be more strict. Small steps. */
1727 if (strict
&& *s
!= '%')
1729 num
= pa_parse_number (&s
, 0);
1730 CHECK_FIELD (num
, 3, 0, 1);
1731 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1733 /* Handle a 3 bit space identifier at 18. */
1735 /* This should be more strict. Small steps. */
1736 if (strict
&& *s
!= '%')
1738 num
= pa_parse_number (&s
, 0);
1739 CHECK_FIELD (num
, 7, 0, 1);
1740 dis_assemble_3 (num
, &num
);
1741 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1743 /* Handle all completers. */
1748 /* Handle a completer for an indexing load or store. */
1754 while (*s
== ',' && i
< 2)
1757 if (strncasecmp (s
, "sm", 2) == 0)
1764 else if (strncasecmp (s
, "m", 1) == 0)
1766 else if (strncasecmp (s
, "s", 1) == 0)
1768 /* When in strict mode this is a match failure. */
1772 as_bad (_("Invalid Indexed Load Completer."));
1777 as_bad (_("Invalid Indexed Load Completer Syntax."));
1779 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1782 /* Handle a short load/store completer. */
1790 if (strncasecmp (s
, "ma", 2) == 0)
1795 else if (strncasecmp (s
, "mb", 2) == 0)
1800 /* When in strict mode this is a match failure. */
1804 as_bad (_("Invalid Short Load/Store Completer."));
1809 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1812 /* Handle a stbys completer. */
1818 while (*s
== ',' && i
< 2)
1821 if (strncasecmp (s
, "m", 1) == 0)
1823 else if (strncasecmp (s
, "b", 1) == 0)
1825 else if (strncasecmp (s
, "e", 1) == 0)
1827 /* When in strict mode this is a match failure. */
1831 as_bad (_("Invalid Store Bytes Short Completer"));
1836 as_bad (_("Invalid Store Bytes Short Completer"));
1838 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1841 /* Handle a local processor completer. */
1843 if (strncasecmp (s
, ",l", 2) != 0)
1848 /* Handle a PROBE read/write completer. */
1851 if (!strncasecmp (s
, ",w", 2))
1856 else if (!strncasecmp (s
, ",r", 2))
1862 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 6);
1864 /* Handle MFCTL wide completer. */
1866 if (strncasecmp (s
, ",w", 2) != 0)
1871 /* Handle an RFI restore completer. */
1874 if (!strncasecmp (s
, ",r", 2))
1880 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1882 /* Handle a system control completer. */
1884 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
1892 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1894 /* Handle intermediate/final completer for DCOR. */
1897 if (!strncasecmp (s
, ",i", 2))
1903 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 6);
1905 /* Handle zero/sign extension completer. */
1908 if (!strncasecmp (s
, ",z", 2))
1914 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 10);
1916 /* Handle add completer. */
1919 if (!strncasecmp (s
, ",l", 2))
1924 else if (!strncasecmp (s
, ",tsv", 4))
1930 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 10);
1932 /* Handle 64 bit carry for ADD. */
1935 if (!strncasecmp (s
, ",dc,tsv", 7) ||
1936 !strncasecmp (s
, ",tsv,dc", 7))
1941 else if (!strncasecmp (s
, ",dc", 3))
1949 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1951 /* Handle 32 bit carry for ADD. */
1954 if (!strncasecmp (s
, ",c,tsv", 6) ||
1955 !strncasecmp (s
, ",tsv,c", 6))
1960 else if (!strncasecmp (s
, ",c", 2))
1968 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1970 /* Handle trap on signed overflow. */
1973 if (!strncasecmp (s
, ",tsv", 4))
1979 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1981 /* Handle trap on condition and overflow. */
1984 if (!strncasecmp (s
, ",tc,tsv", 7) ||
1985 !strncasecmp (s
, ",tsv,tc", 7))
1990 else if (!strncasecmp (s
, ",tc", 3))
1998 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2000 /* Handle 64 bit borrow for SUB. */
2003 if (!strncasecmp (s
, ",db,tsv", 7) ||
2004 !strncasecmp (s
, ",tsv,db", 7))
2009 else if (!strncasecmp (s
, ",db", 3))
2017 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2019 /* Handle 32 bit borrow for SUB. */
2022 if (!strncasecmp (s
, ",b,tsv", 6) ||
2023 !strncasecmp (s
, ",tsv,b", 6))
2028 else if (!strncasecmp (s
, ",b", 2))
2036 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2038 /* Handle trap condition completer for UADDCM. */
2041 if (!strncasecmp (s
, ",tc", 3))
2047 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 6);
2049 /* Handle signed/unsigned at 21. */
2053 if (strncasecmp (s
, ",s", 2) == 0)
2058 else if (strncasecmp (s
, ",u", 2) == 0)
2064 INSERT_FIELD_AND_CONTINUE (opcode
, sign
, 10);
2067 /* Handle left/right combination at 17:18. */
2077 as_bad(_("Invalid left/right combination completer"));
2080 INSERT_FIELD_AND_CONTINUE (opcode
, lr
, 13);
2083 as_bad(_("Invalid left/right combination completer"));
2086 /* Handle saturation at 24:25. */
2090 if (strncasecmp (s
, ",ss", 3) == 0)
2095 else if (strncasecmp (s
, ",us", 3) == 0)
2101 INSERT_FIELD_AND_CONTINUE (opcode
, sat
, 6);
2104 /* Handle permutation completer. */
2108 int permloc
[4] = {13,10,8,6};
2128 as_bad(_("Invalid permutation completer"));
2130 opcode
|= perm
<< permloc
[i
];
2135 as_bad(_("Invalid permutation completer"));
2143 /* Handle all conditions. */
2149 /* Handle FP compare conditions. */
2151 cond
= pa_parse_fp_cmp_cond (&s
);
2152 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2154 /* Handle an add condition. */
2163 /* 64 bit conditions. */
2176 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2180 if (strcmp (name
, "=") == 0)
2182 else if (strcmp (name
, "<") == 0)
2184 else if (strcmp (name
, "<=") == 0)
2186 else if (strcasecmp (name
, "nuv") == 0)
2188 else if (strcasecmp (name
, "znv") == 0)
2190 else if (strcasecmp (name
, "sv") == 0)
2192 else if (strcasecmp (name
, "od") == 0)
2194 else if (strcasecmp (name
, "tr") == 0)
2199 else if (strcmp (name
, "<>") == 0)
2204 else if (strcmp (name
, ">=") == 0)
2209 else if (strcmp (name
, ">") == 0)
2214 else if (strcasecmp (name
, "uv") == 0)
2219 else if (strcasecmp (name
, "vnz") == 0)
2224 else if (strcasecmp (name
, "nsv") == 0)
2229 else if (strcasecmp (name
, "ev") == 0)
2234 /* ",*" is a valid condition. */
2235 else if (*args
== 'a')
2236 as_bad (_("Invalid Add Condition: %s"), name
);
2239 opcode
|= cmpltr
<< 13;
2240 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2242 /* Handle non-negated add and branch condition. */
2244 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
2247 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s
);
2250 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2252 /* Handle negated add and branch condition. */
2256 /* Handle wide-mode non-negated add and branch condition. */
2260 /* Handle wide-mode negated add and branch condition. */
2264 /* Handle a negated or non-negated add and branch
2268 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
2272 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
2275 as_bad (_("Invalid Compare/Subtract Condition"));
2280 /* Negated condition requires an opcode change. */
2284 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2286 /* Handle branch on bit conditions. */
2304 if (strncmp (s
, "<", 1) == 0)
2309 else if (strncmp (s
, ">=", 2) == 0)
2315 as_bad (_("Invalid Bit Branch Condition: %c"), *s
);
2317 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 15);
2319 /* Handle a compare/subtract condition. */
2328 /* 64 bit conditions. */
2341 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2345 if (strcmp (name
, "=") == 0)
2347 else if (strcmp (name
, "<") == 0)
2349 else if (strcmp (name
, "<=") == 0)
2351 else if (strcasecmp (name
, "<<") == 0)
2353 else if (strcasecmp (name
, "<<=") == 0)
2355 else if (strcasecmp (name
, "sv") == 0)
2357 else if (strcasecmp (name
, "od") == 0)
2359 else if (strcasecmp (name
, "tr") == 0)
2364 else if (strcmp (name
, "<>") == 0)
2369 else if (strcmp (name
, ">=") == 0)
2374 else if (strcmp (name
, ">") == 0)
2379 else if (strcasecmp (name
, ">>=") == 0)
2384 else if (strcasecmp (name
, ">>") == 0)
2389 else if (strcasecmp (name
, "nsv") == 0)
2394 else if (strcasecmp (name
, "ev") == 0)
2399 /* ",*" is a valid condition. */
2400 else if (*args
!= 'S')
2401 as_bad (_("Invalid Compare/Subtract Condition: %s"),
2405 opcode
|= cmpltr
<< 13;
2406 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2408 /* Handle a non-negated compare condition. */
2410 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
2413 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s
);
2416 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2418 /* Handle a negated compare condition. */
2422 /* Handle a 64 bit non-negated compare condition. */
2426 /* Handle a 64 bit negated compare condition. */
2430 /* Handle a 64 bit cmpib condition. */
2434 /* Handle a negated or non-negated compare/subtract
2438 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
2442 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
2445 as_bad (_("Invalid Compare/Subtract Condition."));
2450 /* Negated condition requires an opcode change. */
2455 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2457 /* Handle a logical instruction condition. */
2466 /* 64 bit conditions. */
2479 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2485 if (strcmp (name
, "=") == 0)
2487 else if (strcmp (name
, "<") == 0)
2489 else if (strcmp (name
, "<=") == 0)
2491 else if (strcasecmp (name
, "od") == 0)
2493 else if (strcasecmp (name
, "tr") == 0)
2498 else if (strcmp (name
, "<>") == 0)
2503 else if (strcmp (name
, ">=") == 0)
2508 else if (strcmp (name
, ">") == 0)
2513 else if (strcasecmp (name
, "ev") == 0)
2518 /* ",*" is a valid condition. */
2519 else if (*args
!= 'L')
2520 as_bad (_("Invalid Logical Instruction Condition."));
2523 opcode
|= cmpltr
<< 13;
2524 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2526 /* Handle a shift/extract/deposit condition. */
2535 /* 64 bit conditions. */
2548 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2552 if (strcmp (name
, "=") == 0)
2554 else if (strcmp (name
, "<") == 0)
2556 else if (strcasecmp (name
, "od") == 0)
2558 else if (strcasecmp (name
, "tr") == 0)
2560 else if (strcmp (name
, "<>") == 0)
2562 else if (strcmp (name
, ">=") == 0)
2564 else if (strcasecmp (name
, "ev") == 0)
2566 /* Handle movb,n. Put things back the way they were.
2567 This includes moving s back to where it started. */
2568 else if (strcasecmp (name
, "n") == 0 && *args
== 'y')
2574 /* ",*" is a valid condition. */
2575 else if (*args
!= 'X')
2576 as_bad (_("Invalid Shift/Extract/Deposit Condition."));
2579 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2581 /* Handle a unit instruction condition. */
2590 /* 64 bit conditions. */
2601 if (strncasecmp (s
, "sbz", 3) == 0)
2606 else if (strncasecmp (s
, "shz", 3) == 0)
2611 else if (strncasecmp (s
, "sdc", 3) == 0)
2616 else if (strncasecmp (s
, "sbc", 3) == 0)
2621 else if (strncasecmp (s
, "shc", 3) == 0)
2626 else if (strncasecmp (s
, "tr", 2) == 0)
2632 else if (strncasecmp (s
, "nbz", 3) == 0)
2638 else if (strncasecmp (s
, "nhz", 3) == 0)
2644 else if (strncasecmp (s
, "ndc", 3) == 0)
2650 else if (strncasecmp (s
, "nbc", 3) == 0)
2656 else if (strncasecmp (s
, "nhc", 3) == 0)
2662 /* ",*" is a valid condition. */
2663 else if (*args
!= 'U')
2664 as_bad (_("Invalid Unit Instruction Condition."));
2666 opcode
|= cmpltr
<< 13;
2667 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2675 /* Handle a nullification completer for branch instructions. */
2677 nullif
= pa_parse_nullif (&s
);
2678 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2680 /* Handle a nullification completer for copr and spop insns. */
2682 nullif
= pa_parse_nullif (&s
);
2683 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2685 /* Handle ,gate completer for new syntax branches. */
2687 if (*s
== ',' && strcasecmp (s
+ 1, "gate") == 0)
2693 /* Handle ,l completer for new syntax branches. */
2695 if (*s
== ',' && strcasecmp (s
+ 1, "l") == 0)
2701 /* Handle ,push completer for new syntax branches. */
2703 if (*s
== ',' && strcasecmp (s
+ 1, "push") == 0)
2709 /* Handle ,pop completer for new syntax branches. */
2711 if (*s
== ',' && strcasecmp (s
+ 1, "pop") == 0)
2717 /* Handle ,%r2 completer for new syntax branches. */
2719 if (*s
== ',' && strcasecmp (s
+ 1, "%r2") == 0)
2721 else if (*s
== ',' && strcasecmp (s
+ 1, "%rp") == 0)
2727 /* Handle a 11 bit immediate at 31. */
2729 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2732 if (the_insn
.exp
.X_op
== O_constant
)
2734 num
= evaluate_absolute (&the_insn
);
2735 CHECK_FIELD (num
, 1023, -1024, 0);
2736 low_sign_unext (num
, 11, &num
);
2737 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2741 if (is_DP_relative (the_insn
.exp
))
2742 the_insn
.reloc
= R_HPPA_GOTOFF
;
2743 else if (is_PC_relative (the_insn
.exp
))
2744 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2746 the_insn
.reloc
= R_HPPA
;
2747 the_insn
.format
= 11;
2752 /* Handle a 14 bit immediate at 31. */
2754 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2757 if (the_insn
.exp
.X_op
== O_constant
)
2759 num
= evaluate_absolute (&the_insn
);
2760 CHECK_FIELD (num
, 8191, -8192, 0);
2761 low_sign_unext (num
, 14, &num
);
2762 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2766 if (is_DP_relative (the_insn
.exp
))
2767 the_insn
.reloc
= R_HPPA_GOTOFF
;
2768 else if (is_PC_relative (the_insn
.exp
))
2769 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2771 the_insn
.reloc
= R_HPPA
;
2772 the_insn
.format
= 14;
2776 /* Handle a 21 bit immediate at 31. */
2778 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2781 if (the_insn
.exp
.X_op
== O_constant
)
2783 num
= evaluate_absolute (&the_insn
);
2784 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2785 dis_assemble_21 (num
, &num
);
2786 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2790 if (is_DP_relative (the_insn
.exp
))
2791 the_insn
.reloc
= R_HPPA_GOTOFF
;
2792 else if (is_PC_relative (the_insn
.exp
))
2793 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2795 the_insn
.reloc
= R_HPPA
;
2796 the_insn
.format
= 21;
2800 /* Handle a 12 bit branch displacement. */
2802 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2806 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2808 unsigned int w1
, w
, result
;
2810 num
= evaluate_absolute (&the_insn
);
2813 as_bad (_("Branch to unaligned address"));
2816 CHECK_FIELD (num
, 8199, -8184, 0);
2817 sign_unext ((num
- 8) >> 2, 12, &result
);
2818 dis_assemble_12 (result
, &w1
, &w
);
2819 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2823 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2824 the_insn
.format
= 12;
2825 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2826 memset (&last_call_desc
, 0, sizeof (struct call_desc
));
2831 /* Handle a 17 bit branch displacement. */
2833 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2837 if (!the_insn
.exp
.X_add_symbol
2838 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2841 unsigned int w2
, w1
, w
, result
;
2843 num
= evaluate_absolute (&the_insn
);
2846 as_bad (_("Branch to unaligned address"));
2849 CHECK_FIELD (num
, 262143, -262144, 0);
2851 if (the_insn
.exp
.X_add_symbol
)
2854 sign_unext (num
>> 2, 17, &result
);
2855 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2856 INSERT_FIELD_AND_CONTINUE (opcode
,
2857 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2861 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2862 the_insn
.format
= 17;
2863 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2864 memset (&last_call_desc
, 0, sizeof (struct call_desc
));
2868 /* Handle an absolute 17 bit branch target. */
2870 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2874 if (!the_insn
.exp
.X_add_symbol
2875 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2878 unsigned int w2
, w1
, w
, result
;
2880 num
= evaluate_absolute (&the_insn
);
2883 as_bad (_("Branch to unaligned address"));
2886 CHECK_FIELD (num
, 262143, -262144, 0);
2888 if (the_insn
.exp
.X_add_symbol
)
2891 sign_unext (num
>> 2, 17, &result
);
2892 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2893 INSERT_FIELD_AND_CONTINUE (opcode
,
2894 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2898 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2899 the_insn
.format
= 17;
2900 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2901 memset (&last_call_desc
, 0, sizeof (struct call_desc
));
2905 /* Handle '%r1' implicit operand of addil instruction. */
2907 if (*s
== ',' && *(s
+ 1) == '%' && *(s
+ 3) == '1'
2908 && (*(s
+ 2) == 'r' || *(s
+ 2) == 'R'))
2916 /* Handle a 2 bit shift count at 25. */
2918 num
= pa_get_absolute_expression (&the_insn
, &s
);
2919 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2922 CHECK_FIELD (num
, 3, 1, strict
);
2923 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2925 /* Handle a 4 bit shift count at 25. */
2927 num
= pa_get_absolute_expression (&the_insn
, &s
);
2928 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2931 CHECK_FIELD (num
, 15, 0, strict
);
2932 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2934 /* Handle a 5 bit shift count at 26. */
2936 num
= pa_get_absolute_expression (&the_insn
, &s
);
2937 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2940 CHECK_FIELD (num
, 31, 0, strict
);
2941 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2943 /* Handle a 6 bit shift count at 20,22:26. */
2945 num
= pa_get_absolute_expression (&the_insn
, &s
);
2946 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2949 CHECK_FIELD (num
, 63, 0, strict
);
2951 opcode
|= (num
& 0x20) << 6;
2952 INSERT_FIELD_AND_CONTINUE (opcode
, num
& 0x1f, 5);
2954 /* Handle a 6 bit field length at 23,27:31. */
2957 num
= pa_get_absolute_expression (&the_insn
, &s
);
2958 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2961 CHECK_FIELD (num
, 64, 1, strict
);
2963 opcode
|= (num
& 0x20) << 3;
2964 num
= 31 - (num
& 0x1f);
2965 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2967 /* Handle a 6 bit field length at 19,27:31. */
2969 num
= pa_get_absolute_expression (&the_insn
, &s
);
2970 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2973 CHECK_FIELD (num
, 64, 1, strict
);
2975 opcode
|= (num
& 0x20) << 7;
2976 num
= 31 - (num
& 0x1f);
2977 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2979 /* Handle a 5 bit bit position at 26. */
2981 num
= pa_get_absolute_expression (&the_insn
, &s
);
2982 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2985 CHECK_FIELD (num
, 31, 0, strict
);
2986 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2988 /* Handle a 6 bit bit position at 20,22:26. */
2990 num
= pa_get_absolute_expression (&the_insn
, &s
);
2991 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2994 CHECK_FIELD (num
, 63, 0, strict
);
2995 opcode
|= (num
& 0x20) << 6;
2996 INSERT_FIELD_AND_CONTINUE (opcode
, num
& 0x1f, 5);
2998 /* Handle a 5 bit immediate at 10. */
3000 num
= pa_get_absolute_expression (&the_insn
, &s
);
3001 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3003 if (the_insn
.exp
.X_op
!= O_constant
)
3006 CHECK_FIELD (num
, 31, 0, strict
);
3007 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
3009 /* Handle a 9 bit immediate at 28. */
3011 num
= pa_get_absolute_expression (&the_insn
, &s
);
3012 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3015 CHECK_FIELD (num
, 511, 1, strict
);
3016 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 3);
3018 /* Handle a 13 bit immediate at 18. */
3020 num
= pa_get_absolute_expression (&the_insn
, &s
);
3021 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3024 CHECK_FIELD (num
, 8191, 0, strict
);
3025 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
3027 /* Handle a 26 bit immediate at 31. */
3029 num
= pa_get_absolute_expression (&the_insn
, &s
);
3030 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3033 CHECK_FIELD (num
, 671108864, 0, strict
);
3034 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3036 /* Handle a 3 bit SFU identifier at 25. */
3039 as_bad (_("Invalid SFU identifier"));
3040 num
= pa_get_absolute_expression (&the_insn
, &s
);
3041 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3044 CHECK_FIELD (num
, 7, 0, strict
);
3045 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
3047 /* Handle a 20 bit SOP field for spop0. */
3049 num
= pa_get_absolute_expression (&the_insn
, &s
);
3050 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3053 CHECK_FIELD (num
, 1048575, 0, strict
);
3054 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
3055 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3057 /* Handle a 15bit SOP field for spop1. */
3059 num
= pa_get_absolute_expression (&the_insn
, &s
);
3060 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3063 CHECK_FIELD (num
, 32767, 0, strict
);
3064 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
3066 /* Handle a 10bit SOP field for spop3. */
3068 num
= pa_get_absolute_expression (&the_insn
, &s
);
3069 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3072 CHECK_FIELD (num
, 1023, 0, strict
);
3073 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
3074 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3076 /* Handle a 15 bit SOP field for spop2. */
3078 num
= pa_get_absolute_expression (&the_insn
, &s
);
3079 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3082 CHECK_FIELD (num
, 32767, 0, strict
);
3083 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
3084 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3086 /* Handle a 3-bit co-processor ID field. */
3089 as_bad (_("Invalid COPR identifier"));
3090 num
= pa_get_absolute_expression (&the_insn
, &s
);
3091 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3094 CHECK_FIELD (num
, 7, 0, strict
);
3095 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
3097 /* Handle a 22bit SOP field for copr. */
3099 num
= pa_get_absolute_expression (&the_insn
, &s
);
3100 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3103 CHECK_FIELD (num
, 4194303, 0, strict
);
3104 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
3105 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3108 /* Handle a source FP operand format completer. */
3110 flag
= pa_parse_fp_format (&s
);
3111 the_insn
.fpof1
= flag
;
3112 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
3114 /* Handle a destination FP operand format completer. */
3116 /* pa_parse_format needs the ',' prefix. */
3118 flag
= pa_parse_fp_format (&s
);
3119 the_insn
.fpof2
= flag
;
3120 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
3122 /* Handle a source FP operand format completer at 20. */
3124 flag
= pa_parse_fp_format (&s
);
3125 the_insn
.fpof1
= flag
;
3126 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
3128 /* Handle a floating point operand format at 26.
3129 Only allows single and double precision. */
3131 flag
= pa_parse_fp_format (&s
);
3137 the_insn
.fpof1
= flag
;
3143 as_bad (_("Invalid Floating Point Operand Format."));
3147 /* Handle all floating point registers. */
3151 /* Float target register. */
3153 /* This should be more strict. Small steps. */
3154 if (strict
&& *s
!= '%')
3156 num
= pa_parse_number (&s
, 0);
3157 CHECK_FIELD (num
, 31, 0, 0);
3158 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3160 /* Float target register with L/R selection. */
3163 struct pa_11_fp_reg_struct result
;
3165 /* This should be more strict. Small steps. */
3166 if (strict
&& *s
!= '%')
3168 pa_parse_number (&s
, &result
);
3169 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3170 opcode
|= result
.number_part
;
3172 /* 0x30 opcodes are FP arithmetic operation opcodes
3173 and need to be turned into 0x38 opcodes. This
3174 is not necessary for loads/stores. */
3175 if (need_pa11_opcode (&the_insn
, &result
)
3176 && ((opcode
& 0xfc000000) == 0x30000000))
3179 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
3182 /* Float operand 1. */
3185 struct pa_11_fp_reg_struct result
;
3187 /* This should be more strict. Small steps. */
3188 if (strict
&& *s
!= '%')
3190 pa_parse_number (&s
, &result
);
3191 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3192 opcode
|= result
.number_part
<< 21;
3193 if (need_pa11_opcode (&the_insn
, &result
))
3195 opcode
|= (result
.l_r_select
& 1) << 7;
3201 /* Float operand 1 with L/R selection. */
3205 struct pa_11_fp_reg_struct result
;
3207 /* This should be more strict. Small steps. */
3208 if (strict
&& *s
!= '%')
3210 pa_parse_number (&s
, &result
);
3211 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3212 opcode
|= result
.number_part
<< 21;
3213 opcode
|= (result
.l_r_select
& 1) << 7;
3217 /* Float operand 2. */
3220 struct pa_11_fp_reg_struct result
;
3222 /* This should be more strict. Small steps. */
3223 if (strict
&& *s
!= '%')
3225 pa_parse_number (&s
, &result
);
3226 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3227 opcode
|= (result
.number_part
& 0x1f) << 16;
3228 if (need_pa11_opcode (&the_insn
, &result
))
3230 opcode
|= (result
.l_r_select
& 1) << 12;
3236 /* Float operand 2 with L/R selection. */
3239 struct pa_11_fp_reg_struct result
;
3241 /* This should be more strict. Small steps. */
3242 if (strict
&& *s
!= '%')
3244 pa_parse_number (&s
, &result
);
3245 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3246 opcode
|= (result
.number_part
& 0x1f) << 16;
3247 opcode
|= (result
.l_r_select
& 1) << 12;
3251 /* Float operand 3 for fmpyfadd, fmpynfadd. */
3254 struct pa_11_fp_reg_struct result
;
3257 /* This should be more strict. Small steps. */
3258 if (strict
&& *s
!= '%')
3260 pa_parse_number (&s
, &result
);
3261 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3262 opcode
|= (result
.number_part
& 0x1c) << 11;
3263 opcode
|= (result
.number_part
& 0x3) << 9;
3264 opcode
|= (result
.l_r_select
& 1) << 8;
3268 /* Float mult operand 1 for fmpyadd, fmpysub */
3271 struct pa_11_fp_reg_struct result
;
3273 /* This should be more strict. Small steps. */
3274 if (strict
&& *s
!= '%')
3276 pa_parse_number (&s
, &result
);
3277 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3278 if (the_insn
.fpof1
== SGL
)
3280 if (result
.number_part
< 16)
3282 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3286 result
.number_part
&= 0xF;
3287 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3289 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
3292 /* Float mult operand 2 for fmpyadd, fmpysub */
3295 struct pa_11_fp_reg_struct result
;
3297 /* This should be more strict. Small steps. */
3298 if (strict
&& *s
!= '%')
3300 pa_parse_number (&s
, &result
);
3301 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3302 if (the_insn
.fpof1
== SGL
)
3304 if (result
.number_part
< 16)
3306 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3309 result
.number_part
&= 0xF;
3310 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3312 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
3315 /* Float mult target for fmpyadd, fmpysub */
3318 struct pa_11_fp_reg_struct result
;
3320 /* This should be more strict. Small steps. */
3321 if (strict
&& *s
!= '%')
3323 pa_parse_number (&s
, &result
);
3324 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3325 if (the_insn
.fpof1
== SGL
)
3327 if (result
.number_part
< 16)
3329 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3332 result
.number_part
&= 0xF;
3333 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3335 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
3338 /* Float add operand 1 for fmpyadd, fmpysub */
3341 struct pa_11_fp_reg_struct result
;
3343 /* This should be more strict. Small steps. */
3344 if (strict
&& *s
!= '%')
3346 pa_parse_number (&s
, &result
);
3347 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3348 if (the_insn
.fpof1
== SGL
)
3350 if (result
.number_part
< 16)
3352 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3355 result
.number_part
&= 0xF;
3356 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3358 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
3361 /* Float add target for fmpyadd, fmpysub */
3364 struct pa_11_fp_reg_struct result
;
3366 /* This should be more strict. Small steps. */
3367 if (strict
&& *s
!= '%')
3369 pa_parse_number (&s
, &result
);
3370 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3371 if (the_insn
.fpof1
== SGL
)
3373 if (result
.number_part
< 16)
3375 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3378 result
.number_part
&= 0xF;
3379 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3381 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
3389 /* Handle L/R register halves like 'x'. */
3392 struct pa_11_fp_reg_struct result
;
3394 /* This should be more strict. Small steps. */
3395 if (strict
&& *s
!= '%')
3397 pa_parse_number (&s
, &result
);
3398 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3399 opcode
|= (result
.number_part
& 0x1f) << 16;
3400 if (need_pa11_opcode (&the_insn
, &result
))
3402 opcode
|= (result
.l_r_select
& 1) << 1;
3414 /* Check if the args matched. */
3417 if (&insn
[1] - pa_opcodes
< (int) NUMOPCODES
3418 && !strcmp (insn
->name
, insn
[1].name
))
3426 as_bad (_("Invalid operands %s"), error_message
);
3433 the_insn
.opcode
= opcode
;
3436 /* Turn a string in input_line_pointer into a floating point constant of type
3437 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3438 emitted is stored in *sizeP . An error message or NULL is returned. */
3440 #define MAX_LITTLENUMS 6
3443 md_atof (type
, litP
, sizeP
)
3449 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3450 LITTLENUM_TYPE
*wordP
;
3482 return _("Bad call to MD_ATOF()");
3484 t
= atof_ieee (input_line_pointer
, type
, words
);
3486 input_line_pointer
= t
;
3487 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3488 for (wordP
= words
; prec
--;)
3490 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3491 litP
+= sizeof (LITTLENUM_TYPE
);
3496 /* Write out big-endian. */
3499 md_number_to_chars (buf
, val
, n
)
3504 number_to_chars_bigendian (buf
, val
, n
);
3507 /* Translate internal representation of relocation info to BFD target
3511 tc_gen_reloc (section
, fixp
)
3516 struct hppa_fix_struct
*hppa_fixp
;
3517 bfd_reloc_code_real_type code
;
3518 static arelent
*no_relocs
= NULL
;
3520 bfd_reloc_code_real_type
**codes
;
3524 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
3525 if (fixp
->fx_addsy
== 0)
3527 assert (hppa_fixp
!= 0);
3528 assert (section
!= 0);
3530 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3532 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3533 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3534 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
3536 hppa_fixp
->fx_r_format
,
3537 hppa_fixp
->fx_r_field
,
3538 fixp
->fx_subsy
!= NULL
,
3539 symbol_get_bfdsym (fixp
->fx_addsy
));
3544 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
3547 relocs
= (arelent
**) xmalloc (sizeof (arelent
*) * n_relocs
+ 1);
3548 reloc
= (arelent
*) xmalloc (sizeof (arelent
) * n_relocs
);
3549 for (i
= 0; i
< n_relocs
; i
++)
3550 relocs
[i
] = &reloc
[i
];
3552 relocs
[n_relocs
] = NULL
;
3555 switch (fixp
->fx_r_type
)
3558 assert (n_relocs
== 1);
3562 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3563 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3564 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3565 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3566 reloc
->addend
= 0; /* default */
3568 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
3570 /* Now, do any processing that is dependent on the relocation type. */
3573 case R_PARISC_DLTREL21L
:
3574 case R_PARISC_DLTREL14R
:
3575 case R_PARISC_DLTREL14F
:
3576 case R_PARISC_PLABEL32
:
3577 case R_PARISC_PLABEL21L
:
3578 case R_PARISC_PLABEL14R
:
3579 /* For plabel relocations, the addend of the
3580 relocation should be either 0 (no static link) or 2
3581 (static link required).
3583 FIXME: We always assume no static link!
3585 We also slam a zero addend into the DLT relative relocs;
3586 it doesn't make a lot of sense to use any addend since
3587 it gets you a different (eg unknown) DLT entry. */
3591 case R_PARISC_PCREL21L
:
3592 case R_PARISC_PCREL17R
:
3593 case R_PARISC_PCREL17F
:
3594 case R_PARISC_PCREL17C
:
3595 case R_PARISC_PCREL14R
:
3596 case R_PARISC_PCREL14F
:
3597 /* The constant is stored in the instruction. */
3598 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
3601 reloc
->addend
= fixp
->fx_offset
;
3608 /* Walk over reach relocation returned by the BFD backend. */
3609 for (i
= 0; i
< n_relocs
; i
++)
3613 relocs
[i
]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3614 *relocs
[i
]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3615 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3616 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3621 /* The only time we ever use a R_COMP2 fixup is for the difference
3622 of two symbols. With that in mind we fill in all four
3623 relocs now and break out of the loop. */
3625 relocs
[0]->sym_ptr_ptr
= (asymbol
**) &(bfd_abs_symbol
);
3626 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
3627 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3628 relocs
[0]->addend
= 0;
3629 relocs
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3630 *relocs
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3631 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
3632 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3633 relocs
[1]->addend
= 0;
3634 relocs
[2]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3635 *relocs
[2]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
3636 relocs
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[2]);
3637 relocs
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3638 relocs
[2]->addend
= 0;
3639 relocs
[3]->sym_ptr_ptr
= (asymbol
**) &(bfd_abs_symbol
);
3640 relocs
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[3]);
3641 relocs
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3642 relocs
[3]->addend
= 0;
3643 relocs
[4]->sym_ptr_ptr
= (asymbol
**) &(bfd_abs_symbol
);
3644 relocs
[4]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[4]);
3645 relocs
[4]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3646 relocs
[4]->addend
= 0;
3650 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
3656 /* For plabel relocations, the addend of the
3657 relocation should be either 0 (no static link) or 2
3658 (static link required).
3660 FIXME: We always assume no static link!
3662 We also slam a zero addend into the DLT relative relocs;
3663 it doesn't make a lot of sense to use any addend since
3664 it gets you a different (eg unknown) DLT entry. */
3665 relocs
[i
]->addend
= 0;
3680 /* There is no symbol or addend associated with these fixups. */
3681 relocs
[i
]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3682 *relocs
[i
]->sym_ptr_ptr
= symbol_get_bfdsym (dummy_symbol
);
3683 relocs
[i
]->addend
= 0;
3689 /* There is no symbol associated with these fixups. */
3690 relocs
[i
]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3691 *relocs
[i
]->sym_ptr_ptr
= symbol_get_bfdsym (dummy_symbol
);
3692 relocs
[i
]->addend
= fixp
->fx_offset
;
3696 relocs
[i
]->addend
= fixp
->fx_offset
;
3706 /* Process any machine dependent frag types. */
3709 md_convert_frag (abfd
, sec
, fragP
)
3711 register asection
*sec
;
3712 register fragS
*fragP
;
3714 unsigned int address
;
3716 if (fragP
->fr_type
== rs_machine_dependent
)
3718 switch ((int) fragP
->fr_subtype
)
3721 fragP
->fr_type
= rs_fill
;
3722 know (fragP
->fr_var
== 1);
3723 know (fragP
->fr_next
);
3724 address
= fragP
->fr_address
+ fragP
->fr_fix
;
3725 if (address
% fragP
->fr_offset
)
3728 fragP
->fr_next
->fr_address
3733 fragP
->fr_offset
= 0;
3739 /* Round up a section size to the appropriate boundary. */
3742 md_section_align (segment
, size
)
3746 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3747 int align2
= (1 << align
) - 1;
3749 return (size
+ align2
) & ~align2
;
3752 /* Return the approximate size of a frag before relaxation has occurred. */
3754 md_estimate_size_before_relax (fragP
, segment
)
3755 register fragS
*fragP
;
3762 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3768 CONST
char *md_shortopts
= "";
3769 struct option md_longopts
[] = {
3770 {NULL
, no_argument
, NULL
, 0}
3772 size_t md_longopts_size
= sizeof(md_longopts
);
3775 md_parse_option (c
, arg
)
3783 md_show_usage (stream
)
3788 /* We have no need to default values of symbols. */
3791 md_undefined_symbol (name
)
3797 /* Apply a fixup to an instruction. */
3800 md_apply_fix (fixP
, valp
)
3804 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3805 struct hppa_fix_struct
*hppa_fixP
;
3806 long new_val
, result
= 0;
3807 unsigned int w1
, w2
, w
, resulti
;
3809 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
3810 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3811 never be "applied" (they are just markers). Likewise for
3812 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
3814 if (fixP
->fx_r_type
== R_HPPA_ENTRY
3815 || fixP
->fx_r_type
== R_HPPA_EXIT
3816 || fixP
->fx_r_type
== R_HPPA_BEGIN_BRTAB
3817 || fixP
->fx_r_type
== R_HPPA_END_BRTAB
3818 || fixP
->fx_r_type
== R_HPPA_BEGIN_TRY
)
3821 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
3822 fixups are considered not adjustable, which in turn causes
3823 adjust_reloc_syms to not set fx_offset. Ugh. */
3824 if (fixP
->fx_r_type
== R_HPPA_END_TRY
)
3826 fixP
->fx_offset
= *valp
;
3831 /* There should have been an HPPA specific fixup associated
3832 with the GAS fixup. */
3835 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3836 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3838 /* If there is a symbol associated with this fixup, then it's something
3839 which will need a SOM relocation (except for some PC-relative relocs).
3840 In such cases we should treat the "val" or "addend" as zero since it
3841 will be added in as needed from fx_offset in tc_gen_reloc. */
3842 if ((fixP
->fx_addsy
!= NULL
3843 || fixP
->fx_r_type
== R_HPPA_NONE
)
3848 new_val
= ((fmt
== 12 || fmt
== 17 || fmt
== 22) ? 8 : 0);
3850 /* These field selectors imply that we do not want an addend. */
3851 else if (hppa_fixP
->fx_r_field
== e_psel
3852 || hppa_fixP
->fx_r_field
== e_rpsel
3853 || hppa_fixP
->fx_r_field
== e_lpsel
3854 || hppa_fixP
->fx_r_field
== e_tsel
3855 || hppa_fixP
->fx_r_field
== e_rtsel
3856 || hppa_fixP
->fx_r_field
== e_ltsel
)
3857 new_val
= ((fmt
== 12 || fmt
== 17 || fmt
== 22) ? 8 : 0);
3858 /* This is truely disgusting. The machine independent code blindly
3859 adds in the value of the symbol being relocated against. Damn! */
3861 && fixP
->fx_addsy
!= NULL
3862 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
3863 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
3864 0, hppa_fixP
->fx_r_field
);
3867 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
3869 /* Handle pc-relative exceptions from above. */
3870 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3871 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3872 if ((fmt
== 12 || fmt
== 17 || fmt
== 22)
3876 && !arg_reloc_stub_needed ((long) ((obj_symbol_type
*)
3877 symbol_get_bfdsym (fixP
->fx_addsy
))->tc_data
.ap
.hppa_arg_reloc
,
3878 hppa_fixP
->fx_arg_reloc
)
3880 && (((int)(*valp
) > -262144 && (int)(*valp
) < 262143) && fmt
!= 22)
3881 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
3883 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
3885 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
3886 #undef arg_reloc_stub_needed
3890 /* Handle all opcodes with the 'j' operand type. */
3892 CHECK_FIELD (new_val
, 8191, -8192, 0);
3894 /* Mask off 14 bits to be changed. */
3895 bfd_put_32 (stdoutput
,
3896 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3898 low_sign_unext (new_val
, 14, &resulti
);
3902 /* Handle all opcodes with the 'k' operand type. */
3904 CHECK_FIELD (new_val
, 2097152, 0, 0);
3906 /* Mask off 21 bits to be changed. */
3907 bfd_put_32 (stdoutput
,
3908 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3910 dis_assemble_21 (new_val
, &resulti
);
3914 /* Handle all the opcodes with the 'i' operand type. */
3916 CHECK_FIELD (new_val
, 1023, -1023, 0);
3918 /* Mask off 11 bits to be changed. */
3919 bfd_put_32 (stdoutput
,
3920 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3922 low_sign_unext (new_val
, 11, &resulti
);
3926 /* Handle all the opcodes with the 'w' operand type. */
3928 CHECK_FIELD (new_val
, 8199, -8184, 0);
3930 /* Mask off 11 bits to be changed. */
3931 sign_unext ((new_val
- 8) >> 2, 12, &resulti
);
3932 bfd_put_32 (stdoutput
,
3933 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3936 dis_assemble_12 (resulti
, &w1
, &w
);
3937 result
= ((w1
<< 2) | w
);
3940 /* Handle some of the opcodes with the 'W' operand type. */
3943 int distance
= *valp
;
3945 CHECK_FIELD (new_val
, 262143, -262144, 0);
3947 /* If this is an absolute branch (ie no link) with an out of
3948 range target, then we want to complain. */
3949 if (fixP
->fx_r_type
== R_HPPA_PCREL_CALL
3950 && (distance
> 262143 || distance
< -262144)
3951 && (bfd_get_32 (stdoutput
, buf
) & 0xffe00000) == 0xe8000000)
3952 CHECK_FIELD (distance
, 262143, -262144, 0);
3954 /* Mask off 17 bits to be changed. */
3955 bfd_put_32 (stdoutput
,
3956 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3958 sign_unext ((new_val
- 8) >> 2, 17, &resulti
);
3959 dis_assemble_17 (resulti
, &w1
, &w2
, &w
);
3960 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3966 bfd_put_32 (stdoutput
, new_val
, buf
);
3970 as_bad (_("Unknown relocation encountered in md_apply_fix."));
3974 /* Insert the relocation. */
3975 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3980 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
3981 (unsigned int) fixP
, fixP
->fx_r_type
);
3986 /* Exactly what point is a PC-relative offset relative TO?
3987 On the PA, they're relative to the address of the offset. */
3990 md_pcrel_from (fixP
)
3993 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3996 /* Return nonzero if the input line pointer is at the end of
4000 is_end_of_statement ()
4002 return ((*input_line_pointer
== '\n')
4003 || (*input_line_pointer
== ';')
4004 || (*input_line_pointer
== '!'));
4007 /* Read a number from S. The number might come in one of many forms,
4008 the most common will be a hex or decimal constant, but it could be
4009 a pre-defined register (Yuk!), or an absolute symbol.
4011 Return a number or -1 for failure.
4013 When parsing PA-89 FP register numbers RESULT will be
4014 the address of a structure to return information about
4015 L/R half of FP registers, store results there as appropriate.
4017 pa_parse_number can not handle negative constants and will fail
4018 horribly if it is passed such a constant. */
4021 pa_parse_number (s
, result
)
4023 struct pa_11_fp_reg_struct
*result
;
4032 /* Skip whitespace before the number. */
4033 while (*p
== ' ' || *p
== '\t')
4036 /* Store info in RESULT if requested by caller. */
4039 result
->number_part
= -1;
4040 result
->l_r_select
= -1;
4046 /* Looks like a number. */
4049 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
4051 /* The number is specified in hex. */
4053 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
4054 || ((*p
>= 'A') && (*p
<= 'F')))
4057 num
= num
* 16 + *p
- '0';
4058 else if (*p
>= 'a' && *p
<= 'f')
4059 num
= num
* 16 + *p
- 'a' + 10;
4061 num
= num
* 16 + *p
- 'A' + 10;
4067 /* The number is specified in decimal. */
4068 while (isdigit (*p
))
4070 num
= num
* 10 + *p
- '0';
4075 /* Store info in RESULT if requested by the caller. */
4078 result
->number_part
= num
;
4080 if (IS_R_SELECT (p
))
4082 result
->l_r_select
= 1;
4085 else if (IS_L_SELECT (p
))
4087 result
->l_r_select
= 0;
4091 result
->l_r_select
= 0;
4096 /* The number might be a predefined register. */
4101 /* Tege hack: Special case for general registers as the general
4102 code makes a binary search with case translation, and is VERY
4107 if (*p
== 'e' && *(p
+ 1) == 't'
4108 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
4111 num
= *p
- '0' + 28;
4119 else if (!isdigit (*p
))
4122 as_bad (_("Undefined register: '%s'."), name
);
4128 num
= num
* 10 + *p
++ - '0';
4129 while (isdigit (*p
));
4134 /* Do a normal register search. */
4135 while (is_part_of_name (c
))
4141 status
= reg_name_search (name
);
4147 as_bad (_("Undefined register: '%s'."), name
);
4153 /* Store info in RESULT if requested by caller. */
4156 result
->number_part
= num
;
4157 if (IS_R_SELECT (p
- 1))
4158 result
->l_r_select
= 1;
4159 else if (IS_L_SELECT (p
- 1))
4160 result
->l_r_select
= 0;
4162 result
->l_r_select
= 0;
4167 /* And finally, it could be a symbol in the absolute section which
4168 is effectively a constant. */
4172 while (is_part_of_name (c
))
4178 if ((sym
= symbol_find (name
)) != NULL
)
4180 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
4181 num
= S_GET_VALUE (sym
);
4185 as_bad (_("Non-absolute symbol: '%s'."), name
);
4191 /* There is where we'd come for an undefined symbol
4192 or for an empty string. For an empty string we
4193 will return zero. That's a concession made for
4194 compatability with the braindamaged HP assemblers. */
4200 as_bad (_("Undefined absolute constant: '%s'."), name
);
4206 /* Store info in RESULT if requested by caller. */
4209 result
->number_part
= num
;
4210 if (IS_R_SELECT (p
- 1))
4211 result
->l_r_select
= 1;
4212 else if (IS_L_SELECT (p
- 1))
4213 result
->l_r_select
= 0;
4215 result
->l_r_select
= 0;
4223 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
4225 /* Given NAME, find the register number associated with that name, return
4226 the integer value associated with the given name or -1 on failure. */
4229 reg_name_search (name
)
4232 int middle
, low
, high
;
4236 high
= REG_NAME_CNT
- 1;
4240 middle
= (low
+ high
) / 2;
4241 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
4247 return pre_defined_registers
[middle
].value
;
4249 while (low
<= high
);
4255 /* Return nonzero if the given INSN and L/R information will require
4256 a new PA-1.1 opcode. */
4259 need_pa11_opcode (insn
, result
)
4261 struct pa_11_fp_reg_struct
*result
;
4263 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
4265 /* If this instruction is specific to a particular architecture,
4266 then set a new architecture. */
4267 if (bfd_get_mach (stdoutput
) < pa11
)
4269 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
4270 as_warn (_("could not update architecture and machine"));
4278 /* Parse a condition for a fcmp instruction. Return the numerical
4279 code associated with the condition. */
4282 pa_parse_fp_cmp_cond (s
)
4289 for (i
= 0; i
< 32; i
++)
4291 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
4292 strlen (fp_cond_map
[i
].string
)) == 0)
4294 cond
= fp_cond_map
[i
].cond
;
4295 *s
+= strlen (fp_cond_map
[i
].string
);
4296 /* If not a complete match, back up the input string and
4298 if (**s
!= ' ' && **s
!= '\t')
4300 *s
-= strlen (fp_cond_map
[i
].string
);
4303 while (**s
== ' ' || **s
== '\t')
4309 as_bad (_("Invalid FP Compare Condition: %s"), *s
);
4311 /* Advance over the bogus completer. */
4312 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4319 /* Parse an FP operand format completer returning the completer
4322 static fp_operand_format
4323 pa_parse_fp_format (s
)
4332 if (strncasecmp (*s
, "sgl", 3) == 0)
4337 else if (strncasecmp (*s
, "dbl", 3) == 0)
4342 else if (strncasecmp (*s
, "quad", 4) == 0)
4349 format
= ILLEGAL_FMT
;
4350 as_bad (_("Invalid FP Operand Format: %3s"), *s
);
4357 /* Convert from a selector string into a selector type. */
4360 pa_chk_field_selector (str
)
4363 int middle
, low
, high
;
4367 /* Read past any whitespace. */
4368 /* FIXME: should we read past newlines and formfeeds??? */
4369 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
4372 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
4373 name
[0] = tolower ((*str
)[0]),
4375 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
4376 name
[0] = tolower ((*str
)[0]),
4377 name
[1] = tolower ((*str
)[1]),
4379 else if ((*str
)[3] == '\'' || (*str
)[3] == '%')
4380 name
[0] = tolower ((*str
)[0]),
4381 name
[1] = tolower ((*str
)[1]),
4382 name
[2] = tolower ((*str
)[2]),
4388 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
4392 middle
= (low
+ high
) / 2;
4393 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
4400 *str
+= strlen (name
) + 1;
4402 if (selector_table
[middle
].field_selector
== e_nsel
)
4405 return selector_table
[middle
].field_selector
;
4408 while (low
<= high
);
4413 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
4416 get_expression (str
)
4422 save_in
= input_line_pointer
;
4423 input_line_pointer
= str
;
4424 seg
= expression (&the_insn
.exp
);
4425 if (!(seg
== absolute_section
4426 || seg
== undefined_section
4427 || SEG_NORMAL (seg
)))
4429 as_warn (_("Bad segment in expression."));
4430 expr_end
= input_line_pointer
;
4431 input_line_pointer
= save_in
;
4434 expr_end
= input_line_pointer
;
4435 input_line_pointer
= save_in
;
4439 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
4441 pa_get_absolute_expression (insn
, strp
)
4447 insn
->field_selector
= pa_chk_field_selector (strp
);
4448 save_in
= input_line_pointer
;
4449 input_line_pointer
= *strp
;
4450 expression (&insn
->exp
);
4451 /* This is not perfect, but is a huge improvement over doing nothing.
4453 The PA assembly syntax is ambigious in a variety of ways. Consider
4454 this string "4 %r5" Is that the number 4 followed by the register
4455 r5, or is that 4 MOD 5?
4457 If we get a modulo expresion When looking for an absolute, we try
4458 again cutting off the input string at the first whitespace character. */
4459 if (insn
->exp
.X_op
== O_modulus
)
4464 input_line_pointer
= *strp
;
4466 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
4472 retval
= pa_get_absolute_expression (insn
, strp
);
4474 input_line_pointer
= save_in
;
4476 return evaluate_absolute (insn
);
4478 /* When in strict mode we have a non-match, fix up the pointers
4479 and return to our caller. */
4480 if (insn
->exp
.X_op
!= O_constant
&& strict
)
4482 expr_end
= input_line_pointer
;
4483 input_line_pointer
= save_in
;
4486 if (insn
->exp
.X_op
!= O_constant
)
4488 as_bad (_("Bad segment (should be absolute)."));
4489 expr_end
= input_line_pointer
;
4490 input_line_pointer
= save_in
;
4493 expr_end
= input_line_pointer
;
4494 input_line_pointer
= save_in
;
4495 return evaluate_absolute (insn
);
4498 /* Evaluate an absolute expression EXP which may be modified by
4499 the selector FIELD_SELECTOR. Return the value of the expression. */
4501 evaluate_absolute (insn
)
4506 int field_selector
= insn
->field_selector
;
4509 value
= exp
.X_add_number
;
4511 switch (field_selector
)
4517 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
4519 if (value
& 0x00000400)
4521 value
= (value
& 0xfffff800) >> 11;
4524 /* Sign extend from bit 21. */
4526 if (value
& 0x00000400)
4527 value
|= 0xfffff800;
4532 /* Arithmetic shift right 11 bits. */
4534 value
= (value
& 0xfffff800) >> 11;
4537 /* Set bits 0-20 to zero. */
4539 value
= value
& 0x7ff;
4542 /* Add 0x800 and arithmetic shift right 11 bits. */
4545 value
= (value
& 0xfffff800) >> 11;
4548 /* Set bitgs 0-21 to one. */
4550 value
|= 0xfffff800;
4553 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
4555 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
4559 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
4564 BAD_CASE (field_selector
);
4570 /* Given an argument location specification return the associated
4571 argument location number. */
4574 pa_build_arg_reloc (type_name
)
4578 if (strncasecmp (type_name
, "no", 2) == 0)
4580 if (strncasecmp (type_name
, "gr", 2) == 0)
4582 else if (strncasecmp (type_name
, "fr", 2) == 0)
4584 else if (strncasecmp (type_name
, "fu", 2) == 0)
4587 as_bad (_("Invalid argument location: %s\n"), type_name
);
4592 /* Encode and return an argument relocation specification for
4593 the given register in the location specified by arg_reloc. */
4596 pa_align_arg_reloc (reg
, arg_reloc
)
4598 unsigned int arg_reloc
;
4600 unsigned int new_reloc
;
4602 new_reloc
= arg_reloc
;
4618 as_bad (_("Invalid argument description: %d"), reg
);
4624 /* Parse a PA nullification completer (,n). Return nonzero if the
4625 completer was found; return zero if no completer was found. */
4637 if (strncasecmp (*s
, "n", 1) == 0)
4641 as_bad (_("Invalid Nullification: (%c)"), **s
);
4650 /* Parse a non-negated compare/subtract completer returning the
4651 number (for encoding in instrutions) of the given completer.
4653 ISBRANCH specifies whether or not this is parsing a condition
4654 completer for a branch (vs a nullification completer for a
4655 computational instruction. */
4658 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
4663 char *name
= *s
+ 1;
4672 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4678 if (strcmp (name
, "=") == 0)
4682 else if (strcmp (name
, "<") == 0)
4686 else if (strcmp (name
, "<=") == 0)
4690 else if (strcmp (name
, "<<") == 0)
4694 else if (strcmp (name
, "<<=") == 0)
4698 else if (strcasecmp (name
, "sv") == 0)
4702 else if (strcasecmp (name
, "od") == 0)
4706 /* If we have something like addb,n then there is no condition
4708 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4720 /* Reset pointers if this was really a ,n for a branch instruction. */
4728 /* Parse a negated compare/subtract completer returning the
4729 number (for encoding in instrutions) of the given completer.
4731 ISBRANCH specifies whether or not this is parsing a condition
4732 completer for a branch (vs a nullification completer for a
4733 computational instruction. */
4736 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
4741 char *name
= *s
+ 1;
4750 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4756 if (strcasecmp (name
, "tr") == 0)
4760 else if (strcmp (name
, "<>") == 0)
4764 else if (strcmp (name
, ">=") == 0)
4768 else if (strcmp (name
, ">") == 0)
4772 else if (strcmp (name
, ">>=") == 0)
4776 else if (strcmp (name
, ">>") == 0)
4780 else if (strcasecmp (name
, "nsv") == 0)
4784 else if (strcasecmp (name
, "ev") == 0)
4788 /* If we have something like addb,n then there is no condition
4790 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4802 /* Reset pointers if this was really a ,n for a branch instruction. */
4811 /* Parse a non-negated addition completer returning the number
4812 (for encoding in instrutions) of the given completer.
4814 ISBRANCH specifies whether or not this is parsing a condition
4815 completer for a branch (vs a nullification completer for a
4816 computational instruction. */
4819 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
4824 char *name
= *s
+ 1;
4832 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4836 if (strcmp (name
, "=") == 0)
4840 else if (strcmp (name
, "<") == 0)
4844 else if (strcmp (name
, "<=") == 0)
4848 else if (strcasecmp (name
, "nuv") == 0)
4852 else if (strcasecmp (name
, "znv") == 0)
4856 else if (strcasecmp (name
, "sv") == 0)
4860 else if (strcasecmp (name
, "od") == 0)
4864 /* If we have something like addb,n then there is no condition
4866 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4877 /* Reset pointers if this was really a ,n for a branch instruction. */
4878 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4884 /* Parse a negated addition completer returning the number
4885 (for encoding in instrutions) of the given completer.
4887 ISBRANCH specifies whether or not this is parsing a condition
4888 completer for a branch (vs a nullification completer for a
4889 computational instruction). */
4892 pa_parse_neg_add_cmpltr (s
, isbranch
)
4897 char *name
= *s
+ 1;
4905 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4909 if (strcasecmp (name
, "tr") == 0)
4913 else if (strcmp (name
, "<>") == 0)
4917 else if (strcmp (name
, ">=") == 0)
4921 else if (strcmp (name
, ">") == 0)
4925 else if (strcasecmp (name
, "uv") == 0)
4929 else if (strcasecmp (name
, "vnz") == 0)
4933 else if (strcasecmp (name
, "nsv") == 0)
4937 else if (strcasecmp (name
, "ev") == 0)
4941 /* If we have something like addb,n then there is no condition
4943 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4954 /* Reset pointers if this was really a ,n for a branch instruction. */
4955 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4962 /* Handle an alignment directive. Special so that we can update the
4963 alignment of the subspace if necessary. */
4967 /* We must have a valid space and subspace. */
4968 pa_check_current_space_and_subspace ();
4970 /* Let the generic gas code do most of the work. */
4971 s_align_bytes (bytes
);
4973 /* If bytes is a power of 2, then update the current subspace's
4974 alignment if necessary. */
4975 if (log2 (bytes
) != -1)
4976 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
4980 /* Handle a .BLOCK type pseudo-op. */
4988 unsigned int temp_size
;
4992 /* We must have a valid space and subspace. */
4993 pa_check_current_space_and_subspace ();
4996 temp_size
= get_absolute_expression ();
4998 /* Always fill with zeros, that's what the HP assembler does. */
5001 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
5002 (relax_substateT
) 0, (symbolS
*) 0, (offsetT
) 1, NULL
);
5003 memset (p
, 0, temp_size
);
5005 /* Convert 2 bytes at a time. */
5007 for (i
= 0; i
< temp_size
; i
+= 2)
5009 md_number_to_chars (p
+ i
,
5011 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
5014 pa_undefine_label ();
5015 demand_empty_rest_of_line ();
5018 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
5026 /* The BRTAB relocations are only availble in SOM (to denote
5027 the beginning and end of branch tables). */
5028 char *where
= frag_more (0);
5030 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5031 NULL
, (offsetT
) 0, NULL
,
5032 0, begin
? R_HPPA_BEGIN_BRTAB
: R_HPPA_END_BRTAB
,
5033 e_fsel
, 0, 0, NULL
);
5036 demand_empty_rest_of_line ();
5039 /* Handle a .begin_try and .end_try pseudo-op. */
5047 char *where
= frag_more (0);
5052 /* The TRY relocations are only availble in SOM (to denote
5053 the beginning and end of exception handling regions). */
5055 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5056 NULL
, (offsetT
) 0, begin
? NULL
: &exp
,
5057 0, begin
? R_HPPA_BEGIN_TRY
: R_HPPA_END_TRY
,
5058 e_fsel
, 0, 0, NULL
);
5061 demand_empty_rest_of_line ();
5064 /* Handle a .CALL pseudo-op. This involves storing away information
5065 about where arguments are to be found so the linker can detect
5066 (and correct) argument location mismatches between caller and callee. */
5073 /* We must have a valid space and subspace. */
5074 pa_check_current_space_and_subspace ();
5077 pa_call_args (&last_call_desc
);
5078 demand_empty_rest_of_line ();
5081 /* Do the dirty work of building a call descriptor which describes
5082 where the caller placed arguments to a function call. */
5085 pa_call_args (call_desc
)
5086 struct call_desc
*call_desc
;
5089 unsigned int temp
, arg_reloc
;
5091 while (!is_end_of_statement ())
5093 name
= input_line_pointer
;
5094 c
= get_symbol_end ();
5095 /* Process a source argument. */
5096 if ((strncasecmp (name
, "argw", 4) == 0))
5098 temp
= atoi (name
+ 4);
5099 p
= input_line_pointer
;
5101 input_line_pointer
++;
5102 name
= input_line_pointer
;
5103 c
= get_symbol_end ();
5104 arg_reloc
= pa_build_arg_reloc (name
);
5105 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
5107 /* Process a return value. */
5108 else if ((strncasecmp (name
, "rtnval", 6) == 0))
5110 p
= input_line_pointer
;
5112 input_line_pointer
++;
5113 name
= input_line_pointer
;
5114 c
= get_symbol_end ();
5115 arg_reloc
= pa_build_arg_reloc (name
);
5116 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
5120 as_bad (_("Invalid .CALL argument: %s"), name
);
5122 p
= input_line_pointer
;
5124 if (!is_end_of_statement ())
5125 input_line_pointer
++;
5129 /* Return TRUE if FRAG1 and FRAG2 are the same. */
5132 is_same_frag (frag1
, frag2
)
5139 else if (frag2
== NULL
)
5141 else if (frag1
== frag2
)
5143 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
5144 return (is_same_frag (frag1
, frag2
->fr_next
));
5150 /* Build an entry in the UNWIND subspace from the given function
5151 attributes in CALL_INFO. This is not needed for SOM as using
5152 R_ENTRY and R_EXIT relocations allow the linker to handle building
5153 of the unwind spaces. */
5156 pa_build_unwind_subspace (call_info
)
5157 struct call_info
*call_info
;
5160 asection
*seg
, *save_seg
;
5162 subsegT subseg
, save_subseg
;
5166 if (now_seg
!= text_section
)
5169 if (bfd_get_arch_info (stdoutput
)->bits_per_address
== 32)
5170 reloc
= R_PARISC_DIR32
;
5172 reloc
= R_PARISC_SEGREL32
;
5174 /* Get into the right seg/subseg. This may involve creating
5175 the seg the first time through. Make sure to have the
5176 old seg/subseg so that we can reset things when we are done. */
5177 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
5178 if (seg
== ASEC_NULL
)
5180 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
5181 bfd_set_section_flags (stdoutput
, seg
,
5182 SEC_READONLY
| SEC_HAS_CONTENTS
5183 | SEC_LOAD
| SEC_RELOC
| SEC_ALLOC
| SEC_DATA
);
5184 bfd_set_section_alignment (stdoutput
, seg
, 2);
5188 save_subseg
= now_subseg
;
5189 subseg_set (seg
, 0);
5192 /* Get some space to hold relocation information for the unwind
5195 md_number_to_chars (p
, 0, 4);
5197 /* Relocation info. for start offset of the function. */
5198 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
5199 call_info
->start_symbol
, (offsetT
) 0,
5200 (expressionS
*) NULL
, 0, reloc
,
5201 e_fsel
, 32, 0, NULL
);
5204 md_number_to_chars (p
, 0, 4);
5206 /* Relocation info. for end offset of the function.
5208 Because we allow reductions of 32bit relocations for ELF, this will be
5209 reduced to section_sym + offset which avoids putting the temporary
5210 symbol into the symbol table. It (should) end up giving the same
5211 value as call_info->start_symbol + function size once the linker is
5212 finished with its work. */
5214 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
5215 call_info
->end_symbol
, (offsetT
) 0,
5216 (expressionS
*) NULL
, 0, reloc
,
5217 e_fsel
, 32, 0, NULL
);
5220 unwind
= (char *) &call_info
->ci_unwind
;
5221 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
5225 FRAG_APPEND_1_CHAR (c
);
5229 /* Return back to the original segment/subsegment. */
5230 subseg_set (save_seg
, save_subseg
);
5234 /* Process a .CALLINFO pseudo-op. This information is used later
5235 to build unwind descriptors and maybe one day to support
5236 .ENTER and .LEAVE. */
5239 pa_callinfo (unused
)
5246 /* We must have a valid space and subspace. */
5247 pa_check_current_space_and_subspace ();
5250 /* .CALLINFO must appear within a procedure definition. */
5251 if (!within_procedure
)
5252 as_bad (_(".callinfo is not within a procedure definition"));
5254 /* Mark the fact that we found the .CALLINFO for the
5255 current procedure. */
5256 callinfo_found
= TRUE
;
5258 /* Iterate over the .CALLINFO arguments. */
5259 while (!is_end_of_statement ())
5261 name
= input_line_pointer
;
5262 c
= get_symbol_end ();
5263 /* Frame size specification. */
5264 if ((strncasecmp (name
, "frame", 5) == 0))
5266 p
= input_line_pointer
;
5268 input_line_pointer
++;
5269 temp
= get_absolute_expression ();
5270 if ((temp
& 0x3) != 0)
5272 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp
);
5276 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
5277 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
5280 /* Entry register (GR, GR and SR) specifications. */
5281 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
5283 p
= input_line_pointer
;
5285 input_line_pointer
++;
5286 temp
= get_absolute_expression ();
5287 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
5288 even though %r19 is caller saved. I think this is a bug in
5289 the HP assembler, and we are not going to emulate it. */
5290 if (temp
< 3 || temp
> 18)
5291 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
5292 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
5294 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
5296 p
= input_line_pointer
;
5298 input_line_pointer
++;
5299 temp
= get_absolute_expression ();
5300 /* Similarly the HP assembler takes 31 as the high bound even
5301 though %fr21 is the last callee saved floating point register. */
5302 if (temp
< 12 || temp
> 21)
5303 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
5304 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
5306 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
5308 p
= input_line_pointer
;
5310 input_line_pointer
++;
5311 temp
= get_absolute_expression ();
5313 as_bad (_("Value for ENTRY_SR must be 3\n"));
5315 /* Note whether or not this function performs any calls. */
5316 else if ((strncasecmp (name
, "calls", 5) == 0) ||
5317 (strncasecmp (name
, "caller", 6) == 0))
5319 p
= input_line_pointer
;
5322 else if ((strncasecmp (name
, "no_calls", 8) == 0))
5324 p
= input_line_pointer
;
5327 /* Should RP be saved into the stack. */
5328 else if ((strncasecmp (name
, "save_rp", 7) == 0))
5330 p
= input_line_pointer
;
5332 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
5334 /* Likewise for SP. */
5335 else if ((strncasecmp (name
, "save_sp", 7) == 0))
5337 p
= input_line_pointer
;
5339 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
5341 /* Is this an unwindable procedure. If so mark it so
5342 in the unwind descriptor. */
5343 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
5345 p
= input_line_pointer
;
5347 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
5349 /* Is this an interrupt routine. If so mark it in the
5350 unwind descriptor. */
5351 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
5353 p
= input_line_pointer
;
5355 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
5357 /* Is this a millicode routine. "millicode" isn't in my
5358 assembler manual, but my copy is old. The HP assembler
5359 accepts it, and there's a place in the unwind descriptor
5360 to drop the information, so we'll accept it too. */
5361 else if ((strncasecmp (name
, "millicode", 9) == 0))
5363 p
= input_line_pointer
;
5365 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
5369 as_bad (_("Invalid .CALLINFO argument: %s"), name
);
5370 *input_line_pointer
= c
;
5372 if (!is_end_of_statement ())
5373 input_line_pointer
++;
5376 demand_empty_rest_of_line ();
5379 /* Switch into the code subspace. */
5386 current_space
= is_defined_space ("$TEXT$");
5388 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
5391 pa_undefine_label ();
5394 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
5395 the .comm pseudo-op has the following symtax:
5397 <label> .comm <length>
5399 where <label> is optional and is a symbol whose address will be the start of
5400 a block of memory <length> bytes long. <length> must be an absolute
5401 expression. <length> bytes will be allocated in the current space
5404 Also note the label may not even be on the same line as the .comm.
5406 This difference in syntax means the colon function will be called
5407 on the symbol before we arrive in pa_comm. colon will set a number
5408 of attributes of the symbol that need to be fixed here. In particular
5409 the value, section pointer, fragment pointer, flags, etc. What
5412 This also makes error detection all but impossible. */
5420 label_symbol_struct
*label_symbol
= pa_get_label ();
5423 symbol
= label_symbol
->lss_label
;
5428 size
= get_absolute_expression ();
5432 S_SET_VALUE (symbol
, size
);
5433 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
5434 S_SET_EXTERNAL (symbol
);
5436 /* colon() has already set the frag to the current location in the
5437 current subspace; we need to reset the fragment to the zero address
5438 fragment. We also need to reset the segment pointer. */
5439 symbol_set_frag (symbol
, &zero_address_frag
);
5441 demand_empty_rest_of_line ();
5444 /* Process a .END pseudo-op. */
5450 demand_empty_rest_of_line ();
5453 /* Process a .ENTER pseudo-op. This is not supported. */
5459 /* We must have a valid space and subspace. */
5460 pa_check_current_space_and_subspace ();
5463 as_bad (_("The .ENTER pseudo-op is not supported"));
5464 demand_empty_rest_of_line ();
5467 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
5474 /* We must have a valid space and subspace. */
5475 pa_check_current_space_and_subspace ();
5478 if (!within_procedure
)
5479 as_bad (_("Misplaced .entry. Ignored."));
5482 if (!callinfo_found
)
5483 as_bad (_("Missing .callinfo."));
5485 demand_empty_rest_of_line ();
5486 within_entry_exit
= TRUE
;
5489 /* SOM defers building of unwind descriptors until the link phase.
5490 The assembler is responsible for creating an R_ENTRY relocation
5491 to mark the beginning of a region and hold the unwind bits, and
5492 for creating an R_EXIT relocation to mark the end of the region.
5494 FIXME. ELF should be using the same conventions! The problem
5495 is an unwind requires too much relocation space. Hmmm. Maybe
5496 if we split the unwind bits up between the relocations which
5497 denote the entry and exit points. */
5498 if (last_call_info
->start_symbol
!= NULL
)
5500 char *where
= frag_more (0);
5502 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5503 NULL
, (offsetT
) 0, NULL
,
5504 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
5505 (int *) &last_call_info
->ci_unwind
.descriptor
);
5510 /* Handle a .EQU pseudo-op. */
5516 label_symbol_struct
*label_symbol
= pa_get_label ();
5521 symbol
= label_symbol
->lss_label
;
5523 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
5525 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
5526 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
5531 as_bad (_(".REG must use a label"));
5533 as_bad (_(".EQU must use a label"));
5536 pa_undefine_label ();
5537 demand_empty_rest_of_line ();
5540 /* Helper function. Does processing for the end of a function. This
5541 usually involves creating some relocations or building special
5542 symbols to mark the end of the function. */
5549 where
= frag_more (0);
5552 /* Mark the end of the function, stuff away the location of the frag
5553 for the end of the function, and finally call pa_build_unwind_subspace
5554 to add an entry in the unwind table. */
5555 hppa_elf_mark_end_of_function ();
5556 pa_build_unwind_subspace (last_call_info
);
5558 /* SOM defers building of unwind descriptors until the link phase.
5559 The assembler is responsible for creating an R_ENTRY relocation
5560 to mark the beginning of a region and hold the unwind bits, and
5561 for creating an R_EXIT relocation to mark the end of the region.
5563 FIXME. ELF should be using the same conventions! The problem
5564 is an unwind requires too much relocation space. Hmmm. Maybe
5565 if we split the unwind bits up between the relocations which
5566 denote the entry and exit points. */
5567 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5569 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
5570 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
5574 /* Process a .EXIT pseudo-op. */
5581 /* We must have a valid space and subspace. */
5582 pa_check_current_space_and_subspace ();
5585 if (!within_procedure
)
5586 as_bad (_(".EXIT must appear within a procedure"));
5589 if (!callinfo_found
)
5590 as_bad (_("Missing .callinfo"));
5593 if (!within_entry_exit
)
5594 as_bad (_("No .ENTRY for this .EXIT"));
5597 within_entry_exit
= FALSE
;
5602 demand_empty_rest_of_line ();
5605 /* Process a .EXPORT directive. This makes functions external
5606 and provides information such as argument relocation entries
5616 name
= input_line_pointer
;
5617 c
= get_symbol_end ();
5618 /* Make sure the given symbol exists. */
5619 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5621 as_bad (_("Cannot define export symbol: %s\n"), name
);
5622 p
= input_line_pointer
;
5624 input_line_pointer
++;
5628 /* OK. Set the external bits and process argument relocations. */
5629 S_SET_EXTERNAL (symbol
);
5630 p
= input_line_pointer
;
5632 if (!is_end_of_statement ())
5634 input_line_pointer
++;
5635 pa_type_args (symbol
, 1);
5639 demand_empty_rest_of_line ();
5642 /* Helper function to process arguments to a .EXPORT pseudo-op. */
5645 pa_type_args (symbolP
, is_export
)
5650 unsigned int temp
, arg_reloc
;
5651 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
5652 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbol_get_bfdsym (symbolP
);
5654 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
5657 input_line_pointer
+= 8;
5658 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5659 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
5660 type
= SYMBOL_TYPE_ABSOLUTE
;
5662 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
5664 input_line_pointer
+= 4;
5665 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
5666 instead one should be IMPORTing/EXPORTing ENTRY types.
5668 Complain if one tries to EXPORT a CODE type since that's never
5669 done. Both GCC and HP C still try to IMPORT CODE types, so
5670 silently fix them to be ENTRY types. */
5671 if (S_IS_FUNCTION (symbolP
))
5674 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
5675 S_GET_NAME (symbolP
));
5677 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5678 type
= SYMBOL_TYPE_ENTRY
;
5682 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5683 type
= SYMBOL_TYPE_CODE
;
5686 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
5688 input_line_pointer
+= 4;
5689 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5690 symbol_get_bfdsym (symbolP
)->flags
|= BSF_OBJECT
;
5691 type
= SYMBOL_TYPE_DATA
;
5693 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
5695 input_line_pointer
+= 5;
5696 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5697 type
= SYMBOL_TYPE_ENTRY
;
5699 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
5701 input_line_pointer
+= 9;
5702 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5703 type
= SYMBOL_TYPE_MILLICODE
;
5705 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
5707 input_line_pointer
+= 6;
5708 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5709 type
= SYMBOL_TYPE_PLABEL
;
5711 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
5713 input_line_pointer
+= 8;
5714 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5715 type
= SYMBOL_TYPE_PRI_PROG
;
5717 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
5719 input_line_pointer
+= 8;
5720 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5721 type
= SYMBOL_TYPE_SEC_PROG
;
5724 /* SOM requires much more information about symbol types
5725 than BFD understands. This is how we get this information
5726 to the SOM BFD backend. */
5727 #ifdef obj_set_symbol_type
5728 obj_set_symbol_type (symbol_get_bfdsym (symbolP
), (int) type
);
5731 /* Now that the type of the exported symbol has been handled,
5732 handle any argument relocation information. */
5733 while (!is_end_of_statement ())
5735 if (*input_line_pointer
== ',')
5736 input_line_pointer
++;
5737 name
= input_line_pointer
;
5738 c
= get_symbol_end ();
5739 /* Argument sources. */
5740 if ((strncasecmp (name
, "argw", 4) == 0))
5742 p
= input_line_pointer
;
5744 input_line_pointer
++;
5745 temp
= atoi (name
+ 4);
5746 name
= input_line_pointer
;
5747 c
= get_symbol_end ();
5748 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
5750 symbol
->tc_data
.ap
.hppa_arg_reloc
|= arg_reloc
;
5752 *input_line_pointer
= c
;
5754 /* The return value. */
5755 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
5757 p
= input_line_pointer
;
5759 input_line_pointer
++;
5760 name
= input_line_pointer
;
5761 c
= get_symbol_end ();
5762 arg_reloc
= pa_build_arg_reloc (name
);
5764 symbol
->tc_data
.ap
.hppa_arg_reloc
|= arg_reloc
;
5766 *input_line_pointer
= c
;
5768 /* Privelege level. */
5769 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
5771 p
= input_line_pointer
;
5773 input_line_pointer
++;
5774 temp
= atoi (input_line_pointer
);
5776 symbol
->tc_data
.ap
.hppa_priv_level
= temp
;
5778 c
= get_symbol_end ();
5779 *input_line_pointer
= c
;
5783 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name
);
5784 p
= input_line_pointer
;
5787 if (!is_end_of_statement ())
5788 input_line_pointer
++;
5792 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
5793 assembly file must either be defined in the assembly file, or
5794 explicitly IMPORTED from another. */
5803 name
= input_line_pointer
;
5804 c
= get_symbol_end ();
5806 symbol
= symbol_find (name
);
5807 /* Ugh. We might be importing a symbol defined earlier in the file,
5808 in which case all the code below will really screw things up
5809 (set the wrong segment, symbol flags & type, etc). */
5810 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
5812 symbol
= symbol_find_or_make (name
);
5813 p
= input_line_pointer
;
5816 if (!is_end_of_statement ())
5818 input_line_pointer
++;
5819 pa_type_args (symbol
, 0);
5823 /* Sigh. To be compatable with the HP assembler and to help
5824 poorly written assembly code, we assign a type based on
5825 the the current segment. Note only BSF_FUNCTION really
5826 matters, we do not need to set the full SYMBOL_TYPE_* info. */
5827 if (now_seg
== text_section
)
5828 symbol_get_bfdsym (symbol
)->flags
|= BSF_FUNCTION
;
5830 /* If the section is undefined, then the symbol is undefined
5831 Since this is an import, leave the section undefined. */
5832 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
5837 /* The symbol was already defined. Just eat everything up to
5838 the end of the current statement. */
5839 while (!is_end_of_statement ())
5840 input_line_pointer
++;
5843 demand_empty_rest_of_line ();
5846 /* Handle a .LABEL pseudo-op. */
5854 name
= input_line_pointer
;
5855 c
= get_symbol_end ();
5857 if (strlen (name
) > 0)
5860 p
= input_line_pointer
;
5865 as_warn (_("Missing label name on .LABEL"));
5868 if (!is_end_of_statement ())
5870 as_warn (_("extra .LABEL arguments ignored."));
5871 ignore_rest_of_line ();
5873 demand_empty_rest_of_line ();
5876 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5883 /* We must have a valid space and subspace. */
5884 pa_check_current_space_and_subspace ();
5887 as_bad (_("The .LEAVE pseudo-op is not supported"));
5888 demand_empty_rest_of_line ();
5891 /* Handle a .LEVEL pseudo-op. */
5899 level
= input_line_pointer
;
5900 if (strncmp (level
, "1.0", 3) == 0)
5902 input_line_pointer
+= 3;
5903 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
5904 as_warn (_("could not set architecture and machine"));
5906 else if (strncmp (level
, "1.1", 3) == 0)
5908 input_line_pointer
+= 3;
5909 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 11))
5910 as_warn (_("could not set architecture and machine"));
5912 else if (strncmp (level
, "2.0w", 4) == 0)
5914 input_line_pointer
+= 4;
5915 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 25))
5916 as_warn (_("could not set architecture and machine"));
5918 else if (strncmp (level
, "2.0", 3) == 0)
5920 input_line_pointer
+= 3;
5921 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 20))
5922 as_warn (_("could not set architecture and machine"));
5926 as_bad (_("Unrecognized .LEVEL argument\n"));
5927 ignore_rest_of_line ();
5929 demand_empty_rest_of_line ();
5932 /* Handle a .ORIGIN pseudo-op. */
5939 /* We must have a valid space and subspace. */
5940 pa_check_current_space_and_subspace ();
5944 pa_undefine_label ();
5947 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5948 is for static functions. FIXME. Should share more code with .EXPORT. */
5957 name
= input_line_pointer
;
5958 c
= get_symbol_end ();
5960 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5962 as_bad (_("Cannot define static symbol: %s\n"), name
);
5963 p
= input_line_pointer
;
5965 input_line_pointer
++;
5969 S_CLEAR_EXTERNAL (symbol
);
5970 p
= input_line_pointer
;
5972 if (!is_end_of_statement ())
5974 input_line_pointer
++;
5975 pa_type_args (symbol
, 0);
5979 demand_empty_rest_of_line ();
5982 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5983 of a procedure from a syntatical point of view. */
5989 struct call_info
*call_info
;
5992 /* We must have a valid space and subspace. */
5993 pa_check_current_space_and_subspace ();
5996 if (within_procedure
)
5997 as_fatal (_("Nested procedures"));
5999 /* Reset global variables for new procedure. */
6000 callinfo_found
= FALSE
;
6001 within_procedure
= TRUE
;
6003 /* Create another call_info structure. */
6004 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
6007 as_fatal (_("Cannot allocate unwind descriptor\n"));
6009 memset (call_info
, 0, sizeof (struct call_info
));
6011 call_info
->ci_next
= NULL
;
6013 if (call_info_root
== NULL
)
6015 call_info_root
= call_info
;
6016 last_call_info
= call_info
;
6020 last_call_info
->ci_next
= call_info
;
6021 last_call_info
= call_info
;
6024 /* set up defaults on call_info structure */
6026 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
6027 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
6028 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
6030 /* If we got a .PROC pseudo-op, we know that the function is defined
6031 locally. Make sure it gets into the symbol table. */
6033 label_symbol_struct
*label_symbol
= pa_get_label ();
6037 if (label_symbol
->lss_label
)
6039 last_call_info
->start_symbol
= label_symbol
->lss_label
;
6040 symbol_get_bfdsym (label_symbol
->lss_label
)->flags
|= BSF_FUNCTION
;
6043 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6046 last_call_info
->start_symbol
= NULL
;
6049 demand_empty_rest_of_line ();
6052 /* Process the syntatical end of a procedure. Make sure all the
6053 appropriate pseudo-ops were found within the procedure. */
6061 /* We must have a valid space and subspace. */
6062 pa_check_current_space_and_subspace ();
6065 /* If we are within a procedure definition, make sure we've
6066 defined a label for the procedure; handle case where the
6067 label was defined after the .PROC directive.
6069 Note there's not need to diddle with the segment or fragment
6070 for the label symbol in this case. We have already switched
6071 into the new $CODE$ subspace at this point. */
6072 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
6074 label_symbol_struct
*label_symbol
= pa_get_label ();
6078 if (label_symbol
->lss_label
)
6080 last_call_info
->start_symbol
= label_symbol
->lss_label
;
6081 symbol_get_bfdsym (label_symbol
->lss_label
)->flags
6084 /* Also handle allocation of a fixup to hold the unwind
6085 information when the label appears after the proc/procend. */
6086 if (within_entry_exit
)
6088 char *where
= frag_more (0);
6090 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
6091 NULL
, (offsetT
) 0, NULL
,
6092 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
6093 (int *) &last_call_info
->ci_unwind
.descriptor
);
6098 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6101 as_bad (_("Missing function name for .PROC"));
6104 if (!within_procedure
)
6105 as_bad (_("misplaced .procend"));
6107 if (!callinfo_found
)
6108 as_bad (_("Missing .callinfo for this procedure"));
6110 if (within_entry_exit
)
6111 as_bad (_("Missing .EXIT for a .ENTRY"));
6114 /* ELF needs to mark the end of each function so that it can compute
6115 the size of the function (apparently its needed in the symbol table). */
6116 hppa_elf_mark_end_of_function ();
6119 within_procedure
= FALSE
;
6120 demand_empty_rest_of_line ();
6121 pa_undefine_label ();
6124 /* If VALUE is an exact power of two between zero and 2^31, then
6125 return log2 (VALUE). Else return -1. */
6133 while ((1 << shift
) != value
&& shift
< 32)
6144 /* Check to make sure we have a valid space and subspace. */
6147 pa_check_current_space_and_subspace ()
6149 if (current_space
== NULL
)
6150 as_fatal (_("Not in a space.\n"));
6152 if (current_subspace
== NULL
)
6153 as_fatal (_("Not in a subspace.\n"));
6156 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
6157 then create a new space entry to hold the information specified
6158 by the parameters to the .SPACE directive. */
6160 static sd_chain_struct
*
6161 pa_parse_space_stmt (space_name
, create_flag
)
6165 char *name
, *ptemp
, c
;
6166 char loadable
, defined
, private, sort
;
6168 asection
*seg
= NULL
;
6169 sd_chain_struct
*space
;
6171 /* load default values */
6177 if (strcmp (space_name
, "$TEXT$") == 0)
6179 seg
= pa_def_spaces
[0].segment
;
6180 defined
= pa_def_spaces
[0].defined
;
6181 private = pa_def_spaces
[0].private;
6182 sort
= pa_def_spaces
[0].sort
;
6183 spnum
= pa_def_spaces
[0].spnum
;
6185 else if (strcmp (space_name
, "$PRIVATE$") == 0)
6187 seg
= pa_def_spaces
[1].segment
;
6188 defined
= pa_def_spaces
[1].defined
;
6189 private = pa_def_spaces
[1].private;
6190 sort
= pa_def_spaces
[1].sort
;
6191 spnum
= pa_def_spaces
[1].spnum
;
6194 if (!is_end_of_statement ())
6196 print_errors
= FALSE
;
6197 ptemp
= input_line_pointer
+ 1;
6198 /* First see if the space was specified as a number rather than
6199 as a name. According to the PA assembly manual the rest of
6200 the line should be ignored. */
6201 temp
= pa_parse_number (&ptemp
, 0);
6205 input_line_pointer
= ptemp
;
6209 while (!is_end_of_statement ())
6211 input_line_pointer
++;
6212 name
= input_line_pointer
;
6213 c
= get_symbol_end ();
6214 if ((strncasecmp (name
, "spnum", 5) == 0))
6216 *input_line_pointer
= c
;
6217 input_line_pointer
++;
6218 spnum
= get_absolute_expression ();
6220 else if ((strncasecmp (name
, "sort", 4) == 0))
6222 *input_line_pointer
= c
;
6223 input_line_pointer
++;
6224 sort
= get_absolute_expression ();
6226 else if ((strncasecmp (name
, "unloadable", 10) == 0))
6228 *input_line_pointer
= c
;
6231 else if ((strncasecmp (name
, "notdefined", 10) == 0))
6233 *input_line_pointer
= c
;
6236 else if ((strncasecmp (name
, "private", 7) == 0))
6238 *input_line_pointer
= c
;
6243 as_bad (_("Invalid .SPACE argument"));
6244 *input_line_pointer
= c
;
6245 if (!is_end_of_statement ())
6246 input_line_pointer
++;
6250 print_errors
= TRUE
;
6253 if (create_flag
&& seg
== NULL
)
6254 seg
= subseg_new (space_name
, 0);
6256 /* If create_flag is nonzero, then create the new space with
6257 the attributes computed above. Else set the values in
6258 an already existing space -- this can only happen for
6259 the first occurence of a built-in space. */
6261 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
6262 private, sort
, seg
, 1);
6265 space
= is_defined_space (space_name
);
6266 SPACE_SPNUM (space
) = spnum
;
6267 SPACE_DEFINED (space
) = defined
& 1;
6268 SPACE_USER_DEFINED (space
) = 1;
6271 #ifdef obj_set_section_attributes
6272 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
6278 /* Handle a .SPACE pseudo-op; this switches the current space to the
6279 given space, creating the new space if necessary. */
6285 char *name
, c
, *space_name
, *save_s
;
6287 sd_chain_struct
*sd_chain
;
6289 if (within_procedure
)
6291 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
6292 ignore_rest_of_line ();
6296 /* Check for some of the predefined spaces. FIXME: most of the code
6297 below is repeated several times, can we extract the common parts
6298 and place them into a subroutine or something similar? */
6299 /* FIXME Is this (and the next IF stmt) really right?
6300 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
6301 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
6303 input_line_pointer
+= 6;
6304 sd_chain
= is_defined_space ("$TEXT$");
6305 if (sd_chain
== NULL
)
6306 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
6307 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
6308 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
6310 current_space
= sd_chain
;
6311 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
6313 = pa_subsegment_to_subspace (text_section
,
6314 sd_chain
->sd_last_subseg
);
6315 demand_empty_rest_of_line ();
6318 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
6320 input_line_pointer
+= 9;
6321 sd_chain
= is_defined_space ("$PRIVATE$");
6322 if (sd_chain
== NULL
)
6323 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
6324 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
6325 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
6327 current_space
= sd_chain
;
6328 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
6330 = pa_subsegment_to_subspace (data_section
,
6331 sd_chain
->sd_last_subseg
);
6332 demand_empty_rest_of_line ();
6335 if (!strncasecmp (input_line_pointer
,
6336 GDB_DEBUG_SPACE_NAME
,
6337 strlen (GDB_DEBUG_SPACE_NAME
)))
6339 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
6340 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
6341 if (sd_chain
== NULL
)
6342 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
6343 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
6344 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
6346 current_space
= sd_chain
;
6349 asection
*gdb_section
6350 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
6352 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
6354 = pa_subsegment_to_subspace (gdb_section
,
6355 sd_chain
->sd_last_subseg
);
6357 demand_empty_rest_of_line ();
6361 /* It could be a space specified by number. */
6363 save_s
= input_line_pointer
;
6364 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
6366 if ((sd_chain
= pa_find_space_by_number (temp
)))
6368 current_space
= sd_chain
;
6370 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
6372 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
6373 sd_chain
->sd_last_subseg
);
6374 demand_empty_rest_of_line ();
6379 /* Not a number, attempt to create a new space. */
6381 input_line_pointer
= save_s
;
6382 name
= input_line_pointer
;
6383 c
= get_symbol_end ();
6384 space_name
= xmalloc (strlen (name
) + 1);
6385 strcpy (space_name
, name
);
6386 *input_line_pointer
= c
;
6388 sd_chain
= pa_parse_space_stmt (space_name
, 1);
6389 current_space
= sd_chain
;
6391 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
6392 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
6393 sd_chain
->sd_last_subseg
);
6394 demand_empty_rest_of_line ();
6398 /* Switch to a new space. (I think). FIXME. */
6407 sd_chain_struct
*space
;
6409 name
= input_line_pointer
;
6410 c
= get_symbol_end ();
6411 space
= is_defined_space (name
);
6415 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
6418 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name
);
6420 *input_line_pointer
= c
;
6421 demand_empty_rest_of_line ();
6424 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
6425 given subspace, creating the new subspace if necessary.
6427 FIXME. Should mirror pa_space more closely, in particular how
6428 they're broken up into subroutines. */
6431 pa_subspace (create_new
)
6434 char *name
, *ss_name
, c
;
6435 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
6436 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
6437 sd_chain_struct
*space
;
6438 ssd_chain_struct
*ssd
;
6441 if (current_space
== NULL
)
6442 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
6444 if (within_procedure
)
6446 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
6447 ignore_rest_of_line ();
6451 name
= input_line_pointer
;
6452 c
= get_symbol_end ();
6453 ss_name
= xmalloc (strlen (name
) + 1);
6454 strcpy (ss_name
, name
);
6455 *input_line_pointer
= c
;
6457 /* Load default values. */
6469 space
= current_space
;
6473 ssd
= is_defined_subspace (ss_name
);
6474 /* Allow user to override the builtin attributes of subspaces. But
6475 only allow the attributes to be changed once! */
6476 if (ssd
&& SUBSPACE_DEFINED (ssd
))
6478 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
6479 current_subspace
= ssd
;
6480 if (!is_end_of_statement ())
6481 as_warn (_("Parameters of an existing subspace can\'t be modified"));
6482 demand_empty_rest_of_line ();
6487 /* A new subspace. Load default values if it matches one of
6488 the builtin subspaces. */
6490 while (pa_def_subspaces
[i
].name
)
6492 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
6494 loadable
= pa_def_subspaces
[i
].loadable
;
6495 common
= pa_def_subspaces
[i
].common
;
6496 dup_common
= pa_def_subspaces
[i
].dup_common
;
6497 code_only
= pa_def_subspaces
[i
].code_only
;
6498 zero
= pa_def_subspaces
[i
].zero
;
6499 space_index
= pa_def_subspaces
[i
].space_index
;
6500 alignment
= pa_def_subspaces
[i
].alignment
;
6501 quadrant
= pa_def_subspaces
[i
].quadrant
;
6502 access
= pa_def_subspaces
[i
].access
;
6503 sort
= pa_def_subspaces
[i
].sort
;
6510 /* We should be working with a new subspace now. Fill in
6511 any information as specified by the user. */
6512 if (!is_end_of_statement ())
6514 input_line_pointer
++;
6515 while (!is_end_of_statement ())
6517 name
= input_line_pointer
;
6518 c
= get_symbol_end ();
6519 if ((strncasecmp (name
, "quad", 4) == 0))
6521 *input_line_pointer
= c
;
6522 input_line_pointer
++;
6523 quadrant
= get_absolute_expression ();
6525 else if ((strncasecmp (name
, "align", 5) == 0))
6527 *input_line_pointer
= c
;
6528 input_line_pointer
++;
6529 alignment
= get_absolute_expression ();
6530 if (log2 (alignment
) == -1)
6532 as_bad (_("Alignment must be a power of 2"));
6536 else if ((strncasecmp (name
, "access", 6) == 0))
6538 *input_line_pointer
= c
;
6539 input_line_pointer
++;
6540 access
= get_absolute_expression ();
6542 else if ((strncasecmp (name
, "sort", 4) == 0))
6544 *input_line_pointer
= c
;
6545 input_line_pointer
++;
6546 sort
= get_absolute_expression ();
6548 else if ((strncasecmp (name
, "code_only", 9) == 0))
6550 *input_line_pointer
= c
;
6553 else if ((strncasecmp (name
, "unloadable", 10) == 0))
6555 *input_line_pointer
= c
;
6558 else if ((strncasecmp (name
, "common", 6) == 0))
6560 *input_line_pointer
= c
;
6563 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
6565 *input_line_pointer
= c
;
6568 else if ((strncasecmp (name
, "zero", 4) == 0))
6570 *input_line_pointer
= c
;
6573 else if ((strncasecmp (name
, "first", 5) == 0))
6574 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
6576 as_bad (_("Invalid .SUBSPACE argument"));
6577 if (!is_end_of_statement ())
6578 input_line_pointer
++;
6582 /* Compute a reasonable set of BFD flags based on the information
6583 in the .subspace directive. */
6584 applicable
= bfd_applicable_section_flags (stdoutput
);
6587 flags
|= (SEC_ALLOC
| SEC_LOAD
);
6590 if (common
|| dup_common
)
6591 flags
|= SEC_IS_COMMON
;
6593 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
6595 /* This is a zero-filled subspace (eg BSS). */
6597 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
6599 applicable
&= flags
;
6601 /* If this is an existing subspace, then we want to use the
6602 segment already associated with the subspace.
6604 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
6605 lots of sections. It might be a problem in the PA ELF
6606 code, I do not know yet. For now avoid creating anything
6607 but the "standard" sections for ELF. */
6609 section
= subseg_force_new (ss_name
, 0);
6611 section
= ssd
->ssd_seg
;
6613 section
= subseg_new (ss_name
, 0);
6616 seg_info (section
)->bss
= 1;
6618 /* Now set the flags. */
6619 bfd_set_section_flags (stdoutput
, section
, applicable
);
6621 /* Record any alignment request for this section. */
6622 record_alignment (section
, log2 (alignment
));
6624 /* Set the starting offset for this section. */
6625 bfd_set_section_vma (stdoutput
, section
,
6626 pa_subspace_start (space
, quadrant
));
6628 /* Now that all the flags are set, update an existing subspace,
6629 or create a new one. */
6632 current_subspace
= update_subspace (space
, ss_name
, loadable
,
6633 code_only
, common
, dup_common
,
6634 sort
, zero
, access
, space_index
,
6635 alignment
, quadrant
,
6638 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
6640 dup_common
, zero
, sort
,
6641 access
, space_index
,
6642 alignment
, quadrant
, section
);
6644 demand_empty_rest_of_line ();
6645 current_subspace
->ssd_seg
= section
;
6646 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
6648 SUBSPACE_DEFINED (current_subspace
) = 1;
6652 /* Create default space and subspace dictionaries. */
6659 space_dict_root
= NULL
;
6660 space_dict_last
= NULL
;
6663 while (pa_def_spaces
[i
].name
)
6667 /* Pick the right name to use for the new section. */
6668 name
= pa_def_spaces
[i
].name
;
6670 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
6671 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
6672 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
6673 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
6674 pa_def_spaces
[i
].segment
, 0);
6679 while (pa_def_subspaces
[i
].name
)
6682 int applicable
, subsegment
;
6683 asection
*segment
= NULL
;
6684 sd_chain_struct
*space
;
6686 /* Pick the right name for the new section and pick the right
6687 subsegment number. */
6688 name
= pa_def_subspaces
[i
].name
;
6691 /* Create the new section. */
6692 segment
= subseg_new (name
, subsegment
);
6695 /* For SOM we want to replace the standard .text, .data, and .bss
6696 sections with our own. We also want to set BFD flags for
6697 all the built-in subspaces. */
6698 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$"))
6700 text_section
= segment
;
6701 applicable
= bfd_applicable_section_flags (stdoutput
);
6702 bfd_set_section_flags (stdoutput
, segment
,
6703 applicable
& (SEC_ALLOC
| SEC_LOAD
6704 | SEC_RELOC
| SEC_CODE
6706 | SEC_HAS_CONTENTS
));
6708 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$"))
6710 data_section
= segment
;
6711 applicable
= bfd_applicable_section_flags (stdoutput
);
6712 bfd_set_section_flags (stdoutput
, segment
,
6713 applicable
& (SEC_ALLOC
| SEC_LOAD
6715 | SEC_HAS_CONTENTS
));
6719 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$"))
6721 bss_section
= segment
;
6722 applicable
= bfd_applicable_section_flags (stdoutput
);
6723 bfd_set_section_flags (stdoutput
, segment
,
6724 applicable
& SEC_ALLOC
);
6726 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$"))
6728 applicable
= bfd_applicable_section_flags (stdoutput
);
6729 bfd_set_section_flags (stdoutput
, segment
,
6730 applicable
& (SEC_ALLOC
| SEC_LOAD
6733 | SEC_HAS_CONTENTS
));
6735 else if (!strcmp (pa_def_subspaces
[i
].name
, "$MILLICODE$"))
6737 applicable
= bfd_applicable_section_flags (stdoutput
);
6738 bfd_set_section_flags (stdoutput
, segment
,
6739 applicable
& (SEC_ALLOC
| SEC_LOAD
6742 | SEC_HAS_CONTENTS
));
6744 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$"))
6746 applicable
= bfd_applicable_section_flags (stdoutput
);
6747 bfd_set_section_flags (stdoutput
, segment
,
6748 applicable
& (SEC_ALLOC
| SEC_LOAD
6751 | SEC_HAS_CONTENTS
));
6754 /* Find the space associated with this subspace. */
6755 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
6756 def_space_index
].segment
);
6759 as_fatal (_("Internal error: Unable to find containing space for %s."),
6760 pa_def_subspaces
[i
].name
);
6763 create_new_subspace (space
, name
,
6764 pa_def_subspaces
[i
].loadable
,
6765 pa_def_subspaces
[i
].code_only
,
6766 pa_def_subspaces
[i
].common
,
6767 pa_def_subspaces
[i
].dup_common
,
6768 pa_def_subspaces
[i
].zero
,
6769 pa_def_subspaces
[i
].sort
,
6770 pa_def_subspaces
[i
].access
,
6771 pa_def_subspaces
[i
].space_index
,
6772 pa_def_subspaces
[i
].alignment
,
6773 pa_def_subspaces
[i
].quadrant
,
6781 /* Create a new space NAME, with the appropriate flags as defined
6782 by the given parameters. */
6784 static sd_chain_struct
*
6785 create_new_space (name
, spnum
, loadable
, defined
, private,
6786 sort
, seg
, user_defined
)
6796 sd_chain_struct
*chain_entry
;
6798 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
6800 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
6803 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
6804 strcpy (SPACE_NAME (chain_entry
), name
);
6805 SPACE_DEFINED (chain_entry
) = defined
;
6806 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
6807 SPACE_SPNUM (chain_entry
) = spnum
;
6809 chain_entry
->sd_seg
= seg
;
6810 chain_entry
->sd_last_subseg
= -1;
6811 chain_entry
->sd_subspaces
= NULL
;
6812 chain_entry
->sd_next
= NULL
;
6814 /* Find spot for the new space based on its sort key. */
6815 if (!space_dict_last
)
6816 space_dict_last
= chain_entry
;
6818 if (space_dict_root
== NULL
)
6819 space_dict_root
= chain_entry
;
6822 sd_chain_struct
*chain_pointer
;
6823 sd_chain_struct
*prev_chain_pointer
;
6825 chain_pointer
= space_dict_root
;
6826 prev_chain_pointer
= NULL
;
6828 while (chain_pointer
)
6830 prev_chain_pointer
= chain_pointer
;
6831 chain_pointer
= chain_pointer
->sd_next
;
6834 /* At this point we've found the correct place to add the new
6835 entry. So add it and update the linked lists as appropriate. */
6836 if (prev_chain_pointer
)
6838 chain_entry
->sd_next
= chain_pointer
;
6839 prev_chain_pointer
->sd_next
= chain_entry
;
6843 space_dict_root
= chain_entry
;
6844 chain_entry
->sd_next
= chain_pointer
;
6847 if (chain_entry
->sd_next
== NULL
)
6848 space_dict_last
= chain_entry
;
6851 /* This is here to catch predefined spaces which do not get
6852 modified by the user's input. Another call is found at
6853 the bottom of pa_parse_space_stmt to handle cases where
6854 the user modifies a predefined space. */
6855 #ifdef obj_set_section_attributes
6856 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
6862 /* Create a new subspace NAME, with the appropriate flags as defined
6863 by the given parameters.
6865 Add the new subspace to the subspace dictionary chain in numerical
6866 order as defined by the SORT entries. */
6868 static ssd_chain_struct
*
6869 create_new_subspace (space
, name
, loadable
, code_only
, common
,
6870 dup_common
, is_zero
, sort
, access
, space_index
,
6871 alignment
, quadrant
, seg
)
6872 sd_chain_struct
*space
;
6874 int loadable
, code_only
, common
, dup_common
, is_zero
;
6882 ssd_chain_struct
*chain_entry
;
6884 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
6886 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name
);
6888 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
6889 strcpy (SUBSPACE_NAME (chain_entry
), name
);
6891 /* Initialize subspace_defined. When we hit a .subspace directive
6892 we'll set it to 1 which "locks-in" the subspace attributes. */
6893 SUBSPACE_DEFINED (chain_entry
) = 0;
6895 chain_entry
->ssd_subseg
= 0;
6896 chain_entry
->ssd_seg
= seg
;
6897 chain_entry
->ssd_next
= NULL
;
6899 /* Find spot for the new subspace based on its sort key. */
6900 if (space
->sd_subspaces
== NULL
)
6901 space
->sd_subspaces
= chain_entry
;
6904 ssd_chain_struct
*chain_pointer
;
6905 ssd_chain_struct
*prev_chain_pointer
;
6907 chain_pointer
= space
->sd_subspaces
;
6908 prev_chain_pointer
= NULL
;
6910 while (chain_pointer
)
6912 prev_chain_pointer
= chain_pointer
;
6913 chain_pointer
= chain_pointer
->ssd_next
;
6916 /* Now we have somewhere to put the new entry. Insert it and update
6918 if (prev_chain_pointer
)
6920 chain_entry
->ssd_next
= chain_pointer
;
6921 prev_chain_pointer
->ssd_next
= chain_entry
;
6925 space
->sd_subspaces
= chain_entry
;
6926 chain_entry
->ssd_next
= chain_pointer
;
6930 #ifdef obj_set_subsection_attributes
6931 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
6938 /* Update the information for the given subspace based upon the
6939 various arguments. Return the modified subspace chain entry. */
6941 static ssd_chain_struct
*
6942 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
6943 zero
, access
, space_index
, alignment
, quadrant
, section
)
6944 sd_chain_struct
*space
;
6958 ssd_chain_struct
*chain_entry
;
6960 chain_entry
= is_defined_subspace (name
);
6962 #ifdef obj_set_subsection_attributes
6963 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
6970 /* Return the space chain entry for the space with the name NAME or
6971 NULL if no such space exists. */
6973 static sd_chain_struct
*
6974 is_defined_space (name
)
6977 sd_chain_struct
*chain_pointer
;
6979 for (chain_pointer
= space_dict_root
;
6981 chain_pointer
= chain_pointer
->sd_next
)
6983 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6984 return chain_pointer
;
6987 /* No mapping from segment to space was found. Return NULL. */
6991 /* Find and return the space associated with the given seg. If no mapping
6992 from the given seg to a space is found, then return NULL.
6994 Unlike subspaces, the number of spaces is not expected to grow much,
6995 so a linear exhaustive search is OK here. */
6997 static sd_chain_struct
*
6998 pa_segment_to_space (seg
)
7001 sd_chain_struct
*space_chain
;
7003 /* Walk through each space looking for the correct mapping. */
7004 for (space_chain
= space_dict_root
;
7006 space_chain
= space_chain
->sd_next
)
7008 if (space_chain
->sd_seg
== seg
)
7012 /* Mapping was not found. Return NULL. */
7016 /* Return the space chain entry for the subspace with the name NAME or
7017 NULL if no such subspace exists.
7019 Uses a linear search through all the spaces and subspaces, this may
7020 not be appropriate if we ever being placing each function in its
7023 static ssd_chain_struct
*
7024 is_defined_subspace (name
)
7027 sd_chain_struct
*space_chain
;
7028 ssd_chain_struct
*subspace_chain
;
7030 /* Walk through each space. */
7031 for (space_chain
= space_dict_root
;
7033 space_chain
= space_chain
->sd_next
)
7035 /* Walk through each subspace looking for a name which matches. */
7036 for (subspace_chain
= space_chain
->sd_subspaces
;
7038 subspace_chain
= subspace_chain
->ssd_next
)
7039 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
7040 return subspace_chain
;
7043 /* Subspace wasn't found. Return NULL. */
7047 /* Find and return the subspace associated with the given seg. If no
7048 mapping from the given seg to a subspace is found, then return NULL.
7050 If we ever put each procedure/function within its own subspace
7051 (to make life easier on the compiler and linker), then this will have
7052 to become more efficient. */
7054 static ssd_chain_struct
*
7055 pa_subsegment_to_subspace (seg
, subseg
)
7059 sd_chain_struct
*space_chain
;
7060 ssd_chain_struct
*subspace_chain
;
7062 /* Walk through each space. */
7063 for (space_chain
= space_dict_root
;
7065 space_chain
= space_chain
->sd_next
)
7067 if (space_chain
->sd_seg
== seg
)
7069 /* Walk through each subspace within each space looking for
7070 the correct mapping. */
7071 for (subspace_chain
= space_chain
->sd_subspaces
;
7073 subspace_chain
= subspace_chain
->ssd_next
)
7074 if (subspace_chain
->ssd_subseg
== (int) subseg
)
7075 return subspace_chain
;
7079 /* No mapping from subsegment to subspace found. Return NULL. */
7083 /* Given a number, try and find a space with the name number.
7085 Return a pointer to a space dictionary chain entry for the space
7086 that was found or NULL on failure. */
7088 static sd_chain_struct
*
7089 pa_find_space_by_number (number
)
7092 sd_chain_struct
*space_chain
;
7094 for (space_chain
= space_dict_root
;
7096 space_chain
= space_chain
->sd_next
)
7098 if (SPACE_SPNUM (space_chain
) == (unsigned int) number
)
7102 /* No appropriate space found. Return NULL. */
7106 /* Return the starting address for the given subspace. If the starting
7107 address is unknown then return zero. */
7110 pa_subspace_start (space
, quadrant
)
7111 sd_chain_struct
*space
;
7114 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
7115 is not correct for the PA OSF1 port. */
7116 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
7118 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
7125 /* FIXME. Needs documentation. */
7127 pa_next_subseg (space
)
7128 sd_chain_struct
*space
;
7131 space
->sd_last_subseg
++;
7132 return space
->sd_last_subseg
;
7136 /* Helper function for pa_stringer. Used to find the end of
7143 unsigned int c
= *s
& CHAR_MASK
;
7146 /* We must have a valid space and subspace. */
7147 pa_check_current_space_and_subspace ();
7161 /* Handle a .STRING type pseudo-op. */
7164 pa_stringer (append_zero
)
7167 char *s
, num_buf
[4];
7171 /* Preprocess the string to handle PA-specific escape sequences.
7172 For example, \xDD where DD is a hexidecimal number should be
7173 changed to \OOO where OOO is an octal number. */
7175 /* Skip the opening quote. */
7176 s
= input_line_pointer
+ 1;
7178 while (is_a_char (c
= pa_stringer_aux (s
++)))
7185 /* Handle \x<num>. */
7188 unsigned int number
;
7193 /* Get pas the 'x'. */
7195 for (num_digit
= 0, number
= 0, dg
= *s
;
7197 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
7198 || (dg
>= 'A' && dg
<= 'F'));
7202 number
= number
* 16 + dg
- '0';
7203 else if (dg
>= 'a' && dg
<= 'f')
7204 number
= number
* 16 + dg
- 'a' + 10;
7206 number
= number
* 16 + dg
- 'A' + 10;
7216 sprintf (num_buf
, "%02o", number
);
7219 sprintf (num_buf
, "%03o", number
);
7222 for (i
= 0; i
<= num_digit
; i
++)
7223 s_start
[i
] = num_buf
[i
];
7227 /* This might be a "\"", skip over the escaped char. */
7234 stringer (append_zero
);
7235 pa_undefine_label ();
7238 /* Handle a .VERSION pseudo-op. */
7245 pa_undefine_label ();
7250 /* Handle a .COMPILER pseudo-op. */
7253 pa_compiler (unused
)
7256 obj_som_compiler (0);
7257 pa_undefine_label ();
7262 /* Handle a .COPYRIGHT pseudo-op. */
7265 pa_copyright (unused
)
7269 pa_undefine_label ();
7272 /* Just like a normal cons, but when finished we have to undefine
7273 the latest space label. */
7280 pa_undefine_label ();
7283 /* Switch to the data space. As usual delete our label. */
7290 current_space
= is_defined_space ("$PRIVATE$");
7292 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
7295 pa_undefine_label ();
7298 /* Like float_cons, but we need to undefine our label. */
7301 pa_float_cons (float_type
)
7304 float_cons (float_type
);
7305 pa_undefine_label ();
7308 /* Like s_fill, but delete our label when finished. */
7315 /* We must have a valid space and subspace. */
7316 pa_check_current_space_and_subspace ();
7320 pa_undefine_label ();
7323 /* Like lcomm, but delete our label when finished. */
7326 pa_lcomm (needs_align
)
7330 /* We must have a valid space and subspace. */
7331 pa_check_current_space_and_subspace ();
7334 s_lcomm (needs_align
);
7335 pa_undefine_label ();
7338 /* Like lsym, but delete our label when finished. */
7345 /* We must have a valid space and subspace. */
7346 pa_check_current_space_and_subspace ();
7350 pa_undefine_label ();
7353 /* Switch to the text space. Like s_text, but delete our
7354 label when finished. */
7360 current_space
= is_defined_space ("$TEXT$");
7362 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
7366 pa_undefine_label ();
7369 /* On the PA relocations which involve function symbols must not be
7370 adjusted. This so that the linker can know when/how to create argument
7371 relocation stubs for indirect calls and calls to static functions.
7373 "T" field selectors create DLT relative fixups for accessing
7374 globals and statics in PIC code; each DLT relative fixup creates
7375 an entry in the DLT table. The entries contain the address of
7376 the final target (eg accessing "foo" would create a DLT entry
7377 with the address of "foo").
7379 Unfortunately, the HP linker doesn't take into account any addend
7380 when generating the DLT; so accessing $LIT$+8 puts the address of
7381 $LIT$ into the DLT rather than the address of $LIT$+8.
7383 The end result is we can't perform relocation symbol reductions for
7384 any fixup which creates entries in the DLT (eg they use "T" field
7387 Reject reductions involving symbols with external scope; such
7388 reductions make life a living hell for object file editors.
7390 FIXME. Also reject R_HPPA relocations which are 32bits wide in
7391 the code space. The SOM BFD backend doesn't know how to pull the
7392 right bits out of an instruction. */
7395 hppa_fix_adjustable (fixp
)
7398 struct hppa_fix_struct
*hppa_fix
;
7400 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
7403 /* Reject reductions of symbols in 32bit relocs. */
7404 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
7407 /* Reject reductions of symbols in sym1-sym2 expressions when
7408 the fixup will occur in a CODE subspace.
7410 XXX FIXME: Long term we probably want to reject all of these;
7411 for example reducing in the debug section would lose if we ever
7412 supported using the optimizing hp linker. */
7415 && (hppa_fix
->segment
->flags
& SEC_CODE
))
7417 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
7418 symbol_mark_used_in_reloc (fixp
->fx_subsy
);
7422 /* We can't adjust any relocs that use LR% and RR% field selectors.
7423 That confuses the HP linker. */
7424 if (hppa_fix
->fx_r_field
== e_lrsel
7425 || hppa_fix
->fx_r_field
== e_rrsel
7426 || hppa_fix
->fx_r_field
== e_nlrsel
)
7430 /* Reject reductions of symbols in DLT relative relocs,
7431 relocations with plabels. */
7432 if (hppa_fix
->fx_r_field
== e_tsel
7433 || hppa_fix
->fx_r_field
== e_ltsel
7434 || hppa_fix
->fx_r_field
== e_rtsel
7435 || hppa_fix
->fx_r_field
== e_psel
7436 || hppa_fix
->fx_r_field
== e_rpsel
7437 || hppa_fix
->fx_r_field
== e_lpsel
)
7440 if (fixp
->fx_addsy
&& S_IS_EXTERNAL (fixp
->fx_addsy
))
7443 /* Reject absolute calls (jumps). */
7444 if (hppa_fix
->fx_r_type
== R_HPPA_ABS_CALL
)
7447 /* Reject reductions of function symbols. */
7448 if (fixp
->fx_addsy
== 0 || ! S_IS_FUNCTION (fixp
->fx_addsy
))
7454 /* Return nonzero if the fixup in FIXP will require a relocation,
7455 even it if appears that the fixup could be completely handled
7459 hppa_force_relocation (fixp
)
7462 struct hppa_fix_struct
*hppa_fixp
;
7465 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
7467 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
7468 || fixp
->fx_r_type
== R_HPPA_BEGIN_BRTAB
7469 || fixp
->fx_r_type
== R_HPPA_END_BRTAB
7470 || fixp
->fx_r_type
== R_HPPA_BEGIN_TRY
7471 || fixp
->fx_r_type
== R_HPPA_END_TRY
7472 || (fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
7473 && (hppa_fixp
->segment
->flags
& SEC_CODE
) != 0))
7477 #define arg_reloc_stub_needed(CALLER, CALLEE) \
7478 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
7481 /* It is necessary to force PC-relative calls/jumps to have a relocation
7482 entry if they're going to need either a argument relocation or long
7483 call stub. FIXME. Can't we need the same for absolute calls? */
7484 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
7485 && (arg_reloc_stub_needed ((long) ((obj_symbol_type
*)
7486 symbol_get_bfdsym (fixp
->fx_addsy
))->tc_data
.ap
.hppa_arg_reloc
,
7487 hppa_fixp
->fx_arg_reloc
)))
7490 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
7491 - md_pcrel_from (fixp
));
7492 /* Now check and see if we're going to need a long-branch stub. */
7493 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
7494 && (distance
> 262143 || distance
< -262144))
7497 if (fixp
->fx_r_type
== R_HPPA_ABS_CALL
)
7499 #undef arg_reloc_stub_needed
7501 /* No need (yet) to force another relocations to be emitted. */
7505 /* Now for some ELF specific code. FIXME. */
7507 /* Mark the end of a function so that it's possible to compute
7508 the size of the function in hppa_elf_final_processing. */
7511 hppa_elf_mark_end_of_function ()
7513 /* ELF does not have EXIT relocations. All we do is create a
7514 temporary symbol marking the end of the function. */
7515 char *name
= (char *)
7516 xmalloc (strlen ("L$\001end_") +
7517 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
7523 strcpy (name
, "L$\001end_");
7524 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
7526 /* If we have a .exit followed by a .procend, then the
7527 symbol will have already been defined. */
7528 symbolP
= symbol_find (name
);
7531 /* The symbol has already been defined! This can
7532 happen if we have a .exit followed by a .procend.
7534 This is *not* an error. All we want to do is free
7535 the memory we just allocated for the name and continue. */
7540 /* symbol value should be the offset of the
7541 last instruction of the function */
7542 symbolP
= symbol_new (name
, now_seg
, (valueT
) (frag_now_fix () - 4),
7546 S_CLEAR_EXTERNAL (symbolP
);
7547 symbol_table_insert (symbolP
);
7551 last_call_info
->end_symbol
= symbolP
;
7553 as_bad (_("Symbol '%s' could not be created."), name
);
7557 as_bad (_("No memory for symbol name."));
7561 /* For ELF, this function serves one purpose: to setup the st_size
7562 field of STT_FUNC symbols. To do this, we need to scan the
7563 call_info structure list, determining st_size in by taking the
7564 difference in the address of the beginning/end marker symbols. */
7567 elf_hppa_final_processing ()
7569 struct call_info
*call_info_pointer
;
7571 for (call_info_pointer
= call_info_root
;
7573 call_info_pointer
= call_info_pointer
->ci_next
)
7575 elf_symbol_type
*esym
7576 = ((elf_symbol_type
*)
7577 symbol_get_bfdsym (call_info_pointer
->start_symbol
));
7578 esym
->internal_elf_sym
.st_size
=
7579 S_GET_VALUE (call_info_pointer
->end_symbol
)
7580 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;
7588 if (debug_type
== DEBUG_DWARF2
)