1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "../bfd/libhppa.h"
31 #include "../bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".hppa_unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
56 #define obj_version obj_elf_version
58 /* Use space aliases. */
61 /* Some local functions only used by ELF. */
62 static void pa_build_symextn_section
PARAMS ((void));
63 static void hppa_tc_make_symextn_section
PARAMS ((void));
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
;
77 #define obj_version obj_som_version
79 /* Do not use space aliases. */
82 /* How to generate a relocation. */
83 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
85 /* Object file formats specify BFD symbol types. */
86 typedef som_symbol_type obj_symbol_type
;
89 /* Various structures and types used internally in tc-hppa.c. */
91 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
95 unsigned int cannot_unwind
:1;
96 unsigned int millicode
:1;
97 unsigned int millicode_save_rest
:1;
98 unsigned int region_desc
:2;
99 unsigned int save_sr
:2;
100 unsigned int entry_fr
:4;
101 unsigned int entry_gr
:5;
102 unsigned int args_stored
:1;
103 unsigned int call_fr
:5;
104 unsigned int call_gr
:5;
105 unsigned int save_sp
:1;
106 unsigned int save_rp
:1;
107 unsigned int save_rp_in_frame
:1;
108 unsigned int extn_ptr_defined
:1;
109 unsigned int cleanup_defined
:1;
111 unsigned int hpe_interrupt_marker
:1;
112 unsigned int hpux_interrupt_marker
:1;
113 unsigned int reserved
:3;
114 unsigned int frame_size
:27;
119 /* Starting and ending offsets of the region described by
121 unsigned int start_offset
;
122 unsigned int end_offset
;
123 struct unwind_desc descriptor
;
126 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
127 control the entry and exit code they generate. It is also used in
128 creation of the correct stack unwind descriptors.
130 NOTE: GAS does not support .enter and .leave for the generation of
131 prologues and epilogues. FIXME.
133 The fields in structure roughly correspond to the arguments available on the
134 .callinfo pseudo-op. */
138 /* Should sr3 be saved in the prologue? */
141 /* Does this function make calls? */
144 /* The unwind descriptor being built. */
145 struct unwind_table ci_unwind
;
147 /* Name of this function. */
148 symbolS
*start_symbol
;
150 /* (temporary) symbol used to mark the end of this function. */
153 /* frags associated with start and end of this function. */
157 /* frags for starting/ending offset of this descriptor. */
158 fragS
*start_offset_frag
;
159 fragS
*end_offset_frag
;
161 /* The location within {start,end}_offset_frag to find the
162 {start,end}_offset. */
163 int start_frag_where
;
166 /* Fixups (relocations) for start_offset and end_offset. */
170 /* Next entry in the chain. */
171 struct call_info
*ci_next
;
174 /* Operand formats for FP instructions. Note not all FP instructions
175 allow all four formats to be used (for example fmpysub only allows
179 SGL
, DBL
, ILLEGAL_FMT
, QUAD
183 /* This fully describes the symbol types which may be attached to
184 an EXPORT or IMPORT directive. Only SOM uses this formation
185 (ELF has no need for it). */
189 SYMBOL_TYPE_ABSOLUTE
,
193 SYMBOL_TYPE_MILLICODE
,
195 SYMBOL_TYPE_PRI_PROG
,
196 SYMBOL_TYPE_SEC_PROG
,
200 /* This structure contains information needed to assemble
201 individual instructions. */
204 /* Holds the opcode after parsing by pa_ip. */
205 unsigned long opcode
;
207 /* Holds an expression associated with the current instruction. */
210 /* Does this instruction use PC-relative addressing. */
213 /* Floating point formats for operand1 and operand2. */
214 fp_operand_format fpof1
;
215 fp_operand_format fpof2
;
217 /* Holds the field selector for this instruction
218 (for example L%, LR%, etc). */
221 /* Holds any argument relocation bits associated with this
222 instruction. (instruction should be some sort of call). */
225 /* The format specification for this instruction. */
228 /* The relocation (if any) associated with this instruction. */
232 /* PA-89 floating point registers are arranged like this:
235 +--------------+--------------+
236 | 0 or 16L | 16 or 16R |
237 +--------------+--------------+
238 | 1 or 17L | 17 or 17R |
239 +--------------+--------------+
247 +--------------+--------------+
248 | 14 or 30L | 30 or 30R |
249 +--------------+--------------+
250 | 15 or 31L | 31 or 31R |
251 +--------------+--------------+
254 The following is a version of pa_parse_number that
255 handles the L/R notation and returns the correct
256 value to put into the instruction register field.
257 The correct value to put into the instruction is
258 encoded in the structure 'pa_89_fp_reg_struct'. */
260 struct pa_89_fp_reg_struct
262 /* The register number. */
269 /* Additional information needed to build argument relocation stubs. */
272 /* The argument relocation specification. */
273 unsigned int arg_reloc
;
275 /* Number of arguments. */
276 unsigned int arg_count
;
279 /* This structure defines an entry in the subspace dictionary
282 struct subspace_dictionary_chain
284 /* Index of containing space. */
285 unsigned long ssd_space_index
;
287 /* Nonzero if this space has been defined by the user code. */
288 unsigned int ssd_defined
;
290 /* Which quadrant within the space this subspace should be loaded into. */
291 unsigned char ssd_quadrant
;
293 /* Alignment (in bytes) for this subspace. */
294 unsigned long ssd_alignment
;
296 /* Access control bits to determine read/write/execute permissions
297 as well as gateway privilege promotions. */
298 unsigned char ssd_access_control_bits
;
300 /* A sorting key so that it is possible to specify ordering of
301 subspaces within a space. */
302 unsigned char ssd_sort_key
;
304 /* Nonzero of this space should be zero filled. */
305 unsigned long ssd_zero
;
307 /* Nonzero if this is a common subspace. */
308 unsigned char ssd_common
;
310 /* Nonzero if this is a common subspace which allows symbols to be
312 unsigned char ssd_dup_common
;
314 /* Nonzero if this subspace is loadable. Note loadable subspaces
315 must be contained within loadable spaces; unloadable subspaces
316 must be contained in unloadable spaces. */
317 unsigned char ssd_loadable
;
319 /* Nonzero if this subspace contains only code. */
320 unsigned char ssd_code_only
;
322 /* Starting offset of this subspace. */
323 unsigned long ssd_subspace_start
;
325 /* Length of this subspace. */
326 unsigned long ssd_subspace_length
;
328 /* Name of this subspace. */
331 /* GAS segment and subsegment associated with this subspace. */
335 /* Index of this subspace within the subspace dictionary of the object
336 file. Not used until object file is written. */
337 int object_file_index
;
339 /* The size of the last alignment request for this subspace. */
342 /* Next space in the subspace dictionary chain. */
343 struct subspace_dictionary_chain
*ssd_next
;
346 typedef struct subspace_dictionary_chain ssd_chain_struct
;
348 /* This structure defines an entry in the subspace dictionary
351 struct space_dictionary_chain
354 /* Holds the index into the string table of the name of this
356 unsigned int sd_name_index
;
358 /* Nonzero if the space is loadable. */
359 unsigned int sd_loadable
;
361 /* Nonzero if this space has been defined by the user code or
362 as a default space. */
363 unsigned int sd_defined
;
365 /* Nonzero if this spaces has been defined by the user code. */
366 unsigned int sd_user_defined
;
368 /* Nonzero if this space is not sharable. */
369 unsigned int sd_private
;
371 /* The space number (or index). */
372 unsigned int sd_spnum
;
374 /* The sort key for this space. May be used to determine how to lay
375 out the spaces within the object file. */
376 unsigned char sd_sort_key
;
378 /* The name of this subspace. */
381 /* GAS segment to which this subspace corresponds. */
384 /* Current subsegment number being used. */
387 /* The chain of subspaces contained within this space. */
388 ssd_chain_struct
*sd_subspaces
;
390 /* The next entry in the space dictionary chain. */
391 struct space_dictionary_chain
*sd_next
;
394 typedef struct space_dictionary_chain sd_chain_struct
;
396 /* Structure for previous label tracking. Needed so that alignments,
397 callinfo declarations, etc can be easily attached to a particular
399 typedef struct label_symbol_struct
401 struct symbol
*lss_label
;
402 sd_chain_struct
*lss_space
;
403 struct label_symbol_struct
*lss_next
;
407 /* This structure defines attributes of the default subspace
408 dictionary entries. */
410 struct default_subspace_dict
412 /* Name of the subspace. */
415 /* FIXME. Is this still needed? */
418 /* Nonzero if this subspace is loadable. */
421 /* Nonzero if this subspace contains only code. */
424 /* Nonzero if this is a common subspace. */
427 /* Nonzero if this is a common subspace which allows symbols
428 to be multiply defined. */
431 /* Nonzero if this subspace should be zero filled. */
434 /* Sort key for this subspace. */
437 /* Access control bits for this subspace. Can represent RWX access
438 as well as privilege level changes for gateways. */
441 /* Index of containing space. */
444 /* Alignment (in bytes) of this subspace. */
447 /* Quadrant within space where this subspace should be loaded. */
450 /* An index into the default spaces array. */
453 /* An alias for this section (or NULL if no alias exists). */
456 /* Subsegment associated with this subspace. */
460 /* This structure defines attributes of the default space
461 dictionary entries. */
463 struct default_space_dict
465 /* Name of the space. */
468 /* Space number. It is possible to identify spaces within
469 assembly code numerically! */
472 /* Nonzero if this space is loadable. */
475 /* Nonzero if this space is "defined". FIXME is still needed */
478 /* Nonzero if this space can not be shared. */
481 /* Sort key for this space. */
484 /* Segment associated with this space. */
487 /* An alias for this section (or NULL if no alias exists). */
491 /* Extra information needed to perform fixups (relocations) on the PA. */
492 struct hppa_fix_struct
494 /* The field selector. */
495 enum hppa_reloc_field_selector_type fx_r_field
;
500 /* Format of fixup. */
503 /* Argument relocation bits. */
506 /* The unwind descriptor associated with this fixup. */
510 /* Structure to hold information about predefined registers. */
518 /* This structure defines the mapping from a FP condition string
519 to a condition number which can be recorded in an instruction. */
526 /* This structure defines a mapping from a field selector
527 string to a field selector type. */
528 struct selector_entry
534 /* Prototypes for functions local to tc-hppa.c. */
536 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
537 static void pa_cons
PARAMS ((int));
538 static void pa_data
PARAMS ((int));
539 static void pa_desc
PARAMS ((int));
540 static void pa_float_cons
PARAMS ((int));
541 static void pa_fill
PARAMS ((int));
542 static void pa_lcomm
PARAMS ((int));
543 static void pa_lsym
PARAMS ((int));
544 static void pa_stringer
PARAMS ((int));
545 static void pa_text
PARAMS ((int));
546 static void pa_version
PARAMS ((int));
547 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
548 static int get_expression
PARAMS ((char *));
549 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
550 static int evaluate_absolute
PARAMS ((struct pa_it
*));
551 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
552 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
553 static int pa_parse_nullif
PARAMS ((char **));
554 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
555 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
556 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
557 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
558 static void pa_block
PARAMS ((int));
559 static void pa_call
PARAMS ((int));
560 static void pa_call_args
PARAMS ((struct call_desc
*));
561 static void pa_callinfo
PARAMS ((int));
562 static void pa_code
PARAMS ((int));
563 static void pa_comm
PARAMS ((int));
564 static void pa_copyright
PARAMS ((int));
565 static void pa_end
PARAMS ((int));
566 static void pa_enter
PARAMS ((int));
567 static void pa_entry
PARAMS ((int));
568 static void pa_equ
PARAMS ((int));
569 static void pa_exit
PARAMS ((int));
570 static void pa_export
PARAMS ((int));
571 static void pa_type_args
PARAMS ((symbolS
*, int));
572 static void pa_import
PARAMS ((int));
573 static void pa_label
PARAMS ((int));
574 static void pa_leave
PARAMS ((int));
575 static void pa_origin
PARAMS ((int));
576 static void pa_proc
PARAMS ((int));
577 static void pa_procend
PARAMS ((int));
578 static void pa_space
PARAMS ((int));
579 static void pa_spnum
PARAMS ((int));
580 static void pa_subspace
PARAMS ((int));
581 static void pa_param
PARAMS ((int));
582 static void pa_undefine_label
PARAMS ((void));
583 static int need_89_opcode
PARAMS ((struct pa_it
*,
584 struct pa_89_fp_reg_struct
*));
585 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
586 static label_symbol_struct
*pa_get_label
PARAMS ((void));
587 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, char,
590 static ssd_chain_struct
*create_new_subspace
PARAMS ((sd_chain_struct
*,
595 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
596 char *, char, char, char,
597 char, char, char, int,
600 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
601 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
602 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
603 static ssd_chain_struct
*pa_subsegment_to_subspace
PARAMS ((asection
*,
605 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
606 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
607 static void pa_ip
PARAMS ((char *));
608 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
609 long, expressionS
*, int,
610 bfd_reloc_code_real_type
,
611 enum hppa_reloc_field_selector_type
,
613 static int is_end_of_statement
PARAMS ((void));
614 static int reg_name_search
PARAMS ((char *));
615 static int pa_chk_field_selector
PARAMS ((char **));
616 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
617 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
618 static void process_exit
PARAMS ((void));
619 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
620 static int log2
PARAMS ((int));
621 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
622 static unsigned int pa_stringer_aux
PARAMS ((char *));
623 static void pa_spaces_begin
PARAMS ((void));
624 static void hppa_elf_mark_end_of_function
PARAMS ((void));
626 /* File and gloally scoped variable declarations. */
628 /* Root and final entry in the space chain. */
629 static sd_chain_struct
*space_dict_root
;
630 static sd_chain_struct
*space_dict_last
;
632 /* The current space and subspace. */
633 static sd_chain_struct
*current_space
;
634 static ssd_chain_struct
*current_subspace
;
636 /* Root of the call_info chain. */
637 static struct call_info
*call_info_root
;
639 /* The last call_info (for functions) structure
640 seen so it can be associated with fixups and
642 static struct call_info
*last_call_info
;
644 /* The last call description (for actual calls). */
645 static struct call_desc last_call_desc
;
647 /* Relaxation isn't supported for the PA yet. */
648 const relax_typeS md_relax_table
[] =
651 /* Jumps are always the same size -- one instruction. */
652 int md_short_jump_size
= 4;
653 int md_long_jump_size
= 4;
655 /* handle of the OPCODE hash table */
656 static struct hash_control
*op_hash
= NULL
;
658 /* This array holds the chars that always start a comment. If the
659 pre-processor is disabled, these aren't very useful. */
660 const char comment_chars
[] = ";";
662 /* Table of pseudo ops for the PA. FIXME -- how many of these
663 are now redundant with the overall GAS and the object file
665 const pseudo_typeS md_pseudo_table
[] =
667 /* align pseudo-ops on the PA specify the actual alignment requested,
668 not the log2 of the requested alignment. */
669 {"align", s_align_bytes
, 8},
670 {"ALIGN", s_align_bytes
, 8},
671 {"block", pa_block
, 1},
672 {"BLOCK", pa_block
, 1},
673 {"blockz", pa_block
, 0},
674 {"BLOCKZ", pa_block
, 0},
675 {"byte", pa_cons
, 1},
676 {"BYTE", pa_cons
, 1},
677 {"call", pa_call
, 0},
678 {"CALL", pa_call
, 0},
679 {"callinfo", pa_callinfo
, 0},
680 {"CALLINFO", pa_callinfo
, 0},
681 {"code", pa_code
, 0},
682 {"CODE", pa_code
, 0},
683 {"comm", pa_comm
, 0},
684 {"COMM", pa_comm
, 0},
685 {"copyright", pa_copyright
, 0},
686 {"COPYRIGHT", pa_copyright
, 0},
687 {"data", pa_data
, 0},
688 {"DATA", pa_data
, 0},
689 {"desc", pa_desc
, 0},
690 {"DESC", pa_desc
, 0},
691 {"double", pa_float_cons
, 'd'},
692 {"DOUBLE", pa_float_cons
, 'd'},
695 {"enter", pa_enter
, 0},
696 {"ENTER", pa_enter
, 0},
697 {"entry", pa_entry
, 0},
698 {"ENTRY", pa_entry
, 0},
701 {"exit", pa_exit
, 0},
702 {"EXIT", pa_exit
, 0},
703 {"export", pa_export
, 0},
704 {"EXPORT", pa_export
, 0},
705 {"fill", pa_fill
, 0},
706 {"FILL", pa_fill
, 0},
707 {"float", pa_float_cons
, 'f'},
708 {"FLOAT", pa_float_cons
, 'f'},
709 {"half", pa_cons
, 2},
710 {"HALF", pa_cons
, 2},
711 {"import", pa_import
, 0},
712 {"IMPORT", pa_import
, 0},
715 {"label", pa_label
, 0},
716 {"LABEL", pa_label
, 0},
717 {"lcomm", pa_lcomm
, 0},
718 {"LCOMM", pa_lcomm
, 0},
719 {"leave", pa_leave
, 0},
720 {"LEAVE", pa_leave
, 0},
721 {"long", pa_cons
, 4},
722 {"LONG", pa_cons
, 4},
723 {"lsym", pa_lsym
, 0},
724 {"LSYM", pa_lsym
, 0},
725 {"octa", pa_cons
, 16},
726 {"OCTA", pa_cons
, 16},
727 {"org", pa_origin
, 0},
728 {"ORG", pa_origin
, 0},
729 {"origin", pa_origin
, 0},
730 {"ORIGIN", pa_origin
, 0},
731 {"param", pa_param
, 0},
732 {"PARAM", pa_param
, 0},
733 {"proc", pa_proc
, 0},
734 {"PROC", pa_proc
, 0},
735 {"procend", pa_procend
, 0},
736 {"PROCEND", pa_procend
, 0},
737 {"quad", pa_cons
, 8},
738 {"QUAD", pa_cons
, 8},
741 {"short", pa_cons
, 2},
742 {"SHORT", pa_cons
, 2},
743 {"single", pa_float_cons
, 'f'},
744 {"SINGLE", pa_float_cons
, 'f'},
745 {"space", pa_space
, 0},
746 {"SPACE", pa_space
, 0},
747 {"spnum", pa_spnum
, 0},
748 {"SPNUM", pa_spnum
, 0},
749 {"string", pa_stringer
, 0},
750 {"STRING", pa_stringer
, 0},
751 {"stringz", pa_stringer
, 1},
752 {"STRINGZ", pa_stringer
, 1},
753 {"subspa", pa_subspace
, 0},
754 {"SUBSPA", pa_subspace
, 0},
755 {"text", pa_text
, 0},
756 {"TEXT", pa_text
, 0},
757 {"version", pa_version
, 0},
758 {"VERSION", pa_version
, 0},
759 {"word", pa_cons
, 4},
760 {"WORD", pa_cons
, 4},
764 /* This array holds the chars that only start a comment at the beginning of
765 a line. If the line seems to have the form '# 123 filename'
766 .line and .file directives will appear in the pre-processed output.
768 Note that input_file.c hand checks for '#' at the beginning of the
769 first line of the input file. This is because the compiler outputs
770 #NO_APP at the beginning of its output.
772 Also note that '/*' will always start a comment. */
773 const char line_comment_chars
[] = "#";
775 /* This array holds the characters which act as line separators. */
776 const char line_separator_chars
[] = "!";
778 /* Chars that can be used to separate mant from exp in floating point nums. */
779 const char EXP_CHARS
[] = "eE";
781 /* Chars that mean this number is a floating point constant.
782 As in 0f12.456 or 0d1.2345e12.
784 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
785 changed in read.c. Ideally it shouldn't hae to know abou it at
786 all, but nothing is ideal around here. */
787 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
789 static struct pa_it the_insn
;
791 /* Points to the end of an expression just parsed by get_expressoin
792 and friends. FIXME. This shouldn't be handled with a file-global
794 static char *expr_end
;
796 /* Nonzero if a .callinfo appeared within the current procedure. */
797 static int callinfo_found
;
799 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
800 static int within_entry_exit
;
802 /* Nonzero if the assembler is currently within a procedure definition. */
803 static int within_procedure
;
805 /* Handle on strucutre which keep track of the last symbol
806 seen in each subspace. */
807 static label_symbol_struct
*label_symbols_rootp
= NULL
;
809 /* Holds the last field selector. */
810 static int hppa_field_selector
;
812 /* Nonzero if errors are to be printed. */
813 static int print_errors
= 1;
815 /* List of registers that are pre-defined:
817 Each general register has one predefined name of the form
818 %r<REGNUM> which has the value <REGNUM>.
820 Space and control registers are handled in a similar manner,
821 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
823 Likewise for the floating point registers, but of the form
824 %fr<REGNUM>. Floating point registers have additional predefined
825 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
826 again have the value <REGNUM>.
828 Many registers also have synonyms:
830 %r26 - %r23 have %arg0 - %arg3 as synonyms
831 %r28 - %r29 have %ret0 - %ret1 as synonyms
832 %r30 has %sp as a synonym
833 %r27 has %dp as a synonym
834 %r2 has %rp as a synonym
836 Almost every control register has a synonym; they are not listed
839 The table is sorted. Suitable for searching by a binary search. */
841 static const struct pd_reg pre_defined_registers
[] =
1053 /* This table is sorted by order of the length of the string. This is
1054 so we check for <> before we check for <. If we had a <> and checked
1055 for < first, we would get a false match. */
1056 static const struct fp_cond_map fp_cond_map
[] =
1092 static const struct selector_entry selector_table
[] =
1127 /* default space and subspace dictionaries */
1129 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1130 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1132 /* pre-defined subsegments (subspaces) for the HPPA. */
1133 #define SUBSEG_CODE 0
1134 #define SUBSEG_DATA 0
1135 #define SUBSEG_LIT 1
1136 #define SUBSEG_BSS 2
1137 #define SUBSEG_UNWIND 3
1138 #define SUBSEG_GDB_STRINGS 0
1139 #define SUBSEG_GDB_SYMBOLS 1
1141 static struct default_subspace_dict pa_def_subspaces
[] =
1143 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1144 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1145 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1146 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1148 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1150 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1153 static struct default_space_dict pa_def_spaces
[] =
1155 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1156 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1157 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1160 /* Misc local definitions used by the assembler. */
1162 /* Return nonzero if the string pointed to by S potentially represents
1163 a right or left half of a FP register */
1164 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1165 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1167 /* These macros are used to maintain spaces/subspaces. */
1168 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1169 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1170 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1171 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1172 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1173 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1174 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1175 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1177 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1178 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1179 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1180 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1181 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1182 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1183 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1184 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1185 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1186 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1187 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1188 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1189 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1190 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1192 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1193 main loop after insertion. */
1195 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1197 ((OPCODE) |= (FIELD) << (START)); \
1201 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1202 IGNORE is used to suppress the error message. */
1204 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1206 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1209 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1215 #define is_DP_relative(exp) \
1216 ((exp).X_op == O_subtract \
1217 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1219 #define is_PC_relative(exp) \
1220 ((exp).X_op == O_subtract \
1221 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1223 #define is_complex(exp) \
1224 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1226 /* Actual functions to implement the PA specific code for the assembler. */
1228 /* Returns a pointer to the label_symbol_struct for the current space.
1229 or NULL if no label_symbol_struct exists for the current space. */
1231 static label_symbol_struct
*
1234 label_symbol_struct
*label_chain
;
1235 sd_chain_struct
*space_chain
= current_space
;
1237 for (label_chain
= label_symbols_rootp
;
1239 label_chain
= label_chain
->lss_next
)
1240 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1246 /* Defines a label for the current space. If one is already defined,
1247 this function will replace it with the new label. */
1250 pa_define_label (symbol
)
1253 label_symbol_struct
*label_chain
= pa_get_label ();
1254 sd_chain_struct
*space_chain
= current_space
;
1257 label_chain
->lss_label
= symbol
;
1260 /* Create a new label entry and add it to the head of the chain. */
1262 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1263 label_chain
->lss_label
= symbol
;
1264 label_chain
->lss_space
= space_chain
;
1265 label_chain
->lss_next
= NULL
;
1267 if (label_symbols_rootp
)
1268 label_chain
->lss_next
= label_symbols_rootp
;
1270 label_symbols_rootp
= label_chain
;
1274 /* Removes a label definition for the current space.
1275 If there is no label_symbol_struct entry, then no action is taken. */
1278 pa_undefine_label ()
1280 label_symbol_struct
*label_chain
;
1281 label_symbol_struct
*prev_label_chain
= NULL
;
1282 sd_chain_struct
*space_chain
= current_space
;
1284 for (label_chain
= label_symbols_rootp
;
1286 label_chain
= label_chain
->lss_next
)
1288 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1290 /* Remove the label from the chain and free its memory. */
1291 if (prev_label_chain
)
1292 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1294 label_symbols_rootp
= label_chain
->lss_next
;
1299 prev_label_chain
= label_chain
;
1304 /* An HPPA-specific version of fix_new. This is required because the HPPA
1305 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1306 results in the creation of an instance of an hppa_fix_struct. An
1307 hppa_fix_struct stores the extra information along with a pointer to the
1308 original fixS. This is attached to the original fixup via the
1309 tc_fix_data field. */
1312 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1313 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1317 symbolS
*add_symbol
;
1321 bfd_reloc_code_real_type r_type
;
1322 enum hppa_reloc_field_selector_type r_field
;
1329 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1330 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1333 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1335 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1336 new_fix
->tc_fix_data
= hppa_fix
;
1337 hppa_fix
->fx_r_type
= r_type
;
1338 hppa_fix
->fx_r_field
= r_field
;
1339 hppa_fix
->fx_r_format
= r_format
;
1340 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1343 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1345 /* If necessary call BFD backend function to attach the
1346 unwind bits to the target dependent parts of a BFD symbol.
1348 #ifdef obj_attach_unwind_info
1349 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1353 /* foo-$global$ is used to access non-automatic storage. $global$
1354 is really just a marker and has served its purpose, so eliminate
1355 it now so as not to confuse write.c. */
1356 if (new_fix
->fx_subsy
1357 && !strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1358 new_fix
->fx_subsy
= NULL
;
1361 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1362 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1365 parse_cons_expression_hppa (exp
)
1368 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1372 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1373 hppa_field_selector is set by the parse_cons_expression_hppa. */
1376 cons_fix_new_hppa (frag
, where
, size
, exp
)
1382 unsigned int reloc_type
;
1384 if (is_DP_relative (*exp
))
1385 reloc_type
= R_HPPA_GOTOFF
;
1386 else if (is_complex (*exp
))
1387 reloc_type
= R_HPPA_COMPLEX
;
1389 reloc_type
= R_HPPA
;
1391 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1392 as_warn ("Invalid field selector. Assuming F%%.");
1394 fix_new_hppa (frag
, where
, size
,
1395 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1396 hppa_field_selector
, 32, 0, (char *) 0);
1398 /* Reset field selector to its default state. */
1399 hppa_field_selector
= 0;
1402 /* This function is called once, at assembler startup time. It should
1403 set up all the tables, etc. that the MD part of the assembler will need. */
1408 const char *retval
= NULL
;
1412 last_call_info
= NULL
;
1413 call_info_root
= NULL
;
1415 /* Folding of text and data segments fails miserably on the PA.
1416 Warn user and disable "-R" option. */
1419 as_warn ("-R option not supported on this target.");
1420 flag_readonly_data_in_text
= 0;
1426 op_hash
= hash_new ();
1427 if (op_hash
== NULL
)
1428 as_fatal ("Virtual memory exhausted");
1430 while (i
< NUMOPCODES
)
1432 const char *name
= pa_opcodes
[i
].name
;
1433 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*) &pa_opcodes
[i
]);
1434 if (retval
!= NULL
&& *retval
!= '\0')
1436 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1441 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1442 != pa_opcodes
[i
].match
)
1444 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1445 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1450 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1454 as_fatal ("Broken assembler. No assembly attempted.");
1456 /* SOM will change text_section. To make sure we never put
1457 anything into the old one switch to the new one now. */
1458 subseg_set (text_section
, 0);
1461 /* Called at the end of assembling a source file. Nothing to do
1462 at this point on the PA. */
1470 /* Assemble a single instruction storing it into a frag. */
1477 /* The had better be something to assemble. */
1480 /* Assemble the instruction. Results are saved into "the_insn". */
1483 /* Get somewhere to put the assembled instrution. */
1486 /* Output the opcode. */
1487 md_number_to_chars (to
, the_insn
.opcode
, 4);
1489 /* If necessary output more stuff. */
1490 if (the_insn
.reloc
!= R_HPPA_NONE
)
1491 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1492 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1493 the_insn
.reloc
, the_insn
.field_selector
,
1494 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1498 /* Do the real work for assembling a single instruction. Store results
1499 into the global "the_insn" variable.
1501 FIXME: Should define and use some functions/macros to handle
1502 various common insertions of information into the opcode. */
1508 char *error_message
= "";
1509 char *s
, c
, *argstart
, *name
, *save_s
;
1513 int cmpltr
, nullif
, flag
, cond
, num
;
1514 unsigned long opcode
;
1515 struct pa_opcode
*insn
;
1517 /* Skip to something interesting. */
1518 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1537 as_bad ("Unknown opcode: `%s'", str
);
1543 /* Convert everything into lower case. */
1546 if (isupper (*save_s
))
1547 *save_s
= tolower (*save_s
);
1551 /* Look up the opcode in the has table. */
1552 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1554 as_bad ("Unknown opcode: `%s'", str
);
1563 /* Mark the location where arguments for the instruction start, then
1564 start processing them. */
1568 /* Do some initialization. */
1569 opcode
= insn
->match
;
1570 bzero (&the_insn
, sizeof (the_insn
));
1572 the_insn
.reloc
= R_HPPA_NONE
;
1574 /* Build the opcode, checking as we go to make
1575 sure that the operands match. */
1576 for (args
= insn
->args
;; ++args
)
1581 /* End of arguments. */
1597 /* These must match exactly. */
1606 /* Handle a 5 bit register or control register field at 10. */
1609 num
= pa_parse_number (&s
, 0);
1610 CHECK_FIELD (num
, 31, 0, 0);
1611 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1613 /* Handle a 5 bit register field at 15. */
1615 num
= pa_parse_number (&s
, 0);
1616 CHECK_FIELD (num
, 31, 0, 0);
1617 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1619 /* Handle a 5 bit register field at 31. */
1622 num
= pa_parse_number (&s
, 0);
1623 CHECK_FIELD (num
, 31, 0, 0);
1624 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1626 /* Handle a 5 bit field length at 31. */
1628 num
= pa_get_absolute_expression (&the_insn
, &s
);
1630 CHECK_FIELD (num
, 32, 1, 0);
1631 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1633 /* Handle a 5 bit immediate at 15. */
1635 num
= pa_get_absolute_expression (&the_insn
, &s
);
1637 CHECK_FIELD (num
, 15, -16, 0);
1638 low_sign_unext (num
, 5, &num
);
1639 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1641 /* Handle a 5 bit immediate at 31. */
1643 num
= pa_get_absolute_expression (&the_insn
, &s
);
1645 CHECK_FIELD (num
, 15, -16, 0)
1646 low_sign_unext (num
, 5, &num
);
1647 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1649 /* Handle an unsigned 5 bit immediate at 31. */
1651 num
= pa_get_absolute_expression (&the_insn
, &s
);
1653 CHECK_FIELD (num
, 31, 0, 0);
1654 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1656 /* Handle an unsigned 5 bit immediate at 15. */
1658 num
= pa_get_absolute_expression (&the_insn
, &s
);
1660 CHECK_FIELD (num
, 31, 0, 0);
1661 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1663 /* Handle a 2 bit space identifier at 17. */
1665 num
= pa_parse_number (&s
, 0);
1666 CHECK_FIELD (num
, 3, 0, 1);
1667 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1669 /* Handle a 3 bit space identifier at 18. */
1671 num
= pa_parse_number (&s
, 0);
1672 CHECK_FIELD (num
, 7, 0, 1);
1673 dis_assemble_3 (num
, &num
);
1674 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1676 /* Handle a completer for an indexing load or store. */
1682 while (*s
== ',' && i
< 2)
1685 if (strncasecmp (s
, "sm", 2) == 0)
1692 else if (strncasecmp (s
, "m", 1) == 0)
1694 else if (strncasecmp (s
, "s", 1) == 0)
1697 as_bad ("Invalid Indexed Load Completer.");
1702 as_bad ("Invalid Indexed Load Completer Syntax.");
1704 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1707 /* Handle a short load/store completer. */
1715 if (strncasecmp (s
, "ma", 2) == 0)
1720 else if (strncasecmp (s
, "mb", 2) == 0)
1726 as_bad ("Invalid Short Load/Store Completer.");
1730 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1733 /* Handle a stbys completer. */
1739 while (*s
== ',' && i
< 2)
1742 if (strncasecmp (s
, "m", 1) == 0)
1744 else if (strncasecmp (s
, "b", 1) == 0)
1746 else if (strncasecmp (s
, "e", 1) == 0)
1749 as_bad ("Invalid Store Bytes Short Completer");
1754 as_bad ("Invalid Store Bytes Short Completer");
1756 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1759 /* Handle a non-negated compare/stubtract condition. */
1761 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1764 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1767 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1769 /* Handle a negated or non-negated compare/subtract condition. */
1772 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1776 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1779 as_bad ("Invalid Compare/Subtract Condition.");
1784 /* Negated condition requires an opcode change. */
1788 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1790 /* Handle a negated or non-negated add condition. */
1793 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1797 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1800 as_bad ("Invalid Compare/Subtract Condition");
1805 /* Negated condition requires an opcode change. */
1809 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1811 /* Handle a compare/subtract condition. */
1818 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1823 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1826 as_bad ("Invalid Compare/Subtract Condition");
1830 opcode
|= cmpltr
<< 13;
1831 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1833 /* Handle a non-negated add condition. */
1842 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1846 if (strcmp (name
, "=") == 0)
1848 else if (strcmp (name
, "<") == 0)
1850 else if (strcmp (name
, "<=") == 0)
1852 else if (strcasecmp (name
, "nuv") == 0)
1854 else if (strcasecmp (name
, "znv") == 0)
1856 else if (strcasecmp (name
, "sv") == 0)
1858 else if (strcasecmp (name
, "od") == 0)
1860 else if (strcasecmp (name
, "n") == 0)
1862 else if (strcasecmp (name
, "tr") == 0)
1867 else if (strcasecmp (name
, "<>") == 0)
1872 else if (strcasecmp (name
, ">=") == 0)
1877 else if (strcasecmp (name
, ">") == 0)
1882 else if (strcasecmp (name
, "uv") == 0)
1887 else if (strcasecmp (name
, "vnz") == 0)
1892 else if (strcasecmp (name
, "nsv") == 0)
1897 else if (strcasecmp (name
, "ev") == 0)
1903 as_bad ("Invalid Add Condition: %s", name
);
1906 nullif
= pa_parse_nullif (&s
);
1907 opcode
|= nullif
<< 1;
1908 opcode
|= cmpltr
<< 13;
1909 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1911 /* HANDLE a logical instruction condition. */
1919 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1923 if (strcmp (name
, "=") == 0)
1925 else if (strcmp (name
, "<") == 0)
1927 else if (strcmp (name
, "<=") == 0)
1929 else if (strcasecmp (name
, "od") == 0)
1931 else if (strcasecmp (name
, "tr") == 0)
1936 else if (strcmp (name
, "<>") == 0)
1941 else if (strcmp (name
, ">=") == 0)
1946 else if (strcmp (name
, ">") == 0)
1951 else if (strcasecmp (name
, "ev") == 0)
1957 as_bad ("Invalid Logical Instruction Condition.");
1960 opcode
|= cmpltr
<< 13;
1961 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1963 /* Handle a unit instruction condition. */
1970 if (strncasecmp (s
, "sbz", 3) == 0)
1975 else if (strncasecmp (s
, "shz", 3) == 0)
1980 else if (strncasecmp (s
, "sdc", 3) == 0)
1985 else if (strncasecmp (s
, "sbc", 3) == 0)
1990 else if (strncasecmp (s
, "shc", 3) == 0)
1995 else if (strncasecmp (s
, "tr", 2) == 0)
2001 else if (strncasecmp (s
, "nbz", 3) == 0)
2007 else if (strncasecmp (s
, "nhz", 3) == 0)
2013 else if (strncasecmp (s
, "ndc", 3) == 0)
2019 else if (strncasecmp (s
, "nbc", 3) == 0)
2025 else if (strncasecmp (s
, "nhc", 3) == 0)
2032 as_bad ("Invalid Logical Instruction Condition.");
2034 opcode
|= cmpltr
<< 13;
2035 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2037 /* Handle a shift/extract/deposit condition. */
2045 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2049 if (strcmp (name
, "=") == 0)
2051 else if (strcmp (name
, "<") == 0)
2053 else if (strcasecmp (name
, "od") == 0)
2055 else if (strcasecmp (name
, "tr") == 0)
2057 else if (strcmp (name
, "<>") == 0)
2059 else if (strcmp (name
, ">=") == 0)
2061 else if (strcasecmp (name
, "ev") == 0)
2063 /* Handle movb,n. Put things back the way they were.
2064 This includes moving s back to where it started. */
2065 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
2072 as_bad ("Invalid Shift/Extract/Deposit Condition.");
2075 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2077 /* Handle bvb and bb conditions. */
2083 if (strncmp (s
, "<", 1) == 0)
2088 else if (strncmp (s
, ">=", 2) == 0)
2094 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2096 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2098 /* Handle a system control completer. */
2100 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2108 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2110 /* Handle a nullification completer for branch instructions. */
2112 nullif
= pa_parse_nullif (&s
);
2113 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2115 /* Handle a 11 bit immediate at 31. */
2117 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2120 if (the_insn
.exp
.X_op
== O_constant
)
2122 num
= evaluate_absolute (&the_insn
);
2123 CHECK_FIELD (num
, 1023, -1024, 0);
2124 low_sign_unext (num
, 11, &num
);
2125 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2129 if (is_DP_relative (the_insn
.exp
))
2130 the_insn
.reloc
= R_HPPA_GOTOFF
;
2131 else if (is_PC_relative (the_insn
.exp
))
2132 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2133 else if (is_complex (the_insn
.exp
))
2134 the_insn
.reloc
= R_HPPA_COMPLEX
;
2136 the_insn
.reloc
= R_HPPA
;
2137 the_insn
.format
= 11;
2141 /* Handle a 14 bit immediate at 31. */
2143 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2146 if (the_insn
.exp
.X_op
== O_constant
)
2148 num
= evaluate_absolute (&the_insn
);
2149 CHECK_FIELD (num
, 8191, -8192, 0);
2150 low_sign_unext (num
, 14, &num
);
2151 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2155 if (is_DP_relative (the_insn
.exp
))
2156 the_insn
.reloc
= R_HPPA_GOTOFF
;
2157 else if (is_PC_relative (the_insn
.exp
))
2158 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2159 else if (is_complex (the_insn
.exp
))
2160 the_insn
.reloc
= R_HPPA_COMPLEX
;
2162 the_insn
.reloc
= R_HPPA
;
2163 the_insn
.format
= 14;
2167 /* Handle a 21 bit immediate at 31. */
2169 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2172 if (the_insn
.exp
.X_op
== O_constant
)
2174 num
= evaluate_absolute (&the_insn
);
2175 CHECK_FIELD (num
>> 11, 1048575, -1048576, 0);
2176 dis_assemble_21 (num
, &num
);
2177 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2181 if (is_DP_relative (the_insn
.exp
))
2182 the_insn
.reloc
= R_HPPA_GOTOFF
;
2183 else if (is_PC_relative (the_insn
.exp
))
2184 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2185 else if (is_complex (the_insn
.exp
))
2186 the_insn
.reloc
= R_HPPA_COMPLEX
;
2188 the_insn
.reloc
= R_HPPA
;
2189 the_insn
.format
= 21;
2193 /* Handle a 12 bit branch displacement. */
2195 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2199 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2201 unsigned int w1
, w
, result
;
2203 num
= evaluate_absolute (&the_insn
);
2206 as_bad ("Branch to unaligned address");
2209 CHECK_FIELD (num
, 8191, -8192, 0);
2210 sign_unext ((num
- 8) >> 2, 12, &result
);
2211 dis_assemble_12 (result
, &w1
, &w
);
2212 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2216 if (is_complex (the_insn
.exp
))
2217 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2219 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2220 the_insn
.format
= 12;
2221 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2222 bzero (&last_call_desc
, sizeof (struct call_desc
));
2227 /* Handle a 17 bit branch displacement. */
2229 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2233 if (!the_insn
.exp
.X_add_symbol
2234 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2237 unsigned int w2
, w1
, w
, result
;
2239 num
= evaluate_absolute (&the_insn
);
2242 as_bad ("Branch to unaligned address");
2245 CHECK_FIELD (num
, 262143, -262144, 0);
2247 if (the_insn
.exp
.X_add_symbol
)
2250 sign_unext (num
>> 2, 17, &result
);
2251 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2252 INSERT_FIELD_AND_CONTINUE (opcode
,
2253 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2257 if (is_complex (the_insn
.exp
))
2258 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2260 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2261 the_insn
.format
= 17;
2262 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2263 bzero (&last_call_desc
, sizeof (struct call_desc
));
2267 /* Handle an absolute 17 bit branch target. */
2269 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2273 if (!the_insn
.exp
.X_add_symbol
2274 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2277 unsigned int w2
, w1
, w
, result
;
2279 num
= evaluate_absolute (&the_insn
);
2282 as_bad ("Branch to unaligned address");
2285 CHECK_FIELD (num
, 262143, -262144, 0);
2287 if (the_insn
.exp
.X_add_symbol
)
2290 sign_unext (num
>> 2, 17, &result
);
2291 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2292 INSERT_FIELD_AND_CONTINUE (opcode
,
2293 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2297 if (is_complex (the_insn
.exp
))
2298 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2300 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2301 the_insn
.format
= 17;
2305 /* Handle a 5 bit shift count at 26. */
2307 num
= pa_get_absolute_expression (&the_insn
, &s
);
2309 CHECK_FIELD (num
, 31, 0, 0);
2310 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2312 /* Handle a 5 bit bit position at 26. */
2314 num
= pa_get_absolute_expression (&the_insn
, &s
);
2316 CHECK_FIELD (num
, 31, 0, 0);
2317 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2319 /* Handle a 5 bit immediate at 10. */
2321 num
= pa_get_absolute_expression (&the_insn
, &s
);
2323 CHECK_FIELD (num
, 31, 0, 0);
2324 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2326 /* Handle a 13 bit immediate at 18. */
2328 num
= pa_get_absolute_expression (&the_insn
, &s
);
2330 CHECK_FIELD (num
, 4095, -4096, 0);
2331 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2333 /* Handle a 26 bit immediate at 31. */
2335 num
= pa_get_absolute_expression (&the_insn
, &s
);
2337 CHECK_FIELD (num
, 671108864, 0, 0);
2338 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2340 /* Handle a 3 bit SFU identifier at 25. */
2342 num
= pa_get_absolute_expression (&the_insn
, &s
);
2344 CHECK_FIELD (num
, 7, 0, 0);
2345 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2347 /* We don't support any of these. FIXME. */
2354 /* Handle a source FP operand format completer. */
2356 flag
= pa_parse_fp_format (&s
);
2357 the_insn
.fpof1
= flag
;
2358 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2360 /* Handle a destination FP operand format completer. */
2362 /* pa_parse_format needs the ',' prefix. */
2364 flag
= pa_parse_fp_format (&s
);
2365 the_insn
.fpof2
= flag
;
2366 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2368 /* Handle FP compare conditions. */
2370 cond
= pa_parse_fp_cmp_cond (&s
);
2371 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2373 /* Handle L/R register halves like 't'. */
2376 struct pa_89_fp_reg_struct result
;
2378 pa_parse_number (&s
, &result
);
2379 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2380 opcode
|= result
.number_part
;
2382 /* 0x30 opcodes are FP arithmetic operation opcodes
2383 and need to be turned into 0x38 opcodes. This
2384 is not necessary for loads/stores. */
2385 if (need_89_opcode (&the_insn
, &result
)
2386 && ((opcode
& 0xfc000000) == 0x30000000))
2389 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2392 /* Handle L/R register halves like 'b'. */
2395 struct pa_89_fp_reg_struct result
;
2397 pa_parse_number (&s
, &result
);
2398 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2399 opcode
|= result
.number_part
<< 21;
2400 if (need_89_opcode (&the_insn
, &result
))
2402 opcode
|= (result
.l_r_select
& 1) << 7;
2408 /* Handle L/R register halves like 'x'. */
2411 struct pa_89_fp_reg_struct result
;
2413 pa_parse_number (&s
, &result
);
2414 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2415 opcode
|= (result
.number_part
& 0x1f) << 16;
2416 if (need_89_opcode (&the_insn
, &result
))
2418 opcode
|= (result
.l_r_select
& 1) << 12;
2424 /* Handle a 5 bit register field at 10. */
2427 struct pa_89_fp_reg_struct result
;
2429 pa_parse_number (&s
, &result
);
2430 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2431 if (the_insn
.fpof1
== SGL
)
2433 result
.number_part
&= 0xF;
2434 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2436 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2439 /* Handle a 5 bit register field at 15. */
2442 struct pa_89_fp_reg_struct result
;
2444 pa_parse_number (&s
, &result
);
2445 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2446 if (the_insn
.fpof1
== SGL
)
2448 result
.number_part
&= 0xF;
2449 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2451 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2454 /* Handle a 5 bit register field at 31. */
2457 struct pa_89_fp_reg_struct result
;
2459 pa_parse_number (&s
, &result
);
2460 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2461 if (the_insn
.fpof1
== SGL
)
2463 result
.number_part
&= 0xF;
2464 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2466 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2469 /* Handle a 5 bit register field at 20. */
2472 struct pa_89_fp_reg_struct result
;
2474 pa_parse_number (&s
, &result
);
2475 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2476 if (the_insn
.fpof1
== SGL
)
2478 result
.number_part
&= 0xF;
2479 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2481 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2484 /* Handle a 5 bit register field at 25. */
2487 struct pa_89_fp_reg_struct result
;
2489 pa_parse_number (&s
, &result
);
2490 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2491 if (the_insn
.fpof1
== SGL
)
2493 result
.number_part
&= 0xF;
2494 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2496 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2499 /* Handle a floating point operand format at 26.
2500 Only allows single and double precision. */
2502 flag
= pa_parse_fp_format (&s
);
2508 the_insn
.fpof1
= flag
;
2514 as_bad ("Invalid Floating Point Operand Format.");
2524 /* Check if the args matched. */
2527 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2528 && !strcmp (insn
->name
, insn
[1].name
))
2536 as_bad ("Invalid operands %s", error_message
);
2543 the_insn
.opcode
= opcode
;
2547 /* Turn a string in input_line_pointer into a floating point constant of type
2548 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2549 emitted is stored in *sizeP . An error message or NULL is returned. */
2551 #define MAX_LITTLENUMS 6
2554 md_atof (type
, litP
, sizeP
)
2560 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2561 LITTLENUM_TYPE
*wordP
;
2593 return "Bad call to MD_ATOF()";
2595 t
= atof_ieee (input_line_pointer
, type
, words
);
2597 input_line_pointer
= t
;
2598 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2599 for (wordP
= words
; prec
--;)
2601 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2602 litP
+= sizeof (LITTLENUM_TYPE
);
2607 /* Write out big-endian. */
2610 md_number_to_chars (buf
, val
, n
)
2615 number_to_chars_bigendian (buf
, val
, n
);
2618 /* Translate internal representation of relocation info to BFD target
2622 tc_gen_reloc (section
, fixp
)
2627 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2628 bfd_reloc_code_real_type code
;
2629 static int unwind_reloc_fixp_cnt
= 0;
2630 static arelent
*unwind_reloc_entryP
= NULL
;
2631 static arelent
*no_relocs
= NULL
;
2633 bfd_reloc_code_real_type
**codes
;
2637 if (fixp
->fx_addsy
== 0)
2639 assert (hppa_fixp
!= 0);
2640 assert (section
!= 0);
2643 /* Yuk. I would really like to push all this ELF specific unwind
2644 crud into BFD and the linker. That's how SOM does it -- and
2645 if we could make ELF emulate that then we could share more code
2646 in GAS (and potentially a gnu-linker later).
2648 Unwind section relocations are handled in a special way.
2649 The relocations for the .unwind section are originally
2650 built in the usual way. That is, for each unwind table
2651 entry there are two relocations: one for the beginning of
2652 the function and one for the end.
2654 The first time we enter this function we create a
2655 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2656 of the relocation is initialized to 0. Each additional
2657 pair of times this function is called for the unwind
2658 section represents an additional unwind table entry. Thus,
2659 the addend of the relocation should end up to be the number
2660 of unwind table entries. */
2661 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2663 if (unwind_reloc_entryP
== NULL
)
2665 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2667 assert (reloc
!= 0);
2668 unwind_reloc_entryP
= reloc
;
2669 unwind_reloc_fixp_cnt
++;
2670 unwind_reloc_entryP
->address
2671 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2672 /* A pointer to any function will do. We only
2673 need one to tell us what section the unwind
2674 relocations are for. */
2675 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2676 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2677 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2678 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2679 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2680 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2681 sizeof (arelent
*) * 2);
2682 assert (relocs
!= 0);
2683 relocs
[0] = unwind_reloc_entryP
;
2687 unwind_reloc_fixp_cnt
++;
2688 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2694 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2695 assert (reloc
!= 0);
2697 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2698 codes
= hppa_gen_reloc_type (stdoutput
,
2700 hppa_fixp
->fx_r_format
,
2701 hppa_fixp
->fx_r_field
);
2703 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2706 relocs
= (arelent
**)
2707 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2708 assert (relocs
!= 0);
2710 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2711 sizeof (arelent
) * n_relocs
);
2713 assert (reloc
!= 0);
2715 for (i
= 0; i
< n_relocs
; i
++)
2716 relocs
[i
] = &reloc
[i
];
2718 relocs
[n_relocs
] = NULL
;
2721 switch (fixp
->fx_r_type
)
2723 case R_HPPA_COMPLEX
:
2724 case R_HPPA_COMPLEX_PCREL_CALL
:
2725 case R_HPPA_COMPLEX_ABS_CALL
:
2726 assert (n_relocs
== 5);
2728 for (i
= 0; i
< n_relocs
; i
++)
2730 reloc
[i
].sym_ptr_ptr
= NULL
;
2731 reloc
[i
].address
= 0;
2732 reloc
[i
].addend
= 0;
2733 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2734 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2737 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2738 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2739 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2741 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2742 reloc
[3].addend
= fixp
->fx_addnumber
;
2743 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2744 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2745 reloc
[1].addend
= fixp
->fx_addnumber
;
2750 assert (n_relocs
== 1);
2754 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2755 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2756 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2757 reloc
->addend
= 0; /* default */
2759 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2761 /* Now, do any processing that is dependent on the relocation type. */
2764 case R_HPPA_PLABEL_32
:
2765 case R_HPPA_PLABEL_11
:
2766 case R_HPPA_PLABEL_14
:
2767 case R_HPPA_PLABEL_L21
:
2768 case R_HPPA_PLABEL_R11
:
2769 case R_HPPA_PLABEL_R14
:
2770 /* For plabel relocations, the addend of the
2771 relocation should be either 0 (no static link) or 2
2772 (static link required).
2774 FIXME: We always assume no static link! */
2778 case R_HPPA_ABS_CALL_11
:
2779 case R_HPPA_ABS_CALL_14
:
2780 case R_HPPA_ABS_CALL_17
:
2781 case R_HPPA_ABS_CALL_L21
:
2782 case R_HPPA_ABS_CALL_R11
:
2783 case R_HPPA_ABS_CALL_R14
:
2784 case R_HPPA_ABS_CALL_R17
:
2785 case R_HPPA_ABS_CALL_LS21
:
2786 case R_HPPA_ABS_CALL_RS11
:
2787 case R_HPPA_ABS_CALL_RS14
:
2788 case R_HPPA_ABS_CALL_RS17
:
2789 case R_HPPA_ABS_CALL_LD21
:
2790 case R_HPPA_ABS_CALL_RD11
:
2791 case R_HPPA_ABS_CALL_RD14
:
2792 case R_HPPA_ABS_CALL_RD17
:
2793 case R_HPPA_ABS_CALL_LR21
:
2794 case R_HPPA_ABS_CALL_RR14
:
2795 case R_HPPA_ABS_CALL_RR17
:
2797 case R_HPPA_PCREL_CALL_11
:
2798 case R_HPPA_PCREL_CALL_14
:
2799 case R_HPPA_PCREL_CALL_17
:
2800 case R_HPPA_PCREL_CALL_L21
:
2801 case R_HPPA_PCREL_CALL_R11
:
2802 case R_HPPA_PCREL_CALL_R14
:
2803 case R_HPPA_PCREL_CALL_R17
:
2804 case R_HPPA_PCREL_CALL_LS21
:
2805 case R_HPPA_PCREL_CALL_RS11
:
2806 case R_HPPA_PCREL_CALL_RS14
:
2807 case R_HPPA_PCREL_CALL_RS17
:
2808 case R_HPPA_PCREL_CALL_LD21
:
2809 case R_HPPA_PCREL_CALL_RD11
:
2810 case R_HPPA_PCREL_CALL_RD14
:
2811 case R_HPPA_PCREL_CALL_RD17
:
2812 case R_HPPA_PCREL_CALL_LR21
:
2813 case R_HPPA_PCREL_CALL_RR14
:
2814 case R_HPPA_PCREL_CALL_RR17
:
2815 /* The constant is stored in the instruction. */
2816 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2819 reloc
->addend
= fixp
->fx_addnumber
;
2826 /* Preliminary relocation handling for SOM. Needs to handle
2827 COMPLEX relocations (yes, I've seen them occur) and it will
2828 need to handle R_ENTRY/R_EXIT relocations in the very near future
2829 (for generating unwinds). */
2830 switch (fixp
->fx_r_type
)
2832 case R_HPPA_COMPLEX
:
2833 case R_HPPA_COMPLEX_PCREL_CALL
:
2834 case R_HPPA_COMPLEX_ABS_CALL
:
2838 assert (n_relocs
== 1);
2842 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2843 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2844 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2850 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2855 /* For plabel relocations, the addend of the
2856 relocation should be either 0 (no static link) or 2
2857 (static link required).
2859 FIXME: We always assume no static link! */
2864 reloc
->addend
= fixp
->fx_addnumber
;
2874 /* Process any machine dependent frag types. */
2877 md_convert_frag (abfd
, sec
, fragP
)
2879 register asection
*sec
;
2880 register fragS
*fragP
;
2882 unsigned int address
;
2884 if (fragP
->fr_type
== rs_machine_dependent
)
2886 switch ((int) fragP
->fr_subtype
)
2889 fragP
->fr_type
= rs_fill
;
2890 know (fragP
->fr_var
== 1);
2891 know (fragP
->fr_next
);
2892 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2893 if (address
% fragP
->fr_offset
)
2896 fragP
->fr_next
->fr_address
2901 fragP
->fr_offset
= 0;
2907 /* Round up a section size to the appropriate boundary. */
2910 md_section_align (segment
, size
)
2914 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2915 int align2
= (1 << align
) - 1;
2917 return (size
+ align2
) & ~align2
;
2921 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2923 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2925 addressT from_addr
, to_addr
;
2929 fprintf (stderr
, "pa_create_short_jmp\n");
2933 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2935 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2937 addressT from_addr
, to_addr
;
2941 fprintf (stderr
, "pa_create_long_jump\n");
2945 /* Return the approximate size of a frag before relaxation has occurred. */
2947 md_estimate_size_before_relax (fragP
, segment
)
2948 register fragS
*fragP
;
2955 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2961 /* Parse machine dependent options. There are none on the PA. */
2963 md_parse_option (argP
, cntP
, vecP
)
2971 /* We have no need to default values of symbols. */
2974 md_undefined_symbol (name
)
2980 /* Parse an operand that is machine-specific.
2981 We just return without modifying the expression as we have nothing
2985 md_operand (expressionP
)
2986 expressionS
*expressionP
;
2990 /* Apply a fixup to an instruction. */
2993 md_apply_fix (fixP
, valp
)
2997 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2998 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
2999 long new_val
, result
;
3000 unsigned int w1
, w2
, w
;
3003 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3004 never be "applied" (they are just markers). */
3006 if (fixP
->fx_r_type
== R_HPPA_ENTRY
3007 || fixP
->fx_r_type
== R_HPPA_EXIT
)
3011 /* There should have been an HPPA specific fixup associated
3012 with the GAS fixup. */
3015 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3016 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3018 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3021 /* Remember this value for emit_reloc. FIXME, is this braindamage
3022 documented anywhere!?! */
3023 fixP
->fx_addnumber
= val
;
3025 /* Check if this is an undefined symbol. No relocation can
3026 possibly be performed in this case. */
3027 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3029 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3032 /* PLABEL field selectors should not be passed to hppa_field_adjust. */
3033 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
3034 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
3035 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
)
3036 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3042 /* Handle all opcodes with the 'j' operand type. */
3044 CHECK_FIELD (new_val
, 8191, -8192, 0);
3046 /* Mask off 14 bits to be changed. */
3047 bfd_put_32 (stdoutput
,
3048 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3050 low_sign_unext (new_val
, 14, &result
);
3053 /* Handle all opcodes with the 'k' operand type. */
3055 CHECK_FIELD (new_val
, 2097152, 0, 0);
3057 /* Mask off 21 bits to be changed. */
3058 bfd_put_32 (stdoutput
,
3059 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3061 dis_assemble_21 (new_val
, &result
);
3064 /* Handle all the opcodes with the 'i' operand type. */
3066 CHECK_FIELD (new_val
, 1023, -1023, 0);
3068 /* Mask off 11 bits to be changed. */
3069 bfd_put_32 (stdoutput
,
3070 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3072 low_sign_unext (new_val
, 11, &result
);
3075 /* Handle all the opcodes with the 'w' operand type. */
3077 CHECK_FIELD (new_val
, 8191, -8192, 0)
3079 /* Mask off 11 bits to be changed. */
3080 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3081 bfd_put_32 (stdoutput
,
3082 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3085 dis_assemble_12 (result
, &w1
, &w
);
3086 result
= ((w1
<< 2) | w
);
3089 /* Handle some of the opcodes with the 'W' operand type. */
3092 #define stub_needed(CALLER, CALLEE) \
3093 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3094 /* It is necessary to force PC-relative calls/jumps to have a
3095 relocation entry if they're going to need either a argument
3096 relocation or long call stub. FIXME. Can't we need the same
3097 for absolute calls? */
3099 && (stub_needed (((obj_symbol_type
*)
3100 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3101 hppa_fixP
->fx_arg_reloc
)))
3105 CHECK_FIELD (new_val
, 262143, -262144, 0);
3107 /* Mask off 17 bits to be changed. */
3108 bfd_put_32 (stdoutput
,
3109 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3111 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3112 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3113 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3118 /* These are ELF specific relocations. ELF unfortunately
3119 handles unwinds in a completely different manner. */
3120 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3121 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3122 result
= fixP
->fx_addnumber
;
3127 fixP
->fx_addnumber
= fixP
->fx_offset
;
3128 bfd_put_32 (stdoutput
, 0, buf
);
3137 as_bad ("Unknown relocation encountered in md_apply_fix.");
3141 /* Insert the relocation. */
3142 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3147 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3148 (unsigned int) fixP
, fixP
->fx_r_type
);
3153 /* Exactly what point is a PC-relative offset relative TO?
3154 On the PA, they're relative to the address of the offset. */
3157 md_pcrel_from (fixP
)
3160 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3163 /* Return nonzero if the input line pointer is at the end of
3167 is_end_of_statement ()
3169 return ((*input_line_pointer
== '\n')
3170 || (*input_line_pointer
== ';')
3171 || (*input_line_pointer
== '!'));
3174 /* Read a number from S. The number might come in one of many forms,
3175 the most common will be a hex or decimal constant, but it could be
3176 a pre-defined register (Yuk!), or an absolute symbol.
3178 Return a number or -1 for failure.
3180 When parsing PA-89 FP register numbers RESULT will be
3181 the address of a structure to return information about
3182 L/R half of FP registers, store results there as appropriate.
3184 pa_parse_number can not handle negative constants and will fail
3185 horribly if it is passed such a constant. */
3188 pa_parse_number (s
, result
)
3190 struct pa_89_fp_reg_struct
*result
;
3199 /* Skip whitespace before the number. */
3200 while (*p
== ' ' || *p
== '\t')
3203 /* Store info in RESULT if requested by caller. */
3206 result
->number_part
= -1;
3207 result
->l_r_select
= -1;
3213 /* Looks like a number. */
3216 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3218 /* The number is specified in hex. */
3220 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3221 || ((*p
>= 'A') && (*p
<= 'F')))
3224 num
= num
* 16 + *p
- '0';
3225 else if (*p
>= 'a' && *p
<= 'f')
3226 num
= num
* 16 + *p
- 'a' + 10;
3228 num
= num
* 16 + *p
- 'A' + 10;
3234 /* The number is specified in decimal. */
3235 while (isdigit (*p
))
3237 num
= num
* 10 + *p
- '0';
3242 /* Store info in RESULT if requested by the caller. */
3245 result
->number_part
= num
;
3247 if (IS_R_SELECT (p
))
3249 result
->l_r_select
= 1;
3252 else if (IS_L_SELECT (p
))
3254 result
->l_r_select
= 0;
3258 result
->l_r_select
= 0;
3263 /* The number might be a predefined register. */
3268 /* Tege hack: Special case for general registers as the general
3269 code makes a binary search with case translation, and is VERY
3274 if (*p
== 'e' && *(p
+ 1) == 't'
3275 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3278 num
= *p
- '0' + 28;
3286 else if (!isdigit (*p
))
3289 as_bad ("Undefined register: '%s'.", name
);
3295 num
= num
* 10 + *p
++ - '0';
3296 while (isdigit (*p
));
3301 /* Do a normal register search. */
3302 while (is_part_of_name (c
))
3308 status
= reg_name_search (name
);
3314 as_bad ("Undefined register: '%s'.", name
);
3320 /* Store info in RESULT if requested by caller. */
3323 result
->number_part
= num
;
3324 if (IS_R_SELECT (p
- 1))
3325 result
->l_r_select
= 1;
3326 else if (IS_L_SELECT (p
- 1))
3327 result
->l_r_select
= 0;
3329 result
->l_r_select
= 0;
3334 /* And finally, it could be a symbol in the absolute section which
3335 is effectively a constant. */
3339 while (is_part_of_name (c
))
3345 if ((sym
= symbol_find (name
)) != NULL
)
3347 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3348 num
= S_GET_VALUE (sym
);
3352 as_bad ("Non-absolute symbol: '%s'.", name
);
3358 /* There is where we'd come for an undefined symbol
3359 or for an empty string. For an empty string we
3360 will return zero. That's a concession made for
3361 compatability with the braindamaged HP assemblers. */
3367 as_bad ("Undefined absolute constant: '%s'.", name
);
3373 /* Store info in RESULT if requested by caller. */
3376 result
->number_part
= num
;
3377 if (IS_R_SELECT (p
- 1))
3378 result
->l_r_select
= 1;
3379 else if (IS_L_SELECT (p
- 1))
3380 result
->l_r_select
= 0;
3382 result
->l_r_select
= 0;
3390 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3392 /* Given NAME, find the register number associated with that name, return
3393 the integer value associated with the given name or -1 on failure. */
3396 reg_name_search (name
)
3399 int middle
, low
, high
;
3402 high
= REG_NAME_CNT
- 1;
3406 middle
= (low
+ high
) / 2;
3407 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3412 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3415 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3416 return (pre_defined_registers
[middle
].value
);
3422 /* Return nonzero if the given INSN and L/R information will require
3423 a new PA-89 opcode. */
3426 need_89_opcode (insn
, result
)
3428 struct pa_89_fp_reg_struct
*result
;
3430 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3436 /* Parse a condition for a fcmp instruction. Return the numerical
3437 code associated with the condition. */
3440 pa_parse_fp_cmp_cond (s
)
3447 for (i
= 0; i
< 32; i
++)
3449 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3450 strlen (fp_cond_map
[i
].string
)) == 0)
3452 cond
= fp_cond_map
[i
].cond
;
3453 *s
+= strlen (fp_cond_map
[i
].string
);
3454 while (**s
== ' ' || **s
== '\t')
3460 as_bad ("Invalid FP Compare Condition: %c", **s
);
3464 /* Parse an FP operand format completer returning the completer
3467 static fp_operand_format
3468 pa_parse_fp_format (s
)
3477 if (strncasecmp (*s
, "sgl", 3) == 0)
3482 else if (strncasecmp (*s
, "dbl", 3) == 0)
3487 else if (strncasecmp (*s
, "quad", 4) == 0)
3494 format
= ILLEGAL_FMT
;
3495 as_bad ("Invalid FP Operand Format: %3s", *s
);
3502 /* Convert from a selector string into a selector type. */
3505 pa_chk_field_selector (str
)
3509 const struct selector_entry
*tablep
;
3513 /* Read past any whitespace. */
3514 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3517 /* Yuk. Looks like a linear search through the table. With the
3518 frequence of some selectors it might make sense to sort the
3520 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3522 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3524 *str
+= strlen (tablep
->prefix
);
3525 selector
= tablep
->field_selector
;
3532 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3535 get_expression (str
)
3541 save_in
= input_line_pointer
;
3542 input_line_pointer
= str
;
3543 seg
= expression (&the_insn
.exp
);
3544 if (!(seg
== absolute_section
3545 || seg
== undefined_section
3546 || SEG_NORMAL (seg
)))
3548 as_warn ("Bad segment in expression.");
3549 expr_end
= input_line_pointer
;
3550 input_line_pointer
= save_in
;
3553 expr_end
= input_line_pointer
;
3554 input_line_pointer
= save_in
;
3558 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3560 pa_get_absolute_expression (insn
, strp
)
3566 insn
->field_selector
= pa_chk_field_selector (strp
);
3567 save_in
= input_line_pointer
;
3568 input_line_pointer
= *strp
;
3569 expression (&insn
->exp
);
3570 if (insn
->exp
.X_op
!= O_constant
)
3572 as_bad ("Bad segment (should be absolute).");
3573 expr_end
= input_line_pointer
;
3574 input_line_pointer
= save_in
;
3577 expr_end
= input_line_pointer
;
3578 input_line_pointer
= save_in
;
3579 return evaluate_absolute (insn
);
3582 /* Evaluate an absolute expression EXP which may be modified by
3583 the selector FIELD_SELECTOR. Return the value of the expression. */
3585 evaluate_absolute (insn
)
3590 int field_selector
= insn
->field_selector
;
3593 value
= exp
.X_add_number
;
3595 switch (field_selector
)
3601 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3603 if (value
& 0x00000400)
3605 value
= (value
& 0xfffff800) >> 11;
3608 /* Sign extend from bit 21. */
3610 if (value
& 0x00000400)
3611 value
|= 0xfffff800;
3616 /* Arithmetic shift right 11 bits. */
3618 value
= (value
& 0xfffff800) >> 11;
3621 /* Set bits 0-20 to zero. */
3623 value
= value
& 0x7ff;
3626 /* Add 0x800 and arithmetic shift right 11 bits. */
3629 value
= (value
& 0xfffff800) >> 11;
3632 /* Set bitgs 0-21 to one. */
3634 value
|= 0xfffff800;
3637 #define RSEL_ROUND(c) (((c) + 0x1000) & ~0x1fff)
3639 value
= (RSEL_ROUND (value
) & 0x7ff) + (value
- RSEL_ROUND (value
));
3643 value
= (RSEL_ROUND (value
) >> 11) & 0x1fffff;
3648 BAD_CASE (field_selector
);
3654 /* Given an argument location specification return the associated
3655 argument location number. */
3658 pa_build_arg_reloc (type_name
)
3662 if (strncasecmp (type_name
, "no", 2) == 0)
3664 if (strncasecmp (type_name
, "gr", 2) == 0)
3666 else if (strncasecmp (type_name
, "fr", 2) == 0)
3668 else if (strncasecmp (type_name
, "fu", 2) == 0)
3671 as_bad ("Invalid argument location: %s\n", type_name
);
3676 /* Encode and return an argument relocation specification for
3677 the given register in the location specified by arg_reloc. */
3680 pa_align_arg_reloc (reg
, arg_reloc
)
3682 unsigned int arg_reloc
;
3684 unsigned int new_reloc
;
3686 new_reloc
= arg_reloc
;
3702 as_bad ("Invalid argument description: %d", reg
);
3708 /* Parse a PA nullification completer (,n). Return nonzero if the
3709 completer was found; return zero if no completer was found. */
3721 if (strncasecmp (*s
, "n", 1) == 0)
3725 as_bad ("Invalid Nullification: (%c)", **s
);
3734 /* Parse a non-negated compare/subtract completer returning the
3735 number (for encoding in instrutions) of the given completer.
3737 ISBRANCH specifies whether or not this is parsing a condition
3738 completer for a branch (vs a nullification completer for a
3739 computational instruction. */
3742 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3747 char *name
= *s
+ 1;
3755 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3759 if (strcmp (name
, "=") == 0)
3763 else if (strcmp (name
, "<") == 0)
3767 else if (strcmp (name
, "<=") == 0)
3771 else if (strcmp (name
, "<<") == 0)
3775 else if (strcmp (name
, "<<=") == 0)
3779 else if (strcasecmp (name
, "sv") == 0)
3783 else if (strcasecmp (name
, "od") == 0)
3787 /* If we have something like addb,n then there is no condition
3789 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3800 /* Reset pointers if this was really a ,n for a branch instruction. */
3801 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3807 /* Parse a negated compare/subtract completer returning the
3808 number (for encoding in instrutions) of the given completer.
3810 ISBRANCH specifies whether or not this is parsing a condition
3811 completer for a branch (vs a nullification completer for a
3812 computational instruction. */
3815 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3820 char *name
= *s
+ 1;
3828 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3832 if (strcasecmp (name
, "tr") == 0)
3836 else if (strcmp (name
, "<>") == 0)
3840 else if (strcmp (name
, ">=") == 0)
3844 else if (strcmp (name
, ">") == 0)
3848 else if (strcmp (name
, ">>=") == 0)
3852 else if (strcmp (name
, ">>") == 0)
3856 else if (strcasecmp (name
, "nsv") == 0)
3860 else if (strcasecmp (name
, "ev") == 0)
3864 /* If we have something like addb,n then there is no condition
3866 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3877 /* Reset pointers if this was really a ,n for a branch instruction. */
3878 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3884 /* Parse a non-negated addition completer returning the number
3885 (for encoding in instrutions) of the given completer.
3887 ISBRANCH specifies whether or not this is parsing a condition
3888 completer for a branch (vs a nullification completer for a
3889 computational instruction. */
3892 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3897 char *name
= *s
+ 1;
3905 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3909 if (strcmp (name
, "=") == 0)
3913 else if (strcmp (name
, "<") == 0)
3917 else if (strcmp (name
, "<=") == 0)
3921 else if (strcasecmp (name
, "nuv") == 0)
3925 else if (strcasecmp (name
, "znv") == 0)
3929 else if (strcasecmp (name
, "sv") == 0)
3933 else if (strcasecmp (name
, "od") == 0)
3937 /* If we have something like addb,n then there is no condition
3939 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3950 /* Reset pointers if this was really a ,n for a branch instruction. */
3951 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3957 /* Parse a negated addition completer returning the number
3958 (for encoding in instrutions) of the given completer.
3960 ISBRANCH specifies whether or not this is parsing a condition
3961 completer for a branch (vs a nullification completer for a
3962 computational instruction. */
3965 pa_parse_neg_add_cmpltr (s
, isbranch
)
3970 char *name
= *s
+ 1;
3978 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3982 if (strcasecmp (name
, "tr") == 0)
3986 else if (strcmp (name
, "<>") == 0)
3990 else if (strcmp (name
, ">=") == 0)
3994 else if (strcmp (name
, ">") == 0)
3998 else if (strcmp (name
, "uv") == 0)
4002 else if (strcmp (name
, "vnz") == 0)
4006 else if (strcasecmp (name
, "nsv") == 0)
4010 else if (strcasecmp (name
, "ev") == 0)
4014 /* If we have something like addb,n then there is no condition
4016 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4027 /* Reset pointers if this was really a ,n for a branch instruction. */
4028 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4034 /* Handle a .BLOCK type pseudo-op. */
4042 unsigned int temp_size
;
4045 temp_size
= get_absolute_expression ();
4047 /* Always fill with zeros, that's what the HP assembler does. */
4050 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4051 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4052 bzero (p
, temp_size
);
4054 /* Convert 2 bytes at a time. */
4056 for (i
= 0; i
< temp_size
; i
+= 2)
4058 md_number_to_chars (p
+ i
,
4060 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4063 pa_undefine_label ();
4064 demand_empty_rest_of_line ();
4068 /* Handle a .CALL pseudo-op. This involves storing away information
4069 about where arguments are to be found so the linker can detect
4070 (and correct) argument location mismatches between caller and callee. */
4076 pa_call_args (&last_call_desc
);
4077 demand_empty_rest_of_line ();
4081 /* Do the dirty work of building a call descriptor which describes
4082 where the caller placed arguments to a function call. */
4085 pa_call_args (call_desc
)
4086 struct call_desc
*call_desc
;
4089 unsigned int temp
, arg_reloc
;
4091 while (!is_end_of_statement ())
4093 name
= input_line_pointer
;
4094 c
= get_symbol_end ();
4095 /* Process a source argument. */
4096 if ((strncasecmp (name
, "argw", 4) == 0))
4098 temp
= atoi (name
+ 4);
4099 p
= input_line_pointer
;
4101 input_line_pointer
++;
4102 name
= input_line_pointer
;
4103 c
= get_symbol_end ();
4104 arg_reloc
= pa_build_arg_reloc (name
);
4105 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4107 /* Process a return value. */
4108 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4110 p
= input_line_pointer
;
4112 input_line_pointer
++;
4113 name
= input_line_pointer
;
4114 c
= get_symbol_end ();
4115 arg_reloc
= pa_build_arg_reloc (name
);
4116 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4120 as_bad ("Invalid .CALL argument: %s", name
);
4122 p
= input_line_pointer
;
4124 if (!is_end_of_statement ())
4125 input_line_pointer
++;
4129 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4132 is_same_frag (frag1
, frag2
)
4139 else if (frag2
== NULL
)
4141 else if (frag1
== frag2
)
4143 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4144 return (is_same_frag (frag1
, frag2
->fr_next
));
4150 /* Build an entry in the UNWIND subspace from the given function
4151 attributes in CALL_INFO. This is not needed for SOM as using
4152 R_ENTRY and R_EXIT relocations allow the linker to handle building
4153 of the unwind spaces. */
4156 pa_build_unwind_subspace (call_info
)
4157 struct call_info
*call_info
;
4160 asection
*seg
, *save_seg
;
4161 subsegT subseg
, save_subseg
;
4165 /* Get into the right seg/subseg. This may involve creating
4166 the seg the first time through. Make sure to have the
4167 old seg/subseg so that we can reset things when we are done. */
4168 subseg
= SUBSEG_UNWIND
;
4169 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4170 if (seg
== ASEC_NULL
)
4172 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4173 bfd_set_section_flags (stdoutput
, seg
,
4174 SEC_READONLY
| SEC_HAS_CONTENTS
4175 | SEC_LOAD
| SEC_RELOC
);
4179 save_subseg
= now_subseg
;
4180 subseg_set (seg
, subseg
);
4183 /* Get some space to hold relocation information for the unwind
4186 call_info
->start_offset_frag
= frag_now
;
4187 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4189 /* Relocation info. for start offset of the function. */
4190 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4191 call_info
->start_symbol
, (offsetT
) 0,
4192 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4195 /* We need to search for the first relocation involving the start_symbol of
4196 this call_info descriptor. */
4200 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4201 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4203 if (fixP
->fx_addsy
== call_info
->start_symbol
4204 || fixP
->fx_subsy
== call_info
->start_symbol
)
4206 call_info
->start_fix
= fixP
;
4213 call_info
->end_offset_frag
= frag_now
;
4214 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4216 /* Relocation info. for end offset of the function. */
4217 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4218 call_info
->end_symbol
, (offsetT
) 0,
4219 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4222 /* We need to search for the first relocation involving the end_symbol of
4223 this call_info descriptor. */
4227 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4228 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4230 if (fixP
->fx_addsy
== call_info
->end_symbol
4231 || fixP
->fx_subsy
== call_info
->end_symbol
)
4233 call_info
->end_fix
= fixP
;
4240 unwind
= (char *) &call_info
->ci_unwind
;
4241 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4245 FRAG_APPEND_1_CHAR (c
);
4249 /* Return back to the original segment/subsegment. */
4250 subseg_set (save_seg
, save_subseg
);
4254 /* Process a .CALLINFO pseudo-op. This information is used later
4255 to build unwind descriptors and maybe one day to support
4256 .ENTER and .LEAVE. */
4259 pa_callinfo (unused
)
4265 /* .CALLINFO must appear within a procedure definition. */
4266 if (!within_procedure
)
4267 as_bad (".callinfo is not within a procedure definition");
4269 /* Mark the fact that we found the .CALLINFO for the
4270 current procedure. */
4271 callinfo_found
= TRUE
;
4273 /* Iterate over the .CALLINFO arguments. */
4274 while (!is_end_of_statement ())
4276 name
= input_line_pointer
;
4277 c
= get_symbol_end ();
4278 /* Frame size specification. */
4279 if ((strncasecmp (name
, "frame", 5) == 0))
4281 p
= input_line_pointer
;
4283 input_line_pointer
++;
4284 temp
= get_absolute_expression ();
4285 if ((temp
& 0x3) != 0)
4287 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4291 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4292 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4295 /* Entry register (GR, GR and SR) specifications. */
4296 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4298 p
= input_line_pointer
;
4300 input_line_pointer
++;
4301 temp
= get_absolute_expression ();
4302 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4303 even though %r19 is caller saved. I think this is a bug in
4304 the HP assembler, and we are not going to emulate it. */
4305 if (temp
< 3 || temp
> 18)
4306 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4307 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4309 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4311 p
= input_line_pointer
;
4313 input_line_pointer
++;
4314 temp
= get_absolute_expression ();
4315 /* Similarly the HP assembler takes 31 as the high bound even
4316 though %fr21 is the last callee saved floating point register. */
4317 if (temp
< 12 || temp
> 21)
4318 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4319 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4321 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4323 p
= input_line_pointer
;
4325 input_line_pointer
++;
4326 temp
= get_absolute_expression ();
4328 as_bad ("Value for ENTRY_SR must be 3\n");
4329 last_call_info
->entry_sr
= temp
- 2;
4331 /* Note whether or not this function performs any calls. */
4332 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4333 (strncasecmp (name
, "caller", 6) == 0))
4335 p
= input_line_pointer
;
4337 last_call_info
->makes_calls
= 1;
4339 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4341 p
= input_line_pointer
;
4343 last_call_info
->makes_calls
= 0;
4345 /* Should RP be saved into the stack. */
4346 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4348 p
= input_line_pointer
;
4350 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4352 /* Likewise for SP. */
4353 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4355 p
= input_line_pointer
;
4357 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4359 /* Is this an unwindable procedure. If so mark it so
4360 in the unwind descriptor. */
4361 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4363 p
= input_line_pointer
;
4365 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4367 /* Is this an interrupt routine. If so mark it in the
4368 unwind descriptor. */
4369 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4371 p
= input_line_pointer
;
4373 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4377 as_bad ("Invalid .CALLINFO argument: %s", name
);
4379 if (!is_end_of_statement ())
4380 input_line_pointer
++;
4383 demand_empty_rest_of_line ();
4387 /* Switch into the code subspace. */
4393 sd_chain_struct
*sdchain
;
4395 /* First time through it might be necessary to create the
4397 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4399 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4400 pa_def_spaces
[0].spnum
,
4401 pa_def_spaces
[0].loadable
,
4402 pa_def_spaces
[0].defined
,
4403 pa_def_spaces
[0].private,
4404 pa_def_spaces
[0].sort
,
4405 pa_def_spaces
[0].segment
, 0);
4408 SPACE_DEFINED (sdchain
) = 1;
4409 subseg_set (text_section
, SUBSEG_CODE
);
4410 demand_empty_rest_of_line ();
4414 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4415 the .comm pseudo-op has the following symtax:
4417 <label> .comm <length>
4419 where <label> is optional and is a symbol whose address will be the start of
4420 a block of memory <length> bytes long. <length> must be an absolute
4421 expression. <length> bytes will be allocated in the current space
4430 label_symbol_struct
*label_symbol
= pa_get_label ();
4433 symbol
= label_symbol
->lss_label
;
4438 size
= get_absolute_expression ();
4442 /* It is incorrect to check S_IS_DEFINED at this point as
4443 the symbol will *always* be defined. FIXME. How to
4444 correctly determine when this label really as been
4446 if (S_GET_VALUE (symbol
))
4448 if (S_GET_VALUE (symbol
) != size
)
4450 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4451 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4457 S_SET_VALUE (symbol
, size
);
4458 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4459 S_SET_EXTERNAL (symbol
);
4462 demand_empty_rest_of_line ();
4465 /* Process a .COPYRIGHT pseudo-op. */
4468 pa_copyright (unused
)
4475 if (*input_line_pointer
== '\"')
4477 ++input_line_pointer
;
4478 name
= input_line_pointer
;
4479 while ((c
= next_char_of_string ()) >= 0)
4481 c
= *input_line_pointer
;
4482 *input_line_pointer
= '\0';
4483 *(input_line_pointer
- 1) = '\0';
4485 /* FIXME. Not supported */
4488 *input_line_pointer
= c
;
4492 as_bad ("Expected \"-ed string");
4494 pa_undefine_label ();
4495 demand_empty_rest_of_line ();
4498 /* Process a .END pseudo-op. */
4504 demand_empty_rest_of_line ();
4508 /* Process a .ENTER pseudo-op. This is not supported. */
4517 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4523 if (!within_procedure
)
4524 as_bad ("Misplaced .entry. Ignored.");
4527 if (!callinfo_found
)
4528 as_bad ("Missing .callinfo.");
4530 last_call_info
->start_frag
= frag_now
;
4532 demand_empty_rest_of_line ();
4533 within_entry_exit
= TRUE
;
4535 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4536 It will not be on if no .EXPORT pseudo-op exists (static function). */
4537 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4540 /* SOM defers building of unwind descriptors until the link phase.
4541 The assembler is responsible for creating an R_ENTRY relocation
4542 to mark the beginning of a region and hold the unwind bits, and
4543 for creating an R_EXIT relocation to mark the end of the region.
4545 FIXME. ELF should be using the same conventions! The problem
4546 is an unwind requires too much relocation space. Hmmm. Maybe
4547 if we split the unwind bits up between the relocations which
4548 denote the entry and exit points. */
4550 char *where
= frag_more (0);
4552 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4553 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4554 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4555 (char *) &last_call_info
->ci_unwind
.descriptor
);
4562 /* Handle a .EQU pseudo-op. */
4568 label_symbol_struct
*label_symbol
= pa_get_label ();
4573 symbol
= label_symbol
->lss_label
;
4574 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4575 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4580 as_bad (".REG must use a label");
4582 as_bad (".EQU must use a label");
4585 pa_undefine_label ();
4586 demand_empty_rest_of_line ();
4590 /* Helper function. Does processing for the end of a function. This
4591 usually involves creating some relocations or building special
4592 symbols to mark the end of the function. */
4599 where
= frag_more (0);
4602 /* Mark the end of the function, stuff away the location of the frag
4603 for the end of the function, and finally call pa_build_unwind_subspace
4604 to add an entry in the unwind table. */
4605 hppa_elf_mark_end_of_function ();
4606 last_call_info
->end_frag
= frag_now
;
4607 pa_build_unwind_subspace (last_call_info
);
4609 /* SOM defers building of unwind descriptors until the link phase.
4610 The assembler is responsible for creating an R_ENTRY relocation
4611 to mark the beginning of a region and hold the unwind bits, and
4612 for creating an R_EXIT relocation to mark the end of the region.
4614 FIXME. ELF should be using the same conventions! The problem
4615 is an unwind requires too much relocation space. Hmmm. Maybe
4616 if we split the unwind bits up between the relocations which
4617 denote the entry and exit points. */
4618 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4619 last_call_info
->start_symbol
, (offsetT
) 0,
4620 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4625 /* Process a .EXIT pseudo-op. */
4631 if (!within_procedure
)
4632 as_bad (".EXIT must appear within a procedure");
4635 if (!callinfo_found
)
4636 as_bad ("Missing .callinfo");
4639 if (!within_entry_exit
)
4640 as_bad ("No .ENTRY for this .EXIT");
4643 within_entry_exit
= FALSE
;
4648 demand_empty_rest_of_line ();
4652 /* Process a .EXPORT directive. This makes functions external
4653 and provides information such as argument relocation entries
4663 name
= input_line_pointer
;
4664 c
= get_symbol_end ();
4665 /* Make sure the given symbol exists. */
4666 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4668 as_bad ("Cannot define export symbol: %s\n", name
);
4669 p
= input_line_pointer
;
4671 input_line_pointer
++;
4675 /* OK. Set the external bits and process argument relocations. */
4676 S_SET_EXTERNAL (symbol
);
4677 p
= input_line_pointer
;
4679 if (!is_end_of_statement ())
4681 input_line_pointer
++;
4682 pa_type_args (symbol
, 1);
4684 pa_build_symextn_section ();
4689 demand_empty_rest_of_line ();
4693 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4696 pa_type_args (symbolP
, is_export
)
4701 unsigned int temp
, arg_reloc
;
4702 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4703 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4705 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4708 input_line_pointer
+= 8;
4709 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4710 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4711 type
= SYMBOL_TYPE_ABSOLUTE
;
4713 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4715 input_line_pointer
+= 4;
4716 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4717 instead one should be IMPORTing/EXPORTing ENTRY types.
4719 Complain if one tries to EXPORT a CODE type since that's never
4720 done. Both GCC and HP C still try to IMPORT CODE types, so
4721 silently fix them to be ENTRY types. */
4722 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4725 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4727 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4728 type
= SYMBOL_TYPE_ENTRY
;
4732 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4733 type
= SYMBOL_TYPE_CODE
;
4736 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4738 input_line_pointer
+= 4;
4739 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4740 type
= SYMBOL_TYPE_DATA
;
4742 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4744 input_line_pointer
+= 5;
4745 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4746 type
= SYMBOL_TYPE_ENTRY
;
4748 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4750 input_line_pointer
+= 9;
4751 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4752 type
= SYMBOL_TYPE_MILLICODE
;
4754 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4756 input_line_pointer
+= 6;
4757 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4758 type
= SYMBOL_TYPE_PLABEL
;
4760 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4762 input_line_pointer
+= 8;
4763 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4764 type
= SYMBOL_TYPE_PRI_PROG
;
4766 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4768 input_line_pointer
+= 8;
4769 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4770 type
= SYMBOL_TYPE_SEC_PROG
;
4773 /* SOM requires much more information about symbol types
4774 than BFD understands. This is how we get this information
4775 to the SOM BFD backend. */
4776 #ifdef obj_set_symbol_type
4777 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4780 /* Now that the type of the exported symbol has been handled,
4781 handle any argument relocation information. */
4782 while (!is_end_of_statement ())
4784 if (*input_line_pointer
== ',')
4785 input_line_pointer
++;
4786 name
= input_line_pointer
;
4787 c
= get_symbol_end ();
4788 /* Argument sources. */
4789 if ((strncasecmp (name
, "argw", 4) == 0))
4791 p
= input_line_pointer
;
4793 input_line_pointer
++;
4794 temp
= atoi (name
+ 4);
4795 name
= input_line_pointer
;
4796 c
= get_symbol_end ();
4797 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4798 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4799 *input_line_pointer
= c
;
4801 /* The return value. */
4802 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4804 p
= input_line_pointer
;
4806 input_line_pointer
++;
4807 name
= input_line_pointer
;
4808 c
= get_symbol_end ();
4809 arg_reloc
= pa_build_arg_reloc (name
);
4810 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4811 *input_line_pointer
= c
;
4813 /* Privelege level. */
4814 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4816 p
= input_line_pointer
;
4818 input_line_pointer
++;
4819 temp
= atoi (input_line_pointer
);
4820 c
= get_symbol_end ();
4821 *input_line_pointer
= c
;
4825 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4826 p
= input_line_pointer
;
4829 if (!is_end_of_statement ())
4830 input_line_pointer
++;
4834 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4835 assembly file must either be defined in the assembly file, or
4836 explicitly IMPORTED from another. */
4845 name
= input_line_pointer
;
4846 c
= get_symbol_end ();
4848 symbol
= symbol_find_or_make (name
);
4849 p
= input_line_pointer
;
4852 if (!is_end_of_statement ())
4854 input_line_pointer
++;
4855 pa_type_args (symbol
, 0);
4859 /* Sigh. To be compatable with the HP assembler and to help
4860 poorly written assembly code, we assign a type based on
4861 the the current segment. Note only BSF_FUNCTION really
4862 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
4863 if (now_seg
== text_section
)
4864 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4866 /* If the section is undefined, then the symbol is undefined
4867 Since this is an import, leave the section undefined. */
4868 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4871 demand_empty_rest_of_line ();
4875 /* Handle a .LABEL pseudo-op. */
4883 name
= input_line_pointer
;
4884 c
= get_symbol_end ();
4886 if (strlen (name
) > 0)
4889 p
= input_line_pointer
;
4894 as_warn ("Missing label name on .LABEL");
4897 if (!is_end_of_statement ())
4899 as_warn ("extra .LABEL arguments ignored.");
4900 ignore_rest_of_line ();
4902 demand_empty_rest_of_line ();
4906 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4915 /* Handle a .ORIGIN pseudo-op. */
4922 pa_undefine_label ();
4926 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4927 is for static functions. FIXME. Should share more code with .EXPORT. */
4936 name
= input_line_pointer
;
4937 c
= get_symbol_end ();
4939 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4941 as_bad ("Cannot define static symbol: %s\n", name
);
4942 p
= input_line_pointer
;
4944 input_line_pointer
++;
4948 S_CLEAR_EXTERNAL (symbol
);
4949 p
= input_line_pointer
;
4951 if (!is_end_of_statement ())
4953 input_line_pointer
++;
4954 pa_type_args (symbol
, 0);
4958 demand_empty_rest_of_line ();
4962 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4963 of a procedure from a syntatical point of view. */
4969 struct call_info
*call_info
;
4971 if (within_procedure
)
4972 as_fatal ("Nested procedures");
4974 /* Reset global variables for new procedure. */
4975 callinfo_found
= FALSE
;
4976 within_procedure
= TRUE
;
4978 /* Create another call_info structure. */
4979 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
4982 as_fatal ("Cannot allocate unwind descriptor\n");
4984 bzero (call_info
, sizeof (struct call_info
));
4986 call_info
->ci_next
= NULL
;
4988 if (call_info_root
== NULL
)
4990 call_info_root
= call_info
;
4991 last_call_info
= call_info
;
4995 last_call_info
->ci_next
= call_info
;
4996 last_call_info
= call_info
;
4999 /* set up defaults on call_info structure */
5001 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5002 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5003 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5004 call_info
->entry_sr
= ~0;
5005 call_info
->makes_calls
= 1;
5007 /* If we got a .PROC pseudo-op, we know that the function is defined
5008 locally. Make sure it gets into the symbol table. */
5010 label_symbol_struct
*label_symbol
= pa_get_label ();
5014 if (label_symbol
->lss_label
)
5016 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5017 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5020 as_bad ("Missing function name for .PROC (corrupted label)");
5023 as_bad ("Missing function name for .PROC");
5026 demand_empty_rest_of_line ();
5030 /* Process the syntatical end of a procedure. Make sure all the
5031 appropriate pseudo-ops were found within the procedure. */
5038 if (!within_procedure
)
5039 as_bad ("misplaced .procend");
5041 if (!callinfo_found
)
5042 as_bad ("Missing .callinfo for this procedure");
5044 if (within_entry_exit
)
5045 as_bad ("Missing .EXIT for a .ENTRY");
5048 /* ELF needs to mark the end of each function so that it can compute
5049 the size of the function (apparently its needed in the symbol table. */
5050 hppa_elf_mark_end_of_function ();
5053 within_procedure
= FALSE
;
5054 demand_empty_rest_of_line ();
5058 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5059 then create a new space entry to hold the information specified
5060 by the parameters to the .SPACE directive. */
5062 static sd_chain_struct
*
5063 pa_parse_space_stmt (space_name
, create_flag
)
5067 char *name
, *ptemp
, c
;
5068 char loadable
, defined
, private, sort
;
5070 asection
*seg
= NULL
;
5071 sd_chain_struct
*space
;
5073 /* load default values */
5079 if (strcasecmp (space_name
, "$TEXT$") == 0)
5081 seg
= pa_def_spaces
[0].segment
;
5082 sort
= pa_def_spaces
[0].sort
;
5084 else if (strcasecmp (space_name
, "$PRIVATE$") == 0)
5086 seg
= pa_def_spaces
[1].segment
;
5087 sort
= pa_def_spaces
[1].sort
;
5090 if (!is_end_of_statement ())
5092 print_errors
= FALSE
;
5093 ptemp
= input_line_pointer
+ 1;
5094 /* First see if the space was specified as a number rather than
5095 as a name. According to the PA assembly manual the rest of
5096 the line should be ignored. */
5097 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5098 input_line_pointer
= ptemp
;
5101 while (!is_end_of_statement ())
5103 input_line_pointer
++;
5104 name
= input_line_pointer
;
5105 c
= get_symbol_end ();
5106 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5108 *input_line_pointer
= c
;
5109 input_line_pointer
++;
5110 spnum
= get_absolute_expression ();
5112 else if ((strncasecmp (name
, "SORT", 4) == 0))
5114 *input_line_pointer
= c
;
5115 input_line_pointer
++;
5116 sort
= get_absolute_expression ();
5118 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5120 *input_line_pointer
= c
;
5123 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5125 *input_line_pointer
= c
;
5128 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5130 *input_line_pointer
= c
;
5135 as_bad ("Invalid .SPACE argument");
5136 *input_line_pointer
= c
;
5137 if (!is_end_of_statement ())
5138 input_line_pointer
++;
5142 print_errors
= TRUE
;
5145 if (create_flag
&& seg
== NULL
)
5146 seg
= subseg_new (space_name
, 0);
5148 /* If create_flag is nonzero, then create the new space with
5149 the attributes computed above. Else set the values in
5150 an already existing space -- this can only happen for
5151 the first occurence of a built-in space. */
5153 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5154 private, sort
, seg
, 1);
5157 space
= is_defined_space (space_name
);
5158 SPACE_SPNUM (space
) = spnum
;
5159 SPACE_LOADABLE (space
) = loadable
& 1;
5160 SPACE_DEFINED (space
) = defined
& 1;
5161 SPACE_USER_DEFINED (space
) = 1;
5162 SPACE_PRIVATE (space
) = private & 1;
5163 SPACE_SORT (space
) = sort
& 0xff;
5164 space
->sd_seg
= seg
;
5167 #ifdef obj_set_section_attributes
5168 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5174 /* Handle a .SPACE pseudo-op; this switches the current space to the
5175 given space, creating the new space if necessary. */
5181 char *name
, c
, *space_name
, *save_s
;
5183 sd_chain_struct
*sd_chain
;
5185 if (within_procedure
)
5187 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5188 ignore_rest_of_line ();
5192 /* Check for some of the predefined spaces. FIXME: most of the code
5193 below is repeated several times, can we extract the common parts
5194 and place them into a subroutine or something similar? */
5195 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5197 input_line_pointer
+= 6;
5198 sd_chain
= is_defined_space ("$TEXT$");
5199 if (sd_chain
== NULL
)
5200 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5201 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5202 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5204 current_space
= sd_chain
;
5205 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5207 = pa_subsegment_to_subspace (text_section
,
5208 sd_chain
->sd_last_subseg
);
5209 demand_empty_rest_of_line ();
5212 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5214 input_line_pointer
+= 9;
5215 sd_chain
= is_defined_space ("$PRIVATE$");
5216 if (sd_chain
== NULL
)
5217 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5218 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5219 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5221 current_space
= sd_chain
;
5222 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5224 = pa_subsegment_to_subspace (data_section
,
5225 sd_chain
->sd_last_subseg
);
5226 demand_empty_rest_of_line ();
5229 if (!strncasecmp (input_line_pointer
,
5230 GDB_DEBUG_SPACE_NAME
,
5231 strlen (GDB_DEBUG_SPACE_NAME
)))
5233 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5234 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5235 if (sd_chain
== NULL
)
5236 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5237 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5238 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5240 current_space
= sd_chain
;
5243 asection
*gdb_section
5244 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5246 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5248 = pa_subsegment_to_subspace (gdb_section
,
5249 sd_chain
->sd_last_subseg
);
5251 demand_empty_rest_of_line ();
5255 /* It could be a space specified by number. */
5257 save_s
= input_line_pointer
;
5258 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5260 if (sd_chain
= pa_find_space_by_number (temp
))
5262 current_space
= sd_chain
;
5264 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5266 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5267 sd_chain
->sd_last_subseg
);
5268 demand_empty_rest_of_line ();
5273 /* Not a number, attempt to create a new space. */
5275 input_line_pointer
= save_s
;
5276 name
= input_line_pointer
;
5277 c
= get_symbol_end ();
5278 space_name
= xmalloc (strlen (name
) + 1);
5279 strcpy (space_name
, name
);
5280 *input_line_pointer
= c
;
5282 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5283 current_space
= sd_chain
;
5285 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5286 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5287 sd_chain
->sd_last_subseg
);
5288 demand_empty_rest_of_line ();
5293 /* Switch to a new space. (I think). FIXME. */
5302 sd_chain_struct
*space
;
5304 name
= input_line_pointer
;
5305 c
= get_symbol_end ();
5306 space
= is_defined_space (name
);
5310 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5313 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5315 *input_line_pointer
= c
;
5316 demand_empty_rest_of_line ();
5320 /* If VALUE is an exact power of two between zero and 2^31, then
5321 return log2 (VALUE). Else return -1. */
5329 while ((1 << shift
) != value
&& shift
< 32)
5338 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5339 given subspace, creating the new subspace if necessary.
5341 FIXME. Should mirror pa_space more closely, in particular how
5342 they're broken up into subroutines. */
5345 pa_subspace (unused
)
5348 char *name
, *ss_name
, *alias
, c
;
5349 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5350 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5351 sd_chain_struct
*space
;
5352 ssd_chain_struct
*ssd
;
5355 if (within_procedure
)
5357 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5358 ignore_rest_of_line ();
5362 name
= input_line_pointer
;
5363 c
= get_symbol_end ();
5364 ss_name
= xmalloc (strlen (name
) + 1);
5365 strcpy (ss_name
, name
);
5366 *input_line_pointer
= c
;
5368 /* Load default values. */
5381 space
= current_space
;
5382 ssd
= is_defined_subspace (ss_name
);
5383 /* Allow user to override the builtin attributes of subspaces. But
5384 only allow the attributes to be changed once! */
5385 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5387 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5388 if (!is_end_of_statement ())
5389 as_warn ("Parameters of an existing subspace can\'t be modified");
5390 demand_empty_rest_of_line ();
5395 /* A new subspace. Load default values if it matches one of
5396 the builtin subspaces. */
5398 while (pa_def_subspaces
[i
].name
)
5400 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5402 loadable
= pa_def_subspaces
[i
].loadable
;
5403 common
= pa_def_subspaces
[i
].common
;
5404 dup_common
= pa_def_subspaces
[i
].dup_common
;
5405 code_only
= pa_def_subspaces
[i
].code_only
;
5406 zero
= pa_def_subspaces
[i
].zero
;
5407 space_index
= pa_def_subspaces
[i
].space_index
;
5408 alignment
= pa_def_subspaces
[i
].alignment
;
5409 quadrant
= pa_def_subspaces
[i
].quadrant
;
5410 access
= pa_def_subspaces
[i
].access
;
5411 sort
= pa_def_subspaces
[i
].sort
;
5412 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5413 alias
= pa_def_subspaces
[i
].alias
;
5420 /* We should be working with a new subspace now. Fill in
5421 any information as specified by the user. */
5422 if (!is_end_of_statement ())
5424 input_line_pointer
++;
5425 while (!is_end_of_statement ())
5427 name
= input_line_pointer
;
5428 c
= get_symbol_end ();
5429 if ((strncasecmp (name
, "QUAD", 4) == 0))
5431 *input_line_pointer
= c
;
5432 input_line_pointer
++;
5433 quadrant
= get_absolute_expression ();
5435 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5437 *input_line_pointer
= c
;
5438 input_line_pointer
++;
5439 alignment
= get_absolute_expression ();
5440 if (log2 (alignment
) == -1)
5442 as_bad ("Alignment must be a power of 2");
5446 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5448 *input_line_pointer
= c
;
5449 input_line_pointer
++;
5450 access
= get_absolute_expression ();
5452 else if ((strncasecmp (name
, "SORT", 4) == 0))
5454 *input_line_pointer
= c
;
5455 input_line_pointer
++;
5456 sort
= get_absolute_expression ();
5458 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5460 *input_line_pointer
= c
;
5463 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5465 *input_line_pointer
= c
;
5468 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5470 *input_line_pointer
= c
;
5473 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5475 *input_line_pointer
= c
;
5478 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5480 *input_line_pointer
= c
;
5483 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5484 as_bad ("FIRST not supported as a .SUBSPACE argument");
5486 as_bad ("Invalid .SUBSPACE argument");
5487 if (!is_end_of_statement ())
5488 input_line_pointer
++;
5492 /* Compute a reasonable set of BFD flags based on the information
5493 in the .subspace directive. */
5494 applicable
= bfd_applicable_section_flags (stdoutput
);
5497 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5500 if (common
|| dup_common
)
5501 flags
|= SEC_IS_COMMON
;
5503 /* This is a zero-filled subspace (eg BSS). */
5507 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5508 applicable
&= flags
;
5510 /* If this is an existing subspace, then we want to use the
5511 segment already associated with the subspace.
5513 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5514 lots of sections. It might be a problem in the PA ELF
5515 code, I do not know yet. For now avoid creating anything
5516 but the "standard" sections for ELF. */
5518 section
= ssd
->ssd_seg
;
5520 section
= subseg_new (alias
, 0);
5521 else if (!alias
&& USE_ALIASES
)
5523 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5524 demand_empty_rest_of_line ();
5528 section
= subseg_new (ss_name
, 0);
5530 /* Now set the flags. */
5531 bfd_set_section_flags (stdoutput
, section
, applicable
);
5533 /* Record any alignment request for this section. */
5534 record_alignment (section
, log2 (alignment
));
5536 /* Set the starting offset for this section. */
5537 bfd_set_section_vma (stdoutput
, section
,
5538 pa_subspace_start (space
, quadrant
));
5540 /* Now that all the flags are set, update an existing subspace,
5541 or create a new one. */
5544 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5545 code_only
, common
, dup_common
,
5546 sort
, zero
, access
, space_index
,
5547 alignment
, quadrant
,
5550 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5552 dup_common
, zero
, sort
,
5553 access
, space_index
,
5554 alignment
, quadrant
, section
);
5556 demand_empty_rest_of_line ();
5557 current_subspace
->ssd_seg
= section
;
5558 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5560 SUBSPACE_DEFINED (current_subspace
) = 1;
5565 /* Create default space and subspace dictionaries. */
5572 space_dict_root
= NULL
;
5573 space_dict_last
= NULL
;
5576 while (pa_def_spaces
[i
].name
)
5580 /* Pick the right name to use for the new section. */
5581 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5582 name
= pa_def_spaces
[i
].alias
;
5584 name
= pa_def_spaces
[i
].name
;
5586 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5587 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5588 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5589 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5590 pa_def_spaces
[i
].segment
, 0);
5595 while (pa_def_subspaces
[i
].name
)
5598 int applicable
, subsegment
;
5599 asection
*segment
= NULL
;
5600 sd_chain_struct
*space
;
5602 /* Pick the right name for the new section and pick the right
5603 subsegment number. */
5604 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5606 name
= pa_def_subspaces
[i
].alias
;
5607 subsegment
= pa_def_subspaces
[i
].subsegment
;
5611 name
= pa_def_subspaces
[i
].name
;
5615 /* Create the new section. */
5616 segment
= subseg_new (name
, subsegment
);
5619 /* For SOM we want to replace the standard .text, .data, and .bss
5620 sections with our own. */
5621 if (!strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && !USE_ALIASES
)
5623 text_section
= segment
;
5624 applicable
= bfd_applicable_section_flags (stdoutput
);
5625 bfd_set_section_flags (stdoutput
, text_section
,
5626 applicable
& (SEC_ALLOC
| SEC_LOAD
5627 | SEC_RELOC
| SEC_CODE
5629 | SEC_HAS_CONTENTS
));
5631 else if (!strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && !USE_ALIASES
)
5633 data_section
= segment
;
5634 applicable
= bfd_applicable_section_flags (stdoutput
);
5635 bfd_set_section_flags (stdoutput
, data_section
,
5636 applicable
& (SEC_ALLOC
| SEC_LOAD
5638 | SEC_HAS_CONTENTS
));
5642 else if (!strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && !USE_ALIASES
)
5644 bss_section
= segment
;
5645 applicable
= bfd_applicable_section_flags (stdoutput
);
5646 bfd_set_section_flags (stdoutput
, bss_section
,
5647 applicable
& SEC_ALLOC
);
5650 /* Find the space associated with this subspace. */
5651 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5652 def_space_index
].segment
);
5655 as_fatal ("Internal error: Unable to find containing space for %s.",
5656 pa_def_subspaces
[i
].name
);
5659 create_new_subspace (space
, name
,
5660 pa_def_subspaces
[i
].loadable
,
5661 pa_def_subspaces
[i
].code_only
,
5662 pa_def_subspaces
[i
].common
,
5663 pa_def_subspaces
[i
].dup_common
,
5664 pa_def_subspaces
[i
].zero
,
5665 pa_def_subspaces
[i
].sort
,
5666 pa_def_subspaces
[i
].access
,
5667 pa_def_subspaces
[i
].space_index
,
5668 pa_def_subspaces
[i
].alignment
,
5669 pa_def_subspaces
[i
].quadrant
,
5677 /* Create a new space NAME, with the appropriate flags as defined
5678 by the given parameters.
5680 Add the new space to the space dictionary chain in numerical
5681 order as defined by the SORT entries. */
5683 static sd_chain_struct
*
5684 create_new_space (name
, spnum
, loadable
, defined
, private,
5685 sort
, seg
, user_defined
)
5695 sd_chain_struct
*chain_entry
;
5697 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5699 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5702 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5703 strcpy (SPACE_NAME (chain_entry
), name
);
5704 SPACE_NAME_INDEX (chain_entry
) = 0;
5705 SPACE_LOADABLE (chain_entry
) = loadable
;
5706 SPACE_DEFINED (chain_entry
) = defined
;
5707 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5708 SPACE_PRIVATE (chain_entry
) = private;
5709 SPACE_SPNUM (chain_entry
) = spnum
;
5710 SPACE_SORT (chain_entry
) = sort
;
5712 chain_entry
->sd_seg
= seg
;
5713 chain_entry
->sd_last_subseg
= -1;
5714 chain_entry
->sd_next
= NULL
;
5716 /* Find spot for the new space based on its sort key. */
5717 if (!space_dict_last
)
5718 space_dict_last
= chain_entry
;
5720 if (space_dict_root
== NULL
)
5721 space_dict_root
= chain_entry
;
5724 sd_chain_struct
*chain_pointer
;
5725 sd_chain_struct
*prev_chain_pointer
;
5727 chain_pointer
= space_dict_root
;
5728 prev_chain_pointer
= NULL
;
5730 while (chain_pointer
)
5732 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5734 prev_chain_pointer
= chain_pointer
;
5735 chain_pointer
= chain_pointer
->sd_next
;
5741 /* At this point we've found the correct place to add the new
5742 entry. So add it and update the linked lists as appropriate. */
5743 if (prev_chain_pointer
)
5745 chain_entry
->sd_next
= chain_pointer
;
5746 prev_chain_pointer
->sd_next
= chain_entry
;
5750 space_dict_root
= chain_entry
;
5751 chain_entry
->sd_next
= chain_pointer
;
5754 if (chain_entry
->sd_next
== NULL
)
5755 space_dict_last
= chain_entry
;
5758 /* This is here to catch predefined spaces which do not get
5759 modified by the user's input. Another call is found at
5760 the bottom of pa_parse_space_stmt to handle cases where
5761 the user modifies a predefined space. */
5762 #ifdef obj_set_section_attributes
5763 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5769 /* Create a new subspace NAME, with the appropriate flags as defined
5770 by the given parameters.
5772 Add the new subspace to the subspace dictionary chain in numerical
5773 order as defined by the SORT entries. */
5775 static ssd_chain_struct
*
5776 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5777 dup_common
, is_zero
, sort
, access
, space_index
,
5778 alignment
, quadrant
, seg
)
5779 sd_chain_struct
*space
;
5781 char loadable
, code_only
, common
, dup_common
, is_zero
;
5789 ssd_chain_struct
*chain_entry
;
5791 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5793 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5795 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5796 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5798 SUBSPACE_ACCESS (chain_entry
) = access
;
5799 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5800 SUBSPACE_COMMON (chain_entry
) = common
;
5801 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5802 SUBSPACE_SORT (chain_entry
) = sort
;
5803 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
5804 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5805 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5806 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
5807 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5808 SUBSPACE_ZERO (chain_entry
) = is_zero
;
5810 /* Initialize subspace_defined. When we hit a .subspace directive
5811 we'll set it to 1 which "locks-in" the subspace attributes. */
5812 SUBSPACE_DEFINED (chain_entry
) = 0;
5814 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5815 chain_entry
->ssd_seg
= seg
;
5816 chain_entry
->ssd_last_align
= 1;
5817 chain_entry
->ssd_next
= NULL
;
5819 /* Find spot for the new subspace based on its sort key. */
5820 if (space
->sd_subspaces
== NULL
)
5821 space
->sd_subspaces
= chain_entry
;
5824 ssd_chain_struct
*chain_pointer
;
5825 ssd_chain_struct
*prev_chain_pointer
;
5827 chain_pointer
= space
->sd_subspaces
;
5828 prev_chain_pointer
= NULL
;
5830 while (chain_pointer
)
5832 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
5834 prev_chain_pointer
= chain_pointer
;
5835 chain_pointer
= chain_pointer
->ssd_next
;
5842 /* Now we have somewhere to put the new entry. Insert it and update
5844 if (prev_chain_pointer
)
5846 chain_entry
->ssd_next
= chain_pointer
;
5847 prev_chain_pointer
->ssd_next
= chain_entry
;
5851 space
->sd_subspaces
= chain_entry
;
5852 chain_entry
->ssd_next
= chain_pointer
;
5856 #ifdef obj_set_subsection_attributes
5857 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5865 /* Update the information for the given subspace based upon the
5866 various arguments. Return the modified subspace chain entry. */
5868 static ssd_chain_struct
*
5869 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5870 zero
, access
, space_index
, alignment
, quadrant
, section
)
5871 sd_chain_struct
*space
;
5885 ssd_chain_struct
*chain_entry
;
5887 if ((chain_entry
= is_defined_subspace (name
)))
5889 SUBSPACE_ACCESS (chain_entry
) = access
;
5890 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5891 SUBSPACE_COMMON (chain_entry
) = common
;
5892 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5893 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
5894 SUBSPACE_SORT (chain_entry
) = sort
;
5895 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5896 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5897 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5898 SUBSPACE_ZERO (chain_entry
) = zero
;
5903 #ifdef obj_set_subsection_attributes
5904 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
5912 /* Return the space chain entry for the space with the name NAME or
5913 NULL if no such space exists. */
5915 static sd_chain_struct
*
5916 is_defined_space (name
)
5919 sd_chain_struct
*chain_pointer
;
5921 for (chain_pointer
= space_dict_root
;
5923 chain_pointer
= chain_pointer
->sd_next
)
5925 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5926 return chain_pointer
;
5929 /* No mapping from segment to space was found. Return NULL. */
5933 /* Find and return the space associated with the given seg. If no mapping
5934 from the given seg to a space is found, then return NULL.
5936 Unlike subspaces, the number of spaces is not expected to grow much,
5937 so a linear exhaustive search is OK here. */
5939 static sd_chain_struct
*
5940 pa_segment_to_space (seg
)
5943 sd_chain_struct
*space_chain
;
5945 /* Walk through each space looking for the correct mapping. */
5946 for (space_chain
= space_dict_root
;
5948 space_chain
= space_chain
->sd_next
)
5950 if (space_chain
->sd_seg
== seg
)
5954 /* Mapping was not found. Return NULL. */
5958 /* Return the space chain entry for the subspace with the name NAME or
5959 NULL if no such subspace exists.
5961 Uses a linear search through all the spaces and subspaces, this may
5962 not be appropriate if we ever being placing each function in its
5965 static ssd_chain_struct
*
5966 is_defined_subspace (name
)
5969 sd_chain_struct
*space_chain
;
5970 ssd_chain_struct
*subspace_chain
;
5972 /* Walk through each space. */
5973 for (space_chain
= space_dict_root
;
5975 space_chain
= space_chain
->sd_next
)
5977 /* Walk through each subspace looking for a name which matches. */
5978 for (subspace_chain
= space_chain
->sd_subspaces
;
5980 subspace_chain
= subspace_chain
->ssd_next
)
5981 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5982 return subspace_chain
;
5985 /* Subspace wasn't found. Return NULL. */
5989 /* Find and return the subspace associated with the given seg. If no
5990 mapping from the given seg to a subspace is found, then return NULL.
5992 If we ever put each procedure/function within its own subspace
5993 (to make life easier on the compiler and linker), then this will have
5994 to become more efficient. */
5996 static ssd_chain_struct
*
5997 pa_subsegment_to_subspace (seg
, subseg
)
6001 sd_chain_struct
*space_chain
;
6002 ssd_chain_struct
*subspace_chain
;
6004 /* Walk through each space. */
6005 for (space_chain
= space_dict_root
;
6007 space_chain
= space_chain
->sd_next
)
6009 if (space_chain
->sd_seg
== seg
)
6011 /* Walk through each subspace within each space looking for
6012 the correct mapping. */
6013 for (subspace_chain
= space_chain
->sd_subspaces
;
6015 subspace_chain
= subspace_chain
->ssd_next
)
6016 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6017 return subspace_chain
;
6021 /* No mapping from subsegment to subspace found. Return NULL. */
6025 /* Given a number, try and find a space with the name number.
6027 Return a pointer to a space dictionary chain entry for the space
6028 that was found or NULL on failure. */
6030 static sd_chain_struct
*
6031 pa_find_space_by_number (number
)
6034 sd_chain_struct
*space_chain
;
6036 for (space_chain
= space_dict_root
;
6038 space_chain
= space_chain
->sd_next
)
6040 if (SPACE_SPNUM (space_chain
) == number
)
6044 /* No appropriate space found. Return NULL. */
6048 /* Return the starting address for the given subspace. If the starting
6049 address is unknown then return zero. */
6052 pa_subspace_start (space
, quadrant
)
6053 sd_chain_struct
*space
;
6056 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6057 is not correct for the PA OSF1 port. */
6058 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6060 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6066 /* FIXME. Needs documentation. */
6068 pa_next_subseg (space
)
6069 sd_chain_struct
*space
;
6072 space
->sd_last_subseg
++;
6073 return space
->sd_last_subseg
;
6076 /* Helper function for pa_stringer. Used to find the end of
6083 unsigned int c
= *s
& CHAR_MASK
;
6095 /* Handle a .STRING type pseudo-op. */
6098 pa_stringer (append_zero
)
6101 char *s
, num_buf
[4];
6105 /* Preprocess the string to handle PA-specific escape sequences.
6106 For example, \xDD where DD is a hexidecimal number should be
6107 changed to \OOO where OOO is an octal number. */
6109 /* Skip the opening quote. */
6110 s
= input_line_pointer
+ 1;
6112 while (is_a_char (c
= pa_stringer_aux (s
++)))
6119 /* Handle \x<num>. */
6122 unsigned int number
;
6127 /* Get pas the 'x'. */
6129 for (num_digit
= 0, number
= 0, dg
= *s
;
6131 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6132 || (dg
>= 'A' && dg
<= 'F'));
6136 number
= number
* 16 + dg
- '0';
6137 else if (dg
>= 'a' && dg
<= 'f')
6138 number
= number
* 16 + dg
- 'a' + 10;
6140 number
= number
* 16 + dg
- 'A' + 10;
6150 sprintf (num_buf
, "%02o", number
);
6153 sprintf (num_buf
, "%03o", number
);
6156 for (i
= 0; i
<= num_digit
; i
++)
6157 s_start
[i
] = num_buf
[i
];
6161 /* This might be a "\"", skip over the escaped char. */
6168 stringer (append_zero
);
6169 pa_undefine_label ();
6172 /* Handle a .VERSION pseudo-op. */
6179 pa_undefine_label ();
6182 /* Just like a normal cons, but when finished we have to undefine
6183 the latest space label. */
6190 pa_undefine_label ();
6193 /* Switch to the data space. As usual delete our label. */
6200 pa_undefine_label ();
6203 /* FIXME. What's the purpose of this pseudo-op? */
6209 pa_undefine_label ();
6212 /* Like float_cons, but we need to undefine our label. */
6215 pa_float_cons (float_type
)
6218 float_cons (float_type
);
6219 pa_undefine_label ();
6222 /* Like s_fill, but delete our label when finished. */
6229 pa_undefine_label ();
6232 /* Like lcomm, but delete our label when finished. */
6235 pa_lcomm (needs_align
)
6238 s_lcomm (needs_align
);
6239 pa_undefine_label ();
6242 /* Like lsym, but delete our label when finished. */
6249 pa_undefine_label ();
6252 /* Switch to the text space. Like s_text, but delete our
6253 label when finished. */
6259 pa_undefine_label ();
6262 /* On the PA relocations which involve function symbols must not be
6263 adjusted. This so that the linker can know when/how to create argument
6264 relocation stubs for indirect calls and calls to static functions.
6266 FIXME. Also reject R_HPPA relocations which are 32 bits
6267 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6268 needs to generate relocations to push the addend and symbol value
6269 onto the stack, add them, then pop the value off the stack and
6270 use it in a relocation -- yuk. */
6273 hppa_fix_adjustable (fixp
)
6276 struct hppa_fix_struct
*hppa_fix
;
6278 hppa_fix
= fixp
->tc_fix_data
;
6280 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6283 if (fixp
->fx_addsy
== 0
6284 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6290 /* Return nonzero if the fixup in FIXP will require a relocation,
6291 even it if appears that the fixup could be completely handled
6295 hppa_force_relocation (fixp
)
6298 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
6301 if (fixp
->fx_r_type
== R_HPPA_ENTRY
|| fixp
->fx_r_type
== R_HPPA_EXIT
)
6305 #define stub_needed(CALLER, CALLEE) \
6306 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
6308 /* It is necessary to force PC-relative calls/jumps to have a relocation
6309 entry if they're going to need either a argument relocation or long
6310 call stub. FIXME. Can't we need the same for absolute calls? */
6311 if (fixp
->fx_pcrel
&& fixp
->fx_addsy
6312 && (stub_needed (((obj_symbol_type
*)
6313 fixp
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
6314 hppa_fixp
->fx_arg_reloc
)))
6319 /* No need (yet) to force another relocations to be emitted. */
6323 /* Now for some ELF specific code. FIXME. */
6325 static symext_chainS
*symext_rootP
;
6326 static symext_chainS
*symext_lastP
;
6328 /* Mark the end of a function so that it's possible to compute
6329 the size of the function in hppa_elf_final_processing. */
6332 hppa_elf_mark_end_of_function ()
6334 /* ELF does not have EXIT relocations. All we do is create a
6335 temporary symbol marking the end of the function. */
6336 char *name
= (char *)
6337 xmalloc (strlen ("L$\001end_") +
6338 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
6344 strcpy (name
, "L$\001end_");
6345 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
6347 /* If we have a .exit followed by a .procend, then the
6348 symbol will have already been defined. */
6349 symbolP
= symbol_find (name
);
6352 /* The symbol has already been defined! This can
6353 happen if we have a .exit followed by a .procend.
6355 This is *not* an error. All we want to do is free
6356 the memory we just allocated for the name and continue. */
6361 /* symbol value should be the offset of the
6362 last instruction of the function */
6363 symbolP
= symbol_new (name
, now_seg
,
6364 (valueT
) (obstack_next_free (&frags
)
6365 - frag_now
->fr_literal
- 4),
6369 symbolP
->bsym
->flags
= BSF_LOCAL
;
6370 symbol_table_insert (symbolP
);
6374 last_call_info
->end_symbol
= symbolP
;
6376 as_bad ("Symbol '%s' could not be created.", name
);
6380 as_bad ("No memory for symbol name.");
6382 /* Stuff away the location of the frag for the end of the function,
6383 and call pa_build_unwind_subspace to add an entry in the unwind
6385 last_call_info
->end_frag
= frag_now
;
6388 /* Do any symbol processing requested by the target-cpu or target-format. */
6391 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6393 elf_symbol_type
*symbolP
;
6396 symext_chainS
*symextP
;
6397 unsigned int arg_reloc
;
6399 /* Only functions can have argument relocations. */
6400 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6403 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6405 /* If there are no argument relocation bits, then no relocation is
6406 necessary. Do not add this to the symextn section. */
6410 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6412 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6413 symextP
[0].next
= &symextP
[1];
6415 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6416 symextP
[1].next
= NULL
;
6418 if (symext_rootP
== NULL
)
6420 symext_rootP
= &symextP
[0];
6421 symext_lastP
= &symextP
[1];
6425 symext_lastP
->next
= &symextP
[0];
6426 symext_lastP
= &symextP
[1];
6430 /* Make sections needed by the target cpu and/or target format. */
6432 hppa_tc_make_sections (abfd
)
6435 symext_chainS
*symextP
;
6437 asection
*symextn_sec
;
6438 segT save_seg
= now_seg
;
6439 subsegT save_subseg
= now_subseg
;
6441 /* Build the symbol extension section. */
6442 hppa_tc_make_symextn_section ();
6444 /* Force some calculation to occur. */
6445 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6447 hppa_elf_stub_finish (abfd
);
6449 /* If no symbols for the symbol extension section, then stop now. */
6450 if (symext_rootP
== NULL
)
6453 /* Count the number of symbols for the symbol extension section. */
6454 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6457 size
= sizeof (symext_entryS
) * n
;
6459 /* Switch to the symbol extension section. */
6460 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6462 frag_wane (frag_now
);
6465 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6468 int *symtab_map
= elf_sym_extra (abfd
);
6471 /* First, patch the symbol extension record to reflect the true
6472 symbol table index. */
6474 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6476 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6477 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6481 ptr
= frag_more (sizeof (symextP
->entry
));
6482 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6485 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6486 frag_wane (frag_now
);
6488 /* Switch back to the original segment. */
6489 subseg_set (save_seg
, save_subseg
);
6494 /* Make the symbol extension section. */
6497 hppa_tc_make_symextn_section ()
6501 symext_chainS
*symextP
;
6505 segT save_seg
= now_seg
;
6506 subsegT save_subseg
= now_subseg
;
6508 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6511 size
= sizeof (symext_entryS
) * n
;
6513 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6515 bfd_set_section_flags (stdoutput
, symextn_sec
,
6516 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6517 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6519 /* Now, switch back to the original segment. */
6520 subseg_set (save_seg
, save_subseg
);
6524 /* Build the symbol extension section. */
6527 pa_build_symextn_section ()
6530 asection
*save_seg
= now_seg
;
6531 subsegT subseg
= (subsegT
) 0;
6532 subsegT save_subseg
= now_subseg
;
6534 seg
= subseg_new (".hppa_symextn", subseg
);
6535 bfd_set_section_flags (stdoutput
,
6537 SEC_HAS_CONTENTS
| SEC_READONLY
6538 | SEC_ALLOC
| SEC_LOAD
);
6540 subseg_set (save_seg
, save_subseg
);
6544 /* For ELF, this function serves one purpose: to setup the st_size
6545 field of STT_FUNC symbols. To do this, we need to scan the
6546 call_info structure list, determining st_size in one of two possible
6549 1. call_info->start_frag->fr_fix has the size of the fragment.
6550 This approach assumes that the function was built into a
6551 single fragment. This works for most cases, but might fail.
6552 For example, if there was a segment change in the middle of
6555 2. The st_size field is the difference in the addresses of the
6556 call_info->start_frag->fr_address field and the fr_address
6557 field of the next fragment with fr_type == rs_fill and
6561 elf_hppa_final_processing ()
6563 struct call_info
*call_info_pointer
;
6565 for (call_info_pointer
= call_info_root
;
6567 call_info_pointer
= call_info_pointer
->ci_next
)
6569 elf_symbol_type
*esym
6570 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6571 esym
->internal_elf_sym
.st_size
=
6572 S_GET_VALUE (call_info_pointer
->end_symbol
)
6573 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;