1 /* tc-hppa.c -- Assemble for the PA
2 Copyright (C) 1989 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 1, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* HP PA-RISC support was contributed by the Center for Software Science
22 at the University of Utah. */
30 #include "../bfd/libhppa.h"
31 #include "../bfd/libbfd.h"
33 /* Be careful, this file includes data *declarations*. */
34 #include "opcode/hppa.h"
36 /* A "convient" place to put object file dependencies which do
37 not need to be seen outside of tc-hppa.c. */
39 /* Names of various debugging spaces/subspaces. */
40 #define GDB_DEBUG_SPACE_NAME ".stab"
41 #define GDB_STRINGS_SUBSPACE_NAME ".stabstr"
42 #define GDB_SYMBOLS_SUBSPACE_NAME ".stab"
43 #define UNWIND_SECTION_NAME ".hppa_unwind"
44 /* Nonzero if CODE is a fixup code needing further processing. */
46 /* Object file formats specify relocation types. */
47 typedef elf32_hppa_reloc_type reloc_type
;
49 /* Object file formats specify BFD symbol types. */
50 typedef elf_symbol_type obj_symbol_type
;
52 /* How to generate a relocation. */
53 #define hppa_gen_reloc_type hppa_elf_gen_reloc_type
56 #define obj_version obj_elf_version
58 /* Use space aliases. */
61 /* Some local functions only used by ELF. */
62 static void pa_build_symextn_section
PARAMS ((void));
63 static void hppa_tc_make_symextn_section
PARAMS ((void));
67 /* Names of various debugging spaces/subspaces. */
68 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
69 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
70 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
71 #define UNWIND_SECTION_NAME "$UNWIND$"
73 /* Object file formats specify relocation types. */
74 typedef int reloc_type
;
77 #define obj_version obj_som_version
79 /* Do not use space aliases. */
82 /* How to generate a relocation. */
83 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
85 /* Object file formats specify BFD symbol types. */
86 typedef som_symbol_type obj_symbol_type
;
89 /* Various structures and types used internally in tc-hppa.c. */
91 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
95 unsigned int cannot_unwind
:1;
96 unsigned int millicode
:1;
97 unsigned int millicode_save_rest
:1;
98 unsigned int region_desc
:2;
99 unsigned int save_sr
:2;
100 unsigned int entry_fr
:4;
101 unsigned int entry_gr
:5;
102 unsigned int args_stored
:1;
103 unsigned int call_fr
:5;
104 unsigned int call_gr
:5;
105 unsigned int save_sp
:1;
106 unsigned int save_rp
:1;
107 unsigned int save_rp_in_frame
:1;
108 unsigned int extn_ptr_defined
:1;
109 unsigned int cleanup_defined
:1;
111 unsigned int hpe_interrupt_marker
:1;
112 unsigned int hpux_interrupt_marker
:1;
113 unsigned int reserved
:3;
114 unsigned int frame_size
:27;
119 /* Starting and ending offsets of the region described by
121 unsigned int start_offset
;
122 unsigned int end_offset
;
123 struct unwind_desc descriptor
;
126 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
127 control the entry and exit code they generate. It is also used in
128 creation of the correct stack unwind descriptors.
130 NOTE: GAS does not support .enter and .leave for the generation of
131 prologues and epilogues. FIXME.
133 The fields in structure roughly correspond to the arguments available on the
134 .callinfo pseudo-op. */
138 /* Should sr3 be saved in the prologue? */
141 /* Does this function make calls? */
144 /* The unwind descriptor being built. */
145 struct unwind_table ci_unwind
;
147 /* Name of this function. */
148 symbolS
*start_symbol
;
150 /* (temporary) symbol used to mark the end of this function. */
153 /* frags associated with start and end of this function. */
157 /* frags for starting/ending offset of this descriptor. */
158 fragS
*start_offset_frag
;
159 fragS
*end_offset_frag
;
161 /* The location within {start,end}_offset_frag to find the
162 {start,end}_offset. */
163 int start_frag_where
;
166 /* Fixups (relocations) for start_offset and end_offset. */
170 /* Next entry in the chain. */
171 struct call_info
*ci_next
;
174 /* Operand formats for FP instructions. Note not all FP instructions
175 allow all four formats to be used (for example fmpysub only allows
179 SGL
, DBL
, ILLEGAL_FMT
, QUAD
183 /* This fully describes the symbol types which may be attached to
184 an EXPORT or IMPORT directive. Only SOM uses this formation
185 (ELF has no need for it). */
189 SYMBOL_TYPE_ABSOLUTE
,
193 SYMBOL_TYPE_MILLICODE
,
195 SYMBOL_TYPE_PRI_PROG
,
196 SYMBOL_TYPE_SEC_PROG
,
199 /* This structure contains information needed to assemble
200 individual instructions. */
203 /* Holds the opcode after parsing by pa_ip. */
204 unsigned long opcode
;
206 /* Holds an expression associated with the current instruction. */
209 /* Does this instruction use PC-relative addressing. */
212 /* Floating point formats for operand1 and operand2. */
213 fp_operand_format fpof1
;
214 fp_operand_format fpof2
;
216 /* Holds the field selector for this instruction
217 (for example L%, LR%, etc). */
220 /* Holds any argument relocation bits associated with this
221 instruction. (instruction should be some sort of call). */
224 /* The format specification for this instruction. */
227 /* The relocation (if any) associated with this instruction. */
231 /* PA-89 floating point registers are arranged like this:
234 +--------------+--------------+
235 | 0 or 16L | 16 or 16R |
236 +--------------+--------------+
237 | 1 or 17L | 17 or 17R |
238 +--------------+--------------+
246 +--------------+--------------+
247 | 14 or 30L | 30 or 30R |
248 +--------------+--------------+
249 | 15 or 31L | 31 or 31R |
250 +--------------+--------------+
253 The following is a version of pa_parse_number that
254 handles the L/R notation and returns the correct
255 value to put into the instruction register field.
256 The correct value to put into the instruction is
257 encoded in the structure 'pa_89_fp_reg_struct'. */
259 struct pa_89_fp_reg_struct
261 /* The register number. */
268 /* Additional information needed to build argument relocation stubs. */
271 /* The argument relocation specification. */
272 unsigned int arg_reloc
;
274 /* Number of arguments. */
275 unsigned int arg_count
;
278 /* This structure defines an entry in the subspace dictionary
281 struct subspace_dictionary_chain
283 /* Index of containing space. */
284 unsigned long ssd_space_index
;
286 /* Nonzero if this space has been defined by the user code. */
287 unsigned int ssd_defined
;
289 /* Which quadrant within the space this subspace should be loaded into. */
290 unsigned char ssd_quadrant
;
292 /* Alignment (in bytes) for this subspace. */
293 unsigned long ssd_alignment
;
295 /* Access control bits to determine read/write/execute permissions
296 as well as gateway privilege promotions. */
297 unsigned char ssd_access_control_bits
;
299 /* A sorting key so that it is possible to specify ordering of
300 subspaces within a space. */
301 unsigned char ssd_sort_key
;
303 /* Nonzero of this space should be zero filled. */
304 unsigned long ssd_zero
;
306 /* Nonzero if this is a common subspace. */
307 unsigned char ssd_common
;
309 /* Nonzero if this is a common subspace which allows symbols to be
311 unsigned char ssd_dup_common
;
313 /* Nonzero if this subspace is loadable. Note loadable subspaces
314 must be contained within loadable spaces; unloadable subspaces
315 must be contained in unloadable spaces. */
316 unsigned char ssd_loadable
;
318 /* Nonzero if this subspace contains only code. */
319 unsigned char ssd_code_only
;
321 /* Starting offset of this subspace. */
322 unsigned long ssd_subspace_start
;
324 /* Length of this subspace. */
325 unsigned long ssd_subspace_length
;
327 /* Name of this subspace. */
330 /* GAS segment and subsegment associated with this subspace. */
334 /* Index of this subspace within the subspace dictionary of the object
335 file. Not used until object file is written. */
336 int object_file_index
;
338 /* The size of the last alignment request for this subspace. */
341 /* Next space in the subspace dictionary chain. */
342 struct subspace_dictionary_chain
*ssd_next
;
345 typedef struct subspace_dictionary_chain ssd_chain_struct
;
347 /* This structure defines an entry in the subspace dictionary
350 struct space_dictionary_chain
353 /* Holds the index into the string table of the name of this
355 unsigned int sd_name_index
;
357 /* Nonzero if the space is loadable. */
358 unsigned int sd_loadable
;
360 /* Nonzero if this space has been defined by the user code or
361 as a default space. */
362 unsigned int sd_defined
;
364 /* Nonzero if this spaces has been defined by the user code. */
365 unsigned int sd_user_defined
;
367 /* Nonzero if this space is not sharable. */
368 unsigned int sd_private
;
370 /* The space number (or index). */
371 unsigned int sd_spnum
;
373 /* The sort key for this space. May be used to determine how to lay
374 out the spaces within the object file. */
375 unsigned char sd_sort_key
;
377 /* The name of this subspace. */
380 /* GAS segment to which this subspace corresponds. */
383 /* Current subsegment number being used. */
386 /* The chain of subspaces contained within this space. */
387 ssd_chain_struct
*sd_subspaces
;
389 /* The next entry in the space dictionary chain. */
390 struct space_dictionary_chain
*sd_next
;
393 typedef struct space_dictionary_chain sd_chain_struct
;
395 /* Structure for previous label tracking. Needed so that alignments,
396 callinfo declarations, etc can be easily attached to a particular
398 typedef struct label_symbol_struct
400 struct symbol
*lss_label
;
401 sd_chain_struct
*lss_space
;
402 struct label_symbol_struct
*lss_next
;
406 /* This structure defines attributes of the default subspace
407 dictionary entries. */
409 struct default_subspace_dict
411 /* Name of the subspace. */
414 /* FIXME. Is this still needed? */
417 /* Nonzero if this subspace is loadable. */
420 /* Nonzero if this subspace contains only code. */
423 /* Nonzero if this is a common subspace. */
426 /* Nonzero if this is a common subspace which allows symbols
427 to be multiply defined. */
430 /* Nonzero if this subspace should be zero filled. */
433 /* Sort key for this subspace. */
436 /* Access control bits for this subspace. Can represent RWX access
437 as well as privilege level changes for gateways. */
440 /* Index of containing space. */
443 /* Alignment (in bytes) of this subspace. */
446 /* Quadrant within space where this subspace should be loaded. */
449 /* An index into the default spaces array. */
452 /* An alias for this section (or NULL if no alias exists). */
455 /* Subsegment associated with this subspace. */
459 /* This structure defines attributes of the default space
460 dictionary entries. */
462 struct default_space_dict
464 /* Name of the space. */
467 /* Space number. It is possible to identify spaces within
468 assembly code numerically! */
471 /* Nonzero if this space is loadable. */
474 /* Nonzero if this space is "defined". FIXME is still needed */
477 /* Nonzero if this space can not be shared. */
480 /* Sort key for this space. */
483 /* Segment associated with this space. */
486 /* An alias for this section (or NULL if no alias exists). */
490 /* Extra information needed to perform fixups (relocations) on the PA. */
491 struct hppa_fix_struct
493 /* The field selector. */
499 /* Format of fixup. */
502 /* Argument relocation bits. */
505 /* The unwind descriptor associated with this fixup. */
509 /* Structure to hold information about predefined registers. */
517 /* This structure defines the mapping from a FP condition string
518 to a condition number which can be recorded in an instruction. */
525 /* This structure defines a mapping from a field selector
526 string to a field selector type. */
527 struct selector_entry
533 /* Prototypes for functions local to tc-hppa.c. */
535 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
536 static void pa_cons
PARAMS ((int));
537 static void pa_data
PARAMS ((int));
538 static void pa_desc
PARAMS ((int));
539 static void pa_float_cons
PARAMS ((int));
540 static void pa_fill
PARAMS ((int));
541 static void pa_lcomm
PARAMS ((int));
542 static void pa_lsym
PARAMS ((int));
543 static void pa_stringer
PARAMS ((int));
544 static void pa_text
PARAMS ((int));
545 static void pa_version
PARAMS ((int));
546 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
547 static int get_expression
PARAMS ((char *));
548 static int pa_get_absolute_expression
PARAMS ((char *));
549 static int evaluate_absolute
PARAMS ((expressionS
, int));
550 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
551 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
552 static int pa_parse_nullif
PARAMS ((char **));
553 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
554 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
555 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
556 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
557 static void pa_block
PARAMS ((int));
558 static void pa_call
PARAMS ((int));
559 static void pa_call_args
PARAMS ((struct call_desc
*));
560 static void pa_callinfo
PARAMS ((int));
561 static void pa_code
PARAMS ((int));
562 static void pa_comm
PARAMS ((int));
563 static void pa_copyright
PARAMS ((int));
564 static void pa_end
PARAMS ((int));
565 static void pa_enter
PARAMS ((int));
566 static void pa_entry
PARAMS ((int));
567 static void pa_equ
PARAMS ((int));
568 static void pa_exit
PARAMS ((int));
569 static void pa_export
PARAMS ((int));
570 static void pa_export_args
PARAMS ((symbolS
*));
571 static void pa_import
PARAMS ((int));
572 static void pa_label
PARAMS ((int));
573 static void pa_leave
PARAMS ((int));
574 static void pa_origin
PARAMS ((int));
575 static void pa_proc
PARAMS ((int));
576 static void pa_procend
PARAMS ((int));
577 static void pa_space
PARAMS ((int));
578 static void pa_spnum
PARAMS ((int));
579 static void pa_subspace
PARAMS ((int));
580 static void pa_param
PARAMS ((int));
581 static void pa_undefine_label
PARAMS ((void));
582 static int need_89_opcode
PARAMS ((struct pa_it
*,
583 struct pa_89_fp_reg_struct
*));
584 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
585 static label_symbol_struct
*pa_get_label
PARAMS ((void));
586 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, char,
589 static ssd_chain_struct
* create_new_subspace
PARAMS ((sd_chain_struct
*,
594 static ssd_chain_struct
*update_subspace
PARAMS ((sd_chain_struct
*,
595 char *, char, char, char,
596 char, char, char, int,
597 int, int, int, subsegT
));
598 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
599 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *));
600 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
601 static ssd_chain_struct
* pa_subsegment_to_subspace
PARAMS ((asection
*,
603 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
604 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
605 static void pa_ip
PARAMS ((char *));
606 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
607 long, expressionS
*, int,
608 bfd_reloc_code_real_type
, long,
610 static void md_apply_fix_1
PARAMS ((fixS
*, long));
611 static int is_end_of_statement
PARAMS ((void));
612 static int reg_name_search
PARAMS ((char *));
613 static int pa_chk_field_selector
PARAMS ((char **));
614 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
615 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
616 static void process_exit
PARAMS ((void));
617 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
618 static void pa_align_subseg
PARAMS ((asection
*, subsegT
));
619 static int log2
PARAMS ((int));
620 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
621 static unsigned int pa_stringer_aux
PARAMS ((char *));
622 static void pa_spaces_begin
PARAMS ((void));
625 /* File and gloally scoped variable declarations. */
627 /* Root and final entry in the space chain. */
628 static sd_chain_struct
*space_dict_root
;
629 static sd_chain_struct
*space_dict_last
;
631 /* The current space and subspace. */
632 static sd_chain_struct
*current_space
;
633 static ssd_chain_struct
*current_subspace
;
635 /* Root of the call_info chain. */
636 static struct call_info
*call_info_root
;
638 /* The last call_info (for functions) structure
639 seen so it can be associated with fixups and
641 static struct call_info
*last_call_info
;
643 /* The last call description (for actual calls). */
644 static struct call_desc last_call_desc
;
646 /* Relaxation isn't supported for the PA yet. */
647 const relax_typeS md_relax_table
[] = {0};
649 /* Jumps are always the same size -- one instruction. */
650 int md_short_jump_size
= 4;
651 int md_long_jump_size
= 4;
653 /* handle of the OPCODE hash table */
654 static struct hash_control
*op_hash
= NULL
;
656 /* This array holds the chars that always start a comment. If the
657 pre-processor is disabled, these aren't very useful. */
658 const char comment_chars
[] = ";";
660 /* Table of pseudo ops for the PA. FIXME -- how many of these
661 are now redundant with the overall GAS and the object file
663 const pseudo_typeS md_pseudo_table
[] =
665 /* align pseudo-ops on the PA specify the actual alignment requested,
666 not the log2 of the requested alignment. */
667 {"align", s_align_bytes
, 8},
668 {"ALIGN", s_align_bytes
, 8},
669 {"block", pa_block
, 1},
670 {"BLOCK", pa_block
, 1},
671 {"blockz", pa_block
, 0},
672 {"BLOCKZ", pa_block
, 0},
673 {"byte", pa_cons
, 1},
674 {"BYTE", pa_cons
, 1},
675 {"call", pa_call
, 0},
676 {"CALL", pa_call
, 0},
677 {"callinfo", pa_callinfo
, 0},
678 {"CALLINFO", pa_callinfo
, 0},
679 {"code", pa_code
, 0},
680 {"CODE", pa_code
, 0},
681 {"comm", pa_comm
, 0},
682 {"COMM", pa_comm
, 0},
683 {"copyright", pa_copyright
, 0},
684 {"COPYRIGHT", pa_copyright
, 0},
685 {"data", pa_data
, 0},
686 {"DATA", pa_data
, 0},
687 {"desc", pa_desc
, 0},
688 {"DESC", pa_desc
, 0},
689 {"double", pa_float_cons
, 'd'},
690 {"DOUBLE", pa_float_cons
, 'd'},
693 {"enter", pa_enter
, 0},
694 {"ENTER", pa_enter
, 0},
695 {"entry", pa_entry
, 0},
696 {"ENTRY", pa_entry
, 0},
699 {"exit", pa_exit
, 0},
700 {"EXIT", pa_exit
, 0},
701 {"export", pa_export
, 0},
702 {"EXPORT", pa_export
, 0},
703 {"fill", pa_fill
, 0},
704 {"FILL", pa_fill
, 0},
705 {"float", pa_float_cons
, 'f'},
706 {"FLOAT", pa_float_cons
, 'f'},
707 {"half", pa_cons
, 2},
708 {"HALF", pa_cons
, 2},
709 {"import", pa_import
, 0},
710 {"IMPORT", pa_import
, 0},
713 {"label", pa_label
, 0},
714 {"LABEL", pa_label
, 0},
715 {"lcomm", pa_lcomm
, 0},
716 {"LCOMM", pa_lcomm
, 0},
717 {"leave", pa_leave
, 0},
718 {"LEAVE", pa_leave
, 0},
719 {"long", pa_cons
, 4},
720 {"LONG", pa_cons
, 4},
721 {"lsym", pa_lsym
, 0},
722 {"LSYM", pa_lsym
, 0},
723 {"octa", pa_cons
, 16},
724 {"OCTA", pa_cons
, 16},
725 {"org", pa_origin
, 0},
726 {"ORG", pa_origin
, 0},
727 {"origin", pa_origin
, 0},
728 {"ORIGIN", pa_origin
, 0},
729 {"param", pa_param
, 0},
730 {"PARAM", pa_param
, 0},
731 {"proc", pa_proc
, 0},
732 {"PROC", pa_proc
, 0},
733 {"procend", pa_procend
, 0},
734 {"PROCEND", pa_procend
, 0},
735 {"quad", pa_cons
, 8},
736 {"QUAD", pa_cons
, 8},
739 {"short", pa_cons
, 2},
740 {"SHORT", pa_cons
, 2},
741 {"single", pa_float_cons
, 'f'},
742 {"SINGLE", pa_float_cons
, 'f'},
743 {"space", pa_space
, 0},
744 {"SPACE", pa_space
, 0},
745 {"spnum", pa_spnum
, 0},
746 {"SPNUM", pa_spnum
, 0},
747 {"string", pa_stringer
, 0},
748 {"STRING", pa_stringer
, 0},
749 {"stringz", pa_stringer
, 1},
750 {"STRINGZ", pa_stringer
, 1},
751 {"subspa", pa_subspace
, 0},
752 {"SUBSPA", pa_subspace
, 0},
753 {"text", pa_text
, 0},
754 {"TEXT", pa_text
, 0},
755 {"version", pa_version
, 0},
756 {"VERSION", pa_version
, 0},
757 {"word", pa_cons
, 4},
758 {"WORD", pa_cons
, 4},
762 /* This array holds the chars that only start a comment at the beginning of
763 a line. If the line seems to have the form '# 123 filename'
764 .line and .file directives will appear in the pre-processed output.
766 Note that input_file.c hand checks for '#' at the beginning of the
767 first line of the input file. This is because the compiler outputs
768 #NO_APP at the beginning of its output.
770 Also note that '/*' will always start a comment. */
771 const char line_comment_chars
[] = "#";
773 /* This array holds the characters which act as line separators. */
774 const char line_separator_chars
[] = "!";
776 /* Chars that can be used to separate mant from exp in floating point nums. */
777 const char EXP_CHARS
[] = "eE";
779 /* Chars that mean this number is a floating point constant.
780 As in 0f12.456 or 0d1.2345e12.
782 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
783 changed in read.c. Ideally it shouldn't hae to know abou it at
784 all, but nothing is ideal around here. */
785 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
787 static struct pa_it the_insn
;
789 /* Points to the end of an expression just parsed by get_expressoin
790 and friends. FIXME. This shouldn't be handled with a file-global
792 static char *expr_end
;
794 /* Nonzero if a .callinfo appeared within the current procedure. */
795 static int callinfo_found
;
797 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
798 static int within_entry_exit
;
800 /* Nonzero if the assembler has completed exit processing for the
801 current procedure. */
802 static int exit_processing_complete
;
804 /* Nonzero if the assembler is currently within a procedure definition. */
805 static int within_procedure
;
807 /* Handle on strucutre which keep track of the last symbol
808 seen in each subspace. */
809 static label_symbol_struct
*label_symbols_rootp
= NULL
;
811 /* Holds the last field selector. */
812 static int hppa_field_selector
;
814 /* Nonzero if errors are to be printed. */
815 static int print_errors
= 1;
817 /* List of registers that are pre-defined:
819 Each general register has one predefined name of the form
820 %r<REGNUM> which has the value <REGNUM>.
822 Space and control registers are handled in a similar manner,
823 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
825 Likewise for the floating point registers, but of the form
826 %fr<REGNUM>. Floating point registers have additional predefined
827 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
828 again have the value <REGNUM>.
830 Many registers also have synonyms:
832 %r26 - %r23 have %arg0 - %arg3 as synonyms
833 %r28 - %r29 have %ret0 - %ret1 as synonyms
834 %r30 has %sp as a synonym
836 Almost every control register has a synonym; they are not listed
839 The table is sorted. Suitable for searching by a binary search. */
841 static const struct pd_reg pre_defined_registers
[] =
1051 /* This table is sorted by order of the length of the string. This is
1052 so we check for <> before we check for <. If we had a <> and checked
1053 for < first, we would get a false match. */
1054 static const struct fp_cond_map fp_cond_map
[] =
1090 static const struct selector_entry selector_table
[] =
1125 /* default space and subspace dictionaries */
1127 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1128 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1130 /* pre-defined subsegments (subspaces) for the HPPA. */
1131 #define SUBSEG_CODE 0
1132 #define SUBSEG_DATA 0
1133 #define SUBSEG_LIT 1
1134 #define SUBSEG_BSS 2
1135 #define SUBSEG_UNWIND 3
1136 #define SUBSEG_GDB_STRINGS 0
1137 #define SUBSEG_GDB_SYMBOLS 1
1139 static struct default_subspace_dict pa_def_subspaces
[] =
1141 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1142 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1143 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1144 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1145 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1146 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1149 static struct default_space_dict pa_def_spaces
[] =
1151 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1152 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1153 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1156 /* Misc local definitions used by the assembler. */
1158 /* Return nonzero if the string pointed to by S potentially represents
1159 a right or left half of a FP register */
1160 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1161 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1163 /* These macros are used to maintain spaces/subspaces. */
1164 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1165 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1166 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1167 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1168 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1169 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1170 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1171 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1173 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1174 #define SUBSPACE_DEFINED(ss_chain) (ss_chain)->ssd_defined
1175 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1176 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1177 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1178 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1179 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1180 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1181 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1182 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1183 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1184 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1185 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1186 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1188 #define is_DP_relative(exp) \
1189 ((exp).X_op == O_subtract \
1190 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1192 #define is_PC_relative(exp) \
1193 ((exp).X_op == O_subtract \
1194 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1196 #define is_complex(exp) \
1197 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1199 /* Actual functions to implement the PA specific code for the assembler. */
1201 /* Returns a pointer to the label_symbol_struct for the current space.
1202 or NULL if no label_symbol_struct exists for the current space. */
1204 static label_symbol_struct
*
1207 label_symbol_struct
*label_chain
;
1208 sd_chain_struct
*space_chain
= current_space
;
1210 for (label_chain
= label_symbols_rootp
;
1212 label_chain
= label_chain
->lss_next
)
1213 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1219 /* Defines a label for the current space. If one is already defined,
1220 this function will replace it with the new label. */
1223 pa_define_label (symbol
)
1226 label_symbol_struct
*label_chain
= pa_get_label ();
1227 sd_chain_struct
*space_chain
= current_space
;
1230 label_chain
->lss_label
= symbol
;
1233 /* Create a new label entry and add it to the head of the chain. */
1235 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1236 label_chain
->lss_label
= symbol
;
1237 label_chain
->lss_space
= space_chain
;
1238 label_chain
->lss_next
= NULL
;
1240 if (label_symbols_rootp
)
1241 label_chain
->lss_next
= label_symbols_rootp
;
1243 label_symbols_rootp
= label_chain
;
1247 /* Removes a label definition for the current space.
1248 If there is no label_symbol_struct entry, then no action is taken. */
1251 pa_undefine_label ()
1253 label_symbol_struct
*label_chain
;
1254 label_symbol_struct
*prev_label_chain
= NULL
;
1255 sd_chain_struct
*space_chain
= current_space
;
1257 for (label_chain
= label_symbols_rootp
;
1259 label_chain
= label_chain
->lss_next
)
1261 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1263 /* Remove the label from the chain and free its memory. */
1264 if (prev_label_chain
)
1265 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1267 label_symbols_rootp
= label_chain
->lss_next
;
1272 prev_label_chain
= label_chain
;
1277 /* An HPPA-specific version of fix_new. This is required because the HPPA
1278 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1279 results in the creation of an instance of an hppa_fix_struct. An
1280 hppa_fix_struct stores the extra information along with a pointer to the
1281 original fixS. This is attached to the original fixup via the
1282 tc_fix_data field. */
1285 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1286 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1290 symbolS
*add_symbol
;
1294 bfd_reloc_code_real_type r_type
;
1302 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1303 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1306 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1308 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1309 new_fix
->tc_fix_data
= hppa_fix
;
1310 hppa_fix
->fx_r_type
= r_type
;
1311 hppa_fix
->fx_r_field
= r_field
;
1312 hppa_fix
->fx_r_format
= r_format
;
1313 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1315 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1319 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1320 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1323 parse_cons_expression_hppa (exp
)
1326 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1330 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1331 hppa_field_selector is set by the parse_cons_expression_hppa. */
1334 cons_fix_new_hppa (frag
, where
, size
, exp
)
1340 unsigned int reloc_type
;
1342 if (is_DP_relative (*exp
))
1343 reloc_type
= R_HPPA_GOTOFF
;
1344 else if (is_complex (*exp
))
1345 reloc_type
= R_HPPA_COMPLEX
;
1347 reloc_type
= R_HPPA
;
1349 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1350 as_warn ("Invalid field selector. Assuming F%%.");
1352 fix_new_hppa (frag
, where
, size
,
1353 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1354 hppa_field_selector
, 32, 0, (char *) 0);
1357 /* This function is called once, at assembler startup time. It should
1358 set up all the tables, etc. that the MD part of the assembler will need. */
1363 char *retval
= NULL
;
1367 last_call_info
= NULL
;
1368 call_info_root
= NULL
;
1370 /* Folding of text and data segments fails miserably on the PA.
1371 Warn user and disable "-R" option. */
1374 as_warn ("-R option not supported on this target.");
1375 flag_readonly_data_in_text
= 0;
1381 op_hash
= hash_new ();
1382 if (op_hash
== NULL
)
1383 as_fatal ("Virtual memory exhausted");
1385 while (i
< NUMOPCODES
)
1387 const char *name
= pa_opcodes
[i
].name
;
1388 retval
= hash_insert (op_hash
, name
, &pa_opcodes
[i
]);
1389 if (retval
!= NULL
&& *retval
!= '\0')
1391 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1396 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1397 != pa_opcodes
[i
].match
)
1399 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1400 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1405 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1409 as_fatal ("Broken assembler. No assembly attempted.");
1411 /* SOM will change text_section. To make sure we never put
1412 anything into the old one switch to the new one now. */
1413 subseg_set (text_section
, 0);
1416 /* Called at the end of assembling a source file. Nothing to do
1417 at this point on the PA. */
1425 /* Assemble a single instruction storing it into a frag. */
1432 /* The had better be something to assemble. */
1435 /* Assemble the instruction. Results are saved into "the_insn". */
1438 /* Get somewhere to put the assembled instrution. */
1441 /* Output the opcode. */
1442 md_number_to_chars (to
, the_insn
.opcode
, 4);
1444 /* If necessary output more stuff. */
1445 if (the_insn
.reloc
!= R_HPPA_NONE
)
1446 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1447 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1448 the_insn
.reloc
, the_insn
.field_selector
,
1449 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1453 /* Do the real work for assembling a single instruction. Store results
1454 into the global "the_insn" variable.
1456 FIXME: Should define and use some functions/macros to handle
1457 various common insertions of information into the opcode. */
1463 char *error_message
= "";
1464 char *s
, c
, *argstart
, *name
, *save_s
;
1468 int reg
, s2
, s3
, m
, a
, uu
, cmpltr
, nullif
, flag
, sfu
, cond
;
1469 unsigned int im21
, im14
, im11
, im5
;
1470 unsigned long i
, opcode
;
1471 struct pa_opcode
*insn
;
1473 /* Skip to something interesting. */
1474 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1493 as_bad ("Unknown opcode: `%s'", str
);
1499 /* Convert everything into lower case. */
1502 if (isupper (*save_s
))
1503 *save_s
= tolower (*save_s
);
1507 /* Look up the opcode in the has table. */
1508 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1510 as_bad ("Unknown opcode: `%s'", str
);
1519 /* Mark the location where arguments for the instruction start, then
1520 start processing them. */
1524 /* Do some initialization. */
1525 opcode
= insn
->match
;
1526 bzero (&the_insn
, sizeof (the_insn
));
1528 the_insn
.reloc
= R_HPPA_NONE
;
1530 /* Build the opcode, checking as we go to make
1531 sure that the operands match. */
1532 for (args
= insn
->args
;; ++args
)
1537 /* End of arguments. */
1553 /* These must match exactly. */
1562 /* Handle a 5 bit register or control register field at 10. */
1565 reg
= pa_parse_number (&s
, 0);
1566 if (reg
< 32 && reg
>= 0)
1568 opcode
|= reg
<< 21;
1573 /* Handle a 5 bit register field at 15. */
1575 reg
= pa_parse_number (&s
, 0);
1576 if (reg
< 32 && reg
>= 0)
1578 opcode
|= reg
<< 16;
1583 /* Handle a 5 bit register field at 31. */
1586 reg
= pa_parse_number (&s
, 0);
1587 if (reg
< 32 && reg
>= 0)
1594 /* Handle a 5 bit field length at 31. */
1596 pa_get_absolute_expression (s
);
1597 if (the_insn
.exp
.X_op
== O_constant
)
1599 reg
= the_insn
.exp
.X_add_number
;
1600 if (reg
<= 32 && reg
> 0)
1609 /* Handle a 5 bit immediate at 15. */
1611 pa_get_absolute_expression (s
);
1612 if (the_insn
.exp
.X_add_number
> 15)
1614 as_bad ("5 bit immediate > 15. Set to 15");
1615 the_insn
.exp
.X_add_number
= 15;
1617 else if (the_insn
.exp
.X_add_number
< -16)
1619 as_bad ("5 bit immediate < -16. Set to -16");
1620 the_insn
.exp
.X_add_number
= -16;
1623 low_sign_unext (evaluate_absolute (the_insn
.exp
,
1624 the_insn
.field_selector
),
1626 opcode
|= (im5
<< 16);
1630 /* Handle a 2 bit space identifier at 17. */
1632 s2
= pa_parse_number (&s
, 0);
1633 if (s2
< 4 && s2
>= 0)
1640 /* Handle a 3 bit space identifier at 18. */
1642 s3
= pa_parse_number (&s
, 0);
1643 if (s3
< 8 && s3
>= 0)
1645 dis_assemble_3 (s3
, &s3
);
1651 /* Handle a completer for an indexing load or store. */
1656 while (*s
== ',' && i
< 2)
1659 if (strncasecmp (s
, "sm", 2) == 0)
1666 else if (strncasecmp (s
, "m", 1) == 0)
1668 else if (strncasecmp (s
, "s", 1) == 0)
1671 as_bad ("Invalid Indexed Load Completer.");
1676 as_bad ("Invalid Indexed Load Completer Syntax.");
1677 while (*s
== ' ' || *s
== '\t')
1684 /* Handle a short load/store completer. */
1691 if (strncasecmp (s
, "ma", 2) == 0)
1696 else if (strncasecmp (s
, "mb", 2) == 0)
1702 as_bad ("Invalid Short Load/Store Completer.");
1705 while (*s
== ' ' || *s
== '\t')
1711 /* Handle a stbys completer. */
1716 while (*s
== ',' && i
< 2)
1719 if (strncasecmp (s
, "m", 1) == 0)
1721 else if (strncasecmp (s
, "b", 1) == 0)
1723 else if (strncasecmp (s
, "e", 1) == 0)
1726 as_bad ("Invalid Store Bytes Short Completer");
1731 as_bad ("Invalid Store Bytes Short Completer");
1732 while (*s
== ' ' || *s
== '\t')
1738 /* Handle a non-negated compare/stubtract condition. */
1740 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1743 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1746 opcode
|= cmpltr
<< 13;
1749 /* Handle a negated or non-negated compare/subtract condition. */
1752 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1756 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1759 as_bad ("Invalid Compare/Subtract Condition.");
1764 /* Negated condition requires an opcode change. */
1768 opcode
|= cmpltr
<< 13;
1771 /* Handle a negated or non-negated add condition. */
1774 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1778 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1781 as_bad ("Invalid Compare/Subtract Condition");
1786 /* Negated condition requires an opcode change. */
1790 opcode
|= cmpltr
<< 13;
1793 /* Handle a compare/subtract condition. */
1800 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1805 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1808 as_bad ("Invalid Compare/Subtract Condition");
1812 opcode
|= cmpltr
<< 13;
1813 opcode
|= flag
<< 12;
1816 /* Handle a non-negated add condition. */
1825 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1829 if (strcmp (name
, "=") == 0)
1831 else if (strcmp (name
, "<") == 0)
1833 else if (strcmp (name
, "<=") == 0)
1835 else if (strcasecmp (name
, "nuv") == 0)
1837 else if (strcasecmp (name
, "znv") == 0)
1839 else if (strcasecmp (name
, "sv") == 0)
1841 else if (strcasecmp (name
, "od") == 0)
1843 else if (strcasecmp (name
, "n") == 0)
1845 else if (strcasecmp (name
, "tr") == 0)
1850 else if (strcasecmp (name
, "<>") == 0)
1855 else if (strcasecmp (name
, ">=") == 0)
1860 else if (strcasecmp (name
, ">") == 0)
1865 else if (strcasecmp (name
, "uv") == 0)
1870 else if (strcasecmp (name
, "vnz") == 0)
1875 else if (strcasecmp (name
, "nsv") == 0)
1880 else if (strcasecmp (name
, "ev") == 0)
1886 as_bad ("Invalid Add Condition: %s", name
);
1889 nullif
= pa_parse_nullif (&s
);
1890 opcode
|= nullif
<< 1;
1891 opcode
|= cmpltr
<< 13;
1892 opcode
|= flag
<< 12;
1895 /* Handle a logical instruction condition. */
1903 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1907 if (strcmp (name
, "=") == 0)
1909 else if (strcmp (name
, "<") == 0)
1911 else if (strcmp (name
, "<=") == 0)
1913 else if (strcasecmp (name
, "od") == 0)
1915 else if (strcasecmp (name
, "tr") == 0)
1920 else if (strcmp (name
, "<>") == 0)
1925 else if (strcmp (name
, ">=") == 0)
1930 else if (strcmp (name
, ">") == 0)
1935 else if (strcasecmp (name
, "ev") == 0)
1941 as_bad ("Invalid Logical Instruction Condition.");
1944 opcode
|= cmpltr
<< 13;
1945 opcode
|= flag
<< 12;
1948 /* Handle a unit instruction condition. */
1955 if (strncasecmp (s
, "sbz", 3) == 0)
1960 else if (strncasecmp (s
, "shz", 3) == 0)
1965 else if (strncasecmp (s
, "sdc", 3) == 0)
1970 else if (strncasecmp (s
, "sbc", 3) == 0)
1975 else if (strncasecmp (s
, "shc", 3) == 0)
1980 else if (strncasecmp (s
, "tr", 2) == 0)
1986 else if (strncasecmp (s
, "nbz", 3) == 0)
1992 else if (strncasecmp (s
, "nhz", 3) == 0)
1998 else if (strncasecmp (s
, "ndc", 3) == 0)
2004 else if (strncasecmp (s
, "nbc", 3) == 0)
2010 else if (strncasecmp (s
, "nhc", 3) == 0)
2017 as_bad ("Invalid Logical Instruction Condition.");
2019 opcode
|= cmpltr
<< 13;
2020 opcode
|= flag
<< 12;
2023 /* Handle a shift/extract/deposit condition. */
2031 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2035 if (strcmp (name
, "=") == 0)
2037 else if (strcmp (name
, "<") == 0)
2039 else if (strcasecmp (name
, "od") == 0)
2041 else if (strcasecmp (name
, "tr") == 0)
2043 else if (strcmp (name
, "<>") == 0)
2045 else if (strcmp (name
, ">=") == 0)
2047 else if (strcasecmp (name
, "ev") == 0)
2049 /* Handle movb,n. Put things back the way they were.
2050 This includes moving s back to where it started. */
2051 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
2058 as_bad ("Invalid Shift/Extract/Deposit Condition.");
2061 opcode
|= cmpltr
<< 13;
2064 /* Handle bvb and bb conditions. */
2070 if (strncmp (s
, "<", 1) == 0)
2075 else if (strncmp (s
, ">=", 2) == 0)
2081 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2083 opcode
|= cmpltr
<< 13;
2086 /* Handle a 5 bit immediate at 31. */
2089 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2090 the_insn
.field_selector
),
2096 /* Handle an unsigned 5 bit immediate at 31. */
2099 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2102 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2110 /* Handle an unsigned 5 bit immediate at 15. */
2113 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2116 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2120 opcode
|= im5
<< 16;
2124 /* Handle a 11 bit immediate at 31. */
2126 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2128 if (the_insn
.exp
.X_op
== O_constant
)
2130 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2131 the_insn
.field_selector
),
2137 if (is_DP_relative (the_insn
.exp
))
2138 the_insn
.reloc
= R_HPPA_GOTOFF
;
2139 else if (is_PC_relative (the_insn
.exp
))
2140 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2141 else if (is_complex (the_insn
.exp
))
2142 the_insn
.reloc
= R_HPPA_COMPLEX
;
2144 the_insn
.reloc
= R_HPPA
;
2145 the_insn
.format
= 11;
2150 /* Handle a 14 bit immediate at 31. */
2152 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2154 if (the_insn
.exp
.X_op
== O_constant
)
2156 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2157 the_insn
.field_selector
),
2159 if (the_insn
.field_selector
== e_rsel
)
2160 opcode
|= (im14
& 0xfff);
2166 if (is_DP_relative (the_insn
.exp
))
2167 the_insn
.reloc
= R_HPPA_GOTOFF
;
2168 else if (is_PC_relative (the_insn
.exp
))
2169 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2170 else if (is_complex (the_insn
.exp
))
2171 the_insn
.reloc
= R_HPPA_COMPLEX
;
2173 the_insn
.reloc
= R_HPPA
;
2174 the_insn
.format
= 14;
2179 /* Handle a 21 bit immediate at 31. */
2181 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2183 if (the_insn
.exp
.X_op
== O_constant
)
2185 dis_assemble_21 (evaluate_absolute (the_insn
.exp
,
2186 the_insn
.field_selector
),
2192 if (is_DP_relative (the_insn
.exp
))
2193 the_insn
.reloc
= R_HPPA_GOTOFF
;
2194 else if (is_PC_relative (the_insn
.exp
))
2195 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2196 else if (is_complex (the_insn
.exp
))
2197 the_insn
.reloc
= R_HPPA_COMPLEX
;
2199 the_insn
.reloc
= R_HPPA
;
2200 the_insn
.format
= 21;
2205 /* Handle a nullification completer for branch instructions. */
2207 nullif
= pa_parse_nullif (&s
);
2208 opcode
|= nullif
<< 1;
2211 /* Handle a 12 bit branch displacement. */
2213 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2216 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L0\001"))
2218 unsigned int w1
, w
, result
;
2220 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 12,
2222 dis_assemble_12 (result
, &w1
, &w
);
2223 opcode
|= ((w1
<< 2) | w
);
2227 if (is_complex (the_insn
.exp
))
2228 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2230 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2231 the_insn
.format
= 12;
2232 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2233 bzero (&last_call_desc
, sizeof (struct call_desc
));
2238 /* Handle a 17 bit branch displacement. */
2240 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2243 if (the_insn
.exp
.X_add_symbol
)
2245 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2248 unsigned int w2
, w1
, w
, result
;
2250 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2252 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2253 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2257 if (is_complex (the_insn
.exp
))
2258 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2260 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2261 the_insn
.format
= 17;
2262 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2263 bzero (&last_call_desc
, sizeof (struct call_desc
));
2268 unsigned int w2
, w1
, w
, result
;
2270 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2271 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2272 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2277 /* Handle an absolute 17 bit branch target. */
2279 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2282 if (the_insn
.exp
.X_add_symbol
)
2284 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2287 unsigned int w2
, w1
, w
, result
;
2289 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2291 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2292 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2296 if (is_complex (the_insn
.exp
))
2297 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2299 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2300 the_insn
.format
= 17;
2305 unsigned int w2
, w1
, w
, result
;
2307 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2308 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2309 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2314 /* Handle a 5 bit shift count at 26. */
2317 if (the_insn
.exp
.X_op
== O_constant
)
2318 opcode
|= (((31 - the_insn
.exp
.X_add_number
) & 0x1f) << 5);
2322 /* Handle a 5 bit bit position at 26. */
2325 if (the_insn
.exp
.X_op
== O_constant
)
2326 opcode
|= (the_insn
.exp
.X_add_number
& 0x1f) << 5;
2330 /* Handle a 5 bit immediate at 10. */
2333 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2336 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2340 opcode
|= im5
<< 21;
2344 /* Handle a 13 bit immediate at 18. */
2346 pa_get_absolute_expression (s
);
2347 if (the_insn
.exp
.X_op
== O_constant
)
2348 opcode
|= (the_insn
.exp
.X_add_number
& 0x1fff) << 13;
2352 /* Handle a system control completer. */
2354 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2363 while (*s
== ' ' || *s
== '\t')
2367 /* Handle a 26 bit immediate at 31. */
2369 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2371 if (the_insn
.exp
.X_op
== O_constant
)
2373 opcode
|= ((evaluate_absolute (the_insn
.exp
,
2374 the_insn
.field_selector
)
2378 as_bad ("Invalid DIAG operand");
2382 /* Handle a 3 bit SFU identifier at 25. */
2384 sfu
= pa_parse_number (&s
, 0);
2385 if ((sfu
> 7) || (sfu
< 0))
2386 as_bad ("Invalid SFU identifier: %02x", sfu
);
2387 opcode
|= (sfu
& 7) << 6;
2390 /* We don't support any of these. FIXME. */
2397 /* Handle a source FP operand format completer. */
2399 flag
= pa_parse_fp_format (&s
);
2400 opcode
|= (int) flag
<< 11;
2401 the_insn
.fpof1
= flag
;
2404 /* Handle a destination FP operand format completer. */
2407 /* pa_parse_format needs the ',' prefix. */
2409 flag
= pa_parse_fp_format (&s
);
2410 opcode
|= (int) flag
<< 13;
2411 the_insn
.fpof2
= flag
;
2414 /* Handle FP compare conditions. */
2416 cond
= pa_parse_fp_cmp_cond (&s
);
2420 /* Handle L/R register halves like 't'. */
2423 struct pa_89_fp_reg_struct result
;
2425 pa_parse_number (&s
, &result
);
2426 if (result
.number_part
< 32 && result
.number_part
>= 0)
2428 opcode
|= (result
.number_part
& 0x1f);
2430 /* 0x30 opcodes are FP arithmetic operation opcodes
2431 and need to be turned into 0x38 opcodes. This
2432 is not necessary for loads/stores. */
2433 if (need_89_opcode (&the_insn
, &result
))
2435 if ((opcode
& 0xfc000000) == 0x30000000)
2437 opcode
|= (result
.l_r_select
& 1) << 6;
2442 opcode
|= (result
.l_r_select
& 1) << 6;
2450 /* Handle L/R register halves like 'b'. */
2453 struct pa_89_fp_reg_struct result
;
2455 pa_parse_number (&s
, &result
);
2456 if (result
.number_part
< 32 && result
.number_part
>= 0)
2458 opcode
|= (result
.number_part
& 0x1f) << 21;
2459 if (need_89_opcode (&the_insn
, &result
))
2461 opcode
|= (result
.l_r_select
& 1) << 7;
2469 /* Handle L/R register halves like 'x'. */
2472 struct pa_89_fp_reg_struct result
;
2474 pa_parse_number (&s
, &result
);
2475 if (result
.number_part
< 32 && result
.number_part
>= 0)
2477 opcode
|= (result
.number_part
& 0x1f) << 16;
2478 if (need_89_opcode (&the_insn
, &result
))
2480 opcode
|= (result
.l_r_select
& 1) << 12;
2488 /* Handle a 5 bit register field at 10. */
2491 struct pa_89_fp_reg_struct result
;
2494 status
= pa_parse_number (&s
, &result
);
2495 if (result
.number_part
< 32 && result
.number_part
>= 0)
2497 if (the_insn
.fpof1
== SGL
)
2499 result
.number_part
&= 0xF;
2500 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2502 opcode
|= result
.number_part
<< 21;
2508 /* Handle a 5 bit register field at 15. */
2511 struct pa_89_fp_reg_struct result
;
2514 status
= pa_parse_number (&s
, &result
);
2515 if (result
.number_part
< 32 && result
.number_part
>= 0)
2517 if (the_insn
.fpof1
== SGL
)
2519 result
.number_part
&= 0xF;
2520 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2522 opcode
|= result
.number_part
<< 16;
2528 /* Handle a 5 bit register field at 31. */
2531 struct pa_89_fp_reg_struct result
;
2534 status
= pa_parse_number (&s
, &result
);
2535 if (result
.number_part
< 32 && result
.number_part
>= 0)
2537 if (the_insn
.fpof1
== SGL
)
2539 result
.number_part
&= 0xF;
2540 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2542 opcode
|= result
.number_part
;
2548 /* Handle a 5 bit register field at 20. */
2551 struct pa_89_fp_reg_struct result
;
2554 status
= pa_parse_number (&s
, &result
);
2555 if (result
.number_part
< 32 && result
.number_part
>= 0)
2557 if (the_insn
.fpof1
== SGL
)
2559 result
.number_part
&= 0xF;
2560 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2562 opcode
|= result
.number_part
<< 11;
2568 /* Handle a 5 bit register field at 25. */
2571 struct pa_89_fp_reg_struct result
;
2574 status
= pa_parse_number (&s
, &result
);
2575 if (result
.number_part
< 32 && result
.number_part
>= 0)
2577 if (the_insn
.fpof1
== SGL
)
2579 result
.number_part
&= 0xF;
2580 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2582 opcode
|= result
.number_part
<< 6;
2588 /* Handle a floating point operand format at 26.
2589 Only allows single and double precision. */
2591 flag
= pa_parse_fp_format (&s
);
2597 the_insn
.fpof1
= flag
;
2603 as_bad ("Invalid Floating Point Operand Format.");
2613 /* Check if the args matched. */
2616 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2617 && !strcmp (insn
->name
, insn
[1].name
))
2625 as_bad ("Invalid operands %s", error_message
);
2632 the_insn
.opcode
= opcode
;
2636 /* Turn a string in input_line_pointer into a floating point constant of type
2637 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2638 emitted is stored in *sizeP . An error message or NULL is returned. */
2640 #define MAX_LITTLENUMS 6
2643 md_atof (type
, litP
, sizeP
)
2649 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2650 LITTLENUM_TYPE
*wordP
;
2682 return "Bad call to MD_ATOF()";
2684 t
= atof_ieee (input_line_pointer
, type
, words
);
2686 input_line_pointer
= t
;
2687 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2688 for (wordP
= words
; prec
--;)
2690 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2691 litP
+= sizeof (LITTLENUM_TYPE
);
2696 /* Write out big-endian. */
2699 md_number_to_chars (buf
, val
, n
)
2721 /* Translate internal representation of relocation info to BFD target
2725 tc_gen_reloc (section
, fixp
)
2730 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2731 bfd_reloc_code_real_type code
;
2732 static int unwind_reloc_fixp_cnt
= 0;
2733 static arelent
*unwind_reloc_entryP
= NULL
;
2734 static arelent
*no_relocs
= NULL
;
2736 bfd_reloc_code_real_type
**codes
;
2740 if (fixp
->fx_addsy
== 0)
2742 assert (hppa_fixp
!= 0);
2743 assert (section
!= 0);
2746 /* Yuk. I would really like to push all this ELF specific unwind
2747 crud into BFD and the linker. That's how SOM does it -- and
2748 if we could make ELF emulate that then we could share more code
2749 in GAS (and potentially a gnu-linker later).
2751 Unwind section relocations are handled in a special way.
2752 The relocations for the .unwind section are originally
2753 built in the usual way. That is, for each unwind table
2754 entry there are two relocations: one for the beginning of
2755 the function and one for the end.
2757 The first time we enter this function we create a
2758 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2759 of the relocation is initialized to 0. Each additional
2760 pair of times this function is called for the unwind
2761 section represents an additional unwind table entry. Thus,
2762 the addend of the relocation should end up to be the number
2763 of unwind table entries. */
2764 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2766 if (unwind_reloc_entryP
== NULL
)
2768 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2770 assert (reloc
!= 0);
2771 unwind_reloc_entryP
= reloc
;
2772 unwind_reloc_fixp_cnt
++;
2773 unwind_reloc_entryP
->address
2774 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2775 /* A pointer to any function will do. We only
2776 need one to tell us what section the unwind
2777 relocations are for. */
2778 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2779 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2780 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2781 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2782 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2783 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2784 sizeof (arelent
*) * 2);
2785 assert (relocs
!= 0);
2786 relocs
[0] = unwind_reloc_entryP
;
2790 unwind_reloc_fixp_cnt
++;
2791 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2797 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2798 assert (reloc
!= 0);
2800 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2801 codes
= hppa_gen_reloc_type (stdoutput
,
2803 hppa_fixp
->fx_r_format
,
2804 hppa_fixp
->fx_r_field
);
2806 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2809 relocs
= (arelent
**)
2810 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2811 assert (relocs
!= 0);
2813 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2814 sizeof (arelent
) * n_relocs
);
2816 assert (reloc
!= 0);
2818 for (i
= 0; i
< n_relocs
; i
++)
2819 relocs
[i
] = &reloc
[i
];
2821 relocs
[n_relocs
] = NULL
;
2824 switch (fixp
->fx_r_type
)
2826 case R_HPPA_COMPLEX
:
2827 case R_HPPA_COMPLEX_PCREL_CALL
:
2828 case R_HPPA_COMPLEX_ABS_CALL
:
2829 assert (n_relocs
== 5);
2831 for (i
= 0; i
< n_relocs
; i
++)
2833 reloc
[i
].sym_ptr_ptr
= NULL
;
2834 reloc
[i
].address
= 0;
2835 reloc
[i
].addend
= 0;
2836 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2837 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2840 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2841 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2842 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2844 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2845 reloc
[3].addend
= fixp
->fx_addnumber
;
2846 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2847 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2848 reloc
[1].addend
= fixp
->fx_addnumber
;
2853 assert (n_relocs
== 1);
2857 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2858 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2859 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2860 reloc
->addend
= 0; /* default */
2862 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2864 /* Now, do any processing that is dependent on the relocation type. */
2867 case R_HPPA_PLABEL_32
:
2868 case R_HPPA_PLABEL_11
:
2869 case R_HPPA_PLABEL_14
:
2870 case R_HPPA_PLABEL_L21
:
2871 case R_HPPA_PLABEL_R11
:
2872 case R_HPPA_PLABEL_R14
:
2873 /* For plabel relocations, the addend of the
2874 relocation should be either 0 (no static link) or 2
2875 (static link required).
2877 FIXME: assume that fx_addnumber contains this
2879 reloc
->addend
= fixp
->fx_addnumber
;
2882 case R_HPPA_ABS_CALL_11
:
2883 case R_HPPA_ABS_CALL_14
:
2884 case R_HPPA_ABS_CALL_17
:
2885 case R_HPPA_ABS_CALL_L21
:
2886 case R_HPPA_ABS_CALL_R11
:
2887 case R_HPPA_ABS_CALL_R14
:
2888 case R_HPPA_ABS_CALL_R17
:
2889 case R_HPPA_ABS_CALL_LS21
:
2890 case R_HPPA_ABS_CALL_RS11
:
2891 case R_HPPA_ABS_CALL_RS14
:
2892 case R_HPPA_ABS_CALL_RS17
:
2893 case R_HPPA_ABS_CALL_LD21
:
2894 case R_HPPA_ABS_CALL_RD11
:
2895 case R_HPPA_ABS_CALL_RD14
:
2896 case R_HPPA_ABS_CALL_RD17
:
2897 case R_HPPA_ABS_CALL_LR21
:
2898 case R_HPPA_ABS_CALL_RR14
:
2899 case R_HPPA_ABS_CALL_RR17
:
2901 case R_HPPA_PCREL_CALL_11
:
2902 case R_HPPA_PCREL_CALL_14
:
2903 case R_HPPA_PCREL_CALL_17
:
2904 case R_HPPA_PCREL_CALL_L21
:
2905 case R_HPPA_PCREL_CALL_R11
:
2906 case R_HPPA_PCREL_CALL_R14
:
2907 case R_HPPA_PCREL_CALL_R17
:
2908 case R_HPPA_PCREL_CALL_LS21
:
2909 case R_HPPA_PCREL_CALL_RS11
:
2910 case R_HPPA_PCREL_CALL_RS14
:
2911 case R_HPPA_PCREL_CALL_RS17
:
2912 case R_HPPA_PCREL_CALL_LD21
:
2913 case R_HPPA_PCREL_CALL_RD11
:
2914 case R_HPPA_PCREL_CALL_RD14
:
2915 case R_HPPA_PCREL_CALL_RD17
:
2916 case R_HPPA_PCREL_CALL_LR21
:
2917 case R_HPPA_PCREL_CALL_RR14
:
2918 case R_HPPA_PCREL_CALL_RR17
:
2919 /* The constant is stored in the instruction. */
2920 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2923 reloc
->addend
= fixp
->fx_addnumber
;
2930 /* Preliminary relocation handling for SOM. Needs to handle
2931 COMPLEX relocations (yes, I've seen them occur) and it will
2932 need to handle R_ENTRY/R_EXIT relocations in the very near future
2933 (for generating unwinds). */
2934 switch (fixp
->fx_r_type
)
2936 case R_HPPA_COMPLEX
:
2937 case R_HPPA_COMPLEX_PCREL_CALL
:
2938 case R_HPPA_COMPLEX_ABS_CALL
:
2942 assert (n_relocs
== 1);
2946 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2947 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2948 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2955 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2958 reloc
->addend
= fixp
->fx_addnumber
;
2968 /* Process any machine dependent frag types. */
2971 md_convert_frag (abfd
, sec
, fragP
)
2973 register asection
*sec
;
2974 register fragS
*fragP
;
2976 unsigned int address
;
2978 if (fragP
->fr_type
== rs_machine_dependent
)
2980 switch ((int) fragP
->fr_subtype
)
2983 fragP
->fr_type
= rs_fill
;
2984 know (fragP
->fr_var
== 1);
2985 know (fragP
->fr_next
);
2986 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2987 if (address
% fragP
->fr_offset
)
2990 fragP
->fr_next
->fr_address
2995 fragP
->fr_offset
= 0;
3001 /* Round up a section size to the appropriate boundary. */
3004 md_section_align (segment
, size
)
3008 int align
= bfd_get_section_alignment (stdoutput
, segment
);
3009 int align2
= (1 << align
) - 1;
3011 return (size
+ align2
) & ~align2
;
3015 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3017 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3019 addressT from_addr
, to_addr
;
3023 fprintf (stderr
, "pa_create_short_jmp\n");
3027 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3029 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3031 addressT from_addr
, to_addr
;
3035 fprintf (stderr
, "pa_create_long_jump\n");
3039 /* Return the approximate size of a frag before relaxation has occurred. */
3041 md_estimate_size_before_relax (fragP
, segment
)
3042 register fragS
*fragP
;
3049 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3055 /* Parse machine dependent options. There are none on the PA. */
3057 md_parse_option (argP
, cntP
, vecP
)
3065 /* We have no need to default values of symbols. */
3068 md_undefined_symbol (name
)
3074 /* Parse an operand that is machine-specific.
3075 We just return without modifying the expression as we have nothing
3079 md_operand (expressionP
)
3080 expressionS
*expressionP
;
3084 /* Helper function for md_apply_fix. Actually determine if the fix
3085 can be applied, and if so, apply it.
3087 If a fix is applied, then set fx_addsy to NULL which indicates
3088 the fix was applied and need not be emitted into the object file. */
3091 md_apply_fix_1 (fixP
, val
)
3095 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3096 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
3097 long new_val
, result
;
3098 unsigned int w1
, w2
, w
;
3100 /* There should have been an HPPA specific fixup associated
3101 with the GAS fixup. */
3104 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3105 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3107 /* Sanity check the fixup type. */
3108 /* Is this really necessary? */
3109 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3112 /* Remember this value for emit_reloc. FIXME, is this braindamage
3113 documented anywhere!?! */
3114 fixP
->fx_addnumber
= val
;
3116 /* Check if this is an undefined symbol. No relocation can
3117 possibly be performed in this case. */
3118 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3120 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3125 /* Handle all opcodes with the 'j' operand type. */
3127 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3129 /* Mask off 14 bits to be changed. */
3130 bfd_put_32 (stdoutput
,
3131 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3133 low_sign_unext (new_val
, 14, &result
);
3136 /* Handle all opcodes with the 'k' operand type. */
3138 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3140 /* Mask off 21 bits to be changed. */
3141 bfd_put_32 (stdoutput
,
3142 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3144 dis_assemble_21 (new_val
, &result
);
3147 /* Handle all the opcodes with the 'i' operand type. */
3149 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3151 /* Mask off 11 bits to be changed. */
3152 bfd_put_32 (stdoutput
,
3153 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3155 low_sign_unext (new_val
, 11, &result
);
3158 /* Handle all the opcodes with the 'w' operand type. */
3160 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3162 /* Mask off 11 bits to be changed. */
3163 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3164 bfd_put_32 (stdoutput
,
3165 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3168 dis_assemble_12 (result
, &w1
, &w
);
3169 result
= ((w1
<< 2) | w
);
3170 fixP
->fx_addsy
= NULL
;
3173 #define too_far(VAL, NUM_BITS) \
3174 (((int)(VAL) > (1 << (NUM_BITS)) - 1) || ((int)(VAL) < (-1 << (NUM_BITS))))
3176 #define stub_needed(CALLER, CALLEE) \
3177 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3179 /* Handle some of the opcodes with the 'W' operand type. */
3181 /* If a long-call stub or argument relocation stub is
3182 needed, then we can not apply this relocation, instead
3183 the linker must handle it. */
3184 if (too_far (val
, 18)
3185 || stub_needed (((obj_symbol_type
*)
3186 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3187 hppa_fixP
->fx_arg_reloc
))
3190 /* No stubs were needed, we can perform this relocation. */
3191 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3193 /* Mask off 17 bits to be changed. */
3194 bfd_put_32 (stdoutput
,
3195 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3197 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3198 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3199 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3200 fixP
->fx_addsy
= NULL
;
3208 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3209 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3210 result
= fixP
->fx_addnumber
;
3215 fixP
->fx_addnumber
= fixP
->fx_offset
;
3216 bfd_put_32 (stdoutput
, 0, buf
);
3225 as_bad ("bad relocation type/fmt: 0x%02x/0x%02x",
3226 fixP
->fx_r_type
, fmt
);
3230 /* Insert the relocation. */
3231 buf
[0] |= (result
& 0xff000000) >> 24;
3232 buf
[1] |= (result
& 0x00ff0000) >> 16;
3233 buf
[2] |= (result
& 0x0000ff00) >> 8;
3234 buf
[3] |= result
& 0x000000ff;
3237 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3238 (unsigned int) fixP
, fixP
->fx_r_type
);
3241 /* Apply a fix into a frag's data (if possible). */
3244 md_apply_fix (fixP
, valp
)
3248 md_apply_fix_1 (fixP
, (long) *valp
);
3252 /* Exactly what point is a PC-relative offset relative TO?
3253 On the PA, they're relative to the address of the offset. */
3256 md_pcrel_from (fixP
)
3259 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3262 /* Return nonzero if the input line pointer is at the end of
3266 is_end_of_statement ()
3268 return ((*input_line_pointer
== '\n')
3269 || (*input_line_pointer
== ';')
3270 || (*input_line_pointer
== '!'));
3273 /* Read a number from S. The number might come in one of many forms,
3274 the most common will be a hex or decimal constant, but it could be
3275 a pre-defined register (Yuk!), or an absolute symbol.
3277 Return a number or -1 for failure.
3279 When parsing PA-89 FP register numbers RESULT will be
3280 the address of a structure to return information about
3281 L/R half of FP registers, store results there as appropriate.
3283 pa_parse_number can not handle negative constants and will fail
3284 horribly if it is passed such a constant. */
3287 pa_parse_number (s
, result
)
3289 struct pa_89_fp_reg_struct
*result
;
3298 /* Skip whitespace before the number. */
3299 while (*p
== ' ' || *p
== '\t')
3302 /* Store info in RESULT if requested by caller. */
3305 result
->number_part
= -1;
3306 result
->l_r_select
= -1;
3312 /* Looks like a number. */
3315 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3317 /* The number is specified in hex. */
3319 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3320 || ((*p
>= 'A') && (*p
<= 'F')))
3323 num
= num
* 16 + *p
- '0';
3324 else if (*p
>= 'a' && *p
<= 'f')
3325 num
= num
* 16 + *p
- 'a' + 10;
3327 num
= num
* 16 + *p
- 'A' + 10;
3333 /* The number is specified in decimal. */
3334 while (isdigit (*p
))
3336 num
= num
* 10 + *p
- '0';
3341 /* Store info in RESULT if requested by the caller. */
3344 result
->number_part
= num
;
3346 if (IS_R_SELECT (p
))
3348 result
->l_r_select
= 1;
3351 else if (IS_L_SELECT (p
))
3353 result
->l_r_select
= 0;
3357 result
->l_r_select
= 0;
3362 /* The number might be a predefined register. */
3367 /* Tege hack: Special case for general registers as the general
3368 code makes a binary search with case translation, and is VERY
3373 if (*p
== 'e' && *(p
+ 1) == 't'
3374 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3377 num
= *p
- '0' + 28;
3380 else if (!isdigit (*p
))
3381 as_bad ("Undefined register: '%s'. ASSUMING 0", name
);
3385 num
= num
* 10 + *p
++ - '0';
3386 while (isdigit (*p
));
3391 /* Do a normal register search. */
3392 while (is_part_of_name (c
))
3398 status
= reg_name_search (name
);
3404 as_bad ("Undefined register: '%s'. ASSUMING 0", name
);
3411 /* Store info in RESULT if requested by caller. */
3414 result
->number_part
= num
;
3415 if (IS_R_SELECT (p
- 1))
3416 result
->l_r_select
= 1;
3417 else if (IS_L_SELECT (p
- 1))
3418 result
->l_r_select
= 0;
3420 result
->l_r_select
= 0;
3425 /* And finally, it could be a symbol in the absolute section which
3426 is effectively a constant. */
3430 while (is_part_of_name (c
))
3436 if ((sym
= symbol_find (name
)) != NULL
)
3438 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3439 num
= S_GET_VALUE (sym
);
3443 as_bad ("Non-absolute constant: '%s'. ASSUMING 0", name
);
3451 as_bad ("Undefined absolute constant: '%s'. ASSUMING 0", name
);
3457 /* Store info in RESULT if requested by caller. */
3460 result
->number_part
= num
;
3461 if (IS_R_SELECT (p
- 1))
3462 result
->l_r_select
= 1;
3463 else if (IS_L_SELECT (p
- 1))
3464 result
->l_r_select
= 0;
3466 result
->l_r_select
= 0;
3474 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3476 /* Given NAME, find the register number associated with that name, return
3477 the integer value associated with the given name or -1 on failure. */
3480 reg_name_search (name
)
3483 int middle
, low
, high
;
3486 high
= REG_NAME_CNT
- 1;
3490 middle
= (low
+ high
) / 2;
3491 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3496 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3499 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3500 return (pre_defined_registers
[middle
].value
);
3506 /* Return nonzero if the given INSN and L/R information will require
3507 a new PA-89 opcode. */
3510 need_89_opcode (insn
, result
)
3512 struct pa_89_fp_reg_struct
*result
;
3514 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3520 /* Parse a condition for a fcmp instruction. Return the numerical
3521 code associated with the condition. */
3524 pa_parse_fp_cmp_cond (s
)
3531 for (i
= 0; i
< 32; i
++)
3533 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3534 strlen (fp_cond_map
[i
].string
)) == 0)
3536 cond
= fp_cond_map
[i
].cond
;
3537 *s
+= strlen (fp_cond_map
[i
].string
);
3538 while (**s
== ' ' || **s
== '\t')
3544 as_bad ("Invalid FP Compare Condition: %c", **s
);
3548 /* Parse an FP operand format completer returning the completer
3551 static fp_operand_format
3552 pa_parse_fp_format (s
)
3561 if (strncasecmp (*s
, "sgl", 3) == 0)
3566 else if (strncasecmp (*s
, "dbl", 3) == 0)
3571 else if (strncasecmp (*s
, "quad", 4) == 0)
3578 format
= ILLEGAL_FMT
;
3579 as_bad ("Invalid FP Operand Format: %3s", *s
);
3582 while (**s
== ' ' || **s
== '\t' || **s
== 0)
3588 /* Convert from a selector string into a selector type. */
3591 pa_chk_field_selector (str
)
3595 struct selector_entry
*tablep
;
3599 /* Read past any whitespace. */
3600 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3603 /* Yuk. Looks like a linear search through the table. With the
3604 frequence of some selectors it might make sense to sort the
3606 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3608 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3610 *str
+= strlen (tablep
->prefix
);
3611 selector
= tablep
->field_selector
;
3618 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3621 get_expression (str
)
3627 save_in
= input_line_pointer
;
3628 input_line_pointer
= str
;
3629 seg
= expression (&the_insn
.exp
);
3630 if (!(seg
== absolute_section
3631 || seg
== undefined_section
3632 || SEG_NORMAL (seg
)))
3634 as_warn ("Bad segment in expression.");
3635 expr_end
= input_line_pointer
;
3636 input_line_pointer
= save_in
;
3639 expr_end
= input_line_pointer
;
3640 input_line_pointer
= save_in
;
3644 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3646 pa_get_absolute_expression (str
)
3651 save_in
= input_line_pointer
;
3652 input_line_pointer
= str
;
3653 expression (&the_insn
.exp
);
3654 if (the_insn
.exp
.X_op
!= O_constant
)
3656 as_warn ("Bad segment (should be absolute).");
3657 expr_end
= input_line_pointer
;
3658 input_line_pointer
= save_in
;
3661 expr_end
= input_line_pointer
;
3662 input_line_pointer
= save_in
;
3666 /* Evaluate an absolute expression EXP which may be modified by
3667 the selector FIELD_SELECTOR. Return the value of the expression. */
3669 evaluate_absolute (exp
, field_selector
)
3675 value
= exp
.X_add_number
;
3677 switch (field_selector
)
3683 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3685 if (value
& 0x00000400)
3687 value
= (value
& 0xfffff800) >> 11;
3690 /* Sign extend from bit 21. */
3692 if (value
& 0x00000400)
3693 value
|= 0xfffff800;
3698 /* Arithmetic shift right 11 bits. */
3700 value
= (value
& 0xfffff800) >> 11;
3703 /* Set bits 0-20 to zero. */
3705 value
= value
& 0x7ff;
3708 /* Add 0x800 and arithmetic shift right 11 bits. */
3713 value
= (value
& 0xfffff800) >> 11;
3716 /* Set bitgs 0-21 to one. */
3718 value
|= 0xfffff800;
3721 /* This had better get fixed. It looks like we're quickly moving
3728 BAD_CASE (field_selector
);
3734 /* Given an argument location specification return the associated
3735 argument location number. */
3738 pa_build_arg_reloc (type_name
)
3742 if (strncasecmp (type_name
, "no", 2) == 0)
3744 if (strncasecmp (type_name
, "gr", 2) == 0)
3746 else if (strncasecmp (type_name
, "fr", 2) == 0)
3748 else if (strncasecmp (type_name
, "fu", 2) == 0)
3751 as_bad ("Invalid argument location: %s\n", type_name
);
3756 /* Encode and return an argument relocation specification for
3757 the given register in the location specified by arg_reloc. */
3760 pa_align_arg_reloc (reg
, arg_reloc
)
3762 unsigned int arg_reloc
;
3764 unsigned int new_reloc
;
3766 new_reloc
= arg_reloc
;
3782 as_bad ("Invalid argument description: %d", reg
);
3788 /* Parse a PA nullification completer (,n). Return nonzero if the
3789 completer was found; return zero if no completer was found. */
3801 if (strncasecmp (*s
, "n", 1) == 0)
3805 as_bad ("Invalid Nullification: (%c)", **s
);
3810 while (**s
== ' ' || **s
== '\t')
3816 /* Parse a non-negated compare/subtract completer returning the
3817 number (for encoding in instrutions) of the given completer.
3819 ISBRANCH specifies whether or not this is parsing a condition
3820 completer for a branch (vs a nullification completer for a
3821 computational instruction. */
3824 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3829 char *name
= *s
+ 1;
3837 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3841 if (strcmp (name
, "=") == 0)
3845 else if (strcmp (name
, "<") == 0)
3849 else if (strcmp (name
, "<=") == 0)
3853 else if (strcmp (name
, "<<") == 0)
3857 else if (strcmp (name
, "<<=") == 0)
3861 else if (strcasecmp (name
, "sv") == 0)
3865 else if (strcasecmp (name
, "od") == 0)
3869 /* If we have something like addb,n then there is no condition
3871 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3883 while (**s
== ' ' || **s
== '\t')
3887 /* Reset pointers if this was really a ,n for a branch instruction. */
3888 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3894 /* Parse a negated compare/subtract completer returning the
3895 number (for encoding in instrutions) of the given completer.
3897 ISBRANCH specifies whether or not this is parsing a condition
3898 completer for a branch (vs a nullification completer for a
3899 computational instruction. */
3902 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3907 char *name
= *s
+ 1;
3915 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3919 if (strcasecmp (name
, "tr") == 0)
3923 else if (strcmp (name
, "<>") == 0)
3927 else if (strcmp (name
, ">=") == 0)
3931 else if (strcmp (name
, ">") == 0)
3935 else if (strcmp (name
, ">>=") == 0)
3939 else if (strcmp (name
, ">>") == 0)
3943 else if (strcasecmp (name
, "nsv") == 0)
3947 else if (strcasecmp (name
, "ev") == 0)
3951 /* If we have something like addb,n then there is no condition
3953 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3965 while (**s
== ' ' || **s
== '\t')
3969 /* Reset pointers if this was really a ,n for a branch instruction. */
3970 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3976 /* Parse a non-negated addition completer returning the number
3977 (for encoding in instrutions) of the given completer.
3979 ISBRANCH specifies whether or not this is parsing a condition
3980 completer for a branch (vs a nullification completer for a
3981 computational instruction. */
3984 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3989 char *name
= *s
+ 1;
3997 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4001 if (strcmp (name
, "=") == 0)
4005 else if (strcmp (name
, "<") == 0)
4009 else if (strcmp (name
, "<=") == 0)
4013 else if (strcasecmp (name
, "nuv") == 0)
4017 else if (strcasecmp (name
, "znv") == 0)
4021 else if (strcasecmp (name
, "sv") == 0)
4025 else if (strcasecmp (name
, "od") == 0)
4029 /* If we have something like addb,n then there is no condition
4031 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4043 while (**s
== ' ' || **s
== '\t')
4047 /* Reset pointers if this was really a ,n for a branch instruction. */
4048 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4054 /* Parse a negated addition completer returning the number
4055 (for encoding in instrutions) of the given completer.
4057 ISBRANCH specifies whether or not this is parsing a condition
4058 completer for a branch (vs a nullification completer for a
4059 computational instruction. */
4062 pa_parse_neg_add_cmpltr (s
, isbranch
)
4067 char *name
= *s
+ 1;
4075 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4079 if (strcasecmp (name
, "tr") == 0)
4083 else if (strcmp (name
, "<>") == 0)
4087 else if (strcmp (name
, ">=") == 0)
4091 else if (strcmp (name
, ">") == 0)
4095 else if (strcmp (name
, "uv") == 0)
4099 else if (strcmp (name
, "vnz") == 0)
4103 else if (strcasecmp (name
, "nsv") == 0)
4107 else if (strcasecmp (name
, "ev") == 0)
4111 /* If we have something like addb,n then there is no condition
4113 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4125 while (**s
== ' ' || **s
== '\t')
4129 /* Reset pointers if this was really a ,n for a branch instruction. */
4130 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4136 /* Handle a .BLOCK type pseudo-op. */
4144 unsigned int temp_size
;
4147 temp_size
= get_absolute_expression ();
4149 /* Always fill with zeros, that's what the HP assembler does. */
4152 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4153 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4154 bzero (p
, temp_size
);
4156 /* Convert 2 bytes at a time. */
4158 for (i
= 0; i
< temp_size
; i
+= 2)
4160 md_number_to_chars (p
+ i
,
4162 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4165 pa_undefine_label ();
4166 demand_empty_rest_of_line ();
4170 /* Handle a .CALL pseudo-op. This involves storing away information
4171 about where arguments are to be found so the linker can detect
4172 (and correct) argument location mismatches between caller and callee. */
4178 pa_call_args (&last_call_desc
);
4179 demand_empty_rest_of_line ();
4183 /* Do the dirty work of building a call descriptor which describes
4184 where the caller placed arguments to a function call. */
4187 pa_call_args (call_desc
)
4188 struct call_desc
*call_desc
;
4191 unsigned int temp
, arg_reloc
;
4193 while (!is_end_of_statement ())
4195 name
= input_line_pointer
;
4196 c
= get_symbol_end ();
4197 /* Process a source argument. */
4198 if ((strncasecmp (name
, "argw", 4) == 0))
4200 temp
= atoi (name
+ 4);
4201 p
= input_line_pointer
;
4203 input_line_pointer
++;
4204 name
= input_line_pointer
;
4205 c
= get_symbol_end ();
4206 arg_reloc
= pa_build_arg_reloc (name
);
4207 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4209 /* Process a return value. */
4210 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4212 p
= input_line_pointer
;
4214 input_line_pointer
++;
4215 name
= input_line_pointer
;
4216 c
= get_symbol_end ();
4217 arg_reloc
= pa_build_arg_reloc (name
);
4218 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4222 as_bad ("Invalid .CALL argument: %s", name
);
4224 p
= input_line_pointer
;
4226 if (!is_end_of_statement ())
4227 input_line_pointer
++;
4231 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4234 is_same_frag (frag1
, frag2
)
4241 else if (frag2
== NULL
)
4243 else if (frag1
== frag2
)
4245 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4246 return (is_same_frag (frag1
, frag2
->fr_next
));
4251 /* Build an entry in the UNWIND subspace from the given
4252 function attributes in CALL_INFO. */
4255 pa_build_unwind_subspace (call_info
)
4256 struct call_info
*call_info
;
4259 asection
*seg
, *save_seg
;
4260 subsegT subseg
, save_subseg
;
4264 /* Get into the right seg/subseg. This may involve creating
4265 the seg the first time through. Make sure to have the
4266 old seg/subseg so that we can reset things when we are done. */
4267 subseg
= SUBSEG_UNWIND
;
4268 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4269 if (seg
== ASEC_NULL
)
4271 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4272 bfd_set_section_flags (stdoutput
, seg
,
4273 SEC_READONLY
| SEC_HAS_CONTENTS
4274 | SEC_LOAD
| SEC_RELOC
);
4278 save_subseg
= now_subseg
;
4279 subseg_set (seg
, subseg
);
4282 /* Get some space to hold relocation information for the unwind
4285 call_info
->start_offset_frag
= frag_now
;
4286 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4288 /* Relocation info. for start offset of the function. */
4289 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4290 call_info
->start_symbol
, (offsetT
) 0,
4291 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4294 /* We need to search for the first relocation involving the start_symbol of
4295 this call_info descriptor. */
4299 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4300 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4302 if (fixP
->fx_addsy
== call_info
->start_symbol
4303 || fixP
->fx_subsy
== call_info
->start_symbol
)
4305 call_info
->start_fix
= fixP
;
4312 call_info
->end_offset_frag
= frag_now
;
4313 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4315 /* Relocation info. for end offset of the function. */
4316 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4317 call_info
->end_symbol
, (offsetT
) 0,
4318 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4321 /* We need to search for the first relocation involving the end_symbol of
4322 this call_info descriptor. */
4326 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4327 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4329 if (fixP
->fx_addsy
== call_info
->end_symbol
4330 || fixP
->fx_subsy
== call_info
->end_symbol
)
4332 call_info
->end_fix
= fixP
;
4339 unwind
= (char *) &call_info
->ci_unwind
;
4340 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4344 FRAG_APPEND_1_CHAR (c
);
4348 /* Return back to the original segment/subsegment. */
4349 subseg_set (save_seg
, save_subseg
);
4352 /* Process a .CALLINFO pseudo-op. This information is used later
4353 to build unwind descriptors and maybe one day to support
4354 .ENTER and .LEAVE. */
4357 pa_callinfo (unused
)
4363 /* .CALLINFO must appear within a procedure definition. */
4364 if (!within_procedure
)
4365 as_bad (".callinfo is not within a procedure definition");
4367 /* Mark the fact that we found the .CALLINFO for the
4368 current procedure. */
4369 callinfo_found
= TRUE
;
4371 /* Iterate over the .CALLINFO arguments. */
4372 while (!is_end_of_statement ())
4374 name
= input_line_pointer
;
4375 c
= get_symbol_end ();
4376 /* Frame size specification. */
4377 if ((strncasecmp (name
, "frame", 5) == 0))
4379 p
= input_line_pointer
;
4381 input_line_pointer
++;
4382 temp
= get_absolute_expression ();
4383 if ((temp
& 0x3) != 0)
4385 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4389 /* callinfo is in bytes and unwind_desc is in 8 byte units. */
4390 last_call_info
->ci_unwind
.descriptor
.frame_size
= temp
/ 8;
4393 /* Entry register (GR, GR and SR) specifications. */
4394 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4396 p
= input_line_pointer
;
4398 input_line_pointer
++;
4399 temp
= get_absolute_expression ();
4400 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4401 even though %r19 is caller saved. I think this is a bug in
4402 the HP assembler, and we are not going to emulate it. */
4403 if (temp
< 3 || temp
> 18)
4404 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4405 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4407 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4409 p
= input_line_pointer
;
4411 input_line_pointer
++;
4412 temp
= get_absolute_expression ();
4413 /* Similarly the HP assembler takes 31 as the high bound even
4414 though %fr21 is the last callee saved floating point register. */
4415 if (temp
< 12 || temp
> 21)
4416 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4417 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4419 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4421 p
= input_line_pointer
;
4423 input_line_pointer
++;
4424 temp
= get_absolute_expression ();
4426 as_bad ("Value for ENTRY_SR must be 3\n");
4427 last_call_info
->entry_sr
= temp
- 2;
4429 /* Note whether or not this function performs any calls. */
4430 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4431 (strncasecmp (name
, "caller", 6) == 0))
4433 p
= input_line_pointer
;
4435 last_call_info
->makes_calls
= 1;
4437 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4439 p
= input_line_pointer
;
4441 last_call_info
->makes_calls
= 0;
4443 /* Should RP be saved into the stack. */
4444 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4446 p
= input_line_pointer
;
4448 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4450 /* Likewise for SP. */
4451 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4453 p
= input_line_pointer
;
4455 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4457 /* Is this an unwindable procedure. If so mark it so
4458 in the unwind descriptor. */
4459 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4461 p
= input_line_pointer
;
4463 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4465 /* Is this an interrupt routine. If so mark it in the
4466 unwind descriptor. */
4467 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4469 p
= input_line_pointer
;
4471 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4475 as_bad ("Invalid .CALLINFO argument: %s", name
);
4477 if (!is_end_of_statement ())
4478 input_line_pointer
++;
4481 demand_empty_rest_of_line ();
4485 /* Switch into the code subspace. */
4491 sd_chain_struct
*sdchain
;
4493 /* First time through it might be necessary to create the
4495 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4497 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4498 pa_def_spaces
[0].spnum
,
4499 pa_def_spaces
[0].loadable
,
4500 pa_def_spaces
[0].defined
,
4501 pa_def_spaces
[0].private,
4502 pa_def_spaces
[0].sort
,
4503 pa_def_spaces
[0].segment
, 0);
4506 SPACE_DEFINED (sdchain
) = 1;
4507 subseg_set (text_section
, SUBSEG_CODE
);
4508 demand_empty_rest_of_line ();
4512 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4513 the .comm pseudo-op has the following symtax:
4515 <label> .comm <length>
4517 where <label> is optional and is a symbol whose address will be the start of
4518 a block of memory <length> bytes long. <length> must be an absolute
4519 expression. <length> bytes will be allocated in the current space
4528 label_symbol_struct
*label_symbol
= pa_get_label ();
4531 symbol
= label_symbol
->lss_label
;
4536 size
= get_absolute_expression ();
4540 /* It is incorrect to check S_IS_DEFINED at this point as
4541 the symbol will *always* be defined. FIXME. How to
4542 correctly determine when this label really as been
4544 if (S_GET_VALUE (symbol
))
4546 if (S_GET_VALUE (symbol
) != size
)
4548 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4549 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4555 S_SET_VALUE (symbol
, size
);
4556 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4557 S_SET_EXTERNAL (symbol
);
4560 demand_empty_rest_of_line ();
4563 /* Process a .COPYRIGHT pseudo-op. */
4566 pa_copyright (unused
)
4573 if (*input_line_pointer
== '\"')
4575 ++input_line_pointer
;
4576 name
= input_line_pointer
;
4577 while ((c
= next_char_of_string ()) >= 0)
4579 c
= *input_line_pointer
;
4580 *input_line_pointer
= '\0';
4581 *(input_line_pointer
- 1) = '\0';
4583 /* FIXME. Not supported */
4586 *input_line_pointer
= c
;
4590 as_bad ("Expected \"-ed string");
4592 pa_undefine_label ();
4593 demand_empty_rest_of_line ();
4596 /* Process a .END pseudo-op. */
4602 demand_empty_rest_of_line ();
4606 /* Process a .ENTER pseudo-op. This is not supported. */
4615 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4623 if (!within_procedure
)
4624 as_bad ("Misplaced .entry. Ignored.");
4627 if (!callinfo_found
)
4628 as_bad ("Missing .callinfo.");
4630 last_call_info
->start_frag
= frag_now
;
4632 demand_empty_rest_of_line ();
4633 within_entry_exit
= TRUE
;
4634 where
= frag_more (0);
4636 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4637 It will not be on if no .EXPORT pseudo-op exists (static function). */
4638 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4643 /* Handle a .EQU pseudo-op. */
4649 label_symbol_struct
*label_symbol
= pa_get_label ();
4654 symbol
= label_symbol
->lss_label
;
4655 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4656 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4661 as_bad (".REG must use a label");
4663 as_bad (".EQU must use a label");
4666 pa_undefine_label ();
4667 demand_empty_rest_of_line ();
4671 /* Helper function. Does processing for the end of a function. This
4672 usually involves creating some relocations or building special
4673 symbols to mark the end of the function. */
4680 where
= frag_more (0);
4682 /* ELF does not have EXIT relocations. All we do is create a
4683 temporary symbol marking the end of the function. */
4685 char *name
= (char *) xmalloc (strlen ("L\001end_") +
4686 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
4692 strcpy (name
, "L\001end_");
4693 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
4695 symbolP
= symbol_find (name
);
4697 as_warn ("Symbol '%s' already defined.", name
);
4700 /* symbol value should be the offset of the
4701 last instruction of the function */
4702 symbolP
= symbol_new (name
, now_seg
,
4703 (valueT
) (obstack_next_free (&frags
)
4704 - frag_now
->fr_literal
- 4),
4708 symbolP
->bsym
->flags
= BSF_LOCAL
;
4709 symbol_table_insert (symbolP
);
4712 last_call_info
->end_symbol
= symbolP
;
4714 as_bad ("Symbol '%s' could not be created.", name
);
4718 as_bad ("No memory for symbol name.");
4721 /* Stuff away the location of the frag for the end of the function,
4722 and call pa_build_unwind_subspace to add an entry in the unwind
4724 last_call_info
->end_frag
= frag_now
;
4725 pa_build_unwind_subspace (last_call_info
);
4726 exit_processing_complete
= TRUE
;
4729 /* Process a .EXIT pseudo-op. */
4735 if (!within_procedure
)
4736 as_bad (".EXIT must appear within a procedure");
4739 if (!callinfo_found
)
4740 as_bad ("Missing .callinfo");
4743 if (!within_entry_exit
)
4744 as_bad ("No .ENTRY for this .EXIT");
4747 within_entry_exit
= FALSE
;
4752 demand_empty_rest_of_line ();
4756 /* Process a .EXPORT directive. This makes functions external
4757 and provides information such as argument relocation entries
4767 name
= input_line_pointer
;
4768 c
= get_symbol_end ();
4769 /* Make sure the given symbol exists. */
4770 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4772 as_bad ("Cannot define export symbol: %s\n", name
);
4773 p
= input_line_pointer
;
4775 input_line_pointer
++;
4779 /* OK. Set the external bits and process argument relocations. */
4780 S_SET_EXTERNAL (symbol
);
4781 p
= input_line_pointer
;
4783 if (!is_end_of_statement ())
4785 input_line_pointer
++;
4786 pa_export_args (symbol
);
4788 pa_build_symextn_section ();
4793 demand_empty_rest_of_line ();
4797 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4800 pa_export_args (symbolP
)
4804 unsigned int temp
, arg_reloc
;
4805 pa_symbol_type type
= SYMBOL_TYPE_UNKNOWN
;
4806 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4808 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4810 input_line_pointer
+= 8;
4811 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4812 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4813 type
= SYMBOL_TYPE_ABSOLUTE
;
4815 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4817 input_line_pointer
+= 4;
4818 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4819 type
= SYMBOL_TYPE_CODE
;
4821 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4823 input_line_pointer
+= 4;
4824 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4825 type
= SYMBOL_TYPE_DATA
;
4827 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4829 input_line_pointer
+= 5;
4830 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4831 type
= SYMBOL_TYPE_ENTRY
;
4833 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4835 input_line_pointer
+= 9;
4836 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4837 type
= SYMBOL_TYPE_MILLICODE
;
4839 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4841 input_line_pointer
+= 6;
4842 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4843 type
= SYMBOL_TYPE_PLABEL
;
4845 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4847 input_line_pointer
+= 8;
4848 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4849 type
= SYMBOL_TYPE_PRI_PROG
;
4851 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4853 input_line_pointer
+= 8;
4854 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4855 type
= SYMBOL_TYPE_SEC_PROG
;
4858 /* SOM requires much more information about symbol types
4859 than BFD understands. This is how we get this information
4860 to the SOM BFD backend. */
4861 #ifdef obj_set_symbol_type
4862 obj_set_symbol_type (symbolP
->bsym
, (int) type
);
4865 /* Now that the type of the exported symbol has been handled,
4866 handle any argument relocation information. */
4867 while (!is_end_of_statement ())
4869 if (*input_line_pointer
== ',')
4870 input_line_pointer
++;
4871 name
= input_line_pointer
;
4872 c
= get_symbol_end ();
4873 /* Argument sources. */
4874 if ((strncasecmp (name
, "argw", 4) == 0))
4876 p
= input_line_pointer
;
4878 input_line_pointer
++;
4879 temp
= atoi (name
+ 4);
4880 name
= input_line_pointer
;
4881 c
= get_symbol_end ();
4882 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4883 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4884 *input_line_pointer
= c
;
4886 /* The return value. */
4887 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4889 p
= input_line_pointer
;
4891 input_line_pointer
++;
4892 name
= input_line_pointer
;
4893 c
= get_symbol_end ();
4894 arg_reloc
= pa_build_arg_reloc (name
);
4895 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4896 *input_line_pointer
= c
;
4898 /* Privelege level. */
4899 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4901 p
= input_line_pointer
;
4903 input_line_pointer
++;
4904 temp
= atoi (input_line_pointer
);
4905 c
= get_symbol_end ();
4906 *input_line_pointer
= c
;
4910 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4911 p
= input_line_pointer
;
4914 if (!is_end_of_statement ())
4915 input_line_pointer
++;
4919 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4920 assembly file must either be defined in the assembly file, or
4921 explicitly IMPORTED from another. */
4930 name
= input_line_pointer
;
4931 c
= get_symbol_end ();
4933 symbol
= symbol_find_or_make (name
);
4934 p
= input_line_pointer
;
4937 if (!is_end_of_statement ())
4939 input_line_pointer
++;
4940 pa_export_args (symbol
);
4944 /* Sigh. To be compatable with the HP assembler and to help
4945 poorly written assembly code, we assign a type based on
4946 the the current segment. Note only BSF_FUNCTION really
4947 matters, we do not need to set the full SYMBOL_TYPE_* info here. */
4948 if (now_seg
== text_section
)
4949 symbol
->bsym
->flags
|= BSF_FUNCTION
;
4951 /* If the section is undefined, then the symbol is undefined
4952 Since this is an import, leave the section undefined. */
4953 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4956 demand_empty_rest_of_line ();
4960 /* Handle a .LABEL pseudo-op. */
4968 name
= input_line_pointer
;
4969 c
= get_symbol_end ();
4971 if (strlen (name
) > 0)
4974 p
= input_line_pointer
;
4979 as_warn ("Missing label name on .LABEL");
4982 if (!is_end_of_statement ())
4984 as_warn ("extra .LABEL arguments ignored.");
4985 ignore_rest_of_line ();
4987 demand_empty_rest_of_line ();
4991 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
5000 /* Handle a .ORIGIN pseudo-op. */
5007 pa_undefine_label ();
5011 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
5012 is for static functions. FIXME. Should share more code with .EXPORT. */
5021 name
= input_line_pointer
;
5022 c
= get_symbol_end ();
5024 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
5026 as_bad ("Cannot define static symbol: %s\n", name
);
5027 p
= input_line_pointer
;
5029 input_line_pointer
++;
5033 S_CLEAR_EXTERNAL (symbol
);
5034 p
= input_line_pointer
;
5036 if (!is_end_of_statement ())
5038 input_line_pointer
++;
5039 pa_export_args (symbol
);
5043 demand_empty_rest_of_line ();
5047 /* Handle a .PROC pseudo-op. It is used to mark the beginning
5048 of a procedure from a syntatical point of view. */
5054 struct call_info
*call_info
;
5056 if (within_procedure
)
5057 as_fatal ("Nested procedures");
5059 /* Reset global variables for new procedure. */
5060 callinfo_found
= FALSE
;
5061 within_procedure
= TRUE
;
5062 exit_processing_complete
= FALSE
;
5064 /* Create another call_info structure. */
5065 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5068 as_fatal ("Cannot allocate unwind descriptor\n");
5070 bzero (call_info
, sizeof (struct call_info
));
5072 call_info
->ci_next
= NULL
;
5074 if (call_info_root
== NULL
)
5076 call_info_root
= call_info
;
5077 last_call_info
= call_info
;
5081 last_call_info
->ci_next
= call_info
;
5082 last_call_info
= call_info
;
5085 /* set up defaults on call_info structure */
5087 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5088 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5089 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5090 call_info
->entry_sr
= ~0;
5091 call_info
->makes_calls
= 1;
5093 /* If we got a .PROC pseudo-op, we know that the function is defined
5094 locally. Make sure it gets into the symbol table. */
5096 label_symbol_struct
*label_symbol
= pa_get_label ();
5100 if (label_symbol
->lss_label
)
5102 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5103 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5106 as_bad ("Missing function name for .PROC (corrupted label)");
5109 as_bad ("Missing function name for .PROC");
5112 demand_empty_rest_of_line ();
5116 /* Process the syntatical end of a procedure. Make sure all the
5117 appropriate pseudo-ops were found within the procedure. */
5124 if (!within_procedure
)
5125 as_bad ("misplaced .procend");
5127 if (!callinfo_found
)
5128 as_bad ("Missing .callinfo for this procedure");
5130 if (within_entry_exit
)
5131 as_bad ("Missing .EXIT for a .ENTRY");
5133 if (!exit_processing_complete
)
5136 within_procedure
= FALSE
;
5137 demand_empty_rest_of_line ();
5141 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5142 then create a new space entry to hold the information specified
5143 by the parameters to the .SPACE directive. */
5145 static sd_chain_struct
*
5146 pa_parse_space_stmt (space_name
, create_flag
)
5150 char *name
, *ptemp
, c
;
5151 char loadable
, defined
, private, sort
;
5153 asection
*seg
= NULL
;
5154 sd_chain_struct
*space
;
5156 /* load default values */
5162 if (strcasecmp (space_name
, "$TEXT$") == 0)
5164 seg
= pa_def_spaces
[0].segment
;
5165 sort
= pa_def_spaces
[0].sort
;
5167 else if (strcasecmp (space_name
, "$PRIVATE$") == 0)
5169 seg
= pa_def_spaces
[1].segment
;
5170 sort
= pa_def_spaces
[1].sort
;
5173 if (!is_end_of_statement ())
5175 print_errors
= FALSE
;
5176 ptemp
= input_line_pointer
+ 1;
5177 /* First see if the space was specified as a number rather than
5178 as a name. According to the PA assembly manual the rest of
5179 the line should be ignored. */
5180 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5181 input_line_pointer
= ptemp
;
5184 while (!is_end_of_statement ())
5186 input_line_pointer
++;
5187 name
= input_line_pointer
;
5188 c
= get_symbol_end ();
5189 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5191 *input_line_pointer
= c
;
5192 input_line_pointer
++;
5193 spnum
= get_absolute_expression ();
5195 else if ((strncasecmp (name
, "SORT", 4) == 0))
5197 *input_line_pointer
= c
;
5198 input_line_pointer
++;
5199 sort
= get_absolute_expression ();
5201 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5203 *input_line_pointer
= c
;
5206 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5208 *input_line_pointer
= c
;
5211 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5213 *input_line_pointer
= c
;
5218 as_bad ("Invalid .SPACE argument");
5219 *input_line_pointer
= c
;
5220 if (! is_end_of_statement ())
5221 input_line_pointer
++;
5225 print_errors
= TRUE
;
5228 if (create_flag
&& seg
== NULL
)
5229 seg
= subseg_new (space_name
, 0);
5231 /* If create_flag is nonzero, then create the new space with
5232 the attributes computed above. Else set the values in
5233 an already existing space -- this can only happen for
5234 the first occurence of a built-in space. */
5236 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5237 private, sort
, seg
, 1);
5240 space
= is_defined_space (space_name
);
5241 SPACE_SPNUM (space
) = spnum
;
5242 SPACE_LOADABLE (space
) = loadable
& 1;
5243 SPACE_DEFINED (space
) = defined
& 1;
5244 SPACE_USER_DEFINED (space
) = 1;
5245 SPACE_PRIVATE (space
) = private & 1;
5246 SPACE_SORT (space
) = sort
& 0xff;
5247 space
->sd_seg
= seg
;
5250 #ifdef obj_set_section_attributes
5251 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5257 /* Adjust the frag's alignment according to the alignment needs
5258 of the given subspace/subsegment. */
5261 pa_align_subseg (seg
, subseg
)
5265 ssd_chain_struct
*now_subspace
;
5269 now_subspace
= pa_subsegment_to_subspace (seg
, subseg
);
5272 if (SUBSPACE_ALIGN (now_subspace
) == 0)
5273 alignment
= now_subspace
->ssd_last_align
;
5274 else if (now_subspace
->ssd_last_align
> SUBSPACE_ALIGN (now_subspace
))
5275 alignment
= now_subspace
->ssd_last_align
;
5277 alignment
= SUBSPACE_ALIGN (now_subspace
);
5279 while ((1 << shift
) < alignment
)
5283 shift
= bfd_get_section_alignment (stdoutput
, seg
);
5285 frag_align (shift
, 0);
5288 /* Handle a .SPACE pseudo-op; this switches the current space to the
5289 given space, creating the new space if necessary. */
5295 char *name
, c
, *space_name
, *save_s
;
5297 sd_chain_struct
*sd_chain
;
5299 if (within_procedure
)
5301 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5302 ignore_rest_of_line ();
5306 /* Check for some of the predefined spaces. FIXME: most of the code
5307 below is repeated several times, can we extract the common parts
5308 and place them into a subroutine or something similar? */
5309 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5311 input_line_pointer
+= 6;
5312 sd_chain
= is_defined_space ("$TEXT$");
5313 if (sd_chain
== NULL
)
5314 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5315 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5316 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5318 current_space
= sd_chain
;
5320 /* No need to align if we are already there. */
5321 if (now_seg
!= text_section
)
5322 pa_align_subseg (now_seg
, now_subseg
);
5324 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5327 = pa_subsegment_to_subspace (text_section
,
5328 sd_chain
->sd_last_subseg
);
5329 demand_empty_rest_of_line ();
5332 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5334 input_line_pointer
+= 9;
5335 sd_chain
= is_defined_space ("$PRIVATE$");
5336 if (sd_chain
== NULL
)
5337 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5338 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5339 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5341 current_space
= sd_chain
;
5343 /* No need to align if we are already there. */
5344 if (now_seg
!= data_section
)
5345 pa_align_subseg (now_seg
, now_subseg
);
5347 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5349 = pa_subsegment_to_subspace (data_section
,
5350 sd_chain
->sd_last_subseg
);
5351 demand_empty_rest_of_line ();
5354 if (!strncasecmp (input_line_pointer
,
5355 GDB_DEBUG_SPACE_NAME
,
5356 strlen (GDB_DEBUG_SPACE_NAME
)))
5358 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5359 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5360 if (sd_chain
== NULL
)
5361 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5362 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5363 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5365 current_space
= sd_chain
;
5368 asection
*gdb_section
5369 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5371 /* No need to align if we are already there. */
5372 if (strcmp (segment_name (now_seg
), GDB_DEBUG_SPACE_NAME
) != 0)
5373 pa_align_subseg (now_seg
, now_subseg
);
5375 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5377 = pa_subsegment_to_subspace (gdb_section
,
5378 sd_chain
->sd_last_subseg
);
5380 demand_empty_rest_of_line ();
5384 /* It could be a space specified by number. */
5386 save_s
= input_line_pointer
;
5387 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5389 if (sd_chain
= pa_find_space_by_number (temp
))
5391 current_space
= sd_chain
;
5393 if (now_seg
!= sd_chain
->sd_seg
)
5394 pa_align_subseg (now_seg
, now_subseg
);
5395 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5397 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5398 sd_chain
->sd_last_subseg
);
5399 demand_empty_rest_of_line ();
5404 /* Not a number, attempt to create a new space. */
5406 input_line_pointer
= save_s
;
5407 name
= input_line_pointer
;
5408 c
= get_symbol_end ();
5409 space_name
= xmalloc (strlen (name
) + 1);
5410 strcpy (space_name
, name
);
5411 *input_line_pointer
= c
;
5413 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5414 current_space
= sd_chain
;
5416 if (now_seg
!= sd_chain
->sd_seg
)
5417 pa_align_subseg (now_seg
, now_subseg
);
5418 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5419 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5420 sd_chain
->sd_last_subseg
);
5421 demand_empty_rest_of_line ();
5426 /* Switch to a new space. (I think). FIXME. */
5435 sd_chain_struct
*space
;
5437 name
= input_line_pointer
;
5438 c
= get_symbol_end ();
5439 space
= is_defined_space (name
);
5443 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5446 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5448 *input_line_pointer
= c
;
5449 demand_empty_rest_of_line ();
5453 /* If VALUE is an exact power of two between zero and 2^31, then
5454 return log2 (VALUE). Else return -1. */
5462 while ((1 << shift
) != value
&& shift
< 32)
5471 /* Handle a .SUBSPACE pseudo-op; this switches the current subspace to the
5472 given subspace, creating the new subspace if necessary.
5474 FIXME. Should mirror pa_space more closely, in particular how
5475 they're broken up into subroutines. */
5478 pa_subspace (unused
)
5481 char *name
, *ss_name
, *alias
, c
;
5482 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5483 int i
, access
, space_index
, alignment
, quadrant
, applicable
, flags
;
5484 sd_chain_struct
*space
;
5485 ssd_chain_struct
*ssd
;
5488 if (within_procedure
)
5490 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5491 ignore_rest_of_line ();
5495 name
= input_line_pointer
;
5496 c
= get_symbol_end ();
5497 ss_name
= xmalloc (strlen (name
) + 1);
5498 strcpy (ss_name
, name
);
5499 *input_line_pointer
= c
;
5501 /* Load default values. */
5514 space
= current_space
;
5515 ssd
= is_defined_subspace (ss_name
);
5516 /* Allow user to override the builtin attributes of subspaces. But
5517 only allow the attributes to be changed once! */
5518 if (ssd
&& SUBSPACE_DEFINED (ssd
))
5520 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5521 if (!is_end_of_statement ())
5522 as_warn ("Parameters of an existing subspace can\'t be modified");
5523 demand_empty_rest_of_line ();
5528 /* A new subspace. Load default values if it matches one of
5529 the builtin subspaces. */
5531 while (pa_def_subspaces
[i
].name
)
5533 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5535 loadable
= pa_def_subspaces
[i
].loadable
;
5536 common
= pa_def_subspaces
[i
].common
;
5537 dup_common
= pa_def_subspaces
[i
].dup_common
;
5538 code_only
= pa_def_subspaces
[i
].code_only
;
5539 zero
= pa_def_subspaces
[i
].zero
;
5540 space_index
= pa_def_subspaces
[i
].space_index
;
5541 alignment
= pa_def_subspaces
[i
].alignment
;
5542 quadrant
= pa_def_subspaces
[i
].quadrant
;
5543 access
= pa_def_subspaces
[i
].access
;
5544 sort
= pa_def_subspaces
[i
].sort
;
5545 if (USE_ALIASES
&& pa_def_subspaces
[i
].alias
)
5546 alias
= pa_def_subspaces
[i
].alias
;
5553 /* We should be working with a new subspace now. Fill in
5554 any information as specified by the user. */
5555 if (!is_end_of_statement ())
5557 input_line_pointer
++;
5558 while (!is_end_of_statement ())
5560 name
= input_line_pointer
;
5561 c
= get_symbol_end ();
5562 if ((strncasecmp (name
, "QUAD", 4) == 0))
5564 *input_line_pointer
= c
;
5565 input_line_pointer
++;
5566 quadrant
= get_absolute_expression ();
5568 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5570 *input_line_pointer
= c
;
5571 input_line_pointer
++;
5572 alignment
= get_absolute_expression ();
5573 if (log2 (alignment
) == -1)
5575 as_bad ("Alignment must be a power of 2");
5579 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5581 *input_line_pointer
= c
;
5582 input_line_pointer
++;
5583 access
= get_absolute_expression ();
5585 else if ((strncasecmp (name
, "SORT", 4) == 0))
5587 *input_line_pointer
= c
;
5588 input_line_pointer
++;
5589 sort
= get_absolute_expression ();
5591 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5593 *input_line_pointer
= c
;
5596 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5598 *input_line_pointer
= c
;
5601 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5603 *input_line_pointer
= c
;
5606 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5608 *input_line_pointer
= c
;
5611 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5613 *input_line_pointer
= c
;
5616 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5617 as_bad ("FIRST not supported as a .SUBSPACE argument");
5619 as_bad ("Invalid .SUBSPACE argument");
5620 if (!is_end_of_statement ())
5621 input_line_pointer
++;
5625 /* Compute a reasonable set of BFD flags based on the information
5626 in the .subspace directive. */
5627 applicable
= bfd_applicable_section_flags (stdoutput
);
5630 flags
|= (SEC_ALLOC
| SEC_LOAD
);
5633 if (common
|| dup_common
)
5634 flags
|= SEC_IS_COMMON
;
5636 /* This is a zero-filled subspace (eg BSS). */
5640 flags
|= SEC_RELOC
| SEC_HAS_CONTENTS
;
5641 applicable
&= flags
;
5643 /* If this is an existing subspace, then we want to use the
5644 segment already associated with the subspace.
5646 FIXME NOW! ELF BFD doesn't appear to be ready to deal with
5647 lots of sections. It might be a problem in the PA ELF
5648 code, I do not know yet. For now avoid creating anything
5649 but the "standard" sections for ELF. */
5651 section
= ssd
->ssd_seg
;
5653 section
= subseg_new (alias
, 0);
5654 else if (! alias
&& USE_ALIASES
)
5656 as_warn ("Ignoring subspace decl due to ELF BFD bugs.");
5657 demand_empty_rest_of_line ();
5661 section
= subseg_new (ss_name
, 0);
5663 /* Now set the flags. */
5664 bfd_set_section_flags (stdoutput
, section
, applicable
);
5666 /* Record any alignment request for this section. */
5667 record_alignment (section
, log2 (alignment
));
5669 /* Set the starting offset for this section. */
5670 bfd_set_section_vma (stdoutput
, section
,
5671 pa_subspace_start (space
, quadrant
));
5673 /* Now that all the flags are set, update an existing subspace,
5674 or create a new one. */
5677 current_subspace
= update_subspace (space
, ss_name
, loadable
,
5678 code_only
, common
, dup_common
,
5679 sort
, zero
, access
, space_index
,
5680 alignment
, quadrant
,
5683 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5685 dup_common
, zero
, sort
,
5686 access
, space_index
,
5687 alignment
, quadrant
, section
);
5689 demand_empty_rest_of_line ();
5690 current_subspace
->ssd_seg
= section
;
5691 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5693 SUBSPACE_DEFINED (current_subspace
) = 1;
5698 /* Create default space and subspace dictionaries. */
5705 space_dict_root
= NULL
;
5706 space_dict_last
= NULL
;
5709 while (pa_def_spaces
[i
].name
)
5713 /* Pick the right name to use for the new section. */
5714 if (pa_def_spaces
[i
].alias
&& USE_ALIASES
)
5715 name
= pa_def_spaces
[i
].alias
;
5717 name
= pa_def_spaces
[i
].name
;
5719 pa_def_spaces
[i
].segment
= subseg_new (name
, 0);
5720 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5721 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5722 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5723 pa_def_spaces
[i
].segment
, 0);
5728 while (pa_def_subspaces
[i
].name
)
5731 int applicable
, subsegment
;
5732 asection
*segment
= NULL
;
5733 sd_chain_struct
*space
;
5735 /* Pick the right name for the new section and pick the right
5736 subsegment number. */
5737 if (pa_def_subspaces
[i
].alias
&& USE_ALIASES
)
5739 name
= pa_def_subspaces
[i
].alias
;
5740 subsegment
= pa_def_subspaces
[i
].subsegment
;
5744 name
= pa_def_subspaces
[i
].name
;
5748 /* Create the new section. */
5749 segment
= subseg_new (name
, subsegment
);
5752 /* For SOM we want to replace the standard .text, .data, and .bss
5753 sections with our own. */
5754 if (! strcmp (pa_def_subspaces
[i
].name
, "$CODE$") && ! USE_ALIASES
)
5756 text_section
= segment
;
5757 applicable
= bfd_applicable_section_flags (stdoutput
);
5758 bfd_set_section_flags (stdoutput
, text_section
,
5759 applicable
& (SEC_ALLOC
| SEC_LOAD
5760 | SEC_RELOC
| SEC_CODE
5762 | SEC_HAS_CONTENTS
));
5764 else if (! strcmp (pa_def_subspaces
[i
].name
, "$DATA$") && ! USE_ALIASES
)
5766 data_section
= segment
;
5767 applicable
= bfd_applicable_section_flags (stdoutput
);
5768 bfd_set_section_flags (stdoutput
, data_section
,
5769 applicable
& (SEC_ALLOC
| SEC_LOAD
5771 | SEC_HAS_CONTENTS
));
5775 else if (! strcmp (pa_def_subspaces
[i
].name
, "$BSS$") && ! USE_ALIASES
)
5777 bss_section
= segment
;
5778 applicable
= bfd_applicable_section_flags (stdoutput
);
5779 bfd_set_section_flags (stdoutput
, bss_section
,
5780 applicable
& SEC_ALLOC
);
5783 /* Find the space associated with this subspace. */
5784 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].
5785 def_space_index
].segment
);
5788 as_fatal ("Internal error: Unable to find containing space for %s.",
5789 pa_def_subspaces
[i
].name
);
5792 create_new_subspace (space
, name
,
5793 pa_def_subspaces
[i
].loadable
,
5794 pa_def_subspaces
[i
].code_only
,
5795 pa_def_subspaces
[i
].common
,
5796 pa_def_subspaces
[i
].dup_common
,
5797 pa_def_subspaces
[i
].zero
,
5798 pa_def_subspaces
[i
].sort
,
5799 pa_def_subspaces
[i
].access
,
5800 pa_def_subspaces
[i
].space_index
,
5801 pa_def_subspaces
[i
].alignment
,
5802 pa_def_subspaces
[i
].quadrant
,
5810 /* Create a new space NAME, with the appropriate flags as defined
5811 by the given parameters.
5813 Add the new space to the space dictionary chain in numerical
5814 order as defined by the SORT entries. */
5816 static sd_chain_struct
*
5817 create_new_space (name
, spnum
, loadable
, defined
, private,
5818 sort
, seg
, user_defined
)
5828 sd_chain_struct
*chain_entry
;
5830 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5832 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5835 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5836 strcpy (SPACE_NAME (chain_entry
), name
);
5837 SPACE_NAME_INDEX (chain_entry
) = 0;
5838 SPACE_LOADABLE (chain_entry
) = loadable
;
5839 SPACE_DEFINED (chain_entry
) = defined
;
5840 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5841 SPACE_PRIVATE (chain_entry
) = private;
5842 SPACE_SPNUM (chain_entry
) = spnum
;
5843 SPACE_SORT (chain_entry
) = sort
;
5845 chain_entry
->sd_seg
= seg
;
5846 chain_entry
->sd_last_subseg
= -1;
5847 chain_entry
->sd_next
= NULL
;
5849 /* Find spot for the new space based on its sort key. */
5850 if (!space_dict_last
)
5851 space_dict_last
= chain_entry
;
5853 if (space_dict_root
== NULL
)
5854 space_dict_root
= chain_entry
;
5857 sd_chain_struct
*chain_pointer
;
5858 sd_chain_struct
*prev_chain_pointer
;
5860 chain_pointer
= space_dict_root
;
5861 prev_chain_pointer
= NULL
;
5863 while (chain_pointer
)
5865 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5867 prev_chain_pointer
= chain_pointer
;
5868 chain_pointer
= chain_pointer
->sd_next
;
5874 /* At this point we've found the correct place to add the new
5875 entry. So add it and update the linked lists as appropriate. */
5876 if (prev_chain_pointer
)
5878 chain_entry
->sd_next
= chain_pointer
;
5879 prev_chain_pointer
->sd_next
= chain_entry
;
5883 space_dict_root
= chain_entry
;
5884 chain_entry
->sd_next
= chain_pointer
;
5887 if (chain_entry
->sd_next
== NULL
)
5888 space_dict_last
= chain_entry
;
5891 /* This is here to catch predefined spaces which do not get
5892 modified by the user's input. Another call is found at
5893 the bottom of pa_parse_space_stmt to handle cases where
5894 the user modifies a predefined space. */
5895 #ifdef obj_set_section_attributes
5896 obj_set_section_attributes (seg
, defined
, private, sort
, spnum
);
5902 /* Create a new subspace NAME, with the appropriate flags as defined
5903 by the given parameters.
5905 Add the new subspace to the subspace dictionary chain in numerical
5906 order as defined by the SORT entries. */
5908 static ssd_chain_struct
*
5909 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5910 dup_common
, is_zero
, sort
, access
, space_index
,
5911 alignment
, quadrant
, seg
)
5912 sd_chain_struct
*space
;
5914 char loadable
, code_only
, common
, dup_common
, is_zero
;
5922 ssd_chain_struct
*chain_entry
;
5924 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5926 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5928 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5929 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5931 SUBSPACE_ACCESS (chain_entry
) = access
;
5932 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5933 SUBSPACE_COMMON (chain_entry
) = common
;
5934 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5935 SUBSPACE_SORT (chain_entry
) = sort
;
5936 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
5937 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5938 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5939 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
5940 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5941 SUBSPACE_ZERO (chain_entry
) = is_zero
;
5943 chain_entry
->ssd_subseg
= USE_ALIASES
? pa_next_subseg (space
) : 0;
5944 chain_entry
->ssd_seg
= seg
;
5945 chain_entry
->ssd_last_align
= 1;
5946 chain_entry
->ssd_next
= NULL
;
5948 /* Find spot for the new subspace based on its sort key. */
5949 if (space
->sd_subspaces
== NULL
)
5950 space
->sd_subspaces
= chain_entry
;
5953 ssd_chain_struct
*chain_pointer
;
5954 ssd_chain_struct
*prev_chain_pointer
;
5956 chain_pointer
= space
->sd_subspaces
;
5957 prev_chain_pointer
= NULL
;
5959 while (chain_pointer
)
5961 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
5963 prev_chain_pointer
= chain_pointer
;
5964 chain_pointer
= chain_pointer
->ssd_next
;
5971 /* Now we have somewhere to put the new entry. Insert it and update
5973 if (prev_chain_pointer
)
5975 chain_entry
->ssd_next
= chain_pointer
;
5976 prev_chain_pointer
->ssd_next
= chain_entry
;
5980 space
->sd_subspaces
= chain_entry
;
5981 chain_entry
->ssd_next
= chain_pointer
;
5985 #ifdef obj_set_subsection_attributes
5986 obj_set_subsection_attributes (seg
, space
->sd_seg
, access
,
5994 /* Update the information for the given subspace based upon the
5995 various arguments. Return the modified subspace chain entry. */
5997 static ssd_chain_struct
*
5998 update_subspace (space
, name
, loadable
, code_only
, common
, dup_common
, sort
,
5999 zero
, access
, space_index
, alignment
, quadrant
, subseg
)
6000 sd_chain_struct
*space
;
6014 ssd_chain_struct
*chain_entry
;
6016 if ((chain_entry
= is_defined_subspace (name
)))
6018 SUBSPACE_ACCESS (chain_entry
) = access
;
6019 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
6020 SUBSPACE_COMMON (chain_entry
) = common
;
6021 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
6022 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
6023 SUBSPACE_SORT (chain_entry
) = sort
;
6024 SUBSPACE_ALIGN (chain_entry
) = alignment
;
6025 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
6026 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
6027 SUBSPACE_ZERO (chain_entry
) = zero
;
6032 #ifdef obj_set_subsection_attributes
6033 obj_set_subsection_attributes (subseg
, space
->sd_seg
, access
,
6041 /* Return the space chain entry for the space with the name NAME or
6042 NULL if no such space exists. */
6044 static sd_chain_struct
*
6045 is_defined_space (name
)
6048 sd_chain_struct
*chain_pointer
;
6050 for (chain_pointer
= space_dict_root
;
6052 chain_pointer
= chain_pointer
->sd_next
)
6054 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
6055 return chain_pointer
;
6058 /* No mapping from segment to space was found. Return NULL. */
6062 /* Find and return the space associated with the given seg. If no mapping
6063 from the given seg to a space is found, then return NULL.
6065 Unlike subspaces, the number of spaces is not expected to grow much,
6066 so a linear exhaustive search is OK here. */
6068 static sd_chain_struct
*
6069 pa_segment_to_space (seg
)
6072 sd_chain_struct
*space_chain
;
6074 /* Walk through each space looking for the correct mapping. */
6075 for (space_chain
= space_dict_root
;
6077 space_chain
= space_chain
->sd_next
)
6079 if (space_chain
->sd_seg
== seg
)
6083 /* Mapping was not found. Return NULL. */
6087 /* Return the space chain entry for the subspace with the name NAME or
6088 NULL if no such subspace exists.
6090 Uses a linear search through all the spaces and subspaces, this may
6091 not be appropriate if we ever being placing each function in its
6094 static ssd_chain_struct
*
6095 is_defined_subspace (name
)
6098 sd_chain_struct
*space_chain
;
6099 ssd_chain_struct
*subspace_chain
;
6101 /* Walk through each space. */
6102 for (space_chain
= space_dict_root
;
6104 space_chain
= space_chain
->sd_next
)
6106 /* Walk through each subspace looking for a name which matches. */
6107 for (subspace_chain
= space_chain
->sd_subspaces
;
6109 subspace_chain
= subspace_chain
->ssd_next
)
6110 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
6111 return subspace_chain
;
6114 /* Subspace wasn't found. Return NULL. */
6118 /* Find and return the subspace associated with the given seg. If no
6119 mapping from the given seg to a subspace is found, then return NULL.
6121 If we ever put each procedure/function within its own subspace
6122 (to make life easier on the compiler and linker), then this will have
6123 to become more efficient. */
6125 static ssd_chain_struct
*
6126 pa_subsegment_to_subspace (seg
, subseg
)
6130 sd_chain_struct
*space_chain
;
6131 ssd_chain_struct
*subspace_chain
;
6133 /* Walk through each space. */
6134 for (space_chain
= space_dict_root
;
6136 space_chain
= space_chain
->sd_next
)
6138 if (space_chain
->sd_seg
== seg
)
6140 /* Walk through each subspace within each space looking for
6141 the correct mapping. */
6142 for (subspace_chain
= space_chain
->sd_subspaces
;
6144 subspace_chain
= subspace_chain
->ssd_next
)
6145 if (subspace_chain
->ssd_subseg
== (int) subseg
)
6146 return subspace_chain
;
6150 /* No mapping from subsegment to subspace found. Return NULL. */
6154 /* Given a number, try and find a space with the name number.
6156 Return a pointer to a space dictionary chain entry for the space
6157 that was found or NULL on failure. */
6159 static sd_chain_struct
*
6160 pa_find_space_by_number (number
)
6163 sd_chain_struct
*space_chain
;
6165 for (space_chain
= space_dict_root
;
6167 space_chain
= space_chain
->sd_next
)
6169 if (SPACE_SPNUM (space_chain
) == number
)
6173 /* No appropriate space found. Return NULL. */
6177 /* Return the starting address for the given subspace. If the starting
6178 address is unknown then return zero. */
6181 pa_subspace_start (space
, quadrant
)
6182 sd_chain_struct
*space
;
6185 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6186 is not correct for the PA OSF1 port. */
6187 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6189 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6195 /* FIXME. Needs documentation. */
6197 pa_next_subseg (space
)
6198 sd_chain_struct
*space
;
6201 space
->sd_last_subseg
++;
6202 return space
->sd_last_subseg
;
6205 /* Helper function for pa_stringer. Used to find the end of
6212 unsigned int c
= *s
& CHAR_MASK
;
6224 /* Handle a .STRING type pseudo-op. */
6227 pa_stringer (append_zero
)
6230 char *s
, num_buf
[4];
6234 /* Preprocess the string to handle PA-specific escape sequences.
6235 For example, \xDD where DD is a hexidecimal number should be
6236 changed to \OOO where OOO is an octal number. */
6238 /* Skip the opening quote. */
6239 s
= input_line_pointer
+ 1;
6241 while (is_a_char (c
= pa_stringer_aux (s
++)))
6248 /* Handle \x<num>. */
6251 unsigned int number
;
6256 /* Get pas the 'x'. */
6258 for (num_digit
= 0, number
= 0, dg
= *s
;
6260 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6261 || (dg
>= 'A' && dg
<= 'F'));
6265 number
= number
* 16 + dg
- '0';
6266 else if (dg
>= 'a' && dg
<= 'f')
6267 number
= number
* 16 + dg
- 'a' + 10;
6269 number
= number
* 16 + dg
- 'A' + 10;
6279 sprintf (num_buf
, "%02o", number
);
6282 sprintf (num_buf
, "%03o", number
);
6285 for (i
= 0; i
<= num_digit
; i
++)
6286 s_start
[i
] = num_buf
[i
];
6290 /* This might be a "\"", skip over the escaped char. */
6297 stringer (append_zero
);
6298 pa_undefine_label ();
6301 /* Handle a .VERSION pseudo-op. */
6308 pa_undefine_label ();
6311 /* Just like a normal cons, but when finished we have to undefine
6312 the latest space label. */
6319 pa_undefine_label ();
6322 /* Switch to the data space. As usual delete our label. */
6329 pa_undefine_label ();
6332 /* FIXME. What's the purpose of this pseudo-op? */
6338 pa_undefine_label ();
6341 /* Like float_cons, but we need to undefine our label. */
6344 pa_float_cons (float_type
)
6347 float_cons (float_type
);
6348 pa_undefine_label ();
6351 /* Like s_fill, but delete our label when finished. */
6358 pa_undefine_label ();
6361 /* Like lcomm, but delete our label when finished. */
6364 pa_lcomm (needs_align
)
6367 s_lcomm (needs_align
);
6368 pa_undefine_label ();
6371 /* Like lsym, but delete our label when finished. */
6378 pa_undefine_label ();
6381 /* Switch to the text space. Like s_text, but delete our
6382 label when finished. */
6388 pa_undefine_label ();
6391 /* On the PA relocations which involve function symbols must not be
6392 adjusted. This so that the linker can know when/how to create argument
6393 relocation stubs for indirect calls and calls to static functions.
6395 FIXME. Also reject R_HPPA relocations which are 32 bits
6396 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6397 needs to generate relocations to push the addend and symbol value
6398 onto the stack, add them, then pop the value off the stack and
6399 use it in a relocation -- yuk. */
6402 hppa_fix_adjustable (fixp
)
6405 struct hppa_fix_struct
*hppa_fix
;
6407 hppa_fix
= fixp
->tc_fix_data
;
6409 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6412 if (fixp
->fx_addsy
== 0
6413 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6419 /* Now for some ELF specific code. FIXME. */
6421 static symext_chainS
*symext_rootP
;
6422 static symext_chainS
*symext_lastP
;
6424 /* Do any symbol processing requested by the target-cpu or target-format. */
6427 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6429 elf_symbol_type
*symbolP
;
6432 symext_chainS
*symextP
;
6433 unsigned int arg_reloc
;
6435 /* Only functions can have argument relocations. */
6436 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6439 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6441 /* If there are no argument relocation bits, then no relocation is
6442 necessary. Do not add this to the symextn section. */
6446 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6448 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6449 symextP
[0].next
= &symextP
[1];
6451 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6452 symextP
[1].next
= NULL
;
6454 if (symext_rootP
== NULL
)
6456 symext_rootP
= &symextP
[0];
6457 symext_lastP
= &symextP
[1];
6461 symext_lastP
->next
= &symextP
[0];
6462 symext_lastP
= &symextP
[1];
6466 /* Make sections needed by the target cpu and/or target format. */
6468 hppa_tc_make_sections (abfd
)
6471 symext_chainS
*symextP
;
6473 asection
*symextn_sec
;
6474 segT save_seg
= now_seg
;
6475 subsegT save_subseg
= now_subseg
;
6477 /* Build the symbol extension section. */
6478 hppa_tc_make_symextn_section ();
6480 /* Force some calculation to occur. */
6481 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6483 hppa_elf_stub_finish (abfd
);
6485 /* If no symbols for the symbol extension section, then stop now. */
6486 if (symext_rootP
== NULL
)
6489 /* Count the number of symbols for the symbol extension section. */
6490 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6493 size
= sizeof (symext_entryS
) * n
;
6495 /* Switch to the symbol extension section. */
6496 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6498 frag_wane (frag_now
);
6501 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6504 int *symtab_map
= elf_sym_extra (abfd
);
6507 /* First, patch the symbol extension record to reflect the true
6508 symbol table index. */
6510 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6512 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6513 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6517 ptr
= frag_more (sizeof (symextP
->entry
));
6518 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6521 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6522 frag_wane (frag_now
);
6524 /* Switch back to the original segment. */
6525 subseg_set (save_seg
, save_subseg
);
6530 /* Make the symbol extension section. */
6533 hppa_tc_make_symextn_section ()
6537 symext_chainS
*symextP
;
6541 segT save_seg
= now_seg
;
6542 subsegT save_subseg
= now_subseg
;
6544 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6547 size
= sizeof (symext_entryS
) * n
;
6549 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6551 bfd_set_section_flags (stdoutput
, symextn_sec
,
6552 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6553 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6555 /* Now, switch back to the original segment. */
6556 subseg_set (save_seg
, save_subseg
);
6560 /* Build the symbol extension section. */
6563 pa_build_symextn_section ()
6566 asection
*save_seg
= now_seg
;
6567 subsegT subseg
= (subsegT
) 0;
6568 subsegT save_subseg
= now_subseg
;
6570 seg
= subseg_new (".hppa_symextn", subseg
);
6571 bfd_set_section_flags (stdoutput
,
6573 SEC_HAS_CONTENTS
| SEC_READONLY
6574 | SEC_ALLOC
| SEC_LOAD
);
6576 subseg_set (save_seg
, save_subseg
);
6580 /* For ELF, this function serves one purpose: to setup the st_size
6581 field of STT_FUNC symbols. To do this, we need to scan the
6582 call_info structure list, determining st_size in one of two possible
6585 1. call_info->start_frag->fr_fix has the size of the fragment.
6586 This approach assumes that the function was built into a
6587 single fragment. This works for most cases, but might fail.
6588 For example, if there was a segment change in the middle of
6591 2. The st_size field is the difference in the addresses of the
6592 call_info->start_frag->fr_address field and the fr_address
6593 field of the next fragment with fr_type == rs_fill and
6597 elf_hppa_final_processing ()
6599 struct call_info
*call_info_pointer
;
6601 for (call_info_pointer
= call_info_root
;
6603 call_info_pointer
= call_info_pointer
->ci_next
)
6605 elf_symbol_type
*esym
6606 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6607 esym
->internal_elf_sym
.st_size
=
6608 S_GET_VALUE (call_info_pointer
->end_symbol
)
6609 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;