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
,
199 /* This structure contains information needed to assemble
200 individual instructions. */
203 /* Holds the opcode after parsing by pa_ip. */
204 unsigned long opcode
;
206 /* Holds an expression associated with the current instruction. */
209 /* Does this instruction use PC-relative addressing. */
212 /* Floating point formats for operand1 and operand2. */
213 fp_operand_format fpof1
;
214 fp_operand_format fpof2
;
216 /* Holds the field selector for this instruction
217 (for example L%, LR%, etc). */
220 /* Holds any argument relocation bits associated with this
221 instruction. (instruction should be some sort of call). */
224 /* The format specification for this instruction. */
227 /* The relocation (if any) associated with this instruction. */
231 /* PA-89 floating point registers are arranged like this:
234 +--------------+--------------+
235 | 0 or 16L | 16 or 16R |
236 +--------------+--------------+
237 | 1 or 17L | 17 or 17R |
238 +--------------+--------------+
246 +--------------+--------------+
247 | 14 or 30L | 30 or 30R |
248 +--------------+--------------+
249 | 15 or 31L | 31 or 31R |
250 +--------------+--------------+
253 The following is a version of pa_parse_number that
254 handles the L/R notation and returns the correct
255 value to put into the instruction register field.
256 The correct value to put into the instruction is
257 encoded in the structure 'pa_89_fp_reg_struct'. */
259 struct pa_89_fp_reg_struct
261 /* The register number. */
268 /* Additional information needed to build argument relocation stubs. */
271 /* The argument relocation specification. */
272 unsigned int arg_reloc
;
274 /* Number of arguments. */
275 unsigned int arg_count
;
278 /* This structure defines an entry in the subspace dictionary
281 struct subspace_dictionary_chain
283 /* Index of containing space. */
284 unsigned long ssd_space_index
;
286 /* Nonzero if this space has been defined by the user code. */
287 unsigned int ssd_defined
;
289 /* Which quadrant within the space this subspace should be loaded into. */
290 unsigned char ssd_quadrant
;
292 /* Alignment (in bytes) for this subspace. */
293 unsigned long ssd_alignment
;
295 /* Access control bits to determine read/write/execute permissions
296 as well as gateway privilege promotions. */
297 unsigned char ssd_access_control_bits
;
299 /* A sorting key so that it is possible to specify ordering of
300 subspaces within a space. */
301 unsigned char ssd_sort_key
;
303 /* Nonzero of this space should be zero filled. */
304 unsigned long ssd_zero
;
306 /* Nonzero if this is a common subspace. */
307 unsigned char ssd_common
;
309 /* Nonzero if this is a common subspace which allows symbols to be
311 unsigned char ssd_dup_common
;
313 /* Nonzero if this subspace is loadable. Note loadable subspaces
314 must be contained within loadable spaces; unloadable subspaces
315 must be contained in unloadable spaces. */
316 unsigned char ssd_loadable
;
318 /* Nonzero if this subspace contains only code. */
319 unsigned char ssd_code_only
;
321 /* Starting offset of this subspace. */
322 unsigned long ssd_subspace_start
;
324 /* Length of this subspace. */
325 unsigned long ssd_subspace_length
;
327 /* Name of this subspace. */
330 /* GAS segment and subsegment associated with this subspace. */
334 /* Index of this subspace within the subspace dictionary of the object
335 file. Not used until object file is written. */
336 int object_file_index
;
338 /* The size of the last alignment request for this subspace. */
341 /* Next space in the subspace dictionary chain. */
342 struct subspace_dictionary_chain
*ssd_next
;
345 typedef struct subspace_dictionary_chain ssd_chain_struct
;
347 /* This structure defines an entry in the subspace dictionary
350 struct space_dictionary_chain
353 /* Holds the index into the string table of the name of this
355 unsigned int sd_name_index
;
357 /* Nonzero if the space is loadable. */
358 unsigned int sd_loadable
;
360 /* Nonzero if this space has been defined by the user code or
361 as a default space. */
362 unsigned int sd_defined
;
364 /* Nonzero if this spaces has been defined by the user code. */
365 unsigned int sd_user_defined
;
367 /* Nonzero if this space is not sharable. */
368 unsigned int sd_private
;
370 /* The space number (or index). */
371 unsigned int sd_spnum
;
373 /* The sort key for this space. May be used to determine how to lay
374 out the spaces within the object file. */
375 unsigned char sd_sort_key
;
377 /* The name of this subspace. */
380 /* GAS segment to which this subspace corresponds. */
383 /* Current subsegment number being used. */
386 /* The chain of subspaces contained within this space. */
387 ssd_chain_struct
*sd_subspaces
;
389 /* The next entry in the space dictionary chain. */
390 struct space_dictionary_chain
*sd_next
;
393 typedef struct space_dictionary_chain sd_chain_struct
;
395 /* Structure for previous label tracking. Needed so that alignments,
396 callinfo declarations, etc can be easily attached to a particular
398 typedef struct label_symbol_struct
400 struct symbol
*lss_label
;
401 sd_chain_struct
*lss_space
;
402 struct label_symbol_struct
*lss_next
;
406 /* This structure defines attributes of the default subspace
407 dictionary entries. */
409 struct default_subspace_dict
411 /* Name of the subspace. */
414 /* FIXME. Is this still needed? */
417 /* Nonzero if this subspace is loadable. */
420 /* Nonzero if this subspace contains only code. */
423 /* Nonzero if this is a common subspace. */
426 /* Nonzero if this is a common subspace which allows symbols
427 to be multiply defined. */
430 /* Nonzero if this subspace should be zero filled. */
433 /* Sort key for this subspace. */
436 /* Access control bits for this subspace. Can represent RWX access
437 as well as privilege level changes for gateways. */
440 /* Index of containing space. */
443 /* Alignment (in bytes) of this subspace. */
446 /* Quadrant within space where this subspace should be loaded. */
449 /* An index into the default spaces array. */
452 /* An alias for this section (or NULL if no alias exists). */
455 /* Subsegment associated with this subspace. */
459 /* This structure defines attributes of the default space
460 dictionary entries. */
462 struct default_space_dict
464 /* Name of the space. */
467 /* Space number. It is possible to identify spaces within
468 assembly code numerically! */
471 /* Nonzero if this space is loadable. */
474 /* Nonzero if this space is "defined". FIXME is still needed */
477 /* Nonzero if this space can not be shared. */
480 /* Sort key for this space. */
483 /* Segment associated with this space. */
486 /* An alias for this section (or NULL if no alias exists). */
490 /* Extra information needed to perform fixups (relocations) on the PA. */
491 struct hppa_fix_struct
493 /* The field selector. */
494 enum hppa_reloc_field_selector_type fx_r_field
;
499 /* Format of fixup. */
502 /* Argument relocation bits. */
505 /* The unwind descriptor associated with this fixup. */
509 /* Structure to hold information about predefined registers. */
517 /* This structure defines the mapping from a FP condition string
518 to a condition number which can be recorded in an instruction. */
525 /* This structure defines a mapping from a field selector
526 string to a field selector type. */
527 struct selector_entry
533 /* Prototypes for functions local to tc-hppa.c. */
535 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
536 static void pa_cons
PARAMS ((int));
537 static void pa_data
PARAMS ((int));
538 static void pa_desc
PARAMS ((int));
539 static void pa_float_cons
PARAMS ((int));
540 static void pa_fill
PARAMS ((int));
541 static void pa_lcomm
PARAMS ((int));
542 static void pa_lsym
PARAMS ((int));
543 static void pa_stringer
PARAMS ((int));
544 static void pa_text
PARAMS ((int));
545 static void pa_version
PARAMS ((int));
546 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
547 static int get_expression
PARAMS ((char *));
548 static int pa_get_absolute_expression
PARAMS ((struct pa_it
*, char **));
549 static int evaluate_absolute
PARAMS ((struct pa_it
*));
550 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
551 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
552 static int pa_parse_nullif
PARAMS ((char **));
553 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
554 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
555 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
556 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
557 static void pa_block
PARAMS ((int));
558 static void pa_call
PARAMS ((int));
559 static void pa_call_args
PARAMS ((struct call_desc
*));
560 static void pa_callinfo
PARAMS ((int));
561 static void pa_code
PARAMS ((int));
562 static void pa_comm
PARAMS ((int));
563 static void pa_copyright
PARAMS ((int));
564 static void pa_end
PARAMS ((int));
565 static void pa_enter
PARAMS ((int));
566 static void pa_entry
PARAMS ((int));
567 static void pa_equ
PARAMS ((int));
568 static void pa_exit
PARAMS ((int));
569 static void pa_export
PARAMS ((int));
570 static void pa_type_args
PARAMS ((symbolS
*, int));
571 static void pa_import
PARAMS ((int));
572 static void pa_label
PARAMS ((int));
573 static void pa_leave
PARAMS ((int));
574 static void pa_origin
PARAMS ((int));
575 static void pa_proc
PARAMS ((int));
576 static void pa_procend
PARAMS ((int));
577 static void pa_space
PARAMS ((int));
578 static void pa_spnum
PARAMS ((int));
579 static void pa_subspace
PARAMS ((int));
580 static void pa_param
PARAMS ((int));
581 static void pa_undefine_label
PARAMS ((void));
582 static int need_89_opcode
PARAMS ((struct pa_it
*,
583 struct pa_89_fp_reg_struct
*));
584 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
585 static label_symbol_struct
*pa_get_label
PARAMS ((void));
586 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, char,
589 static ssd_chain_struct
* create_new_subspace
PARAMS ((sd_chain_struct
*,
594 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
595 char *, char, char, char,
596 char, char, char, int,
599 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
600 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
601 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
602 static ssd_chain_struct
* pa_subsegment_to_subspace
PARAMS ((asection
*,
604 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
605 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
606 static void pa_ip
PARAMS ((char *));
607 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
608 long, expressionS
*, int,
609 bfd_reloc_code_real_type
,
610 enum hppa_reloc_field_selector_type
,
612 static void md_apply_fix_1
PARAMS ((fixS
*, long));
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 void pa_align_subseg
PARAMS ((asection
*, subsegT
));
621 static int log2
PARAMS ((int));
622 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
623 static unsigned int pa_stringer_aux
PARAMS ((char *));
624 static void pa_spaces_begin
PARAMS ((void));
627 /* File and gloally scoped variable declarations. */
629 /* Root and final entry in the space chain. */
630 static sd_chain_struct
*space_dict_root
;
631 static sd_chain_struct
*space_dict_last
;
633 /* The current space and subspace. */
634 static sd_chain_struct
*current_space
;
635 static ssd_chain_struct
*current_subspace
;
637 /* Root of the call_info chain. */
638 static struct call_info
*call_info_root
;
640 /* The last call_info (for functions) structure
641 seen so it can be associated with fixups and
643 static struct call_info
*last_call_info
;
645 /* The last call description (for actual calls). */
646 static struct call_desc last_call_desc
;
648 /* Relaxation isn't supported for the PA yet. */
649 const relax_typeS md_relax_table
[] = {0};
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 has completed exit processing for the
803 current procedure. */
804 static int exit_processing_complete
;
806 /* Nonzero if the assembler is currently within a procedure definition. */
807 static int within_procedure
;
809 /* Handle on strucutre which keep track of the last symbol
810 seen in each subspace. */
811 static label_symbol_struct
*label_symbols_rootp
= NULL
;
813 /* Holds the last field selector. */
814 static int hppa_field_selector
;
816 /* Nonzero if errors are to be printed. */
817 static int print_errors
= 1;
819 /* List of registers that are pre-defined:
821 Each general register has one predefined name of the form
822 %r<REGNUM> which has the value <REGNUM>.
824 Space and control registers are handled in a similar manner,
825 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
827 Likewise for the floating point registers, but of the form
828 %fr<REGNUM>. Floating point registers have additional predefined
829 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
830 again have the value <REGNUM>.
832 Many registers also have synonyms:
834 %r26 - %r23 have %arg0 - %arg3 as synonyms
835 %r28 - %r29 have %ret0 - %ret1 as synonyms
836 %r30 has %sp as a synonym
837 %r27 has %dp as a synonym
838 %r2 has %rp as a synonym
840 Almost every control register has a synonym; they are not listed
843 The table is sorted. Suitable for searching by a binary search. */
845 static const struct pd_reg pre_defined_registers
[] =
1057 /* This table is sorted by order of the length of the string. This is
1058 so we check for <> before we check for <. If we had a <> and checked
1059 for < first, we would get a false match. */
1060 static const struct fp_cond_map fp_cond_map
[] =
1096 static const struct selector_entry selector_table
[] =
1131 /* default space and subspace dictionaries */
1133 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1134 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1136 /* pre-defined subsegments (subspaces) for the HPPA. */
1137 #define SUBSEG_CODE 0
1138 #define SUBSEG_DATA 0
1139 #define SUBSEG_LIT 1
1140 #define SUBSEG_BSS 2
1141 #define SUBSEG_UNWIND 3
1142 #define SUBSEG_GDB_STRINGS 0
1143 #define SUBSEG_GDB_SYMBOLS 1
1145 static struct default_subspace_dict pa_def_subspaces
[] =
1147 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1148 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1149 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1150 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1151 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1152 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1155 static struct default_space_dict pa_def_spaces
[] =
1157 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1158 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1159 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1162 /* Misc local definitions used by the assembler. */
1164 /* Return nonzero if the string pointed to by S potentially represents
1165 a right or left half of a FP register */
1166 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1167 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1169 /* These macros are used to maintain spaces/subspaces. */
1170 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1171 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1172 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1173 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1174 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1175 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1176 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1177 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1179 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1180 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1181 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1182 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1183 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1184 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1185 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1186 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1187 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1188 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1189 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1190 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1191 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1192 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1194 /* Insert FIELD into OPCODE starting at bit START. Continue pa_ip
1195 main loop after insertion. */
1197 #define INSERT_FIELD_AND_CONTINUE(OPCODE, FIELD, START) \
1199 ((OPCODE) |= (FIELD) << (START)); \
1203 /* Simple range checking for FIELD againt HIGH and LOW bounds.
1204 IGNORE is used to suppress the error message. */
1206 #define CHECK_FIELD(FIELD, HIGH, LOW, IGNORE) \
1208 if ((FIELD) > (HIGH) || (FIELD) < (LOW)) \
1211 as_bad ("Field out of range [%d..%d] (%d).", (LOW), (HIGH), \
1217 #define is_DP_relative(exp) \
1218 ((exp).X_op == O_subtract \
1219 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1221 #define is_PC_relative(exp) \
1222 ((exp).X_op == O_subtract \
1223 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1225 #define is_complex(exp) \
1226 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1228 /* Actual functions to implement the PA specific code for the assembler. */
1230 /* Returns a pointer to the label_symbol_struct for the current space.
1231 or NULL if no label_symbol_struct exists for the current space. */
1233 static label_symbol_struct
*
1236 label_symbol_struct
*label_chain
;
1237 sd_chain_struct
*space_chain
= current_space
;
1239 for (label_chain
= label_symbols_rootp
;
1241 label_chain
= label_chain
->lss_next
)
1242 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1248 /* Defines a label for the current space. If one is already defined,
1249 this function will replace it with the new label. */
1252 pa_define_label (symbol
)
1255 label_symbol_struct
*label_chain
= pa_get_label ();
1256 sd_chain_struct
*space_chain
= current_space
;
1259 label_chain
->lss_label
= symbol
;
1262 /* Create a new label entry and add it to the head of the chain. */
1264 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1265 label_chain
->lss_label
= symbol
;
1266 label_chain
->lss_space
= space_chain
;
1267 label_chain
->lss_next
= NULL
;
1269 if (label_symbols_rootp
)
1270 label_chain
->lss_next
= label_symbols_rootp
;
1272 label_symbols_rootp
= label_chain
;
1276 /* Removes a label definition for the current space.
1277 If there is no label_symbol_struct entry, then no action is taken. */
1280 pa_undefine_label ()
1282 label_symbol_struct
*label_chain
;
1283 label_symbol_struct
*prev_label_chain
= NULL
;
1284 sd_chain_struct
*space_chain
= current_space
;
1286 for (label_chain
= label_symbols_rootp
;
1288 label_chain
= label_chain
->lss_next
)
1290 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1292 /* Remove the label from the chain and free its memory. */
1293 if (prev_label_chain
)
1294 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1296 label_symbols_rootp
= label_chain
->lss_next
;
1301 prev_label_chain
= label_chain
;
1306 /* An HPPA-specific version of fix_new. This is required because the HPPA
1307 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1308 results in the creation of an instance of an hppa_fix_struct. An
1309 hppa_fix_struct stores the extra information along with a pointer to the
1310 original fixS. This is attached to the original fixup via the
1311 tc_fix_data field. */
1314 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1315 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1319 symbolS
*add_symbol
;
1323 bfd_reloc_code_real_type r_type
;
1324 enum hppa_reloc_field_selector_type r_field
;
1331 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1332 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1335 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1337 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1338 new_fix
->tc_fix_data
= hppa_fix
;
1339 hppa_fix
->fx_r_type
= r_type
;
1340 hppa_fix
->fx_r_field
= r_field
;
1341 hppa_fix
->fx_r_format
= r_format
;
1342 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1345 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1347 /* If necessary call BFD backend function to attach the
1348 unwind bits to the target dependent parts of a BFD symbol.
1350 #ifdef obj_attach_unwind_info
1351 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1355 /* foo-$global$ is used to access non-automatic storage. $global$
1356 is really just a marker and has served its purpose, so eliminate
1357 it now so as not to confuse write.c. */
1358 if (!strcmp (S_GET_NAME (new_fix
->fx_subsy
), "$global$"))
1359 new_fix
->fx_subsy
= NULL
;
1362 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1363 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1366 parse_cons_expression_hppa (exp
)
1369 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1373 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1374 hppa_field_selector is set by the parse_cons_expression_hppa. */
1377 cons_fix_new_hppa (frag
, where
, size
, exp
)
1383 unsigned int reloc_type
;
1385 if (is_DP_relative (*exp
))
1386 reloc_type
= R_HPPA_GOTOFF
;
1387 else if (is_complex (*exp
))
1388 reloc_type
= R_HPPA_COMPLEX
;
1390 reloc_type
= R_HPPA
;
1392 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1393 as_warn ("Invalid field selector. Assuming F%%.");
1395 fix_new_hppa (frag
, where
, size
,
1396 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1397 hppa_field_selector
, 32, 0, (char *) 0);
1399 /* Reset field selector to its default state. */
1400 hppa_field_selector
= 0;
1403 /* This function is called once, at assembler startup time. It should
1404 set up all the tables, etc. that the MD part of the assembler will need. */
1409 const char *retval
= NULL
;
1413 last_call_info
= NULL
;
1414 call_info_root
= NULL
;
1416 /* Folding of text and data segments fails miserably on the PA.
1417 Warn user and disable "-R" option. */
1420 as_warn ("-R option not supported on this target.");
1421 flag_readonly_data_in_text
= 0;
1427 op_hash
= hash_new ();
1428 if (op_hash
== NULL
)
1429 as_fatal ("Virtual memory exhausted");
1431 while (i
< NUMOPCODES
)
1433 const char *name
= pa_opcodes
[i
].name
;
1434 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*)&pa_opcodes
[i
]);
1435 if (retval
!= NULL
&& *retval
!= '\0')
1437 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1442 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1443 != pa_opcodes
[i
].match
)
1445 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1446 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1451 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1455 as_fatal ("Broken assembler. No assembly attempted.");
1457 /* SOM will change text_section. To make sure we never put
1458 anything into the old one switch to the new one now. */
1459 subseg_set (text_section
, 0);
1462 /* Called at the end of assembling a source file. Nothing to do
1463 at this point on the PA. */
1471 /* Assemble a single instruction storing it into a frag. */
1478 /* The had better be something to assemble. */
1481 /* Assemble the instruction. Results are saved into "the_insn". */
1484 /* Get somewhere to put the assembled instrution. */
1487 /* Output the opcode. */
1488 md_number_to_chars (to
, the_insn
.opcode
, 4);
1490 /* If necessary output more stuff. */
1491 if (the_insn
.reloc
!= R_HPPA_NONE
)
1492 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1493 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1494 the_insn
.reloc
, the_insn
.field_selector
,
1495 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1499 /* Do the real work for assembling a single instruction. Store results
1500 into the global "the_insn" variable.
1502 FIXME: Should define and use some functions/macros to handle
1503 various common insertions of information into the opcode. */
1509 char *error_message
= "";
1510 char *s
, c
, *argstart
, *name
, *save_s
;
1514 int cmpltr
, nullif
, flag
, cond
, num
;
1515 unsigned long opcode
;
1516 struct pa_opcode
*insn
;
1518 /* Skip to something interesting. */
1519 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1538 as_bad ("Unknown opcode: `%s'", str
);
1544 /* Convert everything into lower case. */
1547 if (isupper (*save_s
))
1548 *save_s
= tolower (*save_s
);
1552 /* Look up the opcode in the has table. */
1553 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1555 as_bad ("Unknown opcode: `%s'", str
);
1564 /* Mark the location where arguments for the instruction start, then
1565 start processing them. */
1569 /* Do some initialization. */
1570 opcode
= insn
->match
;
1571 bzero (&the_insn
, sizeof (the_insn
));
1573 the_insn
.reloc
= R_HPPA_NONE
;
1575 /* Build the opcode, checking as we go to make
1576 sure that the operands match. */
1577 for (args
= insn
->args
;; ++args
)
1582 /* End of arguments. */
1598 /* These must match exactly. */
1607 /* Handle a 5 bit register or control register field at 10. */
1610 num
= pa_parse_number (&s
, 0);
1611 CHECK_FIELD (num
, 31, 0, 0);
1612 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
1614 /* Handle a 5 bit register field at 15. */
1616 num
= pa_parse_number (&s
, 0);
1617 CHECK_FIELD (num
, 31, 0, 0);
1618 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1620 /* Handle a 5 bit register field at 31. */
1623 num
= pa_parse_number (&s
, 0);
1624 CHECK_FIELD (num
, 31, 0, 0);
1625 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1627 /* Handle a 5 bit field length at 31. */
1629 num
= pa_get_absolute_expression (&the_insn
, &s
);
1631 CHECK_FIELD (num
, 32, 1, 0);
1632 INSERT_FIELD_AND_CONTINUE (opcode
, 32 - num
, 0);
1634 /* Handle a 5 bit immediate at 15. */
1636 num
= pa_get_absolute_expression (&the_insn
, &s
);
1638 CHECK_FIELD (num
, 15, -16, 0);
1639 low_sign_unext (num
, 5, &num
);
1640 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1642 /* Handle a 5 bit immediate at 31. */
1644 num
= pa_get_absolute_expression (&the_insn
, &s
);
1646 CHECK_FIELD (num
, 15, -16, 0)
1647 low_sign_unext (num
, 5, &num
);
1648 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1650 /* Handle an unsigned 5 bit immediate at 31. */
1652 num
= pa_get_absolute_expression (&the_insn
, &s
);
1654 CHECK_FIELD (num
, 31, 0, 0);
1655 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
1657 /* Handle an unsigned 5 bit immediate at 15. */
1659 num
= pa_get_absolute_expression (&the_insn
, &s
);
1661 CHECK_FIELD (num
, 31, 0, 0);
1662 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 16);
1664 /* Handle a 2 bit space identifier at 17. */
1666 num
= pa_parse_number (&s
, 0);
1667 CHECK_FIELD (num
, 3, 0, 1);
1668 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 14);
1670 /* Handle a 3 bit space identifier at 18. */
1672 num
= pa_parse_number (&s
, 0);
1673 CHECK_FIELD (num
, 7, 0, 1);
1674 dis_assemble_3 (num
, &num
);
1675 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
1677 /* Handle a completer for an indexing load or store. */
1683 while (*s
== ',' && i
< 2)
1686 if (strncasecmp (s
, "sm", 2) == 0)
1693 else if (strncasecmp (s
, "m", 1) == 0)
1695 else if (strncasecmp (s
, "s", 1) == 0)
1698 as_bad ("Invalid Indexed Load Completer.");
1703 as_bad ("Invalid Indexed Load Completer Syntax.");
1705 INSERT_FIELD_AND_CONTINUE (opcode
, uu
, 13);
1708 /* Handle a short load/store completer. */
1716 if (strncasecmp (s
, "ma", 2) == 0)
1721 else if (strncasecmp (s
, "mb", 2) == 0)
1727 as_bad ("Invalid Short Load/Store Completer.");
1731 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1734 /* Handle a stbys completer. */
1740 while (*s
== ',' && i
< 2)
1743 if (strncasecmp (s
, "m", 1) == 0)
1745 else if (strncasecmp (s
, "b", 1) == 0)
1747 else if (strncasecmp (s
, "e", 1) == 0)
1750 as_bad ("Invalid Store Bytes Short Completer");
1755 as_bad ("Invalid Store Bytes Short Completer");
1757 INSERT_FIELD_AND_CONTINUE (opcode
, a
, 13);
1760 /* Handle a non-negated compare/stubtract condition. */
1762 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1765 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1768 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1770 /* Handle a negated or non-negated compare/subtract condition. */
1773 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1777 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1780 as_bad ("Invalid Compare/Subtract Condition.");
1785 /* Negated condition requires an opcode change. */
1789 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1791 /* Handle a negated or non-negated add condition. */
1794 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1798 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1801 as_bad ("Invalid Compare/Subtract Condition");
1806 /* Negated condition requires an opcode change. */
1810 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
1812 /* Handle a compare/subtract condition. */
1819 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1824 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1827 as_bad ("Invalid Compare/Subtract Condition");
1831 opcode
|= cmpltr
<< 13;
1832 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1834 /* Handle a non-negated add condition. */
1843 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1847 if (strcmp (name
, "=") == 0)
1849 else if (strcmp (name
, "<") == 0)
1851 else if (strcmp (name
, "<=") == 0)
1853 else if (strcasecmp (name
, "nuv") == 0)
1855 else if (strcasecmp (name
, "znv") == 0)
1857 else if (strcasecmp (name
, "sv") == 0)
1859 else if (strcasecmp (name
, "od") == 0)
1861 else if (strcasecmp (name
, "n") == 0)
1863 else if (strcasecmp (name
, "tr") == 0)
1868 else if (strcasecmp (name
, "<>") == 0)
1873 else if (strcasecmp (name
, ">=") == 0)
1878 else if (strcasecmp (name
, ">") == 0)
1883 else if (strcasecmp (name
, "uv") == 0)
1888 else if (strcasecmp (name
, "vnz") == 0)
1893 else if (strcasecmp (name
, "nsv") == 0)
1898 else if (strcasecmp (name
, "ev") == 0)
1904 as_bad ("Invalid Add Condition: %s", name
);
1907 nullif
= pa_parse_nullif (&s
);
1908 opcode
|= nullif
<< 1;
1909 opcode
|= cmpltr
<< 13;
1910 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1912 /* HANDLE a logical instruction condition. */
1920 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1924 if (strcmp (name
, "=") == 0)
1926 else if (strcmp (name
, "<") == 0)
1928 else if (strcmp (name
, "<=") == 0)
1930 else if (strcasecmp (name
, "od") == 0)
1932 else if (strcasecmp (name
, "tr") == 0)
1937 else if (strcmp (name
, "<>") == 0)
1942 else if (strcmp (name
, ">=") == 0)
1947 else if (strcmp (name
, ">") == 0)
1952 else if (strcasecmp (name
, "ev") == 0)
1958 as_bad ("Invalid Logical Instruction Condition.");
1961 opcode
|= cmpltr
<< 13;
1962 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
1964 /* Handle a unit instruction condition. */
1971 if (strncasecmp (s
, "sbz", 3) == 0)
1976 else if (strncasecmp (s
, "shz", 3) == 0)
1981 else if (strncasecmp (s
, "sdc", 3) == 0)
1986 else if (strncasecmp (s
, "sbc", 3) == 0)
1991 else if (strncasecmp (s
, "shc", 3) == 0)
1996 else if (strncasecmp (s
, "tr", 2) == 0)
2002 else if (strncasecmp (s
, "nbz", 3) == 0)
2008 else if (strncasecmp (s
, "nhz", 3) == 0)
2014 else if (strncasecmp (s
, "ndc", 3) == 0)
2020 else if (strncasecmp (s
, "nbc", 3) == 0)
2026 else if (strncasecmp (s
, "nhc", 3) == 0)
2033 as_bad ("Invalid Logical Instruction Condition.");
2035 opcode
|= cmpltr
<< 13;
2036 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 12);
2038 /* Handle a shift/extract/deposit condition. */
2046 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2050 if (strcmp (name
, "=") == 0)
2052 else if (strcmp (name
, "<") == 0)
2054 else if (strcasecmp (name
, "od") == 0)
2056 else if (strcasecmp (name
, "tr") == 0)
2058 else if (strcmp (name
, "<>") == 0)
2060 else if (strcmp (name
, ">=") == 0)
2062 else if (strcasecmp (name
, "ev") == 0)
2064 /* Handle movb,n. Put things back the way they were.
2065 This includes moving s back to where it started. */
2066 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
2073 as_bad ("Invalid Shift/Extract/Deposit Condition.");
2076 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2078 /* Handle bvb and bb conditions. */
2084 if (strncmp (s
, "<", 1) == 0)
2089 else if (strncmp (s
, ">=", 2) == 0)
2095 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2097 INSERT_FIELD_AND_CONTINUE (opcode
, cmpltr
, 13);
2099 /* Handle a system control completer. */
2101 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2109 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 5);
2111 /* Handle a nullification completer for branch instructions. */
2113 nullif
= pa_parse_nullif (&s
);
2114 INSERT_FIELD_AND_CONTINUE (opcode
, nullif
, 1);
2116 /* Handle a 11 bit immediate at 31. */
2118 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2121 if (the_insn
.exp
.X_op
== O_constant
)
2123 num
= evaluate_absolute (&the_insn
);
2124 CHECK_FIELD (num
, 1023, -1024, 0);
2125 low_sign_unext (num
, 11, &num
);
2126 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2130 if (is_DP_relative (the_insn
.exp
))
2131 the_insn
.reloc
= R_HPPA_GOTOFF
;
2132 else if (is_PC_relative (the_insn
.exp
))
2133 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2134 else if (is_complex (the_insn
.exp
))
2135 the_insn
.reloc
= R_HPPA_COMPLEX
;
2137 the_insn
.reloc
= R_HPPA
;
2138 the_insn
.format
= 11;
2142 /* Handle a 14 bit immediate at 31. */
2144 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2147 if (the_insn
.exp
.X_op
== O_constant
)
2149 num
= evaluate_absolute (&the_insn
);
2150 CHECK_FIELD (num
, 8191, -8192, 0);
2151 low_sign_unext (num
, 14, &num
);
2152 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2156 if (is_DP_relative (the_insn
.exp
))
2157 the_insn
.reloc
= R_HPPA_GOTOFF
;
2158 else if (is_PC_relative (the_insn
.exp
))
2159 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2160 else if (is_complex (the_insn
.exp
))
2161 the_insn
.reloc
= R_HPPA_COMPLEX
;
2163 the_insn
.reloc
= R_HPPA
;
2164 the_insn
.format
= 14;
2168 /* Handle a 21 bit immediate at 31. */
2170 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2173 if (the_insn
.exp
.X_op
== O_constant
)
2175 num
= evaluate_absolute (&the_insn
);
2176 CHECK_FIELD (num
, 2097151, 0, 0);
2177 dis_assemble_21 (num
, &num
);
2178 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 0);
2182 if (is_DP_relative (the_insn
.exp
))
2183 the_insn
.reloc
= R_HPPA_GOTOFF
;
2184 else if (is_PC_relative (the_insn
.exp
))
2185 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2186 else if (is_complex (the_insn
.exp
))
2187 the_insn
.reloc
= R_HPPA_COMPLEX
;
2189 the_insn
.reloc
= R_HPPA
;
2190 the_insn
.format
= 21;
2194 /* Handle a 12 bit branch displacement. */
2196 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2200 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L$0\001"))
2202 unsigned int w1
, w
, result
;
2204 num
= evaluate_absolute (&the_insn
);
2207 as_bad ("Branch to unaligned address");
2210 CHECK_FIELD (num
, 8191, -8192, 0);
2211 sign_unext ((num
- 8) >> 2, 12, &result
);
2212 dis_assemble_12 (result
, &w1
, &w
);
2213 INSERT_FIELD_AND_CONTINUE (opcode
, ((w1
<< 2) | w
), 0);
2217 if (is_complex (the_insn
.exp
))
2218 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2220 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2221 the_insn
.format
= 12;
2222 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2223 bzero (&last_call_desc
, sizeof (struct call_desc
));
2228 /* Handle a 17 bit branch displacement. */
2230 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2234 if (! the_insn
.exp
.X_add_symbol
2235 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2238 unsigned int w2
, w1
, w
, result
;
2240 num
= evaluate_absolute (&the_insn
);
2243 as_bad ("Branch to unaligned address");
2246 CHECK_FIELD (num
, 262143, -262144, 0);
2248 if (the_insn
.exp
.X_add_symbol
)
2251 sign_unext (num
>> 2, 17, &result
);
2252 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2253 INSERT_FIELD_AND_CONTINUE (opcode
,
2254 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2258 if (is_complex (the_insn
.exp
))
2259 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2261 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2262 the_insn
.format
= 17;
2263 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2264 bzero (&last_call_desc
, sizeof (struct call_desc
));
2268 /* Handle an absolute 17 bit branch target. */
2270 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2274 if (! the_insn
.exp
.X_add_symbol
2275 || !strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2278 unsigned int w2
, w1
, w
, result
;
2280 num
= evaluate_absolute (&the_insn
);
2283 as_bad ("Branch to unaligned address");
2286 CHECK_FIELD (num
, 262143, -262144, 0);
2288 if (the_insn
.exp
.X_add_symbol
)
2291 sign_unext (num
>> 2, 17, &result
);
2292 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2293 INSERT_FIELD_AND_CONTINUE (opcode
,
2294 ((w2
<< 2) | (w1
<< 16) | w
), 0);
2298 if (is_complex (the_insn
.exp
))
2299 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2301 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2302 the_insn
.format
= 17;
2306 /* Handle a 5 bit shift count at 26. */
2308 num
= pa_get_absolute_expression (&the_insn
, &s
);
2310 CHECK_FIELD (num
, 31, 0, 0);
2311 INSERT_FIELD_AND_CONTINUE (opcode
, 31 - num
, 5);
2313 /* Handle a 5 bit bit position at 26. */
2315 num
= pa_get_absolute_expression (&the_insn
, &s
);
2317 CHECK_FIELD (num
, 31, 0, 0);
2318 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 5);
2320 /* Handle a 5 bit immediate at 10. */
2322 num
= pa_get_absolute_expression (&the_insn
, &s
);
2324 CHECK_FIELD (num
, 31, 0, 0);
2325 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 21);
2327 /* Handle a 13 bit immediate at 18. */
2329 num
= pa_get_absolute_expression (&the_insn
, &s
);
2331 CHECK_FIELD (num
, 4095, -4096, 0);
2332 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 13);
2334 /* Handle a 26 bit immediate at 31. */
2336 num
= pa_get_absolute_expression (&the_insn
, &s
);
2338 CHECK_FIELD (num
, 671108864, 0, 0);
2339 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 1);
2341 /* Handle a 3 bit SFU identifier at 25. */
2343 num
= pa_get_absolute_expression (&the_insn
, &s
);
2345 CHECK_FIELD (num
, 7, 0, 0);
2346 INSERT_FIELD_AND_CONTINUE (opcode
, num
, 6);
2348 /* We don't support any of these. FIXME. */
2355 /* Handle a source FP operand format completer. */
2357 flag
= pa_parse_fp_format (&s
);
2358 the_insn
.fpof1
= flag
;
2359 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 11);
2361 /* Handle a destination FP operand format completer. */
2363 /* pa_parse_format needs the ',' prefix. */
2365 flag
= pa_parse_fp_format (&s
);
2366 the_insn
.fpof2
= flag
;
2367 INSERT_FIELD_AND_CONTINUE (opcode
, flag
, 13);
2369 /* Handle FP compare conditions. */
2371 cond
= pa_parse_fp_cmp_cond (&s
);
2372 INSERT_FIELD_AND_CONTINUE (opcode
, cond
, 0);
2374 /* Handle L/R register halves like 't'. */
2377 struct pa_89_fp_reg_struct result
;
2379 pa_parse_number (&s
, &result
);
2380 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2381 opcode
|= result
.number_part
;
2383 /* 0x30 opcodes are FP arithmetic operation opcodes
2384 and need to be turned into 0x38 opcodes. This
2385 is not necessary for loads/stores. */
2386 if (need_89_opcode (&the_insn
, &result
)
2387 && ((opcode
& 0xfc000000) == 0x30000000))
2390 INSERT_FIELD_AND_CONTINUE (opcode
, result
.l_r_select
& 1, 6);
2393 /* Handle L/R register halves like 'b'. */
2396 struct pa_89_fp_reg_struct result
;
2398 pa_parse_number (&s
, &result
);
2399 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2400 opcode
|= result
.number_part
<< 21;
2401 if (need_89_opcode (&the_insn
, &result
))
2403 opcode
|= (result
.l_r_select
& 1) << 7;
2409 /* Handle L/R register halves like 'x'. */
2412 struct pa_89_fp_reg_struct result
;
2414 pa_parse_number (&s
, &result
);
2415 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2416 opcode
|= (result
.number_part
& 0x1f) << 16;
2417 if (need_89_opcode (&the_insn
, &result
))
2419 opcode
|= (result
.l_r_select
& 1) << 12;
2425 /* Handle a 5 bit register field at 10. */
2428 struct pa_89_fp_reg_struct result
;
2430 pa_parse_number (&s
, &result
);
2431 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2432 if (the_insn
.fpof1
== SGL
)
2434 result
.number_part
&= 0xF;
2435 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2437 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 21);
2440 /* Handle a 5 bit register field at 15. */
2443 struct pa_89_fp_reg_struct result
;
2445 pa_parse_number (&s
, &result
);
2446 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2447 if (the_insn
.fpof1
== SGL
)
2449 result
.number_part
&= 0xF;
2450 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2452 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 16);
2455 /* Handle a 5 bit register field at 31. */
2458 struct pa_89_fp_reg_struct result
;
2460 pa_parse_number (&s
, &result
);
2461 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2462 if (the_insn
.fpof1
== SGL
)
2464 result
.number_part
&= 0xF;
2465 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2467 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 0);
2470 /* Handle a 5 bit register field at 20. */
2473 struct pa_89_fp_reg_struct result
;
2475 pa_parse_number (&s
, &result
);
2476 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2477 if (the_insn
.fpof1
== SGL
)
2479 result
.number_part
&= 0xF;
2480 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2482 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 11);
2485 /* Handle a 5 bit register field at 25. */
2488 struct pa_89_fp_reg_struct result
;
2490 pa_parse_number (&s
, &result
);
2491 CHECK_FIELD (result
.number_part
, 31, 0, 0);
2492 if (the_insn
.fpof1
== SGL
)
2494 result
.number_part
&= 0xF;
2495 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2497 INSERT_FIELD_AND_CONTINUE (opcode
, result
.number_part
, 6);
2500 /* Handle a floating point operand format at 26.
2501 Only allows single and double precision. */
2503 flag
= pa_parse_fp_format (&s
);
2509 the_insn
.fpof1
= flag
;
2515 as_bad ("Invalid Floating Point Operand Format.");
2525 /* Check if the args matched. */
2528 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2529 && !strcmp (insn
->name
, insn
[1].name
))
2537 as_bad ("Invalid operands %s", error_message
);
2544 the_insn
.opcode
= opcode
;
2548 /* Turn a string in input_line_pointer into a floating point constant of type
2549 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2550 emitted is stored in *sizeP . An error message or NULL is returned. */
2552 #define MAX_LITTLENUMS 6
2555 md_atof (type
, litP
, sizeP
)
2561 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2562 LITTLENUM_TYPE
*wordP
;
2594 return "Bad call to MD_ATOF()";
2596 t
= atof_ieee (input_line_pointer
, type
, words
);
2598 input_line_pointer
= t
;
2599 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2600 for (wordP
= words
; prec
--;)
2602 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2603 litP
+= sizeof (LITTLENUM_TYPE
);
2608 /* Write out big-endian. */
2611 md_number_to_chars (buf
, val
, n
)
2633 /* Translate internal representation of relocation info to BFD target
2637 tc_gen_reloc (section
, fixp
)
2642 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2643 bfd_reloc_code_real_type code
;
2644 static int unwind_reloc_fixp_cnt
= 0;
2645 static arelent
*unwind_reloc_entryP
= NULL
;
2646 static arelent
*no_relocs
= NULL
;
2648 bfd_reloc_code_real_type
**codes
;
2652 if (fixp
->fx_addsy
== 0)
2654 assert (hppa_fixp
!= 0);
2655 assert (section
!= 0);
2658 /* Yuk. I would really like to push all this ELF specific unwind
2659 crud into BFD and the linker. That's how SOM does it -- and
2660 if we could make ELF emulate that then we could share more code
2661 in GAS (and potentially a gnu-linker later).
2663 Unwind section relocations are handled in a special way.
2664 The relocations for the .unwind section are originally
2665 built in the usual way. That is, for each unwind table
2666 entry there are two relocations: one for the beginning of
2667 the function and one for the end.
2669 The first time we enter this function we create a
2670 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2671 of the relocation is initialized to 0. Each additional
2672 pair of times this function is called for the unwind
2673 section represents an additional unwind table entry. Thus,
2674 the addend of the relocation should end up to be the number
2675 of unwind table entries. */
2676 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2678 if (unwind_reloc_entryP
== NULL
)
2680 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2682 assert (reloc
!= 0);
2683 unwind_reloc_entryP
= reloc
;
2684 unwind_reloc_fixp_cnt
++;
2685 unwind_reloc_entryP
->address
2686 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2687 /* A pointer to any function will do. We only
2688 need one to tell us what section the unwind
2689 relocations are for. */
2690 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2691 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2692 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2693 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2694 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2695 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2696 sizeof (arelent
*) * 2);
2697 assert (relocs
!= 0);
2698 relocs
[0] = unwind_reloc_entryP
;
2702 unwind_reloc_fixp_cnt
++;
2703 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2709 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2710 assert (reloc
!= 0);
2712 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2713 codes
= hppa_gen_reloc_type (stdoutput
,
2715 hppa_fixp
->fx_r_format
,
2716 hppa_fixp
->fx_r_field
);
2718 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2721 relocs
= (arelent
**)
2722 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2723 assert (relocs
!= 0);
2725 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2726 sizeof (arelent
) * n_relocs
);
2728 assert (reloc
!= 0);
2730 for (i
= 0; i
< n_relocs
; i
++)
2731 relocs
[i
] = &reloc
[i
];
2733 relocs
[n_relocs
] = NULL
;
2736 switch (fixp
->fx_r_type
)
2738 case R_HPPA_COMPLEX
:
2739 case R_HPPA_COMPLEX_PCREL_CALL
:
2740 case R_HPPA_COMPLEX_ABS_CALL
:
2741 assert (n_relocs
== 5);
2743 for (i
= 0; i
< n_relocs
; i
++)
2745 reloc
[i
].sym_ptr_ptr
= NULL
;
2746 reloc
[i
].address
= 0;
2747 reloc
[i
].addend
= 0;
2748 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2749 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2752 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2753 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2754 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2756 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2757 reloc
[3].addend
= fixp
->fx_addnumber
;
2758 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2759 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2760 reloc
[1].addend
= fixp
->fx_addnumber
;
2765 assert (n_relocs
== 1);
2769 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2770 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2771 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2772 reloc
->addend
= 0; /* default */
2774 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2776 /* Now, do any processing that is dependent on the relocation type. */
2779 case R_HPPA_PLABEL_32
:
2780 case R_HPPA_PLABEL_11
:
2781 case R_HPPA_PLABEL_14
:
2782 case R_HPPA_PLABEL_L21
:
2783 case R_HPPA_PLABEL_R11
:
2784 case R_HPPA_PLABEL_R14
:
2785 /* For plabel relocations, the addend of the
2786 relocation should be either 0 (no static link) or 2
2787 (static link required).
2789 FIXME: assume that fx_addnumber contains this
2791 reloc
->addend
= fixp
->fx_addnumber
;
2794 case R_HPPA_ABS_CALL_11
:
2795 case R_HPPA_ABS_CALL_14
:
2796 case R_HPPA_ABS_CALL_17
:
2797 case R_HPPA_ABS_CALL_L21
:
2798 case R_HPPA_ABS_CALL_R11
:
2799 case R_HPPA_ABS_CALL_R14
:
2800 case R_HPPA_ABS_CALL_R17
:
2801 case R_HPPA_ABS_CALL_LS21
:
2802 case R_HPPA_ABS_CALL_RS11
:
2803 case R_HPPA_ABS_CALL_RS14
:
2804 case R_HPPA_ABS_CALL_RS17
:
2805 case R_HPPA_ABS_CALL_LD21
:
2806 case R_HPPA_ABS_CALL_RD11
:
2807 case R_HPPA_ABS_CALL_RD14
:
2808 case R_HPPA_ABS_CALL_RD17
:
2809 case R_HPPA_ABS_CALL_LR21
:
2810 case R_HPPA_ABS_CALL_RR14
:
2811 case R_HPPA_ABS_CALL_RR17
:
2813 case R_HPPA_PCREL_CALL_11
:
2814 case R_HPPA_PCREL_CALL_14
:
2815 case R_HPPA_PCREL_CALL_17
:
2816 case R_HPPA_PCREL_CALL_L21
:
2817 case R_HPPA_PCREL_CALL_R11
:
2818 case R_HPPA_PCREL_CALL_R14
:
2819 case R_HPPA_PCREL_CALL_R17
:
2820 case R_HPPA_PCREL_CALL_LS21
:
2821 case R_HPPA_PCREL_CALL_RS11
:
2822 case R_HPPA_PCREL_CALL_RS14
:
2823 case R_HPPA_PCREL_CALL_RS17
:
2824 case R_HPPA_PCREL_CALL_LD21
:
2825 case R_HPPA_PCREL_CALL_RD11
:
2826 case R_HPPA_PCREL_CALL_RD14
:
2827 case R_HPPA_PCREL_CALL_RD17
:
2828 case R_HPPA_PCREL_CALL_LR21
:
2829 case R_HPPA_PCREL_CALL_RR14
:
2830 case R_HPPA_PCREL_CALL_RR17
:
2831 /* The constant is stored in the instruction. */
2832 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2835 reloc
->addend
= fixp
->fx_addnumber
;
2842 /* Preliminary relocation handling for SOM. Needs to handle
2843 COMPLEX relocations (yes, I've seen them occur) and it will
2844 need to handle R_ENTRY/R_EXIT relocations in the very near future
2845 (for generating unwinds). */
2846 switch (fixp
->fx_r_type
)
2848 case R_HPPA_COMPLEX
:
2849 case R_HPPA_COMPLEX_PCREL_CALL
:
2850 case R_HPPA_COMPLEX_ABS_CALL
:
2854 assert (n_relocs
== 1);
2858 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2859 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2860 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2866 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2871 /* For plabel relocations, the addend of the
2872 relocation should be either 0 (no static link) or 2
2873 (static link required).
2875 FIXME: We always assume no static link! */
2880 reloc
->addend
= fixp
->fx_addnumber
;
2890 /* Process any machine dependent frag types. */
2893 md_convert_frag (abfd
, sec
, fragP
)
2895 register asection
*sec
;
2896 register fragS
*fragP
;
2898 unsigned int address
;
2900 if (fragP
->fr_type
== rs_machine_dependent
)
2902 switch ((int) fragP
->fr_subtype
)
2905 fragP
->fr_type
= rs_fill
;
2906 know (fragP
->fr_var
== 1);
2907 know (fragP
->fr_next
);
2908 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2909 if (address
% fragP
->fr_offset
)
2912 fragP
->fr_next
->fr_address
2917 fragP
->fr_offset
= 0;
2923 /* Round up a section size to the appropriate boundary. */
2926 md_section_align (segment
, size
)
2930 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2931 int align2
= (1 << align
) - 1;
2933 return (size
+ align2
) & ~align2
;
2937 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2939 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2941 addressT from_addr
, to_addr
;
2945 fprintf (stderr
, "pa_create_short_jmp\n");
2949 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2951 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2953 addressT from_addr
, to_addr
;
2957 fprintf (stderr
, "pa_create_long_jump\n");
2961 /* Return the approximate size of a frag before relaxation has occurred. */
2963 md_estimate_size_before_relax (fragP
, segment
)
2964 register fragS
*fragP
;
2971 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
2977 /* Parse machine dependent options. There are none on the PA. */
2979 md_parse_option (argP
, cntP
, vecP
)
2987 /* We have no need to default values of symbols. */
2990 md_undefined_symbol (name
)
2996 /* Parse an operand that is machine-specific.
2997 We just return without modifying the expression as we have nothing
3001 md_operand (expressionP
)
3002 expressionS
*expressionP
;
3006 /* Helper function for md_apply_fix. Actually determine if the fix
3007 can be applied, and if so, apply it.
3009 If a fix is applied, then set fx_addsy to NULL which indicates
3010 the fix was applied and need not be emitted into the object file. */
3013 md_apply_fix_1 (fixP
, val
)
3017 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3018 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
3019 long new_val
, result
;
3020 unsigned int w1
, w2
, w
;
3022 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3023 never be "applied". They must always be emitted. */
3025 if (fixP
->fx_r_type
== R_HPPA_ENTRY
3026 || fixP
->fx_r_type
== R_HPPA_EXIT
)
3030 /* There should have been an HPPA specific fixup associated
3031 with the GAS fixup. */
3034 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3035 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3037 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3040 /* Remember this value for emit_reloc. FIXME, is this braindamage
3041 documented anywhere!?! */
3042 fixP
->fx_addnumber
= val
;
3044 /* Check if this is an undefined symbol. No relocation can
3045 possibly be performed in this case. */
3046 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3048 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3051 if (fmt
!= 0 && hppa_fixP
->fx_r_field
!= R_HPPA_PSEL
3052 && hppa_fixP
->fx_r_field
!= R_HPPA_LPSEL
3053 && hppa_fixP
->fx_r_field
!= R_HPPA_RPSEL
)
3054 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3060 /* Handle all opcodes with the 'j' operand type. */
3062 CHECK_FIELD (new_val
, 8191, -8192, 0);
3064 /* Mask off 14 bits to be changed. */
3065 bfd_put_32 (stdoutput
,
3066 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3068 low_sign_unext (new_val
, 14, &result
);
3071 /* Handle all opcodes with the 'k' operand type. */
3073 CHECK_FIELD (new_val
, 2097152, 0, 0);
3075 /* Mask off 21 bits to be changed. */
3076 bfd_put_32 (stdoutput
,
3077 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3079 dis_assemble_21 (new_val
, &result
);
3082 /* Handle all the opcodes with the 'i' operand type. */
3084 CHECK_FIELD (new_val
, 1023, -1023, 0);
3086 /* Mask off 11 bits to be changed. */
3087 bfd_put_32 (stdoutput
,
3088 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3090 low_sign_unext (new_val
, 11, &result
);
3093 /* Handle all the opcodes with the 'w' operand type. */
3095 CHECK_FIELD (new_val
, 8191, -8192, 0)
3097 /* Mask off 11 bits to be changed. */
3098 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3099 bfd_put_32 (stdoutput
,
3100 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3103 dis_assemble_12 (result
, &w1
, &w
);
3104 result
= ((w1
<< 2) | w
);
3105 fixP
->fx_addsy
= NULL
;
3108 #define stub_needed(CALLER, CALLEE) \
3109 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3111 /* Handle some of the opcodes with the 'W' operand type. */
3113 /* If a long-call stub or argument relocation stub is
3114 needed, then we can not apply this relocation, instead
3115 the linker must handle it. */
3116 if (new_val
> 262143 || new_val
< -262144
3117 || stub_needed (((obj_symbol_type
*)
3118 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3119 hppa_fixP
->fx_arg_reloc
))
3122 /* No stubs were needed, we can perform this relocation. */
3123 CHECK_FIELD (new_val
, 262143, -262144, 0);
3125 /* Mask off 17 bits to be changed. */
3126 bfd_put_32 (stdoutput
,
3127 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3129 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3130 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3131 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3132 fixP
->fx_addsy
= NULL
;
3140 /* These are ELF specific relocations. ELF unfortunately
3141 handles unwinds in a completely different manner. */
3142 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3143 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3144 result
= fixP
->fx_addnumber
;
3149 fixP
->fx_addnumber
= fixP
->fx_offset
;
3150 bfd_put_32 (stdoutput
, 0, buf
);
3159 as_bad ("Unknown relocation encountered in md_apply_fix.");
3163 /* Insert the relocation. */
3164 bfd_put_32 (stdoutput
, bfd_get_32 (stdoutput
, buf
) | result
, buf
);
3167 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3168 (unsigned int) fixP
, fixP
->fx_r_type
);
3171 /* Apply a fix into a frag's data (if possible). */
3174 md_apply_fix (fixP
, valp
)
3178 md_apply_fix_1 (fixP
, (long) *valp
);
3182 /* Exactly what point is a PC-relative offset relative TO?
3183 On the PA, they're relative to the address of the offset. */
3186 md_pcrel_from (fixP
)
3189 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3192 /* Return nonzero if the input line pointer is at the end of
3196 is_end_of_statement ()
3198 return ((*input_line_pointer
== '\n')
3199 || (*input_line_pointer
== ';')
3200 || (*input_line_pointer
== '!'));
3203 /* Read a number from S. The number might come in one of many forms,
3204 the most common will be a hex or decimal constant, but it could be
3205 a pre-defined register (Yuk!), or an absolute symbol.
3207 Return a number or -1 for failure.
3209 When parsing PA-89 FP register numbers RESULT will be
3210 the address of a structure to return information about
3211 L/R half of FP registers, store results there as appropriate.
3213 pa_parse_number can not handle negative constants and will fail
3214 horribly if it is passed such a constant. */
3217 pa_parse_number (s
, result
)
3219 struct pa_89_fp_reg_struct
*result
;
3228 /* Skip whitespace before the number. */
3229 while (*p
== ' ' || *p
== '\t')
3232 /* Store info in RESULT if requested by caller. */
3235 result
->number_part
= -1;
3236 result
->l_r_select
= -1;
3242 /* Looks like a number. */
3245 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3247 /* The number is specified in hex. */
3249 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3250 || ((*p
>= 'A') && (*p
<= 'F')))
3253 num
= num
* 16 + *p
- '0';
3254 else if (*p
>= 'a' && *p
<= 'f')
3255 num
= num
* 16 + *p
- 'a' + 10;
3257 num
= num
* 16 + *p
- 'A' + 10;
3263 /* The number is specified in decimal. */
3264 while (isdigit (*p
))
3266 num
= num
* 10 + *p
- '0';
3271 /* Store info in RESULT if requested by the caller. */
3274 result
->number_part
= num
;
3276 if (IS_R_SELECT (p
))
3278 result
->l_r_select
= 1;
3281 else if (IS_L_SELECT (p
))
3283 result
->l_r_select
= 0;
3287 result
->l_r_select
= 0;
3292 /* The number might be a predefined register. */
3297 /* Tege hack: Special case for general registers as the general
3298 code makes a binary search with case translation, and is VERY
3303 if (*p
== 'e' && *(p
+ 1) == 't'
3304 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3307 num
= *p
- '0' + 28;
3315 else if (!isdigit (*p
))
3318 as_bad ("Undefined register: '%s'.", name
);
3324 num
= num
* 10 + *p
++ - '0';
3325 while (isdigit (*p
));
3330 /* Do a normal register search. */
3331 while (is_part_of_name (c
))
3337 status
= reg_name_search (name
);
3343 as_bad ("Undefined register: '%s'.", name
);
3349 /* Store info in RESULT if requested by caller. */
3352 result
->number_part
= num
;
3353 if (IS_R_SELECT (p
- 1))
3354 result
->l_r_select
= 1;
3355 else if (IS_L_SELECT (p
- 1))
3356 result
->l_r_select
= 0;
3358 result
->l_r_select
= 0;
3363 /* And finally, it could be a symbol in the absolute section which
3364 is effectively a constant. */
3368 while (is_part_of_name (c
))
3374 if ((sym
= symbol_find (name
)) != NULL
)
3376 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3377 num
= S_GET_VALUE (sym
);
3381 as_bad ("Non-absolute symbol: '%s'.", name
);
3387 /* There is where we'd come for an undefined symbol
3388 or for an empty string. For an empty string we
3389 will return zero. That's a concession made for
3390 compatability with the braindamaged HP assemblers. */
3396 as_bad ("Undefined absolute constant: '%s'.", name
);
3402 /* Store info in RESULT if requested by caller. */
3405 result
->number_part
= num
;
3406 if (IS_R_SELECT (p
- 1))
3407 result
->l_r_select
= 1;
3408 else if (IS_L_SELECT (p
- 1))
3409 result
->l_r_select
= 0;
3411 result
->l_r_select
= 0;
3419 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3421 /* Given NAME, find the register number associated with that name, return
3422 the integer value associated with the given name or -1 on failure. */
3425 reg_name_search (name
)
3428 int middle
, low
, high
;
3431 high
= REG_NAME_CNT
- 1;
3435 middle
= (low
+ high
) / 2;
3436 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3441 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3444 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3445 return (pre_defined_registers
[middle
].value
);
3451 /* Return nonzero if the given INSN and L/R information will require
3452 a new PA-89 opcode. */
3455 need_89_opcode (insn
, result
)
3457 struct pa_89_fp_reg_struct
*result
;
3459 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3465 /* Parse a condition for a fcmp instruction. Return the numerical
3466 code associated with the condition. */
3469 pa_parse_fp_cmp_cond (s
)
3476 for (i
= 0; i
< 32; i
++)
3478 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3479 strlen (fp_cond_map
[i
].string
)) == 0)
3481 cond
= fp_cond_map
[i
].cond
;
3482 *s
+= strlen (fp_cond_map
[i
].string
);
3483 while (**s
== ' ' || **s
== '\t')
3489 as_bad ("Invalid FP Compare Condition: %c", **s
);
3493 /* Parse an FP operand format completer returning the completer
3496 static fp_operand_format
3497 pa_parse_fp_format (s
)
3506 if (strncasecmp (*s
, "sgl", 3) == 0)
3511 else if (strncasecmp (*s
, "dbl", 3) == 0)
3516 else if (strncasecmp (*s
, "quad", 4) == 0)
3523 format
= ILLEGAL_FMT
;
3524 as_bad ("Invalid FP Operand Format: %3s", *s
);
3531 /* Convert from a selector string into a selector type. */
3534 pa_chk_field_selector (str
)
3538 const struct selector_entry
*tablep
;
3542 /* Read past any whitespace. */
3543 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3546 /* Yuk. Looks like a linear search through the table. With the
3547 frequence of some selectors it might make sense to sort the
3549 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3551 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3553 *str
+= strlen (tablep
->prefix
);
3554 selector
= tablep
->field_selector
;
3561 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3564 get_expression (str
)
3570 save_in
= input_line_pointer
;
3571 input_line_pointer
= str
;
3572 seg
= expression (&the_insn
.exp
);
3573 if (!(seg
== absolute_section
3574 || seg
== undefined_section
3575 || SEG_NORMAL (seg
)))
3577 as_warn ("Bad segment in expression.");
3578 expr_end
= input_line_pointer
;
3579 input_line_pointer
= save_in
;
3582 expr_end
= input_line_pointer
;
3583 input_line_pointer
= save_in
;
3587 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3589 pa_get_absolute_expression (insn
, strp
)
3595 insn
->field_selector
= pa_chk_field_selector (strp
);
3596 save_in
= input_line_pointer
;
3597 input_line_pointer
= *strp
;
3598 expression (&insn
->exp
);
3599 if (insn
->exp
.X_op
!= O_constant
)
3601 as_bad ("Bad segment (should be absolute).");
3602 expr_end
= input_line_pointer
;
3603 input_line_pointer
= save_in
;
3606 expr_end
= input_line_pointer
;
3607 input_line_pointer
= save_in
;
3608 return evaluate_absolute (insn
);
3611 /* Evaluate an absolute expression EXP which may be modified by
3612 the selector FIELD_SELECTOR. Return the value of the expression. */
3614 evaluate_absolute (insn
)
3619 int field_selector
= insn
->field_selector
;
3622 value
= exp
.X_add_number
;
3624 switch (field_selector
)
3630 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3632 if (value
& 0x00000400)
3634 value
= (value
& 0xfffff800) >> 11;
3637 /* Sign extend from bit 21. */
3639 if (value
& 0x00000400)
3640 value
|= 0xfffff800;
3645 /* Arithmetic shift right 11 bits. */
3647 value
= (value
& 0xfffff800) >> 11;
3650 /* Set bits 0-20 to zero. */
3652 value
= value
& 0x7ff;
3655 /* Add 0x800 and arithmetic shift right 11 bits. */
3660 value
= (value
& 0xfffff800) >> 11;
3663 /* Set bitgs 0-21 to one. */
3665 value
|= 0xfffff800;
3668 /* This had better get fixed. It looks like we're quickly moving
3675 BAD_CASE (field_selector
);
3681 /* Given an argument location specification return the associated
3682 argument location number. */
3685 pa_build_arg_reloc (type_name
)
3689 if (strncasecmp (type_name
, "no", 2) == 0)
3691 if (strncasecmp (type_name
, "gr", 2) == 0)
3693 else if (strncasecmp (type_name
, "fr", 2) == 0)
3695 else if (strncasecmp (type_name
, "fu", 2) == 0)
3698 as_bad ("Invalid argument location: %s\n", type_name
);
3703 /* Encode and return an argument relocation specification for
3704 the given register in the location specified by arg_reloc. */
3707 pa_align_arg_reloc (reg
, arg_reloc
)
3709 unsigned int arg_reloc
;
3711 unsigned int new_reloc
;
3713 new_reloc
= arg_reloc
;
3729 as_bad ("Invalid argument description: %d", reg
);
3735 /* Parse a PA nullification completer (,n). Return nonzero if the
3736 completer was found; return zero if no completer was found. */
3748 if (strncasecmp (*s
, "n", 1) == 0)
3752 as_bad ("Invalid Nullification: (%c)", **s
);
3761 /* Parse a non-negated compare/subtract completer returning the
3762 number (for encoding in instrutions) of the given completer.
3764 ISBRANCH specifies whether or not this is parsing a condition
3765 completer for a branch (vs a nullification completer for a
3766 computational instruction. */
3769 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3774 char *name
= *s
+ 1;
3782 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3786 if (strcmp (name
, "=") == 0)
3790 else if (strcmp (name
, "<") == 0)
3794 else if (strcmp (name
, "<=") == 0)
3798 else if (strcmp (name
, "<<") == 0)
3802 else if (strcmp (name
, "<<=") == 0)
3806 else if (strcasecmp (name
, "sv") == 0)
3810 else if (strcasecmp (name
, "od") == 0)
3814 /* If we have something like addb,n then there is no condition
3816 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3827 /* Reset pointers if this was really a ,n for a branch instruction. */
3828 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3834 /* Parse a negated compare/subtract completer returning the
3835 number (for encoding in instrutions) of the given completer.
3837 ISBRANCH specifies whether or not this is parsing a condition
3838 completer for a branch (vs a nullification completer for a
3839 computational instruction. */
3842 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3847 char *name
= *s
+ 1;
3855 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3859 if (strcasecmp (name
, "tr") == 0)
3863 else if (strcmp (name
, "<>") == 0)
3867 else if (strcmp (name
, ">=") == 0)
3871 else if (strcmp (name
, ">") == 0)
3875 else if (strcmp (name
, ">>=") == 0)
3879 else if (strcmp (name
, ">>") == 0)
3883 else if (strcasecmp (name
, "nsv") == 0)
3887 else if (strcasecmp (name
, "ev") == 0)
3891 /* If we have something like addb,n then there is no condition
3893 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3904 /* Reset pointers if this was really a ,n for a branch instruction. */
3905 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3911 /* Parse a non-negated addition completer returning the number
3912 (for encoding in instrutions) of the given completer.
3914 ISBRANCH specifies whether or not this is parsing a condition
3915 completer for a branch (vs a nullification completer for a
3916 computational instruction. */
3919 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3924 char *name
= *s
+ 1;
3932 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3936 if (strcmp (name
, "=") == 0)
3940 else if (strcmp (name
, "<") == 0)
3944 else if (strcmp (name
, "<=") == 0)
3948 else if (strcasecmp (name
, "nuv") == 0)
3952 else if (strcasecmp (name
, "znv") == 0)
3956 else if (strcasecmp (name
, "sv") == 0)
3960 else if (strcasecmp (name
, "od") == 0)
3964 /* If we have something like addb,n then there is no condition
3966 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3977 /* Reset pointers if this was really a ,n for a branch instruction. */
3978 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3984 /* Parse a negated addition completer returning the number
3985 (for encoding in instrutions) of the given completer.
3987 ISBRANCH specifies whether or not this is parsing a condition
3988 completer for a branch (vs a nullification completer for a
3989 computational instruction. */
3992 pa_parse_neg_add_cmpltr (s
, isbranch
)
3997 char *name
= *s
+ 1;
4005 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4009 if (strcasecmp (name
, "tr") == 0)
4013 else if (strcmp (name
, "<>") == 0)
4017 else if (strcmp (name
, ">=") == 0)
4021 else if (strcmp (name
, ">") == 0)
4025 else if (strcmp (name
, "uv") == 0)
4029 else if (strcmp (name
, "vnz") == 0)
4033 else if (strcasecmp (name
, "nsv") == 0)
4037 else if (strcasecmp (name
, "ev") == 0)
4041 /* If we have something like addb,n then there is no condition
4043 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4054 /* Reset pointers if this was really a ,n for a branch instruction. */
4055 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4061 /* Handle a .BLOCK type pseudo-op. */
4069 unsigned int temp_size
;
4072 temp_size
= get_absolute_expression ();
4074 /* Always fill with zeros, that's what the HP assembler does. */
4077 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4078 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4079 bzero (p
, temp_size
);
4081 /* Convert 2 bytes at a time. */
4083 for (i
= 0; i
< temp_size
; i
+= 2)
4085 md_number_to_chars (p
+ i
,
4087 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4090 pa_undefine_label ();
4091 demand_empty_rest_of_line ();
4095 /* Handle a .CALL pseudo-op. This involves storing away information
4096 about where arguments are to be found so the linker can detect
4097 (and correct) argument location mismatches between caller and callee. */
4103 pa_call_args (&last_call_desc
);
4104 demand_empty_rest_of_line ();
4108 /* Do the dirty work of building a call descriptor which describes
4109 where the caller placed arguments to a function call. */
4112 pa_call_args (call_desc
)
4113 struct call_desc
*call_desc
;
4116 unsigned int temp
, arg_reloc
;
4118 while (!is_end_of_statement ())
4120 name
= input_line_pointer
;
4121 c
= get_symbol_end ();
4122 /* Process a source argument. */
4123 if ((strncasecmp (name
, "argw", 4) == 0))
4125 temp
= atoi (name
+ 4);
4126 p
= input_line_pointer
;
4128 input_line_pointer
++;
4129 name
= input_line_pointer
;
4130 c
= get_symbol_end ();
4131 arg_reloc
= pa_build_arg_reloc (name
);
4132 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4134 /* Process a return value. */
4135 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4137 p
= input_line_pointer
;
4139 input_line_pointer
++;
4140 name
= input_line_pointer
;
4141 c
= get_symbol_end ();
4142 arg_reloc
= pa_build_arg_reloc (name
);
4143 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4147 as_bad ("Invalid .CALL argument: %s", name
);
4149 p
= input_line_pointer
;
4151 if (!is_end_of_statement ())
4152 input_line_pointer
++;
4156 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4159 is_same_frag (frag1
, frag2
)
4166 else if (frag2
== NULL
)
4168 else if (frag1
== frag2
)
4170 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4171 return (is_same_frag (frag1
, frag2
->fr_next
));
4177 /* Build an entry in the UNWIND subspace from the given function
4178 attributes in CALL_INFO. This is not needed for SOM as using
4179 R_ENTRY and R_EXIT relocations allow the linker to handle building
4180 of the unwind spaces. */
4183 pa_build_unwind_subspace (call_info
)
4184 struct call_info
*call_info
;
4187 asection
*seg
, *save_seg
;
4188 subsegT subseg
, save_subseg
;
4192 /* Get into the right seg/subseg. This may involve creating
4193 the seg the first time through. Make sure to have the
4194 old seg/subseg so that we can reset things when we are done. */
4195 subseg
= SUBSEG_UNWIND
;
4196 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4197 if (seg
== ASEC_NULL
)
4199 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4200 bfd_set_section_flags (stdoutput
, seg
,
4201 SEC_READONLY
| SEC_HAS_CONTENTS
4202 | SEC_LOAD
| SEC_RELOC
);
4206 save_subseg
= now_subseg
;
4207 subseg_set (seg
, subseg
);
4210 /* Get some space to hold relocation information for the unwind
4213 call_info
->start_offset_frag
= frag_now
;
4214 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4216 /* Relocation info. for start offset of the function. */
4217 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4218 call_info
->start_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 start_symbol of
4223 this call_info descriptor. */
4227 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4228 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4230 if (fixP
->fx_addsy
== call_info
->start_symbol
4231 || fixP
->fx_subsy
== call_info
->start_symbol
)
4233 call_info
->start_fix
= fixP
;
4240 call_info
->end_offset_frag
= frag_now
;
4241 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4243 /* Relocation info. for end offset of the function. */
4244 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4245 call_info
->end_symbol
, (offsetT
) 0,
4246 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4249 /* We need to search for the first relocation involving the end_symbol of
4250 this call_info descriptor. */
4254 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4255 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4257 if (fixP
->fx_addsy
== call_info
->end_symbol
4258 || fixP
->fx_subsy
== call_info
->end_symbol
)
4260 call_info
->end_fix
= fixP
;
4267 unwind
= (char *) &call_info
->ci_unwind
;
4268 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4272 FRAG_APPEND_1_CHAR (c
);
4276 /* Return back to the original segment/subsegment. */
4277 subseg_set (save_seg
, save_subseg
);
4281 /* Process a .CALLINFO pseudo-op. This information is used later
4282 to build unwind descriptors and maybe one day to support
4283 .ENTER and .LEAVE. */
4286 pa_callinfo (unused
)
4292 /* .CALLINFO must appear within a procedure definition. */
4293 if (!within_procedure
)
4294 as_bad (".callinfo is not within a procedure definition");
4296 /* Mark the fact that we found the .CALLINFO for the
4297 current procedure. */
4298 callinfo_found
= TRUE
;
4300 /* Iterate over the .CALLINFO arguments. */
4301 while (!is_end_of_statement ())
4303 name
= input_line_pointer
;
4304 c
= get_symbol_end ();
4305 /* Frame size specification. */
4306 if ((strncasecmp (name
, "frame", 5) == 0))
4308 p
= input_line_pointer
;
4310 input_line_pointer
++;
4311 temp
= get_absolute_expression ();
4312 if ((temp
& 0x3) != 0)
4314 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4318 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4319 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4322 /* Entry register (GR, GR and SR) specifications. */
4323 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4325 p
= input_line_pointer
;
4327 input_line_pointer
++;
4328 temp
= get_absolute_expression ();
4329 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4330 even though %r19 is caller saved. I think this is a bug in
4331 the HP assembler, and we are not going to emulate it. */
4332 if (temp
< 3 || temp
> 18)
4333 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4334 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4336 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4338 p
= input_line_pointer
;
4340 input_line_pointer
++;
4341 temp
= get_absolute_expression ();
4342 /* Similarly the HP assembler takes 31 as the high bound even
4343 though %fr21 is the last callee saved floating point register. */
4344 if (temp
< 12 || temp
> 21)
4345 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4346 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4348 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4350 p
= input_line_pointer
;
4352 input_line_pointer
++;
4353 temp
= get_absolute_expression ();
4355 as_bad ("Value for ENTRY_SR must be 3\n");
4356 last_call_info
->entry_sr
= temp
- 2;
4358 /* Note whether or not this function performs any calls. */
4359 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4360 (strncasecmp (name
, "caller", 6) == 0))
4362 p
= input_line_pointer
;
4364 last_call_info
->makes_calls
= 1;
4366 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4368 p
= input_line_pointer
;
4370 last_call_info
->makes_calls
= 0;
4372 /* Should RP be saved into the stack. */
4373 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4375 p
= input_line_pointer
;
4377 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4379 /* Likewise for SP. */
4380 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4382 p
= input_line_pointer
;
4384 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4386 /* Is this an unwindable procedure. If so mark it so
4387 in the unwind descriptor. */
4388 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4390 p
= input_line_pointer
;
4392 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4394 /* Is this an interrupt routine. If so mark it in the
4395 unwind descriptor. */
4396 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4398 p
= input_line_pointer
;
4400 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4404 as_bad ("Invalid .CALLINFO argument: %s", name
);
4406 if (!is_end_of_statement ())
4407 input_line_pointer
++;
4410 demand_empty_rest_of_line ();
4414 /* Switch into the code subspace. */
4420 sd_chain_struct
*sdchain
;
4422 /* First time through it might be necessary to create the
4424 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4426 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4427 pa_def_spaces
[0].spnum
,
4428 pa_def_spaces
[0].loadable
,
4429 pa_def_spaces
[0].defined
,
4430 pa_def_spaces
[0].private,
4431 pa_def_spaces
[0].sort
,
4432 pa_def_spaces
[0].segment
, 0);
4435 SPACE_DEFINED (sdchain
) = 1;
4436 subseg_set (text_section
, SUBSEG_CODE
);
4437 demand_empty_rest_of_line ();
4441 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4442 the .comm pseudo-op has the following symtax:
4444 <label> .comm <length>
4446 where <label> is optional and is a symbol whose address will be the start of
4447 a block of memory <length> bytes long. <length> must be an absolute
4448 expression. <length> bytes will be allocated in the current space
4457 label_symbol_struct
*label_symbol
= pa_get_label ();
4460 symbol
= label_symbol
->lss_label
;
4465 size
= get_absolute_expression ();
4469 /* It is incorrect to check S_IS_DEFINED at this point as
4470 the symbol will *always* be defined. FIXME. How to
4471 correctly determine when this label really as been
4473 if (S_GET_VALUE (symbol
))
4475 if (S_GET_VALUE (symbol
) != size
)
4477 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4478 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4484 S_SET_VALUE (symbol
, size
);
4485 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4486 S_SET_EXTERNAL (symbol
);
4489 demand_empty_rest_of_line ();
4492 /* Process a .COPYRIGHT pseudo-op. */
4495 pa_copyright (unused
)
4502 if (*input_line_pointer
== '\"')
4504 ++input_line_pointer
;
4505 name
= input_line_pointer
;
4506 while ((c
= next_char_of_string ()) >= 0)
4508 c
= *input_line_pointer
;
4509 *input_line_pointer
= '\0';
4510 *(input_line_pointer
- 1) = '\0';
4512 /* FIXME. Not supported */
4515 *input_line_pointer
= c
;
4519 as_bad ("Expected \"-ed string");
4521 pa_undefine_label ();
4522 demand_empty_rest_of_line ();
4525 /* Process a .END pseudo-op. */
4531 demand_empty_rest_of_line ();
4535 /* Process a .ENTER pseudo-op. This is not supported. */
4544 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4550 if (!within_procedure
)
4551 as_bad ("Misplaced .entry. Ignored.");
4554 if (!callinfo_found
)
4555 as_bad ("Missing .callinfo.");
4557 last_call_info
->start_frag
= frag_now
;
4559 demand_empty_rest_of_line ();
4560 within_entry_exit
= TRUE
;
4562 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4563 It will not be on if no .EXPORT pseudo-op exists (static function). */
4564 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4567 /* SOM defers building of unwind descriptors until the link phase.
4568 The assembler is responsible for creating an R_ENTRY relocation
4569 to mark the beginning of a region and hold the unwind bits, and
4570 for creating an R_EXIT relocation to mark the end of the region.
4572 FIXME. ELF should be using the same conventions! The problem
4573 is an unwind requires too much relocation space. Hmmm. Maybe
4574 if we split the unwind bits up between the relocations which
4575 denote the entry and exit points. */
4577 char *where
= frag_more (0);
4579 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4580 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4581 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4582 (char *)&last_call_info
->ci_unwind
.descriptor
);
4589 /* Handle a .EQU pseudo-op. */
4595 label_symbol_struct
*label_symbol
= pa_get_label ();
4600 symbol
= label_symbol
->lss_label
;
4601 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4602 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4607 as_bad (".REG must use a label");
4609 as_bad (".EQU must use a label");
4612 pa_undefine_label ();
4613 demand_empty_rest_of_line ();
4617 /* Helper function. Does processing for the end of a function. This
4618 usually involves creating some relocations or building special
4619 symbols to mark the end of the function. */
4626 where
= frag_more (0);
4629 /* ELF does not have EXIT relocations. All we do is create a
4630 temporary symbol marking the end of the function. */
4632 char *name
= (char *) xmalloc (strlen ("L$\001end_") +
4633 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
4639 strcpy (name
, "L$\001end_");
4640 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
4642 symbolP
= symbol_find (name
);
4644 as_warn ("Symbol '%s' already defined.", name
);
4647 /* symbol value should be the offset of the
4648 last instruction of the function */
4649 symbolP
= symbol_new (name
, now_seg
,
4650 (valueT
) (obstack_next_free (&frags
)
4651 - frag_now
->fr_literal
- 4),
4655 symbolP
->bsym
->flags
= BSF_LOCAL
;
4656 symbol_table_insert (symbolP
);
4659 last_call_info
->end_symbol
= symbolP
;
4661 as_bad ("Symbol '%s' could not be created.", name
);
4665 as_bad ("No memory for symbol name.");
4668 /* Stuff away the location of the frag for the end of the function,
4669 and call pa_build_unwind_subspace to add an entry in the unwind
4671 last_call_info
->end_frag
= frag_now
;
4672 pa_build_unwind_subspace (last_call_info
);
4674 /* SOM defers building of unwind descriptors until the link phase.
4675 The assembler is responsible for creating an R_ENTRY relocation
4676 to mark the beginning of a region and hold the unwind bits, and
4677 for creating an R_EXIT relocation to mark the end of the region.
4679 FIXME. ELF should be using the same conventions! The problem
4680 is an unwind requires too much relocation space. Hmmm. Maybe
4681 if we split the unwind bits up between the relocations which
4682 denote the entry and exit points. */
4683 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4684 last_call_info
->start_symbol
, (offsetT
) 0,
4685 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4688 exit_processing_complete
= TRUE
;
4691 /* Process a .EXIT pseudo-op. */
4697 if (!within_procedure
)
4698 as_bad (".EXIT must appear within a procedure");
4701 if (!callinfo_found
)
4702 as_bad ("Missing .callinfo");
4705 if (!within_entry_exit
)
4706 as_bad ("No .ENTRY for this .EXIT");
4709 within_entry_exit
= FALSE
;
4714 demand_empty_rest_of_line ();
4718 /* Process a .EXPORT directive. This makes functions external
4719 and provides information such as argument relocation entries
4729 name
= input_line_pointer
;
4730 c
= get_symbol_end ();
4731 /* Make sure the given symbol exists. */
4732 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4734 as_bad ("Cannot define export symbol: %s\n", name
);
4735 p
= input_line_pointer
;
4737 input_line_pointer
++;
4741 /* OK. Set the external bits and process argument relocations. */
4742 S_SET_EXTERNAL (symbol
);
4743 p
= input_line_pointer
;
4745 if (!is_end_of_statement ())
4747 input_line_pointer
++;
4748 pa_type_args (symbol
, 1);
4750 pa_build_symextn_section ();
4755 demand_empty_rest_of_line ();
4759 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4762 pa_type_args (symbolP
, is_export
)
4767 unsigned int temp
, arg_reloc
;
4768 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4769 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4771 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4774 input_line_pointer
+= 8;
4775 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4776 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4777 type
= SYMBOL_TYPE_ABSOLUTE
;
4779 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4781 input_line_pointer
+= 4;
4782 /* IMPORTing/EXPORTing CODE types for functions is meaningless for SOM,
4783 instead one should be IMPORTing/EXPORTing ENTRY types.
4785 Complain if one tries to EXPORT a CODE type since that's never
4786 done. Both GCC and HP C still try to IMPORT CODE types, so
4787 silently fix them to be ENTRY types. */
4788 if (symbolP
->bsym
->flags
& BSF_FUNCTION
)
4791 as_tsktsk ("Using ENTRY rather than CODE in export directive for %s", symbolP
->bsym
->name
);
4793 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4794 type
= SYMBOL_TYPE_ENTRY
;
4798 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4799 type
= SYMBOL_TYPE_CODE
;
4802 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4804 input_line_pointer
+= 4;
4805 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4806 type
= SYMBOL_TYPE_DATA
;
4808 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4810 input_line_pointer
+= 5;
4811 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4812 type
= SYMBOL_TYPE_ENTRY
;
4814 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4816 input_line_pointer
+= 9;
4817 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4818 type
= SYMBOL_TYPE_MILLICODE
;
4820 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4822 input_line_pointer
+= 6;
4823 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4824 type
= SYMBOL_TYPE_PLABEL
;
4826 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4828 input_line_pointer
+= 8;
4829 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4830 type
= SYMBOL_TYPE_PRI_PROG
;
4832 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4834 input_line_pointer
+= 8;
4835 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4836 type
= SYMBOL_TYPE_SEC_PROG
;
4839 /* SOM requires much more information about symbol types
4840 than BFD understands. This is how we get this information
4841 to the SOM BFD backend. */
4842 #ifdef obj_set_symbol_type
4843 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4846 /* Now that the type of the exported symbol has been handled,
4847 handle any argument relocation information. */
4848 while (!is_end_of_statement ())
4850 if (*input_line_pointer
== ',')
4851 input_line_pointer
++;
4852 name
= input_line_pointer
;
4853 c
= get_symbol_end ();
4854 /* Argument sources. */
4855 if ((strncasecmp (name
, "argw", 4) == 0))
4857 p
= input_line_pointer
;
4859 input_line_pointer
++;
4860 temp
= atoi (name
+ 4);
4861 name
= input_line_pointer
;
4862 c
= get_symbol_end ();
4863 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4864 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4865 *input_line_pointer
= c
;
4867 /* The return value. */
4868 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4870 p
= input_line_pointer
;
4872 input_line_pointer
++;
4873 name
= input_line_pointer
;
4874 c
= get_symbol_end ();
4875 arg_reloc
= pa_build_arg_reloc (name
);
4876 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4877 *input_line_pointer
= c
;
4879 /* Privelege level. */
4880 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4882 p
= input_line_pointer
;
4884 input_line_pointer
++;
4885 temp
= atoi (input_line_pointer
);
4886 c
= get_symbol_end ();
4887 *input_line_pointer
= c
;
4891 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4892 p
= input_line_pointer
;
4895 if (!is_end_of_statement ())
4896 input_line_pointer
++;
4900 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4901 assembly file must either be defined in the assembly file, or
4902 explicitly IMPORTED from another. */
4911 name
= input_line_pointer
;
4912 c
= get_symbol_end ();
4914 symbol
= symbol_find_or_make (name
);
4915 p
= input_line_pointer
;
4918 if (!is_end_of_statement ())
4920 input_line_pointer
++;
4921 pa_type_args (symbol
, 0);
4925 /* Sigh. To be compatable with the HP assembler and to help
4926 poorly written assembly code, we assign a type based on
4927 the the current segment. Note only BSF_FUNCTION really
4928 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
4929 if (now_seg
== text_section
)
4930 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4932 /* If the section is undefined, then the symbol is undefined
4933 Since this is an import, leave the section undefined. */
4934 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4937 demand_empty_rest_of_line ();
4941 /* Handle a .LABEL pseudo-op. */
4949 name
= input_line_pointer
;
4950 c
= get_symbol_end ();
4952 if (strlen (name
) > 0)
4955 p
= input_line_pointer
;
4960 as_warn ("Missing label name on .LABEL");
4963 if (!is_end_of_statement ())
4965 as_warn ("extra .LABEL arguments ignored.");
4966 ignore_rest_of_line ();
4968 demand_empty_rest_of_line ();
4972 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4981 /* Handle a .ORIGIN pseudo-op. */
4988 pa_undefine_label ();
4992 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4993 is for static functions. FIXME. Should share more code with .EXPORT. */
5002 name
= input_line_pointer
;
5003 c
= get_symbol_end ();
5005 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5007 as_bad ("Cannot define static symbol: %s\n", name
);
5008 p
= input_line_pointer
;
5010 input_line_pointer
++;
5014 S_CLEAR_EXTERNAL (symbol
);
5015 p
= input_line_pointer
;
5017 if (!is_end_of_statement ())
5019 input_line_pointer
++;
5020 pa_type_args (symbol
, 0);
5024 demand_empty_rest_of_line ();
5028 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5029 of a procedure from a syntatical point of view. */
5035 struct call_info
*call_info
;
5037 if (within_procedure
)
5038 as_fatal ("Nested procedures");
5040 /* Reset global variables for new procedure. */
5041 callinfo_found
= FALSE
;
5042 within_procedure
= TRUE
;
5043 exit_processing_complete
= FALSE
;
5045 /* Create another call_info structure. */
5046 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5049 as_fatal ("Cannot allocate unwind descriptor\n");
5051 bzero (call_info
, sizeof (struct call_info
));
5053 call_info
->ci_next
= NULL
;
5055 if (call_info_root
== NULL
)
5057 call_info_root
= call_info
;
5058 last_call_info
= call_info
;
5062 last_call_info
->ci_next
= call_info
;
5063 last_call_info
= call_info
;
5066 /* set up defaults on call_info structure */
5068 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5069 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5070 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5071 call_info
->entry_sr
= ~0;
5072 call_info
->makes_calls
= 1;
5074 /* If we got a .PROC pseudo-op, we know that the function is defined
5075 locally. Make sure it gets into the symbol table. */
5077 label_symbol_struct
*label_symbol
= pa_get_label ();
5081 if (label_symbol
->lss_label
)
5083 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5084 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5087 as_bad ("Missing function name for .PROC (corrupted label)");
5090 as_bad ("Missing function name for .PROC");
5093 demand_empty_rest_of_line ();
5097 /* Process the syntatical end of a procedure. Make sure all the
5098 appropriate pseudo-ops were found within the procedure. */
5105 if (!within_procedure
)
5106 as_bad ("misplaced .procend");
5108 if (!callinfo_found
)
5109 as_bad ("Missing .callinfo for this procedure");
5111 if (within_entry_exit
)
5112 as_bad ("Missing .EXIT for a .ENTRY");
5114 if (!exit_processing_complete
)
5117 within_procedure
= FALSE
;
5118 demand_empty_rest_of_line ();
5122 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5123 then create a new space entry to hold the information specified
5124 by the parameters to the .SPACE directive. */
5126 static sd_chain_struct
*
5127 pa_parse_space_stmt (space_name
, create_flag
)
5131 char *name
, *ptemp
, c
;
5132 char loadable
, defined
, private, sort
;
5134 asection
*seg
= NULL
;
5135 sd_chain_struct
*space
;
5137 /* load default values */
5143 if (strcasecmp (space_name
, "$TEXT$") == 0)
5145 seg
= pa_def_spaces
[0].segment
;
5146 sort
= pa_def_spaces
[0].sort
;
5148 else if (strcasecmp (space_name
, "$PRIVATE$") == 0)
5150 seg
= pa_def_spaces
[1].segment
;
5151 sort
= pa_def_spaces
[1].sort
;
5154 if (!is_end_of_statement ())
5156 print_errors
= FALSE
;
5157 ptemp
= input_line_pointer
+ 1;
5158 /* First see if the space was specified as a number rather than
5159 as a name. According to the PA assembly manual the rest of
5160 the line should be ignored. */
5161 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5162 input_line_pointer
= ptemp
;
5165 while (!is_end_of_statement ())
5167 input_line_pointer
++;
5168 name
= input_line_pointer
;
5169 c
= get_symbol_end ();
5170 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5172 *input_line_pointer
= c
;
5173 input_line_pointer
++;
5174 spnum
= get_absolute_expression ();
5176 else if ((strncasecmp (name
, "SORT", 4) == 0))
5178 *input_line_pointer
= c
;
5179 input_line_pointer
++;
5180 sort
= get_absolute_expression ();
5182 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5184 *input_line_pointer
= c
;
5187 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5189 *input_line_pointer
= c
;
5192 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5194 *input_line_pointer
= c
;
5199 as_bad ("Invalid .SPACE argument");
5200 *input_line_pointer
= c
;
5201 if (! is_end_of_statement ())
5202 input_line_pointer
++;
5206 print_errors
= TRUE
;
5209 if (create_flag
&& seg
== NULL
)
5210 seg
= subseg_new (space_name
, 0);
5212 /* If create_flag is nonzero, then create the new space with
5213 the attributes computed above. Else set the values in
5214 an already existing space -- this can only happen for
5215 the first occurence of a built-in space. */
5217 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5218 private, sort
, seg
, 1);
5221 space
= is_defined_space (space_name
);
5222 SPACE_SPNUM (space
) = spnum
;
5223 SPACE_LOADABLE (space
) = loadable
& 1;
5224 SPACE_DEFINED (space
) = defined
& 1;
5225 SPACE_USER_DEFINED (space
) = 1;
5226 SPACE_PRIVATE (space
) = private & 1;
5227 SPACE_SORT (space
) = sort
& 0xff;
5228 space
->sd_seg
= seg
;
5231 #ifdef obj_set_section_attributes
5232 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5238 /* Adjust the frag's alignment according to the alignment needs
5239 of the given subspace/subsegment. */
5242 pa_align_subseg (seg
, subseg
)
5246 ssd_chain_struct
*now_subspace
;
5250 now_subspace
= pa_subsegment_to_subspace (seg
, subseg
);
5253 if (SUBSPACE_ALIGN (now_subspace
) == 0)
5254 alignment
= now_subspace
->ssd_last_align
;
5255 else if (now_subspace
->ssd_last_align
> SUBSPACE_ALIGN (now_subspace
))
5256 alignment
= now_subspace
->ssd_last_align
;
5258 alignment
= SUBSPACE_ALIGN (now_subspace
);
5260 while ((1 << shift
) < alignment
)
5264 shift
= bfd_get_section_alignment (stdoutput
, seg
);
5266 frag_align (shift
, 0);
5269 /* Handle a .SPACE pseudo-op; this switches the current space to the
5270 given space, creating the new space if necessary. */
5276 char *name
, c
, *space_name
, *save_s
;
5278 sd_chain_struct
*sd_chain
;
5280 if (within_procedure
)
5282 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5283 ignore_rest_of_line ();
5287 /* Check for some of the predefined spaces. FIXME: most of the code
5288 below is repeated several times, can we extract the common parts
5289 and place them into a subroutine or something similar? */
5290 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5292 input_line_pointer
+= 6;
5293 sd_chain
= is_defined_space ("$TEXT$");
5294 if (sd_chain
== NULL
)
5295 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5296 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5297 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5299 current_space
= sd_chain
;
5301 /* No need to align if we are already there. */
5302 if (now_seg
!= text_section
)
5303 pa_align_subseg (now_seg
, now_subseg
);
5305 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5308 = pa_subsegment_to_subspace (text_section
,
5309 sd_chain
->sd_last_subseg
);
5310 demand_empty_rest_of_line ();
5313 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5315 input_line_pointer
+= 9;
5316 sd_chain
= is_defined_space ("$PRIVATE$");
5317 if (sd_chain
== NULL
)
5318 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5319 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5320 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5322 current_space
= sd_chain
;
5324 /* No need to align if we are already there. */
5325 if (now_seg
!= data_section
)
5326 pa_align_subseg (now_seg
, now_subseg
);
5328 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5330 = pa_subsegment_to_subspace (data_section
,
5331 sd_chain
->sd_last_subseg
);
5332 demand_empty_rest_of_line ();
5335 if (!strncasecmp (input_line_pointer
,
5336 GDB_DEBUG_SPACE_NAME
,
5337 strlen (GDB_DEBUG_SPACE_NAME
)))
5339 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5340 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5341 if (sd_chain
== NULL
)
5342 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5343 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5344 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5346 current_space
= sd_chain
;
5349 asection
*gdb_section
5350 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5352 /* No need to align if we are already there. */
5353 if (strcmp (segment_name (now_seg
), GDB_DEBUG_SPACE_NAME
) != 0)
5354 pa_align_subseg (now_seg
, now_subseg
);
5356 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5358 = pa_subsegment_to_subspace (gdb_section
,
5359 sd_chain
->sd_last_subseg
);
5361 demand_empty_rest_of_line ();
5365 /* It could be a space specified by number. */
5367 save_s
= input_line_pointer
;
5368 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5370 if (sd_chain
= pa_find_space_by_number (temp
))
5372 current_space
= sd_chain
;
5374 if (now_seg
!= sd_chain
->sd_seg
)
5375 pa_align_subseg (now_seg
, now_subseg
);
5376 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5378 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5379 sd_chain
->sd_last_subseg
);
5380 demand_empty_rest_of_line ();
5385 /* Not a number, attempt to create a new space. */
5387 input_line_pointer
= save_s
;
5388 name
= input_line_pointer
;
5389 c
= get_symbol_end ();
5390 space_name
= xmalloc (strlen (name
) + 1);
5391 strcpy (space_name
, name
);
5392 *input_line_pointer
= c
;
5394 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5395 current_space
= sd_chain
;
5397 if (now_seg
!= sd_chain
->sd_seg
)
5398 pa_align_subseg (now_seg
, now_subseg
);
5399 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5400 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5401 sd_chain
->sd_last_subseg
);
5402 demand_empty_rest_of_line ();
5407 /* Switch to a new space. (I think). FIXME. */
5416 sd_chain_struct
*space
;
5418 name
= input_line_pointer
;
5419 c
= get_symbol_end ();
5420 space
= is_defined_space (name
);
5424 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5427 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5429 *input_line_pointer
= c
;
5430 demand_empty_rest_of_line ();
5434 /* If VALUE is an exact power of two between zero and 2^31, then
5435 return log2 (VALUE). Else return -1. */
5443 while ((1 << shift
) != value
&& shift
< 32)
5452 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5453 given subspace, creating the new subspace if necessary.
5455 FIXME. Should mirror pa_space more closely, in particular how
5456 they're broken up into subroutines. */
5459 pa_subspace (unused
)
5462 char *name
, *ss_name
, *alias
, c
;
5463 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5464 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5465 sd_chain_struct
*space
;
5466 ssd_chain_struct
*ssd
;
5469 if (within_procedure
)
5471 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5472 ignore_rest_of_line ();
5476 name
= input_line_pointer
;
5477 c
= get_symbol_end ();
5478 ss_name
= xmalloc (strlen (name
) + 1);
5479 strcpy (ss_name
, name
);
5480 *input_line_pointer
= c
;
5482 /* Load default values. */
5495 space
= current_space
;
5496 ssd
= is_defined_subspace (ss_name
);
5497 /* Allow user to override the builtin attributes of subspaces. But
5498 only allow the attributes to be changed once! */
5499 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5501 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5502 if (!is_end_of_statement ())
5503 as_warn ("Parameters of an existing subspace can\'t be modified");
5504 demand_empty_rest_of_line ();
5509 /* A new subspace. Load default values if it matches one of
5510 the builtin subspaces. */
5512 while (pa_def_subspaces
[i
].name
)
5514 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5516 loadable
= pa_def_subspaces
[i
].loadable
;
5517 common
= pa_def_subspaces
[i
].common
;
5518 dup_common
= pa_def_subspaces
[i
].dup_common
;
5519 code_only
= pa_def_subspaces
[i
].code_only
;
5520 zero
= pa_def_subspaces
[i
].zero
;
5521 space_index
= pa_def_subspaces
[i
].space_index
;
5522 alignment
= pa_def_subspaces
[i
].alignment
;
5523 quadrant
= pa_def_subspaces
[i
].quadrant
;
5524 access
= pa_def_subspaces
[i
].access
;
5525 sort
= pa_def_subspaces
[i
].sort
;
5526 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5527 alias
= pa_def_subspaces
[i
].alias
;
5534 /* We should be working with a new subspace now. Fill in
5535 any information as specified by the user. */
5536 if (!is_end_of_statement ())
5538 input_line_pointer
++;
5539 while (!is_end_of_statement ())
5541 name
= input_line_pointer
;
5542 c
= get_symbol_end ();
5543 if ((strncasecmp (name
, "QUAD", 4) == 0))
5545 *input_line_pointer
= c
;
5546 input_line_pointer
++;
5547 quadrant
= get_absolute_expression ();
5549 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5551 *input_line_pointer
= c
;
5552 input_line_pointer
++;
5553 alignment
= get_absolute_expression ();
5554 if (log2 (alignment
) == -1)
5556 as_bad ("Alignment must be a power of 2");
5560 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5562 *input_line_pointer
= c
;
5563 input_line_pointer
++;
5564 access
= get_absolute_expression ();
5566 else if ((strncasecmp (name
, "SORT", 4) == 0))
5568 *input_line_pointer
= c
;
5569 input_line_pointer
++;
5570 sort
= get_absolute_expression ();
5572 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5574 *input_line_pointer
= c
;
5577 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5579 *input_line_pointer
= c
;
5582 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5584 *input_line_pointer
= c
;
5587 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5589 *input_line_pointer
= c
;
5592 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5594 *input_line_pointer
= c
;
5597 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5598 as_bad ("FIRST not supported as a .SUBSPACE argument");
5600 as_bad ("Invalid .SUBSPACE argument");
5601 if (!is_end_of_statement ())
5602 input_line_pointer
++;
5606 /* Compute a reasonable set of BFD flags based on the information
5607 in the .subspace directive. */
5608 applicable
= bfd_applicable_section_flags (stdoutput
);
5611 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5614 if (common
|| dup_common
)
5615 flags
|= SEC_IS_COMMON
;
5617 /* This is a zero-filled subspace (eg BSS). */
5621 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5622 applicable
&= flags
;
5624 /* If this is an existing subspace, then we want to use the
5625 segment already associated with the subspace.
5627 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5628 lots of sections. It might be a problem in the PA ELF
5629 code, I do not know yet. For now avoid creating anything
5630 but the "standard" sections for ELF. */
5632 section
= ssd
->ssd_seg
;
5634 section
= subseg_new (alias
, 0);
5635 else if (! alias
&& USE_ALIASES
)
5637 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5638 demand_empty_rest_of_line ();
5642 section
= subseg_new (ss_name
, 0);
5644 /* Now set the flags. */
5645 bfd_set_section_flags (stdoutput
, section
, applicable
);
5647 /* Record any alignment request for this section. */
5648 record_alignment (section
, log2 (alignment
));
5650 /* Set the starting offset for this section. */
5651 bfd_set_section_vma (stdoutput
, section
,
5652 pa_subspace_start (space
, quadrant
));
5654 /* Now that all the flags are set, update an existing subspace,
5655 or create a new one. */
5658 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5659 code_only
, common
, dup_common
,
5660 sort
, zero
, access
, space_index
,
5661 alignment
, quadrant
,
5664 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5666 dup_common
, zero
, sort
,
5667 access
, space_index
,
5668 alignment
, quadrant
, section
);
5670 demand_empty_rest_of_line ();
5671 current_subspace
->ssd_seg
= section
;
5672 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5674 SUBSPACE_DEFINED (current_subspace
) = 1;
5679 /* Create default space and subspace dictionaries. */
5686 space_dict_root
= NULL
;
5687 space_dict_last
= NULL
;
5690 while (pa_def_spaces
[i
].name
)
5694 /* Pick the right name to use for the new section. */
5695 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5696 name
= pa_def_spaces
[i
].alias
;
5698 name
= pa_def_spaces
[i
].name
;
5700 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5701 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5702 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5703 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5704 pa_def_spaces
[i
].segment
, 0);
5709 while (pa_def_subspaces
[i
].name
)
5712 int applicable
, subsegment
;
5713 asection
*segment
= NULL
;
5714 sd_chain_struct
*space
;
5716 /* Pick the right name for the new section and pick the right
5717 subsegment number. */
5718 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5720 name
= pa_def_subspaces
[i
].alias
;
5721 subsegment
= pa_def_subspaces
[i
].subsegment
;
5725 name
= pa_def_subspaces
[i
].name
;
5729 /* Create the new section. */
5730 segment
= subseg_new (name
, subsegment
);
5733 /* For SOM we want to replace the standard .text, .data, and .bss
5734 sections with our own. */
5735 if (! strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && ! USE_ALIASES
)
5737 text_section
= segment
;
5738 applicable
= bfd_applicable_section_flags (stdoutput
);
5739 bfd_set_section_flags (stdoutput
, text_section
,
5740 applicable
& (SEC_ALLOC
| SEC_LOAD
5741 | SEC_RELOC
| SEC_CODE
5743 | SEC_HAS_CONTENTS
));
5745 else if (! strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && ! USE_ALIASES
)
5747 data_section
= segment
;
5748 applicable
= bfd_applicable_section_flags (stdoutput
);
5749 bfd_set_section_flags (stdoutput
, data_section
,
5750 applicable
& (SEC_ALLOC
| SEC_LOAD
5752 | SEC_HAS_CONTENTS
));
5756 else if (! strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && ! USE_ALIASES
)
5758 bss_section
= segment
;
5759 applicable
= bfd_applicable_section_flags (stdoutput
);
5760 bfd_set_section_flags (stdoutput
, bss_section
,
5761 applicable
& SEC_ALLOC
);
5764 /* Find the space associated with this subspace. */
5765 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5766 def_space_index
].segment
);
5769 as_fatal ("Internal error: Unable to find containing space for %s.",
5770 pa_def_subspaces
[i
].name
);
5773 create_new_subspace (space
, name
,
5774 pa_def_subspaces
[i
].loadable
,
5775 pa_def_subspaces
[i
].code_only
,
5776 pa_def_subspaces
[i
].common
,
5777 pa_def_subspaces
[i
].dup_common
,
5778 pa_def_subspaces
[i
].zero
,
5779 pa_def_subspaces
[i
].sort
,
5780 pa_def_subspaces
[i
].access
,
5781 pa_def_subspaces
[i
].space_index
,
5782 pa_def_subspaces
[i
].alignment
,
5783 pa_def_subspaces
[i
].quadrant
,
5791 /* Create a new space NAME, with the appropriate flags as defined
5792 by the given parameters.
5794 Add the new space to the space dictionary chain in numerical
5795 order as defined by the SORT entries. */
5797 static sd_chain_struct
*
5798 create_new_space (name
, spnum
, loadable
, defined
, private,
5799 sort
, seg
, user_defined
)
5809 sd_chain_struct
*chain_entry
;
5811 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5813 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5816 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5817 strcpy (SPACE_NAME (chain_entry
), name
);
5818 SPACE_NAME_INDEX (chain_entry
) = 0;
5819 SPACE_LOADABLE (chain_entry
) = loadable
;
5820 SPACE_DEFINED (chain_entry
) = defined
;
5821 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5822 SPACE_PRIVATE (chain_entry
) = private;
5823 SPACE_SPNUM (chain_entry
) = spnum
;
5824 SPACE_SORT (chain_entry
) = sort
;
5826 chain_entry
->sd_seg
= seg
;
5827 chain_entry
->sd_last_subseg
= -1;
5828 chain_entry
->sd_next
= NULL
;
5830 /* Find spot for the new space based on its sort key. */
5831 if (!space_dict_last
)
5832 space_dict_last
= chain_entry
;
5834 if (space_dict_root
== NULL
)
5835 space_dict_root
= chain_entry
;
5838 sd_chain_struct
*chain_pointer
;
5839 sd_chain_struct
*prev_chain_pointer
;
5841 chain_pointer
= space_dict_root
;
5842 prev_chain_pointer
= NULL
;
5844 while (chain_pointer
)
5846 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5848 prev_chain_pointer
= chain_pointer
;
5849 chain_pointer
= chain_pointer
->sd_next
;
5855 /* At this point we've found the correct place to add the new
5856 entry. So add it and update the linked lists as appropriate. */
5857 if (prev_chain_pointer
)
5859 chain_entry
->sd_next
= chain_pointer
;
5860 prev_chain_pointer
->sd_next
= chain_entry
;
5864 space_dict_root
= chain_entry
;
5865 chain_entry
->sd_next
= chain_pointer
;
5868 if (chain_entry
->sd_next
== NULL
)
5869 space_dict_last
= chain_entry
;
5872 /* This is here to catch predefined spaces which do not get
5873 modified by the user's input. Another call is found at
5874 the bottom of pa_parse_space_stmt to handle cases where
5875 the user modifies a predefined space. */
5876 #ifdef obj_set_section_attributes
5877 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5883 /* Create a new subspace NAME, with the appropriate flags as defined
5884 by the given parameters.
5886 Add the new subspace to the subspace dictionary chain in numerical
5887 order as defined by the SORT entries. */
5889 static ssd_chain_struct
*
5890 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5891 dup_common
, is_zero
, sort
, access
, space_index
,
5892 alignment
, quadrant
, seg
)
5893 sd_chain_struct
*space
;
5895 char loadable
, code_only
, common
, dup_common
, is_zero
;
5903 ssd_chain_struct
*chain_entry
;
5905 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5907 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5909 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5910 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5912 SUBSPACE_ACCESS (chain_entry
) = access
;
5913 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5914 SUBSPACE_COMMON (chain_entry
) = common
;
5915 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5916 SUBSPACE_SORT (chain_entry
) = sort
;
5917 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
5918 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5919 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5920 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
5921 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5922 SUBSPACE_ZERO (chain_entry
) = is_zero
;
5924 /* Initialize subspace_defined. When we hit a .subspace directive
5925 we'll set it to 1 which "locks-in" the subspace attributes. */
5926 SUBSPACE_DEFINED (chain_entry
) = 0;
5928 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5929 chain_entry
->ssd_seg
= seg
;
5930 chain_entry
->ssd_last_align
= 1;
5931 chain_entry
->ssd_next
= NULL
;
5933 /* Find spot for the new subspace based on its sort key. */
5934 if (space
->sd_subspaces
== NULL
)
5935 space
->sd_subspaces
= chain_entry
;
5938 ssd_chain_struct
*chain_pointer
;
5939 ssd_chain_struct
*prev_chain_pointer
;
5941 chain_pointer
= space
->sd_subspaces
;
5942 prev_chain_pointer
= NULL
;
5944 while (chain_pointer
)
5946 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
5948 prev_chain_pointer
= chain_pointer
;
5949 chain_pointer
= chain_pointer
->ssd_next
;
5956 /* Now we have somewhere to put the new entry. Insert it and update
5958 if (prev_chain_pointer
)
5960 chain_entry
->ssd_next
= chain_pointer
;
5961 prev_chain_pointer
->ssd_next
= chain_entry
;
5965 space
->sd_subspaces
= chain_entry
;
5966 chain_entry
->ssd_next
= chain_pointer
;
5970 #ifdef obj_set_subsection_attributes
5971 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5979 /* Update the information for the given subspace based upon the
5980 various arguments. Return the modified subspace chain entry. */
5982 static ssd_chain_struct
*
5983 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5984 zero
, access
, space_index
, alignment
, quadrant
, section
)
5985 sd_chain_struct
*space
;
5999 ssd_chain_struct
*chain_entry
;
6001 if ((chain_entry
= is_defined_subspace (name
)))
6003 SUBSPACE_ACCESS (chain_entry
) = access
;
6004 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
6005 SUBSPACE_COMMON (chain_entry
) = common
;
6006 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
6007 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
6008 SUBSPACE_SORT (chain_entry
) = sort
;
6009 SUBSPACE_ALIGN (chain_entry
) = alignment
;
6010 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
6011 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
6012 SUBSPACE_ZERO (chain_entry
) = zero
;
6017 #ifdef obj_set_subsection_attributes
6018 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
6026 /* Return the space chain entry for the space with the name NAME or
6027 NULL if no such space exists. */
6029 static sd_chain_struct
*
6030 is_defined_space (name
)
6033 sd_chain_struct
*chain_pointer
;
6035 for (chain_pointer
= space_dict_root
;
6037 chain_pointer
= chain_pointer
->sd_next
)
6039 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6040 return chain_pointer
;
6043 /* No mapping from segment to space was found. Return NULL. */
6047 /* Find and return the space associated with the given seg. If no mapping
6048 from the given seg to a space is found, then return NULL.
6050 Unlike subspaces, the number of spaces is not expected to grow much,
6051 so a linear exhaustive search is OK here. */
6053 static sd_chain_struct
*
6054 pa_segment_to_space (seg
)
6057 sd_chain_struct
*space_chain
;
6059 /* Walk through each space looking for the correct mapping. */
6060 for (space_chain
= space_dict_root
;
6062 space_chain
= space_chain
->sd_next
)
6064 if (space_chain
->sd_seg
== seg
)
6068 /* Mapping was not found. Return NULL. */
6072 /* Return the space chain entry for the subspace with the name NAME or
6073 NULL if no such subspace exists.
6075 Uses a linear search through all the spaces and subspaces, this may
6076 not be appropriate if we ever being placing each function in its
6079 static ssd_chain_struct
*
6080 is_defined_subspace (name
)
6083 sd_chain_struct
*space_chain
;
6084 ssd_chain_struct
*subspace_chain
;
6086 /* Walk through each space. */
6087 for (space_chain
= space_dict_root
;
6089 space_chain
= space_chain
->sd_next
)
6091 /* Walk through each subspace looking for a name which matches. */
6092 for (subspace_chain
= space_chain
->sd_subspaces
;
6094 subspace_chain
= subspace_chain
->ssd_next
)
6095 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6096 return subspace_chain
;
6099 /* Subspace wasn't found. Return NULL. */
6103 /* Find and return the subspace associated with the given seg. If no
6104 mapping from the given seg to a subspace is found, then return NULL.
6106 If we ever put each procedure/function within its own subspace
6107 (to make life easier on the compiler and linker), then this will have
6108 to become more efficient. */
6110 static ssd_chain_struct
*
6111 pa_subsegment_to_subspace (seg
, subseg
)
6115 sd_chain_struct
*space_chain
;
6116 ssd_chain_struct
*subspace_chain
;
6118 /* Walk through each space. */
6119 for (space_chain
= space_dict_root
;
6121 space_chain
= space_chain
->sd_next
)
6123 if (space_chain
->sd_seg
== seg
)
6125 /* Walk through each subspace within each space looking for
6126 the correct mapping. */
6127 for (subspace_chain
= space_chain
->sd_subspaces
;
6129 subspace_chain
= subspace_chain
->ssd_next
)
6130 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6131 return subspace_chain
;
6135 /* No mapping from subsegment to subspace found. Return NULL. */
6139 /* Given a number, try and find a space with the name number.
6141 Return a pointer to a space dictionary chain entry for the space
6142 that was found or NULL on failure. */
6144 static sd_chain_struct
*
6145 pa_find_space_by_number (number
)
6148 sd_chain_struct
*space_chain
;
6150 for (space_chain
= space_dict_root
;
6152 space_chain
= space_chain
->sd_next
)
6154 if (SPACE_SPNUM (space_chain
) == number
)
6158 /* No appropriate space found. Return NULL. */
6162 /* Return the starting address for the given subspace. If the starting
6163 address is unknown then return zero. */
6166 pa_subspace_start (space
, quadrant
)
6167 sd_chain_struct
*space
;
6170 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6171 is not correct for the PA OSF1 port. */
6172 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6174 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6180 /* FIXME. Needs documentation. */
6182 pa_next_subseg (space
)
6183 sd_chain_struct
*space
;
6186 space
->sd_last_subseg
++;
6187 return space
->sd_last_subseg
;
6190 /* Helper function for pa_stringer. Used to find the end of
6197 unsigned int c
= *s
& CHAR_MASK
;
6209 /* Handle a .STRING type pseudo-op. */
6212 pa_stringer (append_zero
)
6215 char *s
, num_buf
[4];
6219 /* Preprocess the string to handle PA-specific escape sequences.
6220 For example, \xDD where DD is a hexidecimal number should be
6221 changed to \OOO where OOO is an octal number. */
6223 /* Skip the opening quote. */
6224 s
= input_line_pointer
+ 1;
6226 while (is_a_char (c
= pa_stringer_aux (s
++)))
6233 /* Handle \x<num>. */
6236 unsigned int number
;
6241 /* Get pas the 'x'. */
6243 for (num_digit
= 0, number
= 0, dg
= *s
;
6245 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6246 || (dg
>= 'A' && dg
<= 'F'));
6250 number
= number
* 16 + dg
- '0';
6251 else if (dg
>= 'a' && dg
<= 'f')
6252 number
= number
* 16 + dg
- 'a' + 10;
6254 number
= number
* 16 + dg
- 'A' + 10;
6264 sprintf (num_buf
, "%02o", number
);
6267 sprintf (num_buf
, "%03o", number
);
6270 for (i
= 0; i
<= num_digit
; i
++)
6271 s_start
[i
] = num_buf
[i
];
6275 /* This might be a "\"", skip over the escaped char. */
6282 stringer (append_zero
);
6283 pa_undefine_label ();
6286 /* Handle a .VERSION pseudo-op. */
6293 pa_undefine_label ();
6296 /* Just like a normal cons, but when finished we have to undefine
6297 the latest space label. */
6304 pa_undefine_label ();
6307 /* Switch to the data space. As usual delete our label. */
6314 pa_undefine_label ();
6317 /* FIXME. What's the purpose of this pseudo-op? */
6323 pa_undefine_label ();
6326 /* Like float_cons, but we need to undefine our label. */
6329 pa_float_cons (float_type
)
6332 float_cons (float_type
);
6333 pa_undefine_label ();
6336 /* Like s_fill, but delete our label when finished. */
6343 pa_undefine_label ();
6346 /* Like lcomm, but delete our label when finished. */
6349 pa_lcomm (needs_align
)
6352 s_lcomm (needs_align
);
6353 pa_undefine_label ();
6356 /* Like lsym, but delete our label when finished. */
6363 pa_undefine_label ();
6366 /* Switch to the text space. Like s_text, but delete our
6367 label when finished. */
6373 pa_undefine_label ();
6376 /* On the PA relocations which involve function symbols must not be
6377 adjusted. This so that the linker can know when/how to create argument
6378 relocation stubs for indirect calls and calls to static functions.
6380 FIXME. Also reject R_HPPA relocations which are 32 bits
6381 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6382 needs to generate relocations to push the addend and symbol value
6383 onto the stack, add them, then pop the value off the stack and
6384 use it in a relocation -- yuk. */
6387 hppa_fix_adjustable (fixp
)
6390 struct hppa_fix_struct
*hppa_fix
;
6392 hppa_fix
= fixp
->tc_fix_data
;
6394 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6397 if (fixp
->fx_addsy
== 0
6398 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6404 /* Now for some ELF specific code. FIXME. */
6406 static symext_chainS
*symext_rootP
;
6407 static symext_chainS
*symext_lastP
;
6409 /* Do any symbol processing requested by the target-cpu or target-format. */
6412 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6414 elf_symbol_type
*symbolP
;
6417 symext_chainS
*symextP
;
6418 unsigned int arg_reloc
;
6420 /* Only functions can have argument relocations. */
6421 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6424 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6426 /* If there are no argument relocation bits, then no relocation is
6427 necessary. Do not add this to the symextn section. */
6431 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6433 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6434 symextP
[0].next
= &symextP
[1];
6436 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6437 symextP
[1].next
= NULL
;
6439 if (symext_rootP
== NULL
)
6441 symext_rootP
= &symextP
[0];
6442 symext_lastP
= &symextP
[1];
6446 symext_lastP
->next
= &symextP
[0];
6447 symext_lastP
= &symextP
[1];
6451 /* Make sections needed by the target cpu and/or target format. */
6453 hppa_tc_make_sections (abfd
)
6456 symext_chainS
*symextP
;
6458 asection
*symextn_sec
;
6459 segT save_seg
= now_seg
;
6460 subsegT save_subseg
= now_subseg
;
6462 /* Build the symbol extension section. */
6463 hppa_tc_make_symextn_section ();
6465 /* Force some calculation to occur. */
6466 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6468 hppa_elf_stub_finish (abfd
);
6470 /* If no symbols for the symbol extension section, then stop now. */
6471 if (symext_rootP
== NULL
)
6474 /* Count the number of symbols for the symbol extension section. */
6475 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6478 size
= sizeof (symext_entryS
) * n
;
6480 /* Switch to the symbol extension section. */
6481 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6483 frag_wane (frag_now
);
6486 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6489 int *symtab_map
= elf_sym_extra (abfd
);
6492 /* First, patch the symbol extension record to reflect the true
6493 symbol table index. */
6495 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6497 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6498 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6502 ptr
= frag_more (sizeof (symextP
->entry
));
6503 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6506 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6507 frag_wane (frag_now
);
6509 /* Switch back to the original segment. */
6510 subseg_set (save_seg
, save_subseg
);
6515 /* Make the symbol extension section. */
6518 hppa_tc_make_symextn_section ()
6522 symext_chainS
*symextP
;
6526 segT save_seg
= now_seg
;
6527 subsegT save_subseg
= now_subseg
;
6529 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6532 size
= sizeof (symext_entryS
) * n
;
6534 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6536 bfd_set_section_flags (stdoutput
, symextn_sec
,
6537 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6538 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6540 /* Now, switch back to the original segment. */
6541 subseg_set (save_seg
, save_subseg
);
6545 /* Build the symbol extension section. */
6548 pa_build_symextn_section ()
6551 asection
*save_seg
= now_seg
;
6552 subsegT subseg
= (subsegT
) 0;
6553 subsegT save_subseg
= now_subseg
;
6555 seg
= subseg_new (".hppa_symextn", subseg
);
6556 bfd_set_section_flags (stdoutput
,
6558 SEC_HAS_CONTENTS
| SEC_READONLY
6559 | SEC_ALLOC
| SEC_LOAD
);
6561 subseg_set (save_seg
, save_subseg
);
6565 /* For ELF, this function serves one purpose: to setup the st_size
6566 field of STT_FUNC symbols. To do this, we need to scan the
6567 call_info structure list, determining st_size in one of two possible
6570 1. call_info->start_frag->fr_fix has the size of the fragment.
6571 This approach assumes that the function was built into a
6572 single fragment. This works for most cases, but might fail.
6573 For example, if there was a segment change in the middle of
6576 2. The st_size field is the difference in the addresses of the
6577 call_info->start_frag->fr_address field and the fr_address
6578 field of the next fragment with fr_type == rs_fill and
6582 elf_hppa_final_processing ()
6584 struct call_info
*call_info_pointer
;
6586 for (call_info_pointer
= call_info_root
;
6588 call_info_pointer
= call_info_pointer
->ci_next
)
6590 elf_symbol_type
*esym
6591 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6592 esym
->internal_elf_sym
.st_size
=
6593 S_GET_VALUE (call_info_pointer
->end_symbol
)
6594 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;