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. */
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 ((char *));
549 static int evaluate_absolute
PARAMS ((expressionS
, int));
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_export_args
PARAMS ((symbolS
*));
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,
597 int, int, int, subsegT
));
598 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
599 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
600 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
601 static ssd_chain_struct
* pa_subsegment_to_subspace
PARAMS ((asection
*,
603 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
604 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
605 static void pa_ip
PARAMS ((char *));
606 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
607 long, expressionS
*, int,
608 bfd_reloc_code_real_type
, long,
610 static void md_apply_fix_1
PARAMS ((fixS
*, long));
611 static int is_end_of_statement
PARAMS ((void));
612 static int reg_name_search
PARAMS ((char *));
613 static int pa_chk_field_selector
PARAMS ((char **));
614 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
615 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
616 static void process_exit
PARAMS ((void));
617 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
618 static void pa_align_subseg
PARAMS ((asection
*, subsegT
));
619 static int log2
PARAMS ((int));
620 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
621 static unsigned int pa_stringer_aux
PARAMS ((char *));
622 static void pa_spaces_begin
PARAMS ((void));
625 /* File and gloally scoped variable declarations. */
627 /* Root and final entry in the space chain. */
628 static sd_chain_struct
*space_dict_root
;
629 static sd_chain_struct
*space_dict_last
;
631 /* The current space and subspace. */
632 static sd_chain_struct
*current_space
;
633 static ssd_chain_struct
*current_subspace
;
635 /* Root of the call_info chain. */
636 static struct call_info
*call_info_root
;
638 /* The last call_info (for functions) structure
639 seen so it can be associated with fixups and
641 static struct call_info
*last_call_info
;
643 /* The last call description (for actual calls). */
644 static struct call_desc last_call_desc
;
646 /* Relaxation isn't supported for the PA yet. */
647 const relax_typeS md_relax_table
[] = {0};
649 /* Jumps are always the same size -- one instruction. */
650 int md_short_jump_size
= 4;
651 int md_long_jump_size
= 4;
653 /* handle of the OPCODE hash table */
654 static struct hash_control
*op_hash
= NULL
;
656 /* This array holds the chars that always start a comment. If the
657 pre-processor is disabled, these aren't very useful. */
658 const char comment_chars
[] = ";";
660 /* Table of pseudo ops for the PA. FIXME -- how many of these
661 are now redundant with the overall GAS and the object file
663 const pseudo_typeS md_pseudo_table
[] =
665 /* align pseudo-ops on the PA specify the actual alignment requested,
666 not the log2 of the requested alignment. */
667 {"align", s_align_bytes
, 8},
668 {"ALIGN", s_align_bytes
, 8},
669 {"block", pa_block
, 1},
670 {"BLOCK", pa_block
, 1},
671 {"blockz", pa_block
, 0},
672 {"BLOCKZ", pa_block
, 0},
673 {"byte", pa_cons
, 1},
674 {"BYTE", pa_cons
, 1},
675 {"call", pa_call
, 0},
676 {"CALL", pa_call
, 0},
677 {"callinfo", pa_callinfo
, 0},
678 {"CALLINFO", pa_callinfo
, 0},
679 {"code", pa_code
, 0},
680 {"CODE", pa_code
, 0},
681 {"comm", pa_comm
, 0},
682 {"COMM", pa_comm
, 0},
683 {"copyright", pa_copyright
, 0},
684 {"COPYRIGHT", pa_copyright
, 0},
685 {"data", pa_data
, 0},
686 {"DATA", pa_data
, 0},
687 {"desc", pa_desc
, 0},
688 {"DESC", pa_desc
, 0},
689 {"double", pa_float_cons
, 'd'},
690 {"DOUBLE", pa_float_cons
, 'd'},
693 {"enter", pa_enter
, 0},
694 {"ENTER", pa_enter
, 0},
695 {"entry", pa_entry
, 0},
696 {"ENTRY", pa_entry
, 0},
699 {"exit", pa_exit
, 0},
700 {"EXIT", pa_exit
, 0},
701 {"export", pa_export
, 0},
702 {"EXPORT", pa_export
, 0},
703 {"fill", pa_fill
, 0},
704 {"FILL", pa_fill
, 0},
705 {"float", pa_float_cons
, 'f'},
706 {"FLOAT", pa_float_cons
, 'f'},
707 {"half", pa_cons
, 2},
708 {"HALF", pa_cons
, 2},
709 {"import", pa_import
, 0},
710 {"IMPORT", pa_import
, 0},
713 {"label", pa_label
, 0},
714 {"LABEL", pa_label
, 0},
715 {"lcomm", pa_lcomm
, 0},
716 {"LCOMM", pa_lcomm
, 0},
717 {"leave", pa_leave
, 0},
718 {"LEAVE", pa_leave
, 0},
719 {"long", pa_cons
, 4},
720 {"LONG", pa_cons
, 4},
721 {"lsym", pa_lsym
, 0},
722 {"LSYM", pa_lsym
, 0},
723 {"octa", pa_cons
, 16},
724 {"OCTA", pa_cons
, 16},
725 {"org", pa_origin
, 0},
726 {"ORG", pa_origin
, 0},
727 {"origin", pa_origin
, 0},
728 {"ORIGIN", pa_origin
, 0},
729 {"param", pa_param
, 0},
730 {"PARAM", pa_param
, 0},
731 {"proc", pa_proc
, 0},
732 {"PROC", pa_proc
, 0},
733 {"procend", pa_procend
, 0},
734 {"PROCEND", pa_procend
, 0},
735 {"quad", pa_cons
, 8},
736 {"QUAD", pa_cons
, 8},
739 {"short", pa_cons
, 2},
740 {"SHORT", pa_cons
, 2},
741 {"single", pa_float_cons
, 'f'},
742 {"SINGLE", pa_float_cons
, 'f'},
743 {"space", pa_space
, 0},
744 {"SPACE", pa_space
, 0},
745 {"spnum", pa_spnum
, 0},
746 {"SPNUM", pa_spnum
, 0},
747 {"string", pa_stringer
, 0},
748 {"STRING", pa_stringer
, 0},
749 {"stringz", pa_stringer
, 1},
750 {"STRINGZ", pa_stringer
, 1},
751 {"subspa", pa_subspace
, 0},
752 {"SUBSPA", pa_subspace
, 0},
753 {"text", pa_text
, 0},
754 {"TEXT", pa_text
, 0},
755 {"version", pa_version
, 0},
756 {"VERSION", pa_version
, 0},
757 {"word", pa_cons
, 4},
758 {"WORD", pa_cons
, 4},
762 /* This array holds the chars that only start a comment at the beginning of
763 a line. If the line seems to have the form '# 123 filename'
764 .line and .file directives will appear in the pre-processed output.
766 Note that input_file.c hand checks for '#' at the beginning of the
767 first line of the input file. This is because the compiler outputs
768 #NO_APP at the beginning of its output.
770 Also note that '/*' will always start a comment. */
771 const char line_comment_chars
[] = "#";
773 /* This array holds the characters which act as line separators. */
774 const char line_separator_chars
[] = "!";
776 /* Chars that can be used to separate mant from exp in floating point nums. */
777 const char EXP_CHARS
[] = "eE";
779 /* Chars that mean this number is a floating point constant.
780 As in 0f12.456 or 0d1.2345e12.
782 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
783 changed in read.c. Ideally it shouldn't hae to know abou it at
784 all, but nothing is ideal around here. */
785 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
787 static struct pa_it the_insn
;
789 /* Points to the end of an expression just parsed by get_expressoin
790 and friends. FIXME. This shouldn't be handled with a file-global
792 static char *expr_end
;
794 /* Nonzero if a .callinfo appeared within the current procedure. */
795 static int callinfo_found
;
797 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
798 static int within_entry_exit
;
800 /* Nonzero if the assembler has completed exit processing for the
801 current procedure. */
802 static int exit_processing_complete
;
804 /* Nonzero if the assembler is currently within a procedure definition. */
805 static int within_procedure
;
807 /* Handle on strucutre which keep track of the last symbol
808 seen in each subspace. */
809 static label_symbol_struct
*label_symbols_rootp
= NULL
;
811 /* Holds the last field selector. */
812 static int hppa_field_selector
;
814 /* Nonzero if errors are to be printed. */
815 static int print_errors
= 1;
817 /* List of registers that are pre-defined:
819 Each general register has one predefined name of the form
820 %r<REGNUM> which has the value <REGNUM>.
822 Space and control registers are handled in a similar manner,
823 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
825 Likewise for the floating point registers, but of the form
826 %fr<REGNUM>. Floating point registers have additional predefined
827 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
828 again have the value <REGNUM>.
830 Many registers also have synonyms:
832 %r26 - %r23 have %arg0 - %arg3 as synonyms
833 %r28 - %r29 have %ret0 - %ret1 as synonyms
834 %r30 has %sp as a synonym
835 %r27 has %dp as a synonym
836 %r2 has %rp as a synonym
838 Almost every control register has a synonym; they are not listed
841 The table is sorted. Suitable for searching by a binary search. */
843 static const struct pd_reg pre_defined_registers
[] =
1055 /* This table is sorted by order of the length of the string. This is
1056 so we check for <> before we check for <. If we had a <> and checked
1057 for < first, we would get a false match. */
1058 static const struct fp_cond_map fp_cond_map
[] =
1094 static const struct selector_entry selector_table
[] =
1129 /* default space and subspace dictionaries */
1131 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1132 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1134 /* pre-defined subsegments (subspaces) for the HPPA. */
1135 #define SUBSEG_CODE 0
1136 #define SUBSEG_DATA 0
1137 #define SUBSEG_LIT 1
1138 #define SUBSEG_BSS 2
1139 #define SUBSEG_UNWIND 3
1140 #define SUBSEG_GDB_STRINGS 0
1141 #define SUBSEG_GDB_SYMBOLS 1
1143 static struct default_subspace_dict pa_def_subspaces
[] =
1145 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1146 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1147 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1148 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1149 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1150 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1153 static struct default_space_dict pa_def_spaces
[] =
1155 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1156 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1157 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1160 /* Misc local definitions used by the assembler. */
1162 /* Return nonzero if the string pointed to by S potentially represents
1163 a right or left half of a FP register */
1164 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1165 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1167 /* These macros are used to maintain spaces/subspaces. */
1168 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1169 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1170 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1171 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1172 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1173 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1174 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1175 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1177 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1178 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1179 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1180 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1181 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1182 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1183 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1184 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1185 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1186 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1187 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1188 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1189 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1190 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1192 #define is_DP_relative(exp) \
1193 ((exp).X_op == O_subtract \
1194 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1196 #define is_PC_relative(exp) \
1197 ((exp).X_op == O_subtract \
1198 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1200 #define is_complex(exp) \
1201 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1203 /* Actual functions to implement the PA specific code for the assembler. */
1205 /* Returns a pointer to the label_symbol_struct for the current space.
1206 or NULL if no label_symbol_struct exists for the current space. */
1208 static label_symbol_struct
*
1211 label_symbol_struct
*label_chain
;
1212 sd_chain_struct
*space_chain
= current_space
;
1214 for (label_chain
= label_symbols_rootp
;
1216 label_chain
= label_chain
->lss_next
)
1217 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1223 /* Defines a label for the current space. If one is already defined,
1224 this function will replace it with the new label. */
1227 pa_define_label (symbol
)
1230 label_symbol_struct
*label_chain
= pa_get_label ();
1231 sd_chain_struct
*space_chain
= current_space
;
1234 label_chain
->lss_label
= symbol
;
1237 /* Create a new label entry and add it to the head of the chain. */
1239 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1240 label_chain
->lss_label
= symbol
;
1241 label_chain
->lss_space
= space_chain
;
1242 label_chain
->lss_next
= NULL
;
1244 if (label_symbols_rootp
)
1245 label_chain
->lss_next
= label_symbols_rootp
;
1247 label_symbols_rootp
= label_chain
;
1251 /* Removes a label definition for the current space.
1252 If there is no label_symbol_struct entry, then no action is taken. */
1255 pa_undefine_label ()
1257 label_symbol_struct
*label_chain
;
1258 label_symbol_struct
*prev_label_chain
= NULL
;
1259 sd_chain_struct
*space_chain
= current_space
;
1261 for (label_chain
= label_symbols_rootp
;
1263 label_chain
= label_chain
->lss_next
)
1265 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1267 /* Remove the label from the chain and free its memory. */
1268 if (prev_label_chain
)
1269 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1271 label_symbols_rootp
= label_chain
->lss_next
;
1276 prev_label_chain
= label_chain
;
1281 /* An HPPA-specific version of fix_new. This is required because the HPPA
1282 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1283 results in the creation of an instance of an hppa_fix_struct. An
1284 hppa_fix_struct stores the extra information along with a pointer to the
1285 original fixS. This is attached to the original fixup via the
1286 tc_fix_data field. */
1289 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1290 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1294 symbolS
*add_symbol
;
1298 bfd_reloc_code_real_type r_type
;
1306 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1307 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1310 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1312 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1313 new_fix
->tc_fix_data
= hppa_fix
;
1314 hppa_fix
->fx_r_type
= r_type
;
1315 hppa_fix
->fx_r_field
= r_field
;
1316 hppa_fix
->fx_r_format
= r_format
;
1317 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1320 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1322 /* If necessary call BFD backend function to attach the
1323 unwind bits to the target dependent parts of a BFD symbol.
1325 #ifdef obj_attach_unwind_info
1326 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1331 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1332 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1335 parse_cons_expression_hppa (exp
)
1338 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1342 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1343 hppa_field_selector is set by the parse_cons_expression_hppa. */
1346 cons_fix_new_hppa (frag
, where
, size
, exp
)
1352 unsigned int reloc_type
;
1354 if (is_DP_relative (*exp
))
1355 reloc_type
= R_HPPA_GOTOFF
;
1356 else if (is_complex (*exp
))
1357 reloc_type
= R_HPPA_COMPLEX
;
1359 reloc_type
= R_HPPA
;
1361 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1362 as_warn ("Invalid field selector. Assuming F%%.");
1364 fix_new_hppa (frag
, where
, size
,
1365 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1366 hppa_field_selector
, 32, 0, (char *) 0);
1368 /* Reset field selector to its default state. */
1369 hppa_field_selector
= 0;
1372 /* This function is called once, at assembler startup time. It should
1373 set up all the tables, etc. that the MD part of the assembler will need. */
1378 char *retval
= NULL
;
1382 last_call_info
= NULL
;
1383 call_info_root
= NULL
;
1385 /* Folding of text and data segments fails miserably on the PA.
1386 Warn user and disable "-R" option. */
1389 as_warn ("-R option not supported on this target.");
1390 flag_readonly_data_in_text
= 0;
1396 op_hash
= hash_new ();
1397 if (op_hash
== NULL
)
1398 as_fatal ("Virtual memory exhausted");
1400 while (i
< NUMOPCODES
)
1402 const char *name
= pa_opcodes
[i
].name
;
1403 retval
= hash_insert (op_hash
, name
, &pa_opcodes
[i
]);
1404 if (retval
!= NULL
&& *retval
!= '\0')
1406 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1411 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1412 != pa_opcodes
[i
].match
)
1414 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1415 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1420 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1424 as_fatal ("Broken assembler. No assembly attempted.");
1426 /* SOM will change text_section. To make sure we never put
1427 anything into the old one switch to the new one now. */
1428 subseg_set (text_section
, 0);
1431 /* Called at the end of assembling a source file. Nothing to do
1432 at this point on the PA. */
1440 /* Assemble a single instruction storing it into a frag. */
1447 /* The had better be something to assemble. */
1450 /* Assemble the instruction. Results are saved into "the_insn". */
1453 /* Get somewhere to put the assembled instrution. */
1456 /* Output the opcode. */
1457 md_number_to_chars (to
, the_insn
.opcode
, 4);
1459 /* If necessary output more stuff. */
1460 if (the_insn
.reloc
!= R_HPPA_NONE
)
1461 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1462 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1463 the_insn
.reloc
, the_insn
.field_selector
,
1464 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1468 /* Do the real work for assembling a single instruction. Store results
1469 into the global "the_insn" variable.
1471 FIXME: Should define and use some functions/macros to handle
1472 various common insertions of information into the opcode. */
1478 char *error_message
= "";
1479 char *s
, c
, *argstart
, *name
, *save_s
;
1483 int reg
, s2
, s3
, m
, a
, uu
, cmpltr
, nullif
, flag
, sfu
, cond
;
1484 unsigned int im21
, im14
, im11
, im5
;
1485 unsigned long i
, opcode
;
1486 struct pa_opcode
*insn
;
1488 /* Skip to something interesting. */
1489 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1508 as_bad ("Unknown opcode: `%s'", str
);
1514 /* Convert everything into lower case. */
1517 if (isupper (*save_s
))
1518 *save_s
= tolower (*save_s
);
1522 /* Look up the opcode in the has table. */
1523 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1525 as_bad ("Unknown opcode: `%s'", str
);
1534 /* Mark the location where arguments for the instruction start, then
1535 start processing them. */
1539 /* Do some initialization. */
1540 opcode
= insn
->match
;
1541 bzero (&the_insn
, sizeof (the_insn
));
1543 the_insn
.reloc
= R_HPPA_NONE
;
1545 /* Build the opcode, checking as we go to make
1546 sure that the operands match. */
1547 for (args
= insn
->args
;; ++args
)
1552 /* End of arguments. */
1568 /* These must match exactly. */
1577 /* Handle a 5 bit register or control register field at 10. */
1580 reg
= pa_parse_number (&s
, 0);
1581 if (reg
< 32 && reg
>= 0)
1583 opcode
|= reg
<< 21;
1588 /* Handle a 5 bit register field at 15. */
1590 reg
= pa_parse_number (&s
, 0);
1591 if (reg
< 32 && reg
>= 0)
1593 opcode
|= reg
<< 16;
1598 /* Handle a 5 bit register field at 31. */
1601 reg
= pa_parse_number (&s
, 0);
1602 if (reg
< 32 && reg
>= 0)
1609 /* Handle a 5 bit field length at 31. */
1611 pa_get_absolute_expression (s
);
1612 if (the_insn
.exp
.X_op
== O_constant
)
1614 reg
= the_insn
.exp
.X_add_number
;
1615 if (reg
<= 32 && reg
> 0)
1624 /* Handle a 5 bit immediate at 15. */
1626 pa_get_absolute_expression (s
);
1627 if (the_insn
.exp
.X_add_number
> 15)
1629 as_bad ("5 bit immediate > 15. Set to 15");
1630 the_insn
.exp
.X_add_number
= 15;
1632 else if (the_insn
.exp
.X_add_number
< -16)
1634 as_bad ("5 bit immediate < -16. Set to -16");
1635 the_insn
.exp
.X_add_number
= -16;
1638 low_sign_unext (evaluate_absolute (the_insn
.exp
,
1639 the_insn
.field_selector
),
1641 opcode
|= (im5
<< 16);
1645 /* Handle a 2 bit space identifier at 17. */
1647 s2
= pa_parse_number (&s
, 0);
1648 if (s2
< 4 && s2
>= 0)
1655 /* Handle a 3 bit space identifier at 18. */
1657 s3
= pa_parse_number (&s
, 0);
1658 if (s3
< 8 && s3
>= 0)
1660 dis_assemble_3 (s3
, &s3
);
1666 /* Handle a completer for an indexing load or store. */
1671 while (*s
== ',' && i
< 2)
1674 if (strncasecmp (s
, "sm", 2) == 0)
1681 else if (strncasecmp (s
, "m", 1) == 0)
1683 else if (strncasecmp (s
, "s", 1) == 0)
1686 as_bad ("Invalid Indexed Load Completer.");
1691 as_bad ("Invalid Indexed Load Completer Syntax.");
1692 while (*s
== ' ' || *s
== '\t')
1699 /* Handle a short load/store completer. */
1706 if (strncasecmp (s
, "ma", 2) == 0)
1711 else if (strncasecmp (s
, "mb", 2) == 0)
1717 as_bad ("Invalid Short Load/Store Completer.");
1720 while (*s
== ' ' || *s
== '\t')
1726 /* Handle a stbys completer. */
1731 while (*s
== ',' && i
< 2)
1734 if (strncasecmp (s
, "m", 1) == 0)
1736 else if (strncasecmp (s
, "b", 1) == 0)
1738 else if (strncasecmp (s
, "e", 1) == 0)
1741 as_bad ("Invalid Store Bytes Short Completer");
1746 as_bad ("Invalid Store Bytes Short Completer");
1747 while (*s
== ' ' || *s
== '\t')
1753 /* Handle a non-negated compare/stubtract condition. */
1755 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1758 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1761 opcode
|= cmpltr
<< 13;
1764 /* Handle a negated or non-negated compare/subtract condition. */
1767 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1771 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1774 as_bad ("Invalid Compare/Subtract Condition.");
1779 /* Negated condition requires an opcode change. */
1783 opcode
|= cmpltr
<< 13;
1786 /* Handle a negated or non-negated add condition. */
1789 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1793 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1796 as_bad ("Invalid Compare/Subtract Condition");
1801 /* Negated condition requires an opcode change. */
1805 opcode
|= cmpltr
<< 13;
1808 /* Handle a compare/subtract condition. */
1815 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1820 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1823 as_bad ("Invalid Compare/Subtract Condition");
1827 opcode
|= cmpltr
<< 13;
1828 opcode
|= flag
<< 12;
1831 /* Handle a non-negated add condition. */
1840 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1844 if (strcmp (name
, "=") == 0)
1846 else if (strcmp (name
, "<") == 0)
1848 else if (strcmp (name
, "<=") == 0)
1850 else if (strcasecmp (name
, "nuv") == 0)
1852 else if (strcasecmp (name
, "znv") == 0)
1854 else if (strcasecmp (name
, "sv") == 0)
1856 else if (strcasecmp (name
, "od") == 0)
1858 else if (strcasecmp (name
, "n") == 0)
1860 else if (strcasecmp (name
, "tr") == 0)
1865 else if (strcasecmp (name
, "<>") == 0)
1870 else if (strcasecmp (name
, ">=") == 0)
1875 else if (strcasecmp (name
, ">") == 0)
1880 else if (strcasecmp (name
, "uv") == 0)
1885 else if (strcasecmp (name
, "vnz") == 0)
1890 else if (strcasecmp (name
, "nsv") == 0)
1895 else if (strcasecmp (name
, "ev") == 0)
1901 as_bad ("Invalid Add Condition: %s", name
);
1904 nullif
= pa_parse_nullif (&s
);
1905 opcode
|= nullif
<< 1;
1906 opcode
|= cmpltr
<< 13;
1907 opcode
|= flag
<< 12;
1910 /* Handle a logical instruction condition. */
1918 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1922 if (strcmp (name
, "=") == 0)
1924 else if (strcmp (name
, "<") == 0)
1926 else if (strcmp (name
, "<=") == 0)
1928 else if (strcasecmp (name
, "od") == 0)
1930 else if (strcasecmp (name
, "tr") == 0)
1935 else if (strcmp (name
, "<>") == 0)
1940 else if (strcmp (name
, ">=") == 0)
1945 else if (strcmp (name
, ">") == 0)
1950 else if (strcasecmp (name
, "ev") == 0)
1956 as_bad ("Invalid Logical Instruction Condition.");
1959 opcode
|= cmpltr
<< 13;
1960 opcode
|= flag
<< 12;
1963 /* Handle a unit instruction condition. */
1970 if (strncasecmp (s
, "sbz", 3) == 0)
1975 else if (strncasecmp (s
, "shz", 3) == 0)
1980 else if (strncasecmp (s
, "sdc", 3) == 0)
1985 else if (strncasecmp (s
, "sbc", 3) == 0)
1990 else if (strncasecmp (s
, "shc", 3) == 0)
1995 else if (strncasecmp (s
, "tr", 2) == 0)
2001 else if (strncasecmp (s
, "nbz", 3) == 0)
2007 else if (strncasecmp (s
, "nhz", 3) == 0)
2013 else if (strncasecmp (s
, "ndc", 3) == 0)
2019 else if (strncasecmp (s
, "nbc", 3) == 0)
2025 else if (strncasecmp (s
, "nhc", 3) == 0)
2032 as_bad ("Invalid Logical Instruction Condition.");
2034 opcode
|= cmpltr
<< 13;
2035 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 opcode
|= cmpltr
<< 13;
2079 /* Handle bvb and bb conditions. */
2085 if (strncmp (s
, "<", 1) == 0)
2090 else if (strncmp (s
, ">=", 2) == 0)
2096 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2098 opcode
|= cmpltr
<< 13;
2101 /* Handle a 5 bit immediate at 31. */
2104 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2105 the_insn
.field_selector
),
2111 /* Handle an unsigned 5 bit immediate at 31. */
2114 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2117 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2125 /* Handle an unsigned 5 bit immediate at 15. */
2128 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2131 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2135 opcode
|= im5
<< 16;
2139 /* Handle a 11 bit immediate at 31. */
2141 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2143 if (the_insn
.exp
.X_op
== O_constant
)
2145 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2146 the_insn
.field_selector
),
2152 if (is_DP_relative (the_insn
.exp
))
2153 the_insn
.reloc
= R_HPPA_GOTOFF
;
2154 else if (is_PC_relative (the_insn
.exp
))
2155 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2156 else if (is_complex (the_insn
.exp
))
2157 the_insn
.reloc
= R_HPPA_COMPLEX
;
2159 the_insn
.reloc
= R_HPPA
;
2160 the_insn
.format
= 11;
2165 /* Handle a 14 bit immediate at 31. */
2167 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2169 if (the_insn
.exp
.X_op
== O_constant
)
2171 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2172 the_insn
.field_selector
),
2174 if (the_insn
.field_selector
== e_rsel
)
2175 opcode
|= (im14
& 0xfff);
2181 if (is_DP_relative (the_insn
.exp
))
2182 the_insn
.reloc
= R_HPPA_GOTOFF
;
2183 else if (is_PC_relative (the_insn
.exp
))
2184 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2185 else if (is_complex (the_insn
.exp
))
2186 the_insn
.reloc
= R_HPPA_COMPLEX
;
2188 the_insn
.reloc
= R_HPPA
;
2189 the_insn
.format
= 14;
2194 /* Handle a 21 bit immediate at 31. */
2196 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2198 if (the_insn
.exp
.X_op
== O_constant
)
2200 dis_assemble_21 (evaluate_absolute (the_insn
.exp
,
2201 the_insn
.field_selector
),
2207 if (is_DP_relative (the_insn
.exp
))
2208 the_insn
.reloc
= R_HPPA_GOTOFF
;
2209 else if (is_PC_relative (the_insn
.exp
))
2210 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2211 else if (is_complex (the_insn
.exp
))
2212 the_insn
.reloc
= R_HPPA_COMPLEX
;
2214 the_insn
.reloc
= R_HPPA
;
2215 the_insn
.format
= 21;
2220 /* Handle a nullification completer for branch instructions. */
2222 nullif
= pa_parse_nullif (&s
);
2223 opcode
|= nullif
<< 1;
2226 /* Handle a 12 bit branch displacement. */
2228 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2231 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L0\001"))
2233 unsigned int w1
, w
, result
;
2235 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 12,
2237 dis_assemble_12 (result
, &w1
, &w
);
2238 opcode
|= ((w1
<< 2) | w
);
2242 if (is_complex (the_insn
.exp
))
2243 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2245 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2246 the_insn
.format
= 12;
2247 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2248 bzero (&last_call_desc
, sizeof (struct call_desc
));
2253 /* Handle a 17 bit branch displacement. */
2255 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2258 if (the_insn
.exp
.X_add_symbol
)
2260 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2263 unsigned int w2
, w1
, w
, result
;
2265 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2267 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2268 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2272 if (is_complex (the_insn
.exp
))
2273 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2275 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2276 the_insn
.format
= 17;
2277 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2278 bzero (&last_call_desc
, sizeof (struct call_desc
));
2283 unsigned int w2
, w1
, w
, result
;
2285 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2286 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2287 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2292 /* Handle an absolute 17 bit branch target. */
2294 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2297 if (the_insn
.exp
.X_add_symbol
)
2299 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2302 unsigned int w2
, w1
, w
, result
;
2304 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2306 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2307 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2311 if (is_complex (the_insn
.exp
))
2312 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2314 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2315 the_insn
.format
= 17;
2320 unsigned int w2
, w1
, w
, result
;
2322 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2323 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2324 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2329 /* Handle a 5 bit shift count at 26. */
2332 if (the_insn
.exp
.X_op
== O_constant
)
2333 opcode
|= (((31 - the_insn
.exp
.X_add_number
) & 0x1f) << 5);
2337 /* Handle a 5 bit bit position at 26. */
2340 if (the_insn
.exp
.X_op
== O_constant
)
2341 opcode
|= (the_insn
.exp
.X_add_number
& 0x1f) << 5;
2345 /* Handle a 5 bit immediate at 10. */
2348 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2351 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2355 opcode
|= im5
<< 21;
2359 /* Handle a 13 bit immediate at 18. */
2361 pa_get_absolute_expression (s
);
2362 if (the_insn
.exp
.X_op
== O_constant
)
2363 opcode
|= (the_insn
.exp
.X_add_number
& 0x1fff) << 13;
2367 /* Handle a system control completer. */
2369 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2378 while (*s
== ' ' || *s
== '\t')
2382 /* Handle a 26 bit immediate at 31. */
2384 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2386 if (the_insn
.exp
.X_op
== O_constant
)
2388 opcode
|= ((evaluate_absolute (the_insn
.exp
,
2389 the_insn
.field_selector
)
2393 as_bad ("Invalid DIAG operand");
2397 /* Handle a 3 bit SFU identifier at 25. */
2399 sfu
= pa_parse_number (&s
, 0);
2400 if ((sfu
> 7) || (sfu
< 0))
2401 as_bad ("Invalid SFU identifier: %02x", sfu
);
2402 opcode
|= (sfu
& 7) << 6;
2405 /* We don't support any of these. FIXME. */
2412 /* Handle a source FP operand format completer. */
2414 flag
= pa_parse_fp_format (&s
);
2415 opcode
|= (int) flag
<< 11;
2416 the_insn
.fpof1
= flag
;
2419 /* Handle a destination FP operand format completer. */
2422 /* pa_parse_format needs the ',' prefix. */
2424 flag
= pa_parse_fp_format (&s
);
2425 opcode
|= (int) flag
<< 13;
2426 the_insn
.fpof2
= flag
;
2429 /* Handle FP compare conditions. */
2431 cond
= pa_parse_fp_cmp_cond (&s
);
2435 /* Handle L/R register halves like 't'. */
2438 struct pa_89_fp_reg_struct result
;
2440 pa_parse_number (&s
, &result
);
2441 if (result
.number_part
< 32 && result
.number_part
>= 0)
2443 opcode
|= (result
.number_part
& 0x1f);
2445 /* 0x30 opcodes are FP arithmetic operation opcodes
2446 and need to be turned into 0x38 opcodes. This
2447 is not necessary for loads/stores. */
2448 if (need_89_opcode (&the_insn
, &result
))
2450 if ((opcode
& 0xfc000000) == 0x30000000)
2452 opcode
|= (result
.l_r_select
& 1) << 6;
2457 opcode
|= (result
.l_r_select
& 1) << 6;
2465 /* Handle L/R register halves like 'b'. */
2468 struct pa_89_fp_reg_struct result
;
2470 pa_parse_number (&s
, &result
);
2471 if (result
.number_part
< 32 && result
.number_part
>= 0)
2473 opcode
|= (result
.number_part
& 0x1f) << 21;
2474 if (need_89_opcode (&the_insn
, &result
))
2476 opcode
|= (result
.l_r_select
& 1) << 7;
2484 /* Handle L/R register halves like 'x'. */
2487 struct pa_89_fp_reg_struct result
;
2489 pa_parse_number (&s
, &result
);
2490 if (result
.number_part
< 32 && result
.number_part
>= 0)
2492 opcode
|= (result
.number_part
& 0x1f) << 16;
2493 if (need_89_opcode (&the_insn
, &result
))
2495 opcode
|= (result
.l_r_select
& 1) << 12;
2503 /* Handle a 5 bit register field at 10. */
2506 struct pa_89_fp_reg_struct result
;
2509 status
= pa_parse_number (&s
, &result
);
2510 if (result
.number_part
< 32 && result
.number_part
>= 0)
2512 if (the_insn
.fpof1
== SGL
)
2514 result
.number_part
&= 0xF;
2515 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2517 opcode
|= result
.number_part
<< 21;
2523 /* Handle a 5 bit register field at 15. */
2526 struct pa_89_fp_reg_struct result
;
2529 status
= pa_parse_number (&s
, &result
);
2530 if (result
.number_part
< 32 && result
.number_part
>= 0)
2532 if (the_insn
.fpof1
== SGL
)
2534 result
.number_part
&= 0xF;
2535 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2537 opcode
|= result
.number_part
<< 16;
2543 /* Handle a 5 bit register field at 31. */
2546 struct pa_89_fp_reg_struct result
;
2549 status
= pa_parse_number (&s
, &result
);
2550 if (result
.number_part
< 32 && result
.number_part
>= 0)
2552 if (the_insn
.fpof1
== SGL
)
2554 result
.number_part
&= 0xF;
2555 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2557 opcode
|= result
.number_part
;
2563 /* Handle a 5 bit register field at 20. */
2566 struct pa_89_fp_reg_struct result
;
2569 status
= pa_parse_number (&s
, &result
);
2570 if (result
.number_part
< 32 && result
.number_part
>= 0)
2572 if (the_insn
.fpof1
== SGL
)
2574 result
.number_part
&= 0xF;
2575 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2577 opcode
|= result
.number_part
<< 11;
2583 /* Handle a 5 bit register field at 25. */
2586 struct pa_89_fp_reg_struct result
;
2589 status
= pa_parse_number (&s
, &result
);
2590 if (result
.number_part
< 32 && result
.number_part
>= 0)
2592 if (the_insn
.fpof1
== SGL
)
2594 result
.number_part
&= 0xF;
2595 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2597 opcode
|= result
.number_part
<< 6;
2603 /* Handle a floating point operand format at 26.
2604 Only allows single and double precision. */
2606 flag
= pa_parse_fp_format (&s
);
2612 the_insn
.fpof1
= flag
;
2618 as_bad ("Invalid Floating Point Operand Format.");
2628 /* Check if the args matched. */
2631 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2632 && !strcmp (insn
->name
, insn
[1].name
))
2640 as_bad ("Invalid operands %s", error_message
);
2647 the_insn
.opcode
= opcode
;
2651 /* Turn a string in input_line_pointer into a floating point constant of type
2652 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2653 emitted is stored in *sizeP . An error message or NULL is returned. */
2655 #define MAX_LITTLENUMS 6
2658 md_atof (type
, litP
, sizeP
)
2664 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2665 LITTLENUM_TYPE
*wordP
;
2697 return "Bad call to MD_ATOF()";
2699 t
= atof_ieee (input_line_pointer
, type
, words
);
2701 input_line_pointer
= t
;
2702 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2703 for (wordP
= words
; prec
--;)
2705 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2706 litP
+= sizeof (LITTLENUM_TYPE
);
2711 /* Write out big-endian. */
2714 md_number_to_chars (buf
, val
, n
)
2736 /* Translate internal representation of relocation info to BFD target
2740 tc_gen_reloc (section
, fixp
)
2745 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2746 bfd_reloc_code_real_type code
;
2747 static int unwind_reloc_fixp_cnt
= 0;
2748 static arelent
*unwind_reloc_entryP
= NULL
;
2749 static arelent
*no_relocs
= NULL
;
2751 bfd_reloc_code_real_type
**codes
;
2755 if (fixp
->fx_addsy
== 0)
2757 assert (hppa_fixp
!= 0);
2758 assert (section
!= 0);
2761 /* Yuk. I would really like to push all this ELF specific unwind
2762 crud into BFD and the linker. That's how SOM does it -- and
2763 if we could make ELF emulate that then we could share more code
2764 in GAS (and potentially a gnu-linker later).
2766 Unwind section relocations are handled in a special way.
2767 The relocations for the .unwind section are originally
2768 built in the usual way. That is, for each unwind table
2769 entry there are two relocations: one for the beginning of
2770 the function and one for the end.
2772 The first time we enter this function we create a
2773 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2774 of the relocation is initialized to 0. Each additional
2775 pair of times this function is called for the unwind
2776 section represents an additional unwind table entry. Thus,
2777 the addend of the relocation should end up to be the number
2778 of unwind table entries. */
2779 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2781 if (unwind_reloc_entryP
== NULL
)
2783 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2785 assert (reloc
!= 0);
2786 unwind_reloc_entryP
= reloc
;
2787 unwind_reloc_fixp_cnt
++;
2788 unwind_reloc_entryP
->address
2789 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2790 /* A pointer to any function will do. We only
2791 need one to tell us what section the unwind
2792 relocations are for. */
2793 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2794 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2795 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2796 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2797 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2798 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2799 sizeof (arelent
*) * 2);
2800 assert (relocs
!= 0);
2801 relocs
[0] = unwind_reloc_entryP
;
2805 unwind_reloc_fixp_cnt
++;
2806 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2812 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2813 assert (reloc
!= 0);
2815 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2816 codes
= hppa_gen_reloc_type (stdoutput
,
2818 hppa_fixp
->fx_r_format
,
2819 hppa_fixp
->fx_r_field
);
2821 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2824 relocs
= (arelent
**)
2825 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2826 assert (relocs
!= 0);
2828 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2829 sizeof (arelent
) * n_relocs
);
2831 assert (reloc
!= 0);
2833 for (i
= 0; i
< n_relocs
; i
++)
2834 relocs
[i
] = &reloc
[i
];
2836 relocs
[n_relocs
] = NULL
;
2839 switch (fixp
->fx_r_type
)
2841 case R_HPPA_COMPLEX
:
2842 case R_HPPA_COMPLEX_PCREL_CALL
:
2843 case R_HPPA_COMPLEX_ABS_CALL
:
2844 assert (n_relocs
== 5);
2846 for (i
= 0; i
< n_relocs
; i
++)
2848 reloc
[i
].sym_ptr_ptr
= NULL
;
2849 reloc
[i
].address
= 0;
2850 reloc
[i
].addend
= 0;
2851 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2852 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2855 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2856 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2857 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2859 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2860 reloc
[3].addend
= fixp
->fx_addnumber
;
2861 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2862 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2863 reloc
[1].addend
= fixp
->fx_addnumber
;
2868 assert (n_relocs
== 1);
2872 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2873 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2874 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2875 reloc
->addend
= 0; /* default */
2877 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2879 /* Now, do any processing that is dependent on the relocation type. */
2882 case R_HPPA_PLABEL_32
:
2883 case R_HPPA_PLABEL_11
:
2884 case R_HPPA_PLABEL_14
:
2885 case R_HPPA_PLABEL_L21
:
2886 case R_HPPA_PLABEL_R11
:
2887 case R_HPPA_PLABEL_R14
:
2888 /* For plabel relocations, the addend of the
2889 relocation should be either 0 (no static link) or 2
2890 (static link required).
2892 FIXME: assume that fx_addnumber contains this
2894 reloc
->addend
= fixp
->fx_addnumber
;
2897 case R_HPPA_ABS_CALL_11
:
2898 case R_HPPA_ABS_CALL_14
:
2899 case R_HPPA_ABS_CALL_17
:
2900 case R_HPPA_ABS_CALL_L21
:
2901 case R_HPPA_ABS_CALL_R11
:
2902 case R_HPPA_ABS_CALL_R14
:
2903 case R_HPPA_ABS_CALL_R17
:
2904 case R_HPPA_ABS_CALL_LS21
:
2905 case R_HPPA_ABS_CALL_RS11
:
2906 case R_HPPA_ABS_CALL_RS14
:
2907 case R_HPPA_ABS_CALL_RS17
:
2908 case R_HPPA_ABS_CALL_LD21
:
2909 case R_HPPA_ABS_CALL_RD11
:
2910 case R_HPPA_ABS_CALL_RD14
:
2911 case R_HPPA_ABS_CALL_RD17
:
2912 case R_HPPA_ABS_CALL_LR21
:
2913 case R_HPPA_ABS_CALL_RR14
:
2914 case R_HPPA_ABS_CALL_RR17
:
2916 case R_HPPA_PCREL_CALL_11
:
2917 case R_HPPA_PCREL_CALL_14
:
2918 case R_HPPA_PCREL_CALL_17
:
2919 case R_HPPA_PCREL_CALL_L21
:
2920 case R_HPPA_PCREL_CALL_R11
:
2921 case R_HPPA_PCREL_CALL_R14
:
2922 case R_HPPA_PCREL_CALL_R17
:
2923 case R_HPPA_PCREL_CALL_LS21
:
2924 case R_HPPA_PCREL_CALL_RS11
:
2925 case R_HPPA_PCREL_CALL_RS14
:
2926 case R_HPPA_PCREL_CALL_RS17
:
2927 case R_HPPA_PCREL_CALL_LD21
:
2928 case R_HPPA_PCREL_CALL_RD11
:
2929 case R_HPPA_PCREL_CALL_RD14
:
2930 case R_HPPA_PCREL_CALL_RD17
:
2931 case R_HPPA_PCREL_CALL_LR21
:
2932 case R_HPPA_PCREL_CALL_RR14
:
2933 case R_HPPA_PCREL_CALL_RR17
:
2934 /* The constant is stored in the instruction. */
2935 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2938 reloc
->addend
= fixp
->fx_addnumber
;
2945 /* Preliminary relocation handling for SOM. Needs to handle
2946 COMPLEX relocations (yes, I've seen them occur) and it will
2947 need to handle R_ENTRY/R_EXIT relocations in the very near future
2948 (for generating unwinds). */
2949 switch (fixp
->fx_r_type
)
2951 case R_HPPA_COMPLEX
:
2952 case R_HPPA_COMPLEX_PCREL_CALL
:
2953 case R_HPPA_COMPLEX_ABS_CALL
:
2957 assert (n_relocs
== 1);
2961 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2962 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2963 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2970 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2973 reloc
->addend
= fixp
->fx_addnumber
;
2983 /* Process any machine dependent frag types. */
2986 md_convert_frag (abfd
, sec
, fragP
)
2988 register asection
*sec
;
2989 register fragS
*fragP
;
2991 unsigned int address
;
2993 if (fragP
->fr_type
== rs_machine_dependent
)
2995 switch ((int) fragP
->fr_subtype
)
2998 fragP
->fr_type
= rs_fill
;
2999 know (fragP
->fr_var
== 1);
3000 know (fragP
->fr_next
);
3001 address
= fragP
->fr_address
+ fragP
->fr_fix
;
3002 if (address
% fragP
->fr_offset
)
3005 fragP
->fr_next
->fr_address
3010 fragP
->fr_offset
= 0;
3016 /* Round up a section size to the appropriate boundary. */
3019 md_section_align (segment
, size
)
3023 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3024 int align2
= (1 << align
) - 1;
3026 return (size
+ align2
) & ~align2
;
3030 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3032 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3034 addressT from_addr
, to_addr
;
3038 fprintf (stderr
, "pa_create_short_jmp\n");
3042 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3044 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3046 addressT from_addr
, to_addr
;
3050 fprintf (stderr
, "pa_create_long_jump\n");
3054 /* Return the approximate size of a frag before relaxation has occurred. */
3056 md_estimate_size_before_relax (fragP
, segment
)
3057 register fragS
*fragP
;
3064 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3070 /* Parse machine dependent options. There are none on the PA. */
3072 md_parse_option (argP
, cntP
, vecP
)
3080 /* We have no need to default values of symbols. */
3083 md_undefined_symbol (name
)
3089 /* Parse an operand that is machine-specific.
3090 We just return without modifying the expression as we have nothing
3094 md_operand (expressionP
)
3095 expressionS
*expressionP
;
3099 /* Helper function for md_apply_fix. Actually determine if the fix
3100 can be applied, and if so, apply it.
3102 If a fix is applied, then set fx_addsy to NULL which indicates
3103 the fix was applied and need not be emitted into the object file. */
3106 md_apply_fix_1 (fixP
, val
)
3110 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3111 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
3112 long new_val
, result
;
3113 unsigned int w1
, w2
, w
;
3115 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3116 never be "applied". They must always be emitted. */
3118 if (fixP
->fx_r_type
== R_HPPA_ENTRY
3119 || fixP
->fx_r_type
== R_HPPA_EXIT
)
3123 /* There should have been an HPPA specific fixup associated
3124 with the GAS fixup. */
3127 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3128 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3130 /* Sanity check the fixup type. */
3131 /* Is this really necessary? */
3132 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3135 /* Remember this value for emit_reloc. FIXME, is this braindamage
3136 documented anywhere!?! */
3137 fixP
->fx_addnumber
= val
;
3139 /* Check if this is an undefined symbol. No relocation can
3140 possibly be performed in this case. */
3141 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3143 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3148 /* Handle all opcodes with the 'j' operand type. */
3150 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3152 /* Mask off 14 bits to be changed. */
3153 bfd_put_32 (stdoutput
,
3154 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3156 low_sign_unext (new_val
, 14, &result
);
3159 /* Handle all opcodes with the 'k' operand type. */
3161 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3163 /* Mask off 21 bits to be changed. */
3164 bfd_put_32 (stdoutput
,
3165 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3167 dis_assemble_21 (new_val
, &result
);
3170 /* Handle all the opcodes with the 'i' operand type. */
3172 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3174 /* Mask off 11 bits to be changed. */
3175 bfd_put_32 (stdoutput
,
3176 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3178 low_sign_unext (new_val
, 11, &result
);
3181 /* Handle all the opcodes with the 'w' operand type. */
3183 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3185 /* Mask off 11 bits to be changed. */
3186 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3187 bfd_put_32 (stdoutput
,
3188 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3191 dis_assemble_12 (result
, &w1
, &w
);
3192 result
= ((w1
<< 2) | w
);
3193 fixP
->fx_addsy
= NULL
;
3196 #define too_far(VAL, NUM_BITS) \
3197 (((int)(VAL) > (1 << (NUM_BITS)) - 1) || ((int)(VAL) < (-1 << (NUM_BITS))))
3199 #define stub_needed(CALLER, CALLEE) \
3200 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3202 /* Handle some of the opcodes with the 'W' operand type. */
3204 /* If a long-call stub or argument relocation stub is
3205 needed, then we can not apply this relocation, instead
3206 the linker must handle it. */
3207 if (too_far (val
, 18)
3208 || stub_needed (((obj_symbol_type
*)
3209 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3210 hppa_fixP
->fx_arg_reloc
))
3213 /* No stubs were needed, we can perform this relocation. */
3214 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3216 /* Mask off 17 bits to be changed. */
3217 bfd_put_32 (stdoutput
,
3218 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3220 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3221 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3222 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3223 fixP
->fx_addsy
= NULL
;
3231 /* These are ELF specific relocations. ELF unfortunately
3232 handles unwinds in a completely different manner. */
3233 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3234 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3235 result
= fixP
->fx_addnumber
;
3240 fixP
->fx_addnumber
= fixP
->fx_offset
;
3241 bfd_put_32 (stdoutput
, 0, buf
);
3250 as_bad ("bad relocation type/fmt: 0x%02x/0x%02x",
3251 fixP
->fx_r_type
, fmt
);
3255 /* Insert the relocation. */
3256 buf
[0] |= (result
& 0xff000000) >> 24;
3257 buf
[1] |= (result
& 0x00ff0000) >> 16;
3258 buf
[2] |= (result
& 0x0000ff00) >> 8;
3259 buf
[3] |= result
& 0x000000ff;
3262 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3263 (unsigned int) fixP
, fixP
->fx_r_type
);
3266 /* Apply a fix into a frag's data (if possible). */
3269 md_apply_fix (fixP
, valp
)
3273 md_apply_fix_1 (fixP
, (long) *valp
);
3277 /* Exactly what point is a PC-relative offset relative TO?
3278 On the PA, they're relative to the address of the offset. */
3281 md_pcrel_from (fixP
)
3284 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3287 /* Return nonzero if the input line pointer is at the end of
3291 is_end_of_statement ()
3293 return ((*input_line_pointer
== '\n')
3294 || (*input_line_pointer
== ';')
3295 || (*input_line_pointer
== '!'));
3298 /* Read a number from S. The number might come in one of many forms,
3299 the most common will be a hex or decimal constant, but it could be
3300 a pre-defined register (Yuk!), or an absolute symbol.
3302 Return a number or -1 for failure.
3304 When parsing PA-89 FP register numbers RESULT will be
3305 the address of a structure to return information about
3306 L/R half of FP registers, store results there as appropriate.
3308 pa_parse_number can not handle negative constants and will fail
3309 horribly if it is passed such a constant. */
3312 pa_parse_number (s
, result
)
3314 struct pa_89_fp_reg_struct
*result
;
3323 /* Skip whitespace before the number. */
3324 while (*p
== ' ' || *p
== '\t')
3327 /* Store info in RESULT if requested by caller. */
3330 result
->number_part
= -1;
3331 result
->l_r_select
= -1;
3337 /* Looks like a number. */
3340 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3342 /* The number is specified in hex. */
3344 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3345 || ((*p
>= 'A') && (*p
<= 'F')))
3348 num
= num
* 16 + *p
- '0';
3349 else if (*p
>= 'a' && *p
<= 'f')
3350 num
= num
* 16 + *p
- 'a' + 10;
3352 num
= num
* 16 + *p
- 'A' + 10;
3358 /* The number is specified in decimal. */
3359 while (isdigit (*p
))
3361 num
= num
* 10 + *p
- '0';
3366 /* Store info in RESULT if requested by the caller. */
3369 result
->number_part
= num
;
3371 if (IS_R_SELECT (p
))
3373 result
->l_r_select
= 1;
3376 else if (IS_L_SELECT (p
))
3378 result
->l_r_select
= 0;
3382 result
->l_r_select
= 0;
3387 /* The number might be a predefined register. */
3392 /* Tege hack: Special case for general registers as the general
3393 code makes a binary search with case translation, and is VERY
3398 if (*p
== 'e' && *(p
+ 1) == 't'
3399 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3402 num
= *p
- '0' + 28;
3410 else if (!isdigit (*p
))
3413 as_bad ("Undefined register: '%s'.", name
);
3419 num
= num
* 10 + *p
++ - '0';
3420 while (isdigit (*p
));
3425 /* Do a normal register search. */
3426 while (is_part_of_name (c
))
3432 status
= reg_name_search (name
);
3438 as_bad ("Undefined register: '%s'.", name
);
3444 /* Store info in RESULT if requested by caller. */
3447 result
->number_part
= num
;
3448 if (IS_R_SELECT (p
- 1))
3449 result
->l_r_select
= 1;
3450 else if (IS_L_SELECT (p
- 1))
3451 result
->l_r_select
= 0;
3453 result
->l_r_select
= 0;
3458 /* And finally, it could be a symbol in the absolute section which
3459 is effectively a constant. */
3463 while (is_part_of_name (c
))
3469 if ((sym
= symbol_find (name
)) != NULL
)
3471 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3472 num
= S_GET_VALUE (sym
);
3476 as_bad ("Non-absolute symbol: '%s'.", name
);
3482 /* There is where we'd come for an undefined symbol
3483 or for an empty string. For an empty string we
3484 will return zero. That's a concession made for
3485 compatability with the braindamaged HP assemblers. */
3491 as_bad ("Undefined absolute constant: '%s'.", name
);
3497 /* Store info in RESULT if requested by caller. */
3500 result
->number_part
= num
;
3501 if (IS_R_SELECT (p
- 1))
3502 result
->l_r_select
= 1;
3503 else if (IS_L_SELECT (p
- 1))
3504 result
->l_r_select
= 0;
3506 result
->l_r_select
= 0;
3514 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3516 /* Given NAME, find the register number associated with that name, return
3517 the integer value associated with the given name or -1 on failure. */
3520 reg_name_search (name
)
3523 int middle
, low
, high
;
3526 high
= REG_NAME_CNT
- 1;
3530 middle
= (low
+ high
) / 2;
3531 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3536 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3539 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3540 return (pre_defined_registers
[middle
].value
);
3546 /* Return nonzero if the given INSN and L/R information will require
3547 a new PA-89 opcode. */
3550 need_89_opcode (insn
, result
)
3552 struct pa_89_fp_reg_struct
*result
;
3554 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3560 /* Parse a condition for a fcmp instruction. Return the numerical
3561 code associated with the condition. */
3564 pa_parse_fp_cmp_cond (s
)
3571 for (i
= 0; i
< 32; i
++)
3573 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3574 strlen (fp_cond_map
[i
].string
)) == 0)
3576 cond
= fp_cond_map
[i
].cond
;
3577 *s
+= strlen (fp_cond_map
[i
].string
);
3578 while (**s
== ' ' || **s
== '\t')
3584 as_bad ("Invalid FP Compare Condition: %c", **s
);
3588 /* Parse an FP operand format completer returning the completer
3591 static fp_operand_format
3592 pa_parse_fp_format (s
)
3601 if (strncasecmp (*s
, "sgl", 3) == 0)
3606 else if (strncasecmp (*s
, "dbl", 3) == 0)
3611 else if (strncasecmp (*s
, "quad", 4) == 0)
3618 format
= ILLEGAL_FMT
;
3619 as_bad ("Invalid FP Operand Format: %3s", *s
);
3622 while (**s
== ' ' || **s
== '\t' || **s
== 0)
3628 /* Convert from a selector string into a selector type. */
3631 pa_chk_field_selector (str
)
3635 struct selector_entry
*tablep
;
3639 /* Read past any whitespace. */
3640 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3643 /* Yuk. Looks like a linear search through the table. With the
3644 frequence of some selectors it might make sense to sort the
3646 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3648 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3650 *str
+= strlen (tablep
->prefix
);
3651 selector
= tablep
->field_selector
;
3658 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3661 get_expression (str
)
3667 save_in
= input_line_pointer
;
3668 input_line_pointer
= str
;
3669 seg
= expression (&the_insn
.exp
);
3670 if (!(seg
== absolute_section
3671 || seg
== undefined_section
3672 || SEG_NORMAL (seg
)))
3674 as_warn ("Bad segment in expression.");
3675 expr_end
= input_line_pointer
;
3676 input_line_pointer
= save_in
;
3679 expr_end
= input_line_pointer
;
3680 input_line_pointer
= save_in
;
3684 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3686 pa_get_absolute_expression (str
)
3691 save_in
= input_line_pointer
;
3692 input_line_pointer
= str
;
3693 expression (&the_insn
.exp
);
3694 if (the_insn
.exp
.X_op
!= O_constant
)
3696 as_warn ("Bad segment (should be absolute).");
3697 expr_end
= input_line_pointer
;
3698 input_line_pointer
= save_in
;
3701 expr_end
= input_line_pointer
;
3702 input_line_pointer
= save_in
;
3706 /* Evaluate an absolute expression EXP which may be modified by
3707 the selector FIELD_SELECTOR. Return the value of the expression. */
3709 evaluate_absolute (exp
, field_selector
)
3715 value
= exp
.X_add_number
;
3717 switch (field_selector
)
3723 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3725 if (value
& 0x00000400)
3727 value
= (value
& 0xfffff800) >> 11;
3730 /* Sign extend from bit 21. */
3732 if (value
& 0x00000400)
3733 value
|= 0xfffff800;
3738 /* Arithmetic shift right 11 bits. */
3740 value
= (value
& 0xfffff800) >> 11;
3743 /* Set bits 0-20 to zero. */
3745 value
= value
& 0x7ff;
3748 /* Add 0x800 and arithmetic shift right 11 bits. */
3753 value
= (value
& 0xfffff800) >> 11;
3756 /* Set bitgs 0-21 to one. */
3758 value
|= 0xfffff800;
3761 /* This had better get fixed. It looks like we're quickly moving
3768 BAD_CASE (field_selector
);
3774 /* Given an argument location specification return the associated
3775 argument location number. */
3778 pa_build_arg_reloc (type_name
)
3782 if (strncasecmp (type_name
, "no", 2) == 0)
3784 if (strncasecmp (type_name
, "gr", 2) == 0)
3786 else if (strncasecmp (type_name
, "fr", 2) == 0)
3788 else if (strncasecmp (type_name
, "fu", 2) == 0)
3791 as_bad ("Invalid argument location: %s\n", type_name
);
3796 /* Encode and return an argument relocation specification for
3797 the given register in the location specified by arg_reloc. */
3800 pa_align_arg_reloc (reg
, arg_reloc
)
3802 unsigned int arg_reloc
;
3804 unsigned int new_reloc
;
3806 new_reloc
= arg_reloc
;
3822 as_bad ("Invalid argument description: %d", reg
);
3828 /* Parse a PA nullification completer (,n). Return nonzero if the
3829 completer was found; return zero if no completer was found. */
3841 if (strncasecmp (*s
, "n", 1) == 0)
3845 as_bad ("Invalid Nullification: (%c)", **s
);
3850 while (**s
== ' ' || **s
== '\t')
3856 /* Parse a non-negated compare/subtract completer returning the
3857 number (for encoding in instrutions) of the given completer.
3859 ISBRANCH specifies whether or not this is parsing a condition
3860 completer for a branch (vs a nullification completer for a
3861 computational instruction. */
3864 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3869 char *name
= *s
+ 1;
3877 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3881 if (strcmp (name
, "=") == 0)
3885 else if (strcmp (name
, "<") == 0)
3889 else if (strcmp (name
, "<=") == 0)
3893 else if (strcmp (name
, "<<") == 0)
3897 else if (strcmp (name
, "<<=") == 0)
3901 else if (strcasecmp (name
, "sv") == 0)
3905 else if (strcasecmp (name
, "od") == 0)
3909 /* If we have something like addb,n then there is no condition
3911 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3923 while (**s
== ' ' || **s
== '\t')
3927 /* Reset pointers if this was really a ,n for a branch instruction. */
3928 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3934 /* Parse a negated compare/subtract completer returning the
3935 number (for encoding in instrutions) of the given completer.
3937 ISBRANCH specifies whether or not this is parsing a condition
3938 completer for a branch (vs a nullification completer for a
3939 computational instruction. */
3942 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3947 char *name
= *s
+ 1;
3955 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3959 if (strcasecmp (name
, "tr") == 0)
3963 else if (strcmp (name
, "<>") == 0)
3967 else if (strcmp (name
, ">=") == 0)
3971 else if (strcmp (name
, ">") == 0)
3975 else if (strcmp (name
, ">>=") == 0)
3979 else if (strcmp (name
, ">>") == 0)
3983 else if (strcasecmp (name
, "nsv") == 0)
3987 else if (strcasecmp (name
, "ev") == 0)
3991 /* If we have something like addb,n then there is no condition
3993 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4005 while (**s
== ' ' || **s
== '\t')
4009 /* Reset pointers if this was really a ,n for a branch instruction. */
4010 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4016 /* Parse a non-negated addition completer returning the number
4017 (for encoding in instrutions) of the given completer.
4019 ISBRANCH specifies whether or not this is parsing a condition
4020 completer for a branch (vs a nullification completer for a
4021 computational instruction. */
4024 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
4029 char *name
= *s
+ 1;
4037 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4041 if (strcmp (name
, "=") == 0)
4045 else if (strcmp (name
, "<") == 0)
4049 else if (strcmp (name
, "<=") == 0)
4053 else if (strcasecmp (name
, "nuv") == 0)
4057 else if (strcasecmp (name
, "znv") == 0)
4061 else if (strcasecmp (name
, "sv") == 0)
4065 else if (strcasecmp (name
, "od") == 0)
4069 /* If we have something like addb,n then there is no condition
4071 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4083 while (**s
== ' ' || **s
== '\t')
4087 /* Reset pointers if this was really a ,n for a branch instruction. */
4088 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4094 /* Parse a negated addition completer returning the number
4095 (for encoding in instrutions) of the given completer.
4097 ISBRANCH specifies whether or not this is parsing a condition
4098 completer for a branch (vs a nullification completer for a
4099 computational instruction. */
4102 pa_parse_neg_add_cmpltr (s
, isbranch
)
4107 char *name
= *s
+ 1;
4115 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4119 if (strcasecmp (name
, "tr") == 0)
4123 else if (strcmp (name
, "<>") == 0)
4127 else if (strcmp (name
, ">=") == 0)
4131 else if (strcmp (name
, ">") == 0)
4135 else if (strcmp (name
, "uv") == 0)
4139 else if (strcmp (name
, "vnz") == 0)
4143 else if (strcasecmp (name
, "nsv") == 0)
4147 else if (strcasecmp (name
, "ev") == 0)
4151 /* If we have something like addb,n then there is no condition
4153 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4165 while (**s
== ' ' || **s
== '\t')
4169 /* Reset pointers if this was really a ,n for a branch instruction. */
4170 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4176 /* Handle a .BLOCK type pseudo-op. */
4184 unsigned int temp_size
;
4187 temp_size
= get_absolute_expression ();
4189 /* Always fill with zeros, that's what the HP assembler does. */
4192 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4193 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4194 bzero (p
, temp_size
);
4196 /* Convert 2 bytes at a time. */
4198 for (i
= 0; i
< temp_size
; i
+= 2)
4200 md_number_to_chars (p
+ i
,
4202 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4205 pa_undefine_label ();
4206 demand_empty_rest_of_line ();
4210 /* Handle a .CALL pseudo-op. This involves storing away information
4211 about where arguments are to be found so the linker can detect
4212 (and correct) argument location mismatches between caller and callee. */
4218 pa_call_args (&last_call_desc
);
4219 demand_empty_rest_of_line ();
4223 /* Do the dirty work of building a call descriptor which describes
4224 where the caller placed arguments to a function call. */
4227 pa_call_args (call_desc
)
4228 struct call_desc
*call_desc
;
4231 unsigned int temp
, arg_reloc
;
4233 while (!is_end_of_statement ())
4235 name
= input_line_pointer
;
4236 c
= get_symbol_end ();
4237 /* Process a source argument. */
4238 if ((strncasecmp (name
, "argw", 4) == 0))
4240 temp
= atoi (name
+ 4);
4241 p
= input_line_pointer
;
4243 input_line_pointer
++;
4244 name
= input_line_pointer
;
4245 c
= get_symbol_end ();
4246 arg_reloc
= pa_build_arg_reloc (name
);
4247 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4249 /* Process a return value. */
4250 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4252 p
= input_line_pointer
;
4254 input_line_pointer
++;
4255 name
= input_line_pointer
;
4256 c
= get_symbol_end ();
4257 arg_reloc
= pa_build_arg_reloc (name
);
4258 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4262 as_bad ("Invalid .CALL argument: %s", name
);
4264 p
= input_line_pointer
;
4266 if (!is_end_of_statement ())
4267 input_line_pointer
++;
4271 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4274 is_same_frag (frag1
, frag2
)
4281 else if (frag2
== NULL
)
4283 else if (frag1
== frag2
)
4285 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4286 return (is_same_frag (frag1
, frag2
->fr_next
));
4292 /* Build an entry in the UNWIND subspace from the given function
4293 attributes in CALL_INFO. This is not needed for SOM as using
4294 R_ENTRY and R_EXIT relocations allow the linker to handle building
4295 of the unwind spaces. */
4298 pa_build_unwind_subspace (call_info
)
4299 struct call_info
*call_info
;
4302 asection
*seg
, *save_seg
;
4303 subsegT subseg
, save_subseg
;
4307 /* Get into the right seg/subseg. This may involve creating
4308 the seg the first time through. Make sure to have the
4309 old seg/subseg so that we can reset things when we are done. */
4310 subseg
= SUBSEG_UNWIND
;
4311 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4312 if (seg
== ASEC_NULL
)
4314 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4315 bfd_set_section_flags (stdoutput
, seg
,
4316 SEC_READONLY
| SEC_HAS_CONTENTS
4317 | SEC_LOAD
| SEC_RELOC
);
4321 save_subseg
= now_subseg
;
4322 subseg_set (seg
, subseg
);
4325 /* Get some space to hold relocation information for the unwind
4328 call_info
->start_offset_frag
= frag_now
;
4329 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4331 /* Relocation info. for start offset of the function. */
4332 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4333 call_info
->start_symbol
, (offsetT
) 0,
4334 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4337 /* We need to search for the first relocation involving the start_symbol of
4338 this call_info descriptor. */
4342 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4343 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4345 if (fixP
->fx_addsy
== call_info
->start_symbol
4346 || fixP
->fx_subsy
== call_info
->start_symbol
)
4348 call_info
->start_fix
= fixP
;
4355 call_info
->end_offset_frag
= frag_now
;
4356 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4358 /* Relocation info. for end offset of the function. */
4359 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4360 call_info
->end_symbol
, (offsetT
) 0,
4361 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4364 /* We need to search for the first relocation involving the end_symbol of
4365 this call_info descriptor. */
4369 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4370 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4372 if (fixP
->fx_addsy
== call_info
->end_symbol
4373 || fixP
->fx_subsy
== call_info
->end_symbol
)
4375 call_info
->end_fix
= fixP
;
4382 unwind
= (char *) &call_info
->ci_unwind
;
4383 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4387 FRAG_APPEND_1_CHAR (c
);
4391 /* Return back to the original segment/subsegment. */
4392 subseg_set (save_seg
, save_subseg
);
4396 /* Process a .CALLINFO pseudo-op. This information is used later
4397 to build unwind descriptors and maybe one day to support
4398 .ENTER and .LEAVE. */
4401 pa_callinfo (unused
)
4407 /* .CALLINFO must appear within a procedure definition. */
4408 if (!within_procedure
)
4409 as_bad (".callinfo is not within a procedure definition");
4411 /* Mark the fact that we found the .CALLINFO for the
4412 current procedure. */
4413 callinfo_found
= TRUE
;
4415 /* Iterate over the .CALLINFO arguments. */
4416 while (!is_end_of_statement ())
4418 name
= input_line_pointer
;
4419 c
= get_symbol_end ();
4420 /* Frame size specification. */
4421 if ((strncasecmp (name
, "frame", 5) == 0))
4423 p
= input_line_pointer
;
4425 input_line_pointer
++;
4426 temp
= get_absolute_expression ();
4427 if ((temp
& 0x3) != 0)
4429 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4433 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4434 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4437 /* Entry register (GR, GR and SR) specifications. */
4438 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4440 p
= input_line_pointer
;
4442 input_line_pointer
++;
4443 temp
= get_absolute_expression ();
4444 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4445 even though %r19 is caller saved. I think this is a bug in
4446 the HP assembler, and we are not going to emulate it. */
4447 if (temp
< 3 || temp
> 18)
4448 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4449 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4451 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4453 p
= input_line_pointer
;
4455 input_line_pointer
++;
4456 temp
= get_absolute_expression ();
4457 /* Similarly the HP assembler takes 31 as the high bound even
4458 though %fr21 is the last callee saved floating point register. */
4459 if (temp
< 12 || temp
> 21)
4460 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4461 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4463 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4465 p
= input_line_pointer
;
4467 input_line_pointer
++;
4468 temp
= get_absolute_expression ();
4470 as_bad ("Value for ENTRY_SR must be 3\n");
4471 last_call_info
->entry_sr
= temp
- 2;
4473 /* Note whether or not this function performs any calls. */
4474 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4475 (strncasecmp (name
, "caller", 6) == 0))
4477 p
= input_line_pointer
;
4479 last_call_info
->makes_calls
= 1;
4481 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4483 p
= input_line_pointer
;
4485 last_call_info
->makes_calls
= 0;
4487 /* Should RP be saved into the stack. */
4488 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4490 p
= input_line_pointer
;
4492 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4494 /* Likewise for SP. */
4495 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4497 p
= input_line_pointer
;
4499 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4501 /* Is this an unwindable procedure. If so mark it so
4502 in the unwind descriptor. */
4503 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4505 p
= input_line_pointer
;
4507 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4509 /* Is this an interrupt routine. If so mark it in the
4510 unwind descriptor. */
4511 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4513 p
= input_line_pointer
;
4515 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4519 as_bad ("Invalid .CALLINFO argument: %s", name
);
4521 if (!is_end_of_statement ())
4522 input_line_pointer
++;
4525 demand_empty_rest_of_line ();
4529 /* Switch into the code subspace. */
4535 sd_chain_struct
*sdchain
;
4537 /* First time through it might be necessary to create the
4539 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4541 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4542 pa_def_spaces
[0].spnum
,
4543 pa_def_spaces
[0].loadable
,
4544 pa_def_spaces
[0].defined
,
4545 pa_def_spaces
[0].private,
4546 pa_def_spaces
[0].sort
,
4547 pa_def_spaces
[0].segment
, 0);
4550 SPACE_DEFINED (sdchain
) = 1;
4551 subseg_set (text_section
, SUBSEG_CODE
);
4552 demand_empty_rest_of_line ();
4556 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4557 the .comm pseudo-op has the following symtax:
4559 <label> .comm <length>
4561 where <label> is optional and is a symbol whose address will be the start of
4562 a block of memory <length> bytes long. <length> must be an absolute
4563 expression. <length> bytes will be allocated in the current space
4572 label_symbol_struct
*label_symbol
= pa_get_label ();
4575 symbol
= label_symbol
->lss_label
;
4580 size
= get_absolute_expression ();
4584 /* It is incorrect to check S_IS_DEFINED at this point as
4585 the symbol will *always* be defined. FIXME. How to
4586 correctly determine when this label really as been
4588 if (S_GET_VALUE (symbol
))
4590 if (S_GET_VALUE (symbol
) != size
)
4592 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4593 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4599 S_SET_VALUE (symbol
, size
);
4600 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4601 S_SET_EXTERNAL (symbol
);
4604 demand_empty_rest_of_line ();
4607 /* Process a .COPYRIGHT pseudo-op. */
4610 pa_copyright (unused
)
4617 if (*input_line_pointer
== '\"')
4619 ++input_line_pointer
;
4620 name
= input_line_pointer
;
4621 while ((c
= next_char_of_string ()) >= 0)
4623 c
= *input_line_pointer
;
4624 *input_line_pointer
= '\0';
4625 *(input_line_pointer
- 1) = '\0';
4627 /* FIXME. Not supported */
4630 *input_line_pointer
= c
;
4634 as_bad ("Expected \"-ed string");
4636 pa_undefine_label ();
4637 demand_empty_rest_of_line ();
4640 /* Process a .END pseudo-op. */
4646 demand_empty_rest_of_line ();
4650 /* Process a .ENTER pseudo-op. This is not supported. */
4659 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4665 if (!within_procedure
)
4666 as_bad ("Misplaced .entry. Ignored.");
4669 if (!callinfo_found
)
4670 as_bad ("Missing .callinfo.");
4672 last_call_info
->start_frag
= frag_now
;
4674 demand_empty_rest_of_line ();
4675 within_entry_exit
= TRUE
;
4677 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4678 It will not be on if no .EXPORT pseudo-op exists (static function). */
4679 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4682 /* SOM defers building of unwind descriptors until the link phase.
4683 The assembler is responsible for creating an R_ENTRY relocation
4684 to mark the beginning of a region and hold the unwind bits, and
4685 for creating an R_EXIT relocation to mark the end of the region.
4687 FIXME. ELF should be using the same conventions! The problem
4688 is an unwind requires too much relocation space. Hmmm. Maybe
4689 if we split the unwind bits up between the relocations which
4690 denote the entry and exit points. */
4692 char *where
= frag_more (0);
4694 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4695 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4696 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4697 &last_call_info
->ci_unwind
.descriptor
);
4704 /* Handle a .EQU pseudo-op. */
4710 label_symbol_struct
*label_symbol
= pa_get_label ();
4715 symbol
= label_symbol
->lss_label
;
4716 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4717 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4722 as_bad (".REG must use a label");
4724 as_bad (".EQU must use a label");
4727 pa_undefine_label ();
4728 demand_empty_rest_of_line ();
4732 /* Helper function. Does processing for the end of a function. This
4733 usually involves creating some relocations or building special
4734 symbols to mark the end of the function. */
4741 where
= frag_more (0);
4744 /* ELF does not have EXIT relocations. All we do is create a
4745 temporary symbol marking the end of the function. */
4747 char *name
= (char *) xmalloc (strlen ("L$\001end_") +
4748 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
4754 strcpy (name
, "L$\001end_");
4755 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
4757 symbolP
= symbol_find (name
);
4759 as_warn ("Symbol '%s' already defined.", name
);
4762 /* symbol value should be the offset of the
4763 last instruction of the function */
4764 symbolP
= symbol_new (name
, now_seg
,
4765 (valueT
) (obstack_next_free (&frags
)
4766 - frag_now
->fr_literal
- 4),
4770 symbolP
->bsym
->flags
= BSF_LOCAL
;
4771 symbol_table_insert (symbolP
);
4774 last_call_info
->end_symbol
= symbolP
;
4776 as_bad ("Symbol '%s' could not be created.", name
);
4780 as_bad ("No memory for symbol name.");
4783 /* Stuff away the location of the frag for the end of the function,
4784 and call pa_build_unwind_subspace to add an entry in the unwind
4786 last_call_info
->end_frag
= frag_now
;
4787 pa_build_unwind_subspace (last_call_info
);
4789 /* SOM defers building of unwind descriptors until the link phase.
4790 The assembler is responsible for creating an R_ENTRY relocation
4791 to mark the beginning of a region and hold the unwind bits, and
4792 for creating an R_EXIT relocation to mark the end of the region.
4794 FIXME. ELF should be using the same conventions! The problem
4795 is an unwind requires too much relocation space. Hmmm. Maybe
4796 if we split the unwind bits up between the relocations which
4797 denote the entry and exit points. */
4798 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4799 last_call_info
->start_symbol
, (offsetT
) 0,
4800 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4803 exit_processing_complete
= TRUE
;
4806 /* Process a .EXIT pseudo-op. */
4812 if (!within_procedure
)
4813 as_bad (".EXIT must appear within a procedure");
4816 if (!callinfo_found
)
4817 as_bad ("Missing .callinfo");
4820 if (!within_entry_exit
)
4821 as_bad ("No .ENTRY for this .EXIT");
4824 within_entry_exit
= FALSE
;
4829 demand_empty_rest_of_line ();
4833 /* Process a .EXPORT directive. This makes functions external
4834 and provides information such as argument relocation entries
4844 name
= input_line_pointer
;
4845 c
= get_symbol_end ();
4846 /* Make sure the given symbol exists. */
4847 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4849 as_bad ("Cannot define export symbol: %s\n", name
);
4850 p
= input_line_pointer
;
4852 input_line_pointer
++;
4856 /* OK. Set the external bits and process argument relocations. */
4857 S_SET_EXTERNAL (symbol
);
4858 p
= input_line_pointer
;
4860 if (!is_end_of_statement ())
4862 input_line_pointer
++;
4863 pa_export_args (symbol
);
4865 pa_build_symextn_section ();
4870 demand_empty_rest_of_line ();
4874 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4877 pa_export_args (symbolP
)
4881 unsigned int temp
, arg_reloc
;
4882 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4883 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4885 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4887 input_line_pointer
+= 8;
4888 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4889 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4890 type
= SYMBOL_TYPE_ABSOLUTE
;
4892 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4894 input_line_pointer
+= 4;
4895 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4896 type
= SYMBOL_TYPE_CODE
;
4898 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4900 input_line_pointer
+= 4;
4901 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4902 type
= SYMBOL_TYPE_DATA
;
4904 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4906 input_line_pointer
+= 5;
4907 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4908 type
= SYMBOL_TYPE_ENTRY
;
4910 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4912 input_line_pointer
+= 9;
4913 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4914 type
= SYMBOL_TYPE_MILLICODE
;
4916 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4918 input_line_pointer
+= 6;
4919 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4920 type
= SYMBOL_TYPE_PLABEL
;
4922 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4924 input_line_pointer
+= 8;
4925 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4926 type
= SYMBOL_TYPE_PRI_PROG
;
4928 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4930 input_line_pointer
+= 8;
4931 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4932 type
= SYMBOL_TYPE_SEC_PROG
;
4935 /* SOM requires much more information about symbol types
4936 than BFD understands. This is how we get this information
4937 to the SOM BFD backend. */
4938 #ifdef obj_set_symbol_type
4939 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4942 /* Now that the type of the exported symbol has been handled,
4943 handle any argument relocation information. */
4944 while (!is_end_of_statement ())
4946 if (*input_line_pointer
== ',')
4947 input_line_pointer
++;
4948 name
= input_line_pointer
;
4949 c
= get_symbol_end ();
4950 /* Argument sources. */
4951 if ((strncasecmp (name
, "argw", 4) == 0))
4953 p
= input_line_pointer
;
4955 input_line_pointer
++;
4956 temp
= atoi (name
+ 4);
4957 name
= input_line_pointer
;
4958 c
= get_symbol_end ();
4959 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4960 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4961 *input_line_pointer
= c
;
4963 /* The return value. */
4964 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4966 p
= input_line_pointer
;
4968 input_line_pointer
++;
4969 name
= input_line_pointer
;
4970 c
= get_symbol_end ();
4971 arg_reloc
= pa_build_arg_reloc (name
);
4972 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4973 *input_line_pointer
= c
;
4975 /* Privelege level. */
4976 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4978 p
= input_line_pointer
;
4980 input_line_pointer
++;
4981 temp
= atoi (input_line_pointer
);
4982 c
= get_symbol_end ();
4983 *input_line_pointer
= c
;
4987 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4988 p
= input_line_pointer
;
4991 if (!is_end_of_statement ())
4992 input_line_pointer
++;
4996 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4997 assembly file must either be defined in the assembly file, or
4998 explicitly IMPORTED from another. */
5007 name
= input_line_pointer
;
5008 c
= get_symbol_end ();
5010 symbol
= symbol_find_or_make (name
);
5011 p
= input_line_pointer
;
5014 if (!is_end_of_statement ())
5016 input_line_pointer
++;
5017 pa_export_args (symbol
);
5021 /* Sigh. To be compatable with the HP assembler and to help
5022 poorly written assembly code, we assign a type based on
5023 the the current segment. Note only BSF_FUNCTION really
5024 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
5025 if (now_seg
== text_section
)
5026 symbol
->bsym
->flags
|= BSF_FUNCTION
;
5028 /* If the section is undefined, then the symbol is undefined
5029 Since this is an import, leave the section undefined. */
5030 S_SET_SEGMENT (symbol
, &bfd_und_section
);
5033 demand_empty_rest_of_line ();
5037 /* Handle a .LABEL pseudo-op. */
5045 name
= input_line_pointer
;
5046 c
= get_symbol_end ();
5048 if (strlen (name
) > 0)
5051 p
= input_line_pointer
;
5056 as_warn ("Missing label name on .LABEL");
5059 if (!is_end_of_statement ())
5061 as_warn ("extra .LABEL arguments ignored.");
5062 ignore_rest_of_line ();
5064 demand_empty_rest_of_line ();
5068 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5077 /* Handle a .ORIGIN pseudo-op. */
5084 pa_undefine_label ();
5088 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5089 is for static functions. FIXME. Should share more code with .EXPORT. */
5098 name
= input_line_pointer
;
5099 c
= get_symbol_end ();
5101 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5103 as_bad ("Cannot define static symbol: %s\n", name
);
5104 p
= input_line_pointer
;
5106 input_line_pointer
++;
5110 S_CLEAR_EXTERNAL (symbol
);
5111 p
= input_line_pointer
;
5113 if (!is_end_of_statement ())
5115 input_line_pointer
++;
5116 pa_export_args (symbol
);
5120 demand_empty_rest_of_line ();
5124 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5125 of a procedure from a syntatical point of view. */
5131 struct call_info
*call_info
;
5133 if (within_procedure
)
5134 as_fatal ("Nested procedures");
5136 /* Reset global variables for new procedure. */
5137 callinfo_found
= FALSE
;
5138 within_procedure
= TRUE
;
5139 exit_processing_complete
= FALSE
;
5141 /* Create another call_info structure. */
5142 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5145 as_fatal ("Cannot allocate unwind descriptor\n");
5147 bzero (call_info
, sizeof (struct call_info
));
5149 call_info
->ci_next
= NULL
;
5151 if (call_info_root
== NULL
)
5153 call_info_root
= call_info
;
5154 last_call_info
= call_info
;
5158 last_call_info
->ci_next
= call_info
;
5159 last_call_info
= call_info
;
5162 /* set up defaults on call_info structure */
5164 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5165 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5166 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5167 call_info
->entry_sr
= ~0;
5168 call_info
->makes_calls
= 1;
5170 /* If we got a .PROC pseudo-op, we know that the function is defined
5171 locally. Make sure it gets into the symbol table. */
5173 label_symbol_struct
*label_symbol
= pa_get_label ();
5177 if (label_symbol
->lss_label
)
5179 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5180 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5183 as_bad ("Missing function name for .PROC (corrupted label)");
5186 as_bad ("Missing function name for .PROC");
5189 demand_empty_rest_of_line ();
5193 /* Process the syntatical end of a procedure. Make sure all the
5194 appropriate pseudo-ops were found within the procedure. */
5201 if (!within_procedure
)
5202 as_bad ("misplaced .procend");
5204 if (!callinfo_found
)
5205 as_bad ("Missing .callinfo for this procedure");
5207 if (within_entry_exit
)
5208 as_bad ("Missing .EXIT for a .ENTRY");
5210 if (!exit_processing_complete
)
5213 within_procedure
= FALSE
;
5214 demand_empty_rest_of_line ();
5218 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5219 then create a new space entry to hold the information specified
5220 by the parameters to the .SPACE directive. */
5222 static sd_chain_struct
*
5223 pa_parse_space_stmt (space_name
, create_flag
)
5227 char *name
, *ptemp
, c
;
5228 char loadable
, defined
, private, sort
;
5230 asection
*seg
= NULL
;
5231 sd_chain_struct
*space
;
5233 /* load default values */
5239 if (strcasecmp (space_name
, "$TEXT$") == 0)
5241 seg
= pa_def_spaces
[0].segment
;
5242 sort
= pa_def_spaces
[0].sort
;
5244 else if (strcasecmp (space_name
, "$PRIVATE$") == 0)
5246 seg
= pa_def_spaces
[1].segment
;
5247 sort
= pa_def_spaces
[1].sort
;
5250 if (!is_end_of_statement ())
5252 print_errors
= FALSE
;
5253 ptemp
= input_line_pointer
+ 1;
5254 /* First see if the space was specified as a number rather than
5255 as a name. According to the PA assembly manual the rest of
5256 the line should be ignored. */
5257 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5258 input_line_pointer
= ptemp
;
5261 while (!is_end_of_statement ())
5263 input_line_pointer
++;
5264 name
= input_line_pointer
;
5265 c
= get_symbol_end ();
5266 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5268 *input_line_pointer
= c
;
5269 input_line_pointer
++;
5270 spnum
= get_absolute_expression ();
5272 else if ((strncasecmp (name
, "SORT", 4) == 0))
5274 *input_line_pointer
= c
;
5275 input_line_pointer
++;
5276 sort
= get_absolute_expression ();
5278 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5280 *input_line_pointer
= c
;
5283 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5285 *input_line_pointer
= c
;
5288 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5290 *input_line_pointer
= c
;
5295 as_bad ("Invalid .SPACE argument");
5296 *input_line_pointer
= c
;
5297 if (! is_end_of_statement ())
5298 input_line_pointer
++;
5302 print_errors
= TRUE
;
5305 if (create_flag
&& seg
== NULL
)
5306 seg
= subseg_new (space_name
, 0);
5308 /* If create_flag is nonzero, then create the new space with
5309 the attributes computed above. Else set the values in
5310 an already existing space -- this can only happen for
5311 the first occurence of a built-in space. */
5313 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5314 private, sort
, seg
, 1);
5317 space
= is_defined_space (space_name
);
5318 SPACE_SPNUM (space
) = spnum
;
5319 SPACE_LOADABLE (space
) = loadable
& 1;
5320 SPACE_DEFINED (space
) = defined
& 1;
5321 SPACE_USER_DEFINED (space
) = 1;
5322 SPACE_PRIVATE (space
) = private & 1;
5323 SPACE_SORT (space
) = sort
& 0xff;
5324 space
->sd_seg
= seg
;
5327 #ifdef obj_set_section_attributes
5328 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5334 /* Adjust the frag's alignment according to the alignment needs
5335 of the given subspace/subsegment. */
5338 pa_align_subseg (seg
, subseg
)
5342 ssd_chain_struct
*now_subspace
;
5346 now_subspace
= pa_subsegment_to_subspace (seg
, subseg
);
5349 if (SUBSPACE_ALIGN (now_subspace
) == 0)
5350 alignment
= now_subspace
->ssd_last_align
;
5351 else if (now_subspace
->ssd_last_align
> SUBSPACE_ALIGN (now_subspace
))
5352 alignment
= now_subspace
->ssd_last_align
;
5354 alignment
= SUBSPACE_ALIGN (now_subspace
);
5356 while ((1 << shift
) < alignment
)
5360 shift
= bfd_get_section_alignment (stdoutput
, seg
);
5362 frag_align (shift
, 0);
5365 /* Handle a .SPACE pseudo-op; this switches the current space to the
5366 given space, creating the new space if necessary. */
5372 char *name
, c
, *space_name
, *save_s
;
5374 sd_chain_struct
*sd_chain
;
5376 if (within_procedure
)
5378 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5379 ignore_rest_of_line ();
5383 /* Check for some of the predefined spaces. FIXME: most of the code
5384 below is repeated several times, can we extract the common parts
5385 and place them into a subroutine or something similar? */
5386 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5388 input_line_pointer
+= 6;
5389 sd_chain
= is_defined_space ("$TEXT$");
5390 if (sd_chain
== NULL
)
5391 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5392 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5393 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5395 current_space
= sd_chain
;
5397 /* No need to align if we are already there. */
5398 if (now_seg
!= text_section
)
5399 pa_align_subseg (now_seg
, now_subseg
);
5401 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5404 = pa_subsegment_to_subspace (text_section
,
5405 sd_chain
->sd_last_subseg
);
5406 demand_empty_rest_of_line ();
5409 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5411 input_line_pointer
+= 9;
5412 sd_chain
= is_defined_space ("$PRIVATE$");
5413 if (sd_chain
== NULL
)
5414 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5415 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5416 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5418 current_space
= sd_chain
;
5420 /* No need to align if we are already there. */
5421 if (now_seg
!= data_section
)
5422 pa_align_subseg (now_seg
, now_subseg
);
5424 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5426 = pa_subsegment_to_subspace (data_section
,
5427 sd_chain
->sd_last_subseg
);
5428 demand_empty_rest_of_line ();
5431 if (!strncasecmp (input_line_pointer
,
5432 GDB_DEBUG_SPACE_NAME
,
5433 strlen (GDB_DEBUG_SPACE_NAME
)))
5435 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5436 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5437 if (sd_chain
== NULL
)
5438 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5439 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5440 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5442 current_space
= sd_chain
;
5445 asection
*gdb_section
5446 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5448 /* No need to align if we are already there. */
5449 if (strcmp (segment_name (now_seg
), GDB_DEBUG_SPACE_NAME
) != 0)
5450 pa_align_subseg (now_seg
, now_subseg
);
5452 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5454 = pa_subsegment_to_subspace (gdb_section
,
5455 sd_chain
->sd_last_subseg
);
5457 demand_empty_rest_of_line ();
5461 /* It could be a space specified by number. */
5463 save_s
= input_line_pointer
;
5464 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5466 if (sd_chain
= pa_find_space_by_number (temp
))
5468 current_space
= sd_chain
;
5470 if (now_seg
!= sd_chain
->sd_seg
)
5471 pa_align_subseg (now_seg
, now_subseg
);
5472 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5474 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5475 sd_chain
->sd_last_subseg
);
5476 demand_empty_rest_of_line ();
5481 /* Not a number, attempt to create a new space. */
5483 input_line_pointer
= save_s
;
5484 name
= input_line_pointer
;
5485 c
= get_symbol_end ();
5486 space_name
= xmalloc (strlen (name
) + 1);
5487 strcpy (space_name
, name
);
5488 *input_line_pointer
= c
;
5490 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5491 current_space
= sd_chain
;
5493 if (now_seg
!= sd_chain
->sd_seg
)
5494 pa_align_subseg (now_seg
, now_subseg
);
5495 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5496 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5497 sd_chain
->sd_last_subseg
);
5498 demand_empty_rest_of_line ();
5503 /* Switch to a new space. (I think). FIXME. */
5512 sd_chain_struct
*space
;
5514 name
= input_line_pointer
;
5515 c
= get_symbol_end ();
5516 space
= is_defined_space (name
);
5520 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5523 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5525 *input_line_pointer
= c
;
5526 demand_empty_rest_of_line ();
5530 /* If VALUE is an exact power of two between zero and 2^31, then
5531 return log2 (VALUE). Else return -1. */
5539 while ((1 << shift
) != value
&& shift
< 32)
5548 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5549 given subspace, creating the new subspace if necessary.
5551 FIXME. Should mirror pa_space more closely, in particular how
5552 they're broken up into subroutines. */
5555 pa_subspace (unused
)
5558 char *name
, *ss_name
, *alias
, c
;
5559 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5560 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5561 sd_chain_struct
*space
;
5562 ssd_chain_struct
*ssd
;
5565 if (within_procedure
)
5567 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5568 ignore_rest_of_line ();
5572 name
= input_line_pointer
;
5573 c
= get_symbol_end ();
5574 ss_name
= xmalloc (strlen (name
) + 1);
5575 strcpy (ss_name
, name
);
5576 *input_line_pointer
= c
;
5578 /* Load default values. */
5591 space
= current_space
;
5592 ssd
= is_defined_subspace (ss_name
);
5593 /* Allow user to override the builtin attributes of subspaces. But
5594 only allow the attributes to be changed once! */
5595 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5597 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5598 if (!is_end_of_statement ())
5599 as_warn ("Parameters of an existing subspace can\'t be modified");
5600 demand_empty_rest_of_line ();
5605 /* A new subspace. Load default values if it matches one of
5606 the builtin subspaces. */
5608 while (pa_def_subspaces
[i
].name
)
5610 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5612 loadable
= pa_def_subspaces
[i
].loadable
;
5613 common
= pa_def_subspaces
[i
].common
;
5614 dup_common
= pa_def_subspaces
[i
].dup_common
;
5615 code_only
= pa_def_subspaces
[i
].code_only
;
5616 zero
= pa_def_subspaces
[i
].zero
;
5617 space_index
= pa_def_subspaces
[i
].space_index
;
5618 alignment
= pa_def_subspaces
[i
].alignment
;
5619 quadrant
= pa_def_subspaces
[i
].quadrant
;
5620 access
= pa_def_subspaces
[i
].access
;
5621 sort
= pa_def_subspaces
[i
].sort
;
5622 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5623 alias
= pa_def_subspaces
[i
].alias
;
5630 /* We should be working with a new subspace now. Fill in
5631 any information as specified by the user. */
5632 if (!is_end_of_statement ())
5634 input_line_pointer
++;
5635 while (!is_end_of_statement ())
5637 name
= input_line_pointer
;
5638 c
= get_symbol_end ();
5639 if ((strncasecmp (name
, "QUAD", 4) == 0))
5641 *input_line_pointer
= c
;
5642 input_line_pointer
++;
5643 quadrant
= get_absolute_expression ();
5645 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5647 *input_line_pointer
= c
;
5648 input_line_pointer
++;
5649 alignment
= get_absolute_expression ();
5650 if (log2 (alignment
) == -1)
5652 as_bad ("Alignment must be a power of 2");
5656 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5658 *input_line_pointer
= c
;
5659 input_line_pointer
++;
5660 access
= get_absolute_expression ();
5662 else if ((strncasecmp (name
, "SORT", 4) == 0))
5664 *input_line_pointer
= c
;
5665 input_line_pointer
++;
5666 sort
= get_absolute_expression ();
5668 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5670 *input_line_pointer
= c
;
5673 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5675 *input_line_pointer
= c
;
5678 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5680 *input_line_pointer
= c
;
5683 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5685 *input_line_pointer
= c
;
5688 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5690 *input_line_pointer
= c
;
5693 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5694 as_bad ("FIRST not supported as a .SUBSPACE argument");
5696 as_bad ("Invalid .SUBSPACE argument");
5697 if (!is_end_of_statement ())
5698 input_line_pointer
++;
5702 /* Compute a reasonable set of BFD flags based on the information
5703 in the .subspace directive. */
5704 applicable
= bfd_applicable_section_flags (stdoutput
);
5707 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5710 if (common
|| dup_common
)
5711 flags
|= SEC_IS_COMMON
;
5713 /* This is a zero-filled subspace (eg BSS). */
5717 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5718 applicable
&= flags
;
5720 /* If this is an existing subspace, then we want to use the
5721 segment already associated with the subspace.
5723 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5724 lots of sections. It might be a problem in the PA ELF
5725 code, I do not know yet. For now avoid creating anything
5726 but the "standard" sections for ELF. */
5728 section
= ssd
->ssd_seg
;
5730 section
= subseg_new (alias
, 0);
5731 else if (! alias
&& USE_ALIASES
)
5733 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5734 demand_empty_rest_of_line ();
5738 section
= subseg_new (ss_name
, 0);
5740 /* Now set the flags. */
5741 bfd_set_section_flags (stdoutput
, section
, applicable
);
5743 /* Record any alignment request for this section. */
5744 record_alignment (section
, log2 (alignment
));
5746 /* Set the starting offset for this section. */
5747 bfd_set_section_vma (stdoutput
, section
,
5748 pa_subspace_start (space
, quadrant
));
5750 /* Now that all the flags are set, update an existing subspace,
5751 or create a new one. */
5754 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5755 code_only
, common
, dup_common
,
5756 sort
, zero
, access
, space_index
,
5757 alignment
, quadrant
,
5760 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5762 dup_common
, zero
, sort
,
5763 access
, space_index
,
5764 alignment
, quadrant
, section
);
5766 demand_empty_rest_of_line ();
5767 current_subspace
->ssd_seg
= section
;
5768 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5770 SUBSPACE_DEFINED (current_subspace
) = 1;
5775 /* Create default space and subspace dictionaries. */
5782 space_dict_root
= NULL
;
5783 space_dict_last
= NULL
;
5786 while (pa_def_spaces
[i
].name
)
5790 /* Pick the right name to use for the new section. */
5791 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5792 name
= pa_def_spaces
[i
].alias
;
5794 name
= pa_def_spaces
[i
].name
;
5796 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5797 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5798 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5799 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5800 pa_def_spaces
[i
].segment
, 0);
5805 while (pa_def_subspaces
[i
].name
)
5808 int applicable
, subsegment
;
5809 asection
*segment
= NULL
;
5810 sd_chain_struct
*space
;
5812 /* Pick the right name for the new section and pick the right
5813 subsegment number. */
5814 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5816 name
= pa_def_subspaces
[i
].alias
;
5817 subsegment
= pa_def_subspaces
[i
].subsegment
;
5821 name
= pa_def_subspaces
[i
].name
;
5825 /* Create the new section. */
5826 segment
= subseg_new (name
, subsegment
);
5829 /* For SOM we want to replace the standard .text, .data, and .bss
5830 sections with our own. */
5831 if (! strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && ! USE_ALIASES
)
5833 text_section
= segment
;
5834 applicable
= bfd_applicable_section_flags (stdoutput
);
5835 bfd_set_section_flags (stdoutput
, text_section
,
5836 applicable
& (SEC_ALLOC
| SEC_LOAD
5837 | SEC_RELOC
| SEC_CODE
5839 | SEC_HAS_CONTENTS
));
5841 else if (! strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && ! USE_ALIASES
)
5843 data_section
= segment
;
5844 applicable
= bfd_applicable_section_flags (stdoutput
);
5845 bfd_set_section_flags (stdoutput
, data_section
,
5846 applicable
& (SEC_ALLOC
| SEC_LOAD
5848 | SEC_HAS_CONTENTS
));
5852 else if (! strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && ! USE_ALIASES
)
5854 bss_section
= segment
;
5855 applicable
= bfd_applicable_section_flags (stdoutput
);
5856 bfd_set_section_flags (stdoutput
, bss_section
,
5857 applicable
& SEC_ALLOC
);
5860 /* Find the space associated with this subspace. */
5861 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5862 def_space_index
].segment
);
5865 as_fatal ("Internal error: Unable to find containing space for %s.",
5866 pa_def_subspaces
[i
].name
);
5869 create_new_subspace (space
, name
,
5870 pa_def_subspaces
[i
].loadable
,
5871 pa_def_subspaces
[i
].code_only
,
5872 pa_def_subspaces
[i
].common
,
5873 pa_def_subspaces
[i
].dup_common
,
5874 pa_def_subspaces
[i
].zero
,
5875 pa_def_subspaces
[i
].sort
,
5876 pa_def_subspaces
[i
].access
,
5877 pa_def_subspaces
[i
].space_index
,
5878 pa_def_subspaces
[i
].alignment
,
5879 pa_def_subspaces
[i
].quadrant
,
5887 /* Create a new space NAME, with the appropriate flags as defined
5888 by the given parameters.
5890 Add the new space to the space dictionary chain in numerical
5891 order as defined by the SORT entries. */
5893 static sd_chain_struct
*
5894 create_new_space (name
, spnum
, loadable
, defined
, private,
5895 sort
, seg
, user_defined
)
5905 sd_chain_struct
*chain_entry
;
5907 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5909 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5912 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5913 strcpy (SPACE_NAME (chain_entry
), name
);
5914 SPACE_NAME_INDEX (chain_entry
) = 0;
5915 SPACE_LOADABLE (chain_entry
) = loadable
;
5916 SPACE_DEFINED (chain_entry
) = defined
;
5917 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5918 SPACE_PRIVATE (chain_entry
) = private;
5919 SPACE_SPNUM (chain_entry
) = spnum
;
5920 SPACE_SORT (chain_entry
) = sort
;
5922 chain_entry
->sd_seg
= seg
;
5923 chain_entry
->sd_last_subseg
= -1;
5924 chain_entry
->sd_next
= NULL
;
5926 /* Find spot for the new space based on its sort key. */
5927 if (!space_dict_last
)
5928 space_dict_last
= chain_entry
;
5930 if (space_dict_root
== NULL
)
5931 space_dict_root
= chain_entry
;
5934 sd_chain_struct
*chain_pointer
;
5935 sd_chain_struct
*prev_chain_pointer
;
5937 chain_pointer
= space_dict_root
;
5938 prev_chain_pointer
= NULL
;
5940 while (chain_pointer
)
5942 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5944 prev_chain_pointer
= chain_pointer
;
5945 chain_pointer
= chain_pointer
->sd_next
;
5951 /* At this point we've found the correct place to add the new
5952 entry. So add it and update the linked lists as appropriate. */
5953 if (prev_chain_pointer
)
5955 chain_entry
->sd_next
= chain_pointer
;
5956 prev_chain_pointer
->sd_next
= chain_entry
;
5960 space_dict_root
= chain_entry
;
5961 chain_entry
->sd_next
= chain_pointer
;
5964 if (chain_entry
->sd_next
== NULL
)
5965 space_dict_last
= chain_entry
;
5968 /* This is here to catch predefined spaces which do not get
5969 modified by the user's input. Another call is found at
5970 the bottom of pa_parse_space_stmt to handle cases where
5971 the user modifies a predefined space. */
5972 #ifdef obj_set_section_attributes
5973 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5979 /* Create a new subspace NAME, with the appropriate flags as defined
5980 by the given parameters.
5982 Add the new subspace to the subspace dictionary chain in numerical
5983 order as defined by the SORT entries. */
5985 static ssd_chain_struct
*
5986 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5987 dup_common
, is_zero
, sort
, access
, space_index
,
5988 alignment
, quadrant
, seg
)
5989 sd_chain_struct
*space
;
5991 char loadable
, code_only
, common
, dup_common
, is_zero
;
5999 ssd_chain_struct
*chain_entry
;
6001 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
6003 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
6005 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
6006 strcpy (SUBSPACE_NAME (chain_entry
), name
);
6008 SUBSPACE_ACCESS (chain_entry
) = access
;
6009 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
6010 SUBSPACE_COMMON (chain_entry
) = common
;
6011 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
6012 SUBSPACE_SORT (chain_entry
) = sort
;
6013 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
6014 SUBSPACE_ALIGN (chain_entry
) = alignment
;
6015 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
6016 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
6017 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
6018 SUBSPACE_ZERO (chain_entry
) = is_zero
;
6020 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
6021 chain_entry
->ssd_seg
= seg
;
6022 chain_entry
->ssd_last_align
= 1;
6023 chain_entry
->ssd_next
= NULL
;
6025 /* Find spot for the new subspace based on its sort key. */
6026 if (space
->sd_subspaces
== NULL
)
6027 space
->sd_subspaces
= chain_entry
;
6030 ssd_chain_struct
*chain_pointer
;
6031 ssd_chain_struct
*prev_chain_pointer
;
6033 chain_pointer
= space
->sd_subspaces
;
6034 prev_chain_pointer
= NULL
;
6036 while (chain_pointer
)
6038 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
6040 prev_chain_pointer
= chain_pointer
;
6041 chain_pointer
= chain_pointer
->ssd_next
;
6048 /* Now we have somewhere to put the new entry. Insert it and update
6050 if (prev_chain_pointer
)
6052 chain_entry
->ssd_next
= chain_pointer
;
6053 prev_chain_pointer
->ssd_next
= chain_entry
;
6057 space
->sd_subspaces
= chain_entry
;
6058 chain_entry
->ssd_next
= chain_pointer
;
6062 #ifdef obj_set_subsection_attributes
6063 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
6071 /* Update the information for the given subspace based upon the
6072 various arguments. Return the modified subspace chain entry. */
6074 static ssd_chain_struct
*
6075 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
6076 zero
, access
, space_index
, alignment
, quadrant
, subseg
)
6077 sd_chain_struct
*space
;
6091 ssd_chain_struct
*chain_entry
;
6093 if ((chain_entry
= is_defined_subspace (name
)))
6095 SUBSPACE_ACCESS (chain_entry
) = access
;
6096 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
6097 SUBSPACE_COMMON (chain_entry
) = common
;
6098 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
6099 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
6100 SUBSPACE_SORT (chain_entry
) = sort
;
6101 SUBSPACE_ALIGN (chain_entry
) = alignment
;
6102 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
6103 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
6104 SUBSPACE_ZERO (chain_entry
) = zero
;
6109 #ifdef obj_set_subsection_attributes
6110 obj_set_subsection_attributes (subseg
, space
->sd_seg
, access
,
6118 /* Return the space chain entry for the space with the name NAME or
6119 NULL if no such space exists. */
6121 static sd_chain_struct
*
6122 is_defined_space (name
)
6125 sd_chain_struct
*chain_pointer
;
6127 for (chain_pointer
= space_dict_root
;
6129 chain_pointer
= chain_pointer
->sd_next
)
6131 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6132 return chain_pointer
;
6135 /* No mapping from segment to space was found. Return NULL. */
6139 /* Find and return the space associated with the given seg. If no mapping
6140 from the given seg to a space is found, then return NULL.
6142 Unlike subspaces, the number of spaces is not expected to grow much,
6143 so a linear exhaustive search is OK here. */
6145 static sd_chain_struct
*
6146 pa_segment_to_space (seg
)
6149 sd_chain_struct
*space_chain
;
6151 /* Walk through each space looking for the correct mapping. */
6152 for (space_chain
= space_dict_root
;
6154 space_chain
= space_chain
->sd_next
)
6156 if (space_chain
->sd_seg
== seg
)
6160 /* Mapping was not found. Return NULL. */
6164 /* Return the space chain entry for the subspace with the name NAME or
6165 NULL if no such subspace exists.
6167 Uses a linear search through all the spaces and subspaces, this may
6168 not be appropriate if we ever being placing each function in its
6171 static ssd_chain_struct
*
6172 is_defined_subspace (name
)
6175 sd_chain_struct
*space_chain
;
6176 ssd_chain_struct
*subspace_chain
;
6178 /* Walk through each space. */
6179 for (space_chain
= space_dict_root
;
6181 space_chain
= space_chain
->sd_next
)
6183 /* Walk through each subspace looking for a name which matches. */
6184 for (subspace_chain
= space_chain
->sd_subspaces
;
6186 subspace_chain
= subspace_chain
->ssd_next
)
6187 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6188 return subspace_chain
;
6191 /* Subspace wasn't found. Return NULL. */
6195 /* Find and return the subspace associated with the given seg. If no
6196 mapping from the given seg to a subspace is found, then return NULL.
6198 If we ever put each procedure/function within its own subspace
6199 (to make life easier on the compiler and linker), then this will have
6200 to become more efficient. */
6202 static ssd_chain_struct
*
6203 pa_subsegment_to_subspace (seg
, subseg
)
6207 sd_chain_struct
*space_chain
;
6208 ssd_chain_struct
*subspace_chain
;
6210 /* Walk through each space. */
6211 for (space_chain
= space_dict_root
;
6213 space_chain
= space_chain
->sd_next
)
6215 if (space_chain
->sd_seg
== seg
)
6217 /* Walk through each subspace within each space looking for
6218 the correct mapping. */
6219 for (subspace_chain
= space_chain
->sd_subspaces
;
6221 subspace_chain
= subspace_chain
->ssd_next
)
6222 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6223 return subspace_chain
;
6227 /* No mapping from subsegment to subspace found. Return NULL. */
6231 /* Given a number, try and find a space with the name number.
6233 Return a pointer to a space dictionary chain entry for the space
6234 that was found or NULL on failure. */
6236 static sd_chain_struct
*
6237 pa_find_space_by_number (number
)
6240 sd_chain_struct
*space_chain
;
6242 for (space_chain
= space_dict_root
;
6244 space_chain
= space_chain
->sd_next
)
6246 if (SPACE_SPNUM (space_chain
) == number
)
6250 /* No appropriate space found. Return NULL. */
6254 /* Return the starting address for the given subspace. If the starting
6255 address is unknown then return zero. */
6258 pa_subspace_start (space
, quadrant
)
6259 sd_chain_struct
*space
;
6262 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6263 is not correct for the PA OSF1 port. */
6264 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6266 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6272 /* FIXME. Needs documentation. */
6274 pa_next_subseg (space
)
6275 sd_chain_struct
*space
;
6278 space
->sd_last_subseg
++;
6279 return space
->sd_last_subseg
;
6282 /* Helper function for pa_stringer. Used to find the end of
6289 unsigned int c
= *s
& CHAR_MASK
;
6301 /* Handle a .STRING type pseudo-op. */
6304 pa_stringer (append_zero
)
6307 char *s
, num_buf
[4];
6311 /* Preprocess the string to handle PA-specific escape sequences.
6312 For example, \xDD where DD is a hexidecimal number should be
6313 changed to \OOO where OOO is an octal number. */
6315 /* Skip the opening quote. */
6316 s
= input_line_pointer
+ 1;
6318 while (is_a_char (c
= pa_stringer_aux (s
++)))
6325 /* Handle \x<num>. */
6328 unsigned int number
;
6333 /* Get pas the 'x'. */
6335 for (num_digit
= 0, number
= 0, dg
= *s
;
6337 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6338 || (dg
>= 'A' && dg
<= 'F'));
6342 number
= number
* 16 + dg
- '0';
6343 else if (dg
>= 'a' && dg
<= 'f')
6344 number
= number
* 16 + dg
- 'a' + 10;
6346 number
= number
* 16 + dg
- 'A' + 10;
6356 sprintf (num_buf
, "%02o", number
);
6359 sprintf (num_buf
, "%03o", number
);
6362 for (i
= 0; i
<= num_digit
; i
++)
6363 s_start
[i
] = num_buf
[i
];
6367 /* This might be a "\"", skip over the escaped char. */
6374 stringer (append_zero
);
6375 pa_undefine_label ();
6378 /* Handle a .VERSION pseudo-op. */
6385 pa_undefine_label ();
6388 /* Just like a normal cons, but when finished we have to undefine
6389 the latest space label. */
6396 pa_undefine_label ();
6399 /* Switch to the data space. As usual delete our label. */
6406 pa_undefine_label ();
6409 /* FIXME. What's the purpose of this pseudo-op? */
6415 pa_undefine_label ();
6418 /* Like float_cons, but we need to undefine our label. */
6421 pa_float_cons (float_type
)
6424 float_cons (float_type
);
6425 pa_undefine_label ();
6428 /* Like s_fill, but delete our label when finished. */
6435 pa_undefine_label ();
6438 /* Like lcomm, but delete our label when finished. */
6441 pa_lcomm (needs_align
)
6444 s_lcomm (needs_align
);
6445 pa_undefine_label ();
6448 /* Like lsym, but delete our label when finished. */
6455 pa_undefine_label ();
6458 /* Switch to the text space. Like s_text, but delete our
6459 label when finished. */
6465 pa_undefine_label ();
6468 /* On the PA relocations which involve function symbols must not be
6469 adjusted. This so that the linker can know when/how to create argument
6470 relocation stubs for indirect calls and calls to static functions.
6472 FIXME. Also reject R_HPPA relocations which are 32 bits
6473 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6474 needs to generate relocations to push the addend and symbol value
6475 onto the stack, add them, then pop the value off the stack and
6476 use it in a relocation -- yuk. */
6479 hppa_fix_adjustable (fixp
)
6482 struct hppa_fix_struct
*hppa_fix
;
6484 hppa_fix
= fixp
->tc_fix_data
;
6486 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6489 if (fixp
->fx_addsy
== 0
6490 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6496 /* Now for some ELF specific code. FIXME. */
6498 static symext_chainS
*symext_rootP
;
6499 static symext_chainS
*symext_lastP
;
6501 /* Do any symbol processing requested by the target-cpu or target-format. */
6504 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6506 elf_symbol_type
*symbolP
;
6509 symext_chainS
*symextP
;
6510 unsigned int arg_reloc
;
6512 /* Only functions can have argument relocations. */
6513 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6516 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6518 /* If there are no argument relocation bits, then no relocation is
6519 necessary. Do not add this to the symextn section. */
6523 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6525 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6526 symextP
[0].next
= &symextP
[1];
6528 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6529 symextP
[1].next
= NULL
;
6531 if (symext_rootP
== NULL
)
6533 symext_rootP
= &symextP
[0];
6534 symext_lastP
= &symextP
[1];
6538 symext_lastP
->next
= &symextP
[0];
6539 symext_lastP
= &symextP
[1];
6543 /* Make sections needed by the target cpu and/or target format. */
6545 hppa_tc_make_sections (abfd
)
6548 symext_chainS
*symextP
;
6550 asection
*symextn_sec
;
6551 segT save_seg
= now_seg
;
6552 subsegT save_subseg
= now_subseg
;
6554 /* Build the symbol extension section. */
6555 hppa_tc_make_symextn_section ();
6557 /* Force some calculation to occur. */
6558 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6560 hppa_elf_stub_finish (abfd
);
6562 /* If no symbols for the symbol extension section, then stop now. */
6563 if (symext_rootP
== NULL
)
6566 /* Count the number of symbols for the symbol extension section. */
6567 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6570 size
= sizeof (symext_entryS
) * n
;
6572 /* Switch to the symbol extension section. */
6573 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6575 frag_wane (frag_now
);
6578 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6581 int *symtab_map
= elf_sym_extra (abfd
);
6584 /* First, patch the symbol extension record to reflect the true
6585 symbol table index. */
6587 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6589 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6590 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6594 ptr
= frag_more (sizeof (symextP
->entry
));
6595 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6598 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6599 frag_wane (frag_now
);
6601 /* Switch back to the original segment. */
6602 subseg_set (save_seg
, save_subseg
);
6607 /* Make the symbol extension section. */
6610 hppa_tc_make_symextn_section ()
6614 symext_chainS
*symextP
;
6618 segT save_seg
= now_seg
;
6619 subsegT save_subseg
= now_subseg
;
6621 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6624 size
= sizeof (symext_entryS
) * n
;
6626 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6628 bfd_set_section_flags (stdoutput
, symextn_sec
,
6629 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6630 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6632 /* Now, switch back to the original segment. */
6633 subseg_set (save_seg
, save_subseg
);
6637 /* Build the symbol extension section. */
6640 pa_build_symextn_section ()
6643 asection
*save_seg
= now_seg
;
6644 subsegT subseg
= (subsegT
) 0;
6645 subsegT save_subseg
= now_subseg
;
6647 seg
= subseg_new (".hppa_symextn", subseg
);
6648 bfd_set_section_flags (stdoutput
,
6650 SEC_HAS_CONTENTS
| SEC_READONLY
6651 | SEC_ALLOC
| SEC_LOAD
);
6653 subseg_set (save_seg
, save_subseg
);
6657 /* For ELF, this function serves one purpose: to setup the st_size
6658 field of STT_FUNC symbols. To do this, we need to scan the
6659 call_info structure list, determining st_size in one of two possible
6662 1. call_info->start_frag->fr_fix has the size of the fragment.
6663 This approach assumes that the function was built into a
6664 single fragment. This works for most cases, but might fail.
6665 For example, if there was a segment change in the middle of
6668 2. The st_size field is the difference in the addresses of the
6669 call_info->start_frag->fr_address field and the fr_address
6670 field of the next fragment with fr_type == rs_fill and
6674 elf_hppa_final_processing ()
6676 struct call_info
*call_info_pointer
;
6678 for (call_info_pointer
= call_info_root
;
6680 call_info_pointer
= call_info_pointer
->ci_next
)
6682 elf_symbol_type
*esym
6683 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6684 esym
->internal_elf_sym
.st_size
=
6685 S_GET_VALUE (call_info_pointer
->end_symbol
)
6686 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;