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 /* A "convient" place to put object file dependencies which do
43 not need to be seen outside of tc-hppa.c. */
45 /* Object file formats specify relocation types. */
46 typedef elf_hppa_reloc_type reloc_type
;
48 /* Object file formats specify BFD symbol types. */
49 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type _bfd_elf64_hppa_gen_reloc_type
55 #define hppa_gen_reloc_type _bfd_elf32_hppa_gen_reloc_type
58 /* ELF objects can have versions, but apparently do not have anywhere
59 to store a copyright string. */
60 #define obj_version obj_elf_version
61 #define obj_copyright obj_elf_version
63 #define UNWIND_SECTION_NAME ".PARISC.unwind"
67 /* Names of various debugging spaces/subspaces. */
68 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
69 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
70 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
71 #define UNWIND_SECTION_NAME "$UNWIND$"
73 /* Object file formats specify relocation types. */
74 typedef int reloc_type
;
76 /* SOM objects can have both a version string and a copyright string. */
77 #define obj_version obj_som_version
78 #define obj_copyright obj_som_copyright
80 /* How to generate a relocation. */
81 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
83 /* Object file formats specify BFD symbol types. */
84 typedef som_symbol_type obj_symbol_type
;
86 /* This apparently isn't in older versions of hpux reloc.h. */
88 #define R_DLT_REL 0x78
100 /* Various structures and types used internally in tc-hppa.c. */
102 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
106 unsigned int cannot_unwind
:1;
107 unsigned int millicode
:1;
108 unsigned int millicode_save_rest
:1;
109 unsigned int region_desc
:2;
110 unsigned int save_sr
:2;
111 unsigned int entry_fr
:4;
112 unsigned int entry_gr
:5;
113 unsigned int args_stored
:1;
114 unsigned int call_fr
:5;
115 unsigned int call_gr
:5;
116 unsigned int save_sp
:1;
117 unsigned int save_rp
:1;
118 unsigned int save_rp_in_frame
:1;
119 unsigned int extn_ptr_defined
:1;
120 unsigned int cleanup_defined
:1;
122 unsigned int hpe_interrupt_marker
:1;
123 unsigned int hpux_interrupt_marker
:1;
124 unsigned int reserved
:3;
125 unsigned int frame_size
:27;
130 /* Starting and ending offsets of the region described by
132 unsigned int start_offset
;
133 unsigned int end_offset
;
134 struct unwind_desc descriptor
;
137 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
138 control the entry and exit code they generate. It is also used in
139 creation of the correct stack unwind descriptors.
141 NOTE: GAS does not support .enter and .leave for the generation of
142 prologues and epilogues. FIXME.
144 The fields in structure roughly correspond to the arguments available on the
145 .callinfo pseudo-op. */
149 /* The unwind descriptor being built. */
150 struct unwind_table ci_unwind
;
152 /* Name of this function. */
153 symbolS
*start_symbol
;
155 /* (temporary) symbol used to mark the end of this function. */
158 /* Next entry in the chain. */
159 struct call_info
*ci_next
;
162 /* Operand formats for FP instructions. Note not all FP instructions
163 allow all four formats to be used (for example fmpysub only allows
167 SGL
, DBL
, ILLEGAL_FMT
, QUAD
, W
, UW
, DW
, UDW
, QW
, UQW
171 /* This fully describes the symbol types which may be attached to
172 an EXPORT or IMPORT directive. Only SOM uses this formation
173 (ELF has no need for it). */
177 SYMBOL_TYPE_ABSOLUTE
,
181 SYMBOL_TYPE_MILLICODE
,
183 SYMBOL_TYPE_PRI_PROG
,
184 SYMBOL_TYPE_SEC_PROG
,
188 /* This structure contains information needed to assemble
189 individual instructions. */
192 /* Holds the opcode after parsing by pa_ip. */
193 unsigned long opcode
;
195 /* Holds an expression associated with the current instruction. */
198 /* Does this instruction use PC-relative addressing. */
201 /* Floating point formats for operand1 and operand2. */
202 fp_operand_format fpof1
;
203 fp_operand_format fpof2
;
206 /* Holds the field selector for this instruction
207 (for example L%, LR%, etc). */
210 /* Holds any argument relocation bits associated with this
211 instruction. (instruction should be some sort of call). */
214 /* The format specification for this instruction. */
217 /* The relocation (if any) associated with this instruction. */
221 /* PA-89 floating point registers are arranged like this:
224 +--------------+--------------+
225 | 0 or 16L | 16 or 16R |
226 +--------------+--------------+
227 | 1 or 17L | 17 or 17R |
228 +--------------+--------------+
236 +--------------+--------------+
237 | 14 or 30L | 30 or 30R |
238 +--------------+--------------+
239 | 15 or 31L | 31 or 31R |
240 +--------------+--------------+
243 The following is a version of pa_parse_number that
244 handles the L/R notation and returns the correct
245 value to put into the instruction register field.
246 The correct value to put into the instruction is
247 encoded in the structure 'pa_11_fp_reg_struct'. */
249 struct pa_11_fp_reg_struct
251 /* The register number. */
258 /* Additional information needed to build argument relocation stubs. */
261 /* The argument relocation specification. */
262 unsigned int arg_reloc
;
264 /* Number of arguments. */
265 unsigned int arg_count
;
269 /* This structure defines an entry in the subspace dictionary
272 struct subspace_dictionary_chain
274 /* Nonzero if this space has been defined by the user code. */
275 unsigned int ssd_defined
;
277 /* Name of this subspace. */
280 /* GAS segment and subsegment associated with this subspace. */
284 /* Next space in the subspace dictionary chain. */
285 struct subspace_dictionary_chain
*ssd_next
;
288 typedef struct subspace_dictionary_chain ssd_chain_struct
;
290 /* This structure defines an entry in the subspace dictionary
293 struct space_dictionary_chain
295 /* Nonzero if this space has been defined by the user code or
296 as a default space. */
297 unsigned int sd_defined
;
299 /* Nonzero if this spaces has been defined by the user code. */
300 unsigned int sd_user_defined
;
302 /* The space number (or index). */
303 unsigned int sd_spnum
;
305 /* The name of this subspace. */
308 /* GAS segment to which this subspace corresponds. */
311 /* Current subsegment number being used. */
314 /* The chain of subspaces contained within this space. */
315 ssd_chain_struct
*sd_subspaces
;
317 /* The next entry in the space dictionary chain. */
318 struct space_dictionary_chain
*sd_next
;
321 typedef struct space_dictionary_chain sd_chain_struct
;
323 /* This structure defines attributes of the default subspace
324 dictionary entries. */
326 struct default_subspace_dict
328 /* Name of the subspace. */
331 /* FIXME. Is this still needed? */
334 /* Nonzero if this subspace is loadable. */
337 /* Nonzero if this subspace contains only code. */
340 /* Nonzero if this is a common subspace. */
343 /* Nonzero if this is a common subspace which allows symbols
344 to be multiply defined. */
347 /* Nonzero if this subspace should be zero filled. */
350 /* Sort key for this subspace. */
353 /* Access control bits for this subspace. Can represent RWX access
354 as well as privilege level changes for gateways. */
357 /* Index of containing space. */
360 /* Alignment (in bytes) of this subspace. */
363 /* Quadrant within space where this subspace should be loaded. */
366 /* An index into the default spaces array. */
369 /* Subsegment associated with this subspace. */
373 /* This structure defines attributes of the default space
374 dictionary entries. */
376 struct default_space_dict
378 /* Name of the space. */
381 /* Space number. It is possible to identify spaces within
382 assembly code numerically! */
385 /* Nonzero if this space is loadable. */
388 /* Nonzero if this space is "defined". FIXME is still needed */
391 /* Nonzero if this space can not be shared. */
394 /* Sort key for this space. */
397 /* Segment associated with this space. */
402 /* Structure for previous label tracking. Needed so that alignments,
403 callinfo declarations, etc can be easily attached to a particular
405 typedef struct label_symbol_struct
407 struct symbol
*lss_label
;
409 sd_chain_struct
*lss_space
;
414 struct label_symbol_struct
*lss_next
;
418 /* Extra information needed to perform fixups (relocations) on the PA. */
419 struct hppa_fix_struct
421 /* The field selector. */
422 enum hppa_reloc_field_selector_type_alt fx_r_field
;
427 /* Format of fixup. */
430 /* Argument relocation bits. */
433 /* The segment this fixup appears in. */
437 /* Structure to hold information about predefined registers. */
445 /* This structure defines the mapping from a FP condition string
446 to a condition number which can be recorded in an instruction. */
453 /* This structure defines a mapping from a field selector
454 string to a field selector type. */
455 struct selector_entry
461 /* Prototypes for functions local to tc-hppa.c. */
464 static void pa_check_current_space_and_subspace
PARAMS ((void));
467 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
468 static void pa_cons
PARAMS ((int));
469 static void pa_data
PARAMS ((int));
470 static void pa_float_cons
PARAMS ((int));
471 static void pa_fill
PARAMS ((int));
472 static void pa_lcomm
PARAMS ((int));
473 static void pa_lsym
PARAMS ((int));
474 static void pa_stringer
PARAMS ((int));
475 static void pa_text
PARAMS ((int));
476 static void pa_version
PARAMS ((int));
477 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
478 static int get_expression
PARAMS ((char *));
479 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
480 static int evaluate_absolute
PARAMS ((struct pa_it
*));
481 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
482 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
483 static int pa_parse_nullif
PARAMS ((char **));
484 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
485 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
486 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
487 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
488 static void pa_block
PARAMS ((int));
489 static void pa_brtab
PARAMS ((int));
490 static void pa_try
PARAMS ((int));
491 static void pa_call
PARAMS ((int));
492 static void pa_call_args
PARAMS ((struct call_desc
*));
493 static void pa_callinfo
PARAMS ((int));
494 static void pa_code
PARAMS ((int));
495 static void pa_comm
PARAMS ((int));
496 static void pa_copyright
PARAMS ((int));
497 static void pa_end
PARAMS ((int));
498 static void pa_enter
PARAMS ((int));
499 static void pa_entry
PARAMS ((int));
500 static void pa_equ
PARAMS ((int));
501 static void pa_exit
PARAMS ((int));
502 static void pa_export
PARAMS ((int));
503 static void pa_type_args
PARAMS ((symbolS
*, int));
504 static void pa_import
PARAMS ((int));
505 static void pa_label
PARAMS ((int));
506 static void pa_leave
PARAMS ((int));
507 static void pa_level
PARAMS ((int));
508 static void pa_origin
PARAMS ((int));
509 static void pa_proc
PARAMS ((int));
510 static void pa_procend
PARAMS ((int));
511 static void pa_param
PARAMS ((int));
512 static void pa_undefine_label
PARAMS ((void));
513 static int need_pa11_opcode
PARAMS ((struct pa_it
*,
514 struct pa_11_fp_reg_struct
*));
515 static int pa_parse_number
PARAMS ((char **, struct pa_11_fp_reg_struct
*));
516 static label_symbol_struct
*pa_get_label
PARAMS ((void));
518 static void pa_compiler
PARAMS ((int));
519 static void pa_align
PARAMS ((int));
520 static void pa_space
PARAMS ((int));
521 static void pa_spnum
PARAMS ((int));
522 static void pa_subspace
PARAMS ((int));
523 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, int,
526 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
531 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
532 char *, int, int, int,
536 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
537 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
538 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
539 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
541 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
542 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
543 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
544 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
545 static void pa_spaces_begin
PARAMS ((void));
547 static void pa_ip
PARAMS ((char *));
548 static void fix_new_hppa
PARAMS ((fragS
*, int, int, symbolS
*,
549 long, expressionS
*, int,
550 bfd_reloc_code_real_type
,
551 enum hppa_reloc_field_selector_type_alt
,
553 static int is_end_of_statement
PARAMS ((void));
554 static int reg_name_search
PARAMS ((char *));
555 static int pa_chk_field_selector
PARAMS ((char **));
556 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
557 static void process_exit
PARAMS ((void));
558 static int log2
PARAMS ((int));
559 static unsigned int pa_stringer_aux
PARAMS ((char *));
562 static void hppa_elf_mark_end_of_function
PARAMS ((void));
563 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
566 /* File and gloally scoped variable declarations. */
569 /* Root and final entry in the space chain. */
570 static sd_chain_struct
*space_dict_root
;
571 static sd_chain_struct
*space_dict_last
;
573 /* The current space and subspace. */
574 static sd_chain_struct
*current_space
;
575 static ssd_chain_struct
*current_subspace
;
578 /* Root of the call_info chain. */
579 static struct call_info
*call_info_root
;
581 /* The last call_info (for functions) structure
582 seen so it can be associated with fixups and
584 static struct call_info
*last_call_info
;
586 /* The last call description (for actual calls). */
587 static struct call_desc last_call_desc
;
589 /* handle of the OPCODE hash table */
590 static struct hash_control
*op_hash
= NULL
;
592 /* This array holds the chars that always start a comment. If the
593 pre-processor is disabled, these aren't very useful. */
594 const char comment_chars
[] = ";";
596 /* Table of pseudo ops for the PA. FIXME -- how many of these
597 are now redundant with the overall GAS and the object file
599 const pseudo_typeS md_pseudo_table
[] =
601 /* align pseudo-ops on the PA specify the actual alignment requested,
602 not the log2 of the requested alignment. */
604 {"align", pa_align
, 8},
607 {"align", s_align_bytes
, 8},
609 {"begin_brtab", pa_brtab
, 1},
610 {"begin_try", pa_try
, 1},
611 {"block", pa_block
, 1},
612 {"blockz", pa_block
, 0},
613 {"byte", pa_cons
, 1},
614 {"call", pa_call
, 0},
615 {"callinfo", pa_callinfo
, 0},
616 {"code", pa_code
, 0},
617 {"comm", pa_comm
, 0},
619 {"compiler", pa_compiler
, 0},
621 {"copyright", pa_copyright
, 0},
622 {"data", pa_data
, 0},
623 {"double", pa_float_cons
, 'd'},
624 {"dword", pa_cons
, 8},
626 {"end_brtab", pa_brtab
, 0},
627 {"end_try", pa_try
, 0},
628 {"enter", pa_enter
, 0},
629 {"entry", pa_entry
, 0},
631 {"exit", pa_exit
, 0},
632 {"export", pa_export
, 0},
633 {"fill", pa_fill
, 0},
634 {"float", pa_float_cons
, 'f'},
635 {"half", pa_cons
, 2},
636 {"import", pa_import
, 0},
638 {"label", pa_label
, 0},
639 {"lcomm", pa_lcomm
, 0},
640 {"leave", pa_leave
, 0},
641 {"level", pa_level
, 0},
642 {"long", pa_cons
, 4},
643 {"lsym", pa_lsym
, 0},
645 {"nsubspa", pa_subspace
, 1},
647 {"octa", pa_cons
, 16},
648 {"org", pa_origin
, 0},
649 {"origin", pa_origin
, 0},
650 {"param", pa_param
, 0},
651 {"proc", pa_proc
, 0},
652 {"procend", pa_procend
, 0},
653 {"quad", pa_cons
, 8},
655 {"short", pa_cons
, 2},
656 {"single", pa_float_cons
, 'f'},
658 {"space", pa_space
, 0},
659 {"spnum", pa_spnum
, 0},
661 {"string", pa_stringer
, 0},
662 {"stringz", pa_stringer
, 1},
664 {"subspa", pa_subspace
, 0},
666 {"text", pa_text
, 0},
667 {"version", pa_version
, 0},
668 {"word", pa_cons
, 4},
672 /* This array holds the chars that only start a comment at the beginning of
673 a line. If the line seems to have the form '# 123 filename'
674 .line and .file directives will appear in the pre-processed output.
676 Note that input_file.c hand checks for '#' at the beginning of the
677 first line of the input file. This is because the compiler outputs
678 #NO_APP at the beginning of its output.
680 Also note that C style comments will always work. */
681 const char line_comment_chars
[] = "#";
683 /* This array holds the characters which act as line separators. */
684 const char line_separator_chars
[] = "!";
686 /* Chars that can be used to separate mant from exp in floating point nums. */
687 const char EXP_CHARS
[] = "eE";
689 /* Chars that mean this number is a floating point constant.
690 As in 0f12.456 or 0d1.2345e12.
692 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
693 changed in read.c. Ideally it shouldn't hae to know abou it at
694 all, but nothing is ideal around here. */
695 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
697 static struct pa_it the_insn
;
699 /* Points to the end of an expression just parsed by get_expressoin
700 and friends. FIXME. This shouldn't be handled with a file-global
702 static char *expr_end
;
704 /* Nonzero if a .callinfo appeared within the current procedure. */
705 static int callinfo_found
;
707 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
708 static int within_entry_exit
;
710 /* Nonzero if the assembler is currently within a procedure definition. */
711 static int within_procedure
;
713 /* Handle on strucutre which keep track of the last symbol
714 seen in each subspace. */
715 static label_symbol_struct
*label_symbols_rootp
= NULL
;
717 /* Holds the last field selector. */
718 static int hppa_field_selector
;
720 /* Nonzero when strict syntax checking is enabled. Zero otherwise.
722 Each opcode in the table has a flag which indicates whether or not
723 strict syntax checking should be enabled for that instruction. */
724 static int strict
= 0;
727 /* A dummy bfd symbol so that all relocations have symbols of some kind. */
728 static symbolS
*dummy_symbol
;
731 /* Nonzero if errors are to be printed. */
732 static int print_errors
= 1;
734 /* List of registers that are pre-defined:
736 Each general register has one predefined name of the form
737 %r<REGNUM> which has the value <REGNUM>.
739 Space and control registers are handled in a similar manner,
740 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
742 Likewise for the floating point registers, but of the form
743 %fr<REGNUM>. Floating point registers have additional predefined
744 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
745 again have the value <REGNUM>.
747 Many registers also have synonyms:
749 %r26 - %r23 have %arg0 - %arg3 as synonyms
750 %r28 - %r29 have %ret0 - %ret1 as synonyms
751 %r30 has %sp as a synonym
752 %r27 has %dp as a synonym
753 %r2 has %rp as a synonym
755 Almost every control register has a synonym; they are not listed
758 The table is sorted. Suitable for searching by a binary search. */
760 static const struct pd_reg pre_defined_registers
[] =
960 /* This table is sorted by order of the length of the string. This is
961 so we check for <> before we check for <. If we had a <> and checked
962 for < first, we would get a false match. */
963 static const struct fp_cond_map fp_cond_map
[] =
999 static const struct selector_entry selector_table
[] =
1024 /* default space and subspace dictionaries */
1026 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1027 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1029 /* pre-defined subsegments (subspaces) for the HPPA. */
1030 #define SUBSEG_CODE 0
1031 #define SUBSEG_LIT 1
1032 #define SUBSEG_MILLI 2
1033 #define SUBSEG_DATA 0
1034 #define SUBSEG_BSS 2
1035 #define SUBSEG_UNWIND 3
1036 #define SUBSEG_GDB_STRINGS 0
1037 #define SUBSEG_GDB_SYMBOLS 1
1039 static struct default_subspace_dict pa_def_subspaces
[] =
1041 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, SUBSEG_CODE
},
1042 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, SUBSEG_DATA
},
1043 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, SUBSEG_LIT
},
1044 {"$MILLICODE$", 1, 1, 0, 0, 0, 0, 8, 0x2c, 0, 8, 0, 0, SUBSEG_MILLI
},
1045 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, SUBSEG_BSS
},
1046 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1049 static struct default_space_dict pa_def_spaces
[] =
1051 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
},
1052 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
},
1053 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
}
1056 /* Misc local definitions used by the assembler. */
1058 /* These macros are used to maintain spaces/subspaces. */
1059 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1060 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1061 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1062 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1064 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1065 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1068 /* Return nonzero if the string pointed to by S potentially represents
1069 a right or left half of a FP register */
1070 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1071 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1073 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1074 main loop after insertion. */
1076 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1078 ((OPCODE) |= (FIELD) << (START)); \
1082 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1083 IGNORE is used to suppress the error message. */
1085 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1087 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1090 as_bad (_("Field out of range [%d..%d] (%d)."), (LOW), (HIGH), \
1096 #define is_DP_relative(exp) \
1097 ((exp).X_op == O_subtract \
1098 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$global$") == 0)
1100 #define is_PC_relative(exp) \
1101 ((exp).X_op == O_subtract \
1102 && strcmp (S_GET_NAME ((exp).X_op_symbol), "$PIC_pcrel$0") == 0)
1104 /* We need some complex handling for stabs (sym1 - sym2). Luckily, we'll
1105 always be able to reduce the expression to a constant, so we don't
1106 need real complex handling yet. */
1107 #define is_complex(exp) \
1108 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1110 /* Actual functions to implement the PA specific code for the assembler. */
1112 /* Called before writing the object file. Make sure entry/exit and
1113 proc/procend pairs match. */
1118 if (within_entry_exit
)
1119 as_fatal (_("Missing .exit\n"));
1121 if (within_procedure
)
1122 as_fatal (_("Missing .procend\n"));
1125 /* Returns a pointer to the label_symbol_struct for the current space.
1126 or NULL if no label_symbol_struct exists for the current space. */
1128 static label_symbol_struct
*
1131 label_symbol_struct
*label_chain
;
1133 for (label_chain
= label_symbols_rootp
;
1135 label_chain
= label_chain
->lss_next
)
1138 if (current_space
== label_chain
->lss_space
&& label_chain
->lss_label
)
1142 if (now_seg
== label_chain
->lss_segment
&& label_chain
->lss_label
)
1150 /* Defines a label for the current space. If one is already defined,
1151 this function will replace it with the new label. */
1154 pa_define_label (symbol
)
1157 label_symbol_struct
*label_chain
= pa_get_label ();
1160 label_chain
->lss_label
= symbol
;
1163 /* Create a new label entry and add it to the head of the chain. */
1165 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1166 label_chain
->lss_label
= symbol
;
1168 label_chain
->lss_space
= current_space
;
1171 label_chain
->lss_segment
= now_seg
;
1173 label_chain
->lss_next
= NULL
;
1175 if (label_symbols_rootp
)
1176 label_chain
->lss_next
= label_symbols_rootp
;
1178 label_symbols_rootp
= label_chain
;
1182 /* Removes a label definition for the current space.
1183 If there is no label_symbol_struct entry, then no action is taken. */
1186 pa_undefine_label ()
1188 label_symbol_struct
*label_chain
;
1189 label_symbol_struct
*prev_label_chain
= NULL
;
1191 for (label_chain
= label_symbols_rootp
;
1193 label_chain
= label_chain
->lss_next
)
1197 && current_space
== label_chain
->lss_space
&& label_chain
->lss_label
1200 && now_seg
== label_chain
->lss_segment
&& label_chain
->lss_label
1204 /* Remove the label from the chain and free its memory. */
1205 if (prev_label_chain
)
1206 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1208 label_symbols_rootp
= label_chain
->lss_next
;
1213 prev_label_chain
= label_chain
;
1218 /* An HPPA-specific version of fix_new. This is required because the HPPA
1219 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1220 results in the creation of an instance of an hppa_fix_struct. An
1221 hppa_fix_struct stores the extra information along with a pointer to the
1222 original fixS. This is attached to the original fixup via the
1223 tc_fix_data field. */
1226 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1227 r_type
, r_field
, r_format
, arg_reloc
, unwind_bits
)
1231 symbolS
*add_symbol
;
1235 bfd_reloc_code_real_type r_type
;
1236 enum hppa_reloc_field_selector_type_alt r_field
;
1243 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1244 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1247 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1249 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1250 new_fix
->tc_fix_data
= (void *) hppa_fix
;
1251 hppa_fix
->fx_r_type
= r_type
;
1252 hppa_fix
->fx_r_field
= r_field
;
1253 hppa_fix
->fx_r_format
= r_format
;
1254 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1255 hppa_fix
->segment
= now_seg
;
1257 if (r_type
== R_ENTRY
|| r_type
== R_EXIT
)
1258 new_fix
->fx_offset
= *unwind_bits
;
1261 /* foo-$global$ is used to access non-automatic storage. $global$
1262 is really just a marker and has served its purpose, so eliminate
1263 it now so as not to confuse write.c. */
1264 if (new_fix
->fx_subsy
1265 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1266 new_fix
->fx_subsy
= NULL
;
1269 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1270 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1273 parse_cons_expression_hppa (exp
)
1276 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1280 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1281 hppa_field_selector is set by the parse_cons_expression_hppa. */
1284 cons_fix_new_hppa (frag
, where
, size
, exp
)
1290 unsigned int rel_type
;
1292 /* Get a base relocation type. */
1293 if (is_DP_relative (*exp
))
1294 rel_type
= R_HPPA_GOTOFF
;
1295 else if (is_complex (*exp
))
1296 rel_type
= R_HPPA_COMPLEX
;
1300 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1301 as_warn (_("Invalid field selector. Assuming F%%."));
1303 fix_new_hppa (frag
, where
, size
,
1304 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, rel_type
,
1305 hppa_field_selector
, size
* 8, 0, NULL
);
1307 /* Reset field selector to its default state. */
1308 hppa_field_selector
= 0;
1311 /* This function is called once, at assembler startup time. It should
1312 set up all the tables, etc. that the MD part of the assembler will need. */
1317 const char *retval
= NULL
;
1321 last_call_info
= NULL
;
1322 call_info_root
= NULL
;
1324 /* Set the default machine type. */
1325 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
1326 as_warn (_("could not set architecture and machine"));
1328 /* Folding of text and data segments fails miserably on the PA.
1329 Warn user and disable "-R" option. */
1330 if (flag_readonly_data_in_text
)
1332 as_warn (_("-R option not supported on this target."));
1333 flag_readonly_data_in_text
= 0;
1340 op_hash
= hash_new ();
1342 while (i
< NUMOPCODES
)
1344 const char *name
= pa_opcodes
[i
].name
;
1345 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1346 if (retval
!= NULL
&& *retval
!= '\0')
1348 as_fatal (_("Internal error: can't hash `%s': %s\n"), name
, retval
);
1353 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1354 != pa_opcodes
[i
].match
)
1356 fprintf (stderr
, _("internal error: losing opcode: `%s' \"%s\"\n"),
1357 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1362 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1366 as_fatal (_("Broken assembler. No assembly attempted."));
1369 /* SOM will change text_section. To make sure we never put
1370 anything into the old one switch to the new one now. */
1371 subseg_set (text_section
, 0);
1375 dummy_symbol
= symbol_find_or_make ("L$dummy");
1376 S_SET_SEGMENT (dummy_symbol
, text_section
);
1377 /* Force the symbol to be converted to a real symbol. */
1378 (void) symbol_get_bfdsym (dummy_symbol
);
1382 /* Assemble a single instruction storing it into a frag. */
1389 /* The had better be something to assemble. */
1392 /* If we are within a procedure definition, make sure we've
1393 defined a label for the procedure; handle case where the
1394 label was defined after the .PROC directive.
1396 Note there's not need to diddle with the segment or fragment
1397 for the label symbol in this case. We have already switched
1398 into the new $CODE$ subspace at this point. */
1399 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
1401 label_symbol_struct
*label_symbol
= pa_get_label ();
1405 if (label_symbol
->lss_label
)
1407 last_call_info
->start_symbol
= label_symbol
->lss_label
;
1408 symbol_get_bfdsym (label_symbol
->lss_label
)->flags
1411 /* Also handle allocation of a fixup to hold the unwind
1412 information when the label appears after the proc/procend. */
1413 if (within_entry_exit
)
1415 char *where
= frag_more (0);
1417 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
1418 NULL
, (offsetT
) 0, NULL
,
1419 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
1420 (int *)&last_call_info
->ci_unwind
.descriptor
);
1425 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
1428 as_bad (_("Missing function name for .PROC"));
1431 /* Assemble the instruction. Results are saved into "the_insn". */
1434 /* Get somewhere to put the assembled instrution. */
1437 /* Output the opcode. */
1438 md_number_to_chars (to
, the_insn
.opcode
, 4);
1440 /* If necessary output more stuff. */
1441 if (the_insn
.reloc
!= R_HPPA_NONE
)
1442 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1443 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1444 the_insn
.reloc
, the_insn
.field_selector
,
1445 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1448 /* Do the real work for assembling a single instruction. Store results
1449 into the global "the_insn" variable. */
1455 char *error_message
= "";
1456 char *s
, c
, *argstart
, *name
, *save_s
;
1460 int cmpltr
, nullif
, flag
, cond
, num
;
1461 unsigned long opcode
;
1462 struct pa_opcode
*insn
;
1465 /* We must have a valid space and subspace. */
1466 pa_check_current_space_and_subspace ();
1469 /* Convert everything up to the first whitespace character into lower
1471 for (s
= str
; *s
!= ' ' && *s
!= '\t' && *s
!= '\n' && *s
!= '\0'; s
++)
1475 /* Skip to something interesting. */
1476 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1495 as_fatal (_("Unknown opcode: `%s'"), str
);
1500 /* Look up the opcode in the has table. */
1501 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1503 as_bad ("Unknown opcode: `%s'", str
);
1512 /* Mark the location where arguments for the instruction start, then
1513 start processing them. */
1517 /* Do some initialization. */
1518 opcode
= insn
->match
;
1519 strict
= (insn
->flags
& FLAG_STRICT
);
1520 memset (&the_insn
, 0, sizeof (the_insn
));
1522 the_insn
.reloc
= R_HPPA_NONE
;
1524 /* If this instruction is specific to a particular architecture,
1525 then set a new architecture. */
1526 /* But do not automatically promote to pa2.0. The automatic promotion
1527 crud is for compatability with HP's old assemblers only. */
1529 && bfd_get_mach (stdoutput
) < insn
->arch
)
1531 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, insn
->arch
))
1532 as_warn (_("could not update architecture and machine"));
1534 else if (bfd_get_mach (stdoutput
) < insn
->arch
)
1540 /* Build the opcode, checking as we go to make
1541 sure that the operands match. */
1542 for (args
= insn
->args
;; ++args
)
1544 /* Absorb white space in instruction. */
1545 while (*s
== ' ' || *s
== '\t')
1551 /* End of arguments. */
1567 /* These must match exactly. */
1576 /* Handle a 5 bit register or control register field at 10. */
1579 /* This should be more strict. Small steps. */
1580 if (strict
&& *s
!= '%')
1582 num
= pa_parse_number (&s
, 0);
1583 CHECK_FIELD (num
, 31, 0, 0);
1584 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1586 /* Handle %sar or %cr11. No bits get set, we just verify that it
1589 /* Skip whitespace before register. */
1590 while (*s
== ' ' || *s
== '\t')
1593 if (!strncasecmp(s
, "%sar", 4))
1598 else if (!strncasecmp(s
, "%cr11", 5))
1605 /* Handle a 5 bit register field at 15. */
1607 /* This should be more strict. Small steps. */
1608 if (strict
&& *s
!= '%')
1610 num
= pa_parse_number (&s
, 0);
1611 CHECK_FIELD (num
, 31, 0, 0);
1612 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1614 /* Handle a 5 bit register field at 31. */
1616 /* This should be more strict. Small steps. */
1617 if (strict
&& *s
!= '%')
1619 num
= pa_parse_number (&s
, 0);
1620 CHECK_FIELD (num
, 31, 0, 0);
1621 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1623 /* Handle a 5 bit register field at 10 and 15. */
1625 /* This should be more strict. Small steps. */
1626 if (strict
&& *s
!= '%')
1628 num
= pa_parse_number (&s
, 0);
1629 CHECK_FIELD (num
, 31, 0, 0);
1630 opcode
|= num
<< 16;
1631 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1633 /* Handle a 5 bit field length at 31. */
1635 num
= pa_get_absolute_expression (&the_insn
, &s
);
1636 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1639 CHECK_FIELD (num
, 32, 1, 0);
1640 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1642 /* Handle a 5 bit immediate at 15. */
1644 num
= pa_get_absolute_expression (&the_insn
, &s
);
1645 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1648 /* When in strict mode, we want to just reject this
1649 match instead of giving an out of range error. */
1650 CHECK_FIELD (num
, 15, -16, strict
);
1651 low_sign_unext (num
, 5, &num
);
1652 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1654 /* Handle a 5 bit immediate at 31. */
1656 num
= pa_get_absolute_expression (&the_insn
, &s
);
1657 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1660 /* When in strict mode, we want to just reject this
1661 match instead of giving an out of range error. */
1662 CHECK_FIELD (num
, 15, -16, strict
)
1663 low_sign_unext (num
, 5, &num
);
1664 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1666 /* Handle an unsigned 5 bit immediate at 31. */
1668 num
= pa_get_absolute_expression (&the_insn
, &s
);
1669 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1672 CHECK_FIELD (num
, 31, 0, 0);
1673 INSERT_FIELD_AND_CONTINUE (opcode
, num
, strict
);
1675 /* Handle an unsigned 5 bit immediate at 15. */
1677 num
= pa_get_absolute_expression (&the_insn
, &s
);
1678 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1681 CHECK_FIELD (num
, 31, 0, strict
);
1682 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1684 /* Handle an unsigned 10 bit immediate at 15. */
1686 num
= pa_get_absolute_expression (&the_insn
, &s
);
1687 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
1690 CHECK_FIELD (num
, 1023, 0, strict
);
1691 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1693 /* Handle a 2 bit space identifier at 17. */
1695 /* This should be more strict. Small steps. */
1696 if (strict
&& *s
!= '%')
1698 num
= pa_parse_number (&s
, 0);
1699 CHECK_FIELD (num
, 3, 0, 1);
1700 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1702 /* Handle a 3 bit space identifier at 18. */
1704 /* This should be more strict. Small steps. */
1705 if (strict
&& *s
!= '%')
1707 num
= pa_parse_number (&s
, 0);
1708 CHECK_FIELD (num
, 7, 0, 1);
1709 dis_assemble_3 (num
, &num
);
1710 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1712 /* Handle all completers. */
1717 /* Handle a completer for an indexing load or store. */
1723 while (*s
== ',' && i
< 2)
1726 if (strncasecmp (s
, "sm", 2) == 0)
1733 else if (strncasecmp (s
, "m", 1) == 0)
1735 else if (strncasecmp (s
, "s", 1) == 0)
1737 /* When in strict mode this is a match failure. */
1741 as_bad (_("Invalid Indexed Load Completer."));
1746 as_bad (_("Invalid Indexed Load Completer Syntax."));
1748 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1751 /* Handle a short load/store completer. */
1759 if (strncasecmp (s
, "ma", 2) == 0)
1764 else if (strncasecmp (s
, "mb", 2) == 0)
1769 /* When in strict mode this is a match failure. */
1773 as_bad (_("Invalid Short Load/Store Completer."));
1778 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1781 /* Handle a stbys completer. */
1787 while (*s
== ',' && i
< 2)
1790 if (strncasecmp (s
, "m", 1) == 0)
1792 else if (strncasecmp (s
, "b", 1) == 0)
1794 else if (strncasecmp (s
, "e", 1) == 0)
1796 /* When in strict mode this is a match failure. */
1800 as_bad (_("Invalid Store Bytes Short Completer"));
1805 as_bad (_("Invalid Store Bytes Short Completer"));
1807 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1810 /* Handle a local processor completer. */
1812 if (strncasecmp (s
, ",l", 2) != 0)
1817 /* Handle a PROBE read/write completer. */
1820 if (!strncasecmp (s
, ",w", 2))
1825 else if (!strncasecmp (s
, ",r", 2))
1831 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 6);
1833 /* Handle MFCTL wide completer. */
1835 if (strncasecmp (s
, ",w", 2) != 0)
1840 /* Handle an RFI restore completer. */
1843 if (!strncasecmp (s
, ",r", 2))
1849 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1851 /* Handle a system control completer. */
1853 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
1861 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
1863 /* Handle intermediate/final completer for DCOR. */
1866 if (!strncasecmp (s
, ",i", 2))
1872 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 6);
1874 /* Handle zero/sign extension completer. */
1877 if (!strncasecmp (s
, ",z", 2))
1883 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 10);
1885 /* Handle add completer. */
1888 if (!strncasecmp (s
, ",l", 2))
1893 else if (!strncasecmp (s
, ",tsv", 4))
1899 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 10);
1901 /* Handle 64 bit carry for ADD. */
1904 if (!strncasecmp (s
, ",dc,tsv", 7) ||
1905 !strncasecmp (s
, ",tsv,dc", 7))
1910 else if (!strncasecmp (s
, ",dc", 3))
1918 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1920 /* Handle 32 bit carry for ADD. */
1923 if (!strncasecmp (s
, ",c,tsv", 6) ||
1924 !strncasecmp (s
, ",tsv,c", 6))
1929 else if (!strncasecmp (s
, ",c", 2))
1937 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1939 /* Handle trap on signed overflow. */
1942 if (!strncasecmp (s
, ",tsv", 4))
1948 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1950 /* Handle trap on condition and overflow. */
1953 if (!strncasecmp (s
, ",tc,tsv", 7) ||
1954 !strncasecmp (s
, ",tsv,tc", 7))
1959 else if (!strncasecmp (s
, ",tc", 3))
1967 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1969 /* Handle 64 bit borrow for SUB. */
1972 if (!strncasecmp (s
, ",db,tsv", 7) ||
1973 !strncasecmp (s
, ",tsv,db", 7))
1978 else if (!strncasecmp (s
, ",db", 3))
1986 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
1988 /* Handle 32 bit borrow for SUB. */
1991 if (!strncasecmp (s
, ",b,tsv", 6) ||
1992 !strncasecmp (s
, ",tsv,b", 6))
1997 else if (!strncasecmp (s
, ",b", 2))
2005 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2007 /* Handle trap condition completer for UADDCM. */
2010 if (!strncasecmp (s
, ",tc", 3))
2016 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 6);
2018 /* Handle signed/unsigned at 21. */
2022 if (strncasecmp (s
, ",s", 2) == 0)
2027 else if (strncasecmp (s
, ",u", 2) == 0)
2033 INSERT_FIELD_AND_CONTINUE (opcode
, sign
, 10);
2036 /* Handle left/right combination at 17:18. */
2046 as_bad(_("Invalid left/right combination completer"));
2049 INSERT_FIELD_AND_CONTINUE (opcode
, lr
, 13);
2052 as_bad(_("Invalid left/right combination completer"));
2055 /* Handle saturation at 24:25. */
2059 if (strncasecmp (s
, ",ss", 3) == 0)
2064 else if (strncasecmp (s
, ",us", 3) == 0)
2070 INSERT_FIELD_AND_CONTINUE (opcode
, sat
, 6);
2073 /* Handle permutation completer. */
2077 int permloc
[4] = {13,10,8,6};
2097 as_bad(_("Invalid permutation completer"));
2099 opcode
|= perm
<< permloc
[i
];
2104 as_bad(_("Invalid permutation completer"));
2112 /* Handle all conditions. */
2118 /* Handle FP compare conditions. */
2120 cond
= pa_parse_fp_cmp_cond (&s
);
2121 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2123 /* Handle an add condition. */
2132 /* 64 bit conditions. */
2145 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2149 if (strcmp (name
, "=") == 0)
2151 else if (strcmp (name
, "<") == 0)
2153 else if (strcmp (name
, "<=") == 0)
2155 else if (strcasecmp (name
, "nuv") == 0)
2157 else if (strcasecmp (name
, "znv") == 0)
2159 else if (strcasecmp (name
, "sv") == 0)
2161 else if (strcasecmp (name
, "od") == 0)
2163 else if (strcasecmp (name
, "tr") == 0)
2168 else if (strcmp (name
, "<>") == 0)
2173 else if (strcmp (name
, ">=") == 0)
2178 else if (strcmp (name
, ">") == 0)
2183 else if (strcasecmp (name
, "uv") == 0)
2188 else if (strcasecmp (name
, "vnz") == 0)
2193 else if (strcasecmp (name
, "nsv") == 0)
2198 else if (strcasecmp (name
, "ev") == 0)
2203 /* ",*" is a valid condition. */
2204 else if (*args
== 'a')
2205 as_bad (_("Invalid Add Condition: %s"), name
);
2208 opcode
|= cmpltr
<< 13;
2209 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2211 /* Handle non-negated add and branch condition. */
2213 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
2216 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s
);
2219 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2221 /* Handle negated add and branch condition. */
2225 /* Handle wide-mode non-negated add and branch condition. */
2229 /* Handle wide-mode negated add and branch condition. */
2233 /* Handle a negated or non-negated add and branch
2237 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
2241 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
2244 as_bad (_("Invalid Compare/Subtract Condition"));
2249 /* Negated condition requires an opcode change. */
2253 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2255 /* Handle branch on bit conditions. */
2273 if (strncmp (s
, "<", 1) == 0)
2278 else if (strncmp (s
, ">=", 2) == 0)
2284 as_bad (_("Invalid Bit Branch Condition: %c"), *s
);
2286 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 15);
2288 /* Handle a compare/subtract condition. */
2297 /* 64 bit conditions. */
2310 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2314 if (strcmp (name
, "=") == 0)
2316 else if (strcmp (name
, "<") == 0)
2318 else if (strcmp (name
, "<=") == 0)
2320 else if (strcasecmp (name
, "<<") == 0)
2322 else if (strcasecmp (name
, "<<=") == 0)
2324 else if (strcasecmp (name
, "sv") == 0)
2326 else if (strcasecmp (name
, "od") == 0)
2328 else if (strcasecmp (name
, "tr") == 0)
2333 else if (strcmp (name
, "<>") == 0)
2338 else if (strcmp (name
, ">=") == 0)
2343 else if (strcmp (name
, ">") == 0)
2348 else if (strcasecmp (name
, ">>=") == 0)
2353 else if (strcasecmp (name
, ">>") == 0)
2358 else if (strcasecmp (name
, "nsv") == 0)
2363 else if (strcasecmp (name
, "ev") == 0)
2368 /* ",*" is a valid condition. */
2369 else if (*args
!= 'S')
2370 as_bad (_("Invalid Compare/Subtract Condition: %s"),
2374 opcode
|= cmpltr
<< 13;
2375 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2377 /* Handle a non-negated compare condition. */
2379 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
2382 as_bad (_("Invalid Compare/Subtract Condition: %c"), *s
);
2385 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2387 /* Handle a negated compare condition. */
2391 /* Handle a 64 bit non-negated compare condition. */
2395 /* Handle a 64 bit negated compare condition. */
2399 /* Handle a 64 bit cmpib condition. */
2403 /* Handle a negated or non-negated compare/subtract
2407 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
2411 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
2414 as_bad (_("Invalid Compare/Subtract Condition."));
2419 /* Negated condition requires an opcode change. */
2424 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2426 /* Handle a logical instruction condition. */
2435 /* 64 bit conditions. */
2448 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2454 if (strcmp (name
, "=") == 0)
2456 else if (strcmp (name
, "<") == 0)
2458 else if (strcmp (name
, "<=") == 0)
2460 else if (strcasecmp (name
, "od") == 0)
2462 else if (strcasecmp (name
, "tr") == 0)
2467 else if (strcmp (name
, "<>") == 0)
2472 else if (strcmp (name
, ">=") == 0)
2477 else if (strcmp (name
, ">") == 0)
2482 else if (strcasecmp (name
, "ev") == 0)
2487 /* ",*" is a valid condition. */
2488 else if (*args
!= 'L')
2489 as_bad (_("Invalid Logical Instruction Condition."));
2492 opcode
|= cmpltr
<< 13;
2493 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2495 /* Handle a shift/extract/deposit condition. */
2504 /* 64 bit conditions. */
2517 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2521 if (strcmp (name
, "=") == 0)
2523 else if (strcmp (name
, "<") == 0)
2525 else if (strcasecmp (name
, "od") == 0)
2527 else if (strcasecmp (name
, "tr") == 0)
2529 else if (strcmp (name
, "<>") == 0)
2531 else if (strcmp (name
, ">=") == 0)
2533 else if (strcasecmp (name
, "ev") == 0)
2535 /* Handle movb,n. Put things back the way they were.
2536 This includes moving s back to where it started. */
2537 else if (strcasecmp (name
, "n") == 0 && *args
== 'y')
2543 /* ",*" is a valid condition. */
2544 else if (*args
!= 'X')
2545 as_bad (_("Invalid Shift/Extract/Deposit Condition."));
2548 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2550 /* Handle a unit instruction condition. */
2559 /* 64 bit conditions. */
2570 if (strncasecmp (s
, "sbz", 3) == 0)
2575 else if (strncasecmp (s
, "shz", 3) == 0)
2580 else if (strncasecmp (s
, "sdc", 3) == 0)
2585 else if (strncasecmp (s
, "sbc", 3) == 0)
2590 else if (strncasecmp (s
, "shc", 3) == 0)
2595 else if (strncasecmp (s
, "tr", 2) == 0)
2601 else if (strncasecmp (s
, "nbz", 3) == 0)
2607 else if (strncasecmp (s
, "nhz", 3) == 0)
2613 else if (strncasecmp (s
, "ndc", 3) == 0)
2619 else if (strncasecmp (s
, "nbc", 3) == 0)
2625 else if (strncasecmp (s
, "nhc", 3) == 0)
2631 /* ",*" is a valid condition. */
2632 else if (*args
!= 'U')
2633 as_bad (_("Invalid Unit Instruction Condition."));
2635 opcode
|= cmpltr
<< 13;
2636 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2644 /* Handle a nullification completer for branch instructions. */
2646 nullif
= pa_parse_nullif (&s
);
2647 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2649 /* Handle a nullification completer for copr and spop insns. */
2651 nullif
= pa_parse_nullif (&s
);
2652 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 5);
2655 /* Handle a 11 bit immediate at 31. */
2657 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2660 if (the_insn
.exp
.X_op
== O_constant
)
2662 num
= evaluate_absolute (&the_insn
);
2663 CHECK_FIELD (num
, 1023, -1024, 0);
2664 low_sign_unext (num
, 11, &num
);
2665 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2669 if (is_DP_relative (the_insn
.exp
))
2670 the_insn
.reloc
= R_HPPA_GOTOFF
;
2671 else if (is_PC_relative (the_insn
.exp
))
2672 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2674 the_insn
.reloc
= R_HPPA
;
2675 the_insn
.format
= 11;
2680 /* Handle a 14 bit immediate at 31. */
2682 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2685 if (the_insn
.exp
.X_op
== O_constant
)
2687 num
= evaluate_absolute (&the_insn
);
2688 CHECK_FIELD (num
, 8191, -8192, 0);
2689 low_sign_unext (num
, 14, &num
);
2690 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2694 if (is_DP_relative (the_insn
.exp
))
2695 the_insn
.reloc
= R_HPPA_GOTOFF
;
2696 else if (is_PC_relative (the_insn
.exp
))
2697 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2699 the_insn
.reloc
= R_HPPA
;
2700 the_insn
.format
= 14;
2704 /* Handle a 21 bit immediate at 31. */
2706 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2709 if (the_insn
.exp
.X_op
== O_constant
)
2711 num
= evaluate_absolute (&the_insn
);
2712 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2713 dis_assemble_21 (num
, &num
);
2714 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2718 if (is_DP_relative (the_insn
.exp
))
2719 the_insn
.reloc
= R_HPPA_GOTOFF
;
2720 else if (is_PC_relative (the_insn
.exp
))
2721 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2723 the_insn
.reloc
= R_HPPA
;
2724 the_insn
.format
= 21;
2728 /* Handle a 12 bit branch displacement. */
2730 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2734 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2736 unsigned int w1
, w
, result
;
2738 num
= evaluate_absolute (&the_insn
);
2741 as_bad (_("Branch to unaligned address"));
2744 CHECK_FIELD (num
, 8199, -8184, 0);
2745 sign_unext ((num
- 8) >> 2, 12, &result
);
2746 dis_assemble_12 (result
, &w1
, &w
);
2747 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2751 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2752 the_insn
.format
= 12;
2753 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2754 memset (&last_call_desc
, 0, sizeof (struct call_desc
));
2759 /* Handle a 17 bit branch displacement. */
2761 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2765 if (!the_insn
.exp
.X_add_symbol
2766 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2769 unsigned int w2
, w1
, w
, result
;
2771 num
= evaluate_absolute (&the_insn
);
2774 as_bad (_("Branch to unaligned address"));
2777 CHECK_FIELD (num
, 262143, -262144, 0);
2779 if (the_insn
.exp
.X_add_symbol
)
2782 sign_unext (num
>> 2, 17, &result
);
2783 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2784 INSERT_FIELD_AND_CONTINUE (opcode
,
2785 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2789 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2790 the_insn
.format
= 17;
2791 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2792 memset (&last_call_desc
, 0, sizeof (struct call_desc
));
2796 /* Handle an absolute 17 bit branch target. */
2798 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2802 if (!the_insn
.exp
.X_add_symbol
2803 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2806 unsigned int w2
, w1
, w
, result
;
2808 num
= evaluate_absolute (&the_insn
);
2811 as_bad (_("Branch to unaligned address"));
2814 CHECK_FIELD (num
, 262143, -262144, 0);
2816 if (the_insn
.exp
.X_add_symbol
)
2819 sign_unext (num
>> 2, 17, &result
);
2820 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2821 INSERT_FIELD_AND_CONTINUE (opcode
,
2822 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2826 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2827 the_insn
.format
= 17;
2828 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2829 memset (&last_call_desc
, 0, sizeof (struct call_desc
));
2833 /* Handle a 2 bit shift count at 25. */
2835 num
= pa_get_absolute_expression (&the_insn
, &s
);
2836 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2839 CHECK_FIELD (num
, 3, 1, strict
);
2840 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2842 /* Handle a 4 bit shift count at 25. */
2844 num
= pa_get_absolute_expression (&the_insn
, &s
);
2845 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2848 CHECK_FIELD (num
, 15, 0, strict
);
2849 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2851 /* Handle a 5 bit shift count at 26. */
2853 num
= pa_get_absolute_expression (&the_insn
, &s
);
2854 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2857 CHECK_FIELD (num
, 31, 0, strict
);
2858 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2860 /* Handle a 6 bit shift count at 20,22:26. */
2862 num
= pa_get_absolute_expression (&the_insn
, &s
);
2863 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2866 CHECK_FIELD (num
, 63, 0, strict
);
2868 opcode
|= (num
& 0x20) << 6;
2869 INSERT_FIELD_AND_CONTINUE (opcode
, num
& 0x1f, 5);
2871 /* Handle a 6 bit field length at 23,27:31. */
2874 num
= pa_get_absolute_expression (&the_insn
, &s
);
2875 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2878 CHECK_FIELD (num
, 64, 1, strict
);
2880 opcode
|= (num
& 0x20) << 3;
2881 num
= 31 - (num
& 0x1f);
2882 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2884 /* Handle a 6 bit field length at 19,27:31. */
2886 num
= pa_get_absolute_expression (&the_insn
, &s
);
2887 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2890 CHECK_FIELD (num
, 64, 1, strict
);
2892 opcode
|= (num
& 0x20) << 7;
2893 num
= 31 - (num
& 0x1f);
2894 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2896 /* Handle a 5 bit bit position at 26. */
2898 num
= pa_get_absolute_expression (&the_insn
, &s
);
2899 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2902 CHECK_FIELD (num
, 31, 0, strict
);
2903 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2905 /* Handle a 6 bit bit position at 20,22:26. */
2907 num
= pa_get_absolute_expression (&the_insn
, &s
);
2908 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2911 CHECK_FIELD (num
, 63, 0, strict
);
2912 opcode
|= (num
& 0x20) << 6;
2913 INSERT_FIELD_AND_CONTINUE (opcode
, num
& 0x1f, 5);
2915 /* Handle a 5 bit immediate at 10. */
2917 num
= pa_get_absolute_expression (&the_insn
, &s
);
2918 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2920 if (the_insn
.exp
.X_op
!= O_constant
)
2923 CHECK_FIELD (num
, 31, 0, strict
);
2924 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2926 /* Handle a 9 bit immediate at 28. */
2928 num
= pa_get_absolute_expression (&the_insn
, &s
);
2929 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2932 CHECK_FIELD (num
, 511, 1, strict
);
2933 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 3);
2935 /* Handle a 13 bit immediate at 18. */
2937 num
= pa_get_absolute_expression (&the_insn
, &s
);
2938 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2941 CHECK_FIELD (num
, 8191, 0, strict
);
2942 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2944 /* Handle a 26 bit immediate at 31. */
2946 num
= pa_get_absolute_expression (&the_insn
, &s
);
2947 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2950 CHECK_FIELD (num
, 671108864, 0, strict
);
2951 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2953 /* Handle a 3 bit SFU identifier at 25. */
2956 as_bad (_("Invalid SFU identifier"));
2957 num
= pa_get_absolute_expression (&the_insn
, &s
);
2958 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2961 CHECK_FIELD (num
, 7, 0, strict
);
2962 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2964 /* Handle a 20 bit SOP field for spop0. */
2966 num
= pa_get_absolute_expression (&the_insn
, &s
);
2967 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2970 CHECK_FIELD (num
, 1048575, 0, strict
);
2971 num
= (num
& 0x1f) | ((num
& 0x000fffe0) << 6);
2972 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2974 /* Handle a 15bit SOP field for spop1. */
2976 num
= pa_get_absolute_expression (&the_insn
, &s
);
2977 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2980 CHECK_FIELD (num
, 32767, 0, strict
);
2981 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 11);
2983 /* Handle a 10bit SOP field for spop3. */
2985 num
= pa_get_absolute_expression (&the_insn
, &s
);
2986 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2989 CHECK_FIELD (num
, 1023, 0, strict
);
2990 num
= (num
& 0x1f) | ((num
& 0x000003e0) << 6);
2991 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2993 /* Handle a 15 bit SOP field for spop2. */
2995 num
= pa_get_absolute_expression (&the_insn
, &s
);
2996 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
2999 CHECK_FIELD (num
, 32767, 0, strict
);
3000 num
= (num
& 0x1f) | ((num
& 0x00007fe0) << 6);
3001 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3003 /* Handle a 3-bit co-processor ID field. */
3006 as_bad (_("Invalid COPR identifier"));
3007 num
= pa_get_absolute_expression (&the_insn
, &s
);
3008 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3011 CHECK_FIELD (num
, 7, 0, strict
);
3012 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
3014 /* Handle a 22bit SOP field for copr. */
3016 num
= pa_get_absolute_expression (&the_insn
, &s
);
3017 if (strict
&& the_insn
.exp
.X_op
!= O_constant
)
3020 CHECK_FIELD (num
, 4194303, 0, strict
);
3021 num
= (num
& 0x1f) | ((num
& 0x003fffe0) << 4);
3022 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3025 /* Handle a source FP operand format completer. */
3027 flag
= pa_parse_fp_format (&s
);
3028 the_insn
.fpof1
= flag
;
3029 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
3031 /* Handle a destination FP operand format completer. */
3033 /* pa_parse_format needs the ',' prefix. */
3035 flag
= pa_parse_fp_format (&s
);
3036 the_insn
.fpof2
= flag
;
3037 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
3039 /* Handle a source FP operand format completer at 20. */
3041 flag
= pa_parse_fp_format (&s
);
3042 the_insn
.fpof1
= flag
;
3043 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
3045 /* Handle a floating point operand format at 26.
3046 Only allows single and double precision. */
3048 flag
= pa_parse_fp_format (&s
);
3054 the_insn
.fpof1
= flag
;
3060 as_bad (_("Invalid Floating Point Operand Format."));
3064 /* Handle all floating point registers. */
3068 /* Float target register. */
3070 /* This should be more strict. Small steps. */
3071 if (strict
&& *s
!= '%')
3073 num
= pa_parse_number (&s
, 0);
3074 CHECK_FIELD (num
, 31, 0, 0);
3075 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
3077 /* Float target register with L/R selection. */
3080 struct pa_11_fp_reg_struct result
;
3082 /* This should be more strict. Small steps. */
3083 if (strict
&& *s
!= '%')
3085 pa_parse_number (&s
, &result
);
3086 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3087 opcode
|= result
.number_part
;
3089 /* 0x30 opcodes are FP arithmetic operation opcodes
3090 and need to be turned into 0x38 opcodes. This
3091 is not necessary for loads/stores. */
3092 if (need_pa11_opcode (&the_insn
, &result
)
3093 && ((opcode
& 0xfc000000) == 0x30000000))
3096 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
3099 /* Float operand 1. */
3102 struct pa_11_fp_reg_struct result
;
3104 /* This should be more strict. Small steps. */
3105 if (strict
&& *s
!= '%')
3107 pa_parse_number (&s
, &result
);
3108 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3109 opcode
|= result
.number_part
<< 21;
3110 if (need_pa11_opcode (&the_insn
, &result
))
3112 opcode
|= (result
.l_r_select
& 1) << 7;
3118 /* Float operand 1 with L/R selection. */
3121 struct pa_11_fp_reg_struct result
;
3123 /* This should be more strict. Small steps. */
3124 if (strict
&& *s
!= '%')
3126 pa_parse_number (&s
, &result
);
3127 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3128 opcode
|= result
.number_part
<< 21;
3129 opcode
|= (result
.l_r_select
& 1) << 7;
3133 /* Float operand 2. */
3136 struct pa_11_fp_reg_struct result
;
3138 /* This should be more strict. Small steps. */
3139 if (strict
&& *s
!= '%')
3141 pa_parse_number (&s
, &result
);
3142 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3143 opcode
|= (result
.number_part
& 0x1f) << 16;
3144 if (need_pa11_opcode (&the_insn
, &result
))
3146 opcode
|= (result
.l_r_select
& 1) << 12;
3152 /* Float operand 2 with L/R selection. */
3155 struct pa_11_fp_reg_struct result
;
3157 /* This should be more strict. Small steps. */
3158 if (strict
&& *s
!= '%')
3160 pa_parse_number (&s
, &result
);
3161 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3162 opcode
|= (result
.number_part
& 0x1f) << 16;
3163 opcode
|= (result
.l_r_select
& 1) << 12;
3167 /* Float operand 3 for fmpyfadd, fmpynfadd. */
3170 struct pa_11_fp_reg_struct result
;
3173 /* This should be more strict. Small steps. */
3174 if (strict
&& *s
!= '%')
3176 pa_parse_number (&s
, &result
);
3177 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3178 opcode
|= (result
.number_part
& 0x1c) << 11;
3179 opcode
|= (result
.number_part
& 0x3) << 9;
3180 opcode
|= (result
.l_r_select
& 1) << 8;
3184 /* Float mult operand 1 for fmpyadd, fmpysub */
3187 struct pa_11_fp_reg_struct result
;
3189 /* This should be more strict. Small steps. */
3190 if (strict
&& *s
!= '%')
3192 pa_parse_number (&s
, &result
);
3193 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3194 if (the_insn
.fpof1
== SGL
)
3196 if (result
.number_part
< 16)
3198 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3202 result
.number_part
&= 0xF;
3203 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3205 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
3208 /* Float mult operand 2 for fmpyadd, fmpysub */
3211 struct pa_11_fp_reg_struct result
;
3213 /* This should be more strict. Small steps. */
3214 if (strict
&& *s
!= '%')
3216 pa_parse_number (&s
, &result
);
3217 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3218 if (the_insn
.fpof1
== SGL
)
3220 if (result
.number_part
< 16)
3222 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3225 result
.number_part
&= 0xF;
3226 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3228 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
3231 /* Float mult target for fmpyadd, fmpysub */
3234 struct pa_11_fp_reg_struct result
;
3236 /* This should be more strict. Small steps. */
3237 if (strict
&& *s
!= '%')
3239 pa_parse_number (&s
, &result
);
3240 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3241 if (the_insn
.fpof1
== SGL
)
3243 if (result
.number_part
< 16)
3245 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3248 result
.number_part
&= 0xF;
3249 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3251 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
3254 /* Float add operand 1 for fmpyadd, fmpysub */
3257 struct pa_11_fp_reg_struct result
;
3259 /* This should be more strict. Small steps. */
3260 if (strict
&& *s
!= '%')
3262 pa_parse_number (&s
, &result
);
3263 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3264 if (the_insn
.fpof1
== SGL
)
3266 if (result
.number_part
< 16)
3268 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3271 result
.number_part
&= 0xF;
3272 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3274 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
3277 /* Float add target for fmpyadd, fmpysub */
3280 struct pa_11_fp_reg_struct result
;
3282 /* This should be more strict. Small steps. */
3283 if (strict
&& *s
!= '%')
3285 pa_parse_number (&s
, &result
);
3286 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3287 if (the_insn
.fpof1
== SGL
)
3289 if (result
.number_part
< 16)
3291 as_bad (_("Invalid register for single precision fmpyadd or fmpysub"));
3294 result
.number_part
&= 0xF;
3295 result
.number_part
|= (result
.l_r_select
& 1) << 4;
3297 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
3305 /* Handle L/R register halves like 'x'. */
3308 struct pa_11_fp_reg_struct result
;
3310 /* This should be more strict. Small steps. */
3311 if (strict
&& *s
!= '%')
3313 pa_parse_number (&s
, &result
);
3314 CHECK_FIELD (result
.number_part
, 31, 0, 0);
3315 opcode
|= (result
.number_part
& 0x1f) << 16;
3316 if (need_pa11_opcode (&the_insn
, &result
))
3318 opcode
|= (result
.l_r_select
& 1) << 1;
3330 /* Check if the args matched. */
3333 if (&insn
[1] - pa_opcodes
< (int) NUMOPCODES
3334 && !strcmp (insn
->name
, insn
[1].name
))
3342 as_bad (_("Invalid operands %s"), error_message
);
3349 the_insn
.opcode
= opcode
;
3352 /* Turn a string in input_line_pointer into a floating point constant of type
3353 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
3354 emitted is stored in *sizeP . An error message or NULL is returned. */
3356 #define MAX_LITTLENUMS 6
3359 md_atof (type
, litP
, sizeP
)
3365 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
3366 LITTLENUM_TYPE
*wordP
;
3398 return _("Bad call to MD_ATOF()");
3400 t
= atof_ieee (input_line_pointer
, type
, words
);
3402 input_line_pointer
= t
;
3403 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
3404 for (wordP
= words
; prec
--;)
3406 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
3407 litP
+= sizeof (LITTLENUM_TYPE
);
3412 /* Write out big-endian. */
3415 md_number_to_chars (buf
, val
, n
)
3420 number_to_chars_bigendian (buf
, val
, n
);
3423 /* Translate internal representation of relocation info to BFD target
3427 tc_gen_reloc (section
, fixp
)
3432 struct hppa_fix_struct
*hppa_fixp
;
3433 bfd_reloc_code_real_type code
;
3434 static arelent
*no_relocs
= NULL
;
3436 bfd_reloc_code_real_type
**codes
;
3440 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
3441 if (fixp
->fx_addsy
== 0)
3443 assert (hppa_fixp
!= 0);
3444 assert (section
!= 0);
3446 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3448 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3449 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3450 codes
= (bfd_reloc_code_real_type
**) hppa_gen_reloc_type (stdoutput
,
3452 hppa_fixp
->fx_r_format
,
3453 hppa_fixp
->fx_r_field
,
3454 fixp
->fx_subsy
!= NULL
,
3455 symbol_get_bfdsym (fixp
->fx_addsy
));
3460 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
3463 relocs
= (arelent
**) xmalloc (sizeof (arelent
*) * n_relocs
+ 1);
3464 reloc
= (arelent
*) xmalloc (sizeof (arelent
) * n_relocs
);
3465 for (i
= 0; i
< n_relocs
; i
++)
3466 relocs
[i
] = &reloc
[i
];
3468 relocs
[n_relocs
] = NULL
;
3471 switch (fixp
->fx_r_type
)
3474 assert (n_relocs
== 1);
3478 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3479 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3480 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3481 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3482 reloc
->addend
= 0; /* default */
3484 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
3486 /* Now, do any processing that is dependent on the relocation type. */
3489 case R_PARISC_DLTREL21L
:
3490 case R_PARISC_DLTREL14R
:
3491 case R_PARISC_DLTREL14F
:
3492 case R_PARISC_PLABEL32
:
3493 case R_PARISC_PLABEL21L
:
3494 case R_PARISC_PLABEL14R
:
3495 /* For plabel relocations, the addend of the
3496 relocation should be either 0 (no static link) or 2
3497 (static link required).
3499 FIXME: We always assume no static link!
3501 We also slam a zero addend into the DLT relative relocs;
3502 it doesn't make a lot of sense to use any addend since
3503 it gets you a different (eg unknown) DLT entry. */
3507 case R_PARISC_PCREL21L
:
3508 case R_PARISC_PCREL17R
:
3509 case R_PARISC_PCREL17F
:
3510 case R_PARISC_PCREL17C
:
3511 case R_PARISC_PCREL14R
:
3512 case R_PARISC_PCREL14F
:
3513 /* The constant is stored in the instruction. */
3514 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
3517 reloc
->addend
= fixp
->fx_offset
;
3524 /* Walk over reach relocation returned by the BFD backend. */
3525 for (i
= 0; i
< n_relocs
; i
++)
3529 relocs
[i
]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3530 *relocs
[i
]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3531 relocs
[i
]->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3532 relocs
[i
]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3537 /* The only time we ever use a R_COMP2 fixup is for the difference
3538 of two symbols. With that in mind we fill in all four
3539 relocs now and break out of the loop. */
3541 relocs
[0]->sym_ptr_ptr
= (asymbol
**) &(bfd_abs_symbol
);
3542 relocs
[0]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[0]);
3543 relocs
[0]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3544 relocs
[0]->addend
= 0;
3545 relocs
[1]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3546 *relocs
[1]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3547 relocs
[1]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[1]);
3548 relocs
[1]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3549 relocs
[1]->addend
= 0;
3550 relocs
[2]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3551 *relocs
[2]->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_subsy
);
3552 relocs
[2]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[2]);
3553 relocs
[2]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3554 relocs
[2]->addend
= 0;
3555 relocs
[3]->sym_ptr_ptr
= (asymbol
**) &(bfd_abs_symbol
);
3556 relocs
[3]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[3]);
3557 relocs
[3]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3558 relocs
[3]->addend
= 0;
3559 relocs
[4]->sym_ptr_ptr
= (asymbol
**) &(bfd_abs_symbol
);
3560 relocs
[4]->howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[4]);
3561 relocs
[4]->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3562 relocs
[4]->addend
= 0;
3566 relocs
[i
]->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
3572 /* For plabel relocations, the addend of the
3573 relocation should be either 0 (no static link) or 2
3574 (static link required).
3576 FIXME: We always assume no static link!
3578 We also slam a zero addend into the DLT relative relocs;
3579 it doesn't make a lot of sense to use any addend since
3580 it gets you a different (eg unknown) DLT entry. */
3581 relocs
[i
]->addend
= 0;
3596 /* There is no symbol or addend associated with these fixups. */
3597 relocs
[i
]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3598 *relocs
[i
]->sym_ptr_ptr
= symbol_get_bfdsym (dummy_symbol
);
3599 relocs
[i
]->addend
= 0;
3605 /* There is no symbol associated with these fixups. */
3606 relocs
[i
]->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3607 *relocs
[i
]->sym_ptr_ptr
= symbol_get_bfdsym (dummy_symbol
);
3608 relocs
[i
]->addend
= fixp
->fx_offset
;
3612 relocs
[i
]->addend
= fixp
->fx_offset
;
3622 /* Process any machine dependent frag types. */
3625 md_convert_frag (abfd
, sec
, fragP
)
3627 register asection
*sec
;
3628 register fragS
*fragP
;
3630 unsigned int address
;
3632 if (fragP
->fr_type
== rs_machine_dependent
)
3634 switch ((int) fragP
->fr_subtype
)
3637 fragP
->fr_type
= rs_fill
;
3638 know (fragP
->fr_var
== 1);
3639 know (fragP
->fr_next
);
3640 address
= fragP
->fr_address
+ fragP
->fr_fix
;
3641 if (address
% fragP
->fr_offset
)
3644 fragP
->fr_next
->fr_address
3649 fragP
->fr_offset
= 0;
3655 /* Round up a section size to the appropriate boundary. */
3658 md_section_align (segment
, size
)
3662 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3663 int align2
= (1 << align
) - 1;
3665 return (size
+ align2
) & ~align2
;
3668 /* Return the approximate size of a frag before relaxation has occurred. */
3670 md_estimate_size_before_relax (fragP
, segment
)
3671 register fragS
*fragP
;
3678 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3684 CONST
char *md_shortopts
= "";
3685 struct option md_longopts
[] = {
3686 {NULL
, no_argument
, NULL
, 0}
3688 size_t md_longopts_size
= sizeof(md_longopts
);
3691 md_parse_option (c
, arg
)
3699 md_show_usage (stream
)
3704 /* We have no need to default values of symbols. */
3707 md_undefined_symbol (name
)
3713 /* Apply a fixup to an instruction. */
3716 md_apply_fix (fixP
, valp
)
3720 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3721 struct hppa_fix_struct
*hppa_fixP
;
3722 long new_val
, result
= 0;
3723 unsigned int w1
, w2
, w
, resulti
;
3725 hppa_fixP
= (struct hppa_fix_struct
*) fixP
->tc_fix_data
;
3726 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3727 never be "applied" (they are just markers). Likewise for
3728 R_HPPA_BEGIN_BRTAB and R_HPPA_END_BRTAB. */
3730 if (fixP
->fx_r_type
== R_HPPA_ENTRY
3731 || fixP
->fx_r_type
== R_HPPA_EXIT
3732 || fixP
->fx_r_type
== R_HPPA_BEGIN_BRTAB
3733 || fixP
->fx_r_type
== R_HPPA_END_BRTAB
3734 || fixP
->fx_r_type
== R_HPPA_BEGIN_TRY
)
3737 /* Disgusting. We must set fx_offset ourselves -- R_HPPA_END_TRY
3738 fixups are considered not adjustable, which in turn causes
3739 adjust_reloc_syms to not set fx_offset. Ugh. */
3740 if (fixP
->fx_r_type
== R_HPPA_END_TRY
)
3742 fixP
->fx_offset
= *valp
;
3747 /* There should have been an HPPA specific fixup associated
3748 with the GAS fixup. */
3751 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3752 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3754 /* If there is a symbol associated with this fixup, then it's something
3755 which will need a SOM relocation (except for some PC-relative relocs).
3756 In such cases we should treat the "val" or "addend" as zero since it
3757 will be added in as needed from fx_offset in tc_gen_reloc. */
3758 if ((fixP
->fx_addsy
!= NULL
3759 || fixP
->fx_r_type
== R_HPPA_NONE
)
3764 new_val
= ((fmt
== 12 || fmt
== 17 || fmt
== 22) ? 8 : 0);
3766 /* These field selectors imply that we do not want an addend. */
3767 else if (hppa_fixP
->fx_r_field
== e_psel
3768 || hppa_fixP
->fx_r_field
== e_rpsel
3769 || hppa_fixP
->fx_r_field
== e_lpsel
3770 || hppa_fixP
->fx_r_field
== e_tsel
3771 || hppa_fixP
->fx_r_field
== e_rtsel
3772 || hppa_fixP
->fx_r_field
== e_ltsel
)
3773 new_val
= ((fmt
== 12 || fmt
== 17 || fmt
== 22) ? 8 : 0);
3774 /* This is truely disgusting. The machine independent code blindly
3775 adds in the value of the symbol being relocated against. Damn! */
3777 && fixP
->fx_addsy
!= NULL
3778 && S_GET_SEGMENT (fixP
->fx_addsy
) != bfd_com_section_ptr
)
3779 new_val
= hppa_field_adjust (*valp
- S_GET_VALUE (fixP
->fx_addsy
),
3780 0, hppa_fixP
->fx_r_field
);
3783 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
3785 /* Handle pc-relative exceptions from above. */
3786 #define arg_reloc_stub_needed(CALLER, CALLEE) \
3787 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3788 if ((fmt
== 12 || fmt
== 17 || fmt
== 22)
3792 && !arg_reloc_stub_needed ((long) ((obj_symbol_type
*)
3793 symbol_get_bfdsym (fixP
->fx_addsy
))->tc_data
.ap
.hppa_arg_reloc
,
3794 hppa_fixP
->fx_arg_reloc
)
3796 && (((int)(*valp
) > -262144 && (int)(*valp
) < 262143) && fmt
!= 22)
3797 && S_GET_SEGMENT (fixP
->fx_addsy
) == hppa_fixP
->segment
3799 && S_GET_SEGMENT (fixP
->fx_subsy
) != hppa_fixP
->segment
))
3801 new_val
= hppa_field_adjust (*valp
, 0, hppa_fixP
->fx_r_field
);
3802 #undef arg_reloc_stub_needed
3806 /* Handle all opcodes with the 'j' operand type. */
3808 CHECK_FIELD (new_val
, 8191, -8192, 0);
3810 /* Mask off 14 bits to be changed. */
3811 bfd_put_32 (stdoutput
,
3812 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3814 low_sign_unext (new_val
, 14, &resulti
);
3818 /* Handle all opcodes with the 'k' operand type. */
3820 CHECK_FIELD (new_val
, 2097152, 0, 0);
3822 /* Mask off 21 bits to be changed. */
3823 bfd_put_32 (stdoutput
,
3824 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3826 dis_assemble_21 (new_val
, &resulti
);
3830 /* Handle all the opcodes with the 'i' operand type. */
3832 CHECK_FIELD (new_val
, 1023, -1023, 0);
3834 /* Mask off 11 bits to be changed. */
3835 bfd_put_32 (stdoutput
,
3836 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3838 low_sign_unext (new_val
, 11, &resulti
);
3842 /* Handle all the opcodes with the 'w' operand type. */
3844 CHECK_FIELD (new_val
, 8199, -8184, 0);
3846 /* Mask off 11 bits to be changed. */
3847 sign_unext ((new_val
- 8) >> 2, 12, &resulti
);
3848 bfd_put_32 (stdoutput
,
3849 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3852 dis_assemble_12 (resulti
, &w1
, &w
);
3853 result
= ((w1
<< 2) | w
);
3856 /* Handle some of the opcodes with the 'W' operand type. */
3859 int distance
= *valp
;
3861 CHECK_FIELD (new_val
, 262143, -262144, 0);
3863 /* If this is an absolute branch (ie no link) with an out of
3864 range target, then we want to complain. */
3865 if (fixP
->fx_r_type
== R_HPPA_PCREL_CALL
3866 && (distance
> 262143 || distance
< -262144)
3867 && (bfd_get_32 (stdoutput
, buf
) & 0xffe00000) == 0xe8000000)
3868 CHECK_FIELD (distance
, 262143, -262144, 0);
3870 /* Mask off 17 bits to be changed. */
3871 bfd_put_32 (stdoutput
,
3872 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3874 sign_unext ((new_val
- 8) >> 2, 17, &resulti
);
3875 dis_assemble_17 (resulti
, &w1
, &w2
, &w
);
3876 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3882 bfd_put_32 (stdoutput
, new_val
, buf
);
3886 as_bad (_("Unknown relocation encountered in md_apply_fix."));
3890 /* Insert the relocation. */
3891 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3896 printf (_("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n"),
3897 (unsigned int) fixP
, fixP
->fx_r_type
);
3902 /* Exactly what point is a PC-relative offset relative TO?
3903 On the PA, they're relative to the address of the offset. */
3906 md_pcrel_from (fixP
)
3909 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3912 /* Return nonzero if the input line pointer is at the end of
3916 is_end_of_statement ()
3918 return ((*input_line_pointer
== '\n')
3919 || (*input_line_pointer
== ';')
3920 || (*input_line_pointer
== '!'));
3923 /* Read a number from S. The number might come in one of many forms,
3924 the most common will be a hex or decimal constant, but it could be
3925 a pre-defined register (Yuk!), or an absolute symbol.
3927 Return a number or -1 for failure.
3929 When parsing PA-89 FP register numbers RESULT will be
3930 the address of a structure to return information about
3931 L/R half of FP registers, store results there as appropriate.
3933 pa_parse_number can not handle negative constants and will fail
3934 horribly if it is passed such a constant. */
3937 pa_parse_number (s
, result
)
3939 struct pa_11_fp_reg_struct
*result
;
3948 /* Skip whitespace before the number. */
3949 while (*p
== ' ' || *p
== '\t')
3952 /* Store info in RESULT if requested by caller. */
3955 result
->number_part
= -1;
3956 result
->l_r_select
= -1;
3962 /* Looks like a number. */
3965 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3967 /* The number is specified in hex. */
3969 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3970 || ((*p
>= 'A') && (*p
<= 'F')))
3973 num
= num
* 16 + *p
- '0';
3974 else if (*p
>= 'a' && *p
<= 'f')
3975 num
= num
* 16 + *p
- 'a' + 10;
3977 num
= num
* 16 + *p
- 'A' + 10;
3983 /* The number is specified in decimal. */
3984 while (isdigit (*p
))
3986 num
= num
* 10 + *p
- '0';
3991 /* Store info in RESULT if requested by the caller. */
3994 result
->number_part
= num
;
3996 if (IS_R_SELECT (p
))
3998 result
->l_r_select
= 1;
4001 else if (IS_L_SELECT (p
))
4003 result
->l_r_select
= 0;
4007 result
->l_r_select
= 0;
4012 /* The number might be a predefined register. */
4017 /* Tege hack: Special case for general registers as the general
4018 code makes a binary search with case translation, and is VERY
4023 if (*p
== 'e' && *(p
+ 1) == 't'
4024 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
4027 num
= *p
- '0' + 28;
4035 else if (!isdigit (*p
))
4038 as_bad (_("Undefined register: '%s'."), name
);
4044 num
= num
* 10 + *p
++ - '0';
4045 while (isdigit (*p
));
4050 /* Do a normal register search. */
4051 while (is_part_of_name (c
))
4057 status
= reg_name_search (name
);
4063 as_bad (_("Undefined register: '%s'."), name
);
4069 /* Store info in RESULT if requested by caller. */
4072 result
->number_part
= num
;
4073 if (IS_R_SELECT (p
- 1))
4074 result
->l_r_select
= 1;
4075 else if (IS_L_SELECT (p
- 1))
4076 result
->l_r_select
= 0;
4078 result
->l_r_select
= 0;
4083 /* And finally, it could be a symbol in the absolute section which
4084 is effectively a constant. */
4088 while (is_part_of_name (c
))
4094 if ((sym
= symbol_find (name
)) != NULL
)
4096 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
4097 num
= S_GET_VALUE (sym
);
4101 as_bad (_("Non-absolute symbol: '%s'."), name
);
4107 /* There is where we'd come for an undefined symbol
4108 or for an empty string. For an empty string we
4109 will return zero. That's a concession made for
4110 compatability with the braindamaged HP assemblers. */
4116 as_bad (_("Undefined absolute constant: '%s'."), name
);
4122 /* Store info in RESULT if requested by caller. */
4125 result
->number_part
= num
;
4126 if (IS_R_SELECT (p
- 1))
4127 result
->l_r_select
= 1;
4128 else if (IS_L_SELECT (p
- 1))
4129 result
->l_r_select
= 0;
4131 result
->l_r_select
= 0;
4139 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
4141 /* Given NAME, find the register number associated with that name, return
4142 the integer value associated with the given name or -1 on failure. */
4145 reg_name_search (name
)
4148 int middle
, low
, high
;
4152 high
= REG_NAME_CNT
- 1;
4156 middle
= (low
+ high
) / 2;
4157 cmp
= strcasecmp (name
, pre_defined_registers
[middle
].name
);
4163 return pre_defined_registers
[middle
].value
;
4165 while (low
<= high
);
4171 /* Return nonzero if the given INSN and L/R information will require
4172 a new PA-1.1 opcode. */
4175 need_pa11_opcode (insn
, result
)
4177 struct pa_11_fp_reg_struct
*result
;
4179 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
4181 /* If this instruction is specific to a particular architecture,
4182 then set a new architecture. */
4183 if (bfd_get_mach (stdoutput
) < pa11
)
4185 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, pa11
))
4186 as_warn (_("could not update architecture and machine"));
4194 /* Parse a condition for a fcmp instruction. Return the numerical
4195 code associated with the condition. */
4198 pa_parse_fp_cmp_cond (s
)
4205 for (i
= 0; i
< 32; i
++)
4207 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
4208 strlen (fp_cond_map
[i
].string
)) == 0)
4210 cond
= fp_cond_map
[i
].cond
;
4211 *s
+= strlen (fp_cond_map
[i
].string
);
4212 /* If not a complete match, back up the input string and
4214 if (**s
!= ' ' && **s
!= '\t')
4216 *s
-= strlen (fp_cond_map
[i
].string
);
4219 while (**s
== ' ' || **s
== '\t')
4225 as_bad (_("Invalid FP Compare Condition: %s"), *s
);
4227 /* Advance over the bogus completer. */
4228 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4235 /* Parse an FP operand format completer returning the completer
4238 static fp_operand_format
4239 pa_parse_fp_format (s
)
4248 if (strncasecmp (*s
, "sgl", 3) == 0)
4253 else if (strncasecmp (*s
, "dbl", 3) == 0)
4258 else if (strncasecmp (*s
, "quad", 4) == 0)
4265 format
= ILLEGAL_FMT
;
4266 as_bad (_("Invalid FP Operand Format: %3s"), *s
);
4273 /* Convert from a selector string into a selector type. */
4276 pa_chk_field_selector (str
)
4279 int middle
, low
, high
;
4283 /* Read past any whitespace. */
4284 /* FIXME: should we read past newlines and formfeeds??? */
4285 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
4288 if ((*str
)[1] == '\'' || (*str
)[1] == '%')
4289 name
[0] = tolower ((*str
)[0]),
4291 else if ((*str
)[2] == '\'' || (*str
)[2] == '%')
4292 name
[0] = tolower ((*str
)[0]),
4293 name
[1] = tolower ((*str
)[1]),
4295 else if ((*str
)[3] == '\'' || (*str
)[3] == '%')
4296 name
[0] = tolower ((*str
)[0]),
4297 name
[1] = tolower ((*str
)[1]),
4298 name
[2] = tolower ((*str
)[2]),
4304 high
= sizeof (selector_table
) / sizeof (struct selector_entry
) - 1;
4308 middle
= (low
+ high
) / 2;
4309 cmp
= strcmp (name
, selector_table
[middle
].prefix
);
4316 *str
+= strlen (name
) + 1;
4318 if (selector_table
[middle
].field_selector
== e_nsel
)
4321 return selector_table
[middle
].field_selector
;
4324 while (low
<= high
);
4329 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
4332 get_expression (str
)
4338 save_in
= input_line_pointer
;
4339 input_line_pointer
= str
;
4340 seg
= expression (&the_insn
.exp
);
4341 if (!(seg
== absolute_section
4342 || seg
== undefined_section
4343 || SEG_NORMAL (seg
)))
4345 as_warn (_("Bad segment in expression."));
4346 expr_end
= input_line_pointer
;
4347 input_line_pointer
= save_in
;
4350 expr_end
= input_line_pointer
;
4351 input_line_pointer
= save_in
;
4355 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
4357 pa_get_absolute_expression (insn
, strp
)
4363 insn
->field_selector
= pa_chk_field_selector (strp
);
4364 save_in
= input_line_pointer
;
4365 input_line_pointer
= *strp
;
4366 expression (&insn
->exp
);
4367 /* This is not perfect, but is a huge improvement over doing nothing.
4369 The PA assembly syntax is ambigious in a variety of ways. Consider
4370 this string "4 %r5" Is that the number 4 followed by the register
4371 r5, or is that 4 MOD 5?
4373 If we get a modulo expresion When looking for an absolute, we try
4374 again cutting off the input string at the first whitespace character. */
4375 if (insn
->exp
.X_op
== O_modulus
)
4380 input_line_pointer
= *strp
;
4382 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
4388 retval
= pa_get_absolute_expression (insn
, strp
);
4390 input_line_pointer
= save_in
;
4392 return evaluate_absolute (insn
);
4394 /* When in strict mode we have a non-match, fix up the pointers
4395 and return to our caller. */
4396 if (insn
->exp
.X_op
!= O_constant
&& strict
)
4398 expr_end
= input_line_pointer
;
4399 input_line_pointer
= save_in
;
4402 if (insn
->exp
.X_op
!= O_constant
)
4404 as_bad (_("Bad segment (should be absolute)."));
4405 expr_end
= input_line_pointer
;
4406 input_line_pointer
= save_in
;
4409 expr_end
= input_line_pointer
;
4410 input_line_pointer
= save_in
;
4411 return evaluate_absolute (insn
);
4414 /* Evaluate an absolute expression EXP which may be modified by
4415 the selector FIELD_SELECTOR. Return the value of the expression. */
4417 evaluate_absolute (insn
)
4422 int field_selector
= insn
->field_selector
;
4425 value
= exp
.X_add_number
;
4427 switch (field_selector
)
4433 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
4435 if (value
& 0x00000400)
4437 value
= (value
& 0xfffff800) >> 11;
4440 /* Sign extend from bit 21. */
4442 if (value
& 0x00000400)
4443 value
|= 0xfffff800;
4448 /* Arithmetic shift right 11 bits. */
4450 value
= (value
& 0xfffff800) >> 11;
4453 /* Set bits 0-20 to zero. */
4455 value
= value
& 0x7ff;
4458 /* Add 0x800 and arithmetic shift right 11 bits. */
4461 value
= (value
& 0xfffff800) >> 11;
4464 /* Set bitgs 0-21 to one. */
4466 value
|= 0xfffff800;
4469 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
4471 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
4475 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
4480 BAD_CASE (field_selector
);
4486 /* Given an argument location specification return the associated
4487 argument location number. */
4490 pa_build_arg_reloc (type_name
)
4494 if (strncasecmp (type_name
, "no", 2) == 0)
4496 if (strncasecmp (type_name
, "gr", 2) == 0)
4498 else if (strncasecmp (type_name
, "fr", 2) == 0)
4500 else if (strncasecmp (type_name
, "fu", 2) == 0)
4503 as_bad (_("Invalid argument location: %s\n"), type_name
);
4508 /* Encode and return an argument relocation specification for
4509 the given register in the location specified by arg_reloc. */
4512 pa_align_arg_reloc (reg
, arg_reloc
)
4514 unsigned int arg_reloc
;
4516 unsigned int new_reloc
;
4518 new_reloc
= arg_reloc
;
4534 as_bad (_("Invalid argument description: %d"), reg
);
4540 /* Parse a PA nullification completer (,n). Return nonzero if the
4541 completer was found; return zero if no completer was found. */
4553 if (strncasecmp (*s
, "n", 1) == 0)
4557 as_bad (_("Invalid Nullification: (%c)"), **s
);
4566 /* Parse a non-negated compare/subtract completer returning the
4567 number (for encoding in instrutions) of the given completer.
4569 ISBRANCH specifies whether or not this is parsing a condition
4570 completer for a branch (vs a nullification completer for a
4571 computational instruction. */
4574 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
4579 char *name
= *s
+ 1;
4588 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4594 if (strcmp (name
, "=") == 0)
4598 else if (strcmp (name
, "<") == 0)
4602 else if (strcmp (name
, "<=") == 0)
4606 else if (strcmp (name
, "<<") == 0)
4610 else if (strcmp (name
, "<<=") == 0)
4614 else if (strcasecmp (name
, "sv") == 0)
4618 else if (strcasecmp (name
, "od") == 0)
4622 /* If we have something like addb,n then there is no condition
4624 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4636 /* Reset pointers if this was really a ,n for a branch instruction. */
4644 /* Parse a negated compare/subtract completer returning the
4645 number (for encoding in instrutions) of the given completer.
4647 ISBRANCH specifies whether or not this is parsing a condition
4648 completer for a branch (vs a nullification completer for a
4649 computational instruction. */
4652 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
4657 char *name
= *s
+ 1;
4666 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4672 if (strcasecmp (name
, "tr") == 0)
4676 else if (strcmp (name
, "<>") == 0)
4680 else if (strcmp (name
, ">=") == 0)
4684 else if (strcmp (name
, ">") == 0)
4688 else if (strcmp (name
, ">>=") == 0)
4692 else if (strcmp (name
, ">>") == 0)
4696 else if (strcasecmp (name
, "nsv") == 0)
4700 else if (strcasecmp (name
, "ev") == 0)
4704 /* If we have something like addb,n then there is no condition
4706 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4718 /* Reset pointers if this was really a ,n for a branch instruction. */
4727 /* Parse a non-negated addition completer returning the number
4728 (for encoding in instrutions) of the given completer.
4730 ISBRANCH specifies whether or not this is parsing a condition
4731 completer for a branch (vs a nullification completer for a
4732 computational instruction. */
4735 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
4740 char *name
= *s
+ 1;
4748 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4752 if (strcmp (name
, "=") == 0)
4756 else if (strcmp (name
, "<") == 0)
4760 else if (strcmp (name
, "<=") == 0)
4764 else if (strcasecmp (name
, "nuv") == 0)
4768 else if (strcasecmp (name
, "znv") == 0)
4772 else if (strcasecmp (name
, "sv") == 0)
4776 else if (strcasecmp (name
, "od") == 0)
4780 /* If we have something like addb,n then there is no condition
4782 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4793 /* Reset pointers if this was really a ,n for a branch instruction. */
4794 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4800 /* Parse a negated addition completer returning the number
4801 (for encoding in instrutions) of the given completer.
4803 ISBRANCH specifies whether or not this is parsing a condition
4804 completer for a branch (vs a nullification completer for a
4805 computational instruction). */
4808 pa_parse_neg_add_cmpltr (s
, isbranch
)
4813 char *name
= *s
+ 1;
4821 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4825 if (strcasecmp (name
, "tr") == 0)
4829 else if (strcmp (name
, "<>") == 0)
4833 else if (strcmp (name
, ">=") == 0)
4837 else if (strcmp (name
, ">") == 0)
4841 else if (strcasecmp (name
, "uv") == 0)
4845 else if (strcasecmp (name
, "vnz") == 0)
4849 else if (strcasecmp (name
, "nsv") == 0)
4853 else if (strcasecmp (name
, "ev") == 0)
4857 /* If we have something like addb,n then there is no condition
4859 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4870 /* Reset pointers if this was really a ,n for a branch instruction. */
4871 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4878 /* Handle an alignment directive. Special so that we can update the
4879 alignment of the subspace if necessary. */
4883 /* We must have a valid space and subspace. */
4884 pa_check_current_space_and_subspace ();
4886 /* Let the generic gas code do most of the work. */
4887 s_align_bytes (bytes
);
4889 /* If bytes is a power of 2, then update the current subspace's
4890 alignment if necessary. */
4891 if (log2 (bytes
) != -1)
4892 record_alignment (current_subspace
->ssd_seg
, log2 (bytes
));
4896 /* Handle a .BLOCK type pseudo-op. */
4904 unsigned int temp_size
;
4908 /* We must have a valid space and subspace. */
4909 pa_check_current_space_and_subspace ();
4912 temp_size
= get_absolute_expression ();
4914 /* Always fill with zeros, that's what the HP assembler does. */
4917 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4918 (relax_substateT
) 0, (symbolS
*) 0, (offsetT
) 1, NULL
);
4919 memset (p
, 0, temp_size
);
4921 /* Convert 2 bytes at a time. */
4923 for (i
= 0; i
< temp_size
; i
+= 2)
4925 md_number_to_chars (p
+ i
,
4927 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4930 pa_undefine_label ();
4931 demand_empty_rest_of_line ();
4934 /* Handle a .begin_brtab and .end_brtab pseudo-op. */
4942 /* The BRTAB relocations are only availble in SOM (to denote
4943 the beginning and end of branch tables). */
4944 char *where
= frag_more (0);
4946 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4947 NULL
, (offsetT
) 0, NULL
,
4948 0, begin
? R_HPPA_BEGIN_BRTAB
: R_HPPA_END_BRTAB
,
4949 e_fsel
, 0, 0, NULL
);
4952 demand_empty_rest_of_line ();
4955 /* Handle a .begin_try and .end_try pseudo-op. */
4963 char *where
= frag_more (0);
4968 /* The TRY relocations are only availble in SOM (to denote
4969 the beginning and end of exception handling regions). */
4971 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4972 NULL
, (offsetT
) 0, begin
? NULL
: &exp
,
4973 0, begin
? R_HPPA_BEGIN_TRY
: R_HPPA_END_TRY
,
4974 e_fsel
, 0, 0, NULL
);
4977 demand_empty_rest_of_line ();
4980 /* Handle a .CALL pseudo-op. This involves storing away information
4981 about where arguments are to be found so the linker can detect
4982 (and correct) argument location mismatches between caller and callee. */
4989 /* We must have a valid space and subspace. */
4990 pa_check_current_space_and_subspace ();
4993 pa_call_args (&last_call_desc
);
4994 demand_empty_rest_of_line ();
4997 /* Do the dirty work of building a call descriptor which describes
4998 where the caller placed arguments to a function call. */
5001 pa_call_args (call_desc
)
5002 struct call_desc
*call_desc
;
5005 unsigned int temp
, arg_reloc
;
5007 while (!is_end_of_statement ())
5009 name
= input_line_pointer
;
5010 c
= get_symbol_end ();
5011 /* Process a source argument. */
5012 if ((strncasecmp (name
, "argw", 4) == 0))
5014 temp
= atoi (name
+ 4);
5015 p
= input_line_pointer
;
5017 input_line_pointer
++;
5018 name
= input_line_pointer
;
5019 c
= get_symbol_end ();
5020 arg_reloc
= pa_build_arg_reloc (name
);
5021 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
5023 /* Process a return value. */
5024 else if ((strncasecmp (name
, "rtnval", 6) == 0))
5026 p
= input_line_pointer
;
5028 input_line_pointer
++;
5029 name
= input_line_pointer
;
5030 c
= get_symbol_end ();
5031 arg_reloc
= pa_build_arg_reloc (name
);
5032 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
5036 as_bad (_("Invalid .CALL argument: %s"), name
);
5038 p
= input_line_pointer
;
5040 if (!is_end_of_statement ())
5041 input_line_pointer
++;
5045 /* Return TRUE if FRAG1 and FRAG2 are the same. */
5048 is_same_frag (frag1
, frag2
)
5055 else if (frag2
== NULL
)
5057 else if (frag1
== frag2
)
5059 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
5060 return (is_same_frag (frag1
, frag2
->fr_next
));
5066 /* Build an entry in the UNWIND subspace from the given function
5067 attributes in CALL_INFO. This is not needed for SOM as using
5068 R_ENTRY and R_EXIT relocations allow the linker to handle building
5069 of the unwind spaces. */
5072 pa_build_unwind_subspace (call_info
)
5073 struct call_info
*call_info
;
5076 asection
*seg
, *save_seg
;
5078 subsegT subseg
, save_subseg
;
5082 if (bfd_get_arch_info (stdoutput
)->bits_per_address
== 32)
5083 reloc
= R_PARISC_DIR32
;
5085 reloc
= R_PARISC_SEGREL32
;
5087 /* Get into the right seg/subseg. This may involve creating
5088 the seg the first time through. Make sure to have the
5089 old seg/subseg so that we can reset things when we are done. */
5090 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
5091 if (seg
== ASEC_NULL
)
5093 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
5094 bfd_set_section_flags (stdoutput
, seg
,
5095 SEC_READONLY
| SEC_HAS_CONTENTS
5096 | SEC_LOAD
| SEC_RELOC
| SEC_ALLOC
| SEC_DATA
);
5097 bfd_set_section_alignment (stdoutput
, seg
, 2);
5101 save_subseg
= now_subseg
;
5102 subseg_set (seg
, 0);
5105 /* Get some space to hold relocation information for the unwind
5108 md_number_to_chars (p
, 0, 4);
5110 /* Relocation info. for start offset of the function. */
5111 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
5112 call_info
->start_symbol
, (offsetT
) 0,
5113 (expressionS
*) NULL
, 0, reloc
,
5114 e_fsel
, 32, 0, NULL
);
5117 md_number_to_chars (p
, 0, 4);
5119 /* Relocation info. for end offset of the function.
5121 Because we allow reductions of 32bit relocations for ELF, this will be
5122 reduced to section_sym + offset which avoids putting the temporary
5123 symbol into the symbol table. It (should) end up giving the same
5124 value as call_info->start_symbol + function size once the linker is
5125 finished with its work. */
5127 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
5128 call_info
->end_symbol
, (offsetT
) 0,
5129 (expressionS
*) NULL
, 0, reloc
,
5130 e_fsel
, 32, 0, NULL
);
5133 unwind
= (char *) &call_info
->ci_unwind
;
5134 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
5138 FRAG_APPEND_1_CHAR (c
);
5142 /* Return back to the original segment/subsegment. */
5143 subseg_set (save_seg
, save_subseg
);
5147 /* Process a .CALLINFO pseudo-op. This information is used later
5148 to build unwind descriptors and maybe one day to support
5149 .ENTER and .LEAVE. */
5152 pa_callinfo (unused
)
5159 /* We must have a valid space and subspace. */
5160 pa_check_current_space_and_subspace ();
5163 /* .CALLINFO must appear within a procedure definition. */
5164 if (!within_procedure
)
5165 as_bad (_(".callinfo is not within a procedure definition"));
5167 /* Mark the fact that we found the .CALLINFO for the
5168 current procedure. */
5169 callinfo_found
= TRUE
;
5171 /* Iterate over the .CALLINFO arguments. */
5172 while (!is_end_of_statement ())
5174 name
= input_line_pointer
;
5175 c
= get_symbol_end ();
5176 /* Frame size specification. */
5177 if ((strncasecmp (name
, "frame", 5) == 0))
5179 p
= input_line_pointer
;
5181 input_line_pointer
++;
5182 temp
= get_absolute_expression ();
5183 if ((temp
& 0x3) != 0)
5185 as_bad (_("FRAME parameter must be a multiple of 8: %d\n"), temp
);
5189 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
5190 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
5193 /* Entry register (GR, GR and SR) specifications. */
5194 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
5196 p
= input_line_pointer
;
5198 input_line_pointer
++;
5199 temp
= get_absolute_expression ();
5200 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
5201 even though %r19 is caller saved. I think this is a bug in
5202 the HP assembler, and we are not going to emulate it. */
5203 if (temp
< 3 || temp
> 18)
5204 as_bad (_("Value for ENTRY_GR must be in the range 3..18\n"));
5205 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
5207 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
5209 p
= input_line_pointer
;
5211 input_line_pointer
++;
5212 temp
= get_absolute_expression ();
5213 /* Similarly the HP assembler takes 31 as the high bound even
5214 though %fr21 is the last callee saved floating point register. */
5215 if (temp
< 12 || temp
> 21)
5216 as_bad (_("Value for ENTRY_FR must be in the range 12..21\n"));
5217 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
5219 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
5221 p
= input_line_pointer
;
5223 input_line_pointer
++;
5224 temp
= get_absolute_expression ();
5226 as_bad (_("Value for ENTRY_SR must be 3\n"));
5228 /* Note whether or not this function performs any calls. */
5229 else if ((strncasecmp (name
, "calls", 5) == 0) ||
5230 (strncasecmp (name
, "caller", 6) == 0))
5232 p
= input_line_pointer
;
5235 else if ((strncasecmp (name
, "no_calls", 8) == 0))
5237 p
= input_line_pointer
;
5240 /* Should RP be saved into the stack. */
5241 else if ((strncasecmp (name
, "save_rp", 7) == 0))
5243 p
= input_line_pointer
;
5245 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
5247 /* Likewise for SP. */
5248 else if ((strncasecmp (name
, "save_sp", 7) == 0))
5250 p
= input_line_pointer
;
5252 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
5254 /* Is this an unwindable procedure. If so mark it so
5255 in the unwind descriptor. */
5256 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
5258 p
= input_line_pointer
;
5260 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
5262 /* Is this an interrupt routine. If so mark it in the
5263 unwind descriptor. */
5264 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
5266 p
= input_line_pointer
;
5268 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
5270 /* Is this a millicode routine. "millicode" isn't in my
5271 assembler manual, but my copy is old. The HP assembler
5272 accepts it, and there's a place in the unwind descriptor
5273 to drop the information, so we'll accept it too. */
5274 else if ((strncasecmp (name
, "millicode", 9) == 0))
5276 p
= input_line_pointer
;
5278 last_call_info
->ci_unwind
.descriptor
.millicode
= 1;
5282 as_bad (_("Invalid .CALLINFO argument: %s"), name
);
5283 *input_line_pointer
= c
;
5285 if (!is_end_of_statement ())
5286 input_line_pointer
++;
5289 demand_empty_rest_of_line ();
5292 /* Switch into the code subspace. */
5299 current_space
= is_defined_space ("$TEXT$");
5301 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
5304 pa_undefine_label ();
5307 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
5308 the .comm pseudo-op has the following symtax:
5310 <label> .comm <length>
5312 where <label> is optional and is a symbol whose address will be the start of
5313 a block of memory <length> bytes long. <length> must be an absolute
5314 expression. <length> bytes will be allocated in the current space
5317 Also note the label may not even be on the same line as the .comm.
5319 This difference in syntax means the colon function will be called
5320 on the symbol before we arrive in pa_comm. colon will set a number
5321 of attributes of the symbol that need to be fixed here. In particular
5322 the value, section pointer, fragment pointer, flags, etc. What
5325 This also makes error detection all but impossible. */
5333 label_symbol_struct
*label_symbol
= pa_get_label ();
5336 symbol
= label_symbol
->lss_label
;
5341 size
= get_absolute_expression ();
5345 S_SET_VALUE (symbol
, size
);
5346 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
5347 S_SET_EXTERNAL (symbol
);
5349 /* colon() has already set the frag to the current location in the
5350 current subspace; we need to reset the fragment to the zero address
5351 fragment. We also need to reset the segment pointer. */
5352 symbol_set_frag (symbol
, &zero_address_frag
);
5354 demand_empty_rest_of_line ();
5357 /* Process a .END pseudo-op. */
5363 demand_empty_rest_of_line ();
5366 /* Process a .ENTER pseudo-op. This is not supported. */
5372 /* We must have a valid space and subspace. */
5373 pa_check_current_space_and_subspace ();
5376 as_bad (_("The .ENTER pseudo-op is not supported"));
5377 demand_empty_rest_of_line ();
5380 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
5387 /* We must have a valid space and subspace. */
5388 pa_check_current_space_and_subspace ();
5391 if (!within_procedure
)
5392 as_bad (_("Misplaced .entry. Ignored."));
5395 if (!callinfo_found
)
5396 as_bad (_("Missing .callinfo."));
5398 demand_empty_rest_of_line ();
5399 within_entry_exit
= TRUE
;
5402 /* SOM defers building of unwind descriptors until the link phase.
5403 The assembler is responsible for creating an R_ENTRY relocation
5404 to mark the beginning of a region and hold the unwind bits, and
5405 for creating an R_EXIT relocation to mark the end of the region.
5407 FIXME. ELF should be using the same conventions! The problem
5408 is an unwind requires too much relocation space. Hmmm. Maybe
5409 if we split the unwind bits up between the relocations which
5410 denote the entry and exit points. */
5411 if (last_call_info
->start_symbol
!= NULL
)
5413 char *where
= frag_more (0);
5415 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5416 NULL
, (offsetT
) 0, NULL
,
5417 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
5418 (int *) &last_call_info
->ci_unwind
.descriptor
);
5423 /* Handle a .EQU pseudo-op. */
5429 label_symbol_struct
*label_symbol
= pa_get_label ();
5434 symbol
= label_symbol
->lss_label
;
5436 S_SET_VALUE (symbol
, pa_parse_number (&input_line_pointer
, 0));
5438 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
5439 S_SET_SEGMENT (symbol
, bfd_abs_section_ptr
);
5444 as_bad (_(".REG must use a label"));
5446 as_bad (_(".EQU must use a label"));
5449 pa_undefine_label ();
5450 demand_empty_rest_of_line ();
5453 /* Helper function. Does processing for the end of a function. This
5454 usually involves creating some relocations or building special
5455 symbols to mark the end of the function. */
5462 where
= frag_more (0);
5465 /* Mark the end of the function, stuff away the location of the frag
5466 for the end of the function, and finally call pa_build_unwind_subspace
5467 to add an entry in the unwind table. */
5468 hppa_elf_mark_end_of_function ();
5469 pa_build_unwind_subspace (last_call_info
);
5471 /* SOM defers building of unwind descriptors until the link phase.
5472 The assembler is responsible for creating an R_ENTRY relocation
5473 to mark the beginning of a region and hold the unwind bits, and
5474 for creating an R_EXIT relocation to mark the end of the region.
5476 FIXME. ELF should be using the same conventions! The problem
5477 is an unwind requires too much relocation space. Hmmm. Maybe
5478 if we split the unwind bits up between the relocations which
5479 denote the entry and exit points. */
5480 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
5482 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0,
5483 (int *) &last_call_info
->ci_unwind
.descriptor
+ 1);
5487 /* Process a .EXIT pseudo-op. */
5494 /* We must have a valid space and subspace. */
5495 pa_check_current_space_and_subspace ();
5498 if (!within_procedure
)
5499 as_bad (_(".EXIT must appear within a procedure"));
5502 if (!callinfo_found
)
5503 as_bad (_("Missing .callinfo"));
5506 if (!within_entry_exit
)
5507 as_bad (_("No .ENTRY for this .EXIT"));
5510 within_entry_exit
= FALSE
;
5515 demand_empty_rest_of_line ();
5518 /* Process a .EXPORT directive. This makes functions external
5519 and provides information such as argument relocation entries
5529 name
= input_line_pointer
;
5530 c
= get_symbol_end ();
5531 /* Make sure the given symbol exists. */
5532 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5534 as_bad (_("Cannot define export symbol: %s\n"), name
);
5535 p
= input_line_pointer
;
5537 input_line_pointer
++;
5541 /* OK. Set the external bits and process argument relocations. */
5542 S_SET_EXTERNAL (symbol
);
5543 p
= input_line_pointer
;
5545 if (!is_end_of_statement ())
5547 input_line_pointer
++;
5548 pa_type_args (symbol
, 1);
5552 demand_empty_rest_of_line ();
5555 /* Helper function to process arguments to a .EXPORT pseudo-op. */
5558 pa_type_args (symbolP
, is_export
)
5563 unsigned int temp
, arg_reloc
;
5564 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
5565 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbol_get_bfdsym (symbolP
);
5567 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
5570 input_line_pointer
+= 8;
5571 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5572 S_SET_SEGMENT (symbolP
, bfd_abs_section_ptr
);
5573 type
= SYMBOL_TYPE_ABSOLUTE
;
5575 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
5577 input_line_pointer
+= 4;
5578 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
5579 instead one should be IMPORTing/EXPORTing ENTRY types.
5581 Complain if one tries to EXPORT a CODE type since that's never
5582 done. Both GCC and HP C still try to IMPORT CODE types, so
5583 silently fix them to be ENTRY types. */
5584 if (S_IS_FUNCTION (symbolP
))
5587 as_tsktsk (_("Using ENTRY rather than CODE in export directive for %s"),
5588 S_GET_NAME (symbolP
));
5590 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5591 type
= SYMBOL_TYPE_ENTRY
;
5595 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5596 type
= SYMBOL_TYPE_CODE
;
5599 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
5601 input_line_pointer
+= 4;
5602 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5603 type
= SYMBOL_TYPE_DATA
;
5605 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
5607 input_line_pointer
+= 5;
5608 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5609 type
= SYMBOL_TYPE_ENTRY
;
5611 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
5613 input_line_pointer
+= 9;
5614 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5615 type
= SYMBOL_TYPE_MILLICODE
;
5617 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
5619 input_line_pointer
+= 6;
5620 symbol_get_bfdsym (symbolP
)->flags
&= ~BSF_FUNCTION
;
5621 type
= SYMBOL_TYPE_PLABEL
;
5623 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
5625 input_line_pointer
+= 8;
5626 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5627 type
= SYMBOL_TYPE_PRI_PROG
;
5629 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
5631 input_line_pointer
+= 8;
5632 symbol_get_bfdsym (symbolP
)->flags
|= BSF_FUNCTION
;
5633 type
= SYMBOL_TYPE_SEC_PROG
;
5636 /* SOM requires much more information about symbol types
5637 than BFD understands. This is how we get this information
5638 to the SOM BFD backend. */
5639 #ifdef obj_set_symbol_type
5640 obj_set_symbol_type (symbol_get_bfdsym (symbolP
), (int) type
);
5643 /* Now that the type of the exported symbol has been handled,
5644 handle any argument relocation information. */
5645 while (!is_end_of_statement ())
5647 if (*input_line_pointer
== ',')
5648 input_line_pointer
++;
5649 name
= input_line_pointer
;
5650 c
= get_symbol_end ();
5651 /* Argument sources. */
5652 if ((strncasecmp (name
, "argw", 4) == 0))
5654 p
= input_line_pointer
;
5656 input_line_pointer
++;
5657 temp
= atoi (name
+ 4);
5658 name
= input_line_pointer
;
5659 c
= get_symbol_end ();
5660 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
5662 symbol
->tc_data
.ap
.hppa_arg_reloc
|= arg_reloc
;
5664 *input_line_pointer
= c
;
5666 /* The return value. */
5667 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
5669 p
= input_line_pointer
;
5671 input_line_pointer
++;
5672 name
= input_line_pointer
;
5673 c
= get_symbol_end ();
5674 arg_reloc
= pa_build_arg_reloc (name
);
5676 symbol
->tc_data
.ap
.hppa_arg_reloc
|= arg_reloc
;
5678 *input_line_pointer
= c
;
5680 /* Privelege level. */
5681 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
5683 p
= input_line_pointer
;
5685 input_line_pointer
++;
5686 temp
= atoi (input_line_pointer
);
5688 symbol
->tc_data
.ap
.hppa_priv_level
= temp
;
5690 c
= get_symbol_end ();
5691 *input_line_pointer
= c
;
5695 as_bad (_("Undefined .EXPORT/.IMPORT argument (ignored): %s"), name
);
5696 p
= input_line_pointer
;
5699 if (!is_end_of_statement ())
5700 input_line_pointer
++;
5704 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
5705 assembly file must either be defined in the assembly file, or
5706 explicitly IMPORTED from another. */
5715 name
= input_line_pointer
;
5716 c
= get_symbol_end ();
5718 symbol
= symbol_find (name
);
5719 /* Ugh. We might be importing a symbol defined earlier in the file,
5720 in which case all the code below will really screw things up
5721 (set the wrong segment, symbol flags & type, etc). */
5722 if (symbol
== NULL
|| !S_IS_DEFINED (symbol
))
5724 symbol
= symbol_find_or_make (name
);
5725 p
= input_line_pointer
;
5728 if (!is_end_of_statement ())
5730 input_line_pointer
++;
5731 pa_type_args (symbol
, 0);
5735 /* Sigh. To be compatable with the HP assembler and to help
5736 poorly written assembly code, we assign a type based on
5737 the the current segment. Note only BSF_FUNCTION really
5738 matters, we do not need to set the full SYMBOL_TYPE_* info. */
5739 if (now_seg
== text_section
)
5740 symbol_get_bfdsym (symbol
)->flags
|= BSF_FUNCTION
;
5742 /* If the section is undefined, then the symbol is undefined
5743 Since this is an import, leave the section undefined. */
5744 S_SET_SEGMENT (symbol
, bfd_und_section_ptr
);
5749 /* The symbol was already defined. Just eat everything up to
5750 the end of the current statement. */
5751 while (!is_end_of_statement ())
5752 input_line_pointer
++;
5755 demand_empty_rest_of_line ();
5758 /* Handle a .LABEL pseudo-op. */
5766 name
= input_line_pointer
;
5767 c
= get_symbol_end ();
5769 if (strlen (name
) > 0)
5772 p
= input_line_pointer
;
5777 as_warn (_("Missing label name on .LABEL"));
5780 if (!is_end_of_statement ())
5782 as_warn (_("extra .LABEL arguments ignored."));
5783 ignore_rest_of_line ();
5785 demand_empty_rest_of_line ();
5788 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5795 /* We must have a valid space and subspace. */
5796 pa_check_current_space_and_subspace ();
5799 as_bad (_("The .LEAVE pseudo-op is not supported"));
5800 demand_empty_rest_of_line ();
5803 /* Handle a .LEVEL pseudo-op. */
5811 level
= input_line_pointer
;
5812 if (strncmp (level
, "1.0", 3) == 0)
5814 input_line_pointer
+= 3;
5815 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 10))
5816 as_warn (_("could not set architecture and machine"));
5818 else if (strncmp (level
, "1.1", 3) == 0)
5820 input_line_pointer
+= 3;
5821 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 11))
5822 as_warn (_("could not set architecture and machine"));
5824 else if (strncmp (level
, "2.0w", 4) == 0)
5826 input_line_pointer
+= 4;
5827 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 25))
5828 as_warn (_("could not set architecture and machine"));
5830 else if (strncmp (level
, "2.0", 3) == 0)
5832 input_line_pointer
+= 3;
5833 if (!bfd_set_arch_mach (stdoutput
, bfd_arch_hppa
, 20))
5834 as_warn (_("could not set architecture and machine"));
5838 as_bad (_("Unrecognized .LEVEL argument\n"));
5839 ignore_rest_of_line ();
5841 demand_empty_rest_of_line ();
5844 /* Handle a .ORIGIN pseudo-op. */
5851 /* We must have a valid space and subspace. */
5852 pa_check_current_space_and_subspace ();
5856 pa_undefine_label ();
5859 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5860 is for static functions. FIXME. Should share more code with .EXPORT. */
5869 name
= input_line_pointer
;
5870 c
= get_symbol_end ();
5872 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5874 as_bad (_("Cannot define static symbol: %s\n"), name
);
5875 p
= input_line_pointer
;
5877 input_line_pointer
++;
5881 S_CLEAR_EXTERNAL (symbol
);
5882 p
= input_line_pointer
;
5884 if (!is_end_of_statement ())
5886 input_line_pointer
++;
5887 pa_type_args (symbol
, 0);
5891 demand_empty_rest_of_line ();
5894 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5895 of a procedure from a syntatical point of view. */
5901 struct call_info
*call_info
;
5904 /* We must have a valid space and subspace. */
5905 pa_check_current_space_and_subspace ();
5908 if (within_procedure
)
5909 as_fatal (_("Nested procedures"));
5911 /* Reset global variables for new procedure. */
5912 callinfo_found
= FALSE
;
5913 within_procedure
= TRUE
;
5915 /* Create another call_info structure. */
5916 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5919 as_fatal (_("Cannot allocate unwind descriptor\n"));
5921 memset (call_info
, 0, sizeof (struct call_info
));
5923 call_info
->ci_next
= NULL
;
5925 if (call_info_root
== NULL
)
5927 call_info_root
= call_info
;
5928 last_call_info
= call_info
;
5932 last_call_info
->ci_next
= call_info
;
5933 last_call_info
= call_info
;
5936 /* set up defaults on call_info structure */
5938 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5939 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5940 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5942 /* If we got a .PROC pseudo-op, we know that the function is defined
5943 locally. Make sure it gets into the symbol table. */
5945 label_symbol_struct
*label_symbol
= pa_get_label ();
5949 if (label_symbol
->lss_label
)
5951 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5952 symbol_get_bfdsym (label_symbol
->lss_label
)->flags
|= BSF_FUNCTION
;
5955 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
5958 last_call_info
->start_symbol
= NULL
;
5961 demand_empty_rest_of_line ();
5964 /* Process the syntatical end of a procedure. Make sure all the
5965 appropriate pseudo-ops were found within the procedure. */
5973 /* We must have a valid space and subspace. */
5974 pa_check_current_space_and_subspace ();
5977 /* If we are within a procedure definition, make sure we've
5978 defined a label for the procedure; handle case where the
5979 label was defined after the .PROC directive.
5981 Note there's not need to diddle with the segment or fragment
5982 for the label symbol in this case. We have already switched
5983 into the new $CODE$ subspace at this point. */
5984 if (within_procedure
&& last_call_info
->start_symbol
== NULL
)
5986 label_symbol_struct
*label_symbol
= pa_get_label ();
5990 if (label_symbol
->lss_label
)
5992 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5993 symbol_get_bfdsym (label_symbol
->lss_label
)->flags
5996 /* Also handle allocation of a fixup to hold the unwind
5997 information when the label appears after the proc/procend. */
5998 if (within_entry_exit
)
6000 char *where
= frag_more (0);
6002 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
6003 NULL
, (offsetT
) 0, NULL
,
6004 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
6005 (int *) &last_call_info
->ci_unwind
.descriptor
);
6010 as_bad (_("Missing function name for .PROC (corrupted label chain)"));
6013 as_bad (_("Missing function name for .PROC"));
6016 if (!within_procedure
)
6017 as_bad (_("misplaced .procend"));
6019 if (!callinfo_found
)
6020 as_bad (_("Missing .callinfo for this procedure"));
6022 if (within_entry_exit
)
6023 as_bad (_("Missing .EXIT for a .ENTRY"));
6026 /* ELF needs to mark the end of each function so that it can compute
6027 the size of the function (apparently its needed in the symbol table). */
6028 hppa_elf_mark_end_of_function ();
6031 within_procedure
= FALSE
;
6032 demand_empty_rest_of_line ();
6033 pa_undefine_label ();
6036 /* If VALUE is an exact power of two between zero and 2^31, then
6037 return log2 (VALUE). Else return -1. */
6045 while ((1 << shift
) != value
&& shift
< 32)
6056 /* Check to make sure we have a valid space and subspace. */
6059 pa_check_current_space_and_subspace ()
6061 if (current_space
== NULL
)
6062 as_fatal (_("Not in a space.\n"));
6064 if (current_subspace
== NULL
)
6065 as_fatal (_("Not in a subspace.\n"));
6068 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
6069 then create a new space entry to hold the information specified
6070 by the parameters to the .SPACE directive. */
6072 static sd_chain_struct
*
6073 pa_parse_space_stmt (space_name
, create_flag
)
6077 char *name
, *ptemp
, c
;
6078 char loadable
, defined
, private, sort
;
6080 asection
*seg
= NULL
;
6081 sd_chain_struct
*space
;
6083 /* load default values */
6089 if (strcmp (space_name
, "$TEXT$") == 0)
6091 seg
= pa_def_spaces
[0].segment
;
6092 defined
= pa_def_spaces
[0].defined
;
6093 private = pa_def_spaces
[0].private;
6094 sort
= pa_def_spaces
[0].sort
;
6095 spnum
= pa_def_spaces
[0].spnum
;
6097 else if (strcmp (space_name
, "$PRIVATE$") == 0)
6099 seg
= pa_def_spaces
[1].segment
;
6100 defined
= pa_def_spaces
[1].defined
;
6101 private = pa_def_spaces
[1].private;
6102 sort
= pa_def_spaces
[1].sort
;
6103 spnum
= pa_def_spaces
[1].spnum
;
6106 if (!is_end_of_statement ())
6108 print_errors
= FALSE
;
6109 ptemp
= input_line_pointer
+ 1;
6110 /* First see if the space was specified as a number rather than
6111 as a name. According to the PA assembly manual the rest of
6112 the line should be ignored. */
6113 temp
= pa_parse_number (&ptemp
, 0);
6117 input_line_pointer
= ptemp
;
6121 while (!is_end_of_statement ())
6123 input_line_pointer
++;
6124 name
= input_line_pointer
;
6125 c
= get_symbol_end ();
6126 if ((strncasecmp (name
, "spnum", 5) == 0))
6128 *input_line_pointer
= c
;
6129 input_line_pointer
++;
6130 spnum
= get_absolute_expression ();
6132 else if ((strncasecmp (name
, "sort", 4) == 0))
6134 *input_line_pointer
= c
;
6135 input_line_pointer
++;
6136 sort
= get_absolute_expression ();
6138 else if ((strncasecmp (name
, "unloadable", 10) == 0))
6140 *input_line_pointer
= c
;
6143 else if ((strncasecmp (name
, "notdefined", 10) == 0))
6145 *input_line_pointer
= c
;
6148 else if ((strncasecmp (name
, "private", 7) == 0))
6150 *input_line_pointer
= c
;
6155 as_bad (_("Invalid .SPACE argument"));
6156 *input_line_pointer
= c
;
6157 if (!is_end_of_statement ())
6158 input_line_pointer
++;
6162 print_errors
= TRUE
;
6165 if (create_flag
&& seg
== NULL
)
6166 seg
= subseg_new (space_name
, 0);
6168 /* If create_flag is nonzero, then create the new space with
6169 the attributes computed above. Else set the values in
6170 an already existing space -- this can only happen for
6171 the first occurence of a built-in space. */
6173 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
6174 private, sort
, seg
, 1);
6177 space
= is_defined_space (space_name
);
6178 SPACE_SPNUM (space
) = spnum
;
6179 SPACE_DEFINED (space
) = defined
& 1;
6180 SPACE_USER_DEFINED (space
) = 1;
6183 #ifdef obj_set_section_attributes
6184 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
6190 /* Handle a .SPACE pseudo-op; this switches the current space to the
6191 given space, creating the new space if necessary. */
6197 char *name
, c
, *space_name
, *save_s
;
6199 sd_chain_struct
*sd_chain
;
6201 if (within_procedure
)
6203 as_bad (_("Can\'t change spaces within a procedure definition. Ignored"));
6204 ignore_rest_of_line ();
6208 /* Check for some of the predefined spaces. FIXME: most of the code
6209 below is repeated several times, can we extract the common parts
6210 and place them into a subroutine or something similar? */
6211 /* FIXME Is this (and the next IF stmt) really right?
6212 What if INPUT_LINE_POINTER points to "$TEXT$FOO"? */
6213 if (strncmp (input_line_pointer
, "$TEXT$", 6) == 0)
6215 input_line_pointer
+= 6;
6216 sd_chain
= is_defined_space ("$TEXT$");
6217 if (sd_chain
== NULL
)
6218 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
6219 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
6220 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
6222 current_space
= sd_chain
;
6223 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
6225 = pa_subsegment_to_subspace (text_section
,
6226 sd_chain
->sd_last_subseg
);
6227 demand_empty_rest_of_line ();
6230 if (strncmp (input_line_pointer
, "$PRIVATE$", 9) == 0)
6232 input_line_pointer
+= 9;
6233 sd_chain
= is_defined_space ("$PRIVATE$");
6234 if (sd_chain
== NULL
)
6235 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
6236 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
6237 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
6239 current_space
= sd_chain
;
6240 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
6242 = pa_subsegment_to_subspace (data_section
,
6243 sd_chain
->sd_last_subseg
);
6244 demand_empty_rest_of_line ();
6247 if (!strncasecmp (input_line_pointer
,
6248 GDB_DEBUG_SPACE_NAME
,
6249 strlen (GDB_DEBUG_SPACE_NAME
)))
6251 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
6252 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
6253 if (sd_chain
== NULL
)
6254 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
6255 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
6256 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
6258 current_space
= sd_chain
;
6261 asection
*gdb_section
6262 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
6264 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
6266 = pa_subsegment_to_subspace (gdb_section
,
6267 sd_chain
->sd_last_subseg
);
6269 demand_empty_rest_of_line ();
6273 /* It could be a space specified by number. */
6275 save_s
= input_line_pointer
;
6276 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
6278 if ((sd_chain
= pa_find_space_by_number (temp
)))
6280 current_space
= sd_chain
;
6282 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
6284 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
6285 sd_chain
->sd_last_subseg
);
6286 demand_empty_rest_of_line ();
6291 /* Not a number, attempt to create a new space. */
6293 input_line_pointer
= save_s
;
6294 name
= input_line_pointer
;
6295 c
= get_symbol_end ();
6296 space_name
= xmalloc (strlen (name
) + 1);
6297 strcpy (space_name
, name
);
6298 *input_line_pointer
= c
;
6300 sd_chain
= pa_parse_space_stmt (space_name
, 1);
6301 current_space
= sd_chain
;
6303 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
6304 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
6305 sd_chain
->sd_last_subseg
);
6306 demand_empty_rest_of_line ();
6310 /* Switch to a new space. (I think). FIXME. */
6319 sd_chain_struct
*space
;
6321 name
= input_line_pointer
;
6322 c
= get_symbol_end ();
6323 space
= is_defined_space (name
);
6327 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
6330 as_warn (_("Undefined space: '%s' Assuming space number = 0."), name
);
6332 *input_line_pointer
= c
;
6333 demand_empty_rest_of_line ();
6336 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
6337 given subspace, creating the new subspace if necessary.
6339 FIXME. Should mirror pa_space more closely, in particular how
6340 they're broken up into subroutines. */
6343 pa_subspace (create_new
)
6346 char *name
, *ss_name
, c
;
6347 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
6348 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
6349 sd_chain_struct
*space
;
6350 ssd_chain_struct
*ssd
;
6353 if (current_space
== NULL
)
6354 as_fatal (_("Must be in a space before changing or declaring subspaces.\n"));
6356 if (within_procedure
)
6358 as_bad (_("Can\'t change subspaces within a procedure definition. Ignored"));
6359 ignore_rest_of_line ();
6363 name
= input_line_pointer
;
6364 c
= get_symbol_end ();
6365 ss_name
= xmalloc (strlen (name
) + 1);
6366 strcpy (ss_name
, name
);
6367 *input_line_pointer
= c
;
6369 /* Load default values. */
6381 space
= current_space
;
6385 ssd
= is_defined_subspace (ss_name
);
6386 /* Allow user to override the builtin attributes of subspaces. But
6387 only allow the attributes to be changed once! */
6388 if (ssd
&& SUBSPACE_DEFINED (ssd
))
6390 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
6391 current_subspace
= ssd
;
6392 if (!is_end_of_statement ())
6393 as_warn (_("Parameters of an existing subspace can\'t be modified"));
6394 demand_empty_rest_of_line ();
6399 /* A new subspace. Load default values if it matches one of
6400 the builtin subspaces. */
6402 while (pa_def_subspaces
[i
].name
)
6404 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
6406 loadable
= pa_def_subspaces
[i
].loadable
;
6407 common
= pa_def_subspaces
[i
].common
;
6408 dup_common
= pa_def_subspaces
[i
].dup_common
;
6409 code_only
= pa_def_subspaces
[i
].code_only
;
6410 zero
= pa_def_subspaces
[i
].zero
;
6411 space_index
= pa_def_subspaces
[i
].space_index
;
6412 alignment
= pa_def_subspaces
[i
].alignment
;
6413 quadrant
= pa_def_subspaces
[i
].quadrant
;
6414 access
= pa_def_subspaces
[i
].access
;
6415 sort
= pa_def_subspaces
[i
].sort
;
6422 /* We should be working with a new subspace now. Fill in
6423 any information as specified by the user. */
6424 if (!is_end_of_statement ())
6426 input_line_pointer
++;
6427 while (!is_end_of_statement ())
6429 name
= input_line_pointer
;
6430 c
= get_symbol_end ();
6431 if ((strncasecmp (name
, "quad", 4) == 0))
6433 *input_line_pointer
= c
;
6434 input_line_pointer
++;
6435 quadrant
= get_absolute_expression ();
6437 else if ((strncasecmp (name
, "align", 5) == 0))
6439 *input_line_pointer
= c
;
6440 input_line_pointer
++;
6441 alignment
= get_absolute_expression ();
6442 if (log2 (alignment
) == -1)
6444 as_bad (_("Alignment must be a power of 2"));
6448 else if ((strncasecmp (name
, "access", 6) == 0))
6450 *input_line_pointer
= c
;
6451 input_line_pointer
++;
6452 access
= get_absolute_expression ();
6454 else if ((strncasecmp (name
, "sort", 4) == 0))
6456 *input_line_pointer
= c
;
6457 input_line_pointer
++;
6458 sort
= get_absolute_expression ();
6460 else if ((strncasecmp (name
, "code_only", 9) == 0))
6462 *input_line_pointer
= c
;
6465 else if ((strncasecmp (name
, "unloadable", 10) == 0))
6467 *input_line_pointer
= c
;
6470 else if ((strncasecmp (name
, "common", 6) == 0))
6472 *input_line_pointer
= c
;
6475 else if ((strncasecmp (name
, "dup_comm", 8) == 0))
6477 *input_line_pointer
= c
;
6480 else if ((strncasecmp (name
, "zero", 4) == 0))
6482 *input_line_pointer
= c
;
6485 else if ((strncasecmp (name
, "first", 5) == 0))
6486 as_bad (_("FIRST not supported as a .SUBSPACE argument"));
6488 as_bad (_("Invalid .SUBSPACE argument"));
6489 if (!is_end_of_statement ())
6490 input_line_pointer
++;
6494 /* Compute a reasonable set of BFD flags based on the information
6495 in the .subspace directive. */
6496 applicable
= bfd_applicable_section_flags (stdoutput
);
6499 flags
|= (SEC_ALLOC
| SEC_LOAD
);
6502 if (common
|| dup_common
)
6503 flags
|= SEC_IS_COMMON
;
6505 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
6507 /* This is a zero-filled subspace (eg BSS). */
6509 flags
&= ~(SEC_LOAD
| SEC_HAS_CONTENTS
);
6511 applicable
&= flags
;
6513 /* If this is an existing subspace, then we want to use the
6514 segment already associated with the subspace.
6516 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
6517 lots of sections. It might be a problem in the PA ELF
6518 code, I do not know yet. For now avoid creating anything
6519 but the "standard" sections for ELF. */
6521 section
= subseg_force_new (ss_name
, 0);
6523 section
= ssd
->ssd_seg
;
6525 section
= subseg_new (ss_name
, 0);
6528 seg_info (section
)->bss
= 1;
6530 /* Now set the flags. */
6531 bfd_set_section_flags (stdoutput
, section
, applicable
);
6533 /* Record any alignment request for this section. */
6534 record_alignment (section
, log2 (alignment
));
6536 /* Set the starting offset for this section. */
6537 bfd_set_section_vma (stdoutput
, section
,
6538 pa_subspace_start (space
, quadrant
));
6540 /* Now that all the flags are set, update an existing subspace,
6541 or create a new one. */
6544 current_subspace
= update_subspace (space
, ss_name
, loadable
,
6545 code_only
, common
, dup_common
,
6546 sort
, zero
, access
, space_index
,
6547 alignment
, quadrant
,
6550 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
6552 dup_common
, zero
, sort
,
6553 access
, space_index
,
6554 alignment
, quadrant
, section
);
6556 demand_empty_rest_of_line ();
6557 current_subspace
->ssd_seg
= section
;
6558 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
6560 SUBSPACE_DEFINED (current_subspace
) = 1;
6564 /* Create default space and subspace dictionaries. */
6571 space_dict_root
= NULL
;
6572 space_dict_last
= NULL
;
6575 while (pa_def_spaces
[i
].name
)
6579 /* Pick the right name to use for the new section. */
6580 name
= pa_def_spaces
[i
].name
;
6582 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
6583 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
6584 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
6585 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
6586 pa_def_spaces
[i
].segment
, 0);
6591 while (pa_def_subspaces
[i
].name
)
6594 int applicable
, subsegment
;
6595 asection
*segment
= NULL
;
6596 sd_chain_struct
*space
;
6598 /* Pick the right name for the new section and pick the right
6599 subsegment number. */
6600 name
= pa_def_subspaces
[i
].name
;
6603 /* Create the new section. */
6604 segment
= subseg_new (name
, subsegment
);
6607 /* For SOM we want to replace the standard .text, .data, and .bss
6608 sections with our own. We also want to set BFD flags for
6609 all the built-in subspaces. */
6610 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$"))
6612 text_section
= segment
;
6613 applicable
= bfd_applicable_section_flags (stdoutput
);
6614 bfd_set_section_flags (stdoutput
, segment
,
6615 applicable
& (SEC_ALLOC
| SEC_LOAD
6616 | SEC_RELOC
| SEC_CODE
6618 | SEC_HAS_CONTENTS
));
6620 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$"))
6622 data_section
= segment
;
6623 applicable
= bfd_applicable_section_flags (stdoutput
);
6624 bfd_set_section_flags (stdoutput
, segment
,
6625 applicable
& (SEC_ALLOC
| SEC_LOAD
6627 | SEC_HAS_CONTENTS
));
6631 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$"))
6633 bss_section
= segment
;
6634 applicable
= bfd_applicable_section_flags (stdoutput
);
6635 bfd_set_section_flags (stdoutput
, segment
,
6636 applicable
& SEC_ALLOC
);
6638 else if (!strcmp (pa_def_subspaces
[i
].name
, "$LIT$"))
6640 applicable
= bfd_applicable_section_flags (stdoutput
);
6641 bfd_set_section_flags (stdoutput
, segment
,
6642 applicable
& (SEC_ALLOC
| SEC_LOAD
6645 | SEC_HAS_CONTENTS
));
6647 else if (!strcmp (pa_def_subspaces
[i
].name
, "$MILLICODE$"))
6649 applicable
= bfd_applicable_section_flags (stdoutput
);
6650 bfd_set_section_flags (stdoutput
, segment
,
6651 applicable
& (SEC_ALLOC
| SEC_LOAD
6654 | SEC_HAS_CONTENTS
));
6656 else if (!strcmp (pa_def_subspaces
[i
].name
, "$UNWIND$"))
6658 applicable
= bfd_applicable_section_flags (stdoutput
);
6659 bfd_set_section_flags (stdoutput
, segment
,
6660 applicable
& (SEC_ALLOC
| SEC_LOAD
6663 | SEC_HAS_CONTENTS
));
6666 /* Find the space associated with this subspace. */
6667 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
6668 def_space_index
].segment
);
6671 as_fatal (_("Internal error: Unable to find containing space for %s."),
6672 pa_def_subspaces
[i
].name
);
6675 create_new_subspace (space
, name
,
6676 pa_def_subspaces
[i
].loadable
,
6677 pa_def_subspaces
[i
].code_only
,
6678 pa_def_subspaces
[i
].common
,
6679 pa_def_subspaces
[i
].dup_common
,
6680 pa_def_subspaces
[i
].zero
,
6681 pa_def_subspaces
[i
].sort
,
6682 pa_def_subspaces
[i
].access
,
6683 pa_def_subspaces
[i
].space_index
,
6684 pa_def_subspaces
[i
].alignment
,
6685 pa_def_subspaces
[i
].quadrant
,
6693 /* Create a new space NAME, with the appropriate flags as defined
6694 by the given parameters. */
6696 static sd_chain_struct
*
6697 create_new_space (name
, spnum
, loadable
, defined
, private,
6698 sort
, seg
, user_defined
)
6708 sd_chain_struct
*chain_entry
;
6710 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
6712 as_fatal (_("Out of memory: could not allocate new space chain entry: %s\n"),
6715 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
6716 strcpy (SPACE_NAME (chain_entry
), name
);
6717 SPACE_DEFINED (chain_entry
) = defined
;
6718 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
6719 SPACE_SPNUM (chain_entry
) = spnum
;
6721 chain_entry
->sd_seg
= seg
;
6722 chain_entry
->sd_last_subseg
= -1;
6723 chain_entry
->sd_subspaces
= NULL
;
6724 chain_entry
->sd_next
= NULL
;
6726 /* Find spot for the new space based on its sort key. */
6727 if (!space_dict_last
)
6728 space_dict_last
= chain_entry
;
6730 if (space_dict_root
== NULL
)
6731 space_dict_root
= chain_entry
;
6734 sd_chain_struct
*chain_pointer
;
6735 sd_chain_struct
*prev_chain_pointer
;
6737 chain_pointer
= space_dict_root
;
6738 prev_chain_pointer
= NULL
;
6740 while (chain_pointer
)
6742 prev_chain_pointer
= chain_pointer
;
6743 chain_pointer
= chain_pointer
->sd_next
;
6746 /* At this point we've found the correct place to add the new
6747 entry. So add it and update the linked lists as appropriate. */
6748 if (prev_chain_pointer
)
6750 chain_entry
->sd_next
= chain_pointer
;
6751 prev_chain_pointer
->sd_next
= chain_entry
;
6755 space_dict_root
= chain_entry
;
6756 chain_entry
->sd_next
= chain_pointer
;
6759 if (chain_entry
->sd_next
== NULL
)
6760 space_dict_last
= chain_entry
;
6763 /* This is here to catch predefined spaces which do not get
6764 modified by the user's input. Another call is found at
6765 the bottom of pa_parse_space_stmt to handle cases where
6766 the user modifies a predefined space. */
6767 #ifdef obj_set_section_attributes
6768 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
6774 /* Create a new subspace NAME, with the appropriate flags as defined
6775 by the given parameters.
6777 Add the new subspace to the subspace dictionary chain in numerical
6778 order as defined by the SORT entries. */
6780 static ssd_chain_struct
*
6781 create_new_subspace (space
, name
, loadable
, code_only
, common
,
6782 dup_common
, is_zero
, sort
, access
, space_index
,
6783 alignment
, quadrant
, seg
)
6784 sd_chain_struct
*space
;
6786 int loadable
, code_only
, common
, dup_common
, is_zero
;
6794 ssd_chain_struct
*chain_entry
;
6796 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
6798 as_fatal (_("Out of memory: could not allocate new subspace chain entry: %s\n"), name
);
6800 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
6801 strcpy (SUBSPACE_NAME (chain_entry
), name
);
6803 /* Initialize subspace_defined. When we hit a .subspace directive
6804 we'll set it to 1 which "locks-in" the subspace attributes. */
6805 SUBSPACE_DEFINED (chain_entry
) = 0;
6807 chain_entry
->ssd_subseg
= 0;
6808 chain_entry
->ssd_seg
= seg
;
6809 chain_entry
->ssd_next
= NULL
;
6811 /* Find spot for the new subspace based on its sort key. */
6812 if (space
->sd_subspaces
== NULL
)
6813 space
->sd_subspaces
= chain_entry
;
6816 ssd_chain_struct
*chain_pointer
;
6817 ssd_chain_struct
*prev_chain_pointer
;
6819 chain_pointer
= space
->sd_subspaces
;
6820 prev_chain_pointer
= NULL
;
6822 while (chain_pointer
)
6824 prev_chain_pointer
= chain_pointer
;
6825 chain_pointer
= chain_pointer
->ssd_next
;
6828 /* Now we have somewhere to put the new entry. Insert it and update
6830 if (prev_chain_pointer
)
6832 chain_entry
->ssd_next
= chain_pointer
;
6833 prev_chain_pointer
->ssd_next
= chain_entry
;
6837 space
->sd_subspaces
= chain_entry
;
6838 chain_entry
->ssd_next
= chain_pointer
;
6842 #ifdef obj_set_subsection_attributes
6843 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
6850 /* Update the information for the given subspace based upon the
6851 various arguments. Return the modified subspace chain entry. */
6853 static ssd_chain_struct
*
6854 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
6855 zero
, access
, space_index
, alignment
, quadrant
, section
)
6856 sd_chain_struct
*space
;
6870 ssd_chain_struct
*chain_entry
;
6872 chain_entry
= is_defined_subspace (name
);
6874 #ifdef obj_set_subsection_attributes
6875 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
6882 /* Return the space chain entry for the space with the name NAME or
6883 NULL if no such space exists. */
6885 static sd_chain_struct
*
6886 is_defined_space (name
)
6889 sd_chain_struct
*chain_pointer
;
6891 for (chain_pointer
= space_dict_root
;
6893 chain_pointer
= chain_pointer
->sd_next
)
6895 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6896 return chain_pointer
;
6899 /* No mapping from segment to space was found. Return NULL. */
6903 /* Find and return the space associated with the given seg. If no mapping
6904 from the given seg to a space is found, then return NULL.
6906 Unlike subspaces, the number of spaces is not expected to grow much,
6907 so a linear exhaustive search is OK here. */
6909 static sd_chain_struct
*
6910 pa_segment_to_space (seg
)
6913 sd_chain_struct
*space_chain
;
6915 /* Walk through each space looking for the correct mapping. */
6916 for (space_chain
= space_dict_root
;
6918 space_chain
= space_chain
->sd_next
)
6920 if (space_chain
->sd_seg
== seg
)
6924 /* Mapping was not found. Return NULL. */
6928 /* Return the space chain entry for the subspace with the name NAME or
6929 NULL if no such subspace exists.
6931 Uses a linear search through all the spaces and subspaces, this may
6932 not be appropriate if we ever being placing each function in its
6935 static ssd_chain_struct
*
6936 is_defined_subspace (name
)
6939 sd_chain_struct
*space_chain
;
6940 ssd_chain_struct
*subspace_chain
;
6942 /* Walk through each space. */
6943 for (space_chain
= space_dict_root
;
6945 space_chain
= space_chain
->sd_next
)
6947 /* Walk through each subspace looking for a name which matches. */
6948 for (subspace_chain
= space_chain
->sd_subspaces
;
6950 subspace_chain
= subspace_chain
->ssd_next
)
6951 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6952 return subspace_chain
;
6955 /* Subspace wasn't found. Return NULL. */
6959 /* Find and return the subspace associated with the given seg. If no
6960 mapping from the given seg to a subspace is found, then return NULL.
6962 If we ever put each procedure/function within its own subspace
6963 (to make life easier on the compiler and linker), then this will have
6964 to become more efficient. */
6966 static ssd_chain_struct
*
6967 pa_subsegment_to_subspace (seg
, subseg
)
6971 sd_chain_struct
*space_chain
;
6972 ssd_chain_struct
*subspace_chain
;
6974 /* Walk through each space. */
6975 for (space_chain
= space_dict_root
;
6977 space_chain
= space_chain
->sd_next
)
6979 if (space_chain
->sd_seg
== seg
)
6981 /* Walk through each subspace within each space looking for
6982 the correct mapping. */
6983 for (subspace_chain
= space_chain
->sd_subspaces
;
6985 subspace_chain
= subspace_chain
->ssd_next
)
6986 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6987 return subspace_chain
;
6991 /* No mapping from subsegment to subspace found. Return NULL. */
6995 /* Given a number, try and find a space with the name number.
6997 Return a pointer to a space dictionary chain entry for the space
6998 that was found or NULL on failure. */
7000 static sd_chain_struct
*
7001 pa_find_space_by_number (number
)
7004 sd_chain_struct
*space_chain
;
7006 for (space_chain
= space_dict_root
;
7008 space_chain
= space_chain
->sd_next
)
7010 if (SPACE_SPNUM (space_chain
) == (unsigned int) number
)
7014 /* No appropriate space found. Return NULL. */
7018 /* Return the starting address for the given subspace. If the starting
7019 address is unknown then return zero. */
7022 pa_subspace_start (space
, quadrant
)
7023 sd_chain_struct
*space
;
7026 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
7027 is not correct for the PA OSF1 port. */
7028 if ((strcmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
7030 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
7037 /* FIXME. Needs documentation. */
7039 pa_next_subseg (space
)
7040 sd_chain_struct
*space
;
7043 space
->sd_last_subseg
++;
7044 return space
->sd_last_subseg
;
7048 /* Helper function for pa_stringer. Used to find the end of
7055 unsigned int c
= *s
& CHAR_MASK
;
7058 /* We must have a valid space and subspace. */
7059 pa_check_current_space_and_subspace ();
7073 /* Handle a .STRING type pseudo-op. */
7076 pa_stringer (append_zero
)
7079 char *s
, num_buf
[4];
7083 /* Preprocess the string to handle PA-specific escape sequences.
7084 For example, \xDD where DD is a hexidecimal number should be
7085 changed to \OOO where OOO is an octal number. */
7087 /* Skip the opening quote. */
7088 s
= input_line_pointer
+ 1;
7090 while (is_a_char (c
= pa_stringer_aux (s
++)))
7097 /* Handle \x<num>. */
7100 unsigned int number
;
7105 /* Get pas the 'x'. */
7107 for (num_digit
= 0, number
= 0, dg
= *s
;
7109 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
7110 || (dg
>= 'A' && dg
<= 'F'));
7114 number
= number
* 16 + dg
- '0';
7115 else if (dg
>= 'a' && dg
<= 'f')
7116 number
= number
* 16 + dg
- 'a' + 10;
7118 number
= number
* 16 + dg
- 'A' + 10;
7128 sprintf (num_buf
, "%02o", number
);
7131 sprintf (num_buf
, "%03o", number
);
7134 for (i
= 0; i
<= num_digit
; i
++)
7135 s_start
[i
] = num_buf
[i
];
7139 /* This might be a "\"", skip over the escaped char. */
7146 stringer (append_zero
);
7147 pa_undefine_label ();
7150 /* Handle a .VERSION pseudo-op. */
7157 pa_undefine_label ();
7162 /* Handle a .COMPILER pseudo-op. */
7165 pa_compiler (unused
)
7168 obj_som_compiler (0);
7169 pa_undefine_label ();
7174 /* Handle a .COPYRIGHT pseudo-op. */
7177 pa_copyright (unused
)
7181 pa_undefine_label ();
7184 /* Just like a normal cons, but when finished we have to undefine
7185 the latest space label. */
7192 pa_undefine_label ();
7195 /* Switch to the data space. As usual delete our label. */
7202 current_space
= is_defined_space ("$PRIVATE$");
7204 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
7207 pa_undefine_label ();
7210 /* Like float_cons, but we need to undefine our label. */
7213 pa_float_cons (float_type
)
7216 float_cons (float_type
);
7217 pa_undefine_label ();
7220 /* Like s_fill, but delete our label when finished. */
7227 /* We must have a valid space and subspace. */
7228 pa_check_current_space_and_subspace ();
7232 pa_undefine_label ();
7235 /* Like lcomm, but delete our label when finished. */
7238 pa_lcomm (needs_align
)
7242 /* We must have a valid space and subspace. */
7243 pa_check_current_space_and_subspace ();
7246 s_lcomm (needs_align
);
7247 pa_undefine_label ();
7250 /* Like lsym, but delete our label when finished. */
7257 /* We must have a valid space and subspace. */
7258 pa_check_current_space_and_subspace ();
7262 pa_undefine_label ();
7265 /* Switch to the text space. Like s_text, but delete our
7266 label when finished. */
7272 current_space
= is_defined_space ("$TEXT$");
7274 = pa_subsegment_to_subspace (current_space
->sd_seg
, 0);
7278 pa_undefine_label ();
7281 /* On the PA relocations which involve function symbols must not be
7282 adjusted. This so that the linker can know when/how to create argument
7283 relocation stubs for indirect calls and calls to static functions.
7285 "T" field selectors create DLT relative fixups for accessing
7286 globals and statics in PIC code; each DLT relative fixup creates
7287 an entry in the DLT table. The entries contain the address of
7288 the final target (eg accessing "foo" would create a DLT entry
7289 with the address of "foo").
7291 Unfortunately, the HP linker doesn't take into account any addend
7292 when generating the DLT; so accessing $LIT$+8 puts the address of
7293 $LIT$ into the DLT rather than the address of $LIT$+8.
7295 The end result is we can't perform relocation symbol reductions for
7296 any fixup which creates entries in the DLT (eg they use "T" field
7299 Reject reductions involving symbols with external scope; such
7300 reductions make life a living hell for object file editors.
7302 FIXME. Also reject R_HPPA relocations which are 32bits wide in
7303 the code space. The SOM BFD backend doesn't know how to pull the
7304 right bits out of an instruction. */
7307 hppa_fix_adjustable (fixp
)
7310 struct hppa_fix_struct
*hppa_fix
;
7312 hppa_fix
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
7315 /* Reject reductions of symbols in 32bit relocs. */
7316 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
7319 /* Reject reductions of symbols in sym1-sym2 expressions when
7320 the fixup will occur in a CODE subspace.
7322 XXX FIXME: Long term we probably want to reject all of these;
7323 for example reducing in the debug section would lose if we ever
7324 supported using the optimizing hp linker. */
7327 && (hppa_fix
->segment
->flags
& SEC_CODE
))
7329 /* Apparently sy_used_in_reloc never gets set for sub symbols. */
7330 symbol_mark_used_in_reloc (fixp
->fx_subsy
);
7334 /* We can't adjust any relocs that use LR% and RR% field selectors.
7335 That confuses the HP linker. */
7336 if (hppa_fix
->fx_r_field
== e_lrsel
7337 || hppa_fix
->fx_r_field
== e_rrsel
7338 || hppa_fix
->fx_r_field
== e_nlrsel
)
7342 /* Reject reductions of symbols in DLT relative relocs,
7343 relocations with plabels. */
7344 if (hppa_fix
->fx_r_field
== e_tsel
7345 || hppa_fix
->fx_r_field
== e_ltsel
7346 || hppa_fix
->fx_r_field
== e_rtsel
7347 || hppa_fix
->fx_r_field
== e_psel
7348 || hppa_fix
->fx_r_field
== e_rpsel
7349 || hppa_fix
->fx_r_field
== e_lpsel
)
7352 if (fixp
->fx_addsy
&& S_IS_EXTERNAL (fixp
->fx_addsy
))
7355 /* Reject absolute calls (jumps). */
7356 if (hppa_fix
->fx_r_type
== R_HPPA_ABS_CALL
)
7359 /* Reject reductions of function symbols. */
7360 if (fixp
->fx_addsy
== 0 || ! S_IS_FUNCTION (fixp
->fx_addsy
))
7366 /* Return nonzero if the fixup in FIXP will require a relocation,
7367 even it if appears that the fixup could be completely handled
7371 hppa_force_relocation (fixp
)
7374 struct hppa_fix_struct
*hppa_fixp
;
7377 hppa_fixp
= (struct hppa_fix_struct
*) fixp
->tc_fix_data
;
7379 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
7380 || fixp
->fx_r_type
== R_HPPA_BEGIN_BRTAB
7381 || fixp
->fx_r_type
== R_HPPA_END_BRTAB
7382 || fixp
->fx_r_type
== R_HPPA_BEGIN_TRY
7383 || fixp
->fx_r_type
== R_HPPA_END_TRY
7384 || (fixp
->fx_addsy
!= NULL
&& fixp
->fx_subsy
!= NULL
7385 && (hppa_fixp
->segment
->flags
& SEC_CODE
) != 0))
7389 #define arg_reloc_stub_needed(CALLER, CALLEE) \
7390 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
7393 /* It is necessary to force PC-relative calls/jumps to have a relocation
7394 entry if they're going to need either a argument relocation or long
7395 call stub. FIXME. Can't we need the same for absolute calls? */
7396 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
7397 && (arg_reloc_stub_needed ((long) ((obj_symbol_type
*)
7398 symbol_get_bfdsym (fixp
->fx_addsy
))->tc_data
.ap
.hppa_arg_reloc
,
7399 hppa_fixp
->fx_arg_reloc
)))
7402 distance
= (fixp
->fx_offset
+ S_GET_VALUE (fixp
->fx_addsy
)
7403 - md_pcrel_from (fixp
));
7404 /* Now check and see if we're going to need a long-branch stub. */
7405 if (fixp
->fx_r_type
== R_HPPA_PCREL_CALL
7406 && (distance
> 262143 || distance
< -262144))
7409 if (fixp
->fx_r_type
== R_HPPA_ABS_CALL
)
7411 #undef arg_reloc_stub_needed
7413 /* No need (yet) to force another relocations to be emitted. */
7417 /* Now for some ELF specific code. FIXME. */
7419 /* Mark the end of a function so that it's possible to compute
7420 the size of the function in hppa_elf_final_processing. */
7423 hppa_elf_mark_end_of_function ()
7425 /* ELF does not have EXIT relocations. All we do is create a
7426 temporary symbol marking the end of the function. */
7427 char *name
= (char *)
7428 xmalloc (strlen ("L$\001end_") +
7429 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
7435 strcpy (name
, "L$\001end_");
7436 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
7438 /* If we have a .exit followed by a .procend, then the
7439 symbol will have already been defined. */
7440 symbolP
= symbol_find (name
);
7443 /* The symbol has already been defined! This can
7444 happen if we have a .exit followed by a .procend.
7446 This is *not* an error. All we want to do is free
7447 the memory we just allocated for the name and continue. */
7452 /* symbol value should be the offset of the
7453 last instruction of the function */
7454 symbolP
= symbol_new (name
, now_seg
, (valueT
) (frag_now_fix () - 4),
7458 S_CLEAR_EXTERNAL (symbolP
);
7459 symbol_table_insert (symbolP
);
7463 last_call_info
->end_symbol
= symbolP
;
7465 as_bad (_("Symbol '%s' could not be created."), name
);
7469 as_bad (_("No memory for symbol name."));
7473 /* For ELF, this function serves one purpose: to setup the st_size
7474 field of STT_FUNC symbols. To do this, we need to scan the
7475 call_info structure list, determining st_size in by taking the
7476 difference in the address of the beginning/end marker symbols. */
7479 elf_hppa_final_processing ()
7481 struct call_info
*call_info_pointer
;
7483 for (call_info_pointer
= call_info_root
;
7485 call_info_pointer
= call_info_pointer
->ci_next
)
7487 elf_symbol_type
*esym
7488 = ((elf_symbol_type
*)
7489 symbol_get_bfdsym (call_info_pointer
->start_symbol
));
7490 esym
->internal_elf_sym
.st_size
=
7491 S_GET_VALUE (call_info_pointer
->end_symbol
)
7492 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;