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 /* Some local functions only used by ELF. */
59 static void pa_build_symextn_section
PARAMS ((void));
60 static void hppa_tc_make_symextn_section
PARAMS ((void));
64 /* Names of various debugging spaces/subspaces. */
65 #define GDB_DEBUG_SPACE_NAME "$GDB_DEBUG$"
66 #define GDB_STRINGS_SUBSPACE_NAME "$GDB_STRINGS$"
67 #define GDB_SYMBOLS_SUBSPACE_NAME "$GDB_SYMBOLS$"
68 #define UNWIND_SECTION_NAME "$UNWIND$"
70 /* Object file formats specify relocation types. */
71 typedef int reloc_type
;
74 #define obj_version obj_som_version
76 /* How to generate a relocation. */
77 #define hppa_gen_reloc_type hppa_som_gen_reloc_type
79 /* Object file formats specify BFD symbol types. */
80 typedef som_symbol_type obj_symbol_type
;
83 /* Various structures and types used internally in tc-hppa.c. */
85 /* Unwind table and descriptor. FIXME: Sync this with GDB version. */
89 unsigned int cannot_unwind
:1;
90 unsigned int millicode
:1;
91 unsigned int millicode_save_rest
:1;
92 unsigned int region_desc
:2;
93 unsigned int save_sr
:2;
94 unsigned int entry_fr
:4;
95 unsigned int entry_gr
:5;
96 unsigned int args_stored
:1;
97 unsigned int call_fr
:5;
98 unsigned int call_gr
:5;
99 unsigned int save_sp
:1;
100 unsigned int save_rp
:1;
101 unsigned int save_rp_in_frame
:1;
102 unsigned int extn_ptr_defined
:1;
103 unsigned int cleanup_defined
:1;
105 unsigned int hpe_interrupt_marker
:1;
106 unsigned int hpux_interrupt_marker
:1;
107 unsigned int reserved
:3;
108 unsigned int frame_size
:27;
113 /* Starting and ending offsets of the region described by
115 unsigned int start_offset
;
116 unsigned int end_offset
;
117 struct unwind_desc descriptor
;
120 /* This structure is used by the .callinfo, .enter, .leave pseudo-ops to
121 control the entry and exit code they generate. It is also used in
122 creation of the correct stack unwind descriptors.
124 NOTE: GAS does not support .enter and .leave for the generation of
125 prologues and epilogues. FIXME.
127 The fields in structure roughly correspond to the arguments available on the
128 .callinfo pseudo-op. */
132 /* Size of the stack frame. */
135 /* Should sr3 be saved in the prologue? */
138 /* Does this function make calls? */
141 /* The unwind descriptor being built. */
142 struct unwind_table ci_unwind
;
144 /* Name of this function. */
145 symbolS
*start_symbol
;
147 /* (temporary) symbol used to mark the end of this function. */
150 /* frags associated with start and end of this function. */
154 /* frags for starting/ending offset of this descriptor. */
155 fragS
*start_offset_frag
;
156 fragS
*end_offset_frag
;
158 /* The location within {start,end}_offset_frag to find the
159 {start,end}_offset. */
160 int start_frag_where
;
163 /* Fixups (relocations) for start_offset and end_offset. */
167 /* Next entry in the chain. */
168 struct call_info
*ci_next
;
171 /* Operand formats for FP instructions. Note not all FP instructions
172 allow all four formats to be used (for example fmpysub only allows
176 SGL
, DBL
, ILLEGAL_FMT
, QUAD
180 /* This structure contains information needed to assemble
181 individual instructions. */
184 /* Holds the opcode after parsing by pa_ip. */
185 unsigned long opcode
;
187 /* Holds an expression associated with the current instruction. */
190 /* Does this instruction use PC-relative addressing. */
193 /* Floating point formats for operand1 and operand2. */
194 fp_operand_format fpof1
;
195 fp_operand_format fpof2
;
197 /* Holds the field selector for this instruction
198 (for example L%, LR%, etc). */
201 /* Holds any argument relocation bits associated with this
202 instruction. (instruction should be some sort of call). */
205 /* The format specification for this instruction. */
208 /* The relocation (if any) associated with this instruction. */
212 /* PA-89 floating point registers are arranged like this:
215 +--------------+--------------+
216 | 0 or 16L | 16 or 16R |
217 +--------------+--------------+
218 | 1 or 17L | 17 or 17R |
219 +--------------+--------------+
227 +--------------+--------------+
228 | 14 or 30L | 30 or 30R |
229 +--------------+--------------+
230 | 15 or 31L | 31 or 31R |
231 +--------------+--------------+
234 The following is a version of pa_parse_number that
235 handles the L/R notation and returns the correct
236 value to put into the instruction register field.
237 The correct value to put into the instruction is
238 encoded in the structure 'pa_89_fp_reg_struct'. */
240 struct pa_89_fp_reg_struct
242 /* The register number. */
249 /* Additional information needed to build argument relocation stubs. */
252 /* The argument relocation specification. */
253 unsigned int arg_reloc
;
255 /* Number of arguments. */
256 unsigned int arg_count
;
259 /* This structure defines an entry in the subspace dictionary
262 struct subspace_dictionary_chain
264 /* Index of containing space. */
265 unsigned long ssd_space_index
;
267 /* Which quadrant within the space this subspace should be loaded into. */
268 unsigned char ssd_quadrant
;
270 /* Alignment (in bytes) for this subspace. */
271 unsigned long ssd_alignment
;
273 /* Access control bits to determine read/write/execute permissions
274 as well as gateway privilege promotions. */
275 unsigned char ssd_access_control_bits
;
277 /* A sorting key so that it is possible to specify ordering of
278 subspaces within a space. */
279 unsigned char ssd_sort_key
;
281 /* Nonzero of this space should be zero filled. */
282 unsigned long ssd_zero
;
284 /* Nonzero if this is a common subspace. */
285 unsigned char ssd_common
;
287 /* Nonzero if this is a common subspace which allows symbols to be
289 unsigned char ssd_dup_common
;
291 /* Nonzero if this subspace is loadable. Note loadable subspaces
292 must be contained within loadable spaces; unloadable subspaces
293 must be contained in unloadable spaces. */
294 unsigned char ssd_loadable
;
296 /* Nonzero if this subspace contains only code. */
297 unsigned char ssd_code_only
;
299 /* Starting offset of this subspace. */
300 unsigned long ssd_subspace_start
;
302 /* Length of this subspace. */
303 unsigned long ssd_subspace_length
;
305 /* Name of this subspace. */
308 /* GAS segment and subsegment associated with this subspace. */
312 /* Index of this subspace within the subspace dictionary of the object
313 file. Not used until object file is written. */
314 int object_file_index
;
316 /* The size of the last alignment request for this subspace. */
319 /* Next space in the subspace dictionary chain. */
320 struct subspace_dictionary_chain
*ssd_next
;
323 typedef struct subspace_dictionary_chain ssd_chain_struct
;
325 /* This structure defines an entry in the subspace dictionary
328 struct space_dictionary_chain
331 /* Holds the index into the string table of the name of this
333 unsigned int sd_name_index
;
335 /* Nonzero if the space is loadable. */
336 unsigned int sd_loadable
;
338 /* Nonzero if this space has been defined by the user code or
339 as a default space. */
340 unsigned int sd_defined
;
342 /* Nonzero if this spaces has been defined by the user code. */
343 unsigned int sd_user_defined
;
345 /* Nonzero if this space is not sharable. */
346 unsigned int sd_private
;
348 /* The space number (or index). */
349 unsigned int sd_spnum
;
351 /* The sort key for this space. May be used to determine how to lay
352 out the spaces within the object file. */
353 unsigned char sd_sort_key
;
355 /* The name of this subspace. */
358 /* GAS segment to which this subspace corresponds. */
361 /* Current subsegment number being used. */
364 /* The chain of subspaces contained within this space. */
365 ssd_chain_struct
*sd_subspaces
;
367 /* The next entry in the space dictionary chain. */
368 struct space_dictionary_chain
*sd_next
;
371 typedef struct space_dictionary_chain sd_chain_struct
;
373 /* Structure for previous label tracking. Needed so that alignments,
374 callinfo declarations, etc can be easily attached to a particular
376 typedef struct label_symbol_struct
378 struct symbol
*lss_label
;
379 sd_chain_struct
*lss_space
;
380 struct label_symbol_struct
*lss_next
;
384 /* This structure defines attributes of the default subspace
385 dictionary entries. */
387 struct default_subspace_dict
389 /* Name of the subspace. */
392 /* FIXME. Is this still needed? */
395 /* Nonzero if this subspace is loadable. */
398 /* Nonzero if this subspace contains only code. */
401 /* Nonzero if this is a common subspace. */
404 /* Nonzero if this is a common subspace which allows symbols
405 to be multiply defined. */
408 /* Nonzero if this subspace should be zero filled. */
411 /* Sort key for this subspace. */
414 /* Access control bits for this subspace. Can represent RWX access
415 as well as privilege level changes for gateways. */
418 /* Index of containing space. */
421 /* Alignment (in bytes) of this subspace. */
424 /* Quadrant within space where this subspace should be loaded. */
427 /* An index into the default spaces array. */
430 /* An alias for this section (or NULL if no alias exists). */
433 /* Subsegment associated with this subspace. */
437 /* This structure defines attributes of the default space
438 dictionary entries. */
440 struct default_space_dict
442 /* Name of the space. */
445 /* Space number. It is possible to identify spaces within
446 assembly code numerically! */
449 /* Nonzero if this space is loadable. */
452 /* Nonzero if this space is "defined". FIXME is still needed */
455 /* Nonzero if this space can not be shared. */
458 /* Sort key for this space. */
461 /* Segment associated with this space. */
464 /* An alias for this section (or NULL if no alias exists). */
468 /* Extra information needed to perform fixups (relocations) on the PA. */
469 struct hppa_fix_struct
471 /* The field selector. */
477 /* Format of fixup. */
480 /* Argument relocation bits. */
483 /* The unwind descriptor associated with this fixup. */
487 /* Structure to hold information about predefined registers. */
495 /* This structure defines the mapping from a FP condition string
496 to a condition number which can be recorded in an instruction. */
503 /* This structure defines a mapping from a field selector
504 string to a field selector type. */
505 struct selector_entry
511 /* Prototypes for functions local to tc-hppa.c. */
513 static fp_operand_format pa_parse_fp_format
PARAMS ((char **s
));
514 static void pa_cons
PARAMS ((int));
515 static void pa_data
PARAMS ((int));
516 static void pa_desc
PARAMS ((int));
517 static void pa_float_cons
PARAMS ((int));
518 static void pa_fill
PARAMS ((int));
519 static void pa_lcomm
PARAMS ((int));
520 static void pa_lsym
PARAMS ((int));
521 static void pa_stringer
PARAMS ((int));
522 static void pa_text
PARAMS ((int));
523 static void pa_version
PARAMS ((int));
524 static int pa_parse_fp_cmp_cond
PARAMS ((char **));
525 static int get_expression
PARAMS ((char *));
526 static int pa_get_absolute_expression
PARAMS ((char *));
527 static int evaluate_absolute
PARAMS ((expressionS
, int));
528 static unsigned int pa_build_arg_reloc
PARAMS ((char *));
529 static unsigned int pa_align_arg_reloc
PARAMS ((unsigned int, unsigned int));
530 static int pa_parse_nullif
PARAMS ((char **));
531 static int pa_parse_nonneg_cmpsub_cmpltr
PARAMS ((char **, int));
532 static int pa_parse_neg_cmpsub_cmpltr
PARAMS ((char **, int));
533 static int pa_parse_neg_add_cmpltr
PARAMS ((char **, int));
534 static int pa_parse_nonneg_add_cmpltr
PARAMS ((char **, int));
535 static void pa_block
PARAMS ((int));
536 static void pa_call
PARAMS ((int));
537 static void pa_call_args
PARAMS ((struct call_desc
*));
538 static void pa_callinfo
PARAMS ((int));
539 static void pa_code
PARAMS ((int));
540 static void pa_comm
PARAMS ((int));
541 static void pa_copyright
PARAMS ((int));
542 static void pa_end
PARAMS ((int));
543 static void pa_enter
PARAMS ((int));
544 static void pa_entry
PARAMS ((int));
545 static void pa_equ
PARAMS ((int));
546 static void pa_exit
PARAMS ((int));
547 static void pa_export
PARAMS ((int));
548 static void pa_export_args
PARAMS ((symbolS
*));
549 static void pa_import
PARAMS ((int));
550 static void pa_label
PARAMS ((int));
551 static void pa_leave
PARAMS ((int));
552 static void pa_origin
PARAMS ((int));
553 static void pa_proc
PARAMS ((int));
554 static void pa_procend
PARAMS ((int));
555 static void pa_space
PARAMS ((int));
556 static void pa_spnum
PARAMS ((int));
557 static void pa_subspace
PARAMS ((int));
558 static void pa_param
PARAMS ((int));
559 static void pa_undefine_label
PARAMS ((void));
560 static int need_89_opcode
PARAMS ((struct pa_it
*,
561 struct pa_89_fp_reg_struct
*));
562 static int pa_parse_number
PARAMS ((char **, struct pa_89_fp_reg_struct
*));
563 static label_symbol_struct
*pa_get_label
PARAMS ((void));
564 static sd_chain_struct
*create_new_space
PARAMS ((char *, int, char,
567 static ssd_chain_struct
* create_new_subspace
PARAMS ((sd_chain_struct
*,
572 static ssd_chain_struct
*update_subspace
PARAMS ((char *, char, char, char,
573 char, char, char, int,
574 int, int, int, subsegT
));
575 static sd_chain_struct
*is_defined_space
PARAMS ((char *));
576 static ssd_chain_struct
*is_defined_subspace
PARAMS ((char *, subsegT
));
577 static sd_chain_struct
*pa_segment_to_space
PARAMS ((asection
*));
578 static ssd_chain_struct
* pa_subsegment_to_subspace
PARAMS ((asection
*,
580 static sd_chain_struct
*pa_find_space_by_number
PARAMS ((int));
581 static unsigned int pa_subspace_start
PARAMS ((sd_chain_struct
*, int));
582 static void pa_ip
PARAMS ((char *));
583 static void fix_new_hppa
PARAMS ((fragS
*, int, short int, symbolS
*,
584 long, expressionS
*, int,
585 bfd_reloc_code_real_type
, long,
587 static void md_apply_fix_1
PARAMS ((fixS
*, long));
588 static int is_end_of_statement
PARAMS ((void));
589 static int reg_name_search
PARAMS ((char *));
590 static int pa_chk_field_selector
PARAMS ((char **));
591 static int is_same_frag
PARAMS ((fragS
*, fragS
*));
592 static void pa_build_unwind_subspace
PARAMS ((struct call_info
*));
593 static void process_exit
PARAMS ((void));
594 static sd_chain_struct
*pa_parse_space_stmt
PARAMS ((char *, int));
595 static void pa_align_subseg
PARAMS ((asection
*, subsegT
));
596 static int log2
PARAMS ((int));
597 static int pa_next_subseg
PARAMS ((sd_chain_struct
*));
598 static unsigned int pa_stringer_aux
PARAMS ((char *));
599 static void pa_spaces_begin
PARAMS ((void));
602 /* File and gloally scoped variable declarations. */
604 /* Root and final entry in the space chain. */
605 static sd_chain_struct
*space_dict_root
;
606 static sd_chain_struct
*space_dict_last
;
608 /* The current space and subspace. */
609 static sd_chain_struct
*current_space
;
610 static ssd_chain_struct
*current_subspace
;
612 /* Root of the call_info chain. */
613 static struct call_info
*call_info_root
;
615 /* The last call_info (for functions) structure
616 seen so it can be associated with fixups and
618 static struct call_info
*last_call_info
;
620 /* The last call description (for actual calls). */
621 static struct call_desc last_call_desc
;
623 /* Relaxation isn't supported for the PA yet. */
624 const relax_typeS md_relax_table
[] = {0};
626 /* Jumps are always the same size -- one instruction. */
627 int md_short_jump_size
= 4;
628 int md_long_jump_size
= 4;
630 /* handle of the OPCODE hash table */
631 static struct hash_control
*op_hash
= NULL
;
633 /* This array holds the chars that always start a comment. If the
634 pre-processor is disabled, these aren't very useful. */
635 const char comment_chars
[] = ";";
637 /* Table of pseudo ops for the PA. FIXME -- how many of these
638 are now redundant with the overall GAS and the object file
640 const pseudo_typeS md_pseudo_table
[] =
642 /* align pseudo-ops on the PA specify the actual alignment requested,
643 not the log2 of the requested alignment. */
644 {"align", s_align_bytes
, 8},
645 {"ALIGN", s_align_bytes
, 8},
646 {"block", pa_block
, 1},
647 {"BLOCK", pa_block
, 1},
648 {"blockz", pa_block
, 0},
649 {"BLOCKZ", pa_block
, 0},
650 {"byte", pa_cons
, 1},
651 {"BYTE", pa_cons
, 1},
652 {"call", pa_call
, 0},
653 {"CALL", pa_call
, 0},
654 {"callinfo", pa_callinfo
, 0},
655 {"CALLINFO", pa_callinfo
, 0},
656 {"code", pa_code
, 0},
657 {"CODE", pa_code
, 0},
658 {"comm", pa_comm
, 0},
659 {"COMM", pa_comm
, 0},
660 {"copyright", pa_copyright
, 0},
661 {"COPYRIGHT", pa_copyright
, 0},
662 {"data", pa_data
, 0},
663 {"DATA", pa_data
, 0},
664 {"desc", pa_desc
, 0},
665 {"DESC", pa_desc
, 0},
666 {"double", pa_float_cons
, 'd'},
667 {"DOUBLE", pa_float_cons
, 'd'},
670 {"enter", pa_enter
, 0},
671 {"ENTER", pa_enter
, 0},
672 {"entry", pa_entry
, 0},
673 {"ENTRY", pa_entry
, 0},
676 {"exit", pa_exit
, 0},
677 {"EXIT", pa_exit
, 0},
678 {"export", pa_export
, 0},
679 {"EXPORT", pa_export
, 0},
680 {"fill", pa_fill
, 0},
681 {"FILL", pa_fill
, 0},
682 {"float", pa_float_cons
, 'f'},
683 {"FLOAT", pa_float_cons
, 'f'},
684 {"half", pa_cons
, 2},
685 {"HALF", pa_cons
, 2},
686 {"import", pa_import
, 0},
687 {"IMPORT", pa_import
, 0},
690 {"label", pa_label
, 0},
691 {"LABEL", pa_label
, 0},
692 {"lcomm", pa_lcomm
, 0},
693 {"LCOMM", pa_lcomm
, 0},
694 {"leave", pa_leave
, 0},
695 {"LEAVE", pa_leave
, 0},
696 {"long", pa_cons
, 4},
697 {"LONG", pa_cons
, 4},
698 {"lsym", pa_lsym
, 0},
699 {"LSYM", pa_lsym
, 0},
700 {"octa", pa_cons
, 16},
701 {"OCTA", pa_cons
, 16},
702 {"org", pa_origin
, 0},
703 {"ORG", pa_origin
, 0},
704 {"origin", pa_origin
, 0},
705 {"ORIGIN", pa_origin
, 0},
706 {"param", pa_param
, 0},
707 {"PARAM", pa_param
, 0},
708 {"proc", pa_proc
, 0},
709 {"PROC", pa_proc
, 0},
710 {"procend", pa_procend
, 0},
711 {"PROCEND", pa_procend
, 0},
712 {"quad", pa_cons
, 8},
713 {"QUAD", pa_cons
, 8},
716 {"short", pa_cons
, 2},
717 {"SHORT", pa_cons
, 2},
718 {"single", pa_float_cons
, 'f'},
719 {"SINGLE", pa_float_cons
, 'f'},
720 {"space", pa_space
, 0},
721 {"SPACE", pa_space
, 0},
722 {"spnum", pa_spnum
, 0},
723 {"SPNUM", pa_spnum
, 0},
724 {"string", pa_stringer
, 0},
725 {"STRING", pa_stringer
, 0},
726 {"stringz", pa_stringer
, 1},
727 {"STRINGZ", pa_stringer
, 1},
728 {"subspa", pa_subspace
, 0},
729 {"SUBSPA", pa_subspace
, 0},
730 {"text", pa_text
, 0},
731 {"TEXT", pa_text
, 0},
732 {"version", pa_version
, 0},
733 {"VERSION", pa_version
, 0},
734 {"word", pa_cons
, 4},
735 {"WORD", pa_cons
, 4},
739 /* This array holds the chars that only start a comment at the beginning of
740 a line. If the line seems to have the form '# 123 filename'
741 .line and .file directives will appear in the pre-processed output.
743 Note that input_file.c hand checks for '#' at the beginning of the
744 first line of the input file. This is because the compiler outputs
745 #NO_APP at the beginning of its output.
747 Also note that '/*' will always start a comment. */
748 const char line_comment_chars
[] = "#";
750 /* This array holds the characters which act as line separators. */
751 const char line_separator_chars
[] = "!";
753 /* Chars that can be used to separate mant from exp in floating point nums. */
754 const char EXP_CHARS
[] = "eE";
756 /* Chars that mean this number is a floating point constant.
757 As in 0f12.456 or 0d1.2345e12.
759 Be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
760 changed in read.c. Ideally it shouldn't hae to know abou it at
761 all, but nothing is ideal around here. */
762 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
764 static struct pa_it the_insn
;
766 /* Points to the end of an expression just parsed by get_expressoin
767 and friends. FIXME. This shouldn't be handled with a file-global
769 static char *expr_end
;
771 /* Nonzero if a .callinfo appeared within the current procedure. */
772 static int callinfo_found
;
774 /* Nonzero if the assembler is currently within a .entry/.exit pair. */
775 static int within_entry_exit
;
777 /* Nonzero if the assembler has completed exit processing for the
778 current procedure. */
779 static int exit_processing_complete
;
781 /* Nonzero if the assembler is currently within a procedure definition. */
782 static int within_procedure
;
784 /* Handle on strucutre which keep track of the last symbol
785 seen in each subspace. */
786 static label_symbol_struct
*label_symbols_rootp
= NULL
;
788 /* Holds the last field selector. */
789 static int hppa_field_selector
;
791 /* Nonzero if errors are to be printed. */
792 static int print_errors
= 1;
794 /* List of registers that are pre-defined:
796 Each general register has one predefined name of the form
797 %r<REGNUM> which has the value <REGNUM>.
799 Space and control registers are handled in a similar manner,
800 but use %sr<REGNUM> and %cr<REGNUM> as their predefined names.
802 Likewise for the floating point registers, but of the form
803 %fr<REGNUM>. Floating point registers have additional predefined
804 names with 'L' and 'R' suffixes (e.g. %fr19L, %fr19R) which
805 again have the value <REGNUM>.
807 Many registers also have synonyms:
809 %r26 - %r23 have %arg0 - %arg3 as synonyms
810 %r28 - %r29 have %ret0 - %ret1 as synonyms
811 %r30 has %sp as a synonym
813 Almost every control register has a synonym; they are not listed
816 The table is sorted. Suitable for searching by a binary search. */
818 static const struct pd_reg pre_defined_registers
[] =
1028 /* This table is sorted by order of the length of the string. This is
1029 so we check for <> before we check for <. If we had a <> and checked
1030 for < first, we would get a false match. */
1031 static const struct fp_cond_map fp_cond_map
[] =
1067 static const struct selector_entry selector_table
[] =
1102 /* default space and subspace dictionaries */
1104 #define GDB_SYMBOLS GDB_SYMBOLS_SUBSPACE_NAME
1105 #define GDB_STRINGS GDB_STRINGS_SUBSPACE_NAME
1107 /* pre-defined subsegments (subspaces) for the HPPA. */
1108 #define SUBSEG_CODE 0
1109 #define SUBSEG_DATA 0
1110 #define SUBSEG_LIT 1
1111 #define SUBSEG_BSS 2
1112 #define SUBSEG_UNWIND 3
1113 #define SUBSEG_GDB_STRINGS 0
1114 #define SUBSEG_GDB_SYMBOLS 1
1116 static struct default_subspace_dict pa_def_subspaces
[] =
1118 {"$CODE$", 1, 1, 1, 0, 0, 0, 24, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_CODE
},
1119 {"$DATA$", 1, 1, 0, 0, 0, 0, 24, 0x1f, 1, 8, 1, 1, ".data", SUBSEG_DATA
},
1120 {"$LIT$", 1, 1, 0, 0, 0, 0, 16, 0x2c, 0, 8, 0, 0, ".text", SUBSEG_LIT
},
1121 {"$BSS$", 1, 1, 0, 0, 0, 1, 80, 0x1f, 1, 8, 1, 1, ".bss", SUBSEG_BSS
},
1122 {"$UNWIND$", 1, 1, 0, 0, 0, 0, 64, 0x2c, 0, 4, 0, 0, ".hppa_unwind", SUBSEG_UNWIND
},
1123 {NULL
, 0, 1, 0, 0, 0, 0, 255, 0x1f, 0, 4, 0, 0, 0}
1126 static struct default_space_dict pa_def_spaces
[] =
1128 {"$TEXT$", 0, 1, 1, 0, 8, ASEC_NULL
, ".text"},
1129 {"$PRIVATE$", 1, 1, 1, 1, 16, ASEC_NULL
, ".data"},
1130 {NULL
, 0, 0, 0, 0, 0, ASEC_NULL
, NULL
}
1133 /* Misc local definitions used by the assembler. */
1135 /* Return nonzero if the string pointed to by S potentially represents
1136 a right or left half of a FP register */
1137 #define IS_R_SELECT(S) (*(S) == 'R' || *(S) == 'r')
1138 #define IS_L_SELECT(S) (*(S) == 'L' || *(S) == 'l')
1140 /* These macros are used to maintain spaces/subspaces. */
1141 #define SPACE_DEFINED(space_chain) (space_chain)->sd_defined
1142 #define SPACE_USER_DEFINED(space_chain) (space_chain)->sd_user_defined
1143 #define SPACE_PRIVATE(space_chain) (space_chain)->sd_private
1144 #define SPACE_LOADABLE(space_chain) (space_chain)->sd_loadable
1145 #define SPACE_SPNUM(space_chain) (space_chain)->sd_spnum
1146 #define SPACE_SORT(space_chain) (space_chain)->sd_sort_key
1147 #define SPACE_NAME(space_chain) (space_chain)->sd_name
1148 #define SPACE_NAME_INDEX(space_chain) (space_chain)->sd_name_index
1150 #define SUBSPACE_SPACE_INDEX(ss_chain) (ss_chain)->ssd_space_index
1151 #define SUBSPACE_QUADRANT(ss_chain) (ss_chain)->ssd_quadrant
1152 #define SUBSPACE_ALIGN(ss_chain) (ss_chain)->ssd_alignment
1153 #define SUBSPACE_ACCESS(ss_chain) (ss_chain)->ssd_access_control_bits
1154 #define SUBSPACE_SORT(ss_chain) (ss_chain)->ssd_sort_key
1155 #define SUBSPACE_COMMON(ss_chain) (ss_chain)->ssd_common
1156 #define SUBSPACE_ZERO(ss_chain) (ss_chain)->ssd_zero
1157 #define SUBSPACE_DUP_COMM(ss_chain) (ss_chain)->ssd_dup_common
1158 #define SUBSPACE_CODE_ONLY(ss_chain) (ss_chain)->ssd_code_only
1159 #define SUBSPACE_LOADABLE(ss_chain) (ss_chain)->ssd_loadable
1160 #define SUBSPACE_SUBSPACE_START(ss_chain) (ss_chain)->ssd_subspace_start
1161 #define SUBSPACE_SUBSPACE_LENGTH(ss_chain) (ss_chain)->ssd_subspace_length
1162 #define SUBSPACE_NAME(ss_chain) (ss_chain)->ssd_name
1164 #define is_DP_relative(exp) \
1165 ((exp).X_op == O_subtract \
1166 && strcmp((exp).X_op_symbol->bsym->name, "$global$") == 0)
1168 #define is_PC_relative(exp) \
1169 ((exp).X_op == O_subtract \
1170 && strcmp((exp).X_op_symbol->bsym->name, "$PIC_pcrel$0") == 0)
1172 #define is_complex(exp) \
1173 ((exp).X_op != O_constant && (exp).X_op != O_symbol)
1175 /* Actual functions to implement the PA specific code for the assembler. */
1177 /* Returns a pointer to the label_symbol_struct for the current space.
1178 or NULL if no label_symbol_struct exists for the current space. */
1180 static label_symbol_struct
*
1183 label_symbol_struct
*label_chain
;
1184 sd_chain_struct
*space_chain
= pa_segment_to_space (now_seg
);
1186 for (label_chain
= label_symbols_rootp
;
1188 label_chain
= label_chain
->lss_next
)
1189 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1195 /* Defines a label for the current space. If one is already defined,
1196 this function will replace it with the new label. */
1199 pa_define_label (symbol
)
1202 label_symbol_struct
*label_chain
= pa_get_label ();
1203 sd_chain_struct
*space_chain
= pa_segment_to_space (now_seg
);
1206 label_chain
->lss_label
= symbol
;
1209 /* Create a new label entry and add it to the head of the chain. */
1211 = (label_symbol_struct
*) xmalloc (sizeof (label_symbol_struct
));
1212 label_chain
->lss_label
= symbol
;
1213 label_chain
->lss_space
= space_chain
;
1214 label_chain
->lss_next
= NULL
;
1216 if (label_symbols_rootp
)
1217 label_chain
->lss_next
= label_symbols_rootp
;
1219 label_symbols_rootp
= label_chain
;
1223 /* Removes a label definition for the current space.
1224 If there is no label_symbol_struct entry, then no action is taken. */
1227 pa_undefine_label ()
1229 label_symbol_struct
*label_chain
;
1230 label_symbol_struct
*prev_label_chain
= NULL
;
1231 sd_chain_struct
*space_chain
= pa_segment_to_space (now_seg
);
1233 for (label_chain
= label_symbols_rootp
;
1235 label_chain
= label_chain
->lss_next
)
1237 if (space_chain
== label_chain
->lss_space
&& label_chain
->lss_label
)
1239 /* Remove the label from the chain and free its memory. */
1240 if (prev_label_chain
)
1241 prev_label_chain
->lss_next
= label_chain
->lss_next
;
1243 label_symbols_rootp
= label_chain
->lss_next
;
1248 prev_label_chain
= label_chain
;
1253 /* An HPPA-specific version of fix_new. This is required because the HPPA
1254 code needs to keep track of some extra stuff. Each call to fix_new_hppa
1255 results in the creation of an instance of an hppa_fix_struct. An
1256 hppa_fix_struct stores the extra information along with a pointer to the
1257 original fixS. This is attached to the original fixup via the
1258 tc_fix_data field. */
1261 fix_new_hppa (frag
, where
, size
, add_symbol
, offset
, exp
, pcrel
,
1262 r_type
, r_field
, r_format
, arg_reloc
, unwind_desc
)
1266 symbolS
*add_symbol
;
1270 bfd_reloc_code_real_type r_type
;
1278 struct hppa_fix_struct
*hppa_fix
= (struct hppa_fix_struct
*)
1279 obstack_alloc (¬es
, sizeof (struct hppa_fix_struct
));
1282 new_fix
= fix_new_exp (frag
, where
, size
, exp
, pcrel
, r_type
);
1284 new_fix
= fix_new (frag
, where
, size
, add_symbol
, offset
, pcrel
, r_type
);
1285 new_fix
->tc_fix_data
= hppa_fix
;
1286 hppa_fix
->fx_r_type
= r_type
;
1287 hppa_fix
->fx_r_field
= r_field
;
1288 hppa_fix
->fx_r_format
= r_format
;
1289 hppa_fix
->fx_arg_reloc
= arg_reloc
;
1291 bcopy (unwind_desc
, hppa_fix
->fx_unwind
, 8);
1295 /* Parse a .byte, .word, .long expression for the HPPA. Called by
1296 cons via the TC_PARSE_CONS_EXPRESSION macro. */
1299 parse_cons_expression_hppa (exp
)
1302 hppa_field_selector
= pa_chk_field_selector (&input_line_pointer
);
1306 /* This fix_new is called by cons via TC_CONS_FIX_NEW.
1307 hppa_field_selector is set by the parse_cons_expression_hppa. */
1310 cons_fix_new_hppa (frag
, where
, size
, exp
)
1316 unsigned int reloc_type
;
1318 if (is_DP_relative (*exp
))
1319 reloc_type
= R_HPPA_GOTOFF
;
1320 else if (is_complex (*exp
))
1321 reloc_type
= R_HPPA_COMPLEX
;
1323 reloc_type
= R_HPPA
;
1325 if (hppa_field_selector
!= e_psel
&& hppa_field_selector
!= e_fsel
)
1326 as_warn ("Invalid field selector. Assuming F%%.");
1328 fix_new_hppa (frag
, where
, size
,
1329 (symbolS
*) NULL
, (offsetT
) 0, exp
, 0, reloc_type
,
1330 hppa_field_selector
, 32, 0, (char *) 0);
1333 /* This function is called once, at assembler startup time. It should
1334 set up all the tables, etc. that the MD part of the assembler will need. */
1339 char *retval
= NULL
;
1343 last_call_info
= NULL
;
1344 call_info_root
= NULL
;
1346 /* Folding of text and data segments fails miserably on the PA.
1347 Warn user and disable "-R" option. */
1350 as_warn ("-R option not supported on this target.");
1351 flag_readonly_data_in_text
= 0;
1357 op_hash
= hash_new ();
1358 if (op_hash
== NULL
)
1359 as_fatal ("Virtual memory exhausted");
1361 while (i
< NUMOPCODES
)
1363 const char *name
= pa_opcodes
[i
].name
;
1364 retval
= hash_insert (op_hash
, name
, &pa_opcodes
[i
]);
1365 if (retval
!= NULL
&& *retval
!= '\0')
1367 as_fatal ("Internal error: can't hash `%s': %s\n", name
, retval
);
1372 if ((pa_opcodes
[i
].match
& pa_opcodes
[i
].mask
)
1373 != pa_opcodes
[i
].match
)
1375 fprintf (stderr
, "internal error: losing opcode: `%s' \"%s\"\n",
1376 pa_opcodes
[i
].name
, pa_opcodes
[i
].args
);
1381 while (i
< NUMOPCODES
&& !strcmp (pa_opcodes
[i
].name
, name
));
1385 as_fatal ("Broken assembler. No assembly attempted.");
1388 /* Called at the end of assembling a source file. Nothing to do
1389 at this point on the PA. */
1397 /* Assemble a single instruction storing it into a frag. */
1404 /* The had better be something to assemble. */
1407 /* Assemble the instruction. Results are saved into "the_insn". */
1410 /* Get somewhere to put the assembled instrution. */
1413 /* Output the opcode. */
1414 md_number_to_chars (to
, the_insn
.opcode
, 4);
1416 /* If necessary output more stuff. */
1417 if (the_insn
.reloc
!= R_HPPA_NONE
)
1418 fix_new_hppa (frag_now
, (to
- frag_now
->fr_literal
), 4, NULL
,
1419 (offsetT
) 0, &the_insn
.exp
, the_insn
.pcrel
,
1420 the_insn
.reloc
, the_insn
.field_selector
,
1421 the_insn
.format
, the_insn
.arg_reloc
, NULL
);
1425 /* Do the real work for assembling a single instruction. Store results
1426 into the global "the_insn" variable.
1428 FIXME: Should define and use some functions/macros to handle
1429 various common insertions of information into the opcode. */
1435 char *error_message
= "";
1436 char *s
, c
, *argstart
, *name
, *save_s
;
1440 int reg
, s2
, s3
, m
, a
, uu
, cmpltr
, nullif
, flag
, sfu
, cond
;
1441 unsigned int im21
, im14
, im11
, im5
;
1442 unsigned long i
, opcode
;
1443 struct pa_opcode
*insn
;
1445 /* Skip to something interesting. */
1446 for (s
= str
; isupper (*s
) || islower (*s
) || (*s
>= '0' && *s
<= '3'); ++s
)
1465 as_bad ("Unknown opcode: `%s'", str
);
1471 /* Convert everything into lower case. */
1474 if (isupper (*save_s
))
1475 *save_s
= tolower (*save_s
);
1479 /* Look up the opcode in the has table. */
1480 if ((insn
= (struct pa_opcode
*) hash_find (op_hash
, str
)) == NULL
)
1482 as_bad ("Unknown opcode: `%s'", str
);
1491 /* Mark the location where arguments for the instruction start, then
1492 start processing them. */
1496 /* Do some initialization. */
1497 opcode
= insn
->match
;
1498 bzero (&the_insn
, sizeof (the_insn
));
1500 the_insn
.reloc
= R_HPPA_NONE
;
1502 /* Build the opcode, checking as we go to make
1503 sure that the operands match. */
1504 for (args
= insn
->args
;; ++args
)
1509 /* End of arguments. */
1525 /* These must match exactly. */
1534 /* Handle a 5 bit register or control register field at 10. */
1537 reg
= pa_parse_number (&s
, 0);
1538 if (reg
< 32 && reg
>= 0)
1540 opcode
|= reg
<< 21;
1545 /* Handle a 5 bit register field at 15. */
1547 reg
= pa_parse_number (&s
, 0);
1548 if (reg
< 32 && reg
>= 0)
1550 opcode
|= reg
<< 16;
1555 /* Handle a 5 bit register field at 31. */
1558 reg
= pa_parse_number (&s
, 0);
1559 if (reg
< 32 && reg
>= 0)
1566 /* Handle a 5 bit field length at 31. */
1568 pa_get_absolute_expression (s
);
1569 if (the_insn
.exp
.X_op
== O_constant
)
1571 reg
= the_insn
.exp
.X_add_number
;
1572 if (reg
<= 32 && reg
> 0)
1581 /* Handle a 5 bit immediate at 15. */
1583 pa_get_absolute_expression (s
);
1584 if (the_insn
.exp
.X_add_number
> 15)
1586 as_bad ("5 bit immediate > 15. Set to 15");
1587 the_insn
.exp
.X_add_number
= 15;
1589 else if (the_insn
.exp
.X_add_number
< -16)
1591 as_bad ("5 bit immediate < -16. Set to -16");
1592 the_insn
.exp
.X_add_number
= -16;
1595 low_sign_unext (evaluate_absolute (the_insn
.exp
,
1596 the_insn
.field_selector
),
1598 opcode
|= (im5
<< 16);
1602 /* Handle a 2 bit space identifier at 17. */
1604 s2
= pa_parse_number (&s
, 0);
1605 if (s2
< 4 && s2
>= 0)
1612 /* Handle a 3 bit space identifier at 18. */
1614 s3
= pa_parse_number (&s
, 0);
1615 if (s3
< 8 && s3
>= 0)
1617 dis_assemble_3 (s3
, &s3
);
1623 /* Handle a completer for an indexing load or store. */
1628 while (*s
== ',' && i
< 2)
1631 if (strncasecmp (s
, "sm", 2) == 0)
1638 else if (strncasecmp (s
, "m", 1) == 0)
1640 else if (strncasecmp (s
, "s", 1) == 0)
1643 as_bad ("Invalid Indexed Load Completer.");
1648 as_bad ("Invalid Indexed Load Completer Syntax.");
1649 while (*s
== ' ' || *s
== '\t')
1656 /* Handle a short load/store completer. */
1663 if (strncasecmp (s
, "ma", 2) == 0)
1668 else if (strncasecmp (s
, "mb", 2) == 0)
1674 as_bad ("Invalid Short Load/Store Completer.");
1677 while (*s
== ' ' || *s
== '\t')
1683 /* Handle a stbys completer. */
1688 while (*s
== ',' && i
< 2)
1691 if (strncasecmp (s
, "m", 1) == 0)
1693 else if (strncasecmp (s
, "b", 1) == 0)
1695 else if (strncasecmp (s
, "e", 1) == 0)
1698 as_bad ("Invalid Store Bytes Short Completer");
1703 as_bad ("Invalid Store Bytes Short Completer");
1704 while (*s
== ' ' || *s
== '\t')
1710 /* Handle a non-negated compare/stubtract condition. */
1712 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1715 as_bad ("Invalid Compare/Subtract Condition: %c", *s
);
1718 opcode
|= cmpltr
<< 13;
1721 /* Handle a negated or non-negated compare/subtract condition. */
1724 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 1);
1728 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 1);
1731 as_bad ("Invalid Compare/Subtract Condition.");
1736 /* Negated condition requires an opcode change. */
1740 opcode
|= cmpltr
<< 13;
1743 /* Handle a negated or non-negated add condition. */
1746 cmpltr
= pa_parse_nonneg_add_cmpltr (&s
, 1);
1750 cmpltr
= pa_parse_neg_add_cmpltr (&s
, 1);
1753 as_bad ("Invalid Compare/Subtract Condition");
1758 /* Negated condition requires an opcode change. */
1762 opcode
|= cmpltr
<< 13;
1765 /* Handle a compare/subtract condition. */
1772 cmpltr
= pa_parse_nonneg_cmpsub_cmpltr (&s
, 0);
1777 cmpltr
= pa_parse_neg_cmpsub_cmpltr (&s
, 0);
1780 as_bad ("Invalid Compare/Subtract Condition");
1784 opcode
|= cmpltr
<< 13;
1785 opcode
|= flag
<< 12;
1788 /* Handle a non-negated add condition. */
1797 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1801 if (strcmp (name
, "=") == 0)
1803 else if (strcmp (name
, "<") == 0)
1805 else if (strcmp (name
, "<=") == 0)
1807 else if (strcasecmp (name
, "nuv") == 0)
1809 else if (strcasecmp (name
, "znv") == 0)
1811 else if (strcasecmp (name
, "sv") == 0)
1813 else if (strcasecmp (name
, "od") == 0)
1815 else if (strcasecmp (name
, "n") == 0)
1817 else if (strcasecmp (name
, "tr") == 0)
1822 else if (strcasecmp (name
, "<>") == 0)
1827 else if (strcasecmp (name
, ">=") == 0)
1832 else if (strcasecmp (name
, ">") == 0)
1837 else if (strcasecmp (name
, "uv") == 0)
1842 else if (strcasecmp (name
, "vnz") == 0)
1847 else if (strcasecmp (name
, "nsv") == 0)
1852 else if (strcasecmp (name
, "ev") == 0)
1858 as_bad ("Invalid Add Condition: %s", name
);
1861 nullif
= pa_parse_nullif (&s
);
1862 opcode
|= nullif
<< 1;
1863 opcode
|= cmpltr
<< 13;
1864 opcode
|= flag
<< 12;
1867 /* Handle a logical instruction condition. */
1875 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
1879 if (strcmp (name
, "=") == 0)
1881 else if (strcmp (name
, "<") == 0)
1883 else if (strcmp (name
, "<=") == 0)
1885 else if (strcasecmp (name
, "od") == 0)
1887 else if (strcasecmp (name
, "tr") == 0)
1892 else if (strcmp (name
, "<>") == 0)
1897 else if (strcmp (name
, ">=") == 0)
1902 else if (strcmp (name
, ">") == 0)
1907 else if (strcasecmp (name
, "ev") == 0)
1913 as_bad ("Invalid Logical Instruction Condition.");
1916 opcode
|= cmpltr
<< 13;
1917 opcode
|= flag
<< 12;
1920 /* Handle a unit instruction condition. */
1927 if (strncasecmp (s
, "sbz", 3) == 0)
1932 else if (strncasecmp (s
, "shz", 3) == 0)
1937 else if (strncasecmp (s
, "sdc", 3) == 0)
1942 else if (strncasecmp (s
, "sbc", 3) == 0)
1947 else if (strncasecmp (s
, "shc", 3) == 0)
1952 else if (strncasecmp (s
, "tr", 2) == 0)
1958 else if (strncasecmp (s
, "nbz", 3) == 0)
1964 else if (strncasecmp (s
, "nhz", 3) == 0)
1970 else if (strncasecmp (s
, "ndc", 3) == 0)
1976 else if (strncasecmp (s
, "nbc", 3) == 0)
1982 else if (strncasecmp (s
, "nhc", 3) == 0)
1989 as_bad ("Invalid Logical Instruction Condition.");
1991 opcode
|= cmpltr
<< 13;
1992 opcode
|= flag
<< 12;
1995 /* Handle a shift/extract/deposit condition. */
2003 while (*s
!= ',' && *s
!= ' ' && *s
!= '\t')
2007 if (strcmp (name
, "=") == 0)
2009 else if (strcmp (name
, "<") == 0)
2011 else if (strcasecmp (name
, "od") == 0)
2013 else if (strcasecmp (name
, "tr") == 0)
2015 else if (strcmp (name
, "<>") == 0)
2017 else if (strcmp (name
, ">=") == 0)
2019 else if (strcasecmp (name
, "ev") == 0)
2021 /* Handle movb,n. Put things back the way they were.
2022 This includes moving s back to where it started. */
2023 else if (strcasecmp (name
, "n") == 0 && *args
== '|')
2030 as_bad ("Invalid Shift/Extract/Deposit Condition.");
2033 opcode
|= cmpltr
<< 13;
2036 /* Handle bvb and bb conditions. */
2042 if (strncmp (s
, "<", 1) == 0)
2047 else if (strncmp (s
, ">=", 2) == 0)
2053 as_bad ("Invalid Bit Branch Condition: %c", *s
);
2055 opcode
|= cmpltr
<< 13;
2058 /* Handle a 5 bit immediate at 31. */
2061 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2062 the_insn
.field_selector
),
2068 /* Handle an unsigned 5 bit immediate at 31. */
2071 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2074 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2082 /* Handle an unsigned 5 bit immediate at 15. */
2085 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2088 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2092 opcode
|= im5
<< 16;
2096 /* Handle a 11 bit immediate at 31. */
2098 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2100 if (the_insn
.exp
.X_op
== O_constant
)
2102 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2103 the_insn
.field_selector
),
2109 if (is_DP_relative (the_insn
.exp
))
2110 the_insn
.reloc
= R_HPPA_GOTOFF
;
2111 else if (is_PC_relative (the_insn
.exp
))
2112 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2113 else if (is_complex (the_insn
.exp
))
2114 the_insn
.reloc
= R_HPPA_COMPLEX
;
2116 the_insn
.reloc
= R_HPPA
;
2117 the_insn
.format
= 11;
2122 /* Handle a 14 bit immediate at 31. */
2124 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2126 if (the_insn
.exp
.X_op
== O_constant
)
2128 low_sign_unext (evaluate_absolute (the_insn
.exp
,
2129 the_insn
.field_selector
),
2131 if (the_insn
.field_selector
== e_rsel
)
2132 opcode
|= (im14
& 0xfff);
2138 if (is_DP_relative (the_insn
.exp
))
2139 the_insn
.reloc
= R_HPPA_GOTOFF
;
2140 else if (is_PC_relative (the_insn
.exp
))
2141 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2142 else if (is_complex (the_insn
.exp
))
2143 the_insn
.reloc
= R_HPPA_COMPLEX
;
2145 the_insn
.reloc
= R_HPPA
;
2146 the_insn
.format
= 14;
2151 /* Handle a 21 bit immediate at 31. */
2153 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2155 if (the_insn
.exp
.X_op
== O_constant
)
2157 dis_assemble_21 (evaluate_absolute (the_insn
.exp
,
2158 the_insn
.field_selector
),
2164 if (is_DP_relative (the_insn
.exp
))
2165 the_insn
.reloc
= R_HPPA_GOTOFF
;
2166 else if (is_PC_relative (the_insn
.exp
))
2167 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2168 else if (is_complex (the_insn
.exp
))
2169 the_insn
.reloc
= R_HPPA_COMPLEX
;
2171 the_insn
.reloc
= R_HPPA
;
2172 the_insn
.format
= 21;
2177 /* Handle a nullification completer for branch instructions. */
2179 nullif
= pa_parse_nullif (&s
);
2180 opcode
|= nullif
<< 1;
2183 /* Handle a 12 bit branch displacement. */
2185 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2188 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
), "L0\001"))
2190 unsigned int w1
, w
, result
;
2192 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 12,
2194 dis_assemble_12 (result
, &w1
, &w
);
2195 opcode
|= ((w1
<< 2) | w
);
2199 if (is_complex (the_insn
.exp
))
2200 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2202 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2203 the_insn
.format
= 12;
2204 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2205 bzero (&last_call_desc
, sizeof (struct call_desc
));
2210 /* Handle a 17 bit branch displacement. */
2212 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2215 if (the_insn
.exp
.X_add_symbol
)
2217 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2220 unsigned int w2
, w1
, w
, result
;
2222 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2224 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2225 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2229 if (is_complex (the_insn
.exp
))
2230 the_insn
.reloc
= R_HPPA_COMPLEX_PCREL_CALL
;
2232 the_insn
.reloc
= R_HPPA_PCREL_CALL
;
2233 the_insn
.format
= 17;
2234 the_insn
.arg_reloc
= last_call_desc
.arg_reloc
;
2235 bzero (&last_call_desc
, sizeof (struct call_desc
));
2240 unsigned int w2
, w1
, w
, result
;
2242 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2243 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2244 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2249 /* Handle an absolute 17 bit branch target. */
2251 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2254 if (the_insn
.exp
.X_add_symbol
)
2256 if (!strcmp (S_GET_NAME (the_insn
.exp
.X_add_symbol
),
2259 unsigned int w2
, w1
, w
, result
;
2261 sign_unext ((the_insn
.exp
.X_add_number
- 8) >> 2, 17,
2263 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2264 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2268 if (is_complex (the_insn
.exp
))
2269 the_insn
.reloc
= R_HPPA_COMPLEX_ABS_CALL
;
2271 the_insn
.reloc
= R_HPPA_ABS_CALL
;
2272 the_insn
.format
= 17;
2277 unsigned int w2
, w1
, w
, result
;
2279 sign_unext (the_insn
.exp
.X_add_number
>> 2, 17, &result
);
2280 dis_assemble_17 (result
, &w1
, &w2
, &w
);
2281 opcode
|= ((w2
<< 2) | (w1
<< 16) | w
);
2286 /* Handle a 5 bit shift count at 26. */
2289 if (the_insn
.exp
.X_op
== O_constant
)
2290 opcode
|= (((31 - the_insn
.exp
.X_add_number
) & 0x1f) << 5);
2294 /* Handle a 5 bit bit position at 26. */
2297 if (the_insn
.exp
.X_op
== O_constant
)
2298 opcode
|= (the_insn
.exp
.X_add_number
& 0x1f) << 5;
2302 /* Handle a 5 bit immediate at 10. */
2305 im5
= evaluate_absolute (the_insn
.exp
, the_insn
.field_selector
);
2308 as_bad ("Operand out of range. Was: %d. Should be [0..31].",
2312 opcode
|= im5
<< 21;
2316 /* Handle a 13 bit immediate at 18. */
2318 pa_get_absolute_expression (s
);
2319 if (the_insn
.exp
.X_op
== O_constant
)
2320 opcode
|= (the_insn
.exp
.X_add_number
& 0x1fff) << 13;
2324 /* Handle a system control completer. */
2326 if (*s
== ',' && (*(s
+ 1) == 'm' || *(s
+ 1) == 'M'))
2335 while (*s
== ' ' || *s
== '\t')
2339 /* Handle a 26 bit immediate at 31. */
2341 the_insn
.field_selector
= pa_chk_field_selector (&s
);
2343 if (the_insn
.exp
.X_op
== O_constant
)
2345 opcode
|= ((evaluate_absolute (the_insn
.exp
,
2346 the_insn
.field_selector
)
2350 as_bad ("Invalid DIAG operand");
2354 /* Handle a 3 bit SFU identifier at 25. */
2356 sfu
= pa_parse_number (&s
, 0);
2357 if ((sfu
> 7) || (sfu
< 0))
2358 as_bad ("Invalid SFU identifier: %02x", sfu
);
2359 opcode
|= (sfu
& 7) << 6;
2362 /* We don't support any of these. FIXME. */
2369 /* Handle a source FP operand format completer. */
2371 flag
= pa_parse_fp_format (&s
);
2372 opcode
|= (int) flag
<< 11;
2373 the_insn
.fpof1
= flag
;
2376 /* Handle a destination FP operand format completer. */
2379 /* pa_parse_format needs the ',' prefix. */
2381 flag
= pa_parse_fp_format (&s
);
2382 opcode
|= (int) flag
<< 13;
2383 the_insn
.fpof2
= flag
;
2386 /* Handle FP compare conditions. */
2388 cond
= pa_parse_fp_cmp_cond (&s
);
2392 /* Handle L/R register halves like 't'. */
2395 struct pa_89_fp_reg_struct result
;
2397 pa_parse_number (&s
, &result
);
2398 if (result
.number_part
< 32 && result
.number_part
>= 0)
2400 opcode
|= (result
.number_part
& 0x1f);
2402 /* 0x30 opcodes are FP arithmetic operation opcodes
2403 and need to be turned into 0x38 opcodes. This
2404 is not necessary for loads/stores. */
2405 if (need_89_opcode (&the_insn
, &result
))
2407 if ((opcode
& 0xfc000000) == 0x30000000)
2409 opcode
|= (result
.l_r_select
& 1) << 6;
2414 opcode
|= (result
.l_r_select
& 1) << 6;
2422 /* Handle L/R register halves like 'b'. */
2425 struct pa_89_fp_reg_struct result
;
2427 pa_parse_number (&s
, &result
);
2428 if (result
.number_part
< 32 && result
.number_part
>= 0)
2430 opcode
|= (result
.number_part
& 0x1f) << 21;
2431 if (need_89_opcode (&the_insn
, &result
))
2433 opcode
|= (result
.l_r_select
& 1) << 7;
2441 /* Handle L/R register halves like 'x'. */
2444 struct pa_89_fp_reg_struct result
;
2446 pa_parse_number (&s
, &result
);
2447 if (result
.number_part
< 32 && result
.number_part
>= 0)
2449 opcode
|= (result
.number_part
& 0x1f) << 16;
2450 if (need_89_opcode (&the_insn
, &result
))
2452 opcode
|= (result
.l_r_select
& 1) << 12;
2460 /* Handle a 5 bit register field at 10. */
2463 struct pa_89_fp_reg_struct result
;
2466 status
= pa_parse_number (&s
, &result
);
2467 if (result
.number_part
< 32 && result
.number_part
>= 0)
2469 if (the_insn
.fpof1
== SGL
)
2471 result
.number_part
&= 0xF;
2472 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2474 opcode
|= result
.number_part
<< 21;
2480 /* Handle a 5 bit register field at 15. */
2483 struct pa_89_fp_reg_struct result
;
2486 status
= pa_parse_number (&s
, &result
);
2487 if (result
.number_part
< 32 && result
.number_part
>= 0)
2489 if (the_insn
.fpof1
== SGL
)
2491 result
.number_part
&= 0xF;
2492 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2494 opcode
|= result
.number_part
<< 16;
2500 /* Handle a 5 bit register field at 31. */
2503 struct pa_89_fp_reg_struct result
;
2506 status
= pa_parse_number (&s
, &result
);
2507 if (result
.number_part
< 32 && result
.number_part
>= 0)
2509 if (the_insn
.fpof1
== SGL
)
2511 result
.number_part
&= 0xF;
2512 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2514 opcode
|= result
.number_part
;
2520 /* Handle a 5 bit register field at 20. */
2523 struct pa_89_fp_reg_struct result
;
2526 status
= pa_parse_number (&s
, &result
);
2527 if (result
.number_part
< 32 && result
.number_part
>= 0)
2529 if (the_insn
.fpof1
== SGL
)
2531 result
.number_part
&= 0xF;
2532 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2534 opcode
|= result
.number_part
<< 11;
2540 /* Handle a 5 bit register field at 25. */
2543 struct pa_89_fp_reg_struct result
;
2546 status
= pa_parse_number (&s
, &result
);
2547 if (result
.number_part
< 32 && result
.number_part
>= 0)
2549 if (the_insn
.fpof1
== SGL
)
2551 result
.number_part
&= 0xF;
2552 result
.number_part
|= (result
.l_r_select
& 1) << 4;
2554 opcode
|= result
.number_part
<< 6;
2560 /* Handle a floating point operand format at 26.
2561 Only allows single and double precision. */
2563 flag
= pa_parse_fp_format (&s
);
2569 the_insn
.fpof1
= flag
;
2575 as_bad ("Invalid Floating Point Operand Format.");
2585 /* Check if the args matched. */
2588 if (&insn
[1] - pa_opcodes
< NUMOPCODES
2589 && !strcmp (insn
->name
, insn
[1].name
))
2597 as_bad ("Invalid operands %s", error_message
);
2604 the_insn
.opcode
= opcode
;
2608 /* Turn a string in input_line_pointer into a floating point constant of type
2609 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2610 emitted is stored in *sizeP . An error message or NULL is returned. */
2612 #define MAX_LITTLENUMS 6
2615 md_atof (type
, litP
, sizeP
)
2621 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
2622 LITTLENUM_TYPE
*wordP
;
2654 return "Bad call to MD_ATOF()";
2656 t
= atof_ieee (input_line_pointer
, type
, words
);
2658 input_line_pointer
= t
;
2659 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
2660 for (wordP
= words
; prec
--;)
2662 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
2663 litP
+= sizeof (LITTLENUM_TYPE
);
2668 /* Write out big-endian. */
2671 md_number_to_chars (buf
, val
, n
)
2693 /* Translate internal representation of relocation info to BFD target
2697 tc_gen_reloc (section
, fixp
)
2702 struct hppa_fix_struct
*hppa_fixp
= fixp
->tc_fix_data
;
2703 bfd_reloc_code_real_type code
;
2704 static int unwind_reloc_fixp_cnt
= 0;
2705 static arelent
*unwind_reloc_entryP
= NULL
;
2706 static arelent
*no_relocs
= NULL
;
2708 bfd_reloc_code_real_type
**codes
;
2712 if (fixp
->fx_addsy
== 0)
2714 assert (hppa_fixp
!= 0);
2715 assert (section
!= 0);
2718 /* Yuk. I would really like to push all this ELF specific unwind
2719 crud into BFD and the linker. That's how SOM does it -- and
2720 if we could make ELF emulate that then we could share more code
2721 in GAS (and potentially a gnu-linker later).
2723 Unwind section relocations are handled in a special way.
2724 The relocations for the .unwind section are originally
2725 built in the usual way. That is, for each unwind table
2726 entry there are two relocations: one for the beginning of
2727 the function and one for the end.
2729 The first time we enter this function we create a
2730 relocation of the type R_HPPA_UNWIND_ENTRIES. The addend
2731 of the relocation is initialized to 0. Each additional
2732 pair of times this function is called for the unwind
2733 section represents an additional unwind table entry. Thus,
2734 the addend of the relocation should end up to be the number
2735 of unwind table entries. */
2736 if (strcmp (UNWIND_SECTION_NAME
, section
->name
) == 0)
2738 if (unwind_reloc_entryP
== NULL
)
2740 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2742 assert (reloc
!= 0);
2743 unwind_reloc_entryP
= reloc
;
2744 unwind_reloc_fixp_cnt
++;
2745 unwind_reloc_entryP
->address
2746 = fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2747 /* A pointer to any function will do. We only
2748 need one to tell us what section the unwind
2749 relocations are for. */
2750 unwind_reloc_entryP
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2751 hppa_fixp
->fx_r_type
= code
= R_HPPA_UNWIND_ENTRIES
;
2752 fixp
->fx_r_type
= R_HPPA_UNWIND
;
2753 unwind_reloc_entryP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2754 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2755 relocs
= (arelent
**) bfd_alloc_by_size_t (stdoutput
,
2756 sizeof (arelent
*) * 2);
2757 assert (relocs
!= 0);
2758 relocs
[0] = unwind_reloc_entryP
;
2762 unwind_reloc_fixp_cnt
++;
2763 unwind_reloc_entryP
->addend
= unwind_reloc_fixp_cnt
/ 2;
2769 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
));
2770 assert (reloc
!= 0);
2772 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2773 codes
= hppa_gen_reloc_type (stdoutput
,
2775 hppa_fixp
->fx_r_format
,
2776 hppa_fixp
->fx_r_field
);
2778 for (n_relocs
= 0; codes
[n_relocs
]; n_relocs
++)
2781 relocs
= (arelent
**)
2782 bfd_alloc_by_size_t (stdoutput
, sizeof (arelent
*) * n_relocs
+ 1);
2783 assert (relocs
!= 0);
2785 reloc
= (arelent
*) bfd_alloc_by_size_t (stdoutput
,
2786 sizeof (arelent
) * n_relocs
);
2788 assert (reloc
!= 0);
2790 for (i
= 0; i
< n_relocs
; i
++)
2791 relocs
[i
] = &reloc
[i
];
2793 relocs
[n_relocs
] = NULL
;
2796 switch (fixp
->fx_r_type
)
2798 case R_HPPA_COMPLEX
:
2799 case R_HPPA_COMPLEX_PCREL_CALL
:
2800 case R_HPPA_COMPLEX_ABS_CALL
:
2801 assert (n_relocs
== 5);
2803 for (i
= 0; i
< n_relocs
; i
++)
2805 reloc
[i
].sym_ptr_ptr
= NULL
;
2806 reloc
[i
].address
= 0;
2807 reloc
[i
].addend
= 0;
2808 reloc
[i
].howto
= bfd_reloc_type_lookup (stdoutput
, *codes
[i
]);
2809 assert (reloc
[i
].howto
&& *codes
[i
] == reloc
[i
].howto
->type
);
2812 reloc
[0].sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2813 reloc
[1].sym_ptr_ptr
= &fixp
->fx_subsy
->bsym
;
2814 reloc
[4].address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2816 if (fixp
->fx_r_type
== R_HPPA_COMPLEX
)
2817 reloc
[3].addend
= fixp
->fx_addnumber
;
2818 else if (fixp
->fx_r_type
== R_HPPA_COMPLEX_PCREL_CALL
||
2819 fixp
->fx_r_type
== R_HPPA_COMPLEX_ABS_CALL
)
2820 reloc
[1].addend
= fixp
->fx_addnumber
;
2825 assert (n_relocs
== 1);
2829 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2830 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2831 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2832 reloc
->addend
= 0; /* default */
2834 assert (reloc
->howto
&& code
== reloc
->howto
->type
);
2836 /* Now, do any processing that is dependent on the relocation type. */
2839 case R_HPPA_PLABEL_32
:
2840 case R_HPPA_PLABEL_11
:
2841 case R_HPPA_PLABEL_14
:
2842 case R_HPPA_PLABEL_L21
:
2843 case R_HPPA_PLABEL_R11
:
2844 case R_HPPA_PLABEL_R14
:
2845 /* For plabel relocations, the addend of the
2846 relocation should be either 0 (no static link) or 2
2847 (static link required).
2849 FIXME: assume that fx_addnumber contains this
2851 reloc
->addend
= fixp
->fx_addnumber
;
2854 case R_HPPA_ABS_CALL_11
:
2855 case R_HPPA_ABS_CALL_14
:
2856 case R_HPPA_ABS_CALL_17
:
2857 case R_HPPA_ABS_CALL_L21
:
2858 case R_HPPA_ABS_CALL_R11
:
2859 case R_HPPA_ABS_CALL_R14
:
2860 case R_HPPA_ABS_CALL_R17
:
2861 case R_HPPA_ABS_CALL_LS21
:
2862 case R_HPPA_ABS_CALL_RS11
:
2863 case R_HPPA_ABS_CALL_RS14
:
2864 case R_HPPA_ABS_CALL_RS17
:
2865 case R_HPPA_ABS_CALL_LD21
:
2866 case R_HPPA_ABS_CALL_RD11
:
2867 case R_HPPA_ABS_CALL_RD14
:
2868 case R_HPPA_ABS_CALL_RD17
:
2869 case R_HPPA_ABS_CALL_LR21
:
2870 case R_HPPA_ABS_CALL_RR14
:
2871 case R_HPPA_ABS_CALL_RR17
:
2873 case R_HPPA_PCREL_CALL_11
:
2874 case R_HPPA_PCREL_CALL_14
:
2875 case R_HPPA_PCREL_CALL_17
:
2876 case R_HPPA_PCREL_CALL_L21
:
2877 case R_HPPA_PCREL_CALL_R11
:
2878 case R_HPPA_PCREL_CALL_R14
:
2879 case R_HPPA_PCREL_CALL_R17
:
2880 case R_HPPA_PCREL_CALL_LS21
:
2881 case R_HPPA_PCREL_CALL_RS11
:
2882 case R_HPPA_PCREL_CALL_RS14
:
2883 case R_HPPA_PCREL_CALL_RS17
:
2884 case R_HPPA_PCREL_CALL_LD21
:
2885 case R_HPPA_PCREL_CALL_RD11
:
2886 case R_HPPA_PCREL_CALL_RD14
:
2887 case R_HPPA_PCREL_CALL_RD17
:
2888 case R_HPPA_PCREL_CALL_LR21
:
2889 case R_HPPA_PCREL_CALL_RR14
:
2890 case R_HPPA_PCREL_CALL_RR17
:
2891 /* The constant is stored in the instruction. */
2892 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2895 reloc
->addend
= fixp
->fx_addnumber
;
2902 /* Preliminary relocation handling for SOM. Needs to handle
2903 COMPLEX relocations (yes, I've seen them occur) and it will
2904 need to handle R_ENTRY/R_EXIT relocations in the very near future
2905 (for generating unwinds). */
2906 switch (fixp
->fx_r_type
)
2908 case R_HPPA_COMPLEX
:
2909 case R_HPPA_COMPLEX_PCREL_CALL
:
2910 case R_HPPA_COMPLEX_ABS_CALL
:
2914 assert (n_relocs
== 1);
2918 reloc
->sym_ptr_ptr
= &fixp
->fx_addsy
->bsym
;
2919 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2920 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2927 reloc
->addend
= HPPA_R_ADDEND (hppa_fixp
->fx_arg_reloc
, 0);
2930 reloc
->addend
= fixp
->fx_addnumber
;
2940 /* Process any machine dependent frag types. */
2943 md_convert_frag (abfd
, sec
, fragP
)
2945 register asection
*sec
;
2946 register fragS
*fragP
;
2948 unsigned int address
;
2950 if (fragP
->fr_type
== rs_machine_dependent
)
2952 switch ((int) fragP
->fr_subtype
)
2955 fragP
->fr_type
= rs_fill
;
2956 know (fragP
->fr_var
== 1);
2957 know (fragP
->fr_next
);
2958 address
= fragP
->fr_address
+ fragP
->fr_fix
;
2959 if (address
% fragP
->fr_offset
)
2962 fragP
->fr_next
->fr_address
2967 fragP
->fr_offset
= 0;
2973 /* Round up a section size to the appropriate boundary. */
2976 md_section_align (segment
, size
)
2980 int align
= bfd_get_section_alignment (stdoutput
, segment
);
2981 int align2
= (1 << align
) - 1;
2983 return (size
+ align2
) & ~align2
;
2987 /* Create a short jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
2989 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
2991 addressT from_addr
, to_addr
;
2995 fprintf (stderr
, "pa_create_short_jmp\n");
2999 /* Create a long jump from FROM_ADDR to TO_ADDR. Not used on the PA. */
3001 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3003 addressT from_addr
, to_addr
;
3007 fprintf (stderr
, "pa_create_long_jump\n");
3011 /* Return the approximate size of a frag before relaxation has occurred. */
3013 md_estimate_size_before_relax (fragP
, segment
)
3014 register fragS
*fragP
;
3021 while ((fragP
->fr_fix
+ size
) % fragP
->fr_offset
)
3027 /* Parse machine dependent options. There are none on the PA. */
3029 md_parse_option (argP
, cntP
, vecP
)
3037 /* We have no need to default values of symbols. */
3040 md_undefined_symbol (name
)
3046 /* Parse an operand that is machine-specific.
3047 We just return without modifying the expression as we have nothing
3051 md_operand (expressionP
)
3052 expressionS
*expressionP
;
3056 /* Helper function for md_apply_fix. Actually determine if the fix
3057 can be applied, and if so, apply it.
3059 If a fix is applied, then set fx_addsy to NULL which indicates
3060 the fix was applied and need not be emitted into the object file. */
3063 md_apply_fix_1 (fixP
, val
)
3067 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
3068 struct hppa_fix_struct
*hppa_fixP
= fixP
->tc_fix_data
;
3069 long new_val
, result
;
3070 unsigned int w1
, w2
, w
;
3072 /* There should have been an HPPA specific fixup associated
3073 with the GAS fixup. */
3076 unsigned long buf_wd
= bfd_get_32 (stdoutput
, buf
);
3077 unsigned char fmt
= bfd_hppa_insn2fmt (buf_wd
);
3079 /* Sanity check the fixup type. */
3080 /* Is this really necessary? */
3081 if (fixP
->fx_r_type
== R_HPPA_NONE
)
3084 /* Remember this value for emit_reloc. FIXME, is this braindamage
3085 documented anywhere!?! */
3086 fixP
->fx_addnumber
= val
;
3088 /* Check if this is an undefined symbol. No relocation can
3089 possibly be performed in this case. */
3090 if ((fixP
->fx_addsy
&& fixP
->fx_addsy
->bsym
->section
== &bfd_und_section
)
3092 && fixP
->fx_subsy
->bsym
->section
== &bfd_und_section
))
3097 /* Handle all opcodes with the 'j' operand type. */
3099 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3101 /* Mask off 14 bits to be changed. */
3102 bfd_put_32 (stdoutput
,
3103 bfd_get_32 (stdoutput
, buf
) & 0xffffc000,
3105 low_sign_unext (new_val
, 14, &result
);
3108 /* Handle all opcodes with the 'k' operand type. */
3110 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3112 /* Mask off 21 bits to be changed. */
3113 bfd_put_32 (stdoutput
,
3114 bfd_get_32 (stdoutput
, buf
) & 0xffe00000,
3116 dis_assemble_21 (new_val
, &result
);
3119 /* Handle all the opcodes with the 'i' operand type. */
3121 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3123 /* Mask off 11 bits to be changed. */
3124 bfd_put_32 (stdoutput
,
3125 bfd_get_32 (stdoutput
, buf
) & 0xffff800,
3127 low_sign_unext (new_val
, 11, &result
);
3130 /* Handle all the opcodes with the 'w' operand type. */
3132 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3134 /* Mask off 11 bits to be changed. */
3135 sign_unext ((new_val
- 8) >> 2, 12, &result
);
3136 bfd_put_32 (stdoutput
,
3137 bfd_get_32 (stdoutput
, buf
) & 0xffffe002,
3140 dis_assemble_12 (result
, &w1
, &w
);
3141 result
= ((w1
<< 2) | w
);
3142 fixP
->fx_addsy
= NULL
;
3145 #define too_far(VAL, NUM_BITS) \
3146 (((int)(VAL) > (1 << (NUM_BITS)) - 1) || ((int)(VAL) < (-1 << (NUM_BITS))))
3148 #define stub_needed(CALLER, CALLEE) \
3149 ((CALLEE) && (CALLER) && ((CALLEE) != (CALLER)))
3151 /* Handle some of the opcodes with the 'W' operand type. */
3153 /* If a long-call stub or argument relocation stub is
3154 needed, then we can not apply this relocation, instead
3155 the linker must handle it. */
3156 if (too_far (val
, 18)
3157 || stub_needed (((obj_symbol_type
*)
3158 fixP
->fx_addsy
->bsym
)->tc_data
.hppa_arg_reloc
,
3159 hppa_fixP
->fx_arg_reloc
))
3162 /* No stubs were needed, we can perform this relocation. */
3163 new_val
= hppa_field_adjust (val
, 0, hppa_fixP
->fx_r_field
);
3165 /* Mask off 17 bits to be changed. */
3166 bfd_put_32 (stdoutput
,
3167 bfd_get_32 (stdoutput
, buf
) & 0xffe0e002,
3169 sign_unext ((new_val
- 8) >> 2, 17, &result
);
3170 dis_assemble_17 (result
, &w1
, &w2
, &w
);
3171 result
= ((w2
<< 2) | (w1
<< 16) | w
);
3172 fixP
->fx_addsy
= NULL
;
3180 if (hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRY
3181 || hppa_fixP
->fx_r_type
== R_HPPA_UNWIND_ENTRIES
)
3182 result
= fixP
->fx_addnumber
;
3187 fixP
->fx_addnumber
= fixP
->fx_offset
;
3188 bfd_put_32 (stdoutput
, 0, buf
);
3197 as_bad ("bad relocation type/fmt: 0x%02x/0x%02x",
3198 fixP
->fx_r_type
, fmt
);
3202 /* Insert the relocation. */
3203 buf
[0] |= (result
& 0xff000000) >> 24;
3204 buf
[1] |= (result
& 0x00ff0000) >> 16;
3205 buf
[2] |= (result
& 0x0000ff00) >> 8;
3206 buf
[3] |= result
& 0x000000ff;
3209 printf ("no hppa_fixup entry for this fixup (fixP = 0x%x, type = 0x%x)\n",
3210 (unsigned int) fixP
, fixP
->fx_r_type
);
3213 /* Apply a fix into a frag's data (if possible). */
3216 md_apply_fix (fixP
, valp
)
3220 md_apply_fix_1 (fixP
, (long) *valp
);
3224 /* Exactly what point is a PC-relative offset relative TO?
3225 On the PA, they're relative to the address of the offset. */
3228 md_pcrel_from (fixP
)
3231 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3234 /* Return nonzero if the input line pointer is at the end of
3238 is_end_of_statement ()
3240 return ((*input_line_pointer
== '\n')
3241 || (*input_line_pointer
== ';')
3242 || (*input_line_pointer
== '!'));
3245 /* Read a number from S. The number might come in one of many forms,
3246 the most common will be a hex or decimal constant, but it could be
3247 a pre-defined register (Yuk!), or an absolute symbol.
3249 Return a number or -1 for failure.
3251 When parsing PA-89 FP register numbers RESULT will be
3252 the address of a structure to return information about
3253 L/R half of FP registers, store results there as appropriate.
3255 pa_parse_number can not handle negative constants and will fail
3256 horribly if it is passed such a constant. */
3259 pa_parse_number (s
, result
)
3261 struct pa_89_fp_reg_struct
*result
;
3270 /* Skip whitespace before the number. */
3271 while (*p
== ' ' || *p
== '\t')
3274 /* Store info in RESULT if requested by caller. */
3277 result
->number_part
= -1;
3278 result
->l_r_select
= -1;
3284 /* Looks like a number. */
3287 if (*p
== '0' && (*(p
+ 1) == 'x' || *(p
+ 1) == 'X'))
3289 /* The number is specified in hex. */
3291 while (isdigit (*p
) || ((*p
>= 'a') && (*p
<= 'f'))
3292 || ((*p
>= 'A') && (*p
<= 'F')))
3295 num
= num
* 16 + *p
- '0';
3296 else if (*p
>= 'a' && *p
<= 'f')
3297 num
= num
* 16 + *p
- 'a' + 10;
3299 num
= num
* 16 + *p
- 'A' + 10;
3305 /* The number is specified in decimal. */
3306 while (isdigit (*p
))
3308 num
= num
* 10 + *p
- '0';
3313 /* Store info in RESULT if requested by the caller. */
3316 result
->number_part
= num
;
3318 if (IS_R_SELECT (p
))
3320 result
->l_r_select
= 1;
3323 else if (IS_L_SELECT (p
))
3325 result
->l_r_select
= 0;
3329 result
->l_r_select
= 0;
3334 /* The number might be a predefined register. */
3339 /* Tege hack: Special case for general registers as the general
3340 code makes a binary search with case translation, and is VERY
3345 if (*p
== 'e' && *(p
+ 1) == 't'
3346 && (*(p
+ 2) == '0' || *(p
+ 2) == '1'))
3349 num
= *p
- '0' + 28;
3352 else if (!isdigit (*p
))
3353 as_bad ("Undefined register: '%s'. ASSUMING 0", name
);
3357 num
= num
* 10 + *p
++ - '0';
3358 while (isdigit (*p
));
3363 /* Do a normal register search. */
3364 while (is_part_of_name (c
))
3370 status
= reg_name_search (name
);
3376 as_bad ("Undefined register: '%s'. ASSUMING 0", name
);
3383 /* Store info in RESULT if requested by caller. */
3386 result
->number_part
= num
;
3387 if (IS_R_SELECT (p
- 1))
3388 result
->l_r_select
= 1;
3389 else if (IS_L_SELECT (p
- 1))
3390 result
->l_r_select
= 0;
3392 result
->l_r_select
= 0;
3397 /* And finally, it could be a symbol in the absolute section which
3398 is effectively a constant. */
3402 while (is_part_of_name (c
))
3408 if ((sym
= symbol_find (name
)) != NULL
)
3410 if (S_GET_SEGMENT (sym
) == &bfd_abs_section
)
3411 num
= S_GET_VALUE (sym
);
3415 as_bad ("Non-absolute constant: '%s'. ASSUMING 0", name
);
3423 as_bad ("Undefined absolute constant: '%s'. ASSUMING 0", name
);
3429 /* Store info in RESULT if requested by caller. */
3432 result
->number_part
= num
;
3433 if (IS_R_SELECT (p
- 1))
3434 result
->l_r_select
= 1;
3435 else if (IS_L_SELECT (p
- 1))
3436 result
->l_r_select
= 0;
3438 result
->l_r_select
= 0;
3446 #define REG_NAME_CNT (sizeof(pre_defined_registers) / sizeof(struct pd_reg))
3448 /* Given NAME, find the register number associated with that name, return
3449 the integer value associated with the given name or -1 on failure. */
3452 reg_name_search (name
)
3455 int middle
, low
, high
;
3458 high
= REG_NAME_CNT
- 1;
3462 middle
= (low
+ high
) / 2;
3463 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) < 0)
3468 while (!((strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0) ||
3471 if (strcasecmp (name
, pre_defined_registers
[middle
].name
) == 0)
3472 return (pre_defined_registers
[middle
].value
);
3478 /* Return nonzero if the given INSN and L/R information will require
3479 a new PA-89 opcode. */
3482 need_89_opcode (insn
, result
)
3484 struct pa_89_fp_reg_struct
*result
;
3486 if (result
->l_r_select
== 1 && !(insn
->fpof1
== DBL
&& insn
->fpof2
== DBL
))
3492 /* Parse a condition for a fcmp instruction. Return the numerical
3493 code associated with the condition. */
3496 pa_parse_fp_cmp_cond (s
)
3503 for (i
= 0; i
< 32; i
++)
3505 if (strncasecmp (*s
, fp_cond_map
[i
].string
,
3506 strlen (fp_cond_map
[i
].string
)) == 0)
3508 cond
= fp_cond_map
[i
].cond
;
3509 *s
+= strlen (fp_cond_map
[i
].string
);
3510 while (**s
== ' ' || **s
== '\t')
3516 as_bad ("Invalid FP Compare Condition: %c", **s
);
3520 /* Parse an FP operand format completer returning the completer
3523 static fp_operand_format
3524 pa_parse_fp_format (s
)
3533 if (strncasecmp (*s
, "sgl", 3) == 0)
3538 else if (strncasecmp (*s
, "dbl", 3) == 0)
3543 else if (strncasecmp (*s
, "quad", 4) == 0)
3550 format
= ILLEGAL_FMT
;
3551 as_bad ("Invalid FP Operand Format: %3s", *s
);
3554 while (**s
== ' ' || **s
== '\t' || **s
== 0)
3560 /* Convert from a selector string into a selector type. */
3563 pa_chk_field_selector (str
)
3567 struct selector_entry
*tablep
;
3571 /* Read past any whitespace. */
3572 while (**str
== ' ' || **str
== '\t' || **str
== '\n' || **str
== '\f')
3575 /* Yuk. Looks like a linear search through the table. With the
3576 frequence of some selectors it might make sense to sort the
3578 for (tablep
= selector_table
; tablep
->prefix
; tablep
++)
3580 if (strncasecmp (tablep
->prefix
, *str
, strlen (tablep
->prefix
)) == 0)
3582 *str
+= strlen (tablep
->prefix
);
3583 selector
= tablep
->field_selector
;
3590 /* Mark (via expr_end) the end of an expression (I think). FIXME. */
3593 get_expression (str
)
3599 save_in
= input_line_pointer
;
3600 input_line_pointer
= str
;
3601 seg
= expression (&the_insn
.exp
);
3602 if (!(seg
== absolute_section
3603 || seg
== undefined_section
3604 || SEG_NORMAL (seg
)))
3606 as_warn ("Bad segment in expression.");
3607 expr_end
= input_line_pointer
;
3608 input_line_pointer
= save_in
;
3611 expr_end
= input_line_pointer
;
3612 input_line_pointer
= save_in
;
3616 /* Mark (via expr_end) the end of an absolute expression. FIXME. */
3618 pa_get_absolute_expression (str
)
3623 save_in
= input_line_pointer
;
3624 input_line_pointer
= str
;
3625 expression (&the_insn
.exp
);
3626 if (the_insn
.exp
.X_op
!= O_constant
)
3628 as_warn ("Bad segment (should be absolute).");
3629 expr_end
= input_line_pointer
;
3630 input_line_pointer
= save_in
;
3633 expr_end
= input_line_pointer
;
3634 input_line_pointer
= save_in
;
3638 /* Evaluate an absolute expression EXP which may be modified by
3639 the selector FIELD_SELECTOR. Return the value of the expression. */
3641 evaluate_absolute (exp
, field_selector
)
3647 value
= exp
.X_add_number
;
3649 switch (field_selector
)
3655 /* If bit 21 is on then add 0x800 and arithmetic shift right 11 bits. */
3657 if (value
& 0x00000400)
3659 value
= (value
& 0xfffff800) >> 11;
3662 /* Sign extend from bit 21. */
3664 if (value
& 0x00000400)
3665 value
|= 0xfffff800;
3670 /* Arithmetic shift right 11 bits. */
3672 value
= (value
& 0xfffff800) >> 11;
3675 /* Set bits 0-20 to zero. */
3677 value
= value
& 0x7ff;
3680 /* Add 0x800 and arithmetic shift right 11 bits. */
3685 value
= (value
& 0xfffff800) >> 11;
3688 /* Set bitgs 0-21 to one. */
3690 value
|= 0xfffff800;
3693 /* This had better get fixed. It looks like we're quickly moving
3700 BAD_CASE (field_selector
);
3706 /* Given an argument location specification return the associated
3707 argument location number. */
3710 pa_build_arg_reloc (type_name
)
3714 if (strncasecmp (type_name
, "no", 2) == 0)
3716 if (strncasecmp (type_name
, "gr", 2) == 0)
3718 else if (strncasecmp (type_name
, "fr", 2) == 0)
3720 else if (strncasecmp (type_name
, "fu", 2) == 0)
3723 as_bad ("Invalid argument location: %s\n", type_name
);
3728 /* Encode and return an argument relocation specification for
3729 the given register in the location specified by arg_reloc. */
3732 pa_align_arg_reloc (reg
, arg_reloc
)
3734 unsigned int arg_reloc
;
3736 unsigned int new_reloc
;
3738 new_reloc
= arg_reloc
;
3754 as_bad ("Invalid argument description: %d", reg
);
3760 /* Parse a PA nullification completer (,n). Return nonzero if the
3761 completer was found; return zero if no completer was found. */
3773 if (strncasecmp (*s
, "n", 1) == 0)
3777 as_bad ("Invalid Nullification: (%c)", **s
);
3782 while (**s
== ' ' || **s
== '\t')
3788 /* Parse a non-negated compare/subtract completer returning the
3789 number (for encoding in instrutions) of the given completer.
3791 ISBRANCH specifies whether or not this is parsing a condition
3792 completer for a branch (vs a nullification completer for a
3793 computational instruction. */
3796 pa_parse_nonneg_cmpsub_cmpltr (s
, isbranch
)
3801 char *name
= *s
+ 1;
3809 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3813 if (strcmp (name
, "=") == 0)
3817 else if (strcmp (name
, "<") == 0)
3821 else if (strcmp (name
, "<=") == 0)
3825 else if (strcmp (name
, "<<") == 0)
3829 else if (strcmp (name
, "<<=") == 0)
3833 else if (strcasecmp (name
, "sv") == 0)
3837 else if (strcasecmp (name
, "od") == 0)
3841 /* If we have something like addb,n then there is no condition
3843 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3855 while (**s
== ' ' || **s
== '\t')
3859 /* Reset pointers if this was really a ,n for a branch instruction. */
3860 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3866 /* Parse a negated compare/subtract completer returning the
3867 number (for encoding in instrutions) of the given completer.
3869 ISBRANCH specifies whether or not this is parsing a condition
3870 completer for a branch (vs a nullification completer for a
3871 computational instruction. */
3874 pa_parse_neg_cmpsub_cmpltr (s
, isbranch
)
3879 char *name
= *s
+ 1;
3887 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3891 if (strcasecmp (name
, "tr") == 0)
3895 else if (strcmp (name
, "<>") == 0)
3899 else if (strcmp (name
, ">=") == 0)
3903 else if (strcmp (name
, ">") == 0)
3907 else if (strcmp (name
, ">>=") == 0)
3911 else if (strcmp (name
, ">>") == 0)
3915 else if (strcasecmp (name
, "nsv") == 0)
3919 else if (strcasecmp (name
, "ev") == 0)
3923 /* If we have something like addb,n then there is no condition
3925 else if (strcasecmp (name
, "n") == 0 && isbranch
)
3937 while (**s
== ' ' || **s
== '\t')
3941 /* Reset pointers if this was really a ,n for a branch instruction. */
3942 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
3948 /* Parse a non-negated addition completer returning the number
3949 (for encoding in instrutions) of the given completer.
3951 ISBRANCH specifies whether or not this is parsing a condition
3952 completer for a branch (vs a nullification completer for a
3953 computational instruction. */
3956 pa_parse_nonneg_add_cmpltr (s
, isbranch
)
3961 char *name
= *s
+ 1;
3969 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
3973 if (strcmp (name
, "=") == 0)
3977 else if (strcmp (name
, "<") == 0)
3981 else if (strcmp (name
, "<=") == 0)
3985 else if (strcasecmp (name
, "nuv") == 0)
3989 else if (strcasecmp (name
, "znv") == 0)
3993 else if (strcasecmp (name
, "sv") == 0)
3997 else if (strcasecmp (name
, "od") == 0)
4001 /* If we have something like addb,n then there is no condition
4003 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4015 while (**s
== ' ' || **s
== '\t')
4019 /* Reset pointers if this was really a ,n for a branch instruction. */
4020 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4026 /* Parse a negated addition completer returning the number
4027 (for encoding in instrutions) of the given completer.
4029 ISBRANCH specifies whether or not this is parsing a condition
4030 completer for a branch (vs a nullification completer for a
4031 computational instruction. */
4034 pa_parse_neg_add_cmpltr (s
, isbranch
)
4039 char *name
= *s
+ 1;
4047 while (**s
!= ',' && **s
!= ' ' && **s
!= '\t')
4051 if (strcasecmp (name
, "tr") == 0)
4055 else if (strcmp (name
, "<>") == 0)
4059 else if (strcmp (name
, ">=") == 0)
4063 else if (strcmp (name
, ">") == 0)
4067 else if (strcmp (name
, "uv") == 0)
4071 else if (strcmp (name
, "vnz") == 0)
4075 else if (strcasecmp (name
, "nsv") == 0)
4079 else if (strcasecmp (name
, "ev") == 0)
4083 /* If we have something like addb,n then there is no condition
4085 else if (strcasecmp (name
, "n") == 0 && isbranch
)
4097 while (**s
== ' ' || **s
== '\t')
4101 /* Reset pointers if this was really a ,n for a branch instruction. */
4102 if (cmpltr
== 0 && *name
== 'n' && isbranch
)
4108 /* Handle a .BLOCK type pseudo-op. */
4116 unsigned int temp_size
;
4119 temp_size
= get_absolute_expression ();
4121 /* Always fill with zeros, that's what the HP assembler does. */
4124 p
= frag_var (rs_fill
, (int) temp_size
, (int) temp_size
,
4125 (relax_substateT
) 0, (symbolS
*) 0, 1, NULL
);
4126 bzero (p
, temp_size
);
4128 /* Convert 2 bytes at a time. */
4130 for (i
= 0; i
< temp_size
; i
+= 2)
4132 md_number_to_chars (p
+ i
,
4134 (int) ((temp_size
- i
) > 2 ? 2 : (temp_size
- i
)));
4137 pa_undefine_label ();
4138 demand_empty_rest_of_line ();
4142 /* Handle a .CALL pseudo-op. This involves storing away information
4143 about where arguments are to be found so the linker can detect
4144 (and correct) argument location mismatches between caller and callee. */
4150 pa_call_args (&last_call_desc
);
4151 demand_empty_rest_of_line ();
4155 /* Do the dirty work of building a call descriptor which describes
4156 where the caller placed arguments to a function call. */
4159 pa_call_args (call_desc
)
4160 struct call_desc
*call_desc
;
4163 unsigned int temp
, arg_reloc
;
4165 while (!is_end_of_statement ())
4167 name
= input_line_pointer
;
4168 c
= get_symbol_end ();
4169 /* Process a source argument. */
4170 if ((strncasecmp (name
, "argw", 4) == 0))
4172 temp
= atoi (name
+ 4);
4173 p
= input_line_pointer
;
4175 input_line_pointer
++;
4176 name
= input_line_pointer
;
4177 c
= get_symbol_end ();
4178 arg_reloc
= pa_build_arg_reloc (name
);
4179 call_desc
->arg_reloc
|= pa_align_arg_reloc (temp
, arg_reloc
);
4181 /* Process a return value. */
4182 else if ((strncasecmp (name
, "rtnval", 6) == 0))
4184 p
= input_line_pointer
;
4186 input_line_pointer
++;
4187 name
= input_line_pointer
;
4188 c
= get_symbol_end ();
4189 arg_reloc
= pa_build_arg_reloc (name
);
4190 call_desc
->arg_reloc
|= (arg_reloc
& 0x3);
4194 as_bad ("Invalid .CALL argument: %s", name
);
4196 p
= input_line_pointer
;
4198 if (!is_end_of_statement ())
4199 input_line_pointer
++;
4203 /* Return TRUE if FRAG1 and FRAG2 are the same. */
4206 is_same_frag (frag1
, frag2
)
4213 else if (frag2
== NULL
)
4215 else if (frag1
== frag2
)
4217 else if (frag2
->fr_type
== rs_fill
&& frag2
->fr_fix
== 0)
4218 return (is_same_frag (frag1
, frag2
->fr_next
));
4223 /* Build an entry in the UNWIND subspace from the given
4224 function attributes in CALL_INFO. */
4227 pa_build_unwind_subspace (call_info
)
4228 struct call_info
*call_info
;
4231 asection
*seg
, *save_seg
;
4232 subsegT subseg
, save_subseg
;
4236 /* Get into the right seg/subseg. This may involve creating
4237 the seg the first time through. Make sure to have the
4238 old seg/subseg so that we can reset things when we are done. */
4239 subseg
= SUBSEG_UNWIND
;
4240 seg
= bfd_get_section_by_name (stdoutput
, UNWIND_SECTION_NAME
);
4241 if (seg
== ASEC_NULL
)
4243 seg
= bfd_make_section_old_way (stdoutput
, UNWIND_SECTION_NAME
);
4244 bfd_set_section_flags (stdoutput
, seg
,
4245 SEC_READONLY
| SEC_HAS_CONTENTS
4246 | SEC_LOAD
| SEC_RELOC
);
4250 save_subseg
= now_subseg
;
4251 subseg_set (seg
, subseg
);
4254 /* Get some space to hold relocation information for the unwind
4257 call_info
->start_offset_frag
= frag_now
;
4258 call_info
->start_frag_where
= p
- frag_now
->fr_literal
;
4260 /* Relocation info. for start offset of the function. */
4261 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4262 call_info
->start_symbol
, (offsetT
) 0,
4263 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4266 /* We need to search for the first relocation involving the start_symbol of
4267 this call_info descriptor. */
4271 call_info
->start_fix
= seg_info (now_seg
)->fix_root
;
4272 for (fixP
= call_info
->start_fix
; fixP
; fixP
= fixP
->fx_next
)
4274 if (fixP
->fx_addsy
== call_info
->start_symbol
4275 || fixP
->fx_subsy
== call_info
->start_symbol
)
4277 call_info
->start_fix
= fixP
;
4284 call_info
->end_offset_frag
= frag_now
;
4285 call_info
->end_frag_where
= p
- frag_now
->fr_literal
;
4287 /* Relocation info. for end offset of the function. */
4288 fix_new_hppa (frag_now
, p
- frag_now
->fr_literal
, 4,
4289 call_info
->end_symbol
, (offsetT
) 0,
4290 (expressionS
*) NULL
, 0, R_HPPA_UNWIND
, e_fsel
, 32, 0,
4293 /* We need to search for the first relocation involving the end_symbol of
4294 this call_info descriptor. */
4298 call_info
->end_fix
= seg_info (now_seg
)->fix_root
; /* the default */
4299 for (fixP
= call_info
->end_fix
; fixP
; fixP
= fixP
->fx_next
)
4301 if (fixP
->fx_addsy
== call_info
->end_symbol
4302 || fixP
->fx_subsy
== call_info
->end_symbol
)
4304 call_info
->end_fix
= fixP
;
4310 /* callinfo.frame is in bytes and unwind_desc is in 8 byte units. */
4311 call_info
->ci_unwind
.descriptor
.frame_size
= call_info
->frame
/ 8;
4314 unwind
= (char *) &call_info
->ci_unwind
;
4315 for (i
= 8; i
< sizeof (struct unwind_table
); i
++)
4319 FRAG_APPEND_1_CHAR (c
);
4323 /* Return back to the original segment/subsegment. */
4324 subseg_set (save_seg
, save_subseg
);
4327 /* Process a .CALLINFO pseudo-op. This information is used later
4328 to build unwind descriptors and maybe one day to support
4329 .ENTER and .LEAVE. */
4332 pa_callinfo (unused
)
4338 /* .CALLINFO must appear within a procedure definition. */
4339 if (!within_procedure
)
4340 as_bad (".callinfo is not within a procedure definition");
4342 /* Mark the fact that we found the .CALLINFO for the
4343 current procedure. */
4344 callinfo_found
= TRUE
;
4346 /* Iterate over the .CALLINFO arguments. */
4347 while (!is_end_of_statement ())
4349 name
= input_line_pointer
;
4350 c
= get_symbol_end ();
4351 /* Frame size specification. */
4352 if ((strncasecmp (name
, "frame", 5) == 0))
4354 p
= input_line_pointer
;
4356 input_line_pointer
++;
4357 temp
= get_absolute_expression ();
4358 if ((temp
& 0x3) != 0)
4360 as_bad ("FRAME parameter must be a multiple of 8: %d\n", temp
);
4363 last_call_info
->frame
= temp
;
4365 /* Entry register (GR, GR and SR) specifications. */
4366 else if ((strncasecmp (name
, "entry_gr", 8) == 0))
4368 p
= input_line_pointer
;
4370 input_line_pointer
++;
4371 temp
= get_absolute_expression ();
4372 /* The HP assembler accepts 19 as the high bound for ENTRY_GR
4373 even though %r19 is caller saved. I think this is a bug in
4374 the HP assembler, and we are not going to emulate it. */
4375 if (temp
< 3 || temp
> 18)
4376 as_bad ("Value for ENTRY_GR must be in the range 3..18\n");
4377 last_call_info
->ci_unwind
.descriptor
.entry_gr
= temp
- 2;
4379 else if ((strncasecmp (name
, "entry_fr", 8) == 0))
4381 p
= input_line_pointer
;
4383 input_line_pointer
++;
4384 temp
= get_absolute_expression ();
4385 /* Similarly the HP assembler takes 31 as the high bound even
4386 though %fr21 is the last callee saved floating point register. */
4387 if (temp
< 12 || temp
> 21)
4388 as_bad ("Value for ENTRY_FR must be in the range 12..21\n");
4389 last_call_info
->ci_unwind
.descriptor
.entry_fr
= temp
- 11;
4391 else if ((strncasecmp (name
, "entry_sr", 8) == 0))
4393 p
= input_line_pointer
;
4395 input_line_pointer
++;
4396 temp
= get_absolute_expression ();
4398 as_bad ("Value for ENTRY_SR must be 3\n");
4399 last_call_info
->entry_sr
= temp
- 2;
4401 /* Note whether or not this function performs any calls. */
4402 else if ((strncasecmp (name
, "calls", 5) == 0) ||
4403 (strncasecmp (name
, "caller", 6) == 0))
4405 p
= input_line_pointer
;
4407 last_call_info
->makes_calls
= 1;
4409 else if ((strncasecmp (name
, "no_calls", 8) == 0))
4411 p
= input_line_pointer
;
4413 last_call_info
->makes_calls
= 0;
4415 /* Should RP be saved into the stack. */
4416 else if ((strncasecmp (name
, "save_rp", 7) == 0))
4418 p
= input_line_pointer
;
4420 last_call_info
->ci_unwind
.descriptor
.save_rp
= 1;
4422 /* Likewise for SP. */
4423 else if ((strncasecmp (name
, "save_sp", 7) == 0))
4425 p
= input_line_pointer
;
4427 last_call_info
->ci_unwind
.descriptor
.save_sp
= 1;
4429 /* Is this an unwindable procedure. If so mark it so
4430 in the unwind descriptor. */
4431 else if ((strncasecmp (name
, "no_unwind", 9) == 0))
4433 p
= input_line_pointer
;
4435 last_call_info
->ci_unwind
.descriptor
.cannot_unwind
= 1;
4437 /* Is this an interrupt routine. If so mark it in the
4438 unwind descriptor. */
4439 else if ((strncasecmp (name
, "hpux_int", 7) == 0))
4441 p
= input_line_pointer
;
4443 last_call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 1;
4447 as_bad ("Invalid .CALLINFO argument: %s", name
);
4449 if (!is_end_of_statement ())
4450 input_line_pointer
++;
4453 demand_empty_rest_of_line ();
4457 /* Switch into the code subspace. */
4463 sd_chain_struct
*sdchain
;
4465 /* First time through it might be necessary to create the
4467 if ((sdchain
= is_defined_space ("$TEXT$")) == NULL
)
4469 sdchain
= create_new_space (pa_def_spaces
[0].name
,
4470 pa_def_spaces
[0].spnum
,
4471 pa_def_spaces
[0].loadable
,
4472 pa_def_spaces
[0].defined
,
4473 pa_def_spaces
[0].private,
4474 pa_def_spaces
[0].sort
,
4475 pa_def_spaces
[0].segment
, 0);
4478 SPACE_DEFINED (sdchain
) = 1;
4479 subseg_set (text_section
, SUBSEG_CODE
);
4480 demand_empty_rest_of_line ();
4484 /* This is different than the standard GAS s_comm(). On HP9000/800 machines,
4485 the .comm pseudo-op has the following symtax:
4487 <label> .comm <length>
4489 where <label> is optional and is a symbol whose address will be the start of
4490 a block of memory <length> bytes long. <length> must be an absolute
4491 expression. <length> bytes will be allocated in the current space
4500 label_symbol_struct
*label_symbol
= pa_get_label ();
4503 symbol
= label_symbol
->lss_label
;
4508 size
= get_absolute_expression ();
4512 /* It is incorrect to check S_IS_DEFINED at this point as
4513 the symbol will *always* be defined. FIXME. How to
4514 correctly determine when this label really as been
4516 if (S_GET_VALUE (symbol
))
4518 if (S_GET_VALUE (symbol
) != size
)
4520 as_warn ("Length of .comm \"%s\" is already %d. Not changed.",
4521 S_GET_NAME (symbol
), S_GET_VALUE (symbol
));
4527 S_SET_VALUE (symbol
, size
);
4528 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4529 S_SET_EXTERNAL (symbol
);
4532 demand_empty_rest_of_line ();
4535 /* Process a .COPYRIGHT pseudo-op. */
4538 pa_copyright (unused
)
4545 if (*input_line_pointer
== '\"')
4547 ++input_line_pointer
;
4548 name
= input_line_pointer
;
4549 while ((c
= next_char_of_string ()) >= 0)
4551 c
= *input_line_pointer
;
4552 *input_line_pointer
= '\0';
4553 *(input_line_pointer
- 1) = '\0';
4555 /* FIXME. Not supported */
4558 *input_line_pointer
= c
;
4562 as_bad ("Expected \"-ed string");
4564 pa_undefine_label ();
4565 demand_empty_rest_of_line ();
4568 /* Process a .END pseudo-op. */
4574 demand_empty_rest_of_line ();
4578 /* Process a .ENTER pseudo-op. This is not supported. */
4587 /* Process a .ENTRY pseudo-op. .ENTRY marks the beginning of the
4595 if (!within_procedure
)
4596 as_bad ("Misplaced .entry. Ignored.");
4599 if (!callinfo_found
)
4600 as_bad ("Missing .callinfo.");
4602 last_call_info
->start_frag
= frag_now
;
4604 demand_empty_rest_of_line ();
4605 within_entry_exit
= TRUE
;
4606 where
= frag_more (0);
4608 /* Go back to the last symbol and turn on the BSF_FUNCTION flag.
4609 It will not be on if no .EXPORT pseudo-op exists (static function). */
4610 last_call_info
->start_symbol
->bsym
->flags
|= BSF_FUNCTION
;
4615 /* Handle a .EQU pseudo-op. */
4621 label_symbol_struct
*label_symbol
= pa_get_label ();
4626 symbol
= label_symbol
->lss_label
;
4627 S_SET_VALUE (symbol
, (unsigned int) get_absolute_expression ());
4628 S_SET_SEGMENT (symbol
, &bfd_abs_section
);
4633 as_bad (".REG must use a label");
4635 as_bad (".EQU must use a label");
4638 pa_undefine_label ();
4639 demand_empty_rest_of_line ();
4643 /* Helper function. Does processing for the end of a function. This
4644 usually involves creating some relocations or building special
4645 symbols to mark the end of the function. */
4652 where
= frag_more (0);
4654 /* ELF does not have EXIT relocations. All we do is create a
4655 temporary symbol marking the end of the function. */
4657 char *name
= (char *) xmalloc (strlen ("L\001end_") +
4658 strlen (S_GET_NAME (last_call_info
->start_symbol
)) + 1);
4664 strcpy (name
, "L\001end_");
4665 strcat (name
, S_GET_NAME (last_call_info
->start_symbol
));
4667 symbolP
= symbol_find (name
);
4669 as_warn ("Symbol '%s' already defined.", name
);
4672 /* symbol value should be the offset of the
4673 last instruction of the function */
4674 symbolP
= symbol_new (name
, now_seg
,
4675 (valueT
) (obstack_next_free (&frags
)
4676 - frag_now
->fr_literal
- 4),
4680 symbolP
->bsym
->flags
= BSF_LOCAL
;
4681 symbol_table_insert (symbolP
);
4684 last_call_info
->end_symbol
= symbolP
;
4686 as_bad ("Symbol '%s' could not be created.", name
);
4690 as_bad ("No memory for symbol name.");
4693 /* Stuff away the location of the frag for the end of the function,
4694 and call pa_build_unwind_subspace to add an entry in the unwind
4696 last_call_info
->end_frag
= frag_now
;
4697 pa_build_unwind_subspace (last_call_info
);
4698 exit_processing_complete
= TRUE
;
4701 /* Process a .EXIT pseudo-op. */
4707 if (!within_procedure
)
4708 as_bad (".EXIT must appear within a procedure");
4711 if (!callinfo_found
)
4712 as_bad ("Missing .callinfo");
4715 if (!within_entry_exit
)
4716 as_bad ("No .ENTRY for this .EXIT");
4719 within_entry_exit
= FALSE
;
4724 demand_empty_rest_of_line ();
4728 /* Process a .EXPORT directive. This makes functions external
4729 and provides information such as argument relocation entries
4739 name
= input_line_pointer
;
4740 c
= get_symbol_end ();
4741 /* Make sure the given symbol exists. */
4742 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4744 as_bad ("Cannot define export symbol: %s\n", name
);
4745 p
= input_line_pointer
;
4747 input_line_pointer
++;
4751 /* OK. Set the external bits and process argument relocations. */
4752 S_SET_EXTERNAL (symbol
);
4753 p
= input_line_pointer
;
4755 if (!is_end_of_statement ())
4757 input_line_pointer
++;
4758 pa_export_args (symbol
);
4760 pa_build_symextn_section ();
4765 demand_empty_rest_of_line ();
4769 /* Helper function to process arguments to a .EXPORT pseudo-op. */
4772 pa_export_args (symbolP
)
4776 unsigned int temp
, arg_reloc
;
4777 obj_symbol_type
*symbol
= (obj_symbol_type
*) symbolP
->bsym
;
4779 if (strncasecmp (input_line_pointer
, "absolute", 8) == 0)
4781 input_line_pointer
+= 8;
4782 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4783 S_SET_SEGMENT (symbolP
, &bfd_abs_section
);
4785 else if (strncasecmp (input_line_pointer
, "code", 4) == 0)
4787 input_line_pointer
+= 4;
4788 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4790 else if (strncasecmp (input_line_pointer
, "data", 4) == 0)
4792 input_line_pointer
+= 4;
4793 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4795 else if ((strncasecmp (input_line_pointer
, "entry", 5) == 0))
4797 input_line_pointer
+= 5;
4798 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4800 else if (strncasecmp (input_line_pointer
, "millicode", 9) == 0)
4802 input_line_pointer
+= 9;
4803 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4805 else if (strncasecmp (input_line_pointer
, "plabel", 6) == 0)
4807 input_line_pointer
+= 6;
4808 symbolP
->bsym
->flags
&= ~BSF_FUNCTION
;
4810 else if (strncasecmp (input_line_pointer
, "pri_prog", 8) == 0)
4812 input_line_pointer
+= 8;
4813 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4815 else if (strncasecmp (input_line_pointer
, "sec_prog", 8) == 0)
4817 input_line_pointer
+= 8;
4818 symbolP
->bsym
->flags
|= BSF_FUNCTION
;
4821 /* Now that the type of the exported symbol has been handled,
4822 handle any argument relocation information. */
4823 while (!is_end_of_statement ())
4825 if (*input_line_pointer
== ',')
4826 input_line_pointer
++;
4827 name
= input_line_pointer
;
4828 c
= get_symbol_end ();
4829 /* Argument sources. */
4830 if ((strncasecmp (name
, "argw", 4) == 0))
4832 p
= input_line_pointer
;
4834 input_line_pointer
++;
4835 temp
= atoi (name
+ 4);
4836 name
= input_line_pointer
;
4837 c
= get_symbol_end ();
4838 arg_reloc
= pa_align_arg_reloc (temp
, pa_build_arg_reloc (name
));
4839 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4840 *input_line_pointer
= c
;
4842 /* The return value. */
4843 else if ((strncasecmp (name
, "rtnval", 6)) == 0)
4845 p
= input_line_pointer
;
4847 input_line_pointer
++;
4848 name
= input_line_pointer
;
4849 c
= get_symbol_end ();
4850 arg_reloc
= pa_build_arg_reloc (name
);
4851 symbol
->tc_data
.hppa_arg_reloc
|= arg_reloc
;
4852 *input_line_pointer
= c
;
4854 /* Privelege level. */
4855 else if ((strncasecmp (name
, "priv_lev", 8)) == 0)
4857 p
= input_line_pointer
;
4859 input_line_pointer
++;
4860 temp
= atoi (input_line_pointer
);
4861 c
= get_symbol_end ();
4862 *input_line_pointer
= c
;
4866 as_bad ("Undefined .EXPORT/.IMPORT argument (ignored): %s", name
);
4867 p
= input_line_pointer
;
4870 if (!is_end_of_statement ())
4871 input_line_pointer
++;
4875 /* Handle an .IMPORT pseudo-op. Any symbol referenced in a given
4876 assembly file must either be defined in the assembly file, or
4877 explicitly IMPORTED from another. */
4886 name
= input_line_pointer
;
4887 c
= get_symbol_end ();
4889 symbol
= symbol_find_or_make (name
);
4890 p
= input_line_pointer
;
4893 if (!is_end_of_statement ())
4895 input_line_pointer
++;
4896 /* Hmmm. This doesn't look right. */
4897 pa_export_args (symbol
);
4901 /* If the section is undefined, then the symbol is undefined
4902 Since this is an import, leave the section undefined. */
4903 S_SET_SEGMENT (symbol
, &bfd_und_section
);
4906 demand_empty_rest_of_line ();
4910 /* Handle a .LABEL pseudo-op. */
4918 name
= input_line_pointer
;
4919 c
= get_symbol_end ();
4921 if (strlen (name
) > 0)
4924 p
= input_line_pointer
;
4929 as_warn ("Missing label name on .LABEL");
4932 if (!is_end_of_statement ())
4934 as_warn ("extra .LABEL arguments ignored.");
4935 ignore_rest_of_line ();
4937 demand_empty_rest_of_line ();
4941 /* Handle a .LEAVE pseudo-op. This is not supported yet. */
4950 /* Handle a .ORIGIN pseudo-op. */
4957 pa_undefine_label ();
4961 /* Handle a .PARAM pseudo-op. This is much like a .EXPORT, except it
4962 is for static functions. FIXME. Should share more code with .EXPORT. */
4971 name
= input_line_pointer
;
4972 c
= get_symbol_end ();
4974 if ((symbol
= symbol_find_or_make (name
)) == NULL
)
4976 as_bad ("Cannot define static symbol: %s\n", name
);
4977 p
= input_line_pointer
;
4979 input_line_pointer
++;
4983 S_CLEAR_EXTERNAL (symbol
);
4984 p
= input_line_pointer
;
4986 if (!is_end_of_statement ())
4988 input_line_pointer
++;
4989 pa_export_args (symbol
);
4993 demand_empty_rest_of_line ();
4997 /* Handle a .PROC pseudo-op. It is used to mark the beginning
4998 of a procedure from a syntatical point of view. */
5004 struct call_info
*call_info
;
5006 if (within_procedure
)
5007 as_fatal ("Nested procedures");
5009 /* Reset global variables for new procedure. */
5010 callinfo_found
= FALSE
;
5011 within_procedure
= TRUE
;
5012 exit_processing_complete
= FALSE
;
5014 /* Create another call_info structure. */
5015 call_info
= (struct call_info
*) xmalloc (sizeof (struct call_info
));
5018 as_fatal ("Cannot allocate unwind descriptor\n");
5020 bzero (call_info
, sizeof (struct call_info
));
5022 call_info
->ci_next
= NULL
;
5024 if (call_info_root
== NULL
)
5026 call_info_root
= call_info
;
5027 last_call_info
= call_info
;
5031 last_call_info
->ci_next
= call_info
;
5032 last_call_info
= call_info
;
5035 /* set up defaults on call_info structure */
5037 call_info
->ci_unwind
.descriptor
.cannot_unwind
= 0;
5038 call_info
->ci_unwind
.descriptor
.region_desc
= 1;
5039 call_info
->ci_unwind
.descriptor
.hpux_interrupt_marker
= 0;
5040 call_info
->entry_sr
= ~0;
5041 call_info
->makes_calls
= 1;
5043 /* If we got a .PROC pseudo-op, we know that the function is defined
5044 locally. Make sure it gets into the symbol table. */
5046 label_symbol_struct
*label_symbol
= pa_get_label ();
5050 if (label_symbol
->lss_label
)
5052 last_call_info
->start_symbol
= label_symbol
->lss_label
;
5053 label_symbol
->lss_label
->bsym
->flags
|= BSF_FUNCTION
;
5056 as_bad ("Missing function name for .PROC (corrupted label)");
5059 as_bad ("Missing function name for .PROC");
5062 demand_empty_rest_of_line ();
5066 /* Process the syntatical end of a procedure. Make sure all the
5067 appropriate pseudo-ops were found within the procedure. */
5074 if (!within_procedure
)
5075 as_bad ("misplaced .procend");
5077 if (!callinfo_found
)
5078 as_bad ("Missing .callinfo for this procedure");
5080 if (within_entry_exit
)
5081 as_bad ("Missing .EXIT for a .ENTRY");
5083 if (!exit_processing_complete
)
5086 within_procedure
= FALSE
;
5087 demand_empty_rest_of_line ();
5091 /* Parse the parameters to a .SPACE directive; if CREATE_FLAG is nonzero,
5092 then create a new space entry to hold the information specified
5093 by the parameters to the .SPACE directive. */
5095 static sd_chain_struct
*
5096 pa_parse_space_stmt (space_name
, create_flag
)
5100 char *name
, *ptemp
, c
;
5101 char loadable
, defined
, private, sort
;
5104 sd_chain_struct
*space
;
5106 /* load default values */
5111 if (strcasecmp (space_name
, "$TEXT$") == 0)
5122 if (!is_end_of_statement ())
5124 print_errors
= FALSE
;
5125 ptemp
= input_line_pointer
+ 1;
5126 /* First see if the space was specified as a number rather than
5127 as a name. According to the PA assembly manual the rest of
5128 the line should be ignored. */
5129 if ((spnum
= pa_parse_number (&ptemp
, 0)) >= 0)
5130 input_line_pointer
= ptemp
;
5133 while (!is_end_of_statement ())
5135 input_line_pointer
++;
5136 name
= input_line_pointer
;
5137 c
= get_symbol_end ();
5138 if ((strncasecmp (name
, "SPNUM", 5) == 0))
5140 *input_line_pointer
= c
;
5141 input_line_pointer
++;
5142 spnum
= get_absolute_expression ();
5144 else if ((strncasecmp (name
, "SORT", 4) == 0))
5146 *input_line_pointer
= c
;
5147 input_line_pointer
++;
5148 sort
= get_absolute_expression ();
5150 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5152 *input_line_pointer
= c
;
5155 else if ((strncasecmp (name
, "NOTDEFINED", 10) == 0))
5157 *input_line_pointer
= c
;
5160 else if ((strncasecmp (name
, "PRIVATE", 7) == 0))
5162 *input_line_pointer
= c
;
5167 as_bad ("Invalid .SPACE argument");
5168 *input_line_pointer
= c
;
5169 if (! is_end_of_statement ())
5170 input_line_pointer
++;
5174 print_errors
= TRUE
;
5177 /* If create_flag is nonzero, then create the new space with
5178 the attributes computed above. Else set the values in
5179 an already existing space -- this can only happen for
5180 the first occurence of a built-in space. */
5182 space
= create_new_space (space_name
, spnum
, loadable
, defined
,
5183 private, sort
, seg
, 1);
5186 space
= is_defined_space (space_name
);
5187 SPACE_SPNUM (space
) = spnum
;
5188 SPACE_LOADABLE (space
) = loadable
& 1;
5189 SPACE_DEFINED (space
) = defined
& 1;
5190 SPACE_USER_DEFINED (space
) = 1;
5191 SPACE_PRIVATE (space
) = private & 1;
5192 SPACE_SORT (space
) = sort
& 0xff;
5193 space
->sd_seg
= seg
;
5198 /* Adjust the frag's alignment according to the alignment needs
5199 of the given subspace/subsegment. */
5202 pa_align_subseg (seg
, subseg
)
5206 ssd_chain_struct
*now_subspace
;
5210 now_subspace
= pa_subsegment_to_subspace (seg
, subseg
);
5213 if (SUBSPACE_ALIGN (now_subspace
) == 0)
5214 alignment
= now_subspace
->ssd_last_align
;
5215 else if (now_subspace
->ssd_last_align
> SUBSPACE_ALIGN (now_subspace
))
5216 alignment
= now_subspace
->ssd_last_align
;
5218 alignment
= SUBSPACE_ALIGN (now_subspace
);
5220 while ((1 << shift
) < alignment
)
5224 shift
= bfd_get_section_alignment (stdoutput
, seg
);
5226 frag_align (shift
, 0);
5229 /* Handle a .SPACE pseudo-op; this switches the current space to the
5230 given space, creating the new space if necessary. */
5236 char *name
, c
, *space_name
, *save_s
;
5238 sd_chain_struct
*sd_chain
;
5240 if (within_procedure
)
5242 as_bad ("Can\'t change spaces within a procedure definition. Ignored");
5243 ignore_rest_of_line ();
5247 /* Check for some of the predefined spaces. FIXME: most of the code
5248 below is repeated several times, can we extract the common parts
5249 and place them into a subroutine or something similar? */
5250 if (strncasecmp (input_line_pointer
, "$text$", 6) == 0)
5252 input_line_pointer
+= 6;
5253 sd_chain
= is_defined_space ("$TEXT$");
5254 if (sd_chain
== NULL
)
5255 sd_chain
= pa_parse_space_stmt ("$TEXT$", 1);
5256 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5257 sd_chain
= pa_parse_space_stmt ("$TEXT$", 0);
5259 current_space
= sd_chain
;
5261 /* No need to align if we are already there. */
5262 if (now_seg
!= text_section
)
5263 pa_align_subseg (now_seg
, now_subseg
);
5265 subseg_set (text_section
, sd_chain
->sd_last_subseg
);
5268 = pa_subsegment_to_subspace (text_section
,
5269 sd_chain
->sd_last_subseg
);
5270 demand_empty_rest_of_line ();
5273 if (strncasecmp (input_line_pointer
, "$private$", 9) == 0)
5275 input_line_pointer
+= 9;
5276 sd_chain
= is_defined_space ("$PRIVATE$");
5277 if (sd_chain
== NULL
)
5278 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 1);
5279 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5280 sd_chain
= pa_parse_space_stmt ("$PRIVATE$", 0);
5282 current_space
= sd_chain
;
5284 /* No need to align if we are already there. */
5285 if (now_seg
!= data_section
)
5286 pa_align_subseg (now_seg
, now_subseg
);
5288 subseg_set (data_section
, sd_chain
->sd_last_subseg
);
5290 = pa_subsegment_to_subspace (data_section
,
5291 sd_chain
->sd_last_subseg
);
5292 demand_empty_rest_of_line ();
5295 if (!strncasecmp (input_line_pointer
,
5296 GDB_DEBUG_SPACE_NAME
,
5297 strlen (GDB_DEBUG_SPACE_NAME
)))
5299 input_line_pointer
+= strlen (GDB_DEBUG_SPACE_NAME
);
5300 sd_chain
= is_defined_space (GDB_DEBUG_SPACE_NAME
);
5301 if (sd_chain
== NULL
)
5302 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 1);
5303 else if (SPACE_USER_DEFINED (sd_chain
) == 0)
5304 sd_chain
= pa_parse_space_stmt (GDB_DEBUG_SPACE_NAME
, 0);
5306 current_space
= sd_chain
;
5309 asection
*gdb_section
5310 = bfd_make_section_old_way (stdoutput
, GDB_DEBUG_SPACE_NAME
);
5312 /* No need to align if we are already there. */
5313 if (strcmp (segment_name (now_seg
), GDB_DEBUG_SPACE_NAME
) != 0)
5314 pa_align_subseg (now_seg
, now_subseg
);
5316 subseg_set (gdb_section
, sd_chain
->sd_last_subseg
);
5318 = pa_subsegment_to_subspace (gdb_section
,
5319 sd_chain
->sd_last_subseg
);
5321 demand_empty_rest_of_line ();
5325 /* It could be a space specified by number. */
5327 save_s
= input_line_pointer
;
5328 if ((temp
= pa_parse_number (&input_line_pointer
, 0)) >= 0)
5330 if (sd_chain
= pa_find_space_by_number (temp
))
5332 current_space
= sd_chain
;
5334 if (now_seg
!= sd_chain
->sd_seg
)
5335 pa_align_subseg (now_seg
, now_subseg
);
5336 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5338 = pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5339 sd_chain
->sd_last_subseg
);
5340 demand_empty_rest_of_line ();
5345 /* Not a number, attempt to create a new space. */
5347 input_line_pointer
= save_s
;
5348 name
= input_line_pointer
;
5349 c
= get_symbol_end ();
5350 space_name
= xmalloc (strlen (name
) + 1);
5351 strcpy (space_name
, name
);
5352 *input_line_pointer
= c
;
5354 sd_chain
= pa_parse_space_stmt (space_name
, 1);
5355 current_space
= sd_chain
;
5357 if (now_seg
!= sd_chain
->sd_seg
)
5358 pa_align_subseg (now_seg
, now_subseg
);
5359 subseg_set (sd_chain
->sd_seg
, sd_chain
->sd_last_subseg
);
5360 current_subspace
= pa_subsegment_to_subspace (sd_chain
->sd_seg
,
5361 sd_chain
->sd_last_subseg
);
5362 demand_empty_rest_of_line ();
5367 /* Switch to a new space. (I think). FIXME. */
5376 sd_chain_struct
*space
;
5378 name
= input_line_pointer
;
5379 c
= get_symbol_end ();
5380 space
= is_defined_space (name
);
5384 md_number_to_chars (p
, SPACE_SPNUM (space
), 4);
5387 as_warn ("Undefined space: '%s' Assuming space number = 0.", name
);
5389 *input_line_pointer
= c
;
5390 demand_empty_rest_of_line ();
5394 /* If VALUE is an exact power of two between zero and 2^31, then
5395 return log2 (VALUE). Else return -1. */
5403 while ((1 << shift
) != value
&& shift
< 32)
5412 /* Handle a .SPACE pseudo-op; this switches the current subspace to the
5413 given subspace, creating the new subspace if necessary.
5415 FIXME. Should mirror pa_space more closely, in particular how
5416 they're broken up into subroutines. */
5419 pa_subspace (unused
)
5422 char *name
, *ss_name
, c
;
5423 char loadable
, code_only
, common
, dup_common
, zero
, sort
;
5424 int i
, access
, space_index
, alignment
, quadrant
;
5425 sd_chain_struct
*space
;
5426 ssd_chain_struct
*ssd
;
5428 if (within_procedure
)
5430 as_bad ("Can\'t change subspaces within a procedure definition. Ignored");
5431 ignore_rest_of_line ();
5435 name
= input_line_pointer
;
5436 c
= get_symbol_end ();
5437 ss_name
= xmalloc (strlen (name
) + 1);
5438 strcpy (ss_name
, name
);
5439 *input_line_pointer
= c
;
5441 /* Load default values. */
5453 space
= pa_segment_to_space (now_seg
);
5454 ssd
= is_defined_subspace (name
, space
->sd_last_subseg
);
5457 subseg_set (ssd
->ssd_seg
, ssd
->ssd_subseg
);
5458 if (!is_end_of_statement ())
5459 as_warn ("Parameters of an existing subspace can\'t be modified");
5460 demand_empty_rest_of_line ();
5465 /* A new subspace. Load default values. */
5467 while (pa_def_subspaces
[i
].name
)
5469 if (strcasecmp (pa_def_subspaces
[i
].name
, ss_name
) == 0)
5471 loadable
= pa_def_subspaces
[i
].loadable
;
5472 common
= pa_def_subspaces
[i
].common
;
5473 dup_common
= pa_def_subspaces
[i
].dup_common
;
5474 code_only
= pa_def_subspaces
[i
].code_only
;
5475 zero
= pa_def_subspaces
[i
].zero
;
5476 space_index
= pa_def_subspaces
[i
].space_index
;
5477 alignment
= pa_def_subspaces
[i
].alignment
;
5478 quadrant
= pa_def_subspaces
[i
].quadrant
;
5479 access
= pa_def_subspaces
[i
].access
;
5480 sort
= pa_def_subspaces
[i
].sort
;
5487 /* We should be working with a new subspace now. Fill in
5488 any information as specified by the user. */
5489 if (!is_end_of_statement ())
5491 input_line_pointer
++;
5492 while (!is_end_of_statement ())
5494 name
= input_line_pointer
;
5495 c
= get_symbol_end ();
5496 if ((strncasecmp (name
, "QUAD", 4) == 0))
5498 *input_line_pointer
= c
;
5499 input_line_pointer
++;
5500 quadrant
= get_absolute_expression ();
5502 else if ((strncasecmp (name
, "ALIGN", 5) == 0))
5504 *input_line_pointer
= c
;
5505 input_line_pointer
++;
5506 alignment
= get_absolute_expression ();
5507 if (log2 (alignment
) == -1)
5509 as_bad ("Alignment must be a power of 2");
5513 else if ((strncasecmp (name
, "ACCESS", 6) == 0))
5515 *input_line_pointer
= c
;
5516 input_line_pointer
++;
5517 access
= get_absolute_expression ();
5519 else if ((strncasecmp (name
, "SORT", 4) == 0))
5521 *input_line_pointer
= c
;
5522 input_line_pointer
++;
5523 sort
= get_absolute_expression ();
5525 else if ((strncasecmp (name
, "CODE_ONLY", 9) == 0))
5527 *input_line_pointer
= c
;
5530 else if ((strncasecmp (name
, "UNLOADABLE", 10) == 0))
5532 *input_line_pointer
= c
;
5535 else if ((strncasecmp (name
, "COMMON", 6) == 0))
5537 *input_line_pointer
= c
;
5540 else if ((strncasecmp (name
, "DUP_COMM", 8) == 0))
5542 *input_line_pointer
= c
;
5545 else if ((strncasecmp (name
, "ZERO", 4) == 0))
5547 *input_line_pointer
= c
;
5550 else if ((strncasecmp (name
, "FIRST", 5) == 0))
5551 as_bad ("FIRST not supported as a .SUBSPACE argument");
5553 as_bad ("Invalid .SUBSPACE argument");
5554 if (!is_end_of_statement ())
5555 input_line_pointer
++;
5559 /* Now that all the flags are set, update an existing subspace,
5560 or create a new one with the given flags if the subspace does
5561 not currently exist. */
5562 space
= pa_segment_to_space (now_seg
);
5564 current_subspace
= update_subspace (ss_name
, loadable
, code_only
,
5565 common
, dup_common
, sort
, zero
,
5566 access
, space_index
, alignment
,
5567 quadrant
, ssd
->ssd_subseg
);
5569 current_subspace
= create_new_subspace (space
, ss_name
, loadable
,
5571 dup_common
, zero
, sort
,
5572 access
, space_index
,
5573 alignment
, quadrant
, now_seg
);
5574 SUBSPACE_SUBSPACE_START (current_subspace
) = pa_subspace_start (space
,
5577 demand_empty_rest_of_line ();
5578 subseg_set (current_subspace
->ssd_seg
, current_subspace
->ssd_subseg
);
5584 /* Create default space and subspace dictionaries. */
5589 sd_chain_struct
*space
;
5592 space_dict_root
= NULL
;
5593 space_dict_last
= NULL
;
5596 while (pa_def_spaces
[i
].name
)
5598 if (pa_def_spaces
[i
].alias
)
5599 pa_def_spaces
[i
].segment
= subseg_new (pa_def_spaces
[i
].alias
, 0);
5601 pa_def_spaces
[i
].segment
5602 = bfd_make_section_old_way (stdoutput
, pa_def_spaces
[i
].name
);
5604 create_new_space (pa_def_spaces
[i
].name
, pa_def_spaces
[i
].spnum
,
5605 pa_def_spaces
[i
].loadable
, pa_def_spaces
[i
].defined
,
5606 pa_def_spaces
[i
].private, pa_def_spaces
[i
].sort
,
5607 pa_def_spaces
[i
].segment
, 0);
5612 while (pa_def_subspaces
[i
].name
)
5614 space
= pa_segment_to_space (pa_def_spaces
[pa_def_subspaces
[i
].def_space_index
].segment
);
5617 char *name
= pa_def_subspaces
[i
].alias
;
5619 name
= pa_def_subspaces
[i
].name
;
5620 create_new_subspace (space
, name
,
5621 pa_def_subspaces
[i
].loadable
,
5622 pa_def_subspaces
[i
].code_only
,
5623 pa_def_subspaces
[i
].common
,
5624 pa_def_subspaces
[i
].dup_common
,
5625 pa_def_subspaces
[i
].zero
,
5626 pa_def_subspaces
[i
].sort
,
5627 pa_def_subspaces
[i
].access
,
5628 pa_def_subspaces
[i
].space_index
,
5629 pa_def_subspaces
[i
].alignment
,
5630 pa_def_subspaces
[i
].quadrant
,
5631 pa_def_spaces
[pa_def_subspaces
[i
].def_space_index
].segment
);
5632 subseg_new (name
, pa_def_subspaces
[i
].subsegment
);
5635 as_fatal ("Internal error: space missing for subspace \"%s\"\n",
5636 pa_def_subspaces
[i
].name
);
5643 /* Create a new space NAME, with the appropriate flags as defined
5644 by the given parameters.
5646 Add the new space to the space dictionary chain in numerical
5647 order as defined by the SORT entries. */
5649 static sd_chain_struct
*
5650 create_new_space (name
, spnum
, loadable
, defined
, private,
5651 sort
, seg
, user_defined
)
5661 sd_chain_struct
*chain_entry
;
5663 chain_entry
= (sd_chain_struct
*) xmalloc (sizeof (sd_chain_struct
));
5665 as_fatal ("Out of memory: could not allocate new space chain entry: %s\n",
5668 SPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5669 strcpy (SPACE_NAME (chain_entry
), name
);
5670 SPACE_NAME_INDEX (chain_entry
) = 0;
5671 SPACE_LOADABLE (chain_entry
) = loadable
;
5672 SPACE_DEFINED (chain_entry
) = defined
;
5673 SPACE_USER_DEFINED (chain_entry
) = user_defined
;
5674 SPACE_PRIVATE (chain_entry
) = private;
5675 SPACE_SPNUM (chain_entry
) = spnum
;
5676 SPACE_SORT (chain_entry
) = sort
;
5678 chain_entry
->sd_seg
= seg
;
5679 chain_entry
->sd_last_subseg
= -1;
5680 chain_entry
->sd_next
= NULL
;
5682 /* Find spot for the new space based on its sort key. */
5683 if (!space_dict_last
)
5684 space_dict_last
= chain_entry
;
5686 if (space_dict_root
== NULL
)
5687 space_dict_root
= chain_entry
;
5690 sd_chain_struct
*chain_pointer
;
5691 sd_chain_struct
*prev_chain_pointer
;
5693 chain_pointer
= space_dict_root
;
5694 prev_chain_pointer
= NULL
;
5696 while (chain_pointer
)
5698 if (SPACE_SORT (chain_pointer
) <= SPACE_SORT (chain_entry
))
5700 prev_chain_pointer
= chain_pointer
;
5701 chain_pointer
= chain_pointer
->sd_next
;
5707 /* At this point we've found the correct place to add the new
5708 entry. So add it and update the linked lists as appropriate. */
5709 if (prev_chain_pointer
)
5711 chain_entry
->sd_next
= chain_pointer
;
5712 prev_chain_pointer
->sd_next
= chain_entry
;
5716 space_dict_root
= chain_entry
;
5717 chain_entry
->sd_next
= chain_pointer
;
5720 if (chain_entry
->sd_next
== NULL
)
5721 space_dict_last
= chain_entry
;
5727 /* Create a new subspace NAME, with the appropriate flags as defined
5728 by the given parameters.
5730 Add the new subspace to the subspace dictionary chain in numerical
5731 order as defined by the SORT entries. */
5733 static ssd_chain_struct
*
5734 create_new_subspace (space
, name
, loadable
, code_only
, common
,
5735 dup_common
, is_zero
, sort
, access
, space_index
,
5736 alignment
, quadrant
, seg
)
5737 sd_chain_struct
*space
;
5739 char loadable
, code_only
, common
, dup_common
, is_zero
;
5747 ssd_chain_struct
*chain_entry
;
5748 symbolS
*start_symbol
;
5750 chain_entry
= (ssd_chain_struct
*) xmalloc (sizeof (ssd_chain_struct
));
5752 as_fatal ("Out of memory: could not allocate new subspace chain entry: %s\n", name
);
5754 SUBSPACE_NAME (chain_entry
) = (char *) xmalloc (strlen (name
) + 1);
5755 strcpy (SUBSPACE_NAME (chain_entry
), name
);
5757 SUBSPACE_ACCESS (chain_entry
) = access
;
5758 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5759 SUBSPACE_COMMON (chain_entry
) = common
;
5760 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5761 SUBSPACE_SORT (chain_entry
) = sort
;
5762 SUBSPACE_CODE_ONLY (chain_entry
) = code_only
;
5763 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5764 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5765 SUBSPACE_SUBSPACE_START (chain_entry
) = pa_subspace_start (space
, quadrant
);
5766 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5767 SUBSPACE_ZERO (chain_entry
) = is_zero
;
5769 chain_entry
->ssd_subseg
= pa_next_subseg (space
);
5770 chain_entry
->ssd_seg
= seg
;
5771 chain_entry
->ssd_last_align
= 1;
5772 chain_entry
->ssd_next
= NULL
;
5774 /* Find spot for the new subspace based on its sort key. */
5775 if (space
->sd_subspaces
== NULL
)
5776 space
->sd_subspaces
= chain_entry
;
5779 ssd_chain_struct
*chain_pointer
;
5780 ssd_chain_struct
*prev_chain_pointer
;
5782 chain_pointer
= space
->sd_subspaces
;
5783 prev_chain_pointer
= NULL
;
5785 while (chain_pointer
)
5787 if (SUBSPACE_SORT (chain_pointer
) <= SUBSPACE_SORT (chain_entry
))
5789 prev_chain_pointer
= chain_pointer
;
5790 chain_pointer
= chain_pointer
->ssd_next
;
5797 /* Now we have somewhere to put the new entry. Insert it and update
5799 if (prev_chain_pointer
)
5801 chain_entry
->ssd_next
= chain_pointer
;
5802 prev_chain_pointer
->ssd_next
= chain_entry
;
5806 space
->sd_subspaces
= chain_entry
;
5807 chain_entry
->ssd_next
= chain_pointer
;
5815 /* Update the information for the given subspace based upon the
5816 various arguments. Return the modified subspace chain entry. */
5818 static ssd_chain_struct
*
5819 update_subspace (name
, loadable
, code_only
, common
, dup_common
, sort
,
5820 zero
, access
, space_index
, alignment
, quadrant
, subseg
)
5834 ssd_chain_struct
*chain_entry
;
5836 if ((chain_entry
= is_defined_subspace (name
, subseg
)))
5838 SUBSPACE_ACCESS (chain_entry
) = access
;
5839 SUBSPACE_LOADABLE (chain_entry
) = loadable
;
5840 SUBSPACE_COMMON (chain_entry
) = common
;
5841 SUBSPACE_DUP_COMM (chain_entry
) = dup_common
;
5842 SUBSPACE_CODE_ONLY (chain_entry
) = 1;
5843 SUBSPACE_SORT (chain_entry
) = sort
;
5844 SUBSPACE_ALIGN (chain_entry
) = alignment
;
5845 SUBSPACE_QUADRANT (chain_entry
) = quadrant
;
5846 SUBSPACE_SPACE_INDEX (chain_entry
) = space_index
;
5847 SUBSPACE_ZERO (chain_entry
) = zero
;
5856 /* Return the space chain entry for the space with the name NAME or
5857 NULL if no such space exists. */
5859 static sd_chain_struct
*
5860 is_defined_space (name
)
5863 sd_chain_struct
*chain_pointer
;
5865 for (chain_pointer
= space_dict_root
;
5867 chain_pointer
= chain_pointer
->sd_next
)
5869 if (strcmp (SPACE_NAME (chain_pointer
), name
) == 0)
5870 return chain_pointer
;
5873 /* No mapping from segment to space was found. Return NULL. */
5877 /* Find and return the space associated with the given seg. If no mapping
5878 from the given seg to a space is found, then return NULL.
5880 Unlike subspaces, the number of spaces is not expected to grow much,
5881 so a linear exhaustive search is OK here. */
5883 static sd_chain_struct
*
5884 pa_segment_to_space (seg
)
5887 sd_chain_struct
*space_chain
;
5889 /* Walk through each space looking for the correct mapping. */
5890 for (space_chain
= space_dict_root
;
5892 space_chain
= space_chain
->sd_next
)
5894 if (space_chain
->sd_seg
== seg
)
5898 /* Mapping was not found. Return NULL. */
5902 /* Return the space chain entry for the subspace with the name NAME or
5903 NULL if no such subspace exists.
5905 Uses a linear search through all the spaces and subspaces, this may
5906 not be appropriate if we ever being placing each function in its
5909 static ssd_chain_struct
*
5910 is_defined_subspace (name
, subseg
)
5914 sd_chain_struct
*space_chain
;
5915 ssd_chain_struct
*subspace_chain
;
5917 /* Walk through each space. */
5918 for (space_chain
= space_dict_root
;
5920 space_chain
= space_chain
->sd_next
)
5922 /* Walk through each subspace looking for a name which matches. */
5923 for (subspace_chain
= space_chain
->sd_subspaces
;
5925 subspace_chain
= subspace_chain
->ssd_next
)
5926 if (strcmp (SUBSPACE_NAME (subspace_chain
), name
) == 0)
5927 return subspace_chain
;
5930 /* Subspace wasn't found. Return NULL. */
5934 /* Find and return the subspace associated with the given seg. If no
5935 mapping from the given seg to a subspace is found, then return NULL.
5937 If we ever put each procedure/function within its own subspace
5938 (to make life easier on the compiler and linker), then this will have
5939 to become more efficient. */
5941 static ssd_chain_struct
*
5942 pa_subsegment_to_subspace (seg
, subseg
)
5946 sd_chain_struct
*space_chain
;
5947 ssd_chain_struct
*subspace_chain
;
5949 /* Walk through each space. */
5950 for (space_chain
= space_dict_root
;
5952 space_chain
= space_chain
->sd_next
)
5954 if (space_chain
->sd_seg
== seg
)
5956 /* Walk through each subspace within each space looking for
5957 the correct mapping. */
5958 for (subspace_chain
= space_chain
->sd_subspaces
;
5960 subspace_chain
= subspace_chain
->ssd_next
)
5961 if (subspace_chain
->ssd_subseg
== (int) subseg
)
5962 return subspace_chain
;
5966 /* No mapping from subsegment to subspace found. Return NULL. */
5970 /* Given a number, try and find a space with the name number.
5972 Return a pointer to a space dictionary chain entry for the space
5973 that was found or NULL on failure. */
5975 static sd_chain_struct
*
5976 pa_find_space_by_number (number
)
5979 sd_chain_struct
*space_chain
;
5981 for (space_chain
= space_dict_root
;
5983 space_chain
= space_chain
->sd_next
)
5985 if (SPACE_SPNUM (space_chain
) == number
)
5989 /* No appropriate space found. Return NULL. */
5993 /* Return the starting address for the given subspace. If the starting
5994 address is unknown then return zero. */
5997 pa_subspace_start (space
, quadrant
)
5998 sd_chain_struct
*space
;
6001 /* FIXME. Assumes everyone puts read/write data at 0x4000000, this
6002 is not correct for the PA OSF1 port. */
6003 if ((strcasecmp (SPACE_NAME (space
), "$PRIVATE$") == 0) && quadrant
== 1)
6005 else if (space
->sd_seg
== data_section
&& quadrant
== 1)
6011 /* FIXME. Needs documentation. */
6013 pa_next_subseg (space
)
6014 sd_chain_struct
*space
;
6017 space
->sd_last_subseg
++;
6018 return space
->sd_last_subseg
;
6021 /* Helper function for pa_stringer. Used to find the end of
6028 unsigned int c
= *s
& CHAR_MASK
;
6040 /* Handle a .STRING type pseudo-op. */
6043 pa_stringer (append_zero
)
6046 char *s
, num_buf
[4];
6050 /* Preprocess the string to handle PA-specific escape sequences.
6051 For example, \xDD where DD is a hexidecimal number should be
6052 changed to \OOO where OOO is an octal number. */
6054 /* Skip the opening quote. */
6055 s
= input_line_pointer
+ 1;
6057 while (is_a_char (c
= pa_stringer_aux (s
++)))
6064 /* Handle \x<num>. */
6067 unsigned int number
;
6072 /* Get pas the 'x'. */
6074 for (num_digit
= 0, number
= 0, dg
= *s
;
6076 && (isdigit (dg
) || (dg
>= 'a' && dg
<= 'f')
6077 || (dg
>= 'A' && dg
<= 'F'));
6081 number
= number
* 16 + dg
- '0';
6082 else if (dg
>= 'a' && dg
<= 'f')
6083 number
= number
* 16 + dg
- 'a' + 10;
6085 number
= number
* 16 + dg
- 'A' + 10;
6095 sprintf (num_buf
, "%02o", number
);
6098 sprintf (num_buf
, "%03o", number
);
6101 for (i
= 0; i
<= num_digit
; i
++)
6102 s_start
[i
] = num_buf
[i
];
6106 /* This might be a "\"", skip over the escaped char. */
6113 stringer (append_zero
);
6114 pa_undefine_label ();
6117 /* Handle a .VERSION pseudo-op. */
6124 pa_undefine_label ();
6127 /* Just like a normal cons, but when finished we have to undefine
6128 the latest space label. */
6135 pa_undefine_label ();
6138 /* Switch to the data space. As usual delete our label. */
6145 pa_undefine_label ();
6148 /* FIXME. What's the purpose of this pseudo-op? */
6154 pa_undefine_label ();
6157 /* Like float_cons, but we need to undefine our label. */
6160 pa_float_cons (float_type
)
6163 float_cons (float_type
);
6164 pa_undefine_label ();
6167 /* Like s_fill, but delete our label when finished. */
6174 pa_undefine_label ();
6177 /* Like lcomm, but delete our label when finished. */
6180 pa_lcomm (needs_align
)
6183 s_lcomm (needs_align
);
6184 pa_undefine_label ();
6187 /* Like lsym, but delete our label when finished. */
6194 pa_undefine_label ();
6197 /* Switch to the text space. Like s_text, but delete our
6198 label when finished. */
6204 pa_undefine_label ();
6207 /* On the PA relocations which involve function symbols must not be
6208 adjusted. This so that the linker can know when/how to create argument
6209 relocation stubs for indirect calls and calls to static functions.
6211 FIXME. Also reject R_HPPA relocations which are 32 bits
6212 wide. Helps with code lables in arrays for SOM. (SOM BFD code
6213 needs to generate relocations to push the addend and symbol value
6214 onto the stack, add them, then pop the value off the stack and
6215 use it in a relocation -- yuk. */
6218 hppa_fix_adjustable (fixp
)
6221 struct hppa_fix_struct
*hppa_fix
;
6223 hppa_fix
= fixp
->tc_fix_data
;
6225 if (fixp
->fx_r_type
== R_HPPA
&& hppa_fix
->fx_r_format
== 32)
6228 if (fixp
->fx_addsy
== 0
6229 || (fixp
->fx_addsy
->bsym
->flags
& BSF_FUNCTION
) == 0)
6235 /* Now for some ELF specific code. FIXME. */
6237 static symext_chainS
*symext_rootP
;
6238 static symext_chainS
*symext_lastP
;
6240 /* Do any symbol processing requested by the target-cpu or target-format. */
6243 hppa_tc_symbol (abfd
, symbolP
, sym_idx
)
6245 elf_symbol_type
*symbolP
;
6248 symext_chainS
*symextP
;
6249 unsigned int arg_reloc
;
6251 /* Only functions can have argument relocations. */
6252 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
6255 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
6257 /* If there are no argument relocation bits, then no relocation is
6258 necessary. Do not add this to the symextn section. */
6262 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
6264 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
6265 symextP
[0].next
= &symextP
[1];
6267 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
6268 symextP
[1].next
= NULL
;
6270 if (symext_rootP
== NULL
)
6272 symext_rootP
= &symextP
[0];
6273 symext_lastP
= &symextP
[1];
6277 symext_lastP
->next
= &symextP
[0];
6278 symext_lastP
= &symextP
[1];
6282 /* Make sections needed by the target cpu and/or target format. */
6284 hppa_tc_make_sections (abfd
)
6287 symext_chainS
*symextP
;
6289 asection
*symextn_sec
;
6290 segT save_seg
= now_seg
;
6291 subsegT save_subseg
= now_subseg
;
6293 /* Build the symbol extension section. */
6294 hppa_tc_make_symextn_section ();
6296 /* Force some calculation to occur. */
6297 bfd_set_section_contents (stdoutput
, stdoutput
->sections
, "", 0, 0);
6299 hppa_elf_stub_finish (abfd
);
6301 /* If no symbols for the symbol extension section, then stop now. */
6302 if (symext_rootP
== NULL
)
6305 /* Count the number of symbols for the symbol extension section. */
6306 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6309 size
= sizeof (symext_entryS
) * n
;
6311 /* Switch to the symbol extension section. */
6312 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6314 frag_wane (frag_now
);
6317 for (symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
)
6320 int *symtab_map
= elf_sym_extra (abfd
);
6323 /* First, patch the symbol extension record to reflect the true
6324 symbol table index. */
6326 if (ELF32_HPPA_SX_TYPE (symextP
->entry
) == HPPA_SXT_SYMNDX
)
6328 idx
= ELF32_HPPA_SX_VAL (symextP
->entry
) - 1;
6329 symextP
->entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
,
6333 ptr
= frag_more (sizeof (symextP
->entry
));
6334 md_number_to_chars (ptr
, symextP
->entry
, sizeof (symextP
->entry
));
6337 frag_now
->fr_fix
= obstack_next_free (&frags
) - frag_now
->fr_literal
;
6338 frag_wane (frag_now
);
6340 /* Switch back to the original segment. */
6341 subseg_set (save_seg
, save_subseg
);
6346 /* Make the symbol extension section. */
6349 hppa_tc_make_symextn_section ()
6353 symext_chainS
*symextP
;
6357 segT save_seg
= now_seg
;
6358 subsegT save_subseg
= now_subseg
;
6360 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
6363 size
= sizeof (symext_entryS
) * n
;
6365 symextn_sec
= subseg_new (SYMEXTN_SECTION_NAME
, 0);
6367 bfd_set_section_flags (stdoutput
, symextn_sec
,
6368 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
6369 bfd_set_section_size (stdoutput
, symextn_sec
, size
);
6371 /* Now, switch back to the original segment. */
6372 subseg_set (save_seg
, save_subseg
);
6376 /* Build the symbol extension section. */
6379 pa_build_symextn_section ()
6382 asection
*save_seg
= now_seg
;
6383 subsegT subseg
= (subsegT
) 0;
6384 subsegT save_subseg
= now_subseg
;
6386 seg
= subseg_new (".hppa_symextn", subseg
);
6387 bfd_set_section_flags (stdoutput
,
6389 SEC_HAS_CONTENTS
| SEC_READONLY
6390 | SEC_ALLOC
| SEC_LOAD
);
6392 subseg_set (save_seg
, save_subseg
);
6396 /* For ELF, this function serves one purpose: to setup the st_size
6397 field of STT_FUNC symbols. To do this, we need to scan the
6398 call_info structure list, determining st_size in one of two possible
6401 1. call_info->start_frag->fr_fix has the size of the fragment.
6402 This approach assumes that the function was built into a
6403 single fragment. This works for most cases, but might fail.
6404 For example, if there was a segment change in the middle of
6407 2. The st_size field is the difference in the addresses of the
6408 call_info->start_frag->fr_address field and the fr_address
6409 field of the next fragment with fr_type == rs_fill and
6413 elf_hppa_final_processing ()
6415 struct call_info
*call_info_pointer
;
6417 for (call_info_pointer
= call_info_root
;
6419 call_info_pointer
= call_info_pointer
->ci_next
)
6421 elf_symbol_type
*esym
6422 = (elf_symbol_type
*) call_info_pointer
->start_symbol
->bsym
;
6423 esym
->internal_elf_sym
.st_size
=
6424 S_GET_VALUE (call_info_pointer
->end_symbol
)
6425 - S_GET_VALUE (call_info_pointer
->start_symbol
) + 4;