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,
599 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
600 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
601 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
602 static ssd_chain_struct
* pa_subsegment_to_subspace
PARAMS ((asection
*,
604 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
605 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
606 static void pa_ip
PARAMS ((char *));
607 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
608 long, expressionS
*, int,
609 bfd_reloc_code_real_type
, long,
611 static void md_apply_fix_1
PARAMS ((fixS
*, long));
612 static int is_end_of_statement
PARAMS ((void));
613 static int reg_name_search
PARAMS ((char *));
614 static int pa_chk_field_selector
PARAMS ((char **));
615 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
616 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
617 static void process_exit
PARAMS ((void));
618 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
619 static void pa_align_subseg
PARAMS ((asection
*, subsegT
));
620 static int log2
PARAMS ((int));
621 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
622 static unsigned int pa_stringer_aux
PARAMS ((char *));
623 static void pa_spaces_begin
PARAMS ((void));
626 /* File and gloally scoped variable declarations. */
628 /* Root and final entry in the space chain. */
629 static sd_chain_struct
*space_dict_root
;
630 static sd_chain_struct
*space_dict_last
;
632 /* The current space and subspace. */
633 static sd_chain_struct
*current_space
;
634 static ssd_chain_struct
*current_subspace
;
636 /* Root of the call_info chain. */
637 static struct call_info
*call_info_root
;
639 /* The last call_info (for functions) structure
640 seen so it can be associated with fixups and
642 static struct call_info
*last_call_info
;
644 /* The last call description (for actual calls). */
645 static struct call_desc last_call_desc
;
647 /* Relaxation isn't supported for the PA yet. */
648 const relax_typeS md_relax_table
[] = {0};
650 /* Jumps are always the same size -- one instruction. */
651 int md_short_jump_size
= 4;
652 int md_long_jump_size
= 4;
654 /* handle of the OPCODE hash table */
655 static struct hash_control
*op_hash
= NULL
;
657 /* This array holds the chars that always start a comment. If the
658 pre-processor is disabled, these aren't very useful. */
659 const char comment_chars
[] = ";";
661 /* Table of pseudo ops for the PA. FIXME -- how many of these
662 are now redundant with the overall GAS and the object file
664 const pseudo_typeS md_pseudo_table
[] =
666 /* align pseudo-ops on the PA specify the actual alignment requested,
667 not the log2 of the requested alignment. */
668 {"align", s_align_bytes
, 8},
669 {"ALIGN", s_align_bytes
, 8},
670 {"block", pa_block
, 1},
671 {"BLOCK", pa_block
, 1},
672 {"blockz", pa_block
, 0},
673 {"BLOCKZ", pa_block
, 0},
674 {"byte", pa_cons
, 1},
675 {"BYTE", pa_cons
, 1},
676 {"call", pa_call
, 0},
677 {"CALL", pa_call
, 0},
678 {"callinfo", pa_callinfo
, 0},
679 {"CALLINFO", pa_callinfo
, 0},
680 {"code", pa_code
, 0},
681 {"CODE", pa_code
, 0},
682 {"comm", pa_comm
, 0},
683 {"COMM", pa_comm
, 0},
684 {"copyright", pa_copyright
, 0},
685 {"COPYRIGHT", pa_copyright
, 0},
686 {"data", pa_data
, 0},
687 {"DATA", pa_data
, 0},
688 {"desc", pa_desc
, 0},
689 {"DESC", pa_desc
, 0},
690 {"double", pa_float_cons
, 'd'},
691 {"DOUBLE", pa_float_cons
, 'd'},
694 {"enter", pa_enter
, 0},
695 {"ENTER", pa_enter
, 0},
696 {"entry", pa_entry
, 0},
697 {"ENTRY", pa_entry
, 0},
700 {"exit", pa_exit
, 0},
701 {"EXIT", pa_exit
, 0},
702 {"export", pa_export
, 0},
703 {"EXPORT", pa_export
, 0},
704 {"fill", pa_fill
, 0},
705 {"FILL", pa_fill
, 0},
706 {"float", pa_float_cons
, 'f'},
707 {"FLOAT", pa_float_cons
, 'f'},
708 {"half", pa_cons
, 2},
709 {"HALF", pa_cons
, 2},
710 {"import", pa_import
, 0},
711 {"IMPORT", pa_import
, 0},
714 {"label", pa_label
, 0},
715 {"LABEL", pa_label
, 0},
716 {"lcomm", pa_lcomm
, 0},
717 {"LCOMM", pa_lcomm
, 0},
718 {"leave", pa_leave
, 0},
719 {"LEAVE", pa_leave
, 0},
720 {"long", pa_cons
, 4},
721 {"LONG", pa_cons
, 4},
722 {"lsym", pa_lsym
, 0},
723 {"LSYM", pa_lsym
, 0},
724 {"octa", pa_cons
, 16},
725 {"OCTA", pa_cons
, 16},
726 {"org", pa_origin
, 0},
727 {"ORG", pa_origin
, 0},
728 {"origin", pa_origin
, 0},
729 {"ORIGIN", pa_origin
, 0},
730 {"param", pa_param
, 0},
731 {"PARAM", pa_param
, 0},
732 {"proc", pa_proc
, 0},
733 {"PROC", pa_proc
, 0},
734 {"procend", pa_procend
, 0},
735 {"PROCEND", pa_procend
, 0},
736 {"quad", pa_cons
, 8},
737 {"QUAD", pa_cons
, 8},
740 {"short", pa_cons
, 2},
741 {"SHORT", pa_cons
, 2},
742 {"single", pa_float_cons
, 'f'},
743 {"SINGLE", pa_float_cons
, 'f'},
744 {"space", pa_space
, 0},
745 {"SPACE", pa_space
, 0},
746 {"spnum", pa_spnum
, 0},
747 {"SPNUM", pa_spnum
, 0},
748 {"string", pa_stringer
, 0},
749 {"STRING", pa_stringer
, 0},
750 {"stringz", pa_stringer
, 1},
751 {"STRINGZ", pa_stringer
, 1},
752 {"subspa", pa_subspace
, 0},
753 {"SUBSPA", pa_subspace
, 0},
754 {"text", pa_text
, 0},
755 {"TEXT", pa_text
, 0},
756 {"version", pa_version
, 0},
757 {"VERSION", pa_version
, 0},
758 {"word", pa_cons
, 4},
759 {"WORD", pa_cons
, 4},
763 /* This array holds the chars that only start a comment at the beginning of
764 a line. If the line seems to have the form '# 123 filename'
765 .line and .file directives will appear in the pre-processed output.
767 Note that input_file.c hand checks for '#' at the beginning of the
768 first line of the input file. This is because the compiler outputs
769 #NO_APP at the beginning of its output.
771 Also note that '/*' will always start a comment. */
772 const char line_comment_chars
[] = "#";
774 /* This array holds the characters which act as line separators. */
775 const char line_separator_chars
[] = "!";
777 /* Chars that can be used to separate mant from exp in floating point nums. */
778 const char EXP_CHARS
[] = "eE";
780 /* Chars that mean this number is a floating point constant.
781 As in 0f12.456 or 0d1.2345e12.
783 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
784 changed in read.c. Ideally it shouldn't hae to know abou it at
785 all, but nothing is ideal around here. */
786 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
788 static struct pa_it the_insn
;
790 /* Points to the end of an expression just parsed by get_expressoin
791 and friends. FIXME. This shouldn't be handled with a file-global
793 static char *expr_end
;
795 /* Nonzero if a .callinfo appeared within the current procedure. */
796 static int callinfo_found
;
798 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
799 static int within_entry_exit
;
801 /* Nonzero if the assembler has completed exit processing for the
802 current procedure. */
803 static int exit_processing_complete
;
805 /* Nonzero if the assembler is currently within a procedure definition. */
806 static int within_procedure
;
808 /* Handle on strucutre which keep track of the last symbol
809 seen in each subspace. */
810 static label_symbol_struct
*label_symbols_rootp
= NULL
;
812 /* Holds the last field selector. */
813 static int hppa_field_selector
;
815 /* Nonzero if errors are to be printed. */
816 static int print_errors
= 1;
818 /* List of registers that are pre-defined:
820 Each general register has one predefined name of the form
821 %r<REGNUM> which has the value <REGNUM>.
823 Space and control registers are handled in a similar manner,
824 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
826 Likewise for the floating point registers, but of the form
827 %fr<REGNUM>. Floating point registers have additional predefined
828 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
829 again have the value <REGNUM>.
831 Many registers also have synonyms:
833 %r26 - %r23 have %arg0 - %arg3 as synonyms
834 %r28 - %r29 have %ret0 - %ret1 as synonyms
835 %r30 has %sp as a synonym
836 %r27 has %dp as a synonym
837 %r2 has %rp as a synonym
839 Almost every control register has a synonym; they are not listed
842 The table is sorted. Suitable for searching by a binary search. */
844 static const struct pd_reg pre_defined_registers
[] =
1056 /* This table is sorted by order of the length of the string. This is
1057 so we check for <> before we check for <. If we had a <> and checked
1058 for < first, we would get a false match. */
1059 static const struct fp_cond_map fp_cond_map
[] =
1095 static const struct selector_entry selector_table
[] =
1130 /* default space and subspace dictionaries */
1132 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1133 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1135 /* pre-defined subsegments (subspaces) for the HPPA. */
1136 #define SUBSEG_CODE 0
1137 #define SUBSEG_DATA 0
1138 #define SUBSEG_LIT 1
1139 #define SUBSEG_BSS 2
1140 #define SUBSEG_UNWIND 3
1141 #define SUBSEG_GDB_STRINGS 0
1142 #define SUBSEG_GDB_SYMBOLS 1
1144 static struct default_subspace_dict pa_def_subspaces
[] =
1146 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1147 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1148 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1149 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1150 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1151 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1154 static struct default_space_dict pa_def_spaces
[] =
1156 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1157 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1158 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1161 /* Misc local definitions used by the assembler. */
1163 /* Return nonzero if the string pointed to by S potentially represents
1164 a right or left half of a FP register */
1165 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1166 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1168 /* These macros are used to maintain spaces/subspaces. */
1169 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1170 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1171 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1172 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1173 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1174 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1175 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1176 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1178 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1179 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1180 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1181 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1182 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1183 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1184 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1185 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1186 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1187 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1188 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1189 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1190 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1191 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1193 #define is_DP_relative(exp) \
1194 ((exp).X_op == O_subtract \
1195 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1197 #define is_PC_relative(exp) \
1198 ((exp).X_op == O_subtract \
1199 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1201 #define is_complex(exp) \
1202 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1204 /* Actual functions to implement the PA specific code for the assembler. */
1206 /* Returns a pointer to the label_symbol_struct for the current space.
1207 or NULL if no label_symbol_struct exists for the current space. */
1209 static label_symbol_struct
*
1212 label_symbol_struct
*label_chain
;
1213 sd_chain_struct
*space_chain
= current_space
;
1215 for (label_chain
= label_symbols_rootp
;
1217 label_chain
= label_chain
->lss_next
)
1218 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1224 /* Defines a label for the current space. If one is already defined,
1225 this function will replace it with the new label. */
1228 pa_define_label (symbol
)
1231 label_symbol_struct
*label_chain
= pa_get_label ();
1232 sd_chain_struct
*space_chain
= current_space
;
1235 label_chain
->lss_label
= symbol
;
1238 /* Create a new label entry and add it to the head of the chain. */
1240 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1241 label_chain
->lss_label
= symbol
;
1242 label_chain
->lss_space
= space_chain
;
1243 label_chain
->lss_next
= NULL
;
1245 if (label_symbols_rootp
)
1246 label_chain
->lss_next
= label_symbols_rootp
;
1248 label_symbols_rootp
= label_chain
;
1252 /* Removes a label definition for the current space.
1253 If there is no label_symbol_struct entry, then no action is taken. */
1256 pa_undefine_label ()
1258 label_symbol_struct
*label_chain
;
1259 label_symbol_struct
*prev_label_chain
= NULL
;
1260 sd_chain_struct
*space_chain
= current_space
;
1262 for (label_chain
= label_symbols_rootp
;
1264 label_chain
= label_chain
->lss_next
)
1266 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1268 /* Remove the label from the chain and free its memory. */
1269 if (prev_label_chain
)
1270 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1272 label_symbols_rootp
= label_chain
->lss_next
;
1277 prev_label_chain
= label_chain
;
1282 /* An HPPA-specific version of fix_new. This is required because the HPPA
1283 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1284 results in the creation of an instance of an hppa_fix_struct. An
1285 hppa_fix_struct stores the extra information along with a pointer to the
1286 original fixS. This is attached to the original fixup via the
1287 tc_fix_data field. */
1290 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1291 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1295 symbolS
*add_symbol
;
1299 bfd_reloc_code_real_type r_type
;
1307 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1308 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1311 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1313 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1314 new_fix
->tc_fix_data
= hppa_fix
;
1315 hppa_fix
->fx_r_type
= r_type
;
1316 hppa_fix
->fx_r_field
= r_field
;
1317 hppa_fix
->fx_r_format
= r_format
;
1318 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1321 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1323 /* If necessary call BFD backend function to attach the
1324 unwind bits to the target dependent parts of a BFD symbol.
1326 #ifdef obj_attach_unwind_info
1327 obj_attach_unwind_info (add_symbol
->bsym
, unwind_desc
);
1332 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1333 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1336 parse_cons_expression_hppa (exp
)
1339 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1343 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1344 hppa_field_selector is set by the parse_cons_expression_hppa. */
1347 cons_fix_new_hppa (frag
, where
, size
, exp
)
1353 unsigned int reloc_type
;
1355 if (is_DP_relative (*exp
))
1356 reloc_type
= R_HPPA_GOTOFF
;
1357 else if (is_complex (*exp
))
1358 reloc_type
= R_HPPA_COMPLEX
;
1360 reloc_type
= R_HPPA
;
1362 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1363 as_warn ("Invalid field selector. Assuming F%%.");
1365 fix_new_hppa (frag
, where
, size
,
1366 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1367 hppa_field_selector
, 32, 0, (char *) 0);
1369 /* Reset field selector to its default state. */
1370 hppa_field_selector
= 0;
1373 /* This function is called once, at assembler startup time. It should
1374 set up all the tables, etc. that the MD part of the assembler will need. */
1379 const char *retval
= NULL
;
1383 last_call_info
= NULL
;
1384 call_info_root
= NULL
;
1386 /* Folding of text and data segments fails miserably on the PA.
1387 Warn user and disable "-R" option. */
1390 as_warn ("-R option not supported on this target.");
1391 flag_readonly_data_in_text
= 0;
1397 op_hash
= hash_new ();
1398 if (op_hash
== NULL
)
1399 as_fatal ("Virtual memory exhausted");
1401 while (i
< NUMOPCODES
)
1403 const char *name
= pa_opcodes
[i
].name
;
1404 retval
= hash_insert (op_hash
, name
, (struct pa_opcode
*)&pa_opcodes
[i
]);
1405 if (retval
!= NULL
&& *retval
!= '\0')
1407 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1412 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1413 != pa_opcodes
[i
].match
)
1415 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1416 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1421 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1425 as_fatal ("Broken assembler. No assembly attempted.");
1427 /* SOM will change text_section. To make sure we never put
1428 anything into the old one switch to the new one now. */
1429 subseg_set (text_section
, 0);
1432 /* Called at the end of assembling a source file. Nothing to do
1433 at this point on the PA. */
1441 /* Assemble a single instruction storing it into a frag. */
1448 /* The had better be something to assemble. */
1451 /* Assemble the instruction. Results are saved into "the_insn". */
1454 /* Get somewhere to put the assembled instrution. */
1457 /* Output the opcode. */
1458 md_number_to_chars (to
, the_insn
.opcode
, 4);
1460 /* If necessary output more stuff. */
1461 if (the_insn
.reloc
!= R_HPPA_NONE
)
1462 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1463 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1464 the_insn
.reloc
, the_insn
.field_selector
,
1465 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1469 /* Do the real work for assembling a single instruction. Store results
1470 into the global "the_insn" variable.
1472 FIXME: Should define and use some functions/macros to handle
1473 various common insertions of information into the opcode. */
1479 char *error_message
= "";
1480 char *s
, c
, *argstart
, *name
, *save_s
;
1484 int reg
, s2
, s3
, m
, a
, uu
, cmpltr
, nullif
, flag
, sfu
, cond
;
1485 unsigned int im21
, im14
, im11
, im5
;
1486 unsigned long i
, opcode
;
1487 struct pa_opcode
*insn
;
1489 /* Skip to something interesting. */
1490 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1509 as_bad ("Unknown opcode: `%s'", str
);
1515 /* Convert everything into lower case. */
1518 if (isupper (*save_s
))
1519 *save_s
= tolower (*save_s
);
1523 /* Look up the opcode in the has table. */
1524 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1526 as_bad ("Unknown opcode: `%s'", str
);
1535 /* Mark the location where arguments for the instruction start, then
1536 start processing them. */
1540 /* Do some initialization. */
1541 opcode
= insn
->match
;
1542 bzero (&the_insn
, sizeof (the_insn
));
1544 the_insn
.reloc
= R_HPPA_NONE
;
1546 /* Build the opcode, checking as we go to make
1547 sure that the operands match. */
1548 for (args
= insn
->args
;; ++args
)
1553 /* End of arguments. */
1569 /* These must match exactly. */
1578 /* Handle a 5 bit register or control register field at 10. */
1581 reg
= pa_parse_number (&s
, 0);
1582 if (reg
< 32 && reg
>= 0)
1584 opcode
|= reg
<< 21;
1589 /* Handle a 5 bit register field at 15. */
1591 reg
= pa_parse_number (&s
, 0);
1592 if (reg
< 32 && reg
>= 0)
1594 opcode
|= reg
<< 16;
1599 /* Handle a 5 bit register field at 31. */
1602 reg
= pa_parse_number (&s
, 0);
1603 if (reg
< 32 && reg
>= 0)
1610 /* Handle a 5 bit field length at 31. */
1612 pa_get_absolute_expression (s
);
1613 if (the_insn
.exp
.X_op
== O_constant
)
1615 reg
= the_insn
.exp
.X_add_number
;
1616 if (reg
<= 32 && reg
> 0)
1625 /* Handle a 5 bit immediate at 15. */
1627 pa_get_absolute_expression (s
);
1628 if (the_insn
.exp
.X_add_number
> 15)
1630 as_bad ("5 bit immediate > 15. Set to 15");
1631 the_insn
.exp
.X_add_number
= 15;
1633 else if (the_insn
.exp
.X_add_number
< -16)
1635 as_bad ("5 bit immediate < -16. Set to -16");
1636 the_insn
.exp
.X_add_number
= -16;
1639 low_sign_unext (evaluate_absolute (the_insn
.exp
,
1640 the_insn
.field_selector
),
1642 opcode
|= (im5
<< 16);
1646 /* Handle a 2 bit space identifier at 17. */
1648 s2
= pa_parse_number (&s
, 0);
1649 if (s2
< 4 && s2
>= 0)
1656 /* Handle a 3 bit space identifier at 18. */
1658 s3
= pa_parse_number (&s
, 0);
1659 if (s3
< 8 && s3
>= 0)
1661 dis_assemble_3 (s3
, &s3
);
1667 /* Handle a completer for an indexing load or store. */
1672 while (*s
== ',' && i
< 2)
1675 if (strncasecmp (s
, "sm", 2) == 0)
1682 else if (strncasecmp (s
, "m", 1) == 0)
1684 else if (strncasecmp (s
, "s", 1) == 0)
1687 as_bad ("Invalid Indexed Load Completer.");
1692 as_bad ("Invalid Indexed Load Completer Syntax.");
1693 while (*s
== ' ' || *s
== '\t')
1700 /* Handle a short load/store completer. */
1707 if (strncasecmp (s
, "ma", 2) == 0)
1712 else if (strncasecmp (s
, "mb", 2) == 0)
1718 as_bad ("Invalid Short Load/Store Completer.");
1721 while (*s
== ' ' || *s
== '\t')
1727 /* Handle a stbys completer. */
1732 while (*s
== ',' && i
< 2)
1735 if (strncasecmp (s
, "m", 1) == 0)
1737 else if (strncasecmp (s
, "b", 1) == 0)
1739 else if (strncasecmp (s
, "e", 1) == 0)
1742 as_bad ("Invalid Store Bytes Short Completer");
1747 as_bad ("Invalid Store Bytes Short Completer");
1748 while (*s
== ' ' || *s
== '\t')
1754 /* Handle a non-negated compare/stubtract condition. */
1756 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1759 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1762 opcode
|= cmpltr
<< 13;
1765 /* Handle a negated or non-negated compare/subtract condition. */
1768 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1772 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1775 as_bad ("Invalid Compare/Subtract Condition.");
1780 /* Negated condition requires an opcode change. */
1784 opcode
|= cmpltr
<< 13;
1787 /* Handle a negated or non-negated add condition. */
1790 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1794 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1797 as_bad ("Invalid Compare/Subtract Condition");
1802 /* Negated condition requires an opcode change. */
1806 opcode
|= cmpltr
<< 13;
1809 /* Handle a compare/subtract condition. */
1816 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1821 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1824 as_bad ("Invalid Compare/Subtract Condition");
1828 opcode
|= cmpltr
<< 13;
1829 opcode
|= flag
<< 12;
1832 /* Handle a non-negated add condition. */
1841 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1845 if (strcmp (name
, "=") == 0)
1847 else if (strcmp (name
, "<") == 0)
1849 else if (strcmp (name
, "<=") == 0)
1851 else if (strcasecmp (name
, "nuv") == 0)
1853 else if (strcasecmp (name
, "znv") == 0)
1855 else if (strcasecmp (name
, "sv") == 0)
1857 else if (strcasecmp (name
, "od") == 0)
1859 else if (strcasecmp (name
, "n") == 0)
1861 else if (strcasecmp (name
, "tr") == 0)
1866 else if (strcasecmp (name
, "<>") == 0)
1871 else if (strcasecmp (name
, ">=") == 0)
1876 else if (strcasecmp (name
, ">") == 0)
1881 else if (strcasecmp (name
, "uv") == 0)
1886 else if (strcasecmp (name
, "vnz") == 0)
1891 else if (strcasecmp (name
, "nsv") == 0)
1896 else if (strcasecmp (name
, "ev") == 0)
1902 as_bad ("Invalid Add Condition: %s", name
);
1905 nullif
= pa_parse_nullif (&s
);
1906 opcode
|= nullif
<< 1;
1907 opcode
|= cmpltr
<< 13;
1908 opcode
|= flag
<< 12;
1911 /* Handle a logical instruction condition. */
1919 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1923 if (strcmp (name
, "=") == 0)
1925 else if (strcmp (name
, "<") == 0)
1927 else if (strcmp (name
, "<=") == 0)
1929 else if (strcasecmp (name
, "od") == 0)
1931 else if (strcasecmp (name
, "tr") == 0)
1936 else if (strcmp (name
, "<>") == 0)
1941 else if (strcmp (name
, ">=") == 0)
1946 else if (strcmp (name
, ">") == 0)
1951 else if (strcasecmp (name
, "ev") == 0)
1957 as_bad ("Invalid Logical Instruction Condition.");
1960 opcode
|= cmpltr
<< 13;
1961 opcode
|= flag
<< 12;
1964 /* Handle a unit instruction condition. */
1971 if (strncasecmp (s
, "sbz", 3) == 0)
1976 else if (strncasecmp (s
, "shz", 3) == 0)
1981 else if (strncasecmp (s
, "sdc", 3) == 0)
1986 else if (strncasecmp (s
, "sbc", 3) == 0)
1991 else if (strncasecmp (s
, "shc", 3) == 0)
1996 else if (strncasecmp (s
, "tr", 2) == 0)
2002 else if (strncasecmp (s
, "nbz", 3) == 0)
2008 else if (strncasecmp (s
, "nhz", 3) == 0)
2014 else if (strncasecmp (s
, "ndc", 3) == 0)
2020 else if (strncasecmp (s
, "nbc", 3) == 0)
2026 else if (strncasecmp (s
, "nhc", 3) == 0)
2033 as_bad ("Invalid Logical Instruction Condition.");
2035 opcode
|= cmpltr
<< 13;
2036 opcode
|= flag
<< 12;
2039 /* Handle a shift/extract/deposit condition. */
2047 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2051 if (strcmp (name
, "=") == 0)
2053 else if (strcmp (name
, "<") == 0)
2055 else if (strcasecmp (name
, "od") == 0)
2057 else if (strcasecmp (name
, "tr") == 0)
2059 else if (strcmp (name
, "<>") == 0)
2061 else if (strcmp (name
, ">=") == 0)
2063 else if (strcasecmp (name
, "ev") == 0)
2065 /* Handle movb,n. Put things back the way they were.
2066 This includes moving s back to where it started. */
2067 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
2074 as_bad ("Invalid Shift/Extract/Deposit Condition.");
2077 opcode
|= cmpltr
<< 13;
2080 /* Handle bvb and bb conditions. */
2086 if (strncmp (s
, "<", 1) == 0)
2091 else if (strncmp (s
, ">=", 2) == 0)
2097 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2099 opcode
|= cmpltr
<< 13;
2102 /* Handle a 5 bit immediate at 31. */
2105 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2106 the_insn
.field_selector
),
2112 /* Handle an unsigned 5 bit immediate at 31. */
2115 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2118 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2126 /* Handle an unsigned 5 bit immediate at 15. */
2129 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2132 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2136 opcode
|= im5
<< 16;
2140 /* Handle a 11 bit immediate at 31. */
2142 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2144 if (the_insn
.exp
.X_op
== O_constant
)
2146 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2147 the_insn
.field_selector
),
2153 if (is_DP_relative (the_insn
.exp
))
2154 the_insn
.reloc
= R_HPPA_GOTOFF
;
2155 else if (is_PC_relative (the_insn
.exp
))
2156 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2157 else if (is_complex (the_insn
.exp
))
2158 the_insn
.reloc
= R_HPPA_COMPLEX
;
2160 the_insn
.reloc
= R_HPPA
;
2161 the_insn
.format
= 11;
2166 /* Handle a 14 bit immediate at 31. */
2168 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2170 if (the_insn
.exp
.X_op
== O_constant
)
2172 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2173 the_insn
.field_selector
),
2175 if (the_insn
.field_selector
== e_rsel
)
2176 opcode
|= (im14
& 0xfff);
2182 if (is_DP_relative (the_insn
.exp
))
2183 the_insn
.reloc
= R_HPPA_GOTOFF
;
2184 else if (is_PC_relative (the_insn
.exp
))
2185 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2186 else if (is_complex (the_insn
.exp
))
2187 the_insn
.reloc
= R_HPPA_COMPLEX
;
2189 the_insn
.reloc
= R_HPPA
;
2190 the_insn
.format
= 14;
2195 /* Handle a 21 bit immediate at 31. */
2197 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2199 if (the_insn
.exp
.X_op
== O_constant
)
2201 dis_assemble_21 (evaluate_absolute (the_insn
.exp
,
2202 the_insn
.field_selector
),
2208 if (is_DP_relative (the_insn
.exp
))
2209 the_insn
.reloc
= R_HPPA_GOTOFF
;
2210 else if (is_PC_relative (the_insn
.exp
))
2211 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2212 else if (is_complex (the_insn
.exp
))
2213 the_insn
.reloc
= R_HPPA_COMPLEX
;
2215 the_insn
.reloc
= R_HPPA
;
2216 the_insn
.format
= 21;
2221 /* Handle a nullification completer for branch instructions. */
2223 nullif
= pa_parse_nullif (&s
);
2224 opcode
|= nullif
<< 1;
2227 /* Handle a 12 bit branch displacement. */
2229 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2232 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L0\001"))
2234 unsigned int w1
, w
, result
;
2236 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 12,
2238 dis_assemble_12 (result
, &w1
, &w
);
2239 opcode
|= ((w1
<< 2) | w
);
2243 if (is_complex (the_insn
.exp
))
2244 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2246 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2247 the_insn
.format
= 12;
2248 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2249 bzero (&last_call_desc
, sizeof (struct call_desc
));
2254 /* Handle a 17 bit branch displacement. */
2256 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2259 if (the_insn
.exp
.X_add_symbol
)
2261 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2264 unsigned int w2
, w1
, w
, result
;
2266 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2268 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2269 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2273 if (is_complex (the_insn
.exp
))
2274 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2276 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2277 the_insn
.format
= 17;
2278 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2279 bzero (&last_call_desc
, sizeof (struct call_desc
));
2284 unsigned int w2
, w1
, w
, result
;
2286 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2287 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2288 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2293 /* Handle an absolute 17 bit branch target. */
2295 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2298 if (the_insn
.exp
.X_add_symbol
)
2300 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2303 unsigned int w2
, w1
, w
, result
;
2305 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2307 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2308 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2312 if (is_complex (the_insn
.exp
))
2313 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2315 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2316 the_insn
.format
= 17;
2321 unsigned int w2
, w1
, w
, result
;
2323 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2324 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2325 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2330 /* Handle a 5 bit shift count at 26. */
2333 if (the_insn
.exp
.X_op
== O_constant
)
2334 opcode
|= (((31 - the_insn
.exp
.X_add_number
) & 0x1f) << 5);
2338 /* Handle a 5 bit bit position at 26. */
2341 if (the_insn
.exp
.X_op
== O_constant
)
2342 opcode
|= (the_insn
.exp
.X_add_number
& 0x1f) << 5;
2346 /* Handle a 5 bit immediate at 10. */
2349 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2352 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2356 opcode
|= im5
<< 21;
2360 /* Handle a 13 bit immediate at 18. */
2362 pa_get_absolute_expression (s
);
2363 if (the_insn
.exp
.X_op
== O_constant
)
2364 opcode
|= (the_insn
.exp
.X_add_number
& 0x1fff) << 13;
2368 /* Handle a system control completer. */
2370 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2379 while (*s
== ' ' || *s
== '\t')
2383 /* Handle a 26 bit immediate at 31. */
2385 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2387 if (the_insn
.exp
.X_op
== O_constant
)
2389 opcode
|= ((evaluate_absolute (the_insn
.exp
,
2390 the_insn
.field_selector
)
2394 as_bad ("Invalid DIAG operand");
2398 /* Handle a 3 bit SFU identifier at 25. */
2400 sfu
= pa_parse_number (&s
, 0);
2401 if ((sfu
> 7) || (sfu
< 0))
2402 as_bad ("Invalid SFU identifier: %02x", sfu
);
2403 opcode
|= (sfu
& 7) << 6;
2406 /* We don't support any of these. FIXME. */
2413 /* Handle a source FP operand format completer. */
2415 flag
= pa_parse_fp_format (&s
);
2416 opcode
|= (int) flag
<< 11;
2417 the_insn
.fpof1
= flag
;
2420 /* Handle a destination FP operand format completer. */
2423 /* pa_parse_format needs the ',' prefix. */
2425 flag
= pa_parse_fp_format (&s
);
2426 opcode
|= (int) flag
<< 13;
2427 the_insn
.fpof2
= flag
;
2430 /* Handle FP compare conditions. */
2432 cond
= pa_parse_fp_cmp_cond (&s
);
2436 /* Handle L/R register halves like 't'. */
2439 struct pa_89_fp_reg_struct result
;
2441 pa_parse_number (&s
, &result
);
2442 if (result
.number_part
< 32 && result
.number_part
>= 0)
2444 opcode
|= (result
.number_part
& 0x1f);
2446 /* 0x30 opcodes are FP arithmetic operation opcodes
2447 and need to be turned into 0x38 opcodes. This
2448 is not necessary for loads/stores. */
2449 if (need_89_opcode (&the_insn
, &result
))
2451 if ((opcode
& 0xfc000000) == 0x30000000)
2453 opcode
|= (result
.l_r_select
& 1) << 6;
2458 opcode
|= (result
.l_r_select
& 1) << 6;
2466 /* Handle L/R register halves like 'b'. */
2469 struct pa_89_fp_reg_struct result
;
2471 pa_parse_number (&s
, &result
);
2472 if (result
.number_part
< 32 && result
.number_part
>= 0)
2474 opcode
|= (result
.number_part
& 0x1f) << 21;
2475 if (need_89_opcode (&the_insn
, &result
))
2477 opcode
|= (result
.l_r_select
& 1) << 7;
2485 /* Handle L/R register halves like 'x'. */
2488 struct pa_89_fp_reg_struct result
;
2490 pa_parse_number (&s
, &result
);
2491 if (result
.number_part
< 32 && result
.number_part
>= 0)
2493 opcode
|= (result
.number_part
& 0x1f) << 16;
2494 if (need_89_opcode (&the_insn
, &result
))
2496 opcode
|= (result
.l_r_select
& 1) << 12;
2504 /* Handle a 5 bit register field at 10. */
2507 struct pa_89_fp_reg_struct result
;
2510 status
= pa_parse_number (&s
, &result
);
2511 if (result
.number_part
< 32 && result
.number_part
>= 0)
2513 if (the_insn
.fpof1
== SGL
)
2515 result
.number_part
&= 0xF;
2516 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2518 opcode
|= result
.number_part
<< 21;
2524 /* Handle a 5 bit register field at 15. */
2527 struct pa_89_fp_reg_struct result
;
2530 status
= pa_parse_number (&s
, &result
);
2531 if (result
.number_part
< 32 && result
.number_part
>= 0)
2533 if (the_insn
.fpof1
== SGL
)
2535 result
.number_part
&= 0xF;
2536 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2538 opcode
|= result
.number_part
<< 16;
2544 /* Handle a 5 bit register field at 31. */
2547 struct pa_89_fp_reg_struct result
;
2550 status
= pa_parse_number (&s
, &result
);
2551 if (result
.number_part
< 32 && result
.number_part
>= 0)
2553 if (the_insn
.fpof1
== SGL
)
2555 result
.number_part
&= 0xF;
2556 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2558 opcode
|= result
.number_part
;
2564 /* Handle a 5 bit register field at 20. */
2567 struct pa_89_fp_reg_struct result
;
2570 status
= pa_parse_number (&s
, &result
);
2571 if (result
.number_part
< 32 && result
.number_part
>= 0)
2573 if (the_insn
.fpof1
== SGL
)
2575 result
.number_part
&= 0xF;
2576 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2578 opcode
|= result
.number_part
<< 11;
2584 /* Handle a 5 bit register field at 25. */
2587 struct pa_89_fp_reg_struct result
;
2590 status
= pa_parse_number (&s
, &result
);
2591 if (result
.number_part
< 32 && result
.number_part
>= 0)
2593 if (the_insn
.fpof1
== SGL
)
2595 result
.number_part
&= 0xF;
2596 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2598 opcode
|= result
.number_part
<< 6;
2604 /* Handle a floating point operand format at 26.
2605 Only allows single and double precision. */
2607 flag
= pa_parse_fp_format (&s
);
2613 the_insn
.fpof1
= flag
;
2619 as_bad ("Invalid Floating Point Operand Format.");
2629 /* Check if the args matched. */
2632 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2633 && !strcmp (insn
->name
, insn
[1].name
))
2641 as_bad ("Invalid operands %s", error_message
);
2648 the_insn
.opcode
= opcode
;
2652 /* Turn a string in input_line_pointer into a floating point constant of type
2653 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2654 emitted is stored in *sizeP . An error message or NULL is returned. */
2656 #define MAX_LITTLENUMS 6
2659 md_atof (type
, litP
, sizeP
)
2665 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2666 LITTLENUM_TYPE
*wordP
;
2698 return "Bad call to MD_ATOF()";
2700 t
= atof_ieee (input_line_pointer
, type
, words
);
2702 input_line_pointer
= t
;
2703 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2704 for (wordP
= words
; prec
--;)
2706 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2707 litP
+= sizeof (LITTLENUM_TYPE
);
2712 /* Write out big-endian. */
2715 md_number_to_chars (buf
, val
, n
)
2737 /* Translate internal representation of relocation info to BFD target
2741 tc_gen_reloc (section
, fixp
)
2746 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2747 bfd_reloc_code_real_type code
;
2748 static int unwind_reloc_fixp_cnt
= 0;
2749 static arelent
*unwind_reloc_entryP
= NULL
;
2750 static arelent
*no_relocs
= NULL
;
2752 bfd_reloc_code_real_type
**codes
;
2756 if (fixp
->fx_addsy
== 0)
2758 assert (hppa_fixp
!= 0);
2759 assert (section
!= 0);
2762 /* Yuk. I would really like to push all this ELF specific unwind
2763 crud into BFD and the linker. That's how SOM does it -- and
2764 if we could make ELF emulate that then we could share more code
2765 in GAS (and potentially a gnu-linker later).
2767 Unwind section relocations are handled in a special way.
2768 The relocations for the .unwind section are originally
2769 built in the usual way. That is, for each unwind table
2770 entry there are two relocations: one for the beginning of
2771 the function and one for the end.
2773 The first time we enter this function we create a
2774 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2775 of the relocation is initialized to 0. Each additional
2776 pair of times this function is called for the unwind
2777 section represents an additional unwind table entry. Thus,
2778 the addend of the relocation should end up to be the number
2779 of unwind table entries. */
2780 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2782 if (unwind_reloc_entryP
== NULL
)
2784 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2786 assert (reloc
!= 0);
2787 unwind_reloc_entryP
= reloc
;
2788 unwind_reloc_fixp_cnt
++;
2789 unwind_reloc_entryP
->address
2790 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2791 /* A pointer to any function will do. We only
2792 need one to tell us what section the unwind
2793 relocations are for. */
2794 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2795 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2796 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2797 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2798 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2799 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2800 sizeof (arelent
*) * 2);
2801 assert (relocs
!= 0);
2802 relocs
[0] = unwind_reloc_entryP
;
2806 unwind_reloc_fixp_cnt
++;
2807 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2813 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2814 assert (reloc
!= 0);
2816 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2817 codes
= hppa_gen_reloc_type (stdoutput
,
2819 hppa_fixp
->fx_r_format
,
2820 hppa_fixp
->fx_r_field
);
2822 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2825 relocs
= (arelent
**)
2826 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2827 assert (relocs
!= 0);
2829 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2830 sizeof (arelent
) * n_relocs
);
2832 assert (reloc
!= 0);
2834 for (i
= 0; i
< n_relocs
; i
++)
2835 relocs
[i
] = &reloc
[i
];
2837 relocs
[n_relocs
] = NULL
;
2840 switch (fixp
->fx_r_type
)
2842 case R_HPPA_COMPLEX
:
2843 case R_HPPA_COMPLEX_PCREL_CALL
:
2844 case R_HPPA_COMPLEX_ABS_CALL
:
2845 assert (n_relocs
== 5);
2847 for (i
= 0; i
< n_relocs
; i
++)
2849 reloc
[i
].sym_ptr_ptr
= NULL
;
2850 reloc
[i
].address
= 0;
2851 reloc
[i
].addend
= 0;
2852 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2853 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2856 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2857 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2858 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2860 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2861 reloc
[3].addend
= fixp
->fx_addnumber
;
2862 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2863 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2864 reloc
[1].addend
= fixp
->fx_addnumber
;
2869 assert (n_relocs
== 1);
2873 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2874 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2875 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2876 reloc
->addend
= 0; /* default */
2878 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2880 /* Now, do any processing that is dependent on the relocation type. */
2883 case R_HPPA_PLABEL_32
:
2884 case R_HPPA_PLABEL_11
:
2885 case R_HPPA_PLABEL_14
:
2886 case R_HPPA_PLABEL_L21
:
2887 case R_HPPA_PLABEL_R11
:
2888 case R_HPPA_PLABEL_R14
:
2889 /* For plabel relocations, the addend of the
2890 relocation should be either 0 (no static link) or 2
2891 (static link required).
2893 FIXME: assume that fx_addnumber contains this
2895 reloc
->addend
= fixp
->fx_addnumber
;
2898 case R_HPPA_ABS_CALL_11
:
2899 case R_HPPA_ABS_CALL_14
:
2900 case R_HPPA_ABS_CALL_17
:
2901 case R_HPPA_ABS_CALL_L21
:
2902 case R_HPPA_ABS_CALL_R11
:
2903 case R_HPPA_ABS_CALL_R14
:
2904 case R_HPPA_ABS_CALL_R17
:
2905 case R_HPPA_ABS_CALL_LS21
:
2906 case R_HPPA_ABS_CALL_RS11
:
2907 case R_HPPA_ABS_CALL_RS14
:
2908 case R_HPPA_ABS_CALL_RS17
:
2909 case R_HPPA_ABS_CALL_LD21
:
2910 case R_HPPA_ABS_CALL_RD11
:
2911 case R_HPPA_ABS_CALL_RD14
:
2912 case R_HPPA_ABS_CALL_RD17
:
2913 case R_HPPA_ABS_CALL_LR21
:
2914 case R_HPPA_ABS_CALL_RR14
:
2915 case R_HPPA_ABS_CALL_RR17
:
2917 case R_HPPA_PCREL_CALL_11
:
2918 case R_HPPA_PCREL_CALL_14
:
2919 case R_HPPA_PCREL_CALL_17
:
2920 case R_HPPA_PCREL_CALL_L21
:
2921 case R_HPPA_PCREL_CALL_R11
:
2922 case R_HPPA_PCREL_CALL_R14
:
2923 case R_HPPA_PCREL_CALL_R17
:
2924 case R_HPPA_PCREL_CALL_LS21
:
2925 case R_HPPA_PCREL_CALL_RS11
:
2926 case R_HPPA_PCREL_CALL_RS14
:
2927 case R_HPPA_PCREL_CALL_RS17
:
2928 case R_HPPA_PCREL_CALL_LD21
:
2929 case R_HPPA_PCREL_CALL_RD11
:
2930 case R_HPPA_PCREL_CALL_RD14
:
2931 case R_HPPA_PCREL_CALL_RD17
:
2932 case R_HPPA_PCREL_CALL_LR21
:
2933 case R_HPPA_PCREL_CALL_RR14
:
2934 case R_HPPA_PCREL_CALL_RR17
:
2935 /* The constant is stored in the instruction. */
2936 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2939 reloc
->addend
= fixp
->fx_addnumber
;
2946 /* Preliminary relocation handling for SOM. Needs to handle
2947 COMPLEX relocations (yes, I've seen them occur) and it will
2948 need to handle R_ENTRY/R_EXIT relocations in the very near future
2949 (for generating unwinds). */
2950 switch (fixp
->fx_r_type
)
2952 case R_HPPA_COMPLEX
:
2953 case R_HPPA_COMPLEX_PCREL_CALL
:
2954 case R_HPPA_COMPLEX_ABS_CALL
:
2958 assert (n_relocs
== 1);
2962 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2963 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2964 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2971 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2974 reloc
->addend
= fixp
->fx_addnumber
;
2984 /* Process any machine dependent frag types. */
2987 md_convert_frag (abfd
, sec
, fragP
)
2989 register asection
*sec
;
2990 register fragS
*fragP
;
2992 unsigned int address
;
2994 if (fragP
->fr_type
== rs_machine_dependent
)
2996 switch ((int) fragP
->fr_subtype
)
2999 fragP
->fr_type
= rs_fill
;
3000 know (fragP
->fr_var
== 1);
3001 know (fragP
->fr_next
);
3002 address
= fragP
->fr_address
+ fragP
->fr_fix
;
3003 if (address
% fragP
->fr_offset
)
3006 fragP
->fr_next
->fr_address
3011 fragP
->fr_offset
= 0;
3017 /* Round up a section size to the appropriate boundary. */
3020 md_section_align (segment
, size
)
3024 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3025 int align2
= (1 << align
) - 1;
3027 return (size
+ align2
) & ~align2
;
3031 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3033 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3035 addressT from_addr
, to_addr
;
3039 fprintf (stderr
, "pa_create_short_jmp\n");
3043 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3045 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3047 addressT from_addr
, to_addr
;
3051 fprintf (stderr
, "pa_create_long_jump\n");
3055 /* Return the approximate size of a frag before relaxation has occurred. */
3057 md_estimate_size_before_relax (fragP
, segment
)
3058 register fragS
*fragP
;
3065 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3071 /* Parse machine dependent options. There are none on the PA. */
3073 md_parse_option (argP
, cntP
, vecP
)
3081 /* We have no need to default values of symbols. */
3084 md_undefined_symbol (name
)
3090 /* Parse an operand that is machine-specific.
3091 We just return without modifying the expression as we have nothing
3095 md_operand (expressionP
)
3096 expressionS
*expressionP
;
3100 /* Helper function for md_apply_fix. Actually determine if the fix
3101 can be applied, and if so, apply it.
3103 If a fix is applied, then set fx_addsy to NULL which indicates
3104 the fix was applied and need not be emitted into the object file. */
3107 md_apply_fix_1 (fixP
, val
)
3111 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3112 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
3113 long new_val
, result
;
3114 unsigned int w1
, w2
, w
;
3116 /* SOM uses R_HPPA_ENTRY and R_HPPA_EXIT relocations which can
3117 never be "applied". They must always be emitted. */
3119 if (fixP
->fx_r_type
== R_HPPA_ENTRY
3120 || fixP
->fx_r_type
== R_HPPA_EXIT
)
3124 /* There should have been an HPPA specific fixup associated
3125 with the GAS fixup. */
3128 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3129 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3131 /* Sanity check the fixup type. */
3132 /* Is this really necessary? */
3133 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3136 /* Remember this value for emit_reloc. FIXME, is this braindamage
3137 documented anywhere!?! */
3138 fixP
->fx_addnumber
= val
;
3140 /* Check if this is an undefined symbol. No relocation can
3141 possibly be performed in this case. */
3142 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3144 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3149 /* Handle all opcodes with the 'j' operand type. */
3151 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3153 /* Mask off 14 bits to be changed. */
3154 bfd_put_32 (stdoutput
,
3155 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3157 low_sign_unext (new_val
, 14, &result
);
3160 /* Handle all opcodes with the 'k' operand type. */
3162 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3164 /* Mask off 21 bits to be changed. */
3165 bfd_put_32 (stdoutput
,
3166 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3168 dis_assemble_21 (new_val
, &result
);
3171 /* Handle all the opcodes with the 'i' operand type. */
3173 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3175 /* Mask off 11 bits to be changed. */
3176 bfd_put_32 (stdoutput
,
3177 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3179 low_sign_unext (new_val
, 11, &result
);
3182 /* Handle all the opcodes with the 'w' operand type. */
3184 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3186 /* Mask off 11 bits to be changed. */
3187 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3188 bfd_put_32 (stdoutput
,
3189 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3192 dis_assemble_12 (result
, &w1
, &w
);
3193 result
= ((w1
<< 2) | w
);
3194 fixP
->fx_addsy
= NULL
;
3197 #define too_far(VAL, NUM_BITS) \
3198 (((int)(VAL) > (1 << (NUM_BITS)) - 1) || ((int)(VAL) < (-1 << (NUM_BITS))))
3200 #define stub_needed(CALLER, CALLEE) \
3201 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3203 /* Handle some of the opcodes with the 'W' operand type. */
3205 /* If a long-call stub or argument relocation stub is
3206 needed, then we can not apply this relocation, instead
3207 the linker must handle it. */
3208 if (too_far (val
, 18)
3209 || stub_needed (((obj_symbol_type
*)
3210 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3211 hppa_fixP
->fx_arg_reloc
))
3214 /* No stubs were needed, we can perform this relocation. */
3215 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3217 /* Mask off 17 bits to be changed. */
3218 bfd_put_32 (stdoutput
,
3219 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3221 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3222 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3223 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3224 fixP
->fx_addsy
= NULL
;
3232 /* These are ELF specific relocations. ELF unfortunately
3233 handles unwinds in a completely different manner. */
3234 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3235 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3236 result
= fixP
->fx_addnumber
;
3241 fixP
->fx_addnumber
= fixP
->fx_offset
;
3242 bfd_put_32 (stdoutput
, 0, buf
);
3251 as_bad ("bad relocation type/fmt: 0x%02x/0x%02x",
3252 fixP
->fx_r_type
, fmt
);
3256 /* Insert the relocation. */
3257 buf
[0] |= (result
& 0xff000000) >> 24;
3258 buf
[1] |= (result
& 0x00ff0000) >> 16;
3259 buf
[2] |= (result
& 0x0000ff00) >> 8;
3260 buf
[3] |= result
& 0x000000ff;
3263 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3264 (unsigned int) fixP
, fixP
->fx_r_type
);
3267 /* Apply a fix into a frag's data (if possible). */
3270 md_apply_fix (fixP
, valp
)
3274 md_apply_fix_1 (fixP
, (long) *valp
);
3278 /* Exactly what point is a PC-relative offset relative TO?
3279 On the PA, they're relative to the address of the offset. */
3282 md_pcrel_from (fixP
)
3285 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3288 /* Return nonzero if the input line pointer is at the end of
3292 is_end_of_statement ()
3294 return ((*input_line_pointer
== '\n')
3295 || (*input_line_pointer
== ';')
3296 || (*input_line_pointer
== '!'));
3299 /* Read a number from S. The number might come in one of many forms,
3300 the most common will be a hex or decimal constant, but it could be
3301 a pre-defined register (Yuk!), or an absolute symbol.
3303 Return a number or -1 for failure.
3305 When parsing PA-89 FP register numbers RESULT will be
3306 the address of a structure to return information about
3307 L/R half of FP registers, store results there as appropriate.
3309 pa_parse_number can not handle negative constants and will fail
3310 horribly if it is passed such a constant. */
3313 pa_parse_number (s
, result
)
3315 struct pa_89_fp_reg_struct
*result
;
3324 /* Skip whitespace before the number. */
3325 while (*p
== ' ' || *p
== '\t')
3328 /* Store info in RESULT if requested by caller. */
3331 result
->number_part
= -1;
3332 result
->l_r_select
= -1;
3338 /* Looks like a number. */
3341 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3343 /* The number is specified in hex. */
3345 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3346 || ((*p
>= 'A') && (*p
<= 'F')))
3349 num
= num
* 16 + *p
- '0';
3350 else if (*p
>= 'a' && *p
<= 'f')
3351 num
= num
* 16 + *p
- 'a' + 10;
3353 num
= num
* 16 + *p
- 'A' + 10;
3359 /* The number is specified in decimal. */
3360 while (isdigit (*p
))
3362 num
= num
* 10 + *p
- '0';
3367 /* Store info in RESULT if requested by the caller. */
3370 result
->number_part
= num
;
3372 if (IS_R_SELECT (p
))
3374 result
->l_r_select
= 1;
3377 else if (IS_L_SELECT (p
))
3379 result
->l_r_select
= 0;
3383 result
->l_r_select
= 0;
3388 /* The number might be a predefined register. */
3393 /* Tege hack: Special case for general registers as the general
3394 code makes a binary search with case translation, and is VERY
3399 if (*p
== 'e' && *(p
+ 1) == 't'
3400 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3403 num
= *p
- '0' + 28;
3411 else if (!isdigit (*p
))
3414 as_bad ("Undefined register: '%s'.", name
);
3420 num
= num
* 10 + *p
++ - '0';
3421 while (isdigit (*p
));
3426 /* Do a normal register search. */
3427 while (is_part_of_name (c
))
3433 status
= reg_name_search (name
);
3439 as_bad ("Undefined register: '%s'.", name
);
3445 /* Store info in RESULT if requested by caller. */
3448 result
->number_part
= num
;
3449 if (IS_R_SELECT (p
- 1))
3450 result
->l_r_select
= 1;
3451 else if (IS_L_SELECT (p
- 1))
3452 result
->l_r_select
= 0;
3454 result
->l_r_select
= 0;
3459 /* And finally, it could be a symbol in the absolute section which
3460 is effectively a constant. */
3464 while (is_part_of_name (c
))
3470 if ((sym
= symbol_find (name
)) != NULL
)
3472 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3473 num
= S_GET_VALUE (sym
);
3477 as_bad ("Non-absolute symbol: '%s'.", name
);
3483 /* There is where we'd come for an undefined symbol
3484 or for an empty string. For an empty string we
3485 will return zero. That's a concession made for
3486 compatability with the braindamaged HP assemblers. */
3492 as_bad ("Undefined absolute constant: '%s'.", name
);
3498 /* Store info in RESULT if requested by caller. */
3501 result
->number_part
= num
;
3502 if (IS_R_SELECT (p
- 1))
3503 result
->l_r_select
= 1;
3504 else if (IS_L_SELECT (p
- 1))
3505 result
->l_r_select
= 0;
3507 result
->l_r_select
= 0;
3515 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3517 /* Given NAME, find the register number associated with that name, return
3518 the integer value associated with the given name or -1 on failure. */
3521 reg_name_search (name
)
3524 int middle
, low
, high
;
3527 high
= REG_NAME_CNT
- 1;
3531 middle
= (low
+ high
) / 2;
3532 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3537 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3540 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3541 return (pre_defined_registers
[middle
].value
);
3547 /* Return nonzero if the given INSN and L/R information will require
3548 a new PA-89 opcode. */
3551 need_89_opcode (insn
, result
)
3553 struct pa_89_fp_reg_struct
*result
;
3555 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3561 /* Parse a condition for a fcmp instruction. Return the numerical
3562 code associated with the condition. */
3565 pa_parse_fp_cmp_cond (s
)
3572 for (i
= 0; i
< 32; i
++)
3574 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3575 strlen (fp_cond_map
[i
].string
)) == 0)
3577 cond
= fp_cond_map
[i
].cond
;
3578 *s
+= strlen (fp_cond_map
[i
].string
);
3579 while (**s
== ' ' || **s
== '\t')
3585 as_bad ("Invalid FP Compare Condition: %c", **s
);
3589 /* Parse an FP operand format completer returning the completer
3592 static fp_operand_format
3593 pa_parse_fp_format (s
)
3602 if (strncasecmp (*s
, "sgl", 3) == 0)
3607 else if (strncasecmp (*s
, "dbl", 3) == 0)
3612 else if (strncasecmp (*s
, "quad", 4) == 0)
3619 format
= ILLEGAL_FMT
;
3620 as_bad ("Invalid FP Operand Format: %3s", *s
);
3623 while (**s
== ' ' || **s
== '\t' || **s
== 0)
3629 /* Convert from a selector string into a selector type. */
3632 pa_chk_field_selector (str
)
3636 const struct selector_entry
*tablep
;
3640 /* Read past any whitespace. */
3641 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3644 /* Yuk. Looks like a linear search through the table. With the
3645 frequence of some selectors it might make sense to sort the
3647 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3649 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3651 *str
+= strlen (tablep
->prefix
);
3652 selector
= tablep
->field_selector
;
3659 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3662 get_expression (str
)
3668 save_in
= input_line_pointer
;
3669 input_line_pointer
= str
;
3670 seg
= expression (&the_insn
.exp
);
3671 if (!(seg
== absolute_section
3672 || seg
== undefined_section
3673 || SEG_NORMAL (seg
)))
3675 as_warn ("Bad segment in expression.");
3676 expr_end
= input_line_pointer
;
3677 input_line_pointer
= save_in
;
3680 expr_end
= input_line_pointer
;
3681 input_line_pointer
= save_in
;
3685 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3687 pa_get_absolute_expression (str
)
3692 save_in
= input_line_pointer
;
3693 input_line_pointer
= str
;
3694 expression (&the_insn
.exp
);
3695 if (the_insn
.exp
.X_op
!= O_constant
)
3697 as_warn ("Bad segment (should be absolute).");
3698 expr_end
= input_line_pointer
;
3699 input_line_pointer
= save_in
;
3702 expr_end
= input_line_pointer
;
3703 input_line_pointer
= save_in
;
3707 /* Evaluate an absolute expression EXP which may be modified by
3708 the selector FIELD_SELECTOR. Return the value of the expression. */
3710 evaluate_absolute (exp
, field_selector
)
3716 value
= exp
.X_add_number
;
3718 switch (field_selector
)
3724 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3726 if (value
& 0x00000400)
3728 value
= (value
& 0xfffff800) >> 11;
3731 /* Sign extend from bit 21. */
3733 if (value
& 0x00000400)
3734 value
|= 0xfffff800;
3739 /* Arithmetic shift right 11 bits. */
3741 value
= (value
& 0xfffff800) >> 11;
3744 /* Set bits 0-20 to zero. */
3746 value
= value
& 0x7ff;
3749 /* Add 0x800 and arithmetic shift right 11 bits. */
3754 value
= (value
& 0xfffff800) >> 11;
3757 /* Set bitgs 0-21 to one. */
3759 value
|= 0xfffff800;
3762 /* This had better get fixed. It looks like we're quickly moving
3769 BAD_CASE (field_selector
);
3775 /* Given an argument location specification return the associated
3776 argument location number. */
3779 pa_build_arg_reloc (type_name
)
3783 if (strncasecmp (type_name
, "no", 2) == 0)
3785 if (strncasecmp (type_name
, "gr", 2) == 0)
3787 else if (strncasecmp (type_name
, "fr", 2) == 0)
3789 else if (strncasecmp (type_name
, "fu", 2) == 0)
3792 as_bad ("Invalid argument location: %s\n", type_name
);
3797 /* Encode and return an argument relocation specification for
3798 the given register in the location specified by arg_reloc. */
3801 pa_align_arg_reloc (reg
, arg_reloc
)
3803 unsigned int arg_reloc
;
3805 unsigned int new_reloc
;
3807 new_reloc
= arg_reloc
;
3823 as_bad ("Invalid argument description: %d", reg
);
3829 /* Parse a PA nullification completer (,n). Return nonzero if the
3830 completer was found; return zero if no completer was found. */
3842 if (strncasecmp (*s
, "n", 1) == 0)
3846 as_bad ("Invalid Nullification: (%c)", **s
);
3851 while (**s
== ' ' || **s
== '\t')
3857 /* Parse a non-negated compare/subtract completer returning the
3858 number (for encoding in instrutions) of the given completer.
3860 ISBRANCH specifies whether or not this is parsing a condition
3861 completer for a branch (vs a nullification completer for a
3862 computational instruction. */
3865 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3870 char *name
= *s
+ 1;
3878 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3882 if (strcmp (name
, "=") == 0)
3886 else if (strcmp (name
, "<") == 0)
3890 else if (strcmp (name
, "<=") == 0)
3894 else if (strcmp (name
, "<<") == 0)
3898 else if (strcmp (name
, "<<=") == 0)
3902 else if (strcasecmp (name
, "sv") == 0)
3906 else if (strcasecmp (name
, "od") == 0)
3910 /* If we have something like addb,n then there is no condition
3912 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3924 while (**s
== ' ' || **s
== '\t')
3928 /* Reset pointers if this was really a ,n for a branch instruction. */
3929 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3935 /* Parse a negated compare/subtract completer returning the
3936 number (for encoding in instrutions) of the given completer.
3938 ISBRANCH specifies whether or not this is parsing a condition
3939 completer for a branch (vs a nullification completer for a
3940 computational instruction. */
3943 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3948 char *name
= *s
+ 1;
3956 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3960 if (strcasecmp (name
, "tr") == 0)
3964 else if (strcmp (name
, "<>") == 0)
3968 else if (strcmp (name
, ">=") == 0)
3972 else if (strcmp (name
, ">") == 0)
3976 else if (strcmp (name
, ">>=") == 0)
3980 else if (strcmp (name
, ">>") == 0)
3984 else if (strcasecmp (name
, "nsv") == 0)
3988 else if (strcasecmp (name
, "ev") == 0)
3992 /* If we have something like addb,n then there is no condition
3994 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4006 while (**s
== ' ' || **s
== '\t')
4010 /* Reset pointers if this was really a ,n for a branch instruction. */
4011 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4017 /* Parse a non-negated addition completer returning the number
4018 (for encoding in instrutions) of the given completer.
4020 ISBRANCH specifies whether or not this is parsing a condition
4021 completer for a branch (vs a nullification completer for a
4022 computational instruction. */
4025 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
4030 char *name
= *s
+ 1;
4038 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4042 if (strcmp (name
, "=") == 0)
4046 else if (strcmp (name
, "<") == 0)
4050 else if (strcmp (name
, "<=") == 0)
4054 else if (strcasecmp (name
, "nuv") == 0)
4058 else if (strcasecmp (name
, "znv") == 0)
4062 else if (strcasecmp (name
, "sv") == 0)
4066 else if (strcasecmp (name
, "od") == 0)
4070 /* If we have something like addb,n then there is no condition
4072 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4084 while (**s
== ' ' || **s
== '\t')
4088 /* Reset pointers if this was really a ,n for a branch instruction. */
4089 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4095 /* Parse a negated addition completer returning the number
4096 (for encoding in instrutions) of the given completer.
4098 ISBRANCH specifies whether or not this is parsing a condition
4099 completer for a branch (vs a nullification completer for a
4100 computational instruction. */
4103 pa_parse_neg_add_cmpltr (s
, isbranch
)
4108 char *name
= *s
+ 1;
4116 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4120 if (strcasecmp (name
, "tr") == 0)
4124 else if (strcmp (name
, "<>") == 0)
4128 else if (strcmp (name
, ">=") == 0)
4132 else if (strcmp (name
, ">") == 0)
4136 else if (strcmp (name
, "uv") == 0)
4140 else if (strcmp (name
, "vnz") == 0)
4144 else if (strcasecmp (name
, "nsv") == 0)
4148 else if (strcasecmp (name
, "ev") == 0)
4152 /* If we have something like addb,n then there is no condition
4154 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4166 while (**s
== ' ' || **s
== '\t')
4170 /* Reset pointers if this was really a ,n for a branch instruction. */
4171 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4177 /* Handle a .BLOCK type pseudo-op. */
4185 unsigned int temp_size
;
4188 temp_size
= get_absolute_expression ();
4190 /* Always fill with zeros, that's what the HP assembler does. */
4193 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4194 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4195 bzero (p
, temp_size
);
4197 /* Convert 2 bytes at a time. */
4199 for (i
= 0; i
< temp_size
; i
+= 2)
4201 md_number_to_chars (p
+ i
,
4203 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4206 pa_undefine_label ();
4207 demand_empty_rest_of_line ();
4211 /* Handle a .CALL pseudo-op. This involves storing away information
4212 about where arguments are to be found so the linker can detect
4213 (and correct) argument location mismatches between caller and callee. */
4219 pa_call_args (&last_call_desc
);
4220 demand_empty_rest_of_line ();
4224 /* Do the dirty work of building a call descriptor which describes
4225 where the caller placed arguments to a function call. */
4228 pa_call_args (call_desc
)
4229 struct call_desc
*call_desc
;
4232 unsigned int temp
, arg_reloc
;
4234 while (!is_end_of_statement ())
4236 name
= input_line_pointer
;
4237 c
= get_symbol_end ();
4238 /* Process a source argument. */
4239 if ((strncasecmp (name
, "argw", 4) == 0))
4241 temp
= atoi (name
+ 4);
4242 p
= input_line_pointer
;
4244 input_line_pointer
++;
4245 name
= input_line_pointer
;
4246 c
= get_symbol_end ();
4247 arg_reloc
= pa_build_arg_reloc (name
);
4248 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4250 /* Process a return value. */
4251 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4253 p
= input_line_pointer
;
4255 input_line_pointer
++;
4256 name
= input_line_pointer
;
4257 c
= get_symbol_end ();
4258 arg_reloc
= pa_build_arg_reloc (name
);
4259 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4263 as_bad ("Invalid .CALL argument: %s", name
);
4265 p
= input_line_pointer
;
4267 if (!is_end_of_statement ())
4268 input_line_pointer
++;
4272 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4275 is_same_frag (frag1
, frag2
)
4282 else if (frag2
== NULL
)
4284 else if (frag1
== frag2
)
4286 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4287 return (is_same_frag (frag1
, frag2
->fr_next
));
4293 /* Build an entry in the UNWIND subspace from the given function
4294 attributes in CALL_INFO. This is not needed for SOM as using
4295 R_ENTRY and R_EXIT relocations allow the linker to handle building
4296 of the unwind spaces. */
4299 pa_build_unwind_subspace (call_info
)
4300 struct call_info
*call_info
;
4303 asection
*seg
, *save_seg
;
4304 subsegT subseg
, save_subseg
;
4308 /* Get into the right seg/subseg. This may involve creating
4309 the seg the first time through. Make sure to have the
4310 old seg/subseg so that we can reset things when we are done. */
4311 subseg
= SUBSEG_UNWIND
;
4312 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4313 if (seg
== ASEC_NULL
)
4315 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4316 bfd_set_section_flags (stdoutput
, seg
,
4317 SEC_READONLY
| SEC_HAS_CONTENTS
4318 | SEC_LOAD
| SEC_RELOC
);
4322 save_subseg
= now_subseg
;
4323 subseg_set (seg
, subseg
);
4326 /* Get some space to hold relocation information for the unwind
4329 call_info
->start_offset_frag
= frag_now
;
4330 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4332 /* Relocation info. for start offset of the function. */
4333 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4334 call_info
->start_symbol
, (offsetT
) 0,
4335 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4338 /* We need to search for the first relocation involving the start_symbol of
4339 this call_info descriptor. */
4343 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4344 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4346 if (fixP
->fx_addsy
== call_info
->start_symbol
4347 || fixP
->fx_subsy
== call_info
->start_symbol
)
4349 call_info
->start_fix
= fixP
;
4356 call_info
->end_offset_frag
= frag_now
;
4357 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4359 /* Relocation info. for end offset of the function. */
4360 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4361 call_info
->end_symbol
, (offsetT
) 0,
4362 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4365 /* We need to search for the first relocation involving the end_symbol of
4366 this call_info descriptor. */
4370 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4371 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4373 if (fixP
->fx_addsy
== call_info
->end_symbol
4374 || fixP
->fx_subsy
== call_info
->end_symbol
)
4376 call_info
->end_fix
= fixP
;
4383 unwind
= (char *) &call_info
->ci_unwind
;
4384 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4388 FRAG_APPEND_1_CHAR (c
);
4392 /* Return back to the original segment/subsegment. */
4393 subseg_set (save_seg
, save_subseg
);
4397 /* Process a .CALLINFO pseudo-op. This information is used later
4398 to build unwind descriptors and maybe one day to support
4399 .ENTER and .LEAVE. */
4402 pa_callinfo (unused
)
4408 /* .CALLINFO must appear within a procedure definition. */
4409 if (!within_procedure
)
4410 as_bad (".callinfo is not within a procedure definition");
4412 /* Mark the fact that we found the .CALLINFO for the
4413 current procedure. */
4414 callinfo_found
= TRUE
;
4416 /* Iterate over the .CALLINFO arguments. */
4417 while (!is_end_of_statement ())
4419 name
= input_line_pointer
;
4420 c
= get_symbol_end ();
4421 /* Frame size specification. */
4422 if ((strncasecmp (name
, "frame", 5) == 0))
4424 p
= input_line_pointer
;
4426 input_line_pointer
++;
4427 temp
= get_absolute_expression ();
4428 if ((temp
& 0x3) != 0)
4430 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4434 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4435 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4438 /* Entry register (GR, GR and SR) specifications. */
4439 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4441 p
= input_line_pointer
;
4443 input_line_pointer
++;
4444 temp
= get_absolute_expression ();
4445 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4446 even though %r19 is caller saved. I think this is a bug in
4447 the HP assembler, and we are not going to emulate it. */
4448 if (temp
< 3 || temp
> 18)
4449 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4450 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4452 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4454 p
= input_line_pointer
;
4456 input_line_pointer
++;
4457 temp
= get_absolute_expression ();
4458 /* Similarly the HP assembler takes 31 as the high bound even
4459 though %fr21 is the last callee saved floating point register. */
4460 if (temp
< 12 || temp
> 21)
4461 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4462 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4464 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4466 p
= input_line_pointer
;
4468 input_line_pointer
++;
4469 temp
= get_absolute_expression ();
4471 as_bad ("Value for ENTRY_SR must be 3\n");
4472 last_call_info
->entry_sr
= temp
- 2;
4474 /* Note whether or not this function performs any calls. */
4475 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4476 (strncasecmp (name
, "caller", 6) == 0))
4478 p
= input_line_pointer
;
4480 last_call_info
->makes_calls
= 1;
4482 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4484 p
= input_line_pointer
;
4486 last_call_info
->makes_calls
= 0;
4488 /* Should RP be saved into the stack. */
4489 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4491 p
= input_line_pointer
;
4493 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4495 /* Likewise for SP. */
4496 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4498 p
= input_line_pointer
;
4500 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4502 /* Is this an unwindable procedure. If so mark it so
4503 in the unwind descriptor. */
4504 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4506 p
= input_line_pointer
;
4508 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4510 /* Is this an interrupt routine. If so mark it in the
4511 unwind descriptor. */
4512 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4514 p
= input_line_pointer
;
4516 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4520 as_bad ("Invalid .CALLINFO argument: %s", name
);
4522 if (!is_end_of_statement ())
4523 input_line_pointer
++;
4526 demand_empty_rest_of_line ();
4530 /* Switch into the code subspace. */
4536 sd_chain_struct
*sdchain
;
4538 /* First time through it might be necessary to create the
4540 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4542 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4543 pa_def_spaces
[0].spnum
,
4544 pa_def_spaces
[0].loadable
,
4545 pa_def_spaces
[0].defined
,
4546 pa_def_spaces
[0].private,
4547 pa_def_spaces
[0].sort
,
4548 pa_def_spaces
[0].segment
, 0);
4551 SPACE_DEFINED (sdchain
) = 1;
4552 subseg_set (text_section
, SUBSEG_CODE
);
4553 demand_empty_rest_of_line ();
4557 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4558 the .comm pseudo-op has the following symtax:
4560 <label> .comm <length>
4562 where <label> is optional and is a symbol whose address will be the start of
4563 a block of memory <length> bytes long. <length> must be an absolute
4564 expression. <length> bytes will be allocated in the current space
4573 label_symbol_struct
*label_symbol
= pa_get_label ();
4576 symbol
= label_symbol
->lss_label
;
4581 size
= get_absolute_expression ();
4585 /* It is incorrect to check S_IS_DEFINED at this point as
4586 the symbol will *always* be defined. FIXME. How to
4587 correctly determine when this label really as been
4589 if (S_GET_VALUE (symbol
))
4591 if (S_GET_VALUE (symbol
) != size
)
4593 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4594 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4600 S_SET_VALUE (symbol
, size
);
4601 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4602 S_SET_EXTERNAL (symbol
);
4605 demand_empty_rest_of_line ();
4608 /* Process a .COPYRIGHT pseudo-op. */
4611 pa_copyright (unused
)
4618 if (*input_line_pointer
== '\"')
4620 ++input_line_pointer
;
4621 name
= input_line_pointer
;
4622 while ((c
= next_char_of_string ()) >= 0)
4624 c
= *input_line_pointer
;
4625 *input_line_pointer
= '\0';
4626 *(input_line_pointer
- 1) = '\0';
4628 /* FIXME. Not supported */
4631 *input_line_pointer
= c
;
4635 as_bad ("Expected \"-ed string");
4637 pa_undefine_label ();
4638 demand_empty_rest_of_line ();
4641 /* Process a .END pseudo-op. */
4647 demand_empty_rest_of_line ();
4651 /* Process a .ENTER pseudo-op. This is not supported. */
4660 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4666 if (!within_procedure
)
4667 as_bad ("Misplaced .entry. Ignored.");
4670 if (!callinfo_found
)
4671 as_bad ("Missing .callinfo.");
4673 last_call_info
->start_frag
= frag_now
;
4675 demand_empty_rest_of_line ();
4676 within_entry_exit
= TRUE
;
4678 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4679 It will not be on if no .EXPORT pseudo-op exists (static function). */
4680 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4683 /* SOM defers building of unwind descriptors until the link phase.
4684 The assembler is responsible for creating an R_ENTRY relocation
4685 to mark the beginning of a region and hold the unwind bits, and
4686 for creating an R_EXIT relocation to mark the end of the region.
4688 FIXME. ELF should be using the same conventions! The problem
4689 is an unwind requires too much relocation space. Hmmm. Maybe
4690 if we split the unwind bits up between the relocations which
4691 denote the entry and exit points. */
4693 char *where
= frag_more (0);
4695 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4696 last_call_info
->start_symbol
, (offsetT
) 0, NULL
,
4697 0, R_HPPA_ENTRY
, e_fsel
, 0, 0,
4698 (char *)&last_call_info
->ci_unwind
.descriptor
);
4705 /* Handle a .EQU pseudo-op. */
4711 label_symbol_struct
*label_symbol
= pa_get_label ();
4716 symbol
= label_symbol
->lss_label
;
4717 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4718 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4723 as_bad (".REG must use a label");
4725 as_bad (".EQU must use a label");
4728 pa_undefine_label ();
4729 demand_empty_rest_of_line ();
4733 /* Helper function. Does processing for the end of a function. This
4734 usually involves creating some relocations or building special
4735 symbols to mark the end of the function. */
4742 where
= frag_more (0);
4745 /* ELF does not have EXIT relocations. All we do is create a
4746 temporary symbol marking the end of the function. */
4748 char *name
= (char *) xmalloc (strlen ("L$\001end_") +
4749 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
4755 strcpy (name
, "L$\001end_");
4756 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
4758 symbolP
= symbol_find (name
);
4760 as_warn ("Symbol '%s' already defined.", name
);
4763 /* symbol value should be the offset of the
4764 last instruction of the function */
4765 symbolP
= symbol_new (name
, now_seg
,
4766 (valueT
) (obstack_next_free (&frags
)
4767 - frag_now
->fr_literal
- 4),
4771 symbolP
->bsym
->flags
= BSF_LOCAL
;
4772 symbol_table_insert (symbolP
);
4775 last_call_info
->end_symbol
= symbolP
;
4777 as_bad ("Symbol '%s' could not be created.", name
);
4781 as_bad ("No memory for symbol name.");
4784 /* Stuff away the location of the frag for the end of the function,
4785 and call pa_build_unwind_subspace to add an entry in the unwind
4787 last_call_info
->end_frag
= frag_now
;
4788 pa_build_unwind_subspace (last_call_info
);
4790 /* SOM defers building of unwind descriptors until the link phase.
4791 The assembler is responsible for creating an R_ENTRY relocation
4792 to mark the beginning of a region and hold the unwind bits, and
4793 for creating an R_EXIT relocation to mark the end of the region.
4795 FIXME. ELF should be using the same conventions! The problem
4796 is an unwind requires too much relocation space. Hmmm. Maybe
4797 if we split the unwind bits up between the relocations which
4798 denote the entry and exit points. */
4799 fix_new_hppa (frag_now
, where
- frag_now
->fr_literal
, 0,
4800 last_call_info
->start_symbol
, (offsetT
) 0,
4801 NULL
, 0, R_HPPA_EXIT
, e_fsel
, 0, 0, NULL
);
4804 exit_processing_complete
= TRUE
;
4807 /* Process a .EXIT pseudo-op. */
4813 if (!within_procedure
)
4814 as_bad (".EXIT must appear within a procedure");
4817 if (!callinfo_found
)
4818 as_bad ("Missing .callinfo");
4821 if (!within_entry_exit
)
4822 as_bad ("No .ENTRY for this .EXIT");
4825 within_entry_exit
= FALSE
;
4830 demand_empty_rest_of_line ();
4834 /* Process a .EXPORT directive. This makes functions external
4835 and provides information such as argument relocation entries
4845 name
= input_line_pointer
;
4846 c
= get_symbol_end ();
4847 /* Make sure the given symbol exists. */
4848 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4850 as_bad ("Cannot define export symbol: %s\n", name
);
4851 p
= input_line_pointer
;
4853 input_line_pointer
++;
4857 /* OK. Set the external bits and process argument relocations. */
4858 S_SET_EXTERNAL (symbol
);
4859 p
= input_line_pointer
;
4861 if (!is_end_of_statement ())
4863 input_line_pointer
++;
4864 pa_export_args (symbol
);
4866 pa_build_symextn_section ();
4871 demand_empty_rest_of_line ();
4875 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4878 pa_export_args (symbolP
)
4882 unsigned int temp
, arg_reloc
;
4883 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4884 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4886 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4888 input_line_pointer
+= 8;
4889 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4890 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4891 type
= SYMBOL_TYPE_ABSOLUTE
;
4893 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4895 input_line_pointer
+= 4;
4896 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4897 type
= SYMBOL_TYPE_CODE
;
4899 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4901 input_line_pointer
+= 4;
4902 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4903 type
= SYMBOL_TYPE_DATA
;
4905 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4907 input_line_pointer
+= 5;
4908 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4909 type
= SYMBOL_TYPE_ENTRY
;
4911 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4913 input_line_pointer
+= 9;
4914 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4915 type
= SYMBOL_TYPE_MILLICODE
;
4917 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4919 input_line_pointer
+= 6;
4920 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4921 type
= SYMBOL_TYPE_PLABEL
;
4923 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4925 input_line_pointer
+= 8;
4926 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4927 type
= SYMBOL_TYPE_PRI_PROG
;
4929 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4931 input_line_pointer
+= 8;
4932 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4933 type
= SYMBOL_TYPE_SEC_PROG
;
4936 /* SOM requires much more information about symbol types
4937 than BFD understands. This is how we get this information
4938 to the SOM BFD backend. */
4939 #ifdef obj_set_symbol_type
4940 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4943 /* Now that the type of the exported symbol has been handled,
4944 handle any argument relocation information. */
4945 while (!is_end_of_statement ())
4947 if (*input_line_pointer
== ',')
4948 input_line_pointer
++;
4949 name
= input_line_pointer
;
4950 c
= get_symbol_end ();
4951 /* Argument sources. */
4952 if ((strncasecmp (name
, "argw", 4) == 0))
4954 p
= input_line_pointer
;
4956 input_line_pointer
++;
4957 temp
= atoi (name
+ 4);
4958 name
= input_line_pointer
;
4959 c
= get_symbol_end ();
4960 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4961 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4962 *input_line_pointer
= c
;
4964 /* The return value. */
4965 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4967 p
= input_line_pointer
;
4969 input_line_pointer
++;
4970 name
= input_line_pointer
;
4971 c
= get_symbol_end ();
4972 arg_reloc
= pa_build_arg_reloc (name
);
4973 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4974 *input_line_pointer
= c
;
4976 /* Privelege level. */
4977 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4979 p
= input_line_pointer
;
4981 input_line_pointer
++;
4982 temp
= atoi (input_line_pointer
);
4983 c
= get_symbol_end ();
4984 *input_line_pointer
= c
;
4988 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4989 p
= input_line_pointer
;
4992 if (!is_end_of_statement ())
4993 input_line_pointer
++;
4997 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4998 assembly file must either be defined in the assembly file, or
4999 explicitly IMPORTED from another. */
5008 name
= input_line_pointer
;
5009 c
= get_symbol_end ();
5011 symbol
= symbol_find_or_make (name
);
5012 p
= input_line_pointer
;
5015 if (!is_end_of_statement ())
5017 input_line_pointer
++;
5018 pa_export_args (symbol
);
5022 /* Sigh. To be compatable with the HP assembler and to help
5023 poorly written assembly code, we assign a type based on
5024 the the current segment. Note only BSF_FUNCTION really
5025 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
5026 if (now_seg
== text_section
)
5027 symbol
->bsym
->flags
|= BSF_FUNCTION
;
5029 /* If the section is undefined, then the symbol is undefined
5030 Since this is an import, leave the section undefined. */
5031 S_SET_SEGMENT (symbol
, &bfd_und_section
);
5034 demand_empty_rest_of_line ();
5038 /* Handle a .LABEL pseudo-op. */
5046 name
= input_line_pointer
;
5047 c
= get_symbol_end ();
5049 if (strlen (name
) > 0)
5052 p
= input_line_pointer
;
5057 as_warn ("Missing label name on .LABEL");
5060 if (!is_end_of_statement ())
5062 as_warn ("extra .LABEL arguments ignored.");
5063 ignore_rest_of_line ();
5065 demand_empty_rest_of_line ();
5069 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5078 /* Handle a .ORIGIN pseudo-op. */
5085 pa_undefine_label ();
5089 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5090 is for static functions. FIXME. Should share more code with .EXPORT. */
5099 name
= input_line_pointer
;
5100 c
= get_symbol_end ();
5102 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5104 as_bad ("Cannot define static symbol: %s\n", name
);
5105 p
= input_line_pointer
;
5107 input_line_pointer
++;
5111 S_CLEAR_EXTERNAL (symbol
);
5112 p
= input_line_pointer
;
5114 if (!is_end_of_statement ())
5116 input_line_pointer
++;
5117 pa_export_args (symbol
);
5121 demand_empty_rest_of_line ();
5125 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5126 of a procedure from a syntatical point of view. */
5132 struct call_info
*call_info
;
5134 if (within_procedure
)
5135 as_fatal ("Nested procedures");
5137 /* Reset global variables for new procedure. */
5138 callinfo_found
= FALSE
;
5139 within_procedure
= TRUE
;
5140 exit_processing_complete
= FALSE
;
5142 /* Create another call_info structure. */
5143 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5146 as_fatal ("Cannot allocate unwind descriptor\n");
5148 bzero (call_info
, sizeof (struct call_info
));
5150 call_info
->ci_next
= NULL
;
5152 if (call_info_root
== NULL
)
5154 call_info_root
= call_info
;
5155 last_call_info
= call_info
;
5159 last_call_info
->ci_next
= call_info
;
5160 last_call_info
= call_info
;
5163 /* set up defaults on call_info structure */
5165 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5166 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5167 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5168 call_info
->entry_sr
= ~0;
5169 call_info
->makes_calls
= 1;
5171 /* If we got a .PROC pseudo-op, we know that the function is defined
5172 locally. Make sure it gets into the symbol table. */
5174 label_symbol_struct
*label_symbol
= pa_get_label ();
5178 if (label_symbol
->lss_label
)
5180 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5181 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5184 as_bad ("Missing function name for .PROC (corrupted label)");
5187 as_bad ("Missing function name for .PROC");
5190 demand_empty_rest_of_line ();
5194 /* Process the syntatical end of a procedure. Make sure all the
5195 appropriate pseudo-ops were found within the procedure. */
5202 if (!within_procedure
)
5203 as_bad ("misplaced .procend");
5205 if (!callinfo_found
)
5206 as_bad ("Missing .callinfo for this procedure");
5208 if (within_entry_exit
)
5209 as_bad ("Missing .EXIT for a .ENTRY");
5211 if (!exit_processing_complete
)
5214 within_procedure
= FALSE
;
5215 demand_empty_rest_of_line ();
5219 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5220 then create a new space entry to hold the information specified
5221 by the parameters to the .SPACE directive. */
5223 static sd_chain_struct
*
5224 pa_parse_space_stmt (space_name
, create_flag
)
5228 char *name
, *ptemp
, c
;
5229 char loadable
, defined
, private, sort
;
5231 asection
*seg
= NULL
;
5232 sd_chain_struct
*space
;
5234 /* load default values */
5240 if (strcasecmp (space_name
, "$TEXT$") == 0)
5242 seg
= pa_def_spaces
[0].segment
;
5243 sort
= pa_def_spaces
[0].sort
;
5245 else if (strcasecmp (space_name
, "$PRIVATE$") == 0)
5247 seg
= pa_def_spaces
[1].segment
;
5248 sort
= pa_def_spaces
[1].sort
;
5251 if (!is_end_of_statement ())
5253 print_errors
= FALSE
;
5254 ptemp
= input_line_pointer
+ 1;
5255 /* First see if the space was specified as a number rather than
5256 as a name. According to the PA assembly manual the rest of
5257 the line should be ignored. */
5258 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5259 input_line_pointer
= ptemp
;
5262 while (!is_end_of_statement ())
5264 input_line_pointer
++;
5265 name
= input_line_pointer
;
5266 c
= get_symbol_end ();
5267 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5269 *input_line_pointer
= c
;
5270 input_line_pointer
++;
5271 spnum
= get_absolute_expression ();
5273 else if ((strncasecmp (name
, "SORT", 4) == 0))
5275 *input_line_pointer
= c
;
5276 input_line_pointer
++;
5277 sort
= get_absolute_expression ();
5279 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5281 *input_line_pointer
= c
;
5284 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5286 *input_line_pointer
= c
;
5289 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5291 *input_line_pointer
= c
;
5296 as_bad ("Invalid .SPACE argument");
5297 *input_line_pointer
= c
;
5298 if (! is_end_of_statement ())
5299 input_line_pointer
++;
5303 print_errors
= TRUE
;
5306 if (create_flag
&& seg
== NULL
)
5307 seg
= subseg_new (space_name
, 0);
5309 /* If create_flag is nonzero, then create the new space with
5310 the attributes computed above. Else set the values in
5311 an already existing space -- this can only happen for
5312 the first occurence of a built-in space. */
5314 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5315 private, sort
, seg
, 1);
5318 space
= is_defined_space (space_name
);
5319 SPACE_SPNUM (space
) = spnum
;
5320 SPACE_LOADABLE (space
) = loadable
& 1;
5321 SPACE_DEFINED (space
) = defined
& 1;
5322 SPACE_USER_DEFINED (space
) = 1;
5323 SPACE_PRIVATE (space
) = private & 1;
5324 SPACE_SORT (space
) = sort
& 0xff;
5325 space
->sd_seg
= seg
;
5328 #ifdef obj_set_section_attributes
5329 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5335 /* Adjust the frag's alignment according to the alignment needs
5336 of the given subspace/subsegment. */
5339 pa_align_subseg (seg
, subseg
)
5343 ssd_chain_struct
*now_subspace
;
5347 now_subspace
= pa_subsegment_to_subspace (seg
, subseg
);
5350 if (SUBSPACE_ALIGN (now_subspace
) == 0)
5351 alignment
= now_subspace
->ssd_last_align
;
5352 else if (now_subspace
->ssd_last_align
> SUBSPACE_ALIGN (now_subspace
))
5353 alignment
= now_subspace
->ssd_last_align
;
5355 alignment
= SUBSPACE_ALIGN (now_subspace
);
5357 while ((1 << shift
) < alignment
)
5361 shift
= bfd_get_section_alignment (stdoutput
, seg
);
5363 frag_align (shift
, 0);
5366 /* Handle a .SPACE pseudo-op; this switches the current space to the
5367 given space, creating the new space if necessary. */
5373 char *name
, c
, *space_name
, *save_s
;
5375 sd_chain_struct
*sd_chain
;
5377 if (within_procedure
)
5379 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5380 ignore_rest_of_line ();
5384 /* Check for some of the predefined spaces. FIXME: most of the code
5385 below is repeated several times, can we extract the common parts
5386 and place them into a subroutine or something similar? */
5387 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5389 input_line_pointer
+= 6;
5390 sd_chain
= is_defined_space ("$TEXT$");
5391 if (sd_chain
== NULL
)
5392 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5393 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5394 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5396 current_space
= sd_chain
;
5398 /* No need to align if we are already there. */
5399 if (now_seg
!= text_section
)
5400 pa_align_subseg (now_seg
, now_subseg
);
5402 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5405 = pa_subsegment_to_subspace (text_section
,
5406 sd_chain
->sd_last_subseg
);
5407 demand_empty_rest_of_line ();
5410 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5412 input_line_pointer
+= 9;
5413 sd_chain
= is_defined_space ("$PRIVATE$");
5414 if (sd_chain
== NULL
)
5415 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5416 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5417 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5419 current_space
= sd_chain
;
5421 /* No need to align if we are already there. */
5422 if (now_seg
!= data_section
)
5423 pa_align_subseg (now_seg
, now_subseg
);
5425 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5427 = pa_subsegment_to_subspace (data_section
,
5428 sd_chain
->sd_last_subseg
);
5429 demand_empty_rest_of_line ();
5432 if (!strncasecmp (input_line_pointer
,
5433 GDB_DEBUG_SPACE_NAME
,
5434 strlen (GDB_DEBUG_SPACE_NAME
)))
5436 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5437 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5438 if (sd_chain
== NULL
)
5439 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5440 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5441 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5443 current_space
= sd_chain
;
5446 asection
*gdb_section
5447 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5449 /* No need to align if we are already there. */
5450 if (strcmp (segment_name (now_seg
), GDB_DEBUG_SPACE_NAME
) != 0)
5451 pa_align_subseg (now_seg
, now_subseg
);
5453 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5455 = pa_subsegment_to_subspace (gdb_section
,
5456 sd_chain
->sd_last_subseg
);
5458 demand_empty_rest_of_line ();
5462 /* It could be a space specified by number. */
5464 save_s
= input_line_pointer
;
5465 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5467 if (sd_chain
= pa_find_space_by_number (temp
))
5469 current_space
= sd_chain
;
5471 if (now_seg
!= sd_chain
->sd_seg
)
5472 pa_align_subseg (now_seg
, now_subseg
);
5473 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5475 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5476 sd_chain
->sd_last_subseg
);
5477 demand_empty_rest_of_line ();
5482 /* Not a number, attempt to create a new space. */
5484 input_line_pointer
= save_s
;
5485 name
= input_line_pointer
;
5486 c
= get_symbol_end ();
5487 space_name
= xmalloc (strlen (name
) + 1);
5488 strcpy (space_name
, name
);
5489 *input_line_pointer
= c
;
5491 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5492 current_space
= sd_chain
;
5494 if (now_seg
!= sd_chain
->sd_seg
)
5495 pa_align_subseg (now_seg
, now_subseg
);
5496 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5497 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5498 sd_chain
->sd_last_subseg
);
5499 demand_empty_rest_of_line ();
5504 /* Switch to a new space. (I think). FIXME. */
5513 sd_chain_struct
*space
;
5515 name
= input_line_pointer
;
5516 c
= get_symbol_end ();
5517 space
= is_defined_space (name
);
5521 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5524 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5526 *input_line_pointer
= c
;
5527 demand_empty_rest_of_line ();
5531 /* If VALUE is an exact power of two between zero and 2^31, then
5532 return log2 (VALUE). Else return -1. */
5540 while ((1 << shift
) != value
&& shift
< 32)
5549 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5550 given subspace, creating the new subspace if necessary.
5552 FIXME. Should mirror pa_space more closely, in particular how
5553 they're broken up into subroutines. */
5556 pa_subspace (unused
)
5559 char *name
, *ss_name
, *alias
, c
;
5560 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5561 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5562 sd_chain_struct
*space
;
5563 ssd_chain_struct
*ssd
;
5566 if (within_procedure
)
5568 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5569 ignore_rest_of_line ();
5573 name
= input_line_pointer
;
5574 c
= get_symbol_end ();
5575 ss_name
= xmalloc (strlen (name
) + 1);
5576 strcpy (ss_name
, name
);
5577 *input_line_pointer
= c
;
5579 /* Load default values. */
5592 space
= current_space
;
5593 ssd
= is_defined_subspace (ss_name
);
5594 /* Allow user to override the builtin attributes of subspaces. But
5595 only allow the attributes to be changed once! */
5596 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5598 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5599 if (!is_end_of_statement ())
5600 as_warn ("Parameters of an existing subspace can\'t be modified");
5601 demand_empty_rest_of_line ();
5606 /* A new subspace. Load default values if it matches one of
5607 the builtin subspaces. */
5609 while (pa_def_subspaces
[i
].name
)
5611 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5613 loadable
= pa_def_subspaces
[i
].loadable
;
5614 common
= pa_def_subspaces
[i
].common
;
5615 dup_common
= pa_def_subspaces
[i
].dup_common
;
5616 code_only
= pa_def_subspaces
[i
].code_only
;
5617 zero
= pa_def_subspaces
[i
].zero
;
5618 space_index
= pa_def_subspaces
[i
].space_index
;
5619 alignment
= pa_def_subspaces
[i
].alignment
;
5620 quadrant
= pa_def_subspaces
[i
].quadrant
;
5621 access
= pa_def_subspaces
[i
].access
;
5622 sort
= pa_def_subspaces
[i
].sort
;
5623 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5624 alias
= pa_def_subspaces
[i
].alias
;
5631 /* We should be working with a new subspace now. Fill in
5632 any information as specified by the user. */
5633 if (!is_end_of_statement ())
5635 input_line_pointer
++;
5636 while (!is_end_of_statement ())
5638 name
= input_line_pointer
;
5639 c
= get_symbol_end ();
5640 if ((strncasecmp (name
, "QUAD", 4) == 0))
5642 *input_line_pointer
= c
;
5643 input_line_pointer
++;
5644 quadrant
= get_absolute_expression ();
5646 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5648 *input_line_pointer
= c
;
5649 input_line_pointer
++;
5650 alignment
= get_absolute_expression ();
5651 if (log2 (alignment
) == -1)
5653 as_bad ("Alignment must be a power of 2");
5657 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5659 *input_line_pointer
= c
;
5660 input_line_pointer
++;
5661 access
= get_absolute_expression ();
5663 else if ((strncasecmp (name
, "SORT", 4) == 0))
5665 *input_line_pointer
= c
;
5666 input_line_pointer
++;
5667 sort
= get_absolute_expression ();
5669 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5671 *input_line_pointer
= c
;
5674 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5676 *input_line_pointer
= c
;
5679 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5681 *input_line_pointer
= c
;
5684 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5686 *input_line_pointer
= c
;
5689 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5691 *input_line_pointer
= c
;
5694 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5695 as_bad ("FIRST not supported as a .SUBSPACE argument");
5697 as_bad ("Invalid .SUBSPACE argument");
5698 if (!is_end_of_statement ())
5699 input_line_pointer
++;
5703 /* Compute a reasonable set of BFD flags based on the information
5704 in the .subspace directive. */
5705 applicable
= bfd_applicable_section_flags (stdoutput
);
5708 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5711 if (common
|| dup_common
)
5712 flags
|= SEC_IS_COMMON
;
5714 /* This is a zero-filled subspace (eg BSS). */
5718 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5719 applicable
&= flags
;
5721 /* If this is an existing subspace, then we want to use the
5722 segment already associated with the subspace.
5724 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5725 lots of sections. It might be a problem in the PA ELF
5726 code, I do not know yet. For now avoid creating anything
5727 but the "standard" sections for ELF. */
5729 section
= ssd
->ssd_seg
;
5731 section
= subseg_new (alias
, 0);
5732 else if (! alias
&& USE_ALIASES
)
5734 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5735 demand_empty_rest_of_line ();
5739 section
= subseg_new (ss_name
, 0);
5741 /* Now set the flags. */
5742 bfd_set_section_flags (stdoutput
, section
, applicable
);
5744 /* Record any alignment request for this section. */
5745 record_alignment (section
, log2 (alignment
));
5747 /* Set the starting offset for this section. */
5748 bfd_set_section_vma (stdoutput
, section
,
5749 pa_subspace_start (space
, quadrant
));
5751 /* Now that all the flags are set, update an existing subspace,
5752 or create a new one. */
5755 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5756 code_only
, common
, dup_common
,
5757 sort
, zero
, access
, space_index
,
5758 alignment
, quadrant
,
5761 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5763 dup_common
, zero
, sort
,
5764 access
, space_index
,
5765 alignment
, quadrant
, section
);
5767 demand_empty_rest_of_line ();
5768 current_subspace
->ssd_seg
= section
;
5769 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5771 SUBSPACE_DEFINED (current_subspace
) = 1;
5776 /* Create default space and subspace dictionaries. */
5783 space_dict_root
= NULL
;
5784 space_dict_last
= NULL
;
5787 while (pa_def_spaces
[i
].name
)
5791 /* Pick the right name to use for the new section. */
5792 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5793 name
= pa_def_spaces
[i
].alias
;
5795 name
= pa_def_spaces
[i
].name
;
5797 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5798 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5799 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5800 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5801 pa_def_spaces
[i
].segment
, 0);
5806 while (pa_def_subspaces
[i
].name
)
5809 int applicable
, subsegment
;
5810 asection
*segment
= NULL
;
5811 sd_chain_struct
*space
;
5813 /* Pick the right name for the new section and pick the right
5814 subsegment number. */
5815 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5817 name
= pa_def_subspaces
[i
].alias
;
5818 subsegment
= pa_def_subspaces
[i
].subsegment
;
5822 name
= pa_def_subspaces
[i
].name
;
5826 /* Create the new section. */
5827 segment
= subseg_new (name
, subsegment
);
5830 /* For SOM we want to replace the standard .text, .data, and .bss
5831 sections with our own. */
5832 if (! strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && ! USE_ALIASES
)
5834 text_section
= segment
;
5835 applicable
= bfd_applicable_section_flags (stdoutput
);
5836 bfd_set_section_flags (stdoutput
, text_section
,
5837 applicable
& (SEC_ALLOC
| SEC_LOAD
5838 | SEC_RELOC
| SEC_CODE
5840 | SEC_HAS_CONTENTS
));
5842 else if (! strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && ! USE_ALIASES
)
5844 data_section
= segment
;
5845 applicable
= bfd_applicable_section_flags (stdoutput
);
5846 bfd_set_section_flags (stdoutput
, data_section
,
5847 applicable
& (SEC_ALLOC
| SEC_LOAD
5849 | SEC_HAS_CONTENTS
));
5853 else if (! strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && ! USE_ALIASES
)
5855 bss_section
= segment
;
5856 applicable
= bfd_applicable_section_flags (stdoutput
);
5857 bfd_set_section_flags (stdoutput
, bss_section
,
5858 applicable
& SEC_ALLOC
);
5861 /* Find the space associated with this subspace. */
5862 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5863 def_space_index
].segment
);
5866 as_fatal ("Internal error: Unable to find containing space for %s.",
5867 pa_def_subspaces
[i
].name
);
5870 create_new_subspace (space
, name
,
5871 pa_def_subspaces
[i
].loadable
,
5872 pa_def_subspaces
[i
].code_only
,
5873 pa_def_subspaces
[i
].common
,
5874 pa_def_subspaces
[i
].dup_common
,
5875 pa_def_subspaces
[i
].zero
,
5876 pa_def_subspaces
[i
].sort
,
5877 pa_def_subspaces
[i
].access
,
5878 pa_def_subspaces
[i
].space_index
,
5879 pa_def_subspaces
[i
].alignment
,
5880 pa_def_subspaces
[i
].quadrant
,
5888 /* Create a new space NAME, with the appropriate flags as defined
5889 by the given parameters.
5891 Add the new space to the space dictionary chain in numerical
5892 order as defined by the SORT entries. */
5894 static sd_chain_struct
*
5895 create_new_space (name
, spnum
, loadable
, defined
, private,
5896 sort
, seg
, user_defined
)
5906 sd_chain_struct
*chain_entry
;
5908 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5910 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5913 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5914 strcpy (SPACE_NAME (chain_entry
), name
);
5915 SPACE_NAME_INDEX (chain_entry
) = 0;
5916 SPACE_LOADABLE (chain_entry
) = loadable
;
5917 SPACE_DEFINED (chain_entry
) = defined
;
5918 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5919 SPACE_PRIVATE (chain_entry
) = private;
5920 SPACE_SPNUM (chain_entry
) = spnum
;
5921 SPACE_SORT (chain_entry
) = sort
;
5923 chain_entry
->sd_seg
= seg
;
5924 chain_entry
->sd_last_subseg
= -1;
5925 chain_entry
->sd_next
= NULL
;
5927 /* Find spot for the new space based on its sort key. */
5928 if (!space_dict_last
)
5929 space_dict_last
= chain_entry
;
5931 if (space_dict_root
== NULL
)
5932 space_dict_root
= chain_entry
;
5935 sd_chain_struct
*chain_pointer
;
5936 sd_chain_struct
*prev_chain_pointer
;
5938 chain_pointer
= space_dict_root
;
5939 prev_chain_pointer
= NULL
;
5941 while (chain_pointer
)
5943 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5945 prev_chain_pointer
= chain_pointer
;
5946 chain_pointer
= chain_pointer
->sd_next
;
5952 /* At this point we've found the correct place to add the new
5953 entry. So add it and update the linked lists as appropriate. */
5954 if (prev_chain_pointer
)
5956 chain_entry
->sd_next
= chain_pointer
;
5957 prev_chain_pointer
->sd_next
= chain_entry
;
5961 space_dict_root
= chain_entry
;
5962 chain_entry
->sd_next
= chain_pointer
;
5965 if (chain_entry
->sd_next
== NULL
)
5966 space_dict_last
= chain_entry
;
5969 /* This is here to catch predefined spaces which do not get
5970 modified by the user's input. Another call is found at
5971 the bottom of pa_parse_space_stmt to handle cases where
5972 the user modifies a predefined space. */
5973 #ifdef obj_set_section_attributes
5974 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5980 /* Create a new subspace NAME, with the appropriate flags as defined
5981 by the given parameters.
5983 Add the new subspace to the subspace dictionary chain in numerical
5984 order as defined by the SORT entries. */
5986 static ssd_chain_struct
*
5987 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5988 dup_common
, is_zero
, sort
, access
, space_index
,
5989 alignment
, quadrant
, seg
)
5990 sd_chain_struct
*space
;
5992 char loadable
, code_only
, common
, dup_common
, is_zero
;
6000 ssd_chain_struct
*chain_entry
;
6002 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
6004 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
6006 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
6007 strcpy (SUBSPACE_NAME (chain_entry
), name
);
6009 SUBSPACE_ACCESS (chain_entry
) = access
;
6010 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
6011 SUBSPACE_COMMON (chain_entry
) = common
;
6012 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
6013 SUBSPACE_SORT (chain_entry
) = sort
;
6014 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
6015 SUBSPACE_ALIGN (chain_entry
) = alignment
;
6016 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
6017 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
6018 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
6019 SUBSPACE_ZERO (chain_entry
) = is_zero
;
6021 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
6022 chain_entry
->ssd_seg
= seg
;
6023 chain_entry
->ssd_last_align
= 1;
6024 chain_entry
->ssd_next
= NULL
;
6026 /* Find spot for the new subspace based on its sort key. */
6027 if (space
->sd_subspaces
== NULL
)
6028 space
->sd_subspaces
= chain_entry
;
6031 ssd_chain_struct
*chain_pointer
;
6032 ssd_chain_struct
*prev_chain_pointer
;
6034 chain_pointer
= space
->sd_subspaces
;
6035 prev_chain_pointer
= NULL
;
6037 while (chain_pointer
)
6039 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
6041 prev_chain_pointer
= chain_pointer
;
6042 chain_pointer
= chain_pointer
->ssd_next
;
6049 /* Now we have somewhere to put the new entry. Insert it and update
6051 if (prev_chain_pointer
)
6053 chain_entry
->ssd_next
= chain_pointer
;
6054 prev_chain_pointer
->ssd_next
= chain_entry
;
6058 space
->sd_subspaces
= chain_entry
;
6059 chain_entry
->ssd_next
= chain_pointer
;
6063 #ifdef obj_set_subsection_attributes
6064 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
6072 /* Update the information for the given subspace based upon the
6073 various arguments. Return the modified subspace chain entry. */
6075 static ssd_chain_struct
*
6076 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
6077 zero
, access
, space_index
, alignment
, quadrant
, section
)
6078 sd_chain_struct
*space
;
6092 ssd_chain_struct
*chain_entry
;
6094 if ((chain_entry
= is_defined_subspace (name
)))
6096 SUBSPACE_ACCESS (chain_entry
) = access
;
6097 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
6098 SUBSPACE_COMMON (chain_entry
) = common
;
6099 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
6100 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
6101 SUBSPACE_SORT (chain_entry
) = sort
;
6102 SUBSPACE_ALIGN (chain_entry
) = alignment
;
6103 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
6104 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
6105 SUBSPACE_ZERO (chain_entry
) = zero
;
6110 #ifdef obj_set_subsection_attributes
6111 obj_set_subsection_attributes (section
, space
->sd_seg
, access
,
6119 /* Return the space chain entry for the space with the name NAME or
6120 NULL if no such space exists. */
6122 static sd_chain_struct
*
6123 is_defined_space (name
)
6126 sd_chain_struct
*chain_pointer
;
6128 for (chain_pointer
= space_dict_root
;
6130 chain_pointer
= chain_pointer
->sd_next
)
6132 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6133 return chain_pointer
;
6136 /* No mapping from segment to space was found. Return NULL. */
6140 /* Find and return the space associated with the given seg. If no mapping
6141 from the given seg to a space is found, then return NULL.
6143 Unlike subspaces, the number of spaces is not expected to grow much,
6144 so a linear exhaustive search is OK here. */
6146 static sd_chain_struct
*
6147 pa_segment_to_space (seg
)
6150 sd_chain_struct
*space_chain
;
6152 /* Walk through each space looking for the correct mapping. */
6153 for (space_chain
= space_dict_root
;
6155 space_chain
= space_chain
->sd_next
)
6157 if (space_chain
->sd_seg
== seg
)
6161 /* Mapping was not found. Return NULL. */
6165 /* Return the space chain entry for the subspace with the name NAME or
6166 NULL if no such subspace exists.
6168 Uses a linear search through all the spaces and subspaces, this may
6169 not be appropriate if we ever being placing each function in its
6172 static ssd_chain_struct
*
6173 is_defined_subspace (name
)
6176 sd_chain_struct
*space_chain
;
6177 ssd_chain_struct
*subspace_chain
;
6179 /* Walk through each space. */
6180 for (space_chain
= space_dict_root
;
6182 space_chain
= space_chain
->sd_next
)
6184 /* Walk through each subspace looking for a name which matches. */
6185 for (subspace_chain
= space_chain
->sd_subspaces
;
6187 subspace_chain
= subspace_chain
->ssd_next
)
6188 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6189 return subspace_chain
;
6192 /* Subspace wasn't found. Return NULL. */
6196 /* Find and return the subspace associated with the given seg. If no
6197 mapping from the given seg to a subspace is found, then return NULL.
6199 If we ever put each procedure/function within its own subspace
6200 (to make life easier on the compiler and linker), then this will have
6201 to become more efficient. */
6203 static ssd_chain_struct
*
6204 pa_subsegment_to_subspace (seg
, subseg
)
6208 sd_chain_struct
*space_chain
;
6209 ssd_chain_struct
*subspace_chain
;
6211 /* Walk through each space. */
6212 for (space_chain
= space_dict_root
;
6214 space_chain
= space_chain
->sd_next
)
6216 if (space_chain
->sd_seg
== seg
)
6218 /* Walk through each subspace within each space looking for
6219 the correct mapping. */
6220 for (subspace_chain
= space_chain
->sd_subspaces
;
6222 subspace_chain
= subspace_chain
->ssd_next
)
6223 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6224 return subspace_chain
;
6228 /* No mapping from subsegment to subspace found. Return NULL. */
6232 /* Given a number, try and find a space with the name number.
6234 Return a pointer to a space dictionary chain entry for the space
6235 that was found or NULL on failure. */
6237 static sd_chain_struct
*
6238 pa_find_space_by_number (number
)
6241 sd_chain_struct
*space_chain
;
6243 for (space_chain
= space_dict_root
;
6245 space_chain
= space_chain
->sd_next
)
6247 if (SPACE_SPNUM (space_chain
) == number
)
6251 /* No appropriate space found. Return NULL. */
6255 /* Return the starting address for the given subspace. If the starting
6256 address is unknown then return zero. */
6259 pa_subspace_start (space
, quadrant
)
6260 sd_chain_struct
*space
;
6263 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6264 is not correct for the PA OSF1 port. */
6265 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6267 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6273 /* FIXME. Needs documentation. */
6275 pa_next_subseg (space
)
6276 sd_chain_struct
*space
;
6279 space
->sd_last_subseg
++;
6280 return space
->sd_last_subseg
;
6283 /* Helper function for pa_stringer. Used to find the end of
6290 unsigned int c
= *s
& CHAR_MASK
;
6302 /* Handle a .STRING type pseudo-op. */
6305 pa_stringer (append_zero
)
6308 char *s
, num_buf
[4];
6312 /* Preprocess the string to handle PA-specific escape sequences.
6313 For example, \xDD where DD is a hexidecimal number should be
6314 changed to \OOO where OOO is an octal number. */
6316 /* Skip the opening quote. */
6317 s
= input_line_pointer
+ 1;
6319 while (is_a_char (c
= pa_stringer_aux (s
++)))
6326 /* Handle \x<num>. */
6329 unsigned int number
;
6334 /* Get pas the 'x'. */
6336 for (num_digit
= 0, number
= 0, dg
= *s
;
6338 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6339 || (dg
>= 'A' && dg
<= 'F'));
6343 number
= number
* 16 + dg
- '0';
6344 else if (dg
>= 'a' && dg
<= 'f')
6345 number
= number
* 16 + dg
- 'a' + 10;
6347 number
= number
* 16 + dg
- 'A' + 10;
6357 sprintf (num_buf
, "%02o", number
);
6360 sprintf (num_buf
, "%03o", number
);
6363 for (i
= 0; i
<= num_digit
; i
++)
6364 s_start
[i
] = num_buf
[i
];
6368 /* This might be a "\"", skip over the escaped char. */
6375 stringer (append_zero
);
6376 pa_undefine_label ();
6379 /* Handle a .VERSION pseudo-op. */
6386 pa_undefine_label ();
6389 /* Just like a normal cons, but when finished we have to undefine
6390 the latest space label. */
6397 pa_undefine_label ();
6400 /* Switch to the data space. As usual delete our label. */
6407 pa_undefine_label ();
6410 /* FIXME. What's the purpose of this pseudo-op? */
6416 pa_undefine_label ();
6419 /* Like float_cons, but we need to undefine our label. */
6422 pa_float_cons (float_type
)
6425 float_cons (float_type
);
6426 pa_undefine_label ();
6429 /* Like s_fill, but delete our label when finished. */
6436 pa_undefine_label ();
6439 /* Like lcomm, but delete our label when finished. */
6442 pa_lcomm (needs_align
)
6445 s_lcomm (needs_align
);
6446 pa_undefine_label ();
6449 /* Like lsym, but delete our label when finished. */
6456 pa_undefine_label ();
6459 /* Switch to the text space. Like s_text, but delete our
6460 label when finished. */
6466 pa_undefine_label ();
6469 /* On the PA relocations which involve function symbols must not be
6470 adjusted. This so that the linker can know when/how to create argument
6471 relocation stubs for indirect calls and calls to static functions.
6473 FIXME. Also reject R_HPPA relocations which are 32 bits
6474 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6475 needs to generate relocations to push the addend and symbol value
6476 onto the stack, add them, then pop the value off the stack and
6477 use it in a relocation -- yuk. */
6480 hppa_fix_adjustable (fixp
)
6483 struct hppa_fix_struct
*hppa_fix
;
6485 hppa_fix
= fixp
->tc_fix_data
;
6487 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6490 if (fixp
->fx_addsy
== 0
6491 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6497 /* Now for some ELF specific code. FIXME. */
6499 static symext_chainS
*symext_rootP
;
6500 static symext_chainS
*symext_lastP
;
6502 /* Do any symbol processing requested by the target-cpu or target-format. */
6505 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6507 elf_symbol_type
*symbolP
;
6510 symext_chainS
*symextP
;
6511 unsigned int arg_reloc
;
6513 /* Only functions can have argument relocations. */
6514 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6517 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6519 /* If there are no argument relocation bits, then no relocation is
6520 necessary. Do not add this to the symextn section. */
6524 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6526 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6527 symextP
[0].next
= &symextP
[1];
6529 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6530 symextP
[1].next
= NULL
;
6532 if (symext_rootP
== NULL
)
6534 symext_rootP
= &symextP
[0];
6535 symext_lastP
= &symextP
[1];
6539 symext_lastP
->next
= &symextP
[0];
6540 symext_lastP
= &symextP
[1];
6544 /* Make sections needed by the target cpu and/or target format. */
6546 hppa_tc_make_sections (abfd
)
6549 symext_chainS
*symextP
;
6551 asection
*symextn_sec
;
6552 segT save_seg
= now_seg
;
6553 subsegT save_subseg
= now_subseg
;
6555 /* Build the symbol extension section. */
6556 hppa_tc_make_symextn_section ();
6558 /* Force some calculation to occur. */
6559 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6561 hppa_elf_stub_finish (abfd
);
6563 /* If no symbols for the symbol extension section, then stop now. */
6564 if (symext_rootP
== NULL
)
6567 /* Count the number of symbols for the symbol extension section. */
6568 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6571 size
= sizeof (symext_entryS
) * n
;
6573 /* Switch to the symbol extension section. */
6574 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6576 frag_wane (frag_now
);
6579 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6582 int *symtab_map
= elf_sym_extra (abfd
);
6585 /* First, patch the symbol extension record to reflect the true
6586 symbol table index. */
6588 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6590 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6591 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6595 ptr
= frag_more (sizeof (symextP
->entry
));
6596 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6599 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6600 frag_wane (frag_now
);
6602 /* Switch back to the original segment. */
6603 subseg_set (save_seg
, save_subseg
);
6608 /* Make the symbol extension section. */
6611 hppa_tc_make_symextn_section ()
6615 symext_chainS
*symextP
;
6619 segT save_seg
= now_seg
;
6620 subsegT save_subseg
= now_subseg
;
6622 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6625 size
= sizeof (symext_entryS
) * n
;
6627 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6629 bfd_set_section_flags (stdoutput
, symextn_sec
,
6630 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6631 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6633 /* Now, switch back to the original segment. */
6634 subseg_set (save_seg
, save_subseg
);
6638 /* Build the symbol extension section. */
6641 pa_build_symextn_section ()
6644 asection
*save_seg
= now_seg
;
6645 subsegT subseg
= (subsegT
) 0;
6646 subsegT save_subseg
= now_subseg
;
6648 seg
= subseg_new (".hppa_symextn", subseg
);
6649 bfd_set_section_flags (stdoutput
,
6651 SEC_HAS_CONTENTS
| SEC_READONLY
6652 | SEC_ALLOC
| SEC_LOAD
);
6654 subseg_set (save_seg
, save_subseg
);
6658 /* For ELF, this function serves one purpose: to setup the st_size
6659 field of STT_FUNC symbols. To do this, we need to scan the
6660 call_info structure list, determining st_size in one of two possible
6663 1. call_info->start_frag->fr_fix has the size of the fragment.
6664 This approach assumes that the function was built into a
6665 single fragment. This works for most cases, but might fail.
6666 For example, if there was a segment change in the middle of
6669 2. The st_size field is the difference in the addresses of the
6670 call_info->start_frag->fr_address field and the fr_address
6671 field of the next fragment with fr_type == rs_fill and
6675 elf_hppa_final_processing ()
6677 struct call_info
*call_info_pointer
;
6679 for (call_info_pointer
= call_info_root
;
6681 call_info_pointer
= call_info_pointer
->ci_next
)
6683 elf_symbol_type
*esym
6684 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6685 esym
->internal_elf_sym
.st_size
=
6686 S_GET_VALUE (call_info_pointer
->end_symbol
)
6687 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;